summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/3rdparty/eigen/.gitignore38
-rw-r--r--src/3rdparty/eigen/COPYING.BSD24
-rw-r--r--src/3rdparty/eigen/COPYING.MPL2373
-rw-r--r--src/3rdparty/eigen/COPYING.README18
-rw-r--r--src/3rdparty/eigen/COPYRIGHTS45
-rw-r--r--src/3rdparty/eigen/Eigen/Cholesky45
-rw-r--r--src/3rdparty/eigen/Eigen/Core384
-rw-r--r--src/3rdparty/eigen/Eigen/Dense7
-rw-r--r--src/3rdparty/eigen/Eigen/Eigenvalues60
-rw-r--r--src/3rdparty/eigen/Eigen/Geometry59
-rw-r--r--src/3rdparty/eigen/Eigen/Householder29
-rw-r--r--src/3rdparty/eigen/Eigen/Jacobi32
-rw-r--r--src/3rdparty/eigen/Eigen/LU47
-rw-r--r--src/3rdparty/eigen/Eigen/QR50
-rw-r--r--src/3rdparty/eigen/Eigen/SVD50
-rw-r--r--src/3rdparty/eigen/Eigen/src/Cholesky/LDLT.h688
-rw-r--r--src/3rdparty/eigen/Eigen/src/Cholesky/LLT.h558
-rw-r--r--src/3rdparty/eigen/Eigen/src/Cholesky/LLT_LAPACKE.h99
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/ArithmeticSequence.h413
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Array.h417
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/ArrayBase.h226
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/ArrayWrapper.h209
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Assign.h90
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/AssignEvaluator.h1010
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Assign_MKL.h178
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/BandMatrix.h353
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Block.h448
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/BooleanRedux.h162
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/CommaInitializer.h164
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/ConditionEstimator.h175
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/CoreEvaluators.h1741
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/CoreIterators.h132
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/CwiseBinaryOp.h183
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/CwiseNullaryOp.h1001
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/CwiseTernaryOp.h197
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/CwiseUnaryOp.h103
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/CwiseUnaryView.h132
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/DenseBase.h701
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/DenseCoeffsBase.h685
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/DenseStorage.h652
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Diagonal.h258
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/DiagonalMatrix.h391
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/DiagonalProduct.h28
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Dot.h318
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/EigenBase.h160
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/ForceAlignedAccess.h150
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Fuzzy.h155
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/GeneralProduct.h465
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/GenericPacketMath.h1040
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/GlobalFunctions.h194
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/IO.h258
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/IndexedView.h237
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Inverse.h117
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Map.h171
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/MapBase.h310
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/MathFunctions.h2057
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/MathFunctionsImpl.h200
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Matrix.h565
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/MatrixBase.h547
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/NestByValue.h85
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/NoAlias.h109
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/NumTraits.h335
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/PartialReduxEvaluator.h232
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/PermutationMatrix.h605
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/PlainObjectBase.h1128
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Product.h191
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/ProductEvaluators.h1179
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Random.h218
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Redux.h515
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Ref.h381
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Replicate.h142
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Reshaped.h454
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/ReturnByValue.h119
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Reverse.h217
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Select.h164
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/SelfAdjointView.h365
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h47
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Solve.h188
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/SolveTriangular.h235
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/SolverBase.h168
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/StableNorm.h251
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/StlIterators.h463
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Stride.h116
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Swap.h68
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Transpose.h464
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Transpositions.h386
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/TriangularMatrix.h1001
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/VectorBlock.h96
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/VectorwiseOp.h784
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/Visitor.h381
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AVX/Complex.h372
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h228
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AVX/PacketMath.h1574
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h115
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/Complex.h422
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h362
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h2303
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/TypeCasting.h89
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/Complex.h417
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h90
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProduct.h2937
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductCommon.h221
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMA.h629
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h2711
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/CUDA/Complex.h258
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/Default/BFloat16.h700
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/Default/ConjHelper.h117
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h1649
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h110
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/Default/Half.h942
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/Default/Settings.h49
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/Default/TypeCasting.h120
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/GPU/MathFunctions.h103
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/GPU/PacketMath.h1685
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/GPU/TypeCasting.h80
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/HIP/hcc/math_constants.h23
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/MSA/Complex.h648
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/MSA/MathFunctions.h387
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/MSA/PacketMath.h1233
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/NEON/Complex.h584
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/NEON/GeneralBlockPanelKernel.h183
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h75
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/NEON/PacketMath.h4587
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/NEON/TypeCasting.h1419
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SSE/Complex.h351
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h199
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SSE/PacketMath.h1505
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h142
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SVE/MathFunctions.h44
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SVE/PacketMath.h752
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SVE/TypeCasting.h49
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/InteropHeaders.h232
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/MathFunctions.h301
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/PacketMath.h670
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h694
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/TypeCasting.h85
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/Complex.h426
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h233
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h1060
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/functors/AssignmentFunctors.h177
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/functors/BinaryFunctors.h541
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/functors/NullaryFunctors.h189
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/functors/StlFunctors.h166
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/functors/TernaryFunctors.h25
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/functors/UnaryFunctors.h1131
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h2645
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h517
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h317
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h145
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h124
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixVector.h518
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h136
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/Parallelizer.h180
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h544
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h295
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h262
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h118
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointProduct.h133
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h94
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h472
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h317
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixVector.h350
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h255
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h337
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h167
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverVector.h148
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/BlasUtil.h583
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/ConfigureVectorization.h512
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/Constants.h563
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/DisableStupidWarnings.h106
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/ForwardDeclarations.h322
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/IndexedViewHelper.h186
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/IntegralConstant.h272
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/MKL_support.h137
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/Macros.h1464
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/Memory.h1163
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/Meta.h812
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/NonMPL2.h3
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h31
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/ReshapedHelper.h51
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/StaticAssert.h221
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/SymbolicIndex.h293
-rw-r--r--src/3rdparty/eigen/Eigen/src/Core/util/XprHelper.h856
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexEigenSolver.h346
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexSchur.h462
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h91
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/EigenSolver.h622
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h418
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h226
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/HessenbergDecomposition.h374
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h158
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/RealQZ.h657
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/RealSchur.h558
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h77
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h904
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h87
-rw-r--r--src/3rdparty/eigen/Eigen/src/Eigenvalues/Tridiagonalization.h561
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/AlignedBox.h486
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/AngleAxis.h247
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/EulerAngles.h114
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/Homogeneous.h501
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/Hyperplane.h282
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/OrthoMethods.h235
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/ParametrizedLine.h232
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/Quaternion.h870
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/Rotation2D.h199
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/RotationBase.h206
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/Scaling.h188
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/Transform.h1563
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/Translation.h202
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/Umeyama.h166
-rw-r--r--src/3rdparty/eigen/Eigen/src/Geometry/arch/Geometry_SIMD.h168
-rw-r--r--src/3rdparty/eigen/Eigen/src/Householder/BlockHouseholder.h110
-rw-r--r--src/3rdparty/eigen/Eigen/src/Householder/Householder.h176
-rw-r--r--src/3rdparty/eigen/Eigen/src/Householder/HouseholderSequence.h545
-rw-r--r--src/3rdparty/eigen/Eigen/src/Jacobi/Jacobi.h483
-rw-r--r--src/3rdparty/eigen/Eigen/src/LU/Determinant.h117
-rw-r--r--src/3rdparty/eigen/Eigen/src/LU/FullPivLU.h877
-rw-r--r--src/3rdparty/eigen/Eigen/src/LU/InverseImpl.h432
-rw-r--r--src/3rdparty/eigen/Eigen/src/LU/PartialPivLU.h624
-rw-r--r--src/3rdparty/eigen/Eigen/src/LU/PartialPivLU_LAPACKE.h83
-rw-r--r--src/3rdparty/eigen/Eigen/src/LU/arch/InverseSize4.h351
-rw-r--r--src/3rdparty/eigen/Eigen/src/QR/ColPivHouseholderQR.h674
-rw-r--r--src/3rdparty/eigen/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h97
-rw-r--r--src/3rdparty/eigen/Eigen/src/QR/CompleteOrthogonalDecomposition.h635
-rw-r--r--src/3rdparty/eigen/Eigen/src/QR/FullPivHouseholderQR.h713
-rw-r--r--src/3rdparty/eigen/Eigen/src/QR/HouseholderQR.h434
-rw-r--r--src/3rdparty/eigen/Eigen/src/QR/HouseholderQR_LAPACKE.h68
-rw-r--r--src/3rdparty/eigen/Eigen/src/SVD/BDCSVD.h1366
-rw-r--r--src/3rdparty/eigen/Eigen/src/SVD/JacobiSVD.h812
-rw-r--r--src/3rdparty/eigen/Eigen/src/SVD/JacobiSVD_LAPACKE.h91
-rw-r--r--src/3rdparty/eigen/Eigen/src/SVD/SVDBase.h376
-rw-r--r--src/3rdparty/eigen/Eigen/src/SVD/UpperBidiagonalization.h414
-rw-r--r--src/3rdparty/eigen/Eigen/src/misc/Image.h82
-rw-r--r--src/3rdparty/eigen/Eigen/src/misc/Kernel.h79
-rw-r--r--src/3rdparty/eigen/Eigen/src/misc/RealSvd2x2.h55
-rw-r--r--src/3rdparty/eigen/Eigen/src/misc/blas.h440
-rw-r--r--src/3rdparty/eigen/Eigen/src/misc/lapack.h152
-rw-r--r--src/3rdparty/eigen/Eigen/src/misc/lapacke.h16292
-rw-r--r--src/3rdparty/eigen/Eigen/src/misc/lapacke_mangling.h17
-rw-r--r--src/3rdparty/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h358
-rw-r--r--src/3rdparty/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h696
-rw-r--r--src/3rdparty/eigen/Eigen/src/plugins/BlockMethods.h1442
-rw-r--r--src/3rdparty/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h115
-rw-r--r--src/3rdparty/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h177
-rw-r--r--src/3rdparty/eigen/Eigen/src/plugins/IndexedViewMethods.h262
-rw-r--r--src/3rdparty/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h152
-rw-r--r--src/3rdparty/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h95
-rw-r--r--src/3rdparty/eigen/Eigen/src/plugins/ReshapedMethods.h149
-rw-r--r--src/3rdparty/eigen/INSTALL35
-rw-r--r--src/3rdparty/eigen/README.md5
-rw-r--r--src/3rdparty/eigen/qt_attribution.json20
-rw-r--r--src/3rdparty/ffmpeg/qt_attribution.json55
-rw-r--r--src/3rdparty/pffft/COPYRIGHTS2
-rw-r--r--src/3rdparty/pffft/LICENSE45
-rw-r--r--src/3rdparty/pffft/README.md320
-rw-r--r--src/3rdparty/pffft/fftpack.c3111
-rw-r--r--src/3rdparty/pffft/fftpack.h799
-rw-r--r--src/3rdparty/pffft/pffft.c1885
-rw-r--r--src/3rdparty/pffft/pffft.h177
-rw-r--r--src/3rdparty/pffft/qt_attribution.json16
-rw-r--r--src/3rdparty/pffft/test_pffft.c463
-rw-r--r--src/3rdparty/resonance-audio/.gitignore19
-rw-r--r--src/3rdparty/resonance-audio/.travis.yml17
-rw-r--r--src/3rdparty/resonance-audio/AUTHORS10
-rw-r--r--src/3rdparty/resonance-audio/CMakeLists.txt109
-rw-r--r--src/3rdparty/resonance-audio/CODEOWNERS6
-rw-r--r--src/3rdparty/resonance-audio/CONTRIBUTING.md14
-rw-r--r--src/3rdparty/resonance-audio/COPYRIGHTS1
-rw-r--r--src/3rdparty/resonance-audio/LICENSE202
-rw-r--r--src/3rdparty/resonance-audio/README.md192
-rwxr-xr-xsrc/3rdparty/resonance-audio/build.sh151
-rw-r--r--src/3rdparty/resonance-audio/patches/0001-resonance_audio-fix-C-20-build.patch36
-rw-r--r--src/3rdparty/resonance-audio/platforms/CMakeLists.txt30
-rw-r--r--src/3rdparty/resonance-audio/platforms/common/room_effects_utils.cc327
-rw-r--r--src/3rdparty/resonance-audio/platforms/common/room_effects_utils.h83
-rw-r--r--src/3rdparty/resonance-audio/platforms/common/room_effects_utils_test.cc197
-rw-r--r--src/3rdparty/resonance-audio/platforms/common/room_properties.h123
-rw-r--r--src/3rdparty/resonance-audio/platforms/common/utils.cc59
-rw-r--r--src/3rdparty/resonance-audio/platforms/common/utils.h55
-rw-r--r--src/3rdparty/resonance-audio/platforms/common/utils_test.cc107
-rw-r--r--src/3rdparty/resonance-audio/qt_attribution.json18
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/CMakeLists.txt335
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder.cc80
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder.h71
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder_test.cc162
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec.h62
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec_impl.h295
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec_impl_test.cc354
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table.cc231
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table.h92
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table_test.cc240
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_spread_coefficients.h610
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator.cc147
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator.h89
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator_test.cc167
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator.cc117
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator.h61
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator_test.cc201
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator.cc308
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator.h69
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator_test.cc201
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter.cc52
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter.h35
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter_test.cc103
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/utils.h120
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/ambisonics/utils_test.cc65
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/api/binaural_surround_renderer.cc35
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/api/binaural_surround_renderer.h255
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/api/resonance_audio_api.cc30
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/api/resonance_audio_api.h416
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/aligned_allocator.h117
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/aligned_allocator_test.cc53
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer.cc74
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer.h222
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer_test.cc144
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/channel_view.cc50
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/channel_view.h138
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/channel_view_test.cc157
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/constants_and_types.h176
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/integral_types.h121
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/logging.h108
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/misc_math.cc94
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/misc_math.h385
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/misc_math_test.cc373
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/object_transform.h31
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/simd_macros.h65
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/simd_utils.cc1299
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/simd_utils.h296
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/simd_utils_test.cc711
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/source_parameters.h101
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle.cc78
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle.h87
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle_test.cc122
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/base/unique_ptr_wrapper.h33
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/config/global_config.h37
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/config/source_config.cc76
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/config/source_config.h32
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter.cc149
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter.h137
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter_test.cc303
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter.cc45
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter.h40
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter_test.cc80
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer.cc120
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer.h96
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer_test.cc230
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter.cc180
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter.h85
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter_test.cc197
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation.cc121
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation.h82
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation_test.cc132
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager.cc209
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager.h182
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager_test.cc260
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators.cc165
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators.h177
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators_test.cc146
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter.cc148
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter.h62
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter_test.cc104
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/gain.cc102
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/gain.h67
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer.cc115
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer.h96
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer_test.cc188
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor.cc94
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor.h74
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor_test.cc181
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/gain_test.cc132
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/mixer.cc56
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/mixer.h62
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/mixer_test.cc163
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter.cc59
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter.h57
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter_test.cc59
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir.cc152
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir.h88
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir_test.cc117
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/near_field_processor.cc97
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/near_field_processor.h75
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator.cc52
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator.h54
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator_test.cc139
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter.cc267
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter.h167
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter_test.cc761
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/reflection.h34
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor.cc177
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor.h128
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor_test.cc142
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/resampler.cc335
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/resampler.h135
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/resampler_test.cc325
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_compensator.cc214
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_compensator.h110
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_update_processor.cc184
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_update_processor.h113
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/sh_hrir_creator.cc72
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/sh_hrir_creator.h54
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room.cc61
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room.h44
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room_test.cc96
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb.cc350
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb.h173
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb_constants_and_tables.h6508
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb_test.cc324
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner.cc46
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner.h35
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner_test.cc88
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/utils.cc190
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/utils.h93
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/dsp/utils_test.cc194
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_listener.h57
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray.cc27
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray.h195
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray_test.cc243
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_source.h111
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_source_test.cc136
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel.cc128
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel.h79
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel_test.cc353
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60.cc155
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60.h38
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60_test.cc185
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer.cc188
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer.h112
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer_test.cc377
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/mesh.h40
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for.cc44
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for.h53
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for_test.cc65
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path.h36
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer.cc96
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer.h59
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer_test.cc193
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator.cc438
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator.h156
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator_test.cc317
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel.cc99
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel.h104
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel_test.cc300
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sampling.h126
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager.cc153
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager.h130
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager_test.cc202
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere.cc120
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere.h69
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere_test.cc267
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/test_util.cc231
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/test_util.h131
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_binaural_decoder_node.cc111
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_binaural_decoder_node.h88
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node.cc69
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node.h71
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node_test.cc150
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl.cc495
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl.h190
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl_test.cc202
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/buffered_source_node.cc46
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/buffered_source_node.h62
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/foa_rotator_node.cc67
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/foa_rotator_node.h54
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node.cc66
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node.h68
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node_test.cc246
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/gain_node.cc82
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/gain_node.h69
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/gain_node_test.cc138
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager.cc290
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager.h404
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager_config.h40
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/hoa_rotator_node.cc69
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/hoa_rotator_node.h55
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node.cc57
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node.h54
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node_test.cc112
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/mono_from_soundfield_node.cc45
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/mono_from_soundfield_node.h44
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node.cc117
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node.h69
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node_test.cc127
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node.cc101
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node.h59
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node_test.cc186
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/reflections_node.cc113
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/reflections_node.h78
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/resonance_audio_api_impl.cc586
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/resonance_audio_api_impl.h175
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/reverb_node.cc162
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/reverb_node.h99
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/source_graph_config.h43
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager.cc58
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager.h68
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager_test.cc91
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/stereo_mixing_panner_node.cc65
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/stereo_mixing_panner_node.h61
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/graph/system_settings.h189
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/node/audio_nodes_test.cc407
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/node/node.h258
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/node/node_test.cc330
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/node/processing_node.cc89
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/node/processing_node.h115
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/node/publisher_node.h51
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/node/sink_node.cc54
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/node/sink_node.h59
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/node/source_node.cc41
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/node/source_node.h68
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/node/subscriber_node.h48
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader.cc66
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader.h48
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader_test.cc53
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner.cc160
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner.h152
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner_test.cc241
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner.cc132
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner.h135
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner_test.cc294
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue.cc156
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue.h124
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue_test.cc215
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/ogg_vorbis_recorder.cc107
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/ogg_vorbis_recorder.h94
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion.cc505
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion.h421
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion_test.cc875
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/pseudoinverse.h45
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/pseudoinverse_test.cc87
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion.cc40
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion.h79
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion_test.cc80
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/semi_lockless_fifo.h232
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor.cc40
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor.h44
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor_test.cc42
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool.cc249
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool.h121
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool_test.cc185
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/test_util.cc190
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/test_util.h91
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/test_util_test.cc249
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/threadsafe_fifo.h258
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/vorbis_stream_encoder.cc174
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/vorbis_stream_encoder.h114
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/wav.cc53
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/wav.h66
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/wav_reader.cc214
-rw-r--r--src/3rdparty/resonance-audio/resonance_audio/utils/wav_reader.h103
-rw-r--r--src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/LICENSE157
-rwxr-xr-xsrc/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generate_hrtf_assets.py287
-rw-r--r--src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/README5
-rw-r--r--src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/hrtf_assets.cc1200
-rw-r--r--src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/hrtf_assets.h45
-rw-r--r--src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/hrtf_assets.iad8
-rw-r--r--src/CMakeLists.txt28
-rw-r--r--src/android/CMakeLists.txt6
-rw-r--r--src/android/jar/AndroidManifest.xml (renamed from src/plugins/android/jar/AndroidManifest.xml)0
-rw-r--r--src/android/jar/CMakeLists.txt32
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer.java751
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/multimedia/QtAudioDeviceManager.java361
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/multimedia/QtCamera2.java526
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/multimedia/QtCameraListener.java207
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/multimedia/QtExifDataHandler.java51
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/multimedia/QtMediaRecorderListener.java31
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/multimedia/QtMultimediaUtils.java148
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback.java37
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder.java89
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureListener.java24
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/multimedia/QtVideoDeviceManager.java247
-rw-r--r--src/gsttools/gsttools.pro104
-rw-r--r--src/gsttools/gstvideoconnector.c471
-rw-r--r--src/gsttools/gstvideoconnector_p.h98
-rw-r--r--src/gsttools/qgstappsrc.cpp253
-rw-r--r--src/gsttools/qgstappsrc_p.h121
-rw-r--r--src/gsttools/qgstbufferpoolinterface.cpp51
-rw-r--r--src/gsttools/qgstbufferpoolinterface_p.h117
-rw-r--r--src/gsttools/qgstcodecsinfo.cpp300
-rw-r--r--src/gsttools/qgstcodecsinfo_p.h96
-rw-r--r--src/gsttools/qgstreameraudioinputselector.cpp167
-rw-r--r--src/gsttools/qgstreameraudioinputselector_p.h88
-rw-r--r--src/gsttools/qgstreameraudioprobecontrol.cpp101
-rw-r--r--src/gsttools/qgstreameraudioprobecontrol_p.h90
-rw-r--r--src/gsttools/qgstreamerbufferprobe.cpp166
-rw-r--r--src/gsttools/qgstreamerbufferprobe_p.h97
-rw-r--r--src/gsttools/qgstreamerbushelper.cpp216
-rw-r--r--src/gsttools/qgstreamerbushelper_p.h104
-rw-r--r--src/gsttools/qgstreamermessage.cpp93
-rw-r--r--src/gsttools/qgstreamermessage_p.h84
-rw-r--r--src/gsttools/qgstreamerplayercontrol.cpp613
-rw-r--r--src/gsttools/qgstreamerplayercontrol_p.h145
-rw-r--r--src/gsttools/qgstreamerplayersession.cpp2016
-rw-r--r--src/gsttools/qgstreamerplayersession_p.h284
-rw-r--r--src/gsttools/qgstreamervideoinputdevicecontrol.cpp98
-rw-r--r--src/gsttools/qgstreamervideoinputdevicecontrol_p.h93
-rw-r--r--src/gsttools/qgstreamervideooverlay.cpp639
-rw-r--r--src/gsttools/qgstreamervideooverlay_p.h127
-rw-r--r--src/gsttools/qgstreamervideoprobecontrol.cpp129
-rw-r--r--src/gsttools/qgstreamervideoprobecontrol_p.h100
-rw-r--r--src/gsttools/qgstreamervideorenderer.cpp128
-rw-r--r--src/gsttools/qgstreamervideorenderer_p.h94
-rw-r--r--src/gsttools/qgstreamervideorendererinterface.cpp44
-rw-r--r--src/gsttools/qgstreamervideorendererinterface_p.h85
-rw-r--r--src/gsttools/qgstreamervideowidget.cpp280
-rw-r--r--src/gsttools/qgstreamervideowidget_p.h128
-rw-r--r--src/gsttools/qgstreamervideowindow.cpp179
-rw-r--r--src/gsttools/qgstreamervideowindow_p.h127
-rw-r--r--src/gsttools/qgsttools_global_p.h70
-rw-r--r--src/gsttools/qgstutils.cpp1746
-rw-r--r--src/gsttools/qgstutils_p.h176
-rw-r--r--src/gsttools/qgstvideobuffer.cpp159
-rw-r--r--src/gsttools/qgstvideobuffer_p.h107
-rw-r--r--src/gsttools/qgstvideorendererplugin.cpp51
-rw-r--r--src/gsttools/qgstvideorendererplugin_p.h110
-rw-r--r--src/gsttools/qgstvideorenderersink.cpp810
-rw-r--r--src/gsttools/qgstvideorenderersink_p.h199
-rw-r--r--src/gsttools/qvideosurfacegstsink.cpp712
-rw-r--r--src/gsttools/qvideosurfacegstsink_p.h192
-rw-r--r--src/imports/imports.pro4
-rw-r--r--src/imports/multimedia/Video.qml545
-rw-r--r--src/imports/multimedia/multimedia.cpp180
-rw-r--r--src/imports/multimedia/multimedia.pro44
-rw-r--r--src/imports/multimedia/plugins.qmltypes2194
-rw-r--r--src/imports/multimedia/qdeclarativeaudio.cpp1736
-rw-r--r--src/imports/multimedia/qdeclarativeaudio_p.h322
-rw-r--r--src/imports/multimedia/qdeclarativecamera.cpp999
-rw-r--r--src/imports/multimedia/qdeclarativecamera_p.h366
-rw-r--r--src/imports/multimedia/qdeclarativecameracapture.cpp384
-rw-r--r--src/imports/multimedia/qdeclarativecameracapture_p.h128
-rw-r--r--src/imports/multimedia/qdeclarativecameraexposure.cpp464
-rw-r--r--src/imports/multimedia/qdeclarativecameraexposure_p.h177
-rw-r--r--src/imports/multimedia/qdeclarativecameraflash.cpp198
-rw-r--r--src/imports/multimedia/qdeclarativecameraflash_p.h111
-rw-r--r--src/imports/multimedia/qdeclarativecamerafocus.cpp413
-rw-r--r--src/imports/multimedia/qdeclarativecamerafocus_p.h157
-rw-r--r--src/imports/multimedia/qdeclarativecameraimageprocessing.cpp361
-rw-r--r--src/imports/multimedia/qdeclarativecameraimageprocessing_p.h163
-rw-r--r--src/imports/multimedia/qdeclarativecamerapreviewprovider.cpp95
-rw-r--r--src/imports/multimedia/qdeclarativecamerapreviewprovider_p.h70
-rw-r--r--src/imports/multimedia/qdeclarativecamerarecorder.cpp592
-rw-r--r--src/imports/multimedia/qdeclarativecamerarecorder_p.h226
-rw-r--r--src/imports/multimedia/qdeclarativecameraviewfinder.cpp125
-rw-r--r--src/imports/multimedia/qdeclarativecameraviewfinder_p.h97
-rw-r--r--src/imports/multimedia/qdeclarativemediametadata_p.h452
-rw-r--r--src/imports/multimedia/qdeclarativemultimediaglobal.cpp239
-rw-r--r--src/imports/multimedia/qdeclarativemultimediaglobal_p.h96
-rw-r--r--src/imports/multimedia/qdeclarativeplaylist.cpp660
-rw-r--r--src/imports/multimedia/qdeclarativeplaylist_p.h209
-rw-r--r--src/imports/multimedia/qdeclarativetorch.cpp180
-rw-r--r--src/imports/multimedia/qdeclarativetorch_p.h98
-rw-r--r--src/imports/multimedia/qmldir5
-rw-r--r--src/multimedia/CMakeLists.txt374
-rw-r--r--src/multimedia/alsa/alsa.json3
-rw-r--r--src/multimedia/alsa/qalsaaudiodevice.cpp71
-rw-r--r--src/multimedia/alsa/qalsaaudiodevice_p.h49
-rw-r--r--src/multimedia/alsa/qalsaaudiosink.cpp698
-rw-r--r--src/multimedia/alsa/qalsaaudiosink_p.h121
-rw-r--r--src/multimedia/alsa/qalsaaudiosource.cpp770
-rw-r--r--src/multimedia/alsa/qalsaaudiosource_p.h142
-rw-r--r--src/multimedia/alsa/qalsamediadevices.cpp130
-rw-r--r--src/multimedia/alsa/qalsamediadevices_p.h41
-rw-r--r--src/multimedia/android/qandroidaudiodevice.cpp39
-rw-r--r--src/multimedia/android/qandroidaudiodevice_p.h37
-rw-r--r--src/multimedia/android/qandroidaudiosink.cpp614
-rw-r--r--src/multimedia/android/qandroidaudiosink_p.h127
-rw-r--r--src/multimedia/android/qandroidaudiosource.cpp470
-rw-r--r--src/multimedia/android/qandroidaudiosource_p.h101
-rw-r--r--src/multimedia/android/qandroidmediadevices.cpp113
-rw-r--r--src/multimedia/android/qandroidmediadevices_p.h42
-rw-r--r--src/multimedia/android/qopenslesengine.cpp378
-rw-r--r--src/multimedia/android/qopenslesengine_p.h65
-rw-r--r--src/multimedia/audio/audio.pri50
-rw-r--r--src/multimedia/audio/qaudio.cpp383
-rw-r--r--src/multimedia/audio/qaudio.h88
-rw-r--r--src/multimedia/audio/qaudiobuffer.cpp511
-rw-r--r--src/multimedia/audio/qaudiobuffer.h230
-rw-r--r--src/multimedia/audio/qaudiobuffer_p.h96
-rw-r--r--src/multimedia/audio/qaudiobufferinput.cpp162
-rw-r--r--src/multimedia/audio/qaudiobufferinput.h44
-rw-r--r--src/multimedia/audio/qaudiobufferoutput.cpp78
-rw-r--r--src/multimedia/audio/qaudiobufferoutput.h37
-rw-r--r--src/multimedia/audio/qaudiobufferoutput_p.h42
-rw-r--r--src/multimedia/audio/qaudiodecoder.cpp345
-rw-r--r--src/multimedia/audio/qaudiodecoder.h85
-rw-r--r--src/multimedia/audio/qaudiodecoder_p.h40
-rw-r--r--src/multimedia/audio/qaudiodevice.cpp373
-rw-r--r--src/multimedia/audio/qaudiodevice.h84
-rw-r--r--src/multimedia/audio/qaudiodevice_p.h62
-rw-r--r--src/multimedia/audio/qaudiodevicefactory.cpp259
-rw-r--r--src/multimedia/audio/qaudiodevicefactory_p.h91
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo.cpp476
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo.h109
-rw-r--r--src/multimedia/audio/qaudioformat.cpp550
-rw-r--r--src/multimedia/audio/qaudioformat.h214
-rw-r--r--src/multimedia/audio/qaudiohelpers.cpp137
-rw-r--r--src/multimedia/audio/qaudiohelpers_p.h41
-rw-r--r--src/multimedia/audio/qaudioinput.cpp461
-rw-r--r--src/multimedia/audio/qaudioinput.h113
-rw-r--r--src/multimedia/audio/qaudiooutput.cpp490
-rw-r--r--src/multimedia/audio/qaudiooutput.h117
-rw-r--r--src/multimedia/audio/qaudioprobe.cpp205
-rw-r--r--src/multimedia/audio/qaudioprobe.h74
-rw-r--r--src/multimedia/audio/qaudiosink.cpp339
-rw-r--r--src/multimedia/audio/qaudiosink.h74
-rw-r--r--src/multimedia/audio/qaudiosource.cpp369
-rw-r--r--src/multimedia/audio/qaudiosource.h72
-rw-r--r--src/multimedia/audio/qaudiostatemachine.cpp150
-rw-r--r--src/multimedia/audio/qaudiostatemachine_p.h149
-rw-r--r--src/multimedia/audio/qaudiostatemachineutils_p.h96
-rw-r--r--src/multimedia/audio/qaudiosystem.cpp379
-rw-r--r--src/multimedia/audio/qaudiosystem.h138
-rw-r--r--src/multimedia/audio/qaudiosystem_p.h96
-rw-r--r--src/multimedia/audio/qaudiosystemplugin.cpp138
-rw-r--r--src/multimedia/audio/qaudiosystemplugin.h86
-rw-r--r--src/multimedia/audio/qaudiosystempluginext_p.h71
-rw-r--r--src/multimedia/audio/qsamplecache_p.cpp145
-rw-r--r--src/multimedia/audio/qsamplecache_p.h47
-rw-r--r--src/multimedia/audio/qsound.cpp244
-rw-r--r--src/multimedia/audio/qsound.h85
-rw-r--r--src/multimedia/audio/qsoundeffect.cpp575
-rw-r--r--src/multimedia/audio/qsoundeffect.h65
-rw-r--r--src/multimedia/audio/qsoundeffect_pulse_p.cpp1214
-rw-r--r--src/multimedia/audio/qsoundeffect_pulse_p.h188
-rw-r--r--src/multimedia/audio/qsoundeffect_qaudio_p.cpp457
-rw-r--r--src/multimedia/audio/qsoundeffect_qaudio_p.h151
-rw-r--r--src/multimedia/audio/qtaudio.cpp245
-rw-r--r--src/multimedia/audio/qtaudio.h18
-rw-r--r--src/multimedia/audio/qwavedecoder.cpp507
-rw-r--r--src/multimedia/audio/qwavedecoder.h115
-rw-r--r--src/multimedia/audio/qwavedecoder_p.cpp312
-rw-r--r--src/multimedia/audio/qwavedecoder_p.h133
-rw-r--r--src/multimedia/camera/camera.pri22
-rw-r--r--src/multimedia/camera/qcamera.cpp1789
-rw-r--r--src/multimedia/camera/qcamera.h426
-rw-r--r--src/multimedia/camera/qcamera_p.h130
-rw-r--r--src/multimedia/camera/qcameradevice.cpp470
-rw-r--r--src/multimedia/camera/qcameradevice.h104
-rw-r--r--src/multimedia/camera/qcameradevice_p.h75
-rw-r--r--src/multimedia/camera/qcameraexposure.cpp707
-rw-r--r--src/multimedia/camera/qcameraexposure.h195
-rw-r--r--src/multimedia/camera/qcamerafocus.cpp614
-rw-r--r--src/multimedia/camera/qcamerafocus.h177
-rw-r--r--src/multimedia/camera/qcameraimagecapture.cpp651
-rw-r--r--src/multimedia/camera/qcameraimagecapture.h161
-rw-r--r--src/multimedia/camera/qcameraimageprocessing.cpp401
-rw-r--r--src/multimedia/camera/qcameraimageprocessing.h139
-rw-r--r--src/multimedia/camera/qcamerainfo.cpp287
-rw-r--r--src/multimedia/camera/qcamerainfo.h84
-rw-r--r--src/multimedia/camera/qcameraviewfindersettings.cpp331
-rw-r--r--src/multimedia/camera/qcameraviewfindersettings.h104
-rw-r--r--src/multimedia/camera/qimagecapture.cpp548
-rw-r--r--src/multimedia/camera/qimagecapture.h135
-rw-r--r--src/multimedia/compat/removed_api.cpp16
-rw-r--r--src/multimedia/configure.cmake212
-rw-r--r--src/multimedia/configure.json300
-rw-r--r--src/multimedia/controls/controls.pri80
-rw-r--r--src/multimedia/controls/qaudiodecodercontrol.cpp267
-rw-r--r--src/multimedia/controls/qaudiodecodercontrol.h103
-rw-r--r--src/multimedia/controls/qaudioencodersettingscontrol.cpp140
-rw-r--r--src/multimedia/controls/qaudioencodersettingscontrol.h84
-rw-r--r--src/multimedia/controls/qaudioinputselectorcontrol.cpp131
-rw-r--r--src/multimedia/controls/qaudioinputselectorcontrol.h80
-rw-r--r--src/multimedia/controls/qaudiooutputselectorcontrol.cpp131
-rw-r--r--src/multimedia/controls/qaudiooutputselectorcontrol.h80
-rw-r--r--src/multimedia/controls/qaudiorolecontrol.cpp118
-rw-r--r--src/multimedia/controls/qaudiorolecontrol.h75
-rw-r--r--src/multimedia/controls/qcameracapturebufferformatcontrol.cpp113
-rw-r--r--src/multimedia/controls/qcameracapturebufferformatcontrol.h75
-rw-r--r--src/multimedia/controls/qcameracapturedestinationcontrol.cpp115
-rw-r--r--src/multimedia/controls/qcameracapturedestinationcontrol.h75
-rw-r--r--src/multimedia/controls/qcameracontrol.cpp205
-rw-r--r--src/multimedia/controls/qcameracontrol.h96
-rw-r--r--src/multimedia/controls/qcameraexposurecontrol.cpp207
-rw-r--r--src/multimedia/controls/qcameraexposurecontrol.h104
-rw-r--r--src/multimedia/controls/qcamerafeedbackcontrol.cpp182
-rw-r--r--src/multimedia/controls/qcamerafeedbackcontrol.h96
-rw-r--r--src/multimedia/controls/qcameraflashcontrol.cpp134
-rw-r--r--src/multimedia/controls/qcameraflashcontrol.h81
-rw-r--r--src/multimedia/controls/qcamerafocuscontrol.cpp198
-rw-r--r--src/multimedia/controls/qcamerafocuscontrol.h90
-rw-r--r--src/multimedia/controls/qcameraimagecapturecontrol.cpp195
-rw-r--r--src/multimedia/controls/qcameraimagecapturecontrol.h93
-rw-r--r--src/multimedia/controls/qcameraimageprocessingcontrol.cpp189
-rw-r--r--src/multimedia/controls/qcameraimageprocessingcontrol.h98
-rw-r--r--src/multimedia/controls/qcamerainfocontrol.cpp103
-rw-r--r--src/multimedia/controls/qcamerainfocontrol.h69
-rw-r--r--src/multimedia/controls/qcameralockscontrol.cpp128
-rw-r--r--src/multimedia/controls/qcameralockscontrol.h80
-rw-r--r--src/multimedia/controls/qcameraviewfindersettingscontrol.cpp206
-rw-r--r--src/multimedia/controls/qcameraviewfindersettingscontrol.h103
-rw-r--r--src/multimedia/controls/qcamerazoomcontrol.cpp188
-rw-r--r--src/multimedia/controls/qcamerazoomcontrol.h86
-rw-r--r--src/multimedia/controls/qcustomaudiorolecontrol.cpp119
-rw-r--r--src/multimedia/controls/qcustomaudiorolecontrol.h75
-rw-r--r--src/multimedia/controls/qimageencodercontrol.cpp137
-rw-r--r--src/multimedia/controls/qimageencodercontrol.h82
-rw-r--r--src/multimedia/controls/qmediaaudioprobecontrol.cpp103
-rw-r--r--src/multimedia/controls/qmediaaudioprobecontrol.h68
-rw-r--r--src/multimedia/controls/qmediaavailabilitycontrol.cpp109
-rw-r--r--src/multimedia/controls/qmediaavailabilitycontrol.h73
-rw-r--r--src/multimedia/controls/qmediacontainercontrol.cpp122
-rw-r--r--src/multimedia/controls/qmediacontainercontrol.h74
-rw-r--r--src/multimedia/controls/qmediagaplessplaybackcontrol.cpp157
-rw-r--r--src/multimedia/controls/qmediagaplessplaybackcontrol.h77
-rw-r--r--src/multimedia/controls/qmediaplayercontrol.cpp386
-rw-r--r--src/multimedia/controls/qmediaplayercontrol.h123
-rw-r--r--src/multimedia/controls/qmediaplaylistcontrol.cpp206
-rw-r--r--src/multimedia/controls/qmediaplaylistcontrol_p.h102
-rw-r--r--src/multimedia/controls/qmediaplaylistsourcecontrol.cpp126
-rw-r--r--src/multimedia/controls/qmediaplaylistsourcecontrol_p.h85
-rw-r--r--src/multimedia/controls/qmediarecordercontrol.cpp223
-rw-r--r--src/multimedia/controls/qmediarecordercontrol.h100
-rw-r--r--src/multimedia/controls/qmediastreamscontrol.cpp161
-rw-r--r--src/multimedia/controls/qmediastreamscontrol.h89
-rw-r--r--src/multimedia/controls/qmediavideoprobecontrol.cpp102
-rw-r--r--src/multimedia/controls/qmediavideoprobecontrol.h70
-rw-r--r--src/multimedia/controls/qmetadatareadercontrol.cpp149
-rw-r--r--src/multimedia/controls/qmetadatareadercontrol.h81
-rw-r--r--src/multimedia/controls/qmetadatawritercontrol.cpp169
-rw-r--r--src/multimedia/controls/qmetadatawritercontrol.h84
-rw-r--r--src/multimedia/controls/qvideodeviceselectorcontrol.cpp143
-rw-r--r--src/multimedia/controls/qvideodeviceselectorcontrol.h82
-rw-r--r--src/multimedia/controls/qvideoencodersettingscontrol.cpp161
-rw-r--r--src/multimedia/controls/qvideoencodersettingscontrol.h88
-rw-r--r--src/multimedia/controls/qvideorenderercontrol.cpp109
-rw-r--r--src/multimedia/controls/qvideorenderercontrol.h68
-rw-r--r--src/multimedia/controls/qvideowindowcontrol.cpp259
-rw-r--r--src/multimedia/controls/qvideowindowcontrol.h106
-rw-r--r--src/multimedia/darwin/qcoreaudiosessionmanager.mm437
-rw-r--r--src/multimedia/darwin/qcoreaudiosessionmanager_p.h95
-rw-r--r--src/multimedia/darwin/qcoreaudioutils.mm344
-rw-r--r--src/multimedia/darwin/qcoreaudioutils_p.h72
-rw-r--r--src/multimedia/darwin/qdarwinaudiodevice.mm108
-rw-r--r--src/multimedia/darwin/qdarwinaudiodevice_p.h52
-rw-r--r--src/multimedia/darwin/qdarwinaudiosink.mm609
-rw-r--r--src/multimedia/darwin/qdarwinaudiosink_p.h170
-rw-r--r--src/multimedia/darwin/qdarwinaudiosource.mm942
-rw-r--r--src/multimedia/darwin/qdarwinaudiosource_p.h244
-rw-r--r--src/multimedia/darwin/qdarwinmediadevices.mm269
-rw-r--r--src/multimedia/darwin/qdarwinmediadevices_p.h49
-rw-r--r--src/multimedia/darwin/qmacosaudiodatautils_p.h112
-rw-r--r--src/multimedia/doc/qtmultimedia.qdocconf36
-rw-r--r--src/multimedia/doc/snippets/CMakeLists.txt15
-rw-r--r--src/multimedia/doc/snippets/doc_src_qtmultimedia.cpp53
-rw-r--r--src/multimedia/doc/snippets/doc_src_qtmultimedia.pro3
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/audio.cpp118
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/audiorecorder.cpp211
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/camera.cpp216
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/devices.cpp38
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/media.cpp318
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/multimedia-snippets.pro26
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/multiple-videooutputs.qml50
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/qaudioprobe.cpp51
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp64
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/qtvideosink.qml52
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/soundeffect.qml44
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/video.cpp136
-rw-r--r--src/multimedia/doc/snippets/snippets.pro3
-rw-r--r--src/multimedia/doc/src/audiooverview.qdoc158
-rw-r--r--src/multimedia/doc/src/cameraoverview.qdoc309
-rw-r--r--src/multimedia/doc/src/changes.qdoc140
-rw-r--r--src/multimedia/doc/src/examples/video-qml-paint-rate.qdocinc8
-rw-r--r--src/multimedia/doc/src/images/Zoom.gifbin0 -> 706673 bytes
-rw-r--r--src/multimedia/doc/src/images/camera_correctionAngle_90.pngbin0 -> 48562 bytes
-rw-r--r--src/multimedia/doc/src/images/how-focus-works.gifbin0 -> 289878 bytes
-rw-r--r--src/multimedia/doc/src/images/image_processing.pngbin0 -> 215435 bytes
-rw-r--r--src/multimedia/doc/src/images/noun_Media_166644.svg64
-rw-r--r--src/multimedia/doc/src/images/qS1FmgPVL.jpgbin0 -> 23184 bytes
-rw-r--r--src/multimedia/doc/src/images/sound-wave-small.jpgbin0 -> 37707 bytes
-rw-r--r--src/multimedia/doc/src/multimedia-overview.qdoc142
-rw-r--r--src/multimedia/doc/src/multimedia.qdoc186
-rw-r--r--src/multimedia/doc/src/multimediabackend.qdoc139
-rw-r--r--src/multimedia/doc/src/platform-notes-apple.qdoc19
-rw-r--r--src/multimedia/doc/src/platform-notes-gstreamer-on-android.qdoc59
-rw-r--r--src/multimedia/doc/src/platform-notes-ios.qdoc43
-rw-r--r--src/multimedia/doc/src/platform-notes-wasm.qdoc35
-rw-r--r--src/multimedia/doc/src/platform-notes-windows.qdoc62
-rw-r--r--src/multimedia/doc/src/plugins/qml-multimedia.qdoc216
-rw-r--r--src/multimedia/doc/src/qm-external-pages.qdoc232
-rw-r--r--src/multimedia/doc/src/qt6-changes.qdoc145
-rw-r--r--src/multimedia/doc/src/qtaudioengine.qdoc59
-rw-r--r--src/multimedia/doc/src/qtmultimedia-building-from-source.qdoc94
-rw-r--r--src/multimedia/doc/src/qtmultimedia-cpp.qdoc48
-rw-r--r--src/multimedia/doc/src/qtmultimedia-examples.qdoc38
-rw-r--r--src/multimedia/doc/src/qtmultimedia-index.qdoc328
-rw-r--r--src/multimedia/doc/src/qtmultimedia-qml-types.qdoc45
-rw-r--r--src/multimedia/doc/src/qtmultimedia5.qdoc66
-rw-r--r--src/multimedia/doc/src/videooverview.qdoc127
-rw-r--r--src/multimedia/multimedia.pro98
-rw-r--r--src/multimedia/platform/qgstreamer_platformspecificinterface.cpp27
-rw-r--r--src/multimedia/platform/qgstreamer_platformspecificinterface_p.h46
-rw-r--r--src/multimedia/platform/qplatformaudiobufferinput.cpp10
-rw-r--r--src/multimedia/platform/qplatformaudiobufferinput_p.h56
-rw-r--r--src/multimedia/platform/qplatformaudiodecoder.cpp81
-rw-r--r--src/multimedia/platform/qplatformaudiodecoder_p.h92
-rw-r--r--src/multimedia/platform/qplatformaudioinput_p.h46
-rw-r--r--src/multimedia/platform/qplatformaudiooutput_p.h44
-rw-r--r--src/multimedia/platform/qplatformaudioresampler_p.h33
-rw-r--r--src/multimedia/platform/qplatformcamera.cpp233
-rw-r--r--src/multimedia/platform/qplatformcamera_p.h165
-rw-r--r--src/multimedia/platform/qplatformcapturablewindows_p.h44
-rw-r--r--src/multimedia/platform/qplatformimagecapture.cpp27
-rw-r--r--src/multimedia/platform/qplatformimagecapture_p.h97
-rw-r--r--src/multimedia/platform/qplatformmediacapture.cpp37
-rw-r--r--src/multimedia/platform/qplatformmediacapture_p.h89
-rw-r--r--src/multimedia/platform/qplatformmediadevices.cpp114
-rw-r--r--src/multimedia/platform/qplatformmediadevices_p.h63
-rw-r--r--src/multimedia/platform/qplatformmediaformatinfo.cpp76
-rw-r--r--src/multimedia/platform/qplatformmediaformatinfo_p.h50
-rw-r--r--src/multimedia/platform/qplatformmediaintegration.cpp222
-rw-r--r--src/multimedia/platform/qplatformmediaintegration_p.h139
-rw-r--r--src/multimedia/platform/qplatformmediaplayer.cpp40
-rw-r--r--src/multimedia/platform/qplatformmediaplayer_p.h170
-rw-r--r--src/multimedia/platform/qplatformmediaplugin.cpp14
-rw-r--r--src/multimedia/platform/qplatformmediaplugin_p.h42
-rw-r--r--src/multimedia/platform/qplatformmediarecorder.cpp75
-rw-r--r--src/multimedia/platform/qplatformmediarecorder_p.h159
-rw-r--r--src/multimedia/platform/qplatformsurfacecapture.cpp83
-rw-r--r--src/multimedia/platform/qplatformsurfacecapture_p.h87
-rw-r--r--src/multimedia/platform/qplatformvideodevices.cpp12
-rw-r--r--src/multimedia/platform/qplatformvideodevices_p.h46
-rw-r--r--src/multimedia/platform/qplatformvideoframeinput.cpp10
-rw-r--r--src/multimedia/platform/qplatformvideoframeinput_p.h55
-rw-r--r--src/multimedia/platform/qplatformvideosink.cpp78
-rw-r--r--src/multimedia/platform/qplatformvideosink_p.h84
-rw-r--r--src/multimedia/platform/qplatformvideosource.cpp15
-rw-r--r--src/multimedia/platform/qplatformvideosource_p.h58
-rw-r--r--src/multimedia/playback/playback.pri24
-rw-r--r--src/multimedia/playback/qmediacontent.cpp249
-rw-r--r--src/multimedia/playback/qmediacontent.h81
-rw-r--r--src/multimedia/playback/qmedianetworkplaylistprovider.cpp281
-rw-r--r--src/multimedia/playback/qmedianetworkplaylistprovider_p.h96
-rw-r--r--src/multimedia/playback/qmediaplayer.cpp1866
-rw-r--r--src/multimedia/playback/qmediaplayer.h238
-rw-r--r--src/multimedia/playback/qmediaplayer_p.h90
-rw-r--r--src/multimedia/playback/qmediaplaylist.cpp824
-rw-r--r--src/multimedia/playback/qmediaplaylist.h148
-rw-r--r--src/multimedia/playback/qmediaplaylist_p.h173
-rw-r--r--src/multimedia/playback/qmediaplaylistioplugin.cpp188
-rw-r--r--src/multimedia/playback/qmediaplaylistioplugin_p.h125
-rw-r--r--src/multimedia/playback/qmediaplaylistnavigator.cpp544
-rw-r--r--src/multimedia/playback/qmediaplaylistnavigator_p.h118
-rw-r--r--src/multimedia/playback/qmediaplaylistprovider.cpp321
-rw-r--r--src/multimedia/playback/qmediaplaylistprovider_p.h122
-rw-r--r--src/multimedia/playback/qplaylistfileparser.cpp632
-rw-r--r--src/multimedia/playback/qplaylistfileparser_p.h122
-rw-r--r--src/multimedia/pulseaudio/pulseaudio.json3
-rw-r--r--src/multimedia/pulseaudio/qaudioengine_pulse.cpp508
-rw-r--r--src/multimedia/pulseaudio/qaudioengine_pulse_p.h93
-rw-r--r--src/multimedia/pulseaudio/qpulseaudiodevice.cpp46
-rw-r--r--src/multimedia/pulseaudio/qpulseaudiodevice_p.h41
-rw-r--r--src/multimedia/pulseaudio/qpulseaudiomediadevices.cpp55
-rw-r--r--src/multimedia/pulseaudio/qpulseaudiomediadevices_p.h45
-rw-r--r--src/multimedia/pulseaudio/qpulseaudiosink.cpp749
-rw-r--r--src/multimedia/pulseaudio/qpulseaudiosink_p.h136
-rw-r--r--src/multimedia/pulseaudio/qpulseaudiosource.cpp566
-rw-r--r--src/multimedia/pulseaudio/qpulseaudiosource_p.h116
-rw-r--r--src/multimedia/pulseaudio/qpulsehelpers.cpp284
-rw-r--r--src/multimedia/pulseaudio/qpulsehelpers_p.h55
-rw-r--r--src/multimedia/qerrorinfo_p.h57
-rw-r--r--src/multimedia/qmaybe_p.h96
-rw-r--r--src/multimedia/qmediabindableinterface.cpp82
-rw-r--r--src/multimedia/qmediabindableinterface.h69
-rw-r--r--src/multimedia/qmediacontrol.cpp136
-rw-r--r--src/multimedia/qmediacontrol.h79
-rw-r--r--src/multimedia/qmediacontrol_p.h72
-rw-r--r--src/multimedia/qmediadevices.cpp288
-rw-r--r--src/multimedia/qmediadevices.h56
-rw-r--r--src/multimedia/qmediaenumdebug.h40
-rw-r--r--src/multimedia/qmediaformat.cpp883
-rw-r--r--src/multimedia/qmediaformat.h149
-rw-r--r--src/multimedia/qmediaframeinput.cpp43
-rw-r--r--src/multimedia/qmediaframeinput_p.h74
-rw-r--r--src/multimedia/qmediainputencoderinterface_p.h31
-rw-r--r--src/multimedia/qmediametadata.cpp608
-rw-r--r--src/multimedia/qmediametadata.h351
-rw-r--r--src/multimedia/qmediaobject.cpp427
-rw-r--r--src/multimedia/qmediaobject.h108
-rw-r--r--src/multimedia/qmediaobject_p.h94
-rw-r--r--src/multimedia/qmediapluginloader.cpp186
-rw-r--r--src/multimedia/qmediapluginloader_p.h92
-rw-r--r--src/multimedia/qmediaresourcepolicy_p.cpp114
-rw-r--r--src/multimedia/qmediaresourcepolicy_p.h78
-rw-r--r--src/multimedia/qmediaresourcepolicyplugin_p.cpp53
-rw-r--r--src/multimedia/qmediaresourcepolicyplugin_p.h81
-rw-r--r--src/multimedia/qmediaresourceset_p.cpp54
-rw-r--r--src/multimedia/qmediaresourceset_p.h88
-rw-r--r--src/multimedia/qmediaservice.cpp143
-rw-r--r--src/multimedia/qmediaservice.h85
-rw-r--r--src/multimedia/qmediaservice_p.h73
-rw-r--r--src/multimedia/qmediaserviceprovider.cpp1004
-rw-r--r--src/multimedia/qmediaserviceprovider_p.h95
-rw-r--r--src/multimedia/qmediaserviceproviderplugin.h245
-rw-r--r--src/multimedia/qmediastoragelocation.cpp161
-rw-r--r--src/multimedia/qmediastoragelocation_p.h70
-rw-r--r--src/multimedia/qmediatimerange.cpp321
-rw-r--r--src/multimedia/qmediatimerange.h158
-rw-r--r--src/multimedia/qmultimedia.cpp116
-rw-r--r--src/multimedia/qmultimedia.h96
-rw-r--r--src/multimedia/qmultimediautils.cpp135
-rw-r--r--src/multimedia/qmultimediautils_p.h82
-rw-r--r--src/multimedia/qnx/qqnxaudiodevice.cpp85
-rw-r--r--src/multimedia/qnx/qqnxaudiodevice_p.h35
-rw-r--r--src/multimedia/qnx/qqnxaudiosink.cpp516
-rw-r--r--src/multimedia/qnx/qqnxaudiosink_p.h119
-rw-r--r--src/multimedia/qnx/qqnxaudiosource.cpp376
-rw-r--r--src/multimedia/qnx/qqnxaudiosource_p.h113
-rw-r--r--src/multimedia/qnx/qqnxaudioutils.cpp148
-rw-r--r--src/multimedia/qnx/qqnxaudioutils_p.h51
-rw-r--r--src/multimedia/qnx/qqnxmediadevices.cpp70
-rw-r--r--src/multimedia/qnx/qqnxmediadevices_p.h39
-rw-r--r--src/multimedia/qsymbolsresolveutils.cpp79
-rw-r--r--src/multimedia/qsymbolsresolveutils_p.h178
-rw-r--r--src/multimedia/qt_cmdline.cmake8
-rw-r--r--src/multimedia/qtmultimediaglobal.h56
-rw-r--r--src/multimedia/qtmultimediaglobal_p.h40
-rw-r--r--src/multimedia/recording/qaudiorecorder.cpp248
-rw-r--r--src/multimedia/recording/qaudiorecorder.h88
-rw-r--r--src/multimedia/recording/qcapturablewindow.cpp156
-rw-r--r--src/multimedia/recording/qcapturablewindow.h66
-rw-r--r--src/multimedia/recording/qcapturablewindow_p.h41
-rw-r--r--src/multimedia/recording/qmediacapturesession.cpp688
-rw-r--r--src/multimedia/recording/qmediacapturesession.h106
-rw-r--r--src/multimedia/recording/qmediacapturesession_p.h53
-rw-r--r--src/multimedia/recording/qmediaencodersettings.cpp952
-rw-r--r--src/multimedia/recording/qmediaencodersettings.h180
-rw-r--r--src/multimedia/recording/qmediarecorder.cpp1346
-rw-r--r--src/multimedia/recording/qmediarecorder.h249
-rw-r--r--src/multimedia/recording/qmediarecorder_p.h99
-rw-r--r--src/multimedia/recording/qscreencapture-limitations.qdocinc25
-rw-r--r--src/multimedia/recording/qscreencapture.cpp261
-rw-r--r--src/multimedia/recording/qscreencapture.h72
-rw-r--r--src/multimedia/recording/qvideoframeinput.cpp156
-rw-r--r--src/multimedia/recording/qvideoframeinput.h44
-rw-r--r--src/multimedia/recording/qwindowcapture.cpp268
-rw-r--r--src/multimedia/recording/qwindowcapture.h71
-rw-r--r--src/multimedia/recording/recording.pri14
-rw-r--r--src/multimedia/shaders/abgr.frag19
-rw-r--r--src/multimedia/shaders/argb.frag19
-rw-r--r--src/multimedia/shaders/ayuv.frag25
-rw-r--r--src/multimedia/shaders/bgra.frag19
-rw-r--r--src/multimedia/shaders/colorconvert.glsl19
-rw-r--r--src/multimedia/shaders/colortransfer.glsl118
-rwxr-xr-xsrc/multimedia/shaders/compile.bat16
-rw-r--r--src/multimedia/shaders/externalsampler.frag14
-rw-r--r--src/multimedia/shaders/externalsampler.vert16
-rw-r--r--src/multimedia/shaders/externalsampler_gles.frag28
-rw-r--r--src/multimedia/shaders/hdrtonemapper.glsl38
-rw-r--r--src/multimedia/shaders/imc2.frag29
-rw-r--r--src/multimedia/shaders/imc4.frag29
-rw-r--r--src/multimedia/shaders/nv12.frag27
-rw-r--r--src/multimedia/shaders/nv12_bt2020_hlg.frag42
-rw-r--r--src/multimedia/shaders/nv12_bt2020_pq.frag48
-rw-r--r--src/multimedia/shaders/nv21.frag27
-rw-r--r--src/multimedia/shaders/rectsampler.vert16
-rw-r--r--src/multimedia/shaders/rectsampler_bgra.frag19
-rw-r--r--src/multimedia/shaders/rgba.frag19
-rw-r--r--src/multimedia/shaders/uniformbuffer.glsl11
-rw-r--r--src/multimedia/shaders/uyvy.frag27
-rw-r--r--src/multimedia/shaders/vertex.vert16
-rw-r--r--src/multimedia/shaders/y.frag25
-rw-r--r--src/multimedia/shaders/yuv_triplanar.frag29
-rw-r--r--src/multimedia/shaders/yuv_triplanar_p10.frag29
-rw-r--r--src/multimedia/shaders/yuyv.frag27
-rw-r--r--src/multimedia/shaders/yvu_triplanar.frag29
-rw-r--r--src/multimedia/video/qabstractvideobuffer.cpp400
-rw-r--r--src/multimedia/video/qabstractvideobuffer.h125
-rw-r--r--src/multimedia/video/qabstractvideobuffer_p.h97
-rw-r--r--src/multimedia/video/qabstractvideofilter.cpp325
-rw-r--r--src/multimedia/video/qabstractvideofilter.h91
-rw-r--r--src/multimedia/video/qabstractvideosurface.cpp389
-rw-r--r--src/multimedia/video/qabstractvideosurface.h112
-rw-r--r--src/multimedia/video/qhwvideobuffer.cpp17
-rw-r--r--src/multimedia/video/qhwvideobuffer_p.h58
-rw-r--r--src/multimedia/video/qimagevideobuffer.cpp147
-rw-r--r--src/multimedia/video/qimagevideobuffer_p.h68
-rw-r--r--src/multimedia/video/qmemoryvideobuffer.cpp110
-rw-r--r--src/multimedia/video/qmemoryvideobuffer_p.h61
-rw-r--r--src/multimedia/video/qtvideo.cpp71
-rw-r--r--src/multimedia/video/qtvideo.h57
-rw-r--r--src/multimedia/video/qvideoframe.cpp1454
-rw-r--r--src/multimedia/video/qvideoframe.h213
-rw-r--r--src/multimedia/video/qvideoframe_p.h87
-rw-r--r--src/multimedia/video/qvideoframeconversionhelper.cpp506
-rw-r--r--src/multimedia/video/qvideoframeconversionhelper_avx2.cpp146
-rw-r--r--src/multimedia/video/qvideoframeconversionhelper_p.h145
-rw-r--r--src/multimedia/video/qvideoframeconversionhelper_sse2.cpp138
-rw-r--r--src/multimedia/video/qvideoframeconversionhelper_ssse3.cpp99
-rw-r--r--src/multimedia/video/qvideoframeconverter.cpp462
-rw-r--r--src/multimedia/video/qvideoframeconverter_p.h36
-rw-r--r--src/multimedia/video/qvideoframeformat.cpp1044
-rw-r--r--src/multimedia/video/qvideoframeformat.h223
-rw-r--r--src/multimedia/video/qvideooutputorientationhandler.cpp55
-rw-r--r--src/multimedia/video/qvideooutputorientationhandler_p.h45
-rw-r--r--src/multimedia/video/qvideoprobe.cpp218
-rw-r--r--src/multimedia/video/qvideoprobe.h74
-rw-r--r--src/multimedia/video/qvideosink.cpp194
-rw-r--r--src/multimedia/video/qvideosink.h57
-rw-r--r--src/multimedia/video/qvideosurfaceformat.cpp678
-rw-r--r--src/multimedia/video/qvideosurfaceformat.h146
-rw-r--r--src/multimedia/video/qvideosurfaceoutput.cpp101
-rw-r--r--src/multimedia/video/qvideosurfaceoutput_p.h90
-rw-r--r--src/multimedia/video/qvideosurfaces.cpp102
-rw-r--r--src/multimedia/video/qvideosurfaces_p.h77
-rw-r--r--src/multimedia/video/qvideotexturehelper.cpp855
-rw-r--r--src/multimedia/video/qvideotexturehelper_p.h93
-rw-r--r--src/multimedia/video/qvideowindow.cpp531
-rw-r--r--src/multimedia/video/qvideowindow_p.h127
-rw-r--r--src/multimedia/video/video.pri37
-rw-r--r--src/multimedia/wasm/qwasmaudiodevice.cpp56
-rw-r--r--src/multimedia/wasm/qwasmaudiodevice_p.h31
-rw-r--r--src/multimedia/wasm/qwasmaudiosink.cpp464
-rw-r--r--src/multimedia/wasm/qwasmaudiosink_p.h89
-rw-r--r--src/multimedia/wasm/qwasmaudiosource.cpp315
-rw-r--r--src/multimedia/wasm/qwasmaudiosource_p.h75
-rw-r--r--src/multimedia/wasm/qwasmmediadevices.cpp276
-rw-r--r--src/multimedia/wasm/qwasmmediadevices_p.h89
-rw-r--r--src/multimedia/windows/qcomptr_p.h33
-rw-r--r--src/multimedia/windows/qcomtaskresource_p.h152
-rw-r--r--src/multimedia/windows/qwindowsaudiodevice.cpp229
-rw-r--r--src/multimedia/windows/qwindowsaudiodevice_p.h60
-rw-r--r--src/multimedia/windows/qwindowsaudiosink.cpp388
-rw-r--r--src/multimedia/windows/qwindowsaudiosink_p.h97
-rw-r--r--src/multimedia/windows/qwindowsaudiosource.cpp406
-rw-r--r--src/multimedia/windows/qwindowsaudiosource_p.h96
-rw-r--r--src/multimedia/windows/qwindowsaudioutils.cpp208
-rw-r--r--src/multimedia/windows/qwindowsaudioutils_p.h45
-rw-r--r--src/multimedia/windows/qwindowsmediadevices.cpp345
-rw-r--r--src/multimedia/windows/qwindowsmediadevices_p.h65
-rw-r--r--src/multimedia/windows/qwindowsmediafoundation.cpp70
-rw-r--r--src/multimedia/windows/qwindowsmediafoundation_p.h59
-rw-r--r--src/multimedia/windows/qwindowsmfdefs.cpp26
-rw-r--r--src/multimedia/windows/qwindowsmfdefs_p.h94
-rw-r--r--src/multimedia/windows/qwindowsmultimediautils.cpp215
-rw-r--r--src/multimedia/windows/qwindowsmultimediautils_p.h47
-rw-r--r--src/multimedia/windows/qwindowsresampler.cpp241
-rw-r--r--src/multimedia/windows/qwindowsresampler_p.h75
-rw-r--r--src/multimediaquick/CMakeLists.txt45
-rw-r--r--src/multimediaquick/Video.qml371
-rw-r--r--src/multimediaquick/multimedia_plugin.cpp42
-rw-r--r--src/multimediaquick/qquickimagecapture.cpp189
-rw-r--r--src/multimediaquick/qquickimagecapture_p.h57
-rw-r--r--src/multimediaquick/qquickimagepreviewprovider.cpp59
-rw-r--r--src/multimediaquick/qquickimagepreviewprovider_p.h35
-rw-r--r--src/multimediaquick/qquickmediaplayer.cpp95
-rw-r--r--src/multimediaquick/qquickmediaplayer_p.h75
-rw-r--r--src/multimediaquick/qquickplaylist.cpp594
-rw-r--r--src/multimediaquick/qquickplaylist_p.h171
-rw-r--r--src/multimediaquick/qquickscreencapture.cpp27
-rw-r--r--src/multimediaquick/qquickscreencapture_p.h44
-rw-r--r--src/multimediaquick/qquicksoundeffect.cpp29
-rw-r--r--src/multimediaquick/qquicksoundeffect_p.h47
-rw-r--r--src/multimediaquick/qquickvideooutput.cpp566
-rw-r--r--src/multimediaquick/qquickvideooutput_p.h128
-rw-r--r--src/multimediaquick/qsgvideonode_p.cpp378
-rw-r--r--src/multimediaquick/qsgvideonode_p.h65
-rw-r--r--src/multimediaquick/qsgvideotexture.cpp77
-rw-r--r--src/multimediaquick/qsgvideotexture_p.h47
-rw-r--r--src/multimediaquick/qtmultimediaquickglobal_p.h28
-rw-r--r--src/multimediaquick/qtmultimediaquicktypes.cpp12
-rw-r--r--src/multimediaquick/qtmultimediaquicktypes_p.h201
-rw-r--r--src/multimediawidgets/CMakeLists.txt34
-rw-r--r--src/multimediawidgets/doc/snippets/doc_src_qtmultimediawidgets.cpp53
-rw-r--r--src/multimediawidgets/doc/snippets/doc_src_qtmultimediawidgets.pro3
-rw-r--r--src/multimediawidgets/doc/snippets/multimedia-snippets/camera.cpp65
-rw-r--r--src/multimediawidgets/doc/snippets/multimedia-snippets/video.cpp51
-rw-r--r--src/multimediawidgets/doc/src/qtmultimediawidgets-index.qdoc59
-rw-r--r--src/multimediawidgets/doc/src/qtmultimediawidgets.qdoc38
-rw-r--r--src/multimediawidgets/multimediawidgets.pro36
-rw-r--r--src/multimediawidgets/qcameraviewfinder.cpp110
-rw-r--r--src/multimediawidgets/qcameraviewfinder.h80
-rw-r--r--src/multimediawidgets/qgraphicsvideoitem.cpp300
-rw-r--r--src/multimediawidgets/qgraphicsvideoitem.h58
-rw-r--r--src/multimediawidgets/qpaintervideosurface.cpp1733
-rw-r--r--src/multimediawidgets/qpaintervideosurface_p.h176
-rw-r--r--src/multimediawidgets/qtmultimediawidgetdefs.h71
-rw-r--r--src/multimediawidgets/qtmultimediawidgetsglobal.h9
-rw-r--r--src/multimediawidgets/qvideowidget.cpp943
-rw-r--r--src/multimediawidgets/qvideowidget.h90
-rw-r--r--src/multimediawidgets/qvideowidget_p.h237
-rw-r--r--src/multimediawidgets/qvideowidgetcontrol.cpp224
-rw-r--r--src/multimediawidgets/qvideowidgetcontrol.h97
-rw-r--r--src/plugins/CMakeLists.txt1
-rw-r--r--src/plugins/alsa/alsa.json3
-rw-r--r--src/plugins/alsa/alsa.pro23
-rw-r--r--src/plugins/alsa/qalsaaudiodeviceinfo.cpp430
-rw-r--r--src/plugins/alsa/qalsaaudiodeviceinfo.h120
-rw-r--r--src/plugins/alsa/qalsaaudioinput.cpp872
-rw-r--r--src/plugins/alsa/qalsaaudioinput.h185
-rw-r--r--src/plugins/alsa/qalsaaudiooutput.cpp813
-rw-r--r--src/plugins/alsa/qalsaaudiooutput.h164
-rw-r--r--src/plugins/alsa/qalsaplugin.cpp77
-rw-r--r--src/plugins/alsa/qalsaplugin.h68
-rw-r--r--src/plugins/android/android.pro4
-rw-r--r--src/plugins/android/jar/jar.pro21
-rw-r--r--src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer.java590
-rw-r--r--src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtCameraListener.java216
-rw-r--r--src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtMediaRecorderListener.java67
-rw-r--r--src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtMultimediaUtils.java138
-rw-r--r--src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback.java73
-rw-r--r--src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder.java125
-rw-r--r--src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureListener.java60
-rw-r--r--src/plugins/android/src/android_mediaservice.json4
-rw-r--r--src/plugins/android/src/common/common.pri10
-rw-r--r--src/plugins/android/src/common/qandroidglobal.h52
-rw-r--r--src/plugins/android/src/common/qandroidmultimediautils.cpp152
-rw-r--r--src/plugins/android/src/common/qandroidmultimediautils.h63
-rw-r--r--src/plugins/android/src/common/qandroidvideooutput.cpp504
-rw-r--r--src/plugins/android/src/common/qandroidvideooutput.h145
-rw-r--r--src/plugins/android/src/mediacapture/mediacapture.pri53
-rw-r--r--src/plugins/android/src/mediacapture/qandroidaudioencodersettingscontrol.cpp96
-rw-r--r--src/plugins/android/src/mediacapture/qandroidaudioencodersettingscontrol.h67
-rw-r--r--src/plugins/android/src/mediacapture/qandroidaudioinputselectorcontrol.cpp111
-rw-r--r--src/plugins/android/src/mediacapture/qandroidaudioinputselectorcontrol.h71
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameracapturebufferformatcontrol.cpp64
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameracapturebufferformatcontrol.h60
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameracapturedestinationcontrol.cpp69
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameracapturedestinationcontrol.h65
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameracontrol.cpp112
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameracontrol.h74
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameraexposurecontrol.cpp293
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameraexposurecontrol.h83
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameraflashcontrol.cpp128
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameraflashcontrol.h71
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerafocuscontrol.cpp309
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerafocuscontrol.h109
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameraimagecapturecontrol.cpp84
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameraimagecapturecontrol.h69
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameraimageprocessingcontrol.cpp140
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameraimageprocessingcontrol.h75
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerainfocontrol.cpp80
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerainfocontrol.h60
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameralockscontrol.cpp252
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameralockscontrol.h85
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerasession.cpp942
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerasession.h205
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameravideorenderercontrol.cpp281
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcameravideorenderercontrol.h72
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerazoomcontrol.cpp133
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerazoomcontrol.h78
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcaptureservice.cpp249
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcaptureservice.h112
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcapturesession.cpp594
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcapturesession.h182
-rw-r--r--src/plugins/android/src/mediacapture/qandroidimageencodercontrol.cpp93
-rw-r--r--src/plugins/android/src/mediacapture/qandroidimageencodercontrol.h72
-rw-r--r--src/plugins/android/src/mediacapture/qandroidmediacontainercontrol.cpp84
-rw-r--r--src/plugins/android/src/mediacapture/qandroidmediacontainercontrol.h66
-rw-r--r--src/plugins/android/src/mediacapture/qandroidmediarecordercontrol.cpp118
-rw-r--r--src/plugins/android/src/mediacapture/qandroidmediarecordercontrol.h75
-rw-r--r--src/plugins/android/src/mediacapture/qandroidmediavideoprobecontrol.cpp61
-rw-r--r--src/plugins/android/src/mediacapture/qandroidmediavideoprobecontrol.h61
-rw-r--r--src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.cpp99
-rw-r--r--src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.h74
-rw-r--r--src/plugins/android/src/mediacapture/qandroidvideoencodersettingscontrol.cpp97
-rw-r--r--src/plugins/android/src/mediacapture/qandroidvideoencodersettingscontrol.h68
-rw-r--r--src/plugins/android/src/mediacapture/qandroidviewfindersettingscontrol.cpp89
-rw-r--r--src/plugins/android/src/mediacapture/qandroidviewfindersettingscontrol.h71
-rw-r--r--src/plugins/android/src/mediaplayer/mediaplayer.pri17
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp77
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h63
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp87
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h63
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp797
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h140
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.cpp76
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.h68
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp111
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidmediaservice.h73
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.cpp248
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.h79
-rw-r--r--src/plugins/android/src/qandroidmediaserviceplugin.cpp184
-rw-r--r--src/plugins/android/src/qandroidmediaserviceplugin.h81
-rw-r--r--src/plugins/android/src/src.pro20
-rw-r--r--src/plugins/android/src/wrappers/jni/androidcamera.cpp1712
-rw-r--r--src/plugins/android/src/wrappers/jni/androidcamera.h237
-rw-r--r--src/plugins/android/src/wrappers/jni/androidmediametadataretriever.cpp193
-rw-r--r--src/plugins/android/src/wrappers/jni/androidmediametadataretriever.h89
-rw-r--r--src/plugins/android/src/wrappers/jni/androidmediaplayer.cpp435
-rw-r--r--src/plugins/android/src/wrappers/jni/androidmediaplayer.h141
-rw-r--r--src/plugins/android/src/wrappers/jni/androidmediarecorder.cpp405
-rw-r--r--src/plugins/android/src/wrappers/jni/androidmediarecorder.h176
-rw-r--r--src/plugins/android/src/wrappers/jni/androidmultimediautils.cpp78
-rw-r--r--src/plugins/android/src/wrappers/jni/androidmultimediautils.h66
-rw-r--r--src/plugins/android/src/wrappers/jni/androidsurfacetexture.cpp211
-rw-r--r--src/plugins/android/src/wrappers/jni/androidsurfacetexture.h84
-rw-r--r--src/plugins/android/src/wrappers/jni/androidsurfaceview.cpp195
-rw-r--r--src/plugins/android/src/wrappers/jni/androidsurfaceview.h102
-rw-r--r--src/plugins/android/src/wrappers/jni/jni.pri21
-rw-r--r--src/plugins/audiocapture/audiocapture.json4
-rw-r--r--src/plugins/audiocapture/audiocapture.pro27
-rw-r--r--src/plugins/audiocapture/audiocaptureprobecontrol.cpp62
-rw-r--r--src/plugins/audiocapture/audiocaptureprobecontrol.h61
-rw-r--r--src/plugins/audiocapture/audiocaptureservice.cpp97
-rw-r--r--src/plugins/audiocapture/audiocaptureservice.h74
-rw-r--r--src/plugins/audiocapture/audiocaptureserviceplugin.cpp62
-rw-r--r--src/plugins/audiocapture/audiocaptureserviceplugin.h61
-rw-r--r--src/plugins/audiocapture/audiocapturesession.cpp458
-rw-r--r--src/plugins/audiocapture/audiocapturesession.h194
-rw-r--r--src/plugins/audiocapture/audiocontainercontrol.cpp82
-rw-r--r--src/plugins/audiocapture/audiocontainercontrol.h70
-rw-r--r--src/plugins/audiocapture/audioencodercontrol.cpp174
-rw-r--r--src/plugins/audiocapture/audioencodercontrol.h77
-rw-r--r--src/plugins/audiocapture/audioinputselector.cpp111
-rw-r--r--src/plugins/audiocapture/audioinputselector.h77
-rw-r--r--src/plugins/audiocapture/audiomediarecordercontrol.cpp121
-rw-r--r--src/plugins/audiocapture/audiomediarecordercontrol.h82
-rw-r--r--src/plugins/avfoundation/avfoundation.pro4
-rw-r--r--src/plugins/avfoundation/camera/avfaudioencodersettingscontrol.h75
-rw-r--r--src/plugins/avfoundation/camera/avfaudioencodersettingscontrol.mm226
-rw-r--r--src/plugins/avfoundation/camera/avfaudioinputselectorcontrol.h83
-rw-r--r--src/plugins/avfoundation/camera/avfaudioinputselectorcontrol.mm119
-rw-r--r--src/plugins/avfoundation/camera/avfcamera.json4
-rw-r--r--src/plugins/avfoundation/camera/avfcameracontrol.h83
-rw-r--r--src/plugins/avfoundation/camera/avfcameracontrol.mm134
-rw-r--r--src/plugins/avfoundation/camera/avfcameradebug.h57
-rw-r--r--src/plugins/avfoundation/camera/avfcameradevicecontrol.h85
-rw-r--r--src/plugins/avfoundation/camera/avfcameradevicecontrol.mm123
-rw-r--r--src/plugins/avfoundation/camera/avfcameraexposurecontrol.h89
-rw-r--r--src/plugins/avfoundation/camera/avfcameraexposurecontrol.mm661
-rw-r--r--src/plugins/avfoundation/camera/avfcameraflashcontrol.h83
-rw-r--r--src/plugins/avfoundation/camera/avfcameraflashcontrol.mm233
-rw-r--r--src/plugins/avfoundation/camera/avfcamerafocuscontrol.h87
-rw-r--r--src/plugins/avfoundation/camera/avfcamerafocuscontrol.mm306
-rw-r--r--src/plugins/avfoundation/camera/avfcamerainfocontrol.h59
-rw-r--r--src/plugins/avfoundation/camera/avfcamerainfocontrol.mm60
-rw-r--r--src/plugins/avfoundation/camera/avfcamerametadatacontrol.h69
-rw-r--r--src/plugins/avfoundation/camera/avfcamerametadatacontrol.mm83
-rw-r--r--src/plugins/avfoundation/camera/avfcamerarenderercontrol.h108
-rw-r--r--src/plugins/avfoundation/camera/avfcamerarenderercontrol.mm411
-rw-r--r--src/plugins/avfoundation/camera/avfcameraservice.h132
-rw-r--r--src/plugins/avfoundation/camera/avfcameraservice.mm267
-rw-r--r--src/plugins/avfoundation/camera/avfcameraserviceplugin.h76
-rw-r--r--src/plugins/avfoundation/camera/avfcameraserviceplugin.mm113
-rw-r--r--src/plugins/avfoundation/camera/avfcamerasession.h144
-rw-r--r--src/plugins/avfoundation/camera/avfcamerasession.mm492
-rw-r--r--src/plugins/avfoundation/camera/avfcamerautility.h179
-rw-r--r--src/plugins/avfoundation/camera/avfcamerautility.mm575
-rw-r--r--src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.h117
-rw-r--r--src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm599
-rw-r--r--src/plugins/avfoundation/camera/avfcamerawindowcontrol.h129
-rw-r--r--src/plugins/avfoundation/camera/avfcamerawindowcontrol.mm262
-rw-r--r--src/plugins/avfoundation/camera/avfcamerazoomcontrol.h85
-rw-r--r--src/plugins/avfoundation/camera/avfcamerazoomcontrol.mm179
-rw-r--r--src/plugins/avfoundation/camera/avfcapturedestinationcontrol.h63
-rw-r--r--src/plugins/avfoundation/camera/avfcapturedestinationcontrol.mm62
-rw-r--r--src/plugins/avfoundation/camera/avfimagecapturecontrol.h100
-rw-r--r--src/plugins/avfoundation/camera/avfimagecapturecontrol.mm266
-rw-r--r--src/plugins/avfoundation/camera/avfimageencodercontrol.h85
-rw-r--r--src/plugins/avfoundation/camera/avfimageencodercontrol.mm240
-rw-r--r--src/plugins/avfoundation/camera/avfmediaassetwriter.h75
-rw-r--r--src/plugins/avfoundation/camera/avfmediaassetwriter.mm514
-rw-r--r--src/plugins/avfoundation/camera/avfmediacontainercontrol.h69
-rw-r--r--src/plugins/avfoundation/camera/avfmediacontainercontrol.mm112
-rw-r--r--src/plugins/avfoundation/camera/avfmediarecordercontrol.h120
-rw-r--r--src/plugins/avfoundation/camera/avfmediarecordercontrol.mm430
-rw-r--r--src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.h115
-rw-r--r--src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm414
-rw-r--r--src/plugins/avfoundation/camera/avfmediavideoprobecontrol.h60
-rw-r--r--src/plugins/avfoundation/camera/avfmediavideoprobecontrol.mm61
-rw-r--r--src/plugins/avfoundation/camera/avfstoragelocation.h71
-rw-r--r--src/plugins/avfoundation/camera/avfstoragelocation.mm136
-rw-r--r--src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.h88
-rw-r--r--src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.mm385
-rw-r--r--src/plugins/avfoundation/camera/camera.pro94
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfdisplaylink.h90
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfdisplaylink.mm241
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayer.json4
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayercontrol.h99
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayercontrol.mm192
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.h74
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.mm161
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.h70
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm134
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayerserviceplugin.h77
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayerserviceplugin.mm107
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h161
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm1067
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.h92
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm276
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideoframerenderer_ios.h120
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideoframerenderer_ios.mm307
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideooutput.h60
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideooutput.mm42
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.h92
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.mm301
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideowidget.h85
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideowidget.mm187
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.h95
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.mm145
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideowindowcontrol.h118
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideowindowcontrol.mm255
-rw-r--r--src/plugins/avfoundation/mediaplayer/mediaplayer.pro76
-rw-r--r--src/plugins/common/evr.pri20
-rw-r--r--src/plugins/common/evr/evrcustompresenter.cpp2062
-rw-r--r--src/plugins/common/evr/evrcustompresenter.h377
-rw-r--r--src/plugins/common/evr/evrd3dpresentengine.cpp413
-rw-r--r--src/plugins/common/evr/evrd3dpresentengine.h152
-rw-r--r--src/plugins/common/evr/evrdefs.cpp48
-rw-r--r--src/plugins/common/evr/evrdefs.h353
-rw-r--r--src/plugins/common/evr/evrhelpers.cpp186
-rw-r--r--src/plugins/common/evr/evrhelpers.h101
-rw-r--r--src/plugins/common/evr/evrvideowindowcontrol.cpp362
-rw-r--r--src/plugins/common/evr/evrvideowindowcontrol.h109
-rw-r--r--src/plugins/coreaudio/coreaudio.json3
-rw-r--r--src/plugins/coreaudio/coreaudio.pro39
-rw-r--r--src/plugins/coreaudio/coreaudiodeviceinfo.h82
-rw-r--r--src/plugins/coreaudio/coreaudiodeviceinfo.mm346
-rw-r--r--src/plugins/coreaudio/coreaudioinput.h266
-rw-r--r--src/plugins/coreaudio/coreaudioinput.mm1005
-rw-r--r--src/plugins/coreaudio/coreaudiooutput.h205
-rw-r--r--src/plugins/coreaudio/coreaudiooutput.mm752
-rw-r--r--src/plugins/coreaudio/coreaudioplugin.h66
-rw-r--r--src/plugins/coreaudio/coreaudioplugin.mm82
-rw-r--r--src/plugins/coreaudio/coreaudiosessionmanager.h125
-rw-r--r--src/plugins/coreaudio/coreaudiosessionmanager.mm472
-rw-r--r--src/plugins/coreaudio/coreaudioutils.h93
-rw-r--r--src/plugins/coreaudio/coreaudioutils.mm198
-rw-r--r--src/plugins/directshow/camera/camera.pri37
-rw-r--r--src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.cpp65
-rw-r--r--src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.h60
-rw-r--r--src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.cpp68
-rw-r--r--src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.h66
-rw-r--r--src/plugins/directshow/camera/directshowcameraexposurecontrol.cpp413
-rw-r--r--src/plugins/directshow/camera/directshowcameraexposurecontrol.h100
-rw-r--r--src/plugins/directshow/camera/directshowcameraglobal.h231
-rw-r--r--src/plugins/directshow/camera/directshowcameraimageencodercontrol.cpp95
-rw-r--r--src/plugins/directshow/camera/directshowcameraimageencodercontrol.h70
-rw-r--r--src/plugins/directshow/camera/directshowcamerazoomcontrol.cpp209
-rw-r--r--src/plugins/directshow/camera/directshowcamerazoomcontrol.h88
-rw-r--r--src/plugins/directshow/camera/dscameracontrol.cpp120
-rw-r--r--src/plugins/directshow/camera/dscameracontrol.h80
-rw-r--r--src/plugins/directshow/camera/dscameraimageprocessingcontrol.cpp78
-rw-r--r--src/plugins/directshow/camera/dscameraimageprocessingcontrol.h70
-rw-r--r--src/plugins/directshow/camera/dscameraservice.cpp161
-rw-r--r--src/plugins/directshow/camera/dscameraservice.h91
-rw-r--r--src/plugins/directshow/camera/dscamerasession.cpp1177
-rw-r--r--src/plugins/directshow/camera/dscamerasession.h242
-rw-r--r--src/plugins/directshow/camera/dscameraviewfindersettingscontrol.cpp66
-rw-r--r--src/plugins/directshow/camera/dscameraviewfindersettingscontrol.h65
-rw-r--r--src/plugins/directshow/camera/dsimagecapturecontrol.cpp88
-rw-r--r--src/plugins/directshow/camera/dsimagecapturecontrol.h69
-rw-r--r--src/plugins/directshow/camera/dsvideodevicecontrol.cpp186
-rw-r--r--src/plugins/directshow/camera/dsvideodevicecontrol.h79
-rw-r--r--src/plugins/directshow/camera/dsvideorenderer.cpp67
-rw-r--r--src/plugins/directshow/camera/dsvideorenderer.h68
-rw-r--r--src/plugins/directshow/common/common.pri29
-rw-r--r--src/plugins/directshow/common/directshowaudioprobecontrol.cpp57
-rw-r--r--src/plugins/directshow/common/directshowaudioprobecontrol.h64
-rw-r--r--src/plugins/directshow/common/directshowbasefilter.cpp251
-rw-r--r--src/plugins/directshow/common/directshowbasefilter.h95
-rw-r--r--src/plugins/directshow/common/directshoweventloop.cpp150
-rw-r--r--src/plugins/directshow/common/directshoweventloop.h80
-rw-r--r--src/plugins/directshow/common/directshowglobal.h160
-rw-r--r--src/plugins/directshow/common/directshowmediatype.cpp352
-rw-r--r--src/plugins/directshow/common/directshowmediatype.h97
-rw-r--r--src/plugins/directshow/common/directshowmediatypeenum.cpp113
-rw-r--r--src/plugins/directshow/common/directshowmediatypeenum.h77
-rw-r--r--src/plugins/directshow/common/directshowobject.h64
-rw-r--r--src/plugins/directshow/common/directshowpin.cpp696
-rw-r--r--src/plugins/directshow/common/directshowpin.h180
-rw-r--r--src/plugins/directshow/common/directshowpinenum.cpp125
-rw-r--r--src/plugins/directshow/common/directshowpinenum.h78
-rw-r--r--src/plugins/directshow/common/directshowsamplegrabber.cpp197
-rw-r--r--src/plugins/directshow/common/directshowsamplegrabber.h89
-rw-r--r--src/plugins/directshow/common/directshowutils.cpp346
-rw-r--r--src/plugins/directshow/common/directshowutils.h91
-rw-r--r--src/plugins/directshow/common/directshowvideobuffer.cpp88
-rw-r--r--src/plugins/directshow/common/directshowvideobuffer.h70
-rw-r--r--src/plugins/directshow/common/directshowvideoprobecontrol.cpp69
-rw-r--r--src/plugins/directshow/common/directshowvideoprobecontrol.h67
-rw-r--r--src/plugins/directshow/directshow.json4
-rw-r--r--src/plugins/directshow/directshow.pro32
-rw-r--r--src/plugins/directshow/dsserviceplugin.cpp148
-rw-r--r--src/plugins/directshow/dsserviceplugin.h73
-rw-r--r--src/plugins/directshow/player/directshowaudioendpointcontrol.cpp161
-rw-r--r--src/plugins/directshow/player/directshowaudioendpointcontrol.h82
-rw-r--r--src/plugins/directshow/player/directshowevrvideowindowcontrol.cpp66
-rw-r--r--src/plugins/directshow/player/directshowevrvideowindowcontrol.h63
-rw-r--r--src/plugins/directshow/player/directshowioreader.cpp462
-rw-r--r--src/plugins/directshow/player/directshowioreader.h120
-rw-r--r--src/plugins/directshow/player/directshowiosource.cpp530
-rw-r--r--src/plugins/directshow/player/directshowiosource.h140
-rw-r--r--src/plugins/directshow/player/directshowmetadatacontrol.cpp697
-rw-r--r--src/plugins/directshow/player/directshowmetadatacontrol.h84
-rw-r--r--src/plugins/directshow/player/directshowplayercontrol.cpp397
-rw-r--r--src/plugins/directshow/player/directshowplayercontrol.h153
-rw-r--r--src/plugins/directshow/player/directshowplayerservice.cpp1812
-rw-r--r--src/plugins/directshow/player/directshowplayerservice.h240
-rw-r--r--src/plugins/directshow/player/directshowvideorenderercontrol.cpp121
-rw-r--r--src/plugins/directshow/player/directshowvideorenderercontrol.h84
-rw-r--r--src/plugins/directshow/player/player.pri45
-rw-r--r--src/plugins/directshow/player/videosurfacefilter.cpp810
-rw-r--r--src/plugins/directshow/player/videosurfacefilter.h161
-rw-r--r--src/plugins/directshow/player/vmr9videowindowcontrol.cpp326
-rw-r--r--src/plugins/directshow/player/vmr9videowindowcontrol.h108
-rw-r--r--src/plugins/gstreamer/audiodecoder/audiodecoder.json4
-rw-r--r--src/plugins/gstreamer/audiodecoder/audiodecoder.pro24
-rw-r--r--src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodercontrol.cpp139
-rw-r--r--src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodercontrol.h95
-rw-r--r--src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderservice.cpp73
-rw-r--r--src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderservice.h69
-rw-r--r--src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderserviceplugin.cpp99
-rw-r--r--src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderserviceplugin.h72
-rw-r--r--src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.cpp614
-rw-r--r--src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.h157
-rw-r--r--src/plugins/gstreamer/camerabin/camerabin.json4
-rw-r--r--src/plugins/gstreamer/camerabin/camerabin.pro85
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp165
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinaudioencoder.h109
-rw-r--r--src/plugins/gstreamer/camerabin/camerabincapturebufferformat.cpp76
-rw-r--r--src/plugins/gstreamer/camerabin/camerabincapturebufferformat.h74
-rw-r--r--src/plugins/gstreamer/camerabin/camerabincapturedestination.cpp76
-rw-r--r--src/plugins/gstreamer/camerabin/camerabincapturedestination.h70
-rw-r--r--src/plugins/gstreamer/camerabin/camerabincontainer.cpp152
-rw-r--r--src/plugins/gstreamer/camerabin/camerabincontainer.h94
-rw-r--r--src/plugins/gstreamer/camerabin/camerabincontrol.cpp309
-rw-r--r--src/plugins/gstreamer/camerabin/camerabincontrol.h101
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinexposure.cpp285
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinexposure.h75
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinflash.cpp109
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinflash.h73
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinfocus.cpp540
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinfocus.h134
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinimagecapture.cpp380
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinimagecapture.h123
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinimageencoder.cpp88
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinimageencoder.h86
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp441
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinimageprocessing.h108
-rw-r--r--src/plugins/gstreamer/camerabin/camerabininfocontrol.cpp69
-rw-r--r--src/plugins/gstreamer/camerabin/camerabininfocontrol.h65
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinlocks.cpp259
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinlocks.h98
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinmetadata.cpp234
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinmetadata.h71
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinrecorder.cpp298
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinrecorder.h94
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinresourcepolicy.cpp242
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinresourcepolicy.h95
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinservice.cpp271
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinservice.h104
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp163
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinserviceplugin.h89
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinsession.cpp1587
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinsession.h291
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp316
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h90
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp239
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinvideoencoder.h109
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinviewfindersettings.cpp118
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinviewfindersettings.h67
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinviewfindersettings2.cpp73
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinviewfindersettings2.h67
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinzoom.cpp147
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinzoom.h78
-rw-r--r--src/plugins/gstreamer/common.pri15
-rw-r--r--src/plugins/gstreamer/gstreamer.json4
-rw-r--r--src/plugins/gstreamer/gstreamer.pro10
-rw-r--r--src/plugins/gstreamer/mediacapture/mediacapture.json4
-rw-r--r--src/plugins/gstreamer/mediacapture/mediacapture.pro52
-rw-r--r--src/plugins/gstreamer/mediacapture/mediacapturecamera.json4
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreameraudioencode.cpp239
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreameraudioencode.h94
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.cpp197
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.h94
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp158
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.h71
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.cpp227
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.h103
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.cpp142
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.h95
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp1032
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercapturesession.h244
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.cpp113
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.h74
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamerimageencode.cpp88
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamerimageencode.h81
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.cpp60
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.h80
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp372
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.h97
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.cpp286
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.h83
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamervideoencode.cpp296
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamervideoencode.h97
-rw-r--r--src/plugins/gstreamer/mediaplayer/mediaplayer.json4
-rw-r--r--src/plugins/gstreamer/mediaplayer/mediaplayer.pro26
-rw-r--r--src/plugins/gstreamer/mediaplayer/qgstreameravailabilitycontrol.cpp64
-rw-r--r--src/plugins/gstreamer/mediaplayer/qgstreameravailabilitycontrol.h65
-rw-r--r--src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp190
-rw-r--r--src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.h72
-rw-r--r--src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp193
-rw-r--r--src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h99
-rw-r--r--src/plugins/gstreamer/mediaplayer/qgstreamerplayerserviceplugin.cpp113
-rw-r--r--src/plugins/gstreamer/mediaplayer/qgstreamerplayerserviceplugin.h78
-rw-r--r--src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.cpp87
-rw-r--r--src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.h71
-rw-r--r--src/plugins/m3u/m3u.json3
-rw-r--r--src/plugins/m3u/m3u.pro12
-rw-r--r--src/plugins/m3u/qm3uhandler.cpp229
-rw-r--r--src/plugins/m3u/qm3uhandler.h68
-rw-r--r--src/plugins/multimedia/CMakeLists.txt24
-rw-r--r--src/plugins/multimedia/android/CMakeLists.txt62
-rw-r--r--src/plugins/multimedia/android/android.json3
-rw-r--r--src/plugins/multimedia/android/audio/qandroidaudiodecoder.cpp437
-rw-r--r--src/plugins/multimedia/android/audio/qandroidaudiodecoder_p.h118
-rw-r--r--src/plugins/multimedia/android/common/qandroidaudioinput.cpp47
-rw-r--r--src/plugins/multimedia/android/common/qandroidaudioinput_p.h47
-rw-r--r--src/plugins/multimedia/android/common/qandroidaudiooutput_p.h30
-rw-r--r--src/plugins/multimedia/android/common/qandroidglobal_p.h28
-rw-r--r--src/plugins/multimedia/android/common/qandroidmultimediautils.cpp125
-rw-r--r--src/plugins/multimedia/android/common/qandroidmultimediautils_p.h40
-rw-r--r--src/plugins/multimedia/android/common/qandroidvideooutput.cpp468
-rw-r--r--src/plugins/multimedia/android/common/qandroidvideooutput_p.h93
-rw-r--r--src/plugins/multimedia/android/common/qandroidvideosink.cpp35
-rw-r--r--src/plugins/multimedia/android/common/qandroidvideosink_p.h41
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidcamera.cpp562
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidcamera_p.h99
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidcamerasession.cpp808
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidcamerasession_p.h166
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidcapturesession.cpp473
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidcapturesession_p.h158
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidimagecapture.cpp73
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidimagecapture_p.h48
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidmediacapturesession.cpp115
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidmediacapturesession_p.h66
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidmediaencoder.cpp72
-rw-r--r--src/plugins/multimedia/android/mediacapture/qandroidmediaencoder_p.h50
-rw-r--r--src/plugins/multimedia/android/mediaplayer/qandroidmediaplayer.cpp999
-rw-r--r--src/plugins/multimedia/android/mediaplayer/qandroidmediaplayer_p.h127
-rw-r--r--src/plugins/multimedia/android/mediaplayer/qandroidmetadata.cpp163
-rw-r--r--src/plugins/multimedia/android/mediaplayer/qandroidmetadata_p.h47
-rw-r--r--src/plugins/multimedia/android/qandroidformatsinfo.cpp160
-rw-r--r--src/plugins/multimedia/android/qandroidformatsinfo_p.h40
-rw-r--r--src/plugins/multimedia/android/qandroidintegration.cpp136
-rw-r--r--src/plugins/multimedia/android/qandroidintegration_p.h48
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidcamera.cpp1797
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidcamera_p.h208
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidmediametadataretriever.cpp136
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidmediametadataretriever_p.h66
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidmediaplayer.cpp535
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidmediaplayer_p.h135
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidmediarecorder.cpp337
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidmediarecorder_p.h161
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidmultimediautils.cpp43
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidmultimediautils_p.h40
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidsurfacetexture.cpp152
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidsurfacetexture_p.h61
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidsurfaceview.cpp152
-rw-r--r--src/plugins/multimedia/android/wrappers/jni/androidsurfaceview_p.h78
-rw-r--r--src/plugins/multimedia/darwin/CMakeLists.txt70
-rw-r--r--src/plugins/multimedia/darwin/avfaudiodecoder.mm544
-rw-r--r--src/plugins/multimedia/darwin/avfaudiodecoder_p.h99
-rw-r--r--src/plugins/multimedia/darwin/avfvideobuffer.mm207
-rw-r--r--src/plugins/multimedia/darwin/avfvideobuffer_p.h64
-rw-r--r--src/plugins/multimedia/darwin/avfvideosink.mm228
-rw-r--r--src/plugins/multimedia/darwin/avfvideosink_p.h99
-rw-r--r--src/plugins/multimedia/darwin/camera/avfaudiopreviewdelegate.mm98
-rw-r--r--src/plugins/multimedia/darwin/camera/avfaudiopreviewdelegate_p.h40
-rw-r--r--src/plugins/multimedia/darwin/camera/avfcamera.mm89
-rw-r--r--src/plugins/multimedia/darwin/camera/avfcamera_p.h48
-rw-r--r--src/plugins/multimedia/darwin/camera/avfcameradebug_p.h26
-rw-r--r--src/plugins/multimedia/darwin/camera/avfcamerarenderer.mm296
-rw-r--r--src/plugins/multimedia/darwin/camera/avfcamerarenderer_p.h95
-rw-r--r--src/plugins/multimedia/darwin/camera/avfcameraservice.mm169
-rw-r--r--src/plugins/multimedia/darwin/camera/avfcameraservice_p.h84
-rw-r--r--src/plugins/multimedia/darwin/camera/avfcamerasession.mm513
-rw-r--r--src/plugins/multimedia/darwin/camera/avfcamerasession_p.h132
-rw-r--r--src/plugins/multimedia/darwin/camera/avfcamerautility.mm729
-rw-r--r--src/plugins/multimedia/darwin/camera/avfcamerautility_p.h165
-rw-r--r--src/plugins/multimedia/darwin/camera/avfimagecapture.mm385
-rw-r--r--src/plugins/multimedia/darwin/camera/avfimagecapture_p.h81
-rw-r--r--src/plugins/multimedia/darwin/camera/avfmediaassetwriter.mm556
-rw-r--r--src/plugins/multimedia/darwin/camera/avfmediaassetwriter_p.h54
-rw-r--r--src/plugins/multimedia/darwin/camera/avfmediaencoder.mm664
-rw-r--r--src/plugins/multimedia/darwin/camera/avfmediaencoder_p.h96
-rw-r--r--src/plugins/multimedia/darwin/camera/qavfcamerabase.mm1084
-rw-r--r--src/plugins/multimedia/darwin/camera/qavfcamerabase_p.h110
-rw-r--r--src/plugins/multimedia/darwin/common/avfmetadata.mm382
-rw-r--r--src/plugins/multimedia/darwin/common/avfmetadata_p.h37
-rw-r--r--src/plugins/multimedia/darwin/darwin.json3
-rw-r--r--src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink.mm207
-rw-r--r--src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink_p.h65
-rw-r--r--src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer.mm1270
-rw-r--r--src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer_p.h151
-rw-r--r--src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol.mm222
-rw-r--r--src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol_p.h72
-rw-r--r--src/plugins/multimedia/darwin/qavfhelpers.mm143
-rw-r--r--src/plugins/multimedia/darwin/qavfhelpers_p.h41
-rw-r--r--src/plugins/multimedia/darwin/qdarwinformatsinfo.mm211
-rw-r--r--src/plugins/multimedia/darwin/qdarwinformatsinfo_p.h38
-rw-r--r--src/plugins/multimedia/darwin/qdarwinintegration.mm93
-rw-r--r--src/plugins/multimedia/darwin/qdarwinintegration_p.h45
-rw-r--r--src/plugins/multimedia/ffmpeg/CMakeLists.txt260
-rw-r--r--src/plugins/multimedia/ffmpeg/cmake/QtAddFFmpegStubs.cmake199
-rw-r--r--src/plugins/multimedia/ffmpeg/cmake/QtDeployFFmpeg.cmake43
-rw-r--r--src/plugins/multimedia/ffmpeg/ffmpeg.json3
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer.cpp407
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer_p.h132
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegcodec.cpp82
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegcodec_p.h62
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegdemuxer.cpp228
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegdemuxer_p.h87
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegframe_p.h109
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegmediadataholder.cpp390
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegmediadataholder_p.h107
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegpacket_p.h61
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackenginedefs_p.h46
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackengineobject.cpp109
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackengineobject_p.h84
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegpositionwithoffset_p.h40
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegrenderer.cpp216
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegrenderer_p.h125
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegstreamdecoder.cpp240
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegstreamdecoder_p.h87
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegsubtitlerenderer.cpp44
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegsubtitlerenderer_p.h48
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegtimecontroller.cpp165
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegtimecontroller_p.h94
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegvideorenderer.cpp79
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegvideorenderer_p.h47
-rw-r--r--src/plugins/multimedia/ffmpeg/qandroidcamera.cpp697
-rw-r--r--src/plugins/multimedia/ffmpeg/qandroidcamera_p.h91
-rw-r--r--src/plugins/multimedia/ffmpeg/qandroidcameraframe.cpp224
-rw-r--r--src/plugins/multimedia/ffmpeg/qandroidcameraframe_p.h75
-rw-r--r--src/plugins/multimedia/ffmpeg/qandroidimagecapture.cpp46
-rw-r--r--src/plugins/multimedia/ffmpeg/qandroidimagecapture_p.h38
-rw-r--r--src/plugins/multimedia/ffmpeg/qandroidvideodevices.cpp150
-rw-r--r--src/plugins/multimedia/ffmpeg/qandroidvideodevices_p.h35
-rw-r--r--src/plugins/multimedia/ffmpeg/qavfcamera.mm345
-rw-r--r--src/plugins/multimedia/ffmpeg/qavfcamera_p.h90
-rw-r--r--src/plugins/multimedia/ffmpeg/qavfsamplebufferdelegate.mm224
-rw-r--r--src/plugins/multimedia/ffmpeg/qavfsamplebufferdelegate_p.h51
-rw-r--r--src/plugins/multimedia/ffmpeg/qavfscreencapture.mm201
-rw-r--r--src/plugins/multimedia/ffmpeg/qavfscreencapture_p.h60
-rw-r--r--src/plugins/multimedia/ffmpeg/qcgcapturablewindows.mm48
-rw-r--r--src/plugins/multimedia/ffmpeg/qcgcapturablewindows_p.h32
-rw-r--r--src/plugins/multimedia/ffmpeg/qcgwindowcapture.mm203
-rw-r--r--src/plugins/multimedia/ffmpeg/qcgwindowcapture_p.h43
-rw-r--r--src/plugins/multimedia/ffmpeg/qeglfsscreencapture.cpp180
-rw-r--r--src/plugins/multimedia/ffmpeg/qeglfsscreencapture_p.h48
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeg.cpp645
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeg_p.h280
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegaudiodecoder.cpp247
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegaudiodecoder_p.h68
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegaudioinput.cpp195
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegaudioinput_p.h57
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegavaudioformat.cpp78
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegavaudioformat_p.h68
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegconverter.cpp272
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegconverter_p.h30
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegdefs_p.h41
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegencodingformatcontext.cpp116
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegencodingformatcontext_p.h60
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeghwaccel.cpp504
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeghwaccel_d3d11.cpp309
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeghwaccel_d3d11_p.h104
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeghwaccel_mediacodec.cpp120
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeghwaccel_mediacodec_p.h36
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeghwaccel_p.h130
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp364
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi_p.h48
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeghwaccel_videotoolbox.mm288
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeghwaccel_videotoolbox_p.h63
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegimagecapture.cpp271
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegimagecapture_p.h71
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegioutils.cpp55
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegioutils_p.h40
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediacapturesession.cpp318
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediacapturesession_p.h112
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo.cpp517
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo_p.h52
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediaintegration.cpp375
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediaintegration_p.h57
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediametadata.cpp182
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediametadata_p.h35
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediaplayer.cpp411
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediaplayer_p.h119
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediarecorder.cpp189
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegmediarecorder_p.h72
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegplaybackengine.cpp649
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegplaybackengine_p.h234
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegresampler.cpp112
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegresampler_p.h62
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp467
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi_p.h44
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegsurfacecapturegrabber.cpp202
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegsurfacecapturegrabber_p.h92
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegthread.cpp53
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegthread_p.h96
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegvideobuffer.cpp363
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegvideobuffer_p.h71
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegvideosink.cpp34
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegvideosink_p.h44
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegwindowcapture_uwp.cpp508
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegwindowcapture_uwp_p.h46
-rw-r--r--src/plugins/multimedia/ffmpeg/qgdiwindowcapture.cpp197
-rw-r--r--src/plugins/multimedia/ffmpeg/qgdiwindowcapture_p.h43
-rw-r--r--src/plugins/multimedia/ffmpeg/qgrabwindowsurfacecapture.cpp221
-rw-r--r--src/plugins/multimedia/ffmpeg/qgrabwindowsurfacecapture_p.h48
-rw-r--r--src/plugins/multimedia/ffmpeg/qopenglvideobuffer.cpp96
-rw-r--r--src/plugins/multimedia/ffmpeg/qopenglvideobuffer_p.h44
-rw-r--r--src/plugins/multimedia/ffmpeg/qv4l2camera.cpp708
-rw-r--r--src/plugins/multimedia/ffmpeg/qv4l2camera_p.h133
-rw-r--r--src/plugins/multimedia/ffmpeg/qv4l2cameradevices.cpp182
-rw-r--r--src/plugins/multimedia/ffmpeg/qv4l2cameradevices_p.h46
-rw-r--r--src/plugins/multimedia/ffmpeg/qv4l2filedescriptor.cpp71
-rw-r--r--src/plugins/multimedia/ffmpeg/qv4l2filedescriptor_p.h50
-rw-r--r--src/plugins/multimedia/ffmpeg/qv4l2memorytransfer.cpp223
-rw-r--r--src/plugins/multimedia/ffmpeg/qv4l2memorytransfer_p.h66
-rw-r--r--src/plugins/multimedia/ffmpeg/qwincapturablewindows.cpp74
-rw-r--r--src/plugins/multimedia/ffmpeg/qwincapturablewindows_p.h32
-rw-r--r--src/plugins/multimedia/ffmpeg/qwindowscamera.cpp330
-rw-r--r--src/plugins/multimedia/ffmpeg/qwindowscamera_p.h45
-rw-r--r--src/plugins/multimedia/ffmpeg/qx11capturablewindows.cpp74
-rw-r--r--src/plugins/multimedia/ffmpeg/qx11capturablewindows_p.h45
-rw-r--r--src/plugins/multimedia/ffmpeg/qx11surfacecapture.cpp342
-rw-r--r--src/plugins/multimedia/ffmpeg/qx11surfacecapture_p.h48
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoder.cpp343
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoder_p.h77
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoderutils.cpp97
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoderutils_p.h28
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderoptions.cpp362
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderoptions_p.h32
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderthread.cpp31
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderthread_p.h66
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencodinginitializer.cpp165
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencodinginitializer_p.h77
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegmuxer.cpp64
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegmuxer_p.h41
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengine.cpp267
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengine_p.h116
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengineutils.cpp63
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengineutils_p.h81
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoder.cpp245
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoder_p.h64
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoderutils.cpp214
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoderutils_p.h64
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder.cpp451
-rw-r--r--src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder_p.h93
-rw-r--r--src/plugins/multimedia/ffmpeg/symbolstubs/openssl3.ver7
-rw-r--r--src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-crypto.cpp6
-rw-r--r--src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-ssl.cpp300
-rw-r--r--src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va-drm.cpp14
-rw-r--r--src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va-x11.cpp14
-rw-r--r--src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va.cpp150
-rw-r--r--src/plugins/multimedia/ffmpeg/symbolstubs/va.ver7
-rw-r--r--src/plugins/multimedia/gstreamer/CMakeLists.txt73
-rw-r--r--src/plugins/multimedia/gstreamer/audio/qgstreameraudiodecoder.cpp533
-rw-r--r--src/plugins/multimedia/gstreamer/audio/qgstreameraudiodecoder_p.h116
-rw-r--r--src/plugins/multimedia/gstreamer/audio/qgstreameraudiodevice.cpp77
-rw-r--r--src/plugins/multimedia/gstreamer/audio/qgstreameraudiodevice_p.h52
-rw-r--r--src/plugins/multimedia/gstreamer/common/qglist_helper_p.h82
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgst.cpp1339
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgst_debug.cpp565
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgst_debug_p.h74
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgst_handle_types_p.h269
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgst_p.h844
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstappsource.cpp319
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstappsource_p.h96
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstpipeline.cpp425
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstpipeline_p.h122
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreameraudioinput.cpp137
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreameraudioinput_p.h62
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreameraudiooutput.cpp138
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreameraudiooutput_p.h63
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamerbufferprobe.cpp88
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamerbufferprobe_p.h56
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp1111
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h199
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamermessage_p.h55
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamermetadata.cpp489
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamermetadata_p.h35
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamervideooutput.cpp221
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamervideooutput_p.h81
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamervideooverlay.cpp218
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamervideooverlay_p.h74
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamervideosink.cpp312
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstreamervideosink_p.h76
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstsubtitlesink.cpp155
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstsubtitlesink_p.h70
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstutils.cpp141
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstutils_p.h41
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstvideobuffer.cpp393
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstvideobuffer_p.h55
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstvideorenderersink.cpp499
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgstvideorenderersink_p.h138
-rw-r--r--src/plugins/multimedia/gstreamer/gstreamer.json3
-rw-r--r--src/plugins/multimedia/gstreamer/mediacapture/qgstreamercamera.cpp771
-rw-r--r--src/plugins/multimedia/gstreamer/mediacapture/qgstreamercamera_p.h152
-rw-r--r--src/plugins/multimedia/gstreamer/mediacapture/qgstreamerimagecapture.cpp450
-rw-r--r--src/plugins/multimedia/gstreamer/mediacapture/qgstreamerimagecapture_p.h109
-rw-r--r--src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediacapture.cpp326
-rw-r--r--src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediacapture_p.h97
-rw-r--r--src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder.cpp419
-rw-r--r--src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder_p.h91
-rw-r--r--src/plugins/multimedia/gstreamer/qgstreamerformatinfo.cpp445
-rw-r--r--src/plugins/multimedia/gstreamer/qgstreamerformatinfo_p.h44
-rw-r--r--src/plugins/multimedia/gstreamer/qgstreamerintegration.cpp242
-rw-r--r--src/plugins/multimedia/gstreamer/qgstreamerintegration_p.h79
-rw-r--r--src/plugins/multimedia/gstreamer/qgstreamerplugin.cpp28
-rw-r--r--src/plugins/multimedia/gstreamer/qgstreamervideodevices.cpp158
-rw-r--r--src/plugins/multimedia/gstreamer/qgstreamervideodevices_p.h54
-rw-r--r--src/plugins/multimedia/qnx/CMakeLists.txt39
-rw-r--r--src/plugins/multimedia/qnx/camera/qqnxcamera.cpp820
-rw-r--r--src/plugins/multimedia/qnx/camera/qqnxcamera_p.h201
-rw-r--r--src/plugins/multimedia/qnx/camera/qqnxcameraframebuffer.cpp299
-rw-r--r--src/plugins/multimedia/qnx/camera/qqnxcameraframebuffer_p.h60
-rw-r--r--src/plugins/multimedia/qnx/camera/qqnxcamerahandle_p.h102
-rw-r--r--src/plugins/multimedia/qnx/camera/qqnximagecapture.cpp257
-rw-r--r--src/plugins/multimedia/qnx/camera/qqnximagecapture_p.h63
-rw-r--r--src/plugins/multimedia/qnx/camera/qqnxplatformcamera.cpp426
-rw-r--r--src/plugins/multimedia/qnx/camera/qqnxplatformcamera_p.h113
-rw-r--r--src/plugins/multimedia/qnx/capture/qqnxaudiorecorder.cpp284
-rw-r--r--src/plugins/multimedia/qnx/capture/qqnxaudiorecorder_p.h103
-rw-r--r--src/plugins/multimedia/qnx/capture/qqnxmediacapturesession.cpp121
-rw-r--r--src/plugins/multimedia/qnx/capture/qqnxmediacapturesession_p.h67
-rw-r--r--src/plugins/multimedia/qnx/capture/qqnxmediarecorder.cpp115
-rw-r--r--src/plugins/multimedia/qnx/capture/qqnxmediarecorder_p.h51
-rw-r--r--src/plugins/multimedia/qnx/common/mmrenderertypes.h95
-rw-r--r--src/plugins/multimedia/qnx/common/qqnxaudioinput.cpp25
-rw-r--r--src/plugins/multimedia/qnx/common/qqnxaudioinput_p.h33
-rw-r--r--src/plugins/multimedia/qnx/common/qqnxaudiooutput.cpp52
-rw-r--r--src/plugins/multimedia/qnx/common/qqnxaudiooutput_p.h39
-rw-r--r--src/plugins/multimedia/qnx/common/qqnxmediaeventthread.cpp98
-rw-r--r--src/plugins/multimedia/qnx/common/qqnxmediaeventthread_p.h55
-rw-r--r--src/plugins/multimedia/qnx/common/qqnxwindowgrabber.cpp435
-rw-r--r--src/plugins/multimedia/qnx/common/qqnxwindowgrabber_p.h114
-rw-r--r--src/plugins/multimedia/qnx/mediaplayer/qqnxmediametadata.cpp262
-rw-r--r--src/plugins/multimedia/qnx/mediaplayer/qqnxmediametadata_p.h74
-rw-r--r--src/plugins/multimedia/qnx/mediaplayer/qqnxmediaplayer.cpp887
-rw-r--r--src/plugins/multimedia/qnx/mediaplayer/qqnxmediaplayer_p.h167
-rw-r--r--src/plugins/multimedia/qnx/mediaplayer/qqnxmediautil.cpp126
-rw-r--r--src/plugins/multimedia/qnx/mediaplayer/qqnxmediautil_p.h32
-rw-r--r--src/plugins/multimedia/qnx/mediaplayer/qqnxvideosink.cpp26
-rw-r--r--src/plugins/multimedia/qnx/mediaplayer/qqnxvideosink_p.h41
-rw-r--r--src/plugins/multimedia/qnx/qnx.json3
-rw-r--r--src/plugins/multimedia/qnx/qqnxformatinfo.cpp36
-rw-r--r--src/plugins/multimedia/qnx/qqnxformatinfo_p.h33
-rw-r--r--src/plugins/multimedia/qnx/qqnxmediaintegration.cpp79
-rw-r--r--src/plugins/multimedia/qnx/qqnxmediaintegration_p.h50
-rw-r--r--src/plugins/multimedia/qnx/qqnxvideodevices.cpp111
-rw-r--r--src/plugins/multimedia/qnx/qqnxvideodevices_p.h32
-rw-r--r--src/plugins/multimedia/wasm/CMakeLists.txt25
-rw-r--r--src/plugins/multimedia/wasm/common/qwasmaudioinput.cpp107
-rw-r--r--src/plugins/multimedia/wasm/common/qwasmaudioinput_p.h57
-rw-r--r--src/plugins/multimedia/wasm/common/qwasmaudiooutput.cpp378
-rw-r--r--src/plugins/multimedia/wasm/common/qwasmaudiooutput_p.h97
-rw-r--r--src/plugins/multimedia/wasm/common/qwasmvideooutput.cpp1071
-rw-r--r--src/plugins/multimedia/wasm/common/qwasmvideooutput_p.h153
-rw-r--r--src/plugins/multimedia/wasm/mediacapture/qwasmcamera.cpp478
-rw-r--r--src/plugins/multimedia/wasm/mediacapture/qwasmcamera_p.h99
-rw-r--r--src/plugins/multimedia/wasm/mediacapture/qwasmimagecapture.cpp130
-rw-r--r--src/plugins/multimedia/wasm/mediacapture/qwasmimagecapture_p.h58
-rw-r--r--src/plugins/multimedia/wasm/mediacapture/qwasmmediacapturesession.cpp111
-rw-r--r--src/plugins/multimedia/wasm/mediacapture/qwasmmediacapturesession_p.h71
-rw-r--r--src/plugins/multimedia/wasm/mediacapture/qwasmmediarecorder.cpp520
-rw-r--r--src/plugins/multimedia/wasm/mediacapture/qwasmmediarecorder_p.h89
-rw-r--r--src/plugins/multimedia/wasm/mediaplayer/qwasmmediaplayer.cpp475
-rw-r--r--src/plugins/multimedia/wasm/mediaplayer/qwasmmediaplayer_p.h124
-rw-r--r--src/plugins/multimedia/wasm/mediaplayer/qwasmvideosink.cpp26
-rw-r--r--src/plugins/multimedia/wasm/mediaplayer/qwasmvideosink_p.h40
-rw-r--r--src/plugins/multimedia/wasm/qwasmmediaintegration.cpp109
-rw-r--r--src/plugins/multimedia/wasm/qwasmmediaintegration_p.h50
-rw-r--r--src/plugins/multimedia/wasm/wasm.json5
-rw-r--r--src/plugins/multimedia/windows/CMakeLists.txt69
-rw-r--r--src/plugins/multimedia/windows/common/mfmetadata.cpp408
-rw-r--r--src/plugins/multimedia/windows/common/mfmetadata_p.h30
-rw-r--r--src/plugins/multimedia/windows/decoder/mfaudiodecodercontrol.cpp225
-rw-r--r--src/plugins/multimedia/windows/decoder/mfaudiodecodercontrol_p.h75
-rw-r--r--src/plugins/multimedia/windows/decoder/mfdecodersourcereader.cpp103
-rw-r--r--src/plugins/multimedia/windows/decoder/mfdecodersourcereader_p.h63
-rw-r--r--src/plugins/multimedia/windows/evr/evrcustompresenter.cpp1849
-rw-r--r--src/plugins/multimedia/windows/evr/evrcustompresenter_p.h357
-rw-r--r--src/plugins/multimedia/windows/evr/evrd3dpresentengine.cpp699
-rw-r--r--src/plugins/multimedia/windows/evr/evrd3dpresentengine_p.h153
-rw-r--r--src/plugins/multimedia/windows/evr/evrhelpers.cpp140
-rw-r--r--src/plugins/multimedia/windows/evr/evrhelpers_p.h93
-rw-r--r--src/plugins/multimedia/windows/evr/evrvideowindowcontrol.cpp228
-rw-r--r--src/plugins/multimedia/windows/evr/evrvideowindowcontrol_p.h72
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowscamera.cpp101
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowscamera_p.h55
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowsimagecapture.cpp207
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowsimagecapture_p.h64
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowsmediacapture.cpp109
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowsmediacapture_p.h62
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicereader.cpp1019
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicereader_p.h154
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicesession.cpp376
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicesession_p.h100
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowsmediaencoder.cpp225
-rw-r--r--src/plugins/multimedia/windows/mediacapture/qwindowsmediaencoder_p.h71
-rw-r--r--src/plugins/multimedia/windows/mfstream.cpp326
-rw-r--r--src/plugins/multimedia/windows/mfstream_p.h124
-rw-r--r--src/plugins/multimedia/windows/player/mfactivate.cpp17
-rw-r--r--src/plugins/multimedia/windows/player/mfactivate_p.h202
-rw-r--r--src/plugins/multimedia/windows/player/mfevrvideowindowcontrol.cpp55
-rw-r--r--src/plugins/multimedia/windows/player/mfevrvideowindowcontrol_p.h38
-rw-r--r--src/plugins/multimedia/windows/player/mfplayercontrol.cpp306
-rw-r--r--src/plugins/multimedia/windows/player/mfplayercontrol_p.h103
-rw-r--r--src/plugins/multimedia/windows/player/mfplayersession.cpp1736
-rw-r--r--src/plugins/multimedia/windows/player/mfplayersession_p.h240
-rw-r--r--src/plugins/multimedia/windows/player/mfvideorenderercontrol.cpp152
-rw-r--r--src/plugins/multimedia/windows/player/mfvideorenderercontrol_p.h47
-rw-r--r--src/plugins/multimedia/windows/qwindowsformatinfo.cpp187
-rw-r--r--src/plugins/multimedia/windows/qwindowsformatinfo_p.h31
-rw-r--r--src/plugins/multimedia/windows/qwindowsintegration.cpp96
-rw-r--r--src/plugins/multimedia/windows/qwindowsintegration_p.h51
-rw-r--r--src/plugins/multimedia/windows/qwindowsvideodevices.cpp228
-rw-r--r--src/plugins/multimedia/windows/qwindowsvideodevices_p.h44
-rw-r--r--src/plugins/multimedia/windows/sourceresolver.cpp294
-rw-r--r--src/plugins/multimedia/windows/sourceresolver_p.h83
-rw-r--r--src/plugins/multimedia/windows/windows.json3
-rw-r--r--src/plugins/opensles/opensles.json3
-rw-r--r--src/plugins/opensles/opensles.pro25
-rw-r--r--src/plugins/opensles/qopenslesaudioinput.cpp548
-rw-r--r--src/plugins/opensles/qopenslesaudioinput.h133
-rw-r--r--src/plugins/opensles/qopenslesaudiooutput.cpp733
-rw-r--r--src/plugins/opensles/qopenslesaudiooutput.h159
-rw-r--r--src/plugins/opensles/qopenslesdeviceinfo.cpp113
-rw-r--r--src/plugins/opensles/qopenslesdeviceinfo.h75
-rw-r--r--src/plugins/opensles/qopenslesengine.cpp369
-rw-r--r--src/plugins/opensles/qopenslesengine.h90
-rw-r--r--src/plugins/opensles/qopenslesplugin.cpp81
-rw-r--r--src/plugins/opensles/qopenslesplugin.h73
-rw-r--r--src/plugins/plugins.pro54
-rw-r--r--src/plugins/pulseaudio/pulseaudio.json3
-rw-r--r--src/plugins/pulseaudio/pulseaudio.pro25
-rw-r--r--src/plugins/pulseaudio/qaudiodeviceinfo_pulse.cpp103
-rw-r--r--src/plugins/pulseaudio/qaudiodeviceinfo_pulse.h90
-rw-r--r--src/plugins/pulseaudio/qaudioinput_pulse.cpp682
-rw-r--r--src/plugins/pulseaudio/qaudioinput_pulse.h161
-rw-r--r--src/plugins/pulseaudio/qaudiooutput_pulse.cpp739
-rw-r--r--src/plugins/pulseaudio/qaudiooutput_pulse.h166
-rw-r--r--src/plugins/pulseaudio/qpulseaudioengine.cpp482
-rw-r--r--src/plugins/pulseaudio/qpulseaudioengine.h129
-rw-r--r--src/plugins/pulseaudio/qpulseaudioplugin.cpp85
-rw-r--r--src/plugins/pulseaudio/qpulseaudioplugin.h73
-rw-r--r--src/plugins/pulseaudio/qpulsehelpers.cpp211
-rw-r--r--src/plugins/pulseaudio/qpulsehelpers.h71
-rw-r--r--src/plugins/qnx-audio/audio/audio.pro22
-rw-r--r--src/plugins/qnx-audio/audio/qnx_audio.json3
-rw-r--r--src/plugins/qnx-audio/audio/qnxaudiodeviceinfo.cpp148
-rw-r--r--src/plugins/qnx-audio/audio/qnxaudiodeviceinfo.h72
-rw-r--r--src/plugins/qnx-audio/audio/qnxaudioinput.cpp453
-rw-r--r--src/plugins/qnx-audio/audio/qnxaudioinput.h138
-rw-r--r--src/plugins/qnx-audio/audio/qnxaudiooutput.cpp578
-rw-r--r--src/plugins/qnx-audio/audio/qnxaudiooutput.h150
-rw-r--r--src/plugins/qnx-audio/audio/qnxaudioplugin.cpp91
-rw-r--r--src/plugins/qnx-audio/audio/qnxaudioplugin.h67
-rw-r--r--src/plugins/qnx-audio/audio/qnxaudioutils.cpp128
-rw-r--r--src/plugins/qnx-audio/audio/qnxaudioutils.h55
-rw-r--r--src/plugins/qnx-audio/qnx-audio.pro3
-rw-r--r--src/plugins/qnx/camera/bbcameraaudioencodersettingscontrol.cpp87
-rw-r--r--src/plugins/qnx/camera/bbcameraaudioencodersettingscontrol.h66
-rw-r--r--src/plugins/qnx/camera/bbcameracapturebufferformatcontrol.cpp64
-rw-r--r--src/plugins/qnx/camera/bbcameracapturebufferformatcontrol.h59
-rw-r--r--src/plugins/qnx/camera/bbcameracapturedestinationcontrol.cpp68
-rw-r--r--src/plugins/qnx/camera/bbcameracapturedestinationcontrol.h64
-rw-r--r--src/plugins/qnx/camera/bbcameracontrol.cpp90
-rw-r--r--src/plugins/qnx/camera/bbcameracontrol.h71
-rw-r--r--src/plugins/qnx/camera/bbcameraexposurecontrol.cpp232
-rw-r--r--src/plugins/qnx/camera/bbcameraexposurecontrol.h71
-rw-r--r--src/plugins/qnx/camera/bbcameraflashcontrol.cpp111
-rw-r--r--src/plugins/qnx/camera/bbcameraflashcontrol.h66
-rw-r--r--src/plugins/qnx/camera/bbcamerafocuscontrol.cpp329
-rw-r--r--src/plugins/qnx/camera/bbcamerafocuscontrol.h77
-rw-r--r--src/plugins/qnx/camera/bbcameraimagecapturecontrol.cpp83
-rw-r--r--src/plugins/qnx/camera/bbcameraimagecapturecontrol.h68
-rw-r--r--src/plugins/qnx/camera/bbcameraimageprocessingcontrol.cpp144
-rw-r--r--src/plugins/qnx/camera/bbcameraimageprocessingcontrol.h65
-rw-r--r--src/plugins/qnx/camera/bbcamerainfocontrol.cpp81
-rw-r--r--src/plugins/qnx/camera/bbcamerainfocontrol.h63
-rw-r--r--src/plugins/qnx/camera/bbcameralockscontrol.cpp256
-rw-r--r--src/plugins/qnx/camera/bbcameralockscontrol.h84
-rw-r--r--src/plugins/qnx/camera/bbcameramediarecordercontrol.cpp156
-rw-r--r--src/plugins/qnx/camera/bbcameramediarecordercontrol.h74
-rw-r--r--src/plugins/qnx/camera/bbcameraorientationhandler.cpp113
-rw-r--r--src/plugins/qnx/camera/bbcameraorientationhandler.h69
-rw-r--r--src/plugins/qnx/camera/bbcameraservice.cpp143
-rw-r--r--src/plugins/qnx/camera/bbcameraservice.h104
-rw-r--r--src/plugins/qnx/camera/bbcamerasession.cpp1154
-rw-r--r--src/plugins/qnx/camera/bbcamerasession.h215
-rw-r--r--src/plugins/qnx/camera/bbcameravideoencodersettingscontrol.cpp88
-rw-r--r--src/plugins/qnx/camera/bbcameravideoencodersettingscontrol.h67
-rw-r--r--src/plugins/qnx/camera/bbcameraviewfindersettingscontrol.cpp245
-rw-r--r--src/plugins/qnx/camera/bbcameraviewfindersettingscontrol.h64
-rw-r--r--src/plugins/qnx/camera/bbcamerazoomcontrol.cpp155
-rw-r--r--src/plugins/qnx/camera/bbcamerazoomcontrol.h77
-rw-r--r--src/plugins/qnx/camera/bbimageencodercontrol.cpp79
-rw-r--r--src/plugins/qnx/camera/bbimageencodercontrol.h66
-rw-r--r--src/plugins/qnx/camera/bbmediastoragelocation.cpp118
-rw-r--r--src/plugins/qnx/camera/bbmediastoragelocation.h64
-rw-r--r--src/plugins/qnx/camera/bbvideodeviceselectorcontrol.cpp145
-rw-r--r--src/plugins/qnx/camera/bbvideodeviceselectorcontrol.h78
-rw-r--r--src/plugins/qnx/camera/bbvideorenderercontrol.cpp62
-rw-r--r--src/plugins/qnx/camera/bbvideorenderercontrol.h63
-rw-r--r--src/plugins/qnx/camera/camera.pri52
-rw-r--r--src/plugins/qnx/common/common.pri7
-rw-r--r--src/plugins/qnx/common/windowgrabber.cpp419
-rw-r--r--src/plugins/qnx/common/windowgrabber.h144
-rw-r--r--src/plugins/qnx/mediaplayer/mediaplayer.pri28
-rw-r--r--src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.cpp68
-rw-r--r--src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.h63
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderercustomaudiorolecontrol.cpp67
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderercustomaudiorolecontrol.h63
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.cpp653
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.h180
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.cpp164
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.h80
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermetadata.cpp298
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermetadata.h99
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermetadatareadercontrol.cpp170
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermetadatareadercontrol.h66
-rw-r--r--src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.cpp218
-rw-r--r--src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.h84
-rw-r--r--src/plugins/qnx/mediaplayer/mmrendererutil.cpp246
-rw-r--r--src/plugins/qnx/mediaplayer/mmrendererutil.h60
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderervideowindowcontrol.cpp413
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderervideowindowcontrol.h118
-rw-r--r--src/plugins/qnx/mediaplayer/mmreventmediaplayercontrol.cpp229
-rw-r--r--src/plugins/qnx/mediaplayer/mmreventmediaplayercontrol.h84
-rw-r--r--src/plugins/qnx/mediaplayer/mmreventthread.cpp121
-rw-r--r--src/plugins/qnx/mediaplayer/mmreventthread.h79
-rw-r--r--src/plugins/qnx/neutrino_mediaservice.json4
-rw-r--r--src/plugins/qnx/neutrinoserviceplugin.cpp68
-rw-r--r--src/plugins/qnx/neutrinoserviceplugin.h63
-rw-r--r--src/plugins/qnx/qnx.pro15
-rw-r--r--src/plugins/resourcepolicy/resourcepolicy.json4
-rw-r--r--src/plugins/resourcepolicy/resourcepolicy.pro22
-rw-r--r--src/plugins/resourcepolicy/resourcepolicyimpl.cpp100
-rw-r--r--src/plugins/resourcepolicy/resourcepolicyimpl.h67
-rw-r--r--src/plugins/resourcepolicy/resourcepolicyint.cpp405
-rw-r--r--src/plugins/resourcepolicy/resourcepolicyint.h106
-rw-r--r--src/plugins/resourcepolicy/resourcepolicyplugin.cpp62
-rw-r--r--src/plugins/resourcepolicy/resourcepolicyplugin.h59
-rw-r--r--src/plugins/videonode/CMakeLists.txt8
-rw-r--r--src/plugins/videonode/imx6/CMakeLists.txt43
-rw-r--r--src/plugins/videonode/imx6/imx6.pro28
-rw-r--r--src/plugins/videonode/imx6/imx6.qrc6
-rw-r--r--src/plugins/videonode/imx6/qsgvivantevideomaterial.cpp59
-rw-r--r--src/plugins/videonode/imx6/qsgvivantevideomaterial.h42
-rw-r--r--src/plugins/videonode/imx6/qsgvivantevideomaterialshader.cpp40
-rw-r--r--src/plugins/videonode/imx6/qsgvivantevideomaterialshader.h40
-rw-r--r--src/plugins/videonode/imx6/qsgvivantevideonode.cpp90
-rw-r--r--src/plugins/videonode/imx6/qsgvivantevideonode.h56
-rw-r--r--src/plugins/videonode/imx6/qsgvivantevideonodefactory.cpp50
-rw-r--r--src/plugins/videonode/imx6/qsgvivantevideonodefactory.h44
-rwxr-xr-xsrc/plugins/videonode/imx6/shaders/compile.bat38
-rw-r--r--src/plugins/videonode/videonode.pro6
-rw-r--r--src/plugins/windowsaudio/qwindowsaudiodeviceinfo.cpp469
-rw-r--r--src/plugins/windowsaudio/qwindowsaudiodeviceinfo.h109
-rw-r--r--src/plugins/windowsaudio/qwindowsaudioinput.cpp732
-rw-r--r--src/plugins/windowsaudio/qwindowsaudioinput.h177
-rw-r--r--src/plugins/windowsaudio/qwindowsaudiooutput.cpp676
-rw-r--r--src/plugins/windowsaudio/qwindowsaudiooutput.h168
-rw-r--r--src/plugins/windowsaudio/qwindowsaudioplugin.cpp77
-rw-r--r--src/plugins/windowsaudio/qwindowsaudioplugin.h68
-rw-r--r--src/plugins/windowsaudio/qwindowsaudioutils.cpp117
-rw-r--r--src/plugins/windowsaudio/qwindowsaudioutils.h73
-rw-r--r--src/plugins/windowsaudio/windowsaudio.json3
-rw-r--r--src/plugins/windowsaudio/windowsaudio.pro25
-rw-r--r--src/plugins/wmf/decoder/decoder.pri14
-rw-r--r--src/plugins/wmf/decoder/mfaudiodecodercontrol.cpp486
-rw-r--r--src/plugins/wmf/decoder/mfaudiodecodercontrol.h108
-rw-r--r--src/plugins/wmf/decoder/mfdecoderservice.cpp65
-rw-r--r--src/plugins/wmf/decoder/mfdecoderservice.h56
-rw-r--r--src/plugins/wmf/decoder/mfdecodersourcereader.cpp197
-rw-r--r--src/plugins/wmf/decoder/mfdecodersourcereader.h89
-rw-r--r--src/plugins/wmf/mfstream.cpp361
-rw-r--r--src/plugins/wmf/mfstream.h148
-rw-r--r--src/plugins/wmf/player/mfactivate.cpp87
-rw-r--r--src/plugins/wmf/player/mfactivate.h212
-rw-r--r--src/plugins/wmf/player/mfaudioendpointcontrol.cpp180
-rw-r--r--src/plugins/wmf/player/mfaudioendpointcontrol.h82
-rw-r--r--src/plugins/wmf/player/mfaudioprobecontrol.cpp75
-rw-r--r--src/plugins/wmf/player/mfaudioprobecontrol.h66
-rw-r--r--src/plugins/wmf/player/mfevrvideowindowcontrol.cpp91
-rw-r--r--src/plugins/wmf/player/mfevrvideowindowcontrol.h63
-rw-r--r--src/plugins/wmf/player/mfmetadatacontrol.cpp431
-rw-r--r--src/plugins/wmf/player/mfmetadatacontrol.h72
-rw-r--r--src/plugins/wmf/player/mfplayercontrol.cpp316
-rw-r--r--src/plugins/wmf/player/mfplayercontrol.h122
-rw-r--r--src/plugins/wmf/player/mfplayerservice.cpp167
-rw-r--r--src/plugins/wmf/player/mfplayerservice.h87
-rw-r--r--src/plugins/wmf/player/mfplayersession.cpp1818
-rw-r--r--src/plugins/wmf/player/mfplayersession.h239
-rw-r--r--src/plugins/wmf/player/mftvideo.cpp753
-rw-r--r--src/plugins/wmf/player/mftvideo.h117
-rw-r--r--src/plugins/wmf/player/mfvideoprobecontrol.cpp54
-rw-r--r--src/plugins/wmf/player/mfvideoprobecontrol.h59
-rw-r--r--src/plugins/wmf/player/mfvideorenderercontrol.cpp2426
-rw-r--r--src/plugins/wmf/player/mfvideorenderercontrol.h81
-rw-r--r--src/plugins/wmf/player/player.pri34
-rw-r--r--src/plugins/wmf/player/samplegrabber.cpp173
-rw-r--r--src/plugins/wmf/player/samplegrabber.h96
-rw-r--r--src/plugins/wmf/sourceresolver.cpp325
-rw-r--r--src/plugins/wmf/sourceresolver.h104
-rw-r--r--src/plugins/wmf/wmf.json4
-rw-r--r--src/plugins/wmf/wmf.pro28
-rw-r--r--src/plugins/wmf/wmfserviceplugin.cpp117
-rw-r--r--src/plugins/wmf/wmfserviceplugin.h71
-rw-r--r--src/qtmultimediaquicktools/qdeclarativevideooutput.cpp919
-rw-r--r--src/qtmultimediaquicktools/qdeclarativevideooutput_backend_p.h137
-rw-r--r--src/qtmultimediaquicktools/qdeclarativevideooutput_p.h203
-rw-r--r--src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp501
-rw-r--r--src/qtmultimediaquicktools/qdeclarativevideooutput_render_p.h154
-rw-r--r--src/qtmultimediaquicktools/qdeclarativevideooutput_window.cpp151
-rw-r--r--src/qtmultimediaquicktools/qdeclarativevideooutput_window_p.h83
-rw-r--r--src/qtmultimediaquicktools/qsgvideonode_p.cpp131
-rw-r--r--src/qtmultimediaquicktools/qsgvideonode_p.h110
-rw-r--r--src/qtmultimediaquicktools/qsgvideonode_rgb.cpp205
-rw-r--r--src/qtmultimediaquicktools/qsgvideonode_rgb_p.h89
-rw-r--r--src/qtmultimediaquicktools/qsgvideonode_texture.cpp229
-rw-r--r--src/qtmultimediaquicktools/qsgvideonode_texture_p.h89
-rw-r--r--src/qtmultimediaquicktools/qsgvideonode_yuv.cpp407
-rw-r--r--src/qtmultimediaquicktools/qsgvideonode_yuv_p.h89
-rw-r--r--src/qtmultimediaquicktools/qsgvideotexture.cpp166
-rw-r--r--src/qtmultimediaquicktools/qsgvideotexture_p.h84
-rw-r--r--src/qtmultimediaquicktools/qtmultimediaquickdefs_p.h68
-rw-r--r--src/qtmultimediaquicktools/qtmultimediaquicktools.pro35
-rw-r--r--src/qtmultimediaquicktools/qtmultimediaquicktools.qrc13
-rw-r--r--src/qtmultimediaquicktools/shaders/bgra.frag16
-rw-r--r--src/qtmultimediaquicktools/shaders/bgra.frag.qsbbin1265 -> 0 bytes
-rwxr-xr-xsrc/qtmultimediaquicktools/shaders/compile.bat50
-rw-r--r--src/qtmultimediaquicktools/shaders/nv12.frag25
-rw-r--r--src/qtmultimediaquicktools/shaders/nv12.frag.qsbbin1849 -> 0 bytes
-rw-r--r--src/qtmultimediaquicktools/shaders/nv21.frag25
-rw-r--r--src/qtmultimediaquicktools/shaders/nv21.frag.qsbbin1848 -> 0 bytes
-rw-r--r--src/qtmultimediaquicktools/shaders/rgba.frag16
-rw-r--r--src/qtmultimediaquicktools/shaders/rgba.frag.qsbbin1244 -> 0 bytes
-rw-r--r--src/qtmultimediaquicktools/shaders/rgba.vert18
-rw-r--r--src/qtmultimediaquicktools/shaders/rgba.vert.qsbbin1511 -> 0 bytes
-rw-r--r--src/qtmultimediaquicktools/shaders/uyvy.frag23
-rw-r--r--src/qtmultimediaquicktools/shaders/uyvy.frag.qsbbin1801 -> 0 bytes
-rw-r--r--src/qtmultimediaquicktools/shaders/yuv.vert26
-rw-r--r--src/qtmultimediaquicktools/shaders/yuv.vert.qsbbin2017 -> 0 bytes
-rw-r--r--src/qtmultimediaquicktools/shaders/yuv_yv.frag28
-rw-r--r--src/qtmultimediaquicktools/shaders/yuv_yv.frag.qsbbin1975 -> 0 bytes
-rw-r--r--src/qtmultimediaquicktools/shaders/yuyv.frag23
-rw-r--r--src/qtmultimediaquicktools/shaders/yuyv.frag.qsbbin1805 -> 0 bytes
-rw-r--r--src/resonance-audio/CMakeLists.txt238
-rw-r--r--src/resonance-audio/resonance_audio.cpp42
-rw-r--r--src/resonance-audio/resonance_audio.h33
-rw-r--r--src/spatialaudio/CMakeLists.txt29
-rw-r--r--src/spatialaudio/doc/qtspatialaudio.qdocconf62
-rw-r--r--src/spatialaudio/doc/src/qtspatialaudio-cpp.qdoc33
-rw-r--r--src/spatialaudio/doc/src/qtspatialaudio-examples.qdoc15
-rw-r--r--src/spatialaudio/doc/src/qtspatialaudio-index.qdoc104
-rw-r--r--src/spatialaudio/doc/src/qtspatialaudio-qml-types.qdoc26
-rw-r--r--src/spatialaudio/doc/src/spatialaudiooverview.qdoc64
-rw-r--r--src/spatialaudio/qambientsound.cpp283
-rw-r--r--src/spatialaudio/qambientsound.h68
-rw-r--r--src/spatialaudio/qambientsound_p.h84
-rw-r--r--src/spatialaudio/qambisonicdecoder.cpp314
-rw-r--r--src/spatialaudio/qambisonicdecoder_p.h69
-rw-r--r--src/spatialaudio/qambisonicdecoderdata_p.h279
-rw-r--r--src/spatialaudio/qaudioengine.cpp602
-rw-r--r--src/spatialaudio/qaudioengine.h80
-rw-r--r--src/spatialaudio/qaudioengine_p.h92
-rw-r--r--src/spatialaudio/qaudiolistener.cpp134
-rw-r--r--src/spatialaudio/qaudiolistener.h37
-rw-r--r--src/spatialaudio/qaudioroom.cpp399
-rw-r--r--src/spatialaudio/qaudioroom.h107
-rw-r--r--src/spatialaudio/qaudioroom_p.h50
-rw-r--r--src/spatialaudio/qspatialsound.cpp595
-rw-r--r--src/spatialaudio/qspatialsound.h127
-rw-r--r--src/spatialaudio/qspatialsound_p.h62
-rw-r--r--src/spatialaudio/qtspatialaudioglobal.h10
-rw-r--r--src/spatialaudio/qtspatialaudioglobal_p.h21
-rw-r--r--src/spatialaudioquick3d/CMakeLists.txt33
-rw-r--r--src/spatialaudioquick3d/qquick3dambientsound.cpp146
-rw-r--r--src/spatialaudioquick3d/qquick3dambientsound_p.h74
-rw-r--r--src/spatialaudioquick3d/qquick3daudio-qml-types.qdoc32
-rw-r--r--src/spatialaudioquick3d/qquick3daudioengine.cpp128
-rw-r--r--src/spatialaudioquick3d/qquick3daudioengine_p.h64
-rw-r--r--src/spatialaudioquick3d/qquick3daudiolistener.cpp49
-rw-r--r--src/spatialaudioquick3d/qquick3daudiolistener_p.h47
-rw-r--r--src/spatialaudioquick3d/qquick3daudioroom.cpp270
-rw-r--r--src/spatialaudioquick3d/qquick3daudioroom_p.h129
-rw-r--r--src/spatialaudioquick3d/qquick3dspatialaudio_plugin.cpp35
-rw-r--r--src/spatialaudioquick3d/qquick3dspatialsound.cpp323
-rw-r--r--src/spatialaudioquick3d/qquick3dspatialsound_p.h127
-rw-r--r--src/spatialaudioquick3d/qtquick3daudioglobal_p.h28
-rw-r--r--src/spatialaudioquick3d/qtquick3daudiotypes_p.h27
-rw-r--r--src/src.pro53
2287 files changed, 312438 insertions, 180621 deletions
diff --git a/src/3rdparty/eigen/.gitignore b/src/3rdparty/eigen/.gitignore
new file mode 100644
index 000000000..f6ab76fda
--- /dev/null
+++ b/src/3rdparty/eigen/.gitignore
@@ -0,0 +1,38 @@
+qrc_*cxx
+*.orig
+*.pyc
+*.diff
+diff
+*.save
+save
+*.old
+*.gmo
+*.qm
+core
+core.*
+*.bak
+*~
+*build*
+*.moc.*
+*.moc
+ui_*
+CMakeCache.txt
+tags
+.*.swp
+activity.png
+*.out
+*.php*
+*.log
+*.orig
+*.rej
+log
+patch
+*.patch
+a
+a.*
+lapack/testing
+lapack/reference
+.*project
+.settings
+Makefile
+!ci/build.gitlab-ci.yml
diff --git a/src/3rdparty/eigen/COPYING.BSD b/src/3rdparty/eigen/COPYING.BSD
new file mode 100644
index 000000000..25a08ded2
--- /dev/null
+++ b/src/3rdparty/eigen/COPYING.BSD
@@ -0,0 +1,24 @@
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/src/3rdparty/eigen/COPYING.MPL2 b/src/3rdparty/eigen/COPYING.MPL2
new file mode 100644
index 000000000..14e2f777f
--- /dev/null
+++ b/src/3rdparty/eigen/COPYING.MPL2
@@ -0,0 +1,373 @@
+Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+ means each individual or legal entity that creates, contributes to
+ the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+ means the combination of the Contributions of others (if any) used
+ by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+ means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+ means Source Code Form to which the initial Contributor has attached
+ the notice in Exhibit A, the Executable Form of such Source Code
+ Form, and Modifications of such Source Code Form, in each case
+ including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+ means
+
+ (a) that the initial Contributor has attached the notice described
+ in Exhibit B to the Covered Software; or
+
+ (b) that the Covered Software was made available under the terms of
+ version 1.1 or earlier of the License, but not also under the
+ terms of a Secondary License.
+
+1.6. "Executable Form"
+ means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+ means a work that combines Covered Software with other material, in
+ a separate file or files, that is not Covered Software.
+
+1.8. "License"
+ means this document.
+
+1.9. "Licensable"
+ means having the right to grant, to the maximum extent possible,
+ whether at the time of the initial grant or subsequently, any and
+ all of the rights conveyed by this License.
+
+1.10. "Modifications"
+ means any of the following:
+
+ (a) any file in Source Code Form that results from an addition to,
+ deletion from, or modification of the contents of Covered
+ Software; or
+
+ (b) any new file in Source Code Form that contains any Covered
+ Software.
+
+1.11. "Patent Claims" of a Contributor
+ means any patent claim(s), including without limitation, method,
+ process, and apparatus claims, in any patent Licensable by such
+ Contributor that would be infringed, but for the grant of the
+ License, by the making, using, selling, offering for sale, having
+ made, import, or transfer of either its Contributions or its
+ Contributor Version.
+
+1.12. "Secondary License"
+ means either the GNU General Public License, Version 2.0, the GNU
+ Lesser General Public License, Version 2.1, the GNU Affero General
+ Public License, Version 3.0, or any later versions of those
+ licenses.
+
+1.13. "Source Code Form"
+ means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+ means an individual or a legal entity exercising rights under this
+ License. For legal entities, "You" includes any entity that
+ controls, is controlled by, or is under common control with You. For
+ purposes of this definition, "control" means (a) the power, direct
+ or indirect, to cause the direction or management of such entity,
+ whether by contract or otherwise, or (b) ownership of more than
+ fifty percent (50%) of the outstanding shares or beneficial
+ ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+ Licensable by such Contributor to use, reproduce, make available,
+ modify, display, perform, distribute, and otherwise exploit its
+ Contributions, either on an unmodified basis, with Modifications, or
+ as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+ for sale, have made, import, and otherwise transfer either its
+ Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+ or
+
+(b) for infringements caused by: (i) Your and any other third party's
+ modifications of Covered Software, or (ii) the combination of its
+ Contributions with other software (except as part of its Contributor
+ Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+ its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+ Form, as described in Section 3.1, and You must inform recipients of
+ the Executable Form how they can obtain a copy of such Source Code
+ Form by reasonable means in a timely manner, at a charge no more
+ than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+ License, or sublicense it under different terms, provided that the
+ license for the Executable Form does not attempt to limit or alter
+ the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+* *
+* 6. Disclaimer of Warranty *
+* ------------------------- *
+* *
+* Covered Software is provided under this License on an "as is" *
+* basis, without warranty of any kind, either expressed, implied, or *
+* statutory, including, without limitation, warranties that the *
+* Covered Software is free of defects, merchantable, fit for a *
+* particular purpose or non-infringing. The entire risk as to the *
+* quality and performance of the Covered Software is with You. *
+* Should any Covered Software prove defective in any respect, You *
+* (not any Contributor) assume the cost of any necessary servicing, *
+* repair, or correction. This disclaimer of warranty constitutes an *
+* essential part of this License. No use of any Covered Software is *
+* authorized under this License except under this disclaimer. *
+* *
+************************************************************************
+
+************************************************************************
+* *
+* 7. Limitation of Liability *
+* -------------------------- *
+* *
+* Under no circumstances and under no legal theory, whether tort *
+* (including negligence), contract, or otherwise, shall any *
+* Contributor, or anyone who distributes Covered Software as *
+* permitted above, be liable to You for any direct, indirect, *
+* special, incidental, or consequential damages of any character *
+* including, without limitation, damages for lost profits, loss of *
+* goodwill, work stoppage, computer failure or malfunction, or any *
+* and all other commercial damages or losses, even if such party *
+* shall have been informed of the possibility of such damages. This *
+* limitation of liability shall not apply to liability for death or *
+* personal injury resulting from such party's negligence to the *
+* extent applicable law prohibits such limitation. Some *
+* jurisdictions do not allow the exclusion or limitation of *
+* incidental or consequential damages, so this exclusion and *
+* limitation may not apply to You. *
+* *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+ This Source Code Form is "Incompatible With Secondary Licenses", as
+ defined by the Mozilla Public License, v. 2.0.
diff --git a/src/3rdparty/eigen/COPYING.README b/src/3rdparty/eigen/COPYING.README
new file mode 100644
index 000000000..de5b63215
--- /dev/null
+++ b/src/3rdparty/eigen/COPYING.README
@@ -0,0 +1,18 @@
+Eigen is primarily MPL2 licensed. See COPYING.MPL2 and these links:
+ http://www.mozilla.org/MPL/2.0/
+ http://www.mozilla.org/MPL/2.0/FAQ.html
+
+Some files contain third-party code under BSD or LGPL licenses, whence the other
+COPYING.* files here.
+
+All the LGPL code is either LGPL 2.1-only, or LGPL 2.1-or-later.
+For this reason, the COPYING.LGPL file contains the LGPL 2.1 text.
+
+If you want to guarantee that the Eigen code that you are #including is licensed
+under the MPL2 and possibly more permissive licenses (like BSD), #define this
+preprocessor symbol:
+ EIGEN_MPL2_ONLY
+For example, with most compilers, you could add this to your project CXXFLAGS:
+ -DEIGEN_MPL2_ONLY
+This will cause a compilation error to be generated if you #include any code that is
+LGPL licensed.
diff --git a/src/3rdparty/eigen/COPYRIGHTS b/src/3rdparty/eigen/COPYRIGHTS
new file mode 100644
index 000000000..d5884f2d3
--- /dev/null
+++ b/src/3rdparty/eigen/COPYRIGHTS
@@ -0,0 +1,45 @@
+Copyright (c) 2012 Alexey Korepanov <kaikaikai@yandex.ru>
+Copyright (c) 2020 Antonio Sanchez <cantonios@google.com>
+Copyright (c) 2020 Arm Limited and Contributors
+Copyright (c) 2006-2011 Benoit Jacob <jacob.benoit.1@gmail.com>
+Copyright (c) 2014-2016 Benoit Steiner (benoit.steiner.goog@gmail.com)
+Copyright (c) 16 BfToF32Even (c) Packet4f
+Copyright (c) 16 BfToF32Odd (c) Packet4f
+Copyright (c) 2021 C. Antonio Sanchez <cantonios@google.com>
+Copyright (c) 2021 Chip Kerchner (chip.kerchner@ibm.com)
+Copyright (c) 2009 Claire Maurice
+Copyright (c) 2017 Codeplay Software Limited
+Copyright (c) 2016 Eugene Brevdo <ebrevdo@gmail.com>
+Copyright (c) 2020 Everton Constantino (everton.constantino@ibm.com)
+Copyright (c) 2016 Fabian Giesen
+Copyright (c) 2008-2019 Gael Guennebaud <gael.guennebaud@inria.fr>
+Copyright (c) 2013 Gauthier Brun <brun.gauthier@gmail.com>
+Copyright (c) 2010-2013 Hauke Heibel <hauke.heibel@gmail.com>
+Copyright (c) 2009 Hauke Heibel <hauke.heibel@gmail.com>
+Copyright (c) 2001, 2010, 2011 Intel Corporation
+Copyright (c) 2013 Jean Ceccato <jean.ceccato@ensimag.fr>
+Copyright (c) 2010-2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
+Copyright (c) 2013 Jitse Niesen <jitse@maths.leeds.ac.uk>
+Copyright (c) 2007 Julien Pommier
+Copyright (c) 2009 Keir Mierle <mierle@gmail.com>
+Copyright (c) 2009 Kenneth Riddile <kfriddile@yahoo.com>
+Copyright (c) 2008-2016 Konstantinos Margaritis <markos@freevec.org>
+Copyright (c) 2009 Mathieu Gautier <mathieu.gautier@cea.fr>
+Copyright (c) 2007 Michael Olbrich <michael.olbrich@gmx.net>
+Copyright (c) 2021 NVIDIA CORPORATION.
+Copyright (c) 2013 Nicolas Carre <nicolas.carre@ensimag.fr>
+Copyright (c) 2014-2015 Open Source Robotics Foundation
+Copyright (c) 2013 Pavel Holoborodko <pavel@holoborodko.com>
+Copyright (c) 2014, 2016 Pedro Gonnet (pedro.gonnet@gmail.com)
+Copyright (c) 2013 Pierre Zoppitelli <pierre.zoppitelli@ensimag.fr>
+Copyright (c) 2016, 2018, 2019 Rasmus Munk Larsen (rmlarsen@google.com)
+Copyright (c) 2009 Ricard Marxer <email@ricardmarxer.com>
+Copyright (c) 2009 Rohit Garg <rpg.314@gmail.com>
+Copyright (c) 2017 The TensorFlow Authors
+Copyright (c) 2010 Thomas Capricelli <orzel@freehackers.org>
+Copyright (c) 2011 Timothy E. Holy tim.holy@gmail.com
+Copyright (c) 2016 Tobias Wood <tobias@spinicist.org.uk>
+Copyright (c) 2010 Vincent Lejeune
+Copyright (c) 2018 Wave Computing, Inc.
+Copyright (c) 2011-2014 Willow Garage, Inc.
+Copyright (c) 2014 yoco <peter.xiau@gmail.com>
diff --git a/src/3rdparty/eigen/Eigen/Cholesky b/src/3rdparty/eigen/Eigen/Cholesky
new file mode 100644
index 000000000..a318ceb79
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/Cholesky
@@ -0,0 +1,45 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_CHOLESKY_MODULE_H
+#define EIGEN_CHOLESKY_MODULE_H
+
+#include "Core"
+#include "Jacobi"
+
+#include "src/Core/util/DisableStupidWarnings.h"
+
+/** \defgroup Cholesky_Module Cholesky module
+ *
+ *
+ *
+ * This module provides two variants of the Cholesky decomposition for selfadjoint (hermitian) matrices.
+ * Those decompositions are also accessible via the following methods:
+ * - MatrixBase::llt()
+ * - MatrixBase::ldlt()
+ * - SelfAdjointView::llt()
+ * - SelfAdjointView::ldlt()
+ *
+ * \code
+ * #include <Eigen/Cholesky>
+ * \endcode
+ */
+
+#include "src/Cholesky/LLT.h"
+#include "src/Cholesky/LDLT.h"
+#ifdef EIGEN_USE_LAPACKE
+#ifdef EIGEN_USE_MKL
+#include "mkl_lapacke.h"
+#else
+#include "src/misc/lapacke.h"
+#endif
+#include "src/Cholesky/LLT_LAPACKE.h"
+#endif
+
+#include "src/Core/util/ReenableStupidWarnings.h"
+
+#endif // EIGEN_CHOLESKY_MODULE_H
diff --git a/src/3rdparty/eigen/Eigen/Core b/src/3rdparty/eigen/Eigen/Core
new file mode 100644
index 000000000..5921e15f9
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/Core
@@ -0,0 +1,384 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2007-2011 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_CORE_H
+#define EIGEN_CORE_H
+
+// first thing Eigen does: stop the compiler from reporting useless warnings.
+#include "src/Core/util/DisableStupidWarnings.h"
+
+// then include this file where all our macros are defined. It's really important to do it first because
+// it's where we do all the compiler/OS/arch detections and define most defaults.
+#include "src/Core/util/Macros.h"
+
+// This detects SSE/AVX/NEON/etc. and configure alignment settings
+#include "src/Core/util/ConfigureVectorization.h"
+
+// We need cuda_runtime.h/hip_runtime.h to ensure that
+// the EIGEN_USING_STD macro works properly on the device side
+#if defined(EIGEN_CUDACC)
+ #include <cuda_runtime.h>
+#elif defined(EIGEN_HIPCC)
+ #include <hip/hip_runtime.h>
+#endif
+
+
+#ifdef EIGEN_EXCEPTIONS
+ #include <new>
+#endif
+
+// Disable the ipa-cp-clone optimization flag with MinGW 6.x or newer (enabled by default with -O3)
+// See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=556 for details.
+#if EIGEN_COMP_MINGW && EIGEN_GNUC_AT_LEAST(4,6) && EIGEN_GNUC_AT_MOST(5,5)
+ #pragma GCC optimize ("-fno-ipa-cp-clone")
+#endif
+
+// Prevent ICC from specializing std::complex operators that silently fail
+// on device. This allows us to use our own device-compatible specializations
+// instead.
+#if defined(EIGEN_COMP_ICC) && defined(EIGEN_GPU_COMPILE_PHASE) \
+ && !defined(_OVERRIDE_COMPLEX_SPECIALIZATION_)
+#define _OVERRIDE_COMPLEX_SPECIALIZATION_ 1
+#endif
+#include <complex>
+
+// this include file manages BLAS and MKL related macros
+// and inclusion of their respective header files
+#include "src/Core/util/MKL_support.h"
+
+
+#if defined(EIGEN_HAS_CUDA_FP16) || defined(EIGEN_HAS_HIP_FP16)
+ #define EIGEN_HAS_GPU_FP16
+#endif
+
+#if defined(EIGEN_HAS_CUDA_BF16) || defined(EIGEN_HAS_HIP_BF16)
+ #define EIGEN_HAS_GPU_BF16
+#endif
+
+#if (defined _OPENMP) && (!defined EIGEN_DONT_PARALLELIZE)
+ #define EIGEN_HAS_OPENMP
+#endif
+
+#ifdef EIGEN_HAS_OPENMP
+#include <omp.h>
+#endif
+
+// MSVC for windows mobile does not have the errno.h file
+#if !(EIGEN_COMP_MSVC && EIGEN_OS_WINCE) && !EIGEN_COMP_ARM
+#define EIGEN_HAS_ERRNO
+#endif
+
+#ifdef EIGEN_HAS_ERRNO
+#include <cerrno>
+#endif
+#include <cstddef>
+#include <cstdlib>
+#include <cmath>
+#include <cassert>
+#include <functional>
+#include <sstream>
+#ifndef EIGEN_NO_IO
+ #include <iosfwd>
+#endif
+#include <cstring>
+#include <string>
+#include <limits>
+#include <climits> // for CHAR_BIT
+// for min/max:
+#include <algorithm>
+
+#if EIGEN_HAS_CXX11
+#include <array>
+#endif
+
+// for std::is_nothrow_move_assignable
+#ifdef EIGEN_INCLUDE_TYPE_TRAITS
+#include <type_traits>
+#endif
+
+// for outputting debug info
+#ifdef EIGEN_DEBUG_ASSIGN
+#include <iostream>
+#endif
+
+// required for __cpuid, needs to be included after cmath
+#if EIGEN_COMP_MSVC && EIGEN_ARCH_i386_OR_x86_64 && !EIGEN_OS_WINCE
+ #include <intrin.h>
+#endif
+
+#if defined(EIGEN_USE_SYCL)
+ #undef min
+ #undef max
+ #undef isnan
+ #undef isinf
+ #undef isfinite
+ #include <CL/sycl.hpp>
+ #include <map>
+ #include <memory>
+ #include <utility>
+ #include <thread>
+ #ifndef EIGEN_SYCL_LOCAL_THREAD_DIM0
+ #define EIGEN_SYCL_LOCAL_THREAD_DIM0 16
+ #endif
+ #ifndef EIGEN_SYCL_LOCAL_THREAD_DIM1
+ #define EIGEN_SYCL_LOCAL_THREAD_DIM1 16
+ #endif
+#endif
+
+
+#if defined EIGEN2_SUPPORT_STAGE40_FULL_EIGEN3_STRICTNESS || defined EIGEN2_SUPPORT_STAGE30_FULL_EIGEN3_API || defined EIGEN2_SUPPORT_STAGE20_RESOLVE_API_CONFLICTS || defined EIGEN2_SUPPORT_STAGE10_FULL_EIGEN2_API || defined EIGEN2_SUPPORT
+// This will generate an error message:
+#error Eigen2-support is only available up to version 3.2. Please go to "http://eigen.tuxfamily.org/index.php?title=Eigen2" for further information
+#endif
+
+namespace Eigen {
+
+// we use size_t frequently and we'll never remember to prepend it with std:: every time just to
+// ensure QNX/QCC support
+using std::size_t;
+// gcc 4.6.0 wants std:: for ptrdiff_t
+using std::ptrdiff_t;
+
+}
+
+/** \defgroup Core_Module Core module
+ * This is the main module of Eigen providing dense matrix and vector support
+ * (both fixed and dynamic size) with all the features corresponding to a BLAS library
+ * and much more...
+ *
+ * \code
+ * #include <Eigen/Core>
+ * \endcode
+ */
+
+#include "src/Core/util/Constants.h"
+#include "src/Core/util/Meta.h"
+#include "src/Core/util/ForwardDeclarations.h"
+#include "src/Core/util/StaticAssert.h"
+#include "src/Core/util/XprHelper.h"
+#include "src/Core/util/Memory.h"
+#include "src/Core/util/IntegralConstant.h"
+#include "src/Core/util/SymbolicIndex.h"
+
+#include "src/Core/NumTraits.h"
+#include "src/Core/MathFunctions.h"
+#include "src/Core/GenericPacketMath.h"
+#include "src/Core/MathFunctionsImpl.h"
+#include "src/Core/arch/Default/ConjHelper.h"
+// Generic half float support
+#include "src/Core/arch/Default/Half.h"
+#include "src/Core/arch/Default/BFloat16.h"
+#include "src/Core/arch/Default/TypeCasting.h"
+#include "src/Core/arch/Default/GenericPacketMathFunctionsFwd.h"
+
+#if defined EIGEN_VECTORIZE_AVX512
+ #include "src/Core/arch/SSE/PacketMath.h"
+ #include "src/Core/arch/SSE/TypeCasting.h"
+ #include "src/Core/arch/SSE/Complex.h"
+ #include "src/Core/arch/AVX/PacketMath.h"
+ #include "src/Core/arch/AVX/TypeCasting.h"
+ #include "src/Core/arch/AVX/Complex.h"
+ #include "src/Core/arch/AVX512/PacketMath.h"
+ #include "src/Core/arch/AVX512/TypeCasting.h"
+ #include "src/Core/arch/AVX512/Complex.h"
+ #include "src/Core/arch/SSE/MathFunctions.h"
+ #include "src/Core/arch/AVX/MathFunctions.h"
+ #include "src/Core/arch/AVX512/MathFunctions.h"
+#elif defined EIGEN_VECTORIZE_AVX
+ // Use AVX for floats and doubles, SSE for integers
+ #include "src/Core/arch/SSE/PacketMath.h"
+ #include "src/Core/arch/SSE/TypeCasting.h"
+ #include "src/Core/arch/SSE/Complex.h"
+ #include "src/Core/arch/AVX/PacketMath.h"
+ #include "src/Core/arch/AVX/TypeCasting.h"
+ #include "src/Core/arch/AVX/Complex.h"
+ #include "src/Core/arch/SSE/MathFunctions.h"
+ #include "src/Core/arch/AVX/MathFunctions.h"
+#elif defined EIGEN_VECTORIZE_SSE
+ #include "src/Core/arch/SSE/PacketMath.h"
+ #include "src/Core/arch/SSE/TypeCasting.h"
+ #include "src/Core/arch/SSE/MathFunctions.h"
+ #include "src/Core/arch/SSE/Complex.h"
+#elif defined(EIGEN_VECTORIZE_ALTIVEC) || defined(EIGEN_VECTORIZE_VSX)
+ #include "src/Core/arch/AltiVec/PacketMath.h"
+ #include "src/Core/arch/AltiVec/MathFunctions.h"
+ #include "src/Core/arch/AltiVec/Complex.h"
+#elif defined EIGEN_VECTORIZE_NEON
+ #include "src/Core/arch/NEON/PacketMath.h"
+ #include "src/Core/arch/NEON/TypeCasting.h"
+ #include "src/Core/arch/NEON/MathFunctions.h"
+ #include "src/Core/arch/NEON/Complex.h"
+#elif defined EIGEN_VECTORIZE_SVE
+ #include "src/Core/arch/SVE/PacketMath.h"
+ #include "src/Core/arch/SVE/TypeCasting.h"
+ #include "src/Core/arch/SVE/MathFunctions.h"
+#elif defined EIGEN_VECTORIZE_ZVECTOR
+ #include "src/Core/arch/ZVector/PacketMath.h"
+ #include "src/Core/arch/ZVector/MathFunctions.h"
+ #include "src/Core/arch/ZVector/Complex.h"
+#elif defined EIGEN_VECTORIZE_MSA
+ #include "src/Core/arch/MSA/PacketMath.h"
+ #include "src/Core/arch/MSA/MathFunctions.h"
+ #include "src/Core/arch/MSA/Complex.h"
+#endif
+
+#if defined EIGEN_VECTORIZE_GPU
+ #include "src/Core/arch/GPU/PacketMath.h"
+ #include "src/Core/arch/GPU/MathFunctions.h"
+ #include "src/Core/arch/GPU/TypeCasting.h"
+#endif
+
+#if defined(EIGEN_USE_SYCL)
+ #include "src/Core/arch/SYCL/SyclMemoryModel.h"
+ #include "src/Core/arch/SYCL/InteropHeaders.h"
+#if !defined(EIGEN_DONT_VECTORIZE_SYCL)
+ #include "src/Core/arch/SYCL/PacketMath.h"
+ #include "src/Core/arch/SYCL/MathFunctions.h"
+ #include "src/Core/arch/SYCL/TypeCasting.h"
+#endif
+#endif
+
+#include "src/Core/arch/Default/Settings.h"
+// This file provides generic implementations valid for scalar as well
+#include "src/Core/arch/Default/GenericPacketMathFunctions.h"
+
+#include "src/Core/functors/TernaryFunctors.h"
+#include "src/Core/functors/BinaryFunctors.h"
+#include "src/Core/functors/UnaryFunctors.h"
+#include "src/Core/functors/NullaryFunctors.h"
+#include "src/Core/functors/StlFunctors.h"
+#include "src/Core/functors/AssignmentFunctors.h"
+
+// Specialized functors to enable the processing of complex numbers
+// on CUDA devices
+#ifdef EIGEN_CUDACC
+#include "src/Core/arch/CUDA/Complex.h"
+#endif
+
+#include "src/Core/util/IndexedViewHelper.h"
+#include "src/Core/util/ReshapedHelper.h"
+#include "src/Core/ArithmeticSequence.h"
+#ifndef EIGEN_NO_IO
+ #include "src/Core/IO.h"
+#endif
+#include "src/Core/DenseCoeffsBase.h"
+#include "src/Core/DenseBase.h"
+#include "src/Core/MatrixBase.h"
+#include "src/Core/EigenBase.h"
+
+#include "src/Core/Product.h"
+#include "src/Core/CoreEvaluators.h"
+#include "src/Core/AssignEvaluator.h"
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN // work around Doxygen bug triggered by Assign.h r814874
+ // at least confirmed with Doxygen 1.5.5 and 1.5.6
+ #include "src/Core/Assign.h"
+#endif
+
+#include "src/Core/ArrayBase.h"
+#include "src/Core/util/BlasUtil.h"
+#include "src/Core/DenseStorage.h"
+#include "src/Core/NestByValue.h"
+
+// #include "src/Core/ForceAlignedAccess.h"
+
+#include "src/Core/ReturnByValue.h"
+#include "src/Core/NoAlias.h"
+#include "src/Core/PlainObjectBase.h"
+#include "src/Core/Matrix.h"
+#include "src/Core/Array.h"
+#include "src/Core/CwiseTernaryOp.h"
+#include "src/Core/CwiseBinaryOp.h"
+#include "src/Core/CwiseUnaryOp.h"
+#include "src/Core/CwiseNullaryOp.h"
+#include "src/Core/CwiseUnaryView.h"
+#include "src/Core/SelfCwiseBinaryOp.h"
+#include "src/Core/Dot.h"
+#include "src/Core/StableNorm.h"
+#include "src/Core/Stride.h"
+#include "src/Core/MapBase.h"
+#include "src/Core/Map.h"
+#include "src/Core/Ref.h"
+#include "src/Core/Block.h"
+#include "src/Core/VectorBlock.h"
+#include "src/Core/IndexedView.h"
+#include "src/Core/Reshaped.h"
+#include "src/Core/Transpose.h"
+#include "src/Core/DiagonalMatrix.h"
+#include "src/Core/Diagonal.h"
+#include "src/Core/DiagonalProduct.h"
+#include "src/Core/Redux.h"
+#include "src/Core/Visitor.h"
+#include "src/Core/Fuzzy.h"
+#include "src/Core/Swap.h"
+#include "src/Core/CommaInitializer.h"
+#include "src/Core/GeneralProduct.h"
+#include "src/Core/Solve.h"
+#include "src/Core/Inverse.h"
+#include "src/Core/SolverBase.h"
+#include "src/Core/PermutationMatrix.h"
+#include "src/Core/Transpositions.h"
+#include "src/Core/TriangularMatrix.h"
+#include "src/Core/SelfAdjointView.h"
+#include "src/Core/products/GeneralBlockPanelKernel.h"
+#include "src/Core/products/Parallelizer.h"
+#include "src/Core/ProductEvaluators.h"
+#include "src/Core/products/GeneralMatrixVector.h"
+#include "src/Core/products/GeneralMatrixMatrix.h"
+#include "src/Core/SolveTriangular.h"
+#include "src/Core/products/GeneralMatrixMatrixTriangular.h"
+#include "src/Core/products/SelfadjointMatrixVector.h"
+#include "src/Core/products/SelfadjointMatrixMatrix.h"
+#include "src/Core/products/SelfadjointProduct.h"
+#include "src/Core/products/SelfadjointRank2Update.h"
+#include "src/Core/products/TriangularMatrixVector.h"
+#include "src/Core/products/TriangularMatrixMatrix.h"
+#include "src/Core/products/TriangularSolverMatrix.h"
+#include "src/Core/products/TriangularSolverVector.h"
+#include "src/Core/BandMatrix.h"
+#include "src/Core/CoreIterators.h"
+#include "src/Core/ConditionEstimator.h"
+
+#if defined(EIGEN_VECTORIZE_ALTIVEC) || defined(EIGEN_VECTORIZE_VSX)
+ #include "src/Core/arch/AltiVec/MatrixProduct.h"
+#elif defined EIGEN_VECTORIZE_NEON
+ #include "src/Core/arch/NEON/GeneralBlockPanelKernel.h"
+#endif
+
+#include "src/Core/BooleanRedux.h"
+#include "src/Core/Select.h"
+#include "src/Core/VectorwiseOp.h"
+#include "src/Core/PartialReduxEvaluator.h"
+#include "src/Core/Random.h"
+#include "src/Core/Replicate.h"
+#include "src/Core/Reverse.h"
+#include "src/Core/ArrayWrapper.h"
+#include "src/Core/StlIterators.h"
+
+#ifdef EIGEN_USE_BLAS
+#include "src/Core/products/GeneralMatrixMatrix_BLAS.h"
+#include "src/Core/products/GeneralMatrixVector_BLAS.h"
+#include "src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h"
+#include "src/Core/products/SelfadjointMatrixMatrix_BLAS.h"
+#include "src/Core/products/SelfadjointMatrixVector_BLAS.h"
+#include "src/Core/products/TriangularMatrixMatrix_BLAS.h"
+#include "src/Core/products/TriangularMatrixVector_BLAS.h"
+#include "src/Core/products/TriangularSolverMatrix_BLAS.h"
+#endif // EIGEN_USE_BLAS
+
+#ifdef EIGEN_USE_MKL_VML
+#include "src/Core/Assign_MKL.h"
+#endif
+
+#include "src/Core/GlobalFunctions.h"
+
+#include "src/Core/util/ReenableStupidWarnings.h"
+
+#endif // EIGEN_CORE_H
diff --git a/src/3rdparty/eigen/Eigen/Dense b/src/3rdparty/eigen/Eigen/Dense
new file mode 100644
index 000000000..5768910bd
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/Dense
@@ -0,0 +1,7 @@
+#include "Core"
+#include "LU"
+#include "Cholesky"
+#include "QR"
+#include "SVD"
+#include "Geometry"
+#include "Eigenvalues"
diff --git a/src/3rdparty/eigen/Eigen/Eigenvalues b/src/3rdparty/eigen/Eigen/Eigenvalues
new file mode 100644
index 000000000..5467a2e7b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/Eigenvalues
@@ -0,0 +1,60 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_EIGENVALUES_MODULE_H
+#define EIGEN_EIGENVALUES_MODULE_H
+
+#include "Core"
+
+#include "Cholesky"
+#include "Jacobi"
+#include "Householder"
+#include "LU"
+#include "Geometry"
+
+#include "src/Core/util/DisableStupidWarnings.h"
+
+/** \defgroup Eigenvalues_Module Eigenvalues module
+ *
+ *
+ *
+ * This module mainly provides various eigenvalue solvers.
+ * This module also provides some MatrixBase methods, including:
+ * - MatrixBase::eigenvalues(),
+ * - MatrixBase::operatorNorm()
+ *
+ * \code
+ * #include <Eigen/Eigenvalues>
+ * \endcode
+ */
+
+#include "src/misc/RealSvd2x2.h"
+#include "src/Eigenvalues/Tridiagonalization.h"
+#include "src/Eigenvalues/RealSchur.h"
+#include "src/Eigenvalues/EigenSolver.h"
+#include "src/Eigenvalues/SelfAdjointEigenSolver.h"
+#include "src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h"
+#include "src/Eigenvalues/HessenbergDecomposition.h"
+#include "src/Eigenvalues/ComplexSchur.h"
+#include "src/Eigenvalues/ComplexEigenSolver.h"
+#include "src/Eigenvalues/RealQZ.h"
+#include "src/Eigenvalues/GeneralizedEigenSolver.h"
+#include "src/Eigenvalues/MatrixBaseEigenvalues.h"
+#ifdef EIGEN_USE_LAPACKE
+#ifdef EIGEN_USE_MKL
+#include "mkl_lapacke.h"
+#else
+#include "src/misc/lapacke.h"
+#endif
+#include "src/Eigenvalues/RealSchur_LAPACKE.h"
+#include "src/Eigenvalues/ComplexSchur_LAPACKE.h"
+#include "src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h"
+#endif
+
+#include "src/Core/util/ReenableStupidWarnings.h"
+
+#endif // EIGEN_EIGENVALUES_MODULE_H
diff --git a/src/3rdparty/eigen/Eigen/Geometry b/src/3rdparty/eigen/Eigen/Geometry
new file mode 100644
index 000000000..bc78110a8
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/Geometry
@@ -0,0 +1,59 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GEOMETRY_MODULE_H
+#define EIGEN_GEOMETRY_MODULE_H
+
+#include "Core"
+
+#include "SVD"
+#include "LU"
+#include <limits>
+
+#include "src/Core/util/DisableStupidWarnings.h"
+
+/** \defgroup Geometry_Module Geometry module
+ *
+ * This module provides support for:
+ * - fixed-size homogeneous transformations
+ * - translation, scaling, 2D and 3D rotations
+ * - \link Quaternion quaternions \endlink
+ * - cross products (\ref MatrixBase::cross, \ref MatrixBase::cross3)
+ * - orthognal vector generation (\ref MatrixBase::unitOrthogonal)
+ * - some linear components: \link ParametrizedLine parametrized-lines \endlink and \link Hyperplane hyperplanes \endlink
+ * - \link AlignedBox axis aligned bounding boxes \endlink
+ * - \link umeyama least-square transformation fitting \endlink
+ *
+ * \code
+ * #include <Eigen/Geometry>
+ * \endcode
+ */
+
+#include "src/Geometry/OrthoMethods.h"
+#include "src/Geometry/EulerAngles.h"
+
+#include "src/Geometry/Homogeneous.h"
+#include "src/Geometry/RotationBase.h"
+#include "src/Geometry/Rotation2D.h"
+#include "src/Geometry/Quaternion.h"
+#include "src/Geometry/AngleAxis.h"
+#include "src/Geometry/Transform.h"
+#include "src/Geometry/Translation.h"
+#include "src/Geometry/Scaling.h"
+#include "src/Geometry/Hyperplane.h"
+#include "src/Geometry/ParametrizedLine.h"
+#include "src/Geometry/AlignedBox.h"
+#include "src/Geometry/Umeyama.h"
+
+// Use the SSE optimized version whenever possible.
+#if (defined EIGEN_VECTORIZE_SSE) || (defined EIGEN_VECTORIZE_NEON)
+#include "src/Geometry/arch/Geometry_SIMD.h"
+#endif
+
+#include "src/Core/util/ReenableStupidWarnings.h"
+
+#endif // EIGEN_GEOMETRY_MODULE_H
diff --git a/src/3rdparty/eigen/Eigen/Householder b/src/3rdparty/eigen/Eigen/Householder
new file mode 100644
index 000000000..f2fa79969
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/Householder
@@ -0,0 +1,29 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_HOUSEHOLDER_MODULE_H
+#define EIGEN_HOUSEHOLDER_MODULE_H
+
+#include "Core"
+
+#include "src/Core/util/DisableStupidWarnings.h"
+
+/** \defgroup Householder_Module Householder module
+ * This module provides Householder transformations.
+ *
+ * \code
+ * #include <Eigen/Householder>
+ * \endcode
+ */
+
+#include "src/Householder/Householder.h"
+#include "src/Householder/HouseholderSequence.h"
+#include "src/Householder/BlockHouseholder.h"
+
+#include "src/Core/util/ReenableStupidWarnings.h"
+
+#endif // EIGEN_HOUSEHOLDER_MODULE_H
diff --git a/src/3rdparty/eigen/Eigen/Jacobi b/src/3rdparty/eigen/Eigen/Jacobi
new file mode 100644
index 000000000..43edc7a19
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/Jacobi
@@ -0,0 +1,32 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_JACOBI_MODULE_H
+#define EIGEN_JACOBI_MODULE_H
+
+#include "Core"
+
+#include "src/Core/util/DisableStupidWarnings.h"
+
+/** \defgroup Jacobi_Module Jacobi module
+ * This module provides Jacobi and Givens rotations.
+ *
+ * \code
+ * #include <Eigen/Jacobi>
+ * \endcode
+ *
+ * In addition to listed classes, it defines the two following MatrixBase methods to apply a Jacobi or Givens rotation:
+ * - MatrixBase::applyOnTheLeft()
+ * - MatrixBase::applyOnTheRight().
+ */
+
+#include "src/Jacobi/Jacobi.h"
+
+#include "src/Core/util/ReenableStupidWarnings.h"
+
+#endif // EIGEN_JACOBI_MODULE_H
+
diff --git a/src/3rdparty/eigen/Eigen/LU b/src/3rdparty/eigen/Eigen/LU
new file mode 100644
index 000000000..1236ceb04
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/LU
@@ -0,0 +1,47 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_LU_MODULE_H
+#define EIGEN_LU_MODULE_H
+
+#include "Core"
+
+#include "src/Core/util/DisableStupidWarnings.h"
+
+/** \defgroup LU_Module LU module
+ * This module includes %LU decomposition and related notions such as matrix inversion and determinant.
+ * This module defines the following MatrixBase methods:
+ * - MatrixBase::inverse()
+ * - MatrixBase::determinant()
+ *
+ * \code
+ * #include <Eigen/LU>
+ * \endcode
+ */
+
+#include "src/misc/Kernel.h"
+#include "src/misc/Image.h"
+#include "src/LU/FullPivLU.h"
+#include "src/LU/PartialPivLU.h"
+#ifdef EIGEN_USE_LAPACKE
+#ifdef EIGEN_USE_MKL
+#include "mkl_lapacke.h"
+#else
+#include "src/misc/lapacke.h"
+#endif
+#include "src/LU/PartialPivLU_LAPACKE.h"
+#endif
+#include "src/LU/Determinant.h"
+#include "src/LU/InverseImpl.h"
+
+#if defined EIGEN_VECTORIZE_SSE || defined EIGEN_VECTORIZE_NEON
+ #include "src/LU/arch/InverseSize4.h"
+#endif
+
+#include "src/Core/util/ReenableStupidWarnings.h"
+
+#endif // EIGEN_LU_MODULE_H
diff --git a/src/3rdparty/eigen/Eigen/QR b/src/3rdparty/eigen/Eigen/QR
new file mode 100644
index 000000000..8465b62ce
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/QR
@@ -0,0 +1,50 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_QR_MODULE_H
+#define EIGEN_QR_MODULE_H
+
+#include "Core"
+
+#include "Cholesky"
+#include "Jacobi"
+#include "Householder"
+
+#include "src/Core/util/DisableStupidWarnings.h"
+
+/** \defgroup QR_Module QR module
+ *
+ *
+ *
+ * This module provides various QR decompositions
+ * This module also provides some MatrixBase methods, including:
+ * - MatrixBase::householderQr()
+ * - MatrixBase::colPivHouseholderQr()
+ * - MatrixBase::fullPivHouseholderQr()
+ *
+ * \code
+ * #include <Eigen/QR>
+ * \endcode
+ */
+
+#include "src/QR/HouseholderQR.h"
+#include "src/QR/FullPivHouseholderQR.h"
+#include "src/QR/ColPivHouseholderQR.h"
+#include "src/QR/CompleteOrthogonalDecomposition.h"
+#ifdef EIGEN_USE_LAPACKE
+#ifdef EIGEN_USE_MKL
+#include "mkl_lapacke.h"
+#else
+#include "src/misc/lapacke.h"
+#endif
+#include "src/QR/HouseholderQR_LAPACKE.h"
+#include "src/QR/ColPivHouseholderQR_LAPACKE.h"
+#endif
+
+#include "src/Core/util/ReenableStupidWarnings.h"
+
+#endif // EIGEN_QR_MODULE_H
diff --git a/src/3rdparty/eigen/Eigen/SVD b/src/3rdparty/eigen/Eigen/SVD
new file mode 100644
index 000000000..345179496
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/SVD
@@ -0,0 +1,50 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SVD_MODULE_H
+#define EIGEN_SVD_MODULE_H
+
+#include "QR"
+#include "Householder"
+#include "Jacobi"
+
+#include "src/Core/util/DisableStupidWarnings.h"
+
+/** \defgroup SVD_Module SVD module
+ *
+ *
+ *
+ * This module provides SVD decomposition for matrices (both real and complex).
+ * Two decomposition algorithms are provided:
+ * - JacobiSVD implementing two-sided Jacobi iterations is numerically very accurate, fast for small matrices, but very slow for larger ones.
+ * - BDCSVD implementing a recursive divide & conquer strategy on top of an upper-bidiagonalization which remains fast for large problems.
+ * These decompositions are accessible via the respective classes and following MatrixBase methods:
+ * - MatrixBase::jacobiSvd()
+ * - MatrixBase::bdcSvd()
+ *
+ * \code
+ * #include <Eigen/SVD>
+ * \endcode
+ */
+
+#include "src/misc/RealSvd2x2.h"
+#include "src/SVD/UpperBidiagonalization.h"
+#include "src/SVD/SVDBase.h"
+#include "src/SVD/JacobiSVD.h"
+#include "src/SVD/BDCSVD.h"
+#if defined(EIGEN_USE_LAPACKE) && !defined(EIGEN_USE_LAPACKE_STRICT)
+#ifdef EIGEN_USE_MKL
+#include "mkl_lapacke.h"
+#else
+#include "src/misc/lapacke.h"
+#endif
+#include "src/SVD/JacobiSVD_LAPACKE.h"
+#endif
+
+#include "src/Core/util/ReenableStupidWarnings.h"
+
+#endif // EIGEN_SVD_MODULE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Cholesky/LDLT.h b/src/3rdparty/eigen/Eigen/src/Cholesky/LDLT.h
new file mode 100644
index 000000000..1013ca045
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Cholesky/LDLT.h
@@ -0,0 +1,688 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2009 Keir Mierle <mierle@gmail.com>
+// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2011 Timothy E. Holy <tim.holy@gmail.com >
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_LDLT_H
+#define EIGEN_LDLT_H
+
+namespace Eigen {
+
+namespace internal {
+ template<typename _MatrixType, int _UpLo> struct traits<LDLT<_MatrixType, _UpLo> >
+ : traits<_MatrixType>
+ {
+ typedef MatrixXpr XprKind;
+ typedef SolverStorage StorageKind;
+ typedef int StorageIndex;
+ enum { Flags = 0 };
+ };
+
+ template<typename MatrixType, int UpLo> struct LDLT_Traits;
+
+ // PositiveSemiDef means positive semi-definite and non-zero; same for NegativeSemiDef
+ enum SignMatrix { PositiveSemiDef, NegativeSemiDef, ZeroSign, Indefinite };
+}
+
+/** \ingroup Cholesky_Module
+ *
+ * \class LDLT
+ *
+ * \brief Robust Cholesky decomposition of a matrix with pivoting
+ *
+ * \tparam _MatrixType the type of the matrix of which to compute the LDL^T Cholesky decomposition
+ * \tparam _UpLo the triangular part that will be used for the decompositon: Lower (default) or Upper.
+ * The other triangular part won't be read.
+ *
+ * Perform a robust Cholesky decomposition of a positive semidefinite or negative semidefinite
+ * matrix \f$ A \f$ such that \f$ A = P^TLDL^*P \f$, where P is a permutation matrix, L
+ * is lower triangular with a unit diagonal and D is a diagonal matrix.
+ *
+ * The decomposition uses pivoting to ensure stability, so that D will have
+ * zeros in the bottom right rank(A) - n submatrix. Avoiding the square root
+ * on D also stabilizes the computation.
+ *
+ * Remember that Cholesky decompositions are not rank-revealing. Also, do not use a Cholesky
+ * decomposition to determine whether a system of equations has a solution.
+ *
+ * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism.
+ *
+ * \sa MatrixBase::ldlt(), SelfAdjointView::ldlt(), class LLT
+ */
+template<typename _MatrixType, int _UpLo> class LDLT
+ : public SolverBase<LDLT<_MatrixType, _UpLo> >
+{
+ public:
+ typedef _MatrixType MatrixType;
+ typedef SolverBase<LDLT> Base;
+ friend class SolverBase<LDLT>;
+
+ EIGEN_GENERIC_PUBLIC_INTERFACE(LDLT)
+ enum {
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
+ UpLo = _UpLo
+ };
+ typedef Matrix<Scalar, RowsAtCompileTime, 1, 0, MaxRowsAtCompileTime, 1> TmpMatrixType;
+
+ typedef Transpositions<RowsAtCompileTime, MaxRowsAtCompileTime> TranspositionType;
+ typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationType;
+
+ typedef internal::LDLT_Traits<MatrixType,UpLo> Traits;
+
+ /** \brief Default Constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via LDLT::compute(const MatrixType&).
+ */
+ LDLT()
+ : m_matrix(),
+ m_transpositions(),
+ m_sign(internal::ZeroSign),
+ m_isInitialized(false)
+ {}
+
+ /** \brief Default Constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem \a size.
+ * \sa LDLT()
+ */
+ explicit LDLT(Index size)
+ : m_matrix(size, size),
+ m_transpositions(size),
+ m_temporary(size),
+ m_sign(internal::ZeroSign),
+ m_isInitialized(false)
+ {}
+
+ /** \brief Constructor with decomposition
+ *
+ * This calculates the decomposition for the input \a matrix.
+ *
+ * \sa LDLT(Index size)
+ */
+ template<typename InputType>
+ explicit LDLT(const EigenBase<InputType>& matrix)
+ : m_matrix(matrix.rows(), matrix.cols()),
+ m_transpositions(matrix.rows()),
+ m_temporary(matrix.rows()),
+ m_sign(internal::ZeroSign),
+ m_isInitialized(false)
+ {
+ compute(matrix.derived());
+ }
+
+ /** \brief Constructs a LDLT factorization from a given matrix
+ *
+ * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c MatrixType is a Eigen::Ref.
+ *
+ * \sa LDLT(const EigenBase&)
+ */
+ template<typename InputType>
+ explicit LDLT(EigenBase<InputType>& matrix)
+ : m_matrix(matrix.derived()),
+ m_transpositions(matrix.rows()),
+ m_temporary(matrix.rows()),
+ m_sign(internal::ZeroSign),
+ m_isInitialized(false)
+ {
+ compute(matrix.derived());
+ }
+
+ /** Clear any existing decomposition
+ * \sa rankUpdate(w,sigma)
+ */
+ void setZero()
+ {
+ m_isInitialized = false;
+ }
+
+ /** \returns a view of the upper triangular matrix U */
+ inline typename Traits::MatrixU matrixU() const
+ {
+ eigen_assert(m_isInitialized && "LDLT is not initialized.");
+ return Traits::getU(m_matrix);
+ }
+
+ /** \returns a view of the lower triangular matrix L */
+ inline typename Traits::MatrixL matrixL() const
+ {
+ eigen_assert(m_isInitialized && "LDLT is not initialized.");
+ return Traits::getL(m_matrix);
+ }
+
+ /** \returns the permutation matrix P as a transposition sequence.
+ */
+ inline const TranspositionType& transpositionsP() const
+ {
+ eigen_assert(m_isInitialized && "LDLT is not initialized.");
+ return m_transpositions;
+ }
+
+ /** \returns the coefficients of the diagonal matrix D */
+ inline Diagonal<const MatrixType> vectorD() const
+ {
+ eigen_assert(m_isInitialized && "LDLT is not initialized.");
+ return m_matrix.diagonal();
+ }
+
+ /** \returns true if the matrix is positive (semidefinite) */
+ inline bool isPositive() const
+ {
+ eigen_assert(m_isInitialized && "LDLT is not initialized.");
+ return m_sign == internal::PositiveSemiDef || m_sign == internal::ZeroSign;
+ }
+
+ /** \returns true if the matrix is negative (semidefinite) */
+ inline bool isNegative(void) const
+ {
+ eigen_assert(m_isInitialized && "LDLT is not initialized.");
+ return m_sign == internal::NegativeSemiDef || m_sign == internal::ZeroSign;
+ }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** \returns a solution x of \f$ A x = b \f$ using the current decomposition of A.
+ *
+ * This function also supports in-place solves using the syntax <tt>x = decompositionObject.solve(x)</tt> .
+ *
+ * \note_about_checking_solutions
+ *
+ * More precisely, this method solves \f$ A x = b \f$ using the decomposition \f$ A = P^T L D L^* P \f$
+ * by solving the systems \f$ P^T y_1 = b \f$, \f$ L y_2 = y_1 \f$, \f$ D y_3 = y_2 \f$,
+ * \f$ L^* y_4 = y_3 \f$ and \f$ P x = y_4 \f$ in succession. If the matrix \f$ A \f$ is singular, then
+ * \f$ D \f$ will also be singular (all the other matrices are invertible). In that case, the
+ * least-square solution of \f$ D y_3 = y_2 \f$ is computed. This does not mean that this function
+ * computes the least-square solution of \f$ A x = b \f$ if \f$ A \f$ is singular.
+ *
+ * \sa MatrixBase::ldlt(), SelfAdjointView::ldlt()
+ */
+ template<typename Rhs>
+ inline const Solve<LDLT, Rhs>
+ solve(const MatrixBase<Rhs>& b) const;
+ #endif
+
+ template<typename Derived>
+ bool solveInPlace(MatrixBase<Derived> &bAndX) const;
+
+ template<typename InputType>
+ LDLT& compute(const EigenBase<InputType>& matrix);
+
+ /** \returns an estimate of the reciprocal condition number of the matrix of
+ * which \c *this is the LDLT decomposition.
+ */
+ RealScalar rcond() const
+ {
+ eigen_assert(m_isInitialized && "LDLT is not initialized.");
+ return internal::rcond_estimate_helper(m_l1_norm, *this);
+ }
+
+ template <typename Derived>
+ LDLT& rankUpdate(const MatrixBase<Derived>& w, const RealScalar& alpha=1);
+
+ /** \returns the internal LDLT decomposition matrix
+ *
+ * TODO: document the storage layout
+ */
+ inline const MatrixType& matrixLDLT() const
+ {
+ eigen_assert(m_isInitialized && "LDLT is not initialized.");
+ return m_matrix;
+ }
+
+ MatrixType reconstructedMatrix() const;
+
+ /** \returns the adjoint of \c *this, that is, a const reference to the decomposition itself as the underlying matrix is self-adjoint.
+ *
+ * This method is provided for compatibility with other matrix decompositions, thus enabling generic code such as:
+ * \code x = decomposition.adjoint().solve(b) \endcode
+ */
+ const LDLT& adjoint() const { return *this; };
+
+ EIGEN_DEVICE_FUNC inline EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
+ EIGEN_DEVICE_FUNC inline EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
+
+ /** \brief Reports whether previous computation was successful.
+ *
+ * \returns \c Success if computation was successful,
+ * \c NumericalIssue if the factorization failed because of a zero pivot.
+ */
+ ComputationInfo info() const
+ {
+ eigen_assert(m_isInitialized && "LDLT is not initialized.");
+ return m_info;
+ }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename RhsType, typename DstType>
+ void _solve_impl(const RhsType &rhs, DstType &dst) const;
+
+ template<bool Conjugate, typename RhsType, typename DstType>
+ void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const;
+ #endif
+
+ protected:
+
+ static void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ }
+
+ /** \internal
+ * Used to compute and store the Cholesky decomposition A = L D L^* = U^* D U.
+ * The strict upper part is used during the decomposition, the strict lower
+ * part correspond to the coefficients of L (its diagonal is equal to 1 and
+ * is not stored), and the diagonal entries correspond to D.
+ */
+ MatrixType m_matrix;
+ RealScalar m_l1_norm;
+ TranspositionType m_transpositions;
+ TmpMatrixType m_temporary;
+ internal::SignMatrix m_sign;
+ bool m_isInitialized;
+ ComputationInfo m_info;
+};
+
+namespace internal {
+
+template<int UpLo> struct ldlt_inplace;
+
+template<> struct ldlt_inplace<Lower>
+{
+ template<typename MatrixType, typename TranspositionType, typename Workspace>
+ static bool unblocked(MatrixType& mat, TranspositionType& transpositions, Workspace& temp, SignMatrix& sign)
+ {
+ using std::abs;
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename MatrixType::RealScalar RealScalar;
+ typedef typename TranspositionType::StorageIndex IndexType;
+ eigen_assert(mat.rows()==mat.cols());
+ const Index size = mat.rows();
+ bool found_zero_pivot = false;
+ bool ret = true;
+
+ if (size <= 1)
+ {
+ transpositions.setIdentity();
+ if(size==0) sign = ZeroSign;
+ else if (numext::real(mat.coeff(0,0)) > static_cast<RealScalar>(0) ) sign = PositiveSemiDef;
+ else if (numext::real(mat.coeff(0,0)) < static_cast<RealScalar>(0)) sign = NegativeSemiDef;
+ else sign = ZeroSign;
+ return true;
+ }
+
+ for (Index k = 0; k < size; ++k)
+ {
+ // Find largest diagonal element
+ Index index_of_biggest_in_corner;
+ mat.diagonal().tail(size-k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner);
+ index_of_biggest_in_corner += k;
+
+ transpositions.coeffRef(k) = IndexType(index_of_biggest_in_corner);
+ if(k != index_of_biggest_in_corner)
+ {
+ // apply the transposition while taking care to consider only
+ // the lower triangular part
+ Index s = size-index_of_biggest_in_corner-1; // trailing size after the biggest element
+ mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k));
+ mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s));
+ std::swap(mat.coeffRef(k,k),mat.coeffRef(index_of_biggest_in_corner,index_of_biggest_in_corner));
+ for(Index i=k+1;i<index_of_biggest_in_corner;++i)
+ {
+ Scalar tmp = mat.coeffRef(i,k);
+ mat.coeffRef(i,k) = numext::conj(mat.coeffRef(index_of_biggest_in_corner,i));
+ mat.coeffRef(index_of_biggest_in_corner,i) = numext::conj(tmp);
+ }
+ if(NumTraits<Scalar>::IsComplex)
+ mat.coeffRef(index_of_biggest_in_corner,k) = numext::conj(mat.coeff(index_of_biggest_in_corner,k));
+ }
+
+ // partition the matrix:
+ // A00 | - | -
+ // lu = A10 | A11 | -
+ // A20 | A21 | A22
+ Index rs = size - k - 1;
+ Block<MatrixType,Dynamic,1> A21(mat,k+1,k,rs,1);
+ Block<MatrixType,1,Dynamic> A10(mat,k,0,1,k);
+ Block<MatrixType,Dynamic,Dynamic> A20(mat,k+1,0,rs,k);
+
+ if(k>0)
+ {
+ temp.head(k) = mat.diagonal().real().head(k).asDiagonal() * A10.adjoint();
+ mat.coeffRef(k,k) -= (A10 * temp.head(k)).value();
+ if(rs>0)
+ A21.noalias() -= A20 * temp.head(k);
+ }
+
+ // In some previous versions of Eigen (e.g., 3.2.1), the scaling was omitted if the pivot
+ // was smaller than the cutoff value. However, since LDLT is not rank-revealing
+ // we should only make sure that we do not introduce INF or NaN values.
+ // Remark that LAPACK also uses 0 as the cutoff value.
+ RealScalar realAkk = numext::real(mat.coeffRef(k,k));
+ bool pivot_is_valid = (abs(realAkk) > RealScalar(0));
+
+ if(k==0 && !pivot_is_valid)
+ {
+ // The entire diagonal is zero, there is nothing more to do
+ // except filling the transpositions, and checking whether the matrix is zero.
+ sign = ZeroSign;
+ for(Index j = 0; j<size; ++j)
+ {
+ transpositions.coeffRef(j) = IndexType(j);
+ ret = ret && (mat.col(j).tail(size-j-1).array()==Scalar(0)).all();
+ }
+ return ret;
+ }
+
+ if((rs>0) && pivot_is_valid)
+ A21 /= realAkk;
+ else if(rs>0)
+ ret = ret && (A21.array()==Scalar(0)).all();
+
+ if(found_zero_pivot && pivot_is_valid) ret = false; // factorization failed
+ else if(!pivot_is_valid) found_zero_pivot = true;
+
+ if (sign == PositiveSemiDef) {
+ if (realAkk < static_cast<RealScalar>(0)) sign = Indefinite;
+ } else if (sign == NegativeSemiDef) {
+ if (realAkk > static_cast<RealScalar>(0)) sign = Indefinite;
+ } else if (sign == ZeroSign) {
+ if (realAkk > static_cast<RealScalar>(0)) sign = PositiveSemiDef;
+ else if (realAkk < static_cast<RealScalar>(0)) sign = NegativeSemiDef;
+ }
+ }
+
+ return ret;
+ }
+
+ // Reference for the algorithm: Davis and Hager, "Multiple Rank
+ // Modifications of a Sparse Cholesky Factorization" (Algorithm 1)
+ // Trivial rearrangements of their computations (Timothy E. Holy)
+ // allow their algorithm to work for rank-1 updates even if the
+ // original matrix is not of full rank.
+ // Here only rank-1 updates are implemented, to reduce the
+ // requirement for intermediate storage and improve accuracy
+ template<typename MatrixType, typename WDerived>
+ static bool updateInPlace(MatrixType& mat, MatrixBase<WDerived>& w, const typename MatrixType::RealScalar& sigma=1)
+ {
+ using numext::isfinite;
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename MatrixType::RealScalar RealScalar;
+
+ const Index size = mat.rows();
+ eigen_assert(mat.cols() == size && w.size()==size);
+
+ RealScalar alpha = 1;
+
+ // Apply the update
+ for (Index j = 0; j < size; j++)
+ {
+ // Check for termination due to an original decomposition of low-rank
+ if (!(isfinite)(alpha))
+ break;
+
+ // Update the diagonal terms
+ RealScalar dj = numext::real(mat.coeff(j,j));
+ Scalar wj = w.coeff(j);
+ RealScalar swj2 = sigma*numext::abs2(wj);
+ RealScalar gamma = dj*alpha + swj2;
+
+ mat.coeffRef(j,j) += swj2/alpha;
+ alpha += swj2/dj;
+
+
+ // Update the terms of L
+ Index rs = size-j-1;
+ w.tail(rs) -= wj * mat.col(j).tail(rs);
+ if(gamma != 0)
+ mat.col(j).tail(rs) += (sigma*numext::conj(wj)/gamma)*w.tail(rs);
+ }
+ return true;
+ }
+
+ template<typename MatrixType, typename TranspositionType, typename Workspace, typename WType>
+ static bool update(MatrixType& mat, const TranspositionType& transpositions, Workspace& tmp, const WType& w, const typename MatrixType::RealScalar& sigma=1)
+ {
+ // Apply the permutation to the input w
+ tmp = transpositions * w;
+
+ return ldlt_inplace<Lower>::updateInPlace(mat,tmp,sigma);
+ }
+};
+
+template<> struct ldlt_inplace<Upper>
+{
+ template<typename MatrixType, typename TranspositionType, typename Workspace>
+ static EIGEN_STRONG_INLINE bool unblocked(MatrixType& mat, TranspositionType& transpositions, Workspace& temp, SignMatrix& sign)
+ {
+ Transpose<MatrixType> matt(mat);
+ return ldlt_inplace<Lower>::unblocked(matt, transpositions, temp, sign);
+ }
+
+ template<typename MatrixType, typename TranspositionType, typename Workspace, typename WType>
+ static EIGEN_STRONG_INLINE bool update(MatrixType& mat, TranspositionType& transpositions, Workspace& tmp, WType& w, const typename MatrixType::RealScalar& sigma=1)
+ {
+ Transpose<MatrixType> matt(mat);
+ return ldlt_inplace<Lower>::update(matt, transpositions, tmp, w.conjugate(), sigma);
+ }
+};
+
+template<typename MatrixType> struct LDLT_Traits<MatrixType,Lower>
+{
+ typedef const TriangularView<const MatrixType, UnitLower> MatrixL;
+ typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitUpper> MatrixU;
+ static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); }
+ static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); }
+};
+
+template<typename MatrixType> struct LDLT_Traits<MatrixType,Upper>
+{
+ typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitLower> MatrixL;
+ typedef const TriangularView<const MatrixType, UnitUpper> MatrixU;
+ static inline MatrixL getL(const MatrixType& m) { return MatrixL(m.adjoint()); }
+ static inline MatrixU getU(const MatrixType& m) { return MatrixU(m); }
+};
+
+} // end namespace internal
+
+/** Compute / recompute the LDLT decomposition A = L D L^* = U^* D U of \a matrix
+ */
+template<typename MatrixType, int _UpLo>
+template<typename InputType>
+LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::compute(const EigenBase<InputType>& a)
+{
+ check_template_parameters();
+
+ eigen_assert(a.rows()==a.cols());
+ const Index size = a.rows();
+
+ m_matrix = a.derived();
+
+ // Compute matrix L1 norm = max abs column sum.
+ m_l1_norm = RealScalar(0);
+ // TODO move this code to SelfAdjointView
+ for (Index col = 0; col < size; ++col) {
+ RealScalar abs_col_sum;
+ if (_UpLo == Lower)
+ abs_col_sum = m_matrix.col(col).tail(size - col).template lpNorm<1>() + m_matrix.row(col).head(col).template lpNorm<1>();
+ else
+ abs_col_sum = m_matrix.col(col).head(col).template lpNorm<1>() + m_matrix.row(col).tail(size - col).template lpNorm<1>();
+ if (abs_col_sum > m_l1_norm)
+ m_l1_norm = abs_col_sum;
+ }
+
+ m_transpositions.resize(size);
+ m_isInitialized = false;
+ m_temporary.resize(size);
+ m_sign = internal::ZeroSign;
+
+ m_info = internal::ldlt_inplace<UpLo>::unblocked(m_matrix, m_transpositions, m_temporary, m_sign) ? Success : NumericalIssue;
+
+ m_isInitialized = true;
+ return *this;
+}
+
+/** Update the LDLT decomposition: given A = L D L^T, efficiently compute the decomposition of A + sigma w w^T.
+ * \param w a vector to be incorporated into the decomposition.
+ * \param sigma a scalar, +1 for updates and -1 for "downdates," which correspond to removing previously-added column vectors. Optional; default value is +1.
+ * \sa setZero()
+ */
+template<typename MatrixType, int _UpLo>
+template<typename Derived>
+LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::rankUpdate(const MatrixBase<Derived>& w, const typename LDLT<MatrixType,_UpLo>::RealScalar& sigma)
+{
+ typedef typename TranspositionType::StorageIndex IndexType;
+ const Index size = w.rows();
+ if (m_isInitialized)
+ {
+ eigen_assert(m_matrix.rows()==size);
+ }
+ else
+ {
+ m_matrix.resize(size,size);
+ m_matrix.setZero();
+ m_transpositions.resize(size);
+ for (Index i = 0; i < size; i++)
+ m_transpositions.coeffRef(i) = IndexType(i);
+ m_temporary.resize(size);
+ m_sign = sigma>=0 ? internal::PositiveSemiDef : internal::NegativeSemiDef;
+ m_isInitialized = true;
+ }
+
+ internal::ldlt_inplace<UpLo>::update(m_matrix, m_transpositions, m_temporary, w, sigma);
+
+ return *this;
+}
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+template<typename _MatrixType, int _UpLo>
+template<typename RhsType, typename DstType>
+void LDLT<_MatrixType,_UpLo>::_solve_impl(const RhsType &rhs, DstType &dst) const
+{
+ _solve_impl_transposed<true>(rhs, dst);
+}
+
+template<typename _MatrixType,int _UpLo>
+template<bool Conjugate, typename RhsType, typename DstType>
+void LDLT<_MatrixType,_UpLo>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const
+{
+ // dst = P b
+ dst = m_transpositions * rhs;
+
+ // dst = L^-1 (P b)
+ // dst = L^-*T (P b)
+ matrixL().template conjugateIf<!Conjugate>().solveInPlace(dst);
+
+ // dst = D^-* (L^-1 P b)
+ // dst = D^-1 (L^-*T P b)
+ // more precisely, use pseudo-inverse of D (see bug 241)
+ using std::abs;
+ const typename Diagonal<const MatrixType>::RealReturnType vecD(vectorD());
+ // In some previous versions, tolerance was set to the max of 1/highest (or rather numeric_limits::min())
+ // and the maximal diagonal entry * epsilon as motivated by LAPACK's xGELSS:
+ // RealScalar tolerance = numext::maxi(vecD.array().abs().maxCoeff() * NumTraits<RealScalar>::epsilon(),RealScalar(1) / NumTraits<RealScalar>::highest());
+ // However, LDLT is not rank revealing, and so adjusting the tolerance wrt to the highest
+ // diagonal element is not well justified and leads to numerical issues in some cases.
+ // Moreover, Lapack's xSYTRS routines use 0 for the tolerance.
+ // Using numeric_limits::min() gives us more robustness to denormals.
+ RealScalar tolerance = (std::numeric_limits<RealScalar>::min)();
+ for (Index i = 0; i < vecD.size(); ++i)
+ {
+ if(abs(vecD(i)) > tolerance)
+ dst.row(i) /= vecD(i);
+ else
+ dst.row(i).setZero();
+ }
+
+ // dst = L^-* (D^-* L^-1 P b)
+ // dst = L^-T (D^-1 L^-*T P b)
+ matrixL().transpose().template conjugateIf<Conjugate>().solveInPlace(dst);
+
+ // dst = P^T (L^-* D^-* L^-1 P b) = A^-1 b
+ // dst = P^-T (L^-T D^-1 L^-*T P b) = A^-1 b
+ dst = m_transpositions.transpose() * dst;
+}
+#endif
+
+/** \internal use x = ldlt_object.solve(x);
+ *
+ * This is the \em in-place version of solve().
+ *
+ * \param bAndX represents both the right-hand side matrix b and result x.
+ *
+ * \returns true always! If you need to check for existence of solutions, use another decomposition like LU, QR, or SVD.
+ *
+ * This version avoids a copy when the right hand side matrix b is not
+ * needed anymore.
+ *
+ * \sa LDLT::solve(), MatrixBase::ldlt()
+ */
+template<typename MatrixType,int _UpLo>
+template<typename Derived>
+bool LDLT<MatrixType,_UpLo>::solveInPlace(MatrixBase<Derived> &bAndX) const
+{
+ eigen_assert(m_isInitialized && "LDLT is not initialized.");
+ eigen_assert(m_matrix.rows() == bAndX.rows());
+
+ bAndX = this->solve(bAndX);
+
+ return true;
+}
+
+/** \returns the matrix represented by the decomposition,
+ * i.e., it returns the product: P^T L D L^* P.
+ * This function is provided for debug purpose. */
+template<typename MatrixType, int _UpLo>
+MatrixType LDLT<MatrixType,_UpLo>::reconstructedMatrix() const
+{
+ eigen_assert(m_isInitialized && "LDLT is not initialized.");
+ const Index size = m_matrix.rows();
+ MatrixType res(size,size);
+
+ // P
+ res.setIdentity();
+ res = transpositionsP() * res;
+ // L^* P
+ res = matrixU() * res;
+ // D(L^*P)
+ res = vectorD().real().asDiagonal() * res;
+ // L(DL^*P)
+ res = matrixL() * res;
+ // P^T (LDL^*P)
+ res = transpositionsP().transpose() * res;
+
+ return res;
+}
+
+/** \cholesky_module
+ * \returns the Cholesky decomposition with full pivoting without square root of \c *this
+ * \sa MatrixBase::ldlt()
+ */
+template<typename MatrixType, unsigned int UpLo>
+inline const LDLT<typename SelfAdjointView<MatrixType, UpLo>::PlainObject, UpLo>
+SelfAdjointView<MatrixType, UpLo>::ldlt() const
+{
+ return LDLT<PlainObject,UpLo>(m_matrix);
+}
+
+/** \cholesky_module
+ * \returns the Cholesky decomposition with full pivoting without square root of \c *this
+ * \sa SelfAdjointView::ldlt()
+ */
+template<typename Derived>
+inline const LDLT<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::ldlt() const
+{
+ return LDLT<PlainObject>(derived());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_LDLT_H
diff --git a/src/3rdparty/eigen/Eigen/src/Cholesky/LLT.h b/src/3rdparty/eigen/Eigen/src/Cholesky/LLT.h
new file mode 100644
index 000000000..8c9b2b398
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Cholesky/LLT.h
@@ -0,0 +1,558 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_LLT_H
+#define EIGEN_LLT_H
+
+namespace Eigen {
+
+namespace internal{
+
+template<typename _MatrixType, int _UpLo> struct traits<LLT<_MatrixType, _UpLo> >
+ : traits<_MatrixType>
+{
+ typedef MatrixXpr XprKind;
+ typedef SolverStorage StorageKind;
+ typedef int StorageIndex;
+ enum { Flags = 0 };
+};
+
+template<typename MatrixType, int UpLo> struct LLT_Traits;
+}
+
+/** \ingroup Cholesky_Module
+ *
+ * \class LLT
+ *
+ * \brief Standard Cholesky decomposition (LL^T) of a matrix and associated features
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the LL^T Cholesky decomposition
+ * \tparam _UpLo the triangular part that will be used for the decompositon: Lower (default) or Upper.
+ * The other triangular part won't be read.
+ *
+ * This class performs a LL^T Cholesky decomposition of a symmetric, positive definite
+ * matrix A such that A = LL^* = U^*U, where L is lower triangular.
+ *
+ * While the Cholesky decomposition is particularly useful to solve selfadjoint problems like D^*D x = b,
+ * for that purpose, we recommend the Cholesky decomposition without square root which is more stable
+ * and even faster. Nevertheless, this standard Cholesky decomposition remains useful in many other
+ * situations like generalised eigen problems with hermitian matrices.
+ *
+ * Remember that Cholesky decompositions are not rank-revealing. This LLT decomposition is only stable on positive definite matrices,
+ * use LDLT instead for the semidefinite case. Also, do not use a Cholesky decomposition to determine whether a system of equations
+ * has a solution.
+ *
+ * Example: \include LLT_example.cpp
+ * Output: \verbinclude LLT_example.out
+ *
+ * \b Performance: for best performance, it is recommended to use a column-major storage format
+ * with the Lower triangular part (the default), or, equivalently, a row-major storage format
+ * with the Upper triangular part. Otherwise, you might get a 20% slowdown for the full factorization
+ * step, and rank-updates can be up to 3 times slower.
+ *
+ * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism.
+ *
+ * Note that during the decomposition, only the lower (or upper, as defined by _UpLo) triangular part of A is considered.
+ * Therefore, the strict lower part does not have to store correct values.
+ *
+ * \sa MatrixBase::llt(), SelfAdjointView::llt(), class LDLT
+ */
+template<typename _MatrixType, int _UpLo> class LLT
+ : public SolverBase<LLT<_MatrixType, _UpLo> >
+{
+ public:
+ typedef _MatrixType MatrixType;
+ typedef SolverBase<LLT> Base;
+ friend class SolverBase<LLT>;
+
+ EIGEN_GENERIC_PUBLIC_INTERFACE(LLT)
+ enum {
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+
+ enum {
+ PacketSize = internal::packet_traits<Scalar>::size,
+ AlignmentMask = int(PacketSize)-1,
+ UpLo = _UpLo
+ };
+
+ typedef internal::LLT_Traits<MatrixType,UpLo> Traits;
+
+ /**
+ * \brief Default Constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via LLT::compute(const MatrixType&).
+ */
+ LLT() : m_matrix(), m_isInitialized(false) {}
+
+ /** \brief Default Constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem \a size.
+ * \sa LLT()
+ */
+ explicit LLT(Index size) : m_matrix(size, size),
+ m_isInitialized(false) {}
+
+ template<typename InputType>
+ explicit LLT(const EigenBase<InputType>& matrix)
+ : m_matrix(matrix.rows(), matrix.cols()),
+ m_isInitialized(false)
+ {
+ compute(matrix.derived());
+ }
+
+ /** \brief Constructs a LLT factorization from a given matrix
+ *
+ * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when
+ * \c MatrixType is a Eigen::Ref.
+ *
+ * \sa LLT(const EigenBase&)
+ */
+ template<typename InputType>
+ explicit LLT(EigenBase<InputType>& matrix)
+ : m_matrix(matrix.derived()),
+ m_isInitialized(false)
+ {
+ compute(matrix.derived());
+ }
+
+ /** \returns a view of the upper triangular matrix U */
+ inline typename Traits::MatrixU matrixU() const
+ {
+ eigen_assert(m_isInitialized && "LLT is not initialized.");
+ return Traits::getU(m_matrix);
+ }
+
+ /** \returns a view of the lower triangular matrix L */
+ inline typename Traits::MatrixL matrixL() const
+ {
+ eigen_assert(m_isInitialized && "LLT is not initialized.");
+ return Traits::getL(m_matrix);
+ }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** \returns the solution x of \f$ A x = b \f$ using the current decomposition of A.
+ *
+ * Since this LLT class assumes anyway that the matrix A is invertible, the solution
+ * theoretically exists and is unique regardless of b.
+ *
+ * Example: \include LLT_solve.cpp
+ * Output: \verbinclude LLT_solve.out
+ *
+ * \sa solveInPlace(), MatrixBase::llt(), SelfAdjointView::llt()
+ */
+ template<typename Rhs>
+ inline const Solve<LLT, Rhs>
+ solve(const MatrixBase<Rhs>& b) const;
+ #endif
+
+ template<typename Derived>
+ void solveInPlace(const MatrixBase<Derived> &bAndX) const;
+
+ template<typename InputType>
+ LLT& compute(const EigenBase<InputType>& matrix);
+
+ /** \returns an estimate of the reciprocal condition number of the matrix of
+ * which \c *this is the Cholesky decomposition.
+ */
+ RealScalar rcond() const
+ {
+ eigen_assert(m_isInitialized && "LLT is not initialized.");
+ eigen_assert(m_info == Success && "LLT failed because matrix appears to be negative");
+ return internal::rcond_estimate_helper(m_l1_norm, *this);
+ }
+
+ /** \returns the LLT decomposition matrix
+ *
+ * TODO: document the storage layout
+ */
+ inline const MatrixType& matrixLLT() const
+ {
+ eigen_assert(m_isInitialized && "LLT is not initialized.");
+ return m_matrix;
+ }
+
+ MatrixType reconstructedMatrix() const;
+
+
+ /** \brief Reports whether previous computation was successful.
+ *
+ * \returns \c Success if computation was successful,
+ * \c NumericalIssue if the matrix.appears not to be positive definite.
+ */
+ ComputationInfo info() const
+ {
+ eigen_assert(m_isInitialized && "LLT is not initialized.");
+ return m_info;
+ }
+
+ /** \returns the adjoint of \c *this, that is, a const reference to the decomposition itself as the underlying matrix is self-adjoint.
+ *
+ * This method is provided for compatibility with other matrix decompositions, thus enabling generic code such as:
+ * \code x = decomposition.adjoint().solve(b) \endcode
+ */
+ const LLT& adjoint() const EIGEN_NOEXCEPT { return *this; };
+
+ inline EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
+ inline EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
+
+ template<typename VectorType>
+ LLT & rankUpdate(const VectorType& vec, const RealScalar& sigma = 1);
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename RhsType, typename DstType>
+ void _solve_impl(const RhsType &rhs, DstType &dst) const;
+
+ template<bool Conjugate, typename RhsType, typename DstType>
+ void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const;
+ #endif
+
+ protected:
+
+ static void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ }
+
+ /** \internal
+ * Used to compute and store L
+ * The strict upper part is not used and even not initialized.
+ */
+ MatrixType m_matrix;
+ RealScalar m_l1_norm;
+ bool m_isInitialized;
+ ComputationInfo m_info;
+};
+
+namespace internal {
+
+template<typename Scalar, int UpLo> struct llt_inplace;
+
+template<typename MatrixType, typename VectorType>
+static Index llt_rank_update_lower(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma)
+{
+ using std::sqrt;
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename MatrixType::RealScalar RealScalar;
+ typedef typename MatrixType::ColXpr ColXpr;
+ typedef typename internal::remove_all<ColXpr>::type ColXprCleaned;
+ typedef typename ColXprCleaned::SegmentReturnType ColXprSegment;
+ typedef Matrix<Scalar,Dynamic,1> TempVectorType;
+ typedef typename TempVectorType::SegmentReturnType TempVecSegment;
+
+ Index n = mat.cols();
+ eigen_assert(mat.rows()==n && vec.size()==n);
+
+ TempVectorType temp;
+
+ if(sigma>0)
+ {
+ // This version is based on Givens rotations.
+ // It is faster than the other one below, but only works for updates,
+ // i.e., for sigma > 0
+ temp = sqrt(sigma) * vec;
+
+ for(Index i=0; i<n; ++i)
+ {
+ JacobiRotation<Scalar> g;
+ g.makeGivens(mat(i,i), -temp(i), &mat(i,i));
+
+ Index rs = n-i-1;
+ if(rs>0)
+ {
+ ColXprSegment x(mat.col(i).tail(rs));
+ TempVecSegment y(temp.tail(rs));
+ apply_rotation_in_the_plane(x, y, g);
+ }
+ }
+ }
+ else
+ {
+ temp = vec;
+ RealScalar beta = 1;
+ for(Index j=0; j<n; ++j)
+ {
+ RealScalar Ljj = numext::real(mat.coeff(j,j));
+ RealScalar dj = numext::abs2(Ljj);
+ Scalar wj = temp.coeff(j);
+ RealScalar swj2 = sigma*numext::abs2(wj);
+ RealScalar gamma = dj*beta + swj2;
+
+ RealScalar x = dj + swj2/beta;
+ if (x<=RealScalar(0))
+ return j;
+ RealScalar nLjj = sqrt(x);
+ mat.coeffRef(j,j) = nLjj;
+ beta += swj2/dj;
+
+ // Update the terms of L
+ Index rs = n-j-1;
+ if(rs)
+ {
+ temp.tail(rs) -= (wj/Ljj) * mat.col(j).tail(rs);
+ if(gamma != 0)
+ mat.col(j).tail(rs) = (nLjj/Ljj) * mat.col(j).tail(rs) + (nLjj * sigma*numext::conj(wj)/gamma)*temp.tail(rs);
+ }
+ }
+ }
+ return -1;
+}
+
+template<typename Scalar> struct llt_inplace<Scalar, Lower>
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ template<typename MatrixType>
+ static Index unblocked(MatrixType& mat)
+ {
+ using std::sqrt;
+
+ eigen_assert(mat.rows()==mat.cols());
+ const Index size = mat.rows();
+ for(Index k = 0; k < size; ++k)
+ {
+ Index rs = size-k-1; // remaining size
+
+ Block<MatrixType,Dynamic,1> A21(mat,k+1,k,rs,1);
+ Block<MatrixType,1,Dynamic> A10(mat,k,0,1,k);
+ Block<MatrixType,Dynamic,Dynamic> A20(mat,k+1,0,rs,k);
+
+ RealScalar x = numext::real(mat.coeff(k,k));
+ if (k>0) x -= A10.squaredNorm();
+ if (x<=RealScalar(0))
+ return k;
+ mat.coeffRef(k,k) = x = sqrt(x);
+ if (k>0 && rs>0) A21.noalias() -= A20 * A10.adjoint();
+ if (rs>0) A21 /= x;
+ }
+ return -1;
+ }
+
+ template<typename MatrixType>
+ static Index blocked(MatrixType& m)
+ {
+ eigen_assert(m.rows()==m.cols());
+ Index size = m.rows();
+ if(size<32)
+ return unblocked(m);
+
+ Index blockSize = size/8;
+ blockSize = (blockSize/16)*16;
+ blockSize = (std::min)((std::max)(blockSize,Index(8)), Index(128));
+
+ for (Index k=0; k<size; k+=blockSize)
+ {
+ // partition the matrix:
+ // A00 | - | -
+ // lu = A10 | A11 | -
+ // A20 | A21 | A22
+ Index bs = (std::min)(blockSize, size-k);
+ Index rs = size - k - bs;
+ Block<MatrixType,Dynamic,Dynamic> A11(m,k, k, bs,bs);
+ Block<MatrixType,Dynamic,Dynamic> A21(m,k+bs,k, rs,bs);
+ Block<MatrixType,Dynamic,Dynamic> A22(m,k+bs,k+bs,rs,rs);
+
+ Index ret;
+ if((ret=unblocked(A11))>=0) return k+ret;
+ if(rs>0) A11.adjoint().template triangularView<Upper>().template solveInPlace<OnTheRight>(A21);
+ if(rs>0) A22.template selfadjointView<Lower>().rankUpdate(A21,typename NumTraits<RealScalar>::Literal(-1)); // bottleneck
+ }
+ return -1;
+ }
+
+ template<typename MatrixType, typename VectorType>
+ static Index rankUpdate(MatrixType& mat, const VectorType& vec, const RealScalar& sigma)
+ {
+ return Eigen::internal::llt_rank_update_lower(mat, vec, sigma);
+ }
+};
+
+template<typename Scalar> struct llt_inplace<Scalar, Upper>
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ template<typename MatrixType>
+ static EIGEN_STRONG_INLINE Index unblocked(MatrixType& mat)
+ {
+ Transpose<MatrixType> matt(mat);
+ return llt_inplace<Scalar, Lower>::unblocked(matt);
+ }
+ template<typename MatrixType>
+ static EIGEN_STRONG_INLINE Index blocked(MatrixType& mat)
+ {
+ Transpose<MatrixType> matt(mat);
+ return llt_inplace<Scalar, Lower>::blocked(matt);
+ }
+ template<typename MatrixType, typename VectorType>
+ static Index rankUpdate(MatrixType& mat, const VectorType& vec, const RealScalar& sigma)
+ {
+ Transpose<MatrixType> matt(mat);
+ return llt_inplace<Scalar, Lower>::rankUpdate(matt, vec.conjugate(), sigma);
+ }
+};
+
+template<typename MatrixType> struct LLT_Traits<MatrixType,Lower>
+{
+ typedef const TriangularView<const MatrixType, Lower> MatrixL;
+ typedef const TriangularView<const typename MatrixType::AdjointReturnType, Upper> MatrixU;
+ static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); }
+ static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); }
+ static bool inplace_decomposition(MatrixType& m)
+ { return llt_inplace<typename MatrixType::Scalar, Lower>::blocked(m)==-1; }
+};
+
+template<typename MatrixType> struct LLT_Traits<MatrixType,Upper>
+{
+ typedef const TriangularView<const typename MatrixType::AdjointReturnType, Lower> MatrixL;
+ typedef const TriangularView<const MatrixType, Upper> MatrixU;
+ static inline MatrixL getL(const MatrixType& m) { return MatrixL(m.adjoint()); }
+ static inline MatrixU getU(const MatrixType& m) { return MatrixU(m); }
+ static bool inplace_decomposition(MatrixType& m)
+ { return llt_inplace<typename MatrixType::Scalar, Upper>::blocked(m)==-1; }
+};
+
+} // end namespace internal
+
+/** Computes / recomputes the Cholesky decomposition A = LL^* = U^*U of \a matrix
+ *
+ * \returns a reference to *this
+ *
+ * Example: \include TutorialLinAlgComputeTwice.cpp
+ * Output: \verbinclude TutorialLinAlgComputeTwice.out
+ */
+template<typename MatrixType, int _UpLo>
+template<typename InputType>
+LLT<MatrixType,_UpLo>& LLT<MatrixType,_UpLo>::compute(const EigenBase<InputType>& a)
+{
+ check_template_parameters();
+
+ eigen_assert(a.rows()==a.cols());
+ const Index size = a.rows();
+ m_matrix.resize(size, size);
+ if (!internal::is_same_dense(m_matrix, a.derived()))
+ m_matrix = a.derived();
+
+ // Compute matrix L1 norm = max abs column sum.
+ m_l1_norm = RealScalar(0);
+ // TODO move this code to SelfAdjointView
+ for (Index col = 0; col < size; ++col) {
+ RealScalar abs_col_sum;
+ if (_UpLo == Lower)
+ abs_col_sum = m_matrix.col(col).tail(size - col).template lpNorm<1>() + m_matrix.row(col).head(col).template lpNorm<1>();
+ else
+ abs_col_sum = m_matrix.col(col).head(col).template lpNorm<1>() + m_matrix.row(col).tail(size - col).template lpNorm<1>();
+ if (abs_col_sum > m_l1_norm)
+ m_l1_norm = abs_col_sum;
+ }
+
+ m_isInitialized = true;
+ bool ok = Traits::inplace_decomposition(m_matrix);
+ m_info = ok ? Success : NumericalIssue;
+
+ return *this;
+}
+
+/** Performs a rank one update (or dowdate) of the current decomposition.
+ * If A = LL^* before the rank one update,
+ * then after it we have LL^* = A + sigma * v v^* where \a v must be a vector
+ * of same dimension.
+ */
+template<typename _MatrixType, int _UpLo>
+template<typename VectorType>
+LLT<_MatrixType,_UpLo> & LLT<_MatrixType,_UpLo>::rankUpdate(const VectorType& v, const RealScalar& sigma)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorType);
+ eigen_assert(v.size()==m_matrix.cols());
+ eigen_assert(m_isInitialized);
+ if(internal::llt_inplace<typename MatrixType::Scalar, UpLo>::rankUpdate(m_matrix,v,sigma)>=0)
+ m_info = NumericalIssue;
+ else
+ m_info = Success;
+
+ return *this;
+}
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+template<typename _MatrixType,int _UpLo>
+template<typename RhsType, typename DstType>
+void LLT<_MatrixType,_UpLo>::_solve_impl(const RhsType &rhs, DstType &dst) const
+{
+ _solve_impl_transposed<true>(rhs, dst);
+}
+
+template<typename _MatrixType,int _UpLo>
+template<bool Conjugate, typename RhsType, typename DstType>
+void LLT<_MatrixType,_UpLo>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const
+{
+ dst = rhs;
+
+ matrixL().template conjugateIf<!Conjugate>().solveInPlace(dst);
+ matrixU().template conjugateIf<!Conjugate>().solveInPlace(dst);
+}
+#endif
+
+/** \internal use x = llt_object.solve(x);
+ *
+ * This is the \em in-place version of solve().
+ *
+ * \param bAndX represents both the right-hand side matrix b and result x.
+ *
+ * This version avoids a copy when the right hand side matrix b is not needed anymore.
+ *
+ * \warning The parameter is only marked 'const' to make the C++ compiler accept a temporary expression here.
+ * This function will const_cast it, so constness isn't honored here.
+ *
+ * \sa LLT::solve(), MatrixBase::llt()
+ */
+template<typename MatrixType, int _UpLo>
+template<typename Derived>
+void LLT<MatrixType,_UpLo>::solveInPlace(const MatrixBase<Derived> &bAndX) const
+{
+ eigen_assert(m_isInitialized && "LLT is not initialized.");
+ eigen_assert(m_matrix.rows()==bAndX.rows());
+ matrixL().solveInPlace(bAndX);
+ matrixU().solveInPlace(bAndX);
+}
+
+/** \returns the matrix represented by the decomposition,
+ * i.e., it returns the product: L L^*.
+ * This function is provided for debug purpose. */
+template<typename MatrixType, int _UpLo>
+MatrixType LLT<MatrixType,_UpLo>::reconstructedMatrix() const
+{
+ eigen_assert(m_isInitialized && "LLT is not initialized.");
+ return matrixL() * matrixL().adjoint().toDenseMatrix();
+}
+
+/** \cholesky_module
+ * \returns the LLT decomposition of \c *this
+ * \sa SelfAdjointView::llt()
+ */
+template<typename Derived>
+inline const LLT<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::llt() const
+{
+ return LLT<PlainObject>(derived());
+}
+
+/** \cholesky_module
+ * \returns the LLT decomposition of \c *this
+ * \sa SelfAdjointView::llt()
+ */
+template<typename MatrixType, unsigned int UpLo>
+inline const LLT<typename SelfAdjointView<MatrixType, UpLo>::PlainObject, UpLo>
+SelfAdjointView<MatrixType, UpLo>::llt() const
+{
+ return LLT<PlainObject,UpLo>(m_matrix);
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_LLT_H
diff --git a/src/3rdparty/eigen/Eigen/src/Cholesky/LLT_LAPACKE.h b/src/3rdparty/eigen/Eigen/src/Cholesky/LLT_LAPACKE.h
new file mode 100644
index 000000000..bc6489e69
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Cholesky/LLT_LAPACKE.h
@@ -0,0 +1,99 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to LAPACKe
+ * LLt decomposition based on LAPACKE_?potrf function.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_LLT_LAPACKE_H
+#define EIGEN_LLT_LAPACKE_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Scalar> struct lapacke_llt;
+
+#define EIGEN_LAPACKE_LLT(EIGTYPE, BLASTYPE, LAPACKE_PREFIX) \
+template<> struct lapacke_llt<EIGTYPE> \
+{ \
+ template<typename MatrixType> \
+ static inline Index potrf(MatrixType& m, char uplo) \
+ { \
+ lapack_int matrix_order; \
+ lapack_int size, lda, info, StorageOrder; \
+ EIGTYPE* a; \
+ eigen_assert(m.rows()==m.cols()); \
+ /* Set up parameters for ?potrf */ \
+ size = convert_index<lapack_int>(m.rows()); \
+ StorageOrder = MatrixType::Flags&RowMajorBit?RowMajor:ColMajor; \
+ matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \
+ a = &(m.coeffRef(0,0)); \
+ lda = convert_index<lapack_int>(m.outerStride()); \
+\
+ info = LAPACKE_##LAPACKE_PREFIX##potrf( matrix_order, uplo, size, (BLASTYPE*)a, lda ); \
+ info = (info==0) ? -1 : info>0 ? info-1 : size; \
+ return info; \
+ } \
+}; \
+template<> struct llt_inplace<EIGTYPE, Lower> \
+{ \
+ template<typename MatrixType> \
+ static Index blocked(MatrixType& m) \
+ { \
+ return lapacke_llt<EIGTYPE>::potrf(m, 'L'); \
+ } \
+ template<typename MatrixType, typename VectorType> \
+ static Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \
+ { return Eigen::internal::llt_rank_update_lower(mat, vec, sigma); } \
+}; \
+template<> struct llt_inplace<EIGTYPE, Upper> \
+{ \
+ template<typename MatrixType> \
+ static Index blocked(MatrixType& m) \
+ { \
+ return lapacke_llt<EIGTYPE>::potrf(m, 'U'); \
+ } \
+ template<typename MatrixType, typename VectorType> \
+ static Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \
+ { \
+ Transpose<MatrixType> matt(mat); \
+ return llt_inplace<EIGTYPE, Lower>::rankUpdate(matt, vec.conjugate(), sigma); \
+ } \
+};
+
+EIGEN_LAPACKE_LLT(double, double, d)
+EIGEN_LAPACKE_LLT(float, float, s)
+EIGEN_LAPACKE_LLT(dcomplex, lapack_complex_double, z)
+EIGEN_LAPACKE_LLT(scomplex, lapack_complex_float, c)
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_LLT_LAPACKE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/ArithmeticSequence.h b/src/3rdparty/eigen/Eigen/src/Core/ArithmeticSequence.h
new file mode 100644
index 000000000..b6200fac1
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/ArithmeticSequence.h
@@ -0,0 +1,413 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ARITHMETIC_SEQUENCE_H
+#define EIGEN_ARITHMETIC_SEQUENCE_H
+
+namespace Eigen {
+
+namespace internal {
+
+#if (!EIGEN_HAS_CXX11) || !((!EIGEN_COMP_GNUC) || EIGEN_COMP_GNUC>=48)
+template<typename T> struct aseq_negate {};
+
+template<> struct aseq_negate<Index> {
+ typedef Index type;
+};
+
+template<int N> struct aseq_negate<FixedInt<N> > {
+ typedef FixedInt<-N> type;
+};
+
+// Compilation error in the following case:
+template<> struct aseq_negate<FixedInt<DynamicIndex> > {};
+
+template<typename FirstType,typename SizeType,typename IncrType,
+ bool FirstIsSymbolic=symbolic::is_symbolic<FirstType>::value,
+ bool SizeIsSymbolic =symbolic::is_symbolic<SizeType>::value>
+struct aseq_reverse_first_type {
+ typedef Index type;
+};
+
+template<typename FirstType,typename SizeType,typename IncrType>
+struct aseq_reverse_first_type<FirstType,SizeType,IncrType,true,true> {
+ typedef symbolic::AddExpr<FirstType,
+ symbolic::ProductExpr<symbolic::AddExpr<SizeType,symbolic::ValueExpr<FixedInt<-1> > >,
+ symbolic::ValueExpr<IncrType> >
+ > type;
+};
+
+template<typename SizeType,typename IncrType,typename EnableIf = void>
+struct aseq_reverse_first_type_aux {
+ typedef Index type;
+};
+
+template<typename SizeType,typename IncrType>
+struct aseq_reverse_first_type_aux<SizeType,IncrType,typename internal::enable_if<bool((SizeType::value+IncrType::value)|0x1)>::type> {
+ typedef FixedInt<(SizeType::value-1)*IncrType::value> type;
+};
+
+template<typename FirstType,typename SizeType,typename IncrType>
+struct aseq_reverse_first_type<FirstType,SizeType,IncrType,true,false> {
+ typedef typename aseq_reverse_first_type_aux<SizeType,IncrType>::type Aux;
+ typedef symbolic::AddExpr<FirstType,symbolic::ValueExpr<Aux> > type;
+};
+
+template<typename FirstType,typename SizeType,typename IncrType>
+struct aseq_reverse_first_type<FirstType,SizeType,IncrType,false,true> {
+ typedef symbolic::AddExpr<symbolic::ProductExpr<symbolic::AddExpr<SizeType,symbolic::ValueExpr<FixedInt<-1> > >,
+ symbolic::ValueExpr<IncrType> >,
+ symbolic::ValueExpr<> > type;
+};
+#endif
+
+// Helper to cleanup the type of the increment:
+template<typename T> struct cleanup_seq_incr {
+ typedef typename cleanup_index_type<T,DynamicIndex>::type type;
+};
+
+}
+
+//--------------------------------------------------------------------------------
+// seq(first,last,incr) and seqN(first,size,incr)
+//--------------------------------------------------------------------------------
+
+template<typename FirstType=Index,typename SizeType=Index,typename IncrType=internal::FixedInt<1> >
+class ArithmeticSequence;
+
+template<typename FirstType,typename SizeType,typename IncrType>
+ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,
+ typename internal::cleanup_index_type<SizeType>::type,
+ typename internal::cleanup_seq_incr<IncrType>::type >
+seqN(FirstType first, SizeType size, IncrType incr);
+
+/** \class ArithmeticSequence
+ * \ingroup Core_Module
+ *
+ * This class represents an arithmetic progression \f$ a_0, a_1, a_2, ..., a_{n-1}\f$ defined by
+ * its \em first value \f$ a_0 \f$, its \em size (aka length) \em n, and the \em increment (aka stride)
+ * that is equal to \f$ a_{i+1}-a_{i}\f$ for any \em i.
+ *
+ * It is internally used as the return type of the Eigen::seq and Eigen::seqN functions, and as the input arguments
+ * of DenseBase::operator()(const RowIndices&, const ColIndices&), and most of the time this is the
+ * only way it is used.
+ *
+ * \tparam FirstType type of the first element, usually an Index,
+ * but internally it can be a symbolic expression
+ * \tparam SizeType type representing the size of the sequence, usually an Index
+ * or a compile time integral constant. Internally, it can also be a symbolic expression
+ * \tparam IncrType type of the increment, can be a runtime Index, or a compile time integral constant (default is compile-time 1)
+ *
+ * \sa Eigen::seq, Eigen::seqN, DenseBase::operator()(const RowIndices&, const ColIndices&), class IndexedView
+ */
+template<typename FirstType,typename SizeType,typename IncrType>
+class ArithmeticSequence
+{
+public:
+ ArithmeticSequence(FirstType first, SizeType size) : m_first(first), m_size(size) {}
+ ArithmeticSequence(FirstType first, SizeType size, IncrType incr) : m_first(first), m_size(size), m_incr(incr) {}
+
+ enum {
+ SizeAtCompileTime = internal::get_fixed_value<SizeType>::value,
+ IncrAtCompileTime = internal::get_fixed_value<IncrType,DynamicIndex>::value
+ };
+
+ /** \returns the size, i.e., number of elements, of the sequence */
+ Index size() const { return m_size; }
+
+ /** \returns the first element \f$ a_0 \f$ in the sequence */
+ Index first() const { return m_first; }
+
+ /** \returns the value \f$ a_i \f$ at index \a i in the sequence. */
+ Index operator[](Index i) const { return m_first + i * m_incr; }
+
+ const FirstType& firstObject() const { return m_first; }
+ const SizeType& sizeObject() const { return m_size; }
+ const IncrType& incrObject() const { return m_incr; }
+
+protected:
+ FirstType m_first;
+ SizeType m_size;
+ IncrType m_incr;
+
+public:
+
+#if EIGEN_HAS_CXX11 && ((!EIGEN_COMP_GNUC) || EIGEN_COMP_GNUC>=48)
+ auto reverse() const -> decltype(Eigen::seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr)) {
+ return seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr);
+ }
+#else
+protected:
+ typedef typename internal::aseq_negate<IncrType>::type ReverseIncrType;
+ typedef typename internal::aseq_reverse_first_type<FirstType,SizeType,IncrType>::type ReverseFirstType;
+public:
+ ArithmeticSequence<ReverseFirstType,SizeType,ReverseIncrType>
+ reverse() const {
+ return seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr);
+ }
+#endif
+};
+
+/** \returns an ArithmeticSequence starting at \a first, of length \a size, and increment \a incr
+ *
+ * \sa seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType) */
+template<typename FirstType,typename SizeType,typename IncrType>
+ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type,typename internal::cleanup_seq_incr<IncrType>::type >
+seqN(FirstType first, SizeType size, IncrType incr) {
+ return ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type,typename internal::cleanup_seq_incr<IncrType>::type>(first,size,incr);
+}
+
+/** \returns an ArithmeticSequence starting at \a first, of length \a size, and unit increment
+ *
+ * \sa seqN(FirstType,SizeType,IncrType), seq(FirstType,LastType) */
+template<typename FirstType,typename SizeType>
+ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type >
+seqN(FirstType first, SizeType size) {
+ return ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type>(first,size);
+}
+
+#ifdef EIGEN_PARSED_BY_DOXYGEN
+
+/** \returns an ArithmeticSequence starting at \a f, up (or down) to \a l, and with positive (or negative) increment \a incr
+ *
+ * It is essentially an alias to:
+ * \code
+ * seqN(f, (l-f+incr)/incr, incr);
+ * \endcode
+ *
+ * \sa seqN(FirstType,SizeType,IncrType), seq(FirstType,LastType)
+ */
+template<typename FirstType,typename LastType, typename IncrType>
+auto seq(FirstType f, LastType l, IncrType incr);
+
+/** \returns an ArithmeticSequence starting at \a f, up (or down) to \a l, and unit increment
+ *
+ * It is essentially an alias to:
+ * \code
+ * seqN(f,l-f+1);
+ * \endcode
+ *
+ * \sa seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType)
+ */
+template<typename FirstType,typename LastType>
+auto seq(FirstType f, LastType l);
+
+#else // EIGEN_PARSED_BY_DOXYGEN
+
+#if EIGEN_HAS_CXX11
+template<typename FirstType,typename LastType>
+auto seq(FirstType f, LastType l) -> decltype(seqN(typename internal::cleanup_index_type<FirstType>::type(f),
+ ( typename internal::cleanup_index_type<LastType>::type(l)
+ - typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>())))
+{
+ return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
+ (typename internal::cleanup_index_type<LastType>::type(l)
+ -typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>()));
+}
+
+template<typename FirstType,typename LastType, typename IncrType>
+auto seq(FirstType f, LastType l, IncrType incr)
+ -> decltype(seqN(typename internal::cleanup_index_type<FirstType>::type(f),
+ ( typename internal::cleanup_index_type<LastType>::type(l)
+ - typename internal::cleanup_index_type<FirstType>::type(f)+typename internal::cleanup_seq_incr<IncrType>::type(incr)
+ ) / typename internal::cleanup_seq_incr<IncrType>::type(incr),
+ typename internal::cleanup_seq_incr<IncrType>::type(incr)))
+{
+ typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
+ return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
+ ( typename internal::cleanup_index_type<LastType>::type(l)
+ -typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr)) / CleanedIncrType(incr),
+ CleanedIncrType(incr));
+}
+
+#else // EIGEN_HAS_CXX11
+
+template<typename FirstType,typename LastType>
+typename internal::enable_if<!(symbolic::is_symbolic<FirstType>::value || symbolic::is_symbolic<LastType>::value),
+ ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,Index> >::type
+seq(FirstType f, LastType l)
+{
+ return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
+ Index((typename internal::cleanup_index_type<LastType>::type(l)-typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>())));
+}
+
+template<typename FirstTypeDerived,typename LastType>
+typename internal::enable_if<!symbolic::is_symbolic<LastType>::value,
+ ArithmeticSequence<FirstTypeDerived, symbolic::AddExpr<symbolic::AddExpr<symbolic::NegateExpr<FirstTypeDerived>,symbolic::ValueExpr<> >,
+ symbolic::ValueExpr<internal::FixedInt<1> > > > >::type
+seq(const symbolic::BaseExpr<FirstTypeDerived> &f, LastType l)
+{
+ return seqN(f.derived(),(typename internal::cleanup_index_type<LastType>::type(l)-f.derived()+fix<1>()));
+}
+
+template<typename FirstType,typename LastTypeDerived>
+typename internal::enable_if<!symbolic::is_symbolic<FirstType>::value,
+ ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,
+ symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::ValueExpr<> >,
+ symbolic::ValueExpr<internal::FixedInt<1> > > > >::type
+seq(FirstType f, const symbolic::BaseExpr<LastTypeDerived> &l)
+{
+ return seqN(typename internal::cleanup_index_type<FirstType>::type(f),(l.derived()-typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>()));
+}
+
+template<typename FirstTypeDerived,typename LastTypeDerived>
+ArithmeticSequence<FirstTypeDerived,
+ symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::NegateExpr<FirstTypeDerived> >,symbolic::ValueExpr<internal::FixedInt<1> > > >
+seq(const symbolic::BaseExpr<FirstTypeDerived> &f, const symbolic::BaseExpr<LastTypeDerived> &l)
+{
+ return seqN(f.derived(),(l.derived()-f.derived()+fix<1>()));
+}
+
+
+template<typename FirstType,typename LastType, typename IncrType>
+typename internal::enable_if<!(symbolic::is_symbolic<FirstType>::value || symbolic::is_symbolic<LastType>::value),
+ ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,Index,typename internal::cleanup_seq_incr<IncrType>::type> >::type
+seq(FirstType f, LastType l, IncrType incr)
+{
+ typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
+ return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
+ Index((typename internal::cleanup_index_type<LastType>::type(l)-typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr))/CleanedIncrType(incr)), incr);
+}
+
+template<typename FirstTypeDerived,typename LastType, typename IncrType>
+typename internal::enable_if<!symbolic::is_symbolic<LastType>::value,
+ ArithmeticSequence<FirstTypeDerived,
+ symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<symbolic::NegateExpr<FirstTypeDerived>,
+ symbolic::ValueExpr<> >,
+ symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
+ symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
+ typename internal::cleanup_seq_incr<IncrType>::type> >::type
+seq(const symbolic::BaseExpr<FirstTypeDerived> &f, LastType l, IncrType incr)
+{
+ typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
+ return seqN(f.derived(),(typename internal::cleanup_index_type<LastType>::type(l)-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr);
+}
+
+template<typename FirstType,typename LastTypeDerived, typename IncrType>
+typename internal::enable_if<!symbolic::is_symbolic<FirstType>::value,
+ ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,
+ symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::ValueExpr<> >,
+ symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
+ symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
+ typename internal::cleanup_seq_incr<IncrType>::type> >::type
+seq(FirstType f, const symbolic::BaseExpr<LastTypeDerived> &l, IncrType incr)
+{
+ typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
+ return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
+ (l.derived()-typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr))/CleanedIncrType(incr), incr);
+}
+
+template<typename FirstTypeDerived,typename LastTypeDerived, typename IncrType>
+ArithmeticSequence<FirstTypeDerived,
+ symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,
+ symbolic::NegateExpr<FirstTypeDerived> >,
+ symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
+ symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
+ typename internal::cleanup_seq_incr<IncrType>::type>
+seq(const symbolic::BaseExpr<FirstTypeDerived> &f, const symbolic::BaseExpr<LastTypeDerived> &l, IncrType incr)
+{
+ typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
+ return seqN(f.derived(),(l.derived()-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr);
+}
+#endif // EIGEN_HAS_CXX11
+
+#endif // EIGEN_PARSED_BY_DOXYGEN
+
+
+#if EIGEN_HAS_CXX11 || defined(EIGEN_PARSED_BY_DOXYGEN)
+/** \cpp11
+ * \returns a symbolic ArithmeticSequence representing the last \a size elements with increment \a incr.
+ *
+ * It is a shortcut for: \code seqN(last-(size-fix<1>)*incr, size, incr) \endcode
+ *
+ * \sa lastN(SizeType), seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType) */
+template<typename SizeType,typename IncrType>
+auto lastN(SizeType size, IncrType incr)
+-> decltype(seqN(Eigen::last-(size-fix<1>())*incr, size, incr))
+{
+ return seqN(Eigen::last-(size-fix<1>())*incr, size, incr);
+}
+
+/** \cpp11
+ * \returns a symbolic ArithmeticSequence representing the last \a size elements with a unit increment.
+ *
+ * It is a shortcut for: \code seq(last+fix<1>-size, last) \endcode
+ *
+ * \sa lastN(SizeType,IncrType, seqN(FirstType,SizeType), seq(FirstType,LastType) */
+template<typename SizeType>
+auto lastN(SizeType size)
+-> decltype(seqN(Eigen::last+fix<1>()-size, size))
+{
+ return seqN(Eigen::last+fix<1>()-size, size);
+}
+#endif
+
+namespace internal {
+
+// Convert a symbolic span into a usable one (i.e., remove last/end "keywords")
+template<typename T>
+struct make_size_type {
+ typedef typename internal::conditional<symbolic::is_symbolic<T>::value, Index, T>::type type;
+};
+
+template<typename FirstType,typename SizeType,typename IncrType,int XprSize>
+struct IndexedViewCompatibleType<ArithmeticSequence<FirstType,SizeType,IncrType>, XprSize> {
+ typedef ArithmeticSequence<Index,typename make_size_type<SizeType>::type,IncrType> type;
+};
+
+template<typename FirstType,typename SizeType,typename IncrType>
+ArithmeticSequence<Index,typename make_size_type<SizeType>::type,IncrType>
+makeIndexedViewCompatible(const ArithmeticSequence<FirstType,SizeType,IncrType>& ids, Index size,SpecializedType) {
+ return ArithmeticSequence<Index,typename make_size_type<SizeType>::type,IncrType>(
+ eval_expr_given_size(ids.firstObject(),size),eval_expr_given_size(ids.sizeObject(),size),ids.incrObject());
+}
+
+template<typename FirstType,typename SizeType,typename IncrType>
+struct get_compile_time_incr<ArithmeticSequence<FirstType,SizeType,IncrType> > {
+ enum { value = get_fixed_value<IncrType,DynamicIndex>::value };
+};
+
+} // end namespace internal
+
+/** \namespace Eigen::indexing
+ * \ingroup Core_Module
+ *
+ * The sole purpose of this namespace is to be able to import all functions
+ * and symbols that are expected to be used within operator() for indexing
+ * and slicing. If you already imported the whole Eigen namespace:
+ * \code using namespace Eigen; \endcode
+ * then you are already all set. Otherwise, if you don't want/cannot import
+ * the whole Eigen namespace, the following line:
+ * \code using namespace Eigen::indexing; \endcode
+ * is equivalent to:
+ * \code
+ using Eigen::all;
+ using Eigen::seq;
+ using Eigen::seqN;
+ using Eigen::lastN; // c++11 only
+ using Eigen::last;
+ using Eigen::lastp1;
+ using Eigen::fix;
+ \endcode
+ */
+namespace indexing {
+ using Eigen::all;
+ using Eigen::seq;
+ using Eigen::seqN;
+ #if EIGEN_HAS_CXX11
+ using Eigen::lastN;
+ #endif
+ using Eigen::last;
+ using Eigen::lastp1;
+ using Eigen::fix;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_ARITHMETIC_SEQUENCE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Array.h b/src/3rdparty/eigen/Eigen/src/Core/Array.h
new file mode 100644
index 000000000..20c789b10
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Array.h
@@ -0,0 +1,417 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ARRAY_H
+#define EIGEN_ARRAY_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
+struct traits<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > : traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
+{
+ typedef ArrayXpr XprKind;
+ typedef ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > XprBase;
+};
+}
+
+/** \class Array
+ * \ingroup Core_Module
+ *
+ * \brief General-purpose arrays with easy API for coefficient-wise operations
+ *
+ * The %Array class is very similar to the Matrix class. It provides
+ * general-purpose one- and two-dimensional arrays. The difference between the
+ * %Array and the %Matrix class is primarily in the API: the API for the
+ * %Array class provides easy access to coefficient-wise operations, while the
+ * API for the %Matrix class provides easy access to linear-algebra
+ * operations.
+ *
+ * See documentation of class Matrix for detailed information on the template parameters
+ * storage layout.
+ *
+ * This class can be extended with the help of the plugin mechanism described on the page
+ * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAY_PLUGIN.
+ *
+ * \sa \blank \ref TutorialArrayClass, \ref TopicClassHierarchy
+ */
+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
+class Array
+ : public PlainObjectBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
+{
+ public:
+
+ typedef PlainObjectBase<Array> Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Array)
+
+ enum { Options = _Options };
+ typedef typename Base::PlainObject PlainObject;
+
+ protected:
+ template <typename Derived, typename OtherDerived, bool IsVector>
+ friend struct internal::conservative_resize_like_impl;
+
+ using Base::m_storage;
+
+ public:
+
+ using Base::base;
+ using Base::coeff;
+ using Base::coeffRef;
+
+ /**
+ * The usage of
+ * using Base::operator=;
+ * fails on MSVC. Since the code below is working with GCC and MSVC, we skipped
+ * the usage of 'using'. This should be done only for operator=.
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Array& operator=(const EigenBase<OtherDerived> &other)
+ {
+ return Base::operator=(other);
+ }
+
+ /** Set all the entries to \a value.
+ * \sa DenseBase::setConstant(), DenseBase::fill()
+ */
+ /* This overload is needed because the usage of
+ * using Base::operator=;
+ * fails on MSVC. Since the code below is working with GCC and MSVC, we skipped
+ * the usage of 'using'. This should be done only for operator=.
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Array& operator=(const Scalar &value)
+ {
+ Base::setConstant(value);
+ return *this;
+ }
+
+ /** Copies the value of the expression \a other into \c *this with automatic resizing.
+ *
+ * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized),
+ * it will be initialized.
+ *
+ * Note that copying a row-vector into a vector (and conversely) is allowed.
+ * The resizing, if any, is then done in the appropriate way so that row-vectors
+ * remain row-vectors and vectors remain vectors.
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Array& operator=(const DenseBase<OtherDerived>& other)
+ {
+ return Base::_set(other);
+ }
+
+ /** This is a special case of the templated operator=. Its purpose is to
+ * prevent a default operator= from hiding the templated operator=.
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Array& operator=(const Array& other)
+ {
+ return Base::_set(other);
+ }
+
+ /** Default constructor.
+ *
+ * For fixed-size matrices, does nothing.
+ *
+ * For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix
+ * is called a null matrix. This constructor is the unique way to create null matrices: resizing
+ * a matrix to 0 is not supported.
+ *
+ * \sa resize(Index,Index)
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Array() : Base()
+ {
+ Base::_check_template_params();
+ EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
+ }
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ // FIXME is it still needed ??
+ /** \internal */
+ EIGEN_DEVICE_FUNC
+ Array(internal::constructor_without_unaligned_array_assert)
+ : Base(internal::constructor_without_unaligned_array_assert())
+ {
+ Base::_check_template_params();
+ EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
+ }
+#endif
+
+#if EIGEN_HAS_RVALUE_REFERENCES
+ EIGEN_DEVICE_FUNC
+ Array(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
+ : Base(std::move(other))
+ {
+ Base::_check_template_params();
+ }
+ EIGEN_DEVICE_FUNC
+ Array& operator=(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
+ {
+ Base::operator=(std::move(other));
+ return *this;
+ }
+#endif
+
+ #if EIGEN_HAS_CXX11
+ /** \copydoc PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
+ *
+ * Example: \include Array_variadic_ctor_cxx11.cpp
+ * Output: \verbinclude Array_variadic_ctor_cxx11.out
+ *
+ * \sa Array(const std::initializer_list<std::initializer_list<Scalar>>&)
+ * \sa Array(const Scalar&), Array(const Scalar&,const Scalar&)
+ */
+ template <typename... ArgTypes>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
+ : Base(a0, a1, a2, a3, args...) {}
+
+ /** \brief Constructs an array and initializes it from the coefficients given as initializer-lists grouped by row. \cpp11
+ *
+ * In the general case, the constructor takes a list of rows, each row being represented as a list of coefficients:
+ *
+ * Example: \include Array_initializer_list_23_cxx11.cpp
+ * Output: \verbinclude Array_initializer_list_23_cxx11.out
+ *
+ * Each of the inner initializer lists must contain the exact same number of elements, otherwise an assertion is triggered.
+ *
+ * In the case of a compile-time column 1D array, implicit transposition from a single row is allowed.
+ * Therefore <code> Array<int,Dynamic,1>{{1,2,3,4,5}}</code> is legal and the more verbose syntax
+ * <code>Array<int,Dynamic,1>{{1},{2},{3},{4},{5}}</code> can be avoided:
+ *
+ * Example: \include Array_initializer_list_vector_cxx11.cpp
+ * Output: \verbinclude Array_initializer_list_vector_cxx11.out
+ *
+ * In the case of fixed-sized arrays, the initializer list sizes must exactly match the array sizes,
+ * and implicit transposition is allowed for compile-time 1D arrays only.
+ *
+ * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Array(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {}
+ #endif // end EIGEN_HAS_CXX11
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename T>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE explicit Array(const T& x)
+ {
+ Base::_check_template_params();
+ Base::template _init1<T>(x);
+ }
+
+ template<typename T0, typename T1>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Array(const T0& val0, const T1& val1)
+ {
+ Base::_check_template_params();
+ this->template _init2<T0,T1>(val0, val1);
+ }
+
+ #else
+ /** \brief Constructs a fixed-sized array initialized with coefficients starting at \a data */
+ EIGEN_DEVICE_FUNC explicit Array(const Scalar *data);
+ /** Constructs a vector or row-vector with given dimension. \only_for_vectors
+ *
+ * Note that this is only useful for dynamic-size vectors. For fixed-size vectors,
+ * it is redundant to pass the dimension here, so it makes more sense to use the default
+ * constructor Array() instead.
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE explicit Array(Index dim);
+ /** constructs an initialized 1x1 Array with the given coefficient
+ * \sa const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args */
+ Array(const Scalar& value);
+ /** constructs an uninitialized array with \a rows rows and \a cols columns.
+ *
+ * This is useful for dynamic-size arrays. For fixed-size arrays,
+ * it is redundant to pass these parameters, so one should use the default constructor
+ * Array() instead. */
+ Array(Index rows, Index cols);
+ /** constructs an initialized 2D vector with given coefficients
+ * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) */
+ Array(const Scalar& val0, const Scalar& val1);
+ #endif // end EIGEN_PARSED_BY_DOXYGEN
+
+ /** constructs an initialized 3D vector with given coefficients
+ * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2)
+ {
+ Base::_check_template_params();
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 3)
+ m_storage.data()[0] = val0;
+ m_storage.data()[1] = val1;
+ m_storage.data()[2] = val2;
+ }
+ /** constructs an initialized 4D vector with given coefficients
+ * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2, const Scalar& val3)
+ {
+ Base::_check_template_params();
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 4)
+ m_storage.data()[0] = val0;
+ m_storage.data()[1] = val1;
+ m_storage.data()[2] = val2;
+ m_storage.data()[3] = val3;
+ }
+
+ /** Copy constructor */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Array(const Array& other)
+ : Base(other)
+ { }
+
+ private:
+ struct PrivateType {};
+ public:
+
+ /** \sa MatrixBase::operator=(const EigenBase<OtherDerived>&) */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Array(const EigenBase<OtherDerived> &other,
+ typename internal::enable_if<internal::is_convertible<typename OtherDerived::Scalar,Scalar>::value,
+ PrivateType>::type = PrivateType())
+ : Base(other.derived())
+ { }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const EIGEN_NOEXCEPT{ return 1; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
+
+ #ifdef EIGEN_ARRAY_PLUGIN
+ #include EIGEN_ARRAY_PLUGIN
+ #endif
+
+ private:
+
+ template<typename MatrixType, typename OtherDerived, bool SwapPointers>
+ friend struct internal::matrix_swap_impl;
+};
+
+/** \defgroup arraytypedefs Global array typedefs
+ * \ingroup Core_Module
+ *
+ * %Eigen defines several typedef shortcuts for most common 1D and 2D array types.
+ *
+ * The general patterns are the following:
+ *
+ * \c ArrayRowsColsType where \c Rows and \c Cols can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size,
+ * and where \c Type can be \c i for integer, \c f for float, \c d for double, \c cf for complex float, \c cd
+ * for complex double.
+ *
+ * For example, \c Array33d is a fixed-size 3x3 array type of doubles, and \c ArrayXXf is a dynamic-size matrix of floats.
+ *
+ * There are also \c ArraySizeType which are self-explanatory. For example, \c Array4cf is
+ * a fixed-size 1D array of 4 complex floats.
+ *
+ * With \cpp11, template alias are also defined for common sizes.
+ * They follow the same pattern as above except that the scalar type suffix is replaced by a
+ * template parameter, i.e.:
+ * - `ArrayRowsCols<Type>` where `Rows` and `Cols` can be \c 2,\c 3,\c 4, or \c X for fixed or dynamic size.
+ * - `ArraySize<Type>` where `Size` can be \c 2,\c 3,\c 4 or \c X for fixed or dynamic size 1D arrays.
+ *
+ * \sa class Array
+ */
+
+#define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
+/** \ingroup arraytypedefs */ \
+typedef Array<Type, Size, Size> Array##SizeSuffix##SizeSuffix##TypeSuffix; \
+/** \ingroup arraytypedefs */ \
+typedef Array<Type, Size, 1> Array##SizeSuffix##TypeSuffix;
+
+#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
+/** \ingroup arraytypedefs */ \
+typedef Array<Type, Size, Dynamic> Array##Size##X##TypeSuffix; \
+/** \ingroup arraytypedefs */ \
+typedef Array<Type, Dynamic, Size> Array##X##Size##TypeSuffix;
+
+#define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
+EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \
+EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \
+EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \
+EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
+EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
+EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
+EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
+
+EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(int, i)
+EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(float, f)
+EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(double, d)
+EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
+EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
+
+#undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES
+#undef EIGEN_MAKE_ARRAY_TYPEDEFS
+#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
+
+#if EIGEN_HAS_CXX11
+
+#define EIGEN_MAKE_ARRAY_TYPEDEFS(Size, SizeSuffix) \
+/** \ingroup arraytypedefs */ \
+/** \brief \cpp11 */ \
+template <typename Type> \
+using Array##SizeSuffix##SizeSuffix = Array<Type, Size, Size>; \
+/** \ingroup arraytypedefs */ \
+/** \brief \cpp11 */ \
+template <typename Type> \
+using Array##SizeSuffix = Array<Type, Size, 1>;
+
+#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Size) \
+/** \ingroup arraytypedefs */ \
+/** \brief \cpp11 */ \
+template <typename Type> \
+using Array##Size##X = Array<Type, Size, Dynamic>; \
+/** \ingroup arraytypedefs */ \
+/** \brief \cpp11 */ \
+template <typename Type> \
+using Array##X##Size = Array<Type, Dynamic, Size>;
+
+EIGEN_MAKE_ARRAY_TYPEDEFS(2, 2)
+EIGEN_MAKE_ARRAY_TYPEDEFS(3, 3)
+EIGEN_MAKE_ARRAY_TYPEDEFS(4, 4)
+EIGEN_MAKE_ARRAY_TYPEDEFS(Dynamic, X)
+EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(2)
+EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(3)
+EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(4)
+
+#undef EIGEN_MAKE_ARRAY_TYPEDEFS
+#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
+
+#endif // EIGEN_HAS_CXX11
+
+#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \
+using Eigen::Matrix##SizeSuffix##TypeSuffix; \
+using Eigen::Vector##SizeSuffix##TypeSuffix; \
+using Eigen::RowVector##SizeSuffix##TypeSuffix;
+
+#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \
+EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \
+EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \
+EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \
+EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) \
+
+#define EIGEN_USING_ARRAY_TYPEDEFS \
+EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \
+EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \
+EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \
+EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \
+EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd)
+
+} // end namespace Eigen
+
+#endif // EIGEN_ARRAY_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/ArrayBase.h b/src/3rdparty/eigen/Eigen/src/Core/ArrayBase.h
new file mode 100644
index 000000000..ea3dd1c3b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/ArrayBase.h
@@ -0,0 +1,226 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ARRAYBASE_H
+#define EIGEN_ARRAYBASE_H
+
+namespace Eigen {
+
+template<typename ExpressionType> class MatrixWrapper;
+
+/** \class ArrayBase
+ * \ingroup Core_Module
+ *
+ * \brief Base class for all 1D and 2D array, and related expressions
+ *
+ * An array is similar to a dense vector or matrix. While matrices are mathematical
+ * objects with well defined linear algebra operators, an array is just a collection
+ * of scalar values arranged in a one or two dimensionnal fashion. As the main consequence,
+ * all operations applied to an array are performed coefficient wise. Furthermore,
+ * arrays support scalar math functions of the c++ standard library (e.g., std::sin(x)), and convenient
+ * constructors allowing to easily write generic code working for both scalar values
+ * and arrays.
+ *
+ * This class is the base that is inherited by all array expression types.
+ *
+ * \tparam Derived is the derived type, e.g., an array or an expression type.
+ *
+ * This class can be extended with the help of the plugin mechanism described on the page
+ * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAYBASE_PLUGIN.
+ *
+ * \sa class MatrixBase, \ref TopicClassHierarchy
+ */
+template<typename Derived> class ArrayBase
+ : public DenseBase<Derived>
+{
+ public:
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ /** The base class for a given storage type. */
+ typedef ArrayBase StorageBaseType;
+
+ typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl;
+
+ typedef typename internal::traits<Derived>::StorageKind StorageKind;
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+ typedef typename internal::packet_traits<Scalar>::type PacketScalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ typedef DenseBase<Derived> Base;
+ using Base::RowsAtCompileTime;
+ using Base::ColsAtCompileTime;
+ using Base::SizeAtCompileTime;
+ using Base::MaxRowsAtCompileTime;
+ using Base::MaxColsAtCompileTime;
+ using Base::MaxSizeAtCompileTime;
+ using Base::IsVectorAtCompileTime;
+ using Base::Flags;
+
+ using Base::derived;
+ using Base::const_cast_derived;
+ using Base::rows;
+ using Base::cols;
+ using Base::size;
+ using Base::coeff;
+ using Base::coeffRef;
+ using Base::lazyAssign;
+ using Base::operator-;
+ using Base::operator=;
+ using Base::operator+=;
+ using Base::operator-=;
+ using Base::operator*=;
+ using Base::operator/=;
+
+ typedef typename Base::CoeffReturnType CoeffReturnType;
+
+#endif // not EIGEN_PARSED_BY_DOXYGEN
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ typedef typename Base::PlainObject PlainObject;
+
+ /** \internal Represents a matrix with all coefficients equal to one another*/
+ typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
+#endif // not EIGEN_PARSED_BY_DOXYGEN
+
+#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
+#define EIGEN_DOC_UNARY_ADDONS(X,Y)
+# include "../plugins/MatrixCwiseUnaryOps.h"
+# include "../plugins/ArrayCwiseUnaryOps.h"
+# include "../plugins/CommonCwiseBinaryOps.h"
+# include "../plugins/MatrixCwiseBinaryOps.h"
+# include "../plugins/ArrayCwiseBinaryOps.h"
+# ifdef EIGEN_ARRAYBASE_PLUGIN
+# include EIGEN_ARRAYBASE_PLUGIN
+# endif
+#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
+#undef EIGEN_DOC_UNARY_ADDONS
+
+ /** Special case of the template operator=, in order to prevent the compiler
+ * from generating a default operator= (issue hit with g++ 4.1)
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator=(const ArrayBase& other)
+ {
+ internal::call_assignment(derived(), other.derived());
+ return derived();
+ }
+
+ /** Set all the entries to \a value.
+ * \sa DenseBase::setConstant(), DenseBase::fill() */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator=(const Scalar &value)
+ { Base::setConstant(value); return derived(); }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator+=(const Scalar& scalar);
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator-=(const Scalar& scalar);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator+=(const ArrayBase<OtherDerived>& other);
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator-=(const ArrayBase<OtherDerived>& other);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator*=(const ArrayBase<OtherDerived>& other);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator/=(const ArrayBase<OtherDerived>& other);
+
+ public:
+ EIGEN_DEVICE_FUNC
+ ArrayBase<Derived>& array() { return *this; }
+ EIGEN_DEVICE_FUNC
+ const ArrayBase<Derived>& array() const { return *this; }
+
+ /** \returns an \link Eigen::MatrixBase Matrix \endlink expression of this array
+ * \sa MatrixBase::array() */
+ EIGEN_DEVICE_FUNC
+ MatrixWrapper<Derived> matrix() { return MatrixWrapper<Derived>(derived()); }
+ EIGEN_DEVICE_FUNC
+ const MatrixWrapper<const Derived> matrix() const { return MatrixWrapper<const Derived>(derived()); }
+
+// template<typename Dest>
+// inline void evalTo(Dest& dst) const { dst = matrix(); }
+
+ protected:
+ EIGEN_DEFAULT_COPY_CONSTRUCTOR(ArrayBase)
+ EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(ArrayBase)
+
+ private:
+ explicit ArrayBase(Index);
+ ArrayBase(Index,Index);
+ template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&);
+ protected:
+ // mixing arrays and matrices is not legal
+ template<typename OtherDerived> Derived& operator+=(const MatrixBase<OtherDerived>& )
+ {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
+ // mixing arrays and matrices is not legal
+ template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& )
+ {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
+};
+
+/** replaces \c *this by \c *this - \a other.
+ *
+ * \returns a reference to \c *this
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
+ArrayBase<Derived>::operator-=(const ArrayBase<OtherDerived> &other)
+{
+ call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
+ return derived();
+}
+
+/** replaces \c *this by \c *this + \a other.
+ *
+ * \returns a reference to \c *this
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
+ArrayBase<Derived>::operator+=(const ArrayBase<OtherDerived>& other)
+{
+ call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
+ return derived();
+}
+
+/** replaces \c *this by \c *this * \a other coefficient wise.
+ *
+ * \returns a reference to \c *this
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
+ArrayBase<Derived>::operator*=(const ArrayBase<OtherDerived>& other)
+{
+ call_assignment(derived(), other.derived(), internal::mul_assign_op<Scalar,typename OtherDerived::Scalar>());
+ return derived();
+}
+
+/** replaces \c *this by \c *this / \a other coefficient wise.
+ *
+ * \returns a reference to \c *this
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
+ArrayBase<Derived>::operator/=(const ArrayBase<OtherDerived>& other)
+{
+ call_assignment(derived(), other.derived(), internal::div_assign_op<Scalar,typename OtherDerived::Scalar>());
+ return derived();
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_ARRAYBASE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/ArrayWrapper.h b/src/3rdparty/eigen/Eigen/src/Core/ArrayWrapper.h
new file mode 100644
index 000000000..2e9555b53
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/ArrayWrapper.h
@@ -0,0 +1,209 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ARRAYWRAPPER_H
+#define EIGEN_ARRAYWRAPPER_H
+
+namespace Eigen {
+
+/** \class ArrayWrapper
+ * \ingroup Core_Module
+ *
+ * \brief Expression of a mathematical vector or matrix as an array object
+ *
+ * This class is the return type of MatrixBase::array(), and most of the time
+ * this is the only way it is use.
+ *
+ * \sa MatrixBase::array(), class MatrixWrapper
+ */
+
+namespace internal {
+template<typename ExpressionType>
+struct traits<ArrayWrapper<ExpressionType> >
+ : public traits<typename remove_all<typename ExpressionType::Nested>::type >
+{
+ typedef ArrayXpr XprKind;
+ // Let's remove NestByRefBit
+ enum {
+ Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
+ LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
+ Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
+ };
+};
+}
+
+template<typename ExpressionType>
+class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
+{
+ public:
+ typedef ArrayBase<ArrayWrapper> Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
+ typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
+
+ typedef typename internal::conditional<
+ internal::is_lvalue<ExpressionType>::value,
+ Scalar,
+ const Scalar
+ >::type ScalarWithConstIfNotLvalue;
+
+ typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
+
+ using Base::coeffRef;
+
+ EIGEN_DEVICE_FUNC
+ explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
+
+ EIGEN_DEVICE_FUNC
+ inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
+ EIGEN_DEVICE_FUNC
+ inline const Scalar* data() const { return m_expression.data(); }
+
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index rowId, Index colId) const
+ {
+ return m_expression.coeffRef(rowId, colId);
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index index) const
+ {
+ return m_expression.coeffRef(index);
+ }
+
+ template<typename Dest>
+ EIGEN_DEVICE_FUNC
+ inline void evalTo(Dest& dst) const { dst = m_expression; }
+
+ EIGEN_DEVICE_FUNC
+ const typename internal::remove_all<NestedExpressionType>::type&
+ nestedExpression() const
+ {
+ return m_expression;
+ }
+
+ /** Forwards the resizing request to the nested expression
+ * \sa DenseBase::resize(Index) */
+ EIGEN_DEVICE_FUNC
+ void resize(Index newSize) { m_expression.resize(newSize); }
+ /** Forwards the resizing request to the nested expression
+ * \sa DenseBase::resize(Index,Index)*/
+ EIGEN_DEVICE_FUNC
+ void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
+
+ protected:
+ NestedExpressionType m_expression;
+};
+
+/** \class MatrixWrapper
+ * \ingroup Core_Module
+ *
+ * \brief Expression of an array as a mathematical vector or matrix
+ *
+ * This class is the return type of ArrayBase::matrix(), and most of the time
+ * this is the only way it is use.
+ *
+ * \sa MatrixBase::matrix(), class ArrayWrapper
+ */
+
+namespace internal {
+template<typename ExpressionType>
+struct traits<MatrixWrapper<ExpressionType> >
+ : public traits<typename remove_all<typename ExpressionType::Nested>::type >
+{
+ typedef MatrixXpr XprKind;
+ // Let's remove NestByRefBit
+ enum {
+ Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
+ LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
+ Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
+ };
+};
+}
+
+template<typename ExpressionType>
+class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
+{
+ public:
+ typedef MatrixBase<MatrixWrapper<ExpressionType> > Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
+ typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
+
+ typedef typename internal::conditional<
+ internal::is_lvalue<ExpressionType>::value,
+ Scalar,
+ const Scalar
+ >::type ScalarWithConstIfNotLvalue;
+
+ typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
+
+ using Base::coeffRef;
+
+ EIGEN_DEVICE_FUNC
+ explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
+
+ EIGEN_DEVICE_FUNC
+ inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
+ EIGEN_DEVICE_FUNC
+ inline const Scalar* data() const { return m_expression.data(); }
+
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index rowId, Index colId) const
+ {
+ return m_expression.derived().coeffRef(rowId, colId);
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index index) const
+ {
+ return m_expression.coeffRef(index);
+ }
+
+ EIGEN_DEVICE_FUNC
+ const typename internal::remove_all<NestedExpressionType>::type&
+ nestedExpression() const
+ {
+ return m_expression;
+ }
+
+ /** Forwards the resizing request to the nested expression
+ * \sa DenseBase::resize(Index) */
+ EIGEN_DEVICE_FUNC
+ void resize(Index newSize) { m_expression.resize(newSize); }
+ /** Forwards the resizing request to the nested expression
+ * \sa DenseBase::resize(Index,Index)*/
+ EIGEN_DEVICE_FUNC
+ void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
+
+ protected:
+ NestedExpressionType m_expression;
+};
+
+} // end namespace Eigen
+
+#endif // EIGEN_ARRAYWRAPPER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Assign.h b/src/3rdparty/eigen/Eigen/src/Core/Assign.h
new file mode 100644
index 000000000..655412efd
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Assign.h
@@ -0,0 +1,90 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2007 Michael Olbrich <michael.olbrich@gmx.net>
+// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ASSIGN_H
+#define EIGEN_ASSIGN_H
+
+namespace Eigen {
+
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>
+ ::lazyAssign(const DenseBase<OtherDerived>& other)
+{
+ enum{
+ SameType = internal::is_same<typename Derived::Scalar,typename OtherDerived::Scalar>::value
+ };
+
+ EIGEN_STATIC_ASSERT_LVALUE(Derived)
+ EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Derived,OtherDerived)
+ EIGEN_STATIC_ASSERT(SameType,YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
+
+ eigen_assert(rows() == other.rows() && cols() == other.cols());
+ internal::call_assignment_no_alias(derived(),other.derived());
+
+ return derived();
+}
+
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator=(const DenseBase<OtherDerived>& other)
+{
+ internal::call_assignment(derived(), other.derived());
+ return derived();
+}
+
+template<typename Derived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator=(const DenseBase& other)
+{
+ internal::call_assignment(derived(), other.derived());
+ return derived();
+}
+
+template<typename Derived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const MatrixBase& other)
+{
+ internal::call_assignment(derived(), other.derived());
+ return derived();
+}
+
+template<typename Derived>
+template <typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const DenseBase<OtherDerived>& other)
+{
+ internal::call_assignment(derived(), other.derived());
+ return derived();
+}
+
+template<typename Derived>
+template <typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const EigenBase<OtherDerived>& other)
+{
+ internal::call_assignment(derived(), other.derived());
+ return derived();
+}
+
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other)
+{
+ other.derived().evalTo(derived());
+ return derived();
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_ASSIGN_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/AssignEvaluator.h b/src/3rdparty/eigen/Eigen/src/Core/AssignEvaluator.h
new file mode 100644
index 000000000..7d76f0c25
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/AssignEvaluator.h
@@ -0,0 +1,1010 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2011-2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ASSIGN_EVALUATOR_H
+#define EIGEN_ASSIGN_EVALUATOR_H
+
+namespace Eigen {
+
+// This implementation is based on Assign.h
+
+namespace internal {
+
+/***************************************************************************
+* Part 1 : the logic deciding a strategy for traversal and unrolling *
+***************************************************************************/
+
+// copy_using_evaluator_traits is based on assign_traits
+
+template <typename DstEvaluator, typename SrcEvaluator, typename AssignFunc, int MaxPacketSize = -1>
+struct copy_using_evaluator_traits
+{
+ typedef typename DstEvaluator::XprType Dst;
+ typedef typename Dst::Scalar DstScalar;
+
+ enum {
+ DstFlags = DstEvaluator::Flags,
+ SrcFlags = SrcEvaluator::Flags
+ };
+
+public:
+ enum {
+ DstAlignment = DstEvaluator::Alignment,
+ SrcAlignment = SrcEvaluator::Alignment,
+ DstHasDirectAccess = (DstFlags & DirectAccessBit) == DirectAccessBit,
+ JointAlignment = EIGEN_PLAIN_ENUM_MIN(DstAlignment,SrcAlignment)
+ };
+
+private:
+ enum {
+ InnerSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::SizeAtCompileTime)
+ : int(DstFlags)&RowMajorBit ? int(Dst::ColsAtCompileTime)
+ : int(Dst::RowsAtCompileTime),
+ InnerMaxSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::MaxSizeAtCompileTime)
+ : int(DstFlags)&RowMajorBit ? int(Dst::MaxColsAtCompileTime)
+ : int(Dst::MaxRowsAtCompileTime),
+ RestrictedInnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(InnerSize,MaxPacketSize),
+ RestrictedLinearSize = EIGEN_SIZE_MIN_PREFER_FIXED(Dst::SizeAtCompileTime,MaxPacketSize),
+ OuterStride = int(outer_stride_at_compile_time<Dst>::ret),
+ MaxSizeAtCompileTime = Dst::SizeAtCompileTime
+ };
+
+ // TODO distinguish between linear traversal and inner-traversals
+ typedef typename find_best_packet<DstScalar,RestrictedLinearSize>::type LinearPacketType;
+ typedef typename find_best_packet<DstScalar,RestrictedInnerSize>::type InnerPacketType;
+
+ enum {
+ LinearPacketSize = unpacket_traits<LinearPacketType>::size,
+ InnerPacketSize = unpacket_traits<InnerPacketType>::size
+ };
+
+public:
+ enum {
+ LinearRequiredAlignment = unpacket_traits<LinearPacketType>::alignment,
+ InnerRequiredAlignment = unpacket_traits<InnerPacketType>::alignment
+ };
+
+private:
+ enum {
+ DstIsRowMajor = DstFlags&RowMajorBit,
+ SrcIsRowMajor = SrcFlags&RowMajorBit,
+ StorageOrdersAgree = (int(DstIsRowMajor) == int(SrcIsRowMajor)),
+ MightVectorize = bool(StorageOrdersAgree)
+ && (int(DstFlags) & int(SrcFlags) & ActualPacketAccessBit)
+ && bool(functor_traits<AssignFunc>::PacketAccess),
+ MayInnerVectorize = MightVectorize
+ && int(InnerSize)!=Dynamic && int(InnerSize)%int(InnerPacketSize)==0
+ && int(OuterStride)!=Dynamic && int(OuterStride)%int(InnerPacketSize)==0
+ && (EIGEN_UNALIGNED_VECTORIZE || int(JointAlignment)>=int(InnerRequiredAlignment)),
+ MayLinearize = bool(StorageOrdersAgree) && (int(DstFlags) & int(SrcFlags) & LinearAccessBit),
+ MayLinearVectorize = bool(MightVectorize) && bool(MayLinearize) && bool(DstHasDirectAccess)
+ && (EIGEN_UNALIGNED_VECTORIZE || (int(DstAlignment)>=int(LinearRequiredAlignment)) || MaxSizeAtCompileTime == Dynamic),
+ /* If the destination isn't aligned, we have to do runtime checks and we don't unroll,
+ so it's only good for large enough sizes. */
+ MaySliceVectorize = bool(MightVectorize) && bool(DstHasDirectAccess)
+ && (int(InnerMaxSize)==Dynamic || int(InnerMaxSize)>=(EIGEN_UNALIGNED_VECTORIZE?InnerPacketSize:(3*InnerPacketSize)))
+ /* slice vectorization can be slow, so we only want it if the slices are big, which is
+ indicated by InnerMaxSize rather than InnerSize, think of the case of a dynamic block
+ in a fixed-size matrix
+ However, with EIGEN_UNALIGNED_VECTORIZE and unrolling, slice vectorization is still worth it */
+ };
+
+public:
+ enum {
+ Traversal = int(Dst::SizeAtCompileTime) == 0 ? int(AllAtOnceTraversal) // If compile-size is zero, traversing will fail at compile-time.
+ : (int(MayLinearVectorize) && (LinearPacketSize>InnerPacketSize)) ? int(LinearVectorizedTraversal)
+ : int(MayInnerVectorize) ? int(InnerVectorizedTraversal)
+ : int(MayLinearVectorize) ? int(LinearVectorizedTraversal)
+ : int(MaySliceVectorize) ? int(SliceVectorizedTraversal)
+ : int(MayLinearize) ? int(LinearTraversal)
+ : int(DefaultTraversal),
+ Vectorized = int(Traversal) == InnerVectorizedTraversal
+ || int(Traversal) == LinearVectorizedTraversal
+ || int(Traversal) == SliceVectorizedTraversal
+ };
+
+ typedef typename conditional<int(Traversal)==LinearVectorizedTraversal, LinearPacketType, InnerPacketType>::type PacketType;
+
+private:
+ enum {
+ ActualPacketSize = int(Traversal)==LinearVectorizedTraversal ? LinearPacketSize
+ : Vectorized ? InnerPacketSize
+ : 1,
+ UnrollingLimit = EIGEN_UNROLLING_LIMIT * ActualPacketSize,
+ MayUnrollCompletely = int(Dst::SizeAtCompileTime) != Dynamic
+ && int(Dst::SizeAtCompileTime) * (int(DstEvaluator::CoeffReadCost)+int(SrcEvaluator::CoeffReadCost)) <= int(UnrollingLimit),
+ MayUnrollInner = int(InnerSize) != Dynamic
+ && int(InnerSize) * (int(DstEvaluator::CoeffReadCost)+int(SrcEvaluator::CoeffReadCost)) <= int(UnrollingLimit)
+ };
+
+public:
+ enum {
+ Unrolling = (int(Traversal) == int(InnerVectorizedTraversal) || int(Traversal) == int(DefaultTraversal))
+ ? (
+ int(MayUnrollCompletely) ? int(CompleteUnrolling)
+ : int(MayUnrollInner) ? int(InnerUnrolling)
+ : int(NoUnrolling)
+ )
+ : int(Traversal) == int(LinearVectorizedTraversal)
+ ? ( bool(MayUnrollCompletely) && ( EIGEN_UNALIGNED_VECTORIZE || (int(DstAlignment)>=int(LinearRequiredAlignment)))
+ ? int(CompleteUnrolling)
+ : int(NoUnrolling) )
+ : int(Traversal) == int(LinearTraversal)
+ ? ( bool(MayUnrollCompletely) ? int(CompleteUnrolling)
+ : int(NoUnrolling) )
+#if EIGEN_UNALIGNED_VECTORIZE
+ : int(Traversal) == int(SliceVectorizedTraversal)
+ ? ( bool(MayUnrollInner) ? int(InnerUnrolling)
+ : int(NoUnrolling) )
+#endif
+ : int(NoUnrolling)
+ };
+
+#ifdef EIGEN_DEBUG_ASSIGN
+ static void debug()
+ {
+ std::cerr << "DstXpr: " << typeid(typename DstEvaluator::XprType).name() << std::endl;
+ std::cerr << "SrcXpr: " << typeid(typename SrcEvaluator::XprType).name() << std::endl;
+ std::cerr.setf(std::ios::hex, std::ios::basefield);
+ std::cerr << "DstFlags" << " = " << DstFlags << " (" << demangle_flags(DstFlags) << " )" << std::endl;
+ std::cerr << "SrcFlags" << " = " << SrcFlags << " (" << demangle_flags(SrcFlags) << " )" << std::endl;
+ std::cerr.unsetf(std::ios::hex);
+ EIGEN_DEBUG_VAR(DstAlignment)
+ EIGEN_DEBUG_VAR(SrcAlignment)
+ EIGEN_DEBUG_VAR(LinearRequiredAlignment)
+ EIGEN_DEBUG_VAR(InnerRequiredAlignment)
+ EIGEN_DEBUG_VAR(JointAlignment)
+ EIGEN_DEBUG_VAR(InnerSize)
+ EIGEN_DEBUG_VAR(InnerMaxSize)
+ EIGEN_DEBUG_VAR(LinearPacketSize)
+ EIGEN_DEBUG_VAR(InnerPacketSize)
+ EIGEN_DEBUG_VAR(ActualPacketSize)
+ EIGEN_DEBUG_VAR(StorageOrdersAgree)
+ EIGEN_DEBUG_VAR(MightVectorize)
+ EIGEN_DEBUG_VAR(MayLinearize)
+ EIGEN_DEBUG_VAR(MayInnerVectorize)
+ EIGEN_DEBUG_VAR(MayLinearVectorize)
+ EIGEN_DEBUG_VAR(MaySliceVectorize)
+ std::cerr << "Traversal" << " = " << Traversal << " (" << demangle_traversal(Traversal) << ")" << std::endl;
+ EIGEN_DEBUG_VAR(SrcEvaluator::CoeffReadCost)
+ EIGEN_DEBUG_VAR(DstEvaluator::CoeffReadCost)
+ EIGEN_DEBUG_VAR(Dst::SizeAtCompileTime)
+ EIGEN_DEBUG_VAR(UnrollingLimit)
+ EIGEN_DEBUG_VAR(MayUnrollCompletely)
+ EIGEN_DEBUG_VAR(MayUnrollInner)
+ std::cerr << "Unrolling" << " = " << Unrolling << " (" << demangle_unrolling(Unrolling) << ")" << std::endl;
+ std::cerr << std::endl;
+ }
+#endif
+};
+
+/***************************************************************************
+* Part 2 : meta-unrollers
+***************************************************************************/
+
+/************************
+*** Default traversal ***
+************************/
+
+template<typename Kernel, int Index, int Stop>
+struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling
+{
+ // FIXME: this is not very clean, perhaps this information should be provided by the kernel?
+ typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
+ typedef typename DstEvaluatorType::XprType DstXprType;
+
+ enum {
+ outer = Index / DstXprType::InnerSizeAtCompileTime,
+ inner = Index % DstXprType::InnerSizeAtCompileTime
+ };
+
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ kernel.assignCoeffByOuterInner(outer, inner);
+ copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, Index+1, Stop>::run(kernel);
+ }
+};
+
+template<typename Kernel, int Stop>
+struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, Stop, Stop>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) { }
+};
+
+template<typename Kernel, int Index_, int Stop>
+struct copy_using_evaluator_DefaultTraversal_InnerUnrolling
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel, Index outer)
+ {
+ kernel.assignCoeffByOuterInner(outer, Index_);
+ copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, Index_+1, Stop>::run(kernel, outer);
+ }
+};
+
+template<typename Kernel, int Stop>
+struct copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, Stop, Stop>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&, Index) { }
+};
+
+/***********************
+*** Linear traversal ***
+***********************/
+
+template<typename Kernel, int Index, int Stop>
+struct copy_using_evaluator_LinearTraversal_CompleteUnrolling
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel)
+ {
+ kernel.assignCoeff(Index);
+ copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, Index+1, Stop>::run(kernel);
+ }
+};
+
+template<typename Kernel, int Stop>
+struct copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, Stop, Stop>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) { }
+};
+
+/**************************
+*** Inner vectorization ***
+**************************/
+
+template<typename Kernel, int Index, int Stop>
+struct copy_using_evaluator_innervec_CompleteUnrolling
+{
+ // FIXME: this is not very clean, perhaps this information should be provided by the kernel?
+ typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
+ typedef typename DstEvaluatorType::XprType DstXprType;
+ typedef typename Kernel::PacketType PacketType;
+
+ enum {
+ outer = Index / DstXprType::InnerSizeAtCompileTime,
+ inner = Index % DstXprType::InnerSizeAtCompileTime,
+ SrcAlignment = Kernel::AssignmentTraits::SrcAlignment,
+ DstAlignment = Kernel::AssignmentTraits::DstAlignment
+ };
+
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, inner);
+ enum { NextIndex = Index + unpacket_traits<PacketType>::size };
+ copy_using_evaluator_innervec_CompleteUnrolling<Kernel, NextIndex, Stop>::run(kernel);
+ }
+};
+
+template<typename Kernel, int Stop>
+struct copy_using_evaluator_innervec_CompleteUnrolling<Kernel, Stop, Stop>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) { }
+};
+
+template<typename Kernel, int Index_, int Stop, int SrcAlignment, int DstAlignment>
+struct copy_using_evaluator_innervec_InnerUnrolling
+{
+ typedef typename Kernel::PacketType PacketType;
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel, Index outer)
+ {
+ kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, Index_);
+ enum { NextIndex = Index_ + unpacket_traits<PacketType>::size };
+ copy_using_evaluator_innervec_InnerUnrolling<Kernel, NextIndex, Stop, SrcAlignment, DstAlignment>::run(kernel, outer);
+ }
+};
+
+template<typename Kernel, int Stop, int SrcAlignment, int DstAlignment>
+struct copy_using_evaluator_innervec_InnerUnrolling<Kernel, Stop, Stop, SrcAlignment, DstAlignment>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &, Index) { }
+};
+
+/***************************************************************************
+* Part 3 : implementation of all cases
+***************************************************************************/
+
+// dense_assignment_loop is based on assign_impl
+
+template<typename Kernel,
+ int Traversal = Kernel::AssignmentTraits::Traversal,
+ int Unrolling = Kernel::AssignmentTraits::Unrolling>
+struct dense_assignment_loop;
+
+/************************
+***** Special Cases *****
+************************/
+
+// Zero-sized assignment is a no-op.
+template<typename Kernel, int Unrolling>
+struct dense_assignment_loop<Kernel, AllAtOnceTraversal, Unrolling>
+{
+ EIGEN_DEVICE_FUNC static void EIGEN_STRONG_INLINE run(Kernel& /*kernel*/)
+ {
+ typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
+ EIGEN_STATIC_ASSERT(int(DstXprType::SizeAtCompileTime) == 0,
+ EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT)
+ }
+};
+
+/************************
+*** Default traversal ***
+************************/
+
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, DefaultTraversal, NoUnrolling>
+{
+ EIGEN_DEVICE_FUNC static void EIGEN_STRONG_INLINE run(Kernel &kernel)
+ {
+ for(Index outer = 0; outer < kernel.outerSize(); ++outer) {
+ for(Index inner = 0; inner < kernel.innerSize(); ++inner) {
+ kernel.assignCoeffByOuterInner(outer, inner);
+ }
+ }
+ }
+};
+
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, DefaultTraversal, CompleteUnrolling>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
+ copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, 0, DstXprType::SizeAtCompileTime>::run(kernel);
+ }
+};
+
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, DefaultTraversal, InnerUnrolling>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
+
+ const Index outerSize = kernel.outerSize();
+ for(Index outer = 0; outer < outerSize; ++outer)
+ copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, 0, DstXprType::InnerSizeAtCompileTime>::run(kernel, outer);
+ }
+};
+
+/***************************
+*** Linear vectorization ***
+***************************/
+
+
+// The goal of unaligned_dense_assignment_loop is simply to factorize the handling
+// of the non vectorizable beginning and ending parts
+
+template <bool IsAligned = false>
+struct unaligned_dense_assignment_loop
+{
+ // if IsAligned = true, then do nothing
+ template <typename Kernel>
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&, Index, Index) {}
+};
+
+template <>
+struct unaligned_dense_assignment_loop<false>
+{
+ // MSVC must not inline this functions. If it does, it fails to optimize the
+ // packet access path.
+ // FIXME check which version exhibits this issue
+#if EIGEN_COMP_MSVC
+ template <typename Kernel>
+ static EIGEN_DONT_INLINE void run(Kernel &kernel,
+ Index start,
+ Index end)
+#else
+ template <typename Kernel>
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel,
+ Index start,
+ Index end)
+#endif
+ {
+ for (Index index = start; index < end; ++index)
+ kernel.assignCoeff(index);
+ }
+};
+
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, NoUnrolling>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ const Index size = kernel.size();
+ typedef typename Kernel::Scalar Scalar;
+ typedef typename Kernel::PacketType PacketType;
+ enum {
+ requestedAlignment = Kernel::AssignmentTraits::LinearRequiredAlignment,
+ packetSize = unpacket_traits<PacketType>::size,
+ dstIsAligned = int(Kernel::AssignmentTraits::DstAlignment)>=int(requestedAlignment),
+ dstAlignment = packet_traits<Scalar>::AlignedOnScalar ? int(requestedAlignment)
+ : int(Kernel::AssignmentTraits::DstAlignment),
+ srcAlignment = Kernel::AssignmentTraits::JointAlignment
+ };
+ const Index alignedStart = dstIsAligned ? 0 : internal::first_aligned<requestedAlignment>(kernel.dstDataPtr(), size);
+ const Index alignedEnd = alignedStart + ((size-alignedStart)/packetSize)*packetSize;
+
+ unaligned_dense_assignment_loop<dstIsAligned!=0>::run(kernel, 0, alignedStart);
+
+ for(Index index = alignedStart; index < alignedEnd; index += packetSize)
+ kernel.template assignPacket<dstAlignment, srcAlignment, PacketType>(index);
+
+ unaligned_dense_assignment_loop<>::run(kernel, alignedEnd, size);
+ }
+};
+
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, CompleteUnrolling>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
+ typedef typename Kernel::PacketType PacketType;
+
+ enum { size = DstXprType::SizeAtCompileTime,
+ packetSize =unpacket_traits<PacketType>::size,
+ alignedSize = (int(size)/packetSize)*packetSize };
+
+ copy_using_evaluator_innervec_CompleteUnrolling<Kernel, 0, alignedSize>::run(kernel);
+ copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, alignedSize, size>::run(kernel);
+ }
+};
+
+/**************************
+*** Inner vectorization ***
+**************************/
+
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, NoUnrolling>
+{
+ typedef typename Kernel::PacketType PacketType;
+ enum {
+ SrcAlignment = Kernel::AssignmentTraits::SrcAlignment,
+ DstAlignment = Kernel::AssignmentTraits::DstAlignment
+ };
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ const Index innerSize = kernel.innerSize();
+ const Index outerSize = kernel.outerSize();
+ const Index packetSize = unpacket_traits<PacketType>::size;
+ for(Index outer = 0; outer < outerSize; ++outer)
+ for(Index inner = 0; inner < innerSize; inner+=packetSize)
+ kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, inner);
+ }
+};
+
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, CompleteUnrolling>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
+ copy_using_evaluator_innervec_CompleteUnrolling<Kernel, 0, DstXprType::SizeAtCompileTime>::run(kernel);
+ }
+};
+
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, InnerUnrolling>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
+ typedef typename Kernel::AssignmentTraits Traits;
+ const Index outerSize = kernel.outerSize();
+ for(Index outer = 0; outer < outerSize; ++outer)
+ copy_using_evaluator_innervec_InnerUnrolling<Kernel, 0, DstXprType::InnerSizeAtCompileTime,
+ Traits::SrcAlignment, Traits::DstAlignment>::run(kernel, outer);
+ }
+};
+
+/***********************
+*** Linear traversal ***
+***********************/
+
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, LinearTraversal, NoUnrolling>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ const Index size = kernel.size();
+ for(Index i = 0; i < size; ++i)
+ kernel.assignCoeff(i);
+ }
+};
+
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, LinearTraversal, CompleteUnrolling>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
+ copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, 0, DstXprType::SizeAtCompileTime>::run(kernel);
+ }
+};
+
+/**************************
+*** Slice vectorization ***
+***************************/
+
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, NoUnrolling>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ typedef typename Kernel::Scalar Scalar;
+ typedef typename Kernel::PacketType PacketType;
+ enum {
+ packetSize = unpacket_traits<PacketType>::size,
+ requestedAlignment = int(Kernel::AssignmentTraits::InnerRequiredAlignment),
+ alignable = packet_traits<Scalar>::AlignedOnScalar || int(Kernel::AssignmentTraits::DstAlignment)>=sizeof(Scalar),
+ dstIsAligned = int(Kernel::AssignmentTraits::DstAlignment)>=int(requestedAlignment),
+ dstAlignment = alignable ? int(requestedAlignment)
+ : int(Kernel::AssignmentTraits::DstAlignment)
+ };
+ const Scalar *dst_ptr = kernel.dstDataPtr();
+ if((!bool(dstIsAligned)) && (UIntPtr(dst_ptr) % sizeof(Scalar))>0)
+ {
+ // the pointer is not aligned-on scalar, so alignment is not possible
+ return dense_assignment_loop<Kernel,DefaultTraversal,NoUnrolling>::run(kernel);
+ }
+ const Index packetAlignedMask = packetSize - 1;
+ const Index innerSize = kernel.innerSize();
+ const Index outerSize = kernel.outerSize();
+ const Index alignedStep = alignable ? (packetSize - kernel.outerStride() % packetSize) & packetAlignedMask : 0;
+ Index alignedStart = ((!alignable) || bool(dstIsAligned)) ? 0 : internal::first_aligned<requestedAlignment>(dst_ptr, innerSize);
+
+ for(Index outer = 0; outer < outerSize; ++outer)
+ {
+ const Index alignedEnd = alignedStart + ((innerSize-alignedStart) & ~packetAlignedMask);
+ // do the non-vectorizable part of the assignment
+ for(Index inner = 0; inner<alignedStart ; ++inner)
+ kernel.assignCoeffByOuterInner(outer, inner);
+
+ // do the vectorizable part of the assignment
+ for(Index inner = alignedStart; inner<alignedEnd; inner+=packetSize)
+ kernel.template assignPacketByOuterInner<dstAlignment, Unaligned, PacketType>(outer, inner);
+
+ // do the non-vectorizable part of the assignment
+ for(Index inner = alignedEnd; inner<innerSize ; ++inner)
+ kernel.assignCoeffByOuterInner(outer, inner);
+
+ alignedStart = numext::mini((alignedStart+alignedStep)%packetSize, innerSize);
+ }
+ }
+};
+
+#if EIGEN_UNALIGNED_VECTORIZE
+template<typename Kernel>
+struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, InnerUnrolling>
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
+ {
+ typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
+ typedef typename Kernel::PacketType PacketType;
+
+ enum { innerSize = DstXprType::InnerSizeAtCompileTime,
+ packetSize =unpacket_traits<PacketType>::size,
+ vectorizableSize = (int(innerSize) / int(packetSize)) * int(packetSize),
+ size = DstXprType::SizeAtCompileTime };
+
+ for(Index outer = 0; outer < kernel.outerSize(); ++outer)
+ {
+ copy_using_evaluator_innervec_InnerUnrolling<Kernel, 0, vectorizableSize, 0, 0>::run(kernel, outer);
+ copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, vectorizableSize, innerSize>::run(kernel, outer);
+ }
+ }
+};
+#endif
+
+
+/***************************************************************************
+* Part 4 : Generic dense assignment kernel
+***************************************************************************/
+
+// This class generalize the assignment of a coefficient (or packet) from one dense evaluator
+// to another dense writable evaluator.
+// It is parametrized by the two evaluators, and the actual assignment functor.
+// This abstraction level permits to keep the evaluation loops as simple and as generic as possible.
+// One can customize the assignment using this generic dense_assignment_kernel with different
+// functors, or by completely overloading it, by-passing a functor.
+template<typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor, int Version = Specialized>
+class generic_dense_assignment_kernel
+{
+protected:
+ typedef typename DstEvaluatorTypeT::XprType DstXprType;
+ typedef typename SrcEvaluatorTypeT::XprType SrcXprType;
+public:
+
+ typedef DstEvaluatorTypeT DstEvaluatorType;
+ typedef SrcEvaluatorTypeT SrcEvaluatorType;
+ typedef typename DstEvaluatorType::Scalar Scalar;
+ typedef copy_using_evaluator_traits<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor> AssignmentTraits;
+ typedef typename AssignmentTraits::PacketType PacketType;
+
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ generic_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType& dstExpr)
+ : m_dst(dst), m_src(src), m_functor(func), m_dstExpr(dstExpr)
+ {
+ #ifdef EIGEN_DEBUG_ASSIGN
+ AssignmentTraits::debug();
+ #endif
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT { return m_dstExpr.size(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerSize() const EIGEN_NOEXCEPT { return m_dstExpr.innerSize(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerSize() const EIGEN_NOEXCEPT { return m_dstExpr.outerSize(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_dstExpr.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_dstExpr.cols(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT { return m_dstExpr.outerStride(); }
+
+ EIGEN_DEVICE_FUNC DstEvaluatorType& dstEvaluator() EIGEN_NOEXCEPT { return m_dst; }
+ EIGEN_DEVICE_FUNC const SrcEvaluatorType& srcEvaluator() const EIGEN_NOEXCEPT { return m_src; }
+
+ /// Assign src(row,col) to dst(row,col) through the assignment functor.
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index row, Index col)
+ {
+ m_functor.assignCoeff(m_dst.coeffRef(row,col), m_src.coeff(row,col));
+ }
+
+ /// \sa assignCoeff(Index,Index)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index index)
+ {
+ m_functor.assignCoeff(m_dst.coeffRef(index), m_src.coeff(index));
+ }
+
+ /// \sa assignCoeff(Index,Index)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeffByOuterInner(Index outer, Index inner)
+ {
+ Index row = rowIndexByOuterInner(outer, inner);
+ Index col = colIndexByOuterInner(outer, inner);
+ assignCoeff(row, col);
+ }
+
+
+ template<int StoreMode, int LoadMode, typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index row, Index col)
+ {
+ m_functor.template assignPacket<StoreMode>(&m_dst.coeffRef(row,col), m_src.template packet<LoadMode,PacketType>(row,col));
+ }
+
+ template<int StoreMode, int LoadMode, typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index index)
+ {
+ m_functor.template assignPacket<StoreMode>(&m_dst.coeffRef(index), m_src.template packet<LoadMode,PacketType>(index));
+ }
+
+ template<int StoreMode, int LoadMode, typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacketByOuterInner(Index outer, Index inner)
+ {
+ Index row = rowIndexByOuterInner(outer, inner);
+ Index col = colIndexByOuterInner(outer, inner);
+ assignPacket<StoreMode,LoadMode,PacketType>(row, col);
+ }
+
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner)
+ {
+ typedef typename DstEvaluatorType::ExpressionTraits Traits;
+ return int(Traits::RowsAtCompileTime) == 1 ? 0
+ : int(Traits::ColsAtCompileTime) == 1 ? inner
+ : int(DstEvaluatorType::Flags)&RowMajorBit ? outer
+ : inner;
+ }
+
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner)
+ {
+ typedef typename DstEvaluatorType::ExpressionTraits Traits;
+ return int(Traits::ColsAtCompileTime) == 1 ? 0
+ : int(Traits::RowsAtCompileTime) == 1 ? inner
+ : int(DstEvaluatorType::Flags)&RowMajorBit ? inner
+ : outer;
+ }
+
+ EIGEN_DEVICE_FUNC const Scalar* dstDataPtr() const
+ {
+ return m_dstExpr.data();
+ }
+
+protected:
+ DstEvaluatorType& m_dst;
+ const SrcEvaluatorType& m_src;
+ const Functor &m_functor;
+ // TODO find a way to avoid the needs of the original expression
+ DstXprType& m_dstExpr;
+};
+
+// Special kernel used when computing small products whose operands have dynamic dimensions. It ensures that the
+// PacketSize used is no larger than 4, thereby increasing the chance that vectorized instructions will be used
+// when computing the product.
+
+template<typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor>
+class restricted_packet_dense_assignment_kernel : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, BuiltIn>
+{
+protected:
+ typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, BuiltIn> Base;
+ public:
+ typedef typename Base::Scalar Scalar;
+ typedef typename Base::DstXprType DstXprType;
+ typedef copy_using_evaluator_traits<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, 4> AssignmentTraits;
+ typedef typename AssignmentTraits::PacketType PacketType;
+
+ EIGEN_DEVICE_FUNC restricted_packet_dense_assignment_kernel(DstEvaluatorTypeT &dst, const SrcEvaluatorTypeT &src, const Functor &func, DstXprType& dstExpr)
+ : Base(dst, src, func, dstExpr)
+ {
+ }
+ };
+
+/***************************************************************************
+* Part 5 : Entry point for dense rectangular assignment
+***************************************************************************/
+
+template<typename DstXprType,typename SrcXprType, typename Functor>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void resize_if_allowed(DstXprType &dst, const SrcXprType& src, const Functor &/*func*/)
+{
+ EIGEN_ONLY_USED_FOR_DEBUG(dst);
+ EIGEN_ONLY_USED_FOR_DEBUG(src);
+ eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
+}
+
+template<typename DstXprType,typename SrcXprType, typename T1, typename T2>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void resize_if_allowed(DstXprType &dst, const SrcXprType& src, const internal::assign_op<T1,T2> &/*func*/)
+{
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if(((dst.rows()!=dstRows) || (dst.cols()!=dstCols)))
+ dst.resize(dstRows, dstCols);
+ eigen_assert(dst.rows() == dstRows && dst.cols() == dstCols);
+}
+
+template<typename DstXprType, typename SrcXprType, typename Functor>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType& dst, const SrcXprType& src, const Functor &func)
+{
+ typedef evaluator<DstXprType> DstEvaluatorType;
+ typedef evaluator<SrcXprType> SrcEvaluatorType;
+
+ SrcEvaluatorType srcEvaluator(src);
+
+ // NOTE To properly handle A = (A*A.transpose())/s with A rectangular,
+ // we need to resize the destination after the source evaluator has been created.
+ resize_if_allowed(dst, src, func);
+
+ DstEvaluatorType dstEvaluator(dst);
+
+ typedef generic_dense_assignment_kernel<DstEvaluatorType,SrcEvaluatorType,Functor> Kernel;
+ Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
+
+ dense_assignment_loop<Kernel>::run(kernel);
+}
+
+// Specialization for filling the destination with a constant value.
+#ifndef EIGEN_GPU_COMPILE_PHASE
+template<typename DstXprType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType& dst, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<typename DstXprType::Scalar>, DstXprType>& src, const internal::assign_op<typename DstXprType::Scalar,typename DstXprType::Scalar>& func)
+{
+ resize_if_allowed(dst, src, func);
+ std::fill_n(dst.data(), dst.size(), src.functor()());
+}
+#endif
+
+template<typename DstXprType, typename SrcXprType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType& dst, const SrcXprType& src)
+{
+ call_dense_assignment_loop(dst, src, internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar>());
+}
+
+/***************************************************************************
+* Part 6 : Generic assignment
+***************************************************************************/
+
+// Based on the respective shapes of the destination and source,
+// the class AssignmentKind determine the kind of assignment mechanism.
+// AssignmentKind must define a Kind typedef.
+template<typename DstShape, typename SrcShape> struct AssignmentKind;
+
+// Assignment kind defined in this file:
+struct Dense2Dense {};
+struct EigenBase2EigenBase {};
+
+template<typename,typename> struct AssignmentKind { typedef EigenBase2EigenBase Kind; };
+template<> struct AssignmentKind<DenseShape,DenseShape> { typedef Dense2Dense Kind; };
+
+// This is the main assignment class
+template< typename DstXprType, typename SrcXprType, typename Functor,
+ typename Kind = typename AssignmentKind< typename evaluator_traits<DstXprType>::Shape , typename evaluator_traits<SrcXprType>::Shape >::Kind,
+ typename EnableIf = void>
+struct Assignment;
+
+
+// The only purpose of this call_assignment() function is to deal with noalias() / "assume-aliasing" and automatic transposition.
+// Indeed, I (Gael) think that this concept of "assume-aliasing" was a mistake, and it makes thing quite complicated.
+// So this intermediate function removes everything related to "assume-aliasing" such that Assignment
+// does not has to bother about these annoying details.
+
+template<typename Dst, typename Src>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_assignment(Dst& dst, const Src& src)
+{
+ call_assignment(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>());
+}
+template<typename Dst, typename Src>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_assignment(const Dst& dst, const Src& src)
+{
+ call_assignment(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>());
+}
+
+// Deal with "assume-aliasing"
+template<typename Dst, typename Src, typename Func>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_assignment(Dst& dst, const Src& src, const Func& func, typename enable_if< evaluator_assume_aliasing<Src>::value, void*>::type = 0)
+{
+ typename plain_matrix_type<Src>::type tmp(src);
+ call_assignment_no_alias(dst, tmp, func);
+}
+
+template<typename Dst, typename Src, typename Func>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_assignment(Dst& dst, const Src& src, const Func& func, typename enable_if<!evaluator_assume_aliasing<Src>::value, void*>::type = 0)
+{
+ call_assignment_no_alias(dst, src, func);
+}
+
+// by-pass "assume-aliasing"
+// When there is no aliasing, we require that 'dst' has been properly resized
+template<typename Dst, template <typename> class StorageBase, typename Src, typename Func>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_assignment(NoAlias<Dst,StorageBase>& dst, const Src& src, const Func& func)
+{
+ call_assignment_no_alias(dst.expression(), src, func);
+}
+
+
+template<typename Dst, typename Src, typename Func>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_assignment_no_alias(Dst& dst, const Src& src, const Func& func)
+{
+ enum {
+ NeedToTranspose = ( (int(Dst::RowsAtCompileTime) == 1 && int(Src::ColsAtCompileTime) == 1)
+ || (int(Dst::ColsAtCompileTime) == 1 && int(Src::RowsAtCompileTime) == 1)
+ ) && int(Dst::SizeAtCompileTime) != 1
+ };
+
+ typedef typename internal::conditional<NeedToTranspose, Transpose<Dst>, Dst>::type ActualDstTypeCleaned;
+ typedef typename internal::conditional<NeedToTranspose, Transpose<Dst>, Dst&>::type ActualDstType;
+ ActualDstType actualDst(dst);
+
+ // TODO check whether this is the right place to perform these checks:
+ EIGEN_STATIC_ASSERT_LVALUE(Dst)
+ EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(ActualDstTypeCleaned,Src)
+ EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar);
+
+ Assignment<ActualDstTypeCleaned,Src,Func>::run(actualDst, src, func);
+}
+
+template<typename Dst, typename Src, typename Func>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_restricted_packet_assignment_no_alias(Dst& dst, const Src& src, const Func& func)
+{
+ typedef evaluator<Dst> DstEvaluatorType;
+ typedef evaluator<Src> SrcEvaluatorType;
+ typedef restricted_packet_dense_assignment_kernel<DstEvaluatorType,SrcEvaluatorType,Func> Kernel;
+
+ EIGEN_STATIC_ASSERT_LVALUE(Dst)
+ EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename Dst::Scalar,typename Src::Scalar);
+
+ SrcEvaluatorType srcEvaluator(src);
+ resize_if_allowed(dst, src, func);
+
+ DstEvaluatorType dstEvaluator(dst);
+ Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
+
+ dense_assignment_loop<Kernel>::run(kernel);
+}
+
+template<typename Dst, typename Src>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_assignment_no_alias(Dst& dst, const Src& src)
+{
+ call_assignment_no_alias(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>());
+}
+
+template<typename Dst, typename Src, typename Func>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_assignment_no_alias_no_transpose(Dst& dst, const Src& src, const Func& func)
+{
+ // TODO check whether this is the right place to perform these checks:
+ EIGEN_STATIC_ASSERT_LVALUE(Dst)
+ EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Dst,Src)
+ EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename Dst::Scalar,typename Src::Scalar);
+
+ Assignment<Dst,Src,Func>::run(dst, src, func);
+}
+template<typename Dst, typename Src>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_assignment_no_alias_no_transpose(Dst& dst, const Src& src)
+{
+ call_assignment_no_alias_no_transpose(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>());
+}
+
+// forward declaration
+template<typename Dst, typename Src> void check_for_aliasing(const Dst &dst, const Src &src);
+
+// Generic Dense to Dense assignment
+// Note that the last template argument "Weak" is needed to make it possible to perform
+// both partial specialization+SFINAE without ambiguous specialization
+template< typename DstXprType, typename SrcXprType, typename Functor, typename Weak>
+struct Assignment<DstXprType, SrcXprType, Functor, Dense2Dense, Weak>
+{
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const Functor &func)
+ {
+#ifndef EIGEN_NO_DEBUG
+ internal::check_for_aliasing(dst, src);
+#endif
+
+ call_dense_assignment_loop(dst, src, func);
+ }
+};
+
+// Generic assignment through evalTo.
+// TODO: not sure we have to keep that one, but it helps porting current code to new evaluator mechanism.
+// Note that the last template argument "Weak" is needed to make it possible to perform
+// both partial specialization+SFINAE without ambiguous specialization
+template< typename DstXprType, typename SrcXprType, typename Functor, typename Weak>
+struct Assignment<DstXprType, SrcXprType, Functor, EigenBase2EigenBase, Weak>
+{
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+
+ eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
+ src.evalTo(dst);
+ }
+
+ // NOTE The following two functions are templated to avoid their instantiation if not needed
+ // This is needed because some expressions supports evalTo only and/or have 'void' as scalar type.
+ template<typename SrcScalarType>
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<typename DstXprType::Scalar,SrcScalarType> &/*func*/)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+
+ eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
+ src.addTo(dst);
+ }
+
+ template<typename SrcScalarType>
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<typename DstXprType::Scalar,SrcScalarType> &/*func*/)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+
+ eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
+ src.subTo(dst);
+ }
+};
+
+} // namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_ASSIGN_EVALUATOR_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Assign_MKL.h b/src/3rdparty/eigen/Eigen/src/Core/Assign_MKL.h
new file mode 100644
index 000000000..c6140d185
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Assign_MKL.h
@@ -0,0 +1,178 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+ Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr>
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to Intel(R) MKL
+ * MKL VML support for coefficient-wise unary Eigen expressions like a=b.sin()
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_ASSIGN_VML_H
+#define EIGEN_ASSIGN_VML_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Dst, typename Src>
+class vml_assign_traits
+{
+ private:
+ enum {
+ DstHasDirectAccess = Dst::Flags & DirectAccessBit,
+ SrcHasDirectAccess = Src::Flags & DirectAccessBit,
+ StorageOrdersAgree = (int(Dst::IsRowMajor) == int(Src::IsRowMajor)),
+ InnerSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::SizeAtCompileTime)
+ : int(Dst::Flags)&RowMajorBit ? int(Dst::ColsAtCompileTime)
+ : int(Dst::RowsAtCompileTime),
+ InnerMaxSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::MaxSizeAtCompileTime)
+ : int(Dst::Flags)&RowMajorBit ? int(Dst::MaxColsAtCompileTime)
+ : int(Dst::MaxRowsAtCompileTime),
+ MaxSizeAtCompileTime = Dst::SizeAtCompileTime,
+
+ MightEnableVml = StorageOrdersAgree && DstHasDirectAccess && SrcHasDirectAccess && Src::InnerStrideAtCompileTime==1 && Dst::InnerStrideAtCompileTime==1,
+ MightLinearize = MightEnableVml && (int(Dst::Flags) & int(Src::Flags) & LinearAccessBit),
+ VmlSize = MightLinearize ? MaxSizeAtCompileTime : InnerMaxSize,
+ LargeEnough = VmlSize==Dynamic || VmlSize>=EIGEN_MKL_VML_THRESHOLD
+ };
+ public:
+ enum {
+ EnableVml = MightEnableVml && LargeEnough,
+ Traversal = MightLinearize ? LinearTraversal : DefaultTraversal
+ };
+};
+
+#define EIGEN_PP_EXPAND(ARG) ARG
+#if !defined (EIGEN_FAST_MATH) || (EIGEN_FAST_MATH != 1)
+#define EIGEN_VMLMODE_EXPAND_xLA , VML_HA
+#else
+#define EIGEN_VMLMODE_EXPAND_xLA , VML_LA
+#endif
+
+#define EIGEN_VMLMODE_EXPAND_x_
+
+#define EIGEN_VMLMODE_PREFIX_xLA vm
+#define EIGEN_VMLMODE_PREFIX_x_ v
+#define EIGEN_VMLMODE_PREFIX(VMLMODE) EIGEN_CAT(EIGEN_VMLMODE_PREFIX_x,VMLMODE)
+
+#define EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, VMLOP, EIGENTYPE, VMLTYPE, VMLMODE) \
+ template< typename DstXprType, typename SrcXprNested> \
+ struct Assignment<DstXprType, CwiseUnaryOp<scalar_##EIGENOP##_op<EIGENTYPE>, SrcXprNested>, assign_op<EIGENTYPE,EIGENTYPE>, \
+ Dense2Dense, typename enable_if<vml_assign_traits<DstXprType,SrcXprNested>::EnableVml>::type> { \
+ typedef CwiseUnaryOp<scalar_##EIGENOP##_op<EIGENTYPE>, SrcXprNested> SrcXprType; \
+ static void run(DstXprType &dst, const SrcXprType &src, const assign_op<EIGENTYPE,EIGENTYPE> &func) { \
+ resize_if_allowed(dst, src, func); \
+ eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); \
+ if(vml_assign_traits<DstXprType,SrcXprNested>::Traversal==LinearTraversal) { \
+ VMLOP(dst.size(), (const VMLTYPE*)src.nestedExpression().data(), \
+ (VMLTYPE*)dst.data() EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE) ); \
+ } else { \
+ const Index outerSize = dst.outerSize(); \
+ for(Index outer = 0; outer < outerSize; ++outer) { \
+ const EIGENTYPE *src_ptr = src.IsRowMajor ? &(src.nestedExpression().coeffRef(outer,0)) : \
+ &(src.nestedExpression().coeffRef(0, outer)); \
+ EIGENTYPE *dst_ptr = dst.IsRowMajor ? &(dst.coeffRef(outer,0)) : &(dst.coeffRef(0, outer)); \
+ VMLOP( dst.innerSize(), (const VMLTYPE*)src_ptr, \
+ (VMLTYPE*)dst_ptr EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \
+ } \
+ } \
+ } \
+ }; \
+
+
+#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(EIGENOP, VMLOP, VMLMODE) \
+ EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),s##VMLOP), float, float, VMLMODE) \
+ EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),d##VMLOP), double, double, VMLMODE)
+
+#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(EIGENOP, VMLOP, VMLMODE) \
+ EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),c##VMLOP), scomplex, MKL_Complex8, VMLMODE) \
+ EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),z##VMLOP), dcomplex, MKL_Complex16, VMLMODE)
+
+#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS(EIGENOP, VMLOP, VMLMODE) \
+ EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(EIGENOP, VMLOP, VMLMODE) \
+ EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(EIGENOP, VMLOP, VMLMODE)
+
+
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sin, Sin, LA)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(asin, Asin, LA)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sinh, Sinh, LA)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(cos, Cos, LA)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(acos, Acos, LA)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(cosh, Cosh, LA)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(tan, Tan, LA)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(atan, Atan, LA)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(tanh, Tanh, LA)
+// EIGEN_MKL_VML_DECLARE_UNARY_CALLS(abs, Abs, _)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(exp, Exp, LA)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(log, Ln, LA)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(log10, Log10, LA)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sqrt, Sqrt, _)
+
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(square, Sqr, _)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(arg, Arg, _)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(round, Round, _)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(floor, Floor, _)
+EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(ceil, Ceil, _)
+
+#define EIGEN_MKL_VML_DECLARE_POW_CALL(EIGENOP, VMLOP, EIGENTYPE, VMLTYPE, VMLMODE) \
+ template< typename DstXprType, typename SrcXprNested, typename Plain> \
+ struct Assignment<DstXprType, CwiseBinaryOp<scalar_##EIGENOP##_op<EIGENTYPE,EIGENTYPE>, SrcXprNested, \
+ const CwiseNullaryOp<internal::scalar_constant_op<EIGENTYPE>,Plain> >, assign_op<EIGENTYPE,EIGENTYPE>, \
+ Dense2Dense, typename enable_if<vml_assign_traits<DstXprType,SrcXprNested>::EnableVml>::type> { \
+ typedef CwiseBinaryOp<scalar_##EIGENOP##_op<EIGENTYPE,EIGENTYPE>, SrcXprNested, \
+ const CwiseNullaryOp<internal::scalar_constant_op<EIGENTYPE>,Plain> > SrcXprType; \
+ static void run(DstXprType &dst, const SrcXprType &src, const assign_op<EIGENTYPE,EIGENTYPE> &func) { \
+ resize_if_allowed(dst, src, func); \
+ eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); \
+ VMLTYPE exponent = reinterpret_cast<const VMLTYPE&>(src.rhs().functor().m_other); \
+ if(vml_assign_traits<DstXprType,SrcXprNested>::Traversal==LinearTraversal) \
+ { \
+ VMLOP( dst.size(), (const VMLTYPE*)src.lhs().data(), exponent, \
+ (VMLTYPE*)dst.data() EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE) ); \
+ } else { \
+ const Index outerSize = dst.outerSize(); \
+ for(Index outer = 0; outer < outerSize; ++outer) { \
+ const EIGENTYPE *src_ptr = src.IsRowMajor ? &(src.lhs().coeffRef(outer,0)) : \
+ &(src.lhs().coeffRef(0, outer)); \
+ EIGENTYPE *dst_ptr = dst.IsRowMajor ? &(dst.coeffRef(outer,0)) : &(dst.coeffRef(0, outer)); \
+ VMLOP( dst.innerSize(), (const VMLTYPE*)src_ptr, exponent, \
+ (VMLTYPE*)dst_ptr EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \
+ } \
+ } \
+ } \
+ };
+
+EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmsPowx, float, float, LA)
+EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmdPowx, double, double, LA)
+EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmcPowx, scomplex, MKL_Complex8, LA)
+EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmzPowx, dcomplex, MKL_Complex16, LA)
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_ASSIGN_VML_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/BandMatrix.h b/src/3rdparty/eigen/Eigen/src/Core/BandMatrix.h
new file mode 100644
index 000000000..878c0240a
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/BandMatrix.h
@@ -0,0 +1,353 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_BANDMATRIX_H
+#define EIGEN_BANDMATRIX_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Derived>
+class BandMatrixBase : public EigenBase<Derived>
+{
+ public:
+
+ enum {
+ Flags = internal::traits<Derived>::Flags,
+ CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
+ RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
+ ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
+ MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
+ Supers = internal::traits<Derived>::Supers,
+ Subs = internal::traits<Derived>::Subs,
+ Options = internal::traits<Derived>::Options
+ };
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+ typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> DenseMatrixType;
+ typedef typename DenseMatrixType::StorageIndex StorageIndex;
+ typedef typename internal::traits<Derived>::CoefficientsType CoefficientsType;
+ typedef EigenBase<Derived> Base;
+
+ protected:
+ enum {
+ DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic))
+ ? 1 + Supers + Subs
+ : Dynamic,
+ SizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime)
+ };
+
+ public:
+
+ using Base::derived;
+ using Base::rows;
+ using Base::cols;
+
+ /** \returns the number of super diagonals */
+ inline Index supers() const { return derived().supers(); }
+
+ /** \returns the number of sub diagonals */
+ inline Index subs() const { return derived().subs(); }
+
+ /** \returns an expression of the underlying coefficient matrix */
+ inline const CoefficientsType& coeffs() const { return derived().coeffs(); }
+
+ /** \returns an expression of the underlying coefficient matrix */
+ inline CoefficientsType& coeffs() { return derived().coeffs(); }
+
+ /** \returns a vector expression of the \a i -th column,
+ * only the meaningful part is returned.
+ * \warning the internal storage must be column major. */
+ inline Block<CoefficientsType,Dynamic,1> col(Index i)
+ {
+ EIGEN_STATIC_ASSERT((int(Options) & int(RowMajor)) == 0, THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
+ Index start = 0;
+ Index len = coeffs().rows();
+ if (i<=supers())
+ {
+ start = supers()-i;
+ len = (std::min)(rows(),std::max<Index>(0,coeffs().rows() - (supers()-i)));
+ }
+ else if (i>=rows()-subs())
+ len = std::max<Index>(0,coeffs().rows() - (i + 1 - rows() + subs()));
+ return Block<CoefficientsType,Dynamic,1>(coeffs(), start, i, len, 1);
+ }
+
+ /** \returns a vector expression of the main diagonal */
+ inline Block<CoefficientsType,1,SizeAtCompileTime> diagonal()
+ { return Block<CoefficientsType,1,SizeAtCompileTime>(coeffs(),supers(),0,1,(std::min)(rows(),cols())); }
+
+ /** \returns a vector expression of the main diagonal (const version) */
+ inline const Block<const CoefficientsType,1,SizeAtCompileTime> diagonal() const
+ { return Block<const CoefficientsType,1,SizeAtCompileTime>(coeffs(),supers(),0,1,(std::min)(rows(),cols())); }
+
+ template<int Index> struct DiagonalIntReturnType {
+ enum {
+ ReturnOpposite = (int(Options) & int(SelfAdjoint)) && (((Index) > 0 && Supers == 0) || ((Index) < 0 && Subs == 0)),
+ Conjugate = ReturnOpposite && NumTraits<Scalar>::IsComplex,
+ ActualIndex = ReturnOpposite ? -Index : Index,
+ DiagonalSize = (RowsAtCompileTime==Dynamic || ColsAtCompileTime==Dynamic)
+ ? Dynamic
+ : (ActualIndex<0
+ ? EIGEN_SIZE_MIN_PREFER_DYNAMIC(ColsAtCompileTime, RowsAtCompileTime + ActualIndex)
+ : EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime, ColsAtCompileTime - ActualIndex))
+ };
+ typedef Block<CoefficientsType,1, DiagonalSize> BuildType;
+ typedef typename internal::conditional<Conjugate,
+ CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>,BuildType >,
+ BuildType>::type Type;
+ };
+
+ /** \returns a vector expression of the \a N -th sub or super diagonal */
+ template<int N> inline typename DiagonalIntReturnType<N>::Type diagonal()
+ {
+ return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers()-N, (std::max)(0,N), 1, diagonalLength(N));
+ }
+
+ /** \returns a vector expression of the \a N -th sub or super diagonal */
+ template<int N> inline const typename DiagonalIntReturnType<N>::Type diagonal() const
+ {
+ return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers()-N, (std::max)(0,N), 1, diagonalLength(N));
+ }
+
+ /** \returns a vector expression of the \a i -th sub or super diagonal */
+ inline Block<CoefficientsType,1,Dynamic> diagonal(Index i)
+ {
+ eigen_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers()));
+ return Block<CoefficientsType,1,Dynamic>(coeffs(), supers()-i, std::max<Index>(0,i), 1, diagonalLength(i));
+ }
+
+ /** \returns a vector expression of the \a i -th sub or super diagonal */
+ inline const Block<const CoefficientsType,1,Dynamic> diagonal(Index i) const
+ {
+ eigen_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers()));
+ return Block<const CoefficientsType,1,Dynamic>(coeffs(), supers()-i, std::max<Index>(0,i), 1, diagonalLength(i));
+ }
+
+ template<typename Dest> inline void evalTo(Dest& dst) const
+ {
+ dst.resize(rows(),cols());
+ dst.setZero();
+ dst.diagonal() = diagonal();
+ for (Index i=1; i<=supers();++i)
+ dst.diagonal(i) = diagonal(i);
+ for (Index i=1; i<=subs();++i)
+ dst.diagonal(-i) = diagonal(-i);
+ }
+
+ DenseMatrixType toDenseMatrix() const
+ {
+ DenseMatrixType res(rows(),cols());
+ evalTo(res);
+ return res;
+ }
+
+ protected:
+
+ inline Index diagonalLength(Index i) const
+ { return i<0 ? (std::min)(cols(),rows()+i) : (std::min)(rows(),cols()-i); }
+};
+
+/**
+ * \class BandMatrix
+ * \ingroup Core_Module
+ *
+ * \brief Represents a rectangular matrix with a banded storage
+ *
+ * \tparam _Scalar Numeric type, i.e. float, double, int
+ * \tparam _Rows Number of rows, or \b Dynamic
+ * \tparam _Cols Number of columns, or \b Dynamic
+ * \tparam _Supers Number of super diagonal
+ * \tparam _Subs Number of sub diagonal
+ * \tparam _Options A combination of either \b #RowMajor or \b #ColMajor, and of \b #SelfAdjoint
+ * The former controls \ref TopicStorageOrders "storage order", and defaults to
+ * column-major. The latter controls whether the matrix represents a selfadjoint
+ * matrix in which case either Supers of Subs have to be null.
+ *
+ * \sa class TridiagonalMatrix
+ */
+
+template<typename _Scalar, int _Rows, int _Cols, int _Supers, int _Subs, int _Options>
+struct traits<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> >
+{
+ typedef _Scalar Scalar;
+ typedef Dense StorageKind;
+ typedef Eigen::Index StorageIndex;
+ enum {
+ CoeffReadCost = NumTraits<Scalar>::ReadCost,
+ RowsAtCompileTime = _Rows,
+ ColsAtCompileTime = _Cols,
+ MaxRowsAtCompileTime = _Rows,
+ MaxColsAtCompileTime = _Cols,
+ Flags = LvalueBit,
+ Supers = _Supers,
+ Subs = _Subs,
+ Options = _Options,
+ DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic)) ? 1 + Supers + Subs : Dynamic
+ };
+ typedef Matrix<Scalar, DataRowsAtCompileTime, ColsAtCompileTime, int(Options) & int(RowMajor) ? RowMajor : ColMajor> CoefficientsType;
+};
+
+template<typename _Scalar, int Rows, int Cols, int Supers, int Subs, int Options>
+class BandMatrix : public BandMatrixBase<BandMatrix<_Scalar,Rows,Cols,Supers,Subs,Options> >
+{
+ public:
+
+ typedef typename internal::traits<BandMatrix>::Scalar Scalar;
+ typedef typename internal::traits<BandMatrix>::StorageIndex StorageIndex;
+ typedef typename internal::traits<BandMatrix>::CoefficientsType CoefficientsType;
+
+ explicit inline BandMatrix(Index rows=Rows, Index cols=Cols, Index supers=Supers, Index subs=Subs)
+ : m_coeffs(1+supers+subs,cols),
+ m_rows(rows), m_supers(supers), m_subs(subs)
+ {
+ }
+
+ /** \returns the number of columns */
+ inline EIGEN_CONSTEXPR Index rows() const { return m_rows.value(); }
+
+ /** \returns the number of rows */
+ inline EIGEN_CONSTEXPR Index cols() const { return m_coeffs.cols(); }
+
+ /** \returns the number of super diagonals */
+ inline EIGEN_CONSTEXPR Index supers() const { return m_supers.value(); }
+
+ /** \returns the number of sub diagonals */
+ inline EIGEN_CONSTEXPR Index subs() const { return m_subs.value(); }
+
+ inline const CoefficientsType& coeffs() const { return m_coeffs; }
+ inline CoefficientsType& coeffs() { return m_coeffs; }
+
+ protected:
+
+ CoefficientsType m_coeffs;
+ internal::variable_if_dynamic<Index, Rows> m_rows;
+ internal::variable_if_dynamic<Index, Supers> m_supers;
+ internal::variable_if_dynamic<Index, Subs> m_subs;
+};
+
+template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options>
+class BandMatrixWrapper;
+
+template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options>
+struct traits<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> >
+{
+ typedef typename _CoefficientsType::Scalar Scalar;
+ typedef typename _CoefficientsType::StorageKind StorageKind;
+ typedef typename _CoefficientsType::StorageIndex StorageIndex;
+ enum {
+ CoeffReadCost = internal::traits<_CoefficientsType>::CoeffReadCost,
+ RowsAtCompileTime = _Rows,
+ ColsAtCompileTime = _Cols,
+ MaxRowsAtCompileTime = _Rows,
+ MaxColsAtCompileTime = _Cols,
+ Flags = LvalueBit,
+ Supers = _Supers,
+ Subs = _Subs,
+ Options = _Options,
+ DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic)) ? 1 + Supers + Subs : Dynamic
+ };
+ typedef _CoefficientsType CoefficientsType;
+};
+
+template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options>
+class BandMatrixWrapper : public BandMatrixBase<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> >
+{
+ public:
+
+ typedef typename internal::traits<BandMatrixWrapper>::Scalar Scalar;
+ typedef typename internal::traits<BandMatrixWrapper>::CoefficientsType CoefficientsType;
+ typedef typename internal::traits<BandMatrixWrapper>::StorageIndex StorageIndex;
+
+ explicit inline BandMatrixWrapper(const CoefficientsType& coeffs, Index rows=_Rows, Index cols=_Cols, Index supers=_Supers, Index subs=_Subs)
+ : m_coeffs(coeffs),
+ m_rows(rows), m_supers(supers), m_subs(subs)
+ {
+ EIGEN_UNUSED_VARIABLE(cols);
+ //internal::assert(coeffs.cols()==cols() && (supers()+subs()+1)==coeffs.rows());
+ }
+
+ /** \returns the number of columns */
+ inline EIGEN_CONSTEXPR Index rows() const { return m_rows.value(); }
+
+ /** \returns the number of rows */
+ inline EIGEN_CONSTEXPR Index cols() const { return m_coeffs.cols(); }
+
+ /** \returns the number of super diagonals */
+ inline EIGEN_CONSTEXPR Index supers() const { return m_supers.value(); }
+
+ /** \returns the number of sub diagonals */
+ inline EIGEN_CONSTEXPR Index subs() const { return m_subs.value(); }
+
+ inline const CoefficientsType& coeffs() const { return m_coeffs; }
+
+ protected:
+
+ const CoefficientsType& m_coeffs;
+ internal::variable_if_dynamic<Index, _Rows> m_rows;
+ internal::variable_if_dynamic<Index, _Supers> m_supers;
+ internal::variable_if_dynamic<Index, _Subs> m_subs;
+};
+
+/**
+ * \class TridiagonalMatrix
+ * \ingroup Core_Module
+ *
+ * \brief Represents a tridiagonal matrix with a compact banded storage
+ *
+ * \tparam Scalar Numeric type, i.e. float, double, int
+ * \tparam Size Number of rows and cols, or \b Dynamic
+ * \tparam Options Can be 0 or \b SelfAdjoint
+ *
+ * \sa class BandMatrix
+ */
+template<typename Scalar, int Size, int Options>
+class TridiagonalMatrix : public BandMatrix<Scalar,Size,Size,Options&SelfAdjoint?0:1,1,Options|RowMajor>
+{
+ typedef BandMatrix<Scalar,Size,Size,Options&SelfAdjoint?0:1,1,Options|RowMajor> Base;
+ typedef typename Base::StorageIndex StorageIndex;
+ public:
+ explicit TridiagonalMatrix(Index size = Size) : Base(size,size,Options&SelfAdjoint?0:1,1) {}
+
+ inline typename Base::template DiagonalIntReturnType<1>::Type super()
+ { return Base::template diagonal<1>(); }
+ inline const typename Base::template DiagonalIntReturnType<1>::Type super() const
+ { return Base::template diagonal<1>(); }
+ inline typename Base::template DiagonalIntReturnType<-1>::Type sub()
+ { return Base::template diagonal<-1>(); }
+ inline const typename Base::template DiagonalIntReturnType<-1>::Type sub() const
+ { return Base::template diagonal<-1>(); }
+ protected:
+};
+
+
+struct BandShape {};
+
+template<typename _Scalar, int _Rows, int _Cols, int _Supers, int _Subs, int _Options>
+struct evaluator_traits<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> >
+ : public evaluator_traits_base<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> >
+{
+ typedef BandShape Shape;
+};
+
+template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options>
+struct evaluator_traits<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> >
+ : public evaluator_traits_base<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> >
+{
+ typedef BandShape Shape;
+};
+
+template<> struct AssignmentKind<DenseShape,BandShape> { typedef EigenBase2EigenBase Kind; };
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_BANDMATRIX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Block.h b/src/3rdparty/eigen/Eigen/src/Core/Block.h
new file mode 100644
index 000000000..3206d6633
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Block.h
@@ -0,0 +1,448 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_BLOCK_H
+#define EIGEN_BLOCK_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
+struct traits<Block<XprType, BlockRows, BlockCols, InnerPanel> > : traits<XprType>
+{
+ typedef typename traits<XprType>::Scalar Scalar;
+ typedef typename traits<XprType>::StorageKind StorageKind;
+ typedef typename traits<XprType>::XprKind XprKind;
+ typedef typename ref_selector<XprType>::type XprTypeNested;
+ typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
+ enum{
+ MatrixRows = traits<XprType>::RowsAtCompileTime,
+ MatrixCols = traits<XprType>::ColsAtCompileTime,
+ RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows,
+ ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols,
+ MaxRowsAtCompileTime = BlockRows==0 ? 0
+ : RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime)
+ : int(traits<XprType>::MaxRowsAtCompileTime),
+ MaxColsAtCompileTime = BlockCols==0 ? 0
+ : ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime)
+ : int(traits<XprType>::MaxColsAtCompileTime),
+
+ XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0,
+ IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
+ : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
+ : XprTypeIsRowMajor,
+ HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
+ InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
+ InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
+ ? int(inner_stride_at_compile_time<XprType>::ret)
+ : int(outer_stride_at_compile_time<XprType>::ret),
+ OuterStrideAtCompileTime = HasSameStorageOrderAsXprType
+ ? int(outer_stride_at_compile_time<XprType>::ret)
+ : int(inner_stride_at_compile_time<XprType>::ret),
+
+ // FIXME, this traits is rather specialized for dense object and it needs to be cleaned further
+ FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
+ FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0,
+ Flags = (traits<XprType>::Flags & (DirectAccessBit | (InnerPanel?CompressedAccessBit:0))) | FlagsLvalueBit | FlagsRowMajorBit,
+ // FIXME DirectAccessBit should not be handled by expressions
+ //
+ // Alignment is needed by MapBase's assertions
+ // We can sefely set it to false here. Internal alignment errors will be detected by an eigen_internal_assert in the respective evaluator
+ Alignment = 0
+ };
+};
+
+template<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic, bool InnerPanel = false,
+ bool HasDirectAccess = internal::has_direct_access<XprType>::ret> class BlockImpl_dense;
+
+} // end namespace internal
+
+template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, typename StorageKind> class BlockImpl;
+
+/** \class Block
+ * \ingroup Core_Module
+ *
+ * \brief Expression of a fixed-size or dynamic-size block
+ *
+ * \tparam XprType the type of the expression in which we are taking a block
+ * \tparam BlockRows the number of rows of the block we are taking at compile time (optional)
+ * \tparam BlockCols the number of columns of the block we are taking at compile time (optional)
+ * \tparam InnerPanel is true, if the block maps to a set of rows of a row major matrix or
+ * to set of columns of a column major matrix (optional). The parameter allows to determine
+ * at compile time whether aligned access is possible on the block expression.
+ *
+ * This class represents an expression of either a fixed-size or dynamic-size block. It is the return
+ * type of DenseBase::block(Index,Index,Index,Index) and DenseBase::block<int,int>(Index,Index) and
+ * most of the time this is the only way it is used.
+ *
+ * However, if you want to directly maniputate block expressions,
+ * for instance if you want to write a function returning such an expression, you
+ * will need to use this class.
+ *
+ * Here is an example illustrating the dynamic case:
+ * \include class_Block.cpp
+ * Output: \verbinclude class_Block.out
+ *
+ * \note Even though this expression has dynamic size, in the case where \a XprType
+ * has fixed size, this expression inherits a fixed maximal size which means that evaluating
+ * it does not cause a dynamic memory allocation.
+ *
+ * Here is an example illustrating the fixed-size case:
+ * \include class_FixedBlock.cpp
+ * Output: \verbinclude class_FixedBlock.out
+ *
+ * \sa DenseBase::block(Index,Index,Index,Index), DenseBase::block(Index,Index), class VectorBlock
+ */
+template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel> class Block
+ : public BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind>
+{
+ typedef BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind> Impl;
+ public:
+ //typedef typename Impl::Base Base;
+ typedef Impl Base;
+ EIGEN_GENERIC_PUBLIC_INTERFACE(Block)
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
+
+ typedef typename internal::remove_all<XprType>::type NestedExpression;
+
+ /** Column or Row constructor
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Block(XprType& xpr, Index i) : Impl(xpr,i)
+ {
+ eigen_assert( (i>=0) && (
+ ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
+ ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
+ }
+
+ /** Fixed-size constructor
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Block(XprType& xpr, Index startRow, Index startCol)
+ : Impl(xpr, startRow, startCol)
+ {
+ EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
+ eigen_assert(startRow >= 0 && BlockRows >= 0 && startRow + BlockRows <= xpr.rows()
+ && startCol >= 0 && BlockCols >= 0 && startCol + BlockCols <= xpr.cols());
+ }
+
+ /** Dynamic-size constructor
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Block(XprType& xpr,
+ Index startRow, Index startCol,
+ Index blockRows, Index blockCols)
+ : Impl(xpr, startRow, startCol, blockRows, blockCols)
+ {
+ eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows)
+ && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols));
+ eigen_assert(startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows
+ && startCol >= 0 && blockCols >= 0 && startCol <= xpr.cols() - blockCols);
+ }
+};
+
+// The generic default implementation for dense block simplu forward to the internal::BlockImpl_dense
+// that must be specialized for direct and non-direct access...
+template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
+class BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, Dense>
+ : public internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel>
+{
+ typedef internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel> Impl;
+ typedef typename XprType::StorageIndex StorageIndex;
+ public:
+ typedef Impl Base;
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index i) : Impl(xpr,i) {}
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index startRow, Index startCol) : Impl(xpr, startRow, startCol) {}
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
+ : Impl(xpr, startRow, startCol, blockRows, blockCols) {}
+};
+
+namespace internal {
+
+/** \internal Internal implementation of dense Blocks in the general case. */
+template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, bool HasDirectAccess> class BlockImpl_dense
+ : public internal::dense_xpr_base<Block<XprType, BlockRows, BlockCols, InnerPanel> >::type
+{
+ typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType;
+ typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested;
+ public:
+
+ typedef typename internal::dense_xpr_base<BlockType>::type Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
+
+ // class InnerIterator; // FIXME apparently never used
+
+ /** Column or Row constructor
+ */
+ EIGEN_DEVICE_FUNC
+ inline BlockImpl_dense(XprType& xpr, Index i)
+ : m_xpr(xpr),
+ // It is a row if and only if BlockRows==1 and BlockCols==XprType::ColsAtCompileTime,
+ // and it is a column if and only if BlockRows==XprType::RowsAtCompileTime and BlockCols==1,
+ // all other cases are invalid.
+ // The case a 1x1 matrix seems ambiguous, but the result is the same anyway.
+ m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
+ m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
+ m_blockRows(BlockRows==1 ? 1 : xpr.rows()),
+ m_blockCols(BlockCols==1 ? 1 : xpr.cols())
+ {}
+
+ /** Fixed-size constructor
+ */
+ EIGEN_DEVICE_FUNC
+ inline BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
+ : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
+ m_blockRows(BlockRows), m_blockCols(BlockCols)
+ {}
+
+ /** Dynamic-size constructor
+ */
+ EIGEN_DEVICE_FUNC
+ inline BlockImpl_dense(XprType& xpr,
+ Index startRow, Index startCol,
+ Index blockRows, Index blockCols)
+ : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
+ m_blockRows(blockRows), m_blockCols(blockCols)
+ {}
+
+ EIGEN_DEVICE_FUNC inline Index rows() const { return m_blockRows.value(); }
+ EIGEN_DEVICE_FUNC inline Index cols() const { return m_blockCols.value(); }
+
+ EIGEN_DEVICE_FUNC
+ inline Scalar& coeffRef(Index rowId, Index colId)
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(XprType)
+ return m_xpr.coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index rowId, Index colId) const
+ {
+ return m_xpr.derived().coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
+ }
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const
+ {
+ return m_xpr.coeff(rowId + m_startRow.value(), colId + m_startCol.value());
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline Scalar& coeffRef(Index index)
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(XprType)
+ return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
+ m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index index) const
+ {
+ return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
+ m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const CoeffReturnType coeff(Index index) const
+ {
+ return m_xpr.coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
+ m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
+ }
+
+ template<int LoadMode>
+ inline PacketScalar packet(Index rowId, Index colId) const
+ {
+ return m_xpr.template packet<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value());
+ }
+
+ template<int LoadMode>
+ inline void writePacket(Index rowId, Index colId, const PacketScalar& val)
+ {
+ m_xpr.template writePacket<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value(), val);
+ }
+
+ template<int LoadMode>
+ inline PacketScalar packet(Index index) const
+ {
+ return m_xpr.template packet<Unaligned>
+ (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
+ m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
+ }
+
+ template<int LoadMode>
+ inline void writePacket(Index index, const PacketScalar& val)
+ {
+ m_xpr.template writePacket<Unaligned>
+ (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
+ m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), val);
+ }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** \sa MapBase::data() */
+ EIGEN_DEVICE_FUNC inline const Scalar* data() const;
+ EIGEN_DEVICE_FUNC inline Index innerStride() const;
+ EIGEN_DEVICE_FUNC inline Index outerStride() const;
+ #endif
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const typename internal::remove_all<XprTypeNested>::type& nestedExpression() const
+ {
+ return m_xpr;
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ XprType& nestedExpression() { return m_xpr; }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ StorageIndex startRow() const EIGEN_NOEXCEPT
+ {
+ return m_startRow.value();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ StorageIndex startCol() const EIGEN_NOEXCEPT
+ {
+ return m_startCol.value();
+ }
+
+ protected:
+
+ XprTypeNested m_xpr;
+ const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow;
+ const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol;
+ const internal::variable_if_dynamic<StorageIndex, RowsAtCompileTime> m_blockRows;
+ const internal::variable_if_dynamic<StorageIndex, ColsAtCompileTime> m_blockCols;
+};
+
+/** \internal Internal implementation of dense Blocks in the direct access case.*/
+template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
+class BlockImpl_dense<XprType,BlockRows,BlockCols, InnerPanel,true>
+ : public MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel> >
+{
+ typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType;
+ typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested;
+ enum {
+ XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0
+ };
+ public:
+
+ typedef MapBase<BlockType> Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
+
+ /** Column or Row constructor
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ BlockImpl_dense(XprType& xpr, Index i)
+ : Base(xpr.data() + i * ( ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && (!XprTypeIsRowMajor))
+ || ((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && ( XprTypeIsRowMajor)) ? xpr.innerStride() : xpr.outerStride()),
+ BlockRows==1 ? 1 : xpr.rows(),
+ BlockCols==1 ? 1 : xpr.cols()),
+ m_xpr(xpr),
+ m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
+ m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0)
+ {
+ init();
+ }
+
+ /** Fixed-size constructor
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
+ : Base(xpr.data()+xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol)),
+ m_xpr(xpr), m_startRow(startRow), m_startCol(startCol)
+ {
+ init();
+ }
+
+ /** Dynamic-size constructor
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ BlockImpl_dense(XprType& xpr,
+ Index startRow, Index startCol,
+ Index blockRows, Index blockCols)
+ : Base(xpr.data()+xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol), blockRows, blockCols),
+ m_xpr(xpr), m_startRow(startRow), m_startCol(startCol)
+ {
+ init();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const typename internal::remove_all<XprTypeNested>::type& nestedExpression() const EIGEN_NOEXCEPT
+ {
+ return m_xpr;
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ XprType& nestedExpression() { return m_xpr; }
+
+ /** \sa MapBase::innerStride() */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index innerStride() const EIGEN_NOEXCEPT
+ {
+ return internal::traits<BlockType>::HasSameStorageOrderAsXprType
+ ? m_xpr.innerStride()
+ : m_xpr.outerStride();
+ }
+
+ /** \sa MapBase::outerStride() */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index outerStride() const EIGEN_NOEXCEPT
+ {
+ return internal::traits<BlockType>::HasSameStorageOrderAsXprType
+ ? m_xpr.outerStride()
+ : m_xpr.innerStride();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ StorageIndex startRow() const EIGEN_NOEXCEPT { return m_startRow.value(); }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ StorageIndex startCol() const EIGEN_NOEXCEPT { return m_startCol.value(); }
+
+ #ifndef __SUNPRO_CC
+ // FIXME sunstudio is not friendly with the above friend...
+ // META-FIXME there is no 'friend' keyword around here. Is this obsolete?
+ protected:
+ #endif
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ /** \internal used by allowAligned() */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ BlockImpl_dense(XprType& xpr, const Scalar* data, Index blockRows, Index blockCols)
+ : Base(data, blockRows, blockCols), m_xpr(xpr)
+ {
+ init();
+ }
+ #endif
+
+ protected:
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void init()
+ {
+ m_outerStride = internal::traits<BlockType>::HasSameStorageOrderAsXprType
+ ? m_xpr.outerStride()
+ : m_xpr.innerStride();
+ }
+
+ XprTypeNested m_xpr;
+ const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow;
+ const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol;
+ Index m_outerStride;
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_BLOCK_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/BooleanRedux.h b/src/3rdparty/eigen/Eigen/src/Core/BooleanRedux.h
new file mode 100644
index 000000000..852de8b90
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/BooleanRedux.h
@@ -0,0 +1,162 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ALLANDANY_H
+#define EIGEN_ALLANDANY_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Derived, int UnrollCount, int Rows>
+struct all_unroller
+{
+ enum {
+ col = (UnrollCount-1) / Rows,
+ row = (UnrollCount-1) % Rows
+ };
+
+ EIGEN_DEVICE_FUNC static inline bool run(const Derived &mat)
+ {
+ return all_unroller<Derived, UnrollCount-1, Rows>::run(mat) && mat.coeff(row, col);
+ }
+};
+
+template<typename Derived, int Rows>
+struct all_unroller<Derived, 0, Rows>
+{
+ EIGEN_DEVICE_FUNC static inline bool run(const Derived &/*mat*/) { return true; }
+};
+
+template<typename Derived, int Rows>
+struct all_unroller<Derived, Dynamic, Rows>
+{
+ EIGEN_DEVICE_FUNC static inline bool run(const Derived &) { return false; }
+};
+
+template<typename Derived, int UnrollCount, int Rows>
+struct any_unroller
+{
+ enum {
+ col = (UnrollCount-1) / Rows,
+ row = (UnrollCount-1) % Rows
+ };
+
+ EIGEN_DEVICE_FUNC static inline bool run(const Derived &mat)
+ {
+ return any_unroller<Derived, UnrollCount-1, Rows>::run(mat) || mat.coeff(row, col);
+ }
+};
+
+template<typename Derived, int Rows>
+struct any_unroller<Derived, 0, Rows>
+{
+ EIGEN_DEVICE_FUNC static inline bool run(const Derived & /*mat*/) { return false; }
+};
+
+template<typename Derived, int Rows>
+struct any_unroller<Derived, Dynamic, Rows>
+{
+ EIGEN_DEVICE_FUNC static inline bool run(const Derived &) { return false; }
+};
+
+} // end namespace internal
+
+/** \returns true if all coefficients are true
+ *
+ * Example: \include MatrixBase_all.cpp
+ * Output: \verbinclude MatrixBase_all.out
+ *
+ * \sa any(), Cwise::operator<()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::all() const
+{
+ typedef internal::evaluator<Derived> Evaluator;
+ enum {
+ unroll = SizeAtCompileTime != Dynamic
+ && SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits<Scalar>::AddCost)) <= EIGEN_UNROLLING_LIMIT
+ };
+ Evaluator evaluator(derived());
+ if(unroll)
+ return internal::all_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic, internal::traits<Derived>::RowsAtCompileTime>::run(evaluator);
+ else
+ {
+ for(Index j = 0; j < cols(); ++j)
+ for(Index i = 0; i < rows(); ++i)
+ if (!evaluator.coeff(i, j)) return false;
+ return true;
+ }
+}
+
+/** \returns true if at least one coefficient is true
+ *
+ * \sa all()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::any() const
+{
+ typedef internal::evaluator<Derived> Evaluator;
+ enum {
+ unroll = SizeAtCompileTime != Dynamic
+ && SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits<Scalar>::AddCost)) <= EIGEN_UNROLLING_LIMIT
+ };
+ Evaluator evaluator(derived());
+ if(unroll)
+ return internal::any_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic, internal::traits<Derived>::RowsAtCompileTime>::run(evaluator);
+ else
+ {
+ for(Index j = 0; j < cols(); ++j)
+ for(Index i = 0; i < rows(); ++i)
+ if (evaluator.coeff(i, j)) return true;
+ return false;
+ }
+}
+
+/** \returns the number of coefficients which evaluate to true
+ *
+ * \sa all(), any()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline Eigen::Index DenseBase<Derived>::count() const
+{
+ return derived().template cast<bool>().template cast<Index>().sum();
+}
+
+/** \returns true is \c *this contains at least one Not A Number (NaN).
+ *
+ * \sa allFinite()
+ */
+template<typename Derived>
+inline bool DenseBase<Derived>::hasNaN() const
+{
+#if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
+ return derived().array().isNaN().any();
+#else
+ return !((derived().array()==derived().array()).all());
+#endif
+}
+
+/** \returns true if \c *this contains only finite numbers, i.e., no NaN and no +/-INF values.
+ *
+ * \sa hasNaN()
+ */
+template<typename Derived>
+inline bool DenseBase<Derived>::allFinite() const
+{
+#if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
+ return derived().array().isFinite().all();
+#else
+ return !((derived()-derived()).hasNaN());
+#endif
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_ALLANDANY_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/CommaInitializer.h b/src/3rdparty/eigen/Eigen/src/Core/CommaInitializer.h
new file mode 100644
index 000000000..c0e29c75c
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/CommaInitializer.h
@@ -0,0 +1,164 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMMAINITIALIZER_H
+#define EIGEN_COMMAINITIALIZER_H
+
+namespace Eigen {
+
+/** \class CommaInitializer
+ * \ingroup Core_Module
+ *
+ * \brief Helper class used by the comma initializer operator
+ *
+ * This class is internally used to implement the comma initializer feature. It is
+ * the return type of MatrixBase::operator<<, and most of the time this is the only
+ * way it is used.
+ *
+ * \sa \blank \ref MatrixBaseCommaInitRef "MatrixBase::operator<<", CommaInitializer::finished()
+ */
+template<typename XprType>
+struct CommaInitializer
+{
+ typedef typename XprType::Scalar Scalar;
+
+ EIGEN_DEVICE_FUNC
+ inline CommaInitializer(XprType& xpr, const Scalar& s)
+ : m_xpr(xpr), m_row(0), m_col(1), m_currentBlockRows(1)
+ {
+ eigen_assert(m_xpr.rows() > 0 && m_xpr.cols() > 0
+ && "Cannot comma-initialize a 0x0 matrix (operator<<)");
+ m_xpr.coeffRef(0,0) = s;
+ }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ inline CommaInitializer(XprType& xpr, const DenseBase<OtherDerived>& other)
+ : m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows())
+ {
+ eigen_assert(m_xpr.rows() >= other.rows() && m_xpr.cols() >= other.cols()
+ && "Cannot comma-initialize a 0x0 matrix (operator<<)");
+ m_xpr.block(0, 0, other.rows(), other.cols()) = other;
+ }
+
+ /* Copy/Move constructor which transfers ownership. This is crucial in
+ * absence of return value optimization to avoid assertions during destruction. */
+ // FIXME in C++11 mode this could be replaced by a proper RValue constructor
+ EIGEN_DEVICE_FUNC
+ inline CommaInitializer(const CommaInitializer& o)
+ : m_xpr(o.m_xpr), m_row(o.m_row), m_col(o.m_col), m_currentBlockRows(o.m_currentBlockRows) {
+ // Mark original object as finished. In absence of R-value references we need to const_cast:
+ const_cast<CommaInitializer&>(o).m_row = m_xpr.rows();
+ const_cast<CommaInitializer&>(o).m_col = m_xpr.cols();
+ const_cast<CommaInitializer&>(o).m_currentBlockRows = 0;
+ }
+
+ /* inserts a scalar value in the target matrix */
+ EIGEN_DEVICE_FUNC
+ CommaInitializer& operator,(const Scalar& s)
+ {
+ if (m_col==m_xpr.cols())
+ {
+ m_row+=m_currentBlockRows;
+ m_col = 0;
+ m_currentBlockRows = 1;
+ eigen_assert(m_row<m_xpr.rows()
+ && "Too many rows passed to comma initializer (operator<<)");
+ }
+ eigen_assert(m_col<m_xpr.cols()
+ && "Too many coefficients passed to comma initializer (operator<<)");
+ eigen_assert(m_currentBlockRows==1);
+ m_xpr.coeffRef(m_row, m_col++) = s;
+ return *this;
+ }
+
+ /* inserts a matrix expression in the target matrix */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ CommaInitializer& operator,(const DenseBase<OtherDerived>& other)
+ {
+ if (m_col==m_xpr.cols() && (other.cols()!=0 || other.rows()!=m_currentBlockRows))
+ {
+ m_row+=m_currentBlockRows;
+ m_col = 0;
+ m_currentBlockRows = other.rows();
+ eigen_assert(m_row+m_currentBlockRows<=m_xpr.rows()
+ && "Too many rows passed to comma initializer (operator<<)");
+ }
+ eigen_assert((m_col + other.cols() <= m_xpr.cols())
+ && "Too many coefficients passed to comma initializer (operator<<)");
+ eigen_assert(m_currentBlockRows==other.rows());
+ m_xpr.template block<OtherDerived::RowsAtCompileTime, OtherDerived::ColsAtCompileTime>
+ (m_row, m_col, other.rows(), other.cols()) = other;
+ m_col += other.cols();
+ return *this;
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline ~CommaInitializer()
+#if defined VERIFY_RAISES_ASSERT && (!defined EIGEN_NO_ASSERTION_CHECKING) && defined EIGEN_EXCEPTIONS
+ EIGEN_EXCEPTION_SPEC(Eigen::eigen_assert_exception)
+#endif
+ {
+ finished();
+ }
+
+ /** \returns the built matrix once all its coefficients have been set.
+ * Calling finished is 100% optional. Its purpose is to write expressions
+ * like this:
+ * \code
+ * quaternion.fromRotationMatrix((Matrix3f() << axis0, axis1, axis2).finished());
+ * \endcode
+ */
+ EIGEN_DEVICE_FUNC
+ inline XprType& finished() {
+ eigen_assert(((m_row+m_currentBlockRows) == m_xpr.rows() || m_xpr.cols() == 0)
+ && m_col == m_xpr.cols()
+ && "Too few coefficients passed to comma initializer (operator<<)");
+ return m_xpr;
+ }
+
+ XprType& m_xpr; // target expression
+ Index m_row; // current row id
+ Index m_col; // current col id
+ Index m_currentBlockRows; // current block height
+};
+
+/** \anchor MatrixBaseCommaInitRef
+ * Convenient operator to set the coefficients of a matrix.
+ *
+ * The coefficients must be provided in a row major order and exactly match
+ * the size of the matrix. Otherwise an assertion is raised.
+ *
+ * Example: \include MatrixBase_set.cpp
+ * Output: \verbinclude MatrixBase_set.out
+ *
+ * \note According the c++ standard, the argument expressions of this comma initializer are evaluated in arbitrary order.
+ *
+ * \sa CommaInitializer::finished(), class CommaInitializer
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline CommaInitializer<Derived> DenseBase<Derived>::operator<< (const Scalar& s)
+{
+ return CommaInitializer<Derived>(*static_cast<Derived*>(this), s);
+}
+
+/** \sa operator<<(const Scalar&) */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC inline CommaInitializer<Derived>
+DenseBase<Derived>::operator<<(const DenseBase<OtherDerived>& other)
+{
+ return CommaInitializer<Derived>(*static_cast<Derived *>(this), other);
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_COMMAINITIALIZER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/ConditionEstimator.h b/src/3rdparty/eigen/Eigen/src/Core/ConditionEstimator.h
new file mode 100644
index 000000000..51a2e5f1b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/ConditionEstimator.h
@@ -0,0 +1,175 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2016 Rasmus Munk Larsen (rmlarsen@google.com)
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_CONDITIONESTIMATOR_H
+#define EIGEN_CONDITIONESTIMATOR_H
+
+namespace Eigen {
+
+namespace internal {
+
+template <typename Vector, typename RealVector, bool IsComplex>
+struct rcond_compute_sign {
+ static inline Vector run(const Vector& v) {
+ const RealVector v_abs = v.cwiseAbs();
+ return (v_abs.array() == static_cast<typename Vector::RealScalar>(0))
+ .select(Vector::Ones(v.size()), v.cwiseQuotient(v_abs));
+ }
+};
+
+// Partial specialization to avoid elementwise division for real vectors.
+template <typename Vector>
+struct rcond_compute_sign<Vector, Vector, false> {
+ static inline Vector run(const Vector& v) {
+ return (v.array() < static_cast<typename Vector::RealScalar>(0))
+ .select(-Vector::Ones(v.size()), Vector::Ones(v.size()));
+ }
+};
+
+/**
+ * \returns an estimate of ||inv(matrix)||_1 given a decomposition of
+ * \a matrix that implements .solve() and .adjoint().solve() methods.
+ *
+ * This function implements Algorithms 4.1 and 5.1 from
+ * http://www.maths.manchester.ac.uk/~higham/narep/narep135.pdf
+ * which also forms the basis for the condition number estimators in
+ * LAPACK. Since at most 10 calls to the solve method of dec are
+ * performed, the total cost is O(dims^2), as opposed to O(dims^3)
+ * needed to compute the inverse matrix explicitly.
+ *
+ * The most common usage is in estimating the condition number
+ * ||matrix||_1 * ||inv(matrix)||_1. The first term ||matrix||_1 can be
+ * computed directly in O(n^2) operations.
+ *
+ * Supports the following decompositions: FullPivLU, PartialPivLU, LDLT, and
+ * LLT.
+ *
+ * \sa FullPivLU, PartialPivLU, LDLT, LLT.
+ */
+template <typename Decomposition>
+typename Decomposition::RealScalar rcond_invmatrix_L1_norm_estimate(const Decomposition& dec)
+{
+ typedef typename Decomposition::MatrixType MatrixType;
+ typedef typename Decomposition::Scalar Scalar;
+ typedef typename Decomposition::RealScalar RealScalar;
+ typedef typename internal::plain_col_type<MatrixType>::type Vector;
+ typedef typename internal::plain_col_type<MatrixType, RealScalar>::type RealVector;
+ const bool is_complex = (NumTraits<Scalar>::IsComplex != 0);
+
+ eigen_assert(dec.rows() == dec.cols());
+ const Index n = dec.rows();
+ if (n == 0)
+ return 0;
+
+ // Disable Index to float conversion warning
+#ifdef __INTEL_COMPILER
+ #pragma warning push
+ #pragma warning ( disable : 2259 )
+#endif
+ Vector v = dec.solve(Vector::Ones(n) / Scalar(n));
+#ifdef __INTEL_COMPILER
+ #pragma warning pop
+#endif
+
+ // lower_bound is a lower bound on
+ // ||inv(matrix)||_1 = sup_v ||inv(matrix) v||_1 / ||v||_1
+ // and is the objective maximized by the ("super-") gradient ascent
+ // algorithm below.
+ RealScalar lower_bound = v.template lpNorm<1>();
+ if (n == 1)
+ return lower_bound;
+
+ // Gradient ascent algorithm follows: We know that the optimum is achieved at
+ // one of the simplices v = e_i, so in each iteration we follow a
+ // super-gradient to move towards the optimal one.
+ RealScalar old_lower_bound = lower_bound;
+ Vector sign_vector(n);
+ Vector old_sign_vector;
+ Index v_max_abs_index = -1;
+ Index old_v_max_abs_index = v_max_abs_index;
+ for (int k = 0; k < 4; ++k)
+ {
+ sign_vector = internal::rcond_compute_sign<Vector, RealVector, is_complex>::run(v);
+ if (k > 0 && !is_complex && sign_vector == old_sign_vector) {
+ // Break if the solution stagnated.
+ break;
+ }
+ // v_max_abs_index = argmax |real( inv(matrix)^T * sign_vector )|
+ v = dec.adjoint().solve(sign_vector);
+ v.real().cwiseAbs().maxCoeff(&v_max_abs_index);
+ if (v_max_abs_index == old_v_max_abs_index) {
+ // Break if the solution stagnated.
+ break;
+ }
+ // Move to the new simplex e_j, where j = v_max_abs_index.
+ v = dec.solve(Vector::Unit(n, v_max_abs_index)); // v = inv(matrix) * e_j.
+ lower_bound = v.template lpNorm<1>();
+ if (lower_bound <= old_lower_bound) {
+ // Break if the gradient step did not increase the lower_bound.
+ break;
+ }
+ if (!is_complex) {
+ old_sign_vector = sign_vector;
+ }
+ old_v_max_abs_index = v_max_abs_index;
+ old_lower_bound = lower_bound;
+ }
+ // The following calculates an independent estimate of ||matrix||_1 by
+ // multiplying matrix by a vector with entries of slowly increasing
+ // magnitude and alternating sign:
+ // v_i = (-1)^{i} (1 + (i / (dim-1))), i = 0,...,dim-1.
+ // This improvement to Hager's algorithm above is due to Higham. It was
+ // added to make the algorithm more robust in certain corner cases where
+ // large elements in the matrix might otherwise escape detection due to
+ // exact cancellation (especially when op and op_adjoint correspond to a
+ // sequence of backsubstitutions and permutations), which could cause
+ // Hager's algorithm to vastly underestimate ||matrix||_1.
+ Scalar alternating_sign(RealScalar(1));
+ for (Index i = 0; i < n; ++i) {
+ // The static_cast is needed when Scalar is a complex and RealScalar implements expression templates
+ v[i] = alternating_sign * static_cast<RealScalar>(RealScalar(1) + (RealScalar(i) / (RealScalar(n - 1))));
+ alternating_sign = -alternating_sign;
+ }
+ v = dec.solve(v);
+ const RealScalar alternate_lower_bound = (2 * v.template lpNorm<1>()) / (3 * RealScalar(n));
+ return numext::maxi(lower_bound, alternate_lower_bound);
+}
+
+/** \brief Reciprocal condition number estimator.
+ *
+ * Computing a decomposition of a dense matrix takes O(n^3) operations, while
+ * this method estimates the condition number quickly and reliably in O(n^2)
+ * operations.
+ *
+ * \returns an estimate of the reciprocal condition number
+ * (1 / (||matrix||_1 * ||inv(matrix)||_1)) of matrix, given ||matrix||_1 and
+ * its decomposition. Supports the following decompositions: FullPivLU,
+ * PartialPivLU, LDLT, and LLT.
+ *
+ * \sa FullPivLU, PartialPivLU, LDLT, LLT.
+ */
+template <typename Decomposition>
+typename Decomposition::RealScalar
+rcond_estimate_helper(typename Decomposition::RealScalar matrix_norm, const Decomposition& dec)
+{
+ typedef typename Decomposition::RealScalar RealScalar;
+ eigen_assert(dec.rows() == dec.cols());
+ if (dec.rows() == 0) return NumTraits<RealScalar>::infinity();
+ if (matrix_norm == RealScalar(0)) return RealScalar(0);
+ if (dec.rows() == 1) return RealScalar(1);
+ const RealScalar inverse_matrix_norm = rcond_invmatrix_L1_norm_estimate(dec);
+ return (inverse_matrix_norm == RealScalar(0) ? RealScalar(0)
+ : (RealScalar(1) / inverse_matrix_norm) / matrix_norm);
+}
+
+} // namespace internal
+
+} // namespace Eigen
+
+#endif
diff --git a/src/3rdparty/eigen/Eigen/src/Core/CoreEvaluators.h b/src/3rdparty/eigen/Eigen/src/Core/CoreEvaluators.h
new file mode 100644
index 000000000..0ff8c8deb
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/CoreEvaluators.h
@@ -0,0 +1,1741 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2011-2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#ifndef EIGEN_COREEVALUATORS_H
+#define EIGEN_COREEVALUATORS_H
+
+namespace Eigen {
+
+namespace internal {
+
+// This class returns the evaluator kind from the expression storage kind.
+// Default assumes index based accessors
+template<typename StorageKind>
+struct storage_kind_to_evaluator_kind {
+ typedef IndexBased Kind;
+};
+
+// This class returns the evaluator shape from the expression storage kind.
+// It can be Dense, Sparse, Triangular, Diagonal, SelfAdjoint, Band, etc.
+template<typename StorageKind> struct storage_kind_to_shape;
+
+template<> struct storage_kind_to_shape<Dense> { typedef DenseShape Shape; };
+template<> struct storage_kind_to_shape<SolverStorage> { typedef SolverShape Shape; };
+template<> struct storage_kind_to_shape<PermutationStorage> { typedef PermutationShape Shape; };
+template<> struct storage_kind_to_shape<TranspositionsStorage> { typedef TranspositionsShape Shape; };
+
+// Evaluators have to be specialized with respect to various criteria such as:
+// - storage/structure/shape
+// - scalar type
+// - etc.
+// Therefore, we need specialization of evaluator providing additional template arguments for each kind of evaluators.
+// We currently distinguish the following kind of evaluators:
+// - unary_evaluator for expressions taking only one arguments (CwiseUnaryOp, CwiseUnaryView, Transpose, MatrixWrapper, ArrayWrapper, Reverse, Replicate)
+// - binary_evaluator for expression taking two arguments (CwiseBinaryOp)
+// - ternary_evaluator for expression taking three arguments (CwiseTernaryOp)
+// - product_evaluator for linear algebra products (Product); special case of binary_evaluator because it requires additional tags for dispatching.
+// - mapbase_evaluator for Map, Block, Ref
+// - block_evaluator for Block (special dispatching to a mapbase_evaluator or unary_evaluator)
+
+template< typename T,
+ typename Arg1Kind = typename evaluator_traits<typename T::Arg1>::Kind,
+ typename Arg2Kind = typename evaluator_traits<typename T::Arg2>::Kind,
+ typename Arg3Kind = typename evaluator_traits<typename T::Arg3>::Kind,
+ typename Arg1Scalar = typename traits<typename T::Arg1>::Scalar,
+ typename Arg2Scalar = typename traits<typename T::Arg2>::Scalar,
+ typename Arg3Scalar = typename traits<typename T::Arg3>::Scalar> struct ternary_evaluator;
+
+template< typename T,
+ typename LhsKind = typename evaluator_traits<typename T::Lhs>::Kind,
+ typename RhsKind = typename evaluator_traits<typename T::Rhs>::Kind,
+ typename LhsScalar = typename traits<typename T::Lhs>::Scalar,
+ typename RhsScalar = typename traits<typename T::Rhs>::Scalar> struct binary_evaluator;
+
+template< typename T,
+ typename Kind = typename evaluator_traits<typename T::NestedExpression>::Kind,
+ typename Scalar = typename T::Scalar> struct unary_evaluator;
+
+// evaluator_traits<T> contains traits for evaluator<T>
+
+template<typename T>
+struct evaluator_traits_base
+{
+ // by default, get evaluator kind and shape from storage
+ typedef typename storage_kind_to_evaluator_kind<typename traits<T>::StorageKind>::Kind Kind;
+ typedef typename storage_kind_to_shape<typename traits<T>::StorageKind>::Shape Shape;
+};
+
+// Default evaluator traits
+template<typename T>
+struct evaluator_traits : public evaluator_traits_base<T>
+{
+};
+
+template<typename T, typename Shape = typename evaluator_traits<T>::Shape >
+struct evaluator_assume_aliasing {
+ static const bool value = false;
+};
+
+// By default, we assume a unary expression:
+template<typename T>
+struct evaluator : public unary_evaluator<T>
+{
+ typedef unary_evaluator<T> Base;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit evaluator(const T& xpr) : Base(xpr) {}
+};
+
+
+// TODO: Think about const-correctness
+template<typename T>
+struct evaluator<const T>
+ : evaluator<T>
+{
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit evaluator(const T& xpr) : evaluator<T>(xpr) {}
+};
+
+// ---------- base class for all evaluators ----------
+
+template<typename ExpressionType>
+struct evaluator_base
+{
+ // TODO that's not very nice to have to propagate all these traits. They are currently only needed to handle outer,inner indices.
+ typedef traits<ExpressionType> ExpressionTraits;
+
+ enum {
+ Alignment = 0
+ };
+ // noncopyable:
+ // Don't make this class inherit noncopyable as this kills EBO (Empty Base Optimization)
+ // and make complex evaluator much larger than then should do.
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator_base() {}
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ~evaluator_base() {}
+private:
+ EIGEN_DEVICE_FUNC evaluator_base(const evaluator_base&);
+ EIGEN_DEVICE_FUNC const evaluator_base& operator=(const evaluator_base&);
+};
+
+// -------------------- Matrix and Array --------------------
+//
+// evaluator<PlainObjectBase> is a common base class for the
+// Matrix and Array evaluators.
+// Here we directly specialize evaluator. This is not really a unary expression, and it is, by definition, dense,
+// so no need for more sophisticated dispatching.
+
+// this helper permits to completely eliminate m_outerStride if it is known at compiletime.
+template<typename Scalar,int OuterStride> class plainobjectbase_evaluator_data {
+public:
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ plainobjectbase_evaluator_data(const Scalar* ptr, Index outerStride) : data(ptr)
+ {
+#ifndef EIGEN_INTERNAL_DEBUGGING
+ EIGEN_UNUSED_VARIABLE(outerStride);
+#endif
+ eigen_internal_assert(outerStride==OuterStride);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index outerStride() const EIGEN_NOEXCEPT { return OuterStride; }
+ const Scalar *data;
+};
+
+template<typename Scalar> class plainobjectbase_evaluator_data<Scalar,Dynamic> {
+public:
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ plainobjectbase_evaluator_data(const Scalar* ptr, Index outerStride) : data(ptr), m_outerStride(outerStride) {}
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Index outerStride() const { return m_outerStride; }
+ const Scalar *data;
+protected:
+ Index m_outerStride;
+};
+
+template<typename Derived>
+struct evaluator<PlainObjectBase<Derived> >
+ : evaluator_base<Derived>
+{
+ typedef PlainObjectBase<Derived> PlainObjectType;
+ typedef typename PlainObjectType::Scalar Scalar;
+ typedef typename PlainObjectType::CoeffReturnType CoeffReturnType;
+
+ enum {
+ IsRowMajor = PlainObjectType::IsRowMajor,
+ IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime,
+ RowsAtCompileTime = PlainObjectType::RowsAtCompileTime,
+ ColsAtCompileTime = PlainObjectType::ColsAtCompileTime,
+
+ CoeffReadCost = NumTraits<Scalar>::ReadCost,
+ Flags = traits<Derived>::EvaluatorFlags,
+ Alignment = traits<Derived>::Alignment
+ };
+ enum {
+ // We do not need to know the outer stride for vectors
+ OuterStrideAtCompileTime = IsVectorAtCompileTime ? 0
+ : int(IsRowMajor) ? ColsAtCompileTime
+ : RowsAtCompileTime
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ evaluator()
+ : m_d(0,OuterStrideAtCompileTime)
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit evaluator(const PlainObjectType& m)
+ : m_d(m.data(),IsVectorAtCompileTime ? 0 : m.outerStride())
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ if (IsRowMajor)
+ return m_d.data[row * m_d.outerStride() + col];
+ else
+ return m_d.data[row + col * m_d.outerStride()];
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ return m_d.data[index];
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index row, Index col)
+ {
+ if (IsRowMajor)
+ return const_cast<Scalar*>(m_d.data)[row * m_d.outerStride() + col];
+ else
+ return const_cast<Scalar*>(m_d.data)[row + col * m_d.outerStride()];
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index index)
+ {
+ return const_cast<Scalar*>(m_d.data)[index];
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index row, Index col) const
+ {
+ if (IsRowMajor)
+ return ploadt<PacketType, LoadMode>(m_d.data + row * m_d.outerStride() + col);
+ else
+ return ploadt<PacketType, LoadMode>(m_d.data + row + col * m_d.outerStride());
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index index) const
+ {
+ return ploadt<PacketType, LoadMode>(m_d.data + index);
+ }
+
+ template<int StoreMode,typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index row, Index col, const PacketType& x)
+ {
+ if (IsRowMajor)
+ return pstoret<Scalar, PacketType, StoreMode>
+ (const_cast<Scalar*>(m_d.data) + row * m_d.outerStride() + col, x);
+ else
+ return pstoret<Scalar, PacketType, StoreMode>
+ (const_cast<Scalar*>(m_d.data) + row + col * m_d.outerStride(), x);
+ }
+
+ template<int StoreMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index index, const PacketType& x)
+ {
+ return pstoret<Scalar, PacketType, StoreMode>(const_cast<Scalar*>(m_d.data) + index, x);
+ }
+
+protected:
+
+ plainobjectbase_evaluator_data<Scalar,OuterStrideAtCompileTime> m_d;
+};
+
+template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
+struct evaluator<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
+ : evaluator<PlainObjectBase<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
+{
+ typedef Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ evaluator() {}
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit evaluator(const XprType& m)
+ : evaluator<PlainObjectBase<XprType> >(m)
+ { }
+};
+
+template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
+struct evaluator<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
+ : evaluator<PlainObjectBase<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
+{
+ typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ evaluator() {}
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit evaluator(const XprType& m)
+ : evaluator<PlainObjectBase<XprType> >(m)
+ { }
+};
+
+// -------------------- Transpose --------------------
+
+template<typename ArgType>
+struct unary_evaluator<Transpose<ArgType>, IndexBased>
+ : evaluator_base<Transpose<ArgType> >
+{
+ typedef Transpose<ArgType> XprType;
+
+ enum {
+ CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
+ Flags = evaluator<ArgType>::Flags ^ RowMajorBit,
+ Alignment = evaluator<ArgType>::Alignment
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit unary_evaluator(const XprType& t) : m_argImpl(t.nestedExpression()) {}
+
+ typedef typename XprType::Scalar Scalar;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ return m_argImpl.coeff(col, row);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ return m_argImpl.coeff(index);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index row, Index col)
+ {
+ return m_argImpl.coeffRef(col, row);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ typename XprType::Scalar& coeffRef(Index index)
+ {
+ return m_argImpl.coeffRef(index);
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index row, Index col) const
+ {
+ return m_argImpl.template packet<LoadMode,PacketType>(col, row);
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index index) const
+ {
+ return m_argImpl.template packet<LoadMode,PacketType>(index);
+ }
+
+ template<int StoreMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index row, Index col, const PacketType& x)
+ {
+ m_argImpl.template writePacket<StoreMode,PacketType>(col, row, x);
+ }
+
+ template<int StoreMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index index, const PacketType& x)
+ {
+ m_argImpl.template writePacket<StoreMode,PacketType>(index, x);
+ }
+
+protected:
+ evaluator<ArgType> m_argImpl;
+};
+
+// -------------------- CwiseNullaryOp --------------------
+// Like Matrix and Array, this is not really a unary expression, so we directly specialize evaluator.
+// Likewise, there is not need to more sophisticated dispatching here.
+
+template<typename Scalar,typename NullaryOp,
+ bool has_nullary = has_nullary_operator<NullaryOp>::value,
+ bool has_unary = has_unary_operator<NullaryOp>::value,
+ bool has_binary = has_binary_operator<NullaryOp>::value>
+struct nullary_wrapper
+{
+ template <typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j) const { return op(i,j); }
+ template <typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i) const { return op(i); }
+
+ template <typename T, typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j) const { return op.template packetOp<T>(i,j); }
+ template <typename T, typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i) const { return op.template packetOp<T>(i); }
+};
+
+template<typename Scalar,typename NullaryOp>
+struct nullary_wrapper<Scalar,NullaryOp,true,false,false>
+{
+ template <typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType=0, IndexType=0) const { return op(); }
+ template <typename T, typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType=0, IndexType=0) const { return op.template packetOp<T>(); }
+};
+
+template<typename Scalar,typename NullaryOp>
+struct nullary_wrapper<Scalar,NullaryOp,false,false,true>
+{
+ template <typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j=0) const { return op(i,j); }
+ template <typename T, typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j=0) const { return op.template packetOp<T>(i,j); }
+};
+
+// We need the following specialization for vector-only functors assigned to a runtime vector,
+// for instance, using linspace and assigning a RowVectorXd to a MatrixXd or even a row of a MatrixXd.
+// In this case, i==0 and j is used for the actual iteration.
+template<typename Scalar,typename NullaryOp>
+struct nullary_wrapper<Scalar,NullaryOp,false,true,false>
+{
+ template <typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j) const {
+ eigen_assert(i==0 || j==0);
+ return op(i+j);
+ }
+ template <typename T, typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j) const {
+ eigen_assert(i==0 || j==0);
+ return op.template packetOp<T>(i+j);
+ }
+
+ template <typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i) const { return op(i); }
+ template <typename T, typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i) const { return op.template packetOp<T>(i); }
+};
+
+template<typename Scalar,typename NullaryOp>
+struct nullary_wrapper<Scalar,NullaryOp,false,false,false> {};
+
+#if 0 && EIGEN_COMP_MSVC>0
+// Disable this ugly workaround. This is now handled in traits<Ref>::match,
+// but this piece of code might still become handly if some other weird compilation
+// erros pop up again.
+
+// MSVC exhibits a weird compilation error when
+// compiling:
+// Eigen::MatrixXf A = MatrixXf::Random(3,3);
+// Ref<const MatrixXf> R = 2.f*A;
+// and that has_*ary_operator<scalar_constant_op<float>> have not been instantiated yet.
+// The "problem" is that evaluator<2.f*A> is instantiated by traits<Ref>::match<2.f*A>
+// and at that time has_*ary_operator<T> returns true regardless of T.
+// Then nullary_wrapper is badly instantiated as nullary_wrapper<.,.,true,true,true>.
+// The trick is thus to defer the proper instantiation of nullary_wrapper when coeff(),
+// and packet() are really instantiated as implemented below:
+
+// This is a simple wrapper around Index to enforce the re-instantiation of
+// has_*ary_operator when needed.
+template<typename T> struct nullary_wrapper_workaround_msvc {
+ nullary_wrapper_workaround_msvc(const T&);
+ operator T()const;
+};
+
+template<typename Scalar,typename NullaryOp>
+struct nullary_wrapper<Scalar,NullaryOp,true,true,true>
+{
+ template <typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j) const {
+ return nullary_wrapper<Scalar,NullaryOp,
+ has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
+ has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
+ has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().operator()(op,i,j);
+ }
+ template <typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i) const {
+ return nullary_wrapper<Scalar,NullaryOp,
+ has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
+ has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
+ has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().operator()(op,i);
+ }
+
+ template <typename T, typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j) const {
+ return nullary_wrapper<Scalar,NullaryOp,
+ has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
+ has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
+ has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().template packetOp<T>(op,i,j);
+ }
+ template <typename T, typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i) const {
+ return nullary_wrapper<Scalar,NullaryOp,
+ has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
+ has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
+ has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().template packetOp<T>(op,i);
+ }
+};
+#endif // MSVC workaround
+
+template<typename NullaryOp, typename PlainObjectType>
+struct evaluator<CwiseNullaryOp<NullaryOp,PlainObjectType> >
+ : evaluator_base<CwiseNullaryOp<NullaryOp,PlainObjectType> >
+{
+ typedef CwiseNullaryOp<NullaryOp,PlainObjectType> XprType;
+ typedef typename internal::remove_all<PlainObjectType>::type PlainObjectTypeCleaned;
+
+ enum {
+ CoeffReadCost = internal::functor_traits<NullaryOp>::Cost,
+
+ Flags = (evaluator<PlainObjectTypeCleaned>::Flags
+ & ( HereditaryBits
+ | (functor_has_linear_access<NullaryOp>::ret ? LinearAccessBit : 0)
+ | (functor_traits<NullaryOp>::PacketAccess ? PacketAccessBit : 0)))
+ | (functor_traits<NullaryOp>::IsRepeatable ? 0 : EvalBeforeNestingBit),
+ Alignment = AlignedMax
+ };
+
+ EIGEN_DEVICE_FUNC explicit evaluator(const XprType& n)
+ : m_functor(n.functor()), m_wrapper()
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ template <typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(IndexType row, IndexType col) const
+ {
+ return m_wrapper(m_functor, row, col);
+ }
+
+ template <typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(IndexType index) const
+ {
+ return m_wrapper(m_functor,index);
+ }
+
+ template<int LoadMode, typename PacketType, typename IndexType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(IndexType row, IndexType col) const
+ {
+ return m_wrapper.template packetOp<PacketType>(m_functor, row, col);
+ }
+
+ template<int LoadMode, typename PacketType, typename IndexType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(IndexType index) const
+ {
+ return m_wrapper.template packetOp<PacketType>(m_functor, index);
+ }
+
+protected:
+ const NullaryOp m_functor;
+ const internal::nullary_wrapper<CoeffReturnType,NullaryOp> m_wrapper;
+};
+
+// -------------------- CwiseUnaryOp --------------------
+
+template<typename UnaryOp, typename ArgType>
+struct unary_evaluator<CwiseUnaryOp<UnaryOp, ArgType>, IndexBased >
+ : evaluator_base<CwiseUnaryOp<UnaryOp, ArgType> >
+{
+ typedef CwiseUnaryOp<UnaryOp, ArgType> XprType;
+
+ enum {
+ CoeffReadCost = int(evaluator<ArgType>::CoeffReadCost) + int(functor_traits<UnaryOp>::Cost),
+
+ Flags = evaluator<ArgType>::Flags
+ & (HereditaryBits | LinearAccessBit | (functor_traits<UnaryOp>::PacketAccess ? PacketAccessBit : 0)),
+ Alignment = evaluator<ArgType>::Alignment
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit unary_evaluator(const XprType& op) : m_d(op)
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost);
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ return m_d.func()(m_d.argImpl.coeff(row, col));
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ return m_d.func()(m_d.argImpl.coeff(index));
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index row, Index col) const
+ {
+ return m_d.func().packetOp(m_d.argImpl.template packet<LoadMode, PacketType>(row, col));
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index index) const
+ {
+ return m_d.func().packetOp(m_d.argImpl.template packet<LoadMode, PacketType>(index));
+ }
+
+protected:
+
+ // this helper permits to completely eliminate the functor if it is empty
+ struct Data
+ {
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Data(const XprType& xpr) : op(xpr.functor()), argImpl(xpr.nestedExpression()) {}
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const UnaryOp& func() const { return op; }
+ UnaryOp op;
+ evaluator<ArgType> argImpl;
+ };
+
+ Data m_d;
+};
+
+// -------------------- CwiseTernaryOp --------------------
+
+// this is a ternary expression
+template<typename TernaryOp, typename Arg1, typename Arg2, typename Arg3>
+struct evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >
+ : public ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >
+{
+ typedef CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> XprType;
+ typedef ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> > Base;
+
+ EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) : Base(xpr) {}
+};
+
+template<typename TernaryOp, typename Arg1, typename Arg2, typename Arg3>
+struct ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3>, IndexBased, IndexBased>
+ : evaluator_base<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >
+{
+ typedef CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> XprType;
+
+ enum {
+ CoeffReadCost = int(evaluator<Arg1>::CoeffReadCost) + int(evaluator<Arg2>::CoeffReadCost) + int(evaluator<Arg3>::CoeffReadCost) + int(functor_traits<TernaryOp>::Cost),
+
+ Arg1Flags = evaluator<Arg1>::Flags,
+ Arg2Flags = evaluator<Arg2>::Flags,
+ Arg3Flags = evaluator<Arg3>::Flags,
+ SameType = is_same<typename Arg1::Scalar,typename Arg2::Scalar>::value && is_same<typename Arg1::Scalar,typename Arg3::Scalar>::value,
+ StorageOrdersAgree = (int(Arg1Flags)&RowMajorBit)==(int(Arg2Flags)&RowMajorBit) && (int(Arg1Flags)&RowMajorBit)==(int(Arg3Flags)&RowMajorBit),
+ Flags0 = (int(Arg1Flags) | int(Arg2Flags) | int(Arg3Flags)) & (
+ HereditaryBits
+ | (int(Arg1Flags) & int(Arg2Flags) & int(Arg3Flags) &
+ ( (StorageOrdersAgree ? LinearAccessBit : 0)
+ | (functor_traits<TernaryOp>::PacketAccess && StorageOrdersAgree && SameType ? PacketAccessBit : 0)
+ )
+ )
+ ),
+ Flags = (Flags0 & ~RowMajorBit) | (Arg1Flags & RowMajorBit),
+ Alignment = EIGEN_PLAIN_ENUM_MIN(
+ EIGEN_PLAIN_ENUM_MIN(evaluator<Arg1>::Alignment, evaluator<Arg2>::Alignment),
+ evaluator<Arg3>::Alignment)
+ };
+
+ EIGEN_DEVICE_FUNC explicit ternary_evaluator(const XprType& xpr) : m_d(xpr)
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<TernaryOp>::Cost);
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ return m_d.func()(m_d.arg1Impl.coeff(row, col), m_d.arg2Impl.coeff(row, col), m_d.arg3Impl.coeff(row, col));
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ return m_d.func()(m_d.arg1Impl.coeff(index), m_d.arg2Impl.coeff(index), m_d.arg3Impl.coeff(index));
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index row, Index col) const
+ {
+ return m_d.func().packetOp(m_d.arg1Impl.template packet<LoadMode,PacketType>(row, col),
+ m_d.arg2Impl.template packet<LoadMode,PacketType>(row, col),
+ m_d.arg3Impl.template packet<LoadMode,PacketType>(row, col));
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index index) const
+ {
+ return m_d.func().packetOp(m_d.arg1Impl.template packet<LoadMode,PacketType>(index),
+ m_d.arg2Impl.template packet<LoadMode,PacketType>(index),
+ m_d.arg3Impl.template packet<LoadMode,PacketType>(index));
+ }
+
+protected:
+ // this helper permits to completely eliminate the functor if it is empty
+ struct Data
+ {
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Data(const XprType& xpr) : op(xpr.functor()), arg1Impl(xpr.arg1()), arg2Impl(xpr.arg2()), arg3Impl(xpr.arg3()) {}
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const TernaryOp& func() const { return op; }
+ TernaryOp op;
+ evaluator<Arg1> arg1Impl;
+ evaluator<Arg2> arg2Impl;
+ evaluator<Arg3> arg3Impl;
+ };
+
+ Data m_d;
+};
+
+// -------------------- CwiseBinaryOp --------------------
+
+// this is a binary expression
+template<typename BinaryOp, typename Lhs, typename Rhs>
+struct evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
+ : public binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
+{
+ typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType;
+ typedef binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > Base;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit evaluator(const XprType& xpr) : Base(xpr) {}
+};
+
+template<typename BinaryOp, typename Lhs, typename Rhs>
+struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IndexBased, IndexBased>
+ : evaluator_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
+{
+ typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType;
+
+ enum {
+ CoeffReadCost = int(evaluator<Lhs>::CoeffReadCost) + int(evaluator<Rhs>::CoeffReadCost) + int(functor_traits<BinaryOp>::Cost),
+
+ LhsFlags = evaluator<Lhs>::Flags,
+ RhsFlags = evaluator<Rhs>::Flags,
+ SameType = is_same<typename Lhs::Scalar,typename Rhs::Scalar>::value,
+ StorageOrdersAgree = (int(LhsFlags)&RowMajorBit)==(int(RhsFlags)&RowMajorBit),
+ Flags0 = (int(LhsFlags) | int(RhsFlags)) & (
+ HereditaryBits
+ | (int(LhsFlags) & int(RhsFlags) &
+ ( (StorageOrdersAgree ? LinearAccessBit : 0)
+ | (functor_traits<BinaryOp>::PacketAccess && StorageOrdersAgree && SameType ? PacketAccessBit : 0)
+ )
+ )
+ ),
+ Flags = (Flags0 & ~RowMajorBit) | (LhsFlags & RowMajorBit),
+ Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<Lhs>::Alignment,evaluator<Rhs>::Alignment)
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit binary_evaluator(const XprType& xpr) : m_d(xpr)
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost);
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ return m_d.func()(m_d.lhsImpl.coeff(row, col), m_d.rhsImpl.coeff(row, col));
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ return m_d.func()(m_d.lhsImpl.coeff(index), m_d.rhsImpl.coeff(index));
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index row, Index col) const
+ {
+ return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode,PacketType>(row, col),
+ m_d.rhsImpl.template packet<LoadMode,PacketType>(row, col));
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index index) const
+ {
+ return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode,PacketType>(index),
+ m_d.rhsImpl.template packet<LoadMode,PacketType>(index));
+ }
+
+protected:
+
+ // this helper permits to completely eliminate the functor if it is empty
+ struct Data
+ {
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Data(const XprType& xpr) : op(xpr.functor()), lhsImpl(xpr.lhs()), rhsImpl(xpr.rhs()) {}
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const BinaryOp& func() const { return op; }
+ BinaryOp op;
+ evaluator<Lhs> lhsImpl;
+ evaluator<Rhs> rhsImpl;
+ };
+
+ Data m_d;
+};
+
+// -------------------- CwiseUnaryView --------------------
+
+template<typename UnaryOp, typename ArgType>
+struct unary_evaluator<CwiseUnaryView<UnaryOp, ArgType>, IndexBased>
+ : evaluator_base<CwiseUnaryView<UnaryOp, ArgType> >
+{
+ typedef CwiseUnaryView<UnaryOp, ArgType> XprType;
+
+ enum {
+ CoeffReadCost = int(evaluator<ArgType>::CoeffReadCost) + int(functor_traits<UnaryOp>::Cost),
+
+ Flags = (evaluator<ArgType>::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit)),
+
+ Alignment = 0 // FIXME it is not very clear why alignment is necessarily lost...
+ };
+
+ EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& op) : m_d(op)
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost);
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ typedef typename XprType::Scalar Scalar;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ return m_d.func()(m_d.argImpl.coeff(row, col));
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ return m_d.func()(m_d.argImpl.coeff(index));
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index row, Index col)
+ {
+ return m_d.func()(m_d.argImpl.coeffRef(row, col));
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index index)
+ {
+ return m_d.func()(m_d.argImpl.coeffRef(index));
+ }
+
+protected:
+
+ // this helper permits to completely eliminate the functor if it is empty
+ struct Data
+ {
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Data(const XprType& xpr) : op(xpr.functor()), argImpl(xpr.nestedExpression()) {}
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const UnaryOp& func() const { return op; }
+ UnaryOp op;
+ evaluator<ArgType> argImpl;
+ };
+
+ Data m_d;
+};
+
+// -------------------- Map --------------------
+
+// FIXME perhaps the PlainObjectType could be provided by Derived::PlainObject ?
+// but that might complicate template specialization
+template<typename Derived, typename PlainObjectType>
+struct mapbase_evaluator;
+
+template<typename Derived, typename PlainObjectType>
+struct mapbase_evaluator : evaluator_base<Derived>
+{
+ typedef Derived XprType;
+ typedef typename XprType::PointerType PointerType;
+ typedef typename XprType::Scalar Scalar;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ enum {
+ IsRowMajor = XprType::RowsAtCompileTime,
+ ColsAtCompileTime = XprType::ColsAtCompileTime,
+ CoeffReadCost = NumTraits<Scalar>::ReadCost
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit mapbase_evaluator(const XprType& map)
+ : m_data(const_cast<PointerType>(map.data())),
+ m_innerStride(map.innerStride()),
+ m_outerStride(map.outerStride())
+ {
+ EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(evaluator<Derived>::Flags&PacketAccessBit, internal::inner_stride_at_compile_time<Derived>::ret==1),
+ PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ return m_data[col * colStride() + row * rowStride()];
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ return m_data[index * m_innerStride.value()];
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index row, Index col)
+ {
+ return m_data[col * colStride() + row * rowStride()];
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index index)
+ {
+ return m_data[index * m_innerStride.value()];
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index row, Index col) const
+ {
+ PointerType ptr = m_data + row * rowStride() + col * colStride();
+ return internal::ploadt<PacketType, LoadMode>(ptr);
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index index) const
+ {
+ return internal::ploadt<PacketType, LoadMode>(m_data + index * m_innerStride.value());
+ }
+
+ template<int StoreMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index row, Index col, const PacketType& x)
+ {
+ PointerType ptr = m_data + row * rowStride() + col * colStride();
+ return internal::pstoret<Scalar, PacketType, StoreMode>(ptr, x);
+ }
+
+ template<int StoreMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index index, const PacketType& x)
+ {
+ internal::pstoret<Scalar, PacketType, StoreMode>(m_data + index * m_innerStride.value(), x);
+ }
+protected:
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index rowStride() const EIGEN_NOEXCEPT {
+ return XprType::IsRowMajor ? m_outerStride.value() : m_innerStride.value();
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index colStride() const EIGEN_NOEXCEPT {
+ return XprType::IsRowMajor ? m_innerStride.value() : m_outerStride.value();
+ }
+
+ PointerType m_data;
+ const internal::variable_if_dynamic<Index, XprType::InnerStrideAtCompileTime> m_innerStride;
+ const internal::variable_if_dynamic<Index, XprType::OuterStrideAtCompileTime> m_outerStride;
+};
+
+template<typename PlainObjectType, int MapOptions, typename StrideType>
+struct evaluator<Map<PlainObjectType, MapOptions, StrideType> >
+ : public mapbase_evaluator<Map<PlainObjectType, MapOptions, StrideType>, PlainObjectType>
+{
+ typedef Map<PlainObjectType, MapOptions, StrideType> XprType;
+ typedef typename XprType::Scalar Scalar;
+ // TODO: should check for smaller packet types once we can handle multi-sized packet types
+ typedef typename packet_traits<Scalar>::type PacketScalar;
+
+ enum {
+ InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
+ ? int(PlainObjectType::InnerStrideAtCompileTime)
+ : int(StrideType::InnerStrideAtCompileTime),
+ OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
+ ? int(PlainObjectType::OuterStrideAtCompileTime)
+ : int(StrideType::OuterStrideAtCompileTime),
+ HasNoInnerStride = InnerStrideAtCompileTime == 1,
+ HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0,
+ HasNoStride = HasNoInnerStride && HasNoOuterStride,
+ IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic,
+
+ PacketAccessMask = bool(HasNoInnerStride) ? ~int(0) : ~int(PacketAccessBit),
+ LinearAccessMask = bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime) ? ~int(0) : ~int(LinearAccessBit),
+ Flags = int( evaluator<PlainObjectType>::Flags) & (LinearAccessMask&PacketAccessMask),
+
+ Alignment = int(MapOptions)&int(AlignedMask)
+ };
+
+ EIGEN_DEVICE_FUNC explicit evaluator(const XprType& map)
+ : mapbase_evaluator<XprType, PlainObjectType>(map)
+ { }
+};
+
+// -------------------- Ref --------------------
+
+template<typename PlainObjectType, int RefOptions, typename StrideType>
+struct evaluator<Ref<PlainObjectType, RefOptions, StrideType> >
+ : public mapbase_evaluator<Ref<PlainObjectType, RefOptions, StrideType>, PlainObjectType>
+{
+ typedef Ref<PlainObjectType, RefOptions, StrideType> XprType;
+
+ enum {
+ Flags = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Flags,
+ Alignment = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Alignment
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit evaluator(const XprType& ref)
+ : mapbase_evaluator<XprType, PlainObjectType>(ref)
+ { }
+};
+
+// -------------------- Block --------------------
+
+template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel,
+ bool HasDirectAccess = internal::has_direct_access<ArgType>::ret> struct block_evaluator;
+
+template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel>
+struct evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
+ : block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel>
+{
+ typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
+ typedef typename XprType::Scalar Scalar;
+ // TODO: should check for smaller packet types once we can handle multi-sized packet types
+ typedef typename packet_traits<Scalar>::type PacketScalar;
+
+ enum {
+ CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
+
+ RowsAtCompileTime = traits<XprType>::RowsAtCompileTime,
+ ColsAtCompileTime = traits<XprType>::ColsAtCompileTime,
+ MaxRowsAtCompileTime = traits<XprType>::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = traits<XprType>::MaxColsAtCompileTime,
+
+ ArgTypeIsRowMajor = (int(evaluator<ArgType>::Flags)&RowMajorBit) != 0,
+ IsRowMajor = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? 1
+ : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
+ : ArgTypeIsRowMajor,
+ HasSameStorageOrderAsArgType = (IsRowMajor == ArgTypeIsRowMajor),
+ InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
+ InnerStrideAtCompileTime = HasSameStorageOrderAsArgType
+ ? int(inner_stride_at_compile_time<ArgType>::ret)
+ : int(outer_stride_at_compile_time<ArgType>::ret),
+ OuterStrideAtCompileTime = HasSameStorageOrderAsArgType
+ ? int(outer_stride_at_compile_time<ArgType>::ret)
+ : int(inner_stride_at_compile_time<ArgType>::ret),
+ MaskPacketAccessBit = (InnerStrideAtCompileTime == 1 || HasSameStorageOrderAsArgType) ? PacketAccessBit : 0,
+
+ FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1 || (InnerPanel && (evaluator<ArgType>::Flags&LinearAccessBit))) ? LinearAccessBit : 0,
+ FlagsRowMajorBit = XprType::Flags&RowMajorBit,
+ Flags0 = evaluator<ArgType>::Flags & ( (HereditaryBits & ~RowMajorBit) |
+ DirectAccessBit |
+ MaskPacketAccessBit),
+ Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit,
+
+ PacketAlignment = unpacket_traits<PacketScalar>::alignment,
+ Alignment0 = (InnerPanel && (OuterStrideAtCompileTime!=Dynamic)
+ && (OuterStrideAtCompileTime!=0)
+ && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % int(PacketAlignment)) == 0)) ? int(PacketAlignment) : 0,
+ Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ArgType>::Alignment, Alignment0)
+ };
+ typedef block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel> block_evaluator_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit evaluator(const XprType& block) : block_evaluator_type(block)
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+};
+
+// no direct-access => dispatch to a unary evaluator
+template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel>
+struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, /*HasDirectAccess*/ false>
+ : unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
+{
+ typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit block_evaluator(const XprType& block)
+ : unary_evaluator<XprType>(block)
+ {}
+};
+
+template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel>
+struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBased>
+ : evaluator_base<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
+{
+ typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit unary_evaluator(const XprType& block)
+ : m_argImpl(block.nestedExpression()),
+ m_startRow(block.startRow()),
+ m_startCol(block.startCol()),
+ m_linear_offset(ForwardLinearAccess?(ArgType::IsRowMajor ? block.startRow()*block.nestedExpression().cols() + block.startCol() : block.startCol()*block.nestedExpression().rows() + block.startRow()):0)
+ { }
+
+ typedef typename XprType::Scalar Scalar;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ enum {
+ RowsAtCompileTime = XprType::RowsAtCompileTime,
+ ForwardLinearAccess = (InnerPanel || int(XprType::IsRowMajor)==int(ArgType::IsRowMajor)) && bool(evaluator<ArgType>::Flags&LinearAccessBit)
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ return m_argImpl.coeff(m_startRow.value() + row, m_startCol.value() + col);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ return linear_coeff_impl(index, bool_constant<ForwardLinearAccess>());
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index row, Index col)
+ {
+ return m_argImpl.coeffRef(m_startRow.value() + row, m_startCol.value() + col);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index index)
+ {
+ return linear_coeffRef_impl(index, bool_constant<ForwardLinearAccess>());
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index row, Index col) const
+ {
+ return m_argImpl.template packet<LoadMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col);
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index index) const
+ {
+ if (ForwardLinearAccess)
+ return m_argImpl.template packet<LoadMode,PacketType>(m_linear_offset.value() + index);
+ else
+ return packet<LoadMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
+ RowsAtCompileTime == 1 ? index : 0);
+ }
+
+ template<int StoreMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index row, Index col, const PacketType& x)
+ {
+ return m_argImpl.template writePacket<StoreMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col, x);
+ }
+
+ template<int StoreMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index index, const PacketType& x)
+ {
+ if (ForwardLinearAccess)
+ return m_argImpl.template writePacket<StoreMode,PacketType>(m_linear_offset.value() + index, x);
+ else
+ return writePacket<StoreMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
+ RowsAtCompileTime == 1 ? index : 0,
+ x);
+ }
+
+protected:
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType linear_coeff_impl(Index index, internal::true_type /* ForwardLinearAccess */) const
+ {
+ return m_argImpl.coeff(m_linear_offset.value() + index);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType linear_coeff_impl(Index index, internal::false_type /* not ForwardLinearAccess */) const
+ {
+ return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& linear_coeffRef_impl(Index index, internal::true_type /* ForwardLinearAccess */)
+ {
+ return m_argImpl.coeffRef(m_linear_offset.value() + index);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& linear_coeffRef_impl(Index index, internal::false_type /* not ForwardLinearAccess */)
+ {
+ return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
+ }
+
+ evaluator<ArgType> m_argImpl;
+ const variable_if_dynamic<Index, (ArgType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow;
+ const variable_if_dynamic<Index, (ArgType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol;
+ const variable_if_dynamic<Index, ForwardLinearAccess ? Dynamic : 0> m_linear_offset;
+};
+
+// TODO: This evaluator does not actually use the child evaluator;
+// all action is via the data() as returned by the Block expression.
+
+template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel>
+struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, /* HasDirectAccess */ true>
+ : mapbase_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>,
+ typename Block<ArgType, BlockRows, BlockCols, InnerPanel>::PlainObject>
+{
+ typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
+ typedef typename XprType::Scalar Scalar;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit block_evaluator(const XprType& block)
+ : mapbase_evaluator<XprType, typename XprType::PlainObject>(block)
+ {
+ // TODO: for the 3.3 release, this should be turned to an internal assertion, but let's keep it as is for the beta lifetime
+ eigen_assert(((internal::UIntPtr(block.data()) % EIGEN_PLAIN_ENUM_MAX(1,evaluator<XprType>::Alignment)) == 0) && "data is not aligned");
+ }
+};
+
+
+// -------------------- Select --------------------
+// NOTE shall we introduce a ternary_evaluator?
+
+// TODO enable vectorization for Select
+template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
+struct evaluator<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
+ : evaluator_base<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
+{
+ typedef Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> XprType;
+ enum {
+ CoeffReadCost = evaluator<ConditionMatrixType>::CoeffReadCost
+ + EIGEN_PLAIN_ENUM_MAX(evaluator<ThenMatrixType>::CoeffReadCost,
+ evaluator<ElseMatrixType>::CoeffReadCost),
+
+ Flags = (unsigned int)evaluator<ThenMatrixType>::Flags & evaluator<ElseMatrixType>::Flags & HereditaryBits,
+
+ Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ThenMatrixType>::Alignment, evaluator<ElseMatrixType>::Alignment)
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit evaluator(const XprType& select)
+ : m_conditionImpl(select.conditionMatrix()),
+ m_thenImpl(select.thenMatrix()),
+ m_elseImpl(select.elseMatrix())
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ if (m_conditionImpl.coeff(row, col))
+ return m_thenImpl.coeff(row, col);
+ else
+ return m_elseImpl.coeff(row, col);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ if (m_conditionImpl.coeff(index))
+ return m_thenImpl.coeff(index);
+ else
+ return m_elseImpl.coeff(index);
+ }
+
+protected:
+ evaluator<ConditionMatrixType> m_conditionImpl;
+ evaluator<ThenMatrixType> m_thenImpl;
+ evaluator<ElseMatrixType> m_elseImpl;
+};
+
+
+// -------------------- Replicate --------------------
+
+template<typename ArgType, int RowFactor, int ColFactor>
+struct unary_evaluator<Replicate<ArgType, RowFactor, ColFactor> >
+ : evaluator_base<Replicate<ArgType, RowFactor, ColFactor> >
+{
+ typedef Replicate<ArgType, RowFactor, ColFactor> XprType;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+ enum {
+ Factor = (RowFactor==Dynamic || ColFactor==Dynamic) ? Dynamic : RowFactor*ColFactor
+ };
+ typedef typename internal::nested_eval<ArgType,Factor>::type ArgTypeNested;
+ typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
+
+ enum {
+ CoeffReadCost = evaluator<ArgTypeNestedCleaned>::CoeffReadCost,
+ LinearAccessMask = XprType::IsVectorAtCompileTime ? LinearAccessBit : 0,
+ Flags = (evaluator<ArgTypeNestedCleaned>::Flags & (HereditaryBits|LinearAccessMask) & ~RowMajorBit) | (traits<XprType>::Flags & RowMajorBit),
+
+ Alignment = evaluator<ArgTypeNestedCleaned>::Alignment
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit unary_evaluator(const XprType& replicate)
+ : m_arg(replicate.nestedExpression()),
+ m_argImpl(m_arg),
+ m_rows(replicate.nestedExpression().rows()),
+ m_cols(replicate.nestedExpression().cols())
+ {}
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ // try to avoid using modulo; this is a pure optimization strategy
+ const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
+ : RowFactor==1 ? row
+ : row % m_rows.value();
+ const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
+ : ColFactor==1 ? col
+ : col % m_cols.value();
+
+ return m_argImpl.coeff(actual_row, actual_col);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ // try to avoid using modulo; this is a pure optimization strategy
+ const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
+ ? (ColFactor==1 ? index : index%m_cols.value())
+ : (RowFactor==1 ? index : index%m_rows.value());
+
+ return m_argImpl.coeff(actual_index);
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index row, Index col) const
+ {
+ const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
+ : RowFactor==1 ? row
+ : row % m_rows.value();
+ const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
+ : ColFactor==1 ? col
+ : col % m_cols.value();
+
+ return m_argImpl.template packet<LoadMode,PacketType>(actual_row, actual_col);
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index index) const
+ {
+ const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
+ ? (ColFactor==1 ? index : index%m_cols.value())
+ : (RowFactor==1 ? index : index%m_rows.value());
+
+ return m_argImpl.template packet<LoadMode,PacketType>(actual_index);
+ }
+
+protected:
+ const ArgTypeNested m_arg;
+ evaluator<ArgTypeNestedCleaned> m_argImpl;
+ const variable_if_dynamic<Index, ArgType::RowsAtCompileTime> m_rows;
+ const variable_if_dynamic<Index, ArgType::ColsAtCompileTime> m_cols;
+};
+
+// -------------------- MatrixWrapper and ArrayWrapper --------------------
+//
+// evaluator_wrapper_base<T> is a common base class for the
+// MatrixWrapper and ArrayWrapper evaluators.
+
+template<typename XprType>
+struct evaluator_wrapper_base
+ : evaluator_base<XprType>
+{
+ typedef typename remove_all<typename XprType::NestedExpressionType>::type ArgType;
+ enum {
+ CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
+ Flags = evaluator<ArgType>::Flags,
+ Alignment = evaluator<ArgType>::Alignment
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit evaluator_wrapper_base(const ArgType& arg) : m_argImpl(arg) {}
+
+ typedef typename ArgType::Scalar Scalar;
+ typedef typename ArgType::CoeffReturnType CoeffReturnType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ return m_argImpl.coeff(row, col);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ return m_argImpl.coeff(index);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index row, Index col)
+ {
+ return m_argImpl.coeffRef(row, col);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index index)
+ {
+ return m_argImpl.coeffRef(index);
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index row, Index col) const
+ {
+ return m_argImpl.template packet<LoadMode,PacketType>(row, col);
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index index) const
+ {
+ return m_argImpl.template packet<LoadMode,PacketType>(index);
+ }
+
+ template<int StoreMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index row, Index col, const PacketType& x)
+ {
+ m_argImpl.template writePacket<StoreMode>(row, col, x);
+ }
+
+ template<int StoreMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index index, const PacketType& x)
+ {
+ m_argImpl.template writePacket<StoreMode>(index, x);
+ }
+
+protected:
+ evaluator<ArgType> m_argImpl;
+};
+
+template<typename TArgType>
+struct unary_evaluator<MatrixWrapper<TArgType> >
+ : evaluator_wrapper_base<MatrixWrapper<TArgType> >
+{
+ typedef MatrixWrapper<TArgType> XprType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit unary_evaluator(const XprType& wrapper)
+ : evaluator_wrapper_base<MatrixWrapper<TArgType> >(wrapper.nestedExpression())
+ { }
+};
+
+template<typename TArgType>
+struct unary_evaluator<ArrayWrapper<TArgType> >
+ : evaluator_wrapper_base<ArrayWrapper<TArgType> >
+{
+ typedef ArrayWrapper<TArgType> XprType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit unary_evaluator(const XprType& wrapper)
+ : evaluator_wrapper_base<ArrayWrapper<TArgType> >(wrapper.nestedExpression())
+ { }
+};
+
+
+// -------------------- Reverse --------------------
+
+// defined in Reverse.h:
+template<typename PacketType, bool ReversePacket> struct reverse_packet_cond;
+
+template<typename ArgType, int Direction>
+struct unary_evaluator<Reverse<ArgType, Direction> >
+ : evaluator_base<Reverse<ArgType, Direction> >
+{
+ typedef Reverse<ArgType, Direction> XprType;
+ typedef typename XprType::Scalar Scalar;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ enum {
+ IsRowMajor = XprType::IsRowMajor,
+ IsColMajor = !IsRowMajor,
+ ReverseRow = (Direction == Vertical) || (Direction == BothDirections),
+ ReverseCol = (Direction == Horizontal) || (Direction == BothDirections),
+ ReversePacket = (Direction == BothDirections)
+ || ((Direction == Vertical) && IsColMajor)
+ || ((Direction == Horizontal) && IsRowMajor),
+
+ CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
+
+ // let's enable LinearAccess only with vectorization because of the product overhead
+ // FIXME enable DirectAccess with negative strides?
+ Flags0 = evaluator<ArgType>::Flags,
+ LinearAccess = ( (Direction==BothDirections) && (int(Flags0)&PacketAccessBit) )
+ || ((ReverseRow && XprType::ColsAtCompileTime==1) || (ReverseCol && XprType::RowsAtCompileTime==1))
+ ? LinearAccessBit : 0,
+
+ Flags = int(Flags0) & (HereditaryBits | PacketAccessBit | LinearAccess),
+
+ Alignment = 0 // FIXME in some rare cases, Alignment could be preserved, like a Vector4f.
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit unary_evaluator(const XprType& reverse)
+ : m_argImpl(reverse.nestedExpression()),
+ m_rows(ReverseRow ? reverse.nestedExpression().rows() : 1),
+ m_cols(ReverseCol ? reverse.nestedExpression().cols() : 1)
+ { }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ return m_argImpl.coeff(ReverseRow ? m_rows.value() - row - 1 : row,
+ ReverseCol ? m_cols.value() - col - 1 : col);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ return m_argImpl.coeff(m_rows.value() * m_cols.value() - index - 1);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index row, Index col)
+ {
+ return m_argImpl.coeffRef(ReverseRow ? m_rows.value() - row - 1 : row,
+ ReverseCol ? m_cols.value() - col - 1 : col);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index index)
+ {
+ return m_argImpl.coeffRef(m_rows.value() * m_cols.value() - index - 1);
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index row, Index col) const
+ {
+ enum {
+ PacketSize = unpacket_traits<PacketType>::size,
+ OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
+ OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
+ };
+ typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet;
+ return reverse_packet::run(m_argImpl.template packet<LoadMode,PacketType>(
+ ReverseRow ? m_rows.value() - row - OffsetRow : row,
+ ReverseCol ? m_cols.value() - col - OffsetCol : col));
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ PacketType packet(Index index) const
+ {
+ enum { PacketSize = unpacket_traits<PacketType>::size };
+ return preverse(m_argImpl.template packet<LoadMode,PacketType>(m_rows.value() * m_cols.value() - index - PacketSize));
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index row, Index col, const PacketType& x)
+ {
+ // FIXME we could factorize some code with packet(i,j)
+ enum {
+ PacketSize = unpacket_traits<PacketType>::size,
+ OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
+ OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
+ };
+ typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet;
+ m_argImpl.template writePacket<LoadMode>(
+ ReverseRow ? m_rows.value() - row - OffsetRow : row,
+ ReverseCol ? m_cols.value() - col - OffsetCol : col,
+ reverse_packet::run(x));
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE
+ void writePacket(Index index, const PacketType& x)
+ {
+ enum { PacketSize = unpacket_traits<PacketType>::size };
+ m_argImpl.template writePacket<LoadMode>
+ (m_rows.value() * m_cols.value() - index - PacketSize, preverse(x));
+ }
+
+protected:
+ evaluator<ArgType> m_argImpl;
+
+ // If we do not reverse rows, then we do not need to know the number of rows; same for columns
+ // Nonetheless, in this case it is important to set to 1 such that the coeff(index) method works fine for vectors.
+ const variable_if_dynamic<Index, ReverseRow ? ArgType::RowsAtCompileTime : 1> m_rows;
+ const variable_if_dynamic<Index, ReverseCol ? ArgType::ColsAtCompileTime : 1> m_cols;
+};
+
+
+// -------------------- Diagonal --------------------
+
+template<typename ArgType, int DiagIndex>
+struct evaluator<Diagonal<ArgType, DiagIndex> >
+ : evaluator_base<Diagonal<ArgType, DiagIndex> >
+{
+ typedef Diagonal<ArgType, DiagIndex> XprType;
+
+ enum {
+ CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
+
+ Flags = (unsigned int)(evaluator<ArgType>::Flags & (HereditaryBits | DirectAccessBit) & ~RowMajorBit) | LinearAccessBit,
+
+ Alignment = 0
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit evaluator(const XprType& diagonal)
+ : m_argImpl(diagonal.nestedExpression()),
+ m_index(diagonal.index())
+ { }
+
+ typedef typename XprType::Scalar Scalar;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index) const
+ {
+ return m_argImpl.coeff(row + rowOffset(), row + colOffset());
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index index) const
+ {
+ return m_argImpl.coeff(index + rowOffset(), index + colOffset());
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index row, Index)
+ {
+ return m_argImpl.coeffRef(row + rowOffset(), row + colOffset());
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index index)
+ {
+ return m_argImpl.coeffRef(index + rowOffset(), index + colOffset());
+ }
+
+protected:
+ evaluator<ArgType> m_argImpl;
+ const internal::variable_if_dynamicindex<Index, XprType::DiagIndex> m_index;
+
+private:
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index rowOffset() const { return m_index.value() > 0 ? 0 : -m_index.value(); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index colOffset() const { return m_index.value() > 0 ? m_index.value() : 0; }
+};
+
+
+//----------------------------------------------------------------------
+// deprecated code
+//----------------------------------------------------------------------
+
+// -------------------- EvalToTemp --------------------
+
+// expression class for evaluating nested expression to a temporary
+
+template<typename ArgType> class EvalToTemp;
+
+template<typename ArgType>
+struct traits<EvalToTemp<ArgType> >
+ : public traits<ArgType>
+{ };
+
+template<typename ArgType>
+class EvalToTemp
+ : public dense_xpr_base<EvalToTemp<ArgType> >::type
+{
+ public:
+
+ typedef typename dense_xpr_base<EvalToTemp>::type Base;
+ EIGEN_GENERIC_PUBLIC_INTERFACE(EvalToTemp)
+
+ explicit EvalToTemp(const ArgType& arg)
+ : m_arg(arg)
+ { }
+
+ const ArgType& arg() const
+ {
+ return m_arg;
+ }
+
+ EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
+ {
+ return m_arg.rows();
+ }
+
+ EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
+ {
+ return m_arg.cols();
+ }
+
+ private:
+ const ArgType& m_arg;
+};
+
+template<typename ArgType>
+struct evaluator<EvalToTemp<ArgType> >
+ : public evaluator<typename ArgType::PlainObject>
+{
+ typedef EvalToTemp<ArgType> XprType;
+ typedef typename ArgType::PlainObject PlainObject;
+ typedef evaluator<PlainObject> Base;
+
+ EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr)
+ : m_result(xpr.arg())
+ {
+ ::new (static_cast<Base*>(this)) Base(m_result);
+ }
+
+ // This constructor is used when nesting an EvalTo evaluator in another evaluator
+ EIGEN_DEVICE_FUNC evaluator(const ArgType& arg)
+ : m_result(arg)
+ {
+ ::new (static_cast<Base*>(this)) Base(m_result);
+ }
+
+protected:
+ PlainObject m_result;
+};
+
+} // namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_COREEVALUATORS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/CoreIterators.h b/src/3rdparty/eigen/Eigen/src/Core/CoreIterators.h
new file mode 100644
index 000000000..b96719681
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/CoreIterators.h
@@ -0,0 +1,132 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COREITERATORS_H
+#define EIGEN_COREITERATORS_H
+
+namespace Eigen {
+
+/* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core
+ */
+
+namespace internal {
+
+template<typename XprType, typename EvaluatorKind>
+class inner_iterator_selector;
+
+}
+
+/** \class InnerIterator
+ * \brief An InnerIterator allows to loop over the element of any matrix expression.
+ *
+ * \warning To be used with care because an evaluator is constructed every time an InnerIterator iterator is constructed.
+ *
+ * TODO: add a usage example
+ */
+template<typename XprType>
+class InnerIterator
+{
+protected:
+ typedef internal::inner_iterator_selector<XprType, typename internal::evaluator_traits<XprType>::Kind> IteratorType;
+ typedef internal::evaluator<XprType> EvaluatorType;
+ typedef typename internal::traits<XprType>::Scalar Scalar;
+public:
+ /** Construct an iterator over the \a outerId -th row or column of \a xpr */
+ InnerIterator(const XprType &xpr, const Index &outerId)
+ : m_eval(xpr), m_iter(m_eval, outerId, xpr.innerSize())
+ {}
+
+ /// \returns the value of the current coefficient.
+ EIGEN_STRONG_INLINE Scalar value() const { return m_iter.value(); }
+ /** Increment the iterator \c *this to the next non-zero coefficient.
+ * Explicit zeros are not skipped over. To skip explicit zeros, see class SparseView
+ */
+ EIGEN_STRONG_INLINE InnerIterator& operator++() { m_iter.operator++(); return *this; }
+ EIGEN_STRONG_INLINE InnerIterator& operator+=(Index i) { m_iter.operator+=(i); return *this; }
+ EIGEN_STRONG_INLINE InnerIterator operator+(Index i)
+ { InnerIterator result(*this); result+=i; return result; }
+
+
+ /// \returns the column or row index of the current coefficient.
+ EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); }
+ /// \returns the row index of the current coefficient.
+ EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); }
+ /// \returns the column index of the current coefficient.
+ EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); }
+ /// \returns \c true if the iterator \c *this still references a valid coefficient.
+ EIGEN_STRONG_INLINE operator bool() const { return m_iter; }
+
+protected:
+ EvaluatorType m_eval;
+ IteratorType m_iter;
+private:
+ // If you get here, then you're not using the right InnerIterator type, e.g.:
+ // SparseMatrix<double,RowMajor> A;
+ // SparseMatrix<double>::InnerIterator it(A,0);
+ template<typename T> InnerIterator(const EigenBase<T>&,Index outer);
+};
+
+namespace internal {
+
+// Generic inner iterator implementation for dense objects
+template<typename XprType>
+class inner_iterator_selector<XprType, IndexBased>
+{
+protected:
+ typedef evaluator<XprType> EvaluatorType;
+ typedef typename traits<XprType>::Scalar Scalar;
+ enum { IsRowMajor = (XprType::Flags&RowMajorBit)==RowMajorBit };
+
+public:
+ EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize)
+ : m_eval(eval), m_inner(0), m_outer(outerId), m_end(innerSize)
+ {}
+
+ EIGEN_STRONG_INLINE Scalar value() const
+ {
+ return (IsRowMajor) ? m_eval.coeff(m_outer, m_inner)
+ : m_eval.coeff(m_inner, m_outer);
+ }
+
+ EIGEN_STRONG_INLINE inner_iterator_selector& operator++() { m_inner++; return *this; }
+
+ EIGEN_STRONG_INLINE Index index() const { return m_inner; }
+ inline Index row() const { return IsRowMajor ? m_outer : index(); }
+ inline Index col() const { return IsRowMajor ? index() : m_outer; }
+
+ EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; }
+
+protected:
+ const EvaluatorType& m_eval;
+ Index m_inner;
+ const Index m_outer;
+ const Index m_end;
+};
+
+// For iterator-based evaluator, inner-iterator is already implemented as
+// evaluator<>::InnerIterator
+template<typename XprType>
+class inner_iterator_selector<XprType, IteratorBased>
+ : public evaluator<XprType>::InnerIterator
+{
+protected:
+ typedef typename evaluator<XprType>::InnerIterator Base;
+ typedef evaluator<XprType> EvaluatorType;
+
+public:
+ EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &/*innerSize*/)
+ : Base(eval, outerId)
+ {}
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_COREITERATORS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/CwiseBinaryOp.h b/src/3rdparty/eigen/Eigen/src/Core/CwiseBinaryOp.h
new file mode 100644
index 000000000..2202b1cc6
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/CwiseBinaryOp.h
@@ -0,0 +1,183 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_CWISE_BINARY_OP_H
+#define EIGEN_CWISE_BINARY_OP_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename BinaryOp, typename Lhs, typename Rhs>
+struct traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
+{
+ // we must not inherit from traits<Lhs> since it has
+ // the potential to cause problems with MSVC
+ typedef typename remove_all<Lhs>::type Ancestor;
+ typedef typename traits<Ancestor>::XprKind XprKind;
+ enum {
+ RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
+ ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
+ MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
+ };
+
+ // even though we require Lhs and Rhs to have the same scalar type (see CwiseBinaryOp constructor),
+ // we still want to handle the case when the result type is different.
+ typedef typename result_of<
+ BinaryOp(
+ const typename Lhs::Scalar&,
+ const typename Rhs::Scalar&
+ )
+ >::type Scalar;
+ typedef typename cwise_promote_storage_type<typename traits<Lhs>::StorageKind,
+ typename traits<Rhs>::StorageKind,
+ BinaryOp>::ret StorageKind;
+ typedef typename promote_index_type<typename traits<Lhs>::StorageIndex,
+ typename traits<Rhs>::StorageIndex>::type StorageIndex;
+ typedef typename Lhs::Nested LhsNested;
+ typedef typename Rhs::Nested RhsNested;
+ typedef typename remove_reference<LhsNested>::type _LhsNested;
+ typedef typename remove_reference<RhsNested>::type _RhsNested;
+ enum {
+ Flags = cwise_promote_storage_order<typename traits<Lhs>::StorageKind,typename traits<Rhs>::StorageKind,_LhsNested::Flags & RowMajorBit,_RhsNested::Flags & RowMajorBit>::value
+ };
+};
+} // end namespace internal
+
+template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
+class CwiseBinaryOpImpl;
+
+/** \class CwiseBinaryOp
+ * \ingroup Core_Module
+ *
+ * \brief Generic expression where a coefficient-wise binary operator is applied to two expressions
+ *
+ * \tparam BinaryOp template functor implementing the operator
+ * \tparam LhsType the type of the left-hand side
+ * \tparam RhsType the type of the right-hand side
+ *
+ * This class represents an expression where a coefficient-wise binary operator is applied to two expressions.
+ * It is the return type of binary operators, by which we mean only those binary operators where
+ * both the left-hand side and the right-hand side are Eigen expressions.
+ * For example, the return type of matrix1+matrix2 is a CwiseBinaryOp.
+ *
+ * Most of the time, this is the only way that it is used, so you typically don't have to name
+ * CwiseBinaryOp types explicitly.
+ *
+ * \sa MatrixBase::binaryExpr(const MatrixBase<OtherDerived> &,const CustomBinaryOp &) const, class CwiseUnaryOp, class CwiseNullaryOp
+ */
+template<typename BinaryOp, typename LhsType, typename RhsType>
+class CwiseBinaryOp :
+ public CwiseBinaryOpImpl<
+ BinaryOp, LhsType, RhsType,
+ typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
+ typename internal::traits<RhsType>::StorageKind,
+ BinaryOp>::ret>,
+ internal::no_assignment_operator
+{
+ public:
+
+ typedef typename internal::remove_all<BinaryOp>::type Functor;
+ typedef typename internal::remove_all<LhsType>::type Lhs;
+ typedef typename internal::remove_all<RhsType>::type Rhs;
+
+ typedef typename CwiseBinaryOpImpl<
+ BinaryOp, LhsType, RhsType,
+ typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
+ typename internal::traits<Rhs>::StorageKind,
+ BinaryOp>::ret>::Base Base;
+ EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp)
+
+ typedef typename internal::ref_selector<LhsType>::type LhsNested;
+ typedef typename internal::ref_selector<RhsType>::type RhsNested;
+ typedef typename internal::remove_reference<LhsNested>::type _LhsNested;
+ typedef typename internal::remove_reference<RhsNested>::type _RhsNested;
+
+#if EIGEN_COMP_MSVC && EIGEN_HAS_CXX11
+ //Required for Visual Studio or the Copy constructor will probably not get inlined!
+ EIGEN_STRONG_INLINE
+ CwiseBinaryOp(const CwiseBinaryOp<BinaryOp,LhsType,RhsType>&) = default;
+#endif
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CwiseBinaryOp(const Lhs& aLhs, const Rhs& aRhs, const BinaryOp& func = BinaryOp())
+ : m_lhs(aLhs), m_rhs(aRhs), m_functor(func)
+ {
+ EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename Rhs::Scalar);
+ // require the sizes to match
+ EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs)
+ eigen_assert(aLhs.rows() == aRhs.rows() && aLhs.cols() == aRhs.cols());
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index rows() const EIGEN_NOEXCEPT {
+ // return the fixed size type if available to enable compile time optimizations
+ return internal::traits<typename internal::remove_all<LhsNested>::type>::RowsAtCompileTime==Dynamic ? m_rhs.rows() : m_lhs.rows();
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index cols() const EIGEN_NOEXCEPT {
+ // return the fixed size type if available to enable compile time optimizations
+ return internal::traits<typename internal::remove_all<LhsNested>::type>::ColsAtCompileTime==Dynamic ? m_rhs.cols() : m_lhs.cols();
+ }
+
+ /** \returns the left hand side nested expression */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const _LhsNested& lhs() const { return m_lhs; }
+ /** \returns the right hand side nested expression */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const _RhsNested& rhs() const { return m_rhs; }
+ /** \returns the functor representing the binary operation */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const BinaryOp& functor() const { return m_functor; }
+
+ protected:
+ LhsNested m_lhs;
+ RhsNested m_rhs;
+ const BinaryOp m_functor;
+};
+
+// Generic API dispatcher
+template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
+class CwiseBinaryOpImpl
+ : public internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type
+{
+public:
+ typedef typename internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type Base;
+};
+
+/** replaces \c *this by \c *this - \a other.
+ *
+ * \returns a reference to \c *this
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
+MatrixBase<Derived>::operator-=(const MatrixBase<OtherDerived> &other)
+{
+ call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
+ return derived();
+}
+
+/** replaces \c *this by \c *this + \a other.
+ *
+ * \returns a reference to \c *this
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
+MatrixBase<Derived>::operator+=(const MatrixBase<OtherDerived>& other)
+{
+ call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
+ return derived();
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_CWISE_BINARY_OP_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/CwiseNullaryOp.h b/src/3rdparty/eigen/Eigen/src/Core/CwiseNullaryOp.h
new file mode 100644
index 000000000..289ec510a
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/CwiseNullaryOp.h
@@ -0,0 +1,1001 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_CWISE_NULLARY_OP_H
+#define EIGEN_CWISE_NULLARY_OP_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename NullaryOp, typename PlainObjectType>
+struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
+{
+ enum {
+ Flags = traits<PlainObjectType>::Flags & RowMajorBit
+ };
+};
+
+} // namespace internal
+
+/** \class CwiseNullaryOp
+ * \ingroup Core_Module
+ *
+ * \brief Generic expression of a matrix where all coefficients are defined by a functor
+ *
+ * \tparam NullaryOp template functor implementing the operator
+ * \tparam PlainObjectType the underlying plain matrix/array type
+ *
+ * This class represents an expression of a generic nullary operator.
+ * It is the return type of the Ones(), Zero(), Constant(), Identity() and Random() methods,
+ * and most of the time this is the only way it is used.
+ *
+ * However, if you want to write a function returning such an expression, you
+ * will need to use this class.
+ *
+ * The functor NullaryOp must expose one of the following method:
+ <table class="manual">
+ <tr ><td>\c operator()() </td><td>if the procedural generation does not depend on the coefficient entries (e.g., random numbers)</td></tr>
+ <tr class="alt"><td>\c operator()(Index i)</td><td>if the procedural generation makes sense for vectors only and that it depends on the coefficient index \c i (e.g., linspace) </td></tr>
+ <tr ><td>\c operator()(Index i,Index j)</td><td>if the procedural generation depends on the matrix coordinates \c i, \c j (e.g., to generate a checkerboard with 0 and 1)</td></tr>
+ </table>
+ * It is also possible to expose the last two operators if the generation makes sense for matrices but can be optimized for vectors.
+ *
+ * See DenseBase::NullaryExpr(Index,const CustomNullaryOp&) for an example binding
+ * C++11 random number generators.
+ *
+ * A nullary expression can also be used to implement custom sophisticated matrix manipulations
+ * that cannot be covered by the existing set of natively supported matrix manipulations.
+ * See this \ref TopicCustomizing_NullaryExpr "page" for some examples and additional explanations
+ * on the behavior of CwiseNullaryOp.
+ *
+ * \sa class CwiseUnaryOp, class CwiseBinaryOp, DenseBase::NullaryExpr
+ */
+template<typename NullaryOp, typename PlainObjectType>
+class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
+{
+ public:
+
+ typedef typename internal::dense_xpr_base<CwiseNullaryOp>::type Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(CwiseNullaryOp)
+
+ EIGEN_DEVICE_FUNC
+ CwiseNullaryOp(Index rows, Index cols, const NullaryOp& func = NullaryOp())
+ : m_rows(rows), m_cols(cols), m_functor(func)
+ {
+ eigen_assert(rows >= 0
+ && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
+ && cols >= 0
+ && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index rows() const { return m_rows.value(); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index cols() const { return m_cols.value(); }
+
+ /** \returns the functor representing the nullary operation */
+ EIGEN_DEVICE_FUNC
+ const NullaryOp& functor() const { return m_functor; }
+
+ protected:
+ const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
+ const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
+ const NullaryOp m_functor;
+};
+
+
+/** \returns an expression of a matrix defined by a custom functor \a func
+ *
+ * The parameters \a rows and \a cols are the number of rows and of columns of
+ * the returned matrix. Must be compatible with this MatrixBase type.
+ *
+ * This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
+ * it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used
+ * instead.
+ *
+ * The template parameter \a CustomNullaryOp is the type of the functor.
+ *
+ * \sa class CwiseNullaryOp
+ */
+template<typename Derived>
+template<typename CustomNullaryOp>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const CwiseNullaryOp<CustomNullaryOp,typename DenseBase<Derived>::PlainObject>
+#else
+const CwiseNullaryOp<CustomNullaryOp,PlainObject>
+#endif
+DenseBase<Derived>::NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func)
+{
+ return CwiseNullaryOp<CustomNullaryOp, PlainObject>(rows, cols, func);
+}
+
+/** \returns an expression of a matrix defined by a custom functor \a func
+ *
+ * The parameter \a size is the size of the returned vector.
+ * Must be compatible with this MatrixBase type.
+ *
+ * \only_for_vectors
+ *
+ * This variant is meant to be used for dynamic-size vector types. For fixed-size types,
+ * it is redundant to pass \a size as argument, so Zero() should be used
+ * instead.
+ *
+ * The template parameter \a CustomNullaryOp is the type of the functor.
+ *
+ * Here is an example with C++11 random generators: \include random_cpp11.cpp
+ * Output: \verbinclude random_cpp11.out
+ *
+ * \sa class CwiseNullaryOp
+ */
+template<typename Derived>
+template<typename CustomNullaryOp>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const CwiseNullaryOp<CustomNullaryOp, typename DenseBase<Derived>::PlainObject>
+#else
+const CwiseNullaryOp<CustomNullaryOp, PlainObject>
+#endif
+DenseBase<Derived>::NullaryExpr(Index size, const CustomNullaryOp& func)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ if(RowsAtCompileTime == 1) return CwiseNullaryOp<CustomNullaryOp, PlainObject>(1, size, func);
+ else return CwiseNullaryOp<CustomNullaryOp, PlainObject>(size, 1, func);
+}
+
+/** \returns an expression of a matrix defined by a custom functor \a func
+ *
+ * This variant is only for fixed-size DenseBase types. For dynamic-size types, you
+ * need to use the variants taking size arguments.
+ *
+ * The template parameter \a CustomNullaryOp is the type of the functor.
+ *
+ * \sa class CwiseNullaryOp
+ */
+template<typename Derived>
+template<typename CustomNullaryOp>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const CwiseNullaryOp<CustomNullaryOp, typename DenseBase<Derived>::PlainObject>
+#else
+const CwiseNullaryOp<CustomNullaryOp, PlainObject>
+#endif
+DenseBase<Derived>::NullaryExpr(const CustomNullaryOp& func)
+{
+ return CwiseNullaryOp<CustomNullaryOp, PlainObject>(RowsAtCompileTime, ColsAtCompileTime, func);
+}
+
+/** \returns an expression of a constant matrix of value \a value
+ *
+ * The parameters \a rows and \a cols are the number of rows and of columns of
+ * the returned matrix. Must be compatible with this DenseBase type.
+ *
+ * This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
+ * it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used
+ * instead.
+ *
+ * The template parameter \a CustomNullaryOp is the type of the functor.
+ *
+ * \sa class CwiseNullaryOp
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
+DenseBase<Derived>::Constant(Index rows, Index cols, const Scalar& value)
+{
+ return DenseBase<Derived>::NullaryExpr(rows, cols, internal::scalar_constant_op<Scalar>(value));
+}
+
+/** \returns an expression of a constant matrix of value \a value
+ *
+ * The parameter \a size is the size of the returned vector.
+ * Must be compatible with this DenseBase type.
+ *
+ * \only_for_vectors
+ *
+ * This variant is meant to be used for dynamic-size vector types. For fixed-size types,
+ * it is redundant to pass \a size as argument, so Zero() should be used
+ * instead.
+ *
+ * The template parameter \a CustomNullaryOp is the type of the functor.
+ *
+ * \sa class CwiseNullaryOp
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
+DenseBase<Derived>::Constant(Index size, const Scalar& value)
+{
+ return DenseBase<Derived>::NullaryExpr(size, internal::scalar_constant_op<Scalar>(value));
+}
+
+/** \returns an expression of a constant matrix of value \a value
+ *
+ * This variant is only for fixed-size DenseBase types. For dynamic-size types, you
+ * need to use the variants taking size arguments.
+ *
+ * The template parameter \a CustomNullaryOp is the type of the functor.
+ *
+ * \sa class CwiseNullaryOp
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
+DenseBase<Derived>::Constant(const Scalar& value)
+{
+ EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
+ return DenseBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_constant_op<Scalar>(value));
+}
+
+/** \deprecated because of accuracy loss. In Eigen 3.3, it is an alias for LinSpaced(Index,const Scalar&,const Scalar&)
+ *
+ * \only_for_vectors
+ *
+ * Example: \include DenseBase_LinSpaced_seq_deprecated.cpp
+ * Output: \verbinclude DenseBase_LinSpaced_seq_deprecated.out
+ *
+ * \sa LinSpaced(Index,const Scalar&, const Scalar&), setLinSpaced(Index,const Scalar&,const Scalar&)
+ */
+template<typename Derived>
+EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType
+DenseBase<Derived>::LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return DenseBase<Derived>::NullaryExpr(size, internal::linspaced_op<Scalar>(low,high,size));
+}
+
+/** \deprecated because of accuracy loss. In Eigen 3.3, it is an alias for LinSpaced(const Scalar&,const Scalar&)
+ *
+ * \sa LinSpaced(const Scalar&, const Scalar&)
+ */
+template<typename Derived>
+EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType
+DenseBase<Derived>::LinSpaced(Sequential_t, const Scalar& low, const Scalar& high)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
+ return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar>(low,high,Derived::SizeAtCompileTime));
+}
+
+/**
+ * \brief Sets a linearly spaced vector.
+ *
+ * The function generates 'size' equally spaced values in the closed interval [low,high].
+ * When size is set to 1, a vector of length 1 containing 'high' is returned.
+ *
+ * \only_for_vectors
+ *
+ * Example: \include DenseBase_LinSpaced.cpp
+ * Output: \verbinclude DenseBase_LinSpaced.out
+ *
+ * For integer scalar types, an even spacing is possible if and only if the length of the range,
+ * i.e., \c high-low is a scalar multiple of \c size-1, or if \c size is a scalar multiple of the
+ * number of values \c high-low+1 (meaning each value can be repeated the same number of time).
+ * If one of these two considions is not satisfied, then \c high is lowered to the largest value
+ * satisfying one of this constraint.
+ * Here are some examples:
+ *
+ * Example: \include DenseBase_LinSpacedInt.cpp
+ * Output: \verbinclude DenseBase_LinSpacedInt.out
+ *
+ * \sa setLinSpaced(Index,const Scalar&,const Scalar&), CwiseNullaryOp
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType
+DenseBase<Derived>::LinSpaced(Index size, const Scalar& low, const Scalar& high)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return DenseBase<Derived>::NullaryExpr(size, internal::linspaced_op<Scalar>(low,high,size));
+}
+
+/**
+ * \copydoc DenseBase::LinSpaced(Index, const Scalar&, const Scalar&)
+ * Special version for fixed size types which does not require the size parameter.
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType
+DenseBase<Derived>::LinSpaced(const Scalar& low, const Scalar& high)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
+ return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar>(low,high,Derived::SizeAtCompileTime));
+}
+
+/** \returns true if all coefficients in this matrix are approximately equal to \a val, to within precision \a prec */
+template<typename Derived>
+EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isApproxToConstant
+(const Scalar& val, const RealScalar& prec) const
+{
+ typename internal::nested_eval<Derived,1>::type self(derived());
+ for(Index j = 0; j < cols(); ++j)
+ for(Index i = 0; i < rows(); ++i)
+ if(!internal::isApprox(self.coeff(i, j), val, prec))
+ return false;
+ return true;
+}
+
+/** This is just an alias for isApproxToConstant().
+ *
+ * \returns true if all coefficients in this matrix are approximately equal to \a value, to within precision \a prec */
+template<typename Derived>
+EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isConstant
+(const Scalar& val, const RealScalar& prec) const
+{
+ return isApproxToConstant(val, prec);
+}
+
+/** Alias for setConstant(): sets all coefficients in this expression to \a val.
+ *
+ * \sa setConstant(), Constant(), class CwiseNullaryOp
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void DenseBase<Derived>::fill(const Scalar& val)
+{
+ setConstant(val);
+}
+
+/** Sets all coefficients in this expression to value \a val.
+ *
+ * \sa fill(), setConstant(Index,const Scalar&), setConstant(Index,Index,const Scalar&), setZero(), setOnes(), Constant(), class CwiseNullaryOp, setZero(), setOnes()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setConstant(const Scalar& val)
+{
+ return derived() = Constant(rows(), cols(), val);
+}
+
+/** Resizes to the given \a size, and sets all coefficients in this expression to the given value \a val.
+ *
+ * \only_for_vectors
+ *
+ * Example: \include Matrix_setConstant_int.cpp
+ * Output: \verbinclude Matrix_setConstant_int.out
+ *
+ * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setConstant(Index size, const Scalar& val)
+{
+ resize(size);
+ return setConstant(val);
+}
+
+/** Resizes to the given size, and sets all coefficients in this expression to the given value \a val.
+ *
+ * \param rows the new number of rows
+ * \param cols the new number of columns
+ * \param val the value to which all coefficients are set
+ *
+ * Example: \include Matrix_setConstant_int_int.cpp
+ * Output: \verbinclude Matrix_setConstant_int_int.out
+ *
+ * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setConstant(Index rows, Index cols, const Scalar& val)
+{
+ resize(rows, cols);
+ return setConstant(val);
+}
+
+/** Resizes to the given size, changing only the number of columns, and sets all
+ * coefficients in this expression to the given value \a val. For the parameter
+ * of type NoChange_t, just pass the special value \c NoChange.
+ *
+ * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setConstant(NoChange_t, Index cols, const Scalar& val)
+{
+ return setConstant(rows(), cols, val);
+}
+
+/** Resizes to the given size, changing only the number of rows, and sets all
+ * coefficients in this expression to the given value \a val. For the parameter
+ * of type NoChange_t, just pass the special value \c NoChange.
+ *
+ * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setConstant(Index rows, NoChange_t, const Scalar& val)
+{
+ return setConstant(rows, cols(), val);
+}
+
+
+/**
+ * \brief Sets a linearly spaced vector.
+ *
+ * The function generates 'size' equally spaced values in the closed interval [low,high].
+ * When size is set to 1, a vector of length 1 containing 'high' is returned.
+ *
+ * \only_for_vectors
+ *
+ * Example: \include DenseBase_setLinSpaced.cpp
+ * Output: \verbinclude DenseBase_setLinSpaced.out
+ *
+ * For integer scalar types, do not miss the explanations on the definition
+ * of \link LinSpaced(Index,const Scalar&,const Scalar&) even spacing \endlink.
+ *
+ * \sa LinSpaced(Index,const Scalar&,const Scalar&), CwiseNullaryOp
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setLinSpaced(Index newSize, const Scalar& low, const Scalar& high)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar>(low,high,newSize));
+}
+
+/**
+ * \brief Sets a linearly spaced vector.
+ *
+ * The function fills \c *this with equally spaced values in the closed interval [low,high].
+ * When size is set to 1, a vector of length 1 containing 'high' is returned.
+ *
+ * \only_for_vectors
+ *
+ * For integer scalar types, do not miss the explanations on the definition
+ * of \link LinSpaced(Index,const Scalar&,const Scalar&) even spacing \endlink.
+ *
+ * \sa LinSpaced(Index,const Scalar&,const Scalar&), setLinSpaced(Index, const Scalar&, const Scalar&), CwiseNullaryOp
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setLinSpaced(const Scalar& low, const Scalar& high)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return setLinSpaced(size(), low, high);
+}
+
+// zero:
+
+/** \returns an expression of a zero matrix.
+ *
+ * The parameters \a rows and \a cols are the number of rows and of columns of
+ * the returned matrix. Must be compatible with this MatrixBase type.
+ *
+ * This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
+ * it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used
+ * instead.
+ *
+ * Example: \include MatrixBase_zero_int_int.cpp
+ * Output: \verbinclude MatrixBase_zero_int_int.out
+ *
+ * \sa Zero(), Zero(Index)
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
+DenseBase<Derived>::Zero(Index rows, Index cols)
+{
+ return Constant(rows, cols, Scalar(0));
+}
+
+/** \returns an expression of a zero vector.
+ *
+ * The parameter \a size is the size of the returned vector.
+ * Must be compatible with this MatrixBase type.
+ *
+ * \only_for_vectors
+ *
+ * This variant is meant to be used for dynamic-size vector types. For fixed-size types,
+ * it is redundant to pass \a size as argument, so Zero() should be used
+ * instead.
+ *
+ * Example: \include MatrixBase_zero_int.cpp
+ * Output: \verbinclude MatrixBase_zero_int.out
+ *
+ * \sa Zero(), Zero(Index,Index)
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
+DenseBase<Derived>::Zero(Index size)
+{
+ return Constant(size, Scalar(0));
+}
+
+/** \returns an expression of a fixed-size zero matrix or vector.
+ *
+ * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you
+ * need to use the variants taking size arguments.
+ *
+ * Example: \include MatrixBase_zero.cpp
+ * Output: \verbinclude MatrixBase_zero.out
+ *
+ * \sa Zero(Index), Zero(Index,Index)
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
+DenseBase<Derived>::Zero()
+{
+ return Constant(Scalar(0));
+}
+
+/** \returns true if *this is approximately equal to the zero matrix,
+ * within the precision given by \a prec.
+ *
+ * Example: \include MatrixBase_isZero.cpp
+ * Output: \verbinclude MatrixBase_isZero.out
+ *
+ * \sa class CwiseNullaryOp, Zero()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isZero(const RealScalar& prec) const
+{
+ typename internal::nested_eval<Derived,1>::type self(derived());
+ for(Index j = 0; j < cols(); ++j)
+ for(Index i = 0; i < rows(); ++i)
+ if(!internal::isMuchSmallerThan(self.coeff(i, j), static_cast<Scalar>(1), prec))
+ return false;
+ return true;
+}
+
+/** Sets all coefficients in this expression to zero.
+ *
+ * Example: \include MatrixBase_setZero.cpp
+ * Output: \verbinclude MatrixBase_setZero.out
+ *
+ * \sa class CwiseNullaryOp, Zero()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setZero()
+{
+ return setConstant(Scalar(0));
+}
+
+/** Resizes to the given \a size, and sets all coefficients in this expression to zero.
+ *
+ * \only_for_vectors
+ *
+ * Example: \include Matrix_setZero_int.cpp
+ * Output: \verbinclude Matrix_setZero_int.out
+ *
+ * \sa DenseBase::setZero(), setZero(Index,Index), class CwiseNullaryOp, DenseBase::Zero()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setZero(Index newSize)
+{
+ resize(newSize);
+ return setConstant(Scalar(0));
+}
+
+/** Resizes to the given size, and sets all coefficients in this expression to zero.
+ *
+ * \param rows the new number of rows
+ * \param cols the new number of columns
+ *
+ * Example: \include Matrix_setZero_int_int.cpp
+ * Output: \verbinclude Matrix_setZero_int_int.out
+ *
+ * \sa DenseBase::setZero(), setZero(Index), class CwiseNullaryOp, DenseBase::Zero()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setZero(Index rows, Index cols)
+{
+ resize(rows, cols);
+ return setConstant(Scalar(0));
+}
+
+/** Resizes to the given size, changing only the number of columns, and sets all
+ * coefficients in this expression to zero. For the parameter of type NoChange_t,
+ * just pass the special value \c NoChange.
+ *
+ * \sa DenseBase::setZero(), setZero(Index), setZero(Index, Index), setZero(Index, NoChange_t), class CwiseNullaryOp, DenseBase::Zero()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setZero(NoChange_t, Index cols)
+{
+ return setZero(rows(), cols);
+}
+
+/** Resizes to the given size, changing only the number of rows, and sets all
+ * coefficients in this expression to zero. For the parameter of type NoChange_t,
+ * just pass the special value \c NoChange.
+ *
+ * \sa DenseBase::setZero(), setZero(Index), setZero(Index, Index), setZero(NoChange_t, Index), class CwiseNullaryOp, DenseBase::Zero()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setZero(Index rows, NoChange_t)
+{
+ return setZero(rows, cols());
+}
+
+// ones:
+
+/** \returns an expression of a matrix where all coefficients equal one.
+ *
+ * The parameters \a rows and \a cols are the number of rows and of columns of
+ * the returned matrix. Must be compatible with this MatrixBase type.
+ *
+ * This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
+ * it is redundant to pass \a rows and \a cols as arguments, so Ones() should be used
+ * instead.
+ *
+ * Example: \include MatrixBase_ones_int_int.cpp
+ * Output: \verbinclude MatrixBase_ones_int_int.out
+ *
+ * \sa Ones(), Ones(Index), isOnes(), class Ones
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
+DenseBase<Derived>::Ones(Index rows, Index cols)
+{
+ return Constant(rows, cols, Scalar(1));
+}
+
+/** \returns an expression of a vector where all coefficients equal one.
+ *
+ * The parameter \a newSize is the size of the returned vector.
+ * Must be compatible with this MatrixBase type.
+ *
+ * \only_for_vectors
+ *
+ * This variant is meant to be used for dynamic-size vector types. For fixed-size types,
+ * it is redundant to pass \a size as argument, so Ones() should be used
+ * instead.
+ *
+ * Example: \include MatrixBase_ones_int.cpp
+ * Output: \verbinclude MatrixBase_ones_int.out
+ *
+ * \sa Ones(), Ones(Index,Index), isOnes(), class Ones
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
+DenseBase<Derived>::Ones(Index newSize)
+{
+ return Constant(newSize, Scalar(1));
+}
+
+/** \returns an expression of a fixed-size matrix or vector where all coefficients equal one.
+ *
+ * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you
+ * need to use the variants taking size arguments.
+ *
+ * Example: \include MatrixBase_ones.cpp
+ * Output: \verbinclude MatrixBase_ones.out
+ *
+ * \sa Ones(Index), Ones(Index,Index), isOnes(), class Ones
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
+DenseBase<Derived>::Ones()
+{
+ return Constant(Scalar(1));
+}
+
+/** \returns true if *this is approximately equal to the matrix where all coefficients
+ * are equal to 1, within the precision given by \a prec.
+ *
+ * Example: \include MatrixBase_isOnes.cpp
+ * Output: \verbinclude MatrixBase_isOnes.out
+ *
+ * \sa class CwiseNullaryOp, Ones()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isOnes
+(const RealScalar& prec) const
+{
+ return isApproxToConstant(Scalar(1), prec);
+}
+
+/** Sets all coefficients in this expression to one.
+ *
+ * Example: \include MatrixBase_setOnes.cpp
+ * Output: \verbinclude MatrixBase_setOnes.out
+ *
+ * \sa class CwiseNullaryOp, Ones()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setOnes()
+{
+ return setConstant(Scalar(1));
+}
+
+/** Resizes to the given \a newSize, and sets all coefficients in this expression to one.
+ *
+ * \only_for_vectors
+ *
+ * Example: \include Matrix_setOnes_int.cpp
+ * Output: \verbinclude Matrix_setOnes_int.out
+ *
+ * \sa MatrixBase::setOnes(), setOnes(Index,Index), class CwiseNullaryOp, MatrixBase::Ones()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setOnes(Index newSize)
+{
+ resize(newSize);
+ return setConstant(Scalar(1));
+}
+
+/** Resizes to the given size, and sets all coefficients in this expression to one.
+ *
+ * \param rows the new number of rows
+ * \param cols the new number of columns
+ *
+ * Example: \include Matrix_setOnes_int_int.cpp
+ * Output: \verbinclude Matrix_setOnes_int_int.out
+ *
+ * \sa MatrixBase::setOnes(), setOnes(Index), class CwiseNullaryOp, MatrixBase::Ones()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setOnes(Index rows, Index cols)
+{
+ resize(rows, cols);
+ return setConstant(Scalar(1));
+}
+
+/** Resizes to the given size, changing only the number of rows, and sets all
+ * coefficients in this expression to one. For the parameter of type NoChange_t,
+ * just pass the special value \c NoChange.
+ *
+ * \sa MatrixBase::setOnes(), setOnes(Index), setOnes(Index, Index), setOnes(NoChange_t, Index), class CwiseNullaryOp, MatrixBase::Ones()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setOnes(Index rows, NoChange_t)
+{
+ return setOnes(rows, cols());
+}
+
+/** Resizes to the given size, changing only the number of columns, and sets all
+ * coefficients in this expression to one. For the parameter of type NoChange_t,
+ * just pass the special value \c NoChange.
+ *
+ * \sa MatrixBase::setOnes(), setOnes(Index), setOnes(Index, Index), setOnes(Index, NoChange_t) class CwiseNullaryOp, MatrixBase::Ones()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setOnes(NoChange_t, Index cols)
+{
+ return setOnes(rows(), cols);
+}
+
+// Identity:
+
+/** \returns an expression of the identity matrix (not necessarily square).
+ *
+ * The parameters \a rows and \a cols are the number of rows and of columns of
+ * the returned matrix. Must be compatible with this MatrixBase type.
+ *
+ * This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
+ * it is redundant to pass \a rows and \a cols as arguments, so Identity() should be used
+ * instead.
+ *
+ * Example: \include MatrixBase_identity_int_int.cpp
+ * Output: \verbinclude MatrixBase_identity_int_int.out
+ *
+ * \sa Identity(), setIdentity(), isIdentity()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::IdentityReturnType
+MatrixBase<Derived>::Identity(Index rows, Index cols)
+{
+ return DenseBase<Derived>::NullaryExpr(rows, cols, internal::scalar_identity_op<Scalar>());
+}
+
+/** \returns an expression of the identity matrix (not necessarily square).
+ *
+ * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you
+ * need to use the variant taking size arguments.
+ *
+ * Example: \include MatrixBase_identity.cpp
+ * Output: \verbinclude MatrixBase_identity.out
+ *
+ * \sa Identity(Index,Index), setIdentity(), isIdentity()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::IdentityReturnType
+MatrixBase<Derived>::Identity()
+{
+ EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
+ return MatrixBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_identity_op<Scalar>());
+}
+
+/** \returns true if *this is approximately equal to the identity matrix
+ * (not necessarily square),
+ * within the precision given by \a prec.
+ *
+ * Example: \include MatrixBase_isIdentity.cpp
+ * Output: \verbinclude MatrixBase_isIdentity.out
+ *
+ * \sa class CwiseNullaryOp, Identity(), Identity(Index,Index), setIdentity()
+ */
+template<typename Derived>
+bool MatrixBase<Derived>::isIdentity
+(const RealScalar& prec) const
+{
+ typename internal::nested_eval<Derived,1>::type self(derived());
+ for(Index j = 0; j < cols(); ++j)
+ {
+ for(Index i = 0; i < rows(); ++i)
+ {
+ if(i == j)
+ {
+ if(!internal::isApprox(self.coeff(i, j), static_cast<Scalar>(1), prec))
+ return false;
+ }
+ else
+ {
+ if(!internal::isMuchSmallerThan(self.coeff(i, j), static_cast<RealScalar>(1), prec))
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+namespace internal {
+
+template<typename Derived, bool Big = (Derived::SizeAtCompileTime>=16)>
+struct setIdentity_impl
+{
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE Derived& run(Derived& m)
+ {
+ return m = Derived::Identity(m.rows(), m.cols());
+ }
+};
+
+template<typename Derived>
+struct setIdentity_impl<Derived, true>
+{
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE Derived& run(Derived& m)
+ {
+ m.setZero();
+ const Index size = numext::mini(m.rows(), m.cols());
+ for(Index i = 0; i < size; ++i) m.coeffRef(i,i) = typename Derived::Scalar(1);
+ return m;
+ }
+};
+
+} // end namespace internal
+
+/** Writes the identity expression (not necessarily square) into *this.
+ *
+ * Example: \include MatrixBase_setIdentity.cpp
+ * Output: \verbinclude MatrixBase_setIdentity.out
+ *
+ * \sa class CwiseNullaryOp, Identity(), Identity(Index,Index), isIdentity()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setIdentity()
+{
+ return internal::setIdentity_impl<Derived>::run(derived());
+}
+
+/** \brief Resizes to the given size, and writes the identity expression (not necessarily square) into *this.
+ *
+ * \param rows the new number of rows
+ * \param cols the new number of columns
+ *
+ * Example: \include Matrix_setIdentity_int_int.cpp
+ * Output: \verbinclude Matrix_setIdentity_int_int.out
+ *
+ * \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Identity()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setIdentity(Index rows, Index cols)
+{
+ derived().resize(rows, cols);
+ return setIdentity();
+}
+
+/** \returns an expression of the i-th unit (basis) vector.
+ *
+ * \only_for_vectors
+ *
+ * \sa MatrixBase::Unit(Index), MatrixBase::UnitX(), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::Unit(Index newSize, Index i)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
+}
+
+/** \returns an expression of the i-th unit (basis) vector.
+ *
+ * \only_for_vectors
+ *
+ * This variant is for fixed-size vector only.
+ *
+ * \sa MatrixBase::Unit(Index,Index), MatrixBase::UnitX(), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::Unit(Index i)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return BasisReturnType(SquareMatrixType::Identity(),i);
+}
+
+/** \returns an expression of the X axis unit vector (1{,0}^*)
+ *
+ * \only_for_vectors
+ *
+ * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitX()
+{ return Derived::Unit(0); }
+
+/** \returns an expression of the Y axis unit vector (0,1{,0}^*)
+ *
+ * \only_for_vectors
+ *
+ * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitY()
+{ return Derived::Unit(1); }
+
+/** \returns an expression of the Z axis unit vector (0,0,1{,0}^*)
+ *
+ * \only_for_vectors
+ *
+ * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitZ()
+{ return Derived::Unit(2); }
+
+/** \returns an expression of the W axis unit vector (0,0,0,1)
+ *
+ * \only_for_vectors
+ *
+ * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitW()
+{ return Derived::Unit(3); }
+
+/** \brief Set the coefficients of \c *this to the i-th unit (basis) vector
+ *
+ * \param i index of the unique coefficient to be set to 1
+ *
+ * \only_for_vectors
+ *
+ * \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Unit(Index,Index)
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setUnit(Index i)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
+ eigen_assert(i<size());
+ derived().setZero();
+ derived().coeffRef(i) = Scalar(1);
+ return derived();
+}
+
+/** \brief Resizes to the given \a newSize, and writes the i-th unit (basis) vector into *this.
+ *
+ * \param newSize the new size of the vector
+ * \param i index of the unique coefficient to be set to 1
+ *
+ * \only_for_vectors
+ *
+ * \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Unit(Index,Index)
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setUnit(Index newSize, Index i)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
+ eigen_assert(i<newSize);
+ derived().resize(newSize);
+ return setUnit(i);
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_CWISE_NULLARY_OP_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/CwiseTernaryOp.h b/src/3rdparty/eigen/Eigen/src/Core/CwiseTernaryOp.h
new file mode 100644
index 000000000..9f3576fec
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/CwiseTernaryOp.h
@@ -0,0 +1,197 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_CWISE_TERNARY_OP_H
+#define EIGEN_CWISE_TERNARY_OP_H
+
+namespace Eigen {
+
+namespace internal {
+template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3>
+struct traits<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> > {
+ // we must not inherit from traits<Arg1> since it has
+ // the potential to cause problems with MSVC
+ typedef typename remove_all<Arg1>::type Ancestor;
+ typedef typename traits<Ancestor>::XprKind XprKind;
+ enum {
+ RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
+ ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
+ MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
+ };
+
+ // even though we require Arg1, Arg2, and Arg3 to have the same scalar type
+ // (see CwiseTernaryOp constructor),
+ // we still want to handle the case when the result type is different.
+ typedef typename result_of<TernaryOp(
+ const typename Arg1::Scalar&, const typename Arg2::Scalar&,
+ const typename Arg3::Scalar&)>::type Scalar;
+
+ typedef typename internal::traits<Arg1>::StorageKind StorageKind;
+ typedef typename internal::traits<Arg1>::StorageIndex StorageIndex;
+
+ typedef typename Arg1::Nested Arg1Nested;
+ typedef typename Arg2::Nested Arg2Nested;
+ typedef typename Arg3::Nested Arg3Nested;
+ typedef typename remove_reference<Arg1Nested>::type _Arg1Nested;
+ typedef typename remove_reference<Arg2Nested>::type _Arg2Nested;
+ typedef typename remove_reference<Arg3Nested>::type _Arg3Nested;
+ enum { Flags = _Arg1Nested::Flags & RowMajorBit };
+};
+} // end namespace internal
+
+template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3,
+ typename StorageKind>
+class CwiseTernaryOpImpl;
+
+/** \class CwiseTernaryOp
+ * \ingroup Core_Module
+ *
+ * \brief Generic expression where a coefficient-wise ternary operator is
+ * applied to two expressions
+ *
+ * \tparam TernaryOp template functor implementing the operator
+ * \tparam Arg1Type the type of the first argument
+ * \tparam Arg2Type the type of the second argument
+ * \tparam Arg3Type the type of the third argument
+ *
+ * This class represents an expression where a coefficient-wise ternary
+ * operator is applied to three expressions.
+ * It is the return type of ternary operators, by which we mean only those
+ * ternary operators where
+ * all three arguments are Eigen expressions.
+ * For example, the return type of betainc(matrix1, matrix2, matrix3) is a
+ * CwiseTernaryOp.
+ *
+ * Most of the time, this is the only way that it is used, so you typically
+ * don't have to name
+ * CwiseTernaryOp types explicitly.
+ *
+ * \sa MatrixBase::ternaryExpr(const MatrixBase<Argument2> &, const
+ * MatrixBase<Argument3> &, const CustomTernaryOp &) const, class CwiseBinaryOp,
+ * class CwiseUnaryOp, class CwiseNullaryOp
+ */
+template <typename TernaryOp, typename Arg1Type, typename Arg2Type,
+ typename Arg3Type>
+class CwiseTernaryOp : public CwiseTernaryOpImpl<
+ TernaryOp, Arg1Type, Arg2Type, Arg3Type,
+ typename internal::traits<Arg1Type>::StorageKind>,
+ internal::no_assignment_operator
+{
+ public:
+ typedef typename internal::remove_all<Arg1Type>::type Arg1;
+ typedef typename internal::remove_all<Arg2Type>::type Arg2;
+ typedef typename internal::remove_all<Arg3Type>::type Arg3;
+
+ typedef typename CwiseTernaryOpImpl<
+ TernaryOp, Arg1Type, Arg2Type, Arg3Type,
+ typename internal::traits<Arg1Type>::StorageKind>::Base Base;
+ EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseTernaryOp)
+
+ typedef typename internal::ref_selector<Arg1Type>::type Arg1Nested;
+ typedef typename internal::ref_selector<Arg2Type>::type Arg2Nested;
+ typedef typename internal::ref_selector<Arg3Type>::type Arg3Nested;
+ typedef typename internal::remove_reference<Arg1Nested>::type _Arg1Nested;
+ typedef typename internal::remove_reference<Arg2Nested>::type _Arg2Nested;
+ typedef typename internal::remove_reference<Arg3Nested>::type _Arg3Nested;
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE CwiseTernaryOp(const Arg1& a1, const Arg2& a2,
+ const Arg3& a3,
+ const TernaryOp& func = TernaryOp())
+ : m_arg1(a1), m_arg2(a2), m_arg3(a3), m_functor(func) {
+ // require the sizes to match
+ EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Arg1, Arg2)
+ EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Arg1, Arg3)
+
+ // The index types should match
+ EIGEN_STATIC_ASSERT((internal::is_same<
+ typename internal::traits<Arg1Type>::StorageKind,
+ typename internal::traits<Arg2Type>::StorageKind>::value),
+ STORAGE_KIND_MUST_MATCH)
+ EIGEN_STATIC_ASSERT((internal::is_same<
+ typename internal::traits<Arg1Type>::StorageKind,
+ typename internal::traits<Arg3Type>::StorageKind>::value),
+ STORAGE_KIND_MUST_MATCH)
+
+ eigen_assert(a1.rows() == a2.rows() && a1.cols() == a2.cols() &&
+ a1.rows() == a3.rows() && a1.cols() == a3.cols());
+ }
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Index rows() const {
+ // return the fixed size type if available to enable compile time
+ // optimizations
+ if (internal::traits<typename internal::remove_all<Arg1Nested>::type>::
+ RowsAtCompileTime == Dynamic &&
+ internal::traits<typename internal::remove_all<Arg2Nested>::type>::
+ RowsAtCompileTime == Dynamic)
+ return m_arg3.rows();
+ else if (internal::traits<typename internal::remove_all<Arg1Nested>::type>::
+ RowsAtCompileTime == Dynamic &&
+ internal::traits<typename internal::remove_all<Arg3Nested>::type>::
+ RowsAtCompileTime == Dynamic)
+ return m_arg2.rows();
+ else
+ return m_arg1.rows();
+ }
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Index cols() const {
+ // return the fixed size type if available to enable compile time
+ // optimizations
+ if (internal::traits<typename internal::remove_all<Arg1Nested>::type>::
+ ColsAtCompileTime == Dynamic &&
+ internal::traits<typename internal::remove_all<Arg2Nested>::type>::
+ ColsAtCompileTime == Dynamic)
+ return m_arg3.cols();
+ else if (internal::traits<typename internal::remove_all<Arg1Nested>::type>::
+ ColsAtCompileTime == Dynamic &&
+ internal::traits<typename internal::remove_all<Arg3Nested>::type>::
+ ColsAtCompileTime == Dynamic)
+ return m_arg2.cols();
+ else
+ return m_arg1.cols();
+ }
+
+ /** \returns the first argument nested expression */
+ EIGEN_DEVICE_FUNC
+ const _Arg1Nested& arg1() const { return m_arg1; }
+ /** \returns the first argument nested expression */
+ EIGEN_DEVICE_FUNC
+ const _Arg2Nested& arg2() const { return m_arg2; }
+ /** \returns the third argument nested expression */
+ EIGEN_DEVICE_FUNC
+ const _Arg3Nested& arg3() const { return m_arg3; }
+ /** \returns the functor representing the ternary operation */
+ EIGEN_DEVICE_FUNC
+ const TernaryOp& functor() const { return m_functor; }
+
+ protected:
+ Arg1Nested m_arg1;
+ Arg2Nested m_arg2;
+ Arg3Nested m_arg3;
+ const TernaryOp m_functor;
+};
+
+// Generic API dispatcher
+template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3,
+ typename StorageKind>
+class CwiseTernaryOpImpl
+ : public internal::generic_xpr_base<
+ CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >::type {
+ public:
+ typedef typename internal::generic_xpr_base<
+ CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >::type Base;
+};
+
+} // end namespace Eigen
+
+#endif // EIGEN_CWISE_TERNARY_OP_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/CwiseUnaryOp.h b/src/3rdparty/eigen/Eigen/src/Core/CwiseUnaryOp.h
new file mode 100644
index 000000000..e68c4f748
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/CwiseUnaryOp.h
@@ -0,0 +1,103 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_CWISE_UNARY_OP_H
+#define EIGEN_CWISE_UNARY_OP_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename UnaryOp, typename XprType>
+struct traits<CwiseUnaryOp<UnaryOp, XprType> >
+ : traits<XprType>
+{
+ typedef typename result_of<
+ UnaryOp(const typename XprType::Scalar&)
+ >::type Scalar;
+ typedef typename XprType::Nested XprTypeNested;
+ typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
+ enum {
+ Flags = _XprTypeNested::Flags & RowMajorBit
+ };
+};
+}
+
+template<typename UnaryOp, typename XprType, typename StorageKind>
+class CwiseUnaryOpImpl;
+
+/** \class CwiseUnaryOp
+ * \ingroup Core_Module
+ *
+ * \brief Generic expression where a coefficient-wise unary operator is applied to an expression
+ *
+ * \tparam UnaryOp template functor implementing the operator
+ * \tparam XprType the type of the expression to which we are applying the unary operator
+ *
+ * This class represents an expression where a unary operator is applied to an expression.
+ * It is the return type of all operations taking exactly 1 input expression, regardless of the
+ * presence of other inputs such as scalars. For example, the operator* in the expression 3*matrix
+ * is considered unary, because only the right-hand side is an expression, and its
+ * return type is a specialization of CwiseUnaryOp.
+ *
+ * Most of the time, this is the only way that it is used, so you typically don't have to name
+ * CwiseUnaryOp types explicitly.
+ *
+ * \sa MatrixBase::unaryExpr(const CustomUnaryOp &) const, class CwiseBinaryOp, class CwiseNullaryOp
+ */
+template<typename UnaryOp, typename XprType>
+class CwiseUnaryOp : public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>, internal::no_assignment_operator
+{
+ public:
+
+ typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename internal::traits<XprType>::StorageKind>::Base Base;
+ EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
+ typedef typename internal::ref_selector<XprType>::type XprTypeNested;
+ typedef typename internal::remove_all<XprType>::type NestedExpression;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
+ : m_xpr(xpr), m_functor(func) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index rows() const EIGEN_NOEXCEPT { return m_xpr.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index cols() const EIGEN_NOEXCEPT { return m_xpr.cols(); }
+
+ /** \returns the functor representing the unary operation */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const UnaryOp& functor() const { return m_functor; }
+
+ /** \returns the nested expression */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const typename internal::remove_all<XprTypeNested>::type&
+ nestedExpression() const { return m_xpr; }
+
+ /** \returns the nested expression */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ typename internal::remove_all<XprTypeNested>::type&
+ nestedExpression() { return m_xpr; }
+
+ protected:
+ XprTypeNested m_xpr;
+ const UnaryOp m_functor;
+};
+
+// Generic API dispatcher
+template<typename UnaryOp, typename XprType, typename StorageKind>
+class CwiseUnaryOpImpl
+ : public internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type
+{
+public:
+ typedef typename internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base;
+};
+
+} // end namespace Eigen
+
+#endif // EIGEN_CWISE_UNARY_OP_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/CwiseUnaryView.h b/src/3rdparty/eigen/Eigen/src/Core/CwiseUnaryView.h
new file mode 100644
index 000000000..a06d7621e
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/CwiseUnaryView.h
@@ -0,0 +1,132 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_CWISE_UNARY_VIEW_H
+#define EIGEN_CWISE_UNARY_VIEW_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename ViewOp, typename MatrixType>
+struct traits<CwiseUnaryView<ViewOp, MatrixType> >
+ : traits<MatrixType>
+{
+ typedef typename result_of<
+ ViewOp(const typename traits<MatrixType>::Scalar&)
+ >::type Scalar;
+ typedef typename MatrixType::Nested MatrixTypeNested;
+ typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
+ enum {
+ FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
+ Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions
+ MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret,
+ // need to cast the sizeof's from size_t to int explicitly, otherwise:
+ // "error: no integral type can represent all of the enumerator values
+ InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
+ ? int(Dynamic)
+ : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
+ OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic
+ ? int(Dynamic)
+ : outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar))
+ };
+};
+}
+
+template<typename ViewOp, typename MatrixType, typename StorageKind>
+class CwiseUnaryViewImpl;
+
+/** \class CwiseUnaryView
+ * \ingroup Core_Module
+ *
+ * \brief Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector
+ *
+ * \tparam ViewOp template functor implementing the view
+ * \tparam MatrixType the type of the matrix we are applying the unary operator
+ *
+ * This class represents a lvalue expression of a generic unary view operator of a matrix or a vector.
+ * It is the return type of real() and imag(), and most of the time this is the only way it is used.
+ *
+ * \sa MatrixBase::unaryViewExpr(const CustomUnaryOp &) const, class CwiseUnaryOp
+ */
+template<typename ViewOp, typename MatrixType>
+class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
+{
+ public:
+
+ typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
+ EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
+ typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested;
+ typedef typename internal::remove_all<MatrixType>::type NestedExpression;
+
+ explicit EIGEN_DEVICE_FUNC inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp())
+ : m_matrix(mat), m_functor(func) {}
+
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
+
+ /** \returns the functor representing unary operation */
+ EIGEN_DEVICE_FUNC const ViewOp& functor() const { return m_functor; }
+
+ /** \returns the nested expression */
+ EIGEN_DEVICE_FUNC const typename internal::remove_all<MatrixTypeNested>::type&
+ nestedExpression() const { return m_matrix; }
+
+ /** \returns the nested expression */
+ EIGEN_DEVICE_FUNC typename internal::remove_reference<MatrixTypeNested>::type&
+ nestedExpression() { return m_matrix; }
+
+ protected:
+ MatrixTypeNested m_matrix;
+ ViewOp m_functor;
+};
+
+// Generic API dispatcher
+template<typename ViewOp, typename XprType, typename StorageKind>
+class CwiseUnaryViewImpl
+ : public internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type
+{
+public:
+ typedef typename internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type Base;
+};
+
+template<typename ViewOp, typename MatrixType>
+class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
+ : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
+{
+ public:
+
+ typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
+ typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base;
+
+ EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
+
+ EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); }
+ EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeff(0)); }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const
+ {
+ return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const
+ {
+ return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
+ }
+ protected:
+ EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
+};
+
+} // end namespace Eigen
+
+#endif // EIGEN_CWISE_UNARY_VIEW_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/DenseBase.h b/src/3rdparty/eigen/Eigen/src/Core/DenseBase.h
new file mode 100644
index 000000000..9b16db68d
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/DenseBase.h
@@ -0,0 +1,701 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_DENSEBASE_H
+#define EIGEN_DENSEBASE_H
+
+namespace Eigen {
+
+namespace internal {
+
+// The index type defined by EIGEN_DEFAULT_DENSE_INDEX_TYPE must be a signed type.
+// This dummy function simply aims at checking that at compile time.
+static inline void check_DenseIndex_is_signed() {
+ EIGEN_STATIC_ASSERT(NumTraits<DenseIndex>::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE)
+}
+
+} // end namespace internal
+
+/** \class DenseBase
+ * \ingroup Core_Module
+ *
+ * \brief Base class for all dense matrices, vectors, and arrays
+ *
+ * This class is the base that is inherited by all dense objects (matrix, vector, arrays,
+ * and related expression types). The common Eigen API for dense objects is contained in this class.
+ *
+ * \tparam Derived is the derived type, e.g., a matrix type or an expression.
+ *
+ * This class can be extended with the help of the plugin mechanism described on the page
+ * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_DENSEBASE_PLUGIN.
+ *
+ * \sa \blank \ref TopicClassHierarchy
+ */
+template<typename Derived> class DenseBase
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ : public DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value>
+#else
+ : public DenseCoeffsBase<Derived,DirectWriteAccessors>
+#endif // not EIGEN_PARSED_BY_DOXYGEN
+{
+ public:
+
+ /** Inner iterator type to iterate over the coefficients of a row or column.
+ * \sa class InnerIterator
+ */
+ typedef Eigen::InnerIterator<Derived> InnerIterator;
+
+ typedef typename internal::traits<Derived>::StorageKind StorageKind;
+
+ /**
+ * \brief The type used to store indices
+ * \details This typedef is relevant for types that store multiple indices such as
+ * PermutationMatrix or Transpositions, otherwise it defaults to Eigen::Index
+ * \sa \blank \ref TopicPreprocessorDirectives, Eigen::Index, SparseMatrixBase.
+ */
+ typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
+
+ /** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex<float>, etc. */
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+
+ /** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex<float>, etc.
+ *
+ * It is an alias for the Scalar type */
+ typedef Scalar value_type;
+
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value> Base;
+
+ using Base::derived;
+ using Base::const_cast_derived;
+ using Base::rows;
+ using Base::cols;
+ using Base::size;
+ using Base::rowIndexByOuterInner;
+ using Base::colIndexByOuterInner;
+ using Base::coeff;
+ using Base::coeffByOuterInner;
+ using Base::operator();
+ using Base::operator[];
+ using Base::x;
+ using Base::y;
+ using Base::z;
+ using Base::w;
+ using Base::stride;
+ using Base::innerStride;
+ using Base::outerStride;
+ using Base::rowStride;
+ using Base::colStride;
+ typedef typename Base::CoeffReturnType CoeffReturnType;
+
+ enum {
+
+ RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
+ /**< The number of rows at compile-time. This is just a copy of the value provided
+ * by the \a Derived type. If a value is not known at compile-time,
+ * it is set to the \a Dynamic constant.
+ * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */
+
+ ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
+ /**< The number of columns at compile-time. This is just a copy of the value provided
+ * by the \a Derived type. If a value is not known at compile-time,
+ * it is set to the \a Dynamic constant.
+ * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */
+
+
+ SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
+ internal::traits<Derived>::ColsAtCompileTime>::ret),
+ /**< This is equal to the number of coefficients, i.e. the number of
+ * rows times the number of columns, or to \a Dynamic if this is not
+ * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */
+
+ MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
+ /**< This value is equal to the maximum possible number of rows that this expression
+ * might have. If this expression might have an arbitrarily high number of rows,
+ * this value is set to \a Dynamic.
+ *
+ * This value is useful to know when evaluating an expression, in order to determine
+ * whether it is possible to avoid doing a dynamic memory allocation.
+ *
+ * \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime
+ */
+
+ MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
+ /**< This value is equal to the maximum possible number of columns that this expression
+ * might have. If this expression might have an arbitrarily high number of columns,
+ * this value is set to \a Dynamic.
+ *
+ * This value is useful to know when evaluating an expression, in order to determine
+ * whether it is possible to avoid doing a dynamic memory allocation.
+ *
+ * \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime
+ */
+
+ MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
+ internal::traits<Derived>::MaxColsAtCompileTime>::ret),
+ /**< This value is equal to the maximum possible number of coefficients that this expression
+ * might have. If this expression might have an arbitrarily high number of coefficients,
+ * this value is set to \a Dynamic.
+ *
+ * This value is useful to know when evaluating an expression, in order to determine
+ * whether it is possible to avoid doing a dynamic memory allocation.
+ *
+ * \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime
+ */
+
+ IsVectorAtCompileTime = internal::traits<Derived>::RowsAtCompileTime == 1
+ || internal::traits<Derived>::ColsAtCompileTime == 1,
+ /**< This is set to true if either the number of rows or the number of
+ * columns is known at compile-time to be equal to 1. Indeed, in that case,
+ * we are dealing with a column-vector (if there is only one column) or with
+ * a row-vector (if there is only one row). */
+
+ NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2,
+ /**< This value is equal to Tensor::NumDimensions, i.e. 0 for scalars, 1 for vectors,
+ * and 2 for matrices.
+ */
+
+ Flags = internal::traits<Derived>::Flags,
+ /**< This stores expression \ref flags flags which may or may not be inherited by new expressions
+ * constructed from this one. See the \ref flags "list of flags".
+ */
+
+ IsRowMajor = int(Flags) & RowMajorBit, /**< True if this expression has row-major storage order. */
+
+ InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime)
+ : int(IsRowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
+
+ InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::ret,
+ OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::ret
+ };
+
+ typedef typename internal::find_best_packet<Scalar,SizeAtCompileTime>::type PacketScalar;
+
+ enum { IsPlainObjectBase = 0 };
+
+ /** The plain matrix type corresponding to this expression.
+ * \sa PlainObject */
+ typedef Matrix<typename internal::traits<Derived>::Scalar,
+ internal::traits<Derived>::RowsAtCompileTime,
+ internal::traits<Derived>::ColsAtCompileTime,
+ AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
+ internal::traits<Derived>::MaxRowsAtCompileTime,
+ internal::traits<Derived>::MaxColsAtCompileTime
+ > PlainMatrix;
+
+ /** The plain array type corresponding to this expression.
+ * \sa PlainObject */
+ typedef Array<typename internal::traits<Derived>::Scalar,
+ internal::traits<Derived>::RowsAtCompileTime,
+ internal::traits<Derived>::ColsAtCompileTime,
+ AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
+ internal::traits<Derived>::MaxRowsAtCompileTime,
+ internal::traits<Derived>::MaxColsAtCompileTime
+ > PlainArray;
+
+ /** \brief The plain matrix or array type corresponding to this expression.
+ *
+ * This is not necessarily exactly the return type of eval(). In the case of plain matrices,
+ * the return type of eval() is a const reference to a matrix, not a matrix! It is however guaranteed
+ * that the return type of eval() is either PlainObject or const PlainObject&.
+ */
+ typedef typename internal::conditional<internal::is_same<typename internal::traits<Derived>::XprKind,MatrixXpr >::value,
+ PlainMatrix, PlainArray>::type PlainObject;
+
+ /** \returns the number of nonzero coefficients which is in practice the number
+ * of stored coefficients. */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index nonZeros() const { return size(); }
+
+ /** \returns the outer size.
+ *
+ * \note For a vector, this returns just 1. For a matrix (non-vector), this is the major dimension
+ * with respect to the \ref TopicStorageOrders "storage order", i.e., the number of columns for a
+ * column-major matrix, and the number of rows for a row-major matrix. */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ Index outerSize() const
+ {
+ return IsVectorAtCompileTime ? 1
+ : int(IsRowMajor) ? this->rows() : this->cols();
+ }
+
+ /** \returns the inner size.
+ *
+ * \note For a vector, this is just the size. For a matrix (non-vector), this is the minor dimension
+ * with respect to the \ref TopicStorageOrders "storage order", i.e., the number of rows for a
+ * column-major matrix, and the number of columns for a row-major matrix. */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ Index innerSize() const
+ {
+ return IsVectorAtCompileTime ? this->size()
+ : int(IsRowMajor) ? this->cols() : this->rows();
+ }
+
+ /** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are
+ * Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and does
+ * nothing else.
+ */
+ EIGEN_DEVICE_FUNC
+ void resize(Index newSize)
+ {
+ EIGEN_ONLY_USED_FOR_DEBUG(newSize);
+ eigen_assert(newSize == this->size()
+ && "DenseBase::resize() does not actually allow to resize.");
+ }
+ /** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are
+ * Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and does
+ * nothing else.
+ */
+ EIGEN_DEVICE_FUNC
+ void resize(Index rows, Index cols)
+ {
+ EIGEN_ONLY_USED_FOR_DEBUG(rows);
+ EIGEN_ONLY_USED_FOR_DEBUG(cols);
+ eigen_assert(rows == this->rows() && cols == this->cols()
+ && "DenseBase::resize() does not actually allow to resize.");
+ }
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ /** \internal Represents a matrix with all coefficients equal to one another*/
+ typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
+ /** \internal \deprecated Represents a vector with linearly spaced coefficients that allows sequential access only. */
+ EIGEN_DEPRECATED typedef CwiseNullaryOp<internal::linspaced_op<Scalar>,PlainObject> SequentialLinSpacedReturnType;
+ /** \internal Represents a vector with linearly spaced coefficients that allows random access. */
+ typedef CwiseNullaryOp<internal::linspaced_op<Scalar>,PlainObject> RandomAccessLinSpacedReturnType;
+ /** \internal the return type of MatrixBase::eigenvalues() */
+ typedef Matrix<typename NumTraits<typename internal::traits<Derived>::Scalar>::Real, internal::traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType;
+
+#endif // not EIGEN_PARSED_BY_DOXYGEN
+
+ /** Copies \a other into *this. \returns a reference to *this. */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator=(const DenseBase<OtherDerived>& other);
+
+ /** Special case of the template operator=, in order to prevent the compiler
+ * from generating a default operator= (issue hit with g++ 4.1)
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator=(const DenseBase& other);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ Derived& operator=(const EigenBase<OtherDerived> &other);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ Derived& operator+=(const EigenBase<OtherDerived> &other);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ Derived& operator-=(const EigenBase<OtherDerived> &other);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ Derived& operator=(const ReturnByValue<OtherDerived>& func);
+
+ /** \internal
+ * Copies \a other into *this without evaluating other. \returns a reference to *this. */
+ template<typename OtherDerived>
+ /** \deprecated */
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC
+ Derived& lazyAssign(const DenseBase<OtherDerived>& other);
+
+ EIGEN_DEVICE_FUNC
+ CommaInitializer<Derived> operator<< (const Scalar& s);
+
+ template<unsigned int Added,unsigned int Removed>
+ /** \deprecated it now returns \c *this */
+ EIGEN_DEPRECATED
+ const Derived& flagged() const
+ { return derived(); }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other);
+
+ typedef Transpose<Derived> TransposeReturnType;
+ EIGEN_DEVICE_FUNC
+ TransposeReturnType transpose();
+ typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType;
+ EIGEN_DEVICE_FUNC
+ ConstTransposeReturnType transpose() const;
+ EIGEN_DEVICE_FUNC
+ void transposeInPlace();
+
+ EIGEN_DEVICE_FUNC static const ConstantReturnType
+ Constant(Index rows, Index cols, const Scalar& value);
+ EIGEN_DEVICE_FUNC static const ConstantReturnType
+ Constant(Index size, const Scalar& value);
+ EIGEN_DEVICE_FUNC static const ConstantReturnType
+ Constant(const Scalar& value);
+
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
+ LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high);
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
+ LinSpaced(Sequential_t, const Scalar& low, const Scalar& high);
+
+ EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
+ LinSpaced(Index size, const Scalar& low, const Scalar& high);
+ EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
+ LinSpaced(const Scalar& low, const Scalar& high);
+
+ template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
+ static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
+ NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func);
+ template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
+ static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
+ NullaryExpr(Index size, const CustomNullaryOp& func);
+ template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
+ static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
+ NullaryExpr(const CustomNullaryOp& func);
+
+ EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index rows, Index cols);
+ EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index size);
+ EIGEN_DEVICE_FUNC static const ConstantReturnType Zero();
+ EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index rows, Index cols);
+ EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index size);
+ EIGEN_DEVICE_FUNC static const ConstantReturnType Ones();
+
+ EIGEN_DEVICE_FUNC void fill(const Scalar& value);
+ EIGEN_DEVICE_FUNC Derived& setConstant(const Scalar& value);
+ EIGEN_DEVICE_FUNC Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high);
+ EIGEN_DEVICE_FUNC Derived& setLinSpaced(const Scalar& low, const Scalar& high);
+ EIGEN_DEVICE_FUNC Derived& setZero();
+ EIGEN_DEVICE_FUNC Derived& setOnes();
+ EIGEN_DEVICE_FUNC Derived& setRandom();
+
+ template<typename OtherDerived> EIGEN_DEVICE_FUNC
+ bool isApprox(const DenseBase<OtherDerived>& other,
+ const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+ EIGEN_DEVICE_FUNC
+ bool isMuchSmallerThan(const RealScalar& other,
+ const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+ template<typename OtherDerived> EIGEN_DEVICE_FUNC
+ bool isMuchSmallerThan(const DenseBase<OtherDerived>& other,
+ const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+
+ EIGEN_DEVICE_FUNC bool isApproxToConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+ EIGEN_DEVICE_FUNC bool isConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+ EIGEN_DEVICE_FUNC bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+ EIGEN_DEVICE_FUNC bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+
+ inline bool hasNaN() const;
+ inline bool allFinite() const;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator*=(const Scalar& other);
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator/=(const Scalar& other);
+
+ typedef typename internal::add_const_on_value_type<typename internal::eval<Derived>::type>::type EvalReturnType;
+ /** \returns the matrix or vector obtained by evaluating this expression.
+ *
+ * Notice that in the case of a plain matrix or vector (not an expression) this function just returns
+ * a const reference, in order to avoid a useless copy.
+ *
+ * \warning Be careful with eval() and the auto C++ keyword, as detailed in this \link TopicPitfalls_auto_keyword page \endlink.
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE EvalReturnType eval() const
+ {
+ // Even though MSVC does not honor strong inlining when the return type
+ // is a dynamic matrix, we desperately need strong inlining for fixed
+ // size types on MSVC.
+ return typename internal::eval<Derived>::type(derived());
+ }
+
+ /** swaps *this with the expression \a other.
+ *
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void swap(const DenseBase<OtherDerived>& other)
+ {
+ EIGEN_STATIC_ASSERT(!OtherDerived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
+ eigen_assert(rows()==other.rows() && cols()==other.cols());
+ call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>());
+ }
+
+ /** swaps *this with the matrix or array \a other.
+ *
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void swap(PlainObjectBase<OtherDerived>& other)
+ {
+ eigen_assert(rows()==other.rows() && cols()==other.cols());
+ call_assignment(derived(), other.derived(), internal::swap_assign_op<Scalar>());
+ }
+
+ EIGEN_DEVICE_FUNC inline const NestByValue<Derived> nestByValue() const;
+ EIGEN_DEVICE_FUNC inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
+ EIGEN_DEVICE_FUNC inline ForceAlignedAccess<Derived> forceAlignedAccess();
+ template<bool Enable> EIGEN_DEVICE_FUNC
+ inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const;
+ template<bool Enable> EIGEN_DEVICE_FUNC
+ inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
+
+ EIGEN_DEVICE_FUNC Scalar sum() const;
+ EIGEN_DEVICE_FUNC Scalar mean() const;
+ EIGEN_DEVICE_FUNC Scalar trace() const;
+
+ EIGEN_DEVICE_FUNC Scalar prod() const;
+
+ template<int NaNPropagation>
+ EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff() const;
+ template<int NaNPropagation>
+ EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar maxCoeff() const;
+
+
+ // By default, the fastest version with undefined NaN propagation semantics is
+ // used.
+ // TODO(rmlarsen): Replace with default template argument when we move to
+ // c++11 or beyond.
+ EIGEN_DEVICE_FUNC inline typename internal::traits<Derived>::Scalar minCoeff() const {
+ return minCoeff<PropagateFast>();
+ }
+ EIGEN_DEVICE_FUNC inline typename internal::traits<Derived>::Scalar maxCoeff() const {
+ return maxCoeff<PropagateFast>();
+ }
+
+ template<int NaNPropagation, typename IndexType>
+ EIGEN_DEVICE_FUNC
+ typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const;
+ template<int NaNPropagation, typename IndexType>
+ EIGEN_DEVICE_FUNC
+ typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const;
+ template<int NaNPropagation, typename IndexType>
+ EIGEN_DEVICE_FUNC
+ typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const;
+ template<int NaNPropagation, typename IndexType>
+ EIGEN_DEVICE_FUNC
+ typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const;
+
+ // TODO(rmlarsen): Replace these methods with a default template argument.
+ template<typename IndexType>
+ EIGEN_DEVICE_FUNC inline
+ typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const {
+ return minCoeff<PropagateFast>(row, col);
+ }
+ template<typename IndexType>
+ EIGEN_DEVICE_FUNC inline
+ typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const {
+ return maxCoeff<PropagateFast>(row, col);
+ }
+ template<typename IndexType>
+ EIGEN_DEVICE_FUNC inline
+ typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const {
+ return minCoeff<PropagateFast>(index);
+ }
+ template<typename IndexType>
+ EIGEN_DEVICE_FUNC inline
+ typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const {
+ return maxCoeff<PropagateFast>(index);
+ }
+
+ template<typename BinaryOp>
+ EIGEN_DEVICE_FUNC
+ Scalar redux(const BinaryOp& func) const;
+
+ template<typename Visitor>
+ EIGEN_DEVICE_FUNC
+ void visit(Visitor& func) const;
+
+ /** \returns a WithFormat proxy object allowing to print a matrix the with given
+ * format \a fmt.
+ *
+ * See class IOFormat for some examples.
+ *
+ * \sa class IOFormat, class WithFormat
+ */
+ inline const WithFormat<Derived> format(const IOFormat& fmt) const
+ {
+ return WithFormat<Derived>(derived(), fmt);
+ }
+
+ /** \returns the unique coefficient of a 1x1 expression */
+ EIGEN_DEVICE_FUNC
+ CoeffReturnType value() const
+ {
+ EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
+ eigen_assert(this->rows() == 1 && this->cols() == 1);
+ return derived().coeff(0,0);
+ }
+
+ EIGEN_DEVICE_FUNC bool all() const;
+ EIGEN_DEVICE_FUNC bool any() const;
+ EIGEN_DEVICE_FUNC Index count() const;
+
+ typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType;
+ typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType;
+ typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType;
+ typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType;
+
+ /** \returns a VectorwiseOp wrapper of *this for broadcasting and partial reductions
+ *
+ * Example: \include MatrixBase_rowwise.cpp
+ * Output: \verbinclude MatrixBase_rowwise.out
+ *
+ * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
+ */
+ //Code moved here due to a CUDA compiler bug
+ EIGEN_DEVICE_FUNC inline ConstRowwiseReturnType rowwise() const {
+ return ConstRowwiseReturnType(derived());
+ }
+ EIGEN_DEVICE_FUNC RowwiseReturnType rowwise();
+
+ /** \returns a VectorwiseOp wrapper of *this broadcasting and partial reductions
+ *
+ * Example: \include MatrixBase_colwise.cpp
+ * Output: \verbinclude MatrixBase_colwise.out
+ *
+ * \sa rowwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
+ */
+ EIGEN_DEVICE_FUNC inline ConstColwiseReturnType colwise() const {
+ return ConstColwiseReturnType(derived());
+ }
+ EIGEN_DEVICE_FUNC ColwiseReturnType colwise();
+
+ typedef CwiseNullaryOp<internal::scalar_random_op<Scalar>,PlainObject> RandomReturnType;
+ static const RandomReturnType Random(Index rows, Index cols);
+ static const RandomReturnType Random(Index size);
+ static const RandomReturnType Random();
+
+ template<typename ThenDerived,typename ElseDerived>
+ inline EIGEN_DEVICE_FUNC const Select<Derived,ThenDerived,ElseDerived>
+ select(const DenseBase<ThenDerived>& thenMatrix,
+ const DenseBase<ElseDerived>& elseMatrix) const;
+
+ template<typename ThenDerived>
+ inline EIGEN_DEVICE_FUNC const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
+ select(const DenseBase<ThenDerived>& thenMatrix, const typename ThenDerived::Scalar& elseScalar) const;
+
+ template<typename ElseDerived>
+ inline EIGEN_DEVICE_FUNC const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
+ select(const typename ElseDerived::Scalar& thenScalar, const DenseBase<ElseDerived>& elseMatrix) const;
+
+ template<int p> RealScalar lpNorm() const;
+
+ template<int RowFactor, int ColFactor>
+ EIGEN_DEVICE_FUNC
+ const Replicate<Derived,RowFactor,ColFactor> replicate() const;
+ /**
+ * \return an expression of the replication of \c *this
+ *
+ * Example: \include MatrixBase_replicate_int_int.cpp
+ * Output: \verbinclude MatrixBase_replicate_int_int.out
+ *
+ * \sa VectorwiseOp::replicate(), DenseBase::replicate<int,int>(), class Replicate
+ */
+ //Code moved here due to a CUDA compiler bug
+ EIGEN_DEVICE_FUNC
+ const Replicate<Derived, Dynamic, Dynamic> replicate(Index rowFactor, Index colFactor) const
+ {
+ return Replicate<Derived, Dynamic, Dynamic>(derived(), rowFactor, colFactor);
+ }
+
+ typedef Reverse<Derived, BothDirections> ReverseReturnType;
+ typedef const Reverse<const Derived, BothDirections> ConstReverseReturnType;
+ EIGEN_DEVICE_FUNC ReverseReturnType reverse();
+ /** This is the const version of reverse(). */
+ //Code moved here due to a CUDA compiler bug
+ EIGEN_DEVICE_FUNC ConstReverseReturnType reverse() const
+ {
+ return ConstReverseReturnType(derived());
+ }
+ EIGEN_DEVICE_FUNC void reverseInPlace();
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** STL-like <a href="https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator">RandomAccessIterator</a>
+ * iterator type as returned by the begin() and end() methods.
+ */
+ typedef random_access_iterator_type iterator;
+ /** This is the const version of iterator (aka read-only) */
+ typedef random_access_iterator_type const_iterator;
+ #else
+ typedef typename internal::conditional< (Flags&DirectAccessBit)==DirectAccessBit,
+ internal::pointer_based_stl_iterator<Derived>,
+ internal::generic_randaccess_stl_iterator<Derived>
+ >::type iterator_type;
+
+ typedef typename internal::conditional< (Flags&DirectAccessBit)==DirectAccessBit,
+ internal::pointer_based_stl_iterator<const Derived>,
+ internal::generic_randaccess_stl_iterator<const Derived>
+ >::type const_iterator_type;
+
+ // Stl-style iterators are supported only for vectors.
+
+ typedef typename internal::conditional< IsVectorAtCompileTime,
+ iterator_type,
+ void
+ >::type iterator;
+
+ typedef typename internal::conditional< IsVectorAtCompileTime,
+ const_iterator_type,
+ void
+ >::type const_iterator;
+ #endif
+
+ inline iterator begin();
+ inline const_iterator begin() const;
+ inline const_iterator cbegin() const;
+ inline iterator end();
+ inline const_iterator end() const;
+ inline const_iterator cend() const;
+
+#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
+#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
+#define EIGEN_DOC_UNARY_ADDONS(X,Y)
+# include "../plugins/CommonCwiseUnaryOps.h"
+# include "../plugins/BlockMethods.h"
+# include "../plugins/IndexedViewMethods.h"
+# include "../plugins/ReshapedMethods.h"
+# ifdef EIGEN_DENSEBASE_PLUGIN
+# include EIGEN_DENSEBASE_PLUGIN
+# endif
+#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
+#undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+#undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF
+#undef EIGEN_DOC_UNARY_ADDONS
+
+ // disable the use of evalTo for dense objects with a nice compilation error
+ template<typename Dest>
+ EIGEN_DEVICE_FUNC
+ inline void evalTo(Dest& ) const
+ {
+ EIGEN_STATIC_ASSERT((internal::is_same<Dest,void>::value),THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS);
+ }
+
+ protected:
+ EIGEN_DEFAULT_COPY_CONSTRUCTOR(DenseBase)
+ /** Default constructor. Do nothing. */
+ EIGEN_DEVICE_FUNC DenseBase()
+ {
+ /* Just checks for self-consistency of the flags.
+ * Only do it when debugging Eigen, as this borders on paranoia and could slow compilation down
+ */
+#ifdef EIGEN_INTERNAL_DEBUGGING
+ EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, int(IsRowMajor))
+ && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, int(!IsRowMajor))),
+ INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION)
+#endif
+ }
+
+ private:
+ EIGEN_DEVICE_FUNC explicit DenseBase(int);
+ EIGEN_DEVICE_FUNC DenseBase(int,int);
+ template<typename OtherDerived> EIGEN_DEVICE_FUNC explicit DenseBase(const DenseBase<OtherDerived>&);
+};
+
+} // end namespace Eigen
+
+#endif // EIGEN_DENSEBASE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/DenseCoeffsBase.h b/src/3rdparty/eigen/Eigen/src/Core/DenseCoeffsBase.h
new file mode 100644
index 000000000..37fcdb591
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/DenseCoeffsBase.h
@@ -0,0 +1,685 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_DENSECOEFFSBASE_H
+#define EIGEN_DENSECOEFFSBASE_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename T> struct add_const_on_value_type_if_arithmetic
+{
+ typedef typename conditional<is_arithmetic<T>::value, T, typename add_const_on_value_type<T>::type>::type type;
+};
+}
+
+/** \brief Base class providing read-only coefficient access to matrices and arrays.
+ * \ingroup Core_Module
+ * \tparam Derived Type of the derived class
+ *
+ * \note #ReadOnlyAccessors Constant indicating read-only access
+ *
+ * This class defines the \c operator() \c const function and friends, which can be used to read specific
+ * entries of a matrix or array.
+ *
+ * \sa DenseCoeffsBase<Derived, WriteAccessors>, DenseCoeffsBase<Derived, DirectAccessors>,
+ * \ref TopicClassHierarchy
+ */
+template<typename Derived>
+class DenseCoeffsBase<Derived,ReadOnlyAccessors> : public EigenBase<Derived>
+{
+ public:
+ typedef typename internal::traits<Derived>::StorageKind StorageKind;
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+ typedef typename internal::packet_traits<Scalar>::type PacketScalar;
+
+ // Explanation for this CoeffReturnType typedef.
+ // - This is the return type of the coeff() method.
+ // - The LvalueBit means exactly that we can offer a coeffRef() method, which means exactly that we can get references
+ // to coeffs, which means exactly that we can have coeff() return a const reference (as opposed to returning a value).
+ // - The is_artihmetic check is required since "const int", "const double", etc. will cause warnings on some systems
+ // while the declaration of "const T", where T is a non arithmetic type does not. Always returning "const Scalar&" is
+ // not possible, since the underlying expressions might not offer a valid address the reference could be referring to.
+ typedef typename internal::conditional<bool(internal::traits<Derived>::Flags&LvalueBit),
+ const Scalar&,
+ typename internal::conditional<internal::is_arithmetic<Scalar>::value, Scalar, const Scalar>::type
+ >::type CoeffReturnType;
+
+ typedef typename internal::add_const_on_value_type_if_arithmetic<
+ typename internal::packet_traits<Scalar>::type
+ >::type PacketReturnType;
+
+ typedef EigenBase<Derived> Base;
+ using Base::rows;
+ using Base::cols;
+ using Base::size;
+ using Base::derived;
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) const
+ {
+ return int(Derived::RowsAtCompileTime) == 1 ? 0
+ : int(Derived::ColsAtCompileTime) == 1 ? inner
+ : int(Derived::Flags)&RowMajorBit ? outer
+ : inner;
+ }
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner) const
+ {
+ return int(Derived::ColsAtCompileTime) == 1 ? 0
+ : int(Derived::RowsAtCompileTime) == 1 ? inner
+ : int(Derived::Flags)&RowMajorBit ? inner
+ : outer;
+ }
+
+ /** Short version: don't use this function, use
+ * \link operator()(Index,Index) const \endlink instead.
+ *
+ * Long version: this function is similar to
+ * \link operator()(Index,Index) const \endlink, but without the assertion.
+ * Use this for limiting the performance cost of debugging code when doing
+ * repeated coefficient access. Only use this when it is guaranteed that the
+ * parameters \a row and \a col are in range.
+ *
+ * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
+ * function equivalent to \link operator()(Index,Index) const \endlink.
+ *
+ * \sa operator()(Index,Index) const, coeffRef(Index,Index), coeff(Index) const
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const
+ {
+ eigen_internal_assert(row >= 0 && row < rows()
+ && col >= 0 && col < cols());
+ return internal::evaluator<Derived>(derived()).coeff(row,col);
+ }
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(Index outer, Index inner) const
+ {
+ return coeff(rowIndexByOuterInner(outer, inner),
+ colIndexByOuterInner(outer, inner));
+ }
+
+ /** \returns the coefficient at given the given row and column.
+ *
+ * \sa operator()(Index,Index), operator[](Index)
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE CoeffReturnType operator()(Index row, Index col) const
+ {
+ eigen_assert(row >= 0 && row < rows()
+ && col >= 0 && col < cols());
+ return coeff(row, col);
+ }
+
+ /** Short version: don't use this function, use
+ * \link operator[](Index) const \endlink instead.
+ *
+ * Long version: this function is similar to
+ * \link operator[](Index) const \endlink, but without the assertion.
+ * Use this for limiting the performance cost of debugging code when doing
+ * repeated coefficient access. Only use this when it is guaranteed that the
+ * parameter \a index is in range.
+ *
+ * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
+ * function equivalent to \link operator[](Index) const \endlink.
+ *
+ * \sa operator[](Index) const, coeffRef(Index), coeff(Index,Index) const
+ */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE CoeffReturnType
+ coeff(Index index) const
+ {
+ EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags & LinearAccessBit,
+ THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
+ eigen_internal_assert(index >= 0 && index < size());
+ return internal::evaluator<Derived>(derived()).coeff(index);
+ }
+
+
+ /** \returns the coefficient at given index.
+ *
+ * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit.
+ *
+ * \sa operator[](Index), operator()(Index,Index) const, x() const, y() const,
+ * z() const, w() const
+ */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE CoeffReturnType
+ operator[](Index index) const
+ {
+ EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
+ THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
+ eigen_assert(index >= 0 && index < size());
+ return coeff(index);
+ }
+
+ /** \returns the coefficient at given index.
+ *
+ * This is synonymous to operator[](Index) const.
+ *
+ * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit.
+ *
+ * \sa operator[](Index), operator()(Index,Index) const, x() const, y() const,
+ * z() const, w() const
+ */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE CoeffReturnType
+ operator()(Index index) const
+ {
+ eigen_assert(index >= 0 && index < size());
+ return coeff(index);
+ }
+
+ /** equivalent to operator[](0). */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE CoeffReturnType
+ x() const { return (*this)[0]; }
+
+ /** equivalent to operator[](1). */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE CoeffReturnType
+ y() const
+ {
+ EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS);
+ return (*this)[1];
+ }
+
+ /** equivalent to operator[](2). */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE CoeffReturnType
+ z() const
+ {
+ EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS);
+ return (*this)[2];
+ }
+
+ /** equivalent to operator[](3). */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE CoeffReturnType
+ w() const
+ {
+ EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS);
+ return (*this)[3];
+ }
+
+ /** \internal
+ * \returns the packet of coefficients starting at the given row and column. It is your responsibility
+ * to ensure that a packet really starts there. This method is only available on expressions having the
+ * PacketAccessBit.
+ *
+ * The \a LoadMode parameter may have the value \a #Aligned or \a #Unaligned. Its effect is to select
+ * the appropriate vectorization instruction. Aligned access is faster, but is only possible for packets
+ * starting at an address which is a multiple of the packet size.
+ */
+
+ template<int LoadMode>
+ EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col) const
+ {
+ typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
+ eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
+ return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(row,col);
+ }
+
+
+ /** \internal */
+ template<int LoadMode>
+ EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(Index outer, Index inner) const
+ {
+ return packet<LoadMode>(rowIndexByOuterInner(outer, inner),
+ colIndexByOuterInner(outer, inner));
+ }
+
+ /** \internal
+ * \returns the packet of coefficients starting at the given index. It is your responsibility
+ * to ensure that a packet really starts there. This method is only available on expressions having the
+ * PacketAccessBit and the LinearAccessBit.
+ *
+ * The \a LoadMode parameter may have the value \a #Aligned or \a #Unaligned. Its effect is to select
+ * the appropriate vectorization instruction. Aligned access is faster, but is only possible for packets
+ * starting at an address which is a multiple of the packet size.
+ */
+
+ template<int LoadMode>
+ EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
+ {
+ EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags & LinearAccessBit,
+ THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
+ typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
+ eigen_internal_assert(index >= 0 && index < size());
+ return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(index);
+ }
+
+ protected:
+ // explanation: DenseBase is doing "using ..." on the methods from DenseCoeffsBase.
+ // But some methods are only available in the DirectAccess case.
+ // So we add dummy methods here with these names, so that "using... " doesn't fail.
+ // It's not private so that the child class DenseBase can access them, and it's not public
+ // either since it's an implementation detail, so has to be protected.
+ void coeffRef();
+ void coeffRefByOuterInner();
+ void writePacket();
+ void writePacketByOuterInner();
+ void copyCoeff();
+ void copyCoeffByOuterInner();
+ void copyPacket();
+ void copyPacketByOuterInner();
+ void stride();
+ void innerStride();
+ void outerStride();
+ void rowStride();
+ void colStride();
+};
+
+/** \brief Base class providing read/write coefficient access to matrices and arrays.
+ * \ingroup Core_Module
+ * \tparam Derived Type of the derived class
+ *
+ * \note #WriteAccessors Constant indicating read/write access
+ *
+ * This class defines the non-const \c operator() function and friends, which can be used to write specific
+ * entries of a matrix or array. This class inherits DenseCoeffsBase<Derived, ReadOnlyAccessors> which
+ * defines the const variant for reading specific entries.
+ *
+ * \sa DenseCoeffsBase<Derived, DirectAccessors>, \ref TopicClassHierarchy
+ */
+template<typename Derived>
+class DenseCoeffsBase<Derived, WriteAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors>
+{
+ public:
+
+ typedef DenseCoeffsBase<Derived, ReadOnlyAccessors> Base;
+
+ typedef typename internal::traits<Derived>::StorageKind StorageKind;
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+ typedef typename internal::packet_traits<Scalar>::type PacketScalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ using Base::coeff;
+ using Base::rows;
+ using Base::cols;
+ using Base::size;
+ using Base::derived;
+ using Base::rowIndexByOuterInner;
+ using Base::colIndexByOuterInner;
+ using Base::operator[];
+ using Base::operator();
+ using Base::x;
+ using Base::y;
+ using Base::z;
+ using Base::w;
+
+ /** Short version: don't use this function, use
+ * \link operator()(Index,Index) \endlink instead.
+ *
+ * Long version: this function is similar to
+ * \link operator()(Index,Index) \endlink, but without the assertion.
+ * Use this for limiting the performance cost of debugging code when doing
+ * repeated coefficient access. Only use this when it is guaranteed that the
+ * parameters \a row and \a col are in range.
+ *
+ * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
+ * function equivalent to \link operator()(Index,Index) \endlink.
+ *
+ * \sa operator()(Index,Index), coeff(Index, Index) const, coeffRef(Index)
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col)
+ {
+ eigen_internal_assert(row >= 0 && row < rows()
+ && col >= 0 && col < cols());
+ return internal::evaluator<Derived>(derived()).coeffRef(row,col);
+ }
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar&
+ coeffRefByOuterInner(Index outer, Index inner)
+ {
+ return coeffRef(rowIndexByOuterInner(outer, inner),
+ colIndexByOuterInner(outer, inner));
+ }
+
+ /** \returns a reference to the coefficient at given the given row and column.
+ *
+ * \sa operator[](Index)
+ */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar&
+ operator()(Index row, Index col)
+ {
+ eigen_assert(row >= 0 && row < rows()
+ && col >= 0 && col < cols());
+ return coeffRef(row, col);
+ }
+
+
+ /** Short version: don't use this function, use
+ * \link operator[](Index) \endlink instead.
+ *
+ * Long version: this function is similar to
+ * \link operator[](Index) \endlink, but without the assertion.
+ * Use this for limiting the performance cost of debugging code when doing
+ * repeated coefficient access. Only use this when it is guaranteed that the
+ * parameters \a row and \a col are in range.
+ *
+ * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
+ * function equivalent to \link operator[](Index) \endlink.
+ *
+ * \sa operator[](Index), coeff(Index) const, coeffRef(Index,Index)
+ */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar&
+ coeffRef(Index index)
+ {
+ EIGEN_STATIC_ASSERT(internal::evaluator<Derived>::Flags & LinearAccessBit,
+ THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
+ eigen_internal_assert(index >= 0 && index < size());
+ return internal::evaluator<Derived>(derived()).coeffRef(index);
+ }
+
+ /** \returns a reference to the coefficient at given index.
+ *
+ * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit.
+ *
+ * \sa operator[](Index) const, operator()(Index,Index), x(), y(), z(), w()
+ */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar&
+ operator[](Index index)
+ {
+ EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
+ THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
+ eigen_assert(index >= 0 && index < size());
+ return coeffRef(index);
+ }
+
+ /** \returns a reference to the coefficient at given index.
+ *
+ * This is synonymous to operator[](Index).
+ *
+ * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit.
+ *
+ * \sa operator[](Index) const, operator()(Index,Index), x(), y(), z(), w()
+ */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar&
+ operator()(Index index)
+ {
+ eigen_assert(index >= 0 && index < size());
+ return coeffRef(index);
+ }
+
+ /** equivalent to operator[](0). */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar&
+ x() { return (*this)[0]; }
+
+ /** equivalent to operator[](1). */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar&
+ y()
+ {
+ EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS);
+ return (*this)[1];
+ }
+
+ /** equivalent to operator[](2). */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar&
+ z()
+ {
+ EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS);
+ return (*this)[2];
+ }
+
+ /** equivalent to operator[](3). */
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar&
+ w()
+ {
+ EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS);
+ return (*this)[3];
+ }
+};
+
+/** \brief Base class providing direct read-only coefficient access to matrices and arrays.
+ * \ingroup Core_Module
+ * \tparam Derived Type of the derived class
+ *
+ * \note #DirectAccessors Constant indicating direct access
+ *
+ * This class defines functions to work with strides which can be used to access entries directly. This class
+ * inherits DenseCoeffsBase<Derived, ReadOnlyAccessors> which defines functions to access entries read-only using
+ * \c operator() .
+ *
+ * \sa \blank \ref TopicClassHierarchy
+ */
+template<typename Derived>
+class DenseCoeffsBase<Derived, DirectAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors>
+{
+ public:
+
+ typedef DenseCoeffsBase<Derived, ReadOnlyAccessors> Base;
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ using Base::rows;
+ using Base::cols;
+ using Base::size;
+ using Base::derived;
+
+ /** \returns the pointer increment between two consecutive elements within a slice in the inner direction.
+ *
+ * \sa outerStride(), rowStride(), colStride()
+ */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const
+ {
+ return derived().innerStride();
+ }
+
+ /** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns
+ * in a column-major matrix).
+ *
+ * \sa innerStride(), rowStride(), colStride()
+ */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const
+ {
+ return derived().outerStride();
+ }
+
+ // FIXME shall we remove it ?
+ EIGEN_CONSTEXPR inline Index stride() const
+ {
+ return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
+ }
+
+ /** \returns the pointer increment between two consecutive rows.
+ *
+ * \sa innerStride(), outerStride(), colStride()
+ */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rowStride() const
+ {
+ return Derived::IsRowMajor ? outerStride() : innerStride();
+ }
+
+ /** \returns the pointer increment between two consecutive columns.
+ *
+ * \sa innerStride(), outerStride(), rowStride()
+ */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index colStride() const
+ {
+ return Derived::IsRowMajor ? innerStride() : outerStride();
+ }
+};
+
+/** \brief Base class providing direct read/write coefficient access to matrices and arrays.
+ * \ingroup Core_Module
+ * \tparam Derived Type of the derived class
+ *
+ * \note #DirectWriteAccessors Constant indicating direct access
+ *
+ * This class defines functions to work with strides which can be used to access entries directly. This class
+ * inherits DenseCoeffsBase<Derived, WriteAccessors> which defines functions to access entries read/write using
+ * \c operator().
+ *
+ * \sa \blank \ref TopicClassHierarchy
+ */
+template<typename Derived>
+class DenseCoeffsBase<Derived, DirectWriteAccessors>
+ : public DenseCoeffsBase<Derived, WriteAccessors>
+{
+ public:
+
+ typedef DenseCoeffsBase<Derived, WriteAccessors> Base;
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ using Base::rows;
+ using Base::cols;
+ using Base::size;
+ using Base::derived;
+
+ /** \returns the pointer increment between two consecutive elements within a slice in the inner direction.
+ *
+ * \sa outerStride(), rowStride(), colStride()
+ */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const EIGEN_NOEXCEPT
+ {
+ return derived().innerStride();
+ }
+
+ /** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns
+ * in a column-major matrix).
+ *
+ * \sa innerStride(), rowStride(), colStride()
+ */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const EIGEN_NOEXCEPT
+ {
+ return derived().outerStride();
+ }
+
+ // FIXME shall we remove it ?
+ EIGEN_CONSTEXPR inline Index stride() const EIGEN_NOEXCEPT
+ {
+ return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
+ }
+
+ /** \returns the pointer increment between two consecutive rows.
+ *
+ * \sa innerStride(), outerStride(), colStride()
+ */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rowStride() const EIGEN_NOEXCEPT
+ {
+ return Derived::IsRowMajor ? outerStride() : innerStride();
+ }
+
+ /** \returns the pointer increment between two consecutive columns.
+ *
+ * \sa innerStride(), outerStride(), rowStride()
+ */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index colStride() const EIGEN_NOEXCEPT
+ {
+ return Derived::IsRowMajor ? innerStride() : outerStride();
+ }
+};
+
+namespace internal {
+
+template<int Alignment, typename Derived, bool JustReturnZero>
+struct first_aligned_impl
+{
+ static EIGEN_CONSTEXPR inline Index run(const Derived&) EIGEN_NOEXCEPT
+ { return 0; }
+};
+
+template<int Alignment, typename Derived>
+struct first_aligned_impl<Alignment, Derived, false>
+{
+ static inline Index run(const Derived& m)
+ {
+ return internal::first_aligned<Alignment>(m.data(), m.size());
+ }
+};
+
+/** \internal \returns the index of the first element of the array stored by \a m that is properly aligned with respect to \a Alignment for vectorization.
+ *
+ * \tparam Alignment requested alignment in Bytes.
+ *
+ * There is also the variant first_aligned(const Scalar*, Integer) defined in Memory.h. See it for more
+ * documentation.
+ */
+template<int Alignment, typename Derived>
+static inline Index first_aligned(const DenseBase<Derived>& m)
+{
+ enum { ReturnZero = (int(evaluator<Derived>::Alignment) >= Alignment) || !(Derived::Flags & DirectAccessBit) };
+ return first_aligned_impl<Alignment, Derived, ReturnZero>::run(m.derived());
+}
+
+template<typename Derived>
+static inline Index first_default_aligned(const DenseBase<Derived>& m)
+{
+ typedef typename Derived::Scalar Scalar;
+ typedef typename packet_traits<Scalar>::type DefaultPacketType;
+ return internal::first_aligned<int(unpacket_traits<DefaultPacketType>::alignment),Derived>(m);
+}
+
+template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
+struct inner_stride_at_compile_time
+{
+ enum { ret = traits<Derived>::InnerStrideAtCompileTime };
+};
+
+template<typename Derived>
+struct inner_stride_at_compile_time<Derived, false>
+{
+ enum { ret = 0 };
+};
+
+template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
+struct outer_stride_at_compile_time
+{
+ enum { ret = traits<Derived>::OuterStrideAtCompileTime };
+};
+
+template<typename Derived>
+struct outer_stride_at_compile_time<Derived, false>
+{
+ enum { ret = 0 };
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_DENSECOEFFSBASE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/DenseStorage.h b/src/3rdparty/eigen/Eigen/src/Core/DenseStorage.h
new file mode 100644
index 000000000..08ef6c530
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/DenseStorage.h
@@ -0,0 +1,652 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2010-2013 Hauke Heibel <hauke.heibel@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATRIXSTORAGE_H
+#define EIGEN_MATRIXSTORAGE_H
+
+#ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X) X; EIGEN_DENSE_STORAGE_CTOR_PLUGIN;
+#else
+ #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X)
+#endif
+
+namespace Eigen {
+
+namespace internal {
+
+struct constructor_without_unaligned_array_assert {};
+
+template<typename T, int Size>
+EIGEN_DEVICE_FUNC
+void check_static_allocation_size()
+{
+ // if EIGEN_STACK_ALLOCATION_LIMIT is defined to 0, then no limit
+ #if EIGEN_STACK_ALLOCATION_LIMIT
+ EIGEN_STATIC_ASSERT(Size * sizeof(T) <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG);
+ #endif
+}
+
+/** \internal
+ * Static array. If the MatrixOrArrayOptions require auto-alignment, the array will be automatically aligned:
+ * to 16 bytes boundary if the total size is a multiple of 16 bytes.
+ */
+template <typename T, int Size, int MatrixOrArrayOptions,
+ int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0
+ : compute_default_alignment<T,Size>::value >
+struct plain_array
+{
+ T array[Size];
+
+ EIGEN_DEVICE_FUNC
+ plain_array()
+ {
+ check_static_allocation_size<T,Size>();
+ }
+
+ EIGEN_DEVICE_FUNC
+ plain_array(constructor_without_unaligned_array_assert)
+ {
+ check_static_allocation_size<T,Size>();
+ }
+};
+
+#if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
+ #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
+#elif EIGEN_GNUC_AT_LEAST(4,7)
+ // GCC 4.7 is too aggressive in its optimizations and remove the alignment test based on the fact the array is declared to be aligned.
+ // See this bug report: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53900
+ // Hiding the origin of the array pointer behind a function argument seems to do the trick even if the function is inlined:
+ template<typename PtrType>
+ EIGEN_ALWAYS_INLINE PtrType eigen_unaligned_array_assert_workaround_gcc47(PtrType array) { return array; }
+ #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
+ eigen_assert((internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array)) & (sizemask)) == 0 \
+ && "this assertion is explained here: " \
+ "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
+ " **** READ THIS WEB PAGE !!! ****");
+#else
+ #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
+ eigen_assert((internal::UIntPtr(array) & (sizemask)) == 0 \
+ && "this assertion is explained here: " \
+ "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
+ " **** READ THIS WEB PAGE !!! ****");
+#endif
+
+template <typename T, int Size, int MatrixOrArrayOptions>
+struct plain_array<T, Size, MatrixOrArrayOptions, 8>
+{
+ EIGEN_ALIGN_TO_BOUNDARY(8) T array[Size];
+
+ EIGEN_DEVICE_FUNC
+ plain_array()
+ {
+ EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(7);
+ check_static_allocation_size<T,Size>();
+ }
+
+ EIGEN_DEVICE_FUNC
+ plain_array(constructor_without_unaligned_array_assert)
+ {
+ check_static_allocation_size<T,Size>();
+ }
+};
+
+template <typename T, int Size, int MatrixOrArrayOptions>
+struct plain_array<T, Size, MatrixOrArrayOptions, 16>
+{
+ EIGEN_ALIGN_TO_BOUNDARY(16) T array[Size];
+
+ EIGEN_DEVICE_FUNC
+ plain_array()
+ {
+ EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(15);
+ check_static_allocation_size<T,Size>();
+ }
+
+ EIGEN_DEVICE_FUNC
+ plain_array(constructor_without_unaligned_array_assert)
+ {
+ check_static_allocation_size<T,Size>();
+ }
+};
+
+template <typename T, int Size, int MatrixOrArrayOptions>
+struct plain_array<T, Size, MatrixOrArrayOptions, 32>
+{
+ EIGEN_ALIGN_TO_BOUNDARY(32) T array[Size];
+
+ EIGEN_DEVICE_FUNC
+ plain_array()
+ {
+ EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(31);
+ check_static_allocation_size<T,Size>();
+ }
+
+ EIGEN_DEVICE_FUNC
+ plain_array(constructor_without_unaligned_array_assert)
+ {
+ check_static_allocation_size<T,Size>();
+ }
+};
+
+template <typename T, int Size, int MatrixOrArrayOptions>
+struct plain_array<T, Size, MatrixOrArrayOptions, 64>
+{
+ EIGEN_ALIGN_TO_BOUNDARY(64) T array[Size];
+
+ EIGEN_DEVICE_FUNC
+ plain_array()
+ {
+ EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(63);
+ check_static_allocation_size<T,Size>();
+ }
+
+ EIGEN_DEVICE_FUNC
+ plain_array(constructor_without_unaligned_array_assert)
+ {
+ check_static_allocation_size<T,Size>();
+ }
+};
+
+template <typename T, int MatrixOrArrayOptions, int Alignment>
+struct plain_array<T, 0, MatrixOrArrayOptions, Alignment>
+{
+ T array[1];
+ EIGEN_DEVICE_FUNC plain_array() {}
+ EIGEN_DEVICE_FUNC plain_array(constructor_without_unaligned_array_assert) {}
+};
+
+struct plain_array_helper {
+ template<typename T, int Size, int MatrixOrArrayOptions, int Alignment>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ static void copy(const plain_array<T, Size, MatrixOrArrayOptions, Alignment>& src, const Eigen::Index size,
+ plain_array<T, Size, MatrixOrArrayOptions, Alignment>& dst) {
+ smart_copy(src.array, src.array + size, dst.array);
+ }
+
+ template<typename T, int Size, int MatrixOrArrayOptions, int Alignment>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ static void swap(plain_array<T, Size, MatrixOrArrayOptions, Alignment>& a, const Eigen::Index a_size,
+ plain_array<T, Size, MatrixOrArrayOptions, Alignment>& b, const Eigen::Index b_size) {
+ if (a_size < b_size) {
+ std::swap_ranges(b.array, b.array + a_size, a.array);
+ smart_move(b.array + a_size, b.array + b_size, a.array + a_size);
+ } else if (a_size > b_size) {
+ std::swap_ranges(a.array, a.array + b_size, b.array);
+ smart_move(a.array + b_size, a.array + a_size, b.array + b_size);
+ } else {
+ std::swap_ranges(a.array, a.array + a_size, b.array);
+ }
+ }
+};
+
+} // end namespace internal
+
+/** \internal
+ *
+ * \class DenseStorage
+ * \ingroup Core_Module
+ *
+ * \brief Stores the data of a matrix
+ *
+ * This class stores the data of fixed-size, dynamic-size or mixed matrices
+ * in a way as compact as possible.
+ *
+ * \sa Matrix
+ */
+template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage;
+
+// purely fixed-size matrix
+template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage
+{
+ internal::plain_array<T,Size,_Options> m_data;
+ public:
+ EIGEN_DEVICE_FUNC DenseStorage() {
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size)
+ }
+ EIGEN_DEVICE_FUNC
+ explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
+ : m_data(internal::constructor_without_unaligned_array_assert()) {}
+#if !EIGEN_HAS_CXX11 || defined(EIGEN_DENSE_STORAGE_CTOR_PLUGIN)
+ EIGEN_DEVICE_FUNC
+ DenseStorage(const DenseStorage& other) : m_data(other.m_data) {
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size)
+ }
+#else
+ EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage&) = default;
+#endif
+#if !EIGEN_HAS_CXX11
+ EIGEN_DEVICE_FUNC
+ DenseStorage& operator=(const DenseStorage& other)
+ {
+ if (this != &other) m_data = other.m_data;
+ return *this;
+ }
+#else
+ EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage&) = default;
+#endif
+#if EIGEN_HAS_RVALUE_REFERENCES
+#if !EIGEN_HAS_CXX11
+ EIGEN_DEVICE_FUNC DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
+ : m_data(std::move(other.m_data))
+ {
+ }
+ EIGEN_DEVICE_FUNC DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
+ {
+ if (this != &other)
+ m_data = std::move(other.m_data);
+ return *this;
+ }
+#else
+ EIGEN_DEVICE_FUNC DenseStorage(DenseStorage&&) = default;
+ EIGEN_DEVICE_FUNC DenseStorage& operator=(DenseStorage&&) = default;
+#endif
+#endif
+ EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) {
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
+ eigen_internal_assert(size==rows*cols && rows==_Rows && cols==_Cols);
+ EIGEN_UNUSED_VARIABLE(size);
+ EIGEN_UNUSED_VARIABLE(rows);
+ EIGEN_UNUSED_VARIABLE(cols);
+ }
+ EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
+ numext::swap(m_data, other.m_data);
+ }
+ EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index rows(void) EIGEN_NOEXCEPT {return _Rows;}
+ EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index cols(void) EIGEN_NOEXCEPT {return _Cols;}
+ EIGEN_DEVICE_FUNC void conservativeResize(Index,Index,Index) {}
+ EIGEN_DEVICE_FUNC void resize(Index,Index,Index) {}
+ EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
+ EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
+};
+
+// null matrix
+template<typename T, int _Rows, int _Cols, int _Options> class DenseStorage<T, 0, _Rows, _Cols, _Options>
+{
+ public:
+ EIGEN_DEVICE_FUNC DenseStorage() {}
+ EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) {}
+ EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage&) {}
+ EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage&) { return *this; }
+ EIGEN_DEVICE_FUNC DenseStorage(Index,Index,Index) {}
+ EIGEN_DEVICE_FUNC void swap(DenseStorage& ) {}
+ EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index rows(void) EIGEN_NOEXCEPT {return _Rows;}
+ EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index cols(void) EIGEN_NOEXCEPT {return _Cols;}
+ EIGEN_DEVICE_FUNC void conservativeResize(Index,Index,Index) {}
+ EIGEN_DEVICE_FUNC void resize(Index,Index,Index) {}
+ EIGEN_DEVICE_FUNC const T *data() const { return 0; }
+ EIGEN_DEVICE_FUNC T *data() { return 0; }
+};
+
+// more specializations for null matrices; these are necessary to resolve ambiguities
+template<typename T, int _Options> class DenseStorage<T, 0, Dynamic, Dynamic, _Options>
+: public DenseStorage<T, 0, 0, 0, _Options> { };
+
+template<typename T, int _Rows, int _Options> class DenseStorage<T, 0, _Rows, Dynamic, _Options>
+: public DenseStorage<T, 0, 0, 0, _Options> { };
+
+template<typename T, int _Cols, int _Options> class DenseStorage<T, 0, Dynamic, _Cols, _Options>
+: public DenseStorage<T, 0, 0, 0, _Options> { };
+
+// dynamic-size matrix with fixed-size storage
+template<typename T, int Size, int _Options> class DenseStorage<T, Size, Dynamic, Dynamic, _Options>
+{
+ internal::plain_array<T,Size,_Options> m_data;
+ Index m_rows;
+ Index m_cols;
+ public:
+ EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0), m_cols(0) {}
+ EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
+ : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
+ EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
+ : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(other.m_rows), m_cols(other.m_cols)
+ {
+ internal::plain_array_helper::copy(other.m_data, m_rows * m_cols, m_data);
+ }
+ EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
+ {
+ if (this != &other)
+ {
+ m_rows = other.m_rows;
+ m_cols = other.m_cols;
+ internal::plain_array_helper::copy(other.m_data, m_rows * m_cols, m_data);
+ }
+ return *this;
+ }
+ EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index cols) : m_rows(rows), m_cols(cols) {}
+ EIGEN_DEVICE_FUNC void swap(DenseStorage& other)
+ {
+ internal::plain_array_helper::swap(m_data, m_rows * m_cols, other.m_data, other.m_rows * other.m_cols);
+ numext::swap(m_rows,other.m_rows);
+ numext::swap(m_cols,other.m_cols);
+ }
+ EIGEN_DEVICE_FUNC Index rows() const {return m_rows;}
+ EIGEN_DEVICE_FUNC Index cols() const {return m_cols;}
+ EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index cols) { m_rows = rows; m_cols = cols; }
+ EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index cols) { m_rows = rows; m_cols = cols; }
+ EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
+ EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
+};
+
+// dynamic-size matrix with fixed-size storage and fixed width
+template<typename T, int Size, int _Cols, int _Options> class DenseStorage<T, Size, Dynamic, _Cols, _Options>
+{
+ internal::plain_array<T,Size,_Options> m_data;
+ Index m_rows;
+ public:
+ EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0) {}
+ EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
+ : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {}
+ EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
+ : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(other.m_rows)
+ {
+ internal::plain_array_helper::copy(other.m_data, m_rows * _Cols, m_data);
+ }
+
+ EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
+ {
+ if (this != &other)
+ {
+ m_rows = other.m_rows;
+ internal::plain_array_helper::copy(other.m_data, m_rows * _Cols, m_data);
+ }
+ return *this;
+ }
+ EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index) : m_rows(rows) {}
+ EIGEN_DEVICE_FUNC void swap(DenseStorage& other)
+ {
+ internal::plain_array_helper::swap(m_data, m_rows * _Cols, other.m_data, other.m_rows * _Cols);
+ numext::swap(m_rows, other.m_rows);
+ }
+ EIGEN_DEVICE_FUNC Index rows(void) const EIGEN_NOEXCEPT {return m_rows;}
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols(void) const EIGEN_NOEXCEPT {return _Cols;}
+ EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index) { m_rows = rows; }
+ EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index) { m_rows = rows; }
+ EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
+ EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
+};
+
+// dynamic-size matrix with fixed-size storage and fixed height
+template<typename T, int Size, int _Rows, int _Options> class DenseStorage<T, Size, _Rows, Dynamic, _Options>
+{
+ internal::plain_array<T,Size,_Options> m_data;
+ Index m_cols;
+ public:
+ EIGEN_DEVICE_FUNC DenseStorage() : m_cols(0) {}
+ EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
+ : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {}
+ EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
+ : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(other.m_cols)
+ {
+ internal::plain_array_helper::copy(other.m_data, _Rows * m_cols, m_data);
+ }
+ EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
+ {
+ if (this != &other)
+ {
+ m_cols = other.m_cols;
+ internal::plain_array_helper::copy(other.m_data, _Rows * m_cols, m_data);
+ }
+ return *this;
+ }
+ EIGEN_DEVICE_FUNC DenseStorage(Index, Index, Index cols) : m_cols(cols) {}
+ EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
+ internal::plain_array_helper::swap(m_data, _Rows * m_cols, other.m_data, _Rows * other.m_cols);
+ numext::swap(m_cols, other.m_cols);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows(void) const EIGEN_NOEXCEPT {return _Rows;}
+ EIGEN_DEVICE_FUNC Index cols(void) const EIGEN_NOEXCEPT {return m_cols;}
+ EIGEN_DEVICE_FUNC void conservativeResize(Index, Index, Index cols) { m_cols = cols; }
+ EIGEN_DEVICE_FUNC void resize(Index, Index, Index cols) { m_cols = cols; }
+ EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
+ EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
+};
+
+// purely dynamic matrix.
+template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynamic, _Options>
+{
+ T *m_data;
+ Index m_rows;
+ Index m_cols;
+ public:
+ EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0), m_cols(0) {}
+ EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
+ : m_data(0), m_rows(0), m_cols(0) {}
+ EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols)
+ : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols)
+ {
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
+ eigen_internal_assert(size==rows*cols && rows>=0 && cols >=0);
+ }
+ EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
+ : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(other.m_rows*other.m_cols))
+ , m_rows(other.m_rows)
+ , m_cols(other.m_cols)
+ {
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows*m_cols)
+ internal::smart_copy(other.m_data, other.m_data+other.m_rows*other.m_cols, m_data);
+ }
+ EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
+ {
+ if (this != &other)
+ {
+ DenseStorage tmp(other);
+ this->swap(tmp);
+ }
+ return *this;
+ }
+#if EIGEN_HAS_RVALUE_REFERENCES
+ EIGEN_DEVICE_FUNC
+ DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
+ : m_data(std::move(other.m_data))
+ , m_rows(std::move(other.m_rows))
+ , m_cols(std::move(other.m_cols))
+ {
+ other.m_data = nullptr;
+ other.m_rows = 0;
+ other.m_cols = 0;
+ }
+ EIGEN_DEVICE_FUNC
+ DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
+ {
+ numext::swap(m_data, other.m_data);
+ numext::swap(m_rows, other.m_rows);
+ numext::swap(m_cols, other.m_cols);
+ return *this;
+ }
+#endif
+ EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
+ EIGEN_DEVICE_FUNC void swap(DenseStorage& other)
+ {
+ numext::swap(m_data,other.m_data);
+ numext::swap(m_rows,other.m_rows);
+ numext::swap(m_cols,other.m_cols);
+ }
+ EIGEN_DEVICE_FUNC Index rows(void) const EIGEN_NOEXCEPT {return m_rows;}
+ EIGEN_DEVICE_FUNC Index cols(void) const EIGEN_NOEXCEPT {return m_cols;}
+ void conservativeResize(Index size, Index rows, Index cols)
+ {
+ m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
+ m_rows = rows;
+ m_cols = cols;
+ }
+ EIGEN_DEVICE_FUNC void resize(Index size, Index rows, Index cols)
+ {
+ if(size != m_rows*m_cols)
+ {
+ internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
+ if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative
+ m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
+ else
+ m_data = 0;
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
+ }
+ m_rows = rows;
+ m_cols = cols;
+ }
+ EIGEN_DEVICE_FUNC const T *data() const { return m_data; }
+ EIGEN_DEVICE_FUNC T *data() { return m_data; }
+};
+
+// matrix with dynamic width and fixed height (so that matrix has dynamic size).
+template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Rows, Dynamic, _Options>
+{
+ T *m_data;
+ Index m_cols;
+ public:
+ EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_cols(0) {}
+ explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
+ EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(cols)
+ {
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
+ eigen_internal_assert(size==rows*cols && rows==_Rows && cols >=0);
+ EIGEN_UNUSED_VARIABLE(rows);
+ }
+ EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
+ : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(_Rows*other.m_cols))
+ , m_cols(other.m_cols)
+ {
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_cols*_Rows)
+ internal::smart_copy(other.m_data, other.m_data+_Rows*m_cols, m_data);
+ }
+ EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
+ {
+ if (this != &other)
+ {
+ DenseStorage tmp(other);
+ this->swap(tmp);
+ }
+ return *this;
+ }
+#if EIGEN_HAS_RVALUE_REFERENCES
+ EIGEN_DEVICE_FUNC
+ DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
+ : m_data(std::move(other.m_data))
+ , m_cols(std::move(other.m_cols))
+ {
+ other.m_data = nullptr;
+ other.m_cols = 0;
+ }
+ EIGEN_DEVICE_FUNC
+ DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
+ {
+ numext::swap(m_data, other.m_data);
+ numext::swap(m_cols, other.m_cols);
+ return *this;
+ }
+#endif
+ EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
+ EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
+ numext::swap(m_data,other.m_data);
+ numext::swap(m_cols,other.m_cols);
+ }
+ EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index rows(void) EIGEN_NOEXCEPT {return _Rows;}
+ EIGEN_DEVICE_FUNC Index cols(void) const EIGEN_NOEXCEPT {return m_cols;}
+ EIGEN_DEVICE_FUNC void conservativeResize(Index size, Index, Index cols)
+ {
+ m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
+ m_cols = cols;
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index, Index cols)
+ {
+ if(size != _Rows*m_cols)
+ {
+ internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
+ if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative
+ m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
+ else
+ m_data = 0;
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
+ }
+ m_cols = cols;
+ }
+ EIGEN_DEVICE_FUNC const T *data() const { return m_data; }
+ EIGEN_DEVICE_FUNC T *data() { return m_data; }
+};
+
+// matrix with dynamic height and fixed width (so that matrix has dynamic size).
+template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dynamic, _Cols, _Options>
+{
+ T *m_data;
+ Index m_rows;
+ public:
+ EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0) {}
+ explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
+ EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows)
+ {
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
+ eigen_internal_assert(size==rows*cols && rows>=0 && cols == _Cols);
+ EIGEN_UNUSED_VARIABLE(cols);
+ }
+ EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
+ : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(other.m_rows*_Cols))
+ , m_rows(other.m_rows)
+ {
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows*_Cols)
+ internal::smart_copy(other.m_data, other.m_data+other.m_rows*_Cols, m_data);
+ }
+ EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
+ {
+ if (this != &other)
+ {
+ DenseStorage tmp(other);
+ this->swap(tmp);
+ }
+ return *this;
+ }
+#if EIGEN_HAS_RVALUE_REFERENCES
+ EIGEN_DEVICE_FUNC
+ DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
+ : m_data(std::move(other.m_data))
+ , m_rows(std::move(other.m_rows))
+ {
+ other.m_data = nullptr;
+ other.m_rows = 0;
+ }
+ EIGEN_DEVICE_FUNC
+ DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
+ {
+ numext::swap(m_data, other.m_data);
+ numext::swap(m_rows, other.m_rows);
+ return *this;
+ }
+#endif
+ EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
+ EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
+ numext::swap(m_data,other.m_data);
+ numext::swap(m_rows,other.m_rows);
+ }
+ EIGEN_DEVICE_FUNC Index rows(void) const EIGEN_NOEXCEPT {return m_rows;}
+ EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index cols(void) {return _Cols;}
+ void conservativeResize(Index size, Index rows, Index)
+ {
+ m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
+ m_rows = rows;
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index rows, Index)
+ {
+ if(size != m_rows*_Cols)
+ {
+ internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
+ if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative
+ m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
+ else
+ m_data = 0;
+ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
+ }
+ m_rows = rows;
+ }
+ EIGEN_DEVICE_FUNC const T *data() const { return m_data; }
+ EIGEN_DEVICE_FUNC T *data() { return m_data; }
+};
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATRIX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Diagonal.h b/src/3rdparty/eigen/Eigen/src/Core/Diagonal.h
new file mode 100644
index 000000000..3112d2c16
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Diagonal.h
@@ -0,0 +1,258 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_DIAGONAL_H
+#define EIGEN_DIAGONAL_H
+
+namespace Eigen {
+
+/** \class Diagonal
+ * \ingroup Core_Module
+ *
+ * \brief Expression of a diagonal/subdiagonal/superdiagonal in a matrix
+ *
+ * \param MatrixType the type of the object in which we are taking a sub/main/super diagonal
+ * \param DiagIndex the index of the sub/super diagonal. The default is 0 and it means the main diagonal.
+ * A positive value means a superdiagonal, a negative value means a subdiagonal.
+ * You can also use DynamicIndex so the index can be set at runtime.
+ *
+ * The matrix is not required to be square.
+ *
+ * This class represents an expression of the main diagonal, or any sub/super diagonal
+ * of a square matrix. It is the return type of MatrixBase::diagonal() and MatrixBase::diagonal(Index) and most of the
+ * time this is the only way it is used.
+ *
+ * \sa MatrixBase::diagonal(), MatrixBase::diagonal(Index)
+ */
+
+namespace internal {
+template<typename MatrixType, int DiagIndex>
+struct traits<Diagonal<MatrixType,DiagIndex> >
+ : traits<MatrixType>
+{
+ typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
+ typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
+ typedef typename MatrixType::StorageKind StorageKind;
+ enum {
+ RowsAtCompileTime = (int(DiagIndex) == DynamicIndex || int(MatrixType::SizeAtCompileTime) == Dynamic) ? Dynamic
+ : (EIGEN_PLAIN_ENUM_MIN(MatrixType::RowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0),
+ MatrixType::ColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))),
+ ColsAtCompileTime = 1,
+ MaxRowsAtCompileTime = int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic
+ : DiagIndex == DynamicIndex ? EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime,
+ MatrixType::MaxColsAtCompileTime)
+ : (EIGEN_PLAIN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0),
+ MatrixType::MaxColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))),
+ MaxColsAtCompileTime = 1,
+ MaskLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
+ Flags = (unsigned int)_MatrixTypeNested::Flags & (RowMajorBit | MaskLvalueBit | DirectAccessBit) & ~RowMajorBit, // FIXME DirectAccessBit should not be handled by expressions
+ MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret,
+ InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1,
+ OuterStrideAtCompileTime = 0
+ };
+};
+}
+
+template<typename MatrixType, int _DiagIndex> class Diagonal
+ : public internal::dense_xpr_base< Diagonal<MatrixType,_DiagIndex> >::type
+{
+ public:
+
+ enum { DiagIndex = _DiagIndex };
+ typedef typename internal::dense_xpr_base<Diagonal>::type Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Diagonal)
+
+ EIGEN_DEVICE_FUNC
+ explicit inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index)
+ {
+ eigen_assert( a_index <= m_matrix.cols() && -a_index <= m_matrix.rows() );
+ }
+
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal)
+
+ EIGEN_DEVICE_FUNC
+ inline Index rows() const
+ {
+ return m_index.value()<0 ? numext::mini<Index>(m_matrix.cols(),m_matrix.rows()+m_index.value())
+ : numext::mini<Index>(m_matrix.rows(),m_matrix.cols()-m_index.value());
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return 1; }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const EIGEN_NOEXCEPT {
+ return m_matrix.outerStride() + 1;
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const EIGEN_NOEXCEPT { return 0; }
+
+ typedef typename internal::conditional<
+ internal::is_lvalue<MatrixType>::value,
+ Scalar,
+ const Scalar
+ >::type ScalarWithConstIfNotLvalue;
+
+ EIGEN_DEVICE_FUNC
+ inline ScalarWithConstIfNotLvalue* data() { return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
+ EIGEN_DEVICE_FUNC
+ inline const Scalar* data() const { return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
+
+ EIGEN_DEVICE_FUNC
+ inline Scalar& coeffRef(Index row, Index)
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
+ return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index row, Index) const
+ {
+ return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline CoeffReturnType coeff(Index row, Index) const
+ {
+ return m_matrix.coeff(row+rowOffset(), row+colOffset());
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline Scalar& coeffRef(Index idx)
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
+ return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index idx) const
+ {
+ return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline CoeffReturnType coeff(Index idx) const
+ {
+ return m_matrix.coeff(idx+rowOffset(), idx+colOffset());
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const typename internal::remove_all<typename MatrixType::Nested>::type&
+ nestedExpression() const
+ {
+ return m_matrix;
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline Index index() const
+ {
+ return m_index.value();
+ }
+
+ protected:
+ typename internal::ref_selector<MatrixType>::non_const_type m_matrix;
+ const internal::variable_if_dynamicindex<Index, DiagIndex> m_index;
+
+ private:
+ // some compilers may fail to optimize std::max etc in case of compile-time constants...
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index absDiagIndex() const EIGEN_NOEXCEPT { return m_index.value()>0 ? m_index.value() : -m_index.value(); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index rowOffset() const EIGEN_NOEXCEPT { return m_index.value()>0 ? 0 : -m_index.value(); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index colOffset() const EIGEN_NOEXCEPT { return m_index.value()>0 ? m_index.value() : 0; }
+ // trigger a compile-time error if someone try to call packet
+ template<int LoadMode> typename MatrixType::PacketReturnType packet(Index) const;
+ template<int LoadMode> typename MatrixType::PacketReturnType packet(Index,Index) const;
+};
+
+/** \returns an expression of the main diagonal of the matrix \c *this
+ *
+ * \c *this is not required to be square.
+ *
+ * Example: \include MatrixBase_diagonal.cpp
+ * Output: \verbinclude MatrixBase_diagonal.out
+ *
+ * \sa class Diagonal */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::DiagonalReturnType
+MatrixBase<Derived>::diagonal()
+{
+ return DiagonalReturnType(derived());
+}
+
+/** This is the const version of diagonal(). */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::ConstDiagonalReturnType
+MatrixBase<Derived>::diagonal() const
+{
+ return ConstDiagonalReturnType(derived());
+}
+
+/** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this
+ *
+ * \c *this is not required to be square.
+ *
+ * The template parameter \a DiagIndex represent a super diagonal if \a DiagIndex > 0
+ * and a sub diagonal otherwise. \a DiagIndex == 0 is equivalent to the main diagonal.
+ *
+ * Example: \include MatrixBase_diagonal_int.cpp
+ * Output: \verbinclude MatrixBase_diagonal_int.out
+ *
+ * \sa MatrixBase::diagonal(), class Diagonal */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::DiagonalDynamicIndexReturnType
+MatrixBase<Derived>::diagonal(Index index)
+{
+ return DiagonalDynamicIndexReturnType(derived(), index);
+}
+
+/** This is the const version of diagonal(Index). */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::ConstDiagonalDynamicIndexReturnType
+MatrixBase<Derived>::diagonal(Index index) const
+{
+ return ConstDiagonalDynamicIndexReturnType(derived(), index);
+}
+
+/** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this
+ *
+ * \c *this is not required to be square.
+ *
+ * The template parameter \a DiagIndex represent a super diagonal if \a DiagIndex > 0
+ * and a sub diagonal otherwise. \a DiagIndex == 0 is equivalent to the main diagonal.
+ *
+ * Example: \include MatrixBase_diagonal_template_int.cpp
+ * Output: \verbinclude MatrixBase_diagonal_template_int.out
+ *
+ * \sa MatrixBase::diagonal(), class Diagonal */
+template<typename Derived>
+template<int Index_>
+EIGEN_DEVICE_FUNC
+inline typename MatrixBase<Derived>::template DiagonalIndexReturnType<Index_>::Type
+MatrixBase<Derived>::diagonal()
+{
+ return typename DiagonalIndexReturnType<Index_>::Type(derived());
+}
+
+/** This is the const version of diagonal<int>(). */
+template<typename Derived>
+template<int Index_>
+EIGEN_DEVICE_FUNC
+inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index_>::Type
+MatrixBase<Derived>::diagonal() const
+{
+ return typename ConstDiagonalIndexReturnType<Index_>::Type(derived());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_DIAGONAL_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/DiagonalMatrix.h b/src/3rdparty/eigen/Eigen/src/Core/DiagonalMatrix.h
new file mode 100644
index 000000000..542685c65
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/DiagonalMatrix.h
@@ -0,0 +1,391 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_DIAGONALMATRIX_H
+#define EIGEN_DIAGONALMATRIX_H
+
+namespace Eigen {
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+template<typename Derived>
+class DiagonalBase : public EigenBase<Derived>
+{
+ public:
+ typedef typename internal::traits<Derived>::DiagonalVectorType DiagonalVectorType;
+ typedef typename DiagonalVectorType::Scalar Scalar;
+ typedef typename DiagonalVectorType::RealScalar RealScalar;
+ typedef typename internal::traits<Derived>::StorageKind StorageKind;
+ typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
+
+ enum {
+ RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
+ ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
+ MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
+ MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
+ IsVectorAtCompileTime = 0,
+ Flags = NoPreferredStorageOrderBit
+ };
+
+ typedef Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, 0, MaxRowsAtCompileTime, MaxColsAtCompileTime> DenseMatrixType;
+ typedef DenseMatrixType DenseType;
+ typedef DiagonalMatrix<Scalar,DiagonalVectorType::SizeAtCompileTime,DiagonalVectorType::MaxSizeAtCompileTime> PlainObject;
+
+ EIGEN_DEVICE_FUNC
+ inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
+ EIGEN_DEVICE_FUNC
+ inline Derived& derived() { return *static_cast<Derived*>(this); }
+
+ EIGEN_DEVICE_FUNC
+ DenseMatrixType toDenseMatrix() const { return derived(); }
+
+ EIGEN_DEVICE_FUNC
+ inline const DiagonalVectorType& diagonal() const { return derived().diagonal(); }
+ EIGEN_DEVICE_FUNC
+ inline DiagonalVectorType& diagonal() { return derived().diagonal(); }
+
+ EIGEN_DEVICE_FUNC
+ inline Index rows() const { return diagonal().size(); }
+ EIGEN_DEVICE_FUNC
+ inline Index cols() const { return diagonal().size(); }
+
+ template<typename MatrixDerived>
+ EIGEN_DEVICE_FUNC
+ const Product<Derived,MatrixDerived,LazyProduct>
+ operator*(const MatrixBase<MatrixDerived> &matrix) const
+ {
+ return Product<Derived, MatrixDerived, LazyProduct>(derived(),matrix.derived());
+ }
+
+ typedef DiagonalWrapper<const CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const DiagonalVectorType> > InverseReturnType;
+ EIGEN_DEVICE_FUNC
+ inline const InverseReturnType
+ inverse() const
+ {
+ return InverseReturnType(diagonal().cwiseInverse());
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const DiagonalWrapper<const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DiagonalVectorType,Scalar,product) >
+ operator*(const Scalar& scalar) const
+ {
+ return DiagonalWrapper<const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DiagonalVectorType,Scalar,product) >(diagonal() * scalar);
+ }
+ EIGEN_DEVICE_FUNC
+ friend inline const DiagonalWrapper<const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,DiagonalVectorType,product) >
+ operator*(const Scalar& scalar, const DiagonalBase& other)
+ {
+ return DiagonalWrapper<const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,DiagonalVectorType,product) >(scalar * other.diagonal());
+ }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ inline unspecified_expression_type
+ #else
+ inline const DiagonalWrapper<const EIGEN_CWISE_BINARY_RETURN_TYPE(DiagonalVectorType,typename OtherDerived::DiagonalVectorType,sum) >
+ #endif
+ operator+(const DiagonalBase<OtherDerived>& other) const
+ {
+ return (diagonal() + other.diagonal()).asDiagonal();
+ }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ inline unspecified_expression_type
+ #else
+ inline const DiagonalWrapper<const EIGEN_CWISE_BINARY_RETURN_TYPE(DiagonalVectorType,typename OtherDerived::DiagonalVectorType,difference) >
+ #endif
+ operator-(const DiagonalBase<OtherDerived>& other) const
+ {
+ return (diagonal() - other.diagonal()).asDiagonal();
+ }
+};
+
+#endif
+
+/** \class DiagonalMatrix
+ * \ingroup Core_Module
+ *
+ * \brief Represents a diagonal matrix with its storage
+ *
+ * \param _Scalar the type of coefficients
+ * \param SizeAtCompileTime the dimension of the matrix, or Dynamic
+ * \param MaxSizeAtCompileTime the dimension of the matrix, or Dynamic. This parameter is optional and defaults
+ * to SizeAtCompileTime. Most of the time, you do not need to specify it.
+ *
+ * \sa class DiagonalWrapper
+ */
+
+namespace internal {
+template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime>
+struct traits<DiagonalMatrix<_Scalar,SizeAtCompileTime,MaxSizeAtCompileTime> >
+ : traits<Matrix<_Scalar,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
+{
+ typedef Matrix<_Scalar,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1> DiagonalVectorType;
+ typedef DiagonalShape StorageKind;
+ enum {
+ Flags = LvalueBit | NoPreferredStorageOrderBit
+ };
+};
+}
+template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime>
+class DiagonalMatrix
+ : public DiagonalBase<DiagonalMatrix<_Scalar,SizeAtCompileTime,MaxSizeAtCompileTime> >
+{
+ public:
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ typedef typename internal::traits<DiagonalMatrix>::DiagonalVectorType DiagonalVectorType;
+ typedef const DiagonalMatrix& Nested;
+ typedef _Scalar Scalar;
+ typedef typename internal::traits<DiagonalMatrix>::StorageKind StorageKind;
+ typedef typename internal::traits<DiagonalMatrix>::StorageIndex StorageIndex;
+ #endif
+
+ protected:
+
+ DiagonalVectorType m_diagonal;
+
+ public:
+
+ /** const version of diagonal(). */
+ EIGEN_DEVICE_FUNC
+ inline const DiagonalVectorType& diagonal() const { return m_diagonal; }
+ /** \returns a reference to the stored vector of diagonal coefficients. */
+ EIGEN_DEVICE_FUNC
+ inline DiagonalVectorType& diagonal() { return m_diagonal; }
+
+ /** Default constructor without initialization */
+ EIGEN_DEVICE_FUNC
+ inline DiagonalMatrix() {}
+
+ /** Constructs a diagonal matrix with given dimension */
+ EIGEN_DEVICE_FUNC
+ explicit inline DiagonalMatrix(Index dim) : m_diagonal(dim) {}
+
+ /** 2D constructor. */
+ EIGEN_DEVICE_FUNC
+ inline DiagonalMatrix(const Scalar& x, const Scalar& y) : m_diagonal(x,y) {}
+
+ /** 3D constructor. */
+ EIGEN_DEVICE_FUNC
+ inline DiagonalMatrix(const Scalar& x, const Scalar& y, const Scalar& z) : m_diagonal(x,y,z) {}
+
+ #if EIGEN_HAS_CXX11
+ /** \brief Construct a diagonal matrix with fixed size from an arbitrary number of coefficients. \cpp11
+ *
+ * There exists C++98 anologue constructors for fixed-size diagonal matrices having 2 or 3 coefficients.
+ *
+ * \warning To construct a diagonal matrix of fixed size, the number of values passed to this
+ * constructor must match the fixed dimension of \c *this.
+ *
+ * \sa DiagonalMatrix(const Scalar&, const Scalar&)
+ * \sa DiagonalMatrix(const Scalar&, const Scalar&, const Scalar&)
+ */
+ template <typename... ArgTypes>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ DiagonalMatrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const ArgTypes&... args)
+ : m_diagonal(a0, a1, a2, args...) {}
+
+ /** \brief Constructs a DiagonalMatrix and initializes it by elements given by an initializer list of initializer
+ * lists \cpp11
+ */
+ EIGEN_DEVICE_FUNC
+ explicit EIGEN_STRONG_INLINE DiagonalMatrix(const std::initializer_list<std::initializer_list<Scalar>>& list)
+ : m_diagonal(list) {}
+ #endif // EIGEN_HAS_CXX11
+
+ /** Copy constructor. */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ inline DiagonalMatrix(const DiagonalBase<OtherDerived>& other) : m_diagonal(other.diagonal()) {}
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ /** copy constructor. prevent a default copy constructor from hiding the other templated constructor */
+ inline DiagonalMatrix(const DiagonalMatrix& other) : m_diagonal(other.diagonal()) {}
+ #endif
+
+ /** generic constructor from expression of the diagonal coefficients */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ explicit inline DiagonalMatrix(const MatrixBase<OtherDerived>& other) : m_diagonal(other)
+ {}
+
+ /** Copy operator. */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ DiagonalMatrix& operator=(const DiagonalBase<OtherDerived>& other)
+ {
+ m_diagonal = other.diagonal();
+ return *this;
+ }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ /** This is a special case of the templated operator=. Its purpose is to
+ * prevent a default operator= from hiding the templated operator=.
+ */
+ EIGEN_DEVICE_FUNC
+ DiagonalMatrix& operator=(const DiagonalMatrix& other)
+ {
+ m_diagonal = other.diagonal();
+ return *this;
+ }
+ #endif
+
+ /** Resizes to given size. */
+ EIGEN_DEVICE_FUNC
+ inline void resize(Index size) { m_diagonal.resize(size); }
+ /** Sets all coefficients to zero. */
+ EIGEN_DEVICE_FUNC
+ inline void setZero() { m_diagonal.setZero(); }
+ /** Resizes and sets all coefficients to zero. */
+ EIGEN_DEVICE_FUNC
+ inline void setZero(Index size) { m_diagonal.setZero(size); }
+ /** Sets this matrix to be the identity matrix of the current size. */
+ EIGEN_DEVICE_FUNC
+ inline void setIdentity() { m_diagonal.setOnes(); }
+ /** Sets this matrix to be the identity matrix of the given size. */
+ EIGEN_DEVICE_FUNC
+ inline void setIdentity(Index size) { m_diagonal.setOnes(size); }
+};
+
+/** \class DiagonalWrapper
+ * \ingroup Core_Module
+ *
+ * \brief Expression of a diagonal matrix
+ *
+ * \param _DiagonalVectorType the type of the vector of diagonal coefficients
+ *
+ * This class is an expression of a diagonal matrix, but not storing its own vector of diagonal coefficients,
+ * instead wrapping an existing vector expression. It is the return type of MatrixBase::asDiagonal()
+ * and most of the time this is the only way that it is used.
+ *
+ * \sa class DiagonalMatrix, class DiagonalBase, MatrixBase::asDiagonal()
+ */
+
+namespace internal {
+template<typename _DiagonalVectorType>
+struct traits<DiagonalWrapper<_DiagonalVectorType> >
+{
+ typedef _DiagonalVectorType DiagonalVectorType;
+ typedef typename DiagonalVectorType::Scalar Scalar;
+ typedef typename DiagonalVectorType::StorageIndex StorageIndex;
+ typedef DiagonalShape StorageKind;
+ typedef typename traits<DiagonalVectorType>::XprKind XprKind;
+ enum {
+ RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
+ ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
+ MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
+ MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
+ Flags = (traits<DiagonalVectorType>::Flags & LvalueBit) | NoPreferredStorageOrderBit
+ };
+};
+}
+
+template<typename _DiagonalVectorType>
+class DiagonalWrapper
+ : public DiagonalBase<DiagonalWrapper<_DiagonalVectorType> >, internal::no_assignment_operator
+{
+ public:
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ typedef _DiagonalVectorType DiagonalVectorType;
+ typedef DiagonalWrapper Nested;
+ #endif
+
+ /** Constructor from expression of diagonal coefficients to wrap. */
+ EIGEN_DEVICE_FUNC
+ explicit inline DiagonalWrapper(DiagonalVectorType& a_diagonal) : m_diagonal(a_diagonal) {}
+
+ /** \returns a const reference to the wrapped expression of diagonal coefficients. */
+ EIGEN_DEVICE_FUNC
+ const DiagonalVectorType& diagonal() const { return m_diagonal; }
+
+ protected:
+ typename DiagonalVectorType::Nested m_diagonal;
+};
+
+/** \returns a pseudo-expression of a diagonal matrix with *this as vector of diagonal coefficients
+ *
+ * \only_for_vectors
+ *
+ * Example: \include MatrixBase_asDiagonal.cpp
+ * Output: \verbinclude MatrixBase_asDiagonal.out
+ *
+ * \sa class DiagonalWrapper, class DiagonalMatrix, diagonal(), isDiagonal()
+ **/
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline const DiagonalWrapper<const Derived>
+MatrixBase<Derived>::asDiagonal() const
+{
+ return DiagonalWrapper<const Derived>(derived());
+}
+
+/** \returns true if *this is approximately equal to a diagonal matrix,
+ * within the precision given by \a prec.
+ *
+ * Example: \include MatrixBase_isDiagonal.cpp
+ * Output: \verbinclude MatrixBase_isDiagonal.out
+ *
+ * \sa asDiagonal()
+ */
+template<typename Derived>
+bool MatrixBase<Derived>::isDiagonal(const RealScalar& prec) const
+{
+ if(cols() != rows()) return false;
+ RealScalar maxAbsOnDiagonal = static_cast<RealScalar>(-1);
+ for(Index j = 0; j < cols(); ++j)
+ {
+ RealScalar absOnDiagonal = numext::abs(coeff(j,j));
+ if(absOnDiagonal > maxAbsOnDiagonal) maxAbsOnDiagonal = absOnDiagonal;
+ }
+ for(Index j = 0; j < cols(); ++j)
+ for(Index i = 0; i < j; ++i)
+ {
+ if(!internal::isMuchSmallerThan(coeff(i, j), maxAbsOnDiagonal, prec)) return false;
+ if(!internal::isMuchSmallerThan(coeff(j, i), maxAbsOnDiagonal, prec)) return false;
+ }
+ return true;
+}
+
+namespace internal {
+
+template<> struct storage_kind_to_shape<DiagonalShape> { typedef DiagonalShape Shape; };
+
+struct Diagonal2Dense {};
+
+template<> struct AssignmentKind<DenseShape,DiagonalShape> { typedef Diagonal2Dense Kind; };
+
+// Diagonal matrix to Dense assignment
+template< typename DstXprType, typename SrcXprType, typename Functor>
+struct Assignment<DstXprType, SrcXprType, Functor, Diagonal2Dense>
+{
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+
+ dst.setZero();
+ dst.diagonal() = src.diagonal();
+ }
+
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/)
+ { dst.diagonal() += src.diagonal(); }
+
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/)
+ { dst.diagonal() -= src.diagonal(); }
+};
+
+} // namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_DIAGONALMATRIX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/DiagonalProduct.h b/src/3rdparty/eigen/Eigen/src/Core/DiagonalProduct.h
new file mode 100644
index 000000000..7911d1cd1
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/DiagonalProduct.h
@@ -0,0 +1,28 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_DIAGONALPRODUCT_H
+#define EIGEN_DIAGONALPRODUCT_H
+
+namespace Eigen {
+
+/** \returns the diagonal matrix product of \c *this by the diagonal matrix \a diagonal.
+ */
+template<typename Derived>
+template<typename DiagonalDerived>
+EIGEN_DEVICE_FUNC inline const Product<Derived, DiagonalDerived, LazyProduct>
+MatrixBase<Derived>::operator*(const DiagonalBase<DiagonalDerived> &a_diagonal) const
+{
+ return Product<Derived, DiagonalDerived, LazyProduct>(derived(),a_diagonal.derived());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_DIAGONALPRODUCT_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Dot.h b/src/3rdparty/eigen/Eigen/src/Core/Dot.h
new file mode 100644
index 000000000..5c3441b92
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Dot.h
@@ -0,0 +1,318 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2008, 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_DOT_H
+#define EIGEN_DOT_H
+
+namespace Eigen {
+
+namespace internal {
+
+// helper function for dot(). The problem is that if we put that in the body of dot(), then upon calling dot
+// with mismatched types, the compiler emits errors about failing to instantiate cwiseProduct BEFORE
+// looking at the static assertions. Thus this is a trick to get better compile errors.
+template<typename T, typename U,
+// the NeedToTranspose condition here is taken straight from Assign.h
+ bool NeedToTranspose = T::IsVectorAtCompileTime
+ && U::IsVectorAtCompileTime
+ && ((int(T::RowsAtCompileTime) == 1 && int(U::ColsAtCompileTime) == 1)
+ | // FIXME | instead of || to please GCC 4.4.0 stupid warning "suggest parentheses around &&".
+ // revert to || as soon as not needed anymore.
+ (int(T::ColsAtCompileTime) == 1 && int(U::RowsAtCompileTime) == 1))
+>
+struct dot_nocheck
+{
+ typedef scalar_conj_product_op<typename traits<T>::Scalar,typename traits<U>::Scalar> conj_prod;
+ typedef typename conj_prod::result_type ResScalar;
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE
+ static ResScalar run(const MatrixBase<T>& a, const MatrixBase<U>& b)
+ {
+ return a.template binaryExpr<conj_prod>(b).sum();
+ }
+};
+
+template<typename T, typename U>
+struct dot_nocheck<T, U, true>
+{
+ typedef scalar_conj_product_op<typename traits<T>::Scalar,typename traits<U>::Scalar> conj_prod;
+ typedef typename conj_prod::result_type ResScalar;
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE
+ static ResScalar run(const MatrixBase<T>& a, const MatrixBase<U>& b)
+ {
+ return a.transpose().template binaryExpr<conj_prod>(b).sum();
+ }
+};
+
+} // end namespace internal
+
+/** \fn MatrixBase::dot
+ * \returns the dot product of *this with other.
+ *
+ * \only_for_vectors
+ *
+ * \note If the scalar type is complex numbers, then this function returns the hermitian
+ * (sesquilinear) dot product, conjugate-linear in the first variable and linear in the
+ * second variable.
+ *
+ * \sa squaredNorm(), norm()
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE
+typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType
+MatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
+ EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived)
+#if !(defined(EIGEN_NO_STATIC_ASSERT) && defined(EIGEN_NO_DEBUG))
+ typedef internal::scalar_conj_product_op<Scalar,typename OtherDerived::Scalar> func;
+ EIGEN_CHECK_BINARY_COMPATIBILIY(func,Scalar,typename OtherDerived::Scalar);
+#endif
+
+ eigen_assert(size() == other.size());
+
+ return internal::dot_nocheck<Derived,OtherDerived>::run(*this, other);
+}
+
+//---------- implementation of L2 norm and related functions ----------
+
+/** \returns, for vectors, the squared \em l2 norm of \c *this, and for matrices the squared Frobenius norm.
+ * In both cases, it consists in the sum of the square of all the matrix entries.
+ * For vectors, this is also equals to the dot product of \c *this with itself.
+ *
+ * \sa dot(), norm(), lpNorm()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename NumTraits<typename internal::traits<Derived>::Scalar>::Real MatrixBase<Derived>::squaredNorm() const
+{
+ return numext::real((*this).cwiseAbs2().sum());
+}
+
+/** \returns, for vectors, the \em l2 norm of \c *this, and for matrices the Frobenius norm.
+ * In both cases, it consists in the square root of the sum of the square of all the matrix entries.
+ * For vectors, this is also equals to the square root of the dot product of \c *this with itself.
+ *
+ * \sa lpNorm(), dot(), squaredNorm()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename NumTraits<typename internal::traits<Derived>::Scalar>::Real MatrixBase<Derived>::norm() const
+{
+ return numext::sqrt(squaredNorm());
+}
+
+/** \returns an expression of the quotient of \c *this by its own norm.
+ *
+ * \warning If the input vector is too small (i.e., this->norm()==0),
+ * then this function returns a copy of the input.
+ *
+ * \only_for_vectors
+ *
+ * \sa norm(), normalize()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::PlainObject
+MatrixBase<Derived>::normalized() const
+{
+ typedef typename internal::nested_eval<Derived,2>::type _Nested;
+ _Nested n(derived());
+ RealScalar z = n.squaredNorm();
+ // NOTE: after extensive benchmarking, this conditional does not impact performance, at least on recent x86 CPU
+ if(z>RealScalar(0))
+ return n / numext::sqrt(z);
+ else
+ return n;
+}
+
+/** Normalizes the vector, i.e. divides it by its own norm.
+ *
+ * \only_for_vectors
+ *
+ * \warning If the input vector is too small (i.e., this->norm()==0), then \c *this is left unchanged.
+ *
+ * \sa norm(), normalized()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void MatrixBase<Derived>::normalize()
+{
+ RealScalar z = squaredNorm();
+ // NOTE: after extensive benchmarking, this conditional does not impact performance, at least on recent x86 CPU
+ if(z>RealScalar(0))
+ derived() /= numext::sqrt(z);
+}
+
+/** \returns an expression of the quotient of \c *this by its own norm while avoiding underflow and overflow.
+ *
+ * \only_for_vectors
+ *
+ * This method is analogue to the normalized() method, but it reduces the risk of
+ * underflow and overflow when computing the norm.
+ *
+ * \warning If the input vector is too small (i.e., this->norm()==0),
+ * then this function returns a copy of the input.
+ *
+ * \sa stableNorm(), stableNormalize(), normalized()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::PlainObject
+MatrixBase<Derived>::stableNormalized() const
+{
+ typedef typename internal::nested_eval<Derived,3>::type _Nested;
+ _Nested n(derived());
+ RealScalar w = n.cwiseAbs().maxCoeff();
+ RealScalar z = (n/w).squaredNorm();
+ if(z>RealScalar(0))
+ return n / (numext::sqrt(z)*w);
+ else
+ return n;
+}
+
+/** Normalizes the vector while avoid underflow and overflow
+ *
+ * \only_for_vectors
+ *
+ * This method is analogue to the normalize() method, but it reduces the risk of
+ * underflow and overflow when computing the norm.
+ *
+ * \warning If the input vector is too small (i.e., this->norm()==0), then \c *this is left unchanged.
+ *
+ * \sa stableNorm(), stableNormalized(), normalize()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void MatrixBase<Derived>::stableNormalize()
+{
+ RealScalar w = cwiseAbs().maxCoeff();
+ RealScalar z = (derived()/w).squaredNorm();
+ if(z>RealScalar(0))
+ derived() /= numext::sqrt(z)*w;
+}
+
+//---------- implementation of other norms ----------
+
+namespace internal {
+
+template<typename Derived, int p>
+struct lpNorm_selector
+{
+ typedef typename NumTraits<typename traits<Derived>::Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const MatrixBase<Derived>& m)
+ {
+ EIGEN_USING_STD(pow)
+ return pow(m.cwiseAbs().array().pow(p).sum(), RealScalar(1)/p);
+ }
+};
+
+template<typename Derived>
+struct lpNorm_selector<Derived, 1>
+{
+ EIGEN_DEVICE_FUNC
+ static inline typename NumTraits<typename traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m)
+ {
+ return m.cwiseAbs().sum();
+ }
+};
+
+template<typename Derived>
+struct lpNorm_selector<Derived, 2>
+{
+ EIGEN_DEVICE_FUNC
+ static inline typename NumTraits<typename traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m)
+ {
+ return m.norm();
+ }
+};
+
+template<typename Derived>
+struct lpNorm_selector<Derived, Infinity>
+{
+ typedef typename NumTraits<typename traits<Derived>::Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const MatrixBase<Derived>& m)
+ {
+ if(Derived::SizeAtCompileTime==0 || (Derived::SizeAtCompileTime==Dynamic && m.size()==0))
+ return RealScalar(0);
+ return m.cwiseAbs().maxCoeff();
+ }
+};
+
+} // end namespace internal
+
+/** \returns the \b coefficient-wise \f$ \ell^p \f$ norm of \c *this, that is, returns the p-th root of the sum of the p-th powers of the absolute values
+ * of the coefficients of \c *this. If \a p is the special value \a Eigen::Infinity, this function returns the \f$ \ell^\infty \f$
+ * norm, that is the maximum of the absolute values of the coefficients of \c *this.
+ *
+ * In all cases, if \c *this is empty, then the value 0 is returned.
+ *
+ * \note For matrices, this function does not compute the <a href="https://en.wikipedia.org/wiki/Operator_norm">operator-norm</a>. That is, if \c *this is a matrix, then its coefficients are interpreted as a 1D vector. Nonetheless, you can easily compute the 1-norm and \f$\infty\f$-norm matrix operator norms using \link TutorialReductionsVisitorsBroadcastingReductionsNorm partial reductions \endlink.
+ *
+ * \sa norm()
+ */
+template<typename Derived>
+template<int p>
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+EIGEN_DEVICE_FUNC inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real
+#else
+EIGEN_DEVICE_FUNC MatrixBase<Derived>::RealScalar
+#endif
+MatrixBase<Derived>::lpNorm() const
+{
+ return internal::lpNorm_selector<Derived, p>::run(*this);
+}
+
+//---------- implementation of isOrthogonal / isUnitary ----------
+
+/** \returns true if *this is approximately orthogonal to \a other,
+ * within the precision given by \a prec.
+ *
+ * Example: \include MatrixBase_isOrthogonal.cpp
+ * Output: \verbinclude MatrixBase_isOrthogonal.out
+ */
+template<typename Derived>
+template<typename OtherDerived>
+bool MatrixBase<Derived>::isOrthogonal
+(const MatrixBase<OtherDerived>& other, const RealScalar& prec) const
+{
+ typename internal::nested_eval<Derived,2>::type nested(derived());
+ typename internal::nested_eval<OtherDerived,2>::type otherNested(other.derived());
+ return numext::abs2(nested.dot(otherNested)) <= prec * prec * nested.squaredNorm() * otherNested.squaredNorm();
+}
+
+/** \returns true if *this is approximately an unitary matrix,
+ * within the precision given by \a prec. In the case where the \a Scalar
+ * type is real numbers, a unitary matrix is an orthogonal matrix, whence the name.
+ *
+ * \note This can be used to check whether a family of vectors forms an orthonormal basis.
+ * Indeed, \c m.isUnitary() returns true if and only if the columns (equivalently, the rows) of m form an
+ * orthonormal basis.
+ *
+ * Example: \include MatrixBase_isUnitary.cpp
+ * Output: \verbinclude MatrixBase_isUnitary.out
+ */
+template<typename Derived>
+bool MatrixBase<Derived>::isUnitary(const RealScalar& prec) const
+{
+ typename internal::nested_eval<Derived,1>::type self(derived());
+ for(Index i = 0; i < cols(); ++i)
+ {
+ if(!internal::isApprox(self.col(i).squaredNorm(), static_cast<RealScalar>(1), prec))
+ return false;
+ for(Index j = 0; j < i; ++j)
+ if(!internal::isMuchSmallerThan(self.col(i).dot(self.col(j)), static_cast<Scalar>(1), prec))
+ return false;
+ }
+ return true;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_DOT_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/EigenBase.h b/src/3rdparty/eigen/Eigen/src/Core/EigenBase.h
new file mode 100644
index 000000000..6b3c7d374
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/EigenBase.h
@@ -0,0 +1,160 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_EIGENBASE_H
+#define EIGEN_EIGENBASE_H
+
+namespace Eigen {
+
+/** \class EigenBase
+ * \ingroup Core_Module
+ *
+ * Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T).
+ *
+ * In other words, an EigenBase object is an object that can be copied into a MatrixBase.
+ *
+ * Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc.
+ *
+ * Notice that this class is trivial, it is only used to disambiguate overloaded functions.
+ *
+ * \sa \blank \ref TopicClassHierarchy
+ */
+template<typename Derived> struct EigenBase
+{
+// typedef typename internal::plain_matrix_type<Derived>::type PlainObject;
+
+ /** \brief The interface type of indices
+ * \details To change this, \c \#define the preprocessor symbol \c EIGEN_DEFAULT_DENSE_INDEX_TYPE.
+ * \sa StorageIndex, \ref TopicPreprocessorDirectives.
+ * DEPRECATED: Since Eigen 3.3, its usage is deprecated. Use Eigen::Index instead.
+ * Deprecation is not marked with a doxygen comment because there are too many existing usages to add the deprecation attribute.
+ */
+ typedef Eigen::Index Index;
+
+ // FIXME is it needed?
+ typedef typename internal::traits<Derived>::StorageKind StorageKind;
+
+ /** \returns a reference to the derived object */
+ EIGEN_DEVICE_FUNC
+ Derived& derived() { return *static_cast<Derived*>(this); }
+ /** \returns a const reference to the derived object */
+ EIGEN_DEVICE_FUNC
+ const Derived& derived() const { return *static_cast<const Derived*>(this); }
+
+ EIGEN_DEVICE_FUNC
+ inline Derived& const_cast_derived() const
+ { return *static_cast<Derived*>(const_cast<EigenBase*>(this)); }
+ EIGEN_DEVICE_FUNC
+ inline const Derived& const_derived() const
+ { return *static_cast<const Derived*>(this); }
+
+ /** \returns the number of rows. \sa cols(), RowsAtCompileTime */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return derived().rows(); }
+ /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return derived().cols(); }
+ /** \returns the number of coefficients, which is rows()*cols().
+ * \sa rows(), cols(), SizeAtCompileTime. */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index size() const EIGEN_NOEXCEPT { return rows() * cols(); }
+
+ /** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */
+ template<typename Dest>
+ EIGEN_DEVICE_FUNC
+ inline void evalTo(Dest& dst) const
+ { derived().evalTo(dst); }
+
+ /** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */
+ template<typename Dest>
+ EIGEN_DEVICE_FUNC
+ inline void addTo(Dest& dst) const
+ {
+ // This is the default implementation,
+ // derived class can reimplement it in a more optimized way.
+ typename Dest::PlainObject res(rows(),cols());
+ evalTo(res);
+ dst += res;
+ }
+
+ /** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */
+ template<typename Dest>
+ EIGEN_DEVICE_FUNC
+ inline void subTo(Dest& dst) const
+ {
+ // This is the default implementation,
+ // derived class can reimplement it in a more optimized way.
+ typename Dest::PlainObject res(rows(),cols());
+ evalTo(res);
+ dst -= res;
+ }
+
+ /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */
+ template<typename Dest>
+ EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const
+ {
+ // This is the default implementation,
+ // derived class can reimplement it in a more optimized way.
+ dst = dst * this->derived();
+ }
+
+ /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */
+ template<typename Dest>
+ EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const
+ {
+ // This is the default implementation,
+ // derived class can reimplement it in a more optimized way.
+ dst = this->derived() * dst;
+ }
+
+};
+
+/***************************************************************************
+* Implementation of matrix base methods
+***************************************************************************/
+
+/** \brief Copies the generic expression \a other into *this.
+ *
+ * \details The expression must provide a (templated) evalTo(Derived& dst) const
+ * function which does the actual job. In practice, this allows any user to write
+ * its own special matrix without having to modify MatrixBase
+ *
+ * \returns a reference to *this.
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+Derived& DenseBase<Derived>::operator=(const EigenBase<OtherDerived> &other)
+{
+ call_assignment(derived(), other.derived());
+ return derived();
+}
+
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+Derived& DenseBase<Derived>::operator+=(const EigenBase<OtherDerived> &other)
+{
+ call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
+ return derived();
+}
+
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived> &other)
+{
+ call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
+ return derived();
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_EIGENBASE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/ForceAlignedAccess.h b/src/3rdparty/eigen/Eigen/src/Core/ForceAlignedAccess.h
new file mode 100644
index 000000000..817a43afc
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/ForceAlignedAccess.h
@@ -0,0 +1,150 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_FORCEALIGNEDACCESS_H
+#define EIGEN_FORCEALIGNEDACCESS_H
+
+namespace Eigen {
+
+/** \class ForceAlignedAccess
+ * \ingroup Core_Module
+ *
+ * \brief Enforce aligned packet loads and stores regardless of what is requested
+ *
+ * \param ExpressionType the type of the object of which we are forcing aligned packet access
+ *
+ * This class is the return type of MatrixBase::forceAlignedAccess()
+ * and most of the time this is the only way it is used.
+ *
+ * \sa MatrixBase::forceAlignedAccess()
+ */
+
+namespace internal {
+template<typename ExpressionType>
+struct traits<ForceAlignedAccess<ExpressionType> > : public traits<ExpressionType>
+{};
+}
+
+template<typename ExpressionType> class ForceAlignedAccess
+ : public internal::dense_xpr_base< ForceAlignedAccess<ExpressionType> >::type
+{
+ public:
+
+ typedef typename internal::dense_xpr_base<ForceAlignedAccess>::type Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(ForceAlignedAccess)
+
+ EIGEN_DEVICE_FUNC explicit inline ForceAlignedAccess(const ExpressionType& matrix) : m_expression(matrix) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
+
+ EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index row, Index col) const
+ {
+ return m_expression.coeff(row, col);
+ }
+
+ EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index row, Index col)
+ {
+ return m_expression.const_cast_derived().coeffRef(row, col);
+ }
+
+ EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index index) const
+ {
+ return m_expression.coeff(index);
+ }
+
+ EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index index)
+ {
+ return m_expression.const_cast_derived().coeffRef(index);
+ }
+
+ template<int LoadMode>
+ inline const PacketScalar packet(Index row, Index col) const
+ {
+ return m_expression.template packet<Aligned>(row, col);
+ }
+
+ template<int LoadMode>
+ inline void writePacket(Index row, Index col, const PacketScalar& x)
+ {
+ m_expression.const_cast_derived().template writePacket<Aligned>(row, col, x);
+ }
+
+ template<int LoadMode>
+ inline const PacketScalar packet(Index index) const
+ {
+ return m_expression.template packet<Aligned>(index);
+ }
+
+ template<int LoadMode>
+ inline void writePacket(Index index, const PacketScalar& x)
+ {
+ m_expression.const_cast_derived().template writePacket<Aligned>(index, x);
+ }
+
+ EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; }
+
+ protected:
+ const ExpressionType& m_expression;
+
+ private:
+ ForceAlignedAccess& operator=(const ForceAlignedAccess&);
+};
+
+/** \returns an expression of *this with forced aligned access
+ * \sa forceAlignedAccessIf(),class ForceAlignedAccess
+ */
+template<typename Derived>
+inline const ForceAlignedAccess<Derived>
+MatrixBase<Derived>::forceAlignedAccess() const
+{
+ return ForceAlignedAccess<Derived>(derived());
+}
+
+/** \returns an expression of *this with forced aligned access
+ * \sa forceAlignedAccessIf(), class ForceAlignedAccess
+ */
+template<typename Derived>
+inline ForceAlignedAccess<Derived>
+MatrixBase<Derived>::forceAlignedAccess()
+{
+ return ForceAlignedAccess<Derived>(derived());
+}
+
+/** \returns an expression of *this with forced aligned access if \a Enable is true.
+ * \sa forceAlignedAccess(), class ForceAlignedAccess
+ */
+template<typename Derived>
+template<bool Enable>
+inline typename internal::add_const_on_value_type<typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type>::type
+MatrixBase<Derived>::forceAlignedAccessIf() const
+{
+ return derived(); // FIXME This should not work but apparently is never used
+}
+
+/** \returns an expression of *this with forced aligned access if \a Enable is true.
+ * \sa forceAlignedAccess(), class ForceAlignedAccess
+ */
+template<typename Derived>
+template<bool Enable>
+inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type
+MatrixBase<Derived>::forceAlignedAccessIf()
+{
+ return derived(); // FIXME This should not work but apparently is never used
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_FORCEALIGNEDACCESS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Fuzzy.h b/src/3rdparty/eigen/Eigen/src/Core/Fuzzy.h
new file mode 100644
index 000000000..43aa49b2b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Fuzzy.h
@@ -0,0 +1,155 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_FUZZY_H
+#define EIGEN_FUZZY_H
+
+namespace Eigen {
+
+namespace internal
+{
+
+template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
+struct isApprox_selector
+{
+ EIGEN_DEVICE_FUNC
+ static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec)
+ {
+ typename internal::nested_eval<Derived,2>::type nested(x);
+ typename internal::nested_eval<OtherDerived,2>::type otherNested(y);
+ return (nested - otherNested).cwiseAbs2().sum() <= prec * prec * numext::mini(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum());
+ }
+};
+
+template<typename Derived, typename OtherDerived>
+struct isApprox_selector<Derived, OtherDerived, true>
+{
+ EIGEN_DEVICE_FUNC
+ static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar&)
+ {
+ return x.matrix() == y.matrix();
+ }
+};
+
+template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
+struct isMuchSmallerThan_object_selector
+{
+ EIGEN_DEVICE_FUNC
+ static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec)
+ {
+ return x.cwiseAbs2().sum() <= numext::abs2(prec) * y.cwiseAbs2().sum();
+ }
+};
+
+template<typename Derived, typename OtherDerived>
+struct isMuchSmallerThan_object_selector<Derived, OtherDerived, true>
+{
+ EIGEN_DEVICE_FUNC
+ static bool run(const Derived& x, const OtherDerived&, const typename Derived::RealScalar&)
+ {
+ return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
+ }
+};
+
+template<typename Derived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
+struct isMuchSmallerThan_scalar_selector
+{
+ EIGEN_DEVICE_FUNC
+ static bool run(const Derived& x, const typename Derived::RealScalar& y, const typename Derived::RealScalar& prec)
+ {
+ return x.cwiseAbs2().sum() <= numext::abs2(prec * y);
+ }
+};
+
+template<typename Derived>
+struct isMuchSmallerThan_scalar_selector<Derived, true>
+{
+ EIGEN_DEVICE_FUNC
+ static bool run(const Derived& x, const typename Derived::RealScalar&, const typename Derived::RealScalar&)
+ {
+ return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
+ }
+};
+
+} // end namespace internal
+
+
+/** \returns \c true if \c *this is approximately equal to \a other, within the precision
+ * determined by \a prec.
+ *
+ * \note The fuzzy compares are done multiplicatively. Two vectors \f$ v \f$ and \f$ w \f$
+ * are considered to be approximately equal within precision \f$ p \f$ if
+ * \f[ \Vert v - w \Vert \leqslant p\,\min(\Vert v\Vert, \Vert w\Vert). \f]
+ * For matrices, the comparison is done using the Hilbert-Schmidt norm (aka Frobenius norm
+ * L2 norm).
+ *
+ * \note Because of the multiplicativeness of this comparison, one can't use this function
+ * to check whether \c *this is approximately equal to the zero matrix or vector.
+ * Indeed, \c isApprox(zero) returns false unless \c *this itself is exactly the zero matrix
+ * or vector. If you want to test whether \c *this is zero, use internal::isMuchSmallerThan(const
+ * RealScalar&, RealScalar) instead.
+ *
+ * \sa internal::isMuchSmallerThan(const RealScalar&, RealScalar) const
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isApprox(
+ const DenseBase<OtherDerived>& other,
+ const RealScalar& prec
+) const
+{
+ return internal::isApprox_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
+}
+
+/** \returns \c true if the norm of \c *this is much smaller than \a other,
+ * within the precision determined by \a prec.
+ *
+ * \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is
+ * considered to be much smaller than \f$ x \f$ within precision \f$ p \f$ if
+ * \f[ \Vert v \Vert \leqslant p\,\vert x\vert. \f]
+ *
+ * For matrices, the comparison is done using the Hilbert-Schmidt norm. For this reason,
+ * the value of the reference scalar \a other should come from the Hilbert-Schmidt norm
+ * of a reference matrix of same dimensions.
+ *
+ * \sa isApprox(), isMuchSmallerThan(const DenseBase<OtherDerived>&, RealScalar) const
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isMuchSmallerThan(
+ const typename NumTraits<Scalar>::Real& other,
+ const RealScalar& prec
+) const
+{
+ return internal::isMuchSmallerThan_scalar_selector<Derived>::run(derived(), other, prec);
+}
+
+/** \returns \c true if the norm of \c *this is much smaller than the norm of \a other,
+ * within the precision determined by \a prec.
+ *
+ * \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is
+ * considered to be much smaller than a vector \f$ w \f$ within precision \f$ p \f$ if
+ * \f[ \Vert v \Vert \leqslant p\,\Vert w\Vert. \f]
+ * For matrices, the comparison is done using the Hilbert-Schmidt norm.
+ *
+ * \sa isApprox(), isMuchSmallerThan(const RealScalar&, RealScalar) const
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isMuchSmallerThan(
+ const DenseBase<OtherDerived>& other,
+ const RealScalar& prec
+) const
+{
+ return internal::isMuchSmallerThan_object_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_FUZZY_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/GeneralProduct.h b/src/3rdparty/eigen/Eigen/src/Core/GeneralProduct.h
new file mode 100644
index 000000000..6906aa75d
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/GeneralProduct.h
@@ -0,0 +1,465 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GENERAL_PRODUCT_H
+#define EIGEN_GENERAL_PRODUCT_H
+
+namespace Eigen {
+
+enum {
+ Large = 2,
+ Small = 3
+};
+
+// Define the threshold value to fallback from the generic matrix-matrix product
+// implementation (heavy) to the lightweight coeff-based product one.
+// See generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemmProduct>
+// in products/GeneralMatrixMatrix.h for more details.
+// TODO This threshold should also be used in the compile-time selector below.
+#ifndef EIGEN_GEMM_TO_COEFFBASED_THRESHOLD
+// This default value has been obtained on a Haswell architecture.
+#define EIGEN_GEMM_TO_COEFFBASED_THRESHOLD 20
+#endif
+
+namespace internal {
+
+template<int Rows, int Cols, int Depth> struct product_type_selector;
+
+template<int Size, int MaxSize> struct product_size_category
+{
+ enum {
+ #ifndef EIGEN_GPU_COMPILE_PHASE
+ is_large = MaxSize == Dynamic ||
+ Size >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD ||
+ (Size==Dynamic && MaxSize>=EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD),
+ #else
+ is_large = 0,
+ #endif
+ value = is_large ? Large
+ : Size == 1 ? 1
+ : Small
+ };
+};
+
+template<typename Lhs, typename Rhs> struct product_type
+{
+ typedef typename remove_all<Lhs>::type _Lhs;
+ typedef typename remove_all<Rhs>::type _Rhs;
+ enum {
+ MaxRows = traits<_Lhs>::MaxRowsAtCompileTime,
+ Rows = traits<_Lhs>::RowsAtCompileTime,
+ MaxCols = traits<_Rhs>::MaxColsAtCompileTime,
+ Cols = traits<_Rhs>::ColsAtCompileTime,
+ MaxDepth = EIGEN_SIZE_MIN_PREFER_FIXED(traits<_Lhs>::MaxColsAtCompileTime,
+ traits<_Rhs>::MaxRowsAtCompileTime),
+ Depth = EIGEN_SIZE_MIN_PREFER_FIXED(traits<_Lhs>::ColsAtCompileTime,
+ traits<_Rhs>::RowsAtCompileTime)
+ };
+
+ // the splitting into different lines of code here, introducing the _select enums and the typedef below,
+ // is to work around an internal compiler error with gcc 4.1 and 4.2.
+private:
+ enum {
+ rows_select = product_size_category<Rows,MaxRows>::value,
+ cols_select = product_size_category<Cols,MaxCols>::value,
+ depth_select = product_size_category<Depth,MaxDepth>::value
+ };
+ typedef product_type_selector<rows_select, cols_select, depth_select> selector;
+
+public:
+ enum {
+ value = selector::ret,
+ ret = selector::ret
+ };
+#ifdef EIGEN_DEBUG_PRODUCT
+ static void debug()
+ {
+ EIGEN_DEBUG_VAR(Rows);
+ EIGEN_DEBUG_VAR(Cols);
+ EIGEN_DEBUG_VAR(Depth);
+ EIGEN_DEBUG_VAR(rows_select);
+ EIGEN_DEBUG_VAR(cols_select);
+ EIGEN_DEBUG_VAR(depth_select);
+ EIGEN_DEBUG_VAR(value);
+ }
+#endif
+};
+
+/* The following allows to select the kind of product at compile time
+ * based on the three dimensions of the product.
+ * This is a compile time mapping from {1,Small,Large}^3 -> {product types} */
+// FIXME I'm not sure the current mapping is the ideal one.
+template<int M, int N> struct product_type_selector<M,N,1> { enum { ret = OuterProduct }; };
+template<int M> struct product_type_selector<M, 1, 1> { enum { ret = LazyCoeffBasedProductMode }; };
+template<int N> struct product_type_selector<1, N, 1> { enum { ret = LazyCoeffBasedProductMode }; };
+template<int Depth> struct product_type_selector<1, 1, Depth> { enum { ret = InnerProduct }; };
+template<> struct product_type_selector<1, 1, 1> { enum { ret = InnerProduct }; };
+template<> struct product_type_selector<Small,1, Small> { enum { ret = CoeffBasedProductMode }; };
+template<> struct product_type_selector<1, Small,Small> { enum { ret = CoeffBasedProductMode }; };
+template<> struct product_type_selector<Small,Small,Small> { enum { ret = CoeffBasedProductMode }; };
+template<> struct product_type_selector<Small, Small, 1> { enum { ret = LazyCoeffBasedProductMode }; };
+template<> struct product_type_selector<Small, Large, 1> { enum { ret = LazyCoeffBasedProductMode }; };
+template<> struct product_type_selector<Large, Small, 1> { enum { ret = LazyCoeffBasedProductMode }; };
+template<> struct product_type_selector<1, Large,Small> { enum { ret = CoeffBasedProductMode }; };
+template<> struct product_type_selector<1, Large,Large> { enum { ret = GemvProduct }; };
+template<> struct product_type_selector<1, Small,Large> { enum { ret = CoeffBasedProductMode }; };
+template<> struct product_type_selector<Large,1, Small> { enum { ret = CoeffBasedProductMode }; };
+template<> struct product_type_selector<Large,1, Large> { enum { ret = GemvProduct }; };
+template<> struct product_type_selector<Small,1, Large> { enum { ret = CoeffBasedProductMode }; };
+template<> struct product_type_selector<Small,Small,Large> { enum { ret = GemmProduct }; };
+template<> struct product_type_selector<Large,Small,Large> { enum { ret = GemmProduct }; };
+template<> struct product_type_selector<Small,Large,Large> { enum { ret = GemmProduct }; };
+template<> struct product_type_selector<Large,Large,Large> { enum { ret = GemmProduct }; };
+template<> struct product_type_selector<Large,Small,Small> { enum { ret = CoeffBasedProductMode }; };
+template<> struct product_type_selector<Small,Large,Small> { enum { ret = CoeffBasedProductMode }; };
+template<> struct product_type_selector<Large,Large,Small> { enum { ret = GemmProduct }; };
+
+} // end namespace internal
+
+/***********************************************************************
+* Implementation of Inner Vector Vector Product
+***********************************************************************/
+
+// FIXME : maybe the "inner product" could return a Scalar
+// instead of a 1x1 matrix ??
+// Pro: more natural for the user
+// Cons: this could be a problem if in a meta unrolled algorithm a matrix-matrix
+// product ends up to a row-vector times col-vector product... To tackle this use
+// case, we could have a specialization for Block<MatrixType,1,1> with: operator=(Scalar x);
+
+/***********************************************************************
+* Implementation of Outer Vector Vector Product
+***********************************************************************/
+
+/***********************************************************************
+* Implementation of General Matrix Vector Product
+***********************************************************************/
+
+/* According to the shape/flags of the matrix we have to distinghish 3 different cases:
+ * 1 - the matrix is col-major, BLAS compatible and M is large => call fast BLAS-like colmajor routine
+ * 2 - the matrix is row-major, BLAS compatible and N is large => call fast BLAS-like rowmajor routine
+ * 3 - all other cases are handled using a simple loop along the outer-storage direction.
+ * Therefore we need a lower level meta selector.
+ * Furthermore, if the matrix is the rhs, then the product has to be transposed.
+ */
+namespace internal {
+
+template<int Side, int StorageOrder, bool BlasCompatible>
+struct gemv_dense_selector;
+
+} // end namespace internal
+
+namespace internal {
+
+template<typename Scalar,int Size,int MaxSize,bool Cond> struct gemv_static_vector_if;
+
+template<typename Scalar,int Size,int MaxSize>
+struct gemv_static_vector_if<Scalar,Size,MaxSize,false>
+{
+ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Scalar* data() { eigen_internal_assert(false && "should never be called"); return 0; }
+};
+
+template<typename Scalar,int Size>
+struct gemv_static_vector_if<Scalar,Size,Dynamic,true>
+{
+ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Scalar* data() { return 0; }
+};
+
+template<typename Scalar,int Size,int MaxSize>
+struct gemv_static_vector_if<Scalar,Size,MaxSize,true>
+{
+ enum {
+ ForceAlignment = internal::packet_traits<Scalar>::Vectorizable,
+ PacketSize = internal::packet_traits<Scalar>::size
+ };
+ #if EIGEN_MAX_STATIC_ALIGN_BYTES!=0
+ internal::plain_array<Scalar,EIGEN_SIZE_MIN_PREFER_FIXED(Size,MaxSize),0,EIGEN_PLAIN_ENUM_MIN(AlignedMax,PacketSize)> m_data;
+ EIGEN_STRONG_INLINE Scalar* data() { return m_data.array; }
+ #else
+ // Some architectures cannot align on the stack,
+ // => let's manually enforce alignment by allocating more data and return the address of the first aligned element.
+ internal::plain_array<Scalar,EIGEN_SIZE_MIN_PREFER_FIXED(Size,MaxSize)+(ForceAlignment?EIGEN_MAX_ALIGN_BYTES:0),0> m_data;
+ EIGEN_STRONG_INLINE Scalar* data() {
+ return ForceAlignment
+ ? reinterpret_cast<Scalar*>((internal::UIntPtr(m_data.array) & ~(std::size_t(EIGEN_MAX_ALIGN_BYTES-1))) + EIGEN_MAX_ALIGN_BYTES)
+ : m_data.array;
+ }
+ #endif
+};
+
+// The vector is on the left => transposition
+template<int StorageOrder, bool BlasCompatible>
+struct gemv_dense_selector<OnTheLeft,StorageOrder,BlasCompatible>
+{
+ template<typename Lhs, typename Rhs, typename Dest>
+ static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
+ {
+ Transpose<Dest> destT(dest);
+ enum { OtherStorageOrder = StorageOrder == RowMajor ? ColMajor : RowMajor };
+ gemv_dense_selector<OnTheRight,OtherStorageOrder,BlasCompatible>
+ ::run(rhs.transpose(), lhs.transpose(), destT, alpha);
+ }
+};
+
+template<> struct gemv_dense_selector<OnTheRight,ColMajor,true>
+{
+ template<typename Lhs, typename Rhs, typename Dest>
+ static inline void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
+ {
+ typedef typename Lhs::Scalar LhsScalar;
+ typedef typename Rhs::Scalar RhsScalar;
+ typedef typename Dest::Scalar ResScalar;
+ typedef typename Dest::RealScalar RealScalar;
+
+ typedef internal::blas_traits<Lhs> LhsBlasTraits;
+ typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
+ typedef internal::blas_traits<Rhs> RhsBlasTraits;
+ typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
+
+ typedef Map<Matrix<ResScalar,Dynamic,1>, EIGEN_PLAIN_ENUM_MIN(AlignedMax,internal::packet_traits<ResScalar>::size)> MappedDest;
+
+ ActualLhsType actualLhs = LhsBlasTraits::extract(lhs);
+ ActualRhsType actualRhs = RhsBlasTraits::extract(rhs);
+
+ ResScalar actualAlpha = combine_scalar_factors(alpha, lhs, rhs);
+
+ // make sure Dest is a compile-time vector type (bug 1166)
+ typedef typename conditional<Dest::IsVectorAtCompileTime, Dest, typename Dest::ColXpr>::type ActualDest;
+
+ enum {
+ // FIXME find a way to allow an inner stride on the result if packet_traits<Scalar>::size==1
+ // on, the other hand it is good for the cache to pack the vector anyways...
+ EvalToDestAtCompileTime = (ActualDest::InnerStrideAtCompileTime==1),
+ ComplexByReal = (NumTraits<LhsScalar>::IsComplex) && (!NumTraits<RhsScalar>::IsComplex),
+ MightCannotUseDest = ((!EvalToDestAtCompileTime) || ComplexByReal) && (ActualDest::MaxSizeAtCompileTime!=0)
+ };
+
+ typedef const_blas_data_mapper<LhsScalar,Index,ColMajor> LhsMapper;
+ typedef const_blas_data_mapper<RhsScalar,Index,RowMajor> RhsMapper;
+ RhsScalar compatibleAlpha = get_factor<ResScalar,RhsScalar>::run(actualAlpha);
+
+ if(!MightCannotUseDest)
+ {
+ // shortcut if we are sure to be able to use dest directly,
+ // this ease the compiler to generate cleaner and more optimzized code for most common cases
+ general_matrix_vector_product
+ <Index,LhsScalar,LhsMapper,ColMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsMapper,RhsBlasTraits::NeedToConjugate>::run(
+ actualLhs.rows(), actualLhs.cols(),
+ LhsMapper(actualLhs.data(), actualLhs.outerStride()),
+ RhsMapper(actualRhs.data(), actualRhs.innerStride()),
+ dest.data(), 1,
+ compatibleAlpha);
+ }
+ else
+ {
+ gemv_static_vector_if<ResScalar,ActualDest::SizeAtCompileTime,ActualDest::MaxSizeAtCompileTime,MightCannotUseDest> static_dest;
+
+ const bool alphaIsCompatible = (!ComplexByReal) || (numext::imag(actualAlpha)==RealScalar(0));
+ const bool evalToDest = EvalToDestAtCompileTime && alphaIsCompatible;
+
+ ei_declare_aligned_stack_constructed_variable(ResScalar,actualDestPtr,dest.size(),
+ evalToDest ? dest.data() : static_dest.data());
+
+ if(!evalToDest)
+ {
+ #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ Index size = dest.size();
+ EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ #endif
+ if(!alphaIsCompatible)
+ {
+ MappedDest(actualDestPtr, dest.size()).setZero();
+ compatibleAlpha = RhsScalar(1);
+ }
+ else
+ MappedDest(actualDestPtr, dest.size()) = dest;
+ }
+
+ general_matrix_vector_product
+ <Index,LhsScalar,LhsMapper,ColMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsMapper,RhsBlasTraits::NeedToConjugate>::run(
+ actualLhs.rows(), actualLhs.cols(),
+ LhsMapper(actualLhs.data(), actualLhs.outerStride()),
+ RhsMapper(actualRhs.data(), actualRhs.innerStride()),
+ actualDestPtr, 1,
+ compatibleAlpha);
+
+ if (!evalToDest)
+ {
+ if(!alphaIsCompatible)
+ dest.matrix() += actualAlpha * MappedDest(actualDestPtr, dest.size());
+ else
+ dest = MappedDest(actualDestPtr, dest.size());
+ }
+ }
+ }
+};
+
+template<> struct gemv_dense_selector<OnTheRight,RowMajor,true>
+{
+ template<typename Lhs, typename Rhs, typename Dest>
+ static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
+ {
+ typedef typename Lhs::Scalar LhsScalar;
+ typedef typename Rhs::Scalar RhsScalar;
+ typedef typename Dest::Scalar ResScalar;
+
+ typedef internal::blas_traits<Lhs> LhsBlasTraits;
+ typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
+ typedef internal::blas_traits<Rhs> RhsBlasTraits;
+ typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
+ typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned;
+
+ typename add_const<ActualLhsType>::type actualLhs = LhsBlasTraits::extract(lhs);
+ typename add_const<ActualRhsType>::type actualRhs = RhsBlasTraits::extract(rhs);
+
+ ResScalar actualAlpha = combine_scalar_factors(alpha, lhs, rhs);
+
+ enum {
+ // FIXME find a way to allow an inner stride on the result if packet_traits<Scalar>::size==1
+ // on, the other hand it is good for the cache to pack the vector anyways...
+ DirectlyUseRhs = ActualRhsTypeCleaned::InnerStrideAtCompileTime==1 || ActualRhsTypeCleaned::MaxSizeAtCompileTime==0
+ };
+
+ gemv_static_vector_if<RhsScalar,ActualRhsTypeCleaned::SizeAtCompileTime,ActualRhsTypeCleaned::MaxSizeAtCompileTime,!DirectlyUseRhs> static_rhs;
+
+ ei_declare_aligned_stack_constructed_variable(RhsScalar,actualRhsPtr,actualRhs.size(),
+ DirectlyUseRhs ? const_cast<RhsScalar*>(actualRhs.data()) : static_rhs.data());
+
+ if(!DirectlyUseRhs)
+ {
+ #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ Index size = actualRhs.size();
+ EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ #endif
+ Map<typename ActualRhsTypeCleaned::PlainObject>(actualRhsPtr, actualRhs.size()) = actualRhs;
+ }
+
+ typedef const_blas_data_mapper<LhsScalar,Index,RowMajor> LhsMapper;
+ typedef const_blas_data_mapper<RhsScalar,Index,ColMajor> RhsMapper;
+ general_matrix_vector_product
+ <Index,LhsScalar,LhsMapper,RowMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsMapper,RhsBlasTraits::NeedToConjugate>::run(
+ actualLhs.rows(), actualLhs.cols(),
+ LhsMapper(actualLhs.data(), actualLhs.outerStride()),
+ RhsMapper(actualRhsPtr, 1),
+ dest.data(), dest.col(0).innerStride(), //NOTE if dest is not a vector at compile-time, then dest.innerStride() might be wrong. (bug 1166)
+ actualAlpha);
+ }
+};
+
+template<> struct gemv_dense_selector<OnTheRight,ColMajor,false>
+{
+ template<typename Lhs, typename Rhs, typename Dest>
+ static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
+ {
+ EIGEN_STATIC_ASSERT((!nested_eval<Lhs,1>::Evaluate),EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE);
+ // TODO if rhs is large enough it might be beneficial to make sure that dest is sequentially stored in memory, otherwise use a temp
+ typename nested_eval<Rhs,1>::type actual_rhs(rhs);
+ const Index size = rhs.rows();
+ for(Index k=0; k<size; ++k)
+ dest += (alpha*actual_rhs.coeff(k)) * lhs.col(k);
+ }
+};
+
+template<> struct gemv_dense_selector<OnTheRight,RowMajor,false>
+{
+ template<typename Lhs, typename Rhs, typename Dest>
+ static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
+ {
+ EIGEN_STATIC_ASSERT((!nested_eval<Lhs,1>::Evaluate),EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE);
+ typename nested_eval<Rhs,Lhs::RowsAtCompileTime>::type actual_rhs(rhs);
+ const Index rows = dest.rows();
+ for(Index i=0; i<rows; ++i)
+ dest.coeffRef(i) += alpha * (lhs.row(i).cwiseProduct(actual_rhs.transpose())).sum();
+ }
+};
+
+} // end namespace internal
+
+/***************************************************************************
+* Implementation of matrix base methods
+***************************************************************************/
+
+/** \returns the matrix product of \c *this and \a other.
+ *
+ * \note If instead of the matrix product you want the coefficient-wise product, see Cwise::operator*().
+ *
+ * \sa lazyProduct(), operator*=(const MatrixBase&), Cwise::operator*()
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const Product<Derived, OtherDerived>
+MatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const
+{
+ // A note regarding the function declaration: In MSVC, this function will sometimes
+ // not be inlined since DenseStorage is an unwindable object for dynamic
+ // matrices and product types are holding a member to store the result.
+ // Thus it does not help tagging this function with EIGEN_STRONG_INLINE.
+ enum {
+ ProductIsValid = Derived::ColsAtCompileTime==Dynamic
+ || OtherDerived::RowsAtCompileTime==Dynamic
+ || int(Derived::ColsAtCompileTime)==int(OtherDerived::RowsAtCompileTime),
+ AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime,
+ SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(Derived,OtherDerived)
+ };
+ // note to the lost user:
+ // * for a dot product use: v1.dot(v2)
+ // * for a coeff-wise product use: v1.cwiseProduct(v2)
+ EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
+ INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
+ EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
+ INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
+ EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
+#ifdef EIGEN_DEBUG_PRODUCT
+ internal::product_type<Derived,OtherDerived>::debug();
+#endif
+
+ return Product<Derived, OtherDerived>(derived(), other.derived());
+}
+
+/** \returns an expression of the matrix product of \c *this and \a other without implicit evaluation.
+ *
+ * The returned product will behave like any other expressions: the coefficients of the product will be
+ * computed once at a time as requested. This might be useful in some extremely rare cases when only
+ * a small and no coherent fraction of the result's coefficients have to be computed.
+ *
+ * \warning This version of the matrix product can be much much slower. So use it only if you know
+ * what you are doing and that you measured a true speed improvement.
+ *
+ * \sa operator*(const MatrixBase&)
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const Product<Derived,OtherDerived,LazyProduct>
+MatrixBase<Derived>::lazyProduct(const MatrixBase<OtherDerived> &other) const
+{
+ enum {
+ ProductIsValid = Derived::ColsAtCompileTime==Dynamic
+ || OtherDerived::RowsAtCompileTime==Dynamic
+ || int(Derived::ColsAtCompileTime)==int(OtherDerived::RowsAtCompileTime),
+ AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime,
+ SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(Derived,OtherDerived)
+ };
+ // note to the lost user:
+ // * for a dot product use: v1.dot(v2)
+ // * for a coeff-wise product use: v1.cwiseProduct(v2)
+ EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
+ INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
+ EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
+ INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
+ EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
+
+ return Product<Derived,OtherDerived,LazyProduct>(derived(), other.derived());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_PRODUCT_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/GenericPacketMath.h b/src/3rdparty/eigen/Eigen/src/Core/GenericPacketMath.h
new file mode 100644
index 000000000..cf677a190
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/GenericPacketMath.h
@@ -0,0 +1,1040 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GENERIC_PACKET_MATH_H
+#define EIGEN_GENERIC_PACKET_MATH_H
+
+namespace Eigen {
+
+namespace internal {
+
+/** \internal
+ * \file GenericPacketMath.h
+ *
+ * Default implementation for types not supported by the vectorization.
+ * In practice these functions are provided to make easier the writing
+ * of generic vectorized code.
+ */
+
+#ifndef EIGEN_DEBUG_ALIGNED_LOAD
+#define EIGEN_DEBUG_ALIGNED_LOAD
+#endif
+
+#ifndef EIGEN_DEBUG_UNALIGNED_LOAD
+#define EIGEN_DEBUG_UNALIGNED_LOAD
+#endif
+
+#ifndef EIGEN_DEBUG_ALIGNED_STORE
+#define EIGEN_DEBUG_ALIGNED_STORE
+#endif
+
+#ifndef EIGEN_DEBUG_UNALIGNED_STORE
+#define EIGEN_DEBUG_UNALIGNED_STORE
+#endif
+
+struct default_packet_traits
+{
+ enum {
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasAbsDiff = 0,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 1,
+ HasBlend = 0,
+ // This flag is used to indicate whether packet comparison is supported.
+ // pcmp_eq, pcmp_lt and pcmp_le should be defined for it to be true.
+ HasCmp = 0,
+
+ HasDiv = 0,
+ HasSqrt = 0,
+ HasRsqrt = 0,
+ HasExp = 0,
+ HasExpm1 = 0,
+ HasLog = 0,
+ HasLog1p = 0,
+ HasLog10 = 0,
+ HasPow = 0,
+
+ HasSin = 0,
+ HasCos = 0,
+ HasTan = 0,
+ HasASin = 0,
+ HasACos = 0,
+ HasATan = 0,
+ HasSinh = 0,
+ HasCosh = 0,
+ HasTanh = 0,
+ HasLGamma = 0,
+ HasDiGamma = 0,
+ HasZeta = 0,
+ HasPolygamma = 0,
+ HasErf = 0,
+ HasErfc = 0,
+ HasNdtri = 0,
+ HasBessel = 0,
+ HasIGamma = 0,
+ HasIGammaDerA = 0,
+ HasGammaSampleDerAlpha = 0,
+ HasIGammac = 0,
+ HasBetaInc = 0,
+
+ HasRound = 0,
+ HasRint = 0,
+ HasFloor = 0,
+ HasCeil = 0,
+ HasSign = 0
+ };
+};
+
+template<typename T> struct packet_traits : default_packet_traits
+{
+ typedef T type;
+ typedef T half;
+ enum {
+ Vectorizable = 0,
+ size = 1,
+ AlignedOnScalar = 0,
+ HasHalfPacket = 0
+ };
+ enum {
+ HasAdd = 0,
+ HasSub = 0,
+ HasMul = 0,
+ HasNegate = 0,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasConj = 0,
+ HasSetLinear = 0
+ };
+};
+
+template<typename T> struct packet_traits<const T> : packet_traits<T> { };
+
+template<typename T> struct unpacket_traits
+{
+ typedef T type;
+ typedef T half;
+ enum
+ {
+ size = 1,
+ alignment = 1,
+ vectorizable = false,
+ masked_load_available=false,
+ masked_store_available=false
+ };
+};
+
+template<typename T> struct unpacket_traits<const T> : unpacket_traits<T> { };
+
+template <typename Src, typename Tgt> struct type_casting_traits {
+ enum {
+ VectorizedCast = 0,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+/** \internal Wrapper to ensure that multiple packet types can map to the same
+ same underlying vector type. */
+template<typename T, int unique_id = 0>
+struct eigen_packet_wrapper
+{
+ EIGEN_ALWAYS_INLINE operator T&() { return m_val; }
+ EIGEN_ALWAYS_INLINE operator const T&() const { return m_val; }
+ EIGEN_ALWAYS_INLINE eigen_packet_wrapper() {}
+ EIGEN_ALWAYS_INLINE eigen_packet_wrapper(const T &v) : m_val(v) {}
+ EIGEN_ALWAYS_INLINE eigen_packet_wrapper& operator=(const T &v) {
+ m_val = v;
+ return *this;
+ }
+
+ T m_val;
+};
+
+
+/** \internal A convenience utility for determining if the type is a scalar.
+ * This is used to enable some generic packet implementations.
+ */
+template<typename Packet>
+struct is_scalar {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ enum {
+ value = internal::is_same<Packet, Scalar>::value
+ };
+};
+
+/** \internal \returns static_cast<TgtType>(a) (coeff-wise) */
+template <typename SrcPacket, typename TgtPacket>
+EIGEN_DEVICE_FUNC inline TgtPacket
+pcast(const SrcPacket& a) {
+ return static_cast<TgtPacket>(a);
+}
+template <typename SrcPacket, typename TgtPacket>
+EIGEN_DEVICE_FUNC inline TgtPacket
+pcast(const SrcPacket& a, const SrcPacket& /*b*/) {
+ return static_cast<TgtPacket>(a);
+}
+template <typename SrcPacket, typename TgtPacket>
+EIGEN_DEVICE_FUNC inline TgtPacket
+pcast(const SrcPacket& a, const SrcPacket& /*b*/, const SrcPacket& /*c*/, const SrcPacket& /*d*/) {
+ return static_cast<TgtPacket>(a);
+}
+template <typename SrcPacket, typename TgtPacket>
+EIGEN_DEVICE_FUNC inline TgtPacket
+pcast(const SrcPacket& a, const SrcPacket& /*b*/, const SrcPacket& /*c*/, const SrcPacket& /*d*/,
+ const SrcPacket& /*e*/, const SrcPacket& /*f*/, const SrcPacket& /*g*/, const SrcPacket& /*h*/) {
+ return static_cast<TgtPacket>(a);
+}
+
+/** \internal \returns reinterpret_cast<Target>(a) */
+template <typename Target, typename Packet>
+EIGEN_DEVICE_FUNC inline Target
+preinterpret(const Packet& a); /* { return reinterpret_cast<const Target&>(a); } */
+
+/** \internal \returns a + b (coeff-wise) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+padd(const Packet& a, const Packet& b) { return a+b; }
+// Avoid compiler warning for boolean algebra.
+template<> EIGEN_DEVICE_FUNC inline bool
+padd(const bool& a, const bool& b) { return a || b; }
+
+/** \internal \returns a - b (coeff-wise) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+psub(const Packet& a, const Packet& b) { return a-b; }
+
+/** \internal \returns -a (coeff-wise) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pnegate(const Packet& a) { return -a; }
+
+template<> EIGEN_DEVICE_FUNC inline bool
+pnegate(const bool& a) { return !a; }
+
+/** \internal \returns conj(a) (coeff-wise) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pconj(const Packet& a) { return numext::conj(a); }
+
+/** \internal \returns a * b (coeff-wise) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pmul(const Packet& a, const Packet& b) { return a*b; }
+// Avoid compiler warning for boolean algebra.
+template<> EIGEN_DEVICE_FUNC inline bool
+pmul(const bool& a, const bool& b) { return a && b; }
+
+/** \internal \returns a / b (coeff-wise) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pdiv(const Packet& a, const Packet& b) { return a/b; }
+
+// In the generic case, memset to all one bits.
+template<typename Packet, typename EnableIf = void>
+struct ptrue_impl {
+ static EIGEN_DEVICE_FUNC inline Packet run(const Packet& /*a*/){
+ Packet b;
+ memset(static_cast<void*>(&b), 0xff, sizeof(Packet));
+ return b;
+ }
+};
+
+// For non-trivial scalars, set to Scalar(1) (i.e. a non-zero value).
+// Although this is technically not a valid bitmask, the scalar path for pselect
+// uses a comparison to zero, so this should still work in most cases. We don't
+// have another option, since the scalar type requires initialization.
+template<typename T>
+struct ptrue_impl<T,
+ typename internal::enable_if<is_scalar<T>::value && NumTraits<T>::RequireInitialization>::type > {
+ static EIGEN_DEVICE_FUNC inline T run(const T& /*a*/){
+ return T(1);
+ }
+};
+
+/** \internal \returns one bits. */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+ptrue(const Packet& a) {
+ return ptrue_impl<Packet>::run(a);
+}
+
+// In the general case, memset to zero.
+template<typename Packet, typename EnableIf = void>
+struct pzero_impl {
+ static EIGEN_DEVICE_FUNC inline Packet run(const Packet& /*a*/) {
+ Packet b;
+ memset(static_cast<void*>(&b), 0x00, sizeof(Packet));
+ return b;
+ }
+};
+
+// For scalars, explicitly set to Scalar(0), since the underlying representation
+// for zero may not consist of all-zero bits.
+template<typename T>
+struct pzero_impl<T,
+ typename internal::enable_if<is_scalar<T>::value>::type> {
+ static EIGEN_DEVICE_FUNC inline T run(const T& /*a*/) {
+ return T(0);
+ }
+};
+
+/** \internal \returns packet of zeros */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pzero(const Packet& a) {
+ return pzero_impl<Packet>::run(a);
+}
+
+/** \internal \returns a <= b as a bit mask */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pcmp_le(const Packet& a, const Packet& b) { return a<=b ? ptrue(a) : pzero(a); }
+
+/** \internal \returns a < b as a bit mask */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pcmp_lt(const Packet& a, const Packet& b) { return a<b ? ptrue(a) : pzero(a); }
+
+/** \internal \returns a == b as a bit mask */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pcmp_eq(const Packet& a, const Packet& b) { return a==b ? ptrue(a) : pzero(a); }
+
+/** \internal \returns a < b or a==NaN or b==NaN as a bit mask */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pcmp_lt_or_nan(const Packet& a, const Packet& b) { return a>=b ? pzero(a) : ptrue(a); }
+
+template<typename T>
+struct bit_and {
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a, const T& b) const {
+ return a & b;
+ }
+};
+
+template<typename T>
+struct bit_or {
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a, const T& b) const {
+ return a | b;
+ }
+};
+
+template<typename T>
+struct bit_xor {
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a, const T& b) const {
+ return a ^ b;
+ }
+};
+
+template<typename T>
+struct bit_not {
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a) const {
+ return ~a;
+ }
+};
+
+// Use operators &, |, ^, ~.
+template<typename T>
+struct operator_bitwise_helper {
+ EIGEN_DEVICE_FUNC static inline T bitwise_and(const T& a, const T& b) { return bit_and<T>()(a, b); }
+ EIGEN_DEVICE_FUNC static inline T bitwise_or(const T& a, const T& b) { return bit_or<T>()(a, b); }
+ EIGEN_DEVICE_FUNC static inline T bitwise_xor(const T& a, const T& b) { return bit_xor<T>()(a, b); }
+ EIGEN_DEVICE_FUNC static inline T bitwise_not(const T& a) { return bit_not<T>()(a); }
+};
+
+// Apply binary operations byte-by-byte
+template<typename T>
+struct bytewise_bitwise_helper {
+ EIGEN_DEVICE_FUNC static inline T bitwise_and(const T& a, const T& b) {
+ return binary(a, b, bit_and<unsigned char>());
+ }
+ EIGEN_DEVICE_FUNC static inline T bitwise_or(const T& a, const T& b) {
+ return binary(a, b, bit_or<unsigned char>());
+ }
+ EIGEN_DEVICE_FUNC static inline T bitwise_xor(const T& a, const T& b) {
+ return binary(a, b, bit_xor<unsigned char>());
+ }
+ EIGEN_DEVICE_FUNC static inline T bitwise_not(const T& a) {
+ return unary(a,bit_not<unsigned char>());
+ }
+
+ private:
+ template<typename Op>
+ EIGEN_DEVICE_FUNC static inline T unary(const T& a, Op op) {
+ const unsigned char* a_ptr = reinterpret_cast<const unsigned char*>(&a);
+ T c;
+ unsigned char* c_ptr = reinterpret_cast<unsigned char*>(&c);
+ for (size_t i = 0; i < sizeof(T); ++i) {
+ *c_ptr++ = op(*a_ptr++);
+ }
+ return c;
+ }
+
+ template<typename Op>
+ EIGEN_DEVICE_FUNC static inline T binary(const T& a, const T& b, Op op) {
+ const unsigned char* a_ptr = reinterpret_cast<const unsigned char*>(&a);
+ const unsigned char* b_ptr = reinterpret_cast<const unsigned char*>(&b);
+ T c;
+ unsigned char* c_ptr = reinterpret_cast<unsigned char*>(&c);
+ for (size_t i = 0; i < sizeof(T); ++i) {
+ *c_ptr++ = op(*a_ptr++, *b_ptr++);
+ }
+ return c;
+ }
+};
+
+// In the general case, use byte-by-byte manipulation.
+template<typename T, typename EnableIf = void>
+struct bitwise_helper : public bytewise_bitwise_helper<T> {};
+
+// For integers or non-trivial scalars, use binary operators.
+template<typename T>
+struct bitwise_helper<T,
+ typename internal::enable_if<
+ is_scalar<T>::value && (NumTraits<T>::IsInteger || NumTraits<T>::RequireInitialization)>::type
+ > : public operator_bitwise_helper<T> {};
+
+/** \internal \returns the bitwise and of \a a and \a b */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pand(const Packet& a, const Packet& b) {
+ return bitwise_helper<Packet>::bitwise_and(a, b);
+}
+
+/** \internal \returns the bitwise or of \a a and \a b */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+por(const Packet& a, const Packet& b) {
+ return bitwise_helper<Packet>::bitwise_or(a, b);
+}
+
+/** \internal \returns the bitwise xor of \a a and \a b */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pxor(const Packet& a, const Packet& b) {
+ return bitwise_helper<Packet>::bitwise_xor(a, b);
+}
+
+/** \internal \returns the bitwise not of \a a */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pnot(const Packet& a) {
+ return bitwise_helper<Packet>::bitwise_not(a);
+}
+
+/** \internal \returns the bitwise and of \a a and not \a b */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pandnot(const Packet& a, const Packet& b) { return pand(a, pnot(b)); }
+
+// In the general case, use bitwise select.
+template<typename Packet, typename EnableIf = void>
+struct pselect_impl {
+ static EIGEN_DEVICE_FUNC inline Packet run(const Packet& mask, const Packet& a, const Packet& b) {
+ return por(pand(a,mask),pandnot(b,mask));
+ }
+};
+
+// For scalars, use ternary select.
+template<typename Packet>
+struct pselect_impl<Packet,
+ typename internal::enable_if<is_scalar<Packet>::value>::type > {
+ static EIGEN_DEVICE_FUNC inline Packet run(const Packet& mask, const Packet& a, const Packet& b) {
+ return numext::equal_strict(mask, Packet(0)) ? b : a;
+ }
+};
+
+/** \internal \returns \a or \b for each field in packet according to \mask */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pselect(const Packet& mask, const Packet& a, const Packet& b) {
+ return pselect_impl<Packet>::run(mask, a, b);
+}
+
+template<> EIGEN_DEVICE_FUNC inline bool pselect<bool>(
+ const bool& cond, const bool& a, const bool& b) {
+ return cond ? a : b;
+}
+
+/** \internal \returns the min or of \a a and \a b (coeff-wise)
+ If either \a a or \a b are NaN, the result is implementation defined. */
+template<int NaNPropagation>
+struct pminmax_impl {
+ template <typename Packet, typename Op>
+ static EIGEN_DEVICE_FUNC inline Packet run(const Packet& a, const Packet& b, Op op) {
+ return op(a,b);
+ }
+};
+
+/** \internal \returns the min or max of \a a and \a b (coeff-wise)
+ If either \a a or \a b are NaN, NaN is returned. */
+template<>
+struct pminmax_impl<PropagateNaN> {
+ template <typename Packet, typename Op>
+ static EIGEN_DEVICE_FUNC inline Packet run(const Packet& a, const Packet& b, Op op) {
+ Packet not_nan_mask_a = pcmp_eq(a, a);
+ Packet not_nan_mask_b = pcmp_eq(b, b);
+ return pselect(not_nan_mask_a,
+ pselect(not_nan_mask_b, op(a, b), b),
+ a);
+ }
+};
+
+/** \internal \returns the min or max of \a a and \a b (coeff-wise)
+ If both \a a and \a b are NaN, NaN is returned.
+ Equivalent to std::fmin(a, b). */
+template<>
+struct pminmax_impl<PropagateNumbers> {
+ template <typename Packet, typename Op>
+ static EIGEN_DEVICE_FUNC inline Packet run(const Packet& a, const Packet& b, Op op) {
+ Packet not_nan_mask_a = pcmp_eq(a, a);
+ Packet not_nan_mask_b = pcmp_eq(b, b);
+ return pselect(not_nan_mask_a,
+ pselect(not_nan_mask_b, op(a, b), a),
+ b);
+ }
+};
+
+
+#ifndef SYCL_DEVICE_ONLY
+#define EIGEN_BINARY_OP_NAN_PROPAGATION(Type, Func) Func
+#else
+#define EIGEN_BINARY_OP_NAN_PROPAGATION(Type, Func) \
+[](const Type& a, const Type& b) { \
+ return Func(a, b);}
+#endif
+
+/** \internal \returns the min of \a a and \a b (coeff-wise).
+ If \a a or \b b is NaN, the return value is implementation defined. */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pmin(const Packet& a, const Packet& b) { return numext::mini(a,b); }
+
+/** \internal \returns the min of \a a and \a b (coeff-wise).
+ NaNPropagation determines the NaN propagation semantics. */
+template <int NaNPropagation, typename Packet>
+EIGEN_DEVICE_FUNC inline Packet pmin(const Packet& a, const Packet& b) {
+ return pminmax_impl<NaNPropagation>::run(a, b, EIGEN_BINARY_OP_NAN_PROPAGATION(Packet, (pmin<Packet>)));
+}
+
+/** \internal \returns the max of \a a and \a b (coeff-wise)
+ If \a a or \b b is NaN, the return value is implementation defined. */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pmax(const Packet& a, const Packet& b) { return numext::maxi(a, b); }
+
+/** \internal \returns the max of \a a and \a b (coeff-wise).
+ NaNPropagation determines the NaN propagation semantics. */
+template <int NaNPropagation, typename Packet>
+EIGEN_DEVICE_FUNC inline Packet pmax(const Packet& a, const Packet& b) {
+ return pminmax_impl<NaNPropagation>::run(a, b, EIGEN_BINARY_OP_NAN_PROPAGATION(Packet,(pmax<Packet>)));
+}
+
+/** \internal \returns the absolute value of \a a */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pabs(const Packet& a) { return numext::abs(a); }
+template<> EIGEN_DEVICE_FUNC inline unsigned int
+pabs(const unsigned int& a) { return a; }
+template<> EIGEN_DEVICE_FUNC inline unsigned long
+pabs(const unsigned long& a) { return a; }
+template<> EIGEN_DEVICE_FUNC inline unsigned long long
+pabs(const unsigned long long& a) { return a; }
+
+/** \internal \returns the addsub value of \a a,b */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+paddsub(const Packet& a, const Packet& b) {
+ return pselect(peven_mask(a), padd(a, b), psub(a, b));
+ }
+
+/** \internal \returns the phase angle of \a a */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+parg(const Packet& a) { using numext::arg; return arg(a); }
+
+
+/** \internal \returns \a a logically shifted by N bits to the right */
+template<int N> EIGEN_DEVICE_FUNC inline int
+parithmetic_shift_right(const int& a) { return a >> N; }
+template<int N> EIGEN_DEVICE_FUNC inline long int
+parithmetic_shift_right(const long int& a) { return a >> N; }
+
+/** \internal \returns \a a arithmetically shifted by N bits to the right */
+template<int N> EIGEN_DEVICE_FUNC inline int
+plogical_shift_right(const int& a) { return static_cast<int>(static_cast<unsigned int>(a) >> N); }
+template<int N> EIGEN_DEVICE_FUNC inline long int
+plogical_shift_right(const long int& a) { return static_cast<long>(static_cast<unsigned long>(a) >> N); }
+
+/** \internal \returns \a a shifted by N bits to the left */
+template<int N> EIGEN_DEVICE_FUNC inline int
+plogical_shift_left(const int& a) { return a << N; }
+template<int N> EIGEN_DEVICE_FUNC inline long int
+plogical_shift_left(const long int& a) { return a << N; }
+
+/** \internal \returns the significant and exponent of the underlying floating point numbers
+ * See https://en.cppreference.com/w/cpp/numeric/math/frexp
+ */
+template <typename Packet>
+EIGEN_DEVICE_FUNC inline Packet pfrexp(const Packet& a, Packet& exponent) {
+ int exp;
+ EIGEN_USING_STD(frexp);
+ Packet result = static_cast<Packet>(frexp(a, &exp));
+ exponent = static_cast<Packet>(exp);
+ return result;
+}
+
+/** \internal \returns a * 2^((int)exponent)
+ * See https://en.cppreference.com/w/cpp/numeric/math/ldexp
+ */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pldexp(const Packet &a, const Packet &exponent) {
+ EIGEN_USING_STD(ldexp)
+ return static_cast<Packet>(ldexp(a, static_cast<int>(exponent)));
+}
+
+/** \internal \returns the min of \a a and \a b (coeff-wise) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pabsdiff(const Packet& a, const Packet& b) { return pselect(pcmp_lt(a, b), psub(b, a), psub(a, b)); }
+
+/** \internal \returns a packet version of \a *from, from must be 16 bytes aligned */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pload(const typename unpacket_traits<Packet>::type* from) { return *from; }
+
+/** \internal \returns a packet version of \a *from, (un-aligned load) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+ploadu(const typename unpacket_traits<Packet>::type* from) { return *from; }
+
+/** \internal \returns a packet version of \a *from, (un-aligned masked load)
+ * There is no generic implementation. We only have implementations for specialized
+ * cases. Generic case should not be called.
+ */
+template<typename Packet> EIGEN_DEVICE_FUNC inline
+typename enable_if<unpacket_traits<Packet>::masked_load_available, Packet>::type
+ploadu(const typename unpacket_traits<Packet>::type* from, typename unpacket_traits<Packet>::mask_t umask);
+
+/** \internal \returns a packet with constant coefficients \a a, e.g.: (a,a,a,a) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pset1(const typename unpacket_traits<Packet>::type& a) { return a; }
+
+/** \internal \returns a packet with constant coefficients set from bits */
+template<typename Packet,typename BitsType> EIGEN_DEVICE_FUNC inline Packet
+pset1frombits(BitsType a);
+
+/** \internal \returns a packet with constant coefficients \a a[0], e.g.: (a[0],a[0],a[0],a[0]) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pload1(const typename unpacket_traits<Packet>::type *a) { return pset1<Packet>(*a); }
+
+/** \internal \returns a packet with elements of \a *from duplicated.
+ * For instance, for a packet of 8 elements, 4 scalars will be read from \a *from and
+ * duplicated to form: {from[0],from[0],from[1],from[1],from[2],from[2],from[3],from[3]}
+ * Currently, this function is only used for scalar * complex products.
+ */
+template<typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet
+ploaddup(const typename unpacket_traits<Packet>::type* from) { return *from; }
+
+/** \internal \returns a packet with elements of \a *from quadrupled.
+ * For instance, for a packet of 8 elements, 2 scalars will be read from \a *from and
+ * replicated to form: {from[0],from[0],from[0],from[0],from[1],from[1],from[1],from[1]}
+ * Currently, this function is only used in matrix products.
+ * For packet-size smaller or equal to 4, this function is equivalent to pload1
+ */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+ploadquad(const typename unpacket_traits<Packet>::type* from)
+{ return pload1<Packet>(from); }
+
+/** \internal equivalent to
+ * \code
+ * a0 = pload1(a+0);
+ * a1 = pload1(a+1);
+ * a2 = pload1(a+2);
+ * a3 = pload1(a+3);
+ * \endcode
+ * \sa pset1, pload1, ploaddup, pbroadcast2
+ */
+template<typename Packet> EIGEN_DEVICE_FUNC
+inline void pbroadcast4(const typename unpacket_traits<Packet>::type *a,
+ Packet& a0, Packet& a1, Packet& a2, Packet& a3)
+{
+ a0 = pload1<Packet>(a+0);
+ a1 = pload1<Packet>(a+1);
+ a2 = pload1<Packet>(a+2);
+ a3 = pload1<Packet>(a+3);
+}
+
+/** \internal equivalent to
+ * \code
+ * a0 = pload1(a+0);
+ * a1 = pload1(a+1);
+ * \endcode
+ * \sa pset1, pload1, ploaddup, pbroadcast4
+ */
+template<typename Packet> EIGEN_DEVICE_FUNC
+inline void pbroadcast2(const typename unpacket_traits<Packet>::type *a,
+ Packet& a0, Packet& a1)
+{
+ a0 = pload1<Packet>(a+0);
+ a1 = pload1<Packet>(a+1);
+}
+
+/** \internal \brief Returns a packet with coefficients (a,a+1,...,a+packet_size-1). */
+template<typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet
+plset(const typename unpacket_traits<Packet>::type& a) { return a; }
+
+/** \internal \returns a packet with constant coefficients \a a, e.g.: (x, 0, x, 0),
+ where x is the value of all 1-bits. */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+peven_mask(const Packet& /*a*/) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ const size_t n = unpacket_traits<Packet>::size;
+ EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) Scalar elements[n];
+ for(size_t i = 0; i < n; ++i) {
+ memset(elements+i, ((i & 1) == 0 ? 0xff : 0), sizeof(Scalar));
+ }
+ return ploadu<Packet>(elements);
+}
+
+
+/** \internal copy the packet \a from to \a *to, \a to must be 16 bytes aligned */
+template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline void pstore(Scalar* to, const Packet& from)
+{ (*to) = from; }
+
+/** \internal copy the packet \a from to \a *to, (un-aligned store) */
+template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline void pstoreu(Scalar* to, const Packet& from)
+{ (*to) = from; }
+
+/** \internal copy the packet \a from to \a *to, (un-aligned store with a mask)
+ * There is no generic implementation. We only have implementations for specialized
+ * cases. Generic case should not be called.
+ */
+template<typename Scalar, typename Packet>
+EIGEN_DEVICE_FUNC inline
+typename enable_if<unpacket_traits<Packet>::masked_store_available, void>::type
+pstoreu(Scalar* to, const Packet& from, typename unpacket_traits<Packet>::mask_t umask);
+
+ template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline Packet pgather(const Scalar* from, Index /*stride*/)
+ { return ploadu<Packet>(from); }
+
+ template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline void pscatter(Scalar* to, const Packet& from, Index /*stride*/)
+ { pstore(to, from); }
+
+/** \internal tries to do cache prefetching of \a addr */
+template<typename Scalar> EIGEN_DEVICE_FUNC inline void prefetch(const Scalar* addr)
+{
+#if defined(EIGEN_HIP_DEVICE_COMPILE)
+ // do nothing
+#elif defined(EIGEN_CUDA_ARCH)
+#if defined(__LP64__) || EIGEN_OS_WIN64
+ // 64-bit pointer operand constraint for inlined asm
+ asm(" prefetch.L1 [ %1 ];" : "=l"(addr) : "l"(addr));
+#else
+ // 32-bit pointer operand constraint for inlined asm
+ asm(" prefetch.L1 [ %1 ];" : "=r"(addr) : "r"(addr));
+#endif
+#elif (!EIGEN_COMP_MSVC) && (EIGEN_COMP_GNUC || EIGEN_COMP_CLANG || EIGEN_COMP_ICC)
+ __builtin_prefetch(addr);
+#endif
+}
+
+/** \internal \returns the reversed elements of \a a*/
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet preverse(const Packet& a)
+{ return a; }
+
+/** \internal \returns \a a with real and imaginary part flipped (for complex type only) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet pcplxflip(const Packet& a)
+{
+ return Packet(numext::imag(a),numext::real(a));
+}
+
+/**************************
+* Special math functions
+***************************/
+
+/** \internal \returns the sine of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet psin(const Packet& a) { EIGEN_USING_STD(sin); return sin(a); }
+
+/** \internal \returns the cosine of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet pcos(const Packet& a) { EIGEN_USING_STD(cos); return cos(a); }
+
+/** \internal \returns the tan of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet ptan(const Packet& a) { EIGEN_USING_STD(tan); return tan(a); }
+
+/** \internal \returns the arc sine of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet pasin(const Packet& a) { EIGEN_USING_STD(asin); return asin(a); }
+
+/** \internal \returns the arc cosine of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet pacos(const Packet& a) { EIGEN_USING_STD(acos); return acos(a); }
+
+/** \internal \returns the arc tangent of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet patan(const Packet& a) { EIGEN_USING_STD(atan); return atan(a); }
+
+/** \internal \returns the hyperbolic sine of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet psinh(const Packet& a) { EIGEN_USING_STD(sinh); return sinh(a); }
+
+/** \internal \returns the hyperbolic cosine of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet pcosh(const Packet& a) { EIGEN_USING_STD(cosh); return cosh(a); }
+
+/** \internal \returns the hyperbolic tan of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet ptanh(const Packet& a) { EIGEN_USING_STD(tanh); return tanh(a); }
+
+/** \internal \returns the exp of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet pexp(const Packet& a) { EIGEN_USING_STD(exp); return exp(a); }
+
+/** \internal \returns the expm1 of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet pexpm1(const Packet& a) { return numext::expm1(a); }
+
+/** \internal \returns the log of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet plog(const Packet& a) { EIGEN_USING_STD(log); return log(a); }
+
+/** \internal \returns the log1p of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet plog1p(const Packet& a) { return numext::log1p(a); }
+
+/** \internal \returns the log10 of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet plog10(const Packet& a) { EIGEN_USING_STD(log10); return log10(a); }
+
+/** \internal \returns the log10 of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet plog2(const Packet& a) {
+ typedef typename internal::unpacket_traits<Packet>::type Scalar;
+ return pmul(pset1<Packet>(Scalar(EIGEN_LOG2E)), plog(a));
+}
+
+/** \internal \returns the square-root of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet psqrt(const Packet& a) { return numext::sqrt(a); }
+
+/** \internal \returns the reciprocal square-root of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet prsqrt(const Packet& a) {
+ typedef typename internal::unpacket_traits<Packet>::type Scalar;
+ return pdiv(pset1<Packet>(Scalar(1)), psqrt(a));
+}
+
+/** \internal \returns the rounded value of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet pround(const Packet& a) { using numext::round; return round(a); }
+
+/** \internal \returns the floor of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet pfloor(const Packet& a) { using numext::floor; return floor(a); }
+
+/** \internal \returns the rounded value of \a a (coeff-wise) with current
+ * rounding mode */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet print(const Packet& a) { using numext::rint; return rint(a); }
+
+/** \internal \returns the ceil of \a a (coeff-wise) */
+template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+Packet pceil(const Packet& a) { using numext::ceil; return ceil(a); }
+
+/** \internal \returns the first element of a packet */
+template<typename Packet>
+EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type
+pfirst(const Packet& a)
+{ return a; }
+
+/** \internal \returns the sum of the elements of upper and lower half of \a a if \a a is larger than 4.
+ * For a packet {a0, a1, a2, a3, a4, a5, a6, a7}, it returns a half packet {a0+a4, a1+a5, a2+a6, a3+a7}
+ * For packet-size smaller or equal to 4, this boils down to a noop.
+ */
+template<typename Packet>
+EIGEN_DEVICE_FUNC inline typename conditional<(unpacket_traits<Packet>::size%8)==0,typename unpacket_traits<Packet>::half,Packet>::type
+predux_half_dowto4(const Packet& a)
+{ return a; }
+
+// Slow generic implementation of Packet reduction.
+template <typename Packet, typename Op>
+EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type
+predux_helper(const Packet& a, Op op) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ const size_t n = unpacket_traits<Packet>::size;
+ EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) Scalar elements[n];
+ pstoreu<Scalar>(elements, a);
+ for(size_t k = n / 2; k > 0; k /= 2) {
+ for(size_t i = 0; i < k; ++i) {
+ elements[i] = op(elements[i], elements[i + k]);
+ }
+ }
+ return elements[0];
+}
+
+/** \internal \returns the sum of the elements of \a a*/
+template<typename Packet>
+EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type
+predux(const Packet& a)
+{
+ return a;
+}
+
+/** \internal \returns the product of the elements of \a a */
+template <typename Packet>
+EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_mul(
+ const Packet& a) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmul<Scalar>)));
+}
+
+/** \internal \returns the min of the elements of \a a */
+template <typename Packet>
+EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_min(
+ const Packet &a) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmin<PropagateFast, Scalar>)));
+}
+
+template <int NaNPropagation, typename Packet>
+EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_min(
+ const Packet& a) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmin<NaNPropagation, Scalar>)));
+}
+
+/** \internal \returns the min of the elements of \a a */
+template <typename Packet>
+EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_max(
+ const Packet &a) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmax<PropagateFast, Scalar>)));
+}
+
+template <int NaNPropagation, typename Packet>
+EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_max(
+ const Packet& a) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmax<NaNPropagation, Scalar>)));
+}
+
+#undef EIGEN_BINARY_OP_NAN_PROPAGATION
+
+/** \internal \returns true if all coeffs of \a a means "true"
+ * It is supposed to be called on values returned by pcmp_*.
+ */
+// not needed yet
+// template<typename Packet> EIGEN_DEVICE_FUNC inline bool predux_all(const Packet& a)
+// { return bool(a); }
+
+/** \internal \returns true if any coeffs of \a a means "true"
+ * It is supposed to be called on values returned by pcmp_*.
+ */
+template<typename Packet> EIGEN_DEVICE_FUNC inline bool predux_any(const Packet& a)
+{
+ // Dirty but generic implementation where "true" is assumed to be non 0 and all the sames.
+ // It is expected that "true" is either:
+ // - Scalar(1)
+ // - bits full of ones (NaN for floats),
+ // - or first bit equals to 1 (1 for ints, smallest denormal for floats).
+ // For all these cases, taking the sum is just fine, and this boils down to a no-op for scalars.
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ return numext::not_equal_strict(predux(a), Scalar(0));
+}
+
+/***************************************************************************
+* The following functions might not have to be overwritten for vectorized types
+***************************************************************************/
+
+/** \internal copy a packet with constant coefficient \a a (e.g., [a,a,a,a]) to \a *to. \a to must be 16 bytes aligned */
+// NOTE: this function must really be templated on the packet type (think about different packet types for the same scalar type)
+template<typename Packet>
+inline void pstore1(typename unpacket_traits<Packet>::type* to, const typename unpacket_traits<Packet>::type& a)
+{
+ pstore(to, pset1<Packet>(a));
+}
+
+/** \internal \returns a * b + c (coeff-wise) */
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pmadd(const Packet& a,
+ const Packet& b,
+ const Packet& c)
+{ return padd(pmul(a, b),c); }
+
+/** \internal \returns a packet version of \a *from.
+ * The pointer \a from must be aligned on a \a Alignment bytes boundary. */
+template<typename Packet, int Alignment>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet ploadt(const typename unpacket_traits<Packet>::type* from)
+{
+ if(Alignment >= unpacket_traits<Packet>::alignment)
+ return pload<Packet>(from);
+ else
+ return ploadu<Packet>(from);
+}
+
+/** \internal copy the packet \a from to \a *to.
+ * The pointer \a from must be aligned on a \a Alignment bytes boundary. */
+template<typename Scalar, typename Packet, int Alignment>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstoret(Scalar* to, const Packet& from)
+{
+ if(Alignment >= unpacket_traits<Packet>::alignment)
+ pstore(to, from);
+ else
+ pstoreu(to, from);
+}
+
+/** \internal \returns a packet version of \a *from.
+ * Unlike ploadt, ploadt_ro takes advantage of the read-only memory path on the
+ * hardware if available to speedup the loading of data that won't be modified
+ * by the current computation.
+ */
+template<typename Packet, int LoadMode>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet ploadt_ro(const typename unpacket_traits<Packet>::type* from)
+{
+ return ploadt<Packet, LoadMode>(from);
+}
+
+/***************************************************************************
+* Fast complex products (GCC generates a function call which is very slow)
+***************************************************************************/
+
+// Eigen+CUDA does not support complexes.
+#if !defined(EIGEN_GPUCC)
+
+template<> inline std::complex<float> pmul(const std::complex<float>& a, const std::complex<float>& b)
+{ return std::complex<float>(a.real()*b.real() - a.imag()*b.imag(), a.imag()*b.real() + a.real()*b.imag()); }
+
+template<> inline std::complex<double> pmul(const std::complex<double>& a, const std::complex<double>& b)
+{ return std::complex<double>(a.real()*b.real() - a.imag()*b.imag(), a.imag()*b.real() + a.real()*b.imag()); }
+
+#endif
+
+
+/***************************************************************************
+ * PacketBlock, that is a collection of N packets where the number of words
+ * in the packet is a multiple of N.
+***************************************************************************/
+template <typename Packet,int N=unpacket_traits<Packet>::size> struct PacketBlock {
+ Packet packet[N];
+};
+
+template<typename Packet> EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet,1>& /*kernel*/) {
+ // Nothing to do in the scalar case, i.e. a 1x1 matrix.
+}
+
+/***************************************************************************
+ * Selector, i.e. vector of N boolean values used to select (i.e. blend)
+ * words from 2 packets.
+***************************************************************************/
+template <size_t N> struct Selector {
+ bool select[N];
+};
+
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
+pblend(const Selector<unpacket_traits<Packet>::size>& ifPacket, const Packet& thenPacket, const Packet& elsePacket) {
+ return ifPacket.select[0] ? thenPacket : elsePacket;
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_GENERIC_PACKET_MATH_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/GlobalFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/GlobalFunctions.h
new file mode 100644
index 000000000..629af94b9
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/GlobalFunctions.h
@@ -0,0 +1,194 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2010-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GLOBAL_FUNCTIONS_H
+#define EIGEN_GLOBAL_FUNCTIONS_H
+
+#ifdef EIGEN_PARSED_BY_DOXYGEN
+
+#define EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(NAME,FUNCTOR,DOC_OP,DOC_DETAILS) \
+ /** \returns an expression of the coefficient-wise DOC_OP of \a x
+
+ DOC_DETAILS
+
+ \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_##NAME">Math functions</a>, class CwiseUnaryOp
+ */ \
+ template<typename Derived> \
+ inline const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> \
+ NAME(const Eigen::ArrayBase<Derived>& x);
+
+#else
+
+#define EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(NAME,FUNCTOR,DOC_OP,DOC_DETAILS) \
+ template<typename Derived> \
+ inline const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> \
+ (NAME)(const Eigen::ArrayBase<Derived>& x) { \
+ return Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived>(x.derived()); \
+ }
+
+#endif // EIGEN_PARSED_BY_DOXYGEN
+
+#define EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(NAME,FUNCTOR) \
+ \
+ template<typename Derived> \
+ struct NAME##_retval<ArrayBase<Derived> > \
+ { \
+ typedef const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> type; \
+ }; \
+ template<typename Derived> \
+ struct NAME##_impl<ArrayBase<Derived> > \
+ { \
+ static inline typename NAME##_retval<ArrayBase<Derived> >::type run(const Eigen::ArrayBase<Derived>& x) \
+ { \
+ return typename NAME##_retval<ArrayBase<Derived> >::type(x.derived()); \
+ } \
+ };
+
+namespace Eigen
+{
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(real,scalar_real_op,real part,\sa ArrayBase::real)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(imag,scalar_imag_op,imaginary part,\sa ArrayBase::imag)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(conj,scalar_conjugate_op,complex conjugate,\sa ArrayBase::conjugate)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(inverse,scalar_inverse_op,inverse,\sa ArrayBase::inverse)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sin,scalar_sin_op,sine,\sa ArrayBase::sin)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cos,scalar_cos_op,cosine,\sa ArrayBase::cos)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tan,scalar_tan_op,tangent,\sa ArrayBase::tan)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atan,scalar_atan_op,arc-tangent,\sa ArrayBase::atan)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asin,scalar_asin_op,arc-sine,\sa ArrayBase::asin)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acos,scalar_acos_op,arc-consine,\sa ArrayBase::acos)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sinh,scalar_sinh_op,hyperbolic sine,\sa ArrayBase::sinh)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cosh,scalar_cosh_op,hyperbolic cosine,\sa ArrayBase::cosh)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tanh,scalar_tanh_op,hyperbolic tangent,\sa ArrayBase::tanh)
+#if EIGEN_HAS_CXX11_MATH
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asinh,scalar_asinh_op,inverse hyperbolic sine,\sa ArrayBase::asinh)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acosh,scalar_acosh_op,inverse hyperbolic cosine,\sa ArrayBase::acosh)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atanh,scalar_atanh_op,inverse hyperbolic tangent,\sa ArrayBase::atanh)
+#endif
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(logistic,scalar_logistic_op,logistic function,\sa ArrayBase::logistic)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(lgamma,scalar_lgamma_op,natural logarithm of the gamma function,\sa ArrayBase::lgamma)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(digamma,scalar_digamma_op,derivative of lgamma,\sa ArrayBase::digamma)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erf,scalar_erf_op,error function,\sa ArrayBase::erf)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erfc,scalar_erfc_op,complement error function,\sa ArrayBase::erfc)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ndtri,scalar_ndtri_op,inverse normal distribution function,\sa ArrayBase::ndtri)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(exp,scalar_exp_op,exponential,\sa ArrayBase::exp)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(expm1,scalar_expm1_op,exponential of a value minus 1,\sa ArrayBase::expm1)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log,scalar_log_op,natural logarithm,\sa Eigen::log10 DOXCOMMA ArrayBase::log)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log1p,scalar_log1p_op,natural logarithm of 1 plus the value,\sa ArrayBase::log1p)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log10,scalar_log10_op,base 10 logarithm,\sa Eigen::log DOXCOMMA ArrayBase::log10)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log2,scalar_log2_op,base 2 logarithm,\sa Eigen::log DOXCOMMA ArrayBase::log2)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs,scalar_abs_op,absolute value,\sa ArrayBase::abs DOXCOMMA MatrixBase::cwiseAbs)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs2,scalar_abs2_op,squared absolute value,\sa ArrayBase::abs2 DOXCOMMA MatrixBase::cwiseAbs2)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(arg,scalar_arg_op,complex argument,\sa ArrayBase::arg DOXCOMMA MatrixBase::cwiseArg)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sqrt,scalar_sqrt_op,square root,\sa ArrayBase::sqrt DOXCOMMA MatrixBase::cwiseSqrt)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(rsqrt,scalar_rsqrt_op,reciprocal square root,\sa ArrayBase::rsqrt)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(square,scalar_square_op,square (power 2),\sa Eigen::abs2 DOXCOMMA Eigen::pow DOXCOMMA ArrayBase::square)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cube,scalar_cube_op,cube (power 3),\sa Eigen::pow DOXCOMMA ArrayBase::cube)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(rint,scalar_rint_op,nearest integer,\sa Eigen::floor DOXCOMMA Eigen::ceil DOXCOMMA ArrayBase::round)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(round,scalar_round_op,nearest integer,\sa Eigen::floor DOXCOMMA Eigen::ceil DOXCOMMA ArrayBase::round)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(floor,scalar_floor_op,nearest integer not greater than the giben value,\sa Eigen::ceil DOXCOMMA ArrayBase::floor)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ceil,scalar_ceil_op,nearest integer not less than the giben value,\sa Eigen::floor DOXCOMMA ArrayBase::ceil)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isnan,scalar_isnan_op,not-a-number test,\sa Eigen::isinf DOXCOMMA Eigen::isfinite DOXCOMMA ArrayBase::isnan)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isinf,scalar_isinf_op,infinite value test,\sa Eigen::isnan DOXCOMMA Eigen::isfinite DOXCOMMA ArrayBase::isinf)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isfinite,scalar_isfinite_op,finite value test,\sa Eigen::isinf DOXCOMMA Eigen::isnan DOXCOMMA ArrayBase::isfinite)
+ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sign,scalar_sign_op,sign (or 0),\sa ArrayBase::sign)
+
+ /** \returns an expression of the coefficient-wise power of \a x to the given constant \a exponent.
+ *
+ * \tparam ScalarExponent is the scalar type of \a exponent. It must be compatible with the scalar type of the given expression (\c Derived::Scalar).
+ *
+ * \sa ArrayBase::pow()
+ *
+ * \relates ArrayBase
+ */
+#ifdef EIGEN_PARSED_BY_DOXYGEN
+ template<typename Derived,typename ScalarExponent>
+ inline const CwiseBinaryOp<internal::scalar_pow_op<Derived::Scalar,ScalarExponent>,Derived,Constant<ScalarExponent> >
+ pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent);
+#else
+ template <typename Derived,typename ScalarExponent>
+ EIGEN_DEVICE_FUNC inline
+ EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(
+ const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename internal::promote_scalar_arg<typename Derived::Scalar
+ EIGEN_COMMA ScalarExponent EIGEN_COMMA
+ EIGEN_SCALAR_BINARY_SUPPORTED(pow,typename Derived::Scalar,ScalarExponent)>::type,pow))
+ pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent)
+ {
+ typedef typename internal::promote_scalar_arg<typename Derived::Scalar,ScalarExponent,
+ EIGEN_SCALAR_BINARY_SUPPORTED(pow,typename Derived::Scalar,ScalarExponent)>::type PromotedExponent;
+ return EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,PromotedExponent,pow)(x.derived(),
+ typename internal::plain_constant_type<Derived,PromotedExponent>::type(x.derived().rows(), x.derived().cols(), internal::scalar_constant_op<PromotedExponent>(exponent)));
+ }
+#endif
+
+ /** \returns an expression of the coefficient-wise power of \a x to the given array of \a exponents.
+ *
+ * This function computes the coefficient-wise power.
+ *
+ * Example: \include Cwise_array_power_array.cpp
+ * Output: \verbinclude Cwise_array_power_array.out
+ *
+ * \sa ArrayBase::pow()
+ *
+ * \relates ArrayBase
+ */
+ template<typename Derived,typename ExponentDerived>
+ inline const Eigen::CwiseBinaryOp<Eigen::internal::scalar_pow_op<typename Derived::Scalar, typename ExponentDerived::Scalar>, const Derived, const ExponentDerived>
+ pow(const Eigen::ArrayBase<Derived>& x, const Eigen::ArrayBase<ExponentDerived>& exponents)
+ {
+ return Eigen::CwiseBinaryOp<Eigen::internal::scalar_pow_op<typename Derived::Scalar, typename ExponentDerived::Scalar>, const Derived, const ExponentDerived>(
+ x.derived(),
+ exponents.derived()
+ );
+ }
+
+ /** \returns an expression of the coefficient-wise power of the scalar \a x to the given array of \a exponents.
+ *
+ * This function computes the coefficient-wise power between a scalar and an array of exponents.
+ *
+ * \tparam Scalar is the scalar type of \a x. It must be compatible with the scalar type of the given array expression (\c Derived::Scalar).
+ *
+ * Example: \include Cwise_scalar_power_array.cpp
+ * Output: \verbinclude Cwise_scalar_power_array.out
+ *
+ * \sa ArrayBase::pow()
+ *
+ * \relates ArrayBase
+ */
+#ifdef EIGEN_PARSED_BY_DOXYGEN
+ template<typename Scalar,typename Derived>
+ inline const CwiseBinaryOp<internal::scalar_pow_op<Scalar,Derived::Scalar>,Constant<Scalar>,Derived>
+ pow(const Scalar& x,const Eigen::ArrayBase<Derived>& x);
+#else
+ template <typename Scalar, typename Derived>
+ EIGEN_DEVICE_FUNC inline
+ EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(
+ const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename internal::promote_scalar_arg<typename Derived::Scalar
+ EIGEN_COMMA Scalar EIGEN_COMMA
+ EIGEN_SCALAR_BINARY_SUPPORTED(pow,Scalar,typename Derived::Scalar)>::type,Derived,pow))
+ pow(const Scalar& x, const Eigen::ArrayBase<Derived>& exponents) {
+ typedef typename internal::promote_scalar_arg<typename Derived::Scalar,Scalar,
+ EIGEN_SCALAR_BINARY_SUPPORTED(pow,Scalar,typename Derived::Scalar)>::type PromotedScalar;
+ return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(PromotedScalar,Derived,pow)(
+ typename internal::plain_constant_type<Derived,PromotedScalar>::type(exponents.derived().rows(), exponents.derived().cols(), internal::scalar_constant_op<PromotedScalar>(x)), exponents.derived());
+ }
+#endif
+
+
+ namespace internal
+ {
+ EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(real,scalar_real_op)
+ EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(imag,scalar_imag_op)
+ EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(abs2,scalar_abs2_op)
+ }
+}
+
+// TODO: cleanly disable those functions that are not supported on Array (numext::real_ref, internal::random, internal::isApprox...)
+
+#endif // EIGEN_GLOBAL_FUNCTIONS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/IO.h b/src/3rdparty/eigen/Eigen/src/Core/IO.h
new file mode 100644
index 000000000..e81c31521
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/IO.h
@@ -0,0 +1,258 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_IO_H
+#define EIGEN_IO_H
+
+namespace Eigen {
+
+enum { DontAlignCols = 1 };
+enum { StreamPrecision = -1,
+ FullPrecision = -2 };
+
+namespace internal {
+template<typename Derived>
+std::ostream & print_matrix(std::ostream & s, const Derived& _m, const IOFormat& fmt);
+}
+
+/** \class IOFormat
+ * \ingroup Core_Module
+ *
+ * \brief Stores a set of parameters controlling the way matrices are printed
+ *
+ * List of available parameters:
+ * - \b precision number of digits for floating point values, or one of the special constants \c StreamPrecision and \c FullPrecision.
+ * The default is the special value \c StreamPrecision which means to use the
+ * stream's own precision setting, as set for instance using \c cout.precision(3). The other special value
+ * \c FullPrecision means that the number of digits will be computed to match the full precision of each floating-point
+ * type.
+ * - \b flags an OR-ed combination of flags, the default value is 0, the only currently available flag is \c DontAlignCols which
+ * allows to disable the alignment of columns, resulting in faster code.
+ * - \b coeffSeparator string printed between two coefficients of the same row
+ * - \b rowSeparator string printed between two rows
+ * - \b rowPrefix string printed at the beginning of each row
+ * - \b rowSuffix string printed at the end of each row
+ * - \b matPrefix string printed at the beginning of the matrix
+ * - \b matSuffix string printed at the end of the matrix
+ * - \b fill character printed to fill the empty space in aligned columns
+ *
+ * Example: \include IOFormat.cpp
+ * Output: \verbinclude IOFormat.out
+ *
+ * \sa DenseBase::format(), class WithFormat
+ */
+struct IOFormat
+{
+ /** Default constructor, see class IOFormat for the meaning of the parameters */
+ IOFormat(int _precision = StreamPrecision, int _flags = 0,
+ const std::string& _coeffSeparator = " ",
+ const std::string& _rowSeparator = "\n", const std::string& _rowPrefix="", const std::string& _rowSuffix="",
+ const std::string& _matPrefix="", const std::string& _matSuffix="", const char _fill=' ')
+ : matPrefix(_matPrefix), matSuffix(_matSuffix), rowPrefix(_rowPrefix), rowSuffix(_rowSuffix), rowSeparator(_rowSeparator),
+ rowSpacer(""), coeffSeparator(_coeffSeparator), fill(_fill), precision(_precision), flags(_flags)
+ {
+ // TODO check if rowPrefix, rowSuffix or rowSeparator contains a newline
+ // don't add rowSpacer if columns are not to be aligned
+ if((flags & DontAlignCols))
+ return;
+ int i = int(matSuffix.length())-1;
+ while (i>=0 && matSuffix[i]!='\n')
+ {
+ rowSpacer += ' ';
+ i--;
+ }
+ }
+ std::string matPrefix, matSuffix;
+ std::string rowPrefix, rowSuffix, rowSeparator, rowSpacer;
+ std::string coeffSeparator;
+ char fill;
+ int precision;
+ int flags;
+};
+
+/** \class WithFormat
+ * \ingroup Core_Module
+ *
+ * \brief Pseudo expression providing matrix output with given format
+ *
+ * \tparam ExpressionType the type of the object on which IO stream operations are performed
+ *
+ * This class represents an expression with stream operators controlled by a given IOFormat.
+ * It is the return type of DenseBase::format()
+ * and most of the time this is the only way it is used.
+ *
+ * See class IOFormat for some examples.
+ *
+ * \sa DenseBase::format(), class IOFormat
+ */
+template<typename ExpressionType>
+class WithFormat
+{
+ public:
+
+ WithFormat(const ExpressionType& matrix, const IOFormat& format)
+ : m_matrix(matrix), m_format(format)
+ {}
+
+ friend std::ostream & operator << (std::ostream & s, const WithFormat& wf)
+ {
+ return internal::print_matrix(s, wf.m_matrix.eval(), wf.m_format);
+ }
+
+ protected:
+ typename ExpressionType::Nested m_matrix;
+ IOFormat m_format;
+};
+
+namespace internal {
+
+// NOTE: This helper is kept for backward compatibility with previous code specializing
+// this internal::significant_decimals_impl structure. In the future we should directly
+// call digits10() which has been introduced in July 2016 in 3.3.
+template<typename Scalar>
+struct significant_decimals_impl
+{
+ static inline int run()
+ {
+ return NumTraits<Scalar>::digits10();
+ }
+};
+
+/** \internal
+ * print the matrix \a _m to the output stream \a s using the output format \a fmt */
+template<typename Derived>
+std::ostream & print_matrix(std::ostream & s, const Derived& _m, const IOFormat& fmt)
+{
+ using internal::is_same;
+ using internal::conditional;
+
+ if(_m.size() == 0)
+ {
+ s << fmt.matPrefix << fmt.matSuffix;
+ return s;
+ }
+
+ typename Derived::Nested m = _m;
+ typedef typename Derived::Scalar Scalar;
+ typedef typename
+ conditional<
+ is_same<Scalar, char>::value ||
+ is_same<Scalar, unsigned char>::value ||
+ is_same<Scalar, numext::int8_t>::value ||
+ is_same<Scalar, numext::uint8_t>::value,
+ int,
+ typename conditional<
+ is_same<Scalar, std::complex<char> >::value ||
+ is_same<Scalar, std::complex<unsigned char> >::value ||
+ is_same<Scalar, std::complex<numext::int8_t> >::value ||
+ is_same<Scalar, std::complex<numext::uint8_t> >::value,
+ std::complex<int>,
+ const Scalar&
+ >::type
+ >::type PrintType;
+
+ Index width = 0;
+
+ std::streamsize explicit_precision;
+ if(fmt.precision == StreamPrecision)
+ {
+ explicit_precision = 0;
+ }
+ else if(fmt.precision == FullPrecision)
+ {
+ if (NumTraits<Scalar>::IsInteger)
+ {
+ explicit_precision = 0;
+ }
+ else
+ {
+ explicit_precision = significant_decimals_impl<Scalar>::run();
+ }
+ }
+ else
+ {
+ explicit_precision = fmt.precision;
+ }
+
+ std::streamsize old_precision = 0;
+ if(explicit_precision) old_precision = s.precision(explicit_precision);
+
+ bool align_cols = !(fmt.flags & DontAlignCols);
+ if(align_cols)
+ {
+ // compute the largest width
+ for(Index j = 0; j < m.cols(); ++j)
+ for(Index i = 0; i < m.rows(); ++i)
+ {
+ std::stringstream sstr;
+ sstr.copyfmt(s);
+ sstr << static_cast<PrintType>(m.coeff(i,j));
+ width = std::max<Index>(width, Index(sstr.str().length()));
+ }
+ }
+ std::streamsize old_width = s.width();
+ char old_fill_character = s.fill();
+ s << fmt.matPrefix;
+ for(Index i = 0; i < m.rows(); ++i)
+ {
+ if (i)
+ s << fmt.rowSpacer;
+ s << fmt.rowPrefix;
+ if(width) {
+ s.fill(fmt.fill);
+ s.width(width);
+ }
+ s << static_cast<PrintType>(m.coeff(i, 0));
+ for(Index j = 1; j < m.cols(); ++j)
+ {
+ s << fmt.coeffSeparator;
+ if(width) {
+ s.fill(fmt.fill);
+ s.width(width);
+ }
+ s << static_cast<PrintType>(m.coeff(i, j));
+ }
+ s << fmt.rowSuffix;
+ if( i < m.rows() - 1)
+ s << fmt.rowSeparator;
+ }
+ s << fmt.matSuffix;
+ if(explicit_precision) s.precision(old_precision);
+ if(width) {
+ s.fill(old_fill_character);
+ s.width(old_width);
+ }
+ return s;
+}
+
+} // end namespace internal
+
+/** \relates DenseBase
+ *
+ * Outputs the matrix, to the given stream.
+ *
+ * If you wish to print the matrix with a format different than the default, use DenseBase::format().
+ *
+ * It is also possible to change the default format by defining EIGEN_DEFAULT_IO_FORMAT before including Eigen headers.
+ * If not defined, this will automatically be defined to Eigen::IOFormat(), that is the Eigen::IOFormat with default parameters.
+ *
+ * \sa DenseBase::format()
+ */
+template<typename Derived>
+std::ostream & operator <<
+(std::ostream & s,
+ const DenseBase<Derived> & m)
+{
+ return internal::print_matrix(s, m.eval(), EIGEN_DEFAULT_IO_FORMAT);
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_IO_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/IndexedView.h b/src/3rdparty/eigen/Eigen/src/Core/IndexedView.h
new file mode 100644
index 000000000..08476251d
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/IndexedView.h
@@ -0,0 +1,237 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_INDEXED_VIEW_H
+#define EIGEN_INDEXED_VIEW_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename XprType, typename RowIndices, typename ColIndices>
+struct traits<IndexedView<XprType, RowIndices, ColIndices> >
+ : traits<XprType>
+{
+ enum {
+ RowsAtCompileTime = int(array_size<RowIndices>::value),
+ ColsAtCompileTime = int(array_size<ColIndices>::value),
+ MaxRowsAtCompileTime = RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) : Dynamic,
+ MaxColsAtCompileTime = ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) : Dynamic,
+
+ XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0,
+ IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
+ : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
+ : XprTypeIsRowMajor,
+
+ RowIncr = int(get_compile_time_incr<RowIndices>::value),
+ ColIncr = int(get_compile_time_incr<ColIndices>::value),
+ InnerIncr = IsRowMajor ? ColIncr : RowIncr,
+ OuterIncr = IsRowMajor ? RowIncr : ColIncr,
+
+ HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
+ XprInnerStride = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time<XprType>::ret) : int(outer_stride_at_compile_time<XprType>::ret),
+ XprOuterstride = HasSameStorageOrderAsXprType ? int(outer_stride_at_compile_time<XprType>::ret) : int(inner_stride_at_compile_time<XprType>::ret),
+
+ InnerSize = XprTypeIsRowMajor ? ColsAtCompileTime : RowsAtCompileTime,
+ IsBlockAlike = InnerIncr==1 && OuterIncr==1,
+ IsInnerPannel = HasSameStorageOrderAsXprType && is_same<AllRange<InnerSize>,typename conditional<XprTypeIsRowMajor,ColIndices,RowIndices>::type>::value,
+
+ InnerStrideAtCompileTime = InnerIncr<0 || InnerIncr==DynamicIndex || XprInnerStride==Dynamic ? Dynamic : XprInnerStride * InnerIncr,
+ OuterStrideAtCompileTime = OuterIncr<0 || OuterIncr==DynamicIndex || XprOuterstride==Dynamic ? Dynamic : XprOuterstride * OuterIncr,
+
+ ReturnAsScalar = is_same<RowIndices,SingleRange>::value && is_same<ColIndices,SingleRange>::value,
+ ReturnAsBlock = (!ReturnAsScalar) && IsBlockAlike,
+ ReturnAsIndexedView = (!ReturnAsScalar) && (!ReturnAsBlock),
+
+ // FIXME we deal with compile-time strides if and only if we have DirectAccessBit flag,
+ // but this is too strict regarding negative strides...
+ DirectAccessMask = (int(InnerIncr)!=UndefinedIncr && int(OuterIncr)!=UndefinedIncr && InnerIncr>=0 && OuterIncr>=0) ? DirectAccessBit : 0,
+ FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0,
+ FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
+ FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
+ Flags = (traits<XprType>::Flags & (HereditaryBits | DirectAccessMask )) | FlagsLvalueBit | FlagsRowMajorBit | FlagsLinearAccessBit
+ };
+
+ typedef Block<XprType,RowsAtCompileTime,ColsAtCompileTime,IsInnerPannel> BlockType;
+};
+
+}
+
+template<typename XprType, typename RowIndices, typename ColIndices, typename StorageKind>
+class IndexedViewImpl;
+
+
+/** \class IndexedView
+ * \ingroup Core_Module
+ *
+ * \brief Expression of a non-sequential sub-matrix defined by arbitrary sequences of row and column indices
+ *
+ * \tparam XprType the type of the expression in which we are taking the intersections of sub-rows and sub-columns
+ * \tparam RowIndices the type of the object defining the sequence of row indices
+ * \tparam ColIndices the type of the object defining the sequence of column indices
+ *
+ * This class represents an expression of a sub-matrix (or sub-vector) defined as the intersection
+ * of sub-sets of rows and columns, that are themself defined by generic sequences of row indices \f$ \{r_0,r_1,..r_{m-1}\} \f$
+ * and column indices \f$ \{c_0,c_1,..c_{n-1} \}\f$. Let \f$ A \f$ be the nested matrix, then the resulting matrix \f$ B \f$ has \c m
+ * rows and \c n columns, and its entries are given by: \f$ B(i,j) = A(r_i,c_j) \f$.
+ *
+ * The \c RowIndices and \c ColIndices types must be compatible with the following API:
+ * \code
+ * <integral type> operator[](Index) const;
+ * Index size() const;
+ * \endcode
+ *
+ * Typical supported types thus include:
+ * - std::vector<int>
+ * - std::valarray<int>
+ * - std::array<int>
+ * - Plain C arrays: int[N]
+ * - Eigen::ArrayXi
+ * - decltype(ArrayXi::LinSpaced(...))
+ * - Any view/expressions of the previous types
+ * - Eigen::ArithmeticSequence
+ * - Eigen::internal::AllRange (helper for Eigen::all)
+ * - Eigen::internal::SingleRange (helper for single index)
+ * - etc.
+ *
+ * In typical usages of %Eigen, this class should never be used directly. It is the return type of
+ * DenseBase::operator()(const RowIndices&, const ColIndices&).
+ *
+ * \sa class Block
+ */
+template<typename XprType, typename RowIndices, typename ColIndices>
+class IndexedView : public IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>
+{
+public:
+ typedef typename IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>::Base Base;
+ EIGEN_GENERIC_PUBLIC_INTERFACE(IndexedView)
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndexedView)
+
+ typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested;
+ typedef typename internal::remove_all<XprType>::type NestedExpression;
+
+ template<typename T0, typename T1>
+ IndexedView(XprType& xpr, const T0& rowIndices, const T1& colIndices)
+ : m_xpr(xpr), m_rowIndices(rowIndices), m_colIndices(colIndices)
+ {}
+
+ /** \returns number of rows */
+ Index rows() const { return internal::size(m_rowIndices); }
+
+ /** \returns number of columns */
+ Index cols() const { return internal::size(m_colIndices); }
+
+ /** \returns the nested expression */
+ const typename internal::remove_all<XprType>::type&
+ nestedExpression() const { return m_xpr; }
+
+ /** \returns the nested expression */
+ typename internal::remove_reference<XprType>::type&
+ nestedExpression() { return m_xpr; }
+
+ /** \returns a const reference to the object storing/generating the row indices */
+ const RowIndices& rowIndices() const { return m_rowIndices; }
+
+ /** \returns a const reference to the object storing/generating the column indices */
+ const ColIndices& colIndices() const { return m_colIndices; }
+
+protected:
+ MatrixTypeNested m_xpr;
+ RowIndices m_rowIndices;
+ ColIndices m_colIndices;
+};
+
+
+// Generic API dispatcher
+template<typename XprType, typename RowIndices, typename ColIndices, typename StorageKind>
+class IndexedViewImpl
+ : public internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type
+{
+public:
+ typedef typename internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type Base;
+};
+
+namespace internal {
+
+
+template<typename ArgType, typename RowIndices, typename ColIndices>
+struct unary_evaluator<IndexedView<ArgType, RowIndices, ColIndices>, IndexBased>
+ : evaluator_base<IndexedView<ArgType, RowIndices, ColIndices> >
+{
+ typedef IndexedView<ArgType, RowIndices, ColIndices> XprType;
+
+ enum {
+ CoeffReadCost = evaluator<ArgType>::CoeffReadCost /* TODO + cost of row/col index */,
+
+ FlagsLinearAccessBit = (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1) ? LinearAccessBit : 0,
+
+ FlagsRowMajorBit = traits<XprType>::FlagsRowMajorBit,
+
+ Flags = (evaluator<ArgType>::Flags & (HereditaryBits & ~RowMajorBit /*| LinearAccessBit | DirectAccessBit*/)) | FlagsLinearAccessBit | FlagsRowMajorBit,
+
+ Alignment = 0
+ };
+
+ EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr)
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ typedef typename XprType::Scalar Scalar;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index row, Index col)
+ {
+ return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Scalar& coeffRef(Index index)
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(XprType)
+ Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
+ Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
+ return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const Scalar& coeffRef(Index index) const
+ {
+ Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
+ Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
+ return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const CoeffReturnType coeff(Index index) const
+ {
+ Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
+ Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
+ return m_argImpl.coeff( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
+ }
+
+protected:
+
+ evaluator<ArgType> m_argImpl;
+ const XprType& m_xpr;
+
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_INDEXED_VIEW_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Inverse.h b/src/3rdparty/eigen/Eigen/src/Core/Inverse.h
new file mode 100644
index 000000000..c514438c4
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Inverse.h
@@ -0,0 +1,117 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2014-2019 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_INVERSE_H
+#define EIGEN_INVERSE_H
+
+namespace Eigen {
+
+template<typename XprType,typename StorageKind> class InverseImpl;
+
+namespace internal {
+
+template<typename XprType>
+struct traits<Inverse<XprType> >
+ : traits<typename XprType::PlainObject>
+{
+ typedef typename XprType::PlainObject PlainObject;
+ typedef traits<PlainObject> BaseTraits;
+ enum {
+ Flags = BaseTraits::Flags & RowMajorBit
+ };
+};
+
+} // end namespace internal
+
+/** \class Inverse
+ *
+ * \brief Expression of the inverse of another expression
+ *
+ * \tparam XprType the type of the expression we are taking the inverse
+ *
+ * This class represents an abstract expression of A.inverse()
+ * and most of the time this is the only way it is used.
+ *
+ */
+template<typename XprType>
+class Inverse : public InverseImpl<XprType,typename internal::traits<XprType>::StorageKind>
+{
+public:
+ typedef typename XprType::StorageIndex StorageIndex;
+ typedef typename XprType::Scalar Scalar;
+ typedef typename internal::ref_selector<XprType>::type XprTypeNested;
+ typedef typename internal::remove_all<XprTypeNested>::type XprTypeNestedCleaned;
+ typedef typename internal::ref_selector<Inverse>::type Nested;
+ typedef typename internal::remove_all<XprType>::type NestedExpression;
+
+ explicit EIGEN_DEVICE_FUNC Inverse(const XprType &xpr)
+ : m_xpr(xpr)
+ {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_xpr.cols(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_xpr.rows(); }
+
+ EIGEN_DEVICE_FUNC const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; }
+
+protected:
+ XprTypeNested m_xpr;
+};
+
+// Generic API dispatcher
+template<typename XprType, typename StorageKind>
+class InverseImpl
+ : public internal::generic_xpr_base<Inverse<XprType> >::type
+{
+public:
+ typedef typename internal::generic_xpr_base<Inverse<XprType> >::type Base;
+ typedef typename XprType::Scalar Scalar;
+private:
+
+ Scalar coeff(Index row, Index col) const;
+ Scalar coeff(Index i) const;
+};
+
+namespace internal {
+
+/** \internal
+ * \brief Default evaluator for Inverse expression.
+ *
+ * This default evaluator for Inverse expression simply evaluate the inverse into a temporary
+ * by a call to internal::call_assignment_no_alias.
+ * Therefore, inverse implementers only have to specialize Assignment<Dst,Inverse<...>, ...> for
+ * there own nested expression.
+ *
+ * \sa class Inverse
+ */
+template<typename ArgType>
+struct unary_evaluator<Inverse<ArgType> >
+ : public evaluator<typename Inverse<ArgType>::PlainObject>
+{
+ typedef Inverse<ArgType> InverseType;
+ typedef typename InverseType::PlainObject PlainObject;
+ typedef evaluator<PlainObject> Base;
+
+ enum { Flags = Base::Flags | EvalBeforeNestingBit };
+
+ unary_evaluator(const InverseType& inv_xpr)
+ : m_result(inv_xpr.rows(), inv_xpr.cols())
+ {
+ ::new (static_cast<Base*>(this)) Base(m_result);
+ internal::call_assignment_no_alias(m_result, inv_xpr);
+ }
+
+protected:
+ PlainObject m_result;
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_INVERSE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Map.h b/src/3rdparty/eigen/Eigen/src/Core/Map.h
new file mode 100644
index 000000000..218cc157f
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Map.h
@@ -0,0 +1,171 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MAP_H
+#define EIGEN_MAP_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename PlainObjectType, int MapOptions, typename StrideType>
+struct traits<Map<PlainObjectType, MapOptions, StrideType> >
+ : public traits<PlainObjectType>
+{
+ typedef traits<PlainObjectType> TraitsBase;
+ enum {
+ PlainObjectTypeInnerSize = ((traits<PlainObjectType>::Flags&RowMajorBit)==RowMajorBit)
+ ? PlainObjectType::ColsAtCompileTime
+ : PlainObjectType::RowsAtCompileTime,
+
+ InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
+ ? int(PlainObjectType::InnerStrideAtCompileTime)
+ : int(StrideType::InnerStrideAtCompileTime),
+ OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
+ ? (InnerStrideAtCompileTime==Dynamic || PlainObjectTypeInnerSize==Dynamic
+ ? Dynamic
+ : int(InnerStrideAtCompileTime) * int(PlainObjectTypeInnerSize))
+ : int(StrideType::OuterStrideAtCompileTime),
+ Alignment = int(MapOptions)&int(AlignedMask),
+ Flags0 = TraitsBase::Flags & (~NestByRefBit),
+ Flags = is_lvalue<PlainObjectType>::value ? int(Flags0) : (int(Flags0) & ~LvalueBit)
+ };
+private:
+ enum { Options }; // Expressions don't have Options
+};
+}
+
+/** \class Map
+ * \ingroup Core_Module
+ *
+ * \brief A matrix or vector expression mapping an existing array of data.
+ *
+ * \tparam PlainObjectType the equivalent matrix type of the mapped data
+ * \tparam MapOptions specifies the pointer alignment in bytes. It can be: \c #Aligned128, \c #Aligned64, \c #Aligned32, \c #Aligned16, \c #Aligned8 or \c #Unaligned.
+ * The default is \c #Unaligned.
+ * \tparam StrideType optionally specifies strides. By default, Map assumes the memory layout
+ * of an ordinary, contiguous array. This can be overridden by specifying strides.
+ * The type passed here must be a specialization of the Stride template, see examples below.
+ *
+ * This class represents a matrix or vector expression mapping an existing array of data.
+ * It can be used to let Eigen interface without any overhead with non-Eigen data structures,
+ * such as plain C arrays or structures from other libraries. By default, it assumes that the
+ * data is laid out contiguously in memory. You can however override this by explicitly specifying
+ * inner and outer strides.
+ *
+ * Here's an example of simply mapping a contiguous array as a \ref TopicStorageOrders "column-major" matrix:
+ * \include Map_simple.cpp
+ * Output: \verbinclude Map_simple.out
+ *
+ * If you need to map non-contiguous arrays, you can do so by specifying strides:
+ *
+ * Here's an example of mapping an array as a vector, specifying an inner stride, that is, the pointer
+ * increment between two consecutive coefficients. Here, we're specifying the inner stride as a compile-time
+ * fixed value.
+ * \include Map_inner_stride.cpp
+ * Output: \verbinclude Map_inner_stride.out
+ *
+ * Here's an example of mapping an array while specifying an outer stride. Here, since we're mapping
+ * as a column-major matrix, 'outer stride' means the pointer increment between two consecutive columns.
+ * Here, we're specifying the outer stride as a runtime parameter. Note that here \c OuterStride<> is
+ * a short version of \c OuterStride<Dynamic> because the default template parameter of OuterStride
+ * is \c Dynamic
+ * \include Map_outer_stride.cpp
+ * Output: \verbinclude Map_outer_stride.out
+ *
+ * For more details and for an example of specifying both an inner and an outer stride, see class Stride.
+ *
+ * \b Tip: to change the array of data mapped by a Map object, you can use the C++
+ * placement new syntax:
+ *
+ * Example: \include Map_placement_new.cpp
+ * Output: \verbinclude Map_placement_new.out
+ *
+ * This class is the return type of PlainObjectBase::Map() but can also be used directly.
+ *
+ * \sa PlainObjectBase::Map(), \ref TopicStorageOrders
+ */
+template<typename PlainObjectType, int MapOptions, typename StrideType> class Map
+ : public MapBase<Map<PlainObjectType, MapOptions, StrideType> >
+{
+ public:
+
+ typedef MapBase<Map> Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Map)
+
+ typedef typename Base::PointerType PointerType;
+ typedef PointerType PointerArgType;
+ EIGEN_DEVICE_FUNC
+ inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const
+ {
+ return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const
+ {
+ return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
+ : internal::traits<Map>::OuterStrideAtCompileTime != Dynamic ? Index(internal::traits<Map>::OuterStrideAtCompileTime)
+ : IsVectorAtCompileTime ? (this->size() * innerStride())
+ : int(Flags)&RowMajorBit ? (this->cols() * innerStride())
+ : (this->rows() * innerStride());
+ }
+
+ /** Constructor in the fixed-size case.
+ *
+ * \param dataPtr pointer to the array to map
+ * \param stride optional Stride object, passing the strides.
+ */
+ EIGEN_DEVICE_FUNC
+ explicit inline Map(PointerArgType dataPtr, const StrideType& stride = StrideType())
+ : Base(cast_to_pointer_type(dataPtr)), m_stride(stride)
+ {
+ PlainObjectType::Base::_check_template_params();
+ }
+
+ /** Constructor in the dynamic-size vector case.
+ *
+ * \param dataPtr pointer to the array to map
+ * \param size the size of the vector expression
+ * \param stride optional Stride object, passing the strides.
+ */
+ EIGEN_DEVICE_FUNC
+ inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType())
+ : Base(cast_to_pointer_type(dataPtr), size), m_stride(stride)
+ {
+ PlainObjectType::Base::_check_template_params();
+ }
+
+ /** Constructor in the dynamic-size matrix case.
+ *
+ * \param dataPtr pointer to the array to map
+ * \param rows the number of rows of the matrix expression
+ * \param cols the number of columns of the matrix expression
+ * \param stride optional Stride object, passing the strides.
+ */
+ EIGEN_DEVICE_FUNC
+ inline Map(PointerArgType dataPtr, Index rows, Index cols, const StrideType& stride = StrideType())
+ : Base(cast_to_pointer_type(dataPtr), rows, cols), m_stride(stride)
+ {
+ PlainObjectType::Base::_check_template_params();
+ }
+
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
+
+ protected:
+ StrideType m_stride;
+};
+
+
+} // end namespace Eigen
+
+#endif // EIGEN_MAP_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/MapBase.h b/src/3rdparty/eigen/Eigen/src/Core/MapBase.h
new file mode 100644
index 000000000..d856447f0
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/MapBase.h
@@ -0,0 +1,310 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MAPBASE_H
+#define EIGEN_MAPBASE_H
+
+#define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) \
+ EIGEN_STATIC_ASSERT((int(internal::evaluator<Derived>::Flags) & LinearAccessBit) || Derived::IsVectorAtCompileTime, \
+ YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT)
+
+namespace Eigen {
+
+/** \ingroup Core_Module
+ *
+ * \brief Base class for dense Map and Block expression with direct access
+ *
+ * This base class provides the const low-level accessors (e.g. coeff, coeffRef) of dense
+ * Map and Block objects with direct access.
+ * Typical users do not have to directly deal with this class.
+ *
+ * This class can be extended by through the macro plugin \c EIGEN_MAPBASE_PLUGIN.
+ * See \link TopicCustomizing_Plugins customizing Eigen \endlink for details.
+ *
+ * The \c Derived class has to provide the following two methods describing the memory layout:
+ * \code Index innerStride() const; \endcode
+ * \code Index outerStride() const; \endcode
+ *
+ * \sa class Map, class Block
+ */
+template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
+ : public internal::dense_xpr_base<Derived>::type
+{
+ public:
+
+ typedef typename internal::dense_xpr_base<Derived>::type Base;
+ enum {
+ RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
+ ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
+ InnerStrideAtCompileTime = internal::traits<Derived>::InnerStrideAtCompileTime,
+ SizeAtCompileTime = Base::SizeAtCompileTime
+ };
+
+ typedef typename internal::traits<Derived>::StorageKind StorageKind;
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+ typedef typename internal::packet_traits<Scalar>::type PacketScalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef typename internal::conditional<
+ bool(internal::is_lvalue<Derived>::value),
+ Scalar *,
+ const Scalar *>::type
+ PointerType;
+
+ using Base::derived;
+// using Base::RowsAtCompileTime;
+// using Base::ColsAtCompileTime;
+// using Base::SizeAtCompileTime;
+ using Base::MaxRowsAtCompileTime;
+ using Base::MaxColsAtCompileTime;
+ using Base::MaxSizeAtCompileTime;
+ using Base::IsVectorAtCompileTime;
+ using Base::Flags;
+ using Base::IsRowMajor;
+
+ using Base::rows;
+ using Base::cols;
+ using Base::size;
+ using Base::coeff;
+ using Base::coeffRef;
+ using Base::lazyAssign;
+ using Base::eval;
+
+ using Base::innerStride;
+ using Base::outerStride;
+ using Base::rowStride;
+ using Base::colStride;
+
+ // bug 217 - compile error on ICC 11.1
+ using Base::operator=;
+
+ typedef typename Base::CoeffReturnType CoeffReturnType;
+
+ /** \copydoc DenseBase::rows() */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return m_rows.value(); }
+ /** \copydoc DenseBase::cols() */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return m_cols.value(); }
+
+ /** Returns a pointer to the first coefficient of the matrix or vector.
+ *
+ * \note When addressing this data, make sure to honor the strides returned by innerStride() and outerStride().
+ *
+ * \sa innerStride(), outerStride()
+ */
+ EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_data; }
+
+ /** \copydoc PlainObjectBase::coeff(Index,Index) const */
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeff(Index rowId, Index colId) const
+ {
+ return m_data[colId * colStride() + rowId * rowStride()];
+ }
+
+ /** \copydoc PlainObjectBase::coeff(Index) const */
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeff(Index index) const
+ {
+ EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
+ return m_data[index * innerStride()];
+ }
+
+ /** \copydoc PlainObjectBase::coeffRef(Index,Index) const */
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index rowId, Index colId) const
+ {
+ return this->m_data[colId * colStride() + rowId * rowStride()];
+ }
+
+ /** \copydoc PlainObjectBase::coeffRef(Index) const */
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index index) const
+ {
+ EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
+ return this->m_data[index * innerStride()];
+ }
+
+ /** \internal */
+ template<int LoadMode>
+ inline PacketScalar packet(Index rowId, Index colId) const
+ {
+ return internal::ploadt<PacketScalar, LoadMode>
+ (m_data + (colId * colStride() + rowId * rowStride()));
+ }
+
+ /** \internal */
+ template<int LoadMode>
+ inline PacketScalar packet(Index index) const
+ {
+ EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
+ return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride());
+ }
+
+ /** \internal Constructor for fixed size matrices or vectors */
+ EIGEN_DEVICE_FUNC
+ explicit inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime)
+ {
+ EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
+ checkSanity<Derived>();
+ }
+
+ /** \internal Constructor for dynamically sized vectors */
+ EIGEN_DEVICE_FUNC
+ inline MapBase(PointerType dataPtr, Index vecSize)
+ : m_data(dataPtr),
+ m_rows(RowsAtCompileTime == Dynamic ? vecSize : Index(RowsAtCompileTime)),
+ m_cols(ColsAtCompileTime == Dynamic ? vecSize : Index(ColsAtCompileTime))
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ eigen_assert(vecSize >= 0);
+ eigen_assert(dataPtr == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == vecSize);
+ checkSanity<Derived>();
+ }
+
+ /** \internal Constructor for dynamically sized matrices */
+ EIGEN_DEVICE_FUNC
+ inline MapBase(PointerType dataPtr, Index rows, Index cols)
+ : m_data(dataPtr), m_rows(rows), m_cols(cols)
+ {
+ eigen_assert( (dataPtr == 0)
+ || ( rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
+ && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)));
+ checkSanity<Derived>();
+ }
+
+ #ifdef EIGEN_MAPBASE_PLUGIN
+ #include EIGEN_MAPBASE_PLUGIN
+ #endif
+
+ protected:
+ EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase)
+ EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase)
+
+ template<typename T>
+ EIGEN_DEVICE_FUNC
+ void checkSanity(typename internal::enable_if<(internal::traits<T>::Alignment>0),void*>::type = 0) const
+ {
+#if EIGEN_MAX_ALIGN_BYTES>0
+ // innerStride() is not set yet when this function is called, so we optimistically assume the lowest plausible value:
+ const Index minInnerStride = InnerStrideAtCompileTime == Dynamic ? 1 : Index(InnerStrideAtCompileTime);
+ EIGEN_ONLY_USED_FOR_DEBUG(minInnerStride);
+ eigen_assert(( ((internal::UIntPtr(m_data) % internal::traits<Derived>::Alignment) == 0)
+ || (cols() * rows() * minInnerStride * sizeof(Scalar)) < internal::traits<Derived>::Alignment ) && "data is not aligned");
+#endif
+ }
+
+ template<typename T>
+ EIGEN_DEVICE_FUNC
+ void checkSanity(typename internal::enable_if<internal::traits<T>::Alignment==0,void*>::type = 0) const
+ {}
+
+ PointerType m_data;
+ const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
+ const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
+};
+
+/** \ingroup Core_Module
+ *
+ * \brief Base class for non-const dense Map and Block expression with direct access
+ *
+ * This base class provides the non-const low-level accessors (e.g. coeff and coeffRef) of
+ * dense Map and Block objects with direct access.
+ * It inherits MapBase<Derived, ReadOnlyAccessors> which defines the const variant for reading specific entries.
+ *
+ * \sa class Map, class Block
+ */
+template<typename Derived> class MapBase<Derived, WriteAccessors>
+ : public MapBase<Derived, ReadOnlyAccessors>
+{
+ typedef MapBase<Derived, ReadOnlyAccessors> ReadOnlyMapBase;
+ public:
+
+ typedef MapBase<Derived, ReadOnlyAccessors> Base;
+
+ typedef typename Base::Scalar Scalar;
+ typedef typename Base::PacketScalar PacketScalar;
+ typedef typename Base::StorageIndex StorageIndex;
+ typedef typename Base::PointerType PointerType;
+
+ using Base::derived;
+ using Base::rows;
+ using Base::cols;
+ using Base::size;
+ using Base::coeff;
+ using Base::coeffRef;
+
+ using Base::innerStride;
+ using Base::outerStride;
+ using Base::rowStride;
+ using Base::colStride;
+
+ typedef typename internal::conditional<
+ internal::is_lvalue<Derived>::value,
+ Scalar,
+ const Scalar
+ >::type ScalarWithConstIfNotLvalue;
+
+ EIGEN_DEVICE_FUNC
+ inline const Scalar* data() const { return this->m_data; }
+ EIGEN_DEVICE_FUNC
+ inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error
+
+ EIGEN_DEVICE_FUNC
+ inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col)
+ {
+ return this->m_data[col * colStride() + row * rowStride()];
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline ScalarWithConstIfNotLvalue& coeffRef(Index index)
+ {
+ EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
+ return this->m_data[index * innerStride()];
+ }
+
+ template<int StoreMode>
+ inline void writePacket(Index row, Index col, const PacketScalar& val)
+ {
+ internal::pstoret<Scalar, PacketScalar, StoreMode>
+ (this->m_data + (col * colStride() + row * rowStride()), val);
+ }
+
+ template<int StoreMode>
+ inline void writePacket(Index index, const PacketScalar& val)
+ {
+ EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
+ internal::pstoret<Scalar, PacketScalar, StoreMode>
+ (this->m_data + index * innerStride(), val);
+ }
+
+ EIGEN_DEVICE_FUNC explicit inline MapBase(PointerType dataPtr) : Base(dataPtr) {}
+ EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index vecSize) : Base(dataPtr, vecSize) {}
+ EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index rows, Index cols) : Base(dataPtr, rows, cols) {}
+
+ EIGEN_DEVICE_FUNC
+ Derived& operator=(const MapBase& other)
+ {
+ ReadOnlyMapBase::Base::operator=(other);
+ return derived();
+ }
+
+ // In theory we could simply refer to Base:Base::operator=, but MSVC does not like Base::Base,
+ // see bugs 821 and 920.
+ using ReadOnlyMapBase::Base::operator=;
+ protected:
+ EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase)
+ EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase)
+};
+
+#undef EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS
+
+} // end namespace Eigen
+
+#endif // EIGEN_MAPBASE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/MathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/MathFunctions.h
new file mode 100644
index 000000000..61b78f4f2
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/MathFunctions.h
@@ -0,0 +1,2057 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATHFUNCTIONS_H
+#define EIGEN_MATHFUNCTIONS_H
+
+// TODO this should better be moved to NumTraits
+// Source: WolframAlpha
+#define EIGEN_PI 3.141592653589793238462643383279502884197169399375105820974944592307816406L
+#define EIGEN_LOG2E 1.442695040888963407359924681001892137426645954152985934135449406931109219L
+#define EIGEN_LN2 0.693147180559945309417232121458176568075500134360255254120680009493393621L
+
+namespace Eigen {
+
+// On WINCE, std::abs is defined for int only, so let's defined our own overloads:
+// This issue has been confirmed with MSVC 2008 only, but the issue might exist for more recent versions too.
+#if EIGEN_OS_WINCE && EIGEN_COMP_MSVC && EIGEN_COMP_MSVC<=1500
+long abs(long x) { return (labs(x)); }
+double abs(double x) { return (fabs(x)); }
+float abs(float x) { return (fabsf(x)); }
+long double abs(long double x) { return (fabsl(x)); }
+#endif
+
+namespace internal {
+
+/** \internal \class global_math_functions_filtering_base
+ *
+ * What it does:
+ * Defines a typedef 'type' as follows:
+ * - if type T has a member typedef Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl, then
+ * global_math_functions_filtering_base<T>::type is a typedef for it.
+ * - otherwise, global_math_functions_filtering_base<T>::type is a typedef for T.
+ *
+ * How it's used:
+ * To allow to defined the global math functions (like sin...) in certain cases, like the Array expressions.
+ * When you do sin(array1+array2), the object array1+array2 has a complicated expression type, all what you want to know
+ * is that it inherits ArrayBase. So we implement a partial specialization of sin_impl for ArrayBase<Derived>.
+ * So we must make sure to use sin_impl<ArrayBase<Derived> > and not sin_impl<Derived>, otherwise our partial specialization
+ * won't be used. How does sin know that? That's exactly what global_math_functions_filtering_base tells it.
+ *
+ * How it's implemented:
+ * SFINAE in the style of enable_if. Highly susceptible of breaking compilers. With GCC, it sure does work, but if you replace
+ * the typename dummy by an integer template parameter, it doesn't work anymore!
+ */
+
+template<typename T, typename dummy = void>
+struct global_math_functions_filtering_base
+{
+ typedef T type;
+};
+
+template<typename T> struct always_void { typedef void type; };
+
+template<typename T>
+struct global_math_functions_filtering_base
+ <T,
+ typename always_void<typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl>::type
+ >
+{
+ typedef typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl type;
+};
+
+#define EIGEN_MATHFUNC_IMPL(func, scalar) Eigen::internal::func##_impl<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type>
+#define EIGEN_MATHFUNC_RETVAL(func, scalar) typename Eigen::internal::func##_retval<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type>::type
+
+/****************************************************************************
+* Implementation of real *
+****************************************************************************/
+
+template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
+struct real_default_impl
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar& x)
+ {
+ return x;
+ }
+};
+
+template<typename Scalar>
+struct real_default_impl<Scalar,true>
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar& x)
+ {
+ using std::real;
+ return real(x);
+ }
+};
+
+template<typename Scalar> struct real_impl : real_default_impl<Scalar> {};
+
+#if defined(EIGEN_GPU_COMPILE_PHASE)
+template<typename T>
+struct real_impl<std::complex<T> >
+{
+ typedef T RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline T run(const std::complex<T>& x)
+ {
+ return x.real();
+ }
+};
+#endif
+
+template<typename Scalar>
+struct real_retval
+{
+ typedef typename NumTraits<Scalar>::Real type;
+};
+
+/****************************************************************************
+* Implementation of imag *
+****************************************************************************/
+
+template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
+struct imag_default_impl
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar&)
+ {
+ return RealScalar(0);
+ }
+};
+
+template<typename Scalar>
+struct imag_default_impl<Scalar,true>
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar& x)
+ {
+ using std::imag;
+ return imag(x);
+ }
+};
+
+template<typename Scalar> struct imag_impl : imag_default_impl<Scalar> {};
+
+#if defined(EIGEN_GPU_COMPILE_PHASE)
+template<typename T>
+struct imag_impl<std::complex<T> >
+{
+ typedef T RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline T run(const std::complex<T>& x)
+ {
+ return x.imag();
+ }
+};
+#endif
+
+template<typename Scalar>
+struct imag_retval
+{
+ typedef typename NumTraits<Scalar>::Real type;
+};
+
+/****************************************************************************
+* Implementation of real_ref *
+****************************************************************************/
+
+template<typename Scalar>
+struct real_ref_impl
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar& run(Scalar& x)
+ {
+ return reinterpret_cast<RealScalar*>(&x)[0];
+ }
+ EIGEN_DEVICE_FUNC
+ static inline const RealScalar& run(const Scalar& x)
+ {
+ return reinterpret_cast<const RealScalar*>(&x)[0];
+ }
+};
+
+template<typename Scalar>
+struct real_ref_retval
+{
+ typedef typename NumTraits<Scalar>::Real & type;
+};
+
+/****************************************************************************
+* Implementation of imag_ref *
+****************************************************************************/
+
+template<typename Scalar, bool IsComplex>
+struct imag_ref_default_impl
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar& run(Scalar& x)
+ {
+ return reinterpret_cast<RealScalar*>(&x)[1];
+ }
+ EIGEN_DEVICE_FUNC
+ static inline const RealScalar& run(const Scalar& x)
+ {
+ return reinterpret_cast<RealScalar*>(&x)[1];
+ }
+};
+
+template<typename Scalar>
+struct imag_ref_default_impl<Scalar, false>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline Scalar run(Scalar&)
+ {
+ return Scalar(0);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline const Scalar run(const Scalar&)
+ {
+ return Scalar(0);
+ }
+};
+
+template<typename Scalar>
+struct imag_ref_impl : imag_ref_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
+
+template<typename Scalar>
+struct imag_ref_retval
+{
+ typedef typename NumTraits<Scalar>::Real & type;
+};
+
+/****************************************************************************
+* Implementation of conj *
+****************************************************************************/
+
+template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
+struct conj_default_impl
+{
+ EIGEN_DEVICE_FUNC
+ static inline Scalar run(const Scalar& x)
+ {
+ return x;
+ }
+};
+
+template<typename Scalar>
+struct conj_default_impl<Scalar,true>
+{
+ EIGEN_DEVICE_FUNC
+ static inline Scalar run(const Scalar& x)
+ {
+ using std::conj;
+ return conj(x);
+ }
+};
+
+template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
+struct conj_impl : conj_default_impl<Scalar, IsComplex> {};
+
+template<typename Scalar>
+struct conj_retval
+{
+ typedef Scalar type;
+};
+
+/****************************************************************************
+* Implementation of abs2 *
+****************************************************************************/
+
+template<typename Scalar,bool IsComplex>
+struct abs2_impl_default
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar& x)
+ {
+ return x*x;
+ }
+};
+
+template<typename Scalar>
+struct abs2_impl_default<Scalar, true> // IsComplex
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar& x)
+ {
+ return x.real()*x.real() + x.imag()*x.imag();
+ }
+};
+
+template<typename Scalar>
+struct abs2_impl
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar& x)
+ {
+ return abs2_impl_default<Scalar,NumTraits<Scalar>::IsComplex>::run(x);
+ }
+};
+
+template<typename Scalar>
+struct abs2_retval
+{
+ typedef typename NumTraits<Scalar>::Real type;
+};
+
+/****************************************************************************
+* Implementation of sqrt/rsqrt *
+****************************************************************************/
+
+template<typename Scalar>
+struct sqrt_impl
+{
+ EIGEN_DEVICE_FUNC
+ static EIGEN_ALWAYS_INLINE Scalar run(const Scalar& x)
+ {
+ EIGEN_USING_STD(sqrt);
+ return sqrt(x);
+ }
+};
+
+// Complex sqrt defined in MathFunctionsImpl.h.
+template<typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_sqrt(const std::complex<T>& a_x);
+
+// Custom implementation is faster than `std::sqrt`, works on
+// GPU, and correctly handles special cases (unlike MSVC).
+template<typename T>
+struct sqrt_impl<std::complex<T> >
+{
+ EIGEN_DEVICE_FUNC
+ static EIGEN_ALWAYS_INLINE std::complex<T> run(const std::complex<T>& x)
+ {
+ return complex_sqrt<T>(x);
+ }
+};
+
+template<typename Scalar>
+struct sqrt_retval
+{
+ typedef Scalar type;
+};
+
+// Default implementation relies on numext::sqrt, at bottom of file.
+template<typename T>
+struct rsqrt_impl;
+
+// Complex rsqrt defined in MathFunctionsImpl.h.
+template<typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_rsqrt(const std::complex<T>& a_x);
+
+template<typename T>
+struct rsqrt_impl<std::complex<T> >
+{
+ EIGEN_DEVICE_FUNC
+ static EIGEN_ALWAYS_INLINE std::complex<T> run(const std::complex<T>& x)
+ {
+ return complex_rsqrt<T>(x);
+ }
+};
+
+template<typename Scalar>
+struct rsqrt_retval
+{
+ typedef Scalar type;
+};
+
+/****************************************************************************
+* Implementation of norm1 *
+****************************************************************************/
+
+template<typename Scalar, bool IsComplex>
+struct norm1_default_impl;
+
+template<typename Scalar>
+struct norm1_default_impl<Scalar,true>
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar& x)
+ {
+ EIGEN_USING_STD(abs);
+ return abs(x.real()) + abs(x.imag());
+ }
+};
+
+template<typename Scalar>
+struct norm1_default_impl<Scalar, false>
+{
+ EIGEN_DEVICE_FUNC
+ static inline Scalar run(const Scalar& x)
+ {
+ EIGEN_USING_STD(abs);
+ return abs(x);
+ }
+};
+
+template<typename Scalar>
+struct norm1_impl : norm1_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
+
+template<typename Scalar>
+struct norm1_retval
+{
+ typedef typename NumTraits<Scalar>::Real type;
+};
+
+/****************************************************************************
+* Implementation of hypot *
+****************************************************************************/
+
+template<typename Scalar> struct hypot_impl;
+
+template<typename Scalar>
+struct hypot_retval
+{
+ typedef typename NumTraits<Scalar>::Real type;
+};
+
+/****************************************************************************
+* Implementation of cast *
+****************************************************************************/
+
+template<typename OldType, typename NewType, typename EnableIf = void>
+struct cast_impl
+{
+ EIGEN_DEVICE_FUNC
+ static inline NewType run(const OldType& x)
+ {
+ return static_cast<NewType>(x);
+ }
+};
+
+// Casting from S -> Complex<T> leads to an implicit conversion from S to T,
+// generating warnings on clang. Here we explicitly cast the real component.
+template<typename OldType, typename NewType>
+struct cast_impl<OldType, NewType,
+ typename internal::enable_if<
+ !NumTraits<OldType>::IsComplex && NumTraits<NewType>::IsComplex
+ >::type>
+{
+ EIGEN_DEVICE_FUNC
+ static inline NewType run(const OldType& x)
+ {
+ typedef typename NumTraits<NewType>::Real NewReal;
+ return static_cast<NewType>(static_cast<NewReal>(x));
+ }
+};
+
+// here, for once, we're plainly returning NewType: we don't want cast to do weird things.
+
+template<typename OldType, typename NewType>
+EIGEN_DEVICE_FUNC
+inline NewType cast(const OldType& x)
+{
+ return cast_impl<OldType, NewType>::run(x);
+}
+
+/****************************************************************************
+* Implementation of round *
+****************************************************************************/
+
+template<typename Scalar>
+struct round_impl
+{
+ EIGEN_DEVICE_FUNC
+ static inline Scalar run(const Scalar& x)
+ {
+ EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
+#if EIGEN_HAS_CXX11_MATH
+ EIGEN_USING_STD(round);
+#endif
+ return Scalar(round(x));
+ }
+};
+
+#if !EIGEN_HAS_CXX11_MATH
+#if EIGEN_HAS_C99_MATH
+// Use ::roundf for float.
+template<>
+struct round_impl<float> {
+ EIGEN_DEVICE_FUNC
+ static inline float run(const float& x)
+ {
+ return ::roundf(x);
+ }
+};
+#else
+template<typename Scalar>
+struct round_using_floor_ceil_impl
+{
+ EIGEN_DEVICE_FUNC
+ static inline Scalar run(const Scalar& x)
+ {
+ EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
+ // Without C99 round/roundf, resort to floor/ceil.
+ EIGEN_USING_STD(floor);
+ EIGEN_USING_STD(ceil);
+ // If not enough precision to resolve a decimal at all, return the input.
+ // Otherwise, adding 0.5 can trigger an increment by 1.
+ const Scalar limit = Scalar(1ull << (NumTraits<Scalar>::digits() - 1));
+ if (x >= limit || x <= -limit) {
+ return x;
+ }
+ return (x > Scalar(0)) ? Scalar(floor(x + Scalar(0.5))) : Scalar(ceil(x - Scalar(0.5)));
+ }
+};
+
+template<>
+struct round_impl<float> : round_using_floor_ceil_impl<float> {};
+
+template<>
+struct round_impl<double> : round_using_floor_ceil_impl<double> {};
+#endif // EIGEN_HAS_C99_MATH
+#endif // !EIGEN_HAS_CXX11_MATH
+
+template<typename Scalar>
+struct round_retval
+{
+ typedef Scalar type;
+};
+
+/****************************************************************************
+* Implementation of rint *
+****************************************************************************/
+
+template<typename Scalar>
+struct rint_impl {
+ EIGEN_DEVICE_FUNC
+ static inline Scalar run(const Scalar& x)
+ {
+ EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
+#if EIGEN_HAS_CXX11_MATH
+ EIGEN_USING_STD(rint);
+#endif
+ return rint(x);
+ }
+};
+
+#if !EIGEN_HAS_CXX11_MATH
+template<>
+struct rint_impl<double> {
+ EIGEN_DEVICE_FUNC
+ static inline double run(const double& x)
+ {
+ return ::rint(x);
+ }
+};
+template<>
+struct rint_impl<float> {
+ EIGEN_DEVICE_FUNC
+ static inline float run(const float& x)
+ {
+ return ::rintf(x);
+ }
+};
+#endif
+
+template<typename Scalar>
+struct rint_retval
+{
+ typedef Scalar type;
+};
+
+/****************************************************************************
+* Implementation of arg *
+****************************************************************************/
+
+// Visual Studio 2017 has a bug where arg(float) returns 0 for negative inputs.
+// This seems to be fixed in VS 2019.
+#if EIGEN_HAS_CXX11_MATH && (!EIGEN_COMP_MSVC || EIGEN_COMP_MSVC >= 1920)
+// std::arg is only defined for types of std::complex, or integer types or float/double/long double
+template<typename Scalar,
+ bool HasStdImpl = NumTraits<Scalar>::IsComplex || is_integral<Scalar>::value
+ || is_same<Scalar, float>::value || is_same<Scalar, double>::value
+ || is_same<Scalar, long double>::value >
+struct arg_default_impl;
+
+template<typename Scalar>
+struct arg_default_impl<Scalar, true> {
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar& x)
+ {
+ #if defined(EIGEN_HIP_DEVICE_COMPILE)
+ // HIP does not seem to have a native device side implementation for the math routine "arg"
+ using std::arg;
+ #else
+ EIGEN_USING_STD(arg);
+ #endif
+ return static_cast<RealScalar>(arg(x));
+ }
+};
+
+// Must be non-complex floating-point type (e.g. half/bfloat16).
+template<typename Scalar>
+struct arg_default_impl<Scalar, false> {
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar& x)
+ {
+ return (x < Scalar(0)) ? RealScalar(EIGEN_PI) : RealScalar(0);
+ }
+};
+#else
+template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
+struct arg_default_impl
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar& x)
+ {
+ return (x < RealScalar(0)) ? RealScalar(EIGEN_PI) : RealScalar(0);
+ }
+};
+
+template<typename Scalar>
+struct arg_default_impl<Scalar,true>
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline RealScalar run(const Scalar& x)
+ {
+ EIGEN_USING_STD(arg);
+ return arg(x);
+ }
+};
+#endif
+template<typename Scalar> struct arg_impl : arg_default_impl<Scalar> {};
+
+template<typename Scalar>
+struct arg_retval
+{
+ typedef typename NumTraits<Scalar>::Real type;
+};
+
+/****************************************************************************
+* Implementation of expm1 *
+****************************************************************************/
+
+// This implementation is based on GSL Math's expm1.
+namespace std_fallback {
+ // fallback expm1 implementation in case there is no expm1(Scalar) function in namespace of Scalar,
+ // or that there is no suitable std::expm1 function available. Implementation
+ // attributed to Kahan. See: http://www.plunk.org/~hatch/rightway.php.
+ template<typename Scalar>
+ EIGEN_DEVICE_FUNC inline Scalar expm1(const Scalar& x) {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ EIGEN_USING_STD(exp);
+ Scalar u = exp(x);
+ if (numext::equal_strict(u, Scalar(1))) {
+ return x;
+ }
+ Scalar um1 = u - RealScalar(1);
+ if (numext::equal_strict(um1, Scalar(-1))) {
+ return RealScalar(-1);
+ }
+
+ EIGEN_USING_STD(log);
+ Scalar logu = log(u);
+ return numext::equal_strict(u, logu) ? u : (u - RealScalar(1)) * x / logu;
+ }
+}
+
+template<typename Scalar>
+struct expm1_impl {
+ EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x)
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
+ #if EIGEN_HAS_CXX11_MATH
+ using std::expm1;
+ #else
+ using std_fallback::expm1;
+ #endif
+ return expm1(x);
+ }
+};
+
+template<typename Scalar>
+struct expm1_retval
+{
+ typedef Scalar type;
+};
+
+/****************************************************************************
+* Implementation of log *
+****************************************************************************/
+
+// Complex log defined in MathFunctionsImpl.h.
+template<typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_log(const std::complex<T>& z);
+
+template<typename Scalar>
+struct log_impl {
+ EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x)
+ {
+ EIGEN_USING_STD(log);
+ return static_cast<Scalar>(log(x));
+ }
+};
+
+template<typename Scalar>
+struct log_impl<std::complex<Scalar> > {
+ EIGEN_DEVICE_FUNC static inline std::complex<Scalar> run(const std::complex<Scalar>& z)
+ {
+ return complex_log(z);
+ }
+};
+
+/****************************************************************************
+* Implementation of log1p *
+****************************************************************************/
+
+namespace std_fallback {
+ // fallback log1p implementation in case there is no log1p(Scalar) function in namespace of Scalar,
+ // or that there is no suitable std::log1p function available
+ template<typename Scalar>
+ EIGEN_DEVICE_FUNC inline Scalar log1p(const Scalar& x) {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_USING_STD(log);
+ Scalar x1p = RealScalar(1) + x;
+ Scalar log_1p = log_impl<Scalar>::run(x1p);
+ const bool is_small = numext::equal_strict(x1p, Scalar(1));
+ const bool is_inf = numext::equal_strict(x1p, log_1p);
+ return (is_small || is_inf) ? x : x * (log_1p / (x1p - RealScalar(1)));
+ }
+}
+
+template<typename Scalar>
+struct log1p_impl {
+ EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x)
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
+ #if EIGEN_HAS_CXX11_MATH
+ using std::log1p;
+ #else
+ using std_fallback::log1p;
+ #endif
+ return log1p(x);
+ }
+};
+
+// Specialization for complex types that are not supported by std::log1p.
+template <typename RealScalar>
+struct log1p_impl<std::complex<RealScalar> > {
+ EIGEN_DEVICE_FUNC static inline std::complex<RealScalar> run(
+ const std::complex<RealScalar>& x) {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar)
+ return std_fallback::log1p(x);
+ }
+};
+
+template<typename Scalar>
+struct log1p_retval
+{
+ typedef Scalar type;
+};
+
+/****************************************************************************
+* Implementation of pow *
+****************************************************************************/
+
+template<typename ScalarX,typename ScalarY, bool IsInteger = NumTraits<ScalarX>::IsInteger&&NumTraits<ScalarY>::IsInteger>
+struct pow_impl
+{
+ //typedef Scalar retval;
+ typedef typename ScalarBinaryOpTraits<ScalarX,ScalarY,internal::scalar_pow_op<ScalarX,ScalarY> >::ReturnType result_type;
+ static EIGEN_DEVICE_FUNC inline result_type run(const ScalarX& x, const ScalarY& y)
+ {
+ EIGEN_USING_STD(pow);
+ return pow(x, y);
+ }
+};
+
+template<typename ScalarX,typename ScalarY>
+struct pow_impl<ScalarX,ScalarY, true>
+{
+ typedef ScalarX result_type;
+ static EIGEN_DEVICE_FUNC inline ScalarX run(ScalarX x, ScalarY y)
+ {
+ ScalarX res(1);
+ eigen_assert(!NumTraits<ScalarY>::IsSigned || y >= 0);
+ if(y & 1) res *= x;
+ y >>= 1;
+ while(y)
+ {
+ x *= x;
+ if(y&1) res *= x;
+ y >>= 1;
+ }
+ return res;
+ }
+};
+
+/****************************************************************************
+* Implementation of random *
+****************************************************************************/
+
+template<typename Scalar,
+ bool IsComplex,
+ bool IsInteger>
+struct random_default_impl {};
+
+template<typename Scalar>
+struct random_impl : random_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
+
+template<typename Scalar>
+struct random_retval
+{
+ typedef Scalar type;
+};
+
+template<typename Scalar> inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(const Scalar& x, const Scalar& y);
+template<typename Scalar> inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random();
+
+template<typename Scalar>
+struct random_default_impl<Scalar, false, false>
+{
+ static inline Scalar run(const Scalar& x, const Scalar& y)
+ {
+ return x + (y-x) * Scalar(std::rand()) / Scalar(RAND_MAX);
+ }
+ static inline Scalar run()
+ {
+ return run(Scalar(NumTraits<Scalar>::IsSigned ? -1 : 0), Scalar(1));
+ }
+};
+
+enum {
+ meta_floor_log2_terminate,
+ meta_floor_log2_move_up,
+ meta_floor_log2_move_down,
+ meta_floor_log2_bogus
+};
+
+template<unsigned int n, int lower, int upper> struct meta_floor_log2_selector
+{
+ enum { middle = (lower + upper) / 2,
+ value = (upper <= lower + 1) ? int(meta_floor_log2_terminate)
+ : (n < (1 << middle)) ? int(meta_floor_log2_move_down)
+ : (n==0) ? int(meta_floor_log2_bogus)
+ : int(meta_floor_log2_move_up)
+ };
+};
+
+template<unsigned int n,
+ int lower = 0,
+ int upper = sizeof(unsigned int) * CHAR_BIT - 1,
+ int selector = meta_floor_log2_selector<n, lower, upper>::value>
+struct meta_floor_log2 {};
+
+template<unsigned int n, int lower, int upper>
+struct meta_floor_log2<n, lower, upper, meta_floor_log2_move_down>
+{
+ enum { value = meta_floor_log2<n, lower, meta_floor_log2_selector<n, lower, upper>::middle>::value };
+};
+
+template<unsigned int n, int lower, int upper>
+struct meta_floor_log2<n, lower, upper, meta_floor_log2_move_up>
+{
+ enum { value = meta_floor_log2<n, meta_floor_log2_selector<n, lower, upper>::middle, upper>::value };
+};
+
+template<unsigned int n, int lower, int upper>
+struct meta_floor_log2<n, lower, upper, meta_floor_log2_terminate>
+{
+ enum { value = (n >= ((unsigned int)(1) << (lower+1))) ? lower+1 : lower };
+};
+
+template<unsigned int n, int lower, int upper>
+struct meta_floor_log2<n, lower, upper, meta_floor_log2_bogus>
+{
+ // no value, error at compile time
+};
+
+template<typename Scalar>
+struct random_default_impl<Scalar, false, true>
+{
+ static inline Scalar run(const Scalar& x, const Scalar& y)
+ {
+ if (y <= x)
+ return x;
+ // ScalarU is the unsigned counterpart of Scalar, possibly Scalar itself.
+ typedef typename make_unsigned<Scalar>::type ScalarU;
+ // ScalarX is the widest of ScalarU and unsigned int.
+ // We'll deal only with ScalarX and unsigned int below thus avoiding signed
+ // types and arithmetic and signed overflows (which are undefined behavior).
+ typedef typename conditional<(ScalarU(-1) > unsigned(-1)), ScalarU, unsigned>::type ScalarX;
+ // The following difference doesn't overflow, provided our integer types are two's
+ // complement and have the same number of padding bits in signed and unsigned variants.
+ // This is the case in most modern implementations of C++.
+ ScalarX range = ScalarX(y) - ScalarX(x);
+ ScalarX offset = 0;
+ ScalarX divisor = 1;
+ ScalarX multiplier = 1;
+ const unsigned rand_max = RAND_MAX;
+ if (range <= rand_max) divisor = (rand_max + 1) / (range + 1);
+ else multiplier = 1 + range / (rand_max + 1);
+ // Rejection sampling.
+ do {
+ offset = (unsigned(std::rand()) * multiplier) / divisor;
+ } while (offset > range);
+ return Scalar(ScalarX(x) + offset);
+ }
+
+ static inline Scalar run()
+ {
+#ifdef EIGEN_MAKING_DOCS
+ return run(Scalar(NumTraits<Scalar>::IsSigned ? -10 : 0), Scalar(10));
+#else
+ enum { rand_bits = meta_floor_log2<(unsigned int)(RAND_MAX)+1>::value,
+ scalar_bits = sizeof(Scalar) * CHAR_BIT,
+ shift = EIGEN_PLAIN_ENUM_MAX(0, int(rand_bits) - int(scalar_bits)),
+ offset = NumTraits<Scalar>::IsSigned ? (1 << (EIGEN_PLAIN_ENUM_MIN(rand_bits,scalar_bits)-1)) : 0
+ };
+ return Scalar((std::rand() >> shift) - offset);
+#endif
+ }
+};
+
+template<typename Scalar>
+struct random_default_impl<Scalar, true, false>
+{
+ static inline Scalar run(const Scalar& x, const Scalar& y)
+ {
+ return Scalar(random(x.real(), y.real()),
+ random(x.imag(), y.imag()));
+ }
+ static inline Scalar run()
+ {
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ return Scalar(random<RealScalar>(), random<RealScalar>());
+ }
+};
+
+template<typename Scalar>
+inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(const Scalar& x, const Scalar& y)
+{
+ return EIGEN_MATHFUNC_IMPL(random, Scalar)::run(x, y);
+}
+
+template<typename Scalar>
+inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random()
+{
+ return EIGEN_MATHFUNC_IMPL(random, Scalar)::run();
+}
+
+// Implementation of is* functions
+
+// std::is* do not work with fast-math and gcc, std::is* are available on MSVC 2013 and newer, as well as in clang.
+#if (EIGEN_HAS_CXX11_MATH && !(EIGEN_COMP_GNUC_STRICT && __FINITE_MATH_ONLY__)) || (EIGEN_COMP_MSVC>=1800) || (EIGEN_COMP_CLANG)
+#define EIGEN_USE_STD_FPCLASSIFY 1
+#else
+#define EIGEN_USE_STD_FPCLASSIFY 0
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+typename internal::enable_if<internal::is_integral<T>::value,bool>::type
+isnan_impl(const T&) { return false; }
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+typename internal::enable_if<internal::is_integral<T>::value,bool>::type
+isinf_impl(const T&) { return false; }
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+typename internal::enable_if<internal::is_integral<T>::value,bool>::type
+isfinite_impl(const T&) { return true; }
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),bool>::type
+isfinite_impl(const T& x)
+{
+ #if defined(EIGEN_GPU_COMPILE_PHASE)
+ return (::isfinite)(x);
+ #elif EIGEN_USE_STD_FPCLASSIFY
+ using std::isfinite;
+ return isfinite EIGEN_NOT_A_MACRO (x);
+ #else
+ return x<=NumTraits<T>::highest() && x>=NumTraits<T>::lowest();
+ #endif
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),bool>::type
+isinf_impl(const T& x)
+{
+ #if defined(EIGEN_GPU_COMPILE_PHASE)
+ return (::isinf)(x);
+ #elif EIGEN_USE_STD_FPCLASSIFY
+ using std::isinf;
+ return isinf EIGEN_NOT_A_MACRO (x);
+ #else
+ return x>NumTraits<T>::highest() || x<NumTraits<T>::lowest();
+ #endif
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),bool>::type
+isnan_impl(const T& x)
+{
+ #if defined(EIGEN_GPU_COMPILE_PHASE)
+ return (::isnan)(x);
+ #elif EIGEN_USE_STD_FPCLASSIFY
+ using std::isnan;
+ return isnan EIGEN_NOT_A_MACRO (x);
+ #else
+ return x != x;
+ #endif
+}
+
+#if (!EIGEN_USE_STD_FPCLASSIFY)
+
+#if EIGEN_COMP_MSVC
+
+template<typename T> EIGEN_DEVICE_FUNC bool isinf_msvc_helper(T x)
+{
+ return _fpclass(x)==_FPCLASS_NINF || _fpclass(x)==_FPCLASS_PINF;
+}
+
+//MSVC defines a _isnan builtin function, but for double only
+EIGEN_DEVICE_FUNC inline bool isnan_impl(const long double& x) { return _isnan(x)!=0; }
+EIGEN_DEVICE_FUNC inline bool isnan_impl(const double& x) { return _isnan(x)!=0; }
+EIGEN_DEVICE_FUNC inline bool isnan_impl(const float& x) { return _isnan(x)!=0; }
+
+EIGEN_DEVICE_FUNC inline bool isinf_impl(const long double& x) { return isinf_msvc_helper(x); }
+EIGEN_DEVICE_FUNC inline bool isinf_impl(const double& x) { return isinf_msvc_helper(x); }
+EIGEN_DEVICE_FUNC inline bool isinf_impl(const float& x) { return isinf_msvc_helper(x); }
+
+#elif (defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ && EIGEN_COMP_GNUC)
+
+#if EIGEN_GNUC_AT_LEAST(5,0)
+ #define EIGEN_TMP_NOOPT_ATTRIB EIGEN_DEVICE_FUNC inline __attribute__((optimize("no-finite-math-only")))
+#else
+ // NOTE the inline qualifier and noinline attribute are both needed: the former is to avoid linking issue (duplicate symbol),
+ // while the second prevent too aggressive optimizations in fast-math mode:
+ #define EIGEN_TMP_NOOPT_ATTRIB EIGEN_DEVICE_FUNC inline __attribute__((noinline,optimize("no-finite-math-only")))
+#endif
+
+template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const long double& x) { return __builtin_isnan(x); }
+template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const double& x) { return __builtin_isnan(x); }
+template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const float& x) { return __builtin_isnan(x); }
+template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const double& x) { return __builtin_isinf(x); }
+template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const float& x) { return __builtin_isinf(x); }
+template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const long double& x) { return __builtin_isinf(x); }
+
+#undef EIGEN_TMP_NOOPT_ATTRIB
+
+#endif
+
+#endif
+
+// The following overload are defined at the end of this file
+template<typename T> EIGEN_DEVICE_FUNC bool isfinite_impl(const std::complex<T>& x);
+template<typename T> EIGEN_DEVICE_FUNC bool isnan_impl(const std::complex<T>& x);
+template<typename T> EIGEN_DEVICE_FUNC bool isinf_impl(const std::complex<T>& x);
+
+template<typename T> T generic_fast_tanh_float(const T& a_x);
+} // end namespace internal
+
+/****************************************************************************
+* Generic math functions *
+****************************************************************************/
+
+namespace numext {
+
+#if (!defined(EIGEN_GPUCC) || defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC))
+template<typename T>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE T mini(const T& x, const T& y)
+{
+ EIGEN_USING_STD(min)
+ return min EIGEN_NOT_A_MACRO (x,y);
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE T maxi(const T& x, const T& y)
+{
+ EIGEN_USING_STD(max)
+ return max EIGEN_NOT_A_MACRO (x,y);
+}
+#else
+template<typename T>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE T mini(const T& x, const T& y)
+{
+ return y < x ? y : x;
+}
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE float mini(const float& x, const float& y)
+{
+ return fminf(x, y);
+}
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE double mini(const double& x, const double& y)
+{
+ return fmin(x, y);
+}
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE long double mini(const long double& x, const long double& y)
+{
+#if defined(EIGEN_HIPCC)
+ // no "fminl" on HIP yet
+ return (x < y) ? x : y;
+#else
+ return fminl(x, y);
+#endif
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE T maxi(const T& x, const T& y)
+{
+ return x < y ? y : x;
+}
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE float maxi(const float& x, const float& y)
+{
+ return fmaxf(x, y);
+}
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE double maxi(const double& x, const double& y)
+{
+ return fmax(x, y);
+}
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE long double maxi(const long double& x, const long double& y)
+{
+#if defined(EIGEN_HIPCC)
+ // no "fmaxl" on HIP yet
+ return (x > y) ? x : y;
+#else
+ return fmaxl(x, y);
+#endif
+}
+#endif
+
+#if defined(SYCL_DEVICE_ONLY)
+
+
+#define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
+ SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \
+ SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \
+ SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \
+ SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_long)
+#define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
+ SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \
+ SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \
+ SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \
+ SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_long)
+#define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
+ SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \
+ SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \
+ SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \
+ SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong)
+#define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
+ SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \
+ SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \
+ SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \
+ SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong)
+#define SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(NAME, FUNC) \
+ SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
+ SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC)
+#define SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(NAME, FUNC) \
+ SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
+ SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC)
+#define SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(NAME, FUNC) \
+ SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \
+ SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC,cl::sycl::cl_double)
+#define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(NAME, FUNC) \
+ SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \
+ SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC,cl::sycl::cl_double)
+#define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(NAME, FUNC, RET_TYPE) \
+ SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_float) \
+ SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_double)
+
+#define SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \
+template<> \
+ EIGEN_DEVICE_FUNC \
+ EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE& x) { \
+ return cl::sycl::FUNC(x); \
+ }
+
+#define SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, TYPE) \
+ SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, TYPE, TYPE)
+
+#define SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE1, ARG_TYPE2) \
+ template<> \
+ EIGEN_DEVICE_FUNC \
+ EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE1& x, const ARG_TYPE2& y) { \
+ return cl::sycl::FUNC(x, y); \
+ }
+
+#define SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \
+ SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE, ARG_TYPE)
+
+#define SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, TYPE) \
+ SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, TYPE, TYPE)
+
+SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(mini, min)
+SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(mini, fmin)
+SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(maxi, max)
+SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(maxi, fmax)
+
+#endif
+
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(real, Scalar) real(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(real, Scalar)::run(x);
+}
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) >::type real_ref(const Scalar& x)
+{
+ return internal::real_ref_impl<Scalar>::run(x);
+}
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) real_ref(Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(real_ref, Scalar)::run(x);
+}
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(imag, Scalar) imag(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(imag, Scalar)::run(x);
+}
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(arg, Scalar) arg(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(arg, Scalar)::run(x);
+}
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) >::type imag_ref(const Scalar& x)
+{
+ return internal::imag_ref_impl<Scalar>::run(x);
+}
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) imag_ref(Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(imag_ref, Scalar)::run(x);
+}
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(conj, Scalar) conj(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(conj, Scalar)::run(x);
+}
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(abs2, Scalar) abs2(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(abs2, Scalar)::run(x);
+}
+
+EIGEN_DEVICE_FUNC
+inline bool abs2(bool x) { return x; }
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE T absdiff(const T& x, const T& y)
+{
+ return x > y ? x - y : y - x;
+}
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE float absdiff(const float& x, const float& y)
+{
+ return fabsf(x - y);
+}
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE double absdiff(const double& x, const double& y)
+{
+ return fabs(x - y);
+}
+
+#if !defined(EIGEN_GPUCC)
+// HIP and CUDA do not support long double.
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE long double absdiff(const long double& x, const long double& y) {
+ return fabsl(x - y);
+}
+#endif
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) norm1(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(norm1, Scalar)::run(x);
+}
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(hypot, Scalar) hypot(const Scalar& x, const Scalar& y)
+{
+ return EIGEN_MATHFUNC_IMPL(hypot, Scalar)::run(x, y);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+ SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(hypot, hypot)
+#endif
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(log1p, Scalar) log1p(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(log1p, Scalar)::run(x);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(log1p, log1p)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float log1p(const float &x) { return ::log1pf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double log1p(const double &x) { return ::log1p(x); }
+#endif
+
+template<typename ScalarX,typename ScalarY>
+EIGEN_DEVICE_FUNC
+inline typename internal::pow_impl<ScalarX,ScalarY>::result_type pow(const ScalarX& x, const ScalarY& y)
+{
+ return internal::pow_impl<ScalarX,ScalarY>::run(x, y);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(pow, pow)
+#endif
+
+template<typename T> EIGEN_DEVICE_FUNC bool (isnan) (const T &x) { return internal::isnan_impl(x); }
+template<typename T> EIGEN_DEVICE_FUNC bool (isinf) (const T &x) { return internal::isinf_impl(x); }
+template<typename T> EIGEN_DEVICE_FUNC bool (isfinite)(const T &x) { return internal::isfinite_impl(x); }
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isnan, isnan, bool)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isinf, isinf, bool)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isfinite, isfinite, bool)
+#endif
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(rint, Scalar) rint(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(rint, Scalar)::run(x);
+}
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(round, Scalar) round(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(round, Scalar)::run(x);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(round, round)
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+T (floor)(const T& x)
+{
+ EIGEN_USING_STD(floor)
+ return floor(x);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(floor, floor)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float floor(const float &x) { return ::floorf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double floor(const double &x) { return ::floor(x); }
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+T (ceil)(const T& x)
+{
+ EIGEN_USING_STD(ceil);
+ return ceil(x);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(ceil, ceil)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float ceil(const float &x) { return ::ceilf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double ceil(const double &x) { return ::ceil(x); }
+#endif
+
+
+/** Log base 2 for 32 bits positive integers.
+ * Conveniently returns 0 for x==0. */
+inline int log2(int x)
+{
+ eigen_assert(x>=0);
+ unsigned int v(x);
+ static const int table[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+ return table[(v * 0x07C4ACDDU) >> 27];
+}
+
+/** \returns the square root of \a x.
+ *
+ * It is essentially equivalent to
+ * \code using std::sqrt; return sqrt(x); \endcode
+ * but slightly faster for float/double and some compilers (e.g., gcc), thanks to
+ * specializations when SSE is enabled.
+ *
+ * It's usage is justified in performance critical functions, like norm/normalize.
+ */
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE EIGEN_MATHFUNC_RETVAL(sqrt, Scalar) sqrt(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(sqrt, Scalar)::run(x);
+}
+
+// Boolean specialization, avoids implicit float to bool conversion (-Wimplicit-conversion-floating-point-to-bool).
+template<>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC
+bool sqrt<bool>(const bool &x) { return x; }
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sqrt, sqrt)
+#endif
+
+/** \returns the reciprocal square root of \a x. **/
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T rsqrt(const T& x)
+{
+ return internal::rsqrt_impl<T>::run(x);
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T log(const T &x) {
+ return internal::log_impl<T>::run(x);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(log, log)
+#endif
+
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float log(const float &x) { return ::logf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double log(const double &x) { return ::log(x); }
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+typename internal::enable_if<NumTraits<T>::IsSigned || NumTraits<T>::IsComplex,typename NumTraits<T>::Real>::type
+abs(const T &x) {
+ EIGEN_USING_STD(abs);
+ return abs(x);
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+typename internal::enable_if<!(NumTraits<T>::IsSigned || NumTraits<T>::IsComplex),typename NumTraits<T>::Real>::type
+abs(const T &x) {
+ return x;
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(abs, abs)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(abs, fabs)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float abs(const float &x) { return ::fabsf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double abs(const double &x) { return ::fabs(x); }
+
+template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float abs(const std::complex<float>& x) {
+ return ::hypotf(x.real(), x.imag());
+}
+
+template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double abs(const std::complex<double>& x) {
+ return ::hypot(x.real(), x.imag());
+}
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T exp(const T &x) {
+ EIGEN_USING_STD(exp);
+ return exp(x);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(exp, exp)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float exp(const float &x) { return ::expf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double exp(const double &x) { return ::exp(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+std::complex<float> exp(const std::complex<float>& x) {
+ float com = ::expf(x.real());
+ float res_real = com * ::cosf(x.imag());
+ float res_imag = com * ::sinf(x.imag());
+ return std::complex<float>(res_real, res_imag);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+std::complex<double> exp(const std::complex<double>& x) {
+ double com = ::exp(x.real());
+ double res_real = com * ::cos(x.imag());
+ double res_imag = com * ::sin(x.imag());
+ return std::complex<double>(res_real, res_imag);
+}
+#endif
+
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+inline EIGEN_MATHFUNC_RETVAL(expm1, Scalar) expm1(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(expm1, Scalar)::run(x);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(expm1, expm1)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float expm1(const float &x) { return ::expm1f(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double expm1(const double &x) { return ::expm1(x); }
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T cos(const T &x) {
+ EIGEN_USING_STD(cos);
+ return cos(x);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(cos,cos)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float cos(const float &x) { return ::cosf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double cos(const double &x) { return ::cos(x); }
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T sin(const T &x) {
+ EIGEN_USING_STD(sin);
+ return sin(x);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sin, sin)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float sin(const float &x) { return ::sinf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double sin(const double &x) { return ::sin(x); }
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T tan(const T &x) {
+ EIGEN_USING_STD(tan);
+ return tan(x);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(tan, tan)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float tan(const float &x) { return ::tanf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double tan(const double &x) { return ::tan(x); }
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T acos(const T &x) {
+ EIGEN_USING_STD(acos);
+ return acos(x);
+}
+
+#if EIGEN_HAS_CXX11_MATH
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T acosh(const T &x) {
+ EIGEN_USING_STD(acosh);
+ return static_cast<T>(acosh(x));
+}
+#endif
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(acos, acos)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(acosh, acosh)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float acos(const float &x) { return ::acosf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double acos(const double &x) { return ::acos(x); }
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T asin(const T &x) {
+ EIGEN_USING_STD(asin);
+ return asin(x);
+}
+
+#if EIGEN_HAS_CXX11_MATH
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T asinh(const T &x) {
+ EIGEN_USING_STD(asinh);
+ return static_cast<T>(asinh(x));
+}
+#endif
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(asin, asin)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(asinh, asinh)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float asin(const float &x) { return ::asinf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double asin(const double &x) { return ::asin(x); }
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T atan(const T &x) {
+ EIGEN_USING_STD(atan);
+ return static_cast<T>(atan(x));
+}
+
+#if EIGEN_HAS_CXX11_MATH
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T atanh(const T &x) {
+ EIGEN_USING_STD(atanh);
+ return static_cast<T>(atanh(x));
+}
+#endif
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(atan, atan)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(atanh, atanh)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float atan(const float &x) { return ::atanf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double atan(const double &x) { return ::atan(x); }
+#endif
+
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T cosh(const T &x) {
+ EIGEN_USING_STD(cosh);
+ return static_cast<T>(cosh(x));
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(cosh, cosh)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float cosh(const float &x) { return ::coshf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double cosh(const double &x) { return ::cosh(x); }
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T sinh(const T &x) {
+ EIGEN_USING_STD(sinh);
+ return static_cast<T>(sinh(x));
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sinh, sinh)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float sinh(const float &x) { return ::sinhf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double sinh(const double &x) { return ::sinh(x); }
+#endif
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T tanh(const T &x) {
+ EIGEN_USING_STD(tanh);
+ return tanh(x);
+}
+
+#if (!defined(EIGEN_GPUCC)) && EIGEN_FAST_MATH && !defined(SYCL_DEVICE_ONLY)
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float tanh(float x) { return internal::generic_fast_tanh_float(x); }
+#endif
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(tanh, tanh)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float tanh(const float &x) { return ::tanhf(x); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double tanh(const double &x) { return ::tanh(x); }
+#endif
+
+template <typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+T fmod(const T& a, const T& b) {
+ EIGEN_USING_STD(fmod);
+ return fmod(a, b);
+}
+
+#if defined(SYCL_DEVICE_ONLY)
+SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(fmod, fmod)
+#endif
+
+#if defined(EIGEN_GPUCC)
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float fmod(const float& a, const float& b) {
+ return ::fmodf(a, b);
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double fmod(const double& a, const double& b) {
+ return ::fmod(a, b);
+}
+#endif
+
+#if defined(SYCL_DEVICE_ONLY)
+#undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY
+#undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY
+#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY
+#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY
+#undef SYCL_SPECIALIZE_INTEGER_TYPES_BINARY
+#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY
+#undef SYCL_SPECIALIZE_FLOATING_TYPES_BINARY
+#undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY
+#undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE
+#undef SYCL_SPECIALIZE_GEN_UNARY_FUNC
+#undef SYCL_SPECIALIZE_UNARY_FUNC
+#undef SYCL_SPECIALIZE_GEN1_BINARY_FUNC
+#undef SYCL_SPECIALIZE_GEN2_BINARY_FUNC
+#undef SYCL_SPECIALIZE_BINARY_FUNC
+#endif
+
+} // end namespace numext
+
+namespace internal {
+
+template<typename T>
+EIGEN_DEVICE_FUNC bool isfinite_impl(const std::complex<T>& x)
+{
+ return (numext::isfinite)(numext::real(x)) && (numext::isfinite)(numext::imag(x));
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC bool isnan_impl(const std::complex<T>& x)
+{
+ return (numext::isnan)(numext::real(x)) || (numext::isnan)(numext::imag(x));
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC bool isinf_impl(const std::complex<T>& x)
+{
+ return ((numext::isinf)(numext::real(x)) || (numext::isinf)(numext::imag(x))) && (!(numext::isnan)(x));
+}
+
+/****************************************************************************
+* Implementation of fuzzy comparisons *
+****************************************************************************/
+
+template<typename Scalar,
+ bool IsComplex,
+ bool IsInteger>
+struct scalar_fuzzy_default_impl {};
+
+template<typename Scalar>
+struct scalar_fuzzy_default_impl<Scalar, false, false>
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ template<typename OtherScalar> EIGEN_DEVICE_FUNC
+ static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, const RealScalar& prec)
+ {
+ return numext::abs(x) <= numext::abs(y) * prec;
+ }
+ EIGEN_DEVICE_FUNC
+ static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec)
+ {
+ return numext::abs(x - y) <= numext::mini(numext::abs(x), numext::abs(y)) * prec;
+ }
+ EIGEN_DEVICE_FUNC
+ static inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y, const RealScalar& prec)
+ {
+ return x <= y || isApprox(x, y, prec);
+ }
+};
+
+template<typename Scalar>
+struct scalar_fuzzy_default_impl<Scalar, false, true>
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ template<typename OtherScalar> EIGEN_DEVICE_FUNC
+ static inline bool isMuchSmallerThan(const Scalar& x, const Scalar&, const RealScalar&)
+ {
+ return x == Scalar(0);
+ }
+ EIGEN_DEVICE_FUNC
+ static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar&)
+ {
+ return x == y;
+ }
+ EIGEN_DEVICE_FUNC
+ static inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y, const RealScalar&)
+ {
+ return x <= y;
+ }
+};
+
+template<typename Scalar>
+struct scalar_fuzzy_default_impl<Scalar, true, false>
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ template<typename OtherScalar> EIGEN_DEVICE_FUNC
+ static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, const RealScalar& prec)
+ {
+ return numext::abs2(x) <= numext::abs2(y) * prec * prec;
+ }
+ EIGEN_DEVICE_FUNC
+ static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec)
+ {
+ return numext::abs2(x - y) <= numext::mini(numext::abs2(x), numext::abs2(y)) * prec * prec;
+ }
+};
+
+template<typename Scalar>
+struct scalar_fuzzy_impl : scalar_fuzzy_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
+
+template<typename Scalar, typename OtherScalar> EIGEN_DEVICE_FUNC
+inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y,
+ const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
+{
+ return scalar_fuzzy_impl<Scalar>::template isMuchSmallerThan<OtherScalar>(x, y, precision);
+}
+
+template<typename Scalar> EIGEN_DEVICE_FUNC
+inline bool isApprox(const Scalar& x, const Scalar& y,
+ const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
+{
+ return scalar_fuzzy_impl<Scalar>::isApprox(x, y, precision);
+}
+
+template<typename Scalar> EIGEN_DEVICE_FUNC
+inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y,
+ const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
+{
+ return scalar_fuzzy_impl<Scalar>::isApproxOrLessThan(x, y, precision);
+}
+
+/******************************************
+*** The special case of the bool type ***
+******************************************/
+
+template<> struct random_impl<bool>
+{
+ static inline bool run()
+ {
+ return random<int>(0,1)==0 ? false : true;
+ }
+
+ static inline bool run(const bool& a, const bool& b)
+ {
+ return random<int>(a, b)==0 ? false : true;
+ }
+};
+
+template<> struct scalar_fuzzy_impl<bool>
+{
+ typedef bool RealScalar;
+
+ template<typename OtherScalar> EIGEN_DEVICE_FUNC
+ static inline bool isMuchSmallerThan(const bool& x, const bool&, const bool&)
+ {
+ return !x;
+ }
+
+ EIGEN_DEVICE_FUNC
+ static inline bool isApprox(bool x, bool y, bool)
+ {
+ return x == y;
+ }
+
+ EIGEN_DEVICE_FUNC
+ static inline bool isApproxOrLessThan(const bool& x, const bool& y, const bool&)
+ {
+ return (!x) || y;
+ }
+
+};
+
+} // end namespace internal
+
+// Default implementations that rely on other numext implementations
+namespace internal {
+
+// Specialization for complex types that are not supported by std::expm1.
+template <typename RealScalar>
+struct expm1_impl<std::complex<RealScalar> > {
+ EIGEN_DEVICE_FUNC static inline std::complex<RealScalar> run(
+ const std::complex<RealScalar>& x) {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar)
+ RealScalar xr = x.real();
+ RealScalar xi = x.imag();
+ // expm1(z) = exp(z) - 1
+ // = exp(x + i * y) - 1
+ // = exp(x) * (cos(y) + i * sin(y)) - 1
+ // = exp(x) * cos(y) - 1 + i * exp(x) * sin(y)
+ // Imag(expm1(z)) = exp(x) * sin(y)
+ // Real(expm1(z)) = exp(x) * cos(y) - 1
+ // = exp(x) * cos(y) - 1.
+ // = expm1(x) + exp(x) * (cos(y) - 1)
+ // = expm1(x) + exp(x) * (2 * sin(y / 2) ** 2)
+ RealScalar erm1 = numext::expm1<RealScalar>(xr);
+ RealScalar er = erm1 + RealScalar(1.);
+ RealScalar sin2 = numext::sin(xi / RealScalar(2.));
+ sin2 = sin2 * sin2;
+ RealScalar s = numext::sin(xi);
+ RealScalar real_part = erm1 - RealScalar(2.) * er * sin2;
+ return std::complex<RealScalar>(real_part, er * s);
+ }
+};
+
+template<typename T>
+struct rsqrt_impl {
+ EIGEN_DEVICE_FUNC
+ static EIGEN_ALWAYS_INLINE T run(const T& x) {
+ return T(1)/numext::sqrt(x);
+ }
+};
+
+#if defined(EIGEN_GPU_COMPILE_PHASE)
+template<typename T>
+struct conj_impl<std::complex<T>, true>
+{
+ EIGEN_DEVICE_FUNC
+ static inline std::complex<T> run(const std::complex<T>& x)
+ {
+ return std::complex<T>(numext::real(x), -numext::imag(x));
+ }
+};
+#endif
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATHFUNCTIONS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/MathFunctionsImpl.h b/src/3rdparty/eigen/Eigen/src/Core/MathFunctionsImpl.h
new file mode 100644
index 000000000..4eaaaa784
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/MathFunctionsImpl.h
@@ -0,0 +1,200 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com)
+// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATHFUNCTIONSIMPL_H
+#define EIGEN_MATHFUNCTIONSIMPL_H
+
+namespace Eigen {
+
+namespace internal {
+
+/** \internal \returns the hyperbolic tan of \a a (coeff-wise)
+ Doesn't do anything fancy, just a 13/6-degree rational interpolant which
+ is accurate up to a couple of ulps in the (approximate) range [-8, 8],
+ outside of which tanh(x) = +/-1 in single precision. The input is clamped
+ to the range [-c, c]. The value c is chosen as the smallest value where
+ the approximation evaluates to exactly 1. In the reange [-0.0004, 0.0004]
+ the approxmation tanh(x) ~= x is used for better accuracy as x tends to zero.
+
+ This implementation works on both scalars and packets.
+*/
+template<typename T>
+T generic_fast_tanh_float(const T& a_x)
+{
+ // Clamp the inputs to the range [-c, c]
+#ifdef EIGEN_VECTORIZE_FMA
+ const T plus_clamp = pset1<T>(7.99881172180175781f);
+ const T minus_clamp = pset1<T>(-7.99881172180175781f);
+#else
+ const T plus_clamp = pset1<T>(7.90531110763549805f);
+ const T minus_clamp = pset1<T>(-7.90531110763549805f);
+#endif
+ const T tiny = pset1<T>(0.0004f);
+ const T x = pmax(pmin(a_x, plus_clamp), minus_clamp);
+ const T tiny_mask = pcmp_lt(pabs(a_x), tiny);
+ // The monomial coefficients of the numerator polynomial (odd).
+ const T alpha_1 = pset1<T>(4.89352455891786e-03f);
+ const T alpha_3 = pset1<T>(6.37261928875436e-04f);
+ const T alpha_5 = pset1<T>(1.48572235717979e-05f);
+ const T alpha_7 = pset1<T>(5.12229709037114e-08f);
+ const T alpha_9 = pset1<T>(-8.60467152213735e-11f);
+ const T alpha_11 = pset1<T>(2.00018790482477e-13f);
+ const T alpha_13 = pset1<T>(-2.76076847742355e-16f);
+
+ // The monomial coefficients of the denominator polynomial (even).
+ const T beta_0 = pset1<T>(4.89352518554385e-03f);
+ const T beta_2 = pset1<T>(2.26843463243900e-03f);
+ const T beta_4 = pset1<T>(1.18534705686654e-04f);
+ const T beta_6 = pset1<T>(1.19825839466702e-06f);
+
+ // Since the polynomials are odd/even, we need x^2.
+ const T x2 = pmul(x, x);
+
+ // Evaluate the numerator polynomial p.
+ T p = pmadd(x2, alpha_13, alpha_11);
+ p = pmadd(x2, p, alpha_9);
+ p = pmadd(x2, p, alpha_7);
+ p = pmadd(x2, p, alpha_5);
+ p = pmadd(x2, p, alpha_3);
+ p = pmadd(x2, p, alpha_1);
+ p = pmul(x, p);
+
+ // Evaluate the denominator polynomial q.
+ T q = pmadd(x2, beta_6, beta_4);
+ q = pmadd(x2, q, beta_2);
+ q = pmadd(x2, q, beta_0);
+
+ // Divide the numerator by the denominator.
+ return pselect(tiny_mask, x, pdiv(p, q));
+}
+
+template<typename RealScalar>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+RealScalar positive_real_hypot(const RealScalar& x, const RealScalar& y)
+{
+ // IEEE IEC 6059 special cases.
+ if ((numext::isinf)(x) || (numext::isinf)(y))
+ return NumTraits<RealScalar>::infinity();
+ if ((numext::isnan)(x) || (numext::isnan)(y))
+ return NumTraits<RealScalar>::quiet_NaN();
+
+ EIGEN_USING_STD(sqrt);
+ RealScalar p, qp;
+ p = numext::maxi(x,y);
+ if(p==RealScalar(0)) return RealScalar(0);
+ qp = numext::mini(y,x) / p;
+ return p * sqrt(RealScalar(1) + qp*qp);
+}
+
+template<typename Scalar>
+struct hypot_impl
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ static EIGEN_DEVICE_FUNC
+ inline RealScalar run(const Scalar& x, const Scalar& y)
+ {
+ EIGEN_USING_STD(abs);
+ return positive_real_hypot<RealScalar>(abs(x), abs(y));
+ }
+};
+
+// Generic complex sqrt implementation that correctly handles corner cases
+// according to https://en.cppreference.com/w/cpp/numeric/complex/sqrt
+template<typename T>
+EIGEN_DEVICE_FUNC std::complex<T> complex_sqrt(const std::complex<T>& z) {
+ // Computes the principal sqrt of the input.
+ //
+ // For a complex square root of the number x + i*y. We want to find real
+ // numbers u and v such that
+ // (u + i*v)^2 = x + i*y <=>
+ // u^2 - v^2 + i*2*u*v = x + i*v.
+ // By equating the real and imaginary parts we get:
+ // u^2 - v^2 = x
+ // 2*u*v = y.
+ //
+ // For x >= 0, this has the numerically stable solution
+ // u = sqrt(0.5 * (x + sqrt(x^2 + y^2)))
+ // v = y / (2 * u)
+ // and for x < 0,
+ // v = sign(y) * sqrt(0.5 * (-x + sqrt(x^2 + y^2)))
+ // u = y / (2 * v)
+ //
+ // Letting w = sqrt(0.5 * (|x| + |z|)),
+ // if x == 0: u = w, v = sign(y) * w
+ // if x > 0: u = w, v = y / (2 * w)
+ // if x < 0: u = |y| / (2 * w), v = sign(y) * w
+
+ const T x = numext::real(z);
+ const T y = numext::imag(z);
+ const T zero = T(0);
+ const T w = numext::sqrt(T(0.5) * (numext::abs(x) + numext::hypot(x, y)));
+
+ return
+ (numext::isinf)(y) ? std::complex<T>(NumTraits<T>::infinity(), y)
+ : x == zero ? std::complex<T>(w, y < zero ? -w : w)
+ : x > zero ? std::complex<T>(w, y / (2 * w))
+ : std::complex<T>(numext::abs(y) / (2 * w), y < zero ? -w : w );
+}
+
+// Generic complex rsqrt implementation.
+template<typename T>
+EIGEN_DEVICE_FUNC std::complex<T> complex_rsqrt(const std::complex<T>& z) {
+ // Computes the principal reciprocal sqrt of the input.
+ //
+ // For a complex reciprocal square root of the number z = x + i*y. We want to
+ // find real numbers u and v such that
+ // (u + i*v)^2 = 1 / (x + i*y) <=>
+ // u^2 - v^2 + i*2*u*v = x/|z|^2 - i*v/|z|^2.
+ // By equating the real and imaginary parts we get:
+ // u^2 - v^2 = x/|z|^2
+ // 2*u*v = y/|z|^2.
+ //
+ // For x >= 0, this has the numerically stable solution
+ // u = sqrt(0.5 * (x + |z|)) / |z|
+ // v = -y / (2 * u * |z|)
+ // and for x < 0,
+ // v = -sign(y) * sqrt(0.5 * (-x + |z|)) / |z|
+ // u = -y / (2 * v * |z|)
+ //
+ // Letting w = sqrt(0.5 * (|x| + |z|)),
+ // if x == 0: u = w / |z|, v = -sign(y) * w / |z|
+ // if x > 0: u = w / |z|, v = -y / (2 * w * |z|)
+ // if x < 0: u = |y| / (2 * w * |z|), v = -sign(y) * w / |z|
+
+ const T x = numext::real(z);
+ const T y = numext::imag(z);
+ const T zero = T(0);
+
+ const T abs_z = numext::hypot(x, y);
+ const T w = numext::sqrt(T(0.5) * (numext::abs(x) + abs_z));
+ const T woz = w / abs_z;
+ // Corner cases consistent with 1/sqrt(z) on gcc/clang.
+ return
+ abs_z == zero ? std::complex<T>(NumTraits<T>::infinity(), NumTraits<T>::quiet_NaN())
+ : ((numext::isinf)(x) || (numext::isinf)(y)) ? std::complex<T>(zero, zero)
+ : x == zero ? std::complex<T>(woz, y < zero ? woz : -woz)
+ : x > zero ? std::complex<T>(woz, -y / (2 * w * abs_z))
+ : std::complex<T>(numext::abs(y) / (2 * w * abs_z), y < zero ? woz : -woz );
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC std::complex<T> complex_log(const std::complex<T>& z) {
+ // Computes complex log.
+ T a = numext::abs(z);
+ EIGEN_USING_STD(atan2);
+ T b = atan2(z.imag(), z.real());
+ return std::complex<T>(numext::log(a), b);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATHFUNCTIONSIMPL_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Matrix.h b/src/3rdparty/eigen/Eigen/src/Core/Matrix.h
new file mode 100644
index 000000000..f0e59a911
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Matrix.h
@@ -0,0 +1,565 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATRIX_H
+#define EIGEN_MATRIX_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
+struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
+{
+private:
+ enum { size = internal::size_at_compile_time<_Rows,_Cols>::ret };
+ typedef typename find_best_packet<_Scalar,size>::type PacketScalar;
+ enum {
+ row_major_bit = _Options&RowMajor ? RowMajorBit : 0,
+ is_dynamic_size_storage = _MaxRows==Dynamic || _MaxCols==Dynamic,
+ max_size = is_dynamic_size_storage ? Dynamic : _MaxRows*_MaxCols,
+ default_alignment = compute_default_alignment<_Scalar,max_size>::value,
+ actual_alignment = ((_Options&DontAlign)==0) ? default_alignment : 0,
+ required_alignment = unpacket_traits<PacketScalar>::alignment,
+ packet_access_bit = (packet_traits<_Scalar>::Vectorizable && (EIGEN_UNALIGNED_VECTORIZE || (actual_alignment>=required_alignment))) ? PacketAccessBit : 0
+ };
+
+public:
+ typedef _Scalar Scalar;
+ typedef Dense StorageKind;
+ typedef Eigen::Index StorageIndex;
+ typedef MatrixXpr XprKind;
+ enum {
+ RowsAtCompileTime = _Rows,
+ ColsAtCompileTime = _Cols,
+ MaxRowsAtCompileTime = _MaxRows,
+ MaxColsAtCompileTime = _MaxCols,
+ Flags = compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret,
+ Options = _Options,
+ InnerStrideAtCompileTime = 1,
+ OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime,
+
+ // FIXME, the following flag in only used to define NeedsToAlign in PlainObjectBase
+ EvaluatorFlags = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit,
+ Alignment = actual_alignment
+ };
+};
+}
+
+/** \class Matrix
+ * \ingroup Core_Module
+ *
+ * \brief The matrix class, also used for vectors and row-vectors
+ *
+ * The %Matrix class is the work-horse for all \em dense (\ref dense "note") matrices and vectors within Eigen.
+ * Vectors are matrices with one column, and row-vectors are matrices with one row.
+ *
+ * The %Matrix class encompasses \em both fixed-size and dynamic-size objects (\ref fixedsize "note").
+ *
+ * The first three template parameters are required:
+ * \tparam _Scalar Numeric type, e.g. float, double, int or std::complex<float>.
+ * User defined scalar types are supported as well (see \ref user_defined_scalars "here").
+ * \tparam _Rows Number of rows, or \b Dynamic
+ * \tparam _Cols Number of columns, or \b Dynamic
+ *
+ * The remaining template parameters are optional -- in most cases you don't have to worry about them.
+ * \tparam _Options A combination of either \b #RowMajor or \b #ColMajor, and of either
+ * \b #AutoAlign or \b #DontAlign.
+ * The former controls \ref TopicStorageOrders "storage order", and defaults to column-major. The latter controls alignment, which is required
+ * for vectorization. It defaults to aligning matrices except for fixed sizes that aren't a multiple of the packet size.
+ * \tparam _MaxRows Maximum number of rows. Defaults to \a _Rows (\ref maxrows "note").
+ * \tparam _MaxCols Maximum number of columns. Defaults to \a _Cols (\ref maxrows "note").
+ *
+ * Eigen provides a number of typedefs covering the usual cases. Here are some examples:
+ *
+ * \li \c Matrix2d is a 2x2 square matrix of doubles (\c Matrix<double, 2, 2>)
+ * \li \c Vector4f is a vector of 4 floats (\c Matrix<float, 4, 1>)
+ * \li \c RowVector3i is a row-vector of 3 ints (\c Matrix<int, 1, 3>)
+ *
+ * \li \c MatrixXf is a dynamic-size matrix of floats (\c Matrix<float, Dynamic, Dynamic>)
+ * \li \c VectorXf is a dynamic-size vector of floats (\c Matrix<float, Dynamic, 1>)
+ *
+ * \li \c Matrix2Xf is a partially fixed-size (dynamic-size) matrix of floats (\c Matrix<float, 2, Dynamic>)
+ * \li \c MatrixX3d is a partially dynamic-size (fixed-size) matrix of double (\c Matrix<double, Dynamic, 3>)
+ *
+ * See \link matrixtypedefs this page \endlink for a complete list of predefined \em %Matrix and \em Vector typedefs.
+ *
+ * You can access elements of vectors and matrices using normal subscripting:
+ *
+ * \code
+ * Eigen::VectorXd v(10);
+ * v[0] = 0.1;
+ * v[1] = 0.2;
+ * v(0) = 0.3;
+ * v(1) = 0.4;
+ *
+ * Eigen::MatrixXi m(10, 10);
+ * m(0, 1) = 1;
+ * m(0, 2) = 2;
+ * m(0, 3) = 3;
+ * \endcode
+ *
+ * This class can be extended with the help of the plugin mechanism described on the page
+ * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_MATRIX_PLUGIN.
+ *
+ * <i><b>Some notes:</b></i>
+ *
+ * <dl>
+ * <dt><b>\anchor dense Dense versus sparse:</b></dt>
+ * <dd>This %Matrix class handles dense, not sparse matrices and vectors. For sparse matrices and vectors, see the Sparse module.
+ *
+ * Dense matrices and vectors are plain usual arrays of coefficients. All the coefficients are stored, in an ordinary contiguous array.
+ * This is unlike Sparse matrices and vectors where the coefficients are stored as a list of nonzero coefficients.</dd>
+ *
+ * <dt><b>\anchor fixedsize Fixed-size versus dynamic-size:</b></dt>
+ * <dd>Fixed-size means that the numbers of rows and columns are known are compile-time. In this case, Eigen allocates the array
+ * of coefficients as a fixed-size array, as a class member. This makes sense for very small matrices, typically up to 4x4, sometimes up
+ * to 16x16. Larger matrices should be declared as dynamic-size even if one happens to know their size at compile-time.
+ *
+ * Dynamic-size means that the numbers of rows or columns are not necessarily known at compile-time. In this case they are runtime
+ * variables, and the array of coefficients is allocated dynamically on the heap.
+ *
+ * Note that \em dense matrices, be they Fixed-size or Dynamic-size, <em>do not</em> expand dynamically in the sense of a std::map.
+ * If you want this behavior, see the Sparse module.</dd>
+ *
+ * <dt><b>\anchor maxrows _MaxRows and _MaxCols:</b></dt>
+ * <dd>In most cases, one just leaves these parameters to the default values.
+ * These parameters mean the maximum size of rows and columns that the matrix may have. They are useful in cases
+ * when the exact numbers of rows and columns are not known are compile-time, but it is known at compile-time that they cannot
+ * exceed a certain value. This happens when taking dynamic-size blocks inside fixed-size matrices: in this case _MaxRows and _MaxCols
+ * are the dimensions of the original matrix, while _Rows and _Cols are Dynamic.</dd>
+ * </dl>
+ *
+ * <i><b>ABI and storage layout</b></i>
+ *
+ * The table below summarizes the ABI of some possible Matrix instances which is fixed thorough the lifetime of Eigen 3.
+ * <table class="manual">
+ * <tr><th>Matrix type</th><th>Equivalent C structure</th></tr>
+ * <tr><td>\code Matrix<T,Dynamic,Dynamic> \endcode</td><td>\code
+ * struct {
+ * T *data; // with (size_t(data)%EIGEN_MAX_ALIGN_BYTES)==0
+ * Eigen::Index rows, cols;
+ * };
+ * \endcode</td></tr>
+ * <tr class="alt"><td>\code
+ * Matrix<T,Dynamic,1>
+ * Matrix<T,1,Dynamic> \endcode</td><td>\code
+ * struct {
+ * T *data; // with (size_t(data)%EIGEN_MAX_ALIGN_BYTES)==0
+ * Eigen::Index size;
+ * };
+ * \endcode</td></tr>
+ * <tr><td>\code Matrix<T,Rows,Cols> \endcode</td><td>\code
+ * struct {
+ * T data[Rows*Cols]; // with (size_t(data)%A(Rows*Cols*sizeof(T)))==0
+ * };
+ * \endcode</td></tr>
+ * <tr class="alt"><td>\code Matrix<T,Dynamic,Dynamic,0,MaxRows,MaxCols> \endcode</td><td>\code
+ * struct {
+ * T data[MaxRows*MaxCols]; // with (size_t(data)%A(MaxRows*MaxCols*sizeof(T)))==0
+ * Eigen::Index rows, cols;
+ * };
+ * \endcode</td></tr>
+ * </table>
+ * Note that in this table Rows, Cols, MaxRows and MaxCols are all positive integers. A(S) is defined to the largest possible power-of-two
+ * smaller to EIGEN_MAX_STATIC_ALIGN_BYTES.
+ *
+ * \see MatrixBase for the majority of the API methods for matrices, \ref TopicClassHierarchy,
+ * \ref TopicStorageOrders
+ */
+
+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
+class Matrix
+ : public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
+{
+ public:
+
+ /** \brief Base class typedef.
+ * \sa PlainObjectBase
+ */
+ typedef PlainObjectBase<Matrix> Base;
+
+ enum { Options = _Options };
+
+ EIGEN_DENSE_PUBLIC_INTERFACE(Matrix)
+
+ typedef typename Base::PlainObject PlainObject;
+
+ using Base::base;
+ using Base::coeffRef;
+
+ /**
+ * \brief Assigns matrices to each other.
+ *
+ * \note This is a special case of the templated operator=. Its purpose is
+ * to prevent a default operator= from hiding the templated operator=.
+ *
+ * \callgraph
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other)
+ {
+ return Base::_set(other);
+ }
+
+ /** \internal
+ * \brief Copies the value of the expression \a other into \c *this with automatic resizing.
+ *
+ * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized),
+ * it will be initialized.
+ *
+ * Note that copying a row-vector into a vector (and conversely) is allowed.
+ * The resizing, if any, is then done in the appropriate way so that row-vectors
+ * remain row-vectors and vectors remain vectors.
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Matrix& operator=(const DenseBase<OtherDerived>& other)
+ {
+ return Base::_set(other);
+ }
+
+ /* Here, doxygen failed to copy the brief information when using \copydoc */
+
+ /**
+ * \brief Copies the generic expression \a other into *this.
+ * \copydetails DenseBase::operator=(const EigenBase<OtherDerived> &other)
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived> &other)
+ {
+ return Base::operator=(other);
+ }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func)
+ {
+ return Base::operator=(func);
+ }
+
+ /** \brief Default constructor.
+ *
+ * For fixed-size matrices, does nothing.
+ *
+ * For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix
+ * is called a null matrix. This constructor is the unique way to create null matrices: resizing
+ * a matrix to 0 is not supported.
+ *
+ * \sa resize(Index,Index)
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Matrix() : Base()
+ {
+ Base::_check_template_params();
+ EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
+ }
+
+ // FIXME is it still needed
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit Matrix(internal::constructor_without_unaligned_array_assert)
+ : Base(internal::constructor_without_unaligned_array_assert())
+ { Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED }
+
+#if EIGEN_HAS_RVALUE_REFERENCES
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Matrix(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
+ : Base(std::move(other))
+ {
+ Base::_check_template_params();
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Matrix& operator=(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
+ {
+ Base::operator=(std::move(other));
+ return *this;
+ }
+#endif
+
+#if EIGEN_HAS_CXX11
+ /** \copydoc PlainObjectBase(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&... args)
+ *
+ * Example: \include Matrix_variadic_ctor_cxx11.cpp
+ * Output: \verbinclude Matrix_variadic_ctor_cxx11.out
+ *
+ * \sa Matrix(const std::initializer_list<std::initializer_list<Scalar>>&)
+ */
+ template <typename... ArgTypes>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
+ : Base(a0, a1, a2, a3, args...) {}
+
+ /** \brief Constructs a Matrix and initializes it from the coefficients given as initializer-lists grouped by row. \cpp11
+ *
+ * In the general case, the constructor takes a list of rows, each row being represented as a list of coefficients:
+ *
+ * Example: \include Matrix_initializer_list_23_cxx11.cpp
+ * Output: \verbinclude Matrix_initializer_list_23_cxx11.out
+ *
+ * Each of the inner initializer lists must contain the exact same number of elements, otherwise an assertion is triggered.
+ *
+ * In the case of a compile-time column vector, implicit transposition from a single row is allowed.
+ * Therefore <code>VectorXd{{1,2,3,4,5}}</code> is legal and the more verbose syntax
+ * <code>RowVectorXd{{1},{2},{3},{4},{5}}</code> can be avoided:
+ *
+ * Example: \include Matrix_initializer_list_vector_cxx11.cpp
+ * Output: \verbinclude Matrix_initializer_list_vector_cxx11.out
+ *
+ * In the case of fixed-sized matrices, the initializer list sizes must exactly match the matrix sizes,
+ * and implicit transposition is allowed for compile-time vectors only.
+ *
+ * \sa Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
+ */
+ EIGEN_DEVICE_FUNC
+ explicit EIGEN_STRONG_INLINE Matrix(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {}
+#endif // end EIGEN_HAS_CXX11
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+
+ // This constructor is for both 1x1 matrices and dynamic vectors
+ template<typename T>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit Matrix(const T& x)
+ {
+ Base::_check_template_params();
+ Base::template _init1<T>(x);
+ }
+
+ template<typename T0, typename T1>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Matrix(const T0& x, const T1& y)
+ {
+ Base::_check_template_params();
+ Base::template _init2<T0,T1>(x, y);
+ }
+
+
+#else
+ /** \brief Constructs a fixed-sized matrix initialized with coefficients starting at \a data */
+ EIGEN_DEVICE_FUNC
+ explicit Matrix(const Scalar *data);
+
+ /** \brief Constructs a vector or row-vector with given dimension. \only_for_vectors
+ *
+ * This is useful for dynamic-size vectors. For fixed-size vectors,
+ * it is redundant to pass these parameters, so one should use the default constructor
+ * Matrix() instead.
+ *
+ * \warning This constructor is disabled for fixed-size \c 1x1 matrices. For instance,
+ * calling Matrix<double,1,1>(1) will call the initialization constructor: Matrix(const Scalar&).
+ * For fixed-size \c 1x1 matrices it is therefore recommended to use the default
+ * constructor Matrix() instead, especially when using one of the non standard
+ * \c EIGEN_INITIALIZE_MATRICES_BY_{ZERO,\c NAN} macros (see \ref TopicPreprocessorDirectives).
+ */
+ EIGEN_STRONG_INLINE explicit Matrix(Index dim);
+ /** \brief Constructs an initialized 1x1 matrix with the given coefficient
+ * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) */
+ Matrix(const Scalar& x);
+ /** \brief Constructs an uninitialized matrix with \a rows rows and \a cols columns.
+ *
+ * This is useful for dynamic-size matrices. For fixed-size matrices,
+ * it is redundant to pass these parameters, so one should use the default constructor
+ * Matrix() instead.
+ *
+ * \warning This constructor is disabled for fixed-size \c 1x2 and \c 2x1 vectors. For instance,
+ * calling Matrix2f(2,1) will call the initialization constructor: Matrix(const Scalar& x, const Scalar& y).
+ * For fixed-size \c 1x2 or \c 2x1 vectors it is therefore recommended to use the default
+ * constructor Matrix() instead, especially when using one of the non standard
+ * \c EIGEN_INITIALIZE_MATRICES_BY_{ZERO,\c NAN} macros (see \ref TopicPreprocessorDirectives).
+ */
+ EIGEN_DEVICE_FUNC
+ Matrix(Index rows, Index cols);
+
+ /** \brief Constructs an initialized 2D vector with given coefficients
+ * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) */
+ Matrix(const Scalar& x, const Scalar& y);
+ #endif // end EIGEN_PARSED_BY_DOXYGEN
+
+ /** \brief Constructs an initialized 3D vector with given coefficients
+ * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...)
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
+ {
+ Base::_check_template_params();
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3)
+ m_storage.data()[0] = x;
+ m_storage.data()[1] = y;
+ m_storage.data()[2] = z;
+ }
+ /** \brief Constructs an initialized 4D vector with given coefficients
+ * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...)
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
+ {
+ Base::_check_template_params();
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4)
+ m_storage.data()[0] = x;
+ m_storage.data()[1] = y;
+ m_storage.data()[2] = z;
+ m_storage.data()[3] = w;
+ }
+
+
+ /** \brief Copy constructor */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Matrix(const Matrix& other) : Base(other)
+ { }
+
+ /** \brief Copy constructor for generic expressions.
+ * \sa MatrixBase::operator=(const EigenBase<OtherDerived>&)
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived> &other)
+ : Base(other.derived())
+ { }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const EIGEN_NOEXCEPT { return 1; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
+
+ /////////// Geometry module ///////////
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ explicit Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ Matrix& operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
+
+ // allow to extend Matrix outside Eigen
+ #ifdef EIGEN_MATRIX_PLUGIN
+ #include EIGEN_MATRIX_PLUGIN
+ #endif
+
+ protected:
+ template <typename Derived, typename OtherDerived, bool IsVector>
+ friend struct internal::conservative_resize_like_impl;
+
+ using Base::m_storage;
+};
+
+/** \defgroup matrixtypedefs Global matrix typedefs
+ *
+ * \ingroup Core_Module
+ *
+ * %Eigen defines several typedef shortcuts for most common matrix and vector types.
+ *
+ * The general patterns are the following:
+ *
+ * \c MatrixSizeType where \c Size can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size,
+ * and where \c Type can be \c i for integer, \c f for float, \c d for double, \c cf for complex float, \c cd
+ * for complex double.
+ *
+ * For example, \c Matrix3d is a fixed-size 3x3 matrix type of doubles, and \c MatrixXf is a dynamic-size matrix of floats.
+ *
+ * There are also \c VectorSizeType and \c RowVectorSizeType which are self-explanatory. For example, \c Vector4cf is
+ * a fixed-size vector of 4 complex floats.
+ *
+ * With \cpp11, template alias are also defined for common sizes.
+ * They follow the same pattern as above except that the scalar type suffix is replaced by a
+ * template parameter, i.e.:
+ * - `MatrixSize<Type>` where `Size` can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size.
+ * - `MatrixXSize<Type>` and `MatrixSizeX<Type>` where `Size` can be \c 2,\c 3,\c 4 for hybrid dynamic/fixed matrices.
+ * - `VectorSize<Type>` and `RowVectorSize<Type>` for column and row vectors.
+ *
+ * With \cpp11, you can also use fully generic column and row vector types: `Vector<Type,Size>` and `RowVector<Type,Size>`.
+ *
+ * \sa class Matrix
+ */
+
+#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
+/** \ingroup matrixtypedefs */ \
+typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
+/** \ingroup matrixtypedefs */ \
+typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
+/** \ingroup matrixtypedefs */ \
+typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
+
+#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
+/** \ingroup matrixtypedefs */ \
+typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \
+/** \ingroup matrixtypedefs */ \
+typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
+
+#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
+EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
+EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
+EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
+EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
+EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
+EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
+EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
+
+EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i)
+EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)
+EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d)
+EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
+EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
+
+#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
+#undef EIGEN_MAKE_TYPEDEFS
+#undef EIGEN_MAKE_FIXED_TYPEDEFS
+
+#if EIGEN_HAS_CXX11
+
+#define EIGEN_MAKE_TYPEDEFS(Size, SizeSuffix) \
+/** \ingroup matrixtypedefs */ \
+/** \brief \cpp11 */ \
+template <typename Type> \
+using Matrix##SizeSuffix = Matrix<Type, Size, Size>; \
+/** \ingroup matrixtypedefs */ \
+/** \brief \cpp11 */ \
+template <typename Type> \
+using Vector##SizeSuffix = Matrix<Type, Size, 1>; \
+/** \ingroup matrixtypedefs */ \
+/** \brief \cpp11 */ \
+template <typename Type> \
+using RowVector##SizeSuffix = Matrix<Type, 1, Size>;
+
+#define EIGEN_MAKE_FIXED_TYPEDEFS(Size) \
+/** \ingroup matrixtypedefs */ \
+/** \brief \cpp11 */ \
+template <typename Type> \
+using Matrix##Size##X = Matrix<Type, Size, Dynamic>; \
+/** \ingroup matrixtypedefs */ \
+/** \brief \cpp11 */ \
+template <typename Type> \
+using Matrix##X##Size = Matrix<Type, Dynamic, Size>;
+
+EIGEN_MAKE_TYPEDEFS(2, 2)
+EIGEN_MAKE_TYPEDEFS(3, 3)
+EIGEN_MAKE_TYPEDEFS(4, 4)
+EIGEN_MAKE_TYPEDEFS(Dynamic, X)
+EIGEN_MAKE_FIXED_TYPEDEFS(2)
+EIGEN_MAKE_FIXED_TYPEDEFS(3)
+EIGEN_MAKE_FIXED_TYPEDEFS(4)
+
+/** \ingroup matrixtypedefs
+ * \brief \cpp11 */
+template <typename Type, int Size>
+using Vector = Matrix<Type, Size, 1>;
+
+/** \ingroup matrixtypedefs
+ * \brief \cpp11 */
+template <typename Type, int Size>
+using RowVector = Matrix<Type, 1, Size>;
+
+#undef EIGEN_MAKE_TYPEDEFS
+#undef EIGEN_MAKE_FIXED_TYPEDEFS
+
+#endif // EIGEN_HAS_CXX11
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATRIX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/MatrixBase.h b/src/3rdparty/eigen/Eigen/src/Core/MatrixBase.h
new file mode 100644
index 000000000..45c3a596e
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/MatrixBase.h
@@ -0,0 +1,547 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATRIXBASE_H
+#define EIGEN_MATRIXBASE_H
+
+namespace Eigen {
+
+/** \class MatrixBase
+ * \ingroup Core_Module
+ *
+ * \brief Base class for all dense matrices, vectors, and expressions
+ *
+ * This class is the base that is inherited by all matrix, vector, and related expression
+ * types. Most of the Eigen API is contained in this class, and its base classes. Other important
+ * classes for the Eigen API are Matrix, and VectorwiseOp.
+ *
+ * Note that some methods are defined in other modules such as the \ref LU_Module LU module
+ * for all functions related to matrix inversions.
+ *
+ * \tparam Derived is the derived type, e.g. a matrix type, or an expression, etc.
+ *
+ * When writing a function taking Eigen objects as argument, if you want your function
+ * to take as argument any matrix, vector, or expression, just let it take a
+ * MatrixBase argument. As an example, here is a function printFirstRow which, given
+ * a matrix, vector, or expression \a x, prints the first row of \a x.
+ *
+ * \code
+ template<typename Derived>
+ void printFirstRow(const Eigen::MatrixBase<Derived>& x)
+ {
+ cout << x.row(0) << endl;
+ }
+ * \endcode
+ *
+ * This class can be extended with the help of the plugin mechanism described on the page
+ * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_MATRIXBASE_PLUGIN.
+ *
+ * \sa \blank \ref TopicClassHierarchy
+ */
+template<typename Derived> class MatrixBase
+ : public DenseBase<Derived>
+{
+ public:
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ typedef MatrixBase StorageBaseType;
+ typedef typename internal::traits<Derived>::StorageKind StorageKind;
+ typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+ typedef typename internal::packet_traits<Scalar>::type PacketScalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ typedef DenseBase<Derived> Base;
+ using Base::RowsAtCompileTime;
+ using Base::ColsAtCompileTime;
+ using Base::SizeAtCompileTime;
+ using Base::MaxRowsAtCompileTime;
+ using Base::MaxColsAtCompileTime;
+ using Base::MaxSizeAtCompileTime;
+ using Base::IsVectorAtCompileTime;
+ using Base::Flags;
+
+ using Base::derived;
+ using Base::const_cast_derived;
+ using Base::rows;
+ using Base::cols;
+ using Base::size;
+ using Base::coeff;
+ using Base::coeffRef;
+ using Base::lazyAssign;
+ using Base::eval;
+ using Base::operator-;
+ using Base::operator+=;
+ using Base::operator-=;
+ using Base::operator*=;
+ using Base::operator/=;
+
+ typedef typename Base::CoeffReturnType CoeffReturnType;
+ typedef typename Base::ConstTransposeReturnType ConstTransposeReturnType;
+ typedef typename Base::RowXpr RowXpr;
+ typedef typename Base::ColXpr ColXpr;
+#endif // not EIGEN_PARSED_BY_DOXYGEN
+
+
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ /** type of the equivalent square matrix */
+ typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime),
+ EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType;
+#endif // not EIGEN_PARSED_BY_DOXYGEN
+
+ /** \returns the size of the main diagonal, which is min(rows(),cols()).
+ * \sa rows(), cols(), SizeAtCompileTime. */
+ EIGEN_DEVICE_FUNC
+ inline Index diagonalSize() const { return (numext::mini)(rows(),cols()); }
+
+ typedef typename Base::PlainObject PlainObject;
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ /** \internal Represents a matrix with all coefficients equal to one another*/
+ typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
+ /** \internal the return type of MatrixBase::adjoint() */
+ typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
+ CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, ConstTransposeReturnType>,
+ ConstTransposeReturnType
+ >::type AdjointReturnType;
+ /** \internal Return type of eigenvalues() */
+ typedef Matrix<std::complex<RealScalar>, internal::traits<Derived>::ColsAtCompileTime, 1, ColMajor> EigenvaluesReturnType;
+ /** \internal the return type of identity */
+ typedef CwiseNullaryOp<internal::scalar_identity_op<Scalar>,PlainObject> IdentityReturnType;
+ /** \internal the return type of unit vectors */
+ typedef Block<const CwiseNullaryOp<internal::scalar_identity_op<Scalar>, SquareMatrixType>,
+ internal::traits<Derived>::RowsAtCompileTime,
+ internal::traits<Derived>::ColsAtCompileTime> BasisReturnType;
+#endif // not EIGEN_PARSED_BY_DOXYGEN
+
+#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::MatrixBase
+#define EIGEN_DOC_UNARY_ADDONS(X,Y)
+# include "../plugins/CommonCwiseBinaryOps.h"
+# include "../plugins/MatrixCwiseUnaryOps.h"
+# include "../plugins/MatrixCwiseBinaryOps.h"
+# ifdef EIGEN_MATRIXBASE_PLUGIN
+# include EIGEN_MATRIXBASE_PLUGIN
+# endif
+#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
+#undef EIGEN_DOC_UNARY_ADDONS
+
+ /** Special case of the template operator=, in order to prevent the compiler
+ * from generating a default operator= (issue hit with g++ 4.1)
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator=(const MatrixBase& other);
+
+ // We cannot inherit here via Base::operator= since it is causing
+ // trouble with MSVC.
+
+ template <typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator=(const DenseBase<OtherDerived>& other);
+
+ template <typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ Derived& operator=(const EigenBase<OtherDerived>& other);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ Derived& operator=(const ReturnByValue<OtherDerived>& other);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator+=(const MatrixBase<OtherDerived>& other);
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Derived& operator-=(const MatrixBase<OtherDerived>& other);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ const Product<Derived,OtherDerived>
+ operator*(const MatrixBase<OtherDerived> &other) const;
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ const Product<Derived,OtherDerived,LazyProduct>
+ lazyProduct(const MatrixBase<OtherDerived> &other) const;
+
+ template<typename OtherDerived>
+ Derived& operator*=(const EigenBase<OtherDerived>& other);
+
+ template<typename OtherDerived>
+ void applyOnTheLeft(const EigenBase<OtherDerived>& other);
+
+ template<typename OtherDerived>
+ void applyOnTheRight(const EigenBase<OtherDerived>& other);
+
+ template<typename DiagonalDerived>
+ EIGEN_DEVICE_FUNC
+ const Product<Derived, DiagonalDerived, LazyProduct>
+ operator*(const DiagonalBase<DiagonalDerived> &diagonal) const;
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType
+ dot(const MatrixBase<OtherDerived>& other) const;
+
+ EIGEN_DEVICE_FUNC RealScalar squaredNorm() const;
+ EIGEN_DEVICE_FUNC RealScalar norm() const;
+ RealScalar stableNorm() const;
+ RealScalar blueNorm() const;
+ RealScalar hypotNorm() const;
+ EIGEN_DEVICE_FUNC const PlainObject normalized() const;
+ EIGEN_DEVICE_FUNC const PlainObject stableNormalized() const;
+ EIGEN_DEVICE_FUNC void normalize();
+ EIGEN_DEVICE_FUNC void stableNormalize();
+
+ EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const;
+ EIGEN_DEVICE_FUNC void adjointInPlace();
+
+ typedef Diagonal<Derived> DiagonalReturnType;
+ EIGEN_DEVICE_FUNC
+ DiagonalReturnType diagonal();
+
+ typedef typename internal::add_const<Diagonal<const Derived> >::type ConstDiagonalReturnType;
+ EIGEN_DEVICE_FUNC
+ ConstDiagonalReturnType diagonal() const;
+
+ template<int Index> struct DiagonalIndexReturnType { typedef Diagonal<Derived,Index> Type; };
+ template<int Index> struct ConstDiagonalIndexReturnType { typedef const Diagonal<const Derived,Index> Type; };
+
+ template<int Index>
+ EIGEN_DEVICE_FUNC
+ typename DiagonalIndexReturnType<Index>::Type diagonal();
+
+ template<int Index>
+ EIGEN_DEVICE_FUNC
+ typename ConstDiagonalIndexReturnType<Index>::Type diagonal() const;
+
+ typedef Diagonal<Derived,DynamicIndex> DiagonalDynamicIndexReturnType;
+ typedef typename internal::add_const<Diagonal<const Derived,DynamicIndex> >::type ConstDiagonalDynamicIndexReturnType;
+
+ EIGEN_DEVICE_FUNC
+ DiagonalDynamicIndexReturnType diagonal(Index index);
+ EIGEN_DEVICE_FUNC
+ ConstDiagonalDynamicIndexReturnType diagonal(Index index) const;
+
+ template<unsigned int Mode> struct TriangularViewReturnType { typedef TriangularView<Derived, Mode> Type; };
+ template<unsigned int Mode> struct ConstTriangularViewReturnType { typedef const TriangularView<const Derived, Mode> Type; };
+
+ template<unsigned int Mode>
+ EIGEN_DEVICE_FUNC
+ typename TriangularViewReturnType<Mode>::Type triangularView();
+ template<unsigned int Mode>
+ EIGEN_DEVICE_FUNC
+ typename ConstTriangularViewReturnType<Mode>::Type triangularView() const;
+
+ template<unsigned int UpLo> struct SelfAdjointViewReturnType { typedef SelfAdjointView<Derived, UpLo> Type; };
+ template<unsigned int UpLo> struct ConstSelfAdjointViewReturnType { typedef const SelfAdjointView<const Derived, UpLo> Type; };
+
+ template<unsigned int UpLo>
+ EIGEN_DEVICE_FUNC
+ typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView();
+ template<unsigned int UpLo>
+ EIGEN_DEVICE_FUNC
+ typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView() const;
+
+ const SparseView<Derived> sparseView(const Scalar& m_reference = Scalar(0),
+ const typename NumTraits<Scalar>::Real& m_epsilon = NumTraits<Scalar>::dummy_precision()) const;
+ EIGEN_DEVICE_FUNC static const IdentityReturnType Identity();
+ EIGEN_DEVICE_FUNC static const IdentityReturnType Identity(Index rows, Index cols);
+ EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index size, Index i);
+ EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index i);
+ EIGEN_DEVICE_FUNC static const BasisReturnType UnitX();
+ EIGEN_DEVICE_FUNC static const BasisReturnType UnitY();
+ EIGEN_DEVICE_FUNC static const BasisReturnType UnitZ();
+ EIGEN_DEVICE_FUNC static const BasisReturnType UnitW();
+
+ EIGEN_DEVICE_FUNC
+ const DiagonalWrapper<const Derived> asDiagonal() const;
+ const PermutationWrapper<const Derived> asPermutation() const;
+
+ EIGEN_DEVICE_FUNC
+ Derived& setIdentity();
+ EIGEN_DEVICE_FUNC
+ Derived& setIdentity(Index rows, Index cols);
+ EIGEN_DEVICE_FUNC Derived& setUnit(Index i);
+ EIGEN_DEVICE_FUNC Derived& setUnit(Index newSize, Index i);
+
+ bool isIdentity(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+ bool isDiagonal(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+
+ bool isUpperTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+ bool isLowerTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+
+ template<typename OtherDerived>
+ bool isOrthogonal(const MatrixBase<OtherDerived>& other,
+ const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+ bool isUnitary(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
+
+ /** \returns true if each coefficients of \c *this and \a other are all exactly equal.
+ * \warning When using floating point scalar values you probably should rather use a
+ * fuzzy comparison such as isApprox()
+ * \sa isApprox(), operator!= */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC inline bool operator==(const MatrixBase<OtherDerived>& other) const
+ { return cwiseEqual(other).all(); }
+
+ /** \returns true if at least one pair of coefficients of \c *this and \a other are not exactly equal to each other.
+ * \warning When using floating point scalar values you probably should rather use a
+ * fuzzy comparison such as isApprox()
+ * \sa isApprox(), operator== */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC inline bool operator!=(const MatrixBase<OtherDerived>& other) const
+ { return cwiseNotEqual(other).any(); }
+
+ NoAlias<Derived,Eigen::MatrixBase > EIGEN_DEVICE_FUNC noalias();
+
+ // TODO forceAlignedAccess is temporarily disabled
+ // Need to find a nicer workaround.
+ inline const Derived& forceAlignedAccess() const { return derived(); }
+ inline Derived& forceAlignedAccess() { return derived(); }
+ template<bool Enable> inline const Derived& forceAlignedAccessIf() const { return derived(); }
+ template<bool Enable> inline Derived& forceAlignedAccessIf() { return derived(); }
+
+ EIGEN_DEVICE_FUNC Scalar trace() const;
+
+ template<int p> EIGEN_DEVICE_FUNC RealScalar lpNorm() const;
+
+ EIGEN_DEVICE_FUNC MatrixBase<Derived>& matrix() { return *this; }
+ EIGEN_DEVICE_FUNC const MatrixBase<Derived>& matrix() const { return *this; }
+
+ /** \returns an \link Eigen::ArrayBase Array \endlink expression of this matrix
+ * \sa ArrayBase::matrix() */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ArrayWrapper<Derived> array() { return ArrayWrapper<Derived>(derived()); }
+ /** \returns a const \link Eigen::ArrayBase Array \endlink expression of this matrix
+ * \sa ArrayBase::matrix() */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArrayWrapper<const Derived> array() const { return ArrayWrapper<const Derived>(derived()); }
+
+/////////// LU module ///////////
+
+ inline const FullPivLU<PlainObject> fullPivLu() const;
+ inline const PartialPivLU<PlainObject> partialPivLu() const;
+
+ inline const PartialPivLU<PlainObject> lu() const;
+
+ EIGEN_DEVICE_FUNC
+ inline const Inverse<Derived> inverse() const;
+
+ template<typename ResultType>
+ inline void computeInverseAndDetWithCheck(
+ ResultType& inverse,
+ typename ResultType::Scalar& determinant,
+ bool& invertible,
+ const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
+ ) const;
+
+ template<typename ResultType>
+ inline void computeInverseWithCheck(
+ ResultType& inverse,
+ bool& invertible,
+ const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
+ ) const;
+
+ EIGEN_DEVICE_FUNC
+ Scalar determinant() const;
+
+/////////// Cholesky module ///////////
+
+ inline const LLT<PlainObject> llt() const;
+ inline const LDLT<PlainObject> ldlt() const;
+
+/////////// QR module ///////////
+
+ inline const HouseholderQR<PlainObject> householderQr() const;
+ inline const ColPivHouseholderQR<PlainObject> colPivHouseholderQr() const;
+ inline const FullPivHouseholderQR<PlainObject> fullPivHouseholderQr() const;
+ inline const CompleteOrthogonalDecomposition<PlainObject> completeOrthogonalDecomposition() const;
+
+/////////// Eigenvalues module ///////////
+
+ inline EigenvaluesReturnType eigenvalues() const;
+ inline RealScalar operatorNorm() const;
+
+/////////// SVD module ///////////
+
+ inline JacobiSVD<PlainObject> jacobiSvd(unsigned int computationOptions = 0) const;
+ inline BDCSVD<PlainObject> bdcSvd(unsigned int computationOptions = 0) const;
+
+/////////// Geometry module ///////////
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ /// \internal helper struct to form the return type of the cross product
+ template<typename OtherDerived> struct cross_product_return_type {
+ typedef typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType Scalar;
+ typedef Matrix<Scalar,MatrixBase::RowsAtCompileTime,MatrixBase::ColsAtCompileTime> type;
+ };
+ #endif // EIGEN_PARSED_BY_DOXYGEN
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ inline typename cross_product_return_type<OtherDerived>::type
+#else
+ inline PlainObject
+#endif
+ cross(const MatrixBase<OtherDerived>& other) const;
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ inline PlainObject cross3(const MatrixBase<OtherDerived>& other) const;
+
+ EIGEN_DEVICE_FUNC
+ inline PlainObject unitOrthogonal(void) const;
+
+ EIGEN_DEVICE_FUNC
+ inline Matrix<Scalar,3,1> eulerAngles(Index a0, Index a1, Index a2) const;
+
+ // put this as separate enum value to work around possible GCC 4.3 bug (?)
+ enum { HomogeneousReturnTypeDirection = ColsAtCompileTime==1&&RowsAtCompileTime==1 ? ((internal::traits<Derived>::Flags&RowMajorBit)==RowMajorBit ? Horizontal : Vertical)
+ : ColsAtCompileTime==1 ? Vertical : Horizontal };
+ typedef Homogeneous<Derived, HomogeneousReturnTypeDirection> HomogeneousReturnType;
+ EIGEN_DEVICE_FUNC
+ inline HomogeneousReturnType homogeneous() const;
+
+ enum {
+ SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1
+ };
+ typedef Block<const Derived,
+ internal::traits<Derived>::ColsAtCompileTime==1 ? SizeMinusOne : 1,
+ internal::traits<Derived>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> ConstStartMinusOne;
+ typedef EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(ConstStartMinusOne,Scalar,quotient) HNormalizedReturnType;
+ EIGEN_DEVICE_FUNC
+ inline const HNormalizedReturnType hnormalized() const;
+
+////////// Householder module ///////////
+
+ EIGEN_DEVICE_FUNC
+ void makeHouseholderInPlace(Scalar& tau, RealScalar& beta);
+ template<typename EssentialPart>
+ EIGEN_DEVICE_FUNC
+ void makeHouseholder(EssentialPart& essential,
+ Scalar& tau, RealScalar& beta) const;
+ template<typename EssentialPart>
+ EIGEN_DEVICE_FUNC
+ void applyHouseholderOnTheLeft(const EssentialPart& essential,
+ const Scalar& tau,
+ Scalar* workspace);
+ template<typename EssentialPart>
+ EIGEN_DEVICE_FUNC
+ void applyHouseholderOnTheRight(const EssentialPart& essential,
+ const Scalar& tau,
+ Scalar* workspace);
+
+///////// Jacobi module /////////
+
+ template<typename OtherScalar>
+ EIGEN_DEVICE_FUNC
+ void applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j);
+ template<typename OtherScalar>
+ EIGEN_DEVICE_FUNC
+ void applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j);
+
+///////// SparseCore module /////////
+
+ template<typename OtherDerived>
+ EIGEN_STRONG_INLINE const typename SparseMatrixBase<OtherDerived>::template CwiseProductDenseReturnType<Derived>::Type
+ cwiseProduct(const SparseMatrixBase<OtherDerived> &other) const
+ {
+ return other.cwiseProduct(derived());
+ }
+
+///////// MatrixFunctions module /////////
+
+ typedef typename internal::stem_function<Scalar>::type StemFunction;
+#define EIGEN_MATRIX_FUNCTION(ReturnType, Name, Description) \
+ /** \returns an expression of the matrix Description of \c *this. \brief This function requires the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>. To compute the coefficient-wise Description use ArrayBase::##Name . */ \
+ const ReturnType<Derived> Name() const;
+#define EIGEN_MATRIX_FUNCTION_1(ReturnType, Name, Description, Argument) \
+ /** \returns an expression of the matrix Description of \c *this. \brief This function requires the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>. To compute the coefficient-wise Description use ArrayBase::##Name . */ \
+ const ReturnType<Derived> Name(Argument) const;
+
+ EIGEN_MATRIX_FUNCTION(MatrixExponentialReturnValue, exp, exponential)
+ /** \brief Helper function for the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>.*/
+ const MatrixFunctionReturnValue<Derived> matrixFunction(StemFunction f) const;
+ EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cosh, hyperbolic cosine)
+ EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sinh, hyperbolic sine)
+#if EIGEN_HAS_CXX11_MATH
+ EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, atanh, inverse hyperbolic cosine)
+ EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, acosh, inverse hyperbolic cosine)
+ EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, asinh, inverse hyperbolic sine)
+#endif
+ EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cos, cosine)
+ EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sin, sine)
+ EIGEN_MATRIX_FUNCTION(MatrixSquareRootReturnValue, sqrt, square root)
+ EIGEN_MATRIX_FUNCTION(MatrixLogarithmReturnValue, log, logarithm)
+ EIGEN_MATRIX_FUNCTION_1(MatrixPowerReturnValue, pow, power to \c p, const RealScalar& p)
+ EIGEN_MATRIX_FUNCTION_1(MatrixComplexPowerReturnValue, pow, power to \c p, const std::complex<RealScalar>& p)
+
+ protected:
+ EIGEN_DEFAULT_COPY_CONSTRUCTOR(MatrixBase)
+ EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MatrixBase)
+
+ private:
+ EIGEN_DEVICE_FUNC explicit MatrixBase(int);
+ EIGEN_DEVICE_FUNC MatrixBase(int,int);
+ template<typename OtherDerived> EIGEN_DEVICE_FUNC explicit MatrixBase(const MatrixBase<OtherDerived>&);
+ protected:
+ // mixing arrays and matrices is not legal
+ template<typename OtherDerived> Derived& operator+=(const ArrayBase<OtherDerived>& )
+ {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
+ // mixing arrays and matrices is not legal
+ template<typename OtherDerived> Derived& operator-=(const ArrayBase<OtherDerived>& )
+ {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
+};
+
+
+/***************************************************************************
+* Implementation of matrix base methods
+***************************************************************************/
+
+/** replaces \c *this by \c *this * \a other.
+ *
+ * \returns a reference to \c *this
+ *
+ * Example: \include MatrixBase_applyOnTheRight.cpp
+ * Output: \verbinclude MatrixBase_applyOnTheRight.out
+ */
+template<typename Derived>
+template<typename OtherDerived>
+inline Derived&
+MatrixBase<Derived>::operator*=(const EigenBase<OtherDerived> &other)
+{
+ other.derived().applyThisOnTheRight(derived());
+ return derived();
+}
+
+/** replaces \c *this by \c *this * \a other. It is equivalent to MatrixBase::operator*=().
+ *
+ * Example: \include MatrixBase_applyOnTheRight.cpp
+ * Output: \verbinclude MatrixBase_applyOnTheRight.out
+ */
+template<typename Derived>
+template<typename OtherDerived>
+inline void MatrixBase<Derived>::applyOnTheRight(const EigenBase<OtherDerived> &other)
+{
+ other.derived().applyThisOnTheRight(derived());
+}
+
+/** replaces \c *this by \a other * \c *this.
+ *
+ * Example: \include MatrixBase_applyOnTheLeft.cpp
+ * Output: \verbinclude MatrixBase_applyOnTheLeft.out
+ */
+template<typename Derived>
+template<typename OtherDerived>
+inline void MatrixBase<Derived>::applyOnTheLeft(const EigenBase<OtherDerived> &other)
+{
+ other.derived().applyThisOnTheLeft(derived());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATRIXBASE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/NestByValue.h b/src/3rdparty/eigen/Eigen/src/Core/NestByValue.h
new file mode 100644
index 000000000..b4275768a
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/NestByValue.h
@@ -0,0 +1,85 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_NESTBYVALUE_H
+#define EIGEN_NESTBYVALUE_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename ExpressionType>
+struct traits<NestByValue<ExpressionType> > : public traits<ExpressionType>
+{
+ enum {
+ Flags = traits<ExpressionType>::Flags & ~NestByRefBit
+ };
+};
+}
+
+/** \class NestByValue
+ * \ingroup Core_Module
+ *
+ * \brief Expression which must be nested by value
+ *
+ * \tparam ExpressionType the type of the object of which we are requiring nesting-by-value
+ *
+ * This class is the return type of MatrixBase::nestByValue()
+ * and most of the time this is the only way it is used.
+ *
+ * \sa MatrixBase::nestByValue()
+ */
+template<typename ExpressionType> class NestByValue
+ : public internal::dense_xpr_base< NestByValue<ExpressionType> >::type
+{
+ public:
+
+ typedef typename internal::dense_xpr_base<NestByValue>::type Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(NestByValue)
+
+ EIGEN_DEVICE_FUNC explicit inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
+
+ EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; }
+
+ EIGEN_DEVICE_FUNC const ExpressionType& nestedExpression() const { return m_expression; }
+
+ protected:
+ const ExpressionType m_expression;
+};
+
+/** \returns an expression of the temporary version of *this.
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline const NestByValue<Derived>
+DenseBase<Derived>::nestByValue() const
+{
+ return NestByValue<Derived>(derived());
+}
+
+namespace internal {
+
+// Evaluator of Solve -> eval into a temporary
+template<typename ArgType>
+struct evaluator<NestByValue<ArgType> >
+ : public evaluator<ArgType>
+{
+ typedef evaluator<ArgType> Base;
+
+ EIGEN_DEVICE_FUNC explicit evaluator(const NestByValue<ArgType>& xpr)
+ : Base(xpr.nestedExpression())
+ {}
+};
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_NESTBYVALUE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/NoAlias.h b/src/3rdparty/eigen/Eigen/src/Core/NoAlias.h
new file mode 100644
index 000000000..570283d90
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/NoAlias.h
@@ -0,0 +1,109 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_NOALIAS_H
+#define EIGEN_NOALIAS_H
+
+namespace Eigen {
+
+/** \class NoAlias
+ * \ingroup Core_Module
+ *
+ * \brief Pseudo expression providing an operator = assuming no aliasing
+ *
+ * \tparam ExpressionType the type of the object on which to do the lazy assignment
+ *
+ * This class represents an expression with special assignment operators
+ * assuming no aliasing between the target expression and the source expression.
+ * More precisely it alloas to bypass the EvalBeforeAssignBit flag of the source expression.
+ * It is the return type of MatrixBase::noalias()
+ * and most of the time this is the only way it is used.
+ *
+ * \sa MatrixBase::noalias()
+ */
+template<typename ExpressionType, template <typename> class StorageBase>
+class NoAlias
+{
+ public:
+ typedef typename ExpressionType::Scalar Scalar;
+
+ EIGEN_DEVICE_FUNC
+ explicit NoAlias(ExpressionType& expression) : m_expression(expression) {}
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase<OtherDerived>& other)
+ {
+ call_assignment_no_alias(m_expression, other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>());
+ return m_expression;
+ }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase<OtherDerived>& other)
+ {
+ call_assignment_no_alias(m_expression, other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
+ return m_expression;
+ }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase<OtherDerived>& other)
+ {
+ call_assignment_no_alias(m_expression, other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
+ return m_expression;
+ }
+
+ EIGEN_DEVICE_FUNC
+ ExpressionType& expression() const
+ {
+ return m_expression;
+ }
+
+ protected:
+ ExpressionType& m_expression;
+};
+
+/** \returns a pseudo expression of \c *this with an operator= assuming
+ * no aliasing between \c *this and the source expression.
+ *
+ * More precisely, noalias() allows to bypass the EvalBeforeAssignBit flag.
+ * Currently, even though several expressions may alias, only product
+ * expressions have this flag. Therefore, noalias() is only useful when
+ * the source expression contains a matrix product.
+ *
+ * Here are some examples where noalias is useful:
+ * \code
+ * D.noalias() = A * B;
+ * D.noalias() += A.transpose() * B;
+ * D.noalias() -= 2 * A * B.adjoint();
+ * \endcode
+ *
+ * On the other hand the following example will lead to a \b wrong result:
+ * \code
+ * A.noalias() = A * B;
+ * \endcode
+ * because the result matrix A is also an operand of the matrix product. Therefore,
+ * there is no alternative than evaluating A * B in a temporary, that is the default
+ * behavior when you write:
+ * \code
+ * A = A * B;
+ * \endcode
+ *
+ * \sa class NoAlias
+ */
+template<typename Derived>
+NoAlias<Derived,MatrixBase> EIGEN_DEVICE_FUNC MatrixBase<Derived>::noalias()
+{
+ return NoAlias<Derived, Eigen::MatrixBase >(derived());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_NOALIAS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/NumTraits.h b/src/3rdparty/eigen/Eigen/src/Core/NumTraits.h
new file mode 100644
index 000000000..72eac5a93
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/NumTraits.h
@@ -0,0 +1,335 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_NUMTRAITS_H
+#define EIGEN_NUMTRAITS_H
+
+namespace Eigen {
+
+namespace internal {
+
+// default implementation of digits10(), based on numeric_limits if specialized,
+// 0 for integer types, and log10(epsilon()) otherwise.
+template< typename T,
+ bool use_numeric_limits = std::numeric_limits<T>::is_specialized,
+ bool is_integer = NumTraits<T>::IsInteger>
+struct default_digits10_impl
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static int run() { return std::numeric_limits<T>::digits10; }
+};
+
+template<typename T>
+struct default_digits10_impl<T,false,false> // Floating point
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static int run() {
+ using std::log10;
+ using std::ceil;
+ typedef typename NumTraits<T>::Real Real;
+ return int(ceil(-log10(NumTraits<Real>::epsilon())));
+ }
+};
+
+template<typename T>
+struct default_digits10_impl<T,false,true> // Integer
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static int run() { return 0; }
+};
+
+
+// default implementation of digits(), based on numeric_limits if specialized,
+// 0 for integer types, and log2(epsilon()) otherwise.
+template< typename T,
+ bool use_numeric_limits = std::numeric_limits<T>::is_specialized,
+ bool is_integer = NumTraits<T>::IsInteger>
+struct default_digits_impl
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static int run() { return std::numeric_limits<T>::digits; }
+};
+
+template<typename T>
+struct default_digits_impl<T,false,false> // Floating point
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static int run() {
+ using std::log;
+ using std::ceil;
+ typedef typename NumTraits<T>::Real Real;
+ return int(ceil(-log(NumTraits<Real>::epsilon())/log(static_cast<Real>(2))));
+ }
+};
+
+template<typename T>
+struct default_digits_impl<T,false,true> // Integer
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static int run() { return 0; }
+};
+
+} // end namespace internal
+
+namespace numext {
+/** \internal bit-wise cast without changing the underlying bit representation. */
+
+// TODO: Replace by std::bit_cast (available in C++20)
+template <typename Tgt, typename Src>
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Tgt bit_cast(const Src& src) {
+#if EIGEN_HAS_TYPE_TRAITS
+ // The behaviour of memcpy is not specified for non-trivially copyable types
+ EIGEN_STATIC_ASSERT(std::is_trivially_copyable<Src>::value, THIS_TYPE_IS_NOT_SUPPORTED);
+ EIGEN_STATIC_ASSERT(std::is_trivially_copyable<Tgt>::value && std::is_default_constructible<Tgt>::value,
+ THIS_TYPE_IS_NOT_SUPPORTED);
+#endif
+
+ EIGEN_STATIC_ASSERT(sizeof(Src) == sizeof(Tgt), THIS_TYPE_IS_NOT_SUPPORTED);
+ Tgt tgt;
+ EIGEN_USING_STD(memcpy)
+ memcpy(&tgt, &src, sizeof(Tgt));
+ return tgt;
+}
+} // namespace numext
+
+/** \class NumTraits
+ * \ingroup Core_Module
+ *
+ * \brief Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
+ *
+ * \tparam T the numeric type at hand
+ *
+ * This class stores enums, typedefs and static methods giving information about a numeric type.
+ *
+ * The provided data consists of:
+ * \li A typedef \c Real, giving the "real part" type of \a T. If \a T is already real,
+ * then \c Real is just a typedef to \a T. If \a T is \c std::complex<U> then \c Real
+ * is a typedef to \a U.
+ * \li A typedef \c NonInteger, giving the type that should be used for operations producing non-integral values,
+ * such as quotients, square roots, etc. If \a T is a floating-point type, then this typedef just gives
+ * \a T again. Note however that many Eigen functions such as internal::sqrt simply refuse to
+ * take integers. Outside of a few cases, Eigen doesn't do automatic type promotion. Thus, this typedef is
+ * only intended as a helper for code that needs to explicitly promote types.
+ * \li A typedef \c Literal giving the type to use for numeric literals such as "2" or "0.5". For instance, for \c std::complex<U>, Literal is defined as \c U.
+ * Of course, this type must be fully compatible with \a T. In doubt, just use \a T here.
+ * \li A typedef \a Nested giving the type to use to nest a value inside of the expression tree. If you don't know what
+ * this means, just use \a T here.
+ * \li An enum value \a IsComplex. It is equal to 1 if \a T is a \c std::complex
+ * type, and to 0 otherwise.
+ * \li An enum value \a IsInteger. It is equal to \c 1 if \a T is an integer type such as \c int,
+ * and to \c 0 otherwise.
+ * \li Enum values ReadCost, AddCost and MulCost representing a rough estimate of the number of CPU cycles needed
+ * to by move / add / mul instructions respectively, assuming the data is already stored in CPU registers.
+ * Stay vague here. No need to do architecture-specific stuff. If you don't know what this means, just use \c Eigen::HugeCost.
+ * \li An enum value \a IsSigned. It is equal to \c 1 if \a T is a signed type and to 0 if \a T is unsigned.
+ * \li An enum value \a RequireInitialization. It is equal to \c 1 if the constructor of the numeric type \a T must
+ * be called, and to 0 if it is safe not to call it. Default is 0 if \a T is an arithmetic type, and 1 otherwise.
+ * \li An epsilon() function which, unlike <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/epsilon">std::numeric_limits::epsilon()</a>,
+ * it returns a \a Real instead of a \a T.
+ * \li A dummy_precision() function returning a weak epsilon value. It is mainly used as a default
+ * value by the fuzzy comparison operators.
+ * \li highest() and lowest() functions returning the highest and lowest possible values respectively.
+ * \li digits() function returning the number of radix digits (non-sign digits for integers, mantissa for floating-point). This is
+ * the analogue of <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/digits">std::numeric_limits<T>::digits</a>
+ * which is used as the default implementation if specialized.
+ * \li digits10() function returning the number of decimal digits that can be represented without change. This is
+ * the analogue of <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/digits10">std::numeric_limits<T>::digits10</a>
+ * which is used as the default implementation if specialized.
+ * \li min_exponent() and max_exponent() functions returning the highest and lowest possible values, respectively,
+ * such that the radix raised to the power exponent-1 is a normalized floating-point number. These are equivalent to
+ * <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/min_exponent">std::numeric_limits<T>::min_exponent</a>/
+ * <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/max_exponent">std::numeric_limits<T>::max_exponent</a>.
+ * \li infinity() function returning a representation of positive infinity, if available.
+ * \li quiet_NaN function returning a non-signaling "not-a-number", if available.
+ */
+
+template<typename T> struct GenericNumTraits
+{
+ enum {
+ IsInteger = std::numeric_limits<T>::is_integer,
+ IsSigned = std::numeric_limits<T>::is_signed,
+ IsComplex = 0,
+ RequireInitialization = internal::is_arithmetic<T>::value ? 0 : 1,
+ ReadCost = 1,
+ AddCost = 1,
+ MulCost = 1
+ };
+
+ typedef T Real;
+ typedef typename internal::conditional<
+ IsInteger,
+ typename internal::conditional<sizeof(T)<=2, float, double>::type,
+ T
+ >::type NonInteger;
+ typedef T Nested;
+ typedef T Literal;
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline Real epsilon()
+ {
+ return numext::numeric_limits<T>::epsilon();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline int digits10()
+ {
+ return internal::default_digits10_impl<T>::run();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline int digits()
+ {
+ return internal::default_digits_impl<T>::run();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline int min_exponent()
+ {
+ return numext::numeric_limits<T>::min_exponent;
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline int max_exponent()
+ {
+ return numext::numeric_limits<T>::max_exponent;
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline Real dummy_precision()
+ {
+ // make sure to override this for floating-point types
+ return Real(0);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline T highest() {
+ return (numext::numeric_limits<T>::max)();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline T lowest() {
+ return IsInteger ? (numext::numeric_limits<T>::min)()
+ : static_cast<T>(-(numext::numeric_limits<T>::max)());
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline T infinity() {
+ return numext::numeric_limits<T>::infinity();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline T quiet_NaN() {
+ return numext::numeric_limits<T>::quiet_NaN();
+ }
+};
+
+template<typename T> struct NumTraits : GenericNumTraits<T>
+{};
+
+template<> struct NumTraits<float>
+ : GenericNumTraits<float>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline float dummy_precision() { return 1e-5f; }
+};
+
+template<> struct NumTraits<double> : GenericNumTraits<double>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline double dummy_precision() { return 1e-12; }
+};
+
+template<> struct NumTraits<long double>
+ : GenericNumTraits<long double>
+{
+ EIGEN_CONSTEXPR
+ static inline long double dummy_precision() { return 1e-15l; }
+};
+
+template<typename _Real> struct NumTraits<std::complex<_Real> >
+ : GenericNumTraits<std::complex<_Real> >
+{
+ typedef _Real Real;
+ typedef typename NumTraits<_Real>::Literal Literal;
+ enum {
+ IsComplex = 1,
+ RequireInitialization = NumTraits<_Real>::RequireInitialization,
+ ReadCost = 2 * NumTraits<_Real>::ReadCost,
+ AddCost = 2 * NumTraits<Real>::AddCost,
+ MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::AddCost
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline Real epsilon() { return NumTraits<Real>::epsilon(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline Real dummy_precision() { return NumTraits<Real>::dummy_precision(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline int digits10() { return NumTraits<Real>::digits10(); }
+};
+
+template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
+struct NumTraits<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
+{
+ typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> ArrayType;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef Array<RealScalar, Rows, Cols, Options, MaxRows, MaxCols> Real;
+ typedef typename NumTraits<Scalar>::NonInteger NonIntegerScalar;
+ typedef Array<NonIntegerScalar, Rows, Cols, Options, MaxRows, MaxCols> NonInteger;
+ typedef ArrayType & Nested;
+ typedef typename NumTraits<Scalar>::Literal Literal;
+
+ enum {
+ IsComplex = NumTraits<Scalar>::IsComplex,
+ IsInteger = NumTraits<Scalar>::IsInteger,
+ IsSigned = NumTraits<Scalar>::IsSigned,
+ RequireInitialization = 1,
+ ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * int(NumTraits<Scalar>::ReadCost),
+ AddCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * int(NumTraits<Scalar>::AddCost),
+ MulCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * int(NumTraits<Scalar>::MulCost)
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline RealScalar epsilon() { return NumTraits<RealScalar>::epsilon(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static inline RealScalar dummy_precision() { return NumTraits<RealScalar>::dummy_precision(); }
+
+ EIGEN_CONSTEXPR
+ static inline int digits10() { return NumTraits<Scalar>::digits10(); }
+};
+
+template<> struct NumTraits<std::string>
+ : GenericNumTraits<std::string>
+{
+ enum {
+ RequireInitialization = 1,
+ ReadCost = HugeCost,
+ AddCost = HugeCost,
+ MulCost = HugeCost
+ };
+
+ EIGEN_CONSTEXPR
+ static inline int digits10() { return 0; }
+
+private:
+ static inline std::string epsilon();
+ static inline std::string dummy_precision();
+ static inline std::string lowest();
+ static inline std::string highest();
+ static inline std::string infinity();
+ static inline std::string quiet_NaN();
+};
+
+// Empty specialization for void to allow template specialization based on NumTraits<T>::Real with T==void and SFINAE.
+template<> struct NumTraits<void> {};
+
+template<> struct NumTraits<bool> : GenericNumTraits<bool> {};
+
+} // end namespace Eigen
+
+#endif // EIGEN_NUMTRAITS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/PartialReduxEvaluator.h b/src/3rdparty/eigen/Eigen/src/Core/PartialReduxEvaluator.h
new file mode 100644
index 000000000..29abf35b9
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/PartialReduxEvaluator.h
@@ -0,0 +1,232 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2011-2018 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PARTIALREDUX_H
+#define EIGEN_PARTIALREDUX_H
+
+namespace Eigen {
+
+namespace internal {
+
+
+/***************************************************************************
+*
+* This file provides evaluators for partial reductions.
+* There are two modes:
+*
+* - scalar path: simply calls the respective function on the column or row.
+* -> nothing special here, all the tricky part is handled by the return
+* types of VectorwiseOp's members. They embed the functor calling the
+* respective DenseBase's member function.
+*
+* - vectorized path: implements a packet-wise reductions followed by
+* some (optional) processing of the outcome, e.g., division by n for mean.
+*
+* For the vectorized path let's observe that the packet-size and outer-unrolling
+* are both decided by the assignement logic. So all we have to do is to decide
+* on the inner unrolling.
+*
+* For the unrolling, we can reuse "internal::redux_vec_unroller" from Redux.h,
+* but be need to be careful to specify correct increment.
+*
+***************************************************************************/
+
+
+/* logic deciding a strategy for unrolling of vectorized paths */
+template<typename Func, typename Evaluator>
+struct packetwise_redux_traits
+{
+ enum {
+ OuterSize = int(Evaluator::IsRowMajor) ? Evaluator::RowsAtCompileTime : Evaluator::ColsAtCompileTime,
+ Cost = OuterSize == Dynamic ? HugeCost
+ : OuterSize * Evaluator::CoeffReadCost + (OuterSize-1) * functor_traits<Func>::Cost,
+ Unrolling = Cost <= EIGEN_UNROLLING_LIMIT ? CompleteUnrolling : NoUnrolling
+ };
+
+};
+
+/* Value to be returned when size==0 , by default let's return 0 */
+template<typename PacketType,typename Func>
+EIGEN_DEVICE_FUNC
+PacketType packetwise_redux_empty_value(const Func& ) { return pset1<PacketType>(0); }
+
+/* For products the default is 1 */
+template<typename PacketType,typename Scalar>
+EIGEN_DEVICE_FUNC
+PacketType packetwise_redux_empty_value(const scalar_product_op<Scalar,Scalar>& ) { return pset1<PacketType>(1); }
+
+/* Perform the actual reduction */
+template<typename Func, typename Evaluator,
+ int Unrolling = packetwise_redux_traits<Func, Evaluator>::Unrolling
+>
+struct packetwise_redux_impl;
+
+/* Perform the actual reduction with unrolling */
+template<typename Func, typename Evaluator>
+struct packetwise_redux_impl<Func, Evaluator, CompleteUnrolling>
+{
+ typedef redux_novec_unroller<Func,Evaluator, 0, Evaluator::SizeAtCompileTime> Base;
+ typedef typename Evaluator::Scalar Scalar;
+
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE
+ PacketType run(const Evaluator &eval, const Func& func, Index /*size*/)
+ {
+ return redux_vec_unroller<Func, Evaluator, 0, packetwise_redux_traits<Func, Evaluator>::OuterSize>::template run<PacketType>(eval,func);
+ }
+};
+
+/* Add a specialization of redux_vec_unroller for size==0 at compiletime.
+ * This specialization is not required for general reductions, which is
+ * why it is defined here.
+ */
+template<typename Func, typename Evaluator, int Start>
+struct redux_vec_unroller<Func, Evaluator, Start, 0>
+{
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE PacketType run(const Evaluator &, const Func& f)
+ {
+ return packetwise_redux_empty_value<PacketType>(f);
+ }
+};
+
+/* Perform the actual reduction for dynamic sizes */
+template<typename Func, typename Evaluator>
+struct packetwise_redux_impl<Func, Evaluator, NoUnrolling>
+{
+ typedef typename Evaluator::Scalar Scalar;
+ typedef typename redux_traits<Func, Evaluator>::PacketType PacketScalar;
+
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC
+ static PacketType run(const Evaluator &eval, const Func& func, Index size)
+ {
+ if(size==0)
+ return packetwise_redux_empty_value<PacketType>(func);
+
+ const Index size4 = (size-1)&(~3);
+ PacketType p = eval.template packetByOuterInner<Unaligned,PacketType>(0,0);
+ Index i = 1;
+ // This loop is optimized for instruction pipelining:
+ // - each iteration generates two independent instructions
+ // - thanks to branch prediction and out-of-order execution we have independent instructions across loops
+ for(; i<size4; i+=4)
+ p = func.packetOp(p,
+ func.packetOp(
+ func.packetOp(eval.template packetByOuterInner<Unaligned,PacketType>(i+0,0),eval.template packetByOuterInner<Unaligned,PacketType>(i+1,0)),
+ func.packetOp(eval.template packetByOuterInner<Unaligned,PacketType>(i+2,0),eval.template packetByOuterInner<Unaligned,PacketType>(i+3,0))));
+ for(; i<size; ++i)
+ p = func.packetOp(p, eval.template packetByOuterInner<Unaligned,PacketType>(i,0));
+ return p;
+ }
+};
+
+template< typename ArgType, typename MemberOp, int Direction>
+struct evaluator<PartialReduxExpr<ArgType, MemberOp, Direction> >
+ : evaluator_base<PartialReduxExpr<ArgType, MemberOp, Direction> >
+{
+ typedef PartialReduxExpr<ArgType, MemberOp, Direction> XprType;
+ typedef typename internal::nested_eval<ArgType,1>::type ArgTypeNested;
+ typedef typename internal::add_const_on_value_type<ArgTypeNested>::type ConstArgTypeNested;
+ typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
+ typedef typename ArgType::Scalar InputScalar;
+ typedef typename XprType::Scalar Scalar;
+ enum {
+ TraversalSize = Direction==int(Vertical) ? int(ArgType::RowsAtCompileTime) : int(ArgType::ColsAtCompileTime)
+ };
+ typedef typename MemberOp::template Cost<int(TraversalSize)> CostOpType;
+ enum {
+ CoeffReadCost = TraversalSize==Dynamic ? HugeCost
+ : TraversalSize==0 ? 1
+ : int(TraversalSize) * int(evaluator<ArgType>::CoeffReadCost) + int(CostOpType::value),
+
+ _ArgFlags = evaluator<ArgType>::Flags,
+
+ _Vectorizable = bool(int(_ArgFlags)&PacketAccessBit)
+ && bool(MemberOp::Vectorizable)
+ && (Direction==int(Vertical) ? bool(_ArgFlags&RowMajorBit) : (_ArgFlags&RowMajorBit)==0)
+ && (TraversalSize!=0),
+
+ Flags = (traits<XprType>::Flags&RowMajorBit)
+ | (evaluator<ArgType>::Flags&(HereditaryBits&(~RowMajorBit)))
+ | (_Vectorizable ? PacketAccessBit : 0)
+ | LinearAccessBit,
+
+ Alignment = 0 // FIXME this will need to be improved once PartialReduxExpr is vectorized
+ };
+
+ EIGEN_DEVICE_FUNC explicit evaluator(const XprType xpr)
+ : m_arg(xpr.nestedExpression()), m_functor(xpr.functor())
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(TraversalSize==Dynamic ? HugeCost : (TraversalSize==0 ? 1 : int(CostOpType::value)));
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const Scalar coeff(Index i, Index j) const
+ {
+ return coeff(Direction==Vertical ? j : i);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const Scalar coeff(Index index) const
+ {
+ return m_functor(m_arg.template subVector<DirectionType(Direction)>(index));
+ }
+
+ template<int LoadMode,typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ PacketType packet(Index i, Index j) const
+ {
+ return packet<LoadMode,PacketType>(Direction==Vertical ? j : i);
+ }
+
+ template<int LoadMode,typename PacketType>
+ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+ PacketType packet(Index idx) const
+ {
+ enum { PacketSize = internal::unpacket_traits<PacketType>::size };
+ typedef Block<const ArgTypeNestedCleaned,
+ Direction==Vertical ? int(ArgType::RowsAtCompileTime) : int(PacketSize),
+ Direction==Vertical ? int(PacketSize) : int(ArgType::ColsAtCompileTime),
+ true /* InnerPanel */> PanelType;
+
+ PanelType panel(m_arg,
+ Direction==Vertical ? 0 : idx,
+ Direction==Vertical ? idx : 0,
+ Direction==Vertical ? m_arg.rows() : Index(PacketSize),
+ Direction==Vertical ? Index(PacketSize) : m_arg.cols());
+
+ // FIXME
+ // See bug 1612, currently if PacketSize==1 (i.e. complex<double> with 128bits registers) then the storage-order of panel get reversed
+ // and methods like packetByOuterInner do not make sense anymore in this context.
+ // So let's just by pass "vectorization" in this case:
+ if(PacketSize==1)
+ return internal::pset1<PacketType>(coeff(idx));
+
+ typedef typename internal::redux_evaluator<PanelType> PanelEvaluator;
+ PanelEvaluator panel_eval(panel);
+ typedef typename MemberOp::BinaryOp BinaryOp;
+ PacketType p = internal::packetwise_redux_impl<BinaryOp,PanelEvaluator>::template run<PacketType>(panel_eval,m_functor.binaryFunc(),m_arg.outerSize());
+ return p;
+ }
+
+protected:
+ ConstArgTypeNested m_arg;
+ const MemberOp m_functor;
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PARTIALREDUX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/PermutationMatrix.h b/src/3rdparty/eigen/Eigen/src/Core/PermutationMatrix.h
new file mode 100644
index 000000000..69401bf41
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/PermutationMatrix.h
@@ -0,0 +1,605 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2009-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PERMUTATIONMATRIX_H
+#define EIGEN_PERMUTATIONMATRIX_H
+
+namespace Eigen {
+
+namespace internal {
+
+enum PermPermProduct_t {PermPermProduct};
+
+} // end namespace internal
+
+/** \class PermutationBase
+ * \ingroup Core_Module
+ *
+ * \brief Base class for permutations
+ *
+ * \tparam Derived the derived class
+ *
+ * This class is the base class for all expressions representing a permutation matrix,
+ * internally stored as a vector of integers.
+ * The convention followed here is that if \f$ \sigma \f$ is a permutation, the corresponding permutation matrix
+ * \f$ P_\sigma \f$ is such that if \f$ (e_1,\ldots,e_p) \f$ is the canonical basis, we have:
+ * \f[ P_\sigma(e_i) = e_{\sigma(i)}. \f]
+ * This convention ensures that for any two permutations \f$ \sigma, \tau \f$, we have:
+ * \f[ P_{\sigma\circ\tau} = P_\sigma P_\tau. \f]
+ *
+ * Permutation matrices are square and invertible.
+ *
+ * Notice that in addition to the member functions and operators listed here, there also are non-member
+ * operator* to multiply any kind of permutation object with any kind of matrix expression (MatrixBase)
+ * on either side.
+ *
+ * \sa class PermutationMatrix, class PermutationWrapper
+ */
+template<typename Derived>
+class PermutationBase : public EigenBase<Derived>
+{
+ typedef internal::traits<Derived> Traits;
+ typedef EigenBase<Derived> Base;
+ public:
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ typedef typename Traits::IndicesType IndicesType;
+ enum {
+ Flags = Traits::Flags,
+ RowsAtCompileTime = Traits::RowsAtCompileTime,
+ ColsAtCompileTime = Traits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
+ };
+ typedef typename Traits::StorageIndex StorageIndex;
+ typedef Matrix<StorageIndex,RowsAtCompileTime,ColsAtCompileTime,0,MaxRowsAtCompileTime,MaxColsAtCompileTime>
+ DenseMatrixType;
+ typedef PermutationMatrix<IndicesType::SizeAtCompileTime,IndicesType::MaxSizeAtCompileTime,StorageIndex>
+ PlainPermutationType;
+ typedef PlainPermutationType PlainObject;
+ using Base::derived;
+ typedef Inverse<Derived> InverseReturnType;
+ typedef void Scalar;
+ #endif
+
+ /** Copies the other permutation into *this */
+ template<typename OtherDerived>
+ Derived& operator=(const PermutationBase<OtherDerived>& other)
+ {
+ indices() = other.indices();
+ return derived();
+ }
+
+ /** Assignment from the Transpositions \a tr */
+ template<typename OtherDerived>
+ Derived& operator=(const TranspositionsBase<OtherDerived>& tr)
+ {
+ setIdentity(tr.size());
+ for(Index k=size()-1; k>=0; --k)
+ applyTranspositionOnTheRight(k,tr.coeff(k));
+ return derived();
+ }
+
+ /** \returns the number of rows */
+ inline EIGEN_DEVICE_FUNC Index rows() const { return Index(indices().size()); }
+
+ /** \returns the number of columns */
+ inline EIGEN_DEVICE_FUNC Index cols() const { return Index(indices().size()); }
+
+ /** \returns the size of a side of the respective square matrix, i.e., the number of indices */
+ inline EIGEN_DEVICE_FUNC Index size() const { return Index(indices().size()); }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename DenseDerived>
+ void evalTo(MatrixBase<DenseDerived>& other) const
+ {
+ other.setZero();
+ for (Index i=0; i<rows(); ++i)
+ other.coeffRef(indices().coeff(i),i) = typename DenseDerived::Scalar(1);
+ }
+ #endif
+
+ /** \returns a Matrix object initialized from this permutation matrix. Notice that it
+ * is inefficient to return this Matrix object by value. For efficiency, favor using
+ * the Matrix constructor taking EigenBase objects.
+ */
+ DenseMatrixType toDenseMatrix() const
+ {
+ return derived();
+ }
+
+ /** const version of indices(). */
+ const IndicesType& indices() const { return derived().indices(); }
+ /** \returns a reference to the stored array representing the permutation. */
+ IndicesType& indices() { return derived().indices(); }
+
+ /** Resizes to given size.
+ */
+ inline void resize(Index newSize)
+ {
+ indices().resize(newSize);
+ }
+
+ /** Sets *this to be the identity permutation matrix */
+ void setIdentity()
+ {
+ StorageIndex n = StorageIndex(size());
+ for(StorageIndex i = 0; i < n; ++i)
+ indices().coeffRef(i) = i;
+ }
+
+ /** Sets *this to be the identity permutation matrix of given size.
+ */
+ void setIdentity(Index newSize)
+ {
+ resize(newSize);
+ setIdentity();
+ }
+
+ /** Multiplies *this by the transposition \f$(ij)\f$ on the left.
+ *
+ * \returns a reference to *this.
+ *
+ * \warning This is much slower than applyTranspositionOnTheRight(Index,Index):
+ * this has linear complexity and requires a lot of branching.
+ *
+ * \sa applyTranspositionOnTheRight(Index,Index)
+ */
+ Derived& applyTranspositionOnTheLeft(Index i, Index j)
+ {
+ eigen_assert(i>=0 && j>=0 && i<size() && j<size());
+ for(Index k = 0; k < size(); ++k)
+ {
+ if(indices().coeff(k) == i) indices().coeffRef(k) = StorageIndex(j);
+ else if(indices().coeff(k) == j) indices().coeffRef(k) = StorageIndex(i);
+ }
+ return derived();
+ }
+
+ /** Multiplies *this by the transposition \f$(ij)\f$ on the right.
+ *
+ * \returns a reference to *this.
+ *
+ * This is a fast operation, it only consists in swapping two indices.
+ *
+ * \sa applyTranspositionOnTheLeft(Index,Index)
+ */
+ Derived& applyTranspositionOnTheRight(Index i, Index j)
+ {
+ eigen_assert(i>=0 && j>=0 && i<size() && j<size());
+ std::swap(indices().coeffRef(i), indices().coeffRef(j));
+ return derived();
+ }
+
+ /** \returns the inverse permutation matrix.
+ *
+ * \note \blank \note_try_to_help_rvo
+ */
+ inline InverseReturnType inverse() const
+ { return InverseReturnType(derived()); }
+ /** \returns the tranpose permutation matrix.
+ *
+ * \note \blank \note_try_to_help_rvo
+ */
+ inline InverseReturnType transpose() const
+ { return InverseReturnType(derived()); }
+
+ /**** multiplication helpers to hopefully get RVO ****/
+
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ protected:
+ template<typename OtherDerived>
+ void assignTranspose(const PermutationBase<OtherDerived>& other)
+ {
+ for (Index i=0; i<rows();++i) indices().coeffRef(other.indices().coeff(i)) = i;
+ }
+ template<typename Lhs,typename Rhs>
+ void assignProduct(const Lhs& lhs, const Rhs& rhs)
+ {
+ eigen_assert(lhs.cols() == rhs.rows());
+ for (Index i=0; i<rows();++i) indices().coeffRef(i) = lhs.indices().coeff(rhs.indices().coeff(i));
+ }
+#endif
+
+ public:
+
+ /** \returns the product permutation matrix.
+ *
+ * \note \blank \note_try_to_help_rvo
+ */
+ template<typename Other>
+ inline PlainPermutationType operator*(const PermutationBase<Other>& other) const
+ { return PlainPermutationType(internal::PermPermProduct, derived(), other.derived()); }
+
+ /** \returns the product of a permutation with another inverse permutation.
+ *
+ * \note \blank \note_try_to_help_rvo
+ */
+ template<typename Other>
+ inline PlainPermutationType operator*(const InverseImpl<Other,PermutationStorage>& other) const
+ { return PlainPermutationType(internal::PermPermProduct, *this, other.eval()); }
+
+ /** \returns the product of an inverse permutation with another permutation.
+ *
+ * \note \blank \note_try_to_help_rvo
+ */
+ template<typename Other> friend
+ inline PlainPermutationType operator*(const InverseImpl<Other, PermutationStorage>& other, const PermutationBase& perm)
+ { return PlainPermutationType(internal::PermPermProduct, other.eval(), perm); }
+
+ /** \returns the determinant of the permutation matrix, which is either 1 or -1 depending on the parity of the permutation.
+ *
+ * This function is O(\c n) procedure allocating a buffer of \c n booleans.
+ */
+ Index determinant() const
+ {
+ Index res = 1;
+ Index n = size();
+ Matrix<bool,RowsAtCompileTime,1,0,MaxRowsAtCompileTime> mask(n);
+ mask.fill(false);
+ Index r = 0;
+ while(r < n)
+ {
+ // search for the next seed
+ while(r<n && mask[r]) r++;
+ if(r>=n)
+ break;
+ // we got one, let's follow it until we are back to the seed
+ Index k0 = r++;
+ mask.coeffRef(k0) = true;
+ for(Index k=indices().coeff(k0); k!=k0; k=indices().coeff(k))
+ {
+ mask.coeffRef(k) = true;
+ res = -res;
+ }
+ }
+ return res;
+ }
+
+ protected:
+
+};
+
+namespace internal {
+template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
+struct traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex> >
+ : traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
+{
+ typedef PermutationStorage StorageKind;
+ typedef Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
+ typedef _StorageIndex StorageIndex;
+ typedef void Scalar;
+};
+}
+
+/** \class PermutationMatrix
+ * \ingroup Core_Module
+ *
+ * \brief Permutation matrix
+ *
+ * \tparam SizeAtCompileTime the number of rows/cols, or Dynamic
+ * \tparam MaxSizeAtCompileTime the maximum number of rows/cols, or Dynamic. This optional parameter defaults to SizeAtCompileTime. Most of the time, you should not have to specify it.
+ * \tparam _StorageIndex the integer type of the indices
+ *
+ * This class represents a permutation matrix, internally stored as a vector of integers.
+ *
+ * \sa class PermutationBase, class PermutationWrapper, class DiagonalMatrix
+ */
+template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
+class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex> >
+{
+ typedef PermutationBase<PermutationMatrix> Base;
+ typedef internal::traits<PermutationMatrix> Traits;
+ public:
+
+ typedef const PermutationMatrix& Nested;
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ typedef typename Traits::IndicesType IndicesType;
+ typedef typename Traits::StorageIndex StorageIndex;
+ #endif
+
+ inline PermutationMatrix()
+ {}
+
+ /** Constructs an uninitialized permutation matrix of given size.
+ */
+ explicit inline PermutationMatrix(Index size) : m_indices(size)
+ {
+ eigen_internal_assert(size <= NumTraits<StorageIndex>::highest());
+ }
+
+ /** Copy constructor. */
+ template<typename OtherDerived>
+ inline PermutationMatrix(const PermutationBase<OtherDerived>& other)
+ : m_indices(other.indices()) {}
+
+ /** Generic constructor from expression of the indices. The indices
+ * array has the meaning that the permutations sends each integer i to indices[i].
+ *
+ * \warning It is your responsibility to check that the indices array that you passes actually
+ * describes a permutation, i.e., each value between 0 and n-1 occurs exactly once, where n is the
+ * array's size.
+ */
+ template<typename Other>
+ explicit inline PermutationMatrix(const MatrixBase<Other>& indices) : m_indices(indices)
+ {}
+
+ /** Convert the Transpositions \a tr to a permutation matrix */
+ template<typename Other>
+ explicit PermutationMatrix(const TranspositionsBase<Other>& tr)
+ : m_indices(tr.size())
+ {
+ *this = tr;
+ }
+
+ /** Copies the other permutation into *this */
+ template<typename Other>
+ PermutationMatrix& operator=(const PermutationBase<Other>& other)
+ {
+ m_indices = other.indices();
+ return *this;
+ }
+
+ /** Assignment from the Transpositions \a tr */
+ template<typename Other>
+ PermutationMatrix& operator=(const TranspositionsBase<Other>& tr)
+ {
+ return Base::operator=(tr.derived());
+ }
+
+ /** const version of indices(). */
+ const IndicesType& indices() const { return m_indices; }
+ /** \returns a reference to the stored array representing the permutation. */
+ IndicesType& indices() { return m_indices; }
+
+
+ /**** multiplication helpers to hopefully get RVO ****/
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename Other>
+ PermutationMatrix(const InverseImpl<Other,PermutationStorage>& other)
+ : m_indices(other.derived().nestedExpression().size())
+ {
+ eigen_internal_assert(m_indices.size() <= NumTraits<StorageIndex>::highest());
+ StorageIndex end = StorageIndex(m_indices.size());
+ for (StorageIndex i=0; i<end;++i)
+ m_indices.coeffRef(other.derived().nestedExpression().indices().coeff(i)) = i;
+ }
+ template<typename Lhs,typename Rhs>
+ PermutationMatrix(internal::PermPermProduct_t, const Lhs& lhs, const Rhs& rhs)
+ : m_indices(lhs.indices().size())
+ {
+ Base::assignProduct(lhs,rhs);
+ }
+#endif
+
+ protected:
+
+ IndicesType m_indices;
+};
+
+
+namespace internal {
+template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess>
+struct traits<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> >
+ : traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
+{
+ typedef PermutationStorage StorageKind;
+ typedef Map<const Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, _PacketAccess> IndicesType;
+ typedef _StorageIndex StorageIndex;
+ typedef void Scalar;
+};
+}
+
+template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess>
+class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess>
+ : public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> >
+{
+ typedef PermutationBase<Map> Base;
+ typedef internal::traits<Map> Traits;
+ public:
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ typedef typename Traits::IndicesType IndicesType;
+ typedef typename IndicesType::Scalar StorageIndex;
+ #endif
+
+ inline Map(const StorageIndex* indicesPtr)
+ : m_indices(indicesPtr)
+ {}
+
+ inline Map(const StorageIndex* indicesPtr, Index size)
+ : m_indices(indicesPtr,size)
+ {}
+
+ /** Copies the other permutation into *this */
+ template<typename Other>
+ Map& operator=(const PermutationBase<Other>& other)
+ { return Base::operator=(other.derived()); }
+
+ /** Assignment from the Transpositions \a tr */
+ template<typename Other>
+ Map& operator=(const TranspositionsBase<Other>& tr)
+ { return Base::operator=(tr.derived()); }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ /** This is a special case of the templated operator=. Its purpose is to
+ * prevent a default operator= from hiding the templated operator=.
+ */
+ Map& operator=(const Map& other)
+ {
+ m_indices = other.m_indices;
+ return *this;
+ }
+ #endif
+
+ /** const version of indices(). */
+ const IndicesType& indices() const { return m_indices; }
+ /** \returns a reference to the stored array representing the permutation. */
+ IndicesType& indices() { return m_indices; }
+
+ protected:
+
+ IndicesType m_indices;
+};
+
+template<typename _IndicesType> class TranspositionsWrapper;
+namespace internal {
+template<typename _IndicesType>
+struct traits<PermutationWrapper<_IndicesType> >
+{
+ typedef PermutationStorage StorageKind;
+ typedef void Scalar;
+ typedef typename _IndicesType::Scalar StorageIndex;
+ typedef _IndicesType IndicesType;
+ enum {
+ RowsAtCompileTime = _IndicesType::SizeAtCompileTime,
+ ColsAtCompileTime = _IndicesType::SizeAtCompileTime,
+ MaxRowsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
+ MaxColsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
+ Flags = 0
+ };
+};
+}
+
+/** \class PermutationWrapper
+ * \ingroup Core_Module
+ *
+ * \brief Class to view a vector of integers as a permutation matrix
+ *
+ * \tparam _IndicesType the type of the vector of integer (can be any compatible expression)
+ *
+ * This class allows to view any vector expression of integers as a permutation matrix.
+ *
+ * \sa class PermutationBase, class PermutationMatrix
+ */
+template<typename _IndicesType>
+class PermutationWrapper : public PermutationBase<PermutationWrapper<_IndicesType> >
+{
+ typedef PermutationBase<PermutationWrapper> Base;
+ typedef internal::traits<PermutationWrapper> Traits;
+ public:
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ typedef typename Traits::IndicesType IndicesType;
+ #endif
+
+ inline PermutationWrapper(const IndicesType& indices)
+ : m_indices(indices)
+ {}
+
+ /** const version of indices(). */
+ const typename internal::remove_all<typename IndicesType::Nested>::type&
+ indices() const { return m_indices; }
+
+ protected:
+
+ typename IndicesType::Nested m_indices;
+};
+
+
+/** \returns the matrix with the permutation applied to the columns.
+ */
+template<typename MatrixDerived, typename PermutationDerived>
+EIGEN_DEVICE_FUNC
+const Product<MatrixDerived, PermutationDerived, AliasFreeProduct>
+operator*(const MatrixBase<MatrixDerived> &matrix,
+ const PermutationBase<PermutationDerived>& permutation)
+{
+ return Product<MatrixDerived, PermutationDerived, AliasFreeProduct>
+ (matrix.derived(), permutation.derived());
+}
+
+/** \returns the matrix with the permutation applied to the rows.
+ */
+template<typename PermutationDerived, typename MatrixDerived>
+EIGEN_DEVICE_FUNC
+const Product<PermutationDerived, MatrixDerived, AliasFreeProduct>
+operator*(const PermutationBase<PermutationDerived> &permutation,
+ const MatrixBase<MatrixDerived>& matrix)
+{
+ return Product<PermutationDerived, MatrixDerived, AliasFreeProduct>
+ (permutation.derived(), matrix.derived());
+}
+
+
+template<typename PermutationType>
+class InverseImpl<PermutationType, PermutationStorage>
+ : public EigenBase<Inverse<PermutationType> >
+{
+ typedef typename PermutationType::PlainPermutationType PlainPermutationType;
+ typedef internal::traits<PermutationType> PermTraits;
+ protected:
+ InverseImpl() {}
+ public:
+ typedef Inverse<PermutationType> InverseType;
+ using EigenBase<Inverse<PermutationType> >::derived;
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ typedef typename PermutationType::DenseMatrixType DenseMatrixType;
+ enum {
+ RowsAtCompileTime = PermTraits::RowsAtCompileTime,
+ ColsAtCompileTime = PermTraits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = PermTraits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = PermTraits::MaxColsAtCompileTime
+ };
+ #endif
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename DenseDerived>
+ void evalTo(MatrixBase<DenseDerived>& other) const
+ {
+ other.setZero();
+ for (Index i=0; i<derived().rows();++i)
+ other.coeffRef(i, derived().nestedExpression().indices().coeff(i)) = typename DenseDerived::Scalar(1);
+ }
+ #endif
+
+ /** \return the equivalent permutation matrix */
+ PlainPermutationType eval() const { return derived(); }
+
+ DenseMatrixType toDenseMatrix() const { return derived(); }
+
+ /** \returns the matrix with the inverse permutation applied to the columns.
+ */
+ template<typename OtherDerived> friend
+ const Product<OtherDerived, InverseType, AliasFreeProduct>
+ operator*(const MatrixBase<OtherDerived>& matrix, const InverseType& trPerm)
+ {
+ return Product<OtherDerived, InverseType, AliasFreeProduct>(matrix.derived(), trPerm.derived());
+ }
+
+ /** \returns the matrix with the inverse permutation applied to the rows.
+ */
+ template<typename OtherDerived>
+ const Product<InverseType, OtherDerived, AliasFreeProduct>
+ operator*(const MatrixBase<OtherDerived>& matrix) const
+ {
+ return Product<InverseType, OtherDerived, AliasFreeProduct>(derived(), matrix.derived());
+ }
+};
+
+template<typename Derived>
+const PermutationWrapper<const Derived> MatrixBase<Derived>::asPermutation() const
+{
+ return derived();
+}
+
+namespace internal {
+
+template<> struct AssignmentKind<DenseShape,PermutationShape> { typedef EigenBase2EigenBase Kind; };
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PERMUTATIONMATRIX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/PlainObjectBase.h b/src/3rdparty/eigen/Eigen/src/Core/PlainObjectBase.h
new file mode 100644
index 000000000..e2ddbd1d5
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/PlainObjectBase.h
@@ -0,0 +1,1128 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_DENSESTORAGEBASE_H
+#define EIGEN_DENSESTORAGEBASE_H
+
+#if defined(EIGEN_INITIALIZE_MATRICES_BY_ZERO)
+# define EIGEN_INITIALIZE_COEFFS
+# define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(Index i=0;i<base().size();++i) coeffRef(i)=Scalar(0);
+#elif defined(EIGEN_INITIALIZE_MATRICES_BY_NAN)
+# define EIGEN_INITIALIZE_COEFFS
+# define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(Index i=0;i<base().size();++i) coeffRef(i)=std::numeric_limits<Scalar>::quiet_NaN();
+#else
+# undef EIGEN_INITIALIZE_COEFFS
+# define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
+#endif
+
+namespace Eigen {
+
+namespace internal {
+
+template<int MaxSizeAtCompileTime> struct check_rows_cols_for_overflow {
+ template<typename Index>
+ EIGEN_DEVICE_FUNC
+ static EIGEN_ALWAYS_INLINE void run(Index, Index)
+ {
+ }
+};
+
+template<> struct check_rows_cols_for_overflow<Dynamic> {
+ template<typename Index>
+ EIGEN_DEVICE_FUNC
+ static EIGEN_ALWAYS_INLINE void run(Index rows, Index cols)
+ {
+ // http://hg.mozilla.org/mozilla-central/file/6c8a909977d3/xpcom/ds/CheckedInt.h#l242
+ // we assume Index is signed
+ Index max_index = (std::size_t(1) << (8 * sizeof(Index) - 1)) - 1; // assume Index is signed
+ bool error = (rows == 0 || cols == 0) ? false
+ : (rows > max_index / cols);
+ if (error)
+ throw_std_bad_alloc();
+ }
+};
+
+template <typename Derived,
+ typename OtherDerived = Derived,
+ bool IsVector = bool(Derived::IsVectorAtCompileTime) && bool(OtherDerived::IsVectorAtCompileTime)>
+struct conservative_resize_like_impl;
+
+template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers> struct matrix_swap_impl;
+
+} // end namespace internal
+
+#ifdef EIGEN_PARSED_BY_DOXYGEN
+namespace doxygen {
+
+// This is a workaround to doxygen not being able to understand the inheritance logic
+// when it is hidden by the dense_xpr_base helper struct.
+// Moreover, doxygen fails to include members that are not documented in the declaration body of
+// MatrixBase if we inherits MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >,
+// this is why we simply inherits MatrixBase, though this does not make sense.
+
+/** This class is just a workaround for Doxygen and it does not not actually exist. */
+template<typename Derived> struct dense_xpr_base_dispatcher;
+/** This class is just a workaround for Doxygen and it does not not actually exist. */
+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
+struct dense_xpr_base_dispatcher<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
+ : public MatrixBase {};
+/** This class is just a workaround for Doxygen and it does not not actually exist. */
+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
+struct dense_xpr_base_dispatcher<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
+ : public ArrayBase {};
+
+} // namespace doxygen
+
+/** \class PlainObjectBase
+ * \ingroup Core_Module
+ * \brief %Dense storage base class for matrices and arrays.
+ *
+ * This class can be extended with the help of the plugin mechanism described on the page
+ * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_PLAINOBJECTBASE_PLUGIN.
+ *
+ * \tparam Derived is the derived type, e.g., a Matrix or Array
+ *
+ * \sa \ref TopicClassHierarchy
+ */
+template<typename Derived>
+class PlainObjectBase : public doxygen::dense_xpr_base_dispatcher<Derived>
+#else
+template<typename Derived>
+class PlainObjectBase : public internal::dense_xpr_base<Derived>::type
+#endif
+{
+ public:
+ enum { Options = internal::traits<Derived>::Options };
+ typedef typename internal::dense_xpr_base<Derived>::type Base;
+
+ typedef typename internal::traits<Derived>::StorageKind StorageKind;
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+
+ typedef typename internal::packet_traits<Scalar>::type PacketScalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef Derived DenseType;
+
+ using Base::RowsAtCompileTime;
+ using Base::ColsAtCompileTime;
+ using Base::SizeAtCompileTime;
+ using Base::MaxRowsAtCompileTime;
+ using Base::MaxColsAtCompileTime;
+ using Base::MaxSizeAtCompileTime;
+ using Base::IsVectorAtCompileTime;
+ using Base::Flags;
+
+ typedef Eigen::Map<Derived, Unaligned> MapType;
+ typedef const Eigen::Map<const Derived, Unaligned> ConstMapType;
+ typedef Eigen::Map<Derived, AlignedMax> AlignedMapType;
+ typedef const Eigen::Map<const Derived, AlignedMax> ConstAlignedMapType;
+ template<typename StrideType> struct StridedMapType { typedef Eigen::Map<Derived, Unaligned, StrideType> type; };
+ template<typename StrideType> struct StridedConstMapType { typedef Eigen::Map<const Derived, Unaligned, StrideType> type; };
+ template<typename StrideType> struct StridedAlignedMapType { typedef Eigen::Map<Derived, AlignedMax, StrideType> type; };
+ template<typename StrideType> struct StridedConstAlignedMapType { typedef Eigen::Map<const Derived, AlignedMax, StrideType> type; };
+
+ protected:
+ DenseStorage<Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options> m_storage;
+
+ public:
+ enum { NeedsToAlign = (SizeAtCompileTime != Dynamic) && (internal::traits<Derived>::Alignment>0) };
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
+
+ EIGEN_DEVICE_FUNC
+ Base& base() { return *static_cast<Base*>(this); }
+ EIGEN_DEVICE_FUNC
+ const Base& base() const { return *static_cast<const Base*>(this); }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index rows() const EIGEN_NOEXCEPT { return m_storage.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index cols() const EIGEN_NOEXCEPT { return m_storage.cols(); }
+
+ /** This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index,Index) const
+ * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.
+ *
+ * See DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const for details. */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE const Scalar& coeff(Index rowId, Index colId) const
+ {
+ if(Flags & RowMajorBit)
+ return m_storage.data()[colId + rowId * m_storage.cols()];
+ else // column-major
+ return m_storage.data()[rowId + colId * m_storage.rows()];
+ }
+
+ /** This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const
+ * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.
+ *
+ * See DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const for details. */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE const Scalar& coeff(Index index) const
+ {
+ return m_storage.data()[index];
+ }
+
+ /** This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const
+ * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.
+ *
+ * See DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const for details. */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar& coeffRef(Index rowId, Index colId)
+ {
+ if(Flags & RowMajorBit)
+ return m_storage.data()[colId + rowId * m_storage.cols()];
+ else // column-major
+ return m_storage.data()[rowId + colId * m_storage.rows()];
+ }
+
+ /** This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index) const
+ * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.
+ *
+ * See DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index) const for details. */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
+ {
+ return m_storage.data()[index];
+ }
+
+ /** This is the const version of coeffRef(Index,Index) which is thus synonym of coeff(Index,Index).
+ * It is provided for convenience. */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE const Scalar& coeffRef(Index rowId, Index colId) const
+ {
+ if(Flags & RowMajorBit)
+ return m_storage.data()[colId + rowId * m_storage.cols()];
+ else // column-major
+ return m_storage.data()[rowId + colId * m_storage.rows()];
+ }
+
+ /** This is the const version of coeffRef(Index) which is thus synonym of coeff(Index).
+ * It is provided for convenience. */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE const Scalar& coeffRef(Index index) const
+ {
+ return m_storage.data()[index];
+ }
+
+ /** \internal */
+ template<int LoadMode>
+ EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId) const
+ {
+ return internal::ploadt<PacketScalar, LoadMode>
+ (m_storage.data() + (Flags & RowMajorBit
+ ? colId + rowId * m_storage.cols()
+ : rowId + colId * m_storage.rows()));
+ }
+
+ /** \internal */
+ template<int LoadMode>
+ EIGEN_STRONG_INLINE PacketScalar packet(Index index) const
+ {
+ return internal::ploadt<PacketScalar, LoadMode>(m_storage.data() + index);
+ }
+
+ /** \internal */
+ template<int StoreMode>
+ EIGEN_STRONG_INLINE void writePacket(Index rowId, Index colId, const PacketScalar& val)
+ {
+ internal::pstoret<Scalar, PacketScalar, StoreMode>
+ (m_storage.data() + (Flags & RowMajorBit
+ ? colId + rowId * m_storage.cols()
+ : rowId + colId * m_storage.rows()), val);
+ }
+
+ /** \internal */
+ template<int StoreMode>
+ EIGEN_STRONG_INLINE void writePacket(Index index, const PacketScalar& val)
+ {
+ internal::pstoret<Scalar, PacketScalar, StoreMode>(m_storage.data() + index, val);
+ }
+
+ /** \returns a const pointer to the data array of this matrix */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar *data() const
+ { return m_storage.data(); }
+
+ /** \returns a pointer to the data array of this matrix */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data()
+ { return m_storage.data(); }
+
+ /** Resizes \c *this to a \a rows x \a cols matrix.
+ *
+ * This method is intended for dynamic-size matrices, although it is legal to call it on any
+ * matrix as long as fixed dimensions are left unchanged. If you only want to change the number
+ * of rows and/or of columns, you can use resize(NoChange_t, Index), resize(Index, NoChange_t).
+ *
+ * If the current number of coefficients of \c *this exactly matches the
+ * product \a rows * \a cols, then no memory allocation is performed and
+ * the current values are left unchanged. In all other cases, including
+ * shrinking, the data is reallocated and all previous values are lost.
+ *
+ * Example: \include Matrix_resize_int_int.cpp
+ * Output: \verbinclude Matrix_resize_int_int.out
+ *
+ * \sa resize(Index) for vectors, resize(NoChange_t, Index), resize(Index, NoChange_t)
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
+ {
+ eigen_assert( EIGEN_IMPLIES(RowsAtCompileTime!=Dynamic,rows==RowsAtCompileTime)
+ && EIGEN_IMPLIES(ColsAtCompileTime!=Dynamic,cols==ColsAtCompileTime)
+ && EIGEN_IMPLIES(RowsAtCompileTime==Dynamic && MaxRowsAtCompileTime!=Dynamic,rows<=MaxRowsAtCompileTime)
+ && EIGEN_IMPLIES(ColsAtCompileTime==Dynamic && MaxColsAtCompileTime!=Dynamic,cols<=MaxColsAtCompileTime)
+ && rows>=0 && cols>=0 && "Invalid sizes when resizing a matrix or array.");
+ internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(rows, cols);
+ #ifdef EIGEN_INITIALIZE_COEFFS
+ Index size = rows*cols;
+ bool size_changed = size != this->size();
+ m_storage.resize(size, rows, cols);
+ if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
+ #else
+ m_storage.resize(rows*cols, rows, cols);
+ #endif
+ }
+
+ /** Resizes \c *this to a vector of length \a size
+ *
+ * \only_for_vectors. This method does not work for
+ * partially dynamic matrices when the static dimension is anything other
+ * than 1. For example it will not work with Matrix<double, 2, Dynamic>.
+ *
+ * Example: \include Matrix_resize_int.cpp
+ * Output: \verbinclude Matrix_resize_int.out
+ *
+ * \sa resize(Index,Index), resize(NoChange_t, Index), resize(Index, NoChange_t)
+ */
+ EIGEN_DEVICE_FUNC
+ inline void resize(Index size)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(PlainObjectBase)
+ eigen_assert(((SizeAtCompileTime == Dynamic && (MaxSizeAtCompileTime==Dynamic || size<=MaxSizeAtCompileTime)) || SizeAtCompileTime == size) && size>=0);
+ #ifdef EIGEN_INITIALIZE_COEFFS
+ bool size_changed = size != this->size();
+ #endif
+ if(RowsAtCompileTime == 1)
+ m_storage.resize(size, 1, size);
+ else
+ m_storage.resize(size, size, 1);
+ #ifdef EIGEN_INITIALIZE_COEFFS
+ if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
+ #endif
+ }
+
+ /** Resizes the matrix, changing only the number of columns. For the parameter of type NoChange_t, just pass the special value \c NoChange
+ * as in the example below.
+ *
+ * Example: \include Matrix_resize_NoChange_int.cpp
+ * Output: \verbinclude Matrix_resize_NoChange_int.out
+ *
+ * \sa resize(Index,Index)
+ */
+ EIGEN_DEVICE_FUNC
+ inline void resize(NoChange_t, Index cols)
+ {
+ resize(rows(), cols);
+ }
+
+ /** Resizes the matrix, changing only the number of rows. For the parameter of type NoChange_t, just pass the special value \c NoChange
+ * as in the example below.
+ *
+ * Example: \include Matrix_resize_int_NoChange.cpp
+ * Output: \verbinclude Matrix_resize_int_NoChange.out
+ *
+ * \sa resize(Index,Index)
+ */
+ EIGEN_DEVICE_FUNC
+ inline void resize(Index rows, NoChange_t)
+ {
+ resize(rows, cols());
+ }
+
+ /** Resizes \c *this to have the same dimensions as \a other.
+ * Takes care of doing all the checking that's needed.
+ *
+ * Note that copying a row-vector into a vector (and conversely) is allowed.
+ * The resizing, if any, is then done in the appropriate way so that row-vectors
+ * remain row-vectors and vectors remain vectors.
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void resizeLike(const EigenBase<OtherDerived>& _other)
+ {
+ const OtherDerived& other = _other.derived();
+ internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(other.rows(), other.cols());
+ const Index othersize = other.rows()*other.cols();
+ if(RowsAtCompileTime == 1)
+ {
+ eigen_assert(other.rows() == 1 || other.cols() == 1);
+ resize(1, othersize);
+ }
+ else if(ColsAtCompileTime == 1)
+ {
+ eigen_assert(other.rows() == 1 || other.cols() == 1);
+ resize(othersize, 1);
+ }
+ else resize(other.rows(), other.cols());
+ }
+
+ /** Resizes the matrix to \a rows x \a cols while leaving old values untouched.
+ *
+ * The method is intended for matrices of dynamic size. If you only want to change the number
+ * of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or
+ * conservativeResize(Index, NoChange_t).
+ *
+ * Matrices are resized relative to the top-left element. In case values need to be
+ * appended to the matrix they will be uninitialized.
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void conservativeResize(Index rows, Index cols)
+ {
+ internal::conservative_resize_like_impl<Derived>::run(*this, rows, cols);
+ }
+
+ /** Resizes the matrix to \a rows x \a cols while leaving old values untouched.
+ *
+ * As opposed to conservativeResize(Index rows, Index cols), this version leaves
+ * the number of columns unchanged.
+ *
+ * In case the matrix is growing, new rows will be uninitialized.
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void conservativeResize(Index rows, NoChange_t)
+ {
+ // Note: see the comment in conservativeResize(Index,Index)
+ conservativeResize(rows, cols());
+ }
+
+ /** Resizes the matrix to \a rows x \a cols while leaving old values untouched.
+ *
+ * As opposed to conservativeResize(Index rows, Index cols), this version leaves
+ * the number of rows unchanged.
+ *
+ * In case the matrix is growing, new columns will be uninitialized.
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void conservativeResize(NoChange_t, Index cols)
+ {
+ // Note: see the comment in conservativeResize(Index,Index)
+ conservativeResize(rows(), cols);
+ }
+
+ /** Resizes the vector to \a size while retaining old values.
+ *
+ * \only_for_vectors. This method does not work for
+ * partially dynamic matrices when the static dimension is anything other
+ * than 1. For example it will not work with Matrix<double, 2, Dynamic>.
+ *
+ * When values are appended, they will be uninitialized.
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void conservativeResize(Index size)
+ {
+ internal::conservative_resize_like_impl<Derived>::run(*this, size);
+ }
+
+ /** Resizes the matrix to \a rows x \a cols of \c other, while leaving old values untouched.
+ *
+ * The method is intended for matrices of dynamic size. If you only want to change the number
+ * of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or
+ * conservativeResize(Index, NoChange_t).
+ *
+ * Matrices are resized relative to the top-left element. In case values need to be
+ * appended to the matrix they will copied from \c other.
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void conservativeResizeLike(const DenseBase<OtherDerived>& other)
+ {
+ internal::conservative_resize_like_impl<Derived,OtherDerived>::run(*this, other);
+ }
+
+ /** This is a special case of the templated operator=. Its purpose is to
+ * prevent a default operator= from hiding the templated operator=.
+ */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Derived& operator=(const PlainObjectBase& other)
+ {
+ return _set(other);
+ }
+
+ /** \sa MatrixBase::lazyAssign() */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Derived& lazyAssign(const DenseBase<OtherDerived>& other)
+ {
+ _resize_to_match(other);
+ return Base::lazyAssign(other.derived());
+ }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Derived& operator=(const ReturnByValue<OtherDerived>& func)
+ {
+ resize(func.rows(), func.cols());
+ return Base::operator=(func);
+ }
+
+ // Prevent user from trying to instantiate PlainObjectBase objects
+ // by making all its constructor protected. See bug 1074.
+ protected:
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE PlainObjectBase() : m_storage()
+ {
+// _check_template_params();
+// EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
+ }
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ // FIXME is it still needed ?
+ /** \internal */
+ EIGEN_DEVICE_FUNC
+ explicit PlainObjectBase(internal::constructor_without_unaligned_array_assert)
+ : m_storage(internal::constructor_without_unaligned_array_assert())
+ {
+// _check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
+ }
+#endif
+
+#if EIGEN_HAS_RVALUE_REFERENCES
+ EIGEN_DEVICE_FUNC
+ PlainObjectBase(PlainObjectBase&& other) EIGEN_NOEXCEPT
+ : m_storage( std::move(other.m_storage) )
+ {
+ }
+
+ EIGEN_DEVICE_FUNC
+ PlainObjectBase& operator=(PlainObjectBase&& other) EIGEN_NOEXCEPT
+ {
+ _check_template_params();
+ m_storage = std::move(other.m_storage);
+ return *this;
+ }
+#endif
+
+ /** Copy constructor */
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE PlainObjectBase(const PlainObjectBase& other)
+ : Base(), m_storage(other.m_storage) { }
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE PlainObjectBase(Index size, Index rows, Index cols)
+ : m_storage(size, rows, cols)
+ {
+// _check_template_params();
+// EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
+ }
+
+ #if EIGEN_HAS_CXX11
+ /** \brief Construct a row of column vector with fixed size from an arbitrary number of coefficients. \cpp11
+ *
+ * \only_for_vectors
+ *
+ * This constructor is for 1D array or vectors with more than 4 coefficients.
+ * There exists C++98 analogue constructors for fixed-size array/vector having 1, 2, 3, or 4 coefficients.
+ *
+ * \warning To construct a column (resp. row) vector of fixed length, the number of values passed to this
+ * constructor must match the the fixed number of rows (resp. columns) of \c *this.
+ */
+ template <typename... ArgTypes>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
+ : m_storage()
+ {
+ _check_template_params();
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, sizeof...(args) + 4);
+ m_storage.data()[0] = a0;
+ m_storage.data()[1] = a1;
+ m_storage.data()[2] = a2;
+ m_storage.data()[3] = a3;
+ Index i = 4;
+ auto x = {(m_storage.data()[i++] = args, 0)...};
+ static_cast<void>(x);
+ }
+
+ /** \brief Constructs a Matrix or Array and initializes it by elements given by an initializer list of initializer
+ * lists \cpp11
+ */
+ EIGEN_DEVICE_FUNC
+ explicit EIGEN_STRONG_INLINE PlainObjectBase(const std::initializer_list<std::initializer_list<Scalar>>& list)
+ : m_storage()
+ {
+ _check_template_params();
+
+ size_t list_size = 0;
+ if (list.begin() != list.end()) {
+ list_size = list.begin()->size();
+ }
+
+ // This is to allow syntax like VectorXi {{1, 2, 3, 4}}
+ if (ColsAtCompileTime == 1 && list.size() == 1) {
+ eigen_assert(list_size == static_cast<size_t>(RowsAtCompileTime) || RowsAtCompileTime == Dynamic);
+ resize(list_size, ColsAtCompileTime);
+ std::copy(list.begin()->begin(), list.begin()->end(), m_storage.data());
+ } else {
+ eigen_assert(list.size() == static_cast<size_t>(RowsAtCompileTime) || RowsAtCompileTime == Dynamic);
+ eigen_assert(list_size == static_cast<size_t>(ColsAtCompileTime) || ColsAtCompileTime == Dynamic);
+ resize(list.size(), list_size);
+
+ Index row_index = 0;
+ for (const std::initializer_list<Scalar>& row : list) {
+ eigen_assert(list_size == row.size());
+ Index col_index = 0;
+ for (const Scalar& e : row) {
+ coeffRef(row_index, col_index) = e;
+ ++col_index;
+ }
+ ++row_index;
+ }
+ }
+ }
+ #endif // end EIGEN_HAS_CXX11
+
+ /** \sa PlainObjectBase::operator=(const EigenBase<OtherDerived>&) */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE PlainObjectBase(const DenseBase<OtherDerived> &other)
+ : m_storage()
+ {
+ _check_template_params();
+ resizeLike(other);
+ _set_noalias(other);
+ }
+
+ /** \sa PlainObjectBase::operator=(const EigenBase<OtherDerived>&) */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE PlainObjectBase(const EigenBase<OtherDerived> &other)
+ : m_storage()
+ {
+ _check_template_params();
+ resizeLike(other);
+ *this = other.derived();
+ }
+ /** \brief Copy constructor with in-place evaluation */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE PlainObjectBase(const ReturnByValue<OtherDerived>& other)
+ {
+ _check_template_params();
+ // FIXME this does not automatically transpose vectors if necessary
+ resize(other.rows(), other.cols());
+ other.evalTo(this->derived());
+ }
+
+ public:
+
+ /** \brief Copies the generic expression \a other into *this.
+ * \copydetails DenseBase::operator=(const EigenBase<OtherDerived> &other)
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Derived& operator=(const EigenBase<OtherDerived> &other)
+ {
+ _resize_to_match(other);
+ Base::operator=(other.derived());
+ return this->derived();
+ }
+
+ /** \name Map
+ * These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects,
+ * while the AlignedMap() functions return aligned Map objects and thus should be called only with 16-byte-aligned
+ * \a data pointers.
+ *
+ * Here is an example using strides:
+ * \include Matrix_Map_stride.cpp
+ * Output: \verbinclude Matrix_Map_stride.out
+ *
+ * \see class Map
+ */
+ //@{
+ static inline ConstMapType Map(const Scalar* data)
+ { return ConstMapType(data); }
+ static inline MapType Map(Scalar* data)
+ { return MapType(data); }
+ static inline ConstMapType Map(const Scalar* data, Index size)
+ { return ConstMapType(data, size); }
+ static inline MapType Map(Scalar* data, Index size)
+ { return MapType(data, size); }
+ static inline ConstMapType Map(const Scalar* data, Index rows, Index cols)
+ { return ConstMapType(data, rows, cols); }
+ static inline MapType Map(Scalar* data, Index rows, Index cols)
+ { return MapType(data, rows, cols); }
+
+ static inline ConstAlignedMapType MapAligned(const Scalar* data)
+ { return ConstAlignedMapType(data); }
+ static inline AlignedMapType MapAligned(Scalar* data)
+ { return AlignedMapType(data); }
+ static inline ConstAlignedMapType MapAligned(const Scalar* data, Index size)
+ { return ConstAlignedMapType(data, size); }
+ static inline AlignedMapType MapAligned(Scalar* data, Index size)
+ { return AlignedMapType(data, size); }
+ static inline ConstAlignedMapType MapAligned(const Scalar* data, Index rows, Index cols)
+ { return ConstAlignedMapType(data, rows, cols); }
+ static inline AlignedMapType MapAligned(Scalar* data, Index rows, Index cols)
+ { return AlignedMapType(data, rows, cols); }
+
+ template<int Outer, int Inner>
+ static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, const Stride<Outer, Inner>& stride)
+ { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, stride); }
+ template<int Outer, int Inner>
+ static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, const Stride<Outer, Inner>& stride)
+ { return typename StridedMapType<Stride<Outer, Inner> >::type(data, stride); }
+ template<int Outer, int Inner>
+ static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, Index size, const Stride<Outer, Inner>& stride)
+ { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, size, stride); }
+ template<int Outer, int Inner>
+ static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, Index size, const Stride<Outer, Inner>& stride)
+ { return typename StridedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
+ template<int Outer, int Inner>
+ static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
+ { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
+ template<int Outer, int Inner>
+ static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
+ { return typename StridedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
+
+ template<int Outer, int Inner>
+ static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, const Stride<Outer, Inner>& stride)
+ { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
+ template<int Outer, int Inner>
+ static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, const Stride<Outer, Inner>& stride)
+ { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
+ template<int Outer, int Inner>
+ static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, Index size, const Stride<Outer, Inner>& stride)
+ { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
+ template<int Outer, int Inner>
+ static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, Index size, const Stride<Outer, Inner>& stride)
+ { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
+ template<int Outer, int Inner>
+ static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
+ { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
+ template<int Outer, int Inner>
+ static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
+ { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
+ //@}
+
+ using Base::setConstant;
+ EIGEN_DEVICE_FUNC Derived& setConstant(Index size, const Scalar& val);
+ EIGEN_DEVICE_FUNC Derived& setConstant(Index rows, Index cols, const Scalar& val);
+ EIGEN_DEVICE_FUNC Derived& setConstant(NoChange_t, Index cols, const Scalar& val);
+ EIGEN_DEVICE_FUNC Derived& setConstant(Index rows, NoChange_t, const Scalar& val);
+
+ using Base::setZero;
+ EIGEN_DEVICE_FUNC Derived& setZero(Index size);
+ EIGEN_DEVICE_FUNC Derived& setZero(Index rows, Index cols);
+ EIGEN_DEVICE_FUNC Derived& setZero(NoChange_t, Index cols);
+ EIGEN_DEVICE_FUNC Derived& setZero(Index rows, NoChange_t);
+
+ using Base::setOnes;
+ EIGEN_DEVICE_FUNC Derived& setOnes(Index size);
+ EIGEN_DEVICE_FUNC Derived& setOnes(Index rows, Index cols);
+ EIGEN_DEVICE_FUNC Derived& setOnes(NoChange_t, Index cols);
+ EIGEN_DEVICE_FUNC Derived& setOnes(Index rows, NoChange_t);
+
+ using Base::setRandom;
+ Derived& setRandom(Index size);
+ Derived& setRandom(Index rows, Index cols);
+ Derived& setRandom(NoChange_t, Index cols);
+ Derived& setRandom(Index rows, NoChange_t);
+
+ #ifdef EIGEN_PLAINOBJECTBASE_PLUGIN
+ #include EIGEN_PLAINOBJECTBASE_PLUGIN
+ #endif
+
+ protected:
+ /** \internal Resizes *this in preparation for assigning \a other to it.
+ * Takes care of doing all the checking that's needed.
+ *
+ * Note that copying a row-vector into a vector (and conversely) is allowed.
+ * The resizing, if any, is then done in the appropriate way so that row-vectors
+ * remain row-vectors and vectors remain vectors.
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _resize_to_match(const EigenBase<OtherDerived>& other)
+ {
+ #ifdef EIGEN_NO_AUTOMATIC_RESIZING
+ eigen_assert((this->size()==0 || (IsVectorAtCompileTime ? (this->size() == other.size())
+ : (rows() == other.rows() && cols() == other.cols())))
+ && "Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined");
+ EIGEN_ONLY_USED_FOR_DEBUG(other);
+ #else
+ resizeLike(other);
+ #endif
+ }
+
+ /**
+ * \brief Copies the value of the expression \a other into \c *this with automatic resizing.
+ *
+ * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized),
+ * it will be initialized.
+ *
+ * Note that copying a row-vector into a vector (and conversely) is allowed.
+ * The resizing, if any, is then done in the appropriate way so that row-vectors
+ * remain row-vectors and vectors remain vectors.
+ *
+ * \sa operator=(const MatrixBase<OtherDerived>&), _set_noalias()
+ *
+ * \internal
+ */
+ // aliasing is dealt once in internal::call_assignment
+ // so at this stage we have to assume aliasing... and resising has to be done later.
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Derived& _set(const DenseBase<OtherDerived>& other)
+ {
+ internal::call_assignment(this->derived(), other.derived());
+ return this->derived();
+ }
+
+ /** \internal Like _set() but additionally makes the assumption that no aliasing effect can happen (which
+ * is the case when creating a new matrix) so one can enforce lazy evaluation.
+ *
+ * \sa operator=(const MatrixBase<OtherDerived>&), _set()
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE Derived& _set_noalias(const DenseBase<OtherDerived>& other)
+ {
+ // I don't think we need this resize call since the lazyAssign will anyways resize
+ // and lazyAssign will be called by the assign selector.
+ //_resize_to_match(other);
+ // the 'false' below means to enforce lazy evaluation. We don't use lazyAssign() because
+ // it wouldn't allow to copy a row-vector into a column-vector.
+ internal::call_assignment_no_alias(this->derived(), other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>());
+ return this->derived();
+ }
+
+ template<typename T0, typename T1>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init2(Index rows, Index cols, typename internal::enable_if<Base::SizeAtCompileTime!=2,T0>::type* = 0)
+ {
+ const bool t0_is_integer_alike = internal::is_valid_index_type<T0>::value;
+ const bool t1_is_integer_alike = internal::is_valid_index_type<T1>::value;
+ EIGEN_STATIC_ASSERT(t0_is_integer_alike &&
+ t1_is_integer_alike,
+ FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
+ resize(rows,cols);
+ }
+
+ template<typename T0, typename T1>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init2(const T0& val0, const T1& val1, typename internal::enable_if<Base::SizeAtCompileTime==2,T0>::type* = 0)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
+ m_storage.data()[0] = Scalar(val0);
+ m_storage.data()[1] = Scalar(val1);
+ }
+
+ template<typename T0, typename T1>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init2(const Index& val0, const Index& val1,
+ typename internal::enable_if< (!internal::is_same<Index,Scalar>::value)
+ && (internal::is_same<T0,Index>::value)
+ && (internal::is_same<T1,Index>::value)
+ && Base::SizeAtCompileTime==2,T1>::type* = 0)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
+ m_storage.data()[0] = Scalar(val0);
+ m_storage.data()[1] = Scalar(val1);
+ }
+
+ // The argument is convertible to the Index type and we either have a non 1x1 Matrix, or a dynamic-sized Array,
+ // then the argument is meant to be the size of the object.
+ template<typename T>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init1(Index size, typename internal::enable_if< (Base::SizeAtCompileTime!=1 || !internal::is_convertible<T, Scalar>::value)
+ && ((!internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value || Base::SizeAtCompileTime==Dynamic)),T>::type* = 0)
+ {
+ // NOTE MSVC 2008 complains if we directly put bool(NumTraits<T>::IsInteger) as the EIGEN_STATIC_ASSERT argument.
+ const bool is_integer_alike = internal::is_valid_index_type<T>::value;
+ EIGEN_UNUSED_VARIABLE(is_integer_alike);
+ EIGEN_STATIC_ASSERT(is_integer_alike,
+ FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
+ resize(size);
+ }
+
+ // We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar type can be implicitly converted)
+ template<typename T>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init1(const Scalar& val0, typename internal::enable_if<Base::SizeAtCompileTime==1 && internal::is_convertible<T, Scalar>::value,T>::type* = 0)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
+ m_storage.data()[0] = val0;
+ }
+
+ // We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar type match the index type)
+ template<typename T>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init1(const Index& val0,
+ typename internal::enable_if< (!internal::is_same<Index,Scalar>::value)
+ && (internal::is_same<Index,T>::value)
+ && Base::SizeAtCompileTime==1
+ && internal::is_convertible<T, Scalar>::value,T*>::type* = 0)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
+ m_storage.data()[0] = Scalar(val0);
+ }
+
+ // Initialize a fixed size matrix from a pointer to raw data
+ template<typename T>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init1(const Scalar* data){
+ this->_set_noalias(ConstMapType(data));
+ }
+
+ // Initialize an arbitrary matrix from a dense expression
+ template<typename T, typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init1(const DenseBase<OtherDerived>& other){
+ this->_set_noalias(other);
+ }
+
+ // Initialize an arbitrary matrix from an object convertible to the Derived type.
+ template<typename T>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init1(const Derived& other){
+ this->_set_noalias(other);
+ }
+
+ // Initialize an arbitrary matrix from a generic Eigen expression
+ template<typename T, typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init1(const EigenBase<OtherDerived>& other){
+ this->derived() = other;
+ }
+
+ template<typename T, typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init1(const ReturnByValue<OtherDerived>& other)
+ {
+ resize(other.rows(), other.cols());
+ other.evalTo(this->derived());
+ }
+
+ template<typename T, typename OtherDerived, int ColsAtCompileTime>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init1(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
+ {
+ this->derived() = r;
+ }
+
+ // For fixed-size Array<Scalar,...>
+ template<typename T>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init1(const Scalar& val0,
+ typename internal::enable_if< Base::SizeAtCompileTime!=Dynamic
+ && Base::SizeAtCompileTime!=1
+ && internal::is_convertible<T, Scalar>::value
+ && internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T>::type* = 0)
+ {
+ Base::setConstant(val0);
+ }
+
+ // For fixed-size Array<Index,...>
+ template<typename T>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _init1(const Index& val0,
+ typename internal::enable_if< (!internal::is_same<Index,Scalar>::value)
+ && (internal::is_same<Index,T>::value)
+ && Base::SizeAtCompileTime!=Dynamic
+ && Base::SizeAtCompileTime!=1
+ && internal::is_convertible<T, Scalar>::value
+ && internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T*>::type* = 0)
+ {
+ Base::setConstant(val0);
+ }
+
+ template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers>
+ friend struct internal::matrix_swap_impl;
+
+ public:
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ /** \internal
+ * \brief Override DenseBase::swap() since for dynamic-sized matrices
+ * of same type it is enough to swap the data pointers.
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void swap(DenseBase<OtherDerived> & other)
+ {
+ enum { SwapPointers = internal::is_same<Derived, OtherDerived>::value && Base::SizeAtCompileTime==Dynamic };
+ internal::matrix_swap_impl<Derived, OtherDerived, bool(SwapPointers)>::run(this->derived(), other.derived());
+ }
+
+ /** \internal
+ * \brief const version forwarded to DenseBase::swap
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void swap(DenseBase<OtherDerived> const & other)
+ { Base::swap(other.derived()); }
+
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE void _check_template_params()
+ {
+ EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, (int(Options)&RowMajor)==RowMajor)
+ && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, (int(Options)&RowMajor)==0)
+ && ((RowsAtCompileTime == Dynamic) || (RowsAtCompileTime >= 0))
+ && ((ColsAtCompileTime == Dynamic) || (ColsAtCompileTime >= 0))
+ && ((MaxRowsAtCompileTime == Dynamic) || (MaxRowsAtCompileTime >= 0))
+ && ((MaxColsAtCompileTime == Dynamic) || (MaxColsAtCompileTime >= 0))
+ && (MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime==Dynamic)
+ && (MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime==Dynamic)
+ && (Options & (DontAlign|RowMajor)) == Options),
+ INVALID_MATRIX_TEMPLATE_PARAMETERS)
+ }
+
+ enum { IsPlainObjectBase = 1 };
+#endif
+ public:
+ // These apparently need to be down here for nvcc+icc to prevent duplicate
+ // Map symbol.
+ template<typename PlainObjectType, int MapOptions, typename StrideType> friend class Eigen::Map;
+ friend class Eigen::Map<Derived, Unaligned>;
+ friend class Eigen::Map<const Derived, Unaligned>;
+#if EIGEN_MAX_ALIGN_BYTES>0
+ // for EIGEN_MAX_ALIGN_BYTES==0, AlignedMax==Unaligned, and many compilers generate warnings for friend-ing a class twice.
+ friend class Eigen::Map<Derived, AlignedMax>;
+ friend class Eigen::Map<const Derived, AlignedMax>;
+#endif
+};
+
+namespace internal {
+
+template <typename Derived, typename OtherDerived, bool IsVector>
+struct conservative_resize_like_impl
+{
+ #if EIGEN_HAS_TYPE_TRAITS
+ static const bool IsRelocatable = std::is_trivially_copyable<typename Derived::Scalar>::value;
+ #else
+ static const bool IsRelocatable = !NumTraits<typename Derived::Scalar>::RequireInitialization;
+ #endif
+ static void run(DenseBase<Derived>& _this, Index rows, Index cols)
+ {
+ if (_this.rows() == rows && _this.cols() == cols) return;
+ EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
+
+ if ( IsRelocatable
+ && (( Derived::IsRowMajor && _this.cols() == cols) || // row-major and we change only the number of rows
+ (!Derived::IsRowMajor && _this.rows() == rows) )) // column-major and we change only the number of columns
+ {
+ internal::check_rows_cols_for_overflow<Derived::MaxSizeAtCompileTime>::run(rows, cols);
+ _this.derived().m_storage.conservativeResize(rows*cols,rows,cols);
+ }
+ else
+ {
+ // The storage order does not allow us to use reallocation.
+ Derived tmp(rows,cols);
+ const Index common_rows = numext::mini(rows, _this.rows());
+ const Index common_cols = numext::mini(cols, _this.cols());
+ tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols);
+ _this.derived().swap(tmp);
+ }
+ }
+
+ static void run(DenseBase<Derived>& _this, const DenseBase<OtherDerived>& other)
+ {
+ if (_this.rows() == other.rows() && _this.cols() == other.cols()) return;
+
+ // Note: Here is space for improvement. Basically, for conservativeResize(Index,Index),
+ // neither RowsAtCompileTime or ColsAtCompileTime must be Dynamic. If only one of the
+ // dimensions is dynamic, one could use either conservativeResize(Index rows, NoChange_t) or
+ // conservativeResize(NoChange_t, Index cols). For these methods new static asserts like
+ // EIGEN_STATIC_ASSERT_DYNAMIC_ROWS and EIGEN_STATIC_ASSERT_DYNAMIC_COLS would be good.
+ EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
+ EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(OtherDerived)
+
+ if ( IsRelocatable &&
+ (( Derived::IsRowMajor && _this.cols() == other.cols()) || // row-major and we change only the number of rows
+ (!Derived::IsRowMajor && _this.rows() == other.rows()) )) // column-major and we change only the number of columns
+ {
+ const Index new_rows = other.rows() - _this.rows();
+ const Index new_cols = other.cols() - _this.cols();
+ _this.derived().m_storage.conservativeResize(other.size(),other.rows(),other.cols());
+ if (new_rows>0)
+ _this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows);
+ else if (new_cols>0)
+ _this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_cols);
+ }
+ else
+ {
+ // The storage order does not allow us to use reallocation.
+ Derived tmp(other);
+ const Index common_rows = numext::mini(tmp.rows(), _this.rows());
+ const Index common_cols = numext::mini(tmp.cols(), _this.cols());
+ tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols);
+ _this.derived().swap(tmp);
+ }
+ }
+};
+
+// Here, the specialization for vectors inherits from the general matrix case
+// to allow calling .conservativeResize(rows,cols) on vectors.
+template <typename Derived, typename OtherDerived>
+struct conservative_resize_like_impl<Derived,OtherDerived,true>
+ : conservative_resize_like_impl<Derived,OtherDerived,false>
+{
+ typedef conservative_resize_like_impl<Derived,OtherDerived,false> Base;
+ using Base::run;
+ using Base::IsRelocatable;
+
+ static void run(DenseBase<Derived>& _this, Index size)
+ {
+ const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : size;
+ const Index new_cols = Derived::RowsAtCompileTime==1 ? size : 1;
+ if(IsRelocatable)
+ _this.derived().m_storage.conservativeResize(size,new_rows,new_cols);
+ else
+ Base::run(_this.derived(), new_rows, new_cols);
+ }
+
+ static void run(DenseBase<Derived>& _this, const DenseBase<OtherDerived>& other)
+ {
+ if (_this.rows() == other.rows() && _this.cols() == other.cols()) return;
+
+ const Index num_new_elements = other.size() - _this.size();
+
+ const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : other.rows();
+ const Index new_cols = Derived::RowsAtCompileTime==1 ? other.cols() : 1;
+ if(IsRelocatable)
+ _this.derived().m_storage.conservativeResize(other.size(),new_rows,new_cols);
+ else
+ Base::run(_this.derived(), new_rows, new_cols);
+
+ if (num_new_elements > 0)
+ _this.tail(num_new_elements) = other.tail(num_new_elements);
+ }
+};
+
+template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers>
+struct matrix_swap_impl
+{
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE void run(MatrixTypeA& a, MatrixTypeB& b)
+ {
+ a.base().swap(b);
+ }
+};
+
+template<typename MatrixTypeA, typename MatrixTypeB>
+struct matrix_swap_impl<MatrixTypeA, MatrixTypeB, true>
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(MatrixTypeA& a, MatrixTypeB& b)
+ {
+ static_cast<typename MatrixTypeA::Base&>(a).m_storage.swap(static_cast<typename MatrixTypeB::Base&>(b).m_storage);
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_DENSESTORAGEBASE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Product.h b/src/3rdparty/eigen/Eigen/src/Core/Product.h
new file mode 100644
index 000000000..70a6c1063
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Product.h
@@ -0,0 +1,191 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PRODUCT_H
+#define EIGEN_PRODUCT_H
+
+namespace Eigen {
+
+template<typename Lhs, typename Rhs, int Option, typename StorageKind> class ProductImpl;
+
+namespace internal {
+
+template<typename Lhs, typename Rhs, int Option>
+struct traits<Product<Lhs, Rhs, Option> >
+{
+ typedef typename remove_all<Lhs>::type LhsCleaned;
+ typedef typename remove_all<Rhs>::type RhsCleaned;
+ typedef traits<LhsCleaned> LhsTraits;
+ typedef traits<RhsCleaned> RhsTraits;
+
+ typedef MatrixXpr XprKind;
+
+ typedef typename ScalarBinaryOpTraits<typename traits<LhsCleaned>::Scalar, typename traits<RhsCleaned>::Scalar>::ReturnType Scalar;
+ typedef typename product_promote_storage_type<typename LhsTraits::StorageKind,
+ typename RhsTraits::StorageKind,
+ internal::product_type<Lhs,Rhs>::ret>::ret StorageKind;
+ typedef typename promote_index_type<typename LhsTraits::StorageIndex,
+ typename RhsTraits::StorageIndex>::type StorageIndex;
+
+ enum {
+ RowsAtCompileTime = LhsTraits::RowsAtCompileTime,
+ ColsAtCompileTime = RhsTraits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = LhsTraits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = RhsTraits::MaxColsAtCompileTime,
+
+ // FIXME: only needed by GeneralMatrixMatrixTriangular
+ InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(LhsTraits::ColsAtCompileTime, RhsTraits::RowsAtCompileTime),
+
+ // The storage order is somewhat arbitrary here. The correct one will be determined through the evaluator.
+ Flags = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? RowMajorBit
+ : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
+ : ( ((LhsTraits::Flags&NoPreferredStorageOrderBit) && (RhsTraits::Flags&RowMajorBit))
+ || ((RhsTraits::Flags&NoPreferredStorageOrderBit) && (LhsTraits::Flags&RowMajorBit)) ) ? RowMajorBit
+ : NoPreferredStorageOrderBit
+ };
+};
+
+} // end namespace internal
+
+/** \class Product
+ * \ingroup Core_Module
+ *
+ * \brief Expression of the product of two arbitrary matrices or vectors
+ *
+ * \tparam _Lhs the type of the left-hand side expression
+ * \tparam _Rhs the type of the right-hand side expression
+ *
+ * This class represents an expression of the product of two arbitrary matrices.
+ *
+ * The other template parameters are:
+ * \tparam Option can be DefaultProduct, AliasFreeProduct, or LazyProduct
+ *
+ */
+template<typename _Lhs, typename _Rhs, int Option>
+class Product : public ProductImpl<_Lhs,_Rhs,Option,
+ typename internal::product_promote_storage_type<typename internal::traits<_Lhs>::StorageKind,
+ typename internal::traits<_Rhs>::StorageKind,
+ internal::product_type<_Lhs,_Rhs>::ret>::ret>
+{
+ public:
+
+ typedef _Lhs Lhs;
+ typedef _Rhs Rhs;
+
+ typedef typename ProductImpl<
+ Lhs, Rhs, Option,
+ typename internal::product_promote_storage_type<typename internal::traits<Lhs>::StorageKind,
+ typename internal::traits<Rhs>::StorageKind,
+ internal::product_type<Lhs,Rhs>::ret>::ret>::Base Base;
+ EIGEN_GENERIC_PUBLIC_INTERFACE(Product)
+
+ typedef typename internal::ref_selector<Lhs>::type LhsNested;
+ typedef typename internal::ref_selector<Rhs>::type RhsNested;
+ typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
+ typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Product(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs)
+ {
+ eigen_assert(lhs.cols() == rhs.rows()
+ && "invalid matrix product"
+ && "if you wanted a coeff-wise or a dot product use the respective explicit functions");
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index rows() const EIGEN_NOEXCEPT { return m_lhs.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const LhsNestedCleaned& lhs() const { return m_lhs; }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const RhsNestedCleaned& rhs() const { return m_rhs; }
+
+ protected:
+
+ LhsNested m_lhs;
+ RhsNested m_rhs;
+};
+
+namespace internal {
+
+template<typename Lhs, typename Rhs, int Option, int ProductTag = internal::product_type<Lhs,Rhs>::ret>
+class dense_product_base
+ : public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
+{};
+
+/** Conversion to scalar for inner-products */
+template<typename Lhs, typename Rhs, int Option>
+class dense_product_base<Lhs, Rhs, Option, InnerProduct>
+ : public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
+{
+ typedef Product<Lhs,Rhs,Option> ProductXpr;
+ typedef typename internal::dense_xpr_base<ProductXpr>::type Base;
+public:
+ using Base::derived;
+ typedef typename Base::Scalar Scalar;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator const Scalar() const
+ {
+ return internal::evaluator<ProductXpr>(derived()).coeff(0,0);
+ }
+};
+
+} // namespace internal
+
+// Generic API dispatcher
+template<typename Lhs, typename Rhs, int Option, typename StorageKind>
+class ProductImpl : public internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type
+{
+ public:
+ typedef typename internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type Base;
+};
+
+template<typename Lhs, typename Rhs, int Option>
+class ProductImpl<Lhs,Rhs,Option,Dense>
+ : public internal::dense_product_base<Lhs,Rhs,Option>
+{
+ typedef Product<Lhs, Rhs, Option> Derived;
+
+ public:
+
+ typedef typename internal::dense_product_base<Lhs, Rhs, Option> Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
+ protected:
+ enum {
+ IsOneByOne = (RowsAtCompileTime == 1 || RowsAtCompileTime == Dynamic) &&
+ (ColsAtCompileTime == 1 || ColsAtCompileTime == Dynamic),
+ EnableCoeff = IsOneByOne || Option==LazyProduct
+ };
+
+ public:
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index row, Index col) const
+ {
+ EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
+ eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
+
+ return internal::evaluator<Derived>(derived()).coeff(row,col);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index i) const
+ {
+ EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
+ eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
+
+ return internal::evaluator<Derived>(derived()).coeff(i);
+ }
+
+
+};
+
+} // end namespace Eigen
+
+#endif // EIGEN_PRODUCT_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/ProductEvaluators.h b/src/3rdparty/eigen/Eigen/src/Core/ProductEvaluators.h
new file mode 100644
index 000000000..8cf294b28
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/ProductEvaluators.h
@@ -0,0 +1,1179 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2011 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#ifndef EIGEN_PRODUCTEVALUATORS_H
+#define EIGEN_PRODUCTEVALUATORS_H
+
+namespace Eigen {
+
+namespace internal {
+
+/** \internal
+ * Evaluator of a product expression.
+ * Since products require special treatments to handle all possible cases,
+ * we simply defer the evaluation logic to a product_evaluator class
+ * which offers more partial specialization possibilities.
+ *
+ * \sa class product_evaluator
+ */
+template<typename Lhs, typename Rhs, int Options>
+struct evaluator<Product<Lhs, Rhs, Options> >
+ : public product_evaluator<Product<Lhs, Rhs, Options> >
+{
+ typedef Product<Lhs, Rhs, Options> XprType;
+ typedef product_evaluator<XprType> Base;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr) : Base(xpr) {}
+};
+
+// Catch "scalar * ( A * B )" and transform it to "(A*scalar) * B"
+// TODO we should apply that rule only if that's really helpful
+template<typename Lhs, typename Rhs, typename Scalar1, typename Scalar2, typename Plain1>
+struct evaluator_assume_aliasing<CwiseBinaryOp<internal::scalar_product_op<Scalar1,Scalar2>,
+ const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>,
+ const Product<Lhs, Rhs, DefaultProduct> > >
+{
+ static const bool value = true;
+};
+template<typename Lhs, typename Rhs, typename Scalar1, typename Scalar2, typename Plain1>
+struct evaluator<CwiseBinaryOp<internal::scalar_product_op<Scalar1,Scalar2>,
+ const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>,
+ const Product<Lhs, Rhs, DefaultProduct> > >
+ : public evaluator<Product<EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar1,Lhs,product), Rhs, DefaultProduct> >
+{
+ typedef CwiseBinaryOp<internal::scalar_product_op<Scalar1,Scalar2>,
+ const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>,
+ const Product<Lhs, Rhs, DefaultProduct> > XprType;
+ typedef evaluator<Product<EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar1,Lhs,product), Rhs, DefaultProduct> > Base;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr)
+ : Base(xpr.lhs().functor().m_other * xpr.rhs().lhs() * xpr.rhs().rhs())
+ {}
+};
+
+
+template<typename Lhs, typename Rhs, int DiagIndex>
+struct evaluator<Diagonal<const Product<Lhs, Rhs, DefaultProduct>, DiagIndex> >
+ : public evaluator<Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex> >
+{
+ typedef Diagonal<const Product<Lhs, Rhs, DefaultProduct>, DiagIndex> XprType;
+ typedef evaluator<Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex> > Base;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr)
+ : Base(Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex>(
+ Product<Lhs, Rhs, LazyProduct>(xpr.nestedExpression().lhs(), xpr.nestedExpression().rhs()),
+ xpr.index() ))
+ {}
+};
+
+
+// Helper class to perform a matrix product with the destination at hand.
+// Depending on the sizes of the factors, there are different evaluation strategies
+// as controlled by internal::product_type.
+template< typename Lhs, typename Rhs,
+ typename LhsShape = typename evaluator_traits<Lhs>::Shape,
+ typename RhsShape = typename evaluator_traits<Rhs>::Shape,
+ int ProductType = internal::product_type<Lhs,Rhs>::value>
+struct generic_product_impl;
+
+template<typename Lhs, typename Rhs>
+struct evaluator_assume_aliasing<Product<Lhs, Rhs, DefaultProduct> > {
+ static const bool value = true;
+};
+
+// This is the default evaluator implementation for products:
+// It creates a temporary and call generic_product_impl
+template<typename Lhs, typename Rhs, int Options, int ProductTag, typename LhsShape, typename RhsShape>
+struct product_evaluator<Product<Lhs, Rhs, Options>, ProductTag, LhsShape, RhsShape>
+ : public evaluator<typename Product<Lhs, Rhs, Options>::PlainObject>
+{
+ typedef Product<Lhs, Rhs, Options> XprType;
+ typedef typename XprType::PlainObject PlainObject;
+ typedef evaluator<PlainObject> Base;
+ enum {
+ Flags = Base::Flags | EvalBeforeNestingBit
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit product_evaluator(const XprType& xpr)
+ : m_result(xpr.rows(), xpr.cols())
+ {
+ ::new (static_cast<Base*>(this)) Base(m_result);
+
+// FIXME shall we handle nested_eval here?,
+// if so, then we must take care at removing the call to nested_eval in the specializations (e.g., in permutation_matrix_product, transposition_matrix_product, etc.)
+// typedef typename internal::nested_eval<Lhs,Rhs::ColsAtCompileTime>::type LhsNested;
+// typedef typename internal::nested_eval<Rhs,Lhs::RowsAtCompileTime>::type RhsNested;
+// typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
+// typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
+//
+// const LhsNested lhs(xpr.lhs());
+// const RhsNested rhs(xpr.rhs());
+//
+// generic_product_impl<LhsNestedCleaned, RhsNestedCleaned>::evalTo(m_result, lhs, rhs);
+
+ generic_product_impl<Lhs, Rhs, LhsShape, RhsShape, ProductTag>::evalTo(m_result, xpr.lhs(), xpr.rhs());
+ }
+
+protected:
+ PlainObject m_result;
+};
+
+// The following three shortcuts are enabled only if the scalar types match exactly.
+// TODO: we could enable them for different scalar types when the product is not vectorized.
+
+// Dense = Product
+template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar>
+struct Assignment<DstXprType, Product<Lhs,Rhs,Options>, internal::assign_op<Scalar,Scalar>, Dense2Dense,
+ typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
+{
+ typedef Product<Lhs,Rhs,Options> SrcXprType;
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+ // FIXME shall we handle nested_eval here?
+ generic_product_impl<Lhs, Rhs>::evalTo(dst, src.lhs(), src.rhs());
+ }
+};
+
+// Dense += Product
+template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar>
+struct Assignment<DstXprType, Product<Lhs,Rhs,Options>, internal::add_assign_op<Scalar,Scalar>, Dense2Dense,
+ typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
+{
+ typedef Product<Lhs,Rhs,Options> SrcXprType;
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<Scalar,Scalar> &)
+ {
+ eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
+ // FIXME shall we handle nested_eval here?
+ generic_product_impl<Lhs, Rhs>::addTo(dst, src.lhs(), src.rhs());
+ }
+};
+
+// Dense -= Product
+template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar>
+struct Assignment<DstXprType, Product<Lhs,Rhs,Options>, internal::sub_assign_op<Scalar,Scalar>, Dense2Dense,
+ typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
+{
+ typedef Product<Lhs,Rhs,Options> SrcXprType;
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<Scalar,Scalar> &)
+ {
+ eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
+ // FIXME shall we handle nested_eval here?
+ generic_product_impl<Lhs, Rhs>::subTo(dst, src.lhs(), src.rhs());
+ }
+};
+
+
+// Dense ?= scalar * Product
+// TODO we should apply that rule if that's really helpful
+// for instance, this is not good for inner products
+template< typename DstXprType, typename Lhs, typename Rhs, typename AssignFunc, typename Scalar, typename ScalarBis, typename Plain>
+struct Assignment<DstXprType, CwiseBinaryOp<internal::scalar_product_op<ScalarBis,Scalar>, const CwiseNullaryOp<internal::scalar_constant_op<ScalarBis>,Plain>,
+ const Product<Lhs,Rhs,DefaultProduct> >, AssignFunc, Dense2Dense>
+{
+ typedef CwiseBinaryOp<internal::scalar_product_op<ScalarBis,Scalar>,
+ const CwiseNullaryOp<internal::scalar_constant_op<ScalarBis>,Plain>,
+ const Product<Lhs,Rhs,DefaultProduct> > SrcXprType;
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void run(DstXprType &dst, const SrcXprType &src, const AssignFunc& func)
+ {
+ call_assignment_no_alias(dst, (src.lhs().functor().m_other * src.rhs().lhs())*src.rhs().rhs(), func);
+ }
+};
+
+//----------------------------------------
+// Catch "Dense ?= xpr + Product<>" expression to save one temporary
+// FIXME we could probably enable these rules for any product, i.e., not only Dense and DefaultProduct
+
+template<typename OtherXpr, typename Lhs, typename Rhs>
+struct evaluator_assume_aliasing<CwiseBinaryOp<internal::scalar_sum_op<typename OtherXpr::Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, const OtherXpr,
+ const Product<Lhs,Rhs,DefaultProduct> >, DenseShape > {
+ static const bool value = true;
+};
+
+template<typename OtherXpr, typename Lhs, typename Rhs>
+struct evaluator_assume_aliasing<CwiseBinaryOp<internal::scalar_difference_op<typename OtherXpr::Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, const OtherXpr,
+ const Product<Lhs,Rhs,DefaultProduct> >, DenseShape > {
+ static const bool value = true;
+};
+
+template<typename DstXprType, typename OtherXpr, typename ProductType, typename Func1, typename Func2>
+struct assignment_from_xpr_op_product
+{
+ template<typename SrcXprType, typename InitialFunc>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void run(DstXprType &dst, const SrcXprType &src, const InitialFunc& /*func*/)
+ {
+ call_assignment_no_alias(dst, src.lhs(), Func1());
+ call_assignment_no_alias(dst, src.rhs(), Func2());
+ }
+};
+
+#define EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(ASSIGN_OP,BINOP,ASSIGN_OP2) \
+ template< typename DstXprType, typename OtherXpr, typename Lhs, typename Rhs, typename DstScalar, typename SrcScalar, typename OtherScalar,typename ProdScalar> \
+ struct Assignment<DstXprType, CwiseBinaryOp<internal::BINOP<OtherScalar,ProdScalar>, const OtherXpr, \
+ const Product<Lhs,Rhs,DefaultProduct> >, internal::ASSIGN_OP<DstScalar,SrcScalar>, Dense2Dense> \
+ : assignment_from_xpr_op_product<DstXprType, OtherXpr, Product<Lhs,Rhs,DefaultProduct>, internal::ASSIGN_OP<DstScalar,OtherScalar>, internal::ASSIGN_OP2<DstScalar,ProdScalar> > \
+ {}
+
+EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(assign_op, scalar_sum_op,add_assign_op);
+EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(add_assign_op,scalar_sum_op,add_assign_op);
+EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(sub_assign_op,scalar_sum_op,sub_assign_op);
+
+EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(assign_op, scalar_difference_op,sub_assign_op);
+EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(add_assign_op,scalar_difference_op,sub_assign_op);
+EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(sub_assign_op,scalar_difference_op,add_assign_op);
+
+//----------------------------------------
+
+template<typename Lhs, typename Rhs>
+struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,InnerProduct>
+{
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ dst.coeffRef(0,0) = (lhs.transpose().cwiseProduct(rhs)).sum();
+ }
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ dst.coeffRef(0,0) += (lhs.transpose().cwiseProduct(rhs)).sum();
+ }
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ { dst.coeffRef(0,0) -= (lhs.transpose().cwiseProduct(rhs)).sum(); }
+};
+
+
+/***********************************************************************
+* Implementation of outer dense * dense vector product
+***********************************************************************/
+
+// Column major result
+template<typename Dst, typename Lhs, typename Rhs, typename Func>
+void EIGEN_DEVICE_FUNC outer_product_selector_run(Dst& dst, const Lhs &lhs, const Rhs &rhs, const Func& func, const false_type&)
+{
+ evaluator<Rhs> rhsEval(rhs);
+ ei_declare_local_nested_eval(Lhs,lhs,Rhs::SizeAtCompileTime,actual_lhs);
+ // FIXME if cols is large enough, then it might be useful to make sure that lhs is sequentially stored
+ // FIXME not very good if rhs is real and lhs complex while alpha is real too
+ const Index cols = dst.cols();
+ for (Index j=0; j<cols; ++j)
+ func(dst.col(j), rhsEval.coeff(Index(0),j) * actual_lhs);
+}
+
+// Row major result
+template<typename Dst, typename Lhs, typename Rhs, typename Func>
+void EIGEN_DEVICE_FUNC outer_product_selector_run(Dst& dst, const Lhs &lhs, const Rhs &rhs, const Func& func, const true_type&)
+{
+ evaluator<Lhs> lhsEval(lhs);
+ ei_declare_local_nested_eval(Rhs,rhs,Lhs::SizeAtCompileTime,actual_rhs);
+ // FIXME if rows is large enough, then it might be useful to make sure that rhs is sequentially stored
+ // FIXME not very good if lhs is real and rhs complex while alpha is real too
+ const Index rows = dst.rows();
+ for (Index i=0; i<rows; ++i)
+ func(dst.row(i), lhsEval.coeff(i,Index(0)) * actual_rhs);
+}
+
+template<typename Lhs, typename Rhs>
+struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,OuterProduct>
+{
+ template<typename T> struct is_row_major : internal::conditional<(int(T::Flags)&RowMajorBit), internal::true_type, internal::false_type>::type {};
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+
+ // TODO it would be nice to be able to exploit our *_assign_op functors for that purpose
+ struct set { template<typename Dst, typename Src> EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { dst.const_cast_derived() = src; } };
+ struct add { template<typename Dst, typename Src> EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { dst.const_cast_derived() += src; } };
+ struct sub { template<typename Dst, typename Src> EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { dst.const_cast_derived() -= src; } };
+ struct adds {
+ Scalar m_scale;
+ explicit adds(const Scalar& s) : m_scale(s) {}
+ template<typename Dst, typename Src> void EIGEN_DEVICE_FUNC operator()(const Dst& dst, const Src& src) const {
+ dst.const_cast_derived() += m_scale * src;
+ }
+ };
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ internal::outer_product_selector_run(dst, lhs, rhs, set(), is_row_major<Dst>());
+ }
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ internal::outer_product_selector_run(dst, lhs, rhs, add(), is_row_major<Dst>());
+ }
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ internal::outer_product_selector_run(dst, lhs, rhs, sub(), is_row_major<Dst>());
+ }
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
+ {
+ internal::outer_product_selector_run(dst, lhs, rhs, adds(alpha), is_row_major<Dst>());
+ }
+
+};
+
+
+// This base class provides default implementations for evalTo, addTo, subTo, in terms of scaleAndAddTo
+template<typename Lhs, typename Rhs, typename Derived>
+struct generic_product_impl_base
+{
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ { dst.setZero(); scaleAndAddTo(dst, lhs, rhs, Scalar(1)); }
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ { scaleAndAddTo(dst,lhs, rhs, Scalar(1)); }
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ { scaleAndAddTo(dst, lhs, rhs, Scalar(-1)); }
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
+ { Derived::scaleAndAddTo(dst,lhs,rhs,alpha); }
+
+};
+
+template<typename Lhs, typename Rhs>
+struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemvProduct>
+ : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemvProduct> >
+{
+ typedef typename nested_eval<Lhs,1>::type LhsNested;
+ typedef typename nested_eval<Rhs,1>::type RhsNested;
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+ enum { Side = Lhs::IsVectorAtCompileTime ? OnTheLeft : OnTheRight };
+ typedef typename internal::remove_all<typename internal::conditional<int(Side)==OnTheRight,LhsNested,RhsNested>::type>::type MatrixType;
+
+ template<typename Dest>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
+ {
+ // Fallback to inner product if both the lhs and rhs is a runtime vector.
+ if (lhs.rows() == 1 && rhs.cols() == 1) {
+ dst.coeffRef(0,0) += alpha * lhs.row(0).conjugate().dot(rhs.col(0));
+ return;
+ }
+ LhsNested actual_lhs(lhs);
+ RhsNested actual_rhs(rhs);
+ internal::gemv_dense_selector<Side,
+ (int(MatrixType::Flags)&RowMajorBit) ? RowMajor : ColMajor,
+ bool(internal::blas_traits<MatrixType>::HasUsableDirectAccess)
+ >::run(actual_lhs, actual_rhs, dst, alpha);
+ }
+};
+
+template<typename Lhs, typename Rhs>
+struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,CoeffBasedProductMode>
+{
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ // Same as: dst.noalias() = lhs.lazyProduct(rhs);
+ // but easier on the compiler side
+ call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::assign_op<typename Dst::Scalar,Scalar>());
+ }
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ // dst.noalias() += lhs.lazyProduct(rhs);
+ call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::add_assign_op<typename Dst::Scalar,Scalar>());
+ }
+
+ template<typename Dst>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ // dst.noalias() -= lhs.lazyProduct(rhs);
+ call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::sub_assign_op<typename Dst::Scalar,Scalar>());
+ }
+
+ // This is a special evaluation path called from generic_product_impl<...,GemmProduct> in file GeneralMatrixMatrix.h
+ // This variant tries to extract scalar multiples from both the LHS and RHS and factor them out. For instance:
+ // dst {,+,-}= (s1*A)*(B*s2)
+ // will be rewritten as:
+ // dst {,+,-}= (s1*s2) * (A.lazyProduct(B))
+ // There are at least four benefits of doing so:
+ // 1 - huge performance gain for heap-allocated matrix types as it save costly allocations.
+ // 2 - it is faster than simply by-passing the heap allocation through stack allocation.
+ // 3 - it makes this fallback consistent with the heavy GEMM routine.
+ // 4 - it fully by-passes huge stack allocation attempts when multiplying huge fixed-size matrices.
+ // (see https://stackoverflow.com/questions/54738495)
+ // For small fixed sizes matrices, howver, the gains are less obvious, it is sometimes x2 faster, but sometimes x3 slower,
+ // and the behavior depends also a lot on the compiler... This is why this re-writting strategy is currently
+ // enabled only when falling back from the main GEMM.
+ template<typename Dst, typename Func>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void eval_dynamic(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Func &func)
+ {
+ enum {
+ HasScalarFactor = blas_traits<Lhs>::HasScalarFactor || blas_traits<Rhs>::HasScalarFactor,
+ ConjLhs = blas_traits<Lhs>::NeedToConjugate,
+ ConjRhs = blas_traits<Rhs>::NeedToConjugate
+ };
+ // FIXME: in c++11 this should be auto, and extractScalarFactor should also return auto
+ // this is important for real*complex_mat
+ Scalar actualAlpha = combine_scalar_factors<Scalar>(lhs, rhs);
+
+ eval_dynamic_impl(dst,
+ blas_traits<Lhs>::extract(lhs).template conjugateIf<ConjLhs>(),
+ blas_traits<Rhs>::extract(rhs).template conjugateIf<ConjRhs>(),
+ func,
+ actualAlpha,
+ typename conditional<HasScalarFactor,true_type,false_type>::type());
+ }
+
+protected:
+
+ template<typename Dst, typename LhsT, typename RhsT, typename Func, typename Scalar>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void eval_dynamic_impl(Dst& dst, const LhsT& lhs, const RhsT& rhs, const Func &func, const Scalar& s /* == 1 */, false_type)
+ {
+ EIGEN_UNUSED_VARIABLE(s);
+ eigen_internal_assert(s==Scalar(1));
+ call_restricted_packet_assignment_no_alias(dst, lhs.lazyProduct(rhs), func);
+ }
+
+ template<typename Dst, typename LhsT, typename RhsT, typename Func, typename Scalar>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void eval_dynamic_impl(Dst& dst, const LhsT& lhs, const RhsT& rhs, const Func &func, const Scalar& s, true_type)
+ {
+ call_restricted_packet_assignment_no_alias(dst, s * lhs.lazyProduct(rhs), func);
+ }
+};
+
+// This specialization enforces the use of a coefficient-based evaluation strategy
+template<typename Lhs, typename Rhs>
+struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,LazyCoeffBasedProductMode>
+ : generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,CoeffBasedProductMode> {};
+
+// Case 2: Evaluate coeff by coeff
+//
+// This is mostly taken from CoeffBasedProduct.h
+// The main difference is that we add an extra argument to the etor_product_*_impl::run() function
+// for the inner dimension of the product, because evaluator object do not know their size.
+
+template<int Traversal, int UnrollingIndex, typename Lhs, typename Rhs, typename RetScalar>
+struct etor_product_coeff_impl;
+
+template<int StorageOrder, int UnrollingIndex, typename Lhs, typename Rhs, typename Packet, int LoadMode>
+struct etor_product_packet_impl;
+
+template<typename Lhs, typename Rhs, int ProductTag>
+struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, DenseShape>
+ : evaluator_base<Product<Lhs, Rhs, LazyProduct> >
+{
+ typedef Product<Lhs, Rhs, LazyProduct> XprType;
+ typedef typename XprType::Scalar Scalar;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit product_evaluator(const XprType& xpr)
+ : m_lhs(xpr.lhs()),
+ m_rhs(xpr.rhs()),
+ m_lhsImpl(m_lhs), // FIXME the creation of the evaluator objects should result in a no-op, but check that!
+ m_rhsImpl(m_rhs), // Moreover, they are only useful for the packet path, so we could completely disable them when not needed,
+ // or perhaps declare them on the fly on the packet method... We have experiment to check what's best.
+ m_innerDim(xpr.lhs().cols())
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::MulCost);
+ EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::AddCost);
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+#if 0
+ std::cerr << "LhsOuterStrideBytes= " << LhsOuterStrideBytes << "\n";
+ std::cerr << "RhsOuterStrideBytes= " << RhsOuterStrideBytes << "\n";
+ std::cerr << "LhsAlignment= " << LhsAlignment << "\n";
+ std::cerr << "RhsAlignment= " << RhsAlignment << "\n";
+ std::cerr << "CanVectorizeLhs= " << CanVectorizeLhs << "\n";
+ std::cerr << "CanVectorizeRhs= " << CanVectorizeRhs << "\n";
+ std::cerr << "CanVectorizeInner= " << CanVectorizeInner << "\n";
+ std::cerr << "EvalToRowMajor= " << EvalToRowMajor << "\n";
+ std::cerr << "Alignment= " << Alignment << "\n";
+ std::cerr << "Flags= " << Flags << "\n";
+#endif
+ }
+
+ // Everything below here is taken from CoeffBasedProduct.h
+
+ typedef typename internal::nested_eval<Lhs,Rhs::ColsAtCompileTime>::type LhsNested;
+ typedef typename internal::nested_eval<Rhs,Lhs::RowsAtCompileTime>::type RhsNested;
+
+ typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
+ typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
+
+ typedef evaluator<LhsNestedCleaned> LhsEtorType;
+ typedef evaluator<RhsNestedCleaned> RhsEtorType;
+
+ enum {
+ RowsAtCompileTime = LhsNestedCleaned::RowsAtCompileTime,
+ ColsAtCompileTime = RhsNestedCleaned::ColsAtCompileTime,
+ InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(LhsNestedCleaned::ColsAtCompileTime, RhsNestedCleaned::RowsAtCompileTime),
+ MaxRowsAtCompileTime = LhsNestedCleaned::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = RhsNestedCleaned::MaxColsAtCompileTime
+ };
+
+ typedef typename find_best_packet<Scalar,RowsAtCompileTime>::type LhsVecPacketType;
+ typedef typename find_best_packet<Scalar,ColsAtCompileTime>::type RhsVecPacketType;
+
+ enum {
+
+ LhsCoeffReadCost = LhsEtorType::CoeffReadCost,
+ RhsCoeffReadCost = RhsEtorType::CoeffReadCost,
+ CoeffReadCost = InnerSize==0 ? NumTraits<Scalar>::ReadCost
+ : InnerSize == Dynamic ? HugeCost
+ : InnerSize * (NumTraits<Scalar>::MulCost + int(LhsCoeffReadCost) + int(RhsCoeffReadCost))
+ + (InnerSize - 1) * NumTraits<Scalar>::AddCost,
+
+ Unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT,
+
+ LhsFlags = LhsEtorType::Flags,
+ RhsFlags = RhsEtorType::Flags,
+
+ LhsRowMajor = LhsFlags & RowMajorBit,
+ RhsRowMajor = RhsFlags & RowMajorBit,
+
+ LhsVecPacketSize = unpacket_traits<LhsVecPacketType>::size,
+ RhsVecPacketSize = unpacket_traits<RhsVecPacketType>::size,
+
+ // Here, we don't care about alignment larger than the usable packet size.
+ LhsAlignment = EIGEN_PLAIN_ENUM_MIN(LhsEtorType::Alignment,LhsVecPacketSize*int(sizeof(typename LhsNestedCleaned::Scalar))),
+ RhsAlignment = EIGEN_PLAIN_ENUM_MIN(RhsEtorType::Alignment,RhsVecPacketSize*int(sizeof(typename RhsNestedCleaned::Scalar))),
+
+ SameType = is_same<typename LhsNestedCleaned::Scalar,typename RhsNestedCleaned::Scalar>::value,
+
+ CanVectorizeRhs = bool(RhsRowMajor) && (RhsFlags & PacketAccessBit) && (ColsAtCompileTime!=1),
+ CanVectorizeLhs = (!LhsRowMajor) && (LhsFlags & PacketAccessBit) && (RowsAtCompileTime!=1),
+
+ EvalToRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
+ : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
+ : (bool(RhsRowMajor) && !CanVectorizeLhs),
+
+ Flags = ((int(LhsFlags) | int(RhsFlags)) & HereditaryBits & ~RowMajorBit)
+ | (EvalToRowMajor ? RowMajorBit : 0)
+ // TODO enable vectorization for mixed types
+ | (SameType && (CanVectorizeLhs || CanVectorizeRhs) ? PacketAccessBit : 0)
+ | (XprType::IsVectorAtCompileTime ? LinearAccessBit : 0),
+
+ LhsOuterStrideBytes = int(LhsNestedCleaned::OuterStrideAtCompileTime) * int(sizeof(typename LhsNestedCleaned::Scalar)),
+ RhsOuterStrideBytes = int(RhsNestedCleaned::OuterStrideAtCompileTime) * int(sizeof(typename RhsNestedCleaned::Scalar)),
+
+ Alignment = bool(CanVectorizeLhs) ? (LhsOuterStrideBytes<=0 || (int(LhsOuterStrideBytes) % EIGEN_PLAIN_ENUM_MAX(1,LhsAlignment))!=0 ? 0 : LhsAlignment)
+ : bool(CanVectorizeRhs) ? (RhsOuterStrideBytes<=0 || (int(RhsOuterStrideBytes) % EIGEN_PLAIN_ENUM_MAX(1,RhsAlignment))!=0 ? 0 : RhsAlignment)
+ : 0,
+
+ /* CanVectorizeInner deserves special explanation. It does not affect the product flags. It is not used outside
+ * of Product. If the Product itself is not a packet-access expression, there is still a chance that the inner
+ * loop of the product might be vectorized. This is the meaning of CanVectorizeInner. Since it doesn't affect
+ * the Flags, it is safe to make this value depend on ActualPacketAccessBit, that doesn't affect the ABI.
+ */
+ CanVectorizeInner = SameType
+ && LhsRowMajor
+ && (!RhsRowMajor)
+ && (int(LhsFlags) & int(RhsFlags) & ActualPacketAccessBit)
+ && (int(InnerSize) % packet_traits<Scalar>::size == 0)
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index row, Index col) const
+ {
+ return (m_lhs.row(row).transpose().cwiseProduct( m_rhs.col(col) )).sum();
+ }
+
+ /* Allow index-based non-packet access. It is impossible though to allow index-based packed access,
+ * which is why we don't set the LinearAccessBit.
+ * TODO: this seems possible when the result is a vector
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const CoeffReturnType coeff(Index index) const
+ {
+ const Index row = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? 0 : index;
+ const Index col = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? index : 0;
+ return (m_lhs.row(row).transpose().cwiseProduct( m_rhs.col(col) )).sum();
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const PacketType packet(Index row, Index col) const
+ {
+ PacketType res;
+ typedef etor_product_packet_impl<bool(int(Flags)&RowMajorBit) ? RowMajor : ColMajor,
+ Unroll ? int(InnerSize) : Dynamic,
+ LhsEtorType, RhsEtorType, PacketType, LoadMode> PacketImpl;
+ PacketImpl::run(row, col, m_lhsImpl, m_rhsImpl, m_innerDim, res);
+ return res;
+ }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const PacketType packet(Index index) const
+ {
+ const Index row = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? 0 : index;
+ const Index col = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? index : 0;
+ return packet<LoadMode,PacketType>(row,col);
+ }
+
+protected:
+ typename internal::add_const_on_value_type<LhsNested>::type m_lhs;
+ typename internal::add_const_on_value_type<RhsNested>::type m_rhs;
+
+ LhsEtorType m_lhsImpl;
+ RhsEtorType m_rhsImpl;
+
+ // TODO: Get rid of m_innerDim if known at compile time
+ Index m_innerDim;
+};
+
+template<typename Lhs, typename Rhs>
+struct product_evaluator<Product<Lhs, Rhs, DefaultProduct>, LazyCoeffBasedProductMode, DenseShape, DenseShape>
+ : product_evaluator<Product<Lhs, Rhs, LazyProduct>, CoeffBasedProductMode, DenseShape, DenseShape>
+{
+ typedef Product<Lhs, Rhs, DefaultProduct> XprType;
+ typedef Product<Lhs, Rhs, LazyProduct> BaseProduct;
+ typedef product_evaluator<BaseProduct, CoeffBasedProductMode, DenseShape, DenseShape> Base;
+ enum {
+ Flags = Base::Flags | EvalBeforeNestingBit
+ };
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit product_evaluator(const XprType& xpr)
+ : Base(BaseProduct(xpr.lhs(),xpr.rhs()))
+ {}
+};
+
+/****************************************
+*** Coeff based product, Packet path ***
+****************************************/
+
+template<int UnrollingIndex, typename Lhs, typename Rhs, typename Packet, int LoadMode>
+struct etor_product_packet_impl<RowMajor, UnrollingIndex, Lhs, Rhs, Packet, LoadMode>
+{
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet &res)
+ {
+ etor_product_packet_impl<RowMajor, UnrollingIndex-1, Lhs, Rhs, Packet, LoadMode>::run(row, col, lhs, rhs, innerDim, res);
+ res = pmadd(pset1<Packet>(lhs.coeff(row, Index(UnrollingIndex-1))), rhs.template packet<LoadMode,Packet>(Index(UnrollingIndex-1), col), res);
+ }
+};
+
+template<int UnrollingIndex, typename Lhs, typename Rhs, typename Packet, int LoadMode>
+struct etor_product_packet_impl<ColMajor, UnrollingIndex, Lhs, Rhs, Packet, LoadMode>
+{
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet &res)
+ {
+ etor_product_packet_impl<ColMajor, UnrollingIndex-1, Lhs, Rhs, Packet, LoadMode>::run(row, col, lhs, rhs, innerDim, res);
+ res = pmadd(lhs.template packet<LoadMode,Packet>(row, Index(UnrollingIndex-1)), pset1<Packet>(rhs.coeff(Index(UnrollingIndex-1), col)), res);
+ }
+};
+
+template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
+struct etor_product_packet_impl<RowMajor, 1, Lhs, Rhs, Packet, LoadMode>
+{
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index /*innerDim*/, Packet &res)
+ {
+ res = pmul(pset1<Packet>(lhs.coeff(row, Index(0))),rhs.template packet<LoadMode,Packet>(Index(0), col));
+ }
+};
+
+template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
+struct etor_product_packet_impl<ColMajor, 1, Lhs, Rhs, Packet, LoadMode>
+{
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index /*innerDim*/, Packet &res)
+ {
+ res = pmul(lhs.template packet<LoadMode,Packet>(row, Index(0)), pset1<Packet>(rhs.coeff(Index(0), col)));
+ }
+};
+
+template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
+struct etor_product_packet_impl<RowMajor, 0, Lhs, Rhs, Packet, LoadMode>
+{
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index /*row*/, Index /*col*/, const Lhs& /*lhs*/, const Rhs& /*rhs*/, Index /*innerDim*/, Packet &res)
+ {
+ res = pset1<Packet>(typename unpacket_traits<Packet>::type(0));
+ }
+};
+
+template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
+struct etor_product_packet_impl<ColMajor, 0, Lhs, Rhs, Packet, LoadMode>
+{
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index /*row*/, Index /*col*/, const Lhs& /*lhs*/, const Rhs& /*rhs*/, Index /*innerDim*/, Packet &res)
+ {
+ res = pset1<Packet>(typename unpacket_traits<Packet>::type(0));
+ }
+};
+
+template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
+struct etor_product_packet_impl<RowMajor, Dynamic, Lhs, Rhs, Packet, LoadMode>
+{
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet& res)
+ {
+ res = pset1<Packet>(typename unpacket_traits<Packet>::type(0));
+ for(Index i = 0; i < innerDim; ++i)
+ res = pmadd(pset1<Packet>(lhs.coeff(row, i)), rhs.template packet<LoadMode,Packet>(i, col), res);
+ }
+};
+
+template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
+struct etor_product_packet_impl<ColMajor, Dynamic, Lhs, Rhs, Packet, LoadMode>
+{
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet& res)
+ {
+ res = pset1<Packet>(typename unpacket_traits<Packet>::type(0));
+ for(Index i = 0; i < innerDim; ++i)
+ res = pmadd(lhs.template packet<LoadMode,Packet>(row, i), pset1<Packet>(rhs.coeff(i, col)), res);
+ }
+};
+
+
+/***************************************************************************
+* Triangular products
+***************************************************************************/
+template<int Mode, bool LhsIsTriangular,
+ typename Lhs, bool LhsIsVector,
+ typename Rhs, bool RhsIsVector>
+struct triangular_product_impl;
+
+template<typename Lhs, typename Rhs, int ProductTag>
+struct generic_product_impl<Lhs,Rhs,TriangularShape,DenseShape,ProductTag>
+ : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,TriangularShape,DenseShape,ProductTag> >
+{
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+
+ template<typename Dest>
+ static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
+ {
+ triangular_product_impl<Lhs::Mode,true,typename Lhs::MatrixType,false,Rhs, Rhs::ColsAtCompileTime==1>
+ ::run(dst, lhs.nestedExpression(), rhs, alpha);
+ }
+};
+
+template<typename Lhs, typename Rhs, int ProductTag>
+struct generic_product_impl<Lhs,Rhs,DenseShape,TriangularShape,ProductTag>
+: generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,TriangularShape,ProductTag> >
+{
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+
+ template<typename Dest>
+ static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
+ {
+ triangular_product_impl<Rhs::Mode,false,Lhs,Lhs::RowsAtCompileTime==1, typename Rhs::MatrixType, false>::run(dst, lhs, rhs.nestedExpression(), alpha);
+ }
+};
+
+
+/***************************************************************************
+* SelfAdjoint products
+***************************************************************************/
+template <typename Lhs, int LhsMode, bool LhsIsVector,
+ typename Rhs, int RhsMode, bool RhsIsVector>
+struct selfadjoint_product_impl;
+
+template<typename Lhs, typename Rhs, int ProductTag>
+struct generic_product_impl<Lhs,Rhs,SelfAdjointShape,DenseShape,ProductTag>
+ : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,SelfAdjointShape,DenseShape,ProductTag> >
+{
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+
+ template<typename Dest>
+ static EIGEN_DEVICE_FUNC
+ void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
+ {
+ selfadjoint_product_impl<typename Lhs::MatrixType,Lhs::Mode,false,Rhs,0,Rhs::IsVectorAtCompileTime>::run(dst, lhs.nestedExpression(), rhs, alpha);
+ }
+};
+
+template<typename Lhs, typename Rhs, int ProductTag>
+struct generic_product_impl<Lhs,Rhs,DenseShape,SelfAdjointShape,ProductTag>
+: generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,SelfAdjointShape,ProductTag> >
+{
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+
+ template<typename Dest>
+ static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
+ {
+ selfadjoint_product_impl<Lhs,0,Lhs::IsVectorAtCompileTime,typename Rhs::MatrixType,Rhs::Mode,false>::run(dst, lhs, rhs.nestedExpression(), alpha);
+ }
+};
+
+
+/***************************************************************************
+* Diagonal products
+***************************************************************************/
+
+template<typename MatrixType, typename DiagonalType, typename Derived, int ProductOrder>
+struct diagonal_product_evaluator_base
+ : evaluator_base<Derived>
+{
+ typedef typename ScalarBinaryOpTraits<typename MatrixType::Scalar, typename DiagonalType::Scalar>::ReturnType Scalar;
+public:
+ enum {
+ CoeffReadCost = int(NumTraits<Scalar>::MulCost) + int(evaluator<MatrixType>::CoeffReadCost) + int(evaluator<DiagonalType>::CoeffReadCost),
+
+ MatrixFlags = evaluator<MatrixType>::Flags,
+ DiagFlags = evaluator<DiagonalType>::Flags,
+
+ _StorageOrder = (Derived::MaxRowsAtCompileTime==1 && Derived::MaxColsAtCompileTime!=1) ? RowMajor
+ : (Derived::MaxColsAtCompileTime==1 && Derived::MaxRowsAtCompileTime!=1) ? ColMajor
+ : MatrixFlags & RowMajorBit ? RowMajor : ColMajor,
+ _SameStorageOrder = _StorageOrder == (MatrixFlags & RowMajorBit ? RowMajor : ColMajor),
+
+ _ScalarAccessOnDiag = !((int(_StorageOrder) == ColMajor && int(ProductOrder) == OnTheLeft)
+ ||(int(_StorageOrder) == RowMajor && int(ProductOrder) == OnTheRight)),
+ _SameTypes = is_same<typename MatrixType::Scalar, typename DiagonalType::Scalar>::value,
+ // FIXME currently we need same types, but in the future the next rule should be the one
+ //_Vectorizable = bool(int(MatrixFlags)&PacketAccessBit) && ((!_PacketOnDiag) || (_SameTypes && bool(int(DiagFlags)&PacketAccessBit))),
+ _Vectorizable = bool(int(MatrixFlags)&PacketAccessBit)
+ && _SameTypes
+ && (_SameStorageOrder || (MatrixFlags&LinearAccessBit)==LinearAccessBit)
+ && (_ScalarAccessOnDiag || (bool(int(DiagFlags)&PacketAccessBit))),
+ _LinearAccessMask = (MatrixType::RowsAtCompileTime==1 || MatrixType::ColsAtCompileTime==1) ? LinearAccessBit : 0,
+ Flags = ((HereditaryBits|_LinearAccessMask) & (unsigned int)(MatrixFlags)) | (_Vectorizable ? PacketAccessBit : 0),
+ Alignment = evaluator<MatrixType>::Alignment,
+
+ AsScalarProduct = (DiagonalType::SizeAtCompileTime==1)
+ || (DiagonalType::SizeAtCompileTime==Dynamic && MatrixType::RowsAtCompileTime==1 && ProductOrder==OnTheLeft)
+ || (DiagonalType::SizeAtCompileTime==Dynamic && MatrixType::ColsAtCompileTime==1 && ProductOrder==OnTheRight)
+ };
+
+ EIGEN_DEVICE_FUNC diagonal_product_evaluator_base(const MatrixType &mat, const DiagonalType &diag)
+ : m_diagImpl(diag), m_matImpl(mat)
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::MulCost);
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index idx) const
+ {
+ if(AsScalarProduct)
+ return m_diagImpl.coeff(0) * m_matImpl.coeff(idx);
+ else
+ return m_diagImpl.coeff(idx) * m_matImpl.coeff(idx);
+ }
+
+protected:
+ template<int LoadMode,typename PacketType>
+ EIGEN_STRONG_INLINE PacketType packet_impl(Index row, Index col, Index id, internal::true_type) const
+ {
+ return internal::pmul(m_matImpl.template packet<LoadMode,PacketType>(row, col),
+ internal::pset1<PacketType>(m_diagImpl.coeff(id)));
+ }
+
+ template<int LoadMode,typename PacketType>
+ EIGEN_STRONG_INLINE PacketType packet_impl(Index row, Index col, Index id, internal::false_type) const
+ {
+ enum {
+ InnerSize = (MatrixType::Flags & RowMajorBit) ? MatrixType::ColsAtCompileTime : MatrixType::RowsAtCompileTime,
+ DiagonalPacketLoadMode = EIGEN_PLAIN_ENUM_MIN(LoadMode,((InnerSize%16) == 0) ? int(Aligned16) : int(evaluator<DiagonalType>::Alignment)) // FIXME hardcoded 16!!
+ };
+ return internal::pmul(m_matImpl.template packet<LoadMode,PacketType>(row, col),
+ m_diagImpl.template packet<DiagonalPacketLoadMode,PacketType>(id));
+ }
+
+ evaluator<DiagonalType> m_diagImpl;
+ evaluator<MatrixType> m_matImpl;
+};
+
+// diagonal * dense
+template<typename Lhs, typename Rhs, int ProductKind, int ProductTag>
+struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DiagonalShape, DenseShape>
+ : diagonal_product_evaluator_base<Rhs, typename Lhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheLeft>
+{
+ typedef diagonal_product_evaluator_base<Rhs, typename Lhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheLeft> Base;
+ using Base::m_diagImpl;
+ using Base::m_matImpl;
+ using Base::coeff;
+ typedef typename Base::Scalar Scalar;
+
+ typedef Product<Lhs, Rhs, ProductKind> XprType;
+ typedef typename XprType::PlainObject PlainObject;
+ typedef typename Lhs::DiagonalVectorType DiagonalType;
+
+
+ enum { StorageOrder = Base::_StorageOrder };
+
+ EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr)
+ : Base(xpr.rhs(), xpr.lhs().diagonal())
+ {
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const
+ {
+ return m_diagImpl.coeff(row) * m_matImpl.coeff(row, col);
+ }
+
+#ifndef EIGEN_GPUCC
+ template<int LoadMode,typename PacketType>
+ EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const
+ {
+ // FIXME: NVCC used to complain about the template keyword, but we have to check whether this is still the case.
+ // See also similar calls below.
+ return this->template packet_impl<LoadMode,PacketType>(row,col, row,
+ typename internal::conditional<int(StorageOrder)==RowMajor, internal::true_type, internal::false_type>::type());
+ }
+
+ template<int LoadMode,typename PacketType>
+ EIGEN_STRONG_INLINE PacketType packet(Index idx) const
+ {
+ return packet<LoadMode,PacketType>(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx);
+ }
+#endif
+};
+
+// dense * diagonal
+template<typename Lhs, typename Rhs, int ProductKind, int ProductTag>
+struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DenseShape, DiagonalShape>
+ : diagonal_product_evaluator_base<Lhs, typename Rhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheRight>
+{
+ typedef diagonal_product_evaluator_base<Lhs, typename Rhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheRight> Base;
+ using Base::m_diagImpl;
+ using Base::m_matImpl;
+ using Base::coeff;
+ typedef typename Base::Scalar Scalar;
+
+ typedef Product<Lhs, Rhs, ProductKind> XprType;
+ typedef typename XprType::PlainObject PlainObject;
+
+ enum { StorageOrder = Base::_StorageOrder };
+
+ EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr)
+ : Base(xpr.lhs(), xpr.rhs().diagonal())
+ {
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const
+ {
+ return m_matImpl.coeff(row, col) * m_diagImpl.coeff(col);
+ }
+
+#ifndef EIGEN_GPUCC
+ template<int LoadMode,typename PacketType>
+ EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const
+ {
+ return this->template packet_impl<LoadMode,PacketType>(row,col, col,
+ typename internal::conditional<int(StorageOrder)==ColMajor, internal::true_type, internal::false_type>::type());
+ }
+
+ template<int LoadMode,typename PacketType>
+ EIGEN_STRONG_INLINE PacketType packet(Index idx) const
+ {
+ return packet<LoadMode,PacketType>(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx);
+ }
+#endif
+};
+
+/***************************************************************************
+* Products with permutation matrices
+***************************************************************************/
+
+/** \internal
+ * \class permutation_matrix_product
+ * Internal helper class implementing the product between a permutation matrix and a matrix.
+ * This class is specialized for DenseShape below and for SparseShape in SparseCore/SparsePermutation.h
+ */
+template<typename ExpressionType, int Side, bool Transposed, typename ExpressionShape>
+struct permutation_matrix_product;
+
+template<typename ExpressionType, int Side, bool Transposed>
+struct permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape>
+{
+ typedef typename nested_eval<ExpressionType, 1>::type MatrixType;
+ typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
+
+ template<typename Dest, typename PermutationType>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Dest& dst, const PermutationType& perm, const ExpressionType& xpr)
+ {
+ MatrixType mat(xpr);
+ const Index n = Side==OnTheLeft ? mat.rows() : mat.cols();
+ // FIXME we need an is_same for expression that is not sensitive to constness. For instance
+ // is_same_xpr<Block<const Matrix>, Block<Matrix> >::value should be true.
+ //if(is_same<MatrixTypeCleaned,Dest>::value && extract_data(dst) == extract_data(mat))
+ if(is_same_dense(dst, mat))
+ {
+ // apply the permutation inplace
+ Matrix<bool,PermutationType::RowsAtCompileTime,1,0,PermutationType::MaxRowsAtCompileTime> mask(perm.size());
+ mask.fill(false);
+ Index r = 0;
+ while(r < perm.size())
+ {
+ // search for the next seed
+ while(r<perm.size() && mask[r]) r++;
+ if(r>=perm.size())
+ break;
+ // we got one, let's follow it until we are back to the seed
+ Index k0 = r++;
+ Index kPrev = k0;
+ mask.coeffRef(k0) = true;
+ for(Index k=perm.indices().coeff(k0); k!=k0; k=perm.indices().coeff(k))
+ {
+ Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime>(dst, k)
+ .swap(Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime>
+ (dst,((Side==OnTheLeft) ^ Transposed) ? k0 : kPrev));
+
+ mask.coeffRef(k) = true;
+ kPrev = k;
+ }
+ }
+ }
+ else
+ {
+ for(Index i = 0; i < n; ++i)
+ {
+ Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime>
+ (dst, ((Side==OnTheLeft) ^ Transposed) ? perm.indices().coeff(i) : i)
+
+ =
+
+ Block<const MatrixTypeCleaned,Side==OnTheLeft ? 1 : MatrixTypeCleaned::RowsAtCompileTime,Side==OnTheRight ? 1 : MatrixTypeCleaned::ColsAtCompileTime>
+ (mat, ((Side==OnTheRight) ^ Transposed) ? perm.indices().coeff(i) : i);
+ }
+ }
+ }
+};
+
+template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
+struct generic_product_impl<Lhs, Rhs, PermutationShape, MatrixShape, ProductTag>
+{
+ template<typename Dest>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ permutation_matrix_product<Rhs, OnTheLeft, false, MatrixShape>::run(dst, lhs, rhs);
+ }
+};
+
+template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
+struct generic_product_impl<Lhs, Rhs, MatrixShape, PermutationShape, ProductTag>
+{
+ template<typename Dest>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ permutation_matrix_product<Lhs, OnTheRight, false, MatrixShape>::run(dst, rhs, lhs);
+ }
+};
+
+template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
+struct generic_product_impl<Inverse<Lhs>, Rhs, PermutationShape, MatrixShape, ProductTag>
+{
+ template<typename Dest>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Inverse<Lhs>& lhs, const Rhs& rhs)
+ {
+ permutation_matrix_product<Rhs, OnTheLeft, true, MatrixShape>::run(dst, lhs.nestedExpression(), rhs);
+ }
+};
+
+template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
+struct generic_product_impl<Lhs, Inverse<Rhs>, MatrixShape, PermutationShape, ProductTag>
+{
+ template<typename Dest>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Inverse<Rhs>& rhs)
+ {
+ permutation_matrix_product<Lhs, OnTheRight, true, MatrixShape>::run(dst, rhs.nestedExpression(), lhs);
+ }
+};
+
+
+/***************************************************************************
+* Products with transpositions matrices
+***************************************************************************/
+
+// FIXME could we unify Transpositions and Permutation into a single "shape"??
+
+/** \internal
+ * \class transposition_matrix_product
+ * Internal helper class implementing the product between a permutation matrix and a matrix.
+ */
+template<typename ExpressionType, int Side, bool Transposed, typename ExpressionShape>
+struct transposition_matrix_product
+{
+ typedef typename nested_eval<ExpressionType, 1>::type MatrixType;
+ typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
+
+ template<typename Dest, typename TranspositionType>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Dest& dst, const TranspositionType& tr, const ExpressionType& xpr)
+ {
+ MatrixType mat(xpr);
+ typedef typename TranspositionType::StorageIndex StorageIndex;
+ const Index size = tr.size();
+ StorageIndex j = 0;
+
+ if(!is_same_dense(dst,mat))
+ dst = mat;
+
+ for(Index k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k)
+ if(Index(j=tr.coeff(k))!=k)
+ {
+ if(Side==OnTheLeft) dst.row(k).swap(dst.row(j));
+ else if(Side==OnTheRight) dst.col(k).swap(dst.col(j));
+ }
+ }
+};
+
+template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
+struct generic_product_impl<Lhs, Rhs, TranspositionsShape, MatrixShape, ProductTag>
+{
+ template<typename Dest>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ transposition_matrix_product<Rhs, OnTheLeft, false, MatrixShape>::run(dst, lhs, rhs);
+ }
+};
+
+template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
+struct generic_product_impl<Lhs, Rhs, MatrixShape, TranspositionsShape, ProductTag>
+{
+ template<typename Dest>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ transposition_matrix_product<Lhs, OnTheRight, false, MatrixShape>::run(dst, rhs, lhs);
+ }
+};
+
+
+template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
+struct generic_product_impl<Transpose<Lhs>, Rhs, TranspositionsShape, MatrixShape, ProductTag>
+{
+ template<typename Dest>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Transpose<Lhs>& lhs, const Rhs& rhs)
+ {
+ transposition_matrix_product<Rhs, OnTheLeft, true, MatrixShape>::run(dst, lhs.nestedExpression(), rhs);
+ }
+};
+
+template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
+struct generic_product_impl<Lhs, Transpose<Rhs>, MatrixShape, TranspositionsShape, ProductTag>
+{
+ template<typename Dest>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Transpose<Rhs>& rhs)
+ {
+ transposition_matrix_product<Lhs, OnTheRight, true, MatrixShape>::run(dst, rhs.nestedExpression(), lhs);
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PRODUCT_EVALUATORS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Random.h b/src/3rdparty/eigen/Eigen/src/Core/Random.h
new file mode 100644
index 000000000..dab2ac8e9
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Random.h
@@ -0,0 +1,218 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_RANDOM_H
+#define EIGEN_RANDOM_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Scalar> struct scalar_random_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_random_op)
+ inline const Scalar operator() () const { return random<Scalar>(); }
+};
+
+template<typename Scalar>
+struct functor_traits<scalar_random_op<Scalar> >
+{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false }; };
+
+} // end namespace internal
+
+/** \returns a random matrix expression
+ *
+ * Numbers are uniformly spread through their whole definition range for integer types,
+ * and in the [-1:1] range for floating point scalar types.
+ *
+ * The parameters \a rows and \a cols are the number of rows and of columns of
+ * the returned matrix. Must be compatible with this MatrixBase type.
+ *
+ * \not_reentrant
+ *
+ * This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
+ * it is redundant to pass \a rows and \a cols as arguments, so Random() should be used
+ * instead.
+ *
+ *
+ * Example: \include MatrixBase_random_int_int.cpp
+ * Output: \verbinclude MatrixBase_random_int_int.out
+ *
+ * This expression has the "evaluate before nesting" flag so that it will be evaluated into
+ * a temporary matrix whenever it is nested in a larger expression. This prevents unexpected
+ * behavior with expressions involving random matrices.
+ *
+ * See DenseBase::NullaryExpr(Index, const CustomNullaryOp&) for an example using C++11 random generators.
+ *
+ * \sa DenseBase::setRandom(), DenseBase::Random(Index), DenseBase::Random()
+ */
+template<typename Derived>
+inline const typename DenseBase<Derived>::RandomReturnType
+DenseBase<Derived>::Random(Index rows, Index cols)
+{
+ return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>());
+}
+
+/** \returns a random vector expression
+ *
+ * Numbers are uniformly spread through their whole definition range for integer types,
+ * and in the [-1:1] range for floating point scalar types.
+ *
+ * The parameter \a size is the size of the returned vector.
+ * Must be compatible with this MatrixBase type.
+ *
+ * \only_for_vectors
+ * \not_reentrant
+ *
+ * This variant is meant to be used for dynamic-size vector types. For fixed-size types,
+ * it is redundant to pass \a size as argument, so Random() should be used
+ * instead.
+ *
+ * Example: \include MatrixBase_random_int.cpp
+ * Output: \verbinclude MatrixBase_random_int.out
+ *
+ * This expression has the "evaluate before nesting" flag so that it will be evaluated into
+ * a temporary vector whenever it is nested in a larger expression. This prevents unexpected
+ * behavior with expressions involving random matrices.
+ *
+ * \sa DenseBase::setRandom(), DenseBase::Random(Index,Index), DenseBase::Random()
+ */
+template<typename Derived>
+inline const typename DenseBase<Derived>::RandomReturnType
+DenseBase<Derived>::Random(Index size)
+{
+ return NullaryExpr(size, internal::scalar_random_op<Scalar>());
+}
+
+/** \returns a fixed-size random matrix or vector expression
+ *
+ * Numbers are uniformly spread through their whole definition range for integer types,
+ * and in the [-1:1] range for floating point scalar types.
+ *
+ * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you
+ * need to use the variants taking size arguments.
+ *
+ * Example: \include MatrixBase_random.cpp
+ * Output: \verbinclude MatrixBase_random.out
+ *
+ * This expression has the "evaluate before nesting" flag so that it will be evaluated into
+ * a temporary matrix whenever it is nested in a larger expression. This prevents unexpected
+ * behavior with expressions involving random matrices.
+ *
+ * \not_reentrant
+ *
+ * \sa DenseBase::setRandom(), DenseBase::Random(Index,Index), DenseBase::Random(Index)
+ */
+template<typename Derived>
+inline const typename DenseBase<Derived>::RandomReturnType
+DenseBase<Derived>::Random()
+{
+ return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>());
+}
+
+/** Sets all coefficients in this expression to random values.
+ *
+ * Numbers are uniformly spread through their whole definition range for integer types,
+ * and in the [-1:1] range for floating point scalar types.
+ *
+ * \not_reentrant
+ *
+ * Example: \include MatrixBase_setRandom.cpp
+ * Output: \verbinclude MatrixBase_setRandom.out
+ *
+ * \sa class CwiseNullaryOp, setRandom(Index), setRandom(Index,Index)
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline Derived& DenseBase<Derived>::setRandom()
+{
+ return *this = Random(rows(), cols());
+}
+
+/** Resizes to the given \a newSize, and sets all coefficients in this expression to random values.
+ *
+ * Numbers are uniformly spread through their whole definition range for integer types,
+ * and in the [-1:1] range for floating point scalar types.
+ *
+ * \only_for_vectors
+ * \not_reentrant
+ *
+ * Example: \include Matrix_setRandom_int.cpp
+ * Output: \verbinclude Matrix_setRandom_int.out
+ *
+ * \sa DenseBase::setRandom(), setRandom(Index,Index), class CwiseNullaryOp, DenseBase::Random()
+ */
+template<typename Derived>
+EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setRandom(Index newSize)
+{
+ resize(newSize);
+ return setRandom();
+}
+
+/** Resizes to the given size, and sets all coefficients in this expression to random values.
+ *
+ * Numbers are uniformly spread through their whole definition range for integer types,
+ * and in the [-1:1] range for floating point scalar types.
+ *
+ * \not_reentrant
+ *
+ * \param rows the new number of rows
+ * \param cols the new number of columns
+ *
+ * Example: \include Matrix_setRandom_int_int.cpp
+ * Output: \verbinclude Matrix_setRandom_int_int.out
+ *
+ * \sa DenseBase::setRandom(), setRandom(Index), class CwiseNullaryOp, DenseBase::Random()
+ */
+template<typename Derived>
+EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setRandom(Index rows, Index cols)
+{
+ resize(rows, cols);
+ return setRandom();
+}
+
+/** Resizes to the given size, changing only the number of columns, and sets all
+ * coefficients in this expression to random values. For the parameter of type
+ * NoChange_t, just pass the special value \c NoChange.
+ *
+ * Numbers are uniformly spread through their whole definition range for integer types,
+ * and in the [-1:1] range for floating point scalar types.
+ *
+ * \not_reentrant
+ *
+ * \sa DenseBase::setRandom(), setRandom(Index), setRandom(Index, NoChange_t), class CwiseNullaryOp, DenseBase::Random()
+ */
+template<typename Derived>
+EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setRandom(NoChange_t, Index cols)
+{
+ return setRandom(rows(), cols);
+}
+
+/** Resizes to the given size, changing only the number of rows, and sets all
+ * coefficients in this expression to random values. For the parameter of type
+ * NoChange_t, just pass the special value \c NoChange.
+ *
+ * Numbers are uniformly spread through their whole definition range for integer types,
+ * and in the [-1:1] range for floating point scalar types.
+ *
+ * \not_reentrant
+ *
+ * \sa DenseBase::setRandom(), setRandom(Index), setRandom(NoChange_t, Index), class CwiseNullaryOp, DenseBase::Random()
+ */
+template<typename Derived>
+EIGEN_STRONG_INLINE Derived&
+PlainObjectBase<Derived>::setRandom(Index rows, NoChange_t)
+{
+ return setRandom(rows, cols());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_RANDOM_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Redux.h b/src/3rdparty/eigen/Eigen/src/Core/Redux.h
new file mode 100644
index 000000000..b6790d110
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Redux.h
@@ -0,0 +1,515 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_REDUX_H
+#define EIGEN_REDUX_H
+
+namespace Eigen {
+
+namespace internal {
+
+// TODO
+// * implement other kind of vectorization
+// * factorize code
+
+/***************************************************************************
+* Part 1 : the logic deciding a strategy for vectorization and unrolling
+***************************************************************************/
+
+template<typename Func, typename Evaluator>
+struct redux_traits
+{
+public:
+ typedef typename find_best_packet<typename Evaluator::Scalar,Evaluator::SizeAtCompileTime>::type PacketType;
+ enum {
+ PacketSize = unpacket_traits<PacketType>::size,
+ InnerMaxSize = int(Evaluator::IsRowMajor)
+ ? Evaluator::MaxColsAtCompileTime
+ : Evaluator::MaxRowsAtCompileTime,
+ OuterMaxSize = int(Evaluator::IsRowMajor)
+ ? Evaluator::MaxRowsAtCompileTime
+ : Evaluator::MaxColsAtCompileTime,
+ SliceVectorizedWork = int(InnerMaxSize)==Dynamic ? Dynamic
+ : int(OuterMaxSize)==Dynamic ? (int(InnerMaxSize)>=int(PacketSize) ? Dynamic : 0)
+ : (int(InnerMaxSize)/int(PacketSize)) * int(OuterMaxSize)
+ };
+
+ enum {
+ MightVectorize = (int(Evaluator::Flags)&ActualPacketAccessBit)
+ && (functor_traits<Func>::PacketAccess),
+ MayLinearVectorize = bool(MightVectorize) && (int(Evaluator::Flags)&LinearAccessBit),
+ MaySliceVectorize = bool(MightVectorize) && (int(SliceVectorizedWork)==Dynamic || int(SliceVectorizedWork)>=3)
+ };
+
+public:
+ enum {
+ Traversal = int(MayLinearVectorize) ? int(LinearVectorizedTraversal)
+ : int(MaySliceVectorize) ? int(SliceVectorizedTraversal)
+ : int(DefaultTraversal)
+ };
+
+public:
+ enum {
+ Cost = Evaluator::SizeAtCompileTime == Dynamic ? HugeCost
+ : int(Evaluator::SizeAtCompileTime) * int(Evaluator::CoeffReadCost) + (Evaluator::SizeAtCompileTime-1) * functor_traits<Func>::Cost,
+ UnrollingLimit = EIGEN_UNROLLING_LIMIT * (int(Traversal) == int(DefaultTraversal) ? 1 : int(PacketSize))
+ };
+
+public:
+ enum {
+ Unrolling = Cost <= UnrollingLimit ? CompleteUnrolling : NoUnrolling
+ };
+
+#ifdef EIGEN_DEBUG_ASSIGN
+ static void debug()
+ {
+ std::cerr << "Xpr: " << typeid(typename Evaluator::XprType).name() << std::endl;
+ std::cerr.setf(std::ios::hex, std::ios::basefield);
+ EIGEN_DEBUG_VAR(Evaluator::Flags)
+ std::cerr.unsetf(std::ios::hex);
+ EIGEN_DEBUG_VAR(InnerMaxSize)
+ EIGEN_DEBUG_VAR(OuterMaxSize)
+ EIGEN_DEBUG_VAR(SliceVectorizedWork)
+ EIGEN_DEBUG_VAR(PacketSize)
+ EIGEN_DEBUG_VAR(MightVectorize)
+ EIGEN_DEBUG_VAR(MayLinearVectorize)
+ EIGEN_DEBUG_VAR(MaySliceVectorize)
+ std::cerr << "Traversal" << " = " << Traversal << " (" << demangle_traversal(Traversal) << ")" << std::endl;
+ EIGEN_DEBUG_VAR(UnrollingLimit)
+ std::cerr << "Unrolling" << " = " << Unrolling << " (" << demangle_unrolling(Unrolling) << ")" << std::endl;
+ std::cerr << std::endl;
+ }
+#endif
+};
+
+/***************************************************************************
+* Part 2 : unrollers
+***************************************************************************/
+
+/*** no vectorization ***/
+
+template<typename Func, typename Evaluator, int Start, int Length>
+struct redux_novec_unroller
+{
+ enum {
+ HalfLength = Length/2
+ };
+
+ typedef typename Evaluator::Scalar Scalar;
+
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE Scalar run(const Evaluator &eval, const Func& func)
+ {
+ return func(redux_novec_unroller<Func, Evaluator, Start, HalfLength>::run(eval,func),
+ redux_novec_unroller<Func, Evaluator, Start+HalfLength, Length-HalfLength>::run(eval,func));
+ }
+};
+
+template<typename Func, typename Evaluator, int Start>
+struct redux_novec_unroller<Func, Evaluator, Start, 1>
+{
+ enum {
+ outer = Start / Evaluator::InnerSizeAtCompileTime,
+ inner = Start % Evaluator::InnerSizeAtCompileTime
+ };
+
+ typedef typename Evaluator::Scalar Scalar;
+
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE Scalar run(const Evaluator &eval, const Func&)
+ {
+ return eval.coeffByOuterInner(outer, inner);
+ }
+};
+
+// This is actually dead code and will never be called. It is required
+// to prevent false warnings regarding failed inlining though
+// for 0 length run() will never be called at all.
+template<typename Func, typename Evaluator, int Start>
+struct redux_novec_unroller<Func, Evaluator, Start, 0>
+{
+ typedef typename Evaluator::Scalar Scalar;
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE Scalar run(const Evaluator&, const Func&) { return Scalar(); }
+};
+
+/*** vectorization ***/
+
+template<typename Func, typename Evaluator, int Start, int Length>
+struct redux_vec_unroller
+{
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE PacketType run(const Evaluator &eval, const Func& func)
+ {
+ enum {
+ PacketSize = unpacket_traits<PacketType>::size,
+ HalfLength = Length/2
+ };
+
+ return func.packetOp(
+ redux_vec_unroller<Func, Evaluator, Start, HalfLength>::template run<PacketType>(eval,func),
+ redux_vec_unroller<Func, Evaluator, Start+HalfLength, Length-HalfLength>::template run<PacketType>(eval,func) );
+ }
+};
+
+template<typename Func, typename Evaluator, int Start>
+struct redux_vec_unroller<Func, Evaluator, Start, 1>
+{
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE PacketType run(const Evaluator &eval, const Func&)
+ {
+ enum {
+ PacketSize = unpacket_traits<PacketType>::size,
+ index = Start * PacketSize,
+ outer = index / int(Evaluator::InnerSizeAtCompileTime),
+ inner = index % int(Evaluator::InnerSizeAtCompileTime),
+ alignment = Evaluator::Alignment
+ };
+ return eval.template packetByOuterInner<alignment,PacketType>(outer, inner);
+ }
+};
+
+/***************************************************************************
+* Part 3 : implementation of all cases
+***************************************************************************/
+
+template<typename Func, typename Evaluator,
+ int Traversal = redux_traits<Func, Evaluator>::Traversal,
+ int Unrolling = redux_traits<Func, Evaluator>::Unrolling
+>
+struct redux_impl;
+
+template<typename Func, typename Evaluator>
+struct redux_impl<Func, Evaluator, DefaultTraversal, NoUnrolling>
+{
+ typedef typename Evaluator::Scalar Scalar;
+
+ template<typename XprType>
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE
+ Scalar run(const Evaluator &eval, const Func& func, const XprType& xpr)
+ {
+ eigen_assert(xpr.rows()>0 && xpr.cols()>0 && "you are using an empty matrix");
+ Scalar res;
+ res = eval.coeffByOuterInner(0, 0);
+ for(Index i = 1; i < xpr.innerSize(); ++i)
+ res = func(res, eval.coeffByOuterInner(0, i));
+ for(Index i = 1; i < xpr.outerSize(); ++i)
+ for(Index j = 0; j < xpr.innerSize(); ++j)
+ res = func(res, eval.coeffByOuterInner(i, j));
+ return res;
+ }
+};
+
+template<typename Func, typename Evaluator>
+struct redux_impl<Func,Evaluator, DefaultTraversal, CompleteUnrolling>
+ : redux_novec_unroller<Func,Evaluator, 0, Evaluator::SizeAtCompileTime>
+{
+ typedef redux_novec_unroller<Func,Evaluator, 0, Evaluator::SizeAtCompileTime> Base;
+ typedef typename Evaluator::Scalar Scalar;
+ template<typename XprType>
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE
+ Scalar run(const Evaluator &eval, const Func& func, const XprType& /*xpr*/)
+ {
+ return Base::run(eval,func);
+ }
+};
+
+template<typename Func, typename Evaluator>
+struct redux_impl<Func, Evaluator, LinearVectorizedTraversal, NoUnrolling>
+{
+ typedef typename Evaluator::Scalar Scalar;
+ typedef typename redux_traits<Func, Evaluator>::PacketType PacketScalar;
+
+ template<typename XprType>
+ static Scalar run(const Evaluator &eval, const Func& func, const XprType& xpr)
+ {
+ const Index size = xpr.size();
+
+ const Index packetSize = redux_traits<Func, Evaluator>::PacketSize;
+ const int packetAlignment = unpacket_traits<PacketScalar>::alignment;
+ enum {
+ alignment0 = (bool(Evaluator::Flags & DirectAccessBit) && bool(packet_traits<Scalar>::AlignedOnScalar)) ? int(packetAlignment) : int(Unaligned),
+ alignment = EIGEN_PLAIN_ENUM_MAX(alignment0, Evaluator::Alignment)
+ };
+ const Index alignedStart = internal::first_default_aligned(xpr);
+ const Index alignedSize2 = ((size-alignedStart)/(2*packetSize))*(2*packetSize);
+ const Index alignedSize = ((size-alignedStart)/(packetSize))*(packetSize);
+ const Index alignedEnd2 = alignedStart + alignedSize2;
+ const Index alignedEnd = alignedStart + alignedSize;
+ Scalar res;
+ if(alignedSize)
+ {
+ PacketScalar packet_res0 = eval.template packet<alignment,PacketScalar>(alignedStart);
+ if(alignedSize>packetSize) // we have at least two packets to partly unroll the loop
+ {
+ PacketScalar packet_res1 = eval.template packet<alignment,PacketScalar>(alignedStart+packetSize);
+ for(Index index = alignedStart + 2*packetSize; index < alignedEnd2; index += 2*packetSize)
+ {
+ packet_res0 = func.packetOp(packet_res0, eval.template packet<alignment,PacketScalar>(index));
+ packet_res1 = func.packetOp(packet_res1, eval.template packet<alignment,PacketScalar>(index+packetSize));
+ }
+
+ packet_res0 = func.packetOp(packet_res0,packet_res1);
+ if(alignedEnd>alignedEnd2)
+ packet_res0 = func.packetOp(packet_res0, eval.template packet<alignment,PacketScalar>(alignedEnd2));
+ }
+ res = func.predux(packet_res0);
+
+ for(Index index = 0; index < alignedStart; ++index)
+ res = func(res,eval.coeff(index));
+
+ for(Index index = alignedEnd; index < size; ++index)
+ res = func(res,eval.coeff(index));
+ }
+ else // too small to vectorize anything.
+ // since this is dynamic-size hence inefficient anyway for such small sizes, don't try to optimize.
+ {
+ res = eval.coeff(0);
+ for(Index index = 1; index < size; ++index)
+ res = func(res,eval.coeff(index));
+ }
+
+ return res;
+ }
+};
+
+// NOTE: for SliceVectorizedTraversal we simply bypass unrolling
+template<typename Func, typename Evaluator, int Unrolling>
+struct redux_impl<Func, Evaluator, SliceVectorizedTraversal, Unrolling>
+{
+ typedef typename Evaluator::Scalar Scalar;
+ typedef typename redux_traits<Func, Evaluator>::PacketType PacketType;
+
+ template<typename XprType>
+ EIGEN_DEVICE_FUNC static Scalar run(const Evaluator &eval, const Func& func, const XprType& xpr)
+ {
+ eigen_assert(xpr.rows()>0 && xpr.cols()>0 && "you are using an empty matrix");
+ const Index innerSize = xpr.innerSize();
+ const Index outerSize = xpr.outerSize();
+ enum {
+ packetSize = redux_traits<Func, Evaluator>::PacketSize
+ };
+ const Index packetedInnerSize = ((innerSize)/packetSize)*packetSize;
+ Scalar res;
+ if(packetedInnerSize)
+ {
+ PacketType packet_res = eval.template packet<Unaligned,PacketType>(0,0);
+ for(Index j=0; j<outerSize; ++j)
+ for(Index i=(j==0?packetSize:0); i<packetedInnerSize; i+=Index(packetSize))
+ packet_res = func.packetOp(packet_res, eval.template packetByOuterInner<Unaligned,PacketType>(j,i));
+
+ res = func.predux(packet_res);
+ for(Index j=0; j<outerSize; ++j)
+ for(Index i=packetedInnerSize; i<innerSize; ++i)
+ res = func(res, eval.coeffByOuterInner(j,i));
+ }
+ else // too small to vectorize anything.
+ // since this is dynamic-size hence inefficient anyway for such small sizes, don't try to optimize.
+ {
+ res = redux_impl<Func, Evaluator, DefaultTraversal, NoUnrolling>::run(eval, func, xpr);
+ }
+
+ return res;
+ }
+};
+
+template<typename Func, typename Evaluator>
+struct redux_impl<Func, Evaluator, LinearVectorizedTraversal, CompleteUnrolling>
+{
+ typedef typename Evaluator::Scalar Scalar;
+
+ typedef typename redux_traits<Func, Evaluator>::PacketType PacketType;
+ enum {
+ PacketSize = redux_traits<Func, Evaluator>::PacketSize,
+ Size = Evaluator::SizeAtCompileTime,
+ VectorizedSize = (int(Size) / int(PacketSize)) * int(PacketSize)
+ };
+
+ template<typename XprType>
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE
+ Scalar run(const Evaluator &eval, const Func& func, const XprType &xpr)
+ {
+ EIGEN_ONLY_USED_FOR_DEBUG(xpr)
+ eigen_assert(xpr.rows()>0 && xpr.cols()>0 && "you are using an empty matrix");
+ if (VectorizedSize > 0) {
+ Scalar res = func.predux(redux_vec_unroller<Func, Evaluator, 0, Size / PacketSize>::template run<PacketType>(eval,func));
+ if (VectorizedSize != Size)
+ res = func(res,redux_novec_unroller<Func, Evaluator, VectorizedSize, Size-VectorizedSize>::run(eval,func));
+ return res;
+ }
+ else {
+ return redux_novec_unroller<Func, Evaluator, 0, Size>::run(eval,func);
+ }
+ }
+};
+
+// evaluator adaptor
+template<typename _XprType>
+class redux_evaluator : public internal::evaluator<_XprType>
+{
+ typedef internal::evaluator<_XprType> Base;
+public:
+ typedef _XprType XprType;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ explicit redux_evaluator(const XprType &xpr) : Base(xpr) {}
+
+ typedef typename XprType::Scalar Scalar;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+ typedef typename XprType::PacketScalar PacketScalar;
+
+ enum {
+ MaxRowsAtCompileTime = XprType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = XprType::MaxColsAtCompileTime,
+ // TODO we should not remove DirectAccessBit and rather find an elegant way to query the alignment offset at runtime from the evaluator
+ Flags = Base::Flags & ~DirectAccessBit,
+ IsRowMajor = XprType::IsRowMajor,
+ SizeAtCompileTime = XprType::SizeAtCompileTime,
+ InnerSizeAtCompileTime = XprType::InnerSizeAtCompileTime
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ CoeffReturnType coeffByOuterInner(Index outer, Index inner) const
+ { return Base::coeff(IsRowMajor ? outer : inner, IsRowMajor ? inner : outer); }
+
+ template<int LoadMode, typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ PacketType packetByOuterInner(Index outer, Index inner) const
+ { return Base::template packet<LoadMode,PacketType>(IsRowMajor ? outer : inner, IsRowMajor ? inner : outer); }
+
+};
+
+} // end namespace internal
+
+/***************************************************************************
+* Part 4 : public API
+***************************************************************************/
+
+
+/** \returns the result of a full redux operation on the whole matrix or vector using \a func
+ *
+ * The template parameter \a BinaryOp is the type of the functor \a func which must be
+ * an associative operator. Both current C++98 and C++11 functor styles are handled.
+ *
+ * \warning the matrix must be not empty, otherwise an assertion is triggered.
+ *
+ * \sa DenseBase::sum(), DenseBase::minCoeff(), DenseBase::maxCoeff(), MatrixBase::colwise(), MatrixBase::rowwise()
+ */
+template<typename Derived>
+template<typename Func>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
+DenseBase<Derived>::redux(const Func& func) const
+{
+ eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix");
+
+ typedef typename internal::redux_evaluator<Derived> ThisEvaluator;
+ ThisEvaluator thisEval(derived());
+
+ // The initial expression is passed to the reducer as an additional argument instead of
+ // passing it as a member of redux_evaluator to help
+ return internal::redux_impl<Func, ThisEvaluator>::run(thisEval, func, derived());
+}
+
+/** \returns the minimum of all coefficients of \c *this.
+ * In case \c *this contains NaN, NaNPropagation determines the behavior:
+ * NaNPropagation == PropagateFast : undefined
+ * NaNPropagation == PropagateNaN : result is NaN
+ * NaNPropagation == PropagateNumbers : result is minimum of elements that are not NaN
+ * \warning the matrix must be not empty, otherwise an assertion is triggered.
+ */
+template<typename Derived>
+template<int NaNPropagation>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
+DenseBase<Derived>::minCoeff() const
+{
+ return derived().redux(Eigen::internal::scalar_min_op<Scalar,Scalar, NaNPropagation>());
+}
+
+/** \returns the maximum of all coefficients of \c *this.
+ * In case \c *this contains NaN, NaNPropagation determines the behavior:
+ * NaNPropagation == PropagateFast : undefined
+ * NaNPropagation == PropagateNaN : result is NaN
+ * NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
+ * \warning the matrix must be not empty, otherwise an assertion is triggered.
+ */
+template<typename Derived>
+template<int NaNPropagation>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
+DenseBase<Derived>::maxCoeff() const
+{
+ return derived().redux(Eigen::internal::scalar_max_op<Scalar,Scalar, NaNPropagation>());
+}
+
+/** \returns the sum of all coefficients of \c *this
+ *
+ * If \c *this is empty, then the value 0 is returned.
+ *
+ * \sa trace(), prod(), mean()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
+DenseBase<Derived>::sum() const
+{
+ if(SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0))
+ return Scalar(0);
+ return derived().redux(Eigen::internal::scalar_sum_op<Scalar,Scalar>());
+}
+
+/** \returns the mean of all coefficients of *this
+*
+* \sa trace(), prod(), sum()
+*/
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
+DenseBase<Derived>::mean() const
+{
+#ifdef __INTEL_COMPILER
+ #pragma warning push
+ #pragma warning ( disable : 2259 )
+#endif
+ return Scalar(derived().redux(Eigen::internal::scalar_sum_op<Scalar,Scalar>())) / Scalar(this->size());
+#ifdef __INTEL_COMPILER
+ #pragma warning pop
+#endif
+}
+
+/** \returns the product of all coefficients of *this
+ *
+ * Example: \include MatrixBase_prod.cpp
+ * Output: \verbinclude MatrixBase_prod.out
+ *
+ * \sa sum(), mean(), trace()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
+DenseBase<Derived>::prod() const
+{
+ if(SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0))
+ return Scalar(1);
+ return derived().redux(Eigen::internal::scalar_product_op<Scalar>());
+}
+
+/** \returns the trace of \c *this, i.e. the sum of the coefficients on the main diagonal.
+ *
+ * \c *this can be any matrix, not necessarily square.
+ *
+ * \sa diagonal(), sum()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
+MatrixBase<Derived>::trace() const
+{
+ return derived().diagonal().sum();
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_REDUX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Ref.h b/src/3rdparty/eigen/Eigen/src/Core/Ref.h
new file mode 100644
index 000000000..c2a37eadb
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Ref.h
@@ -0,0 +1,381 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_REF_H
+#define EIGEN_REF_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename _PlainObjectType, int _Options, typename _StrideType>
+struct traits<Ref<_PlainObjectType, _Options, _StrideType> >
+ : public traits<Map<_PlainObjectType, _Options, _StrideType> >
+{
+ typedef _PlainObjectType PlainObjectType;
+ typedef _StrideType StrideType;
+ enum {
+ Options = _Options,
+ Flags = traits<Map<_PlainObjectType, _Options, _StrideType> >::Flags | NestByRefBit,
+ Alignment = traits<Map<_PlainObjectType, _Options, _StrideType> >::Alignment
+ };
+
+ template<typename Derived> struct match {
+ enum {
+ IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime,
+ HasDirectAccess = internal::has_direct_access<Derived>::ret,
+ StorageOrderMatch = IsVectorAtCompileTime || ((PlainObjectType::Flags&RowMajorBit)==(Derived::Flags&RowMajorBit)),
+ InnerStrideMatch = int(StrideType::InnerStrideAtCompileTime)==int(Dynamic)
+ || int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime)
+ || (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1),
+ OuterStrideMatch = IsVectorAtCompileTime
+ || int(StrideType::OuterStrideAtCompileTime)==int(Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime),
+ // NOTE, this indirection of evaluator<Derived>::Alignment is needed
+ // to workaround a very strange bug in MSVC related to the instantiation
+ // of has_*ary_operator in evaluator<CwiseNullaryOp>.
+ // This line is surprisingly very sensitive. For instance, simply adding parenthesis
+ // as "DerivedAlignment = (int(evaluator<Derived>::Alignment))," will make MSVC fail...
+ DerivedAlignment = int(evaluator<Derived>::Alignment),
+ AlignmentMatch = (int(traits<PlainObjectType>::Alignment)==int(Unaligned)) || (DerivedAlignment >= int(Alignment)), // FIXME the first condition is not very clear, it should be replaced by the required alignment
+ ScalarTypeMatch = internal::is_same<typename PlainObjectType::Scalar, typename Derived::Scalar>::value,
+ MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch && ScalarTypeMatch
+ };
+ typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type;
+ };
+
+};
+
+template<typename Derived>
+struct traits<RefBase<Derived> > : public traits<Derived> {};
+
+}
+
+template<typename Derived> class RefBase
+ : public MapBase<Derived>
+{
+ typedef typename internal::traits<Derived>::PlainObjectType PlainObjectType;
+ typedef typename internal::traits<Derived>::StrideType StrideType;
+
+public:
+
+ typedef MapBase<Derived> Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const
+ {
+ return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const
+ {
+ return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
+ : IsVectorAtCompileTime ? this->size()
+ : int(Flags)&RowMajorBit ? this->cols()
+ : this->rows();
+ }
+
+ EIGEN_DEVICE_FUNC RefBase()
+ : Base(0,RowsAtCompileTime==Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==Dynamic?0:ColsAtCompileTime),
+ // Stride<> does not allow default ctor for Dynamic strides, so let' initialize it with dummy values:
+ m_stride(StrideType::OuterStrideAtCompileTime==Dynamic?0:StrideType::OuterStrideAtCompileTime,
+ StrideType::InnerStrideAtCompileTime==Dynamic?0:StrideType::InnerStrideAtCompileTime)
+ {}
+
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase)
+
+protected:
+
+ typedef Stride<StrideType::OuterStrideAtCompileTime,StrideType::InnerStrideAtCompileTime> StrideBase;
+
+ // Resolves inner stride if default 0.
+ static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index resolveInnerStride(Index inner) {
+ return inner == 0 ? 1 : inner;
+ }
+
+ // Resolves outer stride if default 0.
+ static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index resolveOuterStride(Index inner, Index outer, Index rows, Index cols, bool isVectorAtCompileTime, bool isRowMajor) {
+ return outer == 0 ? isVectorAtCompileTime ? inner * rows * cols : isRowMajor ? inner * cols : inner * rows : outer;
+ }
+
+ // Returns true if construction is valid, false if there is a stride mismatch,
+ // and fails if there is a size mismatch.
+ template<typename Expression>
+ EIGEN_DEVICE_FUNC bool construct(Expression& expr)
+ {
+ // Check matrix sizes. If this is a compile-time vector, we do allow
+ // implicitly transposing.
+ EIGEN_STATIC_ASSERT(
+ EIGEN_PREDICATE_SAME_MATRIX_SIZE(PlainObjectType, Expression)
+ // If it is a vector, the transpose sizes might match.
+ || ( PlainObjectType::IsVectorAtCompileTime
+ && ((int(PlainObjectType::RowsAtCompileTime)==Eigen::Dynamic
+ || int(Expression::ColsAtCompileTime)==Eigen::Dynamic
+ || int(PlainObjectType::RowsAtCompileTime)==int(Expression::ColsAtCompileTime))
+ && (int(PlainObjectType::ColsAtCompileTime)==Eigen::Dynamic
+ || int(Expression::RowsAtCompileTime)==Eigen::Dynamic
+ || int(PlainObjectType::ColsAtCompileTime)==int(Expression::RowsAtCompileTime)))),
+ YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES
+ )
+
+ // Determine runtime rows and columns.
+ Index rows = expr.rows();
+ Index cols = expr.cols();
+ if(PlainObjectType::RowsAtCompileTime==1)
+ {
+ eigen_assert(expr.rows()==1 || expr.cols()==1);
+ rows = 1;
+ cols = expr.size();
+ }
+ else if(PlainObjectType::ColsAtCompileTime==1)
+ {
+ eigen_assert(expr.rows()==1 || expr.cols()==1);
+ rows = expr.size();
+ cols = 1;
+ }
+ // Verify that the sizes are valid.
+ eigen_assert(
+ (PlainObjectType::RowsAtCompileTime == Dynamic) || (PlainObjectType::RowsAtCompileTime == rows));
+ eigen_assert(
+ (PlainObjectType::ColsAtCompileTime == Dynamic) || (PlainObjectType::ColsAtCompileTime == cols));
+
+
+ // If this is a vector, we might be transposing, which means that stride should swap.
+ const bool transpose = PlainObjectType::IsVectorAtCompileTime && (rows != expr.rows());
+ // If the storage format differs, we also need to swap the stride.
+ const bool row_major = ((PlainObjectType::Flags)&RowMajorBit) != 0;
+ const bool expr_row_major = (Expression::Flags&RowMajorBit) != 0;
+ const bool storage_differs = (row_major != expr_row_major);
+
+ const bool swap_stride = (transpose != storage_differs);
+
+ // Determine expr's actual strides, resolving any defaults if zero.
+ const Index expr_inner_actual = resolveInnerStride(expr.innerStride());
+ const Index expr_outer_actual = resolveOuterStride(expr_inner_actual,
+ expr.outerStride(),
+ expr.rows(),
+ expr.cols(),
+ Expression::IsVectorAtCompileTime != 0,
+ expr_row_major);
+
+ // If this is a column-major row vector or row-major column vector, the inner-stride
+ // is arbitrary, so set it to either the compile-time inner stride or 1.
+ const bool row_vector = (rows == 1);
+ const bool col_vector = (cols == 1);
+ const Index inner_stride =
+ ( (!row_major && row_vector) || (row_major && col_vector) ) ?
+ ( StrideType::InnerStrideAtCompileTime > 0 ? Index(StrideType::InnerStrideAtCompileTime) : 1)
+ : swap_stride ? expr_outer_actual : expr_inner_actual;
+
+ // If this is a column-major column vector or row-major row vector, the outer-stride
+ // is arbitrary, so set it to either the compile-time outer stride or vector size.
+ const Index outer_stride =
+ ( (!row_major && col_vector) || (row_major && row_vector) ) ?
+ ( StrideType::OuterStrideAtCompileTime > 0 ? Index(StrideType::OuterStrideAtCompileTime) : rows * cols * inner_stride)
+ : swap_stride ? expr_inner_actual : expr_outer_actual;
+
+ // Check if given inner/outer strides are compatible with compile-time strides.
+ const bool inner_valid = (StrideType::InnerStrideAtCompileTime == Dynamic)
+ || (resolveInnerStride(Index(StrideType::InnerStrideAtCompileTime)) == inner_stride);
+ if (!inner_valid) {
+ return false;
+ }
+
+ const bool outer_valid = (StrideType::OuterStrideAtCompileTime == Dynamic)
+ || (resolveOuterStride(
+ inner_stride,
+ Index(StrideType::OuterStrideAtCompileTime),
+ rows, cols, PlainObjectType::IsVectorAtCompileTime != 0,
+ row_major)
+ == outer_stride);
+ if (!outer_valid) {
+ return false;
+ }
+
+ ::new (static_cast<Base*>(this)) Base(expr.data(), rows, cols);
+ ::new (&m_stride) StrideBase(
+ (StrideType::OuterStrideAtCompileTime == 0) ? 0 : outer_stride,
+ (StrideType::InnerStrideAtCompileTime == 0) ? 0 : inner_stride );
+ return true;
+ }
+
+ StrideBase m_stride;
+};
+
+/** \class Ref
+ * \ingroup Core_Module
+ *
+ * \brief A matrix or vector expression mapping an existing expression
+ *
+ * \tparam PlainObjectType the equivalent matrix type of the mapped data
+ * \tparam Options specifies the pointer alignment in bytes. It can be: \c #Aligned128, , \c #Aligned64, \c #Aligned32, \c #Aligned16, \c #Aligned8 or \c #Unaligned.
+ * The default is \c #Unaligned.
+ * \tparam StrideType optionally specifies strides. By default, Ref implies a contiguous storage along the inner dimension (inner stride==1),
+ * but accepts a variable outer stride (leading dimension).
+ * This can be overridden by specifying strides.
+ * The type passed here must be a specialization of the Stride template, see examples below.
+ *
+ * This class provides a way to write non-template functions taking Eigen objects as parameters while limiting the number of copies.
+ * A Ref<> object can represent either a const expression or a l-value:
+ * \code
+ * // in-out argument:
+ * void foo1(Ref<VectorXf> x);
+ *
+ * // read-only const argument:
+ * void foo2(const Ref<const VectorXf>& x);
+ * \endcode
+ *
+ * In the in-out case, the input argument must satisfy the constraints of the actual Ref<> type, otherwise a compilation issue will be triggered.
+ * By default, a Ref<VectorXf> can reference any dense vector expression of float having a contiguous memory layout.
+ * Likewise, a Ref<MatrixXf> can reference any column-major dense matrix expression of float whose column's elements are contiguously stored with
+ * the possibility to have a constant space in-between each column, i.e. the inner stride must be equal to 1, but the outer stride (or leading dimension)
+ * can be greater than the number of rows.
+ *
+ * In the const case, if the input expression does not match the above requirement, then it is evaluated into a temporary before being passed to the function.
+ * Here are some examples:
+ * \code
+ * MatrixXf A;
+ * VectorXf a;
+ * foo1(a.head()); // OK
+ * foo1(A.col()); // OK
+ * foo1(A.row()); // Compilation error because here innerstride!=1
+ * foo2(A.row()); // Compilation error because A.row() is a 1xN object while foo2 is expecting a Nx1 object
+ * foo2(A.row().transpose()); // The row is copied into a contiguous temporary
+ * foo2(2*a); // The expression is evaluated into a temporary
+ * foo2(A.col().segment(2,4)); // No temporary
+ * \endcode
+ *
+ * The range of inputs that can be referenced without temporary can be enlarged using the last two template parameters.
+ * Here is an example accepting an innerstride!=1:
+ * \code
+ * // in-out argument:
+ * void foo3(Ref<VectorXf,0,InnerStride<> > x);
+ * foo3(A.row()); // OK
+ * \endcode
+ * The downside here is that the function foo3 might be significantly slower than foo1 because it won't be able to exploit vectorization, and will involve more
+ * expensive address computations even if the input is contiguously stored in memory. To overcome this issue, one might propose to overload internally calling a
+ * template function, e.g.:
+ * \code
+ * // in the .h:
+ * void foo(const Ref<MatrixXf>& A);
+ * void foo(const Ref<MatrixXf,0,Stride<> >& A);
+ *
+ * // in the .cpp:
+ * template<typename TypeOfA> void foo_impl(const TypeOfA& A) {
+ * ... // crazy code goes here
+ * }
+ * void foo(const Ref<MatrixXf>& A) { foo_impl(A); }
+ * void foo(const Ref<MatrixXf,0,Stride<> >& A) { foo_impl(A); }
+ * \endcode
+ *
+ * See also the following stackoverflow questions for further references:
+ * - <a href="http://stackoverflow.com/questions/21132538/correct-usage-of-the-eigenref-class">Correct usage of the Eigen::Ref<> class</a>
+ *
+ * \sa PlainObjectBase::Map(), \ref TopicStorageOrders
+ */
+template<typename PlainObjectType, int Options, typename StrideType> class Ref
+ : public RefBase<Ref<PlainObjectType, Options, StrideType> >
+{
+ private:
+ typedef internal::traits<Ref> Traits;
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline Ref(const PlainObjectBase<Derived>& expr,
+ typename internal::enable_if<bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0);
+ public:
+
+ typedef RefBase<Ref> Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
+
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline Ref(PlainObjectBase<Derived>& expr,
+ typename internal::enable_if<bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
+ {
+ EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
+ // Construction must pass since we will not create temprary storage in the non-const case.
+ const bool success = Base::construct(expr.derived());
+ EIGEN_UNUSED_VARIABLE(success)
+ eigen_assert(success);
+ }
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline Ref(const DenseBase<Derived>& expr,
+ typename internal::enable_if<bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
+ #else
+ /** Implicit constructor from any dense expression */
+ template<typename Derived>
+ inline Ref(DenseBase<Derived>& expr)
+ #endif
+ {
+ EIGEN_STATIC_ASSERT(bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
+ EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
+ EIGEN_STATIC_ASSERT(!Derived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
+ // Construction must pass since we will not create temporary storage in the non-const case.
+ const bool success = Base::construct(expr.const_cast_derived());
+ EIGEN_UNUSED_VARIABLE(success)
+ eigen_assert(success);
+ }
+
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Ref)
+
+};
+
+// this is the const ref version
+template<typename TPlainObjectType, int Options, typename StrideType> class Ref<const TPlainObjectType, Options, StrideType>
+ : public RefBase<Ref<const TPlainObjectType, Options, StrideType> >
+{
+ typedef internal::traits<Ref> Traits;
+ public:
+
+ typedef RefBase<Ref> Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
+
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline Ref(const DenseBase<Derived>& expr,
+ typename internal::enable_if<bool(Traits::template match<Derived>::ScalarTypeMatch),Derived>::type* = 0)
+ {
+// std::cout << match_helper<Derived>::HasDirectAccess << "," << match_helper<Derived>::OuterStrideMatch << "," << match_helper<Derived>::InnerStrideMatch << "\n";
+// std::cout << int(StrideType::OuterStrideAtCompileTime) << " - " << int(Derived::OuterStrideAtCompileTime) << "\n";
+// std::cout << int(StrideType::InnerStrideAtCompileTime) << " - " << int(Derived::InnerStrideAtCompileTime) << "\n";
+ construct(expr.derived(), typename Traits::template match<Derived>::type());
+ }
+
+ EIGEN_DEVICE_FUNC inline Ref(const Ref& other) : Base(other) {
+ // copy constructor shall not copy the m_object, to avoid unnecessary malloc and copy
+ }
+
+ template<typename OtherRef>
+ EIGEN_DEVICE_FUNC inline Ref(const RefBase<OtherRef>& other) {
+ construct(other.derived(), typename Traits::template match<OtherRef>::type());
+ }
+
+ protected:
+
+ template<typename Expression>
+ EIGEN_DEVICE_FUNC void construct(const Expression& expr,internal::true_type)
+ {
+ // Check if we can use the underlying expr's storage directly, otherwise call the copy version.
+ if (!Base::construct(expr)) {
+ construct(expr, internal::false_type());
+ }
+ }
+
+ template<typename Expression>
+ EIGEN_DEVICE_FUNC void construct(const Expression& expr, internal::false_type)
+ {
+ internal::call_assignment_no_alias(m_object,expr,internal::assign_op<Scalar,Scalar>());
+ Base::construct(m_object);
+ }
+
+ protected:
+ TPlainObjectType m_object;
+};
+
+} // end namespace Eigen
+
+#endif // EIGEN_REF_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Replicate.h b/src/3rdparty/eigen/Eigen/src/Core/Replicate.h
new file mode 100644
index 000000000..ab5be7e64
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Replicate.h
@@ -0,0 +1,142 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_REPLICATE_H
+#define EIGEN_REPLICATE_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename MatrixType,int RowFactor,int ColFactor>
+struct traits<Replicate<MatrixType,RowFactor,ColFactor> >
+ : traits<MatrixType>
+{
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename traits<MatrixType>::StorageKind StorageKind;
+ typedef typename traits<MatrixType>::XprKind XprKind;
+ typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
+ typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
+ enum {
+ RowsAtCompileTime = RowFactor==Dynamic || int(MatrixType::RowsAtCompileTime)==Dynamic
+ ? Dynamic
+ : RowFactor * MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = ColFactor==Dynamic || int(MatrixType::ColsAtCompileTime)==Dynamic
+ ? Dynamic
+ : ColFactor * MatrixType::ColsAtCompileTime,
+ //FIXME we don't propagate the max sizes !!!
+ MaxRowsAtCompileTime = RowsAtCompileTime,
+ MaxColsAtCompileTime = ColsAtCompileTime,
+ IsRowMajor = MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1 ? 1
+ : MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1 ? 0
+ : (MatrixType::Flags & RowMajorBit) ? 1 : 0,
+
+ // FIXME enable DirectAccess with negative strides?
+ Flags = IsRowMajor ? RowMajorBit : 0
+ };
+};
+}
+
+/**
+ * \class Replicate
+ * \ingroup Core_Module
+ *
+ * \brief Expression of the multiple replication of a matrix or vector
+ *
+ * \tparam MatrixType the type of the object we are replicating
+ * \tparam RowFactor number of repetitions at compile time along the vertical direction, can be Dynamic.
+ * \tparam ColFactor number of repetitions at compile time along the horizontal direction, can be Dynamic.
+ *
+ * This class represents an expression of the multiple replication of a matrix or vector.
+ * It is the return type of DenseBase::replicate() and most of the time
+ * this is the only way it is used.
+ *
+ * \sa DenseBase::replicate()
+ */
+template<typename MatrixType,int RowFactor,int ColFactor> class Replicate
+ : public internal::dense_xpr_base< Replicate<MatrixType,RowFactor,ColFactor> >::type
+{
+ typedef typename internal::traits<Replicate>::MatrixTypeNested MatrixTypeNested;
+ typedef typename internal::traits<Replicate>::_MatrixTypeNested _MatrixTypeNested;
+ public:
+
+ typedef typename internal::dense_xpr_base<Replicate>::type Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Replicate)
+ typedef typename internal::remove_all<MatrixType>::type NestedExpression;
+
+ template<typename OriginalMatrixType>
+ EIGEN_DEVICE_FUNC
+ inline explicit Replicate(const OriginalMatrixType& matrix)
+ : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor)
+ {
+ EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
+ THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
+ eigen_assert(RowFactor!=Dynamic && ColFactor!=Dynamic);
+ }
+
+ template<typename OriginalMatrixType>
+ EIGEN_DEVICE_FUNC
+ inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor)
+ : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor)
+ {
+ EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
+ THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
+
+ EIGEN_DEVICE_FUNC
+ const _MatrixTypeNested& nestedExpression() const
+ {
+ return m_matrix;
+ }
+
+ protected:
+ MatrixTypeNested m_matrix;
+ const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor;
+ const internal::variable_if_dynamic<Index, ColFactor> m_colFactor;
+};
+
+/**
+ * \return an expression of the replication of \c *this
+ *
+ * Example: \include MatrixBase_replicate.cpp
+ * Output: \verbinclude MatrixBase_replicate.out
+ *
+ * \sa VectorwiseOp::replicate(), DenseBase::replicate(Index,Index), class Replicate
+ */
+template<typename Derived>
+template<int RowFactor, int ColFactor>
+EIGEN_DEVICE_FUNC const Replicate<Derived,RowFactor,ColFactor>
+DenseBase<Derived>::replicate() const
+{
+ return Replicate<Derived,RowFactor,ColFactor>(derived());
+}
+
+/**
+ * \return an expression of the replication of each column (or row) of \c *this
+ *
+ * Example: \include DirectionWise_replicate_int.cpp
+ * Output: \verbinclude DirectionWise_replicate_int.out
+ *
+ * \sa VectorwiseOp::replicate(), DenseBase::replicate(), class Replicate
+ */
+template<typename ExpressionType, int Direction>
+EIGEN_DEVICE_FUNC const typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
+VectorwiseOp<ExpressionType,Direction>::replicate(Index factor) const
+{
+ return typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
+ (_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1);
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_REPLICATE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Reshaped.h b/src/3rdparty/eigen/Eigen/src/Core/Reshaped.h
new file mode 100644
index 000000000..52de73b6f
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Reshaped.h
@@ -0,0 +1,454 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2014 yoco <peter.xiau@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_RESHAPED_H
+#define EIGEN_RESHAPED_H
+
+namespace Eigen {
+
+/** \class Reshaped
+ * \ingroup Core_Module
+ *
+ * \brief Expression of a fixed-size or dynamic-size reshape
+ *
+ * \tparam XprType the type of the expression in which we are taking a reshape
+ * \tparam Rows the number of rows of the reshape we are taking at compile time (optional)
+ * \tparam Cols the number of columns of the reshape we are taking at compile time (optional)
+ * \tparam Order can be ColMajor or RowMajor, default is ColMajor.
+ *
+ * This class represents an expression of either a fixed-size or dynamic-size reshape.
+ * It is the return type of DenseBase::reshaped(NRowsType,NColsType) and
+ * most of the time this is the only way it is used.
+ *
+ * However, in C++98, if you want to directly maniputate reshaped expressions,
+ * for instance if you want to write a function returning such an expression, you
+ * will need to use this class. In C++11, it is advised to use the \em auto
+ * keyword for such use cases.
+ *
+ * Here is an example illustrating the dynamic case:
+ * \include class_Reshaped.cpp
+ * Output: \verbinclude class_Reshaped.out
+ *
+ * Here is an example illustrating the fixed-size case:
+ * \include class_FixedReshaped.cpp
+ * Output: \verbinclude class_FixedReshaped.out
+ *
+ * \sa DenseBase::reshaped(NRowsType,NColsType)
+ */
+
+namespace internal {
+
+template<typename XprType, int Rows, int Cols, int Order>
+struct traits<Reshaped<XprType, Rows, Cols, Order> > : traits<XprType>
+{
+ typedef typename traits<XprType>::Scalar Scalar;
+ typedef typename traits<XprType>::StorageKind StorageKind;
+ typedef typename traits<XprType>::XprKind XprKind;
+ enum{
+ MatrixRows = traits<XprType>::RowsAtCompileTime,
+ MatrixCols = traits<XprType>::ColsAtCompileTime,
+ RowsAtCompileTime = Rows,
+ ColsAtCompileTime = Cols,
+ MaxRowsAtCompileTime = Rows,
+ MaxColsAtCompileTime = Cols,
+ XpxStorageOrder = ((int(traits<XprType>::Flags) & RowMajorBit) == RowMajorBit) ? RowMajor : ColMajor,
+ ReshapedStorageOrder = (RowsAtCompileTime == 1 && ColsAtCompileTime != 1) ? RowMajor
+ : (ColsAtCompileTime == 1 && RowsAtCompileTime != 1) ? ColMajor
+ : XpxStorageOrder,
+ HasSameStorageOrderAsXprType = (ReshapedStorageOrder == XpxStorageOrder),
+ InnerSize = (ReshapedStorageOrder==int(RowMajor)) ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
+ InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
+ ? int(inner_stride_at_compile_time<XprType>::ret)
+ : Dynamic,
+ OuterStrideAtCompileTime = Dynamic,
+
+ HasDirectAccess = internal::has_direct_access<XprType>::ret
+ && (Order==int(XpxStorageOrder))
+ && ((evaluator<XprType>::Flags&LinearAccessBit)==LinearAccessBit),
+
+ MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0)
+ && (InnerStrideAtCompileTime == 1)
+ ? PacketAccessBit : 0,
+ //MaskAlignedBit = ((OuterStrideAtCompileTime!=Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % 16) == 0)) ? AlignedBit : 0,
+ FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
+ FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
+ FlagsRowMajorBit = (ReshapedStorageOrder==int(RowMajor)) ? RowMajorBit : 0,
+ FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0,
+ Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~RowMajorBit) | MaskPacketAccessBit),
+
+ Flags = (Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit | FlagsDirectAccessBit)
+ };
+};
+
+template<typename XprType, int Rows, int Cols, int Order, bool HasDirectAccess> class ReshapedImpl_dense;
+
+} // end namespace internal
+
+template<typename XprType, int Rows, int Cols, int Order, typename StorageKind> class ReshapedImpl;
+
+template<typename XprType, int Rows, int Cols, int Order> class Reshaped
+ : public ReshapedImpl<XprType, Rows, Cols, Order, typename internal::traits<XprType>::StorageKind>
+{
+ typedef ReshapedImpl<XprType, Rows, Cols, Order, typename internal::traits<XprType>::StorageKind> Impl;
+ public:
+ //typedef typename Impl::Base Base;
+ typedef Impl Base;
+ EIGEN_GENERIC_PUBLIC_INTERFACE(Reshaped)
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reshaped)
+
+ /** Fixed-size constructor
+ */
+ EIGEN_DEVICE_FUNC
+ inline Reshaped(XprType& xpr)
+ : Impl(xpr)
+ {
+ EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
+ eigen_assert(Rows * Cols == xpr.rows() * xpr.cols());
+ }
+
+ /** Dynamic-size constructor
+ */
+ EIGEN_DEVICE_FUNC
+ inline Reshaped(XprType& xpr,
+ Index reshapeRows, Index reshapeCols)
+ : Impl(xpr, reshapeRows, reshapeCols)
+ {
+ eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==reshapeRows)
+ && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==reshapeCols));
+ eigen_assert(reshapeRows * reshapeCols == xpr.rows() * xpr.cols());
+ }
+};
+
+// The generic default implementation for dense reshape simply forward to the internal::ReshapedImpl_dense
+// that must be specialized for direct and non-direct access...
+template<typename XprType, int Rows, int Cols, int Order>
+class ReshapedImpl<XprType, Rows, Cols, Order, Dense>
+ : public internal::ReshapedImpl_dense<XprType, Rows, Cols, Order,internal::traits<Reshaped<XprType,Rows,Cols,Order> >::HasDirectAccess>
+{
+ typedef internal::ReshapedImpl_dense<XprType, Rows, Cols, Order,internal::traits<Reshaped<XprType,Rows,Cols,Order> >::HasDirectAccess> Impl;
+ public:
+ typedef Impl Base;
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl)
+ EIGEN_DEVICE_FUNC inline ReshapedImpl(XprType& xpr) : Impl(xpr) {}
+ EIGEN_DEVICE_FUNC inline ReshapedImpl(XprType& xpr, Index reshapeRows, Index reshapeCols)
+ : Impl(xpr, reshapeRows, reshapeCols) {}
+};
+
+namespace internal {
+
+/** \internal Internal implementation of dense Reshaped in the general case. */
+template<typename XprType, int Rows, int Cols, int Order>
+class ReshapedImpl_dense<XprType,Rows,Cols,Order,false>
+ : public internal::dense_xpr_base<Reshaped<XprType, Rows, Cols, Order> >::type
+{
+ typedef Reshaped<XprType, Rows, Cols, Order> ReshapedType;
+ public:
+
+ typedef typename internal::dense_xpr_base<ReshapedType>::type Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType)
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense)
+
+ typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested;
+ typedef typename internal::remove_all<XprType>::type NestedExpression;
+
+ class InnerIterator;
+
+ /** Fixed-size constructor
+ */
+ EIGEN_DEVICE_FUNC
+ inline ReshapedImpl_dense(XprType& xpr)
+ : m_xpr(xpr), m_rows(Rows), m_cols(Cols)
+ {}
+
+ /** Dynamic-size constructor
+ */
+ EIGEN_DEVICE_FUNC
+ inline ReshapedImpl_dense(XprType& xpr, Index nRows, Index nCols)
+ : m_xpr(xpr), m_rows(nRows), m_cols(nCols)
+ {}
+
+ EIGEN_DEVICE_FUNC Index rows() const { return m_rows; }
+ EIGEN_DEVICE_FUNC Index cols() const { return m_cols; }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** \sa MapBase::data() */
+ EIGEN_DEVICE_FUNC inline const Scalar* data() const;
+ EIGEN_DEVICE_FUNC inline Index innerStride() const;
+ EIGEN_DEVICE_FUNC inline Index outerStride() const;
+ #endif
+
+ /** \returns the nested expression */
+ EIGEN_DEVICE_FUNC
+ const typename internal::remove_all<XprType>::type&
+ nestedExpression() const { return m_xpr; }
+
+ /** \returns the nested expression */
+ EIGEN_DEVICE_FUNC
+ typename internal::remove_reference<XprType>::type&
+ nestedExpression() { return m_xpr; }
+
+ protected:
+
+ MatrixTypeNested m_xpr;
+ const internal::variable_if_dynamic<Index, Rows> m_rows;
+ const internal::variable_if_dynamic<Index, Cols> m_cols;
+};
+
+
+/** \internal Internal implementation of dense Reshaped in the direct access case. */
+template<typename XprType, int Rows, int Cols, int Order>
+class ReshapedImpl_dense<XprType, Rows, Cols, Order, true>
+ : public MapBase<Reshaped<XprType, Rows, Cols, Order> >
+{
+ typedef Reshaped<XprType, Rows, Cols, Order> ReshapedType;
+ typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested;
+ public:
+
+ typedef MapBase<ReshapedType> Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType)
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense)
+
+ /** Fixed-size constructor
+ */
+ EIGEN_DEVICE_FUNC
+ inline ReshapedImpl_dense(XprType& xpr)
+ : Base(xpr.data()), m_xpr(xpr)
+ {}
+
+ /** Dynamic-size constructor
+ */
+ EIGEN_DEVICE_FUNC
+ inline ReshapedImpl_dense(XprType& xpr, Index nRows, Index nCols)
+ : Base(xpr.data(), nRows, nCols),
+ m_xpr(xpr)
+ {}
+
+ EIGEN_DEVICE_FUNC
+ const typename internal::remove_all<XprTypeNested>::type& nestedExpression() const
+ {
+ return m_xpr;
+ }
+
+ EIGEN_DEVICE_FUNC
+ XprType& nestedExpression() { return m_xpr; }
+
+ /** \sa MapBase::innerStride() */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const
+ {
+ return m_xpr.innerStride();
+ }
+
+ /** \sa MapBase::outerStride() */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const
+ {
+ return ((Flags&RowMajorBit)==RowMajorBit) ? this->cols() : this->rows();
+ }
+
+ protected:
+
+ XprTypeNested m_xpr;
+};
+
+// Evaluators
+template<typename ArgType, int Rows, int Cols, int Order, bool HasDirectAccess> struct reshaped_evaluator;
+
+template<typename ArgType, int Rows, int Cols, int Order>
+struct evaluator<Reshaped<ArgType, Rows, Cols, Order> >
+ : reshaped_evaluator<ArgType, Rows, Cols, Order, traits<Reshaped<ArgType,Rows,Cols,Order> >::HasDirectAccess>
+{
+ typedef Reshaped<ArgType, Rows, Cols, Order> XprType;
+ typedef typename XprType::Scalar Scalar;
+ // TODO: should check for smaller packet types
+ typedef typename packet_traits<Scalar>::type PacketScalar;
+
+ enum {
+ CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
+ HasDirectAccess = traits<XprType>::HasDirectAccess,
+
+// RowsAtCompileTime = traits<XprType>::RowsAtCompileTime,
+// ColsAtCompileTime = traits<XprType>::ColsAtCompileTime,
+// MaxRowsAtCompileTime = traits<XprType>::MaxRowsAtCompileTime,
+// MaxColsAtCompileTime = traits<XprType>::MaxColsAtCompileTime,
+//
+// InnerStrideAtCompileTime = traits<XprType>::HasSameStorageOrderAsXprType
+// ? int(inner_stride_at_compile_time<ArgType>::ret)
+// : Dynamic,
+// OuterStrideAtCompileTime = Dynamic,
+
+ FlagsLinearAccessBit = (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1 || HasDirectAccess) ? LinearAccessBit : 0,
+ FlagsRowMajorBit = (traits<XprType>::ReshapedStorageOrder==int(RowMajor)) ? RowMajorBit : 0,
+ FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0,
+ Flags0 = evaluator<ArgType>::Flags & (HereditaryBits & ~RowMajorBit),
+ Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit | FlagsDirectAccessBit,
+
+ PacketAlignment = unpacket_traits<PacketScalar>::alignment,
+ Alignment = evaluator<ArgType>::Alignment
+ };
+ typedef reshaped_evaluator<ArgType, Rows, Cols, Order, HasDirectAccess> reshaped_evaluator_type;
+ EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) : reshaped_evaluator_type(xpr)
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+};
+
+template<typename ArgType, int Rows, int Cols, int Order>
+struct reshaped_evaluator<ArgType, Rows, Cols, Order, /* HasDirectAccess */ false>
+ : evaluator_base<Reshaped<ArgType, Rows, Cols, Order> >
+{
+ typedef Reshaped<ArgType, Rows, Cols, Order> XprType;
+
+ enum {
+ CoeffReadCost = evaluator<ArgType>::CoeffReadCost /* TODO + cost of index computations */,
+
+ Flags = (evaluator<ArgType>::Flags & (HereditaryBits /*| LinearAccessBit | DirectAccessBit*/)),
+
+ Alignment = 0
+ };
+
+ EIGEN_DEVICE_FUNC explicit reshaped_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr)
+ {
+ EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
+ }
+
+ typedef typename XprType::Scalar Scalar;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ typedef std::pair<Index, Index> RowCol;
+
+ inline RowCol index_remap(Index rowId, Index colId) const
+ {
+ if(Order==ColMajor)
+ {
+ const Index nth_elem_idx = colId * m_xpr.rows() + rowId;
+ return RowCol(nth_elem_idx % m_xpr.nestedExpression().rows(),
+ nth_elem_idx / m_xpr.nestedExpression().rows());
+ }
+ else
+ {
+ const Index nth_elem_idx = colId + rowId * m_xpr.cols();
+ return RowCol(nth_elem_idx / m_xpr.nestedExpression().cols(),
+ nth_elem_idx % m_xpr.nestedExpression().cols());
+ }
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline Scalar& coeffRef(Index rowId, Index colId)
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(XprType)
+ const RowCol row_col = index_remap(rowId, colId);
+ return m_argImpl.coeffRef(row_col.first, row_col.second);
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index rowId, Index colId) const
+ {
+ const RowCol row_col = index_remap(rowId, colId);
+ return m_argImpl.coeffRef(row_col.first, row_col.second);
+ }
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const
+ {
+ const RowCol row_col = index_remap(rowId, colId);
+ return m_argImpl.coeff(row_col.first, row_col.second);
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline Scalar& coeffRef(Index index)
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(XprType)
+ const RowCol row_col = index_remap(Rows == 1 ? 0 : index,
+ Rows == 1 ? index : 0);
+ return m_argImpl.coeffRef(row_col.first, row_col.second);
+
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const Scalar& coeffRef(Index index) const
+ {
+ const RowCol row_col = index_remap(Rows == 1 ? 0 : index,
+ Rows == 1 ? index : 0);
+ return m_argImpl.coeffRef(row_col.first, row_col.second);
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline const CoeffReturnType coeff(Index index) const
+ {
+ const RowCol row_col = index_remap(Rows == 1 ? 0 : index,
+ Rows == 1 ? index : 0);
+ return m_argImpl.coeff(row_col.first, row_col.second);
+ }
+#if 0
+ EIGEN_DEVICE_FUNC
+ template<int LoadMode>
+ inline PacketScalar packet(Index rowId, Index colId) const
+ {
+ const RowCol row_col = index_remap(rowId, colId);
+ return m_argImpl.template packet<Unaligned>(row_col.first, row_col.second);
+
+ }
+
+ template<int LoadMode>
+ EIGEN_DEVICE_FUNC
+ inline void writePacket(Index rowId, Index colId, const PacketScalar& val)
+ {
+ const RowCol row_col = index_remap(rowId, colId);
+ m_argImpl.const_cast_derived().template writePacket<Unaligned>
+ (row_col.first, row_col.second, val);
+ }
+
+ template<int LoadMode>
+ EIGEN_DEVICE_FUNC
+ inline PacketScalar packet(Index index) const
+ {
+ const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index,
+ RowsAtCompileTime == 1 ? index : 0);
+ return m_argImpl.template packet<Unaligned>(row_col.first, row_col.second);
+ }
+
+ template<int LoadMode>
+ EIGEN_DEVICE_FUNC
+ inline void writePacket(Index index, const PacketScalar& val)
+ {
+ const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index,
+ RowsAtCompileTime == 1 ? index : 0);
+ return m_argImpl.template packet<Unaligned>(row_col.first, row_col.second, val);
+ }
+#endif
+protected:
+
+ evaluator<ArgType> m_argImpl;
+ const XprType& m_xpr;
+
+};
+
+template<typename ArgType, int Rows, int Cols, int Order>
+struct reshaped_evaluator<ArgType, Rows, Cols, Order, /* HasDirectAccess */ true>
+: mapbase_evaluator<Reshaped<ArgType, Rows, Cols, Order>,
+ typename Reshaped<ArgType, Rows, Cols, Order>::PlainObject>
+{
+ typedef Reshaped<ArgType, Rows, Cols, Order> XprType;
+ typedef typename XprType::Scalar Scalar;
+
+ EIGEN_DEVICE_FUNC explicit reshaped_evaluator(const XprType& xpr)
+ : mapbase_evaluator<XprType, typename XprType::PlainObject>(xpr)
+ {
+ // TODO: for the 3.4 release, this should be turned to an internal assertion, but let's keep it as is for the beta lifetime
+ eigen_assert(((internal::UIntPtr(xpr.data()) % EIGEN_PLAIN_ENUM_MAX(1,evaluator<XprType>::Alignment)) == 0) && "data is not aligned");
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_RESHAPED_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/ReturnByValue.h b/src/3rdparty/eigen/Eigen/src/Core/ReturnByValue.h
new file mode 100644
index 000000000..4dad13ea1
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/ReturnByValue.h
@@ -0,0 +1,119 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_RETURNBYVALUE_H
+#define EIGEN_RETURNBYVALUE_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Derived>
+struct traits<ReturnByValue<Derived> >
+ : public traits<typename traits<Derived>::ReturnType>
+{
+ enum {
+ // We're disabling the DirectAccess because e.g. the constructor of
+ // the Block-with-DirectAccess expression requires to have a coeffRef method.
+ // Also, we don't want to have to implement the stride stuff.
+ Flags = (traits<typename traits<Derived>::ReturnType>::Flags
+ | EvalBeforeNestingBit) & ~DirectAccessBit
+ };
+};
+
+/* The ReturnByValue object doesn't even have a coeff() method.
+ * So the only way that nesting it in an expression can work, is by evaluating it into a plain matrix.
+ * So internal::nested always gives the plain return matrix type.
+ *
+ * FIXME: I don't understand why we need this specialization: isn't this taken care of by the EvalBeforeNestingBit ??
+ * Answer: EvalBeforeNestingBit should be deprecated since we have the evaluators
+ */
+template<typename Derived,int n,typename PlainObject>
+struct nested_eval<ReturnByValue<Derived>, n, PlainObject>
+{
+ typedef typename traits<Derived>::ReturnType type;
+};
+
+} // end namespace internal
+
+/** \class ReturnByValue
+ * \ingroup Core_Module
+ *
+ */
+template<typename Derived> class ReturnByValue
+ : public internal::dense_xpr_base< ReturnByValue<Derived> >::type, internal::no_assignment_operator
+{
+ public:
+ typedef typename internal::traits<Derived>::ReturnType ReturnType;
+
+ typedef typename internal::dense_xpr_base<ReturnByValue>::type Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(ReturnByValue)
+
+ template<typename Dest>
+ EIGEN_DEVICE_FUNC
+ inline void evalTo(Dest& dst) const
+ { static_cast<const Derived*>(this)->evalTo(dst); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return static_cast<const Derived*>(this)->rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return static_cast<const Derived*>(this)->cols(); }
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+#define Unusable YOU_ARE_TRYING_TO_ACCESS_A_SINGLE_COEFFICIENT_IN_A_SPECIAL_EXPRESSION_WHERE_THAT_IS_NOT_ALLOWED_BECAUSE_THAT_WOULD_BE_INEFFICIENT
+ class Unusable{
+ Unusable(const Unusable&) {}
+ Unusable& operator=(const Unusable&) {return *this;}
+ };
+ const Unusable& coeff(Index) const { return *reinterpret_cast<const Unusable*>(this); }
+ const Unusable& coeff(Index,Index) const { return *reinterpret_cast<const Unusable*>(this); }
+ Unusable& coeffRef(Index) { return *reinterpret_cast<Unusable*>(this); }
+ Unusable& coeffRef(Index,Index) { return *reinterpret_cast<Unusable*>(this); }
+#undef Unusable
+#endif
+};
+
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC Derived& DenseBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other)
+{
+ other.evalTo(derived());
+ return derived();
+}
+
+namespace internal {
+
+// Expression is evaluated in a temporary; default implementation of Assignment is bypassed so that
+// when a ReturnByValue expression is assigned, the evaluator is not constructed.
+// TODO: Finalize port to new regime; ReturnByValue should not exist in the expression world
+
+template<typename Derived>
+struct evaluator<ReturnByValue<Derived> >
+ : public evaluator<typename internal::traits<Derived>::ReturnType>
+{
+ typedef ReturnByValue<Derived> XprType;
+ typedef typename internal::traits<Derived>::ReturnType PlainObject;
+ typedef evaluator<PlainObject> Base;
+
+ EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr)
+ : m_result(xpr.rows(), xpr.cols())
+ {
+ ::new (static_cast<Base*>(this)) Base(m_result);
+ xpr.evalTo(m_result);
+ }
+
+protected:
+ PlainObject m_result;
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_RETURNBYVALUE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Reverse.h b/src/3rdparty/eigen/Eigen/src/Core/Reverse.h
new file mode 100644
index 000000000..28cdd76ac
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Reverse.h
@@ -0,0 +1,217 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2009 Ricard Marxer <email@ricardmarxer.com>
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_REVERSE_H
+#define EIGEN_REVERSE_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename MatrixType, int Direction>
+struct traits<Reverse<MatrixType, Direction> >
+ : traits<MatrixType>
+{
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename traits<MatrixType>::StorageKind StorageKind;
+ typedef typename traits<MatrixType>::XprKind XprKind;
+ typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
+ typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
+ enum {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
+ Flags = _MatrixTypeNested::Flags & (RowMajorBit | LvalueBit)
+ };
+};
+
+template<typename PacketType, bool ReversePacket> struct reverse_packet_cond
+{
+ static inline PacketType run(const PacketType& x) { return preverse(x); }
+};
+
+template<typename PacketType> struct reverse_packet_cond<PacketType,false>
+{
+ static inline PacketType run(const PacketType& x) { return x; }
+};
+
+} // end namespace internal
+
+/** \class Reverse
+ * \ingroup Core_Module
+ *
+ * \brief Expression of the reverse of a vector or matrix
+ *
+ * \tparam MatrixType the type of the object of which we are taking the reverse
+ * \tparam Direction defines the direction of the reverse operation, can be Vertical, Horizontal, or BothDirections
+ *
+ * This class represents an expression of the reverse of a vector.
+ * It is the return type of MatrixBase::reverse() and VectorwiseOp::reverse()
+ * and most of the time this is the only way it is used.
+ *
+ * \sa MatrixBase::reverse(), VectorwiseOp::reverse()
+ */
+template<typename MatrixType, int Direction> class Reverse
+ : public internal::dense_xpr_base< Reverse<MatrixType, Direction> >::type
+{
+ public:
+
+ typedef typename internal::dense_xpr_base<Reverse>::type Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Reverse)
+ typedef typename internal::remove_all<MatrixType>::type NestedExpression;
+ using Base::IsRowMajor;
+
+ protected:
+ enum {
+ PacketSize = internal::packet_traits<Scalar>::size,
+ IsColMajor = !IsRowMajor,
+ ReverseRow = (Direction == Vertical) || (Direction == BothDirections),
+ ReverseCol = (Direction == Horizontal) || (Direction == BothDirections),
+ OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
+ OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1,
+ ReversePacket = (Direction == BothDirections)
+ || ((Direction == Vertical) && IsColMajor)
+ || ((Direction == Horizontal) && IsRowMajor)
+ };
+ typedef internal::reverse_packet_cond<PacketScalar,ReversePacket> reverse_packet;
+ public:
+
+ EIGEN_DEVICE_FUNC explicit inline Reverse(const MatrixType& matrix) : m_matrix(matrix) { }
+
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reverse)
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
+
+ EIGEN_DEVICE_FUNC inline Index innerStride() const
+ {
+ return -m_matrix.innerStride();
+ }
+
+ EIGEN_DEVICE_FUNC const typename internal::remove_all<typename MatrixType::Nested>::type&
+ nestedExpression() const
+ {
+ return m_matrix;
+ }
+
+ protected:
+ typename MatrixType::Nested m_matrix;
+};
+
+/** \returns an expression of the reverse of *this.
+ *
+ * Example: \include MatrixBase_reverse.cpp
+ * Output: \verbinclude MatrixBase_reverse.out
+ *
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline typename DenseBase<Derived>::ReverseReturnType
+DenseBase<Derived>::reverse()
+{
+ return ReverseReturnType(derived());
+}
+
+
+//reverse const overload moved DenseBase.h due to a CUDA compiler bug
+
+/** This is the "in place" version of reverse: it reverses \c *this.
+ *
+ * In most cases it is probably better to simply use the reversed expression
+ * of a matrix. However, when reversing the matrix data itself is really needed,
+ * then this "in-place" version is probably the right choice because it provides
+ * the following additional benefits:
+ * - less error prone: doing the same operation with .reverse() requires special care:
+ * \code m = m.reverse().eval(); \endcode
+ * - this API enables reverse operations without the need for a temporary
+ * - it allows future optimizations (cache friendliness, etc.)
+ *
+ * \sa VectorwiseOp::reverseInPlace(), reverse() */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline void DenseBase<Derived>::reverseInPlace()
+{
+ if(cols()>rows())
+ {
+ Index half = cols()/2;
+ leftCols(half).swap(rightCols(half).reverse());
+ if((cols()%2)==1)
+ {
+ Index half2 = rows()/2;
+ col(half).head(half2).swap(col(half).tail(half2).reverse());
+ }
+ }
+ else
+ {
+ Index half = rows()/2;
+ topRows(half).swap(bottomRows(half).reverse());
+ if((rows()%2)==1)
+ {
+ Index half2 = cols()/2;
+ row(half).head(half2).swap(row(half).tail(half2).reverse());
+ }
+ }
+}
+
+namespace internal {
+
+template<int Direction>
+struct vectorwise_reverse_inplace_impl;
+
+template<>
+struct vectorwise_reverse_inplace_impl<Vertical>
+{
+ template<typename ExpressionType>
+ static void run(ExpressionType &xpr)
+ {
+ const int HalfAtCompileTime = ExpressionType::RowsAtCompileTime==Dynamic?Dynamic:ExpressionType::RowsAtCompileTime/2;
+ Index half = xpr.rows()/2;
+ xpr.topRows(fix<HalfAtCompileTime>(half))
+ .swap(xpr.bottomRows(fix<HalfAtCompileTime>(half)).colwise().reverse());
+ }
+};
+
+template<>
+struct vectorwise_reverse_inplace_impl<Horizontal>
+{
+ template<typename ExpressionType>
+ static void run(ExpressionType &xpr)
+ {
+ const int HalfAtCompileTime = ExpressionType::ColsAtCompileTime==Dynamic?Dynamic:ExpressionType::ColsAtCompileTime/2;
+ Index half = xpr.cols()/2;
+ xpr.leftCols(fix<HalfAtCompileTime>(half))
+ .swap(xpr.rightCols(fix<HalfAtCompileTime>(half)).rowwise().reverse());
+ }
+};
+
+} // end namespace internal
+
+/** This is the "in place" version of VectorwiseOp::reverse: it reverses each column or row of \c *this.
+ *
+ * In most cases it is probably better to simply use the reversed expression
+ * of a matrix. However, when reversing the matrix data itself is really needed,
+ * then this "in-place" version is probably the right choice because it provides
+ * the following additional benefits:
+ * - less error prone: doing the same operation with .reverse() requires special care:
+ * \code m = m.reverse().eval(); \endcode
+ * - this API enables reverse operations without the need for a temporary
+ *
+ * \sa DenseBase::reverseInPlace(), reverse() */
+template<typename ExpressionType, int Direction>
+EIGEN_DEVICE_FUNC void VectorwiseOp<ExpressionType,Direction>::reverseInPlace()
+{
+ internal::vectorwise_reverse_inplace_impl<Direction>::run(m_matrix);
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_REVERSE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Select.h b/src/3rdparty/eigen/Eigen/src/Core/Select.h
new file mode 100644
index 000000000..7c86bf87c
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Select.h
@@ -0,0 +1,164 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SELECT_H
+#define EIGEN_SELECT_H
+
+namespace Eigen {
+
+/** \class Select
+ * \ingroup Core_Module
+ *
+ * \brief Expression of a coefficient wise version of the C++ ternary operator ?:
+ *
+ * \param ConditionMatrixType the type of the \em condition expression which must be a boolean matrix
+ * \param ThenMatrixType the type of the \em then expression
+ * \param ElseMatrixType the type of the \em else expression
+ *
+ * This class represents an expression of a coefficient wise version of the C++ ternary operator ?:.
+ * It is the return type of DenseBase::select() and most of the time this is the only way it is used.
+ *
+ * \sa DenseBase::select(const DenseBase<ThenDerived>&, const DenseBase<ElseDerived>&) const
+ */
+
+namespace internal {
+template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
+struct traits<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
+ : traits<ThenMatrixType>
+{
+ typedef typename traits<ThenMatrixType>::Scalar Scalar;
+ typedef Dense StorageKind;
+ typedef typename traits<ThenMatrixType>::XprKind XprKind;
+ typedef typename ConditionMatrixType::Nested ConditionMatrixNested;
+ typedef typename ThenMatrixType::Nested ThenMatrixNested;
+ typedef typename ElseMatrixType::Nested ElseMatrixNested;
+ enum {
+ RowsAtCompileTime = ConditionMatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = ConditionMatrixType::ColsAtCompileTime,
+ MaxRowsAtCompileTime = ConditionMatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = ConditionMatrixType::MaxColsAtCompileTime,
+ Flags = (unsigned int)ThenMatrixType::Flags & ElseMatrixType::Flags & RowMajorBit
+ };
+};
+}
+
+template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
+class Select : public internal::dense_xpr_base< Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >::type,
+ internal::no_assignment_operator
+{
+ public:
+
+ typedef typename internal::dense_xpr_base<Select>::type Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Select)
+
+ inline EIGEN_DEVICE_FUNC
+ Select(const ConditionMatrixType& a_conditionMatrix,
+ const ThenMatrixType& a_thenMatrix,
+ const ElseMatrixType& a_elseMatrix)
+ : m_condition(a_conditionMatrix), m_then(a_thenMatrix), m_else(a_elseMatrix)
+ {
+ eigen_assert(m_condition.rows() == m_then.rows() && m_condition.rows() == m_else.rows());
+ eigen_assert(m_condition.cols() == m_then.cols() && m_condition.cols() == m_else.cols());
+ }
+
+ inline EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ Index rows() const EIGEN_NOEXCEPT { return m_condition.rows(); }
+ inline EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ Index cols() const EIGEN_NOEXCEPT { return m_condition.cols(); }
+
+ inline EIGEN_DEVICE_FUNC
+ const Scalar coeff(Index i, Index j) const
+ {
+ if (m_condition.coeff(i,j))
+ return m_then.coeff(i,j);
+ else
+ return m_else.coeff(i,j);
+ }
+
+ inline EIGEN_DEVICE_FUNC
+ const Scalar coeff(Index i) const
+ {
+ if (m_condition.coeff(i))
+ return m_then.coeff(i);
+ else
+ return m_else.coeff(i);
+ }
+
+ inline EIGEN_DEVICE_FUNC const ConditionMatrixType& conditionMatrix() const
+ {
+ return m_condition;
+ }
+
+ inline EIGEN_DEVICE_FUNC const ThenMatrixType& thenMatrix() const
+ {
+ return m_then;
+ }
+
+ inline EIGEN_DEVICE_FUNC const ElseMatrixType& elseMatrix() const
+ {
+ return m_else;
+ }
+
+ protected:
+ typename ConditionMatrixType::Nested m_condition;
+ typename ThenMatrixType::Nested m_then;
+ typename ElseMatrixType::Nested m_else;
+};
+
+
+/** \returns a matrix where each coefficient (i,j) is equal to \a thenMatrix(i,j)
+ * if \c *this(i,j), and \a elseMatrix(i,j) otherwise.
+ *
+ * Example: \include MatrixBase_select.cpp
+ * Output: \verbinclude MatrixBase_select.out
+ *
+ * \sa class Select
+ */
+template<typename Derived>
+template<typename ThenDerived,typename ElseDerived>
+inline EIGEN_DEVICE_FUNC const Select<Derived,ThenDerived,ElseDerived>
+DenseBase<Derived>::select(const DenseBase<ThenDerived>& thenMatrix,
+ const DenseBase<ElseDerived>& elseMatrix) const
+{
+ return Select<Derived,ThenDerived,ElseDerived>(derived(), thenMatrix.derived(), elseMatrix.derived());
+}
+
+/** Version of DenseBase::select(const DenseBase&, const DenseBase&) with
+ * the \em else expression being a scalar value.
+ *
+ * \sa DenseBase::select(const DenseBase<ThenDerived>&, const DenseBase<ElseDerived>&) const, class Select
+ */
+template<typename Derived>
+template<typename ThenDerived>
+inline EIGEN_DEVICE_FUNC const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
+DenseBase<Derived>::select(const DenseBase<ThenDerived>& thenMatrix,
+ const typename ThenDerived::Scalar& elseScalar) const
+{
+ return Select<Derived,ThenDerived,typename ThenDerived::ConstantReturnType>(
+ derived(), thenMatrix.derived(), ThenDerived::Constant(rows(),cols(),elseScalar));
+}
+
+/** Version of DenseBase::select(const DenseBase&, const DenseBase&) with
+ * the \em then expression being a scalar value.
+ *
+ * \sa DenseBase::select(const DenseBase<ThenDerived>&, const DenseBase<ElseDerived>&) const, class Select
+ */
+template<typename Derived>
+template<typename ElseDerived>
+inline EIGEN_DEVICE_FUNC const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
+DenseBase<Derived>::select(const typename ElseDerived::Scalar& thenScalar,
+ const DenseBase<ElseDerived>& elseMatrix) const
+{
+ return Select<Derived,typename ElseDerived::ConstantReturnType,ElseDerived>(
+ derived(), ElseDerived::Constant(rows(),cols(),thenScalar), elseMatrix.derived());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_SELECT_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/SelfAdjointView.h b/src/3rdparty/eigen/Eigen/src/Core/SelfAdjointView.h
new file mode 100644
index 000000000..8ce3b372a
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/SelfAdjointView.h
@@ -0,0 +1,365 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SELFADJOINTMATRIX_H
+#define EIGEN_SELFADJOINTMATRIX_H
+
+namespace Eigen {
+
+/** \class SelfAdjointView
+ * \ingroup Core_Module
+ *
+ *
+ * \brief Expression of a selfadjoint matrix from a triangular part of a dense matrix
+ *
+ * \param MatrixType the type of the dense matrix storing the coefficients
+ * \param TriangularPart can be either \c #Lower or \c #Upper
+ *
+ * This class is an expression of a sefladjoint matrix from a triangular part of a matrix
+ * with given dense storage of the coefficients. It is the return type of MatrixBase::selfadjointView()
+ * and most of the time this is the only way that it is used.
+ *
+ * \sa class TriangularBase, MatrixBase::selfadjointView()
+ */
+
+namespace internal {
+template<typename MatrixType, unsigned int UpLo>
+struct traits<SelfAdjointView<MatrixType, UpLo> > : traits<MatrixType>
+{
+ typedef typename ref_selector<MatrixType>::non_const_type MatrixTypeNested;
+ typedef typename remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned;
+ typedef MatrixType ExpressionType;
+ typedef typename MatrixType::PlainObject FullMatrixType;
+ enum {
+ Mode = UpLo | SelfAdjoint,
+ FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
+ Flags = MatrixTypeNestedCleaned::Flags & (HereditaryBits|FlagsLvalueBit)
+ & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit)) // FIXME these flags should be preserved
+ };
+};
+}
+
+
+template<typename _MatrixType, unsigned int UpLo> class SelfAdjointView
+ : public TriangularBase<SelfAdjointView<_MatrixType, UpLo> >
+{
+ public:
+
+ typedef _MatrixType MatrixType;
+ typedef TriangularBase<SelfAdjointView> Base;
+ typedef typename internal::traits<SelfAdjointView>::MatrixTypeNested MatrixTypeNested;
+ typedef typename internal::traits<SelfAdjointView>::MatrixTypeNestedCleaned MatrixTypeNestedCleaned;
+ typedef MatrixTypeNestedCleaned NestedExpression;
+
+ /** \brief The type of coefficients in this matrix */
+ typedef typename internal::traits<SelfAdjointView>::Scalar Scalar;
+ typedef typename MatrixType::StorageIndex StorageIndex;
+ typedef typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type MatrixConjugateReturnType;
+ typedef SelfAdjointView<typename internal::add_const<MatrixType>::type, UpLo> ConstSelfAdjointView;
+
+ enum {
+ Mode = internal::traits<SelfAdjointView>::Mode,
+ Flags = internal::traits<SelfAdjointView>::Flags,
+ TransposeMode = ((int(Mode) & int(Upper)) ? Lower : 0) | ((int(Mode) & int(Lower)) ? Upper : 0)
+ };
+ typedef typename MatrixType::PlainObject PlainObject;
+
+ EIGEN_DEVICE_FUNC
+ explicit inline SelfAdjointView(MatrixType& matrix) : m_matrix(matrix)
+ {
+ EIGEN_STATIC_ASSERT(UpLo==Lower || UpLo==Upper,SELFADJOINTVIEW_ACCEPTS_UPPER_AND_LOWER_MODE_ONLY);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const EIGEN_NOEXCEPT { return m_matrix.outerStride(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const EIGEN_NOEXCEPT { return m_matrix.innerStride(); }
+
+ /** \sa MatrixBase::coeff()
+ * \warning the coordinates must fit into the referenced triangular part
+ */
+ EIGEN_DEVICE_FUNC
+ inline Scalar coeff(Index row, Index col) const
+ {
+ Base::check_coordinates_internal(row, col);
+ return m_matrix.coeff(row, col);
+ }
+
+ /** \sa MatrixBase::coeffRef()
+ * \warning the coordinates must fit into the referenced triangular part
+ */
+ EIGEN_DEVICE_FUNC
+ inline Scalar& coeffRef(Index row, Index col)
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(SelfAdjointView);
+ Base::check_coordinates_internal(row, col);
+ return m_matrix.coeffRef(row, col);
+ }
+
+ /** \internal */
+ EIGEN_DEVICE_FUNC
+ const MatrixTypeNestedCleaned& _expression() const { return m_matrix; }
+
+ EIGEN_DEVICE_FUNC
+ const MatrixTypeNestedCleaned& nestedExpression() const { return m_matrix; }
+ EIGEN_DEVICE_FUNC
+ MatrixTypeNestedCleaned& nestedExpression() { return m_matrix; }
+
+ /** Efficient triangular matrix times vector/matrix product */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ const Product<SelfAdjointView,OtherDerived>
+ operator*(const MatrixBase<OtherDerived>& rhs) const
+ {
+ return Product<SelfAdjointView,OtherDerived>(*this, rhs.derived());
+ }
+
+ /** Efficient vector/matrix times triangular matrix product */
+ template<typename OtherDerived> friend
+ EIGEN_DEVICE_FUNC
+ const Product<OtherDerived,SelfAdjointView>
+ operator*(const MatrixBase<OtherDerived>& lhs, const SelfAdjointView& rhs)
+ {
+ return Product<OtherDerived,SelfAdjointView>(lhs.derived(),rhs);
+ }
+
+ friend EIGEN_DEVICE_FUNC
+ const SelfAdjointView<const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,MatrixType,product),UpLo>
+ operator*(const Scalar& s, const SelfAdjointView& mat)
+ {
+ return (s*mat.nestedExpression()).template selfadjointView<UpLo>();
+ }
+
+ /** Perform a symmetric rank 2 update of the selfadjoint matrix \c *this:
+ * \f$ this = this + \alpha u v^* + conj(\alpha) v u^* \f$
+ * \returns a reference to \c *this
+ *
+ * The vectors \a u and \c v \b must be column vectors, however they can be
+ * a adjoint expression without any overhead. Only the meaningful triangular
+ * part of the matrix is updated, the rest is left unchanged.
+ *
+ * \sa rankUpdate(const MatrixBase<DerivedU>&, Scalar)
+ */
+ template<typename DerivedU, typename DerivedV>
+ EIGEN_DEVICE_FUNC
+ SelfAdjointView& rankUpdate(const MatrixBase<DerivedU>& u, const MatrixBase<DerivedV>& v, const Scalar& alpha = Scalar(1));
+
+ /** Perform a symmetric rank K update of the selfadjoint matrix \c *this:
+ * \f$ this = this + \alpha ( u u^* ) \f$ where \a u is a vector or matrix.
+ *
+ * \returns a reference to \c *this
+ *
+ * Note that to perform \f$ this = this + \alpha ( u^* u ) \f$ you can simply
+ * call this function with u.adjoint().
+ *
+ * \sa rankUpdate(const MatrixBase<DerivedU>&, const MatrixBase<DerivedV>&, Scalar)
+ */
+ template<typename DerivedU>
+ EIGEN_DEVICE_FUNC
+ SelfAdjointView& rankUpdate(const MatrixBase<DerivedU>& u, const Scalar& alpha = Scalar(1));
+
+ /** \returns an expression of a triangular view extracted from the current selfadjoint view of a given triangular part
+ *
+ * The parameter \a TriMode can have the following values: \c #Upper, \c #StrictlyUpper, \c #UnitUpper,
+ * \c #Lower, \c #StrictlyLower, \c #UnitLower.
+ *
+ * If \c TriMode references the same triangular part than \c *this, then this method simply return a \c TriangularView of the nested expression,
+ * otherwise, the nested expression is first transposed, thus returning a \c TriangularView<Transpose<MatrixType>> object.
+ *
+ * \sa MatrixBase::triangularView(), class TriangularView
+ */
+ template<unsigned int TriMode>
+ EIGEN_DEVICE_FUNC
+ typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)),
+ TriangularView<MatrixType,TriMode>,
+ TriangularView<typename MatrixType::AdjointReturnType,TriMode> >::type
+ triangularView() const
+ {
+ typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)), MatrixType&, typename MatrixType::ConstTransposeReturnType>::type tmp1(m_matrix);
+ typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)), MatrixType&, typename MatrixType::AdjointReturnType>::type tmp2(tmp1);
+ return typename internal::conditional<(TriMode&(Upper|Lower))==(UpLo&(Upper|Lower)),
+ TriangularView<MatrixType,TriMode>,
+ TriangularView<typename MatrixType::AdjointReturnType,TriMode> >::type(tmp2);
+ }
+
+ typedef SelfAdjointView<const MatrixConjugateReturnType,UpLo> ConjugateReturnType;
+ /** \sa MatrixBase::conjugate() const */
+ EIGEN_DEVICE_FUNC
+ inline const ConjugateReturnType conjugate() const
+ { return ConjugateReturnType(m_matrix.conjugate()); }
+
+ /** \returns an expression of the complex conjugate of \c *this if Cond==true,
+ * returns \c *this otherwise.
+ */
+ template<bool Cond>
+ EIGEN_DEVICE_FUNC
+ inline typename internal::conditional<Cond,ConjugateReturnType,ConstSelfAdjointView>::type
+ conjugateIf() const
+ {
+ typedef typename internal::conditional<Cond,ConjugateReturnType,ConstSelfAdjointView>::type ReturnType;
+ return ReturnType(m_matrix.template conjugateIf<Cond>());
+ }
+
+ typedef SelfAdjointView<const typename MatrixType::AdjointReturnType,TransposeMode> AdjointReturnType;
+ /** \sa MatrixBase::adjoint() const */
+ EIGEN_DEVICE_FUNC
+ inline const AdjointReturnType adjoint() const
+ { return AdjointReturnType(m_matrix.adjoint()); }
+
+ typedef SelfAdjointView<typename MatrixType::TransposeReturnType,TransposeMode> TransposeReturnType;
+ /** \sa MatrixBase::transpose() */
+ EIGEN_DEVICE_FUNC
+ inline TransposeReturnType transpose()
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
+ typename MatrixType::TransposeReturnType tmp(m_matrix);
+ return TransposeReturnType(tmp);
+ }
+
+ typedef SelfAdjointView<const typename MatrixType::ConstTransposeReturnType,TransposeMode> ConstTransposeReturnType;
+ /** \sa MatrixBase::transpose() const */
+ EIGEN_DEVICE_FUNC
+ inline const ConstTransposeReturnType transpose() const
+ {
+ return ConstTransposeReturnType(m_matrix.transpose());
+ }
+
+ /** \returns a const expression of the main diagonal of the matrix \c *this
+ *
+ * This method simply returns the diagonal of the nested expression, thus by-passing the SelfAdjointView decorator.
+ *
+ * \sa MatrixBase::diagonal(), class Diagonal */
+ EIGEN_DEVICE_FUNC
+ typename MatrixType::ConstDiagonalReturnType diagonal() const
+ {
+ return typename MatrixType::ConstDiagonalReturnType(m_matrix);
+ }
+
+/////////// Cholesky module ///////////
+
+ const LLT<PlainObject, UpLo> llt() const;
+ const LDLT<PlainObject, UpLo> ldlt() const;
+
+/////////// Eigenvalue module ///////////
+
+ /** Real part of #Scalar */
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ /** Return type of eigenvalues() */
+ typedef Matrix<RealScalar, internal::traits<MatrixType>::ColsAtCompileTime, 1> EigenvaluesReturnType;
+
+ EIGEN_DEVICE_FUNC
+ EigenvaluesReturnType eigenvalues() const;
+ EIGEN_DEVICE_FUNC
+ RealScalar operatorNorm() const;
+
+ protected:
+ MatrixTypeNested m_matrix;
+};
+
+
+// template<typename OtherDerived, typename MatrixType, unsigned int UpLo>
+// internal::selfadjoint_matrix_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> >
+// operator*(const MatrixBase<OtherDerived>& lhs, const SelfAdjointView<MatrixType,UpLo>& rhs)
+// {
+// return internal::matrix_selfadjoint_product_returntype<OtherDerived,SelfAdjointView<MatrixType,UpLo> >(lhs.derived(),rhs);
+// }
+
+// selfadjoint to dense matrix
+
+namespace internal {
+
+// TODO currently a selfadjoint expression has the form SelfAdjointView<.,.>
+// in the future selfadjoint-ness should be defined by the expression traits
+// such that Transpose<SelfAdjointView<.,.> > is valid. (currently TriangularBase::transpose() is overloaded to make it work)
+template<typename MatrixType, unsigned int Mode>
+struct evaluator_traits<SelfAdjointView<MatrixType,Mode> >
+{
+ typedef typename storage_kind_to_evaluator_kind<typename MatrixType::StorageKind>::Kind Kind;
+ typedef SelfAdjointShape Shape;
+};
+
+template<int UpLo, int SetOpposite, typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor, int Version>
+class triangular_dense_assignment_kernel<UpLo,SelfAdjoint,SetOpposite,DstEvaluatorTypeT,SrcEvaluatorTypeT,Functor,Version>
+ : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version>
+{
+protected:
+ typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version> Base;
+ typedef typename Base::DstXprType DstXprType;
+ typedef typename Base::SrcXprType SrcXprType;
+ using Base::m_dst;
+ using Base::m_src;
+ using Base::m_functor;
+public:
+
+ typedef typename Base::DstEvaluatorType DstEvaluatorType;
+ typedef typename Base::SrcEvaluatorType SrcEvaluatorType;
+ typedef typename Base::Scalar Scalar;
+ typedef typename Base::AssignmentTraits AssignmentTraits;
+
+
+ EIGEN_DEVICE_FUNC triangular_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType& dstExpr)
+ : Base(dst, src, func, dstExpr)
+ {}
+
+ EIGEN_DEVICE_FUNC void assignCoeff(Index row, Index col)
+ {
+ eigen_internal_assert(row!=col);
+ Scalar tmp = m_src.coeff(row,col);
+ m_functor.assignCoeff(m_dst.coeffRef(row,col), tmp);
+ m_functor.assignCoeff(m_dst.coeffRef(col,row), numext::conj(tmp));
+ }
+
+ EIGEN_DEVICE_FUNC void assignDiagonalCoeff(Index id)
+ {
+ Base::assignCoeff(id,id);
+ }
+
+ EIGEN_DEVICE_FUNC void assignOppositeCoeff(Index, Index)
+ { eigen_internal_assert(false && "should never be called"); }
+};
+
+} // end namespace internal
+
+/***************************************************************************
+* Implementation of MatrixBase methods
+***************************************************************************/
+
+/** This is the const version of MatrixBase::selfadjointView() */
+template<typename Derived>
+template<unsigned int UpLo>
+EIGEN_DEVICE_FUNC typename MatrixBase<Derived>::template ConstSelfAdjointViewReturnType<UpLo>::Type
+MatrixBase<Derived>::selfadjointView() const
+{
+ return typename ConstSelfAdjointViewReturnType<UpLo>::Type(derived());
+}
+
+/** \returns an expression of a symmetric/self-adjoint view extracted from the upper or lower triangular part of the current matrix
+ *
+ * The parameter \a UpLo can be either \c #Upper or \c #Lower
+ *
+ * Example: \include MatrixBase_selfadjointView.cpp
+ * Output: \verbinclude MatrixBase_selfadjointView.out
+ *
+ * \sa class SelfAdjointView
+ */
+template<typename Derived>
+template<unsigned int UpLo>
+EIGEN_DEVICE_FUNC typename MatrixBase<Derived>::template SelfAdjointViewReturnType<UpLo>::Type
+MatrixBase<Derived>::selfadjointView()
+{
+ return typename SelfAdjointViewReturnType<UpLo>::Type(derived());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_SELFADJOINTMATRIX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h b/src/3rdparty/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h
new file mode 100644
index 000000000..7c89c2e23
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h
@@ -0,0 +1,47 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SELFCWISEBINARYOP_H
+#define EIGEN_SELFCWISEBINARYOP_H
+
+namespace Eigen {
+
+// TODO generalize the scalar type of 'other'
+
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator*=(const Scalar& other)
+{
+ internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::mul_assign_op<Scalar,Scalar>());
+ return derived();
+}
+
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& ArrayBase<Derived>::operator+=(const Scalar& other)
+{
+ internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::add_assign_op<Scalar,Scalar>());
+ return derived();
+}
+
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& ArrayBase<Derived>::operator-=(const Scalar& other)
+{
+ internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::sub_assign_op<Scalar,Scalar>());
+ return derived();
+}
+
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator/=(const Scalar& other)
+{
+ internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::div_assign_op<Scalar,Scalar>());
+ return derived();
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_SELFCWISEBINARYOP_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Solve.h b/src/3rdparty/eigen/Eigen/src/Core/Solve.h
new file mode 100644
index 000000000..23d5cb707
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Solve.h
@@ -0,0 +1,188 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SOLVE_H
+#define EIGEN_SOLVE_H
+
+namespace Eigen {
+
+template<typename Decomposition, typename RhsType, typename StorageKind> class SolveImpl;
+
+/** \class Solve
+ * \ingroup Core_Module
+ *
+ * \brief Pseudo expression representing a solving operation
+ *
+ * \tparam Decomposition the type of the matrix or decomposition object
+ * \tparam Rhstype the type of the right-hand side
+ *
+ * This class represents an expression of A.solve(B)
+ * and most of the time this is the only way it is used.
+ *
+ */
+namespace internal {
+
+// this solve_traits class permits to determine the evaluation type with respect to storage kind (Dense vs Sparse)
+template<typename Decomposition, typename RhsType,typename StorageKind> struct solve_traits;
+
+template<typename Decomposition, typename RhsType>
+struct solve_traits<Decomposition,RhsType,Dense>
+{
+ typedef typename make_proper_matrix_type<typename RhsType::Scalar,
+ Decomposition::ColsAtCompileTime,
+ RhsType::ColsAtCompileTime,
+ RhsType::PlainObject::Options,
+ Decomposition::MaxColsAtCompileTime,
+ RhsType::MaxColsAtCompileTime>::type PlainObject;
+};
+
+template<typename Decomposition, typename RhsType>
+struct traits<Solve<Decomposition, RhsType> >
+ : traits<typename solve_traits<Decomposition,RhsType,typename internal::traits<RhsType>::StorageKind>::PlainObject>
+{
+ typedef typename solve_traits<Decomposition,RhsType,typename internal::traits<RhsType>::StorageKind>::PlainObject PlainObject;
+ typedef typename promote_index_type<typename Decomposition::StorageIndex, typename RhsType::StorageIndex>::type StorageIndex;
+ typedef traits<PlainObject> BaseTraits;
+ enum {
+ Flags = BaseTraits::Flags & RowMajorBit,
+ CoeffReadCost = HugeCost
+ };
+};
+
+}
+
+
+template<typename Decomposition, typename RhsType>
+class Solve : public SolveImpl<Decomposition,RhsType,typename internal::traits<RhsType>::StorageKind>
+{
+public:
+ typedef typename internal::traits<Solve>::PlainObject PlainObject;
+ typedef typename internal::traits<Solve>::StorageIndex StorageIndex;
+
+ Solve(const Decomposition &dec, const RhsType &rhs)
+ : m_dec(dec), m_rhs(rhs)
+ {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_dec.cols(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
+
+ EIGEN_DEVICE_FUNC const Decomposition& dec() const { return m_dec; }
+ EIGEN_DEVICE_FUNC const RhsType& rhs() const { return m_rhs; }
+
+protected:
+ const Decomposition &m_dec;
+ const RhsType &m_rhs;
+};
+
+
+// Specialization of the Solve expression for dense results
+template<typename Decomposition, typename RhsType>
+class SolveImpl<Decomposition,RhsType,Dense>
+ : public MatrixBase<Solve<Decomposition,RhsType> >
+{
+ typedef Solve<Decomposition,RhsType> Derived;
+
+public:
+
+ typedef MatrixBase<Solve<Decomposition,RhsType> > Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
+
+private:
+
+ Scalar coeff(Index row, Index col) const;
+ Scalar coeff(Index i) const;
+};
+
+// Generic API dispatcher
+template<typename Decomposition, typename RhsType, typename StorageKind>
+class SolveImpl : public internal::generic_xpr_base<Solve<Decomposition,RhsType>, MatrixXpr, StorageKind>::type
+{
+ public:
+ typedef typename internal::generic_xpr_base<Solve<Decomposition,RhsType>, MatrixXpr, StorageKind>::type Base;
+};
+
+namespace internal {
+
+// Evaluator of Solve -> eval into a temporary
+template<typename Decomposition, typename RhsType>
+struct evaluator<Solve<Decomposition,RhsType> >
+ : public evaluator<typename Solve<Decomposition,RhsType>::PlainObject>
+{
+ typedef Solve<Decomposition,RhsType> SolveType;
+ typedef typename SolveType::PlainObject PlainObject;
+ typedef evaluator<PlainObject> Base;
+
+ enum { Flags = Base::Flags | EvalBeforeNestingBit };
+
+ EIGEN_DEVICE_FUNC explicit evaluator(const SolveType& solve)
+ : m_result(solve.rows(), solve.cols())
+ {
+ ::new (static_cast<Base*>(this)) Base(m_result);
+ solve.dec()._solve_impl(solve.rhs(), m_result);
+ }
+
+protected:
+ PlainObject m_result;
+};
+
+// Specialization for "dst = dec.solve(rhs)"
+// NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere
+template<typename DstXprType, typename DecType, typename RhsType, typename Scalar>
+struct Assignment<DstXprType, Solve<DecType,RhsType>, internal::assign_op<Scalar,Scalar>, Dense2Dense>
+{
+ typedef Solve<DecType,RhsType> SrcXprType;
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+
+ src.dec()._solve_impl(src.rhs(), dst);
+ }
+};
+
+// Specialization for "dst = dec.transpose().solve(rhs)"
+template<typename DstXprType, typename DecType, typename RhsType, typename Scalar>
+struct Assignment<DstXprType, Solve<Transpose<const DecType>,RhsType>, internal::assign_op<Scalar,Scalar>, Dense2Dense>
+{
+ typedef Solve<Transpose<const DecType>,RhsType> SrcXprType;
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+
+ src.dec().nestedExpression().template _solve_impl_transposed<false>(src.rhs(), dst);
+ }
+};
+
+// Specialization for "dst = dec.adjoint().solve(rhs)"
+template<typename DstXprType, typename DecType, typename RhsType, typename Scalar>
+struct Assignment<DstXprType, Solve<CwiseUnaryOp<internal::scalar_conjugate_op<typename DecType::Scalar>, const Transpose<const DecType> >,RhsType>,
+ internal::assign_op<Scalar,Scalar>, Dense2Dense>
+{
+ typedef Solve<CwiseUnaryOp<internal::scalar_conjugate_op<typename DecType::Scalar>, const Transpose<const DecType> >,RhsType> SrcXprType;
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+
+ src.dec().nestedExpression().nestedExpression().template _solve_impl_transposed<true>(src.rhs(), dst);
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_SOLVE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/SolveTriangular.h b/src/3rdparty/eigen/Eigen/src/Core/SolveTriangular.h
new file mode 100644
index 000000000..dfbf99523
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/SolveTriangular.h
@@ -0,0 +1,235 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SOLVETRIANGULAR_H
+#define EIGEN_SOLVETRIANGULAR_H
+
+namespace Eigen {
+
+namespace internal {
+
+// Forward declarations:
+// The following two routines are implemented in the products/TriangularSolver*.h files
+template<typename LhsScalar, typename RhsScalar, typename Index, int Side, int Mode, bool Conjugate, int StorageOrder>
+struct triangular_solve_vector;
+
+template <typename Scalar, typename Index, int Side, int Mode, bool Conjugate, int TriStorageOrder, int OtherStorageOrder, int OtherInnerStride>
+struct triangular_solve_matrix;
+
+// small helper struct extracting some traits on the underlying solver operation
+template<typename Lhs, typename Rhs, int Side>
+class trsolve_traits
+{
+ private:
+ enum {
+ RhsIsVectorAtCompileTime = (Side==OnTheLeft ? Rhs::ColsAtCompileTime : Rhs::RowsAtCompileTime)==1
+ };
+ public:
+ enum {
+ Unrolling = (RhsIsVectorAtCompileTime && Rhs::SizeAtCompileTime != Dynamic && Rhs::SizeAtCompileTime <= 8)
+ ? CompleteUnrolling : NoUnrolling,
+ RhsVectors = RhsIsVectorAtCompileTime ? 1 : Dynamic
+ };
+};
+
+template<typename Lhs, typename Rhs,
+ int Side, // can be OnTheLeft/OnTheRight
+ int Mode, // can be Upper/Lower | UnitDiag
+ int Unrolling = trsolve_traits<Lhs,Rhs,Side>::Unrolling,
+ int RhsVectors = trsolve_traits<Lhs,Rhs,Side>::RhsVectors
+ >
+struct triangular_solver_selector;
+
+template<typename Lhs, typename Rhs, int Side, int Mode>
+struct triangular_solver_selector<Lhs,Rhs,Side,Mode,NoUnrolling,1>
+{
+ typedef typename Lhs::Scalar LhsScalar;
+ typedef typename Rhs::Scalar RhsScalar;
+ typedef blas_traits<Lhs> LhsProductTraits;
+ typedef typename LhsProductTraits::ExtractType ActualLhsType;
+ typedef Map<Matrix<RhsScalar,Dynamic,1>, Aligned> MappedRhs;
+ static EIGEN_DEVICE_FUNC void run(const Lhs& lhs, Rhs& rhs)
+ {
+ ActualLhsType actualLhs = LhsProductTraits::extract(lhs);
+
+ // FIXME find a way to allow an inner stride if packet_traits<Scalar>::size==1
+
+ bool useRhsDirectly = Rhs::InnerStrideAtCompileTime==1 || rhs.innerStride()==1;
+
+ ei_declare_aligned_stack_constructed_variable(RhsScalar,actualRhs,rhs.size(),
+ (useRhsDirectly ? rhs.data() : 0));
+
+ if(!useRhsDirectly)
+ MappedRhs(actualRhs,rhs.size()) = rhs;
+
+ triangular_solve_vector<LhsScalar, RhsScalar, Index, Side, Mode, LhsProductTraits::NeedToConjugate,
+ (int(Lhs::Flags) & RowMajorBit) ? RowMajor : ColMajor>
+ ::run(actualLhs.cols(), actualLhs.data(), actualLhs.outerStride(), actualRhs);
+
+ if(!useRhsDirectly)
+ rhs = MappedRhs(actualRhs, rhs.size());
+ }
+};
+
+// the rhs is a matrix
+template<typename Lhs, typename Rhs, int Side, int Mode>
+struct triangular_solver_selector<Lhs,Rhs,Side,Mode,NoUnrolling,Dynamic>
+{
+ typedef typename Rhs::Scalar Scalar;
+ typedef blas_traits<Lhs> LhsProductTraits;
+ typedef typename LhsProductTraits::DirectLinearAccessType ActualLhsType;
+
+ static EIGEN_DEVICE_FUNC void run(const Lhs& lhs, Rhs& rhs)
+ {
+ typename internal::add_const_on_value_type<ActualLhsType>::type actualLhs = LhsProductTraits::extract(lhs);
+
+ const Index size = lhs.rows();
+ const Index othersize = Side==OnTheLeft? rhs.cols() : rhs.rows();
+
+ typedef internal::gemm_blocking_space<(Rhs::Flags&RowMajorBit) ? RowMajor : ColMajor,Scalar,Scalar,
+ Rhs::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime, Lhs::MaxRowsAtCompileTime,4> BlockingType;
+
+ BlockingType blocking(rhs.rows(), rhs.cols(), size, 1, false);
+
+ triangular_solve_matrix<Scalar,Index,Side,Mode,LhsProductTraits::NeedToConjugate,(int(Lhs::Flags) & RowMajorBit) ? RowMajor : ColMajor,
+ (Rhs::Flags&RowMajorBit) ? RowMajor : ColMajor, Rhs::InnerStrideAtCompileTime>
+ ::run(size, othersize, &actualLhs.coeffRef(0,0), actualLhs.outerStride(), &rhs.coeffRef(0,0), rhs.innerStride(), rhs.outerStride(), blocking);
+ }
+};
+
+/***************************************************************************
+* meta-unrolling implementation
+***************************************************************************/
+
+template<typename Lhs, typename Rhs, int Mode, int LoopIndex, int Size,
+ bool Stop = LoopIndex==Size>
+struct triangular_solver_unroller;
+
+template<typename Lhs, typename Rhs, int Mode, int LoopIndex, int Size>
+struct triangular_solver_unroller<Lhs,Rhs,Mode,LoopIndex,Size,false> {
+ enum {
+ IsLower = ((Mode&Lower)==Lower),
+ DiagIndex = IsLower ? LoopIndex : Size - LoopIndex - 1,
+ StartIndex = IsLower ? 0 : DiagIndex+1
+ };
+ static EIGEN_DEVICE_FUNC void run(const Lhs& lhs, Rhs& rhs)
+ {
+ if (LoopIndex>0)
+ rhs.coeffRef(DiagIndex) -= lhs.row(DiagIndex).template segment<LoopIndex>(StartIndex).transpose()
+ .cwiseProduct(rhs.template segment<LoopIndex>(StartIndex)).sum();
+
+ if(!(Mode & UnitDiag))
+ rhs.coeffRef(DiagIndex) /= lhs.coeff(DiagIndex,DiagIndex);
+
+ triangular_solver_unroller<Lhs,Rhs,Mode,LoopIndex+1,Size>::run(lhs,rhs);
+ }
+};
+
+template<typename Lhs, typename Rhs, int Mode, int LoopIndex, int Size>
+struct triangular_solver_unroller<Lhs,Rhs,Mode,LoopIndex,Size,true> {
+ static EIGEN_DEVICE_FUNC void run(const Lhs&, Rhs&) {}
+};
+
+template<typename Lhs, typename Rhs, int Mode>
+struct triangular_solver_selector<Lhs,Rhs,OnTheLeft,Mode,CompleteUnrolling,1> {
+ static EIGEN_DEVICE_FUNC void run(const Lhs& lhs, Rhs& rhs)
+ { triangular_solver_unroller<Lhs,Rhs,Mode,0,Rhs::SizeAtCompileTime>::run(lhs,rhs); }
+};
+
+template<typename Lhs, typename Rhs, int Mode>
+struct triangular_solver_selector<Lhs,Rhs,OnTheRight,Mode,CompleteUnrolling,1> {
+ static EIGEN_DEVICE_FUNC void run(const Lhs& lhs, Rhs& rhs)
+ {
+ Transpose<const Lhs> trLhs(lhs);
+ Transpose<Rhs> trRhs(rhs);
+
+ triangular_solver_unroller<Transpose<const Lhs>,Transpose<Rhs>,
+ ((Mode&Upper)==Upper ? Lower : Upper) | (Mode&UnitDiag),
+ 0,Rhs::SizeAtCompileTime>::run(trLhs,trRhs);
+ }
+};
+
+} // end namespace internal
+
+/***************************************************************************
+* TriangularView methods
+***************************************************************************/
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+template<typename MatrixType, unsigned int Mode>
+template<int Side, typename OtherDerived>
+EIGEN_DEVICE_FUNC void TriangularViewImpl<MatrixType,Mode,Dense>::solveInPlace(const MatrixBase<OtherDerived>& _other) const
+{
+ OtherDerived& other = _other.const_cast_derived();
+ eigen_assert( derived().cols() == derived().rows() && ((Side==OnTheLeft && derived().cols() == other.rows()) || (Side==OnTheRight && derived().cols() == other.cols())) );
+ eigen_assert((!(int(Mode) & int(ZeroDiag))) && bool(int(Mode) & (int(Upper) | int(Lower))));
+ // If solving for a 0x0 matrix, nothing to do, simply return.
+ if (derived().cols() == 0)
+ return;
+
+ enum { copy = (internal::traits<OtherDerived>::Flags & RowMajorBit) && OtherDerived::IsVectorAtCompileTime && OtherDerived::SizeAtCompileTime!=1};
+ typedef typename internal::conditional<copy,
+ typename internal::plain_matrix_type_column_major<OtherDerived>::type, OtherDerived&>::type OtherCopy;
+ OtherCopy otherCopy(other);
+
+ internal::triangular_solver_selector<MatrixType, typename internal::remove_reference<OtherCopy>::type,
+ Side, Mode>::run(derived().nestedExpression(), otherCopy);
+
+ if (copy)
+ other = otherCopy;
+}
+
+template<typename Derived, unsigned int Mode>
+template<int Side, typename Other>
+const internal::triangular_solve_retval<Side,TriangularView<Derived,Mode>,Other>
+TriangularViewImpl<Derived,Mode,Dense>::solve(const MatrixBase<Other>& other) const
+{
+ return internal::triangular_solve_retval<Side,TriangularViewType,Other>(derived(), other.derived());
+}
+#endif
+
+namespace internal {
+
+
+template<int Side, typename TriangularType, typename Rhs>
+struct traits<triangular_solve_retval<Side, TriangularType, Rhs> >
+{
+ typedef typename internal::plain_matrix_type_column_major<Rhs>::type ReturnType;
+};
+
+template<int Side, typename TriangularType, typename Rhs> struct triangular_solve_retval
+ : public ReturnByValue<triangular_solve_retval<Side, TriangularType, Rhs> >
+{
+ typedef typename remove_all<typename Rhs::Nested>::type RhsNestedCleaned;
+ typedef ReturnByValue<triangular_solve_retval> Base;
+
+ triangular_solve_retval(const TriangularType& tri, const Rhs& rhs)
+ : m_triangularMatrix(tri), m_rhs(rhs)
+ {}
+
+ inline EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_rhs.rows(); }
+ inline EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
+
+ template<typename Dest> inline void evalTo(Dest& dst) const
+ {
+ if(!is_same_dense(dst,m_rhs))
+ dst = m_rhs;
+ m_triangularMatrix.template solveInPlace<Side>(dst);
+ }
+
+ protected:
+ const TriangularType& m_triangularMatrix;
+ typename Rhs::Nested m_rhs;
+};
+
+} // namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_SOLVETRIANGULAR_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/SolverBase.h b/src/3rdparty/eigen/Eigen/src/Core/SolverBase.h
new file mode 100644
index 000000000..501461042
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/SolverBase.h
@@ -0,0 +1,168 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SOLVERBASE_H
+#define EIGEN_SOLVERBASE_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Derived>
+struct solve_assertion {
+ template<bool Transpose_, typename Rhs>
+ static void run(const Derived& solver, const Rhs& b) { solver.template _check_solve_assertion<Transpose_>(b); }
+};
+
+template<typename Derived>
+struct solve_assertion<Transpose<Derived> >
+{
+ typedef Transpose<Derived> type;
+
+ template<bool Transpose_, typename Rhs>
+ static void run(const type& transpose, const Rhs& b)
+ {
+ internal::solve_assertion<typename internal::remove_all<Derived>::type>::template run<true>(transpose.nestedExpression(), b);
+ }
+};
+
+template<typename Scalar, typename Derived>
+struct solve_assertion<CwiseUnaryOp<Eigen::internal::scalar_conjugate_op<Scalar>, const Transpose<Derived> > >
+{
+ typedef CwiseUnaryOp<Eigen::internal::scalar_conjugate_op<Scalar>, const Transpose<Derived> > type;
+
+ template<bool Transpose_, typename Rhs>
+ static void run(const type& adjoint, const Rhs& b)
+ {
+ internal::solve_assertion<typename internal::remove_all<Transpose<Derived> >::type>::template run<true>(adjoint.nestedExpression(), b);
+ }
+};
+} // end namespace internal
+
+/** \class SolverBase
+ * \brief A base class for matrix decomposition and solvers
+ *
+ * \tparam Derived the actual type of the decomposition/solver.
+ *
+ * Any matrix decomposition inheriting this base class provide the following API:
+ *
+ * \code
+ * MatrixType A, b, x;
+ * DecompositionType dec(A);
+ * x = dec.solve(b); // solve A * x = b
+ * x = dec.transpose().solve(b); // solve A^T * x = b
+ * x = dec.adjoint().solve(b); // solve A' * x = b
+ * \endcode
+ *
+ * \warning Currently, any other usage of transpose() and adjoint() are not supported and will produce compilation errors.
+ *
+ * \sa class PartialPivLU, class FullPivLU, class HouseholderQR, class ColPivHouseholderQR, class FullPivHouseholderQR, class CompleteOrthogonalDecomposition, class LLT, class LDLT, class SVDBase
+ */
+template<typename Derived>
+class SolverBase : public EigenBase<Derived>
+{
+ public:
+
+ typedef EigenBase<Derived> Base;
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+ typedef Scalar CoeffReturnType;
+
+ template<typename Derived_>
+ friend struct internal::solve_assertion;
+
+ enum {
+ RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
+ ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
+ SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
+ internal::traits<Derived>::ColsAtCompileTime>::ret),
+ MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
+ MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
+ internal::traits<Derived>::MaxColsAtCompileTime>::ret),
+ IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1
+ || internal::traits<Derived>::MaxColsAtCompileTime == 1,
+ NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2
+ };
+
+ /** Default constructor */
+ SolverBase()
+ {}
+
+ ~SolverBase()
+ {}
+
+ using Base::derived;
+
+ /** \returns an expression of the solution x of \f$ A x = b \f$ using the current decomposition of A.
+ */
+ template<typename Rhs>
+ inline const Solve<Derived, Rhs>
+ solve(const MatrixBase<Rhs>& b) const
+ {
+ internal::solve_assertion<typename internal::remove_all<Derived>::type>::template run<false>(derived(), b);
+ return Solve<Derived, Rhs>(derived(), b.derived());
+ }
+
+ /** \internal the return type of transpose() */
+ typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType;
+ /** \returns an expression of the transposed of the factored matrix.
+ *
+ * A typical usage is to solve for the transposed problem A^T x = b:
+ * \code x = dec.transpose().solve(b); \endcode
+ *
+ * \sa adjoint(), solve()
+ */
+ inline ConstTransposeReturnType transpose() const
+ {
+ return ConstTransposeReturnType(derived());
+ }
+
+ /** \internal the return type of adjoint() */
+ typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
+ CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, ConstTransposeReturnType>,
+ ConstTransposeReturnType
+ >::type AdjointReturnType;
+ /** \returns an expression of the adjoint of the factored matrix
+ *
+ * A typical usage is to solve for the adjoint problem A' x = b:
+ * \code x = dec.adjoint().solve(b); \endcode
+ *
+ * For real scalar types, this function is equivalent to transpose().
+ *
+ * \sa transpose(), solve()
+ */
+ inline AdjointReturnType adjoint() const
+ {
+ return AdjointReturnType(derived().transpose());
+ }
+
+ protected:
+
+ template<bool Transpose_, typename Rhs>
+ void _check_solve_assertion(const Rhs& b) const {
+ EIGEN_ONLY_USED_FOR_DEBUG(b);
+ eigen_assert(derived().m_isInitialized && "Solver is not initialized.");
+ eigen_assert((Transpose_?derived().cols():derived().rows())==b.rows() && "SolverBase::solve(): invalid number of rows of the right hand side matrix b");
+ }
+};
+
+namespace internal {
+
+template<typename Derived>
+struct generic_xpr_base<Derived, MatrixXpr, SolverStorage>
+{
+ typedef SolverBase<Derived> type;
+
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_SOLVERBASE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/StableNorm.h b/src/3rdparty/eigen/Eigen/src/Core/StableNorm.h
new file mode 100644
index 000000000..4a3f0cca8
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/StableNorm.h
@@ -0,0 +1,251 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_STABLENORM_H
+#define EIGEN_STABLENORM_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename ExpressionType, typename Scalar>
+inline void stable_norm_kernel(const ExpressionType& bl, Scalar& ssq, Scalar& scale, Scalar& invScale)
+{
+ Scalar maxCoeff = bl.cwiseAbs().maxCoeff();
+
+ if(maxCoeff>scale)
+ {
+ ssq = ssq * numext::abs2(scale/maxCoeff);
+ Scalar tmp = Scalar(1)/maxCoeff;
+ if(tmp > NumTraits<Scalar>::highest())
+ {
+ invScale = NumTraits<Scalar>::highest();
+ scale = Scalar(1)/invScale;
+ }
+ else if(maxCoeff>NumTraits<Scalar>::highest()) // we got a INF
+ {
+ invScale = Scalar(1);
+ scale = maxCoeff;
+ }
+ else
+ {
+ scale = maxCoeff;
+ invScale = tmp;
+ }
+ }
+ else if(maxCoeff!=maxCoeff) // we got a NaN
+ {
+ scale = maxCoeff;
+ }
+
+ // TODO if the maxCoeff is much much smaller than the current scale,
+ // then we can neglect this sub vector
+ if(scale>Scalar(0)) // if scale==0, then bl is 0
+ ssq += (bl*invScale).squaredNorm();
+}
+
+template<typename VectorType, typename RealScalar>
+void stable_norm_impl_inner_step(const VectorType &vec, RealScalar& ssq, RealScalar& scale, RealScalar& invScale)
+{
+ typedef typename VectorType::Scalar Scalar;
+ const Index blockSize = 4096;
+
+ typedef typename internal::nested_eval<VectorType,2>::type VectorTypeCopy;
+ typedef typename internal::remove_all<VectorTypeCopy>::type VectorTypeCopyClean;
+ const VectorTypeCopy copy(vec);
+
+ enum {
+ CanAlign = ( (int(VectorTypeCopyClean::Flags)&DirectAccessBit)
+ || (int(internal::evaluator<VectorTypeCopyClean>::Alignment)>0) // FIXME Alignment)>0 might not be enough
+ ) && (blockSize*sizeof(Scalar)*2<EIGEN_STACK_ALLOCATION_LIMIT)
+ && (EIGEN_MAX_STATIC_ALIGN_BYTES>0) // if we cannot allocate on the stack, then let's not bother about this optimization
+ };
+ typedef typename internal::conditional<CanAlign, Ref<const Matrix<Scalar,Dynamic,1,0,blockSize,1>, internal::evaluator<VectorTypeCopyClean>::Alignment>,
+ typename VectorTypeCopyClean::ConstSegmentReturnType>::type SegmentWrapper;
+ Index n = vec.size();
+
+ Index bi = internal::first_default_aligned(copy);
+ if (bi>0)
+ internal::stable_norm_kernel(copy.head(bi), ssq, scale, invScale);
+ for (; bi<n; bi+=blockSize)
+ internal::stable_norm_kernel(SegmentWrapper(copy.segment(bi,numext::mini(blockSize, n - bi))), ssq, scale, invScale);
+}
+
+template<typename VectorType>
+typename VectorType::RealScalar
+stable_norm_impl(const VectorType &vec, typename enable_if<VectorType::IsVectorAtCompileTime>::type* = 0 )
+{
+ using std::sqrt;
+ using std::abs;
+
+ Index n = vec.size();
+
+ if(n==1)
+ return abs(vec.coeff(0));
+
+ typedef typename VectorType::RealScalar RealScalar;
+ RealScalar scale(0);
+ RealScalar invScale(1);
+ RealScalar ssq(0); // sum of squares
+
+ stable_norm_impl_inner_step(vec, ssq, scale, invScale);
+
+ return scale * sqrt(ssq);
+}
+
+template<typename MatrixType>
+typename MatrixType::RealScalar
+stable_norm_impl(const MatrixType &mat, typename enable_if<!MatrixType::IsVectorAtCompileTime>::type* = 0 )
+{
+ using std::sqrt;
+
+ typedef typename MatrixType::RealScalar RealScalar;
+ RealScalar scale(0);
+ RealScalar invScale(1);
+ RealScalar ssq(0); // sum of squares
+
+ for(Index j=0; j<mat.outerSize(); ++j)
+ stable_norm_impl_inner_step(mat.innerVector(j), ssq, scale, invScale);
+ return scale * sqrt(ssq);
+}
+
+template<typename Derived>
+inline typename NumTraits<typename traits<Derived>::Scalar>::Real
+blueNorm_impl(const EigenBase<Derived>& _vec)
+{
+ typedef typename Derived::RealScalar RealScalar;
+ using std::pow;
+ using std::sqrt;
+ using std::abs;
+
+ // This program calculates the machine-dependent constants
+ // bl, b2, slm, s2m, relerr overfl
+ // from the "basic" machine-dependent numbers
+ // nbig, ibeta, it, iemin, iemax, rbig.
+ // The following define the basic machine-dependent constants.
+ // For portability, the PORT subprograms "ilmaeh" and "rlmach"
+ // are used. For any specific computer, each of the assignment
+ // statements can be replaced
+ static const int ibeta = std::numeric_limits<RealScalar>::radix; // base for floating-point numbers
+ static const int it = NumTraits<RealScalar>::digits(); // number of base-beta digits in mantissa
+ static const int iemin = NumTraits<RealScalar>::min_exponent(); // minimum exponent
+ static const int iemax = NumTraits<RealScalar>::max_exponent(); // maximum exponent
+ static const RealScalar rbig = NumTraits<RealScalar>::highest(); // largest floating-point number
+ static const RealScalar b1 = RealScalar(pow(RealScalar(ibeta),RealScalar(-((1-iemin)/2)))); // lower boundary of midrange
+ static const RealScalar b2 = RealScalar(pow(RealScalar(ibeta),RealScalar((iemax + 1 - it)/2))); // upper boundary of midrange
+ static const RealScalar s1m = RealScalar(pow(RealScalar(ibeta),RealScalar((2-iemin)/2))); // scaling factor for lower range
+ static const RealScalar s2m = RealScalar(pow(RealScalar(ibeta),RealScalar(- ((iemax+it)/2)))); // scaling factor for upper range
+ static const RealScalar eps = RealScalar(pow(double(ibeta), 1-it));
+ static const RealScalar relerr = sqrt(eps); // tolerance for neglecting asml
+
+ const Derived& vec(_vec.derived());
+ Index n = vec.size();
+ RealScalar ab2 = b2 / RealScalar(n);
+ RealScalar asml = RealScalar(0);
+ RealScalar amed = RealScalar(0);
+ RealScalar abig = RealScalar(0);
+
+ for(Index j=0; j<vec.outerSize(); ++j)
+ {
+ for(typename Derived::InnerIterator iter(vec, j); iter; ++iter)
+ {
+ RealScalar ax = abs(iter.value());
+ if(ax > ab2) abig += numext::abs2(ax*s2m);
+ else if(ax < b1) asml += numext::abs2(ax*s1m);
+ else amed += numext::abs2(ax);
+ }
+ }
+ if(amed!=amed)
+ return amed; // we got a NaN
+ if(abig > RealScalar(0))
+ {
+ abig = sqrt(abig);
+ if(abig > rbig) // overflow, or *this contains INF values
+ return abig; // return INF
+ if(amed > RealScalar(0))
+ {
+ abig = abig/s2m;
+ amed = sqrt(amed);
+ }
+ else
+ return abig/s2m;
+ }
+ else if(asml > RealScalar(0))
+ {
+ if (amed > RealScalar(0))
+ {
+ abig = sqrt(amed);
+ amed = sqrt(asml) / s1m;
+ }
+ else
+ return sqrt(asml)/s1m;
+ }
+ else
+ return sqrt(amed);
+ asml = numext::mini(abig, amed);
+ abig = numext::maxi(abig, amed);
+ if(asml <= abig*relerr)
+ return abig;
+ else
+ return abig * sqrt(RealScalar(1) + numext::abs2(asml/abig));
+}
+
+} // end namespace internal
+
+/** \returns the \em l2 norm of \c *this avoiding underflow and overflow.
+ * This version use a blockwise two passes algorithm:
+ * 1 - find the absolute largest coefficient \c s
+ * 2 - compute \f$ s \Vert \frac{*this}{s} \Vert \f$ in a standard way
+ *
+ * For architecture/scalar types supporting vectorization, this version
+ * is faster than blueNorm(). Otherwise the blueNorm() is much faster.
+ *
+ * \sa norm(), blueNorm(), hypotNorm()
+ */
+template<typename Derived>
+inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real
+MatrixBase<Derived>::stableNorm() const
+{
+ return internal::stable_norm_impl(derived());
+}
+
+/** \returns the \em l2 norm of \c *this using the Blue's algorithm.
+ * A Portable Fortran Program to Find the Euclidean Norm of a Vector,
+ * ACM TOMS, Vol 4, Issue 1, 1978.
+ *
+ * For architecture/scalar types without vectorization, this version
+ * is much faster than stableNorm(). Otherwise the stableNorm() is faster.
+ *
+ * \sa norm(), stableNorm(), hypotNorm()
+ */
+template<typename Derived>
+inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real
+MatrixBase<Derived>::blueNorm() const
+{
+ return internal::blueNorm_impl(*this);
+}
+
+/** \returns the \em l2 norm of \c *this avoiding undeflow and overflow.
+ * This version use a concatenation of hypot() calls, and it is very slow.
+ *
+ * \sa norm(), stableNorm()
+ */
+template<typename Derived>
+inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real
+MatrixBase<Derived>::hypotNorm() const
+{
+ if(size()==1)
+ return numext::abs(coeff(0,0));
+ else
+ return this->cwiseAbs().redux(internal::scalar_hypot_op<RealScalar>());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_STABLENORM_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/StlIterators.h b/src/3rdparty/eigen/Eigen/src/Core/StlIterators.h
new file mode 100644
index 000000000..09041db1d
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/StlIterators.h
@@ -0,0 +1,463 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2018 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_STLITERATORS_H
+#define EIGEN_STLITERATORS_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename IteratorType>
+struct indexed_based_stl_iterator_traits;
+
+template<typename Derived>
+class indexed_based_stl_iterator_base
+{
+protected:
+ typedef indexed_based_stl_iterator_traits<Derived> traits;
+ typedef typename traits::XprType XprType;
+ typedef indexed_based_stl_iterator_base<typename traits::non_const_iterator> non_const_iterator;
+ typedef indexed_based_stl_iterator_base<typename traits::const_iterator> const_iterator;
+ typedef typename internal::conditional<internal::is_const<XprType>::value,non_const_iterator,const_iterator>::type other_iterator;
+ // NOTE: in C++03 we cannot declare friend classes through typedefs because we need to write friend class:
+ friend class indexed_based_stl_iterator_base<typename traits::const_iterator>;
+ friend class indexed_based_stl_iterator_base<typename traits::non_const_iterator>;
+public:
+ typedef Index difference_type;
+ typedef std::random_access_iterator_tag iterator_category;
+
+ indexed_based_stl_iterator_base() EIGEN_NO_THROW : mp_xpr(0), m_index(0) {}
+ indexed_based_stl_iterator_base(XprType& xpr, Index index) EIGEN_NO_THROW : mp_xpr(&xpr), m_index(index) {}
+
+ indexed_based_stl_iterator_base(const non_const_iterator& other) EIGEN_NO_THROW
+ : mp_xpr(other.mp_xpr), m_index(other.m_index)
+ {}
+
+ indexed_based_stl_iterator_base& operator=(const non_const_iterator& other)
+ {
+ mp_xpr = other.mp_xpr;
+ m_index = other.m_index;
+ return *this;
+ }
+
+ Derived& operator++() { ++m_index; return derived(); }
+ Derived& operator--() { --m_index; return derived(); }
+
+ Derived operator++(int) { Derived prev(derived()); operator++(); return prev;}
+ Derived operator--(int) { Derived prev(derived()); operator--(); return prev;}
+
+ friend Derived operator+(const indexed_based_stl_iterator_base& a, Index b) { Derived ret(a.derived()); ret += b; return ret; }
+ friend Derived operator-(const indexed_based_stl_iterator_base& a, Index b) { Derived ret(a.derived()); ret -= b; return ret; }
+ friend Derived operator+(Index a, const indexed_based_stl_iterator_base& b) { Derived ret(b.derived()); ret += a; return ret; }
+ friend Derived operator-(Index a, const indexed_based_stl_iterator_base& b) { Derived ret(b.derived()); ret -= a; return ret; }
+
+ Derived& operator+=(Index b) { m_index += b; return derived(); }
+ Derived& operator-=(Index b) { m_index -= b; return derived(); }
+
+ difference_type operator-(const indexed_based_stl_iterator_base& other) const
+ {
+ eigen_assert(mp_xpr == other.mp_xpr);
+ return m_index - other.m_index;
+ }
+
+ difference_type operator-(const other_iterator& other) const
+ {
+ eigen_assert(mp_xpr == other.mp_xpr);
+ return m_index - other.m_index;
+ }
+
+ bool operator==(const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index == other.m_index; }
+ bool operator!=(const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index != other.m_index; }
+ bool operator< (const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index < other.m_index; }
+ bool operator<=(const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index <= other.m_index; }
+ bool operator> (const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index > other.m_index; }
+ bool operator>=(const indexed_based_stl_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index >= other.m_index; }
+
+ bool operator==(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index == other.m_index; }
+ bool operator!=(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index != other.m_index; }
+ bool operator< (const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index < other.m_index; }
+ bool operator<=(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index <= other.m_index; }
+ bool operator> (const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index > other.m_index; }
+ bool operator>=(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index >= other.m_index; }
+
+protected:
+
+ Derived& derived() { return static_cast<Derived&>(*this); }
+ const Derived& derived() const { return static_cast<const Derived&>(*this); }
+
+ XprType *mp_xpr;
+ Index m_index;
+};
+
+template<typename Derived>
+class indexed_based_stl_reverse_iterator_base
+{
+protected:
+ typedef indexed_based_stl_iterator_traits<Derived> traits;
+ typedef typename traits::XprType XprType;
+ typedef indexed_based_stl_reverse_iterator_base<typename traits::non_const_iterator> non_const_iterator;
+ typedef indexed_based_stl_reverse_iterator_base<typename traits::const_iterator> const_iterator;
+ typedef typename internal::conditional<internal::is_const<XprType>::value,non_const_iterator,const_iterator>::type other_iterator;
+ // NOTE: in C++03 we cannot declare friend classes through typedefs because we need to write friend class:
+ friend class indexed_based_stl_reverse_iterator_base<typename traits::const_iterator>;
+ friend class indexed_based_stl_reverse_iterator_base<typename traits::non_const_iterator>;
+public:
+ typedef Index difference_type;
+ typedef std::random_access_iterator_tag iterator_category;
+
+ indexed_based_stl_reverse_iterator_base() : mp_xpr(0), m_index(0) {}
+ indexed_based_stl_reverse_iterator_base(XprType& xpr, Index index) : mp_xpr(&xpr), m_index(index) {}
+
+ indexed_based_stl_reverse_iterator_base(const non_const_iterator& other)
+ : mp_xpr(other.mp_xpr), m_index(other.m_index)
+ {}
+
+ indexed_based_stl_reverse_iterator_base& operator=(const non_const_iterator& other)
+ {
+ mp_xpr = other.mp_xpr;
+ m_index = other.m_index;
+ return *this;
+ }
+
+ Derived& operator++() { --m_index; return derived(); }
+ Derived& operator--() { ++m_index; return derived(); }
+
+ Derived operator++(int) { Derived prev(derived()); operator++(); return prev;}
+ Derived operator--(int) { Derived prev(derived()); operator--(); return prev;}
+
+ friend Derived operator+(const indexed_based_stl_reverse_iterator_base& a, Index b) { Derived ret(a.derived()); ret += b; return ret; }
+ friend Derived operator-(const indexed_based_stl_reverse_iterator_base& a, Index b) { Derived ret(a.derived()); ret -= b; return ret; }
+ friend Derived operator+(Index a, const indexed_based_stl_reverse_iterator_base& b) { Derived ret(b.derived()); ret += a; return ret; }
+ friend Derived operator-(Index a, const indexed_based_stl_reverse_iterator_base& b) { Derived ret(b.derived()); ret -= a; return ret; }
+
+ Derived& operator+=(Index b) { m_index -= b; return derived(); }
+ Derived& operator-=(Index b) { m_index += b; return derived(); }
+
+ difference_type operator-(const indexed_based_stl_reverse_iterator_base& other) const
+ {
+ eigen_assert(mp_xpr == other.mp_xpr);
+ return other.m_index - m_index;
+ }
+
+ difference_type operator-(const other_iterator& other) const
+ {
+ eigen_assert(mp_xpr == other.mp_xpr);
+ return other.m_index - m_index;
+ }
+
+ bool operator==(const indexed_based_stl_reverse_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index == other.m_index; }
+ bool operator!=(const indexed_based_stl_reverse_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index != other.m_index; }
+ bool operator< (const indexed_based_stl_reverse_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index > other.m_index; }
+ bool operator<=(const indexed_based_stl_reverse_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index >= other.m_index; }
+ bool operator> (const indexed_based_stl_reverse_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index < other.m_index; }
+ bool operator>=(const indexed_based_stl_reverse_iterator_base& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index <= other.m_index; }
+
+ bool operator==(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index == other.m_index; }
+ bool operator!=(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index != other.m_index; }
+ bool operator< (const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index > other.m_index; }
+ bool operator<=(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index >= other.m_index; }
+ bool operator> (const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index < other.m_index; }
+ bool operator>=(const other_iterator& other) const { eigen_assert(mp_xpr == other.mp_xpr); return m_index <= other.m_index; }
+
+protected:
+
+ Derived& derived() { return static_cast<Derived&>(*this); }
+ const Derived& derived() const { return static_cast<const Derived&>(*this); }
+
+ XprType *mp_xpr;
+ Index m_index;
+};
+
+template<typename XprType>
+class pointer_based_stl_iterator
+{
+ enum { is_lvalue = internal::is_lvalue<XprType>::value };
+ typedef pointer_based_stl_iterator<typename internal::remove_const<XprType>::type> non_const_iterator;
+ typedef pointer_based_stl_iterator<typename internal::add_const<XprType>::type> const_iterator;
+ typedef typename internal::conditional<internal::is_const<XprType>::value,non_const_iterator,const_iterator>::type other_iterator;
+ // NOTE: in C++03 we cannot declare friend classes through typedefs because we need to write friend class:
+ friend class pointer_based_stl_iterator<typename internal::add_const<XprType>::type>;
+ friend class pointer_based_stl_iterator<typename internal::remove_const<XprType>::type>;
+public:
+ typedef Index difference_type;
+ typedef typename XprType::Scalar value_type;
+ typedef std::random_access_iterator_tag iterator_category;
+ typedef typename internal::conditional<bool(is_lvalue), value_type*, const value_type*>::type pointer;
+ typedef typename internal::conditional<bool(is_lvalue), value_type&, const value_type&>::type reference;
+
+
+ pointer_based_stl_iterator() EIGEN_NO_THROW : m_ptr(0) {}
+ pointer_based_stl_iterator(XprType& xpr, Index index) EIGEN_NO_THROW : m_incr(xpr.innerStride())
+ {
+ m_ptr = xpr.data() + index * m_incr.value();
+ }
+
+ pointer_based_stl_iterator(const non_const_iterator& other) EIGEN_NO_THROW
+ : m_ptr(other.m_ptr), m_incr(other.m_incr)
+ {}
+
+ pointer_based_stl_iterator& operator=(const non_const_iterator& other) EIGEN_NO_THROW
+ {
+ m_ptr = other.m_ptr;
+ m_incr.setValue(other.m_incr);
+ return *this;
+ }
+
+ reference operator*() const { return *m_ptr; }
+ reference operator[](Index i) const { return *(m_ptr+i*m_incr.value()); }
+ pointer operator->() const { return m_ptr; }
+
+ pointer_based_stl_iterator& operator++() { m_ptr += m_incr.value(); return *this; }
+ pointer_based_stl_iterator& operator--() { m_ptr -= m_incr.value(); return *this; }
+
+ pointer_based_stl_iterator operator++(int) { pointer_based_stl_iterator prev(*this); operator++(); return prev;}
+ pointer_based_stl_iterator operator--(int) { pointer_based_stl_iterator prev(*this); operator--(); return prev;}
+
+ friend pointer_based_stl_iterator operator+(const pointer_based_stl_iterator& a, Index b) { pointer_based_stl_iterator ret(a); ret += b; return ret; }
+ friend pointer_based_stl_iterator operator-(const pointer_based_stl_iterator& a, Index b) { pointer_based_stl_iterator ret(a); ret -= b; return ret; }
+ friend pointer_based_stl_iterator operator+(Index a, const pointer_based_stl_iterator& b) { pointer_based_stl_iterator ret(b); ret += a; return ret; }
+ friend pointer_based_stl_iterator operator-(Index a, const pointer_based_stl_iterator& b) { pointer_based_stl_iterator ret(b); ret -= a; return ret; }
+
+ pointer_based_stl_iterator& operator+=(Index b) { m_ptr += b*m_incr.value(); return *this; }
+ pointer_based_stl_iterator& operator-=(Index b) { m_ptr -= b*m_incr.value(); return *this; }
+
+ difference_type operator-(const pointer_based_stl_iterator& other) const {
+ return (m_ptr - other.m_ptr)/m_incr.value();
+ }
+
+ difference_type operator-(const other_iterator& other) const {
+ return (m_ptr - other.m_ptr)/m_incr.value();
+ }
+
+ bool operator==(const pointer_based_stl_iterator& other) const { return m_ptr == other.m_ptr; }
+ bool operator!=(const pointer_based_stl_iterator& other) const { return m_ptr != other.m_ptr; }
+ bool operator< (const pointer_based_stl_iterator& other) const { return m_ptr < other.m_ptr; }
+ bool operator<=(const pointer_based_stl_iterator& other) const { return m_ptr <= other.m_ptr; }
+ bool operator> (const pointer_based_stl_iterator& other) const { return m_ptr > other.m_ptr; }
+ bool operator>=(const pointer_based_stl_iterator& other) const { return m_ptr >= other.m_ptr; }
+
+ bool operator==(const other_iterator& other) const { return m_ptr == other.m_ptr; }
+ bool operator!=(const other_iterator& other) const { return m_ptr != other.m_ptr; }
+ bool operator< (const other_iterator& other) const { return m_ptr < other.m_ptr; }
+ bool operator<=(const other_iterator& other) const { return m_ptr <= other.m_ptr; }
+ bool operator> (const other_iterator& other) const { return m_ptr > other.m_ptr; }
+ bool operator>=(const other_iterator& other) const { return m_ptr >= other.m_ptr; }
+
+protected:
+
+ pointer m_ptr;
+ internal::variable_if_dynamic<Index, XprType::InnerStrideAtCompileTime> m_incr;
+};
+
+template<typename _XprType>
+struct indexed_based_stl_iterator_traits<generic_randaccess_stl_iterator<_XprType> >
+{
+ typedef _XprType XprType;
+ typedef generic_randaccess_stl_iterator<typename internal::remove_const<XprType>::type> non_const_iterator;
+ typedef generic_randaccess_stl_iterator<typename internal::add_const<XprType>::type> const_iterator;
+};
+
+template<typename XprType>
+class generic_randaccess_stl_iterator : public indexed_based_stl_iterator_base<generic_randaccess_stl_iterator<XprType> >
+{
+public:
+ typedef typename XprType::Scalar value_type;
+
+protected:
+
+ enum {
+ has_direct_access = (internal::traits<XprType>::Flags & DirectAccessBit) ? 1 : 0,
+ is_lvalue = internal::is_lvalue<XprType>::value
+ };
+
+ typedef indexed_based_stl_iterator_base<generic_randaccess_stl_iterator> Base;
+ using Base::m_index;
+ using Base::mp_xpr;
+
+ // TODO currently const Transpose/Reshape expressions never returns const references,
+ // so lets return by value too.
+ //typedef typename internal::conditional<bool(has_direct_access), const value_type&, const value_type>::type read_only_ref_t;
+ typedef const value_type read_only_ref_t;
+
+public:
+
+ typedef typename internal::conditional<bool(is_lvalue), value_type *, const value_type *>::type pointer;
+ typedef typename internal::conditional<bool(is_lvalue), value_type&, read_only_ref_t>::type reference;
+
+ generic_randaccess_stl_iterator() : Base() {}
+ generic_randaccess_stl_iterator(XprType& xpr, Index index) : Base(xpr,index) {}
+ generic_randaccess_stl_iterator(const typename Base::non_const_iterator& other) : Base(other) {}
+ using Base::operator=;
+
+ reference operator*() const { return (*mp_xpr)(m_index); }
+ reference operator[](Index i) const { return (*mp_xpr)(m_index+i); }
+ pointer operator->() const { return &((*mp_xpr)(m_index)); }
+};
+
+template<typename _XprType, DirectionType Direction>
+struct indexed_based_stl_iterator_traits<subvector_stl_iterator<_XprType,Direction> >
+{
+ typedef _XprType XprType;
+ typedef subvector_stl_iterator<typename internal::remove_const<XprType>::type, Direction> non_const_iterator;
+ typedef subvector_stl_iterator<typename internal::add_const<XprType>::type, Direction> const_iterator;
+};
+
+template<typename XprType, DirectionType Direction>
+class subvector_stl_iterator : public indexed_based_stl_iterator_base<subvector_stl_iterator<XprType,Direction> >
+{
+protected:
+
+ enum { is_lvalue = internal::is_lvalue<XprType>::value };
+
+ typedef indexed_based_stl_iterator_base<subvector_stl_iterator> Base;
+ using Base::m_index;
+ using Base::mp_xpr;
+
+ typedef typename internal::conditional<Direction==Vertical,typename XprType::ColXpr,typename XprType::RowXpr>::type SubVectorType;
+ typedef typename internal::conditional<Direction==Vertical,typename XprType::ConstColXpr,typename XprType::ConstRowXpr>::type ConstSubVectorType;
+
+
+public:
+ typedef typename internal::conditional<bool(is_lvalue), SubVectorType, ConstSubVectorType>::type reference;
+ typedef typename reference::PlainObject value_type;
+
+private:
+ class subvector_stl_iterator_ptr
+ {
+ public:
+ subvector_stl_iterator_ptr(const reference &subvector) : m_subvector(subvector) {}
+ reference* operator->() { return &m_subvector; }
+ private:
+ reference m_subvector;
+ };
+public:
+
+ typedef subvector_stl_iterator_ptr pointer;
+
+ subvector_stl_iterator() : Base() {}
+ subvector_stl_iterator(XprType& xpr, Index index) : Base(xpr,index) {}
+
+ reference operator*() const { return (*mp_xpr).template subVector<Direction>(m_index); }
+ reference operator[](Index i) const { return (*mp_xpr).template subVector<Direction>(m_index+i); }
+ pointer operator->() const { return (*mp_xpr).template subVector<Direction>(m_index); }
+};
+
+template<typename _XprType, DirectionType Direction>
+struct indexed_based_stl_iterator_traits<subvector_stl_reverse_iterator<_XprType,Direction> >
+{
+ typedef _XprType XprType;
+ typedef subvector_stl_reverse_iterator<typename internal::remove_const<XprType>::type, Direction> non_const_iterator;
+ typedef subvector_stl_reverse_iterator<typename internal::add_const<XprType>::type, Direction> const_iterator;
+};
+
+template<typename XprType, DirectionType Direction>
+class subvector_stl_reverse_iterator : public indexed_based_stl_reverse_iterator_base<subvector_stl_reverse_iterator<XprType,Direction> >
+{
+protected:
+
+ enum { is_lvalue = internal::is_lvalue<XprType>::value };
+
+ typedef indexed_based_stl_reverse_iterator_base<subvector_stl_reverse_iterator> Base;
+ using Base::m_index;
+ using Base::mp_xpr;
+
+ typedef typename internal::conditional<Direction==Vertical,typename XprType::ColXpr,typename XprType::RowXpr>::type SubVectorType;
+ typedef typename internal::conditional<Direction==Vertical,typename XprType::ConstColXpr,typename XprType::ConstRowXpr>::type ConstSubVectorType;
+
+
+public:
+ typedef typename internal::conditional<bool(is_lvalue), SubVectorType, ConstSubVectorType>::type reference;
+ typedef typename reference::PlainObject value_type;
+
+private:
+ class subvector_stl_reverse_iterator_ptr
+ {
+ public:
+ subvector_stl_reverse_iterator_ptr(const reference &subvector) : m_subvector(subvector) {}
+ reference* operator->() { return &m_subvector; }
+ private:
+ reference m_subvector;
+ };
+public:
+
+ typedef subvector_stl_reverse_iterator_ptr pointer;
+
+ subvector_stl_reverse_iterator() : Base() {}
+ subvector_stl_reverse_iterator(XprType& xpr, Index index) : Base(xpr,index) {}
+
+ reference operator*() const { return (*mp_xpr).template subVector<Direction>(m_index); }
+ reference operator[](Index i) const { return (*mp_xpr).template subVector<Direction>(m_index+i); }
+ pointer operator->() const { return (*mp_xpr).template subVector<Direction>(m_index); }
+};
+
+} // namespace internal
+
+
+/** returns an iterator to the first element of the 1D vector or array
+ * \only_for_vectors
+ * \sa end(), cbegin()
+ */
+template<typename Derived>
+inline typename DenseBase<Derived>::iterator DenseBase<Derived>::begin()
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
+ return iterator(derived(), 0);
+}
+
+/** const version of begin() */
+template<typename Derived>
+inline typename DenseBase<Derived>::const_iterator DenseBase<Derived>::begin() const
+{
+ return cbegin();
+}
+
+/** returns a read-only const_iterator to the first element of the 1D vector or array
+ * \only_for_vectors
+ * \sa cend(), begin()
+ */
+template<typename Derived>
+inline typename DenseBase<Derived>::const_iterator DenseBase<Derived>::cbegin() const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
+ return const_iterator(derived(), 0);
+}
+
+/** returns an iterator to the element following the last element of the 1D vector or array
+ * \only_for_vectors
+ * \sa begin(), cend()
+ */
+template<typename Derived>
+inline typename DenseBase<Derived>::iterator DenseBase<Derived>::end()
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
+ return iterator(derived(), size());
+}
+
+/** const version of end() */
+template<typename Derived>
+inline typename DenseBase<Derived>::const_iterator DenseBase<Derived>::end() const
+{
+ return cend();
+}
+
+/** returns a read-only const_iterator to the element following the last element of the 1D vector or array
+ * \only_for_vectors
+ * \sa begin(), cend()
+ */
+template<typename Derived>
+inline typename DenseBase<Derived>::const_iterator DenseBase<Derived>::cend() const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
+ return const_iterator(derived(), size());
+}
+
+} // namespace Eigen
+
+#endif // EIGEN_STLITERATORS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Stride.h b/src/3rdparty/eigen/Eigen/src/Core/Stride.h
new file mode 100644
index 000000000..6494d5142
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Stride.h
@@ -0,0 +1,116 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_STRIDE_H
+#define EIGEN_STRIDE_H
+
+namespace Eigen {
+
+/** \class Stride
+ * \ingroup Core_Module
+ *
+ * \brief Holds strides information for Map
+ *
+ * This class holds the strides information for mapping arrays with strides with class Map.
+ *
+ * It holds two values: the inner stride and the outer stride.
+ *
+ * The inner stride is the pointer increment between two consecutive entries within a given row of a
+ * row-major matrix or within a given column of a column-major matrix.
+ *
+ * The outer stride is the pointer increment between two consecutive rows of a row-major matrix or
+ * between two consecutive columns of a column-major matrix.
+ *
+ * These two values can be passed either at compile-time as template parameters, or at runtime as
+ * arguments to the constructor.
+ *
+ * Indeed, this class takes two template parameters:
+ * \tparam _OuterStrideAtCompileTime the outer stride, or Dynamic if you want to specify it at runtime.
+ * \tparam _InnerStrideAtCompileTime the inner stride, or Dynamic if you want to specify it at runtime.
+ *
+ * Here is an example:
+ * \include Map_general_stride.cpp
+ * Output: \verbinclude Map_general_stride.out
+ *
+ * Both strides can be negative, however, a negative stride of -1 cannot be specified at compiletime
+ * because of the ambiguity with Dynamic which is defined to -1 (historically, negative strides were
+ * not allowed).
+ *
+ * \sa class InnerStride, class OuterStride, \ref TopicStorageOrders
+ */
+template<int _OuterStrideAtCompileTime, int _InnerStrideAtCompileTime>
+class Stride
+{
+ public:
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+ enum {
+ InnerStrideAtCompileTime = _InnerStrideAtCompileTime,
+ OuterStrideAtCompileTime = _OuterStrideAtCompileTime
+ };
+
+ /** Default constructor, for use when strides are fixed at compile time */
+ EIGEN_DEVICE_FUNC
+ Stride()
+ : m_outer(OuterStrideAtCompileTime), m_inner(InnerStrideAtCompileTime)
+ {
+ // FIXME: for Eigen 4 we should use DynamicIndex instead of Dynamic.
+ // FIXME: for Eigen 4 we should also unify this API with fix<>
+ eigen_assert(InnerStrideAtCompileTime != Dynamic && OuterStrideAtCompileTime != Dynamic);
+ }
+
+ /** Constructor allowing to pass the strides at runtime */
+ EIGEN_DEVICE_FUNC
+ Stride(Index outerStride, Index innerStride)
+ : m_outer(outerStride), m_inner(innerStride)
+ {
+ }
+
+ /** Copy constructor */
+ EIGEN_DEVICE_FUNC
+ Stride(const Stride& other)
+ : m_outer(other.outer()), m_inner(other.inner())
+ {}
+
+ /** \returns the outer stride */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outer() const { return m_outer.value(); }
+ /** \returns the inner stride */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index inner() const { return m_inner.value(); }
+
+ protected:
+ internal::variable_if_dynamic<Index, OuterStrideAtCompileTime> m_outer;
+ internal::variable_if_dynamic<Index, InnerStrideAtCompileTime> m_inner;
+};
+
+/** \brief Convenience specialization of Stride to specify only an inner stride
+ * See class Map for some examples */
+template<int Value>
+class InnerStride : public Stride<0, Value>
+{
+ typedef Stride<0, Value> Base;
+ public:
+ EIGEN_DEVICE_FUNC InnerStride() : Base() {}
+ EIGEN_DEVICE_FUNC InnerStride(Index v) : Base(0, v) {} // FIXME making this explicit could break valid code
+};
+
+/** \brief Convenience specialization of Stride to specify only an outer stride
+ * See class Map for some examples */
+template<int Value>
+class OuterStride : public Stride<Value, 0>
+{
+ typedef Stride<Value, 0> Base;
+ public:
+ EIGEN_DEVICE_FUNC OuterStride() : Base() {}
+ EIGEN_DEVICE_FUNC OuterStride(Index v) : Base(v,0) {} // FIXME making this explicit could break valid code
+};
+
+} // end namespace Eigen
+
+#endif // EIGEN_STRIDE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Swap.h b/src/3rdparty/eigen/Eigen/src/Core/Swap.h
new file mode 100644
index 000000000..180a4e5ad
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Swap.h
@@ -0,0 +1,68 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SWAP_H
+#define EIGEN_SWAP_H
+
+namespace Eigen {
+
+namespace internal {
+
+// Overload default assignPacket behavior for swapping them
+template<typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT>
+class generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, Specialized>
+ : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn>
+{
+protected:
+ typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn> Base;
+ using Base::m_dst;
+ using Base::m_src;
+ using Base::m_functor;
+
+public:
+ typedef typename Base::Scalar Scalar;
+ typedef typename Base::DstXprType DstXprType;
+ typedef swap_assign_op<Scalar> Functor;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ generic_dense_assignment_kernel(DstEvaluatorTypeT &dst, const SrcEvaluatorTypeT &src, const Functor &func, DstXprType& dstExpr)
+ : Base(dst, src, func, dstExpr)
+ {}
+
+ template<int StoreMode, int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE void assignPacket(Index row, Index col)
+ {
+ PacketType tmp = m_src.template packet<LoadMode,PacketType>(row,col);
+ const_cast<SrcEvaluatorTypeT&>(m_src).template writePacket<LoadMode>(row,col, m_dst.template packet<StoreMode,PacketType>(row,col));
+ m_dst.template writePacket<StoreMode>(row,col,tmp);
+ }
+
+ template<int StoreMode, int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE void assignPacket(Index index)
+ {
+ PacketType tmp = m_src.template packet<LoadMode,PacketType>(index);
+ const_cast<SrcEvaluatorTypeT&>(m_src).template writePacket<LoadMode>(index, m_dst.template packet<StoreMode,PacketType>(index));
+ m_dst.template writePacket<StoreMode>(index,tmp);
+ }
+
+ // TODO find a simple way not to have to copy/paste this function from generic_dense_assignment_kernel, by simple I mean no CRTP (Gael)
+ template<int StoreMode, int LoadMode, typename PacketType>
+ EIGEN_STRONG_INLINE void assignPacketByOuterInner(Index outer, Index inner)
+ {
+ Index row = Base::rowIndexByOuterInner(outer, inner);
+ Index col = Base::colIndexByOuterInner(outer, inner);
+ assignPacket<StoreMode,LoadMode,PacketType>(row, col);
+ }
+};
+
+} // namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_SWAP_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Transpose.h b/src/3rdparty/eigen/Eigen/src/Core/Transpose.h
new file mode 100644
index 000000000..2bc658f40
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Transpose.h
@@ -0,0 +1,464 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2009-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TRANSPOSE_H
+#define EIGEN_TRANSPOSE_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename MatrixType>
+struct traits<Transpose<MatrixType> > : public traits<MatrixType>
+{
+ typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
+ typedef typename remove_reference<MatrixTypeNested>::type MatrixTypeNestedPlain;
+ enum {
+ RowsAtCompileTime = MatrixType::ColsAtCompileTime,
+ ColsAtCompileTime = MatrixType::RowsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
+ Flags0 = traits<MatrixTypeNestedPlain>::Flags & ~(LvalueBit | NestByRefBit),
+ Flags1 = Flags0 | FlagsLvalueBit,
+ Flags = Flags1 ^ RowMajorBit,
+ InnerStrideAtCompileTime = inner_stride_at_compile_time<MatrixType>::ret,
+ OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret
+ };
+};
+}
+
+template<typename MatrixType, typename StorageKind> class TransposeImpl;
+
+/** \class Transpose
+ * \ingroup Core_Module
+ *
+ * \brief Expression of the transpose of a matrix
+ *
+ * \tparam MatrixType the type of the object of which we are taking the transpose
+ *
+ * This class represents an expression of the transpose of a matrix.
+ * It is the return type of MatrixBase::transpose() and MatrixBase::adjoint()
+ * and most of the time this is the only way it is used.
+ *
+ * \sa MatrixBase::transpose(), MatrixBase::adjoint()
+ */
+template<typename MatrixType> class Transpose
+ : public TransposeImpl<MatrixType,typename internal::traits<MatrixType>::StorageKind>
+{
+ public:
+
+ typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested;
+
+ typedef typename TransposeImpl<MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
+ EIGEN_GENERIC_PUBLIC_INTERFACE(Transpose)
+ typedef typename internal::remove_all<MatrixType>::type NestedExpression;
+
+ EIGEN_DEVICE_FUNC
+ explicit EIGEN_STRONG_INLINE Transpose(MatrixType& matrix) : m_matrix(matrix) {}
+
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose)
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index rows() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ Index cols() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
+
+ /** \returns the nested expression */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const typename internal::remove_all<MatrixTypeNested>::type&
+ nestedExpression() const { return m_matrix; }
+
+ /** \returns the nested expression */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ typename internal::remove_reference<MatrixTypeNested>::type&
+ nestedExpression() { return m_matrix; }
+
+ /** \internal */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void resize(Index nrows, Index ncols) {
+ m_matrix.resize(ncols,nrows);
+ }
+
+ protected:
+ typename internal::ref_selector<MatrixType>::non_const_type m_matrix;
+};
+
+namespace internal {
+
+template<typename MatrixType, bool HasDirectAccess = has_direct_access<MatrixType>::ret>
+struct TransposeImpl_base
+{
+ typedef typename dense_xpr_base<Transpose<MatrixType> >::type type;
+};
+
+template<typename MatrixType>
+struct TransposeImpl_base<MatrixType, false>
+{
+ typedef typename dense_xpr_base<Transpose<MatrixType> >::type type;
+};
+
+} // end namespace internal
+
+// Generic API dispatcher
+template<typename XprType, typename StorageKind>
+class TransposeImpl
+ : public internal::generic_xpr_base<Transpose<XprType> >::type
+{
+public:
+ typedef typename internal::generic_xpr_base<Transpose<XprType> >::type Base;
+};
+
+template<typename MatrixType> class TransposeImpl<MatrixType,Dense>
+ : public internal::TransposeImpl_base<MatrixType>::type
+{
+ public:
+
+ typedef typename internal::TransposeImpl_base<MatrixType>::type Base;
+ using Base::coeffRef;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Transpose<MatrixType>)
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TransposeImpl)
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Index innerStride() const { return derived().nestedExpression().innerStride(); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Index outerStride() const { return derived().nestedExpression().outerStride(); }
+
+ typedef typename internal::conditional<
+ internal::is_lvalue<MatrixType>::value,
+ Scalar,
+ const Scalar
+ >::type ScalarWithConstIfNotLvalue;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ ScalarWithConstIfNotLvalue* data() { return derived().nestedExpression().data(); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const Scalar* data() const { return derived().nestedExpression().data(); }
+
+ // FIXME: shall we keep the const version of coeffRef?
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const Scalar& coeffRef(Index rowId, Index colId) const
+ {
+ return derived().nestedExpression().coeffRef(colId, rowId);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const Scalar& coeffRef(Index index) const
+ {
+ return derived().nestedExpression().coeffRef(index);
+ }
+ protected:
+ EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(TransposeImpl)
+};
+
+/** \returns an expression of the transpose of *this.
+ *
+ * Example: \include MatrixBase_transpose.cpp
+ * Output: \verbinclude MatrixBase_transpose.out
+ *
+ * \warning If you want to replace a matrix by its own transpose, do \b NOT do this:
+ * \code
+ * m = m.transpose(); // bug!!! caused by aliasing effect
+ * \endcode
+ * Instead, use the transposeInPlace() method:
+ * \code
+ * m.transposeInPlace();
+ * \endcode
+ * which gives Eigen good opportunities for optimization, or alternatively you can also do:
+ * \code
+ * m = m.transpose().eval();
+ * \endcode
+ *
+ * \sa transposeInPlace(), adjoint() */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+Transpose<Derived>
+DenseBase<Derived>::transpose()
+{
+ return TransposeReturnType(derived());
+}
+
+/** This is the const version of transpose().
+ *
+ * Make sure you read the warning for transpose() !
+ *
+ * \sa transposeInPlace(), adjoint() */
+template<typename Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename DenseBase<Derived>::ConstTransposeReturnType
+DenseBase<Derived>::transpose() const
+{
+ return ConstTransposeReturnType(derived());
+}
+
+/** \returns an expression of the adjoint (i.e. conjugate transpose) of *this.
+ *
+ * Example: \include MatrixBase_adjoint.cpp
+ * Output: \verbinclude MatrixBase_adjoint.out
+ *
+ * \warning If you want to replace a matrix by its own adjoint, do \b NOT do this:
+ * \code
+ * m = m.adjoint(); // bug!!! caused by aliasing effect
+ * \endcode
+ * Instead, use the adjointInPlace() method:
+ * \code
+ * m.adjointInPlace();
+ * \endcode
+ * which gives Eigen good opportunities for optimization, or alternatively you can also do:
+ * \code
+ * m = m.adjoint().eval();
+ * \endcode
+ *
+ * \sa adjointInPlace(), transpose(), conjugate(), class Transpose, class internal::scalar_conjugate_op */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline const typename MatrixBase<Derived>::AdjointReturnType
+MatrixBase<Derived>::adjoint() const
+{
+ return AdjointReturnType(this->transpose());
+}
+
+/***************************************************************************
+* "in place" transpose implementation
+***************************************************************************/
+
+namespace internal {
+
+template<typename MatrixType,
+ bool IsSquare = (MatrixType::RowsAtCompileTime == MatrixType::ColsAtCompileTime) && MatrixType::RowsAtCompileTime!=Dynamic,
+ bool MatchPacketSize =
+ (int(MatrixType::RowsAtCompileTime) == int(internal::packet_traits<typename MatrixType::Scalar>::size))
+ && (internal::evaluator<MatrixType>::Flags&PacketAccessBit) >
+struct inplace_transpose_selector;
+
+template<typename MatrixType>
+struct inplace_transpose_selector<MatrixType,true,false> { // square matrix
+ static void run(MatrixType& m) {
+ m.matrix().template triangularView<StrictlyUpper>().swap(m.matrix().transpose().template triangularView<StrictlyUpper>());
+ }
+};
+
+template<typename MatrixType>
+struct inplace_transpose_selector<MatrixType,true,true> { // PacketSize x PacketSize
+ static void run(MatrixType& m) {
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename internal::packet_traits<typename MatrixType::Scalar>::type Packet;
+ const Index PacketSize = internal::packet_traits<Scalar>::size;
+ const Index Alignment = internal::evaluator<MatrixType>::Alignment;
+ PacketBlock<Packet> A;
+ for (Index i=0; i<PacketSize; ++i)
+ A.packet[i] = m.template packetByOuterInner<Alignment>(i,0);
+ internal::ptranspose(A);
+ for (Index i=0; i<PacketSize; ++i)
+ m.template writePacket<Alignment>(m.rowIndexByOuterInner(i,0), m.colIndexByOuterInner(i,0), A.packet[i]);
+ }
+};
+
+
+template <typename MatrixType, Index Alignment>
+void BlockedInPlaceTranspose(MatrixType& m) {
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename internal::packet_traits<typename MatrixType::Scalar>::type Packet;
+ const Index PacketSize = internal::packet_traits<Scalar>::size;
+ eigen_assert(m.rows() == m.cols());
+ int row_start = 0;
+ for (; row_start + PacketSize <= m.rows(); row_start += PacketSize) {
+ for (int col_start = row_start; col_start + PacketSize <= m.cols(); col_start += PacketSize) {
+ PacketBlock<Packet> A;
+ if (row_start == col_start) {
+ for (Index i=0; i<PacketSize; ++i)
+ A.packet[i] = m.template packetByOuterInner<Alignment>(row_start + i,col_start);
+ internal::ptranspose(A);
+ for (Index i=0; i<PacketSize; ++i)
+ m.template writePacket<Alignment>(m.rowIndexByOuterInner(row_start + i, col_start), m.colIndexByOuterInner(row_start + i,col_start), A.packet[i]);
+ } else {
+ PacketBlock<Packet> B;
+ for (Index i=0; i<PacketSize; ++i) {
+ A.packet[i] = m.template packetByOuterInner<Alignment>(row_start + i,col_start);
+ B.packet[i] = m.template packetByOuterInner<Alignment>(col_start + i, row_start);
+ }
+ internal::ptranspose(A);
+ internal::ptranspose(B);
+ for (Index i=0; i<PacketSize; ++i) {
+ m.template writePacket<Alignment>(m.rowIndexByOuterInner(row_start + i, col_start), m.colIndexByOuterInner(row_start + i,col_start), B.packet[i]);
+ m.template writePacket<Alignment>(m.rowIndexByOuterInner(col_start + i, row_start), m.colIndexByOuterInner(col_start + i,row_start), A.packet[i]);
+ }
+ }
+ }
+ }
+ for (Index row = row_start; row < m.rows(); ++row) {
+ m.matrix().row(row).head(row).swap(
+ m.matrix().col(row).head(row).transpose());
+ }
+}
+
+template<typename MatrixType,bool MatchPacketSize>
+struct inplace_transpose_selector<MatrixType,false,MatchPacketSize> { // non square or dynamic matrix
+ static void run(MatrixType& m) {
+ typedef typename MatrixType::Scalar Scalar;
+ if (m.rows() == m.cols()) {
+ const Index PacketSize = internal::packet_traits<Scalar>::size;
+ if (!NumTraits<Scalar>::IsComplex && m.rows() >= PacketSize) {
+ if ((m.rows() % PacketSize) == 0)
+ BlockedInPlaceTranspose<MatrixType,internal::evaluator<MatrixType>::Alignment>(m);
+ else
+ BlockedInPlaceTranspose<MatrixType,Unaligned>(m);
+ }
+ else {
+ m.matrix().template triangularView<StrictlyUpper>().swap(m.matrix().transpose().template triangularView<StrictlyUpper>());
+ }
+ } else {
+ m = m.transpose().eval();
+ }
+ }
+};
+
+
+} // end namespace internal
+
+/** This is the "in place" version of transpose(): it replaces \c *this by its own transpose.
+ * Thus, doing
+ * \code
+ * m.transposeInPlace();
+ * \endcode
+ * has the same effect on m as doing
+ * \code
+ * m = m.transpose().eval();
+ * \endcode
+ * and is faster and also safer because in the latter line of code, forgetting the eval() results
+ * in a bug caused by \ref TopicAliasing "aliasing".
+ *
+ * Notice however that this method is only useful if you want to replace a matrix by its own transpose.
+ * If you just need the transpose of a matrix, use transpose().
+ *
+ * \note if the matrix is not square, then \c *this must be a resizable matrix.
+ * This excludes (non-square) fixed-size matrices, block-expressions and maps.
+ *
+ * \sa transpose(), adjoint(), adjointInPlace() */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline void DenseBase<Derived>::transposeInPlace()
+{
+ eigen_assert((rows() == cols() || (RowsAtCompileTime == Dynamic && ColsAtCompileTime == Dynamic))
+ && "transposeInPlace() called on a non-square non-resizable matrix");
+ internal::inplace_transpose_selector<Derived>::run(derived());
+}
+
+/***************************************************************************
+* "in place" adjoint implementation
+***************************************************************************/
+
+/** This is the "in place" version of adjoint(): it replaces \c *this by its own transpose.
+ * Thus, doing
+ * \code
+ * m.adjointInPlace();
+ * \endcode
+ * has the same effect on m as doing
+ * \code
+ * m = m.adjoint().eval();
+ * \endcode
+ * and is faster and also safer because in the latter line of code, forgetting the eval() results
+ * in a bug caused by aliasing.
+ *
+ * Notice however that this method is only useful if you want to replace a matrix by its own adjoint.
+ * If you just need the adjoint of a matrix, use adjoint().
+ *
+ * \note if the matrix is not square, then \c *this must be a resizable matrix.
+ * This excludes (non-square) fixed-size matrices, block-expressions and maps.
+ *
+ * \sa transpose(), adjoint(), transposeInPlace() */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline void MatrixBase<Derived>::adjointInPlace()
+{
+ derived() = adjoint().eval();
+}
+
+#ifndef EIGEN_NO_DEBUG
+
+// The following is to detect aliasing problems in most common cases.
+
+namespace internal {
+
+template<bool DestIsTransposed, typename OtherDerived>
+struct check_transpose_aliasing_compile_time_selector
+{
+ enum { ret = bool(blas_traits<OtherDerived>::IsTransposed) != DestIsTransposed };
+};
+
+template<bool DestIsTransposed, typename BinOp, typename DerivedA, typename DerivedB>
+struct check_transpose_aliasing_compile_time_selector<DestIsTransposed,CwiseBinaryOp<BinOp,DerivedA,DerivedB> >
+{
+ enum { ret = bool(blas_traits<DerivedA>::IsTransposed) != DestIsTransposed
+ || bool(blas_traits<DerivedB>::IsTransposed) != DestIsTransposed
+ };
+};
+
+template<typename Scalar, bool DestIsTransposed, typename OtherDerived>
+struct check_transpose_aliasing_run_time_selector
+{
+ static bool run(const Scalar* dest, const OtherDerived& src)
+ {
+ return (bool(blas_traits<OtherDerived>::IsTransposed) != DestIsTransposed) && (dest!=0 && dest==(const Scalar*)extract_data(src));
+ }
+};
+
+template<typename Scalar, bool DestIsTransposed, typename BinOp, typename DerivedA, typename DerivedB>
+struct check_transpose_aliasing_run_time_selector<Scalar,DestIsTransposed,CwiseBinaryOp<BinOp,DerivedA,DerivedB> >
+{
+ static bool run(const Scalar* dest, const CwiseBinaryOp<BinOp,DerivedA,DerivedB>& src)
+ {
+ return ((blas_traits<DerivedA>::IsTransposed != DestIsTransposed) && (dest!=0 && dest==(const Scalar*)extract_data(src.lhs())))
+ || ((blas_traits<DerivedB>::IsTransposed != DestIsTransposed) && (dest!=0 && dest==(const Scalar*)extract_data(src.rhs())));
+ }
+};
+
+// the following selector, checkTransposeAliasing_impl, based on MightHaveTransposeAliasing,
+// is because when the condition controlling the assert is known at compile time, ICC emits a warning.
+// This is actually a good warning: in expressions that don't have any transposing, the condition is
+// known at compile time to be false, and using that, we can avoid generating the code of the assert again
+// and again for all these expressions that don't need it.
+
+template<typename Derived, typename OtherDerived,
+ bool MightHaveTransposeAliasing
+ = check_transpose_aliasing_compile_time_selector
+ <blas_traits<Derived>::IsTransposed,OtherDerived>::ret
+ >
+struct checkTransposeAliasing_impl
+{
+ static void run(const Derived& dst, const OtherDerived& other)
+ {
+ eigen_assert((!check_transpose_aliasing_run_time_selector
+ <typename Derived::Scalar,blas_traits<Derived>::IsTransposed,OtherDerived>
+ ::run(extract_data(dst), other))
+ && "aliasing detected during transposition, use transposeInPlace() "
+ "or evaluate the rhs into a temporary using .eval()");
+
+ }
+};
+
+template<typename Derived, typename OtherDerived>
+struct checkTransposeAliasing_impl<Derived, OtherDerived, false>
+{
+ static void run(const Derived&, const OtherDerived&)
+ {
+ }
+};
+
+template<typename Dst, typename Src>
+void check_for_aliasing(const Dst &dst, const Src &src)
+{
+ if((!Dst::IsVectorAtCompileTime) && dst.rows()>1 && dst.cols()>1)
+ internal::checkTransposeAliasing_impl<Dst, Src>::run(dst, src);
+}
+
+} // end namespace internal
+
+#endif // EIGEN_NO_DEBUG
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRANSPOSE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Transpositions.h b/src/3rdparty/eigen/Eigen/src/Core/Transpositions.h
new file mode 100644
index 000000000..38a7b01cb
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Transpositions.h
@@ -0,0 +1,386 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2010-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TRANSPOSITIONS_H
+#define EIGEN_TRANSPOSITIONS_H
+
+namespace Eigen {
+
+template<typename Derived>
+class TranspositionsBase
+{
+ typedef internal::traits<Derived> Traits;
+
+ public:
+
+ typedef typename Traits::IndicesType IndicesType;
+ typedef typename IndicesType::Scalar StorageIndex;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+
+ EIGEN_DEVICE_FUNC
+ Derived& derived() { return *static_cast<Derived*>(this); }
+ EIGEN_DEVICE_FUNC
+ const Derived& derived() const { return *static_cast<const Derived*>(this); }
+
+ /** Copies the \a other transpositions into \c *this */
+ template<typename OtherDerived>
+ Derived& operator=(const TranspositionsBase<OtherDerived>& other)
+ {
+ indices() = other.indices();
+ return derived();
+ }
+
+ /** \returns the number of transpositions */
+ EIGEN_DEVICE_FUNC
+ Index size() const { return indices().size(); }
+ /** \returns the number of rows of the equivalent permutation matrix */
+ EIGEN_DEVICE_FUNC
+ Index rows() const { return indices().size(); }
+ /** \returns the number of columns of the equivalent permutation matrix */
+ EIGEN_DEVICE_FUNC
+ Index cols() const { return indices().size(); }
+
+ /** Direct access to the underlying index vector */
+ EIGEN_DEVICE_FUNC
+ inline const StorageIndex& coeff(Index i) const { return indices().coeff(i); }
+ /** Direct access to the underlying index vector */
+ inline StorageIndex& coeffRef(Index i) { return indices().coeffRef(i); }
+ /** Direct access to the underlying index vector */
+ inline const StorageIndex& operator()(Index i) const { return indices()(i); }
+ /** Direct access to the underlying index vector */
+ inline StorageIndex& operator()(Index i) { return indices()(i); }
+ /** Direct access to the underlying index vector */
+ inline const StorageIndex& operator[](Index i) const { return indices()(i); }
+ /** Direct access to the underlying index vector */
+ inline StorageIndex& operator[](Index i) { return indices()(i); }
+
+ /** const version of indices(). */
+ EIGEN_DEVICE_FUNC
+ const IndicesType& indices() const { return derived().indices(); }
+ /** \returns a reference to the stored array representing the transpositions. */
+ EIGEN_DEVICE_FUNC
+ IndicesType& indices() { return derived().indices(); }
+
+ /** Resizes to given size. */
+ inline void resize(Index newSize)
+ {
+ indices().resize(newSize);
+ }
+
+ /** Sets \c *this to represents an identity transformation */
+ void setIdentity()
+ {
+ for(StorageIndex i = 0; i < indices().size(); ++i)
+ coeffRef(i) = i;
+ }
+
+ // FIXME: do we want such methods ?
+ // might be useful when the target matrix expression is complex, e.g.:
+ // object.matrix().block(..,..,..,..) = trans * object.matrix().block(..,..,..,..);
+ /*
+ template<typename MatrixType>
+ void applyForwardToRows(MatrixType& mat) const
+ {
+ for(Index k=0 ; k<size() ; ++k)
+ if(m_indices(k)!=k)
+ mat.row(k).swap(mat.row(m_indices(k)));
+ }
+
+ template<typename MatrixType>
+ void applyBackwardToRows(MatrixType& mat) const
+ {
+ for(Index k=size()-1 ; k>=0 ; --k)
+ if(m_indices(k)!=k)
+ mat.row(k).swap(mat.row(m_indices(k)));
+ }
+ */
+
+ /** \returns the inverse transformation */
+ inline Transpose<TranspositionsBase> inverse() const
+ { return Transpose<TranspositionsBase>(derived()); }
+
+ /** \returns the tranpose transformation */
+ inline Transpose<TranspositionsBase> transpose() const
+ { return Transpose<TranspositionsBase>(derived()); }
+
+ protected:
+};
+
+namespace internal {
+template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
+struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
+ : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
+{
+ typedef Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
+ typedef TranspositionsStorage StorageKind;
+};
+}
+
+/** \class Transpositions
+ * \ingroup Core_Module
+ *
+ * \brief Represents a sequence of transpositions (row/column interchange)
+ *
+ * \tparam SizeAtCompileTime the number of transpositions, or Dynamic
+ * \tparam MaxSizeAtCompileTime the maximum number of transpositions, or Dynamic. This optional parameter defaults to SizeAtCompileTime. Most of the time, you should not have to specify it.
+ *
+ * This class represents a permutation transformation as a sequence of \em n transpositions
+ * \f$[T_{n-1} \ldots T_{i} \ldots T_{0}]\f$. It is internally stored as a vector of integers \c indices.
+ * Each transposition \f$ T_{i} \f$ applied on the left of a matrix (\f$ T_{i} M\f$) interchanges
+ * the rows \c i and \c indices[i] of the matrix \c M.
+ * A transposition applied on the right (e.g., \f$ M T_{i}\f$) yields a column interchange.
+ *
+ * Compared to the class PermutationMatrix, such a sequence of transpositions is what is
+ * computed during a decomposition with pivoting, and it is faster when applying the permutation in-place.
+ *
+ * To apply a sequence of transpositions to a matrix, simply use the operator * as in the following example:
+ * \code
+ * Transpositions tr;
+ * MatrixXf mat;
+ * mat = tr * mat;
+ * \endcode
+ * In this example, we detect that the matrix appears on both side, and so the transpositions
+ * are applied in-place without any temporary or extra copy.
+ *
+ * \sa class PermutationMatrix
+ */
+
+template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
+class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
+{
+ typedef internal::traits<Transpositions> Traits;
+ public:
+
+ typedef TranspositionsBase<Transpositions> Base;
+ typedef typename Traits::IndicesType IndicesType;
+ typedef typename IndicesType::Scalar StorageIndex;
+
+ inline Transpositions() {}
+
+ /** Copy constructor. */
+ template<typename OtherDerived>
+ inline Transpositions(const TranspositionsBase<OtherDerived>& other)
+ : m_indices(other.indices()) {}
+
+ /** Generic constructor from expression of the transposition indices. */
+ template<typename Other>
+ explicit inline Transpositions(const MatrixBase<Other>& indices) : m_indices(indices)
+ {}
+
+ /** Copies the \a other transpositions into \c *this */
+ template<typename OtherDerived>
+ Transpositions& operator=(const TranspositionsBase<OtherDerived>& other)
+ {
+ return Base::operator=(other);
+ }
+
+ /** Constructs an uninitialized permutation matrix of given size.
+ */
+ inline Transpositions(Index size) : m_indices(size)
+ {}
+
+ /** const version of indices(). */
+ EIGEN_DEVICE_FUNC
+ const IndicesType& indices() const { return m_indices; }
+ /** \returns a reference to the stored array representing the transpositions. */
+ EIGEN_DEVICE_FUNC
+ IndicesType& indices() { return m_indices; }
+
+ protected:
+
+ IndicesType m_indices;
+};
+
+
+namespace internal {
+template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess>
+struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,_PacketAccess> >
+ : traits<PermutationMatrix<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex> >
+{
+ typedef Map<const Matrix<_StorageIndex,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1>, _PacketAccess> IndicesType;
+ typedef _StorageIndex StorageIndex;
+ typedef TranspositionsStorage StorageKind;
+};
+}
+
+template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int PacketAccess>
+class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess>
+ : public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndex>,PacketAccess> >
+{
+ typedef internal::traits<Map> Traits;
+ public:
+
+ typedef TranspositionsBase<Map> Base;
+ typedef typename Traits::IndicesType IndicesType;
+ typedef typename IndicesType::Scalar StorageIndex;
+
+ explicit inline Map(const StorageIndex* indicesPtr)
+ : m_indices(indicesPtr)
+ {}
+
+ inline Map(const StorageIndex* indicesPtr, Index size)
+ : m_indices(indicesPtr,size)
+ {}
+
+ /** Copies the \a other transpositions into \c *this */
+ template<typename OtherDerived>
+ Map& operator=(const TranspositionsBase<OtherDerived>& other)
+ {
+ return Base::operator=(other);
+ }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ /** This is a special case of the templated operator=. Its purpose is to
+ * prevent a default operator= from hiding the templated operator=.
+ */
+ Map& operator=(const Map& other)
+ {
+ m_indices = other.m_indices;
+ return *this;
+ }
+ #endif
+
+ /** const version of indices(). */
+ EIGEN_DEVICE_FUNC
+ const IndicesType& indices() const { return m_indices; }
+
+ /** \returns a reference to the stored array representing the transpositions. */
+ EIGEN_DEVICE_FUNC
+ IndicesType& indices() { return m_indices; }
+
+ protected:
+
+ IndicesType m_indices;
+};
+
+namespace internal {
+template<typename _IndicesType>
+struct traits<TranspositionsWrapper<_IndicesType> >
+ : traits<PermutationWrapper<_IndicesType> >
+{
+ typedef TranspositionsStorage StorageKind;
+};
+}
+
+template<typename _IndicesType>
+class TranspositionsWrapper
+ : public TranspositionsBase<TranspositionsWrapper<_IndicesType> >
+{
+ typedef internal::traits<TranspositionsWrapper> Traits;
+ public:
+
+ typedef TranspositionsBase<TranspositionsWrapper> Base;
+ typedef typename Traits::IndicesType IndicesType;
+ typedef typename IndicesType::Scalar StorageIndex;
+
+ explicit inline TranspositionsWrapper(IndicesType& indices)
+ : m_indices(indices)
+ {}
+
+ /** Copies the \a other transpositions into \c *this */
+ template<typename OtherDerived>
+ TranspositionsWrapper& operator=(const TranspositionsBase<OtherDerived>& other)
+ {
+ return Base::operator=(other);
+ }
+
+ /** const version of indices(). */
+ EIGEN_DEVICE_FUNC
+ const IndicesType& indices() const { return m_indices; }
+
+ /** \returns a reference to the stored array representing the transpositions. */
+ EIGEN_DEVICE_FUNC
+ IndicesType& indices() { return m_indices; }
+
+ protected:
+
+ typename IndicesType::Nested m_indices;
+};
+
+
+
+/** \returns the \a matrix with the \a transpositions applied to the columns.
+ */
+template<typename MatrixDerived, typename TranspositionsDerived>
+EIGEN_DEVICE_FUNC
+const Product<MatrixDerived, TranspositionsDerived, AliasFreeProduct>
+operator*(const MatrixBase<MatrixDerived> &matrix,
+ const TranspositionsBase<TranspositionsDerived>& transpositions)
+{
+ return Product<MatrixDerived, TranspositionsDerived, AliasFreeProduct>
+ (matrix.derived(), transpositions.derived());
+}
+
+/** \returns the \a matrix with the \a transpositions applied to the rows.
+ */
+template<typename TranspositionsDerived, typename MatrixDerived>
+EIGEN_DEVICE_FUNC
+const Product<TranspositionsDerived, MatrixDerived, AliasFreeProduct>
+operator*(const TranspositionsBase<TranspositionsDerived> &transpositions,
+ const MatrixBase<MatrixDerived>& matrix)
+{
+ return Product<TranspositionsDerived, MatrixDerived, AliasFreeProduct>
+ (transpositions.derived(), matrix.derived());
+}
+
+// Template partial specialization for transposed/inverse transpositions
+
+namespace internal {
+
+template<typename Derived>
+struct traits<Transpose<TranspositionsBase<Derived> > >
+ : traits<Derived>
+{};
+
+} // end namespace internal
+
+template<typename TranspositionsDerived>
+class Transpose<TranspositionsBase<TranspositionsDerived> >
+{
+ typedef TranspositionsDerived TranspositionType;
+ typedef typename TranspositionType::IndicesType IndicesType;
+ public:
+
+ explicit Transpose(const TranspositionType& t) : m_transpositions(t) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ Index size() const EIGEN_NOEXCEPT { return m_transpositions.size(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ Index rows() const EIGEN_NOEXCEPT { return m_transpositions.size(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ Index cols() const EIGEN_NOEXCEPT { return m_transpositions.size(); }
+
+ /** \returns the \a matrix with the inverse transpositions applied to the columns.
+ */
+ template<typename OtherDerived> friend
+ const Product<OtherDerived, Transpose, AliasFreeProduct>
+ operator*(const MatrixBase<OtherDerived>& matrix, const Transpose& trt)
+ {
+ return Product<OtherDerived, Transpose, AliasFreeProduct>(matrix.derived(), trt);
+ }
+
+ /** \returns the \a matrix with the inverse transpositions applied to the rows.
+ */
+ template<typename OtherDerived>
+ const Product<Transpose, OtherDerived, AliasFreeProduct>
+ operator*(const MatrixBase<OtherDerived>& matrix) const
+ {
+ return Product<Transpose, OtherDerived, AliasFreeProduct>(*this, matrix.derived());
+ }
+
+ EIGEN_DEVICE_FUNC
+ const TranspositionType& nestedExpression() const { return m_transpositions; }
+
+ protected:
+ const TranspositionType& m_transpositions;
+};
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRANSPOSITIONS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/TriangularMatrix.h b/src/3rdparty/eigen/Eigen/src/Core/TriangularMatrix.h
new file mode 100644
index 000000000..fdb8bc15a
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/TriangularMatrix.h
@@ -0,0 +1,1001 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TRIANGULARMATRIX_H
+#define EIGEN_TRIANGULARMATRIX_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<int Side, typename TriangularType, typename Rhs> struct triangular_solve_retval;
+
+}
+
+/** \class TriangularBase
+ * \ingroup Core_Module
+ *
+ * \brief Base class for triangular part in a matrix
+ */
+template<typename Derived> class TriangularBase : public EigenBase<Derived>
+{
+ public:
+
+ enum {
+ Mode = internal::traits<Derived>::Mode,
+ RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
+ ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
+ MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
+
+ SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
+ internal::traits<Derived>::ColsAtCompileTime>::ret),
+ /**< This is equal to the number of coefficients, i.e. the number of
+ * rows times the number of columns, or to \a Dynamic if this is not
+ * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */
+
+ MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
+ internal::traits<Derived>::MaxColsAtCompileTime>::ret)
+
+ };
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+ typedef typename internal::traits<Derived>::StorageKind StorageKind;
+ typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
+ typedef typename internal::traits<Derived>::FullMatrixType DenseMatrixType;
+ typedef DenseMatrixType DenseType;
+ typedef Derived const& Nested;
+
+ EIGEN_DEVICE_FUNC
+ inline TriangularBase() { eigen_assert(!((int(Mode) & int(UnitDiag)) && (int(Mode) & int(ZeroDiag)))); }
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return derived().rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return derived().cols(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index outerStride() const EIGEN_NOEXCEPT { return derived().outerStride(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index innerStride() const EIGEN_NOEXCEPT { return derived().innerStride(); }
+
+ // dummy resize function
+ EIGEN_DEVICE_FUNC
+ void resize(Index rows, Index cols)
+ {
+ EIGEN_UNUSED_VARIABLE(rows);
+ EIGEN_UNUSED_VARIABLE(cols);
+ eigen_assert(rows==this->rows() && cols==this->cols());
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline Scalar coeff(Index row, Index col) const { return derived().coeff(row,col); }
+ EIGEN_DEVICE_FUNC
+ inline Scalar& coeffRef(Index row, Index col) { return derived().coeffRef(row,col); }
+
+ /** \see MatrixBase::copyCoeff(row,col)
+ */
+ template<typename Other>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void copyCoeff(Index row, Index col, Other& other)
+ {
+ derived().coeffRef(row, col) = other.coeff(row, col);
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline Scalar operator()(Index row, Index col) const
+ {
+ check_coordinates(row, col);
+ return coeff(row,col);
+ }
+ EIGEN_DEVICE_FUNC
+ inline Scalar& operator()(Index row, Index col)
+ {
+ check_coordinates(row, col);
+ return coeffRef(row,col);
+ }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ EIGEN_DEVICE_FUNC
+ inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
+ EIGEN_DEVICE_FUNC
+ inline Derived& derived() { return *static_cast<Derived*>(this); }
+ #endif // not EIGEN_PARSED_BY_DOXYGEN
+
+ template<typename DenseDerived>
+ EIGEN_DEVICE_FUNC
+ void evalTo(MatrixBase<DenseDerived> &other) const;
+ template<typename DenseDerived>
+ EIGEN_DEVICE_FUNC
+ void evalToLazy(MatrixBase<DenseDerived> &other) const;
+
+ EIGEN_DEVICE_FUNC
+ DenseMatrixType toDenseMatrix() const
+ {
+ DenseMatrixType res(rows(), cols());
+ evalToLazy(res);
+ return res;
+ }
+
+ protected:
+
+ void check_coordinates(Index row, Index col) const
+ {
+ EIGEN_ONLY_USED_FOR_DEBUG(row);
+ EIGEN_ONLY_USED_FOR_DEBUG(col);
+ eigen_assert(col>=0 && col<cols() && row>=0 && row<rows());
+ const int mode = int(Mode) & ~SelfAdjoint;
+ EIGEN_ONLY_USED_FOR_DEBUG(mode);
+ eigen_assert((mode==Upper && col>=row)
+ || (mode==Lower && col<=row)
+ || ((mode==StrictlyUpper || mode==UnitUpper) && col>row)
+ || ((mode==StrictlyLower || mode==UnitLower) && col<row));
+ }
+
+ #ifdef EIGEN_INTERNAL_DEBUGGING
+ void check_coordinates_internal(Index row, Index col) const
+ {
+ check_coordinates(row, col);
+ }
+ #else
+ void check_coordinates_internal(Index , Index ) const {}
+ #endif
+
+};
+
+/** \class TriangularView
+ * \ingroup Core_Module
+ *
+ * \brief Expression of a triangular part in a matrix
+ *
+ * \param MatrixType the type of the object in which we are taking the triangular part
+ * \param Mode the kind of triangular matrix expression to construct. Can be #Upper,
+ * #Lower, #UnitUpper, #UnitLower, #StrictlyUpper, or #StrictlyLower.
+ * This is in fact a bit field; it must have either #Upper or #Lower,
+ * and additionally it may have #UnitDiag or #ZeroDiag or neither.
+ *
+ * This class represents a triangular part of a matrix, not necessarily square. Strictly speaking, for rectangular
+ * matrices one should speak of "trapezoid" parts. This class is the return type
+ * of MatrixBase::triangularView() and SparseMatrixBase::triangularView(), and most of the time this is the only way it is used.
+ *
+ * \sa MatrixBase::triangularView()
+ */
+namespace internal {
+template<typename MatrixType, unsigned int _Mode>
+struct traits<TriangularView<MatrixType, _Mode> > : traits<MatrixType>
+{
+ typedef typename ref_selector<MatrixType>::non_const_type MatrixTypeNested;
+ typedef typename remove_reference<MatrixTypeNested>::type MatrixTypeNestedNonRef;
+ typedef typename remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned;
+ typedef typename MatrixType::PlainObject FullMatrixType;
+ typedef MatrixType ExpressionType;
+ enum {
+ Mode = _Mode,
+ FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
+ Flags = (MatrixTypeNestedCleaned::Flags & (HereditaryBits | FlagsLvalueBit) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit)))
+ };
+};
+}
+
+template<typename _MatrixType, unsigned int _Mode, typename StorageKind> class TriangularViewImpl;
+
+template<typename _MatrixType, unsigned int _Mode> class TriangularView
+ : public TriangularViewImpl<_MatrixType, _Mode, typename internal::traits<_MatrixType>::StorageKind >
+{
+ public:
+
+ typedef TriangularViewImpl<_MatrixType, _Mode, typename internal::traits<_MatrixType>::StorageKind > Base;
+ typedef typename internal::traits<TriangularView>::Scalar Scalar;
+ typedef _MatrixType MatrixType;
+
+ protected:
+ typedef typename internal::traits<TriangularView>::MatrixTypeNested MatrixTypeNested;
+ typedef typename internal::traits<TriangularView>::MatrixTypeNestedNonRef MatrixTypeNestedNonRef;
+
+ typedef typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type MatrixConjugateReturnType;
+ typedef TriangularView<typename internal::add_const<MatrixType>::type, _Mode> ConstTriangularView;
+
+ public:
+
+ typedef typename internal::traits<TriangularView>::StorageKind StorageKind;
+ typedef typename internal::traits<TriangularView>::MatrixTypeNestedCleaned NestedExpression;
+
+ enum {
+ Mode = _Mode,
+ Flags = internal::traits<TriangularView>::Flags,
+ TransposeMode = (Mode & Upper ? Lower : 0)
+ | (Mode & Lower ? Upper : 0)
+ | (Mode & (UnitDiag))
+ | (Mode & (ZeroDiag)),
+ IsVectorAtCompileTime = false
+ };
+
+ EIGEN_DEVICE_FUNC
+ explicit inline TriangularView(MatrixType& matrix) : m_matrix(matrix)
+ {}
+
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TriangularView)
+
+ /** \copydoc EigenBase::rows() */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
+ /** \copydoc EigenBase::cols() */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
+
+ /** \returns a const reference to the nested expression */
+ EIGEN_DEVICE_FUNC
+ const NestedExpression& nestedExpression() const { return m_matrix; }
+
+ /** \returns a reference to the nested expression */
+ EIGEN_DEVICE_FUNC
+ NestedExpression& nestedExpression() { return m_matrix; }
+
+ typedef TriangularView<const MatrixConjugateReturnType,Mode> ConjugateReturnType;
+ /** \sa MatrixBase::conjugate() const */
+ EIGEN_DEVICE_FUNC
+ inline const ConjugateReturnType conjugate() const
+ { return ConjugateReturnType(m_matrix.conjugate()); }
+
+ /** \returns an expression of the complex conjugate of \c *this if Cond==true,
+ * returns \c *this otherwise.
+ */
+ template<bool Cond>
+ EIGEN_DEVICE_FUNC
+ inline typename internal::conditional<Cond,ConjugateReturnType,ConstTriangularView>::type
+ conjugateIf() const
+ {
+ typedef typename internal::conditional<Cond,ConjugateReturnType,ConstTriangularView>::type ReturnType;
+ return ReturnType(m_matrix.template conjugateIf<Cond>());
+ }
+
+ typedef TriangularView<const typename MatrixType::AdjointReturnType,TransposeMode> AdjointReturnType;
+ /** \sa MatrixBase::adjoint() const */
+ EIGEN_DEVICE_FUNC
+ inline const AdjointReturnType adjoint() const
+ { return AdjointReturnType(m_matrix.adjoint()); }
+
+ typedef TriangularView<typename MatrixType::TransposeReturnType,TransposeMode> TransposeReturnType;
+ /** \sa MatrixBase::transpose() */
+ EIGEN_DEVICE_FUNC
+ inline TransposeReturnType transpose()
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
+ typename MatrixType::TransposeReturnType tmp(m_matrix);
+ return TransposeReturnType(tmp);
+ }
+
+ typedef TriangularView<const typename MatrixType::ConstTransposeReturnType,TransposeMode> ConstTransposeReturnType;
+ /** \sa MatrixBase::transpose() const */
+ EIGEN_DEVICE_FUNC
+ inline const ConstTransposeReturnType transpose() const
+ {
+ return ConstTransposeReturnType(m_matrix.transpose());
+ }
+
+ template<typename Other>
+ EIGEN_DEVICE_FUNC
+ inline const Solve<TriangularView, Other>
+ solve(const MatrixBase<Other>& other) const
+ { return Solve<TriangularView, Other>(*this, other.derived()); }
+
+ // workaround MSVC ICE
+ #if EIGEN_COMP_MSVC
+ template<int Side, typename Other>
+ EIGEN_DEVICE_FUNC
+ inline const internal::triangular_solve_retval<Side,TriangularView, Other>
+ solve(const MatrixBase<Other>& other) const
+ { return Base::template solve<Side>(other); }
+ #else
+ using Base::solve;
+ #endif
+
+ /** \returns a selfadjoint view of the referenced triangular part which must be either \c #Upper or \c #Lower.
+ *
+ * This is a shortcut for \code this->nestedExpression().selfadjointView<(*this)::Mode>() \endcode
+ * \sa MatrixBase::selfadjointView() */
+ EIGEN_DEVICE_FUNC
+ SelfAdjointView<MatrixTypeNestedNonRef,Mode> selfadjointView()
+ {
+ EIGEN_STATIC_ASSERT((Mode&(UnitDiag|ZeroDiag))==0,PROGRAMMING_ERROR);
+ return SelfAdjointView<MatrixTypeNestedNonRef,Mode>(m_matrix);
+ }
+
+ /** This is the const version of selfadjointView() */
+ EIGEN_DEVICE_FUNC
+ const SelfAdjointView<MatrixTypeNestedNonRef,Mode> selfadjointView() const
+ {
+ EIGEN_STATIC_ASSERT((Mode&(UnitDiag|ZeroDiag))==0,PROGRAMMING_ERROR);
+ return SelfAdjointView<MatrixTypeNestedNonRef,Mode>(m_matrix);
+ }
+
+
+ /** \returns the determinant of the triangular matrix
+ * \sa MatrixBase::determinant() */
+ EIGEN_DEVICE_FUNC
+ Scalar determinant() const
+ {
+ if (Mode & UnitDiag)
+ return 1;
+ else if (Mode & ZeroDiag)
+ return 0;
+ else
+ return m_matrix.diagonal().prod();
+ }
+
+ protected:
+
+ MatrixTypeNested m_matrix;
+};
+
+/** \ingroup Core_Module
+ *
+ * \brief Base class for a triangular part in a \b dense matrix
+ *
+ * This class is an abstract base class of class TriangularView, and objects of type TriangularViewImpl cannot be instantiated.
+ * It extends class TriangularView with additional methods which available for dense expressions only.
+ *
+ * \sa class TriangularView, MatrixBase::triangularView()
+ */
+template<typename _MatrixType, unsigned int _Mode> class TriangularViewImpl<_MatrixType,_Mode,Dense>
+ : public TriangularBase<TriangularView<_MatrixType, _Mode> >
+{
+ public:
+
+ typedef TriangularView<_MatrixType, _Mode> TriangularViewType;
+ typedef TriangularBase<TriangularViewType> Base;
+ typedef typename internal::traits<TriangularViewType>::Scalar Scalar;
+
+ typedef _MatrixType MatrixType;
+ typedef typename MatrixType::PlainObject DenseMatrixType;
+ typedef DenseMatrixType PlainObject;
+
+ public:
+ using Base::evalToLazy;
+ using Base::derived;
+
+ typedef typename internal::traits<TriangularViewType>::StorageKind StorageKind;
+
+ enum {
+ Mode = _Mode,
+ Flags = internal::traits<TriangularViewType>::Flags
+ };
+
+ /** \returns the outer-stride of the underlying dense matrix
+ * \sa DenseCoeffsBase::outerStride() */
+ EIGEN_DEVICE_FUNC
+ inline Index outerStride() const { return derived().nestedExpression().outerStride(); }
+ /** \returns the inner-stride of the underlying dense matrix
+ * \sa DenseCoeffsBase::innerStride() */
+ EIGEN_DEVICE_FUNC
+ inline Index innerStride() const { return derived().nestedExpression().innerStride(); }
+
+ /** \sa MatrixBase::operator+=() */
+ template<typename Other>
+ EIGEN_DEVICE_FUNC
+ TriangularViewType& operator+=(const DenseBase<Other>& other) {
+ internal::call_assignment_no_alias(derived(), other.derived(), internal::add_assign_op<Scalar,typename Other::Scalar>());
+ return derived();
+ }
+ /** \sa MatrixBase::operator-=() */
+ template<typename Other>
+ EIGEN_DEVICE_FUNC
+ TriangularViewType& operator-=(const DenseBase<Other>& other) {
+ internal::call_assignment_no_alias(derived(), other.derived(), internal::sub_assign_op<Scalar,typename Other::Scalar>());
+ return derived();
+ }
+
+ /** \sa MatrixBase::operator*=() */
+ EIGEN_DEVICE_FUNC
+ TriangularViewType& operator*=(const typename internal::traits<MatrixType>::Scalar& other) { return *this = derived().nestedExpression() * other; }
+ /** \sa DenseBase::operator/=() */
+ EIGEN_DEVICE_FUNC
+ TriangularViewType& operator/=(const typename internal::traits<MatrixType>::Scalar& other) { return *this = derived().nestedExpression() / other; }
+
+ /** \sa MatrixBase::fill() */
+ EIGEN_DEVICE_FUNC
+ void fill(const Scalar& value) { setConstant(value); }
+ /** \sa MatrixBase::setConstant() */
+ EIGEN_DEVICE_FUNC
+ TriangularViewType& setConstant(const Scalar& value)
+ { return *this = MatrixType::Constant(derived().rows(), derived().cols(), value); }
+ /** \sa MatrixBase::setZero() */
+ EIGEN_DEVICE_FUNC
+ TriangularViewType& setZero() { return setConstant(Scalar(0)); }
+ /** \sa MatrixBase::setOnes() */
+ EIGEN_DEVICE_FUNC
+ TriangularViewType& setOnes() { return setConstant(Scalar(1)); }
+
+ /** \sa MatrixBase::coeff()
+ * \warning the coordinates must fit into the referenced triangular part
+ */
+ EIGEN_DEVICE_FUNC
+ inline Scalar coeff(Index row, Index col) const
+ {
+ Base::check_coordinates_internal(row, col);
+ return derived().nestedExpression().coeff(row, col);
+ }
+
+ /** \sa MatrixBase::coeffRef()
+ * \warning the coordinates must fit into the referenced triangular part
+ */
+ EIGEN_DEVICE_FUNC
+ inline Scalar& coeffRef(Index row, Index col)
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(TriangularViewType);
+ Base::check_coordinates_internal(row, col);
+ return derived().nestedExpression().coeffRef(row, col);
+ }
+
+ /** Assigns a triangular matrix to a triangular part of a dense matrix */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ TriangularViewType& operator=(const TriangularBase<OtherDerived>& other);
+
+ /** Shortcut for\code *this = other.other.triangularView<(*this)::Mode>() \endcode */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ TriangularViewType& operator=(const MatrixBase<OtherDerived>& other);
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ EIGEN_DEVICE_FUNC
+ TriangularViewType& operator=(const TriangularViewImpl& other)
+ { return *this = other.derived().nestedExpression(); }
+
+ template<typename OtherDerived>
+ /** \deprecated */
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC
+ void lazyAssign(const TriangularBase<OtherDerived>& other);
+
+ template<typename OtherDerived>
+ /** \deprecated */
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC
+ void lazyAssign(const MatrixBase<OtherDerived>& other);
+#endif
+
+ /** Efficient triangular matrix times vector/matrix product */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ const Product<TriangularViewType,OtherDerived>
+ operator*(const MatrixBase<OtherDerived>& rhs) const
+ {
+ return Product<TriangularViewType,OtherDerived>(derived(), rhs.derived());
+ }
+
+ /** Efficient vector/matrix times triangular matrix product */
+ template<typename OtherDerived> friend
+ EIGEN_DEVICE_FUNC
+ const Product<OtherDerived,TriangularViewType>
+ operator*(const MatrixBase<OtherDerived>& lhs, const TriangularViewImpl& rhs)
+ {
+ return Product<OtherDerived,TriangularViewType>(lhs.derived(),rhs.derived());
+ }
+
+ /** \returns the product of the inverse of \c *this with \a other, \a *this being triangular.
+ *
+ * This function computes the inverse-matrix matrix product inverse(\c *this) * \a other if
+ * \a Side==OnTheLeft (the default), or the right-inverse-multiply \a other * inverse(\c *this) if
+ * \a Side==OnTheRight.
+ *
+ * Note that the template parameter \c Side can be omitted, in which case \c Side==OnTheLeft
+ *
+ * The matrix \c *this must be triangular and invertible (i.e., all the coefficients of the
+ * diagonal must be non zero). It works as a forward (resp. backward) substitution if \c *this
+ * is an upper (resp. lower) triangular matrix.
+ *
+ * Example: \include Triangular_solve.cpp
+ * Output: \verbinclude Triangular_solve.out
+ *
+ * This function returns an expression of the inverse-multiply and can works in-place if it is assigned
+ * to the same matrix or vector \a other.
+ *
+ * For users coming from BLAS, this function (and more specifically solveInPlace()) offer
+ * all the operations supported by the \c *TRSV and \c *TRSM BLAS routines.
+ *
+ * \sa TriangularView::solveInPlace()
+ */
+ template<int Side, typename Other>
+ inline const internal::triangular_solve_retval<Side,TriangularViewType, Other>
+ solve(const MatrixBase<Other>& other) const;
+
+ /** "in-place" version of TriangularView::solve() where the result is written in \a other
+ *
+ * \warning The parameter is only marked 'const' to make the C++ compiler accept a temporary expression here.
+ * This function will const_cast it, so constness isn't honored here.
+ *
+ * Note that the template parameter \c Side can be omitted, in which case \c Side==OnTheLeft
+ *
+ * See TriangularView:solve() for the details.
+ */
+ template<int Side, typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ void solveInPlace(const MatrixBase<OtherDerived>& other) const;
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ void solveInPlace(const MatrixBase<OtherDerived>& other) const
+ { return solveInPlace<OnTheLeft>(other); }
+
+ /** Swaps the coefficients of the common triangular parts of two matrices */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+#ifdef EIGEN_PARSED_BY_DOXYGEN
+ void swap(TriangularBase<OtherDerived> &other)
+#else
+ void swap(TriangularBase<OtherDerived> const & other)
+#endif
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(OtherDerived);
+ call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>());
+ }
+
+ /** Shortcut for \code (*this).swap(other.triangularView<(*this)::Mode>()) \endcode */
+ template<typename OtherDerived>
+ /** \deprecated */
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC
+ void swap(MatrixBase<OtherDerived> const & other)
+ {
+ EIGEN_STATIC_ASSERT_LVALUE(OtherDerived);
+ call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>());
+ }
+
+ template<typename RhsType, typename DstType>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE void _solve_impl(const RhsType &rhs, DstType &dst) const {
+ if(!internal::is_same_dense(dst,rhs))
+ dst = rhs;
+ this->solveInPlace(dst);
+ }
+
+ template<typename ProductType>
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE TriangularViewType& _assignProduct(const ProductType& prod, const Scalar& alpha, bool beta);
+ protected:
+ EIGEN_DEFAULT_COPY_CONSTRUCTOR(TriangularViewImpl)
+ EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(TriangularViewImpl)
+
+};
+
+/***************************************************************************
+* Implementation of triangular evaluation/assignment
+***************************************************************************/
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+// FIXME should we keep that possibility
+template<typename MatrixType, unsigned int Mode>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC inline TriangularView<MatrixType, Mode>&
+TriangularViewImpl<MatrixType, Mode, Dense>::operator=(const MatrixBase<OtherDerived>& other)
+{
+ internal::call_assignment_no_alias(derived(), other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>());
+ return derived();
+}
+
+// FIXME should we keep that possibility
+template<typename MatrixType, unsigned int Mode>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(const MatrixBase<OtherDerived>& other)
+{
+ internal::call_assignment_no_alias(derived(), other.template triangularView<Mode>());
+}
+
+
+
+template<typename MatrixType, unsigned int Mode>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC inline TriangularView<MatrixType, Mode>&
+TriangularViewImpl<MatrixType, Mode, Dense>::operator=(const TriangularBase<OtherDerived>& other)
+{
+ eigen_assert(Mode == int(OtherDerived::Mode));
+ internal::call_assignment(derived(), other.derived());
+ return derived();
+}
+
+template<typename MatrixType, unsigned int Mode>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(const TriangularBase<OtherDerived>& other)
+{
+ eigen_assert(Mode == int(OtherDerived::Mode));
+ internal::call_assignment_no_alias(derived(), other.derived());
+}
+#endif
+
+/***************************************************************************
+* Implementation of TriangularBase methods
+***************************************************************************/
+
+/** Assigns a triangular or selfadjoint matrix to a dense matrix.
+ * If the matrix is triangular, the opposite part is set to zero. */
+template<typename Derived>
+template<typename DenseDerived>
+EIGEN_DEVICE_FUNC void TriangularBase<Derived>::evalTo(MatrixBase<DenseDerived> &other) const
+{
+ evalToLazy(other.derived());
+}
+
+/***************************************************************************
+* Implementation of TriangularView methods
+***************************************************************************/
+
+/***************************************************************************
+* Implementation of MatrixBase methods
+***************************************************************************/
+
+/**
+ * \returns an expression of a triangular view extracted from the current matrix
+ *
+ * The parameter \a Mode can have the following values: \c #Upper, \c #StrictlyUpper, \c #UnitUpper,
+ * \c #Lower, \c #StrictlyLower, \c #UnitLower.
+ *
+ * Example: \include MatrixBase_triangularView.cpp
+ * Output: \verbinclude MatrixBase_triangularView.out
+ *
+ * \sa class TriangularView
+ */
+template<typename Derived>
+template<unsigned int Mode>
+EIGEN_DEVICE_FUNC
+typename MatrixBase<Derived>::template TriangularViewReturnType<Mode>::Type
+MatrixBase<Derived>::triangularView()
+{
+ return typename TriangularViewReturnType<Mode>::Type(derived());
+}
+
+/** This is the const version of MatrixBase::triangularView() */
+template<typename Derived>
+template<unsigned int Mode>
+EIGEN_DEVICE_FUNC
+typename MatrixBase<Derived>::template ConstTriangularViewReturnType<Mode>::Type
+MatrixBase<Derived>::triangularView() const
+{
+ return typename ConstTriangularViewReturnType<Mode>::Type(derived());
+}
+
+/** \returns true if *this is approximately equal to an upper triangular matrix,
+ * within the precision given by \a prec.
+ *
+ * \sa isLowerTriangular()
+ */
+template<typename Derived>
+bool MatrixBase<Derived>::isUpperTriangular(const RealScalar& prec) const
+{
+ RealScalar maxAbsOnUpperPart = static_cast<RealScalar>(-1);
+ for(Index j = 0; j < cols(); ++j)
+ {
+ Index maxi = numext::mini(j, rows()-1);
+ for(Index i = 0; i <= maxi; ++i)
+ {
+ RealScalar absValue = numext::abs(coeff(i,j));
+ if(absValue > maxAbsOnUpperPart) maxAbsOnUpperPart = absValue;
+ }
+ }
+ RealScalar threshold = maxAbsOnUpperPart * prec;
+ for(Index j = 0; j < cols(); ++j)
+ for(Index i = j+1; i < rows(); ++i)
+ if(numext::abs(coeff(i, j)) > threshold) return false;
+ return true;
+}
+
+/** \returns true if *this is approximately equal to a lower triangular matrix,
+ * within the precision given by \a prec.
+ *
+ * \sa isUpperTriangular()
+ */
+template<typename Derived>
+bool MatrixBase<Derived>::isLowerTriangular(const RealScalar& prec) const
+{
+ RealScalar maxAbsOnLowerPart = static_cast<RealScalar>(-1);
+ for(Index j = 0; j < cols(); ++j)
+ for(Index i = j; i < rows(); ++i)
+ {
+ RealScalar absValue = numext::abs(coeff(i,j));
+ if(absValue > maxAbsOnLowerPart) maxAbsOnLowerPart = absValue;
+ }
+ RealScalar threshold = maxAbsOnLowerPart * prec;
+ for(Index j = 1; j < cols(); ++j)
+ {
+ Index maxi = numext::mini(j, rows()-1);
+ for(Index i = 0; i < maxi; ++i)
+ if(numext::abs(coeff(i, j)) > threshold) return false;
+ }
+ return true;
+}
+
+
+/***************************************************************************
+****************************************************************************
+* Evaluators and Assignment of triangular expressions
+***************************************************************************
+***************************************************************************/
+
+namespace internal {
+
+
+// TODO currently a triangular expression has the form TriangularView<.,.>
+// in the future triangular-ness should be defined by the expression traits
+// such that Transpose<TriangularView<.,.> > is valid. (currently TriangularBase::transpose() is overloaded to make it work)
+template<typename MatrixType, unsigned int Mode>
+struct evaluator_traits<TriangularView<MatrixType,Mode> >
+{
+ typedef typename storage_kind_to_evaluator_kind<typename MatrixType::StorageKind>::Kind Kind;
+ typedef typename glue_shapes<typename evaluator_traits<MatrixType>::Shape, TriangularShape>::type Shape;
+};
+
+template<typename MatrixType, unsigned int Mode>
+struct unary_evaluator<TriangularView<MatrixType,Mode>, IndexBased>
+ : evaluator<typename internal::remove_all<MatrixType>::type>
+{
+ typedef TriangularView<MatrixType,Mode> XprType;
+ typedef evaluator<typename internal::remove_all<MatrixType>::type> Base;
+ EIGEN_DEVICE_FUNC
+ unary_evaluator(const XprType &xpr) : Base(xpr.nestedExpression()) {}
+};
+
+// Additional assignment kinds:
+struct Triangular2Triangular {};
+struct Triangular2Dense {};
+struct Dense2Triangular {};
+
+
+template<typename Kernel, unsigned int Mode, int UnrollCount, bool ClearOpposite> struct triangular_assignment_loop;
+
+
+/** \internal Specialization of the dense assignment kernel for triangular matrices.
+ * The main difference is that the triangular, diagonal, and opposite parts are processed through three different functions.
+ * \tparam UpLo must be either Lower or Upper
+ * \tparam Mode must be either 0, UnitDiag, ZeroDiag, or SelfAdjoint
+ */
+template<int UpLo, int Mode, int SetOpposite, typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor, int Version = Specialized>
+class triangular_dense_assignment_kernel : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version>
+{
+protected:
+ typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version> Base;
+ typedef typename Base::DstXprType DstXprType;
+ typedef typename Base::SrcXprType SrcXprType;
+ using Base::m_dst;
+ using Base::m_src;
+ using Base::m_functor;
+public:
+
+ typedef typename Base::DstEvaluatorType DstEvaluatorType;
+ typedef typename Base::SrcEvaluatorType SrcEvaluatorType;
+ typedef typename Base::Scalar Scalar;
+ typedef typename Base::AssignmentTraits AssignmentTraits;
+
+
+ EIGEN_DEVICE_FUNC triangular_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType& dstExpr)
+ : Base(dst, src, func, dstExpr)
+ {}
+
+#ifdef EIGEN_INTERNAL_DEBUGGING
+ EIGEN_DEVICE_FUNC void assignCoeff(Index row, Index col)
+ {
+ eigen_internal_assert(row!=col);
+ Base::assignCoeff(row,col);
+ }
+#else
+ using Base::assignCoeff;
+#endif
+
+ EIGEN_DEVICE_FUNC void assignDiagonalCoeff(Index id)
+ {
+ if(Mode==UnitDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(id,id), Scalar(1));
+ else if(Mode==ZeroDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(id,id), Scalar(0));
+ else if(Mode==0) Base::assignCoeff(id,id);
+ }
+
+ EIGEN_DEVICE_FUNC void assignOppositeCoeff(Index row, Index col)
+ {
+ eigen_internal_assert(row!=col);
+ if(SetOpposite)
+ m_functor.assignCoeff(m_dst.coeffRef(row,col), Scalar(0));
+ }
+};
+
+template<int Mode, bool SetOpposite, typename DstXprType, typename SrcXprType, typename Functor>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_triangular_assignment_loop(DstXprType& dst, const SrcXprType& src, const Functor &func)
+{
+ typedef evaluator<DstXprType> DstEvaluatorType;
+ typedef evaluator<SrcXprType> SrcEvaluatorType;
+
+ SrcEvaluatorType srcEvaluator(src);
+
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+ DstEvaluatorType dstEvaluator(dst);
+
+ typedef triangular_dense_assignment_kernel< Mode&(Lower|Upper),Mode&(UnitDiag|ZeroDiag|SelfAdjoint),SetOpposite,
+ DstEvaluatorType,SrcEvaluatorType,Functor> Kernel;
+ Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
+
+ enum {
+ unroll = DstXprType::SizeAtCompileTime != Dynamic
+ && SrcEvaluatorType::CoeffReadCost < HugeCost
+ && DstXprType::SizeAtCompileTime * (int(DstEvaluatorType::CoeffReadCost) + int(SrcEvaluatorType::CoeffReadCost)) / 2 <= EIGEN_UNROLLING_LIMIT
+ };
+
+ triangular_assignment_loop<Kernel, Mode, unroll ? int(DstXprType::SizeAtCompileTime) : Dynamic, SetOpposite>::run(kernel);
+}
+
+template<int Mode, bool SetOpposite, typename DstXprType, typename SrcXprType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+void call_triangular_assignment_loop(DstXprType& dst, const SrcXprType& src)
+{
+ call_triangular_assignment_loop<Mode,SetOpposite>(dst, src, internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar>());
+}
+
+template<> struct AssignmentKind<TriangularShape,TriangularShape> { typedef Triangular2Triangular Kind; };
+template<> struct AssignmentKind<DenseShape,TriangularShape> { typedef Triangular2Dense Kind; };
+template<> struct AssignmentKind<TriangularShape,DenseShape> { typedef Dense2Triangular Kind; };
+
+
+template< typename DstXprType, typename SrcXprType, typename Functor>
+struct Assignment<DstXprType, SrcXprType, Functor, Triangular2Triangular>
+{
+ EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const Functor &func)
+ {
+ eigen_assert(int(DstXprType::Mode) == int(SrcXprType::Mode));
+
+ call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src, func);
+ }
+};
+
+template< typename DstXprType, typename SrcXprType, typename Functor>
+struct Assignment<DstXprType, SrcXprType, Functor, Triangular2Dense>
+{
+ EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const Functor &func)
+ {
+ call_triangular_assignment_loop<SrcXprType::Mode, (int(SrcXprType::Mode) & int(SelfAdjoint)) == 0>(dst, src, func);
+ }
+};
+
+template< typename DstXprType, typename SrcXprType, typename Functor>
+struct Assignment<DstXprType, SrcXprType, Functor, Dense2Triangular>
+{
+ EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const Functor &func)
+ {
+ call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src, func);
+ }
+};
+
+
+template<typename Kernel, unsigned int Mode, int UnrollCount, bool SetOpposite>
+struct triangular_assignment_loop
+{
+ // FIXME: this is not very clean, perhaps this information should be provided by the kernel?
+ typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
+ typedef typename DstEvaluatorType::XprType DstXprType;
+
+ enum {
+ col = (UnrollCount-1) / DstXprType::RowsAtCompileTime,
+ row = (UnrollCount-1) % DstXprType::RowsAtCompileTime
+ };
+
+ typedef typename Kernel::Scalar Scalar;
+
+ EIGEN_DEVICE_FUNC
+ static inline void run(Kernel &kernel)
+ {
+ triangular_assignment_loop<Kernel, Mode, UnrollCount-1, SetOpposite>::run(kernel);
+
+ if(row==col)
+ kernel.assignDiagonalCoeff(row);
+ else if( ((Mode&Lower) && row>col) || ((Mode&Upper) && row<col) )
+ kernel.assignCoeff(row,col);
+ else if(SetOpposite)
+ kernel.assignOppositeCoeff(row,col);
+ }
+};
+
+// prevent buggy user code from causing an infinite recursion
+template<typename Kernel, unsigned int Mode, bool SetOpposite>
+struct triangular_assignment_loop<Kernel, Mode, 0, SetOpposite>
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(Kernel &) {}
+};
+
+
+
+// TODO: experiment with a recursive assignment procedure splitting the current
+// triangular part into one rectangular and two triangular parts.
+
+
+template<typename Kernel, unsigned int Mode, bool SetOpposite>
+struct triangular_assignment_loop<Kernel, Mode, Dynamic, SetOpposite>
+{
+ typedef typename Kernel::Scalar Scalar;
+ EIGEN_DEVICE_FUNC
+ static inline void run(Kernel &kernel)
+ {
+ for(Index j = 0; j < kernel.cols(); ++j)
+ {
+ Index maxi = numext::mini(j, kernel.rows());
+ Index i = 0;
+ if (((Mode&Lower) && SetOpposite) || (Mode&Upper))
+ {
+ for(; i < maxi; ++i)
+ if(Mode&Upper) kernel.assignCoeff(i, j);
+ else kernel.assignOppositeCoeff(i, j);
+ }
+ else
+ i = maxi;
+
+ if(i<kernel.rows()) // then i==j
+ kernel.assignDiagonalCoeff(i++);
+
+ if (((Mode&Upper) && SetOpposite) || (Mode&Lower))
+ {
+ for(; i < kernel.rows(); ++i)
+ if(Mode&Lower) kernel.assignCoeff(i, j);
+ else kernel.assignOppositeCoeff(i, j);
+ }
+ }
+ }
+};
+
+} // end namespace internal
+
+/** Assigns a triangular or selfadjoint matrix to a dense matrix.
+ * If the matrix is triangular, the opposite part is set to zero. */
+template<typename Derived>
+template<typename DenseDerived>
+EIGEN_DEVICE_FUNC void TriangularBase<Derived>::evalToLazy(MatrixBase<DenseDerived> &other) const
+{
+ other.derived().resize(this->rows(), this->cols());
+ internal::call_triangular_assignment_loop<Derived::Mode, (int(Derived::Mode) & int(SelfAdjoint)) == 0 /* SetOpposite */>(other.derived(), derived().nestedExpression());
+}
+
+namespace internal {
+
+// Triangular = Product
+template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar>
+struct Assignment<DstXprType, Product<Lhs,Rhs,DefaultProduct>, internal::assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular>
+{
+ typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType;
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,typename SrcXprType::Scalar> &)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+
+ dst._assignProduct(src, Scalar(1), false);
+ }
+};
+
+// Triangular += Product
+template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar>
+struct Assignment<DstXprType, Product<Lhs,Rhs,DefaultProduct>, internal::add_assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular>
+{
+ typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType;
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<Scalar,typename SrcXprType::Scalar> &)
+ {
+ dst._assignProduct(src, Scalar(1), true);
+ }
+};
+
+// Triangular -= Product
+template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar>
+struct Assignment<DstXprType, Product<Lhs,Rhs,DefaultProduct>, internal::sub_assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular>
+{
+ typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType;
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<Scalar,typename SrcXprType::Scalar> &)
+ {
+ dst._assignProduct(src, Scalar(-1), true);
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRIANGULARMATRIX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/VectorBlock.h b/src/3rdparty/eigen/Eigen/src/Core/VectorBlock.h
new file mode 100644
index 000000000..71c5b95ee
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/VectorBlock.h
@@ -0,0 +1,96 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_VECTORBLOCK_H
+#define EIGEN_VECTORBLOCK_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename VectorType, int Size>
+struct traits<VectorBlock<VectorType, Size> >
+ : public traits<Block<VectorType,
+ traits<VectorType>::Flags & RowMajorBit ? 1 : Size,
+ traits<VectorType>::Flags & RowMajorBit ? Size : 1> >
+{
+};
+}
+
+/** \class VectorBlock
+ * \ingroup Core_Module
+ *
+ * \brief Expression of a fixed-size or dynamic-size sub-vector
+ *
+ * \tparam VectorType the type of the object in which we are taking a sub-vector
+ * \tparam Size size of the sub-vector we are taking at compile time (optional)
+ *
+ * This class represents an expression of either a fixed-size or dynamic-size sub-vector.
+ * It is the return type of DenseBase::segment(Index,Index) and DenseBase::segment<int>(Index) and
+ * most of the time this is the only way it is used.
+ *
+ * However, if you want to directly manipulate sub-vector expressions,
+ * for instance if you want to write a function returning such an expression, you
+ * will need to use this class.
+ *
+ * Here is an example illustrating the dynamic case:
+ * \include class_VectorBlock.cpp
+ * Output: \verbinclude class_VectorBlock.out
+ *
+ * \note Even though this expression has dynamic size, in the case where \a VectorType
+ * has fixed size, this expression inherits a fixed maximal size which means that evaluating
+ * it does not cause a dynamic memory allocation.
+ *
+ * Here is an example illustrating the fixed-size case:
+ * \include class_FixedVectorBlock.cpp
+ * Output: \verbinclude class_FixedVectorBlock.out
+ *
+ * \sa class Block, DenseBase::segment(Index,Index,Index,Index), DenseBase::segment(Index,Index)
+ */
+template<typename VectorType, int Size> class VectorBlock
+ : public Block<VectorType,
+ internal::traits<VectorType>::Flags & RowMajorBit ? 1 : Size,
+ internal::traits<VectorType>::Flags & RowMajorBit ? Size : 1>
+{
+ typedef Block<VectorType,
+ internal::traits<VectorType>::Flags & RowMajorBit ? 1 : Size,
+ internal::traits<VectorType>::Flags & RowMajorBit ? Size : 1> Base;
+ enum {
+ IsColVector = !(internal::traits<VectorType>::Flags & RowMajorBit)
+ };
+ public:
+ EIGEN_DENSE_PUBLIC_INTERFACE(VectorBlock)
+
+ using Base::operator=;
+
+ /** Dynamic-size constructor
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ VectorBlock(VectorType& vector, Index start, Index size)
+ : Base(vector,
+ IsColVector ? start : 0, IsColVector ? 0 : start,
+ IsColVector ? size : 1, IsColVector ? 1 : size)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorBlock);
+ }
+
+ /** Fixed-size constructor
+ */
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ VectorBlock(VectorType& vector, Index start)
+ : Base(vector, IsColVector ? start : 0, IsColVector ? 0 : start)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorBlock);
+ }
+};
+
+
+} // end namespace Eigen
+
+#endif // EIGEN_VECTORBLOCK_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/VectorwiseOp.h b/src/3rdparty/eigen/Eigen/src/Core/VectorwiseOp.h
new file mode 100644
index 000000000..870f4f1e4
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/VectorwiseOp.h
@@ -0,0 +1,784 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2019 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PARTIAL_REDUX_H
+#define EIGEN_PARTIAL_REDUX_H
+
+namespace Eigen {
+
+/** \class PartialReduxExpr
+ * \ingroup Core_Module
+ *
+ * \brief Generic expression of a partially reduxed matrix
+ *
+ * \tparam MatrixType the type of the matrix we are applying the redux operation
+ * \tparam MemberOp type of the member functor
+ * \tparam Direction indicates the direction of the redux (#Vertical or #Horizontal)
+ *
+ * This class represents an expression of a partial redux operator of a matrix.
+ * It is the return type of some VectorwiseOp functions,
+ * and most of the time this is the only way it is used.
+ *
+ * \sa class VectorwiseOp
+ */
+
+template< typename MatrixType, typename MemberOp, int Direction>
+class PartialReduxExpr;
+
+namespace internal {
+template<typename MatrixType, typename MemberOp, int Direction>
+struct traits<PartialReduxExpr<MatrixType, MemberOp, Direction> >
+ : traits<MatrixType>
+{
+ typedef typename MemberOp::result_type Scalar;
+ typedef typename traits<MatrixType>::StorageKind StorageKind;
+ typedef typename traits<MatrixType>::XprKind XprKind;
+ typedef typename MatrixType::Scalar InputScalar;
+ enum {
+ RowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::ColsAtCompileTime,
+ MaxRowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime,
+ Flags = RowsAtCompileTime == 1 ? RowMajorBit : 0,
+ TraversalSize = Direction==Vertical ? MatrixType::RowsAtCompileTime : MatrixType::ColsAtCompileTime
+ };
+};
+}
+
+template< typename MatrixType, typename MemberOp, int Direction>
+class PartialReduxExpr : public internal::dense_xpr_base< PartialReduxExpr<MatrixType, MemberOp, Direction> >::type,
+ internal::no_assignment_operator
+{
+ public:
+
+ typedef typename internal::dense_xpr_base<PartialReduxExpr>::type Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(PartialReduxExpr)
+
+ EIGEN_DEVICE_FUNC
+ explicit PartialReduxExpr(const MatrixType& mat, const MemberOp& func = MemberOp())
+ : m_matrix(mat), m_functor(func) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ Index rows() const EIGEN_NOEXCEPT { return (Direction==Vertical ? 1 : m_matrix.rows()); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ Index cols() const EIGEN_NOEXCEPT { return (Direction==Horizontal ? 1 : m_matrix.cols()); }
+
+ EIGEN_DEVICE_FUNC
+ typename MatrixType::Nested nestedExpression() const { return m_matrix; }
+
+ EIGEN_DEVICE_FUNC
+ const MemberOp& functor() const { return m_functor; }
+
+ protected:
+ typename MatrixType::Nested m_matrix;
+ const MemberOp m_functor;
+};
+
+template<typename A,typename B> struct partial_redux_dummy_func;
+
+#define EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(MEMBER,COST,VECTORIZABLE,BINARYOP) \
+ template <typename ResultType,typename Scalar> \
+ struct member_##MEMBER { \
+ EIGEN_EMPTY_STRUCT_CTOR(member_##MEMBER) \
+ typedef ResultType result_type; \
+ typedef BINARYOP<Scalar,Scalar> BinaryOp; \
+ template<int Size> struct Cost { enum { value = COST }; }; \
+ enum { Vectorizable = VECTORIZABLE }; \
+ template<typename XprType> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+ ResultType operator()(const XprType& mat) const \
+ { return mat.MEMBER(); } \
+ BinaryOp binaryFunc() const { return BinaryOp(); } \
+ }
+
+#define EIGEN_MEMBER_FUNCTOR(MEMBER,COST) \
+ EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(MEMBER,COST,0,partial_redux_dummy_func)
+
+namespace internal {
+
+EIGEN_MEMBER_FUNCTOR(norm, (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost);
+EIGEN_MEMBER_FUNCTOR(stableNorm, (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost);
+EIGEN_MEMBER_FUNCTOR(blueNorm, (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost);
+EIGEN_MEMBER_FUNCTOR(hypotNorm, (Size-1) * functor_traits<scalar_hypot_op<Scalar> >::Cost );
+EIGEN_MEMBER_FUNCTOR(all, (Size-1)*NumTraits<Scalar>::AddCost);
+EIGEN_MEMBER_FUNCTOR(any, (Size-1)*NumTraits<Scalar>::AddCost);
+EIGEN_MEMBER_FUNCTOR(count, (Size-1)*NumTraits<Scalar>::AddCost);
+
+EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(sum, (Size-1)*NumTraits<Scalar>::AddCost, 1, internal::scalar_sum_op);
+EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(minCoeff, (Size-1)*NumTraits<Scalar>::AddCost, 1, internal::scalar_min_op);
+EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(maxCoeff, (Size-1)*NumTraits<Scalar>::AddCost, 1, internal::scalar_max_op);
+EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(prod, (Size-1)*NumTraits<Scalar>::MulCost, 1, internal::scalar_product_op);
+
+template <int p, typename ResultType,typename Scalar>
+struct member_lpnorm {
+ typedef ResultType result_type;
+ enum { Vectorizable = 0 };
+ template<int Size> struct Cost
+ { enum { value = (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost }; };
+ EIGEN_DEVICE_FUNC member_lpnorm() {}
+ template<typename XprType>
+ EIGEN_DEVICE_FUNC inline ResultType operator()(const XprType& mat) const
+ { return mat.template lpNorm<p>(); }
+};
+
+template <typename BinaryOpT, typename Scalar>
+struct member_redux {
+ typedef BinaryOpT BinaryOp;
+ typedef typename result_of<
+ BinaryOp(const Scalar&,const Scalar&)
+ >::type result_type;
+
+ enum { Vectorizable = functor_traits<BinaryOp>::PacketAccess };
+ template<int Size> struct Cost { enum { value = (Size-1) * functor_traits<BinaryOp>::Cost }; };
+ EIGEN_DEVICE_FUNC explicit member_redux(const BinaryOp func) : m_functor(func) {}
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline result_type operator()(const DenseBase<Derived>& mat) const
+ { return mat.redux(m_functor); }
+ const BinaryOp& binaryFunc() const { return m_functor; }
+ const BinaryOp m_functor;
+};
+}
+
+/** \class VectorwiseOp
+ * \ingroup Core_Module
+ *
+ * \brief Pseudo expression providing broadcasting and partial reduction operations
+ *
+ * \tparam ExpressionType the type of the object on which to do partial reductions
+ * \tparam Direction indicates whether to operate on columns (#Vertical) or rows (#Horizontal)
+ *
+ * This class represents a pseudo expression with broadcasting and partial reduction features.
+ * It is the return type of DenseBase::colwise() and DenseBase::rowwise()
+ * and most of the time this is the only way it is explicitly used.
+ *
+ * To understand the logic of rowwise/colwise expression, let's consider a generic case `A.colwise().foo()`
+ * where `foo` is any method of `VectorwiseOp`. This expression is equivalent to applying `foo()` to each
+ * column of `A` and then re-assemble the outputs in a matrix expression:
+ * \code [A.col(0).foo(), A.col(1).foo(), ..., A.col(A.cols()-1).foo()] \endcode
+ *
+ * Example: \include MatrixBase_colwise.cpp
+ * Output: \verbinclude MatrixBase_colwise.out
+ *
+ * The begin() and end() methods are obviously exceptions to the previous rule as they
+ * return STL-compatible begin/end iterators to the rows or columns of the nested expression.
+ * Typical use cases include for-range-loop and calls to STL algorithms:
+ *
+ * Example: \include MatrixBase_colwise_iterator_cxx11.cpp
+ * Output: \verbinclude MatrixBase_colwise_iterator_cxx11.out
+ *
+ * For a partial reduction on an empty input, some rules apply.
+ * For the sake of clarity, let's consider a vertical reduction:
+ * - If the number of columns is zero, then a 1x0 row-major vector expression is returned.
+ * - Otherwise, if the number of rows is zero, then
+ * - a row vector of zeros is returned for sum-like reductions (sum, squaredNorm, norm, etc.)
+ * - a row vector of ones is returned for a product reduction (e.g., <code>MatrixXd(n,0).colwise().prod()</code>)
+ * - an assert is triggered for all other reductions (minCoeff,maxCoeff,redux(bin_op))
+ *
+ * \sa DenseBase::colwise(), DenseBase::rowwise(), class PartialReduxExpr
+ */
+template<typename ExpressionType, int Direction> class VectorwiseOp
+{
+ public:
+
+ typedef typename ExpressionType::Scalar Scalar;
+ typedef typename ExpressionType::RealScalar RealScalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+ typedef typename internal::ref_selector<ExpressionType>::non_const_type ExpressionTypeNested;
+ typedef typename internal::remove_all<ExpressionTypeNested>::type ExpressionTypeNestedCleaned;
+
+ template<template<typename OutScalar,typename InputScalar> class Functor,
+ typename ReturnScalar=Scalar> struct ReturnType
+ {
+ typedef PartialReduxExpr<ExpressionType,
+ Functor<ReturnScalar,Scalar>,
+ Direction
+ > Type;
+ };
+
+ template<typename BinaryOp> struct ReduxReturnType
+ {
+ typedef PartialReduxExpr<ExpressionType,
+ internal::member_redux<BinaryOp,Scalar>,
+ Direction
+ > Type;
+ };
+
+ enum {
+ isVertical = (Direction==Vertical) ? 1 : 0,
+ isHorizontal = (Direction==Horizontal) ? 1 : 0
+ };
+
+ protected:
+
+ template<typename OtherDerived> struct ExtendedType {
+ typedef Replicate<OtherDerived,
+ isVertical ? 1 : ExpressionType::RowsAtCompileTime,
+ isHorizontal ? 1 : ExpressionType::ColsAtCompileTime> Type;
+ };
+
+ /** \internal
+ * Replicates a vector to match the size of \c *this */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ typename ExtendedType<OtherDerived>::Type
+ extendedTo(const DenseBase<OtherDerived>& other) const
+ {
+ EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isVertical, OtherDerived::MaxColsAtCompileTime==1),
+ YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
+ EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isHorizontal, OtherDerived::MaxRowsAtCompileTime==1),
+ YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
+ return typename ExtendedType<OtherDerived>::Type
+ (other.derived(),
+ isVertical ? 1 : m_matrix.rows(),
+ isHorizontal ? 1 : m_matrix.cols());
+ }
+
+ template<typename OtherDerived> struct OppositeExtendedType {
+ typedef Replicate<OtherDerived,
+ isHorizontal ? 1 : ExpressionType::RowsAtCompileTime,
+ isVertical ? 1 : ExpressionType::ColsAtCompileTime> Type;
+ };
+
+ /** \internal
+ * Replicates a vector in the opposite direction to match the size of \c *this */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ typename OppositeExtendedType<OtherDerived>::Type
+ extendedToOpposite(const DenseBase<OtherDerived>& other) const
+ {
+ EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isHorizontal, OtherDerived::MaxColsAtCompileTime==1),
+ YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
+ EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isVertical, OtherDerived::MaxRowsAtCompileTime==1),
+ YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
+ return typename OppositeExtendedType<OtherDerived>::Type
+ (other.derived(),
+ isHorizontal ? 1 : m_matrix.rows(),
+ isVertical ? 1 : m_matrix.cols());
+ }
+
+ public:
+ EIGEN_DEVICE_FUNC
+ explicit inline VectorwiseOp(ExpressionType& matrix) : m_matrix(matrix) {}
+
+ /** \internal */
+ EIGEN_DEVICE_FUNC
+ inline const ExpressionType& _expression() const { return m_matrix; }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** STL-like <a href="https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator">RandomAccessIterator</a>
+ * iterator type over the columns or rows as returned by the begin() and end() methods.
+ */
+ random_access_iterator_type iterator;
+ /** This is the const version of iterator (aka read-only) */
+ random_access_iterator_type const_iterator;
+ #else
+ typedef internal::subvector_stl_iterator<ExpressionType, DirectionType(Direction)> iterator;
+ typedef internal::subvector_stl_iterator<const ExpressionType, DirectionType(Direction)> const_iterator;
+ typedef internal::subvector_stl_reverse_iterator<ExpressionType, DirectionType(Direction)> reverse_iterator;
+ typedef internal::subvector_stl_reverse_iterator<const ExpressionType, DirectionType(Direction)> const_reverse_iterator;
+ #endif
+
+ /** returns an iterator to the first row (rowwise) or column (colwise) of the nested expression.
+ * \sa end(), cbegin()
+ */
+ iterator begin() { return iterator (m_matrix, 0); }
+ /** const version of begin() */
+ const_iterator begin() const { return const_iterator(m_matrix, 0); }
+ /** const version of begin() */
+ const_iterator cbegin() const { return const_iterator(m_matrix, 0); }
+
+ /** returns a reverse iterator to the last row (rowwise) or column (colwise) of the nested expression.
+ * \sa rend(), crbegin()
+ */
+ reverse_iterator rbegin() { return reverse_iterator (m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()-1); }
+ /** const version of rbegin() */
+ const_reverse_iterator rbegin() const { return const_reverse_iterator (m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()-1); }
+ /** const version of rbegin() */
+ const_reverse_iterator crbegin() const { return const_reverse_iterator (m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()-1); }
+
+ /** returns an iterator to the row (resp. column) following the last row (resp. column) of the nested expression
+ * \sa begin(), cend()
+ */
+ iterator end() { return iterator (m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()); }
+ /** const version of end() */
+ const_iterator end() const { return const_iterator(m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()); }
+ /** const version of end() */
+ const_iterator cend() const { return const_iterator(m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()); }
+
+ /** returns a reverse iterator to the row (resp. column) before the first row (resp. column) of the nested expression
+ * \sa begin(), cend()
+ */
+ reverse_iterator rend() { return reverse_iterator (m_matrix, -1); }
+ /** const version of rend() */
+ const_reverse_iterator rend() const { return const_reverse_iterator (m_matrix, -1); }
+ /** const version of rend() */
+ const_reverse_iterator crend() const { return const_reverse_iterator (m_matrix, -1); }
+
+ /** \returns a row or column vector expression of \c *this reduxed by \a func
+ *
+ * The template parameter \a BinaryOp is the type of the functor
+ * of the custom redux operator. Note that func must be an associative operator.
+ *
+ * \warning the size along the reduction direction must be strictly positive,
+ * otherwise an assertion is triggered.
+ *
+ * \sa class VectorwiseOp, DenseBase::colwise(), DenseBase::rowwise()
+ */
+ template<typename BinaryOp>
+ EIGEN_DEVICE_FUNC
+ const typename ReduxReturnType<BinaryOp>::Type
+ redux(const BinaryOp& func = BinaryOp()) const
+ {
+ eigen_assert(redux_length()>0 && "you are using an empty matrix");
+ return typename ReduxReturnType<BinaryOp>::Type(_expression(), internal::member_redux<BinaryOp,Scalar>(func));
+ }
+
+ typedef typename ReturnType<internal::member_minCoeff>::Type MinCoeffReturnType;
+ typedef typename ReturnType<internal::member_maxCoeff>::Type MaxCoeffReturnType;
+ typedef PartialReduxExpr<const CwiseUnaryOp<internal::scalar_abs2_op<Scalar>, const ExpressionTypeNestedCleaned>,internal::member_sum<RealScalar,RealScalar>,Direction> SquaredNormReturnType;
+ typedef CwiseUnaryOp<internal::scalar_sqrt_op<RealScalar>, const SquaredNormReturnType> NormReturnType;
+ typedef typename ReturnType<internal::member_blueNorm,RealScalar>::Type BlueNormReturnType;
+ typedef typename ReturnType<internal::member_stableNorm,RealScalar>::Type StableNormReturnType;
+ typedef typename ReturnType<internal::member_hypotNorm,RealScalar>::Type HypotNormReturnType;
+ typedef typename ReturnType<internal::member_sum>::Type SumReturnType;
+ typedef EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(SumReturnType,Scalar,quotient) MeanReturnType;
+ typedef typename ReturnType<internal::member_all>::Type AllReturnType;
+ typedef typename ReturnType<internal::member_any>::Type AnyReturnType;
+ typedef PartialReduxExpr<ExpressionType, internal::member_count<Index,Scalar>, Direction> CountReturnType;
+ typedef typename ReturnType<internal::member_prod>::Type ProdReturnType;
+ typedef Reverse<const ExpressionType, Direction> ConstReverseReturnType;
+ typedef Reverse<ExpressionType, Direction> ReverseReturnType;
+
+ template<int p> struct LpNormReturnType {
+ typedef PartialReduxExpr<ExpressionType, internal::member_lpnorm<p,RealScalar,Scalar>,Direction> Type;
+ };
+
+ /** \returns a row (or column) vector expression of the smallest coefficient
+ * of each column (or row) of the referenced expression.
+ *
+ * \warning the size along the reduction direction must be strictly positive,
+ * otherwise an assertion is triggered.
+ *
+ * \warning the result is undefined if \c *this contains NaN.
+ *
+ * Example: \include PartialRedux_minCoeff.cpp
+ * Output: \verbinclude PartialRedux_minCoeff.out
+ *
+ * \sa DenseBase::minCoeff() */
+ EIGEN_DEVICE_FUNC
+ const MinCoeffReturnType minCoeff() const
+ {
+ eigen_assert(redux_length()>0 && "you are using an empty matrix");
+ return MinCoeffReturnType(_expression());
+ }
+
+ /** \returns a row (or column) vector expression of the largest coefficient
+ * of each column (or row) of the referenced expression.
+ *
+ * \warning the size along the reduction direction must be strictly positive,
+ * otherwise an assertion is triggered.
+ *
+ * \warning the result is undefined if \c *this contains NaN.
+ *
+ * Example: \include PartialRedux_maxCoeff.cpp
+ * Output: \verbinclude PartialRedux_maxCoeff.out
+ *
+ * \sa DenseBase::maxCoeff() */
+ EIGEN_DEVICE_FUNC
+ const MaxCoeffReturnType maxCoeff() const
+ {
+ eigen_assert(redux_length()>0 && "you are using an empty matrix");
+ return MaxCoeffReturnType(_expression());
+ }
+
+ /** \returns a row (or column) vector expression of the squared norm
+ * of each column (or row) of the referenced expression.
+ * This is a vector with real entries, even if the original matrix has complex entries.
+ *
+ * Example: \include PartialRedux_squaredNorm.cpp
+ * Output: \verbinclude PartialRedux_squaredNorm.out
+ *
+ * \sa DenseBase::squaredNorm() */
+ EIGEN_DEVICE_FUNC
+ const SquaredNormReturnType squaredNorm() const
+ { return SquaredNormReturnType(m_matrix.cwiseAbs2()); }
+
+ /** \returns a row (or column) vector expression of the norm
+ * of each column (or row) of the referenced expression.
+ * This is a vector with real entries, even if the original matrix has complex entries.
+ *
+ * Example: \include PartialRedux_norm.cpp
+ * Output: \verbinclude PartialRedux_norm.out
+ *
+ * \sa DenseBase::norm() */
+ EIGEN_DEVICE_FUNC
+ const NormReturnType norm() const
+ { return NormReturnType(squaredNorm()); }
+
+ /** \returns a row (or column) vector expression of the norm
+ * of each column (or row) of the referenced expression.
+ * This is a vector with real entries, even if the original matrix has complex entries.
+ *
+ * Example: \include PartialRedux_norm.cpp
+ * Output: \verbinclude PartialRedux_norm.out
+ *
+ * \sa DenseBase::norm() */
+ template<int p>
+ EIGEN_DEVICE_FUNC
+ const typename LpNormReturnType<p>::Type lpNorm() const
+ { return typename LpNormReturnType<p>::Type(_expression()); }
+
+
+ /** \returns a row (or column) vector expression of the norm
+ * of each column (or row) of the referenced expression, using
+ * Blue's algorithm.
+ * This is a vector with real entries, even if the original matrix has complex entries.
+ *
+ * \sa DenseBase::blueNorm() */
+ EIGEN_DEVICE_FUNC
+ const BlueNormReturnType blueNorm() const
+ { return BlueNormReturnType(_expression()); }
+
+
+ /** \returns a row (or column) vector expression of the norm
+ * of each column (or row) of the referenced expression, avoiding
+ * underflow and overflow.
+ * This is a vector with real entries, even if the original matrix has complex entries.
+ *
+ * \sa DenseBase::stableNorm() */
+ EIGEN_DEVICE_FUNC
+ const StableNormReturnType stableNorm() const
+ { return StableNormReturnType(_expression()); }
+
+
+ /** \returns a row (or column) vector expression of the norm
+ * of each column (or row) of the referenced expression, avoiding
+ * underflow and overflow using a concatenation of hypot() calls.
+ * This is a vector with real entries, even if the original matrix has complex entries.
+ *
+ * \sa DenseBase::hypotNorm() */
+ EIGEN_DEVICE_FUNC
+ const HypotNormReturnType hypotNorm() const
+ { return HypotNormReturnType(_expression()); }
+
+ /** \returns a row (or column) vector expression of the sum
+ * of each column (or row) of the referenced expression.
+ *
+ * Example: \include PartialRedux_sum.cpp
+ * Output: \verbinclude PartialRedux_sum.out
+ *
+ * \sa DenseBase::sum() */
+ EIGEN_DEVICE_FUNC
+ const SumReturnType sum() const
+ { return SumReturnType(_expression()); }
+
+ /** \returns a row (or column) vector expression of the mean
+ * of each column (or row) of the referenced expression.
+ *
+ * \sa DenseBase::mean() */
+ EIGEN_DEVICE_FUNC
+ const MeanReturnType mean() const
+ { return sum() / Scalar(Direction==Vertical?m_matrix.rows():m_matrix.cols()); }
+
+ /** \returns a row (or column) vector expression representing
+ * whether \b all coefficients of each respective column (or row) are \c true.
+ * This expression can be assigned to a vector with entries of type \c bool.
+ *
+ * \sa DenseBase::all() */
+ EIGEN_DEVICE_FUNC
+ const AllReturnType all() const
+ { return AllReturnType(_expression()); }
+
+ /** \returns a row (or column) vector expression representing
+ * whether \b at \b least one coefficient of each respective column (or row) is \c true.
+ * This expression can be assigned to a vector with entries of type \c bool.
+ *
+ * \sa DenseBase::any() */
+ EIGEN_DEVICE_FUNC
+ const AnyReturnType any() const
+ { return AnyReturnType(_expression()); }
+
+ /** \returns a row (or column) vector expression representing
+ * the number of \c true coefficients of each respective column (or row).
+ * This expression can be assigned to a vector whose entries have the same type as is used to
+ * index entries of the original matrix; for dense matrices, this is \c std::ptrdiff_t .
+ *
+ * Example: \include PartialRedux_count.cpp
+ * Output: \verbinclude PartialRedux_count.out
+ *
+ * \sa DenseBase::count() */
+ EIGEN_DEVICE_FUNC
+ const CountReturnType count() const
+ { return CountReturnType(_expression()); }
+
+ /** \returns a row (or column) vector expression of the product
+ * of each column (or row) of the referenced expression.
+ *
+ * Example: \include PartialRedux_prod.cpp
+ * Output: \verbinclude PartialRedux_prod.out
+ *
+ * \sa DenseBase::prod() */
+ EIGEN_DEVICE_FUNC
+ const ProdReturnType prod() const
+ { return ProdReturnType(_expression()); }
+
+
+ /** \returns a matrix expression
+ * where each column (or row) are reversed.
+ *
+ * Example: \include Vectorwise_reverse.cpp
+ * Output: \verbinclude Vectorwise_reverse.out
+ *
+ * \sa DenseBase::reverse() */
+ EIGEN_DEVICE_FUNC
+ const ConstReverseReturnType reverse() const
+ { return ConstReverseReturnType( _expression() ); }
+
+ /** \returns a writable matrix expression
+ * where each column (or row) are reversed.
+ *
+ * \sa reverse() const */
+ EIGEN_DEVICE_FUNC
+ ReverseReturnType reverse()
+ { return ReverseReturnType( _expression() ); }
+
+ typedef Replicate<ExpressionType,(isVertical?Dynamic:1),(isHorizontal?Dynamic:1)> ReplicateReturnType;
+ EIGEN_DEVICE_FUNC
+ const ReplicateReturnType replicate(Index factor) const;
+
+ /**
+ * \return an expression of the replication of each column (or row) of \c *this
+ *
+ * Example: \include DirectionWise_replicate.cpp
+ * Output: \verbinclude DirectionWise_replicate.out
+ *
+ * \sa VectorwiseOp::replicate(Index), DenseBase::replicate(), class Replicate
+ */
+ // NOTE implemented here because of sunstudio's compilation errors
+ // isVertical*Factor+isHorizontal instead of (isVertical?Factor:1) to handle CUDA bug with ternary operator
+ template<int Factor> const Replicate<ExpressionType,isVertical*Factor+isHorizontal,isHorizontal*Factor+isVertical>
+ EIGEN_DEVICE_FUNC
+ replicate(Index factor = Factor) const
+ {
+ return Replicate<ExpressionType,(isVertical?Factor:1),(isHorizontal?Factor:1)>
+ (_expression(),isVertical?factor:1,isHorizontal?factor:1);
+ }
+
+/////////// Artithmetic operators ///////////
+
+ /** Copies the vector \a other to each subvector of \c *this */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ ExpressionType& operator=(const DenseBase<OtherDerived>& other)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
+ EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
+ //eigen_assert((m_matrix.isNull()) == (other.isNull())); FIXME
+ return m_matrix = extendedTo(other.derived());
+ }
+
+ /** Adds the vector \a other to each subvector of \c *this */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ ExpressionType& operator+=(const DenseBase<OtherDerived>& other)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
+ EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
+ return m_matrix += extendedTo(other.derived());
+ }
+
+ /** Substracts the vector \a other to each subvector of \c *this */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ ExpressionType& operator-=(const DenseBase<OtherDerived>& other)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
+ EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
+ return m_matrix -= extendedTo(other.derived());
+ }
+
+ /** Multiples each subvector of \c *this by the vector \a other */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ ExpressionType& operator*=(const DenseBase<OtherDerived>& other)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
+ EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
+ EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
+ m_matrix *= extendedTo(other.derived());
+ return m_matrix;
+ }
+
+ /** Divides each subvector of \c *this by the vector \a other */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ ExpressionType& operator/=(const DenseBase<OtherDerived>& other)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
+ EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
+ EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
+ m_matrix /= extendedTo(other.derived());
+ return m_matrix;
+ }
+
+ /** Returns the expression of the sum of the vector \a other to each subvector of \c *this */
+ template<typename OtherDerived> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+ CwiseBinaryOp<internal::scalar_sum_op<Scalar,typename OtherDerived::Scalar>,
+ const ExpressionTypeNestedCleaned,
+ const typename ExtendedType<OtherDerived>::Type>
+ operator+(const DenseBase<OtherDerived>& other) const
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
+ EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
+ return m_matrix + extendedTo(other.derived());
+ }
+
+ /** Returns the expression of the difference between each subvector of \c *this and the vector \a other */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ CwiseBinaryOp<internal::scalar_difference_op<Scalar,typename OtherDerived::Scalar>,
+ const ExpressionTypeNestedCleaned,
+ const typename ExtendedType<OtherDerived>::Type>
+ operator-(const DenseBase<OtherDerived>& other) const
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
+ EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
+ return m_matrix - extendedTo(other.derived());
+ }
+
+ /** Returns the expression where each subvector is the product of the vector \a other
+ * by the corresponding subvector of \c *this */
+ template<typename OtherDerived> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+ CwiseBinaryOp<internal::scalar_product_op<Scalar>,
+ const ExpressionTypeNestedCleaned,
+ const typename ExtendedType<OtherDerived>::Type>
+ EIGEN_DEVICE_FUNC
+ operator*(const DenseBase<OtherDerived>& other) const
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
+ EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
+ EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
+ return m_matrix * extendedTo(other.derived());
+ }
+
+ /** Returns the expression where each subvector is the quotient of the corresponding
+ * subvector of \c *this by the vector \a other */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ CwiseBinaryOp<internal::scalar_quotient_op<Scalar>,
+ const ExpressionTypeNestedCleaned,
+ const typename ExtendedType<OtherDerived>::Type>
+ operator/(const DenseBase<OtherDerived>& other) const
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
+ EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
+ EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
+ return m_matrix / extendedTo(other.derived());
+ }
+
+ /** \returns an expression where each column (or row) of the referenced matrix are normalized.
+ * The referenced matrix is \b not modified.
+ * \sa MatrixBase::normalized(), normalize()
+ */
+ EIGEN_DEVICE_FUNC
+ CwiseBinaryOp<internal::scalar_quotient_op<Scalar>,
+ const ExpressionTypeNestedCleaned,
+ const typename OppositeExtendedType<NormReturnType>::Type>
+ normalized() const { return m_matrix.cwiseQuotient(extendedToOpposite(this->norm())); }
+
+
+ /** Normalize in-place each row or columns of the referenced matrix.
+ * \sa MatrixBase::normalize(), normalized()
+ */
+ EIGEN_DEVICE_FUNC void normalize() {
+ m_matrix = this->normalized();
+ }
+
+ EIGEN_DEVICE_FUNC inline void reverseInPlace();
+
+/////////// Geometry module ///////////
+
+ typedef Homogeneous<ExpressionType,Direction> HomogeneousReturnType;
+ EIGEN_DEVICE_FUNC
+ HomogeneousReturnType homogeneous() const;
+
+ typedef typename ExpressionType::PlainObject CrossReturnType;
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ const CrossReturnType cross(const MatrixBase<OtherDerived>& other) const;
+
+ enum {
+ HNormalized_Size = Direction==Vertical ? internal::traits<ExpressionType>::RowsAtCompileTime
+ : internal::traits<ExpressionType>::ColsAtCompileTime,
+ HNormalized_SizeMinusOne = HNormalized_Size==Dynamic ? Dynamic : HNormalized_Size-1
+ };
+ typedef Block<const ExpressionType,
+ Direction==Vertical ? int(HNormalized_SizeMinusOne)
+ : int(internal::traits<ExpressionType>::RowsAtCompileTime),
+ Direction==Horizontal ? int(HNormalized_SizeMinusOne)
+ : int(internal::traits<ExpressionType>::ColsAtCompileTime)>
+ HNormalized_Block;
+ typedef Block<const ExpressionType,
+ Direction==Vertical ? 1 : int(internal::traits<ExpressionType>::RowsAtCompileTime),
+ Direction==Horizontal ? 1 : int(internal::traits<ExpressionType>::ColsAtCompileTime)>
+ HNormalized_Factors;
+ typedef CwiseBinaryOp<internal::scalar_quotient_op<typename internal::traits<ExpressionType>::Scalar>,
+ const HNormalized_Block,
+ const Replicate<HNormalized_Factors,
+ Direction==Vertical ? HNormalized_SizeMinusOne : 1,
+ Direction==Horizontal ? HNormalized_SizeMinusOne : 1> >
+ HNormalizedReturnType;
+
+ EIGEN_DEVICE_FUNC
+ const HNormalizedReturnType hnormalized() const;
+
+# ifdef EIGEN_VECTORWISEOP_PLUGIN
+# include EIGEN_VECTORWISEOP_PLUGIN
+# endif
+
+ protected:
+ Index redux_length() const
+ {
+ return Direction==Vertical ? m_matrix.rows() : m_matrix.cols();
+ }
+ ExpressionTypeNested m_matrix;
+};
+
+//const colwise moved to DenseBase.h due to CUDA compiler bug
+
+
+/** \returns a writable VectorwiseOp wrapper of *this providing additional partial reduction operations
+ *
+ * \sa rowwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline typename DenseBase<Derived>::ColwiseReturnType
+DenseBase<Derived>::colwise()
+{
+ return ColwiseReturnType(derived());
+}
+
+//const rowwise moved to DenseBase.h due to CUDA compiler bug
+
+
+/** \returns a writable VectorwiseOp wrapper of *this providing additional partial reduction operations
+ *
+ * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline typename DenseBase<Derived>::RowwiseReturnType
+DenseBase<Derived>::rowwise()
+{
+ return RowwiseReturnType(derived());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_PARTIAL_REDUX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/Visitor.h b/src/3rdparty/eigen/Eigen/src/Core/Visitor.h
new file mode 100644
index 000000000..00bcca877
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/Visitor.h
@@ -0,0 +1,381 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_VISITOR_H
+#define EIGEN_VISITOR_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Visitor, typename Derived, int UnrollCount>
+struct visitor_impl
+{
+ enum {
+ col = (UnrollCount-1) / Derived::RowsAtCompileTime,
+ row = (UnrollCount-1) % Derived::RowsAtCompileTime
+ };
+
+ EIGEN_DEVICE_FUNC
+ static inline void run(const Derived &mat, Visitor& visitor)
+ {
+ visitor_impl<Visitor, Derived, UnrollCount-1>::run(mat, visitor);
+ visitor(mat.coeff(row, col), row, col);
+ }
+};
+
+template<typename Visitor, typename Derived>
+struct visitor_impl<Visitor, Derived, 1>
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(const Derived &mat, Visitor& visitor)
+ {
+ return visitor.init(mat.coeff(0, 0), 0, 0);
+ }
+};
+
+// This specialization enables visitors on empty matrices at compile-time
+template<typename Visitor, typename Derived>
+struct visitor_impl<Visitor, Derived, 0> {
+ EIGEN_DEVICE_FUNC
+ static inline void run(const Derived &/*mat*/, Visitor& /*visitor*/)
+ {}
+};
+
+template<typename Visitor, typename Derived>
+struct visitor_impl<Visitor, Derived, Dynamic>
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(const Derived& mat, Visitor& visitor)
+ {
+ visitor.init(mat.coeff(0,0), 0, 0);
+ for(Index i = 1; i < mat.rows(); ++i)
+ visitor(mat.coeff(i, 0), i, 0);
+ for(Index j = 1; j < mat.cols(); ++j)
+ for(Index i = 0; i < mat.rows(); ++i)
+ visitor(mat.coeff(i, j), i, j);
+ }
+};
+
+// evaluator adaptor
+template<typename XprType>
+class visitor_evaluator
+{
+public:
+ EIGEN_DEVICE_FUNC
+ explicit visitor_evaluator(const XprType &xpr) : m_evaluator(xpr), m_xpr(xpr) {}
+
+ typedef typename XprType::Scalar Scalar;
+ typedef typename XprType::CoeffReturnType CoeffReturnType;
+
+ enum {
+ RowsAtCompileTime = XprType::RowsAtCompileTime,
+ CoeffReadCost = internal::evaluator<XprType>::CoeffReadCost
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_xpr.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_xpr.cols(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT { return m_xpr.size(); }
+
+ EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col) const
+ { return m_evaluator.coeff(row, col); }
+
+protected:
+ internal::evaluator<XprType> m_evaluator;
+ const XprType &m_xpr;
+};
+} // end namespace internal
+
+/** Applies the visitor \a visitor to the whole coefficients of the matrix or vector.
+ *
+ * The template parameter \a Visitor is the type of the visitor and provides the following interface:
+ * \code
+ * struct MyVisitor {
+ * // called for the first coefficient
+ * void init(const Scalar& value, Index i, Index j);
+ * // called for all other coefficients
+ * void operator() (const Scalar& value, Index i, Index j);
+ * };
+ * \endcode
+ *
+ * \note compared to one or two \em for \em loops, visitors offer automatic
+ * unrolling for small fixed size matrix.
+ *
+ * \note if the matrix is empty, then the visitor is left unchanged.
+ *
+ * \sa minCoeff(Index*,Index*), maxCoeff(Index*,Index*), DenseBase::redux()
+ */
+template<typename Derived>
+template<typename Visitor>
+EIGEN_DEVICE_FUNC
+void DenseBase<Derived>::visit(Visitor& visitor) const
+{
+ if(size()==0)
+ return;
+
+ typedef typename internal::visitor_evaluator<Derived> ThisEvaluator;
+ ThisEvaluator thisEval(derived());
+
+ enum {
+ unroll = SizeAtCompileTime != Dynamic
+ && SizeAtCompileTime * int(ThisEvaluator::CoeffReadCost) + (SizeAtCompileTime-1) * int(internal::functor_traits<Visitor>::Cost) <= EIGEN_UNROLLING_LIMIT
+ };
+ return internal::visitor_impl<Visitor, ThisEvaluator, unroll ? int(SizeAtCompileTime) : Dynamic>::run(thisEval, visitor);
+}
+
+namespace internal {
+
+/** \internal
+ * \brief Base class to implement min and max visitors
+ */
+template <typename Derived>
+struct coeff_visitor
+{
+ // default initialization to avoid countless invalid maybe-uninitialized warnings by gcc
+ EIGEN_DEVICE_FUNC
+ coeff_visitor() : row(-1), col(-1), res(0) {}
+ typedef typename Derived::Scalar Scalar;
+ Index row, col;
+ Scalar res;
+ EIGEN_DEVICE_FUNC
+ inline void init(const Scalar& value, Index i, Index j)
+ {
+ res = value;
+ row = i;
+ col = j;
+ }
+};
+
+/** \internal
+ * \brief Visitor computing the min coefficient with its value and coordinates
+ *
+ * \sa DenseBase::minCoeff(Index*, Index*)
+ */
+template <typename Derived, int NaNPropagation>
+struct min_coeff_visitor : coeff_visitor<Derived>
+{
+ typedef typename Derived::Scalar Scalar;
+ EIGEN_DEVICE_FUNC
+ void operator() (const Scalar& value, Index i, Index j)
+ {
+ if(value < this->res)
+ {
+ this->res = value;
+ this->row = i;
+ this->col = j;
+ }
+ }
+};
+
+template <typename Derived>
+struct min_coeff_visitor<Derived, PropagateNumbers> : coeff_visitor<Derived>
+{
+ typedef typename Derived::Scalar Scalar;
+ EIGEN_DEVICE_FUNC
+ void operator() (const Scalar& value, Index i, Index j)
+ {
+ if((numext::isnan)(this->res) || (!(numext::isnan)(value) && value < this->res))
+ {
+ this->res = value;
+ this->row = i;
+ this->col = j;
+ }
+ }
+};
+
+template <typename Derived>
+struct min_coeff_visitor<Derived, PropagateNaN> : coeff_visitor<Derived>
+{
+ typedef typename Derived::Scalar Scalar;
+ EIGEN_DEVICE_FUNC
+ void operator() (const Scalar& value, Index i, Index j)
+ {
+ if((numext::isnan)(value) || value < this->res)
+ {
+ this->res = value;
+ this->row = i;
+ this->col = j;
+ }
+ }
+};
+
+template<typename Scalar, int NaNPropagation>
+ struct functor_traits<min_coeff_visitor<Scalar, NaNPropagation> > {
+ enum {
+ Cost = NumTraits<Scalar>::AddCost
+ };
+};
+
+/** \internal
+ * \brief Visitor computing the max coefficient with its value and coordinates
+ *
+ * \sa DenseBase::maxCoeff(Index*, Index*)
+ */
+template <typename Derived, int NaNPropagation>
+struct max_coeff_visitor : coeff_visitor<Derived>
+{
+ typedef typename Derived::Scalar Scalar;
+ EIGEN_DEVICE_FUNC
+ void operator() (const Scalar& value, Index i, Index j)
+ {
+ if(value > this->res)
+ {
+ this->res = value;
+ this->row = i;
+ this->col = j;
+ }
+ }
+};
+
+template <typename Derived>
+struct max_coeff_visitor<Derived, PropagateNumbers> : coeff_visitor<Derived>
+{
+ typedef typename Derived::Scalar Scalar;
+ EIGEN_DEVICE_FUNC
+ void operator() (const Scalar& value, Index i, Index j)
+ {
+ if((numext::isnan)(this->res) || (!(numext::isnan)(value) && value > this->res))
+ {
+ this->res = value;
+ this->row = i;
+ this->col = j;
+ }
+ }
+};
+
+template <typename Derived>
+struct max_coeff_visitor<Derived, PropagateNaN> : coeff_visitor<Derived>
+{
+ typedef typename Derived::Scalar Scalar;
+ EIGEN_DEVICE_FUNC
+ void operator() (const Scalar& value, Index i, Index j)
+ {
+ if((numext::isnan)(value) || value > this->res)
+ {
+ this->res = value;
+ this->row = i;
+ this->col = j;
+ }
+ }
+};
+
+template<typename Scalar, int NaNPropagation>
+struct functor_traits<max_coeff_visitor<Scalar, NaNPropagation> > {
+ enum {
+ Cost = NumTraits<Scalar>::AddCost
+ };
+};
+
+} // end namespace internal
+
+/** \fn DenseBase<Derived>::minCoeff(IndexType* rowId, IndexType* colId) const
+ * \returns the minimum of all coefficients of *this and puts in *row and *col its location.
+ *
+ * In case \c *this contains NaN, NaNPropagation determines the behavior:
+ * NaNPropagation == PropagateFast : undefined
+ * NaNPropagation == PropagateNaN : result is NaN
+ * NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
+ * \warning the matrix must be not empty, otherwise an assertion is triggered.
+ *
+ * \sa DenseBase::minCoeff(Index*), DenseBase::maxCoeff(Index*,Index*), DenseBase::visit(), DenseBase::minCoeff()
+ */
+template<typename Derived>
+template<int NaNPropagation, typename IndexType>
+EIGEN_DEVICE_FUNC
+typename internal::traits<Derived>::Scalar
+DenseBase<Derived>::minCoeff(IndexType* rowId, IndexType* colId) const
+{
+ eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix");
+
+ internal::min_coeff_visitor<Derived, NaNPropagation> minVisitor;
+ this->visit(minVisitor);
+ *rowId = minVisitor.row;
+ if (colId) *colId = minVisitor.col;
+ return minVisitor.res;
+}
+
+/** \returns the minimum of all coefficients of *this and puts in *index its location.
+ *
+ * In case \c *this contains NaN, NaNPropagation determines the behavior:
+ * NaNPropagation == PropagateFast : undefined
+ * NaNPropagation == PropagateNaN : result is NaN
+ * NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
+ * \warning the matrix must be not empty, otherwise an assertion is triggered.
+ *
+ * \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::visit(), DenseBase::minCoeff()
+ */
+template<typename Derived>
+template<int NaNPropagation, typename IndexType>
+EIGEN_DEVICE_FUNC
+typename internal::traits<Derived>::Scalar
+DenseBase<Derived>::minCoeff(IndexType* index) const
+{
+ eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix");
+
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ internal::min_coeff_visitor<Derived, NaNPropagation> minVisitor;
+ this->visit(minVisitor);
+ *index = IndexType((RowsAtCompileTime==1) ? minVisitor.col : minVisitor.row);
+ return minVisitor.res;
+}
+
+/** \fn DenseBase<Derived>::maxCoeff(IndexType* rowId, IndexType* colId) const
+ * \returns the maximum of all coefficients of *this and puts in *row and *col its location.
+ *
+ * In case \c *this contains NaN, NaNPropagation determines the behavior:
+ * NaNPropagation == PropagateFast : undefined
+ * NaNPropagation == PropagateNaN : result is NaN
+ * NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
+ * \warning the matrix must be not empty, otherwise an assertion is triggered.
+ *
+ * \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visit(), DenseBase::maxCoeff()
+ */
+template<typename Derived>
+template<int NaNPropagation, typename IndexType>
+EIGEN_DEVICE_FUNC
+typename internal::traits<Derived>::Scalar
+DenseBase<Derived>::maxCoeff(IndexType* rowPtr, IndexType* colPtr) const
+{
+ eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix");
+
+ internal::max_coeff_visitor<Derived, NaNPropagation> maxVisitor;
+ this->visit(maxVisitor);
+ *rowPtr = maxVisitor.row;
+ if (colPtr) *colPtr = maxVisitor.col;
+ return maxVisitor.res;
+}
+
+/** \returns the maximum of all coefficients of *this and puts in *index its location.
+ *
+ * In case \c *this contains NaN, NaNPropagation determines the behavior:
+ * NaNPropagation == PropagateFast : undefined
+ * NaNPropagation == PropagateNaN : result is NaN
+ * NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
+ * \warning the matrix must be not empty, otherwise an assertion is triggered.
+ *
+ * \sa DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visitor(), DenseBase::maxCoeff()
+ */
+template<typename Derived>
+template<int NaNPropagation, typename IndexType>
+EIGEN_DEVICE_FUNC
+typename internal::traits<Derived>::Scalar
+DenseBase<Derived>::maxCoeff(IndexType* index) const
+{
+ eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix");
+
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ internal::max_coeff_visitor<Derived, NaNPropagation> maxVisitor;
+ this->visit(maxVisitor);
+ *index = (RowsAtCompileTime==1) ? maxVisitor.col : maxVisitor.row;
+ return maxVisitor.res;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_VISITOR_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/Complex.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/Complex.h
new file mode 100644
index 000000000..ab7bd6c65
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/Complex.h
@@ -0,0 +1,372 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2014 Benoit Steiner (benoit.steiner.goog@gmail.com)
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMPLEX_AVX_H
+#define EIGEN_COMPLEX_AVX_H
+
+namespace Eigen {
+
+namespace internal {
+
+//---------- float ----------
+struct Packet4cf
+{
+ EIGEN_STRONG_INLINE Packet4cf() {}
+ EIGEN_STRONG_INLINE explicit Packet4cf(const __m256& a) : v(a) {}
+ __m256 v;
+};
+
+#ifndef EIGEN_VECTORIZE_AVX512
+template<> struct packet_traits<std::complex<float> > : default_packet_traits
+{
+ typedef Packet4cf type;
+ typedef Packet2cf half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasSqrt = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0
+ };
+};
+#endif
+
+template<> struct unpacket_traits<Packet4cf> {
+ typedef std::complex<float> type;
+ typedef Packet2cf half;
+ typedef Packet8f as_real;
+ enum {
+ size=4,
+ alignment=Aligned32,
+ vectorizable=true,
+ masked_load_available=false,
+ masked_store_available=false
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet4cf padd<Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_add_ps(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet4cf psub<Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_sub_ps(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet4cf pnegate(const Packet4cf& a)
+{
+ return Packet4cf(pnegate(a.v));
+}
+template<> EIGEN_STRONG_INLINE Packet4cf pconj(const Packet4cf& a)
+{
+ const __m256 mask = _mm256_castsi256_ps(_mm256_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000));
+ return Packet4cf(_mm256_xor_ps(a.v,mask));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cf pmul<Packet4cf>(const Packet4cf& a, const Packet4cf& b)
+{
+ __m256 tmp1 = _mm256_mul_ps(_mm256_moveldup_ps(a.v), b.v);
+ __m256 tmp2 = _mm256_mul_ps(_mm256_movehdup_ps(a.v), _mm256_permute_ps(b.v, _MM_SHUFFLE(2,3,0,1)));
+ __m256 result = _mm256_addsub_ps(tmp1, tmp2);
+ return Packet4cf(result);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4cf pcmp_eq(const Packet4cf& a, const Packet4cf& b) {
+ __m256 eq = _mm256_cmp_ps(a.v, b.v, _CMP_EQ_OQ);
+ return Packet4cf(_mm256_and_ps(eq, _mm256_permute_ps(eq, 0xb1)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cf ptrue<Packet4cf>(const Packet4cf& a) { return Packet4cf(ptrue(Packet8f(a.v))); }
+template<> EIGEN_STRONG_INLINE Packet4cf pand <Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_and_ps(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet4cf por <Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_or_ps(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet4cf pxor <Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_xor_ps(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet4cf pandnot<Packet4cf>(const Packet4cf& a, const Packet4cf& b) { return Packet4cf(_mm256_andnot_ps(b.v,a.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet4cf pload <Packet4cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet4cf(pload<Packet8f>(&numext::real_ref(*from))); }
+template<> EIGEN_STRONG_INLINE Packet4cf ploadu<Packet4cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet4cf(ploadu<Packet8f>(&numext::real_ref(*from))); }
+
+
+template<> EIGEN_STRONG_INLINE Packet4cf pset1<Packet4cf>(const std::complex<float>& from)
+{
+ return Packet4cf(_mm256_castpd_ps(_mm256_broadcast_sd((const double*)(const void*)&from)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cf ploaddup<Packet4cf>(const std::complex<float>* from)
+{
+ // FIXME The following might be optimized using _mm256_movedup_pd
+ Packet2cf a = ploaddup<Packet2cf>(from);
+ Packet2cf b = ploaddup<Packet2cf>(from+1);
+ return Packet4cf(_mm256_insertf128_ps(_mm256_castps128_ps256(a.v), b.v, 1));
+}
+
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float>* to, const Packet4cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore(&numext::real_ref(*to), from.v); }
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float>* to, const Packet4cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(&numext::real_ref(*to), from.v); }
+
+template<> EIGEN_DEVICE_FUNC inline Packet4cf pgather<std::complex<float>, Packet4cf>(const std::complex<float>* from, Index stride)
+{
+ return Packet4cf(_mm256_set_ps(std::imag(from[3*stride]), std::real(from[3*stride]),
+ std::imag(from[2*stride]), std::real(from[2*stride]),
+ std::imag(from[1*stride]), std::real(from[1*stride]),
+ std::imag(from[0*stride]), std::real(from[0*stride])));
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet4cf>(std::complex<float>* to, const Packet4cf& from, Index stride)
+{
+ __m128 low = _mm256_extractf128_ps(from.v, 0);
+ to[stride*0] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(low, low, 0)),
+ _mm_cvtss_f32(_mm_shuffle_ps(low, low, 1)));
+ to[stride*1] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(low, low, 2)),
+ _mm_cvtss_f32(_mm_shuffle_ps(low, low, 3)));
+
+ __m128 high = _mm256_extractf128_ps(from.v, 1);
+ to[stride*2] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(high, high, 0)),
+ _mm_cvtss_f32(_mm_shuffle_ps(high, high, 1)));
+ to[stride*3] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(high, high, 2)),
+ _mm_cvtss_f32(_mm_shuffle_ps(high, high, 3)));
+
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet4cf>(const Packet4cf& a)
+{
+ return pfirst(Packet2cf(_mm256_castps256_ps128(a.v)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cf preverse(const Packet4cf& a) {
+ __m128 low = _mm256_extractf128_ps(a.v, 0);
+ __m128 high = _mm256_extractf128_ps(a.v, 1);
+ __m128d lowd = _mm_castps_pd(low);
+ __m128d highd = _mm_castps_pd(high);
+ low = _mm_castpd_ps(_mm_shuffle_pd(lowd,lowd,0x1));
+ high = _mm_castpd_ps(_mm_shuffle_pd(highd,highd,0x1));
+ __m256 result = _mm256_setzero_ps();
+ result = _mm256_insertf128_ps(result, low, 1);
+ result = _mm256_insertf128_ps(result, high, 0);
+ return Packet4cf(result);
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet4cf>(const Packet4cf& a)
+{
+ return predux(padd(Packet2cf(_mm256_extractf128_ps(a.v,0)),
+ Packet2cf(_mm256_extractf128_ps(a.v,1))));
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet4cf>(const Packet4cf& a)
+{
+ return predux_mul(pmul(Packet2cf(_mm256_extractf128_ps(a.v, 0)),
+ Packet2cf(_mm256_extractf128_ps(a.v, 1))));
+}
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet4cf,Packet8f)
+
+template<> EIGEN_STRONG_INLINE Packet4cf pdiv<Packet4cf>(const Packet4cf& a, const Packet4cf& b)
+{
+ Packet4cf num = pmul(a, pconj(b));
+ __m256 tmp = _mm256_mul_ps(b.v, b.v);
+ __m256 tmp2 = _mm256_shuffle_ps(tmp,tmp,0xB1);
+ __m256 denom = _mm256_add_ps(tmp, tmp2);
+ return Packet4cf(_mm256_div_ps(num.v, denom));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cf pcplxflip<Packet4cf>(const Packet4cf& x)
+{
+ return Packet4cf(_mm256_shuffle_ps(x.v, x.v, _MM_SHUFFLE(2, 3, 0 ,1)));
+}
+
+//---------- double ----------
+struct Packet2cd
+{
+ EIGEN_STRONG_INLINE Packet2cd() {}
+ EIGEN_STRONG_INLINE explicit Packet2cd(const __m256d& a) : v(a) {}
+ __m256d v;
+};
+
+#ifndef EIGEN_VECTORIZE_AVX512
+template<> struct packet_traits<std::complex<double> > : default_packet_traits
+{
+ typedef Packet2cd type;
+ typedef Packet1cd half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 0,
+ size = 2,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasSqrt = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0
+ };
+};
+#endif
+
+template<> struct unpacket_traits<Packet2cd> {
+ typedef std::complex<double> type;
+ typedef Packet1cd half;
+ typedef Packet4d as_real;
+ enum {
+ size=2,
+ alignment=Aligned32,
+ vectorizable=true,
+ masked_load_available=false,
+ masked_store_available=false
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet2cd padd<Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_add_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cd psub<Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_sub_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cd pnegate(const Packet2cd& a) { return Packet2cd(pnegate(a.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cd pconj(const Packet2cd& a)
+{
+ const __m256d mask = _mm256_castsi256_pd(_mm256_set_epi32(0x80000000,0x0,0x0,0x0,0x80000000,0x0,0x0,0x0));
+ return Packet2cd(_mm256_xor_pd(a.v,mask));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cd pmul<Packet2cd>(const Packet2cd& a, const Packet2cd& b)
+{
+ __m256d tmp1 = _mm256_shuffle_pd(a.v,a.v,0x0);
+ __m256d even = _mm256_mul_pd(tmp1, b.v);
+ __m256d tmp2 = _mm256_shuffle_pd(a.v,a.v,0xF);
+ __m256d tmp3 = _mm256_shuffle_pd(b.v,b.v,0x5);
+ __m256d odd = _mm256_mul_pd(tmp2, tmp3);
+ return Packet2cd(_mm256_addsub_pd(even, odd));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cd pcmp_eq(const Packet2cd& a, const Packet2cd& b) {
+ __m256d eq = _mm256_cmp_pd(a.v, b.v, _CMP_EQ_OQ);
+ return Packet2cd(pand(eq, _mm256_permute_pd(eq, 0x5)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cd ptrue<Packet2cd>(const Packet2cd& a) { return Packet2cd(ptrue(Packet4d(a.v))); }
+template<> EIGEN_STRONG_INLINE Packet2cd pand <Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_and_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cd por <Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_or_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cd pxor <Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_xor_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cd pandnot<Packet2cd>(const Packet2cd& a, const Packet2cd& b) { return Packet2cd(_mm256_andnot_pd(b.v,a.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet2cd pload <Packet2cd>(const std::complex<double>* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return Packet2cd(pload<Packet4d>((const double*)from)); }
+template<> EIGEN_STRONG_INLINE Packet2cd ploadu<Packet2cd>(const std::complex<double>* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cd(ploadu<Packet4d>((const double*)from)); }
+
+template<> EIGEN_STRONG_INLINE Packet2cd pset1<Packet2cd>(const std::complex<double>& from)
+{
+ // in case casting to a __m128d* is really not safe, then we can still fallback to this version: (much slower though)
+// return Packet2cd(_mm256_loadu2_m128d((const double*)&from,(const double*)&from));
+ return Packet2cd(_mm256_broadcast_pd((const __m128d*)(const void*)&from));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cd ploaddup<Packet2cd>(const std::complex<double>* from) { return pset1<Packet2cd>(*from); }
+
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet2cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((double*)to, from.v); }
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet2cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, from.v); }
+
+template<> EIGEN_DEVICE_FUNC inline Packet2cd pgather<std::complex<double>, Packet2cd>(const std::complex<double>* from, Index stride)
+{
+ return Packet2cd(_mm256_set_pd(std::imag(from[1*stride]), std::real(from[1*stride]),
+ std::imag(from[0*stride]), std::real(from[0*stride])));
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet2cd>(std::complex<double>* to, const Packet2cd& from, Index stride)
+{
+ __m128d low = _mm256_extractf128_pd(from.v, 0);
+ to[stride*0] = std::complex<double>(_mm_cvtsd_f64(low), _mm_cvtsd_f64(_mm_shuffle_pd(low, low, 1)));
+ __m128d high = _mm256_extractf128_pd(from.v, 1);
+ to[stride*1] = std::complex<double>(_mm_cvtsd_f64(high), _mm_cvtsd_f64(_mm_shuffle_pd(high, high, 1)));
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet2cd>(const Packet2cd& a)
+{
+ __m128d low = _mm256_extractf128_pd(a.v, 0);
+ EIGEN_ALIGN16 double res[2];
+ _mm_store_pd(res, low);
+ return std::complex<double>(res[0],res[1]);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cd preverse(const Packet2cd& a) {
+ __m256d result = _mm256_permute2f128_pd(a.v, a.v, 1);
+ return Packet2cd(result);
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet2cd>(const Packet2cd& a)
+{
+ return predux(padd(Packet1cd(_mm256_extractf128_pd(a.v,0)),
+ Packet1cd(_mm256_extractf128_pd(a.v,1))));
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet2cd>(const Packet2cd& a)
+{
+ return predux(pmul(Packet1cd(_mm256_extractf128_pd(a.v,0)),
+ Packet1cd(_mm256_extractf128_pd(a.v,1))));
+}
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cd,Packet4d)
+
+template<> EIGEN_STRONG_INLINE Packet2cd pdiv<Packet2cd>(const Packet2cd& a, const Packet2cd& b)
+{
+ Packet2cd num = pmul(a, pconj(b));
+ __m256d tmp = _mm256_mul_pd(b.v, b.v);
+ __m256d denom = _mm256_hadd_pd(tmp, tmp);
+ return Packet2cd(_mm256_div_pd(num.v, denom));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cd pcplxflip<Packet2cd>(const Packet2cd& x)
+{
+ return Packet2cd(_mm256_shuffle_pd(x.v, x.v, 0x5));
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet4cf,4>& kernel) {
+ __m256d P0 = _mm256_castps_pd(kernel.packet[0].v);
+ __m256d P1 = _mm256_castps_pd(kernel.packet[1].v);
+ __m256d P2 = _mm256_castps_pd(kernel.packet[2].v);
+ __m256d P3 = _mm256_castps_pd(kernel.packet[3].v);
+
+ __m256d T0 = _mm256_shuffle_pd(P0, P1, 15);
+ __m256d T1 = _mm256_shuffle_pd(P0, P1, 0);
+ __m256d T2 = _mm256_shuffle_pd(P2, P3, 15);
+ __m256d T3 = _mm256_shuffle_pd(P2, P3, 0);
+
+ kernel.packet[1].v = _mm256_castpd_ps(_mm256_permute2f128_pd(T0, T2, 32));
+ kernel.packet[3].v = _mm256_castpd_ps(_mm256_permute2f128_pd(T0, T2, 49));
+ kernel.packet[0].v = _mm256_castpd_ps(_mm256_permute2f128_pd(T1, T3, 32));
+ kernel.packet[2].v = _mm256_castpd_ps(_mm256_permute2f128_pd(T1, T3, 49));
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet2cd,2>& kernel) {
+ __m256d tmp = _mm256_permute2f128_pd(kernel.packet[0].v, kernel.packet[1].v, 0+(2<<4));
+ kernel.packet[1].v = _mm256_permute2f128_pd(kernel.packet[0].v, kernel.packet[1].v, 1+(3<<4));
+ kernel.packet[0].v = tmp;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cd psqrt<Packet2cd>(const Packet2cd& a) {
+ return psqrt_complex<Packet2cd>(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cf psqrt<Packet4cf>(const Packet4cf& a) {
+ return psqrt_complex<Packet4cf>(a);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_COMPLEX_AVX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h
new file mode 100644
index 000000000..67041c812
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h
@@ -0,0 +1,228 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com)
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATH_FUNCTIONS_AVX_H
+#define EIGEN_MATH_FUNCTIONS_AVX_H
+
+/* The sin and cos functions of this file are loosely derived from
+ * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/
+ */
+
+namespace Eigen {
+
+namespace internal {
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f
+psin<Packet8f>(const Packet8f& _x) {
+ return psin_float(_x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f
+pcos<Packet8f>(const Packet8f& _x) {
+ return pcos_float(_x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f
+plog<Packet8f>(const Packet8f& _x) {
+ return plog_float(_x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4d
+plog<Packet4d>(const Packet4d& _x) {
+ return plog_double(_x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f
+plog2<Packet8f>(const Packet8f& _x) {
+ return plog2_float(_x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4d
+plog2<Packet4d>(const Packet4d& _x) {
+ return plog2_double(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet8f plog1p<Packet8f>(const Packet8f& _x) {
+ return generic_plog1p(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet8f pexpm1<Packet8f>(const Packet8f& _x) {
+ return generic_expm1(_x);
+}
+
+// Exponential function. Works by writing "x = m*log(2) + r" where
+// "m = floor(x/log(2)+1/2)" and "r" is the remainder. The result is then
+// "exp(x) = 2^m*exp(r)" where exp(r) is in the range [-1,1).
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f
+pexp<Packet8f>(const Packet8f& _x) {
+ return pexp_float(_x);
+}
+
+// Hyperbolic Tangent function.
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f
+ptanh<Packet8f>(const Packet8f& _x) {
+ return internal::generic_fast_tanh_float(_x);
+}
+
+// Exponential function for doubles.
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4d
+pexp<Packet4d>(const Packet4d& _x) {
+ return pexp_double(_x);
+}
+
+// Functions for sqrt.
+// The EIGEN_FAST_MATH version uses the _mm_rsqrt_ps approximation and one step
+// of Newton's method, at a cost of 1-2 bits of precision as opposed to the
+// exact solution. It does not handle +inf, or denormalized numbers correctly.
+// The main advantage of this approach is not just speed, but also the fact that
+// it can be inlined and pipelined with other computations, further reducing its
+// effective latency. This is similar to Quake3's fast inverse square root.
+// For detail see here: http://www.beyond3d.com/content/articles/8/
+#if EIGEN_FAST_MATH
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet8f psqrt<Packet8f>(const Packet8f& _x) {
+ Packet8f minus_half_x = pmul(_x, pset1<Packet8f>(-0.5f));
+ Packet8f denormal_mask = pandnot(
+ pcmp_lt(_x, pset1<Packet8f>((std::numeric_limits<float>::min)())),
+ pcmp_lt(_x, pzero(_x)));
+
+ // Compute approximate reciprocal sqrt.
+ Packet8f x = _mm256_rsqrt_ps(_x);
+ // Do a single step of Newton's iteration.
+ x = pmul(x, pmadd(minus_half_x, pmul(x,x), pset1<Packet8f>(1.5f)));
+ // Flush results for denormals to zero.
+ return pandnot(pmul(_x,x), denormal_mask);
+}
+
+#else
+
+template <> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet8f psqrt<Packet8f>(const Packet8f& _x) {
+ return _mm256_sqrt_ps(_x);
+}
+
+#endif
+
+template <> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4d psqrt<Packet4d>(const Packet4d& _x) {
+ return _mm256_sqrt_pd(_x);
+}
+
+#if EIGEN_FAST_MATH
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet8f prsqrt<Packet8f>(const Packet8f& _x) {
+ _EIGEN_DECLARE_CONST_Packet8f_FROM_INT(inf, 0x7f800000);
+ _EIGEN_DECLARE_CONST_Packet8f(one_point_five, 1.5f);
+ _EIGEN_DECLARE_CONST_Packet8f(minus_half, -0.5f);
+ _EIGEN_DECLARE_CONST_Packet8f_FROM_INT(flt_min, 0x00800000);
+
+ Packet8f neg_half = pmul(_x, p8f_minus_half);
+
+ // select only the inverse sqrt of positive normal inputs (denormals are
+ // flushed to zero and cause infs as well).
+ Packet8f lt_min_mask = _mm256_cmp_ps(_x, p8f_flt_min, _CMP_LT_OQ);
+ Packet8f inf_mask = _mm256_cmp_ps(_x, p8f_inf, _CMP_EQ_OQ);
+ Packet8f not_normal_finite_mask = _mm256_or_ps(lt_min_mask, inf_mask);
+
+ // Compute an approximate result using the rsqrt intrinsic.
+ Packet8f y_approx = _mm256_rsqrt_ps(_x);
+
+ // Do a single step of Newton-Raphson iteration to improve the approximation.
+ // This uses the formula y_{n+1} = y_n * (1.5 - y_n * (0.5 * x) * y_n).
+ // It is essential to evaluate the inner term like this because forming
+ // y_n^2 may over- or underflow.
+ Packet8f y_newton = pmul(y_approx, pmadd(y_approx, pmul(neg_half, y_approx), p8f_one_point_five));
+
+ // Select the result of the Newton-Raphson step for positive normal arguments.
+ // For other arguments, choose the output of the intrinsic. This will
+ // return rsqrt(+inf) = 0, rsqrt(x) = NaN if x < 0, and rsqrt(x) = +inf if
+ // x is zero or a positive denormalized float (equivalent to flushing positive
+ // denormalized inputs to zero).
+ return pselect<Packet8f>(not_normal_finite_mask, y_approx, y_newton);
+}
+
+#else
+template <> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet8f prsqrt<Packet8f>(const Packet8f& _x) {
+ _EIGEN_DECLARE_CONST_Packet8f(one, 1.0f);
+ return _mm256_div_ps(p8f_one, _mm256_sqrt_ps(_x));
+}
+#endif
+
+template <> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4d prsqrt<Packet4d>(const Packet4d& _x) {
+ _EIGEN_DECLARE_CONST_Packet4d(one, 1.0);
+ return _mm256_div_pd(p4d_one, _mm256_sqrt_pd(_x));
+}
+
+F16_PACKET_FUNCTION(Packet8f, Packet8h, psin)
+F16_PACKET_FUNCTION(Packet8f, Packet8h, pcos)
+F16_PACKET_FUNCTION(Packet8f, Packet8h, plog)
+F16_PACKET_FUNCTION(Packet8f, Packet8h, plog2)
+F16_PACKET_FUNCTION(Packet8f, Packet8h, plog1p)
+F16_PACKET_FUNCTION(Packet8f, Packet8h, pexpm1)
+F16_PACKET_FUNCTION(Packet8f, Packet8h, pexp)
+F16_PACKET_FUNCTION(Packet8f, Packet8h, ptanh)
+F16_PACKET_FUNCTION(Packet8f, Packet8h, psqrt)
+F16_PACKET_FUNCTION(Packet8f, Packet8h, prsqrt)
+
+template <>
+EIGEN_STRONG_INLINE Packet8h pfrexp(const Packet8h& a, Packet8h& exponent) {
+ Packet8f fexponent;
+ const Packet8h out = float2half(pfrexp<Packet8f>(half2float(a), fexponent));
+ exponent = float2half(fexponent);
+ return out;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8h pldexp(const Packet8h& a, const Packet8h& exponent) {
+ return float2half(pldexp<Packet8f>(half2float(a), half2float(exponent)));
+}
+
+BF16_PACKET_FUNCTION(Packet8f, Packet8bf, psin)
+BF16_PACKET_FUNCTION(Packet8f, Packet8bf, pcos)
+BF16_PACKET_FUNCTION(Packet8f, Packet8bf, plog)
+BF16_PACKET_FUNCTION(Packet8f, Packet8bf, plog2)
+BF16_PACKET_FUNCTION(Packet8f, Packet8bf, plog1p)
+BF16_PACKET_FUNCTION(Packet8f, Packet8bf, pexpm1)
+BF16_PACKET_FUNCTION(Packet8f, Packet8bf, pexp)
+BF16_PACKET_FUNCTION(Packet8f, Packet8bf, ptanh)
+BF16_PACKET_FUNCTION(Packet8f, Packet8bf, psqrt)
+BF16_PACKET_FUNCTION(Packet8f, Packet8bf, prsqrt)
+
+template <>
+EIGEN_STRONG_INLINE Packet8bf pfrexp(const Packet8bf& a, Packet8bf& exponent) {
+ Packet8f fexponent;
+ const Packet8bf out = F32ToBf16(pfrexp<Packet8f>(Bf16ToF32(a), fexponent));
+ exponent = F32ToBf16(fexponent);
+ return out;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8bf pldexp(const Packet8bf& a, const Packet8bf& exponent) {
+ return F32ToBf16(pldexp<Packet8f>(Bf16ToF32(a), Bf16ToF32(exponent)));
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATH_FUNCTIONS_AVX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/PacketMath.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/PacketMath.h
new file mode 100644
index 000000000..7fc32fd71
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/PacketMath.h
@@ -0,0 +1,1574 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2014 Benoit Steiner (benoit.steiner.goog@gmail.com)
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PACKET_MATH_AVX_H
+#define EIGEN_PACKET_MATH_AVX_H
+
+namespace Eigen {
+
+namespace internal {
+
+#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
+#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
+#endif
+
+#if !defined(EIGEN_VECTORIZE_AVX512) && !defined(EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS)
+#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 16
+#endif
+
+#ifdef EIGEN_VECTORIZE_FMA
+#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#endif
+#endif
+
+typedef __m256 Packet8f;
+typedef __m256i Packet8i;
+typedef __m256d Packet4d;
+typedef eigen_packet_wrapper<__m128i, 2> Packet8h;
+typedef eigen_packet_wrapper<__m128i, 3> Packet8bf;
+
+template<> struct is_arithmetic<__m256> { enum { value = true }; };
+template<> struct is_arithmetic<__m256i> { enum { value = true }; };
+template<> struct is_arithmetic<__m256d> { enum { value = true }; };
+template<> struct is_arithmetic<Packet8h> { enum { value = true }; };
+template<> struct is_arithmetic<Packet8bf> { enum { value = true }; };
+
+#define _EIGEN_DECLARE_CONST_Packet8f(NAME,X) \
+ const Packet8f p8f_##NAME = pset1<Packet8f>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet4d(NAME,X) \
+ const Packet4d p4d_##NAME = pset1<Packet4d>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet8f_FROM_INT(NAME,X) \
+ const Packet8f p8f_##NAME = _mm256_castsi256_ps(pset1<Packet8i>(X))
+
+#define _EIGEN_DECLARE_CONST_Packet8i(NAME,X) \
+ const Packet8i p8i_##NAME = pset1<Packet8i>(X)
+
+// Use the packet_traits defined in AVX512/PacketMath.h instead if we're going
+// to leverage AVX512 instructions.
+#ifndef EIGEN_VECTORIZE_AVX512
+template<> struct packet_traits<float> : default_packet_traits
+{
+ typedef Packet8f type;
+ typedef Packet4f half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 8,
+ HasHalfPacket = 1,
+
+ HasCmp = 1,
+ HasDiv = 1,
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+ HasLog = 1,
+ HasLog1p = 1,
+ HasExpm1 = 1,
+ HasExp = 1,
+ HasNdtri = 1,
+ HasBessel = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+ HasBlend = 1,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1
+ };
+};
+template<> struct packet_traits<double> : default_packet_traits
+{
+ typedef Packet4d type;
+ typedef Packet2d half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size=4,
+ HasHalfPacket = 1,
+
+ HasCmp = 1,
+ HasDiv = 1,
+ HasLog = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasBlend = 1,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1
+ };
+};
+
+template <>
+struct packet_traits<Eigen::half> : default_packet_traits {
+ typedef Packet8h type;
+ // There is no half-size packet for Packet8h.
+ typedef Packet8h half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 8,
+ HasHalfPacket = 0,
+
+ HasCmp = 1,
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasAbs2 = 0,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasLog = 1,
+ HasLog1p = 1,
+ HasExpm1 = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+ HasBlend = 0,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1,
+ HasBessel = 1,
+ HasNdtri = 1
+ };
+};
+
+template <>
+struct packet_traits<bfloat16> : default_packet_traits {
+ typedef Packet8bf type;
+ // There is no half-size packet for current Packet8bf.
+ // TODO: support as SSE path.
+ typedef Packet8bf half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 8,
+ HasHalfPacket = 0,
+
+ HasCmp = 1,
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasAbs2 = 0,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasLog = 1,
+ HasLog1p = 1,
+ HasExpm1 = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+ HasBlend = 0,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1,
+ HasBessel = 1,
+ HasNdtri = 1
+ };
+};
+#endif
+
+template<> struct scalar_div_cost<float,true> { enum { value = 14 }; };
+template<> struct scalar_div_cost<double,true> { enum { value = 16 }; };
+
+/* Proper support for integers is only provided by AVX2. In the meantime, we'll
+ use SSE instructions and packets to deal with integers.
+template<> struct packet_traits<int> : default_packet_traits
+{
+ typedef Packet8i type;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size=8
+ };
+};
+*/
+
+template<> struct unpacket_traits<Packet8f> {
+ typedef float type;
+ typedef Packet4f half;
+ typedef Packet8i integer_packet;
+ typedef uint8_t mask_t;
+ enum {size=8, alignment=Aligned32, vectorizable=true, masked_load_available=true, masked_store_available=true};
+};
+template<> struct unpacket_traits<Packet4d> {
+ typedef double type;
+ typedef Packet2d half;
+ enum {size=4, alignment=Aligned32, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+template<> struct unpacket_traits<Packet8i> { typedef int type; typedef Packet4i half; enum {size=8, alignment=Aligned32, vectorizable=false, masked_load_available=false, masked_store_available=false}; };
+template<> struct unpacket_traits<Packet8bf> { typedef bfloat16 type; typedef Packet8bf half; enum {size=8, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; };
+
+// Helper function for bit packing snippet of low precision comparison.
+// It packs the flags from 16x16 to 8x16.
+EIGEN_STRONG_INLINE __m128i Pack16To8(Packet8f rf) {
+ return _mm_packs_epi32(_mm256_extractf128_si256(_mm256_castps_si256(rf), 0),
+ _mm256_extractf128_si256(_mm256_castps_si256(rf), 1));
+}
+
+
+template<> EIGEN_STRONG_INLINE Packet8f pset1<Packet8f>(const float& from) { return _mm256_set1_ps(from); }
+template<> EIGEN_STRONG_INLINE Packet4d pset1<Packet4d>(const double& from) { return _mm256_set1_pd(from); }
+template<> EIGEN_STRONG_INLINE Packet8i pset1<Packet8i>(const int& from) { return _mm256_set1_epi32(from); }
+
+template<> EIGEN_STRONG_INLINE Packet8f pset1frombits<Packet8f>(unsigned int from) { return _mm256_castsi256_ps(pset1<Packet8i>(from)); }
+template<> EIGEN_STRONG_INLINE Packet4d pset1frombits<Packet4d>(uint64_t from) { return _mm256_castsi256_pd(_mm256_set1_epi64x(from)); }
+
+template<> EIGEN_STRONG_INLINE Packet8f pzero(const Packet8f& /*a*/) { return _mm256_setzero_ps(); }
+template<> EIGEN_STRONG_INLINE Packet4d pzero(const Packet4d& /*a*/) { return _mm256_setzero_pd(); }
+template<> EIGEN_STRONG_INLINE Packet8i pzero(const Packet8i& /*a*/) { return _mm256_setzero_si256(); }
+
+
+template<> EIGEN_STRONG_INLINE Packet8f peven_mask(const Packet8f& /*a*/) { return _mm256_castsi256_ps(_mm256_set_epi32(0, -1, 0, -1, 0, -1, 0, -1)); }
+template<> EIGEN_STRONG_INLINE Packet8i peven_mask(const Packet8i& /*a*/) { return _mm256_set_epi32(0, -1, 0, -1, 0, -1, 0, -1); }
+template<> EIGEN_STRONG_INLINE Packet4d peven_mask(const Packet4d& /*a*/) { return _mm256_castsi256_pd(_mm256_set_epi32(0, 0, -1, -1, 0, 0, -1, -1)); }
+
+template<> EIGEN_STRONG_INLINE Packet8f pload1<Packet8f>(const float* from) { return _mm256_broadcast_ss(from); }
+template<> EIGEN_STRONG_INLINE Packet4d pload1<Packet4d>(const double* from) { return _mm256_broadcast_sd(from); }
+
+template<> EIGEN_STRONG_INLINE Packet8f plset<Packet8f>(const float& a) { return _mm256_add_ps(_mm256_set1_ps(a), _mm256_set_ps(7.0,6.0,5.0,4.0,3.0,2.0,1.0,0.0)); }
+template<> EIGEN_STRONG_INLINE Packet4d plset<Packet4d>(const double& a) { return _mm256_add_pd(_mm256_set1_pd(a), _mm256_set_pd(3.0,2.0,1.0,0.0)); }
+
+template<> EIGEN_STRONG_INLINE Packet8f padd<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_add_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4d padd<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_add_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8i padd<Packet8i>(const Packet8i& a, const Packet8i& b) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ return _mm256_add_epi32(a,b);
+#else
+ __m128i lo = _mm_add_epi32(_mm256_extractf128_si256(a, 0), _mm256_extractf128_si256(b, 0));
+ __m128i hi = _mm_add_epi32(_mm256_extractf128_si256(a, 1), _mm256_extractf128_si256(b, 1));
+ return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 1);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f psub<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_sub_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4d psub<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_sub_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8i psub<Packet8i>(const Packet8i& a, const Packet8i& b) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ return _mm256_sub_epi32(a,b);
+#else
+ __m128i lo = _mm_sub_epi32(_mm256_extractf128_si256(a, 0), _mm256_extractf128_si256(b, 0));
+ __m128i hi = _mm_sub_epi32(_mm256_extractf128_si256(a, 1), _mm256_extractf128_si256(b, 1));
+ return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 1);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pnegate(const Packet8f& a)
+{
+ return _mm256_sub_ps(_mm256_set1_ps(0.0),a);
+}
+template<> EIGEN_STRONG_INLINE Packet4d pnegate(const Packet4d& a)
+{
+ return _mm256_sub_pd(_mm256_set1_pd(0.0),a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pconj(const Packet8f& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4d pconj(const Packet4d& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet8i pconj(const Packet8i& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet8f pmul<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_mul_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4d pmul<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_mul_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8i pmul<Packet8i>(const Packet8i& a, const Packet8i& b) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ return _mm256_mullo_epi32(a,b);
+#else
+ const __m128i lo = _mm_mullo_epi32(_mm256_extractf128_si256(a, 0), _mm256_extractf128_si256(b, 0));
+ const __m128i hi = _mm_mullo_epi32(_mm256_extractf128_si256(a, 1), _mm256_extractf128_si256(b, 1));
+ return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 1);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pdiv<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_div_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4d pdiv<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_div_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8i pdiv<Packet8i>(const Packet8i& /*a*/, const Packet8i& /*b*/)
+{ eigen_assert(false && "packet integer division are not supported by AVX");
+ return pset1<Packet8i>(0);
+}
+
+#ifdef EIGEN_VECTORIZE_FMA
+template<> EIGEN_STRONG_INLINE Packet8f pmadd(const Packet8f& a, const Packet8f& b, const Packet8f& c) {
+#if ( (EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<80) || (EIGEN_COMP_CLANG) )
+ // Clang stupidly generates a vfmadd213ps instruction plus some vmovaps on registers,
+ // and even register spilling with clang>=6.0 (bug 1637).
+ // Gcc stupidly generates a vfmadd132ps instruction.
+ // So let's enforce it to generate a vfmadd231ps instruction since the most common use
+ // case is to accumulate the result of the product.
+ Packet8f res = c;
+ __asm__("vfmadd231ps %[a], %[b], %[c]" : [c] "+x" (res) : [a] "x" (a), [b] "x" (b));
+ return res;
+#else
+ return _mm256_fmadd_ps(a,b,c);
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet4d pmadd(const Packet4d& a, const Packet4d& b, const Packet4d& c) {
+#if ( (EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<80) || (EIGEN_COMP_CLANG) )
+ // see above
+ Packet4d res = c;
+ __asm__("vfmadd231pd %[a], %[b], %[c]" : [c] "+x" (res) : [a] "x" (a), [b] "x" (b));
+ return res;
+#else
+ return _mm256_fmadd_pd(a,b,c);
+#endif
+}
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet8f pcmp_le(const Packet8f& a, const Packet8f& b) { return _mm256_cmp_ps(a,b,_CMP_LE_OQ); }
+template<> EIGEN_STRONG_INLINE Packet8f pcmp_lt(const Packet8f& a, const Packet8f& b) { return _mm256_cmp_ps(a,b,_CMP_LT_OQ); }
+template<> EIGEN_STRONG_INLINE Packet8f pcmp_lt_or_nan(const Packet8f& a, const Packet8f& b) { return _mm256_cmp_ps(a, b, _CMP_NGE_UQ); }
+template<> EIGEN_STRONG_INLINE Packet8f pcmp_eq(const Packet8f& a, const Packet8f& b) { return _mm256_cmp_ps(a,b,_CMP_EQ_OQ); }
+
+template<> EIGEN_STRONG_INLINE Packet4d pcmp_le(const Packet4d& a, const Packet4d& b) { return _mm256_cmp_pd(a,b,_CMP_LE_OQ); }
+template<> EIGEN_STRONG_INLINE Packet4d pcmp_lt(const Packet4d& a, const Packet4d& b) { return _mm256_cmp_pd(a,b,_CMP_LT_OQ); }
+template<> EIGEN_STRONG_INLINE Packet4d pcmp_lt_or_nan(const Packet4d& a, const Packet4d& b) { return _mm256_cmp_pd(a, b, _CMP_NGE_UQ); }
+template<> EIGEN_STRONG_INLINE Packet4d pcmp_eq(const Packet4d& a, const Packet4d& b) { return _mm256_cmp_pd(a,b,_CMP_EQ_OQ); }
+
+
+template<> EIGEN_STRONG_INLINE Packet8i pcmp_eq(const Packet8i& a, const Packet8i& b) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ return _mm256_cmpeq_epi32(a,b);
+#else
+ __m128i lo = _mm_cmpeq_epi32(_mm256_extractf128_si256(a, 0), _mm256_extractf128_si256(b, 0));
+ __m128i hi = _mm_cmpeq_epi32(_mm256_extractf128_si256(a, 1), _mm256_extractf128_si256(b, 1));
+ return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 1);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pmin<Packet8f>(const Packet8f& a, const Packet8f& b) {
+#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63
+ // There appears to be a bug in GCC, by which the optimizer may flip
+ // the argument order in calls to _mm_min_ps/_mm_max_ps, so we have to
+ // resort to inline ASM here. This is supposed to be fixed in gcc6.3,
+ // see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72867
+ Packet8f res;
+ asm("vminps %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b));
+ return res;
+#else
+ // Arguments are swapped to match NaN propagation behavior of std::min.
+ return _mm256_min_ps(b,a);
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet4d pmin<Packet4d>(const Packet4d& a, const Packet4d& b) {
+#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63
+ // See pmin above
+ Packet4d res;
+ asm("vminpd %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b));
+ return res;
+#else
+ // Arguments are swapped to match NaN propagation behavior of std::min.
+ return _mm256_min_pd(b,a);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pmax<Packet8f>(const Packet8f& a, const Packet8f& b) {
+#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63
+ // See pmin above
+ Packet8f res;
+ asm("vmaxps %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b));
+ return res;
+#else
+ // Arguments are swapped to match NaN propagation behavior of std::max.
+ return _mm256_max_ps(b,a);
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet4d pmax<Packet4d>(const Packet4d& a, const Packet4d& b) {
+#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63
+ // See pmin above
+ Packet4d res;
+ asm("vmaxpd %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b));
+ return res;
+#else
+ // Arguments are swapped to match NaN propagation behavior of std::max.
+ return _mm256_max_pd(b,a);
+#endif
+}
+
+// Add specializations for min/max with prescribed NaN progation.
+template<>
+EIGEN_STRONG_INLINE Packet8f pmin<PropagateNumbers, Packet8f>(const Packet8f& a, const Packet8f& b) {
+ return pminmax_propagate_numbers(a, b, pmin<Packet8f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet4d pmin<PropagateNumbers, Packet4d>(const Packet4d& a, const Packet4d& b) {
+ return pminmax_propagate_numbers(a, b, pmin<Packet4d>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet8f pmax<PropagateNumbers, Packet8f>(const Packet8f& a, const Packet8f& b) {
+ return pminmax_propagate_numbers(a, b, pmax<Packet8f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet4d pmax<PropagateNumbers, Packet4d>(const Packet4d& a, const Packet4d& b) {
+ return pminmax_propagate_numbers(a, b, pmax<Packet4d>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet8f pmin<PropagateNaN, Packet8f>(const Packet8f& a, const Packet8f& b) {
+ return pminmax_propagate_nan(a, b, pmin<Packet8f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet4d pmin<PropagateNaN, Packet4d>(const Packet4d& a, const Packet4d& b) {
+ return pminmax_propagate_nan(a, b, pmin<Packet4d>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet8f pmax<PropagateNaN, Packet8f>(const Packet8f& a, const Packet8f& b) {
+ return pminmax_propagate_nan(a, b, pmax<Packet8f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet4d pmax<PropagateNaN, Packet4d>(const Packet4d& a, const Packet4d& b) {
+ return pminmax_propagate_nan(a, b, pmax<Packet4d>);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f print<Packet8f>(const Packet8f& a) { return _mm256_round_ps(a, _MM_FROUND_CUR_DIRECTION); }
+template<> EIGEN_STRONG_INLINE Packet4d print<Packet4d>(const Packet4d& a) { return _mm256_round_pd(a, _MM_FROUND_CUR_DIRECTION); }
+
+template<> EIGEN_STRONG_INLINE Packet8f pceil<Packet8f>(const Packet8f& a) { return _mm256_ceil_ps(a); }
+template<> EIGEN_STRONG_INLINE Packet4d pceil<Packet4d>(const Packet4d& a) { return _mm256_ceil_pd(a); }
+
+template<> EIGEN_STRONG_INLINE Packet8f pfloor<Packet8f>(const Packet8f& a) { return _mm256_floor_ps(a); }
+template<> EIGEN_STRONG_INLINE Packet4d pfloor<Packet4d>(const Packet4d& a) { return _mm256_floor_pd(a); }
+
+
+template<> EIGEN_STRONG_INLINE Packet8i ptrue<Packet8i>(const Packet8i& a) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ // vpcmpeqd has lower latency than the more general vcmpps
+ return _mm256_cmpeq_epi32(a,a);
+#else
+ const __m256 b = _mm256_castsi256_ps(a);
+ return _mm256_castps_si256(_mm256_cmp_ps(b,b,_CMP_TRUE_UQ));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f ptrue<Packet8f>(const Packet8f& a) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ // vpcmpeqd has lower latency than the more general vcmpps
+ const __m256i b = _mm256_castps_si256(a);
+ return _mm256_castsi256_ps(_mm256_cmpeq_epi32(b,b));
+#else
+ return _mm256_cmp_ps(a,a,_CMP_TRUE_UQ);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet4d ptrue<Packet4d>(const Packet4d& a) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ // vpcmpeqq has lower latency than the more general vcmppd
+ const __m256i b = _mm256_castpd_si256(a);
+ return _mm256_castsi256_pd(_mm256_cmpeq_epi64(b,b));
+#else
+ return _mm256_cmp_pd(a,a,_CMP_TRUE_UQ);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pand<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_and_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4d pand<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_and_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8i pand<Packet8i>(const Packet8i& a, const Packet8i& b) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ return _mm256_and_si256(a,b);
+#else
+ return _mm256_castps_si256(_mm256_and_ps(_mm256_castsi256_ps(a),_mm256_castsi256_ps(b)));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f por<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_or_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4d por<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_or_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8i por<Packet8i>(const Packet8i& a, const Packet8i& b) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ return _mm256_or_si256(a,b);
+#else
+ return _mm256_castps_si256(_mm256_or_ps(_mm256_castsi256_ps(a),_mm256_castsi256_ps(b)));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pxor<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_xor_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4d pxor<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_xor_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8i pxor<Packet8i>(const Packet8i& a, const Packet8i& b) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ return _mm256_xor_si256(a,b);
+#else
+ return _mm256_castps_si256(_mm256_xor_ps(_mm256_castsi256_ps(a),_mm256_castsi256_ps(b)));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pandnot<Packet8f>(const Packet8f& a, const Packet8f& b) { return _mm256_andnot_ps(b,a); }
+template<> EIGEN_STRONG_INLINE Packet4d pandnot<Packet4d>(const Packet4d& a, const Packet4d& b) { return _mm256_andnot_pd(b,a); }
+template<> EIGEN_STRONG_INLINE Packet8i pandnot<Packet8i>(const Packet8i& a, const Packet8i& b) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ return _mm256_andnot_si256(b,a);
+#else
+ return _mm256_castps_si256(_mm256_andnot_ps(_mm256_castsi256_ps(b),_mm256_castsi256_ps(a)));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pround<Packet8f>(const Packet8f& a)
+{
+ const Packet8f mask = pset1frombits<Packet8f>(static_cast<numext::uint32_t>(0x80000000u));
+ const Packet8f prev0dot5 = pset1frombits<Packet8f>(static_cast<numext::uint32_t>(0x3EFFFFFFu));
+ return _mm256_round_ps(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO);
+}
+template<> EIGEN_STRONG_INLINE Packet4d pround<Packet4d>(const Packet4d& a)
+{
+ const Packet4d mask = pset1frombits<Packet4d>(static_cast<numext::uint64_t>(0x8000000000000000ull));
+ const Packet4d prev0dot5 = pset1frombits<Packet4d>(static_cast<numext::uint64_t>(0x3FDFFFFFFFFFFFFFull));
+ return _mm256_round_pd(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pselect<Packet8f>(const Packet8f& mask, const Packet8f& a, const Packet8f& b)
+{ return _mm256_blendv_ps(b,a,mask); }
+template<> EIGEN_STRONG_INLINE Packet4d pselect<Packet4d>(const Packet4d& mask, const Packet4d& a, const Packet4d& b)
+{ return _mm256_blendv_pd(b,a,mask); }
+
+template<int N> EIGEN_STRONG_INLINE Packet8i parithmetic_shift_right(Packet8i a) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ return _mm256_srai_epi32(a, N);
+#else
+ __m128i lo = _mm_srai_epi32(_mm256_extractf128_si256(a, 0), N);
+ __m128i hi = _mm_srai_epi32(_mm256_extractf128_si256(a, 1), N);
+ return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 1);
+#endif
+}
+
+template<int N> EIGEN_STRONG_INLINE Packet8i plogical_shift_right(Packet8i a) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ return _mm256_srli_epi32(a, N);
+#else
+ __m128i lo = _mm_srli_epi32(_mm256_extractf128_si256(a, 0), N);
+ __m128i hi = _mm_srli_epi32(_mm256_extractf128_si256(a, 1), N);
+ return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 1);
+#endif
+}
+
+template<int N> EIGEN_STRONG_INLINE Packet8i plogical_shift_left(Packet8i a) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ return _mm256_slli_epi32(a, N);
+#else
+ __m128i lo = _mm_slli_epi32(_mm256_extractf128_si256(a, 0), N);
+ __m128i hi = _mm_slli_epi32(_mm256_extractf128_si256(a, 1), N);
+ return _mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 1);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pload<Packet8f>(const float* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm256_load_ps(from); }
+template<> EIGEN_STRONG_INLINE Packet4d pload<Packet4d>(const double* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm256_load_pd(from); }
+template<> EIGEN_STRONG_INLINE Packet8i pload<Packet8i>(const int* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm256_load_si256(reinterpret_cast<const __m256i*>(from)); }
+
+template<> EIGEN_STRONG_INLINE Packet8f ploadu<Packet8f>(const float* from) { EIGEN_DEBUG_UNALIGNED_LOAD return _mm256_loadu_ps(from); }
+template<> EIGEN_STRONG_INLINE Packet4d ploadu<Packet4d>(const double* from) { EIGEN_DEBUG_UNALIGNED_LOAD return _mm256_loadu_pd(from); }
+template<> EIGEN_STRONG_INLINE Packet8i ploadu<Packet8i>(const int* from) { EIGEN_DEBUG_UNALIGNED_LOAD return _mm256_loadu_si256(reinterpret_cast<const __m256i*>(from)); }
+
+template<> EIGEN_STRONG_INLINE Packet8f ploadu<Packet8f>(const float* from, uint8_t umask) {
+ Packet8i mask = _mm256_set1_epi8(static_cast<char>(umask));
+ const Packet8i bit_mask = _mm256_set_epi32(0xffffff7f, 0xffffffbf, 0xffffffdf, 0xffffffef, 0xfffffff7, 0xfffffffb, 0xfffffffd, 0xfffffffe);
+ mask = por<Packet8i>(mask, bit_mask);
+ mask = pcmp_eq<Packet8i>(mask, _mm256_set1_epi32(0xffffffff));
+ EIGEN_DEBUG_UNALIGNED_LOAD return _mm256_maskload_ps(from, mask);
+}
+
+// Loads 4 floats from memory a returns the packet {a0, a0 a1, a1, a2, a2, a3, a3}
+template<> EIGEN_STRONG_INLINE Packet8f ploaddup<Packet8f>(const float* from)
+{
+ // TODO try to find a way to avoid the need of a temporary register
+// Packet8f tmp = _mm256_castps128_ps256(_mm_loadu_ps(from));
+// tmp = _mm256_insertf128_ps(tmp, _mm_movehl_ps(_mm256_castps256_ps128(tmp),_mm256_castps256_ps128(tmp)), 1);
+// return _mm256_unpacklo_ps(tmp,tmp);
+
+ // _mm256_insertf128_ps is very slow on Haswell, thus:
+ Packet8f tmp = _mm256_broadcast_ps((const __m128*)(const void*)from);
+ // mimic an "inplace" permutation of the lower 128bits using a blend
+ tmp = _mm256_blend_ps(tmp,_mm256_castps128_ps256(_mm_permute_ps( _mm256_castps256_ps128(tmp), _MM_SHUFFLE(1,0,1,0))), 15);
+ // then we can perform a consistent permutation on the global register to get everything in shape:
+ return _mm256_permute_ps(tmp, _MM_SHUFFLE(3,3,2,2));
+}
+// Loads 2 doubles from memory a returns the packet {a0, a0 a1, a1}
+template<> EIGEN_STRONG_INLINE Packet4d ploaddup<Packet4d>(const double* from)
+{
+ Packet4d tmp = _mm256_broadcast_pd((const __m128d*)(const void*)from);
+ return _mm256_permute_pd(tmp, 3<<2);
+}
+
+// Loads 2 floats from memory a returns the packet {a0, a0 a0, a0, a1, a1, a1, a1}
+template<> EIGEN_STRONG_INLINE Packet8f ploadquad<Packet8f>(const float* from)
+{
+ Packet8f tmp = _mm256_castps128_ps256(_mm_broadcast_ss(from));
+ return _mm256_insertf128_ps(tmp, _mm_broadcast_ss(from+1), 1);
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet8f& from) { EIGEN_DEBUG_ALIGNED_STORE _mm256_store_ps(to, from); }
+template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet4d& from) { EIGEN_DEBUG_ALIGNED_STORE _mm256_store_pd(to, from); }
+template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet8i& from) { EIGEN_DEBUG_ALIGNED_STORE _mm256_storeu_si256(reinterpret_cast<__m256i*>(to), from); }
+
+template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet8f& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm256_storeu_ps(to, from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet4d& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm256_storeu_pd(to, from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet8i& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm256_storeu_si256(reinterpret_cast<__m256i*>(to), from); }
+
+template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet8f& from, uint8_t umask) {
+ Packet8i mask = _mm256_set1_epi8(static_cast<char>(umask));
+ const Packet8i bit_mask = _mm256_set_epi32(0xffffff7f, 0xffffffbf, 0xffffffdf, 0xffffffef, 0xfffffff7, 0xfffffffb, 0xfffffffd, 0xfffffffe);
+ mask = por<Packet8i>(mask, bit_mask);
+ mask = pcmp_eq<Packet8i>(mask, _mm256_set1_epi32(0xffffffff));
+ EIGEN_DEBUG_UNALIGNED_STORE return _mm256_maskstore_ps(to, mask, from);
+}
+
+// NOTE: leverage _mm256_i32gather_ps and _mm256_i32gather_pd if AVX2 instructions are available
+// NOTE: for the record the following seems to be slower: return _mm256_i32gather_ps(from, _mm256_set1_epi32(stride), 4);
+template<> EIGEN_DEVICE_FUNC inline Packet8f pgather<float, Packet8f>(const float* from, Index stride)
+{
+ return _mm256_set_ps(from[7*stride], from[6*stride], from[5*stride], from[4*stride],
+ from[3*stride], from[2*stride], from[1*stride], from[0*stride]);
+}
+template<> EIGEN_DEVICE_FUNC inline Packet4d pgather<double, Packet4d>(const double* from, Index stride)
+{
+ return _mm256_set_pd(from[3*stride], from[2*stride], from[1*stride], from[0*stride]);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet8f>(float* to, const Packet8f& from, Index stride)
+{
+ __m128 low = _mm256_extractf128_ps(from, 0);
+ to[stride*0] = _mm_cvtss_f32(low);
+ to[stride*1] = _mm_cvtss_f32(_mm_shuffle_ps(low, low, 1));
+ to[stride*2] = _mm_cvtss_f32(_mm_shuffle_ps(low, low, 2));
+ to[stride*3] = _mm_cvtss_f32(_mm_shuffle_ps(low, low, 3));
+
+ __m128 high = _mm256_extractf128_ps(from, 1);
+ to[stride*4] = _mm_cvtss_f32(high);
+ to[stride*5] = _mm_cvtss_f32(_mm_shuffle_ps(high, high, 1));
+ to[stride*6] = _mm_cvtss_f32(_mm_shuffle_ps(high, high, 2));
+ to[stride*7] = _mm_cvtss_f32(_mm_shuffle_ps(high, high, 3));
+}
+template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet4d>(double* to, const Packet4d& from, Index stride)
+{
+ __m128d low = _mm256_extractf128_pd(from, 0);
+ to[stride*0] = _mm_cvtsd_f64(low);
+ to[stride*1] = _mm_cvtsd_f64(_mm_shuffle_pd(low, low, 1));
+ __m128d high = _mm256_extractf128_pd(from, 1);
+ to[stride*2] = _mm_cvtsd_f64(high);
+ to[stride*3] = _mm_cvtsd_f64(_mm_shuffle_pd(high, high, 1));
+}
+
+template<> EIGEN_STRONG_INLINE void pstore1<Packet8f>(float* to, const float& a)
+{
+ Packet8f pa = pset1<Packet8f>(a);
+ pstore(to, pa);
+}
+template<> EIGEN_STRONG_INLINE void pstore1<Packet4d>(double* to, const double& a)
+{
+ Packet4d pa = pset1<Packet4d>(a);
+ pstore(to, pa);
+}
+template<> EIGEN_STRONG_INLINE void pstore1<Packet8i>(int* to, const int& a)
+{
+ Packet8i pa = pset1<Packet8i>(a);
+ pstore(to, pa);
+}
+
+#ifndef EIGEN_VECTORIZE_AVX512
+template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
+template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
+template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
+#endif
+
+template<> EIGEN_STRONG_INLINE float pfirst<Packet8f>(const Packet8f& a) {
+ return _mm_cvtss_f32(_mm256_castps256_ps128(a));
+}
+template<> EIGEN_STRONG_INLINE double pfirst<Packet4d>(const Packet4d& a) {
+ return _mm_cvtsd_f64(_mm256_castpd256_pd128(a));
+}
+template<> EIGEN_STRONG_INLINE int pfirst<Packet8i>(const Packet8i& a) {
+ return _mm_cvtsi128_si32(_mm256_castsi256_si128(a));
+}
+
+
+template<> EIGEN_STRONG_INLINE Packet8f preverse(const Packet8f& a)
+{
+ __m256 tmp = _mm256_shuffle_ps(a,a,0x1b);
+ return _mm256_permute2f128_ps(tmp, tmp, 1);
+}
+template<> EIGEN_STRONG_INLINE Packet4d preverse(const Packet4d& a)
+{
+ __m256d tmp = _mm256_shuffle_pd(a,a,5);
+ return _mm256_permute2f128_pd(tmp, tmp, 1);
+ #if 0
+ // This version is unlikely to be faster as _mm256_shuffle_ps and _mm256_permute_pd
+ // exhibit the same latency/throughput, but it is here for future reference/benchmarking...
+ __m256d swap_halves = _mm256_permute2f128_pd(a,a,1);
+ return _mm256_permute_pd(swap_halves,5);
+ #endif
+}
+
+// pabs should be ok
+template<> EIGEN_STRONG_INLINE Packet8f pabs(const Packet8f& a)
+{
+ const Packet8f mask = _mm256_castsi256_ps(_mm256_setr_epi32(0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF));
+ return _mm256_and_ps(a,mask);
+}
+template<> EIGEN_STRONG_INLINE Packet4d pabs(const Packet4d& a)
+{
+ const Packet4d mask = _mm256_castsi256_pd(_mm256_setr_epi32(0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0x7FFFFFFF));
+ return _mm256_and_pd(a,mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pfrexp<Packet8f>(const Packet8f& a, Packet8f& exponent) {
+ return pfrexp_generic(a,exponent);
+}
+
+// Extract exponent without existence of Packet4l.
+template<>
+EIGEN_STRONG_INLINE
+Packet4d pfrexp_generic_get_biased_exponent(const Packet4d& a) {
+ const Packet4d cst_exp_mask = pset1frombits<Packet4d>(static_cast<uint64_t>(0x7ff0000000000000ull));
+ __m256i a_expo = _mm256_castpd_si256(pand(a, cst_exp_mask));
+#ifdef EIGEN_VECTORIZE_AVX2
+ a_expo = _mm256_srli_epi64(a_expo, 52);
+ __m128i lo = _mm256_extractf128_si256(a_expo, 0);
+ __m128i hi = _mm256_extractf128_si256(a_expo, 1);
+#else
+ __m128i lo = _mm256_extractf128_si256(a_expo, 0);
+ __m128i hi = _mm256_extractf128_si256(a_expo, 1);
+ lo = _mm_srli_epi64(lo, 52);
+ hi = _mm_srli_epi64(hi, 52);
+#endif
+ Packet2d exponent_lo = _mm_cvtepi32_pd(vec4i_swizzle1(lo, 0, 2, 1, 3));
+ Packet2d exponent_hi = _mm_cvtepi32_pd(vec4i_swizzle1(hi, 0, 2, 1, 3));
+ Packet4d exponent = _mm256_insertf128_pd(_mm256_setzero_pd(), exponent_lo, 0);
+ exponent = _mm256_insertf128_pd(exponent, exponent_hi, 1);
+ return exponent;
+}
+
+
+template<> EIGEN_STRONG_INLINE Packet4d pfrexp<Packet4d>(const Packet4d& a, Packet4d& exponent) {
+ return pfrexp_generic(a, exponent);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pldexp<Packet8f>(const Packet8f& a, const Packet8f& exponent) {
+ return pldexp_generic(a, exponent);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4d pldexp<Packet4d>(const Packet4d& a, const Packet4d& exponent) {
+ // Clamp exponent to [-2099, 2099]
+ const Packet4d max_exponent = pset1<Packet4d>(2099.0);
+ const Packet4i e = _mm256_cvtpd_epi32(pmin(pmax(exponent, pnegate(max_exponent)), max_exponent));
+
+ // Split 2^e into four factors and multiply.
+ const Packet4i bias = pset1<Packet4i>(1023);
+ Packet4i b = parithmetic_shift_right<2>(e); // floor(e/4)
+
+ // 2^b
+ Packet4i hi = vec4i_swizzle1(padd(b, bias), 0, 2, 1, 3);
+ Packet4i lo = _mm_slli_epi64(hi, 52);
+ hi = _mm_slli_epi64(_mm_srli_epi64(hi, 32), 52);
+ Packet4d c = _mm256_castsi256_pd(_mm256_insertf128_si256(_mm256_castsi128_si256(lo), hi, 1));
+ Packet4d out = pmul(pmul(pmul(a, c), c), c); // a * 2^(3b)
+
+ // 2^(e - 3b)
+ b = psub(psub(psub(e, b), b), b); // e - 3b
+ hi = vec4i_swizzle1(padd(b, bias), 0, 2, 1, 3);
+ lo = _mm_slli_epi64(hi, 52);
+ hi = _mm_slli_epi64(_mm_srli_epi64(hi, 32), 52);
+ c = _mm256_castsi256_pd(_mm256_insertf128_si256(_mm256_castsi128_si256(lo), hi, 1));
+ out = pmul(out, c); // a * 2^e
+ return out;
+}
+
+template<> EIGEN_STRONG_INLINE float predux<Packet8f>(const Packet8f& a)
+{
+ return predux(Packet4f(_mm_add_ps(_mm256_castps256_ps128(a),_mm256_extractf128_ps(a,1))));
+}
+template<> EIGEN_STRONG_INLINE double predux<Packet4d>(const Packet4d& a)
+{
+ return predux(Packet2d(_mm_add_pd(_mm256_castpd256_pd128(a),_mm256_extractf128_pd(a,1))));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f predux_half_dowto4<Packet8f>(const Packet8f& a)
+{
+ return _mm_add_ps(_mm256_castps256_ps128(a),_mm256_extractf128_ps(a,1));
+}
+
+template<> EIGEN_STRONG_INLINE float predux_mul<Packet8f>(const Packet8f& a)
+{
+ Packet8f tmp;
+ tmp = _mm256_mul_ps(a, _mm256_permute2f128_ps(a,a,1));
+ tmp = _mm256_mul_ps(tmp, _mm256_shuffle_ps(tmp,tmp,_MM_SHUFFLE(1,0,3,2)));
+ return pfirst(_mm256_mul_ps(tmp, _mm256_shuffle_ps(tmp,tmp,1)));
+}
+template<> EIGEN_STRONG_INLINE double predux_mul<Packet4d>(const Packet4d& a)
+{
+ Packet4d tmp;
+ tmp = _mm256_mul_pd(a, _mm256_permute2f128_pd(a,a,1));
+ return pfirst(_mm256_mul_pd(tmp, _mm256_shuffle_pd(tmp,tmp,1)));
+}
+
+template<> EIGEN_STRONG_INLINE float predux_min<Packet8f>(const Packet8f& a)
+{
+ Packet8f tmp = _mm256_min_ps(a, _mm256_permute2f128_ps(a,a,1));
+ tmp = _mm256_min_ps(tmp, _mm256_shuffle_ps(tmp,tmp,_MM_SHUFFLE(1,0,3,2)));
+ return pfirst(_mm256_min_ps(tmp, _mm256_shuffle_ps(tmp,tmp,1)));
+}
+template<> EIGEN_STRONG_INLINE double predux_min<Packet4d>(const Packet4d& a)
+{
+ Packet4d tmp = _mm256_min_pd(a, _mm256_permute2f128_pd(a,a,1));
+ return pfirst(_mm256_min_pd(tmp, _mm256_shuffle_pd(tmp, tmp, 1)));
+}
+
+template<> EIGEN_STRONG_INLINE float predux_max<Packet8f>(const Packet8f& a)
+{
+ Packet8f tmp = _mm256_max_ps(a, _mm256_permute2f128_ps(a,a,1));
+ tmp = _mm256_max_ps(tmp, _mm256_shuffle_ps(tmp,tmp,_MM_SHUFFLE(1,0,3,2)));
+ return pfirst(_mm256_max_ps(tmp, _mm256_shuffle_ps(tmp,tmp,1)));
+}
+
+template<> EIGEN_STRONG_INLINE double predux_max<Packet4d>(const Packet4d& a)
+{
+ Packet4d tmp = _mm256_max_pd(a, _mm256_permute2f128_pd(a,a,1));
+ return pfirst(_mm256_max_pd(tmp, _mm256_shuffle_pd(tmp, tmp, 1)));
+}
+
+// not needed yet
+// template<> EIGEN_STRONG_INLINE bool predux_all(const Packet8f& x)
+// {
+// return _mm256_movemask_ps(x)==0xFF;
+// }
+
+template<> EIGEN_STRONG_INLINE bool predux_any(const Packet8f& x)
+{
+ return _mm256_movemask_ps(x)!=0;
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet8f,8>& kernel) {
+ __m256 T0 = _mm256_unpacklo_ps(kernel.packet[0], kernel.packet[1]);
+ __m256 T1 = _mm256_unpackhi_ps(kernel.packet[0], kernel.packet[1]);
+ __m256 T2 = _mm256_unpacklo_ps(kernel.packet[2], kernel.packet[3]);
+ __m256 T3 = _mm256_unpackhi_ps(kernel.packet[2], kernel.packet[3]);
+ __m256 T4 = _mm256_unpacklo_ps(kernel.packet[4], kernel.packet[5]);
+ __m256 T5 = _mm256_unpackhi_ps(kernel.packet[4], kernel.packet[5]);
+ __m256 T6 = _mm256_unpacklo_ps(kernel.packet[6], kernel.packet[7]);
+ __m256 T7 = _mm256_unpackhi_ps(kernel.packet[6], kernel.packet[7]);
+ __m256 S0 = _mm256_shuffle_ps(T0,T2,_MM_SHUFFLE(1,0,1,0));
+ __m256 S1 = _mm256_shuffle_ps(T0,T2,_MM_SHUFFLE(3,2,3,2));
+ __m256 S2 = _mm256_shuffle_ps(T1,T3,_MM_SHUFFLE(1,0,1,0));
+ __m256 S3 = _mm256_shuffle_ps(T1,T3,_MM_SHUFFLE(3,2,3,2));
+ __m256 S4 = _mm256_shuffle_ps(T4,T6,_MM_SHUFFLE(1,0,1,0));
+ __m256 S5 = _mm256_shuffle_ps(T4,T6,_MM_SHUFFLE(3,2,3,2));
+ __m256 S6 = _mm256_shuffle_ps(T5,T7,_MM_SHUFFLE(1,0,1,0));
+ __m256 S7 = _mm256_shuffle_ps(T5,T7,_MM_SHUFFLE(3,2,3,2));
+ kernel.packet[0] = _mm256_permute2f128_ps(S0, S4, 0x20);
+ kernel.packet[1] = _mm256_permute2f128_ps(S1, S5, 0x20);
+ kernel.packet[2] = _mm256_permute2f128_ps(S2, S6, 0x20);
+ kernel.packet[3] = _mm256_permute2f128_ps(S3, S7, 0x20);
+ kernel.packet[4] = _mm256_permute2f128_ps(S0, S4, 0x31);
+ kernel.packet[5] = _mm256_permute2f128_ps(S1, S5, 0x31);
+ kernel.packet[6] = _mm256_permute2f128_ps(S2, S6, 0x31);
+ kernel.packet[7] = _mm256_permute2f128_ps(S3, S7, 0x31);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet8f,4>& kernel) {
+ __m256 T0 = _mm256_unpacklo_ps(kernel.packet[0], kernel.packet[1]);
+ __m256 T1 = _mm256_unpackhi_ps(kernel.packet[0], kernel.packet[1]);
+ __m256 T2 = _mm256_unpacklo_ps(kernel.packet[2], kernel.packet[3]);
+ __m256 T3 = _mm256_unpackhi_ps(kernel.packet[2], kernel.packet[3]);
+
+ __m256 S0 = _mm256_shuffle_ps(T0,T2,_MM_SHUFFLE(1,0,1,0));
+ __m256 S1 = _mm256_shuffle_ps(T0,T2,_MM_SHUFFLE(3,2,3,2));
+ __m256 S2 = _mm256_shuffle_ps(T1,T3,_MM_SHUFFLE(1,0,1,0));
+ __m256 S3 = _mm256_shuffle_ps(T1,T3,_MM_SHUFFLE(3,2,3,2));
+
+ kernel.packet[0] = _mm256_permute2f128_ps(S0, S1, 0x20);
+ kernel.packet[1] = _mm256_permute2f128_ps(S2, S3, 0x20);
+ kernel.packet[2] = _mm256_permute2f128_ps(S0, S1, 0x31);
+ kernel.packet[3] = _mm256_permute2f128_ps(S2, S3, 0x31);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet4d,4>& kernel) {
+ __m256d T0 = _mm256_shuffle_pd(kernel.packet[0], kernel.packet[1], 15);
+ __m256d T1 = _mm256_shuffle_pd(kernel.packet[0], kernel.packet[1], 0);
+ __m256d T2 = _mm256_shuffle_pd(kernel.packet[2], kernel.packet[3], 15);
+ __m256d T3 = _mm256_shuffle_pd(kernel.packet[2], kernel.packet[3], 0);
+
+ kernel.packet[1] = _mm256_permute2f128_pd(T0, T2, 32);
+ kernel.packet[3] = _mm256_permute2f128_pd(T0, T2, 49);
+ kernel.packet[0] = _mm256_permute2f128_pd(T1, T3, 32);
+ kernel.packet[2] = _mm256_permute2f128_pd(T1, T3, 49);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pblend(const Selector<8>& ifPacket, const Packet8f& thenPacket, const Packet8f& elsePacket) {
+ const __m256 zero = _mm256_setzero_ps();
+ const __m256 select = _mm256_set_ps(ifPacket.select[7], ifPacket.select[6], ifPacket.select[5], ifPacket.select[4], ifPacket.select[3], ifPacket.select[2], ifPacket.select[1], ifPacket.select[0]);
+ __m256 false_mask = _mm256_cmp_ps(select, zero, _CMP_EQ_UQ);
+ return _mm256_blendv_ps(thenPacket, elsePacket, false_mask);
+}
+template<> EIGEN_STRONG_INLINE Packet4d pblend(const Selector<4>& ifPacket, const Packet4d& thenPacket, const Packet4d& elsePacket) {
+ const __m256d zero = _mm256_setzero_pd();
+ const __m256d select = _mm256_set_pd(ifPacket.select[3], ifPacket.select[2], ifPacket.select[1], ifPacket.select[0]);
+ __m256d false_mask = _mm256_cmp_pd(select, zero, _CMP_EQ_UQ);
+ return _mm256_blendv_pd(thenPacket, elsePacket, false_mask);
+}
+
+// Packet math for Eigen::half
+
+template<> struct unpacket_traits<Packet8h> { typedef Eigen::half type; enum {size=8, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet8h half; };
+
+template<> EIGEN_STRONG_INLINE Packet8h pset1<Packet8h>(const Eigen::half& from) {
+ return _mm_set1_epi16(numext::bit_cast<numext::uint16_t>(from));
+}
+
+template<> EIGEN_STRONG_INLINE Eigen::half pfirst<Packet8h>(const Packet8h& from) {
+ return numext::bit_cast<Eigen::half>(static_cast<numext::uint16_t>(_mm_extract_epi16(from, 0)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pload<Packet8h>(const Eigen::half* from) {
+ return _mm_load_si128(reinterpret_cast<const __m128i*>(from));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h ploadu<Packet8h>(const Eigen::half* from) {
+ return _mm_loadu_si128(reinterpret_cast<const __m128i*>(from));
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<Eigen::half>(Eigen::half* to, const Packet8h& from) {
+ _mm_store_si128(reinterpret_cast<__m128i*>(to), from);
+}
+
+template<> EIGEN_STRONG_INLINE void pstoreu<Eigen::half>(Eigen::half* to, const Packet8h& from) {
+ _mm_storeu_si128(reinterpret_cast<__m128i*>(to), from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h
+ploaddup<Packet8h>(const Eigen::half* from) {
+ const numext::uint16_t a = numext::bit_cast<numext::uint16_t>(from[0]);
+ const numext::uint16_t b = numext::bit_cast<numext::uint16_t>(from[1]);
+ const numext::uint16_t c = numext::bit_cast<numext::uint16_t>(from[2]);
+ const numext::uint16_t d = numext::bit_cast<numext::uint16_t>(from[3]);
+ return _mm_set_epi16(d, d, c, c, b, b, a, a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h
+ploadquad<Packet8h>(const Eigen::half* from) {
+ const numext::uint16_t a = numext::bit_cast<numext::uint16_t>(from[0]);
+ const numext::uint16_t b = numext::bit_cast<numext::uint16_t>(from[1]);
+ return _mm_set_epi16(b, b, b, b, a, a, a, a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h ptrue(const Packet8h& a) {
+ return _mm_cmpeq_epi32(a, a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8h pabs(const Packet8h& a) {
+ const __m128i sign_mask = _mm_set1_epi16(static_cast<numext::uint16_t>(0x8000));
+ return _mm_andnot_si128(sign_mask, a);
+}
+
+EIGEN_STRONG_INLINE Packet8f half2float(const Packet8h& a) {
+#ifdef EIGEN_HAS_FP16_C
+ return _mm256_cvtph_ps(a);
+#else
+ EIGEN_ALIGN32 Eigen::half aux[8];
+ pstore(aux, a);
+ float f0(aux[0]);
+ float f1(aux[1]);
+ float f2(aux[2]);
+ float f3(aux[3]);
+ float f4(aux[4]);
+ float f5(aux[5]);
+ float f6(aux[6]);
+ float f7(aux[7]);
+
+ return _mm256_set_ps(f7, f6, f5, f4, f3, f2, f1, f0);
+#endif
+}
+
+EIGEN_STRONG_INLINE Packet8h float2half(const Packet8f& a) {
+#ifdef EIGEN_HAS_FP16_C
+ return _mm256_cvtps_ph(a, _MM_FROUND_TO_NEAREST_INT|_MM_FROUND_NO_EXC);
+#else
+ EIGEN_ALIGN32 float aux[8];
+ pstore(aux, a);
+ const numext::uint16_t s0 = numext::bit_cast<numext::uint16_t>(Eigen::half(aux[0]));
+ const numext::uint16_t s1 = numext::bit_cast<numext::uint16_t>(Eigen::half(aux[1]));
+ const numext::uint16_t s2 = numext::bit_cast<numext::uint16_t>(Eigen::half(aux[2]));
+ const numext::uint16_t s3 = numext::bit_cast<numext::uint16_t>(Eigen::half(aux[3]));
+ const numext::uint16_t s4 = numext::bit_cast<numext::uint16_t>(Eigen::half(aux[4]));
+ const numext::uint16_t s5 = numext::bit_cast<numext::uint16_t>(Eigen::half(aux[5]));
+ const numext::uint16_t s6 = numext::bit_cast<numext::uint16_t>(Eigen::half(aux[6]));
+ const numext::uint16_t s7 = numext::bit_cast<numext::uint16_t>(Eigen::half(aux[7]));
+ return _mm_set_epi16(s7, s6, s5, s4, s3, s2, s1, s0);
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8h pmin<Packet8h>(const Packet8h& a,
+ const Packet8h& b) {
+ return float2half(pmin<Packet8f>(half2float(a), half2float(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8h pmax<Packet8h>(const Packet8h& a,
+ const Packet8h& b) {
+ return float2half(pmax<Packet8f>(half2float(a), half2float(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8h plset<Packet8h>(const half& a) {
+ return float2half(plset<Packet8f>(static_cast<float>(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h por(const Packet8h& a,const Packet8h& b) {
+ // in some cases Packet4i is a wrapper around __m128i, so we either need to
+ // cast to Packet4i to directly call the intrinsics as below:
+ return _mm_or_si128(a,b);
+}
+template<> EIGEN_STRONG_INLINE Packet8h pxor(const Packet8h& a,const Packet8h& b) {
+ return _mm_xor_si128(a,b);
+}
+template<> EIGEN_STRONG_INLINE Packet8h pand(const Packet8h& a,const Packet8h& b) {
+ return _mm_and_si128(a,b);
+}
+template<> EIGEN_STRONG_INLINE Packet8h pandnot(const Packet8h& a,const Packet8h& b) {
+ return _mm_andnot_si128(b,a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pselect(const Packet8h& mask, const Packet8h& a, const Packet8h& b) {
+ return _mm_blendv_epi8(b, a, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pround<Packet8h>(const Packet8h& a) {
+ return float2half(pround<Packet8f>(half2float(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h print<Packet8h>(const Packet8h& a) {
+ return float2half(print<Packet8f>(half2float(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pceil<Packet8h>(const Packet8h& a) {
+ return float2half(pceil<Packet8f>(half2float(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pfloor<Packet8h>(const Packet8h& a) {
+ return float2half(pfloor<Packet8f>(half2float(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pcmp_eq(const Packet8h& a,const Packet8h& b) {
+ return Pack16To8(pcmp_eq(half2float(a), half2float(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pcmp_le(const Packet8h& a,const Packet8h& b) {
+ return Pack16To8(pcmp_le(half2float(a), half2float(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pcmp_lt(const Packet8h& a,const Packet8h& b) {
+ return Pack16To8(pcmp_lt(half2float(a), half2float(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pcmp_lt_or_nan(const Packet8h& a,const Packet8h& b) {
+ return Pack16To8(pcmp_lt_or_nan(half2float(a), half2float(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pconj(const Packet8h& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet8h pnegate(const Packet8h& a) {
+ Packet8h sign_mask = _mm_set1_epi16(static_cast<numext::uint16_t>(0x8000));
+ return _mm_xor_si128(a, sign_mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h padd<Packet8h>(const Packet8h& a, const Packet8h& b) {
+ Packet8f af = half2float(a);
+ Packet8f bf = half2float(b);
+ Packet8f rf = padd(af, bf);
+ return float2half(rf);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h psub<Packet8h>(const Packet8h& a, const Packet8h& b) {
+ Packet8f af = half2float(a);
+ Packet8f bf = half2float(b);
+ Packet8f rf = psub(af, bf);
+ return float2half(rf);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pmul<Packet8h>(const Packet8h& a, const Packet8h& b) {
+ Packet8f af = half2float(a);
+ Packet8f bf = half2float(b);
+ Packet8f rf = pmul(af, bf);
+ return float2half(rf);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pdiv<Packet8h>(const Packet8h& a, const Packet8h& b) {
+ Packet8f af = half2float(a);
+ Packet8f bf = half2float(b);
+ Packet8f rf = pdiv(af, bf);
+ return float2half(rf);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pgather<Eigen::half, Packet8h>(const Eigen::half* from, Index stride)
+{
+ const numext::uint16_t s0 = numext::bit_cast<numext::uint16_t>(from[0*stride]);
+ const numext::uint16_t s1 = numext::bit_cast<numext::uint16_t>(from[1*stride]);
+ const numext::uint16_t s2 = numext::bit_cast<numext::uint16_t>(from[2*stride]);
+ const numext::uint16_t s3 = numext::bit_cast<numext::uint16_t>(from[3*stride]);
+ const numext::uint16_t s4 = numext::bit_cast<numext::uint16_t>(from[4*stride]);
+ const numext::uint16_t s5 = numext::bit_cast<numext::uint16_t>(from[5*stride]);
+ const numext::uint16_t s6 = numext::bit_cast<numext::uint16_t>(from[6*stride]);
+ const numext::uint16_t s7 = numext::bit_cast<numext::uint16_t>(from[7*stride]);
+ return _mm_set_epi16(s7, s6, s5, s4, s3, s2, s1, s0);
+}
+
+template<> EIGEN_STRONG_INLINE void pscatter<Eigen::half, Packet8h>(Eigen::half* to, const Packet8h& from, Index stride)
+{
+ EIGEN_ALIGN32 Eigen::half aux[8];
+ pstore(aux, from);
+ to[stride*0] = aux[0];
+ to[stride*1] = aux[1];
+ to[stride*2] = aux[2];
+ to[stride*3] = aux[3];
+ to[stride*4] = aux[4];
+ to[stride*5] = aux[5];
+ to[stride*6] = aux[6];
+ to[stride*7] = aux[7];
+}
+
+template<> EIGEN_STRONG_INLINE Eigen::half predux<Packet8h>(const Packet8h& a) {
+ Packet8f af = half2float(a);
+ float reduced = predux<Packet8f>(af);
+ return Eigen::half(reduced);
+}
+
+template<> EIGEN_STRONG_INLINE Eigen::half predux_max<Packet8h>(const Packet8h& a) {
+ Packet8f af = half2float(a);
+ float reduced = predux_max<Packet8f>(af);
+ return Eigen::half(reduced);
+}
+
+template<> EIGEN_STRONG_INLINE Eigen::half predux_min<Packet8h>(const Packet8h& a) {
+ Packet8f af = half2float(a);
+ float reduced = predux_min<Packet8f>(af);
+ return Eigen::half(reduced);
+}
+
+template<> EIGEN_STRONG_INLINE Eigen::half predux_mul<Packet8h>(const Packet8h& a) {
+ Packet8f af = half2float(a);
+ float reduced = predux_mul<Packet8f>(af);
+ return Eigen::half(reduced);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h preverse(const Packet8h& a)
+{
+ __m128i m = _mm_setr_epi8(14,15,12,13,10,11,8,9,6,7,4,5,2,3,0,1);
+ return _mm_shuffle_epi8(a,m);
+}
+
+EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet8h,8>& kernel) {
+ __m128i a = kernel.packet[0];
+ __m128i b = kernel.packet[1];
+ __m128i c = kernel.packet[2];
+ __m128i d = kernel.packet[3];
+ __m128i e = kernel.packet[4];
+ __m128i f = kernel.packet[5];
+ __m128i g = kernel.packet[6];
+ __m128i h = kernel.packet[7];
+
+ __m128i a03b03 = _mm_unpacklo_epi16(a, b);
+ __m128i c03d03 = _mm_unpacklo_epi16(c, d);
+ __m128i e03f03 = _mm_unpacklo_epi16(e, f);
+ __m128i g03h03 = _mm_unpacklo_epi16(g, h);
+ __m128i a47b47 = _mm_unpackhi_epi16(a, b);
+ __m128i c47d47 = _mm_unpackhi_epi16(c, d);
+ __m128i e47f47 = _mm_unpackhi_epi16(e, f);
+ __m128i g47h47 = _mm_unpackhi_epi16(g, h);
+
+ __m128i a01b01c01d01 = _mm_unpacklo_epi32(a03b03, c03d03);
+ __m128i a23b23c23d23 = _mm_unpackhi_epi32(a03b03, c03d03);
+ __m128i e01f01g01h01 = _mm_unpacklo_epi32(e03f03, g03h03);
+ __m128i e23f23g23h23 = _mm_unpackhi_epi32(e03f03, g03h03);
+ __m128i a45b45c45d45 = _mm_unpacklo_epi32(a47b47, c47d47);
+ __m128i a67b67c67d67 = _mm_unpackhi_epi32(a47b47, c47d47);
+ __m128i e45f45g45h45 = _mm_unpacklo_epi32(e47f47, g47h47);
+ __m128i e67f67g67h67 = _mm_unpackhi_epi32(e47f47, g47h47);
+
+ __m128i a0b0c0d0e0f0g0h0 = _mm_unpacklo_epi64(a01b01c01d01, e01f01g01h01);
+ __m128i a1b1c1d1e1f1g1h1 = _mm_unpackhi_epi64(a01b01c01d01, e01f01g01h01);
+ __m128i a2b2c2d2e2f2g2h2 = _mm_unpacklo_epi64(a23b23c23d23, e23f23g23h23);
+ __m128i a3b3c3d3e3f3g3h3 = _mm_unpackhi_epi64(a23b23c23d23, e23f23g23h23);
+ __m128i a4b4c4d4e4f4g4h4 = _mm_unpacklo_epi64(a45b45c45d45, e45f45g45h45);
+ __m128i a5b5c5d5e5f5g5h5 = _mm_unpackhi_epi64(a45b45c45d45, e45f45g45h45);
+ __m128i a6b6c6d6e6f6g6h6 = _mm_unpacklo_epi64(a67b67c67d67, e67f67g67h67);
+ __m128i a7b7c7d7e7f7g7h7 = _mm_unpackhi_epi64(a67b67c67d67, e67f67g67h67);
+
+ kernel.packet[0] = a0b0c0d0e0f0g0h0;
+ kernel.packet[1] = a1b1c1d1e1f1g1h1;
+ kernel.packet[2] = a2b2c2d2e2f2g2h2;
+ kernel.packet[3] = a3b3c3d3e3f3g3h3;
+ kernel.packet[4] = a4b4c4d4e4f4g4h4;
+ kernel.packet[5] = a5b5c5d5e5f5g5h5;
+ kernel.packet[6] = a6b6c6d6e6f6g6h6;
+ kernel.packet[7] = a7b7c7d7e7f7g7h7;
+}
+
+EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet8h,4>& kernel) {
+ EIGEN_ALIGN32 Eigen::half in[4][8];
+ pstore<Eigen::half>(in[0], kernel.packet[0]);
+ pstore<Eigen::half>(in[1], kernel.packet[1]);
+ pstore<Eigen::half>(in[2], kernel.packet[2]);
+ pstore<Eigen::half>(in[3], kernel.packet[3]);
+
+ EIGEN_ALIGN32 Eigen::half out[4][8];
+
+ for (int i = 0; i < 4; ++i) {
+ for (int j = 0; j < 4; ++j) {
+ out[i][j] = in[j][2*i];
+ }
+ for (int j = 0; j < 4; ++j) {
+ out[i][j+4] = in[j][2*i+1];
+ }
+ }
+
+ kernel.packet[0] = pload<Packet8h>(out[0]);
+ kernel.packet[1] = pload<Packet8h>(out[1]);
+ kernel.packet[2] = pload<Packet8h>(out[2]);
+ kernel.packet[3] = pload<Packet8h>(out[3]);
+}
+
+// BFloat16 implementation.
+
+EIGEN_STRONG_INLINE Packet8f Bf16ToF32(const Packet8bf& a) {
+#ifdef EIGEN_VECTORIZE_AVX2
+ __m256i extend = _mm256_cvtepu16_epi32(a);
+ return _mm256_castsi256_ps(_mm256_slli_epi32(extend, 16));
+#else
+ __m128i lo = _mm_cvtepu16_epi32(a);
+ __m128i hi = _mm_cvtepu16_epi32(_mm_srli_si128(a, 8));
+ __m128i lo_shift = _mm_slli_epi32(lo, 16);
+ __m128i hi_shift = _mm_slli_epi32(hi, 16);
+ return _mm256_castsi256_ps(_mm256_insertf128_si256(_mm256_castsi128_si256(lo_shift), hi_shift, 1));
+#endif
+}
+
+// Convert float to bfloat16 according to round-to-nearest-even/denormals algorithm.
+EIGEN_STRONG_INLINE Packet8bf F32ToBf16(const Packet8f& a) {
+ Packet8bf r;
+
+ __m256i input = _mm256_castps_si256(a);
+
+#ifdef EIGEN_VECTORIZE_AVX2
+ // uint32_t lsb = (input >> 16);
+ __m256i t = _mm256_srli_epi32(input, 16);
+ // uint32_t lsb = lsb & 1;
+ t = _mm256_and_si256(t, _mm256_set1_epi32(1));
+ // uint32_t rounding_bias = 0x7fff + lsb;
+ t = _mm256_add_epi32(t, _mm256_set1_epi32(0x7fff));
+ // input += rounding_bias;
+ t = _mm256_add_epi32(t, input);
+ // input = input >> 16;
+ t = _mm256_srli_epi32(t, 16);
+ // Check NaN before converting back to bf16
+ __m256 mask = _mm256_cmp_ps(a, a, _CMP_ORD_Q);
+ __m256i nan = _mm256_set1_epi32(0x7fc0);
+ t = _mm256_blendv_epi8(nan, t, _mm256_castps_si256(mask));
+ // output = numext::bit_cast<uint16_t>(input);
+ return _mm_packus_epi32(_mm256_extractf128_si256(t, 0),
+ _mm256_extractf128_si256(t, 1));
+#else
+ // uint32_t lsb = (input >> 16);
+ __m128i lo = _mm_srli_epi32(_mm256_extractf128_si256(input, 0), 16);
+ __m128i hi = _mm_srli_epi32(_mm256_extractf128_si256(input, 1), 16);
+ // uint32_t lsb = lsb & 1;
+ lo = _mm_and_si128(lo, _mm_set1_epi32(1));
+ hi = _mm_and_si128(hi, _mm_set1_epi32(1));
+ // uint32_t rounding_bias = 0x7fff + lsb;
+ lo = _mm_add_epi32(lo, _mm_set1_epi32(0x7fff));
+ hi = _mm_add_epi32(hi, _mm_set1_epi32(0x7fff));
+ // input += rounding_bias;
+ lo = _mm_add_epi32(lo, _mm256_extractf128_si256(input, 0));
+ hi = _mm_add_epi32(hi, _mm256_extractf128_si256(input, 1));
+ // input = input >> 16;
+ lo = _mm_srli_epi32(lo, 16);
+ hi = _mm_srli_epi32(hi, 16);
+ // Check NaN before converting back to bf16
+ __m256 mask = _mm256_cmp_ps(a, a, _CMP_ORD_Q);
+ __m128i nan = _mm_set1_epi32(0x7fc0);
+ lo = _mm_blendv_epi8(nan, lo, _mm_castps_si128(_mm256_castps256_ps128(mask)));
+ hi = _mm_blendv_epi8(nan, hi, _mm_castps_si128(_mm256_extractf128_ps(mask, 1)));
+ // output = numext::bit_cast<uint16_t>(input);
+ return _mm_packus_epi32(lo, hi);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pset1<Packet8bf>(const bfloat16& from) {
+ return _mm_set1_epi16(numext::bit_cast<numext::uint16_t>(from));
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 pfirst<Packet8bf>(const Packet8bf& from) {
+ return numext::bit_cast<bfloat16>(static_cast<numext::uint16_t>(_mm_extract_epi16(from, 0)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pload<Packet8bf>(const bfloat16* from) {
+ return _mm_load_si128(reinterpret_cast<const __m128i*>(from));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf ploadu<Packet8bf>(const bfloat16* from) {
+ return _mm_loadu_si128(reinterpret_cast<const __m128i*>(from));
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<bfloat16>(bfloat16* to, const Packet8bf& from) {
+ _mm_store_si128(reinterpret_cast<__m128i*>(to), from);
+}
+
+template<> EIGEN_STRONG_INLINE void pstoreu<bfloat16>(bfloat16* to, const Packet8bf& from) {
+ _mm_storeu_si128(reinterpret_cast<__m128i*>(to), from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf
+ploaddup<Packet8bf>(const bfloat16* from) {
+ const numext::uint16_t a = numext::bit_cast<numext::uint16_t>(from[0]);
+ const numext::uint16_t b = numext::bit_cast<numext::uint16_t>(from[1]);
+ const numext::uint16_t c = numext::bit_cast<numext::uint16_t>(from[2]);
+ const numext::uint16_t d = numext::bit_cast<numext::uint16_t>(from[3]);
+ return _mm_set_epi16(d, d, c, c, b, b, a, a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf
+ploadquad<Packet8bf>(const bfloat16* from) {
+ const numext::uint16_t a = numext::bit_cast<numext::uint16_t>(from[0]);
+ const numext::uint16_t b = numext::bit_cast<numext::uint16_t>(from[1]);
+ return _mm_set_epi16(b, b, b, b, a, a, a, a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf ptrue(const Packet8bf& a) {
+ return _mm_cmpeq_epi32(a, a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8bf pabs(const Packet8bf& a) {
+ const __m128i sign_mask = _mm_set1_epi16(static_cast<numext::uint16_t>(0x8000));
+ return _mm_andnot_si128(sign_mask, a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8bf pmin<Packet8bf>(const Packet8bf& a,
+ const Packet8bf& b) {
+ return F32ToBf16(pmin<Packet8f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8bf pmax<Packet8bf>(const Packet8bf& a,
+ const Packet8bf& b) {
+ return F32ToBf16(pmax<Packet8f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8bf plset<Packet8bf>(const bfloat16& a) {
+ return F32ToBf16(plset<Packet8f>(static_cast<float>(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf por(const Packet8bf& a,const Packet8bf& b) {
+ return _mm_or_si128(a,b);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pxor(const Packet8bf& a,const Packet8bf& b) {
+ return _mm_xor_si128(a,b);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pand(const Packet8bf& a,const Packet8bf& b) {
+ return _mm_and_si128(a,b);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pandnot(const Packet8bf& a,const Packet8bf& b) {
+ return _mm_andnot_si128(b,a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pselect(const Packet8bf& mask, const Packet8bf& a, const Packet8bf& b) {
+ return _mm_blendv_epi8(b, a, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pround<Packet8bf>(const Packet8bf& a)
+{
+ return F32ToBf16(pround<Packet8f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf print<Packet8bf>(const Packet8bf& a) {
+ return F32ToBf16(print<Packet8f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pceil<Packet8bf>(const Packet8bf& a) {
+ return F32ToBf16(pceil<Packet8f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pfloor<Packet8bf>(const Packet8bf& a) {
+ return F32ToBf16(pfloor<Packet8f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pcmp_eq(const Packet8bf& a,const Packet8bf& b) {
+ return Pack16To8(pcmp_eq(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pcmp_le(const Packet8bf& a,const Packet8bf& b) {
+ return Pack16To8(pcmp_le(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pcmp_lt(const Packet8bf& a,const Packet8bf& b) {
+ return Pack16To8(pcmp_lt(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pcmp_lt_or_nan(const Packet8bf& a,const Packet8bf& b) {
+ return Pack16To8(pcmp_lt_or_nan(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pconj(const Packet8bf& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet8bf pnegate(const Packet8bf& a) {
+ Packet8bf sign_mask = _mm_set1_epi16(static_cast<numext::uint16_t>(0x8000));
+ return _mm_xor_si128(a, sign_mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf padd<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ return F32ToBf16(padd<Packet8f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf psub<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ return F32ToBf16(psub<Packet8f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pmul<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ return F32ToBf16(pmul<Packet8f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pdiv<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ return F32ToBf16(pdiv<Packet8f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+
+template<> EIGEN_STRONG_INLINE Packet8bf pgather<bfloat16, Packet8bf>(const bfloat16* from, Index stride)
+{
+ const numext::uint16_t s0 = numext::bit_cast<numext::uint16_t>(from[0*stride]);
+ const numext::uint16_t s1 = numext::bit_cast<numext::uint16_t>(from[1*stride]);
+ const numext::uint16_t s2 = numext::bit_cast<numext::uint16_t>(from[2*stride]);
+ const numext::uint16_t s3 = numext::bit_cast<numext::uint16_t>(from[3*stride]);
+ const numext::uint16_t s4 = numext::bit_cast<numext::uint16_t>(from[4*stride]);
+ const numext::uint16_t s5 = numext::bit_cast<numext::uint16_t>(from[5*stride]);
+ const numext::uint16_t s6 = numext::bit_cast<numext::uint16_t>(from[6*stride]);
+ const numext::uint16_t s7 = numext::bit_cast<numext::uint16_t>(from[7*stride]);
+ return _mm_set_epi16(s7, s6, s5, s4, s3, s2, s1, s0);
+}
+
+template<> EIGEN_STRONG_INLINE void pscatter<bfloat16, Packet8bf>(bfloat16* to, const Packet8bf& from, Index stride)
+{
+ EIGEN_ALIGN32 bfloat16 aux[8];
+ pstore(aux, from);
+ to[stride*0] = aux[0];
+ to[stride*1] = aux[1];
+ to[stride*2] = aux[2];
+ to[stride*3] = aux[3];
+ to[stride*4] = aux[4];
+ to[stride*5] = aux[5];
+ to[stride*6] = aux[6];
+ to[stride*7] = aux[7];
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux<Packet8bf>(const Packet8bf& a) {
+ return static_cast<bfloat16>(predux<Packet8f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux_max<Packet8bf>(const Packet8bf& a) {
+ return static_cast<bfloat16>(predux_max<Packet8f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux_min<Packet8bf>(const Packet8bf& a) {
+ return static_cast<bfloat16>(predux_min<Packet8f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux_mul<Packet8bf>(const Packet8bf& a) {
+ return static_cast<bfloat16>(predux_mul<Packet8f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf preverse(const Packet8bf& a)
+{
+ __m128i m = _mm_setr_epi8(14,15,12,13,10,11,8,9,6,7,4,5,2,3,0,1);
+ return _mm_shuffle_epi8(a,m);
+}
+
+EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet8bf,8>& kernel) {
+ __m128i a = kernel.packet[0];
+ __m128i b = kernel.packet[1];
+ __m128i c = kernel.packet[2];
+ __m128i d = kernel.packet[3];
+ __m128i e = kernel.packet[4];
+ __m128i f = kernel.packet[5];
+ __m128i g = kernel.packet[6];
+ __m128i h = kernel.packet[7];
+
+ __m128i a03b03 = _mm_unpacklo_epi16(a, b);
+ __m128i c03d03 = _mm_unpacklo_epi16(c, d);
+ __m128i e03f03 = _mm_unpacklo_epi16(e, f);
+ __m128i g03h03 = _mm_unpacklo_epi16(g, h);
+ __m128i a47b47 = _mm_unpackhi_epi16(a, b);
+ __m128i c47d47 = _mm_unpackhi_epi16(c, d);
+ __m128i e47f47 = _mm_unpackhi_epi16(e, f);
+ __m128i g47h47 = _mm_unpackhi_epi16(g, h);
+
+ __m128i a01b01c01d01 = _mm_unpacklo_epi32(a03b03, c03d03);
+ __m128i a23b23c23d23 = _mm_unpackhi_epi32(a03b03, c03d03);
+ __m128i e01f01g01h01 = _mm_unpacklo_epi32(e03f03, g03h03);
+ __m128i e23f23g23h23 = _mm_unpackhi_epi32(e03f03, g03h03);
+ __m128i a45b45c45d45 = _mm_unpacklo_epi32(a47b47, c47d47);
+ __m128i a67b67c67d67 = _mm_unpackhi_epi32(a47b47, c47d47);
+ __m128i e45f45g45h45 = _mm_unpacklo_epi32(e47f47, g47h47);
+ __m128i e67f67g67h67 = _mm_unpackhi_epi32(e47f47, g47h47);
+
+ kernel.packet[0] = _mm_unpacklo_epi64(a01b01c01d01, e01f01g01h01);
+ kernel.packet[1] = _mm_unpackhi_epi64(a01b01c01d01, e01f01g01h01);
+ kernel.packet[2] = _mm_unpacklo_epi64(a23b23c23d23, e23f23g23h23);
+ kernel.packet[3] = _mm_unpackhi_epi64(a23b23c23d23, e23f23g23h23);
+ kernel.packet[4] = _mm_unpacklo_epi64(a45b45c45d45, e45f45g45h45);
+ kernel.packet[5] = _mm_unpackhi_epi64(a45b45c45d45, e45f45g45h45);
+ kernel.packet[6] = _mm_unpacklo_epi64(a67b67c67d67, e67f67g67h67);
+ kernel.packet[7] = _mm_unpackhi_epi64(a67b67c67d67, e67f67g67h67);
+}
+
+EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet8bf,4>& kernel) {
+ __m128i a = kernel.packet[0];
+ __m128i b = kernel.packet[1];
+ __m128i c = kernel.packet[2];
+ __m128i d = kernel.packet[3];
+
+ __m128i ab_03 = _mm_unpacklo_epi16(a, b);
+ __m128i cd_03 = _mm_unpacklo_epi16(c, d);
+ __m128i ab_47 = _mm_unpackhi_epi16(a, b);
+ __m128i cd_47 = _mm_unpackhi_epi16(c, d);
+
+ kernel.packet[0] = _mm_unpacklo_epi32(ab_03, cd_03);
+ kernel.packet[1] = _mm_unpackhi_epi32(ab_03, cd_03);
+ kernel.packet[2] = _mm_unpacklo_epi32(ab_47, cd_47);
+ kernel.packet[3] = _mm_unpackhi_epi32(ab_47, cd_47);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PACKET_MATH_AVX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h
new file mode 100644
index 000000000..d507fb67b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h
@@ -0,0 +1,115 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TYPE_CASTING_AVX_H
+#define EIGEN_TYPE_CASTING_AVX_H
+
+namespace Eigen {
+
+namespace internal {
+
+// For now we use SSE to handle integers, so we can't use AVX instructions to cast
+// from int to float
+template <>
+struct type_casting_traits<float, int> {
+ enum {
+ VectorizedCast = 0,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template <>
+struct type_casting_traits<int, float> {
+ enum {
+ VectorizedCast = 0,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+
+#ifndef EIGEN_VECTORIZE_AVX512
+
+template <>
+struct type_casting_traits<Eigen::half, float> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+
+template <>
+struct type_casting_traits<float, Eigen::half> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template <>
+struct type_casting_traits<bfloat16, float> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template <>
+struct type_casting_traits<float, bfloat16> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+#endif // EIGEN_VECTORIZE_AVX512
+
+template<> EIGEN_STRONG_INLINE Packet8i pcast<Packet8f, Packet8i>(const Packet8f& a) {
+ return _mm256_cvttps_epi32(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pcast<Packet8i, Packet8f>(const Packet8i& a) {
+ return _mm256_cvtepi32_ps(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8i preinterpret<Packet8i,Packet8f>(const Packet8f& a) {
+ return _mm256_castps_si256(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f preinterpret<Packet8f,Packet8i>(const Packet8i& a) {
+ return _mm256_castsi256_ps(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pcast<Packet8h, Packet8f>(const Packet8h& a) {
+ return half2float(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8f pcast<Packet8bf, Packet8f>(const Packet8bf& a) {
+ return Bf16ToF32(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8h pcast<Packet8f, Packet8h>(const Packet8f& a) {
+ return float2half(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pcast<Packet8f, Packet8bf>(const Packet8f& a) {
+ return F32ToBf16(a);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TYPE_CASTING_AVX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/Complex.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/Complex.h
new file mode 100644
index 000000000..49c72b3f1
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/Complex.h
@@ -0,0 +1,422 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2018 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMPLEX_AVX512_H
+#define EIGEN_COMPLEX_AVX512_H
+
+namespace Eigen {
+
+namespace internal {
+
+//---------- float ----------
+struct Packet8cf
+{
+ EIGEN_STRONG_INLINE Packet8cf() {}
+ EIGEN_STRONG_INLINE explicit Packet8cf(const __m512& a) : v(a) {}
+ __m512 v;
+};
+
+template<> struct packet_traits<std::complex<float> > : default_packet_traits
+{
+ typedef Packet8cf type;
+ typedef Packet4cf half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 8,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasSqrt = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0
+ };
+};
+
+template<> struct unpacket_traits<Packet8cf> {
+ typedef std::complex<float> type;
+ typedef Packet4cf half;
+ typedef Packet16f as_real;
+ enum {
+ size = 8,
+ alignment=unpacket_traits<Packet16f>::alignment,
+ vectorizable=true,
+ masked_load_available=false,
+ masked_store_available=false
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet8cf ptrue<Packet8cf>(const Packet8cf& a) { return Packet8cf(ptrue(Packet16f(a.v))); }
+template<> EIGEN_STRONG_INLINE Packet8cf padd<Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(_mm512_add_ps(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet8cf psub<Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(_mm512_sub_ps(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet8cf pnegate(const Packet8cf& a)
+{
+ return Packet8cf(pnegate(a.v));
+}
+template<> EIGEN_STRONG_INLINE Packet8cf pconj(const Packet8cf& a)
+{
+ const __m512 mask = _mm512_castsi512_ps(_mm512_setr_epi32(
+ 0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000,
+ 0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000,0x00000000,0x80000000));
+ return Packet8cf(pxor(a.v,mask));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8cf pmul<Packet8cf>(const Packet8cf& a, const Packet8cf& b)
+{
+ __m512 tmp2 = _mm512_mul_ps(_mm512_movehdup_ps(a.v), _mm512_permute_ps(b.v, _MM_SHUFFLE(2,3,0,1)));
+ return Packet8cf(_mm512_fmaddsub_ps(_mm512_moveldup_ps(a.v), b.v, tmp2));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8cf pand <Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(pand(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet8cf por <Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(por(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet8cf pxor <Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(pxor(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet8cf pandnot<Packet8cf>(const Packet8cf& a, const Packet8cf& b) { return Packet8cf(pandnot(a.v,b.v)); }
+
+template <>
+EIGEN_STRONG_INLINE Packet8cf pcmp_eq(const Packet8cf& a, const Packet8cf& b) {
+ __m512 eq = pcmp_eq<Packet16f>(a.v, b.v);
+ return Packet8cf(pand(eq, _mm512_permute_ps(eq, 0xB1)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8cf pload <Packet8cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet8cf(pload<Packet16f>(&numext::real_ref(*from))); }
+template<> EIGEN_STRONG_INLINE Packet8cf ploadu<Packet8cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet8cf(ploadu<Packet16f>(&numext::real_ref(*from))); }
+
+
+template<> EIGEN_STRONG_INLINE Packet8cf pset1<Packet8cf>(const std::complex<float>& from)
+{
+ return Packet8cf(_mm512_castpd_ps(pload1<Packet8d>((const double*)(const void*)&from)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8cf ploaddup<Packet8cf>(const std::complex<float>* from)
+{
+ return Packet8cf( _mm512_castpd_ps( ploaddup<Packet8d>((const double*)(const void*)from )) );
+}
+template<> EIGEN_STRONG_INLINE Packet8cf ploadquad<Packet8cf>(const std::complex<float>* from)
+{
+ return Packet8cf( _mm512_castpd_ps( ploadquad<Packet8d>((const double*)(const void*)from )) );
+}
+
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float>* to, const Packet8cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore(&numext::real_ref(*to), from.v); }
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float>* to, const Packet8cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(&numext::real_ref(*to), from.v); }
+
+template<> EIGEN_DEVICE_FUNC inline Packet8cf pgather<std::complex<float>, Packet8cf>(const std::complex<float>* from, Index stride)
+{
+ return Packet8cf(_mm512_castpd_ps(pgather<double,Packet8d>((const double*)(const void*)from, stride)));
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet8cf>(std::complex<float>* to, const Packet8cf& from, Index stride)
+{
+ pscatter((double*)(void*)to, _mm512_castps_pd(from.v), stride);
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet8cf>(const Packet8cf& a)
+{
+ return pfirst(Packet2cf(_mm512_castps512_ps128(a.v)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8cf preverse(const Packet8cf& a) {
+ return Packet8cf(_mm512_castsi512_ps(
+ _mm512_permutexvar_epi64( _mm512_set_epi32(0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7),
+ _mm512_castps_si512(a.v))));
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet8cf>(const Packet8cf& a)
+{
+ return predux(padd(Packet4cf(extract256<0>(a.v)),
+ Packet4cf(extract256<1>(a.v))));
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet8cf>(const Packet8cf& a)
+{
+ return predux_mul(pmul(Packet4cf(extract256<0>(a.v)),
+ Packet4cf(extract256<1>(a.v))));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4cf predux_half_dowto4<Packet8cf>(const Packet8cf& a) {
+ __m256 lane0 = extract256<0>(a.v);
+ __m256 lane1 = extract256<1>(a.v);
+ __m256 res = _mm256_add_ps(lane0, lane1);
+ return Packet4cf(res);
+}
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet8cf,Packet16f)
+
+template<> EIGEN_STRONG_INLINE Packet8cf pdiv<Packet8cf>(const Packet8cf& a, const Packet8cf& b)
+{
+ Packet8cf num = pmul(a, pconj(b));
+ __m512 tmp = _mm512_mul_ps(b.v, b.v);
+ __m512 tmp2 = _mm512_shuffle_ps(tmp,tmp,0xB1);
+ __m512 denom = _mm512_add_ps(tmp, tmp2);
+ return Packet8cf(_mm512_div_ps(num.v, denom));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8cf pcplxflip<Packet8cf>(const Packet8cf& x)
+{
+ return Packet8cf(_mm512_shuffle_ps(x.v, x.v, _MM_SHUFFLE(2, 3, 0 ,1)));
+}
+
+//---------- double ----------
+struct Packet4cd
+{
+ EIGEN_STRONG_INLINE Packet4cd() {}
+ EIGEN_STRONG_INLINE explicit Packet4cd(const __m512d& a) : v(a) {}
+ __m512d v;
+};
+
+template<> struct packet_traits<std::complex<double> > : default_packet_traits
+{
+ typedef Packet4cd type;
+ typedef Packet2cd half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 0,
+ size = 4,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasSqrt = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0
+ };
+};
+
+template<> struct unpacket_traits<Packet4cd> {
+ typedef std::complex<double> type;
+ typedef Packet2cd half;
+ typedef Packet8d as_real;
+ enum {
+ size = 4,
+ alignment = unpacket_traits<Packet8d>::alignment,
+ vectorizable=true,
+ masked_load_available=false,
+ masked_store_available=false
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet4cd padd<Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(_mm512_add_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet4cd psub<Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(_mm512_sub_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet4cd pnegate(const Packet4cd& a) { return Packet4cd(pnegate(a.v)); }
+template<> EIGEN_STRONG_INLINE Packet4cd pconj(const Packet4cd& a)
+{
+ const __m512d mask = _mm512_castsi512_pd(
+ _mm512_set_epi32(0x80000000,0x0,0x0,0x0,0x80000000,0x0,0x0,0x0,
+ 0x80000000,0x0,0x0,0x0,0x80000000,0x0,0x0,0x0));
+ return Packet4cd(pxor(a.v,mask));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cd pmul<Packet4cd>(const Packet4cd& a, const Packet4cd& b)
+{
+ __m512d tmp1 = _mm512_shuffle_pd(a.v,a.v,0x0);
+ __m512d tmp2 = _mm512_shuffle_pd(a.v,a.v,0xFF);
+ __m512d tmp3 = _mm512_shuffle_pd(b.v,b.v,0x55);
+ __m512d odd = _mm512_mul_pd(tmp2, tmp3);
+ return Packet4cd(_mm512_fmaddsub_pd(tmp1, b.v, odd));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cd ptrue<Packet4cd>(const Packet4cd& a) { return Packet4cd(ptrue(Packet8d(a.v))); }
+template<> EIGEN_STRONG_INLINE Packet4cd pand <Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(pand(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet4cd por <Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(por(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet4cd pxor <Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(pxor(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet4cd pandnot<Packet4cd>(const Packet4cd& a, const Packet4cd& b) { return Packet4cd(pandnot(a.v,b.v)); }
+
+template <>
+EIGEN_STRONG_INLINE Packet4cd pcmp_eq(const Packet4cd& a, const Packet4cd& b) {
+ __m512d eq = pcmp_eq<Packet8d>(a.v, b.v);
+ return Packet4cd(pand(eq, _mm512_permute_pd(eq, 0x55)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cd pload <Packet4cd>(const std::complex<double>* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return Packet4cd(pload<Packet8d>((const double*)from)); }
+template<> EIGEN_STRONG_INLINE Packet4cd ploadu<Packet4cd>(const std::complex<double>* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet4cd(ploadu<Packet8d>((const double*)from)); }
+
+template<> EIGEN_STRONG_INLINE Packet4cd pset1<Packet4cd>(const std::complex<double>& from)
+{
+ #ifdef EIGEN_VECTORIZE_AVX512DQ
+ return Packet4cd(_mm512_broadcast_f64x2(pset1<Packet1cd>(from).v));
+ #else
+ return Packet4cd(_mm512_castps_pd(_mm512_broadcast_f32x4( _mm_castpd_ps(pset1<Packet1cd>(from).v))));
+ #endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cd ploaddup<Packet4cd>(const std::complex<double>* from) {
+ return Packet4cd(_mm512_insertf64x4(
+ _mm512_castpd256_pd512(ploaddup<Packet2cd>(from).v), ploaddup<Packet2cd>(from+1).v, 1));
+}
+
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet4cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((double*)to, from.v); }
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet4cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, from.v); }
+
+template<> EIGEN_DEVICE_FUNC inline Packet4cd pgather<std::complex<double>, Packet4cd>(const std::complex<double>* from, Index stride)
+{
+ return Packet4cd(_mm512_insertf64x4(_mm512_castpd256_pd512(
+ _mm256_insertf128_pd(_mm256_castpd128_pd256(ploadu<Packet1cd>(from+0*stride).v), ploadu<Packet1cd>(from+1*stride).v,1)),
+ _mm256_insertf128_pd(_mm256_castpd128_pd256(ploadu<Packet1cd>(from+2*stride).v), ploadu<Packet1cd>(from+3*stride).v,1), 1));
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet4cd>(std::complex<double>* to, const Packet4cd& from, Index stride)
+{
+ __m512i fromi = _mm512_castpd_si512(from.v);
+ double* tod = (double*)(void*)to;
+ _mm_storeu_pd(tod+0*stride, _mm_castsi128_pd(_mm512_extracti32x4_epi32(fromi,0)) );
+ _mm_storeu_pd(tod+2*stride, _mm_castsi128_pd(_mm512_extracti32x4_epi32(fromi,1)) );
+ _mm_storeu_pd(tod+4*stride, _mm_castsi128_pd(_mm512_extracti32x4_epi32(fromi,2)) );
+ _mm_storeu_pd(tod+6*stride, _mm_castsi128_pd(_mm512_extracti32x4_epi32(fromi,3)) );
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet4cd>(const Packet4cd& a)
+{
+ __m128d low = extract128<0>(a.v);
+ EIGEN_ALIGN16 double res[2];
+ _mm_store_pd(res, low);
+ return std::complex<double>(res[0],res[1]);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cd preverse(const Packet4cd& a) {
+ return Packet4cd(_mm512_shuffle_f64x2(a.v, a.v, (shuffle_mask<3,2,1,0>::mask)));
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet4cd>(const Packet4cd& a)
+{
+ return predux(padd(Packet2cd(_mm512_extractf64x4_pd(a.v,0)),
+ Packet2cd(_mm512_extractf64x4_pd(a.v,1))));
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet4cd>(const Packet4cd& a)
+{
+ return predux_mul(pmul(Packet2cd(_mm512_extractf64x4_pd(a.v,0)),
+ Packet2cd(_mm512_extractf64x4_pd(a.v,1))));
+}
+
+template<> struct conj_helper<Packet4cd, Packet4cd, false,true>
+{
+ EIGEN_STRONG_INLINE Packet4cd pmadd(const Packet4cd& x, const Packet4cd& y, const Packet4cd& c) const
+ { return padd(pmul(x,y),c); }
+
+ EIGEN_STRONG_INLINE Packet4cd pmul(const Packet4cd& a, const Packet4cd& b) const
+ {
+ return internal::pmul(a, pconj(b));
+ }
+};
+
+template<> struct conj_helper<Packet4cd, Packet4cd, true,false>
+{
+ EIGEN_STRONG_INLINE Packet4cd pmadd(const Packet4cd& x, const Packet4cd& y, const Packet4cd& c) const
+ { return padd(pmul(x,y),c); }
+
+ EIGEN_STRONG_INLINE Packet4cd pmul(const Packet4cd& a, const Packet4cd& b) const
+ {
+ return internal::pmul(pconj(a), b);
+ }
+};
+
+template<> struct conj_helper<Packet4cd, Packet4cd, true,true>
+{
+ EIGEN_STRONG_INLINE Packet4cd pmadd(const Packet4cd& x, const Packet4cd& y, const Packet4cd& c) const
+ { return padd(pmul(x,y),c); }
+
+ EIGEN_STRONG_INLINE Packet4cd pmul(const Packet4cd& a, const Packet4cd& b) const
+ {
+ return pconj(internal::pmul(a, b));
+ }
+};
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet4cd,Packet8d)
+
+template<> EIGEN_STRONG_INLINE Packet4cd pdiv<Packet4cd>(const Packet4cd& a, const Packet4cd& b)
+{
+ Packet4cd num = pmul(a, pconj(b));
+ __m512d tmp = _mm512_mul_pd(b.v, b.v);
+ __m512d denom = padd(_mm512_permute_pd(tmp,0x55), tmp);
+ return Packet4cd(_mm512_div_pd(num.v, denom));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cd pcplxflip<Packet4cd>(const Packet4cd& x)
+{
+ return Packet4cd(_mm512_permute_pd(x.v,0x55));
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet8cf,4>& kernel) {
+ PacketBlock<Packet8d,4> pb;
+
+ pb.packet[0] = _mm512_castps_pd(kernel.packet[0].v);
+ pb.packet[1] = _mm512_castps_pd(kernel.packet[1].v);
+ pb.packet[2] = _mm512_castps_pd(kernel.packet[2].v);
+ pb.packet[3] = _mm512_castps_pd(kernel.packet[3].v);
+ ptranspose(pb);
+ kernel.packet[0].v = _mm512_castpd_ps(pb.packet[0]);
+ kernel.packet[1].v = _mm512_castpd_ps(pb.packet[1]);
+ kernel.packet[2].v = _mm512_castpd_ps(pb.packet[2]);
+ kernel.packet[3].v = _mm512_castpd_ps(pb.packet[3]);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet8cf,8>& kernel) {
+ PacketBlock<Packet8d,8> pb;
+
+ pb.packet[0] = _mm512_castps_pd(kernel.packet[0].v);
+ pb.packet[1] = _mm512_castps_pd(kernel.packet[1].v);
+ pb.packet[2] = _mm512_castps_pd(kernel.packet[2].v);
+ pb.packet[3] = _mm512_castps_pd(kernel.packet[3].v);
+ pb.packet[4] = _mm512_castps_pd(kernel.packet[4].v);
+ pb.packet[5] = _mm512_castps_pd(kernel.packet[5].v);
+ pb.packet[6] = _mm512_castps_pd(kernel.packet[6].v);
+ pb.packet[7] = _mm512_castps_pd(kernel.packet[7].v);
+ ptranspose(pb);
+ kernel.packet[0].v = _mm512_castpd_ps(pb.packet[0]);
+ kernel.packet[1].v = _mm512_castpd_ps(pb.packet[1]);
+ kernel.packet[2].v = _mm512_castpd_ps(pb.packet[2]);
+ kernel.packet[3].v = _mm512_castpd_ps(pb.packet[3]);
+ kernel.packet[4].v = _mm512_castpd_ps(pb.packet[4]);
+ kernel.packet[5].v = _mm512_castpd_ps(pb.packet[5]);
+ kernel.packet[6].v = _mm512_castpd_ps(pb.packet[6]);
+ kernel.packet[7].v = _mm512_castpd_ps(pb.packet[7]);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet4cd,4>& kernel) {
+ __m512d T0 = _mm512_shuffle_f64x2(kernel.packet[0].v, kernel.packet[1].v, (shuffle_mask<0,1,0,1>::mask)); // [a0 a1 b0 b1]
+ __m512d T1 = _mm512_shuffle_f64x2(kernel.packet[0].v, kernel.packet[1].v, (shuffle_mask<2,3,2,3>::mask)); // [a2 a3 b2 b3]
+ __m512d T2 = _mm512_shuffle_f64x2(kernel.packet[2].v, kernel.packet[3].v, (shuffle_mask<0,1,0,1>::mask)); // [c0 c1 d0 d1]
+ __m512d T3 = _mm512_shuffle_f64x2(kernel.packet[2].v, kernel.packet[3].v, (shuffle_mask<2,3,2,3>::mask)); // [c2 c3 d2 d3]
+
+ kernel.packet[3] = Packet4cd(_mm512_shuffle_f64x2(T1, T3, (shuffle_mask<1,3,1,3>::mask))); // [a3 b3 c3 d3]
+ kernel.packet[2] = Packet4cd(_mm512_shuffle_f64x2(T1, T3, (shuffle_mask<0,2,0,2>::mask))); // [a2 b2 c2 d2]
+ kernel.packet[1] = Packet4cd(_mm512_shuffle_f64x2(T0, T2, (shuffle_mask<1,3,1,3>::mask))); // [a1 b1 c1 d1]
+ kernel.packet[0] = Packet4cd(_mm512_shuffle_f64x2(T0, T2, (shuffle_mask<0,2,0,2>::mask))); // [a0 b0 c0 d0]
+}
+
+template<> EIGEN_STRONG_INLINE Packet4cd psqrt<Packet4cd>(const Packet4cd& a) {
+ return psqrt_complex<Packet4cd>(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8cf psqrt<Packet8cf>(const Packet8cf& a) {
+ return psqrt_complex<Packet8cf>(a);
+}
+
+} // end namespace internal
+} // end namespace Eigen
+
+#endif // EIGEN_COMPLEX_AVX512_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h
new file mode 100644
index 000000000..6fd726d29
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h
@@ -0,0 +1,362 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2016 Pedro Gonnet (pedro.gonnet@gmail.com)
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
+#define THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
+
+namespace Eigen {
+
+namespace internal {
+
+// Disable the code for older versions of gcc that don't support many of the required avx512 instrinsics.
+#if EIGEN_GNUC_AT_LEAST(5, 3) || EIGEN_COMP_CLANG || EIGEN_COMP_MSVC >= 1923
+
+#define _EIGEN_DECLARE_CONST_Packet16f(NAME, X) \
+ const Packet16f p16f_##NAME = pset1<Packet16f>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet16f_FROM_INT(NAME, X) \
+ const Packet16f p16f_##NAME = preinterpret<Packet16f,Packet16i>(pset1<Packet16i>(X))
+
+#define _EIGEN_DECLARE_CONST_Packet8d(NAME, X) \
+ const Packet8d p8d_##NAME = pset1<Packet8d>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet8d_FROM_INT64(NAME, X) \
+ const Packet8d p8d_##NAME = _mm512_castsi512_pd(_mm512_set1_epi64(X))
+
+#define _EIGEN_DECLARE_CONST_Packet16bf(NAME, X) \
+ const Packet16bf p16bf_##NAME = pset1<Packet16bf>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet16bf_FROM_INT(NAME, X) \
+ const Packet16bf p16bf_##NAME = preinterpret<Packet16bf,Packet16i>(pset1<Packet16i>(X))
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f
+plog<Packet16f>(const Packet16f& _x) {
+ return plog_float(_x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8d
+plog<Packet8d>(const Packet8d& _x) {
+ return plog_double(_x);
+}
+
+F16_PACKET_FUNCTION(Packet16f, Packet16h, plog)
+BF16_PACKET_FUNCTION(Packet16f, Packet16bf, plog)
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f
+plog2<Packet16f>(const Packet16f& _x) {
+ return plog2_float(_x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8d
+plog2<Packet8d>(const Packet8d& _x) {
+ return plog2_double(_x);
+}
+
+F16_PACKET_FUNCTION(Packet16f, Packet16h, plog2)
+BF16_PACKET_FUNCTION(Packet16f, Packet16bf, plog2)
+
+// Exponential function. Works by writing "x = m*log(2) + r" where
+// "m = floor(x/log(2)+1/2)" and "r" is the remainder. The result is then
+// "exp(x) = 2^m*exp(r)" where exp(r) is in the range [-1,1).
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f
+pexp<Packet16f>(const Packet16f& _x) {
+ _EIGEN_DECLARE_CONST_Packet16f(1, 1.0f);
+ _EIGEN_DECLARE_CONST_Packet16f(half, 0.5f);
+ _EIGEN_DECLARE_CONST_Packet16f(127, 127.0f);
+
+ _EIGEN_DECLARE_CONST_Packet16f(exp_hi, 88.3762626647950f);
+ _EIGEN_DECLARE_CONST_Packet16f(exp_lo, -88.3762626647949f);
+
+ _EIGEN_DECLARE_CONST_Packet16f(cephes_LOG2EF, 1.44269504088896341f);
+
+ _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p0, 1.9875691500E-4f);
+ _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p1, 1.3981999507E-3f);
+ _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p2, 8.3334519073E-3f);
+ _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p3, 4.1665795894E-2f);
+ _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p4, 1.6666665459E-1f);
+ _EIGEN_DECLARE_CONST_Packet16f(cephes_exp_p5, 5.0000001201E-1f);
+
+ // Clamp x.
+ Packet16f x = pmax(pmin(_x, p16f_exp_hi), p16f_exp_lo);
+
+ // Express exp(x) as exp(m*ln(2) + r), start by extracting
+ // m = floor(x/ln(2) + 0.5).
+ Packet16f m = _mm512_floor_ps(pmadd(x, p16f_cephes_LOG2EF, p16f_half));
+
+ // Get r = x - m*ln(2). Note that we can do this without losing more than one
+ // ulp precision due to the FMA instruction.
+ _EIGEN_DECLARE_CONST_Packet16f(nln2, -0.6931471805599453f);
+ Packet16f r = _mm512_fmadd_ps(m, p16f_nln2, x);
+ Packet16f r2 = pmul(r, r);
+ Packet16f r3 = pmul(r2, r);
+
+ // Evaluate the polynomial approximant,improved by instruction-level parallelism.
+ Packet16f y, y1, y2;
+ y = pmadd(p16f_cephes_exp_p0, r, p16f_cephes_exp_p1);
+ y1 = pmadd(p16f_cephes_exp_p3, r, p16f_cephes_exp_p4);
+ y2 = padd(r, p16f_1);
+ y = pmadd(y, r, p16f_cephes_exp_p2);
+ y1 = pmadd(y1, r, p16f_cephes_exp_p5);
+ y = pmadd(y, r3, y1);
+ y = pmadd(y, r2, y2);
+
+ // Build emm0 = 2^m.
+ Packet16i emm0 = _mm512_cvttps_epi32(padd(m, p16f_127));
+ emm0 = _mm512_slli_epi32(emm0, 23);
+
+ // Return 2^m * exp(r).
+ return pmax(pmul(y, _mm512_castsi512_ps(emm0)), _x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8d
+pexp<Packet8d>(const Packet8d& _x) {
+ return pexp_double(_x);
+}
+
+F16_PACKET_FUNCTION(Packet16f, Packet16h, pexp)
+BF16_PACKET_FUNCTION(Packet16f, Packet16bf, pexp)
+
+template <>
+EIGEN_STRONG_INLINE Packet16h pfrexp(const Packet16h& a, Packet16h& exponent) {
+ Packet16f fexponent;
+ const Packet16h out = float2half(pfrexp<Packet16f>(half2float(a), fexponent));
+ exponent = float2half(fexponent);
+ return out;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16h pldexp(const Packet16h& a, const Packet16h& exponent) {
+ return float2half(pldexp<Packet16f>(half2float(a), half2float(exponent)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pfrexp(const Packet16bf& a, Packet16bf& exponent) {
+ Packet16f fexponent;
+ const Packet16bf out = F32ToBf16(pfrexp<Packet16f>(Bf16ToF32(a), fexponent));
+ exponent = F32ToBf16(fexponent);
+ return out;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pldexp(const Packet16bf& a, const Packet16bf& exponent) {
+ return F32ToBf16(pldexp<Packet16f>(Bf16ToF32(a), Bf16ToF32(exponent)));
+}
+
+// Functions for sqrt.
+// The EIGEN_FAST_MATH version uses the _mm_rsqrt_ps approximation and one step
+// of Newton's method, at a cost of 1-2 bits of precision as opposed to the
+// exact solution. The main advantage of this approach is not just speed, but
+// also the fact that it can be inlined and pipelined with other computations,
+// further reducing its effective latency.
+#if EIGEN_FAST_MATH
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f
+psqrt<Packet16f>(const Packet16f& _x) {
+ Packet16f neg_half = pmul(_x, pset1<Packet16f>(-.5f));
+ __mmask16 denormal_mask = _mm512_kand(
+ _mm512_cmp_ps_mask(_x, pset1<Packet16f>((std::numeric_limits<float>::min)()),
+ _CMP_LT_OQ),
+ _mm512_cmp_ps_mask(_x, _mm512_setzero_ps(), _CMP_GE_OQ));
+
+ Packet16f x = _mm512_rsqrt14_ps(_x);
+
+ // Do a single step of Newton's iteration.
+ x = pmul(x, pmadd(neg_half, pmul(x, x), pset1<Packet16f>(1.5f)));
+
+ // Flush results for denormals to zero.
+ return _mm512_mask_blend_ps(denormal_mask, pmul(_x,x), _mm512_setzero_ps());
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8d
+psqrt<Packet8d>(const Packet8d& _x) {
+ Packet8d neg_half = pmul(_x, pset1<Packet8d>(-.5));
+ __mmask16 denormal_mask = _mm512_kand(
+ _mm512_cmp_pd_mask(_x, pset1<Packet8d>((std::numeric_limits<double>::min)()),
+ _CMP_LT_OQ),
+ _mm512_cmp_pd_mask(_x, _mm512_setzero_pd(), _CMP_GE_OQ));
+
+ Packet8d x = _mm512_rsqrt14_pd(_x);
+
+ // Do a single step of Newton's iteration.
+ x = pmul(x, pmadd(neg_half, pmul(x, x), pset1<Packet8d>(1.5)));
+
+ // Do a second step of Newton's iteration.
+ x = pmul(x, pmadd(neg_half, pmul(x, x), pset1<Packet8d>(1.5)));
+
+ return _mm512_mask_blend_pd(denormal_mask, pmul(_x,x), _mm512_setzero_pd());
+}
+#else
+template <>
+EIGEN_STRONG_INLINE Packet16f psqrt<Packet16f>(const Packet16f& x) {
+ return _mm512_sqrt_ps(x);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8d psqrt<Packet8d>(const Packet8d& x) {
+ return _mm512_sqrt_pd(x);
+}
+#endif
+
+F16_PACKET_FUNCTION(Packet16f, Packet16h, psqrt)
+BF16_PACKET_FUNCTION(Packet16f, Packet16bf, psqrt)
+
+// prsqrt for float.
+#if defined(EIGEN_VECTORIZE_AVX512ER)
+
+template <>
+EIGEN_STRONG_INLINE Packet16f prsqrt<Packet16f>(const Packet16f& x) {
+ return _mm512_rsqrt28_ps(x);
+}
+#elif EIGEN_FAST_MATH
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f
+prsqrt<Packet16f>(const Packet16f& _x) {
+ _EIGEN_DECLARE_CONST_Packet16f_FROM_INT(inf, 0x7f800000);
+ _EIGEN_DECLARE_CONST_Packet16f(one_point_five, 1.5f);
+ _EIGEN_DECLARE_CONST_Packet16f(minus_half, -0.5f);
+
+ Packet16f neg_half = pmul(_x, p16f_minus_half);
+
+ // Identity infinite, negative and denormal arguments.
+ __mmask16 inf_mask = _mm512_cmp_ps_mask(_x, p16f_inf, _CMP_EQ_OQ);
+ __mmask16 not_pos_mask = _mm512_cmp_ps_mask(_x, _mm512_setzero_ps(), _CMP_LE_OQ);
+ __mmask16 not_finite_pos_mask = not_pos_mask | inf_mask;
+
+ // Compute an approximate result using the rsqrt intrinsic, forcing +inf
+ // for denormals for consistency with AVX and SSE implementations.
+ Packet16f y_approx = _mm512_rsqrt14_ps(_x);
+
+ // Do a single step of Newton-Raphson iteration to improve the approximation.
+ // This uses the formula y_{n+1} = y_n * (1.5 - y_n * (0.5 * x) * y_n).
+ // It is essential to evaluate the inner term like this because forming
+ // y_n^2 may over- or underflow.
+ Packet16f y_newton = pmul(y_approx, pmadd(y_approx, pmul(neg_half, y_approx), p16f_one_point_five));
+
+ // Select the result of the Newton-Raphson step for positive finite arguments.
+ // For other arguments, choose the output of the intrinsic. This will
+ // return rsqrt(+inf) = 0, rsqrt(x) = NaN if x < 0, and rsqrt(0) = +inf.
+ return _mm512_mask_blend_ps(not_finite_pos_mask, y_newton, y_approx);
+}
+#else
+
+template <>
+EIGEN_STRONG_INLINE Packet16f prsqrt<Packet16f>(const Packet16f& x) {
+ _EIGEN_DECLARE_CONST_Packet16f(one, 1.0f);
+ return _mm512_div_ps(p16f_one, _mm512_sqrt_ps(x));
+}
+#endif
+
+F16_PACKET_FUNCTION(Packet16f, Packet16h, prsqrt)
+BF16_PACKET_FUNCTION(Packet16f, Packet16bf, prsqrt)
+
+// prsqrt for double.
+#if EIGEN_FAST_MATH
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8d
+prsqrt<Packet8d>(const Packet8d& _x) {
+ _EIGEN_DECLARE_CONST_Packet8d(one_point_five, 1.5);
+ _EIGEN_DECLARE_CONST_Packet8d(minus_half, -0.5);
+ _EIGEN_DECLARE_CONST_Packet8d_FROM_INT64(inf, 0x7ff0000000000000LL);
+
+ Packet8d neg_half = pmul(_x, p8d_minus_half);
+
+ // Identity infinite, negative and denormal arguments.
+ __mmask8 inf_mask = _mm512_cmp_pd_mask(_x, p8d_inf, _CMP_EQ_OQ);
+ __mmask8 not_pos_mask = _mm512_cmp_pd_mask(_x, _mm512_setzero_pd(), _CMP_LE_OQ);
+ __mmask8 not_finite_pos_mask = not_pos_mask | inf_mask;
+
+ // Compute an approximate result using the rsqrt intrinsic, forcing +inf
+ // for denormals for consistency with AVX and SSE implementations.
+#if defined(EIGEN_VECTORIZE_AVX512ER)
+ Packet8d y_approx = _mm512_rsqrt28_pd(_x);
+#else
+ Packet8d y_approx = _mm512_rsqrt14_pd(_x);
+#endif
+ // Do one or two steps of Newton-Raphson's to improve the approximation, depending on the
+ // starting accuracy (either 2^-14 or 2^-28, depending on whether AVX512ER is available).
+ // The Newton-Raphson algorithm has quadratic convergence and roughly doubles the number
+ // of correct digits for each step.
+ // This uses the formula y_{n+1} = y_n * (1.5 - y_n * (0.5 * x) * y_n).
+ // It is essential to evaluate the inner term like this because forming
+ // y_n^2 may over- or underflow.
+ Packet8d y_newton = pmul(y_approx, pmadd(neg_half, pmul(y_approx, y_approx), p8d_one_point_five));
+#if !defined(EIGEN_VECTORIZE_AVX512ER)
+ y_newton = pmul(y_newton, pmadd(y_newton, pmul(neg_half, y_newton), p8d_one_point_five));
+#endif
+ // Select the result of the Newton-Raphson step for positive finite arguments.
+ // For other arguments, choose the output of the intrinsic. This will
+ // return rsqrt(+inf) = 0, rsqrt(x) = NaN if x < 0, and rsqrt(0) = +inf.
+ return _mm512_mask_blend_pd(not_finite_pos_mask, y_newton, y_approx);
+}
+#else
+template <>
+EIGEN_STRONG_INLINE Packet8d prsqrt<Packet8d>(const Packet8d& x) {
+ _EIGEN_DECLARE_CONST_Packet8d(one, 1.0f);
+ return _mm512_div_pd(p8d_one, _mm512_sqrt_pd(x));
+}
+#endif
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet16f plog1p<Packet16f>(const Packet16f& _x) {
+ return generic_plog1p(_x);
+}
+
+F16_PACKET_FUNCTION(Packet16f, Packet16h, plog1p)
+BF16_PACKET_FUNCTION(Packet16f, Packet16bf, plog1p)
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet16f pexpm1<Packet16f>(const Packet16f& _x) {
+ return generic_expm1(_x);
+}
+
+F16_PACKET_FUNCTION(Packet16f, Packet16h, pexpm1)
+BF16_PACKET_FUNCTION(Packet16f, Packet16bf, pexpm1)
+
+#endif
+
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f
+psin<Packet16f>(const Packet16f& _x) {
+ return psin_float(_x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f
+pcos<Packet16f>(const Packet16f& _x) {
+ return pcos_float(_x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet16f
+ptanh<Packet16f>(const Packet16f& _x) {
+ return internal::generic_fast_tanh_float(_x);
+}
+
+F16_PACKET_FUNCTION(Packet16f, Packet16h, psin)
+F16_PACKET_FUNCTION(Packet16f, Packet16h, pcos)
+F16_PACKET_FUNCTION(Packet16f, Packet16h, ptanh)
+
+BF16_PACKET_FUNCTION(Packet16f, Packet16bf, psin)
+BF16_PACKET_FUNCTION(Packet16f, Packet16bf, pcos)
+BF16_PACKET_FUNCTION(Packet16f, Packet16bf, ptanh)
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h
new file mode 100644
index 000000000..34d49ab66
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h
@@ -0,0 +1,2303 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2016 Benoit Steiner (benoit.steiner.goog@gmail.com)
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PACKET_MATH_AVX512_H
+#define EIGEN_PACKET_MATH_AVX512_H
+
+namespace Eigen {
+
+namespace internal {
+
+#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
+#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
+#endif
+
+#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS
+#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32
+#endif
+
+#ifdef EIGEN_VECTORIZE_FMA
+#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#endif
+#endif
+
+typedef __m512 Packet16f;
+typedef __m512i Packet16i;
+typedef __m512d Packet8d;
+typedef eigen_packet_wrapper<__m256i, 1> Packet16h;
+typedef eigen_packet_wrapper<__m256i, 2> Packet16bf;
+
+template <>
+struct is_arithmetic<__m512> {
+ enum { value = true };
+};
+template <>
+struct is_arithmetic<__m512i> {
+ enum { value = true };
+};
+template <>
+struct is_arithmetic<__m512d> {
+ enum { value = true };
+};
+
+template<> struct is_arithmetic<Packet16h> { enum { value = true }; };
+
+template <>
+struct packet_traits<half> : default_packet_traits {
+ typedef Packet16h type;
+ // There is no half-size packet for Packet16h.
+ typedef Packet16h half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 16,
+ HasHalfPacket = 1,
+
+ HasCmp = 1,
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasAbs2 = 0,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasLog = 1,
+ HasLog1p = 1,
+ HasExpm1 = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+ HasBlend = 0,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1,
+ HasBessel = 1,
+ HasNdtri = 1
+ };
+};
+
+template<> struct packet_traits<float> : default_packet_traits
+{
+ typedef Packet16f type;
+ typedef Packet8f half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 16,
+ HasHalfPacket = 1,
+
+ HasAbs = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasBlend = 0,
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+#if EIGEN_GNUC_AT_LEAST(5, 3) || (!EIGEN_COMP_GNUC_STRICT)
+ HasLog = 1,
+ HasLog1p = 1,
+ HasExpm1 = 1,
+ HasNdtri = 1,
+ HasBessel = 1,
+ HasExp = 1,
+ HasSqrt = EIGEN_FAST_MATH,
+ HasRsqrt = EIGEN_FAST_MATH,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+#endif
+ HasCmp = 1,
+ HasDiv = 1,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1
+ };
+ };
+template<> struct packet_traits<double> : default_packet_traits
+{
+ typedef Packet8d type;
+ typedef Packet4d half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 8,
+ HasHalfPacket = 1,
+#if EIGEN_GNUC_AT_LEAST(5, 3) || (!EIGEN_COMP_GNUC_STRICT)
+ HasLog = 1,
+ HasExp = 1,
+ HasSqrt = EIGEN_FAST_MATH,
+ HasRsqrt = EIGEN_FAST_MATH,
+#endif
+ HasCmp = 1,
+ HasDiv = 1,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1
+ };
+};
+
+/* TODO Implement AVX512 for integers
+template<> struct packet_traits<int> : default_packet_traits
+{
+ typedef Packet16i type;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size=8
+ };
+};
+*/
+
+template <>
+struct unpacket_traits<Packet16f> {
+ typedef float type;
+ typedef Packet8f half;
+ typedef Packet16i integer_packet;
+ typedef uint16_t mask_t;
+ enum { size = 16, alignment=Aligned64, vectorizable=true, masked_load_available=true, masked_store_available=true };
+};
+template <>
+struct unpacket_traits<Packet8d> {
+ typedef double type;
+ typedef Packet4d half;
+ enum { size = 8, alignment=Aligned64, vectorizable=true, masked_load_available=false, masked_store_available=false };
+};
+template <>
+struct unpacket_traits<Packet16i> {
+ typedef int type;
+ typedef Packet8i half;
+ enum { size = 16, alignment=Aligned64, vectorizable=false, masked_load_available=false, masked_store_available=false };
+};
+
+template<>
+struct unpacket_traits<Packet16h> {
+ typedef Eigen::half type;
+ typedef Packet8h half;
+ enum {size=16, alignment=Aligned32, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pset1<Packet16f>(const float& from) {
+ return _mm512_set1_ps(from);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pset1<Packet8d>(const double& from) {
+ return _mm512_set1_pd(from);
+}
+template <>
+EIGEN_STRONG_INLINE Packet16i pset1<Packet16i>(const int& from) {
+ return _mm512_set1_epi32(from);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pset1frombits<Packet16f>(unsigned int from) {
+ return _mm512_castsi512_ps(_mm512_set1_epi32(from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8d pset1frombits<Packet8d>(const numext::uint64_t from) {
+ return _mm512_castsi512_pd(_mm512_set1_epi64(from));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16f pzero(const Packet16f& /*a*/) { return _mm512_setzero_ps(); }
+template<> EIGEN_STRONG_INLINE Packet8d pzero(const Packet8d& /*a*/) { return _mm512_setzero_pd(); }
+template<> EIGEN_STRONG_INLINE Packet16i pzero(const Packet16i& /*a*/) { return _mm512_setzero_si512(); }
+
+template<> EIGEN_STRONG_INLINE Packet16f peven_mask(const Packet16f& /*a*/) {
+ return _mm512_castsi512_ps(_mm512_set_epi32(0, -1, 0, -1, 0, -1, 0, -1,
+ 0, -1, 0, -1, 0, -1, 0, -1));
+}
+template<> EIGEN_STRONG_INLINE Packet16i peven_mask(const Packet16i& /*a*/) {
+ return _mm512_set_epi32(0, -1, 0, -1, 0, -1, 0, -1,
+ 0, -1, 0, -1, 0, -1, 0, -1);
+}
+template<> EIGEN_STRONG_INLINE Packet8d peven_mask(const Packet8d& /*a*/) {
+ return _mm512_castsi512_pd(_mm512_set_epi32(0, 0, -1, -1, 0, 0, -1, -1,
+ 0, 0, -1, -1, 0, 0, -1, -1));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pload1<Packet16f>(const float* from) {
+ return _mm512_broadcastss_ps(_mm_load_ps1(from));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pload1<Packet8d>(const double* from) {
+ return _mm512_set1_pd(*from);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f plset<Packet16f>(const float& a) {
+ return _mm512_add_ps(
+ _mm512_set1_ps(a),
+ _mm512_set_ps(15.0f, 14.0f, 13.0f, 12.0f, 11.0f, 10.0f, 9.0f, 8.0f, 7.0f, 6.0f, 5.0f,
+ 4.0f, 3.0f, 2.0f, 1.0f, 0.0f));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d plset<Packet8d>(const double& a) {
+ return _mm512_add_pd(_mm512_set1_pd(a),
+ _mm512_set_pd(7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f padd<Packet16f>(const Packet16f& a,
+ const Packet16f& b) {
+ return _mm512_add_ps(a, b);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d padd<Packet8d>(const Packet8d& a,
+ const Packet8d& b) {
+ return _mm512_add_pd(a, b);
+}
+template <>
+EIGEN_STRONG_INLINE Packet16i padd<Packet16i>(const Packet16i& a,
+ const Packet16i& b) {
+ return _mm512_add_epi32(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f psub<Packet16f>(const Packet16f& a,
+ const Packet16f& b) {
+ return _mm512_sub_ps(a, b);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d psub<Packet8d>(const Packet8d& a,
+ const Packet8d& b) {
+ return _mm512_sub_pd(a, b);
+}
+template <>
+EIGEN_STRONG_INLINE Packet16i psub<Packet16i>(const Packet16i& a,
+ const Packet16i& b) {
+ return _mm512_sub_epi32(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pnegate(const Packet16f& a) {
+ return _mm512_sub_ps(_mm512_set1_ps(0.0), a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pnegate(const Packet8d& a) {
+ return _mm512_sub_pd(_mm512_set1_pd(0.0), a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pconj(const Packet16f& a) {
+ return a;
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pconj(const Packet8d& a) {
+ return a;
+}
+template <>
+EIGEN_STRONG_INLINE Packet16i pconj(const Packet16i& a) {
+ return a;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pmul<Packet16f>(const Packet16f& a,
+ const Packet16f& b) {
+ return _mm512_mul_ps(a, b);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pmul<Packet8d>(const Packet8d& a,
+ const Packet8d& b) {
+ return _mm512_mul_pd(a, b);
+}
+template <>
+EIGEN_STRONG_INLINE Packet16i pmul<Packet16i>(const Packet16i& a,
+ const Packet16i& b) {
+ return _mm512_mullo_epi32(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pdiv<Packet16f>(const Packet16f& a,
+ const Packet16f& b) {
+ return _mm512_div_ps(a, b);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pdiv<Packet8d>(const Packet8d& a,
+ const Packet8d& b) {
+ return _mm512_div_pd(a, b);
+}
+
+#ifdef EIGEN_VECTORIZE_FMA
+template <>
+EIGEN_STRONG_INLINE Packet16f pmadd(const Packet16f& a, const Packet16f& b,
+ const Packet16f& c) {
+ return _mm512_fmadd_ps(a, b, c);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pmadd(const Packet8d& a, const Packet8d& b,
+ const Packet8d& c) {
+ return _mm512_fmadd_pd(a, b, c);
+}
+#endif
+
+template <>
+EIGEN_DEVICE_FUNC inline Packet16f pselect(const Packet16f& mask,
+ const Packet16f& a,
+ const Packet16f& b) {
+ __mmask16 mask16 = _mm512_cmp_epi32_mask(
+ _mm512_castps_si512(mask), _mm512_setzero_epi32(), _MM_CMPINT_EQ);
+ return _mm512_mask_blend_ps(mask16, a, b);
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline Packet8d pselect(const Packet8d& mask,
+ const Packet8d& a,
+ const Packet8d& b) {
+ __mmask8 mask8 = _mm512_cmp_epi64_mask(_mm512_castpd_si512(mask),
+ _mm512_setzero_epi32(), _MM_CMPINT_EQ);
+ return _mm512_mask_blend_pd(mask8, a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pmin<Packet16f>(const Packet16f& a,
+ const Packet16f& b) {
+ // Arguments are reversed to match NaN propagation behavior of std::min.
+ return _mm512_min_ps(b, a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pmin<Packet8d>(const Packet8d& a,
+ const Packet8d& b) {
+ // Arguments are reversed to match NaN propagation behavior of std::min.
+ return _mm512_min_pd(b, a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pmax<Packet16f>(const Packet16f& a,
+ const Packet16f& b) {
+ // Arguments are reversed to match NaN propagation behavior of std::max.
+ return _mm512_max_ps(b, a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pmax<Packet8d>(const Packet8d& a,
+ const Packet8d& b) {
+ // Arguments are reversed to match NaN propagation behavior of std::max.
+ return _mm512_max_pd(b, a);
+}
+
+// Add specializations for min/max with prescribed NaN progation.
+template<>
+EIGEN_STRONG_INLINE Packet16f pmin<PropagateNumbers, Packet16f>(const Packet16f& a, const Packet16f& b) {
+ return pminmax_propagate_numbers(a, b, pmin<Packet16f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet8d pmin<PropagateNumbers, Packet8d>(const Packet8d& a, const Packet8d& b) {
+ return pminmax_propagate_numbers(a, b, pmin<Packet8d>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet16f pmax<PropagateNumbers, Packet16f>(const Packet16f& a, const Packet16f& b) {
+ return pminmax_propagate_numbers(a, b, pmax<Packet16f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet8d pmax<PropagateNumbers, Packet8d>(const Packet8d& a, const Packet8d& b) {
+ return pminmax_propagate_numbers(a, b, pmax<Packet8d>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet16f pmin<PropagateNaN, Packet16f>(const Packet16f& a, const Packet16f& b) {
+ return pminmax_propagate_nan(a, b, pmin<Packet16f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet8d pmin<PropagateNaN, Packet8d>(const Packet8d& a, const Packet8d& b) {
+ return pminmax_propagate_nan(a, b, pmin<Packet8d>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet16f pmax<PropagateNaN, Packet16f>(const Packet16f& a, const Packet16f& b) {
+ return pminmax_propagate_nan(a, b, pmax<Packet16f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet8d pmax<PropagateNaN, Packet8d>(const Packet8d& a, const Packet8d& b) {
+ return pminmax_propagate_nan(a, b, pmax<Packet8d>);
+}
+
+
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+template<int I_> EIGEN_STRONG_INLINE Packet8f extract256(Packet16f x) { return _mm512_extractf32x8_ps(x,I_); }
+template<int I_> EIGEN_STRONG_INLINE Packet2d extract128(Packet8d x) { return _mm512_extractf64x2_pd(x,I_); }
+EIGEN_STRONG_INLINE Packet16f cat256(Packet8f a, Packet8f b) { return _mm512_insertf32x8(_mm512_castps256_ps512(a),b,1); }
+#else
+// AVX512F does not define _mm512_extractf32x8_ps to extract _m256 from _m512
+template<int I_> EIGEN_STRONG_INLINE Packet8f extract256(Packet16f x) {
+ return _mm256_castsi256_ps(_mm512_extracti64x4_epi64( _mm512_castps_si512(x),I_));
+}
+
+// AVX512F does not define _mm512_extractf64x2_pd to extract _m128 from _m512
+template<int I_> EIGEN_STRONG_INLINE Packet2d extract128(Packet8d x) {
+ return _mm_castsi128_pd(_mm512_extracti32x4_epi32( _mm512_castpd_si512(x),I_));
+}
+
+EIGEN_STRONG_INLINE Packet16f cat256(Packet8f a, Packet8f b) {
+ return _mm512_castsi512_ps(_mm512_inserti64x4(_mm512_castsi256_si512(_mm256_castps_si256(a)),
+ _mm256_castps_si256(b),1));
+}
+#endif
+
+// Helper function for bit packing snippet of low precision comparison.
+// It packs the flags from 32x16 to 16x16.
+EIGEN_STRONG_INLINE __m256i Pack32To16(Packet16f rf) {
+ // Split data into small pieces and handle with AVX instructions
+ // to guarantee internal order of vector.
+ // Operation:
+ // dst[15:0] := Saturate16(rf[31:0])
+ // dst[31:16] := Saturate16(rf[63:32])
+ // ...
+ // dst[255:240] := Saturate16(rf[255:224])
+ __m256i lo = _mm256_castps_si256(extract256<0>(rf));
+ __m256i hi = _mm256_castps_si256(extract256<1>(rf));
+ __m128i result_lo = _mm_packs_epi32(_mm256_extractf128_si256(lo, 0),
+ _mm256_extractf128_si256(lo, 1));
+ __m128i result_hi = _mm_packs_epi32(_mm256_extractf128_si256(hi, 0),
+ _mm256_extractf128_si256(hi, 1));
+ return _mm256_insertf128_si256(_mm256_castsi128_si256(result_lo), result_hi, 1);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pcmp_eq(const Packet16f& a, const Packet16f& b) {
+ __mmask16 mask = _mm512_cmp_ps_mask(a, b, _CMP_EQ_OQ);
+ return _mm512_castsi512_ps(
+ _mm512_mask_set1_epi32(_mm512_set1_epi32(0), mask, 0xffffffffu));
+}
+template<> EIGEN_STRONG_INLINE Packet16f pcmp_le(const Packet16f& a, const Packet16f& b) {
+ __mmask16 mask = _mm512_cmp_ps_mask(a, b, _CMP_LE_OQ);
+ return _mm512_castsi512_ps(
+ _mm512_mask_set1_epi32(_mm512_set1_epi32(0), mask, 0xffffffffu));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16f pcmp_lt(const Packet16f& a, const Packet16f& b) {
+ __mmask16 mask = _mm512_cmp_ps_mask(a, b, _CMP_LT_OQ);
+ return _mm512_castsi512_ps(
+ _mm512_mask_set1_epi32(_mm512_set1_epi32(0), mask, 0xffffffffu));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16f pcmp_lt_or_nan(const Packet16f& a, const Packet16f& b) {
+ __mmask16 mask = _mm512_cmp_ps_mask(a, b, _CMP_NGE_UQ);
+ return _mm512_castsi512_ps(
+ _mm512_mask_set1_epi32(_mm512_set1_epi32(0), mask, 0xffffffffu));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16i pcmp_eq(const Packet16i& a, const Packet16i& b) {
+ __mmask16 mask = _mm512_cmp_epi32_mask(a, b, _CMP_EQ_OQ);
+ return _mm512_mask_set1_epi32(_mm512_set1_epi32(0), mask, 0xffffffffu);
+}
+
+
+template <>
+EIGEN_STRONG_INLINE Packet8d pcmp_eq(const Packet8d& a, const Packet8d& b) {
+ __mmask8 mask = _mm512_cmp_pd_mask(a, b, _CMP_EQ_OQ);
+ return _mm512_castsi512_pd(
+ _mm512_mask_set1_epi64(_mm512_set1_epi64(0), mask, 0xffffffffffffffffu));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pcmp_le(const Packet8d& a, const Packet8d& b) {
+ __mmask8 mask = _mm512_cmp_pd_mask(a, b, _CMP_LE_OQ);
+ return _mm512_castsi512_pd(
+ _mm512_mask_set1_epi64(_mm512_set1_epi64(0), mask, 0xffffffffffffffffu));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pcmp_lt(const Packet8d& a, const Packet8d& b) {
+ __mmask8 mask = _mm512_cmp_pd_mask(a, b, _CMP_LT_OQ);
+ return _mm512_castsi512_pd(
+ _mm512_mask_set1_epi64(_mm512_set1_epi64(0), mask, 0xffffffffffffffffu));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pcmp_lt_or_nan(const Packet8d& a, const Packet8d& b) {
+ __mmask8 mask = _mm512_cmp_pd_mask(a, b, _CMP_NGE_UQ);
+ return _mm512_castsi512_pd(
+ _mm512_mask_set1_epi64(_mm512_set1_epi64(0), mask, 0xffffffffffffffffu));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16f print<Packet16f>(const Packet16f& a) { return _mm512_roundscale_ps(a, _MM_FROUND_CUR_DIRECTION); }
+template<> EIGEN_STRONG_INLINE Packet8d print<Packet8d>(const Packet8d& a) { return _mm512_roundscale_pd(a, _MM_FROUND_CUR_DIRECTION); }
+
+template<> EIGEN_STRONG_INLINE Packet16f pceil<Packet16f>(const Packet16f& a) { return _mm512_roundscale_ps(a, _MM_FROUND_TO_POS_INF); }
+template<> EIGEN_STRONG_INLINE Packet8d pceil<Packet8d>(const Packet8d& a) { return _mm512_roundscale_pd(a, _MM_FROUND_TO_POS_INF); }
+
+template<> EIGEN_STRONG_INLINE Packet16f pfloor<Packet16f>(const Packet16f& a) { return _mm512_roundscale_ps(a, _MM_FROUND_TO_NEG_INF); }
+template<> EIGEN_STRONG_INLINE Packet8d pfloor<Packet8d>(const Packet8d& a) { return _mm512_roundscale_pd(a, _MM_FROUND_TO_NEG_INF); }
+
+template <>
+EIGEN_STRONG_INLINE Packet16i ptrue<Packet16i>(const Packet16i& /*a*/) {
+ return _mm512_set1_epi32(0xffffffffu);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f ptrue<Packet16f>(const Packet16f& a) {
+ return _mm512_castsi512_ps(ptrue<Packet16i>(_mm512_castps_si512(a)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8d ptrue<Packet8d>(const Packet8d& a) {
+ return _mm512_castsi512_pd(ptrue<Packet16i>(_mm512_castpd_si512(a)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16i pand<Packet16i>(const Packet16i& a,
+ const Packet16i& b) {
+ return _mm512_and_si512(a,b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pand<Packet16f>(const Packet16f& a,
+ const Packet16f& b) {
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+ return _mm512_and_ps(a, b);
+#else
+ return _mm512_castsi512_ps(pand(_mm512_castps_si512(a),_mm512_castps_si512(b)));
+#endif
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pand<Packet8d>(const Packet8d& a,
+ const Packet8d& b) {
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+ return _mm512_and_pd(a, b);
+#else
+ Packet8d res = _mm512_undefined_pd();
+ Packet4d lane0_a = _mm512_extractf64x4_pd(a, 0);
+ Packet4d lane0_b = _mm512_extractf64x4_pd(b, 0);
+ res = _mm512_insertf64x4(res, _mm256_and_pd(lane0_a, lane0_b), 0);
+
+ Packet4d lane1_a = _mm512_extractf64x4_pd(a, 1);
+ Packet4d lane1_b = _mm512_extractf64x4_pd(b, 1);
+ return _mm512_insertf64x4(res, _mm256_and_pd(lane1_a, lane1_b), 1);
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16i por<Packet16i>(const Packet16i& a, const Packet16i& b) {
+ return _mm512_or_si512(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f por<Packet16f>(const Packet16f& a, const Packet16f& b) {
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+ return _mm512_or_ps(a, b);
+#else
+ return _mm512_castsi512_ps(por(_mm512_castps_si512(a),_mm512_castps_si512(b)));
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8d por<Packet8d>(const Packet8d& a,
+ const Packet8d& b) {
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+ return _mm512_or_pd(a, b);
+#else
+ return _mm512_castsi512_pd(por(_mm512_castpd_si512(a),_mm512_castpd_si512(b)));
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16i pxor<Packet16i>(const Packet16i& a, const Packet16i& b) {
+ return _mm512_xor_si512(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pxor<Packet16f>(const Packet16f& a, const Packet16f& b) {
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+ return _mm512_xor_ps(a, b);
+#else
+ return _mm512_castsi512_ps(pxor(_mm512_castps_si512(a),_mm512_castps_si512(b)));
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8d pxor<Packet8d>(const Packet8d& a, const Packet8d& b) {
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+ return _mm512_xor_pd(a, b);
+#else
+ return _mm512_castsi512_pd(pxor(_mm512_castpd_si512(a),_mm512_castpd_si512(b)));
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16i pandnot<Packet16i>(const Packet16i& a, const Packet16i& b) {
+ return _mm512_andnot_si512(b, a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pandnot<Packet16f>(const Packet16f& a, const Packet16f& b) {
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+ return _mm512_andnot_ps(b, a);
+#else
+ return _mm512_castsi512_ps(pandnot(_mm512_castps_si512(a),_mm512_castps_si512(b)));
+#endif
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pandnot<Packet8d>(const Packet8d& a,const Packet8d& b) {
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+ return _mm512_andnot_pd(b, a);
+#else
+ return _mm512_castsi512_pd(pandnot(_mm512_castpd_si512(a),_mm512_castpd_si512(b)));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet16f pround<Packet16f>(const Packet16f& a)
+{
+ // Work-around for default std::round rounding mode.
+ const Packet16f mask = pset1frombits<Packet16f>(static_cast<numext::uint32_t>(0x80000000u));
+ const Packet16f prev0dot5 = pset1frombits<Packet16f>(static_cast<numext::uint32_t>(0x3EFFFFFFu));
+ return _mm512_roundscale_ps(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO);
+}
+template<> EIGEN_STRONG_INLINE Packet8d pround<Packet8d>(const Packet8d& a)
+{
+ // Work-around for default std::round rounding mode.
+ const Packet8d mask = pset1frombits<Packet8d>(static_cast<numext::uint64_t>(0x8000000000000000ull));
+ const Packet8d prev0dot5 = pset1frombits<Packet8d>(static_cast<numext::uint64_t>(0x3FDFFFFFFFFFFFFFull));
+ return _mm512_roundscale_pd(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO);
+}
+
+template<int N> EIGEN_STRONG_INLINE Packet16i parithmetic_shift_right(Packet16i a) {
+ return _mm512_srai_epi32(a, N);
+}
+
+template<int N> EIGEN_STRONG_INLINE Packet16i plogical_shift_right(Packet16i a) {
+ return _mm512_srli_epi32(a, N);
+}
+
+template<int N> EIGEN_STRONG_INLINE Packet16i plogical_shift_left(Packet16i a) {
+ return _mm512_slli_epi32(a, N);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f pload<Packet16f>(const float* from) {
+ EIGEN_DEBUG_ALIGNED_LOAD return _mm512_load_ps(from);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pload<Packet8d>(const double* from) {
+ EIGEN_DEBUG_ALIGNED_LOAD return _mm512_load_pd(from);
+}
+template <>
+EIGEN_STRONG_INLINE Packet16i pload<Packet16i>(const int* from) {
+ EIGEN_DEBUG_ALIGNED_LOAD return _mm512_load_si512(
+ reinterpret_cast<const __m512i*>(from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f ploadu<Packet16f>(const float* from) {
+ EIGEN_DEBUG_UNALIGNED_LOAD return _mm512_loadu_ps(from);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d ploadu<Packet8d>(const double* from) {
+ EIGEN_DEBUG_UNALIGNED_LOAD return _mm512_loadu_pd(from);
+}
+template <>
+EIGEN_STRONG_INLINE Packet16i ploadu<Packet16i>(const int* from) {
+ EIGEN_DEBUG_UNALIGNED_LOAD return _mm512_loadu_si512(
+ reinterpret_cast<const __m512i*>(from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16f ploadu<Packet16f>(const float* from, uint16_t umask) {
+ __mmask16 mask = static_cast<__mmask16>(umask);
+ EIGEN_DEBUG_UNALIGNED_LOAD return _mm512_maskz_loadu_ps(mask, from);
+}
+
+// Loads 8 floats from memory a returns the packet
+// {a0, a0 a1, a1, a2, a2, a3, a3, a4, a4, a5, a5, a6, a6, a7, a7}
+template <>
+EIGEN_STRONG_INLINE Packet16f ploaddup<Packet16f>(const float* from) {
+ // an unaligned load is required here as there is no requirement
+ // on the alignment of input pointer 'from'
+ __m256i low_half = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(from));
+ __m512 even_elements = _mm512_castsi512_ps(_mm512_cvtepu32_epi64(low_half));
+ __m512 pairs = _mm512_permute_ps(even_elements, _MM_SHUFFLE(2, 2, 0, 0));
+ return pairs;
+}
+
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+// FIXME: this does not look optimal, better load a Packet4d and shuffle...
+// Loads 4 doubles from memory a returns the packet {a0, a0 a1, a1, a2, a2, a3,
+// a3}
+template <>
+EIGEN_STRONG_INLINE Packet8d ploaddup<Packet8d>(const double* from) {
+ __m512d x = _mm512_setzero_pd();
+ x = _mm512_insertf64x2(x, _mm_loaddup_pd(&from[0]), 0);
+ x = _mm512_insertf64x2(x, _mm_loaddup_pd(&from[1]), 1);
+ x = _mm512_insertf64x2(x, _mm_loaddup_pd(&from[2]), 2);
+ x = _mm512_insertf64x2(x, _mm_loaddup_pd(&from[3]), 3);
+ return x;
+}
+#else
+template <>
+EIGEN_STRONG_INLINE Packet8d ploaddup<Packet8d>(const double* from) {
+ __m512d x = _mm512_setzero_pd();
+ x = _mm512_mask_broadcastsd_pd(x, 0x3<<0, _mm_load_sd(from+0));
+ x = _mm512_mask_broadcastsd_pd(x, 0x3<<2, _mm_load_sd(from+1));
+ x = _mm512_mask_broadcastsd_pd(x, 0x3<<4, _mm_load_sd(from+2));
+ x = _mm512_mask_broadcastsd_pd(x, 0x3<<6, _mm_load_sd(from+3));
+ return x;
+}
+#endif
+
+// Loads 4 floats from memory a returns the packet
+// {a0, a0 a0, a0, a1, a1, a1, a1, a2, a2, a2, a2, a3, a3, a3, a3}
+template <>
+EIGEN_STRONG_INLINE Packet16f ploadquad<Packet16f>(const float* from) {
+ Packet16f tmp = _mm512_castps128_ps512(ploadu<Packet4f>(from));
+ const Packet16i scatter_mask = _mm512_set_epi32(3,3,3,3, 2,2,2,2, 1,1,1,1, 0,0,0,0);
+ return _mm512_permutexvar_ps(scatter_mask, tmp);
+}
+
+// Loads 2 doubles from memory a returns the packet
+// {a0, a0 a0, a0, a1, a1, a1, a1}
+template <>
+EIGEN_STRONG_INLINE Packet8d ploadquad<Packet8d>(const double* from) {
+ __m256d lane0 = _mm256_set1_pd(*from);
+ __m256d lane1 = _mm256_set1_pd(*(from+1));
+ __m512d tmp = _mm512_undefined_pd();
+ tmp = _mm512_insertf64x4(tmp, lane0, 0);
+ return _mm512_insertf64x4(tmp, lane1, 1);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet16f& from) {
+ EIGEN_DEBUG_ALIGNED_STORE _mm512_store_ps(to, from);
+}
+template <>
+EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet8d& from) {
+ EIGEN_DEBUG_ALIGNED_STORE _mm512_store_pd(to, from);
+}
+template <>
+EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet16i& from) {
+ EIGEN_DEBUG_ALIGNED_STORE _mm512_storeu_si512(reinterpret_cast<__m512i*>(to),
+ from);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet16f& from) {
+ EIGEN_DEBUG_UNALIGNED_STORE _mm512_storeu_ps(to, from);
+}
+template <>
+EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet8d& from) {
+ EIGEN_DEBUG_UNALIGNED_STORE _mm512_storeu_pd(to, from);
+}
+template <>
+EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet16i& from) {
+ EIGEN_DEBUG_UNALIGNED_STORE _mm512_storeu_si512(
+ reinterpret_cast<__m512i*>(to), from);
+}
+template <>
+EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet16f& from, uint16_t umask) {
+ __mmask16 mask = static_cast<__mmask16>(umask);
+ EIGEN_DEBUG_UNALIGNED_STORE return _mm512_mask_storeu_ps(to, mask, from);
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline Packet16f pgather<float, Packet16f>(const float* from,
+ Index stride) {
+ Packet16i stride_vector = _mm512_set1_epi32(convert_index<int>(stride));
+ Packet16i stride_multiplier =
+ _mm512_set_epi32(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
+ Packet16i indices = _mm512_mullo_epi32(stride_vector, stride_multiplier);
+
+ return _mm512_i32gather_ps(indices, from, 4);
+}
+template <>
+EIGEN_DEVICE_FUNC inline Packet8d pgather<double, Packet8d>(const double* from,
+ Index stride) {
+ Packet8i stride_vector = _mm256_set1_epi32(convert_index<int>(stride));
+ Packet8i stride_multiplier = _mm256_set_epi32(7, 6, 5, 4, 3, 2, 1, 0);
+ Packet8i indices = _mm256_mullo_epi32(stride_vector, stride_multiplier);
+
+ return _mm512_i32gather_pd(indices, from, 8);
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline void pscatter<float, Packet16f>(float* to,
+ const Packet16f& from,
+ Index stride) {
+ Packet16i stride_vector = _mm512_set1_epi32(convert_index<int>(stride));
+ Packet16i stride_multiplier =
+ _mm512_set_epi32(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
+ Packet16i indices = _mm512_mullo_epi32(stride_vector, stride_multiplier);
+ _mm512_i32scatter_ps(to, indices, from, 4);
+}
+template <>
+EIGEN_DEVICE_FUNC inline void pscatter<double, Packet8d>(double* to,
+ const Packet8d& from,
+ Index stride) {
+ Packet8i stride_vector = _mm256_set1_epi32(convert_index<int>(stride));
+ Packet8i stride_multiplier = _mm256_set_epi32(7, 6, 5, 4, 3, 2, 1, 0);
+ Packet8i indices = _mm256_mullo_epi32(stride_vector, stride_multiplier);
+ _mm512_i32scatter_pd(to, indices, from, 8);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstore1<Packet16f>(float* to, const float& a) {
+ Packet16f pa = pset1<Packet16f>(a);
+ pstore(to, pa);
+}
+template <>
+EIGEN_STRONG_INLINE void pstore1<Packet8d>(double* to, const double& a) {
+ Packet8d pa = pset1<Packet8d>(a);
+ pstore(to, pa);
+}
+template <>
+EIGEN_STRONG_INLINE void pstore1<Packet16i>(int* to, const int& a) {
+ Packet16i pa = pset1<Packet16i>(a);
+ pstore(to, pa);
+}
+
+template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
+template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
+template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
+
+template <>
+EIGEN_STRONG_INLINE float pfirst<Packet16f>(const Packet16f& a) {
+ return _mm_cvtss_f32(_mm512_extractf32x4_ps(a, 0));
+}
+template <>
+EIGEN_STRONG_INLINE double pfirst<Packet8d>(const Packet8d& a) {
+ return _mm_cvtsd_f64(_mm256_extractf128_pd(_mm512_extractf64x4_pd(a, 0), 0));
+}
+template <>
+EIGEN_STRONG_INLINE int pfirst<Packet16i>(const Packet16i& a) {
+ return _mm_extract_epi32(_mm512_extracti32x4_epi32(a, 0), 0);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16f preverse(const Packet16f& a)
+{
+ return _mm512_permutexvar_ps(_mm512_set_epi32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8d preverse(const Packet8d& a)
+{
+ return _mm512_permutexvar_pd(_mm512_set_epi32(0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7), a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16f pabs(const Packet16f& a)
+{
+ // _mm512_abs_ps intrinsic not found, so hack around it
+ return _mm512_castsi512_ps(_mm512_and_si512(_mm512_castps_si512(a), _mm512_set1_epi32(0x7fffffff)));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pabs(const Packet8d& a) {
+ // _mm512_abs_ps intrinsic not found, so hack around it
+ return _mm512_castsi512_pd(_mm512_and_si512(_mm512_castpd_si512(a),
+ _mm512_set1_epi64(0x7fffffffffffffff)));
+}
+
+template<>
+EIGEN_STRONG_INLINE Packet16f pfrexp<Packet16f>(const Packet16f& a, Packet16f& exponent){
+ return pfrexp_generic(a, exponent);
+}
+
+// Extract exponent without existence of Packet8l.
+template<>
+EIGEN_STRONG_INLINE
+Packet8d pfrexp_generic_get_biased_exponent(const Packet8d& a) {
+ const Packet8d cst_exp_mask = pset1frombits<Packet8d>(static_cast<uint64_t>(0x7ff0000000000000ull));
+ #ifdef EIGEN_VECTORIZE_AVX512DQ
+ return _mm512_cvtepi64_pd(_mm512_srli_epi64(_mm512_castpd_si512(pand(a, cst_exp_mask)), 52));
+ #else
+ return _mm512_cvtepi32_pd(_mm512_cvtepi64_epi32(_mm512_srli_epi64(_mm512_castpd_si512(pand(a, cst_exp_mask)), 52)));
+ #endif
+}
+
+template<>
+EIGEN_STRONG_INLINE Packet8d pfrexp<Packet8d>(const Packet8d& a, Packet8d& exponent) {
+ return pfrexp_generic(a, exponent);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16f pldexp<Packet16f>(const Packet16f& a, const Packet16f& exponent) {
+ return pldexp_generic(a, exponent);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8d pldexp<Packet8d>(const Packet8d& a, const Packet8d& exponent) {
+ // Clamp exponent to [-2099, 2099]
+ const Packet8d max_exponent = pset1<Packet8d>(2099.0);
+ const Packet8i e = _mm512_cvtpd_epi32(pmin(pmax(exponent, pnegate(max_exponent)), max_exponent));
+
+ // Split 2^e into four factors and multiply.
+ const Packet8i bias = pset1<Packet8i>(1023);
+ Packet8i b = parithmetic_shift_right<2>(e); // floor(e/4)
+
+ // 2^b
+ const Packet8i permute_idx = _mm256_setr_epi32(0, 4, 1, 5, 2, 6, 3, 7);
+ Packet8i hi = _mm256_permutevar8x32_epi32(padd(b, bias), permute_idx);
+ Packet8i lo = _mm256_slli_epi64(hi, 52);
+ hi = _mm256_slli_epi64(_mm256_srli_epi64(hi, 32), 52);
+ Packet8d c = _mm512_castsi512_pd(_mm512_inserti64x4(_mm512_castsi256_si512(lo), hi, 1));
+ Packet8d out = pmul(pmul(pmul(a, c), c), c); // a * 2^(3b)
+
+ // 2^(e - 3b)
+ b = psub(psub(psub(e, b), b), b); // e - 3b
+ hi = _mm256_permutevar8x32_epi32(padd(b, bias), permute_idx);
+ lo = _mm256_slli_epi64(hi, 52);
+ hi = _mm256_slli_epi64(_mm256_srli_epi64(hi, 32), 52);
+ c = _mm512_castsi512_pd(_mm512_inserti64x4(_mm512_castsi256_si512(lo), hi, 1));
+ out = pmul(out, c); // a * 2^e
+ return out;
+}
+
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+// AVX512F does not define _mm512_extractf32x8_ps to extract _m256 from _m512
+#define EIGEN_EXTRACT_8f_FROM_16f(INPUT, OUTPUT) \
+ __m256 OUTPUT##_0 = _mm512_extractf32x8_ps(INPUT, 0); \
+ __m256 OUTPUT##_1 = _mm512_extractf32x8_ps(INPUT, 1)
+#else
+#define EIGEN_EXTRACT_8f_FROM_16f(INPUT, OUTPUT) \
+ __m256 OUTPUT##_0 = _mm256_insertf128_ps( \
+ _mm256_castps128_ps256(_mm512_extractf32x4_ps(INPUT, 0)), \
+ _mm512_extractf32x4_ps(INPUT, 1), 1); \
+ __m256 OUTPUT##_1 = _mm256_insertf128_ps( \
+ _mm256_castps128_ps256(_mm512_extractf32x4_ps(INPUT, 2)), \
+ _mm512_extractf32x4_ps(INPUT, 3), 1);
+#endif
+
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+#define EIGEN_INSERT_8f_INTO_16f(OUTPUT, INPUTA, INPUTB) \
+ OUTPUT = _mm512_insertf32x8(_mm512_castps256_ps512(INPUTA), INPUTB, 1);
+#else
+#define EIGEN_INSERT_8f_INTO_16f(OUTPUT, INPUTA, INPUTB) \
+ OUTPUT = _mm512_undefined_ps(); \
+ OUTPUT = _mm512_insertf32x4(OUTPUT, _mm256_extractf128_ps(INPUTA, 0), 0); \
+ OUTPUT = _mm512_insertf32x4(OUTPUT, _mm256_extractf128_ps(INPUTA, 1), 1); \
+ OUTPUT = _mm512_insertf32x4(OUTPUT, _mm256_extractf128_ps(INPUTB, 0), 2); \
+ OUTPUT = _mm512_insertf32x4(OUTPUT, _mm256_extractf128_ps(INPUTB, 1), 3);
+#endif
+
+template <>
+EIGEN_STRONG_INLINE float predux<Packet16f>(const Packet16f& a) {
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+ __m256 lane0 = _mm512_extractf32x8_ps(a, 0);
+ __m256 lane1 = _mm512_extractf32x8_ps(a, 1);
+ Packet8f x = _mm256_add_ps(lane0, lane1);
+ return predux<Packet8f>(x);
+#else
+ __m128 lane0 = _mm512_extractf32x4_ps(a, 0);
+ __m128 lane1 = _mm512_extractf32x4_ps(a, 1);
+ __m128 lane2 = _mm512_extractf32x4_ps(a, 2);
+ __m128 lane3 = _mm512_extractf32x4_ps(a, 3);
+ __m128 sum = _mm_add_ps(_mm_add_ps(lane0, lane1), _mm_add_ps(lane2, lane3));
+ sum = _mm_hadd_ps(sum, sum);
+ sum = _mm_hadd_ps(sum, _mm_permute_ps(sum, 1));
+ return _mm_cvtss_f32(sum);
+#endif
+}
+template <>
+EIGEN_STRONG_INLINE double predux<Packet8d>(const Packet8d& a) {
+ __m256d lane0 = _mm512_extractf64x4_pd(a, 0);
+ __m256d lane1 = _mm512_extractf64x4_pd(a, 1);
+ __m256d sum = _mm256_add_pd(lane0, lane1);
+ __m256d tmp0 = _mm256_hadd_pd(sum, _mm256_permute2f128_pd(sum, sum, 1));
+ return _mm_cvtsd_f64(_mm256_castpd256_pd128(_mm256_hadd_pd(tmp0, tmp0)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8f predux_half_dowto4<Packet16f>(const Packet16f& a) {
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+ __m256 lane0 = _mm512_extractf32x8_ps(a, 0);
+ __m256 lane1 = _mm512_extractf32x8_ps(a, 1);
+ return _mm256_add_ps(lane0, lane1);
+#else
+ __m128 lane0 = _mm512_extractf32x4_ps(a, 0);
+ __m128 lane1 = _mm512_extractf32x4_ps(a, 1);
+ __m128 lane2 = _mm512_extractf32x4_ps(a, 2);
+ __m128 lane3 = _mm512_extractf32x4_ps(a, 3);
+ __m128 sum0 = _mm_add_ps(lane0, lane2);
+ __m128 sum1 = _mm_add_ps(lane1, lane3);
+ return _mm256_insertf128_ps(_mm256_castps128_ps256(sum0), sum1, 1);
+#endif
+}
+template <>
+EIGEN_STRONG_INLINE Packet4d predux_half_dowto4<Packet8d>(const Packet8d& a) {
+ __m256d lane0 = _mm512_extractf64x4_pd(a, 0);
+ __m256d lane1 = _mm512_extractf64x4_pd(a, 1);
+ return _mm256_add_pd(lane0, lane1);
+}
+
+template <>
+EIGEN_STRONG_INLINE float predux_mul<Packet16f>(const Packet16f& a) {
+//#ifdef EIGEN_VECTORIZE_AVX512DQ
+#if 0
+ Packet8f lane0 = _mm512_extractf32x8_ps(a, 0);
+ Packet8f lane1 = _mm512_extractf32x8_ps(a, 1);
+ Packet8f res = pmul(lane0, lane1);
+ res = pmul(res, _mm256_permute2f128_ps(res, res, 1));
+ res = pmul(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 3, 2)));
+ return pfirst(pmul(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 0, 1))));
+#else
+ __m128 lane0 = _mm512_extractf32x4_ps(a, 0);
+ __m128 lane1 = _mm512_extractf32x4_ps(a, 1);
+ __m128 lane2 = _mm512_extractf32x4_ps(a, 2);
+ __m128 lane3 = _mm512_extractf32x4_ps(a, 3);
+ __m128 res = pmul(pmul(lane0, lane1), pmul(lane2, lane3));
+ res = pmul(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 3, 2)));
+ return pfirst(pmul(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 0, 1))));
+#endif
+}
+template <>
+EIGEN_STRONG_INLINE double predux_mul<Packet8d>(const Packet8d& a) {
+ __m256d lane0 = _mm512_extractf64x4_pd(a, 0);
+ __m256d lane1 = _mm512_extractf64x4_pd(a, 1);
+ __m256d res = pmul(lane0, lane1);
+ res = pmul(res, _mm256_permute2f128_pd(res, res, 1));
+ return pfirst(pmul(res, _mm256_shuffle_pd(res, res, 1)));
+}
+
+template <>
+EIGEN_STRONG_INLINE float predux_min<Packet16f>(const Packet16f& a) {
+ __m128 lane0 = _mm512_extractf32x4_ps(a, 0);
+ __m128 lane1 = _mm512_extractf32x4_ps(a, 1);
+ __m128 lane2 = _mm512_extractf32x4_ps(a, 2);
+ __m128 lane3 = _mm512_extractf32x4_ps(a, 3);
+ __m128 res = _mm_min_ps(_mm_min_ps(lane0, lane1), _mm_min_ps(lane2, lane3));
+ res = _mm_min_ps(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 3, 2)));
+ return pfirst(_mm_min_ps(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 0, 1))));
+}
+template <>
+EIGEN_STRONG_INLINE double predux_min<Packet8d>(const Packet8d& a) {
+ __m256d lane0 = _mm512_extractf64x4_pd(a, 0);
+ __m256d lane1 = _mm512_extractf64x4_pd(a, 1);
+ __m256d res = _mm256_min_pd(lane0, lane1);
+ res = _mm256_min_pd(res, _mm256_permute2f128_pd(res, res, 1));
+ return pfirst(_mm256_min_pd(res, _mm256_shuffle_pd(res, res, 1)));
+}
+
+template <>
+EIGEN_STRONG_INLINE float predux_max<Packet16f>(const Packet16f& a) {
+ __m128 lane0 = _mm512_extractf32x4_ps(a, 0);
+ __m128 lane1 = _mm512_extractf32x4_ps(a, 1);
+ __m128 lane2 = _mm512_extractf32x4_ps(a, 2);
+ __m128 lane3 = _mm512_extractf32x4_ps(a, 3);
+ __m128 res = _mm_max_ps(_mm_max_ps(lane0, lane1), _mm_max_ps(lane2, lane3));
+ res = _mm_max_ps(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 3, 2)));
+ return pfirst(_mm_max_ps(res, _mm_permute_ps(res, _MM_SHUFFLE(0, 0, 0, 1))));
+}
+
+template <>
+EIGEN_STRONG_INLINE double predux_max<Packet8d>(const Packet8d& a) {
+ __m256d lane0 = _mm512_extractf64x4_pd(a, 0);
+ __m256d lane1 = _mm512_extractf64x4_pd(a, 1);
+ __m256d res = _mm256_max_pd(lane0, lane1);
+ res = _mm256_max_pd(res, _mm256_permute2f128_pd(res, res, 1));
+ return pfirst(_mm256_max_pd(res, _mm256_shuffle_pd(res, res, 1)));
+}
+
+template<> EIGEN_STRONG_INLINE bool predux_any(const Packet16f& x)
+{
+ Packet16i xi = _mm512_castps_si512(x);
+ __mmask16 tmp = _mm512_test_epi32_mask(xi,xi);
+ return !_mm512_kortestz(tmp,tmp);
+}
+
+
+
+#define PACK_OUTPUT(OUTPUT, INPUT, INDEX, STRIDE) \
+ EIGEN_INSERT_8f_INTO_16f(OUTPUT[INDEX], INPUT[INDEX], INPUT[INDEX + STRIDE]);
+
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet16f, 16>& kernel) {
+ __m512 T0 = _mm512_unpacklo_ps(kernel.packet[0], kernel.packet[1]);
+ __m512 T1 = _mm512_unpackhi_ps(kernel.packet[0], kernel.packet[1]);
+ __m512 T2 = _mm512_unpacklo_ps(kernel.packet[2], kernel.packet[3]);
+ __m512 T3 = _mm512_unpackhi_ps(kernel.packet[2], kernel.packet[3]);
+ __m512 T4 = _mm512_unpacklo_ps(kernel.packet[4], kernel.packet[5]);
+ __m512 T5 = _mm512_unpackhi_ps(kernel.packet[4], kernel.packet[5]);
+ __m512 T6 = _mm512_unpacklo_ps(kernel.packet[6], kernel.packet[7]);
+ __m512 T7 = _mm512_unpackhi_ps(kernel.packet[6], kernel.packet[7]);
+ __m512 T8 = _mm512_unpacklo_ps(kernel.packet[8], kernel.packet[9]);
+ __m512 T9 = _mm512_unpackhi_ps(kernel.packet[8], kernel.packet[9]);
+ __m512 T10 = _mm512_unpacklo_ps(kernel.packet[10], kernel.packet[11]);
+ __m512 T11 = _mm512_unpackhi_ps(kernel.packet[10], kernel.packet[11]);
+ __m512 T12 = _mm512_unpacklo_ps(kernel.packet[12], kernel.packet[13]);
+ __m512 T13 = _mm512_unpackhi_ps(kernel.packet[12], kernel.packet[13]);
+ __m512 T14 = _mm512_unpacklo_ps(kernel.packet[14], kernel.packet[15]);
+ __m512 T15 = _mm512_unpackhi_ps(kernel.packet[14], kernel.packet[15]);
+ __m512 S0 = _mm512_shuffle_ps(T0, T2, _MM_SHUFFLE(1, 0, 1, 0));
+ __m512 S1 = _mm512_shuffle_ps(T0, T2, _MM_SHUFFLE(3, 2, 3, 2));
+ __m512 S2 = _mm512_shuffle_ps(T1, T3, _MM_SHUFFLE(1, 0, 1, 0));
+ __m512 S3 = _mm512_shuffle_ps(T1, T3, _MM_SHUFFLE(3, 2, 3, 2));
+ __m512 S4 = _mm512_shuffle_ps(T4, T6, _MM_SHUFFLE(1, 0, 1, 0));
+ __m512 S5 = _mm512_shuffle_ps(T4, T6, _MM_SHUFFLE(3, 2, 3, 2));
+ __m512 S6 = _mm512_shuffle_ps(T5, T7, _MM_SHUFFLE(1, 0, 1, 0));
+ __m512 S7 = _mm512_shuffle_ps(T5, T7, _MM_SHUFFLE(3, 2, 3, 2));
+ __m512 S8 = _mm512_shuffle_ps(T8, T10, _MM_SHUFFLE(1, 0, 1, 0));
+ __m512 S9 = _mm512_shuffle_ps(T8, T10, _MM_SHUFFLE(3, 2, 3, 2));
+ __m512 S10 = _mm512_shuffle_ps(T9, T11, _MM_SHUFFLE(1, 0, 1, 0));
+ __m512 S11 = _mm512_shuffle_ps(T9, T11, _MM_SHUFFLE(3, 2, 3, 2));
+ __m512 S12 = _mm512_shuffle_ps(T12, T14, _MM_SHUFFLE(1, 0, 1, 0));
+ __m512 S13 = _mm512_shuffle_ps(T12, T14, _MM_SHUFFLE(3, 2, 3, 2));
+ __m512 S14 = _mm512_shuffle_ps(T13, T15, _MM_SHUFFLE(1, 0, 1, 0));
+ __m512 S15 = _mm512_shuffle_ps(T13, T15, _MM_SHUFFLE(3, 2, 3, 2));
+
+ EIGEN_EXTRACT_8f_FROM_16f(S0, S0);
+ EIGEN_EXTRACT_8f_FROM_16f(S1, S1);
+ EIGEN_EXTRACT_8f_FROM_16f(S2, S2);
+ EIGEN_EXTRACT_8f_FROM_16f(S3, S3);
+ EIGEN_EXTRACT_8f_FROM_16f(S4, S4);
+ EIGEN_EXTRACT_8f_FROM_16f(S5, S5);
+ EIGEN_EXTRACT_8f_FROM_16f(S6, S6);
+ EIGEN_EXTRACT_8f_FROM_16f(S7, S7);
+ EIGEN_EXTRACT_8f_FROM_16f(S8, S8);
+ EIGEN_EXTRACT_8f_FROM_16f(S9, S9);
+ EIGEN_EXTRACT_8f_FROM_16f(S10, S10);
+ EIGEN_EXTRACT_8f_FROM_16f(S11, S11);
+ EIGEN_EXTRACT_8f_FROM_16f(S12, S12);
+ EIGEN_EXTRACT_8f_FROM_16f(S13, S13);
+ EIGEN_EXTRACT_8f_FROM_16f(S14, S14);
+ EIGEN_EXTRACT_8f_FROM_16f(S15, S15);
+
+ PacketBlock<Packet8f, 32> tmp;
+
+ tmp.packet[0] = _mm256_permute2f128_ps(S0_0, S4_0, 0x20);
+ tmp.packet[1] = _mm256_permute2f128_ps(S1_0, S5_0, 0x20);
+ tmp.packet[2] = _mm256_permute2f128_ps(S2_0, S6_0, 0x20);
+ tmp.packet[3] = _mm256_permute2f128_ps(S3_0, S7_0, 0x20);
+ tmp.packet[4] = _mm256_permute2f128_ps(S0_0, S4_0, 0x31);
+ tmp.packet[5] = _mm256_permute2f128_ps(S1_0, S5_0, 0x31);
+ tmp.packet[6] = _mm256_permute2f128_ps(S2_0, S6_0, 0x31);
+ tmp.packet[7] = _mm256_permute2f128_ps(S3_0, S7_0, 0x31);
+
+ tmp.packet[8] = _mm256_permute2f128_ps(S0_1, S4_1, 0x20);
+ tmp.packet[9] = _mm256_permute2f128_ps(S1_1, S5_1, 0x20);
+ tmp.packet[10] = _mm256_permute2f128_ps(S2_1, S6_1, 0x20);
+ tmp.packet[11] = _mm256_permute2f128_ps(S3_1, S7_1, 0x20);
+ tmp.packet[12] = _mm256_permute2f128_ps(S0_1, S4_1, 0x31);
+ tmp.packet[13] = _mm256_permute2f128_ps(S1_1, S5_1, 0x31);
+ tmp.packet[14] = _mm256_permute2f128_ps(S2_1, S6_1, 0x31);
+ tmp.packet[15] = _mm256_permute2f128_ps(S3_1, S7_1, 0x31);
+
+ // Second set of _m256 outputs
+ tmp.packet[16] = _mm256_permute2f128_ps(S8_0, S12_0, 0x20);
+ tmp.packet[17] = _mm256_permute2f128_ps(S9_0, S13_0, 0x20);
+ tmp.packet[18] = _mm256_permute2f128_ps(S10_0, S14_0, 0x20);
+ tmp.packet[19] = _mm256_permute2f128_ps(S11_0, S15_0, 0x20);
+ tmp.packet[20] = _mm256_permute2f128_ps(S8_0, S12_0, 0x31);
+ tmp.packet[21] = _mm256_permute2f128_ps(S9_0, S13_0, 0x31);
+ tmp.packet[22] = _mm256_permute2f128_ps(S10_0, S14_0, 0x31);
+ tmp.packet[23] = _mm256_permute2f128_ps(S11_0, S15_0, 0x31);
+
+ tmp.packet[24] = _mm256_permute2f128_ps(S8_1, S12_1, 0x20);
+ tmp.packet[25] = _mm256_permute2f128_ps(S9_1, S13_1, 0x20);
+ tmp.packet[26] = _mm256_permute2f128_ps(S10_1, S14_1, 0x20);
+ tmp.packet[27] = _mm256_permute2f128_ps(S11_1, S15_1, 0x20);
+ tmp.packet[28] = _mm256_permute2f128_ps(S8_1, S12_1, 0x31);
+ tmp.packet[29] = _mm256_permute2f128_ps(S9_1, S13_1, 0x31);
+ tmp.packet[30] = _mm256_permute2f128_ps(S10_1, S14_1, 0x31);
+ tmp.packet[31] = _mm256_permute2f128_ps(S11_1, S15_1, 0x31);
+
+ // Pack them into the output
+ PACK_OUTPUT(kernel.packet, tmp.packet, 0, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 1, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 2, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 3, 16);
+
+ PACK_OUTPUT(kernel.packet, tmp.packet, 4, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 5, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 6, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 7, 16);
+
+ PACK_OUTPUT(kernel.packet, tmp.packet, 8, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 9, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 10, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 11, 16);
+
+ PACK_OUTPUT(kernel.packet, tmp.packet, 12, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 13, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 14, 16);
+ PACK_OUTPUT(kernel.packet, tmp.packet, 15, 16);
+}
+#define PACK_OUTPUT_2(OUTPUT, INPUT, INDEX, STRIDE) \
+ EIGEN_INSERT_8f_INTO_16f(OUTPUT[INDEX], INPUT[2 * INDEX], \
+ INPUT[2 * INDEX + STRIDE]);
+
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet16f, 4>& kernel) {
+ __m512 T0 = _mm512_unpacklo_ps(kernel.packet[0], kernel.packet[1]);
+ __m512 T1 = _mm512_unpackhi_ps(kernel.packet[0], kernel.packet[1]);
+ __m512 T2 = _mm512_unpacklo_ps(kernel.packet[2], kernel.packet[3]);
+ __m512 T3 = _mm512_unpackhi_ps(kernel.packet[2], kernel.packet[3]);
+
+ __m512 S0 = _mm512_shuffle_ps(T0, T2, _MM_SHUFFLE(1, 0, 1, 0));
+ __m512 S1 = _mm512_shuffle_ps(T0, T2, _MM_SHUFFLE(3, 2, 3, 2));
+ __m512 S2 = _mm512_shuffle_ps(T1, T3, _MM_SHUFFLE(1, 0, 1, 0));
+ __m512 S3 = _mm512_shuffle_ps(T1, T3, _MM_SHUFFLE(3, 2, 3, 2));
+
+ EIGEN_EXTRACT_8f_FROM_16f(S0, S0);
+ EIGEN_EXTRACT_8f_FROM_16f(S1, S1);
+ EIGEN_EXTRACT_8f_FROM_16f(S2, S2);
+ EIGEN_EXTRACT_8f_FROM_16f(S3, S3);
+
+ PacketBlock<Packet8f, 8> tmp;
+
+ tmp.packet[0] = _mm256_permute2f128_ps(S0_0, S1_0, 0x20);
+ tmp.packet[1] = _mm256_permute2f128_ps(S2_0, S3_0, 0x20);
+ tmp.packet[2] = _mm256_permute2f128_ps(S0_0, S1_0, 0x31);
+ tmp.packet[3] = _mm256_permute2f128_ps(S2_0, S3_0, 0x31);
+
+ tmp.packet[4] = _mm256_permute2f128_ps(S0_1, S1_1, 0x20);
+ tmp.packet[5] = _mm256_permute2f128_ps(S2_1, S3_1, 0x20);
+ tmp.packet[6] = _mm256_permute2f128_ps(S0_1, S1_1, 0x31);
+ tmp.packet[7] = _mm256_permute2f128_ps(S2_1, S3_1, 0x31);
+
+ PACK_OUTPUT_2(kernel.packet, tmp.packet, 0, 1);
+ PACK_OUTPUT_2(kernel.packet, tmp.packet, 1, 1);
+ PACK_OUTPUT_2(kernel.packet, tmp.packet, 2, 1);
+ PACK_OUTPUT_2(kernel.packet, tmp.packet, 3, 1);
+}
+
+#define PACK_OUTPUT_SQ_D(OUTPUT, INPUT, INDEX, STRIDE) \
+ OUTPUT[INDEX] = _mm512_insertf64x4(OUTPUT[INDEX], INPUT[INDEX], 0); \
+ OUTPUT[INDEX] = _mm512_insertf64x4(OUTPUT[INDEX], INPUT[INDEX + STRIDE], 1);
+
+#define PACK_OUTPUT_D(OUTPUT, INPUT, INDEX, STRIDE) \
+ OUTPUT[INDEX] = _mm512_insertf64x4(OUTPUT[INDEX], INPUT[(2 * INDEX)], 0); \
+ OUTPUT[INDEX] = \
+ _mm512_insertf64x4(OUTPUT[INDEX], INPUT[(2 * INDEX) + STRIDE], 1);
+
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet8d, 4>& kernel) {
+ __m512d T0 = _mm512_shuffle_pd(kernel.packet[0], kernel.packet[1], 0);
+ __m512d T1 = _mm512_shuffle_pd(kernel.packet[0], kernel.packet[1], 0xff);
+ __m512d T2 = _mm512_shuffle_pd(kernel.packet[2], kernel.packet[3], 0);
+ __m512d T3 = _mm512_shuffle_pd(kernel.packet[2], kernel.packet[3], 0xff);
+
+ PacketBlock<Packet4d, 8> tmp;
+
+ tmp.packet[0] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 0),
+ _mm512_extractf64x4_pd(T2, 0), 0x20);
+ tmp.packet[1] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 0),
+ _mm512_extractf64x4_pd(T3, 0), 0x20);
+ tmp.packet[2] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 0),
+ _mm512_extractf64x4_pd(T2, 0), 0x31);
+ tmp.packet[3] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 0),
+ _mm512_extractf64x4_pd(T3, 0), 0x31);
+
+ tmp.packet[4] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 1),
+ _mm512_extractf64x4_pd(T2, 1), 0x20);
+ tmp.packet[5] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 1),
+ _mm512_extractf64x4_pd(T3, 1), 0x20);
+ tmp.packet[6] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 1),
+ _mm512_extractf64x4_pd(T2, 1), 0x31);
+ tmp.packet[7] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 1),
+ _mm512_extractf64x4_pd(T3, 1), 0x31);
+
+ PACK_OUTPUT_D(kernel.packet, tmp.packet, 0, 1);
+ PACK_OUTPUT_D(kernel.packet, tmp.packet, 1, 1);
+ PACK_OUTPUT_D(kernel.packet, tmp.packet, 2, 1);
+ PACK_OUTPUT_D(kernel.packet, tmp.packet, 3, 1);
+}
+
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet8d, 8>& kernel) {
+ __m512d T0 = _mm512_unpacklo_pd(kernel.packet[0], kernel.packet[1]);
+ __m512d T1 = _mm512_unpackhi_pd(kernel.packet[0], kernel.packet[1]);
+ __m512d T2 = _mm512_unpacklo_pd(kernel.packet[2], kernel.packet[3]);
+ __m512d T3 = _mm512_unpackhi_pd(kernel.packet[2], kernel.packet[3]);
+ __m512d T4 = _mm512_unpacklo_pd(kernel.packet[4], kernel.packet[5]);
+ __m512d T5 = _mm512_unpackhi_pd(kernel.packet[4], kernel.packet[5]);
+ __m512d T6 = _mm512_unpacklo_pd(kernel.packet[6], kernel.packet[7]);
+ __m512d T7 = _mm512_unpackhi_pd(kernel.packet[6], kernel.packet[7]);
+
+ PacketBlock<Packet4d, 16> tmp;
+
+ tmp.packet[0] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 0),
+ _mm512_extractf64x4_pd(T2, 0), 0x20);
+ tmp.packet[1] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 0),
+ _mm512_extractf64x4_pd(T3, 0), 0x20);
+ tmp.packet[2] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 0),
+ _mm512_extractf64x4_pd(T2, 0), 0x31);
+ tmp.packet[3] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 0),
+ _mm512_extractf64x4_pd(T3, 0), 0x31);
+
+ tmp.packet[4] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 1),
+ _mm512_extractf64x4_pd(T2, 1), 0x20);
+ tmp.packet[5] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 1),
+ _mm512_extractf64x4_pd(T3, 1), 0x20);
+ tmp.packet[6] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T0, 1),
+ _mm512_extractf64x4_pd(T2, 1), 0x31);
+ tmp.packet[7] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T1, 1),
+ _mm512_extractf64x4_pd(T3, 1), 0x31);
+
+ tmp.packet[8] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T4, 0),
+ _mm512_extractf64x4_pd(T6, 0), 0x20);
+ tmp.packet[9] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T5, 0),
+ _mm512_extractf64x4_pd(T7, 0), 0x20);
+ tmp.packet[10] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T4, 0),
+ _mm512_extractf64x4_pd(T6, 0), 0x31);
+ tmp.packet[11] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T5, 0),
+ _mm512_extractf64x4_pd(T7, 0), 0x31);
+
+ tmp.packet[12] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T4, 1),
+ _mm512_extractf64x4_pd(T6, 1), 0x20);
+ tmp.packet[13] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T5, 1),
+ _mm512_extractf64x4_pd(T7, 1), 0x20);
+ tmp.packet[14] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T4, 1),
+ _mm512_extractf64x4_pd(T6, 1), 0x31);
+ tmp.packet[15] = _mm256_permute2f128_pd(_mm512_extractf64x4_pd(T5, 1),
+ _mm512_extractf64x4_pd(T7, 1), 0x31);
+
+ PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 0, 8);
+ PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 1, 8);
+ PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 2, 8);
+ PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 3, 8);
+
+ PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 4, 8);
+ PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 5, 8);
+ PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 6, 8);
+ PACK_OUTPUT_SQ_D(kernel.packet, tmp.packet, 7, 8);
+}
+template <>
+EIGEN_STRONG_INLINE Packet16f pblend(const Selector<16>& /*ifPacket*/,
+ const Packet16f& /*thenPacket*/,
+ const Packet16f& /*elsePacket*/) {
+ assert(false && "To be implemented");
+ return Packet16f();
+}
+template <>
+EIGEN_STRONG_INLINE Packet8d pblend(const Selector<8>& ifPacket,
+ const Packet8d& thenPacket,
+ const Packet8d& elsePacket) {
+ __mmask8 m = (ifPacket.select[0] )
+ | (ifPacket.select[1]<<1)
+ | (ifPacket.select[2]<<2)
+ | (ifPacket.select[3]<<3)
+ | (ifPacket.select[4]<<4)
+ | (ifPacket.select[5]<<5)
+ | (ifPacket.select[6]<<6)
+ | (ifPacket.select[7]<<7);
+ return _mm512_mask_blend_pd(m, elsePacket, thenPacket);
+}
+
+// Packet math for Eigen::half
+template<> EIGEN_STRONG_INLINE Packet16h pset1<Packet16h>(const Eigen::half& from) {
+ return _mm256_set1_epi16(from.x);
+}
+
+template<> EIGEN_STRONG_INLINE Eigen::half pfirst<Packet16h>(const Packet16h& from) {
+ return half_impl::raw_uint16_to_half(static_cast<unsigned short>(_mm256_extract_epi16(from, 0)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pload<Packet16h>(const Eigen::half* from) {
+ return _mm256_load_si256(reinterpret_cast<const __m256i*>(from));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h ploadu<Packet16h>(const Eigen::half* from) {
+ return _mm256_loadu_si256(reinterpret_cast<const __m256i*>(from));
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<half>(Eigen::half* to, const Packet16h& from) {
+ // (void*) -> workaround clang warning:
+ // cast from 'Eigen::half *' to '__m256i *' increases required alignment from 2 to 32
+ _mm256_store_si256((__m256i*)(void*)to, from);
+}
+
+template<> EIGEN_STRONG_INLINE void pstoreu<half>(Eigen::half* to, const Packet16h& from) {
+ // (void*) -> workaround clang warning:
+ // cast from 'Eigen::half *' to '__m256i *' increases required alignment from 2 to 32
+ _mm256_storeu_si256((__m256i*)(void*)to, from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h
+ploaddup<Packet16h>(const Eigen::half* from) {
+ unsigned short a = from[0].x;
+ unsigned short b = from[1].x;
+ unsigned short c = from[2].x;
+ unsigned short d = from[3].x;
+ unsigned short e = from[4].x;
+ unsigned short f = from[5].x;
+ unsigned short g = from[6].x;
+ unsigned short h = from[7].x;
+ return _mm256_set_epi16(h, h, g, g, f, f, e, e, d, d, c, c, b, b, a, a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h
+ploadquad(const Eigen::half* from) {
+ unsigned short a = from[0].x;
+ unsigned short b = from[1].x;
+ unsigned short c = from[2].x;
+ unsigned short d = from[3].x;
+ return _mm256_set_epi16(d, d, d, d, c, c, c, c, b, b, b, b, a, a, a, a);
+}
+
+EIGEN_STRONG_INLINE Packet16f half2float(const Packet16h& a) {
+#ifdef EIGEN_HAS_FP16_C
+ return _mm512_cvtph_ps(a);
+#else
+ EIGEN_ALIGN64 half aux[16];
+ pstore(aux, a);
+ float f0(aux[0]);
+ float f1(aux[1]);
+ float f2(aux[2]);
+ float f3(aux[3]);
+ float f4(aux[4]);
+ float f5(aux[5]);
+ float f6(aux[6]);
+ float f7(aux[7]);
+ float f8(aux[8]);
+ float f9(aux[9]);
+ float fa(aux[10]);
+ float fb(aux[11]);
+ float fc(aux[12]);
+ float fd(aux[13]);
+ float fe(aux[14]);
+ float ff(aux[15]);
+
+ return _mm512_set_ps(
+ ff, fe, fd, fc, fb, fa, f9, f8, f7, f6, f5, f4, f3, f2, f1, f0);
+#endif
+}
+
+EIGEN_STRONG_INLINE Packet16h float2half(const Packet16f& a) {
+#ifdef EIGEN_HAS_FP16_C
+ return _mm512_cvtps_ph(a, _MM_FROUND_TO_NEAREST_INT|_MM_FROUND_NO_EXC);
+#else
+ EIGEN_ALIGN64 float aux[16];
+ pstore(aux, a);
+ half h0(aux[0]);
+ half h1(aux[1]);
+ half h2(aux[2]);
+ half h3(aux[3]);
+ half h4(aux[4]);
+ half h5(aux[5]);
+ half h6(aux[6]);
+ half h7(aux[7]);
+ half h8(aux[8]);
+ half h9(aux[9]);
+ half ha(aux[10]);
+ half hb(aux[11]);
+ half hc(aux[12]);
+ half hd(aux[13]);
+ half he(aux[14]);
+ half hf(aux[15]);
+
+ return _mm256_set_epi16(
+ hf.x, he.x, hd.x, hc.x, hb.x, ha.x, h9.x, h8.x,
+ h7.x, h6.x, h5.x, h4.x, h3.x, h2.x, h1.x, h0.x);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h ptrue(const Packet16h& a) {
+ return ptrue(Packet8i(a));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16h pabs(const Packet16h& a) {
+ const __m256i sign_mask = _mm256_set1_epi16(static_cast<numext::uint16_t>(0x8000));
+ return _mm256_andnot_si256(sign_mask, a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16h pmin<Packet16h>(const Packet16h& a,
+ const Packet16h& b) {
+ return float2half(pmin<Packet16f>(half2float(a), half2float(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16h pmax<Packet16h>(const Packet16h& a,
+ const Packet16h& b) {
+ return float2half(pmax<Packet16f>(half2float(a), half2float(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16h plset<Packet16h>(const half& a) {
+ return float2half(plset<Packet16f>(static_cast<float>(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h por(const Packet16h& a,const Packet16h& b) {
+ // in some cases Packet8i is a wrapper around __m256i, so we need to
+ // cast to Packet8i to call the correct overload.
+ return por(Packet8i(a),Packet8i(b));
+}
+template<> EIGEN_STRONG_INLINE Packet16h pxor(const Packet16h& a,const Packet16h& b) {
+ return pxor(Packet8i(a),Packet8i(b));
+}
+template<> EIGEN_STRONG_INLINE Packet16h pand(const Packet16h& a,const Packet16h& b) {
+ return pand(Packet8i(a),Packet8i(b));
+}
+template<> EIGEN_STRONG_INLINE Packet16h pandnot(const Packet16h& a,const Packet16h& b) {
+ return pandnot(Packet8i(a),Packet8i(b));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pselect(const Packet16h& mask, const Packet16h& a, const Packet16h& b) {
+ return _mm256_blendv_epi8(b, a, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pround<Packet16h>(const Packet16h& a) {
+ return float2half(pround<Packet16f>(half2float(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h print<Packet16h>(const Packet16h& a) {
+ return float2half(print<Packet16f>(half2float(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pceil<Packet16h>(const Packet16h& a) {
+ return float2half(pceil<Packet16f>(half2float(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pfloor<Packet16h>(const Packet16h& a) {
+ return float2half(pfloor<Packet16f>(half2float(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pcmp_eq(const Packet16h& a,const Packet16h& b) {
+ Packet16f af = half2float(a);
+ Packet16f bf = half2float(b);
+ return Pack32To16(pcmp_eq(af, bf));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pcmp_le(const Packet16h& a,const Packet16h& b) {
+ return Pack32To16(pcmp_le(half2float(a), half2float(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pcmp_lt(const Packet16h& a,const Packet16h& b) {
+ return Pack32To16(pcmp_lt(half2float(a), half2float(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pcmp_lt_or_nan(const Packet16h& a,const Packet16h& b) {
+ return Pack32To16(pcmp_lt_or_nan(half2float(a), half2float(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pconj(const Packet16h& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet16h pnegate(const Packet16h& a) {
+ Packet16h sign_mask = _mm256_set1_epi16(static_cast<unsigned short>(0x8000));
+ return _mm256_xor_si256(a, sign_mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h padd<Packet16h>(const Packet16h& a, const Packet16h& b) {
+ Packet16f af = half2float(a);
+ Packet16f bf = half2float(b);
+ Packet16f rf = padd(af, bf);
+ return float2half(rf);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h psub<Packet16h>(const Packet16h& a, const Packet16h& b) {
+ Packet16f af = half2float(a);
+ Packet16f bf = half2float(b);
+ Packet16f rf = psub(af, bf);
+ return float2half(rf);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pmul<Packet16h>(const Packet16h& a, const Packet16h& b) {
+ Packet16f af = half2float(a);
+ Packet16f bf = half2float(b);
+ Packet16f rf = pmul(af, bf);
+ return float2half(rf);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pdiv<Packet16h>(const Packet16h& a, const Packet16h& b) {
+ Packet16f af = half2float(a);
+ Packet16f bf = half2float(b);
+ Packet16f rf = pdiv(af, bf);
+ return float2half(rf);
+}
+
+template<> EIGEN_STRONG_INLINE half predux<Packet16h>(const Packet16h& from) {
+ Packet16f from_float = half2float(from);
+ return half(predux(from_float));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8h predux_half_dowto4<Packet16h>(const Packet16h& a) {
+ Packet8h lane0 = _mm256_extractf128_si256(a, 0);
+ Packet8h lane1 = _mm256_extractf128_si256(a, 1);
+ return padd<Packet8h>(lane0, lane1);
+}
+
+template<> EIGEN_STRONG_INLINE Eigen::half predux_max<Packet16h>(const Packet16h& a) {
+ Packet16f af = half2float(a);
+ float reduced = predux_max<Packet16f>(af);
+ return Eigen::half(reduced);
+}
+
+template<> EIGEN_STRONG_INLINE Eigen::half predux_min<Packet16h>(const Packet16h& a) {
+ Packet16f af = half2float(a);
+ float reduced = predux_min<Packet16f>(af);
+ return Eigen::half(reduced);
+}
+
+template<> EIGEN_STRONG_INLINE half predux_mul<Packet16h>(const Packet16h& from) {
+ Packet16f from_float = half2float(from);
+ return half(predux_mul(from_float));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h preverse(const Packet16h& a)
+{
+ __m128i m = _mm_setr_epi8(14,15,12,13,10,11,8,9,6,7,4,5,2,3,0,1);
+ return _mm256_insertf128_si256(
+ _mm256_castsi128_si256(_mm_shuffle_epi8(_mm256_extractf128_si256(a,1),m)),
+ _mm_shuffle_epi8(_mm256_extractf128_si256(a,0),m), 1);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16h pgather<Eigen::half, Packet16h>(const Eigen::half* from, Index stride)
+{
+ return _mm256_set_epi16(
+ from[15*stride].x, from[14*stride].x, from[13*stride].x, from[12*stride].x,
+ from[11*stride].x, from[10*stride].x, from[9*stride].x, from[8*stride].x,
+ from[7*stride].x, from[6*stride].x, from[5*stride].x, from[4*stride].x,
+ from[3*stride].x, from[2*stride].x, from[1*stride].x, from[0*stride].x);
+}
+
+template<> EIGEN_STRONG_INLINE void pscatter<half, Packet16h>(half* to, const Packet16h& from, Index stride)
+{
+ EIGEN_ALIGN64 half aux[16];
+ pstore(aux, from);
+ to[stride*0] = aux[0];
+ to[stride*1] = aux[1];
+ to[stride*2] = aux[2];
+ to[stride*3] = aux[3];
+ to[stride*4] = aux[4];
+ to[stride*5] = aux[5];
+ to[stride*6] = aux[6];
+ to[stride*7] = aux[7];
+ to[stride*8] = aux[8];
+ to[stride*9] = aux[9];
+ to[stride*10] = aux[10];
+ to[stride*11] = aux[11];
+ to[stride*12] = aux[12];
+ to[stride*13] = aux[13];
+ to[stride*14] = aux[14];
+ to[stride*15] = aux[15];
+}
+
+EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet16h,16>& kernel) {
+ __m256i a = kernel.packet[0];
+ __m256i b = kernel.packet[1];
+ __m256i c = kernel.packet[2];
+ __m256i d = kernel.packet[3];
+ __m256i e = kernel.packet[4];
+ __m256i f = kernel.packet[5];
+ __m256i g = kernel.packet[6];
+ __m256i h = kernel.packet[7];
+ __m256i i = kernel.packet[8];
+ __m256i j = kernel.packet[9];
+ __m256i k = kernel.packet[10];
+ __m256i l = kernel.packet[11];
+ __m256i m = kernel.packet[12];
+ __m256i n = kernel.packet[13];
+ __m256i o = kernel.packet[14];
+ __m256i p = kernel.packet[15];
+
+ __m256i ab_07 = _mm256_unpacklo_epi16(a, b);
+ __m256i cd_07 = _mm256_unpacklo_epi16(c, d);
+ __m256i ef_07 = _mm256_unpacklo_epi16(e, f);
+ __m256i gh_07 = _mm256_unpacklo_epi16(g, h);
+ __m256i ij_07 = _mm256_unpacklo_epi16(i, j);
+ __m256i kl_07 = _mm256_unpacklo_epi16(k, l);
+ __m256i mn_07 = _mm256_unpacklo_epi16(m, n);
+ __m256i op_07 = _mm256_unpacklo_epi16(o, p);
+
+ __m256i ab_8f = _mm256_unpackhi_epi16(a, b);
+ __m256i cd_8f = _mm256_unpackhi_epi16(c, d);
+ __m256i ef_8f = _mm256_unpackhi_epi16(e, f);
+ __m256i gh_8f = _mm256_unpackhi_epi16(g, h);
+ __m256i ij_8f = _mm256_unpackhi_epi16(i, j);
+ __m256i kl_8f = _mm256_unpackhi_epi16(k, l);
+ __m256i mn_8f = _mm256_unpackhi_epi16(m, n);
+ __m256i op_8f = _mm256_unpackhi_epi16(o, p);
+
+ __m256i abcd_03 = _mm256_unpacklo_epi32(ab_07, cd_07);
+ __m256i abcd_47 = _mm256_unpackhi_epi32(ab_07, cd_07);
+ __m256i efgh_03 = _mm256_unpacklo_epi32(ef_07, gh_07);
+ __m256i efgh_47 = _mm256_unpackhi_epi32(ef_07, gh_07);
+ __m256i ijkl_03 = _mm256_unpacklo_epi32(ij_07, kl_07);
+ __m256i ijkl_47 = _mm256_unpackhi_epi32(ij_07, kl_07);
+ __m256i mnop_03 = _mm256_unpacklo_epi32(mn_07, op_07);
+ __m256i mnop_47 = _mm256_unpackhi_epi32(mn_07, op_07);
+
+ __m256i abcd_8b = _mm256_unpacklo_epi32(ab_8f, cd_8f);
+ __m256i abcd_cf = _mm256_unpackhi_epi32(ab_8f, cd_8f);
+ __m256i efgh_8b = _mm256_unpacklo_epi32(ef_8f, gh_8f);
+ __m256i efgh_cf = _mm256_unpackhi_epi32(ef_8f, gh_8f);
+ __m256i ijkl_8b = _mm256_unpacklo_epi32(ij_8f, kl_8f);
+ __m256i ijkl_cf = _mm256_unpackhi_epi32(ij_8f, kl_8f);
+ __m256i mnop_8b = _mm256_unpacklo_epi32(mn_8f, op_8f);
+ __m256i mnop_cf = _mm256_unpackhi_epi32(mn_8f, op_8f);
+
+ __m256i abcdefgh_01 = _mm256_unpacklo_epi64(abcd_03, efgh_03);
+ __m256i abcdefgh_23 = _mm256_unpackhi_epi64(abcd_03, efgh_03);
+ __m256i ijklmnop_01 = _mm256_unpacklo_epi64(ijkl_03, mnop_03);
+ __m256i ijklmnop_23 = _mm256_unpackhi_epi64(ijkl_03, mnop_03);
+ __m256i abcdefgh_45 = _mm256_unpacklo_epi64(abcd_47, efgh_47);
+ __m256i abcdefgh_67 = _mm256_unpackhi_epi64(abcd_47, efgh_47);
+ __m256i ijklmnop_45 = _mm256_unpacklo_epi64(ijkl_47, mnop_47);
+ __m256i ijklmnop_67 = _mm256_unpackhi_epi64(ijkl_47, mnop_47);
+ __m256i abcdefgh_89 = _mm256_unpacklo_epi64(abcd_8b, efgh_8b);
+ __m256i abcdefgh_ab = _mm256_unpackhi_epi64(abcd_8b, efgh_8b);
+ __m256i ijklmnop_89 = _mm256_unpacklo_epi64(ijkl_8b, mnop_8b);
+ __m256i ijklmnop_ab = _mm256_unpackhi_epi64(ijkl_8b, mnop_8b);
+ __m256i abcdefgh_cd = _mm256_unpacklo_epi64(abcd_cf, efgh_cf);
+ __m256i abcdefgh_ef = _mm256_unpackhi_epi64(abcd_cf, efgh_cf);
+ __m256i ijklmnop_cd = _mm256_unpacklo_epi64(ijkl_cf, mnop_cf);
+ __m256i ijklmnop_ef = _mm256_unpackhi_epi64(ijkl_cf, mnop_cf);
+
+ // NOTE: no unpacklo/hi instr in this case, so using permute instr.
+ __m256i a_p_0 = _mm256_permute2x128_si256(abcdefgh_01, ijklmnop_01, 0x20);
+ __m256i a_p_1 = _mm256_permute2x128_si256(abcdefgh_23, ijklmnop_23, 0x20);
+ __m256i a_p_2 = _mm256_permute2x128_si256(abcdefgh_45, ijklmnop_45, 0x20);
+ __m256i a_p_3 = _mm256_permute2x128_si256(abcdefgh_67, ijklmnop_67, 0x20);
+ __m256i a_p_4 = _mm256_permute2x128_si256(abcdefgh_89, ijklmnop_89, 0x20);
+ __m256i a_p_5 = _mm256_permute2x128_si256(abcdefgh_ab, ijklmnop_ab, 0x20);
+ __m256i a_p_6 = _mm256_permute2x128_si256(abcdefgh_cd, ijklmnop_cd, 0x20);
+ __m256i a_p_7 = _mm256_permute2x128_si256(abcdefgh_ef, ijklmnop_ef, 0x20);
+ __m256i a_p_8 = _mm256_permute2x128_si256(abcdefgh_01, ijklmnop_01, 0x31);
+ __m256i a_p_9 = _mm256_permute2x128_si256(abcdefgh_23, ijklmnop_23, 0x31);
+ __m256i a_p_a = _mm256_permute2x128_si256(abcdefgh_45, ijklmnop_45, 0x31);
+ __m256i a_p_b = _mm256_permute2x128_si256(abcdefgh_67, ijklmnop_67, 0x31);
+ __m256i a_p_c = _mm256_permute2x128_si256(abcdefgh_89, ijklmnop_89, 0x31);
+ __m256i a_p_d = _mm256_permute2x128_si256(abcdefgh_ab, ijklmnop_ab, 0x31);
+ __m256i a_p_e = _mm256_permute2x128_si256(abcdefgh_cd, ijklmnop_cd, 0x31);
+ __m256i a_p_f = _mm256_permute2x128_si256(abcdefgh_ef, ijklmnop_ef, 0x31);
+
+ kernel.packet[0] = a_p_0;
+ kernel.packet[1] = a_p_1;
+ kernel.packet[2] = a_p_2;
+ kernel.packet[3] = a_p_3;
+ kernel.packet[4] = a_p_4;
+ kernel.packet[5] = a_p_5;
+ kernel.packet[6] = a_p_6;
+ kernel.packet[7] = a_p_7;
+ kernel.packet[8] = a_p_8;
+ kernel.packet[9] = a_p_9;
+ kernel.packet[10] = a_p_a;
+ kernel.packet[11] = a_p_b;
+ kernel.packet[12] = a_p_c;
+ kernel.packet[13] = a_p_d;
+ kernel.packet[14] = a_p_e;
+ kernel.packet[15] = a_p_f;
+}
+
+EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet16h,8>& kernel) {
+ EIGEN_ALIGN64 half in[8][16];
+ pstore<half>(in[0], kernel.packet[0]);
+ pstore<half>(in[1], kernel.packet[1]);
+ pstore<half>(in[2], kernel.packet[2]);
+ pstore<half>(in[3], kernel.packet[3]);
+ pstore<half>(in[4], kernel.packet[4]);
+ pstore<half>(in[5], kernel.packet[5]);
+ pstore<half>(in[6], kernel.packet[6]);
+ pstore<half>(in[7], kernel.packet[7]);
+
+ EIGEN_ALIGN64 half out[8][16];
+
+ for (int i = 0; i < 8; ++i) {
+ for (int j = 0; j < 8; ++j) {
+ out[i][j] = in[j][2*i];
+ }
+ for (int j = 0; j < 8; ++j) {
+ out[i][j+8] = in[j][2*i+1];
+ }
+ }
+
+ kernel.packet[0] = pload<Packet16h>(out[0]);
+ kernel.packet[1] = pload<Packet16h>(out[1]);
+ kernel.packet[2] = pload<Packet16h>(out[2]);
+ kernel.packet[3] = pload<Packet16h>(out[3]);
+ kernel.packet[4] = pload<Packet16h>(out[4]);
+ kernel.packet[5] = pload<Packet16h>(out[5]);
+ kernel.packet[6] = pload<Packet16h>(out[6]);
+ kernel.packet[7] = pload<Packet16h>(out[7]);
+}
+
+EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet16h,4>& kernel) {
+ EIGEN_ALIGN64 half in[4][16];
+ pstore<half>(in[0], kernel.packet[0]);
+ pstore<half>(in[1], kernel.packet[1]);
+ pstore<half>(in[2], kernel.packet[2]);
+ pstore<half>(in[3], kernel.packet[3]);
+
+ EIGEN_ALIGN64 half out[4][16];
+
+ for (int i = 0; i < 4; ++i) {
+ for (int j = 0; j < 4; ++j) {
+ out[i][j] = in[j][4*i];
+ }
+ for (int j = 0; j < 4; ++j) {
+ out[i][j+4] = in[j][4*i+1];
+ }
+ for (int j = 0; j < 4; ++j) {
+ out[i][j+8] = in[j][4*i+2];
+ }
+ for (int j = 0; j < 4; ++j) {
+ out[i][j+12] = in[j][4*i+3];
+ }
+ }
+
+ kernel.packet[0] = pload<Packet16h>(out[0]);
+ kernel.packet[1] = pload<Packet16h>(out[1]);
+ kernel.packet[2] = pload<Packet16h>(out[2]);
+ kernel.packet[3] = pload<Packet16h>(out[3]);
+}
+
+template <> struct is_arithmetic<Packet16bf> { enum { value = true }; };
+
+template <>
+struct packet_traits<bfloat16> : default_packet_traits {
+ typedef Packet16bf type;
+ typedef Packet8bf half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 16,
+ HasHalfPacket = 1,
+ HasBlend = 0,
+ HasInsert = 1,
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+#if EIGEN_GNUC_AT_LEAST(5, 3) || (!EIGEN_COMP_GNUC_STRICT)
+#ifdef EIGEN_VECTORIZE_AVX512DQ
+ HasLog = 1, // Currently fails test with bad accuracy.
+ HasLog1p = 1,
+ HasExpm1 = 1,
+ HasNdtri = 1,
+ HasBessel = 1,
+#endif
+ HasExp = 1,
+ HasSqrt = EIGEN_FAST_MATH,
+ HasRsqrt = EIGEN_FAST_MATH,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+#endif
+ HasCmp = 1,
+ HasDiv = 1
+ };
+};
+
+template <>
+struct unpacket_traits<Packet16bf>
+{
+ typedef bfloat16 type;
+ enum {size=16, alignment=Aligned32, vectorizable=true, masked_load_available=false, masked_store_available=false};
+ typedef Packet8bf half;
+};
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pset1<Packet16bf>(const bfloat16& from) {
+ return _mm256_set1_epi16(from.value);
+}
+
+template <>
+EIGEN_STRONG_INLINE bfloat16 pfirst<Packet16bf>(const Packet16bf& from) {
+ bfloat16 t;
+ t.value = static_cast<unsigned short>(_mm256_extract_epi16(from, 0));
+ return t;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pload<Packet16bf>(const bfloat16* from) {
+ return _mm256_load_si256(reinterpret_cast<const __m256i*>(from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf ploadu<Packet16bf>(const bfloat16* from) {
+ return _mm256_loadu_si256(reinterpret_cast<const __m256i*>(from));
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstore<bfloat16>(bfloat16* to,
+ const Packet16bf& from) {
+ _mm256_store_si256(reinterpret_cast<__m256i*>(to), from);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstoreu<bfloat16>(bfloat16* to,
+ const Packet16bf& from) {
+ _mm256_storeu_si256(reinterpret_cast<__m256i*>(to), from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16bf
+ploaddup<Packet16bf>(const bfloat16* from) {
+ Packet16bf r;
+ unsigned short a = from[0].value;
+ unsigned short b = from[1].value;
+ unsigned short c = from[2].value;
+ unsigned short d = from[3].value;
+ unsigned short e = from[4].value;
+ unsigned short f = from[5].value;
+ unsigned short g = from[6].value;
+ unsigned short h = from[7].value;
+ return _mm256_set_epi16(h, h, g, g, f, f, e, e, d, d, c, c, b, b, a, a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16bf
+ploadquad(const bfloat16* from) {
+ Packet16bf r;
+ unsigned short a = from[0].value;
+ unsigned short b = from[1].value;
+ unsigned short c = from[2].value;
+ unsigned short d = from[3].value;
+ return _mm256_set_epi16(d, d, d, d, c, c, c, c, b, b, b, b, a, a, a, a);
+}
+
+EIGEN_STRONG_INLINE Packet16f Bf16ToF32(const Packet16bf& a) {
+ return _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(a), 16));
+}
+
+// Convert float to bfloat16 according to round-to-nearest-even/denormals algorithm.
+EIGEN_STRONG_INLINE Packet16bf F32ToBf16(const Packet16f& a) {
+ Packet16bf r;
+
+#if defined(EIGEN_VECTORIZE_AVX512BF16) && EIGEN_GNUC_AT_LEAST(10, 1)
+ // Since GCC 10.1 supports avx512bf16 and C style explicit cast
+ // (C++ static_cast is not supported yet), do converion via intrinsic
+ // and register path for performance.
+ r = (__m256i)(_mm512_cvtneps_pbh(a));
+
+#else
+ __m512i t;
+ __m512i input = _mm512_castps_si512(a);
+ __m512i nan = _mm512_set1_epi32(0x7fc0);
+
+ // uint32_t lsb = (input >> 16) & 1;
+ t = _mm512_and_si512(_mm512_srli_epi32(input, 16), _mm512_set1_epi32(1));
+ // uint32_t rounding_bias = 0x7fff + lsb;
+ t = _mm512_add_epi32(t, _mm512_set1_epi32(0x7fff));
+ // input += rounding_bias;
+ t = _mm512_add_epi32(t, input);
+ // input = input >> 16;
+ t = _mm512_srli_epi32(t, 16);
+
+ // Check NaN before converting back to bf16
+ __mmask16 mask = _mm512_cmp_ps_mask(a, a, _CMP_ORD_Q);
+
+ t = _mm512_mask_blend_epi32(mask, nan, t);
+ // output.value = static_cast<uint16_t>(input);
+ r = _mm512_cvtepi32_epi16(t);
+#endif // EIGEN_VECTORIZE_AVX512BF16
+
+ return r;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf ptrue(const Packet16bf& a) {
+ return ptrue<Packet8i>(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf por(const Packet16bf& a, const Packet16bf& b) {
+ return por<Packet8i>(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pxor(const Packet16bf& a, const Packet16bf& b) {
+ return pxor<Packet8i>(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pand(const Packet16bf& a, const Packet16bf& b) {
+ return pand<Packet8i>(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pandnot(const Packet16bf& a,
+ const Packet16bf& b) {
+ return pandnot<Packet8i>(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pselect(const Packet16bf& mask,
+ const Packet16bf& a,
+ const Packet16bf& b) {
+ // Input mask is expected to be all 0/1, handle it with 8-bit
+ // intrinsic for performance.
+ return _mm256_blendv_epi8(b, a, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16bf pround<Packet16bf>(const Packet16bf& a)
+{
+ return F32ToBf16(pround<Packet16f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16bf print<Packet16bf>(const Packet16bf& a) {
+ return F32ToBf16(print<Packet16f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16bf pceil<Packet16bf>(const Packet16bf& a) {
+ return F32ToBf16(pceil<Packet16f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16bf pfloor<Packet16bf>(const Packet16bf& a) {
+ return F32ToBf16(pfloor<Packet16f>(Bf16ToF32(a)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pcmp_eq(const Packet16bf& a,
+ const Packet16bf& b) {
+ return Pack32To16(pcmp_eq(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pcmp_le(const Packet16bf& a,
+ const Packet16bf& b) {
+ return Pack32To16(pcmp_le(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pcmp_lt(const Packet16bf& a,
+ const Packet16bf& b) {
+ return Pack32To16(pcmp_lt(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pcmp_lt_or_nan(const Packet16bf& a,
+ const Packet16bf& b) {
+ return Pack32To16(pcmp_lt_or_nan(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pnegate(const Packet16bf& a) {
+ Packet16bf sign_mask = _mm256_set1_epi16(static_cast<unsigned short>(0x8000));
+ return _mm256_xor_si256(a, sign_mask);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pconj(const Packet16bf& a) {
+ return a;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pabs(const Packet16bf& a) {
+ const __m256i sign_mask = _mm256_set1_epi16(static_cast<numext::uint16_t>(0x8000));
+ return _mm256_andnot_si256(sign_mask, a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf padd<Packet16bf>(const Packet16bf& a,
+ const Packet16bf& b) {
+ return F32ToBf16(padd<Packet16f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf psub<Packet16bf>(const Packet16bf& a,
+ const Packet16bf& b) {
+ return F32ToBf16(psub<Packet16f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pmul<Packet16bf>(const Packet16bf& a,
+ const Packet16bf& b) {
+ return F32ToBf16(pmul<Packet16f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pdiv<Packet16bf>(const Packet16bf& a,
+ const Packet16bf& b) {
+ return F32ToBf16(pdiv<Packet16f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pmin<Packet16bf>(const Packet16bf& a,
+ const Packet16bf& b) {
+ return F32ToBf16(pmin<Packet16f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pmax<Packet16bf>(const Packet16bf& a,
+ const Packet16bf& b) {
+ return F32ToBf16(pmax<Packet16f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf plset<Packet16bf>(const bfloat16& a) {
+ return F32ToBf16(plset<Packet16f>(static_cast<float>(a)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8bf predux_half_dowto4<Packet16bf>(const Packet16bf& a) {
+ Packet8bf lane0 = _mm256_extractf128_si256(a, 0);
+ Packet8bf lane1 = _mm256_extractf128_si256(a, 1);
+ return padd<Packet8bf>(lane0, lane1);
+}
+
+template <>
+EIGEN_STRONG_INLINE bfloat16 predux<Packet16bf>(const Packet16bf& p) {
+ return static_cast<bfloat16>(predux<Packet16f>(Bf16ToF32(p)));
+}
+
+template <>
+EIGEN_STRONG_INLINE bfloat16 predux_mul<Packet16bf>(const Packet16bf& from) {
+ return static_cast<bfloat16>(predux_mul<Packet16f>(Bf16ToF32(from)));
+}
+
+template <>
+EIGEN_STRONG_INLINE bfloat16 predux_min<Packet16bf>(const Packet16bf& from) {
+ return static_cast<bfloat16>(predux_min<Packet16f>(Bf16ToF32(from)));
+}
+
+template <>
+EIGEN_STRONG_INLINE bfloat16 predux_max<Packet16bf>(const Packet16bf& from) {
+ return static_cast<bfloat16>(predux_max<Packet16f>(Bf16ToF32(from)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf preverse(const Packet16bf& a) {
+ __m256i m = _mm256_setr_epi8(14,15,12,13,10,11,8,9,6,7,4,5,2,3,0,1,
+ 14,15,12,13,10,11,8,9,6,7,4,5,2,3,0,1);
+
+ Packet16bf res;
+ // Swap hi and lo first because shuffle is in 128-bit lanes.
+ res = _mm256_permute2x128_si256(a, a, 1);
+ // Shuffle 8-bit values in src within 2*128-bit lanes.
+ return _mm256_shuffle_epi8(res, m);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet16bf pgather<bfloat16, Packet16bf>(const bfloat16* from,
+ Index stride) {
+ return _mm256_set_epi16(
+ from[15*stride].value, from[14*stride].value, from[13*stride].value, from[12*stride].value,
+ from[11*stride].value, from[10*stride].value, from[9*stride].value, from[8*stride].value,
+ from[7*stride].value, from[6*stride].value, from[5*stride].value, from[4*stride].value,
+ from[3*stride].value, from[2*stride].value, from[1*stride].value, from[0*stride].value);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pscatter<bfloat16, Packet16bf>(bfloat16* to,
+ const Packet16bf& from,
+ Index stride) {
+ EIGEN_ALIGN64 bfloat16 aux[16];
+ pstore(aux, from);
+ to[stride*0] = aux[0];
+ to[stride*1] = aux[1];
+ to[stride*2] = aux[2];
+ to[stride*3] = aux[3];
+ to[stride*4] = aux[4];
+ to[stride*5] = aux[5];
+ to[stride*6] = aux[6];
+ to[stride*7] = aux[7];
+ to[stride*8] = aux[8];
+ to[stride*9] = aux[9];
+ to[stride*10] = aux[10];
+ to[stride*11] = aux[11];
+ to[stride*12] = aux[12];
+ to[stride*13] = aux[13];
+ to[stride*14] = aux[14];
+ to[stride*15] = aux[15];
+}
+
+EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16bf,16>& kernel) {
+ __m256i a = kernel.packet[0];
+ __m256i b = kernel.packet[1];
+ __m256i c = kernel.packet[2];
+ __m256i d = kernel.packet[3];
+ __m256i e = kernel.packet[4];
+ __m256i f = kernel.packet[5];
+ __m256i g = kernel.packet[6];
+ __m256i h = kernel.packet[7];
+ __m256i i = kernel.packet[8];
+ __m256i j = kernel.packet[9];
+ __m256i k = kernel.packet[10];
+ __m256i l = kernel.packet[11];
+ __m256i m = kernel.packet[12];
+ __m256i n = kernel.packet[13];
+ __m256i o = kernel.packet[14];
+ __m256i p = kernel.packet[15];
+
+ __m256i ab_07 = _mm256_unpacklo_epi16(a, b);
+ __m256i cd_07 = _mm256_unpacklo_epi16(c, d);
+ __m256i ef_07 = _mm256_unpacklo_epi16(e, f);
+ __m256i gh_07 = _mm256_unpacklo_epi16(g, h);
+ __m256i ij_07 = _mm256_unpacklo_epi16(i, j);
+ __m256i kl_07 = _mm256_unpacklo_epi16(k, l);
+ __m256i mn_07 = _mm256_unpacklo_epi16(m, n);
+ __m256i op_07 = _mm256_unpacklo_epi16(o, p);
+
+ __m256i ab_8f = _mm256_unpackhi_epi16(a, b);
+ __m256i cd_8f = _mm256_unpackhi_epi16(c, d);
+ __m256i ef_8f = _mm256_unpackhi_epi16(e, f);
+ __m256i gh_8f = _mm256_unpackhi_epi16(g, h);
+ __m256i ij_8f = _mm256_unpackhi_epi16(i, j);
+ __m256i kl_8f = _mm256_unpackhi_epi16(k, l);
+ __m256i mn_8f = _mm256_unpackhi_epi16(m, n);
+ __m256i op_8f = _mm256_unpackhi_epi16(o, p);
+
+ __m256i abcd_03 = _mm256_unpacklo_epi32(ab_07, cd_07);
+ __m256i abcd_47 = _mm256_unpackhi_epi32(ab_07, cd_07);
+ __m256i efgh_03 = _mm256_unpacklo_epi32(ef_07, gh_07);
+ __m256i efgh_47 = _mm256_unpackhi_epi32(ef_07, gh_07);
+ __m256i ijkl_03 = _mm256_unpacklo_epi32(ij_07, kl_07);
+ __m256i ijkl_47 = _mm256_unpackhi_epi32(ij_07, kl_07);
+ __m256i mnop_03 = _mm256_unpacklo_epi32(mn_07, op_07);
+ __m256i mnop_47 = _mm256_unpackhi_epi32(mn_07, op_07);
+
+ __m256i abcd_8b = _mm256_unpacklo_epi32(ab_8f, cd_8f);
+ __m256i abcd_cf = _mm256_unpackhi_epi32(ab_8f, cd_8f);
+ __m256i efgh_8b = _mm256_unpacklo_epi32(ef_8f, gh_8f);
+ __m256i efgh_cf = _mm256_unpackhi_epi32(ef_8f, gh_8f);
+ __m256i ijkl_8b = _mm256_unpacklo_epi32(ij_8f, kl_8f);
+ __m256i ijkl_cf = _mm256_unpackhi_epi32(ij_8f, kl_8f);
+ __m256i mnop_8b = _mm256_unpacklo_epi32(mn_8f, op_8f);
+ __m256i mnop_cf = _mm256_unpackhi_epi32(mn_8f, op_8f);
+
+ __m256i abcdefgh_01 = _mm256_unpacklo_epi64(abcd_03, efgh_03);
+ __m256i abcdefgh_23 = _mm256_unpackhi_epi64(abcd_03, efgh_03);
+ __m256i ijklmnop_01 = _mm256_unpacklo_epi64(ijkl_03, mnop_03);
+ __m256i ijklmnop_23 = _mm256_unpackhi_epi64(ijkl_03, mnop_03);
+ __m256i abcdefgh_45 = _mm256_unpacklo_epi64(abcd_47, efgh_47);
+ __m256i abcdefgh_67 = _mm256_unpackhi_epi64(abcd_47, efgh_47);
+ __m256i ijklmnop_45 = _mm256_unpacklo_epi64(ijkl_47, mnop_47);
+ __m256i ijklmnop_67 = _mm256_unpackhi_epi64(ijkl_47, mnop_47);
+ __m256i abcdefgh_89 = _mm256_unpacklo_epi64(abcd_8b, efgh_8b);
+ __m256i abcdefgh_ab = _mm256_unpackhi_epi64(abcd_8b, efgh_8b);
+ __m256i ijklmnop_89 = _mm256_unpacklo_epi64(ijkl_8b, mnop_8b);
+ __m256i ijklmnop_ab = _mm256_unpackhi_epi64(ijkl_8b, mnop_8b);
+ __m256i abcdefgh_cd = _mm256_unpacklo_epi64(abcd_cf, efgh_cf);
+ __m256i abcdefgh_ef = _mm256_unpackhi_epi64(abcd_cf, efgh_cf);
+ __m256i ijklmnop_cd = _mm256_unpacklo_epi64(ijkl_cf, mnop_cf);
+ __m256i ijklmnop_ef = _mm256_unpackhi_epi64(ijkl_cf, mnop_cf);
+
+ // NOTE: no unpacklo/hi instr in this case, so using permute instr.
+ kernel.packet[0] = _mm256_permute2x128_si256(abcdefgh_01, ijklmnop_01, 0x20);
+ kernel.packet[1] = _mm256_permute2x128_si256(abcdefgh_23, ijklmnop_23, 0x20);
+ kernel.packet[2] = _mm256_permute2x128_si256(abcdefgh_45, ijklmnop_45, 0x20);
+ kernel.packet[3] = _mm256_permute2x128_si256(abcdefgh_67, ijklmnop_67, 0x20);
+ kernel.packet[4] = _mm256_permute2x128_si256(abcdefgh_89, ijklmnop_89, 0x20);
+ kernel.packet[5] = _mm256_permute2x128_si256(abcdefgh_ab, ijklmnop_ab, 0x20);
+ kernel.packet[6] = _mm256_permute2x128_si256(abcdefgh_cd, ijklmnop_cd, 0x20);
+ kernel.packet[7] = _mm256_permute2x128_si256(abcdefgh_ef, ijklmnop_ef, 0x20);
+ kernel.packet[8] = _mm256_permute2x128_si256(abcdefgh_01, ijklmnop_01, 0x31);
+ kernel.packet[9] = _mm256_permute2x128_si256(abcdefgh_23, ijklmnop_23, 0x31);
+ kernel.packet[10] = _mm256_permute2x128_si256(abcdefgh_45, ijklmnop_45, 0x31);
+ kernel.packet[11] = _mm256_permute2x128_si256(abcdefgh_67, ijklmnop_67, 0x31);
+ kernel.packet[12] = _mm256_permute2x128_si256(abcdefgh_89, ijklmnop_89, 0x31);
+ kernel.packet[13] = _mm256_permute2x128_si256(abcdefgh_ab, ijklmnop_ab, 0x31);
+ kernel.packet[14] = _mm256_permute2x128_si256(abcdefgh_cd, ijklmnop_cd, 0x31);
+ kernel.packet[15] = _mm256_permute2x128_si256(abcdefgh_ef, ijklmnop_ef, 0x31);
+}
+
+EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16bf,4>& kernel) {
+ __m256i a = kernel.packet[0];
+ __m256i b = kernel.packet[1];
+ __m256i c = kernel.packet[2];
+ __m256i d = kernel.packet[3];
+
+ __m256i ab_07 = _mm256_unpacklo_epi16(a, b);
+ __m256i cd_07 = _mm256_unpacklo_epi16(c, d);
+ __m256i ab_8f = _mm256_unpackhi_epi16(a, b);
+ __m256i cd_8f = _mm256_unpackhi_epi16(c, d);
+
+ __m256i abcd_03 = _mm256_unpacklo_epi32(ab_07, cd_07);
+ __m256i abcd_47 = _mm256_unpackhi_epi32(ab_07, cd_07);
+ __m256i abcd_8b = _mm256_unpacklo_epi32(ab_8f, cd_8f);
+ __m256i abcd_cf = _mm256_unpackhi_epi32(ab_8f, cd_8f);
+
+ // NOTE: no unpacklo/hi instr in this case, so using permute instr.
+ kernel.packet[0] = _mm256_permute2x128_si256(abcd_03, abcd_47, 0x20);
+ kernel.packet[1] = _mm256_permute2x128_si256(abcd_8b, abcd_cf, 0x20);
+ kernel.packet[2] = _mm256_permute2x128_si256(abcd_03, abcd_47, 0x31);
+ kernel.packet[3] = _mm256_permute2x128_si256(abcd_8b, abcd_cf, 0x31);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PACKET_MATH_AVX512_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/TypeCasting.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/TypeCasting.h
new file mode 100644
index 000000000..330412729
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AVX512/TypeCasting.h
@@ -0,0 +1,89 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2019 Rasmus Munk Larsen <rmlarsen@google.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TYPE_CASTING_AVX512_H
+#define EIGEN_TYPE_CASTING_AVX512_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<> EIGEN_STRONG_INLINE Packet16i pcast<Packet16f, Packet16i>(const Packet16f& a) {
+ return _mm512_cvttps_epi32(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16f pcast<Packet16i, Packet16f>(const Packet16i& a) {
+ return _mm512_cvtepi32_ps(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16i preinterpret<Packet16i, Packet16f>(const Packet16f& a) {
+ return _mm512_castps_si512(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16f preinterpret<Packet16f, Packet16i>(const Packet16i& a) {
+ return _mm512_castsi512_ps(a);
+}
+
+template <>
+struct type_casting_traits<half, float> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet16f pcast<Packet16h, Packet16f>(const Packet16h& a) {
+ return half2float(a);
+}
+
+template <>
+struct type_casting_traits<float, half> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet16h pcast<Packet16f, Packet16h>(const Packet16f& a) {
+ return float2half(a);
+}
+
+template <>
+struct type_casting_traits<bfloat16, float> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet16f pcast<Packet16bf, Packet16f>(const Packet16bf& a) {
+ return Bf16ToF32(a);
+}
+
+template <>
+struct type_casting_traits<float, bfloat16> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet16bf pcast<Packet16f, Packet16bf>(const Packet16f& a) {
+ return F32ToBf16(a);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TYPE_CASTING_AVX512_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/Complex.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/Complex.h
new file mode 100644
index 000000000..f424f11cf
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/Complex.h
@@ -0,0 +1,417 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010-2016 Konstantinos Margaritis <markos@freevec.org>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMPLEX32_ALTIVEC_H
+#define EIGEN_COMPLEX32_ALTIVEC_H
+
+namespace Eigen {
+
+namespace internal {
+
+static Packet4ui p4ui_CONJ_XOR = vec_mergeh((Packet4ui)p4i_ZERO, (Packet4ui)p4f_MZERO);//{ 0x00000000, 0x80000000, 0x00000000, 0x80000000 };
+#ifdef __VSX__
+#if defined(_BIG_ENDIAN)
+static Packet2ul p2ul_CONJ_XOR1 = (Packet2ul) vec_sld((Packet4ui) p2d_MZERO, (Packet4ui) p2l_ZERO, 8);//{ 0x8000000000000000, 0x0000000000000000 };
+static Packet2ul p2ul_CONJ_XOR2 = (Packet2ul) vec_sld((Packet4ui) p2l_ZERO, (Packet4ui) p2d_MZERO, 8);//{ 0x8000000000000000, 0x0000000000000000 };
+#else
+static Packet2ul p2ul_CONJ_XOR1 = (Packet2ul) vec_sld((Packet4ui) p2l_ZERO, (Packet4ui) p2d_MZERO, 8);//{ 0x8000000000000000, 0x0000000000000000 };
+static Packet2ul p2ul_CONJ_XOR2 = (Packet2ul) vec_sld((Packet4ui) p2d_MZERO, (Packet4ui) p2l_ZERO, 8);//{ 0x8000000000000000, 0x0000000000000000 };
+#endif
+#endif
+
+//---------- float ----------
+struct Packet2cf
+{
+ EIGEN_STRONG_INLINE explicit Packet2cf() {}
+ EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {}
+
+ EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b)
+ {
+ Packet4f v1, v2;
+
+ // Permute and multiply the real parts of a and b
+ v1 = vec_perm(a.v, a.v, p16uc_PSET32_WODD);
+ // Get the imaginary parts of a
+ v2 = vec_perm(a.v, a.v, p16uc_PSET32_WEVEN);
+ // multiply a_re * b
+ v1 = vec_madd(v1, b.v, p4f_ZERO);
+ // multiply a_im * b and get the conjugate result
+ v2 = vec_madd(v2, b.v, p4f_ZERO);
+ v2 = reinterpret_cast<Packet4f>(pxor(v2, reinterpret_cast<Packet4f>(p4ui_CONJ_XOR)));
+ // permute back to a proper order
+ v2 = vec_perm(v2, v2, p16uc_COMPLEX32_REV);
+
+ return Packet2cf(padd<Packet4f>(v1, v2));
+ }
+
+ EIGEN_STRONG_INLINE Packet2cf& operator*=(const Packet2cf& b) {
+ v = pmul(Packet2cf(*this), b).v;
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet2cf operator*(const Packet2cf& b) const {
+ return Packet2cf(*this) *= b;
+ }
+
+ EIGEN_STRONG_INLINE Packet2cf& operator+=(const Packet2cf& b) {
+ v = padd(v, b.v);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet2cf operator+(const Packet2cf& b) const {
+ return Packet2cf(*this) += b;
+ }
+ EIGEN_STRONG_INLINE Packet2cf& operator-=(const Packet2cf& b) {
+ v = psub(v, b.v);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet2cf operator-(const Packet2cf& b) const {
+ return Packet2cf(*this) -= b;
+ }
+ EIGEN_STRONG_INLINE Packet2cf operator-(void) const {
+ return Packet2cf(-v);
+ }
+
+ Packet4f v;
+};
+
+template<> struct packet_traits<std::complex<float> > : default_packet_traits
+{
+ typedef Packet2cf type;
+ typedef Packet2cf half;
+ typedef Packet4f as_real;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 2,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+#ifdef __VSX__
+ HasBlend = 1,
+#endif
+ HasSetLinear = 0
+ };
+};
+
+template<> struct unpacket_traits<Packet2cf> { typedef std::complex<float> type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet2cf half; typedef Packet4f as_real; };
+
+template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from)
+{
+ Packet2cf res;
+ if((std::ptrdiff_t(&from) % 16) == 0)
+ res.v = pload<Packet4f>((const float *)&from);
+ else
+ res.v = ploadu<Packet4f>((const float *)&from);
+ res.v = vec_perm(res.v, res.v, p16uc_PSET64_HI);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(const std::complex<float>* from) { return Packet2cf(pload<Packet4f>((const float *) from)); }
+template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { return Packet2cf(ploadu<Packet4f>((const float*) from)); }
+template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { return pset1<Packet2cf>(*from); }
+
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { pstore((float*)to, from.v); }
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { pstoreu((float*)to, from.v); }
+
+EIGEN_STRONG_INLINE Packet2cf pload2(const std::complex<float>* from0, const std::complex<float>* from1)
+{
+ Packet4f res0, res1;
+#ifdef __VSX__
+ __asm__ ("lxsdx %x0,%y1" : "=wa" (res0) : "Z" (*from0));
+ __asm__ ("lxsdx %x0,%y1" : "=wa" (res1) : "Z" (*from1));
+#ifdef _BIG_ENDIAN
+ __asm__ ("xxpermdi %x0, %x1, %x2, 0" : "=wa" (res0) : "wa" (res0), "wa" (res1));
+#else
+ __asm__ ("xxpermdi %x0, %x2, %x1, 0" : "=wa" (res0) : "wa" (res0), "wa" (res1));
+#endif
+#else
+ *reinterpret_cast<std::complex<float> *>(&res0) = *from0;
+ *reinterpret_cast<std::complex<float> *>(&res1) = *from1;
+ res0 = vec_perm(res0, res1, p16uc_TRANSPOSE64_HI);
+#endif
+ return Packet2cf(res0);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>(const std::complex<float>* from, Index stride)
+{
+ EIGEN_ALIGN16 std::complex<float> af[2];
+ af[0] = from[0*stride];
+ af[1] = from[1*stride];
+ return pload<Packet2cf>(af);
+}
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to, const Packet2cf& from, Index stride)
+{
+ EIGEN_ALIGN16 std::complex<float> af[2];
+ pstore<std::complex<float> >((std::complex<float> *) af, from);
+ to[0*stride] = af[0];
+ to[1*stride] = af[1];
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(a.v + b.v); }
+template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(a.v - b.v); }
+template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) { return Packet2cf(pnegate(a.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) { return Packet2cf(pxor<Packet4f>(a.v, reinterpret_cast<Packet4f>(p4ui_CONJ_XOR))); }
+
+template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pand<Packet4f>(a.v, b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(por<Packet4f>(a.v, b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pxor<Packet4f>(a.v, b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pandnot<Packet4f>(a.v, b.v)); }
+
+template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> * addr) { EIGEN_PPC_PREFETCH(addr); }
+
+template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a)
+{
+ EIGEN_ALIGN16 std::complex<float> res[2];
+ pstore((float *)&res, a.v);
+
+ return res[0];
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a)
+{
+ Packet4f rev_a;
+ rev_a = vec_perm(a.v, a.v, p16uc_COMPLEX32_REV2);
+ return Packet2cf(rev_a);
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
+{
+ Packet4f b;
+ b = vec_sld(a.v, a.v, 8);
+ b = padd<Packet4f>(a.v, b);
+ return pfirst<Packet2cf>(Packet2cf(b));
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
+{
+ Packet4f b;
+ Packet2cf prod;
+ b = vec_sld(a.v, a.v, 8);
+ prod = pmul<Packet2cf>(a, Packet2cf(b));
+
+ return pfirst<Packet2cf>(prod);
+}
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
+
+template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{
+ // TODO optimize it for AltiVec
+ Packet2cf res = pmul(a, pconj(b));
+ Packet4f s = pmul<Packet4f>(b.v, b.v);
+ return Packet2cf(pdiv(res.v, padd<Packet4f>(s, vec_perm(s, s, p16uc_COMPLEX32_REV))));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& x)
+{
+ return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX32_REV));
+}
+
+EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2cf,2>& kernel)
+{
+ Packet4f tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
+ kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
+ kernel.packet[0].v = tmp;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf& a, const Packet2cf& b) {
+ Packet4f eq = reinterpret_cast<Packet4f>(vec_cmpeq(a.v,b.v));
+ return Packet2cf(vec_and(eq, vec_perm(eq, eq, p16uc_COMPLEX32_REV)));
+}
+
+#ifdef __VSX__
+template<> EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket, const Packet2cf& elsePacket) {
+ Packet2cf result;
+ result.v = reinterpret_cast<Packet4f>(pblend<Packet2d>(ifPacket, reinterpret_cast<Packet2d>(thenPacket.v), reinterpret_cast<Packet2d>(elsePacket.v)));
+ return result;
+}
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet2cf psqrt<Packet2cf>(const Packet2cf& a)
+{
+ return psqrt_complex<Packet2cf>(a);
+}
+
+//---------- double ----------
+#ifdef __VSX__
+struct Packet1cd
+{
+ EIGEN_STRONG_INLINE Packet1cd() {}
+ EIGEN_STRONG_INLINE explicit Packet1cd(const Packet2d& a) : v(a) {}
+
+ EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b)
+ {
+ Packet2d a_re, a_im, v1, v2;
+
+ // Permute and multiply the real parts of a and b
+ a_re = vec_perm(a.v, a.v, p16uc_PSET64_HI);
+ // Get the imaginary parts of a
+ a_im = vec_perm(a.v, a.v, p16uc_PSET64_LO);
+ // multiply a_re * b
+ v1 = vec_madd(a_re, b.v, p2d_ZERO);
+ // multiply a_im * b and get the conjugate result
+ v2 = vec_madd(a_im, b.v, p2d_ZERO);
+ v2 = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(v2), reinterpret_cast<Packet4ui>(v2), 8));
+ v2 = pxor(v2, reinterpret_cast<Packet2d>(p2ul_CONJ_XOR1));
+
+ return Packet1cd(padd<Packet2d>(v1, v2));
+ }
+
+ EIGEN_STRONG_INLINE Packet1cd& operator*=(const Packet1cd& b) {
+ v = pmul(Packet1cd(*this), b).v;
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet1cd operator*(const Packet1cd& b) const {
+ return Packet1cd(*this) *= b;
+ }
+
+ EIGEN_STRONG_INLINE Packet1cd& operator+=(const Packet1cd& b) {
+ v = padd(v, b.v);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet1cd operator+(const Packet1cd& b) const {
+ return Packet1cd(*this) += b;
+ }
+ EIGEN_STRONG_INLINE Packet1cd& operator-=(const Packet1cd& b) {
+ v = psub(v, b.v);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet1cd operator-(const Packet1cd& b) const {
+ return Packet1cd(*this) -= b;
+ }
+ EIGEN_STRONG_INLINE Packet1cd operator-(void) const {
+ return Packet1cd(-v);
+ }
+
+ Packet2d v;
+};
+
+template<> struct packet_traits<std::complex<double> > : default_packet_traits
+{
+ typedef Packet1cd type;
+ typedef Packet1cd half;
+ typedef Packet2d as_real;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 0,
+ size = 1,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0
+ };
+};
+
+template<> struct unpacket_traits<Packet1cd> { typedef std::complex<double> type; enum {size=1, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet1cd half; typedef Packet2d as_real; };
+
+template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(const std::complex<double>* from) { return Packet1cd(pload<Packet2d>((const double*)from)); }
+template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from) { return Packet1cd(ploadu<Packet2d>((const double*)from)); }
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { pstore((double*)to, from.v); }
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { pstoreu((double*)to, from.v); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from)
+{ /* here we really have to use unaligned loads :( */ return ploadu<Packet1cd>(&from); }
+
+template<> EIGEN_DEVICE_FUNC inline Packet1cd pgather<std::complex<double>, Packet1cd>(const std::complex<double>* from, Index)
+{
+ return pload<Packet1cd>(from);
+}
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to, const Packet1cd& from, Index)
+{
+ pstore<std::complex<double> >(to, from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(a.v + b.v); }
+template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(a.v - b.v); }
+template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) { return Packet1cd(pnegate(Packet2d(a.v))); }
+template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a) { return Packet1cd(pxor(a.v, reinterpret_cast<Packet2d>(p2ul_CONJ_XOR2))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(pand(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(por(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(pxor(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(pandnot(a.v, b.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) { return pset1<Packet1cd>(*from); }
+
+template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> * addr) { EIGEN_PPC_PREFETCH(addr); }
+
+template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a)
+{
+ EIGEN_ALIGN16 std::complex<double> res[2];
+ pstore<std::complex<double> >(res, a);
+
+ return res[0];
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a) { return pfirst(a); }
+
+template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a) { return pfirst(a); }
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d)
+
+template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{
+ // TODO optimize it for AltiVec
+ Packet1cd res = pmul(a,pconj(b));
+ Packet2d s = pmul<Packet2d>(b.v, b.v);
+ return Packet1cd(pdiv(res.v, padd<Packet2d>(s, vec_perm(s, s, p16uc_REVERSE64))));
+}
+
+EIGEN_STRONG_INLINE Packet1cd pcplxflip/*<Packet1cd>*/(const Packet1cd& x)
+{
+ return Packet1cd(preverse(Packet2d(x.v)));
+}
+
+EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet1cd,2>& kernel)
+{
+ Packet2d tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
+ kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
+ kernel.packet[0].v = tmp;
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(const Packet1cd& a, const Packet1cd& b) {
+ // Compare real and imaginary parts of a and b to get the mask vector:
+ // [re(a)==re(b), im(a)==im(b)]
+ Packet2d eq = reinterpret_cast<Packet2d>(vec_cmpeq(a.v,b.v));
+ // Swap real/imag elements in the mask in to get:
+ // [im(a)==im(b), re(a)==re(b)]
+ Packet2d eq_swapped = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(eq), reinterpret_cast<Packet4ui>(eq), 8));
+ // Return re(a)==re(b) & im(a)==im(b) by computing bitwise AND of eq and eq_swapped
+ return Packet1cd(vec_and(eq, eq_swapped));
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd psqrt<Packet1cd>(const Packet1cd& a)
+{
+ return psqrt_complex<Packet1cd>(a);
+}
+
+#endif // __VSX__
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_COMPLEX32_ALTIVEC_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h
new file mode 100644
index 000000000..3a7a32936
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h
@@ -0,0 +1,90 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2007 Julien Pommier
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2016 Konstantinos Margaritis <markos@freevec.org>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATH_FUNCTIONS_ALTIVEC_H
+#define EIGEN_MATH_FUNCTIONS_ALTIVEC_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f plog<Packet4f>(const Packet4f& _x)
+{
+ return plog_float(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f pexp<Packet4f>(const Packet4f& _x)
+{
+ return pexp_float(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f psin<Packet4f>(const Packet4f& _x)
+{
+ return psin_float(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f pcos<Packet4f>(const Packet4f& _x)
+{
+ return pcos_float(_x);
+}
+
+#ifndef EIGEN_COMP_CLANG
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f prsqrt<Packet4f>(const Packet4f& x)
+{
+ return vec_rsqrt(x);
+}
+#endif
+
+#ifdef __VSX__
+#ifndef EIGEN_COMP_CLANG
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet2d prsqrt<Packet2d>(const Packet2d& x)
+{
+ return vec_rsqrt(x);
+}
+#endif
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f psqrt<Packet4f>(const Packet4f& x)
+{
+ return vec_sqrt(x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet2d psqrt<Packet2d>(const Packet2d& x)
+{
+ return vec_sqrt(x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet2d pexp<Packet2d>(const Packet2d& _x)
+{
+ return pexp_double(_x);
+}
+#endif
+
+// Hyperbolic Tangent function.
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f
+ptanh<Packet4f>(const Packet4f& x) {
+ return internal::generic_fast_tanh_float(x);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATH_FUNCTIONS_ALTIVEC_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProduct.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProduct.h
new file mode 100644
index 000000000..3f79b97df
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProduct.h
@@ -0,0 +1,2937 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2020 Everton Constantino (everton.constantino@ibm.com)
+// Copyright (C) 2021 Chip Kerchner (chip.kerchner@ibm.com)
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATRIX_PRODUCT_ALTIVEC_H
+#define EIGEN_MATRIX_PRODUCT_ALTIVEC_H
+
+#ifndef EIGEN_ALTIVEC_USE_CUSTOM_PACK
+#define EIGEN_ALTIVEC_USE_CUSTOM_PACK 1
+#endif
+
+#include "MatrixProductCommon.h"
+
+// Since LLVM doesn't support dynamic dispatching, force either always MMA or VSX
+#if EIGEN_COMP_LLVM
+#if !defined(EIGEN_ALTIVEC_DISABLE_MMA) && !defined(EIGEN_ALTIVEC_MMA_ONLY)
+#ifdef __MMA__
+#define EIGEN_ALTIVEC_MMA_ONLY
+#else
+#define EIGEN_ALTIVEC_DISABLE_MMA
+#endif
+#endif
+#endif
+
+#ifdef __has_builtin
+#if __has_builtin(__builtin_mma_assemble_acc)
+ #define ALTIVEC_MMA_SUPPORT
+#endif
+#endif
+
+#if defined(ALTIVEC_MMA_SUPPORT) && !defined(EIGEN_ALTIVEC_DISABLE_MMA)
+ #include "MatrixProductMMA.h"
+#endif
+
+/**************************************************************************************************
+ * TODO *
+ * - Check StorageOrder on dhs_pack (the innermost second loop seems unvectorized when it could). *
+ * - Check the possibility of transposing as GETREAL and GETIMAG when needed. *
+ **************************************************************************************************/
+namespace Eigen {
+
+namespace internal {
+
+/**************************
+ * Constants and typedefs *
+ **************************/
+template<typename Scalar>
+struct quad_traits
+{
+ typedef typename packet_traits<Scalar>::type vectortype;
+ typedef PacketBlock<vectortype,4> type;
+ typedef vectortype rhstype;
+ enum
+ {
+ vectorsize = packet_traits<Scalar>::size,
+ size = 4,
+ rows = 4
+ };
+};
+
+template<>
+struct quad_traits<double>
+{
+ typedef Packet2d vectortype;
+ typedef PacketBlock<vectortype,4> type;
+ typedef PacketBlock<Packet2d,2> rhstype;
+ enum
+ {
+ vectorsize = packet_traits<double>::size,
+ size = 2,
+ rows = 4
+ };
+};
+
+// MatrixProduct decomposes real/imaginary vectors into a real vector and an imaginary vector, this turned out
+// to be faster than Eigen's usual approach of having real/imaginary pairs on a single vector. This constants then
+// are responsible to extract from convert between Eigen's and MatrixProduct approach.
+
+const static Packet16uc p16uc_GETREAL32 = { 0, 1, 2, 3,
+ 8, 9, 10, 11,
+ 16, 17, 18, 19,
+ 24, 25, 26, 27};
+
+const static Packet16uc p16uc_GETIMAG32 = { 4, 5, 6, 7,
+ 12, 13, 14, 15,
+ 20, 21, 22, 23,
+ 28, 29, 30, 31};
+const static Packet16uc p16uc_GETREAL64 = { 0, 1, 2, 3, 4, 5, 6, 7,
+ 16, 17, 18, 19, 20, 21, 22, 23};
+
+//[a,ai],[b,bi] = [ai,bi]
+const static Packet16uc p16uc_GETIMAG64 = { 8, 9, 10, 11, 12, 13, 14, 15,
+ 24, 25, 26, 27, 28, 29, 30, 31};
+
+/*********************************************
+ * Single precision real and complex packing *
+ * *******************************************/
+
+/**
+ * Symm packing is related to packing of symmetric adjoint blocks, as expected the packing leaves
+ * the diagonal real, whatever is below it is copied from the respective upper diagonal element and
+ * conjugated. There's no PanelMode available for symm packing.
+ *
+ * Packing in general is supposed to leave the lhs block and the rhs block easy to be read by gemm using
+ * its respective rank-update instructions. The float32/64 versions are different because at this moment
+ * the size of the accumulator is fixed at 512-bits so you can't have a 4x4 accumulator of 64-bit elements.
+ *
+ * As mentioned earlier MatrixProduct breaks complex numbers into a real vector and a complex vector so packing has
+ * to take that into account, at the moment, we run pack the real part and then the imaginary part, this is the main
+ * reason why packing for complex is broken down into several different parts, also the reason why we endup having a
+ * float32/64 and complex float32/64 version.
+ **/
+template<typename Scalar, typename Index, int StorageOrder>
+EIGEN_ALWAYS_INLINE std::complex<Scalar> getAdjointVal(Index i, Index j, const_blas_data_mapper<std::complex<Scalar>, Index, StorageOrder>& dt)
+{
+ std::complex<Scalar> v;
+ if(i < j)
+ {
+ v.real( dt(j,i).real());
+ v.imag(-dt(j,i).imag());
+ } else if(i > j)
+ {
+ v.real( dt(i,j).real());
+ v.imag( dt(i,j).imag());
+ } else {
+ v.real( dt(i,j).real());
+ v.imag((Scalar)0.0);
+ }
+ return v;
+}
+
+template<typename Scalar, typename Index, int StorageOrder, int N>
+EIGEN_STRONG_INLINE void symm_pack_complex_rhs_helper(std::complex<Scalar>* blockB, const std::complex<Scalar>* _rhs, Index rhsStride, Index rows, Index cols, Index k2)
+{
+ const Index depth = k2 + rows;
+ const_blas_data_mapper<std::complex<Scalar>, Index, StorageOrder> rhs(_rhs, rhsStride);
+ const Index vectorSize = N*quad_traits<Scalar>::vectorsize;
+ const Index vectorDelta = vectorSize * rows;
+ Scalar* blockBf = reinterpret_cast<Scalar *>(blockB);
+
+ Index rir = 0, rii, j = 0;
+ for(; j + vectorSize <= cols; j+=vectorSize)
+ {
+ rii = rir + vectorDelta;
+
+ for(Index i = k2; i < depth; i++)
+ {
+ for(Index k = 0; k < vectorSize; k++)
+ {
+ std::complex<Scalar> v = getAdjointVal<Scalar, Index, StorageOrder>(i, j + k, rhs);
+
+ blockBf[rir + k] = v.real();
+ blockBf[rii + k] = v.imag();
+ }
+ rir += vectorSize;
+ rii += vectorSize;
+ }
+
+ rir += vectorDelta;
+ }
+ if (j < cols)
+ {
+ rii = rir + ((cols - j) * rows);
+
+ for(Index i = k2; i < depth; i++)
+ {
+ Index k = j;
+ for(; k < cols; k++)
+ {
+ std::complex<Scalar> v = getAdjointVal<Scalar, Index, StorageOrder>(i, k, rhs);
+
+ blockBf[rir] = v.real();
+ blockBf[rii] = v.imag();
+
+ rir += 1;
+ rii += 1;
+ }
+ }
+ }
+}
+
+template<typename Scalar, typename Index, int StorageOrder>
+EIGEN_STRONG_INLINE void symm_pack_complex_lhs_helper(std::complex<Scalar>* blockA, const std::complex<Scalar>* _lhs, Index lhsStride, Index cols, Index rows)
+{
+ const Index depth = cols;
+ const_blas_data_mapper<std::complex<Scalar>, Index, StorageOrder> lhs(_lhs, lhsStride);
+ const Index vectorSize = quad_traits<Scalar>::vectorsize;
+ const Index vectorDelta = vectorSize * depth;
+ Scalar* blockAf = (Scalar *)(blockA);
+
+ Index rir = 0, rii, j = 0;
+ for(; j + vectorSize <= rows; j+=vectorSize)
+ {
+ rii = rir + vectorDelta;
+
+ for(Index i = 0; i < depth; i++)
+ {
+ for(Index k = 0; k < vectorSize; k++)
+ {
+ std::complex<Scalar> v = getAdjointVal<Scalar, Index, StorageOrder>(j+k, i, lhs);
+
+ blockAf[rir + k] = v.real();
+ blockAf[rii + k] = v.imag();
+ }
+ rir += vectorSize;
+ rii += vectorSize;
+ }
+
+ rir += vectorDelta;
+ }
+
+ if (j < rows)
+ {
+ rii = rir + ((rows - j) * depth);
+
+ for(Index i = 0; i < depth; i++)
+ {
+ Index k = j;
+ for(; k < rows; k++)
+ {
+ std::complex<Scalar> v = getAdjointVal<Scalar, Index, StorageOrder>(k, i, lhs);
+
+ blockAf[rir] = v.real();
+ blockAf[rii] = v.imag();
+
+ rir += 1;
+ rii += 1;
+ }
+ }
+ }
+}
+
+template<typename Scalar, typename Index, int StorageOrder, int N>
+EIGEN_STRONG_INLINE void symm_pack_rhs_helper(Scalar* blockB, const Scalar* _rhs, Index rhsStride, Index rows, Index cols, Index k2)
+{
+ const Index depth = k2 + rows;
+ const_blas_data_mapper<Scalar, Index, StorageOrder> rhs(_rhs, rhsStride);
+ const Index vectorSize = quad_traits<Scalar>::vectorsize;
+
+ Index ri = 0, j = 0;
+ for(; j + N*vectorSize <= cols; j+=N*vectorSize)
+ {
+ Index i = k2;
+ for(; i < depth; i++)
+ {
+ for(Index k = 0; k < N*vectorSize; k++)
+ {
+ if(i <= j+k)
+ blockB[ri + k] = rhs(j+k, i);
+ else
+ blockB[ri + k] = rhs(i, j+k);
+ }
+ ri += N*vectorSize;
+ }
+ }
+
+ if (j < cols)
+ {
+ for(Index i = k2; i < depth; i++)
+ {
+ Index k = j;
+ for(; k < cols; k++)
+ {
+ if(k <= i)
+ blockB[ri] = rhs(i, k);
+ else
+ blockB[ri] = rhs(k, i);
+ ri += 1;
+ }
+ }
+ }
+}
+
+template<typename Scalar, typename Index, int StorageOrder>
+EIGEN_STRONG_INLINE void symm_pack_lhs_helper(Scalar* blockA, const Scalar* _lhs, Index lhsStride, Index cols, Index rows)
+{
+ const Index depth = cols;
+ const_blas_data_mapper<Scalar, Index, StorageOrder> lhs(_lhs, lhsStride);
+ const Index vectorSize = quad_traits<Scalar>::vectorsize;
+
+ Index ri = 0, j = 0;
+ for(; j + vectorSize <= rows; j+=vectorSize)
+ {
+ Index i = 0;
+
+ for(; i < depth; i++)
+ {
+ for(Index k = 0; k < vectorSize; k++)
+ {
+ if(i <= j+k)
+ blockA[ri + k] = lhs(j+k, i);
+ else
+ blockA[ri + k] = lhs(i, j+k);
+ }
+ ri += vectorSize;
+ }
+ }
+
+ if (j < rows)
+ {
+ for(Index i = 0; i < depth; i++)
+ {
+ Index k = j;
+ for(; k < rows; k++)
+ {
+ if(i <= k)
+ blockA[ri] = lhs(k, i);
+ else
+ blockA[ri] = lhs(i, k);
+ ri += 1;
+ }
+ }
+ }
+}
+
+template<typename Index, int nr, int StorageOrder>
+struct symm_pack_rhs<std::complex<float>, Index, nr, StorageOrder>
+{
+ void operator()(std::complex<float>* blockB, const std::complex<float>* _rhs, Index rhsStride, Index rows, Index cols, Index k2)
+ {
+ symm_pack_complex_rhs_helper<float, Index, StorageOrder, 1>(blockB, _rhs, rhsStride, rows, cols, k2);
+ }
+};
+
+template<typename Index, int Pack1, int Pack2_dummy, int StorageOrder>
+struct symm_pack_lhs<std::complex<float>, Index, Pack1, Pack2_dummy, StorageOrder>
+{
+ void operator()(std::complex<float>* blockA, const std::complex<float>* _lhs, Index lhsStride, Index cols, Index rows)
+ {
+ symm_pack_complex_lhs_helper<float, Index, StorageOrder>(blockA, _lhs, lhsStride, cols, rows);
+ }
+};
+
+// *********** symm_pack std::complex<float64> ***********
+
+template<typename Index, int nr, int StorageOrder>
+struct symm_pack_rhs<std::complex<double>, Index, nr, StorageOrder>
+{
+ void operator()(std::complex<double>* blockB, const std::complex<double>* _rhs, Index rhsStride, Index rows, Index cols, Index k2)
+ {
+ symm_pack_complex_rhs_helper<double, Index, StorageOrder, 2>(blockB, _rhs, rhsStride, rows, cols, k2);
+ }
+};
+
+template<typename Index, int Pack1, int Pack2_dummy, int StorageOrder>
+struct symm_pack_lhs<std::complex<double>, Index, Pack1, Pack2_dummy, StorageOrder>
+{
+ void operator()(std::complex<double>* blockA, const std::complex<double>* _lhs, Index lhsStride, Index cols, Index rows)
+ {
+ symm_pack_complex_lhs_helper<double, Index, StorageOrder>(blockA, _lhs, lhsStride, cols, rows);
+ }
+};
+
+// *********** symm_pack float32 ***********
+template<typename Index, int nr, int StorageOrder>
+struct symm_pack_rhs<float, Index, nr, StorageOrder>
+{
+ void operator()(float* blockB, const float* _rhs, Index rhsStride, Index rows, Index cols, Index k2)
+ {
+ symm_pack_rhs_helper<float, Index, StorageOrder, 1>(blockB, _rhs, rhsStride, rows, cols, k2);
+ }
+};
+
+template<typename Index, int Pack1, int Pack2_dummy, int StorageOrder>
+struct symm_pack_lhs<float, Index, Pack1, Pack2_dummy, StorageOrder>
+{
+ void operator()(float* blockA, const float* _lhs, Index lhsStride, Index cols, Index rows)
+ {
+ symm_pack_lhs_helper<float, Index, StorageOrder>(blockA, _lhs, lhsStride, cols, rows);
+ }
+};
+
+// *********** symm_pack float64 ***********
+template<typename Index, int nr, int StorageOrder>
+struct symm_pack_rhs<double, Index, nr, StorageOrder>
+{
+ void operator()(double* blockB, const double* _rhs, Index rhsStride, Index rows, Index cols, Index k2)
+ {
+ symm_pack_rhs_helper<double, Index, StorageOrder, 2>(blockB, _rhs, rhsStride, rows, cols, k2);
+ }
+};
+
+template<typename Index, int Pack1, int Pack2_dummy, int StorageOrder>
+struct symm_pack_lhs<double, Index, Pack1, Pack2_dummy, StorageOrder>
+{
+ void operator()(double* blockA, const double* _lhs, Index lhsStride, Index cols, Index rows)
+ {
+ symm_pack_lhs_helper<double, Index, StorageOrder>(blockA, _lhs, lhsStride, cols, rows);
+ }
+};
+
+/**
+ * PanelMode
+ * Packing might be called several times before being multiplied by gebp_kernel, this happens because
+ * on special occasions it fills part of block with other parts of the matrix. Two variables control
+ * how PanelMode should behave: offset and stride. The idea is that those variables represent whatever
+ * is going to be the real offset and stride in the future and this is what you should obey. The process
+ * is to behave as you would with normal packing but leave the start of each part with the correct offset
+ * and the end as well respecting the real stride the block will have. Gebp is aware of both blocks stride
+ * and offset and behaves accordingly.
+ **/
+
+template<typename Scalar, typename Packet, typename Index>
+EIGEN_ALWAYS_INLINE void storeBlock(Scalar* to, PacketBlock<Packet,4>& block)
+{
+ const Index size = 16 / sizeof(Scalar);
+ pstore<Scalar>(to + (0 * size), block.packet[0]);
+ pstore<Scalar>(to + (1 * size), block.packet[1]);
+ pstore<Scalar>(to + (2 * size), block.packet[2]);
+ pstore<Scalar>(to + (3 * size), block.packet[3]);
+}
+
+template<typename Scalar, typename Packet, typename Index>
+EIGEN_ALWAYS_INLINE void storeBlock(Scalar* to, PacketBlock<Packet,2>& block)
+{
+ const Index size = 16 / sizeof(Scalar);
+ pstore<Scalar>(to + (0 * size), block.packet[0]);
+ pstore<Scalar>(to + (1 * size), block.packet[1]);
+}
+
+// General template for lhs & rhs complex packing.
+template<typename Scalar, typename Index, typename DataMapper, typename Packet, typename PacketC, int StorageOrder, bool Conjugate, bool PanelMode, bool UseLhs>
+struct dhs_cpack {
+ EIGEN_STRONG_INLINE void operator()(std::complex<Scalar>* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+ {
+ const Index vectorSize = quad_traits<Scalar>::vectorsize;
+ const Index vectorDelta = vectorSize * ((PanelMode) ? stride : depth);
+ Index rir = ((PanelMode) ? (vectorSize*offset) : 0), rii;
+ Scalar* blockAt = reinterpret_cast<Scalar *>(blockA);
+ Index j = 0;
+
+ for(; j + vectorSize <= rows; j+=vectorSize)
+ {
+ Index i = 0;
+
+ rii = rir + vectorDelta;
+
+ for(; i + vectorSize <= depth; i+=vectorSize)
+ {
+ PacketBlock<Packet,4> blockr, blocki;
+ PacketBlock<PacketC,8> cblock;
+
+ if (UseLhs) {
+ bload<DataMapper, PacketC, Index, 2, 0, StorageOrder>(cblock, lhs, j, i);
+ } else {
+ bload<DataMapper, PacketC, Index, 2, 0, StorageOrder>(cblock, lhs, i, j);
+ }
+
+ blockr.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[4].v, p16uc_GETREAL32);
+ blockr.packet[1] = vec_perm(cblock.packet[1].v, cblock.packet[5].v, p16uc_GETREAL32);
+ blockr.packet[2] = vec_perm(cblock.packet[2].v, cblock.packet[6].v, p16uc_GETREAL32);
+ blockr.packet[3] = vec_perm(cblock.packet[3].v, cblock.packet[7].v, p16uc_GETREAL32);
+
+ blocki.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[4].v, p16uc_GETIMAG32);
+ blocki.packet[1] = vec_perm(cblock.packet[1].v, cblock.packet[5].v, p16uc_GETIMAG32);
+ blocki.packet[2] = vec_perm(cblock.packet[2].v, cblock.packet[6].v, p16uc_GETIMAG32);
+ blocki.packet[3] = vec_perm(cblock.packet[3].v, cblock.packet[7].v, p16uc_GETIMAG32);
+
+ if(Conjugate)
+ {
+ blocki.packet[0] = -blocki.packet[0];
+ blocki.packet[1] = -blocki.packet[1];
+ blocki.packet[2] = -blocki.packet[2];
+ blocki.packet[3] = -blocki.packet[3];
+ }
+
+ if(((StorageOrder == RowMajor) && UseLhs) || (((StorageOrder == ColMajor) && !UseLhs)))
+ {
+ ptranspose(blockr);
+ ptranspose(blocki);
+ }
+
+ storeBlock<Scalar, Packet, Index>(blockAt + rir, blockr);
+ storeBlock<Scalar, Packet, Index>(blockAt + rii, blocki);
+
+ rir += 4*vectorSize;
+ rii += 4*vectorSize;
+ }
+ for(; i < depth; i++)
+ {
+ PacketBlock<Packet,1> blockr, blocki;
+ PacketBlock<PacketC,2> cblock;
+
+ if(((StorageOrder == ColMajor) && UseLhs) || (((StorageOrder == RowMajor) && !UseLhs)))
+ {
+ if (UseLhs) {
+ cblock.packet[0] = lhs.template loadPacket<PacketC>(j + 0, i);
+ cblock.packet[1] = lhs.template loadPacket<PacketC>(j + 2, i);
+ } else {
+ cblock.packet[0] = lhs.template loadPacket<PacketC>(i, j + 0);
+ cblock.packet[1] = lhs.template loadPacket<PacketC>(i, j + 2);
+ }
+ } else {
+ std::complex<Scalar> lhs0, lhs1;
+ if (UseLhs) {
+ lhs0 = lhs(j + 0, i);
+ lhs1 = lhs(j + 1, i);
+ cblock.packet[0] = pload2(&lhs0, &lhs1);
+ lhs0 = lhs(j + 2, i);
+ lhs1 = lhs(j + 3, i);
+ cblock.packet[1] = pload2(&lhs0, &lhs1);
+ } else {
+ lhs0 = lhs(i, j + 0);
+ lhs1 = lhs(i, j + 1);
+ cblock.packet[0] = pload2(&lhs0, &lhs1);
+ lhs0 = lhs(i, j + 2);
+ lhs1 = lhs(i, j + 3);
+ cblock.packet[1] = pload2(&lhs0, &lhs1);
+ }
+ }
+
+ blockr.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[1].v, p16uc_GETREAL32);
+ blocki.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[1].v, p16uc_GETIMAG32);
+
+ if(Conjugate)
+ {
+ blocki.packet[0] = -blocki.packet[0];
+ }
+
+ pstore<Scalar>(blockAt + rir, blockr.packet[0]);
+ pstore<Scalar>(blockAt + rii, blocki.packet[0]);
+
+ rir += vectorSize;
+ rii += vectorSize;
+ }
+
+ rir += ((PanelMode) ? (vectorSize*(2*stride - depth)) : vectorDelta);
+ }
+
+ if (j < rows)
+ {
+ if(PanelMode) rir += (offset*(rows - j - vectorSize));
+ rii = rir + (((PanelMode) ? stride : depth) * (rows - j));
+
+ for(Index i = 0; i < depth; i++)
+ {
+ Index k = j;
+ for(; k < rows; k++)
+ {
+ if (UseLhs) {
+ blockAt[rir] = lhs(k, i).real();
+
+ if(Conjugate)
+ blockAt[rii] = -lhs(k, i).imag();
+ else
+ blockAt[rii] = lhs(k, i).imag();
+ } else {
+ blockAt[rir] = lhs(i, k).real();
+
+ if(Conjugate)
+ blockAt[rii] = -lhs(i, k).imag();
+ else
+ blockAt[rii] = lhs(i, k).imag();
+ }
+
+ rir += 1;
+ rii += 1;
+ }
+ }
+ }
+ }
+};
+
+// General template for lhs & rhs packing.
+template<typename Scalar, typename Index, typename DataMapper, typename Packet, int StorageOrder, bool PanelMode, bool UseLhs>
+struct dhs_pack{
+ EIGEN_STRONG_INLINE void operator()(Scalar* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+ {
+ const Index vectorSize = quad_traits<Scalar>::vectorsize;
+ Index ri = 0, j = 0;
+
+ for(; j + vectorSize <= rows; j+=vectorSize)
+ {
+ Index i = 0;
+
+ if(PanelMode) ri += vectorSize*offset;
+
+ for(; i + vectorSize <= depth; i+=vectorSize)
+ {
+ PacketBlock<Packet,4> block;
+
+ if (UseLhs) {
+ bload<DataMapper, Packet, Index, 4, 0, StorageOrder>(block, lhs, j, i);
+ } else {
+ bload<DataMapper, Packet, Index, 4, 0, StorageOrder>(block, lhs, i, j);
+ }
+ if(((StorageOrder == RowMajor) && UseLhs) || ((StorageOrder == ColMajor) && !UseLhs))
+ {
+ ptranspose(block);
+ }
+
+ storeBlock<Scalar, Packet, Index>(blockA + ri, block);
+
+ ri += 4*vectorSize;
+ }
+ for(; i < depth; i++)
+ {
+ if(((StorageOrder == RowMajor) && UseLhs) || ((StorageOrder == ColMajor) && !UseLhs))
+ {
+ if (UseLhs) {
+ blockA[ri+0] = lhs(j+0, i);
+ blockA[ri+1] = lhs(j+1, i);
+ blockA[ri+2] = lhs(j+2, i);
+ blockA[ri+3] = lhs(j+3, i);
+ } else {
+ blockA[ri+0] = lhs(i, j+0);
+ blockA[ri+1] = lhs(i, j+1);
+ blockA[ri+2] = lhs(i, j+2);
+ blockA[ri+3] = lhs(i, j+3);
+ }
+ } else {
+ Packet lhsV;
+ if (UseLhs) {
+ lhsV = lhs.template loadPacket<Packet>(j, i);
+ } else {
+ lhsV = lhs.template loadPacket<Packet>(i, j);
+ }
+ pstore<Scalar>(blockA + ri, lhsV);
+ }
+
+ ri += vectorSize;
+ }
+
+ if(PanelMode) ri += vectorSize*(stride - offset - depth);
+ }
+
+ if (j < rows)
+ {
+ if(PanelMode) ri += offset*(rows - j);
+
+ for(Index i = 0; i < depth; i++)
+ {
+ Index k = j;
+ for(; k < rows; k++)
+ {
+ if (UseLhs) {
+ blockA[ri] = lhs(k, i);
+ } else {
+ blockA[ri] = lhs(i, k);
+ }
+ ri += 1;
+ }
+ }
+ }
+ }
+};
+
+// General template for lhs packing, float64 specialization.
+template<typename Index, typename DataMapper, int StorageOrder, bool PanelMode>
+struct dhs_pack<double, Index, DataMapper, Packet2d, StorageOrder, PanelMode, true>
+{
+ EIGEN_STRONG_INLINE void operator()(double* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+ {
+ const Index vectorSize = quad_traits<double>::vectorsize;
+ Index ri = 0, j = 0;
+
+ for(; j + vectorSize <= rows; j+=vectorSize)
+ {
+ Index i = 0;
+
+ if(PanelMode) ri += vectorSize*offset;
+
+ for(; i + vectorSize <= depth; i+=vectorSize)
+ {
+ PacketBlock<Packet2d,2> block;
+ if(StorageOrder == RowMajor)
+ {
+ block.packet[0] = lhs.template loadPacket<Packet2d>(j + 0, i);
+ block.packet[1] = lhs.template loadPacket<Packet2d>(j + 1, i);
+
+ ptranspose(block);
+ } else {
+ block.packet[0] = lhs.template loadPacket<Packet2d>(j, i + 0);
+ block.packet[1] = lhs.template loadPacket<Packet2d>(j, i + 1);
+ }
+
+ storeBlock<double, Packet2d, Index>(blockA + ri, block);
+
+ ri += 2*vectorSize;
+ }
+ for(; i < depth; i++)
+ {
+ if(StorageOrder == RowMajor)
+ {
+ blockA[ri+0] = lhs(j+0, i);
+ blockA[ri+1] = lhs(j+1, i);
+ } else {
+ Packet2d lhsV = lhs.template loadPacket<Packet2d>(j, i);
+ pstore<double>(blockA + ri, lhsV);
+ }
+
+ ri += vectorSize;
+ }
+
+ if(PanelMode) ri += vectorSize*(stride - offset - depth);
+ }
+
+ if (j < rows)
+ {
+ if(PanelMode) ri += offset*(rows - j);
+
+ for(Index i = 0; i < depth; i++)
+ {
+ Index k = j;
+ for(; k < rows; k++)
+ {
+ blockA[ri] = lhs(k, i);
+ ri += 1;
+ }
+ }
+ }
+ }
+};
+
+// General template for rhs packing, float64 specialization.
+template<typename Index, typename DataMapper, int StorageOrder, bool PanelMode>
+struct dhs_pack<double, Index, DataMapper, Packet2d, StorageOrder, PanelMode, false>
+{
+ EIGEN_STRONG_INLINE void operator()(double* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset)
+ {
+ const Index vectorSize = quad_traits<double>::vectorsize;
+ Index ri = 0, j = 0;
+
+ for(; j + 2*vectorSize <= cols; j+=2*vectorSize)
+ {
+ Index i = 0;
+
+ if(PanelMode) ri += offset*(2*vectorSize);
+
+ for(; i + vectorSize <= depth; i+=vectorSize)
+ {
+ PacketBlock<Packet2d,4> block;
+ if(StorageOrder == ColMajor)
+ {
+ PacketBlock<Packet2d,2> block1, block2;
+ block1.packet[0] = rhs.template loadPacket<Packet2d>(i, j + 0);
+ block1.packet[1] = rhs.template loadPacket<Packet2d>(i, j + 1);
+ block2.packet[0] = rhs.template loadPacket<Packet2d>(i, j + 2);
+ block2.packet[1] = rhs.template loadPacket<Packet2d>(i, j + 3);
+
+ ptranspose(block1);
+ ptranspose(block2);
+
+ pstore<double>(blockB + ri , block1.packet[0]);
+ pstore<double>(blockB + ri + 2, block2.packet[0]);
+ pstore<double>(blockB + ri + 4, block1.packet[1]);
+ pstore<double>(blockB + ri + 6, block2.packet[1]);
+ } else {
+ block.packet[0] = rhs.template loadPacket<Packet2d>(i + 0, j + 0); //[a1 a2]
+ block.packet[1] = rhs.template loadPacket<Packet2d>(i + 0, j + 2); //[a3 a4]
+ block.packet[2] = rhs.template loadPacket<Packet2d>(i + 1, j + 0); //[b1 b2]
+ block.packet[3] = rhs.template loadPacket<Packet2d>(i + 1, j + 2); //[b3 b4]
+
+ storeBlock<double, Packet2d, Index>(blockB + ri, block);
+ }
+
+ ri += 4*vectorSize;
+ }
+ for(; i < depth; i++)
+ {
+ if(StorageOrder == ColMajor)
+ {
+ blockB[ri+0] = rhs(i, j+0);
+ blockB[ri+1] = rhs(i, j+1);
+
+ ri += vectorSize;
+
+ blockB[ri+0] = rhs(i, j+2);
+ blockB[ri+1] = rhs(i, j+3);
+ } else {
+ Packet2d rhsV = rhs.template loadPacket<Packet2d>(i, j);
+ pstore<double>(blockB + ri, rhsV);
+
+ ri += vectorSize;
+
+ rhsV = rhs.template loadPacket<Packet2d>(i, j + 2);
+ pstore<double>(blockB + ri, rhsV);
+ }
+ ri += vectorSize;
+ }
+
+ if(PanelMode) ri += (2*vectorSize)*(stride - offset - depth);
+ }
+
+ if (j < cols)
+ {
+ if(PanelMode) ri += offset*(cols - j);
+
+ for(Index i = 0; i < depth; i++)
+ {
+ Index k = j;
+ for(; k < cols; k++)
+ {
+ blockB[ri] = rhs(i, k);
+ ri += 1;
+ }
+ }
+ }
+ }
+};
+
+// General template for lhs complex packing, float64 specialization.
+template<typename Index, typename DataMapper, typename Packet, typename PacketC, int StorageOrder, bool Conjugate, bool PanelMode>
+struct dhs_cpack<double, Index, DataMapper, Packet, PacketC, StorageOrder, Conjugate, PanelMode, true>
+{
+ EIGEN_STRONG_INLINE void operator()(std::complex<double>* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+ {
+ const Index vectorSize = quad_traits<double>::vectorsize;
+ const Index vectorDelta = vectorSize * ((PanelMode) ? stride : depth);
+ Index rir = ((PanelMode) ? (vectorSize*offset) : 0), rii;
+ double* blockAt = reinterpret_cast<double *>(blockA);
+ Index j = 0;
+
+ for(; j + vectorSize <= rows; j+=vectorSize)
+ {
+ Index i = 0;
+
+ rii = rir + vectorDelta;
+
+ for(; i + vectorSize <= depth; i+=vectorSize)
+ {
+ PacketBlock<Packet,2> blockr, blocki;
+ PacketBlock<PacketC,4> cblock;
+
+ if(StorageOrder == ColMajor)
+ {
+ cblock.packet[0] = lhs.template loadPacket<PacketC>(j, i + 0); //[a1 a1i]
+ cblock.packet[1] = lhs.template loadPacket<PacketC>(j, i + 1); //[b1 b1i]
+
+ cblock.packet[2] = lhs.template loadPacket<PacketC>(j + 1, i + 0); //[a2 a2i]
+ cblock.packet[3] = lhs.template loadPacket<PacketC>(j + 1, i + 1); //[b2 b2i]
+
+ blockr.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[2].v, p16uc_GETREAL64); //[a1 a2]
+ blockr.packet[1] = vec_perm(cblock.packet[1].v, cblock.packet[3].v, p16uc_GETREAL64); //[b1 b2]
+
+ blocki.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[2].v, p16uc_GETIMAG64);
+ blocki.packet[1] = vec_perm(cblock.packet[1].v, cblock.packet[3].v, p16uc_GETIMAG64);
+ } else {
+ cblock.packet[0] = lhs.template loadPacket<PacketC>(j + 0, i); //[a1 a1i]
+ cblock.packet[1] = lhs.template loadPacket<PacketC>(j + 1, i); //[a2 a2i]
+
+ cblock.packet[2] = lhs.template loadPacket<PacketC>(j + 0, i + 1); //[b1 b1i]
+ cblock.packet[3] = lhs.template loadPacket<PacketC>(j + 1, i + 1); //[b2 b2i
+
+ blockr.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[1].v, p16uc_GETREAL64); //[a1 a2]
+ blockr.packet[1] = vec_perm(cblock.packet[2].v, cblock.packet[3].v, p16uc_GETREAL64); //[b1 b2]
+
+ blocki.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[1].v, p16uc_GETIMAG64);
+ blocki.packet[1] = vec_perm(cblock.packet[2].v, cblock.packet[3].v, p16uc_GETIMAG64);
+ }
+
+ if(Conjugate)
+ {
+ blocki.packet[0] = -blocki.packet[0];
+ blocki.packet[1] = -blocki.packet[1];
+ }
+
+ storeBlock<double, Packet, Index>(blockAt + rir, blockr);
+ storeBlock<double, Packet, Index>(blockAt + rii, blocki);
+
+ rir += 2*vectorSize;
+ rii += 2*vectorSize;
+ }
+ for(; i < depth; i++)
+ {
+ PacketBlock<Packet,1> blockr, blocki;
+ PacketBlock<PacketC,2> cblock;
+
+ cblock.packet[0] = lhs.template loadPacket<PacketC>(j + 0, i);
+ cblock.packet[1] = lhs.template loadPacket<PacketC>(j + 1, i);
+
+ blockr.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[1].v, p16uc_GETREAL64);
+ blocki.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[1].v, p16uc_GETIMAG64);
+
+ if(Conjugate)
+ {
+ blocki.packet[0] = -blocki.packet[0];
+ }
+
+ pstore<double>(blockAt + rir, blockr.packet[0]);
+ pstore<double>(blockAt + rii, blocki.packet[0]);
+
+ rir += vectorSize;
+ rii += vectorSize;
+ }
+
+ rir += ((PanelMode) ? (vectorSize*(2*stride - depth)) : vectorDelta);
+ }
+
+ if (j < rows)
+ {
+ if(PanelMode) rir += (offset*(rows - j - vectorSize));
+ rii = rir + (((PanelMode) ? stride : depth) * (rows - j));
+
+ for(Index i = 0; i < depth; i++)
+ {
+ Index k = j;
+ for(; k < rows; k++)
+ {
+ blockAt[rir] = lhs(k, i).real();
+
+ if(Conjugate)
+ blockAt[rii] = -lhs(k, i).imag();
+ else
+ blockAt[rii] = lhs(k, i).imag();
+
+ rir += 1;
+ rii += 1;
+ }
+ }
+ }
+ }
+};
+
+// General template for rhs complex packing, float64 specialization.
+template<typename Index, typename DataMapper, typename Packet, typename PacketC, int StorageOrder, bool Conjugate, bool PanelMode>
+struct dhs_cpack<double, Index, DataMapper, Packet, PacketC, StorageOrder, Conjugate, PanelMode, false>
+{
+ EIGEN_STRONG_INLINE void operator()(std::complex<double>* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset)
+ {
+ const Index vectorSize = quad_traits<double>::vectorsize;
+ const Index vectorDelta = 2*vectorSize * ((PanelMode) ? stride : depth);
+ Index rir = ((PanelMode) ? (2*vectorSize*offset) : 0), rii;
+ double* blockBt = reinterpret_cast<double *>(blockB);
+ Index j = 0;
+
+ for(; j + 2*vectorSize <= cols; j+=2*vectorSize)
+ {
+ Index i = 0;
+
+ rii = rir + vectorDelta;
+
+ for(; i < depth; i++)
+ {
+ PacketBlock<PacketC,4> cblock;
+ PacketBlock<Packet,2> blockr, blocki;
+
+ bload<DataMapper, PacketC, Index, 2, 0, ColMajor>(cblock, rhs, i, j);
+
+ blockr.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[1].v, p16uc_GETREAL64);
+ blockr.packet[1] = vec_perm(cblock.packet[2].v, cblock.packet[3].v, p16uc_GETREAL64);
+
+ blocki.packet[0] = vec_perm(cblock.packet[0].v, cblock.packet[1].v, p16uc_GETIMAG64);
+ blocki.packet[1] = vec_perm(cblock.packet[2].v, cblock.packet[3].v, p16uc_GETIMAG64);
+
+ if(Conjugate)
+ {
+ blocki.packet[0] = -blocki.packet[0];
+ blocki.packet[1] = -blocki.packet[1];
+ }
+
+ storeBlock<double, Packet, Index>(blockBt + rir, blockr);
+ storeBlock<double, Packet, Index>(blockBt + rii, blocki);
+
+ rir += 2*vectorSize;
+ rii += 2*vectorSize;
+ }
+
+ rir += ((PanelMode) ? (2*vectorSize*(2*stride - depth)) : vectorDelta);
+ }
+
+ if (j < cols)
+ {
+ if(PanelMode) rir += (offset*(cols - j - 2*vectorSize));
+ rii = rir + (((PanelMode) ? stride : depth) * (cols - j));
+
+ for(Index i = 0; i < depth; i++)
+ {
+ Index k = j;
+ for(; k < cols; k++)
+ {
+ blockBt[rir] = rhs(i, k).real();
+
+ if(Conjugate)
+ blockBt[rii] = -rhs(i, k).imag();
+ else
+ blockBt[rii] = rhs(i, k).imag();
+
+ rir += 1;
+ rii += 1;
+ }
+ }
+ }
+ }
+};
+
+/**************
+ * GEMM utils *
+ **************/
+
+// 512-bits rank1-update of acc. It can either positive or negative accumulate (useful for complex gemm).
+template<typename Packet, bool NegativeAccumulate>
+EIGEN_ALWAYS_INLINE void pger_common(PacketBlock<Packet,4>* acc, const Packet& lhsV, const Packet* rhsV)
+{
+ if(NegativeAccumulate)
+ {
+ acc->packet[0] = vec_nmsub(lhsV, rhsV[0], acc->packet[0]);
+ acc->packet[1] = vec_nmsub(lhsV, rhsV[1], acc->packet[1]);
+ acc->packet[2] = vec_nmsub(lhsV, rhsV[2], acc->packet[2]);
+ acc->packet[3] = vec_nmsub(lhsV, rhsV[3], acc->packet[3]);
+ } else {
+ acc->packet[0] = vec_madd(lhsV, rhsV[0], acc->packet[0]);
+ acc->packet[1] = vec_madd(lhsV, rhsV[1], acc->packet[1]);
+ acc->packet[2] = vec_madd(lhsV, rhsV[2], acc->packet[2]);
+ acc->packet[3] = vec_madd(lhsV, rhsV[3], acc->packet[3]);
+ }
+}
+
+template<typename Packet, bool NegativeAccumulate>
+EIGEN_ALWAYS_INLINE void pger_common(PacketBlock<Packet,1>* acc, const Packet& lhsV, const Packet* rhsV)
+{
+ if(NegativeAccumulate)
+ {
+ acc->packet[0] = vec_nmsub(lhsV, rhsV[0], acc->packet[0]);
+ } else {
+ acc->packet[0] = vec_madd(lhsV, rhsV[0], acc->packet[0]);
+ }
+}
+
+template<int N, typename Scalar, typename Packet, bool NegativeAccumulate>
+EIGEN_ALWAYS_INLINE void pger(PacketBlock<Packet,N>* acc, const Scalar* lhs, const Packet* rhsV)
+{
+ Packet lhsV = pload<Packet>(lhs);
+
+ pger_common<Packet, NegativeAccumulate>(acc, lhsV, rhsV);
+}
+
+template<typename Scalar, typename Packet, typename Index>
+EIGEN_ALWAYS_INLINE void loadPacketRemaining(const Scalar* lhs, Packet &lhsV, Index remaining_rows)
+{
+#ifdef _ARCH_PWR9
+ lhsV = vec_xl_len((Scalar *)lhs, remaining_rows * sizeof(Scalar));
+#else
+ Index i = 0;
+ do {
+ lhsV[i] = lhs[i];
+ } while (++i < remaining_rows);
+#endif
+}
+
+template<int N, typename Scalar, typename Packet, typename Index, bool NegativeAccumulate>
+EIGEN_ALWAYS_INLINE void pger(PacketBlock<Packet,N>* acc, const Scalar* lhs, const Packet* rhsV, Index remaining_rows)
+{
+ Packet lhsV;
+ loadPacketRemaining<Scalar, Packet, Index>(lhs, lhsV, remaining_rows);
+
+ pger_common<Packet, NegativeAccumulate>(acc, lhsV, rhsV);
+}
+
+// 512-bits rank1-update of complex acc. It takes decoupled accumulators as entries. It also takes cares of mixed types real * complex and complex * real.
+template<int N, typename Packet, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_ALWAYS_INLINE void pgerc_common(PacketBlock<Packet,N>* accReal, PacketBlock<Packet,N>* accImag, const Packet &lhsV, const Packet &lhsVi, const Packet* rhsV, const Packet* rhsVi)
+{
+ pger_common<Packet, false>(accReal, lhsV, rhsV);
+ if(LhsIsReal)
+ {
+ pger_common<Packet, ConjugateRhs>(accImag, lhsV, rhsVi);
+ EIGEN_UNUSED_VARIABLE(lhsVi);
+ } else {
+ if (!RhsIsReal) {
+ pger_common<Packet, ConjugateLhs == ConjugateRhs>(accReal, lhsVi, rhsVi);
+ pger_common<Packet, ConjugateRhs>(accImag, lhsV, rhsVi);
+ } else {
+ EIGEN_UNUSED_VARIABLE(rhsVi);
+ }
+ pger_common<Packet, ConjugateLhs>(accImag, lhsVi, rhsV);
+ }
+}
+
+template<int N, typename Scalar, typename Packet, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_ALWAYS_INLINE void pgerc(PacketBlock<Packet,N>* accReal, PacketBlock<Packet,N>* accImag, const Scalar* lhs_ptr, const Scalar* lhs_ptr_imag, const Packet* rhsV, const Packet* rhsVi)
+{
+ Packet lhsV = ploadLhs<Scalar, Packet>(lhs_ptr);
+ Packet lhsVi;
+ if(!LhsIsReal) lhsVi = ploadLhs<Scalar, Packet>(lhs_ptr_imag);
+ else EIGEN_UNUSED_VARIABLE(lhs_ptr_imag);
+
+ pgerc_common<N, Packet, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(accReal, accImag, lhsV, lhsVi, rhsV, rhsVi);
+}
+
+template<typename Scalar, typename Packet, typename Index, bool LhsIsReal>
+EIGEN_ALWAYS_INLINE void loadPacketRemaining(const Scalar* lhs_ptr, const Scalar* lhs_ptr_imag, Packet &lhsV, Packet &lhsVi, Index remaining_rows)
+{
+#ifdef _ARCH_PWR9
+ lhsV = vec_xl_len((Scalar *)lhs_ptr, remaining_rows * sizeof(Scalar));
+ if(!LhsIsReal) lhsVi = vec_xl_len((Scalar *)lhs_ptr_imag, remaining_rows * sizeof(Scalar));
+ else EIGEN_UNUSED_VARIABLE(lhs_ptr_imag);
+#else
+ Index i = 0;
+ do {
+ lhsV[i] = lhs_ptr[i];
+ if(!LhsIsReal) lhsVi[i] = lhs_ptr_imag[i];
+ } while (++i < remaining_rows);
+ if(LhsIsReal) EIGEN_UNUSED_VARIABLE(lhs_ptr_imag);
+#endif
+}
+
+template<int N, typename Scalar, typename Packet, typename Index, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_ALWAYS_INLINE void pgerc(PacketBlock<Packet,N>* accReal, PacketBlock<Packet,N>* accImag, const Scalar* lhs_ptr, const Scalar* lhs_ptr_imag, const Packet* rhsV, const Packet* rhsVi, Index remaining_rows)
+{
+ Packet lhsV, lhsVi;
+ loadPacketRemaining<Scalar, Packet, Index, LhsIsReal>(lhs_ptr, lhs_ptr_imag, lhsV, lhsVi, remaining_rows);
+
+ pgerc_common<N, Packet, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(accReal, accImag, lhsV, lhsVi, rhsV, rhsVi);
+}
+
+template<typename Scalar, typename Packet>
+EIGEN_ALWAYS_INLINE Packet ploadLhs(const Scalar* lhs)
+{
+ return ploadu<Packet>(lhs);
+}
+
+// Zero the accumulator on PacketBlock.
+template<typename Scalar, typename Packet>
+EIGEN_ALWAYS_INLINE void bsetzero(PacketBlock<Packet,4>& acc)
+{
+ acc.packet[0] = pset1<Packet>((Scalar)0);
+ acc.packet[1] = pset1<Packet>((Scalar)0);
+ acc.packet[2] = pset1<Packet>((Scalar)0);
+ acc.packet[3] = pset1<Packet>((Scalar)0);
+}
+
+template<typename Scalar, typename Packet>
+EIGEN_ALWAYS_INLINE void bsetzero(PacketBlock<Packet,1>& acc)
+{
+ acc.packet[0] = pset1<Packet>((Scalar)0);
+}
+
+// Scale the PacketBlock vectors by alpha.
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void bscale(PacketBlock<Packet,4>& acc, PacketBlock<Packet,4>& accZ, const Packet& pAlpha)
+{
+ acc.packet[0] = pmadd(pAlpha, accZ.packet[0], acc.packet[0]);
+ acc.packet[1] = pmadd(pAlpha, accZ.packet[1], acc.packet[1]);
+ acc.packet[2] = pmadd(pAlpha, accZ.packet[2], acc.packet[2]);
+ acc.packet[3] = pmadd(pAlpha, accZ.packet[3], acc.packet[3]);
+}
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void bscale(PacketBlock<Packet,1>& acc, PacketBlock<Packet,1>& accZ, const Packet& pAlpha)
+{
+ acc.packet[0] = pmadd(pAlpha, accZ.packet[0], acc.packet[0]);
+}
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void bscalec_common(PacketBlock<Packet,4>& acc, PacketBlock<Packet,4>& accZ, const Packet& pAlpha)
+{
+ acc.packet[0] = pmul<Packet>(accZ.packet[0], pAlpha);
+ acc.packet[1] = pmul<Packet>(accZ.packet[1], pAlpha);
+ acc.packet[2] = pmul<Packet>(accZ.packet[2], pAlpha);
+ acc.packet[3] = pmul<Packet>(accZ.packet[3], pAlpha);
+}
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void bscalec_common(PacketBlock<Packet,1>& acc, PacketBlock<Packet,1>& accZ, const Packet& pAlpha)
+{
+ acc.packet[0] = pmul<Packet>(accZ.packet[0], pAlpha);
+}
+
+// Complex version of PacketBlock scaling.
+template<typename Packet, int N>
+EIGEN_ALWAYS_INLINE void bscalec(PacketBlock<Packet,N>& aReal, PacketBlock<Packet,N>& aImag, const Packet& bReal, const Packet& bImag, PacketBlock<Packet,N>& cReal, PacketBlock<Packet,N>& cImag)
+{
+ bscalec_common<Packet>(cReal, aReal, bReal);
+
+ bscalec_common<Packet>(cImag, aImag, bReal);
+
+ pger_common<Packet, true>(&cReal, bImag, aImag.packet);
+
+ pger_common<Packet, false>(&cImag, bImag, aReal.packet);
+}
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void band(PacketBlock<Packet,4>& acc, const Packet& pMask)
+{
+ acc.packet[0] = pand(acc.packet[0], pMask);
+ acc.packet[1] = pand(acc.packet[1], pMask);
+ acc.packet[2] = pand(acc.packet[2], pMask);
+ acc.packet[3] = pand(acc.packet[3], pMask);
+}
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void bscalec(PacketBlock<Packet,4>& aReal, PacketBlock<Packet,4>& aImag, const Packet& bReal, const Packet& bImag, PacketBlock<Packet,4>& cReal, PacketBlock<Packet,4>& cImag, const Packet& pMask)
+{
+ band<Packet>(aReal, pMask);
+ band<Packet>(aImag, pMask);
+
+ bscalec<Packet,4>(aReal, aImag, bReal, bImag, cReal, cImag);
+}
+
+// Load a PacketBlock, the N parameters make tunning gemm easier so we can add more accumulators as needed.
+template<typename DataMapper, typename Packet, typename Index, const Index accCols, int N, int StorageOrder>
+EIGEN_ALWAYS_INLINE void bload(PacketBlock<Packet,4>& acc, const DataMapper& res, Index row, Index col)
+{
+ if (StorageOrder == RowMajor) {
+ acc.packet[0] = res.template loadPacket<Packet>(row + 0, col + N*accCols);
+ acc.packet[1] = res.template loadPacket<Packet>(row + 1, col + N*accCols);
+ acc.packet[2] = res.template loadPacket<Packet>(row + 2, col + N*accCols);
+ acc.packet[3] = res.template loadPacket<Packet>(row + 3, col + N*accCols);
+ } else {
+ acc.packet[0] = res.template loadPacket<Packet>(row + N*accCols, col + 0);
+ acc.packet[1] = res.template loadPacket<Packet>(row + N*accCols, col + 1);
+ acc.packet[2] = res.template loadPacket<Packet>(row + N*accCols, col + 2);
+ acc.packet[3] = res.template loadPacket<Packet>(row + N*accCols, col + 3);
+ }
+}
+
+// An overload of bload when you have a PacketBLock with 8 vectors.
+template<typename DataMapper, typename Packet, typename Index, const Index accCols, int N, int StorageOrder>
+EIGEN_ALWAYS_INLINE void bload(PacketBlock<Packet,8>& acc, const DataMapper& res, Index row, Index col)
+{
+ if (StorageOrder == RowMajor) {
+ acc.packet[0] = res.template loadPacket<Packet>(row + 0, col + N*accCols);
+ acc.packet[1] = res.template loadPacket<Packet>(row + 1, col + N*accCols);
+ acc.packet[2] = res.template loadPacket<Packet>(row + 2, col + N*accCols);
+ acc.packet[3] = res.template loadPacket<Packet>(row + 3, col + N*accCols);
+ acc.packet[4] = res.template loadPacket<Packet>(row + 0, col + (N+1)*accCols);
+ acc.packet[5] = res.template loadPacket<Packet>(row + 1, col + (N+1)*accCols);
+ acc.packet[6] = res.template loadPacket<Packet>(row + 2, col + (N+1)*accCols);
+ acc.packet[7] = res.template loadPacket<Packet>(row + 3, col + (N+1)*accCols);
+ } else {
+ acc.packet[0] = res.template loadPacket<Packet>(row + N*accCols, col + 0);
+ acc.packet[1] = res.template loadPacket<Packet>(row + N*accCols, col + 1);
+ acc.packet[2] = res.template loadPacket<Packet>(row + N*accCols, col + 2);
+ acc.packet[3] = res.template loadPacket<Packet>(row + N*accCols, col + 3);
+ acc.packet[4] = res.template loadPacket<Packet>(row + (N+1)*accCols, col + 0);
+ acc.packet[5] = res.template loadPacket<Packet>(row + (N+1)*accCols, col + 1);
+ acc.packet[6] = res.template loadPacket<Packet>(row + (N+1)*accCols, col + 2);
+ acc.packet[7] = res.template loadPacket<Packet>(row + (N+1)*accCols, col + 3);
+ }
+}
+
+template<typename DataMapper, typename Packet, typename Index, const Index accCols, int N, int StorageOrder>
+EIGEN_ALWAYS_INLINE void bload(PacketBlock<Packet,2>& acc, const DataMapper& res, Index row, Index col)
+{
+ acc.packet[0] = res.template loadPacket<Packet>(row + N*accCols, col + 0);
+ acc.packet[1] = res.template loadPacket<Packet>(row + (N+1)*accCols, col + 0);
+}
+
+const static Packet4i mask41 = { -1, 0, 0, 0 };
+const static Packet4i mask42 = { -1, -1, 0, 0 };
+const static Packet4i mask43 = { -1, -1, -1, 0 };
+
+const static Packet2l mask21 = { -1, 0 };
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE Packet bmask(const int remaining_rows)
+{
+ if (remaining_rows == 0) {
+ return pset1<Packet>(float(0.0)); // Not used
+ } else {
+ switch (remaining_rows) {
+ case 1: return Packet(mask41);
+ case 2: return Packet(mask42);
+ default: return Packet(mask43);
+ }
+ }
+}
+
+template<>
+EIGEN_ALWAYS_INLINE Packet2d bmask<Packet2d>(const int remaining_rows)
+{
+ if (remaining_rows == 0) {
+ return pset1<Packet2d>(double(0.0)); // Not used
+ } else {
+ return Packet2d(mask21);
+ }
+}
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void bscale(PacketBlock<Packet,4>& acc, PacketBlock<Packet,4>& accZ, const Packet& pAlpha, const Packet& pMask)
+{
+ band<Packet>(accZ, pMask);
+
+ bscale<Packet>(acc, accZ, pAlpha);
+}
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void pbroadcast4_old(const __UNPACK_TYPE__(Packet)* a, Packet& a0, Packet& a1, Packet& a2, Packet& a3)
+{
+ pbroadcast4<Packet>(a, a0, a1, a2, a3);
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void pbroadcast4_old<Packet2d>(const double* a, Packet2d& a0, Packet2d& a1, Packet2d& a2, Packet2d& a3)
+{
+ a1 = pload<Packet2d>(a);
+ a3 = pload<Packet2d>(a + 2);
+ a0 = vec_splat(a1, 0);
+ a1 = vec_splat(a1, 1);
+ a2 = vec_splat(a3, 0);
+ a3 = vec_splat(a3, 1);
+}
+
+// PEEL loop factor.
+#define PEEL 7
+
+template<typename Scalar, typename Packet, typename Index>
+EIGEN_ALWAYS_INLINE void MICRO_EXTRA_COL(
+ const Scalar* &lhs_ptr,
+ const Scalar* &rhs_ptr,
+ PacketBlock<Packet,1> &accZero,
+ Index remaining_rows,
+ Index remaining_cols)
+{
+ Packet rhsV[1];
+ rhsV[0] = pset1<Packet>(rhs_ptr[0]);
+ pger<1,Scalar, Packet, false>(&accZero, lhs_ptr, rhsV);
+ lhs_ptr += remaining_rows;
+ rhs_ptr += remaining_cols;
+}
+
+template<typename Scalar, typename Packet, typename DataMapper, typename Index, const Index accRows>
+EIGEN_STRONG_INLINE void gemm_extra_col(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index row,
+ Index col,
+ Index remaining_rows,
+ Index remaining_cols,
+ const Packet& pAlpha)
+{
+ const Scalar* rhs_ptr = rhs_base;
+ const Scalar* lhs_ptr = lhs_base + row*strideA + remaining_rows*offsetA;
+ PacketBlock<Packet,1> accZero;
+
+ bsetzero<Scalar, Packet>(accZero);
+
+ Index remaining_depth = (depth & -accRows);
+ Index k = 0;
+ for(; k + PEEL <= remaining_depth; k+= PEEL)
+ {
+ EIGEN_POWER_PREFETCH(rhs_ptr);
+ EIGEN_POWER_PREFETCH(lhs_ptr);
+ for (int l = 0; l < PEEL; l++) {
+ MICRO_EXTRA_COL<Scalar, Packet, Index>(lhs_ptr, rhs_ptr, accZero, remaining_rows, remaining_cols);
+ }
+ }
+ for(; k < remaining_depth; k++)
+ {
+ MICRO_EXTRA_COL<Scalar, Packet, Index>(lhs_ptr, rhs_ptr, accZero, remaining_rows, remaining_cols);
+ }
+ for(; k < depth; k++)
+ {
+ Packet rhsV[1];
+ rhsV[0] = pset1<Packet>(rhs_ptr[0]);
+ pger<1, Scalar, Packet, Index, false>(&accZero, lhs_ptr, rhsV, remaining_rows);
+ lhs_ptr += remaining_rows;
+ rhs_ptr += remaining_cols;
+ }
+
+ accZero.packet[0] = vec_mul(pAlpha, accZero.packet[0]);
+ for(Index i = 0; i < remaining_rows; i++) {
+ res(row + i, col) += accZero.packet[0][i];
+ }
+}
+
+template<typename Scalar, typename Packet, typename Index, const Index accRows>
+EIGEN_ALWAYS_INLINE void MICRO_EXTRA_ROW(
+ const Scalar* &lhs_ptr,
+ const Scalar* &rhs_ptr,
+ PacketBlock<Packet,4> &accZero,
+ Index remaining_rows)
+{
+ Packet rhsV[4];
+ pbroadcast4<Packet>(rhs_ptr, rhsV[0], rhsV[1], rhsV[2], rhsV[3]);
+ pger<4, Scalar, Packet, false>(&accZero, lhs_ptr, rhsV);
+ lhs_ptr += remaining_rows;
+ rhs_ptr += accRows;
+}
+
+template<typename Scalar, typename Packet, typename DataMapper, typename Index, const Index accRows, const Index accCols>
+EIGEN_STRONG_INLINE void gemm_extra_row(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index row,
+ Index col,
+ Index rows,
+ Index cols,
+ Index remaining_rows,
+ const Packet& pAlpha,
+ const Packet& pMask)
+{
+ const Scalar* rhs_ptr = rhs_base;
+ const Scalar* lhs_ptr = lhs_base + row*strideA + remaining_rows*offsetA;
+ PacketBlock<Packet,4> accZero, acc;
+
+ bsetzero<Scalar, Packet>(accZero);
+
+ Index remaining_depth = (col + accRows < cols) ? depth : (depth & -accRows);
+ Index k = 0;
+ for(; k + PEEL <= remaining_depth; k+= PEEL)
+ {
+ EIGEN_POWER_PREFETCH(rhs_ptr);
+ EIGEN_POWER_PREFETCH(lhs_ptr);
+ for (int l = 0; l < PEEL; l++) {
+ MICRO_EXTRA_ROW<Scalar, Packet, Index, accRows>(lhs_ptr, rhs_ptr, accZero, remaining_rows);
+ }
+ }
+ for(; k < remaining_depth; k++)
+ {
+ MICRO_EXTRA_ROW<Scalar, Packet, Index, accRows>(lhs_ptr, rhs_ptr, accZero, remaining_rows);
+ }
+
+ if ((remaining_depth == depth) && (rows >= accCols))
+ {
+ for(Index j = 0; j < 4; j++) {
+ acc.packet[j] = res.template loadPacket<Packet>(row, col + j);
+ }
+ bscale<Packet>(acc, accZero, pAlpha, pMask);
+ res.template storePacketBlock<Packet,4>(row, col, acc);
+ } else {
+ for(; k < depth; k++)
+ {
+ Packet rhsV[4];
+ pbroadcast4<Packet>(rhs_ptr, rhsV[0], rhsV[1], rhsV[2], rhsV[3]);
+ pger<4, Scalar, Packet, Index, false>(&accZero, lhs_ptr, rhsV, remaining_rows);
+ lhs_ptr += remaining_rows;
+ rhs_ptr += accRows;
+ }
+
+ for(Index j = 0; j < 4; j++) {
+ accZero.packet[j] = vec_mul(pAlpha, accZero.packet[j]);
+ }
+ for(Index j = 0; j < 4; j++) {
+ for(Index i = 0; i < remaining_rows; i++) {
+ res(row + i, col + j) += accZero.packet[j][i];
+ }
+ }
+ }
+}
+
+#define MICRO_UNROLL(func) \
+ func(0) func(1) func(2) func(3) func(4) func(5) func(6) func(7)
+
+#define MICRO_UNROLL_WORK(func, func2, peel) \
+ MICRO_UNROLL(func2); \
+ func(0,peel) func(1,peel) func(2,peel) func(3,peel) \
+ func(4,peel) func(5,peel) func(6,peel) func(7,peel)
+
+#define MICRO_LOAD_ONE(iter) \
+ if (unroll_factor > iter) { \
+ lhsV##iter = ploadLhs<Scalar, Packet>(lhs_ptr##iter); \
+ lhs_ptr##iter += accCols; \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhsV##iter); \
+ }
+
+#define MICRO_WORK_ONE(iter, peel) \
+ if (unroll_factor > iter) { \
+ pger_common<Packet, false>(&accZero##iter, lhsV##iter, rhsV##peel); \
+ }
+
+#define MICRO_TYPE_PEEL4(func, func2, peel) \
+ if (PEEL > peel) { \
+ Packet lhsV0, lhsV1, lhsV2, lhsV3, lhsV4, lhsV5, lhsV6, lhsV7; \
+ pbroadcast4<Packet>(rhs_ptr + (accRows * peel), rhsV##peel[0], rhsV##peel[1], rhsV##peel[2], rhsV##peel[3]); \
+ MICRO_UNROLL_WORK(func, func2, peel) \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(rhsV##peel); \
+ }
+
+#define MICRO_TYPE_PEEL1(func, func2, peel) \
+ if (PEEL > peel) { \
+ Packet lhsV0, lhsV1, lhsV2, lhsV3, lhsV4, lhsV5, lhsV6, lhsV7; \
+ rhsV##peel[0] = pset1<Packet>(rhs_ptr[remaining_cols * peel]); \
+ MICRO_UNROLL_WORK(func, func2, peel) \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(rhsV##peel); \
+ }
+
+#define MICRO_UNROLL_TYPE_PEEL(M, func, func1, func2) \
+ Packet rhsV0[M], rhsV1[M], rhsV2[M], rhsV3[M], rhsV4[M], rhsV5[M], rhsV6[M], rhsV7[M], rhsV8[M], rhsV9[M]; \
+ func(func1,func2,0); func(func1,func2,1); \
+ func(func1,func2,2); func(func1,func2,3); \
+ func(func1,func2,4); func(func1,func2,5); \
+ func(func1,func2,6); func(func1,func2,7); \
+ func(func1,func2,8); func(func1,func2,9);
+
+#define MICRO_UNROLL_TYPE_ONE(M, func, func1, func2) \
+ Packet rhsV0[M]; \
+ func(func1,func2,0);
+
+#define MICRO_ONE_PEEL4 \
+ MICRO_UNROLL_TYPE_PEEL(4, MICRO_TYPE_PEEL4, MICRO_WORK_ONE, MICRO_LOAD_ONE); \
+ rhs_ptr += (accRows * PEEL);
+
+#define MICRO_ONE4 \
+ MICRO_UNROLL_TYPE_ONE(4, MICRO_TYPE_PEEL4, MICRO_WORK_ONE, MICRO_LOAD_ONE); \
+ rhs_ptr += accRows;
+
+#define MICRO_ONE_PEEL1 \
+ MICRO_UNROLL_TYPE_PEEL(1, MICRO_TYPE_PEEL1, MICRO_WORK_ONE, MICRO_LOAD_ONE); \
+ rhs_ptr += (remaining_cols * PEEL);
+
+#define MICRO_ONE1 \
+ MICRO_UNROLL_TYPE_ONE(1, MICRO_TYPE_PEEL1, MICRO_WORK_ONE, MICRO_LOAD_ONE); \
+ rhs_ptr += remaining_cols;
+
+#define MICRO_DST_PTR_ONE(iter) \
+ if (unroll_factor > iter) { \
+ bsetzero<Scalar, Packet>(accZero##iter); \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(accZero##iter); \
+ }
+
+#define MICRO_DST_PTR MICRO_UNROLL(MICRO_DST_PTR_ONE)
+
+#define MICRO_SRC_PTR_ONE(iter) \
+ if (unroll_factor > iter) { \
+ lhs_ptr##iter = lhs_base + ( (row/accCols) + iter )*strideA*accCols + accCols*offsetA; \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhs_ptr##iter); \
+ }
+
+#define MICRO_SRC_PTR MICRO_UNROLL(MICRO_SRC_PTR_ONE)
+
+#define MICRO_PREFETCH_ONE(iter) \
+ if (unroll_factor > iter) { \
+ EIGEN_POWER_PREFETCH(lhs_ptr##iter); \
+ }
+
+#define MICRO_PREFETCH MICRO_UNROLL(MICRO_PREFETCH_ONE)
+
+#define MICRO_STORE_ONE(iter) \
+ if (unroll_factor > iter) { \
+ acc.packet[0] = res.template loadPacket<Packet>(row + iter*accCols, col + 0); \
+ acc.packet[1] = res.template loadPacket<Packet>(row + iter*accCols, col + 1); \
+ acc.packet[2] = res.template loadPacket<Packet>(row + iter*accCols, col + 2); \
+ acc.packet[3] = res.template loadPacket<Packet>(row + iter*accCols, col + 3); \
+ bscale<Packet>(acc, accZero##iter, pAlpha); \
+ res.template storePacketBlock<Packet,4>(row + iter*accCols, col, acc); \
+ }
+
+#define MICRO_STORE MICRO_UNROLL(MICRO_STORE_ONE)
+
+#define MICRO_COL_STORE_ONE(iter) \
+ if (unroll_factor > iter) { \
+ acc.packet[0] = res.template loadPacket<Packet>(row + iter*accCols, col + 0); \
+ bscale<Packet>(acc, accZero##iter, pAlpha); \
+ res.template storePacketBlock<Packet,1>(row + iter*accCols, col, acc); \
+ }
+
+#define MICRO_COL_STORE MICRO_UNROLL(MICRO_COL_STORE_ONE)
+
+template<int unroll_factor, typename Scalar, typename Packet, typename DataMapper, typename Index, const Index accRows, const Index accCols>
+EIGEN_STRONG_INLINE void gemm_unrolled_iteration(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index& row,
+ Index col,
+ const Packet& pAlpha)
+{
+ const Scalar* rhs_ptr = rhs_base;
+ const Scalar* lhs_ptr0 = NULL, * lhs_ptr1 = NULL, * lhs_ptr2 = NULL, * lhs_ptr3 = NULL, * lhs_ptr4 = NULL, * lhs_ptr5 = NULL, * lhs_ptr6 = NULL, * lhs_ptr7 = NULL;
+ PacketBlock<Packet,4> accZero0, accZero1, accZero2, accZero3, accZero4, accZero5, accZero6, accZero7;
+ PacketBlock<Packet,4> acc;
+
+ MICRO_SRC_PTR
+ MICRO_DST_PTR
+
+ Index k = 0;
+ for(; k + PEEL <= depth; k+= PEEL)
+ {
+ EIGEN_POWER_PREFETCH(rhs_ptr);
+ MICRO_PREFETCH
+ MICRO_ONE_PEEL4
+ }
+ for(; k < depth; k++)
+ {
+ MICRO_ONE4
+ }
+ MICRO_STORE
+
+ row += unroll_factor*accCols;
+}
+
+template<int unroll_factor, typename Scalar, typename Packet, typename DataMapper, typename Index, const Index accCols>
+EIGEN_STRONG_INLINE void gemm_unrolled_col_iteration(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index& row,
+ Index col,
+ Index remaining_cols,
+ const Packet& pAlpha)
+{
+ const Scalar* rhs_ptr = rhs_base;
+ const Scalar* lhs_ptr0 = NULL, * lhs_ptr1 = NULL, * lhs_ptr2 = NULL, * lhs_ptr3 = NULL, * lhs_ptr4 = NULL, * lhs_ptr5 = NULL, * lhs_ptr6 = NULL, *lhs_ptr7 = NULL;
+ PacketBlock<Packet,1> accZero0, accZero1, accZero2, accZero3, accZero4, accZero5, accZero6, accZero7;
+ PacketBlock<Packet,1> acc;
+
+ MICRO_SRC_PTR
+ MICRO_DST_PTR
+
+ Index k = 0;
+ for(; k + PEEL <= depth; k+= PEEL)
+ {
+ EIGEN_POWER_PREFETCH(rhs_ptr);
+ MICRO_PREFETCH
+ MICRO_ONE_PEEL1
+ }
+ for(; k < depth; k++)
+ {
+ MICRO_ONE1
+ }
+ MICRO_COL_STORE
+
+ row += unroll_factor*accCols;
+}
+
+template<typename Scalar, typename Packet, typename DataMapper, typename Index, const Index accCols>
+EIGEN_STRONG_INLINE void gemm_unrolled_col(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index& row,
+ Index rows,
+ Index col,
+ Index remaining_cols,
+ const Packet& pAlpha)
+{
+#define MAX_UNROLL 6
+ while(row + MAX_UNROLL*accCols <= rows) {
+ gemm_unrolled_col_iteration<MAX_UNROLL, Scalar, Packet, DataMapper, Index, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, remaining_cols, pAlpha);
+ }
+ switch( (rows-row)/accCols ) {
+#if MAX_UNROLL > 7
+ case 7:
+ gemm_unrolled_col_iteration<7, Scalar, Packet, DataMapper, Index, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, remaining_cols, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 6
+ case 6:
+ gemm_unrolled_col_iteration<6, Scalar, Packet, DataMapper, Index, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, remaining_cols, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 5
+ case 5:
+ gemm_unrolled_col_iteration<5, Scalar, Packet, DataMapper, Index, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, remaining_cols, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 4
+ case 4:
+ gemm_unrolled_col_iteration<4, Scalar, Packet, DataMapper, Index, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, remaining_cols, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 3
+ case 3:
+ gemm_unrolled_col_iteration<3, Scalar, Packet, DataMapper, Index, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, remaining_cols, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 2
+ case 2:
+ gemm_unrolled_col_iteration<2, Scalar, Packet, DataMapper, Index, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, remaining_cols, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 1
+ case 1:
+ gemm_unrolled_col_iteration<1, Scalar, Packet, DataMapper, Index, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, remaining_cols, pAlpha);
+ break;
+#endif
+ default:
+ break;
+ }
+#undef MAX_UNROLL
+}
+
+/****************
+ * GEMM kernels *
+ * **************/
+template<typename Scalar, typename Index, typename Packet, typename RhsPacket, typename DataMapper, const Index accRows, const Index accCols>
+EIGEN_STRONG_INLINE void gemm(const DataMapper& res, const Scalar* blockA, const Scalar* blockB, Index rows, Index depth, Index cols, Scalar alpha, Index strideA, Index strideB, Index offsetA, Index offsetB)
+{
+ const Index remaining_rows = rows % accCols;
+ const Index remaining_cols = cols % accRows;
+
+ if( strideA == -1 ) strideA = depth;
+ if( strideB == -1 ) strideB = depth;
+
+ const Packet pAlpha = pset1<Packet>(alpha);
+ const Packet pMask = bmask<Packet>((const int)(remaining_rows));
+
+ Index col = 0;
+ for(; col + accRows <= cols; col += accRows)
+ {
+ const Scalar* rhs_base = blockB + col*strideB + accRows*offsetB;
+ const Scalar* lhs_base = blockA;
+ Index row = 0;
+
+#define MAX_UNROLL 6
+ while(row + MAX_UNROLL*accCols <= rows) {
+ gemm_unrolled_iteration<MAX_UNROLL, Scalar, Packet, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ }
+ switch( (rows-row)/accCols ) {
+#if MAX_UNROLL > 7
+ case 7:
+ gemm_unrolled_iteration<7, Scalar, Packet, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 6
+ case 6:
+ gemm_unrolled_iteration<6, Scalar, Packet, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 5
+ case 5:
+ gemm_unrolled_iteration<5, Scalar, Packet, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 4
+ case 4:
+ gemm_unrolled_iteration<4, Scalar, Packet, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 3
+ case 3:
+ gemm_unrolled_iteration<3, Scalar, Packet, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 2
+ case 2:
+ gemm_unrolled_iteration<2, Scalar, Packet, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_UNROLL > 1
+ case 1:
+ gemm_unrolled_iteration<1, Scalar, Packet, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+ default:
+ break;
+ }
+#undef MAX_UNROLL
+
+ if(remaining_rows > 0)
+ {
+ gemm_extra_row<Scalar, Packet, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, rows, cols, remaining_rows, pAlpha, pMask);
+ }
+ }
+
+ if(remaining_cols > 0)
+ {
+ const Scalar* rhs_base = blockB + col*strideB + remaining_cols*offsetB;
+ const Scalar* lhs_base = blockA;
+
+ for(; col < cols; col++)
+ {
+ Index row = 0;
+
+ gemm_unrolled_col<Scalar, Packet, DataMapper, Index, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, rows, col, remaining_cols, pAlpha);
+
+ if (remaining_rows > 0)
+ {
+ gemm_extra_col<Scalar, Packet, DataMapper, Index, accRows>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, remaining_rows, remaining_cols, pAlpha);
+ }
+ rhs_base++;
+ }
+ }
+}
+
+#define accColsC (accCols / 2)
+#define advanceRows ((LhsIsReal) ? 1 : 2)
+#define advanceCols ((RhsIsReal) ? 1 : 2)
+
+// PEEL_COMPLEX loop factor.
+#define PEEL_COMPLEX 3
+
+template<typename Scalar, typename Packet, typename Index, const Index accRows, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_ALWAYS_INLINE void MICRO_COMPLEX_EXTRA_COL(
+ const Scalar* &lhs_ptr_real, const Scalar* &lhs_ptr_imag,
+ const Scalar* &rhs_ptr_real, const Scalar* &rhs_ptr_imag,
+ PacketBlock<Packet,1> &accReal, PacketBlock<Packet,1> &accImag,
+ Index remaining_rows,
+ Index remaining_cols)
+{
+ Packet rhsV[1], rhsVi[1];
+ rhsV[0] = pset1<Packet>(rhs_ptr_real[0]);
+ if(!RhsIsReal) rhsVi[0] = pset1<Packet>(rhs_ptr_imag[0]);
+ pgerc<1, Scalar, Packet, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(&accReal, &accImag, lhs_ptr_real, lhs_ptr_imag, rhsV, rhsVi);
+ lhs_ptr_real += remaining_rows;
+ if(!LhsIsReal) lhs_ptr_imag += remaining_rows;
+ else EIGEN_UNUSED_VARIABLE(lhs_ptr_imag);
+ rhs_ptr_real += remaining_cols;
+ if(!RhsIsReal) rhs_ptr_imag += remaining_cols;
+ else EIGEN_UNUSED_VARIABLE(rhs_ptr_imag);
+}
+
+template<typename Scalar, typename Packet, typename Packetc, typename DataMapper, typename Index, const Index accRows, const Index accCols, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_STRONG_INLINE void gemm_complex_extra_col(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index strideB,
+ Index row,
+ Index col,
+ Index remaining_rows,
+ Index remaining_cols,
+ const Packet& pAlphaReal,
+ const Packet& pAlphaImag)
+{
+ const Scalar* rhs_ptr_real = rhs_base;
+ const Scalar* rhs_ptr_imag;
+ if(!RhsIsReal) rhs_ptr_imag = rhs_base + remaining_cols*strideB;
+ else EIGEN_UNUSED_VARIABLE(rhs_ptr_imag);
+ const Scalar* lhs_ptr_real = lhs_base + advanceRows*row*strideA + remaining_rows*offsetA;
+ const Scalar* lhs_ptr_imag;
+ if(!LhsIsReal) lhs_ptr_imag = lhs_ptr_real + remaining_rows*strideA;
+ else EIGEN_UNUSED_VARIABLE(lhs_ptr_imag);
+ PacketBlock<Packet,1> accReal, accImag;
+ PacketBlock<Packet,1> taccReal, taccImag;
+ PacketBlock<Packetc,1> acc0, acc1;
+
+ bsetzero<Scalar, Packet>(accReal);
+ bsetzero<Scalar, Packet>(accImag);
+
+ Index remaining_depth = (depth & -accRows);
+ Index k = 0;
+ for(; k + PEEL_COMPLEX <= remaining_depth; k+= PEEL_COMPLEX)
+ {
+ EIGEN_POWER_PREFETCH(rhs_ptr_real);
+ if(!RhsIsReal) {
+ EIGEN_POWER_PREFETCH(rhs_ptr_imag);
+ }
+ EIGEN_POWER_PREFETCH(lhs_ptr_real);
+ if(!LhsIsReal) {
+ EIGEN_POWER_PREFETCH(lhs_ptr_imag);
+ }
+ for (int l = 0; l < PEEL_COMPLEX; l++) {
+ MICRO_COMPLEX_EXTRA_COL<Scalar, Packet, Index, accRows, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(lhs_ptr_real, lhs_ptr_imag, rhs_ptr_real, rhs_ptr_imag, accReal, accImag, remaining_rows, remaining_cols);
+ }
+ }
+ for(; k < remaining_depth; k++)
+ {
+ MICRO_COMPLEX_EXTRA_COL<Scalar, Packet, Index, accRows, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(lhs_ptr_real, lhs_ptr_imag, rhs_ptr_real, rhs_ptr_imag, accReal, accImag, remaining_rows, remaining_cols);
+ }
+
+ for(; k < depth; k++)
+ {
+ Packet rhsV[1], rhsVi[1];
+ rhsV[0] = pset1<Packet>(rhs_ptr_real[0]);
+ if(!RhsIsReal) rhsVi[0] = pset1<Packet>(rhs_ptr_imag[0]);
+ pgerc<1, Scalar, Packet, Index, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(&accReal, &accImag, lhs_ptr_real, lhs_ptr_imag, rhsV, rhsVi, remaining_rows);
+ lhs_ptr_real += remaining_rows;
+ if(!LhsIsReal) lhs_ptr_imag += remaining_rows;
+ rhs_ptr_real += remaining_cols;
+ if(!RhsIsReal) rhs_ptr_imag += remaining_cols;
+ }
+
+ bscalec<Packet,1>(accReal, accImag, pAlphaReal, pAlphaImag, taccReal, taccImag);
+ bcouple_common<Packet, Packetc>(taccReal, taccImag, acc0, acc1);
+
+ if ((sizeof(Scalar) == sizeof(float)) && (remaining_rows == 1))
+ {
+ res(row + 0, col + 0) += pfirst<Packetc>(acc0.packet[0]);
+ } else {
+ acc0.packet[0] += res.template loadPacket<Packetc>(row + 0, col + 0);
+ res.template storePacketBlock<Packetc,1>(row + 0, col + 0, acc0);
+ if(remaining_rows > accColsC) {
+ res(row + accColsC, col + 0) += pfirst<Packetc>(acc1.packet[0]);
+ }
+ }
+}
+
+template<typename Scalar, typename Packet, typename Index, const Index accRows, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_ALWAYS_INLINE void MICRO_COMPLEX_EXTRA_ROW(
+ const Scalar* &lhs_ptr_real, const Scalar* &lhs_ptr_imag,
+ const Scalar* &rhs_ptr_real, const Scalar* &rhs_ptr_imag,
+ PacketBlock<Packet,4> &accReal, PacketBlock<Packet,4> &accImag,
+ Index remaining_rows)
+{
+ Packet rhsV[4], rhsVi[4];
+ pbroadcast4_old<Packet>(rhs_ptr_real, rhsV[0], rhsV[1], rhsV[2], rhsV[3]);
+ if(!RhsIsReal) pbroadcast4_old<Packet>(rhs_ptr_imag, rhsVi[0], rhsVi[1], rhsVi[2], rhsVi[3]);
+ pgerc<4, Scalar, Packet, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(&accReal, &accImag, lhs_ptr_real, lhs_ptr_imag, rhsV, rhsVi);
+ lhs_ptr_real += remaining_rows;
+ if(!LhsIsReal) lhs_ptr_imag += remaining_rows;
+ else EIGEN_UNUSED_VARIABLE(lhs_ptr_imag);
+ rhs_ptr_real += accRows;
+ if(!RhsIsReal) rhs_ptr_imag += accRows;
+ else EIGEN_UNUSED_VARIABLE(rhs_ptr_imag);
+}
+
+template<typename Scalar, typename Packet, typename Packetc, typename DataMapper, typename Index, const Index accRows, const Index accCols, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_STRONG_INLINE void gemm_complex_extra_row(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index strideB,
+ Index row,
+ Index col,
+ Index rows,
+ Index cols,
+ Index remaining_rows,
+ const Packet& pAlphaReal,
+ const Packet& pAlphaImag,
+ const Packet& pMask)
+{
+ const Scalar* rhs_ptr_real = rhs_base;
+ const Scalar* rhs_ptr_imag;
+ if(!RhsIsReal) rhs_ptr_imag = rhs_base + accRows*strideB;
+ else EIGEN_UNUSED_VARIABLE(rhs_ptr_imag);
+ const Scalar* lhs_ptr_real = lhs_base + advanceRows*row*strideA + remaining_rows*offsetA;
+ const Scalar* lhs_ptr_imag;
+ if(!LhsIsReal) lhs_ptr_imag = lhs_ptr_real + remaining_rows*strideA;
+ else EIGEN_UNUSED_VARIABLE(lhs_ptr_imag);
+ PacketBlock<Packet,4> accReal, accImag;
+ PacketBlock<Packet,4> taccReal, taccImag;
+ PacketBlock<Packetc,4> acc0, acc1;
+ PacketBlock<Packetc,8> tRes;
+
+ bsetzero<Scalar, Packet>(accReal);
+ bsetzero<Scalar, Packet>(accImag);
+
+ Index remaining_depth = (col + accRows < cols) ? depth : (depth & -accRows);
+ Index k = 0;
+ for(; k + PEEL_COMPLEX <= remaining_depth; k+= PEEL_COMPLEX)
+ {
+ EIGEN_POWER_PREFETCH(rhs_ptr_real);
+ if(!RhsIsReal) {
+ EIGEN_POWER_PREFETCH(rhs_ptr_imag);
+ }
+ EIGEN_POWER_PREFETCH(lhs_ptr_real);
+ if(!LhsIsReal) {
+ EIGEN_POWER_PREFETCH(lhs_ptr_imag);
+ }
+ for (int l = 0; l < PEEL_COMPLEX; l++) {
+ MICRO_COMPLEX_EXTRA_ROW<Scalar, Packet, Index, accRows, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(lhs_ptr_real, lhs_ptr_imag, rhs_ptr_real, rhs_ptr_imag, accReal, accImag, remaining_rows);
+ }
+ }
+ for(; k < remaining_depth; k++)
+ {
+ MICRO_COMPLEX_EXTRA_ROW<Scalar, Packet, Index, accRows, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(lhs_ptr_real, lhs_ptr_imag, rhs_ptr_real, rhs_ptr_imag, accReal, accImag, remaining_rows);
+ }
+
+ if ((remaining_depth == depth) && (rows >= accCols))
+ {
+ bload<DataMapper, Packetc, Index, accColsC, 0, ColMajor>(tRes, res, row, col);
+ bscalec<Packet>(accReal, accImag, pAlphaReal, pAlphaImag, taccReal, taccImag, pMask);
+ bcouple<Packet, Packetc>(taccReal, taccImag, tRes, acc0, acc1);
+ res.template storePacketBlock<Packetc,4>(row + 0, col, acc0);
+ res.template storePacketBlock<Packetc,4>(row + accColsC, col, acc1);
+ } else {
+ for(; k < depth; k++)
+ {
+ Packet rhsV[4], rhsVi[4];
+ pbroadcast4_old<Packet>(rhs_ptr_real, rhsV[0], rhsV[1], rhsV[2], rhsV[3]);
+ if(!RhsIsReal) pbroadcast4_old<Packet>(rhs_ptr_imag, rhsVi[0], rhsVi[1], rhsVi[2], rhsVi[3]);
+ pgerc<4, Scalar, Packet, Index, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(&accReal, &accImag, lhs_ptr_real, lhs_ptr_imag, rhsV, rhsVi, remaining_rows);
+ lhs_ptr_real += remaining_rows;
+ if(!LhsIsReal) lhs_ptr_imag += remaining_rows;
+ rhs_ptr_real += accRows;
+ if(!RhsIsReal) rhs_ptr_imag += accRows;
+ }
+
+ bscalec<Packet,4>(accReal, accImag, pAlphaReal, pAlphaImag, taccReal, taccImag);
+ bcouple_common<Packet, Packetc>(taccReal, taccImag, acc0, acc1);
+
+ if ((sizeof(Scalar) == sizeof(float)) && (remaining_rows == 1))
+ {
+ for(Index j = 0; j < 4; j++) {
+ res(row + 0, col + j) += pfirst<Packetc>(acc0.packet[j]);
+ }
+ } else {
+ for(Index j = 0; j < 4; j++) {
+ PacketBlock<Packetc,1> acc2;
+ acc2.packet[0] = res.template loadPacket<Packetc>(row + 0, col + j) + acc0.packet[j];
+ res.template storePacketBlock<Packetc,1>(row + 0, col + j, acc2);
+ if(remaining_rows > accColsC) {
+ res(row + accColsC, col + j) += pfirst<Packetc>(acc1.packet[j]);
+ }
+ }
+ }
+ }
+}
+
+#define MICRO_COMPLEX_UNROLL(func) \
+ func(0) func(1) func(2) func(3) func(4)
+
+#define MICRO_COMPLEX_UNROLL_WORK(func, func2, peel) \
+ MICRO_COMPLEX_UNROLL(func2); \
+ func(0,peel) func(1,peel) func(2,peel) func(3,peel) func(4,peel)
+
+#define MICRO_COMPLEX_LOAD_ONE(iter) \
+ if (unroll_factor > iter) { \
+ lhsV##iter = ploadLhs<Scalar, Packet>(lhs_ptr_real##iter); \
+ lhs_ptr_real##iter += accCols; \
+ if(!LhsIsReal) { \
+ lhsVi##iter = ploadLhs<Scalar, Packet>(lhs_ptr_imag##iter); \
+ lhs_ptr_imag##iter += accCols; \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhsVi##iter); \
+ } \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhsV##iter); \
+ EIGEN_UNUSED_VARIABLE(lhsVi##iter); \
+ }
+
+#define MICRO_COMPLEX_WORK_ONE4(iter, peel) \
+ if (unroll_factor > iter) { \
+ pgerc_common<4, Packet, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(&accReal##iter, &accImag##iter, lhsV##iter, lhsVi##iter, rhsV##peel, rhsVi##peel); \
+ }
+
+#define MICRO_COMPLEX_WORK_ONE1(iter, peel) \
+ if (unroll_factor > iter) { \
+ pgerc_common<1, Packet, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(&accReal##iter, &accImag##iter, lhsV##iter, lhsVi##iter, rhsV##peel, rhsVi##peel); \
+ }
+
+#define MICRO_COMPLEX_TYPE_PEEL4(func, func2, peel) \
+ if (PEEL_COMPLEX > peel) { \
+ Packet lhsV0, lhsV1, lhsV2, lhsV3, lhsV4; \
+ Packet lhsVi0, lhsVi1, lhsVi2, lhsVi3, lhsVi4; \
+ pbroadcast4_old<Packet>(rhs_ptr_real + (accRows * peel), rhsV##peel[0], rhsV##peel[1], rhsV##peel[2], rhsV##peel[3]); \
+ if(!RhsIsReal) { \
+ pbroadcast4_old<Packet>(rhs_ptr_imag + (accRows * peel), rhsVi##peel[0], rhsVi##peel[1], rhsVi##peel[2], rhsVi##peel[3]); \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(rhsVi##peel); \
+ } \
+ MICRO_COMPLEX_UNROLL_WORK(func, func2, peel) \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(rhsV##peel); \
+ EIGEN_UNUSED_VARIABLE(rhsVi##peel); \
+ }
+
+#define MICRO_COMPLEX_TYPE_PEEL1(func, func2, peel) \
+ if (PEEL_COMPLEX > peel) { \
+ Packet lhsV0, lhsV1, lhsV2, lhsV3, lhsV4; \
+ Packet lhsVi0, lhsVi1, lhsVi2, lhsVi3, lhsVi4; \
+ rhsV##peel[0] = pset1<Packet>(rhs_ptr_real[remaining_cols * peel]); \
+ if(!RhsIsReal) { \
+ rhsVi##peel[0] = pset1<Packet>(rhs_ptr_imag[remaining_cols * peel]); \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(rhsVi##peel); \
+ } \
+ MICRO_COMPLEX_UNROLL_WORK(func, func2, peel) \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(rhsV##peel); \
+ EIGEN_UNUSED_VARIABLE(rhsVi##peel); \
+ }
+
+#define MICRO_COMPLEX_UNROLL_TYPE_PEEL(M, func, func1, func2) \
+ Packet rhsV0[M], rhsV1[M], rhsV2[M], rhsV3[M], rhsV4[M], rhsV5[M], rhsV6[M], rhsV7[M], rhsV8[M], rhsV9[M]; \
+ Packet rhsVi0[M], rhsVi1[M], rhsVi2[M], rhsVi3[M], rhsVi4[M], rhsVi5[M], rhsVi6[M], rhsVi7[M], rhsVi8[M], rhsVi9[M]; \
+ func(func1,func2,0); func(func1,func2,1); \
+ func(func1,func2,2); func(func1,func2,3); \
+ func(func1,func2,4); func(func1,func2,5); \
+ func(func1,func2,6); func(func1,func2,7); \
+ func(func1,func2,8); func(func1,func2,9);
+
+#define MICRO_COMPLEX_UNROLL_TYPE_ONE(M, func, func1, func2) \
+ Packet rhsV0[M], rhsVi0[M];\
+ func(func1,func2,0);
+
+#define MICRO_COMPLEX_ONE_PEEL4 \
+ MICRO_COMPLEX_UNROLL_TYPE_PEEL(4, MICRO_COMPLEX_TYPE_PEEL4, MICRO_COMPLEX_WORK_ONE4, MICRO_COMPLEX_LOAD_ONE); \
+ rhs_ptr_real += (accRows * PEEL_COMPLEX); \
+ if(!RhsIsReal) rhs_ptr_imag += (accRows * PEEL_COMPLEX);
+
+#define MICRO_COMPLEX_ONE4 \
+ MICRO_COMPLEX_UNROLL_TYPE_ONE(4, MICRO_COMPLEX_TYPE_PEEL4, MICRO_COMPLEX_WORK_ONE4, MICRO_COMPLEX_LOAD_ONE); \
+ rhs_ptr_real += accRows; \
+ if(!RhsIsReal) rhs_ptr_imag += accRows;
+
+#define MICRO_COMPLEX_ONE_PEEL1 \
+ MICRO_COMPLEX_UNROLL_TYPE_PEEL(1, MICRO_COMPLEX_TYPE_PEEL1, MICRO_COMPLEX_WORK_ONE1, MICRO_COMPLEX_LOAD_ONE); \
+ rhs_ptr_real += (remaining_cols * PEEL_COMPLEX); \
+ if(!RhsIsReal) rhs_ptr_imag += (remaining_cols * PEEL_COMPLEX);
+
+#define MICRO_COMPLEX_ONE1 \
+ MICRO_COMPLEX_UNROLL_TYPE_ONE(1, MICRO_COMPLEX_TYPE_PEEL1, MICRO_COMPLEX_WORK_ONE1, MICRO_COMPLEX_LOAD_ONE); \
+ rhs_ptr_real += remaining_cols; \
+ if(!RhsIsReal) rhs_ptr_imag += remaining_cols;
+
+#define MICRO_COMPLEX_DST_PTR_ONE(iter) \
+ if (unroll_factor > iter) { \
+ bsetzero<Scalar, Packet>(accReal##iter); \
+ bsetzero<Scalar, Packet>(accImag##iter); \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(accReal##iter); \
+ EIGEN_UNUSED_VARIABLE(accImag##iter); \
+ }
+
+#define MICRO_COMPLEX_DST_PTR MICRO_COMPLEX_UNROLL(MICRO_COMPLEX_DST_PTR_ONE)
+
+#define MICRO_COMPLEX_SRC_PTR_ONE(iter) \
+ if (unroll_factor > iter) { \
+ lhs_ptr_real##iter = lhs_base + ( ((advanceRows*row)/accCols) + iter*advanceRows )*strideA*accCols + accCols*offsetA; \
+ if(!LhsIsReal) { \
+ lhs_ptr_imag##iter = lhs_ptr_real##iter + accCols*strideA; \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhs_ptr_imag##iter); \
+ } \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhs_ptr_real##iter); \
+ EIGEN_UNUSED_VARIABLE(lhs_ptr_imag##iter); \
+ }
+
+#define MICRO_COMPLEX_SRC_PTR MICRO_COMPLEX_UNROLL(MICRO_COMPLEX_SRC_PTR_ONE)
+
+#define MICRO_COMPLEX_PREFETCH_ONE(iter) \
+ if (unroll_factor > iter) { \
+ EIGEN_POWER_PREFETCH(lhs_ptr_real##iter); \
+ if(!LhsIsReal) { \
+ EIGEN_POWER_PREFETCH(lhs_ptr_imag##iter); \
+ } \
+ }
+
+#define MICRO_COMPLEX_PREFETCH MICRO_COMPLEX_UNROLL(MICRO_COMPLEX_PREFETCH_ONE)
+
+#define MICRO_COMPLEX_STORE_ONE(iter) \
+ if (unroll_factor > iter) { \
+ bload<DataMapper, Packetc, Index, accColsC, 0, ColMajor>(tRes, res, row + iter*accCols, col); \
+ bscalec<Packet,4>(accReal##iter, accImag##iter, pAlphaReal, pAlphaImag, taccReal, taccImag); \
+ bcouple<Packet, Packetc>(taccReal, taccImag, tRes, acc0, acc1); \
+ res.template storePacketBlock<Packetc,4>(row + iter*accCols + 0, col, acc0); \
+ res.template storePacketBlock<Packetc,4>(row + iter*accCols + accColsC, col, acc1); \
+ }
+
+#define MICRO_COMPLEX_STORE MICRO_COMPLEX_UNROLL(MICRO_COMPLEX_STORE_ONE)
+
+#define MICRO_COMPLEX_COL_STORE_ONE(iter) \
+ if (unroll_factor > iter) { \
+ bload<DataMapper, Packetc, Index, accColsC, 0, ColMajor>(tRes, res, row + iter*accCols, col); \
+ bscalec<Packet,1>(accReal##iter, accImag##iter, pAlphaReal, pAlphaImag, taccReal, taccImag); \
+ bcouple<Packet, Packetc>(taccReal, taccImag, tRes, acc0, acc1); \
+ res.template storePacketBlock<Packetc,1>(row + iter*accCols + 0, col, acc0); \
+ res.template storePacketBlock<Packetc,1>(row + iter*accCols + accColsC, col, acc1); \
+ }
+
+#define MICRO_COMPLEX_COL_STORE MICRO_COMPLEX_UNROLL(MICRO_COMPLEX_COL_STORE_ONE)
+
+template<int unroll_factor, typename Scalar, typename Packet, typename Packetc, typename DataMapper, typename Index, const Index accRows, const Index accCols, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_STRONG_INLINE void gemm_complex_unrolled_iteration(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index strideB,
+ Index& row,
+ Index col,
+ const Packet& pAlphaReal,
+ const Packet& pAlphaImag)
+{
+ const Scalar* rhs_ptr_real = rhs_base;
+ const Scalar* rhs_ptr_imag;
+ if(!RhsIsReal) {
+ rhs_ptr_imag = rhs_base + accRows*strideB;
+ } else {
+ EIGEN_UNUSED_VARIABLE(rhs_ptr_imag);
+ }
+ const Scalar* lhs_ptr_real0 = NULL, * lhs_ptr_imag0 = NULL, * lhs_ptr_real1 = NULL, * lhs_ptr_imag1 = NULL;
+ const Scalar* lhs_ptr_real2 = NULL, * lhs_ptr_imag2 = NULL, * lhs_ptr_real3 = NULL, * lhs_ptr_imag3 = NULL;
+ const Scalar* lhs_ptr_real4 = NULL, * lhs_ptr_imag4 = NULL;
+ PacketBlock<Packet,4> accReal0, accImag0, accReal1, accImag1;
+ PacketBlock<Packet,4> accReal2, accImag2, accReal3, accImag3;
+ PacketBlock<Packet,4> accReal4, accImag4;
+ PacketBlock<Packet,4> taccReal, taccImag;
+ PacketBlock<Packetc,4> acc0, acc1;
+ PacketBlock<Packetc,8> tRes;
+
+ MICRO_COMPLEX_SRC_PTR
+ MICRO_COMPLEX_DST_PTR
+
+ Index k = 0;
+ for(; k + PEEL_COMPLEX <= depth; k+= PEEL_COMPLEX)
+ {
+ EIGEN_POWER_PREFETCH(rhs_ptr_real);
+ if(!RhsIsReal) {
+ EIGEN_POWER_PREFETCH(rhs_ptr_imag);
+ }
+ MICRO_COMPLEX_PREFETCH
+ MICRO_COMPLEX_ONE_PEEL4
+ }
+ for(; k < depth; k++)
+ {
+ MICRO_COMPLEX_ONE4
+ }
+ MICRO_COMPLEX_STORE
+
+ row += unroll_factor*accCols;
+}
+
+template<int unroll_factor, typename Scalar, typename Packet, typename Packetc, typename DataMapper, typename Index, const Index accCols, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_STRONG_INLINE void gemm_complex_unrolled_col_iteration(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index strideB,
+ Index& row,
+ Index col,
+ Index remaining_cols,
+ const Packet& pAlphaReal,
+ const Packet& pAlphaImag)
+{
+ const Scalar* rhs_ptr_real = rhs_base;
+ const Scalar* rhs_ptr_imag;
+ if(!RhsIsReal) {
+ rhs_ptr_imag = rhs_base + remaining_cols*strideB;
+ } else {
+ EIGEN_UNUSED_VARIABLE(rhs_ptr_imag);
+ }
+ const Scalar* lhs_ptr_real0 = NULL, * lhs_ptr_imag0 = NULL, * lhs_ptr_real1 = NULL, * lhs_ptr_imag1 = NULL;
+ const Scalar* lhs_ptr_real2 = NULL, * lhs_ptr_imag2 = NULL, * lhs_ptr_real3 = NULL, * lhs_ptr_imag3 = NULL;
+ const Scalar* lhs_ptr_real4 = NULL, * lhs_ptr_imag4 = NULL;
+ PacketBlock<Packet,1> accReal0, accImag0, accReal1, accImag1;
+ PacketBlock<Packet,1> accReal2, accImag2, accReal3, accImag3;
+ PacketBlock<Packet,1> accReal4, accImag4;
+ PacketBlock<Packet,1> taccReal, taccImag;
+ PacketBlock<Packetc,1> acc0, acc1;
+ PacketBlock<Packetc,2> tRes;
+
+ MICRO_COMPLEX_SRC_PTR
+ MICRO_COMPLEX_DST_PTR
+
+ Index k = 0;
+ for(; k + PEEL_COMPLEX <= depth; k+= PEEL_COMPLEX)
+ {
+ EIGEN_POWER_PREFETCH(rhs_ptr_real);
+ if(!RhsIsReal) {
+ EIGEN_POWER_PREFETCH(rhs_ptr_imag);
+ }
+ MICRO_COMPLEX_PREFETCH
+ MICRO_COMPLEX_ONE_PEEL1
+ }
+ for(; k < depth; k++)
+ {
+ MICRO_COMPLEX_ONE1
+ }
+ MICRO_COMPLEX_COL_STORE
+
+ row += unroll_factor*accCols;
+}
+
+template<typename Scalar, typename Packet, typename Packetc, typename DataMapper, typename Index, const Index accCols, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_STRONG_INLINE void gemm_complex_unrolled_col(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index strideB,
+ Index& row,
+ Index rows,
+ Index col,
+ Index remaining_cols,
+ const Packet& pAlphaReal,
+ const Packet& pAlphaImag)
+{
+#define MAX_COMPLEX_UNROLL 3
+ while(row + MAX_COMPLEX_UNROLL*accCols <= rows) {
+ gemm_complex_unrolled_col_iteration<MAX_COMPLEX_UNROLL, Scalar, Packet, Packetc, DataMapper, Index, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, remaining_cols, pAlphaReal, pAlphaImag);
+ }
+ switch( (rows-row)/accCols ) {
+#if MAX_COMPLEX_UNROLL > 4
+ case 4:
+ gemm_complex_unrolled_col_iteration<4, Scalar, Packet, Packetc, DataMapper, Index, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, remaining_cols, pAlphaReal, pAlphaImag);
+ break;
+#endif
+#if MAX_COMPLEX_UNROLL > 3
+ case 3:
+ gemm_complex_unrolled_col_iteration<3, Scalar, Packet, Packetc, DataMapper, Index, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, remaining_cols, pAlphaReal, pAlphaImag);
+ break;
+#endif
+#if MAX_COMPLEX_UNROLL > 2
+ case 2:
+ gemm_complex_unrolled_col_iteration<2, Scalar, Packet, Packetc, DataMapper, Index, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, remaining_cols, pAlphaReal, pAlphaImag);
+ break;
+#endif
+#if MAX_COMPLEX_UNROLL > 1
+ case 1:
+ gemm_complex_unrolled_col_iteration<1, Scalar, Packet, Packetc, DataMapper, Index, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, remaining_cols, pAlphaReal, pAlphaImag);
+ break;
+#endif
+ default:
+ break;
+ }
+#undef MAX_COMPLEX_UNROLL
+}
+
+template<typename LhsScalar, typename RhsScalar, typename Scalarc, typename Scalar, typename Index, typename Packet, typename Packetc, typename RhsPacket, typename DataMapper, const Index accRows, const Index accCols, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_STRONG_INLINE void gemm_complex(const DataMapper& res, const LhsScalar* blockAc, const RhsScalar* blockBc, Index rows, Index depth, Index cols, Scalarc alpha, Index strideA, Index strideB, Index offsetA, Index offsetB)
+{
+ const Index remaining_rows = rows % accCols;
+ const Index remaining_cols = cols % accRows;
+
+ if( strideA == -1 ) strideA = depth;
+ if( strideB == -1 ) strideB = depth;
+
+ const Packet pAlphaReal = pset1<Packet>(alpha.real());
+ const Packet pAlphaImag = pset1<Packet>(alpha.imag());
+ const Packet pMask = bmask<Packet>((const int)(remaining_rows));
+
+ const Scalar* blockA = (Scalar *) blockAc;
+ const Scalar* blockB = (Scalar *) blockBc;
+
+ Index col = 0;
+ for(; col + accRows <= cols; col += accRows)
+ {
+ const Scalar* rhs_base = blockB + advanceCols*col*strideB + accRows*offsetB;
+ const Scalar* lhs_base = blockA;
+ Index row = 0;
+
+#define MAX_COMPLEX_UNROLL 3
+ while(row + MAX_COMPLEX_UNROLL*accCols <= rows) {
+ gemm_complex_unrolled_iteration<MAX_COMPLEX_UNROLL, Scalar, Packet, Packetc, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, pAlphaReal, pAlphaImag);
+ }
+ switch( (rows-row)/accCols ) {
+#if MAX_COMPLEX_UNROLL > 4
+ case 4:
+ gemm_complex_unrolled_iteration<4, Scalar, Packet, Packetc, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, pAlphaReal, pAlphaImag);
+ break;
+#endif
+#if MAX_COMPLEX_UNROLL > 3
+ case 3:
+ gemm_complex_unrolled_iteration<3, Scalar, Packet, Packetc, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, pAlphaReal, pAlphaImag);
+ break;
+#endif
+#if MAX_COMPLEX_UNROLL > 2
+ case 2:
+ gemm_complex_unrolled_iteration<2, Scalar, Packet, Packetc, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, pAlphaReal, pAlphaImag);
+ break;
+#endif
+#if MAX_COMPLEX_UNROLL > 1
+ case 1:
+ gemm_complex_unrolled_iteration<1, Scalar, Packet, Packetc, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, pAlphaReal, pAlphaImag);
+ break;
+#endif
+ default:
+ break;
+ }
+#undef MAX_COMPLEX_UNROLL
+
+ if(remaining_rows > 0)
+ {
+ gemm_complex_extra_row<Scalar, Packet, Packetc, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, rows, cols, remaining_rows, pAlphaReal, pAlphaImag, pMask);
+ }
+ }
+
+ if(remaining_cols > 0)
+ {
+ const Scalar* rhs_base = blockB + advanceCols*col*strideB + remaining_cols*offsetB;
+ const Scalar* lhs_base = blockA;
+
+ for(; col < cols; col++)
+ {
+ Index row = 0;
+
+ gemm_complex_unrolled_col<Scalar, Packet, Packetc, DataMapper, Index, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, rows, col, remaining_cols, pAlphaReal, pAlphaImag);
+
+ if (remaining_rows > 0)
+ {
+ gemm_complex_extra_col<Scalar, Packet, Packetc, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, remaining_rows, remaining_cols, pAlphaReal, pAlphaImag);
+ }
+ rhs_base++;
+ }
+ }
+}
+
+#undef accColsC
+#undef advanceCols
+#undef advanceRows
+
+/************************************
+ * ppc64le template specializations *
+ * **********************************/
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+struct gemm_pack_lhs<double, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode>
+{
+ void operator()(double* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+void gemm_pack_lhs<double, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode>
+ ::operator()(double* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+{
+ dhs_pack<double, Index, DataMapper, Packet2d, ColMajor, PanelMode, true> pack;
+ pack(blockA, lhs, depth, rows, stride, offset);
+}
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+struct gemm_pack_lhs<double, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode>
+{
+ void operator()(double* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+void gemm_pack_lhs<double, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode>
+ ::operator()(double* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+{
+ dhs_pack<double, Index, DataMapper, Packet2d, RowMajor, PanelMode, true> pack;
+ pack(blockA, lhs, depth, rows, stride, offset);
+}
+
+#if EIGEN_ALTIVEC_USE_CUSTOM_PACK
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+struct gemm_pack_rhs<double, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode>
+{
+ void operator()(double* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+void gemm_pack_rhs<double, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode>
+ ::operator()(double* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset)
+{
+ dhs_pack<double, Index, DataMapper, Packet2d, ColMajor, PanelMode, false> pack;
+ pack(blockB, rhs, depth, cols, stride, offset);
+}
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+struct gemm_pack_rhs<double, Index, DataMapper, nr, RowMajor, Conjugate, PanelMode>
+{
+ void operator()(double* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+void gemm_pack_rhs<double, Index, DataMapper, nr, RowMajor, Conjugate, PanelMode>
+ ::operator()(double* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset)
+{
+ dhs_pack<double, Index, DataMapper, Packet2d, RowMajor, PanelMode, false> pack;
+ pack(blockB, rhs, depth, cols, stride, offset);
+}
+#endif
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+struct gemm_pack_lhs<float, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode>
+{
+ void operator()(float* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+void gemm_pack_lhs<float, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode>
+ ::operator()(float* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+{
+ dhs_pack<float, Index, DataMapper, Packet4f, RowMajor, PanelMode, true> pack;
+ pack(blockA, lhs, depth, rows, stride, offset);
+}
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+struct gemm_pack_lhs<float, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode>
+{
+ void operator()(float* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+void gemm_pack_lhs<float, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode>
+ ::operator()(float* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+{
+ dhs_pack<float, Index, DataMapper, Packet4f, ColMajor, PanelMode, true> pack;
+ pack(blockA, lhs, depth, rows, stride, offset);
+}
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+struct gemm_pack_lhs<std::complex<float>, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode>
+{
+ void operator()(std::complex<float>* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+void gemm_pack_lhs<std::complex<float>, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode>
+ ::operator()(std::complex<float>* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+{
+ dhs_cpack<float, Index, DataMapper, Packet4f, Packet2cf, RowMajor, Conjugate, PanelMode, true> pack;
+ pack(blockA, lhs, depth, rows, stride, offset);
+}
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+struct gemm_pack_lhs<std::complex<float>, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode>
+{
+ void operator()(std::complex<float>* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+void gemm_pack_lhs<std::complex<float>, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode>
+ ::operator()(std::complex<float>* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+{
+ dhs_cpack<float, Index, DataMapper, Packet4f, Packet2cf, ColMajor, Conjugate, PanelMode, true> pack;
+ pack(blockA, lhs, depth, rows, stride, offset);
+}
+
+#if EIGEN_ALTIVEC_USE_CUSTOM_PACK
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+struct gemm_pack_rhs<float, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode>
+{
+ void operator()(float* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+void gemm_pack_rhs<float, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode>
+ ::operator()(float* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset)
+{
+ dhs_pack<float, Index, DataMapper, Packet4f, ColMajor, PanelMode, false> pack;
+ pack(blockB, rhs, depth, cols, stride, offset);
+}
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+struct gemm_pack_rhs<float, Index, DataMapper, nr, RowMajor, Conjugate, PanelMode>
+{
+ void operator()(float* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+void gemm_pack_rhs<float, Index, DataMapper, nr, RowMajor, Conjugate, PanelMode>
+ ::operator()(float* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset)
+{
+ dhs_pack<float, Index, DataMapper, Packet4f, RowMajor, PanelMode, false> pack;
+ pack(blockB, rhs, depth, cols, stride, offset);
+}
+#endif
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+struct gemm_pack_rhs<std::complex<float>, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode>
+{
+ void operator()(std::complex<float>* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+void gemm_pack_rhs<std::complex<float>, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode>
+ ::operator()(std::complex<float>* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset)
+{
+ dhs_cpack<float, Index, DataMapper, Packet4f, Packet2cf, ColMajor, Conjugate, PanelMode, false> pack;
+ pack(blockB, rhs, depth, cols, stride, offset);
+}
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+struct gemm_pack_rhs<std::complex<float>, Index, DataMapper, nr, RowMajor, Conjugate, PanelMode>
+{
+ void operator()(std::complex<float>* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+void gemm_pack_rhs<std::complex<float>, Index, DataMapper, nr, RowMajor, Conjugate, PanelMode>
+ ::operator()(std::complex<float>* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset)
+{
+ dhs_cpack<float, Index, DataMapper, Packet4f, Packet2cf, RowMajor, Conjugate, PanelMode, false> pack;
+ pack(blockB, rhs, depth, cols, stride, offset);
+}
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+struct gemm_pack_lhs<std::complex<double>, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode>
+{
+ void operator()(std::complex<double>* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+void gemm_pack_lhs<std::complex<double>, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode>
+ ::operator()(std::complex<double>* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+{
+ dhs_cpack<double, Index, DataMapper, Packet2d, Packet1cd, RowMajor, Conjugate, PanelMode, true> pack;
+ pack(blockA, lhs, depth, rows, stride, offset);
+}
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+struct gemm_pack_lhs<std::complex<double>, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode>
+{
+ void operator()(std::complex<double>* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+void gemm_pack_lhs<std::complex<double>, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode>
+ ::operator()(std::complex<double>* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+{
+ dhs_cpack<double, Index, DataMapper, Packet2d, Packet1cd, ColMajor, Conjugate, PanelMode, true> pack;
+ pack(blockA, lhs, depth, rows, stride, offset);
+}
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+struct gemm_pack_rhs<std::complex<double>, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode>
+{
+ void operator()(std::complex<double>* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+void gemm_pack_rhs<std::complex<double>, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode>
+ ::operator()(std::complex<double>* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset)
+{
+ dhs_cpack<double, Index, DataMapper, Packet2d, Packet1cd, ColMajor, Conjugate, PanelMode, false> pack;
+ pack(blockB, rhs, depth, cols, stride, offset);
+}
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+struct gemm_pack_rhs<std::complex<double>, Index, DataMapper, nr, RowMajor, Conjugate, PanelMode>
+{
+ void operator()(std::complex<double>* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0);
+};
+
+template<typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+void gemm_pack_rhs<std::complex<double>, Index, DataMapper, nr, RowMajor, Conjugate, PanelMode>
+ ::operator()(std::complex<double>* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset)
+{
+ dhs_cpack<double, Index, DataMapper, Packet2d, Packet1cd, RowMajor, Conjugate, PanelMode, false> pack;
+ pack(blockB, rhs, depth, cols, stride, offset);
+}
+
+// ********* gebp specializations *********
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+struct gebp_kernel<float, float, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+{
+ typedef typename quad_traits<float>::vectortype Packet;
+ typedef typename quad_traits<float>::rhstype RhsPacket;
+
+ void operator()(const DataMapper& res, const float* blockA, const float* blockB,
+ Index rows, Index depth, Index cols, float alpha,
+ Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0);
+};
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+void gebp_kernel<float, float, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+ ::operator()(const DataMapper& res, const float* blockA, const float* blockB,
+ Index rows, Index depth, Index cols, float alpha,
+ Index strideA, Index strideB, Index offsetA, Index offsetB)
+ {
+ const Index accRows = quad_traits<float>::rows;
+ const Index accCols = quad_traits<float>::size;
+ void (*gemm_function)(const DataMapper&, const float*, const float*, Index, Index, Index, float, Index, Index, Index, Index);
+
+ #ifdef EIGEN_ALTIVEC_MMA_ONLY
+ //generate with MMA only
+ gemm_function = &Eigen::internal::gemmMMA<float, Index, Packet, RhsPacket, DataMapper, accRows, accCols>;
+ #elif defined(ALTIVEC_MMA_SUPPORT) && !defined(EIGEN_ALTIVEC_DISABLE_MMA)
+ if (__builtin_cpu_supports ("arch_3_1") && __builtin_cpu_supports ("mma")){
+ gemm_function = &Eigen::internal::gemmMMA<float, Index, Packet, RhsPacket, DataMapper, accRows, accCols>;
+ }
+ else{
+ gemm_function = &Eigen::internal::gemm<float, Index, Packet, RhsPacket, DataMapper, accRows, accCols>;
+ }
+ #else
+ gemm_function = &Eigen::internal::gemm<float, Index, Packet, RhsPacket, DataMapper, accRows, accCols>;
+ #endif
+ gemm_function(res, blockA, blockB, rows, depth, cols, alpha, strideA, strideB, offsetA, offsetB);
+ }
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+struct gebp_kernel<std::complex<float>, std::complex<float>, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+{
+ typedef Packet4f Packet;
+ typedef Packet2cf Packetc;
+ typedef Packet4f RhsPacket;
+
+ void operator()(const DataMapper& res, const std::complex<float>* blockA, const std::complex<float>* blockB,
+ Index rows, Index depth, Index cols, std::complex<float> alpha,
+ Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0);
+};
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+void gebp_kernel<std::complex<float>, std::complex<float>, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+ ::operator()(const DataMapper& res, const std::complex<float>* blockA, const std::complex<float>* blockB,
+ Index rows, Index depth, Index cols, std::complex<float> alpha,
+ Index strideA, Index strideB, Index offsetA, Index offsetB)
+ {
+ const Index accRows = quad_traits<float>::rows;
+ const Index accCols = quad_traits<float>::size;
+ void (*gemm_function)(const DataMapper&, const std::complex<float>*, const std::complex<float>*,
+ Index, Index, Index, std::complex<float>, Index, Index, Index, Index);
+
+ #ifdef EIGEN_ALTIVEC_MMA_ONLY
+ //generate with MMA only
+ gemm_function = &Eigen::internal::gemm_complexMMA<std::complex<float>, std::complex<float>, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, false>;
+ #elif defined(ALTIVEC_MMA_SUPPORT) && !defined(EIGEN_ALTIVEC_DISABLE_MMA)
+ if (__builtin_cpu_supports ("arch_3_1") && __builtin_cpu_supports ("mma")){
+ gemm_function = &Eigen::internal::gemm_complexMMA<std::complex<float>, std::complex<float>, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, false>;
+ }
+ else{
+ gemm_function = &Eigen::internal::gemm_complex<std::complex<float>, std::complex<float>, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, false>;
+ }
+ #else
+ gemm_function = &Eigen::internal::gemm_complex<std::complex<float>, std::complex<float>, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, false>;
+ #endif
+ gemm_function(res, blockA, blockB, rows, depth, cols, alpha, strideA, strideB, offsetA, offsetB);
+ }
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+struct gebp_kernel<float, std::complex<float>, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+{
+ typedef Packet4f Packet;
+ typedef Packet2cf Packetc;
+ typedef Packet4f RhsPacket;
+
+ void operator()(const DataMapper& res, const float* blockA, const std::complex<float>* blockB,
+ Index rows, Index depth, Index cols, std::complex<float> alpha,
+ Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0);
+};
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+void gebp_kernel<float, std::complex<float>, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+ ::operator()(const DataMapper& res, const float* blockA, const std::complex<float>* blockB,
+ Index rows, Index depth, Index cols, std::complex<float> alpha,
+ Index strideA, Index strideB, Index offsetA, Index offsetB)
+ {
+ const Index accRows = quad_traits<float>::rows;
+ const Index accCols = quad_traits<float>::size;
+ void (*gemm_function)(const DataMapper&, const float*, const std::complex<float>*,
+ Index, Index, Index, std::complex<float>, Index, Index, Index, Index);
+ #ifdef EIGEN_ALTIVEC_MMA_ONLY
+ //generate with MMA only
+ gemm_function = &Eigen::internal::gemm_complexMMA<float, std::complex<float>, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, true, false>;
+ #elif defined(ALTIVEC_MMA_SUPPORT) && !defined(EIGEN_ALTIVEC_DISABLE_MMA)
+ if (__builtin_cpu_supports ("arch_3_1") && __builtin_cpu_supports ("mma")){
+ gemm_function = &Eigen::internal::gemm_complexMMA<float, std::complex<float>, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, true, false>;
+ }
+ else{
+ gemm_function = &Eigen::internal::gemm_complex<float, std::complex<float>, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, true, false>;
+ }
+ #else
+ gemm_function = &Eigen::internal::gemm_complex<float, std::complex<float>, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, true, false>;
+ #endif
+ gemm_function(res, blockA, blockB, rows, depth, cols, alpha, strideA, strideB, offsetA, offsetB);
+ }
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+struct gebp_kernel<std::complex<float>, float, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+{
+ typedef Packet4f Packet;
+ typedef Packet2cf Packetc;
+ typedef Packet4f RhsPacket;
+
+ void operator()(const DataMapper& res, const std::complex<float>* blockA, const float* blockB,
+ Index rows, Index depth, Index cols, std::complex<float> alpha,
+ Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0);
+};
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+void gebp_kernel<std::complex<float>, float, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+ ::operator()(const DataMapper& res, const std::complex<float>* blockA, const float* blockB,
+ Index rows, Index depth, Index cols, std::complex<float> alpha,
+ Index strideA, Index strideB, Index offsetA, Index offsetB)
+ {
+ const Index accRows = quad_traits<float>::rows;
+ const Index accCols = quad_traits<float>::size;
+ void (*gemm_function)(const DataMapper&, const std::complex<float>*, const float*,
+ Index, Index, Index, std::complex<float>, Index, Index, Index, Index);
+ #ifdef EIGEN_ALTIVEC_MMA_ONLY
+ //generate with MMA only
+ gemm_function = &Eigen::internal::gemm_complexMMA<std::complex<float>, float, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, true>;
+ #elif defined(ALTIVEC_MMA_SUPPORT) && !defined(EIGEN_ALTIVEC_DISABLE_MMA)
+ if (__builtin_cpu_supports ("arch_3_1") && __builtin_cpu_supports ("mma")){
+ gemm_function = &Eigen::internal::gemm_complexMMA<std::complex<float>, float, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, true>;
+ }
+ else{
+ gemm_function = &Eigen::internal::gemm_complex<std::complex<float>, float, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, true>;
+ }
+ #else
+ gemm_function = &Eigen::internal::gemm_complex<std::complex<float>, float, std::complex<float>, float, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, true>;
+ #endif
+ gemm_function(res, blockA, blockB, rows, depth, cols, alpha, strideA, strideB, offsetA, offsetB);
+ }
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+struct gebp_kernel<double, double, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+{
+ typedef typename quad_traits<double>::vectortype Packet;
+ typedef typename quad_traits<double>::rhstype RhsPacket;
+
+ void operator()(const DataMapper& res, const double* blockA, const double* blockB,
+ Index rows, Index depth, Index cols, double alpha,
+ Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0);
+};
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+void gebp_kernel<double, double, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+ ::operator()(const DataMapper& res, const double* blockA, const double* blockB,
+ Index rows, Index depth, Index cols, double alpha,
+ Index strideA, Index strideB, Index offsetA, Index offsetB)
+ {
+ const Index accRows = quad_traits<double>::rows;
+ const Index accCols = quad_traits<double>::size;
+ void (*gemm_function)(const DataMapper&, const double*, const double*, Index, Index, Index, double, Index, Index, Index, Index);
+
+ #ifdef EIGEN_ALTIVEC_MMA_ONLY
+ //generate with MMA only
+ gemm_function = &Eigen::internal::gemmMMA<double, Index, Packet, RhsPacket, DataMapper, accRows, accCols>;
+ #elif defined(ALTIVEC_MMA_SUPPORT) && !defined(EIGEN_ALTIVEC_DISABLE_MMA)
+ if (__builtin_cpu_supports ("arch_3_1") && __builtin_cpu_supports ("mma")){
+ gemm_function = &Eigen::internal::gemmMMA<double, Index, Packet, RhsPacket, DataMapper, accRows, accCols>;
+ }
+ else{
+ gemm_function = &Eigen::internal::gemm<double, Index, Packet, RhsPacket, DataMapper, accRows, accCols>;
+ }
+ #else
+ gemm_function = &Eigen::internal::gemm<double, Index, Packet, RhsPacket, DataMapper, accRows, accCols>;
+ #endif
+ gemm_function(res, blockA, blockB, rows, depth, cols, alpha, strideA, strideB, offsetA, offsetB);
+ }
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+struct gebp_kernel<std::complex<double>, std::complex<double>, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+{
+ typedef quad_traits<double>::vectortype Packet;
+ typedef Packet1cd Packetc;
+ typedef quad_traits<double>::rhstype RhsPacket;
+
+ void operator()(const DataMapper& res, const std::complex<double>* blockA, const std::complex<double>* blockB,
+ Index rows, Index depth, Index cols, std::complex<double> alpha,
+ Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0);
+};
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+void gebp_kernel<std::complex<double>, std::complex<double>, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+ ::operator()(const DataMapper& res, const std::complex<double>* blockA, const std::complex<double>* blockB,
+ Index rows, Index depth, Index cols, std::complex<double> alpha,
+ Index strideA, Index strideB, Index offsetA, Index offsetB)
+ {
+ const Index accRows = quad_traits<double>::rows;
+ const Index accCols = quad_traits<double>::size;
+ void (*gemm_function)(const DataMapper&, const std::complex<double>*, const std::complex<double>*,
+ Index, Index, Index, std::complex<double>, Index, Index, Index, Index);
+ #ifdef EIGEN_ALTIVEC_MMA_ONLY
+ //generate with MMA only
+ gemm_function = &Eigen::internal::gemm_complexMMA<std::complex<double>, std::complex<double>, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, false>;
+ #elif defined(ALTIVEC_MMA_SUPPORT) && !defined(EIGEN_ALTIVEC_DISABLE_MMA)
+ if (__builtin_cpu_supports ("arch_3_1") && __builtin_cpu_supports ("mma")){
+ gemm_function = &Eigen::internal::gemm_complexMMA<std::complex<double>, std::complex<double>, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, false>;
+ }
+ else{
+ gemm_function = &Eigen::internal::gemm_complex<std::complex<double>, std::complex<double>, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, false>;
+ }
+ #else
+ gemm_function = &Eigen::internal::gemm_complex<std::complex<double>, std::complex<double>, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, false>;
+ #endif
+ gemm_function(res, blockA, blockB, rows, depth, cols, alpha, strideA, strideB, offsetA, offsetB);
+ }
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+struct gebp_kernel<std::complex<double>, double, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+{
+ typedef quad_traits<double>::vectortype Packet;
+ typedef Packet1cd Packetc;
+ typedef quad_traits<double>::rhstype RhsPacket;
+
+ void operator()(const DataMapper& res, const std::complex<double>* blockA, const double* blockB,
+ Index rows, Index depth, Index cols, std::complex<double> alpha,
+ Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0);
+};
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+void gebp_kernel<std::complex<double>, double, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+ ::operator()(const DataMapper& res, const std::complex<double>* blockA, const double* blockB,
+ Index rows, Index depth, Index cols, std::complex<double> alpha,
+ Index strideA, Index strideB, Index offsetA, Index offsetB)
+ {
+ const Index accRows = quad_traits<double>::rows;
+ const Index accCols = quad_traits<double>::size;
+ void (*gemm_function)(const DataMapper&, const std::complex<double>*, const double*,
+ Index, Index, Index, std::complex<double>, Index, Index, Index, Index);
+ #ifdef EIGEN_ALTIVEC_MMA_ONLY
+ //generate with MMA only
+ gemm_function = &Eigen::internal::gemm_complexMMA<std::complex<double>, double, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, true>;
+ #elif defined(ALTIVEC_MMA_SUPPORT) && !defined(EIGEN_ALTIVEC_DISABLE_MMA)
+ if (__builtin_cpu_supports ("arch_3_1") && __builtin_cpu_supports ("mma")){
+ gemm_function = &Eigen::internal::gemm_complexMMA<std::complex<double>, double, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, true>;
+ }
+ else{
+ gemm_function = &Eigen::internal::gemm_complex<std::complex<double>, double, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, true>;
+ }
+ #else
+ gemm_function = &Eigen::internal::gemm_complex<std::complex<double>, double, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, false, true>;
+ #endif
+ gemm_function(res, blockA, blockB, rows, depth, cols, alpha, strideA, strideB, offsetA, offsetB);
+ }
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+struct gebp_kernel<double, std::complex<double>, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+{
+ typedef quad_traits<double>::vectortype Packet;
+ typedef Packet1cd Packetc;
+ typedef quad_traits<double>::rhstype RhsPacket;
+
+ void operator()(const DataMapper& res, const double* blockA, const std::complex<double>* blockB,
+ Index rows, Index depth, Index cols, std::complex<double> alpha,
+ Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0);
+};
+
+template<typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+void gebp_kernel<double, std::complex<double>, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs>
+ ::operator()(const DataMapper& res, const double* blockA, const std::complex<double>* blockB,
+ Index rows, Index depth, Index cols, std::complex<double> alpha,
+ Index strideA, Index strideB, Index offsetA, Index offsetB)
+ {
+ const Index accRows = quad_traits<double>::rows;
+ const Index accCols = quad_traits<double>::size;
+ void (*gemm_function)(const DataMapper&, const double*, const std::complex<double>*,
+ Index, Index, Index, std::complex<double>, Index, Index, Index, Index);
+ #ifdef EIGEN_ALTIVEC_MMA_ONLY
+ //generate with MMA only
+ gemm_function = &Eigen::internal::gemm_complexMMA<double, std::complex<double>, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, true, false>;
+ #elif defined(ALTIVEC_MMA_SUPPORT) && !defined(EIGEN_ALTIVEC_DISABLE_MMA)
+ if (__builtin_cpu_supports ("arch_3_1") && __builtin_cpu_supports ("mma")){
+ gemm_function = &Eigen::internal::gemm_complexMMA<double, std::complex<double>, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, true, false>;
+ }
+ else{
+ gemm_function = &Eigen::internal::gemm_complex<double, std::complex<double>, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, true, false>;
+ }
+ #else
+ gemm_function = &Eigen::internal::gemm_complex<double, std::complex<double>, std::complex<double>, double, Index, Packet, Packetc, RhsPacket, DataMapper, accRows, accCols, ConjugateLhs, ConjugateRhs, true, false>;
+ #endif
+ gemm_function(res, blockA, blockB, rows, depth, cols, alpha, strideA, strideB, offsetA, offsetB);
+ }
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATRIX_PRODUCT_ALTIVEC_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductCommon.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductCommon.h
new file mode 100644
index 000000000..33d543494
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductCommon.h
@@ -0,0 +1,221 @@
+//#define EIGEN_POWER_USE_PREFETCH // Use prefetching in gemm routines
+#ifdef EIGEN_POWER_USE_PREFETCH
+#define EIGEN_POWER_PREFETCH(p) prefetch(p)
+#else
+#define EIGEN_POWER_PREFETCH(p)
+#endif
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Scalar, typename Packet, typename DataMapper, typename Index, const Index accRows>
+EIGEN_STRONG_INLINE void gemm_extra_col(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index row,
+ Index col,
+ Index remaining_rows,
+ Index remaining_cols,
+ const Packet& pAlpha);
+
+template<typename Scalar, typename Packet, typename DataMapper, typename Index, const Index accRows, const Index accCols>
+EIGEN_STRONG_INLINE void gemm_extra_row(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index row,
+ Index col,
+ Index rows,
+ Index cols,
+ Index remaining_rows,
+ const Packet& pAlpha,
+ const Packet& pMask);
+
+template<typename Scalar, typename Packet, typename DataMapper, typename Index, const Index accCols>
+EIGEN_STRONG_INLINE void gemm_unrolled_col(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index& row,
+ Index rows,
+ Index col,
+ Index remaining_cols,
+ const Packet& pAlpha);
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE Packet bmask(const int remaining_rows);
+
+template<typename Scalar, typename Packet, typename Packetc, typename DataMapper, typename Index, const Index accRows, const Index accCols, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_STRONG_INLINE void gemm_complex_extra_col(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index strideB,
+ Index row,
+ Index col,
+ Index remaining_rows,
+ Index remaining_cols,
+ const Packet& pAlphaReal,
+ const Packet& pAlphaImag);
+
+template<typename Scalar, typename Packet, typename Packetc, typename DataMapper, typename Index, const Index accRows, const Index accCols, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_STRONG_INLINE void gemm_complex_extra_row(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index strideB,
+ Index row,
+ Index col,
+ Index rows,
+ Index cols,
+ Index remaining_rows,
+ const Packet& pAlphaReal,
+ const Packet& pAlphaImag,
+ const Packet& pMask);
+
+template<typename Scalar, typename Packet, typename Packetc, typename DataMapper, typename Index, const Index accCols, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_STRONG_INLINE void gemm_complex_unrolled_col(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index strideB,
+ Index& row,
+ Index rows,
+ Index col,
+ Index remaining_cols,
+ const Packet& pAlphaReal,
+ const Packet& pAlphaImag);
+
+template<typename Scalar, typename Packet>
+EIGEN_ALWAYS_INLINE Packet ploadLhs(const Scalar* lhs);
+
+template<typename DataMapper, typename Packet, typename Index, const Index accCols, int N, int StorageOrder>
+EIGEN_ALWAYS_INLINE void bload(PacketBlock<Packet,4>& acc, const DataMapper& res, Index row, Index col);
+
+template<typename DataMapper, typename Packet, typename Index, const Index accCols, int N, int StorageOrder>
+EIGEN_ALWAYS_INLINE void bload(PacketBlock<Packet,8>& acc, const DataMapper& res, Index row, Index col);
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void bscale(PacketBlock<Packet,4>& acc, PacketBlock<Packet,4>& accZ, const Packet& pAlpha);
+
+template<typename Packet, int N>
+EIGEN_ALWAYS_INLINE void bscalec(PacketBlock<Packet,N>& aReal, PacketBlock<Packet,N>& aImag, const Packet& bReal, const Packet& bImag, PacketBlock<Packet,N>& cReal, PacketBlock<Packet,N>& cImag);
+
+const static Packet16uc p16uc_SETCOMPLEX32_FIRST = { 0, 1, 2, 3,
+ 16, 17, 18, 19,
+ 4, 5, 6, 7,
+ 20, 21, 22, 23};
+
+const static Packet16uc p16uc_SETCOMPLEX32_SECOND = { 8, 9, 10, 11,
+ 24, 25, 26, 27,
+ 12, 13, 14, 15,
+ 28, 29, 30, 31};
+//[a,b],[ai,bi] = [a,ai] - This is equivalent to p16uc_GETREAL64
+const static Packet16uc p16uc_SETCOMPLEX64_FIRST = { 0, 1, 2, 3, 4, 5, 6, 7,
+ 16, 17, 18, 19, 20, 21, 22, 23};
+
+//[a,b],[ai,bi] = [b,bi] - This is equivalent to p16uc_GETIMAG64
+const static Packet16uc p16uc_SETCOMPLEX64_SECOND = { 8, 9, 10, 11, 12, 13, 14, 15,
+ 24, 25, 26, 27, 28, 29, 30, 31};
+
+
+// Grab two decouples real/imaginary PacketBlocks and return two coupled (real/imaginary pairs) PacketBlocks.
+template<typename Packet, typename Packetc>
+EIGEN_ALWAYS_INLINE void bcouple_common(PacketBlock<Packet,4>& taccReal, PacketBlock<Packet,4>& taccImag, PacketBlock<Packetc, 4>& acc1, PacketBlock<Packetc, 4>& acc2)
+{
+ acc1.packet[0].v = vec_perm(taccReal.packet[0], taccImag.packet[0], p16uc_SETCOMPLEX32_FIRST);
+ acc1.packet[1].v = vec_perm(taccReal.packet[1], taccImag.packet[1], p16uc_SETCOMPLEX32_FIRST);
+ acc1.packet[2].v = vec_perm(taccReal.packet[2], taccImag.packet[2], p16uc_SETCOMPLEX32_FIRST);
+ acc1.packet[3].v = vec_perm(taccReal.packet[3], taccImag.packet[3], p16uc_SETCOMPLEX32_FIRST);
+
+ acc2.packet[0].v = vec_perm(taccReal.packet[0], taccImag.packet[0], p16uc_SETCOMPLEX32_SECOND);
+ acc2.packet[1].v = vec_perm(taccReal.packet[1], taccImag.packet[1], p16uc_SETCOMPLEX32_SECOND);
+ acc2.packet[2].v = vec_perm(taccReal.packet[2], taccImag.packet[2], p16uc_SETCOMPLEX32_SECOND);
+ acc2.packet[3].v = vec_perm(taccReal.packet[3], taccImag.packet[3], p16uc_SETCOMPLEX32_SECOND);
+}
+
+template<typename Packet, typename Packetc>
+EIGEN_ALWAYS_INLINE void bcouple(PacketBlock<Packet,4>& taccReal, PacketBlock<Packet,4>& taccImag, PacketBlock<Packetc,8>& tRes, PacketBlock<Packetc, 4>& acc1, PacketBlock<Packetc, 4>& acc2)
+{
+ bcouple_common<Packet, Packetc>(taccReal, taccImag, acc1, acc2);
+
+ acc1.packet[0] = padd<Packetc>(tRes.packet[0], acc1.packet[0]);
+ acc1.packet[1] = padd<Packetc>(tRes.packet[1], acc1.packet[1]);
+ acc1.packet[2] = padd<Packetc>(tRes.packet[2], acc1.packet[2]);
+ acc1.packet[3] = padd<Packetc>(tRes.packet[3], acc1.packet[3]);
+
+ acc2.packet[0] = padd<Packetc>(tRes.packet[4], acc2.packet[0]);
+ acc2.packet[1] = padd<Packetc>(tRes.packet[5], acc2.packet[1]);
+ acc2.packet[2] = padd<Packetc>(tRes.packet[6], acc2.packet[2]);
+ acc2.packet[3] = padd<Packetc>(tRes.packet[7], acc2.packet[3]);
+}
+
+template<typename Packet, typename Packetc>
+EIGEN_ALWAYS_INLINE void bcouple_common(PacketBlock<Packet,1>& taccReal, PacketBlock<Packet,1>& taccImag, PacketBlock<Packetc, 1>& acc1, PacketBlock<Packetc, 1>& acc2)
+{
+ acc1.packet[0].v = vec_perm(taccReal.packet[0], taccImag.packet[0], p16uc_SETCOMPLEX32_FIRST);
+
+ acc2.packet[0].v = vec_perm(taccReal.packet[0], taccImag.packet[0], p16uc_SETCOMPLEX32_SECOND);
+}
+
+template<typename Packet, typename Packetc>
+EIGEN_ALWAYS_INLINE void bcouple(PacketBlock<Packet,1>& taccReal, PacketBlock<Packet,1>& taccImag, PacketBlock<Packetc,2>& tRes, PacketBlock<Packetc, 1>& acc1, PacketBlock<Packetc, 1>& acc2)
+{
+ bcouple_common<Packet, Packetc>(taccReal, taccImag, acc1, acc2);
+
+ acc1.packet[0] = padd<Packetc>(tRes.packet[0], acc1.packet[0]);
+
+ acc2.packet[0] = padd<Packetc>(tRes.packet[1], acc2.packet[0]);
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void bcouple_common<Packet2d, Packet1cd>(PacketBlock<Packet2d,4>& taccReal, PacketBlock<Packet2d,4>& taccImag, PacketBlock<Packet1cd, 4>& acc1, PacketBlock<Packet1cd, 4>& acc2)
+{
+ acc1.packet[0].v = vec_perm(taccReal.packet[0], taccImag.packet[0], p16uc_SETCOMPLEX64_FIRST);
+ acc1.packet[1].v = vec_perm(taccReal.packet[1], taccImag.packet[1], p16uc_SETCOMPLEX64_FIRST);
+ acc1.packet[2].v = vec_perm(taccReal.packet[2], taccImag.packet[2], p16uc_SETCOMPLEX64_FIRST);
+ acc1.packet[3].v = vec_perm(taccReal.packet[3], taccImag.packet[3], p16uc_SETCOMPLEX64_FIRST);
+
+ acc2.packet[0].v = vec_perm(taccReal.packet[0], taccImag.packet[0], p16uc_SETCOMPLEX64_SECOND);
+ acc2.packet[1].v = vec_perm(taccReal.packet[1], taccImag.packet[1], p16uc_SETCOMPLEX64_SECOND);
+ acc2.packet[2].v = vec_perm(taccReal.packet[2], taccImag.packet[2], p16uc_SETCOMPLEX64_SECOND);
+ acc2.packet[3].v = vec_perm(taccReal.packet[3], taccImag.packet[3], p16uc_SETCOMPLEX64_SECOND);
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void bcouple_common<Packet2d, Packet1cd>(PacketBlock<Packet2d,1>& taccReal, PacketBlock<Packet2d,1>& taccImag, PacketBlock<Packet1cd, 1>& acc1, PacketBlock<Packet1cd, 1>& acc2)
+{
+ acc1.packet[0].v = vec_perm(taccReal.packet[0], taccImag.packet[0], p16uc_SETCOMPLEX64_FIRST);
+
+ acc2.packet[0].v = vec_perm(taccReal.packet[0], taccImag.packet[0], p16uc_SETCOMPLEX64_SECOND);
+}
+
+// This is necessary because ploadRhs for double returns a pair of vectors when MMA is enabled.
+template<typename Scalar, typename Packet>
+EIGEN_ALWAYS_INLINE Packet ploadRhs(const Scalar* rhs)
+{
+ return ploadu<Packet>(rhs);
+}
+
+} // end namespace internal
+} // end namespace Eigen
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMA.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMA.h
new file mode 100644
index 000000000..6540c6fa6
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMA.h
@@ -0,0 +1,629 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2020 Everton Constantino (everton.constantino@ibm.com)
+// Copyright (C) 2021 Chip Kerchner (chip.kerchner@ibm.com)
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATRIX_PRODUCT_MMA_ALTIVEC_H
+#define EIGEN_MATRIX_PRODUCT_MMA_ALTIVEC_H
+
+#pragma GCC target("cpu=power10")
+
+#ifdef __has_builtin
+#if !__has_builtin(__builtin_vsx_assemble_pair)
+#define __builtin_vsx_assemble_pair __builtin_mma_assemble_pair
+#endif
+#endif
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Scalar, typename Packet>
+EIGEN_ALWAYS_INLINE void bsetzeroMMA(__vector_quad* acc)
+{
+ __builtin_mma_xxsetaccz(acc);
+}
+
+template<typename DataMapper, typename Index, typename Packet, const Index accCols>
+EIGEN_ALWAYS_INLINE void storeAccumulator(Index i, Index j, const DataMapper& data, const Packet& alpha, __vector_quad* acc)
+{
+ PacketBlock<Packet, 4> result;
+ __builtin_mma_disassemble_acc(&result.packet, acc);
+
+ PacketBlock<Packet, 4> tRes;
+ bload<DataMapper, Packet, Index, accCols, 0, ColMajor>(tRes, data, i, j);
+
+ bscale<Packet>(tRes, result, alpha);
+
+ data.template storePacketBlock<Packet, 4>(i, j, tRes);
+}
+
+template<typename DataMapper, typename Index, typename Packet, typename Packetc, const Index accColsC, int N>
+EIGEN_ALWAYS_INLINE void storeComplexAccumulator(Index i, Index j, const DataMapper& data, const Packet& alphaReal, const Packet& alphaImag, __vector_quad* accReal, __vector_quad* accImag)
+{
+ PacketBlock<Packet, 4> resultReal, resultImag;
+ __builtin_mma_disassemble_acc(&resultReal.packet, accReal);
+ __builtin_mma_disassemble_acc(&resultImag.packet, accImag);
+
+ PacketBlock<Packetc, 8> tRes;
+ bload<DataMapper, Packetc, Index, accColsC, N, ColMajor>(tRes, data, i, j);
+
+ PacketBlock<Packet,4> taccReal, taccImag;
+ bscalec<Packet,4>(resultReal, resultImag, alphaReal, alphaImag, taccReal, taccImag);
+
+ PacketBlock<Packetc, 4> acc1, acc2;
+ bcouple<Packet, Packetc>(taccReal, taccImag, tRes, acc1, acc2);
+
+ data.template storePacketBlock<Packetc, 4>(i + N*accColsC, j, acc1);
+ data.template storePacketBlock<Packetc, 4>(i + (N+1)*accColsC, j, acc2);
+}
+
+// Defaults to float32, since Eigen still supports C++03 we can't use default template arguments
+template<typename LhsPacket, typename RhsPacket, bool NegativeAccumulate>
+EIGEN_ALWAYS_INLINE void pgerMMA(__vector_quad* acc, const RhsPacket& a, const LhsPacket& b)
+{
+ if(NegativeAccumulate)
+ {
+ __builtin_mma_xvf32gernp(acc, (__vector unsigned char)a, (__vector unsigned char)b);
+ } else {
+ __builtin_mma_xvf32gerpp(acc, (__vector unsigned char)a, (__vector unsigned char)b);
+ }
+}
+
+template<typename LhsPacket, typename RhsPacket, bool NegativeAccumulate>
+EIGEN_ALWAYS_INLINE void pgerMMA(__vector_quad* acc, const PacketBlock<Packet2d,2>& a, const Packet2d& b)
+{
+ __vector_pair* a0 = (__vector_pair *)(&a.packet[0]);
+ if(NegativeAccumulate)
+ {
+ __builtin_mma_xvf64gernp(acc, *a0, (__vector unsigned char)b);
+ } else {
+ __builtin_mma_xvf64gerpp(acc, *a0, (__vector unsigned char)b);
+ }
+}
+
+template<typename LhsPacket, typename RhsPacket, bool NegativeAccumulate>
+EIGEN_ALWAYS_INLINE void pgerMMA(__vector_quad* acc, const __vector_pair& a, const Packet2d& b)
+{
+ if(NegativeAccumulate)
+ {
+ __builtin_mma_xvf64gernp(acc, (__vector_pair)a, (__vector unsigned char)b);
+ } else {
+ __builtin_mma_xvf64gerpp(acc, (__vector_pair)a, (__vector unsigned char)b);
+ }
+}
+
+template<typename LhsPacket, typename RhsPacket, bool NegativeAccumulate>
+EIGEN_ALWAYS_INLINE void pgerMMA(__vector_quad*, const __vector_pair&, const Packet4f&)
+{
+ // Just for compilation
+}
+
+template<typename Scalar, typename Packet, typename RhsPacket, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_ALWAYS_INLINE void pgercMMA(__vector_quad* accReal, __vector_quad* accImag, const Packet& lhsV, const Packet& lhsVi, const RhsPacket& rhsV, const RhsPacket& rhsVi)
+{
+ pgerMMA<Packet, RhsPacket, false>(accReal, rhsV, lhsV);
+ if(LhsIsReal) {
+ pgerMMA<Packet, RhsPacket, ConjugateRhs>(accImag, rhsVi, lhsV);
+ } else {
+ if(!RhsIsReal) {
+ pgerMMA<Packet, RhsPacket, ConjugateLhs == ConjugateRhs>(accReal, rhsVi, lhsVi);
+ pgerMMA<Packet, RhsPacket, ConjugateRhs>(accImag, rhsVi, lhsV);
+ } else {
+ EIGEN_UNUSED_VARIABLE(rhsVi);
+ }
+ pgerMMA<Packet, RhsPacket, ConjugateLhs>(accImag, rhsV, lhsVi);
+ }
+}
+
+// This is necessary because ploadRhs for double returns a pair of vectors when MMA is enabled.
+template<typename Scalar, typename Packet>
+EIGEN_ALWAYS_INLINE void ploadRhsMMA(const Scalar* rhs, Packet& rhsV)
+{
+ rhsV = ploadRhs<Scalar, Packet>((const Scalar*)(rhs));
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void ploadRhsMMA<double, PacketBlock<Packet2d, 2> >(const double* rhs, PacketBlock<Packet2d, 2>& rhsV)
+{
+ rhsV.packet[0] = ploadRhs<double, Packet2d>((const double *)((Packet2d *)rhs ));
+ rhsV.packet[1] = ploadRhs<double, Packet2d>((const double *)(((Packet2d *)rhs) + 1));
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void ploadRhsMMA<double, __vector_pair>(const double* rhs, __vector_pair& rhsV)
+{
+#if EIGEN_COMP_LLVM
+ __builtin_vsx_assemble_pair(&rhsV,
+ (__vector unsigned char)(ploadRhs<double, Packet2d>((const double *)(((Packet2d *)rhs) + 1))),
+ (__vector unsigned char)(ploadRhs<double, Packet2d>((const double *)((Packet2d *)rhs ))));
+#else
+ __asm__ ("lxvp %x0,%1" : "=wa" (rhsV) : "Y" (*rhs));
+#endif
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void ploadRhsMMA(const float*, __vector_pair&)
+{
+ // Just for compilation
+}
+
+// PEEL_MMA loop factor.
+#define PEEL_MMA 7
+
+#define MICRO_MMA_UNROLL(func) \
+ func(0) func(1) func(2) func(3) func(4) func(5) func(6) func(7)
+
+#define MICRO_MMA_LOAD_ONE(iter) \
+ if (unroll_factor > iter) { \
+ lhsV##iter = ploadLhs<Scalar, Packet>(lhs_ptr##iter); \
+ lhs_ptr##iter += accCols; \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhsV##iter); \
+ }
+
+#define MICRO_MMA_WORK_ONE(iter, type, peel) \
+ if (unroll_factor > iter) { \
+ pgerMMA<Packet, type, false>(&accZero##iter, rhsV##peel, lhsV##iter); \
+ }
+
+#define MICRO_MMA_TYPE_PEEL(func, func2, type, peel) \
+ if (PEEL_MMA > peel) { \
+ Packet lhsV0, lhsV1, lhsV2, lhsV3, lhsV4, lhsV5, lhsV6, lhsV7; \
+ ploadRhsMMA<Scalar, type>(rhs_ptr + (accRows * peel), rhsV##peel); \
+ MICRO_MMA_UNROLL(func2); \
+ func(0,type,peel) func(1,type,peel) func(2,type,peel) func(3,type,peel) \
+ func(4,type,peel) func(5,type,peel) func(6,type,peel) func(7,type,peel) \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(rhsV##peel); \
+ }
+
+#define MICRO_MMA_UNROLL_TYPE_PEEL(func, func2, type) \
+ type rhsV0, rhsV1, rhsV2, rhsV3, rhsV4, rhsV5, rhsV6, rhsV7, rhsV8, rhsV9; \
+ MICRO_MMA_TYPE_PEEL(func,func2,type,0); MICRO_MMA_TYPE_PEEL(func,func2,type,1); \
+ MICRO_MMA_TYPE_PEEL(func,func2,type,2); MICRO_MMA_TYPE_PEEL(func,func2,type,3); \
+ MICRO_MMA_TYPE_PEEL(func,func2,type,4); MICRO_MMA_TYPE_PEEL(func,func2,type,5); \
+ MICRO_MMA_TYPE_PEEL(func,func2,type,6); MICRO_MMA_TYPE_PEEL(func,func2,type,7); \
+ MICRO_MMA_TYPE_PEEL(func,func2,type,8); MICRO_MMA_TYPE_PEEL(func,func2,type,9);
+
+#define MICRO_MMA_UNROLL_TYPE_ONE(func, func2, type) \
+ type rhsV0; \
+ MICRO_MMA_TYPE_PEEL(func,func2,type,0);
+
+#define MICRO_MMA_ONE_PEEL \
+ if (sizeof(Scalar) == sizeof(float)) { \
+ MICRO_MMA_UNROLL_TYPE_PEEL(MICRO_MMA_WORK_ONE, MICRO_MMA_LOAD_ONE, RhsPacket); \
+ } else { \
+ MICRO_MMA_UNROLL_TYPE_PEEL(MICRO_MMA_WORK_ONE, MICRO_MMA_LOAD_ONE, __vector_pair); \
+ } \
+ rhs_ptr += (accRows * PEEL_MMA);
+
+#define MICRO_MMA_ONE \
+ if (sizeof(Scalar) == sizeof(float)) { \
+ MICRO_MMA_UNROLL_TYPE_ONE(MICRO_MMA_WORK_ONE, MICRO_MMA_LOAD_ONE, RhsPacket); \
+ } else { \
+ MICRO_MMA_UNROLL_TYPE_ONE(MICRO_MMA_WORK_ONE, MICRO_MMA_LOAD_ONE, __vector_pair); \
+ } \
+ rhs_ptr += accRows;
+
+#define MICRO_MMA_DST_PTR_ONE(iter) \
+ if (unroll_factor > iter) { \
+ bsetzeroMMA<Scalar, Packet>(&accZero##iter); \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(accZero##iter); \
+ }
+
+#define MICRO_MMA_DST_PTR MICRO_MMA_UNROLL(MICRO_MMA_DST_PTR_ONE)
+
+#define MICRO_MMA_SRC_PTR_ONE(iter) \
+ if (unroll_factor > iter) { \
+ lhs_ptr##iter = lhs_base + ( (row/accCols) + iter )*strideA*accCols + accCols*offsetA; \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhs_ptr##iter); \
+ }
+
+#define MICRO_MMA_SRC_PTR MICRO_MMA_UNROLL(MICRO_MMA_SRC_PTR_ONE)
+
+#define MICRO_MMA_PREFETCH_ONE(iter) \
+ if (unroll_factor > iter) { \
+ EIGEN_POWER_PREFETCH(lhs_ptr##iter); \
+ }
+
+#define MICRO_MMA_PREFETCH MICRO_MMA_UNROLL(MICRO_MMA_PREFETCH_ONE)
+
+#define MICRO_MMA_STORE_ONE(iter) \
+ if (unroll_factor > iter) { \
+ storeAccumulator<DataMapper, Index, Packet, accCols>(row + iter*accCols, col, res, pAlpha, &accZero##iter); \
+ }
+
+#define MICRO_MMA_STORE MICRO_MMA_UNROLL(MICRO_MMA_STORE_ONE)
+
+template<int unroll_factor, typename Scalar, typename Packet, typename RhsPacket, typename DataMapper, typename Index, const Index accRows, const Index accCols>
+EIGEN_STRONG_INLINE void gemm_unrolled_MMA_iteration(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index& row,
+ Index col,
+ const Packet& pAlpha)
+{
+ const Scalar* rhs_ptr = rhs_base;
+ const Scalar* lhs_ptr0 = NULL, * lhs_ptr1 = NULL, * lhs_ptr2 = NULL, * lhs_ptr3 = NULL, * lhs_ptr4 = NULL, * lhs_ptr5 = NULL, * lhs_ptr6 = NULL, * lhs_ptr7 = NULL;
+ __vector_quad accZero0, accZero1, accZero2, accZero3, accZero4, accZero5, accZero6, accZero7;
+
+ MICRO_MMA_SRC_PTR
+ MICRO_MMA_DST_PTR
+
+ Index k = 0;
+ for(; k + PEEL_MMA <= depth; k+= PEEL_MMA)
+ {
+ EIGEN_POWER_PREFETCH(rhs_ptr);
+ MICRO_MMA_PREFETCH
+ MICRO_MMA_ONE_PEEL
+ }
+ for(; k < depth; k++)
+ {
+ MICRO_MMA_ONE
+ }
+ MICRO_MMA_STORE
+
+ row += unroll_factor*accCols;
+}
+
+template<typename Scalar, typename Index, typename Packet, typename RhsPacket, typename DataMapper, const Index accRows, const Index accCols>
+void gemmMMA(const DataMapper& res, const Scalar* blockA, const Scalar* blockB, Index rows, Index depth, Index cols, Scalar alpha, Index strideA, Index strideB, Index offsetA, Index offsetB)
+{
+ const Index remaining_rows = rows % accCols;
+ const Index remaining_cols = cols % accRows;
+
+ if( strideA == -1 ) strideA = depth;
+ if( strideB == -1 ) strideB = depth;
+
+ const Packet pAlpha = pset1<Packet>(alpha);
+ const Packet pMask = bmask<Packet>((const int)(remaining_rows));
+
+ Index col = 0;
+ for(; col + accRows <= cols; col += accRows)
+ {
+ const Scalar* rhs_base = blockB + col*strideB + accRows*offsetB;
+ const Scalar* lhs_base = blockA;
+
+ Index row = 0;
+#define MAX_MMA_UNROLL 7
+ while(row + MAX_MMA_UNROLL*accCols <= rows) {
+ gemm_unrolled_MMA_iteration<MAX_MMA_UNROLL, Scalar, Packet, RhsPacket, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ }
+ switch( (rows-row)/accCols ) {
+#if MAX_MMA_UNROLL > 7
+ case 7:
+ gemm_unrolled_MMA_iteration<7, Scalar, Packet, RhsPacket, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_MMA_UNROLL > 6
+ case 6:
+ gemm_unrolled_MMA_iteration<6, Scalar, Packet, RhsPacket, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_MMA_UNROLL > 5
+ case 5:
+ gemm_unrolled_MMA_iteration<5, Scalar, Packet, RhsPacket, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_MMA_UNROLL > 4
+ case 4:
+ gemm_unrolled_MMA_iteration<4, Scalar, Packet, RhsPacket, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_MMA_UNROLL > 3
+ case 3:
+ gemm_unrolled_MMA_iteration<3, Scalar, Packet, RhsPacket, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_MMA_UNROLL > 2
+ case 2:
+ gemm_unrolled_MMA_iteration<2, Scalar, Packet, RhsPacket, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+#if MAX_MMA_UNROLL > 1
+ case 1:
+ gemm_unrolled_MMA_iteration<1, Scalar, Packet, RhsPacket, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, pAlpha);
+ break;
+#endif
+ default:
+ break;
+ }
+#undef MAX_MMA_UNROLL
+
+ if(remaining_rows > 0)
+ {
+ gemm_extra_row<Scalar, Packet, DataMapper, Index, accRows, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, rows, cols, remaining_rows, pAlpha, pMask);
+ }
+ }
+
+ if(remaining_cols > 0)
+ {
+ const Scalar* rhs_base = blockB + col*strideB + remaining_cols*offsetB;
+ const Scalar* lhs_base = blockA;
+
+ for(; col < cols; col++)
+ {
+ Index row = 0;
+
+ gemm_unrolled_col<Scalar, Packet, DataMapper, Index, accCols>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, rows, col, remaining_cols, pAlpha);
+
+ if (remaining_rows > 0)
+ {
+ gemm_extra_col<Scalar, Packet, DataMapper, Index, accRows>(res, lhs_base, rhs_base, depth, strideA, offsetA, row, col, remaining_rows, remaining_cols, pAlpha);
+ }
+ rhs_base++;
+ }
+ }
+}
+
+#define accColsC (accCols / 2)
+#define advanceRows ((LhsIsReal) ? 1 : 2)
+#define advanceCols ((RhsIsReal) ? 1 : 2)
+
+// PEEL_COMPLEX_MMA loop factor.
+#define PEEL_COMPLEX_MMA 7
+
+#define MICRO_COMPLEX_MMA_UNROLL(func) \
+ func(0) func(1) func(2) func(3) func(4)
+
+#define MICRO_COMPLEX_MMA_LOAD_ONE(iter) \
+ if (unroll_factor > iter) { \
+ lhsV##iter = ploadLhs<Scalar, Packet>(lhs_ptr_real##iter); \
+ lhs_ptr_real##iter += accCols; \
+ if(!LhsIsReal) { \
+ lhsVi##iter = ploadLhs<Scalar, Packet>(lhs_ptr_imag##iter); \
+ lhs_ptr_imag##iter += accCols; \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhsVi##iter); \
+ } \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhsV##iter); \
+ EIGEN_UNUSED_VARIABLE(lhsVi##iter); \
+ }
+
+#define MICRO_COMPLEX_MMA_WORK_ONE(iter, type, peel) \
+ if (unroll_factor > iter) { \
+ pgercMMA<Scalar, Packet, type, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(&accReal##iter, &accImag##iter, lhsV##iter, lhsVi##iter, rhsV##peel, rhsVi##peel); \
+ }
+
+#define MICRO_COMPLEX_MMA_TYPE_PEEL(func, func2, type, peel) \
+ if (PEEL_COMPLEX_MMA > peel) { \
+ Packet lhsV0, lhsV1, lhsV2, lhsV3, lhsV4; \
+ Packet lhsVi0, lhsVi1, lhsVi2, lhsVi3, lhsVi4; \
+ ploadRhsMMA<Scalar, type>(rhs_ptr_real + (accRows * peel), rhsV##peel); \
+ if(!RhsIsReal) { \
+ ploadRhsMMA<Scalar, type>(rhs_ptr_imag + (accRows * peel), rhsVi##peel); \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(rhsVi##peel); \
+ } \
+ MICRO_COMPLEX_MMA_UNROLL(func2); \
+ func(0,type,peel) func(1,type,peel) func(2,type,peel) func(3,type,peel) func(4,type,peel) \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(rhsV##peel); \
+ EIGEN_UNUSED_VARIABLE(rhsVi##peel); \
+ }
+
+#define MICRO_COMPLEX_MMA_UNROLL_TYPE_PEEL(func, func2, type) \
+ type rhsV0, rhsV1, rhsV2, rhsV3, rhsV4, rhsV5, rhsV6, rhsV7, rhsV8, rhsV9; \
+ type rhsVi0, rhsVi1, rhsVi2, rhsVi3, rhsVi4, rhsVi5, rhsVi6, rhsVi7, rhsVi8, rhsVi9; \
+ MICRO_COMPLEX_MMA_TYPE_PEEL(func,func2,type,0); MICRO_COMPLEX_MMA_TYPE_PEEL(func,func2,type,1); \
+ MICRO_COMPLEX_MMA_TYPE_PEEL(func,func2,type,2); MICRO_COMPLEX_MMA_TYPE_PEEL(func,func2,type,3); \
+ MICRO_COMPLEX_MMA_TYPE_PEEL(func,func2,type,4); MICRO_COMPLEX_MMA_TYPE_PEEL(func,func2,type,5); \
+ MICRO_COMPLEX_MMA_TYPE_PEEL(func,func2,type,6); MICRO_COMPLEX_MMA_TYPE_PEEL(func,func2,type,7); \
+ MICRO_COMPLEX_MMA_TYPE_PEEL(func,func2,type,8); MICRO_COMPLEX_MMA_TYPE_PEEL(func,func2,type,9);
+
+#define MICRO_COMPLEX_MMA_UNROLL_TYPE_ONE(func, func2, type) \
+ type rhsV0, rhsVi0; \
+ MICRO_COMPLEX_MMA_TYPE_PEEL(func,func2,type,0);
+
+#define MICRO_COMPLEX_MMA_ONE_PEEL \
+ if (sizeof(Scalar) == sizeof(float)) { \
+ MICRO_COMPLEX_MMA_UNROLL_TYPE_PEEL(MICRO_COMPLEX_MMA_WORK_ONE, MICRO_COMPLEX_MMA_LOAD_ONE, RhsPacket); \
+ } else { \
+ MICRO_COMPLEX_MMA_UNROLL_TYPE_PEEL(MICRO_COMPLEX_MMA_WORK_ONE, MICRO_COMPLEX_MMA_LOAD_ONE, __vector_pair); \
+ } \
+ rhs_ptr_real += (accRows * PEEL_COMPLEX_MMA); \
+ if(!RhsIsReal) rhs_ptr_imag += (accRows * PEEL_COMPLEX_MMA);
+
+#define MICRO_COMPLEX_MMA_ONE \
+ if (sizeof(Scalar) == sizeof(float)) { \
+ MICRO_COMPLEX_MMA_UNROLL_TYPE_ONE(MICRO_COMPLEX_MMA_WORK_ONE, MICRO_COMPLEX_MMA_LOAD_ONE, RhsPacket); \
+ } else { \
+ MICRO_COMPLEX_MMA_UNROLL_TYPE_ONE(MICRO_COMPLEX_MMA_WORK_ONE, MICRO_COMPLEX_MMA_LOAD_ONE, __vector_pair); \
+ } \
+ rhs_ptr_real += accRows; \
+ if(!RhsIsReal) rhs_ptr_imag += accRows;
+
+#define MICRO_COMPLEX_MMA_DST_PTR_ONE(iter) \
+ if (unroll_factor > iter) { \
+ bsetzeroMMA<Scalar, Packet>(&accReal##iter); \
+ bsetzeroMMA<Scalar, Packet>(&accImag##iter); \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(accReal##iter); \
+ EIGEN_UNUSED_VARIABLE(accImag##iter); \
+ }
+
+#define MICRO_COMPLEX_MMA_DST_PTR MICRO_COMPLEX_MMA_UNROLL(MICRO_COMPLEX_MMA_DST_PTR_ONE)
+
+#define MICRO_COMPLEX_MMA_SRC_PTR_ONE(iter) \
+ if (unroll_factor > iter) { \
+ lhs_ptr_real##iter = lhs_base + ( ((advanceRows*row)/accCols) + iter*advanceRows )*strideA*accCols + accCols*offsetA; \
+ if(!LhsIsReal) { \
+ lhs_ptr_imag##iter = lhs_ptr_real##iter + accCols*strideA; \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhs_ptr_imag##iter); \
+ } \
+ } else { \
+ EIGEN_UNUSED_VARIABLE(lhs_ptr_real##iter); \
+ EIGEN_UNUSED_VARIABLE(lhs_ptr_imag##iter); \
+ }
+
+#define MICRO_COMPLEX_MMA_SRC_PTR MICRO_COMPLEX_MMA_UNROLL(MICRO_COMPLEX_MMA_SRC_PTR_ONE)
+
+#define MICRO_COMPLEX_MMA_PREFETCH_ONE(iter) \
+ if (unroll_factor > iter) { \
+ EIGEN_POWER_PREFETCH(lhs_ptr_real##iter); \
+ if(!LhsIsReal) { \
+ EIGEN_POWER_PREFETCH(lhs_ptr_imag##iter); \
+ } \
+ }
+
+#define MICRO_COMPLEX_MMA_PREFETCH MICRO_COMPLEX_MMA_UNROLL(MICRO_COMPLEX_MMA_PREFETCH_ONE)
+
+#define MICRO_COMPLEX_MMA_STORE_ONE(iter) \
+ if (unroll_factor > iter) { \
+ storeComplexAccumulator<DataMapper, Index, Packet, Packetc, accColsC, 0>(row + iter*accCols, col, res, pAlphaReal, pAlphaImag, &accReal##iter, &accImag##iter); \
+ }
+
+#define MICRO_COMPLEX_MMA_STORE MICRO_COMPLEX_MMA_UNROLL(MICRO_COMPLEX_MMA_STORE_ONE)
+
+template<int unroll_factor, typename Scalar, typename Packet, typename Packetc, typename RhsPacket, typename DataMapper, typename Index, const Index accRows, const Index accCols, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+EIGEN_STRONG_INLINE void gemm_complex_unrolled_MMA_iteration(
+ const DataMapper& res,
+ const Scalar* lhs_base,
+ const Scalar* rhs_base,
+ Index depth,
+ Index strideA,
+ Index offsetA,
+ Index strideB,
+ Index& row,
+ Index col,
+ const Packet& pAlphaReal,
+ const Packet& pAlphaImag)
+{
+ const Scalar* rhs_ptr_real = rhs_base;
+ const Scalar* rhs_ptr_imag;
+ if(!RhsIsReal) {
+ rhs_ptr_imag = rhs_base + accRows*strideB;
+ } else {
+ EIGEN_UNUSED_VARIABLE(rhs_ptr_imag);
+ }
+ const Scalar* lhs_ptr_real0 = NULL, * lhs_ptr_imag0 = NULL, * lhs_ptr_real1 = NULL, * lhs_ptr_imag1 = NULL;
+ const Scalar* lhs_ptr_real2 = NULL, * lhs_ptr_imag2 = NULL, * lhs_ptr_real3 = NULL, * lhs_ptr_imag3 = NULL;
+ const Scalar* lhs_ptr_real4 = NULL, * lhs_ptr_imag4 = NULL;
+ __vector_quad accReal0, accImag0, accReal1, accImag1, accReal2, accImag2, accReal3, accImag3, accReal4, accImag4;
+
+ MICRO_COMPLEX_MMA_SRC_PTR
+ MICRO_COMPLEX_MMA_DST_PTR
+
+ Index k = 0;
+ for(; k + PEEL_COMPLEX_MMA <= depth; k+= PEEL_COMPLEX_MMA)
+ {
+ EIGEN_POWER_PREFETCH(rhs_ptr_real);
+ if(!RhsIsReal) {
+ EIGEN_POWER_PREFETCH(rhs_ptr_imag);
+ }
+ MICRO_COMPLEX_MMA_PREFETCH
+ MICRO_COMPLEX_MMA_ONE_PEEL
+ }
+ for(; k < depth; k++)
+ {
+ MICRO_COMPLEX_MMA_ONE
+ }
+ MICRO_COMPLEX_MMA_STORE
+
+ row += unroll_factor*accCols;
+}
+
+template<typename LhsScalar, typename RhsScalar, typename Scalarc, typename Scalar, typename Index, typename Packet, typename Packetc, typename RhsPacket, typename DataMapper, const Index accRows, const Index accCols, bool ConjugateLhs, bool ConjugateRhs, bool LhsIsReal, bool RhsIsReal>
+void gemm_complexMMA(const DataMapper& res, const LhsScalar* blockAc, const RhsScalar* blockBc, Index rows, Index depth, Index cols, Scalarc alpha, Index strideA, Index strideB, Index offsetA, Index offsetB)
+{
+ const Index remaining_rows = rows % accCols;
+ const Index remaining_cols = cols % accRows;
+
+ if( strideA == -1 ) strideA = depth;
+ if( strideB == -1 ) strideB = depth;
+
+ const Packet pAlphaReal = pset1<Packet>(alpha.real());
+ const Packet pAlphaImag = pset1<Packet>(alpha.imag());
+ const Packet pMask = bmask<Packet>((const int)(remaining_rows));
+
+ const Scalar* blockA = (Scalar *) blockAc;
+ const Scalar* blockB = (Scalar *) blockBc;
+
+ Index col = 0;
+ for(; col + accRows <= cols; col += accRows)
+ {
+ const Scalar* rhs_base = blockB + advanceCols*col*strideB + accRows*offsetB;
+ const Scalar* lhs_base = blockA;
+ Index row = 0;
+
+#define MAX_COMPLEX_MMA_UNROLL 4
+ while(row + MAX_COMPLEX_MMA_UNROLL*accCols <= rows) {
+ gemm_complex_unrolled_MMA_iteration<MAX_COMPLEX_MMA_UNROLL, Scalar, Packet, Packetc, RhsPacket, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, pAlphaReal, pAlphaImag);
+ }
+ switch( (rows-row)/accCols ) {
+#if MAX_COMPLEX_MMA_UNROLL > 4
+ case 4:
+ gemm_complex_unrolled_MMA_iteration<4, Scalar, Packet, Packetc, RhsPacket, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, pAlphaReal, pAlphaImag);
+ break;
+#endif
+#if MAX_COMPLEX_MMA_UNROLL > 3
+ case 3:
+ gemm_complex_unrolled_MMA_iteration<3, Scalar, Packet, Packetc, RhsPacket, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, pAlphaReal, pAlphaImag);
+ break;
+#endif
+#if MAX_COMPLEX_MMA_UNROLL > 2
+ case 2:
+ gemm_complex_unrolled_MMA_iteration<2, Scalar, Packet, Packetc, RhsPacket, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, pAlphaReal, pAlphaImag);
+ break;
+#endif
+#if MAX_COMPLEX_MMA_UNROLL > 1
+ case 1:
+ gemm_complex_unrolled_MMA_iteration<1, Scalar, Packet, Packetc, RhsPacket, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, pAlphaReal, pAlphaImag);
+ break;
+#endif
+ default:
+ break;
+ }
+#undef MAX_COMPLEX_MMA_UNROLL
+
+ if(remaining_rows > 0)
+ {
+ gemm_complex_extra_row<Scalar, Packet, Packetc, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, rows, cols, remaining_rows, pAlphaReal, pAlphaImag, pMask);
+ }
+ }
+
+ if(remaining_cols > 0)
+ {
+ const Scalar* rhs_base = blockB + advanceCols*col*strideB + remaining_cols*offsetB;
+ const Scalar* lhs_base = blockA;
+
+ for(; col < cols; col++)
+ {
+ Index row = 0;
+
+ gemm_complex_unrolled_col<Scalar, Packet, Packetc, DataMapper, Index, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, rows, col, remaining_cols, pAlphaReal, pAlphaImag);
+
+ if (remaining_rows > 0)
+ {
+ gemm_complex_extra_col<Scalar, Packet, Packetc, DataMapper, Index, accRows, accCols, ConjugateLhs, ConjugateRhs, LhsIsReal, RhsIsReal>(res, lhs_base, rhs_base, depth, strideA, offsetA, strideB, row, col, remaining_rows, remaining_cols, pAlphaReal, pAlphaImag);
+ }
+ rhs_base++;
+ }
+ }
+}
+
+#undef accColsC
+#undef advanceRows
+#undef advanceCols
+
+#pragma GCC reset_options
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATRIX_PRODUCT_MMA_ALTIVEC_H
+
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h
new file mode 100644
index 000000000..2a440545b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h
@@ -0,0 +1,2711 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2016 Konstantinos Margaritis <markos@freevec.org>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PACKET_MATH_ALTIVEC_H
+#define EIGEN_PACKET_MATH_ALTIVEC_H
+
+namespace Eigen {
+
+namespace internal {
+
+#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
+#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 4
+#endif
+
+#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#endif
+
+// NOTE Altivec has 32 registers, but Eigen only accepts a value of 8 or 16
+#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS
+#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32
+#endif
+
+typedef __vector float Packet4f;
+typedef __vector int Packet4i;
+typedef __vector unsigned int Packet4ui;
+typedef __vector __bool int Packet4bi;
+typedef __vector short int Packet8s;
+typedef __vector unsigned short int Packet8us;
+typedef __vector signed char Packet16c;
+typedef __vector unsigned char Packet16uc;
+typedef eigen_packet_wrapper<__vector unsigned short int,0> Packet8bf;
+
+// We don't want to write the same code all the time, but we need to reuse the constants
+// and it doesn't really work to declare them global, so we define macros instead
+#define _EIGEN_DECLARE_CONST_FAST_Packet4f(NAME,X) \
+ Packet4f p4f_##NAME = {X, X, X, X}
+
+#define _EIGEN_DECLARE_CONST_FAST_Packet4i(NAME,X) \
+ Packet4i p4i_##NAME = vec_splat_s32(X)
+
+#define _EIGEN_DECLARE_CONST_FAST_Packet4ui(NAME,X) \
+ Packet4ui p4ui_##NAME = {X, X, X, X}
+
+#define _EIGEN_DECLARE_CONST_FAST_Packet8us(NAME,X) \
+ Packet8us p8us_##NAME = {X, X, X, X, X, X, X, X}
+
+#define _EIGEN_DECLARE_CONST_FAST_Packet16uc(NAME,X) \
+ Packet16uc p16uc_##NAME = {X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X}
+
+#define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \
+ Packet4f p4f_##NAME = pset1<Packet4f>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \
+ Packet4i p4i_##NAME = pset1<Packet4i>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet2d(NAME,X) \
+ Packet2d p2d_##NAME = pset1<Packet2d>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet2l(NAME,X) \
+ Packet2l p2l_##NAME = pset1<Packet2l>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \
+ const Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(pset1<Packet4i>(X))
+
+#define DST_CHAN 1
+#define DST_CTRL(size, count, stride) (((size) << 24) | ((count) << 16) | (stride))
+#define __UNPACK_TYPE__(PACKETNAME) typename unpacket_traits<PACKETNAME>::type
+
+// These constants are endian-agnostic
+static _EIGEN_DECLARE_CONST_FAST_Packet4f(ZERO, 0); //{ 0.0, 0.0, 0.0, 0.0}
+static _EIGEN_DECLARE_CONST_FAST_Packet4i(ZERO, 0); //{ 0, 0, 0, 0,}
+static _EIGEN_DECLARE_CONST_FAST_Packet4i(ONE,1); //{ 1, 1, 1, 1}
+static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS16,-16); //{ -16, -16, -16, -16}
+static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS1,-1); //{ -1, -1, -1, -1}
+static _EIGEN_DECLARE_CONST_FAST_Packet4ui(SIGN, 0x80000000u);
+static _EIGEN_DECLARE_CONST_FAST_Packet4ui(PREV0DOT5, 0x3EFFFFFFu);
+static _EIGEN_DECLARE_CONST_FAST_Packet8us(ONE,1); //{ 1, 1, 1, 1, 1, 1, 1, 1}
+static _EIGEN_DECLARE_CONST_FAST_Packet16uc(ONE,1);
+static Packet4f p4f_MZERO = (Packet4f) vec_sl((Packet4ui)p4i_MINUS1, (Packet4ui)p4i_MINUS1); //{ 0x80000000, 0x80000000, 0x80000000, 0x80000000}
+#ifndef __VSX__
+static Packet4f p4f_ONE = vec_ctf(p4i_ONE, 0); //{ 1.0, 1.0, 1.0, 1.0}
+#endif
+
+static Packet4f p4f_COUNTDOWN = { 0.0, 1.0, 2.0, 3.0 };
+static Packet4i p4i_COUNTDOWN = { 0, 1, 2, 3 };
+static Packet8s p8s_COUNTDOWN = { 0, 1, 2, 3, 4, 5, 6, 7 };
+static Packet8us p8us_COUNTDOWN = { 0, 1, 2, 3, 4, 5, 6, 7 };
+
+static Packet16c p16c_COUNTDOWN = { 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15};
+static Packet16uc p16uc_COUNTDOWN = { 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15};
+
+static Packet16uc p16uc_REVERSE32 = { 12,13,14,15, 8,9,10,11, 4,5,6,7, 0,1,2,3 };
+static Packet16uc p16uc_REVERSE16 = { 14,15, 12,13, 10,11, 8,9, 6,7, 4,5, 2,3, 0,1 };
+static Packet16uc p16uc_REVERSE8 = { 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };
+
+static Packet16uc p16uc_DUPLICATE32_HI = { 0,1,2,3, 0,1,2,3, 4,5,6,7, 4,5,6,7 };
+static Packet16uc p16uc_DUPLICATE16_HI = { 0,1,0,1, 2,3,2,3, 4,5,4,5, 6,7,6,7 };
+static Packet16uc p16uc_DUPLICATE8_HI = { 0,0, 1,1, 2,2, 3,3, 4,4, 5,5, 6,6, 7,7 };
+static const Packet16uc p16uc_DUPLICATE16_EVEN= { 0,1 ,0,1, 4,5, 4,5, 8,9, 8,9, 12,13, 12,13 };
+static const Packet16uc p16uc_DUPLICATE16_ODD = { 2,3 ,2,3, 6,7, 6,7, 10,11, 10,11, 14,15, 14,15 };
+
+static Packet16uc p16uc_QUADRUPLICATE16_HI = { 0,1,0,1,0,1,0,1, 2,3,2,3,2,3,2,3 };
+
+// Handle endianness properly while loading constants
+// Define global static constants:
+#ifdef _BIG_ENDIAN
+static Packet16uc p16uc_FORWARD = vec_lvsl(0, (float*)0);
+#ifdef __VSX__
+static Packet16uc p16uc_REVERSE64 = { 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 };
+#endif
+static Packet16uc p16uc_PSET32_WODD = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 2), 8);//{ 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 };
+static Packet16uc p16uc_PSET32_WEVEN = vec_sld(p16uc_DUPLICATE32_HI, (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 3), 8);//{ 4,5,6,7, 4,5,6,7, 12,13,14,15, 12,13,14,15 };
+static Packet16uc p16uc_HALF64_0_16 = vec_sld((Packet16uc)p4i_ZERO, vec_splat((Packet16uc) vec_abs(p4i_MINUS16), 3), 8); //{ 0,0,0,0, 0,0,0,0, 16,16,16,16, 16,16,16,16};
+#else
+static Packet16uc p16uc_FORWARD = p16uc_REVERSE32;
+static Packet16uc p16uc_REVERSE64 = { 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 };
+static Packet16uc p16uc_PSET32_WODD = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 1), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 3), 8);//{ 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 };
+static Packet16uc p16uc_PSET32_WEVEN = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 2), 8);//{ 4,5,6,7, 4,5,6,7, 12,13,14,15, 12,13,14,15 };
+static Packet16uc p16uc_HALF64_0_16 = vec_sld(vec_splat((Packet16uc) vec_abs(p4i_MINUS16), 0), (Packet16uc)p4i_ZERO, 8); //{ 0,0,0,0, 0,0,0,0, 16,16,16,16, 16,16,16,16};
+#endif // _BIG_ENDIAN
+
+static Packet16uc p16uc_PSET64_HI = (Packet16uc) vec_mergeh((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 };
+static Packet16uc p16uc_PSET64_LO = (Packet16uc) vec_mergel((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 8,9,10,11, 12,13,14,15, 8,9,10,11, 12,13,14,15 };
+static Packet16uc p16uc_TRANSPOSE64_HI = p16uc_PSET64_HI + p16uc_HALF64_0_16; //{ 0,1,2,3, 4,5,6,7, 16,17,18,19, 20,21,22,23};
+static Packet16uc p16uc_TRANSPOSE64_LO = p16uc_PSET64_LO + p16uc_HALF64_0_16; //{ 8,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31};
+
+static Packet16uc p16uc_COMPLEX32_REV = vec_sld(p16uc_REVERSE32, p16uc_REVERSE32, 8); //{ 4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11 };
+
+#ifdef _BIG_ENDIAN
+static Packet16uc p16uc_COMPLEX32_REV2 = vec_sld(p16uc_FORWARD, p16uc_FORWARD, 8); //{ 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 };
+#else
+static Packet16uc p16uc_COMPLEX32_REV2 = vec_sld(p16uc_PSET64_HI, p16uc_PSET64_LO, 8); //{ 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 };
+#endif // _BIG_ENDIAN
+
+#if EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC
+ #define EIGEN_PPC_PREFETCH(ADDR) __builtin_prefetch(ADDR);
+#else
+ #define EIGEN_PPC_PREFETCH(ADDR) asm( " dcbt [%[addr]]\n" :: [addr] "r" (ADDR) : "cc" );
+#endif
+
+template <>
+struct packet_traits<float> : default_packet_traits {
+ typedef Packet4f type;
+ typedef Packet4f half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasAbs = 1,
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+ HasLog = 1,
+ HasExp = 1,
+#ifdef __VSX__
+ HasSqrt = 1,
+#if !EIGEN_COMP_CLANG
+ HasRsqrt = 1,
+#else
+ HasRsqrt = 0,
+#endif
+#else
+ HasSqrt = 0,
+ HasRsqrt = 0,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+#endif
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1,
+ HasNegate = 1,
+ HasBlend = 1
+ };
+};
+template <>
+struct packet_traits<bfloat16> : default_packet_traits {
+ typedef Packet8bf type;
+ typedef Packet8bf half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 8,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasAbs = 1,
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+ HasLog = 1,
+ HasExp = 1,
+#ifdef __VSX__
+ HasSqrt = 1,
+#if !EIGEN_COMP_CLANG
+ HasRsqrt = 1,
+#else
+ HasRsqrt = 0,
+#endif
+#else
+ HasSqrt = 0,
+ HasRsqrt = 0,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+#endif
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1,
+ HasNegate = 1,
+ HasBlend = 1
+ };
+};
+
+template <>
+struct packet_traits<int> : default_packet_traits {
+ typedef Packet4i type;
+ typedef Packet4i half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasDiv = 0,
+ HasBlend = 1
+ };
+};
+
+template <>
+struct packet_traits<short int> : default_packet_traits {
+ typedef Packet8s type;
+ typedef Packet8s half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 8,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 0,
+ HasBlend = 1
+ };
+};
+
+template <>
+struct packet_traits<unsigned short int> : default_packet_traits {
+ typedef Packet8us type;
+ typedef Packet8us half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 8,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 0,
+ HasBlend = 1
+ };
+};
+
+template <>
+struct packet_traits<signed char> : default_packet_traits {
+ typedef Packet16c type;
+ typedef Packet16c half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 16,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 0,
+ HasBlend = 1
+ };
+};
+
+template <>
+struct packet_traits<unsigned char> : default_packet_traits {
+ typedef Packet16uc type;
+ typedef Packet16uc half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 16,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 0,
+ HasBlend = 1
+ };
+};
+
+template<> struct unpacket_traits<Packet4f>
+{
+ typedef float type;
+ typedef Packet4f half;
+ typedef Packet4i integer_packet;
+ enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+template<> struct unpacket_traits<Packet4i>
+{
+ typedef int type;
+ typedef Packet4i half;
+ enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+template<> struct unpacket_traits<Packet8s>
+{
+ typedef short int type;
+ typedef Packet8s half;
+ enum {size=8, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+template<> struct unpacket_traits<Packet8us>
+{
+ typedef unsigned short int type;
+ typedef Packet8us half;
+ enum {size=8, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+
+template<> struct unpacket_traits<Packet16c>
+{
+ typedef signed char type;
+ typedef Packet16c half;
+ enum {size=16, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+template<> struct unpacket_traits<Packet16uc>
+{
+ typedef unsigned char type;
+ typedef Packet16uc half;
+ enum {size=16, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+
+template<> struct unpacket_traits<Packet8bf>
+{
+ typedef bfloat16 type;
+ typedef Packet8bf half;
+ enum {size=8, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+inline std::ostream & operator <<(std::ostream & s, const Packet16c & v)
+{
+ union {
+ Packet16c v;
+ signed char n[16];
+ } vt;
+ vt.v = v;
+ for (int i=0; i< 16; i++)
+ s << vt.n[i] << ", ";
+ return s;
+}
+
+inline std::ostream & operator <<(std::ostream & s, const Packet16uc & v)
+{
+ union {
+ Packet16uc v;
+ unsigned char n[16];
+ } vt;
+ vt.v = v;
+ for (int i=0; i< 16; i++)
+ s << vt.n[i] << ", ";
+ return s;
+}
+
+inline std::ostream & operator <<(std::ostream & s, const Packet4f & v)
+{
+ union {
+ Packet4f v;
+ float n[4];
+ } vt;
+ vt.v = v;
+ s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3];
+ return s;
+}
+
+inline std::ostream & operator <<(std::ostream & s, const Packet4i & v)
+{
+ union {
+ Packet4i v;
+ int n[4];
+ } vt;
+ vt.v = v;
+ s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3];
+ return s;
+}
+
+inline std::ostream & operator <<(std::ostream & s, const Packet4ui & v)
+{
+ union {
+ Packet4ui v;
+ unsigned int n[4];
+ } vt;
+ vt.v = v;
+ s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3];
+ return s;
+}
+
+template <typename Packet>
+EIGEN_STRONG_INLINE Packet pload_common(const __UNPACK_TYPE__(Packet)* from)
+{
+ // some versions of GCC throw "unused-but-set-parameter".
+ // ignoring these warnings for now.
+ EIGEN_UNUSED_VARIABLE(from);
+ EIGEN_DEBUG_ALIGNED_LOAD
+#ifdef __VSX__
+ return vec_xl(0, const_cast<__UNPACK_TYPE__(Packet)*>(from));
+#else
+ return vec_ld(0, from);
+#endif
+}
+
+// Need to define them first or we get specialization after instantiation errors
+template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from)
+{
+ return pload_common<Packet4f>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from)
+{
+ return pload_common<Packet4i>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8s pload<Packet8s>(const short int* from)
+{
+ return pload_common<Packet8s>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8us pload<Packet8us>(const unsigned short int* from)
+{
+ return pload_common<Packet8us>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16c pload<Packet16c>(const signed char* from)
+{
+ return pload_common<Packet16c>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16uc pload<Packet16uc>(const unsigned char* from)
+{
+ return pload_common<Packet16uc>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pload<Packet8bf>(const bfloat16* from)
+{
+ return pload_common<Packet8us>(reinterpret_cast<const unsigned short int*>(from));
+}
+
+template <typename Packet>
+EIGEN_STRONG_INLINE void pstore_common(__UNPACK_TYPE__(Packet)* to, const Packet& from){
+ // some versions of GCC throw "unused-but-set-parameter" (float *to).
+ // ignoring these warnings for now.
+ EIGEN_UNUSED_VARIABLE(to);
+ EIGEN_DEBUG_ALIGNED_STORE
+#ifdef __VSX__
+ vec_xst(from, 0, to);
+#else
+ vec_st(from, 0, to);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from)
+{
+ pstore_common<Packet4f>(to, from);
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet4i& from)
+{
+ pstore_common<Packet4i>(to, from);
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<short int>(short int* to, const Packet8s& from)
+{
+ pstore_common<Packet8s>(to, from);
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<unsigned short int>(unsigned short int* to, const Packet8us& from)
+{
+ pstore_common<Packet8us>(to, from);
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<bfloat16>(bfloat16* to, const Packet8bf& from)
+{
+ pstore_common<Packet8us>(reinterpret_cast<unsigned short int*>(to), from);
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<signed char>(signed char* to, const Packet16c& from)
+{
+ pstore_common<Packet16c>(to, from);
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<unsigned char>(unsigned char* to, const Packet16uc& from)
+{
+ pstore_common<Packet16uc>(to, from);
+}
+
+template<typename Packet>
+EIGEN_STRONG_INLINE Packet pset1_size4(const __UNPACK_TYPE__(Packet)& from)
+{
+ Packet v = {from, from, from, from};
+ return v;
+}
+
+template<typename Packet>
+EIGEN_STRONG_INLINE Packet pset1_size8(const __UNPACK_TYPE__(Packet)& from)
+{
+ Packet v = {from, from, from, from, from, from, from, from};
+ return v;
+}
+
+template<typename Packet>
+EIGEN_STRONG_INLINE Packet pset1_size16(const __UNPACK_TYPE__(Packet)& from)
+{
+ Packet v = {from, from, from, from, from, from, from, from, from, from, from, from, from, from, from, from};
+ return v;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) {
+ return pset1_size4<Packet4f>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from) {
+ return pset1_size4<Packet4i>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8s pset1<Packet8s>(const short int& from) {
+ return pset1_size8<Packet8s>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8us pset1<Packet8us>(const unsigned short int& from) {
+ return pset1_size8<Packet8us>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16c pset1<Packet16c>(const signed char& from) {
+ return pset1_size16<Packet16c>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16uc pset1<Packet16uc>(const unsigned char& from) {
+ return pset1_size16<Packet16uc>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pset1frombits<Packet4f>(unsigned int from) {
+ return reinterpret_cast<Packet4f>(pset1<Packet4i>(from));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pset1<Packet8bf>(const bfloat16& from) {
+ return pset1_size8<Packet8us>(reinterpret_cast<const unsigned short int&>(from));
+}
+
+template<typename Packet> EIGEN_STRONG_INLINE void
+pbroadcast4_common(const __UNPACK_TYPE__(Packet) *a,
+ Packet& a0, Packet& a1, Packet& a2, Packet& a3)
+{
+ a3 = pload<Packet>(a);
+ a0 = vec_splat(a3, 0);
+ a1 = vec_splat(a3, 1);
+ a2 = vec_splat(a3, 2);
+ a3 = vec_splat(a3, 3);
+}
+
+template<> EIGEN_STRONG_INLINE void
+pbroadcast4<Packet4f>(const float *a,
+ Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3)
+{
+ pbroadcast4_common<Packet4f>(a, a0, a1, a2, a3);
+}
+template<> EIGEN_STRONG_INLINE void
+pbroadcast4<Packet4i>(const int *a,
+ Packet4i& a0, Packet4i& a1, Packet4i& a2, Packet4i& a3)
+{
+ pbroadcast4_common<Packet4i>(a, a0, a1, a2, a3);
+}
+
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet pgather_common(const __UNPACK_TYPE__(Packet)* from, Index stride)
+{
+ EIGEN_ALIGN16 __UNPACK_TYPE__(Packet) a[4];
+ a[0] = from[0*stride];
+ a[1] = from[1*stride];
+ a[2] = from[2*stride];
+ a[3] = from[3*stride];
+ return pload<Packet>(a);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride)
+{
+ return pgather_common<Packet4f>(from, stride);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet4i pgather<int, Packet4i>(const int* from, Index stride)
+{
+ return pgather_common<Packet4i>(from, stride);
+}
+
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet pgather_size8(const __UNPACK_TYPE__(Packet)* from, Index stride)
+{
+ EIGEN_ALIGN16 __UNPACK_TYPE__(Packet) a[8];
+ a[0] = from[0*stride];
+ a[1] = from[1*stride];
+ a[2] = from[2*stride];
+ a[3] = from[3*stride];
+ a[4] = from[4*stride];
+ a[5] = from[5*stride];
+ a[6] = from[6*stride];
+ a[7] = from[7*stride];
+ return pload<Packet>(a);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet8s pgather<short int, Packet8s>(const short int* from, Index stride)
+{
+ return pgather_size8<Packet8s>(from, stride);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet8us pgather<unsigned short int, Packet8us>(const unsigned short int* from, Index stride)
+{
+ return pgather_size8<Packet8us>(from, stride);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet8bf pgather<bfloat16, Packet8bf>(const bfloat16* from, Index stride)
+{
+ return pgather_size8<Packet8bf>(from, stride);
+}
+
+template<typename Packet> EIGEN_DEVICE_FUNC inline Packet pgather_size16(const __UNPACK_TYPE__(Packet)* from, Index stride)
+{
+ EIGEN_ALIGN16 __UNPACK_TYPE__(Packet) a[16];
+ a[0] = from[0*stride];
+ a[1] = from[1*stride];
+ a[2] = from[2*stride];
+ a[3] = from[3*stride];
+ a[4] = from[4*stride];
+ a[5] = from[5*stride];
+ a[6] = from[6*stride];
+ a[7] = from[7*stride];
+ a[8] = from[8*stride];
+ a[9] = from[9*stride];
+ a[10] = from[10*stride];
+ a[11] = from[11*stride];
+ a[12] = from[12*stride];
+ a[13] = from[13*stride];
+ a[14] = from[14*stride];
+ a[15] = from[15*stride];
+ return pload<Packet>(a);
+}
+
+
+template<> EIGEN_DEVICE_FUNC inline Packet16c pgather<signed char, Packet16c>(const signed char* from, Index stride)
+{
+ return pgather_size16<Packet16c>(from, stride);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet16uc pgather<unsigned char, Packet16uc>(const unsigned char* from, Index stride)
+{
+ return pgather_size16<Packet16uc>(from, stride);
+}
+
+template<typename Packet> EIGEN_DEVICE_FUNC inline void pscatter_size4(__UNPACK_TYPE__(Packet)* to, const Packet& from, Index stride)
+{
+ EIGEN_ALIGN16 __UNPACK_TYPE__(Packet) a[4];
+ pstore<__UNPACK_TYPE__(Packet)>(a, from);
+ to[0*stride] = a[0];
+ to[1*stride] = a[1];
+ to[2*stride] = a[2];
+ to[3*stride] = a[3];
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride)
+{
+ pscatter_size4<Packet4f>(to, from, stride);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<int, Packet4i>(int* to, const Packet4i& from, Index stride)
+{
+ pscatter_size4<Packet4i>(to, from, stride);
+}
+
+template<typename Packet> EIGEN_DEVICE_FUNC inline void pscatter_size8(__UNPACK_TYPE__(Packet)* to, const Packet& from, Index stride)
+{
+ EIGEN_ALIGN16 __UNPACK_TYPE__(Packet) a[8];
+ pstore<__UNPACK_TYPE__(Packet)>(a, from);
+ to[0*stride] = a[0];
+ to[1*stride] = a[1];
+ to[2*stride] = a[2];
+ to[3*stride] = a[3];
+ to[4*stride] = a[4];
+ to[5*stride] = a[5];
+ to[6*stride] = a[6];
+ to[7*stride] = a[7];
+}
+
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<short int, Packet8s>(short int* to, const Packet8s& from, Index stride)
+{
+ pscatter_size8<Packet8s>(to, from, stride);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<unsigned short int, Packet8us>(unsigned short int* to, const Packet8us& from, Index stride)
+{
+ pscatter_size8<Packet8us>(to, from, stride);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<bfloat16, Packet8bf>(bfloat16* to, const Packet8bf& from, Index stride)
+{
+ pscatter_size8<Packet8bf>(to, from, stride);
+}
+
+template<typename Packet> EIGEN_DEVICE_FUNC inline void pscatter_size16(__UNPACK_TYPE__(Packet)* to, const Packet& from, Index stride)
+{
+ EIGEN_ALIGN16 __UNPACK_TYPE__(Packet) a[16];
+ pstore<__UNPACK_TYPE__(Packet)>(a, from);
+ to[0*stride] = a[0];
+ to[1*stride] = a[1];
+ to[2*stride] = a[2];
+ to[3*stride] = a[3];
+ to[4*stride] = a[4];
+ to[5*stride] = a[5];
+ to[6*stride] = a[6];
+ to[7*stride] = a[7];
+ to[8*stride] = a[8];
+ to[9*stride] = a[9];
+ to[10*stride] = a[10];
+ to[11*stride] = a[11];
+ to[12*stride] = a[12];
+ to[13*stride] = a[13];
+ to[14*stride] = a[14];
+ to[15*stride] = a[15];
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<signed char, Packet16c>(signed char* to, const Packet16c& from, Index stride)
+{
+ pscatter_size16<Packet16c>(to, from, stride);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<unsigned char, Packet16uc>(unsigned char* to, const Packet16uc& from, Index stride)
+{
+ pscatter_size16<Packet16uc>(to, from, stride);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a) { return pset1<Packet4f>(a) + p4f_COUNTDOWN; }
+template<> EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int& a) { return pset1<Packet4i>(a) + p4i_COUNTDOWN; }
+template<> EIGEN_STRONG_INLINE Packet8s plset<Packet8s>(const short int& a) { return pset1<Packet8s>(a) + p8s_COUNTDOWN; }
+template<> EIGEN_STRONG_INLINE Packet8us plset<Packet8us>(const unsigned short int& a) { return pset1<Packet8us>(a) + p8us_COUNTDOWN; }
+template<> EIGEN_STRONG_INLINE Packet16c plset<Packet16c>(const signed char& a) { return pset1<Packet16c>(a) + p16c_COUNTDOWN; }
+template<> EIGEN_STRONG_INLINE Packet16uc plset<Packet16uc>(const unsigned char& a) { return pset1<Packet16uc>(a) + p16uc_COUNTDOWN; }
+
+template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f> (const Packet4f& a, const Packet4f& b) { return a + b; }
+template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i> (const Packet4i& a, const Packet4i& b) { return a + b; }
+template<> EIGEN_STRONG_INLINE Packet4ui padd<Packet4ui> (const Packet4ui& a, const Packet4ui& b) { return a + b; }
+template<> EIGEN_STRONG_INLINE Packet8s padd<Packet8s> (const Packet8s& a, const Packet8s& b) { return a + b; }
+template<> EIGEN_STRONG_INLINE Packet8us padd<Packet8us> (const Packet8us& a, const Packet8us& b) { return a + b; }
+template<> EIGEN_STRONG_INLINE Packet16c padd<Packet16c> (const Packet16c& a, const Packet16c& b) { return a + b; }
+template<> EIGEN_STRONG_INLINE Packet16uc padd<Packet16uc>(const Packet16uc& a, const Packet16uc& b) { return a + b; }
+
+template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f> (const Packet4f& a, const Packet4f& b) { return a - b; }
+template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i> (const Packet4i& a, const Packet4i& b) { return a - b; }
+template<> EIGEN_STRONG_INLINE Packet8s psub<Packet8s> (const Packet8s& a, const Packet8s& b) { return a - b; }
+template<> EIGEN_STRONG_INLINE Packet8us psub<Packet8us> (const Packet8us& a, const Packet8us& b) { return a - b; }
+template<> EIGEN_STRONG_INLINE Packet16c psub<Packet16c> (const Packet16c& a, const Packet16c& b) { return a - b; }
+template<> EIGEN_STRONG_INLINE Packet16uc psub<Packet16uc>(const Packet16uc& a, const Packet16uc& b) { return a - b; }
+
+template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) { return p4f_ZERO - a; }
+template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return p4i_ZERO - a; }
+
+template<> EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_madd(a,b, p4f_MZERO); }
+template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i> (const Packet4i& a, const Packet4i& b) { return a * b; }
+template<> EIGEN_STRONG_INLINE Packet8s pmul<Packet8s> (const Packet8s& a, const Packet8s& b) { return vec_mul(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pmul<Packet8us> (const Packet8us& a, const Packet8us& b) { return vec_mul(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c pmul<Packet16c> (const Packet16c& a, const Packet16c& b) { return vec_mul(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pmul<Packet16uc>(const Packet16uc& a, const Packet16uc& b) { return vec_mul(a,b); }
+
+
+template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+#ifndef __VSX__ // VSX actually provides a div instruction
+ Packet4f t, y_0, y_1;
+
+ // Altivec does not offer a divide instruction, we have to do a reciprocal approximation
+ y_0 = vec_re(b);
+
+ // Do one Newton-Raphson iteration to get the needed accuracy
+ t = vec_nmsub(y_0, b, p4f_ONE);
+ y_1 = vec_madd(y_0, t, y_0);
+
+ return vec_madd(a, y_1, p4f_MZERO);
+#else
+ return vec_div(a, b);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& /*a*/, const Packet4i& /*b*/)
+{ eigen_assert(false && "packet integer division are not supported by AltiVec");
+ return pset1<Packet4i>(0);
+}
+
+// for some weird raisons, it has to be overloaded for packet of integers
+template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) { return vec_madd(a,b,c); }
+template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { return a*b + c; }
+template<> EIGEN_STRONG_INLINE Packet8s pmadd(const Packet8s& a, const Packet8s& b, const Packet8s& c) { return vec_madd(a,b,c); }
+template<> EIGEN_STRONG_INLINE Packet8us pmadd(const Packet8us& a, const Packet8us& b, const Packet8us& c) { return vec_madd(a,b,c); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ #ifdef __VSX__
+ // NOTE: about 10% slower than vec_min, but consistent with std::min and SSE regarding NaN
+ Packet4f ret;
+ __asm__ ("xvcmpgesp %x0,%x1,%x2\n\txxsel %x0,%x1,%x2,%x0" : "=&wa" (ret) : "wa" (a), "wa" (b));
+ return ret;
+ #else
+ return vec_min(a, b);
+ #endif
+}
+template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_min(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8s pmin<Packet8s>(const Packet8s& a, const Packet8s& b) { return vec_min(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8us pmin<Packet8us>(const Packet8us& a, const Packet8us& b) { return vec_min(a, b); }
+template<> EIGEN_STRONG_INLINE Packet16c pmin<Packet16c>(const Packet16c& a, const Packet16c& b) { return vec_min(a, b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pmin<Packet16uc>(const Packet16uc& a, const Packet16uc& b) { return vec_min(a, b); }
+
+
+template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ #ifdef __VSX__
+ // NOTE: about 10% slower than vec_max, but consistent with std::max and SSE regarding NaN
+ Packet4f ret;
+ __asm__ ("xvcmpgtsp %x0,%x2,%x1\n\txxsel %x0,%x1,%x2,%x0" : "=&wa" (ret) : "wa" (a), "wa" (b));
+ return ret;
+ #else
+ return vec_max(a, b);
+ #endif
+}
+template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_max(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8s pmax<Packet8s>(const Packet8s& a, const Packet8s& b) { return vec_max(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8us pmax<Packet8us>(const Packet8us& a, const Packet8us& b) { return vec_max(a, b); }
+template<> EIGEN_STRONG_INLINE Packet16c pmax<Packet16c>(const Packet16c& a, const Packet16c& b) { return vec_max(a, b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pmax<Packet16uc>(const Packet16uc& a, const Packet16uc& b) { return vec_max(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_le(const Packet4f& a, const Packet4f& b) { return reinterpret_cast<Packet4f>(vec_cmple(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt(const Packet4f& a, const Packet4f& b) { return reinterpret_cast<Packet4f>(vec_cmplt(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_eq(const Packet4f& a, const Packet4f& b) { return reinterpret_cast<Packet4f>(vec_cmpeq(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt_or_nan(const Packet4f& a, const Packet4f& b) {
+ Packet4f c = reinterpret_cast<Packet4f>(vec_cmpge(a,b));
+ return vec_nor(c,c);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i pcmp_le(const Packet4i& a, const Packet4i& b) { return reinterpret_cast<Packet4i>(vec_cmple(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4i pcmp_lt(const Packet4i& a, const Packet4i& b) { return reinterpret_cast<Packet4i>(vec_cmplt(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4i pcmp_eq(const Packet4i& a, const Packet4i& b) { return reinterpret_cast<Packet4i>(vec_cmpeq(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet8s pcmp_le(const Packet8s& a, const Packet8s& b) { return reinterpret_cast<Packet8s>(vec_cmple(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet8s pcmp_lt(const Packet8s& a, const Packet8s& b) { return reinterpret_cast<Packet8s>(vec_cmplt(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet8s pcmp_eq(const Packet8s& a, const Packet8s& b) { return reinterpret_cast<Packet8s>(vec_cmpeq(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet8us pcmp_le(const Packet8us& a, const Packet8us& b) { return reinterpret_cast<Packet8us>(vec_cmple(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet8us pcmp_lt(const Packet8us& a, const Packet8us& b) { return reinterpret_cast<Packet8us>(vec_cmplt(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet8us pcmp_eq(const Packet8us& a, const Packet8us& b) { return reinterpret_cast<Packet8us>(vec_cmpeq(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet16c pcmp_le(const Packet16c& a, const Packet16c& b) { return reinterpret_cast<Packet16c>(vec_cmple(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet16c pcmp_lt(const Packet16c& a, const Packet16c& b) { return reinterpret_cast<Packet16c>(vec_cmplt(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet16c pcmp_eq(const Packet16c& a, const Packet16c& b) { return reinterpret_cast<Packet16c>(vec_cmpeq(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet16uc pcmp_le(const Packet16uc& a, const Packet16uc& b) { return reinterpret_cast<Packet16uc>(vec_cmple(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet16uc pcmp_lt(const Packet16uc& a, const Packet16uc& b) { return reinterpret_cast<Packet16uc>(vec_cmplt(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet16uc pcmp_eq(const Packet16uc& a, const Packet16uc& b) { return reinterpret_cast<Packet16uc>(vec_cmpeq(a,b)); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_and(a, b); }
+template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pand<Packet4ui>(const Packet4ui& a, const Packet4ui& b) { return vec_and(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8us pand<Packet8us>(const Packet8us& a, const Packet8us& b) { return vec_and(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8bf pand<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ return pand<Packet8us>(a, b);
+}
+
+
+template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_or(a, b); }
+template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_or(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8s por<Packet8s>(const Packet8s& a, const Packet8s& b) { return vec_or(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8us por<Packet8us>(const Packet8us& a, const Packet8us& b) { return vec_or(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8bf por<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ return por<Packet8us>(a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_xor(a, b); }
+template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_xor(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8bf pxor<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ return pxor<Packet8us>(a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_andc(a, b); }
+template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_andc(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pselect(const Packet4f& mask, const Packet4f& a, const Packet4f& b) {
+ return vec_sel(b, a, reinterpret_cast<Packet4ui>(mask));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a)
+{
+ Packet4f t = vec_add(reinterpret_cast<Packet4f>(vec_or(vec_and(reinterpret_cast<Packet4ui>(a), p4ui_SIGN), p4ui_PREV0DOT5)), a);
+ Packet4f res;
+
+#ifdef __VSX__
+ __asm__("xvrspiz %x0, %x1\n\t"
+ : "=&wa" (res)
+ : "wa" (t));
+#else
+ __asm__("vrfiz %0, %1\n\t"
+ : "=v" (res)
+ : "v" (t));
+#endif
+
+ return res;
+}
+template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) { return vec_ceil(a); }
+template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) { return vec_floor(a); }
+template<> EIGEN_STRONG_INLINE Packet4f print<Packet4f>(const Packet4f& a)
+{
+ Packet4f res;
+
+ __asm__("xvrspic %x0, %x1\n\t"
+ : "=&wa" (res)
+ : "wa" (a));
+
+ return res;
+}
+
+template<typename Packet> EIGEN_STRONG_INLINE Packet ploadu_common(const __UNPACK_TYPE__(Packet)* from)
+{
+ EIGEN_DEBUG_ALIGNED_LOAD
+#ifdef _BIG_ENDIAN
+ Packet16uc MSQ, LSQ;
+ Packet16uc mask;
+ MSQ = vec_ld(0, (unsigned char *)from); // most significant quadword
+ LSQ = vec_ld(15, (unsigned char *)from); // least significant quadword
+ mask = vec_lvsl(0, from); // create the permute mask
+ //TODO: Add static_cast here
+ return (Packet) vec_perm(MSQ, LSQ, mask); // align the data
+#else
+ EIGEN_DEBUG_UNALIGNED_LOAD
+ return vec_xl(0, const_cast<__UNPACK_TYPE__(Packet)*>(from));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from)
+{
+ return ploadu_common<Packet4f>(from);
+}
+template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from)
+{
+ return ploadu_common<Packet4i>(from);
+}
+template<> EIGEN_STRONG_INLINE Packet8s ploadu<Packet8s>(const short int* from)
+{
+ return ploadu_common<Packet8s>(from);
+}
+template<> EIGEN_STRONG_INLINE Packet8us ploadu<Packet8us>(const unsigned short int* from)
+{
+ return ploadu_common<Packet8us>(from);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf ploadu<Packet8bf>(const bfloat16* from)
+{
+ return ploadu_common<Packet8us>(reinterpret_cast<const unsigned short int*>(from));
+}
+template<> EIGEN_STRONG_INLINE Packet16c ploadu<Packet16c>(const signed char* from)
+{
+ return ploadu_common<Packet16c>(from);
+}
+template<> EIGEN_STRONG_INLINE Packet16uc ploadu<Packet16uc>(const unsigned char* from)
+{
+ return ploadu_common<Packet16uc>(from);
+}
+
+template<typename Packet> EIGEN_STRONG_INLINE Packet ploaddup_common(const __UNPACK_TYPE__(Packet)* from)
+{
+ Packet p;
+ if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet>(from);
+ else p = ploadu<Packet>(from);
+ return vec_perm(p, p, p16uc_DUPLICATE32_HI);
+}
+template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from)
+{
+ return ploaddup_common<Packet4f>(from);
+}
+template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int* from)
+{
+ return ploaddup_common<Packet4i>(from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8s ploaddup<Packet8s>(const short int* from)
+{
+ Packet8s p;
+ if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet8s>(from);
+ else p = ploadu<Packet8s>(from);
+ return vec_perm(p, p, p16uc_DUPLICATE16_HI);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8us ploaddup<Packet8us>(const unsigned short int* from)
+{
+ Packet8us p;
+ if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet8us>(from);
+ else p = ploadu<Packet8us>(from);
+ return vec_perm(p, p, p16uc_DUPLICATE16_HI);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8s ploadquad<Packet8s>(const short int* from)
+{
+ Packet8s p;
+ if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet8s>(from);
+ else p = ploadu<Packet8s>(from);
+ return vec_perm(p, p, p16uc_QUADRUPLICATE16_HI);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8us ploadquad<Packet8us>(const unsigned short int* from)
+{
+ Packet8us p;
+ if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet8us>(from);
+ else p = ploadu<Packet8us>(from);
+ return vec_perm(p, p, p16uc_QUADRUPLICATE16_HI);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf ploadquad<Packet8bf>(const bfloat16* from)
+{
+ return ploadquad<Packet8us>(reinterpret_cast<const unsigned short int*>(from));
+}
+
+template<> EIGEN_STRONG_INLINE Packet16c ploaddup<Packet16c>(const signed char* from)
+{
+ Packet16c p;
+ if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet16c>(from);
+ else p = ploadu<Packet16c>(from);
+ return vec_perm(p, p, p16uc_DUPLICATE8_HI);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16uc ploaddup<Packet16uc>(const unsigned char* from)
+{
+ Packet16uc p;
+ if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet16uc>(from);
+ else p = ploadu<Packet16uc>(from);
+ return vec_perm(p, p, p16uc_DUPLICATE8_HI);
+}
+
+template<typename Packet> EIGEN_STRONG_INLINE void pstoreu_common(__UNPACK_TYPE__(Packet)* to, const Packet& from)
+{
+ EIGEN_DEBUG_UNALIGNED_STORE
+#ifdef _BIG_ENDIAN
+ // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html
+ // Warning: not thread safe!
+ Packet16uc MSQ, LSQ, edges;
+ Packet16uc edgeAlign, align;
+
+ MSQ = vec_ld(0, (unsigned char *)to); // most significant quadword
+ LSQ = vec_ld(15, (unsigned char *)to); // least significant quadword
+ edgeAlign = vec_lvsl(0, to); // permute map to extract edges
+ edges=vec_perm(LSQ,MSQ,edgeAlign); // extract the edges
+ align = vec_lvsr( 0, to ); // permute map to misalign data
+ MSQ = vec_perm(edges,(Packet16uc)from,align); // misalign the data (MSQ)
+ LSQ = vec_perm((Packet16uc)from,edges,align); // misalign the data (LSQ)
+ vec_st( LSQ, 15, (unsigned char *)to ); // Store the LSQ part first
+ vec_st( MSQ, 0, (unsigned char *)to ); // Store the MSQ part second
+#else
+ vec_xst(from, 0, to);
+#endif
+}
+template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from)
+{
+ pstoreu_common<Packet4f>(to, from);
+}
+template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from)
+{
+ pstoreu_common<Packet4i>(to, from);
+}
+template<> EIGEN_STRONG_INLINE void pstoreu<short int>(short int* to, const Packet8s& from)
+{
+ pstoreu_common<Packet8s>(to, from);
+}
+template<> EIGEN_STRONG_INLINE void pstoreu<unsigned short int>(unsigned short int* to, const Packet8us& from)
+{
+ pstoreu_common<Packet8us>(to, from);
+}
+template<> EIGEN_STRONG_INLINE void pstoreu<bfloat16>(bfloat16* to, const Packet8bf& from)
+{
+ pstoreu_common<Packet8us>(reinterpret_cast<unsigned short int*>(to), from);
+}
+template<> EIGEN_STRONG_INLINE void pstoreu<signed char>(signed char* to, const Packet16c& from)
+{
+ pstoreu_common<Packet16c>(to, from);
+}
+template<> EIGEN_STRONG_INLINE void pstoreu<unsigned char>(unsigned char* to, const Packet16uc& from)
+{
+ pstoreu_common<Packet16uc>(to, from);
+}
+
+template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { EIGEN_PPC_PREFETCH(addr); }
+template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { EIGEN_PPC_PREFETCH(addr); }
+
+template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { EIGEN_ALIGN16 float x; vec_ste(a, 0, &x); return x; }
+template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { EIGEN_ALIGN16 int x; vec_ste(a, 0, &x); return x; }
+
+template<typename Packet> EIGEN_STRONG_INLINE __UNPACK_TYPE__(Packet) pfirst_common(const Packet& a) {
+ EIGEN_ALIGN16 __UNPACK_TYPE__(Packet) x;
+ vec_ste(a, 0, &x);
+ return x;
+}
+
+template<> EIGEN_STRONG_INLINE short int pfirst<Packet8s>(const Packet8s& a) {
+ return pfirst_common<Packet8s>(a);
+}
+
+template<> EIGEN_STRONG_INLINE unsigned short int pfirst<Packet8us>(const Packet8us& a) {
+ return pfirst_common<Packet8us>(a);
+}
+
+template<> EIGEN_STRONG_INLINE signed char pfirst<Packet16c>(const Packet16c& a)
+{
+ return pfirst_common<Packet16c>(a);
+}
+
+template<> EIGEN_STRONG_INLINE unsigned char pfirst<Packet16uc>(const Packet16uc& a)
+{
+ return pfirst_common<Packet16uc>(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a)
+{
+ return reinterpret_cast<Packet4f>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32));
+}
+template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a)
+{
+ return reinterpret_cast<Packet4i>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32));
+}
+template<> EIGEN_STRONG_INLINE Packet8s preverse(const Packet8s& a)
+{
+ return reinterpret_cast<Packet8s>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE16));
+}
+template<> EIGEN_STRONG_INLINE Packet8us preverse(const Packet8us& a)
+{
+ return reinterpret_cast<Packet8us>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE16));
+}
+template<> EIGEN_STRONG_INLINE Packet16c preverse(const Packet16c& a)
+{
+ return vec_perm(a, a, p16uc_REVERSE8);
+}
+template<> EIGEN_STRONG_INLINE Packet16uc preverse(const Packet16uc& a)
+{
+ return vec_perm(a, a, p16uc_REVERSE8);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf preverse(const Packet8bf& a)
+{
+ return preverse<Packet8us>(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a) { return vec_abs(a); }
+template<> EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a) { return vec_abs(a); }
+template<> EIGEN_STRONG_INLINE Packet8s pabs(const Packet8s& a) { return vec_abs(a); }
+template<> EIGEN_STRONG_INLINE Packet8us pabs(const Packet8us& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet16c pabs(const Packet16c& a) { return vec_abs(a); }
+template<> EIGEN_STRONG_INLINE Packet16uc pabs(const Packet16uc& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet8bf pabs(const Packet8bf& a) {
+ _EIGEN_DECLARE_CONST_FAST_Packet8us(abs_mask,0x7FFF);
+ return pand<Packet8us>(p8us_abs_mask, a);
+}
+
+template<int N> EIGEN_STRONG_INLINE Packet4i parithmetic_shift_right(const Packet4i& a)
+{ return vec_sra(a,reinterpret_cast<Packet4ui>(pset1<Packet4i>(N))); }
+template<int N> EIGEN_STRONG_INLINE Packet4i plogical_shift_right(const Packet4i& a)
+{ return vec_sr(a,reinterpret_cast<Packet4ui>(pset1<Packet4i>(N))); }
+template<int N> EIGEN_STRONG_INLINE Packet4i plogical_shift_left(const Packet4i& a)
+{ return vec_sl(a,reinterpret_cast<Packet4ui>(pset1<Packet4i>(N))); }
+template<int N> EIGEN_STRONG_INLINE Packet4f plogical_shift_left(const Packet4f& a)
+{
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(mask, N);
+ Packet4ui r = vec_sl(reinterpret_cast<Packet4ui>(a), p4ui_mask);
+ return reinterpret_cast<Packet4f>(r);
+}
+
+template<int N> EIGEN_STRONG_INLINE Packet4f plogical_shift_right(const Packet4f& a)
+{
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(mask, N);
+ Packet4ui r = vec_sr(reinterpret_cast<Packet4ui>(a), p4ui_mask);
+ return reinterpret_cast<Packet4f>(r);
+}
+
+template<int N> EIGEN_STRONG_INLINE Packet4ui plogical_shift_right(const Packet4ui& a)
+{
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(mask, N);
+ return vec_sr(a, p4ui_mask);
+}
+
+template<int N> EIGEN_STRONG_INLINE Packet4ui plogical_shift_left(const Packet4ui& a)
+{
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(mask, N);
+ return vec_sl(a, p4ui_mask);
+}
+
+template<int N> EIGEN_STRONG_INLINE Packet8us plogical_shift_left(const Packet8us& a)
+{
+ const _EIGEN_DECLARE_CONST_FAST_Packet8us(mask, N);
+ return vec_sl(a, p8us_mask);
+}
+template<int N> EIGEN_STRONG_INLINE Packet8us plogical_shift_right(const Packet8us& a)
+{
+ const _EIGEN_DECLARE_CONST_FAST_Packet8us(mask, N);
+ return vec_sr(a, p8us_mask);
+}
+
+EIGEN_STRONG_INLINE Packet4f Bf16ToF32Even(const Packet8bf& bf){
+ return plogical_shift_left<16>(reinterpret_cast<Packet4f>(bf.m_val));
+}
+
+EIGEN_STRONG_INLINE Packet4f Bf16ToF32Odd(const Packet8bf& bf){
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(high_mask, 0xFFFF0000);
+ return pand<Packet4f>(
+ reinterpret_cast<Packet4f>(bf.m_val),
+ reinterpret_cast<Packet4f>(p4ui_high_mask)
+ );
+}
+
+// Simple interleaving of bool masks, prevents true values from being
+// converted to NaNs.
+EIGEN_STRONG_INLINE Packet8bf F32ToBf16Bool(Packet4f even, Packet4f odd) {
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(high_mask, 0xFFFF0000);
+ Packet4f bf_odd, bf_even;
+ bf_odd = pand(reinterpret_cast<Packet4f>(p4ui_high_mask), odd);
+ bf_even = plogical_shift_right<16>(even);
+ return reinterpret_cast<Packet8us>(por<Packet4f>(bf_even, bf_odd));
+}
+
+EIGEN_STRONG_INLINE Packet8bf F32ToBf16(Packet4f p4f){
+ Packet4ui input = reinterpret_cast<Packet4ui>(p4f);
+ Packet4ui lsb = plogical_shift_right<16>(input);
+ lsb = pand<Packet4ui>(lsb, reinterpret_cast<Packet4ui>(p4i_ONE));
+
+ _EIGEN_DECLARE_CONST_FAST_Packet4ui(BIAS,0x7FFFu);
+ Packet4ui rounding_bias = padd<Packet4ui>(lsb, p4ui_BIAS);
+ input = padd<Packet4ui>(input, rounding_bias);
+
+ //Test NaN and Subnormal - Begin
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(exp_mask, 0x7F800000);
+ Packet4ui exp = pand<Packet4ui>(p4ui_exp_mask, reinterpret_cast<Packet4ui>(p4f));
+
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(mantissa_mask, 0x7FFFFF);
+ Packet4ui mantissa = pand<Packet4ui>(p4ui_mantissa_mask, reinterpret_cast<Packet4ui>(p4f));
+
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(max_exp, 0x7F800000);
+ Packet4bi is_max_exp = vec_cmpeq(exp, p4ui_max_exp);
+ Packet4bi is_zero_exp = vec_cmpeq(exp, reinterpret_cast<Packet4ui>(p4i_ZERO));
+
+ Packet4bi is_mant_zero = vec_cmpeq(mantissa, reinterpret_cast<Packet4ui>(p4i_ZERO));
+ Packet4ui nan_selector = pandnot<Packet4ui>(
+ reinterpret_cast<Packet4ui>(is_max_exp),
+ reinterpret_cast<Packet4ui>(is_mant_zero)
+ );
+
+ Packet4ui subnormal_selector = pandnot<Packet4ui>(
+ reinterpret_cast<Packet4ui>(is_zero_exp),
+ reinterpret_cast<Packet4ui>(is_mant_zero)
+ );
+
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(nan, 0x7FC00000);
+ input = vec_sel(input, p4ui_nan, nan_selector);
+ input = vec_sel(input, reinterpret_cast<Packet4ui>(p4f), subnormal_selector);
+ //Test NaN and Subnormal - End
+
+ input = plogical_shift_right<16>(input);
+ return reinterpret_cast<Packet8us>(input);
+}
+
+EIGEN_STRONG_INLINE Packet8bf F32ToBf16(Packet4f even, Packet4f odd){
+ Packet4f bf_odd, bf_even;
+ bf_odd = reinterpret_cast<Packet4f>(F32ToBf16(odd).m_val);
+ bf_odd = plogical_shift_left<16>(bf_odd);
+ bf_even = reinterpret_cast<Packet4f>(F32ToBf16(even).m_val);
+ return reinterpret_cast<Packet8us>(por<Packet4f>(bf_even, bf_odd));
+}
+#define BF16_TO_F32_UNARY_OP_WRAPPER(OP, A) \
+ Packet4f a_even = Bf16ToF32Even(A);\
+ Packet4f a_odd = Bf16ToF32Odd(A);\
+ Packet4f op_even = OP(a_even);\
+ Packet4f op_odd = OP(a_odd);\
+ return F32ToBf16(op_even, op_odd);\
+
+#define BF16_TO_F32_BINARY_OP_WRAPPER(OP, A, B) \
+ Packet4f a_even = Bf16ToF32Even(A);\
+ Packet4f a_odd = Bf16ToF32Odd(A);\
+ Packet4f b_even = Bf16ToF32Even(B);\
+ Packet4f b_odd = Bf16ToF32Odd(B);\
+ Packet4f op_even = OP(a_even, b_even);\
+ Packet4f op_odd = OP(a_odd, b_odd);\
+ return F32ToBf16(op_even, op_odd);\
+
+#define BF16_TO_F32_BINARY_OP_WRAPPER_BOOL(OP, A, B) \
+ Packet4f a_even = Bf16ToF32Even(A);\
+ Packet4f a_odd = Bf16ToF32Odd(A);\
+ Packet4f b_even = Bf16ToF32Even(B);\
+ Packet4f b_odd = Bf16ToF32Odd(B);\
+ Packet4f op_even = OP(a_even, b_even);\
+ Packet4f op_odd = OP(a_odd, b_odd);\
+ return F32ToBf16Bool(op_even, op_odd);\
+
+template<> EIGEN_STRONG_INLINE Packet8bf padd<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ BF16_TO_F32_BINARY_OP_WRAPPER(padd<Packet4f>, a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pmul<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ BF16_TO_F32_BINARY_OP_WRAPPER(pmul<Packet4f>, a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pdiv<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ BF16_TO_F32_BINARY_OP_WRAPPER(pdiv<Packet4f>, a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pnegate<Packet8bf>(const Packet8bf& a) {
+ BF16_TO_F32_UNARY_OP_WRAPPER(pnegate<Packet4f>, a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf psub<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ BF16_TO_F32_BINARY_OP_WRAPPER(psub<Packet4f>, a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf psqrt<Packet8bf> (const Packet8bf& a){
+ BF16_TO_F32_UNARY_OP_WRAPPER(vec_sqrt, a);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf prsqrt<Packet8bf> (const Packet8bf& a){
+ BF16_TO_F32_UNARY_OP_WRAPPER(prsqrt<Packet4f>, a);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pexp<Packet8bf> (const Packet8bf& a){
+ BF16_TO_F32_UNARY_OP_WRAPPER(pexp_float, a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pldexp<Packet4f>(const Packet4f& a, const Packet4f& exponent) {
+ return pldexp_generic(a,exponent);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pldexp<Packet8bf> (const Packet8bf& a, const Packet8bf& exponent){
+ BF16_TO_F32_BINARY_OP_WRAPPER(pldexp<Packet4f>, a, exponent);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pfrexp<Packet4f>(const Packet4f& a, Packet4f& exponent) {
+ return pfrexp_generic(a,exponent);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pfrexp<Packet8bf> (const Packet8bf& a, Packet8bf& e){
+ Packet4f a_even = Bf16ToF32Even(a);
+ Packet4f a_odd = Bf16ToF32Odd(a);
+ Packet4f e_even;
+ Packet4f e_odd;
+ Packet4f op_even = pfrexp<Packet4f>(a_even, e_even);
+ Packet4f op_odd = pfrexp<Packet4f>(a_odd, e_odd);
+ e = F32ToBf16(e_even, e_odd);
+ return F32ToBf16(op_even, op_odd);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf psin<Packet8bf> (const Packet8bf& a){
+ BF16_TO_F32_UNARY_OP_WRAPPER(psin_float, a);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pcos<Packet8bf> (const Packet8bf& a){
+ BF16_TO_F32_UNARY_OP_WRAPPER(pcos_float, a);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf plog<Packet8bf> (const Packet8bf& a){
+ BF16_TO_F32_UNARY_OP_WRAPPER(plog_float, a);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pfloor<Packet8bf> (const Packet8bf& a){
+ BF16_TO_F32_UNARY_OP_WRAPPER(pfloor<Packet4f>, a);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pceil<Packet8bf> (const Packet8bf& a){
+ BF16_TO_F32_UNARY_OP_WRAPPER(pceil<Packet4f>, a);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pround<Packet8bf> (const Packet8bf& a){
+ BF16_TO_F32_UNARY_OP_WRAPPER(pround<Packet4f>, a);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf print<Packet8bf> (const Packet8bf& a){
+ BF16_TO_F32_UNARY_OP_WRAPPER(print<Packet4f>, a);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pmadd(const Packet8bf& a, const Packet8bf& b, const Packet8bf& c) {
+ Packet4f a_even = Bf16ToF32Even(a);
+ Packet4f a_odd = Bf16ToF32Odd(a);
+ Packet4f b_even = Bf16ToF32Even(b);
+ Packet4f b_odd = Bf16ToF32Odd(b);
+ Packet4f c_even = Bf16ToF32Even(c);
+ Packet4f c_odd = Bf16ToF32Odd(c);
+ Packet4f pmadd_even = pmadd<Packet4f>(a_even, b_even, c_even);
+ Packet4f pmadd_odd = pmadd<Packet4f>(a_odd, b_odd, c_odd);
+ return F32ToBf16(pmadd_even, pmadd_odd);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pmin<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ BF16_TO_F32_BINARY_OP_WRAPPER(pmin<Packet4f>, a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pmax<Packet8bf>(const Packet8bf& a, const Packet8bf& b) {
+ BF16_TO_F32_BINARY_OP_WRAPPER(pmax<Packet4f>, a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pcmp_lt(const Packet8bf& a, const Packet8bf& b) {
+ BF16_TO_F32_BINARY_OP_WRAPPER_BOOL(pcmp_lt<Packet4f>, a, b);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pcmp_lt_or_nan(const Packet8bf& a, const Packet8bf& b) {
+ BF16_TO_F32_BINARY_OP_WRAPPER_BOOL(pcmp_lt_or_nan<Packet4f>, a, b);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pcmp_le(const Packet8bf& a, const Packet8bf& b) {
+ BF16_TO_F32_BINARY_OP_WRAPPER_BOOL(pcmp_le<Packet4f>, a, b);
+}
+template<> EIGEN_STRONG_INLINE Packet8bf pcmp_eq(const Packet8bf& a, const Packet8bf& b) {
+ BF16_TO_F32_BINARY_OP_WRAPPER_BOOL(pcmp_eq<Packet4f>, a, b);
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 pfirst(const Packet8bf& a) {
+ return Eigen::bfloat16_impl::raw_uint16_to_bfloat16((pfirst<Packet8us>(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf ploaddup<Packet8bf>(const bfloat16* from)
+{
+ return ploaddup<Packet8us>(reinterpret_cast<const unsigned short int*>(from));
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf plset<Packet8bf>(const bfloat16& a) {
+ bfloat16 countdown[8] = { bfloat16(0), bfloat16(1), bfloat16(2), bfloat16(3),
+ bfloat16(4), bfloat16(5), bfloat16(6), bfloat16(7) };
+ return padd<Packet8bf>(pset1<Packet8bf>(a), pload<Packet8bf>(countdown));
+}
+
+template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a)
+{
+ Packet4f b, sum;
+ b = vec_sld(a, a, 8);
+ sum = a + b;
+ b = vec_sld(sum, sum, 4);
+ sum += b;
+ return pfirst(sum);
+}
+
+template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a)
+{
+ Packet4i sum;
+ sum = vec_sums(a, p4i_ZERO);
+#ifdef _BIG_ENDIAN
+ sum = vec_sld(sum, p4i_ZERO, 12);
+#else
+ sum = vec_sld(p4i_ZERO, sum, 4);
+#endif
+ return pfirst(sum);
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux<Packet8bf>(const Packet8bf& a)
+{
+ float redux_even = predux<Packet4f>(Bf16ToF32Even(a));
+ float redux_odd = predux<Packet4f>(Bf16ToF32Odd(a));
+ float f32_result = redux_even + redux_odd;
+ return bfloat16(f32_result);
+}
+template<typename Packet> EIGEN_STRONG_INLINE __UNPACK_TYPE__(Packet) predux_size8(const Packet& a)
+{
+ union{
+ Packet v;
+ __UNPACK_TYPE__(Packet) n[8];
+ } vt;
+ vt.v = a;
+
+ EIGEN_ALIGN16 int first_loader[4] = { vt.n[0], vt.n[1], vt.n[2], vt.n[3] };
+ EIGEN_ALIGN16 int second_loader[4] = { vt.n[4], vt.n[5], vt.n[6], vt.n[7] };
+ Packet4i first_half = pload<Packet4i>(first_loader);
+ Packet4i second_half = pload<Packet4i>(second_loader);
+
+ return static_cast<__UNPACK_TYPE__(Packet)>(predux(first_half) + predux(second_half));
+}
+
+template<> EIGEN_STRONG_INLINE short int predux<Packet8s>(const Packet8s& a)
+{
+ return predux_size8<Packet8s>(a);
+}
+
+template<> EIGEN_STRONG_INLINE unsigned short int predux<Packet8us>(const Packet8us& a)
+{
+ return predux_size8<Packet8us>(a);
+}
+
+template<typename Packet> EIGEN_STRONG_INLINE __UNPACK_TYPE__(Packet) predux_size16(const Packet& a)
+{
+ union{
+ Packet v;
+ __UNPACK_TYPE__(Packet) n[16];
+ } vt;
+ vt.v = a;
+
+ EIGEN_ALIGN16 int first_loader[4] = { vt.n[0], vt.n[1], vt.n[2], vt.n[3] };
+ EIGEN_ALIGN16 int second_loader[4] = { vt.n[4], vt.n[5], vt.n[6], vt.n[7] };
+ EIGEN_ALIGN16 int third_loader[4] = { vt.n[8], vt.n[9], vt.n[10], vt.n[11] };
+ EIGEN_ALIGN16 int fourth_loader[4] = { vt.n[12], vt.n[13], vt.n[14], vt.n[15] };
+
+ Packet4i first_quarter = pload<Packet4i>(first_loader);
+ Packet4i second_quarter = pload<Packet4i>(second_loader);
+ Packet4i third_quarter = pload<Packet4i>(third_loader);
+ Packet4i fourth_quarter = pload<Packet4i>(fourth_loader);
+
+ return static_cast<__UNPACK_TYPE__(Packet)>(predux(first_quarter) + predux(second_quarter)
+ + predux(third_quarter) + predux(fourth_quarter));
+}
+
+template<> EIGEN_STRONG_INLINE signed char predux<Packet16c>(const Packet16c& a)
+{
+ return predux_size16<Packet16c>(a);
+}
+
+template<> EIGEN_STRONG_INLINE unsigned char predux<Packet16uc>(const Packet16uc& a)
+{
+ return predux_size16<Packet16uc>(a);
+}
+
+// Other reduction functions:
+// mul
+template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a)
+{
+ Packet4f prod;
+ prod = pmul(a, vec_sld(a, a, 8));
+ return pfirst(pmul(prod, vec_sld(prod, prod, 4)));
+}
+
+template<> EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a)
+{
+ EIGEN_ALIGN16 int aux[4];
+ pstore(aux, a);
+ return aux[0] * aux[1] * aux[2] * aux[3];
+}
+
+template<> EIGEN_STRONG_INLINE short int predux_mul<Packet8s>(const Packet8s& a)
+{
+ Packet8s pair, quad, octo;
+
+ pair = vec_mul(a, vec_sld(a, a, 8));
+ quad = vec_mul(pair, vec_sld(pair, pair, 4));
+ octo = vec_mul(quad, vec_sld(quad, quad, 2));
+
+ return pfirst(octo);
+}
+
+template<> EIGEN_STRONG_INLINE unsigned short int predux_mul<Packet8us>(const Packet8us& a)
+{
+ Packet8us pair, quad, octo;
+
+ pair = vec_mul(a, vec_sld(a, a, 8));
+ quad = vec_mul(pair, vec_sld(pair, pair, 4));
+ octo = vec_mul(quad, vec_sld(quad, quad, 2));
+
+ return pfirst(octo);
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux_mul<Packet8bf>(const Packet8bf& a)
+{
+ float redux_even = predux_mul<Packet4f>(Bf16ToF32Even(a));
+ float redux_odd = predux_mul<Packet4f>(Bf16ToF32Odd(a));
+ float f32_result = redux_even * redux_odd;
+ return bfloat16(f32_result);
+}
+
+
+template<> EIGEN_STRONG_INLINE signed char predux_mul<Packet16c>(const Packet16c& a)
+{
+ Packet16c pair, quad, octo, result;
+
+ pair = vec_mul(a, vec_sld(a, a, 8));
+ quad = vec_mul(pair, vec_sld(pair, pair, 4));
+ octo = vec_mul(quad, vec_sld(quad, quad, 2));
+ result = vec_mul(octo, vec_sld(octo, octo, 1));
+
+ return pfirst(result);
+}
+
+template<> EIGEN_STRONG_INLINE unsigned char predux_mul<Packet16uc>(const Packet16uc& a)
+{
+ Packet16uc pair, quad, octo, result;
+
+ pair = vec_mul(a, vec_sld(a, a, 8));
+ quad = vec_mul(pair, vec_sld(pair, pair, 4));
+ octo = vec_mul(quad, vec_sld(quad, quad, 2));
+ result = vec_mul(octo, vec_sld(octo, octo, 1));
+
+ return pfirst(result);
+}
+
+// min
+template<typename Packet> EIGEN_STRONG_INLINE
+__UNPACK_TYPE__(Packet) predux_min4(const Packet& a)
+{
+ Packet b, res;
+ b = vec_min(a, vec_sld(a, a, 8));
+ res = vec_min(b, vec_sld(b, b, 4));
+ return pfirst(res);
+}
+
+
+template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a)
+{
+ return predux_min4<Packet4f>(a);
+}
+
+template<> EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a)
+{
+ return predux_min4<Packet4i>(a);
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux_min<Packet8bf>(const Packet8bf& a)
+{
+ float redux_even = predux_min<Packet4f>(Bf16ToF32Even(a));
+ float redux_odd = predux_min<Packet4f>(Bf16ToF32Odd(a));
+ float f32_result = (std::min)(redux_even, redux_odd);
+ return bfloat16(f32_result);
+}
+
+template<> EIGEN_STRONG_INLINE short int predux_min<Packet8s>(const Packet8s& a)
+{
+ Packet8s pair, quad, octo;
+
+ //pair = { Min(a0,a4), Min(a1,a5), Min(a2,a6), Min(a3,a7) }
+ pair = vec_min(a, vec_sld(a, a, 8));
+
+ //quad = { Min(a0, a4, a2, a6), Min(a1, a5, a3, a7) }
+ quad = vec_min(pair, vec_sld(pair, pair, 4));
+
+ //octo = { Min(a0, a4, a2, a6, a1, a5, a3, a7) }
+ octo = vec_min(quad, vec_sld(quad, quad, 2));
+ return pfirst(octo);
+}
+
+template<> EIGEN_STRONG_INLINE unsigned short int predux_min<Packet8us>(const Packet8us& a)
+{
+ Packet8us pair, quad, octo;
+
+ //pair = { Min(a0,a4), Min(a1,a5), Min(a2,a6), Min(a3,a7) }
+ pair = vec_min(a, vec_sld(a, a, 8));
+
+ //quad = { Min(a0, a4, a2, a6), Min(a1, a5, a3, a7) }
+ quad = vec_min(pair, vec_sld(pair, pair, 4));
+
+ //octo = { Min(a0, a4, a2, a6, a1, a5, a3, a7) }
+ octo = vec_min(quad, vec_sld(quad, quad, 2));
+ return pfirst(octo);
+}
+
+template<> EIGEN_STRONG_INLINE signed char predux_min<Packet16c>(const Packet16c& a)
+{
+ Packet16c pair, quad, octo, result;
+
+ pair = vec_min(a, vec_sld(a, a, 8));
+ quad = vec_min(pair, vec_sld(pair, pair, 4));
+ octo = vec_min(quad, vec_sld(quad, quad, 2));
+ result = vec_min(octo, vec_sld(octo, octo, 1));
+
+ return pfirst(result);
+}
+
+template<> EIGEN_STRONG_INLINE unsigned char predux_min<Packet16uc>(const Packet16uc& a)
+{
+ Packet16uc pair, quad, octo, result;
+
+ pair = vec_min(a, vec_sld(a, a, 8));
+ quad = vec_min(pair, vec_sld(pair, pair, 4));
+ octo = vec_min(quad, vec_sld(quad, quad, 2));
+ result = vec_min(octo, vec_sld(octo, octo, 1));
+
+ return pfirst(result);
+}
+// max
+template<typename Packet> EIGEN_STRONG_INLINE __UNPACK_TYPE__(Packet) predux_max4(const Packet& a)
+{
+ Packet b, res;
+ b = vec_max(a, vec_sld(a, a, 8));
+ res = vec_max(b, vec_sld(b, b, 4));
+ return pfirst(res);
+}
+
+template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a)
+{
+ return predux_max4<Packet4f>(a);
+}
+
+template<> EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a)
+{
+ return predux_max4<Packet4i>(a);
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux_max<Packet8bf>(const Packet8bf& a)
+{
+ float redux_even = predux_max<Packet4f>(Bf16ToF32Even(a));
+ float redux_odd = predux_max<Packet4f>(Bf16ToF32Odd(a));
+ float f32_result = (std::max)(redux_even, redux_odd);
+ return bfloat16(f32_result);
+}
+
+template<> EIGEN_STRONG_INLINE short int predux_max<Packet8s>(const Packet8s& a)
+{
+ Packet8s pair, quad, octo;
+
+ //pair = { Max(a0,a4), Max(a1,a5), Max(a2,a6), Max(a3,a7) }
+ pair = vec_max(a, vec_sld(a, a, 8));
+
+ //quad = { Max(a0, a4, a2, a6), Max(a1, a5, a3, a7) }
+ quad = vec_max(pair, vec_sld(pair, pair, 4));
+
+ //octo = { Max(a0, a4, a2, a6, a1, a5, a3, a7) }
+ octo = vec_max(quad, vec_sld(quad, quad, 2));
+ return pfirst(octo);
+}
+
+template<> EIGEN_STRONG_INLINE unsigned short int predux_max<Packet8us>(const Packet8us& a)
+{
+ Packet8us pair, quad, octo;
+
+ //pair = { Max(a0,a4), Max(a1,a5), Max(a2,a6), Max(a3,a7) }
+ pair = vec_max(a, vec_sld(a, a, 8));
+
+ //quad = { Max(a0, a4, a2, a6), Max(a1, a5, a3, a7) }
+ quad = vec_max(pair, vec_sld(pair, pair, 4));
+
+ //octo = { Max(a0, a4, a2, a6, a1, a5, a3, a7) }
+ octo = vec_max(quad, vec_sld(quad, quad, 2));
+ return pfirst(octo);
+}
+
+template<> EIGEN_STRONG_INLINE signed char predux_max<Packet16c>(const Packet16c& a)
+{
+ Packet16c pair, quad, octo, result;
+
+ pair = vec_max(a, vec_sld(a, a, 8));
+ quad = vec_max(pair, vec_sld(pair, pair, 4));
+ octo = vec_max(quad, vec_sld(quad, quad, 2));
+ result = vec_max(octo, vec_sld(octo, octo, 1));
+
+ return pfirst(result);
+}
+
+template<> EIGEN_STRONG_INLINE unsigned char predux_max<Packet16uc>(const Packet16uc& a)
+{
+ Packet16uc pair, quad, octo, result;
+
+ pair = vec_max(a, vec_sld(a, a, 8));
+ quad = vec_max(pair, vec_sld(pair, pair, 4));
+ octo = vec_max(quad, vec_sld(quad, quad, 2));
+ result = vec_max(octo, vec_sld(octo, octo, 1));
+
+ return pfirst(result);
+}
+
+template<> EIGEN_STRONG_INLINE bool predux_any(const Packet4f& x)
+{
+ return vec_any_ne(x, pzero(x));
+}
+
+template <typename T> EIGEN_DEVICE_FUNC inline void
+ptranpose_common(PacketBlock<T,4>& kernel){
+ T t0, t1, t2, t3;
+ t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]);
+ t1 = vec_mergel(kernel.packet[0], kernel.packet[2]);
+ t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]);
+ t3 = vec_mergel(kernel.packet[1], kernel.packet[3]);
+ kernel.packet[0] = vec_mergeh(t0, t2);
+ kernel.packet[1] = vec_mergel(t0, t2);
+ kernel.packet[2] = vec_mergeh(t1, t3);
+ kernel.packet[3] = vec_mergel(t1, t3);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet4f,4>& kernel) {
+ ptranpose_common<Packet4f>(kernel);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet4i,4>& kernel) {
+ ptranpose_common<Packet4i>(kernel);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet8s,4>& kernel) {
+ Packet8s t0, t1, t2, t3;
+ t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]);
+ t1 = vec_mergel(kernel.packet[0], kernel.packet[2]);
+ t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]);
+ t3 = vec_mergel(kernel.packet[1], kernel.packet[3]);
+ kernel.packet[0] = vec_mergeh(t0, t2);
+ kernel.packet[1] = vec_mergel(t0, t2);
+ kernel.packet[2] = vec_mergeh(t1, t3);
+ kernel.packet[3] = vec_mergel(t1, t3);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet8us,4>& kernel) {
+ Packet8us t0, t1, t2, t3;
+ t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]);
+ t1 = vec_mergel(kernel.packet[0], kernel.packet[2]);
+ t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]);
+ t3 = vec_mergel(kernel.packet[1], kernel.packet[3]);
+ kernel.packet[0] = vec_mergeh(t0, t2);
+ kernel.packet[1] = vec_mergel(t0, t2);
+ kernel.packet[2] = vec_mergeh(t1, t3);
+ kernel.packet[3] = vec_mergel(t1, t3);
+}
+
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet8bf,4>& kernel) {
+ Packet8us t0, t1, t2, t3;
+
+ t0 = vec_mergeh(kernel.packet[0].m_val, kernel.packet[2].m_val);
+ t1 = vec_mergel(kernel.packet[0].m_val, kernel.packet[2].m_val);
+ t2 = vec_mergeh(kernel.packet[1].m_val, kernel.packet[3].m_val);
+ t3 = vec_mergel(kernel.packet[1].m_val, kernel.packet[3].m_val);
+ kernel.packet[0] = vec_mergeh(t0, t2);
+ kernel.packet[1] = vec_mergel(t0, t2);
+ kernel.packet[2] = vec_mergeh(t1, t3);
+ kernel.packet[3] = vec_mergel(t1, t3);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet16c,4>& kernel) {
+ Packet16c t0, t1, t2, t3;
+ t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]);
+ t1 = vec_mergel(kernel.packet[0], kernel.packet[2]);
+ t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]);
+ t3 = vec_mergel(kernel.packet[1], kernel.packet[3]);
+ kernel.packet[0] = vec_mergeh(t0, t2);
+ kernel.packet[1] = vec_mergel(t0, t2);
+ kernel.packet[2] = vec_mergeh(t1, t3);
+ kernel.packet[3] = vec_mergel(t1, t3);
+}
+
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet16uc,4>& kernel) {
+ Packet16uc t0, t1, t2, t3;
+ t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]);
+ t1 = vec_mergel(kernel.packet[0], kernel.packet[2]);
+ t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]);
+ t3 = vec_mergel(kernel.packet[1], kernel.packet[3]);
+ kernel.packet[0] = vec_mergeh(t0, t2);
+ kernel.packet[1] = vec_mergel(t0, t2);
+ kernel.packet[2] = vec_mergeh(t1, t3);
+ kernel.packet[3] = vec_mergel(t1, t3);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet8s,8>& kernel) {
+ Packet8s v[8], sum[8];
+
+ v[0] = vec_mergeh(kernel.packet[0], kernel.packet[4]);
+ v[1] = vec_mergel(kernel.packet[0], kernel.packet[4]);
+ v[2] = vec_mergeh(kernel.packet[1], kernel.packet[5]);
+ v[3] = vec_mergel(kernel.packet[1], kernel.packet[5]);
+ v[4] = vec_mergeh(kernel.packet[2], kernel.packet[6]);
+ v[5] = vec_mergel(kernel.packet[2], kernel.packet[6]);
+ v[6] = vec_mergeh(kernel.packet[3], kernel.packet[7]);
+ v[7] = vec_mergel(kernel.packet[3], kernel.packet[7]);
+ sum[0] = vec_mergeh(v[0], v[4]);
+ sum[1] = vec_mergel(v[0], v[4]);
+ sum[2] = vec_mergeh(v[1], v[5]);
+ sum[3] = vec_mergel(v[1], v[5]);
+ sum[4] = vec_mergeh(v[2], v[6]);
+ sum[5] = vec_mergel(v[2], v[6]);
+ sum[6] = vec_mergeh(v[3], v[7]);
+ sum[7] = vec_mergel(v[3], v[7]);
+
+ kernel.packet[0] = vec_mergeh(sum[0], sum[4]);
+ kernel.packet[1] = vec_mergel(sum[0], sum[4]);
+ kernel.packet[2] = vec_mergeh(sum[1], sum[5]);
+ kernel.packet[3] = vec_mergel(sum[1], sum[5]);
+ kernel.packet[4] = vec_mergeh(sum[2], sum[6]);
+ kernel.packet[5] = vec_mergel(sum[2], sum[6]);
+ kernel.packet[6] = vec_mergeh(sum[3], sum[7]);
+ kernel.packet[7] = vec_mergel(sum[3], sum[7]);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet8us,8>& kernel) {
+ Packet8us v[8], sum[8];
+
+ v[0] = vec_mergeh(kernel.packet[0], kernel.packet[4]);
+ v[1] = vec_mergel(kernel.packet[0], kernel.packet[4]);
+ v[2] = vec_mergeh(kernel.packet[1], kernel.packet[5]);
+ v[3] = vec_mergel(kernel.packet[1], kernel.packet[5]);
+ v[4] = vec_mergeh(kernel.packet[2], kernel.packet[6]);
+ v[5] = vec_mergel(kernel.packet[2], kernel.packet[6]);
+ v[6] = vec_mergeh(kernel.packet[3], kernel.packet[7]);
+ v[7] = vec_mergel(kernel.packet[3], kernel.packet[7]);
+ sum[0] = vec_mergeh(v[0], v[4]);
+ sum[1] = vec_mergel(v[0], v[4]);
+ sum[2] = vec_mergeh(v[1], v[5]);
+ sum[3] = vec_mergel(v[1], v[5]);
+ sum[4] = vec_mergeh(v[2], v[6]);
+ sum[5] = vec_mergel(v[2], v[6]);
+ sum[6] = vec_mergeh(v[3], v[7]);
+ sum[7] = vec_mergel(v[3], v[7]);
+
+ kernel.packet[0] = vec_mergeh(sum[0], sum[4]);
+ kernel.packet[1] = vec_mergel(sum[0], sum[4]);
+ kernel.packet[2] = vec_mergeh(sum[1], sum[5]);
+ kernel.packet[3] = vec_mergel(sum[1], sum[5]);
+ kernel.packet[4] = vec_mergeh(sum[2], sum[6]);
+ kernel.packet[5] = vec_mergel(sum[2], sum[6]);
+ kernel.packet[6] = vec_mergeh(sum[3], sum[7]);
+ kernel.packet[7] = vec_mergel(sum[3], sum[7]);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet8bf,8>& kernel) {
+ Packet8bf v[8], sum[8];
+
+ v[0] = vec_mergeh(kernel.packet[0].m_val, kernel.packet[4].m_val);
+ v[1] = vec_mergel(kernel.packet[0].m_val, kernel.packet[4].m_val);
+ v[2] = vec_mergeh(kernel.packet[1].m_val, kernel.packet[5].m_val);
+ v[3] = vec_mergel(kernel.packet[1].m_val, kernel.packet[5].m_val);
+ v[4] = vec_mergeh(kernel.packet[2].m_val, kernel.packet[6].m_val);
+ v[5] = vec_mergel(kernel.packet[2].m_val, kernel.packet[6].m_val);
+ v[6] = vec_mergeh(kernel.packet[3].m_val, kernel.packet[7].m_val);
+ v[7] = vec_mergel(kernel.packet[3].m_val, kernel.packet[7].m_val);
+ sum[0] = vec_mergeh(v[0].m_val, v[4].m_val);
+ sum[1] = vec_mergel(v[0].m_val, v[4].m_val);
+ sum[2] = vec_mergeh(v[1].m_val, v[5].m_val);
+ sum[3] = vec_mergel(v[1].m_val, v[5].m_val);
+ sum[4] = vec_mergeh(v[2].m_val, v[6].m_val);
+ sum[5] = vec_mergel(v[2].m_val, v[6].m_val);
+ sum[6] = vec_mergeh(v[3].m_val, v[7].m_val);
+ sum[7] = vec_mergel(v[3].m_val, v[7].m_val);
+
+ kernel.packet[0] = vec_mergeh(sum[0].m_val, sum[4].m_val);
+ kernel.packet[1] = vec_mergel(sum[0].m_val, sum[4].m_val);
+ kernel.packet[2] = vec_mergeh(sum[1].m_val, sum[5].m_val);
+ kernel.packet[3] = vec_mergel(sum[1].m_val, sum[5].m_val);
+ kernel.packet[4] = vec_mergeh(sum[2].m_val, sum[6].m_val);
+ kernel.packet[5] = vec_mergel(sum[2].m_val, sum[6].m_val);
+ kernel.packet[6] = vec_mergeh(sum[3].m_val, sum[7].m_val);
+ kernel.packet[7] = vec_mergel(sum[3].m_val, sum[7].m_val);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet16c,16>& kernel) {
+ Packet16c step1[16], step2[16], step3[16];
+
+ step1[0] = vec_mergeh(kernel.packet[0], kernel.packet[8]);
+ step1[1] = vec_mergel(kernel.packet[0], kernel.packet[8]);
+ step1[2] = vec_mergeh(kernel.packet[1], kernel.packet[9]);
+ step1[3] = vec_mergel(kernel.packet[1], kernel.packet[9]);
+ step1[4] = vec_mergeh(kernel.packet[2], kernel.packet[10]);
+ step1[5] = vec_mergel(kernel.packet[2], kernel.packet[10]);
+ step1[6] = vec_mergeh(kernel.packet[3], kernel.packet[11]);
+ step1[7] = vec_mergel(kernel.packet[3], kernel.packet[11]);
+ step1[8] = vec_mergeh(kernel.packet[4], kernel.packet[12]);
+ step1[9] = vec_mergel(kernel.packet[4], kernel.packet[12]);
+ step1[10] = vec_mergeh(kernel.packet[5], kernel.packet[13]);
+ step1[11] = vec_mergel(kernel.packet[5], kernel.packet[13]);
+ step1[12] = vec_mergeh(kernel.packet[6], kernel.packet[14]);
+ step1[13] = vec_mergel(kernel.packet[6], kernel.packet[14]);
+ step1[14] = vec_mergeh(kernel.packet[7], kernel.packet[15]);
+ step1[15] = vec_mergel(kernel.packet[7], kernel.packet[15]);
+
+ step2[0] = vec_mergeh(step1[0], step1[8]);
+ step2[1] = vec_mergel(step1[0], step1[8]);
+ step2[2] = vec_mergeh(step1[1], step1[9]);
+ step2[3] = vec_mergel(step1[1], step1[9]);
+ step2[4] = vec_mergeh(step1[2], step1[10]);
+ step2[5] = vec_mergel(step1[2], step1[10]);
+ step2[6] = vec_mergeh(step1[3], step1[11]);
+ step2[7] = vec_mergel(step1[3], step1[11]);
+ step2[8] = vec_mergeh(step1[4], step1[12]);
+ step2[9] = vec_mergel(step1[4], step1[12]);
+ step2[10] = vec_mergeh(step1[5], step1[13]);
+ step2[11] = vec_mergel(step1[5], step1[13]);
+ step2[12] = vec_mergeh(step1[6], step1[14]);
+ step2[13] = vec_mergel(step1[6], step1[14]);
+ step2[14] = vec_mergeh(step1[7], step1[15]);
+ step2[15] = vec_mergel(step1[7], step1[15]);
+
+ step3[0] = vec_mergeh(step2[0], step2[8]);
+ step3[1] = vec_mergel(step2[0], step2[8]);
+ step3[2] = vec_mergeh(step2[1], step2[9]);
+ step3[3] = vec_mergel(step2[1], step2[9]);
+ step3[4] = vec_mergeh(step2[2], step2[10]);
+ step3[5] = vec_mergel(step2[2], step2[10]);
+ step3[6] = vec_mergeh(step2[3], step2[11]);
+ step3[7] = vec_mergel(step2[3], step2[11]);
+ step3[8] = vec_mergeh(step2[4], step2[12]);
+ step3[9] = vec_mergel(step2[4], step2[12]);
+ step3[10] = vec_mergeh(step2[5], step2[13]);
+ step3[11] = vec_mergel(step2[5], step2[13]);
+ step3[12] = vec_mergeh(step2[6], step2[14]);
+ step3[13] = vec_mergel(step2[6], step2[14]);
+ step3[14] = vec_mergeh(step2[7], step2[15]);
+ step3[15] = vec_mergel(step2[7], step2[15]);
+
+ kernel.packet[0] = vec_mergeh(step3[0], step3[8]);
+ kernel.packet[1] = vec_mergel(step3[0], step3[8]);
+ kernel.packet[2] = vec_mergeh(step3[1], step3[9]);
+ kernel.packet[3] = vec_mergel(step3[1], step3[9]);
+ kernel.packet[4] = vec_mergeh(step3[2], step3[10]);
+ kernel.packet[5] = vec_mergel(step3[2], step3[10]);
+ kernel.packet[6] = vec_mergeh(step3[3], step3[11]);
+ kernel.packet[7] = vec_mergel(step3[3], step3[11]);
+ kernel.packet[8] = vec_mergeh(step3[4], step3[12]);
+ kernel.packet[9] = vec_mergel(step3[4], step3[12]);
+ kernel.packet[10] = vec_mergeh(step3[5], step3[13]);
+ kernel.packet[11] = vec_mergel(step3[5], step3[13]);
+ kernel.packet[12] = vec_mergeh(step3[6], step3[14]);
+ kernel.packet[13] = vec_mergel(step3[6], step3[14]);
+ kernel.packet[14] = vec_mergeh(step3[7], step3[15]);
+ kernel.packet[15] = vec_mergel(step3[7], step3[15]);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet16uc,16>& kernel) {
+ Packet16uc step1[16], step2[16], step3[16];
+
+ step1[0] = vec_mergeh(kernel.packet[0], kernel.packet[8]);
+ step1[1] = vec_mergel(kernel.packet[0], kernel.packet[8]);
+ step1[2] = vec_mergeh(kernel.packet[1], kernel.packet[9]);
+ step1[3] = vec_mergel(kernel.packet[1], kernel.packet[9]);
+ step1[4] = vec_mergeh(kernel.packet[2], kernel.packet[10]);
+ step1[5] = vec_mergel(kernel.packet[2], kernel.packet[10]);
+ step1[6] = vec_mergeh(kernel.packet[3], kernel.packet[11]);
+ step1[7] = vec_mergel(kernel.packet[3], kernel.packet[11]);
+ step1[8] = vec_mergeh(kernel.packet[4], kernel.packet[12]);
+ step1[9] = vec_mergel(kernel.packet[4], kernel.packet[12]);
+ step1[10] = vec_mergeh(kernel.packet[5], kernel.packet[13]);
+ step1[11] = vec_mergel(kernel.packet[5], kernel.packet[13]);
+ step1[12] = vec_mergeh(kernel.packet[6], kernel.packet[14]);
+ step1[13] = vec_mergel(kernel.packet[6], kernel.packet[14]);
+ step1[14] = vec_mergeh(kernel.packet[7], kernel.packet[15]);
+ step1[15] = vec_mergel(kernel.packet[7], kernel.packet[15]);
+
+ step2[0] = vec_mergeh(step1[0], step1[8]);
+ step2[1] = vec_mergel(step1[0], step1[8]);
+ step2[2] = vec_mergeh(step1[1], step1[9]);
+ step2[3] = vec_mergel(step1[1], step1[9]);
+ step2[4] = vec_mergeh(step1[2], step1[10]);
+ step2[5] = vec_mergel(step1[2], step1[10]);
+ step2[6] = vec_mergeh(step1[3], step1[11]);
+ step2[7] = vec_mergel(step1[3], step1[11]);
+ step2[8] = vec_mergeh(step1[4], step1[12]);
+ step2[9] = vec_mergel(step1[4], step1[12]);
+ step2[10] = vec_mergeh(step1[5], step1[13]);
+ step2[11] = vec_mergel(step1[5], step1[13]);
+ step2[12] = vec_mergeh(step1[6], step1[14]);
+ step2[13] = vec_mergel(step1[6], step1[14]);
+ step2[14] = vec_mergeh(step1[7], step1[15]);
+ step2[15] = vec_mergel(step1[7], step1[15]);
+
+ step3[0] = vec_mergeh(step2[0], step2[8]);
+ step3[1] = vec_mergel(step2[0], step2[8]);
+ step3[2] = vec_mergeh(step2[1], step2[9]);
+ step3[3] = vec_mergel(step2[1], step2[9]);
+ step3[4] = vec_mergeh(step2[2], step2[10]);
+ step3[5] = vec_mergel(step2[2], step2[10]);
+ step3[6] = vec_mergeh(step2[3], step2[11]);
+ step3[7] = vec_mergel(step2[3], step2[11]);
+ step3[8] = vec_mergeh(step2[4], step2[12]);
+ step3[9] = vec_mergel(step2[4], step2[12]);
+ step3[10] = vec_mergeh(step2[5], step2[13]);
+ step3[11] = vec_mergel(step2[5], step2[13]);
+ step3[12] = vec_mergeh(step2[6], step2[14]);
+ step3[13] = vec_mergel(step2[6], step2[14]);
+ step3[14] = vec_mergeh(step2[7], step2[15]);
+ step3[15] = vec_mergel(step2[7], step2[15]);
+
+ kernel.packet[0] = vec_mergeh(step3[0], step3[8]);
+ kernel.packet[1] = vec_mergel(step3[0], step3[8]);
+ kernel.packet[2] = vec_mergeh(step3[1], step3[9]);
+ kernel.packet[3] = vec_mergel(step3[1], step3[9]);
+ kernel.packet[4] = vec_mergeh(step3[2], step3[10]);
+ kernel.packet[5] = vec_mergel(step3[2], step3[10]);
+ kernel.packet[6] = vec_mergeh(step3[3], step3[11]);
+ kernel.packet[7] = vec_mergel(step3[3], step3[11]);
+ kernel.packet[8] = vec_mergeh(step3[4], step3[12]);
+ kernel.packet[9] = vec_mergel(step3[4], step3[12]);
+ kernel.packet[10] = vec_mergeh(step3[5], step3[13]);
+ kernel.packet[11] = vec_mergel(step3[5], step3[13]);
+ kernel.packet[12] = vec_mergeh(step3[6], step3[14]);
+ kernel.packet[13] = vec_mergel(step3[6], step3[14]);
+ kernel.packet[14] = vec_mergeh(step3[7], step3[15]);
+ kernel.packet[15] = vec_mergel(step3[7], step3[15]);
+}
+
+template<typename Packet> EIGEN_STRONG_INLINE
+Packet pblend4(const Selector<4>& ifPacket, const Packet& thenPacket, const Packet& elsePacket) {
+ Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] };
+ Packet4ui mask = reinterpret_cast<Packet4ui>(vec_cmpeq(reinterpret_cast<Packet4ui>(select), reinterpret_cast<Packet4ui>(p4i_ONE)));
+ return vec_sel(elsePacket, thenPacket, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i pblend(const Selector<4>& ifPacket, const Packet4i& thenPacket, const Packet4i& elsePacket) {
+ return pblend4<Packet4i>(ifPacket, thenPacket, elsePacket);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, const Packet4f& elsePacket) {
+ return pblend4<Packet4f>(ifPacket, thenPacket, elsePacket);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8s pblend(const Selector<8>& ifPacket, const Packet8s& thenPacket, const Packet8s& elsePacket) {
+ Packet8us select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3],
+ ifPacket.select[4], ifPacket.select[5], ifPacket.select[6], ifPacket.select[7] };
+ Packet8us mask = reinterpret_cast<Packet8us>(vec_cmpeq(select, p8us_ONE));
+ Packet8s result = vec_sel(elsePacket, thenPacket, mask);
+ return result;
+}
+
+template<> EIGEN_STRONG_INLINE Packet8us pblend(const Selector<8>& ifPacket, const Packet8us& thenPacket, const Packet8us& elsePacket) {
+ Packet8us select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3],
+ ifPacket.select[4], ifPacket.select[5], ifPacket.select[6], ifPacket.select[7] };
+ Packet8us mask = reinterpret_cast<Packet8us>(vec_cmpeq(reinterpret_cast<Packet8us>(select), p8us_ONE));
+ return vec_sel(elsePacket, thenPacket, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pblend(const Selector<8>& ifPacket, const Packet8bf& thenPacket, const Packet8bf& elsePacket) {
+ return pblend<Packet8us>(ifPacket, thenPacket, elsePacket);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16c pblend(const Selector<16>& ifPacket, const Packet16c& thenPacket, const Packet16c& elsePacket) {
+ Packet16uc select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3],
+ ifPacket.select[4], ifPacket.select[5], ifPacket.select[6], ifPacket.select[7],
+ ifPacket.select[8], ifPacket.select[9], ifPacket.select[10], ifPacket.select[11],
+ ifPacket.select[12], ifPacket.select[13], ifPacket.select[14], ifPacket.select[15] };
+
+ Packet16uc mask = reinterpret_cast<Packet16uc>(vec_cmpeq(reinterpret_cast<Packet16uc>(select), p16uc_ONE));
+ return vec_sel(elsePacket, thenPacket, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16uc pblend(const Selector<16>& ifPacket, const Packet16uc& thenPacket, const Packet16uc& elsePacket) {
+ Packet16uc select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3],
+ ifPacket.select[4], ifPacket.select[5], ifPacket.select[6], ifPacket.select[7],
+ ifPacket.select[8], ifPacket.select[9], ifPacket.select[10], ifPacket.select[11],
+ ifPacket.select[12], ifPacket.select[13], ifPacket.select[14], ifPacket.select[15] };
+
+ Packet16uc mask = reinterpret_cast<Packet16uc>(vec_cmpeq(reinterpret_cast<Packet16uc>(select), p16uc_ONE));
+ return vec_sel(elsePacket, thenPacket, mask);
+}
+
+template <>
+struct type_casting_traits<float, int> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template <>
+struct type_casting_traits<int, float> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template <>
+struct type_casting_traits<bfloat16, unsigned short int> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template <>
+struct type_casting_traits<unsigned short int, bfloat16> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet4i pcast<Packet4f, Packet4i>(const Packet4f& a) {
+ return vec_cts(a,0);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4ui pcast<Packet4f, Packet4ui>(const Packet4f& a) {
+ return vec_ctu(a,0);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet4i, Packet4f>(const Packet4i& a) {
+ return vec_ctf(a,0);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet4ui, Packet4f>(const Packet4ui& a) {
+ return vec_ctf(a,0);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8us pcast<Packet8bf, Packet8us>(const Packet8bf& a) {
+ Packet4f float_even = Bf16ToF32Even(a);
+ Packet4f float_odd = Bf16ToF32Odd(a);
+ Packet4ui int_even = pcast<Packet4f, Packet4ui>(float_even);
+ Packet4ui int_odd = pcast<Packet4f, Packet4ui>(float_odd);
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(low_mask, 0x0000FFFF);
+ Packet4ui low_even = pand<Packet4ui>(int_even, p4ui_low_mask);
+ Packet4ui low_odd = pand<Packet4ui>(int_odd, p4ui_low_mask);
+
+ //Check values that are bigger than USHRT_MAX (0xFFFF)
+ Packet4bi overflow_selector;
+ if(vec_any_gt(int_even, p4ui_low_mask)){
+ overflow_selector = vec_cmpgt(int_even, p4ui_low_mask);
+ low_even = vec_sel(low_even, p4ui_low_mask, overflow_selector);
+ }
+ if(vec_any_gt(int_odd, p4ui_low_mask)){
+ overflow_selector = vec_cmpgt(int_odd, p4ui_low_mask);
+ low_odd = vec_sel(low_even, p4ui_low_mask, overflow_selector);
+ }
+
+ low_odd = plogical_shift_left<16>(low_odd);
+
+ Packet4ui int_final = por<Packet4ui>(low_even, low_odd);
+ return reinterpret_cast<Packet8us>(int_final);
+}
+
+template<> EIGEN_STRONG_INLINE Packet8bf pcast<Packet8us, Packet8bf>(const Packet8us& a) {
+ //short -> int -> float -> bfloat16
+ const _EIGEN_DECLARE_CONST_FAST_Packet4ui(low_mask, 0x0000FFFF);
+ Packet4ui int_cast = reinterpret_cast<Packet4ui>(a);
+ Packet4ui int_even = pand<Packet4ui>(int_cast, p4ui_low_mask);
+ Packet4ui int_odd = plogical_shift_right<16>(int_cast);
+ Packet4f float_even = pcast<Packet4ui, Packet4f>(int_even);
+ Packet4f float_odd = pcast<Packet4ui, Packet4f>(int_odd);
+ return F32ToBf16(float_even, float_odd);
+}
+
+
+template<> EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i,Packet4f>(const Packet4f& a) {
+ return reinterpret_cast<Packet4i>(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f preinterpret<Packet4f,Packet4i>(const Packet4i& a) {
+ return reinterpret_cast<Packet4f>(a);
+}
+
+
+
+//---------- double ----------
+#ifdef __VSX__
+typedef __vector double Packet2d;
+typedef __vector unsigned long long Packet2ul;
+typedef __vector long long Packet2l;
+#if EIGEN_COMP_CLANG
+typedef Packet2ul Packet2bl;
+#else
+typedef __vector __bool long Packet2bl;
+#endif
+
+static Packet2l p2l_ONE = { 1, 1 };
+static Packet2l p2l_ZERO = reinterpret_cast<Packet2l>(p4i_ZERO);
+static Packet2ul p2ul_SIGN = { 0x8000000000000000ull, 0x8000000000000000ull };
+static Packet2ul p2ul_PREV0DOT5 = { 0x3FDFFFFFFFFFFFFFull, 0x3FDFFFFFFFFFFFFFull };
+static Packet2d p2d_ONE = { 1.0, 1.0 };
+static Packet2d p2d_ZERO = reinterpret_cast<Packet2d>(p4f_ZERO);
+static Packet2d p2d_MZERO = { numext::bit_cast<double>(0x8000000000000000ull),
+ numext::bit_cast<double>(0x8000000000000000ull) };
+
+#ifdef _BIG_ENDIAN
+static Packet2d p2d_COUNTDOWN = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(p2d_ZERO), reinterpret_cast<Packet4f>(p2d_ONE), 8));
+#else
+static Packet2d p2d_COUNTDOWN = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(p2d_ONE), reinterpret_cast<Packet4f>(p2d_ZERO), 8));
+#endif
+
+template<int index> Packet2d vec_splat_dbl(Packet2d& a)
+{
+ return vec_splat(a, index);
+}
+
+template<> struct packet_traits<double> : default_packet_traits
+{
+ typedef Packet2d type;
+ typedef Packet2d half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size=2,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasAbs = 1,
+ HasSin = 0,
+ HasCos = 0,
+ HasLog = 0,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1,
+ HasNegate = 1,
+ HasBlend = 1
+ };
+};
+
+template<> struct unpacket_traits<Packet2d> { typedef double type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet2d half; };
+
+inline std::ostream & operator <<(std::ostream & s, const Packet2l & v)
+{
+ union {
+ Packet2l v;
+ int64_t n[2];
+ } vt;
+ vt.v = v;
+ s << vt.n[0] << ", " << vt.n[1];
+ return s;
+}
+
+inline std::ostream & operator <<(std::ostream & s, const Packet2d & v)
+{
+ union {
+ Packet2d v;
+ double n[2];
+ } vt;
+ vt.v = v;
+ s << vt.n[0] << ", " << vt.n[1];
+ return s;
+}
+
+// Need to define them first or we get specialization after instantiation errors
+template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from)
+{
+ EIGEN_DEBUG_ALIGNED_LOAD
+ return vec_xl(0, const_cast<double *>(from)); // cast needed by Clang
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from)
+{
+ EIGEN_DEBUG_ALIGNED_STORE
+ vec_xst(from, 0, to);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) {
+ Packet2d v = {from, from};
+ return v;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pset1frombits<Packet2d>(unsigned long from) {
+ Packet2l v = {static_cast<long long>(from), static_cast<long long>(from)};
+ return reinterpret_cast<Packet2d>(v);
+}
+
+template<> EIGEN_STRONG_INLINE void
+pbroadcast4<Packet2d>(const double *a,
+ Packet2d& a0, Packet2d& a1, Packet2d& a2, Packet2d& a3)
+{
+ //This way is faster than vec_splat (at least for doubles in Power 9)
+ a0 = pset1<Packet2d>(a[0]);
+ a1 = pset1<Packet2d>(a[1]);
+ a2 = pset1<Packet2d>(a[2]);
+ a3 = pset1<Packet2d>(a[3]);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride)
+{
+ EIGEN_ALIGN16 double af[2];
+ af[0] = from[0*stride];
+ af[1] = from[1*stride];
+ return pload<Packet2d>(af);
+}
+template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride)
+{
+ EIGEN_ALIGN16 double af[2];
+ pstore<double>(af, from);
+ to[0*stride] = af[0];
+ to[1*stride] = af[1];
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) { return pset1<Packet2d>(a) + p2d_COUNTDOWN; }
+
+template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return a + b; }
+
+template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return a - b; }
+
+template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) { return p2d_ZERO - a; }
+
+template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_madd(a,b,p2d_MZERO); }
+template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_div(a,b); }
+
+// for some weird raisons, it has to be overloaded for packet of integers
+template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) { return vec_madd(a, b, c); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b)
+{
+ // NOTE: about 10% slower than vec_min, but consistent with std::min and SSE regarding NaN
+ Packet2d ret;
+ __asm__ ("xvcmpgedp %x0,%x1,%x2\n\txxsel %x0,%x1,%x2,%x0" : "=&wa" (ret) : "wa" (a), "wa" (b));
+ return ret;
+ }
+
+template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b)
+{
+ // NOTE: about 10% slower than vec_max, but consistent with std::max and SSE regarding NaN
+ Packet2d ret;
+ __asm__ ("xvcmpgtdp %x0,%x2,%x1\n\txxsel %x0,%x1,%x2,%x0" : "=&wa" (ret) : "wa" (a), "wa" (b));
+ return ret;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_le(const Packet2d& a, const Packet2d& b) { return reinterpret_cast<Packet2d>(vec_cmple(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_lt(const Packet2d& a, const Packet2d& b) { return reinterpret_cast<Packet2d>(vec_cmplt(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_eq(const Packet2d& a, const Packet2d& b) { return reinterpret_cast<Packet2d>(vec_cmpeq(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_lt_or_nan(const Packet2d& a, const Packet2d& b) {
+ Packet2d c = reinterpret_cast<Packet2d>(vec_cmpge(a,b));
+ return vec_nor(c,c);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_or(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_xor(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, vec_nor(b, b)); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a)
+{
+ Packet2d t = vec_add(reinterpret_cast<Packet2d>(vec_or(vec_and(reinterpret_cast<Packet2ul>(a), p2ul_SIGN), p2ul_PREV0DOT5)), a);
+ Packet2d res;
+
+ __asm__("xvrdpiz %x0, %x1\n\t"
+ : "=&wa" (res)
+ : "wa" (t));
+
+ return res;
+}
+template<> EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) { return vec_ceil(a); }
+template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) { return vec_floor(a); }
+template<> EIGEN_STRONG_INLINE Packet2d print<Packet2d>(const Packet2d& a)
+{
+ Packet2d res;
+
+ __asm__("xvrdpic %x0, %x1\n\t"
+ : "=&wa" (res)
+ : "wa" (a));
+
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from)
+{
+ EIGEN_DEBUG_UNALIGNED_LOAD
+ return vec_xl(0, const_cast<double*>(from));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from)
+{
+ Packet2d p;
+ if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet2d>(from);
+ else p = ploadu<Packet2d>(from);
+ return vec_splat_dbl<0>(p);
+}
+
+template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from)
+{
+ EIGEN_DEBUG_UNALIGNED_STORE
+ vec_xst(from, 0, to);
+}
+
+template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { EIGEN_PPC_PREFETCH(addr); }
+
+template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { EIGEN_ALIGN16 double x[2]; pstore<double>(x, a); return x[0]; }
+
+template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a)
+{
+ return reinterpret_cast<Packet2d>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE64));
+}
+template<> EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a) { return vec_abs(a); }
+
+// VSX support varies between different compilers and even different
+// versions of the same compiler. For gcc version >= 4.9.3, we can use
+// vec_cts to efficiently convert Packet2d to Packet2l. Otherwise, use
+// a slow version that works with older compilers.
+// Update: apparently vec_cts/vec_ctf intrinsics for 64-bit doubles
+// are buggy, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70963
+template<>
+inline Packet2l pcast<Packet2d, Packet2l>(const Packet2d& x) {
+#if EIGEN_GNUC_AT_LEAST(5, 4) || \
+ (EIGEN_GNUC_AT(6, 1) && __GNUC_PATCHLEVEL__ >= 1)
+ return vec_cts(x, 0); // TODO: check clang version.
+#else
+ double tmp[2];
+ memcpy(tmp, &x, sizeof(tmp));
+ Packet2l l = { static_cast<long long>(tmp[0]),
+ static_cast<long long>(tmp[1]) };
+ return l;
+#endif
+}
+
+template<>
+inline Packet2d pcast<Packet2l, Packet2d>(const Packet2l& x) {
+ unsigned long long tmp[2];
+ memcpy(tmp, &x, sizeof(tmp));
+ Packet2d d = { static_cast<double>(tmp[0]),
+ static_cast<double>(tmp[1]) };
+ return d;
+}
+
+
+// Packet2l shifts.
+// For POWER8 we simply use vec_sr/l.
+//
+// Things are more complicated for POWER7. There is actually a
+// vec_xxsxdi intrinsic but it is not supported by some gcc versions.
+// So we need to shift by N % 32 and rearrage bytes.
+#ifdef __POWER8_VECTOR__
+
+template<int N>
+EIGEN_STRONG_INLINE Packet2l plogical_shift_left(const Packet2l& a) {
+ const Packet2ul shift = { N, N };
+ return vec_sl(a, shift);
+}
+
+template<int N>
+EIGEN_STRONG_INLINE Packet2l plogical_shift_right(const Packet2l& a) {
+ const Packet2ul shift = { N, N };
+ return vec_sr(a, shift);
+}
+
+#else
+
+// Shifts [A, B, C, D] to [B, 0, D, 0].
+// Used to implement left shifts for Packet2l.
+EIGEN_ALWAYS_INLINE Packet4i shift_even_left(const Packet4i& a) {
+ static const Packet16uc perm = {
+ 0x14, 0x15, 0x16, 0x17, 0x00, 0x01, 0x02, 0x03,
+ 0x1c, 0x1d, 0x1e, 0x1f, 0x08, 0x09, 0x0a, 0x0b };
+ #ifdef _BIG_ENDIAN
+ return vec_perm(p4i_ZERO, a, perm);
+ #else
+ return vec_perm(a, p4i_ZERO, perm);
+ #endif
+}
+
+// Shifts [A, B, C, D] to [0, A, 0, C].
+// Used to implement right shifts for Packet2l.
+EIGEN_ALWAYS_INLINE Packet4i shift_odd_right(const Packet4i& a) {
+ static const Packet16uc perm = {
+ 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13,
+ 0x0c, 0x0d, 0x0e, 0x0f, 0x18, 0x19, 0x1a, 0x1b };
+ #ifdef _BIG_ENDIAN
+ return vec_perm(p4i_ZERO, a, perm);
+ #else
+ return vec_perm(a, p4i_ZERO, perm);
+ #endif
+}
+
+template<int N, typename EnableIf = void>
+struct plogical_shift_left_impl;
+
+template<int N>
+struct plogical_shift_left_impl<N, typename enable_if<(N < 32) && (N >= 0)>::type> {
+ static EIGEN_STRONG_INLINE Packet2l run(const Packet2l& a) {
+ static const unsigned n = static_cast<unsigned>(N);
+ const Packet4ui shift = {n, n, n, n};
+ const Packet4i ai = reinterpret_cast<Packet4i>(a);
+ static const unsigned m = static_cast<unsigned>(32 - N);
+ const Packet4ui shift_right = {m, m, m, m};
+ const Packet4i out_hi = vec_sl(ai, shift);
+ const Packet4i out_lo = shift_even_left(vec_sr(ai, shift_right));
+ return reinterpret_cast<Packet2l>(por<Packet4i>(out_hi, out_lo));
+ }
+};
+
+template<int N>
+struct plogical_shift_left_impl<N, typename enable_if<(N >= 32)>::type> {
+ static EIGEN_STRONG_INLINE Packet2l run(const Packet2l& a) {
+ static const unsigned m = static_cast<unsigned>(N - 32);
+ const Packet4ui shift = {m, m, m, m};
+ const Packet4i ai = reinterpret_cast<Packet4i>(a);
+ return reinterpret_cast<Packet2l>(shift_even_left(vec_sl(ai, shift)));
+ }
+};
+
+template<int N>
+EIGEN_STRONG_INLINE Packet2l plogical_shift_left(const Packet2l& a) {
+ return plogical_shift_left_impl<N>::run(a);
+}
+
+template<int N, typename EnableIf = void>
+struct plogical_shift_right_impl;
+
+template<int N>
+struct plogical_shift_right_impl<N, typename enable_if<(N < 32) && (N >= 0)>::type> {
+ static EIGEN_STRONG_INLINE Packet2l run(const Packet2l& a) {
+ static const unsigned n = static_cast<unsigned>(N);
+ const Packet4ui shift = {n, n, n, n};
+ const Packet4i ai = reinterpret_cast<Packet4i>(a);
+ static const unsigned m = static_cast<unsigned>(32 - N);
+ const Packet4ui shift_left = {m, m, m, m};
+ const Packet4i out_lo = vec_sr(ai, shift);
+ const Packet4i out_hi = shift_odd_right(vec_sl(ai, shift_left));
+ return reinterpret_cast<Packet2l>(por<Packet4i>(out_hi, out_lo));
+ }
+};
+
+template<int N>
+struct plogical_shift_right_impl<N, typename enable_if<(N >= 32)>::type> {
+ static EIGEN_STRONG_INLINE Packet2l run(const Packet2l& a) {
+ static const unsigned m = static_cast<unsigned>(N - 32);
+ const Packet4ui shift = {m, m, m, m};
+ const Packet4i ai = reinterpret_cast<Packet4i>(a);
+ return reinterpret_cast<Packet2l>(shift_odd_right(vec_sr(ai, shift)));
+ }
+};
+
+template<int N>
+EIGEN_STRONG_INLINE Packet2l plogical_shift_right(const Packet2l& a) {
+ return plogical_shift_right_impl<N>::run(a);
+}
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet2d pldexp<Packet2d>(const Packet2d& a, const Packet2d& exponent) {
+ // Clamp exponent to [-2099, 2099]
+ const Packet2d max_exponent = pset1<Packet2d>(2099.0);
+ const Packet2l e = pcast<Packet2d, Packet2l>(pmin(pmax(exponent, pnegate(max_exponent)), max_exponent));
+
+ // Split 2^e into four factors and multiply:
+ const Packet2l bias = { 1023, 1023 };
+ Packet2l b = plogical_shift_right<2>(e); // floor(e/4)
+ Packet2d c = reinterpret_cast<Packet2d>(plogical_shift_left<52>(b + bias));
+ Packet2d out = pmul(pmul(pmul(a, c), c), c); // a * 2^(3b)
+ b = psub(psub(psub(e, b), b), b); // e - 3b
+ c = reinterpret_cast<Packet2d>(plogical_shift_left<52>(b + bias)); // 2^(e - 3b)
+ out = pmul(out, c); // a * 2^e
+ return out;
+}
+
+
+// Extract exponent without existence of Packet2l.
+template<>
+EIGEN_STRONG_INLINE
+Packet2d pfrexp_generic_get_biased_exponent(const Packet2d& a) {
+ return pcast<Packet2l, Packet2d>(plogical_shift_right<52>(reinterpret_cast<Packet2l>(pabs(a))));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pfrexp<Packet2d> (const Packet2d& a, Packet2d& exponent) {
+ return pfrexp_generic(a, exponent);
+}
+
+template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a)
+{
+ Packet2d b, sum;
+ b = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(a), reinterpret_cast<Packet4f>(a), 8));
+ sum = a + b;
+ return pfirst<Packet2d>(sum);
+}
+
+// Other reduction functions:
+// mul
+template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a)
+{
+ return pfirst(pmul(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(a), reinterpret_cast<Packet4ui>(a), 8))));
+}
+
+// min
+template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a)
+{
+ return pfirst(pmin(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(a), reinterpret_cast<Packet4ui>(a), 8))));
+}
+
+// max
+template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a)
+{
+ return pfirst(pmax(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(a), reinterpret_cast<Packet4ui>(a), 8))));
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet2d,2>& kernel) {
+ Packet2d t0, t1;
+ t0 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_HI);
+ t1 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_LO);
+ kernel.packet[0] = t0;
+ kernel.packet[1] = t1;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pblend(const Selector<2>& ifPacket, const Packet2d& thenPacket, const Packet2d& elsePacket) {
+ Packet2l select = { ifPacket.select[0], ifPacket.select[1] };
+ Packet2bl mask = reinterpret_cast<Packet2bl>( vec_cmpeq(reinterpret_cast<Packet2d>(select), reinterpret_cast<Packet2d>(p2l_ONE)) );
+ return vec_sel(elsePacket, thenPacket, mask);
+}
+
+
+#endif // __VSX__
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PACKET_MATH_ALTIVEC_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/CUDA/Complex.h b/src/3rdparty/eigen/Eigen/src/Core/arch/CUDA/Complex.h
new file mode 100644
index 000000000..deb4c8694
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/CUDA/Complex.h
@@ -0,0 +1,258 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
+// Copyright (C) 2021 C. Antonio Sanchez <cantonios@google.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMPLEX_CUDA_H
+#define EIGEN_COMPLEX_CUDA_H
+
+// clang-format off
+// Many std::complex methods such as operator+, operator-, operator* and
+// operator/ are not constexpr. Due to this, GCC and older versions of clang do
+// not treat them as device functions and thus Eigen functors making use of
+// these operators fail to compile. Here, we manually specialize these
+// operators and functors for complex types when building for CUDA to enable
+// their use on-device.
+
+#if defined(EIGEN_CUDACC) && defined(EIGEN_GPU_COMPILE_PHASE)
+
+// ICC already specializes std::complex<float> and std::complex<double>
+// operators, preventing us from making them device functions here.
+// This will lead to silent runtime errors if the operators are used on device.
+//
+// To allow std::complex operator use on device, define _OVERRIDE_COMPLEX_SPECIALIZATION_
+// prior to first inclusion of <complex>. This prevents ICC from adding
+// its own specializations, so our custom ones below can be used instead.
+#if !(defined(EIGEN_COMP_ICC) && defined(_USE_COMPLEX_SPECIALIZATION_))
+
+// Import Eigen's internal operator specializations.
+#define EIGEN_USING_STD_COMPLEX_OPERATORS \
+ using Eigen::complex_operator_detail::operator+; \
+ using Eigen::complex_operator_detail::operator-; \
+ using Eigen::complex_operator_detail::operator*; \
+ using Eigen::complex_operator_detail::operator/; \
+ using Eigen::complex_operator_detail::operator+=; \
+ using Eigen::complex_operator_detail::operator-=; \
+ using Eigen::complex_operator_detail::operator*=; \
+ using Eigen::complex_operator_detail::operator/=; \
+ using Eigen::complex_operator_detail::operator==; \
+ using Eigen::complex_operator_detail::operator!=;
+
+namespace Eigen {
+
+// Specialized std::complex overloads.
+namespace complex_operator_detail {
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+std::complex<T> complex_multiply(const std::complex<T>& a, const std::complex<T>& b) {
+ const T a_real = numext::real(a);
+ const T a_imag = numext::imag(a);
+ const T b_real = numext::real(b);
+ const T b_imag = numext::imag(b);
+ return std::complex<T>(
+ a_real * b_real - a_imag * b_imag,
+ a_imag * b_real + a_real * b_imag);
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+std::complex<T> complex_divide_fast(const std::complex<T>& a, const std::complex<T>& b) {
+ const T a_real = numext::real(a);
+ const T a_imag = numext::imag(a);
+ const T b_real = numext::real(b);
+ const T b_imag = numext::imag(b);
+ const T norm = (b_real * b_real + b_imag * b_imag);
+ return std::complex<T>((a_real * b_real + a_imag * b_imag) / norm,
+ (a_imag * b_real - a_real * b_imag) / norm);
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+std::complex<T> complex_divide_stable(const std::complex<T>& a, const std::complex<T>& b) {
+ const T a_real = numext::real(a);
+ const T a_imag = numext::imag(a);
+ const T b_real = numext::real(b);
+ const T b_imag = numext::imag(b);
+ // Smith's complex division (https://arxiv.org/pdf/1210.4539.pdf),
+ // guards against over/under-flow.
+ const bool scale_imag = numext::abs(b_imag) <= numext::abs(b_real);
+ const T rscale = scale_imag ? T(1) : b_real / b_imag;
+ const T iscale = scale_imag ? b_imag / b_real : T(1);
+ const T denominator = b_real * rscale + b_imag * iscale;
+ return std::complex<T>((a_real * rscale + a_imag * iscale) / denominator,
+ (a_imag * rscale - a_real * iscale) / denominator);
+}
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+std::complex<T> complex_divide(const std::complex<T>& a, const std::complex<T>& b) {
+#if EIGEN_FAST_MATH
+ return complex_divide_fast(a, b);
+#else
+ return complex_divide_stable(a, b);
+#endif
+}
+
+// NOTE: We cannot specialize compound assignment operators with Scalar T,
+// (i.e. operator@=(const T&), for @=+,-,*,/)
+// since they are already specialized for float/double/long double within
+// the standard <complex> header. We also do not specialize the stream
+// operators.
+#define EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS(T) \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator+(const std::complex<T>& a) { return a; } \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator-(const std::complex<T>& a) { \
+ return std::complex<T>(-numext::real(a), -numext::imag(a)); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator+(const std::complex<T>& a, const std::complex<T>& b) { \
+ return std::complex<T>(numext::real(a) + numext::real(b), numext::imag(a) + numext::imag(b)); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator+(const std::complex<T>& a, const T& b) { \
+ return std::complex<T>(numext::real(a) + b, numext::imag(a)); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator+(const T& a, const std::complex<T>& b) { \
+ return std::complex<T>(a + numext::real(b), numext::imag(b)); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator-(const std::complex<T>& a, const std::complex<T>& b) { \
+ return std::complex<T>(numext::real(a) - numext::real(b), numext::imag(a) - numext::imag(b)); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator-(const std::complex<T>& a, const T& b) { \
+ return std::complex<T>(numext::real(a) - b, numext::imag(a)); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator-(const T& a, const std::complex<T>& b) { \
+ return std::complex<T>(a - numext::real(b), -numext::imag(b)); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator*(const std::complex<T>& a, const std::complex<T>& b) { \
+ return complex_multiply(a, b); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator*(const std::complex<T>& a, const T& b) { \
+ return std::complex<T>(numext::real(a) * b, numext::imag(a) * b); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator*(const T& a, const std::complex<T>& b) { \
+ return std::complex<T>(a * numext::real(b), a * numext::imag(b)); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator/(const std::complex<T>& a, const std::complex<T>& b) { \
+ return complex_divide(a, b); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator/(const std::complex<T>& a, const T& b) { \
+ return std::complex<T>(numext::real(a) / b, numext::imag(a) / b); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T> operator/(const T& a, const std::complex<T>& b) { \
+ return complex_divide(std::complex<T>(a, 0), b); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T>& operator+=(std::complex<T>& a, const std::complex<T>& b) { \
+ numext::real_ref(a) += numext::real(b); \
+ numext::imag_ref(a) += numext::imag(b); \
+ return a; \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T>& operator-=(std::complex<T>& a, const std::complex<T>& b) { \
+ numext::real_ref(a) -= numext::real(b); \
+ numext::imag_ref(a) -= numext::imag(b); \
+ return a; \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T>& operator*=(std::complex<T>& a, const std::complex<T>& b) { \
+ a = complex_multiply(a, b); \
+ return a; \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+std::complex<T>& operator/=(std::complex<T>& a, const std::complex<T>& b) { \
+ a = complex_divide(a, b); \
+ return a; \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+bool operator==(const std::complex<T>& a, const std::complex<T>& b) { \
+ return numext::real(a) == numext::real(b) && numext::imag(a) == numext::imag(b); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+bool operator==(const std::complex<T>& a, const T& b) { \
+ return numext::real(a) == b && numext::imag(a) == 0; \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+bool operator==(const T& a, const std::complex<T>& b) { \
+ return a == numext::real(b) && 0 == numext::imag(b); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+bool operator!=(const std::complex<T>& a, const std::complex<T>& b) { \
+ return !(a == b); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+bool operator!=(const std::complex<T>& a, const T& b) { \
+ return !(a == b); \
+} \
+ \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+bool operator!=(const T& a, const std::complex<T>& b) { \
+ return !(a == b); \
+}
+
+// Do not specialize for long double, since that reduces to double on device.
+EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS(float)
+EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS(double)
+
+#undef EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS
+
+
+} // namespace complex_operator_detail
+
+EIGEN_USING_STD_COMPLEX_OPERATORS
+
+namespace numext {
+EIGEN_USING_STD_COMPLEX_OPERATORS
+} // namespace numext
+
+namespace internal {
+EIGEN_USING_STD_COMPLEX_OPERATORS
+
+} // namespace internal
+} // namespace Eigen
+
+#endif // !(EIGEN_COMP_ICC && _USE_COMPLEX_SPECIALIZATION_)
+
+#endif // EIGEN_CUDACC && EIGEN_GPU_COMPILE_PHASE
+
+#endif // EIGEN_COMPLEX_CUDA_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/Default/BFloat16.h b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/BFloat16.h
new file mode 100644
index 000000000..1c28f4f95
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/BFloat16.h
@@ -0,0 +1,700 @@
+/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+
+#ifndef EIGEN_BFLOAT16_H
+#define EIGEN_BFLOAT16_H
+
+#define BF16_PACKET_FUNCTION(PACKET_F, PACKET_BF16, METHOD) \
+ template <> \
+ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED \
+ PACKET_BF16 METHOD<PACKET_BF16>(const PACKET_BF16& _x) { \
+ return F32ToBf16(METHOD<PACKET_F>(Bf16ToF32(_x))); \
+ }
+
+namespace Eigen {
+
+struct bfloat16;
+
+namespace bfloat16_impl {
+
+// Make our own __bfloat16_raw definition.
+struct __bfloat16_raw {
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __bfloat16_raw() : value(0) {}
+ explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __bfloat16_raw(unsigned short raw) : value(raw) {}
+ unsigned short value;
+};
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __bfloat16_raw raw_uint16_to_bfloat16(unsigned short value);
+template <bool AssumeArgumentIsNormalOrInfinityOrZero>
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw float_to_bfloat16_rtne(float ff);
+// Forward declarations of template specializations, to avoid Visual C++ 2019 errors, saying:
+// > error C2908: explicit specialization; 'float_to_bfloat16_rtne' has already been instantiated
+template <>
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw float_to_bfloat16_rtne<false>(float ff);
+template <>
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw float_to_bfloat16_rtne<true>(float ff);
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC float bfloat16_to_float(__bfloat16_raw h);
+
+struct bfloat16_base : public __bfloat16_raw {
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16_base() {}
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16_base(const __bfloat16_raw& h) : __bfloat16_raw(h) {}
+};
+
+} // namespace bfloat16_impl
+
+// Class definition.
+struct bfloat16 : public bfloat16_impl::bfloat16_base {
+
+ typedef bfloat16_impl::__bfloat16_raw __bfloat16_raw;
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16() {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16(const __bfloat16_raw& h) : bfloat16_impl::bfloat16_base(h) {}
+
+ explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16(bool b)
+ : bfloat16_impl::bfloat16_base(bfloat16_impl::raw_uint16_to_bfloat16(b ? 0x3f80 : 0)) {}
+
+ template<class T>
+ explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16(T val)
+ : bfloat16_impl::bfloat16_base(bfloat16_impl::float_to_bfloat16_rtne<internal::is_integral<T>::value>(static_cast<float>(val))) {}
+
+ explicit EIGEN_DEVICE_FUNC bfloat16(float f)
+ : bfloat16_impl::bfloat16_base(bfloat16_impl::float_to_bfloat16_rtne<false>(f)) {}
+
+ // Following the convention of numpy, converting between complex and
+ // float will lead to loss of imag value.
+ template<typename RealScalar>
+ explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16(const std::complex<RealScalar>& val)
+ : bfloat16_impl::bfloat16_base(bfloat16_impl::float_to_bfloat16_rtne<false>(static_cast<float>(val.real()))) {}
+
+ EIGEN_DEVICE_FUNC operator float() const { // NOLINT: Allow implicit conversion to float, because it is lossless.
+ return bfloat16_impl::bfloat16_to_float(*this);
+ }
+};
+} // namespace Eigen
+
+namespace std {
+template<>
+struct numeric_limits<Eigen::bfloat16> {
+ static const bool is_specialized = true;
+ static const bool is_signed = true;
+ static const bool is_integer = false;
+ static const bool is_exact = false;
+ static const bool has_infinity = true;
+ static const bool has_quiet_NaN = true;
+ static const bool has_signaling_NaN = true;
+ static const float_denorm_style has_denorm = std::denorm_absent;
+ static const bool has_denorm_loss = false;
+ static const std::float_round_style round_style = numeric_limits<float>::round_style;
+ static const bool is_iec559 = false;
+ static const bool is_bounded = true;
+ static const bool is_modulo = false;
+ static const int digits = 8;
+ static const int digits10 = 2;
+ static const int max_digits10 = 4;
+ static const int radix = 2;
+ static const int min_exponent = numeric_limits<float>::min_exponent;
+ static const int min_exponent10 = numeric_limits<float>::min_exponent10;
+ static const int max_exponent = numeric_limits<float>::max_exponent;
+ static const int max_exponent10 = numeric_limits<float>::max_exponent10;
+ static const bool traps = numeric_limits<float>::traps;
+ static const bool tinyness_before = numeric_limits<float>::tinyness_before;
+
+ static Eigen::bfloat16 (min)() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x0080); }
+ static Eigen::bfloat16 lowest() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0xff7f); }
+ static Eigen::bfloat16 (max)() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x7f7f); }
+ static Eigen::bfloat16 epsilon() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x3c00); }
+ static Eigen::bfloat16 round_error() { return Eigen::bfloat16(0x3f00); }
+ static Eigen::bfloat16 infinity() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x7f80); }
+ static Eigen::bfloat16 quiet_NaN() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x7fc0); }
+ static Eigen::bfloat16 signaling_NaN() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x7f81); }
+ static Eigen::bfloat16 denorm_min() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x0001); }
+};
+
+// If std::numeric_limits<T> is specialized, should also specialize
+// std::numeric_limits<const T>, std::numeric_limits<volatile T>, and
+// std::numeric_limits<const volatile T>
+// https://stackoverflow.com/a/16519653/
+template<>
+struct numeric_limits<const Eigen::bfloat16> : numeric_limits<Eigen::bfloat16> {};
+template<>
+struct numeric_limits<volatile Eigen::bfloat16> : numeric_limits<Eigen::bfloat16> {};
+template<>
+struct numeric_limits<const volatile Eigen::bfloat16> : numeric_limits<Eigen::bfloat16> {};
+} // namespace std
+
+namespace Eigen {
+
+namespace bfloat16_impl {
+
+// We need to distinguish ‘clang as the CUDA compiler’ from ‘clang as the host compiler,
+// invoked by NVCC’ (e.g. on MacOS). The former needs to see both host and device implementation
+// of the functions, while the latter can only deal with one of them.
+#if !defined(EIGEN_HAS_NATIVE_BF16) || (EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC) // Emulate support for bfloat16 floats
+
+#if EIGEN_COMP_CLANG && defined(EIGEN_CUDACC)
+// We need to provide emulated *host-side* BF16 operators for clang.
+#pragma push_macro("EIGEN_DEVICE_FUNC")
+#undef EIGEN_DEVICE_FUNC
+#if defined(EIGEN_HAS_CUDA_BF16) && defined(EIGEN_HAS_NATIVE_BF16)
+#define EIGEN_DEVICE_FUNC __host__
+#else // both host and device need emulated ops.
+#define EIGEN_DEVICE_FUNC __host__ __device__
+#endif
+#endif
+
+// Definitions for CPUs, mostly working through conversion
+// to/from fp32.
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator + (const bfloat16& a, const bfloat16& b) {
+ return bfloat16(float(a) + float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator + (const bfloat16& a, const int& b) {
+ return bfloat16(float(a) + static_cast<float>(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator + (const int& a, const bfloat16& b) {
+ return bfloat16(static_cast<float>(a) + float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator * (const bfloat16& a, const bfloat16& b) {
+ return bfloat16(float(a) * float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator - (const bfloat16& a, const bfloat16& b) {
+ return bfloat16(float(a) - float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator / (const bfloat16& a, const bfloat16& b) {
+ return bfloat16(float(a) / float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator - (const bfloat16& a) {
+ bfloat16 result;
+ result.value = a.value ^ 0x8000;
+ return result;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16& operator += (bfloat16& a, const bfloat16& b) {
+ a = bfloat16(float(a) + float(b));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16& operator *= (bfloat16& a, const bfloat16& b) {
+ a = bfloat16(float(a) * float(b));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16& operator -= (bfloat16& a, const bfloat16& b) {
+ a = bfloat16(float(a) - float(b));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16& operator /= (bfloat16& a, const bfloat16& b) {
+ a = bfloat16(float(a) / float(b));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator++(bfloat16& a) {
+ a += bfloat16(1);
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator--(bfloat16& a) {
+ a -= bfloat16(1);
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator++(bfloat16& a, int) {
+ bfloat16 original_value = a;
+ ++a;
+ return original_value;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator--(bfloat16& a, int) {
+ bfloat16 original_value = a;
+ --a;
+ return original_value;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator == (const bfloat16& a, const bfloat16& b) {
+ return numext::equal_strict(float(a),float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator != (const bfloat16& a, const bfloat16& b) {
+ return numext::not_equal_strict(float(a), float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator < (const bfloat16& a, const bfloat16& b) {
+ return float(a) < float(b);
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator <= (const bfloat16& a, const bfloat16& b) {
+ return float(a) <= float(b);
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator > (const bfloat16& a, const bfloat16& b) {
+ return float(a) > float(b);
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator >= (const bfloat16& a, const bfloat16& b) {
+ return float(a) >= float(b);
+}
+
+#if EIGEN_COMP_CLANG && defined(EIGEN_CUDACC)
+#pragma pop_macro("EIGEN_DEVICE_FUNC")
+#endif
+#endif // Emulate support for bfloat16 floats
+
+// Division by an index. Do it in full float precision to avoid accuracy
+// issues in converting the denominator to bfloat16.
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator / (const bfloat16& a, Index b) {
+ return bfloat16(static_cast<float>(a) / static_cast<float>(b));
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw truncate_to_bfloat16(const float v) {
+ __bfloat16_raw output;
+ if (Eigen::numext::isnan EIGEN_NOT_A_MACRO(v)) {
+ output.value = std::signbit(v) ? 0xFFC0: 0x7FC0;
+ return output;
+ }
+ const uint16_t* p = reinterpret_cast<const uint16_t*>(&v);
+#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ output.value = p[0];
+#else
+ output.value = p[1];
+#endif
+ return output;
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __bfloat16_raw raw_uint16_to_bfloat16(numext::uint16_t value) {
+ return __bfloat16_raw(value);
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR numext::uint16_t raw_bfloat16_as_uint16(const __bfloat16_raw& bf) {
+ return bf.value;
+}
+
+// float_to_bfloat16_rtne template specialization that does not make any
+// assumption about the value of its function argument (ff).
+template <>
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw float_to_bfloat16_rtne<false>(float ff) {
+#if (defined(EIGEN_HAS_CUDA_BF16) && defined(EIGEN_HAS_HIP_BF16))
+ // Nothing to do here
+#else
+ __bfloat16_raw output;
+
+ if (Eigen::numext::isnan EIGEN_NOT_A_MACRO(ff)) {
+ // If the value is a NaN, squash it to a qNaN with msb of fraction set,
+ // this makes sure after truncation we don't end up with an inf.
+ //
+ // qNaN magic: All exponent bits set + most significant bit of fraction
+ // set.
+ output.value = std::signbit(ff) ? 0xFFC0: 0x7FC0;
+ } else {
+ // Fast rounding algorithm that rounds a half value to nearest even. This
+ // reduces expected error when we convert a large number of floats. Here
+ // is how it works:
+ //
+ // Definitions:
+ // To convert a float 32 to bfloat16, a float 32 can be viewed as 32 bits
+ // with the following tags:
+ //
+ // Sign | Exp (8 bits) | Frac (23 bits)
+ // S EEEEEEEE FFFFFFLRTTTTTTTTTTTTTTT
+ //
+ // S: Sign bit.
+ // E: Exponent bits.
+ // F: First 6 bits of fraction.
+ // L: Least significant bit of resulting bfloat16 if we truncate away the
+ // rest of the float32. This is also the 7th bit of fraction
+ // R: Rounding bit, 8th bit of fraction.
+ // T: Sticky bits, rest of fraction, 15 bits.
+ //
+ // To round half to nearest even, there are 3 cases where we want to round
+ // down (simply truncate the result of the bits away, which consists of
+ // rounding bit and sticky bits) and two cases where we want to round up
+ // (truncate then add one to the result).
+ //
+ // The fast converting algorithm simply adds lsb (L) to 0x7fff (15 bits of
+ // 1s) as the rounding bias, adds the rounding bias to the input, then
+ // truncates the last 16 bits away.
+ //
+ // To understand how it works, we can analyze this algorithm case by case:
+ //
+ // 1. L = 0, R = 0:
+ // Expect: round down, this is less than half value.
+ //
+ // Algorithm:
+ // - Rounding bias: 0x7fff + 0 = 0x7fff
+ // - Adding rounding bias to input may create any carry, depending on
+ // whether there is any value set to 1 in T bits.
+ // - R may be set to 1 if there is a carry.
+ // - L remains 0.
+ // - Note that this case also handles Inf and -Inf, where all fraction
+ // bits, including L, R and Ts are all 0. The output remains Inf after
+ // this algorithm.
+ //
+ // 2. L = 1, R = 0:
+ // Expect: round down, this is less than half value.
+ //
+ // Algorithm:
+ // - Rounding bias: 0x7fff + 1 = 0x8000
+ // - Adding rounding bias to input doesn't change sticky bits but
+ // adds 1 to rounding bit.
+ // - L remains 1.
+ //
+ // 3. L = 0, R = 1, all of T are 0:
+ // Expect: round down, this is exactly at half, the result is already
+ // even (L=0).
+ //
+ // Algorithm:
+ // - Rounding bias: 0x7fff + 0 = 0x7fff
+ // - Adding rounding bias to input sets all sticky bits to 1, but
+ // doesn't create a carry.
+ // - R remains 1.
+ // - L remains 0.
+ //
+ // 4. L = 1, R = 1:
+ // Expect: round up, this is exactly at half, the result needs to be
+ // round to the next even number.
+ //
+ // Algorithm:
+ // - Rounding bias: 0x7fff + 1 = 0x8000
+ // - Adding rounding bias to input doesn't change sticky bits, but
+ // creates a carry from rounding bit.
+ // - The carry sets L to 0, creates another carry bit and propagate
+ // forward to F bits.
+ // - If all the F bits are 1, a carry then propagates to the exponent
+ // bits, which then creates the minimum value with the next exponent
+ // value. Note that we won't have the case where exponents are all 1,
+ // since that's either a NaN (handled in the other if condition) or inf
+ // (handled in case 1).
+ //
+ // 5. L = 0, R = 1, any of T is 1:
+ // Expect: round up, this is greater than half.
+ //
+ // Algorithm:
+ // - Rounding bias: 0x7fff + 0 = 0x7fff
+ // - Adding rounding bias to input creates a carry from sticky bits,
+ // sets rounding bit to 0, then create another carry.
+ // - The second carry sets L to 1.
+ //
+ // Examples:
+ //
+ // Exact half value that is already even:
+ // Input:
+ // Sign | Exp (8 bit) | Frac (first 7 bit) | Frac (last 16 bit)
+ // S E E E E E E E E F F F F F F L RTTTTTTTTTTTTTTT
+ // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1000000000000000
+ //
+ // This falls into case 3. We truncate the rest of 16 bits and no
+ // carry is created into F and L:
+ //
+ // Output:
+ // Sign | Exp (8 bit) | Frac (first 7 bit)
+ // S E E E E E E E E F F F F F F L
+ // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
+ //
+ // Exact half value, round to next even number:
+ // Input:
+ // Sign | Exp (8 bit) | Frac (first 7 bit) | Frac (last 16 bit)
+ // S E E E E E E E E F F F F F F L RTTTTTTTTTTTTTTT
+ // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1000000000000000
+ //
+ // This falls into case 4. We create a carry from R and T,
+ // which then propagates into L and F:
+ //
+ // Output:
+ // Sign | Exp (8 bit) | Frac (first 7 bit)
+ // S E E E E E E E E F F F F F F L
+ // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
+ //
+ //
+ // Max denormal value round to min normal value:
+ // Input:
+ // Sign | Exp (8 bit) | Frac (first 7 bit) | Frac (last 16 bit)
+ // S E E E E E E E E F F F F F F L RTTTTTTTTTTTTTTT
+ // 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1111111111111111
+ //
+ // This falls into case 4. We create a carry from R and T,
+ // propagate into L and F, which then propagates into exponent
+ // bits:
+ //
+ // Output:
+ // Sign | Exp (8 bit) | Frac (first 7 bit)
+ // S E E E E E E E E F F F F F F L
+ // 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
+ //
+ // Max normal value round to Inf:
+ // Input:
+ // Sign | Exp (8 bit) | Frac (first 7 bit) | Frac (last 16 bit)
+ // S E E E E E E E E F F F F F F L RTTTTTTTTTTTTTTT
+ // 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1111111111111111
+ //
+ // This falls into case 4. We create a carry from R and T,
+ // propagate into L and F, which then propagates into exponent
+ // bits:
+ //
+ // Sign | Exp (8 bit) | Frac (first 7 bit)
+ // S E E E E E E E E F F F F F F L
+ // 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
+
+ // At this point, ff must be either a normal float, or +/-infinity.
+ output = float_to_bfloat16_rtne<true>(ff);
+ }
+ return output;
+#endif
+}
+
+// float_to_bfloat16_rtne template specialization that assumes that its function
+// argument (ff) is either a normal floating point number, or +/-infinity, or
+// zero. Used to improve the runtime performance of conversion from an integer
+// type to bfloat16.
+template <>
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw float_to_bfloat16_rtne<true>(float ff) {
+#if (defined(EIGEN_HAS_CUDA_BF16) && defined(EIGEN_HAS_HIP_BF16))
+ // Nothing to do here
+#else
+ numext::uint32_t input = numext::bit_cast<numext::uint32_t>(ff);
+ __bfloat16_raw output;
+
+ // Least significant bit of resulting bfloat.
+ numext::uint32_t lsb = (input >> 16) & 1;
+ numext::uint32_t rounding_bias = 0x7fff + lsb;
+ input += rounding_bias;
+ output.value = static_cast<numext::uint16_t>(input >> 16);
+ return output;
+#endif
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC float bfloat16_to_float(__bfloat16_raw h) {
+ float result = 0;
+ unsigned short* q = reinterpret_cast<unsigned short*>(&result);
+#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ q[0] = h.value;
+#else
+ q[1] = h.value;
+#endif
+ return result;
+}
+// --- standard functions ---
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isinf)(const bfloat16& a) {
+ EIGEN_USING_STD(isinf);
+ return (isinf)(float(a));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isnan)(const bfloat16& a) {
+ EIGEN_USING_STD(isnan);
+ return (isnan)(float(a));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isfinite)(const bfloat16& a) {
+ return !(isinf EIGEN_NOT_A_MACRO (a)) && !(isnan EIGEN_NOT_A_MACRO (a));
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 abs(const bfloat16& a) {
+ bfloat16 result;
+ result.value = a.value & 0x7FFF;
+ return result;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 exp(const bfloat16& a) {
+ return bfloat16(::expf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 expm1(const bfloat16& a) {
+ return bfloat16(numext::expm1(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log(const bfloat16& a) {
+ return bfloat16(::logf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log1p(const bfloat16& a) {
+ return bfloat16(numext::log1p(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log10(const bfloat16& a) {
+ return bfloat16(::log10f(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log2(const bfloat16& a) {
+ return bfloat16(static_cast<float>(EIGEN_LOG2E) * ::logf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 sqrt(const bfloat16& a) {
+ return bfloat16(::sqrtf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16& a, const bfloat16& b) {
+ return bfloat16(::powf(float(a), float(b)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 sin(const bfloat16& a) {
+ return bfloat16(::sinf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 cos(const bfloat16& a) {
+ return bfloat16(::cosf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 tan(const bfloat16& a) {
+ return bfloat16(::tanf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 asin(const bfloat16& a) {
+ return bfloat16(::asinf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 acos(const bfloat16& a) {
+ return bfloat16(::acosf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 atan(const bfloat16& a) {
+ return bfloat16(::atanf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 sinh(const bfloat16& a) {
+ return bfloat16(::sinhf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 cosh(const bfloat16& a) {
+ return bfloat16(::coshf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 tanh(const bfloat16& a) {
+ return bfloat16(::tanhf(float(a)));
+}
+#if EIGEN_HAS_CXX11_MATH
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 asinh(const bfloat16& a) {
+ return bfloat16(::asinhf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 acosh(const bfloat16& a) {
+ return bfloat16(::acoshf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 atanh(const bfloat16& a) {
+ return bfloat16(::atanhf(float(a)));
+}
+#endif
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 floor(const bfloat16& a) {
+ return bfloat16(::floorf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 ceil(const bfloat16& a) {
+ return bfloat16(::ceilf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 rint(const bfloat16& a) {
+ return bfloat16(::rintf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 round(const bfloat16& a) {
+ return bfloat16(::roundf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmod(const bfloat16& a, const bfloat16& b) {
+ return bfloat16(::fmodf(float(a), float(b)));
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 (min)(const bfloat16& a, const bfloat16& b) {
+ const float f1 = static_cast<float>(a);
+ const float f2 = static_cast<float>(b);
+ return f2 < f1 ? b : a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 (max)(const bfloat16& a, const bfloat16& b) {
+ const float f1 = static_cast<float>(a);
+ const float f2 = static_cast<float>(b);
+ return f1 < f2 ? b : a;
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmin(const bfloat16& a, const bfloat16& b) {
+ const float f1 = static_cast<float>(a);
+ const float f2 = static_cast<float>(b);
+ return bfloat16(::fminf(f1, f2));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmax(const bfloat16& a, const bfloat16& b) {
+ const float f1 = static_cast<float>(a);
+ const float f2 = static_cast<float>(b);
+ return bfloat16(::fmaxf(f1, f2));
+}
+
+#ifndef EIGEN_NO_IO
+EIGEN_ALWAYS_INLINE std::ostream& operator << (std::ostream& os, const bfloat16& v) {
+ os << static_cast<float>(v);
+ return os;
+}
+#endif
+
+} // namespace bfloat16_impl
+
+namespace internal {
+
+template<>
+struct random_default_impl<bfloat16, false, false>
+{
+ static inline bfloat16 run(const bfloat16& x, const bfloat16& y)
+ {
+ return x + (y-x) * bfloat16(float(std::rand()) / float(RAND_MAX));
+ }
+ static inline bfloat16 run()
+ {
+ return run(bfloat16(-1.f), bfloat16(1.f));
+ }
+};
+
+template<> struct is_arithmetic<bfloat16> { enum { value = true }; };
+
+} // namespace internal
+
+template<> struct NumTraits<Eigen::bfloat16>
+ : GenericNumTraits<Eigen::bfloat16>
+{
+ enum {
+ IsSigned = true,
+ IsInteger = false,
+ IsComplex = false,
+ RequireInitialization = false
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::bfloat16 epsilon() {
+ return bfloat16_impl::raw_uint16_to_bfloat16(0x3c00);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::bfloat16 dummy_precision() {
+ return bfloat16_impl::raw_uint16_to_bfloat16(0x3D4D); // bfloat16(5e-2f);
+
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::bfloat16 highest() {
+ return bfloat16_impl::raw_uint16_to_bfloat16(0x7F7F);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::bfloat16 lowest() {
+ return bfloat16_impl::raw_uint16_to_bfloat16(0xFF7F);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::bfloat16 infinity() {
+ return bfloat16_impl::raw_uint16_to_bfloat16(0x7f80);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::bfloat16 quiet_NaN() {
+ return bfloat16_impl::raw_uint16_to_bfloat16(0x7fc0);
+ }
+};
+
+} // namespace Eigen
+
+namespace Eigen {
+namespace numext {
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+bool (isnan)(const Eigen::bfloat16& h) {
+ return (bfloat16_impl::isnan)(h);
+}
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+bool (isinf)(const Eigen::bfloat16& h) {
+ return (bfloat16_impl::isinf)(h);
+}
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+bool (isfinite)(const Eigen::bfloat16& h) {
+ return (bfloat16_impl::isfinite)(h);
+}
+
+template <>
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::bfloat16 bit_cast<Eigen::bfloat16, uint16_t>(const uint16_t& src) {
+ return Eigen::bfloat16(Eigen::bfloat16_impl::raw_uint16_to_bfloat16(src));
+}
+
+template <>
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC uint16_t bit_cast<uint16_t, Eigen::bfloat16>(const Eigen::bfloat16& src) {
+ return Eigen::bfloat16_impl::raw_bfloat16_as_uint16(src);
+}
+
+} // namespace numext
+} // namespace Eigen
+
+#if EIGEN_HAS_STD_HASH
+namespace std {
+template <>
+struct hash<Eigen::bfloat16> {
+ EIGEN_STRONG_INLINE std::size_t operator()(const Eigen::bfloat16& a) const {
+ return static_cast<std::size_t>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(a));
+ }
+};
+} // namespace std
+#endif
+
+
+#endif // EIGEN_BFLOAT16_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/Default/ConjHelper.h b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/ConjHelper.h
new file mode 100644
index 000000000..53830b5a2
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/ConjHelper.h
@@ -0,0 +1,117 @@
+
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ARCH_CONJ_HELPER_H
+#define EIGEN_ARCH_CONJ_HELPER_H
+
+#define EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(PACKET_CPLX, PACKET_REAL) \
+ template <> \
+ struct conj_helper<PACKET_REAL, PACKET_CPLX, false, false> { \
+ EIGEN_STRONG_INLINE PACKET_CPLX pmadd(const PACKET_REAL& x, \
+ const PACKET_CPLX& y, \
+ const PACKET_CPLX& c) const { \
+ return padd(c, this->pmul(x, y)); \
+ } \
+ EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_REAL& x, \
+ const PACKET_CPLX& y) const { \
+ return PACKET_CPLX(Eigen::internal::pmul<PACKET_REAL>(x, y.v)); \
+ } \
+ }; \
+ \
+ template <> \
+ struct conj_helper<PACKET_CPLX, PACKET_REAL, false, false> { \
+ EIGEN_STRONG_INLINE PACKET_CPLX pmadd(const PACKET_CPLX& x, \
+ const PACKET_REAL& y, \
+ const PACKET_CPLX& c) const { \
+ return padd(c, this->pmul(x, y)); \
+ } \
+ EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_CPLX& x, \
+ const PACKET_REAL& y) const { \
+ return PACKET_CPLX(Eigen::internal::pmul<PACKET_REAL>(x.v, y)); \
+ } \
+ };
+
+namespace Eigen {
+namespace internal {
+
+template<bool Conjugate> struct conj_if;
+
+template<> struct conj_if<true> {
+ template<typename T>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T& x) const { return numext::conj(x); }
+ template<typename T>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T pconj(const T& x) const { return internal::pconj(x); }
+};
+
+template<> struct conj_if<false> {
+ template<typename T>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& operator()(const T& x) const { return x; }
+ template<typename T>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& pconj(const T& x) const { return x; }
+};
+
+// Generic Implementation, assume scalars since the packet-version is
+// specialized below.
+template<typename LhsType, typename RhsType, bool ConjLhs, bool ConjRhs>
+struct conj_helper {
+ typedef typename ScalarBinaryOpTraits<LhsType, RhsType>::ReturnType ResultType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
+ pmadd(const LhsType& x, const RhsType& y, const ResultType& c) const
+ { return this->pmul(x, y) + c; }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
+ pmul(const LhsType& x, const RhsType& y) const
+ { return conj_if<ConjLhs>()(x) * conj_if<ConjRhs>()(y); }
+};
+
+template<typename LhsScalar, typename RhsScalar>
+struct conj_helper<LhsScalar, RhsScalar, true, true> {
+ typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar>::ReturnType ResultType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
+ pmadd(const LhsScalar& x, const RhsScalar& y, const ResultType& c) const
+ { return this->pmul(x, y) + c; }
+
+ // We save a conjuation by using the identity conj(a)*conj(b) = conj(a*b).
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
+ pmul(const LhsScalar& x, const RhsScalar& y) const
+ { return numext::conj(x * y); }
+};
+
+// Implementation with equal type, use packet operations.
+template<typename Packet, bool ConjLhs, bool ConjRhs>
+struct conj_helper<Packet, Packet, ConjLhs, ConjRhs>
+{
+ typedef Packet ResultType;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet& x, const Packet& y, const Packet& c) const
+ { return Eigen::internal::pmadd(conj_if<ConjLhs>().pconj(x), conj_if<ConjRhs>().pconj(y), c); }
+
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet& x, const Packet& y) const
+ { return Eigen::internal::pmul(conj_if<ConjLhs>().pconj(x), conj_if<ConjRhs>().pconj(y)); }
+};
+
+template<typename Packet>
+struct conj_helper<Packet, Packet, true, true>
+{
+ typedef Packet ResultType;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet& x, const Packet& y, const Packet& c) const
+ { return Eigen::internal::pmadd(pconj(x), pconj(y), c); }
+ // We save a conjuation by using the identity conj(a)*conj(b) = conj(a*b).
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet& x, const Packet& y) const
+ { return pconj(Eigen::internal::pmul(x, y)); }
+};
+
+} // namespace internal
+} // namespace Eigen
+
+#endif // EIGEN_ARCH_CONJ_HELPER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
new file mode 100644
index 000000000..c9fbaf68b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -0,0 +1,1649 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2007 Julien Pommier
+// Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com)
+// Copyright (C) 2009-2019 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/* The exp and log functions of this file initially come from
+ * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/
+ */
+
+#ifndef EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_H
+#define EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_H
+
+namespace Eigen {
+namespace internal {
+
+// Creates a Scalar integer type with same bit-width.
+template<typename T> struct make_integer;
+template<> struct make_integer<float> { typedef numext::int32_t type; };
+template<> struct make_integer<double> { typedef numext::int64_t type; };
+template<> struct make_integer<half> { typedef numext::int16_t type; };
+template<> struct make_integer<bfloat16> { typedef numext::int16_t type; };
+
+template<typename Packet> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+Packet pfrexp_generic_get_biased_exponent(const Packet& a) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ typedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ enum { mantissa_bits = numext::numeric_limits<Scalar>::digits - 1};
+ return pcast<PacketI, Packet>(plogical_shift_right<mantissa_bits>(preinterpret<PacketI>(pabs(a))));
+}
+
+// Safely applies frexp, correctly handles denormals.
+// Assumes IEEE floating point format.
+template<typename Packet> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+Packet pfrexp_generic(const Packet& a, Packet& exponent) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ typedef typename make_unsigned<typename make_integer<Scalar>::type>::type ScalarUI;
+ enum {
+ TotalBits = sizeof(Scalar) * CHAR_BIT,
+ MantissaBits = numext::numeric_limits<Scalar>::digits - 1,
+ ExponentBits = int(TotalBits) - int(MantissaBits) - 1
+ };
+
+ EIGEN_CONSTEXPR ScalarUI scalar_sign_mantissa_mask =
+ ~(((ScalarUI(1) << int(ExponentBits)) - ScalarUI(1)) << int(MantissaBits)); // ~0x7f800000
+ const Packet sign_mantissa_mask = pset1frombits<Packet>(static_cast<ScalarUI>(scalar_sign_mantissa_mask));
+ const Packet half = pset1<Packet>(Scalar(0.5));
+ const Packet zero = pzero(a);
+ const Packet normal_min = pset1<Packet>((numext::numeric_limits<Scalar>::min)()); // Minimum normal value, 2^-126
+
+ // To handle denormals, normalize by multiplying by 2^(int(MantissaBits)+1).
+ const Packet is_denormal = pcmp_lt(pabs(a), normal_min);
+ EIGEN_CONSTEXPR ScalarUI scalar_normalization_offset = ScalarUI(int(MantissaBits) + 1); // 24
+ // The following cannot be constexpr because bfloat16(uint16_t) is not constexpr.
+ const Scalar scalar_normalization_factor = Scalar(ScalarUI(1) << int(scalar_normalization_offset)); // 2^24
+ const Packet normalization_factor = pset1<Packet>(scalar_normalization_factor);
+ const Packet normalized_a = pselect(is_denormal, pmul(a, normalization_factor), a);
+
+ // Determine exponent offset: -126 if normal, -126-24 if denormal
+ const Scalar scalar_exponent_offset = -Scalar((ScalarUI(1)<<(int(ExponentBits)-1)) - ScalarUI(2)); // -126
+ Packet exponent_offset = pset1<Packet>(scalar_exponent_offset);
+ const Packet normalization_offset = pset1<Packet>(-Scalar(scalar_normalization_offset)); // -24
+ exponent_offset = pselect(is_denormal, padd(exponent_offset, normalization_offset), exponent_offset);
+
+ // Determine exponent and mantissa from normalized_a.
+ exponent = pfrexp_generic_get_biased_exponent(normalized_a);
+ // Zero, Inf and NaN return 'a' unmodified, exponent is zero
+ // (technically the exponent is unspecified for inf/NaN, but GCC/Clang set it to zero)
+ const Scalar scalar_non_finite_exponent = Scalar((ScalarUI(1) << int(ExponentBits)) - ScalarUI(1)); // 255
+ const Packet non_finite_exponent = pset1<Packet>(scalar_non_finite_exponent);
+ const Packet is_zero_or_not_finite = por(pcmp_eq(a, zero), pcmp_eq(exponent, non_finite_exponent));
+ const Packet m = pselect(is_zero_or_not_finite, a, por(pand(normalized_a, sign_mantissa_mask), half));
+ exponent = pselect(is_zero_or_not_finite, zero, padd(exponent, exponent_offset));
+ return m;
+}
+
+// Safely applies ldexp, correctly handles overflows, underflows and denormals.
+// Assumes IEEE floating point format.
+template<typename Packet> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+Packet pldexp_generic(const Packet& a, const Packet& exponent) {
+ // We want to return a * 2^exponent, allowing for all possible integer
+ // exponents without overflowing or underflowing in intermediate
+ // computations.
+ //
+ // Since 'a' and the output can be denormal, the maximum range of 'exponent'
+ // to consider for a float is:
+ // -255-23 -> 255+23
+ // Below -278 any finite float 'a' will become zero, and above +278 any
+ // finite float will become inf, including when 'a' is the smallest possible
+ // denormal.
+ //
+ // Unfortunately, 2^(278) cannot be represented using either one or two
+ // finite normal floats, so we must split the scale factor into at least
+ // three parts. It turns out to be faster to split 'exponent' into four
+ // factors, since [exponent>>2] is much faster to compute that [exponent/3].
+ //
+ // Set e = min(max(exponent, -278), 278);
+ // b = floor(e/4);
+ // out = ((((a * 2^(b)) * 2^(b)) * 2^(b)) * 2^(e-3*b))
+ //
+ // This will avoid any intermediate overflows and correctly handle 0, inf,
+ // NaN cases.
+ typedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ typedef typename unpacket_traits<PacketI>::type ScalarI;
+ enum {
+ TotalBits = sizeof(Scalar) * CHAR_BIT,
+ MantissaBits = numext::numeric_limits<Scalar>::digits - 1,
+ ExponentBits = int(TotalBits) - int(MantissaBits) - 1
+ };
+
+ const Packet max_exponent = pset1<Packet>(Scalar((ScalarI(1)<<int(ExponentBits)) + ScalarI(int(MantissaBits) - 1))); // 278
+ const PacketI bias = pset1<PacketI>((ScalarI(1)<<(int(ExponentBits)-1)) - ScalarI(1)); // 127
+ const PacketI e = pcast<Packet, PacketI>(pmin(pmax(exponent, pnegate(max_exponent)), max_exponent));
+ PacketI b = parithmetic_shift_right<2>(e); // floor(e/4);
+ Packet c = preinterpret<Packet>(plogical_shift_left<int(MantissaBits)>(padd(b, bias))); // 2^b
+ Packet out = pmul(pmul(pmul(a, c), c), c); // a * 2^(3b)
+ b = psub(psub(psub(e, b), b), b); // e - 3b
+ c = preinterpret<Packet>(plogical_shift_left<int(MantissaBits)>(padd(b, bias))); // 2^(e-3*b)
+ out = pmul(out, c);
+ return out;
+}
+
+// Explicitly multiplies
+// a * (2^e)
+// clamping e to the range
+// [NumTraits<Scalar>::min_exponent()-2, NumTraits<Scalar>::max_exponent()]
+//
+// This is approx 7x faster than pldexp_impl, but will prematurely over/underflow
+// if 2^e doesn't fit into a normal floating-point Scalar.
+//
+// Assumes IEEE floating point format
+template<typename Packet>
+struct pldexp_fast_impl {
+ typedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ typedef typename unpacket_traits<PacketI>::type ScalarI;
+ enum {
+ TotalBits = sizeof(Scalar) * CHAR_BIT,
+ MantissaBits = numext::numeric_limits<Scalar>::digits - 1,
+ ExponentBits = int(TotalBits) - int(MantissaBits) - 1
+ };
+
+ static EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+ Packet run(const Packet& a, const Packet& exponent) {
+ const Packet bias = pset1<Packet>(Scalar((ScalarI(1)<<(int(ExponentBits)-1)) - ScalarI(1))); // 127
+ const Packet limit = pset1<Packet>(Scalar((ScalarI(1)<<int(ExponentBits)) - ScalarI(1))); // 255
+ // restrict biased exponent between 0 and 255 for float.
+ const PacketI e = pcast<Packet, PacketI>(pmin(pmax(padd(exponent, bias), pzero(limit)), limit)); // exponent + 127
+ // return a * (2^e)
+ return pmul(a, preinterpret<Packet>(plogical_shift_left<int(MantissaBits)>(e)));
+ }
+};
+
+// Natural or base 2 logarithm.
+// Computes log(x) as log(2^e * m) = C*e + log(m), where the constant C =log(2)
+// and m is in the range [sqrt(1/2),sqrt(2)). In this range, the logarithm can
+// be easily approximated by a polynomial centered on m=1 for stability.
+// TODO(gonnet): Further reduce the interval allowing for lower-degree
+// polynomial interpolants -> ... -> profit!
+template <typename Packet, bool base2>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet plog_impl_float(const Packet _x)
+{
+ Packet x = _x;
+
+ const Packet cst_1 = pset1<Packet>(1.0f);
+ const Packet cst_neg_half = pset1<Packet>(-0.5f);
+ // The smallest non denormalized float number.
+ const Packet cst_min_norm_pos = pset1frombits<Packet>( 0x00800000u);
+ const Packet cst_minus_inf = pset1frombits<Packet>( 0xff800000u);
+ const Packet cst_pos_inf = pset1frombits<Packet>( 0x7f800000u);
+
+ // Polynomial coefficients.
+ const Packet cst_cephes_SQRTHF = pset1<Packet>(0.707106781186547524f);
+ const Packet cst_cephes_log_p0 = pset1<Packet>(7.0376836292E-2f);
+ const Packet cst_cephes_log_p1 = pset1<Packet>(-1.1514610310E-1f);
+ const Packet cst_cephes_log_p2 = pset1<Packet>(1.1676998740E-1f);
+ const Packet cst_cephes_log_p3 = pset1<Packet>(-1.2420140846E-1f);
+ const Packet cst_cephes_log_p4 = pset1<Packet>(+1.4249322787E-1f);
+ const Packet cst_cephes_log_p5 = pset1<Packet>(-1.6668057665E-1f);
+ const Packet cst_cephes_log_p6 = pset1<Packet>(+2.0000714765E-1f);
+ const Packet cst_cephes_log_p7 = pset1<Packet>(-2.4999993993E-1f);
+ const Packet cst_cephes_log_p8 = pset1<Packet>(+3.3333331174E-1f);
+
+ // Truncate input values to the minimum positive normal.
+ x = pmax(x, cst_min_norm_pos);
+
+ Packet e;
+ // extract significant in the range [0.5,1) and exponent
+ x = pfrexp(x,e);
+
+ // part2: Shift the inputs from the range [0.5,1) to [sqrt(1/2),sqrt(2))
+ // and shift by -1. The values are then centered around 0, which improves
+ // the stability of the polynomial evaluation.
+ // if( x < SQRTHF ) {
+ // e -= 1;
+ // x = x + x - 1.0;
+ // } else { x = x - 1.0; }
+ Packet mask = pcmp_lt(x, cst_cephes_SQRTHF);
+ Packet tmp = pand(x, mask);
+ x = psub(x, cst_1);
+ e = psub(e, pand(cst_1, mask));
+ x = padd(x, tmp);
+
+ Packet x2 = pmul(x, x);
+ Packet x3 = pmul(x2, x);
+
+ // Evaluate the polynomial approximant of degree 8 in three parts, probably
+ // to improve instruction-level parallelism.
+ Packet y, y1, y2;
+ y = pmadd(cst_cephes_log_p0, x, cst_cephes_log_p1);
+ y1 = pmadd(cst_cephes_log_p3, x, cst_cephes_log_p4);
+ y2 = pmadd(cst_cephes_log_p6, x, cst_cephes_log_p7);
+ y = pmadd(y, x, cst_cephes_log_p2);
+ y1 = pmadd(y1, x, cst_cephes_log_p5);
+ y2 = pmadd(y2, x, cst_cephes_log_p8);
+ y = pmadd(y, x3, y1);
+ y = pmadd(y, x3, y2);
+ y = pmul(y, x3);
+
+ y = pmadd(cst_neg_half, x2, y);
+ x = padd(x, y);
+
+ // Add the logarithm of the exponent back to the result of the interpolation.
+ if (base2) {
+ const Packet cst_log2e = pset1<Packet>(static_cast<float>(EIGEN_LOG2E));
+ x = pmadd(x, cst_log2e, e);
+ } else {
+ const Packet cst_ln2 = pset1<Packet>(static_cast<float>(EIGEN_LN2));
+ x = pmadd(e, cst_ln2, x);
+ }
+
+ Packet invalid_mask = pcmp_lt_or_nan(_x, pzero(_x));
+ Packet iszero_mask = pcmp_eq(_x,pzero(_x));
+ Packet pos_inf_mask = pcmp_eq(_x,cst_pos_inf);
+ // Filter out invalid inputs, i.e.:
+ // - negative arg will be NAN
+ // - 0 will be -INF
+ // - +INF will be +INF
+ return pselect(iszero_mask, cst_minus_inf,
+ por(pselect(pos_inf_mask,cst_pos_inf,x), invalid_mask));
+}
+
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet plog_float(const Packet _x)
+{
+ return plog_impl_float<Packet, /* base2 */ false>(_x);
+}
+
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet plog2_float(const Packet _x)
+{
+ return plog_impl_float<Packet, /* base2 */ true>(_x);
+}
+
+/* Returns the base e (2.718...) or base 2 logarithm of x.
+ * The argument is separated into its exponent and fractional parts.
+ * The logarithm of the fraction in the interval [sqrt(1/2), sqrt(2)],
+ * is approximated by
+ *
+ * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).
+ *
+ * for more detail see: http://www.netlib.org/cephes/
+ */
+template <typename Packet, bool base2>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet plog_impl_double(const Packet _x)
+{
+ Packet x = _x;
+
+ const Packet cst_1 = pset1<Packet>(1.0);
+ const Packet cst_neg_half = pset1<Packet>(-0.5);
+ // The smallest non denormalized double.
+ const Packet cst_min_norm_pos = pset1frombits<Packet>( static_cast<uint64_t>(0x0010000000000000ull));
+ const Packet cst_minus_inf = pset1frombits<Packet>( static_cast<uint64_t>(0xfff0000000000000ull));
+ const Packet cst_pos_inf = pset1frombits<Packet>( static_cast<uint64_t>(0x7ff0000000000000ull));
+
+
+ // Polynomial Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x)
+ // 1/sqrt(2) <= x < sqrt(2)
+ const Packet cst_cephes_SQRTHF = pset1<Packet>(0.70710678118654752440E0);
+ const Packet cst_cephes_log_p0 = pset1<Packet>(1.01875663804580931796E-4);
+ const Packet cst_cephes_log_p1 = pset1<Packet>(4.97494994976747001425E-1);
+ const Packet cst_cephes_log_p2 = pset1<Packet>(4.70579119878881725854E0);
+ const Packet cst_cephes_log_p3 = pset1<Packet>(1.44989225341610930846E1);
+ const Packet cst_cephes_log_p4 = pset1<Packet>(1.79368678507819816313E1);
+ const Packet cst_cephes_log_p5 = pset1<Packet>(7.70838733755885391666E0);
+
+ const Packet cst_cephes_log_q0 = pset1<Packet>(1.0);
+ const Packet cst_cephes_log_q1 = pset1<Packet>(1.12873587189167450590E1);
+ const Packet cst_cephes_log_q2 = pset1<Packet>(4.52279145837532221105E1);
+ const Packet cst_cephes_log_q3 = pset1<Packet>(8.29875266912776603211E1);
+ const Packet cst_cephes_log_q4 = pset1<Packet>(7.11544750618563894466E1);
+ const Packet cst_cephes_log_q5 = pset1<Packet>(2.31251620126765340583E1);
+
+ // Truncate input values to the minimum positive normal.
+ x = pmax(x, cst_min_norm_pos);
+
+ Packet e;
+ // extract significant in the range [0.5,1) and exponent
+ x = pfrexp(x,e);
+
+ // Shift the inputs from the range [0.5,1) to [sqrt(1/2),sqrt(2))
+ // and shift by -1. The values are then centered around 0, which improves
+ // the stability of the polynomial evaluation.
+ // if( x < SQRTHF ) {
+ // e -= 1;
+ // x = x + x - 1.0;
+ // } else { x = x - 1.0; }
+ Packet mask = pcmp_lt(x, cst_cephes_SQRTHF);
+ Packet tmp = pand(x, mask);
+ x = psub(x, cst_1);
+ e = psub(e, pand(cst_1, mask));
+ x = padd(x, tmp);
+
+ Packet x2 = pmul(x, x);
+ Packet x3 = pmul(x2, x);
+
+ // Evaluate the polynomial approximant , probably to improve instruction-level parallelism.
+ // y = x - 0.5*x^2 + x^3 * polevl( x, P, 5 ) / p1evl( x, Q, 5 ) );
+ Packet y, y1, y_;
+ y = pmadd(cst_cephes_log_p0, x, cst_cephes_log_p1);
+ y1 = pmadd(cst_cephes_log_p3, x, cst_cephes_log_p4);
+ y = pmadd(y, x, cst_cephes_log_p2);
+ y1 = pmadd(y1, x, cst_cephes_log_p5);
+ y_ = pmadd(y, x3, y1);
+
+ y = pmadd(cst_cephes_log_q0, x, cst_cephes_log_q1);
+ y1 = pmadd(cst_cephes_log_q3, x, cst_cephes_log_q4);
+ y = pmadd(y, x, cst_cephes_log_q2);
+ y1 = pmadd(y1, x, cst_cephes_log_q5);
+ y = pmadd(y, x3, y1);
+
+ y_ = pmul(y_, x3);
+ y = pdiv(y_, y);
+
+ y = pmadd(cst_neg_half, x2, y);
+ x = padd(x, y);
+
+ // Add the logarithm of the exponent back to the result of the interpolation.
+ if (base2) {
+ const Packet cst_log2e = pset1<Packet>(static_cast<double>(EIGEN_LOG2E));
+ x = pmadd(x, cst_log2e, e);
+ } else {
+ const Packet cst_ln2 = pset1<Packet>(static_cast<double>(EIGEN_LN2));
+ x = pmadd(e, cst_ln2, x);
+ }
+
+ Packet invalid_mask = pcmp_lt_or_nan(_x, pzero(_x));
+ Packet iszero_mask = pcmp_eq(_x,pzero(_x));
+ Packet pos_inf_mask = pcmp_eq(_x,cst_pos_inf);
+ // Filter out invalid inputs, i.e.:
+ // - negative arg will be NAN
+ // - 0 will be -INF
+ // - +INF will be +INF
+ return pselect(iszero_mask, cst_minus_inf,
+ por(pselect(pos_inf_mask,cst_pos_inf,x), invalid_mask));
+}
+
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet plog_double(const Packet _x)
+{
+ return plog_impl_double<Packet, /* base2 */ false>(_x);
+}
+
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet plog2_double(const Packet _x)
+{
+ return plog_impl_double<Packet, /* base2 */ true>(_x);
+}
+
+/** \internal \returns log(1 + x) computed using W. Kahan's formula.
+ See: http://www.plunk.org/~hatch/rightway.php
+ */
+template<typename Packet>
+Packet generic_plog1p(const Packet& x)
+{
+ typedef typename unpacket_traits<Packet>::type ScalarType;
+ const Packet one = pset1<Packet>(ScalarType(1));
+ Packet xp1 = padd(x, one);
+ Packet small_mask = pcmp_eq(xp1, one);
+ Packet log1 = plog(xp1);
+ Packet inf_mask = pcmp_eq(xp1, log1);
+ Packet log_large = pmul(x, pdiv(log1, psub(xp1, one)));
+ return pselect(por(small_mask, inf_mask), x, log_large);
+}
+
+/** \internal \returns exp(x)-1 computed using W. Kahan's formula.
+ See: http://www.plunk.org/~hatch/rightway.php
+ */
+template<typename Packet>
+Packet generic_expm1(const Packet& x)
+{
+ typedef typename unpacket_traits<Packet>::type ScalarType;
+ const Packet one = pset1<Packet>(ScalarType(1));
+ const Packet neg_one = pset1<Packet>(ScalarType(-1));
+ Packet u = pexp(x);
+ Packet one_mask = pcmp_eq(u, one);
+ Packet u_minus_one = psub(u, one);
+ Packet neg_one_mask = pcmp_eq(u_minus_one, neg_one);
+ Packet logu = plog(u);
+ // The following comparison is to catch the case where
+ // exp(x) = +inf. It is written in this way to avoid having
+ // to form the constant +inf, which depends on the packet
+ // type.
+ Packet pos_inf_mask = pcmp_eq(logu, u);
+ Packet expm1 = pmul(u_minus_one, pdiv(x, logu));
+ expm1 = pselect(pos_inf_mask, u, expm1);
+ return pselect(one_mask,
+ x,
+ pselect(neg_one_mask,
+ neg_one,
+ expm1));
+}
+
+
+// Exponential function. Works by writing "x = m*log(2) + r" where
+// "m = floor(x/log(2)+1/2)" and "r" is the remainder. The result is then
+// "exp(x) = 2^m*exp(r)" where exp(r) is in the range [-1,1).
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet pexp_float(const Packet _x)
+{
+ const Packet cst_1 = pset1<Packet>(1.0f);
+ const Packet cst_half = pset1<Packet>(0.5f);
+ const Packet cst_exp_hi = pset1<Packet>( 88.723f);
+ const Packet cst_exp_lo = pset1<Packet>(-88.723f);
+
+ const Packet cst_cephes_LOG2EF = pset1<Packet>(1.44269504088896341f);
+ const Packet cst_cephes_exp_p0 = pset1<Packet>(1.9875691500E-4f);
+ const Packet cst_cephes_exp_p1 = pset1<Packet>(1.3981999507E-3f);
+ const Packet cst_cephes_exp_p2 = pset1<Packet>(8.3334519073E-3f);
+ const Packet cst_cephes_exp_p3 = pset1<Packet>(4.1665795894E-2f);
+ const Packet cst_cephes_exp_p4 = pset1<Packet>(1.6666665459E-1f);
+ const Packet cst_cephes_exp_p5 = pset1<Packet>(5.0000001201E-1f);
+
+ // Clamp x.
+ Packet x = pmax(pmin(_x, cst_exp_hi), cst_exp_lo);
+
+ // Express exp(x) as exp(m*ln(2) + r), start by extracting
+ // m = floor(x/ln(2) + 0.5).
+ Packet m = pfloor(pmadd(x, cst_cephes_LOG2EF, cst_half));
+
+ // Get r = x - m*ln(2). If no FMA instructions are available, m*ln(2) is
+ // subtracted out in two parts, m*C1+m*C2 = m*ln(2), to avoid accumulating
+ // truncation errors.
+ const Packet cst_cephes_exp_C1 = pset1<Packet>(-0.693359375f);
+ const Packet cst_cephes_exp_C2 = pset1<Packet>(2.12194440e-4f);
+ Packet r = pmadd(m, cst_cephes_exp_C1, x);
+ r = pmadd(m, cst_cephes_exp_C2, r);
+
+ Packet r2 = pmul(r, r);
+ Packet r3 = pmul(r2, r);
+
+ // Evaluate the polynomial approximant,improved by instruction-level parallelism.
+ Packet y, y1, y2;
+ y = pmadd(cst_cephes_exp_p0, r, cst_cephes_exp_p1);
+ y1 = pmadd(cst_cephes_exp_p3, r, cst_cephes_exp_p4);
+ y2 = padd(r, cst_1);
+ y = pmadd(y, r, cst_cephes_exp_p2);
+ y1 = pmadd(y1, r, cst_cephes_exp_p5);
+ y = pmadd(y, r3, y1);
+ y = pmadd(y, r2, y2);
+
+ // Return 2^m * exp(r).
+ // TODO: replace pldexp with faster implementation since y in [-1, 1).
+ return pmax(pldexp(y,m), _x);
+}
+
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet pexp_double(const Packet _x)
+{
+ Packet x = _x;
+
+ const Packet cst_1 = pset1<Packet>(1.0);
+ const Packet cst_2 = pset1<Packet>(2.0);
+ const Packet cst_half = pset1<Packet>(0.5);
+
+ const Packet cst_exp_hi = pset1<Packet>(709.784);
+ const Packet cst_exp_lo = pset1<Packet>(-709.784);
+
+ const Packet cst_cephes_LOG2EF = pset1<Packet>(1.4426950408889634073599);
+ const Packet cst_cephes_exp_p0 = pset1<Packet>(1.26177193074810590878e-4);
+ const Packet cst_cephes_exp_p1 = pset1<Packet>(3.02994407707441961300e-2);
+ const Packet cst_cephes_exp_p2 = pset1<Packet>(9.99999999999999999910e-1);
+ const Packet cst_cephes_exp_q0 = pset1<Packet>(3.00198505138664455042e-6);
+ const Packet cst_cephes_exp_q1 = pset1<Packet>(2.52448340349684104192e-3);
+ const Packet cst_cephes_exp_q2 = pset1<Packet>(2.27265548208155028766e-1);
+ const Packet cst_cephes_exp_q3 = pset1<Packet>(2.00000000000000000009e0);
+ const Packet cst_cephes_exp_C1 = pset1<Packet>(0.693145751953125);
+ const Packet cst_cephes_exp_C2 = pset1<Packet>(1.42860682030941723212e-6);
+
+ Packet tmp, fx;
+
+ // clamp x
+ x = pmax(pmin(x, cst_exp_hi), cst_exp_lo);
+ // Express exp(x) as exp(g + n*log(2)).
+ fx = pmadd(cst_cephes_LOG2EF, x, cst_half);
+
+ // Get the integer modulus of log(2), i.e. the "n" described above.
+ fx = pfloor(fx);
+
+ // Get the remainder modulo log(2), i.e. the "g" described above. Subtract
+ // n*log(2) out in two steps, i.e. n*C1 + n*C2, C1+C2=log2 to get the last
+ // digits right.
+ tmp = pmul(fx, cst_cephes_exp_C1);
+ Packet z = pmul(fx, cst_cephes_exp_C2);
+ x = psub(x, tmp);
+ x = psub(x, z);
+
+ Packet x2 = pmul(x, x);
+
+ // Evaluate the numerator polynomial of the rational interpolant.
+ Packet px = cst_cephes_exp_p0;
+ px = pmadd(px, x2, cst_cephes_exp_p1);
+ px = pmadd(px, x2, cst_cephes_exp_p2);
+ px = pmul(px, x);
+
+ // Evaluate the denominator polynomial of the rational interpolant.
+ Packet qx = cst_cephes_exp_q0;
+ qx = pmadd(qx, x2, cst_cephes_exp_q1);
+ qx = pmadd(qx, x2, cst_cephes_exp_q2);
+ qx = pmadd(qx, x2, cst_cephes_exp_q3);
+
+ // I don't really get this bit, copied from the SSE2 routines, so...
+ // TODO(gonnet): Figure out what is going on here, perhaps find a better
+ // rational interpolant?
+ x = pdiv(px, psub(qx, px));
+ x = pmadd(cst_2, x, cst_1);
+
+ // Construct the result 2^n * exp(g) = e * x. The max is used to catch
+ // non-finite values in the input.
+ // TODO: replace pldexp with faster implementation since x in [-1, 1).
+ return pmax(pldexp(x,fx), _x);
+}
+
+// The following code is inspired by the following stack-overflow answer:
+// https://stackoverflow.com/questions/30463616/payne-hanek-algorithm-implementation-in-c/30465751#30465751
+// It has been largely optimized:
+// - By-pass calls to frexp.
+// - Aligned loads of required 96 bits of 2/pi. This is accomplished by
+// (1) balancing the mantissa and exponent to the required bits of 2/pi are
+// aligned on 8-bits, and (2) replicating the storage of the bits of 2/pi.
+// - Avoid a branch in rounding and extraction of the remaining fractional part.
+// Overall, I measured a speed up higher than x2 on x86-64.
+inline float trig_reduce_huge (float xf, int *quadrant)
+{
+ using Eigen::numext::int32_t;
+ using Eigen::numext::uint32_t;
+ using Eigen::numext::int64_t;
+ using Eigen::numext::uint64_t;
+
+ const double pio2_62 = 3.4061215800865545e-19; // pi/2 * 2^-62
+ const uint64_t zero_dot_five = uint64_t(1) << 61; // 0.5 in 2.62-bit fixed-point foramt
+
+ // 192 bits of 2/pi for Payne-Hanek reduction
+ // Bits are introduced by packet of 8 to enable aligned reads.
+ static const uint32_t two_over_pi [] =
+ {
+ 0x00000028, 0x000028be, 0x0028be60, 0x28be60db,
+ 0xbe60db93, 0x60db9391, 0xdb939105, 0x9391054a,
+ 0x91054a7f, 0x054a7f09, 0x4a7f09d5, 0x7f09d5f4,
+ 0x09d5f47d, 0xd5f47d4d, 0xf47d4d37, 0x7d4d3770,
+ 0x4d377036, 0x377036d8, 0x7036d8a5, 0x36d8a566,
+ 0xd8a5664f, 0xa5664f10, 0x664f10e4, 0x4f10e410,
+ 0x10e41000, 0xe4100000
+ };
+
+ uint32_t xi = numext::bit_cast<uint32_t>(xf);
+ // Below, -118 = -126 + 8.
+ // -126 is to get the exponent,
+ // +8 is to enable alignment of 2/pi's bits on 8 bits.
+ // This is possible because the fractional part of x as only 24 meaningful bits.
+ uint32_t e = (xi >> 23) - 118;
+ // Extract the mantissa and shift it to align it wrt the exponent
+ xi = ((xi & 0x007fffffu)| 0x00800000u) << (e & 0x7);
+
+ uint32_t i = e >> 3;
+ uint32_t twoopi_1 = two_over_pi[i-1];
+ uint32_t twoopi_2 = two_over_pi[i+3];
+ uint32_t twoopi_3 = two_over_pi[i+7];
+
+ // Compute x * 2/pi in 2.62-bit fixed-point format.
+ uint64_t p;
+ p = uint64_t(xi) * twoopi_3;
+ p = uint64_t(xi) * twoopi_2 + (p >> 32);
+ p = (uint64_t(xi * twoopi_1) << 32) + p;
+
+ // Round to nearest: add 0.5 and extract integral part.
+ uint64_t q = (p + zero_dot_five) >> 62;
+ *quadrant = int(q);
+ // Now it remains to compute "r = x - q*pi/2" with high accuracy,
+ // since we have p=x/(pi/2) with high accuracy, we can more efficiently compute r as:
+ // r = (p-q)*pi/2,
+ // where the product can be be carried out with sufficient accuracy using double precision.
+ p -= q<<62;
+ return float(double(int64_t(p)) * pio2_62);
+}
+
+template<bool ComputeSine,typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+#if EIGEN_GNUC_AT_LEAST(4,4) && EIGEN_COMP_GNUC_STRICT
+__attribute__((optimize("-fno-unsafe-math-optimizations")))
+#endif
+Packet psincos_float(const Packet& _x)
+{
+ typedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ const PacketI csti_1 = pset1<PacketI>(1);
+ const Packet cst_sign_mask = pset1frombits<Packet>(0x80000000u);
+
+ Packet x = pabs(_x);
+
+ // Scale x by 2/Pi to find x's octant.
+ Packet y = pmul(x, cst_2oPI);
+
+ // Rounding trick:
+ Packet y_round = padd(y, cst_rounding_magic);
+ EIGEN_OPTIMIZATION_BARRIER(y_round)
+ PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ y = psub(y_round, cst_rounding_magic); // nearest integer to x*4/pi
+
+ // Reduce x by y octants to get: -Pi/4 <= x <= +Pi/4
+ // using "Extended precision modular arithmetic"
+ #if defined(EIGEN_HAS_SINGLE_INSTRUCTION_MADD)
+ // This version requires true FMA for high accuracy
+ // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ const float huge_th = ComputeSine ? 117435.992f : 71476.0625f;
+ x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ #else
+ // Without true FMA, the previous set of coefficients maintain 1ULP accuracy
+ // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7.
+ // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs.
+
+ // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively.
+ // and 2 ULP up to:
+ const float huge_th = ComputeSine ? 25966.f : 18838.f;
+ x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ EIGEN_OPTIMIZATION_BARRIER(x)
+ x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ EIGEN_OPTIMIZATION_BARRIER(x)
+ x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ // For the record, the following set of coefficients maintain 2ULP up
+ // to a slightly larger range:
+ // const float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ // but it slightly fails to maintain 1ULP for two values of sin below pi.
+ // x = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ // x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ // x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ // x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ // For the record, with only 3 iterations it is possible to maintain
+ // 1 ULP up to 3PI (maybe more) and 2ULP up to 255.
+ // The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ #endif
+
+ if(predux_any(pcmp_le(pset1<Packet>(huge_th),pabs(_x))))
+ {
+ const int PacketSize = unpacket_traits<Packet>::size;
+ EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
+ EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
+ EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) int y_int2[PacketSize];
+ pstoreu(vals, pabs(_x));
+ pstoreu(x_cpy, x);
+ pstoreu(y_int2, y_int);
+ for(int k=0; k<PacketSize;++k)
+ {
+ float val = vals[k];
+ if(val>=huge_th && (numext::isfinite)(val))
+ x_cpy[k] = trig_reduce_huge(val,&y_int2[k]);
+ }
+ x = ploadu<Packet>(x_cpy);
+ y_int = ploadu<PacketI>(y_int2);
+ }
+
+ // Compute the sign to apply to the polynomial.
+ // sin: sign = second_bit(y_int) xor signbit(_x)
+ // cos: sign = second_bit(y_int+1)
+ Packet sign_bit = ComputeSine ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int,csti_1)));
+ sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+
+ // Get the polynomial selection mask from the second bit of y_int
+ // We'll calculate both (sin and cos) polynomials and then select from the two.
+ Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ Packet x2 = pmul(x,x);
+
+ // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f ));
+ y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f ));
+ y1 = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ y1 = pmadd(y1, x2, pset1<Packet>(1.f));
+
+ // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4)
+ // octave/matlab code to compute those coefficients:
+ // x = (0:0.0001:pi/4)';
+ // A = [x.^3 x.^5 x.^7];
+ // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy
+ // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1
+ // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+ //
+ Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ y2 = pmadd(y2, x2, pset1<Packet>( 0.0083326873655616851693794799871284340042620897293090820312500000f));
+ y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ y2 = pmul(y2, x2);
+ y2 = pmadd(y2, x, x);
+
+ // Select the correct result from the two polynomials.
+ y = ComputeSine ? pselect(poly_mask,y2,y1)
+ : pselect(poly_mask,y1,y2);
+
+ // Update the sign and filter huge inputs
+ return pxor(y, sign_bit);
+}
+
+template<typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet psin_float(const Packet& x)
+{
+ return psincos_float<true>(x);
+}
+
+template<typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet pcos_float(const Packet& x)
+{
+ return psincos_float<false>(x);
+}
+
+
+template<typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet psqrt_complex(const Packet& a) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ typedef typename Scalar::value_type RealScalar;
+ typedef typename unpacket_traits<Packet>::as_real RealPacket;
+
+ // Computes the principal sqrt of the complex numbers in the input.
+ //
+ // For example, for packets containing 2 complex numbers stored in interleaved format
+ // a = [a0, a1] = [x0, y0, x1, y1],
+ // where x0 = real(a0), y0 = imag(a0) etc., this function returns
+ // b = [b0, b1] = [u0, v0, u1, v1],
+ // such that b0^2 = a0, b1^2 = a1.
+ //
+ // To derive the formula for the complex square roots, let's consider the equation for
+ // a single complex square root of the number x + i*y. We want to find real numbers
+ // u and v such that
+ // (u + i*v)^2 = x + i*y <=>
+ // u^2 - v^2 + i*2*u*v = x + i*v.
+ // By equating the real and imaginary parts we get:
+ // u^2 - v^2 = x
+ // 2*u*v = y.
+ //
+ // For x >= 0, this has the numerically stable solution
+ // u = sqrt(0.5 * (x + sqrt(x^2 + y^2)))
+ // v = 0.5 * (y / u)
+ // and for x < 0,
+ // v = sign(y) * sqrt(0.5 * (-x + sqrt(x^2 + y^2)))
+ // u = 0.5 * (y / v)
+ //
+ // To avoid unnecessary over- and underflow, we compute sqrt(x^2 + y^2) as
+ // l = max(|x|, |y|) * sqrt(1 + (min(|x|, |y|) / max(|x|, |y|))^2) ,
+
+ // In the following, without lack of generality, we have annotated the code, assuming
+ // that the input is a packet of 2 complex numbers.
+ //
+ // Step 1. Compute l = [l0, l0, l1, l1], where
+ // l0 = sqrt(x0^2 + y0^2), l1 = sqrt(x1^2 + y1^2)
+ // To avoid over- and underflow, we use the stable formula for each hypotenuse
+ // l0 = (min0 == 0 ? max0 : max0 * sqrt(1 + (min0/max0)**2)),
+ // where max0 = max(|x0|, |y0|), min0 = min(|x0|, |y0|), and similarly for l1.
+
+ RealPacket a_abs = pabs(a.v); // [|x0|, |y0|, |x1|, |y1|]
+ RealPacket a_abs_flip = pcplxflip(Packet(a_abs)).v; // [|y0|, |x0|, |y1|, |x1|]
+ RealPacket a_max = pmax(a_abs, a_abs_flip);
+ RealPacket a_min = pmin(a_abs, a_abs_flip);
+ RealPacket a_min_zero_mask = pcmp_eq(a_min, pzero(a_min));
+ RealPacket a_max_zero_mask = pcmp_eq(a_max, pzero(a_max));
+ RealPacket r = pdiv(a_min, a_max);
+ const RealPacket cst_one = pset1<RealPacket>(RealScalar(1));
+ RealPacket l = pmul(a_max, psqrt(padd(cst_one, pmul(r, r)))); // [l0, l0, l1, l1]
+ // Set l to a_max if a_min is zero.
+ l = pselect(a_min_zero_mask, a_max, l);
+
+ // Step 2. Compute [rho0, *, rho1, *], where
+ // rho0 = sqrt(0.5 * (l0 + |x0|)), rho1 = sqrt(0.5 * (l1 + |x1|))
+ // We don't care about the imaginary parts computed here. They will be overwritten later.
+ const RealPacket cst_half = pset1<RealPacket>(RealScalar(0.5));
+ Packet rho;
+ rho.v = psqrt(pmul(cst_half, padd(a_abs, l)));
+
+ // Step 3. Compute [rho0, eta0, rho1, eta1], where
+ // eta0 = (y0 / l0) / 2, and eta1 = (y1 / l1) / 2.
+ // set eta = 0 of input is 0 + i0.
+ RealPacket eta = pandnot(pmul(cst_half, pdiv(a.v, pcplxflip(rho).v)), a_max_zero_mask);
+ RealPacket real_mask = peven_mask(a.v);
+ Packet positive_real_result;
+ // Compute result for inputs with positive real part.
+ positive_real_result.v = pselect(real_mask, rho.v, eta);
+
+ // Step 4. Compute solution for inputs with negative real part:
+ // [|eta0|, sign(y0)*rho0, |eta1|, sign(y1)*rho1]
+ const RealScalar neg_zero = RealScalar(numext::bit_cast<float>(0x80000000u));
+ const RealPacket cst_imag_sign_mask = pset1<Packet>(Scalar(RealScalar(0.0), neg_zero)).v;
+ RealPacket imag_signs = pand(a.v, cst_imag_sign_mask);
+ Packet negative_real_result;
+ // Notice that rho is positive, so taking it's absolute value is a noop.
+ negative_real_result.v = por(pabs(pcplxflip(positive_real_result).v), imag_signs);
+
+ // Step 5. Select solution branch based on the sign of the real parts.
+ Packet negative_real_mask;
+ negative_real_mask.v = pcmp_lt(pand(real_mask, a.v), pzero(a.v));
+ negative_real_mask.v = por(negative_real_mask.v, pcplxflip(negative_real_mask).v);
+ Packet result = pselect(negative_real_mask, negative_real_result, positive_real_result);
+
+ // Step 6. Handle special cases for infinities:
+ // * If z is (x,+∞), the result is (+∞,+∞) even if x is NaN
+ // * If z is (x,-∞), the result is (+∞,-∞) even if x is NaN
+ // * If z is (-∞,y), the result is (0*|y|,+∞) for finite or NaN y
+ // * If z is (+∞,y), the result is (+∞,0*|y|) for finite or NaN y
+ const RealPacket cst_pos_inf = pset1<RealPacket>(NumTraits<RealScalar>::infinity());
+ Packet is_inf;
+ is_inf.v = pcmp_eq(a_abs, cst_pos_inf);
+ Packet is_real_inf;
+ is_real_inf.v = pand(is_inf.v, real_mask);
+ is_real_inf = por(is_real_inf, pcplxflip(is_real_inf));
+ // prepare packet of (+∞,0*|y|) or (0*|y|,+∞), depending on the sign of the infinite real part.
+ Packet real_inf_result;
+ real_inf_result.v = pmul(a_abs, pset1<Packet>(Scalar(RealScalar(1.0), RealScalar(0.0))).v);
+ real_inf_result.v = pselect(negative_real_mask.v, pcplxflip(real_inf_result).v, real_inf_result.v);
+ // prepare packet of (+∞,+∞) or (+∞,-∞), depending on the sign of the infinite imaginary part.
+ Packet is_imag_inf;
+ is_imag_inf.v = pandnot(is_inf.v, real_mask);
+ is_imag_inf = por(is_imag_inf, pcplxflip(is_imag_inf));
+ Packet imag_inf_result;
+ imag_inf_result.v = por(pand(cst_pos_inf, real_mask), pandnot(a.v, real_mask));
+
+ return pselect(is_imag_inf, imag_inf_result,
+ pselect(is_real_inf, real_inf_result,result));
+}
+
+// TODO(rmlarsen): The following set of utilities for double word arithmetic
+// should perhaps be refactored as a separate file, since it would be generally
+// useful for special function implementation etc. Writing the algorithms in
+// terms if a double word type would also make the code more readable.
+
+// This function splits x into the nearest integer n and fractional part r,
+// such that x = n + r holds exactly.
+template<typename Packet>
+EIGEN_STRONG_INLINE
+void absolute_split(const Packet& x, Packet& n, Packet& r) {
+ n = pround(x);
+ r = psub(x, n);
+}
+
+// This function computes the sum {s, r}, such that x + y = s_hi + s_lo
+// holds exactly, and s_hi = fl(x+y), if |x| >= |y|.
+template<typename Packet>
+EIGEN_STRONG_INLINE
+void fast_twosum(const Packet& x, const Packet& y, Packet& s_hi, Packet& s_lo) {
+ s_hi = padd(x, y);
+ const Packet t = psub(s_hi, x);
+ s_lo = psub(y, t);
+}
+
+#ifdef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+// This function implements the extended precision product of
+// a pair of floating point numbers. Given {x, y}, it computes the pair
+// {p_hi, p_lo} such that x * y = p_hi + p_lo holds exactly and
+// p_hi = fl(x * y).
+template<typename Packet>
+EIGEN_STRONG_INLINE
+void twoprod(const Packet& x, const Packet& y,
+ Packet& p_hi, Packet& p_lo) {
+ p_hi = pmul(x, y);
+ p_lo = pmadd(x, y, pnegate(p_hi));
+}
+
+#else
+
+// This function implements the Veltkamp splitting. Given a floating point
+// number x it returns the pair {x_hi, x_lo} such that x_hi + x_lo = x holds
+// exactly and that half of the significant of x fits in x_hi.
+// This is Algorithm 3 from Jean-Michel Muller, "Elementary Functions",
+// 3rd edition, Birkh\"auser, 2016.
+template<typename Packet>
+EIGEN_STRONG_INLINE
+void veltkamp_splitting(const Packet& x, Packet& x_hi, Packet& x_lo) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ EIGEN_CONSTEXPR int shift = (NumTraits<Scalar>::digits() + 1) / 2;
+ const Scalar shift_scale = Scalar(uint64_t(1) << shift); // Scalar constructor not necessarily constexpr.
+ const Packet gamma = pmul(pset1<Packet>(shift_scale + Scalar(1)), x);
+ Packet rho = psub(x, gamma);
+ x_hi = padd(rho, gamma);
+ x_lo = psub(x, x_hi);
+}
+
+// This function implements Dekker's algorithm for products x * y.
+// Given floating point numbers {x, y} computes the pair
+// {p_hi, p_lo} such that x * y = p_hi + p_lo holds exactly and
+// p_hi = fl(x * y).
+template<typename Packet>
+EIGEN_STRONG_INLINE
+void twoprod(const Packet& x, const Packet& y,
+ Packet& p_hi, Packet& p_lo) {
+ Packet x_hi, x_lo, y_hi, y_lo;
+ veltkamp_splitting(x, x_hi, x_lo);
+ veltkamp_splitting(y, y_hi, y_lo);
+
+ p_hi = pmul(x, y);
+ p_lo = pmadd(x_hi, y_hi, pnegate(p_hi));
+ p_lo = pmadd(x_hi, y_lo, p_lo);
+ p_lo = pmadd(x_lo, y_hi, p_lo);
+ p_lo = pmadd(x_lo, y_lo, p_lo);
+}
+
+#endif // EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+
+
+// This function implements Dekker's algorithm for the addition
+// of two double word numbers represented by {x_hi, x_lo} and {y_hi, y_lo}.
+// It returns the result as a pair {s_hi, s_lo} such that
+// x_hi + x_lo + y_hi + y_lo = s_hi + s_lo holds exactly.
+// This is Algorithm 5 from Jean-Michel Muller, "Elementary Functions",
+// 3rd edition, Birkh\"auser, 2016.
+template<typename Packet>
+EIGEN_STRONG_INLINE
+ void twosum(const Packet& x_hi, const Packet& x_lo,
+ const Packet& y_hi, const Packet& y_lo,
+ Packet& s_hi, Packet& s_lo) {
+ const Packet x_greater_mask = pcmp_lt(pabs(y_hi), pabs(x_hi));
+ Packet r_hi_1, r_lo_1;
+ fast_twosum(x_hi, y_hi,r_hi_1, r_lo_1);
+ Packet r_hi_2, r_lo_2;
+ fast_twosum(y_hi, x_hi,r_hi_2, r_lo_2);
+ const Packet r_hi = pselect(x_greater_mask, r_hi_1, r_hi_2);
+
+ const Packet s1 = padd(padd(y_lo, r_lo_1), x_lo);
+ const Packet s2 = padd(padd(x_lo, r_lo_2), y_lo);
+ const Packet s = pselect(x_greater_mask, s1, s2);
+
+ fast_twosum(r_hi, s, s_hi, s_lo);
+}
+
+// This is a version of twosum for double word numbers,
+// which assumes that |x_hi| >= |y_hi|.
+template<typename Packet>
+EIGEN_STRONG_INLINE
+ void fast_twosum(const Packet& x_hi, const Packet& x_lo,
+ const Packet& y_hi, const Packet& y_lo,
+ Packet& s_hi, Packet& s_lo) {
+ Packet r_hi, r_lo;
+ fast_twosum(x_hi, y_hi, r_hi, r_lo);
+ const Packet s = padd(padd(y_lo, r_lo), x_lo);
+ fast_twosum(r_hi, s, s_hi, s_lo);
+}
+
+// This is a version of twosum for adding a floating point number x to
+// double word number {y_hi, y_lo} number, with the assumption
+// that |x| >= |y_hi|.
+template<typename Packet>
+EIGEN_STRONG_INLINE
+void fast_twosum(const Packet& x,
+ const Packet& y_hi, const Packet& y_lo,
+ Packet& s_hi, Packet& s_lo) {
+ Packet r_hi, r_lo;
+ fast_twosum(x, y_hi, r_hi, r_lo);
+ const Packet s = padd(y_lo, r_lo);
+ fast_twosum(r_hi, s, s_hi, s_lo);
+}
+
+// This function implements the multiplication of a double word
+// number represented by {x_hi, x_lo} by a floating point number y.
+// It returns the result as a pair {p_hi, p_lo} such that
+// (x_hi + x_lo) * y = p_hi + p_lo hold with a relative error
+// of less than 2*2^{-2p}, where p is the number of significand bit
+// in the floating point type.
+// This is Algorithm 7 from Jean-Michel Muller, "Elementary Functions",
+// 3rd edition, Birkh\"auser, 2016.
+template<typename Packet>
+EIGEN_STRONG_INLINE
+void twoprod(const Packet& x_hi, const Packet& x_lo, const Packet& y,
+ Packet& p_hi, Packet& p_lo) {
+ Packet c_hi, c_lo1;
+ twoprod(x_hi, y, c_hi, c_lo1);
+ const Packet c_lo2 = pmul(x_lo, y);
+ Packet t_hi, t_lo1;
+ fast_twosum(c_hi, c_lo2, t_hi, t_lo1);
+ const Packet t_lo2 = padd(t_lo1, c_lo1);
+ fast_twosum(t_hi, t_lo2, p_hi, p_lo);
+}
+
+// This function implements the multiplication of two double word
+// numbers represented by {x_hi, x_lo} and {y_hi, y_lo}.
+// It returns the result as a pair {p_hi, p_lo} such that
+// (x_hi + x_lo) * (y_hi + y_lo) = p_hi + p_lo holds with a relative error
+// of less than 2*2^{-2p}, where p is the number of significand bit
+// in the floating point type.
+template<typename Packet>
+EIGEN_STRONG_INLINE
+void twoprod(const Packet& x_hi, const Packet& x_lo,
+ const Packet& y_hi, const Packet& y_lo,
+ Packet& p_hi, Packet& p_lo) {
+ Packet p_hi_hi, p_hi_lo;
+ twoprod(x_hi, x_lo, y_hi, p_hi_hi, p_hi_lo);
+ Packet p_lo_hi, p_lo_lo;
+ twoprod(x_hi, x_lo, y_lo, p_lo_hi, p_lo_lo);
+ fast_twosum(p_hi_hi, p_hi_lo, p_lo_hi, p_lo_lo, p_hi, p_lo);
+}
+
+// This function computes the reciprocal of a floating point number
+// with extra precision and returns the result as a double word.
+template <typename Packet>
+void doubleword_reciprocal(const Packet& x, Packet& recip_hi, Packet& recip_lo) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ // 1. Approximate the reciprocal as the reciprocal of the high order element.
+ Packet approx_recip = prsqrt(x);
+ approx_recip = pmul(approx_recip, approx_recip);
+
+ // 2. Run one step of Newton-Raphson iteration in double word arithmetic
+ // to get the bottom half. The NR iteration for reciprocal of 'a' is
+ // x_{i+1} = x_i * (2 - a * x_i)
+
+ // -a*x_i
+ Packet t1_hi, t1_lo;
+ twoprod(pnegate(x), approx_recip, t1_hi, t1_lo);
+ // 2 - a*x_i
+ Packet t2_hi, t2_lo;
+ fast_twosum(pset1<Packet>(Scalar(2)), t1_hi, t2_hi, t2_lo);
+ Packet t3_hi, t3_lo;
+ fast_twosum(t2_hi, padd(t2_lo, t1_lo), t3_hi, t3_lo);
+ // x_i * (2 - a * x_i)
+ twoprod(t3_hi, t3_lo, approx_recip, recip_hi, recip_lo);
+}
+
+
+// This function computes log2(x) and returns the result as a double word.
+template <typename Scalar>
+struct accurate_log2 {
+ template <typename Packet>
+ EIGEN_STRONG_INLINE
+ void operator()(const Packet& x, Packet& log2_x_hi, Packet& log2_x_lo) {
+ log2_x_hi = plog2(x);
+ log2_x_lo = pzero(x);
+ }
+};
+
+// This specialization uses a more accurate algorithm to compute log2(x) for
+// floats in [1/sqrt(2);sqrt(2)] with a relative accuracy of ~6.42e-10.
+// This additional accuracy is needed to counter the error-magnification
+// inherent in multiplying by a potentially large exponent in pow(x,y).
+// The minimax polynomial used was calculated using the Sollya tool.
+// See sollya.org.
+template <>
+struct accurate_log2<float> {
+ template <typename Packet>
+ EIGEN_STRONG_INLINE
+ void operator()(const Packet& z, Packet& log2_x_hi, Packet& log2_x_lo) {
+ // The function log(1+x)/x is approximated in the interval
+ // [1/sqrt(2)-1;sqrt(2)-1] by a degree 10 polynomial of the form
+ // Q(x) = (C0 + x * (C1 + x * (C2 + x * (C3 + x * P(x))))),
+ // where the degree 6 polynomial P(x) is evaluated in single precision,
+ // while the remaining 4 terms of Q(x), as well as the final multiplication by x
+ // to reconstruct log(1+x) are evaluated in extra precision using
+ // double word arithmetic. C0 through C3 are extra precise constants
+ // stored as double words.
+ //
+ // The polynomial coefficients were calculated using Sollya commands:
+ // > n = 10;
+ // > f = log2(1+x)/x;
+ // > interval = [sqrt(0.5)-1;sqrt(2)-1];
+ // > p = fpminimax(f,n,[|double,double,double,double,single...|],interval,relative,floating);
+
+ const Packet p6 = pset1<Packet>( 9.703654795885e-2f);
+ const Packet p5 = pset1<Packet>(-0.1690667718648f);
+ const Packet p4 = pset1<Packet>( 0.1720575392246f);
+ const Packet p3 = pset1<Packet>(-0.1789081543684f);
+ const Packet p2 = pset1<Packet>( 0.2050433009862f);
+ const Packet p1 = pset1<Packet>(-0.2404672354459f);
+ const Packet p0 = pset1<Packet>( 0.2885761857032f);
+
+ const Packet C3_hi = pset1<Packet>(-0.360674142838f);
+ const Packet C3_lo = pset1<Packet>(-6.13283912543e-09f);
+ const Packet C2_hi = pset1<Packet>(0.480897903442f);
+ const Packet C2_lo = pset1<Packet>(-1.44861207474e-08f);
+ const Packet C1_hi = pset1<Packet>(-0.721347510815f);
+ const Packet C1_lo = pset1<Packet>(-4.84483164698e-09f);
+ const Packet C0_hi = pset1<Packet>(1.44269502163f);
+ const Packet C0_lo = pset1<Packet>(2.01711713999e-08f);
+ const Packet one = pset1<Packet>(1.0f);
+
+ const Packet x = psub(z, one);
+ // Evaluate P(x) in working precision.
+ // We evaluate it in multiple parts to improve instruction level
+ // parallelism.
+ Packet x2 = pmul(x,x);
+ Packet p_even = pmadd(p6, x2, p4);
+ p_even = pmadd(p_even, x2, p2);
+ p_even = pmadd(p_even, x2, p0);
+ Packet p_odd = pmadd(p5, x2, p3);
+ p_odd = pmadd(p_odd, x2, p1);
+ Packet p = pmadd(p_odd, x, p_even);
+
+ // Now evaluate the low-order tems of Q(x) in double word precision.
+ // In the following, due to the alternating signs and the fact that
+ // |x| < sqrt(2)-1, we can assume that |C*_hi| >= q_i, and use
+ // fast_twosum instead of the slower twosum.
+ Packet q_hi, q_lo;
+ Packet t_hi, t_lo;
+ // C3 + x * p(x)
+ twoprod(p, x, t_hi, t_lo);
+ fast_twosum(C3_hi, C3_lo, t_hi, t_lo, q_hi, q_lo);
+ // C2 + x * p(x)
+ twoprod(q_hi, q_lo, x, t_hi, t_lo);
+ fast_twosum(C2_hi, C2_lo, t_hi, t_lo, q_hi, q_lo);
+ // C1 + x * p(x)
+ twoprod(q_hi, q_lo, x, t_hi, t_lo);
+ fast_twosum(C1_hi, C1_lo, t_hi, t_lo, q_hi, q_lo);
+ // C0 + x * p(x)
+ twoprod(q_hi, q_lo, x, t_hi, t_lo);
+ fast_twosum(C0_hi, C0_lo, t_hi, t_lo, q_hi, q_lo);
+
+ // log(z) ~= x * Q(x)
+ twoprod(q_hi, q_lo, x, log2_x_hi, log2_x_lo);
+ }
+};
+
+// This specialization uses a more accurate algorithm to compute log2(x) for
+// floats in [1/sqrt(2);sqrt(2)] with a relative accuracy of ~1.27e-18.
+// This additional accuracy is needed to counter the error-magnification
+// inherent in multiplying by a potentially large exponent in pow(x,y).
+// The minimax polynomial used was calculated using the Sollya tool.
+// See sollya.org.
+
+template <>
+struct accurate_log2<double> {
+ template <typename Packet>
+ EIGEN_STRONG_INLINE
+ void operator()(const Packet& x, Packet& log2_x_hi, Packet& log2_x_lo) {
+ // We use a transformation of variables:
+ // r = c * (x-1) / (x+1),
+ // such that
+ // log2(x) = log2((1 + r/c) / (1 - r/c)) = f(r).
+ // The function f(r) can be approximated well using an odd polynomial
+ // of the form
+ // P(r) = ((Q(r^2) * r^2 + C) * r^2 + 1) * r,
+ // For the implementation of log2<double> here, Q is of degree 6 with
+ // coefficient represented in working precision (double), while C is a
+ // constant represented in extra precision as a double word to achieve
+ // full accuracy.
+ //
+ // The polynomial coefficients were computed by the Sollya script:
+ //
+ // c = 2 / log(2);
+ // trans = c * (x-1)/(x+1);
+ // itrans = (1+x/c)/(1-x/c);
+ // interval=[trans(sqrt(0.5)); trans(sqrt(2))];
+ // print(interval);
+ // f = log2(itrans(x));
+ // p=fpminimax(f,[|1,3,5,7,9,11,13,15,17|],[|1,DD,double...|],interval,relative,floating);
+ const Packet q12 = pset1<Packet>(2.87074255468000586e-9);
+ const Packet q10 = pset1<Packet>(2.38957980901884082e-8);
+ const Packet q8 = pset1<Packet>(2.31032094540014656e-7);
+ const Packet q6 = pset1<Packet>(2.27279857398537278e-6);
+ const Packet q4 = pset1<Packet>(2.31271023278625638e-5);
+ const Packet q2 = pset1<Packet>(2.47556738444535513e-4);
+ const Packet q0 = pset1<Packet>(2.88543873228900172e-3);
+ const Packet C_hi = pset1<Packet>(0.0400377511598501157);
+ const Packet C_lo = pset1<Packet>(-4.77726582251425391e-19);
+ const Packet one = pset1<Packet>(1.0);
+
+ const Packet cst_2_log2e_hi = pset1<Packet>(2.88539008177792677);
+ const Packet cst_2_log2e_lo = pset1<Packet>(4.07660016854549667e-17);
+ // c * (x - 1)
+ Packet num_hi, num_lo;
+ twoprod(cst_2_log2e_hi, cst_2_log2e_lo, psub(x, one), num_hi, num_lo);
+ // TODO(rmlarsen): Investigate if using the division algorithm by
+ // Muller et al. is faster/more accurate.
+ // 1 / (x + 1)
+ Packet denom_hi, denom_lo;
+ doubleword_reciprocal(padd(x, one), denom_hi, denom_lo);
+ // r = c * (x-1) / (x+1),
+ Packet r_hi, r_lo;
+ twoprod(num_hi, num_lo, denom_hi, denom_lo, r_hi, r_lo);
+ // r2 = r * r
+ Packet r2_hi, r2_lo;
+ twoprod(r_hi, r_lo, r_hi, r_lo, r2_hi, r2_lo);
+ // r4 = r2 * r2
+ Packet r4_hi, r4_lo;
+ twoprod(r2_hi, r2_lo, r2_hi, r2_lo, r4_hi, r4_lo);
+
+ // Evaluate Q(r^2) in working precision. We evaluate it in two parts
+ // (even and odd in r^2) to improve instruction level parallelism.
+ Packet q_even = pmadd(q12, r4_hi, q8);
+ Packet q_odd = pmadd(q10, r4_hi, q6);
+ q_even = pmadd(q_even, r4_hi, q4);
+ q_odd = pmadd(q_odd, r4_hi, q2);
+ q_even = pmadd(q_even, r4_hi, q0);
+ Packet q = pmadd(q_odd, r2_hi, q_even);
+
+ // Now evaluate the low order terms of P(x) in double word precision.
+ // In the following, due to the increasing magnitude of the coefficients
+ // and r being constrained to [-0.5, 0.5] we can use fast_twosum instead
+ // of the slower twosum.
+ // Q(r^2) * r^2
+ Packet p_hi, p_lo;
+ twoprod(r2_hi, r2_lo, q, p_hi, p_lo);
+ // Q(r^2) * r^2 + C
+ Packet p1_hi, p1_lo;
+ fast_twosum(C_hi, C_lo, p_hi, p_lo, p1_hi, p1_lo);
+ // (Q(r^2) * r^2 + C) * r^2
+ Packet p2_hi, p2_lo;
+ twoprod(r2_hi, r2_lo, p1_hi, p1_lo, p2_hi, p2_lo);
+ // ((Q(r^2) * r^2 + C) * r^2 + 1)
+ Packet p3_hi, p3_lo;
+ fast_twosum(one, p2_hi, p2_lo, p3_hi, p3_lo);
+
+ // log(z) ~= ((Q(r^2) * r^2 + C) * r^2 + 1) * r
+ twoprod(p3_hi, p3_lo, r_hi, r_lo, log2_x_hi, log2_x_lo);
+ }
+};
+
+// This function computes exp2(x) (i.e. 2**x).
+template <typename Scalar>
+struct fast_accurate_exp2 {
+ template <typename Packet>
+ EIGEN_STRONG_INLINE
+ Packet operator()(const Packet& x) {
+ // TODO(rmlarsen): Add a pexp2 packetop.
+ return pexp(pmul(pset1<Packet>(Scalar(EIGEN_LN2)), x));
+ }
+};
+
+// This specialization uses a faster algorithm to compute exp2(x) for floats
+// in [-0.5;0.5] with a relative accuracy of 1 ulp.
+// The minimax polynomial used was calculated using the Sollya tool.
+// See sollya.org.
+template <>
+struct fast_accurate_exp2<float> {
+ template <typename Packet>
+ EIGEN_STRONG_INLINE
+ Packet operator()(const Packet& x) {
+ // This function approximates exp2(x) by a degree 6 polynomial of the form
+ // Q(x) = 1 + x * (C + x * P(x)), where the degree 4 polynomial P(x) is evaluated in
+ // single precision, and the remaining steps are evaluated with extra precision using
+ // double word arithmetic. C is an extra precise constant stored as a double word.
+ //
+ // The polynomial coefficients were calculated using Sollya commands:
+ // > n = 6;
+ // > f = 2^x;
+ // > interval = [-0.5;0.5];
+ // > p = fpminimax(f,n,[|1,double,single...|],interval,relative,floating);
+
+ const Packet p4 = pset1<Packet>(1.539513905e-4f);
+ const Packet p3 = pset1<Packet>(1.340007293e-3f);
+ const Packet p2 = pset1<Packet>(9.618283249e-3f);
+ const Packet p1 = pset1<Packet>(5.550328270e-2f);
+ const Packet p0 = pset1<Packet>(0.2402264923f);
+
+ const Packet C_hi = pset1<Packet>(0.6931471825f);
+ const Packet C_lo = pset1<Packet>(2.36836577e-08f);
+ const Packet one = pset1<Packet>(1.0f);
+
+ // Evaluate P(x) in working precision.
+ // We evaluate even and odd parts of the polynomial separately
+ // to gain some instruction level parallelism.
+ Packet x2 = pmul(x,x);
+ Packet p_even = pmadd(p4, x2, p2);
+ Packet p_odd = pmadd(p3, x2, p1);
+ p_even = pmadd(p_even, x2, p0);
+ Packet p = pmadd(p_odd, x, p_even);
+
+ // Evaluate the remaining terms of Q(x) with extra precision using
+ // double word arithmetic.
+ Packet p_hi, p_lo;
+ // x * p(x)
+ twoprod(p, x, p_hi, p_lo);
+ // C + x * p(x)
+ Packet q1_hi, q1_lo;
+ twosum(p_hi, p_lo, C_hi, C_lo, q1_hi, q1_lo);
+ // x * (C + x * p(x))
+ Packet q2_hi, q2_lo;
+ twoprod(q1_hi, q1_lo, x, q2_hi, q2_lo);
+ // 1 + x * (C + x * p(x))
+ Packet q3_hi, q3_lo;
+ // Since |q2_hi| <= sqrt(2)-1 < 1, we can use fast_twosum
+ // for adding it to unity here.
+ fast_twosum(one, q2_hi, q3_hi, q3_lo);
+ return padd(q3_hi, padd(q2_lo, q3_lo));
+ }
+};
+
+// in [-0.5;0.5] with a relative accuracy of 1 ulp.
+// The minimax polynomial used was calculated using the Sollya tool.
+// See sollya.org.
+template <>
+struct fast_accurate_exp2<double> {
+ template <typename Packet>
+ EIGEN_STRONG_INLINE
+ Packet operator()(const Packet& x) {
+ // This function approximates exp2(x) by a degree 10 polynomial of the form
+ // Q(x) = 1 + x * (C + x * P(x)), where the degree 8 polynomial P(x) is evaluated in
+ // single precision, and the remaining steps are evaluated with extra precision using
+ // double word arithmetic. C is an extra precise constant stored as a double word.
+ //
+ // The polynomial coefficients were calculated using Sollya commands:
+ // > n = 11;
+ // > f = 2^x;
+ // > interval = [-0.5;0.5];
+ // > p = fpminimax(f,n,[|1,DD,double...|],interval,relative,floating);
+
+ const Packet p9 = pset1<Packet>(4.431642109085495276e-10);
+ const Packet p8 = pset1<Packet>(7.073829923303358410e-9);
+ const Packet p7 = pset1<Packet>(1.017822306737031311e-7);
+ const Packet p6 = pset1<Packet>(1.321543498017646657e-6);
+ const Packet p5 = pset1<Packet>(1.525273342728892877e-5);
+ const Packet p4 = pset1<Packet>(1.540353045780084423e-4);
+ const Packet p3 = pset1<Packet>(1.333355814685869807e-3);
+ const Packet p2 = pset1<Packet>(9.618129107593478832e-3);
+ const Packet p1 = pset1<Packet>(5.550410866481961247e-2);
+ const Packet p0 = pset1<Packet>(0.240226506959101332);
+ const Packet C_hi = pset1<Packet>(0.693147180559945286);
+ const Packet C_lo = pset1<Packet>(4.81927865669806721e-17);
+ const Packet one = pset1<Packet>(1.0);
+
+ // Evaluate P(x) in working precision.
+ // We evaluate even and odd parts of the polynomial separately
+ // to gain some instruction level parallelism.
+ Packet x2 = pmul(x,x);
+ Packet p_even = pmadd(p8, x2, p6);
+ Packet p_odd = pmadd(p9, x2, p7);
+ p_even = pmadd(p_even, x2, p4);
+ p_odd = pmadd(p_odd, x2, p5);
+ p_even = pmadd(p_even, x2, p2);
+ p_odd = pmadd(p_odd, x2, p3);
+ p_even = pmadd(p_even, x2, p0);
+ p_odd = pmadd(p_odd, x2, p1);
+ Packet p = pmadd(p_odd, x, p_even);
+
+ // Evaluate the remaining terms of Q(x) with extra precision using
+ // double word arithmetic.
+ Packet p_hi, p_lo;
+ // x * p(x)
+ twoprod(p, x, p_hi, p_lo);
+ // C + x * p(x)
+ Packet q1_hi, q1_lo;
+ twosum(p_hi, p_lo, C_hi, C_lo, q1_hi, q1_lo);
+ // x * (C + x * p(x))
+ Packet q2_hi, q2_lo;
+ twoprod(q1_hi, q1_lo, x, q2_hi, q2_lo);
+ // 1 + x * (C + x * p(x))
+ Packet q3_hi, q3_lo;
+ // Since |q2_hi| <= sqrt(2)-1 < 1, we can use fast_twosum
+ // for adding it to unity here.
+ fast_twosum(one, q2_hi, q3_hi, q3_lo);
+ return padd(q3_hi, padd(q2_lo, q3_lo));
+ }
+};
+
+// This function implements the non-trivial case of pow(x,y) where x is
+// positive and y is (possibly) non-integer.
+// Formally, pow(x,y) = exp2(y * log2(x)), where exp2(x) is shorthand for 2^x.
+// TODO(rmlarsen): We should probably add this as a packet up 'ppow', to make it
+// easier to specialize or turn off for specific types and/or backends.x
+template <typename Packet>
+EIGEN_STRONG_INLINE Packet generic_pow_impl(const Packet& x, const Packet& y) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ // Split x into exponent e_x and mantissa m_x.
+ Packet e_x;
+ Packet m_x = pfrexp(x, e_x);
+
+ // Adjust m_x to lie in [1/sqrt(2):sqrt(2)] to minimize absolute error in log2(m_x).
+ EIGEN_CONSTEXPR Scalar sqrt_half = Scalar(0.70710678118654752440);
+ const Packet m_x_scale_mask = pcmp_lt(m_x, pset1<Packet>(sqrt_half));
+ m_x = pselect(m_x_scale_mask, pmul(pset1<Packet>(Scalar(2)), m_x), m_x);
+ e_x = pselect(m_x_scale_mask, psub(e_x, pset1<Packet>(Scalar(1))), e_x);
+
+ // Compute log2(m_x) with 6 extra bits of accuracy.
+ Packet rx_hi, rx_lo;
+ accurate_log2<Scalar>()(m_x, rx_hi, rx_lo);
+
+ // Compute the two terms {y * e_x, y * r_x} in f = y * log2(x) with doubled
+ // precision using double word arithmetic.
+ Packet f1_hi, f1_lo, f2_hi, f2_lo;
+ twoprod(e_x, y, f1_hi, f1_lo);
+ twoprod(rx_hi, rx_lo, y, f2_hi, f2_lo);
+ // Sum the two terms in f using double word arithmetic. We know
+ // that |e_x| > |log2(m_x)|, except for the case where e_x==0.
+ // This means that we can use fast_twosum(f1,f2).
+ // In the case e_x == 0, e_x * y = f1 = 0, so we don't lose any
+ // accuracy by violating the assumption of fast_twosum, because
+ // it's a no-op.
+ Packet f_hi, f_lo;
+ fast_twosum(f1_hi, f1_lo, f2_hi, f2_lo, f_hi, f_lo);
+
+ // Split f into integer and fractional parts.
+ Packet n_z, r_z;
+ absolute_split(f_hi, n_z, r_z);
+ r_z = padd(r_z, f_lo);
+ Packet n_r;
+ absolute_split(r_z, n_r, r_z);
+ n_z = padd(n_z, n_r);
+
+ // We now have an accurate split of f = n_z + r_z and can compute
+ // x^y = 2**{n_z + r_z) = exp2(r_z) * 2**{n_z}.
+ // Since r_z is in [-0.5;0.5], we compute the first factor to high accuracy
+ // using a specialized algorithm. Multiplication by the second factor can
+ // be done exactly using pldexp(), since it is an integer power of 2.
+ const Packet e_r = fast_accurate_exp2<Scalar>()(r_z);
+ return pldexp(e_r, n_z);
+}
+
+// Generic implementation of pow(x,y).
+template<typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet generic_pow(const Packet& x, const Packet& y) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+
+ const Packet cst_pos_inf = pset1<Packet>(NumTraits<Scalar>::infinity());
+ const Packet cst_zero = pset1<Packet>(Scalar(0));
+ const Packet cst_one = pset1<Packet>(Scalar(1));
+ const Packet cst_nan = pset1<Packet>(NumTraits<Scalar>::quiet_NaN());
+
+ const Packet abs_x = pabs(x);
+ // Predicates for sign and magnitude of x.
+ const Packet x_is_zero = pcmp_eq(x, cst_zero);
+ const Packet x_is_neg = pcmp_lt(x, cst_zero);
+ const Packet abs_x_is_inf = pcmp_eq(abs_x, cst_pos_inf);
+ const Packet abs_x_is_one = pcmp_eq(abs_x, cst_one);
+ const Packet abs_x_is_gt_one = pcmp_lt(cst_one, abs_x);
+ const Packet abs_x_is_lt_one = pcmp_lt(abs_x, cst_one);
+ const Packet x_is_one = pandnot(abs_x_is_one, x_is_neg);
+ const Packet x_is_neg_one = pand(abs_x_is_one, x_is_neg);
+ const Packet x_is_nan = pandnot(ptrue(x), pcmp_eq(x, x));
+
+ // Predicates for sign and magnitude of y.
+ const Packet y_is_one = pcmp_eq(y, cst_one);
+ const Packet y_is_zero = pcmp_eq(y, cst_zero);
+ const Packet y_is_neg = pcmp_lt(y, cst_zero);
+ const Packet y_is_pos = pandnot(ptrue(y), por(y_is_zero, y_is_neg));
+ const Packet y_is_nan = pandnot(ptrue(y), pcmp_eq(y, y));
+ const Packet abs_y_is_inf = pcmp_eq(pabs(y), cst_pos_inf);
+ EIGEN_CONSTEXPR Scalar huge_exponent =
+ (NumTraits<Scalar>::max_exponent() * Scalar(EIGEN_LN2)) /
+ NumTraits<Scalar>::epsilon();
+ const Packet abs_y_is_huge = pcmp_le(pset1<Packet>(huge_exponent), pabs(y));
+
+ // Predicates for whether y is integer and/or even.
+ const Packet y_is_int = pcmp_eq(pfloor(y), y);
+ const Packet y_div_2 = pmul(y, pset1<Packet>(Scalar(0.5)));
+ const Packet y_is_even = pcmp_eq(pround(y_div_2), y_div_2);
+
+ // Predicates encoding special cases for the value of pow(x,y)
+ const Packet invalid_negative_x = pandnot(pandnot(pandnot(x_is_neg, abs_x_is_inf),
+ y_is_int),
+ abs_y_is_inf);
+ const Packet pow_is_one = por(por(x_is_one, y_is_zero),
+ pand(x_is_neg_one,
+ por(abs_y_is_inf, pandnot(y_is_even, invalid_negative_x))));
+ const Packet pow_is_nan = por(invalid_negative_x, por(x_is_nan, y_is_nan));
+ const Packet pow_is_zero = por(por(por(pand(x_is_zero, y_is_pos),
+ pand(abs_x_is_inf, y_is_neg)),
+ pand(pand(abs_x_is_lt_one, abs_y_is_huge),
+ y_is_pos)),
+ pand(pand(abs_x_is_gt_one, abs_y_is_huge),
+ y_is_neg));
+ const Packet pow_is_inf = por(por(por(pand(x_is_zero, y_is_neg),
+ pand(abs_x_is_inf, y_is_pos)),
+ pand(pand(abs_x_is_lt_one, abs_y_is_huge),
+ y_is_neg)),
+ pand(pand(abs_x_is_gt_one, abs_y_is_huge),
+ y_is_pos));
+
+ // General computation of pow(x,y) for positive x or negative x and integer y.
+ const Packet negate_pow_abs = pandnot(x_is_neg, y_is_even);
+ const Packet pow_abs = generic_pow_impl(abs_x, y);
+ return pselect(y_is_one, x,
+ pselect(pow_is_one, cst_one,
+ pselect(pow_is_nan, cst_nan,
+ pselect(pow_is_inf, cst_pos_inf,
+ pselect(pow_is_zero, cst_zero,
+ pselect(negate_pow_abs, pnegate(pow_abs), pow_abs))))));
+}
+
+
+
+/* polevl (modified for Eigen)
+ *
+ * Evaluate polynomial
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * int N;
+ * Scalar x, y, coef[N+1];
+ *
+ * y = polevl<decltype(x), N>( x, coef);
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Evaluates polynomial of degree N:
+ *
+ * 2 N
+ * y = C + C x + C x +...+ C x
+ * 0 1 2 N
+ *
+ * Coefficients are stored in reverse order:
+ *
+ * coef[0] = C , ..., coef[N] = C .
+ * N 0
+ *
+ * The function p1evl() assumes that coef[N] = 1.0 and is
+ * omitted from the array. Its calling arguments are
+ * otherwise the same as polevl().
+ *
+ *
+ * The Eigen implementation is templatized. For best speed, store
+ * coef as a const array (constexpr), e.g.
+ *
+ * const double coef[] = {1.0, 2.0, 3.0, ...};
+ *
+ */
+template <typename Packet, int N>
+struct ppolevl {
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet run(const Packet& x, const typename unpacket_traits<Packet>::type coeff[]) {
+ EIGEN_STATIC_ASSERT((N > 0), YOU_MADE_A_PROGRAMMING_MISTAKE);
+ return pmadd(ppolevl<Packet, N-1>::run(x, coeff), x, pset1<Packet>(coeff[N]));
+ }
+};
+
+template <typename Packet>
+struct ppolevl<Packet, 0> {
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet run(const Packet& x, const typename unpacket_traits<Packet>::type coeff[]) {
+ EIGEN_UNUSED_VARIABLE(x);
+ return pset1<Packet>(coeff[0]);
+ }
+};
+
+/* chbevl (modified for Eigen)
+ *
+ * Evaluate Chebyshev series
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * int N;
+ * Scalar x, y, coef[N], chebevl();
+ *
+ * y = chbevl( x, coef, N );
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Evaluates the series
+ *
+ * N-1
+ * - '
+ * y = > coef[i] T (x/2)
+ * - i
+ * i=0
+ *
+ * of Chebyshev polynomials Ti at argument x/2.
+ *
+ * Coefficients are stored in reverse order, i.e. the zero
+ * order term is last in the array. Note N is the number of
+ * coefficients, not the order.
+ *
+ * If coefficients are for the interval a to b, x must
+ * have been transformed to x -> 2(2x - b - a)/(b-a) before
+ * entering the routine. This maps x from (a, b) to (-1, 1),
+ * over which the Chebyshev polynomials are defined.
+ *
+ * If the coefficients are for the inverted interval, in
+ * which (a, b) is mapped to (1/b, 1/a), the transformation
+ * required is x -> 2(2ab/x - b - a)/(b-a). If b is infinity,
+ * this becomes x -> 4a/x - 1.
+ *
+ *
+ *
+ * SPEED:
+ *
+ * Taking advantage of the recurrence properties of the
+ * Chebyshev polynomials, the routine requires one more
+ * addition per loop than evaluating a nested polynomial of
+ * the same degree.
+ *
+ */
+
+template <typename Packet, int N>
+struct pchebevl {
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE Packet run(Packet x, const typename unpacket_traits<Packet>::type coef[]) {
+ typedef typename unpacket_traits<Packet>::type Scalar;
+ Packet b0 = pset1<Packet>(coef[0]);
+ Packet b1 = pset1<Packet>(static_cast<Scalar>(0.f));
+ Packet b2;
+
+ for (int i = 1; i < N; i++) {
+ b2 = b1;
+ b1 = b0;
+ b0 = psub(pmadd(x, b1, pset1<Packet>(coef[i])), b2);
+ }
+
+ return pmul(pset1<Packet>(static_cast<Scalar>(0.5f)), psub(b0, b2));
+ }
+};
+
+} // end namespace internal
+} // end namespace Eigen
+
+#endif // EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h
new file mode 100644
index 000000000..177a04e93
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h
@@ -0,0 +1,110 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2019 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_FWD_H
+#define EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_FWD_H
+
+namespace Eigen {
+namespace internal {
+
+// Forward declarations of the generic math functions
+// implemented in GenericPacketMathFunctions.h
+// This is needed to workaround a circular dependency.
+
+/***************************************************************************
+ * Some generic implementations to be used by implementors
+***************************************************************************/
+
+/** Default implementation of pfrexp.
+ * It is expected to be called by implementers of template<> pfrexp.
+ */
+template<typename Packet> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+Packet pfrexp_generic(const Packet& a, Packet& exponent);
+
+// Extracts the biased exponent value from Packet p, and casts the results to
+// a floating-point Packet type. Used by pfrexp_generic. Override this if
+// there is no unpacket_traits<Packet>::integer_packet.
+template<typename Packet> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+Packet pfrexp_generic_get_biased_exponent(const Packet& p);
+
+/** Default implementation of pldexp.
+ * It is expected to be called by implementers of template<> pldexp.
+ */
+template<typename Packet> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+Packet pldexp_generic(const Packet& a, const Packet& exponent);
+
+/** \internal \returns log(x) for single precision float */
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet plog_float(const Packet _x);
+
+/** \internal \returns log2(x) for single precision float */
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet plog2_float(const Packet _x);
+
+/** \internal \returns log(x) for single precision float */
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet plog_double(const Packet _x);
+
+/** \internal \returns log2(x) for single precision float */
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet plog2_double(const Packet _x);
+
+/** \internal \returns log(1 + x) */
+template<typename Packet>
+Packet generic_plog1p(const Packet& x);
+
+/** \internal \returns exp(x)-1 */
+template<typename Packet>
+Packet generic_expm1(const Packet& x);
+
+/** \internal \returns exp(x) for single precision float */
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet pexp_float(const Packet _x);
+
+/** \internal \returns exp(x) for double precision real numbers */
+template <typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet pexp_double(const Packet _x);
+
+/** \internal \returns sin(x) for single precision float */
+template<typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet psin_float(const Packet& x);
+
+/** \internal \returns cos(x) for single precision float */
+template<typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet pcos_float(const Packet& x);
+
+/** \internal \returns sqrt(x) for complex types */
+template<typename Packet>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
+EIGEN_UNUSED
+Packet psqrt_complex(const Packet& a);
+
+template <typename Packet, int N> struct ppolevl;
+
+
+} // end namespace internal
+} // end namespace Eigen
+
+#endif // EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_FWD_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/Default/Half.h b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/Half.h
new file mode 100644
index 000000000..9f8e8cc1e
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/Half.h
@@ -0,0 +1,942 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+//
+// The conversion routines are Copyright (c) Fabian Giesen, 2016.
+// The original license follows:
+//
+// Copyright (c) Fabian Giesen, 2016
+// All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted.
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+// Standard 16-bit float type, mostly useful for GPUs. Defines a new
+// type Eigen::half (inheriting either from CUDA's or HIP's __half struct) with
+// operator overloads such that it behaves basically as an arithmetic
+// type. It will be quite slow on CPUs (so it is recommended to stay
+// in fp32 for CPUs, except for simple parameter conversions, I/O
+// to disk and the likes), but fast on GPUs.
+
+
+#ifndef EIGEN_HALF_H
+#define EIGEN_HALF_H
+
+#include <sstream>
+
+#if defined(EIGEN_HAS_GPU_FP16) || defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
+// When compiling with GPU support, the "__half_raw" base class as well as
+// some other routines are defined in the GPU compiler header files
+// (cuda_fp16.h, hip_fp16.h), and they are not tagged constexpr
+// As a consequence, we get compile failures when compiling Eigen with
+// GPU support. Hence the need to disable EIGEN_CONSTEXPR when building
+// Eigen with GPU support
+ #pragma push_macro("EIGEN_CONSTEXPR")
+ #undef EIGEN_CONSTEXPR
+ #define EIGEN_CONSTEXPR
+#endif
+
+#define F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, METHOD) \
+ template <> \
+ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_UNUSED \
+ PACKET_F16 METHOD<PACKET_F16>(const PACKET_F16& _x) { \
+ return float2half(METHOD<PACKET_F>(half2float(_x))); \
+ }
+
+namespace Eigen {
+
+struct half;
+
+namespace half_impl {
+
+// We want to use the __half_raw struct from the HIP header file only during the device compile phase.
+// This is required because of a quirk in the way TensorFlow GPU builds are done.
+// When compiling TensorFlow source code with GPU support, files that
+// * contain GPU kernels (i.e. *.cu.cc files) are compiled via hipcc
+// * do not contain GPU kernels ( i.e. *.cc files) are compiled via gcc (typically)
+//
+// Tensorflow uses the Eigen::half type as its FP16 type, and there are functions that
+// * are defined in a file that gets compiled via hipcc AND
+// * have Eigen::half as a pass-by-value argument AND
+// * are called in a file that gets compiled via gcc
+//
+// In the scenario described above the caller and callee will see different versions
+// of the Eigen::half base class __half_raw, and they will be compiled by different compilers
+//
+// There appears to be an ABI mismatch between gcc and clang (which is called by hipcc) that results in
+// the callee getting corrupted values for the Eigen::half argument.
+//
+// Making the host side compile phase of hipcc use the same Eigen::half impl, as the gcc compile, resolves
+// this error, and hence the following convoluted #if condition
+#if !defined(EIGEN_HAS_GPU_FP16) || !defined(EIGEN_GPU_COMPILE_PHASE)
+// Make our own __half_raw definition that is similar to CUDA's.
+struct __half_raw {
+#if (defined(EIGEN_HAS_GPU_FP16) && !defined(EIGEN_GPU_COMPILE_PHASE))
+ // Eigen::half can be used as the datatype for shared memory declarations (in Eigen and TF)
+ // The element type for shared memory cannot have non-trivial constructors
+ // and hence the following special casing (which skips the zero-initilization).
+ // Note that this check gets done even in the host compilation phase, and
+ // hence the need for this
+ EIGEN_DEVICE_FUNC __half_raw() {}
+#else
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __half_raw() : x(0) {}
+#endif
+#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
+ explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __half_raw(numext::uint16_t raw) : x(numext::bit_cast<__fp16>(raw)) {
+ }
+ __fp16 x;
+#else
+ explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __half_raw(numext::uint16_t raw) : x(raw) {}
+ numext::uint16_t x;
+#endif
+};
+
+#elif defined(EIGEN_HAS_HIP_FP16)
+ // Nothing to do here
+ // HIP fp16 header file has a definition for __half_raw
+#elif defined(EIGEN_HAS_CUDA_FP16)
+ #if EIGEN_CUDA_SDK_VER < 90000
+ // In CUDA < 9.0, __half is the equivalent of CUDA 9's __half_raw
+ typedef __half __half_raw;
+ #endif // defined(EIGEN_HAS_CUDA_FP16)
+#elif defined(SYCL_DEVICE_ONLY)
+ typedef cl::sycl::half __half_raw;
+#endif
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __half_raw raw_uint16_to_half(numext::uint16_t x);
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw float_to_half_rtne(float ff);
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC float half_to_float(__half_raw h);
+
+struct half_base : public __half_raw {
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half_base() {}
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half_base(const __half_raw& h) : __half_raw(h) {}
+
+#if defined(EIGEN_HAS_GPU_FP16)
+ #if defined(EIGEN_HAS_HIP_FP16)
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half_base(const __half& h) { x = __half_as_ushort(h); }
+ #elif defined(EIGEN_HAS_CUDA_FP16)
+ #if EIGEN_CUDA_SDK_VER >= 90000
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half_base(const __half& h) : __half_raw(*(__half_raw*)&h) {}
+ #endif
+ #endif
+#endif
+};
+
+} // namespace half_impl
+
+// Class definition.
+struct half : public half_impl::half_base {
+
+ // Writing this out as separate #if-else blocks to make the code easier to follow
+ // The same applies to most #if-else blocks in this file
+#if !defined(EIGEN_HAS_GPU_FP16) || !defined(EIGEN_GPU_COMPILE_PHASE)
+ // Use the same base class for the following two scenarios
+ // * when compiling without GPU support enabled
+ // * during host compile phase when compiling with GPU support enabled
+ typedef half_impl::__half_raw __half_raw;
+#elif defined(EIGEN_HAS_HIP_FP16)
+ // Nothing to do here
+ // HIP fp16 header file has a definition for __half_raw
+#elif defined(EIGEN_HAS_CUDA_FP16)
+ // Note that EIGEN_CUDA_SDK_VER is set to 0 even when compiling with HIP, so
+ // (EIGEN_CUDA_SDK_VER < 90000) is true even for HIP! So keeping this within
+ // #if defined(EIGEN_HAS_CUDA_FP16) is needed
+ #if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER < 90000
+ typedef half_impl::__half_raw __half_raw;
+ #endif
+#endif
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half() {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half(const __half_raw& h) : half_impl::half_base(h) {}
+
+#if defined(EIGEN_HAS_GPU_FP16)
+ #if defined(EIGEN_HAS_HIP_FP16)
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half(const __half& h) : half_impl::half_base(h) {}
+ #elif defined(EIGEN_HAS_CUDA_FP16)
+ #if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half(const __half& h) : half_impl::half_base(h) {}
+ #endif
+ #endif
+#endif
+
+
+ explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR half(bool b)
+ : half_impl::half_base(half_impl::raw_uint16_to_half(b ? 0x3c00 : 0)) {}
+ template<class T>
+ explicit EIGEN_DEVICE_FUNC half(T val)
+ : half_impl::half_base(half_impl::float_to_half_rtne(static_cast<float>(val))) {}
+ explicit EIGEN_DEVICE_FUNC half(float f)
+ : half_impl::half_base(half_impl::float_to_half_rtne(f)) {}
+
+ // Following the convention of numpy, converting between complex and
+ // float will lead to loss of imag value.
+ template<typename RealScalar>
+ explicit EIGEN_DEVICE_FUNC half(std::complex<RealScalar> c)
+ : half_impl::half_base(half_impl::float_to_half_rtne(static_cast<float>(c.real()))) {}
+
+ EIGEN_DEVICE_FUNC operator float() const { // NOLINT: Allow implicit conversion to float, because it is lossless.
+ return half_impl::half_to_float(*this);
+ }
+
+#if defined(EIGEN_HAS_GPU_FP16) && !defined(EIGEN_GPU_COMPILE_PHASE)
+ EIGEN_DEVICE_FUNC operator __half() const {
+ ::__half_raw hr;
+ hr.x = x;
+ return __half(hr);
+ }
+#endif
+};
+
+} // end namespace Eigen
+
+namespace std {
+template<>
+struct numeric_limits<Eigen::half> {
+ static const bool is_specialized = true;
+ static const bool is_signed = true;
+ static const bool is_integer = false;
+ static const bool is_exact = false;
+ static const bool has_infinity = true;
+ static const bool has_quiet_NaN = true;
+ static const bool has_signaling_NaN = true;
+ static const float_denorm_style has_denorm = denorm_present;
+ static const bool has_denorm_loss = false;
+ static const std::float_round_style round_style = std::round_to_nearest;
+ static const bool is_iec559 = false;
+ static const bool is_bounded = false;
+ static const bool is_modulo = false;
+ static const int digits = 11;
+ static const int digits10 = 3; // according to http://half.sourceforge.net/structstd_1_1numeric__limits_3_01half__float_1_1half_01_4.html
+ static const int max_digits10 = 5; // according to http://half.sourceforge.net/structstd_1_1numeric__limits_3_01half__float_1_1half_01_4.html
+ static const int radix = 2;
+ static const int min_exponent = -13;
+ static const int min_exponent10 = -4;
+ static const int max_exponent = 16;
+ static const int max_exponent10 = 4;
+ static const bool traps = true;
+ static const bool tinyness_before = false;
+
+ static Eigen::half (min)() { return Eigen::half_impl::raw_uint16_to_half(0x400); }
+ static Eigen::half lowest() { return Eigen::half_impl::raw_uint16_to_half(0xfbff); }
+ static Eigen::half (max)() { return Eigen::half_impl::raw_uint16_to_half(0x7bff); }
+ static Eigen::half epsilon() { return Eigen::half_impl::raw_uint16_to_half(0x0800); }
+ static Eigen::half round_error() { return Eigen::half(0.5); }
+ static Eigen::half infinity() { return Eigen::half_impl::raw_uint16_to_half(0x7c00); }
+ static Eigen::half quiet_NaN() { return Eigen::half_impl::raw_uint16_to_half(0x7e00); }
+ static Eigen::half signaling_NaN() { return Eigen::half_impl::raw_uint16_to_half(0x7d00); }
+ static Eigen::half denorm_min() { return Eigen::half_impl::raw_uint16_to_half(0x1); }
+};
+
+// If std::numeric_limits<T> is specialized, should also specialize
+// std::numeric_limits<const T>, std::numeric_limits<volatile T>, and
+// std::numeric_limits<const volatile T>
+// https://stackoverflow.com/a/16519653/
+template<>
+struct numeric_limits<const Eigen::half> : numeric_limits<Eigen::half> {};
+template<>
+struct numeric_limits<volatile Eigen::half> : numeric_limits<Eigen::half> {};
+template<>
+struct numeric_limits<const volatile Eigen::half> : numeric_limits<Eigen::half> {};
+} // end namespace std
+
+namespace Eigen {
+
+namespace half_impl {
+
+#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && \
+ EIGEN_CUDA_ARCH >= 530) || \
+ (defined(EIGEN_HAS_HIP_FP16) && defined(HIP_DEVICE_COMPILE))
+// Note: We deliberatly do *not* define this to 1 even if we have Arm's native
+// fp16 type since GPU halfs are rather different from native CPU halfs.
+// TODO: Rename to something like EIGEN_HAS_NATIVE_GPU_FP16
+#define EIGEN_HAS_NATIVE_FP16
+#endif
+
+// Intrinsics for native fp16 support. Note that on current hardware,
+// these are no faster than fp32 arithmetic (you need to use the half2
+// versions to get the ALU speed increased), but you do save the
+// conversion steps back and forth.
+
+#if defined(EIGEN_HAS_NATIVE_FP16)
+EIGEN_STRONG_INLINE __device__ half operator + (const half& a, const half& b) {
+#if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000
+ return __hadd(::__half(a), ::__half(b));
+#else
+ return __hadd(a, b);
+#endif
+}
+EIGEN_STRONG_INLINE __device__ half operator * (const half& a, const half& b) {
+ return __hmul(a, b);
+}
+EIGEN_STRONG_INLINE __device__ half operator - (const half& a, const half& b) {
+ return __hsub(a, b);
+}
+EIGEN_STRONG_INLINE __device__ half operator / (const half& a, const half& b) {
+#if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000
+ return __hdiv(a, b);
+#else
+ float num = __half2float(a);
+ float denom = __half2float(b);
+ return __float2half(num / denom);
+#endif
+}
+EIGEN_STRONG_INLINE __device__ half operator - (const half& a) {
+ return __hneg(a);
+}
+EIGEN_STRONG_INLINE __device__ half& operator += (half& a, const half& b) {
+ a = a + b;
+ return a;
+}
+EIGEN_STRONG_INLINE __device__ half& operator *= (half& a, const half& b) {
+ a = a * b;
+ return a;
+}
+EIGEN_STRONG_INLINE __device__ half& operator -= (half& a, const half& b) {
+ a = a - b;
+ return a;
+}
+EIGEN_STRONG_INLINE __device__ half& operator /= (half& a, const half& b) {
+ a = a / b;
+ return a;
+}
+EIGEN_STRONG_INLINE __device__ bool operator == (const half& a, const half& b) {
+ return __heq(a, b);
+}
+EIGEN_STRONG_INLINE __device__ bool operator != (const half& a, const half& b) {
+ return __hne(a, b);
+}
+EIGEN_STRONG_INLINE __device__ bool operator < (const half& a, const half& b) {
+ return __hlt(a, b);
+}
+EIGEN_STRONG_INLINE __device__ bool operator <= (const half& a, const half& b) {
+ return __hle(a, b);
+}
+EIGEN_STRONG_INLINE __device__ bool operator > (const half& a, const half& b) {
+ return __hgt(a, b);
+}
+EIGEN_STRONG_INLINE __device__ bool operator >= (const half& a, const half& b) {
+ return __hge(a, b);
+}
+#endif
+
+#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator + (const half& a, const half& b) {
+ return half(vaddh_f16(a.x, b.x));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator * (const half& a, const half& b) {
+ return half(vmulh_f16(a.x, b.x));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator - (const half& a, const half& b) {
+ return half(vsubh_f16(a.x, b.x));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator / (const half& a, const half& b) {
+ return half(vdivh_f16(a.x, b.x));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator - (const half& a) {
+ return half(vnegh_f16(a.x));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator += (half& a, const half& b) {
+ a = half(vaddh_f16(a.x, b.x));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator *= (half& a, const half& b) {
+ a = half(vmulh_f16(a.x, b.x));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator -= (half& a, const half& b) {
+ a = half(vsubh_f16(a.x, b.x));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator /= (half& a, const half& b) {
+ a = half(vdivh_f16(a.x, b.x));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator == (const half& a, const half& b) {
+ return vceqh_f16(a.x, b.x);
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator != (const half& a, const half& b) {
+ return !vceqh_f16(a.x, b.x);
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator < (const half& a, const half& b) {
+ return vclth_f16(a.x, b.x);
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator <= (const half& a, const half& b) {
+ return vcleh_f16(a.x, b.x);
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator > (const half& a, const half& b) {
+ return vcgth_f16(a.x, b.x);
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator >= (const half& a, const half& b) {
+ return vcgeh_f16(a.x, b.x);
+}
+// We need to distinguish ‘clang as the CUDA compiler’ from ‘clang as the host compiler,
+// invoked by NVCC’ (e.g. on MacOS). The former needs to see both host and device implementation
+// of the functions, while the latter can only deal with one of them.
+#elif !defined(EIGEN_HAS_NATIVE_FP16) || (EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC) // Emulate support for half floats
+
+#if EIGEN_COMP_CLANG && defined(EIGEN_CUDACC)
+// We need to provide emulated *host-side* FP16 operators for clang.
+#pragma push_macro("EIGEN_DEVICE_FUNC")
+#undef EIGEN_DEVICE_FUNC
+#if defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_HAS_NATIVE_FP16)
+#define EIGEN_DEVICE_FUNC __host__
+#else // both host and device need emulated ops.
+#define EIGEN_DEVICE_FUNC __host__ __device__
+#endif
+#endif
+
+// Definitions for CPUs and older HIP+CUDA, mostly working through conversion
+// to/from fp32.
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator + (const half& a, const half& b) {
+ return half(float(a) + float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator * (const half& a, const half& b) {
+ return half(float(a) * float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator - (const half& a, const half& b) {
+ return half(float(a) - float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator / (const half& a, const half& b) {
+ return half(float(a) / float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator - (const half& a) {
+ half result;
+ result.x = a.x ^ 0x8000;
+ return result;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator += (half& a, const half& b) {
+ a = half(float(a) + float(b));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator *= (half& a, const half& b) {
+ a = half(float(a) * float(b));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator -= (half& a, const half& b) {
+ a = half(float(a) - float(b));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator /= (half& a, const half& b) {
+ a = half(float(a) / float(b));
+ return a;
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator == (const half& a, const half& b) {
+ return numext::equal_strict(float(a),float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator != (const half& a, const half& b) {
+ return numext::not_equal_strict(float(a), float(b));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator < (const half& a, const half& b) {
+ return float(a) < float(b);
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator <= (const half& a, const half& b) {
+ return float(a) <= float(b);
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator > (const half& a, const half& b) {
+ return float(a) > float(b);
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator >= (const half& a, const half& b) {
+ return float(a) >= float(b);
+}
+
+#if defined(__clang__) && defined(__CUDA__)
+#pragma pop_macro("EIGEN_DEVICE_FUNC")
+#endif
+#endif // Emulate support for half floats
+
+// Division by an index. Do it in full float precision to avoid accuracy
+// issues in converting the denominator to half.
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator / (const half& a, Index b) {
+ return half(static_cast<float>(a) / static_cast<float>(b));
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator++(half& a) {
+ a += half(1);
+ return a;
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator--(half& a) {
+ a -= half(1);
+ return a;
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator++(half& a, int) {
+ half original_value = a;
+ ++a;
+ return original_value;
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator--(half& a, int) {
+ half original_value = a;
+ --a;
+ return original_value;
+}
+
+// Conversion routines, including fallbacks for the host or older CUDA.
+// Note that newer Intel CPUs (Haswell or newer) have vectorized versions of
+// these in hardware. If we need more performance on older/other CPUs, they are
+// also possible to vectorize directly.
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __half_raw raw_uint16_to_half(numext::uint16_t x) {
+ // We cannot simply do a "return __half_raw(x)" here, because __half_raw is union type
+ // in the hip_fp16 header file, and that will trigger a compile error
+ // On the other hand, having anything but a return statement also triggers a compile error
+ // because this is constexpr function.
+ // Fortunately, since we need to disable EIGEN_CONSTEXPR for GPU anyway, we can get out
+ // of this catch22 by having separate bodies for GPU / non GPU
+#if defined(EIGEN_HAS_GPU_FP16)
+ __half_raw h;
+ h.x = x;
+ return h;
+#else
+ return __half_raw(x);
+#endif
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC numext::uint16_t raw_half_as_uint16(const __half_raw& h) {
+ // HIP/CUDA/Default have a member 'x' of type uint16_t.
+ // For ARM64 native half, the member 'x' is of type __fp16, so we need to bit-cast.
+ // For SYCL, cl::sycl::half is _Float16, so cast directly.
+#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
+ return numext::bit_cast<numext::uint16_t>(h.x);
+#elif defined(SYCL_DEVICE_ONLY)
+ return numext::bit_cast<numext::uint16_t>(h);
+#else
+ return h.x;
+#endif
+}
+
+union float32_bits {
+ unsigned int u;
+ float f;
+};
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw float_to_half_rtne(float ff) {
+#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
+ (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
+ __half tmp_ff = __float2half(ff);
+ return *(__half_raw*)&tmp_ff;
+
+#elif defined(EIGEN_HAS_FP16_C)
+ __half_raw h;
+ h.x = _cvtss_sh(ff, 0);
+ return h;
+
+#elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
+ __half_raw h;
+ h.x = static_cast<__fp16>(ff);
+ return h;
+
+#else
+ float32_bits f; f.f = ff;
+
+ const float32_bits f32infty = { 255 << 23 };
+ const float32_bits f16max = { (127 + 16) << 23 };
+ const float32_bits denorm_magic = { ((127 - 15) + (23 - 10) + 1) << 23 };
+ unsigned int sign_mask = 0x80000000u;
+ __half_raw o;
+ o.x = static_cast<numext::uint16_t>(0x0u);
+
+ unsigned int sign = f.u & sign_mask;
+ f.u ^= sign;
+
+ // NOTE all the integer compares in this function can be safely
+ // compiled into signed compares since all operands are below
+ // 0x80000000. Important if you want fast straight SSE2 code
+ // (since there's no unsigned PCMPGTD).
+
+ if (f.u >= f16max.u) { // result is Inf or NaN (all exponent bits set)
+ o.x = (f.u > f32infty.u) ? 0x7e00 : 0x7c00; // NaN->qNaN and Inf->Inf
+ } else { // (De)normalized number or zero
+ if (f.u < (113 << 23)) { // resulting FP16 is subnormal or zero
+ // use a magic value to align our 10 mantissa bits at the bottom of
+ // the float. as long as FP addition is round-to-nearest-even this
+ // just works.
+ f.f += denorm_magic.f;
+
+ // and one integer subtract of the bias later, we have our final float!
+ o.x = static_cast<numext::uint16_t>(f.u - denorm_magic.u);
+ } else {
+ unsigned int mant_odd = (f.u >> 13) & 1; // resulting mantissa is odd
+
+ // update exponent, rounding bias part 1
+ // Equivalent to `f.u += ((unsigned int)(15 - 127) << 23) + 0xfff`, but
+ // without arithmetic overflow.
+ f.u += 0xc8000fffU;
+ // rounding bias part 2
+ f.u += mant_odd;
+ // take the bits!
+ o.x = static_cast<numext::uint16_t>(f.u >> 13);
+ }
+ }
+
+ o.x |= static_cast<numext::uint16_t>(sign >> 16);
+ return o;
+#endif
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC float half_to_float(__half_raw h) {
+#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
+ (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
+ return __half2float(h);
+#elif defined(EIGEN_HAS_FP16_C)
+ return _cvtsh_ss(h.x);
+#elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
+ return static_cast<float>(h.x);
+#else
+ const float32_bits magic = { 113 << 23 };
+ const unsigned int shifted_exp = 0x7c00 << 13; // exponent mask after shift
+ float32_bits o;
+
+ o.u = (h.x & 0x7fff) << 13; // exponent/mantissa bits
+ unsigned int exp = shifted_exp & o.u; // just the exponent
+ o.u += (127 - 15) << 23; // exponent adjust
+
+ // handle exponent special cases
+ if (exp == shifted_exp) { // Inf/NaN?
+ o.u += (128 - 16) << 23; // extra exp adjust
+ } else if (exp == 0) { // Zero/Denormal?
+ o.u += 1 << 23; // extra exp adjust
+ o.f -= magic.f; // renormalize
+ }
+
+ o.u |= (h.x & 0x8000) << 16; // sign bit
+ return o.f;
+#endif
+}
+
+// --- standard functions ---
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isinf)(const half& a) {
+#ifdef EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC
+ return (numext::bit_cast<numext::uint16_t>(a.x) & 0x7fff) == 0x7c00;
+#else
+ return (a.x & 0x7fff) == 0x7c00;
+#endif
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isnan)(const half& a) {
+#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
+ (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
+ return __hisnan(a);
+#elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
+ return (numext::bit_cast<numext::uint16_t>(a.x) & 0x7fff) > 0x7c00;
+#else
+ return (a.x & 0x7fff) > 0x7c00;
+#endif
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isfinite)(const half& a) {
+ return !(isinf EIGEN_NOT_A_MACRO (a)) && !(isnan EIGEN_NOT_A_MACRO (a));
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half abs(const half& a) {
+#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
+ return half(vabsh_f16(a.x));
+#else
+ half result;
+ result.x = a.x & 0x7FFF;
+ return result;
+#endif
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half exp(const half& a) {
+#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \
+ defined(EIGEN_HIP_DEVICE_COMPILE)
+ return half(hexp(a));
+#else
+ return half(::expf(float(a)));
+#endif
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half expm1(const half& a) {
+ return half(numext::expm1(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log(const half& a) {
+#if (defined(EIGEN_HAS_CUDA_FP16) && EIGEN_CUDA_SDK_VER >= 80000 && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
+ (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
+ return half(::hlog(a));
+#else
+ return half(::logf(float(a)));
+#endif
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log1p(const half& a) {
+ return half(numext::log1p(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log10(const half& a) {
+ return half(::log10f(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log2(const half& a) {
+ return half(static_cast<float>(EIGEN_LOG2E) * ::logf(float(a)));
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sqrt(const half& a) {
+#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \
+ defined(EIGEN_HIP_DEVICE_COMPILE)
+ return half(hsqrt(a));
+#else
+ return half(::sqrtf(float(a)));
+#endif
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half& a, const half& b) {
+ return half(::powf(float(a), float(b)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sin(const half& a) {
+ return half(::sinf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half cos(const half& a) {
+ return half(::cosf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tan(const half& a) {
+ return half(::tanf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tanh(const half& a) {
+ return half(::tanhf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half asin(const half& a) {
+ return half(::asinf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half acos(const half& a) {
+ return half(::acosf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half floor(const half& a) {
+#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 300) || \
+ defined(EIGEN_HIP_DEVICE_COMPILE)
+ return half(hfloor(a));
+#else
+ return half(::floorf(float(a)));
+#endif
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half ceil(const half& a) {
+#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 300) || \
+ defined(EIGEN_HIP_DEVICE_COMPILE)
+ return half(hceil(a));
+#else
+ return half(::ceilf(float(a)));
+#endif
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half rint(const half& a) {
+ return half(::rintf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half round(const half& a) {
+ return half(::roundf(float(a)));
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half fmod(const half& a, const half& b) {
+ return half(::fmodf(float(a), float(b)));
+}
+
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half (min)(const half& a, const half& b) {
+#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
+ (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
+ return __hlt(b, a) ? b : a;
+#else
+ const float f1 = static_cast<float>(a);
+ const float f2 = static_cast<float>(b);
+ return f2 < f1 ? b : a;
+#endif
+}
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half (max)(const half& a, const half& b) {
+#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
+ (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
+ return __hlt(a, b) ? b : a;
+#else
+ const float f1 = static_cast<float>(a);
+ const float f2 = static_cast<float>(b);
+ return f1 < f2 ? b : a;
+#endif
+}
+
+#ifndef EIGEN_NO_IO
+EIGEN_ALWAYS_INLINE std::ostream& operator << (std::ostream& os, const half& v) {
+ os << static_cast<float>(v);
+ return os;
+}
+#endif
+
+} // end namespace half_impl
+
+// import Eigen::half_impl::half into Eigen namespace
+// using half_impl::half;
+
+namespace internal {
+
+template<>
+struct random_default_impl<half, false, false>
+{
+ static inline half run(const half& x, const half& y)
+ {
+ return x + (y-x) * half(float(std::rand()) / float(RAND_MAX));
+ }
+ static inline half run()
+ {
+ return run(half(-1.f), half(1.f));
+ }
+};
+
+template<> struct is_arithmetic<half> { enum { value = true }; };
+
+} // end namespace internal
+
+template<> struct NumTraits<Eigen::half>
+ : GenericNumTraits<Eigen::half>
+{
+ enum {
+ IsSigned = true,
+ IsInteger = false,
+ IsComplex = false,
+ RequireInitialization = false
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half epsilon() {
+ return half_impl::raw_uint16_to_half(0x0800);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half dummy_precision() {
+ return half_impl::raw_uint16_to_half(0x211f); // Eigen::half(1e-2f);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half highest() {
+ return half_impl::raw_uint16_to_half(0x7bff);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half lowest() {
+ return half_impl::raw_uint16_to_half(0xfbff);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half infinity() {
+ return half_impl::raw_uint16_to_half(0x7c00);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half quiet_NaN() {
+ return half_impl::raw_uint16_to_half(0x7e00);
+ }
+};
+
+} // end namespace Eigen
+
+#if defined(EIGEN_HAS_GPU_FP16) || defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
+ #pragma pop_macro("EIGEN_CONSTEXPR")
+#endif
+
+namespace Eigen {
+namespace numext {
+
+#if defined(EIGEN_GPU_COMPILE_PHASE)
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool(isnan)(const Eigen::half& h) {
+ return (half_impl::isnan)(h);
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool(isinf)(const Eigen::half& h) {
+ return (half_impl::isinf)(h);
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool(isfinite)(const Eigen::half& h) {
+ return (half_impl::isfinite)(h);
+}
+
+#endif
+
+template <>
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bit_cast<Eigen::half, uint16_t>(const uint16_t& src) {
+ return Eigen::half(Eigen::half_impl::raw_uint16_to_half(src));
+}
+
+template <>
+EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC uint16_t bit_cast<uint16_t, Eigen::half>(const Eigen::half& src) {
+ return Eigen::half_impl::raw_half_as_uint16(src);
+}
+
+} // namespace numext
+} // namespace Eigen
+
+// Add the missing shfl* intrinsics.
+// The __shfl* functions are only valid on HIP or _CUDA_ARCH_ >= 300.
+// CUDA defines them for (__CUDA_ARCH__ >= 300 || !defined(__CUDA_ARCH__))
+//
+// HIP and CUDA prior to SDK 9.0 define
+// __shfl, __shfl_up, __shfl_down, __shfl_xor for int and float
+// CUDA since 9.0 deprecates those and instead defines
+// __shfl_sync, __shfl_up_sync, __shfl_down_sync, __shfl_xor_sync,
+// with native support for __half and __nv_bfloat16
+//
+// Note that the following are __device__ - only functions.
+#if (defined(EIGEN_CUDACC) && (!defined(EIGEN_CUDA_ARCH) || EIGEN_CUDA_ARCH >= 300)) \
+ || defined(EIGEN_HIPCC)
+
+#if defined(EIGEN_HAS_CUDA_FP16) && EIGEN_CUDA_SDK_VER >= 90000
+
+__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_sync(unsigned mask, Eigen::half var, int srcLane, int width=warpSize) {
+ const __half h = var;
+ return static_cast<Eigen::half>(__shfl_sync(mask, h, srcLane, width));
+}
+
+__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_up_sync(unsigned mask, Eigen::half var, unsigned int delta, int width=warpSize) {
+ const __half h = var;
+ return static_cast<Eigen::half>(__shfl_up_sync(mask, h, delta, width));
+}
+
+__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_down_sync(unsigned mask, Eigen::half var, unsigned int delta, int width=warpSize) {
+ const __half h = var;
+ return static_cast<Eigen::half>(__shfl_down_sync(mask, h, delta, width));
+}
+
+__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_xor_sync(unsigned mask, Eigen::half var, int laneMask, int width=warpSize) {
+ const __half h = var;
+ return static_cast<Eigen::half>(__shfl_xor_sync(mask, h, laneMask, width));
+}
+
+#else // HIP or CUDA SDK < 9.0
+
+__device__ EIGEN_STRONG_INLINE Eigen::half __shfl(Eigen::half var, int srcLane, int width=warpSize) {
+ const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
+ return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl(ivar, srcLane, width)));
+}
+
+__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_up(Eigen::half var, unsigned int delta, int width=warpSize) {
+ const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
+ return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl_up(ivar, delta, width)));
+}
+
+__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_down(Eigen::half var, unsigned int delta, int width=warpSize) {
+ const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
+ return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl_down(ivar, delta, width)));
+}
+
+__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_xor(Eigen::half var, int laneMask, int width=warpSize) {
+ const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
+ return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl_xor(ivar, laneMask, width)));
+}
+
+#endif // HIP vs CUDA
+#endif // __shfl*
+
+// ldg() has an overload for __half_raw, but we also need one for Eigen::half.
+#if (defined(EIGEN_CUDACC) && (!defined(EIGEN_CUDA_ARCH) || EIGEN_CUDA_ARCH >= 350)) \
+ || defined(EIGEN_HIPCC)
+EIGEN_STRONG_INLINE __device__ Eigen::half __ldg(const Eigen::half* ptr) {
+ return Eigen::half_impl::raw_uint16_to_half(__ldg(reinterpret_cast<const Eigen::numext::uint16_t*>(ptr)));
+}
+#endif // __ldg
+
+#if EIGEN_HAS_STD_HASH
+namespace std {
+template <>
+struct hash<Eigen::half> {
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t operator()(const Eigen::half& a) const {
+ return static_cast<std::size_t>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(a));
+ }
+};
+} // end namespace std
+#endif
+
+#endif // EIGEN_HALF_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/Default/Settings.h b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/Settings.h
new file mode 100644
index 000000000..a5c3ada4c
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/Settings.h
@@ -0,0 +1,49 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+/* All the parameters defined in this file can be specialized in the
+ * architecture specific files, and/or by the user.
+ * More to come... */
+
+#ifndef EIGEN_DEFAULT_SETTINGS_H
+#define EIGEN_DEFAULT_SETTINGS_H
+
+/** Defines the maximal loop size to enable meta unrolling of loops.
+ * Note that the value here is expressed in Eigen's own notion of "number of FLOPS",
+ * it does not correspond to the number of iterations or the number of instructions
+ */
+#ifndef EIGEN_UNROLLING_LIMIT
+#define EIGEN_UNROLLING_LIMIT 110
+#endif
+
+/** Defines the threshold between a "small" and a "large" matrix.
+ * This threshold is mainly used to select the proper product implementation.
+ */
+#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
+#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
+#endif
+
+/** Defines the maximal width of the blocks used in the triangular product and solver
+ * for vectors (level 2 blas xTRMV and xTRSV). The default is 8.
+ */
+#ifndef EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH
+#define EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH 8
+#endif
+
+
+/** Defines the default number of registers available for that architecture.
+ * Currently it must be 8 or 16. Other values will fail.
+ */
+#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS
+#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 8
+#endif
+
+#endif // EIGEN_DEFAULT_SETTINGS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/Default/TypeCasting.h b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/TypeCasting.h
new file mode 100644
index 000000000..fb8183b78
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/Default/TypeCasting.h
@@ -0,0 +1,120 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com>
+// Copyright (C) 2019 Rasmus Munk Larsen <rmlarsen@google.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GENERIC_TYPE_CASTING_H
+#define EIGEN_GENERIC_TYPE_CASTING_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<>
+struct scalar_cast_op<float, Eigen::half> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
+ typedef Eigen::half result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half operator() (const float& a) const {
+ #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
+ (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
+ return __float2half(a);
+ #else
+ return Eigen::half(a);
+ #endif
+ }
+};
+
+template<>
+struct functor_traits<scalar_cast_op<float, Eigen::half> >
+{ enum { Cost = NumTraits<float>::AddCost, PacketAccess = false }; };
+
+
+template<>
+struct scalar_cast_op<int, Eigen::half> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
+ typedef Eigen::half result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half operator() (const int& a) const {
+ #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
+ (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
+ return __float2half(static_cast<float>(a));
+ #else
+ return Eigen::half(static_cast<float>(a));
+ #endif
+ }
+};
+
+template<>
+struct functor_traits<scalar_cast_op<int, Eigen::half> >
+{ enum { Cost = NumTraits<float>::AddCost, PacketAccess = false }; };
+
+
+template<>
+struct scalar_cast_op<Eigen::half, float> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
+ typedef float result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float operator() (const Eigen::half& a) const {
+ #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
+ (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
+ return __half2float(a);
+ #else
+ return static_cast<float>(a);
+ #endif
+ }
+};
+
+template<>
+struct functor_traits<scalar_cast_op<Eigen::half, float> >
+{ enum { Cost = NumTraits<float>::AddCost, PacketAccess = false }; };
+
+
+template<>
+struct scalar_cast_op<float, Eigen::bfloat16> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
+ typedef Eigen::bfloat16 result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::bfloat16 operator() (const float& a) const {
+ return Eigen::bfloat16(a);
+ }
+};
+
+template<>
+struct functor_traits<scalar_cast_op<float, Eigen::bfloat16> >
+{ enum { Cost = NumTraits<float>::AddCost, PacketAccess = false }; };
+
+
+template<>
+struct scalar_cast_op<int, Eigen::bfloat16> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
+ typedef Eigen::bfloat16 result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::bfloat16 operator() (const int& a) const {
+ return Eigen::bfloat16(static_cast<float>(a));
+ }
+};
+
+template<>
+struct functor_traits<scalar_cast_op<int, Eigen::bfloat16> >
+{ enum { Cost = NumTraits<float>::AddCost, PacketAccess = false }; };
+
+
+template<>
+struct scalar_cast_op<Eigen::bfloat16, float> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
+ typedef float result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float operator() (const Eigen::bfloat16& a) const {
+ return static_cast<float>(a);
+ }
+};
+
+template<>
+struct functor_traits<scalar_cast_op<Eigen::bfloat16, float> >
+{ enum { Cost = NumTraits<float>::AddCost, PacketAccess = false }; };
+
+
+}
+}
+
+#endif // EIGEN_GENERIC_TYPE_CASTING_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/GPU/MathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/arch/GPU/MathFunctions.h
new file mode 100644
index 000000000..d2b3a2568
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/GPU/MathFunctions.h
@@ -0,0 +1,103 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATH_FUNCTIONS_GPU_H
+#define EIGEN_MATH_FUNCTIONS_GPU_H
+
+namespace Eigen {
+
+namespace internal {
+
+// Make sure this is only available when targeting a GPU: we don't want to
+// introduce conflicts between these packet_traits definitions and the ones
+// we'll use on the host side (SSE, AVX, ...)
+#if defined(EIGEN_GPUCC) && defined(EIGEN_USE_GPU)
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+float4 plog<float4>(const float4& a)
+{
+ return make_float4(logf(a.x), logf(a.y), logf(a.z), logf(a.w));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+double2 plog<double2>(const double2& a)
+{
+ using ::log;
+ return make_double2(log(a.x), log(a.y));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+float4 plog1p<float4>(const float4& a)
+{
+ return make_float4(log1pf(a.x), log1pf(a.y), log1pf(a.z), log1pf(a.w));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+double2 plog1p<double2>(const double2& a)
+{
+ return make_double2(log1p(a.x), log1p(a.y));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+float4 pexp<float4>(const float4& a)
+{
+ return make_float4(expf(a.x), expf(a.y), expf(a.z), expf(a.w));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+double2 pexp<double2>(const double2& a)
+{
+ using ::exp;
+ return make_double2(exp(a.x), exp(a.y));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+float4 pexpm1<float4>(const float4& a)
+{
+ return make_float4(expm1f(a.x), expm1f(a.y), expm1f(a.z), expm1f(a.w));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+double2 pexpm1<double2>(const double2& a)
+{
+ return make_double2(expm1(a.x), expm1(a.y));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+float4 psqrt<float4>(const float4& a)
+{
+ return make_float4(sqrtf(a.x), sqrtf(a.y), sqrtf(a.z), sqrtf(a.w));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+double2 psqrt<double2>(const double2& a)
+{
+ using ::sqrt;
+ return make_double2(sqrt(a.x), sqrt(a.y));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+float4 prsqrt<float4>(const float4& a)
+{
+ return make_float4(rsqrtf(a.x), rsqrtf(a.y), rsqrtf(a.z), rsqrtf(a.w));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+double2 prsqrt<double2>(const double2& a)
+{
+ return make_double2(rsqrt(a.x), rsqrt(a.y));
+}
+
+
+#endif
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATH_FUNCTIONS_GPU_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/GPU/PacketMath.h b/src/3rdparty/eigen/Eigen/src/Core/arch/GPU/PacketMath.h
new file mode 100644
index 000000000..689110ded
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/GPU/PacketMath.h
@@ -0,0 +1,1685 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PACKET_MATH_GPU_H
+#define EIGEN_PACKET_MATH_GPU_H
+
+namespace Eigen {
+
+namespace internal {
+
+// Read-only data cached load available.
+#if defined(EIGEN_HIP_DEVICE_COMPILE) || (defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 350)
+#define EIGEN_GPU_HAS_LDG 1
+#endif
+
+// FP16 math available.
+#if (defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530)
+#define EIGEN_CUDA_HAS_FP16_ARITHMETIC 1
+#endif
+
+#if defined(EIGEN_HIP_DEVICE_COMPILE) || defined(EIGEN_CUDA_HAS_FP16_ARITHMETIC)
+#define EIGEN_GPU_HAS_FP16_ARITHMETIC 1
+#endif
+
+// Make sure this is only available when targeting a GPU: we don't want to
+// introduce conflicts between these packet_traits definitions and the ones
+// we'll use on the host side (SSE, AVX, ...)
+#if defined(EIGEN_GPUCC) && defined(EIGEN_USE_GPU)
+
+template<> struct is_arithmetic<float4> { enum { value = true }; };
+template<> struct is_arithmetic<double2> { enum { value = true }; };
+
+template<> struct packet_traits<float> : default_packet_traits
+{
+ typedef float4 type;
+ typedef float4 half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size=4,
+ HasHalfPacket = 0,
+
+ HasDiv = 1,
+ HasSin = 0,
+ HasCos = 0,
+ HasLog = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasLGamma = 1,
+ HasDiGamma = 1,
+ HasZeta = 1,
+ HasPolygamma = 1,
+ HasErf = 1,
+ HasErfc = 1,
+ HasNdtri = 1,
+ HasBessel = 1,
+ HasIGamma = 1,
+ HasIGammaDerA = 1,
+ HasGammaSampleDerAlpha = 1,
+ HasIGammac = 1,
+ HasBetaInc = 1,
+
+ HasBlend = 0,
+ HasFloor = 1,
+ };
+};
+
+template<> struct packet_traits<double> : default_packet_traits
+{
+ typedef double2 type;
+ typedef double2 half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size=2,
+ HasHalfPacket = 0,
+
+ HasDiv = 1,
+ HasLog = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasLGamma = 1,
+ HasDiGamma = 1,
+ HasZeta = 1,
+ HasPolygamma = 1,
+ HasErf = 1,
+ HasErfc = 1,
+ HasNdtri = 1,
+ HasBessel = 1,
+ HasIGamma = 1,
+ HasIGammaDerA = 1,
+ HasGammaSampleDerAlpha = 1,
+ HasIGammac = 1,
+ HasBetaInc = 1,
+
+ HasBlend = 0,
+ HasFloor = 1,
+ };
+};
+
+
+template<> struct unpacket_traits<float4> { typedef float type; enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef float4 half; };
+template<> struct unpacket_traits<double2> { typedef double type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef double2 half; };
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pset1<float4>(const float& from) {
+ return make_float4(from, from, from, from);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pset1<double2>(const double& from) {
+ return make_double2(from, from);
+}
+
+// We need to distinguish ‘clang as the CUDA compiler’ from ‘clang as the host compiler,
+// invoked by NVCC’ (e.g. on MacOS). The former needs to see both host and device implementation
+// of the functions, while the latter can only deal with one of them.
+#if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC)
+namespace {
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float bitwise_and(const float& a,
+ const float& b) {
+ return __int_as_float(__float_as_int(a) & __float_as_int(b));
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bitwise_and(const double& a,
+ const double& b) {
+ return __longlong_as_double(__double_as_longlong(a) &
+ __double_as_longlong(b));
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float bitwise_or(const float& a,
+ const float& b) {
+ return __int_as_float(__float_as_int(a) | __float_as_int(b));
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bitwise_or(const double& a,
+ const double& b) {
+ return __longlong_as_double(__double_as_longlong(a) |
+ __double_as_longlong(b));
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float bitwise_xor(const float& a,
+ const float& b) {
+ return __int_as_float(__float_as_int(a) ^ __float_as_int(b));
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bitwise_xor(const double& a,
+ const double& b) {
+ return __longlong_as_double(__double_as_longlong(a) ^
+ __double_as_longlong(b));
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float bitwise_andnot(const float& a,
+ const float& b) {
+ return __int_as_float(__float_as_int(a) & ~__float_as_int(b));
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bitwise_andnot(const double& a,
+ const double& b) {
+ return __longlong_as_double(__double_as_longlong(a) &
+ ~__double_as_longlong(b));
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float eq_mask(const float& a,
+ const float& b) {
+ return __int_as_float(a == b ? 0xffffffffu : 0u);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double eq_mask(const double& a,
+ const double& b) {
+ return __longlong_as_double(a == b ? 0xffffffffffffffffull : 0ull);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float lt_mask(const float& a,
+ const float& b) {
+ return __int_as_float(a < b ? 0xffffffffu : 0u);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double lt_mask(const double& a,
+ const double& b) {
+ return __longlong_as_double(a < b ? 0xffffffffffffffffull : 0ull);
+}
+
+} // namespace
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pand<float4>(const float4& a,
+ const float4& b) {
+ return make_float4(bitwise_and(a.x, b.x), bitwise_and(a.y, b.y),
+ bitwise_and(a.z, b.z), bitwise_and(a.w, b.w));
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pand<double2>(const double2& a,
+ const double2& b) {
+ return make_double2(bitwise_and(a.x, b.x), bitwise_and(a.y, b.y));
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 por<float4>(const float4& a,
+ const float4& b) {
+ return make_float4(bitwise_or(a.x, b.x), bitwise_or(a.y, b.y),
+ bitwise_or(a.z, b.z), bitwise_or(a.w, b.w));
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 por<double2>(const double2& a,
+ const double2& b) {
+ return make_double2(bitwise_or(a.x, b.x), bitwise_or(a.y, b.y));
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pxor<float4>(const float4& a,
+ const float4& b) {
+ return make_float4(bitwise_xor(a.x, b.x), bitwise_xor(a.y, b.y),
+ bitwise_xor(a.z, b.z), bitwise_xor(a.w, b.w));
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pxor<double2>(const double2& a,
+ const double2& b) {
+ return make_double2(bitwise_xor(a.x, b.x), bitwise_xor(a.y, b.y));
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pandnot<float4>(const float4& a,
+ const float4& b) {
+ return make_float4(bitwise_andnot(a.x, b.x), bitwise_andnot(a.y, b.y),
+ bitwise_andnot(a.z, b.z), bitwise_andnot(a.w, b.w));
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
+pandnot<double2>(const double2& a, const double2& b) {
+ return make_double2(bitwise_andnot(a.x, b.x), bitwise_andnot(a.y, b.y));
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcmp_eq<float4>(const float4& a,
+ const float4& b) {
+ return make_float4(eq_mask(a.x, b.x), eq_mask(a.y, b.y), eq_mask(a.z, b.z),
+ eq_mask(a.w, b.w));
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcmp_lt<float4>(const float4& a,
+ const float4& b) {
+ return make_float4(lt_mask(a.x, b.x), lt_mask(a.y, b.y), lt_mask(a.z, b.z),
+ lt_mask(a.w, b.w));
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
+pcmp_eq<double2>(const double2& a, const double2& b) {
+ return make_double2(eq_mask(a.x, b.x), eq_mask(a.y, b.y));
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
+pcmp_lt<double2>(const double2& a, const double2& b) {
+ return make_double2(lt_mask(a.x, b.x), lt_mask(a.y, b.y));
+}
+#endif // defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC)
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 plset<float4>(const float& a) {
+ return make_float4(a, a+1, a+2, a+3);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 plset<double2>(const double& a) {
+ return make_double2(a, a+1);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 padd<float4>(const float4& a, const float4& b) {
+ return make_float4(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 padd<double2>(const double2& a, const double2& b) {
+ return make_double2(a.x+b.x, a.y+b.y);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 psub<float4>(const float4& a, const float4& b) {
+ return make_float4(a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 psub<double2>(const double2& a, const double2& b) {
+ return make_double2(a.x-b.x, a.y-b.y);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pnegate(const float4& a) {
+ return make_float4(-a.x, -a.y, -a.z, -a.w);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pnegate(const double2& a) {
+ return make_double2(-a.x, -a.y);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pconj(const float4& a) { return a; }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pconj(const double2& a) { return a; }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pmul<float4>(const float4& a, const float4& b) {
+ return make_float4(a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pmul<double2>(const double2& a, const double2& b) {
+ return make_double2(a.x*b.x, a.y*b.y);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pdiv<float4>(const float4& a, const float4& b) {
+ return make_float4(a.x/b.x, a.y/b.y, a.z/b.z, a.w/b.w);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pdiv<double2>(const double2& a, const double2& b) {
+ return make_double2(a.x/b.x, a.y/b.y);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pmin<float4>(const float4& a, const float4& b) {
+ return make_float4(fminf(a.x, b.x), fminf(a.y, b.y), fminf(a.z, b.z), fminf(a.w, b.w));
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pmin<double2>(const double2& a, const double2& b) {
+ return make_double2(fmin(a.x, b.x), fmin(a.y, b.y));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pmax<float4>(const float4& a, const float4& b) {
+ return make_float4(fmaxf(a.x, b.x), fmaxf(a.y, b.y), fmaxf(a.z, b.z), fmaxf(a.w, b.w));
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pmax<double2>(const double2& a, const double2& b) {
+ return make_double2(fmax(a.x, b.x), fmax(a.y, b.y));
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pload<float4>(const float* from) {
+ return *reinterpret_cast<const float4*>(from);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pload<double2>(const double* from) {
+ return *reinterpret_cast<const double2*>(from);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 ploadu<float4>(const float* from) {
+ return make_float4(from[0], from[1], from[2], from[3]);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 ploadu<double2>(const double* from) {
+ return make_double2(from[0], from[1]);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 ploaddup<float4>(const float* from) {
+ return make_float4(from[0], from[0], from[1], from[1]);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 ploaddup<double2>(const double* from) {
+ return make_double2(from[0], from[0]);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstore<float>(float* to, const float4& from) {
+ *reinterpret_cast<float4*>(to) = from;
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstore<double>(double* to, const double2& from) {
+ *reinterpret_cast<double2*>(to) = from;
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const float4& from) {
+ to[0] = from.x;
+ to[1] = from.y;
+ to[2] = from.z;
+ to[3] = from.w;
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const double2& from) {
+ to[0] = from.x;
+ to[1] = from.y;
+}
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float4 ploadt_ro<float4, Aligned>(const float* from) {
+#if defined(EIGEN_GPU_HAS_LDG)
+ return __ldg((const float4*)from);
+#else
+ return make_float4(from[0], from[1], from[2], from[3]);
+#endif
+}
+template<>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double2 ploadt_ro<double2, Aligned>(const double* from) {
+#if defined(EIGEN_GPU_HAS_LDG)
+ return __ldg((const double2*)from);
+#else
+ return make_double2(from[0], from[1]);
+#endif
+}
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float4 ploadt_ro<float4, Unaligned>(const float* from) {
+#if defined(EIGEN_GPU_HAS_LDG)
+ return make_float4(__ldg(from+0), __ldg(from+1), __ldg(from+2), __ldg(from+3));
+#else
+ return make_float4(from[0], from[1], from[2], from[3]);
+#endif
+}
+template<>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double2 ploadt_ro<double2, Unaligned>(const double* from) {
+#if defined(EIGEN_GPU_HAS_LDG)
+ return make_double2(__ldg(from+0), __ldg(from+1));
+#else
+ return make_double2(from[0], from[1]);
+#endif
+}
+
+template<> EIGEN_DEVICE_FUNC inline float4 pgather<float, float4>(const float* from, Index stride) {
+ return make_float4(from[0*stride], from[1*stride], from[2*stride], from[3*stride]);
+}
+
+template<> EIGEN_DEVICE_FUNC inline double2 pgather<double, double2>(const double* from, Index stride) {
+ return make_double2(from[0*stride], from[1*stride]);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<float, float4>(float* to, const float4& from, Index stride) {
+ to[stride*0] = from.x;
+ to[stride*1] = from.y;
+ to[stride*2] = from.z;
+ to[stride*3] = from.w;
+}
+template<> EIGEN_DEVICE_FUNC inline void pscatter<double, double2>(double* to, const double2& from, Index stride) {
+ to[stride*0] = from.x;
+ to[stride*1] = from.y;
+}
+
+template<> EIGEN_DEVICE_FUNC inline float pfirst<float4>(const float4& a) {
+ return a.x;
+}
+template<> EIGEN_DEVICE_FUNC inline double pfirst<double2>(const double2& a) {
+ return a.x;
+}
+
+template<> EIGEN_DEVICE_FUNC inline float predux<float4>(const float4& a) {
+ return a.x + a.y + a.z + a.w;
+}
+template<> EIGEN_DEVICE_FUNC inline double predux<double2>(const double2& a) {
+ return a.x + a.y;
+}
+
+template<> EIGEN_DEVICE_FUNC inline float predux_max<float4>(const float4& a) {
+ return fmaxf(fmaxf(a.x, a.y), fmaxf(a.z, a.w));
+}
+template<> EIGEN_DEVICE_FUNC inline double predux_max<double2>(const double2& a) {
+ return fmax(a.x, a.y);
+}
+
+template<> EIGEN_DEVICE_FUNC inline float predux_min<float4>(const float4& a) {
+ return fminf(fminf(a.x, a.y), fminf(a.z, a.w));
+}
+template<> EIGEN_DEVICE_FUNC inline double predux_min<double2>(const double2& a) {
+ return fmin(a.x, a.y);
+}
+
+template<> EIGEN_DEVICE_FUNC inline float predux_mul<float4>(const float4& a) {
+ return a.x * a.y * a.z * a.w;
+}
+template<> EIGEN_DEVICE_FUNC inline double predux_mul<double2>(const double2& a) {
+ return a.x * a.y;
+}
+
+template<> EIGEN_DEVICE_FUNC inline float4 pabs<float4>(const float4& a) {
+ return make_float4(fabsf(a.x), fabsf(a.y), fabsf(a.z), fabsf(a.w));
+}
+template<> EIGEN_DEVICE_FUNC inline double2 pabs<double2>(const double2& a) {
+ return make_double2(fabs(a.x), fabs(a.y));
+}
+
+template<> EIGEN_DEVICE_FUNC inline float4 pfloor<float4>(const float4& a) {
+ return make_float4(floorf(a.x), floorf(a.y), floorf(a.z), floorf(a.w));
+}
+template<> EIGEN_DEVICE_FUNC inline double2 pfloor<double2>(const double2& a) {
+ return make_double2(floor(a.x), floor(a.y));
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<float4,4>& kernel) {
+ float tmp = kernel.packet[0].y;
+ kernel.packet[0].y = kernel.packet[1].x;
+ kernel.packet[1].x = tmp;
+
+ tmp = kernel.packet[0].z;
+ kernel.packet[0].z = kernel.packet[2].x;
+ kernel.packet[2].x = tmp;
+
+ tmp = kernel.packet[0].w;
+ kernel.packet[0].w = kernel.packet[3].x;
+ kernel.packet[3].x = tmp;
+
+ tmp = kernel.packet[1].z;
+ kernel.packet[1].z = kernel.packet[2].y;
+ kernel.packet[2].y = tmp;
+
+ tmp = kernel.packet[1].w;
+ kernel.packet[1].w = kernel.packet[3].y;
+ kernel.packet[3].y = tmp;
+
+ tmp = kernel.packet[2].w;
+ kernel.packet[2].w = kernel.packet[3].z;
+ kernel.packet[3].z = tmp;
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<double2,2>& kernel) {
+ double tmp = kernel.packet[0].y;
+ kernel.packet[0].y = kernel.packet[1].x;
+ kernel.packet[1].x = tmp;
+}
+
+#endif // defined(EIGEN_GPUCC) && defined(EIGEN_USE_GPU)
+
+// Packet4h2 must be defined in the macro without EIGEN_CUDA_ARCH, meaning
+// its corresponding packet_traits<Eigen::half> must be visible on host.
+#if defined(EIGEN_HAS_CUDA_FP16) || defined(EIGEN_HAS_HIP_FP16)
+
+typedef ulonglong2 Packet4h2;
+template<> struct unpacket_traits<Packet4h2> { typedef Eigen::half type; enum {size=8, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet4h2 half; };
+template<> struct is_arithmetic<Packet4h2> { enum { value = true }; };
+
+template<> struct unpacket_traits<half2> { typedef Eigen::half type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef half2 half; };
+template<> struct is_arithmetic<half2> { enum { value = true }; };
+
+template<> struct packet_traits<Eigen::half> : default_packet_traits
+{
+ typedef Packet4h2 type;
+ typedef Packet4h2 half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size=8,
+ HasHalfPacket = 0,
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasExp = 1,
+ HasExpm1 = 1,
+ HasLog = 1,
+ HasLog1p = 1
+ };
+};
+
+namespace {
+// This is equivalent to make_half2, which is undocumented and doesn't seem to always exist.
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 combine_half(const __half& a, const __half& b) {
+#if defined(EIGEN_GPU_COMPILE_PHASE)
+ return __halves2half2(a, b);
+#else
+ // Round-about way since __halves2half2 is a __device__ function.
+ return __floats2half2_rn(__half2float(a), __half2float(b));
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE __half get_half2_low(const half2& a) {
+#if defined(EIGEN_GPU_COMPILE_PHASE)
+ return __low2half(a);
+#else
+ return __float2half(__low2float(a));
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE __half get_half2_high(const half2& a) {
+#if defined(EIGEN_GPU_COMPILE_PHASE)
+ return __high2half(a);
+#else
+ return __float2half(__high2float(a));
+#endif
+}
+} // namespace
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pset1<half2>(const Eigen::half& from) {
+#if defined(EIGEN_GPU_COMPILE_PHASE)
+ return __half2half2(from);
+#else
+ const float f = __half2float(from);
+ return __floats2half2_rn(f, f);
+#endif
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+pset1<Packet4h2>(const Eigen::half& from) {
+ Packet4h2 r;
+ half2* p_alias = reinterpret_cast<half2*>(&r);
+ p_alias[0] = pset1<half2>(from);
+ p_alias[1] = pset1<half2>(from);
+ p_alias[2] = pset1<half2>(from);
+ p_alias[3] = pset1<half2>(from);
+ return r;
+}
+
+// We now need this visible on both host and device.
+// #if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC)
+namespace {
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pload(const Eigen::half* from) {
+ return *reinterpret_cast<const half2*>(from);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 ploadu(const Eigen::half* from) {
+ return combine_half(from[0], from[1]);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 ploaddup(const Eigen::half* from) {
+ return combine_half(from[0], from[0]);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstore(Eigen::half* to,
+ const half2& from) {
+ *reinterpret_cast<half2*>(to) = from;
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstoreu(Eigen::half* to,
+ const half2& from) {
+ to[0] = get_half2_low(from);
+ to[1] = get_half2_high(from);
+}
+
+
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE half2 ploadt_ro_aligned(
+ const Eigen::half* from) {
+#if defined(EIGEN_GPU_HAS_LDG)
+ // Input is guaranteed to be properly aligned.
+ return __ldg(reinterpret_cast<const half2*>(from));
+#else
+ return combine_half(*(from+0), *(from+1));
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE half2 ploadt_ro_unaligned(
+ const Eigen::half* from) {
+#if defined(EIGEN_GPU_HAS_LDG)
+ return __halves2half2(__ldg(from+0), __ldg(from+1));
+#else
+ return combine_half(*(from+0), *(from+1));
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pgather(const Eigen::half* from,
+ Index stride) {
+ return combine_half(from[0*stride], from[1*stride]);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter(
+ Eigen::half* to, const half2& from, Index stride) {
+ to[stride*0] = get_half2_low(from);
+ to[stride*1] = get_half2_high(from);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half pfirst(const half2& a) {
+ return get_half2_low(a);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pabs(const half2& a) {
+ half a1 = get_half2_low(a);
+ half a2 = get_half2_high(a);
+ half result1 = half_impl::raw_uint16_to_half(a1.x & 0x7FFF);
+ half result2 = half_impl::raw_uint16_to_half(a2.x & 0x7FFF);
+ return combine_half(result1, result2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 ptrue(const half2& /*a*/) {
+ half true_half = half_impl::raw_uint16_to_half(0xffffu);
+ return pset1<half2>(true_half);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pzero(const half2& /*a*/) {
+ half false_half = half_impl::raw_uint16_to_half(0x0000u);
+ return pset1<half2>(false_half);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<half2,2>& kernel) {
+ __half a1 = get_half2_low(kernel.packet[0]);
+ __half a2 = get_half2_high(kernel.packet[0]);
+ __half b1 = get_half2_low(kernel.packet[1]);
+ __half b2 = get_half2_high(kernel.packet[1]);
+ kernel.packet[0] = combine_half(a1, b1);
+ kernel.packet[1] = combine_half(a2, b2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 plset(const Eigen::half& a) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __halves2half2(a, __hadd(a, __float2half(1.0f)));
+#else
+ float f = __half2float(a) + 1.0f;
+ return combine_half(a, __float2half(f));
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pselect(const half2& mask,
+ const half2& a,
+ const half2& b) {
+ half mask_low = get_half2_low(mask);
+ half mask_high = get_half2_high(mask);
+ half result_low = mask_low == half(0) ? get_half2_low(b) : get_half2_low(a);
+ half result_high = mask_high == half(0) ? get_half2_high(b) : get_half2_high(a);
+ return combine_half(result_low, result_high);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcmp_eq(const half2& a,
+ const half2& b) {
+ half true_half = half_impl::raw_uint16_to_half(0xffffu);
+ half false_half = half_impl::raw_uint16_to_half(0x0000u);
+ half a1 = get_half2_low(a);
+ half a2 = get_half2_high(a);
+ half b1 = get_half2_low(b);
+ half b2 = get_half2_high(b);
+ half eq1 = __half2float(a1) == __half2float(b1) ? true_half : false_half;
+ half eq2 = __half2float(a2) == __half2float(b2) ? true_half : false_half;
+ return combine_half(eq1, eq2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcmp_lt(const half2& a,
+ const half2& b) {
+ half true_half = half_impl::raw_uint16_to_half(0xffffu);
+ half false_half = half_impl::raw_uint16_to_half(0x0000u);
+ half a1 = get_half2_low(a);
+ half a2 = get_half2_high(a);
+ half b1 = get_half2_low(b);
+ half b2 = get_half2_high(b);
+ half eq1 = __half2float(a1) < __half2float(b1) ? true_half : false_half;
+ half eq2 = __half2float(a2) < __half2float(b2) ? true_half : false_half;
+ return combine_half(eq1, eq2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pand(const half2& a,
+ const half2& b) {
+ half a1 = get_half2_low(a);
+ half a2 = get_half2_high(a);
+ half b1 = get_half2_low(b);
+ half b2 = get_half2_high(b);
+ half result1 = half_impl::raw_uint16_to_half(a1.x & b1.x);
+ half result2 = half_impl::raw_uint16_to_half(a2.x & b2.x);
+ return combine_half(result1, result2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 por(const half2& a,
+ const half2& b) {
+ half a1 = get_half2_low(a);
+ half a2 = get_half2_high(a);
+ half b1 = get_half2_low(b);
+ half b2 = get_half2_high(b);
+ half result1 = half_impl::raw_uint16_to_half(a1.x | b1.x);
+ half result2 = half_impl::raw_uint16_to_half(a2.x | b2.x);
+ return combine_half(result1, result2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pxor(const half2& a,
+ const half2& b) {
+ half a1 = get_half2_low(a);
+ half a2 = get_half2_high(a);
+ half b1 = get_half2_low(b);
+ half b2 = get_half2_high(b);
+ half result1 = half_impl::raw_uint16_to_half(a1.x ^ b1.x);
+ half result2 = half_impl::raw_uint16_to_half(a2.x ^ b2.x);
+ return combine_half(result1, result2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pandnot(const half2& a,
+ const half2& b) {
+ half a1 = get_half2_low(a);
+ half a2 = get_half2_high(a);
+ half b1 = get_half2_low(b);
+ half b2 = get_half2_high(b);
+ half result1 = half_impl::raw_uint16_to_half(a1.x & ~b1.x);
+ half result2 = half_impl::raw_uint16_to_half(a2.x & ~b2.x);
+ return combine_half(result1, result2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 padd(const half2& a,
+ const half2& b) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __hadd2(a, b);
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ float r1 = a1 + b1;
+ float r2 = a2 + b2;
+ return __floats2half2_rn(r1, r2);
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 psub(const half2& a,
+ const half2& b) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __hsub2(a, b);
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ float r1 = a1 - b1;
+ float r2 = a2 - b2;
+ return __floats2half2_rn(r1, r2);
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pnegate(const half2& a) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __hneg2(a);
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ return __floats2half2_rn(-a1, -a2);
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pconj(const half2& a) { return a; }
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmul(const half2& a,
+ const half2& b) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __hmul2(a, b);
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ float r1 = a1 * b1;
+ float r2 = a2 * b2;
+ return __floats2half2_rn(r1, r2);
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmadd(const half2& a,
+ const half2& b,
+ const half2& c) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __hfma2(a, b, c);
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ float c1 = __low2float(c);
+ float c2 = __high2float(c);
+ float r1 = a1 * b1 + c1;
+ float r2 = a2 * b2 + c2;
+ return __floats2half2_rn(r1, r2);
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pdiv(const half2& a,
+ const half2& b) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __h2div(a, b);
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ float r1 = a1 / b1;
+ float r2 = a2 / b2;
+ return __floats2half2_rn(r1, r2);
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmin(const half2& a,
+ const half2& b) {
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ __half r1 = a1 < b1 ? get_half2_low(a) : get_half2_low(b);
+ __half r2 = a2 < b2 ? get_half2_high(a) : get_half2_high(b);
+ return combine_half(r1, r2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmax(const half2& a,
+ const half2& b) {
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ __half r1 = a1 > b1 ? get_half2_low(a) : get_half2_low(b);
+ __half r2 = a2 > b2 ? get_half2_high(a) : get_half2_high(b);
+ return combine_half(r1, r2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux(const half2& a) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __hadd(__low2half(a), __high2half(a));
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ return Eigen::half(__float2half(a1 + a2));
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_max(const half2& a) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ __half first = __low2half(a);
+ __half second = __high2half(a);
+ return __hgt(first, second) ? first : second;
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ return a1 > a2 ? get_half2_low(a) : get_half2_high(a);
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_min(const half2& a) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ __half first = __low2half(a);
+ __half second = __high2half(a);
+ return __hlt(first, second) ? first : second;
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ return a1 < a2 ? get_half2_low(a) : get_half2_high(a);
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_mul(const half2& a) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __hmul(__low2half(a), __high2half(a));
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ return Eigen::half(__float2half(a1 * a2));
+#endif
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 plog1p(const half2& a) {
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float r1 = log1pf(a1);
+ float r2 = log1pf(a2);
+ return __floats2half2_rn(r1, r2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pexpm1(const half2& a) {
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float r1 = expm1f(a1);
+ float r2 = expm1f(a2);
+ return __floats2half2_rn(r1, r2);
+}
+
+#if (EIGEN_CUDA_SDK_VER >= 80000 && defined(EIGEN_CUDA_HAS_FP16_ARITHMETIC)) || \
+ defined(EIGEN_HIP_DEVICE_COMPILE)
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+half2 plog(const half2& a) {
+ return h2log(a);
+}
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+half2 pexp(const half2& a) {
+ return h2exp(a);
+}
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+half2 psqrt(const half2& a) {
+ return h2sqrt(a);
+}
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+half2 prsqrt(const half2& a) {
+ return h2rsqrt(a);
+}
+
+#else
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 plog(const half2& a) {
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float r1 = logf(a1);
+ float r2 = logf(a2);
+ return __floats2half2_rn(r1, r2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pexp(const half2& a) {
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float r1 = expf(a1);
+ float r2 = expf(a2);
+ return __floats2half2_rn(r1, r2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 psqrt(const half2& a) {
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float r1 = sqrtf(a1);
+ float r2 = sqrtf(a2);
+ return __floats2half2_rn(r1, r2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 prsqrt(const half2& a) {
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float r1 = rsqrtf(a1);
+ float r2 = rsqrtf(a2);
+ return __floats2half2_rn(r1, r2);
+}
+#endif
+} // namespace
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+pload<Packet4h2>(const Eigen::half* from) {
+ return *reinterpret_cast<const Packet4h2*>(from);
+}
+
+// unaligned load;
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+ploadu<Packet4h2>(const Eigen::half* from) {
+ Packet4h2 r;
+ half2* p_alias = reinterpret_cast<half2*>(&r);
+ p_alias[0] = ploadu(from + 0);
+ p_alias[1] = ploadu(from + 2);
+ p_alias[2] = ploadu(from + 4);
+ p_alias[3] = ploadu(from + 6);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+ploaddup<Packet4h2>(const Eigen::half* from) {
+ Packet4h2 r;
+ half2* p_alias = reinterpret_cast<half2*>(&r);
+ p_alias[0] = ploaddup(from + 0);
+ p_alias[1] = ploaddup(from + 1);
+ p_alias[2] = ploaddup(from + 2);
+ p_alias[3] = ploaddup(from + 3);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstore<Eigen::half>(
+ Eigen::half* to, const Packet4h2& from) {
+ *reinterpret_cast<Packet4h2*>(to) = from;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pstoreu<Eigen::half>(
+ Eigen::half* to, const Packet4h2& from) {
+ const half2* from_alias = reinterpret_cast<const half2*>(&from);
+ pstoreu(to + 0,from_alias[0]);
+ pstoreu(to + 2,from_alias[1]);
+ pstoreu(to + 4,from_alias[2]);
+ pstoreu(to + 6,from_alias[3]);
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet4h2
+ploadt_ro<Packet4h2, Aligned>(const Eigen::half* from) {
+#if defined(EIGEN_GPU_HAS_LDG)
+ Packet4h2 r;
+ r = __ldg(reinterpret_cast<const Packet4h2*>(from));
+ return r;
+#else
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ r_alias[0] = ploadt_ro_aligned(from + 0);
+ r_alias[1] = ploadt_ro_aligned(from + 2);
+ r_alias[2] = ploadt_ro_aligned(from + 4);
+ r_alias[3] = ploadt_ro_aligned(from + 6);
+ return r;
+#endif
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet4h2
+ploadt_ro<Packet4h2, Unaligned>(const Eigen::half* from) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ r_alias[0] = ploadt_ro_unaligned(from + 0);
+ r_alias[1] = ploadt_ro_unaligned(from + 2);
+ r_alias[2] = ploadt_ro_unaligned(from + 4);
+ r_alias[3] = ploadt_ro_unaligned(from + 6);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+pgather<Eigen::half, Packet4h2>(const Eigen::half* from, Index stride) {
+ Packet4h2 r;
+ half2* p_alias = reinterpret_cast<half2*>(&r);
+ p_alias[0] = combine_half(from[0 * stride], from[1 * stride]);
+ p_alias[1] = combine_half(from[2 * stride], from[3 * stride]);
+ p_alias[2] = combine_half(from[4 * stride], from[5 * stride]);
+ p_alias[3] = combine_half(from[6 * stride], from[7 * stride]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<Eigen::half, Packet4h2>(
+ Eigen::half* to, const Packet4h2& from, Index stride) {
+ const half2* from_alias = reinterpret_cast<const half2*>(&from);
+ pscatter(to + stride * 0, from_alias[0], stride);
+ pscatter(to + stride * 2, from_alias[1], stride);
+ pscatter(to + stride * 4, from_alias[2], stride);
+ pscatter(to + stride * 6, from_alias[3], stride);
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half pfirst<Packet4h2>(
+ const Packet4h2& a) {
+ return pfirst(*(reinterpret_cast<const half2*>(&a)));
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pabs<Packet4h2>(
+ const Packet4h2& a) {
+ Packet4h2 r;
+ half2* p_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ p_alias[0] = pabs(a_alias[0]);
+ p_alias[1] = pabs(a_alias[1]);
+ p_alias[2] = pabs(a_alias[2]);
+ p_alias[3] = pabs(a_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 ptrue<Packet4h2>(
+ const Packet4h2& /*a*/) {
+ half true_half = half_impl::raw_uint16_to_half(0xffffu);
+ return pset1<Packet4h2>(true_half);
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pzero<Packet4h2>(const Packet4h2& /*a*/) {
+ half false_half = half_impl::raw_uint16_to_half(0x0000u);
+ return pset1<Packet4h2>(false_half);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose_double(
+ double* d_row0, double* d_row1, double* d_row2, double* d_row3,
+ double* d_row4, double* d_row5, double* d_row6, double* d_row7) {
+ double d_tmp;
+ d_tmp = d_row0[1];
+ d_row0[1] = d_row4[0];
+ d_row4[0] = d_tmp;
+
+ d_tmp = d_row1[1];
+ d_row1[1] = d_row5[0];
+ d_row5[0] = d_tmp;
+
+ d_tmp = d_row2[1];
+ d_row2[1] = d_row6[0];
+ d_row6[0] = d_tmp;
+
+ d_tmp = d_row3[1];
+ d_row3[1] = d_row7[0];
+ d_row7[0] = d_tmp;
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose_half2(
+ half2* f_row0, half2* f_row1, half2* f_row2, half2* f_row3) {
+ half2 f_tmp;
+ f_tmp = f_row0[1];
+ f_row0[1] = f_row2[0];
+ f_row2[0] = f_tmp;
+
+ f_tmp = f_row1[1];
+ f_row1[1] = f_row3[0];
+ f_row3[0] = f_tmp;
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void
+ptranspose_half(half2& f0, half2& f1) {
+ __half a1 = get_half2_low(f0);
+ __half a2 = get_half2_high(f0);
+ __half b1 = get_half2_low(f1);
+ __half b2 = get_half2_high(f1);
+ f0 = combine_half(a1, b1);
+ f1 = combine_half(a2, b2);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet4h2,8>& kernel) {
+ double* d_row0 = reinterpret_cast<double*>(&kernel.packet[0]);
+ double* d_row1 = reinterpret_cast<double*>(&kernel.packet[1]);
+ double* d_row2 = reinterpret_cast<double*>(&kernel.packet[2]);
+ double* d_row3 = reinterpret_cast<double*>(&kernel.packet[3]);
+ double* d_row4 = reinterpret_cast<double*>(&kernel.packet[4]);
+ double* d_row5 = reinterpret_cast<double*>(&kernel.packet[5]);
+ double* d_row6 = reinterpret_cast<double*>(&kernel.packet[6]);
+ double* d_row7 = reinterpret_cast<double*>(&kernel.packet[7]);
+ ptranspose_double(d_row0, d_row1, d_row2, d_row3,
+ d_row4, d_row5, d_row6, d_row7);
+
+
+ half2* f_row0 = reinterpret_cast<half2*>(d_row0);
+ half2* f_row1 = reinterpret_cast<half2*>(d_row1);
+ half2* f_row2 = reinterpret_cast<half2*>(d_row2);
+ half2* f_row3 = reinterpret_cast<half2*>(d_row3);
+ ptranspose_half2(f_row0, f_row1, f_row2, f_row3);
+ ptranspose_half(f_row0[0], f_row1[0]);
+ ptranspose_half(f_row0[1], f_row1[1]);
+ ptranspose_half(f_row2[0], f_row3[0]);
+ ptranspose_half(f_row2[1], f_row3[1]);
+
+ f_row0 = reinterpret_cast<half2*>(d_row0 + 1);
+ f_row1 = reinterpret_cast<half2*>(d_row1 + 1);
+ f_row2 = reinterpret_cast<half2*>(d_row2 + 1);
+ f_row3 = reinterpret_cast<half2*>(d_row3 + 1);
+ ptranspose_half2(f_row0, f_row1, f_row2, f_row3);
+ ptranspose_half(f_row0[0], f_row1[0]);
+ ptranspose_half(f_row0[1], f_row1[1]);
+ ptranspose_half(f_row2[0], f_row3[0]);
+ ptranspose_half(f_row2[1], f_row3[1]);
+
+ f_row0 = reinterpret_cast<half2*>(d_row4);
+ f_row1 = reinterpret_cast<half2*>(d_row5);
+ f_row2 = reinterpret_cast<half2*>(d_row6);
+ f_row3 = reinterpret_cast<half2*>(d_row7);
+ ptranspose_half2(f_row0, f_row1, f_row2, f_row3);
+ ptranspose_half(f_row0[0], f_row1[0]);
+ ptranspose_half(f_row0[1], f_row1[1]);
+ ptranspose_half(f_row2[0], f_row3[0]);
+ ptranspose_half(f_row2[1], f_row3[1]);
+
+ f_row0 = reinterpret_cast<half2*>(d_row4 + 1);
+ f_row1 = reinterpret_cast<half2*>(d_row5 + 1);
+ f_row2 = reinterpret_cast<half2*>(d_row6 + 1);
+ f_row3 = reinterpret_cast<half2*>(d_row7 + 1);
+ ptranspose_half2(f_row0, f_row1, f_row2, f_row3);
+ ptranspose_half(f_row0[0], f_row1[0]);
+ ptranspose_half(f_row0[1], f_row1[1]);
+ ptranspose_half(f_row2[0], f_row3[0]);
+ ptranspose_half(f_row2[1], f_row3[1]);
+
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+plset<Packet4h2>(const Eigen::half& a) {
+#if defined(EIGEN_HIP_DEVICE_COMPILE)
+
+ Packet4h2 r;
+ half2* p_alias = reinterpret_cast<half2*>(&r);
+ p_alias[0] = __halves2half2(a, __hadd(a, __float2half(1.0f)));
+ p_alias[1] = __halves2half2(__hadd(a, __float2half(2.0f)),
+ __hadd(a, __float2half(3.0f)));
+ p_alias[2] = __halves2half2(__hadd(a, __float2half(4.0f)),
+ __hadd(a, __float2half(5.0f)));
+ p_alias[3] = __halves2half2(__hadd(a, __float2half(6.0f)),
+ __hadd(a, __float2half(7.0f)));
+ return r;
+#elif defined(EIGEN_CUDA_HAS_FP16_ARITHMETIC)
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+
+ half2 b = pset1<half2>(a);
+ half2 c;
+ half2 half_offset0 = __halves2half2(__float2half(0.0f),__float2half(2.0f));
+ half2 half_offset1 = __halves2half2(__float2half(4.0f),__float2half(6.0f));
+
+ c = __hadd2(b, half_offset0);
+ r_alias[0] = plset(__low2half(c));
+ r_alias[1] = plset(__high2half(c));
+
+ c = __hadd2(b, half_offset1);
+ r_alias[2] = plset(__low2half(c));
+ r_alias[3] = plset(__high2half(c));
+
+ return r;
+
+#else
+ float f = __half2float(a);
+ Packet4h2 r;
+ half2* p_alias = reinterpret_cast<half2*>(&r);
+ p_alias[0] = combine_half(a, __float2half(f + 1.0f));
+ p_alias[1] = combine_half(__float2half(f + 2.0f), __float2half(f + 3.0f));
+ p_alias[2] = combine_half(__float2half(f + 4.0f), __float2half(f + 5.0f));
+ p_alias[3] = combine_half(__float2half(f + 6.0f), __float2half(f + 7.0f));
+ return r;
+#endif
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+pselect<Packet4h2>(const Packet4h2& mask, const Packet4h2& a,
+ const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* mask_alias = reinterpret_cast<const half2*>(&mask);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = pselect(mask_alias[0], a_alias[0], b_alias[0]);
+ r_alias[1] = pselect(mask_alias[1], a_alias[1], b_alias[1]);
+ r_alias[2] = pselect(mask_alias[2], a_alias[2], b_alias[2]);
+ r_alias[3] = pselect(mask_alias[3], a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+pcmp_eq<Packet4h2>(const Packet4h2& a, const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = pcmp_eq(a_alias[0], b_alias[0]);
+ r_alias[1] = pcmp_eq(a_alias[1], b_alias[1]);
+ r_alias[2] = pcmp_eq(a_alias[2], b_alias[2]);
+ r_alias[3] = pcmp_eq(a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pand<Packet4h2>(
+ const Packet4h2& a, const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = pand(a_alias[0], b_alias[0]);
+ r_alias[1] = pand(a_alias[1], b_alias[1]);
+ r_alias[2] = pand(a_alias[2], b_alias[2]);
+ r_alias[3] = pand(a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 por<Packet4h2>(
+ const Packet4h2& a, const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = por(a_alias[0], b_alias[0]);
+ r_alias[1] = por(a_alias[1], b_alias[1]);
+ r_alias[2] = por(a_alias[2], b_alias[2]);
+ r_alias[3] = por(a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pxor<Packet4h2>(
+ const Packet4h2& a, const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = pxor(a_alias[0], b_alias[0]);
+ r_alias[1] = pxor(a_alias[1], b_alias[1]);
+ r_alias[2] = pxor(a_alias[2], b_alias[2]);
+ r_alias[3] = pxor(a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+pandnot<Packet4h2>(const Packet4h2& a, const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = pandnot(a_alias[0], b_alias[0]);
+ r_alias[1] = pandnot(a_alias[1], b_alias[1]);
+ r_alias[2] = pandnot(a_alias[2], b_alias[2]);
+ r_alias[3] = pandnot(a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 padd<Packet4h2>(
+ const Packet4h2& a, const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = padd(a_alias[0], b_alias[0]);
+ r_alias[1] = padd(a_alias[1], b_alias[1]);
+ r_alias[2] = padd(a_alias[2], b_alias[2]);
+ r_alias[3] = padd(a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 psub<Packet4h2>(
+ const Packet4h2& a, const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = psub(a_alias[0], b_alias[0]);
+ r_alias[1] = psub(a_alias[1], b_alias[1]);
+ r_alias[2] = psub(a_alias[2], b_alias[2]);
+ r_alias[3] = psub(a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pnegate(const Packet4h2& a) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ r_alias[0] = pnegate(a_alias[0]);
+ r_alias[1] = pnegate(a_alias[1]);
+ r_alias[2] = pnegate(a_alias[2]);
+ r_alias[3] = pnegate(a_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pconj(const Packet4h2& a) {
+ return a;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pmul<Packet4h2>(
+ const Packet4h2& a, const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = pmul(a_alias[0], b_alias[0]);
+ r_alias[1] = pmul(a_alias[1], b_alias[1]);
+ r_alias[2] = pmul(a_alias[2], b_alias[2]);
+ r_alias[3] = pmul(a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pmadd<Packet4h2>(
+ const Packet4h2& a, const Packet4h2& b, const Packet4h2& c) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ const half2* c_alias = reinterpret_cast<const half2*>(&c);
+ r_alias[0] = pmadd(a_alias[0], b_alias[0], c_alias[0]);
+ r_alias[1] = pmadd(a_alias[1], b_alias[1], c_alias[1]);
+ r_alias[2] = pmadd(a_alias[2], b_alias[2], c_alias[2]);
+ r_alias[3] = pmadd(a_alias[3], b_alias[3], c_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pdiv<Packet4h2>(
+ const Packet4h2& a, const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = pdiv(a_alias[0], b_alias[0]);
+ r_alias[1] = pdiv(a_alias[1], b_alias[1]);
+ r_alias[2] = pdiv(a_alias[2], b_alias[2]);
+ r_alias[3] = pdiv(a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pmin<Packet4h2>(
+ const Packet4h2& a, const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = pmin(a_alias[0], b_alias[0]);
+ r_alias[1] = pmin(a_alias[1], b_alias[1]);
+ r_alias[2] = pmin(a_alias[2], b_alias[2]);
+ r_alias[3] = pmin(a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pmax<Packet4h2>(
+ const Packet4h2& a, const Packet4h2& b) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ const half2* b_alias = reinterpret_cast<const half2*>(&b);
+ r_alias[0] = pmax(a_alias[0], b_alias[0]);
+ r_alias[1] = pmax(a_alias[1], b_alias[1]);
+ r_alias[2] = pmax(a_alias[2], b_alias[2]);
+ r_alias[3] = pmax(a_alias[3], b_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux<Packet4h2>(
+ const Packet4h2& a) {
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+
+ return predux(a_alias[0]) + predux(a_alias[1]) +
+ predux(a_alias[2]) + predux(a_alias[3]);
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_max<Packet4h2>(
+ const Packet4h2& a) {
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ half2 m0 = combine_half(predux_max(a_alias[0]),
+ predux_max(a_alias[1]));
+ half2 m1 = combine_half(predux_max(a_alias[2]),
+ predux_max(a_alias[3]));
+ __half first = predux_max(m0);
+ __half second = predux_max(m1);
+#if defined(EIGEN_CUDA_HAS_FP16_ARITHMETIC)
+ return (__hgt(first, second) ? first : second);
+#else
+ float ffirst = __half2float(first);
+ float fsecond = __half2float(second);
+ return (ffirst > fsecond)? first: second;
+#endif
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_min<Packet4h2>(
+ const Packet4h2& a) {
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ half2 m0 = combine_half(predux_min(a_alias[0]),
+ predux_min(a_alias[1]));
+ half2 m1 = combine_half(predux_min(a_alias[2]),
+ predux_min(a_alias[3]));
+ __half first = predux_min(m0);
+ __half second = predux_min(m1);
+#if defined(EIGEN_CUDA_HAS_FP16_ARITHMETIC)
+ return (__hlt(first, second) ? first : second);
+#else
+ float ffirst = __half2float(first);
+ float fsecond = __half2float(second);
+ return (ffirst < fsecond)? first: second;
+#endif
+}
+
+// likely overflow/underflow
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half predux_mul<Packet4h2>(
+ const Packet4h2& a) {
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ return predux_mul(pmul(pmul(a_alias[0], a_alias[1]),
+ pmul(a_alias[2], a_alias[3])));
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+plog1p<Packet4h2>(const Packet4h2& a) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ r_alias[0] = plog1p(a_alias[0]);
+ r_alias[1] = plog1p(a_alias[1]);
+ r_alias[2] = plog1p(a_alias[2]);
+ r_alias[3] = plog1p(a_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+pexpm1<Packet4h2>(const Packet4h2& a) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ r_alias[0] = pexpm1(a_alias[0]);
+ r_alias[1] = pexpm1(a_alias[1]);
+ r_alias[2] = pexpm1(a_alias[2]);
+ r_alias[3] = pexpm1(a_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 plog<Packet4h2>(const Packet4h2& a) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ r_alias[0] = plog(a_alias[0]);
+ r_alias[1] = plog(a_alias[1]);
+ r_alias[2] = plog(a_alias[2]);
+ r_alias[3] = plog(a_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pexp<Packet4h2>(const Packet4h2& a) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ r_alias[0] = pexp(a_alias[0]);
+ r_alias[1] = pexp(a_alias[1]);
+ r_alias[2] = pexp(a_alias[2]);
+ r_alias[3] = pexp(a_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 psqrt<Packet4h2>(const Packet4h2& a) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ r_alias[0] = psqrt(a_alias[0]);
+ r_alias[1] = psqrt(a_alias[1]);
+ r_alias[2] = psqrt(a_alias[2]);
+ r_alias[3] = psqrt(a_alias[3]);
+ return r;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2
+prsqrt<Packet4h2>(const Packet4h2& a) {
+ Packet4h2 r;
+ half2* r_alias = reinterpret_cast<half2*>(&r);
+ const half2* a_alias = reinterpret_cast<const half2*>(&a);
+ r_alias[0] = prsqrt(a_alias[0]);
+ r_alias[1] = prsqrt(a_alias[1]);
+ r_alias[2] = prsqrt(a_alias[2]);
+ r_alias[3] = prsqrt(a_alias[3]);
+ return r;
+}
+
+// The following specialized padd, pmul, pdiv, pmin, pmax, pset1 are needed for
+// the implementation of GPU half reduction.
+template<>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 padd<half2>(const half2& a,
+ const half2& b) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __hadd2(a, b);
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ float r1 = a1 + b1;
+ float r2 = a2 + b2;
+ return __floats2half2_rn(r1, r2);
+#endif
+}
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmul<half2>(const half2& a,
+ const half2& b) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __hmul2(a, b);
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ float r1 = a1 * b1;
+ float r2 = a2 * b2;
+ return __floats2half2_rn(r1, r2);
+#endif
+}
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pdiv<half2>(const half2& a,
+ const half2& b) {
+#if defined(EIGEN_GPU_HAS_FP16_ARITHMETIC)
+ return __h2div(a, b);
+#else
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ float r1 = a1 / b1;
+ float r2 = a2 / b2;
+ return __floats2half2_rn(r1, r2);
+#endif
+}
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmin<half2>(const half2& a,
+ const half2& b) {
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ __half r1 = a1 < b1 ? get_half2_low(a) : get_half2_low(b);
+ __half r2 = a2 < b2 ? get_half2_high(a) : get_half2_high(b);
+ return combine_half(r1, r2);
+}
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pmax<half2>(const half2& a,
+ const half2& b) {
+ float a1 = __low2float(a);
+ float a2 = __high2float(a);
+ float b1 = __low2float(b);
+ float b2 = __high2float(b);
+ __half r1 = a1 > b1 ? get_half2_low(a) : get_half2_low(b);
+ __half r2 = a2 > b2 ? get_half2_high(a) : get_half2_high(b);
+ return combine_half(r1, r2);
+}
+
+// #endif // defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC)
+
+#endif // defined(EIGEN_HAS_CUDA_FP16) || defined(EIGEN_HAS_HIP_FP16)
+
+#undef EIGEN_GPU_HAS_LDG
+#undef EIGEN_CUDA_HAS_FP16_ARITHMETIC
+#undef EIGEN_GPU_HAS_FP16_ARITHMETIC
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+
+#endif // EIGEN_PACKET_MATH_GPU_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/GPU/TypeCasting.h b/src/3rdparty/eigen/Eigen/src/Core/arch/GPU/TypeCasting.h
new file mode 100644
index 000000000..754546225
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/GPU/TypeCasting.h
@@ -0,0 +1,80 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TYPE_CASTING_GPU_H
+#define EIGEN_TYPE_CASTING_GPU_H
+
+namespace Eigen {
+
+namespace internal {
+
+#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
+ (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
+
+
+template <>
+struct type_casting_traits<Eigen::half, float> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 2
+ };
+};
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcast<half2, float4>(const half2& a, const half2& b) {
+ float2 r1 = __half22float2(a);
+ float2 r2 = __half22float2(b);
+ return make_float4(r1.x, r1.y, r2.x, r2.y);
+}
+
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4h2 pcast<float4, Packet4h2>(const float4& a, const float4& b) {
+ Packet4h2 r;
+ half2* r_alias=reinterpret_cast<half2*>(&r);
+ r_alias[0]=__floats2half2_rn(a.x,a.y);
+ r_alias[1]=__floats2half2_rn(a.z,a.w);
+ r_alias[2]=__floats2half2_rn(b.x,b.y);
+ r_alias[3]=__floats2half2_rn(b.z,b.w);
+ return r;
+}
+
+template <>
+struct type_casting_traits<float, Eigen::half> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 2,
+ TgtCoeffRatio = 1
+ };
+};
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcast<Packet4h2, float4>(const Packet4h2& a) {
+ // Simply discard the second half of the input
+ float4 r;
+ const half2* a_alias=reinterpret_cast<const half2*>(&a);
+ float2 r1 = __half22float2(a_alias[0]);
+ float2 r2 = __half22float2(a_alias[1]);
+ r.x=static_cast<float>(r1.x);
+ r.y=static_cast<float>(r1.y);
+ r.z=static_cast<float>(r2.x);
+ r.w=static_cast<float>(r2.y);
+ return r;
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcast<float4, half2>(const float4& a) {
+ // Simply discard the second half of the input
+ return __floats2half2_rn(a.x, a.y);
+}
+
+#endif
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TYPE_CASTING_GPU_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/HIP/hcc/math_constants.h b/src/3rdparty/eigen/Eigen/src/Core/arch/HIP/hcc/math_constants.h
new file mode 100644
index 000000000..25375a0a4
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/HIP/hcc/math_constants.h
@@ -0,0 +1,23 @@
+/*
+ * math_constants.h -
+ * HIP equivalent of the CUDA header of the same name
+ */
+
+#ifndef __MATH_CONSTANTS_H__
+#define __MATH_CONSTANTS_H__
+
+/* single precision constants */
+
+#define HIPRT_INF_F __int_as_float(0x7f800000)
+#define HIPRT_NAN_F __int_as_float(0x7fffffff)
+#define HIPRT_MIN_DENORM_F __int_as_float(0x00000001)
+#define HIPRT_MAX_NORMAL_F __int_as_float(0x7f7fffff)
+#define HIPRT_NEG_ZERO_F __int_as_float(0x80000000)
+#define HIPRT_ZERO_F 0.0f
+#define HIPRT_ONE_F 1.0f
+
+/* double precision constants */
+#define HIPRT_INF __hiloint2double(0x7ff00000, 0x00000000)
+#define HIPRT_NAN __hiloint2double(0xfff80000, 0x00000000)
+
+#endif
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/MSA/Complex.h b/src/3rdparty/eigen/Eigen/src/Core/arch/MSA/Complex.h
new file mode 100644
index 000000000..53dacfa43
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/MSA/Complex.h
@@ -0,0 +1,648 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2018 Wave Computing, Inc.
+// Written by:
+// Chris Larsen
+// Alexey Frunze (afrunze@wavecomp.com)
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMPLEX_MSA_H
+#define EIGEN_COMPLEX_MSA_H
+
+#include <iostream>
+
+namespace Eigen {
+
+namespace internal {
+
+//---------- float ----------
+struct Packet2cf {
+ EIGEN_STRONG_INLINE Packet2cf() {
+ }
+ EIGEN_STRONG_INLINE explicit Packet2cf(const std::complex<float>& a,
+ const std::complex<float>& b) {
+ Packet4f t = { std::real(a), std::imag(a), std::real(b), std::imag(b) };
+ v = t;
+ }
+ EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {
+ }
+ EIGEN_STRONG_INLINE Packet2cf(const Packet2cf& a) : v(a.v) {
+ }
+ EIGEN_STRONG_INLINE Packet2cf& operator=(const Packet2cf& b) {
+ v = b.v;
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet2cf conjugate(void) const {
+ return Packet2cf((Packet4f)__builtin_msa_bnegi_d((v2u64)v, 63));
+ }
+ EIGEN_STRONG_INLINE Packet2cf& operator*=(const Packet2cf& b) {
+ Packet4f v1, v2;
+
+ // Get the real values of a | a1_re | a1_re | a2_re | a2_re |
+ v1 = (Packet4f)__builtin_msa_ilvev_w((v4i32)v, (v4i32)v);
+ // Get the imag values of a | a1_im | a1_im | a2_im | a2_im |
+ v2 = (Packet4f)__builtin_msa_ilvod_w((v4i32)v, (v4i32)v);
+ // Multiply the real a with b
+ v1 = pmul(v1, b.v);
+ // Multiply the imag a with b
+ v2 = pmul(v2, b.v);
+ // Conjugate v2
+ v2 = Packet2cf(v2).conjugate().v;
+ // Swap real/imag elements in v2.
+ v2 = (Packet4f)__builtin_msa_shf_w((v4i32)v2, EIGEN_MSA_SHF_I8(1, 0, 3, 2));
+ // Add and return the result
+ v = padd(v1, v2);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet2cf operator*(const Packet2cf& b) const {
+ return Packet2cf(*this) *= b;
+ }
+ EIGEN_STRONG_INLINE Packet2cf& operator+=(const Packet2cf& b) {
+ v = padd(v, b.v);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet2cf operator+(const Packet2cf& b) const {
+ return Packet2cf(*this) += b;
+ }
+ EIGEN_STRONG_INLINE Packet2cf& operator-=(const Packet2cf& b) {
+ v = psub(v, b.v);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet2cf operator-(const Packet2cf& b) const {
+ return Packet2cf(*this) -= b;
+ }
+ EIGEN_STRONG_INLINE Packet2cf& operator/=(const Packet2cf& b) {
+ *this *= b.conjugate();
+ Packet4f s = pmul<Packet4f>(b.v, b.v);
+ s = padd(s, (Packet4f)__builtin_msa_shf_w((v4i32)s, EIGEN_MSA_SHF_I8(1, 0, 3, 2)));
+ v = pdiv(v, s);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet2cf operator/(const Packet2cf& b) const {
+ return Packet2cf(*this) /= b;
+ }
+ EIGEN_STRONG_INLINE Packet2cf operator-(void) const {
+ return Packet2cf(pnegate(v));
+ }
+
+ Packet4f v;
+};
+
+inline std::ostream& operator<<(std::ostream& os, const Packet2cf& value) {
+ os << "[ (" << value.v[0] << ", " << value.v[1]
+ << "i),"
+ " ("
+ << value.v[2] << ", " << value.v[3] << "i) ]";
+ return os;
+}
+
+template <>
+struct packet_traits<std::complex<float> > : default_packet_traits {
+ typedef Packet2cf type;
+ typedef Packet2cf half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 2,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0,
+ HasBlend = 1
+ };
+};
+
+template <>
+struct unpacket_traits<Packet2cf> {
+ typedef std::complex<float> type;
+ enum { size = 2, alignment = Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false };
+ typedef Packet2cf half;
+};
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from) {
+ EIGEN_MSA_DEBUG;
+
+ float f0 = from.real(), f1 = from.imag();
+ Packet4f v0 = { f0, f0, f0, f0 };
+ Packet4f v1 = { f1, f1, f1, f1 };
+ return Packet2cf((Packet4f)__builtin_msa_ilvr_w((Packet4i)v1, (Packet4i)v0));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
+ EIGEN_MSA_DEBUG;
+
+ return a + b;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
+ EIGEN_MSA_DEBUG;
+
+ return a - b;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) {
+ EIGEN_MSA_DEBUG;
+
+ return -a;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) {
+ EIGEN_MSA_DEBUG;
+
+ return a.conjugate();
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
+ EIGEN_MSA_DEBUG;
+
+ return a * b;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf pand<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet2cf(pand(a.v, b.v));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf por<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet2cf(por(a.v, b.v));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf pxor<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet2cf(pxor(a.v, b.v));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet2cf(pandnot(a.v, b.v));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(const std::complex<float>* from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>((const float*)from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>((const float*)from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) {
+ EIGEN_MSA_DEBUG;
+
+ return pset1<Packet2cf>(*from);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstore<std::complex<float> >(std::complex<float>* to,
+ const Packet2cf& from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_ALIGNED_STORE pstore<float>((float*)to, from.v);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float>* to,
+ const Packet2cf& from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_UNALIGNED_STORE pstoreu<float>((float*)to, from.v);
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>(
+ const std::complex<float>* from, Index stride) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet2cf(from[0 * stride], from[1 * stride]);
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to,
+ const Packet2cf& from,
+ Index stride) {
+ EIGEN_MSA_DEBUG;
+
+ *to = std::complex<float>(from.v[0], from.v[1]);
+ to += stride;
+ *to = std::complex<float>(from.v[2], from.v[3]);
+}
+
+template <>
+EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float>* addr) {
+ EIGEN_MSA_DEBUG;
+
+ prefetch(reinterpret_cast<const float*>(addr));
+}
+
+template <>
+EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a) {
+ EIGEN_MSA_DEBUG;
+
+ return std::complex<float>(a.v[0], a.v[1]);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet2cf((Packet4f)__builtin_msa_shf_w((v4i32)a.v, EIGEN_MSA_SHF_I8(2, 3, 0, 1)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& a) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet2cf((Packet4f)__builtin_msa_shf_w((v4i32)a.v, EIGEN_MSA_SHF_I8(1, 0, 3, 2)));
+}
+
+template <>
+EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a) {
+ EIGEN_MSA_DEBUG;
+
+ Packet4f value = (Packet4f)preverse((Packet2d)a.v);
+ value += a.v;
+ return std::complex<float>(value[0], value[1]);
+}
+
+template <>
+EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a) {
+ EIGEN_MSA_DEBUG;
+
+ return std::complex<float>((a.v[0] * a.v[2]) - (a.v[1] * a.v[3]),
+ (a.v[0] * a.v[3]) + (a.v[1] * a.v[2]));
+}
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf, Packet4f)
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b) {
+ EIGEN_MSA_DEBUG;
+
+ return a / b;
+}
+
+inline std::ostream& operator<<(std::ostream& os, const PacketBlock<Packet2cf, 2>& value) {
+ os << "[ " << value.packet[0] << ", " << std::endl << " " << value.packet[1] << " ]";
+ return os;
+}
+
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet2cf, 2>& kernel) {
+ EIGEN_MSA_DEBUG;
+
+ Packet4f tmp =
+ (Packet4f)__builtin_msa_ilvl_d((v2i64)kernel.packet[1].v, (v2i64)kernel.packet[0].v);
+ kernel.packet[0].v =
+ (Packet4f)__builtin_msa_ilvr_d((v2i64)kernel.packet[1].v, (v2i64)kernel.packet[0].v);
+ kernel.packet[1].v = tmp;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket,
+ const Packet2cf& elsePacket) {
+ return (Packet2cf)(Packet4f)pblend<Packet2d>(ifPacket, (Packet2d)thenPacket.v,
+ (Packet2d)elsePacket.v);
+}
+
+//---------- double ----------
+
+struct Packet1cd {
+ EIGEN_STRONG_INLINE Packet1cd() {
+ }
+ EIGEN_STRONG_INLINE explicit Packet1cd(const std::complex<double>& a) {
+ v[0] = std::real(a);
+ v[1] = std::imag(a);
+ }
+ EIGEN_STRONG_INLINE explicit Packet1cd(const Packet2d& a) : v(a) {
+ }
+ EIGEN_STRONG_INLINE Packet1cd(const Packet1cd& a) : v(a.v) {
+ }
+ EIGEN_STRONG_INLINE Packet1cd& operator=(const Packet1cd& b) {
+ v = b.v;
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet1cd conjugate(void) const {
+ static const v2u64 p2ul_CONJ_XOR = { 0x0, 0x8000000000000000 };
+ return (Packet1cd)pxor(v, (Packet2d)p2ul_CONJ_XOR);
+ }
+ EIGEN_STRONG_INLINE Packet1cd& operator*=(const Packet1cd& b) {
+ Packet2d v1, v2;
+
+ // Get the real values of a | a1_re | a1_re
+ v1 = (Packet2d)__builtin_msa_ilvev_d((v2i64)v, (v2i64)v);
+ // Get the imag values of a | a1_im | a1_im
+ v2 = (Packet2d)__builtin_msa_ilvod_d((v2i64)v, (v2i64)v);
+ // Multiply the real a with b
+ v1 = pmul(v1, b.v);
+ // Multiply the imag a with b
+ v2 = pmul(v2, b.v);
+ // Conjugate v2
+ v2 = Packet1cd(v2).conjugate().v;
+ // Swap real/imag elements in v2.
+ v2 = (Packet2d)__builtin_msa_shf_w((v4i32)v2, EIGEN_MSA_SHF_I8(2, 3, 0, 1));
+ // Add and return the result
+ v = padd(v1, v2);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet1cd operator*(const Packet1cd& b) const {
+ return Packet1cd(*this) *= b;
+ }
+ EIGEN_STRONG_INLINE Packet1cd& operator+=(const Packet1cd& b) {
+ v = padd(v, b.v);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet1cd operator+(const Packet1cd& b) const {
+ return Packet1cd(*this) += b;
+ }
+ EIGEN_STRONG_INLINE Packet1cd& operator-=(const Packet1cd& b) {
+ v = psub(v, b.v);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet1cd operator-(const Packet1cd& b) const {
+ return Packet1cd(*this) -= b;
+ }
+ EIGEN_STRONG_INLINE Packet1cd& operator/=(const Packet1cd& b) {
+ *this *= b.conjugate();
+ Packet2d s = pmul<Packet2d>(b.v, b.v);
+ s = padd(s, preverse<Packet2d>(s));
+ v = pdiv(v, s);
+ return *this;
+ }
+ EIGEN_STRONG_INLINE Packet1cd operator/(const Packet1cd& b) const {
+ return Packet1cd(*this) /= b;
+ }
+ EIGEN_STRONG_INLINE Packet1cd operator-(void) const {
+ return Packet1cd(pnegate(v));
+ }
+
+ Packet2d v;
+};
+
+inline std::ostream& operator<<(std::ostream& os, const Packet1cd& value) {
+ os << "[ (" << value.v[0] << ", " << value.v[1] << "i) ]";
+ return os;
+}
+
+template <>
+struct packet_traits<std::complex<double> > : default_packet_traits {
+ typedef Packet1cd type;
+ typedef Packet1cd half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 0,
+ size = 1,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0
+ };
+};
+
+template <>
+struct unpacket_traits<Packet1cd> {
+ typedef std::complex<double> type;
+ enum { size = 1, alignment = Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false };
+ typedef Packet1cd half;
+};
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd pload<Packet1cd>(const std::complex<double>* from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>((const double*)from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>((const double*)from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet1cd(from);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
+ EIGEN_MSA_DEBUG;
+
+ return a + b;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
+ EIGEN_MSA_DEBUG;
+
+ return a - b;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) {
+ EIGEN_MSA_DEBUG;
+
+ return -a;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a) {
+ EIGEN_MSA_DEBUG;
+
+ return a.conjugate();
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
+ EIGEN_MSA_DEBUG;
+
+ return a * b;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd pand<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet1cd(pand(a.v, b.v));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd por<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet1cd(por(a.v, b.v));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd pxor<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet1cd(pxor(a.v, b.v));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet1cd(pandnot(a.v, b.v));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) {
+ EIGEN_MSA_DEBUG;
+
+ return pset1<Packet1cd>(*from);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstore<std::complex<double> >(std::complex<double>* to,
+ const Packet1cd& from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_ALIGNED_STORE pstore<double>((double*)to, from.v);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double>* to,
+ const Packet1cd& from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_UNALIGNED_STORE pstoreu<double>((double*)to, from.v);
+}
+
+template <>
+EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double>* addr) {
+ EIGEN_MSA_DEBUG;
+
+ prefetch(reinterpret_cast<const double*>(addr));
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline Packet1cd pgather<std::complex<double>, Packet1cd>(
+ const std::complex<double>* from, Index stride __attribute__((unused))) {
+ EIGEN_MSA_DEBUG;
+
+ Packet1cd res;
+ res.v[0] = std::real(from[0]);
+ res.v[1] = std::imag(from[0]);
+ return res;
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to,
+ const Packet1cd& from,
+ Index stride
+ __attribute__((unused))) {
+ EIGEN_MSA_DEBUG;
+
+ pstore(to, from);
+}
+
+template <>
+EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a) {
+ EIGEN_MSA_DEBUG;
+
+ return std::complex<double>(a.v[0], a.v[1]);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) {
+ EIGEN_MSA_DEBUG;
+
+ return a;
+}
+
+template <>
+EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a) {
+ EIGEN_MSA_DEBUG;
+
+ return pfirst(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a) {
+ EIGEN_MSA_DEBUG;
+
+ return pfirst(a);
+}
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd, Packet2d)
+
+template <>
+EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b) {
+ EIGEN_MSA_DEBUG;
+
+ return a / b;
+}
+
+EIGEN_STRONG_INLINE Packet1cd pcplxflip /*<Packet1cd>*/ (const Packet1cd& x) {
+ EIGEN_MSA_DEBUG;
+
+ return Packet1cd(preverse(Packet2d(x.v)));
+}
+
+inline std::ostream& operator<<(std::ostream& os, const PacketBlock<Packet1cd, 2>& value) {
+ os << "[ " << value.packet[0] << ", " << std::endl << " " << value.packet[1] << " ]";
+ return os;
+}
+
+EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet1cd, 2>& kernel) {
+ EIGEN_MSA_DEBUG;
+
+ Packet2d v1, v2;
+
+ v1 = (Packet2d)__builtin_msa_ilvev_d((v2i64)kernel.packet[0].v, (v2i64)kernel.packet[1].v);
+ // Get the imag values of a
+ v2 = (Packet2d)__builtin_msa_ilvod_d((v2i64)kernel.packet[0].v, (v2i64)kernel.packet[1].v);
+
+ kernel.packet[0].v = v1;
+ kernel.packet[1].v = v2;
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_COMPLEX_MSA_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/MSA/MathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/arch/MSA/MathFunctions.h
new file mode 100644
index 000000000..f5181b90e
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/MSA/MathFunctions.h
@@ -0,0 +1,387 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2007 Julien Pommier
+// Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com)
+// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// Copyright (C) 2018 Wave Computing, Inc.
+// Written by:
+// Chris Larsen
+// Alexey Frunze (afrunze@wavecomp.com)
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/* The sin, cos, exp, and log functions of this file come from
+ * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/
+ */
+
+/* The tanh function of this file is an adaptation of
+ * template<typename T> T generic_fast_tanh_float(const T&)
+ * from MathFunctionsImpl.h.
+ */
+
+#ifndef EIGEN_MATH_FUNCTIONS_MSA_H
+#define EIGEN_MATH_FUNCTIONS_MSA_H
+
+namespace Eigen {
+
+namespace internal {
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f
+plog<Packet4f>(const Packet4f& _x) {
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_SQRTHF, 0.707106781186547524f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p0, 7.0376836292e-2f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p1, -1.1514610310e-1f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p2, 1.1676998740e-1f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p3, -1.2420140846e-1f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p4, +1.4249322787e-1f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p5, -1.6668057665e-1f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p6, +2.0000714765e-1f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p7, -2.4999993993e-1f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p8, +3.3333331174e-1f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_q1, -2.12194440e-4f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_q2, 0.693359375f);
+ static _EIGEN_DECLARE_CONST_Packet4f(half, 0.5f);
+ static _EIGEN_DECLARE_CONST_Packet4f(1, 1.0f);
+
+ // Convert negative argument into NAN (quiet negative, to be specific).
+ Packet4f zero = (Packet4f)__builtin_msa_ldi_w(0);
+ Packet4i neg_mask = __builtin_msa_fclt_w(_x, zero);
+ Packet4i zero_mask = __builtin_msa_fceq_w(_x, zero);
+ Packet4f non_neg_x_or_nan = padd(_x, (Packet4f)neg_mask); // Add 0.0 or NAN.
+ Packet4f x = non_neg_x_or_nan;
+
+ // Extract exponent from x = mantissa * 2**exponent, where 1.0 <= mantissa < 2.0.
+ // N.B. the exponent is one less of what frexpf() would return.
+ Packet4i e_int = __builtin_msa_ftint_s_w(__builtin_msa_flog2_w(x));
+ // Multiply x by 2**(-exponent-1) to get 0.5 <= x < 1.0 as from frexpf().
+ x = __builtin_msa_fexp2_w(x, (Packet4i)__builtin_msa_nori_b((v16u8)e_int, 0));
+
+ /*
+ if (x < SQRTHF) {
+ x = x + x - 1.0;
+ } else {
+ e += 1;
+ x = x - 1.0;
+ }
+ */
+ Packet4f xx = padd(x, x);
+ Packet4i ge_mask = __builtin_msa_fcle_w(p4f_cephes_SQRTHF, x);
+ e_int = psub(e_int, ge_mask);
+ x = (Packet4f)__builtin_msa_bsel_v((v16u8)ge_mask, (v16u8)xx, (v16u8)x);
+ x = psub(x, p4f_1);
+ Packet4f e = __builtin_msa_ffint_s_w(e_int);
+
+ Packet4f x2 = pmul(x, x);
+ Packet4f x3 = pmul(x2, x);
+
+ Packet4f y, y1, y2;
+ y = pmadd(p4f_cephes_log_p0, x, p4f_cephes_log_p1);
+ y1 = pmadd(p4f_cephes_log_p3, x, p4f_cephes_log_p4);
+ y2 = pmadd(p4f_cephes_log_p6, x, p4f_cephes_log_p7);
+ y = pmadd(y, x, p4f_cephes_log_p2);
+ y1 = pmadd(y1, x, p4f_cephes_log_p5);
+ y2 = pmadd(y2, x, p4f_cephes_log_p8);
+ y = pmadd(y, x3, y1);
+ y = pmadd(y, x3, y2);
+ y = pmul(y, x3);
+
+ y = pmadd(e, p4f_cephes_log_q1, y);
+ x = __builtin_msa_fmsub_w(x, x2, p4f_half);
+ x = padd(x, y);
+ x = pmadd(e, p4f_cephes_log_q2, x);
+
+ // x is now the logarithm result candidate. We still need to handle the
+ // extreme arguments of zero and positive infinity, though.
+ // N.B. if the argument is +INFINITY, x is NAN because the polynomial terms
+ // contain infinities of both signs (see the coefficients and code above).
+ // INFINITY - INFINITY is NAN.
+
+ // If the argument is +INFINITY, make it the new result candidate.
+ // To achieve that we choose the smaller of the result candidate and the
+ // argument.
+ // This is correct for all finite pairs of values (the logarithm is smaller
+ // than the argument).
+ // This is also correct in the special case when the argument is +INFINITY
+ // and the result candidate is NAN. This is because the fmin.df instruction
+ // prefers non-NANs to NANs.
+ x = __builtin_msa_fmin_w(x, non_neg_x_or_nan);
+
+ // If the argument is zero (including -0.0), the result becomes -INFINITY.
+ Packet4i neg_infs = __builtin_msa_slli_w(zero_mask, 23);
+ x = (Packet4f)__builtin_msa_bsel_v((v16u8)zero_mask, (v16u8)x, (v16u8)neg_infs);
+
+ return x;
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f
+pexp<Packet4f>(const Packet4f& _x) {
+ // Limiting single-precision pexp's argument to [-128, +128] lets pexp
+ // reach 0 and INFINITY naturally.
+ static _EIGEN_DECLARE_CONST_Packet4f(exp_lo, -128.0f);
+ static _EIGEN_DECLARE_CONST_Packet4f(exp_hi, +128.0f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_LOG2EF, 1.44269504088896341f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_C1, 0.693359375f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_C2, -2.12194440e-4f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p0, 1.9875691500e-4f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p1, 1.3981999507e-3f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p2, 8.3334519073e-3f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p3, 4.1665795894e-2f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p4, 1.6666665459e-1f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p5, 5.0000001201e-1f);
+ static _EIGEN_DECLARE_CONST_Packet4f(half, 0.5f);
+ static _EIGEN_DECLARE_CONST_Packet4f(1, 1.0f);
+
+ Packet4f x = _x;
+
+ // Clamp x.
+ x = (Packet4f)__builtin_msa_bsel_v((v16u8)__builtin_msa_fclt_w(x, p4f_exp_lo), (v16u8)x,
+ (v16u8)p4f_exp_lo);
+ x = (Packet4f)__builtin_msa_bsel_v((v16u8)__builtin_msa_fclt_w(p4f_exp_hi, x), (v16u8)x,
+ (v16u8)p4f_exp_hi);
+
+ // Round to nearest integer by adding 0.5 (with x's sign) and truncating.
+ Packet4f x2_add = (Packet4f)__builtin_msa_binsli_w((v4u32)p4f_half, (v4u32)x, 0);
+ Packet4f x2 = pmadd(x, p4f_cephes_LOG2EF, x2_add);
+ Packet4i x2_int = __builtin_msa_ftrunc_s_w(x2);
+ Packet4f x2_int_f = __builtin_msa_ffint_s_w(x2_int);
+
+ x = __builtin_msa_fmsub_w(x, x2_int_f, p4f_cephes_exp_C1);
+ x = __builtin_msa_fmsub_w(x, x2_int_f, p4f_cephes_exp_C2);
+
+ Packet4f z = pmul(x, x);
+
+ Packet4f y = p4f_cephes_exp_p0;
+ y = pmadd(y, x, p4f_cephes_exp_p1);
+ y = pmadd(y, x, p4f_cephes_exp_p2);
+ y = pmadd(y, x, p4f_cephes_exp_p3);
+ y = pmadd(y, x, p4f_cephes_exp_p4);
+ y = pmadd(y, x, p4f_cephes_exp_p5);
+ y = pmadd(y, z, x);
+ y = padd(y, p4f_1);
+
+ // y *= 2**exponent.
+ y = __builtin_msa_fexp2_w(y, x2_int);
+
+ return y;
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f
+ptanh<Packet4f>(const Packet4f& _x) {
+ static _EIGEN_DECLARE_CONST_Packet4f(tanh_tiny, 1e-4f);
+ static _EIGEN_DECLARE_CONST_Packet4f(tanh_hi, 9.0f);
+ // The monomial coefficients of the numerator polynomial (odd).
+ static _EIGEN_DECLARE_CONST_Packet4f(alpha_1, 4.89352455891786e-3f);
+ static _EIGEN_DECLARE_CONST_Packet4f(alpha_3, 6.37261928875436e-4f);
+ static _EIGEN_DECLARE_CONST_Packet4f(alpha_5, 1.48572235717979e-5f);
+ static _EIGEN_DECLARE_CONST_Packet4f(alpha_7, 5.12229709037114e-8f);
+ static _EIGEN_DECLARE_CONST_Packet4f(alpha_9, -8.60467152213735e-11f);
+ static _EIGEN_DECLARE_CONST_Packet4f(alpha_11, 2.00018790482477e-13f);
+ static _EIGEN_DECLARE_CONST_Packet4f(alpha_13, -2.76076847742355e-16f);
+ // The monomial coefficients of the denominator polynomial (even).
+ static _EIGEN_DECLARE_CONST_Packet4f(beta_0, 4.89352518554385e-3f);
+ static _EIGEN_DECLARE_CONST_Packet4f(beta_2, 2.26843463243900e-3f);
+ static _EIGEN_DECLARE_CONST_Packet4f(beta_4, 1.18534705686654e-4f);
+ static _EIGEN_DECLARE_CONST_Packet4f(beta_6, 1.19825839466702e-6f);
+
+ Packet4f x = pabs(_x);
+ Packet4i tiny_mask = __builtin_msa_fclt_w(x, p4f_tanh_tiny);
+
+ // Clamp the inputs to the range [-9, 9] since anything outside
+ // this range is -/+1.0f in single-precision.
+ x = (Packet4f)__builtin_msa_bsel_v((v16u8)__builtin_msa_fclt_w(p4f_tanh_hi, x), (v16u8)x,
+ (v16u8)p4f_tanh_hi);
+
+ // Since the polynomials are odd/even, we need x**2.
+ Packet4f x2 = pmul(x, x);
+
+ // Evaluate the numerator polynomial p.
+ Packet4f p = pmadd(x2, p4f_alpha_13, p4f_alpha_11);
+ p = pmadd(x2, p, p4f_alpha_9);
+ p = pmadd(x2, p, p4f_alpha_7);
+ p = pmadd(x2, p, p4f_alpha_5);
+ p = pmadd(x2, p, p4f_alpha_3);
+ p = pmadd(x2, p, p4f_alpha_1);
+ p = pmul(x, p);
+
+ // Evaluate the denominator polynomial q.
+ Packet4f q = pmadd(x2, p4f_beta_6, p4f_beta_4);
+ q = pmadd(x2, q, p4f_beta_2);
+ q = pmadd(x2, q, p4f_beta_0);
+
+ // Divide the numerator by the denominator.
+ p = pdiv(p, q);
+
+ // Reinstate the sign.
+ p = (Packet4f)__builtin_msa_binsli_w((v4u32)p, (v4u32)_x, 0);
+
+ // When the argument is very small in magnitude it's more accurate to just return it.
+ p = (Packet4f)__builtin_msa_bsel_v((v16u8)tiny_mask, (v16u8)p, (v16u8)_x);
+
+ return p;
+}
+
+template <bool sine>
+Packet4f psincos_inner_msa_float(const Packet4f& _x) {
+ static _EIGEN_DECLARE_CONST_Packet4f(sincos_max_arg, 13176795.0f); // Approx. (2**24) / (4/Pi).
+ static _EIGEN_DECLARE_CONST_Packet4f(minus_cephes_DP1, -0.78515625f);
+ static _EIGEN_DECLARE_CONST_Packet4f(minus_cephes_DP2, -2.4187564849853515625e-4f);
+ static _EIGEN_DECLARE_CONST_Packet4f(minus_cephes_DP3, -3.77489497744594108e-8f);
+ static _EIGEN_DECLARE_CONST_Packet4f(sincof_p0, -1.9515295891e-4f);
+ static _EIGEN_DECLARE_CONST_Packet4f(sincof_p1, 8.3321608736e-3f);
+ static _EIGEN_DECLARE_CONST_Packet4f(sincof_p2, -1.6666654611e-1f);
+ static _EIGEN_DECLARE_CONST_Packet4f(coscof_p0, 2.443315711809948e-5f);
+ static _EIGEN_DECLARE_CONST_Packet4f(coscof_p1, -1.388731625493765e-3f);
+ static _EIGEN_DECLARE_CONST_Packet4f(coscof_p2, 4.166664568298827e-2f);
+ static _EIGEN_DECLARE_CONST_Packet4f(cephes_FOPI, 1.27323954473516f); // 4/Pi.
+ static _EIGEN_DECLARE_CONST_Packet4f(half, 0.5f);
+ static _EIGEN_DECLARE_CONST_Packet4f(1, 1.0f);
+
+ Packet4f x = pabs(_x);
+
+ // Translate infinite arguments into NANs.
+ Packet4f zero_or_nan_if_inf = psub(_x, _x);
+ x = padd(x, zero_or_nan_if_inf);
+ // Prevent sin/cos from generating values larger than 1.0 in magnitude
+ // for very large arguments by setting x to 0.0.
+ Packet4i small_or_nan_mask = __builtin_msa_fcult_w(x, p4f_sincos_max_arg);
+ x = pand(x, (Packet4f)small_or_nan_mask);
+
+ // Scale x by 4/Pi to find x's octant.
+ Packet4f y = pmul(x, p4f_cephes_FOPI);
+ // Get the octant. We'll reduce x by this number of octants or by one more than it.
+ Packet4i y_int = __builtin_msa_ftrunc_s_w(y);
+ // x's from even-numbered octants will translate to octant 0: [0, +Pi/4].
+ // x's from odd-numbered octants will translate to octant -1: [-Pi/4, 0].
+ // Adjustment for odd-numbered octants: octant = (octant + 1) & (~1).
+ Packet4i y_int1 = __builtin_msa_addvi_w(y_int, 1);
+ Packet4i y_int2 = (Packet4i)__builtin_msa_bclri_w((Packet4ui)y_int1, 0); // bclri = bit-clear
+ y = __builtin_msa_ffint_s_w(y_int2);
+
+ // Compute the sign to apply to the polynomial.
+ Packet4i sign_mask = sine ? pxor(__builtin_msa_slli_w(y_int1, 29), (Packet4i)_x)
+ : __builtin_msa_slli_w(__builtin_msa_addvi_w(y_int, 3), 29);
+
+ // Get the polynomial selection mask.
+ // We'll calculate both (sin and cos) polynomials and then select from the two.
+ Packet4i poly_mask = __builtin_msa_ceqi_w(__builtin_msa_slli_w(y_int2, 30), 0);
+
+ // Reduce x by y octants to get: -Pi/4 <= x <= +Pi/4.
+ // The magic pass: "Extended precision modular arithmetic"
+ // x = ((x - y * DP1) - y * DP2) - y * DP3
+ Packet4f tmp1 = pmul(y, p4f_minus_cephes_DP1);
+ Packet4f tmp2 = pmul(y, p4f_minus_cephes_DP2);
+ Packet4f tmp3 = pmul(y, p4f_minus_cephes_DP3);
+ x = padd(x, tmp1);
+ x = padd(x, tmp2);
+ x = padd(x, tmp3);
+
+ // Evaluate the cos(x) polynomial.
+ y = p4f_coscof_p0;
+ Packet4f z = pmul(x, x);
+ y = pmadd(y, z, p4f_coscof_p1);
+ y = pmadd(y, z, p4f_coscof_p2);
+ y = pmul(y, z);
+ y = pmul(y, z);
+ y = __builtin_msa_fmsub_w(y, z, p4f_half);
+ y = padd(y, p4f_1);
+
+ // Evaluate the sin(x) polynomial.
+ Packet4f y2 = p4f_sincof_p0;
+ y2 = pmadd(y2, z, p4f_sincof_p1);
+ y2 = pmadd(y2, z, p4f_sincof_p2);
+ y2 = pmul(y2, z);
+ y2 = pmadd(y2, x, x);
+
+ // Select the correct result from the two polynomials.
+ y = sine ? (Packet4f)__builtin_msa_bsel_v((v16u8)poly_mask, (v16u8)y, (v16u8)y2)
+ : (Packet4f)__builtin_msa_bsel_v((v16u8)poly_mask, (v16u8)y2, (v16u8)y);
+
+ // Update the sign.
+ sign_mask = pxor(sign_mask, (Packet4i)y);
+ y = (Packet4f)__builtin_msa_binsli_w((v4u32)y, (v4u32)sign_mask, 0); // binsli = bit-insert-left
+ return y;
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f
+psin<Packet4f>(const Packet4f& x) {
+ return psincos_inner_msa_float</* sine */ true>(x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f
+pcos<Packet4f>(const Packet4f& x) {
+ return psincos_inner_msa_float</* sine */ false>(x);
+}
+
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet2d
+pexp<Packet2d>(const Packet2d& _x) {
+ // Limiting double-precision pexp's argument to [-1024, +1024] lets pexp
+ // reach 0 and INFINITY naturally.
+ static _EIGEN_DECLARE_CONST_Packet2d(exp_lo, -1024.0);
+ static _EIGEN_DECLARE_CONST_Packet2d(exp_hi, +1024.0);
+ static _EIGEN_DECLARE_CONST_Packet2d(cephes_LOG2EF, 1.4426950408889634073599);
+ static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_C1, 0.693145751953125);
+ static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_C2, 1.42860682030941723212e-6);
+ static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p0, 1.26177193074810590878e-4);
+ static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p1, 3.02994407707441961300e-2);
+ static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p2, 9.99999999999999999910e-1);
+ static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q0, 3.00198505138664455042e-6);
+ static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q1, 2.52448340349684104192e-3);
+ static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q2, 2.27265548208155028766e-1);
+ static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q3, 2.00000000000000000009e0);
+ static _EIGEN_DECLARE_CONST_Packet2d(half, 0.5);
+ static _EIGEN_DECLARE_CONST_Packet2d(1, 1.0);
+ static _EIGEN_DECLARE_CONST_Packet2d(2, 2.0);
+
+ Packet2d x = _x;
+
+ // Clamp x.
+ x = (Packet2d)__builtin_msa_bsel_v((v16u8)__builtin_msa_fclt_d(x, p2d_exp_lo), (v16u8)x,
+ (v16u8)p2d_exp_lo);
+ x = (Packet2d)__builtin_msa_bsel_v((v16u8)__builtin_msa_fclt_d(p2d_exp_hi, x), (v16u8)x,
+ (v16u8)p2d_exp_hi);
+
+ // Round to nearest integer by adding 0.5 (with x's sign) and truncating.
+ Packet2d x2_add = (Packet2d)__builtin_msa_binsli_d((v2u64)p2d_half, (v2u64)x, 0);
+ Packet2d x2 = pmadd(x, p2d_cephes_LOG2EF, x2_add);
+ Packet2l x2_long = __builtin_msa_ftrunc_s_d(x2);
+ Packet2d x2_long_d = __builtin_msa_ffint_s_d(x2_long);
+
+ x = __builtin_msa_fmsub_d(x, x2_long_d, p2d_cephes_exp_C1);
+ x = __builtin_msa_fmsub_d(x, x2_long_d, p2d_cephes_exp_C2);
+
+ x2 = pmul(x, x);
+
+ Packet2d px = p2d_cephes_exp_p0;
+ px = pmadd(px, x2, p2d_cephes_exp_p1);
+ px = pmadd(px, x2, p2d_cephes_exp_p2);
+ px = pmul(px, x);
+
+ Packet2d qx = p2d_cephes_exp_q0;
+ qx = pmadd(qx, x2, p2d_cephes_exp_q1);
+ qx = pmadd(qx, x2, p2d_cephes_exp_q2);
+ qx = pmadd(qx, x2, p2d_cephes_exp_q3);
+
+ x = pdiv(px, psub(qx, px));
+ x = pmadd(p2d_2, x, p2d_1);
+
+ // x *= 2**exponent.
+ x = __builtin_msa_fexp2_d(x, x2_long);
+
+ return x;
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATH_FUNCTIONS_MSA_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/MSA/PacketMath.h b/src/3rdparty/eigen/Eigen/src/Core/arch/MSA/PacketMath.h
new file mode 100644
index 000000000..afe8f3375
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/MSA/PacketMath.h
@@ -0,0 +1,1233 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2018 Wave Computing, Inc.
+// Written by:
+// Chris Larsen
+// Alexey Frunze (afrunze@wavecomp.com)
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PACKET_MATH_MSA_H
+#define EIGEN_PACKET_MATH_MSA_H
+
+#include <iostream>
+#include <string>
+
+namespace Eigen {
+
+namespace internal {
+
+#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
+#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
+#endif
+
+#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#endif
+
+#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS
+#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32
+#endif
+
+#if 0
+#define EIGEN_MSA_DEBUG \
+ static bool firstTime = true; \
+ do { \
+ if (firstTime) { \
+ std::cout << __FILE__ << ':' << __LINE__ << ':' << __FUNCTION__ << std::endl; \
+ firstTime = false; \
+ } \
+ } while (0)
+#else
+#define EIGEN_MSA_DEBUG
+#endif
+
+#define EIGEN_MSA_SHF_I8(a, b, c, d) (((d) << 6) | ((c) << 4) | ((b) << 2) | (a))
+
+typedef v4f32 Packet4f;
+typedef v4i32 Packet4i;
+typedef v4u32 Packet4ui;
+
+#define _EIGEN_DECLARE_CONST_Packet4f(NAME, X) const Packet4f p4f_##NAME = { X, X, X, X }
+#define _EIGEN_DECLARE_CONST_Packet4i(NAME, X) const Packet4i p4i_##NAME = { X, X, X, X }
+#define _EIGEN_DECLARE_CONST_Packet4ui(NAME, X) const Packet4ui p4ui_##NAME = { X, X, X, X }
+
+inline std::ostream& operator<<(std::ostream& os, const Packet4f& value) {
+ os << "[ " << value[0] << ", " << value[1] << ", " << value[2] << ", " << value[3] << " ]";
+ return os;
+}
+
+inline std::ostream& operator<<(std::ostream& os, const Packet4i& value) {
+ os << "[ " << value[0] << ", " << value[1] << ", " << value[2] << ", " << value[3] << " ]";
+ return os;
+}
+
+inline std::ostream& operator<<(std::ostream& os, const Packet4ui& value) {
+ os << "[ " << value[0] << ", " << value[1] << ", " << value[2] << ", " << value[3] << " ]";
+ return os;
+}
+
+template <>
+struct packet_traits<float> : default_packet_traits {
+ typedef Packet4f type;
+ typedef Packet4f half; // Packet2f intrinsics not implemented yet
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 0, // Packet2f intrinsics not implemented yet
+ // FIXME check the Has*
+ HasDiv = 1,
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+ HasLog = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasBlend = 1
+ };
+};
+
+template <>
+struct packet_traits<int32_t> : default_packet_traits {
+ typedef Packet4i type;
+ typedef Packet4i half; // Packet2i intrinsics not implemented yet
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 0, // Packet2i intrinsics not implemented yet
+ // FIXME check the Has*
+ HasDiv = 1,
+ HasBlend = 1
+ };
+};
+
+template <>
+struct unpacket_traits<Packet4f> {
+ typedef float type;
+ enum { size = 4, alignment = Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false };
+ typedef Packet4f half;
+};
+
+template <>
+struct unpacket_traits<Packet4i> {
+ typedef int32_t type;
+ enum { size = 4, alignment = Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false };
+ typedef Packet4i half;
+};
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) {
+ EIGEN_MSA_DEBUG;
+
+ Packet4f v = { from, from, from, from };
+ return v;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int32_t& from) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fill_w(from);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pload1<Packet4f>(const float* from) {
+ EIGEN_MSA_DEBUG;
+
+ float f = *from;
+ Packet4f v = { f, f, f, f };
+ return v;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pload1<Packet4i>(const int32_t* from) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fill_w(*from);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fadd_w(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_addv_w(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a) {
+ EIGEN_MSA_DEBUG;
+
+ static const Packet4f countdown = { 0.0f, 1.0f, 2.0f, 3.0f };
+ return padd(pset1<Packet4f>(a), countdown);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int32_t& a) {
+ EIGEN_MSA_DEBUG;
+
+ static const Packet4i countdown = { 0, 1, 2, 3 };
+ return padd(pset1<Packet4i>(a), countdown);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fsub_w(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_subv_w(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet4f)__builtin_msa_bnegi_w((v4u32)a, 31);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_addvi_w((v4i32)__builtin_msa_nori_b((v16u8)a, 0), 1);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) {
+ EIGEN_MSA_DEBUG;
+
+ return a;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) {
+ EIGEN_MSA_DEBUG;
+
+ return a;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fmul_w(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_mulv_w(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fdiv_w(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& a, const Packet4i& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_div_s_w(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fmadd_w(c, a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) {
+ EIGEN_MSA_DEBUG;
+
+ // Use "asm" construct to avoid __builtin_msa_maddv_w GNU C bug.
+ Packet4i value = c;
+ __asm__("maddv.w %w[value], %w[a], %w[b]\n"
+ // Outputs
+ : [value] "+f"(value)
+ // Inputs
+ : [a] "f"(a), [b] "f"(b));
+ return value;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet4f)__builtin_msa_and_v((v16u8)a, (v16u8)b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet4i)__builtin_msa_and_v((v16u8)a, (v16u8)b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet4f)__builtin_msa_or_v((v16u8)a, (v16u8)b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet4i)__builtin_msa_or_v((v16u8)a, (v16u8)b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet4f)__builtin_msa_xor_v((v16u8)a, (v16u8)b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet4i)__builtin_msa_xor_v((v16u8)a, (v16u8)b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) {
+ EIGEN_MSA_DEBUG;
+
+ return pand(a, (Packet4f)__builtin_msa_xori_b((v16u8)b, 255));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) {
+ EIGEN_MSA_DEBUG;
+
+ return pand(a, (Packet4i)__builtin_msa_xori_b((v16u8)b, 255));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) {
+ EIGEN_MSA_DEBUG;
+
+#if EIGEN_FAST_MATH
+ // This prefers numbers to NaNs.
+ return __builtin_msa_fmin_w(a, b);
+#else
+ // This prefers NaNs to numbers.
+ Packet4i aNaN = __builtin_msa_fcun_w(a, a);
+ Packet4i aMinOrNaN = por(__builtin_msa_fclt_w(a, b), aNaN);
+ return (Packet4f)__builtin_msa_bsel_v((v16u8)aMinOrNaN, (v16u8)b, (v16u8)a);
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_min_s_w(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) {
+ EIGEN_MSA_DEBUG;
+
+#if EIGEN_FAST_MATH
+ // This prefers numbers to NaNs.
+ return __builtin_msa_fmax_w(a, b);
+#else
+ // This prefers NaNs to numbers.
+ Packet4i aNaN = __builtin_msa_fcun_w(a, a);
+ Packet4i aMaxOrNaN = por(__builtin_msa_fclt_w(b, a), aNaN);
+ return (Packet4f)__builtin_msa_bsel_v((v16u8)aMaxOrNaN, (v16u8)b, (v16u8)a);
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_max_s_w(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_ALIGNED_LOAD return (Packet4f)__builtin_msa_ld_w(const_cast<float*>(from), 0);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int32_t* from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_ALIGNED_LOAD return __builtin_msa_ld_w(const_cast<int32_t*>(from), 0);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_UNALIGNED_LOAD return (Packet4f)__builtin_msa_ld_w(const_cast<float*>(from), 0);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int32_t* from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_UNALIGNED_LOAD return (Packet4i)__builtin_msa_ld_w(const_cast<int32_t*>(from), 0);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) {
+ EIGEN_MSA_DEBUG;
+
+ float f0 = from[0], f1 = from[1];
+ Packet4f v0 = { f0, f0, f0, f0 };
+ Packet4f v1 = { f1, f1, f1, f1 };
+ return (Packet4f)__builtin_msa_ilvr_d((v2i64)v1, (v2i64)v0);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int32_t* from) {
+ EIGEN_MSA_DEBUG;
+
+ int32_t i0 = from[0], i1 = from[1];
+ Packet4i v0 = { i0, i0, i0, i0 };
+ Packet4i v1 = { i1, i1, i1, i1 };
+ return (Packet4i)__builtin_msa_ilvr_d((v2i64)v1, (v2i64)v0);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_ALIGNED_STORE __builtin_msa_st_w((Packet4i)from, to, 0);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstore<int32_t>(int32_t* to, const Packet4i& from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_ALIGNED_STORE __builtin_msa_st_w(from, to, 0);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_UNALIGNED_STORE __builtin_msa_st_w((Packet4i)from, to, 0);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstoreu<int32_t>(int32_t* to, const Packet4i& from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_UNALIGNED_STORE __builtin_msa_st_w(from, to, 0);
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride) {
+ EIGEN_MSA_DEBUG;
+
+ float f = *from;
+ Packet4f v = { f, f, f, f };
+ v[1] = from[stride];
+ v[2] = from[2 * stride];
+ v[3] = from[3 * stride];
+ return v;
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline Packet4i pgather<int32_t, Packet4i>(const int32_t* from, Index stride) {
+ EIGEN_MSA_DEBUG;
+
+ int32_t i = *from;
+ Packet4i v = { i, i, i, i };
+ v[1] = from[stride];
+ v[2] = from[2 * stride];
+ v[3] = from[3 * stride];
+ return v;
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from,
+ Index stride) {
+ EIGEN_MSA_DEBUG;
+
+ *to = from[0];
+ to += stride;
+ *to = from[1];
+ to += stride;
+ *to = from[2];
+ to += stride;
+ *to = from[3];
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline void pscatter<int32_t, Packet4i>(int32_t* to, const Packet4i& from,
+ Index stride) {
+ EIGEN_MSA_DEBUG;
+
+ *to = from[0];
+ to += stride;
+ *to = from[1];
+ to += stride;
+ *to = from[2];
+ to += stride;
+ *to = from[3];
+}
+
+template <>
+EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) {
+ EIGEN_MSA_DEBUG;
+
+ __builtin_prefetch(addr);
+}
+
+template <>
+EIGEN_STRONG_INLINE void prefetch<int32_t>(const int32_t* addr) {
+ EIGEN_MSA_DEBUG;
+
+ __builtin_prefetch(addr);
+}
+
+template <>
+EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) {
+ EIGEN_MSA_DEBUG;
+
+ return a[0];
+}
+
+template <>
+EIGEN_STRONG_INLINE int32_t pfirst<Packet4i>(const Packet4i& a) {
+ EIGEN_MSA_DEBUG;
+
+ return a[0];
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet4f)__builtin_msa_shf_w((v4i32)a, EIGEN_MSA_SHF_I8(3, 2, 1, 0));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_shf_w(a, EIGEN_MSA_SHF_I8(3, 2, 1, 0));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet4f)__builtin_msa_bclri_w((v4u32)a, 31);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a) {
+ EIGEN_MSA_DEBUG;
+
+ Packet4i zero = __builtin_msa_ldi_w(0);
+ return __builtin_msa_add_a_w(zero, a);
+}
+
+template <>
+EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) {
+ EIGEN_MSA_DEBUG;
+
+ Packet4f s = padd(a, (Packet4f)__builtin_msa_shf_w((v4i32)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1)));
+ s = padd(s, (Packet4f)__builtin_msa_shf_w((v4i32)s, EIGEN_MSA_SHF_I8(1, 0, 3, 2)));
+ return s[0];
+}
+
+
+template <>
+EIGEN_STRONG_INLINE int32_t predux<Packet4i>(const Packet4i& a) {
+ EIGEN_MSA_DEBUG;
+
+ Packet4i s = padd(a, __builtin_msa_shf_w(a, EIGEN_MSA_SHF_I8(2, 3, 0, 1)));
+ s = padd(s, __builtin_msa_shf_w(s, EIGEN_MSA_SHF_I8(1, 0, 3, 2)));
+ return s[0];
+}
+
+// Other reduction functions:
+// mul
+template <>
+EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) {
+ EIGEN_MSA_DEBUG;
+
+ Packet4f p = pmul(a, (Packet4f)__builtin_msa_shf_w((v4i32)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1)));
+ p = pmul(p, (Packet4f)__builtin_msa_shf_w((v4i32)p, EIGEN_MSA_SHF_I8(1, 0, 3, 2)));
+ return p[0];
+}
+
+template <>
+EIGEN_STRONG_INLINE int32_t predux_mul<Packet4i>(const Packet4i& a) {
+ EIGEN_MSA_DEBUG;
+
+ Packet4i p = pmul(a, __builtin_msa_shf_w(a, EIGEN_MSA_SHF_I8(2, 3, 0, 1)));
+ p = pmul(p, __builtin_msa_shf_w(p, EIGEN_MSA_SHF_I8(1, 0, 3, 2)));
+ return p[0];
+}
+
+// min
+template <>
+EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) {
+ EIGEN_MSA_DEBUG;
+
+ // Swap 64-bit halves of a.
+ Packet4f swapped = (Packet4f)__builtin_msa_shf_w((Packet4i)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1));
+#if !EIGEN_FAST_MATH
+ // Detect presence of NaNs from pairs a[0]-a[2] and a[1]-a[3] as two 32-bit
+ // masks of all zeroes/ones in low 64 bits.
+ v16u8 unord = (v16u8)__builtin_msa_fcun_w(a, swapped);
+ // Combine the two masks into one: 64 ones if no NaNs, otherwise 64 zeroes.
+ unord = (v16u8)__builtin_msa_ceqi_d((v2i64)unord, 0);
+#endif
+ // Continue with min computation.
+ Packet4f v = __builtin_msa_fmin_w(a, swapped);
+ v = __builtin_msa_fmin_w(
+ v, (Packet4f)__builtin_msa_shf_w((Packet4i)v, EIGEN_MSA_SHF_I8(1, 0, 3, 2)));
+#if !EIGEN_FAST_MATH
+ // Based on the mask select between v and 4 qNaNs.
+ v16u8 qnans = (v16u8)__builtin_msa_fill_w(0x7FC00000);
+ v = (Packet4f)__builtin_msa_bsel_v(unord, qnans, (v16u8)v);
+#endif
+ return v[0];
+}
+
+template <>
+EIGEN_STRONG_INLINE int32_t predux_min<Packet4i>(const Packet4i& a) {
+ EIGEN_MSA_DEBUG;
+
+ Packet4i m = pmin(a, __builtin_msa_shf_w(a, EIGEN_MSA_SHF_I8(2, 3, 0, 1)));
+ m = pmin(m, __builtin_msa_shf_w(m, EIGEN_MSA_SHF_I8(1, 0, 3, 2)));
+ return m[0];
+}
+
+// max
+template <>
+EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) {
+ EIGEN_MSA_DEBUG;
+
+ // Swap 64-bit halves of a.
+ Packet4f swapped = (Packet4f)__builtin_msa_shf_w((Packet4i)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1));
+#if !EIGEN_FAST_MATH
+ // Detect presence of NaNs from pairs a[0]-a[2] and a[1]-a[3] as two 32-bit
+ // masks of all zeroes/ones in low 64 bits.
+ v16u8 unord = (v16u8)__builtin_msa_fcun_w(a, swapped);
+ // Combine the two masks into one: 64 ones if no NaNs, otherwise 64 zeroes.
+ unord = (v16u8)__builtin_msa_ceqi_d((v2i64)unord, 0);
+#endif
+ // Continue with max computation.
+ Packet4f v = __builtin_msa_fmax_w(a, swapped);
+ v = __builtin_msa_fmax_w(
+ v, (Packet4f)__builtin_msa_shf_w((Packet4i)v, EIGEN_MSA_SHF_I8(1, 0, 3, 2)));
+#if !EIGEN_FAST_MATH
+ // Based on the mask select between v and 4 qNaNs.
+ v16u8 qnans = (v16u8)__builtin_msa_fill_w(0x7FC00000);
+ v = (Packet4f)__builtin_msa_bsel_v(unord, qnans, (v16u8)v);
+#endif
+ return v[0];
+}
+
+template <>
+EIGEN_STRONG_INLINE int32_t predux_max<Packet4i>(const Packet4i& a) {
+ EIGEN_MSA_DEBUG;
+
+ Packet4i m = pmax(a, __builtin_msa_shf_w(a, EIGEN_MSA_SHF_I8(2, 3, 0, 1)));
+ m = pmax(m, __builtin_msa_shf_w(m, EIGEN_MSA_SHF_I8(1, 0, 3, 2)));
+ return m[0];
+}
+
+inline std::ostream& operator<<(std::ostream& os, const PacketBlock<Packet4f, 4>& value) {
+ os << "[ " << value.packet[0] << "," << std::endl
+ << " " << value.packet[1] << "," << std::endl
+ << " " << value.packet[2] << "," << std::endl
+ << " " << value.packet[3] << " ]";
+ return os;
+}
+
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4f, 4>& kernel) {
+ EIGEN_MSA_DEBUG;
+
+ v4i32 tmp1, tmp2, tmp3, tmp4;
+
+ tmp1 = __builtin_msa_ilvr_w((v4i32)kernel.packet[1], (v4i32)kernel.packet[0]);
+ tmp2 = __builtin_msa_ilvr_w((v4i32)kernel.packet[3], (v4i32)kernel.packet[2]);
+ tmp3 = __builtin_msa_ilvl_w((v4i32)kernel.packet[1], (v4i32)kernel.packet[0]);
+ tmp4 = __builtin_msa_ilvl_w((v4i32)kernel.packet[3], (v4i32)kernel.packet[2]);
+
+ kernel.packet[0] = (Packet4f)__builtin_msa_ilvr_d((v2i64)tmp2, (v2i64)tmp1);
+ kernel.packet[1] = (Packet4f)__builtin_msa_ilvod_d((v2i64)tmp2, (v2i64)tmp1);
+ kernel.packet[2] = (Packet4f)__builtin_msa_ilvr_d((v2i64)tmp4, (v2i64)tmp3);
+ kernel.packet[3] = (Packet4f)__builtin_msa_ilvod_d((v2i64)tmp4, (v2i64)tmp3);
+}
+
+inline std::ostream& operator<<(std::ostream& os, const PacketBlock<Packet4i, 4>& value) {
+ os << "[ " << value.packet[0] << "," << std::endl
+ << " " << value.packet[1] << "," << std::endl
+ << " " << value.packet[2] << "," << std::endl
+ << " " << value.packet[3] << " ]";
+ return os;
+}
+
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4i, 4>& kernel) {
+ EIGEN_MSA_DEBUG;
+
+ v4i32 tmp1, tmp2, tmp3, tmp4;
+
+ tmp1 = __builtin_msa_ilvr_w(kernel.packet[1], kernel.packet[0]);
+ tmp2 = __builtin_msa_ilvr_w(kernel.packet[3], kernel.packet[2]);
+ tmp3 = __builtin_msa_ilvl_w(kernel.packet[1], kernel.packet[0]);
+ tmp4 = __builtin_msa_ilvl_w(kernel.packet[3], kernel.packet[2]);
+
+ kernel.packet[0] = (Packet4i)__builtin_msa_ilvr_d((v2i64)tmp2, (v2i64)tmp1);
+ kernel.packet[1] = (Packet4i)__builtin_msa_ilvod_d((v2i64)tmp2, (v2i64)tmp1);
+ kernel.packet[2] = (Packet4i)__builtin_msa_ilvr_d((v2i64)tmp4, (v2i64)tmp3);
+ kernel.packet[3] = (Packet4i)__builtin_msa_ilvod_d((v2i64)tmp4, (v2i64)tmp3);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f psqrt(const Packet4f& a) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fsqrt_w(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f prsqrt(const Packet4f& a) {
+ EIGEN_MSA_DEBUG;
+
+#if EIGEN_FAST_MATH
+ return __builtin_msa_frsqrt_w(a);
+#else
+ Packet4f ones = __builtin_msa_ffint_s_w(__builtin_msa_ldi_w(1));
+ return pdiv(ones, psqrt(a));
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) {
+ Packet4f v = a;
+ int32_t old_mode, new_mode;
+ asm volatile(
+ "cfcmsa %[old_mode], $1\n"
+ "ori %[new_mode], %[old_mode], 3\n" // 3 = round towards -INFINITY.
+ "ctcmsa $1, %[new_mode]\n"
+ "frint.w %w[v], %w[v]\n"
+ "ctcmsa $1, %[old_mode]\n"
+ : // outputs
+ [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode),
+ [v] "+f"(v)
+ : // inputs
+ : // clobbers
+ );
+ return v;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) {
+ Packet4f v = a;
+ int32_t old_mode, new_mode;
+ asm volatile(
+ "cfcmsa %[old_mode], $1\n"
+ "ori %[new_mode], %[old_mode], 3\n"
+ "xori %[new_mode], %[new_mode], 1\n" // 2 = round towards +INFINITY.
+ "ctcmsa $1, %[new_mode]\n"
+ "frint.w %w[v], %w[v]\n"
+ "ctcmsa $1, %[old_mode]\n"
+ : // outputs
+ [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode),
+ [v] "+f"(v)
+ : // inputs
+ : // clobbers
+ );
+ return v;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a) {
+ Packet4f v = a;
+ int32_t old_mode, new_mode;
+ asm volatile(
+ "cfcmsa %[old_mode], $1\n"
+ "ori %[new_mode], %[old_mode], 3\n"
+ "xori %[new_mode], %[new_mode], 3\n" // 0 = round to nearest, ties to even.
+ "ctcmsa $1, %[new_mode]\n"
+ "frint.w %w[v], %w[v]\n"
+ "ctcmsa $1, %[old_mode]\n"
+ : // outputs
+ [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode),
+ [v] "+f"(v)
+ : // inputs
+ : // clobbers
+ );
+ return v;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket,
+ const Packet4f& elsePacket) {
+ Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2],
+ ifPacket.select[3] };
+ Packet4i mask = __builtin_msa_ceqi_w((Packet4i)select, 0);
+ return (Packet4f)__builtin_msa_bsel_v((v16u8)mask, (v16u8)thenPacket, (v16u8)elsePacket);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4i pblend(const Selector<4>& ifPacket, const Packet4i& thenPacket,
+ const Packet4i& elsePacket) {
+ Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2],
+ ifPacket.select[3] };
+ Packet4i mask = __builtin_msa_ceqi_w((Packet4i)select, 0);
+ return (Packet4i)__builtin_msa_bsel_v((v16u8)mask, (v16u8)thenPacket, (v16u8)elsePacket);
+}
+
+//---------- double ----------
+
+typedef v2f64 Packet2d;
+typedef v2i64 Packet2l;
+typedef v2u64 Packet2ul;
+
+#define _EIGEN_DECLARE_CONST_Packet2d(NAME, X) const Packet2d p2d_##NAME = { X, X }
+#define _EIGEN_DECLARE_CONST_Packet2l(NAME, X) const Packet2l p2l_##NAME = { X, X }
+#define _EIGEN_DECLARE_CONST_Packet2ul(NAME, X) const Packet2ul p2ul_##NAME = { X, X }
+
+inline std::ostream& operator<<(std::ostream& os, const Packet2d& value) {
+ os << "[ " << value[0] << ", " << value[1] << " ]";
+ return os;
+}
+
+inline std::ostream& operator<<(std::ostream& os, const Packet2l& value) {
+ os << "[ " << value[0] << ", " << value[1] << " ]";
+ return os;
+}
+
+inline std::ostream& operator<<(std::ostream& os, const Packet2ul& value) {
+ os << "[ " << value[0] << ", " << value[1] << " ]";
+ return os;
+}
+
+template <>
+struct packet_traits<double> : default_packet_traits {
+ typedef Packet2d type;
+ typedef Packet2d half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 2,
+ HasHalfPacket = 0,
+ // FIXME check the Has*
+ HasDiv = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasBlend = 1
+ };
+};
+
+template <>
+struct unpacket_traits<Packet2d> {
+ typedef double type;
+ enum { size = 2, alignment = Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false };
+ typedef Packet2d half;
+};
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) {
+ EIGEN_MSA_DEBUG;
+
+ Packet2d value = { from, from };
+ return value;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fadd_d(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) {
+ EIGEN_MSA_DEBUG;
+
+ static const Packet2d countdown = { 0.0, 1.0 };
+ return padd(pset1<Packet2d>(a), countdown);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fsub_d(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet2d)__builtin_msa_bnegi_d((v2u64)a, 63);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) {
+ EIGEN_MSA_DEBUG;
+
+ return a;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fmul_d(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fdiv_d(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fmadd_d(c, a, b);
+}
+
+// Logical Operations are not supported for float, so we have to reinterpret casts using MSA
+// intrinsics
+template <>
+EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet2d)__builtin_msa_and_v((v16u8)a, (v16u8)b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet2d)__builtin_msa_or_v((v16u8)a, (v16u8)b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet2d)__builtin_msa_xor_v((v16u8)a, (v16u8)b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) {
+ EIGEN_MSA_DEBUG;
+
+ return pand(a, (Packet2d)__builtin_msa_xori_b((v16u8)b, 255));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_UNALIGNED_LOAD return (Packet2d)__builtin_msa_ld_d(const_cast<double*>(from), 0);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) {
+ EIGEN_MSA_DEBUG;
+
+#if EIGEN_FAST_MATH
+ // This prefers numbers to NaNs.
+ return __builtin_msa_fmin_d(a, b);
+#else
+ // This prefers NaNs to numbers.
+ v2i64 aNaN = __builtin_msa_fcun_d(a, a);
+ v2i64 aMinOrNaN = por(__builtin_msa_fclt_d(a, b), aNaN);
+ return (Packet2d)__builtin_msa_bsel_v((v16u8)aMinOrNaN, (v16u8)b, (v16u8)a);
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) {
+ EIGEN_MSA_DEBUG;
+
+#if EIGEN_FAST_MATH
+ // This prefers numbers to NaNs.
+ return __builtin_msa_fmax_d(a, b);
+#else
+ // This prefers NaNs to numbers.
+ v2i64 aNaN = __builtin_msa_fcun_d(a, a);
+ v2i64 aMaxOrNaN = por(__builtin_msa_fclt_d(b, a), aNaN);
+ return (Packet2d)__builtin_msa_bsel_v((v16u8)aMaxOrNaN, (v16u8)b, (v16u8)a);
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_UNALIGNED_LOAD return (Packet2d)__builtin_msa_ld_d(const_cast<double*>(from), 0);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from) {
+ EIGEN_MSA_DEBUG;
+
+ Packet2d value = { *from, *from };
+ return value;
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_ALIGNED_STORE __builtin_msa_st_d((v2i64)from, to, 0);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) {
+ EIGEN_MSA_DEBUG;
+
+ EIGEN_DEBUG_UNALIGNED_STORE __builtin_msa_st_d((v2i64)from, to, 0);
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride) {
+ EIGEN_MSA_DEBUG;
+
+ Packet2d value;
+ value[0] = *from;
+ from += stride;
+ value[1] = *from;
+ return value;
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from,
+ Index stride) {
+ EIGEN_MSA_DEBUG;
+
+ *to = from[0];
+ to += stride;
+ *to = from[1];
+}
+
+template <>
+EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) {
+ EIGEN_MSA_DEBUG;
+
+ __builtin_prefetch(addr);
+}
+
+template <>
+EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) {
+ EIGEN_MSA_DEBUG;
+
+ return a[0];
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet2d)__builtin_msa_shf_w((v4i32)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a) {
+ EIGEN_MSA_DEBUG;
+
+ return (Packet2d)__builtin_msa_bclri_d((v2u64)a, 63);
+}
+
+template <>
+EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) {
+ EIGEN_MSA_DEBUG;
+
+ Packet2d s = padd(a, preverse(a));
+ return s[0];
+}
+
+// Other reduction functions:
+// mul
+template <>
+EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) {
+ EIGEN_MSA_DEBUG;
+
+ Packet2d p = pmul(a, preverse(a));
+ return p[0];
+}
+
+// min
+template <>
+EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a) {
+ EIGEN_MSA_DEBUG;
+
+#if EIGEN_FAST_MATH
+ Packet2d swapped = (Packet2d)__builtin_msa_shf_w((Packet4i)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1));
+ Packet2d v = __builtin_msa_fmin_d(a, swapped);
+ return v[0];
+#else
+ double a0 = a[0], a1 = a[1];
+ return ((numext::isnan)(a0) || a0 < a1) ? a0 : a1;
+#endif
+}
+
+// max
+template <>
+EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a) {
+ EIGEN_MSA_DEBUG;
+
+#if EIGEN_FAST_MATH
+ Packet2d swapped = (Packet2d)__builtin_msa_shf_w((Packet4i)a, EIGEN_MSA_SHF_I8(2, 3, 0, 1));
+ Packet2d v = __builtin_msa_fmax_d(a, swapped);
+ return v[0];
+#else
+ double a0 = a[0], a1 = a[1];
+ return ((numext::isnan)(a0) || a0 > a1) ? a0 : a1;
+#endif
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d psqrt(const Packet2d& a) {
+ EIGEN_MSA_DEBUG;
+
+ return __builtin_msa_fsqrt_d(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d prsqrt(const Packet2d& a) {
+ EIGEN_MSA_DEBUG;
+
+#if EIGEN_FAST_MATH
+ return __builtin_msa_frsqrt_d(a);
+#else
+ Packet2d ones = __builtin_msa_ffint_s_d(__builtin_msa_ldi_d(1));
+ return pdiv(ones, psqrt(a));
+#endif
+}
+
+inline std::ostream& operator<<(std::ostream& os, const PacketBlock<Packet2d, 2>& value) {
+ os << "[ " << value.packet[0] << "," << std::endl << " " << value.packet[1] << " ]";
+ return os;
+}
+
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet2d, 2>& kernel) {
+ EIGEN_MSA_DEBUG;
+
+ Packet2d trn1 = (Packet2d)__builtin_msa_ilvev_d((v2i64)kernel.packet[1], (v2i64)kernel.packet[0]);
+ Packet2d trn2 = (Packet2d)__builtin_msa_ilvod_d((v2i64)kernel.packet[1], (v2i64)kernel.packet[0]);
+ kernel.packet[0] = trn1;
+ kernel.packet[1] = trn2;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) {
+ Packet2d v = a;
+ int32_t old_mode, new_mode;
+ asm volatile(
+ "cfcmsa %[old_mode], $1\n"
+ "ori %[new_mode], %[old_mode], 3\n" // 3 = round towards -INFINITY.
+ "ctcmsa $1, %[new_mode]\n"
+ "frint.d %w[v], %w[v]\n"
+ "ctcmsa $1, %[old_mode]\n"
+ : // outputs
+ [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode),
+ [v] "+f"(v)
+ : // inputs
+ : // clobbers
+ );
+ return v;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) {
+ Packet2d v = a;
+ int32_t old_mode, new_mode;
+ asm volatile(
+ "cfcmsa %[old_mode], $1\n"
+ "ori %[new_mode], %[old_mode], 3\n"
+ "xori %[new_mode], %[new_mode], 1\n" // 2 = round towards +INFINITY.
+ "ctcmsa $1, %[new_mode]\n"
+ "frint.d %w[v], %w[v]\n"
+ "ctcmsa $1, %[old_mode]\n"
+ : // outputs
+ [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode),
+ [v] "+f"(v)
+ : // inputs
+ : // clobbers
+ );
+ return v;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) {
+ Packet2d v = a;
+ int32_t old_mode, new_mode;
+ asm volatile(
+ "cfcmsa %[old_mode], $1\n"
+ "ori %[new_mode], %[old_mode], 3\n"
+ "xori %[new_mode], %[new_mode], 3\n" // 0 = round to nearest, ties to even.
+ "ctcmsa $1, %[new_mode]\n"
+ "frint.d %w[v], %w[v]\n"
+ "ctcmsa $1, %[old_mode]\n"
+ : // outputs
+ [old_mode] "=r"(old_mode), [new_mode] "=r"(new_mode),
+ [v] "+f"(v)
+ : // inputs
+ : // clobbers
+ );
+ return v;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d pblend(const Selector<2>& ifPacket, const Packet2d& thenPacket,
+ const Packet2d& elsePacket) {
+ Packet2ul select = { ifPacket.select[0], ifPacket.select[1] };
+ Packet2l mask = __builtin_msa_ceqi_d((Packet2l)select, 0);
+ return (Packet2d)__builtin_msa_bsel_v((v16u8)mask, (v16u8)thenPacket, (v16u8)elsePacket);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PACKET_MATH_MSA_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/Complex.h b/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/Complex.h
new file mode 100644
index 000000000..f40af7f87
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/Complex.h
@@ -0,0 +1,584 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010 Konstantinos Margaritis <markos@freevec.org>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMPLEX_NEON_H
+#define EIGEN_COMPLEX_NEON_H
+
+namespace Eigen {
+
+namespace internal {
+
+inline uint32x4_t p4ui_CONJ_XOR()
+{
+// See bug 1325, clang fails to call vld1q_u64.
+#if EIGEN_COMP_CLANG || EIGEN_COMP_CASTXML
+ uint32x4_t ret = { 0x00000000, 0x80000000, 0x00000000, 0x80000000 };
+ return ret;
+#else
+ static const uint32_t conj_XOR_DATA[] = { 0x00000000, 0x80000000, 0x00000000, 0x80000000 };
+ return vld1q_u32( conj_XOR_DATA );
+#endif
+}
+
+inline uint32x2_t p2ui_CONJ_XOR()
+{
+ static const uint32_t conj_XOR_DATA[] = { 0x00000000, 0x80000000 };
+ return vld1_u32( conj_XOR_DATA );
+}
+
+//---------- float ----------
+
+struct Packet1cf
+{
+ EIGEN_STRONG_INLINE Packet1cf() {}
+ EIGEN_STRONG_INLINE explicit Packet1cf(const Packet2f& a) : v(a) {}
+ Packet2f v;
+};
+struct Packet2cf
+{
+ EIGEN_STRONG_INLINE Packet2cf() {}
+ EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {}
+ Packet4f v;
+};
+
+template<> struct packet_traits<std::complex<float> > : default_packet_traits
+{
+ typedef Packet2cf type;
+ typedef Packet1cf half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 2,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0
+ };
+};
+
+template<> struct unpacket_traits<Packet1cf>
+{
+ typedef std::complex<float> type;
+ typedef Packet1cf half;
+ typedef Packet2f as_real;
+ enum
+ {
+ size = 1,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet2cf>
+{
+ typedef std::complex<float> type;
+ typedef Packet1cf half;
+ typedef Packet4f as_real;
+ enum
+ {
+ size = 2,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet1cf pcast<float,Packet1cf>(const float& a)
+{ return Packet1cf(vset_lane_f32(a, vdup_n_f32(0.f), 0)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pcast<Packet2f,Packet2cf>(const Packet2f& a)
+{ return Packet2cf(vreinterpretq_f32_u64(vmovl_u32(vreinterpret_u32_f32(a)))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cf pset1<Packet1cf>(const std::complex<float>& from)
+{ return Packet1cf(vld1_f32(reinterpret_cast<const float*>(&from))); }
+template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from)
+{
+ const float32x2_t r64 = vld1_f32(reinterpret_cast<const float*>(&from));
+ return Packet2cf(vcombine_f32(r64, r64));
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cf padd<Packet1cf>(const Packet1cf& a, const Packet1cf& b)
+{ return Packet1cf(padd<Packet2f>(a.v, b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{ return Packet2cf(padd<Packet4f>(a.v, b.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet1cf psub<Packet1cf>(const Packet1cf& a, const Packet1cf& b)
+{ return Packet1cf(psub<Packet2f>(a.v, b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{ return Packet2cf(psub<Packet4f>(a.v, b.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet1cf pnegate(const Packet1cf& a) { return Packet1cf(pnegate<Packet2f>(a.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) { return Packet2cf(pnegate<Packet4f>(a.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet1cf pconj(const Packet1cf& a)
+{
+ const Packet2ui b = vreinterpret_u32_f32(a.v);
+ return Packet1cf(vreinterpret_f32_u32(veor_u32(b, p2ui_CONJ_XOR())));
+}
+template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a)
+{
+ const Packet4ui b = vreinterpretq_u32_f32(a.v);
+ return Packet2cf(vreinterpretq_f32_u32(veorq_u32(b, p4ui_CONJ_XOR())));
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cf pmul<Packet1cf>(const Packet1cf& a, const Packet1cf& b)
+{
+ Packet2f v1, v2;
+
+ // Get the real values of a | a1_re | a1_re |
+ v1 = vdup_lane_f32(a.v, 0);
+ // Get the imag values of a | a1_im | a1_im |
+ v2 = vdup_lane_f32(a.v, 1);
+ // Multiply the real a with b
+ v1 = vmul_f32(v1, b.v);
+ // Multiply the imag a with b
+ v2 = vmul_f32(v2, b.v);
+ // Conjugate v2
+ v2 = vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(v2), p2ui_CONJ_XOR()));
+ // Swap real/imag elements in v2.
+ v2 = vrev64_f32(v2);
+ // Add and return the result
+ return Packet1cf(vadd_f32(v1, v2));
+}
+template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{
+ Packet4f v1, v2;
+
+ // Get the real values of a | a1_re | a1_re | a2_re | a2_re |
+ v1 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 0), vdup_lane_f32(vget_high_f32(a.v), 0));
+ // Get the imag values of a | a1_im | a1_im | a2_im | a2_im |
+ v2 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 1), vdup_lane_f32(vget_high_f32(a.v), 1));
+ // Multiply the real a with b
+ v1 = vmulq_f32(v1, b.v);
+ // Multiply the imag a with b
+ v2 = vmulq_f32(v2, b.v);
+ // Conjugate v2
+ v2 = vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(v2), p4ui_CONJ_XOR()));
+ // Swap real/imag elements in v2.
+ v2 = vrev64q_f32(v2);
+ // Add and return the result
+ return Packet2cf(vaddq_f32(v1, v2));
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cf pcmp_eq(const Packet1cf& a, const Packet1cf& b)
+{
+ // Compare real and imaginary parts of a and b to get the mask vector:
+ // [re(a[0])==re(b[0]), im(a[0])==im(b[0])]
+ Packet2f eq = pcmp_eq<Packet2f>(a.v, b.v);
+ // Swap real/imag elements in the mask in to get:
+ // [im(a[0])==im(b[0]), re(a[0])==re(b[0])]
+ Packet2f eq_swapped = vrev64_f32(eq);
+ // Return re(a)==re(b) && im(a)==im(b) by computing bitwise AND of eq and eq_swapped
+ return Packet1cf(pand<Packet2f>(eq, eq_swapped));
+}
+template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf& a, const Packet2cf& b)
+{
+ // Compare real and imaginary parts of a and b to get the mask vector:
+ // [re(a[0])==re(b[0]), im(a[0])==im(b[0]), re(a[1])==re(b[1]), im(a[1])==im(b[1])]
+ Packet4f eq = pcmp_eq<Packet4f>(a.v, b.v);
+ // Swap real/imag elements in the mask in to get:
+ // [im(a[0])==im(b[0]), re(a[0])==re(b[0]), im(a[1])==im(b[1]), re(a[1])==re(b[1])]
+ Packet4f eq_swapped = vrev64q_f32(eq);
+ // Return re(a)==re(b) && im(a)==im(b) by computing bitwise AND of eq and eq_swapped
+ return Packet2cf(pand<Packet4f>(eq, eq_swapped));
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cf pand<Packet1cf>(const Packet1cf& a, const Packet1cf& b)
+{ return Packet1cf(vreinterpret_f32_u32(vand_u32(vreinterpret_u32_f32(a.v), vreinterpret_u32_f32(b.v)))); }
+template<> EIGEN_STRONG_INLINE Packet2cf pand<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{ return Packet2cf(vreinterpretq_f32_u32(vandq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v)))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cf por<Packet1cf>(const Packet1cf& a, const Packet1cf& b)
+{ return Packet1cf(vreinterpret_f32_u32(vorr_u32(vreinterpret_u32_f32(a.v), vreinterpret_u32_f32(b.v)))); }
+template<> EIGEN_STRONG_INLINE Packet2cf por<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{ return Packet2cf(vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v)))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cf pxor<Packet1cf>(const Packet1cf& a, const Packet1cf& b)
+{ return Packet1cf(vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(a.v), vreinterpret_u32_f32(b.v)))); }
+template<> EIGEN_STRONG_INLINE Packet2cf pxor<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{ return Packet2cf(vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v)))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cf pandnot<Packet1cf>(const Packet1cf& a, const Packet1cf& b)
+{ return Packet1cf(vreinterpret_f32_u32(vbic_u32(vreinterpret_u32_f32(a.v), vreinterpret_u32_f32(b.v)))); }
+template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{ return Packet2cf(vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(a.v), vreinterpretq_u32_f32(b.v)))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cf pload<Packet1cf>(const std::complex<float>* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return Packet1cf(pload<Packet2f>((const float*)from)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(const std::complex<float>* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>(reinterpret_cast<const float*>(from))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cf ploadu<Packet1cf>(const std::complex<float>* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cf(ploadu<Packet2f>((const float*)from)); }
+template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>(reinterpret_cast<const float*>(from))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cf ploaddup<Packet1cf>(const std::complex<float>* from)
+{ return pset1<Packet1cf>(*from); }
+template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from)
+{ return pset1<Packet2cf>(*from); }
+
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> *to, const Packet1cf& from)
+{ EIGEN_DEBUG_ALIGNED_STORE pstore((float*)to, from.v); }
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> *to, const Packet2cf& from)
+{ EIGEN_DEBUG_ALIGNED_STORE pstore(reinterpret_cast<float*>(to), from.v); }
+
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> *to, const Packet1cf& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE pstoreu((float*)to, from.v); }
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> *to, const Packet2cf& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE pstoreu(reinterpret_cast<float*>(to), from.v); }
+
+template<> EIGEN_DEVICE_FUNC inline Packet1cf pgather<std::complex<float>, Packet1cf>(
+ const std::complex<float>* from, Index stride)
+{
+ const Packet2f tmp = vdup_n_f32(std::real(from[0*stride]));
+ return Packet1cf(vset_lane_f32(std::imag(from[0*stride]), tmp, 1));
+}
+template<> EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>(
+ const std::complex<float>* from, Index stride)
+{
+ Packet4f res = vdupq_n_f32(std::real(from[0*stride]));
+ res = vsetq_lane_f32(std::imag(from[0*stride]), res, 1);
+ res = vsetq_lane_f32(std::real(from[1*stride]), res, 2);
+ res = vsetq_lane_f32(std::imag(from[1*stride]), res, 3);
+ return Packet2cf(res);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet1cf>(
+ std::complex<float>* to, const Packet1cf& from, Index stride)
+{ to[stride*0] = std::complex<float>(vget_lane_f32(from.v, 0), vget_lane_f32(from.v, 1)); }
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(
+ std::complex<float>* to, const Packet2cf& from, Index stride)
+{
+ to[stride*0] = std::complex<float>(vgetq_lane_f32(from.v, 0), vgetq_lane_f32(from.v, 1));
+ to[stride*1] = std::complex<float>(vgetq_lane_f32(from.v, 2), vgetq_lane_f32(from.v, 3));
+}
+
+template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> *addr)
+{ EIGEN_ARM_PREFETCH(reinterpret_cast<const float*>(addr)); }
+
+template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet1cf>(const Packet1cf& a)
+{
+ EIGEN_ALIGN16 std::complex<float> x;
+ vst1_f32(reinterpret_cast<float*>(&x), a.v);
+ return x;
+}
+template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a)
+{
+ EIGEN_ALIGN16 std::complex<float> x[2];
+ vst1q_f32(reinterpret_cast<float*>(x), a.v);
+ return x[0];
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cf preverse(const Packet1cf& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a)
+{ return Packet2cf(vcombine_f32(vget_high_f32(a.v), vget_low_f32(a.v))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cf pcplxflip<Packet1cf>(const Packet1cf& a)
+{ return Packet1cf(vrev64_f32(a.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& a)
+{ return Packet2cf(vrev64q_f32(a.v)); }
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet1cf>(const Packet1cf& a)
+{
+ std::complex<float> s;
+ vst1_f32((float *)&s, a.v);
+ return s;
+}
+template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
+{
+ std::complex<float> s;
+ vst1_f32(reinterpret_cast<float*>(&s), vadd_f32(vget_low_f32(a.v), vget_high_f32(a.v)));
+ return s;
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet1cf>(const Packet1cf& a)
+{
+ std::complex<float> s;
+ vst1_f32((float *)&s, a.v);
+ return s;
+}
+template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
+{
+ float32x2_t a1, a2, v1, v2, prod;
+ std::complex<float> s;
+
+ a1 = vget_low_f32(a.v);
+ a2 = vget_high_f32(a.v);
+ // Get the real values of a | a1_re | a1_re | a2_re | a2_re |
+ v1 = vdup_lane_f32(a1, 0);
+ // Get the real values of a | a1_im | a1_im | a2_im | a2_im |
+ v2 = vdup_lane_f32(a1, 1);
+ // Multiply the real a with b
+ v1 = vmul_f32(v1, a2);
+ // Multiply the imag a with b
+ v2 = vmul_f32(v2, a2);
+ // Conjugate v2
+ v2 = vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(v2), p2ui_CONJ_XOR()));
+ // Swap real/imag elements in v2.
+ v2 = vrev64_f32(v2);
+ // Add v1, v2
+ prod = vadd_f32(v1, v2);
+
+ vst1_f32(reinterpret_cast<float*>(&s), prod);
+
+ return s;
+}
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cf,Packet2f)
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
+
+template<> EIGEN_STRONG_INLINE Packet1cf pdiv<Packet1cf>(const Packet1cf& a, const Packet1cf& b)
+{
+ // TODO optimize it for NEON
+ Packet1cf res = pmul(a, pconj(b));
+ Packet2f s, rev_s;
+
+ // this computes the norm
+ s = vmul_f32(b.v, b.v);
+ rev_s = vrev64_f32(s);
+
+ return Packet1cf(pdiv<Packet2f>(res.v, vadd_f32(s, rev_s)));
+}
+template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{
+ // TODO optimize it for NEON
+ Packet2cf res = pmul(a,pconj(b));
+ Packet4f s, rev_s;
+
+ // this computes the norm
+ s = vmulq_f32(b.v, b.v);
+ rev_s = vrev64q_f32(s);
+
+ return Packet2cf(pdiv<Packet4f>(res.v, vaddq_f32(s, rev_s)));
+}
+
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet1cf, 1>& /*kernel*/) {}
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet2cf, 2>& kernel)
+{
+ Packet4f tmp = vcombine_f32(vget_high_f32(kernel.packet[0].v), vget_high_f32(kernel.packet[1].v));
+ kernel.packet[0].v = vcombine_f32(vget_low_f32(kernel.packet[0].v), vget_low_f32(kernel.packet[1].v));
+ kernel.packet[1].v = tmp;
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cf psqrt<Packet1cf>(const Packet1cf& a) {
+ return psqrt_complex<Packet1cf>(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf psqrt<Packet2cf>(const Packet2cf& a) {
+ return psqrt_complex<Packet2cf>(a);
+}
+
+//---------- double ----------
+#if EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG
+
+// See bug 1325, clang fails to call vld1q_u64.
+#if EIGEN_COMP_CLANG || EIGEN_COMP_CASTXML
+ static uint64x2_t p2ul_CONJ_XOR = {0x0, 0x8000000000000000};
+#else
+ const uint64_t p2ul_conj_XOR_DATA[] = { 0x0, 0x8000000000000000 };
+ static uint64x2_t p2ul_CONJ_XOR = vld1q_u64( p2ul_conj_XOR_DATA );
+#endif
+
+struct Packet1cd
+{
+ EIGEN_STRONG_INLINE Packet1cd() {}
+ EIGEN_STRONG_INLINE explicit Packet1cd(const Packet2d& a) : v(a) {}
+ Packet2d v;
+};
+
+template<> struct packet_traits<std::complex<double> > : default_packet_traits
+{
+ typedef Packet1cd type;
+ typedef Packet1cd half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 0,
+ size = 1,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0
+ };
+};
+
+template<> struct unpacket_traits<Packet1cd>
+{
+ typedef std::complex<double> type;
+ typedef Packet1cd half;
+ typedef Packet2d as_real;
+ enum
+ {
+ size=1,
+ alignment=Aligned16,
+ vectorizable=true,
+ masked_load_available=false,
+ masked_store_available=false
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet1cd pload<Packet1cd>(const std::complex<double>* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>(reinterpret_cast<const double*>(from))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>(reinterpret_cast<const double*>(from))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from)
+{
+ /* here we really have to use unaligned loads :( */
+ return ploadu<Packet1cd>(&from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{ return Packet1cd(padd<Packet2d>(a.v, b.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{ return Packet1cd(psub<Packet2d>(a.v, b.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a)
+{ return Packet1cd(pnegate<Packet2d>(a.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a)
+{ return Packet1cd(vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(a.v), p2ul_CONJ_XOR))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{
+ Packet2d v1, v2;
+
+ // Get the real values of a
+ v1 = vdupq_lane_f64(vget_low_f64(a.v), 0);
+ // Get the imag values of a
+ v2 = vdupq_lane_f64(vget_high_f64(a.v), 0);
+ // Multiply the real a with b
+ v1 = vmulq_f64(v1, b.v);
+ // Multiply the imag a with b
+ v2 = vmulq_f64(v2, b.v);
+ // Conjugate v2
+ v2 = vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(v2), p2ul_CONJ_XOR));
+ // Swap real/imag elements in v2.
+ v2 = preverse<Packet2d>(v2);
+ // Add and return the result
+ return Packet1cd(vaddq_f64(v1, v2));
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(const Packet1cd& a, const Packet1cd& b)
+{
+ // Compare real and imaginary parts of a and b to get the mask vector:
+ // [re(a)==re(b), im(a)==im(b)]
+ Packet2d eq = pcmp_eq<Packet2d>(a.v, b.v);
+ // Swap real/imag elements in the mask in to get:
+ // [im(a)==im(b), re(a)==re(b)]
+ Packet2d eq_swapped = vreinterpretq_f64_u32(vrev64q_u32(vreinterpretq_u32_f64(eq)));
+ // Return re(a)==re(b) & im(a)==im(b) by computing bitwise AND of eq and eq_swapped
+ return Packet1cd(pand<Packet2d>(eq, eq_swapped));
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd pand<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{ return Packet1cd(vreinterpretq_f64_u64(vandq_u64(vreinterpretq_u64_f64(a.v),vreinterpretq_u64_f64(b.v)))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd por<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{ return Packet1cd(vreinterpretq_f64_u64(vorrq_u64(vreinterpretq_u64_f64(a.v),vreinterpretq_u64_f64(b.v)))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd pxor<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{ return Packet1cd(vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(a.v),vreinterpretq_u64_f64(b.v)))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{ return Packet1cd(vreinterpretq_f64_u64(vbicq_u64(vreinterpretq_u64_f64(a.v),vreinterpretq_u64_f64(b.v)))); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from)
+{ return pset1<Packet1cd>(*from); }
+
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> *to, const Packet1cd& from)
+{ EIGEN_DEBUG_ALIGNED_STORE pstore(reinterpret_cast<double*>(to), from.v); }
+
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> *to, const Packet1cd& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE pstoreu(reinterpret_cast<double*>(to), from.v); }
+
+template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> *addr)
+{ EIGEN_ARM_PREFETCH(reinterpret_cast<const double*>(addr)); }
+
+template<> EIGEN_DEVICE_FUNC inline Packet1cd pgather<std::complex<double>, Packet1cd>(
+ const std::complex<double>* from, Index stride)
+{
+ Packet2d res = pset1<Packet2d>(0.0);
+ res = vsetq_lane_f64(std::real(from[0*stride]), res, 0);
+ res = vsetq_lane_f64(std::imag(from[0*stride]), res, 1);
+ return Packet1cd(res);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet1cd>(
+ std::complex<double>* to, const Packet1cd& from, Index stride)
+{ to[stride*0] = std::complex<double>(vgetq_lane_f64(from.v, 0), vgetq_lane_f64(from.v, 1)); }
+
+template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a)
+{
+ EIGEN_ALIGN16 std::complex<double> res;
+ pstore<std::complex<double> >(&res, a);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a) { return pfirst(a); }
+
+template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a) { return pfirst(a); }
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d)
+
+template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{
+ // TODO optimize it for NEON
+ Packet1cd res = pmul(a,pconj(b));
+ Packet2d s = pmul<Packet2d>(b.v, b.v);
+ Packet2d rev_s = preverse<Packet2d>(s);
+
+ return Packet1cd(pdiv(res.v, padd<Packet2d>(s,rev_s)));
+}
+
+EIGEN_STRONG_INLINE Packet1cd pcplxflip/*<Packet1cd>*/(const Packet1cd& x)
+{ return Packet1cd(preverse(Packet2d(x.v))); }
+
+EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet1cd,2>& kernel)
+{
+ Packet2d tmp = vcombine_f64(vget_high_f64(kernel.packet[0].v), vget_high_f64(kernel.packet[1].v));
+ kernel.packet[0].v = vcombine_f64(vget_low_f64(kernel.packet[0].v), vget_low_f64(kernel.packet[1].v));
+ kernel.packet[1].v = tmp;
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd psqrt<Packet1cd>(const Packet1cd& a) {
+ return psqrt_complex<Packet1cd>(a);
+}
+
+#endif // EIGEN_ARCH_ARM64
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_COMPLEX_NEON_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/GeneralBlockPanelKernel.h b/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/GeneralBlockPanelKernel.h
new file mode 100644
index 000000000..116dbb448
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/GeneralBlockPanelKernel.h
@@ -0,0 +1,183 @@
+namespace Eigen {
+namespace internal {
+
+#if EIGEN_ARCH_ARM && EIGEN_COMP_CLANG
+
+// Clang seems to excessively spill registers in the GEBP kernel on 32-bit arm.
+// Here we specialize gebp_traits to eliminate these register spills.
+// See #2138.
+template<>
+struct gebp_traits <float,float,false,false,Architecture::NEON,GEBPPacketFull>
+ : gebp_traits<float,float,false,false,Architecture::Generic,GEBPPacketFull>
+{
+ EIGEN_STRONG_INLINE void acc(const AccPacket& c, const ResPacket& alpha, ResPacket& r) const
+ {
+ // This volatile inline ASM both acts as a barrier to prevent reordering,
+ // as well as enforces strict register use.
+ asm volatile(
+ "vmla.f32 %q[r], %q[c], %q[alpha]"
+ : [r] "+w" (r)
+ : [c] "w" (c),
+ [alpha] "w" (alpha)
+ : );
+ }
+
+ template <typename LaneIdType>
+ EIGEN_STRONG_INLINE void madd(const Packet4f& a, const Packet4f& b,
+ Packet4f& c, Packet4f& /*tmp*/,
+ const LaneIdType&) const {
+ acc(a, b, c);
+ }
+
+ template <typename LaneIdType>
+ EIGEN_STRONG_INLINE void madd(const Packet4f& a, const QuadPacket<Packet4f>& b,
+ Packet4f& c, Packet4f& tmp,
+ const LaneIdType& lane) const {
+ madd(a, b.get(lane), c, tmp, lane);
+ }
+};
+
+#endif // EIGEN_ARCH_ARM && EIGEN_COMP_CLANG
+
+#if EIGEN_ARCH_ARM64
+
+template<>
+struct gebp_traits <float,float,false,false,Architecture::NEON,GEBPPacketFull>
+ : gebp_traits<float,float,false,false,Architecture::Generic,GEBPPacketFull>
+{
+ typedef float RhsPacket;
+ typedef float32x4_t RhsPacketx4;
+
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacket& dest) const
+ {
+ dest = *b;
+ }
+
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const
+ {
+ dest = vld1q_f32(b);
+ }
+
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacket& dest) const
+ {
+ dest = *b;
+ }
+
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar*, RhsPacketx4&) const
+ {}
+
+ EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, RhsPacket& dest) const
+ {
+ loadRhs(b,dest);
+ }
+
+ EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacket& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<0>&) const
+ {
+ c = vfmaq_n_f32(c, a, b);
+ }
+
+ // NOTE: Template parameter inference failed when compiled with Android NDK:
+ // "candidate template ignored: could not match 'FixedInt<N>' against 'Eigen::internal::FixedInt<0>".
+
+ EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<0>&) const
+ { madd_helper<0>(a, b, c); }
+ EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<1>&) const
+ { madd_helper<1>(a, b, c); }
+ EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<2>&) const
+ { madd_helper<2>(a, b, c); }
+ EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<3>&) const
+ { madd_helper<3>(a, b, c); }
+
+ private:
+ template<int LaneID>
+ EIGEN_STRONG_INLINE void madd_helper(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c) const
+ {
+ #if EIGEN_COMP_GNUC_STRICT && !(EIGEN_GNUC_AT_LEAST(9,0))
+ // workaround gcc issue https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89101
+ // vfmaq_laneq_f32 is implemented through a costly dup
+ if(LaneID==0) asm("fmla %0.4s, %1.4s, %2.s[0]\n" : "+w" (c) : "w" (a), "w" (b) : );
+ else if(LaneID==1) asm("fmla %0.4s, %1.4s, %2.s[1]\n" : "+w" (c) : "w" (a), "w" (b) : );
+ else if(LaneID==2) asm("fmla %0.4s, %1.4s, %2.s[2]\n" : "+w" (c) : "w" (a), "w" (b) : );
+ else if(LaneID==3) asm("fmla %0.4s, %1.4s, %2.s[3]\n" : "+w" (c) : "w" (a), "w" (b) : );
+ #else
+ c = vfmaq_laneq_f32(c, a, b, LaneID);
+ #endif
+ }
+};
+
+
+template<>
+struct gebp_traits <double,double,false,false,Architecture::NEON>
+ : gebp_traits<double,double,false,false,Architecture::Generic>
+{
+ typedef double RhsPacket;
+
+ struct RhsPacketx4 {
+ float64x2_t B_0, B_1;
+ };
+
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacket& dest) const
+ {
+ dest = *b;
+ }
+
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const
+ {
+ dest.B_0 = vld1q_f64(b);
+ dest.B_1 = vld1q_f64(b+2);
+ }
+
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacket& dest) const
+ {
+ loadRhs(b,dest);
+ }
+
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar*, RhsPacketx4&) const
+ {}
+
+ EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, RhsPacket& dest) const
+ {
+ loadRhs(b,dest);
+ }
+
+ EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacket& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<0>&) const
+ {
+ c = vfmaq_n_f64(c, a, b);
+ }
+
+ // NOTE: Template parameter inference failed when compiled with Android NDK:
+ // "candidate template ignored: could not match 'FixedInt<N>' against 'Eigen::internal::FixedInt<0>".
+
+ EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<0>&) const
+ { madd_helper<0>(a, b, c); }
+ EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<1>&) const
+ { madd_helper<1>(a, b, c); }
+ EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<2>&) const
+ { madd_helper<2>(a, b, c); }
+ EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c, RhsPacket& /*tmp*/, const FixedInt<3>&) const
+ { madd_helper<3>(a, b, c); }
+
+ private:
+ template <int LaneID>
+ EIGEN_STRONG_INLINE void madd_helper(const LhsPacket& a, const RhsPacketx4& b, AccPacket& c) const
+ {
+ #if EIGEN_COMP_GNUC_STRICT && !(EIGEN_GNUC_AT_LEAST(9,0))
+ // workaround gcc issue https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89101
+ // vfmaq_laneq_f64 is implemented through a costly dup
+ if(LaneID==0) asm("fmla %0.2d, %1.2d, %2.d[0]\n" : "+w" (c) : "w" (a), "w" (b.B_0) : );
+ else if(LaneID==1) asm("fmla %0.2d, %1.2d, %2.d[1]\n" : "+w" (c) : "w" (a), "w" (b.B_0) : );
+ else if(LaneID==2) asm("fmla %0.2d, %1.2d, %2.d[0]\n" : "+w" (c) : "w" (a), "w" (b.B_1) : );
+ else if(LaneID==3) asm("fmla %0.2d, %1.2d, %2.d[1]\n" : "+w" (c) : "w" (a), "w" (b.B_1) : );
+ #else
+ if(LaneID==0) c = vfmaq_laneq_f64(c, a, b.B_0, 0);
+ else if(LaneID==1) c = vfmaq_laneq_f64(c, a, b.B_0, 1);
+ else if(LaneID==2) c = vfmaq_laneq_f64(c, a, b.B_1, 0);
+ else if(LaneID==3) c = vfmaq_laneq_f64(c, a, b.B_1, 1);
+ #endif
+ }
+};
+
+#endif // EIGEN_ARCH_ARM64
+
+} // namespace internal
+} // namespace Eigen
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h
new file mode 100644
index 000000000..fa6615a85
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h
@@ -0,0 +1,75 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATH_FUNCTIONS_NEON_H
+#define EIGEN_MATH_FUNCTIONS_NEON_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet2f pexp<Packet2f>(const Packet2f& x)
+{ return pexp_float(x); }
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f pexp<Packet4f>(const Packet4f& x)
+{ return pexp_float(x); }
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet2f plog<Packet2f>(const Packet2f& x)
+{ return plog_float(x); }
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f plog<Packet4f>(const Packet4f& x)
+{ return plog_float(x); }
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet2f psin<Packet2f>(const Packet2f& x)
+{ return psin_float(x); }
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f psin<Packet4f>(const Packet4f& x)
+{ return psin_float(x); }
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet2f pcos<Packet2f>(const Packet2f& x)
+{ return pcos_float(x); }
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f pcos<Packet4f>(const Packet4f& x)
+{ return pcos_float(x); }
+
+// Hyperbolic Tangent function.
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet2f ptanh<Packet2f>(const Packet2f& x)
+{ return internal::generic_fast_tanh_float(x); }
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f ptanh<Packet4f>(const Packet4f& x)
+{ return internal::generic_fast_tanh_float(x); }
+
+BF16_PACKET_FUNCTION(Packet4f, Packet4bf, psin)
+BF16_PACKET_FUNCTION(Packet4f, Packet4bf, pcos)
+BF16_PACKET_FUNCTION(Packet4f, Packet4bf, plog)
+BF16_PACKET_FUNCTION(Packet4f, Packet4bf, pexp)
+BF16_PACKET_FUNCTION(Packet4f, Packet4bf, ptanh)
+
+template <>
+EIGEN_STRONG_INLINE Packet4bf pfrexp(const Packet4bf& a, Packet4bf& exponent) {
+ Packet4f fexponent;
+ const Packet4bf out = F32ToBf16(pfrexp<Packet4f>(Bf16ToF32(a), fexponent));
+ exponent = F32ToBf16(fexponent);
+ return out;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4bf pldexp(const Packet4bf& a, const Packet4bf& exponent) {
+ return F32ToBf16(pldexp<Packet4f>(Bf16ToF32(a), Bf16ToF32(exponent)));
+}
+
+//---------- double ----------
+
+#if EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet2d pexp<Packet2d>(const Packet2d& x)
+{ return pexp_double(x); }
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet2d plog<Packet2d>(const Packet2d& x)
+{ return plog_double(x); }
+
+#endif
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATH_FUNCTIONS_NEON_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/PacketMath.h b/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/PacketMath.h
new file mode 100644
index 000000000..34c9bbcdd
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/PacketMath.h
@@ -0,0 +1,4587 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010 Konstantinos Margaritis <markos@freevec.org>
+// Heavily based on Gael's SSE version.
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PACKET_MATH_NEON_H
+#define EIGEN_PACKET_MATH_NEON_H
+
+namespace Eigen {
+
+namespace internal {
+
+#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
+#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
+#endif
+
+#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#endif
+
+#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS
+#if EIGEN_ARCH_ARM64
+#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32
+#else
+#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 16
+#endif
+#endif
+
+#if EIGEN_COMP_MSVC_STRICT
+
+// In MSVC's arm_neon.h header file, all NEON vector types
+// are aliases to the same underlying type __n128.
+// We thus have to wrap them to make them different C++ types.
+// (See also bug 1428)
+typedef eigen_packet_wrapper<float32x2_t,0> Packet2f;
+typedef eigen_packet_wrapper<float32x4_t,1> Packet4f;
+typedef eigen_packet_wrapper<int32_t ,2> Packet4c;
+typedef eigen_packet_wrapper<int8x8_t ,3> Packet8c;
+typedef eigen_packet_wrapper<int8x16_t ,4> Packet16c;
+typedef eigen_packet_wrapper<uint32_t ,5> Packet4uc;
+typedef eigen_packet_wrapper<uint8x8_t ,6> Packet8uc;
+typedef eigen_packet_wrapper<uint8x16_t ,7> Packet16uc;
+typedef eigen_packet_wrapper<int16x4_t ,8> Packet4s;
+typedef eigen_packet_wrapper<int16x8_t ,9> Packet8s;
+typedef eigen_packet_wrapper<uint16x4_t ,10> Packet4us;
+typedef eigen_packet_wrapper<uint16x8_t ,11> Packet8us;
+typedef eigen_packet_wrapper<int32x2_t ,12> Packet2i;
+typedef eigen_packet_wrapper<int32x4_t ,13> Packet4i;
+typedef eigen_packet_wrapper<uint32x2_t ,14> Packet2ui;
+typedef eigen_packet_wrapper<uint32x4_t ,15> Packet4ui;
+typedef eigen_packet_wrapper<int64x2_t ,16> Packet2l;
+typedef eigen_packet_wrapper<uint64x2_t ,17> Packet2ul;
+
+#else
+
+typedef float32x2_t Packet2f;
+typedef float32x4_t Packet4f;
+typedef eigen_packet_wrapper<int32_t ,2> Packet4c;
+typedef int8x8_t Packet8c;
+typedef int8x16_t Packet16c;
+typedef eigen_packet_wrapper<uint32_t ,5> Packet4uc;
+typedef uint8x8_t Packet8uc;
+typedef uint8x16_t Packet16uc;
+typedef int16x4_t Packet4s;
+typedef int16x8_t Packet8s;
+typedef uint16x4_t Packet4us;
+typedef uint16x8_t Packet8us;
+typedef int32x2_t Packet2i;
+typedef int32x4_t Packet4i;
+typedef uint32x2_t Packet2ui;
+typedef uint32x4_t Packet4ui;
+typedef int64x2_t Packet2l;
+typedef uint64x2_t Packet2ul;
+
+#endif // EIGEN_COMP_MSVC_STRICT
+
+EIGEN_STRONG_INLINE Packet4f shuffle1(const Packet4f& m, int mask){
+ const float* a = reinterpret_cast<const float*>(&m);
+ Packet4f res = {*(a + (mask & 3)), *(a + ((mask >> 2) & 3)), *(a + ((mask >> 4) & 3 )), *(a + ((mask >> 6) & 3))};
+ return res;
+}
+
+// fuctionally equivalent to _mm_shuffle_ps in SSE when interleave
+// == false (i.e. shuffle<false>(m, n, mask) equals _mm_shuffle_ps(m, n, mask)),
+// interleave m and n when interleave == true. Currently used in LU/arch/InverseSize4.h
+// to enable a shared implementation for fast inversion of matrices of size 4.
+template<bool interleave>
+EIGEN_STRONG_INLINE Packet4f shuffle2(const Packet4f &m, const Packet4f &n, int mask)
+{
+ const float* a = reinterpret_cast<const float*>(&m);
+ const float* b = reinterpret_cast<const float*>(&n);
+ Packet4f res = {*(a + (mask & 3)), *(a + ((mask >> 2) & 3)), *(b + ((mask >> 4) & 3)), *(b + ((mask >> 6) & 3))};
+ return res;
+}
+
+template<>
+EIGEN_STRONG_INLINE Packet4f shuffle2<true>(const Packet4f &m, const Packet4f &n, int mask)
+{
+ const float* a = reinterpret_cast<const float*>(&m);
+ const float* b = reinterpret_cast<const float*>(&n);
+ Packet4f res = {*(a + (mask & 3)), *(b + ((mask >> 2) & 3)), *(a + ((mask >> 4) & 3)), *(b + ((mask >> 6) & 3))};
+ return res;
+}
+
+EIGEN_STRONG_INLINE static int eigen_neon_shuffle_mask(int p, int q, int r, int s) {return ((s)<<6|(r)<<4|(q)<<2|(p));}
+
+EIGEN_STRONG_INLINE Packet4f vec4f_swizzle1(const Packet4f& a, int p, int q, int r, int s)
+{
+ return shuffle1(a, eigen_neon_shuffle_mask(p, q, r, s));
+}
+EIGEN_STRONG_INLINE Packet4f vec4f_swizzle2(const Packet4f& a, const Packet4f& b, int p, int q, int r, int s)
+{
+ return shuffle2<false>(a,b,eigen_neon_shuffle_mask(p, q, r, s));
+}
+EIGEN_STRONG_INLINE Packet4f vec4f_movelh(const Packet4f& a, const Packet4f& b)
+{
+ return shuffle2<false>(a,b,eigen_neon_shuffle_mask(0, 1, 0, 1));
+}
+EIGEN_STRONG_INLINE Packet4f vec4f_movehl(const Packet4f& a, const Packet4f& b)
+{
+ return shuffle2<false>(b,a,eigen_neon_shuffle_mask(2, 3, 2, 3));
+}
+EIGEN_STRONG_INLINE Packet4f vec4f_unpacklo(const Packet4f& a, const Packet4f& b)
+{
+ return shuffle2<true>(a,b,eigen_neon_shuffle_mask(0, 0, 1, 1));
+}
+EIGEN_STRONG_INLINE Packet4f vec4f_unpackhi(const Packet4f& a, const Packet4f& b)
+{
+ return shuffle2<true>(a,b,eigen_neon_shuffle_mask(2, 2, 3, 3));
+}
+#define vec4f_duplane(a, p) \
+ vdupq_lane_f32(vget_low_f32(a), p)
+
+#define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \
+ const Packet4f p4f_##NAME = pset1<Packet4f>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \
+ const Packet4f p4f_##NAME = vreinterpretq_f32_u32(pset1<int32_t>(X))
+
+#define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \
+ const Packet4i p4i_##NAME = pset1<Packet4i>(X)
+
+#if EIGEN_ARCH_ARM64
+ // __builtin_prefetch tends to do nothing on ARM64 compilers because the
+ // prefetch instructions there are too detailed for __builtin_prefetch to map
+ // meaningfully to them.
+ #define EIGEN_ARM_PREFETCH(ADDR) __asm__ __volatile__("prfm pldl1keep, [%[addr]]\n" ::[addr] "r"(ADDR) : );
+#elif EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC
+ #define EIGEN_ARM_PREFETCH(ADDR) __builtin_prefetch(ADDR);
+#elif defined __pld
+ #define EIGEN_ARM_PREFETCH(ADDR) __pld(ADDR)
+#elif EIGEN_ARCH_ARM32
+ #define EIGEN_ARM_PREFETCH(ADDR) __asm__ __volatile__ ("pld [%[addr]]\n" :: [addr] "r" (ADDR) : );
+#else
+ // by default no explicit prefetching
+ #define EIGEN_ARM_PREFETCH(ADDR)
+#endif
+
+template <>
+struct packet_traits<float> : default_packet_traits
+{
+ typedef Packet4f type;
+ typedef Packet2f half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasAbsDiff = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0,
+
+ HasDiv = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1,
+
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+ HasLog = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+ HasBessel = 0, // Issues with accuracy.
+ HasNdtri = 0
+ };
+};
+
+template <>
+struct packet_traits<int8_t> : default_packet_traits
+{
+ typedef Packet16c type;
+ typedef Packet8c half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 16,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasAbsDiff = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0
+ };
+};
+
+template <>
+struct packet_traits<uint8_t> : default_packet_traits
+{
+ typedef Packet16uc type;
+ typedef Packet8uc half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 16,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 0,
+ HasAbs = 1,
+ HasAbsDiff = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0,
+
+ HasSqrt = 1
+ };
+};
+
+template <>
+struct packet_traits<int16_t> : default_packet_traits
+{
+ typedef Packet8s type;
+ typedef Packet4s half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 8,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasAbsDiff = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0
+ };
+};
+
+template <>
+struct packet_traits<uint16_t> : default_packet_traits
+{
+ typedef Packet8us type;
+ typedef Packet4us half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 8,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 0,
+ HasAbs = 0,
+ HasAbsDiff = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0,
+ HasSqrt = 1
+ };
+};
+
+template <>
+struct packet_traits<int32_t> : default_packet_traits
+{
+ typedef Packet4i type;
+ typedef Packet2i half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasAbsDiff = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0
+ };
+};
+
+template <>
+struct packet_traits<uint32_t> : default_packet_traits
+{
+ typedef Packet4ui type;
+ typedef Packet2ui half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 0,
+ HasAbs = 0,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasAbsDiff = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0,
+
+ HasSqrt = 1
+ };
+};
+
+template <>
+struct packet_traits<int64_t> : default_packet_traits
+{
+ typedef Packet2l type;
+ typedef Packet2l half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 2,
+ HasHalfPacket = 0,
+
+ HasCmp = 1,
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasAbsDiff = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0
+ };
+};
+
+template <>
+struct packet_traits<uint64_t> : default_packet_traits
+{
+ typedef Packet2ul type;
+ typedef Packet2ul half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 2,
+ HasHalfPacket = 0,
+
+ HasCmp = 1,
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 0,
+ HasAbs = 0,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasAbsDiff = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0
+ };
+};
+
+#if EIGEN_GNUC_AT_MOST(4, 4) && !EIGEN_COMP_LLVM
+// workaround gcc 4.2, 4.3 and 4.4 compilation issue
+EIGEN_STRONG_INLINE float32x4_t vld1q_f32(const float* x) { return ::vld1q_f32((const float32_t*)x); }
+EIGEN_STRONG_INLINE float32x2_t vld1_f32(const float* x) { return ::vld1_f32 ((const float32_t*)x); }
+EIGEN_STRONG_INLINE float32x2_t vld1_dup_f32(const float* x) { return ::vld1_dup_f32 ((const float32_t*)x); }
+EIGEN_STRONG_INLINE void vst1q_f32(float* to, float32x4_t from) { ::vst1q_f32((float32_t*)to,from); }
+EIGEN_STRONG_INLINE void vst1_f32 (float* to, float32x2_t from) { ::vst1_f32 ((float32_t*)to,from); }
+#endif
+
+template<> struct unpacket_traits<Packet2f>
+{
+ typedef float type;
+ typedef Packet2f half;
+ typedef Packet2i integer_packet;
+ enum
+ {
+ size = 2,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet4f>
+{
+ typedef float type;
+ typedef Packet2f half;
+ typedef Packet4i integer_packet;
+ enum
+ {
+ size = 4,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet4c>
+{
+ typedef int8_t type;
+ typedef Packet4c half;
+ enum
+ {
+ size = 4,
+ alignment = Unaligned,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet8c>
+{
+ typedef int8_t type;
+ typedef Packet4c half;
+ enum
+ {
+ size = 8,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet16c>
+{
+ typedef int8_t type;
+ typedef Packet8c half;
+ enum
+ {
+ size = 16,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet4uc>
+{
+ typedef uint8_t type;
+ typedef Packet4uc half;
+ enum
+ {
+ size = 4,
+ alignment = Unaligned,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet8uc>
+{
+ typedef uint8_t type;
+ typedef Packet4uc half;
+ enum
+ {
+ size = 8,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet16uc>
+{
+ typedef uint8_t type;
+ typedef Packet8uc half;
+ enum
+ {
+ size = 16,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false};
+};
+template<> struct unpacket_traits<Packet4s>
+{
+ typedef int16_t type;
+ typedef Packet4s half;
+ enum
+ {
+ size = 4,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet8s>
+{
+ typedef int16_t type;
+ typedef Packet4s half;
+ enum
+ {
+ size = 8,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet4us>
+{
+ typedef uint16_t type;
+ typedef Packet4us half;
+ enum
+ {
+ size = 4,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet8us>
+{
+ typedef uint16_t type;
+ typedef Packet4us half;
+ enum
+ {
+ size = 8,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet2i>
+{
+ typedef int32_t type;
+ typedef Packet2i half;
+ enum
+ {
+ size = 2,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet4i>
+{
+ typedef int32_t type;
+ typedef Packet2i half;
+ enum
+ {
+ size = 4,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet2ui>
+{
+ typedef uint32_t type;
+ typedef Packet2ui half;
+ enum
+ {
+ size = 2,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet4ui>
+{
+ typedef uint32_t type;
+ typedef Packet2ui half;
+ enum
+ {
+ size = 4,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet2l>
+{
+ typedef int64_t type;
+ typedef Packet2l half;
+ enum
+ {
+ size = 2,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+template<> struct unpacket_traits<Packet2ul>
+{
+ typedef uint64_t type;
+ typedef Packet2ul half;
+ enum
+ {
+ size = 2,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet2f pset1<Packet2f>(const float& from) { return vdup_n_f32(from); }
+template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) { return vdupq_n_f32(from); }
+template<> EIGEN_STRONG_INLINE Packet4c pset1<Packet4c>(const int8_t& from)
+{ return vget_lane_s32(vreinterpret_s32_s8(vdup_n_s8(from)), 0); }
+template<> EIGEN_STRONG_INLINE Packet8c pset1<Packet8c>(const int8_t& from) { return vdup_n_s8(from); }
+template<> EIGEN_STRONG_INLINE Packet16c pset1<Packet16c>(const int8_t& from) { return vdupq_n_s8(from); }
+template<> EIGEN_STRONG_INLINE Packet4uc pset1<Packet4uc>(const uint8_t& from)
+{ return vget_lane_u32(vreinterpret_u32_u8(vdup_n_u8(from)), 0); }
+template<> EIGEN_STRONG_INLINE Packet8uc pset1<Packet8uc>(const uint8_t& from) { return vdup_n_u8(from); }
+template<> EIGEN_STRONG_INLINE Packet16uc pset1<Packet16uc>(const uint8_t& from) { return vdupq_n_u8(from); }
+template<> EIGEN_STRONG_INLINE Packet4s pset1<Packet4s>(const int16_t& from) { return vdup_n_s16(from); }
+template<> EIGEN_STRONG_INLINE Packet8s pset1<Packet8s>(const int16_t& from) { return vdupq_n_s16(from); }
+template<> EIGEN_STRONG_INLINE Packet4us pset1<Packet4us>(const uint16_t& from) { return vdup_n_u16(from); }
+template<> EIGEN_STRONG_INLINE Packet8us pset1<Packet8us>(const uint16_t& from) { return vdupq_n_u16(from); }
+template<> EIGEN_STRONG_INLINE Packet2i pset1<Packet2i>(const int32_t& from) { return vdup_n_s32(from); }
+template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int32_t& from) { return vdupq_n_s32(from); }
+template<> EIGEN_STRONG_INLINE Packet2ui pset1<Packet2ui>(const uint32_t& from) { return vdup_n_u32(from); }
+template<> EIGEN_STRONG_INLINE Packet4ui pset1<Packet4ui>(const uint32_t& from) { return vdupq_n_u32(from); }
+template<> EIGEN_STRONG_INLINE Packet2l pset1<Packet2l>(const int64_t& from) { return vdupq_n_s64(from); }
+template<> EIGEN_STRONG_INLINE Packet2ul pset1<Packet2ul>(const uint64_t& from) { return vdupq_n_u64(from); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pset1frombits<Packet2f>(unsigned int from)
+{ return vreinterpret_f32_u32(vdup_n_u32(from)); }
+template<> EIGEN_STRONG_INLINE Packet4f pset1frombits<Packet4f>(unsigned int from)
+{ return vreinterpretq_f32_u32(vdupq_n_u32(from)); }
+
+template<> EIGEN_STRONG_INLINE Packet2f plset<Packet2f>(const float& a)
+{
+ const float c[] = {0.0f,1.0f};
+ return vadd_f32(pset1<Packet2f>(a), vld1_f32(c));
+}
+template<> EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a)
+{
+ const float c[] = {0.0f,1.0f,2.0f,3.0f};
+ return vaddq_f32(pset1<Packet4f>(a), vld1q_f32(c));
+}
+template<> EIGEN_STRONG_INLINE Packet4c plset<Packet4c>(const int8_t& a)
+{ return vget_lane_s32(vreinterpret_s32_s8(vadd_s8(vreinterpret_s8_u32(vdup_n_u32(0x03020100)), vdup_n_s8(a))), 0); }
+template<> EIGEN_STRONG_INLINE Packet8c plset<Packet8c>(const int8_t& a)
+{
+ const int8_t c[] = {0,1,2,3,4,5,6,7};
+ return vadd_s8(pset1<Packet8c>(a), vld1_s8(c));
+}
+template<> EIGEN_STRONG_INLINE Packet16c plset<Packet16c>(const int8_t& a)
+{
+ const int8_t c[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+ return vaddq_s8(pset1<Packet16c>(a), vld1q_s8(c));
+}
+template<> EIGEN_STRONG_INLINE Packet4uc plset<Packet4uc>(const uint8_t& a)
+{ return vget_lane_u32(vreinterpret_u32_u8(vadd_u8(vreinterpret_u8_u32(vdup_n_u32(0x03020100)), vdup_n_u8(a))), 0); }
+template<> EIGEN_STRONG_INLINE Packet8uc plset<Packet8uc>(const uint8_t& a)
+{
+ const uint8_t c[] = {0,1,2,3,4,5,6,7};
+ return vadd_u8(pset1<Packet8uc>(a), vld1_u8(c));
+}
+template<> EIGEN_STRONG_INLINE Packet16uc plset<Packet16uc>(const uint8_t& a)
+{
+ const uint8_t c[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+ return vaddq_u8(pset1<Packet16uc>(a), vld1q_u8(c));
+}
+template<> EIGEN_STRONG_INLINE Packet4s plset<Packet4s>(const int16_t& a)
+{
+ const int16_t c[] = {0,1,2,3};
+ return vadd_s16(pset1<Packet4s>(a), vld1_s16(c));
+}
+template<> EIGEN_STRONG_INLINE Packet4us plset<Packet4us>(const uint16_t& a)
+{
+ const uint16_t c[] = {0,1,2,3};
+ return vadd_u16(pset1<Packet4us>(a), vld1_u16(c));
+}
+template<> EIGEN_STRONG_INLINE Packet8s plset<Packet8s>(const int16_t& a)
+{
+ const int16_t c[] = {0,1,2,3,4,5,6,7};
+ return vaddq_s16(pset1<Packet8s>(a), vld1q_s16(c));
+}
+template<> EIGEN_STRONG_INLINE Packet8us plset<Packet8us>(const uint16_t& a)
+{
+ const uint16_t c[] = {0,1,2,3,4,5,6,7};
+ return vaddq_u16(pset1<Packet8us>(a), vld1q_u16(c));
+}
+template<> EIGEN_STRONG_INLINE Packet2i plset<Packet2i>(const int32_t& a)
+{
+ const int32_t c[] = {0,1};
+ return vadd_s32(pset1<Packet2i>(a), vld1_s32(c));
+}
+template<> EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int32_t& a)
+{
+ const int32_t c[] = {0,1,2,3};
+ return vaddq_s32(pset1<Packet4i>(a), vld1q_s32(c));
+}
+template<> EIGEN_STRONG_INLINE Packet2ui plset<Packet2ui>(const uint32_t& a)
+{
+ const uint32_t c[] = {0,1};
+ return vadd_u32(pset1<Packet2ui>(a), vld1_u32(c));
+}
+template<> EIGEN_STRONG_INLINE Packet4ui plset<Packet4ui>(const uint32_t& a)
+{
+ const uint32_t c[] = {0,1,2,3};
+ return vaddq_u32(pset1<Packet4ui>(a), vld1q_u32(c));
+}
+template<> EIGEN_STRONG_INLINE Packet2l plset<Packet2l>(const int64_t& a)
+{
+ const int64_t c[] = {0,1};
+ return vaddq_s64(pset1<Packet2l>(a), vld1q_s64(c));
+}
+template<> EIGEN_STRONG_INLINE Packet2ul plset<Packet2ul>(const uint64_t& a)
+{
+ const uint64_t c[] = {0,1};
+ return vaddq_u64(pset1<Packet2ul>(a), vld1q_u64(c));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f padd<Packet2f>(const Packet2f& a, const Packet2f& b) { return vadd_f32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return vaddq_f32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4c padd<Packet4c>(const Packet4c& a, const Packet4c& b)
+{
+ return vget_lane_s32(vreinterpret_s32_s8(vadd_s8(
+ vreinterpret_s8_s32(vdup_n_s32(a)),
+ vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c padd<Packet8c>(const Packet8c& a, const Packet8c& b) { return vadd_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c padd<Packet16c>(const Packet16c& a, const Packet16c& b) { return vaddq_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4uc padd<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{
+ return vget_lane_u32(vreinterpret_u32_u8(vadd_u8(
+ vreinterpret_u8_u32(vdup_n_u32(a)),
+ vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc padd<Packet8uc>(const Packet8uc& a, const Packet8uc& b) { return vadd_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc padd<Packet16uc>(const Packet16uc& a, const Packet16uc& b) { return vaddq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s padd<Packet4s>(const Packet4s& a, const Packet4s& b) { return vadd_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8s padd<Packet8s>(const Packet8s& a, const Packet8s& b) { return vaddq_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4us padd<Packet4us>(const Packet4us& a, const Packet4us& b) { return vadd_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us padd<Packet8us>(const Packet8us& a, const Packet8us& b) { return vaddq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i padd<Packet2i>(const Packet2i& a, const Packet2i& b) { return vadd_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return vaddq_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ui padd<Packet2ui>(const Packet2ui& a, const Packet2ui& b) { return vadd_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui padd<Packet4ui>(const Packet4ui& a, const Packet4ui& b) { return vaddq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l padd<Packet2l>(const Packet2l& a, const Packet2l& b) { return vaddq_s64(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ul padd<Packet2ul>(const Packet2ul& a, const Packet2ul& b) { return vaddq_u64(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet2f psub<Packet2f>(const Packet2f& a, const Packet2f& b) { return vsub_f32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return vsubq_f32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4c psub<Packet4c>(const Packet4c& a, const Packet4c& b)
+{
+ return vget_lane_s32(vreinterpret_s32_s8(vsub_s8(
+ vreinterpret_s8_s32(vdup_n_s32(a)),
+ vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c psub<Packet8c>(const Packet8c& a, const Packet8c& b) { return vsub_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c psub<Packet16c>(const Packet16c& a, const Packet16c& b) { return vsubq_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4uc psub<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{
+ return vget_lane_u32(vreinterpret_u32_u8(vsub_u8(
+ vreinterpret_u8_u32(vdup_n_u32(a)),
+ vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc psub<Packet8uc>(const Packet8uc& a, const Packet8uc& b) { return vsub_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc psub<Packet16uc>(const Packet16uc& a, const Packet16uc& b) { return vsubq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s psub<Packet4s>(const Packet4s& a, const Packet4s& b) { return vsub_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8s psub<Packet8s>(const Packet8s& a, const Packet8s& b) { return vsubq_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4us psub<Packet4us>(const Packet4us& a, const Packet4us& b) { return vsub_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us psub<Packet8us>(const Packet8us& a, const Packet8us& b) { return vsubq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i psub<Packet2i>(const Packet2i& a, const Packet2i& b) { return vsub_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return vsubq_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ui psub<Packet2ui>(const Packet2ui& a, const Packet2ui& b) { return vsub_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui psub<Packet4ui>(const Packet4ui& a, const Packet4ui& b) { return vsubq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l psub<Packet2l>(const Packet2l& a, const Packet2l& b) { return vsubq_s64(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ul psub<Packet2ul>(const Packet2ul& a, const Packet2ul& b) { return vsubq_u64(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pxor<Packet2f>(const Packet2f& a, const Packet2f& b);
+template<> EIGEN_STRONG_INLINE Packet2f paddsub<Packet2f>(const Packet2f& a, const Packet2f & b) {
+ Packet2f mask = {numext::bit_cast<float>(0x80000000u), 0.0f};
+ return padd(a, pxor(mask, b));
+}
+template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b);
+template<> EIGEN_STRONG_INLINE Packet4f paddsub<Packet4f>(const Packet4f& a, const Packet4f& b) {
+ Packet4f mask = {numext::bit_cast<float>(0x80000000u), 0.0f, numext::bit_cast<float>(0x80000000u), 0.0f};
+ return padd(a, pxor(mask, b));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f pnegate(const Packet2f& a) { return vneg_f32(a); }
+template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) { return vnegq_f32(a); }
+template<> EIGEN_STRONG_INLINE Packet4c pnegate(const Packet4c& a)
+{ return vget_lane_s32(vreinterpret_s32_s8(vneg_s8(vreinterpret_s8_s32(vdup_n_s32(a)))), 0); }
+template<> EIGEN_STRONG_INLINE Packet8c pnegate(const Packet8c& a) { return vneg_s8(a); }
+template<> EIGEN_STRONG_INLINE Packet16c pnegate(const Packet16c& a) { return vnegq_s8(a); }
+template<> EIGEN_STRONG_INLINE Packet4s pnegate(const Packet4s& a) { return vneg_s16(a); }
+template<> EIGEN_STRONG_INLINE Packet8s pnegate(const Packet8s& a) { return vnegq_s16(a); }
+template<> EIGEN_STRONG_INLINE Packet2i pnegate(const Packet2i& a) { return vneg_s32(a); }
+template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return vnegq_s32(a); }
+template<> EIGEN_STRONG_INLINE Packet2l pnegate(const Packet2l& a) {
+#if EIGEN_ARCH_ARM64
+ return vnegq_s64(a);
+#else
+ return vcombine_s64(
+ vdup_n_s64(-vgetq_lane_s64(a, 0)),
+ vdup_n_s64(-vgetq_lane_s64(a, 1)));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f pconj(const Packet2f& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4c pconj(const Packet4c& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet8c pconj(const Packet8c& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet16c pconj(const Packet16c& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4uc pconj(const Packet4uc& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet8uc pconj(const Packet8uc& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet16uc pconj(const Packet16uc& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4s pconj(const Packet4s& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet8s pconj(const Packet8s& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4us pconj(const Packet4us& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet8us pconj(const Packet8us& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet2i pconj(const Packet2i& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet2ui pconj(const Packet2ui& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4ui pconj(const Packet4ui& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet2l pconj(const Packet2l& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet2ul pconj(const Packet2ul& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet2f pmul<Packet2f>(const Packet2f& a, const Packet2f& b) { return vmul_f32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { return vmulq_f32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4c pmul<Packet4c>(const Packet4c& a, const Packet4c& b)
+{
+ return vget_lane_s32(vreinterpret_s32_s8(vmul_s8(
+ vreinterpret_s8_s32(vdup_n_s32(a)),
+ vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c pmul<Packet8c>(const Packet8c& a, const Packet8c& b) { return vmul_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c pmul<Packet16c>(const Packet16c& a, const Packet16c& b) { return vmulq_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4uc pmul<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{
+ return vget_lane_u32(vreinterpret_u32_u8(vmul_u8(
+ vreinterpret_u8_u32(vdup_n_u32(a)),
+ vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc pmul<Packet8uc>(const Packet8uc& a, const Packet8uc& b) { return vmul_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pmul<Packet16uc>(const Packet16uc& a, const Packet16uc& b) { return vmulq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s pmul<Packet4s>(const Packet4s& a, const Packet4s& b) { return vmul_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8s pmul<Packet8s>(const Packet8s& a, const Packet8s& b) { return vmulq_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4us pmul<Packet4us>(const Packet4us& a, const Packet4us& b) { return vmul_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pmul<Packet8us>(const Packet8us& a, const Packet8us& b) { return vmulq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i pmul<Packet2i>(const Packet2i& a, const Packet2i& b) { return vmul_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) { return vmulq_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ui pmul<Packet2ui>(const Packet2ui& a, const Packet2ui& b) { return vmul_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pmul<Packet4ui>(const Packet4ui& a, const Packet4ui& b) { return vmulq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l pmul<Packet2l>(const Packet2l& a, const Packet2l& b) {
+ return vcombine_s64(
+ vdup_n_s64(vgetq_lane_s64(a, 0)*vgetq_lane_s64(b, 0)),
+ vdup_n_s64(vgetq_lane_s64(a, 1)*vgetq_lane_s64(b, 1)));
+}
+template<> EIGEN_STRONG_INLINE Packet2ul pmul<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
+ return vcombine_u64(
+ vdup_n_u64(vgetq_lane_u64(a, 0)*vgetq_lane_u64(b, 0)),
+ vdup_n_u64(vgetq_lane_u64(a, 1)*vgetq_lane_u64(b, 1)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f pdiv<Packet2f>(const Packet2f& a, const Packet2f& b)
+{
+#if EIGEN_ARCH_ARM64
+ return vdiv_f32(a,b);
+#else
+ Packet2f inv, restep, div;
+
+ // NEON does not offer a divide instruction, we have to do a reciprocal approximation
+ // However NEON in contrast to other SIMD engines (AltiVec/SSE), offers
+ // a reciprocal estimate AND a reciprocal step -which saves a few instructions
+ // vrecpeq_f32() returns an estimate to 1/b, which we will finetune with
+ // Newton-Raphson and vrecpsq_f32()
+ inv = vrecpe_f32(b);
+
+ // This returns a differential, by which we will have to multiply inv to get a better
+ // approximation of 1/b.
+ restep = vrecps_f32(b, inv);
+ inv = vmul_f32(restep, inv);
+
+ // Finally, multiply a by 1/b and get the wanted result of the division.
+ div = vmul_f32(a, inv);
+
+ return div;
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+#if EIGEN_ARCH_ARM64
+ return vdivq_f32(a,b);
+#else
+ Packet4f inv, restep, div;
+
+ // NEON does not offer a divide instruction, we have to do a reciprocal approximation
+ // However NEON in contrast to other SIMD engines (AltiVec/SSE), offers
+ // a reciprocal estimate AND a reciprocal step -which saves a few instructions
+ // vrecpeq_f32() returns an estimate to 1/b, which we will finetune with
+ // Newton-Raphson and vrecpsq_f32()
+ inv = vrecpeq_f32(b);
+
+ // This returns a differential, by which we will have to multiply inv to get a better
+ // approximation of 1/b.
+ restep = vrecpsq_f32(b, inv);
+ inv = vmulq_f32(restep, inv);
+
+ // Finally, multiply a by 1/b and get the wanted result of the division.
+ div = vmulq_f32(a, inv);
+
+ return div;
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet4c pdiv<Packet4c>(const Packet4c& /*a*/, const Packet4c& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet4c>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c pdiv<Packet8c>(const Packet8c& /*a*/, const Packet8c& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet8c>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet16c pdiv<Packet16c>(const Packet16c& /*a*/, const Packet16c& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet16c>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet4uc pdiv<Packet4uc>(const Packet4uc& /*a*/, const Packet4uc& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet4uc>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc pdiv<Packet8uc>(const Packet8uc& /*a*/, const Packet8uc& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet8uc>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet16uc pdiv<Packet16uc>(const Packet16uc& /*a*/, const Packet16uc& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet16uc>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet4s pdiv<Packet4s>(const Packet4s& /*a*/, const Packet4s& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet4s>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet8s pdiv<Packet8s>(const Packet8s& /*a*/, const Packet8s& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet8s>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet4us pdiv<Packet4us>(const Packet4us& /*a*/, const Packet4us& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet4us>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet8us pdiv<Packet8us>(const Packet8us& /*a*/, const Packet8us& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet8us>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet2i pdiv<Packet2i>(const Packet2i& /*a*/, const Packet2i& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet2i>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& /*a*/, const Packet4i& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet4i>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet2ui pdiv<Packet2ui>(const Packet2ui& /*a*/, const Packet2ui& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet2ui>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet4ui pdiv<Packet4ui>(const Packet4ui& /*a*/, const Packet4ui& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet4ui>(0);
+}
+template<> EIGEN_STRONG_INLINE Packet2l pdiv<Packet2l>(const Packet2l& /*a*/, const Packet2l& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet2l>(0LL);
+}
+template<> EIGEN_STRONG_INLINE Packet2ul pdiv<Packet2ul>(const Packet2ul& /*a*/, const Packet2ul& /*b*/)
+{
+ eigen_assert(false && "packet integer division are not supported by NEON");
+ return pset1<Packet2ul>(0ULL);
+}
+
+
+#ifdef __ARM_FEATURE_FMA
+template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c)
+{ return vfmaq_f32(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet2f pmadd(const Packet2f& a, const Packet2f& b, const Packet2f& c)
+{ return vfma_f32(c,a,b); }
+#else
+template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c)
+{
+ return vmlaq_f32(c,a,b);
+}
+template<> EIGEN_STRONG_INLINE Packet2f pmadd(const Packet2f& a, const Packet2f& b, const Packet2f& c)
+{
+ return vmla_f32(c,a,b);
+}
+#endif
+
+// No FMA instruction for int, so use MLA unconditionally.
+template<> EIGEN_STRONG_INLINE Packet4c pmadd(const Packet4c& a, const Packet4c& b, const Packet4c& c)
+{
+ return vget_lane_s32(vreinterpret_s32_s8(vmla_s8(
+ vreinterpret_s8_s32(vdup_n_s32(c)),
+ vreinterpret_s8_s32(vdup_n_s32(a)),
+ vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c pmadd(const Packet8c& a, const Packet8c& b, const Packet8c& c)
+{ return vmla_s8(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c pmadd(const Packet16c& a, const Packet16c& b, const Packet16c& c)
+{ return vmlaq_s8(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet4uc pmadd(const Packet4uc& a, const Packet4uc& b, const Packet4uc& c)
+{
+ return vget_lane_u32(vreinterpret_u32_u8(vmla_u8(
+ vreinterpret_u8_u32(vdup_n_u32(c)),
+ vreinterpret_u8_u32(vdup_n_u32(a)),
+ vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc pmadd(const Packet8uc& a, const Packet8uc& b, const Packet8uc& c)
+{ return vmla_u8(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pmadd(const Packet16uc& a, const Packet16uc& b, const Packet16uc& c)
+{ return vmlaq_u8(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s pmadd(const Packet4s& a, const Packet4s& b, const Packet4s& c)
+{ return vmla_s16(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet8s pmadd(const Packet8s& a, const Packet8s& b, const Packet8s& c)
+{ return vmlaq_s16(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet4us pmadd(const Packet4us& a, const Packet4us& b, const Packet4us& c)
+{ return vmla_u16(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pmadd(const Packet8us& a, const Packet8us& b, const Packet8us& c)
+{ return vmlaq_u16(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i pmadd(const Packet2i& a, const Packet2i& b, const Packet2i& c)
+{ return vmla_s32(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c)
+{ return vmlaq_s32(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ui pmadd(const Packet2ui& a, const Packet2ui& b, const Packet2ui& c)
+{ return vmla_u32(c,a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pmadd(const Packet4ui& a, const Packet4ui& b, const Packet4ui& c)
+{ return vmlaq_u32(c,a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pabsdiff<Packet2f>(const Packet2f& a, const Packet2f& b)
+{ return vabd_f32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4f pabsdiff<Packet4f>(const Packet4f& a, const Packet4f& b)
+{ return vabdq_f32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4c pabsdiff<Packet4c>(const Packet4c& a, const Packet4c& b)
+{
+ return vget_lane_s32(vreinterpret_s32_s8(vabd_s8(
+ vreinterpret_s8_s32(vdup_n_s32(a)),
+ vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c pabsdiff<Packet8c>(const Packet8c& a, const Packet8c& b)
+{ return vabd_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c pabsdiff<Packet16c>(const Packet16c& a, const Packet16c& b)
+{ return vabdq_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4uc pabsdiff<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{
+ return vget_lane_u32(vreinterpret_u32_u8(vabd_u8(
+ vreinterpret_u8_u32(vdup_n_u32(a)),
+ vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc pabsdiff<Packet8uc>(const Packet8uc& a, const Packet8uc& b)
+{ return vabd_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pabsdiff<Packet16uc>(const Packet16uc& a, const Packet16uc& b)
+{ return vabdq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s pabsdiff<Packet4s>(const Packet4s& a, const Packet4s& b)
+{ return vabd_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8s pabsdiff<Packet8s>(const Packet8s& a, const Packet8s& b)
+{ return vabdq_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4us pabsdiff<Packet4us>(const Packet4us& a, const Packet4us& b)
+{ return vabd_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pabsdiff<Packet8us>(const Packet8us& a, const Packet8us& b)
+{ return vabdq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i pabsdiff<Packet2i>(const Packet2i& a, const Packet2i& b)
+{ return vabd_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pabsdiff<Packet4i>(const Packet4i& a, const Packet4i& b)
+{ return vabdq_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ui pabsdiff<Packet2ui>(const Packet2ui& a, const Packet2ui& b)
+{ return vabd_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pabsdiff<Packet4ui>(const Packet4ui& a, const Packet4ui& b)
+{ return vabdq_u32(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pmin<Packet2f>(const Packet2f& a, const Packet2f& b) { return vmin_f32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) { return vminq_f32(a,b); }
+
+#ifdef __ARM_FEATURE_NUMERIC_MAXMIN
+// numeric max and min are only available if ARM_FEATURE_NUMERIC_MAXMIN is defined (which can only be the case for Armv8 systems).
+template<> EIGEN_STRONG_INLINE Packet4f pmin<PropagateNumbers, Packet4f>(const Packet4f& a, const Packet4f& b) { return vminnmq_f32(a, b); }
+template<> EIGEN_STRONG_INLINE Packet2f pmin<PropagateNumbers, Packet2f>(const Packet2f& a, const Packet2f& b) { return vminnm_f32(a, b); }
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet4f pmin<PropagateNaN, Packet4f>(const Packet4f& a, const Packet4f& b) { return pmin<Packet4f>(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pmin<PropagateNaN, Packet2f>(const Packet2f& a, const Packet2f& b) { return pmin<Packet2f>(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet4c pmin<Packet4c>(const Packet4c& a, const Packet4c& b)
+{
+ return vget_lane_s32(vreinterpret_s32_s8(vmin_s8(
+ vreinterpret_s8_s32(vdup_n_s32(a)),
+ vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c pmin<Packet8c>(const Packet8c& a, const Packet8c& b) { return vmin_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c pmin<Packet16c>(const Packet16c& a, const Packet16c& b) { return vminq_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4uc pmin<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{
+ return vget_lane_u32(vreinterpret_u32_u8(vmin_u8(
+ vreinterpret_u8_u32(vdup_n_u32(a)),
+ vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc pmin<Packet8uc>(const Packet8uc& a, const Packet8uc& b) { return vmin_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pmin<Packet16uc>(const Packet16uc& a, const Packet16uc& b) { return vminq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s pmin<Packet4s>(const Packet4s& a, const Packet4s& b) { return vmin_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8s pmin<Packet8s>(const Packet8s& a, const Packet8s& b) { return vminq_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4us pmin<Packet4us>(const Packet4us& a, const Packet4us& b) { return vmin_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pmin<Packet8us>(const Packet8us& a, const Packet8us& b) { return vminq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i pmin<Packet2i>(const Packet2i& a, const Packet2i& b) { return vmin_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) { return vminq_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ui pmin<Packet2ui>(const Packet2ui& a, const Packet2ui& b) { return vmin_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pmin<Packet4ui>(const Packet4ui& a, const Packet4ui& b) { return vminq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l pmin<Packet2l>(const Packet2l& a, const Packet2l& b) {
+ return vcombine_s64(
+ vdup_n_s64((std::min)(vgetq_lane_s64(a, 0), vgetq_lane_s64(b, 0))),
+ vdup_n_s64((std::min)(vgetq_lane_s64(a, 1), vgetq_lane_s64(b, 1))));
+}
+template<> EIGEN_STRONG_INLINE Packet2ul pmin<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
+ return vcombine_u64(
+ vdup_n_u64((std::min)(vgetq_lane_u64(a, 0), vgetq_lane_u64(b, 0))),
+ vdup_n_u64((std::min)(vgetq_lane_u64(a, 1), vgetq_lane_u64(b, 1))));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f pmax<Packet2f>(const Packet2f& a, const Packet2f& b) { return vmax_f32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) { return vmaxq_f32(a,b); }
+
+#ifdef __ARM_FEATURE_NUMERIC_MAXMIN
+// numeric max and min are only available if ARM_FEATURE_NUMERIC_MAXMIN is defined (which can only be the case for Armv8 systems).
+template<> EIGEN_STRONG_INLINE Packet4f pmax<PropagateNumbers, Packet4f>(const Packet4f& a, const Packet4f& b) { return vmaxnmq_f32(a, b); }
+template<> EIGEN_STRONG_INLINE Packet2f pmax<PropagateNumbers, Packet2f>(const Packet2f& a, const Packet2f& b) { return vmaxnm_f32(a, b); }
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet4f pmax<PropagateNaN, Packet4f>(const Packet4f& a, const Packet4f& b) { return pmax<Packet4f>(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pmax<PropagateNaN, Packet2f>(const Packet2f& a, const Packet2f& b) { return pmax<Packet2f>(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet4c pmax<Packet4c>(const Packet4c& a, const Packet4c& b)
+{
+ return vget_lane_s32(vreinterpret_s32_s8(vmax_s8(
+ vreinterpret_s8_s32(vdup_n_s32(a)),
+ vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c pmax<Packet8c>(const Packet8c& a, const Packet8c& b) { return vmax_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c pmax<Packet16c>(const Packet16c& a, const Packet16c& b) { return vmaxq_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4uc pmax<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{
+ return vget_lane_u32(vreinterpret_u32_u8(vmax_u8(
+ vreinterpret_u8_u32(vdup_n_u32(a)),
+ vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc pmax<Packet8uc>(const Packet8uc& a, const Packet8uc& b) { return vmax_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pmax<Packet16uc>(const Packet16uc& a, const Packet16uc& b) { return vmaxq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s pmax<Packet4s>(const Packet4s& a, const Packet4s& b) { return vmax_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8s pmax<Packet8s>(const Packet8s& a, const Packet8s& b) { return vmaxq_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4us pmax<Packet4us>(const Packet4us& a, const Packet4us& b) { return vmax_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pmax<Packet8us>(const Packet8us& a, const Packet8us& b) { return vmaxq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i pmax<Packet2i>(const Packet2i& a, const Packet2i& b) { return vmax_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) { return vmaxq_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ui pmax<Packet2ui>(const Packet2ui& a, const Packet2ui& b) { return vmax_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pmax<Packet4ui>(const Packet4ui& a, const Packet4ui& b) { return vmaxq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l pmax<Packet2l>(const Packet2l& a, const Packet2l& b) {
+ return vcombine_s64(
+ vdup_n_s64((std::max)(vgetq_lane_s64(a, 0), vgetq_lane_s64(b, 0))),
+ vdup_n_s64((std::max)(vgetq_lane_s64(a, 1), vgetq_lane_s64(b, 1))));
+}
+template<> EIGEN_STRONG_INLINE Packet2ul pmax<Packet2ul>(const Packet2ul& a, const Packet2ul& b) {
+ return vcombine_u64(
+ vdup_n_u64((std::max)(vgetq_lane_u64(a, 0), vgetq_lane_u64(b, 0))),
+ vdup_n_u64((std::max)(vgetq_lane_u64(a, 1), vgetq_lane_u64(b, 1))));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f pcmp_le<Packet2f>(const Packet2f& a, const Packet2f& b)
+{ return vreinterpret_f32_u32(vcle_f32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_le<Packet4f>(const Packet4f& a, const Packet4f& b)
+{ return vreinterpretq_f32_u32(vcleq_f32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4c pcmp_le<Packet4c>(const Packet4c& a, const Packet4c& b)
+{
+ return vget_lane_s32(vreinterpret_s32_u8(vcle_s8(
+ vreinterpret_s8_s32(vdup_n_s32(a)),
+ vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c pcmp_le<Packet8c>(const Packet8c& a, const Packet8c& b)
+{ return vreinterpret_s8_u8(vcle_s8(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet16c pcmp_le<Packet16c>(const Packet16c& a, const Packet16c& b)
+{ return vreinterpretq_s8_u8(vcleq_s8(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4uc pcmp_le<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{
+ return vget_lane_u32(vreinterpret_u32_u8(vcle_u8(
+ vreinterpret_u8_u32(vdup_n_u32(a)),
+ vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc pcmp_le<Packet8uc>(const Packet8uc& a, const Packet8uc& b)
+{ return vcle_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pcmp_le<Packet16uc>(const Packet16uc& a, const Packet16uc& b)
+{ return vcleq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s pcmp_le<Packet4s>(const Packet4s& a, const Packet4s& b)
+{ return vreinterpret_s16_u16(vcle_s16(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet8s pcmp_le<Packet8s>(const Packet8s& a, const Packet8s& b)
+{ return vreinterpretq_s16_u16(vcleq_s16(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4us pcmp_le<Packet4us>(const Packet4us& a, const Packet4us& b)
+{ return vcle_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pcmp_le<Packet8us>(const Packet8us& a, const Packet8us& b)
+{ return vcleq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i pcmp_le<Packet2i>(const Packet2i& a, const Packet2i& b)
+{ return vreinterpret_s32_u32(vcle_s32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4i pcmp_le<Packet4i>(const Packet4i& a, const Packet4i& b)
+{ return vreinterpretq_s32_u32(vcleq_s32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet2ui pcmp_le<Packet2ui>(const Packet2ui& a, const Packet2ui& b)
+{ return vcle_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pcmp_le<Packet4ui>(const Packet4ui& a, const Packet4ui& b)
+{ return vcleq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l pcmp_le<Packet2l>(const Packet2l& a, const Packet2l& b)
+{
+#if EIGEN_ARCH_ARM64
+ return vreinterpretq_s64_u64(vcleq_s64(a,b));
+#else
+ return vcombine_s64(
+ vdup_n_s64(vgetq_lane_s64(a, 0) <= vgetq_lane_s64(b, 0) ? numext::int64_t(-1) : 0),
+ vdup_n_s64(vgetq_lane_s64(a, 1) <= vgetq_lane_s64(b, 1) ? numext::int64_t(-1) : 0));
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet2ul pcmp_le<Packet2ul>(const Packet2ul& a, const Packet2ul& b)
+{
+#if EIGEN_ARCH_ARM64
+ return vcleq_u64(a,b);
+#else
+ return vcombine_u64(
+ vdup_n_u64(vgetq_lane_u64(a, 0) <= vgetq_lane_u64(b, 0) ? numext::uint64_t(-1) : 0),
+ vdup_n_u64(vgetq_lane_u64(a, 1) <= vgetq_lane_u64(b, 1) ? numext::uint64_t(-1) : 0));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f pcmp_lt<Packet2f>(const Packet2f& a, const Packet2f& b)
+{ return vreinterpret_f32_u32(vclt_f32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt<Packet4f>(const Packet4f& a, const Packet4f& b)
+{ return vreinterpretq_f32_u32(vcltq_f32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4c pcmp_lt<Packet4c>(const Packet4c& a, const Packet4c& b)
+{
+ return vget_lane_s32(vreinterpret_s32_u8(vclt_s8(
+ vreinterpret_s8_s32(vdup_n_s32(a)),
+ vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c pcmp_lt<Packet8c>(const Packet8c& a, const Packet8c& b)
+{ return vreinterpret_s8_u8(vclt_s8(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet16c pcmp_lt<Packet16c>(const Packet16c& a, const Packet16c& b)
+{ return vreinterpretq_s8_u8(vcltq_s8(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4uc pcmp_lt<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{
+ return vget_lane_u32(vreinterpret_u32_u8(vclt_u8(
+ vreinterpret_u8_u32(vdup_n_u32(a)),
+ vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc pcmp_lt<Packet8uc>(const Packet8uc& a, const Packet8uc& b)
+{ return vclt_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pcmp_lt<Packet16uc>(const Packet16uc& a, const Packet16uc& b)
+{ return vcltq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s pcmp_lt<Packet4s>(const Packet4s& a, const Packet4s& b)
+{ return vreinterpret_s16_u16(vclt_s16(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet8s pcmp_lt<Packet8s>(const Packet8s& a, const Packet8s& b)
+{ return vreinterpretq_s16_u16(vcltq_s16(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4us pcmp_lt<Packet4us>(const Packet4us& a, const Packet4us& b)
+{ return vclt_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pcmp_lt<Packet8us>(const Packet8us& a, const Packet8us& b)
+{ return vcltq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i pcmp_lt<Packet2i>(const Packet2i& a, const Packet2i& b)
+{ return vreinterpret_s32_u32(vclt_s32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4i pcmp_lt<Packet4i>(const Packet4i& a, const Packet4i& b)
+{ return vreinterpretq_s32_u32(vcltq_s32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet2ui pcmp_lt<Packet2ui>(const Packet2ui& a, const Packet2ui& b)
+{ return vclt_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pcmp_lt<Packet4ui>(const Packet4ui& a, const Packet4ui& b)
+{ return vcltq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l pcmp_lt<Packet2l>(const Packet2l& a, const Packet2l& b)
+{
+#if EIGEN_ARCH_ARM64
+ return vreinterpretq_s64_u64(vcltq_s64(a,b));
+#else
+ return vcombine_s64(
+ vdup_n_s64(vgetq_lane_s64(a, 0) < vgetq_lane_s64(b, 0) ? numext::int64_t(-1) : 0),
+ vdup_n_s64(vgetq_lane_s64(a, 1) < vgetq_lane_s64(b, 1) ? numext::int64_t(-1) : 0));
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet2ul pcmp_lt<Packet2ul>(const Packet2ul& a, const Packet2ul& b)
+{
+#if EIGEN_ARCH_ARM64
+ return vcltq_u64(a,b);
+#else
+ return vcombine_u64(
+ vdup_n_u64(vgetq_lane_u64(a, 0) < vgetq_lane_u64(b, 0) ? numext::uint64_t(-1) : 0),
+ vdup_n_u64(vgetq_lane_u64(a, 1) < vgetq_lane_u64(b, 1) ? numext::uint64_t(-1) : 0));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f pcmp_eq<Packet2f>(const Packet2f& a, const Packet2f& b)
+{ return vreinterpret_f32_u32(vceq_f32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_eq<Packet4f>(const Packet4f& a, const Packet4f& b)
+{ return vreinterpretq_f32_u32(vceqq_f32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4c pcmp_eq<Packet4c>(const Packet4c& a, const Packet4c& b)
+{
+ return vget_lane_s32(vreinterpret_s32_u8(vceq_s8(
+ vreinterpret_s8_s32(vdup_n_s32(a)),
+ vreinterpret_s8_s32(vdup_n_s32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c pcmp_eq<Packet8c>(const Packet8c& a, const Packet8c& b)
+{ return vreinterpret_s8_u8(vceq_s8(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet16c pcmp_eq<Packet16c>(const Packet16c& a, const Packet16c& b)
+{ return vreinterpretq_s8_u8(vceqq_s8(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4uc pcmp_eq<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{
+ return vget_lane_u32(vreinterpret_u32_u8(vceq_u8(
+ vreinterpret_u8_u32(vdup_n_u32(a)),
+ vreinterpret_u8_u32(vdup_n_u32(b)))), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc pcmp_eq<Packet8uc>(const Packet8uc& a, const Packet8uc& b)
+{ return vceq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pcmp_eq<Packet16uc>(const Packet16uc& a, const Packet16uc& b)
+{ return vceqq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s pcmp_eq<Packet4s>(const Packet4s& a, const Packet4s& b)
+{ return vreinterpret_s16_u16(vceq_s16(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet8s pcmp_eq<Packet8s>(const Packet8s& a, const Packet8s& b)
+{ return vreinterpretq_s16_u16(vceqq_s16(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4us pcmp_eq<Packet4us>(const Packet4us& a, const Packet4us& b)
+{ return vceq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pcmp_eq<Packet8us>(const Packet8us& a, const Packet8us& b)
+{ return vceqq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i pcmp_eq<Packet2i>(const Packet2i& a, const Packet2i& b)
+{ return vreinterpret_s32_u32(vceq_s32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet4i pcmp_eq<Packet4i>(const Packet4i& a, const Packet4i& b)
+{ return vreinterpretq_s32_u32(vceqq_s32(a,b)); }
+template<> EIGEN_STRONG_INLINE Packet2ui pcmp_eq<Packet2ui>(const Packet2ui& a, const Packet2ui& b)
+{ return vceq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pcmp_eq<Packet4ui>(const Packet4ui& a, const Packet4ui& b)
+{ return vceqq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l pcmp_eq<Packet2l>(const Packet2l& a, const Packet2l& b)
+{
+#if EIGEN_ARCH_ARM64
+ return vreinterpretq_s64_u64(vceqq_s64(a,b));
+#else
+ return vcombine_s64(
+ vdup_n_s64(vgetq_lane_s64(a, 0) == vgetq_lane_s64(b, 0) ? numext::int64_t(-1) : 0),
+ vdup_n_s64(vgetq_lane_s64(a, 1) == vgetq_lane_s64(b, 1) ? numext::int64_t(-1) : 0));
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet2ul pcmp_eq<Packet2ul>(const Packet2ul& a, const Packet2ul& b)
+{
+#if EIGEN_ARCH_ARM64
+ return vceqq_u64(a,b);
+#else
+ return vcombine_u64(
+ vdup_n_u64(vgetq_lane_u64(a, 0) == vgetq_lane_u64(b, 0) ? numext::uint64_t(-1) : 0),
+ vdup_n_u64(vgetq_lane_u64(a, 1) == vgetq_lane_u64(b, 1) ? numext::uint64_t(-1) : 0));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f pcmp_lt_or_nan<Packet2f>(const Packet2f& a, const Packet2f& b)
+{ return vreinterpret_f32_u32(vmvn_u32(vcge_f32(a,b))); }
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt_or_nan<Packet4f>(const Packet4f& a, const Packet4f& b)
+{ return vreinterpretq_f32_u32(vmvnq_u32(vcgeq_f32(a,b))); }
+
+// Logical Operations are not supported for float, so we have to reinterpret casts using NEON intrinsics
+template<> EIGEN_STRONG_INLINE Packet2f pand<Packet2f>(const Packet2f& a, const Packet2f& b)
+{ return vreinterpret_f32_u32(vand_u32(vreinterpret_u32_f32(a),vreinterpret_u32_f32(b))); }
+template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b)
+{ return vreinterpretq_f32_u32(vandq_u32(vreinterpretq_u32_f32(a),vreinterpretq_u32_f32(b))); }
+template<> EIGEN_STRONG_INLINE Packet4c pand<Packet4c>(const Packet4c& a, const Packet4c& b)
+{ return a & b; }
+template<> EIGEN_STRONG_INLINE Packet8c pand<Packet8c>(const Packet8c& a, const Packet8c& b)
+{ return vand_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c pand<Packet16c>(const Packet16c& a, const Packet16c& b)
+{ return vandq_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4uc pand<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{ return a & b; }
+template<> EIGEN_STRONG_INLINE Packet8uc pand<Packet8uc>(const Packet8uc& a, const Packet8uc& b)
+{ return vand_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pand<Packet16uc>(const Packet16uc& a, const Packet16uc& b)
+{ return vandq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s pand<Packet4s>(const Packet4s& a, const Packet4s& b) { return vand_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8s pand<Packet8s>(const Packet8s& a, const Packet8s& b) { return vandq_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4us pand<Packet4us>(const Packet4us& a, const Packet4us& b)
+{ return vand_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pand<Packet8us>(const Packet8us& a, const Packet8us& b)
+{ return vandq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i pand<Packet2i>(const Packet2i& a, const Packet2i& b) { return vand_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return vandq_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ui pand<Packet2ui>(const Packet2ui& a, const Packet2ui& b)
+{ return vand_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pand<Packet4ui>(const Packet4ui& a, const Packet4ui& b)
+{ return vandq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l pand<Packet2l>(const Packet2l& a, const Packet2l& b) { return vandq_s64(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ul pand<Packet2ul>(const Packet2ul& a, const Packet2ul& b)
+{ return vandq_u64(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet2f por<Packet2f>(const Packet2f& a, const Packet2f& b)
+{ return vreinterpret_f32_u32(vorr_u32(vreinterpret_u32_f32(a),vreinterpret_u32_f32(b))); }
+template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b)
+{ return vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a),vreinterpretq_u32_f32(b))); }
+template<> EIGEN_STRONG_INLINE Packet4c por<Packet4c>(const Packet4c& a, const Packet4c& b)
+{ return a | b; }
+template<> EIGEN_STRONG_INLINE Packet8c por<Packet8c>(const Packet8c& a, const Packet8c& b) { return vorr_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c por<Packet16c>(const Packet16c& a, const Packet16c& b)
+{ return vorrq_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4uc por<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{ return a | b; }
+template<> EIGEN_STRONG_INLINE Packet8uc por<Packet8uc>(const Packet8uc& a, const Packet8uc& b)
+{ return vorr_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc por<Packet16uc>(const Packet16uc& a, const Packet16uc& b)
+{ return vorrq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s por<Packet4s>(const Packet4s& a, const Packet4s& b)
+{ return vorr_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8s por<Packet8s>(const Packet8s& a, const Packet8s& b)
+{ return vorrq_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4us por<Packet4us>(const Packet4us& a, const Packet4us& b)
+{ return vorr_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us por<Packet8us>(const Packet8us& a, const Packet8us& b)
+{ return vorrq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i por<Packet2i>(const Packet2i& a, const Packet2i& b) { return vorr_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return vorrq_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ui por<Packet2ui>(const Packet2ui& a, const Packet2ui& b)
+{ return vorr_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui por<Packet4ui>(const Packet4ui& a, const Packet4ui& b)
+{ return vorrq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l por<Packet2l>(const Packet2l& a, const Packet2l& b)
+{ return vorrq_s64(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ul por<Packet2ul>(const Packet2ul& a, const Packet2ul& b)
+{ return vorrq_u64(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pxor<Packet2f>(const Packet2f& a, const Packet2f& b)
+{ return vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(a),vreinterpret_u32_f32(b))); }
+template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b)
+{ return vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(a),vreinterpretq_u32_f32(b))); }
+template<> EIGEN_STRONG_INLINE Packet4c pxor<Packet4c>(const Packet4c& a, const Packet4c& b)
+{ return a ^ b; }
+template<> EIGEN_STRONG_INLINE Packet8c pxor<Packet8c>(const Packet8c& a, const Packet8c& b)
+{ return veor_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c pxor<Packet16c>(const Packet16c& a, const Packet16c& b)
+{ return veorq_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4uc pxor<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{ return a ^ b; }
+template<> EIGEN_STRONG_INLINE Packet8uc pxor<Packet8uc>(const Packet8uc& a, const Packet8uc& b)
+{ return veor_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pxor<Packet16uc>(const Packet16uc& a, const Packet16uc& b)
+{ return veorq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s pxor<Packet4s>(const Packet4s& a, const Packet4s& b) { return veor_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8s pxor<Packet8s>(const Packet8s& a, const Packet8s& b) { return veorq_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4us pxor<Packet4us>(const Packet4us& a, const Packet4us& b)
+{ return veor_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pxor<Packet8us>(const Packet8us& a, const Packet8us& b)
+{ return veorq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i pxor<Packet2i>(const Packet2i& a, const Packet2i& b) { return veor_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return veorq_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ui pxor<Packet2ui>(const Packet2ui& a, const Packet2ui& b)
+{ return veor_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pxor<Packet4ui>(const Packet4ui& a, const Packet4ui& b)
+{ return veorq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l pxor<Packet2l>(const Packet2l& a, const Packet2l& b)
+{ return veorq_s64(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ul pxor<Packet2ul>(const Packet2ul& a, const Packet2ul& b)
+{ return veorq_u64(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pandnot<Packet2f>(const Packet2f& a, const Packet2f& b)
+{ return vreinterpret_f32_u32(vbic_u32(vreinterpret_u32_f32(a),vreinterpret_u32_f32(b))); }
+template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b)
+{ return vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(a),vreinterpretq_u32_f32(b))); }
+template<> EIGEN_STRONG_INLINE Packet4c pandnot<Packet4c>(const Packet4c& a, const Packet4c& b)
+{ return a & ~b; }
+template<> EIGEN_STRONG_INLINE Packet8c pandnot<Packet8c>(const Packet8c& a, const Packet8c& b) { return vbic_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16c pandnot<Packet16c>(const Packet16c& a, const Packet16c& b) { return vbicq_s8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4uc pandnot<Packet4uc>(const Packet4uc& a, const Packet4uc& b)
+{ return a & ~b; }
+template<> EIGEN_STRONG_INLINE Packet8uc pandnot<Packet8uc>(const Packet8uc& a, const Packet8uc& b)
+{ return vbic_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16uc pandnot<Packet16uc>(const Packet16uc& a, const Packet16uc& b)
+{ return vbicq_u8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4s pandnot<Packet4s>(const Packet4s& a, const Packet4s& b)
+{ return vbic_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8s pandnot<Packet8s>(const Packet8s& a, const Packet8s& b)
+{ return vbicq_s16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4us pandnot<Packet4us>(const Packet4us& a, const Packet4us& b)
+{ return vbic_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet8us pandnot<Packet8us>(const Packet8us& a, const Packet8us& b)
+{ return vbicq_u16(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2i pandnot<Packet2i>(const Packet2i& a, const Packet2i& b)
+{ return vbic_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b)
+{ return vbicq_s32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ui pandnot<Packet2ui>(const Packet2ui& a, const Packet2ui& b)
+{ return vbic_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4ui pandnot<Packet4ui>(const Packet4ui& a, const Packet4ui& b)
+{ return vbicq_u32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2l pandnot<Packet2l>(const Packet2l& a, const Packet2l& b)
+{ return vbicq_s64(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2ul pandnot<Packet2ul>(const Packet2ul& a, const Packet2ul& b)
+{ return vbicq_u64(a,b); }
+
+
+template<int N> EIGEN_STRONG_INLINE Packet4c parithmetic_shift_right(Packet4c& a)
+{ return vget_lane_s32(vreinterpret_s32_s8(vshr_n_s8(vreinterpret_s8_s32(vdup_n_s32(a)), N)), 0); }
+template<int N> EIGEN_STRONG_INLINE Packet8c parithmetic_shift_right(Packet8c a) { return vshr_n_s8(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet16c parithmetic_shift_right(Packet16c a) { return vshrq_n_s8(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4uc parithmetic_shift_right(Packet4uc& a)
+{ return vget_lane_u32(vreinterpret_u32_u8(vshr_n_u8(vreinterpret_u8_u32(vdup_n_u32(a)), N)), 0); }
+template<int N> EIGEN_STRONG_INLINE Packet8uc parithmetic_shift_right(Packet8uc a) { return vshr_n_u8(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet16uc parithmetic_shift_right(Packet16uc a) { return vshrq_n_u8(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4s parithmetic_shift_right(Packet4s a) { return vshr_n_s16(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet8s parithmetic_shift_right(Packet8s a) { return vshrq_n_s16(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4us parithmetic_shift_right(Packet4us a) { return vshr_n_u16(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet8us parithmetic_shift_right(Packet8us a) { return vshrq_n_u16(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet2i parithmetic_shift_right(Packet2i a) { return vshr_n_s32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4i parithmetic_shift_right(Packet4i a) { return vshrq_n_s32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet2ui parithmetic_shift_right(Packet2ui a) { return vshr_n_u32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4ui parithmetic_shift_right(Packet4ui a) { return vshrq_n_u32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet2l parithmetic_shift_right(Packet2l a) { return vshrq_n_s64(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet2ul parithmetic_shift_right(Packet2ul a) { return vshrq_n_u64(a,N); }
+
+template<int N> EIGEN_STRONG_INLINE Packet4c plogical_shift_right(Packet4c& a)
+{ return vget_lane_s32(vreinterpret_s32_u8(vshr_n_u8(vreinterpret_u8_s32(vdup_n_s32(a)), N)), 0); }
+template<int N> EIGEN_STRONG_INLINE Packet8c plogical_shift_right(Packet8c a)
+{ return vreinterpret_s8_u8(vshr_n_u8(vreinterpret_u8_s8(a),N)); }
+template<int N> EIGEN_STRONG_INLINE Packet16c plogical_shift_right(Packet16c a)
+{ return vreinterpretq_s8_u8(vshrq_n_u8(vreinterpretq_u8_s8(a),N)); }
+template<int N> EIGEN_STRONG_INLINE Packet4uc plogical_shift_right(Packet4uc& a)
+{ return vget_lane_u32(vreinterpret_u32_s8(vshr_n_s8(vreinterpret_s8_u32(vdup_n_u32(a)), N)), 0); }
+template<int N> EIGEN_STRONG_INLINE Packet8uc plogical_shift_right(Packet8uc a) { return vshr_n_u8(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet16uc plogical_shift_right(Packet16uc a) { return vshrq_n_u8(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4s plogical_shift_right(Packet4s a)
+{ return vreinterpret_s16_u16(vshr_n_u16(vreinterpret_u16_s16(a),N)); }
+template<int N> EIGEN_STRONG_INLINE Packet8s plogical_shift_right(Packet8s a)
+{ return vreinterpretq_s16_u16(vshrq_n_u16(vreinterpretq_u16_s16(a),N)); }
+template<int N> EIGEN_STRONG_INLINE Packet4us plogical_shift_right(Packet4us a) { return vshr_n_u16(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet8us plogical_shift_right(Packet8us a) { return vshrq_n_u16(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet2i plogical_shift_right(Packet2i a)
+{ return vreinterpret_s32_u32(vshr_n_u32(vreinterpret_u32_s32(a),N)); }
+template<int N> EIGEN_STRONG_INLINE Packet4i plogical_shift_right(Packet4i a)
+{ return vreinterpretq_s32_u32(vshrq_n_u32(vreinterpretq_u32_s32(a),N)); }
+template<int N> EIGEN_STRONG_INLINE Packet2ui plogical_shift_right(Packet2ui a) { return vshr_n_u32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4ui plogical_shift_right(Packet4ui a) { return vshrq_n_u32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet2l plogical_shift_right(Packet2l a)
+{ return vreinterpretq_s64_u64(vshrq_n_u64(vreinterpretq_u64_s64(a),N)); }
+template<int N> EIGEN_STRONG_INLINE Packet2ul plogical_shift_right(Packet2ul a) { return vshrq_n_u64(a,N); }
+
+template<int N> EIGEN_STRONG_INLINE Packet4c plogical_shift_left(Packet4c& a)
+{ return vget_lane_s32(vreinterpret_s32_s8(vshl_n_s8(vreinterpret_s8_s32(vdup_n_s32(a)), N)), 0); }
+template<int N> EIGEN_STRONG_INLINE Packet8c plogical_shift_left(Packet8c a) { return vshl_n_s8(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet16c plogical_shift_left(Packet16c a) { return vshlq_n_s8(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4uc plogical_shift_left(Packet4uc& a)
+{ return vget_lane_u32(vreinterpret_u32_u8(vshl_n_u8(vreinterpret_u8_u32(vdup_n_u32(a)), N)), 0); }
+template<int N> EIGEN_STRONG_INLINE Packet8uc plogical_shift_left(Packet8uc a) { return vshl_n_u8(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet16uc plogical_shift_left(Packet16uc a) { return vshlq_n_u8(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4s plogical_shift_left(Packet4s a) { return vshl_n_s16(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet8s plogical_shift_left(Packet8s a) { return vshlq_n_s16(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4us plogical_shift_left(Packet4us a) { return vshl_n_u16(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet8us plogical_shift_left(Packet8us a) { return vshlq_n_u16(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet2i plogical_shift_left(Packet2i a) { return vshl_n_s32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4i plogical_shift_left(Packet4i a) { return vshlq_n_s32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet2ui plogical_shift_left(Packet2ui a) { return vshl_n_u32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4ui plogical_shift_left(Packet4ui a) { return vshlq_n_u32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet2l plogical_shift_left(Packet2l a) { return vshlq_n_s64(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet2ul plogical_shift_left(Packet2ul a) { return vshlq_n_u64(a,N); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pload<Packet2f>(const float* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1_f32(from); }
+template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_f32(from); }
+template<> EIGEN_STRONG_INLINE Packet4c pload<Packet4c>(const int8_t* from)
+{
+ Packet4c res;
+ memcpy(static_cast<void*>(&res), from, sizeof(Packet4c));
+ return res;
+}
+template<> EIGEN_STRONG_INLINE Packet8c pload<Packet8c>(const int8_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1_s8(from); }
+template<> EIGEN_STRONG_INLINE Packet16c pload<Packet16c>(const int8_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_s8(from); }
+template<> EIGEN_STRONG_INLINE Packet4uc pload<Packet4uc>(const uint8_t* from)
+{
+ Packet4uc res;
+ memcpy(static_cast<void*>(&res), from, sizeof(Packet4c));
+ return res;
+}
+template<> EIGEN_STRONG_INLINE Packet8uc pload<Packet8uc>(const uint8_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1_u8(from); }
+template<> EIGEN_STRONG_INLINE Packet16uc pload<Packet16uc>(const uint8_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_u8(from); }
+template<> EIGEN_STRONG_INLINE Packet4s pload<Packet4s>(const int16_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1_s16(from); }
+template<> EIGEN_STRONG_INLINE Packet8s pload<Packet8s>(const int16_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_s16(from); }
+template<> EIGEN_STRONG_INLINE Packet4us pload<Packet4us>(const uint16_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1_u16(from); }
+template<> EIGEN_STRONG_INLINE Packet8us pload<Packet8us>(const uint16_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_u16(from); }
+template<> EIGEN_STRONG_INLINE Packet2i pload<Packet2i>(const int32_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1_s32(from); }
+template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int32_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_s32(from); }
+template<> EIGEN_STRONG_INLINE Packet2ui pload<Packet2ui>(const uint32_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1_u32(from); }
+template<> EIGEN_STRONG_INLINE Packet4ui pload<Packet4ui>(const uint32_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_u32(from); }
+template<> EIGEN_STRONG_INLINE Packet2l pload<Packet2l>(const int64_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_s64(from); }
+template<> EIGEN_STRONG_INLINE Packet2ul pload<Packet2ul>(const uint64_t* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_u64(from); }
+
+template<> EIGEN_STRONG_INLINE Packet2f ploadu<Packet2f>(const float* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1_f32(from); }
+template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_f32(from); }
+template<> EIGEN_STRONG_INLINE Packet4c ploadu<Packet4c>(const int8_t* from)
+{
+ Packet4c res;
+ memcpy(static_cast<void*>(&res), from, sizeof(Packet4c));
+ return res;
+}
+template<> EIGEN_STRONG_INLINE Packet8c ploadu<Packet8c>(const int8_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1_s8(from); }
+template<> EIGEN_STRONG_INLINE Packet16c ploadu<Packet16c>(const int8_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_s8(from); }
+template<> EIGEN_STRONG_INLINE Packet4uc ploadu<Packet4uc>(const uint8_t* from)
+{
+ Packet4uc res;
+ memcpy(static_cast<void*>(&res), from, sizeof(Packet4c));
+ return res;
+}
+template<> EIGEN_STRONG_INLINE Packet8uc ploadu<Packet8uc>(const uint8_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1_u8(from); }
+template<> EIGEN_STRONG_INLINE Packet16uc ploadu<Packet16uc>(const uint8_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_u8(from); }
+template<> EIGEN_STRONG_INLINE Packet4s ploadu<Packet4s>(const int16_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1_s16(from); }
+template<> EIGEN_STRONG_INLINE Packet8s ploadu<Packet8s>(const int16_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_s16(from); }
+template<> EIGEN_STRONG_INLINE Packet4us ploadu<Packet4us>(const uint16_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1_u16(from); }
+template<> EIGEN_STRONG_INLINE Packet8us ploadu<Packet8us>(const uint16_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_u16(from); }
+template<> EIGEN_STRONG_INLINE Packet2i ploadu<Packet2i>(const int32_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1_s32(from); }
+template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int32_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_s32(from); }
+template<> EIGEN_STRONG_INLINE Packet2ui ploadu<Packet2ui>(const uint32_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1_u32(from); }
+template<> EIGEN_STRONG_INLINE Packet4ui ploadu<Packet4ui>(const uint32_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_u32(from); }
+template<> EIGEN_STRONG_INLINE Packet2l ploadu<Packet2l>(const int64_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_s64(from); }
+template<> EIGEN_STRONG_INLINE Packet2ul ploadu<Packet2ul>(const uint64_t* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_u64(from); }
+
+template<> EIGEN_STRONG_INLINE Packet2f ploaddup<Packet2f>(const float* from)
+{ return vld1_dup_f32(from); }
+template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from)
+{ return vcombine_f32(vld1_dup_f32(from), vld1_dup_f32(from+1)); }
+template<> EIGEN_STRONG_INLINE Packet4c ploaddup<Packet4c>(const int8_t* from)
+{
+ const int8x8_t a = vreinterpret_s8_s32(vdup_n_s32(pload<Packet4c>(from)));
+ return vget_lane_s32(vreinterpret_s32_s8(vzip_s8(a,a).val[0]), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8c ploaddup<Packet8c>(const int8_t* from)
+{
+ const int8x8_t a = vld1_s8(from);
+ return vzip_s8(a,a).val[0];
+}
+template<> EIGEN_STRONG_INLINE Packet16c ploaddup<Packet16c>(const int8_t* from)
+{
+ const int8x8_t a = vld1_s8(from);
+ const int8x8x2_t b = vzip_s8(a,a);
+ return vcombine_s8(b.val[0], b.val[1]);
+}
+template<> EIGEN_STRONG_INLINE Packet4uc ploaddup<Packet4uc>(const uint8_t* from)
+{
+ const uint8x8_t a = vreinterpret_u8_u32(vdup_n_u32(pload<Packet4uc>(from)));
+ return vget_lane_u32(vreinterpret_u32_u8(vzip_u8(a,a).val[0]), 0);
+}
+template<> EIGEN_STRONG_INLINE Packet8uc ploaddup<Packet8uc>(const uint8_t* from)
+{
+ const uint8x8_t a = vld1_u8(from);
+ return vzip_u8(a,a).val[0];
+}
+template<> EIGEN_STRONG_INLINE Packet16uc ploaddup<Packet16uc>(const uint8_t* from)
+{
+ const uint8x8_t a = vld1_u8(from);
+ const uint8x8x2_t b = vzip_u8(a,a);
+ return vcombine_u8(b.val[0], b.val[1]);
+}
+template<> EIGEN_STRONG_INLINE Packet4s ploaddup<Packet4s>(const int16_t* from)
+{
+ return vreinterpret_s16_u32(vzip_u32(vreinterpret_u32_s16(vld1_dup_s16(from)),
+ vreinterpret_u32_s16(vld1_dup_s16(from+1))).val[0]);
+}
+template<> EIGEN_STRONG_INLINE Packet8s ploaddup<Packet8s>(const int16_t* from)
+{
+ const int16x4_t a = vld1_s16(from);
+ const int16x4x2_t b = vzip_s16(a,a);
+ return vcombine_s16(b.val[0], b.val[1]);
+}
+template<> EIGEN_STRONG_INLINE Packet4us ploaddup<Packet4us>(const uint16_t* from)
+{
+ return vreinterpret_u16_u32(vzip_u32(vreinterpret_u32_u16(vld1_dup_u16(from)),
+ vreinterpret_u32_u16(vld1_dup_u16(from+1))).val[0]);
+}
+template<> EIGEN_STRONG_INLINE Packet8us ploaddup<Packet8us>(const uint16_t* from)
+{
+ const uint16x4_t a = vld1_u16(from);
+ const uint16x4x2_t b = vzip_u16(a,a);
+ return vcombine_u16(b.val[0], b.val[1]);
+}
+template<> EIGEN_STRONG_INLINE Packet2i ploaddup<Packet2i>(const int32_t* from)
+{ return vld1_dup_s32(from); }
+template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int32_t* from)
+{ return vcombine_s32(vld1_dup_s32(from), vld1_dup_s32(from+1)); }
+template<> EIGEN_STRONG_INLINE Packet2ui ploaddup<Packet2ui>(const uint32_t* from)
+{ return vld1_dup_u32(from); }
+template<> EIGEN_STRONG_INLINE Packet4ui ploaddup<Packet4ui>(const uint32_t* from)
+{ return vcombine_u32(vld1_dup_u32(from), vld1_dup_u32(from+1)); }
+template<> EIGEN_STRONG_INLINE Packet2l ploaddup<Packet2l>(const int64_t* from)
+{ return vld1q_dup_s64(from); }
+template<> EIGEN_STRONG_INLINE Packet2ul ploaddup<Packet2ul>(const uint64_t* from)
+{ return vld1q_dup_u64(from); }
+
+template<> EIGEN_STRONG_INLINE Packet4f ploadquad<Packet4f>(const float* from) { return vld1q_dup_f32(from); }
+template<> EIGEN_STRONG_INLINE Packet4c ploadquad<Packet4c>(const int8_t* from)
+{ return vget_lane_s32(vreinterpret_s32_s8(vld1_dup_s8(from)), 0); }
+template<> EIGEN_STRONG_INLINE Packet8c ploadquad<Packet8c>(const int8_t* from)
+{
+ return vreinterpret_s8_u32(vzip_u32(
+ vreinterpret_u32_s8(vld1_dup_s8(from)),
+ vreinterpret_u32_s8(vld1_dup_s8(from+1))).val[0]);
+}
+template<> EIGEN_STRONG_INLINE Packet16c ploadquad<Packet16c>(const int8_t* from)
+{
+ const int8x8_t a = vreinterpret_s8_u32(vzip_u32(
+ vreinterpret_u32_s8(vld1_dup_s8(from)),
+ vreinterpret_u32_s8(vld1_dup_s8(from+1))).val[0]);
+ const int8x8_t b = vreinterpret_s8_u32(vzip_u32(
+ vreinterpret_u32_s8(vld1_dup_s8(from+2)),
+ vreinterpret_u32_s8(vld1_dup_s8(from+3))).val[0]);
+ return vcombine_s8(a,b);
+}
+template<> EIGEN_STRONG_INLINE Packet4uc ploadquad<Packet4uc>(const uint8_t* from)
+{ return vget_lane_u32(vreinterpret_u32_u8(vld1_dup_u8(from)), 0); }
+template<> EIGEN_STRONG_INLINE Packet8uc ploadquad<Packet8uc>(const uint8_t* from)
+{
+ return vreinterpret_u8_u32(vzip_u32(
+ vreinterpret_u32_u8(vld1_dup_u8(from)),
+ vreinterpret_u32_u8(vld1_dup_u8(from+1))).val[0]);
+}
+template<> EIGEN_STRONG_INLINE Packet16uc ploadquad<Packet16uc>(const uint8_t* from)
+{
+ const uint8x8_t a = vreinterpret_u8_u32(vzip_u32(
+ vreinterpret_u32_u8(vld1_dup_u8(from)),
+ vreinterpret_u32_u8(vld1_dup_u8(from+1))).val[0]);
+ const uint8x8_t b = vreinterpret_u8_u32(vzip_u32(
+ vreinterpret_u32_u8(vld1_dup_u8(from+2)),
+ vreinterpret_u32_u8(vld1_dup_u8(from+3))).val[0]);
+ return vcombine_u8(a,b);
+}
+template<> EIGEN_STRONG_INLINE Packet8s ploadquad<Packet8s>(const int16_t* from)
+{ return vcombine_s16(vld1_dup_s16(from), vld1_dup_s16(from+1)); }
+template<> EIGEN_STRONG_INLINE Packet8us ploadquad<Packet8us>(const uint16_t* from)
+{ return vcombine_u16(vld1_dup_u16(from), vld1_dup_u16(from+1)); }
+template<> EIGEN_STRONG_INLINE Packet4i ploadquad<Packet4i>(const int32_t* from) { return vld1q_dup_s32(from); }
+template<> EIGEN_STRONG_INLINE Packet4ui ploadquad<Packet4ui>(const uint32_t* from) { return vld1q_dup_u32(from); }
+
+template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet2f& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1_f32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1q_f32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<int8_t>(int8_t* to, const Packet4c& from)
+{ memcpy(to, &from, sizeof(from)); }
+template<> EIGEN_STRONG_INLINE void pstore<int8_t>(int8_t* to, const Packet8c& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1_s8(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<int8_t>(int8_t* to, const Packet16c& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1q_s8(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<uint8_t>(uint8_t* to, const Packet4uc& from)
+{ memcpy(to, &from, sizeof(from)); }
+template<> EIGEN_STRONG_INLINE void pstore<uint8_t>(uint8_t* to, const Packet8uc& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1_u8(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<uint8_t>(uint8_t* to, const Packet16uc& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1q_u8(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<int16_t>(int16_t* to, const Packet4s& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1_s16(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<int16_t>(int16_t* to, const Packet8s& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1q_s16(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<uint16_t>(uint16_t* to, const Packet4us& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1_u16(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<uint16_t>(uint16_t* to, const Packet8us& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1q_u16(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<int32_t>(int32_t* to, const Packet2i& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1_s32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<int32_t>(int32_t* to, const Packet4i& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1q_s32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<uint32_t>(uint32_t* to, const Packet2ui& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1_u32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<uint32_t>(uint32_t* to, const Packet4ui& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1q_u32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<int64_t>(int64_t* to, const Packet2l& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1q_s64(to,from); }
+template<> EIGEN_STRONG_INLINE void pstore<uint64_t>(uint64_t* to, const Packet2ul& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1q_u64(to,from); }
+
+template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet2f& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1_f32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_f32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<int8_t>(int8_t* to, const Packet4c& from)
+{ memcpy(to, &from, sizeof(from)); }
+template<> EIGEN_STRONG_INLINE void pstoreu<int8_t>(int8_t* to, const Packet8c& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1_s8(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<int8_t>(int8_t* to, const Packet16c& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_s8(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<uint8_t>(uint8_t* to, const Packet4uc& from)
+{ memcpy(to, &from, sizeof(from)); }
+template<> EIGEN_STRONG_INLINE void pstoreu<uint8_t>(uint8_t* to, const Packet8uc& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1_u8(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<uint8_t>(uint8_t* to, const Packet16uc& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_u8(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<int16_t>(int16_t* to, const Packet4s& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1_s16(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<int16_t>(int16_t* to, const Packet8s& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_s16(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<uint16_t>(uint16_t* to, const Packet4us& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1_u16(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<uint16_t>(uint16_t* to, const Packet8us& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_u16(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<int32_t>(int32_t* to, const Packet2i& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1_s32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<int32_t>(int32_t* to, const Packet4i& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_s32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<uint32_t>(uint32_t* to, const Packet2ui& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1_u32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<uint32_t>(uint32_t* to, const Packet4ui& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_u32(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<int64_t>(int64_t* to, const Packet2l& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_s64(to,from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<uint64_t>(uint64_t* to, const Packet2ul& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_u64(to,from); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2f pgather<float, Packet2f>(const float* from, Index stride)
+{
+ Packet2f res = vld1_dup_f32(from);
+ res = vld1_lane_f32(from + 1*stride, res, 1);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4f pgather<float, Packet4f>(const float* from, Index stride)
+{
+ Packet4f res = vld1q_dup_f32(from);
+ res = vld1q_lane_f32(from + 1*stride, res, 1);
+ res = vld1q_lane_f32(from + 2*stride, res, 2);
+ res = vld1q_lane_f32(from + 3*stride, res, 3);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4c pgather<int8_t, Packet4c>(const int8_t* from, Index stride)
+{
+ Packet4c res;
+ for (int i = 0; i != 4; i++)
+ reinterpret_cast<int8_t*>(&res)[i] = *(from + i * stride);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8c pgather<int8_t, Packet8c>(const int8_t* from, Index stride)
+{
+ Packet8c res = vld1_dup_s8(from);
+ res = vld1_lane_s8(from + 1*stride, res, 1);
+ res = vld1_lane_s8(from + 2*stride, res, 2);
+ res = vld1_lane_s8(from + 3*stride, res, 3);
+ res = vld1_lane_s8(from + 4*stride, res, 4);
+ res = vld1_lane_s8(from + 5*stride, res, 5);
+ res = vld1_lane_s8(from + 6*stride, res, 6);
+ res = vld1_lane_s8(from + 7*stride, res, 7);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet16c pgather<int8_t, Packet16c>(const int8_t* from, Index stride)
+{
+ Packet16c res = vld1q_dup_s8(from);
+ res = vld1q_lane_s8(from + 1*stride, res, 1);
+ res = vld1q_lane_s8(from + 2*stride, res, 2);
+ res = vld1q_lane_s8(from + 3*stride, res, 3);
+ res = vld1q_lane_s8(from + 4*stride, res, 4);
+ res = vld1q_lane_s8(from + 5*stride, res, 5);
+ res = vld1q_lane_s8(from + 6*stride, res, 6);
+ res = vld1q_lane_s8(from + 7*stride, res, 7);
+ res = vld1q_lane_s8(from + 8*stride, res, 8);
+ res = vld1q_lane_s8(from + 9*stride, res, 9);
+ res = vld1q_lane_s8(from + 10*stride, res, 10);
+ res = vld1q_lane_s8(from + 11*stride, res, 11);
+ res = vld1q_lane_s8(from + 12*stride, res, 12);
+ res = vld1q_lane_s8(from + 13*stride, res, 13);
+ res = vld1q_lane_s8(from + 14*stride, res, 14);
+ res = vld1q_lane_s8(from + 15*stride, res, 15);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4uc pgather<uint8_t, Packet4uc>(const uint8_t* from, Index stride)
+{
+ Packet4uc res;
+ for (int i = 0; i != 4; i++)
+ reinterpret_cast<uint8_t*>(&res)[i] = *(from + i * stride);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8uc pgather<uint8_t, Packet8uc>(const uint8_t* from, Index stride)
+{
+ Packet8uc res = vld1_dup_u8(from);
+ res = vld1_lane_u8(from + 1*stride, res, 1);
+ res = vld1_lane_u8(from + 2*stride, res, 2);
+ res = vld1_lane_u8(from + 3*stride, res, 3);
+ res = vld1_lane_u8(from + 4*stride, res, 4);
+ res = vld1_lane_u8(from + 5*stride, res, 5);
+ res = vld1_lane_u8(from + 6*stride, res, 6);
+ res = vld1_lane_u8(from + 7*stride, res, 7);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet16uc pgather<uint8_t, Packet16uc>(const uint8_t* from, Index stride)
+{
+ Packet16uc res = vld1q_dup_u8(from);
+ res = vld1q_lane_u8(from + 1*stride, res, 1);
+ res = vld1q_lane_u8(from + 2*stride, res, 2);
+ res = vld1q_lane_u8(from + 3*stride, res, 3);
+ res = vld1q_lane_u8(from + 4*stride, res, 4);
+ res = vld1q_lane_u8(from + 5*stride, res, 5);
+ res = vld1q_lane_u8(from + 6*stride, res, 6);
+ res = vld1q_lane_u8(from + 7*stride, res, 7);
+ res = vld1q_lane_u8(from + 8*stride, res, 8);
+ res = vld1q_lane_u8(from + 9*stride, res, 9);
+ res = vld1q_lane_u8(from + 10*stride, res, 10);
+ res = vld1q_lane_u8(from + 11*stride, res, 11);
+ res = vld1q_lane_u8(from + 12*stride, res, 12);
+ res = vld1q_lane_u8(from + 13*stride, res, 13);
+ res = vld1q_lane_u8(from + 14*stride, res, 14);
+ res = vld1q_lane_u8(from + 15*stride, res, 15);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4s pgather<int16_t, Packet4s>(const int16_t* from, Index stride)
+{
+ Packet4s res = vld1_dup_s16(from);
+ res = vld1_lane_s16(from + 1*stride, res, 1);
+ res = vld1_lane_s16(from + 2*stride, res, 2);
+ res = vld1_lane_s16(from + 3*stride, res, 3);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8s pgather<int16_t, Packet8s>(const int16_t* from, Index stride)
+{
+ Packet8s res = vld1q_dup_s16(from);
+ res = vld1q_lane_s16(from + 1*stride, res, 1);
+ res = vld1q_lane_s16(from + 2*stride, res, 2);
+ res = vld1q_lane_s16(from + 3*stride, res, 3);
+ res = vld1q_lane_s16(from + 4*stride, res, 4);
+ res = vld1q_lane_s16(from + 5*stride, res, 5);
+ res = vld1q_lane_s16(from + 6*stride, res, 6);
+ res = vld1q_lane_s16(from + 7*stride, res, 7);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4us pgather<uint16_t, Packet4us>(const uint16_t* from, Index stride)
+{
+ Packet4us res = vld1_dup_u16(from);
+ res = vld1_lane_u16(from + 1*stride, res, 1);
+ res = vld1_lane_u16(from + 2*stride, res, 2);
+ res = vld1_lane_u16(from + 3*stride, res, 3);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8us pgather<uint16_t, Packet8us>(const uint16_t* from, Index stride)
+{
+ Packet8us res = vld1q_dup_u16(from);
+ res = vld1q_lane_u16(from + 1*stride, res, 1);
+ res = vld1q_lane_u16(from + 2*stride, res, 2);
+ res = vld1q_lane_u16(from + 3*stride, res, 3);
+ res = vld1q_lane_u16(from + 4*stride, res, 4);
+ res = vld1q_lane_u16(from + 5*stride, res, 5);
+ res = vld1q_lane_u16(from + 6*stride, res, 6);
+ res = vld1q_lane_u16(from + 7*stride, res, 7);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2i pgather<int32_t, Packet2i>(const int32_t* from, Index stride)
+{
+ Packet2i res = vld1_dup_s32(from);
+ res = vld1_lane_s32(from + 1*stride, res, 1);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4i pgather<int32_t, Packet4i>(const int32_t* from, Index stride)
+{
+ Packet4i res = vld1q_dup_s32(from);
+ res = vld1q_lane_s32(from + 1*stride, res, 1);
+ res = vld1q_lane_s32(from + 2*stride, res, 2);
+ res = vld1q_lane_s32(from + 3*stride, res, 3);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2ui pgather<uint32_t, Packet2ui>(const uint32_t* from, Index stride)
+{
+ Packet2ui res = vld1_dup_u32(from);
+ res = vld1_lane_u32(from + 1*stride, res, 1);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4ui pgather<uint32_t, Packet4ui>(const uint32_t* from, Index stride)
+{
+ Packet4ui res = vld1q_dup_u32(from);
+ res = vld1q_lane_u32(from + 1*stride, res, 1);
+ res = vld1q_lane_u32(from + 2*stride, res, 2);
+ res = vld1q_lane_u32(from + 3*stride, res, 3);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2l pgather<int64_t, Packet2l>(const int64_t* from, Index stride)
+{
+ Packet2l res = vld1q_dup_s64(from);
+ res = vld1q_lane_s64(from + 1*stride, res, 1);
+ return res;
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2ul pgather<uint64_t, Packet2ul>(const uint64_t* from, Index stride)
+{
+ Packet2ul res = vld1q_dup_u64(from);
+ res = vld1q_lane_u64(from + 1*stride, res, 1);
+ return res;
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<float, Packet2f>(float* to, const Packet2f& from, Index stride)
+{
+ vst1_lane_f32(to + stride*0, from, 0);
+ vst1_lane_f32(to + stride*1, from, 1);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride)
+{
+ vst1q_lane_f32(to + stride*0, from, 0);
+ vst1q_lane_f32(to + stride*1, from, 1);
+ vst1q_lane_f32(to + stride*2, from, 2);
+ vst1q_lane_f32(to + stride*3, from, 3);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int8_t, Packet4c>(int8_t* to, const Packet4c& from, Index stride)
+{
+ for (int i = 0; i != 4; i++)
+ *(to + i * stride) = reinterpret_cast<const int8_t*>(&from)[i];
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int8_t, Packet8c>(int8_t* to, const Packet8c& from, Index stride)
+{
+ vst1_lane_s8(to + stride*0, from, 0);
+ vst1_lane_s8(to + stride*1, from, 1);
+ vst1_lane_s8(to + stride*2, from, 2);
+ vst1_lane_s8(to + stride*3, from, 3);
+ vst1_lane_s8(to + stride*4, from, 4);
+ vst1_lane_s8(to + stride*5, from, 5);
+ vst1_lane_s8(to + stride*6, from, 6);
+ vst1_lane_s8(to + stride*7, from, 7);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int8_t, Packet16c>(int8_t* to, const Packet16c& from, Index stride)
+{
+ vst1q_lane_s8(to + stride*0, from, 0);
+ vst1q_lane_s8(to + stride*1, from, 1);
+ vst1q_lane_s8(to + stride*2, from, 2);
+ vst1q_lane_s8(to + stride*3, from, 3);
+ vst1q_lane_s8(to + stride*4, from, 4);
+ vst1q_lane_s8(to + stride*5, from, 5);
+ vst1q_lane_s8(to + stride*6, from, 6);
+ vst1q_lane_s8(to + stride*7, from, 7);
+ vst1q_lane_s8(to + stride*8, from, 8);
+ vst1q_lane_s8(to + stride*9, from, 9);
+ vst1q_lane_s8(to + stride*10, from, 10);
+ vst1q_lane_s8(to + stride*11, from, 11);
+ vst1q_lane_s8(to + stride*12, from, 12);
+ vst1q_lane_s8(to + stride*13, from, 13);
+ vst1q_lane_s8(to + stride*14, from, 14);
+ vst1q_lane_s8(to + stride*15, from, 15);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint8_t, Packet4uc>(uint8_t* to, const Packet4uc& from, Index stride)
+{
+ for (int i = 0; i != 4; i++)
+ *(to + i * stride) = reinterpret_cast<const uint8_t*>(&from)[i];
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint8_t, Packet8uc>(uint8_t* to, const Packet8uc& from, Index stride)
+{
+ vst1_lane_u8(to + stride*0, from, 0);
+ vst1_lane_u8(to + stride*1, from, 1);
+ vst1_lane_u8(to + stride*2, from, 2);
+ vst1_lane_u8(to + stride*3, from, 3);
+ vst1_lane_u8(to + stride*4, from, 4);
+ vst1_lane_u8(to + stride*5, from, 5);
+ vst1_lane_u8(to + stride*6, from, 6);
+ vst1_lane_u8(to + stride*7, from, 7);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint8_t, Packet16uc>(uint8_t* to, const Packet16uc& from, Index stride)
+{
+ vst1q_lane_u8(to + stride*0, from, 0);
+ vst1q_lane_u8(to + stride*1, from, 1);
+ vst1q_lane_u8(to + stride*2, from, 2);
+ vst1q_lane_u8(to + stride*3, from, 3);
+ vst1q_lane_u8(to + stride*4, from, 4);
+ vst1q_lane_u8(to + stride*5, from, 5);
+ vst1q_lane_u8(to + stride*6, from, 6);
+ vst1q_lane_u8(to + stride*7, from, 7);
+ vst1q_lane_u8(to + stride*8, from, 8);
+ vst1q_lane_u8(to + stride*9, from, 9);
+ vst1q_lane_u8(to + stride*10, from, 10);
+ vst1q_lane_u8(to + stride*11, from, 11);
+ vst1q_lane_u8(to + stride*12, from, 12);
+ vst1q_lane_u8(to + stride*13, from, 13);
+ vst1q_lane_u8(to + stride*14, from, 14);
+ vst1q_lane_u8(to + stride*15, from, 15);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int16_t, Packet4s>(int16_t* to, const Packet4s& from, Index stride)
+{
+ vst1_lane_s16(to + stride*0, from, 0);
+ vst1_lane_s16(to + stride*1, from, 1);
+ vst1_lane_s16(to + stride*2, from, 2);
+ vst1_lane_s16(to + stride*3, from, 3);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int16_t, Packet8s>(int16_t* to, const Packet8s& from, Index stride)
+{
+ vst1q_lane_s16(to + stride*0, from, 0);
+ vst1q_lane_s16(to + stride*1, from, 1);
+ vst1q_lane_s16(to + stride*2, from, 2);
+ vst1q_lane_s16(to + stride*3, from, 3);
+ vst1q_lane_s16(to + stride*4, from, 4);
+ vst1q_lane_s16(to + stride*5, from, 5);
+ vst1q_lane_s16(to + stride*6, from, 6);
+ vst1q_lane_s16(to + stride*7, from, 7);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint16_t, Packet4us>(uint16_t* to, const Packet4us& from, Index stride)
+{
+ vst1_lane_u16(to + stride*0, from, 0);
+ vst1_lane_u16(to + stride*1, from, 1);
+ vst1_lane_u16(to + stride*2, from, 2);
+ vst1_lane_u16(to + stride*3, from, 3);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint16_t, Packet8us>(uint16_t* to, const Packet8us& from, Index stride)
+{
+ vst1q_lane_u16(to + stride*0, from, 0);
+ vst1q_lane_u16(to + stride*1, from, 1);
+ vst1q_lane_u16(to + stride*2, from, 2);
+ vst1q_lane_u16(to + stride*3, from, 3);
+ vst1q_lane_u16(to + stride*4, from, 4);
+ vst1q_lane_u16(to + stride*5, from, 5);
+ vst1q_lane_u16(to + stride*6, from, 6);
+ vst1q_lane_u16(to + stride*7, from, 7);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int32_t, Packet2i>(int32_t* to, const Packet2i& from, Index stride)
+{
+ vst1_lane_s32(to + stride*0, from, 0);
+ vst1_lane_s32(to + stride*1, from, 1);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int32_t, Packet4i>(int32_t* to, const Packet4i& from, Index stride)
+{
+ vst1q_lane_s32(to + stride*0, from, 0);
+ vst1q_lane_s32(to + stride*1, from, 1);
+ vst1q_lane_s32(to + stride*2, from, 2);
+ vst1q_lane_s32(to + stride*3, from, 3);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint32_t, Packet2ui>(uint32_t* to, const Packet2ui& from, Index stride)
+{
+ vst1_lane_u32(to + stride*0, from, 0);
+ vst1_lane_u32(to + stride*1, from, 1);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint32_t, Packet4ui>(uint32_t* to, const Packet4ui& from, Index stride)
+{
+ vst1q_lane_u32(to + stride*0, from, 0);
+ vst1q_lane_u32(to + stride*1, from, 1);
+ vst1q_lane_u32(to + stride*2, from, 2);
+ vst1q_lane_u32(to + stride*3, from, 3);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<int64_t, Packet2l>(int64_t* to, const Packet2l& from, Index stride)
+{
+ vst1q_lane_s64(to + stride*0, from, 0);
+ vst1q_lane_s64(to + stride*1, from, 1);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<uint64_t, Packet2ul>(uint64_t* to, const Packet2ul& from, Index stride)
+{
+ vst1q_lane_u64(to + stride*0, from, 0);
+ vst1q_lane_u64(to + stride*1, from, 1);
+}
+
+template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { EIGEN_ARM_PREFETCH(addr); }
+template<> EIGEN_STRONG_INLINE void prefetch<int8_t>(const int8_t* addr) { EIGEN_ARM_PREFETCH(addr); }
+template<> EIGEN_STRONG_INLINE void prefetch<uint8_t>(const uint8_t* addr) { EIGEN_ARM_PREFETCH(addr); }
+template<> EIGEN_STRONG_INLINE void prefetch<int16_t>(const int16_t* addr) { EIGEN_ARM_PREFETCH(addr); }
+template<> EIGEN_STRONG_INLINE void prefetch<uint16_t>(const uint16_t* addr) { EIGEN_ARM_PREFETCH(addr); }
+template<> EIGEN_STRONG_INLINE void prefetch<int32_t>(const int32_t* addr) { EIGEN_ARM_PREFETCH(addr); }
+template<> EIGEN_STRONG_INLINE void prefetch<uint32_t>(const uint32_t* addr) { EIGEN_ARM_PREFETCH(addr); }
+template<> EIGEN_STRONG_INLINE void prefetch<int64_t>(const int64_t* addr) { EIGEN_ARM_PREFETCH(addr); }
+template<> EIGEN_STRONG_INLINE void prefetch<uint64_t>(const uint64_t* addr) { EIGEN_ARM_PREFETCH(addr); }
+
+template<> EIGEN_STRONG_INLINE float pfirst<Packet2f>(const Packet2f& a) { return vget_lane_f32(a,0); }
+template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { return vgetq_lane_f32(a,0); }
+template<> EIGEN_STRONG_INLINE int8_t pfirst<Packet4c>(const Packet4c& a) { return static_cast<int8_t>(a & 0xff); }
+template<> EIGEN_STRONG_INLINE int8_t pfirst<Packet8c>(const Packet8c& a) { return vget_lane_s8(a,0); }
+template<> EIGEN_STRONG_INLINE int8_t pfirst<Packet16c>(const Packet16c& a) { return vgetq_lane_s8(a,0); }
+template<> EIGEN_STRONG_INLINE uint8_t pfirst<Packet4uc>(const Packet4uc& a) { return static_cast<uint8_t>(a & 0xff); }
+template<> EIGEN_STRONG_INLINE uint8_t pfirst<Packet8uc>(const Packet8uc& a) { return vget_lane_u8(a,0); }
+template<> EIGEN_STRONG_INLINE uint8_t pfirst<Packet16uc>(const Packet16uc& a) { return vgetq_lane_u8(a,0); }
+template<> EIGEN_STRONG_INLINE int16_t pfirst<Packet4s>(const Packet4s& a) { return vget_lane_s16(a,0); }
+template<> EIGEN_STRONG_INLINE int16_t pfirst<Packet8s>(const Packet8s& a) { return vgetq_lane_s16(a,0); }
+template<> EIGEN_STRONG_INLINE uint16_t pfirst<Packet4us>(const Packet4us& a) { return vget_lane_u16(a,0); }
+template<> EIGEN_STRONG_INLINE uint16_t pfirst<Packet8us>(const Packet8us& a) { return vgetq_lane_u16(a,0); }
+template<> EIGEN_STRONG_INLINE int32_t pfirst<Packet2i>(const Packet2i& a) { return vget_lane_s32(a,0); }
+template<> EIGEN_STRONG_INLINE int32_t pfirst<Packet4i>(const Packet4i& a) { return vgetq_lane_s32(a,0); }
+template<> EIGEN_STRONG_INLINE uint32_t pfirst<Packet2ui>(const Packet2ui& a) { return vget_lane_u32(a,0); }
+template<> EIGEN_STRONG_INLINE uint32_t pfirst<Packet4ui>(const Packet4ui& a) { return vgetq_lane_u32(a,0); }
+template<> EIGEN_STRONG_INLINE int64_t pfirst<Packet2l>(const Packet2l& a) { return vgetq_lane_s64(a,0); }
+template<> EIGEN_STRONG_INLINE uint64_t pfirst<Packet2ul>(const Packet2ul& a) { return vgetq_lane_u64(a,0); }
+
+template<> EIGEN_STRONG_INLINE Packet2f preverse(const Packet2f& a) { return vrev64_f32(a); }
+template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a)
+{
+ const float32x4_t a_r64 = vrev64q_f32(a);
+ return vcombine_f32(vget_high_f32(a_r64), vget_low_f32(a_r64));
+}
+template<> EIGEN_STRONG_INLINE Packet4c preverse(const Packet4c& a)
+{ return vget_lane_s32(vreinterpret_s32_s8(vrev64_s8(vreinterpret_s8_s32(vdup_n_s32(a)))), 0); }
+template<> EIGEN_STRONG_INLINE Packet8c preverse(const Packet8c& a) { return vrev64_s8(a); }
+template<> EIGEN_STRONG_INLINE Packet16c preverse(const Packet16c& a)
+{
+ const int8x16_t a_r64 = vrev64q_s8(a);
+ return vcombine_s8(vget_high_s8(a_r64), vget_low_s8(a_r64));
+}
+template<> EIGEN_STRONG_INLINE Packet4uc preverse(const Packet4uc& a)
+{ return vget_lane_u32(vreinterpret_u32_u8(vrev64_u8(vreinterpret_u8_u32(vdup_n_u32(a)))), 0); }
+template<> EIGEN_STRONG_INLINE Packet8uc preverse(const Packet8uc& a) { return vrev64_u8(a); }
+template<> EIGEN_STRONG_INLINE Packet16uc preverse(const Packet16uc& a)
+{
+ const uint8x16_t a_r64 = vrev64q_u8(a);
+ return vcombine_u8(vget_high_u8(a_r64), vget_low_u8(a_r64));
+}
+template<> EIGEN_STRONG_INLINE Packet4s preverse(const Packet4s& a) { return vrev64_s16(a); }
+template<> EIGEN_STRONG_INLINE Packet8s preverse(const Packet8s& a)
+{
+ const int16x8_t a_r64 = vrev64q_s16(a);
+ return vcombine_s16(vget_high_s16(a_r64), vget_low_s16(a_r64));
+}
+template<> EIGEN_STRONG_INLINE Packet4us preverse(const Packet4us& a) { return vrev64_u16(a); }
+template<> EIGEN_STRONG_INLINE Packet8us preverse(const Packet8us& a)
+{
+ const uint16x8_t a_r64 = vrev64q_u16(a);
+ return vcombine_u16(vget_high_u16(a_r64), vget_low_u16(a_r64));
+}
+template<> EIGEN_STRONG_INLINE Packet2i preverse(const Packet2i& a) { return vrev64_s32(a); }
+template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a)
+{
+ const int32x4_t a_r64 = vrev64q_s32(a);
+ return vcombine_s32(vget_high_s32(a_r64), vget_low_s32(a_r64));
+}
+template<> EIGEN_STRONG_INLINE Packet2ui preverse(const Packet2ui& a) { return vrev64_u32(a); }
+template<> EIGEN_STRONG_INLINE Packet4ui preverse(const Packet4ui& a)
+{
+ const uint32x4_t a_r64 = vrev64q_u32(a);
+ return vcombine_u32(vget_high_u32(a_r64), vget_low_u32(a_r64));
+}
+template<> EIGEN_STRONG_INLINE Packet2l preverse(const Packet2l& a)
+{ return vcombine_s64(vget_high_s64(a), vget_low_s64(a)); }
+template<> EIGEN_STRONG_INLINE Packet2ul preverse(const Packet2ul& a)
+{ return vcombine_u64(vget_high_u64(a), vget_low_u64(a)); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pabs(const Packet2f& a) { return vabs_f32(a); }
+template<> EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a) { return vabsq_f32(a); }
+template<> EIGEN_STRONG_INLINE Packet4c pabs<Packet4c>(const Packet4c& a)
+{ return vget_lane_s32(vreinterpret_s32_s8(vabs_s8(vreinterpret_s8_s32(vdup_n_s32(a)))), 0); }
+template<> EIGEN_STRONG_INLINE Packet8c pabs(const Packet8c& a) { return vabs_s8(a); }
+template<> EIGEN_STRONG_INLINE Packet16c pabs(const Packet16c& a) { return vabsq_s8(a); }
+template<> EIGEN_STRONG_INLINE Packet4uc pabs(const Packet4uc& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet8uc pabs(const Packet8uc& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet16uc pabs(const Packet16uc& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4s pabs(const Packet4s& a) { return vabs_s16(a); }
+template<> EIGEN_STRONG_INLINE Packet8s pabs(const Packet8s& a) { return vabsq_s16(a); }
+template<> EIGEN_STRONG_INLINE Packet4us pabs(const Packet4us& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet8us pabs(const Packet8us& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet2i pabs(const Packet2i& a) { return vabs_s32(a); }
+template<> EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a) { return vabsq_s32(a); }
+template<> EIGEN_STRONG_INLINE Packet2ui pabs(const Packet2ui& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4ui pabs(const Packet4ui& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet2l pabs(const Packet2l& a) {
+#if EIGEN_ARCH_ARM64
+ return vabsq_s64(a);
+#else
+ return vcombine_s64(
+ vdup_n_s64((std::abs)(vgetq_lane_s64(a, 0))),
+ vdup_n_s64((std::abs)(vgetq_lane_s64(a, 1))));
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet2ul pabs(const Packet2ul& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet2f pfrexp<Packet2f>(const Packet2f& a, Packet2f& exponent)
+{ return pfrexp_generic(a,exponent); }
+template<> EIGEN_STRONG_INLINE Packet4f pfrexp<Packet4f>(const Packet4f& a, Packet4f& exponent)
+{ return pfrexp_generic(a,exponent); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pldexp<Packet2f>(const Packet2f& a, const Packet2f& exponent)
+{ return pldexp_generic(a,exponent); }
+template<> EIGEN_STRONG_INLINE Packet4f pldexp<Packet4f>(const Packet4f& a, const Packet4f& exponent)
+{ return pldexp_generic(a,exponent); }
+
+template<> EIGEN_STRONG_INLINE float predux<Packet2f>(const Packet2f& a) { return vget_lane_f32(vpadd_f32(a,a), 0); }
+template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a)
+{
+ const float32x2_t sum = vadd_f32(vget_low_f32(a), vget_high_f32(a));
+ return vget_lane_f32(vpadd_f32(sum, sum), 0);
+}
+template<> EIGEN_STRONG_INLINE int8_t predux<Packet4c>(const Packet4c& a)
+{
+ const int8x8_t a_dup = vreinterpret_s8_s32(vdup_n_s32(a));
+ int8x8_t sum = vpadd_s8(a_dup, a_dup);
+ sum = vpadd_s8(sum, sum);
+ return vget_lane_s8(sum, 0);
+}
+template<> EIGEN_STRONG_INLINE int8_t predux<Packet8c>(const Packet8c& a)
+{
+ int8x8_t sum = vpadd_s8(a,a);
+ sum = vpadd_s8(sum, sum);
+ sum = vpadd_s8(sum, sum);
+ return vget_lane_s8(sum, 0);
+}
+template<> EIGEN_STRONG_INLINE int8_t predux<Packet16c>(const Packet16c& a)
+{
+ int8x8_t sum = vadd_s8(vget_low_s8(a), vget_high_s8(a));
+ sum = vpadd_s8(sum, sum);
+ sum = vpadd_s8(sum, sum);
+ sum = vpadd_s8(sum, sum);
+ return vget_lane_s8(sum, 0);
+}
+template<> EIGEN_STRONG_INLINE uint8_t predux<Packet4uc>(const Packet4uc& a)
+{
+ const uint8x8_t a_dup = vreinterpret_u8_u32(vdup_n_u32(a));
+ uint8x8_t sum = vpadd_u8(a_dup, a_dup);
+ sum = vpadd_u8(sum, sum);
+ return vget_lane_u8(sum, 0);
+}
+template<> EIGEN_STRONG_INLINE uint8_t predux<Packet8uc>(const Packet8uc& a)
+{
+ uint8x8_t sum = vpadd_u8(a,a);
+ sum = vpadd_u8(sum, sum);
+ sum = vpadd_u8(sum, sum);
+ return vget_lane_u8(sum, 0);
+}
+template<> EIGEN_STRONG_INLINE uint8_t predux<Packet16uc>(const Packet16uc& a)
+{
+ uint8x8_t sum = vadd_u8(vget_low_u8(a), vget_high_u8(a));
+ sum = vpadd_u8(sum, sum);
+ sum = vpadd_u8(sum, sum);
+ sum = vpadd_u8(sum, sum);
+ return vget_lane_u8(sum, 0);
+}
+template<> EIGEN_STRONG_INLINE int16_t predux<Packet4s>(const Packet4s& a)
+{
+ const int16x4_t sum = vpadd_s16(a,a);
+ return vget_lane_s16(vpadd_s16(sum, sum), 0);
+}
+template<> EIGEN_STRONG_INLINE int16_t predux<Packet8s>(const Packet8s& a)
+{
+ int16x4_t sum = vadd_s16(vget_low_s16(a), vget_high_s16(a));
+ sum = vpadd_s16(sum, sum);
+ sum = vpadd_s16(sum, sum);
+ return vget_lane_s16(sum, 0);
+}
+template<> EIGEN_STRONG_INLINE uint16_t predux<Packet4us>(const Packet4us& a)
+{
+ const uint16x4_t sum = vpadd_u16(a,a);
+ return vget_lane_u16(vpadd_u16(sum, sum), 0);
+}
+template<> EIGEN_STRONG_INLINE uint16_t predux<Packet8us>(const Packet8us& a)
+{
+ uint16x4_t sum = vadd_u16(vget_low_u16(a), vget_high_u16(a));
+ sum = vpadd_u16(sum, sum);
+ sum = vpadd_u16(sum, sum);
+ return vget_lane_u16(sum, 0);
+}
+template<> EIGEN_STRONG_INLINE int32_t predux<Packet2i>(const Packet2i& a) { return vget_lane_s32(vpadd_s32(a,a), 0); }
+template<> EIGEN_STRONG_INLINE int32_t predux<Packet4i>(const Packet4i& a)
+{
+ const int32x2_t sum = vadd_s32(vget_low_s32(a), vget_high_s32(a));
+ return vget_lane_s32(vpadd_s32(sum, sum), 0);
+}
+template<> EIGEN_STRONG_INLINE uint32_t predux<Packet2ui>(const Packet2ui& a) { return vget_lane_u32(vpadd_u32(a,a), 0); }
+template<> EIGEN_STRONG_INLINE uint32_t predux<Packet4ui>(const Packet4ui& a)
+{
+ const uint32x2_t sum = vadd_u32(vget_low_u32(a), vget_high_u32(a));
+ return vget_lane_u32(vpadd_u32(sum, sum), 0);
+}
+template<> EIGEN_STRONG_INLINE int64_t predux<Packet2l>(const Packet2l& a)
+{ return vgetq_lane_s64(a, 0) + vgetq_lane_s64(a, 1); }
+template<> EIGEN_STRONG_INLINE uint64_t predux<Packet2ul>(const Packet2ul& a)
+{ return vgetq_lane_u64(a, 0) + vgetq_lane_u64(a, 1); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4c predux_half_dowto4(const Packet8c& a)
+{
+ return vget_lane_s32(vreinterpret_s32_s8(vadd_s8(a,
+ vreinterpret_s8_s32(vrev64_s32(vreinterpret_s32_s8(a))))), 0);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8c predux_half_dowto4(const Packet16c& a)
+{ return vadd_s8(vget_high_s8(a), vget_low_s8(a)); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4uc predux_half_dowto4(const Packet8uc& a)
+{
+ return vget_lane_u32(vreinterpret_u32_u8(vadd_u8(a,
+ vreinterpret_u8_u32(vrev64_u32(vreinterpret_u32_u8(a))))), 0);
+}
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8uc predux_half_dowto4(const Packet16uc& a)
+{ return vadd_u8(vget_high_u8(a), vget_low_u8(a)); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4s predux_half_dowto4(const Packet8s& a)
+{ return vadd_s16(vget_high_s16(a), vget_low_s16(a)); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4us predux_half_dowto4(const Packet8us& a)
+{ return vadd_u16(vget_high_u16(a), vget_low_u16(a)); }
+
+// Other reduction functions:
+// mul
+template<> EIGEN_STRONG_INLINE float predux_mul<Packet2f>(const Packet2f& a)
+{ return vget_lane_f32(a, 0) * vget_lane_f32(a, 1); }
+template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a)
+{ return predux_mul(vmul_f32(vget_low_f32(a), vget_high_f32(a))); }
+template<> EIGEN_STRONG_INLINE int8_t predux_mul<Packet4c>(const Packet4c& a)
+{
+ int8x8_t prod = vreinterpret_s8_s32(vdup_n_s32(a));
+ prod = vmul_s8(prod, vrev16_s8(prod));
+ return vget_lane_s8(prod, 0) * vget_lane_s8(prod, 2);
+}
+template<> EIGEN_STRONG_INLINE int8_t predux_mul<Packet8c>(const Packet8c& a)
+{
+ int8x8_t prod = vmul_s8(a, vrev16_s8(a));
+ prod = vmul_s8(prod, vrev32_s8(prod));
+ return vget_lane_s8(prod, 0) * vget_lane_s8(prod, 4);
+}
+template<> EIGEN_STRONG_INLINE int8_t predux_mul<Packet16c>(const Packet16c& a)
+{ return predux_mul(vmul_s8(vget_low_s8(a), vget_high_s8(a))); }
+template<> EIGEN_STRONG_INLINE uint8_t predux_mul<Packet4uc>(const Packet4uc& a)
+{
+ uint8x8_t prod = vreinterpret_u8_u32(vdup_n_u32(a));
+ prod = vmul_u8(prod, vrev16_u8(prod));
+ return vget_lane_u8(prod, 0) * vget_lane_u8(prod, 2);
+}
+template<> EIGEN_STRONG_INLINE uint8_t predux_mul<Packet8uc>(const Packet8uc& a)
+{
+ uint8x8_t prod = vmul_u8(a, vrev16_u8(a));
+ prod = vmul_u8(prod, vrev32_u8(prod));
+ return vget_lane_u8(prod, 0) * vget_lane_u8(prod, 4);
+}
+template<> EIGEN_STRONG_INLINE uint8_t predux_mul<Packet16uc>(const Packet16uc& a)
+{ return predux_mul(vmul_u8(vget_low_u8(a), vget_high_u8(a))); }
+template<> EIGEN_STRONG_INLINE int16_t predux_mul<Packet4s>(const Packet4s& a)
+{
+ const int16x4_t prod = vmul_s16(a, vrev32_s16(a));
+ return vget_lane_s16(prod, 0) * vget_lane_s16(prod, 2);
+}
+template<> EIGEN_STRONG_INLINE int16_t predux_mul<Packet8s>(const Packet8s& a)
+{
+ int16x4_t prod;
+
+ // Get the product of a_lo * a_hi -> |a1*a5|a2*a6|a3*a7|a4*a8|
+ prod = vmul_s16(vget_low_s16(a), vget_high_s16(a));
+ // Swap and multiply |a1*a5*a2*a6|a3*a7*a4*a8|
+ prod = vmul_s16(prod, vrev32_s16(prod));
+ // Multiply |a1*a5*a2*a6*a3*a7*a4*a8|
+ return vget_lane_s16(prod, 0) * vget_lane_s16(prod, 2);
+}
+template<> EIGEN_STRONG_INLINE uint16_t predux_mul<Packet4us>(const Packet4us& a)
+{
+ const uint16x4_t prod = vmul_u16(a, vrev32_u16(a));
+ return vget_lane_u16(prod, 0) * vget_lane_u16(prod, 2);
+}
+template<> EIGEN_STRONG_INLINE uint16_t predux_mul<Packet8us>(const Packet8us& a)
+{
+ uint16x4_t prod;
+
+ // Get the product of a_lo * a_hi -> |a1*a5|a2*a6|a3*a7|a4*a8|
+ prod = vmul_u16(vget_low_u16(a), vget_high_u16(a));
+ // Swap and multiply |a1*a5*a2*a6|a3*a7*a4*a8|
+ prod = vmul_u16(prod, vrev32_u16(prod));
+ // Multiply |a1*a5*a2*a6*a3*a7*a4*a8|
+ return vget_lane_u16(prod, 0) * vget_lane_u16(prod, 2);
+}
+template<> EIGEN_STRONG_INLINE int32_t predux_mul<Packet2i>(const Packet2i& a)
+{ return vget_lane_s32(a, 0) * vget_lane_s32(a, 1); }
+template<> EIGEN_STRONG_INLINE int32_t predux_mul<Packet4i>(const Packet4i& a)
+{ return predux_mul(vmul_s32(vget_low_s32(a), vget_high_s32(a))); }
+template<> EIGEN_STRONG_INLINE uint32_t predux_mul<Packet2ui>(const Packet2ui& a)
+{ return vget_lane_u32(a, 0) * vget_lane_u32(a, 1); }
+template<> EIGEN_STRONG_INLINE uint32_t predux_mul<Packet4ui>(const Packet4ui& a)
+{ return predux_mul(vmul_u32(vget_low_u32(a), vget_high_u32(a))); }
+template<> EIGEN_STRONG_INLINE int64_t predux_mul<Packet2l>(const Packet2l& a)
+{ return vgetq_lane_s64(a, 0) * vgetq_lane_s64(a, 1); }
+template<> EIGEN_STRONG_INLINE uint64_t predux_mul<Packet2ul>(const Packet2ul& a)
+{ return vgetq_lane_u64(a, 0) * vgetq_lane_u64(a, 1); }
+
+// min
+template<> EIGEN_STRONG_INLINE float predux_min<Packet2f>(const Packet2f& a)
+{ return vget_lane_f32(vpmin_f32(a,a), 0); }
+template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a)
+{
+ const float32x2_t min = vmin_f32(vget_low_f32(a), vget_high_f32(a));
+ return vget_lane_f32(vpmin_f32(min, min), 0);
+}
+template<> EIGEN_STRONG_INLINE int8_t predux_min<Packet4c>(const Packet4c& a)
+{
+ const int8x8_t a_dup = vreinterpret_s8_s32(vdup_n_s32(a));
+ int8x8_t min = vpmin_s8(a_dup, a_dup);
+ min = vpmin_s8(min, min);
+ return vget_lane_s8(min, 0);
+}
+template<> EIGEN_STRONG_INLINE int8_t predux_min<Packet8c>(const Packet8c& a)
+{
+ int8x8_t min = vpmin_s8(a,a);
+ min = vpmin_s8(min, min);
+ min = vpmin_s8(min, min);
+ return vget_lane_s8(min, 0);
+}
+template<> EIGEN_STRONG_INLINE int8_t predux_min<Packet16c>(const Packet16c& a)
+{
+ int8x8_t min = vmin_s8(vget_low_s8(a), vget_high_s8(a));
+ min = vpmin_s8(min, min);
+ min = vpmin_s8(min, min);
+ min = vpmin_s8(min, min);
+ return vget_lane_s8(min, 0);
+}
+template<> EIGEN_STRONG_INLINE uint8_t predux_min<Packet4uc>(const Packet4uc& a)
+{
+ const uint8x8_t a_dup = vreinterpret_u8_u32(vdup_n_u32(a));
+ uint8x8_t min = vpmin_u8(a_dup, a_dup);
+ min = vpmin_u8(min, min);
+ return vget_lane_u8(min, 0);
+}
+template<> EIGEN_STRONG_INLINE uint8_t predux_min<Packet8uc>(const Packet8uc& a)
+{
+ uint8x8_t min = vpmin_u8(a,a);
+ min = vpmin_u8(min, min);
+ min = vpmin_u8(min, min);
+ return vget_lane_u8(min, 0);
+}
+template<> EIGEN_STRONG_INLINE uint8_t predux_min<Packet16uc>(const Packet16uc& a)
+{
+ uint8x8_t min = vmin_u8(vget_low_u8(a), vget_high_u8(a));
+ min = vpmin_u8(min, min);
+ min = vpmin_u8(min, min);
+ min = vpmin_u8(min, min);
+ return vget_lane_u8(min, 0);
+}
+template<> EIGEN_STRONG_INLINE int16_t predux_min<Packet4s>(const Packet4s& a)
+{
+ const int16x4_t min = vpmin_s16(a,a);
+ return vget_lane_s16(vpmin_s16(min, min), 0);
+}
+template<> EIGEN_STRONG_INLINE int16_t predux_min<Packet8s>(const Packet8s& a)
+{
+ int16x4_t min = vmin_s16(vget_low_s16(a), vget_high_s16(a));
+ min = vpmin_s16(min, min);
+ min = vpmin_s16(min, min);
+ return vget_lane_s16(min, 0);
+}
+template<> EIGEN_STRONG_INLINE uint16_t predux_min<Packet4us>(const Packet4us& a)
+{
+ const uint16x4_t min = vpmin_u16(a,a);
+ return vget_lane_u16(vpmin_u16(min, min), 0);
+}
+template<> EIGEN_STRONG_INLINE uint16_t predux_min<Packet8us>(const Packet8us& a)
+{
+ uint16x4_t min = vmin_u16(vget_low_u16(a), vget_high_u16(a));
+ min = vpmin_u16(min, min);
+ min = vpmin_u16(min, min);
+ return vget_lane_u16(min, 0);
+}
+template<> EIGEN_STRONG_INLINE int32_t predux_min<Packet2i>(const Packet2i& a)
+{ return vget_lane_s32(vpmin_s32(a,a), 0); }
+template<> EIGEN_STRONG_INLINE int32_t predux_min<Packet4i>(const Packet4i& a)
+{
+ const int32x2_t min = vmin_s32(vget_low_s32(a), vget_high_s32(a));
+ return vget_lane_s32(vpmin_s32(min, min), 0);
+}
+template<> EIGEN_STRONG_INLINE uint32_t predux_min<Packet2ui>(const Packet2ui& a)
+{ return vget_lane_u32(vpmin_u32(a,a), 0); }
+template<> EIGEN_STRONG_INLINE uint32_t predux_min<Packet4ui>(const Packet4ui& a)
+{
+ const uint32x2_t min = vmin_u32(vget_low_u32(a), vget_high_u32(a));
+ return vget_lane_u32(vpmin_u32(min, min), 0);
+}
+template<> EIGEN_STRONG_INLINE int64_t predux_min<Packet2l>(const Packet2l& a)
+{ return (std::min)(vgetq_lane_s64(a, 0), vgetq_lane_s64(a, 1)); }
+template<> EIGEN_STRONG_INLINE uint64_t predux_min<Packet2ul>(const Packet2ul& a)
+{ return (std::min)(vgetq_lane_u64(a, 0), vgetq_lane_u64(a, 1)); }
+
+// max
+template<> EIGEN_STRONG_INLINE float predux_max<Packet2f>(const Packet2f& a)
+{ return vget_lane_f32(vpmax_f32(a,a), 0); }
+template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a)
+{
+ const float32x2_t max = vmax_f32(vget_low_f32(a), vget_high_f32(a));
+ return vget_lane_f32(vpmax_f32(max, max), 0);
+}
+template<> EIGEN_STRONG_INLINE int8_t predux_max<Packet4c>(const Packet4c& a)
+{
+ const int8x8_t a_dup = vreinterpret_s8_s32(vdup_n_s32(a));
+ int8x8_t max = vpmax_s8(a_dup, a_dup);
+ max = vpmax_s8(max, max);
+ return vget_lane_s8(max, 0);
+}
+template<> EIGEN_STRONG_INLINE int8_t predux_max<Packet8c>(const Packet8c& a)
+{
+ int8x8_t max = vpmax_s8(a,a);
+ max = vpmax_s8(max, max);
+ max = vpmax_s8(max, max);
+ return vget_lane_s8(max, 0);
+}
+template<> EIGEN_STRONG_INLINE int8_t predux_max<Packet16c>(const Packet16c& a)
+{
+ int8x8_t max = vmax_s8(vget_low_s8(a), vget_high_s8(a));
+ max = vpmax_s8(max, max);
+ max = vpmax_s8(max, max);
+ max = vpmax_s8(max, max);
+ return vget_lane_s8(max, 0);
+}
+template<> EIGEN_STRONG_INLINE uint8_t predux_max<Packet4uc>(const Packet4uc& a)
+{
+ const uint8x8_t a_dup = vreinterpret_u8_u32(vdup_n_u32(a));
+ uint8x8_t max = vpmax_u8(a_dup, a_dup);
+ max = vpmax_u8(max, max);
+ return vget_lane_u8(max, 0);
+}
+template<> EIGEN_STRONG_INLINE uint8_t predux_max<Packet8uc>(const Packet8uc& a)
+{
+ uint8x8_t max = vpmax_u8(a,a);
+ max = vpmax_u8(max, max);
+ max = vpmax_u8(max, max);
+ return vget_lane_u8(max, 0);
+}
+template<> EIGEN_STRONG_INLINE uint8_t predux_max<Packet16uc>(const Packet16uc& a)
+{
+ uint8x8_t max = vmax_u8(vget_low_u8(a), vget_high_u8(a));
+ max = vpmax_u8(max, max);
+ max = vpmax_u8(max, max);
+ max = vpmax_u8(max, max);
+ return vget_lane_u8(max, 0);
+}
+template<> EIGEN_STRONG_INLINE int16_t predux_max<Packet4s>(const Packet4s& a)
+{
+ const int16x4_t max = vpmax_s16(a,a);
+ return vget_lane_s16(vpmax_s16(max, max), 0);
+}
+template<> EIGEN_STRONG_INLINE int16_t predux_max<Packet8s>(const Packet8s& a)
+{
+ int16x4_t max = vmax_s16(vget_low_s16(a), vget_high_s16(a));
+ max = vpmax_s16(max, max);
+ max = vpmax_s16(max, max);
+ return vget_lane_s16(max, 0);
+}
+template<> EIGEN_STRONG_INLINE uint16_t predux_max<Packet4us>(const Packet4us& a)
+{
+ const uint16x4_t max = vpmax_u16(a,a);
+ return vget_lane_u16(vpmax_u16(max, max), 0);
+}
+template<> EIGEN_STRONG_INLINE uint16_t predux_max<Packet8us>(const Packet8us& a)
+{
+ uint16x4_t max = vmax_u16(vget_low_u16(a), vget_high_u16(a));
+ max = vpmax_u16(max, max);
+ max = vpmax_u16(max, max);
+ return vget_lane_u16(max, 0);
+}
+template<> EIGEN_STRONG_INLINE int32_t predux_max<Packet2i>(const Packet2i& a)
+{ return vget_lane_s32(vpmax_s32(a,a), 0); }
+template<> EIGEN_STRONG_INLINE int32_t predux_max<Packet4i>(const Packet4i& a)
+{
+ const int32x2_t max = vmax_s32(vget_low_s32(a), vget_high_s32(a));
+ return vget_lane_s32(vpmax_s32(max, max), 0);
+}
+template<> EIGEN_STRONG_INLINE uint32_t predux_max<Packet2ui>(const Packet2ui& a)
+{ return vget_lane_u32(vpmax_u32(a,a), 0); }
+template<> EIGEN_STRONG_INLINE uint32_t predux_max<Packet4ui>(const Packet4ui& a)
+{
+ const uint32x2_t max = vmax_u32(vget_low_u32(a), vget_high_u32(a));
+ return vget_lane_u32(vpmax_u32(max, max), 0);
+}
+template<> EIGEN_STRONG_INLINE int64_t predux_max<Packet2l>(const Packet2l& a)
+{ return (std::max)(vgetq_lane_s64(a, 0), vgetq_lane_s64(a, 1)); }
+template<> EIGEN_STRONG_INLINE uint64_t predux_max<Packet2ul>(const Packet2ul& a)
+{ return (std::max)(vgetq_lane_u64(a, 0), vgetq_lane_u64(a, 1)); }
+
+template<> EIGEN_STRONG_INLINE bool predux_any(const Packet4f& x)
+{
+ uint32x2_t tmp = vorr_u32(vget_low_u32( vreinterpretq_u32_f32(x)),
+ vget_high_u32(vreinterpretq_u32_f32(x)));
+ return vget_lane_u32(vpmax_u32(tmp, tmp), 0);
+}
+
+// Helpers for ptranspose.
+namespace detail {
+
+template<typename Packet>
+void zip_in_place(Packet& p1, Packet& p2);
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet2f>(Packet2f& p1, Packet2f& p2) {
+ const float32x2x2_t tmp = vzip_f32(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet4f>(Packet4f& p1, Packet4f& p2) {
+ const float32x4x2_t tmp = vzipq_f32(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet8c>(Packet8c& p1, Packet8c& p2) {
+ const int8x8x2_t tmp = vzip_s8(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet16c>(Packet16c& p1, Packet16c& p2) {
+ const int8x16x2_t tmp = vzipq_s8(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet8uc>(Packet8uc& p1, Packet8uc& p2) {
+ const uint8x8x2_t tmp = vzip_u8(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet16uc>(Packet16uc& p1, Packet16uc& p2) {
+ const uint8x16x2_t tmp = vzipq_u8(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet2i>(Packet2i& p1, Packet2i& p2) {
+ const int32x2x2_t tmp = vzip_s32(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet4i>(Packet4i& p1, Packet4i& p2) {
+ const int32x4x2_t tmp = vzipq_s32(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet2ui>(Packet2ui& p1, Packet2ui& p2) {
+ const uint32x2x2_t tmp = vzip_u32(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet4ui>(Packet4ui& p1, Packet4ui& p2) {
+ const uint32x4x2_t tmp = vzipq_u32(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet4s>(Packet4s& p1, Packet4s& p2) {
+ const int16x4x2_t tmp = vzip_s16(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet8s>(Packet8s& p1, Packet8s& p2) {
+ const int16x8x2_t tmp = vzipq_s16(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet4us>(Packet4us& p1, Packet4us& p2) {
+ const uint16x4x2_t tmp = vzip_u16(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet8us>(Packet8us& p1, Packet8us& p2) {
+ const uint16x8x2_t tmp = vzipq_u16(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void ptranspose_impl(PacketBlock<Packet, 2>& kernel) {
+ zip_in_place(kernel.packet[0], kernel.packet[1]);
+}
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void ptranspose_impl(PacketBlock<Packet, 4>& kernel) {
+ zip_in_place(kernel.packet[0], kernel.packet[2]);
+ zip_in_place(kernel.packet[1], kernel.packet[3]);
+ zip_in_place(kernel.packet[0], kernel.packet[1]);
+ zip_in_place(kernel.packet[2], kernel.packet[3]);
+}
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void ptranspose_impl(PacketBlock<Packet, 8>& kernel) {
+ zip_in_place(kernel.packet[0], kernel.packet[4]);
+ zip_in_place(kernel.packet[1], kernel.packet[5]);
+ zip_in_place(kernel.packet[2], kernel.packet[6]);
+ zip_in_place(kernel.packet[3], kernel.packet[7]);
+
+ zip_in_place(kernel.packet[0], kernel.packet[2]);
+ zip_in_place(kernel.packet[1], kernel.packet[3]);
+ zip_in_place(kernel.packet[4], kernel.packet[6]);
+ zip_in_place(kernel.packet[5], kernel.packet[7]);
+
+ zip_in_place(kernel.packet[0], kernel.packet[1]);
+ zip_in_place(kernel.packet[2], kernel.packet[3]);
+ zip_in_place(kernel.packet[4], kernel.packet[5]);
+ zip_in_place(kernel.packet[6], kernel.packet[7]);
+}
+
+template<typename Packet>
+EIGEN_ALWAYS_INLINE void ptranspose_impl(PacketBlock<Packet, 16>& kernel) {
+ EIGEN_UNROLL_LOOP
+ for (int i=0; i<4; ++i) {
+ const int m = (1 << i);
+ EIGEN_UNROLL_LOOP
+ for (int j=0; j<m; ++j) {
+ const int n = (1 << (3-i));
+ EIGEN_UNROLL_LOOP
+ for (int k=0; k<n; ++k) {
+ const int idx = 2*j*n+k;
+ zip_in_place(kernel.packet[idx], kernel.packet[idx + n]);
+ }
+ }
+ }
+}
+
+} // namespace detail
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2f, 2>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4f, 4>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4c, 4>& kernel)
+{
+ const int8x8_t a = vreinterpret_s8_s32(vset_lane_s32(kernel.packet[2], vdup_n_s32(kernel.packet[0]), 1));
+ const int8x8_t b = vreinterpret_s8_s32(vset_lane_s32(kernel.packet[3], vdup_n_s32(kernel.packet[1]), 1));
+
+ const int8x8x2_t zip8 = vzip_s8(a,b);
+ const int16x4x2_t zip16 = vzip_s16(vreinterpret_s16_s8(zip8.val[0]), vreinterpret_s16_s8(zip8.val[1]));
+
+ kernel.packet[0] = vget_lane_s32(vreinterpret_s32_s16(zip16.val[0]), 0);
+ kernel.packet[1] = vget_lane_s32(vreinterpret_s32_s16(zip16.val[0]), 1);
+ kernel.packet[2] = vget_lane_s32(vreinterpret_s32_s16(zip16.val[1]), 0);
+ kernel.packet[3] = vget_lane_s32(vreinterpret_s32_s16(zip16.val[1]), 1);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8c, 8>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8c, 4>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16c, 16>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16c, 8>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16c, 4>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4uc, 4>& kernel)
+{
+ const uint8x8_t a = vreinterpret_u8_u32(vset_lane_u32(kernel.packet[2], vdup_n_u32(kernel.packet[0]), 1));
+ const uint8x8_t b = vreinterpret_u8_u32(vset_lane_u32(kernel.packet[3], vdup_n_u32(kernel.packet[1]), 1));
+
+ const uint8x8x2_t zip8 = vzip_u8(a,b);
+ const uint16x4x2_t zip16 = vzip_u16(vreinterpret_u16_u8(zip8.val[0]), vreinterpret_u16_u8(zip8.val[1]));
+
+ kernel.packet[0] = vget_lane_u32(vreinterpret_u32_u16(zip16.val[0]), 0);
+ kernel.packet[1] = vget_lane_u32(vreinterpret_u32_u16(zip16.val[0]), 1);
+ kernel.packet[2] = vget_lane_u32(vreinterpret_u32_u16(zip16.val[1]), 0);
+ kernel.packet[3] = vget_lane_u32(vreinterpret_u32_u16(zip16.val[1]), 1);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8uc, 8>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8uc, 4>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16uc, 16>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16uc, 8>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet16uc, 4>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4s, 4>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8s, 8>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8s, 4>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4us, 4>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8us, 8>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8us, 4>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2i, 2>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4i, 4>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2ui, 2>& kernel) {
+ detail::zip_in_place(kernel.packet[0], kernel.packet[1]);
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4ui, 4>& kernel) {
+ detail::ptranspose_impl(kernel);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet2l, 2>& kernel)
+{
+#if EIGEN_ARCH_ARM64
+ const int64x2_t tmp1 = vzip1q_s64(kernel.packet[0], kernel.packet[1]);
+ kernel.packet[1] = vzip2q_s64(kernel.packet[0], kernel.packet[1]);
+ kernel.packet[0] = tmp1;
+#else
+ const int64x1_t tmp[2][2] = {
+ { vget_low_s64(kernel.packet[0]), vget_high_s64(kernel.packet[0]) },
+ { vget_low_s64(kernel.packet[1]), vget_high_s64(kernel.packet[1]) }
+ };
+
+ kernel.packet[0] = vcombine_s64(tmp[0][0], tmp[1][0]);
+ kernel.packet[1] = vcombine_s64(tmp[0][1], tmp[1][1]);
+#endif
+}
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet2ul, 2>& kernel)
+{
+#if EIGEN_ARCH_ARM64
+ const uint64x2_t tmp1 = vzip1q_u64(kernel.packet[0], kernel.packet[1]);
+ kernel.packet[1] = vzip2q_u64(kernel.packet[0], kernel.packet[1]);
+ kernel.packet[0] = tmp1;
+#else
+ const uint64x1_t tmp[2][2] = {
+ { vget_low_u64(kernel.packet[0]), vget_high_u64(kernel.packet[0]) },
+ { vget_low_u64(kernel.packet[1]), vget_high_u64(kernel.packet[1]) }
+ };
+
+ kernel.packet[0] = vcombine_u64(tmp[0][0], tmp[1][0]);
+ kernel.packet[1] = vcombine_u64(tmp[0][1], tmp[1][1]);
+#endif
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2f pselect( const Packet2f& mask, const Packet2f& a, const Packet2f& b)
+{ return vbsl_f32(vreinterpret_u32_f32(mask), a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4f pselect(const Packet4f& mask, const Packet4f& a, const Packet4f& b)
+{ return vbslq_f32(vreinterpretq_u32_f32(mask), a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8c pselect(const Packet8c& mask, const Packet8c& a, const Packet8c& b)
+{ return vbsl_s8(vreinterpret_u8_s8(mask), a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet16c pselect(const Packet16c& mask, const Packet16c& a, const Packet16c& b)
+{ return vbslq_s8(vreinterpretq_u8_s8(mask), a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8uc pselect(const Packet8uc& mask, const Packet8uc& a, const Packet8uc& b)
+{ return vbsl_u8(mask, a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet16uc pselect(const Packet16uc& mask, const Packet16uc& a, const Packet16uc& b)
+{ return vbslq_u8(mask, a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4s pselect(const Packet4s& mask, const Packet4s& a, const Packet4s& b)
+{ return vbsl_s16(vreinterpret_u16_s16(mask), a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8s pselect(const Packet8s& mask, const Packet8s& a, const Packet8s& b)
+{ return vbslq_s16(vreinterpretq_u16_s16(mask), a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4us pselect(const Packet4us& mask, const Packet4us& a, const Packet4us& b)
+{ return vbsl_u16(mask, a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8us pselect(const Packet8us& mask, const Packet8us& a, const Packet8us& b)
+{ return vbslq_u16(mask, a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2i pselect(const Packet2i& mask, const Packet2i& a, const Packet2i& b)
+{ return vbsl_s32(vreinterpret_u32_s32(mask), a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4i pselect(const Packet4i& mask, const Packet4i& a, const Packet4i& b)
+{ return vbslq_s32(vreinterpretq_u32_s32(mask), a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2ui pselect(const Packet2ui& mask, const Packet2ui& a, const Packet2ui& b)
+{ return vbsl_u32(mask, a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4ui pselect(const Packet4ui& mask, const Packet4ui& a, const Packet4ui& b)
+{ return vbslq_u32(mask, a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2l pselect(const Packet2l& mask, const Packet2l& a, const Packet2l& b)
+{ return vbslq_s64(vreinterpretq_u64_s64(mask), a, b); }
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2ul pselect(const Packet2ul& mask, const Packet2ul& a, const Packet2ul& b)
+{ return vbslq_u64(mask, a, b); }
+
+// Use armv8 rounding intinsics if available.
+#if EIGEN_ARCH_ARMV8
+template<> EIGEN_STRONG_INLINE Packet2f print<Packet2f>(const Packet2f& a)
+{ return vrndn_f32(a); }
+
+template<> EIGEN_STRONG_INLINE Packet4f print<Packet4f>(const Packet4f& a)
+{ return vrndnq_f32(a); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pfloor<Packet2f>(const Packet2f& a)
+{ return vrndm_f32(a); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a)
+{ return vrndmq_f32(a); }
+
+template<> EIGEN_STRONG_INLINE Packet2f pceil<Packet2f>(const Packet2f& a)
+{ return vrndp_f32(a); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a)
+{ return vrndpq_f32(a); }
+
+#else
+
+template<> EIGEN_STRONG_INLINE Packet4f print(const Packet4f& a) {
+ // Adds and subtracts signum(a) * 2^23 to force rounding.
+ const Packet4f limit = pset1<Packet4f>(static_cast<float>(1<<23));
+ const Packet4f abs_a = pabs(a);
+ Packet4f r = padd(abs_a, limit);
+ // Don't compile-away addition and subtraction.
+ EIGEN_OPTIMIZATION_BARRIER(r);
+ r = psub(r, limit);
+ // If greater than limit, simply return a. Otherwise, account for sign.
+ r = pselect(pcmp_lt(abs_a, limit),
+ pselect(pcmp_lt(a, pzero(a)), pnegate(r), r), a);
+ return r;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f print(const Packet2f& a) {
+ // Adds and subtracts signum(a) * 2^23 to force rounding.
+ const Packet2f limit = pset1<Packet2f>(static_cast<float>(1<<23));
+ const Packet2f abs_a = pabs(a);
+ Packet2f r = padd(abs_a, limit);
+ // Don't compile-away addition and subtraction.
+ EIGEN_OPTIMIZATION_BARRIER(r);
+ r = psub(r, limit);
+ // If greater than limit, simply return a. Otherwise, account for sign.
+ r = pselect(pcmp_lt(abs_a, limit),
+ pselect(pcmp_lt(a, pzero(a)), pnegate(r), r), a);
+ return r;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a)
+{
+ const Packet4f cst_1 = pset1<Packet4f>(1.0f);
+ Packet4f tmp = print<Packet4f>(a);
+ // If greater, subtract one.
+ Packet4f mask = pcmp_lt(a, tmp);
+ mask = pand(mask, cst_1);
+ return psub(tmp, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f pfloor<Packet2f>(const Packet2f& a)
+{
+ const Packet2f cst_1 = pset1<Packet2f>(1.0f);
+ Packet2f tmp = print<Packet2f>(a);
+ // If greater, subtract one.
+ Packet2f mask = pcmp_lt(a, tmp);
+ mask = pand(mask, cst_1);
+ return psub(tmp, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a)
+{
+ const Packet4f cst_1 = pset1<Packet4f>(1.0f);
+ Packet4f tmp = print<Packet4f>(a);
+ // If smaller, add one.
+ Packet4f mask = pcmp_lt(tmp, a);
+ mask = pand(mask, cst_1);
+ return padd(tmp, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f pceil<Packet2f>(const Packet2f& a)
+{
+ const Packet2f cst_1 = pset1<Packet2f>(1.0);
+ Packet2f tmp = print<Packet2f>(a);
+ // If smaller, add one.
+ Packet2f mask = pcmp_lt(tmp, a);
+ mask = pand(mask, cst_1);
+ return padd(tmp, mask);
+}
+
+#endif
+
+/**
+ * Computes the integer square root
+ * @remarks The calculation is performed using an algorithm which iterates through each binary digit of the result
+ * and tests whether setting that digit to 1 would cause the square of the value to be greater than the argument
+ * value. The algorithm is described in detail here: http://ww1.microchip.com/downloads/en/AppNotes/91040a.pdf .
+ */
+template<> EIGEN_STRONG_INLINE Packet4uc psqrt(const Packet4uc& a) {
+ uint8x8_t x = vreinterpret_u8_u32(vdup_n_u32(a));
+ uint8x8_t res = vdup_n_u8(0);
+ uint8x8_t add = vdup_n_u8(0x8);
+ for (int i = 0; i < 4; i++)
+ {
+ const uint8x8_t temp = vorr_u8(res, add);
+ res = vbsl_u8(vcge_u8(x, vmul_u8(temp, temp)), temp, res);
+ add = vshr_n_u8(add, 1);
+ }
+ return vget_lane_u32(vreinterpret_u32_u8(res), 0);
+}
+/// @copydoc Eigen::internal::psqrt(const Packet4uc& a)
+template<> EIGEN_STRONG_INLINE Packet8uc psqrt(const Packet8uc& a) {
+ uint8x8_t res = vdup_n_u8(0);
+ uint8x8_t add = vdup_n_u8(0x8);
+ for (int i = 0; i < 4; i++)
+ {
+ const uint8x8_t temp = vorr_u8(res, add);
+ res = vbsl_u8(vcge_u8(a, vmul_u8(temp, temp)), temp, res);
+ add = vshr_n_u8(add, 1);
+ }
+ return res;
+}
+/// @copydoc Eigen::internal::psqrt(const Packet4uc& a)
+template<> EIGEN_STRONG_INLINE Packet16uc psqrt(const Packet16uc& a) {
+ uint8x16_t res = vdupq_n_u8(0);
+ uint8x16_t add = vdupq_n_u8(0x8);
+ for (int i = 0; i < 4; i++)
+ {
+ const uint8x16_t temp = vorrq_u8(res, add);
+ res = vbslq_u8(vcgeq_u8(a, vmulq_u8(temp, temp)), temp, res);
+ add = vshrq_n_u8(add, 1);
+ }
+ return res;
+}
+/// @copydoc Eigen::internal::psqrt(const Packet4uc& a)
+template<> EIGEN_STRONG_INLINE Packet4us psqrt(const Packet4us& a) {
+ uint16x4_t res = vdup_n_u16(0);
+ uint16x4_t add = vdup_n_u16(0x80);
+ for (int i = 0; i < 8; i++)
+ {
+ const uint16x4_t temp = vorr_u16(res, add);
+ res = vbsl_u16(vcge_u16(a, vmul_u16(temp, temp)), temp, res);
+ add = vshr_n_u16(add, 1);
+ }
+ return res;
+}
+/// @copydoc Eigen::internal::psqrt(const Packet4uc& a)
+template<> EIGEN_STRONG_INLINE Packet8us psqrt(const Packet8us& a) {
+ uint16x8_t res = vdupq_n_u16(0);
+ uint16x8_t add = vdupq_n_u16(0x80);
+ for (int i = 0; i < 8; i++)
+ {
+ const uint16x8_t temp = vorrq_u16(res, add);
+ res = vbslq_u16(vcgeq_u16(a, vmulq_u16(temp, temp)), temp, res);
+ add = vshrq_n_u16(add, 1);
+ }
+ return res;
+}
+/// @copydoc Eigen::internal::psqrt(const Packet4uc& a)
+template<> EIGEN_STRONG_INLINE Packet2ui psqrt(const Packet2ui& a) {
+ uint32x2_t res = vdup_n_u32(0);
+ uint32x2_t add = vdup_n_u32(0x8000);
+ for (int i = 0; i < 16; i++)
+ {
+ const uint32x2_t temp = vorr_u32(res, add);
+ res = vbsl_u32(vcge_u32(a, vmul_u32(temp, temp)), temp, res);
+ add = vshr_n_u32(add, 1);
+ }
+ return res;
+}
+/// @copydoc Eigen::internal::psqrt(const Packet4uc& a)
+template<> EIGEN_STRONG_INLINE Packet4ui psqrt(const Packet4ui& a) {
+ uint32x4_t res = vdupq_n_u32(0);
+ uint32x4_t add = vdupq_n_u32(0x8000);
+ for (int i = 0; i < 16; i++)
+ {
+ const uint32x4_t temp = vorrq_u32(res, add);
+ res = vbslq_u32(vcgeq_u32(a, vmulq_u32(temp, temp)), temp, res);
+ add = vshrq_n_u32(add, 1);
+ }
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f prsqrt(const Packet4f& a) {
+ // Compute approximate reciprocal sqrt.
+ Packet4f x = vrsqrteq_f32(a);
+ // Do Newton iterations for 1/sqrt(x).
+ x = vmulq_f32(vrsqrtsq_f32(vmulq_f32(a, x), x), x);
+ x = vmulq_f32(vrsqrtsq_f32(vmulq_f32(a, x), x), x);
+ const Packet4f infinity = pset1<Packet4f>(NumTraits<float>::infinity());
+ return pselect(pcmp_eq(a, pzero(a)), infinity, x);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2f prsqrt(const Packet2f& a) {
+ // Compute approximate reciprocal sqrt.
+ Packet2f x = vrsqrte_f32(a);
+ // Do Newton iterations for 1/sqrt(x).
+ x = vmul_f32(vrsqrts_f32(vmul_f32(a, x), x), x);
+ x = vmul_f32(vrsqrts_f32(vmul_f32(a, x), x), x);
+ const Packet2f infinity = pset1<Packet2f>(NumTraits<float>::infinity());
+ return pselect(pcmp_eq(a, pzero(a)), infinity, x);
+}
+
+// Unfortunately vsqrt_f32 is only available for A64.
+#if EIGEN_ARCH_ARM64
+template<> EIGEN_STRONG_INLINE Packet4f psqrt(const Packet4f& _x){return vsqrtq_f32(_x);}
+template<> EIGEN_STRONG_INLINE Packet2f psqrt(const Packet2f& _x){return vsqrt_f32(_x); }
+#else
+template<> EIGEN_STRONG_INLINE Packet4f psqrt(const Packet4f& a) {
+ const Packet4f infinity = pset1<Packet4f>(NumTraits<float>::infinity());
+ const Packet4f is_zero_or_inf = por(pcmp_eq(a, pzero(a)), pcmp_eq(a, infinity));
+ return pselect(is_zero_or_inf, a, pmul(a, prsqrt(a)));
+}
+template<> EIGEN_STRONG_INLINE Packet2f psqrt(const Packet2f& a) {
+ const Packet2f infinity = pset1<Packet2f>(NumTraits<float>::infinity());
+ const Packet2f is_zero_or_inf = por(pcmp_eq(a, pzero(a)), pcmp_eq(a, infinity));
+ return pselect(is_zero_or_inf, a, pmul(a, prsqrt(a)));
+}
+#endif
+
+//---------- bfloat16 ----------
+// TODO: Add support for native armv8.6-a bfloat16_t
+
+// TODO: Guard if we have native bfloat16 support
+typedef eigen_packet_wrapper<uint16x4_t, 19> Packet4bf;
+
+template<> struct is_arithmetic<Packet4bf> { enum { value = true }; };
+
+template<> struct packet_traits<bfloat16> : default_packet_traits
+{
+ typedef Packet4bf type;
+ typedef Packet4bf half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 0,
+
+ HasCmp = 1,
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasAbsDiff = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0,
+ HasDiv = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1,
+
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+ HasLog = 1,
+ HasExp = 1,
+ HasSqrt = 0,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+ HasBessel = 0, // Issues with accuracy.
+ HasNdtri = 0
+ };
+};
+
+template<> struct unpacket_traits<Packet4bf>
+{
+ typedef bfloat16 type;
+ typedef Packet4bf half;
+ enum
+ {
+ size = 4,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+
+namespace detail {
+template<>
+EIGEN_ALWAYS_INLINE void zip_in_place<Packet4bf>(Packet4bf& p1, Packet4bf& p2) {
+ const uint16x4x2_t tmp = vzip_u16(p1, p2);
+ p1 = tmp.val[0];
+ p2 = tmp.val[1];
+}
+} // namespace detail
+
+EIGEN_STRONG_INLINE Packet4bf F32ToBf16(const Packet4f& p)
+{
+ // See the scalar implemention in BFloat16.h for a comprehensible explanation
+ // of this fast rounding algorithm
+ Packet4ui input = reinterpret_cast<Packet4ui>(p);
+
+ // lsb = (input >> 16) & 1
+ Packet4ui lsb = vandq_u32(vshrq_n_u32(input, 16), vdupq_n_u32(1));
+
+ // rounding_bias = 0x7fff + lsb
+ Packet4ui rounding_bias = vaddq_u32(lsb, vdupq_n_u32(0x7fff));
+
+ // input += rounding_bias
+ input = vaddq_u32(input, rounding_bias);
+
+ // input = input >> 16
+ input = vshrq_n_u32(input, 16);
+
+ // Replace float-nans by bfloat16-nans, that is 0x7fc0
+ const Packet4ui bf16_nan = vdupq_n_u32(0x7fc0);
+ const Packet4ui mask = vceqq_f32(p, p);
+ input = vbslq_u32(mask, input, bf16_nan);
+
+ // output = static_cast<uint16_t>(input)
+ return vmovn_u32(input);
+}
+
+EIGEN_STRONG_INLINE Packet4f Bf16ToF32(const Packet4bf& p)
+{
+ return reinterpret_cast<Packet4f>(vshlq_n_u32(vmovl_u16(p), 16));
+}
+
+EIGEN_STRONG_INLINE Packet4bf F32MaskToBf16Mask(const Packet4f& p) {
+ return vmovn_u32(vreinterpretq_u32_f32(p));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pset1<Packet4bf>(const bfloat16& from) {
+ return pset1<Packet4us>(from.value);
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 pfirst<Packet4bf>(const Packet4bf& from) {
+ return bfloat16_impl::raw_uint16_to_bfloat16(static_cast<uint16_t>(pfirst<Packet4us>(from)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pload<Packet4bf>(const bfloat16* from)
+{
+ return pload<Packet4us>(reinterpret_cast<const uint16_t*>(from));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf ploadu<Packet4bf>(const bfloat16* from)
+{
+ return ploadu<Packet4us>(reinterpret_cast<const uint16_t*>(from));
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<bfloat16>(bfloat16* to, const Packet4bf& from)
+{
+ EIGEN_DEBUG_ALIGNED_STORE vst1_u16(reinterpret_cast<uint16_t*>(to), from);
+}
+
+template<> EIGEN_STRONG_INLINE void pstoreu<bfloat16>(bfloat16* to, const Packet4bf& from)
+{
+ EIGEN_DEBUG_UNALIGNED_STORE vst1_u16(reinterpret_cast<uint16_t*>(to), from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf ploaddup<Packet4bf>(const bfloat16* from)
+{
+ return ploaddup<Packet4us>(reinterpret_cast<const uint16_t*>(from));
+}
+
+template <> EIGEN_STRONG_INLINE Packet4bf pabs(const Packet4bf& a) {
+ return F32ToBf16(pabs<Packet4f>(Bf16ToF32(a)));
+}
+
+template <> EIGEN_STRONG_INLINE Packet4bf pmin<PropagateNumbers, Packet4bf>(const Packet4bf &a,
+ const Packet4bf &b)
+{
+ return F32ToBf16(pmin<PropagateNumbers, Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+template <> EIGEN_STRONG_INLINE Packet4bf pmin<PropagateNaN, Packet4bf>(const Packet4bf &a,
+ const Packet4bf &b)
+{
+ return F32ToBf16(pmin<PropagateNaN, Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <> EIGEN_STRONG_INLINE Packet4bf pmin<Packet4bf>(const Packet4bf &a,
+ const Packet4bf &b)
+{
+ return F32ToBf16(pmin<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <> EIGEN_STRONG_INLINE Packet4bf pmax<PropagateNumbers, Packet4bf>(const Packet4bf &a,
+ const Packet4bf &b)
+{
+ return F32ToBf16(pmax<PropagateNumbers, Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+template <> EIGEN_STRONG_INLINE Packet4bf pmax<PropagateNaN, Packet4bf>(const Packet4bf &a,
+ const Packet4bf &b)
+{
+ return F32ToBf16(pmax<PropagateNaN, Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template <> EIGEN_STRONG_INLINE Packet4bf pmax<Packet4bf>(const Packet4bf &a,
+ const Packet4bf &b)
+{
+ return F32ToBf16(pmax<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf plset<Packet4bf>(const bfloat16& a)
+{
+ return F32ToBf16(plset<Packet4f>(static_cast<float>(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf por(const Packet4bf& a,const Packet4bf& b) {
+ return por<Packet4us>(a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pxor(const Packet4bf& a,const Packet4bf& b) {
+ return pxor<Packet4us>(a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pand(const Packet4bf& a,const Packet4bf& b) {
+ return pand<Packet4us>(a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pandnot(const Packet4bf& a,const Packet4bf& b) {
+ return pandnot<Packet4us>(a, b);
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4bf pselect(const Packet4bf& mask, const Packet4bf& a,
+ const Packet4bf& b)
+{
+ return pselect<Packet4us>(mask, a, b);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf print<Packet4bf>(const Packet4bf& a)
+{
+ return F32ToBf16(print<Packet4f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pfloor<Packet4bf>(const Packet4bf& a)
+{
+ return F32ToBf16(pfloor<Packet4f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pceil<Packet4bf>(const Packet4bf& a)
+{
+ return F32ToBf16(pceil<Packet4f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pconj(const Packet4bf& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet4bf padd<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
+ return F32ToBf16(padd<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf psub<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
+ return F32ToBf16(psub<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pmul<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
+ return F32ToBf16(pmul<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pdiv<Packet4bf>(const Packet4bf& a, const Packet4bf& b) {
+ return F32ToBf16(pdiv<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<>
+EIGEN_STRONG_INLINE Packet4bf pgather<bfloat16, Packet4bf>(const bfloat16* from, Index stride)
+{
+ return pgather<uint16_t, Packet4us>(reinterpret_cast<const uint16_t*>(from), stride);
+}
+
+template<>
+EIGEN_STRONG_INLINE void pscatter<bfloat16, Packet4bf>(bfloat16* to, const Packet4bf& from, Index stride)
+{
+ pscatter<uint16_t, Packet4us>(reinterpret_cast<uint16_t*>(to), from, stride);
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux<Packet4bf>(const Packet4bf& a)
+{
+ return static_cast<bfloat16>(predux<Packet4f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux_max<Packet4bf>(const Packet4bf& a)
+{
+ return static_cast<bfloat16>(predux_max<Packet4f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux_min<Packet4bf>(const Packet4bf& a)
+{
+ return static_cast<bfloat16>(predux_min<Packet4f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE bfloat16 predux_mul<Packet4bf>(const Packet4bf& a)
+{
+ return static_cast<bfloat16>(predux_mul<Packet4f>(Bf16ToF32(a)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf preverse<Packet4bf>(const Packet4bf& a)
+{
+ return preverse<Packet4us>(a);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4bf, 4>& kernel)
+{
+ detail::ptranspose_impl(kernel);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pabsdiff<Packet4bf>(const Packet4bf& a, const Packet4bf& b)
+{
+ return F32ToBf16(pabsdiff<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pcmp_eq<Packet4bf>(const Packet4bf& a, const Packet4bf& b)
+{
+ return F32MaskToBf16Mask(pcmp_eq<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pcmp_lt<Packet4bf>(const Packet4bf& a, const Packet4bf& b)
+{
+ return F32MaskToBf16Mask(pcmp_lt<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pcmp_lt_or_nan<Packet4bf>(const Packet4bf& a, const Packet4bf& b)
+{
+ return F32MaskToBf16Mask(pcmp_lt_or_nan<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pcmp_le<Packet4bf>(const Packet4bf& a, const Packet4bf& b)
+{
+ return F32MaskToBf16Mask(pcmp_le<Packet4f>(Bf16ToF32(a), Bf16ToF32(b)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4bf pnegate<Packet4bf>(const Packet4bf& a)
+{
+ return pxor<Packet4us>(a, pset1<Packet4us>(static_cast<uint16_t>(0x8000)));
+}
+
+//---------- double ----------
+
+// Clang 3.5 in the iOS toolchain has an ICE triggered by NEON intrisics for double.
+// Confirmed at least with __apple_build_version__ = 6000054.
+#ifdef __apple_build_version__
+// Let's hope that by the time __apple_build_version__ hits the 601* range, the bug will be fixed.
+// https://gist.github.com/yamaya/2924292 suggests that the 3 first digits are only updated with
+// major toolchain updates.
+#define EIGEN_APPLE_DOUBLE_NEON_BUG (__apple_build_version__ < 6010000)
+#else
+#define EIGEN_APPLE_DOUBLE_NEON_BUG 0
+#endif
+
+#if EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG
+
+// Bug 907: workaround missing declarations of the following two functions in the ADK
+// Defining these functions as templates ensures that if these intrinsics are
+// already defined in arm_neon.h, then our workaround doesn't cause a conflict
+// and has lower priority in overload resolution.
+template <typename T> uint64x2_t vreinterpretq_u64_f64(T a) { return (uint64x2_t) a; }
+
+template <typename T> float64x2_t vreinterpretq_f64_u64(T a) { return (float64x2_t) a; }
+
+typedef float64x2_t Packet2d;
+typedef float64x1_t Packet1d;
+
+// fuctionally equivalent to _mm_shuffle_pd in SSE (i.e. shuffle(m, n, mask) equals _mm_shuffle_pd(m,n,mask))
+// Currently used in LU/arch/InverseSize4.h to enable a shared implementation
+// for fast inversion of matrices of size 4.
+EIGEN_STRONG_INLINE Packet2d shuffle(const Packet2d& m, const Packet2d& n, int mask)
+{
+ const double* a = reinterpret_cast<const double*>(&m);
+ const double* b = reinterpret_cast<const double*>(&n);
+ Packet2d res = {*(a + (mask & 1)), *(b + ((mask >> 1) & 1))};
+ return res;
+}
+
+EIGEN_STRONG_INLINE Packet2d vec2d_swizzle2(const Packet2d& a, const Packet2d& b, int mask)
+{
+ return shuffle(a, b, mask);
+}
+EIGEN_STRONG_INLINE Packet2d vec2d_unpacklo(const Packet2d& a,const Packet2d& b)
+{
+ return shuffle(a, b, 0);
+}
+EIGEN_STRONG_INLINE Packet2d vec2d_unpackhi(const Packet2d& a,const Packet2d& b)
+{
+ return shuffle(a, b, 3);
+}
+#define vec2d_duplane(a, p) \
+ vdupq_laneq_f64(a, p)
+
+template<> struct packet_traits<double> : default_packet_traits
+{
+ typedef Packet2d type;
+ typedef Packet2d half;
+ enum
+ {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 2,
+ HasHalfPacket = 0,
+
+ HasCmp = 1,
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasAbsDiff = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0,
+
+ HasDiv = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1,
+
+ HasSin = 0,
+ HasCos = 0,
+ HasLog = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasTanh = 0,
+ HasErf = 0
+ };
+};
+
+template<> struct unpacket_traits<Packet2d>
+{
+ typedef double type;
+ typedef Packet2d half;
+ typedef Packet2l integer_packet;
+ enum
+ {
+ size = 2,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { return vdupq_n_f64(from); }
+
+template<> EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a)
+{
+ const double c[] = {0.0,1.0};
+ return vaddq_f64(pset1<Packet2d>(a), vld1q_f64(c));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return vaddq_f64(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return vsubq_f64(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& , const Packet2d& );
+template<> EIGEN_STRONG_INLINE Packet2d paddsub<Packet2d>(const Packet2d& a, const Packet2d& b){
+ const Packet2d mask = {numext::bit_cast<double>(0x8000000000000000ull),0.0};
+ return padd(a, pxor(mask, b));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) { return vnegq_f64(a); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return vmulq_f64(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return vdivq_f64(a,b); }
+
+#ifdef __ARM_FEATURE_FMA
+// See bug 936. See above comment about FMA for float.
+template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c)
+{ return vfmaq_f64(c,a,b); }
+#else
+template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c)
+{ return vmlaq_f64(c,a,b); }
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) { return vminq_f64(a,b); }
+
+#ifdef __ARM_FEATURE_NUMERIC_MAXMIN
+// numeric max and min are only available if ARM_FEATURE_NUMERIC_MAXMIN is defined (which can only be the case for Armv8 systems).
+template<> EIGEN_STRONG_INLINE Packet2d pmin<PropagateNumbers, Packet2d>(const Packet2d& a, const Packet2d& b) { return vminnmq_f64(a, b); }
+template<> EIGEN_STRONG_INLINE Packet2d pmax<PropagateNumbers, Packet2d>(const Packet2d& a, const Packet2d& b) { return vmaxnmq_f64(a, b); }
+
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet2d pmin<PropagateNaN, Packet2d>(const Packet2d& a, const Packet2d& b) { return pmin<Packet2d>(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) { return vmaxq_f64(a,b); }
+
+
+template<> EIGEN_STRONG_INLINE Packet2d pmax<PropagateNaN, Packet2d>(const Packet2d& a, const Packet2d& b) { return pmax<Packet2d>(a, b); }
+
+// Logical Operations are not supported for float, so we have to reinterpret casts using NEON intrinsics
+template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b)
+{ return vreinterpretq_f64_u64(vandq_u64(vreinterpretq_u64_f64(a),vreinterpretq_u64_f64(b))); }
+
+template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b)
+{ return vreinterpretq_f64_u64(vorrq_u64(vreinterpretq_u64_f64(a),vreinterpretq_u64_f64(b))); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b)
+{ return vreinterpretq_f64_u64(veorq_u64(vreinterpretq_u64_f64(a),vreinterpretq_u64_f64(b))); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b)
+{ return vreinterpretq_f64_u64(vbicq_u64(vreinterpretq_u64_f64(a),vreinterpretq_u64_f64(b))); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_le(const Packet2d& a, const Packet2d& b)
+{ return vreinterpretq_f64_u64(vcleq_f64(a,b)); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_lt(const Packet2d& a, const Packet2d& b)
+{ return vreinterpretq_f64_u64(vcltq_f64(a,b)); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_lt_or_nan(const Packet2d& a, const Packet2d& b)
+{ return vreinterpretq_f64_u32(vmvnq_u32(vreinterpretq_u32_u64(vcgeq_f64(a,b)))); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_eq(const Packet2d& a, const Packet2d& b)
+{ return vreinterpretq_f64_u64(vceqq_f64(a,b)); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_f64(from); }
+
+template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_f64(from); }
+
+template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from) { return vld1q_dup_f64(from); }
+template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from)
+{ EIGEN_DEBUG_ALIGNED_STORE vst1q_f64(to,from); }
+
+template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from)
+{ EIGEN_DEBUG_UNALIGNED_STORE vst1q_f64(to,from); }
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2d pgather<double, Packet2d>(const double* from, Index stride)
+{
+ Packet2d res = pset1<Packet2d>(0.0);
+ res = vld1q_lane_f64(from + 0*stride, res, 0);
+ res = vld1q_lane_f64(from + 1*stride, res, 1);
+ return res;
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride)
+{
+ vst1q_lane_f64(to + stride*0, from, 0);
+ vst1q_lane_f64(to + stride*1, from, 1);
+}
+
+template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { EIGEN_ARM_PREFETCH(addr); }
+
+// FIXME only store the 2 first elements ?
+template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { return vgetq_lane_f64(a,0); }
+
+template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a)
+{ return vcombine_f64(vget_high_f64(a), vget_low_f64(a)); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a) { return vabsq_f64(a); }
+
+#if EIGEN_COMP_CLANG && defined(__apple_build_version__)
+// workaround ICE, see bug 907
+template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a)
+{ return (vget_low_f64(a) + vget_high_f64(a))[0]; }
+#else
+template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a)
+{ return vget_lane_f64(vget_low_f64(a) + vget_high_f64(a), 0); }
+#endif
+
+// Other reduction functions:
+// mul
+#if EIGEN_COMP_CLANG && defined(__apple_build_version__)
+template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a)
+{ return (vget_low_f64(a) * vget_high_f64(a))[0]; }
+#else
+template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a)
+{ return vget_lane_f64(vget_low_f64(a) * vget_high_f64(a), 0); }
+#endif
+
+// min
+template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a)
+{ return vgetq_lane_f64(vpminq_f64(a,a), 0); }
+
+// max
+template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a)
+{ return vgetq_lane_f64(vpmaxq_f64(a,a), 0); }
+
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet2d, 2>& kernel)
+{
+ const float64x2_t tmp1 = vzip1q_f64(kernel.packet[0], kernel.packet[1]);
+ const float64x2_t tmp2 = vzip2q_f64(kernel.packet[0], kernel.packet[1]);
+
+ kernel.packet[0] = tmp1;
+ kernel.packet[1] = tmp2;
+}
+
+template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet2d pselect( const Packet2d& mask, const Packet2d& a, const Packet2d& b)
+{ return vbslq_f64(vreinterpretq_u64_f64(mask), a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet2d print<Packet2d>(const Packet2d& a)
+{ return vrndnq_f64(a); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a)
+{ return vrndmq_f64(a); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a)
+{ return vrndpq_f64(a); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pldexp<Packet2d>(const Packet2d& a, const Packet2d& exponent)
+{ return pldexp_generic(a, exponent); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pfrexp<Packet2d>(const Packet2d& a, Packet2d& exponent)
+{ return pfrexp_generic(a,exponent); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pset1frombits<Packet2d>(uint64_t from)
+{ return vreinterpretq_f64_u64(vdupq_n_u64(from)); }
+
+template<> EIGEN_STRONG_INLINE Packet2d prsqrt(const Packet2d& a) {
+ // Compute approximate reciprocal sqrt.
+ Packet2d x = vrsqrteq_f64(a);
+ // Do Newton iterations for 1/sqrt(x).
+ x = vmulq_f64(vrsqrtsq_f64(vmulq_f64(a, x), x), x);
+ x = vmulq_f64(vrsqrtsq_f64(vmulq_f64(a, x), x), x);
+ x = vmulq_f64(vrsqrtsq_f64(vmulq_f64(a, x), x), x);
+ const Packet2d infinity = pset1<Packet2d>(NumTraits<double>::infinity());
+ return pselect(pcmp_eq(a, pzero(a)), infinity, x);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d psqrt(const Packet2d& _x){ return vsqrtq_f64(_x); }
+
+#endif // EIGEN_ARCH_ARM64
+
+// Do we have an fp16 types and supporting Neon intrinsics?
+#if EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC
+typedef float16x4_t Packet4hf;
+typedef float16x8_t Packet8hf;
+
+template <>
+struct packet_traits<Eigen::half> : default_packet_traits {
+ typedef Packet8hf type;
+ typedef Packet4hf half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 8,
+ HasHalfPacket = 1,
+
+ HasCmp = 1,
+ HasCast = 1,
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasAbsDiff = 0,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0,
+ HasInsert = 1,
+ HasReduxp = 1,
+ HasDiv = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasRint = 1,
+ HasSin = 0,
+ HasCos = 0,
+ HasLog = 0,
+ HasExp = 0,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasErf = EIGEN_FAST_MATH,
+ HasBessel = 0, // Issues with accuracy.
+ HasNdtri = 0
+ };
+};
+
+template <>
+struct unpacket_traits<Packet4hf> {
+ typedef Eigen::half type;
+ typedef Packet4hf half;
+ enum {
+ size = 4,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+
+template <>
+struct unpacket_traits<Packet8hf> {
+ typedef Eigen::half type;
+ typedef Packet4hf half;
+ enum {
+ size = 8,
+ alignment = Aligned16,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4hf predux_half_dowto4<Packet8hf>(const Packet8hf& a) {
+ return vadd_f16(vget_low_f16(a), vget_high_f16(a));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pset1<Packet8hf>(const Eigen::half& from) {
+ return vdupq_n_f16(from.x);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pset1<Packet4hf>(const Eigen::half& from) {
+ return vdup_n_f16(from.x);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf plset<Packet8hf>(const Eigen::half& a) {
+ const float16_t f[] = {0, 1, 2, 3, 4, 5, 6, 7};
+ Packet8hf countdown = vld1q_f16(f);
+ return vaddq_f16(pset1<Packet8hf>(a), countdown);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf plset<Packet4hf>(const Eigen::half& a) {
+ const float16_t f[] = {0, 1, 2, 3};
+ Packet4hf countdown = vld1_f16(f);
+ return vadd_f16(pset1<Packet4hf>(a), countdown);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf padd<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
+ return vaddq_f16(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf padd<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
+ return vadd_f16(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf psub<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
+ return vsubq_f16(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf psub<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
+ return vsub_f16(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pnegate(const Packet8hf& a) {
+ return vnegq_f16(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pnegate(const Packet4hf& a) {
+ return vneg_f16(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pconj(const Packet8hf& a) {
+ return a;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pconj(const Packet4hf& a) {
+ return a;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pmul<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
+ return vmulq_f16(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pmul<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
+ return vmul_f16(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pdiv<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
+ return vdivq_f16(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pdiv<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
+ return vdiv_f16(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pmadd(const Packet8hf& a, const Packet8hf& b, const Packet8hf& c) {
+ return vfmaq_f16(c, a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pmadd(const Packet4hf& a, const Packet4hf& b, const Packet4hf& c) {
+ return vfma_f16(c, a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pmin<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
+ return vminq_f16(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pmin<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
+ return vmin_f16(a, b);
+}
+
+#ifdef __ARM_FEATURE_NUMERIC_MAXMIN
+// numeric max and min are only available if ARM_FEATURE_NUMERIC_MAXMIN is defined (which can only be the case for Armv8 systems).
+template<> EIGEN_STRONG_INLINE Packet4hf pmin<PropagateNumbers, Packet4hf>(const Packet4hf& a, const Packet4hf& b) { return vminnm_f16(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8hf pmin<PropagateNumbers, Packet8hf>(const Packet8hf& a, const Packet8hf& b) { return vminnmq_f16(a, b); }
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet4hf pmin<PropagateNaN, Packet4hf>(const Packet4hf& a, const Packet4hf& b) { return pmin<Packet4hf>(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet8hf pmin<PropagateNaN, Packet8hf>(const Packet8hf& a, const Packet8hf& b) { return pmin<Packet8hf>(a, b); }
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pmax<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
+ return vmaxq_f16(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pmax<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
+ return vmax_f16(a, b);
+}
+
+#ifdef __ARM_FEATURE_NUMERIC_MAXMIN
+// numeric max and min are only available if ARM_FEATURE_NUMERIC_MAXMIN is defined (which can only be the case for Armv8 systems).
+template<> EIGEN_STRONG_INLINE Packet4hf pmax<PropagateNumbers, Packet4hf>(const Packet4hf& a, const Packet4hf& b) { return vmaxnm_f16(a, b); }
+template<> EIGEN_STRONG_INLINE Packet8hf pmax<PropagateNumbers, Packet8hf>(const Packet8hf& a, const Packet8hf& b) { return vmaxnmq_f16(a, b); }
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet4hf pmax<PropagateNaN, Packet4hf>(const Packet4hf& a, const Packet4hf& b) { return pmax<Packet4hf>(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet8hf pmax<PropagateNaN, Packet8hf>(const Packet8hf& a, const Packet8hf& b) { return pmax<Packet8hf>(a, b); }
+
+#define EIGEN_MAKE_ARM_FP16_CMP_8(name) \
+ template <> \
+ EIGEN_STRONG_INLINE Packet8hf pcmp_##name(const Packet8hf& a, const Packet8hf& b) { \
+ return vreinterpretq_f16_u16(vc##name##q_f16(a, b)); \
+ }
+
+#define EIGEN_MAKE_ARM_FP16_CMP_4(name) \
+ template <> \
+ EIGEN_STRONG_INLINE Packet4hf pcmp_##name(const Packet4hf& a, const Packet4hf& b) { \
+ return vreinterpret_f16_u16(vc##name##_f16(a, b)); \
+ }
+
+EIGEN_MAKE_ARM_FP16_CMP_8(eq)
+EIGEN_MAKE_ARM_FP16_CMP_8(lt)
+EIGEN_MAKE_ARM_FP16_CMP_8(le)
+
+EIGEN_MAKE_ARM_FP16_CMP_4(eq)
+EIGEN_MAKE_ARM_FP16_CMP_4(lt)
+EIGEN_MAKE_ARM_FP16_CMP_4(le)
+
+#undef EIGEN_MAKE_ARM_FP16_CMP_8
+#undef EIGEN_MAKE_ARM_FP16_CMP_4
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pcmp_lt_or_nan<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
+ return vreinterpretq_f16_u16(vmvnq_u16(vcgeq_f16(a, b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pcmp_lt_or_nan<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
+ return vreinterpret_f16_u16(vmvn_u16(vcge_f16(a, b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf print<Packet8hf>(const Packet8hf& a)
+{ return vrndnq_f16(a); }
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf print<Packet4hf>(const Packet4hf& a)
+{ return vrndn_f16(a); }
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pfloor<Packet8hf>(const Packet8hf& a)
+{ return vrndmq_f16(a); }
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pfloor<Packet4hf>(const Packet4hf& a)
+{ return vrndm_f16(a); }
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pceil<Packet8hf>(const Packet8hf& a)
+{ return vrndpq_f16(a); }
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pceil<Packet4hf>(const Packet4hf& a)
+{ return vrndp_f16(a); }
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf psqrt<Packet8hf>(const Packet8hf& a) {
+ return vsqrtq_f16(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf psqrt<Packet4hf>(const Packet4hf& a) {
+ return vsqrt_f16(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pand<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
+ return vreinterpretq_f16_u16(vandq_u16(vreinterpretq_u16_f16(a), vreinterpretq_u16_f16(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pand<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
+ return vreinterpret_f16_u16(vand_u16(vreinterpret_u16_f16(a), vreinterpret_u16_f16(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf por<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
+ return vreinterpretq_f16_u16(vorrq_u16(vreinterpretq_u16_f16(a), vreinterpretq_u16_f16(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf por<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
+ return vreinterpret_f16_u16(vorr_u16(vreinterpret_u16_f16(a), vreinterpret_u16_f16(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pxor<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
+ return vreinterpretq_f16_u16(veorq_u16(vreinterpretq_u16_f16(a), vreinterpretq_u16_f16(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pxor<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
+ return vreinterpret_f16_u16(veor_u16(vreinterpret_u16_f16(a), vreinterpret_u16_f16(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pandnot<Packet8hf>(const Packet8hf& a, const Packet8hf& b) {
+ return vreinterpretq_f16_u16(vbicq_u16(vreinterpretq_u16_f16(a), vreinterpretq_u16_f16(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pandnot<Packet4hf>(const Packet4hf& a, const Packet4hf& b) {
+ return vreinterpret_f16_u16(vbic_u16(vreinterpret_u16_f16(a), vreinterpret_u16_f16(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pload<Packet8hf>(const Eigen::half* from) {
+ EIGEN_DEBUG_ALIGNED_LOAD return vld1q_f16(reinterpret_cast<const float16_t*>(from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pload<Packet4hf>(const Eigen::half* from) {
+ EIGEN_DEBUG_ALIGNED_LOAD return vld1_f16(reinterpret_cast<const float16_t*>(from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf ploadu<Packet8hf>(const Eigen::half* from) {
+ EIGEN_DEBUG_UNALIGNED_LOAD return vld1q_f16(reinterpret_cast<const float16_t*>(from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf ploadu<Packet4hf>(const Eigen::half* from) {
+ EIGEN_DEBUG_UNALIGNED_LOAD return vld1_f16(reinterpret_cast<const float16_t*>(from));
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf ploaddup<Packet8hf>(const Eigen::half* from) {
+ Packet8hf packet;
+ packet[0] = from[0].x;
+ packet[1] = from[0].x;
+ packet[2] = from[1].x;
+ packet[3] = from[1].x;
+ packet[4] = from[2].x;
+ packet[5] = from[2].x;
+ packet[6] = from[3].x;
+ packet[7] = from[3].x;
+ return packet;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf ploaddup<Packet4hf>(const Eigen::half* from) {
+ float16x4_t packet;
+ float16_t* tmp;
+ tmp = (float16_t*)&packet;
+ tmp[0] = from[0].x;
+ tmp[1] = from[0].x;
+ tmp[2] = from[1].x;
+ tmp[3] = from[1].x;
+ return packet;
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf ploadquad<Packet8hf>(const Eigen::half* from) {
+ Packet4hf lo, hi;
+ lo = vld1_dup_f16(reinterpret_cast<const float16_t*>(from));
+ hi = vld1_dup_f16(reinterpret_cast<const float16_t*>(from+1));
+ return vcombine_f16(lo, hi);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8hf pinsertfirst(const Packet8hf& a, Eigen::half b) { return vsetq_lane_f16(b.x, a, 0); }
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4hf pinsertfirst(const Packet4hf& a, Eigen::half b) { return vset_lane_f16(b.x, a, 0); }
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8hf pselect(const Packet8hf& mask, const Packet8hf& a, const Packet8hf& b) {
+ return vbslq_f16(vreinterpretq_u16_f16(mask), a, b);
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4hf pselect(const Packet4hf& mask, const Packet4hf& a, const Packet4hf& b) {
+ return vbsl_f16(vreinterpret_u16_f16(mask), a, b);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8hf pinsertlast(const Packet8hf& a, Eigen::half b) { return vsetq_lane_f16(b.x, a, 7); }
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4hf pinsertlast(const Packet4hf& a, Eigen::half b) { return vset_lane_f16(b.x, a, 3); }
+
+template <>
+EIGEN_STRONG_INLINE void pstore<Eigen::half>(Eigen::half* to, const Packet8hf& from) {
+ EIGEN_DEBUG_ALIGNED_STORE vst1q_f16(reinterpret_cast<float16_t*>(to), from);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstore<Eigen::half>(Eigen::half* to, const Packet4hf& from) {
+ EIGEN_DEBUG_ALIGNED_STORE vst1_f16(reinterpret_cast<float16_t*>(to), from);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstoreu<Eigen::half>(Eigen::half* to, const Packet8hf& from) {
+ EIGEN_DEBUG_UNALIGNED_STORE vst1q_f16(reinterpret_cast<float16_t*>(to), from);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstoreu<Eigen::half>(Eigen::half* to, const Packet4hf& from) {
+ EIGEN_DEBUG_UNALIGNED_STORE vst1_f16(reinterpret_cast<float16_t*>(to), from);
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet8hf pgather<Eigen::half, Packet8hf>(const Eigen::half* from, Index stride) {
+ Packet8hf res = pset1<Packet8hf>(Eigen::half(0.f));
+ res = vsetq_lane_f16(from[0 * stride].x, res, 0);
+ res = vsetq_lane_f16(from[1 * stride].x, res, 1);
+ res = vsetq_lane_f16(from[2 * stride].x, res, 2);
+ res = vsetq_lane_f16(from[3 * stride].x, res, 3);
+ res = vsetq_lane_f16(from[4 * stride].x, res, 4);
+ res = vsetq_lane_f16(from[5 * stride].x, res, 5);
+ res = vsetq_lane_f16(from[6 * stride].x, res, 6);
+ res = vsetq_lane_f16(from[7 * stride].x, res, 7);
+ return res;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet4hf pgather<Eigen::half, Packet4hf>(const Eigen::half* from, Index stride) {
+ Packet4hf res = pset1<Packet4hf>(Eigen::half(0.f));
+ res = vset_lane_f16(from[0 * stride].x, res, 0);
+ res = vset_lane_f16(from[1 * stride].x, res, 1);
+ res = vset_lane_f16(from[2 * stride].x, res, 2);
+ res = vset_lane_f16(from[3 * stride].x, res, 3);
+ return res;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<Eigen::half, Packet8hf>(Eigen::half* to, const Packet8hf& from, Index stride) {
+ to[stride * 0].x = vgetq_lane_f16(from, 0);
+ to[stride * 1].x = vgetq_lane_f16(from, 1);
+ to[stride * 2].x = vgetq_lane_f16(from, 2);
+ to[stride * 3].x = vgetq_lane_f16(from, 3);
+ to[stride * 4].x = vgetq_lane_f16(from, 4);
+ to[stride * 5].x = vgetq_lane_f16(from, 5);
+ to[stride * 6].x = vgetq_lane_f16(from, 6);
+ to[stride * 7].x = vgetq_lane_f16(from, 7);
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<Eigen::half, Packet4hf>(Eigen::half* to, const Packet4hf& from, Index stride) {
+ to[stride * 0].x = vget_lane_f16(from, 0);
+ to[stride * 1].x = vget_lane_f16(from, 1);
+ to[stride * 2].x = vget_lane_f16(from, 2);
+ to[stride * 3].x = vget_lane_f16(from, 3);
+}
+
+template <>
+EIGEN_STRONG_INLINE void prefetch<Eigen::half>(const Eigen::half* addr) {
+ EIGEN_ARM_PREFETCH(addr);
+}
+
+template <>
+EIGEN_STRONG_INLINE Eigen::half pfirst<Packet8hf>(const Packet8hf& a) {
+ float16_t x[8];
+ vst1q_f16(x, a);
+ Eigen::half h;
+ h.x = x[0];
+ return h;
+}
+
+template <>
+EIGEN_STRONG_INLINE Eigen::half pfirst<Packet4hf>(const Packet4hf& a) {
+ float16_t x[4];
+ vst1_f16(x, a);
+ Eigen::half h;
+ h.x = x[0];
+ return h;
+}
+
+template<> EIGEN_STRONG_INLINE Packet8hf preverse(const Packet8hf& a) {
+ float16x4_t a_lo, a_hi;
+ Packet8hf a_r64;
+
+ a_r64 = vrev64q_f16(a);
+ a_lo = vget_low_f16(a_r64);
+ a_hi = vget_high_f16(a_r64);
+ return vcombine_f16(a_hi, a_lo);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf preverse<Packet4hf>(const Packet4hf& a) {
+ return vrev64_f16(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet8hf pabs<Packet8hf>(const Packet8hf& a) {
+ return vabsq_f16(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4hf pabs<Packet4hf>(const Packet4hf& a) {
+ return vabs_f16(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Eigen::half predux<Packet8hf>(const Packet8hf& a) {
+ float16x4_t a_lo, a_hi, sum;
+
+ a_lo = vget_low_f16(a);
+ a_hi = vget_high_f16(a);
+ sum = vpadd_f16(a_lo, a_hi);
+ sum = vpadd_f16(sum, sum);
+ sum = vpadd_f16(sum, sum);
+
+ Eigen::half h;
+ h.x = vget_lane_f16(sum, 0);
+ return h;
+}
+
+template <>
+EIGEN_STRONG_INLINE Eigen::half predux<Packet4hf>(const Packet4hf& a) {
+ float16x4_t sum;
+
+ sum = vpadd_f16(a, a);
+ sum = vpadd_f16(sum, sum);
+ Eigen::half h;
+ h.x = vget_lane_f16(sum, 0);
+ return h;
+}
+
+template <>
+EIGEN_STRONG_INLINE Eigen::half predux_mul<Packet8hf>(const Packet8hf& a) {
+ float16x4_t a_lo, a_hi, prod;
+
+ a_lo = vget_low_f16(a);
+ a_hi = vget_high_f16(a);
+ prod = vmul_f16(a_lo, a_hi);
+ prod = vmul_f16(prod, vrev64_f16(prod));
+
+ Eigen::half h;
+ h.x = vmulh_f16(vget_lane_f16(prod, 0), vget_lane_f16(prod, 1));
+ return h;
+}
+
+template <>
+EIGEN_STRONG_INLINE Eigen::half predux_mul<Packet4hf>(const Packet4hf& a) {
+ float16x4_t prod;
+ prod = vmul_f16(a, vrev64_f16(a));
+ Eigen::half h;
+ h.x = vmulh_f16(vget_lane_f16(prod, 0), vget_lane_f16(prod, 1));
+ return h;
+}
+
+template <>
+EIGEN_STRONG_INLINE Eigen::half predux_min<Packet8hf>(const Packet8hf& a) {
+ float16x4_t a_lo, a_hi, min;
+
+ a_lo = vget_low_f16(a);
+ a_hi = vget_high_f16(a);
+ min = vpmin_f16(a_lo, a_hi);
+ min = vpmin_f16(min, min);
+ min = vpmin_f16(min, min);
+
+ Eigen::half h;
+ h.x = vget_lane_f16(min, 0);
+ return h;
+}
+
+template <>
+EIGEN_STRONG_INLINE Eigen::half predux_min<Packet4hf>(const Packet4hf& a) {
+ Packet4hf tmp;
+ tmp = vpmin_f16(a, a);
+ tmp = vpmin_f16(tmp, tmp);
+ Eigen::half h;
+ h.x = vget_lane_f16(tmp, 0);
+ return h;
+}
+
+template <>
+EIGEN_STRONG_INLINE Eigen::half predux_max<Packet8hf>(const Packet8hf& a) {
+ float16x4_t a_lo, a_hi, max;
+
+ a_lo = vget_low_f16(a);
+ a_hi = vget_high_f16(a);
+ max = vpmax_f16(a_lo, a_hi);
+ max = vpmax_f16(max, max);
+ max = vpmax_f16(max, max);
+
+ Eigen::half h;
+ h.x = vget_lane_f16(max, 0);
+ return h;
+}
+
+template <>
+EIGEN_STRONG_INLINE Eigen::half predux_max<Packet4hf>(const Packet4hf& a) {
+ Packet4hf tmp;
+ tmp = vpmax_f16(a, a);
+ tmp = vpmax_f16(tmp, tmp);
+ Eigen::half h;
+ h.x = vget_lane_f16(tmp, 0);
+ return h;
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8hf, 4>& kernel)
+{
+ const float16x8x2_t zip16_1 = vzipq_f16(kernel.packet[0], kernel.packet[1]);
+ const float16x8x2_t zip16_2 = vzipq_f16(kernel.packet[2], kernel.packet[3]);
+
+ const float32x4x2_t zip32_1 = vzipq_f32(vreinterpretq_f32_f16(zip16_1.val[0]), vreinterpretq_f32_f16(zip16_2.val[0]));
+ const float32x4x2_t zip32_2 = vzipq_f32(vreinterpretq_f32_f16(zip16_1.val[1]), vreinterpretq_f32_f16(zip16_2.val[1]));
+
+ kernel.packet[0] = vreinterpretq_f16_f32(zip32_1.val[0]);
+ kernel.packet[1] = vreinterpretq_f16_f32(zip32_1.val[1]);
+ kernel.packet[2] = vreinterpretq_f16_f32(zip32_2.val[0]);
+ kernel.packet[3] = vreinterpretq_f16_f32(zip32_2.val[1]);
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet4hf, 4>& kernel) {
+ EIGEN_ALIGN16 float16x4x4_t tmp_x4;
+ float16_t* tmp = (float16_t*)&kernel;
+ tmp_x4 = vld4_f16(tmp);
+
+ kernel.packet[0] = tmp_x4.val[0];
+ kernel.packet[1] = tmp_x4.val[1];
+ kernel.packet[2] = tmp_x4.val[2];
+ kernel.packet[3] = tmp_x4.val[3];
+}
+
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet8hf, 8>& kernel) {
+ float16x8x2_t T_1[4];
+
+ T_1[0] = vuzpq_f16(kernel.packet[0], kernel.packet[1]);
+ T_1[1] = vuzpq_f16(kernel.packet[2], kernel.packet[3]);
+ T_1[2] = vuzpq_f16(kernel.packet[4], kernel.packet[5]);
+ T_1[3] = vuzpq_f16(kernel.packet[6], kernel.packet[7]);
+
+ float16x8x2_t T_2[4];
+ T_2[0] = vuzpq_f16(T_1[0].val[0], T_1[1].val[0]);
+ T_2[1] = vuzpq_f16(T_1[0].val[1], T_1[1].val[1]);
+ T_2[2] = vuzpq_f16(T_1[2].val[0], T_1[3].val[0]);
+ T_2[3] = vuzpq_f16(T_1[2].val[1], T_1[3].val[1]);
+
+ float16x8x2_t T_3[4];
+ T_3[0] = vuzpq_f16(T_2[0].val[0], T_2[2].val[0]);
+ T_3[1] = vuzpq_f16(T_2[0].val[1], T_2[2].val[1]);
+ T_3[2] = vuzpq_f16(T_2[1].val[0], T_2[3].val[0]);
+ T_3[3] = vuzpq_f16(T_2[1].val[1], T_2[3].val[1]);
+
+ kernel.packet[0] = T_3[0].val[0];
+ kernel.packet[1] = T_3[2].val[0];
+ kernel.packet[2] = T_3[1].val[0];
+ kernel.packet[3] = T_3[3].val[0];
+ kernel.packet[4] = T_3[0].val[1];
+ kernel.packet[5] = T_3[2].val[1];
+ kernel.packet[6] = T_3[1].val[1];
+ kernel.packet[7] = T_3[3].val[1];
+}
+#endif // end EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PACKET_MATH_NEON_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/TypeCasting.h b/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/TypeCasting.h
new file mode 100644
index 000000000..54f97336e
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/NEON/TypeCasting.h
@@ -0,0 +1,1419 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2018 Rasmus Munk Larsen <rmlarsen@google.com>
+// Copyright (C) 2020 Antonio Sanchez <cantonios@google.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TYPE_CASTING_NEON_H
+#define EIGEN_TYPE_CASTING_NEON_H
+
+namespace Eigen {
+
+namespace internal {
+
+//==============================================================================
+// pcast, SrcType = float
+//==============================================================================
+template <>
+struct type_casting_traits<float, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4f pcast<Packet4f, Packet4f>(const Packet4f& a) {
+ return a;
+}
+template <>
+EIGEN_STRONG_INLINE Packet2f pcast<Packet2f, Packet2f>(const Packet2f& a) {
+ return a;
+}
+
+template <>
+struct type_casting_traits<float, numext::int64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+struct type_casting_traits<float, numext::uint64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+// If float64 exists, first convert to that to keep as much precision as possible.
+#if EIGEN_ARCH_ARM64
+template <>
+EIGEN_STRONG_INLINE Packet2l pcast<Packet4f, Packet2l>(const Packet4f& a) {
+ // Discard second half of input.
+ return vcvtq_s64_f64(vcvt_f64_f32(vget_low_f32(a)));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ul pcast<Packet4f, Packet2ul>(const Packet4f& a) {
+ // Discard second half of input.
+ return vcvtq_u64_f64(vcvt_f64_f32(vget_low_f32(a)));
+}
+#else
+template <>
+EIGEN_STRONG_INLINE Packet2l pcast<Packet4f, Packet2l>(const Packet4f& a) {
+ // Discard second half of input.
+ return vmovl_s32(vget_low_s32(vcvtq_s32_f32(a)));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ul pcast<Packet4f, Packet2ul>(const Packet4f& a) {
+ // Discard second half of input.
+ return vmovl_u32(vget_low_u32(vcvtq_u32_f32(a)));
+}
+#endif // EIGEN_ARCH_ARM64
+
+template <>
+struct type_casting_traits<float, numext::int32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4i pcast<Packet4f, Packet4i>(const Packet4f& a) {
+ return vcvtq_s32_f32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2i pcast<Packet2f, Packet2i>(const Packet2f& a) {
+ return vcvt_s32_f32(a);
+}
+
+template <>
+struct type_casting_traits<float, numext::uint32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4ui pcast<Packet4f, Packet4ui>(const Packet4f& a) {
+ return vcvtq_u32_f32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ui pcast<Packet2f, Packet2ui>(const Packet2f& a) {
+ return vcvt_u32_f32(a);
+}
+
+template <>
+struct type_casting_traits<float, numext::int16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8s pcast<Packet4f, Packet8s>(const Packet4f& a, const Packet4f& b) {
+ return vcombine_s16(vmovn_s32(vcvtq_s32_f32(a)), vmovn_s32(vcvtq_s32_f32(b)));
+}
+template <>
+EIGEN_STRONG_INLINE Packet4s pcast<Packet2f, Packet4s>(const Packet2f& a, const Packet2f& b) {
+ return vmovn_s32(vcombine_s32(vcvt_s32_f32(a), vcvt_s32_f32(b)));
+}
+
+template <>
+struct type_casting_traits<float, numext::uint16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8us pcast<Packet4f, Packet8us>(const Packet4f& a, const Packet4f& b) {
+ return vcombine_u16(vmovn_u32(vcvtq_u32_f32(a)), vmovn_u32(vcvtq_u32_f32(b)));
+}
+template <>
+EIGEN_STRONG_INLINE Packet4us pcast<Packet2f, Packet4us>(const Packet2f& a, const Packet2f& b) {
+ return vmovn_u32(vcombine_u32(vcvt_u32_f32(a), vcvt_u32_f32(b)));
+}
+
+template <>
+struct type_casting_traits<float, numext::int8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16c pcast<Packet4f, Packet16c>(const Packet4f& a, const Packet4f& b, const Packet4f& c,
+ const Packet4f& d) {
+ const int16x8_t ab_s16 = pcast<Packet4f, Packet8s>(a, b);
+ const int16x8_t cd_s16 = pcast<Packet4f, Packet8s>(c, d);
+ return vcombine_s8(vmovn_s16(ab_s16), vmovn_s16(cd_s16));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8c pcast<Packet2f, Packet8c>(const Packet2f& a, const Packet2f& b, const Packet2f& c,
+ const Packet2f& d) {
+ const int16x4_t ab_s16 = pcast<Packet2f, Packet4s>(a, b);
+ const int16x4_t cd_s16 = pcast<Packet2f, Packet4s>(c, d);
+ return vmovn_s16(vcombine_s16(ab_s16, cd_s16));
+}
+
+template <>
+struct type_casting_traits<float, numext::uint8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16uc pcast<Packet4f, Packet16uc>(const Packet4f& a, const Packet4f& b, const Packet4f& c,
+ const Packet4f& d) {
+ const uint16x8_t ab_u16 = pcast<Packet4f, Packet8us>(a, b);
+ const uint16x8_t cd_u16 = pcast<Packet4f, Packet8us>(c, d);
+ return vcombine_u8(vmovn_u16(ab_u16), vmovn_u16(cd_u16));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8uc pcast<Packet2f, Packet8uc>(const Packet2f& a, const Packet2f& b, const Packet2f& c,
+ const Packet2f& d) {
+ const uint16x4_t ab_u16 = pcast<Packet2f, Packet4us>(a, b);
+ const uint16x4_t cd_u16 = pcast<Packet2f, Packet4us>(c, d);
+ return vmovn_u16(vcombine_u16(ab_u16, cd_u16));
+}
+
+//==============================================================================
+// pcast, SrcType = int8_t
+//==============================================================================
+template <>
+struct type_casting_traits<numext::int8_t, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4f pcast<Packet16c, Packet4f>(const Packet16c& a) {
+ // Discard all but first 4 bytes.
+ return vcvtq_f32_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_low_s8(a)))));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2f pcast<Packet8c, Packet2f>(const Packet8c& a) {
+ // Discard all but first 2 bytes.
+ return vcvt_f32_s32(vget_low_s32(vmovl_s16(vget_low_s16(vmovl_s8(a)))));
+}
+
+template <>
+struct type_casting_traits<numext::int8_t, numext::int64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2l pcast<Packet16c, Packet2l>(const Packet16c& a) {
+ // Discard all but first two bytes.
+ return vmovl_s32(vget_low_s32(vmovl_s16(vget_low_s16(vmovl_s8(vget_low_s8(a))))));
+}
+
+template <>
+struct type_casting_traits<numext::int8_t, numext::uint64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2ul pcast<Packet16c, Packet2ul>(const Packet16c& a) {
+ return vreinterpretq_u64_s64(pcast<Packet16c, Packet2l>(a));
+}
+
+template <>
+struct type_casting_traits<numext::int8_t, numext::int32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4i pcast<Packet16c, Packet4i>(const Packet16c& a) {
+ // Discard all but first 4 bytes.
+ return vmovl_s16(vget_low_s16(vmovl_s8(vget_low_s8(a))));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2i pcast<Packet8c, Packet2i>(const Packet8c& a) {
+ // Discard all but first 2 bytes.
+ return vget_low_s32(vmovl_s16(vget_low_s16(vmovl_s8(a))));
+}
+
+template <>
+struct type_casting_traits<numext::int8_t, numext::uint32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4ui pcast<Packet16c, Packet4ui>(const Packet16c& a) {
+ return vreinterpretq_u32_s32(pcast<Packet16c, Packet4i>(a));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ui pcast<Packet8c, Packet2ui>(const Packet8c& a) {
+ return vreinterpret_u32_s32(pcast<Packet8c, Packet2i>(a));
+}
+
+template <>
+struct type_casting_traits<numext::int8_t, numext::int16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8s pcast<Packet16c, Packet8s>(const Packet16c& a) {
+ // Discard second half of input.
+ return vmovl_s8(vget_low_s8(a));
+}
+template <>
+EIGEN_STRONG_INLINE Packet4s pcast<Packet8c, Packet4s>(const Packet8c& a) {
+ // Discard second half of input.
+ return vget_low_s16(vmovl_s8(a));
+}
+
+template <>
+struct type_casting_traits<numext::int8_t, numext::uint16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8us pcast<Packet16c, Packet8us>(const Packet16c& a) {
+ return vreinterpretq_u16_s16(pcast<Packet16c, Packet8s>(a));
+}
+template <>
+EIGEN_STRONG_INLINE Packet4us pcast<Packet8c, Packet4us>(const Packet8c& a) {
+ return vreinterpret_u16_s16(pcast<Packet8c, Packet4s>(a));
+}
+
+template <>
+struct type_casting_traits<numext::int8_t, numext::int8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16c pcast<Packet16c, Packet16c>(const Packet16c& a) {
+ return a;
+}
+template <>
+EIGEN_STRONG_INLINE Packet8c pcast<Packet8c, Packet8c>(const Packet8c& a) {
+ return a;
+}
+template <>
+EIGEN_STRONG_INLINE Packet4c pcast<Packet4c, Packet4c>(const Packet4c& a) {
+ return a;
+}
+
+template <>
+struct type_casting_traits<numext::int8_t, numext::uint8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16uc pcast<Packet16c, Packet16uc>(const Packet16c& a) {
+ return vreinterpretq_u8_s8(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8uc pcast<Packet8c, Packet8uc>(const Packet8c& a) {
+ return vreinterpret_u8_s8(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet4uc pcast<Packet4c, Packet4uc>(const Packet4c& a) {
+ return static_cast<Packet4uc>(a);
+}
+
+//==============================================================================
+// pcast, SrcType = uint8_t
+//==============================================================================
+template <>
+struct type_casting_traits<numext::uint8_t, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4f pcast<Packet16uc, Packet4f>(const Packet16uc& a) {
+ // Discard all but first 4 bytes.
+ return vcvtq_f32_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(a)))));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2f pcast<Packet8uc, Packet2f>(const Packet8uc& a) {
+ // Discard all but first 2 bytes.
+ return vcvt_f32_u32(vget_low_u32(vmovl_u16(vget_low_u16(vmovl_u8(a)))));
+}
+
+template <>
+struct type_casting_traits<numext::uint8_t, numext::uint64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2ul pcast<Packet16uc, Packet2ul>(const Packet16uc& a) {
+ // Discard all but first two bytes.
+ return vmovl_u32(vget_low_u32(vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(a))))));
+}
+
+template <>
+struct type_casting_traits<numext::uint8_t, numext::int64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2l pcast<Packet16uc, Packet2l>(const Packet16uc& a) {
+ return vreinterpretq_s64_u64(pcast<Packet16uc, Packet2ul>(a));
+}
+
+template <>
+struct type_casting_traits<numext::uint8_t, numext::uint32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4ui pcast<Packet16uc, Packet4ui>(const Packet16uc& a) {
+ // Discard all but first 4 bytes.
+ return vmovl_u16(vget_low_u16(vmovl_u8(vget_low_u8(a))));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ui pcast<Packet8uc, Packet2ui>(const Packet8uc& a) {
+ // Discard all but first 2 bytes.
+ return vget_low_u32(vmovl_u16(vget_low_u16(vmovl_u8(a))));
+}
+
+template <>
+struct type_casting_traits<numext::uint8_t, numext::int32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4i pcast<Packet16uc, Packet4i>(const Packet16uc& a) {
+ return vreinterpretq_s32_u32(pcast<Packet16uc, Packet4ui>(a));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2i pcast<Packet8uc, Packet2i>(const Packet8uc& a) {
+ return vreinterpret_s32_u32(pcast<Packet8uc, Packet2ui>(a));
+}
+
+template <>
+struct type_casting_traits<numext::uint8_t, numext::uint16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8us pcast<Packet16uc, Packet8us>(const Packet16uc& a) {
+ // Discard second half of input.
+ return vmovl_u8(vget_low_u8(a));
+}
+template <>
+EIGEN_STRONG_INLINE Packet4us pcast<Packet8uc, Packet4us>(const Packet8uc& a) {
+ // Discard second half of input.
+ return vget_low_u16(vmovl_u8(a));
+}
+
+template <>
+struct type_casting_traits<numext::uint8_t, numext::int16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8s pcast<Packet16uc, Packet8s>(const Packet16uc& a) {
+ return vreinterpretq_s16_u16(pcast<Packet16uc, Packet8us>(a));
+}
+template <>
+EIGEN_STRONG_INLINE Packet4s pcast<Packet8uc, Packet4s>(const Packet8uc& a) {
+ return vreinterpret_s16_u16(pcast<Packet8uc, Packet4us>(a));
+}
+
+template <>
+struct type_casting_traits<numext::uint8_t, numext::uint8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16uc pcast<Packet16uc, Packet16uc>(const Packet16uc& a) {
+ return a;
+}
+template <>
+EIGEN_STRONG_INLINE Packet8uc pcast<Packet8uc, Packet8uc>(const Packet8uc& a) {
+ return a;
+}
+template <>
+EIGEN_STRONG_INLINE Packet4uc pcast<Packet4uc, Packet4uc>(const Packet4uc& a) {
+ return a;
+}
+
+template <>
+struct type_casting_traits<numext::uint8_t, numext::int8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16c pcast<Packet16uc, Packet16c>(const Packet16uc& a) {
+ return vreinterpretq_s8_u8(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8c pcast<Packet8uc, Packet8c>(const Packet8uc& a) {
+ return vreinterpret_s8_u8(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet4c pcast<Packet4uc, Packet4c>(const Packet4uc& a) {
+ return static_cast<Packet4c>(a);
+}
+
+//==============================================================================
+// pcast, SrcType = int16_t
+//==============================================================================
+template <>
+struct type_casting_traits<numext::int16_t, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4f pcast<Packet8s, Packet4f>(const Packet8s& a) {
+ // Discard second half of input.
+ return vcvtq_f32_s32(vmovl_s16(vget_low_s16(a)));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2f pcast<Packet4s, Packet2f>(const Packet4s& a) {
+ // Discard second half of input.
+ return vcvt_f32_s32(vget_low_s32(vmovl_s16(a)));
+}
+
+template <>
+struct type_casting_traits<numext::int16_t, numext::int64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2l pcast<Packet8s, Packet2l>(const Packet8s& a) {
+ // Discard all but first two values.
+ return vmovl_s32(vget_low_s32(vmovl_s16(vget_low_s16(a))));
+}
+
+template <>
+struct type_casting_traits<numext::int16_t, numext::uint64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2ul pcast<Packet8s, Packet2ul>(const Packet8s& a) {
+ return vreinterpretq_u64_s64(pcast<Packet8s, Packet2l>(a));
+}
+
+template <>
+struct type_casting_traits<numext::int16_t, numext::int32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4i pcast<Packet8s, Packet4i>(const Packet8s& a) {
+ // Discard second half of input.
+ return vmovl_s16(vget_low_s16(a));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2i pcast<Packet4s, Packet2i>(const Packet4s& a) {
+ // Discard second half of input.
+ return vget_low_s32(vmovl_s16(a));
+}
+
+template <>
+struct type_casting_traits<numext::int16_t, numext::uint32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4ui pcast<Packet8s, Packet4ui>(const Packet8s& a) {
+ return vreinterpretq_u32_s32(pcast<Packet8s, Packet4i>(a));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ui pcast<Packet4s, Packet2ui>(const Packet4s& a) {
+ return vreinterpret_u32_s32(pcast<Packet4s, Packet2i>(a));
+}
+
+template <>
+struct type_casting_traits<numext::int16_t, numext::int16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8s pcast<Packet8s, Packet8s>(const Packet8s& a) {
+ return a;
+}
+template <>
+EIGEN_STRONG_INLINE Packet4s pcast<Packet4s, Packet4s>(const Packet4s& a) {
+ return a;
+}
+
+template <>
+struct type_casting_traits<numext::int16_t, numext::uint16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8us pcast<Packet8s, Packet8us>(const Packet8s& a) {
+ return vreinterpretq_u16_s16(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet4us pcast<Packet4s, Packet4us>(const Packet4s& a) {
+ return vreinterpret_u16_s16(a);
+}
+
+template <>
+struct type_casting_traits<numext::int16_t, numext::int8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16c pcast<Packet8s, Packet16c>(const Packet8s& a, const Packet8s& b) {
+ return vcombine_s8(vmovn_s16(a), vmovn_s16(b));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8c pcast<Packet4s, Packet8c>(const Packet4s& a, const Packet4s& b) {
+ return vmovn_s16(vcombine_s16(a, b));
+}
+
+template <>
+struct type_casting_traits<numext::int16_t, numext::uint8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16uc pcast<Packet8s, Packet16uc>(const Packet8s& a, const Packet8s& b) {
+ return vcombine_u8(vmovn_u16(vreinterpretq_u16_s16(a)), vmovn_u16(vreinterpretq_u16_s16(b)));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8uc pcast<Packet4s, Packet8uc>(const Packet4s& a, const Packet4s& b) {
+ return vmovn_u16(vcombine_u16(vreinterpret_u16_s16(a), vreinterpret_u16_s16(b)));
+}
+
+//==============================================================================
+// pcast, SrcType = uint16_t
+//==============================================================================
+template <>
+struct type_casting_traits<numext::uint16_t, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4f pcast<Packet8us, Packet4f>(const Packet8us& a) {
+ // Discard second half of input.
+ return vcvtq_f32_u32(vmovl_u16(vget_low_u16(a)));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2f pcast<Packet4us, Packet2f>(const Packet4us& a) {
+ // Discard second half of input.
+ return vcvt_f32_u32(vget_low_u32(vmovl_u16(a)));
+}
+
+template <>
+struct type_casting_traits<numext::uint16_t, numext::uint64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2ul pcast<Packet8us, Packet2ul>(const Packet8us& a) {
+ // Discard all but first two values.
+ return vmovl_u32(vget_low_u32(vmovl_u16(vget_low_u16(a))));
+}
+
+template <>
+struct type_casting_traits<numext::uint16_t, numext::int64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2l pcast<Packet8us, Packet2l>(const Packet8us& a) {
+ return vreinterpretq_s64_u64(pcast<Packet8us, Packet2ul>(a));
+}
+
+template <>
+struct type_casting_traits<numext::uint16_t, numext::uint32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4ui pcast<Packet8us, Packet4ui>(const Packet8us& a) {
+ // Discard second half of input.
+ return vmovl_u16(vget_low_u16(a));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ui pcast<Packet4us, Packet2ui>(const Packet4us& a) {
+ // Discard second half of input.
+ return vget_low_u32(vmovl_u16(a));
+}
+
+template <>
+struct type_casting_traits<numext::uint16_t, numext::int32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4i pcast<Packet8us, Packet4i>(const Packet8us& a) {
+ return vreinterpretq_s32_u32(pcast<Packet8us, Packet4ui>(a));
+}
+template <>
+EIGEN_STRONG_INLINE Packet2i pcast<Packet4us, Packet2i>(const Packet4us& a) {
+ return vreinterpret_s32_u32(pcast<Packet4us, Packet2ui>(a));
+}
+
+template <>
+struct type_casting_traits<numext::uint16_t, numext::uint16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8us pcast<Packet8us, Packet8us>(const Packet8us& a) {
+ return a;
+}
+template <>
+EIGEN_STRONG_INLINE Packet4us pcast<Packet4us, Packet4us>(const Packet4us& a) {
+ return a;
+}
+
+template <>
+struct type_casting_traits<numext::uint16_t, numext::int16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8s pcast<Packet8us, Packet8s>(const Packet8us& a) {
+ return vreinterpretq_s16_u16(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet4s pcast<Packet4us, Packet4s>(const Packet4us& a) {
+ return vreinterpret_s16_u16(a);
+}
+
+template <>
+struct type_casting_traits<numext::uint16_t, numext::uint8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16uc pcast<Packet8us, Packet16uc>(const Packet8us& a, const Packet8us& b) {
+ return vcombine_u8(vmovn_u16(a), vmovn_u16(b));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8uc pcast<Packet4us, Packet8uc>(const Packet4us& a, const Packet4us& b) {
+ return vmovn_u16(vcombine_u16(a, b));
+}
+
+template <>
+struct type_casting_traits<numext::uint16_t, numext::int8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16c pcast<Packet8us, Packet16c>(const Packet8us& a, const Packet8us& b) {
+ return vreinterpretq_s8_u8(pcast<Packet8us, Packet16uc>(a, b));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8c pcast<Packet4us, Packet8c>(const Packet4us& a, const Packet4us& b) {
+ return vreinterpret_s8_u8(pcast<Packet4us, Packet8uc>(a, b));
+}
+
+//==============================================================================
+// pcast, SrcType = int32_t
+//==============================================================================
+template <>
+struct type_casting_traits<numext::int32_t, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4f pcast<Packet4i, Packet4f>(const Packet4i& a) {
+ return vcvtq_f32_s32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2f pcast<Packet2i, Packet2f>(const Packet2i& a) {
+ return vcvt_f32_s32(a);
+}
+
+template <>
+struct type_casting_traits<numext::int32_t, numext::int64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2l pcast<Packet4i, Packet2l>(const Packet4i& a) {
+ // Discard second half of input.
+ return vmovl_s32(vget_low_s32(a));
+}
+
+template <>
+struct type_casting_traits<numext::int32_t, numext::uint64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2ul pcast<Packet4i, Packet2ul>(const Packet4i& a) {
+ return vreinterpretq_u64_s64(pcast<Packet4i, Packet2l>(a));
+}
+
+template <>
+struct type_casting_traits<numext::int32_t, numext::int32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4i pcast<Packet4i, Packet4i>(const Packet4i& a) {
+ return a;
+}
+template <>
+EIGEN_STRONG_INLINE Packet2i pcast<Packet2i, Packet2i>(const Packet2i& a) {
+ return a;
+}
+
+template <>
+struct type_casting_traits<numext::int32_t, numext::uint32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4ui pcast<Packet4i, Packet4ui>(const Packet4i& a) {
+ return vreinterpretq_u32_s32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ui pcast<Packet2i, Packet2ui>(const Packet2i& a) {
+ return vreinterpret_u32_s32(a);
+}
+
+template <>
+struct type_casting_traits<numext::int32_t, numext::int16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8s pcast<Packet4i, Packet8s>(const Packet4i& a, const Packet4i& b) {
+ return vcombine_s16(vmovn_s32(a), vmovn_s32(b));
+}
+template <>
+EIGEN_STRONG_INLINE Packet4s pcast<Packet2i, Packet4s>(const Packet2i& a, const Packet2i& b) {
+ return vmovn_s32(vcombine_s32(a, b));
+}
+
+template <>
+struct type_casting_traits<numext::int32_t, numext::uint16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8us pcast<Packet4i, Packet8us>(const Packet4i& a, const Packet4i& b) {
+ return vcombine_u16(vmovn_u32(vreinterpretq_u32_s32(a)), vmovn_u32(vreinterpretq_u32_s32(b)));
+}
+template <>
+EIGEN_STRONG_INLINE Packet4us pcast<Packet2i, Packet4us>(const Packet2i& a, const Packet2i& b) {
+ return vmovn_u32(vreinterpretq_u32_s32(vcombine_s32(a, b)));
+}
+
+template <>
+struct type_casting_traits<numext::int32_t, numext::int8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16c pcast<Packet4i, Packet16c>(const Packet4i& a, const Packet4i& b, const Packet4i& c,
+ const Packet4i& d) {
+ const int16x8_t ab_s16 = pcast<Packet4i, Packet8s>(a, b);
+ const int16x8_t cd_s16 = pcast<Packet4i, Packet8s>(c, d);
+ return vcombine_s8(vmovn_s16(ab_s16), vmovn_s16(cd_s16));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8c pcast<Packet2i, Packet8c>(const Packet2i& a, const Packet2i& b, const Packet2i& c,
+ const Packet2i& d) {
+ const int16x4_t ab_s16 = vmovn_s32(vcombine_s32(a, b));
+ const int16x4_t cd_s16 = vmovn_s32(vcombine_s32(c, d));
+ return vmovn_s16(vcombine_s16(ab_s16, cd_s16));
+}
+
+template <>
+struct type_casting_traits<numext::int32_t, numext::uint8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16uc pcast<Packet4i, Packet16uc>(const Packet4i& a, const Packet4i& b, const Packet4i& c,
+ const Packet4i& d) {
+ const uint16x8_t ab_u16 = pcast<Packet4i, Packet8us>(a, b);
+ const uint16x8_t cd_u16 = pcast<Packet4i, Packet8us>(c, d);
+ return vcombine_u8(vmovn_u16(ab_u16), vmovn_u16(cd_u16));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8uc pcast<Packet2i, Packet8uc>(const Packet2i& a, const Packet2i& b, const Packet2i& c,
+ const Packet2i& d) {
+ const uint16x4_t ab_u16 = pcast<Packet2i, Packet4us>(a, b);
+ const uint16x4_t cd_u16 = pcast<Packet2i, Packet4us>(c, d);
+ return vmovn_u16(vcombine_u16(ab_u16, cd_u16));
+}
+
+//==============================================================================
+// pcast, SrcType = uint32_t
+//==============================================================================
+template <>
+struct type_casting_traits<numext::uint32_t, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4f pcast<Packet4ui, Packet4f>(const Packet4ui& a) {
+ return vcvtq_f32_u32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2f pcast<Packet2ui, Packet2f>(const Packet2ui& a) {
+ return vcvt_f32_u32(a);
+}
+
+template <>
+struct type_casting_traits<numext::uint32_t, numext::uint64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2ul pcast<Packet4ui, Packet2ul>(const Packet4ui& a) {
+ // Discard second half of input.
+ return vmovl_u32(vget_low_u32(a));
+}
+
+template <>
+struct type_casting_traits<numext::uint32_t, numext::int64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2l pcast<Packet4ui, Packet2l>(const Packet4ui& a) {
+ return vreinterpretq_s64_u64(pcast<Packet4ui, Packet2ul>(a));
+}
+
+template <>
+struct type_casting_traits<numext::uint32_t, numext::uint32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4ui pcast<Packet4ui, Packet4ui>(const Packet4ui& a) {
+ return a;
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ui pcast<Packet2ui, Packet2ui>(const Packet2ui& a) {
+ return a;
+}
+
+template <>
+struct type_casting_traits<numext::uint32_t, numext::int32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4i pcast<Packet4ui, Packet4i>(const Packet4ui& a) {
+ return vreinterpretq_s32_u32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2i pcast<Packet2ui, Packet2i>(const Packet2ui& a) {
+ return vreinterpret_s32_u32(a);
+}
+
+template <>
+struct type_casting_traits<numext::uint32_t, numext::uint16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8us pcast<Packet4ui, Packet8us>(const Packet4ui& a, const Packet4ui& b) {
+ return vcombine_u16(vmovn_u32(a), vmovn_u32(b));
+}
+template <>
+EIGEN_STRONG_INLINE Packet4us pcast<Packet2ui, Packet4us>(const Packet2ui& a, const Packet2ui& b) {
+ return vmovn_u32(vcombine_u32(a, b));
+}
+
+template <>
+struct type_casting_traits<numext::uint32_t, numext::int16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8s pcast<Packet4ui, Packet8s>(const Packet4ui& a, const Packet4ui& b) {
+ return vreinterpretq_s16_u16(pcast<Packet4ui, Packet8us>(a, b));
+}
+template <>
+EIGEN_STRONG_INLINE Packet4s pcast<Packet2ui, Packet4s>(const Packet2ui& a, const Packet2ui& b) {
+ return vreinterpret_s16_u16(pcast<Packet2ui, Packet4us>(a, b));
+}
+
+template <>
+struct type_casting_traits<numext::uint32_t, numext::uint8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16uc pcast<Packet4ui, Packet16uc>(const Packet4ui& a, const Packet4ui& b, const Packet4ui& c,
+ const Packet4ui& d) {
+ const uint16x8_t ab_u16 = vcombine_u16(vmovn_u32(a), vmovn_u32(b));
+ const uint16x8_t cd_u16 = vcombine_u16(vmovn_u32(c), vmovn_u32(d));
+ return vcombine_u8(vmovn_u16(ab_u16), vmovn_u16(cd_u16));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8uc pcast<Packet2ui, Packet8uc>(const Packet2ui& a, const Packet2ui& b, const Packet2ui& c,
+ const Packet2ui& d) {
+ const uint16x4_t ab_u16 = vmovn_u32(vcombine_u32(a, b));
+ const uint16x4_t cd_u16 = vmovn_u32(vcombine_u32(c, d));
+ return vmovn_u16(vcombine_u16(ab_u16, cd_u16));
+}
+
+template <>
+struct type_casting_traits<numext::uint32_t, numext::int8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16c pcast<Packet4ui, Packet16c>(const Packet4ui& a, const Packet4ui& b, const Packet4ui& c,
+ const Packet4ui& d) {
+ return vreinterpretq_s8_u8(pcast<Packet4ui, Packet16uc>(a, b, c, d));
+}
+template <>
+EIGEN_STRONG_INLINE Packet8c pcast<Packet2ui, Packet8c>(const Packet2ui& a, const Packet2ui& b, const Packet2ui& c,
+ const Packet2ui& d) {
+ return vreinterpret_s8_u8(pcast<Packet2ui, Packet8uc>(a, b, c, d));
+}
+
+//==============================================================================
+// pcast, SrcType = int64_t
+//==============================================================================
+template <>
+struct type_casting_traits<numext::int64_t, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4f pcast<Packet2l, Packet4f>(const Packet2l& a, const Packet2l& b) {
+ return vcvtq_f32_s32(vcombine_s32(vmovn_s64(a), vmovn_s64(b)));
+}
+
+template <>
+struct type_casting_traits<numext::int64_t, numext::int64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2l pcast<Packet2l, Packet2l>(const Packet2l& a) {
+ return a;
+}
+
+template <>
+struct type_casting_traits<numext::int64_t, numext::uint64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2ul pcast<Packet2l, Packet2ul>(const Packet2l& a) {
+ return vreinterpretq_u64_s64(a);
+}
+
+template <>
+struct type_casting_traits<numext::int64_t, numext::int32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4i pcast<Packet2l, Packet4i>(const Packet2l& a, const Packet2l& b) {
+ return vcombine_s32(vmovn_s64(a), vmovn_s64(b));
+}
+
+template <>
+struct type_casting_traits<numext::int64_t, numext::uint32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4ui pcast<Packet2l, Packet4ui>(const Packet2l& a, const Packet2l& b) {
+ return vcombine_u32(vmovn_u64(vreinterpretq_u64_s64(a)), vmovn_u64(vreinterpretq_u64_s64(b)));
+}
+
+template <>
+struct type_casting_traits<numext::int64_t, numext::int16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8s pcast<Packet2l, Packet8s>(const Packet2l& a, const Packet2l& b, const Packet2l& c,
+ const Packet2l& d) {
+ const int32x4_t ab_s32 = pcast<Packet2l, Packet4i>(a, b);
+ const int32x4_t cd_s32 = pcast<Packet2l, Packet4i>(c, d);
+ return vcombine_s16(vmovn_s32(ab_s32), vmovn_s32(cd_s32));
+}
+
+template <>
+struct type_casting_traits<numext::int64_t, numext::uint16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8us pcast<Packet2l, Packet8us>(const Packet2l& a, const Packet2l& b, const Packet2l& c,
+ const Packet2l& d) {
+ const uint32x4_t ab_u32 = pcast<Packet2l, Packet4ui>(a, b);
+ const uint32x4_t cd_u32 = pcast<Packet2l, Packet4ui>(c, d);
+ return vcombine_u16(vmovn_u32(ab_u32), vmovn_u32(cd_u32));
+}
+
+template <>
+struct type_casting_traits<numext::int64_t, numext::int8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16c pcast<Packet2l, Packet16c>(const Packet2l& a, const Packet2l& b, const Packet2l& c,
+ const Packet2l& d, const Packet2l& e, const Packet2l& f,
+ const Packet2l& g, const Packet2l& h) {
+ const int16x8_t abcd_s16 = pcast<Packet2l, Packet8s>(a, b, c, d);
+ const int16x8_t efgh_s16 = pcast<Packet2l, Packet8s>(e, f, g, h);
+ return vcombine_s8(vmovn_s16(abcd_s16), vmovn_s16(efgh_s16));
+}
+
+template <>
+struct type_casting_traits<numext::int64_t, numext::uint8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16uc pcast<Packet2l, Packet16uc>(const Packet2l& a, const Packet2l& b, const Packet2l& c,
+ const Packet2l& d, const Packet2l& e, const Packet2l& f,
+ const Packet2l& g, const Packet2l& h) {
+ const uint16x8_t abcd_u16 = pcast<Packet2l, Packet8us>(a, b, c, d);
+ const uint16x8_t efgh_u16 = pcast<Packet2l, Packet8us>(e, f, g, h);
+ return vcombine_u8(vmovn_u16(abcd_u16), vmovn_u16(efgh_u16));
+}
+
+//==============================================================================
+// pcast, SrcType = uint64_t
+//==============================================================================
+template <>
+struct type_casting_traits<numext::uint64_t, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4f pcast<Packet2ul, Packet4f>(const Packet2ul& a, const Packet2ul& b) {
+ return vcvtq_f32_u32(vcombine_u32(vmovn_u64(a), vmovn_u64(b)));
+}
+
+template <>
+struct type_casting_traits<numext::uint64_t, numext::uint64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2ul pcast<Packet2ul, Packet2ul>(const Packet2ul& a) {
+ return a;
+}
+
+template <>
+struct type_casting_traits<numext::uint64_t, numext::int64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2l pcast<Packet2ul, Packet2l>(const Packet2ul& a) {
+ return vreinterpretq_s64_u64(a);
+}
+
+template <>
+struct type_casting_traits<numext::uint64_t, numext::uint32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4ui pcast<Packet2ul, Packet4ui>(const Packet2ul& a, const Packet2ul& b) {
+ return vcombine_u32(vmovn_u64(a), vmovn_u64(b));
+}
+
+template <>
+struct type_casting_traits<numext::uint64_t, numext::int32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4i pcast<Packet2ul, Packet4i>(const Packet2ul& a, const Packet2ul& b) {
+ return vreinterpretq_s32_u32(pcast<Packet2ul, Packet4ui>(a, b));
+}
+
+template <>
+struct type_casting_traits<numext::uint64_t, numext::uint16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8us pcast<Packet2ul, Packet8us>(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c,
+ const Packet2ul& d) {
+ const uint16x4_t ab_u16 = vmovn_u32(vcombine_u32(vmovn_u64(a), vmovn_u64(b)));
+ const uint16x4_t cd_u16 = vmovn_u32(vcombine_u32(vmovn_u64(c), vmovn_u64(d)));
+ return vcombine_u16(ab_u16, cd_u16);
+}
+
+template <>
+struct type_casting_traits<numext::uint64_t, numext::int16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8s pcast<Packet2ul, Packet8s>(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c,
+ const Packet2ul& d) {
+ return vreinterpretq_s16_u16(pcast<Packet2ul, Packet8us>(a, b, c, d));
+}
+
+template <>
+struct type_casting_traits<numext::uint64_t, numext::uint8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16uc pcast<Packet2ul, Packet16uc>(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c,
+ const Packet2ul& d, const Packet2ul& e, const Packet2ul& f,
+ const Packet2ul& g, const Packet2ul& h) {
+ const uint16x8_t abcd_u16 = pcast<Packet2ul, Packet8us>(a, b, c, d);
+ const uint16x8_t efgh_u16 = pcast<Packet2ul, Packet8us>(e, f, g, h);
+ return vcombine_u8(vmovn_u16(abcd_u16), vmovn_u16(efgh_u16));
+}
+
+template <>
+struct type_casting_traits<numext::uint64_t, numext::int8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16c pcast<Packet2ul, Packet16c>(const Packet2ul& a, const Packet2ul& b, const Packet2ul& c,
+ const Packet2ul& d, const Packet2ul& e, const Packet2ul& f,
+ const Packet2ul& g, const Packet2ul& h) {
+ return vreinterpretq_s8_u8(pcast<Packet2ul, Packet16uc>(a, b, c, d, e, f, g, h));
+}
+
+//==============================================================================
+// preinterpret
+//==============================================================================
+template <>
+EIGEN_STRONG_INLINE Packet2f preinterpret<Packet2f, Packet2i>(const Packet2i& a) {
+ return vreinterpret_f32_s32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2f preinterpret<Packet2f, Packet2ui>(const Packet2ui& a) {
+ return vreinterpret_f32_u32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet4f preinterpret<Packet4f, Packet4i>(const Packet4i& a) {
+ return vreinterpretq_f32_s32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet4f preinterpret<Packet4f, Packet4ui>(const Packet4ui& a) {
+ return vreinterpretq_f32_u32(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4c preinterpret<Packet4c, Packet4uc>(const Packet4uc& a) {
+ return static_cast<Packet4c>(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8c preinterpret<Packet8c, Packet8uc>(const Packet8uc& a) {
+ return vreinterpret_s8_u8(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet16c preinterpret<Packet16c, Packet16uc>(const Packet16uc& a) {
+ return vreinterpretq_s8_u8(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4uc preinterpret<Packet4uc, Packet4c>(const Packet4c& a) {
+ return static_cast<Packet4uc>(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8uc preinterpret<Packet8uc, Packet8c>(const Packet8c& a) {
+ return vreinterpret_u8_s8(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet16uc preinterpret<Packet16uc, Packet16c>(const Packet16c& a) {
+ return vreinterpretq_u8_s8(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4s preinterpret<Packet4s, Packet4us>(const Packet4us& a) {
+ return vreinterpret_s16_u16(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8s preinterpret<Packet8s, Packet8us>(const Packet8us& a) {
+ return vreinterpretq_s16_u16(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet4us preinterpret<Packet4us, Packet4s>(const Packet4s& a) {
+ return vreinterpret_u16_s16(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet8us preinterpret<Packet8us, Packet8s>(const Packet8s& a) {
+ return vreinterpretq_u16_s16(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2i preinterpret<Packet2i, Packet2f>(const Packet2f& a) {
+ return vreinterpret_s32_f32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2i preinterpret<Packet2i, Packet2ui>(const Packet2ui& a) {
+ return vreinterpret_s32_u32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i, Packet4f>(const Packet4f& a) {
+ return vreinterpretq_s32_f32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i, Packet4ui>(const Packet4ui& a) {
+ return vreinterpretq_s32_u32(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2ui preinterpret<Packet2ui, Packet2f>(const Packet2f& a) {
+ return vreinterpret_u32_f32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ui preinterpret<Packet2ui, Packet2i>(const Packet2i& a) {
+ return vreinterpret_u32_s32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet4ui preinterpret<Packet4ui, Packet4f>(const Packet4f& a) {
+ return vreinterpretq_u32_f32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet4ui preinterpret<Packet4ui, Packet4i>(const Packet4i& a) {
+ return vreinterpretq_u32_s32(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2l preinterpret<Packet2l, Packet2ul>(const Packet2ul& a) {
+ return vreinterpretq_s64_u64(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ul preinterpret<Packet2ul, Packet2l>(const Packet2l& a) {
+ return vreinterpretq_u64_s64(a);
+}
+
+#if EIGEN_ARCH_ARM64
+
+//==============================================================================
+// pcast/preinterpret, Double
+//==============================================================================
+
+template <>
+struct type_casting_traits<double, double> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2d pcast<Packet2d, Packet2d>(const Packet2d& a) {
+ return a;
+}
+
+template <>
+struct type_casting_traits<double, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4f pcast<Packet2d, Packet4f>(const Packet2d& a, const Packet2d& b) {
+ return vcombine_f32(vcvt_f32_f64(a), vcvt_f32_f64(b));
+}
+
+template <>
+struct type_casting_traits<double, numext::int64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2l pcast<Packet2d, Packet2l>(const Packet2d& a) {
+ return vcvtq_s64_f64(a);
+}
+
+template <>
+struct type_casting_traits<double, numext::uint64_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2ul pcast<Packet2d, Packet2ul>(const Packet2d& a) {
+ return vcvtq_u64_f64(a);
+}
+
+template <>
+struct type_casting_traits<double, numext::int32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4i pcast<Packet2d, Packet4i>(const Packet2d& a, const Packet2d& b) {
+ return vcombine_s32(vmovn_s64(vcvtq_s64_f64(a)), vmovn_s64(vcvtq_s64_f64(b)));
+}
+
+template <>
+struct type_casting_traits<double, numext::uint32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet4ui pcast<Packet2d, Packet4ui>(const Packet2d& a, const Packet2d& b) {
+ return vcombine_u32(vmovn_u64(vcvtq_u64_f64(a)), vmovn_u64(vcvtq_u64_f64(b)));
+}
+
+template <>
+struct type_casting_traits<double, numext::int16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8s pcast<Packet2d, Packet8s>(const Packet2d& a, const Packet2d& b, const Packet2d& c,
+ const Packet2d& d) {
+ const int32x4_t ab_s32 = pcast<Packet2d, Packet4i>(a, b);
+ const int32x4_t cd_s32 = pcast<Packet2d, Packet4i>(c, d);
+ return vcombine_s16(vmovn_s32(ab_s32), vmovn_s32(cd_s32));
+}
+
+template <>
+struct type_casting_traits<double, numext::uint16_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 4, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet8us pcast<Packet2d, Packet8us>(const Packet2d& a, const Packet2d& b, const Packet2d& c,
+ const Packet2d& d) {
+ const uint32x4_t ab_u32 = pcast<Packet2d, Packet4ui>(a, b);
+ const uint32x4_t cd_u32 = pcast<Packet2d, Packet4ui>(c, d);
+ return vcombine_u16(vmovn_u32(ab_u32), vmovn_u32(cd_u32));
+}
+
+template <>
+struct type_casting_traits<double, numext::int8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16c pcast<Packet2d, Packet16c>(const Packet2d& a, const Packet2d& b, const Packet2d& c,
+ const Packet2d& d, const Packet2d& e, const Packet2d& f,
+ const Packet2d& g, const Packet2d& h) {
+ const int16x8_t abcd_s16 = pcast<Packet2d, Packet8s>(a, b, c, d);
+ const int16x8_t efgh_s16 = pcast<Packet2d, Packet8s>(e, f, g, h);
+ return vcombine_s8(vmovn_s16(abcd_s16), vmovn_s16(efgh_s16));
+}
+
+template <>
+struct type_casting_traits<double, numext::uint8_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 8, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet16uc pcast<Packet2d, Packet16uc>(const Packet2d& a, const Packet2d& b, const Packet2d& c,
+ const Packet2d& d, const Packet2d& e, const Packet2d& f,
+ const Packet2d& g, const Packet2d& h) {
+ const uint16x8_t abcd_u16 = pcast<Packet2d, Packet8us>(a, b, c, d);
+ const uint16x8_t efgh_u16 = pcast<Packet2d, Packet8us>(e, f, g, h);
+ return vcombine_u8(vmovn_u16(abcd_u16), vmovn_u16(efgh_u16));
+}
+
+template <>
+struct type_casting_traits<float, double> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2d pcast<Packet4f, Packet2d>(const Packet4f& a) {
+ // Discard second-half of input.
+ return vcvt_f64_f32(vget_low_f32(a));
+}
+
+template <>
+struct type_casting_traits<numext::int8_t, double> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2d pcast<Packet16c, Packet2d>(const Packet16c& a) {
+ // Discard all but first two values.
+ return vcvt_f64_f32(pcast<Packet8c, Packet2f>(vget_low_s8(a)));
+}
+
+template <>
+struct type_casting_traits<numext::uint8_t, double> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 8 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2d pcast<Packet16uc, Packet2d>(const Packet16uc& a) {
+ // Discard all but first two values.
+ return vcvt_f64_f32(pcast<Packet8uc, Packet2f>(vget_low_u8(a)));
+}
+
+template <>
+struct type_casting_traits<numext::int16_t, double> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2d pcast<Packet8s, Packet2d>(const Packet8s& a) {
+ // Discard all but first two values.
+ return vcvt_f64_f32(pcast<Packet4s, Packet2f>(vget_low_s16(a)));
+}
+
+template <>
+struct type_casting_traits<numext::uint16_t, double> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 4 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2d pcast<Packet8us, Packet2d>(const Packet8us& a) {
+ // Discard all but first two values.
+ return vcvt_f64_f32(pcast<Packet4us, Packet2f>(vget_low_u16(a)));
+}
+
+template <>
+struct type_casting_traits<numext::int32_t, double> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2d pcast<Packet4i, Packet2d>(const Packet4i& a) {
+ // Discard second half of input.
+ return vcvtq_f64_s64(vmovl_s32(vget_low_s32(a)));
+}
+
+template <>
+struct type_casting_traits<numext::uint32_t, double> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2d pcast<Packet4ui, Packet2d>(const Packet4ui& a) {
+ // Discard second half of input.
+ return vcvtq_f64_u64(vmovl_u32(vget_low_u32(a)));
+}
+
+template <>
+struct type_casting_traits<numext::int64_t, double> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2d pcast<Packet2l, Packet2d>(const Packet2l& a) {
+ return vcvtq_f64_s64(a);
+}
+
+template <>
+struct type_casting_traits<numext::uint64_t, double> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+template <>
+EIGEN_STRONG_INLINE Packet2d pcast<Packet2ul, Packet2d>(const Packet2ul& a) {
+ return vcvtq_f64_u64(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE Packet2d preinterpret<Packet2d, Packet2l>(const Packet2l& a) {
+ return vreinterpretq_f64_s64(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2d preinterpret<Packet2d, Packet2ul>(const Packet2ul& a) {
+ return vreinterpretq_f64_u64(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2l preinterpret<Packet2l, Packet2d>(const Packet2d& a) {
+ return vreinterpretq_s64_f64(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2ul preinterpret<Packet2ul, Packet2d>(const Packet2d& a) {
+ return vreinterpretq_u64_f64(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet2d preinterpret<Packet2d, Packet4i>(const Packet4i& a) {
+ return vreinterpretq_f64_s32(a);
+}
+template <>
+EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i, Packet2d>(const Packet2d& a) {
+ return vreinterpretq_s32_f64(a);
+}
+
+#endif // EIGEN_ARCH_ARM64
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TYPE_CASTING_NEON_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/Complex.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/Complex.h
new file mode 100644
index 000000000..8fe22da46
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/Complex.h
@@ -0,0 +1,351 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMPLEX_SSE_H
+#define EIGEN_COMPLEX_SSE_H
+
+namespace Eigen {
+
+namespace internal {
+
+//---------- float ----------
+struct Packet2cf
+{
+ EIGEN_STRONG_INLINE Packet2cf() {}
+ EIGEN_STRONG_INLINE explicit Packet2cf(const __m128& a) : v(a) {}
+ Packet4f v;
+};
+
+// Use the packet_traits defined in AVX/PacketMath.h instead if we're going
+// to leverage AVX instructions.
+#ifndef EIGEN_VECTORIZE_AVX
+template<> struct packet_traits<std::complex<float> > : default_packet_traits
+{
+ typedef Packet2cf type;
+ typedef Packet2cf half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 2,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasSqrt = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0,
+ HasBlend = 1
+ };
+};
+#endif
+
+template<> struct unpacket_traits<Packet2cf> {
+ typedef std::complex<float> type;
+ typedef Packet2cf half;
+ typedef Packet4f as_real;
+ enum {
+ size=2,
+ alignment=Aligned16,
+ vectorizable=true,
+ masked_load_available=false,
+ masked_store_available=false
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_add_ps(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_sub_ps(a.v,b.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a)
+{
+ const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x80000000,0x80000000,0x80000000));
+ return Packet2cf(_mm_xor_ps(a.v,mask));
+}
+template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a)
+{
+ const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
+ return Packet2cf(_mm_xor_ps(a.v,mask));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{
+ #ifdef EIGEN_VECTORIZE_SSE3
+ return Packet2cf(_mm_addsub_ps(_mm_mul_ps(_mm_moveldup_ps(a.v), b.v),
+ _mm_mul_ps(_mm_movehdup_ps(a.v),
+ vec4f_swizzle1(b.v, 1, 0, 3, 2))));
+// return Packet2cf(_mm_addsub_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
+// _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
+// vec4f_swizzle1(b.v, 1, 0, 3, 2))));
+ #else
+ const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x00000000,0x80000000,0x00000000));
+ return Packet2cf(_mm_add_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
+ _mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
+ vec4f_swizzle1(b.v, 1, 0, 3, 2)), mask)));
+ #endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf ptrue <Packet2cf>(const Packet2cf& a) { return Packet2cf(ptrue(Packet4f(a.v))); }
+template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_and_ps(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_or_ps(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_xor_ps(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_andnot_ps(b.v,a.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>(&numext::real_ref(*from))); }
+template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>(&numext::real_ref(*from))); }
+
+template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from)
+{
+ Packet2cf res;
+#ifdef EIGEN_VECTORIZE_SSE3
+ res.v = _mm_castpd_ps(_mm_loaddup_pd(reinterpret_cast<double const*>(&from)));
+#else
+ res.v = _mm_castpd_ps(_mm_load_sd(reinterpret_cast<double const*>(&from)));
+ res.v = _mm_movelh_ps(res.v, res.v);
+#endif
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { return pset1<Packet2cf>(*from); }
+
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore(&numext::real_ref(*to), Packet4f(from.v)); }
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(&numext::real_ref(*to), Packet4f(from.v)); }
+
+
+template<> EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>(const std::complex<float>* from, Index stride)
+{
+ return Packet2cf(_mm_set_ps(std::imag(from[1*stride]), std::real(from[1*stride]),
+ std::imag(from[0*stride]), std::real(from[0*stride])));
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to, const Packet2cf& from, Index stride)
+{
+ to[stride*0] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 0)),
+ _mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 1)));
+ to[stride*1] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 2)),
+ _mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 3)));
+}
+
+template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> * addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
+
+template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a)
+{
+ #if EIGEN_GNUC_AT_MOST(4,3)
+ // Workaround gcc 4.2 ICE - this is not performance wise ideal, but who cares...
+ // This workaround also fix invalid code generation with gcc 4.3
+ EIGEN_ALIGN16 std::complex<float> res[2];
+ _mm_store_ps((float*)res, a.v);
+ return res[0];
+ #else
+ std::complex<float> res;
+ _mm_storel_pi((__m64*)&res, a.v);
+ return res;
+ #endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) { return Packet2cf(_mm_castpd_ps(preverse(Packet2d(_mm_castps_pd(a.v))))); }
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
+{
+ return pfirst(Packet2cf(_mm_add_ps(a.v, _mm_movehl_ps(a.v,a.v))));
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
+{
+ return pfirst(pmul(a, Packet2cf(_mm_movehl_ps(a.v,a.v))));
+}
+
+EIGEN_STRONG_INLINE Packet2cf pcplxflip/* <Packet2cf> */(const Packet2cf& x)
+{
+ return Packet2cf(vec4f_swizzle1(x.v, 1, 0, 3, 2));
+}
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
+
+template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{
+ // TODO optimize it for SSE3 and 4
+ Packet2cf res = pmul(a, pconj(b));
+ __m128 s = _mm_mul_ps(b.v,b.v);
+ return Packet2cf(_mm_div_ps(res.v,_mm_add_ps(s,vec4f_swizzle1(s, 1, 0, 3, 2))));
+}
+
+
+
+//---------- double ----------
+struct Packet1cd
+{
+ EIGEN_STRONG_INLINE Packet1cd() {}
+ EIGEN_STRONG_INLINE explicit Packet1cd(const __m128d& a) : v(a) {}
+ Packet2d v;
+};
+
+// Use the packet_traits defined in AVX/PacketMath.h instead if we're going
+// to leverage AVX instructions.
+#ifndef EIGEN_VECTORIZE_AVX
+template<> struct packet_traits<std::complex<double> > : default_packet_traits
+{
+ typedef Packet1cd type;
+ typedef Packet1cd half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 0,
+ size = 1,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasSqrt = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0
+ };
+};
+#endif
+
+template<> struct unpacket_traits<Packet1cd> {
+ typedef std::complex<double> type;
+ typedef Packet1cd half;
+ typedef Packet2d as_real;
+ enum {
+ size=1,
+ alignment=Aligned16,
+ vectorizable=true,
+ masked_load_available=false,
+ masked_store_available=false
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_add_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_sub_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) { return Packet1cd(pnegate(Packet2d(a.v))); }
+template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a)
+{
+ const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
+ return Packet1cd(_mm_xor_pd(a.v,mask));
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{
+ #ifdef EIGEN_VECTORIZE_SSE3
+ return Packet1cd(_mm_addsub_pd(_mm_mul_pd(_mm_movedup_pd(a.v), b.v),
+ _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
+ vec2d_swizzle1(b.v, 1, 0))));
+ #else
+ const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x0,0x0,0x80000000,0x0));
+ return Packet1cd(_mm_add_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v),
+ _mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
+ vec2d_swizzle1(b.v, 1, 0)), mask)));
+ #endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd ptrue <Packet1cd>(const Packet1cd& a) { return Packet1cd(ptrue(Packet2d(a.v))); }
+template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_and_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_or_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_xor_pd(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_andnot_pd(b.v,a.v)); }
+
+// FIXME force unaligned load, this is a temporary fix
+template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(const std::complex<double>* from)
+{ EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>((const double*)from)); }
+template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from)
+{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>((const double*)from)); }
+template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from)
+{ /* here we really have to use unaligned loads :( */ return ploadu<Packet1cd>(&from); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) { return pset1<Packet1cd>(*from); }
+
+// FIXME force unaligned store, this is a temporary fix
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((double*)to, Packet2d(from.v)); }
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, Packet2d(from.v)); }
+
+template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> * addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
+
+template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a)
+{
+ EIGEN_ALIGN16 double res[2];
+ _mm_store_pd(res, a.v);
+ return std::complex<double>(res[0],res[1]);
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a)
+{
+ return pfirst(a);
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a)
+{
+ return pfirst(a);
+}
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d)
+
+template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{
+ // TODO optimize it for SSE3 and 4
+ Packet1cd res = pmul(a,pconj(b));
+ __m128d s = _mm_mul_pd(b.v,b.v);
+ return Packet1cd(_mm_div_pd(res.v, _mm_add_pd(s,_mm_shuffle_pd(s, s, 0x1))));
+}
+
+EIGEN_STRONG_INLINE Packet1cd pcplxflip/* <Packet1cd> */(const Packet1cd& x)
+{
+ return Packet1cd(preverse(Packet2d(x.v)));
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet2cf,2>& kernel) {
+ __m128d w1 = _mm_castps_pd(kernel.packet[0].v);
+ __m128d w2 = _mm_castps_pd(kernel.packet[1].v);
+
+ __m128 tmp = _mm_castpd_ps(_mm_unpackhi_pd(w1, w2));
+ kernel.packet[0].v = _mm_castpd_ps(_mm_unpacklo_pd(w1, w2));
+ kernel.packet[1].v = tmp;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf& a, const Packet2cf& b)
+{
+ __m128 eq = _mm_cmpeq_ps(a.v, b.v);
+ return Packet2cf(pand<Packet4f>(eq, vec4f_swizzle1(eq, 1, 0, 3, 2)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(const Packet1cd& a, const Packet1cd& b)
+{
+ __m128d eq = _mm_cmpeq_pd(a.v, b.v);
+ return Packet1cd(pand<Packet2d>(eq, vec2d_swizzle1(eq, 1, 0)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket, const Packet2cf& elsePacket) {
+ __m128d result = pblend<Packet2d>(ifPacket, _mm_castps_pd(thenPacket.v), _mm_castps_pd(elsePacket.v));
+ return Packet2cf(_mm_castpd_ps(result));
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd psqrt<Packet1cd>(const Packet1cd& a) {
+ return psqrt_complex<Packet1cd>(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf psqrt<Packet2cf>(const Packet2cf& a) {
+ return psqrt_complex<Packet2cf>(a);
+}
+
+} // end namespace internal
+} // end namespace Eigen
+
+#endif // EIGEN_COMPLEX_SSE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h
new file mode 100644
index 000000000..8736d0d6b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h
@@ -0,0 +1,199 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2007 Julien Pommier
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/* The sin and cos and functions of this file come from
+ * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/
+ */
+
+#ifndef EIGEN_MATH_FUNCTIONS_SSE_H
+#define EIGEN_MATH_FUNCTIONS_SSE_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f plog<Packet4f>(const Packet4f& _x) {
+ return plog_float(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet2d plog<Packet2d>(const Packet2d& _x) {
+ return plog_double(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f plog2<Packet4f>(const Packet4f& _x) {
+ return plog2_float(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet2d plog2<Packet2d>(const Packet2d& _x) {
+ return plog2_double(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f plog1p<Packet4f>(const Packet4f& _x) {
+ return generic_plog1p(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f pexpm1<Packet4f>(const Packet4f& _x) {
+ return generic_expm1(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f pexp<Packet4f>(const Packet4f& _x)
+{
+ return pexp_float(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet2d pexp<Packet2d>(const Packet2d& x)
+{
+ return pexp_double(x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f psin<Packet4f>(const Packet4f& _x)
+{
+ return psin_float(_x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f pcos<Packet4f>(const Packet4f& _x)
+{
+ return pcos_float(_x);
+}
+
+#if EIGEN_FAST_MATH
+
+// Functions for sqrt.
+// The EIGEN_FAST_MATH version uses the _mm_rsqrt_ps approximation and one step
+// of Newton's method, at a cost of 1-2 bits of precision as opposed to the
+// exact solution. It does not handle +inf, or denormalized numbers correctly.
+// The main advantage of this approach is not just speed, but also the fact that
+// it can be inlined and pipelined with other computations, further reducing its
+// effective latency. This is similar to Quake3's fast inverse square root.
+// For detail see here: http://www.beyond3d.com/content/articles/8/
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f psqrt<Packet4f>(const Packet4f& _x)
+{
+ Packet4f minus_half_x = pmul(_x, pset1<Packet4f>(-0.5f));
+ Packet4f denormal_mask = pandnot(
+ pcmp_lt(_x, pset1<Packet4f>((std::numeric_limits<float>::min)())),
+ pcmp_lt(_x, pzero(_x)));
+
+ // Compute approximate reciprocal sqrt.
+ Packet4f x = _mm_rsqrt_ps(_x);
+ // Do a single step of Newton's iteration.
+ x = pmul(x, pmadd(minus_half_x, pmul(x,x), pset1<Packet4f>(1.5f)));
+ // Flush results for denormals to zero.
+ return pandnot(pmul(_x,x), denormal_mask);
+}
+
+#else
+
+template<>EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f psqrt<Packet4f>(const Packet4f& x) { return _mm_sqrt_ps(x); }
+
+#endif
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet2d psqrt<Packet2d>(const Packet2d& x) { return _mm_sqrt_pd(x); }
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet16b psqrt<Packet16b>(const Packet16b& x) { return x; }
+
+#if EIGEN_FAST_MATH
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f prsqrt<Packet4f>(const Packet4f& _x) {
+ _EIGEN_DECLARE_CONST_Packet4f(one_point_five, 1.5f);
+ _EIGEN_DECLARE_CONST_Packet4f(minus_half, -0.5f);
+ _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(inf, 0x7f800000u);
+ _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(flt_min, 0x00800000u);
+
+ Packet4f neg_half = pmul(_x, p4f_minus_half);
+
+ // Identity infinite, zero, negative and denormal arguments.
+ Packet4f lt_min_mask = _mm_cmplt_ps(_x, p4f_flt_min);
+ Packet4f inf_mask = _mm_cmpeq_ps(_x, p4f_inf);
+ Packet4f not_normal_finite_mask = _mm_or_ps(lt_min_mask, inf_mask);
+
+ // Compute an approximate result using the rsqrt intrinsic.
+ Packet4f y_approx = _mm_rsqrt_ps(_x);
+
+ // Do a single step of Newton-Raphson iteration to improve the approximation.
+ // This uses the formula y_{n+1} = y_n * (1.5 - y_n * (0.5 * x) * y_n).
+ // It is essential to evaluate the inner term like this because forming
+ // y_n^2 may over- or underflow.
+ Packet4f y_newton = pmul(
+ y_approx, pmadd(y_approx, pmul(neg_half, y_approx), p4f_one_point_five));
+
+ // Select the result of the Newton-Raphson step for positive normal arguments.
+ // For other arguments, choose the output of the intrinsic. This will
+ // return rsqrt(+inf) = 0, rsqrt(x) = NaN if x < 0, and rsqrt(x) = +inf if
+ // x is zero or a positive denormalized float (equivalent to flushing positive
+ // denormalized inputs to zero).
+ return pselect<Packet4f>(not_normal_finite_mask, y_approx, y_newton);
+}
+
+#else
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f prsqrt<Packet4f>(const Packet4f& x) {
+ // Unfortunately we can't use the much faster mm_rsqrt_ps since it only provides an approximation.
+ return _mm_div_ps(pset1<Packet4f>(1.0f), _mm_sqrt_ps(x));
+}
+
+#endif
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet2d prsqrt<Packet2d>(const Packet2d& x) {
+ return _mm_div_pd(pset1<Packet2d>(1.0), _mm_sqrt_pd(x));
+}
+
+// Hyperbolic Tangent function.
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f
+ptanh<Packet4f>(const Packet4f& x) {
+ return internal::generic_fast_tanh_float(x);
+}
+
+} // end namespace internal
+
+namespace numext {
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+float sqrt(const float &x)
+{
+ return internal::pfirst(internal::Packet4f(_mm_sqrt_ss(_mm_set_ss(x))));
+}
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
+double sqrt(const double &x)
+{
+#if EIGEN_COMP_GNUC_STRICT
+ // This works around a GCC bug generating poor code for _mm_sqrt_pd
+ // See https://gitlab.com/libeigen/eigen/commit/8dca9f97e38970
+ return internal::pfirst(internal::Packet2d(__builtin_ia32_sqrtsd(_mm_set_sd(x))));
+#else
+ return internal::pfirst(internal::Packet2d(_mm_sqrt_pd(_mm_set_sd(x))));
+#endif
+}
+
+} // end namespace numex
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATH_FUNCTIONS_SSE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/PacketMath.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/PacketMath.h
new file mode 100644
index 000000000..db102c73a
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/PacketMath.h
@@ -0,0 +1,1505 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PACKET_MATH_SSE_H
+#define EIGEN_PACKET_MATH_SSE_H
+
+namespace Eigen {
+
+namespace internal {
+
+#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
+#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
+#endif
+
+#if !defined(EIGEN_VECTORIZE_AVX) && !defined(EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS)
+// 32 bits => 8 registers
+// 64 bits => 16 registers
+#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS (2*sizeof(void*))
+#endif
+
+#ifdef EIGEN_VECTORIZE_FMA
+#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#endif
+#endif
+
+#if ((defined EIGEN_VECTORIZE_AVX) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_MINGW) && (__GXX_ABI_VERSION < 1004)) || EIGEN_OS_QNX
+// With GCC's default ABI version, a __m128 or __m256 are the same types and therefore we cannot
+// have overloads for both types without linking error.
+// One solution is to increase ABI version using -fabi-version=4 (or greater).
+// Otherwise, we workaround this inconvenience by wrapping 128bit types into the following helper
+// structure:
+typedef eigen_packet_wrapper<__m128> Packet4f;
+typedef eigen_packet_wrapper<__m128d> Packet2d;
+#else
+typedef __m128 Packet4f;
+typedef __m128d Packet2d;
+#endif
+
+typedef eigen_packet_wrapper<__m128i, 0> Packet4i;
+typedef eigen_packet_wrapper<__m128i, 1> Packet16b;
+
+template<> struct is_arithmetic<__m128> { enum { value = true }; };
+template<> struct is_arithmetic<__m128i> { enum { value = true }; };
+template<> struct is_arithmetic<__m128d> { enum { value = true }; };
+template<> struct is_arithmetic<Packet4i> { enum { value = true }; };
+template<> struct is_arithmetic<Packet16b> { enum { value = true }; };
+
+template<int p, int q, int r, int s>
+struct shuffle_mask{
+ enum { mask = (s)<<6|(r)<<4|(q)<<2|(p) };
+};
+
+// TODO: change the implementation of all swizzle* ops from macro to template,
+#define vec4f_swizzle1(v,p,q,r,s) \
+ Packet4f(_mm_castsi128_ps(_mm_shuffle_epi32( _mm_castps_si128(v), (shuffle_mask<p,q,r,s>::mask))))
+
+#define vec4i_swizzle1(v,p,q,r,s) \
+ Packet4i(_mm_shuffle_epi32( v, (shuffle_mask<p,q,r,s>::mask)))
+
+#define vec2d_swizzle1(v,p,q) \
+ Packet2d(_mm_castsi128_pd(_mm_shuffle_epi32( _mm_castpd_si128(v), (shuffle_mask<2*p,2*p+1,2*q,2*q+1>::mask))))
+
+#define vec4f_swizzle2(a,b,p,q,r,s) \
+ Packet4f(_mm_shuffle_ps( (a), (b), (shuffle_mask<p,q,r,s>::mask)))
+
+#define vec4i_swizzle2(a,b,p,q,r,s) \
+ Packet4i(_mm_castps_si128( (_mm_shuffle_ps( _mm_castsi128_ps(a), _mm_castsi128_ps(b), (shuffle_mask<p,q,r,s>::mask)))))
+
+EIGEN_STRONG_INLINE Packet4f vec4f_movelh(const Packet4f& a, const Packet4f& b)
+{
+ return Packet4f(_mm_movelh_ps(a,b));
+}
+EIGEN_STRONG_INLINE Packet4f vec4f_movehl(const Packet4f& a, const Packet4f& b)
+{
+ return Packet4f(_mm_movehl_ps(a,b));
+}
+EIGEN_STRONG_INLINE Packet4f vec4f_unpacklo(const Packet4f& a, const Packet4f& b)
+{
+ return Packet4f(_mm_unpacklo_ps(a,b));
+}
+EIGEN_STRONG_INLINE Packet4f vec4f_unpackhi(const Packet4f& a, const Packet4f& b)
+{
+ return Packet4f(_mm_unpackhi_ps(a,b));
+}
+#define vec4f_duplane(a,p) \
+ vec4f_swizzle2(a,a,p,p,p,p)
+
+#define vec2d_swizzle2(a,b,mask) \
+ Packet2d(_mm_shuffle_pd(a,b,mask))
+
+EIGEN_STRONG_INLINE Packet2d vec2d_unpacklo(const Packet2d& a, const Packet2d& b)
+{
+ return Packet2d(_mm_unpacklo_pd(a,b));
+}
+EIGEN_STRONG_INLINE Packet2d vec2d_unpackhi(const Packet2d& a, const Packet2d& b)
+{
+ return Packet2d(_mm_unpackhi_pd(a,b));
+}
+#define vec2d_duplane(a,p) \
+ vec2d_swizzle2(a,a,(p<<1)|p)
+
+#define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \
+ const Packet4f p4f_##NAME = pset1<Packet4f>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet2d(NAME,X) \
+ const Packet2d p2d_##NAME = pset1<Packet2d>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \
+ const Packet4f p4f_##NAME = pset1frombits<Packet4f>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \
+ const Packet4i p4i_##NAME = pset1<Packet4i>(X)
+
+
+// Use the packet_traits defined in AVX/PacketMath.h instead if we're going
+// to leverage AVX instructions.
+#ifndef EIGEN_VECTORIZE_AVX
+template <>
+struct packet_traits<float> : default_packet_traits {
+ typedef Packet4f type;
+ typedef Packet4f half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 0,
+
+ HasCmp = 1,
+ HasDiv = 1,
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+ HasLog = 1,
+ HasLog1p = 1,
+ HasExpm1 = 1,
+ HasNdtri = 1,
+ HasExp = 1,
+ HasBessel = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH,
+ HasBlend = 1,
+ HasCeil = 1,
+ HasFloor = 1,
+#ifdef EIGEN_VECTORIZE_SSE4_1
+ HasRound = 1,
+#endif
+ HasRint = 1
+ };
+};
+template <>
+struct packet_traits<double> : default_packet_traits {
+ typedef Packet2d type;
+ typedef Packet2d half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size=2,
+ HasHalfPacket = 0,
+
+ HasCmp = 1,
+ HasDiv = 1,
+ HasLog = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasBlend = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+#ifdef EIGEN_VECTORIZE_SSE4_1
+ HasRound = 1,
+#endif
+ HasRint = 1
+ };
+};
+#endif
+template<> struct packet_traits<int> : default_packet_traits
+{
+ typedef Packet4i type;
+ typedef Packet4i half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size=4,
+
+ HasShift = 1,
+ HasBlend = 1
+ };
+};
+
+template<> struct packet_traits<bool> : default_packet_traits
+{
+ typedef Packet16b type;
+ typedef Packet16b half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ HasHalfPacket = 0,
+ size=16,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 0,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasConj = 0,
+ HasSqrt = 1
+ };
+};
+
+template<> struct unpacket_traits<Packet4f> {
+ typedef float type;
+ typedef Packet4f half;
+ typedef Packet4i integer_packet;
+ enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+template<> struct unpacket_traits<Packet2d> {
+ typedef double type;
+ typedef Packet2d half;
+ enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+template<> struct unpacket_traits<Packet4i> {
+ typedef int type;
+ typedef Packet4i half;
+ enum {size=4, alignment=Aligned16, vectorizable=false, masked_load_available=false, masked_store_available=false};
+};
+template<> struct unpacket_traits<Packet16b> {
+ typedef bool type;
+ typedef Packet16b half;
+ enum {size=16, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false};
+};
+
+#ifndef EIGEN_VECTORIZE_AVX
+template<> struct scalar_div_cost<float,true> { enum { value = 7 }; };
+template<> struct scalar_div_cost<double,true> { enum { value = 8 }; };
+#endif
+
+#if EIGEN_COMP_MSVC==1500
+// Workaround MSVC 9 internal compiler error.
+// TODO: It has been detected with win64 builds (amd64), so let's check whether it also happens in 32bits+SSE mode
+// TODO: let's check whether there does not exist a better fix, like adding a pset0() function. (it crashed on pset1(0)).
+template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) { return _mm_set_ps(from,from,from,from); }
+template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { return _mm_set_pd(from,from); }
+template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from) { return _mm_set_epi32(from,from,from,from); }
+#else
+template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) { return _mm_set_ps1(from); }
+template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { return _mm_set1_pd(from); }
+template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from) { return _mm_set1_epi32(from); }
+#endif
+template<> EIGEN_STRONG_INLINE Packet16b pset1<Packet16b>(const bool& from) { return _mm_set1_epi8(static_cast<char>(from)); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pset1frombits<Packet4f>(unsigned int from) { return _mm_castsi128_ps(pset1<Packet4i>(from)); }
+template<> EIGEN_STRONG_INLINE Packet2d pset1frombits<Packet2d>(uint64_t from) { return _mm_castsi128_pd(_mm_set1_epi64x(from)); }
+
+template<> EIGEN_STRONG_INLINE Packet4f peven_mask(const Packet4f& /*a*/) { return _mm_castsi128_ps(_mm_set_epi32(0, -1, 0, -1)); }
+template<> EIGEN_STRONG_INLINE Packet4i peven_mask(const Packet4i& /*a*/) { return _mm_set_epi32(0, -1, 0, -1); }
+template<> EIGEN_STRONG_INLINE Packet2d peven_mask(const Packet2d& /*a*/) { return _mm_castsi128_pd(_mm_set_epi32(0, 0, -1, -1)); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pzero(const Packet4f& /*a*/) { return _mm_setzero_ps(); }
+template<> EIGEN_STRONG_INLINE Packet2d pzero(const Packet2d& /*a*/) { return _mm_setzero_pd(); }
+template<> EIGEN_STRONG_INLINE Packet4i pzero(const Packet4i& /*a*/) { return _mm_setzero_si128(); }
+
+// GCC generates a shufps instruction for _mm_set1_ps/_mm_load1_ps instead of the more efficient pshufd instruction.
+// However, using inrinsics for pset1 makes gcc to generate crappy code in some cases (see bug 203)
+// Using inline assembly is also not an option because then gcc fails to reorder properly the instructions.
+// Therefore, we introduced the pload1 functions to be used in product kernels for which bug 203 does not apply.
+// Also note that with AVX, we want it to generate a vbroadcastss.
+#if EIGEN_COMP_GNUC_STRICT && (!defined __AVX__)
+template<> EIGEN_STRONG_INLINE Packet4f pload1<Packet4f>(const float *from) {
+ return vec4f_swizzle1(_mm_load_ss(from),0,0,0,0);
+}
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a) { return _mm_add_ps(pset1<Packet4f>(a), _mm_set_ps(3,2,1,0)); }
+template<> EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) { return _mm_add_pd(pset1<Packet2d>(a),_mm_set_pd(1,0)); }
+template<> EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int& a) { return _mm_add_epi32(pset1<Packet4i>(a),_mm_set_epi32(3,2,1,0)); }
+
+template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_add_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_add_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_add_epi32(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet16b padd<Packet16b>(const Packet16b& a, const Packet16b& b) { return _mm_or_si128(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_sub_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_sub_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_sub_epi32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16b psub<Packet16b>(const Packet16b& a, const Packet16b& b) { return _mm_xor_si128(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b);
+template<> EIGEN_STRONG_INLINE Packet4f paddsub<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+#ifdef EIGEN_VECTORIZE_SSE3
+ return _mm_addsub_ps(a,b);
+#else
+ const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x0,0x80000000,0x0));
+ return padd(a, pxor(mask, b));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& , const Packet2d& );
+template<> EIGEN_STRONG_INLINE Packet2d paddsub<Packet2d>(const Packet2d& a, const Packet2d& b)
+{
+#ifdef EIGEN_VECTORIZE_SSE3
+ return _mm_addsub_pd(a,b);
+#else
+ const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0x0,0x80000000,0x0,0x0));
+ return padd(a, pxor(mask, b));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a)
+{
+ const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x80000000,0x80000000,0x80000000));
+ return _mm_xor_ps(a,mask);
+}
+template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a)
+{
+ const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0x0,0x80000000,0x0,0x80000000));
+ return _mm_xor_pd(a,mask);
+}
+template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a)
+{
+ return psub(Packet4i(_mm_setr_epi32(0,0,0,0)), a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet16b pnegate(const Packet16b& a)
+{
+ return psub(pset1<Packet16b>(false), a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_mul_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_mul_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b)
+{
+#ifdef EIGEN_VECTORIZE_SSE4_1
+ return _mm_mullo_epi32(a,b);
+#else
+ // this version is slightly faster than 4 scalar products
+ return vec4i_swizzle1(
+ vec4i_swizzle2(
+ _mm_mul_epu32(a,b),
+ _mm_mul_epu32(vec4i_swizzle1(a,1,0,3,2),
+ vec4i_swizzle1(b,1,0,3,2)),
+ 0,2,0,2),
+ 0,2,1,3);
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet16b pmul<Packet16b>(const Packet16b& a, const Packet16b& b) { return _mm_and_si128(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_div_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_div_pd(a,b); }
+
+// for some weird raisons, it has to be overloaded for packet of integers
+template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { return padd(pmul(a,b), c); }
+#ifdef EIGEN_VECTORIZE_FMA
+template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) { return _mm_fmadd_ps(a,b,c); }
+template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) { return _mm_fmadd_pd(a,b,c); }
+#endif
+
+#ifdef EIGEN_VECTORIZE_SSE4_1
+template<> EIGEN_DEVICE_FUNC inline Packet4f pselect(const Packet4f& mask, const Packet4f& a, const Packet4f& b) {
+ return _mm_blendv_ps(b,a,mask);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet4i pselect(const Packet4i& mask, const Packet4i& a, const Packet4i& b) {
+ return _mm_castps_si128(_mm_blendv_ps(_mm_castsi128_ps(b),_mm_castsi128_ps(a),_mm_castsi128_ps(mask)));
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet2d pselect(const Packet2d& mask, const Packet2d& a, const Packet2d& b) { return _mm_blendv_pd(b,a,mask); }
+
+template<> EIGEN_DEVICE_FUNC inline Packet16b pselect(const Packet16b& mask, const Packet16b& a, const Packet16b& b) {
+ return _mm_blendv_epi8(b,a,mask);
+}
+#else
+template<> EIGEN_DEVICE_FUNC inline Packet16b pselect(const Packet16b& mask, const Packet16b& a, const Packet16b& b) {
+ Packet16b a_part = _mm_and_si128(mask, a);
+ Packet16b b_part = _mm_andnot_si128(mask, b);
+ return _mm_or_si128(a_part, b_part);
+}
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet4i ptrue<Packet4i>(const Packet4i& a) { return _mm_cmpeq_epi32(a, a); }
+template<> EIGEN_STRONG_INLINE Packet16b ptrue<Packet16b>(const Packet16b& a) { return _mm_cmpeq_epi8(a, a); }
+template<> EIGEN_STRONG_INLINE Packet4f
+ptrue<Packet4f>(const Packet4f& a) {
+ Packet4i b = _mm_castps_si128(a);
+ return _mm_castsi128_ps(_mm_cmpeq_epi32(b, b));
+}
+template<> EIGEN_STRONG_INLINE Packet2d
+ptrue<Packet2d>(const Packet2d& a) {
+ Packet4i b = _mm_castpd_si128(a);
+ return _mm_castsi128_pd(_mm_cmpeq_epi32(b, b));
+}
+
+
+template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_and_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_and_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_and_si128(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16b pand<Packet16b>(const Packet16b& a, const Packet16b& b) { return _mm_and_si128(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_or_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_or_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_or_si128(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16b por<Packet16b>(const Packet16b& a, const Packet16b& b) { return _mm_or_si128(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_xor_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_xor_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_xor_si128(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16b pxor<Packet16b>(const Packet16b& a, const Packet16b& b) { return _mm_xor_si128(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_andnot_ps(b,a); }
+template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_andnot_pd(b,a); }
+template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_andnot_si128(b,a); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_le(const Packet4f& a, const Packet4f& b) { return _mm_cmple_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt(const Packet4f& a, const Packet4f& b) { return _mm_cmplt_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_lt_or_nan(const Packet4f& a, const Packet4f& b) { return _mm_cmpnge_ps(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4f pcmp_eq(const Packet4f& a, const Packet4f& b) { return _mm_cmpeq_ps(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_le(const Packet2d& a, const Packet2d& b) { return _mm_cmple_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_lt(const Packet2d& a, const Packet2d& b) { return _mm_cmplt_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_lt_or_nan(const Packet2d& a, const Packet2d& b) { return _mm_cmpnge_pd(a,b); }
+template<> EIGEN_STRONG_INLINE Packet2d pcmp_eq(const Packet2d& a, const Packet2d& b) { return _mm_cmpeq_pd(a,b); }
+
+template<> EIGEN_STRONG_INLINE Packet4i pcmp_lt(const Packet4i& a, const Packet4i& b) { return _mm_cmplt_epi32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pcmp_eq(const Packet4i& a, const Packet4i& b) { return _mm_cmpeq_epi32(a,b); }
+template<> EIGEN_STRONG_INLINE Packet16b pcmp_eq(const Packet16b& a, const Packet16b& b) { return _mm_cmpeq_epi8(a,b); }
+template<> EIGEN_STRONG_INLINE Packet4i pcmp_le(const Packet4i& a, const Packet4i& b) { return por(pcmp_lt(a,b), pcmp_eq(a,b)); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) {
+#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63
+ // There appears to be a bug in GCC, by which the optimizer may
+ // flip the argument order in calls to _mm_min_ps, so we have to
+ // resort to inline ASM here. This is supposed to be fixed in gcc6.3,
+ // see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72867
+ #ifdef EIGEN_VECTORIZE_AVX
+ Packet4f res;
+ asm("vminps %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b));
+ #else
+ Packet4f res = b;
+ asm("minps %[a], %[res]" : [res] "+x" (res) : [a] "x" (a));
+ #endif
+ return res;
+#else
+ // Arguments are reversed to match NaN propagation behavior of std::min.
+ return _mm_min_ps(b, a);
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) {
+#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63
+ // There appears to be a bug in GCC, by which the optimizer may
+ // flip the argument order in calls to _mm_min_pd, so we have to
+ // resort to inline ASM here. This is supposed to be fixed in gcc6.3,
+ // see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72867
+ #ifdef EIGEN_VECTORIZE_AVX
+ Packet2d res;
+ asm("vminpd %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b));
+ #else
+ Packet2d res = b;
+ asm("minpd %[a], %[res]" : [res] "+x" (res) : [a] "x" (a));
+ #endif
+ return res;
+#else
+ // Arguments are reversed to match NaN propagation behavior of std::min.
+ return _mm_min_pd(b, a);
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b)
+{
+#ifdef EIGEN_VECTORIZE_SSE4_1
+ return _mm_min_epi32(a,b);
+#else
+ // after some bench, this version *is* faster than a scalar implementation
+ Packet4i mask = _mm_cmplt_epi32(a,b);
+ return _mm_or_si128(_mm_and_si128(mask,a),_mm_andnot_si128(mask,b));
+#endif
+}
+
+
+template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) {
+#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63
+ // There appears to be a bug in GCC, by which the optimizer may
+ // flip the argument order in calls to _mm_max_ps, so we have to
+ // resort to inline ASM here. This is supposed to be fixed in gcc6.3,
+ // see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72867
+ #ifdef EIGEN_VECTORIZE_AVX
+ Packet4f res;
+ asm("vmaxps %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b));
+ #else
+ Packet4f res = b;
+ asm("maxps %[a], %[res]" : [res] "+x" (res) : [a] "x" (a));
+ #endif
+ return res;
+#else
+ // Arguments are reversed to match NaN propagation behavior of std::max.
+ return _mm_max_ps(b, a);
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) {
+#if EIGEN_COMP_GNUC && EIGEN_COMP_GNUC < 63
+ // There appears to be a bug in GCC, by which the optimizer may
+ // flip the argument order in calls to _mm_max_pd, so we have to
+ // resort to inline ASM here. This is supposed to be fixed in gcc6.3,
+ // see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72867
+ #ifdef EIGEN_VECTORIZE_AVX
+ Packet2d res;
+ asm("vmaxpd %[a], %[b], %[res]" : [res] "=x" (res) : [a] "x" (a), [b] "x" (b));
+ #else
+ Packet2d res = b;
+ asm("maxpd %[a], %[res]" : [res] "+x" (res) : [a] "x" (a));
+ #endif
+ return res;
+#else
+ // Arguments are reversed to match NaN propagation behavior of std::max.
+ return _mm_max_pd(b, a);
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b)
+{
+#ifdef EIGEN_VECTORIZE_SSE4_1
+ return _mm_max_epi32(a,b);
+#else
+ // after some bench, this version *is* faster than a scalar implementation
+ Packet4i mask = _mm_cmpgt_epi32(a,b);
+ return _mm_or_si128(_mm_and_si128(mask,a),_mm_andnot_si128(mask,b));
+#endif
+}
+
+template <typename Packet, typename Op>
+EIGEN_STRONG_INLINE Packet pminmax_propagate_numbers(const Packet& a, const Packet& b, Op op) {
+ // In this implementation, we take advantage of the fact that pmin/pmax for SSE
+ // always return a if either a or b is NaN.
+ Packet not_nan_mask_a = pcmp_eq(a, a);
+ Packet m = op(a, b);
+ return pselect<Packet>(not_nan_mask_a, m, b);
+}
+
+template <typename Packet, typename Op>
+EIGEN_STRONG_INLINE Packet pminmax_propagate_nan(const Packet& a, const Packet& b, Op op) {
+ // In this implementation, we take advantage of the fact that pmin/pmax for SSE
+ // always return a if either a or b is NaN.
+ Packet not_nan_mask_a = pcmp_eq(a, a);
+ Packet m = op(b, a);
+ return pselect<Packet>(not_nan_mask_a, m, a);
+}
+
+// Add specializations for min/max with prescribed NaN progation.
+template<>
+EIGEN_STRONG_INLINE Packet4f pmin<PropagateNumbers, Packet4f>(const Packet4f& a, const Packet4f& b) {
+ return pminmax_propagate_numbers(a, b, pmin<Packet4f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet2d pmin<PropagateNumbers, Packet2d>(const Packet2d& a, const Packet2d& b) {
+ return pminmax_propagate_numbers(a, b, pmin<Packet2d>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet4f pmax<PropagateNumbers, Packet4f>(const Packet4f& a, const Packet4f& b) {
+ return pminmax_propagate_numbers(a, b, pmax<Packet4f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet2d pmax<PropagateNumbers, Packet2d>(const Packet2d& a, const Packet2d& b) {
+ return pminmax_propagate_numbers(a, b, pmax<Packet2d>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet4f pmin<PropagateNaN, Packet4f>(const Packet4f& a, const Packet4f& b) {
+ return pminmax_propagate_nan(a, b, pmin<Packet4f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet2d pmin<PropagateNaN, Packet2d>(const Packet2d& a, const Packet2d& b) {
+ return pminmax_propagate_nan(a, b, pmin<Packet2d>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet4f pmax<PropagateNaN, Packet4f>(const Packet4f& a, const Packet4f& b) {
+ return pminmax_propagate_nan(a, b, pmax<Packet4f>);
+}
+template<>
+EIGEN_STRONG_INLINE Packet2d pmax<PropagateNaN, Packet2d>(const Packet2d& a, const Packet2d& b) {
+ return pminmax_propagate_nan(a, b, pmax<Packet2d>);
+}
+
+template<int N> EIGEN_STRONG_INLINE Packet4i parithmetic_shift_right(const Packet4i& a) { return _mm_srai_epi32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4i plogical_shift_right (const Packet4i& a) { return _mm_srli_epi32(a,N); }
+template<int N> EIGEN_STRONG_INLINE Packet4i plogical_shift_left (const Packet4i& a) { return _mm_slli_epi32(a,N); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a)
+{
+ const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF));
+ return _mm_and_ps(a,mask);
+}
+template<> EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a)
+{
+ const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0x7FFFFFFF));
+ return _mm_and_pd(a,mask);
+}
+template<> EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a)
+{
+ #ifdef EIGEN_VECTORIZE_SSSE3
+ return _mm_abs_epi32(a);
+ #else
+ Packet4i aux = _mm_srai_epi32(a,31);
+ return _mm_sub_epi32(_mm_xor_si128(a,aux),aux);
+ #endif
+}
+
+#ifdef EIGEN_VECTORIZE_SSE4_1
+template<> EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a)
+{
+ // Unfortunatly _mm_round_ps doesn't have a rounding mode to implement numext::round.
+ const Packet4f mask = pset1frombits<Packet4f>(0x80000000u);
+ const Packet4f prev0dot5 = pset1frombits<Packet4f>(0x3EFFFFFFu);
+ return _mm_round_ps(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a)
+{
+ const Packet2d mask = _mm_castsi128_pd(_mm_set_epi64x(0x8000000000000000ull, 0x8000000000000000ull));
+ const Packet2d prev0dot5 = _mm_castsi128_pd(_mm_set_epi64x(0x3FDFFFFFFFFFFFFFull, 0x3FDFFFFFFFFFFFFFull));
+ return _mm_round_pd(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f print<Packet4f>(const Packet4f& a) { return _mm_round_ps(a, _MM_FROUND_CUR_DIRECTION); }
+template<> EIGEN_STRONG_INLINE Packet2d print<Packet2d>(const Packet2d& a) { return _mm_round_pd(a, _MM_FROUND_CUR_DIRECTION); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) { return _mm_ceil_ps(a); }
+template<> EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) { return _mm_ceil_pd(a); }
+
+template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) { return _mm_floor_ps(a); }
+template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) { return _mm_floor_pd(a); }
+#else
+template<> EIGEN_STRONG_INLINE Packet4f print(const Packet4f& a) {
+ // Adds and subtracts signum(a) * 2^23 to force rounding.
+ const Packet4f limit = pset1<Packet4f>(static_cast<float>(1<<23));
+ const Packet4f abs_a = pabs(a);
+ Packet4f r = padd(abs_a, limit);
+ // Don't compile-away addition and subtraction.
+ EIGEN_OPTIMIZATION_BARRIER(r);
+ r = psub(r, limit);
+ // If greater than limit, simply return a. Otherwise, account for sign.
+ r = pselect(pcmp_lt(abs_a, limit),
+ pselect(pcmp_lt(a, pzero(a)), pnegate(r), r), a);
+ return r;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d print(const Packet2d& a) {
+ // Adds and subtracts signum(a) * 2^52 to force rounding.
+ const Packet2d limit = pset1<Packet2d>(static_cast<double>(1ull<<52));
+ const Packet2d abs_a = pabs(a);
+ Packet2d r = padd(abs_a, limit);
+ // Don't compile-away addition and subtraction.
+ EIGEN_OPTIMIZATION_BARRIER(r);
+ r = psub(r, limit);
+ // If greater than limit, simply return a. Otherwise, account for sign.
+ r = pselect(pcmp_lt(abs_a, limit),
+ pselect(pcmp_lt(a, pzero(a)), pnegate(r), r), a);
+ return r;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a)
+{
+ const Packet4f cst_1 = pset1<Packet4f>(1.0f);
+ Packet4f tmp = print<Packet4f>(a);
+ // If greater, subtract one.
+ Packet4f mask = _mm_cmpgt_ps(tmp, a);
+ mask = pand(mask, cst_1);
+ return psub(tmp, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a)
+{
+ const Packet2d cst_1 = pset1<Packet2d>(1.0);
+ Packet2d tmp = print<Packet2d>(a);
+ // If greater, subtract one.
+ Packet2d mask = _mm_cmpgt_pd(tmp, a);
+ mask = pand(mask, cst_1);
+ return psub(tmp, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a)
+{
+ const Packet4f cst_1 = pset1<Packet4f>(1.0f);
+ Packet4f tmp = print<Packet4f>(a);
+ // If smaller, add one.
+ Packet4f mask = _mm_cmplt_ps(tmp, a);
+ mask = pand(mask, cst_1);
+ return padd(tmp, mask);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a)
+{
+ const Packet2d cst_1 = pset1<Packet2d>(1.0);
+ Packet2d tmp = print<Packet2d>(a);
+ // If smaller, add one.
+ Packet2d mask = _mm_cmplt_pd(tmp, a);
+ mask = pand(mask, cst_1);
+ return padd(tmp, mask);
+}
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm_load_ps(from); }
+template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm_load_pd(from); }
+template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm_load_si128(reinterpret_cast<const __m128i*>(from)); }
+template<> EIGEN_STRONG_INLINE Packet16b pload<Packet16b>(const bool* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm_load_si128(reinterpret_cast<const __m128i*>(from)); }
+
+#if EIGEN_COMP_MSVC
+ template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) {
+ EIGEN_DEBUG_UNALIGNED_LOAD
+ #if (EIGEN_COMP_MSVC==1600)
+ // NOTE Some version of MSVC10 generates bad code when using _mm_loadu_ps
+ // (i.e., it does not generate an unaligned load!!
+ __m128 res = _mm_loadl_pi(_mm_set1_ps(0.0f), (const __m64*)(from));
+ res = _mm_loadh_pi(res, (const __m64*)(from+2));
+ return res;
+ #else
+ return _mm_loadu_ps(from);
+ #endif
+ }
+#else
+// NOTE: with the code below, MSVC's compiler crashes!
+
+template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from)
+{
+ EIGEN_DEBUG_UNALIGNED_LOAD
+ return _mm_loadu_ps(from);
+}
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from)
+{
+ EIGEN_DEBUG_UNALIGNED_LOAD
+ return _mm_loadu_pd(from);
+}
+template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from)
+{
+ EIGEN_DEBUG_UNALIGNED_LOAD
+ return _mm_loadu_si128(reinterpret_cast<const __m128i*>(from));
+}
+template<> EIGEN_STRONG_INLINE Packet16b ploadu<Packet16b>(const bool* from) {
+ EIGEN_DEBUG_UNALIGNED_LOAD
+ return _mm_loadu_si128(reinterpret_cast<const __m128i*>(from));
+}
+
+
+template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from)
+{
+ return vec4f_swizzle1(_mm_castpd_ps(_mm_load_sd(reinterpret_cast<const double*>(from))), 0, 0, 1, 1);
+}
+template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from)
+{ return pset1<Packet2d>(from[0]); }
+template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int* from)
+{
+ Packet4i tmp;
+ tmp = _mm_loadl_epi64(reinterpret_cast<const __m128i*>(from));
+ return vec4i_swizzle1(tmp, 0, 0, 1, 1);
+}
+
+// Loads 8 bools from memory and returns the packet
+// {b0, b0, b1, b1, b2, b2, b3, b3, b4, b4, b5, b5, b6, b6, b7, b7}
+template<> EIGEN_STRONG_INLINE Packet16b ploaddup<Packet16b>(const bool* from)
+{
+ __m128i tmp = _mm_castpd_si128(pload1<Packet2d>(reinterpret_cast<const double*>(from)));
+ return _mm_unpacklo_epi8(tmp, tmp);
+}
+
+// Loads 4 bools from memory and returns the packet
+// {b0, b0 b0, b0, b1, b1, b1, b1, b2, b2, b2, b2, b3, b3, b3, b3}
+template<> EIGEN_STRONG_INLINE Packet16b
+ploadquad<Packet16b>(const bool* from) {
+ __m128i tmp = _mm_castps_si128(pload1<Packet4f>(reinterpret_cast<const float*>(from)));
+ tmp = _mm_unpacklo_epi8(tmp, tmp);
+ return _mm_unpacklo_epi16(tmp, tmp);
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_ps(to, from); }
+template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_pd(to, from); }
+template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet4i& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_si128(reinterpret_cast<__m128i*>(to), from); }
+template<> EIGEN_STRONG_INLINE void pstore<bool>(bool* to, const Packet16b& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_si128(reinterpret_cast<__m128i*>(to), from); }
+
+template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_pd(to, from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_ps(to, from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) { EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_si128(reinterpret_cast<__m128i*>(to), from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<bool>(bool* to, const Packet16b& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_storeu_si128(reinterpret_cast<__m128i*>(to), from); }
+
+template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride)
+{
+ return _mm_set_ps(from[3*stride], from[2*stride], from[1*stride], from[0*stride]);
+}
+template<> EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride)
+{
+ return _mm_set_pd(from[1*stride], from[0*stride]);
+}
+template<> EIGEN_DEVICE_FUNC inline Packet4i pgather<int, Packet4i>(const int* from, Index stride)
+{
+ return _mm_set_epi32(from[3*stride], from[2*stride], from[1*stride], from[0*stride]);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet16b pgather<bool, Packet16b>(const bool* from, Index stride)
+{
+ return _mm_set_epi8(from[15*stride], from[14*stride], from[13*stride], from[12*stride],
+ from[11*stride], from[10*stride], from[9*stride], from[8*stride],
+ from[7*stride], from[6*stride], from[5*stride], from[4*stride],
+ from[3*stride], from[2*stride], from[1*stride], from[0*stride]);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride)
+{
+ to[stride*0] = _mm_cvtss_f32(from);
+ to[stride*1] = _mm_cvtss_f32(_mm_shuffle_ps(from, from, 1));
+ to[stride*2] = _mm_cvtss_f32(_mm_shuffle_ps(from, from, 2));
+ to[stride*3] = _mm_cvtss_f32(_mm_shuffle_ps(from, from, 3));
+}
+template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride)
+{
+ to[stride*0] = _mm_cvtsd_f64(from);
+ to[stride*1] = _mm_cvtsd_f64(_mm_shuffle_pd(from, from, 1));
+}
+template<> EIGEN_DEVICE_FUNC inline void pscatter<int, Packet4i>(int* to, const Packet4i& from, Index stride)
+{
+ to[stride*0] = _mm_cvtsi128_si32(from);
+ to[stride*1] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 1));
+ to[stride*2] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 2));
+ to[stride*3] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 3));
+}
+template<> EIGEN_DEVICE_FUNC inline void pscatter<bool, Packet16b>(bool* to, const Packet16b& from, Index stride)
+{
+ to[4*stride*0] = _mm_cvtsi128_si32(from);
+ to[4*stride*1] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 1));
+ to[4*stride*2] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 2));
+ to[4*stride*3] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 3));
+}
+
+
+// some compilers might be tempted to perform multiple moves instead of using a vector path.
+template<> EIGEN_STRONG_INLINE void pstore1<Packet4f>(float* to, const float& a)
+{
+ Packet4f pa = _mm_set_ss(a);
+ pstore(to, Packet4f(vec4f_swizzle1(pa,0,0,0,0)));
+}
+// some compilers might be tempted to perform multiple moves instead of using a vector path.
+template<> EIGEN_STRONG_INLINE void pstore1<Packet2d>(double* to, const double& a)
+{
+ Packet2d pa = _mm_set_sd(a);
+ pstore(to, Packet2d(vec2d_swizzle1(pa,0,0)));
+}
+
+#if EIGEN_COMP_PGI && EIGEN_COMP_PGI < 1900
+typedef const void * SsePrefetchPtrType;
+#else
+typedef const char * SsePrefetchPtrType;
+#endif
+
+#ifndef EIGEN_VECTORIZE_AVX
+template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
+template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
+template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
+#endif
+
+#if EIGEN_COMP_MSVC_STRICT && EIGEN_OS_WIN64
+// The temporary variable fixes an internal compilation error in vs <= 2008 and a wrong-result bug in vs 2010
+// Direct of the struct members fixed bug #62.
+template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { return a.m128_f32[0]; }
+template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { return a.m128d_f64[0]; }
+template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { int x = _mm_cvtsi128_si32(a); return x; }
+#elif EIGEN_COMP_MSVC_STRICT
+// The temporary variable fixes an internal compilation error in vs <= 2008 and a wrong-result bug in vs 2010
+template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { float x = _mm_cvtss_f32(a); return x; }
+template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { double x = _mm_cvtsd_f64(a); return x; }
+template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { int x = _mm_cvtsi128_si32(a); return x; }
+#else
+template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { return _mm_cvtss_f32(a); }
+template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { return _mm_cvtsd_f64(a); }
+template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { return _mm_cvtsi128_si32(a); }
+#endif
+template<> EIGEN_STRONG_INLINE bool pfirst<Packet16b>(const Packet16b& a) { int x = _mm_cvtsi128_si32(a); return static_cast<bool>(x & 1); }
+
+template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) { return _mm_shuffle_ps(a,a,0x1B); }
+template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a) { return _mm_shuffle_pd(a,a,0x1); }
+template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) { return _mm_shuffle_epi32(a,0x1B); }
+template<> EIGEN_STRONG_INLINE Packet16b preverse(const Packet16b& a) {
+#ifdef EIGEN_VECTORIZE_SSSE3
+ __m128i mask = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+ return _mm_shuffle_epi8(a, mask);
+#else
+ Packet16b tmp = _mm_shuffle_epi32(a, _MM_SHUFFLE(0, 1, 2, 3));
+ tmp = _mm_shufflehi_epi16(_mm_shufflelo_epi16(tmp, _MM_SHUFFLE(2, 3, 0, 1)), _MM_SHUFFLE(2, 3, 0, 1));
+ return _mm_or_si128(_mm_slli_epi16(tmp, 8), _mm_srli_epi16(tmp, 8));
+#endif
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pfrexp<Packet4f>(const Packet4f& a, Packet4f& exponent) {
+ return pfrexp_generic(a,exponent);
+}
+
+// Extract exponent without existence of Packet2l.
+template<>
+EIGEN_STRONG_INLINE
+Packet2d pfrexp_generic_get_biased_exponent(const Packet2d& a) {
+ const Packet2d cst_exp_mask = pset1frombits<Packet2d>(static_cast<uint64_t>(0x7ff0000000000000ull));
+ __m128i a_expo = _mm_srli_epi64(_mm_castpd_si128(pand(a, cst_exp_mask)), 52);
+ return _mm_cvtepi32_pd(vec4i_swizzle1(a_expo, 0, 2, 1, 3));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pfrexp<Packet2d>(const Packet2d& a, Packet2d& exponent) {
+ return pfrexp_generic(a, exponent);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pldexp<Packet4f>(const Packet4f& a, const Packet4f& exponent) {
+ return pldexp_generic(a,exponent);
+}
+
+// We specialize pldexp here, since the generic implementation uses Packet2l, which is not well
+// supported by SSE, and has more range than is needed for exponents.
+template<> EIGEN_STRONG_INLINE Packet2d pldexp<Packet2d>(const Packet2d& a, const Packet2d& exponent) {
+ // Clamp exponent to [-2099, 2099]
+ const Packet2d max_exponent = pset1<Packet2d>(2099.0);
+ const Packet2d e = pmin(pmax(exponent, pnegate(max_exponent)), max_exponent);
+
+ // Convert e to integer and swizzle to low-order bits.
+ const Packet4i ei = vec4i_swizzle1(_mm_cvtpd_epi32(e), 0, 3, 1, 3);
+
+ // Split 2^e into four factors and multiply:
+ const Packet4i bias = _mm_set_epi32(0, 1023, 0, 1023);
+ Packet4i b = parithmetic_shift_right<2>(ei); // floor(e/4)
+ Packet2d c = _mm_castsi128_pd(_mm_slli_epi64(padd(b, bias), 52)); // 2^b
+ Packet2d out = pmul(pmul(pmul(a, c), c), c); // a * 2^(3b)
+ b = psub(psub(psub(ei, b), b), b); // e - 3b
+ c = _mm_castsi128_pd(_mm_slli_epi64(padd(b, bias), 52)); // 2^(e - 3b)
+ out = pmul(out, c); // a * 2^e
+ return out;
+}
+
+// with AVX, the default implementations based on pload1 are faster
+#ifndef __AVX__
+template<> EIGEN_STRONG_INLINE void
+pbroadcast4<Packet4f>(const float *a,
+ Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3)
+{
+ a3 = pload<Packet4f>(a);
+ a0 = vec4f_swizzle1(a3, 0,0,0,0);
+ a1 = vec4f_swizzle1(a3, 1,1,1,1);
+ a2 = vec4f_swizzle1(a3, 2,2,2,2);
+ a3 = vec4f_swizzle1(a3, 3,3,3,3);
+}
+template<> EIGEN_STRONG_INLINE void
+pbroadcast4<Packet2d>(const double *a,
+ Packet2d& a0, Packet2d& a1, Packet2d& a2, Packet2d& a3)
+{
+#ifdef EIGEN_VECTORIZE_SSE3
+ a0 = _mm_loaddup_pd(a+0);
+ a1 = _mm_loaddup_pd(a+1);
+ a2 = _mm_loaddup_pd(a+2);
+ a3 = _mm_loaddup_pd(a+3);
+#else
+ a1 = pload<Packet2d>(a);
+ a0 = vec2d_swizzle1(a1, 0,0);
+ a1 = vec2d_swizzle1(a1, 1,1);
+ a3 = pload<Packet2d>(a+2);
+ a2 = vec2d_swizzle1(a3, 0,0);
+ a3 = vec2d_swizzle1(a3, 1,1);
+#endif
+}
+#endif
+
+EIGEN_STRONG_INLINE void punpackp(Packet4f* vecs)
+{
+ vecs[1] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x55));
+ vecs[2] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xAA));
+ vecs[3] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xFF));
+ vecs[0] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x00));
+}
+
+template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a)
+{
+ // Disable SSE3 _mm_hadd_pd that is extremely slow on all existing Intel's architectures
+ // (from Nehalem to Haswell)
+// #ifdef EIGEN_VECTORIZE_SSE3
+// Packet4f tmp = _mm_add_ps(a, vec4f_swizzle1(a,2,3,2,3));
+// return pfirst<Packet4f>(_mm_hadd_ps(tmp, tmp));
+// #else
+ Packet4f tmp = _mm_add_ps(a, _mm_movehl_ps(a,a));
+ return pfirst<Packet4f>(_mm_add_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
+// #endif
+}
+
+template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a)
+{
+ // Disable SSE3 _mm_hadd_pd that is extremely slow on all existing Intel's architectures
+ // (from Nehalem to Haswell)
+// #ifdef EIGEN_VECTORIZE_SSE3
+// return pfirst<Packet2d>(_mm_hadd_pd(a, a));
+// #else
+ return pfirst<Packet2d>(_mm_add_sd(a, _mm_unpackhi_pd(a,a)));
+// #endif
+}
+
+#ifdef EIGEN_VECTORIZE_SSSE3
+template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a)
+{
+ Packet4i tmp0 = _mm_hadd_epi32(a,a);
+ return pfirst<Packet4i>(_mm_hadd_epi32(tmp0,tmp0));
+}
+
+#else
+template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a)
+{
+ Packet4i tmp = _mm_add_epi32(a, _mm_unpackhi_epi64(a,a));
+ return pfirst(tmp) + pfirst<Packet4i>(_mm_shuffle_epi32(tmp, 1));
+}
+#endif
+
+template<> EIGEN_STRONG_INLINE bool predux<Packet16b>(const Packet16b& a) {
+ Packet4i tmp = _mm_or_si128(a, _mm_unpackhi_epi64(a,a));
+ return (pfirst(tmp) != 0) || (pfirst<Packet4i>(_mm_shuffle_epi32(tmp, 1)) != 0);
+}
+
+// Other reduction functions:
+
+
+// mul
+template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a)
+{
+ Packet4f tmp = _mm_mul_ps(a, _mm_movehl_ps(a,a));
+ return pfirst<Packet4f>(_mm_mul_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
+}
+template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a)
+{
+ return pfirst<Packet2d>(_mm_mul_sd(a, _mm_unpackhi_pd(a,a)));
+}
+template<> EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a)
+{
+ // after some experiments, it is seems this is the fastest way to implement it
+ // for GCC (eg., reusing pmul is very slow !)
+ // TODO try to call _mm_mul_epu32 directly
+ EIGEN_ALIGN16 int aux[4];
+ pstore(aux, a);
+ return (aux[0] * aux[1]) * (aux[2] * aux[3]);
+}
+
+template<> EIGEN_STRONG_INLINE bool predux_mul<Packet16b>(const Packet16b& a) {
+ Packet4i tmp = _mm_and_si128(a, _mm_unpackhi_epi64(a,a));
+ return ((pfirst<Packet4i>(tmp) == 0x01010101) &&
+ (pfirst<Packet4i>(_mm_shuffle_epi32(tmp, 1)) == 0x01010101));
+}
+
+// min
+template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a)
+{
+ Packet4f tmp = _mm_min_ps(a, _mm_movehl_ps(a,a));
+ return pfirst<Packet4f>(_mm_min_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
+}
+template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a)
+{
+ return pfirst<Packet2d>(_mm_min_sd(a, _mm_unpackhi_pd(a,a)));
+}
+template<> EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a)
+{
+#ifdef EIGEN_VECTORIZE_SSE4_1
+ Packet4i tmp = _mm_min_epi32(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(0,0,3,2)));
+ return pfirst<Packet4i>(_mm_min_epi32(tmp,_mm_shuffle_epi32(tmp, 1)));
+#else
+ // after some experiments, it is seems this is the fastest way to implement it
+ // for GCC (eg., it does not like using std::min after the pstore !!)
+ EIGEN_ALIGN16 int aux[4];
+ pstore(aux, a);
+ int aux0 = aux[0]<aux[1] ? aux[0] : aux[1];
+ int aux2 = aux[2]<aux[3] ? aux[2] : aux[3];
+ return aux0<aux2 ? aux0 : aux2;
+#endif // EIGEN_VECTORIZE_SSE4_1
+}
+
+// max
+template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a)
+{
+ Packet4f tmp = _mm_max_ps(a, _mm_movehl_ps(a,a));
+ return pfirst<Packet4f>(_mm_max_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
+}
+template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a)
+{
+ return pfirst<Packet2d>(_mm_max_sd(a, _mm_unpackhi_pd(a,a)));
+}
+template<> EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a)
+{
+#ifdef EIGEN_VECTORIZE_SSE4_1
+ Packet4i tmp = _mm_max_epi32(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(0,0,3,2)));
+ return pfirst<Packet4i>(_mm_max_epi32(tmp,_mm_shuffle_epi32(tmp, 1)));
+#else
+ // after some experiments, it is seems this is the fastest way to implement it
+ // for GCC (eg., it does not like using std::min after the pstore !!)
+ EIGEN_ALIGN16 int aux[4];
+ pstore(aux, a);
+ int aux0 = aux[0]>aux[1] ? aux[0] : aux[1];
+ int aux2 = aux[2]>aux[3] ? aux[2] : aux[3];
+ return aux0>aux2 ? aux0 : aux2;
+#endif // EIGEN_VECTORIZE_SSE4_1
+}
+
+// not needed yet
+// template<> EIGEN_STRONG_INLINE bool predux_all(const Packet4f& x)
+// {
+// return _mm_movemask_ps(x) == 0xF;
+// }
+
+template<> EIGEN_STRONG_INLINE bool predux_any(const Packet4f& x)
+{
+ return _mm_movemask_ps(x) != 0x0;
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet4f,4>& kernel) {
+ _MM_TRANSPOSE4_PS(kernel.packet[0], kernel.packet[1], kernel.packet[2], kernel.packet[3]);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet2d,2>& kernel) {
+ __m128d tmp = _mm_unpackhi_pd(kernel.packet[0], kernel.packet[1]);
+ kernel.packet[0] = _mm_unpacklo_pd(kernel.packet[0], kernel.packet[1]);
+ kernel.packet[1] = tmp;
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet4i,4>& kernel) {
+ __m128i T0 = _mm_unpacklo_epi32(kernel.packet[0], kernel.packet[1]);
+ __m128i T1 = _mm_unpacklo_epi32(kernel.packet[2], kernel.packet[3]);
+ __m128i T2 = _mm_unpackhi_epi32(kernel.packet[0], kernel.packet[1]);
+ __m128i T3 = _mm_unpackhi_epi32(kernel.packet[2], kernel.packet[3]);
+
+ kernel.packet[0] = _mm_unpacklo_epi64(T0, T1);
+ kernel.packet[1] = _mm_unpackhi_epi64(T0, T1);
+ kernel.packet[2] = _mm_unpacklo_epi64(T2, T3);
+ kernel.packet[3] = _mm_unpackhi_epi64(T2, T3);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet16b,4>& kernel) {
+ __m128i T0 = _mm_unpacklo_epi8(kernel.packet[0], kernel.packet[1]);
+ __m128i T1 = _mm_unpackhi_epi8(kernel.packet[0], kernel.packet[1]);
+ __m128i T2 = _mm_unpacklo_epi8(kernel.packet[2], kernel.packet[3]);
+ __m128i T3 = _mm_unpackhi_epi8(kernel.packet[2], kernel.packet[3]);
+ kernel.packet[0] = _mm_unpacklo_epi16(T0, T2);
+ kernel.packet[1] = _mm_unpackhi_epi16(T0, T2);
+ kernel.packet[2] = _mm_unpacklo_epi16(T1, T3);
+ kernel.packet[3] = _mm_unpackhi_epi16(T1, T3);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet16b,16>& kernel) {
+ // If we number the elements in the input thus:
+ // kernel.packet[ 0] = {00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f}
+ // kernel.packet[ 1] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1a, 1b, 1c, 1d, 1e, 1f}
+ // ...
+ // kernel.packet[15] = {f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, fa, fb, fc, fd, fe, ff},
+ //
+ // the desired output is:
+ // kernel.packet[ 0] = {00, 10, 20, 30, 40, 50, 60, 70, 80, 90, a0, b0, c0, d0, e0, f0}
+ // kernel.packet[ 1] = {01, 11, 21, 31, 41, 51, 61, 71, 81, 91, a1, b1, c1, d1, e1, f1}
+ // ...
+ // kernel.packet[15] = {0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, af, bf, cf, df, ef, ff},
+ __m128i t0 = _mm_unpacklo_epi8(kernel.packet[0], kernel.packet[1]); // 00 10 01 11 02 12 03 13 04 14 05 15 06 16 07 17
+ __m128i t1 = _mm_unpackhi_epi8(kernel.packet[0], kernel.packet[1]); // 08 18 09 19 0a 1a 0b 1b 0c 1c 0d 1d 0e 1e 0f 1f
+ __m128i t2 = _mm_unpacklo_epi8(kernel.packet[2], kernel.packet[3]); // 20 30 21 31 22 32 ... 27 37
+ __m128i t3 = _mm_unpackhi_epi8(kernel.packet[2], kernel.packet[3]); // 28 38 29 39 2a 3a ... 2f 3f
+ __m128i t4 = _mm_unpacklo_epi8(kernel.packet[4], kernel.packet[5]); // 40 50 41 51 42 52 47 57
+ __m128i t5 = _mm_unpackhi_epi8(kernel.packet[4], kernel.packet[5]); // 48 58 49 59 4a 5a
+ __m128i t6 = _mm_unpacklo_epi8(kernel.packet[6], kernel.packet[7]);
+ __m128i t7 = _mm_unpackhi_epi8(kernel.packet[6], kernel.packet[7]);
+ __m128i t8 = _mm_unpacklo_epi8(kernel.packet[8], kernel.packet[9]);
+ __m128i t9 = _mm_unpackhi_epi8(kernel.packet[8], kernel.packet[9]);
+ __m128i ta = _mm_unpacklo_epi8(kernel.packet[10], kernel.packet[11]);
+ __m128i tb = _mm_unpackhi_epi8(kernel.packet[10], kernel.packet[11]);
+ __m128i tc = _mm_unpacklo_epi8(kernel.packet[12], kernel.packet[13]);
+ __m128i td = _mm_unpackhi_epi8(kernel.packet[12], kernel.packet[13]);
+ __m128i te = _mm_unpacklo_epi8(kernel.packet[14], kernel.packet[15]);
+ __m128i tf = _mm_unpackhi_epi8(kernel.packet[14], kernel.packet[15]);
+
+ __m128i s0 = _mm_unpacklo_epi16(t0, t2); // 00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
+ __m128i s1 = _mm_unpackhi_epi16(t0, t2); // 04 14 24 34
+ __m128i s2 = _mm_unpacklo_epi16(t1, t3); // 08 18 28 38 ...
+ __m128i s3 = _mm_unpackhi_epi16(t1, t3); // 0c 1c 2c 3c ...
+ __m128i s4 = _mm_unpacklo_epi16(t4, t6); // 40 50 60 70 41 51 61 71 42 52 62 72 43 53 63 73
+ __m128i s5 = _mm_unpackhi_epi16(t4, t6); // 44 54 64 74 ...
+ __m128i s6 = _mm_unpacklo_epi16(t5, t7);
+ __m128i s7 = _mm_unpackhi_epi16(t5, t7);
+ __m128i s8 = _mm_unpacklo_epi16(t8, ta);
+ __m128i s9 = _mm_unpackhi_epi16(t8, ta);
+ __m128i sa = _mm_unpacklo_epi16(t9, tb);
+ __m128i sb = _mm_unpackhi_epi16(t9, tb);
+ __m128i sc = _mm_unpacklo_epi16(tc, te);
+ __m128i sd = _mm_unpackhi_epi16(tc, te);
+ __m128i se = _mm_unpacklo_epi16(td, tf);
+ __m128i sf = _mm_unpackhi_epi16(td, tf);
+
+ __m128i u0 = _mm_unpacklo_epi32(s0, s4); // 00 10 20 30 40 50 60 70 01 11 21 31 41 51 61 71
+ __m128i u1 = _mm_unpackhi_epi32(s0, s4); // 02 12 22 32 42 52 62 72 03 13 23 33 43 53 63 73
+ __m128i u2 = _mm_unpacklo_epi32(s1, s5);
+ __m128i u3 = _mm_unpackhi_epi32(s1, s5);
+ __m128i u4 = _mm_unpacklo_epi32(s2, s6);
+ __m128i u5 = _mm_unpackhi_epi32(s2, s6);
+ __m128i u6 = _mm_unpacklo_epi32(s3, s7);
+ __m128i u7 = _mm_unpackhi_epi32(s3, s7);
+ __m128i u8 = _mm_unpacklo_epi32(s8, sc);
+ __m128i u9 = _mm_unpackhi_epi32(s8, sc);
+ __m128i ua = _mm_unpacklo_epi32(s9, sd);
+ __m128i ub = _mm_unpackhi_epi32(s9, sd);
+ __m128i uc = _mm_unpacklo_epi32(sa, se);
+ __m128i ud = _mm_unpackhi_epi32(sa, se);
+ __m128i ue = _mm_unpacklo_epi32(sb, sf);
+ __m128i uf = _mm_unpackhi_epi32(sb, sf);
+
+ kernel.packet[0] = _mm_unpacklo_epi64(u0, u8);
+ kernel.packet[1] = _mm_unpackhi_epi64(u0, u8);
+ kernel.packet[2] = _mm_unpacklo_epi64(u1, u9);
+ kernel.packet[3] = _mm_unpackhi_epi64(u1, u9);
+ kernel.packet[4] = _mm_unpacklo_epi64(u2, ua);
+ kernel.packet[5] = _mm_unpackhi_epi64(u2, ua);
+ kernel.packet[6] = _mm_unpacklo_epi64(u3, ub);
+ kernel.packet[7] = _mm_unpackhi_epi64(u3, ub);
+ kernel.packet[8] = _mm_unpacklo_epi64(u4, uc);
+ kernel.packet[9] = _mm_unpackhi_epi64(u4, uc);
+ kernel.packet[10] = _mm_unpacklo_epi64(u5, ud);
+ kernel.packet[11] = _mm_unpackhi_epi64(u5, ud);
+ kernel.packet[12] = _mm_unpacklo_epi64(u6, ue);
+ kernel.packet[13] = _mm_unpackhi_epi64(u6, ue);
+ kernel.packet[14] = _mm_unpacklo_epi64(u7, uf);
+ kernel.packet[15] = _mm_unpackhi_epi64(u7, uf);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i pblend(const Selector<4>& ifPacket, const Packet4i& thenPacket, const Packet4i& elsePacket) {
+ const __m128i zero = _mm_setzero_si128();
+ const __m128i select = _mm_set_epi32(ifPacket.select[3], ifPacket.select[2], ifPacket.select[1], ifPacket.select[0]);
+ __m128i false_mask = _mm_cmpeq_epi32(select, zero);
+#ifdef EIGEN_VECTORIZE_SSE4_1
+ return _mm_blendv_epi8(thenPacket, elsePacket, false_mask);
+#else
+ return _mm_or_si128(_mm_andnot_si128(false_mask, thenPacket), _mm_and_si128(false_mask, elsePacket));
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, const Packet4f& elsePacket) {
+ const __m128 zero = _mm_setzero_ps();
+ const __m128 select = _mm_set_ps(ifPacket.select[3], ifPacket.select[2], ifPacket.select[1], ifPacket.select[0]);
+ __m128 false_mask = _mm_cmpeq_ps(select, zero);
+#ifdef EIGEN_VECTORIZE_SSE4_1
+ return _mm_blendv_ps(thenPacket, elsePacket, false_mask);
+#else
+ return _mm_or_ps(_mm_andnot_ps(false_mask, thenPacket), _mm_and_ps(false_mask, elsePacket));
+#endif
+}
+template<> EIGEN_STRONG_INLINE Packet2d pblend(const Selector<2>& ifPacket, const Packet2d& thenPacket, const Packet2d& elsePacket) {
+ const __m128d zero = _mm_setzero_pd();
+ const __m128d select = _mm_set_pd(ifPacket.select[1], ifPacket.select[0]);
+ __m128d false_mask = _mm_cmpeq_pd(select, zero);
+#ifdef EIGEN_VECTORIZE_SSE4_1
+ return _mm_blendv_pd(thenPacket, elsePacket, false_mask);
+#else
+ return _mm_or_pd(_mm_andnot_pd(false_mask, thenPacket), _mm_and_pd(false_mask, elsePacket));
+#endif
+}
+
+// Scalar path for pmadd with FMA to ensure consistency with vectorized path.
+#ifdef EIGEN_VECTORIZE_FMA
+template<> EIGEN_STRONG_INLINE float pmadd(const float& a, const float& b, const float& c) {
+ return ::fmaf(a,b,c);
+}
+template<> EIGEN_STRONG_INLINE double pmadd(const double& a, const double& b, const double& c) {
+ return ::fma(a,b,c);
+}
+#endif
+
+
+// Packet math for Eigen::half
+// Disable the following code since it's broken on too many platforms / compilers.
+//#elif defined(EIGEN_VECTORIZE_SSE) && (!EIGEN_ARCH_x86_64) && (!EIGEN_COMP_MSVC)
+#if 0
+
+typedef struct {
+ __m64 x;
+} Packet4h;
+
+
+template<> struct is_arithmetic<Packet4h> { enum { value = true }; };
+
+template <>
+struct packet_traits<Eigen::half> : default_packet_traits {
+ typedef Packet4h type;
+ // There is no half-size packet for Packet4h.
+ typedef Packet4h half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 0,
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 0,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasConj = 0,
+ HasSetLinear = 0,
+ HasSqrt = 0,
+ HasRsqrt = 0,
+ HasExp = 0,
+ HasLog = 0,
+ HasBlend = 0
+ };
+};
+
+
+template<> struct unpacket_traits<Packet4h> { typedef Eigen::half type; enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet4h half; };
+
+template<> EIGEN_STRONG_INLINE Packet4h pset1<Packet4h>(const Eigen::half& from) {
+ Packet4h result;
+ result.x = _mm_set1_pi16(from.x);
+ return result;
+}
+
+template<> EIGEN_STRONG_INLINE Eigen::half pfirst<Packet4h>(const Packet4h& from) {
+ return half_impl::raw_uint16_to_half(static_cast<unsigned short>(_mm_cvtsi64_si32(from.x)));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4h pconj(const Packet4h& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet4h padd<Packet4h>(const Packet4h& a, const Packet4h& b) {
+ __int64_t a64 = _mm_cvtm64_si64(a.x);
+ __int64_t b64 = _mm_cvtm64_si64(b.x);
+
+ Eigen::half h[4];
+
+ Eigen::half ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64));
+ Eigen::half hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64));
+ h[0] = ha + hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 16));
+ h[1] = ha + hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 32));
+ h[2] = ha + hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 48));
+ h[3] = ha + hb;
+ Packet4h result;
+ result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x);
+ return result;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4h psub<Packet4h>(const Packet4h& a, const Packet4h& b) {
+ __int64_t a64 = _mm_cvtm64_si64(a.x);
+ __int64_t b64 = _mm_cvtm64_si64(b.x);
+
+ Eigen::half h[4];
+
+ Eigen::half ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64));
+ Eigen::half hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64));
+ h[0] = ha - hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 16));
+ h[1] = ha - hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 32));
+ h[2] = ha - hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 48));
+ h[3] = ha - hb;
+ Packet4h result;
+ result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x);
+ return result;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4h pmul<Packet4h>(const Packet4h& a, const Packet4h& b) {
+ __int64_t a64 = _mm_cvtm64_si64(a.x);
+ __int64_t b64 = _mm_cvtm64_si64(b.x);
+
+ Eigen::half h[4];
+
+ Eigen::half ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64));
+ Eigen::half hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64));
+ h[0] = ha * hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 16));
+ h[1] = ha * hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 32));
+ h[2] = ha * hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 48));
+ h[3] = ha * hb;
+ Packet4h result;
+ result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x);
+ return result;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4h pdiv<Packet4h>(const Packet4h& a, const Packet4h& b) {
+ __int64_t a64 = _mm_cvtm64_si64(a.x);
+ __int64_t b64 = _mm_cvtm64_si64(b.x);
+
+ Eigen::half h[4];
+
+ Eigen::half ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64));
+ Eigen::half hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64));
+ h[0] = ha / hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 16));
+ h[1] = ha / hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 32));
+ h[2] = ha / hb;
+ ha = half_impl::raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48));
+ hb = half_impl::raw_uint16_to_half(static_cast<unsigned short>(b64 >> 48));
+ h[3] = ha / hb;
+ Packet4h result;
+ result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x);
+ return result;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4h pload<Packet4h>(const Eigen::half* from) {
+ Packet4h result;
+ result.x = _mm_cvtsi64_m64(*reinterpret_cast<const __int64_t*>(from));
+ return result;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4h ploadu<Packet4h>(const Eigen::half* from) {
+ Packet4h result;
+ result.x = _mm_cvtsi64_m64(*reinterpret_cast<const __int64_t*>(from));
+ return result;
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<Eigen::half>(Eigen::half* to, const Packet4h& from) {
+ __int64_t r = _mm_cvtm64_si64(from.x);
+ *(reinterpret_cast<__int64_t*>(to)) = r;
+}
+
+template<> EIGEN_STRONG_INLINE void pstoreu<Eigen::half>(Eigen::half* to, const Packet4h& from) {
+ __int64_t r = _mm_cvtm64_si64(from.x);
+ *(reinterpret_cast<__int64_t*>(to)) = r;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4h
+ploadquad<Packet4h>(const Eigen::half* from) {
+ return pset1<Packet4h>(*from);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4h pgather<Eigen::half, Packet4h>(const Eigen::half* from, Index stride)
+{
+ Packet4h result;
+ result.x = _mm_set_pi16(from[3*stride].x, from[2*stride].x, from[1*stride].x, from[0*stride].x);
+ return result;
+}
+
+template<> EIGEN_STRONG_INLINE void pscatter<Eigen::half, Packet4h>(Eigen::half* to, const Packet4h& from, Index stride)
+{
+ __int64_t a = _mm_cvtm64_si64(from.x);
+ to[stride*0].x = static_cast<unsigned short>(a);
+ to[stride*1].x = static_cast<unsigned short>(a >> 16);
+ to[stride*2].x = static_cast<unsigned short>(a >> 32);
+ to[stride*3].x = static_cast<unsigned short>(a >> 48);
+}
+
+EIGEN_STRONG_INLINE void
+ptranspose(PacketBlock<Packet4h,4>& kernel) {
+ __m64 T0 = _mm_unpacklo_pi16(kernel.packet[0].x, kernel.packet[1].x);
+ __m64 T1 = _mm_unpacklo_pi16(kernel.packet[2].x, kernel.packet[3].x);
+ __m64 T2 = _mm_unpackhi_pi16(kernel.packet[0].x, kernel.packet[1].x);
+ __m64 T3 = _mm_unpackhi_pi16(kernel.packet[2].x, kernel.packet[3].x);
+
+ kernel.packet[0].x = _mm_unpacklo_pi32(T0, T1);
+ kernel.packet[1].x = _mm_unpackhi_pi32(T0, T1);
+ kernel.packet[2].x = _mm_unpacklo_pi32(T2, T3);
+ kernel.packet[3].x = _mm_unpackhi_pi32(T2, T3);
+}
+
+#endif
+
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#if EIGEN_COMP_PGI && EIGEN_COMP_PGI < 1900
+// PGI++ does not define the following intrinsics in C++ mode.
+static inline __m128 _mm_castpd_ps (__m128d x) { return reinterpret_cast<__m128&>(x); }
+static inline __m128i _mm_castpd_si128(__m128d x) { return reinterpret_cast<__m128i&>(x); }
+static inline __m128d _mm_castps_pd (__m128 x) { return reinterpret_cast<__m128d&>(x); }
+static inline __m128i _mm_castps_si128(__m128 x) { return reinterpret_cast<__m128i&>(x); }
+static inline __m128 _mm_castsi128_ps(__m128i x) { return reinterpret_cast<__m128&>(x); }
+static inline __m128d _mm_castsi128_pd(__m128i x) { return reinterpret_cast<__m128d&>(x); }
+#endif
+
+#endif // EIGEN_PACKET_MATH_SSE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h
new file mode 100644
index 000000000..d2a0037e0
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h
@@ -0,0 +1,142 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TYPE_CASTING_SSE_H
+#define EIGEN_TYPE_CASTING_SSE_H
+
+namespace Eigen {
+
+namespace internal {
+
+#ifndef EIGEN_VECTORIZE_AVX
+template <>
+struct type_casting_traits<float, int> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template <>
+struct type_casting_traits<int, float> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template <>
+struct type_casting_traits<double, float> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 2,
+ TgtCoeffRatio = 1
+ };
+};
+
+template <>
+struct type_casting_traits<float, double> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 2
+ };
+};
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet4i pcast<Packet4f, Packet4i>(const Packet4f& a) {
+ return _mm_cvttps_epi32(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet4i, Packet4f>(const Packet4i& a) {
+ return _mm_cvtepi32_ps(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet2d, Packet4f>(const Packet2d& a, const Packet2d& b) {
+ return _mm_shuffle_ps(_mm_cvtpd_ps(a), _mm_cvtpd_ps(b), (1 << 2) | (1 << 6));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pcast<Packet4f, Packet2d>(const Packet4f& a) {
+ // Simply discard the second half of the input
+ return _mm_cvtps_pd(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i,Packet4f>(const Packet4f& a) {
+ return _mm_castps_si128(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f preinterpret<Packet4f,Packet4i>(const Packet4i& a) {
+ return _mm_castsi128_ps(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d preinterpret<Packet2d,Packet4i>(const Packet4i& a) {
+ return _mm_castsi128_pd(a);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i preinterpret<Packet4i,Packet2d>(const Packet2d& a) {
+ return _mm_castpd_si128(a);
+}
+
+// Disable the following code since it's broken on too many platforms / compilers.
+//#elif defined(EIGEN_VECTORIZE_SSE) && (!EIGEN_ARCH_x86_64) && (!EIGEN_COMP_MSVC)
+#if 0
+
+template <>
+struct type_casting_traits<Eigen::half, float> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet4f pcast<Packet4h, Packet4f>(const Packet4h& a) {
+ __int64_t a64 = _mm_cvtm64_si64(a.x);
+ Eigen::half h = raw_uint16_to_half(static_cast<unsigned short>(a64));
+ float f1 = static_cast<float>(h);
+ h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 16));
+ float f2 = static_cast<float>(h);
+ h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 32));
+ float f3 = static_cast<float>(h);
+ h = raw_uint16_to_half(static_cast<unsigned short>(a64 >> 48));
+ float f4 = static_cast<float>(h);
+ return _mm_set_ps(f4, f3, f2, f1);
+}
+
+template <>
+struct type_casting_traits<float, Eigen::half> {
+ enum {
+ VectorizedCast = 1,
+ SrcCoeffRatio = 1,
+ TgtCoeffRatio = 1
+ };
+};
+
+template<> EIGEN_STRONG_INLINE Packet4h pcast<Packet4f, Packet4h>(const Packet4f& a) {
+ EIGEN_ALIGN16 float aux[4];
+ pstore(aux, a);
+ Eigen::half h0(aux[0]);
+ Eigen::half h1(aux[1]);
+ Eigen::half h2(aux[2]);
+ Eigen::half h3(aux[3]);
+
+ Packet4h result;
+ result.x = _mm_set_pi16(h3.x, h2.x, h1.x, h0.x);
+ return result;
+}
+
+#endif
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TYPE_CASTING_SSE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SVE/MathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SVE/MathFunctions.h
new file mode 100644
index 000000000..b139ea2e4
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SVE/MathFunctions.h
@@ -0,0 +1,44 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2020, Arm Limited and Contributors
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATH_FUNCTIONS_SVE_H
+#define EIGEN_MATH_FUNCTIONS_SVE_H
+
+namespace Eigen {
+namespace internal {
+
+template <>
+EIGEN_STRONG_INLINE EIGEN_UNUSED PacketXf pexp<PacketXf>(const PacketXf& x) {
+ return pexp_float(x);
+}
+
+template <>
+EIGEN_STRONG_INLINE EIGEN_UNUSED PacketXf plog<PacketXf>(const PacketXf& x) {
+ return plog_float(x);
+}
+
+template <>
+EIGEN_STRONG_INLINE EIGEN_UNUSED PacketXf psin<PacketXf>(const PacketXf& x) {
+ return psin_float(x);
+}
+
+template <>
+EIGEN_STRONG_INLINE EIGEN_UNUSED PacketXf pcos<PacketXf>(const PacketXf& x) {
+ return pcos_float(x);
+}
+
+// Hyperbolic Tangent function.
+template <>
+EIGEN_STRONG_INLINE EIGEN_UNUSED PacketXf ptanh<PacketXf>(const PacketXf& x) {
+ return internal::generic_fast_tanh_float(x);
+}
+} // end namespace internal
+} // end namespace Eigen
+
+#endif // EIGEN_MATH_FUNCTIONS_SVE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SVE/PacketMath.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SVE/PacketMath.h
new file mode 100644
index 000000000..9060b372f
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SVE/PacketMath.h
@@ -0,0 +1,752 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2020, Arm Limited and Contributors
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PACKET_MATH_SVE_H
+#define EIGEN_PACKET_MATH_SVE_H
+
+namespace Eigen
+{
+namespace internal
+{
+#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
+#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
+#endif
+
+#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#endif
+
+#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32
+
+template <typename Scalar, int SVEVectorLength>
+struct sve_packet_size_selector {
+ enum { size = SVEVectorLength / (sizeof(Scalar) * CHAR_BIT) };
+};
+
+/********************************* int32 **************************************/
+typedef svint32_t PacketXi __attribute__((arm_sve_vector_bits(EIGEN_ARM64_SVE_VL)));
+
+template <>
+struct packet_traits<numext::int32_t> : default_packet_traits {
+ typedef PacketXi type;
+ typedef PacketXi half; // Half not implemented yet
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = sve_packet_size_selector<numext::int32_t, EIGEN_ARM64_SVE_VL>::size,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0,
+ HasReduxp = 0 // Not implemented in SVE
+ };
+};
+
+template <>
+struct unpacket_traits<PacketXi> {
+ typedef numext::int32_t type;
+ typedef PacketXi half; // Half not yet implemented
+ enum {
+ size = sve_packet_size_selector<numext::int32_t, EIGEN_ARM64_SVE_VL>::size,
+ alignment = Aligned64,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+
+template <>
+EIGEN_STRONG_INLINE void prefetch<numext::int32_t>(const numext::int32_t* addr)
+{
+ svprfw(svptrue_b32(), addr, SV_PLDL1KEEP);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pset1<PacketXi>(const numext::int32_t& from)
+{
+ return svdup_n_s32(from);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi plset<PacketXi>(const numext::int32_t& a)
+{
+ numext::int32_t c[packet_traits<numext::int32_t>::size];
+ for (int i = 0; i < packet_traits<numext::int32_t>::size; i++) c[i] = i;
+ return svadd_s32_z(svptrue_b32(), pset1<PacketXi>(a), svld1_s32(svptrue_b32(), c));
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi padd<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svadd_s32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi psub<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svsub_s32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pnegate(const PacketXi& a)
+{
+ return svneg_s32_z(svptrue_b32(), a);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pconj(const PacketXi& a)
+{
+ return a;
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pmul<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svmul_s32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pdiv<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svdiv_s32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pmadd(const PacketXi& a, const PacketXi& b, const PacketXi& c)
+{
+ return svmla_s32_z(svptrue_b32(), c, a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pmin<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svmin_s32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pmax<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svmax_s32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pcmp_le<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svdup_n_s32_z(svcmplt_s32(svptrue_b32(), a, b), 0xffffffffu);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pcmp_lt<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svdup_n_s32_z(svcmplt_s32(svptrue_b32(), a, b), 0xffffffffu);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pcmp_eq<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svdup_n_s32_z(svcmpeq_s32(svptrue_b32(), a, b), 0xffffffffu);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi ptrue<PacketXi>(const PacketXi& /*a*/)
+{
+ return svdup_n_s32_z(svptrue_b32(), 0xffffffffu);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pzero<PacketXi>(const PacketXi& /*a*/)
+{
+ return svdup_n_s32_z(svptrue_b32(), 0);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pand<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svand_s32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi por<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svorr_s32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pxor<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return sveor_s32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pandnot<PacketXi>(const PacketXi& a, const PacketXi& b)
+{
+ return svbic_s32_z(svptrue_b32(), a, b);
+}
+
+template <int N>
+EIGEN_STRONG_INLINE PacketXi parithmetic_shift_right(PacketXi a)
+{
+ return svasrd_n_s32_z(svptrue_b32(), a, N);
+}
+
+template <int N>
+EIGEN_STRONG_INLINE PacketXi plogical_shift_right(PacketXi a)
+{
+ return svreinterpret_s32_u32(svlsr_u32_z(svptrue_b32(), svreinterpret_u32_s32(a), svdup_n_u32_z(svptrue_b32(), N)));
+}
+
+template <int N>
+EIGEN_STRONG_INLINE PacketXi plogical_shift_left(PacketXi a)
+{
+ return svlsl_s32_z(svptrue_b32(), a, svdup_n_u32_z(svptrue_b32(), N));
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pload<PacketXi>(const numext::int32_t* from)
+{
+ EIGEN_DEBUG_ALIGNED_LOAD return svld1_s32(svptrue_b32(), from);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi ploadu<PacketXi>(const numext::int32_t* from)
+{
+ EIGEN_DEBUG_UNALIGNED_LOAD return svld1_s32(svptrue_b32(), from);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi ploaddup<PacketXi>(const numext::int32_t* from)
+{
+ svuint32_t indices = svindex_u32(0, 1); // index {base=0, base+step=1, base+step*2, ...}
+ indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a1, a1, a2, a2, ...}
+ return svld1_gather_u32index_s32(svptrue_b32(), from, indices);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi ploadquad<PacketXi>(const numext::int32_t* from)
+{
+ svuint32_t indices = svindex_u32(0, 1); // index {base=0, base+step=1, base+step*2, ...}
+ indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a1, a1, a2, a2, ...}
+ indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a0, a0, a1, a1, a1, a1, ...}
+ return svld1_gather_u32index_s32(svptrue_b32(), from, indices);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstore<numext::int32_t>(numext::int32_t* to, const PacketXi& from)
+{
+ EIGEN_DEBUG_ALIGNED_STORE svst1_s32(svptrue_b32(), to, from);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstoreu<numext::int32_t>(numext::int32_t* to, const PacketXi& from)
+{
+ EIGEN_DEBUG_UNALIGNED_STORE svst1_s32(svptrue_b32(), to, from);
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline PacketXi pgather<numext::int32_t, PacketXi>(const numext::int32_t* from, Index stride)
+{
+ // Indice format: {base=0, base+stride, base+stride*2, base+stride*3, ...}
+ svint32_t indices = svindex_s32(0, stride);
+ return svld1_gather_s32index_s32(svptrue_b32(), from, indices);
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline void pscatter<numext::int32_t, PacketXi>(numext::int32_t* to, const PacketXi& from, Index stride)
+{
+ // Indice format: {base=0, base+stride, base+stride*2, base+stride*3, ...}
+ svint32_t indices = svindex_s32(0, stride);
+ svst1_scatter_s32index_s32(svptrue_b32(), to, indices, from);
+}
+
+template <>
+EIGEN_STRONG_INLINE numext::int32_t pfirst<PacketXi>(const PacketXi& a)
+{
+ // svlasta returns the first element if all predicate bits are 0
+ return svlasta_s32(svpfalse_b(), a);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi preverse(const PacketXi& a)
+{
+ return svrev_s32(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pabs(const PacketXi& a)
+{
+ return svabs_s32_z(svptrue_b32(), a);
+}
+
+template <>
+EIGEN_STRONG_INLINE numext::int32_t predux<PacketXi>(const PacketXi& a)
+{
+ return static_cast<numext::int32_t>(svaddv_s32(svptrue_b32(), a));
+}
+
+template <>
+EIGEN_STRONG_INLINE numext::int32_t predux_mul<PacketXi>(const PacketXi& a)
+{
+ EIGEN_STATIC_ASSERT((EIGEN_ARM64_SVE_VL % 128 == 0),
+ EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT);
+
+ // Multiply the vector by its reverse
+ svint32_t prod = svmul_s32_z(svptrue_b32(), a, svrev_s32(a));
+ svint32_t half_prod;
+
+ // Extract the high half of the vector. Depending on the VL more reductions need to be done
+ if (EIGEN_ARM64_SVE_VL >= 2048) {
+ half_prod = svtbl_s32(prod, svindex_u32(32, 1));
+ prod = svmul_s32_z(svptrue_b32(), prod, half_prod);
+ }
+ if (EIGEN_ARM64_SVE_VL >= 1024) {
+ half_prod = svtbl_s32(prod, svindex_u32(16, 1));
+ prod = svmul_s32_z(svptrue_b32(), prod, half_prod);
+ }
+ if (EIGEN_ARM64_SVE_VL >= 512) {
+ half_prod = svtbl_s32(prod, svindex_u32(8, 1));
+ prod = svmul_s32_z(svptrue_b32(), prod, half_prod);
+ }
+ if (EIGEN_ARM64_SVE_VL >= 256) {
+ half_prod = svtbl_s32(prod, svindex_u32(4, 1));
+ prod = svmul_s32_z(svptrue_b32(), prod, half_prod);
+ }
+ // Last reduction
+ half_prod = svtbl_s32(prod, svindex_u32(2, 1));
+ prod = svmul_s32_z(svptrue_b32(), prod, half_prod);
+
+ // The reduction is done to the first element.
+ return pfirst<PacketXi>(prod);
+}
+
+template <>
+EIGEN_STRONG_INLINE numext::int32_t predux_min<PacketXi>(const PacketXi& a)
+{
+ return svminv_s32(svptrue_b32(), a);
+}
+
+template <>
+EIGEN_STRONG_INLINE numext::int32_t predux_max<PacketXi>(const PacketXi& a)
+{
+ return svmaxv_s32(svptrue_b32(), a);
+}
+
+template <int N>
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<PacketXi, N>& kernel) {
+ int buffer[packet_traits<numext::int32_t>::size * N] = {0};
+ int i = 0;
+
+ PacketXi stride_index = svindex_s32(0, N);
+
+ for (i = 0; i < N; i++) {
+ svst1_scatter_s32index_s32(svptrue_b32(), buffer + i, stride_index, kernel.packet[i]);
+ }
+ for (i = 0; i < N; i++) {
+ kernel.packet[i] = svld1_s32(svptrue_b32(), buffer + i * packet_traits<numext::int32_t>::size);
+ }
+}
+
+/********************************* float32 ************************************/
+
+typedef svfloat32_t PacketXf __attribute__((arm_sve_vector_bits(EIGEN_ARM64_SVE_VL)));
+
+template <>
+struct packet_traits<float> : default_packet_traits {
+ typedef PacketXf type;
+ typedef PacketXf half;
+
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = sve_packet_size_selector<float, EIGEN_ARM64_SVE_VL>::size,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasShift = 1,
+ HasMul = 1,
+ HasNegate = 1,
+ HasAbs = 1,
+ HasArg = 0,
+ HasAbs2 = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasConj = 1,
+ HasSetLinear = 0,
+ HasBlend = 0,
+ HasReduxp = 0, // Not implemented in SVE
+
+ HasDiv = 1,
+ HasFloor = 1,
+
+ HasSin = EIGEN_FAST_MATH,
+ HasCos = EIGEN_FAST_MATH,
+ HasLog = 1,
+ HasExp = 1,
+ HasSqrt = 0,
+ HasTanh = EIGEN_FAST_MATH,
+ HasErf = EIGEN_FAST_MATH
+ };
+};
+
+template <>
+struct unpacket_traits<PacketXf> {
+ typedef float type;
+ typedef PacketXf half; // Half not yet implemented
+ typedef PacketXi integer_packet;
+
+ enum {
+ size = sve_packet_size_selector<float, EIGEN_ARM64_SVE_VL>::size,
+ alignment = Aligned64,
+ vectorizable = true,
+ masked_load_available = false,
+ masked_store_available = false
+ };
+};
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pset1<PacketXf>(const float& from)
+{
+ return svdup_n_f32(from);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pset1frombits<PacketXf>(numext::uint32_t from)
+{
+ return svreinterpret_f32_u32(svdup_n_u32_z(svptrue_b32(), from));
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf plset<PacketXf>(const float& a)
+{
+ float c[packet_traits<float>::size];
+ for (int i = 0; i < packet_traits<float>::size; i++) c[i] = i;
+ return svadd_f32_z(svptrue_b32(), pset1<PacketXf>(a), svld1_f32(svptrue_b32(), c));
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf padd<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svadd_f32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf psub<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svsub_f32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pnegate(const PacketXf& a)
+{
+ return svneg_f32_z(svptrue_b32(), a);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pconj(const PacketXf& a)
+{
+ return a;
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pmul<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svmul_f32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pdiv<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svdiv_f32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pmadd(const PacketXf& a, const PacketXf& b, const PacketXf& c)
+{
+ return svmla_f32_z(svptrue_b32(), c, a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pmin<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svmin_f32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pmin<PropagateNaN, PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return pmin<PacketXf>(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pmin<PropagateNumbers, PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svminnm_f32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pmax<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svmax_f32_z(svptrue_b32(), a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pmax<PropagateNaN, PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return pmax<PacketXf>(a, b);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pmax<PropagateNumbers, PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svmaxnm_f32_z(svptrue_b32(), a, b);
+}
+
+// Float comparisons in SVE return svbool (predicate). Use svdup to set active
+// lanes to 1 (0xffffffffu) and inactive lanes to 0.
+template <>
+EIGEN_STRONG_INLINE PacketXf pcmp_le<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svreinterpret_f32_u32(svdup_n_u32_z(svcmplt_f32(svptrue_b32(), a, b), 0xffffffffu));
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pcmp_lt<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svreinterpret_f32_u32(svdup_n_u32_z(svcmplt_f32(svptrue_b32(), a, b), 0xffffffffu));
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pcmp_eq<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svreinterpret_f32_u32(svdup_n_u32_z(svcmpeq_f32(svptrue_b32(), a, b), 0xffffffffu));
+}
+
+// Do a predicate inverse (svnot_b_z) on the predicate resulted from the
+// greater/equal comparison (svcmpge_f32). Then fill a float vector with the
+// active elements.
+template <>
+EIGEN_STRONG_INLINE PacketXf pcmp_lt_or_nan<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svreinterpret_f32_u32(svdup_n_u32_z(svnot_b_z(svptrue_b32(), svcmpge_f32(svptrue_b32(), a, b)), 0xffffffffu));
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pfloor<PacketXf>(const PacketXf& a)
+{
+ return svrintm_f32_z(svptrue_b32(), a);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf ptrue<PacketXf>(const PacketXf& /*a*/)
+{
+ return svreinterpret_f32_u32(svdup_n_u32_z(svptrue_b32(), 0xffffffffu));
+}
+
+// Logical Operations are not supported for float, so reinterpret casts
+template <>
+EIGEN_STRONG_INLINE PacketXf pand<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svreinterpret_f32_u32(svand_u32_z(svptrue_b32(), svreinterpret_u32_f32(a), svreinterpret_u32_f32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf por<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svreinterpret_f32_u32(svorr_u32_z(svptrue_b32(), svreinterpret_u32_f32(a), svreinterpret_u32_f32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pxor<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svreinterpret_f32_u32(sveor_u32_z(svptrue_b32(), svreinterpret_u32_f32(a), svreinterpret_u32_f32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pandnot<PacketXf>(const PacketXf& a, const PacketXf& b)
+{
+ return svreinterpret_f32_u32(svbic_u32_z(svptrue_b32(), svreinterpret_u32_f32(a), svreinterpret_u32_f32(b)));
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pload<PacketXf>(const float* from)
+{
+ EIGEN_DEBUG_ALIGNED_LOAD return svld1_f32(svptrue_b32(), from);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf ploadu<PacketXf>(const float* from)
+{
+ EIGEN_DEBUG_UNALIGNED_LOAD return svld1_f32(svptrue_b32(), from);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf ploaddup<PacketXf>(const float* from)
+{
+ svuint32_t indices = svindex_u32(0, 1); // index {base=0, base+step=1, base+step*2, ...}
+ indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a1, a1, a2, a2, ...}
+ return svld1_gather_u32index_f32(svptrue_b32(), from, indices);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf ploadquad<PacketXf>(const float* from)
+{
+ svuint32_t indices = svindex_u32(0, 1); // index {base=0, base+step=1, base+step*2, ...}
+ indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a1, a1, a2, a2, ...}
+ indices = svzip1_u32(indices, indices); // index in the format {a0, a0, a0, a0, a1, a1, a1, a1, ...}
+ return svld1_gather_u32index_f32(svptrue_b32(), from, indices);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstore<float>(float* to, const PacketXf& from)
+{
+ EIGEN_DEBUG_ALIGNED_STORE svst1_f32(svptrue_b32(), to, from);
+}
+
+template <>
+EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const PacketXf& from)
+{
+ EIGEN_DEBUG_UNALIGNED_STORE svst1_f32(svptrue_b32(), to, from);
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline PacketXf pgather<float, PacketXf>(const float* from, Index stride)
+{
+ // Indice format: {base=0, base+stride, base+stride*2, base+stride*3, ...}
+ svint32_t indices = svindex_s32(0, stride);
+ return svld1_gather_s32index_f32(svptrue_b32(), from, indices);
+}
+
+template <>
+EIGEN_DEVICE_FUNC inline void pscatter<float, PacketXf>(float* to, const PacketXf& from, Index stride)
+{
+ // Indice format: {base=0, base+stride, base+stride*2, base+stride*3, ...}
+ svint32_t indices = svindex_s32(0, stride);
+ svst1_scatter_s32index_f32(svptrue_b32(), to, indices, from);
+}
+
+template <>
+EIGEN_STRONG_INLINE float pfirst<PacketXf>(const PacketXf& a)
+{
+ // svlasta returns the first element if all predicate bits are 0
+ return svlasta_f32(svpfalse_b(), a);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf preverse(const PacketXf& a)
+{
+ return svrev_f32(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pabs(const PacketXf& a)
+{
+ return svabs_f32_z(svptrue_b32(), a);
+}
+
+// TODO(tellenbach): Should this go into MathFunctions.h? If so, change for
+// all vector extensions and the generic version.
+template <>
+EIGEN_STRONG_INLINE PacketXf pfrexp<PacketXf>(const PacketXf& a, PacketXf& exponent)
+{
+ return pfrexp_generic(a, exponent);
+}
+
+template <>
+EIGEN_STRONG_INLINE float predux<PacketXf>(const PacketXf& a)
+{
+ return svaddv_f32(svptrue_b32(), a);
+}
+
+// Other reduction functions:
+// mul
+// Only works for SVE Vls multiple of 128
+template <>
+EIGEN_STRONG_INLINE float predux_mul<PacketXf>(const PacketXf& a)
+{
+ EIGEN_STATIC_ASSERT((EIGEN_ARM64_SVE_VL % 128 == 0),
+ EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT);
+ // Multiply the vector by its reverse
+ svfloat32_t prod = svmul_f32_z(svptrue_b32(), a, svrev_f32(a));
+ svfloat32_t half_prod;
+
+ // Extract the high half of the vector. Depending on the VL more reductions need to be done
+ if (EIGEN_ARM64_SVE_VL >= 2048) {
+ half_prod = svtbl_f32(prod, svindex_u32(32, 1));
+ prod = svmul_f32_z(svptrue_b32(), prod, half_prod);
+ }
+ if (EIGEN_ARM64_SVE_VL >= 1024) {
+ half_prod = svtbl_f32(prod, svindex_u32(16, 1));
+ prod = svmul_f32_z(svptrue_b32(), prod, half_prod);
+ }
+ if (EIGEN_ARM64_SVE_VL >= 512) {
+ half_prod = svtbl_f32(prod, svindex_u32(8, 1));
+ prod = svmul_f32_z(svptrue_b32(), prod, half_prod);
+ }
+ if (EIGEN_ARM64_SVE_VL >= 256) {
+ half_prod = svtbl_f32(prod, svindex_u32(4, 1));
+ prod = svmul_f32_z(svptrue_b32(), prod, half_prod);
+ }
+ // Last reduction
+ half_prod = svtbl_f32(prod, svindex_u32(2, 1));
+ prod = svmul_f32_z(svptrue_b32(), prod, half_prod);
+
+ // The reduction is done to the first element.
+ return pfirst<PacketXf>(prod);
+}
+
+template <>
+EIGEN_STRONG_INLINE float predux_min<PacketXf>(const PacketXf& a)
+{
+ return svminv_f32(svptrue_b32(), a);
+}
+
+template <>
+EIGEN_STRONG_INLINE float predux_max<PacketXf>(const PacketXf& a)
+{
+ return svmaxv_f32(svptrue_b32(), a);
+}
+
+template<int N>
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<PacketXf, N>& kernel)
+{
+ float buffer[packet_traits<float>::size * N] = {0};
+ int i = 0;
+
+ PacketXi stride_index = svindex_s32(0, N);
+
+ for (i = 0; i < N; i++) {
+ svst1_scatter_s32index_f32(svptrue_b32(), buffer + i, stride_index, kernel.packet[i]);
+ }
+
+ for (i = 0; i < N; i++) {
+ kernel.packet[i] = svld1_f32(svptrue_b32(), buffer + i * packet_traits<float>::size);
+ }
+}
+
+template<>
+EIGEN_STRONG_INLINE PacketXf pldexp<PacketXf>(const PacketXf& a, const PacketXf& exponent)
+{
+ return pldexp_generic(a, exponent);
+}
+
+} // namespace internal
+} // namespace Eigen
+
+#endif // EIGEN_PACKET_MATH_SVE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SVE/TypeCasting.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SVE/TypeCasting.h
new file mode 100644
index 000000000..7ba5d9cd1
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SVE/TypeCasting.h
@@ -0,0 +1,49 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2020, Arm Limited and Contributors
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TYPE_CASTING_SVE_H
+#define EIGEN_TYPE_CASTING_SVE_H
+
+namespace Eigen {
+namespace internal {
+
+template <>
+struct type_casting_traits<float, numext::int32_t> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+
+template <>
+struct type_casting_traits<numext::int32_t, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+
+template <>
+EIGEN_STRONG_INLINE PacketXf pcast<PacketXi, PacketXf>(const PacketXi& a) {
+ return svcvt_f32_s32_z(svptrue_b32(), a);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi pcast<PacketXf, PacketXi>(const PacketXf& a) {
+ return svcvt_s32_f32_z(svptrue_b32(), a);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXf preinterpret<PacketXf, PacketXi>(const PacketXi& a) {
+ return svreinterpret_f32_s32(a);
+}
+
+template <>
+EIGEN_STRONG_INLINE PacketXi preinterpret<PacketXi, PacketXf>(const PacketXf& a) {
+ return svreinterpret_s32_f32(a);
+}
+
+} // namespace internal
+} // namespace Eigen
+
+#endif // EIGEN_TYPE_CASTING_SVE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/InteropHeaders.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/InteropHeaders.h
new file mode 100644
index 000000000..10856ff5e
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/InteropHeaders.h
@@ -0,0 +1,232 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Mehdi Goli Codeplay Software Ltd.
+// Ralph Potter Codeplay Software Ltd.
+// Luke Iwanski Codeplay Software Ltd.
+// Contact: <eigen@codeplay.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/*****************************************************************
+ * InteropHeaders.h
+ *
+ * \brief:
+ * InteropHeaders
+ *
+ *****************************************************************/
+
+#ifndef EIGEN_INTEROP_HEADERS_SYCL_H
+#define EIGEN_INTEROP_HEADERS_SYCL_H
+
+namespace Eigen {
+
+#if !defined(EIGEN_DONT_VECTORIZE_SYCL)
+
+namespace internal {
+
+template <int has_blend, int lengths>
+struct sycl_packet_traits : default_packet_traits {
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = lengths,
+ HasHalfPacket = 0,
+ HasDiv = 1,
+ HasLog = 1,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasSin = 1,
+ HasCos = 1,
+ HasTan = 1,
+ HasASin = 1,
+ HasACos = 1,
+ HasATan = 1,
+ HasSinh = 1,
+ HasCosh = 1,
+ HasTanh = 1,
+ HasLGamma = 0,
+ HasDiGamma = 0,
+ HasZeta = 0,
+ HasPolygamma = 0,
+ HasErf = 0,
+ HasErfc = 0,
+ HasNdtri = 0,
+ HasIGamma = 0,
+ HasIGammac = 0,
+ HasBetaInc = 0,
+ HasBlend = has_blend,
+ // This flag is used to indicate whether packet comparison is supported.
+ // pcmp_eq, pcmp_lt and pcmp_le should be defined for it to be true.
+ HasCmp = 1,
+ HasMax = 1,
+ HasMin = 1,
+ HasMul = 1,
+ HasAdd = 1,
+ HasFloor = 1,
+ HasRound = 1,
+ HasRint = 1,
+ HasLog1p = 1,
+ HasExpm1 = 1,
+ HasCeil = 1,
+ };
+};
+
+#ifdef SYCL_DEVICE_ONLY
+#define SYCL_PACKET_TRAITS(packet_type, has_blend, unpacket_type, lengths) \
+ template <> \
+ struct packet_traits<unpacket_type> \
+ : sycl_packet_traits<has_blend, lengths> { \
+ typedef packet_type type; \
+ typedef packet_type half; \
+ };
+
+SYCL_PACKET_TRAITS(cl::sycl::cl_float4, 1, float, 4)
+SYCL_PACKET_TRAITS(cl::sycl::cl_float4, 1, const float, 4)
+SYCL_PACKET_TRAITS(cl::sycl::cl_double2, 0, double, 2)
+SYCL_PACKET_TRAITS(cl::sycl::cl_double2, 0, const double, 2)
+#undef SYCL_PACKET_TRAITS
+
+// Make sure this is only available when targeting a GPU: we don't want to
+// introduce conflicts between these packet_traits definitions and the ones
+// we'll use on the host side (SSE, AVX, ...)
+#define SYCL_ARITHMETIC(packet_type) \
+ template <> \
+ struct is_arithmetic<packet_type> { \
+ enum { value = true }; \
+ };
+SYCL_ARITHMETIC(cl::sycl::cl_float4)
+SYCL_ARITHMETIC(cl::sycl::cl_double2)
+#undef SYCL_ARITHMETIC
+
+#define SYCL_UNPACKET_TRAITS(packet_type, unpacket_type, lengths) \
+ template <> \
+ struct unpacket_traits<packet_type> { \
+ typedef unpacket_type type; \
+ enum { size = lengths, vectorizable = true, alignment = Aligned16 }; \
+ typedef packet_type half; \
+ };
+SYCL_UNPACKET_TRAITS(cl::sycl::cl_float4, float, 4)
+SYCL_UNPACKET_TRAITS(cl::sycl::cl_double2, double, 2)
+
+#undef SYCL_UNPACKET_TRAITS
+#endif
+
+} // end namespace internal
+
+#endif
+
+namespace TensorSycl {
+namespace internal {
+
+template <typename PacketReturnType, int PacketSize>
+struct PacketWrapper;
+// This function should never get called on the device
+#ifndef SYCL_DEVICE_ONLY
+template <typename PacketReturnType, int PacketSize>
+struct PacketWrapper {
+ typedef typename ::Eigen::internal::unpacket_traits<PacketReturnType>::type
+ Scalar;
+ template <typename Index>
+ EIGEN_DEVICE_FUNC static Scalar scalarize(Index, PacketReturnType &) {
+ eigen_assert(false && "THERE IS NO PACKETIZE VERSION FOR THE CHOSEN TYPE");
+ abort();
+ }
+ EIGEN_DEVICE_FUNC static PacketReturnType convert_to_packet_type(Scalar in,
+ Scalar) {
+ return ::Eigen::internal::template plset<PacketReturnType>(in);
+ }
+ EIGEN_DEVICE_FUNC static void set_packet(PacketReturnType, Scalar *) {
+ eigen_assert(false && "THERE IS NO PACKETIZE VERSION FOR THE CHOSEN TYPE");
+ abort();
+ }
+};
+
+#elif defined(SYCL_DEVICE_ONLY)
+template <typename PacketReturnType>
+struct PacketWrapper<PacketReturnType, 4> {
+ typedef typename ::Eigen::internal::unpacket_traits<PacketReturnType>::type
+ Scalar;
+ template <typename Index>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static Scalar scalarize(Index index, PacketReturnType &in) {
+ switch (index) {
+ case 0:
+ return in.x();
+ case 1:
+ return in.y();
+ case 2:
+ return in.z();
+ case 3:
+ return in.w();
+ default:
+ //INDEX MUST BE BETWEEN 0 and 3.There is no abort function in SYCL kernel. so we cannot use abort here.
+ // The code will never reach here
+ __builtin_unreachable();
+ }
+ __builtin_unreachable();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static PacketReturnType convert_to_packet_type(
+ Scalar in, Scalar other) {
+ return PacketReturnType(in, other, other, other);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void set_packet(PacketReturnType &lhs, Scalar *rhs) {
+ lhs = PacketReturnType(rhs[0], rhs[1], rhs[2], rhs[3]);
+ }
+};
+
+template <typename PacketReturnType>
+struct PacketWrapper<PacketReturnType, 1> {
+ typedef typename ::Eigen::internal::unpacket_traits<PacketReturnType>::type
+ Scalar;
+ template <typename Index>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static Scalar scalarize(Index, PacketReturnType &in) {
+ return in;
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static PacketReturnType convert_to_packet_type(Scalar in,
+ Scalar) {
+ return PacketReturnType(in);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void set_packet(PacketReturnType &lhs, Scalar *rhs) {
+ lhs = rhs[0];
+ }
+};
+
+template <typename PacketReturnType>
+struct PacketWrapper<PacketReturnType, 2> {
+ typedef typename ::Eigen::internal::unpacket_traits<PacketReturnType>::type
+ Scalar;
+ template <typename Index>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static Scalar scalarize(Index index, PacketReturnType &in) {
+ switch (index) {
+ case 0:
+ return in.x();
+ case 1:
+ return in.y();
+ default:
+ //INDEX MUST BE BETWEEN 0 and 1.There is no abort function in SYCL kernel. so we cannot use abort here.
+ // The code will never reach here
+ __builtin_unreachable();
+ }
+ __builtin_unreachable();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static PacketReturnType convert_to_packet_type(
+ Scalar in, Scalar other) {
+ return PacketReturnType(in, other);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void set_packet(PacketReturnType &lhs, Scalar *rhs) {
+ lhs = PacketReturnType(rhs[0], rhs[1]);
+ }
+};
+
+#endif
+
+} // end namespace internal
+} // end namespace TensorSycl
+} // end namespace Eigen
+
+#endif // EIGEN_INTEROP_HEADERS_SYCL_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/MathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/MathFunctions.h
new file mode 100644
index 000000000..2ab0f2a76
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/MathFunctions.h
@@ -0,0 +1,301 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Mehdi Goli Codeplay Software Ltd.
+// Ralph Potter Codeplay Software Ltd.
+// Luke Iwanski Codeplay Software Ltd.
+// Contact: <eigen@codeplay.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/*****************************************************************
+ * MathFunctions.h
+ *
+ * \brief:
+ * MathFunctions
+ *
+ *****************************************************************/
+
+#ifndef EIGEN_MATH_FUNCTIONS_SYCL_H
+#define EIGEN_MATH_FUNCTIONS_SYCL_H
+namespace Eigen {
+
+namespace internal {
+
+// Make sure this is only available when targeting a GPU: we don't want to
+// introduce conflicts between these packet_traits definitions and the ones
+// we'll use on the host side (SSE, AVX, ...)
+#if defined(SYCL_DEVICE_ONLY)
+#define SYCL_PLOG(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type plog<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::log(a); \
+ }
+
+SYCL_PLOG(cl::sycl::cl_float4)
+SYCL_PLOG(cl::sycl::cl_double2)
+#undef SYCL_PLOG
+
+#define SYCL_PLOG1P(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type plog1p<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::log1p(a); \
+ }
+
+SYCL_PLOG1P(cl::sycl::cl_float4)
+SYCL_PLOG1P(cl::sycl::cl_double2)
+#undef SYCL_PLOG1P
+
+#define SYCL_PLOG10(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type plog10<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::log10(a); \
+ }
+
+SYCL_PLOG10(cl::sycl::cl_float4)
+SYCL_PLOG10(cl::sycl::cl_double2)
+#undef SYCL_PLOG10
+
+#define SYCL_PEXP(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pexp<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::exp(a); \
+ }
+
+SYCL_PEXP(cl::sycl::cl_float4)
+SYCL_PEXP(cl::sycl::cl_float)
+SYCL_PEXP(cl::sycl::cl_double2)
+#undef SYCL_PEXP
+
+#define SYCL_PEXPM1(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pexpm1<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::expm1(a); \
+ }
+
+SYCL_PEXPM1(cl::sycl::cl_float4)
+SYCL_PEXPM1(cl::sycl::cl_double2)
+#undef SYCL_PEXPM1
+
+#define SYCL_PSQRT(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type psqrt<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::sqrt(a); \
+ }
+
+SYCL_PSQRT(cl::sycl::cl_float4)
+SYCL_PSQRT(cl::sycl::cl_double2)
+#undef SYCL_PSQRT
+
+#define SYCL_PRSQRT(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type prsqrt<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::rsqrt(a); \
+ }
+
+SYCL_PRSQRT(cl::sycl::cl_float4)
+SYCL_PRSQRT(cl::sycl::cl_double2)
+#undef SYCL_PRSQRT
+
+/** \internal \returns the hyperbolic sine of \a a (coeff-wise) */
+#define SYCL_PSIN(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type psin<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::sin(a); \
+ }
+
+SYCL_PSIN(cl::sycl::cl_float4)
+SYCL_PSIN(cl::sycl::cl_double2)
+#undef SYCL_PSIN
+
+/** \internal \returns the hyperbolic cosine of \a a (coeff-wise) */
+#define SYCL_PCOS(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pcos<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::cos(a); \
+ }
+
+SYCL_PCOS(cl::sycl::cl_float4)
+SYCL_PCOS(cl::sycl::cl_double2)
+#undef SYCL_PCOS
+
+/** \internal \returns the hyperbolic tan of \a a (coeff-wise) */
+#define SYCL_PTAN(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type ptan<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::tan(a); \
+ }
+
+SYCL_PTAN(cl::sycl::cl_float4)
+SYCL_PTAN(cl::sycl::cl_double2)
+#undef SYCL_PTAN
+
+/** \internal \returns the hyperbolic sine of \a a (coeff-wise) */
+#define SYCL_PASIN(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pasin<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::asin(a); \
+ }
+
+SYCL_PASIN(cl::sycl::cl_float4)
+SYCL_PASIN(cl::sycl::cl_double2)
+#undef SYCL_PASIN
+
+/** \internal \returns the hyperbolic cosine of \a a (coeff-wise) */
+#define SYCL_PACOS(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pacos<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::acos(a); \
+ }
+
+SYCL_PACOS(cl::sycl::cl_float4)
+SYCL_PACOS(cl::sycl::cl_double2)
+#undef SYCL_PACOS
+
+/** \internal \returns the hyperbolic tan of \a a (coeff-wise) */
+#define SYCL_PATAN(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type patan<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::atan(a); \
+ }
+
+SYCL_PATAN(cl::sycl::cl_float4)
+SYCL_PATAN(cl::sycl::cl_double2)
+#undef SYCL_PATAN
+
+/** \internal \returns the hyperbolic sine of \a a (coeff-wise) */
+#define SYCL_PSINH(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type psinh<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::sinh(a); \
+ }
+
+SYCL_PSINH(cl::sycl::cl_float4)
+SYCL_PSINH(cl::sycl::cl_double2)
+#undef SYCL_PSINH
+
+/** \internal \returns the hyperbolic cosine of \a a (coeff-wise) */
+#define SYCL_PCOSH(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pcosh<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::cosh(a); \
+ }
+
+SYCL_PCOSH(cl::sycl::cl_float4)
+SYCL_PCOSH(cl::sycl::cl_double2)
+#undef SYCL_PCOSH
+
+/** \internal \returns the hyperbolic tan of \a a (coeff-wise) */
+#define SYCL_PTANH(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type ptanh<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::tanh(a); \
+ }
+
+SYCL_PTANH(cl::sycl::cl_float4)
+SYCL_PTANH(cl::sycl::cl_double2)
+#undef SYCL_PTANH
+
+#define SYCL_PCEIL(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pceil<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::ceil(a); \
+ }
+
+SYCL_PCEIL(cl::sycl::cl_float4)
+SYCL_PCEIL(cl::sycl::cl_double2)
+#undef SYCL_PCEIL
+
+#define SYCL_PROUND(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pround<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::round(a); \
+ }
+
+SYCL_PROUND(cl::sycl::cl_float4)
+SYCL_PROUND(cl::sycl::cl_double2)
+#undef SYCL_PROUND
+
+#define SYCL_PRINT(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type print<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::rint(a); \
+ }
+
+SYCL_PRINT(cl::sycl::cl_float4)
+SYCL_PRINT(cl::sycl::cl_double2)
+#undef SYCL_PRINT
+
+#define SYCL_FLOOR(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pfloor<packet_type>( \
+ const packet_type& a) { \
+ return cl::sycl::floor(a); \
+ }
+
+SYCL_FLOOR(cl::sycl::cl_float4)
+SYCL_FLOOR(cl::sycl::cl_double2)
+#undef SYCL_FLOOR
+
+#define SYCL_PMIN(packet_type, expr) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pmin<packet_type>( \
+ const packet_type& a, const packet_type& b) { \
+ return expr; \
+ }
+
+SYCL_PMIN(cl::sycl::cl_float4, cl::sycl::fmin(a, b))
+SYCL_PMIN(cl::sycl::cl_double2, cl::sycl::fmin(a, b))
+#undef SYCL_PMIN
+
+#define SYCL_PMAX(packet_type, expr) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pmax<packet_type>( \
+ const packet_type& a, const packet_type& b) { \
+ return expr; \
+ }
+
+SYCL_PMAX(cl::sycl::cl_float4, cl::sycl::fmax(a, b))
+SYCL_PMAX(cl::sycl::cl_double2, cl::sycl::fmax(a, b))
+#undef SYCL_PMAX
+
+#define SYCL_PLDEXP(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pldexp( \
+ const packet_type& a, const packet_type& exponent) { \
+ return cl::sycl::ldexp( \
+ a, exponent.template convert<cl::sycl::cl_int, \
+ cl::sycl::rounding_mode::automatic>()); \
+ }
+
+SYCL_PLDEXP(cl::sycl::cl_float4)
+SYCL_PLDEXP(cl::sycl::cl_double2)
+#undef SYCL_PLDEXP
+
+#endif
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATH_FUNCTIONS_SYCL_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/PacketMath.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/PacketMath.h
new file mode 100644
index 000000000..87badc076
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/PacketMath.h
@@ -0,0 +1,670 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Mehdi Goli Codeplay Software Ltd.
+// Ralph Potter Codeplay Software Ltd.
+// Luke Iwanski Codeplay Software Ltd.
+// Contact: <eigen@codeplay.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/*****************************************************************
+ * PacketMath.h
+ *
+ * \brief:
+ * PacketMath
+ *
+ *****************************************************************/
+
+#ifndef EIGEN_PACKET_MATH_SYCL_H
+#define EIGEN_PACKET_MATH_SYCL_H
+#include <type_traits>
+namespace Eigen {
+
+namespace internal {
+#ifdef SYCL_DEVICE_ONLY
+
+#define SYCL_PLOADT_RO(address_space_target) \
+ template <typename packet_type, int Alignment> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type ploadt_ro( \
+ typename cl::sycl::multi_ptr< \
+ const typename unpacket_traits<packet_type>::type, \
+ cl::sycl::access::address_space::address_space_target>::pointer_t \
+ from) { \
+ typedef typename unpacket_traits<packet_type>::type scalar; \
+ typedef cl::sycl::multi_ptr< \
+ scalar, cl::sycl::access::address_space::address_space_target> \
+ multi_ptr; \
+ auto res = packet_type( \
+ static_cast<typename unpacket_traits<packet_type>::type>(0)); \
+ res.load(0, multi_ptr(const_cast<typename multi_ptr::pointer_t>(from))); \
+ return res; \
+ }
+
+SYCL_PLOADT_RO(global_space)
+SYCL_PLOADT_RO(local_space)
+#undef SYCL_PLOADT_RO
+#endif
+
+template <typename packet_type, int Alignment, typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type
+ploadt_ro(const Eigen::TensorSycl::internal::RangeAccess<
+ cl::sycl::access::mode::read_write, T>& from) {
+ return ploadt_ro<packet_type, Alignment>(from.get_pointer());
+}
+
+#ifdef SYCL_DEVICE_ONLY
+#define SYCL_PLOAD(address_space_target, Alignment, AlignedType) \
+ template <typename packet_type> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type pload##AlignedType( \
+ typename cl::sycl::multi_ptr< \
+ const typename unpacket_traits<packet_type>::type, \
+ cl::sycl::access::address_space::address_space_target>::pointer_t \
+ from) { \
+ return ploadt_ro<packet_type, Alignment>(from); \
+ }
+
+// global space
+SYCL_PLOAD(global_space, Unaligned, u)
+SYCL_PLOAD(global_space, Aligned, )
+// local space
+SYCL_PLOAD(local_space, Unaligned, u)
+SYCL_PLOAD(local_space, Aligned, )
+
+#undef SYCL_PLOAD
+#endif
+
+#define SYCL_PLOAD(Alignment, AlignedType) \
+ template <typename packet_type> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type pload##AlignedType( \
+ const Eigen::TensorSycl::internal::RangeAccess< \
+ cl::sycl::access::mode::read_write, \
+ typename unpacket_traits<packet_type>::type> \
+ from) { \
+ return ploadt_ro<packet_type, Alignment>(from); \
+ }
+SYCL_PLOAD(Unaligned, u)
+SYCL_PLOAD(Aligned, )
+#undef SYCL_PLOAD
+
+#ifdef SYCL_DEVICE_ONLY
+/** \internal \returns a packet version of \a *from.
+ * The pointer \a from must be aligned on a \a Alignment bytes boundary. */
+#define SYCL_PLOADT(address_space_target) \
+ template <typename packet_type, int Alignment> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type ploadt( \
+ typename cl::sycl::multi_ptr< \
+ const typename unpacket_traits<packet_type>::type, \
+ cl::sycl::access::address_space::address_space_target>::pointer_t \
+ from) { \
+ if (Alignment >= unpacket_traits<packet_type>::alignment) \
+ return pload<packet_type>(from); \
+ else \
+ return ploadu<packet_type>(from); \
+ }
+
+// global space
+SYCL_PLOADT(global_space)
+// local space
+SYCL_PLOADT(local_space)
+#undef SYCL_PLOADT
+#endif
+
+template <typename packet_type, int Alignment>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type
+ploadt(const Eigen::TensorSycl::internal::RangeAccess<
+ cl::sycl::access::mode::read_write,
+ typename unpacket_traits<packet_type>::type>& from) {
+ return ploadt<packet_type, Alignment>(from.get_pointer());
+}
+#ifdef SYCL_DEVICE_ONLY
+
+// private_space
+#define SYCL_PLOADT_RO_SPECIAL(packet_type, Alignment) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type \
+ ploadt_ro<packet_type, Alignment>( \
+ const typename unpacket_traits<packet_type>::type* from) { \
+ typedef typename unpacket_traits<packet_type>::type scalar; \
+ auto res = packet_type(static_cast<scalar>(0)); \
+ res.template load<cl::sycl::access::address_space::private_space>( \
+ 0, const_cast<scalar*>(from)); \
+ return res; \
+ }
+
+SYCL_PLOADT_RO_SPECIAL(cl::sycl::cl_float4, Aligned)
+SYCL_PLOADT_RO_SPECIAL(cl::sycl::cl_double2, Aligned)
+SYCL_PLOADT_RO_SPECIAL(cl::sycl::cl_float4, Unaligned)
+SYCL_PLOADT_RO_SPECIAL(cl::sycl::cl_double2, Unaligned)
+
+#define SYCL_PLOAD_SPECIAL(packet_type, alignment_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type pload##alignment_type( \
+ const typename unpacket_traits<packet_type>::type* from) { \
+ typedef typename unpacket_traits<packet_type>::type scalar; \
+ auto res = packet_type(static_cast<scalar>(0)); \
+ res.template load<cl::sycl::access::address_space::private_space>( \
+ 0, const_cast<scalar*>(from)); \
+ return res; \
+ }
+SYCL_PLOAD_SPECIAL(cl::sycl::cl_float4, )
+SYCL_PLOAD_SPECIAL(cl::sycl::cl_double2, )
+SYCL_PLOAD_SPECIAL(cl::sycl::cl_float4, u)
+SYCL_PLOAD_SPECIAL(cl::sycl::cl_double2, u)
+
+#undef SYCL_PLOAD_SPECIAL
+
+#define SYCL_PSTORE(scalar, packet_type, address_space_target, alignment) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstore##alignment( \
+ typename cl::sycl::multi_ptr< \
+ scalar, \
+ cl::sycl::access::address_space::address_space_target>::pointer_t \
+ to, \
+ const packet_type& from) { \
+ typedef cl::sycl::multi_ptr< \
+ scalar, cl::sycl::access::address_space::address_space_target> \
+ multi_ptr; \
+ from.store(0, multi_ptr(to)); \
+ }
+
+// global space
+SYCL_PSTORE(float, cl::sycl::cl_float4, global_space, )
+SYCL_PSTORE(float, cl::sycl::cl_float4, global_space, u)
+SYCL_PSTORE(double, cl::sycl::cl_double2, global_space, )
+SYCL_PSTORE(double, cl::sycl::cl_double2, global_space, u)
+SYCL_PSTORE(float, cl::sycl::cl_float4, local_space, )
+SYCL_PSTORE(float, cl::sycl::cl_float4, local_space, u)
+SYCL_PSTORE(double, cl::sycl::cl_double2, local_space, )
+SYCL_PSTORE(double, cl::sycl::cl_double2, local_space, u)
+
+SYCL_PSTORE(float, cl::sycl::cl_float4, private_space, )
+SYCL_PSTORE(float, cl::sycl::cl_float4, private_space, u)
+SYCL_PSTORE(double, cl::sycl::cl_double2, private_space, )
+SYCL_PSTORE(double, cl::sycl::cl_double2, private_space, u)
+#undef SYCL_PSTORE
+
+#define SYCL_PSTORE_T(address_space_target) \
+ template <typename scalar, typename packet_type, int Alignment> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstoret( \
+ typename cl::sycl::multi_ptr< \
+ scalar, \
+ cl::sycl::access::address_space::address_space_target>::pointer_t \
+ to, \
+ const packet_type& from) { \
+ if (Alignment) \
+ pstore(to, from); \
+ else \
+ pstoreu(to, from); \
+ }
+
+SYCL_PSTORE_T(global_space)
+
+SYCL_PSTORE_T(local_space)
+
+#undef SYCL_PSTORE_T
+
+#define SYCL_PSET1(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type pset1<packet_type>( \
+ const typename unpacket_traits<packet_type>::type& from) { \
+ return packet_type(from); \
+ }
+
+// global space
+SYCL_PSET1(cl::sycl::cl_float4)
+SYCL_PSET1(cl::sycl::cl_double2)
+
+#undef SYCL_PSET1
+
+template <typename packet_type>
+struct get_base_packet {
+ template <typename sycl_multi_pointer>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type
+ get_ploaddup(sycl_multi_pointer) {}
+
+ template <typename sycl_multi_pointer>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type
+ get_pgather(sycl_multi_pointer, Index) {}
+};
+
+template <>
+struct get_base_packet<cl::sycl::cl_float4> {
+ template <typename sycl_multi_pointer>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_float4 get_ploaddup(
+ sycl_multi_pointer from) {
+ return cl::sycl::cl_float4(from[0], from[0], from[1], from[1]);
+ }
+ template <typename sycl_multi_pointer>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_float4 get_pgather(
+ sycl_multi_pointer from, Index stride) {
+ return cl::sycl::cl_float4(from[0 * stride], from[1 * stride],
+ from[2 * stride], from[3 * stride]);
+ }
+
+ template <typename sycl_multi_pointer>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set_pscatter(
+ sycl_multi_pointer to, const cl::sycl::cl_float4& from, Index stride) {
+ auto tmp = stride;
+ to[0] = from.x();
+ to[tmp] = from.y();
+ to[tmp += stride] = from.z();
+ to[tmp += stride] = from.w();
+ }
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_float4 set_plset(
+ const float& a) {
+ return cl::sycl::cl_float4(static_cast<float>(a), static_cast<float>(a + 1),
+ static_cast<float>(a + 2),
+ static_cast<float>(a + 3));
+ }
+};
+
+template <>
+struct get_base_packet<cl::sycl::cl_double2> {
+ template <typename sycl_multi_pointer>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_double2
+ get_ploaddup(const sycl_multi_pointer from) {
+ return cl::sycl::cl_double2(from[0], from[0]);
+ }
+
+ template <typename sycl_multi_pointer, typename Index>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_double2 get_pgather(
+ const sycl_multi_pointer from, Index stride) {
+ return cl::sycl::cl_double2(from[0 * stride], from[1 * stride]);
+ }
+
+ template <typename sycl_multi_pointer>
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set_pscatter(
+ sycl_multi_pointer to, const cl::sycl::cl_double2& from, Index stride) {
+ to[0] = from.x();
+ to[stride] = from.y();
+ }
+
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE cl::sycl::cl_double2 set_plset(
+ const double& a) {
+ return cl::sycl::cl_double2(static_cast<double>(a),
+ static_cast<double>(a + 1));
+ }
+};
+
+#define SYCL_PLOAD_DUP(address_space_target) \
+ template <typename packet_type> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type ploaddup( \
+ typename cl::sycl::multi_ptr< \
+ const typename unpacket_traits<packet_type>::type, \
+ cl::sycl::access::address_space::address_space_target>::pointer_t \
+ from) { \
+ return get_base_packet<packet_type>::get_ploaddup(from); \
+ }
+
+// global space
+SYCL_PLOAD_DUP(global_space)
+// local_space
+SYCL_PLOAD_DUP(local_space)
+#undef SYCL_PLOAD_DUP
+
+#define SYCL_PLOAD_DUP_SPECILIZE(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type ploaddup<packet_type>( \
+ const typename unpacket_traits<packet_type>::type* from) { \
+ return get_base_packet<packet_type>::get_ploaddup(from); \
+ }
+
+SYCL_PLOAD_DUP_SPECILIZE(cl::sycl::cl_float4)
+SYCL_PLOAD_DUP_SPECILIZE(cl::sycl::cl_double2)
+
+#undef SYCL_PLOAD_DUP_SPECILIZE
+
+#define SYCL_PLSET(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type plset<packet_type>( \
+ const typename unpacket_traits<packet_type>::type& a) { \
+ return get_base_packet<packet_type>::set_plset(a); \
+ }
+
+SYCL_PLSET(cl::sycl::cl_float4)
+SYCL_PLSET(cl::sycl::cl_double2)
+
+#undef SYCL_PLSET
+
+#define SYCL_PGATHER(address_space_target) \
+ template <typename Scalar, typename packet_type> \
+ EIGEN_DEVICE_FUNC inline packet_type pgather( \
+ typename cl::sycl::multi_ptr< \
+ const typename unpacket_traits<packet_type>::type, \
+ cl::sycl::access::address_space::address_space_target>::pointer_t \
+ from, \
+ Index stride) { \
+ return get_base_packet<packet_type>::get_pgather(from, stride); \
+ }
+
+// global space
+SYCL_PGATHER(global_space)
+// local space
+SYCL_PGATHER(local_space)
+
+#undef SYCL_PGATHER
+
+#define SYCL_PGATHER_SPECILIZE(scalar, packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type \
+ pgather<scalar, packet_type>( \
+ const typename unpacket_traits<packet_type>::type* from, Index stride) { \
+ return get_base_packet<packet_type>::get_pgather(from, stride); \
+ }
+
+SYCL_PGATHER_SPECILIZE(float, cl::sycl::cl_float4)
+SYCL_PGATHER_SPECILIZE(double, cl::sycl::cl_double2)
+
+#undef SYCL_PGATHER_SPECILIZE
+
+#define SYCL_PSCATTER(address_space_target) \
+ template <typename Scalar, typename packet_type> \
+ EIGEN_DEVICE_FUNC inline void pscatter( \
+ typename cl::sycl::multi_ptr< \
+ typename unpacket_traits<packet_type>::type, \
+ cl::sycl::access::address_space::address_space_target>::pointer_t \
+ to, \
+ const packet_type& from, Index stride) { \
+ get_base_packet<packet_type>::set_pscatter(to, from, stride); \
+ }
+
+// global space
+SYCL_PSCATTER(global_space)
+// local space
+SYCL_PSCATTER(local_space)
+
+#undef SYCL_PSCATTER
+
+#define SYCL_PSCATTER_SPECILIZE(scalar, packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pscatter<scalar, packet_type>( \
+ typename unpacket_traits<packet_type>::type * to, \
+ const packet_type& from, Index stride) { \
+ get_base_packet<packet_type>::set_pscatter(to, from, stride); \
+ }
+
+SYCL_PSCATTER_SPECILIZE(float, cl::sycl::cl_float4)
+SYCL_PSCATTER_SPECILIZE(double, cl::sycl::cl_double2)
+
+#undef SYCL_PSCATTER_SPECILIZE
+
+#define SYCL_PMAD(packet_type) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE packet_type pmadd( \
+ const packet_type& a, const packet_type& b, const packet_type& c) { \
+ return cl::sycl::mad(a, b, c); \
+ }
+
+SYCL_PMAD(cl::sycl::cl_float4)
+SYCL_PMAD(cl::sycl::cl_double2)
+#undef SYCL_PMAD
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float pfirst<cl::sycl::cl_float4>(
+ const cl::sycl::cl_float4& a) {
+ return a.x();
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double pfirst<cl::sycl::cl_double2>(
+ const cl::sycl::cl_double2& a) {
+ return a.x();
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float predux<cl::sycl::cl_float4>(
+ const cl::sycl::cl_float4& a) {
+ return a.x() + a.y() + a.z() + a.w();
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double predux<cl::sycl::cl_double2>(
+ const cl::sycl::cl_double2& a) {
+ return a.x() + a.y();
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float predux_max<cl::sycl::cl_float4>(
+ const cl::sycl::cl_float4& a) {
+ return cl::sycl::fmax(cl::sycl::fmax(a.x(), a.y()),
+ cl::sycl::fmax(a.z(), a.w()));
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double predux_max<cl::sycl::cl_double2>(
+ const cl::sycl::cl_double2& a) {
+ return cl::sycl::fmax(a.x(), a.y());
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float predux_min<cl::sycl::cl_float4>(
+ const cl::sycl::cl_float4& a) {
+ return cl::sycl::fmin(cl::sycl::fmin(a.x(), a.y()),
+ cl::sycl::fmin(a.z(), a.w()));
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double predux_min<cl::sycl::cl_double2>(
+ const cl::sycl::cl_double2& a) {
+ return cl::sycl::fmin(a.x(), a.y());
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float predux_mul<cl::sycl::cl_float4>(
+ const cl::sycl::cl_float4& a) {
+ return a.x() * a.y() * a.z() * a.w();
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double predux_mul<cl::sycl::cl_double2>(
+ const cl::sycl::cl_double2& a) {
+ return a.x() * a.y();
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4
+pabs<cl::sycl::cl_float4>(const cl::sycl::cl_float4& a) {
+ return cl::sycl::cl_float4(cl::sycl::fabs(a.x()), cl::sycl::fabs(a.y()),
+ cl::sycl::fabs(a.z()), cl::sycl::fabs(a.w()));
+}
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_double2
+pabs<cl::sycl::cl_double2>(const cl::sycl::cl_double2& a) {
+ return cl::sycl::cl_double2(cl::sycl::fabs(a.x()), cl::sycl::fabs(a.y()));
+}
+
+template <typename Packet>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet sycl_pcmp_le(const Packet &a,
+ const Packet &b) {
+ return ((a <= b)
+ .template convert<typename unpacket_traits<Packet>::type,
+ cl::sycl::rounding_mode::automatic>());
+}
+
+template <typename Packet>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet sycl_pcmp_lt(const Packet &a,
+ const Packet &b) {
+ return ((a < b)
+ .template convert<typename unpacket_traits<Packet>::type,
+ cl::sycl::rounding_mode::automatic>());
+}
+
+template <typename Packet>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet sycl_pcmp_eq(const Packet &a,
+ const Packet &b) {
+ return ((a == b)
+ .template convert<typename unpacket_traits<Packet>::type,
+ cl::sycl::rounding_mode::automatic>());
+}
+
+#define SYCL_PCMP(OP, TYPE) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TYPE pcmp_##OP<TYPE>(const TYPE &a, \
+ const TYPE &b) { \
+ return sycl_pcmp_##OP<TYPE>(a, b); \
+ }
+
+SYCL_PCMP(le, cl::sycl::cl_float4)
+SYCL_PCMP(lt, cl::sycl::cl_float4)
+SYCL_PCMP(eq, cl::sycl::cl_float4)
+SYCL_PCMP(le, cl::sycl::cl_double2)
+SYCL_PCMP(lt, cl::sycl::cl_double2)
+SYCL_PCMP(eq, cl::sycl::cl_double2)
+#undef SYCL_PCMP
+
+template <typename T> struct convert_to_integer;
+
+template <> struct convert_to_integer<float> {
+ using type = std::int32_t;
+ using packet_type = cl::sycl::cl_int4;
+};
+template <> struct convert_to_integer<double> {
+ using type = std::int64_t;
+ using packet_type = cl::sycl::cl_long2;
+};
+
+template <typename PacketIn>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename convert_to_integer<
+ typename unpacket_traits<PacketIn>::type>::packet_type
+vector_as_int(const PacketIn &p) {
+ return (
+ p.template convert<typename convert_to_integer<
+ typename unpacket_traits<PacketIn>::type>::type,
+ cl::sycl::rounding_mode::automatic>());
+}
+
+template <typename packetOut, typename PacketIn>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packetOut
+convert_vector(const PacketIn &p) {
+ return (p.template convert<typename unpacket_traits<packetOut>::type,
+ cl::sycl::rounding_mode::automatic>());
+}
+
+#define SYCL_PAND(TYPE) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TYPE pand<TYPE>(const TYPE &a, \
+ const TYPE &b) { \
+ return convert_vector<TYPE>(vector_as_int(a) & vector_as_int(b)); \
+ }
+SYCL_PAND(cl::sycl::cl_float4)
+SYCL_PAND(cl::sycl::cl_double2)
+#undef SYCL_PAND
+
+#define SYCL_POR(TYPE) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TYPE por<TYPE>(const TYPE &a, \
+ const TYPE &b) { \
+ return convert_vector<TYPE>(vector_as_int(a) | vector_as_int(b)); \
+ }
+
+SYCL_POR(cl::sycl::cl_float4)
+SYCL_POR(cl::sycl::cl_double2)
+#undef SYCL_POR
+
+#define SYCL_PXOR(TYPE) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TYPE pxor<TYPE>(const TYPE &a, \
+ const TYPE &b) { \
+ return convert_vector<TYPE>(vector_as_int(a) ^ vector_as_int(b)); \
+ }
+
+SYCL_PXOR(cl::sycl::cl_float4)
+SYCL_PXOR(cl::sycl::cl_double2)
+#undef SYCL_PXOR
+
+#define SYCL_PANDNOT(TYPE) \
+ template <> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TYPE pandnot<TYPE>(const TYPE &a, \
+ const TYPE &b) { \
+ return convert_vector<TYPE>(vector_as_int(a) & (~vector_as_int(b))); \
+ }
+SYCL_PANDNOT(cl::sycl::cl_float4)
+SYCL_PANDNOT(cl::sycl::cl_double2)
+#undef SYCL_PANDNOT
+
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void ptranspose(
+ PacketBlock<cl::sycl::cl_float4, 4>& kernel) {
+ float tmp = kernel.packet[0].y();
+ kernel.packet[0].y() = kernel.packet[1].x();
+ kernel.packet[1].x() = tmp;
+
+ tmp = kernel.packet[0].z();
+ kernel.packet[0].z() = kernel.packet[2].x();
+ kernel.packet[2].x() = tmp;
+
+ tmp = kernel.packet[0].w();
+ kernel.packet[0].w() = kernel.packet[3].x();
+ kernel.packet[3].x() = tmp;
+
+ tmp = kernel.packet[1].z();
+ kernel.packet[1].z() = kernel.packet[2].y();
+ kernel.packet[2].y() = tmp;
+
+ tmp = kernel.packet[1].w();
+ kernel.packet[1].w() = kernel.packet[3].y();
+ kernel.packet[3].y() = tmp;
+
+ tmp = kernel.packet[2].w();
+ kernel.packet[2].w() = kernel.packet[3].z();
+ kernel.packet[3].z() = tmp;
+}
+
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void ptranspose(
+ PacketBlock<cl::sycl::cl_double2, 2>& kernel) {
+ double tmp = kernel.packet[0].y();
+ kernel.packet[0].y() = kernel.packet[1].x();
+ kernel.packet[1].x() = tmp;
+}
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4 pblend(
+ const Selector<unpacket_traits<cl::sycl::cl_float4>::size>& ifPacket,
+ const cl::sycl::cl_float4& thenPacket,
+ const cl::sycl::cl_float4& elsePacket) {
+ cl::sycl::cl_int4 condition(
+ ifPacket.select[0] ? 0 : -1, ifPacket.select[1] ? 0 : -1,
+ ifPacket.select[2] ? 0 : -1, ifPacket.select[3] ? 0 : -1);
+ return cl::sycl::select(thenPacket, elsePacket, condition);
+}
+
+template <>
+inline cl::sycl::cl_double2 pblend(
+ const Selector<unpacket_traits<cl::sycl::cl_double2>::size>& ifPacket,
+ const cl::sycl::cl_double2& thenPacket,
+ const cl::sycl::cl_double2& elsePacket) {
+ cl::sycl::cl_long2 condition(ifPacket.select[0] ? 0 : -1,
+ ifPacket.select[1] ? 0 : -1);
+ return cl::sycl::select(thenPacket, elsePacket, condition);
+}
+#endif // SYCL_DEVICE_ONLY
+
+#define SYCL_PSTORE(alignment) \
+ template <typename packet_type> \
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstore##alignment( \
+ const Eigen::TensorSycl::internal::RangeAccess< \
+ cl::sycl::access::mode::read_write, \
+ typename unpacket_traits<packet_type>::type>& to, \
+ const packet_type& from) { \
+ pstore##alignment(to.get_pointer(), from); \
+ }
+
+// global space
+SYCL_PSTORE()
+SYCL_PSTORE(u)
+
+#undef SYCL_PSTORE
+
+template <typename scalar, typename packet_type, int Alignment>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstoret(
+ Eigen::TensorSycl::internal::RangeAccess<
+ cl::sycl::access::mode::read_write,
+ typename unpacket_traits<packet_type>::type>
+ to,
+ const packet_type& from) {
+ pstoret<scalar, packet_type, Alignment>(to.get_pointer(), from);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PACKET_MATH_SYCL_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h
new file mode 100644
index 000000000..f81e59db5
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h
@@ -0,0 +1,694 @@
+/***************************************************************************
+ * Copyright (C) 2017 Codeplay Software Limited
+ * This Source Code Form is subject to the terms of the Mozilla
+ * Public License v. 2.0. If a copy of the MPL was not distributed
+ * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ *
+ * SyclMemoryModel.h
+ *
+ * Description:
+ * Interface for SYCL buffers to behave as a non-dereferenceable pointer
+ * Interface for Placeholder accessor to behave as a pointer on both host
+ * and device
+ *
+ * Authors:
+ *
+ * Ruyman Reyes Codeplay Software Ltd.
+ * Mehdi Goli Codeplay Software Ltd.
+ * Vanya Yaneva Codeplay Software Ltd.
+ *
+ **************************************************************************/
+
+#if defined(EIGEN_USE_SYCL) && \
+ !defined(EIGEN_CXX11_TENSOR_TENSOR_SYCL_STORAGE_MEMORY_H)
+#define EIGEN_CXX11_TENSOR_TENSOR_SYCL_STORAGE_MEMORY_H
+
+#include <CL/sycl.hpp>
+#ifdef EIGEN_EXCEPTIONS
+#include <stdexcept>
+#endif
+#include <cstddef>
+#include <queue>
+#include <set>
+#include <unordered_map>
+
+namespace Eigen {
+namespace TensorSycl {
+namespace internal {
+
+using sycl_acc_target = cl::sycl::access::target;
+using sycl_acc_mode = cl::sycl::access::mode;
+
+/**
+ * Default values for template arguments
+ */
+using buffer_data_type_t = uint8_t;
+const sycl_acc_target default_acc_target = sycl_acc_target::global_buffer;
+const sycl_acc_mode default_acc_mode = sycl_acc_mode::read_write;
+
+/**
+ * PointerMapper
+ * Associates fake pointers with buffers.
+ *
+ */
+class PointerMapper {
+ public:
+ using base_ptr_t = std::intptr_t;
+
+ /* Structure of a virtual pointer
+ *
+ * |================================================|
+ * | POINTER ADDRESS |
+ * |================================================|
+ */
+ struct virtual_pointer_t {
+ /* Type for the pointers
+ */
+ base_ptr_t m_contents;
+
+ /** Conversions from virtual_pointer_t to
+ * void * should just reinterpret_cast the integer number
+ */
+ operator void *() const { return reinterpret_cast<void *>(m_contents); }
+
+ /**
+ * Convert back to the integer number.
+ */
+ operator base_ptr_t() const { return m_contents; }
+
+ /**
+ * Add a certain value to the pointer to create a
+ * new pointer to that offset
+ */
+ virtual_pointer_t operator+(size_t off) { return m_contents + off; }
+
+ /* Numerical order for sorting pointers in containers. */
+ bool operator<(virtual_pointer_t rhs) const {
+ return (static_cast<base_ptr_t>(m_contents) <
+ static_cast<base_ptr_t>(rhs.m_contents));
+ }
+
+ bool operator>(virtual_pointer_t rhs) const {
+ return (static_cast<base_ptr_t>(m_contents) >
+ static_cast<base_ptr_t>(rhs.m_contents));
+ }
+
+ /**
+ * Numerical order for sorting pointers in containers
+ */
+ bool operator==(virtual_pointer_t rhs) const {
+ return (static_cast<base_ptr_t>(m_contents) ==
+ static_cast<base_ptr_t>(rhs.m_contents));
+ }
+
+ /**
+ * Simple forward to the equality overload.
+ */
+ bool operator!=(virtual_pointer_t rhs) const {
+ return !(this->operator==(rhs));
+ }
+
+ /**
+ * Converts a void * into a virtual pointer structure.
+ * Note that this will only work if the void * was
+ * already a virtual_pointer_t, but we have no way of
+ * checking
+ */
+ virtual_pointer_t(const void *ptr)
+ : m_contents(reinterpret_cast<base_ptr_t>(ptr)){};
+
+ /**
+ * Creates a virtual_pointer_t from the given integer
+ * number
+ */
+ virtual_pointer_t(base_ptr_t u) : m_contents(u){};
+ };
+
+ /* Definition of a null pointer
+ */
+ const virtual_pointer_t null_virtual_ptr = nullptr;
+
+ /**
+ * Whether if a pointer is null or not.
+ * A pointer is nullptr if the value is of null_virtual_ptr
+ */
+ static inline bool is_nullptr(virtual_pointer_t ptr) {
+ return (static_cast<void *>(ptr) == nullptr);
+ }
+
+ /* basic type for all buffers
+ */
+ using buffer_t = cl::sycl::buffer_mem;
+
+ /**
+ * Node that stores information about a device allocation.
+ * Nodes are sorted by size to organise a free list of nodes
+ * that can be recovered.
+ */
+ struct pMapNode_t {
+ buffer_t m_buffer;
+ size_t m_size;
+ bool m_free;
+
+ pMapNode_t(buffer_t b, size_t size, bool f)
+ : m_buffer{b}, m_size{size}, m_free{f} {
+ m_buffer.set_final_data(nullptr);
+ }
+
+ bool operator<=(const pMapNode_t &rhs) { return (m_size <= rhs.m_size); }
+ };
+
+ /** Storage of the pointer / buffer tree
+ */
+ using pointerMap_t = std::map<virtual_pointer_t, pMapNode_t>;
+
+ /**
+ * Obtain the insertion point in the pointer map for
+ * a pointer of the given size.
+ * \param requiredSize Size attemted to reclaim
+ */
+ typename pointerMap_t::iterator get_insertion_point(size_t requiredSize) {
+ typename pointerMap_t::iterator retVal;
+ bool reuse = false;
+ if (!m_freeList.empty()) {
+ // try to re-use an existing block
+ for (auto freeElem : m_freeList) {
+ if (freeElem->second.m_size >= requiredSize) {
+ retVal = freeElem;
+ reuse = true;
+ // Element is not going to be free anymore
+ m_freeList.erase(freeElem);
+ break;
+ }
+ }
+ }
+ if (!reuse) {
+ retVal = std::prev(m_pointerMap.end());
+ }
+ return retVal;
+ }
+
+ /**
+ * Returns an iterator to the node that stores the information
+ * of the given virtual pointer from the given pointer map structure.
+ * If pointer is not found, throws std::out_of_range.
+ * If the pointer map structure is empty, throws std::out_of_range
+ *
+ * \param pMap the pointerMap_t structure storing all the pointers
+ * \param virtual_pointer_ptr The virtual pointer to obtain the node of
+ * \throws std::out:of_range if the pointer is not found or pMap is empty
+ */
+ typename pointerMap_t::iterator get_node(const virtual_pointer_t ptr) {
+ if (this->count() == 0) {
+ m_pointerMap.clear();
+ EIGEN_THROW_X(std::out_of_range("There are no pointers allocated\n"));
+
+ }
+ if (is_nullptr(ptr)) {
+ m_pointerMap.clear();
+ EIGEN_THROW_X(std::out_of_range("Cannot access null pointer\n"));
+ }
+ // The previous element to the lower bound is the node that
+ // holds this memory address
+ auto node = m_pointerMap.lower_bound(ptr);
+ // If the value of the pointer is not the one of the node
+ // then we return the previous one
+ if (node == std::end(m_pointerMap)) {
+ --node;
+ } else if (node->first != ptr) {
+ if (node == std::begin(m_pointerMap)) {
+ m_pointerMap.clear();
+ EIGEN_THROW_X(
+ std::out_of_range("The pointer is not registered in the map\n"));
+
+ }
+ --node;
+ }
+
+ return node;
+ }
+
+ /* get_buffer.
+ * Returns a buffer from the map using the pointer address
+ */
+ template <typename buffer_data_type = buffer_data_type_t>
+ cl::sycl::buffer<buffer_data_type, 1> get_buffer(
+ const virtual_pointer_t ptr) {
+ using sycl_buffer_t = cl::sycl::buffer<buffer_data_type, 1>;
+
+ // get_node() returns a `buffer_mem`, so we need to cast it to a `buffer<>`.
+ // We can do this without the `buffer_mem` being a pointer, as we
+ // only declare member variables in the base class (`buffer_mem`) and not in
+ // the child class (`buffer<>).
+ auto node = get_node(ptr);
+ eigen_assert(node->first == ptr || node->first < ptr);
+ eigen_assert(ptr < static_cast<virtual_pointer_t>(node->second.m_size +
+ node->first));
+ return *(static_cast<sycl_buffer_t *>(&node->second.m_buffer));
+ }
+
+ /**
+ * @brief Returns an accessor to the buffer of the given virtual pointer
+ * @param accessMode
+ * @param accessTarget
+ * @param ptr The virtual pointer
+ */
+ template <sycl_acc_mode access_mode = default_acc_mode,
+ sycl_acc_target access_target = default_acc_target,
+ typename buffer_data_type = buffer_data_type_t>
+ cl::sycl::accessor<buffer_data_type, 1, access_mode, access_target>
+ get_access(const virtual_pointer_t ptr) {
+ auto buf = get_buffer<buffer_data_type>(ptr);
+ return buf.template get_access<access_mode, access_target>();
+ }
+
+ /**
+ * @brief Returns an accessor to the buffer of the given virtual pointer
+ * in the given command group scope
+ * @param accessMode
+ * @param accessTarget
+ * @param ptr The virtual pointer
+ * @param cgh Reference to the command group scope
+ */
+ template <sycl_acc_mode access_mode = default_acc_mode,
+ sycl_acc_target access_target = default_acc_target,
+ typename buffer_data_type = buffer_data_type_t>
+ cl::sycl::accessor<buffer_data_type, 1, access_mode, access_target>
+ get_access(const virtual_pointer_t ptr, cl::sycl::handler &cgh) {
+ auto buf = get_buffer<buffer_data_type>(ptr);
+ return buf.template get_access<access_mode, access_target>(cgh);
+ }
+
+ /*
+ * Returns the offset from the base address of this pointer.
+ */
+ inline std::ptrdiff_t get_offset(const virtual_pointer_t ptr) {
+ // The previous element to the lower bound is the node that
+ // holds this memory address
+ auto node = get_node(ptr);
+ auto start = node->first;
+ eigen_assert(start == ptr || start < ptr);
+ eigen_assert(ptr < start + node->second.m_size);
+ return (ptr - start);
+ }
+
+ /*
+ * Returns the number of elements by which the given pointer is offset from
+ * the base address.
+ */
+ template <typename buffer_data_type>
+ inline size_t get_element_offset(const virtual_pointer_t ptr) {
+ return get_offset(ptr) / sizeof(buffer_data_type);
+ }
+
+ /**
+ * Constructs the PointerMapper structure.
+ */
+ PointerMapper(base_ptr_t baseAddress = 4096)
+ : m_pointerMap{}, m_freeList{}, m_baseAddress{baseAddress} {
+ if (m_baseAddress == 0) {
+ EIGEN_THROW_X(std::invalid_argument("Base address cannot be zero\n"));
+ }
+ };
+
+ /**
+ * PointerMapper cannot be copied or moved
+ */
+ PointerMapper(const PointerMapper &) = delete;
+
+ /**
+ * Empty the pointer list
+ */
+ inline void clear() {
+ m_freeList.clear();
+ m_pointerMap.clear();
+ }
+
+ /* add_pointer.
+ * Adds an existing pointer to the map and returns the virtual pointer id.
+ */
+ inline virtual_pointer_t add_pointer(const buffer_t &b) {
+ return add_pointer_impl(b);
+ }
+
+ /* add_pointer.
+ * Adds a pointer to the map and returns the virtual pointer id.
+ */
+ inline virtual_pointer_t add_pointer(buffer_t &&b) {
+ return add_pointer_impl(b);
+ }
+
+ /**
+ * @brief Fuses the given node with the previous nodes in the
+ * pointer map if they are free
+ *
+ * @param node A reference to the free node to be fused
+ */
+ void fuse_forward(typename pointerMap_t::iterator &node) {
+ while (node != std::prev(m_pointerMap.end())) {
+ // if following node is free
+ // remove it and extend the current node with its size
+ auto fwd_node = std::next(node);
+ if (!fwd_node->second.m_free) {
+ break;
+ }
+ auto fwd_size = fwd_node->second.m_size;
+ m_freeList.erase(fwd_node);
+ m_pointerMap.erase(fwd_node);
+
+ node->second.m_size += fwd_size;
+ }
+ }
+
+ /**
+ * @brief Fuses the given node with the following nodes in the
+ * pointer map if they are free
+ *
+ * @param node A reference to the free node to be fused
+ */
+ void fuse_backward(typename pointerMap_t::iterator &node) {
+ while (node != m_pointerMap.begin()) {
+ // if previous node is free, extend it
+ // with the size of the current one
+ auto prev_node = std::prev(node);
+ if (!prev_node->second.m_free) {
+ break;
+ }
+ prev_node->second.m_size += node->second.m_size;
+
+ // remove the current node
+ m_freeList.erase(node);
+ m_pointerMap.erase(node);
+
+ // point to the previous node
+ node = prev_node;
+ }
+ }
+
+ /* remove_pointer.
+ * Removes the given pointer from the map.
+ * The pointer is allowed to be reused only if ReUse if true.
+ */
+ template <bool ReUse = true>
+ void remove_pointer(const virtual_pointer_t ptr) {
+ if (is_nullptr(ptr)) {
+ return;
+ }
+ auto node = this->get_node(ptr);
+
+ node->second.m_free = true;
+ m_freeList.emplace(node);
+
+ // Fuse the node
+ // with free nodes before and after it
+ fuse_forward(node);
+ fuse_backward(node);
+
+ // If after fusing the node is the last one
+ // simply remove it (since it is free)
+ if (node == std::prev(m_pointerMap.end())) {
+ m_freeList.erase(node);
+ m_pointerMap.erase(node);
+ }
+ }
+
+ /* count.
+ * Return the number of active pointers (i.e, pointers that
+ * have been malloc but not freed).
+ */
+ size_t count() const { return (m_pointerMap.size() - m_freeList.size()); }
+
+ private:
+ /* add_pointer_impl.
+ * Adds a pointer to the map and returns the virtual pointer id.
+ * BufferT is either a const buffer_t& or a buffer_t&&.
+ */
+ template <class BufferT>
+ virtual_pointer_t add_pointer_impl(BufferT b) {
+ virtual_pointer_t retVal = nullptr;
+ size_t bufSize = b.get_count();
+ pMapNode_t p{b, bufSize, false};
+ // If this is the first pointer:
+ if (m_pointerMap.empty()) {
+ virtual_pointer_t initialVal{m_baseAddress};
+ m_pointerMap.emplace(initialVal, p);
+ return initialVal;
+ }
+
+ auto lastElemIter = get_insertion_point(bufSize);
+ // We are recovering an existing free node
+ if (lastElemIter->second.m_free) {
+ lastElemIter->second.m_buffer = b;
+ lastElemIter->second.m_free = false;
+
+ // If the recovered node is bigger than the inserted one
+ // add a new free node with the remaining space
+ if (lastElemIter->second.m_size > bufSize) {
+ // create a new node with the remaining space
+ auto remainingSize = lastElemIter->second.m_size - bufSize;
+ pMapNode_t p2{b, remainingSize, true};
+
+ // update size of the current node
+ lastElemIter->second.m_size = bufSize;
+
+ // add the new free node
+ auto newFreePtr = lastElemIter->first + bufSize;
+ auto freeNode = m_pointerMap.emplace(newFreePtr, p2).first;
+ m_freeList.emplace(freeNode);
+ }
+
+ retVal = lastElemIter->first;
+ } else {
+ size_t lastSize = lastElemIter->second.m_size;
+ retVal = lastElemIter->first + lastSize;
+ m_pointerMap.emplace(retVal, p);
+ }
+ return retVal;
+ }
+
+ /**
+ * Compare two iterators to pointer map entries according to
+ * the size of the allocation on the device.
+ */
+ struct SortBySize {
+ bool operator()(typename pointerMap_t::iterator a,
+ typename pointerMap_t::iterator b) const {
+ return ((a->first < b->first) && (a->second <= b->second)) ||
+ ((a->first < b->first) && (b->second <= a->second));
+ }
+ };
+
+ /* Maps the pointer addresses to buffer and size pairs.
+ */
+ pointerMap_t m_pointerMap;
+
+ /* List of free nodes available for re-using
+ */
+ std::set<typename pointerMap_t::iterator, SortBySize> m_freeList;
+
+ /* Base address used when issuing the first virtual pointer, allows users
+ * to specify alignment. Cannot be zero. */
+ std::intptr_t m_baseAddress;
+};
+
+/* remove_pointer.
+ * Removes the given pointer from the map.
+ * The pointer is allowed to be reused only if ReUse if true.
+ */
+template <>
+inline void PointerMapper::remove_pointer<false>(const virtual_pointer_t ptr) {
+ if (is_nullptr(ptr)) {
+ return;
+ }
+ m_pointerMap.erase(this->get_node(ptr));
+}
+
+/**
+ * Malloc-like interface to the pointer-mapper.
+ * Given a size, creates a byte-typed buffer and returns a
+ * fake pointer to keep track of it.
+ * \param size Size in bytes of the desired allocation
+ * \throw cl::sycl::exception if error while creating the buffer
+ */
+inline void *SYCLmalloc(size_t size, PointerMapper &pMap) {
+ if (size == 0) {
+ return nullptr;
+ }
+ // Create a generic buffer of the given size
+ using buffer_t = cl::sycl::buffer<buffer_data_type_t, 1>;
+ auto thePointer = pMap.add_pointer(buffer_t(cl::sycl::range<1>{size}));
+ // Store the buffer on the global list
+ return static_cast<void *>(thePointer);
+}
+
+/**
+ * Free-like interface to the pointer mapper.
+ * Given a fake-pointer created with the virtual-pointer malloc,
+ * destroys the buffer and remove it from the list.
+ * If ReUse is false, the pointer is not added to the freeList,
+ * it should be false only for sub-buffers.
+ */
+template <bool ReUse = true, typename PointerMapper>
+inline void SYCLfree(void *ptr, PointerMapper &pMap) {
+ pMap.template remove_pointer<ReUse>(ptr);
+}
+
+/**
+ * Clear all the memory allocated by SYCL.
+ */
+template <typename PointerMapper>
+inline void SYCLfreeAll(PointerMapper &pMap) {
+ pMap.clear();
+}
+
+template <cl::sycl::access::mode AcMd, typename T>
+struct RangeAccess {
+ static const auto global_access = cl::sycl::access::target::global_buffer;
+ static const auto is_place_holder = cl::sycl::access::placeholder::true_t;
+ typedef T scalar_t;
+ typedef scalar_t &ref_t;
+ typedef typename cl::sycl::global_ptr<scalar_t>::pointer_t ptr_t;
+
+ // the accessor type does not necessarily the same as T
+ typedef cl::sycl::accessor<scalar_t, 1, AcMd, global_access, is_place_holder>
+ accessor;
+
+ typedef RangeAccess<AcMd, T> self_t;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE RangeAccess(accessor access,
+ size_t offset,
+ std::intptr_t virtual_ptr)
+ : access_(access), offset_(offset), virtual_ptr_(virtual_ptr) {}
+
+ RangeAccess(cl::sycl::buffer<scalar_t, 1> buff =
+ cl::sycl::buffer<scalar_t, 1>(cl::sycl::range<1>(1)))
+ : access_{accessor{buff}}, offset_(0), virtual_ptr_(-1) {}
+
+ // This should be only used for null constructor on the host side
+ RangeAccess(std::nullptr_t) : RangeAccess() {}
+ // This template parameter must be removed and scalar_t should be replaced
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptr_t get_pointer() const {
+ return (access_.get_pointer().get() + offset_);
+ }
+ template <typename Index>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t &operator+=(Index offset) {
+ offset_ += (offset);
+ return *this;
+ }
+ template <typename Index>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t operator+(Index offset) const {
+ return self_t(access_, offset_ + offset, virtual_ptr_);
+ }
+ template <typename Index>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t operator-(Index offset) const {
+ return self_t(access_, offset_ - offset, virtual_ptr_);
+ }
+ template <typename Index>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t &operator-=(Index offset) {
+ offset_ -= offset;
+ return *this;
+ }
+
+ // THIS IS FOR NULL COMPARISON ONLY
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend bool operator==(
+ const RangeAccess &lhs, std::nullptr_t) {
+ return ((lhs.virtual_ptr_ == -1));
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend bool operator!=(
+ const RangeAccess &lhs, std::nullptr_t i) {
+ return !(lhs == i);
+ }
+
+ // THIS IS FOR NULL COMPARISON ONLY
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend bool operator==(
+ std::nullptr_t, const RangeAccess &rhs) {
+ return ((rhs.virtual_ptr_ == -1));
+ }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend bool operator!=(
+ std::nullptr_t i, const RangeAccess &rhs) {
+ return !(i == rhs);
+ }
+ // Prefix operator (Increment and return value)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t &operator++() {
+ offset_++;
+ return (*this);
+ }
+
+ // Postfix operator (Return value and increment)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE self_t operator++(int i) {
+ EIGEN_UNUSED_VARIABLE(i);
+ self_t temp_iterator(*this);
+ offset_++;
+ return temp_iterator;
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t get_size() const {
+ return (access_.get_count() - offset_);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t get_offset() const {
+ return offset_;
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void set_offset(std::ptrdiff_t offset) {
+ offset_ = offset;
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ref_t operator*() const {
+ return *get_pointer();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ref_t operator*() {
+ return *get_pointer();
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptr_t operator->() = delete;
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ref_t operator[](int x) {
+ return *(get_pointer() + x);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ref_t operator[](int x) const {
+ return *(get_pointer() + x);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_t *get_virtual_pointer() const {
+ return reinterpret_cast<scalar_t *>(virtual_ptr_ +
+ (offset_ * sizeof(scalar_t)));
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit operator bool() const {
+ return (virtual_ptr_ != -1);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator RangeAccess<AcMd, const T>() {
+ return RangeAccess<AcMd, const T>(access_, offset_, virtual_ptr_);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ operator RangeAccess<AcMd, const T>() const {
+ return RangeAccess<AcMd, const T>(access_, offset_, virtual_ptr_);
+ }
+ // binding placeholder accessors to a command group handler for SYCL
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(
+ cl::sycl::handler &cgh) const {
+ cgh.require(access_);
+ }
+
+ private:
+ accessor access_;
+ size_t offset_;
+ std::intptr_t virtual_ptr_; // the location of the buffer in the map
+};
+
+template <cl::sycl::access::mode AcMd, typename T>
+struct RangeAccess<AcMd, const T> : RangeAccess<AcMd, T> {
+ typedef RangeAccess<AcMd, T> Base;
+ using Base::Base;
+};
+
+} // namespace internal
+} // namespace TensorSycl
+} // namespace Eigen
+
+#endif // EIGEN_CXX11_TENSOR_TENSOR_SYCL_STORAGE_MEMORY_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/TypeCasting.h b/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/TypeCasting.h
new file mode 100644
index 000000000..9208ab21d
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/SYCL/TypeCasting.h
@@ -0,0 +1,85 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Mehdi Goli Codeplay Software Ltd.
+// Ralph Potter Codeplay Software Ltd.
+// Luke Iwanski Codeplay Software Ltd.
+// Contact: <eigen@codeplay.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/*****************************************************************
+ * TypeCasting.h
+ *
+ * \brief:
+ * TypeCasting
+ *
+ *****************************************************************/
+
+#ifndef EIGEN_TYPE_CASTING_SYCL_H
+#define EIGEN_TYPE_CASTING_SYCL_H
+
+namespace Eigen {
+
+namespace internal {
+#ifdef SYCL_DEVICE_ONLY
+template <>
+struct type_casting_traits<float, int> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_int4
+pcast<cl::sycl::cl_float4, cl::sycl::cl_int4>(const cl::sycl::cl_float4& a) {
+ return a
+ .template convert<cl::sycl::cl_int, cl::sycl::rounding_mode::automatic>();
+}
+
+template <>
+struct type_casting_traits<int, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
+};
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4
+pcast<cl::sycl::cl_int4, cl::sycl::cl_float4>(const cl::sycl::cl_int4& a) {
+ return a.template convert<cl::sycl::cl_float,
+ cl::sycl::rounding_mode::automatic>();
+}
+
+template <>
+struct type_casting_traits<double, float> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
+};
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4
+pcast<cl::sycl::cl_double2, cl::sycl::cl_float4>(
+ const cl::sycl::cl_double2& a, const cl::sycl::cl_double2& b) {
+ auto a1 = a.template convert<cl::sycl::cl_float,
+ cl::sycl::rounding_mode::automatic>();
+ auto b1 = b.template convert<cl::sycl::cl_float,
+ cl::sycl::rounding_mode::automatic>();
+ return cl::sycl::float4(a1.x(), a1.y(), b1.x(), b1.y());
+}
+
+template <>
+struct type_casting_traits<float, double> {
+ enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
+};
+
+template <>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_double2
+pcast<cl::sycl::cl_float4, cl::sycl::cl_double2>(const cl::sycl::cl_float4& a) {
+ // Simply discard the second half of the input
+ return cl::sycl::cl_double2(a.x(), a.y());
+}
+
+#endif
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TYPE_CASTING_SYCL_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/Complex.h b/src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/Complex.h
new file mode 100644
index 000000000..0b9b33d99
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/Complex.h
@@ -0,0 +1,426 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2016 Konstantinos Margaritis <markos@freevec.org>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMPLEX32_ALTIVEC_H
+#define EIGEN_COMPLEX32_ALTIVEC_H
+
+namespace Eigen {
+
+namespace internal {
+
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
+static Packet4ui p4ui_CONJ_XOR = { 0x00000000, 0x80000000, 0x00000000, 0x80000000 }; //vec_mergeh((Packet4ui)p4i_ZERO, (Packet4ui)p4f_MZERO);
+#endif
+
+static Packet2ul p2ul_CONJ_XOR1 = (Packet2ul) vec_sld((Packet4ui) p2d_ZERO_, (Packet4ui) p2l_ZERO, 8);//{ 0x8000000000000000, 0x0000000000000000 };
+static Packet2ul p2ul_CONJ_XOR2 = (Packet2ul) vec_sld((Packet4ui) p2l_ZERO, (Packet4ui) p2d_ZERO_, 8);//{ 0x8000000000000000, 0x0000000000000000 };
+
+struct Packet1cd
+{
+ EIGEN_STRONG_INLINE Packet1cd() {}
+ EIGEN_STRONG_INLINE explicit Packet1cd(const Packet2d& a) : v(a) {}
+ Packet2d v;
+};
+
+struct Packet2cf
+{
+ EIGEN_STRONG_INLINE Packet2cf() {}
+ EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {}
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
+ union {
+ Packet4f v;
+ Packet1cd cd[2];
+ };
+#else
+ Packet4f v;
+#endif
+};
+
+template<> struct packet_traits<std::complex<float> > : default_packet_traits
+{
+ typedef Packet2cf type;
+ typedef Packet2cf half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 2,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasBlend = 1,
+ HasSetLinear = 0
+ };
+};
+
+
+template<> struct packet_traits<std::complex<double> > : default_packet_traits
+{
+ typedef Packet1cd type;
+ typedef Packet1cd half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 1,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasNegate = 1,
+ HasAbs = 0,
+ HasAbs2 = 0,
+ HasMin = 0,
+ HasMax = 0,
+ HasSetLinear = 0
+ };
+};
+
+template<> struct unpacket_traits<Packet2cf> { typedef std::complex<float> type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet2cf half; };
+template<> struct unpacket_traits<Packet1cd> { typedef std::complex<double> type; enum {size=1, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet1cd half; };
+
+/* Forward declaration */
+EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2cf,2>& kernel);
+
+/* complex<double> first */
+template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(const std::complex<double>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>((const double*)from)); }
+template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>((const double*)from)); }
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((double*)to, from.v); }
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, from.v); }
+
+template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from)
+{ /* here we really have to use unaligned loads :( */ return ploadu<Packet1cd>(&from); }
+
+template<> EIGEN_DEVICE_FUNC inline Packet1cd pgather<std::complex<double>, Packet1cd>(const std::complex<double>* from, Index stride EIGEN_UNUSED)
+{
+ return pload<Packet1cd>(from);
+}
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to, const Packet1cd& from, Index stride EIGEN_UNUSED)
+{
+ pstore<std::complex<double> >(to, from);
+}
+template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(a.v + b.v); }
+template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(a.v - b.v); }
+template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) { return Packet1cd(pnegate(Packet2d(a.v))); }
+template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a) { return Packet1cd((Packet2d)vec_xor((Packet2d)a.v, (Packet2d)p2ul_CONJ_XOR2)); }
+template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{
+ Packet2d a_re, a_im, v1, v2;
+
+ // Permute and multiply the real parts of a and b
+ a_re = vec_perm(a.v, a.v, p16uc_PSET64_HI);
+ // Get the imaginary parts of a
+ a_im = vec_perm(a.v, a.v, p16uc_PSET64_LO);
+ // multiply a_re * b
+ v1 = vec_madd(a_re, b.v, p2d_ZERO);
+ // multiply a_im * b and get the conjugate result
+ v2 = vec_madd(a_im, b.v, p2d_ZERO);
+ v2 = (Packet2d) vec_sld((Packet4ui)v2, (Packet4ui)v2, 8);
+ v2 = (Packet2d) vec_xor((Packet2d)v2, (Packet2d) p2ul_CONJ_XOR1);
+
+ return Packet1cd(v1 + v2);
+}
+template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(vec_and(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(vec_or(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(vec_xor(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet1cd pandnot <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(vec_and(a.v, vec_nor(b.v,b.v))); }
+template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) { return pset1<Packet1cd>(*from); }
+template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(const Packet1cd& a, const Packet1cd& b) {
+ Packet2d eq = vec_cmpeq (a.v, b.v);
+ Packet2d tmp = { eq[1], eq[0] };
+ return (Packet1cd)pand<Packet2d>(eq, tmp);
+}
+
+template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> * addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
+
+template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a)
+{
+ std::complex<double> EIGEN_ALIGN16 res;
+ pstore<std::complex<double> >(&res, a);
+
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; }
+template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a)
+{
+ return pfirst(a);
+}
+template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a)
+{
+ return pfirst(a);
+}
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d)
+
+template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
+{
+ // TODO optimize it for AltiVec
+ Packet1cd res = pmul(a,pconj(b));
+ Packet2d s = vec_madd(b.v, b.v, p2d_ZERO_);
+ return Packet1cd(pdiv(res.v, s + vec_perm(s, s, p16uc_REVERSE64)));
+}
+
+EIGEN_STRONG_INLINE Packet1cd pcplxflip/*<Packet1cd>*/(const Packet1cd& x)
+{
+ return Packet1cd(preverse(Packet2d(x.v)));
+}
+
+EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet1cd,2>& kernel)
+{
+ Packet2d tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
+ kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
+ kernel.packet[0].v = tmp;
+}
+
+/* complex<float> follows */
+template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>((const float*)from)); }
+template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>((const float*)from)); }
+template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((float*)to, from.v); }
+template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((float*)to, from.v); }
+
+template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a)
+{
+ std::complex<float> EIGEN_ALIGN16 res[2];
+ pstore<std::complex<float> >(res, a);
+
+ return res[0];
+}
+
+
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
+template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from)
+{
+ Packet2cf res;
+ res.cd[0] = Packet1cd(vec_ld2f((const float *)&from));
+ res.cd[1] = res.cd[0];
+ return res;
+}
+#else
+template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from)
+{
+ Packet2cf res;
+ if((std::ptrdiff_t(&from) % 16) == 0)
+ res.v = pload<Packet4f>((const float *)&from);
+ else
+ res.v = ploadu<Packet4f>((const float *)&from);
+ res.v = vec_perm(res.v, res.v, p16uc_PSET64_HI);
+ return res;
+}
+#endif
+
+template<> EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>(const std::complex<float>* from, Index stride)
+{
+ std::complex<float> EIGEN_ALIGN16 af[2];
+ af[0] = from[0*stride];
+ af[1] = from[1*stride];
+ return pload<Packet2cf>(af);
+}
+template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to, const Packet2cf& from, Index stride)
+{
+ std::complex<float> EIGEN_ALIGN16 af[2];
+ pstore<std::complex<float> >((std::complex<float> *) af, from);
+ to[0*stride] = af[0];
+ to[1*stride] = af[1];
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(padd<Packet4f>(a.v, b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(psub<Packet4f>(a.v, b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) { return Packet2cf(pnegate(Packet4f(a.v))); }
+
+template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pand<Packet4f>(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(por<Packet4f>(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pxor<Packet4f>(a.v,b.v)); }
+template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pandnot<Packet4f>(a.v,b.v)); }
+
+template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { return pset1<Packet2cf>(*from); }
+
+template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> * addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
+
+
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
+
+template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf& a, const Packet2cf& b) {
+ Packet4f eq = pcmp_eq<Packet4f> (a.v, b.v);
+ Packet2cf res;
+ Packet2d tmp1 = { eq.v4f[0][1], eq.v4f[0][0] };
+ Packet2d tmp2 = { eq.v4f[1][1], eq.v4f[1][0] };
+ res.v.v4f[0] = pand<Packet2d>(eq.v4f[0], tmp1);
+ res.v.v4f[1] = pand<Packet2d>(eq.v4f[1], tmp2);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a)
+{
+ Packet2cf res;
+ res.v.v4f[0] = pconj(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[0]))).v;
+ res.v.v4f[1] = pconj(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[1]))).v;
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{
+ Packet2cf res;
+ res.v.v4f[0] = pmul(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[0])), Packet1cd(reinterpret_cast<Packet2d>(b.v.v4f[0]))).v;
+ res.v.v4f[1] = pmul(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[1])), Packet1cd(reinterpret_cast<Packet2d>(b.v.v4f[1]))).v;
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a)
+{
+ Packet2cf res;
+ res.cd[0] = a.cd[1];
+ res.cd[1] = a.cd[0];
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
+{
+ std::complex<float> res;
+ Packet1cd b = padd<Packet1cd>(a.cd[0], a.cd[1]);
+ vec_st2f(b.v, (float*)&res);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
+{
+ std::complex<float> res;
+ Packet1cd b = pmul<Packet1cd>(a.cd[0], a.cd[1]);
+ vec_st2f(b.v, (float*)&res);
+ return res;
+}
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
+
+template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{
+ // TODO optimize it for AltiVec
+ Packet2cf res;
+ res.cd[0] = pdiv<Packet1cd>(a.cd[0], b.cd[0]);
+ res.cd[1] = pdiv<Packet1cd>(a.cd[1], b.cd[1]);
+ return res;
+}
+
+EIGEN_STRONG_INLINE Packet2cf pcplxflip/*<Packet2cf>*/(const Packet2cf& x)
+{
+ Packet2cf res;
+ res.cd[0] = pcplxflip(x.cd[0]);
+ res.cd[1] = pcplxflip(x.cd[1]);
+ return res;
+}
+
+EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2cf,2>& kernel)
+{
+ Packet1cd tmp = kernel.packet[0].cd[1];
+ kernel.packet[0].cd[1] = kernel.packet[1].cd[0];
+ kernel.packet[1].cd[0] = tmp;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket, const Packet2cf& elsePacket) {
+ Packet2cf result;
+ const Selector<4> ifPacket4 = { ifPacket.select[0], ifPacket.select[0], ifPacket.select[1], ifPacket.select[1] };
+ result.v = pblend<Packet4f>(ifPacket4, thenPacket.v, elsePacket.v);
+ return result;
+}
+#else
+template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf& a, const Packet2cf& b) {
+ Packet4f eq = vec_cmpeq (a.v, b.v);
+ Packet4f tmp = { eq[1], eq[0], eq[3], eq[2] };
+ return (Packet2cf)pand<Packet4f>(eq, tmp);
+}
+template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) { return Packet2cf(pxor<Packet4f>(a.v, reinterpret_cast<Packet4f>(p4ui_CONJ_XOR))); }
+template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{
+ Packet4f a_re, a_im, prod, prod_im;
+
+ // Permute and multiply the real parts of a and b
+ a_re = vec_perm(a.v, a.v, p16uc_PSET32_WODD);
+
+ // Get the imaginary parts of a
+ a_im = vec_perm(a.v, a.v, p16uc_PSET32_WEVEN);
+
+ // multiply a_im * b and get the conjugate result
+ prod_im = a_im * b.v;
+ prod_im = pxor<Packet4f>(prod_im, reinterpret_cast<Packet4f>(p4ui_CONJ_XOR));
+ // permute back to a proper order
+ prod_im = vec_perm(prod_im, prod_im, p16uc_COMPLEX32_REV);
+
+ // multiply a_re * b, add prod_im
+ prod = pmadd<Packet4f>(a_re, b.v, prod_im);
+
+ return Packet2cf(prod);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a)
+{
+ Packet4f rev_a;
+ rev_a = vec_perm(a.v, a.v, p16uc_COMPLEX32_REV2);
+ return Packet2cf(rev_a);
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
+{
+ Packet4f b;
+ b = vec_sld(a.v, a.v, 8);
+ b = padd<Packet4f>(a.v, b);
+ return pfirst<Packet2cf>(Packet2cf(b));
+}
+
+template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
+{
+ Packet4f b;
+ Packet2cf prod;
+ b = vec_sld(a.v, a.v, 8);
+ prod = pmul<Packet2cf>(a, Packet2cf(b));
+
+ return pfirst<Packet2cf>(prod);
+}
+
+EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
+
+template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
+{
+ // TODO optimize it for AltiVec
+ Packet2cf res = pmul(a, pconj(b));
+ Packet4f s = pmul<Packet4f>(b.v, b.v);
+ return Packet2cf(pdiv(res.v, padd<Packet4f>(s, vec_perm(s, s, p16uc_COMPLEX32_REV))));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& x)
+{
+ return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX32_REV));
+}
+
+EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2cf,2>& kernel)
+{
+ Packet4f tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
+ kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
+ kernel.packet[0].v = tmp;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket, const Packet2cf& elsePacket) {
+ Packet2cf result;
+ result.v = reinterpret_cast<Packet4f>(pblend<Packet2d>(ifPacket, reinterpret_cast<Packet2d>(thenPacket.v), reinterpret_cast<Packet2d>(elsePacket.v)));
+ return result;
+}
+#endif
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_COMPLEX32_ALTIVEC_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h b/src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h
new file mode 100644
index 000000000..1635e128c
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h
@@ -0,0 +1,233 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2007 Julien Pommier
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2016 Konstantinos Margaritis <markos@freevec.org>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/* The sin, cos, exp, and log functions of this file come from
+ * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/
+ */
+
+#ifndef EIGEN_MATH_FUNCTIONS_ALTIVEC_H
+#define EIGEN_MATH_FUNCTIONS_ALTIVEC_H
+
+namespace Eigen {
+
+namespace internal {
+
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
+static _EIGEN_DECLARE_CONST_Packet4f(1 , 1.0f);
+static _EIGEN_DECLARE_CONST_Packet4f(half, 0.5f);
+static _EIGEN_DECLARE_CONST_Packet4i(0x7f, 0x7f);
+static _EIGEN_DECLARE_CONST_Packet4i(23, 23);
+
+static _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(inv_mant_mask, ~0x7f800000);
+
+/* the smallest non denormalized float number */
+static _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(min_norm_pos, 0x00800000);
+static _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(minus_inf, 0xff800000); // -1.f/0.f
+static _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(minus_nan, 0xffffffff);
+
+/* natural logarithm computed for 4 simultaneous float
+ return NaN for x <= 0
+*/
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_SQRTHF, 0.707106781186547524f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p0, 7.0376836292E-2f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p1, - 1.1514610310E-1f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p2, 1.1676998740E-1f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p3, - 1.2420140846E-1f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p4, + 1.4249322787E-1f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p5, - 1.6668057665E-1f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p6, + 2.0000714765E-1f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p7, - 2.4999993993E-1f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_p8, + 3.3333331174E-1f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_q1, -2.12194440e-4f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_log_q2, 0.693359375f);
+
+static _EIGEN_DECLARE_CONST_Packet4f(exp_hi, 88.3762626647950f);
+static _EIGEN_DECLARE_CONST_Packet4f(exp_lo, -88.3762626647949f);
+
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_LOG2EF, 1.44269504088896341f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_C1, 0.693359375f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_C2, -2.12194440e-4f);
+
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p0, 1.9875691500E-4f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p1, 1.3981999507E-3f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p2, 8.3334519073E-3f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p3, 4.1665795894E-2f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p4, 1.6666665459E-1f);
+static _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p5, 5.0000001201E-1f);
+#endif
+
+static _EIGEN_DECLARE_CONST_Packet2d(1 , 1.0);
+static _EIGEN_DECLARE_CONST_Packet2d(2 , 2.0);
+static _EIGEN_DECLARE_CONST_Packet2d(half, 0.5);
+
+static _EIGEN_DECLARE_CONST_Packet2d(exp_hi, 709.437);
+static _EIGEN_DECLARE_CONST_Packet2d(exp_lo, -709.436139303);
+
+static _EIGEN_DECLARE_CONST_Packet2d(cephes_LOG2EF, 1.4426950408889634073599);
+
+static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p0, 1.26177193074810590878e-4);
+static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p1, 3.02994407707441961300e-2);
+static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p2, 9.99999999999999999910e-1);
+
+static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q0, 3.00198505138664455042e-6);
+static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q1, 2.52448340349684104192e-3);
+static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q2, 2.27265548208155028766e-1);
+static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q3, 2.00000000000000000009e0);
+
+static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_C1, 0.693145751953125);
+static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_C2, 1.42860682030941723212e-6);
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet2d pexp<Packet2d>(const Packet2d& _x)
+{
+ Packet2d x = _x;
+
+ Packet2d tmp, fx;
+ Packet2l emm0;
+
+ // clamp x
+ x = pmax(pmin(x, p2d_exp_hi), p2d_exp_lo);
+ /* express exp(x) as exp(g + n*log(2)) */
+ fx = pmadd(p2d_cephes_LOG2EF, x, p2d_half);
+
+ fx = vec_floor(fx);
+
+ tmp = pmul(fx, p2d_cephes_exp_C1);
+ Packet2d z = pmul(fx, p2d_cephes_exp_C2);
+ x = psub(x, tmp);
+ x = psub(x, z);
+
+ Packet2d x2 = pmul(x,x);
+
+ Packet2d px = p2d_cephes_exp_p0;
+ px = pmadd(px, x2, p2d_cephes_exp_p1);
+ px = pmadd(px, x2, p2d_cephes_exp_p2);
+ px = pmul (px, x);
+
+ Packet2d qx = p2d_cephes_exp_q0;
+ qx = pmadd(qx, x2, p2d_cephes_exp_q1);
+ qx = pmadd(qx, x2, p2d_cephes_exp_q2);
+ qx = pmadd(qx, x2, p2d_cephes_exp_q3);
+
+ x = pdiv(px,psub(qx,px));
+ x = pmadd(p2d_2,x,p2d_1);
+
+ // build 2^n
+ emm0 = vec_ctsl(fx, 0);
+
+ static const Packet2l p2l_1023 = { 1023, 1023 };
+ static const Packet2ul p2ul_52 = { 52, 52 };
+
+ emm0 = emm0 + p2l_1023;
+ emm0 = emm0 << reinterpret_cast<Packet2l>(p2ul_52);
+
+ // Altivec's max & min operators just drop silent NaNs. Check NaNs in
+ // inputs and return them unmodified.
+ Packet2ul isnumber_mask = reinterpret_cast<Packet2ul>(vec_cmpeq(_x, _x));
+ return vec_sel(_x, pmax(pmul(x, reinterpret_cast<Packet2d>(emm0)), _x),
+ isnumber_mask);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f pexp<Packet4f>(const Packet4f& _x)
+{
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
+ Packet4f x = _x;
+
+ Packet4f tmp, fx;
+ Packet4i emm0;
+
+ // clamp x
+ x = pmax(pmin(x, p4f_exp_hi), p4f_exp_lo);
+
+ // express exp(x) as exp(g + n*log(2))
+ fx = pmadd(x, p4f_cephes_LOG2EF, p4f_half);
+
+ fx = pfloor(fx);
+
+ tmp = pmul(fx, p4f_cephes_exp_C1);
+ Packet4f z = pmul(fx, p4f_cephes_exp_C2);
+ x = psub(x, tmp);
+ x = psub(x, z);
+
+ z = pmul(x,x);
+
+ Packet4f y = p4f_cephes_exp_p0;
+ y = pmadd(y, x, p4f_cephes_exp_p1);
+ y = pmadd(y, x, p4f_cephes_exp_p2);
+ y = pmadd(y, x, p4f_cephes_exp_p3);
+ y = pmadd(y, x, p4f_cephes_exp_p4);
+ y = pmadd(y, x, p4f_cephes_exp_p5);
+ y = pmadd(y, z, x);
+ y = padd(y, p4f_1);
+
+ // build 2^n
+ emm0 = (Packet4i){ (int)fx[0], (int)fx[1], (int)fx[2], (int)fx[3] };
+ emm0 = emm0 + p4i_0x7f;
+ emm0 = emm0 << reinterpret_cast<Packet4i>(p4i_23);
+
+ return pmax(pmul(y, reinterpret_cast<Packet4f>(emm0)), _x);
+#else
+ Packet4f res;
+ res.v4f[0] = pexp<Packet2d>(_x.v4f[0]);
+ res.v4f[1] = pexp<Packet2d>(_x.v4f[1]);
+ return res;
+#endif
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet2d psqrt<Packet2d>(const Packet2d& x)
+{
+ return vec_sqrt(x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f psqrt<Packet4f>(const Packet4f& x)
+{
+ Packet4f res;
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
+ res = vec_sqrt(x);
+#else
+ res.v4f[0] = psqrt<Packet2d>(x.v4f[0]);
+ res.v4f[1] = psqrt<Packet2d>(x.v4f[1]);
+#endif
+ return res;
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet2d prsqrt<Packet2d>(const Packet2d& x) {
+ return pset1<Packet2d>(1.0) / psqrt<Packet2d>(x);
+}
+
+template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
+Packet4f prsqrt<Packet4f>(const Packet4f& x) {
+ Packet4f res;
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
+ res = pset1<Packet4f>(1.0) / psqrt<Packet4f>(x);
+#else
+ res.v4f[0] = prsqrt<Packet2d>(x.v4f[0]);
+ res.v4f[1] = prsqrt<Packet2d>(x.v4f[1]);
+#endif
+ return res;
+}
+
+// Hyperbolic Tangent function.
+template <>
+EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet4f
+ptanh<Packet4f>(const Packet4f& x) {
+ return internal::generic_fast_tanh_float(x);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MATH_FUNCTIONS_ALTIVEC_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h b/src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h
new file mode 100644
index 000000000..1f55a90a5
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h
@@ -0,0 +1,1060 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2016 Konstantinos Margaritis <markos@freevec.org>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PACKET_MATH_ZVECTOR_H
+#define EIGEN_PACKET_MATH_ZVECTOR_H
+
+namespace Eigen {
+
+namespace internal {
+
+#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
+#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 16
+#endif
+
+#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+#endif
+
+#ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS
+#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32
+#endif
+
+typedef __vector int Packet4i;
+typedef __vector unsigned int Packet4ui;
+typedef __vector __bool int Packet4bi;
+typedef __vector short int Packet8i;
+typedef __vector unsigned char Packet16uc;
+typedef __vector double Packet2d;
+typedef __vector unsigned long long Packet2ul;
+typedef __vector long long Packet2l;
+
+// Z14 has builtin support for float vectors
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
+typedef __vector float Packet4f;
+#else
+typedef struct {
+ Packet2d v4f[2];
+} Packet4f;
+#endif
+
+typedef union {
+ numext::int32_t i[4];
+ numext::uint32_t ui[4];
+ numext::int64_t l[2];
+ numext::uint64_t ul[2];
+ double d[2];
+ float f[4];
+ Packet4i v4i;
+ Packet4ui v4ui;
+ Packet2l v2l;
+ Packet2ul v2ul;
+ Packet2d v2d;
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
+ Packet4f v4f;
+#endif
+} Packet;
+
+// We don't want to write the same code all the time, but we need to reuse the constants
+// and it doesn't really work to declare them global, so we define macros instead
+
+#define _EIGEN_DECLARE_CONST_FAST_Packet4i(NAME,X) \
+ Packet4i p4i_##NAME = reinterpret_cast<Packet4i>(vec_splat_s32(X))
+
+#define _EIGEN_DECLARE_CONST_FAST_Packet2d(NAME,X) \
+ Packet2d p2d_##NAME = reinterpret_cast<Packet2d>(vec_splat_s64(X))
+
+#define _EIGEN_DECLARE_CONST_FAST_Packet2l(NAME,X) \
+ Packet2l p2l_##NAME = reinterpret_cast<Packet2l>(vec_splat_s64(X))
+
+#define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \
+ Packet4i p4i_##NAME = pset1<Packet4i>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet2d(NAME,X) \
+ Packet2d p2d_##NAME = pset1<Packet2d>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet2l(NAME,X) \
+ Packet2l p2l_##NAME = pset1<Packet2l>(X)
+
+// These constants are endian-agnostic
+static _EIGEN_DECLARE_CONST_FAST_Packet4i(ZERO, 0); //{ 0, 0, 0, 0,}
+static _EIGEN_DECLARE_CONST_FAST_Packet4i(ONE, 1); //{ 1, 1, 1, 1}
+
+static _EIGEN_DECLARE_CONST_FAST_Packet2d(ZERO, 0);
+static _EIGEN_DECLARE_CONST_FAST_Packet2l(ZERO, 0);
+static _EIGEN_DECLARE_CONST_FAST_Packet2l(ONE, 1);
+
+static Packet2d p2d_ONE = { 1.0, 1.0 };
+static Packet2d p2d_ZERO_ = { numext::bit_cast<double>0x8000000000000000ull),
+ numext::bit_cast<double>0x8000000000000000ull) };
+
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
+#define _EIGEN_DECLARE_CONST_FAST_Packet4f(NAME,X) \
+ Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(vec_splat_s32(X))
+
+#define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \
+ Packet4f p4f_##NAME = pset1<Packet4f>(X)
+
+#define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \
+ const Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(pset1<Packet4i>(X))
+
+static _EIGEN_DECLARE_CONST_FAST_Packet4f(ZERO, 0); //{ 0.0, 0.0, 0.0, 0.0}
+static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS1,-1); //{ -1, -1, -1, -1}
+static Packet4f p4f_MZERO = { 0x80000000, 0x80000000, 0x80000000, 0x80000000};
+#endif
+
+static Packet4i p4i_COUNTDOWN = { 0, 1, 2, 3 };
+static Packet4f p4f_COUNTDOWN = { 0.0, 1.0, 2.0, 3.0 };
+static Packet2d p2d_COUNTDOWN = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet16uc>(p2d_ZERO), reinterpret_cast<Packet16uc>(p2d_ONE), 8));
+
+static Packet16uc p16uc_PSET64_HI = { 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 };
+static Packet16uc p16uc_DUPLICATE32_HI = { 0,1,2,3, 0,1,2,3, 4,5,6,7, 4,5,6,7 };
+
+// Mask alignment
+#define _EIGEN_MASK_ALIGNMENT 0xfffffffffffffff0
+
+#define _EIGEN_ALIGNED_PTR(x) ((std::ptrdiff_t)(x) & _EIGEN_MASK_ALIGNMENT)
+
+// Handle endianness properly while loading constants
+// Define global static constants:
+
+static Packet16uc p16uc_FORWARD = { 0,1,2,3, 4,5,6,7, 8,9,10,11, 12,13,14,15 };
+static Packet16uc p16uc_REVERSE32 = { 12,13,14,15, 8,9,10,11, 4,5,6,7, 0,1,2,3 };
+static Packet16uc p16uc_REVERSE64 = { 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 };
+
+static Packet16uc p16uc_PSET32_WODD = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 2), 8);//{ 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 };
+static Packet16uc p16uc_PSET32_WEVEN = vec_sld(p16uc_DUPLICATE32_HI, (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 3), 8);//{ 4,5,6,7, 4,5,6,7, 12,13,14,15, 12,13,14,15 };
+/*static Packet16uc p16uc_HALF64_0_16 = vec_sld((Packet16uc)p4i_ZERO, vec_splat((Packet16uc) vec_abs(p4i_MINUS16), 3), 8); //{ 0,0,0,0, 0,0,0,0, 16,16,16,16, 16,16,16,16};
+
+static Packet16uc p16uc_PSET64_HI = (Packet16uc) vec_mergeh((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 };*/
+static Packet16uc p16uc_PSET64_LO = (Packet16uc) vec_mergel((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 8,9,10,11, 12,13,14,15, 8,9,10,11, 12,13,14,15 };
+/*static Packet16uc p16uc_TRANSPOSE64_HI = vec_add(p16uc_PSET64_HI, p16uc_HALF64_0_16); //{ 0,1,2,3, 4,5,6,7, 16,17,18,19, 20,21,22,23};
+static Packet16uc p16uc_TRANSPOSE64_LO = vec_add(p16uc_PSET64_LO, p16uc_HALF64_0_16); //{ 8,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31};*/
+static Packet16uc p16uc_TRANSPOSE64_HI = { 0,1,2,3, 4,5,6,7, 16,17,18,19, 20,21,22,23};
+static Packet16uc p16uc_TRANSPOSE64_LO = { 8,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31};
+
+static Packet16uc p16uc_COMPLEX32_REV = vec_sld(p16uc_REVERSE32, p16uc_REVERSE32, 8); //{ 4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11 };
+
+static Packet16uc p16uc_COMPLEX32_REV2 = vec_sld(p16uc_FORWARD, p16uc_FORWARD, 8); //{ 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 };
+
+
+#if EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC
+ #define EIGEN_ZVECTOR_PREFETCH(ADDR) __builtin_prefetch(ADDR);
+#else
+ #define EIGEN_ZVECTOR_PREFETCH(ADDR) asm( " pfd [%[addr]]\n" :: [addr] "r" (ADDR) : "cc" );
+#endif
+
+template<> struct packet_traits<int> : default_packet_traits
+{
+ typedef Packet4i type;
+ typedef Packet4i half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasBlend = 1
+ };
+};
+
+template <>
+struct packet_traits<float> : default_packet_traits {
+ typedef Packet4f type;
+ typedef Packet4f half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size = 4,
+ HasHalfPacket = 0,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasAbs = 1,
+ HasSin = 0,
+ HasCos = 0,
+ HasLog = 0,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasTanh = 1,
+ HasErf = 1,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasNegate = 1,
+ HasBlend = 1
+ };
+};
+
+template<> struct packet_traits<double> : default_packet_traits
+{
+ typedef Packet2d type;
+ typedef Packet2d half;
+ enum {
+ Vectorizable = 1,
+ AlignedOnScalar = 1,
+ size=2,
+ HasHalfPacket = 1,
+
+ HasAdd = 1,
+ HasSub = 1,
+ HasMul = 1,
+ HasDiv = 1,
+ HasMin = 1,
+ HasMax = 1,
+ HasAbs = 1,
+ HasSin = 0,
+ HasCos = 0,
+ HasLog = 0,
+ HasExp = 1,
+ HasSqrt = 1,
+ HasRsqrt = 1,
+ HasRound = 1,
+ HasFloor = 1,
+ HasCeil = 1,
+ HasNegate = 1,
+ HasBlend = 1
+ };
+};
+
+template<> struct unpacket_traits<Packet4i> { typedef int type; enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet4i half; };
+template<> struct unpacket_traits<Packet4f> { typedef float type; enum {size=4, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet4f half; };
+template<> struct unpacket_traits<Packet2d> { typedef double type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false, masked_store_available=false}; typedef Packet2d half; };
+
+/* Forward declaration */
+EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4f,4>& kernel);
+
+inline std::ostream & operator <<(std::ostream & s, const Packet4i & v)
+{
+ Packet vt;
+ vt.v4i = v;
+ s << vt.i[0] << ", " << vt.i[1] << ", " << vt.i[2] << ", " << vt.i[3];
+ return s;
+}
+
+inline std::ostream & operator <<(std::ostream & s, const Packet4ui & v)
+{
+ Packet vt;
+ vt.v4ui = v;
+ s << vt.ui[0] << ", " << vt.ui[1] << ", " << vt.ui[2] << ", " << vt.ui[3];
+ return s;
+}
+
+inline std::ostream & operator <<(std::ostream & s, const Packet2l & v)
+{
+ Packet vt;
+ vt.v2l = v;
+ s << vt.l[0] << ", " << vt.l[1];
+ return s;
+}
+
+inline std::ostream & operator <<(std::ostream & s, const Packet2ul & v)
+{
+ Packet vt;
+ vt.v2ul = v;
+ s << vt.ul[0] << ", " << vt.ul[1] ;
+ return s;
+}
+
+inline std::ostream & operator <<(std::ostream & s, const Packet2d & v)
+{
+ Packet vt;
+ vt.v2d = v;
+ s << vt.d[0] << ", " << vt.d[1];
+ return s;
+}
+
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
+inline std::ostream & operator <<(std::ostream & s, const Packet4f & v)
+{
+ Packet vt;
+ vt.v4f = v;
+ s << vt.f[0] << ", " << vt.f[1] << ", " << vt.f[2] << ", " << vt.f[3];
+ return s;
+}
+#endif
+
+template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from)
+{
+ // FIXME: No intrinsic yet
+ EIGEN_DEBUG_ALIGNED_LOAD
+ Packet *vfrom;
+ vfrom = (Packet *) from;
+ return vfrom->v4i;
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from)
+{
+ // FIXME: No intrinsic yet
+ EIGEN_DEBUG_ALIGNED_LOAD
+ Packet *vfrom;
+ vfrom = (Packet *) from;
+ return vfrom->v2d;
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet4i& from)
+{
+ // FIXME: No intrinsic yet
+ EIGEN_DEBUG_ALIGNED_STORE
+ Packet *vto;
+ vto = (Packet *) to;
+ vto->v4i = from;
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from)
+{
+ // FIXME: No intrinsic yet
+ EIGEN_DEBUG_ALIGNED_STORE
+ Packet *vto;
+ vto = (Packet *) to;
+ vto->v2d = from;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from)
+{
+ return vec_splats(from);
+}
+template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) {
+ return vec_splats(from);
+}
+
+template<> EIGEN_STRONG_INLINE void
+pbroadcast4<Packet4i>(const int *a,
+ Packet4i& a0, Packet4i& a1, Packet4i& a2, Packet4i& a3)
+{
+ a3 = pload<Packet4i>(a);
+ a0 = vec_splat(a3, 0);
+ a1 = vec_splat(a3, 1);
+ a2 = vec_splat(a3, 2);
+ a3 = vec_splat(a3, 3);
+}
+
+template<> EIGEN_STRONG_INLINE void
+pbroadcast4<Packet2d>(const double *a,
+ Packet2d& a0, Packet2d& a1, Packet2d& a2, Packet2d& a3)
+{
+ a1 = pload<Packet2d>(a);
+ a0 = vec_splat(a1, 0);
+ a1 = vec_splat(a1, 1);
+ a3 = pload<Packet2d>(a+2);
+ a2 = vec_splat(a3, 0);
+ a3 = vec_splat(a3, 1);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet4i pgather<int, Packet4i>(const int* from, Index stride)
+{
+ int EIGEN_ALIGN16 ai[4];
+ ai[0] = from[0*stride];
+ ai[1] = from[1*stride];
+ ai[2] = from[2*stride];
+ ai[3] = from[3*stride];
+ return pload<Packet4i>(ai);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride)
+{
+ double EIGEN_ALIGN16 af[2];
+ af[0] = from[0*stride];
+ af[1] = from[1*stride];
+ return pload<Packet2d>(af);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<int, Packet4i>(int* to, const Packet4i& from, Index stride)
+{
+ int EIGEN_ALIGN16 ai[4];
+ pstore<int>((int *)ai, from);
+ to[0*stride] = ai[0];
+ to[1*stride] = ai[1];
+ to[2*stride] = ai[2];
+ to[3*stride] = ai[3];
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride)
+{
+ double EIGEN_ALIGN16 af[2];
+ pstore<double>(af, from);
+ to[0*stride] = af[0];
+ to[1*stride] = af[1];
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a + b); }
+template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a + b); }
+
+template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a - b); }
+template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a - b); }
+
+template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a * b); }
+template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a * b); }
+
+template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a / b); }
+template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a / b); }
+
+template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return (-a); }
+template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) { return (-a); }
+
+template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; }
+
+template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { return padd<Packet4i>(pmul<Packet4i>(a, b), c); }
+template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) { return vec_madd(a, b, c); }
+
+template<> EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int& a) { return padd<Packet4i>(pset1<Packet4i>(a), p4i_COUNTDOWN); }
+template<> EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) { return padd<Packet2d>(pset1<Packet2d>(a), p2d_COUNTDOWN); }
+
+template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_min(a, b); }
+template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_min(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_max(a, b); }
+template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_max(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, b); }
+template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_or(a, b); }
+template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_or(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_xor(a, b); }
+template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_xor(a, b); }
+
+template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return pand<Packet4i>(a, vec_nor(b, b)); }
+template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, vec_nor(b, b)); }
+
+template<> EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) { return vec_round(a); }
+template<> EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) { return vec_ceil(a); }
+template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) { return vec_floor(a); }
+
+template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from) { return pload<Packet4i>(from); }
+template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) { return pload<Packet2d>(from); }
+
+
+template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int* from)
+{
+ Packet4i p = pload<Packet4i>(from);
+ return vec_perm(p, p, p16uc_DUPLICATE32_HI);
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from)
+{
+ Packet2d p = pload<Packet2d>(from);
+ return vec_perm(p, p, p16uc_PSET64_HI);
+}
+
+template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) { pstore<int>(to, from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) { pstore<double>(to, from); }
+
+template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
+template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
+
+template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { int EIGEN_ALIGN16 x[4]; pstore(x, a); return x[0]; }
+template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { double EIGEN_ALIGN16 x[2]; pstore(x, a); return x[0]; }
+
+template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a)
+{
+ return reinterpret_cast<Packet4i>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32));
+}
+
+template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a)
+{
+ return reinterpret_cast<Packet2d>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE64));
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i pabs<Packet4i>(const Packet4i& a) { return vec_abs(a); }
+template<> EIGEN_STRONG_INLINE Packet2d pabs<Packet2d>(const Packet2d& a) { return vec_abs(a); }
+
+template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a)
+{
+ Packet4i b, sum;
+ b = vec_sld(a, a, 8);
+ sum = padd<Packet4i>(a, b);
+ b = vec_sld(sum, sum, 4);
+ sum = padd<Packet4i>(sum, b);
+ return pfirst(sum);
+}
+
+template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a)
+{
+ Packet2d b, sum;
+ b = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8));
+ sum = padd<Packet2d>(a, b);
+ return pfirst(sum);
+}
+
+// Other reduction functions:
+// mul
+template<> EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a)
+{
+ EIGEN_ALIGN16 int aux[4];
+ pstore(aux, a);
+ return aux[0] * aux[1] * aux[2] * aux[3];
+}
+
+template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a)
+{
+ return pfirst(pmul(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))));
+}
+
+// min
+template<> EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a)
+{
+ Packet4i b, res;
+ b = pmin<Packet4i>(a, vec_sld(a, a, 8));
+ res = pmin<Packet4i>(b, vec_sld(b, b, 4));
+ return pfirst(res);
+}
+
+template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a)
+{
+ return pfirst(pmin<Packet2d>(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))));
+}
+
+// max
+template<> EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a)
+{
+ Packet4i b, res;
+ b = pmax<Packet4i>(a, vec_sld(a, a, 8));
+ res = pmax<Packet4i>(b, vec_sld(b, b, 4));
+ return pfirst(res);
+}
+
+// max
+template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a)
+{
+ return pfirst(pmax<Packet2d>(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))));
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet4i,4>& kernel) {
+ Packet4i t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]);
+ Packet4i t1 = vec_mergel(kernel.packet[0], kernel.packet[2]);
+ Packet4i t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]);
+ Packet4i t3 = vec_mergel(kernel.packet[1], kernel.packet[3]);
+ kernel.packet[0] = vec_mergeh(t0, t2);
+ kernel.packet[1] = vec_mergel(t0, t2);
+ kernel.packet[2] = vec_mergeh(t1, t3);
+ kernel.packet[3] = vec_mergel(t1, t3);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet2d,2>& kernel) {
+ Packet2d t0 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_HI);
+ Packet2d t1 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_LO);
+ kernel.packet[0] = t0;
+ kernel.packet[1] = t1;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4i pblend(const Selector<4>& ifPacket, const Packet4i& thenPacket, const Packet4i& elsePacket) {
+ Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] };
+ Packet4ui mask = vec_cmpeq(select, reinterpret_cast<Packet4ui>(p4i_ONE));
+ return vec_sel(elsePacket, thenPacket, mask);
+}
+
+
+template<> EIGEN_STRONG_INLINE Packet2d pblend(const Selector<2>& ifPacket, const Packet2d& thenPacket, const Packet2d& elsePacket) {
+ Packet2ul select = { ifPacket.select[0], ifPacket.select[1] };
+ Packet2ul mask = vec_cmpeq(select, reinterpret_cast<Packet2ul>(p2l_ONE));
+ return vec_sel(elsePacket, thenPacket, mask);
+}
+
+/* z13 has no vector float support so we emulate that with double
+ z14 has proper vector float support.
+*/
+#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
+/* Helper function to simulate a vec_splat_packet4f
+ */
+template<int element> EIGEN_STRONG_INLINE Packet4f vec_splat_packet4f(const Packet4f& from)
+{
+ Packet4f splat;
+ switch (element) {
+ case 0:
+ splat.v4f[0] = vec_splat(from.v4f[0], 0);
+ splat.v4f[1] = splat.v4f[0];
+ break;
+ case 1:
+ splat.v4f[0] = vec_splat(from.v4f[0], 1);
+ splat.v4f[1] = splat.v4f[0];
+ break;
+ case 2:
+ splat.v4f[0] = vec_splat(from.v4f[1], 0);
+ splat.v4f[1] = splat.v4f[0];
+ break;
+ case 3:
+ splat.v4f[0] = vec_splat(from.v4f[1], 1);
+ splat.v4f[1] = splat.v4f[0];
+ break;
+ }
+ return splat;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from)
+{
+ // FIXME: No intrinsic yet
+ EIGEN_DEBUG_ALIGNED_LOAD
+ Packet4f vfrom;
+ vfrom.v4f[0] = vec_ld2f(&from[0]);
+ vfrom.v4f[1] = vec_ld2f(&from[2]);
+ return vfrom;
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from)
+{
+ // FIXME: No intrinsic yet
+ EIGEN_DEBUG_ALIGNED_STORE
+ vec_st2f(from.v4f[0], &to[0]);
+ vec_st2f(from.v4f[1], &to[2]);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from)
+{
+ Packet4f to;
+ to.v4f[0] = pset1<Packet2d>(static_cast<const double&>(from));
+ to.v4f[1] = to.v4f[0];
+ return to;
+}
+
+template<> EIGEN_STRONG_INLINE void
+pbroadcast4<Packet4f>(const float *a,
+ Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3)
+{
+ a3 = pload<Packet4f>(a);
+ a0 = vec_splat_packet4f<0>(a3);
+ a1 = vec_splat_packet4f<1>(a3);
+ a2 = vec_splat_packet4f<2>(a3);
+ a3 = vec_splat_packet4f<3>(a3);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride)
+{
+ float EIGEN_ALIGN16 ai[4];
+ ai[0] = from[0*stride];
+ ai[1] = from[1*stride];
+ ai[2] = from[2*stride];
+ ai[3] = from[3*stride];
+ return pload<Packet4f>(ai);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride)
+{
+ float EIGEN_ALIGN16 ai[4];
+ pstore<float>((float *)ai, from);
+ to[0*stride] = ai[0];
+ to[1*stride] = ai[1];
+ to[2*stride] = ai[2];
+ to[3*stride] = ai[3];
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f c;
+ c.v4f[0] = a.v4f[0] + b.v4f[0];
+ c.v4f[1] = a.v4f[1] + b.v4f[1];
+ return c;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f c;
+ c.v4f[0] = a.v4f[0] - b.v4f[0];
+ c.v4f[1] = a.v4f[1] - b.v4f[1];
+ return c;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f c;
+ c.v4f[0] = a.v4f[0] * b.v4f[0];
+ c.v4f[1] = a.v4f[1] * b.v4f[1];
+ return c;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f c;
+ c.v4f[0] = a.v4f[0] / b.v4f[0];
+ c.v4f[1] = a.v4f[1] / b.v4f[1];
+ return c;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a)
+{
+ Packet4f c;
+ c.v4f[0] = -a.v4f[0];
+ c.v4f[1] = -a.v4f[1];
+ return c;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c)
+{
+ Packet4f res;
+ res.v4f[0] = vec_madd(a.v4f[0], b.v4f[0], c.v4f[0]);
+ res.v4f[1] = vec_madd(a.v4f[1], b.v4f[1], c.v4f[1]);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f res;
+ res.v4f[0] = pmin(a.v4f[0], b.v4f[0]);
+ res.v4f[1] = pmin(a.v4f[1], b.v4f[1]);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f res;
+ res.v4f[0] = pmax(a.v4f[0], b.v4f[0]);
+ res.v4f[1] = pmax(a.v4f[1], b.v4f[1]);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f res;
+ res.v4f[0] = pand(a.v4f[0], b.v4f[0]);
+ res.v4f[1] = pand(a.v4f[1], b.v4f[1]);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f res;
+ res.v4f[0] = por(a.v4f[0], b.v4f[0]);
+ res.v4f[1] = por(a.v4f[1], b.v4f[1]);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f res;
+ res.v4f[0] = pxor(a.v4f[0], b.v4f[0]);
+ res.v4f[1] = pxor(a.v4f[1], b.v4f[1]);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f res;
+ res.v4f[0] = pandnot(a.v4f[0], b.v4f[0]);
+ res.v4f[1] = pandnot(a.v4f[1], b.v4f[1]);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a)
+{
+ Packet4f res;
+ res.v4f[0] = vec_round(a.v4f[0]);
+ res.v4f[1] = vec_round(a.v4f[1]);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a)
+{
+ Packet4f res;
+ res.v4f[0] = vec_ceil(a.v4f[0]);
+ res.v4f[1] = vec_ceil(a.v4f[1]);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a)
+{
+ Packet4f res;
+ res.v4f[0] = vec_floor(a.v4f[0]);
+ res.v4f[1] = vec_floor(a.v4f[1]);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from)
+{
+ Packet4f p = pload<Packet4f>(from);
+ p.v4f[1] = vec_splat(p.v4f[0], 1);
+ p.v4f[0] = vec_splat(p.v4f[0], 0);
+ return p;
+}
+
+template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { float EIGEN_ALIGN16 x[2]; vec_st2f(a.v4f[0], &x[0]); return x[0]; }
+
+template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a)
+{
+ Packet4f rev;
+ rev.v4f[0] = preverse<Packet2d>(a.v4f[1]);
+ rev.v4f[1] = preverse<Packet2d>(a.v4f[0]);
+ return rev;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pabs<Packet4f>(const Packet4f& a)
+{
+ Packet4f res;
+ res.v4f[0] = pabs(a.v4f[0]);
+ res.v4f[1] = pabs(a.v4f[1]);
+ return res;
+}
+
+template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a)
+{
+ Packet2d sum;
+ sum = padd<Packet2d>(a.v4f[0], a.v4f[1]);
+ double first = predux<Packet2d>(sum);
+ return static_cast<float>(first);
+}
+
+template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a)
+{
+ // Return predux_mul<Packet2d> of the subvectors product
+ return static_cast<float>(pfirst(predux_mul(pmul(a.v4f[0], a.v4f[1]))));
+}
+
+template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a)
+{
+ Packet2d b, res;
+ b = pmin<Packet2d>(a.v4f[0], a.v4f[1]);
+ res = pmin<Packet2d>(b, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(b), reinterpret_cast<Packet4i>(b), 8)));
+ return static_cast<float>(pfirst(res));
+}
+
+template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a)
+{
+ Packet2d b, res;
+ b = pmax<Packet2d>(a.v4f[0], a.v4f[1]);
+ res = pmax<Packet2d>(b, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4i>(b), reinterpret_cast<Packet4i>(b), 8)));
+ return static_cast<float>(pfirst(res));
+}
+
+/* Split the Packet4f PacketBlock into 4 Packet2d PacketBlocks and transpose each one
+ */
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet4f,4>& kernel) {
+ PacketBlock<Packet2d,2> t0,t1,t2,t3;
+ // copy top-left 2x2 Packet2d block
+ t0.packet[0] = kernel.packet[0].v4f[0];
+ t0.packet[1] = kernel.packet[1].v4f[0];
+
+ // copy top-right 2x2 Packet2d block
+ t1.packet[0] = kernel.packet[0].v4f[1];
+ t1.packet[1] = kernel.packet[1].v4f[1];
+
+ // copy bottom-left 2x2 Packet2d block
+ t2.packet[0] = kernel.packet[2].v4f[0];
+ t2.packet[1] = kernel.packet[3].v4f[0];
+
+ // copy bottom-right 2x2 Packet2d block
+ t3.packet[0] = kernel.packet[2].v4f[1];
+ t3.packet[1] = kernel.packet[3].v4f[1];
+
+ // Transpose all 2x2 blocks
+ ptranspose(t0);
+ ptranspose(t1);
+ ptranspose(t2);
+ ptranspose(t3);
+
+ // Copy back transposed blocks, but exchange t1 and t2 due to transposition
+ kernel.packet[0].v4f[0] = t0.packet[0];
+ kernel.packet[0].v4f[1] = t2.packet[0];
+ kernel.packet[1].v4f[0] = t0.packet[1];
+ kernel.packet[1].v4f[1] = t2.packet[1];
+ kernel.packet[2].v4f[0] = t1.packet[0];
+ kernel.packet[2].v4f[1] = t3.packet[0];
+ kernel.packet[3].v4f[0] = t1.packet[1];
+ kernel.packet[3].v4f[1] = t3.packet[1];
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, const Packet4f& elsePacket) {
+ Packet2ul select_hi = { ifPacket.select[0], ifPacket.select[1] };
+ Packet2ul select_lo = { ifPacket.select[2], ifPacket.select[3] };
+ Packet2ul mask_hi = vec_cmpeq(select_hi, reinterpret_cast<Packet2ul>(p2l_ONE));
+ Packet2ul mask_lo = vec_cmpeq(select_lo, reinterpret_cast<Packet2ul>(p2l_ONE));
+ Packet4f result;
+ result.v4f[0] = vec_sel(elsePacket.v4f[0], thenPacket.v4f[0], mask_hi);
+ result.v4f[1] = vec_sel(elsePacket.v4f[1], thenPacket.v4f[1], mask_lo);
+ return result;
+}
+
+template<> Packet4f EIGEN_STRONG_INLINE pcmp_le<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f res;
+ res.v4f[0] = pcmp_le(a.v4f[0], b.v4f[0]);
+ res.v4f[1] = pcmp_le(a.v4f[1], b.v4f[1]);
+ return res;
+}
+
+template<> Packet4f EIGEN_STRONG_INLINE pcmp_lt<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f res;
+ res.v4f[0] = pcmp_lt(a.v4f[0], b.v4f[0]);
+ res.v4f[1] = pcmp_lt(a.v4f[1], b.v4f[1]);
+ return res;
+}
+
+template<> Packet4f EIGEN_STRONG_INLINE pcmp_eq<Packet4f>(const Packet4f& a, const Packet4f& b)
+{
+ Packet4f res;
+ res.v4f[0] = pcmp_eq(a.v4f[0], b.v4f[0]);
+ res.v4f[1] = pcmp_eq(a.v4f[1], b.v4f[1]);
+ return res;
+}
+
+#else
+template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from)
+{
+ // FIXME: No intrinsic yet
+ EIGEN_DEBUG_ALIGNED_LOAD
+ Packet *vfrom;
+ vfrom = (Packet *) from;
+ return vfrom->v4f;
+}
+
+template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from)
+{
+ // FIXME: No intrinsic yet
+ EIGEN_DEBUG_ALIGNED_STORE
+ Packet *vto;
+ vto = (Packet *) to;
+ vto->v4f = from;
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from)
+{
+ return vec_splats(from);
+}
+
+template<> EIGEN_STRONG_INLINE void
+pbroadcast4<Packet4f>(const float *a,
+ Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3)
+{
+ a3 = pload<Packet4f>(a);
+ a0 = vec_splat(a3, 0);
+ a1 = vec_splat(a3, 1);
+ a2 = vec_splat(a3, 2);
+ a3 = vec_splat(a3, 3);
+}
+
+template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride)
+{
+ float EIGEN_ALIGN16 af[4];
+ af[0] = from[0*stride];
+ af[1] = from[1*stride];
+ af[2] = from[2*stride];
+ af[3] = from[3*stride];
+ return pload<Packet4f>(af);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride)
+{
+ float EIGEN_ALIGN16 af[4];
+ pstore<float>((float*)af, from);
+ to[0*stride] = af[0];
+ to[1*stride] = af[1];
+ to[2*stride] = af[2];
+ to[3*stride] = af[3];
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a + b); }
+template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a - b); }
+template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a * b); }
+template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) { return (a / b); }
+template<> EIGEN_STRONG_INLINE Packet4f pnegate<Packet4f>(const Packet4f& a) { return (-a); }
+template<> EIGEN_STRONG_INLINE Packet4f pconj<Packet4f> (const Packet4f& a) { return a; }
+template<> EIGEN_STRONG_INLINE Packet4f pmadd<Packet4f> (const Packet4f& a, const Packet4f& b, const Packet4f& c) { return vec_madd(a, b, c); }
+template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_min(a, b); }
+template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_max(a, b); }
+template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_and(a, b); }
+template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_or(a, b); }
+template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f> (const Packet4f& a, const Packet4f& b) { return vec_xor(a, b); }
+template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_and(a, vec_nor(b, b)); }
+template<> EIGEN_STRONG_INLINE Packet4f pround<Packet4f> (const Packet4f& a) { return vec_round(a); }
+template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f> (const Packet4f& a) { return vec_ceil(a); }
+template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f> (const Packet4f& a) { return vec_floor(a); }
+template<> EIGEN_STRONG_INLINE Packet4f pabs<Packet4f> (const Packet4f& a) { return vec_abs(a); }
+template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { float EIGEN_ALIGN16 x[4]; pstore(x, a); return x[0]; }
+
+template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from)
+{
+ Packet4f p = pload<Packet4f>(from);
+ return vec_perm(p, p, p16uc_DUPLICATE32_HI);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a)
+{
+ return reinterpret_cast<Packet4f>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32));
+}
+
+template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a)
+{
+ Packet4f b, sum;
+ b = vec_sld(a, a, 8);
+ sum = padd<Packet4f>(a, b);
+ b = vec_sld(sum, sum, 4);
+ sum = padd<Packet4f>(sum, b);
+ return pfirst(sum);
+}
+
+// Other reduction functions:
+// mul
+template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a)
+{
+ Packet4f prod;
+ prod = pmul(a, vec_sld(a, a, 8));
+ return pfirst(pmul(prod, vec_sld(prod, prod, 4)));
+}
+
+// min
+template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a)
+{
+ Packet4f b, res;
+ b = pmin<Packet4f>(a, vec_sld(a, a, 8));
+ res = pmin<Packet4f>(b, vec_sld(b, b, 4));
+ return pfirst(res);
+}
+
+// max
+template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a)
+{
+ Packet4f b, res;
+ b = pmax<Packet4f>(a, vec_sld(a, a, 8));
+ res = pmax<Packet4f>(b, vec_sld(b, b, 4));
+ return pfirst(res);
+}
+
+EIGEN_DEVICE_FUNC inline void
+ptranspose(PacketBlock<Packet4f,4>& kernel) {
+ Packet4f t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]);
+ Packet4f t1 = vec_mergel(kernel.packet[0], kernel.packet[2]);
+ Packet4f t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]);
+ Packet4f t3 = vec_mergel(kernel.packet[1], kernel.packet[3]);
+ kernel.packet[0] = vec_mergeh(t0, t2);
+ kernel.packet[1] = vec_mergel(t0, t2);
+ kernel.packet[2] = vec_mergeh(t1, t3);
+ kernel.packet[3] = vec_mergel(t1, t3);
+}
+
+template<> EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, const Packet4f& elsePacket) {
+ Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] };
+ Packet4ui mask = vec_cmpeq(select, reinterpret_cast<Packet4ui>(p4i_ONE));
+ return vec_sel(elsePacket, thenPacket, mask);
+}
+
+#endif
+
+template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
+template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f> (const float* from) { return pload<Packet4f>(from); }
+template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) { pstore<float>(to, from); }
+template<> EIGEN_STRONG_INLINE Packet4f plset<Packet4f> (const float& a) { return padd<Packet4f>(pset1<Packet4f>(a), p4f_COUNTDOWN); }
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PACKET_MATH_ZVECTOR_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/functors/AssignmentFunctors.h b/src/3rdparty/eigen/Eigen/src/Core/functors/AssignmentFunctors.h
new file mode 100644
index 000000000..bf64ef4ed
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/functors/AssignmentFunctors.h
@@ -0,0 +1,177 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ASSIGNMENT_FUNCTORS_H
+#define EIGEN_ASSIGNMENT_FUNCTORS_H
+
+namespace Eigen {
+
+namespace internal {
+
+/** \internal
+ * \brief Template functor for scalar/packet assignment
+ *
+ */
+template<typename DstScalar,typename SrcScalar> struct assign_op {
+
+ EIGEN_EMPTY_STRUCT_CTOR(assign_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a = b; }
+
+ template<int Alignment, typename Packet>
+ EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
+ { internal::pstoret<DstScalar,Packet,Alignment>(a,b); }
+};
+
+// Empty overload for void type (used by PermutationMatrix)
+template<typename DstScalar> struct assign_op<DstScalar,void> {};
+
+template<typename DstScalar,typename SrcScalar>
+struct functor_traits<assign_op<DstScalar,SrcScalar> > {
+ enum {
+ Cost = NumTraits<DstScalar>::ReadCost,
+ PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::Vectorizable && packet_traits<SrcScalar>::Vectorizable
+ };
+};
+
+/** \internal
+ * \brief Template functor for scalar/packet assignment with addition
+ *
+ */
+template<typename DstScalar,typename SrcScalar> struct add_assign_op {
+
+ EIGEN_EMPTY_STRUCT_CTOR(add_assign_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a += b; }
+
+ template<int Alignment, typename Packet>
+ EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
+ { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::padd(internal::ploadt<Packet,Alignment>(a),b)); }
+};
+template<typename DstScalar,typename SrcScalar>
+struct functor_traits<add_assign_op<DstScalar,SrcScalar> > {
+ enum {
+ Cost = NumTraits<DstScalar>::ReadCost + NumTraits<DstScalar>::AddCost,
+ PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasAdd
+ };
+};
+
+/** \internal
+ * \brief Template functor for scalar/packet assignment with subtraction
+ *
+ */
+template<typename DstScalar,typename SrcScalar> struct sub_assign_op {
+
+ EIGEN_EMPTY_STRUCT_CTOR(sub_assign_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a -= b; }
+
+ template<int Alignment, typename Packet>
+ EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
+ { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::psub(internal::ploadt<Packet,Alignment>(a),b)); }
+};
+template<typename DstScalar,typename SrcScalar>
+struct functor_traits<sub_assign_op<DstScalar,SrcScalar> > {
+ enum {
+ Cost = NumTraits<DstScalar>::ReadCost + NumTraits<DstScalar>::AddCost,
+ PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasSub
+ };
+};
+
+/** \internal
+ * \brief Template functor for scalar/packet assignment with multiplication
+ *
+ */
+template<typename DstScalar, typename SrcScalar=DstScalar>
+struct mul_assign_op {
+
+ EIGEN_EMPTY_STRUCT_CTOR(mul_assign_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a *= b; }
+
+ template<int Alignment, typename Packet>
+ EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
+ { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::pmul(internal::ploadt<Packet,Alignment>(a),b)); }
+};
+template<typename DstScalar, typename SrcScalar>
+struct functor_traits<mul_assign_op<DstScalar,SrcScalar> > {
+ enum {
+ Cost = NumTraits<DstScalar>::ReadCost + NumTraits<DstScalar>::MulCost,
+ PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasMul
+ };
+};
+
+/** \internal
+ * \brief Template functor for scalar/packet assignment with diviving
+ *
+ */
+template<typename DstScalar, typename SrcScalar=DstScalar> struct div_assign_op {
+
+ EIGEN_EMPTY_STRUCT_CTOR(div_assign_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a /= b; }
+
+ template<int Alignment, typename Packet>
+ EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
+ { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::pdiv(internal::ploadt<Packet,Alignment>(a),b)); }
+};
+template<typename DstScalar, typename SrcScalar>
+struct functor_traits<div_assign_op<DstScalar,SrcScalar> > {
+ enum {
+ Cost = NumTraits<DstScalar>::ReadCost + NumTraits<DstScalar>::MulCost,
+ PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasDiv
+ };
+};
+
+/** \internal
+ * \brief Template functor for scalar/packet assignment with swapping
+ *
+ * It works as follow. For a non-vectorized evaluation loop, we have:
+ * for(i) func(A.coeffRef(i), B.coeff(i));
+ * where B is a SwapWrapper expression. The trick is to make SwapWrapper::coeff behaves like a non-const coeffRef.
+ * Actually, SwapWrapper might not even be needed since even if B is a plain expression, since it has to be writable
+ * B.coeff already returns a const reference to the underlying scalar value.
+ *
+ * The case of a vectorized loop is more tricky:
+ * for(i,j) func.assignPacket<A_Align>(&A.coeffRef(i,j), B.packet<B_Align>(i,j));
+ * Here, B must be a SwapWrapper whose packet function actually returns a proxy object holding a Scalar*,
+ * the actual alignment and Packet type.
+ *
+ */
+template<typename Scalar> struct swap_assign_op {
+
+ EIGEN_EMPTY_STRUCT_CTOR(swap_assign_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Scalar& a, const Scalar& b) const
+ {
+#ifdef EIGEN_GPUCC
+ // FIXME is there some kind of cuda::swap?
+ Scalar t=b; const_cast<Scalar&>(b)=a; a=t;
+#else
+ using std::swap;
+ swap(a,const_cast<Scalar&>(b));
+#endif
+ }
+};
+template<typename Scalar>
+struct functor_traits<swap_assign_op<Scalar> > {
+ enum {
+ Cost = 3 * NumTraits<Scalar>::ReadCost,
+ PacketAccess =
+ #if defined(EIGEN_VECTORIZE_AVX) && EIGEN_COMP_CLANG && (EIGEN_COMP_CLANG<800 || defined(__apple_build_version__))
+ // This is a partial workaround for a bug in clang generating bad code
+ // when mixing 256/512 bits loads and 128 bits moves.
+ // See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1684
+ // https://bugs.llvm.org/show_bug.cgi?id=40815
+ 0
+ #else
+ packet_traits<Scalar>::Vectorizable
+ #endif
+ };
+};
+
+} // namespace internal
+
+} // namespace Eigen
+
+#endif // EIGEN_ASSIGNMENT_FUNCTORS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/functors/BinaryFunctors.h b/src/3rdparty/eigen/Eigen/src/Core/functors/BinaryFunctors.h
new file mode 100644
index 000000000..63f09ab93
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/functors/BinaryFunctors.h
@@ -0,0 +1,541 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_BINARY_FUNCTORS_H
+#define EIGEN_BINARY_FUNCTORS_H
+
+namespace Eigen {
+
+namespace internal {
+
+//---------- associative binary functors ----------
+
+template<typename Arg1, typename Arg2>
+struct binary_op_base
+{
+ typedef Arg1 first_argument_type;
+ typedef Arg2 second_argument_type;
+};
+
+/** \internal
+ * \brief Template functor to compute the sum of two scalars
+ *
+ * \sa class CwiseBinaryOp, MatrixBase::operator+, class VectorwiseOp, DenseBase::sum()
+ */
+template<typename LhsScalar,typename RhsScalar>
+struct scalar_sum_op : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_sum_op>::ReturnType result_type;
+#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_sum_op)
+#else
+ scalar_sum_op() {
+ EIGEN_SCALAR_BINARY_OP_PLUGIN
+ }
+#endif
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a + b; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const
+ { return internal::padd(a,b); }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type predux(const Packet& a) const
+ { return internal::predux(a); }
+};
+template<typename LhsScalar,typename RhsScalar>
+struct functor_traits<scalar_sum_op<LhsScalar,RhsScalar> > {
+ enum {
+ Cost = (int(NumTraits<LhsScalar>::AddCost) + int(NumTraits<RhsScalar>::AddCost)) / 2, // rough estimate!
+ PacketAccess = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasAdd && packet_traits<RhsScalar>::HasAdd
+ // TODO vectorize mixed sum
+ };
+};
+
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool scalar_sum_op<bool,bool>::operator() (const bool& a, const bool& b) const { return a || b; }
+
+
+/** \internal
+ * \brief Template functor to compute the product of two scalars
+ *
+ * \sa class CwiseBinaryOp, Cwise::operator*(), class VectorwiseOp, MatrixBase::redux()
+ */
+template<typename LhsScalar,typename RhsScalar>
+struct scalar_product_op : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_product_op>::ReturnType result_type;
+#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_product_op)
+#else
+ scalar_product_op() {
+ EIGEN_SCALAR_BINARY_OP_PLUGIN
+ }
+#endif
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a * b; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const
+ { return internal::pmul(a,b); }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type predux(const Packet& a) const
+ { return internal::predux_mul(a); }
+};
+template<typename LhsScalar,typename RhsScalar>
+struct functor_traits<scalar_product_op<LhsScalar,RhsScalar> > {
+ enum {
+ Cost = (int(NumTraits<LhsScalar>::MulCost) + int(NumTraits<RhsScalar>::MulCost))/2, // rough estimate!
+ PacketAccess = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasMul && packet_traits<RhsScalar>::HasMul
+ // TODO vectorize mixed product
+ };
+};
+
+template<>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool scalar_product_op<bool,bool>::operator() (const bool& a, const bool& b) const { return a && b; }
+
+
+/** \internal
+ * \brief Template functor to compute the conjugate product of two scalars
+ *
+ * This is a short cut for conj(x) * y which is needed for optimization purpose; in Eigen2 support mode, this becomes x * conj(y)
+ */
+template<typename LhsScalar,typename RhsScalar>
+struct scalar_conj_product_op : binary_op_base<LhsScalar,RhsScalar>
+{
+
+ enum {
+ Conj = NumTraits<LhsScalar>::IsComplex
+ };
+
+ typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_conj_product_op>::ReturnType result_type;
+
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_conj_product_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const LhsScalar& a, const RhsScalar& b) const
+ { return conj_helper<LhsScalar,RhsScalar,Conj,false>().pmul(a,b); }
+
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const
+ { return conj_helper<Packet,Packet,Conj,false>().pmul(a,b); }
+};
+template<typename LhsScalar,typename RhsScalar>
+struct functor_traits<scalar_conj_product_op<LhsScalar,RhsScalar> > {
+ enum {
+ Cost = NumTraits<LhsScalar>::MulCost,
+ PacketAccess = internal::is_same<LhsScalar, RhsScalar>::value && packet_traits<LhsScalar>::HasMul
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the min of two scalars
+ *
+ * \sa class CwiseBinaryOp, MatrixBase::cwiseMin, class VectorwiseOp, MatrixBase::minCoeff()
+ */
+template<typename LhsScalar,typename RhsScalar, int NaNPropagation>
+struct scalar_min_op : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_min_op>::ReturnType result_type;
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_min_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const LhsScalar& a, const RhsScalar& b) const {
+ return internal::pmin<NaNPropagation>(a, b);
+ }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const
+ {
+ return internal::pmin<NaNPropagation>(a,b);
+ }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type predux(const Packet& a) const
+ {
+ return internal::predux_min<NaNPropagation>(a);
+ }
+};
+
+template<typename LhsScalar,typename RhsScalar, int NaNPropagation>
+struct functor_traits<scalar_min_op<LhsScalar,RhsScalar, NaNPropagation> > {
+ enum {
+ Cost = (NumTraits<LhsScalar>::AddCost+NumTraits<RhsScalar>::AddCost)/2,
+ PacketAccess = internal::is_same<LhsScalar, RhsScalar>::value && packet_traits<LhsScalar>::HasMin
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the max of two scalars
+ *
+ * \sa class CwiseBinaryOp, MatrixBase::cwiseMax, class VectorwiseOp, MatrixBase::maxCoeff()
+ */
+template<typename LhsScalar,typename RhsScalar, int NaNPropagation>
+struct scalar_max_op : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_max_op>::ReturnType result_type;
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_max_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const LhsScalar& a, const RhsScalar& b) const {
+ return internal::pmax<NaNPropagation>(a,b);
+ }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const
+ {
+ return internal::pmax<NaNPropagation>(a,b);
+ }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type predux(const Packet& a) const
+ {
+ return internal::predux_max<NaNPropagation>(a);
+ }
+};
+
+template<typename LhsScalar,typename RhsScalar, int NaNPropagation>
+struct functor_traits<scalar_max_op<LhsScalar,RhsScalar, NaNPropagation> > {
+ enum {
+ Cost = (NumTraits<LhsScalar>::AddCost+NumTraits<RhsScalar>::AddCost)/2,
+ PacketAccess = internal::is_same<LhsScalar, RhsScalar>::value && packet_traits<LhsScalar>::HasMax
+ };
+};
+
+/** \internal
+ * \brief Template functors for comparison of two scalars
+ * \todo Implement packet-comparisons
+ */
+template<typename LhsScalar, typename RhsScalar, ComparisonName cmp> struct scalar_cmp_op;
+
+template<typename LhsScalar, typename RhsScalar, ComparisonName cmp>
+struct functor_traits<scalar_cmp_op<LhsScalar,RhsScalar, cmp> > {
+ enum {
+ Cost = (NumTraits<LhsScalar>::AddCost+NumTraits<RhsScalar>::AddCost)/2,
+ PacketAccess = false
+ };
+};
+
+template<ComparisonName Cmp, typename LhsScalar, typename RhsScalar>
+struct result_of<scalar_cmp_op<LhsScalar, RhsScalar, Cmp>(LhsScalar,RhsScalar)> {
+ typedef bool type;
+};
+
+
+template<typename LhsScalar, typename RhsScalar>
+struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_EQ> : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef bool result_type;
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a==b;}
+};
+template<typename LhsScalar, typename RhsScalar>
+struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_LT> : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef bool result_type;
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a<b;}
+};
+template<typename LhsScalar, typename RhsScalar>
+struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_LE> : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef bool result_type;
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a<=b;}
+};
+template<typename LhsScalar, typename RhsScalar>
+struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_GT> : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef bool result_type;
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a>b;}
+};
+template<typename LhsScalar, typename RhsScalar>
+struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_GE> : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef bool result_type;
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a>=b;}
+};
+template<typename LhsScalar, typename RhsScalar>
+struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_UNORD> : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef bool result_type;
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return !(a<=b || b<=a);}
+};
+template<typename LhsScalar, typename RhsScalar>
+struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_NEQ> : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef bool result_type;
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a!=b;}
+};
+
+/** \internal
+ * \brief Template functor to compute the hypot of two \b positive \b and \b real scalars
+ *
+ * \sa MatrixBase::stableNorm(), class Redux
+ */
+template<typename Scalar>
+struct scalar_hypot_op<Scalar,Scalar> : binary_op_base<Scalar,Scalar>
+{
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_hypot_op)
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar &x, const Scalar &y) const
+ {
+ // This functor is used by hypotNorm only for which it is faster to first apply abs
+ // on all coefficients prior to reduction through hypot.
+ // This way we avoid calling abs on positive and real entries, and this also permits
+ // to seamlessly handle complexes. Otherwise we would have to handle both real and complexes
+ // through the same functor...
+ return internal::positive_real_hypot(x,y);
+ }
+};
+template<typename Scalar>
+struct functor_traits<scalar_hypot_op<Scalar,Scalar> > {
+ enum
+ {
+ Cost = 3 * NumTraits<Scalar>::AddCost +
+ 2 * NumTraits<Scalar>::MulCost +
+ 2 * scalar_div_cost<Scalar,false>::value,
+ PacketAccess = false
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the pow of two scalars
+ * See the specification of pow in https://en.cppreference.com/w/cpp/numeric/math/pow
+ */
+template<typename Scalar, typename Exponent>
+struct scalar_pow_op : binary_op_base<Scalar,Exponent>
+{
+ typedef typename ScalarBinaryOpTraits<Scalar,Exponent,scalar_pow_op>::ReturnType result_type;
+#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_pow_op)
+#else
+ scalar_pow_op() {
+ typedef Scalar LhsScalar;
+ typedef Exponent RhsScalar;
+ EIGEN_SCALAR_BINARY_OP_PLUGIN
+ }
+#endif
+
+ EIGEN_DEVICE_FUNC
+ inline result_type operator() (const Scalar& a, const Exponent& b) const { return numext::pow(a, b); }
+
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
+ {
+ return generic_pow(a,b);
+ }
+};
+
+template<typename Scalar, typename Exponent>
+struct functor_traits<scalar_pow_op<Scalar,Exponent> > {
+ enum {
+ Cost = 5 * NumTraits<Scalar>::MulCost,
+ PacketAccess = (!NumTraits<Scalar>::IsComplex && !NumTraits<Scalar>::IsInteger &&
+ packet_traits<Scalar>::HasExp && packet_traits<Scalar>::HasLog &&
+ packet_traits<Scalar>::HasRound && packet_traits<Scalar>::HasCmp &&
+ // Temporarly disable packet access for half/bfloat16 until
+ // accuracy is improved.
+ !is_same<Scalar, half>::value && !is_same<Scalar, bfloat16>::value
+ )
+ };
+};
+
+//---------- non associative binary functors ----------
+
+/** \internal
+ * \brief Template functor to compute the difference of two scalars
+ *
+ * \sa class CwiseBinaryOp, MatrixBase::operator-
+ */
+template<typename LhsScalar,typename RhsScalar>
+struct scalar_difference_op : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_difference_op>::ReturnType result_type;
+#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_difference_op)
+#else
+ scalar_difference_op() {
+ EIGEN_SCALAR_BINARY_OP_PLUGIN
+ }
+#endif
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a - b; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
+ { return internal::psub(a,b); }
+};
+template<typename LhsScalar,typename RhsScalar>
+struct functor_traits<scalar_difference_op<LhsScalar,RhsScalar> > {
+ enum {
+ Cost = (int(NumTraits<LhsScalar>::AddCost) + int(NumTraits<RhsScalar>::AddCost)) / 2,
+ PacketAccess = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasSub && packet_traits<RhsScalar>::HasSub
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the quotient of two scalars
+ *
+ * \sa class CwiseBinaryOp, Cwise::operator/()
+ */
+template<typename LhsScalar,typename RhsScalar>
+struct scalar_quotient_op : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_quotient_op>::ReturnType result_type;
+#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_quotient_op)
+#else
+ scalar_quotient_op() {
+ EIGEN_SCALAR_BINARY_OP_PLUGIN
+ }
+#endif
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a / b; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
+ { return internal::pdiv(a,b); }
+};
+template<typename LhsScalar,typename RhsScalar>
+struct functor_traits<scalar_quotient_op<LhsScalar,RhsScalar> > {
+ typedef typename scalar_quotient_op<LhsScalar,RhsScalar>::result_type result_type;
+ enum {
+ PacketAccess = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasDiv && packet_traits<RhsScalar>::HasDiv,
+ Cost = scalar_div_cost<result_type,PacketAccess>::value
+ };
+};
+
+
+
+/** \internal
+ * \brief Template functor to compute the and of two booleans
+ *
+ * \sa class CwiseBinaryOp, ArrayBase::operator&&
+ */
+struct scalar_boolean_and_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_boolean_and_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a, const bool& b) const { return a && b; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
+ { return internal::pand(a,b); }
+};
+template<> struct functor_traits<scalar_boolean_and_op> {
+ enum {
+ Cost = NumTraits<bool>::AddCost,
+ PacketAccess = true
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the or of two booleans
+ *
+ * \sa class CwiseBinaryOp, ArrayBase::operator||
+ */
+struct scalar_boolean_or_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_boolean_or_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a, const bool& b) const { return a || b; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
+ { return internal::por(a,b); }
+};
+template<> struct functor_traits<scalar_boolean_or_op> {
+ enum {
+ Cost = NumTraits<bool>::AddCost,
+ PacketAccess = true
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the xor of two booleans
+ *
+ * \sa class CwiseBinaryOp, ArrayBase::operator^
+ */
+struct scalar_boolean_xor_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_boolean_xor_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a, const bool& b) const { return a ^ b; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
+ { return internal::pxor(a,b); }
+};
+template<> struct functor_traits<scalar_boolean_xor_op> {
+ enum {
+ Cost = NumTraits<bool>::AddCost,
+ PacketAccess = true
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the absolute difference of two scalars
+ *
+ * \sa class CwiseBinaryOp, MatrixBase::absolute_difference
+ */
+template<typename LhsScalar,typename RhsScalar>
+struct scalar_absolute_difference_op : binary_op_base<LhsScalar,RhsScalar>
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar,scalar_absolute_difference_op>::ReturnType result_type;
+#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_absolute_difference_op)
+#else
+ scalar_absolute_difference_op() {
+ EIGEN_SCALAR_BINARY_OP_PLUGIN
+ }
+#endif
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const
+ { return numext::absdiff(a,b); }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
+ { return internal::pabsdiff(a,b); }
+};
+template<typename LhsScalar,typename RhsScalar>
+struct functor_traits<scalar_absolute_difference_op<LhsScalar,RhsScalar> > {
+ enum {
+ Cost = (NumTraits<LhsScalar>::AddCost+NumTraits<RhsScalar>::AddCost)/2,
+ PacketAccess = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasAbsDiff
+ };
+};
+
+
+
+//---------- binary functors bound to a constant, thus appearing as a unary functor ----------
+
+// The following two classes permits to turn any binary functor into a unary one with one argument bound to a constant value.
+// They are analogues to std::binder1st/binder2nd but with the following differences:
+// - they are compatible with packetOp
+// - they are portable across C++ versions (the std::binder* are deprecated in C++11)
+template<typename BinaryOp> struct bind1st_op : BinaryOp {
+
+ typedef typename BinaryOp::first_argument_type first_argument_type;
+ typedef typename BinaryOp::second_argument_type second_argument_type;
+ typedef typename BinaryOp::result_type result_type;
+
+ EIGEN_DEVICE_FUNC explicit bind1st_op(const first_argument_type &val) : m_value(val) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const second_argument_type& b) const { return BinaryOp::operator()(m_value,b); }
+
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& b) const
+ { return BinaryOp::packetOp(internal::pset1<Packet>(m_value), b); }
+
+ first_argument_type m_value;
+};
+template<typename BinaryOp> struct functor_traits<bind1st_op<BinaryOp> > : functor_traits<BinaryOp> {};
+
+
+template<typename BinaryOp> struct bind2nd_op : BinaryOp {
+
+ typedef typename BinaryOp::first_argument_type first_argument_type;
+ typedef typename BinaryOp::second_argument_type second_argument_type;
+ typedef typename BinaryOp::result_type result_type;
+
+ EIGEN_DEVICE_FUNC explicit bind2nd_op(const second_argument_type &val) : m_value(val) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const first_argument_type& a) const { return BinaryOp::operator()(a,m_value); }
+
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
+ { return BinaryOp::packetOp(a,internal::pset1<Packet>(m_value)); }
+
+ second_argument_type m_value;
+};
+template<typename BinaryOp> struct functor_traits<bind2nd_op<BinaryOp> > : functor_traits<BinaryOp> {};
+
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_BINARY_FUNCTORS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/functors/NullaryFunctors.h b/src/3rdparty/eigen/Eigen/src/Core/functors/NullaryFunctors.h
new file mode 100644
index 000000000..192f225dd
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/functors/NullaryFunctors.h
@@ -0,0 +1,189 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_NULLARY_FUNCTORS_H
+#define EIGEN_NULLARY_FUNCTORS_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Scalar>
+struct scalar_constant_op {
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_constant_op(const scalar_constant_op& other) : m_other(other.m_other) { }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_constant_op(const Scalar& other) : m_other(other) { }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const { return m_other; }
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const PacketType packetOp() const { return internal::pset1<PacketType>(m_other); }
+ const Scalar m_other;
+};
+template<typename Scalar>
+struct functor_traits<scalar_constant_op<Scalar> >
+{ enum { Cost = 0 /* as the constant value should be loaded in register only once for the whole expression */,
+ PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = true }; };
+
+template<typename Scalar> struct scalar_identity_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_identity_op)
+ template<typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (IndexType row, IndexType col) const { return row==col ? Scalar(1) : Scalar(0); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_identity_op<Scalar> >
+{ enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = false, IsRepeatable = true }; };
+
+template <typename Scalar, bool IsInteger> struct linspaced_op_impl;
+
+template <typename Scalar>
+struct linspaced_op_impl<Scalar,/*IsInteger*/false>
+{
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ EIGEN_DEVICE_FUNC linspaced_op_impl(const Scalar& low, const Scalar& high, Index num_steps) :
+ m_low(low), m_high(high), m_size1(num_steps==1 ? 1 : num_steps-1), m_step(num_steps==1 ? Scalar() : Scalar((high-low)/RealScalar(num_steps-1))),
+ m_flip(numext::abs(high)<numext::abs(low))
+ {}
+
+ template<typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (IndexType i) const {
+ if(m_flip)
+ return (i==0)? m_low : Scalar(m_high - RealScalar(m_size1-i)*m_step);
+ else
+ return (i==m_size1)? m_high : Scalar(m_low + RealScalar(i)*m_step);
+ }
+
+ template<typename Packet, typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(IndexType i) const
+ {
+ // Principle:
+ // [low, ..., low] + ( [step, ..., step] * ( [i, ..., i] + [0, ..., size] ) )
+ if(m_flip)
+ {
+ Packet pi = plset<Packet>(Scalar(i-m_size1));
+ Packet res = padd(pset1<Packet>(m_high), pmul(pset1<Packet>(m_step), pi));
+ if (EIGEN_PREDICT_TRUE(i != 0)) return res;
+ Packet mask = pcmp_lt(pset1<Packet>(0), plset<Packet>(0));
+ return pselect<Packet>(mask, res, pset1<Packet>(m_low));
+ }
+ else
+ {
+ Packet pi = plset<Packet>(Scalar(i));
+ Packet res = padd(pset1<Packet>(m_low), pmul(pset1<Packet>(m_step), pi));
+ if(EIGEN_PREDICT_TRUE(i != m_size1-unpacket_traits<Packet>::size+1)) return res;
+ Packet mask = pcmp_lt(plset<Packet>(0), pset1<Packet>(unpacket_traits<Packet>::size-1));
+ return pselect<Packet>(mask, res, pset1<Packet>(m_high));
+ }
+ }
+
+ const Scalar m_low;
+ const Scalar m_high;
+ const Index m_size1;
+ const Scalar m_step;
+ const bool m_flip;
+};
+
+template <typename Scalar>
+struct linspaced_op_impl<Scalar,/*IsInteger*/true>
+{
+ EIGEN_DEVICE_FUNC linspaced_op_impl(const Scalar& low, const Scalar& high, Index num_steps) :
+ m_low(low),
+ m_multiplier((high-low)/convert_index<Scalar>(num_steps<=1 ? 1 : num_steps-1)),
+ m_divisor(convert_index<Scalar>((high>=low?num_steps:-num_steps)+(high-low))/((numext::abs(high-low)+1)==0?1:(numext::abs(high-low)+1))),
+ m_use_divisor(num_steps>1 && (numext::abs(high-low)+1)<num_steps)
+ {}
+
+ template<typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ const Scalar operator() (IndexType i) const
+ {
+ if(m_use_divisor) return m_low + convert_index<Scalar>(i)/m_divisor;
+ else return m_low + convert_index<Scalar>(i)*m_multiplier;
+ }
+
+ const Scalar m_low;
+ const Scalar m_multiplier;
+ const Scalar m_divisor;
+ const bool m_use_divisor;
+};
+
+// ----- Linspace functor ----------------------------------------------------------------
+
+// Forward declaration (we default to random access which does not really give
+// us a speed gain when using packet access but it allows to use the functor in
+// nested expressions).
+template <typename Scalar> struct linspaced_op;
+template <typename Scalar> struct functor_traits< linspaced_op<Scalar> >
+{
+ enum
+ {
+ Cost = 1,
+ PacketAccess = (!NumTraits<Scalar>::IsInteger) && packet_traits<Scalar>::HasSetLinear && packet_traits<Scalar>::HasBlend,
+ /*&& ((!NumTraits<Scalar>::IsInteger) || packet_traits<Scalar>::HasDiv),*/ // <- vectorization for integer is currently disabled
+ IsRepeatable = true
+ };
+};
+template <typename Scalar> struct linspaced_op
+{
+ EIGEN_DEVICE_FUNC linspaced_op(const Scalar& low, const Scalar& high, Index num_steps)
+ : impl((num_steps==1 ? high : low),high,num_steps)
+ {}
+
+ template<typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (IndexType i) const { return impl(i); }
+
+ template<typename Packet,typename IndexType>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(IndexType i) const { return impl.template packetOp<Packet>(i); }
+
+ // This proxy object handles the actual required temporaries and the different
+ // implementations (integer vs. floating point).
+ const linspaced_op_impl<Scalar,NumTraits<Scalar>::IsInteger> impl;
+};
+
+// Linear access is automatically determined from the operator() prototypes available for the given functor.
+// If it exposes an operator()(i,j), then we assume the i and j coefficients are required independently
+// and linear access is not possible. In all other cases, linear access is enabled.
+// Users should not have to deal with this structure.
+template<typename Functor> struct functor_has_linear_access { enum { ret = !has_binary_operator<Functor>::value }; };
+
+// For unreliable compilers, let's specialize the has_*ary_operator
+// helpers so that at least built-in nullary functors work fine.
+#if !( (EIGEN_COMP_MSVC>1600) || (EIGEN_GNUC_AT_LEAST(4,8)) || (EIGEN_COMP_ICC>=1600))
+template<typename Scalar,typename IndexType>
+struct has_nullary_operator<scalar_constant_op<Scalar>,IndexType> { enum { value = 1}; };
+template<typename Scalar,typename IndexType>
+struct has_unary_operator<scalar_constant_op<Scalar>,IndexType> { enum { value = 0}; };
+template<typename Scalar,typename IndexType>
+struct has_binary_operator<scalar_constant_op<Scalar>,IndexType> { enum { value = 0}; };
+
+template<typename Scalar,typename IndexType>
+struct has_nullary_operator<scalar_identity_op<Scalar>,IndexType> { enum { value = 0}; };
+template<typename Scalar,typename IndexType>
+struct has_unary_operator<scalar_identity_op<Scalar>,IndexType> { enum { value = 0}; };
+template<typename Scalar,typename IndexType>
+struct has_binary_operator<scalar_identity_op<Scalar>,IndexType> { enum { value = 1}; };
+
+template<typename Scalar,typename IndexType>
+struct has_nullary_operator<linspaced_op<Scalar>,IndexType> { enum { value = 0}; };
+template<typename Scalar,typename IndexType>
+struct has_unary_operator<linspaced_op<Scalar>,IndexType> { enum { value = 1}; };
+template<typename Scalar,typename IndexType>
+struct has_binary_operator<linspaced_op<Scalar>,IndexType> { enum { value = 0}; };
+
+template<typename Scalar,typename IndexType>
+struct has_nullary_operator<scalar_random_op<Scalar>,IndexType> { enum { value = 1}; };
+template<typename Scalar,typename IndexType>
+struct has_unary_operator<scalar_random_op<Scalar>,IndexType> { enum { value = 0}; };
+template<typename Scalar,typename IndexType>
+struct has_binary_operator<scalar_random_op<Scalar>,IndexType> { enum { value = 0}; };
+#endif
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_NULLARY_FUNCTORS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/functors/StlFunctors.h b/src/3rdparty/eigen/Eigen/src/Core/functors/StlFunctors.h
new file mode 100644
index 000000000..4570c9b63
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/functors/StlFunctors.h
@@ -0,0 +1,166 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_STL_FUNCTORS_H
+#define EIGEN_STL_FUNCTORS_H
+
+namespace Eigen {
+
+// Portable replacements for certain functors.
+namespace numext {
+
+template<typename T = void>
+struct equal_to {
+ typedef bool result_type;
+ EIGEN_DEVICE_FUNC bool operator()(const T& lhs, const T& rhs) const {
+ return lhs == rhs;
+ }
+};
+
+template<typename T = void>
+struct not_equal_to {
+ typedef bool result_type;
+ EIGEN_DEVICE_FUNC bool operator()(const T& lhs, const T& rhs) const {
+ return lhs != rhs;
+ }
+};
+
+}
+
+
+namespace internal {
+
+// default functor traits for STL functors:
+
+template<typename T>
+struct functor_traits<std::multiplies<T> >
+{ enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::divides<T> >
+{ enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::plus<T> >
+{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::minus<T> >
+{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::negate<T> >
+{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::logical_or<T> >
+{ enum { Cost = 1, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::logical_and<T> >
+{ enum { Cost = 1, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::logical_not<T> >
+{ enum { Cost = 1, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::greater<T> >
+{ enum { Cost = 1, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::less<T> >
+{ enum { Cost = 1, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::greater_equal<T> >
+{ enum { Cost = 1, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::less_equal<T> >
+{ enum { Cost = 1, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::equal_to<T> >
+{ enum { Cost = 1, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<numext::equal_to<T> >
+ : functor_traits<std::equal_to<T> > {};
+
+template<typename T>
+struct functor_traits<std::not_equal_to<T> >
+{ enum { Cost = 1, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<numext::not_equal_to<T> >
+ : functor_traits<std::not_equal_to<T> > {};
+
+#if (EIGEN_COMP_CXXVER < 11)
+// std::binder* are deprecated since c++11 and will be removed in c++17
+template<typename T>
+struct functor_traits<std::binder2nd<T> >
+{ enum { Cost = functor_traits<T>::Cost, PacketAccess = false }; };
+
+template<typename T>
+struct functor_traits<std::binder1st<T> >
+{ enum { Cost = functor_traits<T>::Cost, PacketAccess = false }; };
+#endif
+
+#if (EIGEN_COMP_CXXVER < 17)
+// std::unary_negate is deprecated since c++17 and will be removed in c++20
+template<typename T>
+struct functor_traits<std::unary_negate<T> >
+{ enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; };
+
+// std::binary_negate is deprecated since c++17 and will be removed in c++20
+template<typename T>
+struct functor_traits<std::binary_negate<T> >
+{ enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; };
+#endif
+
+#ifdef EIGEN_STDEXT_SUPPORT
+
+template<typename T0,typename T1>
+struct functor_traits<std::project1st<T0,T1> >
+{ enum { Cost = 0, PacketAccess = false }; };
+
+template<typename T0,typename T1>
+struct functor_traits<std::project2nd<T0,T1> >
+{ enum { Cost = 0, PacketAccess = false }; };
+
+template<typename T0,typename T1>
+struct functor_traits<std::select2nd<std::pair<T0,T1> > >
+{ enum { Cost = 0, PacketAccess = false }; };
+
+template<typename T0,typename T1>
+struct functor_traits<std::select1st<std::pair<T0,T1> > >
+{ enum { Cost = 0, PacketAccess = false }; };
+
+template<typename T0,typename T1>
+struct functor_traits<std::unary_compose<T0,T1> >
+{ enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost, PacketAccess = false }; };
+
+template<typename T0,typename T1,typename T2>
+struct functor_traits<std::binary_compose<T0,T1,T2> >
+{ enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost + functor_traits<T2>::Cost, PacketAccess = false }; };
+
+#endif // EIGEN_STDEXT_SUPPORT
+
+// allow to add new functors and specializations of functor_traits from outside Eigen.
+// this macro is really needed because functor_traits must be specialized after it is declared but before it is used...
+#ifdef EIGEN_FUNCTORS_PLUGIN
+#include EIGEN_FUNCTORS_PLUGIN
+#endif
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_STL_FUNCTORS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/functors/TernaryFunctors.h b/src/3rdparty/eigen/Eigen/src/Core/functors/TernaryFunctors.h
new file mode 100644
index 000000000..b254e96c6
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/functors/TernaryFunctors.h
@@ -0,0 +1,25 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TERNARY_FUNCTORS_H
+#define EIGEN_TERNARY_FUNCTORS_H
+
+namespace Eigen {
+
+namespace internal {
+
+//---------- associative ternary functors ----------
+
+
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TERNARY_FUNCTORS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/functors/UnaryFunctors.h b/src/3rdparty/eigen/Eigen/src/Core/functors/UnaryFunctors.h
new file mode 100644
index 000000000..16136d185
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/functors/UnaryFunctors.h
@@ -0,0 +1,1131 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_UNARY_FUNCTORS_H
+#define EIGEN_UNARY_FUNCTORS_H
+
+namespace Eigen {
+
+namespace internal {
+
+/** \internal
+ * \brief Template functor to compute the opposite of a scalar
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::operator-
+ */
+template<typename Scalar> struct scalar_opposite_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_opposite_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return -a; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
+ { return internal::pnegate(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_opposite_op<Scalar> >
+{ enum {
+ Cost = NumTraits<Scalar>::AddCost,
+ PacketAccess = packet_traits<Scalar>::HasNegate };
+};
+
+/** \internal
+ * \brief Template functor to compute the absolute value of a scalar
+ *
+ * \sa class CwiseUnaryOp, Cwise::abs
+ */
+template<typename Scalar> struct scalar_abs_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_abs_op)
+ typedef typename NumTraits<Scalar>::Real result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return numext::abs(a); }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
+ { return internal::pabs(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_abs_op<Scalar> >
+{
+ enum {
+ Cost = NumTraits<Scalar>::AddCost,
+ PacketAccess = packet_traits<Scalar>::HasAbs
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the score of a scalar, to chose a pivot
+ *
+ * \sa class CwiseUnaryOp
+ */
+template<typename Scalar> struct scalar_score_coeff_op : scalar_abs_op<Scalar>
+{
+ typedef void Score_is_abs;
+};
+template<typename Scalar>
+struct functor_traits<scalar_score_coeff_op<Scalar> > : functor_traits<scalar_abs_op<Scalar> > {};
+
+/* Avoid recomputing abs when we know the score and they are the same. Not a true Eigen functor. */
+template<typename Scalar, typename=void> struct abs_knowing_score
+{
+ EIGEN_EMPTY_STRUCT_CTOR(abs_knowing_score)
+ typedef typename NumTraits<Scalar>::Real result_type;
+ template<typename Score>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a, const Score&) const { return numext::abs(a); }
+};
+template<typename Scalar> struct abs_knowing_score<Scalar, typename scalar_score_coeff_op<Scalar>::Score_is_abs>
+{
+ EIGEN_EMPTY_STRUCT_CTOR(abs_knowing_score)
+ typedef typename NumTraits<Scalar>::Real result_type;
+ template<typename Scal>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scal&, const result_type& a) const { return a; }
+};
+
+/** \internal
+ * \brief Template functor to compute the squared absolute value of a scalar
+ *
+ * \sa class CwiseUnaryOp, Cwise::abs2
+ */
+template<typename Scalar> struct scalar_abs2_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_abs2_op)
+ typedef typename NumTraits<Scalar>::Real result_type;
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return numext::abs2(a); }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
+ { return internal::pmul(a,a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_abs2_op<Scalar> >
+{ enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasAbs2 }; };
+
+/** \internal
+ * \brief Template functor to compute the conjugate of a complex value
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::conjugate()
+ */
+template<typename Scalar> struct scalar_conjugate_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_conjugate_op)
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::conj(a); }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const { return internal::pconj(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_conjugate_op<Scalar> >
+{
+ enum {
+ Cost = 0,
+ // Yes the cost is zero even for complexes because in most cases for which
+ // the cost is used, conjugation turns to be a no-op. Some examples:
+ // cost(a*conj(b)) == cost(a*b)
+ // cost(a+conj(b)) == cost(a+b)
+ // <etc.
+ // If we don't set it to zero, then:
+ // A.conjugate().lazyProduct(B.conjugate())
+ // will bake its operands. We definitely don't want that!
+ PacketAccess = packet_traits<Scalar>::HasConj
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the phase angle of a complex
+ *
+ * \sa class CwiseUnaryOp, Cwise::arg
+ */
+template<typename Scalar> struct scalar_arg_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_arg_op)
+ typedef typename NumTraits<Scalar>::Real result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return numext::arg(a); }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
+ { return internal::parg(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_arg_op<Scalar> >
+{
+ enum {
+ Cost = NumTraits<Scalar>::IsComplex ? 5 * NumTraits<Scalar>::MulCost : NumTraits<Scalar>::AddCost,
+ PacketAccess = packet_traits<Scalar>::HasArg
+ };
+};
+/** \internal
+ * \brief Template functor to cast a scalar to another type
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::cast()
+ */
+template<typename Scalar, typename NewType>
+struct scalar_cast_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
+ typedef NewType result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const NewType operator() (const Scalar& a) const { return cast<Scalar, NewType>(a); }
+};
+template<typename Scalar, typename NewType>
+struct functor_traits<scalar_cast_op<Scalar,NewType> >
+{ enum { Cost = is_same<Scalar, NewType>::value ? 0 : NumTraits<NewType>::AddCost, PacketAccess = false }; };
+
+/** \internal
+ * \brief Template functor to arithmetically shift a scalar right by a number of bits
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::shift_right()
+ */
+template<typename Scalar, int N>
+struct scalar_shift_right_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_shift_right_op)
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const
+ { return a >> N; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
+ { return internal::parithmetic_shift_right<N>(a); }
+};
+template<typename Scalar, int N>
+struct functor_traits<scalar_shift_right_op<Scalar,N> >
+{ enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = packet_traits<Scalar>::HasShift }; };
+
+/** \internal
+ * \brief Template functor to logically shift a scalar left by a number of bits
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::shift_left()
+ */
+template<typename Scalar, int N>
+struct scalar_shift_left_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_shift_left_op)
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const
+ { return a << N; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
+ { return internal::plogical_shift_left<N>(a); }
+};
+template<typename Scalar, int N>
+struct functor_traits<scalar_shift_left_op<Scalar,N> >
+{ enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = packet_traits<Scalar>::HasShift }; };
+
+/** \internal
+ * \brief Template functor to extract the real part of a complex
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::real()
+ */
+template<typename Scalar>
+struct scalar_real_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_real_op)
+ typedef typename NumTraits<Scalar>::Real result_type;
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::real(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_real_op<Scalar> >
+{ enum { Cost = 0, PacketAccess = false }; };
+
+/** \internal
+ * \brief Template functor to extract the imaginary part of a complex
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::imag()
+ */
+template<typename Scalar>
+struct scalar_imag_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_imag_op)
+ typedef typename NumTraits<Scalar>::Real result_type;
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::imag(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_imag_op<Scalar> >
+{ enum { Cost = 0, PacketAccess = false }; };
+
+/** \internal
+ * \brief Template functor to extract the real part of a complex as a reference
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::real()
+ */
+template<typename Scalar>
+struct scalar_real_ref_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_real_ref_op)
+ typedef typename NumTraits<Scalar>::Real result_type;
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return numext::real_ref(*const_cast<Scalar*>(&a)); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_real_ref_op<Scalar> >
+{ enum { Cost = 0, PacketAccess = false }; };
+
+/** \internal
+ * \brief Template functor to extract the imaginary part of a complex as a reference
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::imag()
+ */
+template<typename Scalar>
+struct scalar_imag_ref_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_imag_ref_op)
+ typedef typename NumTraits<Scalar>::Real result_type;
+ EIGEN_DEVICE_FUNC
+ EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return numext::imag_ref(*const_cast<Scalar*>(&a)); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_imag_ref_op<Scalar> >
+{ enum { Cost = 0, PacketAccess = false }; };
+
+/** \internal
+ *
+ * \brief Template functor to compute the exponential of a scalar
+ *
+ * \sa class CwiseUnaryOp, Cwise::exp()
+ */
+template<typename Scalar> struct scalar_exp_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_exp_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::exp(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pexp(a); }
+};
+template <typename Scalar>
+struct functor_traits<scalar_exp_op<Scalar> > {
+ enum {
+ PacketAccess = packet_traits<Scalar>::HasExp,
+ // The following numbers are based on the AVX implementation.
+#ifdef EIGEN_VECTORIZE_FMA
+ // Haswell can issue 2 add/mul/madd per cycle.
+ Cost =
+ (sizeof(Scalar) == 4
+ // float: 8 pmadd, 4 pmul, 2 padd/psub, 6 other
+ ? (8 * NumTraits<Scalar>::AddCost + 6 * NumTraits<Scalar>::MulCost)
+ // double: 7 pmadd, 5 pmul, 3 padd/psub, 1 div, 13 other
+ : (14 * NumTraits<Scalar>::AddCost +
+ 6 * NumTraits<Scalar>::MulCost +
+ scalar_div_cost<Scalar,packet_traits<Scalar>::HasDiv>::value))
+#else
+ Cost =
+ (sizeof(Scalar) == 4
+ // float: 7 pmadd, 6 pmul, 4 padd/psub, 10 other
+ ? (21 * NumTraits<Scalar>::AddCost + 13 * NumTraits<Scalar>::MulCost)
+ // double: 7 pmadd, 5 pmul, 3 padd/psub, 1 div, 13 other
+ : (23 * NumTraits<Scalar>::AddCost +
+ 12 * NumTraits<Scalar>::MulCost +
+ scalar_div_cost<Scalar,packet_traits<Scalar>::HasDiv>::value))
+#endif
+ };
+};
+
+/** \internal
+ *
+ * \brief Template functor to compute the exponential of a scalar - 1.
+ *
+ * \sa class CwiseUnaryOp, ArrayBase::expm1()
+ */
+template<typename Scalar> struct scalar_expm1_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_expm1_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::expm1(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pexpm1(a); }
+};
+template <typename Scalar>
+struct functor_traits<scalar_expm1_op<Scalar> > {
+ enum {
+ PacketAccess = packet_traits<Scalar>::HasExpm1,
+ Cost = functor_traits<scalar_exp_op<Scalar> >::Cost // TODO measure cost of expm1
+ };
+};
+
+/** \internal
+ *
+ * \brief Template functor to compute the logarithm of a scalar
+ *
+ * \sa class CwiseUnaryOp, ArrayBase::log()
+ */
+template<typename Scalar> struct scalar_log_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_log_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::log(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::plog(a); }
+};
+template <typename Scalar>
+struct functor_traits<scalar_log_op<Scalar> > {
+ enum {
+ PacketAccess = packet_traits<Scalar>::HasLog,
+ Cost =
+ (PacketAccess
+ // The following numbers are based on the AVX implementation.
+#ifdef EIGEN_VECTORIZE_FMA
+ // 8 pmadd, 6 pmul, 8 padd/psub, 16 other, can issue 2 add/mul/madd per cycle.
+ ? (20 * NumTraits<Scalar>::AddCost + 7 * NumTraits<Scalar>::MulCost)
+#else
+ // 8 pmadd, 6 pmul, 8 padd/psub, 20 other
+ ? (36 * NumTraits<Scalar>::AddCost + 14 * NumTraits<Scalar>::MulCost)
+#endif
+ // Measured cost of std::log.
+ : sizeof(Scalar)==4 ? 40 : 85)
+ };
+};
+
+/** \internal
+ *
+ * \brief Template functor to compute the logarithm of 1 plus a scalar value
+ *
+ * \sa class CwiseUnaryOp, ArrayBase::log1p()
+ */
+template<typename Scalar> struct scalar_log1p_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_log1p_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::log1p(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::plog1p(a); }
+};
+template <typename Scalar>
+struct functor_traits<scalar_log1p_op<Scalar> > {
+ enum {
+ PacketAccess = packet_traits<Scalar>::HasLog1p,
+ Cost = functor_traits<scalar_log_op<Scalar> >::Cost // TODO measure cost of log1p
+ };
+};
+
+/** \internal
+ *
+ * \brief Template functor to compute the base-10 logarithm of a scalar
+ *
+ * \sa class CwiseUnaryOp, Cwise::log10()
+ */
+template<typename Scalar> struct scalar_log10_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_log10_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { EIGEN_USING_STD(log10) return log10(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::plog10(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_log10_op<Scalar> >
+{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasLog10 }; };
+
+/** \internal
+ *
+ * \brief Template functor to compute the base-2 logarithm of a scalar
+ *
+ * \sa class CwiseUnaryOp, Cwise::log2()
+ */
+template<typename Scalar> struct scalar_log2_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_log2_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return Scalar(EIGEN_LOG2E) * numext::log(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::plog2(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_log2_op<Scalar> >
+{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasLog }; };
+
+/** \internal
+ * \brief Template functor to compute the square root of a scalar
+ * \sa class CwiseUnaryOp, Cwise::sqrt()
+ */
+template<typename Scalar> struct scalar_sqrt_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_sqrt_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::sqrt(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psqrt(a); }
+};
+template <typename Scalar>
+struct functor_traits<scalar_sqrt_op<Scalar> > {
+ enum {
+#if EIGEN_FAST_MATH
+ // The following numbers are based on the AVX implementation.
+ Cost = (sizeof(Scalar) == 8 ? 28
+ // 4 pmul, 1 pmadd, 3 other
+ : (3 * NumTraits<Scalar>::AddCost +
+ 5 * NumTraits<Scalar>::MulCost)),
+#else
+ // The following numbers are based on min VSQRT throughput on Haswell.
+ Cost = (sizeof(Scalar) == 8 ? 28 : 14),
+#endif
+ PacketAccess = packet_traits<Scalar>::HasSqrt
+ };
+};
+
+// Boolean specialization to eliminate -Wimplicit-conversion-floating-point-to-bool warnings.
+template<> struct scalar_sqrt_op<bool> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_sqrt_op)
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline bool operator() (const bool& a) const { return a; }
+ template <typename Packet>
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return a; }
+};
+template <>
+struct functor_traits<scalar_sqrt_op<bool> > {
+ enum { Cost = 1, PacketAccess = packet_traits<bool>::Vectorizable };
+};
+
+/** \internal
+ * \brief Template functor to compute the reciprocal square root of a scalar
+ * \sa class CwiseUnaryOp, Cwise::rsqrt()
+ */
+template<typename Scalar> struct scalar_rsqrt_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_rsqrt_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::rsqrt(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::prsqrt(a); }
+};
+
+template<typename Scalar>
+struct functor_traits<scalar_rsqrt_op<Scalar> >
+{ enum {
+ Cost = 5 * NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasRsqrt
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the cosine of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::cos()
+ */
+template<typename Scalar> struct scalar_cos_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cos_op)
+ EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return numext::cos(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pcos(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_cos_op<Scalar> >
+{
+ enum {
+ Cost = 5 * NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasCos
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the sine of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::sin()
+ */
+template<typename Scalar> struct scalar_sin_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_sin_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::sin(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psin(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_sin_op<Scalar> >
+{
+ enum {
+ Cost = 5 * NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasSin
+ };
+};
+
+
+/** \internal
+ * \brief Template functor to compute the tan of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::tan()
+ */
+template<typename Scalar> struct scalar_tan_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_tan_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::tan(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::ptan(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_tan_op<Scalar> >
+{
+ enum {
+ Cost = 5 * NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasTan
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the arc cosine of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::acos()
+ */
+template<typename Scalar> struct scalar_acos_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_acos_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::acos(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pacos(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_acos_op<Scalar> >
+{
+ enum {
+ Cost = 5 * NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasACos
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the arc sine of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::asin()
+ */
+template<typename Scalar> struct scalar_asin_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_asin_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::asin(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pasin(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_asin_op<Scalar> >
+{
+ enum {
+ Cost = 5 * NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasASin
+ };
+};
+
+
+/** \internal
+ * \brief Template functor to compute the atan of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::atan()
+ */
+template<typename Scalar> struct scalar_atan_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_atan_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::atan(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::patan(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_atan_op<Scalar> >
+{
+ enum {
+ Cost = 5 * NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasATan
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the tanh of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::tanh()
+ */
+template <typename Scalar>
+struct scalar_tanh_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_tanh_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::tanh(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& x) const { return ptanh(x); }
+};
+
+template <typename Scalar>
+struct functor_traits<scalar_tanh_op<Scalar> > {
+ enum {
+ PacketAccess = packet_traits<Scalar>::HasTanh,
+ Cost = ( (EIGEN_FAST_MATH && is_same<Scalar,float>::value)
+// The following numbers are based on the AVX implementation,
+#ifdef EIGEN_VECTORIZE_FMA
+ // Haswell can issue 2 add/mul/madd per cycle.
+ // 9 pmadd, 2 pmul, 1 div, 2 other
+ ? (2 * NumTraits<Scalar>::AddCost +
+ 6 * NumTraits<Scalar>::MulCost +
+ scalar_div_cost<Scalar,packet_traits<Scalar>::HasDiv>::value)
+#else
+ ? (11 * NumTraits<Scalar>::AddCost +
+ 11 * NumTraits<Scalar>::MulCost +
+ scalar_div_cost<Scalar,packet_traits<Scalar>::HasDiv>::value)
+#endif
+ // This number assumes a naive implementation of tanh
+ : (6 * NumTraits<Scalar>::AddCost +
+ 3 * NumTraits<Scalar>::MulCost +
+ 2 * scalar_div_cost<Scalar,packet_traits<Scalar>::HasDiv>::value +
+ functor_traits<scalar_exp_op<Scalar> >::Cost))
+ };
+};
+
+#if EIGEN_HAS_CXX11_MATH
+/** \internal
+ * \brief Template functor to compute the atanh of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::atanh()
+ */
+template <typename Scalar>
+struct scalar_atanh_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_atanh_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::atanh(a); }
+};
+
+template <typename Scalar>
+struct functor_traits<scalar_atanh_op<Scalar> > {
+ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
+};
+#endif
+
+/** \internal
+ * \brief Template functor to compute the sinh of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::sinh()
+ */
+template<typename Scalar> struct scalar_sinh_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_sinh_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::sinh(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psinh(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_sinh_op<Scalar> >
+{
+ enum {
+ Cost = 5 * NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasSinh
+ };
+};
+
+#if EIGEN_HAS_CXX11_MATH
+/** \internal
+ * \brief Template functor to compute the asinh of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::asinh()
+ */
+template <typename Scalar>
+struct scalar_asinh_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_asinh_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::asinh(a); }
+};
+
+template <typename Scalar>
+struct functor_traits<scalar_asinh_op<Scalar> > {
+ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
+};
+#endif
+
+/** \internal
+ * \brief Template functor to compute the cosh of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::cosh()
+ */
+template<typename Scalar> struct scalar_cosh_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cosh_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::cosh(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pcosh(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_cosh_op<Scalar> >
+{
+ enum {
+ Cost = 5 * NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasCosh
+ };
+};
+
+#if EIGEN_HAS_CXX11_MATH
+/** \internal
+ * \brief Template functor to compute the acosh of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::acosh()
+ */
+template <typename Scalar>
+struct scalar_acosh_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_acosh_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::acosh(a); }
+};
+
+template <typename Scalar>
+struct functor_traits<scalar_acosh_op<Scalar> > {
+ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
+};
+#endif
+
+/** \internal
+ * \brief Template functor to compute the inverse of a scalar
+ * \sa class CwiseUnaryOp, Cwise::inverse()
+ */
+template<typename Scalar>
+struct scalar_inverse_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_inverse_op)
+ EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return Scalar(1)/a; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const
+ { return internal::pdiv(pset1<Packet>(Scalar(1)),a); }
+};
+template <typename Scalar>
+struct functor_traits<scalar_inverse_op<Scalar> > {
+ enum {
+ PacketAccess = packet_traits<Scalar>::HasDiv,
+ Cost = scalar_div_cost<Scalar, PacketAccess>::value
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the square of a scalar
+ * \sa class CwiseUnaryOp, Cwise::square()
+ */
+template<typename Scalar>
+struct scalar_square_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_square_op)
+ EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return a*a; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const
+ { return internal::pmul(a,a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_square_op<Scalar> >
+{ enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
+
+// Boolean specialization to avoid -Wint-in-bool-context warnings on GCC.
+template<>
+struct scalar_square_op<bool> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_square_op)
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline bool operator() (const bool& a) const { return a; }
+ template<typename Packet>
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const
+ { return a; }
+};
+template<>
+struct functor_traits<scalar_square_op<bool> >
+{ enum { Cost = 0, PacketAccess = packet_traits<bool>::Vectorizable }; };
+
+/** \internal
+ * \brief Template functor to compute the cube of a scalar
+ * \sa class CwiseUnaryOp, Cwise::cube()
+ */
+template<typename Scalar>
+struct scalar_cube_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cube_op)
+ EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return a*a*a; }
+ template<typename Packet>
+ EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const
+ { return internal::pmul(a,pmul(a,a)); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_cube_op<Scalar> >
+{ enum { Cost = 2*NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
+
+// Boolean specialization to avoid -Wint-in-bool-context warnings on GCC.
+template<>
+struct scalar_cube_op<bool> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_cube_op)
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline bool operator() (const bool& a) const { return a; }
+ template<typename Packet>
+ EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const
+ { return a; }
+};
+template<>
+struct functor_traits<scalar_cube_op<bool> >
+{ enum { Cost = 0, PacketAccess = packet_traits<bool>::Vectorizable }; };
+
+/** \internal
+ * \brief Template functor to compute the rounded value of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::round()
+ */
+template<typename Scalar> struct scalar_round_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_round_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::round(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pround(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_round_op<Scalar> >
+{
+ enum {
+ Cost = NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasRound
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the floor of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::floor()
+ */
+template<typename Scalar> struct scalar_floor_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_floor_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::floor(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pfloor(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_floor_op<Scalar> >
+{
+ enum {
+ Cost = NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasFloor
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the rounded (with current rounding mode) value of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::rint()
+ */
+template<typename Scalar> struct scalar_rint_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_rint_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::rint(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::print(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_rint_op<Scalar> >
+{
+ enum {
+ Cost = NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasRint
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the ceil of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::ceil()
+ */
+template<typename Scalar> struct scalar_ceil_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_ceil_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::ceil(a); }
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pceil(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_ceil_op<Scalar> >
+{
+ enum {
+ Cost = NumTraits<Scalar>::MulCost,
+ PacketAccess = packet_traits<Scalar>::HasCeil
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute whether a scalar is NaN
+ * \sa class CwiseUnaryOp, ArrayBase::isnan()
+ */
+template<typename Scalar> struct scalar_isnan_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_isnan_op)
+ typedef bool result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const {
+#if defined(SYCL_DEVICE_ONLY)
+ return numext::isnan(a);
+#else
+ return (numext::isnan)(a);
+#endif
+ }
+};
+template<typename Scalar>
+struct functor_traits<scalar_isnan_op<Scalar> >
+{
+ enum {
+ Cost = NumTraits<Scalar>::MulCost,
+ PacketAccess = false
+ };
+};
+
+/** \internal
+ * \brief Template functor to check whether a scalar is +/-inf
+ * \sa class CwiseUnaryOp, ArrayBase::isinf()
+ */
+template<typename Scalar> struct scalar_isinf_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_isinf_op)
+ typedef bool result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const {
+#if defined(SYCL_DEVICE_ONLY)
+ return numext::isinf(a);
+#else
+ return (numext::isinf)(a);
+#endif
+ }
+};
+template<typename Scalar>
+struct functor_traits<scalar_isinf_op<Scalar> >
+{
+ enum {
+ Cost = NumTraits<Scalar>::MulCost,
+ PacketAccess = false
+ };
+};
+
+/** \internal
+ * \brief Template functor to check whether a scalar has a finite value
+ * \sa class CwiseUnaryOp, ArrayBase::isfinite()
+ */
+template<typename Scalar> struct scalar_isfinite_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_isfinite_op)
+ typedef bool result_type;
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const {
+#if defined(SYCL_DEVICE_ONLY)
+ return numext::isfinite(a);
+#else
+ return (numext::isfinite)(a);
+#endif
+ }
+};
+template<typename Scalar>
+struct functor_traits<scalar_isfinite_op<Scalar> >
+{
+ enum {
+ Cost = NumTraits<Scalar>::MulCost,
+ PacketAccess = false
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the logical not of a boolean
+ *
+ * \sa class CwiseUnaryOp, ArrayBase::operator!
+ */
+template<typename Scalar> struct scalar_boolean_not_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_boolean_not_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a) const { return !a; }
+};
+template<typename Scalar>
+struct functor_traits<scalar_boolean_not_op<Scalar> > {
+ enum {
+ Cost = NumTraits<bool>::AddCost,
+ PacketAccess = false
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the signum of a scalar
+ * \sa class CwiseUnaryOp, Cwise::sign()
+ */
+template<typename Scalar,bool is_complex=(NumTraits<Scalar>::IsComplex!=0), bool is_integer=(NumTraits<Scalar>::IsInteger!=0) > struct scalar_sign_op;
+template<typename Scalar>
+struct scalar_sign_op<Scalar, false, true> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_sign_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const
+ {
+ return Scalar( (a>Scalar(0)) - (a<Scalar(0)) );
+ }
+ //TODO
+ //template <typename Packet>
+ //EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psign(a); }
+};
+
+template<typename Scalar>
+struct scalar_sign_op<Scalar, false, false> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_sign_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const
+ {
+ return (numext::isnan)(a) ? a : Scalar( (a>Scalar(0)) - (a<Scalar(0)) );
+ }
+ //TODO
+ //template <typename Packet>
+ //EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psign(a); }
+};
+
+template<typename Scalar, bool is_integer>
+struct scalar_sign_op<Scalar,true, is_integer> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_sign_op)
+ EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const
+ {
+ typedef typename NumTraits<Scalar>::Real real_type;
+ real_type aa = numext::abs(a);
+ if (aa==real_type(0))
+ return Scalar(0);
+ aa = real_type(1)/aa;
+ return Scalar(a.real()*aa, a.imag()*aa );
+ }
+ //TODO
+ //template <typename Packet>
+ //EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psign(a); }
+};
+template<typename Scalar>
+struct functor_traits<scalar_sign_op<Scalar> >
+{ enum {
+ Cost =
+ NumTraits<Scalar>::IsComplex
+ ? ( 8*NumTraits<Scalar>::MulCost ) // roughly
+ : ( 3*NumTraits<Scalar>::AddCost),
+ PacketAccess = packet_traits<Scalar>::HasSign
+ };
+};
+
+/** \internal
+ * \brief Template functor to compute the logistic function of a scalar
+ * \sa class CwiseUnaryOp, ArrayBase::logistic()
+ */
+template <typename T>
+struct scalar_logistic_op {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_logistic_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T& x) const {
+ return packetOp(x);
+ }
+
+ template <typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Packet packetOp(const Packet& x) const {
+ const Packet one = pset1<Packet>(T(1));
+ return pdiv(one, padd(one, pexp(pnegate(x))));
+ }
+};
+
+#ifndef EIGEN_GPU_COMPILE_PHASE
+/** \internal
+ * \brief Template specialization of the logistic function for float.
+ *
+ * Uses just a 9/10-degree rational interpolant which
+ * interpolates 1/(1+exp(-x)) - 0.5 up to a couple of ulps in the range
+ * [-9, 18]. Below -9 we use the more accurate approximation
+ * 1/(1+exp(-x)) ~= exp(x), and above 18 the logistic function is 1 withing
+ * one ulp. The shifted logistic is interpolated because it was easier to
+ * make the fit converge.
+ *
+ */
+template <>
+struct scalar_logistic_op<float> {
+ EIGEN_EMPTY_STRUCT_CTOR(scalar_logistic_op)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float operator()(const float& x) const {
+ return packetOp(x);
+ }
+
+ template <typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ Packet packetOp(const Packet& _x) const {
+ const Packet cutoff_lower = pset1<Packet>(-9.f);
+ const Packet lt_mask = pcmp_lt<Packet>(_x, cutoff_lower);
+ const bool any_small = predux_any(lt_mask);
+
+ // The upper cut-off is the smallest x for which the rational approximation evaluates to 1.
+ // Choosing this value saves us a few instructions clamping the results at the end.
+#ifdef EIGEN_VECTORIZE_FMA
+ const Packet cutoff_upper = pset1<Packet>(15.7243833541870117f);
+#else
+ const Packet cutoff_upper = pset1<Packet>(15.6437711715698242f);
+#endif
+ const Packet x = pmin(_x, cutoff_upper);
+
+ // The monomial coefficients of the numerator polynomial (odd).
+ const Packet alpha_1 = pset1<Packet>(2.48287947061529e-01f);
+ const Packet alpha_3 = pset1<Packet>(8.51377133304701e-03f);
+ const Packet alpha_5 = pset1<Packet>(6.08574864600143e-05f);
+ const Packet alpha_7 = pset1<Packet>(1.15627324459942e-07f);
+ const Packet alpha_9 = pset1<Packet>(4.37031012579801e-11f);
+
+ // The monomial coefficients of the denominator polynomial (even).
+ const Packet beta_0 = pset1<Packet>(9.93151921023180e-01f);
+ const Packet beta_2 = pset1<Packet>(1.16817656904453e-01f);
+ const Packet beta_4 = pset1<Packet>(1.70198817374094e-03f);
+ const Packet beta_6 = pset1<Packet>(6.29106785017040e-06f);
+ const Packet beta_8 = pset1<Packet>(5.76102136993427e-09f);
+ const Packet beta_10 = pset1<Packet>(6.10247389755681e-13f);
+
+ // Since the polynomials are odd/even, we need x^2.
+ const Packet x2 = pmul(x, x);
+
+ // Evaluate the numerator polynomial p.
+ Packet p = pmadd(x2, alpha_9, alpha_7);
+ p = pmadd(x2, p, alpha_5);
+ p = pmadd(x2, p, alpha_3);
+ p = pmadd(x2, p, alpha_1);
+ p = pmul(x, p);
+
+ // Evaluate the denominator polynomial q.
+ Packet q = pmadd(x2, beta_10, beta_8);
+ q = pmadd(x2, q, beta_6);
+ q = pmadd(x2, q, beta_4);
+ q = pmadd(x2, q, beta_2);
+ q = pmadd(x2, q, beta_0);
+ // Divide the numerator by the denominator and shift it up.
+ const Packet logistic = padd(pdiv(p, q), pset1<Packet>(0.5f));
+ if (EIGEN_PREDICT_FALSE(any_small)) {
+ const Packet exponential = pexp(_x);
+ return pselect(lt_mask, exponential, logistic);
+ } else {
+ return logistic;
+ }
+ }
+};
+#endif // #ifndef EIGEN_GPU_COMPILE_PHASE
+
+template <typename T>
+struct functor_traits<scalar_logistic_op<T> > {
+ enum {
+ // The cost estimate for float here here is for the common(?) case where
+ // all arguments are greater than -9.
+ Cost = scalar_div_cost<T, packet_traits<T>::HasDiv>::value +
+ (internal::is_same<T, float>::value
+ ? NumTraits<T>::AddCost * 15 + NumTraits<T>::MulCost * 11
+ : NumTraits<T>::AddCost * 2 +
+ functor_traits<scalar_exp_op<T> >::Cost),
+ PacketAccess =
+ packet_traits<T>::HasAdd && packet_traits<T>::HasDiv &&
+ (internal::is_same<T, float>::value
+ ? packet_traits<T>::HasMul && packet_traits<T>::HasMax &&
+ packet_traits<T>::HasMin
+ : packet_traits<T>::HasNegate && packet_traits<T>::HasExp)
+ };
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_FUNCTORS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h
new file mode 100644
index 000000000..f35b760c1
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h
@@ -0,0 +1,2645 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GENERAL_BLOCK_PANEL_H
+#define EIGEN_GENERAL_BLOCK_PANEL_H
+
+
+namespace Eigen {
+
+namespace internal {
+
+enum GEBPPacketSizeType {
+ GEBPPacketFull = 0,
+ GEBPPacketHalf,
+ GEBPPacketQuarter
+};
+
+template<typename _LhsScalar, typename _RhsScalar, bool _ConjLhs=false, bool _ConjRhs=false, int Arch=Architecture::Target, int _PacketSize=GEBPPacketFull>
+class gebp_traits;
+
+
+/** \internal \returns b if a<=0, and returns a otherwise. */
+inline std::ptrdiff_t manage_caching_sizes_helper(std::ptrdiff_t a, std::ptrdiff_t b)
+{
+ return a<=0 ? b : a;
+}
+
+#if defined(EIGEN_DEFAULT_L1_CACHE_SIZE)
+#define EIGEN_SET_DEFAULT_L1_CACHE_SIZE(val) EIGEN_DEFAULT_L1_CACHE_SIZE
+#else
+#define EIGEN_SET_DEFAULT_L1_CACHE_SIZE(val) val
+#endif // defined(EIGEN_DEFAULT_L1_CACHE_SIZE)
+
+#if defined(EIGEN_DEFAULT_L2_CACHE_SIZE)
+#define EIGEN_SET_DEFAULT_L2_CACHE_SIZE(val) EIGEN_DEFAULT_L2_CACHE_SIZE
+#else
+#define EIGEN_SET_DEFAULT_L2_CACHE_SIZE(val) val
+#endif // defined(EIGEN_DEFAULT_L2_CACHE_SIZE)
+
+#if defined(EIGEN_DEFAULT_L3_CACHE_SIZE)
+#define EIGEN_SET_DEFAULT_L3_CACHE_SIZE(val) EIGEN_DEFAULT_L3_CACHE_SIZE
+#else
+#define EIGEN_SET_DEFAULT_L3_CACHE_SIZE(val) val
+#endif // defined(EIGEN_DEFAULT_L3_CACHE_SIZE)
+
+#if EIGEN_ARCH_i386_OR_x86_64
+const std::ptrdiff_t defaultL1CacheSize = EIGEN_SET_DEFAULT_L1_CACHE_SIZE(32*1024);
+const std::ptrdiff_t defaultL2CacheSize = EIGEN_SET_DEFAULT_L2_CACHE_SIZE(256*1024);
+const std::ptrdiff_t defaultL3CacheSize = EIGEN_SET_DEFAULT_L3_CACHE_SIZE(2*1024*1024);
+#elif EIGEN_ARCH_PPC
+const std::ptrdiff_t defaultL1CacheSize = EIGEN_SET_DEFAULT_L1_CACHE_SIZE(64*1024);
+const std::ptrdiff_t defaultL2CacheSize = EIGEN_SET_DEFAULT_L2_CACHE_SIZE(512*1024);
+const std::ptrdiff_t defaultL3CacheSize = EIGEN_SET_DEFAULT_L3_CACHE_SIZE(4*1024*1024);
+#else
+const std::ptrdiff_t defaultL1CacheSize = EIGEN_SET_DEFAULT_L1_CACHE_SIZE(16*1024);
+const std::ptrdiff_t defaultL2CacheSize = EIGEN_SET_DEFAULT_L2_CACHE_SIZE(512*1024);
+const std::ptrdiff_t defaultL3CacheSize = EIGEN_SET_DEFAULT_L3_CACHE_SIZE(512*1024);
+#endif
+
+#undef EIGEN_SET_DEFAULT_L1_CACHE_SIZE
+#undef EIGEN_SET_DEFAULT_L2_CACHE_SIZE
+#undef EIGEN_SET_DEFAULT_L3_CACHE_SIZE
+
+/** \internal */
+struct CacheSizes {
+ CacheSizes(): m_l1(-1),m_l2(-1),m_l3(-1) {
+ int l1CacheSize, l2CacheSize, l3CacheSize;
+ queryCacheSizes(l1CacheSize, l2CacheSize, l3CacheSize);
+ m_l1 = manage_caching_sizes_helper(l1CacheSize, defaultL1CacheSize);
+ m_l2 = manage_caching_sizes_helper(l2CacheSize, defaultL2CacheSize);
+ m_l3 = manage_caching_sizes_helper(l3CacheSize, defaultL3CacheSize);
+ }
+
+ std::ptrdiff_t m_l1;
+ std::ptrdiff_t m_l2;
+ std::ptrdiff_t m_l3;
+};
+
+/** \internal */
+inline void manage_caching_sizes(Action action, std::ptrdiff_t* l1, std::ptrdiff_t* l2, std::ptrdiff_t* l3)
+{
+ static CacheSizes m_cacheSizes;
+
+ if(action==SetAction)
+ {
+ // set the cpu cache size and cache all block sizes from a global cache size in byte
+ eigen_internal_assert(l1!=0 && l2!=0);
+ m_cacheSizes.m_l1 = *l1;
+ m_cacheSizes.m_l2 = *l2;
+ m_cacheSizes.m_l3 = *l3;
+ }
+ else if(action==GetAction)
+ {
+ eigen_internal_assert(l1!=0 && l2!=0);
+ *l1 = m_cacheSizes.m_l1;
+ *l2 = m_cacheSizes.m_l2;
+ *l3 = m_cacheSizes.m_l3;
+ }
+ else
+ {
+ eigen_internal_assert(false);
+ }
+}
+
+/* Helper for computeProductBlockingSizes.
+ *
+ * Given a m x k times k x n matrix product of scalar types \c LhsScalar and \c RhsScalar,
+ * this function computes the blocking size parameters along the respective dimensions
+ * for matrix products and related algorithms. The blocking sizes depends on various
+ * parameters:
+ * - the L1 and L2 cache sizes,
+ * - the register level blocking sizes defined by gebp_traits,
+ * - the number of scalars that fit into a packet (when vectorization is enabled).
+ *
+ * \sa setCpuCacheSizes */
+
+template<typename LhsScalar, typename RhsScalar, int KcFactor, typename Index>
+void evaluateProductBlockingSizesHeuristic(Index& k, Index& m, Index& n, Index num_threads = 1)
+{
+ typedef gebp_traits<LhsScalar,RhsScalar> Traits;
+
+ // Explanations:
+ // Let's recall that the product algorithms form mc x kc vertical panels A' on the lhs and
+ // kc x nc blocks B' on the rhs. B' has to fit into L2/L3 cache. Moreover, A' is processed
+ // per mr x kc horizontal small panels where mr is the blocking size along the m dimension
+ // at the register level. This small horizontal panel has to stay within L1 cache.
+ std::ptrdiff_t l1, l2, l3;
+ manage_caching_sizes(GetAction, &l1, &l2, &l3);
+ #ifdef EIGEN_VECTORIZE_AVX512
+ // We need to find a rationale for that, but without this adjustment,
+ // performance with AVX512 is pretty bad, like -20% slower.
+ // One reason is that with increasing packet-size, the blocking size k
+ // has to become pretty small if we want that 1 lhs panel fit within L1.
+ // For instance, with the 3pX4 kernel and double, the size of the lhs+rhs panels are:
+ // k*(3*64 + 4*8) Bytes, with l1=32kBytes, and k%8=0, we have k=144.
+ // This is quite small for a good reuse of the accumulation registers.
+ l1 *= 4;
+ #endif
+
+ if (num_threads > 1) {
+ typedef typename Traits::ResScalar ResScalar;
+ enum {
+ kdiv = KcFactor * (Traits::mr * sizeof(LhsScalar) + Traits::nr * sizeof(RhsScalar)),
+ ksub = Traits::mr * Traits::nr * sizeof(ResScalar),
+ kr = 8,
+ mr = Traits::mr,
+ nr = Traits::nr
+ };
+ // Increasing k gives us more time to prefetch the content of the "C"
+ // registers. However once the latency is hidden there is no point in
+ // increasing the value of k, so we'll cap it at 320 (value determined
+ // experimentally).
+ // To avoid that k vanishes, we make k_cache at least as big as kr
+ const Index k_cache = numext::maxi<Index>(kr, (numext::mini<Index>)((l1-ksub)/kdiv, 320));
+ if (k_cache < k) {
+ k = k_cache - (k_cache % kr);
+ eigen_internal_assert(k > 0);
+ }
+
+ const Index n_cache = (l2-l1) / (nr * sizeof(RhsScalar) * k);
+ const Index n_per_thread = numext::div_ceil(n, num_threads);
+ if (n_cache <= n_per_thread) {
+ // Don't exceed the capacity of the l2 cache.
+ eigen_internal_assert(n_cache >= static_cast<Index>(nr));
+ n = n_cache - (n_cache % nr);
+ eigen_internal_assert(n > 0);
+ } else {
+ n = (numext::mini<Index>)(n, (n_per_thread + nr - 1) - ((n_per_thread + nr - 1) % nr));
+ }
+
+ if (l3 > l2) {
+ // l3 is shared between all cores, so we'll give each thread its own chunk of l3.
+ const Index m_cache = (l3-l2) / (sizeof(LhsScalar) * k * num_threads);
+ const Index m_per_thread = numext::div_ceil(m, num_threads);
+ if(m_cache < m_per_thread && m_cache >= static_cast<Index>(mr)) {
+ m = m_cache - (m_cache % mr);
+ eigen_internal_assert(m > 0);
+ } else {
+ m = (numext::mini<Index>)(m, (m_per_thread + mr - 1) - ((m_per_thread + mr - 1) % mr));
+ }
+ }
+ }
+ else {
+ // In unit tests we do not want to use extra large matrices,
+ // so we reduce the cache size to check the blocking strategy is not flawed
+#ifdef EIGEN_DEBUG_SMALL_PRODUCT_BLOCKS
+ l1 = 9*1024;
+ l2 = 32*1024;
+ l3 = 512*1024;
+#endif
+
+ // Early return for small problems because the computation below are time consuming for small problems.
+ // Perhaps it would make more sense to consider k*n*m??
+ // Note that for very tiny problem, this function should be bypassed anyway
+ // because we use the coefficient-based implementation for them.
+ if((numext::maxi)(k,(numext::maxi)(m,n))<48)
+ return;
+
+ typedef typename Traits::ResScalar ResScalar;
+ enum {
+ k_peeling = 8,
+ k_div = KcFactor * (Traits::mr * sizeof(LhsScalar) + Traits::nr * sizeof(RhsScalar)),
+ k_sub = Traits::mr * Traits::nr * sizeof(ResScalar)
+ };
+
+ // ---- 1st level of blocking on L1, yields kc ----
+
+ // Blocking on the third dimension (i.e., k) is chosen so that an horizontal panel
+ // of size mr x kc of the lhs plus a vertical panel of kc x nr of the rhs both fits within L1 cache.
+ // We also include a register-level block of the result (mx x nr).
+ // (In an ideal world only the lhs panel would stay in L1)
+ // Moreover, kc has to be a multiple of 8 to be compatible with loop peeling, leading to a maximum blocking size of:
+ const Index max_kc = numext::maxi<Index>(((l1-k_sub)/k_div) & (~(k_peeling-1)),1);
+ const Index old_k = k;
+ if(k>max_kc)
+ {
+ // We are really blocking on the third dimension:
+ // -> reduce blocking size to make sure the last block is as large as possible
+ // while keeping the same number of sweeps over the result.
+ k = (k%max_kc)==0 ? max_kc
+ : max_kc - k_peeling * ((max_kc-1-(k%max_kc))/(k_peeling*(k/max_kc+1)));
+
+ eigen_internal_assert(((old_k/k) == (old_k/max_kc)) && "the number of sweeps has to remain the same");
+ }
+
+ // ---- 2nd level of blocking on max(L2,L3), yields nc ----
+
+ // TODO find a reliable way to get the actual amount of cache per core to use for 2nd level blocking, that is:
+ // actual_l2 = max(l2, l3/nb_core_sharing_l3)
+ // The number below is quite conservative: it is better to underestimate the cache size rather than overestimating it)
+ // For instance, it corresponds to 6MB of L3 shared among 4 cores.
+ #ifdef EIGEN_DEBUG_SMALL_PRODUCT_BLOCKS
+ const Index actual_l2 = l3;
+ #else
+ const Index actual_l2 = 1572864; // == 1.5 MB
+ #endif
+
+ // Here, nc is chosen such that a block of kc x nc of the rhs fit within half of L2.
+ // The second half is implicitly reserved to access the result and lhs coefficients.
+ // When k<max_kc, then nc can arbitrarily growth. In practice, it seems to be fruitful
+ // to limit this growth: we bound nc to growth by a factor x1.5.
+ // However, if the entire lhs block fit within L1, then we are not going to block on the rows at all,
+ // and it becomes fruitful to keep the packed rhs blocks in L1 if there is enough remaining space.
+ Index max_nc;
+ const Index lhs_bytes = m * k * sizeof(LhsScalar);
+ const Index remaining_l1 = l1- k_sub - lhs_bytes;
+ if(remaining_l1 >= Index(Traits::nr*sizeof(RhsScalar))*k)
+ {
+ // L1 blocking
+ max_nc = remaining_l1 / (k*sizeof(RhsScalar));
+ }
+ else
+ {
+ // L2 blocking
+ max_nc = (3*actual_l2)/(2*2*max_kc*sizeof(RhsScalar));
+ }
+ // WARNING Below, we assume that Traits::nr is a power of two.
+ Index nc = numext::mini<Index>(actual_l2/(2*k*sizeof(RhsScalar)), max_nc) & (~(Traits::nr-1));
+ if(n>nc)
+ {
+ // We are really blocking over the columns:
+ // -> reduce blocking size to make sure the last block is as large as possible
+ // while keeping the same number of sweeps over the packed lhs.
+ // Here we allow one more sweep if this gives us a perfect match, thus the commented "-1"
+ n = (n%nc)==0 ? nc
+ : (nc - Traits::nr * ((nc/*-1*/-(n%nc))/(Traits::nr*(n/nc+1))));
+ }
+ else if(old_k==k)
+ {
+ // So far, no blocking at all, i.e., kc==k, and nc==n.
+ // In this case, let's perform a blocking over the rows such that the packed lhs data is kept in cache L1/L2
+ // TODO: part of this blocking strategy is now implemented within the kernel itself, so the L1-based heuristic here should be obsolete.
+ Index problem_size = k*n*sizeof(LhsScalar);
+ Index actual_lm = actual_l2;
+ Index max_mc = m;
+ if(problem_size<=1024)
+ {
+ // problem is small enough to keep in L1
+ // Let's choose m such that lhs's block fit in 1/3 of L1
+ actual_lm = l1;
+ }
+ else if(l3!=0 && problem_size<=32768)
+ {
+ // we have both L2 and L3, and problem is small enough to be kept in L2
+ // Let's choose m such that lhs's block fit in 1/3 of L2
+ actual_lm = l2;
+ max_mc = (numext::mini<Index>)(576,max_mc);
+ }
+ Index mc = (numext::mini<Index>)(actual_lm/(3*k*sizeof(LhsScalar)), max_mc);
+ if (mc > Traits::mr) mc -= mc % Traits::mr;
+ else if (mc==0) return;
+ m = (m%mc)==0 ? mc
+ : (mc - Traits::mr * ((mc/*-1*/-(m%mc))/(Traits::mr*(m/mc+1))));
+ }
+ }
+}
+
+template <typename Index>
+inline bool useSpecificBlockingSizes(Index& k, Index& m, Index& n)
+{
+#ifdef EIGEN_TEST_SPECIFIC_BLOCKING_SIZES
+ if (EIGEN_TEST_SPECIFIC_BLOCKING_SIZES) {
+ k = numext::mini<Index>(k, EIGEN_TEST_SPECIFIC_BLOCKING_SIZE_K);
+ m = numext::mini<Index>(m, EIGEN_TEST_SPECIFIC_BLOCKING_SIZE_M);
+ n = numext::mini<Index>(n, EIGEN_TEST_SPECIFIC_BLOCKING_SIZE_N);
+ return true;
+ }
+#else
+ EIGEN_UNUSED_VARIABLE(k)
+ EIGEN_UNUSED_VARIABLE(m)
+ EIGEN_UNUSED_VARIABLE(n)
+#endif
+ return false;
+}
+
+/** \brief Computes the blocking parameters for a m x k times k x n matrix product
+ *
+ * \param[in,out] k Input: the third dimension of the product. Output: the blocking size along the same dimension.
+ * \param[in,out] m Input: the number of rows of the left hand side. Output: the blocking size along the same dimension.
+ * \param[in,out] n Input: the number of columns of the right hand side. Output: the blocking size along the same dimension.
+ *
+ * Given a m x k times k x n matrix product of scalar types \c LhsScalar and \c RhsScalar,
+ * this function computes the blocking size parameters along the respective dimensions
+ * for matrix products and related algorithms.
+ *
+ * The blocking size parameters may be evaluated:
+ * - either by a heuristic based on cache sizes;
+ * - or using fixed prescribed values (for testing purposes).
+ *
+ * \sa setCpuCacheSizes */
+
+template<typename LhsScalar, typename RhsScalar, int KcFactor, typename Index>
+void computeProductBlockingSizes(Index& k, Index& m, Index& n, Index num_threads = 1)
+{
+ if (!useSpecificBlockingSizes(k, m, n)) {
+ evaluateProductBlockingSizesHeuristic<LhsScalar, RhsScalar, KcFactor, Index>(k, m, n, num_threads);
+ }
+}
+
+template<typename LhsScalar, typename RhsScalar, typename Index>
+inline void computeProductBlockingSizes(Index& k, Index& m, Index& n, Index num_threads = 1)
+{
+ computeProductBlockingSizes<LhsScalar,RhsScalar,1,Index>(k, m, n, num_threads);
+}
+
+template <typename RhsPacket, typename RhsPacketx4, int registers_taken>
+struct RhsPanelHelper {
+ private:
+ static const int remaining_registers = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS - registers_taken;
+ public:
+ typedef typename conditional<remaining_registers>=4, RhsPacketx4, RhsPacket>::type type;
+};
+
+template <typename Packet>
+struct QuadPacket
+{
+ Packet B_0, B1, B2, B3;
+ const Packet& get(const FixedInt<0>&) const { return B_0; }
+ const Packet& get(const FixedInt<1>&) const { return B1; }
+ const Packet& get(const FixedInt<2>&) const { return B2; }
+ const Packet& get(const FixedInt<3>&) const { return B3; }
+};
+
+template <int N, typename T1, typename T2, typename T3>
+struct packet_conditional { typedef T3 type; };
+
+template <typename T1, typename T2, typename T3>
+struct packet_conditional<GEBPPacketFull, T1, T2, T3> { typedef T1 type; };
+
+template <typename T1, typename T2, typename T3>
+struct packet_conditional<GEBPPacketHalf, T1, T2, T3> { typedef T2 type; };
+
+#define PACKET_DECL_COND_PREFIX(prefix, name, packet_size) \
+ typedef typename packet_conditional<packet_size, \
+ typename packet_traits<name ## Scalar>::type, \
+ typename packet_traits<name ## Scalar>::half, \
+ typename unpacket_traits<typename packet_traits<name ## Scalar>::half>::half>::type \
+ prefix ## name ## Packet
+
+#define PACKET_DECL_COND(name, packet_size) \
+ typedef typename packet_conditional<packet_size, \
+ typename packet_traits<name ## Scalar>::type, \
+ typename packet_traits<name ## Scalar>::half, \
+ typename unpacket_traits<typename packet_traits<name ## Scalar>::half>::half>::type \
+ name ## Packet
+
+#define PACKET_DECL_COND_SCALAR_PREFIX(prefix, packet_size) \
+ typedef typename packet_conditional<packet_size, \
+ typename packet_traits<Scalar>::type, \
+ typename packet_traits<Scalar>::half, \
+ typename unpacket_traits<typename packet_traits<Scalar>::half>::half>::type \
+ prefix ## ScalarPacket
+
+#define PACKET_DECL_COND_SCALAR(packet_size) \
+ typedef typename packet_conditional<packet_size, \
+ typename packet_traits<Scalar>::type, \
+ typename packet_traits<Scalar>::half, \
+ typename unpacket_traits<typename packet_traits<Scalar>::half>::half>::type \
+ ScalarPacket
+
+/* Vectorization logic
+ * real*real: unpack rhs to constant packets, ...
+ *
+ * cd*cd : unpack rhs to (b_r,b_r), (b_i,b_i), mul to get (a_r b_r,a_i b_r) (a_r b_i,a_i b_i),
+ * storing each res packet into two packets (2x2),
+ * at the end combine them: swap the second and addsub them
+ * cf*cf : same but with 2x4 blocks
+ * cplx*real : unpack rhs to constant packets, ...
+ * real*cplx : load lhs as (a0,a0,a1,a1), and mul as usual
+ */
+template<typename _LhsScalar, typename _RhsScalar, bool _ConjLhs, bool _ConjRhs, int Arch, int _PacketSize>
+class gebp_traits
+{
+public:
+ typedef _LhsScalar LhsScalar;
+ typedef _RhsScalar RhsScalar;
+ typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
+
+ PACKET_DECL_COND_PREFIX(_, Lhs, _PacketSize);
+ PACKET_DECL_COND_PREFIX(_, Rhs, _PacketSize);
+ PACKET_DECL_COND_PREFIX(_, Res, _PacketSize);
+
+ enum {
+ ConjLhs = _ConjLhs,
+ ConjRhs = _ConjRhs,
+ Vectorizable = unpacket_traits<_LhsPacket>::vectorizable && unpacket_traits<_RhsPacket>::vectorizable,
+ LhsPacketSize = Vectorizable ? unpacket_traits<_LhsPacket>::size : 1,
+ RhsPacketSize = Vectorizable ? unpacket_traits<_RhsPacket>::size : 1,
+ ResPacketSize = Vectorizable ? unpacket_traits<_ResPacket>::size : 1,
+
+ NumberOfRegisters = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS,
+
+ // register block size along the N direction must be 1 or 4
+ nr = 4,
+
+ // register block size along the M direction (currently, this one cannot be modified)
+ default_mr = (EIGEN_PLAIN_ENUM_MIN(16,NumberOfRegisters)/2/nr)*LhsPacketSize,
+#if defined(EIGEN_HAS_SINGLE_INSTRUCTION_MADD) && !defined(EIGEN_VECTORIZE_ALTIVEC) && !defined(EIGEN_VECTORIZE_VSX) \
+ && ((!EIGEN_COMP_MSVC) || (EIGEN_COMP_MSVC>=1914))
+ // we assume 16 registers or more
+ // See bug 992, if the scalar type is not vectorizable but that EIGEN_HAS_SINGLE_INSTRUCTION_MADD is defined,
+ // then using 3*LhsPacketSize triggers non-implemented paths in syrk.
+ // Bug 1515: MSVC prior to v19.14 yields to register spilling.
+ mr = Vectorizable ? 3*LhsPacketSize : default_mr,
+#else
+ mr = default_mr,
+#endif
+
+ LhsProgress = LhsPacketSize,
+ RhsProgress = 1
+ };
+
+
+ typedef typename conditional<Vectorizable,_LhsPacket,LhsScalar>::type LhsPacket;
+ typedef typename conditional<Vectorizable,_RhsPacket,RhsScalar>::type RhsPacket;
+ typedef typename conditional<Vectorizable,_ResPacket,ResScalar>::type ResPacket;
+ typedef LhsPacket LhsPacket4Packing;
+
+ typedef QuadPacket<RhsPacket> RhsPacketx4;
+ typedef ResPacket AccPacket;
+
+ EIGEN_STRONG_INLINE void initAcc(AccPacket& p)
+ {
+ p = pset1<ResPacket>(ResScalar(0));
+ }
+
+ template<typename RhsPacketType>
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketType& dest) const
+ {
+ dest = pset1<RhsPacketType>(*b);
+ }
+
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const
+ {
+ pbroadcast4(b, dest.B_0, dest.B1, dest.B2, dest.B3);
+ }
+
+ template<typename RhsPacketType>
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacketType& dest) const
+ {
+ loadRhs(b, dest);
+ }
+
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar*, RhsPacketx4&) const
+ {
+ }
+
+ EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, RhsPacket& dest) const
+ {
+ dest = ploadquad<RhsPacket>(b);
+ }
+
+ template<typename LhsPacketType>
+ EIGEN_STRONG_INLINE void loadLhs(const LhsScalar* a, LhsPacketType& dest) const
+ {
+ dest = pload<LhsPacketType>(a);
+ }
+
+ template<typename LhsPacketType>
+ EIGEN_STRONG_INLINE void loadLhsUnaligned(const LhsScalar* a, LhsPacketType& dest) const
+ {
+ dest = ploadu<LhsPacketType>(a);
+ }
+
+ template<typename LhsPacketType, typename RhsPacketType, typename AccPacketType, typename LaneIdType>
+ EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketType& b, AccPacketType& c, RhsPacketType& tmp, const LaneIdType&) const
+ {
+ conj_helper<LhsPacketType,RhsPacketType,ConjLhs,ConjRhs> cj;
+ // It would be a lot cleaner to call pmadd all the time. Unfortunately if we
+ // let gcc allocate the register in which to store the result of the pmul
+ // (in the case where there is no FMA) gcc fails to figure out how to avoid
+ // spilling register.
+#ifdef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+ EIGEN_UNUSED_VARIABLE(tmp);
+ c = cj.pmadd(a,b,c);
+#else
+ tmp = b; tmp = cj.pmul(a,tmp); c = padd(c,tmp);
+#endif
+ }
+
+ template<typename LhsPacketType, typename AccPacketType, typename LaneIdType>
+ EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketx4& b, AccPacketType& c, RhsPacket& tmp, const LaneIdType& lane) const
+ {
+ madd(a, b.get(lane), c, tmp, lane);
+ }
+
+ EIGEN_STRONG_INLINE void acc(const AccPacket& c, const ResPacket& alpha, ResPacket& r) const
+ {
+ r = pmadd(c,alpha,r);
+ }
+
+ template<typename ResPacketHalf>
+ EIGEN_STRONG_INLINE void acc(const ResPacketHalf& c, const ResPacketHalf& alpha, ResPacketHalf& r) const
+ {
+ r = pmadd(c,alpha,r);
+ }
+
+};
+
+template<typename RealScalar, bool _ConjLhs, int Arch, int _PacketSize>
+class gebp_traits<std::complex<RealScalar>, RealScalar, _ConjLhs, false, Arch, _PacketSize>
+{
+public:
+ typedef std::complex<RealScalar> LhsScalar;
+ typedef RealScalar RhsScalar;
+ typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
+
+ PACKET_DECL_COND_PREFIX(_, Lhs, _PacketSize);
+ PACKET_DECL_COND_PREFIX(_, Rhs, _PacketSize);
+ PACKET_DECL_COND_PREFIX(_, Res, _PacketSize);
+
+ enum {
+ ConjLhs = _ConjLhs,
+ ConjRhs = false,
+ Vectorizable = unpacket_traits<_LhsPacket>::vectorizable && unpacket_traits<_RhsPacket>::vectorizable,
+ LhsPacketSize = Vectorizable ? unpacket_traits<_LhsPacket>::size : 1,
+ RhsPacketSize = Vectorizable ? unpacket_traits<_RhsPacket>::size : 1,
+ ResPacketSize = Vectorizable ? unpacket_traits<_ResPacket>::size : 1,
+
+ NumberOfRegisters = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS,
+ nr = 4,
+#if defined(EIGEN_HAS_SINGLE_INSTRUCTION_MADD) && !defined(EIGEN_VECTORIZE_ALTIVEC) && !defined(EIGEN_VECTORIZE_VSX)
+ // we assume 16 registers
+ mr = 3*LhsPacketSize,
+#else
+ mr = (EIGEN_PLAIN_ENUM_MIN(16,NumberOfRegisters)/2/nr)*LhsPacketSize,
+#endif
+
+ LhsProgress = LhsPacketSize,
+ RhsProgress = 1
+ };
+
+ typedef typename conditional<Vectorizable,_LhsPacket,LhsScalar>::type LhsPacket;
+ typedef typename conditional<Vectorizable,_RhsPacket,RhsScalar>::type RhsPacket;
+ typedef typename conditional<Vectorizable,_ResPacket,ResScalar>::type ResPacket;
+ typedef LhsPacket LhsPacket4Packing;
+
+ typedef QuadPacket<RhsPacket> RhsPacketx4;
+
+ typedef ResPacket AccPacket;
+
+ EIGEN_STRONG_INLINE void initAcc(AccPacket& p)
+ {
+ p = pset1<ResPacket>(ResScalar(0));
+ }
+
+ template<typename RhsPacketType>
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketType& dest) const
+ {
+ dest = pset1<RhsPacketType>(*b);
+ }
+
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const
+ {
+ pbroadcast4(b, dest.B_0, dest.B1, dest.B2, dest.B3);
+ }
+
+ template<typename RhsPacketType>
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacketType& dest) const
+ {
+ loadRhs(b, dest);
+ }
+
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar*, RhsPacketx4&) const
+ {}
+
+ EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, RhsPacket& dest) const
+ {
+ loadRhsQuad_impl(b,dest, typename conditional<RhsPacketSize==16,true_type,false_type>::type());
+ }
+
+ EIGEN_STRONG_INLINE void loadRhsQuad_impl(const RhsScalar* b, RhsPacket& dest, const true_type&) const
+ {
+ // FIXME we can do better!
+ // what we want here is a ploadheight
+ RhsScalar tmp[4] = {b[0],b[0],b[1],b[1]};
+ dest = ploadquad<RhsPacket>(tmp);
+ }
+
+ EIGEN_STRONG_INLINE void loadRhsQuad_impl(const RhsScalar* b, RhsPacket& dest, const false_type&) const
+ {
+ eigen_internal_assert(RhsPacketSize<=8);
+ dest = pset1<RhsPacket>(*b);
+ }
+
+ EIGEN_STRONG_INLINE void loadLhs(const LhsScalar* a, LhsPacket& dest) const
+ {
+ dest = pload<LhsPacket>(a);
+ }
+
+ template<typename LhsPacketType>
+ EIGEN_STRONG_INLINE void loadLhsUnaligned(const LhsScalar* a, LhsPacketType& dest) const
+ {
+ dest = ploadu<LhsPacketType>(a);
+ }
+
+ template <typename LhsPacketType, typename RhsPacketType, typename AccPacketType, typename LaneIdType>
+ EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketType& b, AccPacketType& c, RhsPacketType& tmp, const LaneIdType&) const
+ {
+ madd_impl(a, b, c, tmp, typename conditional<Vectorizable,true_type,false_type>::type());
+ }
+
+ template <typename LhsPacketType, typename RhsPacketType, typename AccPacketType>
+ EIGEN_STRONG_INLINE void madd_impl(const LhsPacketType& a, const RhsPacketType& b, AccPacketType& c, RhsPacketType& tmp, const true_type&) const
+ {
+#ifdef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+ EIGEN_UNUSED_VARIABLE(tmp);
+ c.v = pmadd(a.v,b,c.v);
+#else
+ tmp = b; tmp = pmul(a.v,tmp); c.v = padd(c.v,tmp);
+#endif
+ }
+
+ EIGEN_STRONG_INLINE void madd_impl(const LhsScalar& a, const RhsScalar& b, ResScalar& c, RhsScalar& /*tmp*/, const false_type&) const
+ {
+ c += a * b;
+ }
+
+ template<typename LhsPacketType, typename AccPacketType, typename LaneIdType>
+ EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketx4& b, AccPacketType& c, RhsPacket& tmp, const LaneIdType& lane) const
+ {
+ madd(a, b.get(lane), c, tmp, lane);
+ }
+
+ template <typename ResPacketType, typename AccPacketType>
+ EIGEN_STRONG_INLINE void acc(const AccPacketType& c, const ResPacketType& alpha, ResPacketType& r) const
+ {
+ conj_helper<ResPacketType,ResPacketType,ConjLhs,false> cj;
+ r = cj.pmadd(c,alpha,r);
+ }
+
+protected:
+};
+
+template<typename Packet>
+struct DoublePacket
+{
+ Packet first;
+ Packet second;
+};
+
+template<typename Packet>
+DoublePacket<Packet> padd(const DoublePacket<Packet> &a, const DoublePacket<Packet> &b)
+{
+ DoublePacket<Packet> res;
+ res.first = padd(a.first, b.first);
+ res.second = padd(a.second,b.second);
+ return res;
+}
+
+// note that for DoublePacket<RealPacket> the "4" in "downto4"
+// corresponds to the number of complexes, so it means "8"
+// it terms of real coefficients.
+
+template<typename Packet>
+const DoublePacket<Packet>&
+predux_half_dowto4(const DoublePacket<Packet> &a,
+ typename enable_if<unpacket_traits<Packet>::size<=8>::type* = 0)
+{
+ return a;
+}
+
+template<typename Packet>
+DoublePacket<typename unpacket_traits<Packet>::half>
+predux_half_dowto4(const DoublePacket<Packet> &a,
+ typename enable_if<unpacket_traits<Packet>::size==16>::type* = 0)
+{
+ // yes, that's pretty hackish :(
+ DoublePacket<typename unpacket_traits<Packet>::half> res;
+ typedef std::complex<typename unpacket_traits<Packet>::type> Cplx;
+ typedef typename packet_traits<Cplx>::type CplxPacket;
+ res.first = predux_half_dowto4(CplxPacket(a.first)).v;
+ res.second = predux_half_dowto4(CplxPacket(a.second)).v;
+ return res;
+}
+
+// same here, "quad" actually means "8" in terms of real coefficients
+template<typename Scalar, typename RealPacket>
+void loadQuadToDoublePacket(const Scalar* b, DoublePacket<RealPacket>& dest,
+ typename enable_if<unpacket_traits<RealPacket>::size<=8>::type* = 0)
+{
+ dest.first = pset1<RealPacket>(numext::real(*b));
+ dest.second = pset1<RealPacket>(numext::imag(*b));
+}
+
+template<typename Scalar, typename RealPacket>
+void loadQuadToDoublePacket(const Scalar* b, DoublePacket<RealPacket>& dest,
+ typename enable_if<unpacket_traits<RealPacket>::size==16>::type* = 0)
+{
+ // yes, that's pretty hackish too :(
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ RealScalar r[4] = {numext::real(b[0]), numext::real(b[0]), numext::real(b[1]), numext::real(b[1])};
+ RealScalar i[4] = {numext::imag(b[0]), numext::imag(b[0]), numext::imag(b[1]), numext::imag(b[1])};
+ dest.first = ploadquad<RealPacket>(r);
+ dest.second = ploadquad<RealPacket>(i);
+}
+
+
+template<typename Packet> struct unpacket_traits<DoublePacket<Packet> > {
+ typedef DoublePacket<typename unpacket_traits<Packet>::half> half;
+};
+// template<typename Packet>
+// DoublePacket<Packet> pmadd(const DoublePacket<Packet> &a, const DoublePacket<Packet> &b)
+// {
+// DoublePacket<Packet> res;
+// res.first = padd(a.first, b.first);
+// res.second = padd(a.second,b.second);
+// return res;
+// }
+
+template<typename RealScalar, bool _ConjLhs, bool _ConjRhs, int Arch, int _PacketSize>
+class gebp_traits<std::complex<RealScalar>, std::complex<RealScalar>, _ConjLhs, _ConjRhs, Arch, _PacketSize >
+{
+public:
+ typedef std::complex<RealScalar> Scalar;
+ typedef std::complex<RealScalar> LhsScalar;
+ typedef std::complex<RealScalar> RhsScalar;
+ typedef std::complex<RealScalar> ResScalar;
+
+ PACKET_DECL_COND_PREFIX(_, Lhs, _PacketSize);
+ PACKET_DECL_COND_PREFIX(_, Rhs, _PacketSize);
+ PACKET_DECL_COND_PREFIX(_, Res, _PacketSize);
+ PACKET_DECL_COND(Real, _PacketSize);
+ PACKET_DECL_COND_SCALAR(_PacketSize);
+
+ enum {
+ ConjLhs = _ConjLhs,
+ ConjRhs = _ConjRhs,
+ Vectorizable = unpacket_traits<RealPacket>::vectorizable
+ && unpacket_traits<ScalarPacket>::vectorizable,
+ ResPacketSize = Vectorizable ? unpacket_traits<_ResPacket>::size : 1,
+ LhsPacketSize = Vectorizable ? unpacket_traits<_LhsPacket>::size : 1,
+ RhsPacketSize = Vectorizable ? unpacket_traits<RhsScalar>::size : 1,
+ RealPacketSize = Vectorizable ? unpacket_traits<RealPacket>::size : 1,
+
+ // FIXME: should depend on NumberOfRegisters
+ nr = 4,
+ mr = ResPacketSize,
+
+ LhsProgress = ResPacketSize,
+ RhsProgress = 1
+ };
+
+ typedef DoublePacket<RealPacket> DoublePacketType;
+
+ typedef typename conditional<Vectorizable,ScalarPacket,Scalar>::type LhsPacket4Packing;
+ typedef typename conditional<Vectorizable,RealPacket, Scalar>::type LhsPacket;
+ typedef typename conditional<Vectorizable,DoublePacketType,Scalar>::type RhsPacket;
+ typedef typename conditional<Vectorizable,ScalarPacket,Scalar>::type ResPacket;
+ typedef typename conditional<Vectorizable,DoublePacketType,Scalar>::type AccPacket;
+
+ // this actualy holds 8 packets!
+ typedef QuadPacket<RhsPacket> RhsPacketx4;
+
+ EIGEN_STRONG_INLINE void initAcc(Scalar& p) { p = Scalar(0); }
+
+ EIGEN_STRONG_INLINE void initAcc(DoublePacketType& p)
+ {
+ p.first = pset1<RealPacket>(RealScalar(0));
+ p.second = pset1<RealPacket>(RealScalar(0));
+ }
+
+ // Scalar path
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, ScalarPacket& dest) const
+ {
+ dest = pset1<ScalarPacket>(*b);
+ }
+
+ // Vectorized path
+ template<typename RealPacketType>
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, DoublePacket<RealPacketType>& dest) const
+ {
+ dest.first = pset1<RealPacketType>(numext::real(*b));
+ dest.second = pset1<RealPacketType>(numext::imag(*b));
+ }
+
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const
+ {
+ loadRhs(b, dest.B_0);
+ loadRhs(b + 1, dest.B1);
+ loadRhs(b + 2, dest.B2);
+ loadRhs(b + 3, dest.B3);
+ }
+
+ // Scalar path
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, ScalarPacket& dest) const
+ {
+ loadRhs(b, dest);
+ }
+
+ // Vectorized path
+ template<typename RealPacketType>
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, DoublePacket<RealPacketType>& dest) const
+ {
+ loadRhs(b, dest);
+ }
+
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar*, RhsPacketx4&) const {}
+
+ EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, ResPacket& dest) const
+ {
+ loadRhs(b,dest);
+ }
+ EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, DoublePacketType& dest) const
+ {
+ loadQuadToDoublePacket(b,dest);
+ }
+
+ // nothing special here
+ EIGEN_STRONG_INLINE void loadLhs(const LhsScalar* a, LhsPacket& dest) const
+ {
+ dest = pload<LhsPacket>((const typename unpacket_traits<LhsPacket>::type*)(a));
+ }
+
+ template<typename LhsPacketType>
+ EIGEN_STRONG_INLINE void loadLhsUnaligned(const LhsScalar* a, LhsPacketType& dest) const
+ {
+ dest = ploadu<LhsPacketType>((const typename unpacket_traits<LhsPacketType>::type*)(a));
+ }
+
+ template<typename LhsPacketType, typename RhsPacketType, typename ResPacketType, typename TmpType, typename LaneIdType>
+ EIGEN_STRONG_INLINE
+ typename enable_if<!is_same<RhsPacketType,RhsPacketx4>::value>::type
+ madd(const LhsPacketType& a, const RhsPacketType& b, DoublePacket<ResPacketType>& c, TmpType& /*tmp*/, const LaneIdType&) const
+ {
+ c.first = padd(pmul(a,b.first), c.first);
+ c.second = padd(pmul(a,b.second),c.second);
+ }
+
+ template<typename LaneIdType>
+ EIGEN_STRONG_INLINE void madd(const LhsPacket& a, const RhsPacket& b, ResPacket& c, RhsPacket& /*tmp*/, const LaneIdType&) const
+ {
+ c = cj.pmadd(a,b,c);
+ }
+
+ template<typename LhsPacketType, typename AccPacketType, typename LaneIdType>
+ EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketx4& b, AccPacketType& c, RhsPacket& tmp, const LaneIdType& lane) const
+ {
+ madd(a, b.get(lane), c, tmp, lane);
+ }
+
+ EIGEN_STRONG_INLINE void acc(const Scalar& c, const Scalar& alpha, Scalar& r) const { r += alpha * c; }
+
+ template<typename RealPacketType, typename ResPacketType>
+ EIGEN_STRONG_INLINE void acc(const DoublePacket<RealPacketType>& c, const ResPacketType& alpha, ResPacketType& r) const
+ {
+ // assemble c
+ ResPacketType tmp;
+ if((!ConjLhs)&&(!ConjRhs))
+ {
+ tmp = pcplxflip(pconj(ResPacketType(c.second)));
+ tmp = padd(ResPacketType(c.first),tmp);
+ }
+ else if((!ConjLhs)&&(ConjRhs))
+ {
+ tmp = pconj(pcplxflip(ResPacketType(c.second)));
+ tmp = padd(ResPacketType(c.first),tmp);
+ }
+ else if((ConjLhs)&&(!ConjRhs))
+ {
+ tmp = pcplxflip(ResPacketType(c.second));
+ tmp = padd(pconj(ResPacketType(c.first)),tmp);
+ }
+ else if((ConjLhs)&&(ConjRhs))
+ {
+ tmp = pcplxflip(ResPacketType(c.second));
+ tmp = psub(pconj(ResPacketType(c.first)),tmp);
+ }
+
+ r = pmadd(tmp,alpha,r);
+ }
+
+protected:
+ conj_helper<LhsScalar,RhsScalar,ConjLhs,ConjRhs> cj;
+};
+
+template<typename RealScalar, bool _ConjRhs, int Arch, int _PacketSize>
+class gebp_traits<RealScalar, std::complex<RealScalar>, false, _ConjRhs, Arch, _PacketSize >
+{
+public:
+ typedef std::complex<RealScalar> Scalar;
+ typedef RealScalar LhsScalar;
+ typedef Scalar RhsScalar;
+ typedef Scalar ResScalar;
+
+ PACKET_DECL_COND_PREFIX(_, Lhs, _PacketSize);
+ PACKET_DECL_COND_PREFIX(_, Rhs, _PacketSize);
+ PACKET_DECL_COND_PREFIX(_, Res, _PacketSize);
+ PACKET_DECL_COND_PREFIX(_, Real, _PacketSize);
+ PACKET_DECL_COND_SCALAR_PREFIX(_, _PacketSize);
+
+#undef PACKET_DECL_COND_SCALAR_PREFIX
+#undef PACKET_DECL_COND_PREFIX
+#undef PACKET_DECL_COND_SCALAR
+#undef PACKET_DECL_COND
+
+ enum {
+ ConjLhs = false,
+ ConjRhs = _ConjRhs,
+ Vectorizable = unpacket_traits<_RealPacket>::vectorizable
+ && unpacket_traits<_ScalarPacket>::vectorizable,
+ LhsPacketSize = Vectorizable ? unpacket_traits<_LhsPacket>::size : 1,
+ RhsPacketSize = Vectorizable ? unpacket_traits<_RhsPacket>::size : 1,
+ ResPacketSize = Vectorizable ? unpacket_traits<_ResPacket>::size : 1,
+
+ NumberOfRegisters = EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS,
+ // FIXME: should depend on NumberOfRegisters
+ nr = 4,
+ mr = (EIGEN_PLAIN_ENUM_MIN(16,NumberOfRegisters)/2/nr)*ResPacketSize,
+
+ LhsProgress = ResPacketSize,
+ RhsProgress = 1
+ };
+
+ typedef typename conditional<Vectorizable,_LhsPacket,LhsScalar>::type LhsPacket;
+ typedef typename conditional<Vectorizable,_RhsPacket,RhsScalar>::type RhsPacket;
+ typedef typename conditional<Vectorizable,_ResPacket,ResScalar>::type ResPacket;
+ typedef LhsPacket LhsPacket4Packing;
+ typedef QuadPacket<RhsPacket> RhsPacketx4;
+ typedef ResPacket AccPacket;
+
+ EIGEN_STRONG_INLINE void initAcc(AccPacket& p)
+ {
+ p = pset1<ResPacket>(ResScalar(0));
+ }
+
+ template<typename RhsPacketType>
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketType& dest) const
+ {
+ dest = pset1<RhsPacketType>(*b);
+ }
+
+ EIGEN_STRONG_INLINE void loadRhs(const RhsScalar* b, RhsPacketx4& dest) const
+ {
+ pbroadcast4(b, dest.B_0, dest.B1, dest.B2, dest.B3);
+ }
+
+ template<typename RhsPacketType>
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar* b, RhsPacketType& dest) const
+ {
+ loadRhs(b, dest);
+ }
+
+ EIGEN_STRONG_INLINE void updateRhs(const RhsScalar*, RhsPacketx4&) const
+ {}
+
+ EIGEN_STRONG_INLINE void loadLhs(const LhsScalar* a, LhsPacket& dest) const
+ {
+ dest = ploaddup<LhsPacket>(a);
+ }
+
+ EIGEN_STRONG_INLINE void loadRhsQuad(const RhsScalar* b, RhsPacket& dest) const
+ {
+ dest = ploadquad<RhsPacket>(b);
+ }
+
+ template<typename LhsPacketType>
+ EIGEN_STRONG_INLINE void loadLhsUnaligned(const LhsScalar* a, LhsPacketType& dest) const
+ {
+ dest = ploaddup<LhsPacketType>(a);
+ }
+
+ template <typename LhsPacketType, typename RhsPacketType, typename AccPacketType, typename LaneIdType>
+ EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketType& b, AccPacketType& c, RhsPacketType& tmp, const LaneIdType&) const
+ {
+ madd_impl(a, b, c, tmp, typename conditional<Vectorizable,true_type,false_type>::type());
+ }
+
+ template <typename LhsPacketType, typename RhsPacketType, typename AccPacketType>
+ EIGEN_STRONG_INLINE void madd_impl(const LhsPacketType& a, const RhsPacketType& b, AccPacketType& c, RhsPacketType& tmp, const true_type&) const
+ {
+#ifdef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
+ EIGEN_UNUSED_VARIABLE(tmp);
+ c.v = pmadd(a,b.v,c.v);
+#else
+ tmp = b; tmp.v = pmul(a,tmp.v); c = padd(c,tmp);
+#endif
+
+ }
+
+ EIGEN_STRONG_INLINE void madd_impl(const LhsScalar& a, const RhsScalar& b, ResScalar& c, RhsScalar& /*tmp*/, const false_type&) const
+ {
+ c += a * b;
+ }
+
+ template<typename LhsPacketType, typename AccPacketType, typename LaneIdType>
+ EIGEN_STRONG_INLINE void madd(const LhsPacketType& a, const RhsPacketx4& b, AccPacketType& c, RhsPacket& tmp, const LaneIdType& lane) const
+ {
+ madd(a, b.get(lane), c, tmp, lane);
+ }
+
+ template <typename ResPacketType, typename AccPacketType>
+ EIGEN_STRONG_INLINE void acc(const AccPacketType& c, const ResPacketType& alpha, ResPacketType& r) const
+ {
+ conj_helper<ResPacketType,ResPacketType,false,ConjRhs> cj;
+ r = cj.pmadd(alpha,c,r);
+ }
+
+protected:
+
+};
+
+/* optimized General packed Block * packed Panel product kernel
+ *
+ * Mixing type logic: C += A * B
+ * | A | B | comments
+ * |real |cplx | no vectorization yet, would require to pack A with duplication
+ * |cplx |real | easy vectorization
+ */
+template<typename LhsScalar, typename RhsScalar, typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+struct gebp_kernel
+{
+ typedef gebp_traits<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs,Architecture::Target> Traits;
+ typedef gebp_traits<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs,Architecture::Target,GEBPPacketHalf> HalfTraits;
+ typedef gebp_traits<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs,Architecture::Target,GEBPPacketQuarter> QuarterTraits;
+
+ typedef typename Traits::ResScalar ResScalar;
+ typedef typename Traits::LhsPacket LhsPacket;
+ typedef typename Traits::RhsPacket RhsPacket;
+ typedef typename Traits::ResPacket ResPacket;
+ typedef typename Traits::AccPacket AccPacket;
+ typedef typename Traits::RhsPacketx4 RhsPacketx4;
+
+ typedef typename RhsPanelHelper<RhsPacket, RhsPacketx4, 15>::type RhsPanel15;
+
+ typedef gebp_traits<RhsScalar,LhsScalar,ConjugateRhs,ConjugateLhs,Architecture::Target> SwappedTraits;
+
+ typedef typename SwappedTraits::ResScalar SResScalar;
+ typedef typename SwappedTraits::LhsPacket SLhsPacket;
+ typedef typename SwappedTraits::RhsPacket SRhsPacket;
+ typedef typename SwappedTraits::ResPacket SResPacket;
+ typedef typename SwappedTraits::AccPacket SAccPacket;
+
+ typedef typename HalfTraits::LhsPacket LhsPacketHalf;
+ typedef typename HalfTraits::RhsPacket RhsPacketHalf;
+ typedef typename HalfTraits::ResPacket ResPacketHalf;
+ typedef typename HalfTraits::AccPacket AccPacketHalf;
+
+ typedef typename QuarterTraits::LhsPacket LhsPacketQuarter;
+ typedef typename QuarterTraits::RhsPacket RhsPacketQuarter;
+ typedef typename QuarterTraits::ResPacket ResPacketQuarter;
+ typedef typename QuarterTraits::AccPacket AccPacketQuarter;
+
+ typedef typename DataMapper::LinearMapper LinearMapper;
+
+ enum {
+ Vectorizable = Traits::Vectorizable,
+ LhsProgress = Traits::LhsProgress,
+ LhsProgressHalf = HalfTraits::LhsProgress,
+ LhsProgressQuarter = QuarterTraits::LhsProgress,
+ RhsProgress = Traits::RhsProgress,
+ RhsProgressHalf = HalfTraits::RhsProgress,
+ RhsProgressQuarter = QuarterTraits::RhsProgress,
+ ResPacketSize = Traits::ResPacketSize
+ };
+
+ EIGEN_DONT_INLINE
+ void operator()(const DataMapper& res, const LhsScalar* blockA, const RhsScalar* blockB,
+ Index rows, Index depth, Index cols, ResScalar alpha,
+ Index strideA=-1, Index strideB=-1, Index offsetA=0, Index offsetB=0);
+};
+
+template<typename LhsScalar, typename RhsScalar, typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs,
+int SwappedLhsProgress = gebp_traits<RhsScalar,LhsScalar,ConjugateRhs,ConjugateLhs,Architecture::Target>::LhsProgress>
+struct last_row_process_16_packets
+{
+ typedef gebp_traits<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs,Architecture::Target> Traits;
+ typedef gebp_traits<RhsScalar,LhsScalar,ConjugateRhs,ConjugateLhs,Architecture::Target> SwappedTraits;
+
+ typedef typename Traits::ResScalar ResScalar;
+ typedef typename SwappedTraits::LhsPacket SLhsPacket;
+ typedef typename SwappedTraits::RhsPacket SRhsPacket;
+ typedef typename SwappedTraits::ResPacket SResPacket;
+ typedef typename SwappedTraits::AccPacket SAccPacket;
+
+ EIGEN_STRONG_INLINE void operator()(const DataMapper& res, SwappedTraits &straits, const LhsScalar* blA,
+ const RhsScalar* blB, Index depth, const Index endk, Index i, Index j2,
+ ResScalar alpha, SAccPacket &C0)
+ {
+ EIGEN_UNUSED_VARIABLE(res);
+ EIGEN_UNUSED_VARIABLE(straits);
+ EIGEN_UNUSED_VARIABLE(blA);
+ EIGEN_UNUSED_VARIABLE(blB);
+ EIGEN_UNUSED_VARIABLE(depth);
+ EIGEN_UNUSED_VARIABLE(endk);
+ EIGEN_UNUSED_VARIABLE(i);
+ EIGEN_UNUSED_VARIABLE(j2);
+ EIGEN_UNUSED_VARIABLE(alpha);
+ EIGEN_UNUSED_VARIABLE(C0);
+ }
+};
+
+
+template<typename LhsScalar, typename RhsScalar, typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+struct last_row_process_16_packets<LhsScalar, RhsScalar, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs, 16> {
+ typedef gebp_traits<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs,Architecture::Target> Traits;
+ typedef gebp_traits<RhsScalar,LhsScalar,ConjugateRhs,ConjugateLhs,Architecture::Target> SwappedTraits;
+
+ typedef typename Traits::ResScalar ResScalar;
+ typedef typename SwappedTraits::LhsPacket SLhsPacket;
+ typedef typename SwappedTraits::RhsPacket SRhsPacket;
+ typedef typename SwappedTraits::ResPacket SResPacket;
+ typedef typename SwappedTraits::AccPacket SAccPacket;
+
+ EIGEN_STRONG_INLINE void operator()(const DataMapper& res, SwappedTraits &straits, const LhsScalar* blA,
+ const RhsScalar* blB, Index depth, const Index endk, Index i, Index j2,
+ ResScalar alpha, SAccPacket &C0)
+ {
+ typedef typename unpacket_traits<typename unpacket_traits<SResPacket>::half>::half SResPacketQuarter;
+ typedef typename unpacket_traits<typename unpacket_traits<SLhsPacket>::half>::half SLhsPacketQuarter;
+ typedef typename unpacket_traits<typename unpacket_traits<SRhsPacket>::half>::half SRhsPacketQuarter;
+ typedef typename unpacket_traits<typename unpacket_traits<SAccPacket>::half>::half SAccPacketQuarter;
+
+ SResPacketQuarter R = res.template gatherPacket<SResPacketQuarter>(i, j2);
+ SResPacketQuarter alphav = pset1<SResPacketQuarter>(alpha);
+
+ if (depth - endk > 0)
+ {
+ // We have to handle the last row(s) of the rhs, which
+ // correspond to a half-packet
+ SAccPacketQuarter c0 = predux_half_dowto4(predux_half_dowto4(C0));
+
+ for (Index kk = endk; kk < depth; kk++)
+ {
+ SLhsPacketQuarter a0;
+ SRhsPacketQuarter b0;
+ straits.loadLhsUnaligned(blB, a0);
+ straits.loadRhs(blA, b0);
+ straits.madd(a0,b0,c0,b0, fix<0>);
+ blB += SwappedTraits::LhsProgress/4;
+ blA += 1;
+ }
+ straits.acc(c0, alphav, R);
+ }
+ else
+ {
+ straits.acc(predux_half_dowto4(predux_half_dowto4(C0)), alphav, R);
+ }
+ res.scatterPacket(i, j2, R);
+ }
+};
+
+template<int nr, Index LhsProgress, Index RhsProgress, typename LhsScalar, typename RhsScalar, typename ResScalar, typename AccPacket, typename LhsPacket, typename RhsPacket, typename ResPacket, typename GEBPTraits, typename LinearMapper, typename DataMapper>
+struct lhs_process_one_packet
+{
+ typedef typename GEBPTraits::RhsPacketx4 RhsPacketx4;
+
+ EIGEN_STRONG_INLINE void peeled_kc_onestep(Index K, const LhsScalar* blA, const RhsScalar* blB, GEBPTraits traits, LhsPacket *A0, RhsPacketx4 *rhs_panel, RhsPacket *T0, AccPacket *C0, AccPacket *C1, AccPacket *C2, AccPacket *C3)
+ {
+ EIGEN_ASM_COMMENT("begin step of gebp micro kernel 1X4");
+ EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!");
+ traits.loadLhs(&blA[(0+1*K)*LhsProgress], *A0);
+ traits.loadRhs(&blB[(0+4*K)*RhsProgress], *rhs_panel);
+ traits.madd(*A0, *rhs_panel, *C0, *T0, fix<0>);
+ traits.madd(*A0, *rhs_panel, *C1, *T0, fix<1>);
+ traits.madd(*A0, *rhs_panel, *C2, *T0, fix<2>);
+ traits.madd(*A0, *rhs_panel, *C3, *T0, fix<3>);
+ #if EIGEN_GNUC_AT_LEAST(6,0) && defined(EIGEN_VECTORIZE_SSE)
+ __asm__ ("" : "+x,m" (*A0));
+ #endif
+ EIGEN_ASM_COMMENT("end step of gebp micro kernel 1X4");
+ }
+
+ EIGEN_STRONG_INLINE void operator()(
+ const DataMapper& res, const LhsScalar* blockA, const RhsScalar* blockB, ResScalar alpha,
+ Index peelStart, Index peelEnd, Index strideA, Index strideB, Index offsetA, Index offsetB,
+ int prefetch_res_offset, Index peeled_kc, Index pk, Index cols, Index depth, Index packet_cols4)
+ {
+ GEBPTraits traits;
+
+ // loops on each largest micro horizontal panel of lhs
+ // (LhsProgress x depth)
+ for(Index i=peelStart; i<peelEnd; i+=LhsProgress)
+ {
+ // loops on each largest micro vertical panel of rhs (depth * nr)
+ for(Index j2=0; j2<packet_cols4; j2+=nr)
+ {
+ // We select a LhsProgress x nr micro block of res
+ // which is entirely stored into 1 x nr registers.
+
+ const LhsScalar* blA = &blockA[i*strideA+offsetA*(LhsProgress)];
+ prefetch(&blA[0]);
+
+ // gets res block as register
+ AccPacket C0, C1, C2, C3;
+ traits.initAcc(C0);
+ traits.initAcc(C1);
+ traits.initAcc(C2);
+ traits.initAcc(C3);
+ // To improve instruction pipelining, let's double the accumulation registers:
+ // even k will accumulate in C*, while odd k will accumulate in D*.
+ // This trick is crutial to get good performance with FMA, otherwise it is
+ // actually faster to perform separated MUL+ADD because of a naturally
+ // better instruction-level parallelism.
+ AccPacket D0, D1, D2, D3;
+ traits.initAcc(D0);
+ traits.initAcc(D1);
+ traits.initAcc(D2);
+ traits.initAcc(D3);
+
+ LinearMapper r0 = res.getLinearMapper(i, j2 + 0);
+ LinearMapper r1 = res.getLinearMapper(i, j2 + 1);
+ LinearMapper r2 = res.getLinearMapper(i, j2 + 2);
+ LinearMapper r3 = res.getLinearMapper(i, j2 + 3);
+
+ r0.prefetch(prefetch_res_offset);
+ r1.prefetch(prefetch_res_offset);
+ r2.prefetch(prefetch_res_offset);
+ r3.prefetch(prefetch_res_offset);
+
+ // performs "inner" products
+ const RhsScalar* blB = &blockB[j2*strideB+offsetB*nr];
+ prefetch(&blB[0]);
+ LhsPacket A0, A1;
+
+ for(Index k=0; k<peeled_kc; k+=pk)
+ {
+ EIGEN_ASM_COMMENT("begin gebp micro kernel 1/half/quarterX4");
+ RhsPacketx4 rhs_panel;
+ RhsPacket T0;
+
+ internal::prefetch(blB+(48+0));
+ peeled_kc_onestep(0, blA, blB, traits, &A0, &rhs_panel, &T0, &C0, &C1, &C2, &C3);
+ peeled_kc_onestep(1, blA, blB, traits, &A1, &rhs_panel, &T0, &D0, &D1, &D2, &D3);
+ peeled_kc_onestep(2, blA, blB, traits, &A0, &rhs_panel, &T0, &C0, &C1, &C2, &C3);
+ peeled_kc_onestep(3, blA, blB, traits, &A1, &rhs_panel, &T0, &D0, &D1, &D2, &D3);
+ internal::prefetch(blB+(48+16));
+ peeled_kc_onestep(4, blA, blB, traits, &A0, &rhs_panel, &T0, &C0, &C1, &C2, &C3);
+ peeled_kc_onestep(5, blA, blB, traits, &A1, &rhs_panel, &T0, &D0, &D1, &D2, &D3);
+ peeled_kc_onestep(6, blA, blB, traits, &A0, &rhs_panel, &T0, &C0, &C1, &C2, &C3);
+ peeled_kc_onestep(7, blA, blB, traits, &A1, &rhs_panel, &T0, &D0, &D1, &D2, &D3);
+
+ blB += pk*4*RhsProgress;
+ blA += pk*LhsProgress;
+
+ EIGEN_ASM_COMMENT("end gebp micro kernel 1/half/quarterX4");
+ }
+ C0 = padd(C0,D0);
+ C1 = padd(C1,D1);
+ C2 = padd(C2,D2);
+ C3 = padd(C3,D3);
+
+ // process remaining peeled loop
+ for(Index k=peeled_kc; k<depth; k++)
+ {
+ RhsPacketx4 rhs_panel;
+ RhsPacket T0;
+ peeled_kc_onestep(0, blA, blB, traits, &A0, &rhs_panel, &T0, &C0, &C1, &C2, &C3);
+ blB += 4*RhsProgress;
+ blA += LhsProgress;
+ }
+
+ ResPacket R0, R1;
+ ResPacket alphav = pset1<ResPacket>(alpha);
+
+ R0 = r0.template loadPacket<ResPacket>(0);
+ R1 = r1.template loadPacket<ResPacket>(0);
+ traits.acc(C0, alphav, R0);
+ traits.acc(C1, alphav, R1);
+ r0.storePacket(0, R0);
+ r1.storePacket(0, R1);
+
+ R0 = r2.template loadPacket<ResPacket>(0);
+ R1 = r3.template loadPacket<ResPacket>(0);
+ traits.acc(C2, alphav, R0);
+ traits.acc(C3, alphav, R1);
+ r2.storePacket(0, R0);
+ r3.storePacket(0, R1);
+ }
+
+ // Deal with remaining columns of the rhs
+ for(Index j2=packet_cols4; j2<cols; j2++)
+ {
+ // One column at a time
+ const LhsScalar* blA = &blockA[i*strideA+offsetA*(LhsProgress)];
+ prefetch(&blA[0]);
+
+ // gets res block as register
+ AccPacket C0;
+ traits.initAcc(C0);
+
+ LinearMapper r0 = res.getLinearMapper(i, j2);
+
+ // performs "inner" products
+ const RhsScalar* blB = &blockB[j2*strideB+offsetB];
+ LhsPacket A0;
+
+ for(Index k= 0; k<peeled_kc; k+=pk)
+ {
+ EIGEN_ASM_COMMENT("begin gebp micro kernel 1/half/quarterX1");
+ RhsPacket B_0;
+
+#define EIGEN_GEBGP_ONESTEP(K) \
+ do { \
+ EIGEN_ASM_COMMENT("begin step of gebp micro kernel 1/half/quarterX1"); \
+ EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!"); \
+ /* FIXME: why unaligned???? */ \
+ traits.loadLhsUnaligned(&blA[(0+1*K)*LhsProgress], A0); \
+ traits.loadRhs(&blB[(0+K)*RhsProgress], B_0); \
+ traits.madd(A0, B_0, C0, B_0, fix<0>); \
+ EIGEN_ASM_COMMENT("end step of gebp micro kernel 1/half/quarterX1"); \
+ } while(false);
+
+ EIGEN_GEBGP_ONESTEP(0);
+ EIGEN_GEBGP_ONESTEP(1);
+ EIGEN_GEBGP_ONESTEP(2);
+ EIGEN_GEBGP_ONESTEP(3);
+ EIGEN_GEBGP_ONESTEP(4);
+ EIGEN_GEBGP_ONESTEP(5);
+ EIGEN_GEBGP_ONESTEP(6);
+ EIGEN_GEBGP_ONESTEP(7);
+
+ blB += pk*RhsProgress;
+ blA += pk*LhsProgress;
+
+ EIGEN_ASM_COMMENT("end gebp micro kernel 1/half/quarterX1");
+ }
+
+ // process remaining peeled loop
+ for(Index k=peeled_kc; k<depth; k++)
+ {
+ RhsPacket B_0;
+ EIGEN_GEBGP_ONESTEP(0);
+ blB += RhsProgress;
+ blA += LhsProgress;
+ }
+#undef EIGEN_GEBGP_ONESTEP
+ ResPacket R0;
+ ResPacket alphav = pset1<ResPacket>(alpha);
+ R0 = r0.template loadPacket<ResPacket>(0);
+ traits.acc(C0, alphav, R0);
+ r0.storePacket(0, R0);
+ }
+ }
+ }
+};
+
+template<int nr, Index LhsProgress, Index RhsProgress, typename LhsScalar, typename RhsScalar, typename ResScalar, typename AccPacket, typename LhsPacket, typename RhsPacket, typename ResPacket, typename GEBPTraits, typename LinearMapper, typename DataMapper>
+struct lhs_process_fraction_of_packet : lhs_process_one_packet<nr, LhsProgress, RhsProgress, LhsScalar, RhsScalar, ResScalar, AccPacket, LhsPacket, RhsPacket, ResPacket, GEBPTraits, LinearMapper, DataMapper>
+{
+
+EIGEN_STRONG_INLINE void peeled_kc_onestep(Index K, const LhsScalar* blA, const RhsScalar* blB, GEBPTraits traits, LhsPacket *A0, RhsPacket *B_0, RhsPacket *B1, RhsPacket *B2, RhsPacket *B3, AccPacket *C0, AccPacket *C1, AccPacket *C2, AccPacket *C3)
+ {
+ EIGEN_ASM_COMMENT("begin step of gebp micro kernel 1X4");
+ EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!");
+ traits.loadLhsUnaligned(&blA[(0+1*K)*(LhsProgress)], *A0);
+ traits.broadcastRhs(&blB[(0+4*K)*RhsProgress], *B_0, *B1, *B2, *B3);
+ traits.madd(*A0, *B_0, *C0, *B_0);
+ traits.madd(*A0, *B1, *C1, *B1);
+ traits.madd(*A0, *B2, *C2, *B2);
+ traits.madd(*A0, *B3, *C3, *B3);
+ EIGEN_ASM_COMMENT("end step of gebp micro kernel 1X4");
+ }
+};
+
+template<typename LhsScalar, typename RhsScalar, typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs, bool ConjugateRhs>
+EIGEN_DONT_INLINE
+void gebp_kernel<LhsScalar,RhsScalar,Index,DataMapper,mr,nr,ConjugateLhs,ConjugateRhs>
+ ::operator()(const DataMapper& res, const LhsScalar* blockA, const RhsScalar* blockB,
+ Index rows, Index depth, Index cols, ResScalar alpha,
+ Index strideA, Index strideB, Index offsetA, Index offsetB)
+ {
+ Traits traits;
+ SwappedTraits straits;
+
+ if(strideA==-1) strideA = depth;
+ if(strideB==-1) strideB = depth;
+ conj_helper<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs> cj;
+ Index packet_cols4 = nr>=4 ? (cols/4) * 4 : 0;
+ const Index peeled_mc3 = mr>=3*Traits::LhsProgress ? (rows/(3*LhsProgress))*(3*LhsProgress) : 0;
+ const Index peeled_mc2 = mr>=2*Traits::LhsProgress ? peeled_mc3+((rows-peeled_mc3)/(2*LhsProgress))*(2*LhsProgress) : 0;
+ const Index peeled_mc1 = mr>=1*Traits::LhsProgress ? peeled_mc2+((rows-peeled_mc2)/(1*LhsProgress))*(1*LhsProgress) : 0;
+ const Index peeled_mc_half = mr>=LhsProgressHalf ? peeled_mc1+((rows-peeled_mc1)/(LhsProgressHalf))*(LhsProgressHalf) : 0;
+ const Index peeled_mc_quarter = mr>=LhsProgressQuarter ? peeled_mc_half+((rows-peeled_mc_half)/(LhsProgressQuarter))*(LhsProgressQuarter) : 0;
+ enum { pk = 8 }; // NOTE Such a large peeling factor is important for large matrices (~ +5% when >1000 on Haswell)
+ const Index peeled_kc = depth & ~(pk-1);
+ const int prefetch_res_offset = 32/sizeof(ResScalar);
+// const Index depth2 = depth & ~1;
+
+ //---------- Process 3 * LhsProgress rows at once ----------
+ // This corresponds to 3*LhsProgress x nr register blocks.
+ // Usually, make sense only with FMA
+ if(mr>=3*Traits::LhsProgress)
+ {
+ // Here, the general idea is to loop on each largest micro horizontal panel of the lhs (3*Traits::LhsProgress x depth)
+ // and on each largest micro vertical panel of the rhs (depth * nr).
+ // Blocking sizes, i.e., 'depth' has been computed so that the micro horizontal panel of the lhs fit in L1.
+ // However, if depth is too small, we can extend the number of rows of these horizontal panels.
+ // This actual number of rows is computed as follow:
+ const Index l1 = defaultL1CacheSize; // in Bytes, TODO, l1 should be passed to this function.
+ // The max(1, ...) here is needed because we may be using blocking params larger than what our known l1 cache size
+ // suggests we should be using: either because our known l1 cache size is inaccurate (e.g. on Android, we can only guess),
+ // or because we are testing specific blocking sizes.
+ const Index actual_panel_rows = (3*LhsProgress) * std::max<Index>(1,( (l1 - sizeof(ResScalar)*mr*nr - depth*nr*sizeof(RhsScalar)) / (depth * sizeof(LhsScalar) * 3*LhsProgress) ));
+ for(Index i1=0; i1<peeled_mc3; i1+=actual_panel_rows)
+ {
+ const Index actual_panel_end = (std::min)(i1+actual_panel_rows, peeled_mc3);
+ for(Index j2=0; j2<packet_cols4; j2+=nr)
+ {
+ for(Index i=i1; i<actual_panel_end; i+=3*LhsProgress)
+ {
+
+ // We selected a 3*Traits::LhsProgress x nr micro block of res which is entirely
+ // stored into 3 x nr registers.
+
+ const LhsScalar* blA = &blockA[i*strideA+offsetA*(3*LhsProgress)];
+ prefetch(&blA[0]);
+
+ // gets res block as register
+ AccPacket C0, C1, C2, C3,
+ C4, C5, C6, C7,
+ C8, C9, C10, C11;
+ traits.initAcc(C0); traits.initAcc(C1); traits.initAcc(C2); traits.initAcc(C3);
+ traits.initAcc(C4); traits.initAcc(C5); traits.initAcc(C6); traits.initAcc(C7);
+ traits.initAcc(C8); traits.initAcc(C9); traits.initAcc(C10); traits.initAcc(C11);
+
+ LinearMapper r0 = res.getLinearMapper(i, j2 + 0);
+ LinearMapper r1 = res.getLinearMapper(i, j2 + 1);
+ LinearMapper r2 = res.getLinearMapper(i, j2 + 2);
+ LinearMapper r3 = res.getLinearMapper(i, j2 + 3);
+
+ r0.prefetch(0);
+ r1.prefetch(0);
+ r2.prefetch(0);
+ r3.prefetch(0);
+
+ // performs "inner" products
+ const RhsScalar* blB = &blockB[j2*strideB+offsetB*nr];
+ prefetch(&blB[0]);
+ LhsPacket A0, A1;
+
+ for(Index k=0; k<peeled_kc; k+=pk)
+ {
+ EIGEN_ASM_COMMENT("begin gebp micro kernel 3pX4");
+ // 15 registers are taken (12 for acc, 2 for lhs).
+ RhsPanel15 rhs_panel;
+ RhsPacket T0;
+ LhsPacket A2;
+ #if EIGEN_COMP_GNUC_STRICT && EIGEN_ARCH_ARM64 && defined(EIGEN_VECTORIZE_NEON) && !(EIGEN_GNUC_AT_LEAST(9,0))
+ // see http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1633
+ // without this workaround A0, A1, and A2 are loaded in the same register,
+ // which is not good for pipelining
+ #define EIGEN_GEBP_3PX4_REGISTER_ALLOC_WORKAROUND __asm__ ("" : "+w,m" (A0), "+w,m" (A1), "+w,m" (A2));
+ #else
+ #define EIGEN_GEBP_3PX4_REGISTER_ALLOC_WORKAROUND
+ #endif
+#define EIGEN_GEBP_ONESTEP(K) \
+ do { \
+ EIGEN_ASM_COMMENT("begin step of gebp micro kernel 3pX4"); \
+ EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!"); \
+ internal::prefetch(blA + (3 * K + 16) * LhsProgress); \
+ if (EIGEN_ARCH_ARM || EIGEN_ARCH_MIPS) { \
+ internal::prefetch(blB + (4 * K + 16) * RhsProgress); \
+ } /* Bug 953 */ \
+ traits.loadLhs(&blA[(0 + 3 * K) * LhsProgress], A0); \
+ traits.loadLhs(&blA[(1 + 3 * K) * LhsProgress], A1); \
+ traits.loadLhs(&blA[(2 + 3 * K) * LhsProgress], A2); \
+ EIGEN_GEBP_3PX4_REGISTER_ALLOC_WORKAROUND \
+ traits.loadRhs(blB + (0+4*K) * Traits::RhsProgress, rhs_panel); \
+ traits.madd(A0, rhs_panel, C0, T0, fix<0>); \
+ traits.madd(A1, rhs_panel, C4, T0, fix<0>); \
+ traits.madd(A2, rhs_panel, C8, T0, fix<0>); \
+ traits.updateRhs(blB + (1+4*K) * Traits::RhsProgress, rhs_panel); \
+ traits.madd(A0, rhs_panel, C1, T0, fix<1>); \
+ traits.madd(A1, rhs_panel, C5, T0, fix<1>); \
+ traits.madd(A2, rhs_panel, C9, T0, fix<1>); \
+ traits.updateRhs(blB + (2+4*K) * Traits::RhsProgress, rhs_panel); \
+ traits.madd(A0, rhs_panel, C2, T0, fix<2>); \
+ traits.madd(A1, rhs_panel, C6, T0, fix<2>); \
+ traits.madd(A2, rhs_panel, C10, T0, fix<2>); \
+ traits.updateRhs(blB + (3+4*K) * Traits::RhsProgress, rhs_panel); \
+ traits.madd(A0, rhs_panel, C3, T0, fix<3>); \
+ traits.madd(A1, rhs_panel, C7, T0, fix<3>); \
+ traits.madd(A2, rhs_panel, C11, T0, fix<3>); \
+ EIGEN_ASM_COMMENT("end step of gebp micro kernel 3pX4"); \
+ } while (false)
+
+ internal::prefetch(blB);
+ EIGEN_GEBP_ONESTEP(0);
+ EIGEN_GEBP_ONESTEP(1);
+ EIGEN_GEBP_ONESTEP(2);
+ EIGEN_GEBP_ONESTEP(3);
+ EIGEN_GEBP_ONESTEP(4);
+ EIGEN_GEBP_ONESTEP(5);
+ EIGEN_GEBP_ONESTEP(6);
+ EIGEN_GEBP_ONESTEP(7);
+
+ blB += pk*4*RhsProgress;
+ blA += pk*3*Traits::LhsProgress;
+
+ EIGEN_ASM_COMMENT("end gebp micro kernel 3pX4");
+ }
+ // process remaining peeled loop
+ for(Index k=peeled_kc; k<depth; k++)
+ {
+ RhsPanel15 rhs_panel;
+ RhsPacket T0;
+ LhsPacket A2;
+ EIGEN_GEBP_ONESTEP(0);
+ blB += 4*RhsProgress;
+ blA += 3*Traits::LhsProgress;
+ }
+
+#undef EIGEN_GEBP_ONESTEP
+
+ ResPacket R0, R1, R2;
+ ResPacket alphav = pset1<ResPacket>(alpha);
+
+ R0 = r0.template loadPacket<ResPacket>(0 * Traits::ResPacketSize);
+ R1 = r0.template loadPacket<ResPacket>(1 * Traits::ResPacketSize);
+ R2 = r0.template loadPacket<ResPacket>(2 * Traits::ResPacketSize);
+ traits.acc(C0, alphav, R0);
+ traits.acc(C4, alphav, R1);
+ traits.acc(C8, alphav, R2);
+ r0.storePacket(0 * Traits::ResPacketSize, R0);
+ r0.storePacket(1 * Traits::ResPacketSize, R1);
+ r0.storePacket(2 * Traits::ResPacketSize, R2);
+
+ R0 = r1.template loadPacket<ResPacket>(0 * Traits::ResPacketSize);
+ R1 = r1.template loadPacket<ResPacket>(1 * Traits::ResPacketSize);
+ R2 = r1.template loadPacket<ResPacket>(2 * Traits::ResPacketSize);
+ traits.acc(C1, alphav, R0);
+ traits.acc(C5, alphav, R1);
+ traits.acc(C9, alphav, R2);
+ r1.storePacket(0 * Traits::ResPacketSize, R0);
+ r1.storePacket(1 * Traits::ResPacketSize, R1);
+ r1.storePacket(2 * Traits::ResPacketSize, R2);
+
+ R0 = r2.template loadPacket<ResPacket>(0 * Traits::ResPacketSize);
+ R1 = r2.template loadPacket<ResPacket>(1 * Traits::ResPacketSize);
+ R2 = r2.template loadPacket<ResPacket>(2 * Traits::ResPacketSize);
+ traits.acc(C2, alphav, R0);
+ traits.acc(C6, alphav, R1);
+ traits.acc(C10, alphav, R2);
+ r2.storePacket(0 * Traits::ResPacketSize, R0);
+ r2.storePacket(1 * Traits::ResPacketSize, R1);
+ r2.storePacket(2 * Traits::ResPacketSize, R2);
+
+ R0 = r3.template loadPacket<ResPacket>(0 * Traits::ResPacketSize);
+ R1 = r3.template loadPacket<ResPacket>(1 * Traits::ResPacketSize);
+ R2 = r3.template loadPacket<ResPacket>(2 * Traits::ResPacketSize);
+ traits.acc(C3, alphav, R0);
+ traits.acc(C7, alphav, R1);
+ traits.acc(C11, alphav, R2);
+ r3.storePacket(0 * Traits::ResPacketSize, R0);
+ r3.storePacket(1 * Traits::ResPacketSize, R1);
+ r3.storePacket(2 * Traits::ResPacketSize, R2);
+ }
+ }
+
+ // Deal with remaining columns of the rhs
+ for(Index j2=packet_cols4; j2<cols; j2++)
+ {
+ for(Index i=i1; i<actual_panel_end; i+=3*LhsProgress)
+ {
+ // One column at a time
+ const LhsScalar* blA = &blockA[i*strideA+offsetA*(3*Traits::LhsProgress)];
+ prefetch(&blA[0]);
+
+ // gets res block as register
+ AccPacket C0, C4, C8;
+ traits.initAcc(C0);
+ traits.initAcc(C4);
+ traits.initAcc(C8);
+
+ LinearMapper r0 = res.getLinearMapper(i, j2);
+ r0.prefetch(0);
+
+ // performs "inner" products
+ const RhsScalar* blB = &blockB[j2*strideB+offsetB];
+ LhsPacket A0, A1, A2;
+
+ for(Index k=0; k<peeled_kc; k+=pk)
+ {
+ EIGEN_ASM_COMMENT("begin gebp micro kernel 3pX1");
+ RhsPacket B_0;
+#define EIGEN_GEBGP_ONESTEP(K) \
+ do { \
+ EIGEN_ASM_COMMENT("begin step of gebp micro kernel 3pX1"); \
+ EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!"); \
+ traits.loadLhs(&blA[(0 + 3 * K) * LhsProgress], A0); \
+ traits.loadLhs(&blA[(1 + 3 * K) * LhsProgress], A1); \
+ traits.loadLhs(&blA[(2 + 3 * K) * LhsProgress], A2); \
+ traits.loadRhs(&blB[(0 + K) * RhsProgress], B_0); \
+ traits.madd(A0, B_0, C0, B_0, fix<0>); \
+ traits.madd(A1, B_0, C4, B_0, fix<0>); \
+ traits.madd(A2, B_0, C8, B_0, fix<0>); \
+ EIGEN_ASM_COMMENT("end step of gebp micro kernel 3pX1"); \
+ } while (false)
+
+ EIGEN_GEBGP_ONESTEP(0);
+ EIGEN_GEBGP_ONESTEP(1);
+ EIGEN_GEBGP_ONESTEP(2);
+ EIGEN_GEBGP_ONESTEP(3);
+ EIGEN_GEBGP_ONESTEP(4);
+ EIGEN_GEBGP_ONESTEP(5);
+ EIGEN_GEBGP_ONESTEP(6);
+ EIGEN_GEBGP_ONESTEP(7);
+
+ blB += int(pk) * int(RhsProgress);
+ blA += int(pk) * 3 * int(Traits::LhsProgress);
+
+ EIGEN_ASM_COMMENT("end gebp micro kernel 3pX1");
+ }
+
+ // process remaining peeled loop
+ for(Index k=peeled_kc; k<depth; k++)
+ {
+ RhsPacket B_0;
+ EIGEN_GEBGP_ONESTEP(0);
+ blB += RhsProgress;
+ blA += 3*Traits::LhsProgress;
+ }
+#undef EIGEN_GEBGP_ONESTEP
+ ResPacket R0, R1, R2;
+ ResPacket alphav = pset1<ResPacket>(alpha);
+
+ R0 = r0.template loadPacket<ResPacket>(0 * Traits::ResPacketSize);
+ R1 = r0.template loadPacket<ResPacket>(1 * Traits::ResPacketSize);
+ R2 = r0.template loadPacket<ResPacket>(2 * Traits::ResPacketSize);
+ traits.acc(C0, alphav, R0);
+ traits.acc(C4, alphav, R1);
+ traits.acc(C8, alphav, R2);
+ r0.storePacket(0 * Traits::ResPacketSize, R0);
+ r0.storePacket(1 * Traits::ResPacketSize, R1);
+ r0.storePacket(2 * Traits::ResPacketSize, R2);
+ }
+ }
+ }
+ }
+
+ //---------- Process 2 * LhsProgress rows at once ----------
+ if(mr>=2*Traits::LhsProgress)
+ {
+ const Index l1 = defaultL1CacheSize; // in Bytes, TODO, l1 should be passed to this function.
+ // The max(1, ...) here is needed because we may be using blocking params larger than what our known l1 cache size
+ // suggests we should be using: either because our known l1 cache size is inaccurate (e.g. on Android, we can only guess),
+ // or because we are testing specific blocking sizes.
+ Index actual_panel_rows = (2*LhsProgress) * std::max<Index>(1,( (l1 - sizeof(ResScalar)*mr*nr - depth*nr*sizeof(RhsScalar)) / (depth * sizeof(LhsScalar) * 2*LhsProgress) ));
+
+ for(Index i1=peeled_mc3; i1<peeled_mc2; i1+=actual_panel_rows)
+ {
+ Index actual_panel_end = (std::min)(i1+actual_panel_rows, peeled_mc2);
+ for(Index j2=0; j2<packet_cols4; j2+=nr)
+ {
+ for(Index i=i1; i<actual_panel_end; i+=2*LhsProgress)
+ {
+
+ // We selected a 2*Traits::LhsProgress x nr micro block of res which is entirely
+ // stored into 2 x nr registers.
+
+ const LhsScalar* blA = &blockA[i*strideA+offsetA*(2*Traits::LhsProgress)];
+ prefetch(&blA[0]);
+
+ // gets res block as register
+ AccPacket C0, C1, C2, C3,
+ C4, C5, C6, C7;
+ traits.initAcc(C0); traits.initAcc(C1); traits.initAcc(C2); traits.initAcc(C3);
+ traits.initAcc(C4); traits.initAcc(C5); traits.initAcc(C6); traits.initAcc(C7);
+
+ LinearMapper r0 = res.getLinearMapper(i, j2 + 0);
+ LinearMapper r1 = res.getLinearMapper(i, j2 + 1);
+ LinearMapper r2 = res.getLinearMapper(i, j2 + 2);
+ LinearMapper r3 = res.getLinearMapper(i, j2 + 3);
+
+ r0.prefetch(prefetch_res_offset);
+ r1.prefetch(prefetch_res_offset);
+ r2.prefetch(prefetch_res_offset);
+ r3.prefetch(prefetch_res_offset);
+
+ // performs "inner" products
+ const RhsScalar* blB = &blockB[j2*strideB+offsetB*nr];
+ prefetch(&blB[0]);
+ LhsPacket A0, A1;
+
+ for(Index k=0; k<peeled_kc; k+=pk)
+ {
+ EIGEN_ASM_COMMENT("begin gebp micro kernel 2pX4");
+ RhsPacketx4 rhs_panel;
+ RhsPacket T0;
+
+ // NOTE: the begin/end asm comments below work around bug 935!
+ // but they are not enough for gcc>=6 without FMA (bug 1637)
+ #if EIGEN_GNUC_AT_LEAST(6,0) && defined(EIGEN_VECTORIZE_SSE)
+ #define EIGEN_GEBP_2PX4_SPILLING_WORKAROUND __asm__ ("" : [a0] "+x,m" (A0),[a1] "+x,m" (A1));
+ #else
+ #define EIGEN_GEBP_2PX4_SPILLING_WORKAROUND
+ #endif
+#define EIGEN_GEBGP_ONESTEP(K) \
+ do { \
+ EIGEN_ASM_COMMENT("begin step of gebp micro kernel 2pX4"); \
+ traits.loadLhs(&blA[(0 + 2 * K) * LhsProgress], A0); \
+ traits.loadLhs(&blA[(1 + 2 * K) * LhsProgress], A1); \
+ traits.loadRhs(&blB[(0 + 4 * K) * RhsProgress], rhs_panel); \
+ traits.madd(A0, rhs_panel, C0, T0, fix<0>); \
+ traits.madd(A1, rhs_panel, C4, T0, fix<0>); \
+ traits.madd(A0, rhs_panel, C1, T0, fix<1>); \
+ traits.madd(A1, rhs_panel, C5, T0, fix<1>); \
+ traits.madd(A0, rhs_panel, C2, T0, fix<2>); \
+ traits.madd(A1, rhs_panel, C6, T0, fix<2>); \
+ traits.madd(A0, rhs_panel, C3, T0, fix<3>); \
+ traits.madd(A1, rhs_panel, C7, T0, fix<3>); \
+ EIGEN_GEBP_2PX4_SPILLING_WORKAROUND \
+ EIGEN_ASM_COMMENT("end step of gebp micro kernel 2pX4"); \
+ } while (false)
+
+ internal::prefetch(blB+(48+0));
+ EIGEN_GEBGP_ONESTEP(0);
+ EIGEN_GEBGP_ONESTEP(1);
+ EIGEN_GEBGP_ONESTEP(2);
+ EIGEN_GEBGP_ONESTEP(3);
+ internal::prefetch(blB+(48+16));
+ EIGEN_GEBGP_ONESTEP(4);
+ EIGEN_GEBGP_ONESTEP(5);
+ EIGEN_GEBGP_ONESTEP(6);
+ EIGEN_GEBGP_ONESTEP(7);
+
+ blB += pk*4*RhsProgress;
+ blA += pk*(2*Traits::LhsProgress);
+
+ EIGEN_ASM_COMMENT("end gebp micro kernel 2pX4");
+ }
+ // process remaining peeled loop
+ for(Index k=peeled_kc; k<depth; k++)
+ {
+ RhsPacketx4 rhs_panel;
+ RhsPacket T0;
+ EIGEN_GEBGP_ONESTEP(0);
+ blB += 4*RhsProgress;
+ blA += 2*Traits::LhsProgress;
+ }
+#undef EIGEN_GEBGP_ONESTEP
+
+ ResPacket R0, R1, R2, R3;
+ ResPacket alphav = pset1<ResPacket>(alpha);
+
+ R0 = r0.template loadPacket<ResPacket>(0 * Traits::ResPacketSize);
+ R1 = r0.template loadPacket<ResPacket>(1 * Traits::ResPacketSize);
+ R2 = r1.template loadPacket<ResPacket>(0 * Traits::ResPacketSize);
+ R3 = r1.template loadPacket<ResPacket>(1 * Traits::ResPacketSize);
+ traits.acc(C0, alphav, R0);
+ traits.acc(C4, alphav, R1);
+ traits.acc(C1, alphav, R2);
+ traits.acc(C5, alphav, R3);
+ r0.storePacket(0 * Traits::ResPacketSize, R0);
+ r0.storePacket(1 * Traits::ResPacketSize, R1);
+ r1.storePacket(0 * Traits::ResPacketSize, R2);
+ r1.storePacket(1 * Traits::ResPacketSize, R3);
+
+ R0 = r2.template loadPacket<ResPacket>(0 * Traits::ResPacketSize);
+ R1 = r2.template loadPacket<ResPacket>(1 * Traits::ResPacketSize);
+ R2 = r3.template loadPacket<ResPacket>(0 * Traits::ResPacketSize);
+ R3 = r3.template loadPacket<ResPacket>(1 * Traits::ResPacketSize);
+ traits.acc(C2, alphav, R0);
+ traits.acc(C6, alphav, R1);
+ traits.acc(C3, alphav, R2);
+ traits.acc(C7, alphav, R3);
+ r2.storePacket(0 * Traits::ResPacketSize, R0);
+ r2.storePacket(1 * Traits::ResPacketSize, R1);
+ r3.storePacket(0 * Traits::ResPacketSize, R2);
+ r3.storePacket(1 * Traits::ResPacketSize, R3);
+ }
+ }
+
+ // Deal with remaining columns of the rhs
+ for(Index j2=packet_cols4; j2<cols; j2++)
+ {
+ for(Index i=i1; i<actual_panel_end; i+=2*LhsProgress)
+ {
+ // One column at a time
+ const LhsScalar* blA = &blockA[i*strideA+offsetA*(2*Traits::LhsProgress)];
+ prefetch(&blA[0]);
+
+ // gets res block as register
+ AccPacket C0, C4;
+ traits.initAcc(C0);
+ traits.initAcc(C4);
+
+ LinearMapper r0 = res.getLinearMapper(i, j2);
+ r0.prefetch(prefetch_res_offset);
+
+ // performs "inner" products
+ const RhsScalar* blB = &blockB[j2*strideB+offsetB];
+ LhsPacket A0, A1;
+
+ for(Index k=0; k<peeled_kc; k+=pk)
+ {
+ EIGEN_ASM_COMMENT("begin gebp micro kernel 2pX1");
+ RhsPacket B_0, B1;
+
+#define EIGEN_GEBGP_ONESTEP(K) \
+ do { \
+ EIGEN_ASM_COMMENT("begin step of gebp micro kernel 2pX1"); \
+ EIGEN_ASM_COMMENT("Note: these asm comments work around bug 935!"); \
+ traits.loadLhs(&blA[(0+2*K)*LhsProgress], A0); \
+ traits.loadLhs(&blA[(1+2*K)*LhsProgress], A1); \
+ traits.loadRhs(&blB[(0+K)*RhsProgress], B_0); \
+ traits.madd(A0, B_0, C0, B1, fix<0>); \
+ traits.madd(A1, B_0, C4, B_0, fix<0>); \
+ EIGEN_ASM_COMMENT("end step of gebp micro kernel 2pX1"); \
+ } while(false)
+
+ EIGEN_GEBGP_ONESTEP(0);
+ EIGEN_GEBGP_ONESTEP(1);
+ EIGEN_GEBGP_ONESTEP(2);
+ EIGEN_GEBGP_ONESTEP(3);
+ EIGEN_GEBGP_ONESTEP(4);
+ EIGEN_GEBGP_ONESTEP(5);
+ EIGEN_GEBGP_ONESTEP(6);
+ EIGEN_GEBGP_ONESTEP(7);
+
+ blB += int(pk) * int(RhsProgress);
+ blA += int(pk) * 2 * int(Traits::LhsProgress);
+
+ EIGEN_ASM_COMMENT("end gebp micro kernel 2pX1");
+ }
+
+ // process remaining peeled loop
+ for(Index k=peeled_kc; k<depth; k++)
+ {
+ RhsPacket B_0, B1;
+ EIGEN_GEBGP_ONESTEP(0);
+ blB += RhsProgress;
+ blA += 2*Traits::LhsProgress;
+ }
+#undef EIGEN_GEBGP_ONESTEP
+ ResPacket R0, R1;
+ ResPacket alphav = pset1<ResPacket>(alpha);
+
+ R0 = r0.template loadPacket<ResPacket>(0 * Traits::ResPacketSize);
+ R1 = r0.template loadPacket<ResPacket>(1 * Traits::ResPacketSize);
+ traits.acc(C0, alphav, R0);
+ traits.acc(C4, alphav, R1);
+ r0.storePacket(0 * Traits::ResPacketSize, R0);
+ r0.storePacket(1 * Traits::ResPacketSize, R1);
+ }
+ }
+ }
+ }
+ //---------- Process 1 * LhsProgress rows at once ----------
+ if(mr>=1*Traits::LhsProgress)
+ {
+ lhs_process_one_packet<nr, LhsProgress, RhsProgress, LhsScalar, RhsScalar, ResScalar, AccPacket, LhsPacket, RhsPacket, ResPacket, Traits, LinearMapper, DataMapper> p;
+ p(res, blockA, blockB, alpha, peeled_mc2, peeled_mc1, strideA, strideB, offsetA, offsetB, prefetch_res_offset, peeled_kc, pk, cols, depth, packet_cols4);
+ }
+ //---------- Process LhsProgressHalf rows at once ----------
+ if((LhsProgressHalf < LhsProgress) && mr>=LhsProgressHalf)
+ {
+ lhs_process_fraction_of_packet<nr, LhsProgressHalf, RhsProgressHalf, LhsScalar, RhsScalar, ResScalar, AccPacketHalf, LhsPacketHalf, RhsPacketHalf, ResPacketHalf, HalfTraits, LinearMapper, DataMapper> p;
+ p(res, blockA, blockB, alpha, peeled_mc1, peeled_mc_half, strideA, strideB, offsetA, offsetB, prefetch_res_offset, peeled_kc, pk, cols, depth, packet_cols4);
+ }
+ //---------- Process LhsProgressQuarter rows at once ----------
+ if((LhsProgressQuarter < LhsProgressHalf) && mr>=LhsProgressQuarter)
+ {
+ lhs_process_fraction_of_packet<nr, LhsProgressQuarter, RhsProgressQuarter, LhsScalar, RhsScalar, ResScalar, AccPacketQuarter, LhsPacketQuarter, RhsPacketQuarter, ResPacketQuarter, QuarterTraits, LinearMapper, DataMapper> p;
+ p(res, blockA, blockB, alpha, peeled_mc_half, peeled_mc_quarter, strideA, strideB, offsetA, offsetB, prefetch_res_offset, peeled_kc, pk, cols, depth, packet_cols4);
+ }
+ //---------- Process remaining rows, 1 at once ----------
+ if(peeled_mc_quarter<rows)
+ {
+ // loop on each panel of the rhs
+ for(Index j2=0; j2<packet_cols4; j2+=nr)
+ {
+ // loop on each row of the lhs (1*LhsProgress x depth)
+ for(Index i=peeled_mc_quarter; i<rows; i+=1)
+ {
+ const LhsScalar* blA = &blockA[i*strideA+offsetA];
+ prefetch(&blA[0]);
+ const RhsScalar* blB = &blockB[j2*strideB+offsetB*nr];
+
+ // If LhsProgress is 8 or 16, it assumes that there is a
+ // half or quarter packet, respectively, of the same size as
+ // nr (which is currently 4) for the return type.
+ const int SResPacketHalfSize = unpacket_traits<typename unpacket_traits<SResPacket>::half>::size;
+ const int SResPacketQuarterSize = unpacket_traits<typename unpacket_traits<typename unpacket_traits<SResPacket>::half>::half>::size;
+ if ((SwappedTraits::LhsProgress % 4) == 0 &&
+ (SwappedTraits::LhsProgress<=16) &&
+ (SwappedTraits::LhsProgress!=8 || SResPacketHalfSize==nr) &&
+ (SwappedTraits::LhsProgress!=16 || SResPacketQuarterSize==nr))
+ {
+ SAccPacket C0, C1, C2, C3;
+ straits.initAcc(C0);
+ straits.initAcc(C1);
+ straits.initAcc(C2);
+ straits.initAcc(C3);
+
+ const Index spk = (std::max)(1,SwappedTraits::LhsProgress/4);
+ const Index endk = (depth/spk)*spk;
+ const Index endk4 = (depth/(spk*4))*(spk*4);
+
+ Index k=0;
+ for(; k<endk4; k+=4*spk)
+ {
+ SLhsPacket A0,A1;
+ SRhsPacket B_0,B_1;
+
+ straits.loadLhsUnaligned(blB+0*SwappedTraits::LhsProgress, A0);
+ straits.loadLhsUnaligned(blB+1*SwappedTraits::LhsProgress, A1);
+
+ straits.loadRhsQuad(blA+0*spk, B_0);
+ straits.loadRhsQuad(blA+1*spk, B_1);
+ straits.madd(A0,B_0,C0,B_0, fix<0>);
+ straits.madd(A1,B_1,C1,B_1, fix<0>);
+
+ straits.loadLhsUnaligned(blB+2*SwappedTraits::LhsProgress, A0);
+ straits.loadLhsUnaligned(blB+3*SwappedTraits::LhsProgress, A1);
+ straits.loadRhsQuad(blA+2*spk, B_0);
+ straits.loadRhsQuad(blA+3*spk, B_1);
+ straits.madd(A0,B_0,C2,B_0, fix<0>);
+ straits.madd(A1,B_1,C3,B_1, fix<0>);
+
+ blB += 4*SwappedTraits::LhsProgress;
+ blA += 4*spk;
+ }
+ C0 = padd(padd(C0,C1),padd(C2,C3));
+ for(; k<endk; k+=spk)
+ {
+ SLhsPacket A0;
+ SRhsPacket B_0;
+
+ straits.loadLhsUnaligned(blB, A0);
+ straits.loadRhsQuad(blA, B_0);
+ straits.madd(A0,B_0,C0,B_0, fix<0>);
+
+ blB += SwappedTraits::LhsProgress;
+ blA += spk;
+ }
+ if(SwappedTraits::LhsProgress==8)
+ {
+ // Special case where we have to first reduce the accumulation register C0
+ typedef typename conditional<SwappedTraits::LhsProgress>=8,typename unpacket_traits<SResPacket>::half,SResPacket>::type SResPacketHalf;
+ typedef typename conditional<SwappedTraits::LhsProgress>=8,typename unpacket_traits<SLhsPacket>::half,SLhsPacket>::type SLhsPacketHalf;
+ typedef typename conditional<SwappedTraits::LhsProgress>=8,typename unpacket_traits<SRhsPacket>::half,SRhsPacket>::type SRhsPacketHalf;
+ typedef typename conditional<SwappedTraits::LhsProgress>=8,typename unpacket_traits<SAccPacket>::half,SAccPacket>::type SAccPacketHalf;
+
+ SResPacketHalf R = res.template gatherPacket<SResPacketHalf>(i, j2);
+ SResPacketHalf alphav = pset1<SResPacketHalf>(alpha);
+
+ if(depth-endk>0)
+ {
+ // We have to handle the last row of the rhs which corresponds to a half-packet
+ SLhsPacketHalf a0;
+ SRhsPacketHalf b0;
+ straits.loadLhsUnaligned(blB, a0);
+ straits.loadRhs(blA, b0);
+ SAccPacketHalf c0 = predux_half_dowto4(C0);
+ straits.madd(a0,b0,c0,b0, fix<0>);
+ straits.acc(c0, alphav, R);
+ }
+ else
+ {
+ straits.acc(predux_half_dowto4(C0), alphav, R);
+ }
+ res.scatterPacket(i, j2, R);
+ }
+ else if (SwappedTraits::LhsProgress==16)
+ {
+ // Special case where we have to first reduce the
+ // accumulation register C0. We specialize the block in
+ // template form, so that LhsProgress < 16 paths don't
+ // fail to compile
+ last_row_process_16_packets<LhsScalar, RhsScalar, Index, DataMapper, mr, nr, ConjugateLhs, ConjugateRhs> p;
+ p(res, straits, blA, blB, depth, endk, i, j2,alpha, C0);
+ }
+ else
+ {
+ SResPacket R = res.template gatherPacket<SResPacket>(i, j2);
+ SResPacket alphav = pset1<SResPacket>(alpha);
+ straits.acc(C0, alphav, R);
+ res.scatterPacket(i, j2, R);
+ }
+ }
+ else // scalar path
+ {
+ // get a 1 x 4 res block as registers
+ ResScalar C0(0), C1(0), C2(0), C3(0);
+
+ for(Index k=0; k<depth; k++)
+ {
+ LhsScalar A0;
+ RhsScalar B_0, B_1;
+
+ A0 = blA[k];
+
+ B_0 = blB[0];
+ B_1 = blB[1];
+ C0 = cj.pmadd(A0,B_0,C0);
+ C1 = cj.pmadd(A0,B_1,C1);
+
+ B_0 = blB[2];
+ B_1 = blB[3];
+ C2 = cj.pmadd(A0,B_0,C2);
+ C3 = cj.pmadd(A0,B_1,C3);
+
+ blB += 4;
+ }
+ res(i, j2 + 0) += alpha * C0;
+ res(i, j2 + 1) += alpha * C1;
+ res(i, j2 + 2) += alpha * C2;
+ res(i, j2 + 3) += alpha * C3;
+ }
+ }
+ }
+ // remaining columns
+ for(Index j2=packet_cols4; j2<cols; j2++)
+ {
+ // loop on each row of the lhs (1*LhsProgress x depth)
+ for(Index i=peeled_mc_quarter; i<rows; i+=1)
+ {
+ const LhsScalar* blA = &blockA[i*strideA+offsetA];
+ prefetch(&blA[0]);
+ // gets a 1 x 1 res block as registers
+ ResScalar C0(0);
+ const RhsScalar* blB = &blockB[j2*strideB+offsetB];
+ for(Index k=0; k<depth; k++)
+ {
+ LhsScalar A0 = blA[k];
+ RhsScalar B_0 = blB[k];
+ C0 = cj.pmadd(A0, B_0, C0);
+ }
+ res(i, j2) += alpha * C0;
+ }
+ }
+ }
+ }
+
+
+// pack a block of the lhs
+// The traversal is as follow (mr==4):
+// 0 4 8 12 ...
+// 1 5 9 13 ...
+// 2 6 10 14 ...
+// 3 7 11 15 ...
+//
+// 16 20 24 28 ...
+// 17 21 25 29 ...
+// 18 22 26 30 ...
+// 19 23 27 31 ...
+//
+// 32 33 34 35 ...
+// 36 36 38 39 ...
+template<typename Scalar, typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+struct gemm_pack_lhs<Scalar, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode>
+{
+ typedef typename DataMapper::LinearMapper LinearMapper;
+ EIGEN_DONT_INLINE void operator()(Scalar* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0);
+};
+
+template<typename Scalar, typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+EIGEN_DONT_INLINE void gemm_pack_lhs<Scalar, Index, DataMapper, Pack1, Pack2, Packet, ColMajor, Conjugate, PanelMode>
+ ::operator()(Scalar* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+{
+ typedef typename unpacket_traits<Packet>::half HalfPacket;
+ typedef typename unpacket_traits<typename unpacket_traits<Packet>::half>::half QuarterPacket;
+ enum { PacketSize = unpacket_traits<Packet>::size,
+ HalfPacketSize = unpacket_traits<HalfPacket>::size,
+ QuarterPacketSize = unpacket_traits<QuarterPacket>::size,
+ HasHalf = (int)HalfPacketSize < (int)PacketSize,
+ HasQuarter = (int)QuarterPacketSize < (int)HalfPacketSize};
+
+ EIGEN_ASM_COMMENT("EIGEN PRODUCT PACK LHS");
+ EIGEN_UNUSED_VARIABLE(stride);
+ EIGEN_UNUSED_VARIABLE(offset);
+ eigen_assert(((!PanelMode) && stride==0 && offset==0) || (PanelMode && stride>=depth && offset<=stride));
+ eigen_assert( ((Pack1%PacketSize)==0 && Pack1<=4*PacketSize) || (Pack1<=4) );
+ conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj;
+ Index count = 0;
+
+ const Index peeled_mc3 = Pack1>=3*PacketSize ? (rows/(3*PacketSize))*(3*PacketSize) : 0;
+ const Index peeled_mc2 = Pack1>=2*PacketSize ? peeled_mc3+((rows-peeled_mc3)/(2*PacketSize))*(2*PacketSize) : 0;
+ const Index peeled_mc1 = Pack1>=1*PacketSize ? peeled_mc2+((rows-peeled_mc2)/(1*PacketSize))*(1*PacketSize) : 0;
+ const Index peeled_mc_half = Pack1>=HalfPacketSize ? peeled_mc1+((rows-peeled_mc1)/(HalfPacketSize))*(HalfPacketSize) : 0;
+ const Index peeled_mc_quarter = Pack1>=QuarterPacketSize ? (rows/(QuarterPacketSize))*(QuarterPacketSize) : 0;
+ const Index last_lhs_progress = rows > peeled_mc_quarter ? (rows - peeled_mc_quarter) & ~1 : 0;
+ const Index peeled_mc0 = Pack2>=PacketSize ? peeled_mc_quarter
+ : Pack2>1 && last_lhs_progress ? (rows/last_lhs_progress)*last_lhs_progress : 0;
+
+ Index i=0;
+
+ // Pack 3 packets
+ if(Pack1>=3*PacketSize)
+ {
+ for(; i<peeled_mc3; i+=3*PacketSize)
+ {
+ if(PanelMode) count += (3*PacketSize) * offset;
+
+ for(Index k=0; k<depth; k++)
+ {
+ Packet A, B, C;
+ A = lhs.template loadPacket<Packet>(i+0*PacketSize, k);
+ B = lhs.template loadPacket<Packet>(i+1*PacketSize, k);
+ C = lhs.template loadPacket<Packet>(i+2*PacketSize, k);
+ pstore(blockA+count, cj.pconj(A)); count+=PacketSize;
+ pstore(blockA+count, cj.pconj(B)); count+=PacketSize;
+ pstore(blockA+count, cj.pconj(C)); count+=PacketSize;
+ }
+ if(PanelMode) count += (3*PacketSize) * (stride-offset-depth);
+ }
+ }
+ // Pack 2 packets
+ if(Pack1>=2*PacketSize)
+ {
+ for(; i<peeled_mc2; i+=2*PacketSize)
+ {
+ if(PanelMode) count += (2*PacketSize) * offset;
+
+ for(Index k=0; k<depth; k++)
+ {
+ Packet A, B;
+ A = lhs.template loadPacket<Packet>(i+0*PacketSize, k);
+ B = lhs.template loadPacket<Packet>(i+1*PacketSize, k);
+ pstore(blockA+count, cj.pconj(A)); count+=PacketSize;
+ pstore(blockA+count, cj.pconj(B)); count+=PacketSize;
+ }
+ if(PanelMode) count += (2*PacketSize) * (stride-offset-depth);
+ }
+ }
+ // Pack 1 packets
+ if(Pack1>=1*PacketSize)
+ {
+ for(; i<peeled_mc1; i+=1*PacketSize)
+ {
+ if(PanelMode) count += (1*PacketSize) * offset;
+
+ for(Index k=0; k<depth; k++)
+ {
+ Packet A;
+ A = lhs.template loadPacket<Packet>(i+0*PacketSize, k);
+ pstore(blockA+count, cj.pconj(A));
+ count+=PacketSize;
+ }
+ if(PanelMode) count += (1*PacketSize) * (stride-offset-depth);
+ }
+ }
+ // Pack half packets
+ if(HasHalf && Pack1>=HalfPacketSize)
+ {
+ for(; i<peeled_mc_half; i+=HalfPacketSize)
+ {
+ if(PanelMode) count += (HalfPacketSize) * offset;
+
+ for(Index k=0; k<depth; k++)
+ {
+ HalfPacket A;
+ A = lhs.template loadPacket<HalfPacket>(i+0*(HalfPacketSize), k);
+ pstoreu(blockA+count, cj.pconj(A));
+ count+=HalfPacketSize;
+ }
+ if(PanelMode) count += (HalfPacketSize) * (stride-offset-depth);
+ }
+ }
+ // Pack quarter packets
+ if(HasQuarter && Pack1>=QuarterPacketSize)
+ {
+ for(; i<peeled_mc_quarter; i+=QuarterPacketSize)
+ {
+ if(PanelMode) count += (QuarterPacketSize) * offset;
+
+ for(Index k=0; k<depth; k++)
+ {
+ QuarterPacket A;
+ A = lhs.template loadPacket<QuarterPacket>(i+0*(QuarterPacketSize), k);
+ pstoreu(blockA+count, cj.pconj(A));
+ count+=QuarterPacketSize;
+ }
+ if(PanelMode) count += (QuarterPacketSize) * (stride-offset-depth);
+ }
+ }
+ // Pack2 may be *smaller* than PacketSize—that happens for
+ // products like real * complex, where we have to go half the
+ // progress on the lhs in order to duplicate those operands to
+ // address both real & imaginary parts on the rhs. This portion will
+ // pack those half ones until they match the number expected on the
+ // last peeling loop at this point (for the rhs).
+ if(Pack2<PacketSize && Pack2>1)
+ {
+ for(; i<peeled_mc0; i+=last_lhs_progress)
+ {
+ if(PanelMode) count += last_lhs_progress * offset;
+
+ for(Index k=0; k<depth; k++)
+ for(Index w=0; w<last_lhs_progress; w++)
+ blockA[count++] = cj(lhs(i+w, k));
+
+ if(PanelMode) count += last_lhs_progress * (stride-offset-depth);
+ }
+ }
+ // Pack scalars
+ for(; i<rows; i++)
+ {
+ if(PanelMode) count += offset;
+ for(Index k=0; k<depth; k++)
+ blockA[count++] = cj(lhs(i, k));
+ if(PanelMode) count += (stride-offset-depth);
+ }
+}
+
+template<typename Scalar, typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+struct gemm_pack_lhs<Scalar, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode>
+{
+ typedef typename DataMapper::LinearMapper LinearMapper;
+ EIGEN_DONT_INLINE void operator()(Scalar* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride=0, Index offset=0);
+};
+
+template<typename Scalar, typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, bool Conjugate, bool PanelMode>
+EIGEN_DONT_INLINE void gemm_pack_lhs<Scalar, Index, DataMapper, Pack1, Pack2, Packet, RowMajor, Conjugate, PanelMode>
+ ::operator()(Scalar* blockA, const DataMapper& lhs, Index depth, Index rows, Index stride, Index offset)
+{
+ typedef typename unpacket_traits<Packet>::half HalfPacket;
+ typedef typename unpacket_traits<typename unpacket_traits<Packet>::half>::half QuarterPacket;
+ enum { PacketSize = unpacket_traits<Packet>::size,
+ HalfPacketSize = unpacket_traits<HalfPacket>::size,
+ QuarterPacketSize = unpacket_traits<QuarterPacket>::size,
+ HasHalf = (int)HalfPacketSize < (int)PacketSize,
+ HasQuarter = (int)QuarterPacketSize < (int)HalfPacketSize};
+
+ EIGEN_ASM_COMMENT("EIGEN PRODUCT PACK LHS");
+ EIGEN_UNUSED_VARIABLE(stride);
+ EIGEN_UNUSED_VARIABLE(offset);
+ eigen_assert(((!PanelMode) && stride==0 && offset==0) || (PanelMode && stride>=depth && offset<=stride));
+ conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj;
+ Index count = 0;
+ bool gone_half = false, gone_quarter = false, gone_last = false;
+
+ Index i = 0;
+ int pack = Pack1;
+ int psize = PacketSize;
+ while(pack>0)
+ {
+ Index remaining_rows = rows-i;
+ Index peeled_mc = gone_last ? Pack2>1 ? (rows/pack)*pack : 0 : i+(remaining_rows/pack)*pack;
+ Index starting_pos = i;
+ for(; i<peeled_mc; i+=pack)
+ {
+ if(PanelMode) count += pack * offset;
+
+ Index k=0;
+ if(pack>=psize && psize >= QuarterPacketSize)
+ {
+ const Index peeled_k = (depth/psize)*psize;
+ for(; k<peeled_k; k+=psize)
+ {
+ for (Index m = 0; m < pack; m += psize)
+ {
+ if (psize == PacketSize) {
+ PacketBlock<Packet> kernel;
+ for (int p = 0; p < psize; ++p) kernel.packet[p] = lhs.template loadPacket<Packet>(i+p+m, k);
+ ptranspose(kernel);
+ for (int p = 0; p < psize; ++p) pstore(blockA+count+m+(pack)*p, cj.pconj(kernel.packet[p]));
+ } else if (HasHalf && psize == HalfPacketSize) {
+ gone_half = true;
+ PacketBlock<HalfPacket> kernel_half;
+ for (int p = 0; p < psize; ++p) kernel_half.packet[p] = lhs.template loadPacket<HalfPacket>(i+p+m, k);
+ ptranspose(kernel_half);
+ for (int p = 0; p < psize; ++p) pstore(blockA+count+m+(pack)*p, cj.pconj(kernel_half.packet[p]));
+ } else if (HasQuarter && psize == QuarterPacketSize) {
+ gone_quarter = true;
+ PacketBlock<QuarterPacket> kernel_quarter;
+ for (int p = 0; p < psize; ++p) kernel_quarter.packet[p] = lhs.template loadPacket<QuarterPacket>(i+p+m, k);
+ ptranspose(kernel_quarter);
+ for (int p = 0; p < psize; ++p) pstore(blockA+count+m+(pack)*p, cj.pconj(kernel_quarter.packet[p]));
+ }
+ }
+ count += psize*pack;
+ }
+ }
+
+ for(; k<depth; k++)
+ {
+ Index w=0;
+ for(; w<pack-3; w+=4)
+ {
+ Scalar a(cj(lhs(i+w+0, k))),
+ b(cj(lhs(i+w+1, k))),
+ c(cj(lhs(i+w+2, k))),
+ d(cj(lhs(i+w+3, k)));
+ blockA[count++] = a;
+ blockA[count++] = b;
+ blockA[count++] = c;
+ blockA[count++] = d;
+ }
+ if(pack%4)
+ for(;w<pack;++w)
+ blockA[count++] = cj(lhs(i+w, k));
+ }
+
+ if(PanelMode) count += pack * (stride-offset-depth);
+ }
+
+ pack -= psize;
+ Index left = rows - i;
+ if (pack <= 0) {
+ if (!gone_last &&
+ (starting_pos == i || left >= psize/2 || left >= psize/4) &&
+ ((psize/2 == HalfPacketSize && HasHalf && !gone_half) ||
+ (psize/2 == QuarterPacketSize && HasQuarter && !gone_quarter))) {
+ psize /= 2;
+ pack = psize;
+ continue;
+ }
+ // Pack2 may be *smaller* than PacketSize—that happens for
+ // products like real * complex, where we have to go half the
+ // progress on the lhs in order to duplicate those operands to
+ // address both real & imaginary parts on the rhs. This portion will
+ // pack those half ones until they match the number expected on the
+ // last peeling loop at this point (for the rhs).
+ if (Pack2 < PacketSize && !gone_last) {
+ gone_last = true;
+ psize = pack = left & ~1;
+ }
+ }
+ }
+
+ for(; i<rows; i++)
+ {
+ if(PanelMode) count += offset;
+ for(Index k=0; k<depth; k++)
+ blockA[count++] = cj(lhs(i, k));
+ if(PanelMode) count += (stride-offset-depth);
+ }
+}
+
+// copy a complete panel of the rhs
+// this version is optimized for column major matrices
+// The traversal order is as follow: (nr==4):
+// 0 1 2 3 12 13 14 15 24 27
+// 4 5 6 7 16 17 18 19 25 28
+// 8 9 10 11 20 21 22 23 26 29
+// . . . . . . . . . .
+template<typename Scalar, typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+struct gemm_pack_rhs<Scalar, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode>
+{
+ typedef typename packet_traits<Scalar>::type Packet;
+ typedef typename DataMapper::LinearMapper LinearMapper;
+ enum { PacketSize = packet_traits<Scalar>::size };
+ EIGEN_DONT_INLINE void operator()(Scalar* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0);
+};
+
+template<typename Scalar, typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+EIGEN_DONT_INLINE void gemm_pack_rhs<Scalar, Index, DataMapper, nr, ColMajor, Conjugate, PanelMode>
+ ::operator()(Scalar* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride, Index offset)
+{
+ EIGEN_ASM_COMMENT("EIGEN PRODUCT PACK RHS COLMAJOR");
+ EIGEN_UNUSED_VARIABLE(stride);
+ EIGEN_UNUSED_VARIABLE(offset);
+ eigen_assert(((!PanelMode) && stride==0 && offset==0) || (PanelMode && stride>=depth && offset<=stride));
+ conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj;
+ Index packet_cols8 = nr>=8 ? (cols/8) * 8 : 0;
+ Index packet_cols4 = nr>=4 ? (cols/4) * 4 : 0;
+ Index count = 0;
+ const Index peeled_k = (depth/PacketSize)*PacketSize;
+// if(nr>=8)
+// {
+// for(Index j2=0; j2<packet_cols8; j2+=8)
+// {
+// // skip what we have before
+// if(PanelMode) count += 8 * offset;
+// const Scalar* b0 = &rhs[(j2+0)*rhsStride];
+// const Scalar* b1 = &rhs[(j2+1)*rhsStride];
+// const Scalar* b2 = &rhs[(j2+2)*rhsStride];
+// const Scalar* b3 = &rhs[(j2+3)*rhsStride];
+// const Scalar* b4 = &rhs[(j2+4)*rhsStride];
+// const Scalar* b5 = &rhs[(j2+5)*rhsStride];
+// const Scalar* b6 = &rhs[(j2+6)*rhsStride];
+// const Scalar* b7 = &rhs[(j2+7)*rhsStride];
+// Index k=0;
+// if(PacketSize==8) // TODO enable vectorized transposition for PacketSize==4
+// {
+// for(; k<peeled_k; k+=PacketSize) {
+// PacketBlock<Packet> kernel;
+// for (int p = 0; p < PacketSize; ++p) {
+// kernel.packet[p] = ploadu<Packet>(&rhs[(j2+p)*rhsStride+k]);
+// }
+// ptranspose(kernel);
+// for (int p = 0; p < PacketSize; ++p) {
+// pstoreu(blockB+count, cj.pconj(kernel.packet[p]));
+// count+=PacketSize;
+// }
+// }
+// }
+// for(; k<depth; k++)
+// {
+// blockB[count+0] = cj(b0[k]);
+// blockB[count+1] = cj(b1[k]);
+// blockB[count+2] = cj(b2[k]);
+// blockB[count+3] = cj(b3[k]);
+// blockB[count+4] = cj(b4[k]);
+// blockB[count+5] = cj(b5[k]);
+// blockB[count+6] = cj(b6[k]);
+// blockB[count+7] = cj(b7[k]);
+// count += 8;
+// }
+// // skip what we have after
+// if(PanelMode) count += 8 * (stride-offset-depth);
+// }
+// }
+
+ if(nr>=4)
+ {
+ for(Index j2=packet_cols8; j2<packet_cols4; j2+=4)
+ {
+ // skip what we have before
+ if(PanelMode) count += 4 * offset;
+ const LinearMapper dm0 = rhs.getLinearMapper(0, j2 + 0);
+ const LinearMapper dm1 = rhs.getLinearMapper(0, j2 + 1);
+ const LinearMapper dm2 = rhs.getLinearMapper(0, j2 + 2);
+ const LinearMapper dm3 = rhs.getLinearMapper(0, j2 + 3);
+
+ Index k=0;
+ if((PacketSize%4)==0) // TODO enable vectorized transposition for PacketSize==2 ??
+ {
+ for(; k<peeled_k; k+=PacketSize) {
+ PacketBlock<Packet,(PacketSize%4)==0?4:PacketSize> kernel;
+ kernel.packet[0 ] = dm0.template loadPacket<Packet>(k);
+ kernel.packet[1%PacketSize] = dm1.template loadPacket<Packet>(k);
+ kernel.packet[2%PacketSize] = dm2.template loadPacket<Packet>(k);
+ kernel.packet[3%PacketSize] = dm3.template loadPacket<Packet>(k);
+ ptranspose(kernel);
+ pstoreu(blockB+count+0*PacketSize, cj.pconj(kernel.packet[0]));
+ pstoreu(blockB+count+1*PacketSize, cj.pconj(kernel.packet[1%PacketSize]));
+ pstoreu(blockB+count+2*PacketSize, cj.pconj(kernel.packet[2%PacketSize]));
+ pstoreu(blockB+count+3*PacketSize, cj.pconj(kernel.packet[3%PacketSize]));
+ count+=4*PacketSize;
+ }
+ }
+ for(; k<depth; k++)
+ {
+ blockB[count+0] = cj(dm0(k));
+ blockB[count+1] = cj(dm1(k));
+ blockB[count+2] = cj(dm2(k));
+ blockB[count+3] = cj(dm3(k));
+ count += 4;
+ }
+ // skip what we have after
+ if(PanelMode) count += 4 * (stride-offset-depth);
+ }
+ }
+
+ // copy the remaining columns one at a time (nr==1)
+ for(Index j2=packet_cols4; j2<cols; ++j2)
+ {
+ if(PanelMode) count += offset;
+ const LinearMapper dm0 = rhs.getLinearMapper(0, j2);
+ for(Index k=0; k<depth; k++)
+ {
+ blockB[count] = cj(dm0(k));
+ count += 1;
+ }
+ if(PanelMode) count += (stride-offset-depth);
+ }
+}
+
+// this version is optimized for row major matrices
+template<typename Scalar, typename Index, typename DataMapper, int nr, bool Conjugate, bool PanelMode>
+struct gemm_pack_rhs<Scalar, Index, DataMapper, nr, RowMajor, Conjugate, PanelMode>
+{
+ typedef typename packet_traits<Scalar>::type Packet;
+ typedef typename unpacket_traits<Packet>::half HalfPacket;
+ typedef typename unpacket_traits<typename unpacket_traits<Packet>::half>::half QuarterPacket;
+ typedef typename DataMapper::LinearMapper LinearMapper;
+ enum { PacketSize = packet_traits<Scalar>::size,
+ HalfPacketSize = unpacket_traits<HalfPacket>::size,
+ QuarterPacketSize = unpacket_traits<QuarterPacket>::size};
+ EIGEN_DONT_INLINE void operator()(Scalar* blockB, const DataMapper& rhs, Index depth, Index cols, Index stride=0, Index offset=0)
+ {
+ EIGEN_ASM_COMMENT("EIGEN PRODUCT PACK RHS ROWMAJOR");
+ EIGEN_UNUSED_VARIABLE(stride);
+ EIGEN_UNUSED_VARIABLE(offset);
+ eigen_assert(((!PanelMode) && stride==0 && offset==0) || (PanelMode && stride>=depth && offset<=stride));
+ const bool HasHalf = (int)HalfPacketSize < (int)PacketSize;
+ const bool HasQuarter = (int)QuarterPacketSize < (int)HalfPacketSize;
+ conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj;
+ Index packet_cols8 = nr>=8 ? (cols/8) * 8 : 0;
+ Index packet_cols4 = nr>=4 ? (cols/4) * 4 : 0;
+ Index count = 0;
+
+ // if(nr>=8)
+ // {
+ // for(Index j2=0; j2<packet_cols8; j2+=8)
+ // {
+ // // skip what we have before
+ // if(PanelMode) count += 8 * offset;
+ // for(Index k=0; k<depth; k++)
+ // {
+ // if (PacketSize==8) {
+ // Packet A = ploadu<Packet>(&rhs[k*rhsStride + j2]);
+ // pstoreu(blockB+count, cj.pconj(A));
+ // } else if (PacketSize==4) {
+ // Packet A = ploadu<Packet>(&rhs[k*rhsStride + j2]);
+ // Packet B = ploadu<Packet>(&rhs[k*rhsStride + j2 + PacketSize]);
+ // pstoreu(blockB+count, cj.pconj(A));
+ // pstoreu(blockB+count+PacketSize, cj.pconj(B));
+ // } else {
+ // const Scalar* b0 = &rhs[k*rhsStride + j2];
+ // blockB[count+0] = cj(b0[0]);
+ // blockB[count+1] = cj(b0[1]);
+ // blockB[count+2] = cj(b0[2]);
+ // blockB[count+3] = cj(b0[3]);
+ // blockB[count+4] = cj(b0[4]);
+ // blockB[count+5] = cj(b0[5]);
+ // blockB[count+6] = cj(b0[6]);
+ // blockB[count+7] = cj(b0[7]);
+ // }
+ // count += 8;
+ // }
+ // // skip what we have after
+ // if(PanelMode) count += 8 * (stride-offset-depth);
+ // }
+ // }
+ if(nr>=4)
+ {
+ for(Index j2=packet_cols8; j2<packet_cols4; j2+=4)
+ {
+ // skip what we have before
+ if(PanelMode) count += 4 * offset;
+ for(Index k=0; k<depth; k++)
+ {
+ if (PacketSize==4) {
+ Packet A = rhs.template loadPacket<Packet>(k, j2);
+ pstoreu(blockB+count, cj.pconj(A));
+ count += PacketSize;
+ } else if (HasHalf && HalfPacketSize==4) {
+ HalfPacket A = rhs.template loadPacket<HalfPacket>(k, j2);
+ pstoreu(blockB+count, cj.pconj(A));
+ count += HalfPacketSize;
+ } else if (HasQuarter && QuarterPacketSize==4) {
+ QuarterPacket A = rhs.template loadPacket<QuarterPacket>(k, j2);
+ pstoreu(blockB+count, cj.pconj(A));
+ count += QuarterPacketSize;
+ } else {
+ const LinearMapper dm0 = rhs.getLinearMapper(k, j2);
+ blockB[count+0] = cj(dm0(0));
+ blockB[count+1] = cj(dm0(1));
+ blockB[count+2] = cj(dm0(2));
+ blockB[count+3] = cj(dm0(3));
+ count += 4;
+ }
+ }
+ // skip what we have after
+ if(PanelMode) count += 4 * (stride-offset-depth);
+ }
+ }
+ // copy the remaining columns one at a time (nr==1)
+ for(Index j2=packet_cols4; j2<cols; ++j2)
+ {
+ if(PanelMode) count += offset;
+ for(Index k=0; k<depth; k++)
+ {
+ blockB[count] = cj(rhs(k, j2));
+ count += 1;
+ }
+ if(PanelMode) count += stride-offset-depth;
+ }
+ }
+};
+
+} // end namespace internal
+
+/** \returns the currently set level 1 cpu cache size (in bytes) used to estimate the ideal blocking size parameters.
+ * \sa setCpuCacheSize */
+inline std::ptrdiff_t l1CacheSize()
+{
+ std::ptrdiff_t l1, l2, l3;
+ internal::manage_caching_sizes(GetAction, &l1, &l2, &l3);
+ return l1;
+}
+
+/** \returns the currently set level 2 cpu cache size (in bytes) used to estimate the ideal blocking size parameters.
+ * \sa setCpuCacheSize */
+inline std::ptrdiff_t l2CacheSize()
+{
+ std::ptrdiff_t l1, l2, l3;
+ internal::manage_caching_sizes(GetAction, &l1, &l2, &l3);
+ return l2;
+}
+
+/** \returns the currently set level 3 cpu cache size (in bytes) used to estimate the ideal blocking size paramete\
+rs.
+* \sa setCpuCacheSize */
+inline std::ptrdiff_t l3CacheSize()
+{
+ std::ptrdiff_t l1, l2, l3;
+ internal::manage_caching_sizes(GetAction, &l1, &l2, &l3);
+ return l3;
+}
+
+/** Set the cpu L1 and L2 cache sizes (in bytes).
+ * These values are use to adjust the size of the blocks
+ * for the algorithms working per blocks.
+ *
+ * \sa computeProductBlockingSizes */
+inline void setCpuCacheSizes(std::ptrdiff_t l1, std::ptrdiff_t l2, std::ptrdiff_t l3)
+{
+ internal::manage_caching_sizes(SetAction, &l1, &l2, &l3);
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_GENERAL_BLOCK_PANEL_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h
new file mode 100644
index 000000000..caa65fccc
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h
@@ -0,0 +1,517 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GENERAL_MATRIX_MATRIX_H
+#define EIGEN_GENERAL_MATRIX_MATRIX_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename _LhsScalar, typename _RhsScalar> class level3_blocking;
+
+/* Specialization for a row-major destination matrix => simple transposition of the product */
+template<
+ typename Index,
+ typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs,
+ typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride>
+struct general_matrix_matrix_product<Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,RowMajor,ResInnerStride>
+{
+ typedef gebp_traits<RhsScalar,LhsScalar> Traits;
+
+ typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
+ static EIGEN_STRONG_INLINE void run(
+ Index rows, Index cols, Index depth,
+ const LhsScalar* lhs, Index lhsStride,
+ const RhsScalar* rhs, Index rhsStride,
+ ResScalar* res, Index resIncr, Index resStride,
+ ResScalar alpha,
+ level3_blocking<RhsScalar,LhsScalar>& blocking,
+ GemmParallelInfo<Index>* info = 0)
+ {
+ // transpose the product such that the result is column major
+ general_matrix_matrix_product<Index,
+ RhsScalar, RhsStorageOrder==RowMajor ? ColMajor : RowMajor, ConjugateRhs,
+ LhsScalar, LhsStorageOrder==RowMajor ? ColMajor : RowMajor, ConjugateLhs,
+ ColMajor,ResInnerStride>
+ ::run(cols,rows,depth,rhs,rhsStride,lhs,lhsStride,res,resIncr,resStride,alpha,blocking,info);
+ }
+};
+
+/* Specialization for a col-major destination matrix
+ * => Blocking algorithm following Goto's paper */
+template<
+ typename Index,
+ typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs,
+ typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride>
+struct general_matrix_matrix_product<Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride>
+{
+
+typedef gebp_traits<LhsScalar,RhsScalar> Traits;
+
+typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
+static void run(Index rows, Index cols, Index depth,
+ const LhsScalar* _lhs, Index lhsStride,
+ const RhsScalar* _rhs, Index rhsStride,
+ ResScalar* _res, Index resIncr, Index resStride,
+ ResScalar alpha,
+ level3_blocking<LhsScalar,RhsScalar>& blocking,
+ GemmParallelInfo<Index>* info = 0)
+{
+ typedef const_blas_data_mapper<LhsScalar, Index, LhsStorageOrder> LhsMapper;
+ typedef const_blas_data_mapper<RhsScalar, Index, RhsStorageOrder> RhsMapper;
+ typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor,Unaligned,ResInnerStride> ResMapper;
+ LhsMapper lhs(_lhs, lhsStride);
+ RhsMapper rhs(_rhs, rhsStride);
+ ResMapper res(_res, resStride, resIncr);
+
+ Index kc = blocking.kc(); // cache block size along the K direction
+ Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction
+ Index nc = (std::min)(cols,blocking.nc()); // cache block size along the N direction
+
+ gemm_pack_lhs<LhsScalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs;
+ gemm_pack_rhs<RhsScalar, Index, RhsMapper, Traits::nr, RhsStorageOrder> pack_rhs;
+ gebp_kernel<LhsScalar, RhsScalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp;
+
+#ifdef EIGEN_HAS_OPENMP
+ if(info)
+ {
+ // this is the parallel version!
+ int tid = omp_get_thread_num();
+ int threads = omp_get_num_threads();
+
+ LhsScalar* blockA = blocking.blockA();
+ eigen_internal_assert(blockA!=0);
+
+ std::size_t sizeB = kc*nc;
+ ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, 0);
+
+ // For each horizontal panel of the rhs, and corresponding vertical panel of the lhs...
+ for(Index k=0; k<depth; k+=kc)
+ {
+ const Index actual_kc = (std::min)(k+kc,depth)-k; // => rows of B', and cols of the A'
+
+ // In order to reduce the chance that a thread has to wait for the other,
+ // let's start by packing B'.
+ pack_rhs(blockB, rhs.getSubMapper(k,0), actual_kc, nc);
+
+ // Pack A_k to A' in a parallel fashion:
+ // each thread packs the sub block A_k,i to A'_i where i is the thread id.
+
+ // However, before copying to A'_i, we have to make sure that no other thread is still using it,
+ // i.e., we test that info[tid].users equals 0.
+ // Then, we set info[tid].users to the number of threads to mark that all other threads are going to use it.
+ while(info[tid].users!=0) {}
+ info[tid].users = threads;
+
+ pack_lhs(blockA+info[tid].lhs_start*actual_kc, lhs.getSubMapper(info[tid].lhs_start,k), actual_kc, info[tid].lhs_length);
+
+ // Notify the other threads that the part A'_i is ready to go.
+ info[tid].sync = k;
+
+ // Computes C_i += A' * B' per A'_i
+ for(int shift=0; shift<threads; ++shift)
+ {
+ int i = (tid+shift)%threads;
+
+ // At this point we have to make sure that A'_i has been updated by the thread i,
+ // we use testAndSetOrdered to mimic a volatile access.
+ // However, no need to wait for the B' part which has been updated by the current thread!
+ if (shift>0) {
+ while(info[i].sync!=k) {
+ }
+ }
+
+ gebp(res.getSubMapper(info[i].lhs_start, 0), blockA+info[i].lhs_start*actual_kc, blockB, info[i].lhs_length, actual_kc, nc, alpha);
+ }
+
+ // Then keep going as usual with the remaining B'
+ for(Index j=nc; j<cols; j+=nc)
+ {
+ const Index actual_nc = (std::min)(j+nc,cols)-j;
+
+ // pack B_k,j to B'
+ pack_rhs(blockB, rhs.getSubMapper(k,j), actual_kc, actual_nc);
+
+ // C_j += A' * B'
+ gebp(res.getSubMapper(0, j), blockA, blockB, rows, actual_kc, actual_nc, alpha);
+ }
+
+ // Release all the sub blocks A'_i of A' for the current thread,
+ // i.e., we simply decrement the number of users by 1
+ for(Index i=0; i<threads; ++i)
+#if !EIGEN_HAS_CXX11_ATOMIC
+ #pragma omp atomic
+#endif
+ info[i].users -= 1;
+ }
+ }
+ else
+#endif // EIGEN_HAS_OPENMP
+ {
+ EIGEN_UNUSED_VARIABLE(info);
+
+ // this is the sequential version!
+ std::size_t sizeA = kc*mc;
+ std::size_t sizeB = kc*nc;
+
+ ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, blocking.blockA());
+ ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, blocking.blockB());
+
+ const bool pack_rhs_once = mc!=rows && kc==depth && nc==cols;
+
+ // For each horizontal panel of the rhs, and corresponding panel of the lhs...
+ for(Index i2=0; i2<rows; i2+=mc)
+ {
+ const Index actual_mc = (std::min)(i2+mc,rows)-i2;
+
+ for(Index k2=0; k2<depth; k2+=kc)
+ {
+ const Index actual_kc = (std::min)(k2+kc,depth)-k2;
+
+ // OK, here we have selected one horizontal panel of rhs and one vertical panel of lhs.
+ // => Pack lhs's panel into a sequential chunk of memory (L2/L3 caching)
+ // Note that this panel will be read as many times as the number of blocks in the rhs's
+ // horizontal panel which is, in practice, a very low number.
+ pack_lhs(blockA, lhs.getSubMapper(i2,k2), actual_kc, actual_mc);
+
+ // For each kc x nc block of the rhs's horizontal panel...
+ for(Index j2=0; j2<cols; j2+=nc)
+ {
+ const Index actual_nc = (std::min)(j2+nc,cols)-j2;
+
+ // We pack the rhs's block into a sequential chunk of memory (L2 caching)
+ // Note that this block will be read a very high number of times, which is equal to the number of
+ // micro horizontal panel of the large rhs's panel (e.g., rows/12 times).
+ if((!pack_rhs_once) || i2==0)
+ pack_rhs(blockB, rhs.getSubMapper(k2,j2), actual_kc, actual_nc);
+
+ // Everything is packed, we can now call the panel * block kernel:
+ gebp(res.getSubMapper(i2, j2), blockA, blockB, actual_mc, actual_kc, actual_nc, alpha);
+ }
+ }
+ }
+ }
+}
+
+};
+
+/*********************************************************************************
+* Specialization of generic_product_impl for "large" GEMM, i.e.,
+* implementation of the high level wrapper to general_matrix_matrix_product
+**********************************************************************************/
+
+template<typename Scalar, typename Index, typename Gemm, typename Lhs, typename Rhs, typename Dest, typename BlockingType>
+struct gemm_functor
+{
+ gemm_functor(const Lhs& lhs, const Rhs& rhs, Dest& dest, const Scalar& actualAlpha, BlockingType& blocking)
+ : m_lhs(lhs), m_rhs(rhs), m_dest(dest), m_actualAlpha(actualAlpha), m_blocking(blocking)
+ {}
+
+ void initParallelSession(Index num_threads) const
+ {
+ m_blocking.initParallel(m_lhs.rows(), m_rhs.cols(), m_lhs.cols(), num_threads);
+ m_blocking.allocateA();
+ }
+
+ void operator() (Index row, Index rows, Index col=0, Index cols=-1, GemmParallelInfo<Index>* info=0) const
+ {
+ if(cols==-1)
+ cols = m_rhs.cols();
+
+ Gemm::run(rows, cols, m_lhs.cols(),
+ &m_lhs.coeffRef(row,0), m_lhs.outerStride(),
+ &m_rhs.coeffRef(0,col), m_rhs.outerStride(),
+ (Scalar*)&(m_dest.coeffRef(row,col)), m_dest.innerStride(), m_dest.outerStride(),
+ m_actualAlpha, m_blocking, info);
+ }
+
+ typedef typename Gemm::Traits Traits;
+
+ protected:
+ const Lhs& m_lhs;
+ const Rhs& m_rhs;
+ Dest& m_dest;
+ Scalar m_actualAlpha;
+ BlockingType& m_blocking;
+};
+
+template<int StorageOrder, typename LhsScalar, typename RhsScalar, int MaxRows, int MaxCols, int MaxDepth, int KcFactor=1,
+bool FiniteAtCompileTime = MaxRows!=Dynamic && MaxCols!=Dynamic && MaxDepth != Dynamic> class gemm_blocking_space;
+
+template<typename _LhsScalar, typename _RhsScalar>
+class level3_blocking
+{
+ typedef _LhsScalar LhsScalar;
+ typedef _RhsScalar RhsScalar;
+
+ protected:
+ LhsScalar* m_blockA;
+ RhsScalar* m_blockB;
+
+ Index m_mc;
+ Index m_nc;
+ Index m_kc;
+
+ public:
+
+ level3_blocking()
+ : m_blockA(0), m_blockB(0), m_mc(0), m_nc(0), m_kc(0)
+ {}
+
+ inline Index mc() const { return m_mc; }
+ inline Index nc() const { return m_nc; }
+ inline Index kc() const { return m_kc; }
+
+ inline LhsScalar* blockA() { return m_blockA; }
+ inline RhsScalar* blockB() { return m_blockB; }
+};
+
+template<int StorageOrder, typename _LhsScalar, typename _RhsScalar, int MaxRows, int MaxCols, int MaxDepth, int KcFactor>
+class gemm_blocking_space<StorageOrder,_LhsScalar,_RhsScalar,MaxRows, MaxCols, MaxDepth, KcFactor, true /* == FiniteAtCompileTime */>
+ : public level3_blocking<
+ typename conditional<StorageOrder==RowMajor,_RhsScalar,_LhsScalar>::type,
+ typename conditional<StorageOrder==RowMajor,_LhsScalar,_RhsScalar>::type>
+{
+ enum {
+ Transpose = StorageOrder==RowMajor,
+ ActualRows = Transpose ? MaxCols : MaxRows,
+ ActualCols = Transpose ? MaxRows : MaxCols
+ };
+ typedef typename conditional<Transpose,_RhsScalar,_LhsScalar>::type LhsScalar;
+ typedef typename conditional<Transpose,_LhsScalar,_RhsScalar>::type RhsScalar;
+ typedef gebp_traits<LhsScalar,RhsScalar> Traits;
+ enum {
+ SizeA = ActualRows * MaxDepth,
+ SizeB = ActualCols * MaxDepth
+ };
+
+#if EIGEN_MAX_STATIC_ALIGN_BYTES >= EIGEN_DEFAULT_ALIGN_BYTES
+ EIGEN_ALIGN_MAX LhsScalar m_staticA[SizeA];
+ EIGEN_ALIGN_MAX RhsScalar m_staticB[SizeB];
+#else
+ EIGEN_ALIGN_MAX char m_staticA[SizeA * sizeof(LhsScalar) + EIGEN_DEFAULT_ALIGN_BYTES-1];
+ EIGEN_ALIGN_MAX char m_staticB[SizeB * sizeof(RhsScalar) + EIGEN_DEFAULT_ALIGN_BYTES-1];
+#endif
+
+ public:
+
+ gemm_blocking_space(Index /*rows*/, Index /*cols*/, Index /*depth*/, Index /*num_threads*/, bool /*full_rows = false*/)
+ {
+ this->m_mc = ActualRows;
+ this->m_nc = ActualCols;
+ this->m_kc = MaxDepth;
+#if EIGEN_MAX_STATIC_ALIGN_BYTES >= EIGEN_DEFAULT_ALIGN_BYTES
+ this->m_blockA = m_staticA;
+ this->m_blockB = m_staticB;
+#else
+ this->m_blockA = reinterpret_cast<LhsScalar*>((internal::UIntPtr(m_staticA) + (EIGEN_DEFAULT_ALIGN_BYTES-1)) & ~std::size_t(EIGEN_DEFAULT_ALIGN_BYTES-1));
+ this->m_blockB = reinterpret_cast<RhsScalar*>((internal::UIntPtr(m_staticB) + (EIGEN_DEFAULT_ALIGN_BYTES-1)) & ~std::size_t(EIGEN_DEFAULT_ALIGN_BYTES-1));
+#endif
+ }
+
+ void initParallel(Index, Index, Index, Index)
+ {}
+
+ inline void allocateA() {}
+ inline void allocateB() {}
+ inline void allocateAll() {}
+};
+
+template<int StorageOrder, typename _LhsScalar, typename _RhsScalar, int MaxRows, int MaxCols, int MaxDepth, int KcFactor>
+class gemm_blocking_space<StorageOrder,_LhsScalar,_RhsScalar,MaxRows, MaxCols, MaxDepth, KcFactor, false>
+ : public level3_blocking<
+ typename conditional<StorageOrder==RowMajor,_RhsScalar,_LhsScalar>::type,
+ typename conditional<StorageOrder==RowMajor,_LhsScalar,_RhsScalar>::type>
+{
+ enum {
+ Transpose = StorageOrder==RowMajor
+ };
+ typedef typename conditional<Transpose,_RhsScalar,_LhsScalar>::type LhsScalar;
+ typedef typename conditional<Transpose,_LhsScalar,_RhsScalar>::type RhsScalar;
+ typedef gebp_traits<LhsScalar,RhsScalar> Traits;
+
+ Index m_sizeA;
+ Index m_sizeB;
+
+ public:
+
+ gemm_blocking_space(Index rows, Index cols, Index depth, Index num_threads, bool l3_blocking)
+ {
+ this->m_mc = Transpose ? cols : rows;
+ this->m_nc = Transpose ? rows : cols;
+ this->m_kc = depth;
+
+ if(l3_blocking)
+ {
+ computeProductBlockingSizes<LhsScalar,RhsScalar,KcFactor>(this->m_kc, this->m_mc, this->m_nc, num_threads);
+ }
+ else // no l3 blocking
+ {
+ Index n = this->m_nc;
+ computeProductBlockingSizes<LhsScalar,RhsScalar,KcFactor>(this->m_kc, this->m_mc, n, num_threads);
+ }
+
+ m_sizeA = this->m_mc * this->m_kc;
+ m_sizeB = this->m_kc * this->m_nc;
+ }
+
+ void initParallel(Index rows, Index cols, Index depth, Index num_threads)
+ {
+ this->m_mc = Transpose ? cols : rows;
+ this->m_nc = Transpose ? rows : cols;
+ this->m_kc = depth;
+
+ eigen_internal_assert(this->m_blockA==0 && this->m_blockB==0);
+ Index m = this->m_mc;
+ computeProductBlockingSizes<LhsScalar,RhsScalar,KcFactor>(this->m_kc, m, this->m_nc, num_threads);
+ m_sizeA = this->m_mc * this->m_kc;
+ m_sizeB = this->m_kc * this->m_nc;
+ }
+
+ void allocateA()
+ {
+ if(this->m_blockA==0)
+ this->m_blockA = aligned_new<LhsScalar>(m_sizeA);
+ }
+
+ void allocateB()
+ {
+ if(this->m_blockB==0)
+ this->m_blockB = aligned_new<RhsScalar>(m_sizeB);
+ }
+
+ void allocateAll()
+ {
+ allocateA();
+ allocateB();
+ }
+
+ ~gemm_blocking_space()
+ {
+ aligned_delete(this->m_blockA, m_sizeA);
+ aligned_delete(this->m_blockB, m_sizeB);
+ }
+};
+
+} // end namespace internal
+
+namespace internal {
+
+template<typename Lhs, typename Rhs>
+struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemmProduct>
+ : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemmProduct> >
+{
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+ typedef typename Lhs::Scalar LhsScalar;
+ typedef typename Rhs::Scalar RhsScalar;
+
+ typedef internal::blas_traits<Lhs> LhsBlasTraits;
+ typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
+ typedef typename internal::remove_all<ActualLhsType>::type ActualLhsTypeCleaned;
+
+ typedef internal::blas_traits<Rhs> RhsBlasTraits;
+ typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
+ typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned;
+
+ enum {
+ MaxDepthAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(Lhs::MaxColsAtCompileTime,Rhs::MaxRowsAtCompileTime)
+ };
+
+ typedef generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,CoeffBasedProductMode> lazyproduct;
+
+ template<typename Dst>
+ static void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ // See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=404 for a discussion and helper program
+ // to determine the following heuristic.
+ // EIGEN_GEMM_TO_COEFFBASED_THRESHOLD is typically defined to 20 in GeneralProduct.h,
+ // unless it has been specialized by the user or for a given architecture.
+ // Note that the condition rhs.rows()>0 was required because lazy product is (was?) not happy with empty inputs.
+ // I'm not sure it is still required.
+ if((rhs.rows()+dst.rows()+dst.cols())<EIGEN_GEMM_TO_COEFFBASED_THRESHOLD && rhs.rows()>0)
+ lazyproduct::eval_dynamic(dst, lhs, rhs, internal::assign_op<typename Dst::Scalar,Scalar>());
+ else
+ {
+ dst.setZero();
+ scaleAndAddTo(dst, lhs, rhs, Scalar(1));
+ }
+ }
+
+ template<typename Dst>
+ static void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ if((rhs.rows()+dst.rows()+dst.cols())<EIGEN_GEMM_TO_COEFFBASED_THRESHOLD && rhs.rows()>0)
+ lazyproduct::eval_dynamic(dst, lhs, rhs, internal::add_assign_op<typename Dst::Scalar,Scalar>());
+ else
+ scaleAndAddTo(dst,lhs, rhs, Scalar(1));
+ }
+
+ template<typename Dst>
+ static void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
+ {
+ if((rhs.rows()+dst.rows()+dst.cols())<EIGEN_GEMM_TO_COEFFBASED_THRESHOLD && rhs.rows()>0)
+ lazyproduct::eval_dynamic(dst, lhs, rhs, internal::sub_assign_op<typename Dst::Scalar,Scalar>());
+ else
+ scaleAndAddTo(dst, lhs, rhs, Scalar(-1));
+ }
+
+ template<typename Dest>
+ static void scaleAndAddTo(Dest& dst, const Lhs& a_lhs, const Rhs& a_rhs, const Scalar& alpha)
+ {
+ eigen_assert(dst.rows()==a_lhs.rows() && dst.cols()==a_rhs.cols());
+ if(a_lhs.cols()==0 || a_lhs.rows()==0 || a_rhs.cols()==0)
+ return;
+
+ if (dst.cols() == 1)
+ {
+ // Fallback to GEMV if either the lhs or rhs is a runtime vector
+ typename Dest::ColXpr dst_vec(dst.col(0));
+ return internal::generic_product_impl<Lhs,typename Rhs::ConstColXpr,DenseShape,DenseShape,GemvProduct>
+ ::scaleAndAddTo(dst_vec, a_lhs, a_rhs.col(0), alpha);
+ }
+ else if (dst.rows() == 1)
+ {
+ // Fallback to GEMV if either the lhs or rhs is a runtime vector
+ typename Dest::RowXpr dst_vec(dst.row(0));
+ return internal::generic_product_impl<typename Lhs::ConstRowXpr,Rhs,DenseShape,DenseShape,GemvProduct>
+ ::scaleAndAddTo(dst_vec, a_lhs.row(0), a_rhs, alpha);
+ }
+
+ typename internal::add_const_on_value_type<ActualLhsType>::type lhs = LhsBlasTraits::extract(a_lhs);
+ typename internal::add_const_on_value_type<ActualRhsType>::type rhs = RhsBlasTraits::extract(a_rhs);
+
+ Scalar actualAlpha = combine_scalar_factors(alpha, a_lhs, a_rhs);
+
+ typedef internal::gemm_blocking_space<(Dest::Flags&RowMajorBit) ? RowMajor : ColMajor,LhsScalar,RhsScalar,
+ Dest::MaxRowsAtCompileTime,Dest::MaxColsAtCompileTime,MaxDepthAtCompileTime> BlockingType;
+
+ typedef internal::gemm_functor<
+ Scalar, Index,
+ internal::general_matrix_matrix_product<
+ Index,
+ LhsScalar, (ActualLhsTypeCleaned::Flags&RowMajorBit) ? RowMajor : ColMajor, bool(LhsBlasTraits::NeedToConjugate),
+ RhsScalar, (ActualRhsTypeCleaned::Flags&RowMajorBit) ? RowMajor : ColMajor, bool(RhsBlasTraits::NeedToConjugate),
+ (Dest::Flags&RowMajorBit) ? RowMajor : ColMajor,
+ Dest::InnerStrideAtCompileTime>,
+ ActualLhsTypeCleaned, ActualRhsTypeCleaned, Dest, BlockingType> GemmFunctor;
+
+ BlockingType blocking(dst.rows(), dst.cols(), lhs.cols(), 1, true);
+ internal::parallelize_gemm<(Dest::MaxRowsAtCompileTime>32 || Dest::MaxRowsAtCompileTime==Dynamic)>
+ (GemmFunctor(lhs, rhs, dst, actualAlpha, blocking), a_lhs.rows(), a_rhs.cols(), a_lhs.cols(), Dest::Flags&RowMajorBit);
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_GENERAL_MATRIX_MATRIX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h
new file mode 100644
index 000000000..6ba0d9bdb
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h
@@ -0,0 +1,317 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H
+#define EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H
+
+namespace Eigen {
+
+template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjLhs, bool ConjRhs>
+struct selfadjoint_rank1_update;
+
+namespace internal {
+
+/**********************************************************************
+* This file implements a general A * B product while
+* evaluating only one triangular part of the product.
+* This is a more general version of self adjoint product (C += A A^T)
+* as the level 3 SYRK Blas routine.
+**********************************************************************/
+
+// forward declarations (defined at the end of this file)
+template<typename LhsScalar, typename RhsScalar, typename Index, int mr, int nr, bool ConjLhs, bool ConjRhs, int ResInnerStride, int UpLo>
+struct tribb_kernel;
+
+/* Optimized matrix-matrix product evaluating only one triangular half */
+template <typename Index,
+ typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs,
+ typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs,
+ int ResStorageOrder, int ResInnerStride, int UpLo, int Version = Specialized>
+struct general_matrix_matrix_triangular_product;
+
+// as usual if the result is row major => we transpose the product
+template <typename Index, typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs,
+ typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride, int UpLo, int Version>
+struct general_matrix_matrix_triangular_product<Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,RowMajor,ResInnerStride,UpLo,Version>
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
+ static EIGEN_STRONG_INLINE void run(Index size, Index depth,const LhsScalar* lhs, Index lhsStride,
+ const RhsScalar* rhs, Index rhsStride, ResScalar* res, Index resIncr, Index resStride,
+ const ResScalar& alpha, level3_blocking<RhsScalar,LhsScalar>& blocking)
+ {
+ general_matrix_matrix_triangular_product<Index,
+ RhsScalar, RhsStorageOrder==RowMajor ? ColMajor : RowMajor, ConjugateRhs,
+ LhsScalar, LhsStorageOrder==RowMajor ? ColMajor : RowMajor, ConjugateLhs,
+ ColMajor, ResInnerStride, UpLo==Lower?Upper:Lower>
+ ::run(size,depth,rhs,rhsStride,lhs,lhsStride,res,resIncr,resStride,alpha,blocking);
+ }
+};
+
+template <typename Index, typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs,
+ typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride, int UpLo, int Version>
+struct general_matrix_matrix_triangular_product<Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride,UpLo,Version>
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
+ static EIGEN_STRONG_INLINE void run(Index size, Index depth,const LhsScalar* _lhs, Index lhsStride,
+ const RhsScalar* _rhs, Index rhsStride,
+ ResScalar* _res, Index resIncr, Index resStride,
+ const ResScalar& alpha, level3_blocking<LhsScalar,RhsScalar>& blocking)
+ {
+ typedef gebp_traits<LhsScalar,RhsScalar> Traits;
+
+ typedef const_blas_data_mapper<LhsScalar, Index, LhsStorageOrder> LhsMapper;
+ typedef const_blas_data_mapper<RhsScalar, Index, RhsStorageOrder> RhsMapper;
+ typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper;
+ LhsMapper lhs(_lhs,lhsStride);
+ RhsMapper rhs(_rhs,rhsStride);
+ ResMapper res(_res, resStride, resIncr);
+
+ Index kc = blocking.kc();
+ Index mc = (std::min)(size,blocking.mc());
+
+ // !!! mc must be a multiple of nr:
+ if(mc > Traits::nr)
+ mc = (mc/Traits::nr)*Traits::nr;
+
+ std::size_t sizeA = kc*mc;
+ std::size_t sizeB = kc*size;
+
+ ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, blocking.blockA());
+ ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, blocking.blockB());
+
+ gemm_pack_lhs<LhsScalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs;
+ gemm_pack_rhs<RhsScalar, Index, RhsMapper, Traits::nr, RhsStorageOrder> pack_rhs;
+ gebp_kernel<LhsScalar, RhsScalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp;
+ tribb_kernel<LhsScalar, RhsScalar, Index, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs, ResInnerStride, UpLo> sybb;
+
+ for(Index k2=0; k2<depth; k2+=kc)
+ {
+ const Index actual_kc = (std::min)(k2+kc,depth)-k2;
+
+ // note that the actual rhs is the transpose/adjoint of mat
+ pack_rhs(blockB, rhs.getSubMapper(k2,0), actual_kc, size);
+
+ for(Index i2=0; i2<size; i2+=mc)
+ {
+ const Index actual_mc = (std::min)(i2+mc,size)-i2;
+
+ pack_lhs(blockA, lhs.getSubMapper(i2, k2), actual_kc, actual_mc);
+
+ // the selected actual_mc * size panel of res is split into three different part:
+ // 1 - before the diagonal => processed with gebp or skipped
+ // 2 - the actual_mc x actual_mc symmetric block => processed with a special kernel
+ // 3 - after the diagonal => processed with gebp or skipped
+ if (UpLo==Lower)
+ gebp(res.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc,
+ (std::min)(size,i2), alpha, -1, -1, 0, 0);
+
+ sybb(_res+resStride*i2 + resIncr*i2, resIncr, resStride, blockA, blockB + actual_kc*i2, actual_mc, actual_kc, alpha);
+
+ if (UpLo==Upper)
+ {
+ Index j2 = i2+actual_mc;
+ gebp(res.getSubMapper(i2, j2), blockA, blockB+actual_kc*j2, actual_mc,
+ actual_kc, (std::max)(Index(0), size-j2), alpha, -1, -1, 0, 0);
+ }
+ }
+ }
+ }
+};
+
+// Optimized packed Block * packed Block product kernel evaluating only one given triangular part
+// This kernel is built on top of the gebp kernel:
+// - the current destination block is processed per panel of actual_mc x BlockSize
+// where BlockSize is set to the minimal value allowing gebp to be as fast as possible
+// - then, as usual, each panel is split into three parts along the diagonal,
+// the sub blocks above and below the diagonal are processed as usual,
+// while the triangular block overlapping the diagonal is evaluated into a
+// small temporary buffer which is then accumulated into the result using a
+// triangular traversal.
+template<typename LhsScalar, typename RhsScalar, typename Index, int mr, int nr, bool ConjLhs, bool ConjRhs, int ResInnerStride, int UpLo>
+struct tribb_kernel
+{
+ typedef gebp_traits<LhsScalar,RhsScalar,ConjLhs,ConjRhs> Traits;
+ typedef typename Traits::ResScalar ResScalar;
+
+ enum {
+ BlockSize = meta_least_common_multiple<EIGEN_PLAIN_ENUM_MAX(mr,nr),EIGEN_PLAIN_ENUM_MIN(mr,nr)>::ret
+ };
+ void operator()(ResScalar* _res, Index resIncr, Index resStride, const LhsScalar* blockA, const RhsScalar* blockB, Index size, Index depth, const ResScalar& alpha)
+ {
+ typedef blas_data_mapper<ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper;
+ typedef blas_data_mapper<ResScalar, Index, ColMajor, Unaligned> BufferMapper;
+ ResMapper res(_res, resStride, resIncr);
+ gebp_kernel<LhsScalar, RhsScalar, Index, ResMapper, mr, nr, ConjLhs, ConjRhs> gebp_kernel1;
+ gebp_kernel<LhsScalar, RhsScalar, Index, BufferMapper, mr, nr, ConjLhs, ConjRhs> gebp_kernel2;
+
+ Matrix<ResScalar,BlockSize,BlockSize,ColMajor> buffer((internal::constructor_without_unaligned_array_assert()));
+
+ // let's process the block per panel of actual_mc x BlockSize,
+ // again, each is split into three parts, etc.
+ for (Index j=0; j<size; j+=BlockSize)
+ {
+ Index actualBlockSize = std::min<Index>(BlockSize,size - j);
+ const RhsScalar* actual_b = blockB+j*depth;
+
+ if(UpLo==Upper)
+ gebp_kernel1(res.getSubMapper(0, j), blockA, actual_b, j, depth, actualBlockSize, alpha,
+ -1, -1, 0, 0);
+
+ // selfadjoint micro block
+ {
+ Index i = j;
+ buffer.setZero();
+ // 1 - apply the kernel on the temporary buffer
+ gebp_kernel2(BufferMapper(buffer.data(), BlockSize), blockA+depth*i, actual_b, actualBlockSize, depth, actualBlockSize, alpha,
+ -1, -1, 0, 0);
+
+ // 2 - triangular accumulation
+ for(Index j1=0; j1<actualBlockSize; ++j1)
+ {
+ typename ResMapper::LinearMapper r = res.getLinearMapper(i,j+j1);
+ for(Index i1=UpLo==Lower ? j1 : 0;
+ UpLo==Lower ? i1<actualBlockSize : i1<=j1; ++i1)
+ r(i1) += buffer(i1,j1);
+ }
+ }
+
+ if(UpLo==Lower)
+ {
+ Index i = j+actualBlockSize;
+ gebp_kernel1(res.getSubMapper(i, j), blockA+depth*i, actual_b, size-i,
+ depth, actualBlockSize, alpha, -1, -1, 0, 0);
+ }
+ }
+ }
+};
+
+} // end namespace internal
+
+// high level API
+
+template<typename MatrixType, typename ProductType, int UpLo, bool IsOuterProduct>
+struct general_product_to_triangular_selector;
+
+
+template<typename MatrixType, typename ProductType, int UpLo>
+struct general_product_to_triangular_selector<MatrixType,ProductType,UpLo,true>
+{
+ static void run(MatrixType& mat, const ProductType& prod, const typename MatrixType::Scalar& alpha, bool beta)
+ {
+ typedef typename MatrixType::Scalar Scalar;
+
+ typedef typename internal::remove_all<typename ProductType::LhsNested>::type Lhs;
+ typedef internal::blas_traits<Lhs> LhsBlasTraits;
+ typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhs;
+ typedef typename internal::remove_all<ActualLhs>::type _ActualLhs;
+ typename internal::add_const_on_value_type<ActualLhs>::type actualLhs = LhsBlasTraits::extract(prod.lhs());
+
+ typedef typename internal::remove_all<typename ProductType::RhsNested>::type Rhs;
+ typedef internal::blas_traits<Rhs> RhsBlasTraits;
+ typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhs;
+ typedef typename internal::remove_all<ActualRhs>::type _ActualRhs;
+ typename internal::add_const_on_value_type<ActualRhs>::type actualRhs = RhsBlasTraits::extract(prod.rhs());
+
+ Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs().derived()) * RhsBlasTraits::extractScalarFactor(prod.rhs().derived());
+
+ if(!beta)
+ mat.template triangularView<UpLo>().setZero();
+
+ enum {
+ StorageOrder = (internal::traits<MatrixType>::Flags&RowMajorBit) ? RowMajor : ColMajor,
+ UseLhsDirectly = _ActualLhs::InnerStrideAtCompileTime==1,
+ UseRhsDirectly = _ActualRhs::InnerStrideAtCompileTime==1
+ };
+
+ internal::gemv_static_vector_if<Scalar,Lhs::SizeAtCompileTime,Lhs::MaxSizeAtCompileTime,!UseLhsDirectly> static_lhs;
+ ei_declare_aligned_stack_constructed_variable(Scalar, actualLhsPtr, actualLhs.size(),
+ (UseLhsDirectly ? const_cast<Scalar*>(actualLhs.data()) : static_lhs.data()));
+ if(!UseLhsDirectly) Map<typename _ActualLhs::PlainObject>(actualLhsPtr, actualLhs.size()) = actualLhs;
+
+ internal::gemv_static_vector_if<Scalar,Rhs::SizeAtCompileTime,Rhs::MaxSizeAtCompileTime,!UseRhsDirectly> static_rhs;
+ ei_declare_aligned_stack_constructed_variable(Scalar, actualRhsPtr, actualRhs.size(),
+ (UseRhsDirectly ? const_cast<Scalar*>(actualRhs.data()) : static_rhs.data()));
+ if(!UseRhsDirectly) Map<typename _ActualRhs::PlainObject>(actualRhsPtr, actualRhs.size()) = actualRhs;
+
+
+ selfadjoint_rank1_update<Scalar,Index,StorageOrder,UpLo,
+ LhsBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex,
+ RhsBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex>
+ ::run(actualLhs.size(), mat.data(), mat.outerStride(), actualLhsPtr, actualRhsPtr, actualAlpha);
+ }
+};
+
+template<typename MatrixType, typename ProductType, int UpLo>
+struct general_product_to_triangular_selector<MatrixType,ProductType,UpLo,false>
+{
+ static void run(MatrixType& mat, const ProductType& prod, const typename MatrixType::Scalar& alpha, bool beta)
+ {
+ typedef typename internal::remove_all<typename ProductType::LhsNested>::type Lhs;
+ typedef internal::blas_traits<Lhs> LhsBlasTraits;
+ typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhs;
+ typedef typename internal::remove_all<ActualLhs>::type _ActualLhs;
+ typename internal::add_const_on_value_type<ActualLhs>::type actualLhs = LhsBlasTraits::extract(prod.lhs());
+
+ typedef typename internal::remove_all<typename ProductType::RhsNested>::type Rhs;
+ typedef internal::blas_traits<Rhs> RhsBlasTraits;
+ typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhs;
+ typedef typename internal::remove_all<ActualRhs>::type _ActualRhs;
+ typename internal::add_const_on_value_type<ActualRhs>::type actualRhs = RhsBlasTraits::extract(prod.rhs());
+
+ typename ProductType::Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs().derived()) * RhsBlasTraits::extractScalarFactor(prod.rhs().derived());
+
+ if(!beta)
+ mat.template triangularView<UpLo>().setZero();
+
+ enum {
+ IsRowMajor = (internal::traits<MatrixType>::Flags&RowMajorBit) ? 1 : 0,
+ LhsIsRowMajor = _ActualLhs::Flags&RowMajorBit ? 1 : 0,
+ RhsIsRowMajor = _ActualRhs::Flags&RowMajorBit ? 1 : 0,
+ SkipDiag = (UpLo&(UnitDiag|ZeroDiag))!=0
+ };
+
+ Index size = mat.cols();
+ if(SkipDiag)
+ size--;
+ Index depth = actualLhs.cols();
+
+ typedef internal::gemm_blocking_space<IsRowMajor ? RowMajor : ColMajor,typename Lhs::Scalar,typename Rhs::Scalar,
+ MatrixType::MaxColsAtCompileTime, MatrixType::MaxColsAtCompileTime, _ActualRhs::MaxColsAtCompileTime> BlockingType;
+
+ BlockingType blocking(size, size, depth, 1, false);
+
+ internal::general_matrix_matrix_triangular_product<Index,
+ typename Lhs::Scalar, LhsIsRowMajor ? RowMajor : ColMajor, LhsBlasTraits::NeedToConjugate,
+ typename Rhs::Scalar, RhsIsRowMajor ? RowMajor : ColMajor, RhsBlasTraits::NeedToConjugate,
+ IsRowMajor ? RowMajor : ColMajor, MatrixType::InnerStrideAtCompileTime, UpLo&(Lower|Upper)>
+ ::run(size, depth,
+ &actualLhs.coeffRef(SkipDiag&&(UpLo&Lower)==Lower ? 1 : 0,0), actualLhs.outerStride(),
+ &actualRhs.coeffRef(0,SkipDiag&&(UpLo&Upper)==Upper ? 1 : 0), actualRhs.outerStride(),
+ mat.data() + (SkipDiag ? (bool(IsRowMajor) != ((UpLo&Lower)==Lower) ? mat.innerStride() : mat.outerStride() ) : 0),
+ mat.innerStride(), mat.outerStride(), actualAlpha, blocking);
+ }
+};
+
+template<typename MatrixType, unsigned int UpLo>
+template<typename ProductType>
+EIGEN_DEVICE_FUNC TriangularView<MatrixType,UpLo>& TriangularViewImpl<MatrixType,UpLo,Dense>::_assignProduct(const ProductType& prod, const Scalar& alpha, bool beta)
+{
+ EIGEN_STATIC_ASSERT((UpLo&UnitDiag)==0, WRITING_TO_TRIANGULAR_PART_WITH_UNIT_DIAGONAL_IS_NOT_SUPPORTED);
+ eigen_assert(derived().nestedExpression().rows() == prod.rows() && derived().cols() == prod.cols());
+
+ general_product_to_triangular_selector<MatrixType, ProductType, UpLo, internal::traits<ProductType>::InnerSize==1>::run(derived().nestedExpression().const_cast_derived(), prod, alpha, beta);
+
+ return derived();
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h
new file mode 100644
index 000000000..9a650ec23
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h
@@ -0,0 +1,145 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to BLAS F77
+ * Level 3 BLAS SYRK/HERK implementation.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H
+#define EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H
+
+namespace Eigen {
+
+namespace internal {
+
+template <typename Index, typename Scalar, int AStorageOrder, bool ConjugateA, int ResStorageOrder, int UpLo>
+struct general_matrix_matrix_rankupdate :
+ general_matrix_matrix_triangular_product<
+ Index,Scalar,AStorageOrder,ConjugateA,Scalar,AStorageOrder,ConjugateA,ResStorageOrder,1,UpLo,BuiltIn> {};
+
+
+// try to go to BLAS specialization
+#define EIGEN_BLAS_RANKUPDATE_SPECIALIZE(Scalar) \
+template <typename Index, int LhsStorageOrder, bool ConjugateLhs, \
+ int RhsStorageOrder, bool ConjugateRhs, int UpLo> \
+struct general_matrix_matrix_triangular_product<Index,Scalar,LhsStorageOrder,ConjugateLhs, \
+ Scalar,RhsStorageOrder,ConjugateRhs,ColMajor,1,UpLo,Specialized> { \
+ static EIGEN_STRONG_INLINE void run(Index size, Index depth,const Scalar* lhs, Index lhsStride, \
+ const Scalar* rhs, Index rhsStride, Scalar* res, Index resIncr, Index resStride, Scalar alpha, level3_blocking<Scalar, Scalar>& blocking) \
+ { \
+ if ( lhs==rhs && ((UpLo&(Lower|Upper))==UpLo) ) { \
+ general_matrix_matrix_rankupdate<Index,Scalar,LhsStorageOrder,ConjugateLhs,ColMajor,UpLo> \
+ ::run(size,depth,lhs,lhsStride,rhs,rhsStride,res,resStride,alpha,blocking); \
+ } else { \
+ general_matrix_matrix_triangular_product<Index, \
+ Scalar, LhsStorageOrder, ConjugateLhs, \
+ Scalar, RhsStorageOrder, ConjugateRhs, \
+ ColMajor, 1, UpLo, BuiltIn> \
+ ::run(size,depth,lhs,lhsStride,rhs,rhsStride,res,resIncr,resStride,alpha,blocking); \
+ } \
+ } \
+};
+
+EIGEN_BLAS_RANKUPDATE_SPECIALIZE(double)
+EIGEN_BLAS_RANKUPDATE_SPECIALIZE(float)
+// TODO handle complex cases
+// EIGEN_BLAS_RANKUPDATE_SPECIALIZE(dcomplex)
+// EIGEN_BLAS_RANKUPDATE_SPECIALIZE(scomplex)
+
+// SYRK for float/double
+#define EIGEN_BLAS_RANKUPDATE_R(EIGTYPE, BLASTYPE, BLASFUNC) \
+template <typename Index, int AStorageOrder, bool ConjugateA, int UpLo> \
+struct general_matrix_matrix_rankupdate<Index,EIGTYPE,AStorageOrder,ConjugateA,ColMajor,UpLo> { \
+ enum { \
+ IsLower = (UpLo&Lower) == Lower, \
+ LowUp = IsLower ? Lower : Upper, \
+ conjA = ((AStorageOrder==ColMajor) && ConjugateA) ? 1 : 0 \
+ }; \
+ static EIGEN_STRONG_INLINE void run(Index size, Index depth,const EIGTYPE* lhs, Index lhsStride, \
+ const EIGTYPE* /*rhs*/, Index /*rhsStride*/, EIGTYPE* res, Index resStride, EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \
+ { \
+ /* typedef Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder> MatrixRhs;*/ \
+\
+ BlasIndex lda=convert_index<BlasIndex>(lhsStride), ldc=convert_index<BlasIndex>(resStride), n=convert_index<BlasIndex>(size), k=convert_index<BlasIndex>(depth); \
+ char uplo=((IsLower) ? 'L' : 'U'), trans=((AStorageOrder==RowMajor) ? 'T':'N'); \
+ EIGTYPE beta(1); \
+ BLASFUNC(&uplo, &trans, &n, &k, (const BLASTYPE*)&numext::real_ref(alpha), lhs, &lda, (const BLASTYPE*)&numext::real_ref(beta), res, &ldc); \
+ } \
+};
+
+// HERK for complex data
+#define EIGEN_BLAS_RANKUPDATE_C(EIGTYPE, BLASTYPE, RTYPE, BLASFUNC) \
+template <typename Index, int AStorageOrder, bool ConjugateA, int UpLo> \
+struct general_matrix_matrix_rankupdate<Index,EIGTYPE,AStorageOrder,ConjugateA,ColMajor,UpLo> { \
+ enum { \
+ IsLower = (UpLo&Lower) == Lower, \
+ LowUp = IsLower ? Lower : Upper, \
+ conjA = (((AStorageOrder==ColMajor) && ConjugateA) || ((AStorageOrder==RowMajor) && !ConjugateA)) ? 1 : 0 \
+ }; \
+ static EIGEN_STRONG_INLINE void run(Index size, Index depth,const EIGTYPE* lhs, Index lhsStride, \
+ const EIGTYPE* /*rhs*/, Index /*rhsStride*/, EIGTYPE* res, Index resStride, EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \
+ { \
+ typedef Matrix<EIGTYPE, Dynamic, Dynamic, AStorageOrder> MatrixType; \
+\
+ BlasIndex lda=convert_index<BlasIndex>(lhsStride), ldc=convert_index<BlasIndex>(resStride), n=convert_index<BlasIndex>(size), k=convert_index<BlasIndex>(depth); \
+ char uplo=((IsLower) ? 'L' : 'U'), trans=((AStorageOrder==RowMajor) ? 'C':'N'); \
+ RTYPE alpha_, beta_; \
+ const EIGTYPE* a_ptr; \
+\
+ alpha_ = alpha.real(); \
+ beta_ = 1.0; \
+/* Copy with conjugation in some cases*/ \
+ MatrixType a; \
+ if (conjA) { \
+ Map<const MatrixType, 0, OuterStride<> > mapA(lhs,n,k,OuterStride<>(lhsStride)); \
+ a = mapA.conjugate(); \
+ lda = a.outerStride(); \
+ a_ptr = a.data(); \
+ } else a_ptr=lhs; \
+ BLASFUNC(&uplo, &trans, &n, &k, &alpha_, (BLASTYPE*)a_ptr, &lda, &beta_, (BLASTYPE*)res, &ldc); \
+ } \
+};
+
+#ifdef EIGEN_USE_MKL
+EIGEN_BLAS_RANKUPDATE_R(double, double, dsyrk)
+EIGEN_BLAS_RANKUPDATE_R(float, float, ssyrk)
+#else
+EIGEN_BLAS_RANKUPDATE_R(double, double, dsyrk_)
+EIGEN_BLAS_RANKUPDATE_R(float, float, ssyrk_)
+#endif
+
+// TODO hanlde complex cases
+// EIGEN_BLAS_RANKUPDATE_C(dcomplex, double, double, zherk_)
+// EIGEN_BLAS_RANKUPDATE_C(scomplex, float, float, cherk_)
+
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h
new file mode 100644
index 000000000..71abf4013
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h
@@ -0,0 +1,124 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to BLAS F77
+ * General matrix-matrix product functionality based on ?GEMM.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_GENERAL_MATRIX_MATRIX_BLAS_H
+#define EIGEN_GENERAL_MATRIX_MATRIX_BLAS_H
+
+namespace Eigen {
+
+namespace internal {
+
+/**********************************************************************
+* This file implements general matrix-matrix multiplication using BLAS
+* gemm function via partial specialization of
+* general_matrix_matrix_product::run(..) method for float, double,
+* std::complex<float> and std::complex<double> types
+**********************************************************************/
+
+// gemm specialization
+
+#define GEMM_SPECIALIZATION(EIGTYPE, EIGPREFIX, BLASTYPE, BLASFUNC) \
+template< \
+ typename Index, \
+ int LhsStorageOrder, bool ConjugateLhs, \
+ int RhsStorageOrder, bool ConjugateRhs> \
+struct general_matrix_matrix_product<Index,EIGTYPE,LhsStorageOrder,ConjugateLhs,EIGTYPE,RhsStorageOrder,ConjugateRhs,ColMajor,1> \
+{ \
+typedef gebp_traits<EIGTYPE,EIGTYPE> Traits; \
+\
+static void run(Index rows, Index cols, Index depth, \
+ const EIGTYPE* _lhs, Index lhsStride, \
+ const EIGTYPE* _rhs, Index rhsStride, \
+ EIGTYPE* res, Index resIncr, Index resStride, \
+ EIGTYPE alpha, \
+ level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/, \
+ GemmParallelInfo<Index>* /*info = 0*/) \
+{ \
+ using std::conj; \
+\
+ EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \
+ eigen_assert(resIncr == 1); \
+ char transa, transb; \
+ BlasIndex m, n, k, lda, ldb, ldc; \
+ const EIGTYPE *a, *b; \
+ EIGTYPE beta(1); \
+ MatrixX##EIGPREFIX a_tmp, b_tmp; \
+\
+/* Set transpose options */ \
+ transa = (LhsStorageOrder==RowMajor) ? ((ConjugateLhs) ? 'C' : 'T') : 'N'; \
+ transb = (RhsStorageOrder==RowMajor) ? ((ConjugateRhs) ? 'C' : 'T') : 'N'; \
+\
+/* Set m, n, k */ \
+ m = convert_index<BlasIndex>(rows); \
+ n = convert_index<BlasIndex>(cols); \
+ k = convert_index<BlasIndex>(depth); \
+\
+/* Set lda, ldb, ldc */ \
+ lda = convert_index<BlasIndex>(lhsStride); \
+ ldb = convert_index<BlasIndex>(rhsStride); \
+ ldc = convert_index<BlasIndex>(resStride); \
+\
+/* Set a, b, c */ \
+ if ((LhsStorageOrder==ColMajor) && (ConjugateLhs)) { \
+ Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,m,k,OuterStride<>(lhsStride)); \
+ a_tmp = lhs.conjugate(); \
+ a = a_tmp.data(); \
+ lda = convert_index<BlasIndex>(a_tmp.outerStride()); \
+ } else a = _lhs; \
+\
+ if ((RhsStorageOrder==ColMajor) && (ConjugateRhs)) { \
+ Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,k,n,OuterStride<>(rhsStride)); \
+ b_tmp = rhs.conjugate(); \
+ b = b_tmp.data(); \
+ ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \
+ } else b = _rhs; \
+\
+ BLASFUNC(&transa, &transb, &m, &n, &k, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &ldc); \
+}};
+
+#ifdef EIGEN_USE_MKL
+GEMM_SPECIALIZATION(double, d, double, dgemm)
+GEMM_SPECIALIZATION(float, f, float, sgemm)
+GEMM_SPECIALIZATION(dcomplex, cd, MKL_Complex16, zgemm)
+GEMM_SPECIALIZATION(scomplex, cf, MKL_Complex8, cgemm)
+#else
+GEMM_SPECIALIZATION(double, d, double, dgemm_)
+GEMM_SPECIALIZATION(float, f, float, sgemm_)
+GEMM_SPECIALIZATION(dcomplex, cd, double, zgemm_)
+GEMM_SPECIALIZATION(scomplex, cf, float, cgemm_)
+#endif
+
+} // end namespase internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_GENERAL_MATRIX_MATRIX_BLAS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixVector.h b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixVector.h
new file mode 100644
index 000000000..dfb6aebce
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixVector.h
@@ -0,0 +1,518 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GENERAL_MATRIX_VECTOR_H
+#define EIGEN_GENERAL_MATRIX_VECTOR_H
+
+namespace Eigen {
+
+namespace internal {
+
+enum GEMVPacketSizeType {
+ GEMVPacketFull = 0,
+ GEMVPacketHalf,
+ GEMVPacketQuarter
+};
+
+template <int N, typename T1, typename T2, typename T3>
+struct gemv_packet_cond { typedef T3 type; };
+
+template <typename T1, typename T2, typename T3>
+struct gemv_packet_cond<GEMVPacketFull, T1, T2, T3> { typedef T1 type; };
+
+template <typename T1, typename T2, typename T3>
+struct gemv_packet_cond<GEMVPacketHalf, T1, T2, T3> { typedef T2 type; };
+
+template<typename LhsScalar, typename RhsScalar, int _PacketSize=GEMVPacketFull>
+class gemv_traits
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
+
+#define PACKET_DECL_COND_PREFIX(prefix, name, packet_size) \
+ typedef typename gemv_packet_cond<packet_size, \
+ typename packet_traits<name ## Scalar>::type, \
+ typename packet_traits<name ## Scalar>::half, \
+ typename unpacket_traits<typename packet_traits<name ## Scalar>::half>::half>::type \
+ prefix ## name ## Packet
+
+ PACKET_DECL_COND_PREFIX(_, Lhs, _PacketSize);
+ PACKET_DECL_COND_PREFIX(_, Rhs, _PacketSize);
+ PACKET_DECL_COND_PREFIX(_, Res, _PacketSize);
+#undef PACKET_DECL_COND_PREFIX
+
+public:
+ enum {
+ Vectorizable = unpacket_traits<_LhsPacket>::vectorizable &&
+ unpacket_traits<_RhsPacket>::vectorizable &&
+ int(unpacket_traits<_LhsPacket>::size)==int(unpacket_traits<_RhsPacket>::size),
+ LhsPacketSize = Vectorizable ? unpacket_traits<_LhsPacket>::size : 1,
+ RhsPacketSize = Vectorizable ? unpacket_traits<_RhsPacket>::size : 1,
+ ResPacketSize = Vectorizable ? unpacket_traits<_ResPacket>::size : 1
+ };
+
+ typedef typename conditional<Vectorizable,_LhsPacket,LhsScalar>::type LhsPacket;
+ typedef typename conditional<Vectorizable,_RhsPacket,RhsScalar>::type RhsPacket;
+ typedef typename conditional<Vectorizable,_ResPacket,ResScalar>::type ResPacket;
+};
+
+
+/* Optimized col-major matrix * vector product:
+ * This algorithm processes the matrix per vertical panels,
+ * which are then processed horizontaly per chunck of 8*PacketSize x 1 vertical segments.
+ *
+ * Mixing type logic: C += alpha * A * B
+ * | A | B |alpha| comments
+ * |real |cplx |cplx | no vectorization
+ * |real |cplx |real | alpha is converted to a cplx when calling the run function, no vectorization
+ * |cplx |real |cplx | invalid, the caller has to do tmp: = A * B; C += alpha*tmp
+ * |cplx |real |real | optimal case, vectorization possible via real-cplx mul
+ *
+ * The same reasoning apply for the transposed case.
+ */
+template<typename Index, typename LhsScalar, typename LhsMapper, bool ConjugateLhs, typename RhsScalar, typename RhsMapper, bool ConjugateRhs, int Version>
+struct general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,ConjugateLhs,RhsScalar,RhsMapper,ConjugateRhs,Version>
+{
+ typedef gemv_traits<LhsScalar,RhsScalar> Traits;
+ typedef gemv_traits<LhsScalar,RhsScalar,GEMVPacketHalf> HalfTraits;
+ typedef gemv_traits<LhsScalar,RhsScalar,GEMVPacketQuarter> QuarterTraits;
+
+ typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
+
+ typedef typename Traits::LhsPacket LhsPacket;
+ typedef typename Traits::RhsPacket RhsPacket;
+ typedef typename Traits::ResPacket ResPacket;
+
+ typedef typename HalfTraits::LhsPacket LhsPacketHalf;
+ typedef typename HalfTraits::RhsPacket RhsPacketHalf;
+ typedef typename HalfTraits::ResPacket ResPacketHalf;
+
+ typedef typename QuarterTraits::LhsPacket LhsPacketQuarter;
+ typedef typename QuarterTraits::RhsPacket RhsPacketQuarter;
+ typedef typename QuarterTraits::ResPacket ResPacketQuarter;
+
+EIGEN_DEVICE_FUNC EIGEN_DONT_INLINE static void run(
+ Index rows, Index cols,
+ const LhsMapper& lhs,
+ const RhsMapper& rhs,
+ ResScalar* res, Index resIncr,
+ RhsScalar alpha);
+};
+
+template<typename Index, typename LhsScalar, typename LhsMapper, bool ConjugateLhs, typename RhsScalar, typename RhsMapper, bool ConjugateRhs, int Version>
+EIGEN_DEVICE_FUNC EIGEN_DONT_INLINE void general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,ConjugateLhs,RhsScalar,RhsMapper,ConjugateRhs,Version>::run(
+ Index rows, Index cols,
+ const LhsMapper& alhs,
+ const RhsMapper& rhs,
+ ResScalar* res, Index resIncr,
+ RhsScalar alpha)
+{
+ EIGEN_UNUSED_VARIABLE(resIncr);
+ eigen_internal_assert(resIncr==1);
+
+ // The following copy tells the compiler that lhs's attributes are not modified outside this function
+ // This helps GCC to generate propoer code.
+ LhsMapper lhs(alhs);
+
+ conj_helper<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs> cj;
+ conj_helper<LhsPacket,RhsPacket,ConjugateLhs,ConjugateRhs> pcj;
+ conj_helper<LhsPacketHalf,RhsPacketHalf,ConjugateLhs,ConjugateRhs> pcj_half;
+ conj_helper<LhsPacketQuarter,RhsPacketQuarter,ConjugateLhs,ConjugateRhs> pcj_quarter;
+
+ const Index lhsStride = lhs.stride();
+ // TODO: for padded aligned inputs, we could enable aligned reads
+ enum { LhsAlignment = Unaligned,
+ ResPacketSize = Traits::ResPacketSize,
+ ResPacketSizeHalf = HalfTraits::ResPacketSize,
+ ResPacketSizeQuarter = QuarterTraits::ResPacketSize,
+ LhsPacketSize = Traits::LhsPacketSize,
+ HasHalf = (int)ResPacketSizeHalf < (int)ResPacketSize,
+ HasQuarter = (int)ResPacketSizeQuarter < (int)ResPacketSizeHalf
+ };
+
+ const Index n8 = rows-8*ResPacketSize+1;
+ const Index n4 = rows-4*ResPacketSize+1;
+ const Index n3 = rows-3*ResPacketSize+1;
+ const Index n2 = rows-2*ResPacketSize+1;
+ const Index n1 = rows-1*ResPacketSize+1;
+ const Index n_half = rows-1*ResPacketSizeHalf+1;
+ const Index n_quarter = rows-1*ResPacketSizeQuarter+1;
+
+ // TODO: improve the following heuristic:
+ const Index block_cols = cols<128 ? cols : (lhsStride*sizeof(LhsScalar)<32000?16:4);
+ ResPacket palpha = pset1<ResPacket>(alpha);
+ ResPacketHalf palpha_half = pset1<ResPacketHalf>(alpha);
+ ResPacketQuarter palpha_quarter = pset1<ResPacketQuarter>(alpha);
+
+ for(Index j2=0; j2<cols; j2+=block_cols)
+ {
+ Index jend = numext::mini(j2+block_cols,cols);
+ Index i=0;
+ for(; i<n8; i+=ResPacketSize*8)
+ {
+ ResPacket c0 = pset1<ResPacket>(ResScalar(0)),
+ c1 = pset1<ResPacket>(ResScalar(0)),
+ c2 = pset1<ResPacket>(ResScalar(0)),
+ c3 = pset1<ResPacket>(ResScalar(0)),
+ c4 = pset1<ResPacket>(ResScalar(0)),
+ c5 = pset1<ResPacket>(ResScalar(0)),
+ c6 = pset1<ResPacket>(ResScalar(0)),
+ c7 = pset1<ResPacket>(ResScalar(0));
+
+ for(Index j=j2; j<jend; j+=1)
+ {
+ RhsPacket b0 = pset1<RhsPacket>(rhs(j,0));
+ c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*0,j),b0,c0);
+ c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*1,j),b0,c1);
+ c2 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*2,j),b0,c2);
+ c3 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*3,j),b0,c3);
+ c4 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*4,j),b0,c4);
+ c5 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*5,j),b0,c5);
+ c6 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*6,j),b0,c6);
+ c7 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*7,j),b0,c7);
+ }
+ pstoreu(res+i+ResPacketSize*0, pmadd(c0,palpha,ploadu<ResPacket>(res+i+ResPacketSize*0)));
+ pstoreu(res+i+ResPacketSize*1, pmadd(c1,palpha,ploadu<ResPacket>(res+i+ResPacketSize*1)));
+ pstoreu(res+i+ResPacketSize*2, pmadd(c2,palpha,ploadu<ResPacket>(res+i+ResPacketSize*2)));
+ pstoreu(res+i+ResPacketSize*3, pmadd(c3,palpha,ploadu<ResPacket>(res+i+ResPacketSize*3)));
+ pstoreu(res+i+ResPacketSize*4, pmadd(c4,palpha,ploadu<ResPacket>(res+i+ResPacketSize*4)));
+ pstoreu(res+i+ResPacketSize*5, pmadd(c5,palpha,ploadu<ResPacket>(res+i+ResPacketSize*5)));
+ pstoreu(res+i+ResPacketSize*6, pmadd(c6,palpha,ploadu<ResPacket>(res+i+ResPacketSize*6)));
+ pstoreu(res+i+ResPacketSize*7, pmadd(c7,palpha,ploadu<ResPacket>(res+i+ResPacketSize*7)));
+ }
+ if(i<n4)
+ {
+ ResPacket c0 = pset1<ResPacket>(ResScalar(0)),
+ c1 = pset1<ResPacket>(ResScalar(0)),
+ c2 = pset1<ResPacket>(ResScalar(0)),
+ c3 = pset1<ResPacket>(ResScalar(0));
+
+ for(Index j=j2; j<jend; j+=1)
+ {
+ RhsPacket b0 = pset1<RhsPacket>(rhs(j,0));
+ c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*0,j),b0,c0);
+ c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*1,j),b0,c1);
+ c2 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*2,j),b0,c2);
+ c3 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*3,j),b0,c3);
+ }
+ pstoreu(res+i+ResPacketSize*0, pmadd(c0,palpha,ploadu<ResPacket>(res+i+ResPacketSize*0)));
+ pstoreu(res+i+ResPacketSize*1, pmadd(c1,palpha,ploadu<ResPacket>(res+i+ResPacketSize*1)));
+ pstoreu(res+i+ResPacketSize*2, pmadd(c2,palpha,ploadu<ResPacket>(res+i+ResPacketSize*2)));
+ pstoreu(res+i+ResPacketSize*3, pmadd(c3,palpha,ploadu<ResPacket>(res+i+ResPacketSize*3)));
+
+ i+=ResPacketSize*4;
+ }
+ if(i<n3)
+ {
+ ResPacket c0 = pset1<ResPacket>(ResScalar(0)),
+ c1 = pset1<ResPacket>(ResScalar(0)),
+ c2 = pset1<ResPacket>(ResScalar(0));
+
+ for(Index j=j2; j<jend; j+=1)
+ {
+ RhsPacket b0 = pset1<RhsPacket>(rhs(j,0));
+ c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*0,j),b0,c0);
+ c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*1,j),b0,c1);
+ c2 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*2,j),b0,c2);
+ }
+ pstoreu(res+i+ResPacketSize*0, pmadd(c0,palpha,ploadu<ResPacket>(res+i+ResPacketSize*0)));
+ pstoreu(res+i+ResPacketSize*1, pmadd(c1,palpha,ploadu<ResPacket>(res+i+ResPacketSize*1)));
+ pstoreu(res+i+ResPacketSize*2, pmadd(c2,palpha,ploadu<ResPacket>(res+i+ResPacketSize*2)));
+
+ i+=ResPacketSize*3;
+ }
+ if(i<n2)
+ {
+ ResPacket c0 = pset1<ResPacket>(ResScalar(0)),
+ c1 = pset1<ResPacket>(ResScalar(0));
+
+ for(Index j=j2; j<jend; j+=1)
+ {
+ RhsPacket b0 = pset1<RhsPacket>(rhs(j,0));
+ c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*0,j),b0,c0);
+ c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+LhsPacketSize*1,j),b0,c1);
+ }
+ pstoreu(res+i+ResPacketSize*0, pmadd(c0,palpha,ploadu<ResPacket>(res+i+ResPacketSize*0)));
+ pstoreu(res+i+ResPacketSize*1, pmadd(c1,palpha,ploadu<ResPacket>(res+i+ResPacketSize*1)));
+ i+=ResPacketSize*2;
+ }
+ if(i<n1)
+ {
+ ResPacket c0 = pset1<ResPacket>(ResScalar(0));
+ for(Index j=j2; j<jend; j+=1)
+ {
+ RhsPacket b0 = pset1<RhsPacket>(rhs(j,0));
+ c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+0,j),b0,c0);
+ }
+ pstoreu(res+i+ResPacketSize*0, pmadd(c0,palpha,ploadu<ResPacket>(res+i+ResPacketSize*0)));
+ i+=ResPacketSize;
+ }
+ if(HasHalf && i<n_half)
+ {
+ ResPacketHalf c0 = pset1<ResPacketHalf>(ResScalar(0));
+ for(Index j=j2; j<jend; j+=1)
+ {
+ RhsPacketHalf b0 = pset1<RhsPacketHalf>(rhs(j,0));
+ c0 = pcj_half.pmadd(lhs.template load<LhsPacketHalf,LhsAlignment>(i+0,j),b0,c0);
+ }
+ pstoreu(res+i+ResPacketSizeHalf*0, pmadd(c0,palpha_half,ploadu<ResPacketHalf>(res+i+ResPacketSizeHalf*0)));
+ i+=ResPacketSizeHalf;
+ }
+ if(HasQuarter && i<n_quarter)
+ {
+ ResPacketQuarter c0 = pset1<ResPacketQuarter>(ResScalar(0));
+ for(Index j=j2; j<jend; j+=1)
+ {
+ RhsPacketQuarter b0 = pset1<RhsPacketQuarter>(rhs(j,0));
+ c0 = pcj_quarter.pmadd(lhs.template load<LhsPacketQuarter,LhsAlignment>(i+0,j),b0,c0);
+ }
+ pstoreu(res+i+ResPacketSizeQuarter*0, pmadd(c0,palpha_quarter,ploadu<ResPacketQuarter>(res+i+ResPacketSizeQuarter*0)));
+ i+=ResPacketSizeQuarter;
+ }
+ for(;i<rows;++i)
+ {
+ ResScalar c0(0);
+ for(Index j=j2; j<jend; j+=1)
+ c0 += cj.pmul(lhs(i,j), rhs(j,0));
+ res[i] += alpha*c0;
+ }
+ }
+}
+
+/* Optimized row-major matrix * vector product:
+ * This algorithm processes 4 rows at once that allows to both reduce
+ * the number of load/stores of the result by a factor 4 and to reduce
+ * the instruction dependency. Moreover, we know that all bands have the
+ * same alignment pattern.
+ *
+ * Mixing type logic:
+ * - alpha is always a complex (or converted to a complex)
+ * - no vectorization
+ */
+template<typename Index, typename LhsScalar, typename LhsMapper, bool ConjugateLhs, typename RhsScalar, typename RhsMapper, bool ConjugateRhs, int Version>
+struct general_matrix_vector_product<Index,LhsScalar,LhsMapper,RowMajor,ConjugateLhs,RhsScalar,RhsMapper,ConjugateRhs,Version>
+{
+ typedef gemv_traits<LhsScalar,RhsScalar> Traits;
+ typedef gemv_traits<LhsScalar,RhsScalar,GEMVPacketHalf> HalfTraits;
+ typedef gemv_traits<LhsScalar,RhsScalar,GEMVPacketQuarter> QuarterTraits;
+
+ typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
+
+ typedef typename Traits::LhsPacket LhsPacket;
+ typedef typename Traits::RhsPacket RhsPacket;
+ typedef typename Traits::ResPacket ResPacket;
+
+ typedef typename HalfTraits::LhsPacket LhsPacketHalf;
+ typedef typename HalfTraits::RhsPacket RhsPacketHalf;
+ typedef typename HalfTraits::ResPacket ResPacketHalf;
+
+ typedef typename QuarterTraits::LhsPacket LhsPacketQuarter;
+ typedef typename QuarterTraits::RhsPacket RhsPacketQuarter;
+ typedef typename QuarterTraits::ResPacket ResPacketQuarter;
+
+EIGEN_DEVICE_FUNC EIGEN_DONT_INLINE static void run(
+ Index rows, Index cols,
+ const LhsMapper& lhs,
+ const RhsMapper& rhs,
+ ResScalar* res, Index resIncr,
+ ResScalar alpha);
+};
+
+template<typename Index, typename LhsScalar, typename LhsMapper, bool ConjugateLhs, typename RhsScalar, typename RhsMapper, bool ConjugateRhs, int Version>
+EIGEN_DEVICE_FUNC EIGEN_DONT_INLINE void general_matrix_vector_product<Index,LhsScalar,LhsMapper,RowMajor,ConjugateLhs,RhsScalar,RhsMapper,ConjugateRhs,Version>::run(
+ Index rows, Index cols,
+ const LhsMapper& alhs,
+ const RhsMapper& rhs,
+ ResScalar* res, Index resIncr,
+ ResScalar alpha)
+{
+ // The following copy tells the compiler that lhs's attributes are not modified outside this function
+ // This helps GCC to generate propoer code.
+ LhsMapper lhs(alhs);
+
+ eigen_internal_assert(rhs.stride()==1);
+ conj_helper<LhsScalar,RhsScalar,ConjugateLhs,ConjugateRhs> cj;
+ conj_helper<LhsPacket,RhsPacket,ConjugateLhs,ConjugateRhs> pcj;
+ conj_helper<LhsPacketHalf,RhsPacketHalf,ConjugateLhs,ConjugateRhs> pcj_half;
+ conj_helper<LhsPacketQuarter,RhsPacketQuarter,ConjugateLhs,ConjugateRhs> pcj_quarter;
+
+ // TODO: fine tune the following heuristic. The rationale is that if the matrix is very large,
+ // processing 8 rows at once might be counter productive wrt cache.
+ const Index n8 = lhs.stride()*sizeof(LhsScalar)>32000 ? 0 : rows-7;
+ const Index n4 = rows-3;
+ const Index n2 = rows-1;
+
+ // TODO: for padded aligned inputs, we could enable aligned reads
+ enum { LhsAlignment = Unaligned,
+ ResPacketSize = Traits::ResPacketSize,
+ ResPacketSizeHalf = HalfTraits::ResPacketSize,
+ ResPacketSizeQuarter = QuarterTraits::ResPacketSize,
+ LhsPacketSize = Traits::LhsPacketSize,
+ LhsPacketSizeHalf = HalfTraits::LhsPacketSize,
+ LhsPacketSizeQuarter = QuarterTraits::LhsPacketSize,
+ HasHalf = (int)ResPacketSizeHalf < (int)ResPacketSize,
+ HasQuarter = (int)ResPacketSizeQuarter < (int)ResPacketSizeHalf
+ };
+
+ Index i=0;
+ for(; i<n8; i+=8)
+ {
+ ResPacket c0 = pset1<ResPacket>(ResScalar(0)),
+ c1 = pset1<ResPacket>(ResScalar(0)),
+ c2 = pset1<ResPacket>(ResScalar(0)),
+ c3 = pset1<ResPacket>(ResScalar(0)),
+ c4 = pset1<ResPacket>(ResScalar(0)),
+ c5 = pset1<ResPacket>(ResScalar(0)),
+ c6 = pset1<ResPacket>(ResScalar(0)),
+ c7 = pset1<ResPacket>(ResScalar(0));
+
+ Index j=0;
+ for(; j+LhsPacketSize<=cols; j+=LhsPacketSize)
+ {
+ RhsPacket b0 = rhs.template load<RhsPacket, Unaligned>(j,0);
+
+ c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+0,j),b0,c0);
+ c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+1,j),b0,c1);
+ c2 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+2,j),b0,c2);
+ c3 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+3,j),b0,c3);
+ c4 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+4,j),b0,c4);
+ c5 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+5,j),b0,c5);
+ c6 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+6,j),b0,c6);
+ c7 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+7,j),b0,c7);
+ }
+ ResScalar cc0 = predux(c0);
+ ResScalar cc1 = predux(c1);
+ ResScalar cc2 = predux(c2);
+ ResScalar cc3 = predux(c3);
+ ResScalar cc4 = predux(c4);
+ ResScalar cc5 = predux(c5);
+ ResScalar cc6 = predux(c6);
+ ResScalar cc7 = predux(c7);
+ for(; j<cols; ++j)
+ {
+ RhsScalar b0 = rhs(j,0);
+
+ cc0 += cj.pmul(lhs(i+0,j), b0);
+ cc1 += cj.pmul(lhs(i+1,j), b0);
+ cc2 += cj.pmul(lhs(i+2,j), b0);
+ cc3 += cj.pmul(lhs(i+3,j), b0);
+ cc4 += cj.pmul(lhs(i+4,j), b0);
+ cc5 += cj.pmul(lhs(i+5,j), b0);
+ cc6 += cj.pmul(lhs(i+6,j), b0);
+ cc7 += cj.pmul(lhs(i+7,j), b0);
+ }
+ res[(i+0)*resIncr] += alpha*cc0;
+ res[(i+1)*resIncr] += alpha*cc1;
+ res[(i+2)*resIncr] += alpha*cc2;
+ res[(i+3)*resIncr] += alpha*cc3;
+ res[(i+4)*resIncr] += alpha*cc4;
+ res[(i+5)*resIncr] += alpha*cc5;
+ res[(i+6)*resIncr] += alpha*cc6;
+ res[(i+7)*resIncr] += alpha*cc7;
+ }
+ for(; i<n4; i+=4)
+ {
+ ResPacket c0 = pset1<ResPacket>(ResScalar(0)),
+ c1 = pset1<ResPacket>(ResScalar(0)),
+ c2 = pset1<ResPacket>(ResScalar(0)),
+ c3 = pset1<ResPacket>(ResScalar(0));
+
+ Index j=0;
+ for(; j+LhsPacketSize<=cols; j+=LhsPacketSize)
+ {
+ RhsPacket b0 = rhs.template load<RhsPacket, Unaligned>(j,0);
+
+ c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+0,j),b0,c0);
+ c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+1,j),b0,c1);
+ c2 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+2,j),b0,c2);
+ c3 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+3,j),b0,c3);
+ }
+ ResScalar cc0 = predux(c0);
+ ResScalar cc1 = predux(c1);
+ ResScalar cc2 = predux(c2);
+ ResScalar cc3 = predux(c3);
+ for(; j<cols; ++j)
+ {
+ RhsScalar b0 = rhs(j,0);
+
+ cc0 += cj.pmul(lhs(i+0,j), b0);
+ cc1 += cj.pmul(lhs(i+1,j), b0);
+ cc2 += cj.pmul(lhs(i+2,j), b0);
+ cc3 += cj.pmul(lhs(i+3,j), b0);
+ }
+ res[(i+0)*resIncr] += alpha*cc0;
+ res[(i+1)*resIncr] += alpha*cc1;
+ res[(i+2)*resIncr] += alpha*cc2;
+ res[(i+3)*resIncr] += alpha*cc3;
+ }
+ for(; i<n2; i+=2)
+ {
+ ResPacket c0 = pset1<ResPacket>(ResScalar(0)),
+ c1 = pset1<ResPacket>(ResScalar(0));
+
+ Index j=0;
+ for(; j+LhsPacketSize<=cols; j+=LhsPacketSize)
+ {
+ RhsPacket b0 = rhs.template load<RhsPacket, Unaligned>(j,0);
+
+ c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+0,j),b0,c0);
+ c1 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i+1,j),b0,c1);
+ }
+ ResScalar cc0 = predux(c0);
+ ResScalar cc1 = predux(c1);
+ for(; j<cols; ++j)
+ {
+ RhsScalar b0 = rhs(j,0);
+
+ cc0 += cj.pmul(lhs(i+0,j), b0);
+ cc1 += cj.pmul(lhs(i+1,j), b0);
+ }
+ res[(i+0)*resIncr] += alpha*cc0;
+ res[(i+1)*resIncr] += alpha*cc1;
+ }
+ for(; i<rows; ++i)
+ {
+ ResPacket c0 = pset1<ResPacket>(ResScalar(0));
+ ResPacketHalf c0_h = pset1<ResPacketHalf>(ResScalar(0));
+ ResPacketQuarter c0_q = pset1<ResPacketQuarter>(ResScalar(0));
+ Index j=0;
+ for(; j+LhsPacketSize<=cols; j+=LhsPacketSize)
+ {
+ RhsPacket b0 = rhs.template load<RhsPacket,Unaligned>(j,0);
+ c0 = pcj.pmadd(lhs.template load<LhsPacket,LhsAlignment>(i,j),b0,c0);
+ }
+ ResScalar cc0 = predux(c0);
+ if (HasHalf) {
+ for(; j+LhsPacketSizeHalf<=cols; j+=LhsPacketSizeHalf)
+ {
+ RhsPacketHalf b0 = rhs.template load<RhsPacketHalf,Unaligned>(j,0);
+ c0_h = pcj_half.pmadd(lhs.template load<LhsPacketHalf,LhsAlignment>(i,j),b0,c0_h);
+ }
+ cc0 += predux(c0_h);
+ }
+ if (HasQuarter) {
+ for(; j+LhsPacketSizeQuarter<=cols; j+=LhsPacketSizeQuarter)
+ {
+ RhsPacketQuarter b0 = rhs.template load<RhsPacketQuarter,Unaligned>(j,0);
+ c0_q = pcj_quarter.pmadd(lhs.template load<LhsPacketQuarter,LhsAlignment>(i,j),b0,c0_q);
+ }
+ cc0 += predux(c0_q);
+ }
+ for(; j<cols; ++j)
+ {
+ cc0 += cj.pmul(lhs(i,j), rhs(j,0));
+ }
+ res[i*resIncr] += alpha*cc0;
+ }
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_GENERAL_MATRIX_VECTOR_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h
new file mode 100644
index 000000000..6e36c2b3c
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h
@@ -0,0 +1,136 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to BLAS F77
+ * General matrix-vector product functionality based on ?GEMV.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_GENERAL_MATRIX_VECTOR_BLAS_H
+#define EIGEN_GENERAL_MATRIX_VECTOR_BLAS_H
+
+namespace Eigen {
+
+namespace internal {
+
+/**********************************************************************
+* This file implements general matrix-vector multiplication using BLAS
+* gemv function via partial specialization of
+* general_matrix_vector_product::run(..) method for float, double,
+* std::complex<float> and std::complex<double> types
+**********************************************************************/
+
+// gemv specialization
+
+template<typename Index, typename LhsScalar, int StorageOrder, bool ConjugateLhs, typename RhsScalar, bool ConjugateRhs>
+struct general_matrix_vector_product_gemv;
+
+#define EIGEN_BLAS_GEMV_SPECIALIZE(Scalar) \
+template<typename Index, bool ConjugateLhs, bool ConjugateRhs> \
+struct general_matrix_vector_product<Index,Scalar,const_blas_data_mapper<Scalar,Index,ColMajor>,ColMajor,ConjugateLhs,Scalar,const_blas_data_mapper<Scalar,Index,RowMajor>,ConjugateRhs,Specialized> { \
+static void run( \
+ Index rows, Index cols, \
+ const const_blas_data_mapper<Scalar,Index,ColMajor> &lhs, \
+ const const_blas_data_mapper<Scalar,Index,RowMajor> &rhs, \
+ Scalar* res, Index resIncr, Scalar alpha) \
+{ \
+ if (ConjugateLhs) { \
+ general_matrix_vector_product<Index,Scalar,const_blas_data_mapper<Scalar,Index,ColMajor>,ColMajor,ConjugateLhs,Scalar,const_blas_data_mapper<Scalar,Index,RowMajor>,ConjugateRhs,BuiltIn>::run( \
+ rows, cols, lhs, rhs, res, resIncr, alpha); \
+ } else { \
+ general_matrix_vector_product_gemv<Index,Scalar,ColMajor,ConjugateLhs,Scalar,ConjugateRhs>::run( \
+ rows, cols, lhs.data(), lhs.stride(), rhs.data(), rhs.stride(), res, resIncr, alpha); \
+ } \
+} \
+}; \
+template<typename Index, bool ConjugateLhs, bool ConjugateRhs> \
+struct general_matrix_vector_product<Index,Scalar,const_blas_data_mapper<Scalar,Index,RowMajor>,RowMajor,ConjugateLhs,Scalar,const_blas_data_mapper<Scalar,Index,ColMajor>,ConjugateRhs,Specialized> { \
+static void run( \
+ Index rows, Index cols, \
+ const const_blas_data_mapper<Scalar,Index,RowMajor> &lhs, \
+ const const_blas_data_mapper<Scalar,Index,ColMajor> &rhs, \
+ Scalar* res, Index resIncr, Scalar alpha) \
+{ \
+ general_matrix_vector_product_gemv<Index,Scalar,RowMajor,ConjugateLhs,Scalar,ConjugateRhs>::run( \
+ rows, cols, lhs.data(), lhs.stride(), rhs.data(), rhs.stride(), res, resIncr, alpha); \
+} \
+}; \
+
+EIGEN_BLAS_GEMV_SPECIALIZE(double)
+EIGEN_BLAS_GEMV_SPECIALIZE(float)
+EIGEN_BLAS_GEMV_SPECIALIZE(dcomplex)
+EIGEN_BLAS_GEMV_SPECIALIZE(scomplex)
+
+#define EIGEN_BLAS_GEMV_SPECIALIZATION(EIGTYPE,BLASTYPE,BLASFUNC) \
+template<typename Index, int LhsStorageOrder, bool ConjugateLhs, bool ConjugateRhs> \
+struct general_matrix_vector_product_gemv<Index,EIGTYPE,LhsStorageOrder,ConjugateLhs,EIGTYPE,ConjugateRhs> \
+{ \
+typedef Matrix<EIGTYPE,Dynamic,1,ColMajor> GEMVVector;\
+\
+static void run( \
+ Index rows, Index cols, \
+ const EIGTYPE* lhs, Index lhsStride, \
+ const EIGTYPE* rhs, Index rhsIncr, \
+ EIGTYPE* res, Index resIncr, EIGTYPE alpha) \
+{ \
+ BlasIndex m=convert_index<BlasIndex>(rows), n=convert_index<BlasIndex>(cols), \
+ lda=convert_index<BlasIndex>(lhsStride), incx=convert_index<BlasIndex>(rhsIncr), incy=convert_index<BlasIndex>(resIncr); \
+ const EIGTYPE beta(1); \
+ const EIGTYPE *x_ptr; \
+ char trans=(LhsStorageOrder==ColMajor) ? 'N' : (ConjugateLhs) ? 'C' : 'T'; \
+ if (LhsStorageOrder==RowMajor) { \
+ m = convert_index<BlasIndex>(cols); \
+ n = convert_index<BlasIndex>(rows); \
+ }\
+ GEMVVector x_tmp; \
+ if (ConjugateRhs) { \
+ Map<const GEMVVector, 0, InnerStride<> > map_x(rhs,cols,1,InnerStride<>(incx)); \
+ x_tmp=map_x.conjugate(); \
+ x_ptr=x_tmp.data(); \
+ incx=1; \
+ } else x_ptr=rhs; \
+ BLASFUNC(&trans, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)lhs, &lda, (const BLASTYPE*)x_ptr, &incx, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &incy); \
+}\
+};
+
+#ifdef EIGEN_USE_MKL
+EIGEN_BLAS_GEMV_SPECIALIZATION(double, double, dgemv)
+EIGEN_BLAS_GEMV_SPECIALIZATION(float, float, sgemv)
+EIGEN_BLAS_GEMV_SPECIALIZATION(dcomplex, MKL_Complex16, zgemv)
+EIGEN_BLAS_GEMV_SPECIALIZATION(scomplex, MKL_Complex8 , cgemv)
+#else
+EIGEN_BLAS_GEMV_SPECIALIZATION(double, double, dgemv_)
+EIGEN_BLAS_GEMV_SPECIALIZATION(float, float, sgemv_)
+EIGEN_BLAS_GEMV_SPECIALIZATION(dcomplex, double, zgemv_)
+EIGEN_BLAS_GEMV_SPECIALIZATION(scomplex, float, cgemv_)
+#endif
+
+} // end namespase internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_GENERAL_MATRIX_VECTOR_BLAS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/Parallelizer.h b/src/3rdparty/eigen/Eigen/src/Core/products/Parallelizer.h
new file mode 100644
index 000000000..8f91879e4
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/Parallelizer.h
@@ -0,0 +1,180 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PARALLELIZER_H
+#define EIGEN_PARALLELIZER_H
+
+#if EIGEN_HAS_CXX11_ATOMIC
+#include <atomic>
+#endif
+
+namespace Eigen {
+
+namespace internal {
+
+/** \internal */
+inline void manage_multi_threading(Action action, int* v)
+{
+ static int m_maxThreads = -1;
+ EIGEN_UNUSED_VARIABLE(m_maxThreads)
+
+ if(action==SetAction)
+ {
+ eigen_internal_assert(v!=0);
+ m_maxThreads = *v;
+ }
+ else if(action==GetAction)
+ {
+ eigen_internal_assert(v!=0);
+ #ifdef EIGEN_HAS_OPENMP
+ if(m_maxThreads>0)
+ *v = m_maxThreads;
+ else
+ *v = omp_get_max_threads();
+ #else
+ *v = 1;
+ #endif
+ }
+ else
+ {
+ eigen_internal_assert(false);
+ }
+}
+
+}
+
+/** Must be call first when calling Eigen from multiple threads */
+inline void initParallel()
+{
+ int nbt;
+ internal::manage_multi_threading(GetAction, &nbt);
+ std::ptrdiff_t l1, l2, l3;
+ internal::manage_caching_sizes(GetAction, &l1, &l2, &l3);
+}
+
+/** \returns the max number of threads reserved for Eigen
+ * \sa setNbThreads */
+inline int nbThreads()
+{
+ int ret;
+ internal::manage_multi_threading(GetAction, &ret);
+ return ret;
+}
+
+/** Sets the max number of threads reserved for Eigen
+ * \sa nbThreads */
+inline void setNbThreads(int v)
+{
+ internal::manage_multi_threading(SetAction, &v);
+}
+
+namespace internal {
+
+template<typename Index> struct GemmParallelInfo
+{
+ GemmParallelInfo() : sync(-1), users(0), lhs_start(0), lhs_length(0) {}
+
+ // volatile is not enough on all architectures (see bug 1572)
+ // to guarantee that when thread A says to thread B that it is
+ // done with packing a block, then all writes have been really
+ // carried out... C++11 memory model+atomic guarantees this.
+#if EIGEN_HAS_CXX11_ATOMIC
+ std::atomic<Index> sync;
+ std::atomic<int> users;
+#else
+ Index volatile sync;
+ int volatile users;
+#endif
+
+ Index lhs_start;
+ Index lhs_length;
+};
+
+template<bool Condition, typename Functor, typename Index>
+void parallelize_gemm(const Functor& func, Index rows, Index cols, Index depth, bool transpose)
+{
+ // TODO when EIGEN_USE_BLAS is defined,
+ // we should still enable OMP for other scalar types
+ // Without C++11, we have to disable GEMM's parallelization on
+ // non x86 architectures because there volatile is not enough for our purpose.
+ // See bug 1572.
+#if (! defined(EIGEN_HAS_OPENMP)) || defined(EIGEN_USE_BLAS) || ((!EIGEN_HAS_CXX11_ATOMIC) && !(EIGEN_ARCH_i386_OR_x86_64))
+ // FIXME the transpose variable is only needed to properly split
+ // the matrix product when multithreading is enabled. This is a temporary
+ // fix to support row-major destination matrices. This whole
+ // parallelizer mechanism has to be redesigned anyway.
+ EIGEN_UNUSED_VARIABLE(depth);
+ EIGEN_UNUSED_VARIABLE(transpose);
+ func(0,rows, 0,cols);
+#else
+
+ // Dynamically check whether we should enable or disable OpenMP.
+ // The conditions are:
+ // - the max number of threads we can create is greater than 1
+ // - we are not already in a parallel code
+ // - the sizes are large enough
+
+ // compute the maximal number of threads from the size of the product:
+ // This first heuristic takes into account that the product kernel is fully optimized when working with nr columns at once.
+ Index size = transpose ? rows : cols;
+ Index pb_max_threads = std::max<Index>(1,size / Functor::Traits::nr);
+
+ // compute the maximal number of threads from the total amount of work:
+ double work = static_cast<double>(rows) * static_cast<double>(cols) *
+ static_cast<double>(depth);
+ double kMinTaskSize = 50000; // FIXME improve this heuristic.
+ pb_max_threads = std::max<Index>(1, std::min<Index>(pb_max_threads, static_cast<Index>( work / kMinTaskSize ) ));
+
+ // compute the number of threads we are going to use
+ Index threads = std::min<Index>(nbThreads(), pb_max_threads);
+
+ // if multi-threading is explicitly disabled, not useful, or if we already are in a parallel session,
+ // then abort multi-threading
+ // FIXME omp_get_num_threads()>1 only works for openmp, what if the user does not use openmp?
+ if((!Condition) || (threads==1) || (omp_get_num_threads()>1))
+ return func(0,rows, 0,cols);
+
+ Eigen::initParallel();
+ func.initParallelSession(threads);
+
+ if(transpose)
+ std::swap(rows,cols);
+
+ ei_declare_aligned_stack_constructed_variable(GemmParallelInfo<Index>,info,threads,0);
+
+ #pragma omp parallel num_threads(threads)
+ {
+ Index i = omp_get_thread_num();
+ // Note that the actual number of threads might be lower than the number of request ones.
+ Index actual_threads = omp_get_num_threads();
+
+ Index blockCols = (cols / actual_threads) & ~Index(0x3);
+ Index blockRows = (rows / actual_threads);
+ blockRows = (blockRows/Functor::Traits::mr)*Functor::Traits::mr;
+
+ Index r0 = i*blockRows;
+ Index actualBlockRows = (i+1==actual_threads) ? rows-r0 : blockRows;
+
+ Index c0 = i*blockCols;
+ Index actualBlockCols = (i+1==actual_threads) ? cols-c0 : blockCols;
+
+ info[i].lhs_start = r0;
+ info[i].lhs_length = actualBlockRows;
+
+ if(transpose) func(c0, actualBlockCols, 0, rows, info);
+ else func(0, rows, c0, actualBlockCols, info);
+ }
+#endif
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PARALLELIZER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h
new file mode 100644
index 000000000..33ecf10f6
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h
@@ -0,0 +1,544 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SELFADJOINT_MATRIX_MATRIX_H
+#define EIGEN_SELFADJOINT_MATRIX_MATRIX_H
+
+namespace Eigen {
+
+namespace internal {
+
+// pack a selfadjoint block diagonal for use with the gebp_kernel
+template<typename Scalar, typename Index, int Pack1, int Pack2_dummy, int StorageOrder>
+struct symm_pack_lhs
+{
+ template<int BlockRows> inline
+ void pack(Scalar* blockA, const const_blas_data_mapper<Scalar,Index,StorageOrder>& lhs, Index cols, Index i, Index& count)
+ {
+ // normal copy
+ for(Index k=0; k<i; k++)
+ for(Index w=0; w<BlockRows; w++)
+ blockA[count++] = lhs(i+w,k); // normal
+ // symmetric copy
+ Index h = 0;
+ for(Index k=i; k<i+BlockRows; k++)
+ {
+ for(Index w=0; w<h; w++)
+ blockA[count++] = numext::conj(lhs(k, i+w)); // transposed
+
+ blockA[count++] = numext::real(lhs(k,k)); // real (diagonal)
+
+ for(Index w=h+1; w<BlockRows; w++)
+ blockA[count++] = lhs(i+w, k); // normal
+ ++h;
+ }
+ // transposed copy
+ for(Index k=i+BlockRows; k<cols; k++)
+ for(Index w=0; w<BlockRows; w++)
+ blockA[count++] = numext::conj(lhs(k, i+w)); // transposed
+ }
+ void operator()(Scalar* blockA, const Scalar* _lhs, Index lhsStride, Index cols, Index rows)
+ {
+ typedef typename unpacket_traits<typename packet_traits<Scalar>::type>::half HalfPacket;
+ typedef typename unpacket_traits<typename unpacket_traits<typename packet_traits<Scalar>::type>::half>::half QuarterPacket;
+ enum { PacketSize = packet_traits<Scalar>::size,
+ HalfPacketSize = unpacket_traits<HalfPacket>::size,
+ QuarterPacketSize = unpacket_traits<QuarterPacket>::size,
+ HasHalf = (int)HalfPacketSize < (int)PacketSize,
+ HasQuarter = (int)QuarterPacketSize < (int)HalfPacketSize};
+
+ const_blas_data_mapper<Scalar,Index,StorageOrder> lhs(_lhs,lhsStride);
+ Index count = 0;
+ //Index peeled_mc3 = (rows/Pack1)*Pack1;
+
+ const Index peeled_mc3 = Pack1>=3*PacketSize ? (rows/(3*PacketSize))*(3*PacketSize) : 0;
+ const Index peeled_mc2 = Pack1>=2*PacketSize ? peeled_mc3+((rows-peeled_mc3)/(2*PacketSize))*(2*PacketSize) : 0;
+ const Index peeled_mc1 = Pack1>=1*PacketSize ? peeled_mc2+((rows-peeled_mc2)/(1*PacketSize))*(1*PacketSize) : 0;
+ const Index peeled_mc_half = Pack1>=HalfPacketSize ? peeled_mc1+((rows-peeled_mc1)/(HalfPacketSize))*(HalfPacketSize) : 0;
+ const Index peeled_mc_quarter = Pack1>=QuarterPacketSize ? peeled_mc_half+((rows-peeled_mc_half)/(QuarterPacketSize))*(QuarterPacketSize) : 0;
+
+ if(Pack1>=3*PacketSize)
+ for(Index i=0; i<peeled_mc3; i+=3*PacketSize)
+ pack<3*PacketSize>(blockA, lhs, cols, i, count);
+
+ if(Pack1>=2*PacketSize)
+ for(Index i=peeled_mc3; i<peeled_mc2; i+=2*PacketSize)
+ pack<2*PacketSize>(blockA, lhs, cols, i, count);
+
+ if(Pack1>=1*PacketSize)
+ for(Index i=peeled_mc2; i<peeled_mc1; i+=1*PacketSize)
+ pack<1*PacketSize>(blockA, lhs, cols, i, count);
+
+ if(HasHalf && Pack1>=HalfPacketSize)
+ for(Index i=peeled_mc1; i<peeled_mc_half; i+=HalfPacketSize)
+ pack<HalfPacketSize>(blockA, lhs, cols, i, count);
+
+ if(HasQuarter && Pack1>=QuarterPacketSize)
+ for(Index i=peeled_mc_half; i<peeled_mc_quarter; i+=QuarterPacketSize)
+ pack<QuarterPacketSize>(blockA, lhs, cols, i, count);
+
+ // do the same with mr==1
+ for(Index i=peeled_mc_quarter; i<rows; i++)
+ {
+ for(Index k=0; k<i; k++)
+ blockA[count++] = lhs(i, k); // normal
+
+ blockA[count++] = numext::real(lhs(i, i)); // real (diagonal)
+
+ for(Index k=i+1; k<cols; k++)
+ blockA[count++] = numext::conj(lhs(k, i)); // transposed
+ }
+ }
+};
+
+template<typename Scalar, typename Index, int nr, int StorageOrder>
+struct symm_pack_rhs
+{
+ enum { PacketSize = packet_traits<Scalar>::size };
+ void operator()(Scalar* blockB, const Scalar* _rhs, Index rhsStride, Index rows, Index cols, Index k2)
+ {
+ Index end_k = k2 + rows;
+ Index count = 0;
+ const_blas_data_mapper<Scalar,Index,StorageOrder> rhs(_rhs,rhsStride);
+ Index packet_cols8 = nr>=8 ? (cols/8) * 8 : 0;
+ Index packet_cols4 = nr>=4 ? (cols/4) * 4 : 0;
+
+ // first part: normal case
+ for(Index j2=0; j2<k2; j2+=nr)
+ {
+ for(Index k=k2; k<end_k; k++)
+ {
+ blockB[count+0] = rhs(k,j2+0);
+ blockB[count+1] = rhs(k,j2+1);
+ if (nr>=4)
+ {
+ blockB[count+2] = rhs(k,j2+2);
+ blockB[count+3] = rhs(k,j2+3);
+ }
+ if (nr>=8)
+ {
+ blockB[count+4] = rhs(k,j2+4);
+ blockB[count+5] = rhs(k,j2+5);
+ blockB[count+6] = rhs(k,j2+6);
+ blockB[count+7] = rhs(k,j2+7);
+ }
+ count += nr;
+ }
+ }
+
+ // second part: diagonal block
+ Index end8 = nr>=8 ? (std::min)(k2+rows,packet_cols8) : k2;
+ if(nr>=8)
+ {
+ for(Index j2=k2; j2<end8; j2+=8)
+ {
+ // again we can split vertically in three different parts (transpose, symmetric, normal)
+ // transpose
+ for(Index k=k2; k<j2; k++)
+ {
+ blockB[count+0] = numext::conj(rhs(j2+0,k));
+ blockB[count+1] = numext::conj(rhs(j2+1,k));
+ blockB[count+2] = numext::conj(rhs(j2+2,k));
+ blockB[count+3] = numext::conj(rhs(j2+3,k));
+ blockB[count+4] = numext::conj(rhs(j2+4,k));
+ blockB[count+5] = numext::conj(rhs(j2+5,k));
+ blockB[count+6] = numext::conj(rhs(j2+6,k));
+ blockB[count+7] = numext::conj(rhs(j2+7,k));
+ count += 8;
+ }
+ // symmetric
+ Index h = 0;
+ for(Index k=j2; k<j2+8; k++)
+ {
+ // normal
+ for (Index w=0 ; w<h; ++w)
+ blockB[count+w] = rhs(k,j2+w);
+
+ blockB[count+h] = numext::real(rhs(k,k));
+
+ // transpose
+ for (Index w=h+1 ; w<8; ++w)
+ blockB[count+w] = numext::conj(rhs(j2+w,k));
+ count += 8;
+ ++h;
+ }
+ // normal
+ for(Index k=j2+8; k<end_k; k++)
+ {
+ blockB[count+0] = rhs(k,j2+0);
+ blockB[count+1] = rhs(k,j2+1);
+ blockB[count+2] = rhs(k,j2+2);
+ blockB[count+3] = rhs(k,j2+3);
+ blockB[count+4] = rhs(k,j2+4);
+ blockB[count+5] = rhs(k,j2+5);
+ blockB[count+6] = rhs(k,j2+6);
+ blockB[count+7] = rhs(k,j2+7);
+ count += 8;
+ }
+ }
+ }
+ if(nr>=4)
+ {
+ for(Index j2=end8; j2<(std::min)(k2+rows,packet_cols4); j2+=4)
+ {
+ // again we can split vertically in three different parts (transpose, symmetric, normal)
+ // transpose
+ for(Index k=k2; k<j2; k++)
+ {
+ blockB[count+0] = numext::conj(rhs(j2+0,k));
+ blockB[count+1] = numext::conj(rhs(j2+1,k));
+ blockB[count+2] = numext::conj(rhs(j2+2,k));
+ blockB[count+3] = numext::conj(rhs(j2+3,k));
+ count += 4;
+ }
+ // symmetric
+ Index h = 0;
+ for(Index k=j2; k<j2+4; k++)
+ {
+ // normal
+ for (Index w=0 ; w<h; ++w)
+ blockB[count+w] = rhs(k,j2+w);
+
+ blockB[count+h] = numext::real(rhs(k,k));
+
+ // transpose
+ for (Index w=h+1 ; w<4; ++w)
+ blockB[count+w] = numext::conj(rhs(j2+w,k));
+ count += 4;
+ ++h;
+ }
+ // normal
+ for(Index k=j2+4; k<end_k; k++)
+ {
+ blockB[count+0] = rhs(k,j2+0);
+ blockB[count+1] = rhs(k,j2+1);
+ blockB[count+2] = rhs(k,j2+2);
+ blockB[count+3] = rhs(k,j2+3);
+ count += 4;
+ }
+ }
+ }
+
+ // third part: transposed
+ if(nr>=8)
+ {
+ for(Index j2=k2+rows; j2<packet_cols8; j2+=8)
+ {
+ for(Index k=k2; k<end_k; k++)
+ {
+ blockB[count+0] = numext::conj(rhs(j2+0,k));
+ blockB[count+1] = numext::conj(rhs(j2+1,k));
+ blockB[count+2] = numext::conj(rhs(j2+2,k));
+ blockB[count+3] = numext::conj(rhs(j2+3,k));
+ blockB[count+4] = numext::conj(rhs(j2+4,k));
+ blockB[count+5] = numext::conj(rhs(j2+5,k));
+ blockB[count+6] = numext::conj(rhs(j2+6,k));
+ blockB[count+7] = numext::conj(rhs(j2+7,k));
+ count += 8;
+ }
+ }
+ }
+ if(nr>=4)
+ {
+ for(Index j2=(std::max)(packet_cols8,k2+rows); j2<packet_cols4; j2+=4)
+ {
+ for(Index k=k2; k<end_k; k++)
+ {
+ blockB[count+0] = numext::conj(rhs(j2+0,k));
+ blockB[count+1] = numext::conj(rhs(j2+1,k));
+ blockB[count+2] = numext::conj(rhs(j2+2,k));
+ blockB[count+3] = numext::conj(rhs(j2+3,k));
+ count += 4;
+ }
+ }
+ }
+
+ // copy the remaining columns one at a time (=> the same with nr==1)
+ for(Index j2=packet_cols4; j2<cols; ++j2)
+ {
+ // transpose
+ Index half = (std::min)(end_k,j2);
+ for(Index k=k2; k<half; k++)
+ {
+ blockB[count] = numext::conj(rhs(j2,k));
+ count += 1;
+ }
+
+ if(half==j2 && half<k2+rows)
+ {
+ blockB[count] = numext::real(rhs(j2,j2));
+ count += 1;
+ }
+ else
+ half--;
+
+ // normal
+ for(Index k=half+1; k<k2+rows; k++)
+ {
+ blockB[count] = rhs(k,j2);
+ count += 1;
+ }
+ }
+ }
+};
+
+/* Optimized selfadjoint matrix * matrix (_SYMM) product built on top of
+ * the general matrix matrix product.
+ */
+template <typename Scalar, typename Index,
+ int LhsStorageOrder, bool LhsSelfAdjoint, bool ConjugateLhs,
+ int RhsStorageOrder, bool RhsSelfAdjoint, bool ConjugateRhs,
+ int ResStorageOrder, int ResInnerStride>
+struct product_selfadjoint_matrix;
+
+template <typename Scalar, typename Index,
+ int LhsStorageOrder, bool LhsSelfAdjoint, bool ConjugateLhs,
+ int RhsStorageOrder, bool RhsSelfAdjoint, bool ConjugateRhs,
+ int ResInnerStride>
+struct product_selfadjoint_matrix<Scalar,Index,LhsStorageOrder,LhsSelfAdjoint,ConjugateLhs, RhsStorageOrder,RhsSelfAdjoint,ConjugateRhs,RowMajor,ResInnerStride>
+{
+
+ static EIGEN_STRONG_INLINE void run(
+ Index rows, Index cols,
+ const Scalar* lhs, Index lhsStride,
+ const Scalar* rhs, Index rhsStride,
+ Scalar* res, Index resIncr, Index resStride,
+ const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
+ {
+ product_selfadjoint_matrix<Scalar, Index,
+ EIGEN_LOGICAL_XOR(RhsSelfAdjoint,RhsStorageOrder==RowMajor) ? ColMajor : RowMajor,
+ RhsSelfAdjoint, NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(RhsSelfAdjoint,ConjugateRhs),
+ EIGEN_LOGICAL_XOR(LhsSelfAdjoint,LhsStorageOrder==RowMajor) ? ColMajor : RowMajor,
+ LhsSelfAdjoint, NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(LhsSelfAdjoint,ConjugateLhs),
+ ColMajor,ResInnerStride>
+ ::run(cols, rows, rhs, rhsStride, lhs, lhsStride, res, resIncr, resStride, alpha, blocking);
+ }
+};
+
+template <typename Scalar, typename Index,
+ int LhsStorageOrder, bool ConjugateLhs,
+ int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride>
+struct product_selfadjoint_matrix<Scalar,Index,LhsStorageOrder,true,ConjugateLhs, RhsStorageOrder,false,ConjugateRhs,ColMajor,ResInnerStride>
+{
+
+ static EIGEN_DONT_INLINE void run(
+ Index rows, Index cols,
+ const Scalar* _lhs, Index lhsStride,
+ const Scalar* _rhs, Index rhsStride,
+ Scalar* res, Index resIncr, Index resStride,
+ const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking);
+};
+
+template <typename Scalar, typename Index,
+ int LhsStorageOrder, bool ConjugateLhs,
+ int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride>
+EIGEN_DONT_INLINE void product_selfadjoint_matrix<Scalar,Index,LhsStorageOrder,true,ConjugateLhs, RhsStorageOrder,false,ConjugateRhs,ColMajor,ResInnerStride>::run(
+ Index rows, Index cols,
+ const Scalar* _lhs, Index lhsStride,
+ const Scalar* _rhs, Index rhsStride,
+ Scalar* _res, Index resIncr, Index resStride,
+ const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
+ {
+ Index size = rows;
+
+ typedef gebp_traits<Scalar,Scalar> Traits;
+
+ typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper;
+ typedef const_blas_data_mapper<Scalar, Index, (LhsStorageOrder == RowMajor) ? ColMajor : RowMajor> LhsTransposeMapper;
+ typedef const_blas_data_mapper<Scalar, Index, RhsStorageOrder> RhsMapper;
+ typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper;
+ LhsMapper lhs(_lhs,lhsStride);
+ LhsTransposeMapper lhs_transpose(_lhs,lhsStride);
+ RhsMapper rhs(_rhs,rhsStride);
+ ResMapper res(_res, resStride, resIncr);
+
+ Index kc = blocking.kc(); // cache block size along the K direction
+ Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction
+ // kc must be smaller than mc
+ kc = (std::min)(kc,mc);
+ std::size_t sizeA = kc*mc;
+ std::size_t sizeB = kc*cols;
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA());
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB());
+
+ gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel;
+ symm_pack_lhs<Scalar, Index, Traits::mr, Traits::LhsProgress, LhsStorageOrder> pack_lhs;
+ gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder> pack_rhs;
+ gemm_pack_lhs<Scalar, Index, LhsTransposeMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder==RowMajor?ColMajor:RowMajor, true> pack_lhs_transposed;
+
+ for(Index k2=0; k2<size; k2+=kc)
+ {
+ const Index actual_kc = (std::min)(k2+kc,size)-k2;
+
+ // we have selected one row panel of rhs and one column panel of lhs
+ // pack rhs's panel into a sequential chunk of memory
+ // and expand each coeff to a constant packet for further reuse
+ pack_rhs(blockB, rhs.getSubMapper(k2,0), actual_kc, cols);
+
+ // the select lhs's panel has to be split in three different parts:
+ // 1 - the transposed panel above the diagonal block => transposed packed copy
+ // 2 - the diagonal block => special packed copy
+ // 3 - the panel below the diagonal block => generic packed copy
+ for(Index i2=0; i2<k2; i2+=mc)
+ {
+ const Index actual_mc = (std::min)(i2+mc,k2)-i2;
+ // transposed packed copy
+ pack_lhs_transposed(blockA, lhs_transpose.getSubMapper(i2, k2), actual_kc, actual_mc);
+
+ gebp_kernel(res.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc, cols, alpha);
+ }
+ // the block diagonal
+ {
+ const Index actual_mc = (std::min)(k2+kc,size)-k2;
+ // symmetric packed copy
+ pack_lhs(blockA, &lhs(k2,k2), lhsStride, actual_kc, actual_mc);
+
+ gebp_kernel(res.getSubMapper(k2, 0), blockA, blockB, actual_mc, actual_kc, cols, alpha);
+ }
+
+ for(Index i2=k2+kc; i2<size; i2+=mc)
+ {
+ const Index actual_mc = (std::min)(i2+mc,size)-i2;
+ gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder,false>()
+ (blockA, lhs.getSubMapper(i2, k2), actual_kc, actual_mc);
+
+ gebp_kernel(res.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc, cols, alpha);
+ }
+ }
+ }
+
+// matrix * selfadjoint product
+template <typename Scalar, typename Index,
+ int LhsStorageOrder, bool ConjugateLhs,
+ int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride>
+struct product_selfadjoint_matrix<Scalar,Index,LhsStorageOrder,false,ConjugateLhs, RhsStorageOrder,true,ConjugateRhs,ColMajor,ResInnerStride>
+{
+
+ static EIGEN_DONT_INLINE void run(
+ Index rows, Index cols,
+ const Scalar* _lhs, Index lhsStride,
+ const Scalar* _rhs, Index rhsStride,
+ Scalar* res, Index resIncr, Index resStride,
+ const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking);
+};
+
+template <typename Scalar, typename Index,
+ int LhsStorageOrder, bool ConjugateLhs,
+ int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride>
+EIGEN_DONT_INLINE void product_selfadjoint_matrix<Scalar,Index,LhsStorageOrder,false,ConjugateLhs, RhsStorageOrder,true,ConjugateRhs,ColMajor,ResInnerStride>::run(
+ Index rows, Index cols,
+ const Scalar* _lhs, Index lhsStride,
+ const Scalar* _rhs, Index rhsStride,
+ Scalar* _res, Index resIncr, Index resStride,
+ const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
+ {
+ Index size = cols;
+
+ typedef gebp_traits<Scalar,Scalar> Traits;
+
+ typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper;
+ typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper;
+ LhsMapper lhs(_lhs,lhsStride);
+ ResMapper res(_res,resStride, resIncr);
+
+ Index kc = blocking.kc(); // cache block size along the K direction
+ Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction
+ std::size_t sizeA = kc*mc;
+ std::size_t sizeB = kc*cols;
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA());
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB());
+
+ gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel;
+ gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs;
+ symm_pack_rhs<Scalar, Index, Traits::nr,RhsStorageOrder> pack_rhs;
+
+ for(Index k2=0; k2<size; k2+=kc)
+ {
+ const Index actual_kc = (std::min)(k2+kc,size)-k2;
+
+ pack_rhs(blockB, _rhs, rhsStride, actual_kc, cols, k2);
+
+ // => GEPP
+ for(Index i2=0; i2<rows; i2+=mc)
+ {
+ const Index actual_mc = (std::min)(i2+mc,rows)-i2;
+ pack_lhs(blockA, lhs.getSubMapper(i2, k2), actual_kc, actual_mc);
+
+ gebp_kernel(res.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc, cols, alpha);
+ }
+ }
+ }
+
+} // end namespace internal
+
+/***************************************************************************
+* Wrapper to product_selfadjoint_matrix
+***************************************************************************/
+
+namespace internal {
+
+template<typename Lhs, int LhsMode, typename Rhs, int RhsMode>
+struct selfadjoint_product_impl<Lhs,LhsMode,false,Rhs,RhsMode,false>
+{
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+
+ typedef internal::blas_traits<Lhs> LhsBlasTraits;
+ typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
+ typedef internal::blas_traits<Rhs> RhsBlasTraits;
+ typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
+
+ enum {
+ LhsIsUpper = (LhsMode&(Upper|Lower))==Upper,
+ LhsIsSelfAdjoint = (LhsMode&SelfAdjoint)==SelfAdjoint,
+ RhsIsUpper = (RhsMode&(Upper|Lower))==Upper,
+ RhsIsSelfAdjoint = (RhsMode&SelfAdjoint)==SelfAdjoint
+ };
+
+ template<typename Dest>
+ static void run(Dest &dst, const Lhs &a_lhs, const Rhs &a_rhs, const Scalar& alpha)
+ {
+ eigen_assert(dst.rows()==a_lhs.rows() && dst.cols()==a_rhs.cols());
+
+ typename internal::add_const_on_value_type<ActualLhsType>::type lhs = LhsBlasTraits::extract(a_lhs);
+ typename internal::add_const_on_value_type<ActualRhsType>::type rhs = RhsBlasTraits::extract(a_rhs);
+
+ Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(a_lhs)
+ * RhsBlasTraits::extractScalarFactor(a_rhs);
+
+ typedef internal::gemm_blocking_space<(Dest::Flags&RowMajorBit) ? RowMajor : ColMajor,Scalar,Scalar,
+ Lhs::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime, Lhs::MaxColsAtCompileTime,1> BlockingType;
+
+ BlockingType blocking(lhs.rows(), rhs.cols(), lhs.cols(), 1, false);
+
+ internal::product_selfadjoint_matrix<Scalar, Index,
+ EIGEN_LOGICAL_XOR(LhsIsUpper,internal::traits<Lhs>::Flags &RowMajorBit) ? RowMajor : ColMajor, LhsIsSelfAdjoint,
+ NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(LhsIsUpper,bool(LhsBlasTraits::NeedToConjugate)),
+ EIGEN_LOGICAL_XOR(RhsIsUpper,internal::traits<Rhs>::Flags &RowMajorBit) ? RowMajor : ColMajor, RhsIsSelfAdjoint,
+ NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(RhsIsUpper,bool(RhsBlasTraits::NeedToConjugate)),
+ internal::traits<Dest>::Flags&RowMajorBit ? RowMajor : ColMajor,
+ Dest::InnerStrideAtCompileTime>
+ ::run(
+ lhs.rows(), rhs.cols(), // sizes
+ &lhs.coeffRef(0,0), lhs.outerStride(), // lhs info
+ &rhs.coeffRef(0,0), rhs.outerStride(), // rhs info
+ &dst.coeffRef(0,0), dst.innerStride(), dst.outerStride(), // result info
+ actualAlpha, blocking // alpha
+ );
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_SELFADJOINT_MATRIX_MATRIX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h
new file mode 100644
index 000000000..61396dbdf
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h
@@ -0,0 +1,295 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+ ********************************************************************************
+ * Content : Eigen bindings to BLAS F77
+ * Self adjoint matrix * matrix product functionality based on ?SYMM/?HEMM.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_SELFADJOINT_MATRIX_MATRIX_BLAS_H
+#define EIGEN_SELFADJOINT_MATRIX_MATRIX_BLAS_H
+
+namespace Eigen {
+
+namespace internal {
+
+
+/* Optimized selfadjoint matrix * matrix (?SYMM/?HEMM) product */
+
+#define EIGEN_BLAS_SYMM_L(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \
+template <typename Index, \
+ int LhsStorageOrder, bool ConjugateLhs, \
+ int RhsStorageOrder, bool ConjugateRhs> \
+struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,true,ConjugateLhs,RhsStorageOrder,false,ConjugateRhs,ColMajor,1> \
+{\
+\
+ static void run( \
+ Index rows, Index cols, \
+ const EIGTYPE* _lhs, Index lhsStride, \
+ const EIGTYPE* _rhs, Index rhsStride, \
+ EIGTYPE* res, Index resIncr, Index resStride, \
+ EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \
+ { \
+ EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \
+ eigen_assert(resIncr == 1); \
+ char side='L', uplo='L'; \
+ BlasIndex m, n, lda, ldb, ldc; \
+ const EIGTYPE *a, *b; \
+ EIGTYPE beta(1); \
+ MatrixX##EIGPREFIX b_tmp; \
+\
+/* Set transpose options */ \
+/* Set m, n, k */ \
+ m = convert_index<BlasIndex>(rows); \
+ n = convert_index<BlasIndex>(cols); \
+\
+/* Set lda, ldb, ldc */ \
+ lda = convert_index<BlasIndex>(lhsStride); \
+ ldb = convert_index<BlasIndex>(rhsStride); \
+ ldc = convert_index<BlasIndex>(resStride); \
+\
+/* Set a, b, c */ \
+ if (LhsStorageOrder==RowMajor) uplo='U'; \
+ a = _lhs; \
+\
+ if (RhsStorageOrder==RowMajor) { \
+ Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,n,m,OuterStride<>(rhsStride)); \
+ b_tmp = rhs.adjoint(); \
+ b = b_tmp.data(); \
+ ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \
+ } else b = _rhs; \
+\
+ BLASFUNC(&side, &uplo, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &ldc); \
+\
+ } \
+};
+
+
+#define EIGEN_BLAS_HEMM_L(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \
+template <typename Index, \
+ int LhsStorageOrder, bool ConjugateLhs, \
+ int RhsStorageOrder, bool ConjugateRhs> \
+struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,true,ConjugateLhs,RhsStorageOrder,false,ConjugateRhs,ColMajor,1> \
+{\
+ static void run( \
+ Index rows, Index cols, \
+ const EIGTYPE* _lhs, Index lhsStride, \
+ const EIGTYPE* _rhs, Index rhsStride, \
+ EIGTYPE* res, Index resIncr, Index resStride, \
+ EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \
+ { \
+ EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \
+ eigen_assert(resIncr == 1); \
+ char side='L', uplo='L'; \
+ BlasIndex m, n, lda, ldb, ldc; \
+ const EIGTYPE *a, *b; \
+ EIGTYPE beta(1); \
+ MatrixX##EIGPREFIX b_tmp; \
+ Matrix<EIGTYPE, Dynamic, Dynamic, LhsStorageOrder> a_tmp; \
+\
+/* Set transpose options */ \
+/* Set m, n, k */ \
+ m = convert_index<BlasIndex>(rows); \
+ n = convert_index<BlasIndex>(cols); \
+\
+/* Set lda, ldb, ldc */ \
+ lda = convert_index<BlasIndex>(lhsStride); \
+ ldb = convert_index<BlasIndex>(rhsStride); \
+ ldc = convert_index<BlasIndex>(resStride); \
+\
+/* Set a, b, c */ \
+ if (((LhsStorageOrder==ColMajor) && ConjugateLhs) || ((LhsStorageOrder==RowMajor) && (!ConjugateLhs))) { \
+ Map<const Matrix<EIGTYPE, Dynamic, Dynamic, LhsStorageOrder>, 0, OuterStride<> > lhs(_lhs,m,m,OuterStride<>(lhsStride)); \
+ a_tmp = lhs.conjugate(); \
+ a = a_tmp.data(); \
+ lda = convert_index<BlasIndex>(a_tmp.outerStride()); \
+ } else a = _lhs; \
+ if (LhsStorageOrder==RowMajor) uplo='U'; \
+\
+ if (RhsStorageOrder==ColMajor && (!ConjugateRhs)) { \
+ b = _rhs; } \
+ else { \
+ if (RhsStorageOrder==ColMajor && ConjugateRhs) { \
+ Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,m,n,OuterStride<>(rhsStride)); \
+ b_tmp = rhs.conjugate(); \
+ } else \
+ if (ConjugateRhs) { \
+ Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,n,m,OuterStride<>(rhsStride)); \
+ b_tmp = rhs.adjoint(); \
+ } else { \
+ Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,n,m,OuterStride<>(rhsStride)); \
+ b_tmp = rhs.transpose(); \
+ } \
+ b = b_tmp.data(); \
+ ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \
+ } \
+\
+ BLASFUNC(&side, &uplo, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &ldc); \
+\
+ } \
+};
+
+#ifdef EIGEN_USE_MKL
+EIGEN_BLAS_SYMM_L(double, double, d, dsymm)
+EIGEN_BLAS_SYMM_L(float, float, f, ssymm)
+EIGEN_BLAS_HEMM_L(dcomplex, MKL_Complex16, cd, zhemm)
+EIGEN_BLAS_HEMM_L(scomplex, MKL_Complex8, cf, chemm)
+#else
+EIGEN_BLAS_SYMM_L(double, double, d, dsymm_)
+EIGEN_BLAS_SYMM_L(float, float, f, ssymm_)
+EIGEN_BLAS_HEMM_L(dcomplex, double, cd, zhemm_)
+EIGEN_BLAS_HEMM_L(scomplex, float, cf, chemm_)
+#endif
+
+/* Optimized matrix * selfadjoint matrix (?SYMM/?HEMM) product */
+
+#define EIGEN_BLAS_SYMM_R(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \
+template <typename Index, \
+ int LhsStorageOrder, bool ConjugateLhs, \
+ int RhsStorageOrder, bool ConjugateRhs> \
+struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,false,ConjugateLhs,RhsStorageOrder,true,ConjugateRhs,ColMajor,1> \
+{\
+\
+ static void run( \
+ Index rows, Index cols, \
+ const EIGTYPE* _lhs, Index lhsStride, \
+ const EIGTYPE* _rhs, Index rhsStride, \
+ EIGTYPE* res, Index resIncr, Index resStride, \
+ EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \
+ { \
+ EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \
+ eigen_assert(resIncr == 1); \
+ char side='R', uplo='L'; \
+ BlasIndex m, n, lda, ldb, ldc; \
+ const EIGTYPE *a, *b; \
+ EIGTYPE beta(1); \
+ MatrixX##EIGPREFIX b_tmp; \
+\
+/* Set m, n, k */ \
+ m = convert_index<BlasIndex>(rows); \
+ n = convert_index<BlasIndex>(cols); \
+\
+/* Set lda, ldb, ldc */ \
+ lda = convert_index<BlasIndex>(rhsStride); \
+ ldb = convert_index<BlasIndex>(lhsStride); \
+ ldc = convert_index<BlasIndex>(resStride); \
+\
+/* Set a, b, c */ \
+ if (RhsStorageOrder==RowMajor) uplo='U'; \
+ a = _rhs; \
+\
+ if (LhsStorageOrder==RowMajor) { \
+ Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,n,m,OuterStride<>(rhsStride)); \
+ b_tmp = lhs.adjoint(); \
+ b = b_tmp.data(); \
+ ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \
+ } else b = _lhs; \
+\
+ BLASFUNC(&side, &uplo, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &ldc); \
+\
+ } \
+};
+
+
+#define EIGEN_BLAS_HEMM_R(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \
+template <typename Index, \
+ int LhsStorageOrder, bool ConjugateLhs, \
+ int RhsStorageOrder, bool ConjugateRhs> \
+struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,false,ConjugateLhs,RhsStorageOrder,true,ConjugateRhs,ColMajor,1> \
+{\
+ static void run( \
+ Index rows, Index cols, \
+ const EIGTYPE* _lhs, Index lhsStride, \
+ const EIGTYPE* _rhs, Index rhsStride, \
+ EIGTYPE* res, Index resIncr, Index resStride, \
+ EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) \
+ { \
+ EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \
+ eigen_assert(resIncr == 1); \
+ char side='R', uplo='L'; \
+ BlasIndex m, n, lda, ldb, ldc; \
+ const EIGTYPE *a, *b; \
+ EIGTYPE beta(1); \
+ MatrixX##EIGPREFIX b_tmp; \
+ Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder> a_tmp; \
+\
+/* Set m, n, k */ \
+ m = convert_index<BlasIndex>(rows); \
+ n = convert_index<BlasIndex>(cols); \
+\
+/* Set lda, ldb, ldc */ \
+ lda = convert_index<BlasIndex>(rhsStride); \
+ ldb = convert_index<BlasIndex>(lhsStride); \
+ ldc = convert_index<BlasIndex>(resStride); \
+\
+/* Set a, b, c */ \
+ if (((RhsStorageOrder==ColMajor) && ConjugateRhs) || ((RhsStorageOrder==RowMajor) && (!ConjugateRhs))) { \
+ Map<const Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder>, 0, OuterStride<> > rhs(_rhs,n,n,OuterStride<>(rhsStride)); \
+ a_tmp = rhs.conjugate(); \
+ a = a_tmp.data(); \
+ lda = convert_index<BlasIndex>(a_tmp.outerStride()); \
+ } else a = _rhs; \
+ if (RhsStorageOrder==RowMajor) uplo='U'; \
+\
+ if (LhsStorageOrder==ColMajor && (!ConjugateLhs)) { \
+ b = _lhs; } \
+ else { \
+ if (LhsStorageOrder==ColMajor && ConjugateLhs) { \
+ Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,m,n,OuterStride<>(lhsStride)); \
+ b_tmp = lhs.conjugate(); \
+ } else \
+ if (ConjugateLhs) { \
+ Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,n,m,OuterStride<>(lhsStride)); \
+ b_tmp = lhs.adjoint(); \
+ } else { \
+ Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,n,m,OuterStride<>(lhsStride)); \
+ b_tmp = lhs.transpose(); \
+ } \
+ b = b_tmp.data(); \
+ ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \
+ } \
+\
+ BLASFUNC(&side, &uplo, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &ldc); \
+ } \
+};
+
+#ifdef EIGEN_USE_MKL
+EIGEN_BLAS_SYMM_R(double, double, d, dsymm)
+EIGEN_BLAS_SYMM_R(float, float, f, ssymm)
+EIGEN_BLAS_HEMM_R(dcomplex, MKL_Complex16, cd, zhemm)
+EIGEN_BLAS_HEMM_R(scomplex, MKL_Complex8, cf, chemm)
+#else
+EIGEN_BLAS_SYMM_R(double, double, d, dsymm_)
+EIGEN_BLAS_SYMM_R(float, float, f, ssymm_)
+EIGEN_BLAS_HEMM_R(dcomplex, double, cd, zhemm_)
+EIGEN_BLAS_HEMM_R(scomplex, float, cf, chemm_)
+#endif
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_SELFADJOINT_MATRIX_MATRIX_BLAS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h
new file mode 100644
index 000000000..d38fd72b2
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h
@@ -0,0 +1,262 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SELFADJOINT_MATRIX_VECTOR_H
+#define EIGEN_SELFADJOINT_MATRIX_VECTOR_H
+
+namespace Eigen {
+
+namespace internal {
+
+/* Optimized selfadjoint matrix * vector product:
+ * This algorithm processes 2 columns at once that allows to both reduce
+ * the number of load/stores of the result by a factor 2 and to reduce
+ * the instruction dependency.
+ */
+
+template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs, int Version=Specialized>
+struct selfadjoint_matrix_vector_product;
+
+template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs, int Version>
+struct selfadjoint_matrix_vector_product
+
+{
+static EIGEN_DONT_INLINE EIGEN_DEVICE_FUNC
+void run(
+ Index size,
+ const Scalar* lhs, Index lhsStride,
+ const Scalar* rhs,
+ Scalar* res,
+ Scalar alpha);
+};
+
+template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs, int Version>
+EIGEN_DONT_INLINE EIGEN_DEVICE_FUNC
+void selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,Version>::run(
+ Index size,
+ const Scalar* lhs, Index lhsStride,
+ const Scalar* rhs,
+ Scalar* res,
+ Scalar alpha)
+{
+ typedef typename packet_traits<Scalar>::type Packet;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ const Index PacketSize = sizeof(Packet)/sizeof(Scalar);
+
+ enum {
+ IsRowMajor = StorageOrder==RowMajor ? 1 : 0,
+ IsLower = UpLo == Lower ? 1 : 0,
+ FirstTriangular = IsRowMajor == IsLower
+ };
+
+ conj_helper<Scalar,Scalar,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, IsRowMajor), ConjugateRhs> cj0;
+ conj_helper<Scalar,Scalar,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, !IsRowMajor), ConjugateRhs> cj1;
+ conj_helper<RealScalar,Scalar,false, ConjugateRhs> cjd;
+
+ conj_helper<Packet,Packet,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, IsRowMajor), ConjugateRhs> pcj0;
+ conj_helper<Packet,Packet,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, !IsRowMajor), ConjugateRhs> pcj1;
+
+ Scalar cjAlpha = ConjugateRhs ? numext::conj(alpha) : alpha;
+
+ Index bound = numext::maxi(Index(0), size-8) & 0xfffffffe;
+ if (FirstTriangular)
+ bound = size - bound;
+
+ for (Index j=FirstTriangular ? bound : 0;
+ j<(FirstTriangular ? size : bound);j+=2)
+ {
+ const Scalar* EIGEN_RESTRICT A0 = lhs + j*lhsStride;
+ const Scalar* EIGEN_RESTRICT A1 = lhs + (j+1)*lhsStride;
+
+ Scalar t0 = cjAlpha * rhs[j];
+ Packet ptmp0 = pset1<Packet>(t0);
+ Scalar t1 = cjAlpha * rhs[j+1];
+ Packet ptmp1 = pset1<Packet>(t1);
+
+ Scalar t2(0);
+ Packet ptmp2 = pset1<Packet>(t2);
+ Scalar t3(0);
+ Packet ptmp3 = pset1<Packet>(t3);
+
+ Index starti = FirstTriangular ? 0 : j+2;
+ Index endi = FirstTriangular ? j : size;
+ Index alignedStart = (starti) + internal::first_default_aligned(&res[starti], endi-starti);
+ Index alignedEnd = alignedStart + ((endi-alignedStart)/(PacketSize))*(PacketSize);
+
+ res[j] += cjd.pmul(numext::real(A0[j]), t0);
+ res[j+1] += cjd.pmul(numext::real(A1[j+1]), t1);
+ if(FirstTriangular)
+ {
+ res[j] += cj0.pmul(A1[j], t1);
+ t3 += cj1.pmul(A1[j], rhs[j]);
+ }
+ else
+ {
+ res[j+1] += cj0.pmul(A0[j+1],t0);
+ t2 += cj1.pmul(A0[j+1], rhs[j+1]);
+ }
+
+ for (Index i=starti; i<alignedStart; ++i)
+ {
+ res[i] += cj0.pmul(A0[i], t0) + cj0.pmul(A1[i],t1);
+ t2 += cj1.pmul(A0[i], rhs[i]);
+ t3 += cj1.pmul(A1[i], rhs[i]);
+ }
+ // Yes this an optimization for gcc 4.3 and 4.4 (=> huge speed up)
+ // gcc 4.2 does this optimization automatically.
+ const Scalar* EIGEN_RESTRICT a0It = A0 + alignedStart;
+ const Scalar* EIGEN_RESTRICT a1It = A1 + alignedStart;
+ const Scalar* EIGEN_RESTRICT rhsIt = rhs + alignedStart;
+ Scalar* EIGEN_RESTRICT resIt = res + alignedStart;
+ for (Index i=alignedStart; i<alignedEnd; i+=PacketSize)
+ {
+ Packet A0i = ploadu<Packet>(a0It); a0It += PacketSize;
+ Packet A1i = ploadu<Packet>(a1It); a1It += PacketSize;
+ Packet Bi = ploadu<Packet>(rhsIt); rhsIt += PacketSize; // FIXME should be aligned in most cases
+ Packet Xi = pload <Packet>(resIt);
+
+ Xi = pcj0.pmadd(A0i,ptmp0, pcj0.pmadd(A1i,ptmp1,Xi));
+ ptmp2 = pcj1.pmadd(A0i, Bi, ptmp2);
+ ptmp3 = pcj1.pmadd(A1i, Bi, ptmp3);
+ pstore(resIt,Xi); resIt += PacketSize;
+ }
+ for (Index i=alignedEnd; i<endi; i++)
+ {
+ res[i] += cj0.pmul(A0[i], t0) + cj0.pmul(A1[i],t1);
+ t2 += cj1.pmul(A0[i], rhs[i]);
+ t3 += cj1.pmul(A1[i], rhs[i]);
+ }
+
+ res[j] += alpha * (t2 + predux(ptmp2));
+ res[j+1] += alpha * (t3 + predux(ptmp3));
+ }
+ for (Index j=FirstTriangular ? 0 : bound;j<(FirstTriangular ? bound : size);j++)
+ {
+ const Scalar* EIGEN_RESTRICT A0 = lhs + j*lhsStride;
+
+ Scalar t1 = cjAlpha * rhs[j];
+ Scalar t2(0);
+ res[j] += cjd.pmul(numext::real(A0[j]), t1);
+ for (Index i=FirstTriangular ? 0 : j+1; i<(FirstTriangular ? j : size); i++)
+ {
+ res[i] += cj0.pmul(A0[i], t1);
+ t2 += cj1.pmul(A0[i], rhs[i]);
+ }
+ res[j] += alpha * t2;
+ }
+}
+
+} // end namespace internal
+
+/***************************************************************************
+* Wrapper to product_selfadjoint_vector
+***************************************************************************/
+
+namespace internal {
+
+template<typename Lhs, int LhsMode, typename Rhs>
+struct selfadjoint_product_impl<Lhs,LhsMode,false,Rhs,0,true>
+{
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+
+ typedef internal::blas_traits<Lhs> LhsBlasTraits;
+ typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
+ typedef typename internal::remove_all<ActualLhsType>::type ActualLhsTypeCleaned;
+
+ typedef internal::blas_traits<Rhs> RhsBlasTraits;
+ typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
+ typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned;
+
+ enum { LhsUpLo = LhsMode&(Upper|Lower) };
+
+ template<typename Dest>
+ static EIGEN_DEVICE_FUNC
+ void run(Dest& dest, const Lhs &a_lhs, const Rhs &a_rhs, const Scalar& alpha)
+ {
+ typedef typename Dest::Scalar ResScalar;
+ typedef typename Rhs::Scalar RhsScalar;
+ typedef Map<Matrix<ResScalar,Dynamic,1>, EIGEN_PLAIN_ENUM_MIN(AlignedMax,internal::packet_traits<ResScalar>::size)> MappedDest;
+
+ eigen_assert(dest.rows()==a_lhs.rows() && dest.cols()==a_rhs.cols());
+
+ typename internal::add_const_on_value_type<ActualLhsType>::type lhs = LhsBlasTraits::extract(a_lhs);
+ typename internal::add_const_on_value_type<ActualRhsType>::type rhs = RhsBlasTraits::extract(a_rhs);
+
+ Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(a_lhs)
+ * RhsBlasTraits::extractScalarFactor(a_rhs);
+
+ enum {
+ EvalToDest = (Dest::InnerStrideAtCompileTime==1),
+ UseRhs = (ActualRhsTypeCleaned::InnerStrideAtCompileTime==1)
+ };
+
+ internal::gemv_static_vector_if<ResScalar,Dest::SizeAtCompileTime,Dest::MaxSizeAtCompileTime,!EvalToDest> static_dest;
+ internal::gemv_static_vector_if<RhsScalar,ActualRhsTypeCleaned::SizeAtCompileTime,ActualRhsTypeCleaned::MaxSizeAtCompileTime,!UseRhs> static_rhs;
+
+ ei_declare_aligned_stack_constructed_variable(ResScalar,actualDestPtr,dest.size(),
+ EvalToDest ? dest.data() : static_dest.data());
+
+ ei_declare_aligned_stack_constructed_variable(RhsScalar,actualRhsPtr,rhs.size(),
+ UseRhs ? const_cast<RhsScalar*>(rhs.data()) : static_rhs.data());
+
+ if(!EvalToDest)
+ {
+ #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ Index size = dest.size();
+ EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ #endif
+ MappedDest(actualDestPtr, dest.size()) = dest;
+ }
+
+ if(!UseRhs)
+ {
+ #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ Index size = rhs.size();
+ EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ #endif
+ Map<typename ActualRhsTypeCleaned::PlainObject>(actualRhsPtr, rhs.size()) = rhs;
+ }
+
+
+ internal::selfadjoint_matrix_vector_product<Scalar, Index, (internal::traits<ActualLhsTypeCleaned>::Flags&RowMajorBit) ? RowMajor : ColMajor,
+ int(LhsUpLo), bool(LhsBlasTraits::NeedToConjugate), bool(RhsBlasTraits::NeedToConjugate)>::run
+ (
+ lhs.rows(), // size
+ &lhs.coeffRef(0,0), lhs.outerStride(), // lhs info
+ actualRhsPtr, // rhs info
+ actualDestPtr, // result info
+ actualAlpha // scale factor
+ );
+
+ if(!EvalToDest)
+ dest = MappedDest(actualDestPtr, dest.size());
+ }
+};
+
+template<typename Lhs, typename Rhs, int RhsMode>
+struct selfadjoint_product_impl<Lhs,0,true,Rhs,RhsMode,false>
+{
+ typedef typename Product<Lhs,Rhs>::Scalar Scalar;
+ enum { RhsUpLo = RhsMode&(Upper|Lower) };
+
+ template<typename Dest>
+ static void run(Dest& dest, const Lhs &a_lhs, const Rhs &a_rhs, const Scalar& alpha)
+ {
+ // let's simply transpose the product
+ Transpose<Dest> destT(dest);
+ selfadjoint_product_impl<Transpose<const Rhs>, int(RhsUpLo)==Upper ? Lower : Upper, false,
+ Transpose<const Lhs>, 0, true>::run(destT, a_rhs.transpose(), a_lhs.transpose(), alpha);
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_SELFADJOINT_MATRIX_VECTOR_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h
new file mode 100644
index 000000000..1238345e3
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h
@@ -0,0 +1,118 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to BLAS F77
+ * Selfadjoint matrix-vector product functionality based on ?SYMV/HEMV.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H
+#define EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H
+
+namespace Eigen {
+
+namespace internal {
+
+/**********************************************************************
+* This file implements selfadjoint matrix-vector multiplication using BLAS
+**********************************************************************/
+
+// symv/hemv specialization
+
+template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs>
+struct selfadjoint_matrix_vector_product_symv :
+ selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,BuiltIn> {};
+
+#define EIGEN_BLAS_SYMV_SPECIALIZE(Scalar) \
+template<typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> \
+struct selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,Specialized> { \
+static void run( \
+ Index size, const Scalar* lhs, Index lhsStride, \
+ const Scalar* _rhs, Scalar* res, Scalar alpha) { \
+ enum {\
+ IsColMajor = StorageOrder==ColMajor \
+ }; \
+ if (IsColMajor == ConjugateLhs) {\
+ selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,BuiltIn>::run( \
+ size, lhs, lhsStride, _rhs, res, alpha); \
+ } else {\
+ selfadjoint_matrix_vector_product_symv<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs>::run( \
+ size, lhs, lhsStride, _rhs, res, alpha); \
+ }\
+ } \
+}; \
+
+EIGEN_BLAS_SYMV_SPECIALIZE(double)
+EIGEN_BLAS_SYMV_SPECIALIZE(float)
+EIGEN_BLAS_SYMV_SPECIALIZE(dcomplex)
+EIGEN_BLAS_SYMV_SPECIALIZE(scomplex)
+
+#define EIGEN_BLAS_SYMV_SPECIALIZATION(EIGTYPE,BLASTYPE,BLASFUNC) \
+template<typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> \
+struct selfadjoint_matrix_vector_product_symv<EIGTYPE,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs> \
+{ \
+typedef Matrix<EIGTYPE,Dynamic,1,ColMajor> SYMVVector;\
+\
+static void run( \
+Index size, const EIGTYPE* lhs, Index lhsStride, \
+const EIGTYPE* _rhs, EIGTYPE* res, EIGTYPE alpha) \
+{ \
+ enum {\
+ IsRowMajor = StorageOrder==RowMajor ? 1 : 0, \
+ IsLower = UpLo == Lower ? 1 : 0 \
+ }; \
+ BlasIndex n=convert_index<BlasIndex>(size), lda=convert_index<BlasIndex>(lhsStride), incx=1, incy=1; \
+ EIGTYPE beta(1); \
+ const EIGTYPE *x_ptr; \
+ char uplo=(IsRowMajor) ? (IsLower ? 'U' : 'L') : (IsLower ? 'L' : 'U'); \
+ SYMVVector x_tmp; \
+ if (ConjugateRhs) { \
+ Map<const SYMVVector, 0 > map_x(_rhs,size,1); \
+ x_tmp=map_x.conjugate(); \
+ x_ptr=x_tmp.data(); \
+ } else x_ptr=_rhs; \
+ BLASFUNC(&uplo, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)lhs, &lda, (const BLASTYPE*)x_ptr, &incx, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &incy); \
+}\
+};
+
+#ifdef EIGEN_USE_MKL
+EIGEN_BLAS_SYMV_SPECIALIZATION(double, double, dsymv)
+EIGEN_BLAS_SYMV_SPECIALIZATION(float, float, ssymv)
+EIGEN_BLAS_SYMV_SPECIALIZATION(dcomplex, MKL_Complex16, zhemv)
+EIGEN_BLAS_SYMV_SPECIALIZATION(scomplex, MKL_Complex8, chemv)
+#else
+EIGEN_BLAS_SYMV_SPECIALIZATION(double, double, dsymv_)
+EIGEN_BLAS_SYMV_SPECIALIZATION(float, float, ssymv_)
+EIGEN_BLAS_SYMV_SPECIALIZATION(dcomplex, double, zhemv_)
+EIGEN_BLAS_SYMV_SPECIALIZATION(scomplex, float, chemv_)
+#endif
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointProduct.h b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointProduct.h
new file mode 100644
index 000000000..a21be8050
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointProduct.h
@@ -0,0 +1,133 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SELFADJOINT_PRODUCT_H
+#define EIGEN_SELFADJOINT_PRODUCT_H
+
+/**********************************************************************
+* This file implements a self adjoint product: C += A A^T updating only
+* half of the selfadjoint matrix C.
+* It corresponds to the level 3 SYRK and level 2 SYR Blas routines.
+**********************************************************************/
+
+namespace Eigen {
+
+
+template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs>
+struct selfadjoint_rank1_update<Scalar,Index,ColMajor,UpLo,ConjLhs,ConjRhs>
+{
+ static void run(Index size, Scalar* mat, Index stride, const Scalar* vecX, const Scalar* vecY, const Scalar& alpha)
+ {
+ internal::conj_if<ConjRhs> cj;
+ typedef Map<const Matrix<Scalar,Dynamic,1> > OtherMap;
+ typedef typename internal::conditional<ConjLhs,typename OtherMap::ConjugateReturnType,const OtherMap&>::type ConjLhsType;
+ for (Index i=0; i<size; ++i)
+ {
+ Map<Matrix<Scalar,Dynamic,1> >(mat+stride*i+(UpLo==Lower ? i : 0), (UpLo==Lower ? size-i : (i+1)))
+ += (alpha * cj(vecY[i])) * ConjLhsType(OtherMap(vecX+(UpLo==Lower ? i : 0),UpLo==Lower ? size-i : (i+1)));
+ }
+ }
+};
+
+template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs>
+struct selfadjoint_rank1_update<Scalar,Index,RowMajor,UpLo,ConjLhs,ConjRhs>
+{
+ static void run(Index size, Scalar* mat, Index stride, const Scalar* vecX, const Scalar* vecY, const Scalar& alpha)
+ {
+ selfadjoint_rank1_update<Scalar,Index,ColMajor,UpLo==Lower?Upper:Lower,ConjRhs,ConjLhs>::run(size,mat,stride,vecY,vecX,alpha);
+ }
+};
+
+template<typename MatrixType, typename OtherType, int UpLo, bool OtherIsVector = OtherType::IsVectorAtCompileTime>
+struct selfadjoint_product_selector;
+
+template<typename MatrixType, typename OtherType, int UpLo>
+struct selfadjoint_product_selector<MatrixType,OtherType,UpLo,true>
+{
+ static void run(MatrixType& mat, const OtherType& other, const typename MatrixType::Scalar& alpha)
+ {
+ typedef typename MatrixType::Scalar Scalar;
+ typedef internal::blas_traits<OtherType> OtherBlasTraits;
+ typedef typename OtherBlasTraits::DirectLinearAccessType ActualOtherType;
+ typedef typename internal::remove_all<ActualOtherType>::type _ActualOtherType;
+ typename internal::add_const_on_value_type<ActualOtherType>::type actualOther = OtherBlasTraits::extract(other.derived());
+
+ Scalar actualAlpha = alpha * OtherBlasTraits::extractScalarFactor(other.derived());
+
+ enum {
+ StorageOrder = (internal::traits<MatrixType>::Flags&RowMajorBit) ? RowMajor : ColMajor,
+ UseOtherDirectly = _ActualOtherType::InnerStrideAtCompileTime==1
+ };
+ internal::gemv_static_vector_if<Scalar,OtherType::SizeAtCompileTime,OtherType::MaxSizeAtCompileTime,!UseOtherDirectly> static_other;
+
+ ei_declare_aligned_stack_constructed_variable(Scalar, actualOtherPtr, other.size(),
+ (UseOtherDirectly ? const_cast<Scalar*>(actualOther.data()) : static_other.data()));
+
+ if(!UseOtherDirectly)
+ Map<typename _ActualOtherType::PlainObject>(actualOtherPtr, actualOther.size()) = actualOther;
+
+ selfadjoint_rank1_update<Scalar,Index,StorageOrder,UpLo,
+ OtherBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex,
+ (!OtherBlasTraits::NeedToConjugate) && NumTraits<Scalar>::IsComplex>
+ ::run(other.size(), mat.data(), mat.outerStride(), actualOtherPtr, actualOtherPtr, actualAlpha);
+ }
+};
+
+template<typename MatrixType, typename OtherType, int UpLo>
+struct selfadjoint_product_selector<MatrixType,OtherType,UpLo,false>
+{
+ static void run(MatrixType& mat, const OtherType& other, const typename MatrixType::Scalar& alpha)
+ {
+ typedef typename MatrixType::Scalar Scalar;
+ typedef internal::blas_traits<OtherType> OtherBlasTraits;
+ typedef typename OtherBlasTraits::DirectLinearAccessType ActualOtherType;
+ typedef typename internal::remove_all<ActualOtherType>::type _ActualOtherType;
+ typename internal::add_const_on_value_type<ActualOtherType>::type actualOther = OtherBlasTraits::extract(other.derived());
+
+ Scalar actualAlpha = alpha * OtherBlasTraits::extractScalarFactor(other.derived());
+
+ enum {
+ IsRowMajor = (internal::traits<MatrixType>::Flags&RowMajorBit) ? 1 : 0,
+ OtherIsRowMajor = _ActualOtherType::Flags&RowMajorBit ? 1 : 0
+ };
+
+ Index size = mat.cols();
+ Index depth = actualOther.cols();
+
+ typedef internal::gemm_blocking_space<IsRowMajor ? RowMajor : ColMajor,Scalar,Scalar,
+ MatrixType::MaxColsAtCompileTime, MatrixType::MaxColsAtCompileTime, _ActualOtherType::MaxColsAtCompileTime> BlockingType;
+
+ BlockingType blocking(size, size, depth, 1, false);
+
+
+ internal::general_matrix_matrix_triangular_product<Index,
+ Scalar, OtherIsRowMajor ? RowMajor : ColMajor, OtherBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex,
+ Scalar, OtherIsRowMajor ? ColMajor : RowMajor, (!OtherBlasTraits::NeedToConjugate) && NumTraits<Scalar>::IsComplex,
+ IsRowMajor ? RowMajor : ColMajor, MatrixType::InnerStrideAtCompileTime, UpLo>
+ ::run(size, depth,
+ actualOther.data(), actualOther.outerStride(), actualOther.data(), actualOther.outerStride(),
+ mat.data(), mat.innerStride(), mat.outerStride(), actualAlpha, blocking);
+ }
+};
+
+// high level API
+
+template<typename MatrixType, unsigned int UpLo>
+template<typename DerivedU>
+EIGEN_DEVICE_FUNC SelfAdjointView<MatrixType,UpLo>& SelfAdjointView<MatrixType,UpLo>
+::rankUpdate(const MatrixBase<DerivedU>& u, const Scalar& alpha)
+{
+ selfadjoint_product_selector<MatrixType,DerivedU,UpLo>::run(_expression().const_cast_derived(), u.derived(), alpha);
+
+ return *this;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_SELFADJOINT_PRODUCT_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h
new file mode 100644
index 000000000..f752a0bf0
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h
@@ -0,0 +1,94 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SELFADJOINTRANK2UPTADE_H
+#define EIGEN_SELFADJOINTRANK2UPTADE_H
+
+namespace Eigen {
+
+namespace internal {
+
+/* Optimized selfadjoint matrix += alpha * uv' + conj(alpha)*vu'
+ * It corresponds to the Level2 syr2 BLAS routine
+ */
+
+template<typename Scalar, typename Index, typename UType, typename VType, int UpLo>
+struct selfadjoint_rank2_update_selector;
+
+template<typename Scalar, typename Index, typename UType, typename VType>
+struct selfadjoint_rank2_update_selector<Scalar,Index,UType,VType,Lower>
+{
+ static EIGEN_DEVICE_FUNC
+ void run(Scalar* mat, Index stride, const UType& u, const VType& v, const Scalar& alpha)
+ {
+ const Index size = u.size();
+ for (Index i=0; i<size; ++i)
+ {
+ Map<Matrix<Scalar,Dynamic,1> >(mat+stride*i+i, size-i) +=
+ (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.tail(size-i)
+ + (alpha * numext::conj(v.coeff(i))) * u.tail(size-i);
+ }
+ }
+};
+
+template<typename Scalar, typename Index, typename UType, typename VType>
+struct selfadjoint_rank2_update_selector<Scalar,Index,UType,VType,Upper>
+{
+ static void run(Scalar* mat, Index stride, const UType& u, const VType& v, const Scalar& alpha)
+ {
+ const Index size = u.size();
+ for (Index i=0; i<size; ++i)
+ Map<Matrix<Scalar,Dynamic,1> >(mat+stride*i, i+1) +=
+ (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.head(i+1)
+ + (alpha * numext::conj(v.coeff(i))) * u.head(i+1);
+ }
+};
+
+template<bool Cond, typename T> struct conj_expr_if
+ : conditional<!Cond, const T&,
+ CwiseUnaryOp<scalar_conjugate_op<typename traits<T>::Scalar>,T> > {};
+
+} // end namespace internal
+
+template<typename MatrixType, unsigned int UpLo>
+template<typename DerivedU, typename DerivedV>
+EIGEN_DEVICE_FUNC SelfAdjointView<MatrixType,UpLo>& SelfAdjointView<MatrixType,UpLo>
+::rankUpdate(const MatrixBase<DerivedU>& u, const MatrixBase<DerivedV>& v, const Scalar& alpha)
+{
+ typedef internal::blas_traits<DerivedU> UBlasTraits;
+ typedef typename UBlasTraits::DirectLinearAccessType ActualUType;
+ typedef typename internal::remove_all<ActualUType>::type _ActualUType;
+ typename internal::add_const_on_value_type<ActualUType>::type actualU = UBlasTraits::extract(u.derived());
+
+ typedef internal::blas_traits<DerivedV> VBlasTraits;
+ typedef typename VBlasTraits::DirectLinearAccessType ActualVType;
+ typedef typename internal::remove_all<ActualVType>::type _ActualVType;
+ typename internal::add_const_on_value_type<ActualVType>::type actualV = VBlasTraits::extract(v.derived());
+
+ // If MatrixType is row major, then we use the routine for lower triangular in the upper triangular case and
+ // vice versa, and take the complex conjugate of all coefficients and vector entries.
+
+ enum { IsRowMajor = (internal::traits<MatrixType>::Flags&RowMajorBit) ? 1 : 0 };
+ Scalar actualAlpha = alpha * UBlasTraits::extractScalarFactor(u.derived())
+ * numext::conj(VBlasTraits::extractScalarFactor(v.derived()));
+ if (IsRowMajor)
+ actualAlpha = numext::conj(actualAlpha);
+
+ typedef typename internal::remove_all<typename internal::conj_expr_if<int(IsRowMajor) ^ int(UBlasTraits::NeedToConjugate), _ActualUType>::type>::type UType;
+ typedef typename internal::remove_all<typename internal::conj_expr_if<int(IsRowMajor) ^ int(VBlasTraits::NeedToConjugate), _ActualVType>::type>::type VType;
+ internal::selfadjoint_rank2_update_selector<Scalar, Index, UType, VType,
+ (IsRowMajor ? int(UpLo==Upper ? Lower : Upper) : UpLo)>
+ ::run(_expression().const_cast_derived().data(),_expression().outerStride(),UType(actualU),VType(actualV),actualAlpha);
+
+ return *this;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_SELFADJOINTRANK2UPTADE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h
new file mode 100644
index 000000000..f0c60507a
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h
@@ -0,0 +1,472 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TRIANGULAR_MATRIX_MATRIX_H
+#define EIGEN_TRIANGULAR_MATRIX_MATRIX_H
+
+namespace Eigen {
+
+namespace internal {
+
+// template<typename Scalar, int mr, int StorageOrder, bool Conjugate, int Mode>
+// struct gemm_pack_lhs_triangular
+// {
+// Matrix<Scalar,mr,mr,
+// void operator()(Scalar* blockA, const EIGEN_RESTRICT Scalar* _lhs, int lhsStride, int depth, int rows)
+// {
+// conj_if<NumTraits<Scalar>::IsComplex && Conjugate> cj;
+// const_blas_data_mapper<Scalar, StorageOrder> lhs(_lhs,lhsStride);
+// int count = 0;
+// const int peeled_mc = (rows/mr)*mr;
+// for(int i=0; i<peeled_mc; i+=mr)
+// {
+// for(int k=0; k<depth; k++)
+// for(int w=0; w<mr; w++)
+// blockA[count++] = cj(lhs(i+w, k));
+// }
+// for(int i=peeled_mc; i<rows; i++)
+// {
+// for(int k=0; k<depth; k++)
+// blockA[count++] = cj(lhs(i, k));
+// }
+// }
+// };
+
+/* Optimized triangular matrix * matrix (_TRMM++) product built on top of
+ * the general matrix matrix product.
+ */
+template <typename Scalar, typename Index,
+ int Mode, bool LhsIsTriangular,
+ int LhsStorageOrder, bool ConjugateLhs,
+ int RhsStorageOrder, bool ConjugateRhs,
+ int ResStorageOrder, int ResInnerStride,
+ int Version = Specialized>
+struct product_triangular_matrix_matrix;
+
+template <typename Scalar, typename Index,
+ int Mode, bool LhsIsTriangular,
+ int LhsStorageOrder, bool ConjugateLhs,
+ int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride, int Version>
+struct product_triangular_matrix_matrix<Scalar,Index,Mode,LhsIsTriangular,
+ LhsStorageOrder,ConjugateLhs,
+ RhsStorageOrder,ConjugateRhs,RowMajor,ResInnerStride,Version>
+{
+ static EIGEN_STRONG_INLINE void run(
+ Index rows, Index cols, Index depth,
+ const Scalar* lhs, Index lhsStride,
+ const Scalar* rhs, Index rhsStride,
+ Scalar* res, Index resIncr, Index resStride,
+ const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
+ {
+ product_triangular_matrix_matrix<Scalar, Index,
+ (Mode&(UnitDiag|ZeroDiag)) | ((Mode&Upper) ? Lower : Upper),
+ (!LhsIsTriangular),
+ RhsStorageOrder==RowMajor ? ColMajor : RowMajor,
+ ConjugateRhs,
+ LhsStorageOrder==RowMajor ? ColMajor : RowMajor,
+ ConjugateLhs,
+ ColMajor, ResInnerStride>
+ ::run(cols, rows, depth, rhs, rhsStride, lhs, lhsStride, res, resIncr, resStride, alpha, blocking);
+ }
+};
+
+// implements col-major += alpha * op(triangular) * op(general)
+template <typename Scalar, typename Index, int Mode,
+ int LhsStorageOrder, bool ConjugateLhs,
+ int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride, int Version>
+struct product_triangular_matrix_matrix<Scalar,Index,Mode,true,
+ LhsStorageOrder,ConjugateLhs,
+ RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride,Version>
+{
+
+ typedef gebp_traits<Scalar,Scalar> Traits;
+ enum {
+ SmallPanelWidth = 2 * EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr),
+ IsLower = (Mode&Lower) == Lower,
+ SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1
+ };
+
+ static EIGEN_DONT_INLINE void run(
+ Index _rows, Index _cols, Index _depth,
+ const Scalar* _lhs, Index lhsStride,
+ const Scalar* _rhs, Index rhsStride,
+ Scalar* res, Index resIncr, Index resStride,
+ const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking);
+};
+
+template <typename Scalar, typename Index, int Mode,
+ int LhsStorageOrder, bool ConjugateLhs,
+ int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride, int Version>
+EIGEN_DONT_INLINE void product_triangular_matrix_matrix<Scalar,Index,Mode,true,
+ LhsStorageOrder,ConjugateLhs,
+ RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride,Version>::run(
+ Index _rows, Index _cols, Index _depth,
+ const Scalar* _lhs, Index lhsStride,
+ const Scalar* _rhs, Index rhsStride,
+ Scalar* _res, Index resIncr, Index resStride,
+ const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
+ {
+ // strip zeros
+ Index diagSize = (std::min)(_rows,_depth);
+ Index rows = IsLower ? _rows : diagSize;
+ Index depth = IsLower ? diagSize : _depth;
+ Index cols = _cols;
+
+ typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper;
+ typedef const_blas_data_mapper<Scalar, Index, RhsStorageOrder> RhsMapper;
+ typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper;
+ LhsMapper lhs(_lhs,lhsStride);
+ RhsMapper rhs(_rhs,rhsStride);
+ ResMapper res(_res, resStride, resIncr);
+
+ Index kc = blocking.kc(); // cache block size along the K direction
+ Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction
+ // The small panel size must not be larger than blocking size.
+ // Usually this should never be the case because SmallPanelWidth^2 is very small
+ // compared to L2 cache size, but let's be safe:
+ Index panelWidth = (std::min)(Index(SmallPanelWidth),(std::min)(kc,mc));
+
+ std::size_t sizeA = kc*mc;
+ std::size_t sizeB = kc*cols;
+
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA());
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB());
+
+ // To work around an "error: member reference base type 'Matrix<...>
+ // (Eigen::internal::constructor_without_unaligned_array_assert (*)())' is
+ // not a structure or union" compilation error in nvcc (tested V8.0.61),
+ // create a dummy internal::constructor_without_unaligned_array_assert
+ // object to pass to the Matrix constructor.
+ internal::constructor_without_unaligned_array_assert a;
+ Matrix<Scalar,SmallPanelWidth,SmallPanelWidth,LhsStorageOrder> triangularBuffer(a);
+ triangularBuffer.setZero();
+ if((Mode&ZeroDiag)==ZeroDiag)
+ triangularBuffer.diagonal().setZero();
+ else
+ triangularBuffer.diagonal().setOnes();
+
+ gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel;
+ gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs;
+ gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder> pack_rhs;
+
+ for(Index k2=IsLower ? depth : 0;
+ IsLower ? k2>0 : k2<depth;
+ IsLower ? k2-=kc : k2+=kc)
+ {
+ Index actual_kc = (std::min)(IsLower ? k2 : depth-k2, kc);
+ Index actual_k2 = IsLower ? k2-actual_kc : k2;
+
+ // align blocks with the end of the triangular part for trapezoidal lhs
+ if((!IsLower)&&(k2<rows)&&(k2+actual_kc>rows))
+ {
+ actual_kc = rows-k2;
+ k2 = k2+actual_kc-kc;
+ }
+
+ pack_rhs(blockB, rhs.getSubMapper(actual_k2,0), actual_kc, cols);
+
+ // the selected lhs's panel has to be split in three different parts:
+ // 1 - the part which is zero => skip it
+ // 2 - the diagonal block => special kernel
+ // 3 - the dense panel below (lower case) or above (upper case) the diagonal block => GEPP
+
+ // the block diagonal, if any:
+ if(IsLower || actual_k2<rows)
+ {
+ // for each small vertical panels of lhs
+ for (Index k1=0; k1<actual_kc; k1+=panelWidth)
+ {
+ Index actualPanelWidth = std::min<Index>(actual_kc-k1, panelWidth);
+ Index lengthTarget = IsLower ? actual_kc-k1-actualPanelWidth : k1;
+ Index startBlock = actual_k2+k1;
+ Index blockBOffset = k1;
+
+ // => GEBP with the micro triangular block
+ // The trick is to pack this micro block while filling the opposite triangular part with zeros.
+ // To this end we do an extra triangular copy to a small temporary buffer
+ for (Index k=0;k<actualPanelWidth;++k)
+ {
+ if (SetDiag)
+ triangularBuffer.coeffRef(k,k) = lhs(startBlock+k,startBlock+k);
+ for (Index i=IsLower ? k+1 : 0; IsLower ? i<actualPanelWidth : i<k; ++i)
+ triangularBuffer.coeffRef(i,k) = lhs(startBlock+i,startBlock+k);
+ }
+ pack_lhs(blockA, LhsMapper(triangularBuffer.data(), triangularBuffer.outerStride()), actualPanelWidth, actualPanelWidth);
+
+ gebp_kernel(res.getSubMapper(startBlock, 0), blockA, blockB,
+ actualPanelWidth, actualPanelWidth, cols, alpha,
+ actualPanelWidth, actual_kc, 0, blockBOffset);
+
+ // GEBP with remaining micro panel
+ if (lengthTarget>0)
+ {
+ Index startTarget = IsLower ? actual_k2+k1+actualPanelWidth : actual_k2;
+
+ pack_lhs(blockA, lhs.getSubMapper(startTarget,startBlock), actualPanelWidth, lengthTarget);
+
+ gebp_kernel(res.getSubMapper(startTarget, 0), blockA, blockB,
+ lengthTarget, actualPanelWidth, cols, alpha,
+ actualPanelWidth, actual_kc, 0, blockBOffset);
+ }
+ }
+ }
+ // the part below (lower case) or above (upper case) the diagonal => GEPP
+ {
+ Index start = IsLower ? k2 : 0;
+ Index end = IsLower ? rows : (std::min)(actual_k2,rows);
+ for(Index i2=start; i2<end; i2+=mc)
+ {
+ const Index actual_mc = (std::min)(i2+mc,end)-i2;
+ gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr,Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder,false>()
+ (blockA, lhs.getSubMapper(i2, actual_k2), actual_kc, actual_mc);
+
+ gebp_kernel(res.getSubMapper(i2, 0), blockA, blockB, actual_mc,
+ actual_kc, cols, alpha, -1, -1, 0, 0);
+ }
+ }
+ }
+ }
+
+// implements col-major += alpha * op(general) * op(triangular)
+template <typename Scalar, typename Index, int Mode,
+ int LhsStorageOrder, bool ConjugateLhs,
+ int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride, int Version>
+struct product_triangular_matrix_matrix<Scalar,Index,Mode,false,
+ LhsStorageOrder,ConjugateLhs,
+ RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride,Version>
+{
+ typedef gebp_traits<Scalar,Scalar> Traits;
+ enum {
+ SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr),
+ IsLower = (Mode&Lower) == Lower,
+ SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1
+ };
+
+ static EIGEN_DONT_INLINE void run(
+ Index _rows, Index _cols, Index _depth,
+ const Scalar* _lhs, Index lhsStride,
+ const Scalar* _rhs, Index rhsStride,
+ Scalar* res, Index resIncr, Index resStride,
+ const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking);
+};
+
+template <typename Scalar, typename Index, int Mode,
+ int LhsStorageOrder, bool ConjugateLhs,
+ int RhsStorageOrder, bool ConjugateRhs,
+ int ResInnerStride, int Version>
+EIGEN_DONT_INLINE void product_triangular_matrix_matrix<Scalar,Index,Mode,false,
+ LhsStorageOrder,ConjugateLhs,
+ RhsStorageOrder,ConjugateRhs,ColMajor,ResInnerStride,Version>::run(
+ Index _rows, Index _cols, Index _depth,
+ const Scalar* _lhs, Index lhsStride,
+ const Scalar* _rhs, Index rhsStride,
+ Scalar* _res, Index resIncr, Index resStride,
+ const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
+ {
+ const Index PacketBytes = packet_traits<Scalar>::size*sizeof(Scalar);
+ // strip zeros
+ Index diagSize = (std::min)(_cols,_depth);
+ Index rows = _rows;
+ Index depth = IsLower ? _depth : diagSize;
+ Index cols = IsLower ? diagSize : _cols;
+
+ typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper;
+ typedef const_blas_data_mapper<Scalar, Index, RhsStorageOrder> RhsMapper;
+ typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper;
+ LhsMapper lhs(_lhs,lhsStride);
+ RhsMapper rhs(_rhs,rhsStride);
+ ResMapper res(_res, resStride, resIncr);
+
+ Index kc = blocking.kc(); // cache block size along the K direction
+ Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction
+
+ std::size_t sizeA = kc*mc;
+ std::size_t sizeB = kc*cols+EIGEN_MAX_ALIGN_BYTES/sizeof(Scalar);
+
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA());
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB());
+
+ internal::constructor_without_unaligned_array_assert a;
+ Matrix<Scalar,SmallPanelWidth,SmallPanelWidth,RhsStorageOrder> triangularBuffer(a);
+ triangularBuffer.setZero();
+ if((Mode&ZeroDiag)==ZeroDiag)
+ triangularBuffer.diagonal().setZero();
+ else
+ triangularBuffer.diagonal().setOnes();
+
+ gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel;
+ gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs;
+ gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder> pack_rhs;
+ gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder,false,true> pack_rhs_panel;
+
+ for(Index k2=IsLower ? 0 : depth;
+ IsLower ? k2<depth : k2>0;
+ IsLower ? k2+=kc : k2-=kc)
+ {
+ Index actual_kc = (std::min)(IsLower ? depth-k2 : k2, kc);
+ Index actual_k2 = IsLower ? k2 : k2-actual_kc;
+
+ // align blocks with the end of the triangular part for trapezoidal rhs
+ if(IsLower && (k2<cols) && (actual_k2+actual_kc>cols))
+ {
+ actual_kc = cols-k2;
+ k2 = actual_k2 + actual_kc - kc;
+ }
+
+ // remaining size
+ Index rs = IsLower ? (std::min)(cols,actual_k2) : cols - k2;
+ // size of the triangular part
+ Index ts = (IsLower && actual_k2>=cols) ? 0 : actual_kc;
+
+ Scalar* geb = blockB+ts*ts;
+ geb = geb + internal::first_aligned<PacketBytes>(geb,PacketBytes/sizeof(Scalar));
+
+ pack_rhs(geb, rhs.getSubMapper(actual_k2,IsLower ? 0 : k2), actual_kc, rs);
+
+ // pack the triangular part of the rhs padding the unrolled blocks with zeros
+ if(ts>0)
+ {
+ for (Index j2=0; j2<actual_kc; j2+=SmallPanelWidth)
+ {
+ Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
+ Index actual_j2 = actual_k2 + j2;
+ Index panelOffset = IsLower ? j2+actualPanelWidth : 0;
+ Index panelLength = IsLower ? actual_kc-j2-actualPanelWidth : j2;
+ // general part
+ pack_rhs_panel(blockB+j2*actual_kc,
+ rhs.getSubMapper(actual_k2+panelOffset, actual_j2),
+ panelLength, actualPanelWidth,
+ actual_kc, panelOffset);
+
+ // append the triangular part via a temporary buffer
+ for (Index j=0;j<actualPanelWidth;++j)
+ {
+ if (SetDiag)
+ triangularBuffer.coeffRef(j,j) = rhs(actual_j2+j,actual_j2+j);
+ for (Index k=IsLower ? j+1 : 0; IsLower ? k<actualPanelWidth : k<j; ++k)
+ triangularBuffer.coeffRef(k,j) = rhs(actual_j2+k,actual_j2+j);
+ }
+
+ pack_rhs_panel(blockB+j2*actual_kc,
+ RhsMapper(triangularBuffer.data(), triangularBuffer.outerStride()),
+ actualPanelWidth, actualPanelWidth,
+ actual_kc, j2);
+ }
+ }
+
+ for (Index i2=0; i2<rows; i2+=mc)
+ {
+ const Index actual_mc = (std::min)(mc,rows-i2);
+ pack_lhs(blockA, lhs.getSubMapper(i2, actual_k2), actual_kc, actual_mc);
+
+ // triangular kernel
+ if(ts>0)
+ {
+ for (Index j2=0; j2<actual_kc; j2+=SmallPanelWidth)
+ {
+ Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
+ Index panelLength = IsLower ? actual_kc-j2 : j2+actualPanelWidth;
+ Index blockOffset = IsLower ? j2 : 0;
+
+ gebp_kernel(res.getSubMapper(i2, actual_k2 + j2),
+ blockA, blockB+j2*actual_kc,
+ actual_mc, panelLength, actualPanelWidth,
+ alpha,
+ actual_kc, actual_kc, // strides
+ blockOffset, blockOffset);// offsets
+ }
+ }
+ gebp_kernel(res.getSubMapper(i2, IsLower ? 0 : k2),
+ blockA, geb, actual_mc, actual_kc, rs,
+ alpha,
+ -1, -1, 0, 0);
+ }
+ }
+ }
+
+/***************************************************************************
+* Wrapper to product_triangular_matrix_matrix
+***************************************************************************/
+
+} // end namespace internal
+
+namespace internal {
+template<int Mode, bool LhsIsTriangular, typename Lhs, typename Rhs>
+struct triangular_product_impl<Mode,LhsIsTriangular,Lhs,false,Rhs,false>
+{
+ template<typename Dest> static void run(Dest& dst, const Lhs &a_lhs, const Rhs &a_rhs, const typename Dest::Scalar& alpha)
+ {
+ typedef typename Lhs::Scalar LhsScalar;
+ typedef typename Rhs::Scalar RhsScalar;
+ typedef typename Dest::Scalar Scalar;
+
+ typedef internal::blas_traits<Lhs> LhsBlasTraits;
+ typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
+ typedef typename internal::remove_all<ActualLhsType>::type ActualLhsTypeCleaned;
+ typedef internal::blas_traits<Rhs> RhsBlasTraits;
+ typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
+ typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned;
+
+ typename internal::add_const_on_value_type<ActualLhsType>::type lhs = LhsBlasTraits::extract(a_lhs);
+ typename internal::add_const_on_value_type<ActualRhsType>::type rhs = RhsBlasTraits::extract(a_rhs);
+
+ LhsScalar lhs_alpha = LhsBlasTraits::extractScalarFactor(a_lhs);
+ RhsScalar rhs_alpha = RhsBlasTraits::extractScalarFactor(a_rhs);
+ Scalar actualAlpha = alpha * lhs_alpha * rhs_alpha;
+
+ typedef internal::gemm_blocking_space<(Dest::Flags&RowMajorBit) ? RowMajor : ColMajor,Scalar,Scalar,
+ Lhs::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime, Lhs::MaxColsAtCompileTime,4> BlockingType;
+
+ enum { IsLower = (Mode&Lower) == Lower };
+ Index stripedRows = ((!LhsIsTriangular) || (IsLower)) ? lhs.rows() : (std::min)(lhs.rows(),lhs.cols());
+ Index stripedCols = ((LhsIsTriangular) || (!IsLower)) ? rhs.cols() : (std::min)(rhs.cols(),rhs.rows());
+ Index stripedDepth = LhsIsTriangular ? ((!IsLower) ? lhs.cols() : (std::min)(lhs.cols(),lhs.rows()))
+ : ((IsLower) ? rhs.rows() : (std::min)(rhs.rows(),rhs.cols()));
+
+ BlockingType blocking(stripedRows, stripedCols, stripedDepth, 1, false);
+
+ internal::product_triangular_matrix_matrix<Scalar, Index,
+ Mode, LhsIsTriangular,
+ (internal::traits<ActualLhsTypeCleaned>::Flags&RowMajorBit) ? RowMajor : ColMajor, LhsBlasTraits::NeedToConjugate,
+ (internal::traits<ActualRhsTypeCleaned>::Flags&RowMajorBit) ? RowMajor : ColMajor, RhsBlasTraits::NeedToConjugate,
+ (internal::traits<Dest >::Flags&RowMajorBit) ? RowMajor : ColMajor, Dest::InnerStrideAtCompileTime>
+ ::run(
+ stripedRows, stripedCols, stripedDepth, // sizes
+ &lhs.coeffRef(0,0), lhs.outerStride(), // lhs info
+ &rhs.coeffRef(0,0), rhs.outerStride(), // rhs info
+ &dst.coeffRef(0,0), dst.innerStride(), dst.outerStride(), // result info
+ actualAlpha, blocking
+ );
+
+ // Apply correction if the diagonal is unit and a scalar factor was nested:
+ if ((Mode&UnitDiag)==UnitDiag)
+ {
+ if (LhsIsTriangular && lhs_alpha!=LhsScalar(1))
+ {
+ Index diagSize = (std::min)(lhs.rows(),lhs.cols());
+ dst.topRows(diagSize) -= ((lhs_alpha-LhsScalar(1))*a_rhs).topRows(diagSize);
+ }
+ else if ((!LhsIsTriangular) && rhs_alpha!=RhsScalar(1))
+ {
+ Index diagSize = (std::min)(rhs.rows(),rhs.cols());
+ dst.leftCols(diagSize) -= (rhs_alpha-RhsScalar(1))*a_lhs.leftCols(diagSize);
+ }
+ }
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRIANGULAR_MATRIX_MATRIX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h
new file mode 100644
index 000000000..a98d12e4a
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h
@@ -0,0 +1,317 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to BLAS F77
+ * Triangular matrix * matrix product functionality based on ?TRMM.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_TRIANGULAR_MATRIX_MATRIX_BLAS_H
+#define EIGEN_TRIANGULAR_MATRIX_MATRIX_BLAS_H
+
+namespace Eigen {
+
+namespace internal {
+
+
+template <typename Scalar, typename Index,
+ int Mode, bool LhsIsTriangular,
+ int LhsStorageOrder, bool ConjugateLhs,
+ int RhsStorageOrder, bool ConjugateRhs,
+ int ResStorageOrder>
+struct product_triangular_matrix_matrix_trmm :
+ product_triangular_matrix_matrix<Scalar,Index,Mode,
+ LhsIsTriangular,LhsStorageOrder,ConjugateLhs,
+ RhsStorageOrder, ConjugateRhs, ResStorageOrder, 1, BuiltIn> {};
+
+
+// try to go to BLAS specialization
+#define EIGEN_BLAS_TRMM_SPECIALIZE(Scalar, LhsIsTriangular) \
+template <typename Index, int Mode, \
+ int LhsStorageOrder, bool ConjugateLhs, \
+ int RhsStorageOrder, bool ConjugateRhs> \
+struct product_triangular_matrix_matrix<Scalar,Index, Mode, LhsIsTriangular, \
+ LhsStorageOrder,ConjugateLhs, RhsStorageOrder,ConjugateRhs,ColMajor,1,Specialized> { \
+ static inline void run(Index _rows, Index _cols, Index _depth, const Scalar* _lhs, Index lhsStride,\
+ const Scalar* _rhs, Index rhsStride, Scalar* res, Index resIncr, Index resStride, Scalar alpha, level3_blocking<Scalar,Scalar>& blocking) { \
+ EIGEN_ONLY_USED_FOR_DEBUG(resIncr); \
+ eigen_assert(resIncr == 1); \
+ product_triangular_matrix_matrix_trmm<Scalar,Index,Mode, \
+ LhsIsTriangular,LhsStorageOrder,ConjugateLhs, \
+ RhsStorageOrder, ConjugateRhs, ColMajor>::run( \
+ _rows, _cols, _depth, _lhs, lhsStride, _rhs, rhsStride, res, resStride, alpha, blocking); \
+ } \
+};
+
+EIGEN_BLAS_TRMM_SPECIALIZE(double, true)
+EIGEN_BLAS_TRMM_SPECIALIZE(double, false)
+EIGEN_BLAS_TRMM_SPECIALIZE(dcomplex, true)
+EIGEN_BLAS_TRMM_SPECIALIZE(dcomplex, false)
+EIGEN_BLAS_TRMM_SPECIALIZE(float, true)
+EIGEN_BLAS_TRMM_SPECIALIZE(float, false)
+EIGEN_BLAS_TRMM_SPECIALIZE(scomplex, true)
+EIGEN_BLAS_TRMM_SPECIALIZE(scomplex, false)
+
+// implements col-major += alpha * op(triangular) * op(general)
+#define EIGEN_BLAS_TRMM_L(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \
+template <typename Index, int Mode, \
+ int LhsStorageOrder, bool ConjugateLhs, \
+ int RhsStorageOrder, bool ConjugateRhs> \
+struct product_triangular_matrix_matrix_trmm<EIGTYPE,Index,Mode,true, \
+ LhsStorageOrder,ConjugateLhs,RhsStorageOrder,ConjugateRhs,ColMajor> \
+{ \
+ enum { \
+ IsLower = (Mode&Lower) == Lower, \
+ SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1, \
+ IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \
+ IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \
+ LowUp = IsLower ? Lower : Upper, \
+ conjA = ((LhsStorageOrder==ColMajor) && ConjugateLhs) ? 1 : 0 \
+ }; \
+\
+ static void run( \
+ Index _rows, Index _cols, Index _depth, \
+ const EIGTYPE* _lhs, Index lhsStride, \
+ const EIGTYPE* _rhs, Index rhsStride, \
+ EIGTYPE* res, Index resStride, \
+ EIGTYPE alpha, level3_blocking<EIGTYPE,EIGTYPE>& blocking) \
+ { \
+ Index diagSize = (std::min)(_rows,_depth); \
+ Index rows = IsLower ? _rows : diagSize; \
+ Index depth = IsLower ? diagSize : _depth; \
+ Index cols = _cols; \
+\
+ typedef Matrix<EIGTYPE, Dynamic, Dynamic, LhsStorageOrder> MatrixLhs; \
+ typedef Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder> MatrixRhs; \
+\
+/* Non-square case - doesn't fit to BLAS ?TRMM. Fall to default triangular product or call BLAS ?GEMM*/ \
+ if (rows != depth) { \
+\
+ /* FIXME handle mkl_domain_get_max_threads */ \
+ /*int nthr = mkl_domain_get_max_threads(EIGEN_BLAS_DOMAIN_BLAS);*/ int nthr = 1;\
+\
+ if (((nthr==1) && (((std::max)(rows,depth)-diagSize)/(double)diagSize < 0.5))) { \
+ /* Most likely no benefit to call TRMM or GEMM from BLAS */ \
+ product_triangular_matrix_matrix<EIGTYPE,Index,Mode,true, \
+ LhsStorageOrder,ConjugateLhs, RhsStorageOrder, ConjugateRhs, ColMajor, 1, BuiltIn>::run( \
+ _rows, _cols, _depth, _lhs, lhsStride, _rhs, rhsStride, res, 1, resStride, alpha, blocking); \
+ /*std::cout << "TRMM_L: A is not square! Go to Eigen TRMM implementation!\n";*/ \
+ } else { \
+ /* Make sense to call GEMM */ \
+ Map<const MatrixLhs, 0, OuterStride<> > lhsMap(_lhs,rows,depth,OuterStride<>(lhsStride)); \
+ MatrixLhs aa_tmp=lhsMap.template triangularView<Mode>(); \
+ BlasIndex aStride = convert_index<BlasIndex>(aa_tmp.outerStride()); \
+ gemm_blocking_space<ColMajor,EIGTYPE,EIGTYPE,Dynamic,Dynamic,Dynamic> gemm_blocking(_rows,_cols,_depth, 1, true); \
+ general_matrix_matrix_product<Index,EIGTYPE,LhsStorageOrder,ConjugateLhs,EIGTYPE,RhsStorageOrder,ConjugateRhs,ColMajor,1>::run( \
+ rows, cols, depth, aa_tmp.data(), aStride, _rhs, rhsStride, res, 1, resStride, alpha, gemm_blocking, 0); \
+\
+ /*std::cout << "TRMM_L: A is not square! Go to BLAS GEMM implementation! " << nthr<<" \n";*/ \
+ } \
+ return; \
+ } \
+ char side = 'L', transa, uplo, diag = 'N'; \
+ EIGTYPE *b; \
+ const EIGTYPE *a; \
+ BlasIndex m, n, lda, ldb; \
+\
+/* Set m, n */ \
+ m = convert_index<BlasIndex>(diagSize); \
+ n = convert_index<BlasIndex>(cols); \
+\
+/* Set trans */ \
+ transa = (LhsStorageOrder==RowMajor) ? ((ConjugateLhs) ? 'C' : 'T') : 'N'; \
+\
+/* Set b, ldb */ \
+ Map<const MatrixRhs, 0, OuterStride<> > rhs(_rhs,depth,cols,OuterStride<>(rhsStride)); \
+ MatrixX##EIGPREFIX b_tmp; \
+\
+ if (ConjugateRhs) b_tmp = rhs.conjugate(); else b_tmp = rhs; \
+ b = b_tmp.data(); \
+ ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \
+\
+/* Set uplo */ \
+ uplo = IsLower ? 'L' : 'U'; \
+ if (LhsStorageOrder==RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \
+/* Set a, lda */ \
+ Map<const MatrixLhs, 0, OuterStride<> > lhs(_lhs,rows,depth,OuterStride<>(lhsStride)); \
+ MatrixLhs a_tmp; \
+\
+ if ((conjA!=0) || (SetDiag==0)) { \
+ if (conjA) a_tmp = lhs.conjugate(); else a_tmp = lhs; \
+ if (IsZeroDiag) \
+ a_tmp.diagonal().setZero(); \
+ else if (IsUnitDiag) \
+ a_tmp.diagonal().setOnes();\
+ a = a_tmp.data(); \
+ lda = convert_index<BlasIndex>(a_tmp.outerStride()); \
+ } else { \
+ a = _lhs; \
+ lda = convert_index<BlasIndex>(lhsStride); \
+ } \
+ /*std::cout << "TRMM_L: A is square! Go to BLAS TRMM implementation! \n";*/ \
+/* call ?trmm*/ \
+ BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (BLASTYPE*)b, &ldb); \
+\
+/* Add op(a_triangular)*b into res*/ \
+ Map<MatrixX##EIGPREFIX, 0, OuterStride<> > res_tmp(res,rows,cols,OuterStride<>(resStride)); \
+ res_tmp=res_tmp+b_tmp; \
+ } \
+};
+
+#ifdef EIGEN_USE_MKL
+EIGEN_BLAS_TRMM_L(double, double, d, dtrmm)
+EIGEN_BLAS_TRMM_L(dcomplex, MKL_Complex16, cd, ztrmm)
+EIGEN_BLAS_TRMM_L(float, float, f, strmm)
+EIGEN_BLAS_TRMM_L(scomplex, MKL_Complex8, cf, ctrmm)
+#else
+EIGEN_BLAS_TRMM_L(double, double, d, dtrmm_)
+EIGEN_BLAS_TRMM_L(dcomplex, double, cd, ztrmm_)
+EIGEN_BLAS_TRMM_L(float, float, f, strmm_)
+EIGEN_BLAS_TRMM_L(scomplex, float, cf, ctrmm_)
+#endif
+
+// implements col-major += alpha * op(general) * op(triangular)
+#define EIGEN_BLAS_TRMM_R(EIGTYPE, BLASTYPE, EIGPREFIX, BLASFUNC) \
+template <typename Index, int Mode, \
+ int LhsStorageOrder, bool ConjugateLhs, \
+ int RhsStorageOrder, bool ConjugateRhs> \
+struct product_triangular_matrix_matrix_trmm<EIGTYPE,Index,Mode,false, \
+ LhsStorageOrder,ConjugateLhs,RhsStorageOrder,ConjugateRhs,ColMajor> \
+{ \
+ enum { \
+ IsLower = (Mode&Lower) == Lower, \
+ SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1, \
+ IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \
+ IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \
+ LowUp = IsLower ? Lower : Upper, \
+ conjA = ((RhsStorageOrder==ColMajor) && ConjugateRhs) ? 1 : 0 \
+ }; \
+\
+ static void run( \
+ Index _rows, Index _cols, Index _depth, \
+ const EIGTYPE* _lhs, Index lhsStride, \
+ const EIGTYPE* _rhs, Index rhsStride, \
+ EIGTYPE* res, Index resStride, \
+ EIGTYPE alpha, level3_blocking<EIGTYPE,EIGTYPE>& blocking) \
+ { \
+ Index diagSize = (std::min)(_cols,_depth); \
+ Index rows = _rows; \
+ Index depth = IsLower ? _depth : diagSize; \
+ Index cols = IsLower ? diagSize : _cols; \
+\
+ typedef Matrix<EIGTYPE, Dynamic, Dynamic, LhsStorageOrder> MatrixLhs; \
+ typedef Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder> MatrixRhs; \
+\
+/* Non-square case - doesn't fit to BLAS ?TRMM. Fall to default triangular product or call BLAS ?GEMM*/ \
+ if (cols != depth) { \
+\
+ int nthr = 1 /*mkl_domain_get_max_threads(EIGEN_BLAS_DOMAIN_BLAS)*/; \
+\
+ if ((nthr==1) && (((std::max)(cols,depth)-diagSize)/(double)diagSize < 0.5)) { \
+ /* Most likely no benefit to call TRMM or GEMM from BLAS*/ \
+ product_triangular_matrix_matrix<EIGTYPE,Index,Mode,false, \
+ LhsStorageOrder,ConjugateLhs, RhsStorageOrder, ConjugateRhs, ColMajor, 1, BuiltIn>::run( \
+ _rows, _cols, _depth, _lhs, lhsStride, _rhs, rhsStride, res, 1, resStride, alpha, blocking); \
+ /*std::cout << "TRMM_R: A is not square! Go to Eigen TRMM implementation!\n";*/ \
+ } else { \
+ /* Make sense to call GEMM */ \
+ Map<const MatrixRhs, 0, OuterStride<> > rhsMap(_rhs,depth,cols, OuterStride<>(rhsStride)); \
+ MatrixRhs aa_tmp=rhsMap.template triangularView<Mode>(); \
+ BlasIndex aStride = convert_index<BlasIndex>(aa_tmp.outerStride()); \
+ gemm_blocking_space<ColMajor,EIGTYPE,EIGTYPE,Dynamic,Dynamic,Dynamic> gemm_blocking(_rows,_cols,_depth, 1, true); \
+ general_matrix_matrix_product<Index,EIGTYPE,LhsStorageOrder,ConjugateLhs,EIGTYPE,RhsStorageOrder,ConjugateRhs,ColMajor,1>::run( \
+ rows, cols, depth, _lhs, lhsStride, aa_tmp.data(), aStride, res, 1, resStride, alpha, gemm_blocking, 0); \
+\
+ /*std::cout << "TRMM_R: A is not square! Go to BLAS GEMM implementation! " << nthr<<" \n";*/ \
+ } \
+ return; \
+ } \
+ char side = 'R', transa, uplo, diag = 'N'; \
+ EIGTYPE *b; \
+ const EIGTYPE *a; \
+ BlasIndex m, n, lda, ldb; \
+\
+/* Set m, n */ \
+ m = convert_index<BlasIndex>(rows); \
+ n = convert_index<BlasIndex>(diagSize); \
+\
+/* Set trans */ \
+ transa = (RhsStorageOrder==RowMajor) ? ((ConjugateRhs) ? 'C' : 'T') : 'N'; \
+\
+/* Set b, ldb */ \
+ Map<const MatrixLhs, 0, OuterStride<> > lhs(_lhs,rows,depth,OuterStride<>(lhsStride)); \
+ MatrixX##EIGPREFIX b_tmp; \
+\
+ if (ConjugateLhs) b_tmp = lhs.conjugate(); else b_tmp = lhs; \
+ b = b_tmp.data(); \
+ ldb = convert_index<BlasIndex>(b_tmp.outerStride()); \
+\
+/* Set uplo */ \
+ uplo = IsLower ? 'L' : 'U'; \
+ if (RhsStorageOrder==RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \
+/* Set a, lda */ \
+ Map<const MatrixRhs, 0, OuterStride<> > rhs(_rhs,depth,cols, OuterStride<>(rhsStride)); \
+ MatrixRhs a_tmp; \
+\
+ if ((conjA!=0) || (SetDiag==0)) { \
+ if (conjA) a_tmp = rhs.conjugate(); else a_tmp = rhs; \
+ if (IsZeroDiag) \
+ a_tmp.diagonal().setZero(); \
+ else if (IsUnitDiag) \
+ a_tmp.diagonal().setOnes();\
+ a = a_tmp.data(); \
+ lda = convert_index<BlasIndex>(a_tmp.outerStride()); \
+ } else { \
+ a = _rhs; \
+ lda = convert_index<BlasIndex>(rhsStride); \
+ } \
+ /*std::cout << "TRMM_R: A is square! Go to BLAS TRMM implementation! \n";*/ \
+/* call ?trmm*/ \
+ BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (BLASTYPE*)b, &ldb); \
+\
+/* Add op(a_triangular)*b into res*/ \
+ Map<MatrixX##EIGPREFIX, 0, OuterStride<> > res_tmp(res,rows,cols,OuterStride<>(resStride)); \
+ res_tmp=res_tmp+b_tmp; \
+ } \
+};
+
+#ifdef EIGEN_USE_MKL
+EIGEN_BLAS_TRMM_R(double, double, d, dtrmm)
+EIGEN_BLAS_TRMM_R(dcomplex, MKL_Complex16, cd, ztrmm)
+EIGEN_BLAS_TRMM_R(float, float, f, strmm)
+EIGEN_BLAS_TRMM_R(scomplex, MKL_Complex8, cf, ctrmm)
+#else
+EIGEN_BLAS_TRMM_R(double, double, d, dtrmm_)
+EIGEN_BLAS_TRMM_R(dcomplex, double, cd, ztrmm_)
+EIGEN_BLAS_TRMM_R(float, float, f, strmm_)
+EIGEN_BLAS_TRMM_R(scomplex, float, cf, ctrmm_)
+#endif
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRIANGULAR_MATRIX_MATRIX_BLAS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixVector.h b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixVector.h
new file mode 100644
index 000000000..76bfa159c
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixVector.h
@@ -0,0 +1,350 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TRIANGULARMATRIXVECTOR_H
+#define EIGEN_TRIANGULARMATRIXVECTOR_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs, int StorageOrder, int Version=Specialized>
+struct triangular_matrix_vector_product;
+
+template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs, int Version>
+struct triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,ColMajor,Version>
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
+ enum {
+ IsLower = ((Mode&Lower)==Lower),
+ HasUnitDiag = (Mode & UnitDiag)==UnitDiag,
+ HasZeroDiag = (Mode & ZeroDiag)==ZeroDiag
+ };
+ static EIGEN_DONT_INLINE void run(Index _rows, Index _cols, const LhsScalar* _lhs, Index lhsStride,
+ const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, const RhsScalar& alpha);
+};
+
+template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs, int Version>
+EIGEN_DONT_INLINE void triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,ColMajor,Version>
+ ::run(Index _rows, Index _cols, const LhsScalar* _lhs, Index lhsStride,
+ const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, const RhsScalar& alpha)
+ {
+ static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH;
+ Index size = (std::min)(_rows,_cols);
+ Index rows = IsLower ? _rows : (std::min)(_rows,_cols);
+ Index cols = IsLower ? (std::min)(_rows,_cols) : _cols;
+
+ typedef Map<const Matrix<LhsScalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > LhsMap;
+ const LhsMap lhs(_lhs,rows,cols,OuterStride<>(lhsStride));
+ typename conj_expr_if<ConjLhs,LhsMap>::type cjLhs(lhs);
+
+ typedef Map<const Matrix<RhsScalar,Dynamic,1>, 0, InnerStride<> > RhsMap;
+ const RhsMap rhs(_rhs,cols,InnerStride<>(rhsIncr));
+ typename conj_expr_if<ConjRhs,RhsMap>::type cjRhs(rhs);
+
+ typedef Map<Matrix<ResScalar,Dynamic,1> > ResMap;
+ ResMap res(_res,rows);
+
+ typedef const_blas_data_mapper<LhsScalar,Index,ColMajor> LhsMapper;
+ typedef const_blas_data_mapper<RhsScalar,Index,RowMajor> RhsMapper;
+
+ for (Index pi=0; pi<size; pi+=PanelWidth)
+ {
+ Index actualPanelWidth = (std::min)(PanelWidth, size-pi);
+ for (Index k=0; k<actualPanelWidth; ++k)
+ {
+ Index i = pi + k;
+ Index s = IsLower ? ((HasUnitDiag||HasZeroDiag) ? i+1 : i ) : pi;
+ Index r = IsLower ? actualPanelWidth-k : k+1;
+ if ((!(HasUnitDiag||HasZeroDiag)) || (--r)>0)
+ res.segment(s,r) += (alpha * cjRhs.coeff(i)) * cjLhs.col(i).segment(s,r);
+ if (HasUnitDiag)
+ res.coeffRef(i) += alpha * cjRhs.coeff(i);
+ }
+ Index r = IsLower ? rows - pi - actualPanelWidth : pi;
+ if (r>0)
+ {
+ Index s = IsLower ? pi+actualPanelWidth : 0;
+ general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,ConjLhs,RhsScalar,RhsMapper,ConjRhs,BuiltIn>::run(
+ r, actualPanelWidth,
+ LhsMapper(&lhs.coeffRef(s,pi), lhsStride),
+ RhsMapper(&rhs.coeffRef(pi), rhsIncr),
+ &res.coeffRef(s), resIncr, alpha);
+ }
+ }
+ if((!IsLower) && cols>size)
+ {
+ general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,ConjLhs,RhsScalar,RhsMapper,ConjRhs>::run(
+ rows, cols-size,
+ LhsMapper(&lhs.coeffRef(0,size), lhsStride),
+ RhsMapper(&rhs.coeffRef(size), rhsIncr),
+ _res, resIncr, alpha);
+ }
+ }
+
+template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs,int Version>
+struct triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,RowMajor,Version>
+{
+ typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
+ enum {
+ IsLower = ((Mode&Lower)==Lower),
+ HasUnitDiag = (Mode & UnitDiag)==UnitDiag,
+ HasZeroDiag = (Mode & ZeroDiag)==ZeroDiag
+ };
+ static EIGEN_DONT_INLINE void run(Index _rows, Index _cols, const LhsScalar* _lhs, Index lhsStride,
+ const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, const ResScalar& alpha);
+};
+
+template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs,int Version>
+EIGEN_DONT_INLINE void triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,RowMajor,Version>
+ ::run(Index _rows, Index _cols, const LhsScalar* _lhs, Index lhsStride,
+ const RhsScalar* _rhs, Index rhsIncr, ResScalar* _res, Index resIncr, const ResScalar& alpha)
+ {
+ static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH;
+ Index diagSize = (std::min)(_rows,_cols);
+ Index rows = IsLower ? _rows : diagSize;
+ Index cols = IsLower ? diagSize : _cols;
+
+ typedef Map<const Matrix<LhsScalar,Dynamic,Dynamic,RowMajor>, 0, OuterStride<> > LhsMap;
+ const LhsMap lhs(_lhs,rows,cols,OuterStride<>(lhsStride));
+ typename conj_expr_if<ConjLhs,LhsMap>::type cjLhs(lhs);
+
+ typedef Map<const Matrix<RhsScalar,Dynamic,1> > RhsMap;
+ const RhsMap rhs(_rhs,cols);
+ typename conj_expr_if<ConjRhs,RhsMap>::type cjRhs(rhs);
+
+ typedef Map<Matrix<ResScalar,Dynamic,1>, 0, InnerStride<> > ResMap;
+ ResMap res(_res,rows,InnerStride<>(resIncr));
+
+ typedef const_blas_data_mapper<LhsScalar,Index,RowMajor> LhsMapper;
+ typedef const_blas_data_mapper<RhsScalar,Index,RowMajor> RhsMapper;
+
+ for (Index pi=0; pi<diagSize; pi+=PanelWidth)
+ {
+ Index actualPanelWidth = (std::min)(PanelWidth, diagSize-pi);
+ for (Index k=0; k<actualPanelWidth; ++k)
+ {
+ Index i = pi + k;
+ Index s = IsLower ? pi : ((HasUnitDiag||HasZeroDiag) ? i+1 : i);
+ Index r = IsLower ? k+1 : actualPanelWidth-k;
+ if ((!(HasUnitDiag||HasZeroDiag)) || (--r)>0)
+ res.coeffRef(i) += alpha * (cjLhs.row(i).segment(s,r).cwiseProduct(cjRhs.segment(s,r).transpose())).sum();
+ if (HasUnitDiag)
+ res.coeffRef(i) += alpha * cjRhs.coeff(i);
+ }
+ Index r = IsLower ? pi : cols - pi - actualPanelWidth;
+ if (r>0)
+ {
+ Index s = IsLower ? 0 : pi + actualPanelWidth;
+ general_matrix_vector_product<Index,LhsScalar,LhsMapper,RowMajor,ConjLhs,RhsScalar,RhsMapper,ConjRhs,BuiltIn>::run(
+ actualPanelWidth, r,
+ LhsMapper(&lhs.coeffRef(pi,s), lhsStride),
+ RhsMapper(&rhs.coeffRef(s), rhsIncr),
+ &res.coeffRef(pi), resIncr, alpha);
+ }
+ }
+ if(IsLower && rows>diagSize)
+ {
+ general_matrix_vector_product<Index,LhsScalar,LhsMapper,RowMajor,ConjLhs,RhsScalar,RhsMapper,ConjRhs>::run(
+ rows-diagSize, cols,
+ LhsMapper(&lhs.coeffRef(diagSize,0), lhsStride),
+ RhsMapper(&rhs.coeffRef(0), rhsIncr),
+ &res.coeffRef(diagSize), resIncr, alpha);
+ }
+ }
+
+/***************************************************************************
+* Wrapper to product_triangular_vector
+***************************************************************************/
+
+template<int Mode,int StorageOrder>
+struct trmv_selector;
+
+} // end namespace internal
+
+namespace internal {
+
+template<int Mode, typename Lhs, typename Rhs>
+struct triangular_product_impl<Mode,true,Lhs,false,Rhs,true>
+{
+ template<typename Dest> static void run(Dest& dst, const Lhs &lhs, const Rhs &rhs, const typename Dest::Scalar& alpha)
+ {
+ eigen_assert(dst.rows()==lhs.rows() && dst.cols()==rhs.cols());
+
+ internal::trmv_selector<Mode,(int(internal::traits<Lhs>::Flags)&RowMajorBit) ? RowMajor : ColMajor>::run(lhs, rhs, dst, alpha);
+ }
+};
+
+template<int Mode, typename Lhs, typename Rhs>
+struct triangular_product_impl<Mode,false,Lhs,true,Rhs,false>
+{
+ template<typename Dest> static void run(Dest& dst, const Lhs &lhs, const Rhs &rhs, const typename Dest::Scalar& alpha)
+ {
+ eigen_assert(dst.rows()==lhs.rows() && dst.cols()==rhs.cols());
+
+ Transpose<Dest> dstT(dst);
+ internal::trmv_selector<(Mode & (UnitDiag|ZeroDiag)) | ((Mode & Lower) ? Upper : Lower),
+ (int(internal::traits<Rhs>::Flags)&RowMajorBit) ? ColMajor : RowMajor>
+ ::run(rhs.transpose(),lhs.transpose(), dstT, alpha);
+ }
+};
+
+} // end namespace internal
+
+namespace internal {
+
+// TODO: find a way to factorize this piece of code with gemv_selector since the logic is exactly the same.
+
+template<int Mode> struct trmv_selector<Mode,ColMajor>
+{
+ template<typename Lhs, typename Rhs, typename Dest>
+ static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
+ {
+ typedef typename Lhs::Scalar LhsScalar;
+ typedef typename Rhs::Scalar RhsScalar;
+ typedef typename Dest::Scalar ResScalar;
+ typedef typename Dest::RealScalar RealScalar;
+
+ typedef internal::blas_traits<Lhs> LhsBlasTraits;
+ typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
+ typedef internal::blas_traits<Rhs> RhsBlasTraits;
+ typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
+
+ typedef Map<Matrix<ResScalar,Dynamic,1>, EIGEN_PLAIN_ENUM_MIN(AlignedMax,internal::packet_traits<ResScalar>::size)> MappedDest;
+
+ typename internal::add_const_on_value_type<ActualLhsType>::type actualLhs = LhsBlasTraits::extract(lhs);
+ typename internal::add_const_on_value_type<ActualRhsType>::type actualRhs = RhsBlasTraits::extract(rhs);
+
+ LhsScalar lhs_alpha = LhsBlasTraits::extractScalarFactor(lhs);
+ RhsScalar rhs_alpha = RhsBlasTraits::extractScalarFactor(rhs);
+ ResScalar actualAlpha = alpha * lhs_alpha * rhs_alpha;
+
+ enum {
+ // FIXME find a way to allow an inner stride on the result if packet_traits<Scalar>::size==1
+ // on, the other hand it is good for the cache to pack the vector anyways...
+ EvalToDestAtCompileTime = Dest::InnerStrideAtCompileTime==1,
+ ComplexByReal = (NumTraits<LhsScalar>::IsComplex) && (!NumTraits<RhsScalar>::IsComplex),
+ MightCannotUseDest = (Dest::InnerStrideAtCompileTime!=1) || ComplexByReal
+ };
+
+ gemv_static_vector_if<ResScalar,Dest::SizeAtCompileTime,Dest::MaxSizeAtCompileTime,MightCannotUseDest> static_dest;
+
+ bool alphaIsCompatible = (!ComplexByReal) || (numext::imag(actualAlpha)==RealScalar(0));
+ bool evalToDest = EvalToDestAtCompileTime && alphaIsCompatible;
+
+ RhsScalar compatibleAlpha = get_factor<ResScalar,RhsScalar>::run(actualAlpha);
+
+ ei_declare_aligned_stack_constructed_variable(ResScalar,actualDestPtr,dest.size(),
+ evalToDest ? dest.data() : static_dest.data());
+
+ if(!evalToDest)
+ {
+ #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ Index size = dest.size();
+ EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ #endif
+ if(!alphaIsCompatible)
+ {
+ MappedDest(actualDestPtr, dest.size()).setZero();
+ compatibleAlpha = RhsScalar(1);
+ }
+ else
+ MappedDest(actualDestPtr, dest.size()) = dest;
+ }
+
+ internal::triangular_matrix_vector_product
+ <Index,Mode,
+ LhsScalar, LhsBlasTraits::NeedToConjugate,
+ RhsScalar, RhsBlasTraits::NeedToConjugate,
+ ColMajor>
+ ::run(actualLhs.rows(),actualLhs.cols(),
+ actualLhs.data(),actualLhs.outerStride(),
+ actualRhs.data(),actualRhs.innerStride(),
+ actualDestPtr,1,compatibleAlpha);
+
+ if (!evalToDest)
+ {
+ if(!alphaIsCompatible)
+ dest += actualAlpha * MappedDest(actualDestPtr, dest.size());
+ else
+ dest = MappedDest(actualDestPtr, dest.size());
+ }
+
+ if ( ((Mode&UnitDiag)==UnitDiag) && (lhs_alpha!=LhsScalar(1)) )
+ {
+ Index diagSize = (std::min)(lhs.rows(),lhs.cols());
+ dest.head(diagSize) -= (lhs_alpha-LhsScalar(1))*rhs.head(diagSize);
+ }
+ }
+};
+
+template<int Mode> struct trmv_selector<Mode,RowMajor>
+{
+ template<typename Lhs, typename Rhs, typename Dest>
+ static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
+ {
+ typedef typename Lhs::Scalar LhsScalar;
+ typedef typename Rhs::Scalar RhsScalar;
+ typedef typename Dest::Scalar ResScalar;
+
+ typedef internal::blas_traits<Lhs> LhsBlasTraits;
+ typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
+ typedef internal::blas_traits<Rhs> RhsBlasTraits;
+ typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
+ typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned;
+
+ typename add_const<ActualLhsType>::type actualLhs = LhsBlasTraits::extract(lhs);
+ typename add_const<ActualRhsType>::type actualRhs = RhsBlasTraits::extract(rhs);
+
+ LhsScalar lhs_alpha = LhsBlasTraits::extractScalarFactor(lhs);
+ RhsScalar rhs_alpha = RhsBlasTraits::extractScalarFactor(rhs);
+ ResScalar actualAlpha = alpha * lhs_alpha * rhs_alpha;
+
+ enum {
+ DirectlyUseRhs = ActualRhsTypeCleaned::InnerStrideAtCompileTime==1
+ };
+
+ gemv_static_vector_if<RhsScalar,ActualRhsTypeCleaned::SizeAtCompileTime,ActualRhsTypeCleaned::MaxSizeAtCompileTime,!DirectlyUseRhs> static_rhs;
+
+ ei_declare_aligned_stack_constructed_variable(RhsScalar,actualRhsPtr,actualRhs.size(),
+ DirectlyUseRhs ? const_cast<RhsScalar*>(actualRhs.data()) : static_rhs.data());
+
+ if(!DirectlyUseRhs)
+ {
+ #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ Index size = actualRhs.size();
+ EIGEN_DENSE_STORAGE_CTOR_PLUGIN
+ #endif
+ Map<typename ActualRhsTypeCleaned::PlainObject>(actualRhsPtr, actualRhs.size()) = actualRhs;
+ }
+
+ internal::triangular_matrix_vector_product
+ <Index,Mode,
+ LhsScalar, LhsBlasTraits::NeedToConjugate,
+ RhsScalar, RhsBlasTraits::NeedToConjugate,
+ RowMajor>
+ ::run(actualLhs.rows(),actualLhs.cols(),
+ actualLhs.data(),actualLhs.outerStride(),
+ actualRhsPtr,1,
+ dest.data(),dest.innerStride(),
+ actualAlpha);
+
+ if ( ((Mode&UnitDiag)==UnitDiag) && (lhs_alpha!=LhsScalar(1)) )
+ {
+ Index diagSize = (std::min)(lhs.rows(),lhs.cols());
+ dest.head(diagSize) -= (lhs_alpha-LhsScalar(1))*rhs.head(diagSize);
+ }
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRIANGULARMATRIXVECTOR_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h
new file mode 100644
index 000000000..3d47a2b94
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h
@@ -0,0 +1,255 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to BLAS F77
+ * Triangular matrix-vector product functionality based on ?TRMV.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_TRIANGULAR_MATRIX_VECTOR_BLAS_H
+#define EIGEN_TRIANGULAR_MATRIX_VECTOR_BLAS_H
+
+namespace Eigen {
+
+namespace internal {
+
+/**********************************************************************
+* This file implements triangular matrix-vector multiplication using BLAS
+**********************************************************************/
+
+// trmv/hemv specialization
+
+template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs, int StorageOrder>
+struct triangular_matrix_vector_product_trmv :
+ triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,StorageOrder,BuiltIn> {};
+
+#define EIGEN_BLAS_TRMV_SPECIALIZE(Scalar) \
+template<typename Index, int Mode, bool ConjLhs, bool ConjRhs> \
+struct triangular_matrix_vector_product<Index,Mode,Scalar,ConjLhs,Scalar,ConjRhs,ColMajor,Specialized> { \
+ static void run(Index _rows, Index _cols, const Scalar* _lhs, Index lhsStride, \
+ const Scalar* _rhs, Index rhsIncr, Scalar* _res, Index resIncr, Scalar alpha) { \
+ triangular_matrix_vector_product_trmv<Index,Mode,Scalar,ConjLhs,Scalar,ConjRhs,ColMajor>::run( \
+ _rows, _cols, _lhs, lhsStride, _rhs, rhsIncr, _res, resIncr, alpha); \
+ } \
+}; \
+template<typename Index, int Mode, bool ConjLhs, bool ConjRhs> \
+struct triangular_matrix_vector_product<Index,Mode,Scalar,ConjLhs,Scalar,ConjRhs,RowMajor,Specialized> { \
+ static void run(Index _rows, Index _cols, const Scalar* _lhs, Index lhsStride, \
+ const Scalar* _rhs, Index rhsIncr, Scalar* _res, Index resIncr, Scalar alpha) { \
+ triangular_matrix_vector_product_trmv<Index,Mode,Scalar,ConjLhs,Scalar,ConjRhs,RowMajor>::run( \
+ _rows, _cols, _lhs, lhsStride, _rhs, rhsIncr, _res, resIncr, alpha); \
+ } \
+};
+
+EIGEN_BLAS_TRMV_SPECIALIZE(double)
+EIGEN_BLAS_TRMV_SPECIALIZE(float)
+EIGEN_BLAS_TRMV_SPECIALIZE(dcomplex)
+EIGEN_BLAS_TRMV_SPECIALIZE(scomplex)
+
+// implements col-major: res += alpha * op(triangular) * vector
+#define EIGEN_BLAS_TRMV_CM(EIGTYPE, BLASTYPE, EIGPREFIX, BLASPREFIX, BLASPOSTFIX) \
+template<typename Index, int Mode, bool ConjLhs, bool ConjRhs> \
+struct triangular_matrix_vector_product_trmv<Index,Mode,EIGTYPE,ConjLhs,EIGTYPE,ConjRhs,ColMajor> { \
+ enum { \
+ IsLower = (Mode&Lower) == Lower, \
+ SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1, \
+ IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \
+ IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \
+ LowUp = IsLower ? Lower : Upper \
+ }; \
+ static void run(Index _rows, Index _cols, const EIGTYPE* _lhs, Index lhsStride, \
+ const EIGTYPE* _rhs, Index rhsIncr, EIGTYPE* _res, Index resIncr, EIGTYPE alpha) \
+ { \
+ if (ConjLhs || IsZeroDiag) { \
+ triangular_matrix_vector_product<Index,Mode,EIGTYPE,ConjLhs,EIGTYPE,ConjRhs,ColMajor,BuiltIn>::run( \
+ _rows, _cols, _lhs, lhsStride, _rhs, rhsIncr, _res, resIncr, alpha); \
+ return; \
+ }\
+ Index size = (std::min)(_rows,_cols); \
+ Index rows = IsLower ? _rows : size; \
+ Index cols = IsLower ? size : _cols; \
+\
+ typedef VectorX##EIGPREFIX VectorRhs; \
+ EIGTYPE *x, *y;\
+\
+/* Set x*/ \
+ Map<const VectorRhs, 0, InnerStride<> > rhs(_rhs,cols,InnerStride<>(rhsIncr)); \
+ VectorRhs x_tmp; \
+ if (ConjRhs) x_tmp = rhs.conjugate(); else x_tmp = rhs; \
+ x = x_tmp.data(); \
+\
+/* Square part handling */\
+\
+ char trans, uplo, diag; \
+ BlasIndex m, n, lda, incx, incy; \
+ EIGTYPE const *a; \
+ EIGTYPE beta(1); \
+\
+/* Set m, n */ \
+ n = convert_index<BlasIndex>(size); \
+ lda = convert_index<BlasIndex>(lhsStride); \
+ incx = 1; \
+ incy = convert_index<BlasIndex>(resIncr); \
+\
+/* Set uplo, trans and diag*/ \
+ trans = 'N'; \
+ uplo = IsLower ? 'L' : 'U'; \
+ diag = IsUnitDiag ? 'U' : 'N'; \
+\
+/* call ?TRMV*/ \
+ BLASPREFIX##trmv##BLASPOSTFIX(&uplo, &trans, &diag, &n, (const BLASTYPE*)_lhs, &lda, (BLASTYPE*)x, &incx); \
+\
+/* Add op(a_tr)rhs into res*/ \
+ BLASPREFIX##axpy##BLASPOSTFIX(&n, (const BLASTYPE*)&numext::real_ref(alpha),(const BLASTYPE*)x, &incx, (BLASTYPE*)_res, &incy); \
+/* Non-square case - doesn't fit to BLAS ?TRMV. Fall to default triangular product*/ \
+ if (size<(std::max)(rows,cols)) { \
+ if (ConjRhs) x_tmp = rhs.conjugate(); else x_tmp = rhs; \
+ x = x_tmp.data(); \
+ if (size<rows) { \
+ y = _res + size*resIncr; \
+ a = _lhs + size; \
+ m = convert_index<BlasIndex>(rows-size); \
+ n = convert_index<BlasIndex>(size); \
+ } \
+ else { \
+ x += size; \
+ y = _res; \
+ a = _lhs + size*lda; \
+ m = convert_index<BlasIndex>(size); \
+ n = convert_index<BlasIndex>(cols-size); \
+ } \
+ BLASPREFIX##gemv##BLASPOSTFIX(&trans, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)x, &incx, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)y, &incy); \
+ } \
+ } \
+};
+
+#ifdef EIGEN_USE_MKL
+EIGEN_BLAS_TRMV_CM(double, double, d, d,)
+EIGEN_BLAS_TRMV_CM(dcomplex, MKL_Complex16, cd, z,)
+EIGEN_BLAS_TRMV_CM(float, float, f, s,)
+EIGEN_BLAS_TRMV_CM(scomplex, MKL_Complex8, cf, c,)
+#else
+EIGEN_BLAS_TRMV_CM(double, double, d, d, _)
+EIGEN_BLAS_TRMV_CM(dcomplex, double, cd, z, _)
+EIGEN_BLAS_TRMV_CM(float, float, f, s, _)
+EIGEN_BLAS_TRMV_CM(scomplex, float, cf, c, _)
+#endif
+
+// implements row-major: res += alpha * op(triangular) * vector
+#define EIGEN_BLAS_TRMV_RM(EIGTYPE, BLASTYPE, EIGPREFIX, BLASPREFIX, BLASPOSTFIX) \
+template<typename Index, int Mode, bool ConjLhs, bool ConjRhs> \
+struct triangular_matrix_vector_product_trmv<Index,Mode,EIGTYPE,ConjLhs,EIGTYPE,ConjRhs,RowMajor> { \
+ enum { \
+ IsLower = (Mode&Lower) == Lower, \
+ SetDiag = (Mode&(ZeroDiag|UnitDiag)) ? 0 : 1, \
+ IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \
+ IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \
+ LowUp = IsLower ? Lower : Upper \
+ }; \
+ static void run(Index _rows, Index _cols, const EIGTYPE* _lhs, Index lhsStride, \
+ const EIGTYPE* _rhs, Index rhsIncr, EIGTYPE* _res, Index resIncr, EIGTYPE alpha) \
+ { \
+ if (IsZeroDiag) { \
+ triangular_matrix_vector_product<Index,Mode,EIGTYPE,ConjLhs,EIGTYPE,ConjRhs,RowMajor,BuiltIn>::run( \
+ _rows, _cols, _lhs, lhsStride, _rhs, rhsIncr, _res, resIncr, alpha); \
+ return; \
+ }\
+ Index size = (std::min)(_rows,_cols); \
+ Index rows = IsLower ? _rows : size; \
+ Index cols = IsLower ? size : _cols; \
+\
+ typedef VectorX##EIGPREFIX VectorRhs; \
+ EIGTYPE *x, *y;\
+\
+/* Set x*/ \
+ Map<const VectorRhs, 0, InnerStride<> > rhs(_rhs,cols,InnerStride<>(rhsIncr)); \
+ VectorRhs x_tmp; \
+ if (ConjRhs) x_tmp = rhs.conjugate(); else x_tmp = rhs; \
+ x = x_tmp.data(); \
+\
+/* Square part handling */\
+\
+ char trans, uplo, diag; \
+ BlasIndex m, n, lda, incx, incy; \
+ EIGTYPE const *a; \
+ EIGTYPE beta(1); \
+\
+/* Set m, n */ \
+ n = convert_index<BlasIndex>(size); \
+ lda = convert_index<BlasIndex>(lhsStride); \
+ incx = 1; \
+ incy = convert_index<BlasIndex>(resIncr); \
+\
+/* Set uplo, trans and diag*/ \
+ trans = ConjLhs ? 'C' : 'T'; \
+ uplo = IsLower ? 'U' : 'L'; \
+ diag = IsUnitDiag ? 'U' : 'N'; \
+\
+/* call ?TRMV*/ \
+ BLASPREFIX##trmv##BLASPOSTFIX(&uplo, &trans, &diag, &n, (const BLASTYPE*)_lhs, &lda, (BLASTYPE*)x, &incx); \
+\
+/* Add op(a_tr)rhs into res*/ \
+ BLASPREFIX##axpy##BLASPOSTFIX(&n, (const BLASTYPE*)&numext::real_ref(alpha),(const BLASTYPE*)x, &incx, (BLASTYPE*)_res, &incy); \
+/* Non-square case - doesn't fit to BLAS ?TRMV. Fall to default triangular product*/ \
+ if (size<(std::max)(rows,cols)) { \
+ if (ConjRhs) x_tmp = rhs.conjugate(); else x_tmp = rhs; \
+ x = x_tmp.data(); \
+ if (size<rows) { \
+ y = _res + size*resIncr; \
+ a = _lhs + size*lda; \
+ m = convert_index<BlasIndex>(rows-size); \
+ n = convert_index<BlasIndex>(size); \
+ } \
+ else { \
+ x += size; \
+ y = _res; \
+ a = _lhs + size; \
+ m = convert_index<BlasIndex>(size); \
+ n = convert_index<BlasIndex>(cols-size); \
+ } \
+ BLASPREFIX##gemv##BLASPOSTFIX(&trans, &n, &m, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)x, &incx, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)y, &incy); \
+ } \
+ } \
+};
+
+#ifdef EIGEN_USE_MKL
+EIGEN_BLAS_TRMV_RM(double, double, d, d,)
+EIGEN_BLAS_TRMV_RM(dcomplex, MKL_Complex16, cd, z,)
+EIGEN_BLAS_TRMV_RM(float, float, f, s,)
+EIGEN_BLAS_TRMV_RM(scomplex, MKL_Complex8, cf, c,)
+#else
+EIGEN_BLAS_TRMV_RM(double, double, d, d,_)
+EIGEN_BLAS_TRMV_RM(dcomplex, double, cd, z,_)
+EIGEN_BLAS_TRMV_RM(float, float, f, s,_)
+EIGEN_BLAS_TRMV_RM(scomplex, float, cf, c,_)
+#endif
+
+} // end namespase internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRIANGULAR_MATRIX_VECTOR_BLAS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h
new file mode 100644
index 000000000..6d879ba00
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h
@@ -0,0 +1,337 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TRIANGULAR_SOLVER_MATRIX_H
+#define EIGEN_TRIANGULAR_SOLVER_MATRIX_H
+
+namespace Eigen {
+
+namespace internal {
+
+// if the rhs is row major, let's transpose the product
+template <typename Scalar, typename Index, int Side, int Mode, bool Conjugate, int TriStorageOrder, int OtherInnerStride>
+struct triangular_solve_matrix<Scalar,Index,Side,Mode,Conjugate,TriStorageOrder,RowMajor,OtherInnerStride>
+{
+ static void run(
+ Index size, Index cols,
+ const Scalar* tri, Index triStride,
+ Scalar* _other, Index otherIncr, Index otherStride,
+ level3_blocking<Scalar,Scalar>& blocking)
+ {
+ triangular_solve_matrix<
+ Scalar, Index, Side==OnTheLeft?OnTheRight:OnTheLeft,
+ (Mode&UnitDiag) | ((Mode&Upper) ? Lower : Upper),
+ NumTraits<Scalar>::IsComplex && Conjugate,
+ TriStorageOrder==RowMajor ? ColMajor : RowMajor, ColMajor, OtherInnerStride>
+ ::run(size, cols, tri, triStride, _other, otherIncr, otherStride, blocking);
+ }
+};
+
+/* Optimized triangular solver with multiple right hand side and the triangular matrix on the left
+ */
+template <typename Scalar, typename Index, int Mode, bool Conjugate, int TriStorageOrder,int OtherInnerStride>
+struct triangular_solve_matrix<Scalar,Index,OnTheLeft,Mode,Conjugate,TriStorageOrder,ColMajor,OtherInnerStride>
+{
+ static EIGEN_DONT_INLINE void run(
+ Index size, Index otherSize,
+ const Scalar* _tri, Index triStride,
+ Scalar* _other, Index otherIncr, Index otherStride,
+ level3_blocking<Scalar,Scalar>& blocking);
+};
+template <typename Scalar, typename Index, int Mode, bool Conjugate, int TriStorageOrder, int OtherInnerStride>
+EIGEN_DONT_INLINE void triangular_solve_matrix<Scalar,Index,OnTheLeft,Mode,Conjugate,TriStorageOrder,ColMajor,OtherInnerStride>::run(
+ Index size, Index otherSize,
+ const Scalar* _tri, Index triStride,
+ Scalar* _other, Index otherIncr, Index otherStride,
+ level3_blocking<Scalar,Scalar>& blocking)
+ {
+ Index cols = otherSize;
+
+ typedef const_blas_data_mapper<Scalar, Index, TriStorageOrder> TriMapper;
+ typedef blas_data_mapper<Scalar, Index, ColMajor, Unaligned, OtherInnerStride> OtherMapper;
+ TriMapper tri(_tri, triStride);
+ OtherMapper other(_other, otherStride, otherIncr);
+
+ typedef gebp_traits<Scalar,Scalar> Traits;
+
+ enum {
+ SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr),
+ IsLower = (Mode&Lower) == Lower
+ };
+
+ Index kc = blocking.kc(); // cache block size along the K direction
+ Index mc = (std::min)(size,blocking.mc()); // cache block size along the M direction
+
+ std::size_t sizeA = kc*mc;
+ std::size_t sizeB = kc*cols;
+
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA());
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB());
+
+ conj_if<Conjugate> conj;
+ gebp_kernel<Scalar, Scalar, Index, OtherMapper, Traits::mr, Traits::nr, Conjugate, false> gebp_kernel;
+ gemm_pack_lhs<Scalar, Index, TriMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, TriStorageOrder> pack_lhs;
+ gemm_pack_rhs<Scalar, Index, OtherMapper, Traits::nr, ColMajor, false, true> pack_rhs;
+
+ // the goal here is to subdivise the Rhs panels such that we keep some cache
+ // coherence when accessing the rhs elements
+ std::ptrdiff_t l1, l2, l3;
+ manage_caching_sizes(GetAction, &l1, &l2, &l3);
+ Index subcols = cols>0 ? l2/(4 * sizeof(Scalar) * std::max<Index>(otherStride,size)) : 0;
+ subcols = std::max<Index>((subcols/Traits::nr)*Traits::nr, Traits::nr);
+
+ for(Index k2=IsLower ? 0 : size;
+ IsLower ? k2<size : k2>0;
+ IsLower ? k2+=kc : k2-=kc)
+ {
+ const Index actual_kc = (std::min)(IsLower ? size-k2 : k2, kc);
+
+ // We have selected and packed a big horizontal panel R1 of rhs. Let B be the packed copy of this panel,
+ // and R2 the remaining part of rhs. The corresponding vertical panel of lhs is split into
+ // A11 (the triangular part) and A21 the remaining rectangular part.
+ // Then the high level algorithm is:
+ // - B = R1 => general block copy (done during the next step)
+ // - R1 = A11^-1 B => tricky part
+ // - update B from the new R1 => actually this has to be performed continuously during the above step
+ // - R2 -= A21 * B => GEPP
+
+ // The tricky part: compute R1 = A11^-1 B while updating B from R1
+ // The idea is to split A11 into multiple small vertical panels.
+ // Each panel can be split into a small triangular part T1k which is processed without optimization,
+ // and the remaining small part T2k which is processed using gebp with appropriate block strides
+ for(Index j2=0; j2<cols; j2+=subcols)
+ {
+ Index actual_cols = (std::min)(cols-j2,subcols);
+ // for each small vertical panels [T1k^T, T2k^T]^T of lhs
+ for (Index k1=0; k1<actual_kc; k1+=SmallPanelWidth)
+ {
+ Index actualPanelWidth = std::min<Index>(actual_kc-k1, SmallPanelWidth);
+ // tr solve
+ for (Index k=0; k<actualPanelWidth; ++k)
+ {
+ // TODO write a small kernel handling this (can be shared with trsv)
+ Index i = IsLower ? k2+k1+k : k2-k1-k-1;
+ Index rs = actualPanelWidth - k - 1; // remaining size
+ Index s = TriStorageOrder==RowMajor ? (IsLower ? k2+k1 : i+1)
+ : IsLower ? i+1 : i-rs;
+
+ Scalar a = (Mode & UnitDiag) ? Scalar(1) : Scalar(1)/conj(tri(i,i));
+ for (Index j=j2; j<j2+actual_cols; ++j)
+ {
+ if (TriStorageOrder==RowMajor)
+ {
+ Scalar b(0);
+ const Scalar* l = &tri(i,s);
+ typename OtherMapper::LinearMapper r = other.getLinearMapper(s,j);
+ for (Index i3=0; i3<k; ++i3)
+ b += conj(l[i3]) * r(i3);
+
+ other(i,j) = (other(i,j) - b)*a;
+ }
+ else
+ {
+ Scalar& otherij = other(i,j);
+ otherij *= a;
+ Scalar b = otherij;
+ typename OtherMapper::LinearMapper r = other.getLinearMapper(s,j);
+ typename TriMapper::LinearMapper l = tri.getLinearMapper(s,i);
+ for (Index i3=0;i3<rs;++i3)
+ r(i3) -= b * conj(l(i3));
+ }
+ }
+ }
+
+ Index lengthTarget = actual_kc-k1-actualPanelWidth;
+ Index startBlock = IsLower ? k2+k1 : k2-k1-actualPanelWidth;
+ Index blockBOffset = IsLower ? k1 : lengthTarget;
+
+ // update the respective rows of B from other
+ pack_rhs(blockB+actual_kc*j2, other.getSubMapper(startBlock,j2), actualPanelWidth, actual_cols, actual_kc, blockBOffset);
+
+ // GEBP
+ if (lengthTarget>0)
+ {
+ Index startTarget = IsLower ? k2+k1+actualPanelWidth : k2-actual_kc;
+
+ pack_lhs(blockA, tri.getSubMapper(startTarget,startBlock), actualPanelWidth, lengthTarget);
+
+ gebp_kernel(other.getSubMapper(startTarget,j2), blockA, blockB+actual_kc*j2, lengthTarget, actualPanelWidth, actual_cols, Scalar(-1),
+ actualPanelWidth, actual_kc, 0, blockBOffset);
+ }
+ }
+ }
+
+ // R2 -= A21 * B => GEPP
+ {
+ Index start = IsLower ? k2+kc : 0;
+ Index end = IsLower ? size : k2-kc;
+ for(Index i2=start; i2<end; i2+=mc)
+ {
+ const Index actual_mc = (std::min)(mc,end-i2);
+ if (actual_mc>0)
+ {
+ pack_lhs(blockA, tri.getSubMapper(i2, IsLower ? k2 : k2-kc), actual_kc, actual_mc);
+
+ gebp_kernel(other.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc, cols, Scalar(-1), -1, -1, 0, 0);
+ }
+ }
+ }
+ }
+ }
+
+/* Optimized triangular solver with multiple left hand sides and the triangular matrix on the right
+ */
+template <typename Scalar, typename Index, int Mode, bool Conjugate, int TriStorageOrder, int OtherInnerStride>
+struct triangular_solve_matrix<Scalar,Index,OnTheRight,Mode,Conjugate,TriStorageOrder,ColMajor,OtherInnerStride>
+{
+ static EIGEN_DONT_INLINE void run(
+ Index size, Index otherSize,
+ const Scalar* _tri, Index triStride,
+ Scalar* _other, Index otherIncr, Index otherStride,
+ level3_blocking<Scalar,Scalar>& blocking);
+};
+template <typename Scalar, typename Index, int Mode, bool Conjugate, int TriStorageOrder, int OtherInnerStride>
+EIGEN_DONT_INLINE void triangular_solve_matrix<Scalar,Index,OnTheRight,Mode,Conjugate,TriStorageOrder,ColMajor,OtherInnerStride>::run(
+ Index size, Index otherSize,
+ const Scalar* _tri, Index triStride,
+ Scalar* _other, Index otherIncr, Index otherStride,
+ level3_blocking<Scalar,Scalar>& blocking)
+ {
+ Index rows = otherSize;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ typedef blas_data_mapper<Scalar, Index, ColMajor, Unaligned, OtherInnerStride> LhsMapper;
+ typedef const_blas_data_mapper<Scalar, Index, TriStorageOrder> RhsMapper;
+ LhsMapper lhs(_other, otherStride, otherIncr);
+ RhsMapper rhs(_tri, triStride);
+
+ typedef gebp_traits<Scalar,Scalar> Traits;
+ enum {
+ RhsStorageOrder = TriStorageOrder,
+ SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr),
+ IsLower = (Mode&Lower) == Lower
+ };
+
+ Index kc = blocking.kc(); // cache block size along the K direction
+ Index mc = (std::min)(rows,blocking.mc()); // cache block size along the M direction
+
+ std::size_t sizeA = kc*mc;
+ std::size_t sizeB = kc*size;
+
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA());
+ ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB());
+
+ conj_if<Conjugate> conj;
+ gebp_kernel<Scalar, Scalar, Index, LhsMapper, Traits::mr, Traits::nr, false, Conjugate> gebp_kernel;
+ gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr, RhsStorageOrder> pack_rhs;
+ gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr, RhsStorageOrder,false,true> pack_rhs_panel;
+ gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, ColMajor, false, true> pack_lhs_panel;
+
+ for(Index k2=IsLower ? size : 0;
+ IsLower ? k2>0 : k2<size;
+ IsLower ? k2-=kc : k2+=kc)
+ {
+ const Index actual_kc = (std::min)(IsLower ? k2 : size-k2, kc);
+ Index actual_k2 = IsLower ? k2-actual_kc : k2 ;
+
+ Index startPanel = IsLower ? 0 : k2+actual_kc;
+ Index rs = IsLower ? actual_k2 : size - actual_k2 - actual_kc;
+ Scalar* geb = blockB+actual_kc*actual_kc;
+
+ if (rs>0) pack_rhs(geb, rhs.getSubMapper(actual_k2,startPanel), actual_kc, rs);
+
+ // triangular packing (we only pack the panels off the diagonal,
+ // neglecting the blocks overlapping the diagonal
+ {
+ for (Index j2=0; j2<actual_kc; j2+=SmallPanelWidth)
+ {
+ Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
+ Index actual_j2 = actual_k2 + j2;
+ Index panelOffset = IsLower ? j2+actualPanelWidth : 0;
+ Index panelLength = IsLower ? actual_kc-j2-actualPanelWidth : j2;
+
+ if (panelLength>0)
+ pack_rhs_panel(blockB+j2*actual_kc,
+ rhs.getSubMapper(actual_k2+panelOffset, actual_j2),
+ panelLength, actualPanelWidth,
+ actual_kc, panelOffset);
+ }
+ }
+
+ for(Index i2=0; i2<rows; i2+=mc)
+ {
+ const Index actual_mc = (std::min)(mc,rows-i2);
+
+ // triangular solver kernel
+ {
+ // for each small block of the diagonal (=> vertical panels of rhs)
+ for (Index j2 = IsLower
+ ? (actual_kc - ((actual_kc%SmallPanelWidth) ? Index(actual_kc%SmallPanelWidth)
+ : Index(SmallPanelWidth)))
+ : 0;
+ IsLower ? j2>=0 : j2<actual_kc;
+ IsLower ? j2-=SmallPanelWidth : j2+=SmallPanelWidth)
+ {
+ Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
+ Index absolute_j2 = actual_k2 + j2;
+ Index panelOffset = IsLower ? j2+actualPanelWidth : 0;
+ Index panelLength = IsLower ? actual_kc - j2 - actualPanelWidth : j2;
+
+ // GEBP
+ if(panelLength>0)
+ {
+ gebp_kernel(lhs.getSubMapper(i2,absolute_j2),
+ blockA, blockB+j2*actual_kc,
+ actual_mc, panelLength, actualPanelWidth,
+ Scalar(-1),
+ actual_kc, actual_kc, // strides
+ panelOffset, panelOffset); // offsets
+ }
+
+ // unblocked triangular solve
+ for (Index k=0; k<actualPanelWidth; ++k)
+ {
+ Index j = IsLower ? absolute_j2+actualPanelWidth-k-1 : absolute_j2+k;
+
+ typename LhsMapper::LinearMapper r = lhs.getLinearMapper(i2,j);
+ for (Index k3=0; k3<k; ++k3)
+ {
+ Scalar b = conj(rhs(IsLower ? j+1+k3 : absolute_j2+k3,j));
+ typename LhsMapper::LinearMapper a = lhs.getLinearMapper(i2,IsLower ? j+1+k3 : absolute_j2+k3);
+ for (Index i=0; i<actual_mc; ++i)
+ r(i) -= a(i) * b;
+ }
+ if((Mode & UnitDiag)==0)
+ {
+ Scalar inv_rjj = RealScalar(1)/conj(rhs(j,j));
+ for (Index i=0; i<actual_mc; ++i)
+ r(i) *= inv_rjj;
+ }
+ }
+
+ // pack the just computed part of lhs to A
+ pack_lhs_panel(blockA, lhs.getSubMapper(i2,absolute_j2),
+ actualPanelWidth, actual_mc,
+ actual_kc, j2);
+ }
+ }
+
+ if (rs>0)
+ gebp_kernel(lhs.getSubMapper(i2, startPanel), blockA, geb,
+ actual_mc, actual_kc, rs, Scalar(-1),
+ -1, -1, 0, 0);
+ }
+ }
+ }
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRIANGULAR_SOLVER_MATRIX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h
new file mode 100644
index 000000000..621194ce6
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h
@@ -0,0 +1,167 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to BLAS F77
+ * Triangular matrix * matrix product functionality based on ?TRMM.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H
+#define EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H
+
+namespace Eigen {
+
+namespace internal {
+
+// implements LeftSide op(triangular)^-1 * general
+#define EIGEN_BLAS_TRSM_L(EIGTYPE, BLASTYPE, BLASFUNC) \
+template <typename Index, int Mode, bool Conjugate, int TriStorageOrder> \
+struct triangular_solve_matrix<EIGTYPE,Index,OnTheLeft,Mode,Conjugate,TriStorageOrder,ColMajor,1> \
+{ \
+ enum { \
+ IsLower = (Mode&Lower) == Lower, \
+ IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \
+ IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \
+ conjA = ((TriStorageOrder==ColMajor) && Conjugate) ? 1 : 0 \
+ }; \
+ static void run( \
+ Index size, Index otherSize, \
+ const EIGTYPE* _tri, Index triStride, \
+ EIGTYPE* _other, Index otherIncr, Index otherStride, level3_blocking<EIGTYPE,EIGTYPE>& /*blocking*/) \
+ { \
+ EIGEN_ONLY_USED_FOR_DEBUG(otherIncr); \
+ eigen_assert(otherIncr == 1); \
+ BlasIndex m = convert_index<BlasIndex>(size), n = convert_index<BlasIndex>(otherSize), lda, ldb; \
+ char side = 'L', uplo, diag='N', transa; \
+ /* Set alpha_ */ \
+ EIGTYPE alpha(1); \
+ ldb = convert_index<BlasIndex>(otherStride);\
+\
+ const EIGTYPE *a; \
+/* Set trans */ \
+ transa = (TriStorageOrder==RowMajor) ? ((Conjugate) ? 'C' : 'T') : 'N'; \
+/* Set uplo */ \
+ uplo = IsLower ? 'L' : 'U'; \
+ if (TriStorageOrder==RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \
+/* Set a, lda */ \
+ typedef Matrix<EIGTYPE, Dynamic, Dynamic, TriStorageOrder> MatrixTri; \
+ Map<const MatrixTri, 0, OuterStride<> > tri(_tri,size,size,OuterStride<>(triStride)); \
+ MatrixTri a_tmp; \
+\
+ if (conjA) { \
+ a_tmp = tri.conjugate(); \
+ a = a_tmp.data(); \
+ lda = convert_index<BlasIndex>(a_tmp.outerStride()); \
+ } else { \
+ a = _tri; \
+ lda = convert_index<BlasIndex>(triStride); \
+ } \
+ if (IsUnitDiag) diag='U'; \
+/* call ?trsm*/ \
+ BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (BLASTYPE*)_other, &ldb); \
+ } \
+};
+
+#ifdef EIGEN_USE_MKL
+EIGEN_BLAS_TRSM_L(double, double, dtrsm)
+EIGEN_BLAS_TRSM_L(dcomplex, MKL_Complex16, ztrsm)
+EIGEN_BLAS_TRSM_L(float, float, strsm)
+EIGEN_BLAS_TRSM_L(scomplex, MKL_Complex8, ctrsm)
+#else
+EIGEN_BLAS_TRSM_L(double, double, dtrsm_)
+EIGEN_BLAS_TRSM_L(dcomplex, double, ztrsm_)
+EIGEN_BLAS_TRSM_L(float, float, strsm_)
+EIGEN_BLAS_TRSM_L(scomplex, float, ctrsm_)
+#endif
+
+// implements RightSide general * op(triangular)^-1
+#define EIGEN_BLAS_TRSM_R(EIGTYPE, BLASTYPE, BLASFUNC) \
+template <typename Index, int Mode, bool Conjugate, int TriStorageOrder> \
+struct triangular_solve_matrix<EIGTYPE,Index,OnTheRight,Mode,Conjugate,TriStorageOrder,ColMajor,1> \
+{ \
+ enum { \
+ IsLower = (Mode&Lower) == Lower, \
+ IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \
+ IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \
+ conjA = ((TriStorageOrder==ColMajor) && Conjugate) ? 1 : 0 \
+ }; \
+ static void run( \
+ Index size, Index otherSize, \
+ const EIGTYPE* _tri, Index triStride, \
+ EIGTYPE* _other, Index otherIncr, Index otherStride, level3_blocking<EIGTYPE,EIGTYPE>& /*blocking*/) \
+ { \
+ EIGEN_ONLY_USED_FOR_DEBUG(otherIncr); \
+ eigen_assert(otherIncr == 1); \
+ BlasIndex m = convert_index<BlasIndex>(otherSize), n = convert_index<BlasIndex>(size), lda, ldb; \
+ char side = 'R', uplo, diag='N', transa; \
+ /* Set alpha_ */ \
+ EIGTYPE alpha(1); \
+ ldb = convert_index<BlasIndex>(otherStride);\
+\
+ const EIGTYPE *a; \
+/* Set trans */ \
+ transa = (TriStorageOrder==RowMajor) ? ((Conjugate) ? 'C' : 'T') : 'N'; \
+/* Set uplo */ \
+ uplo = IsLower ? 'L' : 'U'; \
+ if (TriStorageOrder==RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \
+/* Set a, lda */ \
+ typedef Matrix<EIGTYPE, Dynamic, Dynamic, TriStorageOrder> MatrixTri; \
+ Map<const MatrixTri, 0, OuterStride<> > tri(_tri,size,size,OuterStride<>(triStride)); \
+ MatrixTri a_tmp; \
+\
+ if (conjA) { \
+ a_tmp = tri.conjugate(); \
+ a = a_tmp.data(); \
+ lda = convert_index<BlasIndex>(a_tmp.outerStride()); \
+ } else { \
+ a = _tri; \
+ lda = convert_index<BlasIndex>(triStride); \
+ } \
+ if (IsUnitDiag) diag='U'; \
+/* call ?trsm*/ \
+ BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (BLASTYPE*)_other, &ldb); \
+ /*std::cout << "TRMS_L specialization!\n";*/ \
+ } \
+};
+
+#ifdef EIGEN_USE_MKL
+EIGEN_BLAS_TRSM_R(double, double, dtrsm)
+EIGEN_BLAS_TRSM_R(dcomplex, MKL_Complex16, ztrsm)
+EIGEN_BLAS_TRSM_R(float, float, strsm)
+EIGEN_BLAS_TRSM_R(scomplex, MKL_Complex8, ctrsm)
+#else
+EIGEN_BLAS_TRSM_R(double, double, dtrsm_)
+EIGEN_BLAS_TRSM_R(dcomplex, double, ztrsm_)
+EIGEN_BLAS_TRSM_R(float, float, strsm_)
+EIGEN_BLAS_TRSM_R(scomplex, float, ctrsm_)
+#endif
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverVector.h b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverVector.h
new file mode 100644
index 000000000..647317016
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/products/TriangularSolverVector.h
@@ -0,0 +1,148 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TRIANGULAR_SOLVER_VECTOR_H
+#define EIGEN_TRIANGULAR_SOLVER_VECTOR_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename LhsScalar, typename RhsScalar, typename Index, int Mode, bool Conjugate, int StorageOrder>
+struct triangular_solve_vector<LhsScalar, RhsScalar, Index, OnTheRight, Mode, Conjugate, StorageOrder>
+{
+ static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs)
+ {
+ triangular_solve_vector<LhsScalar,RhsScalar,Index,OnTheLeft,
+ ((Mode&Upper)==Upper ? Lower : Upper) | (Mode&UnitDiag),
+ Conjugate,StorageOrder==RowMajor?ColMajor:RowMajor
+ >::run(size, _lhs, lhsStride, rhs);
+ }
+};
+
+// forward and backward substitution, row-major, rhs is a vector
+template<typename LhsScalar, typename RhsScalar, typename Index, int Mode, bool Conjugate>
+struct triangular_solve_vector<LhsScalar, RhsScalar, Index, OnTheLeft, Mode, Conjugate, RowMajor>
+{
+ enum {
+ IsLower = ((Mode&Lower)==Lower)
+ };
+ static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs)
+ {
+ typedef Map<const Matrix<LhsScalar,Dynamic,Dynamic,RowMajor>, 0, OuterStride<> > LhsMap;
+ const LhsMap lhs(_lhs,size,size,OuterStride<>(lhsStride));
+
+ typedef const_blas_data_mapper<LhsScalar,Index,RowMajor> LhsMapper;
+ typedef const_blas_data_mapper<RhsScalar,Index,ColMajor> RhsMapper;
+
+ typename internal::conditional<
+ Conjugate,
+ const CwiseUnaryOp<typename internal::scalar_conjugate_op<LhsScalar>,LhsMap>,
+ const LhsMap&>
+ ::type cjLhs(lhs);
+ static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH;
+ for(Index pi=IsLower ? 0 : size;
+ IsLower ? pi<size : pi>0;
+ IsLower ? pi+=PanelWidth : pi-=PanelWidth)
+ {
+ Index actualPanelWidth = (std::min)(IsLower ? size - pi : pi, PanelWidth);
+
+ Index r = IsLower ? pi : size - pi; // remaining size
+ if (r > 0)
+ {
+ // let's directly call the low level product function because:
+ // 1 - it is faster to compile
+ // 2 - it is slightly faster at runtime
+ Index startRow = IsLower ? pi : pi-actualPanelWidth;
+ Index startCol = IsLower ? 0 : pi;
+
+ general_matrix_vector_product<Index,LhsScalar,LhsMapper,RowMajor,Conjugate,RhsScalar,RhsMapper,false>::run(
+ actualPanelWidth, r,
+ LhsMapper(&lhs.coeffRef(startRow,startCol), lhsStride),
+ RhsMapper(rhs + startCol, 1),
+ rhs + startRow, 1,
+ RhsScalar(-1));
+ }
+
+ for(Index k=0; k<actualPanelWidth; ++k)
+ {
+ Index i = IsLower ? pi+k : pi-k-1;
+ Index s = IsLower ? pi : i+1;
+ if (k>0)
+ rhs[i] -= (cjLhs.row(i).segment(s,k).transpose().cwiseProduct(Map<const Matrix<RhsScalar,Dynamic,1> >(rhs+s,k))).sum();
+
+ if((!(Mode & UnitDiag)) && numext::not_equal_strict(rhs[i],RhsScalar(0)))
+ rhs[i] /= cjLhs(i,i);
+ }
+ }
+ }
+};
+
+// forward and backward substitution, column-major, rhs is a vector
+template<typename LhsScalar, typename RhsScalar, typename Index, int Mode, bool Conjugate>
+struct triangular_solve_vector<LhsScalar, RhsScalar, Index, OnTheLeft, Mode, Conjugate, ColMajor>
+{
+ enum {
+ IsLower = ((Mode&Lower)==Lower)
+ };
+ static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs)
+ {
+ typedef Map<const Matrix<LhsScalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > LhsMap;
+ const LhsMap lhs(_lhs,size,size,OuterStride<>(lhsStride));
+ typedef const_blas_data_mapper<LhsScalar,Index,ColMajor> LhsMapper;
+ typedef const_blas_data_mapper<RhsScalar,Index,ColMajor> RhsMapper;
+ typename internal::conditional<Conjugate,
+ const CwiseUnaryOp<typename internal::scalar_conjugate_op<LhsScalar>,LhsMap>,
+ const LhsMap&
+ >::type cjLhs(lhs);
+ static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH;
+
+ for(Index pi=IsLower ? 0 : size;
+ IsLower ? pi<size : pi>0;
+ IsLower ? pi+=PanelWidth : pi-=PanelWidth)
+ {
+ Index actualPanelWidth = (std::min)(IsLower ? size - pi : pi, PanelWidth);
+ Index startBlock = IsLower ? pi : pi-actualPanelWidth;
+ Index endBlock = IsLower ? pi + actualPanelWidth : 0;
+
+ for(Index k=0; k<actualPanelWidth; ++k)
+ {
+ Index i = IsLower ? pi+k : pi-k-1;
+ if(numext::not_equal_strict(rhs[i],RhsScalar(0)))
+ {
+ if(!(Mode & UnitDiag))
+ rhs[i] /= cjLhs.coeff(i,i);
+
+ Index r = actualPanelWidth - k - 1; // remaining size
+ Index s = IsLower ? i+1 : i-r;
+ if (r>0)
+ Map<Matrix<RhsScalar,Dynamic,1> >(rhs+s,r) -= rhs[i] * cjLhs.col(i).segment(s,r);
+ }
+ }
+ Index r = IsLower ? size - endBlock : startBlock; // remaining size
+ if (r > 0)
+ {
+ // let's directly call the low level product function because:
+ // 1 - it is faster to compile
+ // 2 - it is slightly faster at runtime
+ general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,Conjugate,RhsScalar,RhsMapper,false>::run(
+ r, actualPanelWidth,
+ LhsMapper(&lhs.coeffRef(endBlock,startBlock), lhsStride),
+ RhsMapper(rhs+startBlock, 1),
+ rhs+endBlock, 1, RhsScalar(-1));
+ }
+ }
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRIANGULAR_SOLVER_VECTOR_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/BlasUtil.h b/src/3rdparty/eigen/Eigen/src/Core/util/BlasUtil.h
new file mode 100644
index 000000000..e16a56498
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/BlasUtil.h
@@ -0,0 +1,583 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_BLASUTIL_H
+#define EIGEN_BLASUTIL_H
+
+// This file contains many lightweight helper classes used to
+// implement and control fast level 2 and level 3 BLAS-like routines.
+
+namespace Eigen {
+
+namespace internal {
+
+// forward declarations
+template<typename LhsScalar, typename RhsScalar, typename Index, typename DataMapper, int mr, int nr, bool ConjugateLhs=false, bool ConjugateRhs=false>
+struct gebp_kernel;
+
+template<typename Scalar, typename Index, typename DataMapper, int nr, int StorageOrder, bool Conjugate = false, bool PanelMode=false>
+struct gemm_pack_rhs;
+
+template<typename Scalar, typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, int StorageOrder, bool Conjugate = false, bool PanelMode = false>
+struct gemm_pack_lhs;
+
+template<
+ typename Index,
+ typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs,
+ typename RhsScalar, int RhsStorageOrder, bool ConjugateRhs,
+ int ResStorageOrder, int ResInnerStride>
+struct general_matrix_matrix_product;
+
+template<typename Index,
+ typename LhsScalar, typename LhsMapper, int LhsStorageOrder, bool ConjugateLhs,
+ typename RhsScalar, typename RhsMapper, bool ConjugateRhs, int Version=Specialized>
+struct general_matrix_vector_product;
+
+template<typename From,typename To> struct get_factor {
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE To run(const From& x) { return To(x); }
+};
+
+template<typename Scalar> struct get_factor<Scalar,typename NumTraits<Scalar>::Real> {
+ EIGEN_DEVICE_FUNC
+ static EIGEN_STRONG_INLINE typename NumTraits<Scalar>::Real run(const Scalar& x) { return numext::real(x); }
+};
+
+
+template<typename Scalar, typename Index>
+class BlasVectorMapper {
+ public:
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BlasVectorMapper(Scalar *data) : m_data(data) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar operator()(Index i) const {
+ return m_data[i];
+ }
+ template <typename Packet, int AlignmentType>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet load(Index i) const {
+ return ploadt<Packet, AlignmentType>(m_data + i);
+ }
+
+ template <typename Packet>
+ EIGEN_DEVICE_FUNC bool aligned(Index i) const {
+ return (UIntPtr(m_data+i)%sizeof(Packet))==0;
+ }
+
+ protected:
+ Scalar* m_data;
+};
+
+template<typename Scalar, typename Index, int AlignmentType, int Incr=1>
+class BlasLinearMapper;
+
+template<typename Scalar, typename Index, int AlignmentType>
+class BlasLinearMapper<Scalar,Index,AlignmentType>
+{
+public:
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BlasLinearMapper(Scalar *data, Index incr=1)
+ : m_data(data)
+ {
+ EIGEN_ONLY_USED_FOR_DEBUG(incr);
+ eigen_assert(incr==1);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void prefetch(int i) const {
+ internal::prefetch(&operator()(i));
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar& operator()(Index i) const {
+ return m_data[i];
+ }
+
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(Index i) const {
+ return ploadt<PacketType, AlignmentType>(m_data + i);
+ }
+
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void storePacket(Index i, const PacketType &p) const {
+ pstoret<Scalar, PacketType, AlignmentType>(m_data + i, p);
+ }
+
+protected:
+ Scalar *m_data;
+};
+
+// Lightweight helper class to access matrix coefficients.
+template<typename Scalar, typename Index, int StorageOrder, int AlignmentType = Unaligned, int Incr = 1>
+class blas_data_mapper;
+
+// TMP to help PacketBlock store implementation.
+// There's currently no known use case for PacketBlock load.
+// The default implementation assumes ColMajor order.
+// It always store each packet sequentially one `stride` apart.
+template<typename Index, typename Scalar, typename Packet, int n, int idx, int StorageOrder>
+struct PacketBlockManagement
+{
+ PacketBlockManagement<Index, Scalar, Packet, n, idx - 1, StorageOrder> pbm;
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void store(Scalar *to, const Index stride, Index i, Index j, const PacketBlock<Packet, n> &block) const {
+ pbm.store(to, stride, i, j, block);
+ pstoreu<Scalar>(to + i + (j + idx)*stride, block.packet[idx]);
+ }
+};
+
+// PacketBlockManagement specialization to take care of RowMajor order without ifs.
+template<typename Index, typename Scalar, typename Packet, int n, int idx>
+struct PacketBlockManagement<Index, Scalar, Packet, n, idx, RowMajor>
+{
+ PacketBlockManagement<Index, Scalar, Packet, n, idx - 1, RowMajor> pbm;
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void store(Scalar *to, const Index stride, Index i, Index j, const PacketBlock<Packet, n> &block) const {
+ pbm.store(to, stride, i, j, block);
+ pstoreu<Scalar>(to + j + (i + idx)*stride, block.packet[idx]);
+ }
+};
+
+template<typename Index, typename Scalar, typename Packet, int n, int StorageOrder>
+struct PacketBlockManagement<Index, Scalar, Packet, n, -1, StorageOrder>
+{
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void store(Scalar *to, const Index stride, Index i, Index j, const PacketBlock<Packet, n> &block) const {
+ EIGEN_UNUSED_VARIABLE(to);
+ EIGEN_UNUSED_VARIABLE(stride);
+ EIGEN_UNUSED_VARIABLE(i);
+ EIGEN_UNUSED_VARIABLE(j);
+ EIGEN_UNUSED_VARIABLE(block);
+ }
+};
+
+template<typename Index, typename Scalar, typename Packet, int n>
+struct PacketBlockManagement<Index, Scalar, Packet, n, -1, RowMajor>
+{
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void store(Scalar *to, const Index stride, Index i, Index j, const PacketBlock<Packet, n> &block) const {
+ EIGEN_UNUSED_VARIABLE(to);
+ EIGEN_UNUSED_VARIABLE(stride);
+ EIGEN_UNUSED_VARIABLE(i);
+ EIGEN_UNUSED_VARIABLE(j);
+ EIGEN_UNUSED_VARIABLE(block);
+ }
+};
+
+template<typename Scalar, typename Index, int StorageOrder, int AlignmentType>
+class blas_data_mapper<Scalar,Index,StorageOrder,AlignmentType,1>
+{
+public:
+ typedef BlasLinearMapper<Scalar, Index, AlignmentType> LinearMapper;
+ typedef BlasVectorMapper<Scalar, Index> VectorMapper;
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE blas_data_mapper(Scalar* data, Index stride, Index incr=1)
+ : m_data(data), m_stride(stride)
+ {
+ EIGEN_ONLY_USED_FOR_DEBUG(incr);
+ eigen_assert(incr==1);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE blas_data_mapper<Scalar, Index, StorageOrder, AlignmentType>
+ getSubMapper(Index i, Index j) const {
+ return blas_data_mapper<Scalar, Index, StorageOrder, AlignmentType>(&operator()(i, j), m_stride);
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE LinearMapper getLinearMapper(Index i, Index j) const {
+ return LinearMapper(&operator()(i, j));
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE VectorMapper getVectorMapper(Index i, Index j) const {
+ return VectorMapper(&operator()(i, j));
+ }
+
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_ALWAYS_INLINE Scalar& operator()(Index i, Index j) const {
+ return m_data[StorageOrder==RowMajor ? j + i*m_stride : i + j*m_stride];
+ }
+
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(Index i, Index j) const {
+ return ploadt<PacketType, AlignmentType>(&operator()(i, j));
+ }
+
+ template <typename PacketT, int AlignmentT>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT load(Index i, Index j) const {
+ return ploadt<PacketT, AlignmentT>(&operator()(i, j));
+ }
+
+ template<typename SubPacket>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void scatterPacket(Index i, Index j, const SubPacket &p) const {
+ pscatter<Scalar, SubPacket>(&operator()(i, j), p, m_stride);
+ }
+
+ template<typename SubPacket>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE SubPacket gatherPacket(Index i, Index j) const {
+ return pgather<Scalar, SubPacket>(&operator()(i, j), m_stride);
+ }
+
+ EIGEN_DEVICE_FUNC const Index stride() const { return m_stride; }
+ EIGEN_DEVICE_FUNC const Scalar* data() const { return m_data; }
+
+ EIGEN_DEVICE_FUNC Index firstAligned(Index size) const {
+ if (UIntPtr(m_data)%sizeof(Scalar)) {
+ return -1;
+ }
+ return internal::first_default_aligned(m_data, size);
+ }
+
+ template<typename SubPacket, int n>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void storePacketBlock(Index i, Index j, const PacketBlock<SubPacket, n> &block) const {
+ PacketBlockManagement<Index, Scalar, SubPacket, n, n-1, StorageOrder> pbm;
+ pbm.store(m_data, m_stride, i, j, block);
+ }
+protected:
+ Scalar* EIGEN_RESTRICT m_data;
+ const Index m_stride;
+};
+
+// Implementation of non-natural increment (i.e. inner-stride != 1)
+// The exposed API is not complete yet compared to the Incr==1 case
+// because some features makes less sense in this case.
+template<typename Scalar, typename Index, int AlignmentType, int Incr>
+class BlasLinearMapper
+{
+public:
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BlasLinearMapper(Scalar *data,Index incr) : m_data(data), m_incr(incr) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void prefetch(int i) const {
+ internal::prefetch(&operator()(i));
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar& operator()(Index i) const {
+ return m_data[i*m_incr.value()];
+ }
+
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(Index i) const {
+ return pgather<Scalar,PacketType>(m_data + i*m_incr.value(), m_incr.value());
+ }
+
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void storePacket(Index i, const PacketType &p) const {
+ pscatter<Scalar, PacketType>(m_data + i*m_incr.value(), p, m_incr.value());
+ }
+
+protected:
+ Scalar *m_data;
+ const internal::variable_if_dynamic<Index,Incr> m_incr;
+};
+
+template<typename Scalar, typename Index, int StorageOrder, int AlignmentType,int Incr>
+class blas_data_mapper
+{
+public:
+ typedef BlasLinearMapper<Scalar, Index, AlignmentType,Incr> LinearMapper;
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE blas_data_mapper(Scalar* data, Index stride, Index incr) : m_data(data), m_stride(stride), m_incr(incr) {}
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE blas_data_mapper
+ getSubMapper(Index i, Index j) const {
+ return blas_data_mapper(&operator()(i, j), m_stride, m_incr.value());
+ }
+
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE LinearMapper getLinearMapper(Index i, Index j) const {
+ return LinearMapper(&operator()(i, j), m_incr.value());
+ }
+
+ EIGEN_DEVICE_FUNC
+ EIGEN_ALWAYS_INLINE Scalar& operator()(Index i, Index j) const {
+ return m_data[StorageOrder==RowMajor ? j*m_incr.value() + i*m_stride : i*m_incr.value() + j*m_stride];
+ }
+
+ template<typename PacketType>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(Index i, Index j) const {
+ return pgather<Scalar,PacketType>(&operator()(i, j),m_incr.value());
+ }
+
+ template <typename PacketT, int AlignmentT>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT load(Index i, Index j) const {
+ return pgather<Scalar,PacketT>(&operator()(i, j),m_incr.value());
+ }
+
+ template<typename SubPacket>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void scatterPacket(Index i, Index j, const SubPacket &p) const {
+ pscatter<Scalar, SubPacket>(&operator()(i, j), p, m_stride);
+ }
+
+ template<typename SubPacket>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE SubPacket gatherPacket(Index i, Index j) const {
+ return pgather<Scalar, SubPacket>(&operator()(i, j), m_stride);
+ }
+
+ // storePacketBlock_helper defines a way to access values inside the PacketBlock, this is essentially required by the Complex types.
+ template<typename SubPacket, typename ScalarT, int n, int idx>
+ struct storePacketBlock_helper
+ {
+ storePacketBlock_helper<SubPacket, ScalarT, n, idx-1> spbh;
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void store(const blas_data_mapper<Scalar, Index, StorageOrder, AlignmentType, Incr>* sup, Index i, Index j, const PacketBlock<SubPacket, n>& block) const {
+ spbh.store(sup, i,j,block);
+ for(int l = 0; l < unpacket_traits<SubPacket>::size; l++)
+ {
+ ScalarT *v = &sup->operator()(i+l, j+idx);
+ *v = block.packet[idx][l];
+ }
+ }
+ };
+
+ template<typename SubPacket, int n, int idx>
+ struct storePacketBlock_helper<SubPacket, std::complex<float>, n, idx>
+ {
+ storePacketBlock_helper<SubPacket, std::complex<float>, n, idx-1> spbh;
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void store(const blas_data_mapper<Scalar, Index, StorageOrder, AlignmentType, Incr>* sup, Index i, Index j, const PacketBlock<SubPacket, n>& block) const {
+ spbh.store(sup,i,j,block);
+ for(int l = 0; l < unpacket_traits<SubPacket>::size; l++)
+ {
+ std::complex<float> *v = &sup->operator()(i+l, j+idx);
+ v->real(block.packet[idx].v[2*l+0]);
+ v->imag(block.packet[idx].v[2*l+1]);
+ }
+ }
+ };
+
+ template<typename SubPacket, int n, int idx>
+ struct storePacketBlock_helper<SubPacket, std::complex<double>, n, idx>
+ {
+ storePacketBlock_helper<SubPacket, std::complex<double>, n, idx-1> spbh;
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void store(const blas_data_mapper<Scalar, Index, StorageOrder, AlignmentType, Incr>* sup, Index i, Index j, const PacketBlock<SubPacket, n>& block) const {
+ spbh.store(sup,i,j,block);
+ for(int l = 0; l < unpacket_traits<SubPacket>::size; l++)
+ {
+ std::complex<double> *v = &sup->operator()(i+l, j+idx);
+ v->real(block.packet[idx].v[2*l+0]);
+ v->imag(block.packet[idx].v[2*l+1]);
+ }
+ }
+ };
+
+ template<typename SubPacket, typename ScalarT, int n>
+ struct storePacketBlock_helper<SubPacket, ScalarT, n, -1>
+ {
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void store(const blas_data_mapper<Scalar, Index, StorageOrder, AlignmentType, Incr>*, Index, Index, const PacketBlock<SubPacket, n>& ) const {
+ }
+ };
+
+ template<typename SubPacket, int n>
+ struct storePacketBlock_helper<SubPacket, std::complex<float>, n, -1>
+ {
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void store(const blas_data_mapper<Scalar, Index, StorageOrder, AlignmentType, Incr>*, Index, Index, const PacketBlock<SubPacket, n>& ) const {
+ }
+ };
+
+ template<typename SubPacket, int n>
+ struct storePacketBlock_helper<SubPacket, std::complex<double>, n, -1>
+ {
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void store(const blas_data_mapper<Scalar, Index, StorageOrder, AlignmentType, Incr>*, Index, Index, const PacketBlock<SubPacket, n>& ) const {
+ }
+ };
+ // This function stores a PacketBlock on m_data, this approach is really quite slow compare to Incr=1 and should be avoided when possible.
+ template<typename SubPacket, int n>
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void storePacketBlock(Index i, Index j, const PacketBlock<SubPacket, n>&block) const {
+ storePacketBlock_helper<SubPacket, Scalar, n, n-1> spb;
+ spb.store(this, i,j,block);
+ }
+protected:
+ Scalar* EIGEN_RESTRICT m_data;
+ const Index m_stride;
+ const internal::variable_if_dynamic<Index,Incr> m_incr;
+};
+
+// lightweight helper class to access matrix coefficients (const version)
+template<typename Scalar, typename Index, int StorageOrder>
+class const_blas_data_mapper : public blas_data_mapper<const Scalar, Index, StorageOrder> {
+ public:
+ EIGEN_ALWAYS_INLINE const_blas_data_mapper(const Scalar *data, Index stride) : blas_data_mapper<const Scalar, Index, StorageOrder>(data, stride) {}
+
+ EIGEN_ALWAYS_INLINE const_blas_data_mapper<Scalar, Index, StorageOrder> getSubMapper(Index i, Index j) const {
+ return const_blas_data_mapper<Scalar, Index, StorageOrder>(&(this->operator()(i, j)), this->m_stride);
+ }
+};
+
+
+/* Helper class to analyze the factors of a Product expression.
+ * In particular it allows to pop out operator-, scalar multiples,
+ * and conjugate */
+template<typename XprType> struct blas_traits
+{
+ typedef typename traits<XprType>::Scalar Scalar;
+ typedef const XprType& ExtractType;
+ typedef XprType _ExtractType;
+ enum {
+ IsComplex = NumTraits<Scalar>::IsComplex,
+ IsTransposed = false,
+ NeedToConjugate = false,
+ HasUsableDirectAccess = ( (int(XprType::Flags)&DirectAccessBit)
+ && ( bool(XprType::IsVectorAtCompileTime)
+ || int(inner_stride_at_compile_time<XprType>::ret) == 1)
+ ) ? 1 : 0,
+ HasScalarFactor = false
+ };
+ typedef typename conditional<bool(HasUsableDirectAccess),
+ ExtractType,
+ typename _ExtractType::PlainObject
+ >::type DirectLinearAccessType;
+ static inline EIGEN_DEVICE_FUNC ExtractType extract(const XprType& x) { return x; }
+ static inline EIGEN_DEVICE_FUNC const Scalar extractScalarFactor(const XprType&) { return Scalar(1); }
+};
+
+// pop conjugate
+template<typename Scalar, typename NestedXpr>
+struct blas_traits<CwiseUnaryOp<scalar_conjugate_op<Scalar>, NestedXpr> >
+ : blas_traits<NestedXpr>
+{
+ typedef blas_traits<NestedXpr> Base;
+ typedef CwiseUnaryOp<scalar_conjugate_op<Scalar>, NestedXpr> XprType;
+ typedef typename Base::ExtractType ExtractType;
+
+ enum {
+ IsComplex = NumTraits<Scalar>::IsComplex,
+ NeedToConjugate = Base::NeedToConjugate ? 0 : IsComplex
+ };
+ static inline ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); }
+ static inline Scalar extractScalarFactor(const XprType& x) { return conj(Base::extractScalarFactor(x.nestedExpression())); }
+};
+
+// pop scalar multiple
+template<typename Scalar, typename NestedXpr, typename Plain>
+struct blas_traits<CwiseBinaryOp<scalar_product_op<Scalar>, const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain>, NestedXpr> >
+ : blas_traits<NestedXpr>
+{
+ enum {
+ HasScalarFactor = true
+ };
+ typedef blas_traits<NestedXpr> Base;
+ typedef CwiseBinaryOp<scalar_product_op<Scalar>, const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain>, NestedXpr> XprType;
+ typedef typename Base::ExtractType ExtractType;
+ static inline EIGEN_DEVICE_FUNC ExtractType extract(const XprType& x) { return Base::extract(x.rhs()); }
+ static inline EIGEN_DEVICE_FUNC Scalar extractScalarFactor(const XprType& x)
+ { return x.lhs().functor().m_other * Base::extractScalarFactor(x.rhs()); }
+};
+template<typename Scalar, typename NestedXpr, typename Plain>
+struct blas_traits<CwiseBinaryOp<scalar_product_op<Scalar>, NestedXpr, const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain> > >
+ : blas_traits<NestedXpr>
+{
+ enum {
+ HasScalarFactor = true
+ };
+ typedef blas_traits<NestedXpr> Base;
+ typedef CwiseBinaryOp<scalar_product_op<Scalar>, NestedXpr, const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain> > XprType;
+ typedef typename Base::ExtractType ExtractType;
+ static inline ExtractType extract(const XprType& x) { return Base::extract(x.lhs()); }
+ static inline Scalar extractScalarFactor(const XprType& x)
+ { return Base::extractScalarFactor(x.lhs()) * x.rhs().functor().m_other; }
+};
+template<typename Scalar, typename Plain1, typename Plain2>
+struct blas_traits<CwiseBinaryOp<scalar_product_op<Scalar>, const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain1>,
+ const CwiseNullaryOp<scalar_constant_op<Scalar>,Plain2> > >
+ : blas_traits<CwiseNullaryOp<scalar_constant_op<Scalar>,Plain1> >
+{};
+
+// pop opposite
+template<typename Scalar, typename NestedXpr>
+struct blas_traits<CwiseUnaryOp<scalar_opposite_op<Scalar>, NestedXpr> >
+ : blas_traits<NestedXpr>
+{
+ enum {
+ HasScalarFactor = true
+ };
+ typedef blas_traits<NestedXpr> Base;
+ typedef CwiseUnaryOp<scalar_opposite_op<Scalar>, NestedXpr> XprType;
+ typedef typename Base::ExtractType ExtractType;
+ static inline ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); }
+ static inline Scalar extractScalarFactor(const XprType& x)
+ { return - Base::extractScalarFactor(x.nestedExpression()); }
+};
+
+// pop/push transpose
+template<typename NestedXpr>
+struct blas_traits<Transpose<NestedXpr> >
+ : blas_traits<NestedXpr>
+{
+ typedef typename NestedXpr::Scalar Scalar;
+ typedef blas_traits<NestedXpr> Base;
+ typedef Transpose<NestedXpr> XprType;
+ typedef Transpose<const typename Base::_ExtractType> ExtractType; // const to get rid of a compile error; anyway blas traits are only used on the RHS
+ typedef Transpose<const typename Base::_ExtractType> _ExtractType;
+ typedef typename conditional<bool(Base::HasUsableDirectAccess),
+ ExtractType,
+ typename ExtractType::PlainObject
+ >::type DirectLinearAccessType;
+ enum {
+ IsTransposed = Base::IsTransposed ? 0 : 1
+ };
+ static inline ExtractType extract(const XprType& x) { return ExtractType(Base::extract(x.nestedExpression())); }
+ static inline Scalar extractScalarFactor(const XprType& x) { return Base::extractScalarFactor(x.nestedExpression()); }
+};
+
+template<typename T>
+struct blas_traits<const T>
+ : blas_traits<T>
+{};
+
+template<typename T, bool HasUsableDirectAccess=blas_traits<T>::HasUsableDirectAccess>
+struct extract_data_selector {
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static const typename T::Scalar* run(const T& m)
+ {
+ return blas_traits<T>::extract(m).data();
+ }
+};
+
+template<typename T>
+struct extract_data_selector<T,false> {
+ static typename T::Scalar* run(const T&) { return 0; }
+};
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const typename T::Scalar* extract_data(const T& m)
+{
+ return extract_data_selector<T>::run(m);
+}
+
+/**
+ * \c combine_scalar_factors extracts and multiplies factors from GEMM and GEMV products.
+ * There is a specialization for booleans
+ */
+template<typename ResScalar, typename Lhs, typename Rhs>
+struct combine_scalar_factors_impl
+{
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static ResScalar run(const Lhs& lhs, const Rhs& rhs)
+ {
+ return blas_traits<Lhs>::extractScalarFactor(lhs) * blas_traits<Rhs>::extractScalarFactor(rhs);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static ResScalar run(const ResScalar& alpha, const Lhs& lhs, const Rhs& rhs)
+ {
+ return alpha * blas_traits<Lhs>::extractScalarFactor(lhs) * blas_traits<Rhs>::extractScalarFactor(rhs);
+ }
+};
+template<typename Lhs, typename Rhs>
+struct combine_scalar_factors_impl<bool, Lhs, Rhs>
+{
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static bool run(const Lhs& lhs, const Rhs& rhs)
+ {
+ return blas_traits<Lhs>::extractScalarFactor(lhs) && blas_traits<Rhs>::extractScalarFactor(rhs);
+ }
+ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static bool run(const bool& alpha, const Lhs& lhs, const Rhs& rhs)
+ {
+ return alpha && blas_traits<Lhs>::extractScalarFactor(lhs) && blas_traits<Rhs>::extractScalarFactor(rhs);
+ }
+};
+
+template<typename ResScalar, typename Lhs, typename Rhs>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE ResScalar combine_scalar_factors(const ResScalar& alpha, const Lhs& lhs, const Rhs& rhs)
+{
+ return combine_scalar_factors_impl<ResScalar,Lhs,Rhs>::run(alpha, lhs, rhs);
+}
+template<typename ResScalar, typename Lhs, typename Rhs>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE ResScalar combine_scalar_factors(const Lhs& lhs, const Rhs& rhs)
+{
+ return combine_scalar_factors_impl<ResScalar,Lhs,Rhs>::run(lhs, rhs);
+}
+
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_BLASUTIL_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/ConfigureVectorization.h b/src/3rdparty/eigen/Eigen/src/Core/util/ConfigureVectorization.h
new file mode 100644
index 000000000..af4e69623
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/ConfigureVectorization.h
@@ -0,0 +1,512 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2018 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2020, Arm Limited and Contributors
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_CONFIGURE_VECTORIZATION_H
+#define EIGEN_CONFIGURE_VECTORIZATION_H
+
+//------------------------------------------------------------------------------------------
+// Static and dynamic alignment control
+//
+// The main purpose of this section is to define EIGEN_MAX_ALIGN_BYTES and EIGEN_MAX_STATIC_ALIGN_BYTES
+// as the maximal boundary in bytes on which dynamically and statically allocated data may be alignment respectively.
+// The values of EIGEN_MAX_ALIGN_BYTES and EIGEN_MAX_STATIC_ALIGN_BYTES can be specified by the user. If not,
+// a default value is automatically computed based on architecture, compiler, and OS.
+//
+// This section also defines macros EIGEN_ALIGN_TO_BOUNDARY(N) and the shortcuts EIGEN_ALIGN{8,16,32,_MAX}
+// to be used to declare statically aligned buffers.
+//------------------------------------------------------------------------------------------
+
+
+/* EIGEN_ALIGN_TO_BOUNDARY(n) forces data to be n-byte aligned. This is used to satisfy SIMD requirements.
+ * However, we do that EVEN if vectorization (EIGEN_VECTORIZE) is disabled,
+ * so that vectorization doesn't affect binary compatibility.
+ *
+ * If we made alignment depend on whether or not EIGEN_VECTORIZE is defined, it would be impossible to link
+ * vectorized and non-vectorized code.
+ *
+ * FIXME: this code can be cleaned up once we switch to proper C++11 only.
+ */
+#if (defined EIGEN_CUDACC)
+ #define EIGEN_ALIGN_TO_BOUNDARY(n) __align__(n)
+ #define EIGEN_ALIGNOF(x) __alignof(x)
+#elif EIGEN_HAS_ALIGNAS
+ #define EIGEN_ALIGN_TO_BOUNDARY(n) alignas(n)
+ #define EIGEN_ALIGNOF(x) alignof(x)
+#elif EIGEN_COMP_GNUC || EIGEN_COMP_PGI || EIGEN_COMP_IBM || EIGEN_COMP_ARM
+ #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
+ #define EIGEN_ALIGNOF(x) __alignof(x)
+#elif EIGEN_COMP_MSVC
+ #define EIGEN_ALIGN_TO_BOUNDARY(n) __declspec(align(n))
+ #define EIGEN_ALIGNOF(x) __alignof(x)
+#elif EIGEN_COMP_SUNCC
+ // FIXME not sure about this one:
+ #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
+ #define EIGEN_ALIGNOF(x) __alignof(x)
+#else
+ #error Please tell me what is the equivalent of alignas(n) and alignof(x) for your compiler
+#endif
+
+// If the user explicitly disable vectorization, then we also disable alignment
+#if defined(EIGEN_DONT_VECTORIZE)
+ #if defined(EIGEN_GPUCC)
+ // GPU code is always vectorized and requires memory alignment for
+ // statically allocated buffers.
+ #define EIGEN_IDEAL_MAX_ALIGN_BYTES 16
+ #else
+ #define EIGEN_IDEAL_MAX_ALIGN_BYTES 0
+ #endif
+#elif defined(__AVX512F__)
+ // 64 bytes static alignment is preferred only if really required
+ #define EIGEN_IDEAL_MAX_ALIGN_BYTES 64
+#elif defined(__AVX__)
+ // 32 bytes static alignment is preferred only if really required
+ #define EIGEN_IDEAL_MAX_ALIGN_BYTES 32
+#else
+ #define EIGEN_IDEAL_MAX_ALIGN_BYTES 16
+#endif
+
+
+// EIGEN_MIN_ALIGN_BYTES defines the minimal value for which the notion of explicit alignment makes sense
+#define EIGEN_MIN_ALIGN_BYTES 16
+
+// Defined the boundary (in bytes) on which the data needs to be aligned. Note
+// that unless EIGEN_ALIGN is defined and not equal to 0, the data may not be
+// aligned at all regardless of the value of this #define.
+
+#if (defined(EIGEN_DONT_ALIGN_STATICALLY) || defined(EIGEN_DONT_ALIGN)) && defined(EIGEN_MAX_STATIC_ALIGN_BYTES) && EIGEN_MAX_STATIC_ALIGN_BYTES>0
+#error EIGEN_MAX_STATIC_ALIGN_BYTES and EIGEN_DONT_ALIGN[_STATICALLY] are both defined with EIGEN_MAX_STATIC_ALIGN_BYTES!=0. Use EIGEN_MAX_STATIC_ALIGN_BYTES=0 as a synonym of EIGEN_DONT_ALIGN_STATICALLY.
+#endif
+
+// EIGEN_DONT_ALIGN_STATICALLY and EIGEN_DONT_ALIGN are deprecated
+// They imply EIGEN_MAX_STATIC_ALIGN_BYTES=0
+#if defined(EIGEN_DONT_ALIGN_STATICALLY) || defined(EIGEN_DONT_ALIGN)
+ #ifdef EIGEN_MAX_STATIC_ALIGN_BYTES
+ #undef EIGEN_MAX_STATIC_ALIGN_BYTES
+ #endif
+ #define EIGEN_MAX_STATIC_ALIGN_BYTES 0
+#endif
+
+#ifndef EIGEN_MAX_STATIC_ALIGN_BYTES
+
+ // Try to automatically guess what is the best default value for EIGEN_MAX_STATIC_ALIGN_BYTES
+
+ // 16 byte alignment is only useful for vectorization. Since it affects the ABI, we need to enable
+ // 16 byte alignment on all platforms where vectorization might be enabled. In theory we could always
+ // enable alignment, but it can be a cause of problems on some platforms, so we just disable it in
+ // certain common platform (compiler+architecture combinations) to avoid these problems.
+ // Only static alignment is really problematic (relies on nonstandard compiler extensions),
+ // try to keep heap alignment even when we have to disable static alignment.
+ #if EIGEN_COMP_GNUC && !(EIGEN_ARCH_i386_OR_x86_64 || EIGEN_ARCH_ARM_OR_ARM64 || EIGEN_ARCH_PPC || EIGEN_ARCH_IA64 || EIGEN_ARCH_MIPS)
+ #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 1
+ #elif EIGEN_ARCH_ARM_OR_ARM64 && EIGEN_COMP_GNUC_STRICT && EIGEN_GNUC_AT_MOST(4, 6)
+ // Old versions of GCC on ARM, at least 4.4, were once seen to have buggy static alignment support.
+ // Not sure which version fixed it, hopefully it doesn't affect 4.7, which is still somewhat in use.
+ // 4.8 and newer seem definitely unaffected.
+ #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 1
+ #else
+ #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 0
+ #endif
+
+ // static alignment is completely disabled with GCC 3, Sun Studio, and QCC/QNX
+ #if !EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT \
+ && !EIGEN_GCC3_OR_OLDER \
+ && !EIGEN_COMP_SUNCC \
+ && !EIGEN_OS_QNX
+ #define EIGEN_ARCH_WANTS_STACK_ALIGNMENT 1
+ #else
+ #define EIGEN_ARCH_WANTS_STACK_ALIGNMENT 0
+ #endif
+
+ #if EIGEN_ARCH_WANTS_STACK_ALIGNMENT
+ #define EIGEN_MAX_STATIC_ALIGN_BYTES EIGEN_IDEAL_MAX_ALIGN_BYTES
+ #else
+ #define EIGEN_MAX_STATIC_ALIGN_BYTES 0
+ #endif
+
+#endif
+
+// If EIGEN_MAX_ALIGN_BYTES is defined, then it is considered as an upper bound for EIGEN_MAX_STATIC_ALIGN_BYTES
+#if defined(EIGEN_MAX_ALIGN_BYTES) && EIGEN_MAX_ALIGN_BYTES<EIGEN_MAX_STATIC_ALIGN_BYTES
+#undef EIGEN_MAX_STATIC_ALIGN_BYTES
+#define EIGEN_MAX_STATIC_ALIGN_BYTES EIGEN_MAX_ALIGN_BYTES
+#endif
+
+#if EIGEN_MAX_STATIC_ALIGN_BYTES==0 && !defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
+ #define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
+#endif
+
+// At this stage, EIGEN_MAX_STATIC_ALIGN_BYTES>0 is the true test whether we want to align arrays on the stack or not.
+// It takes into account both the user choice to explicitly enable/disable alignment (by setting EIGEN_MAX_STATIC_ALIGN_BYTES)
+// and the architecture config (EIGEN_ARCH_WANTS_STACK_ALIGNMENT).
+// Henceforth, only EIGEN_MAX_STATIC_ALIGN_BYTES should be used.
+
+
+// Shortcuts to EIGEN_ALIGN_TO_BOUNDARY
+#define EIGEN_ALIGN8 EIGEN_ALIGN_TO_BOUNDARY(8)
+#define EIGEN_ALIGN16 EIGEN_ALIGN_TO_BOUNDARY(16)
+#define EIGEN_ALIGN32 EIGEN_ALIGN_TO_BOUNDARY(32)
+#define EIGEN_ALIGN64 EIGEN_ALIGN_TO_BOUNDARY(64)
+#if EIGEN_MAX_STATIC_ALIGN_BYTES>0
+#define EIGEN_ALIGN_MAX EIGEN_ALIGN_TO_BOUNDARY(EIGEN_MAX_STATIC_ALIGN_BYTES)
+#else
+#define EIGEN_ALIGN_MAX
+#endif
+
+
+// Dynamic alignment control
+
+#if defined(EIGEN_DONT_ALIGN) && defined(EIGEN_MAX_ALIGN_BYTES) && EIGEN_MAX_ALIGN_BYTES>0
+#error EIGEN_MAX_ALIGN_BYTES and EIGEN_DONT_ALIGN are both defined with EIGEN_MAX_ALIGN_BYTES!=0. Use EIGEN_MAX_ALIGN_BYTES=0 as a synonym of EIGEN_DONT_ALIGN.
+#endif
+
+#ifdef EIGEN_DONT_ALIGN
+ #ifdef EIGEN_MAX_ALIGN_BYTES
+ #undef EIGEN_MAX_ALIGN_BYTES
+ #endif
+ #define EIGEN_MAX_ALIGN_BYTES 0
+#elif !defined(EIGEN_MAX_ALIGN_BYTES)
+ #define EIGEN_MAX_ALIGN_BYTES EIGEN_IDEAL_MAX_ALIGN_BYTES
+#endif
+
+#if EIGEN_IDEAL_MAX_ALIGN_BYTES > EIGEN_MAX_ALIGN_BYTES
+#define EIGEN_DEFAULT_ALIGN_BYTES EIGEN_IDEAL_MAX_ALIGN_BYTES
+#else
+#define EIGEN_DEFAULT_ALIGN_BYTES EIGEN_MAX_ALIGN_BYTES
+#endif
+
+
+#ifndef EIGEN_UNALIGNED_VECTORIZE
+#define EIGEN_UNALIGNED_VECTORIZE 1
+#endif
+
+//----------------------------------------------------------------------
+
+// if alignment is disabled, then disable vectorization. Note: EIGEN_MAX_ALIGN_BYTES is the proper check, it takes into
+// account both the user's will (EIGEN_MAX_ALIGN_BYTES,EIGEN_DONT_ALIGN) and our own platform checks
+#if EIGEN_MAX_ALIGN_BYTES==0
+ #ifndef EIGEN_DONT_VECTORIZE
+ #define EIGEN_DONT_VECTORIZE
+ #endif
+#endif
+
+
+// The following (except #include <malloc.h> and _M_IX86_FP ??) can likely be
+// removed as gcc 4.1 and msvc 2008 are not supported anyways.
+#if EIGEN_COMP_MSVC
+ #include <malloc.h> // for _aligned_malloc -- need it regardless of whether vectorization is enabled
+ #if (EIGEN_COMP_MSVC >= 1500) // 2008 or later
+ // a user reported that in 64-bit mode, MSVC doesn't care to define _M_IX86_FP.
+ #if (defined(_M_IX86_FP) && (_M_IX86_FP >= 2)) || EIGEN_ARCH_x86_64
+ #define EIGEN_SSE2_ON_MSVC_2008_OR_LATER
+ #endif
+ #endif
+#else
+ #if (defined __SSE2__) && ( (!EIGEN_COMP_GNUC) || EIGEN_COMP_ICC || EIGEN_GNUC_AT_LEAST(4,2) )
+ #define EIGEN_SSE2_ON_NON_MSVC_BUT_NOT_OLD_GCC
+ #endif
+#endif
+
+#if !(defined(EIGEN_DONT_VECTORIZE) || defined(EIGEN_GPUCC))
+
+ #if defined (EIGEN_SSE2_ON_NON_MSVC_BUT_NOT_OLD_GCC) || defined(EIGEN_SSE2_ON_MSVC_2008_OR_LATER)
+
+ // Defines symbols for compile-time detection of which instructions are
+ // used.
+ // EIGEN_VECTORIZE_YY is defined if and only if the instruction set YY is used
+ #define EIGEN_VECTORIZE
+ #define EIGEN_VECTORIZE_SSE
+ #define EIGEN_VECTORIZE_SSE2
+
+ // Detect sse3/ssse3/sse4:
+ // gcc and icc defines __SSE3__, ...
+ // there is no way to know about this on msvc. You can define EIGEN_VECTORIZE_SSE* if you
+ // want to force the use of those instructions with msvc.
+ #ifdef __SSE3__
+ #define EIGEN_VECTORIZE_SSE3
+ #endif
+ #ifdef __SSSE3__
+ #define EIGEN_VECTORIZE_SSSE3
+ #endif
+ #ifdef __SSE4_1__
+ #define EIGEN_VECTORIZE_SSE4_1
+ #endif
+ #ifdef __SSE4_2__
+ #define EIGEN_VECTORIZE_SSE4_2
+ #endif
+ #ifdef __AVX__
+ #ifndef EIGEN_USE_SYCL
+ #define EIGEN_VECTORIZE_AVX
+ #endif
+ #define EIGEN_VECTORIZE_SSE3
+ #define EIGEN_VECTORIZE_SSSE3
+ #define EIGEN_VECTORIZE_SSE4_1
+ #define EIGEN_VECTORIZE_SSE4_2
+ #endif
+ #ifdef __AVX2__
+ #ifndef EIGEN_USE_SYCL
+ #define EIGEN_VECTORIZE_AVX2
+ #define EIGEN_VECTORIZE_AVX
+ #endif
+ #define EIGEN_VECTORIZE_SSE3
+ #define EIGEN_VECTORIZE_SSSE3
+ #define EIGEN_VECTORIZE_SSE4_1
+ #define EIGEN_VECTORIZE_SSE4_2
+ #endif
+ #if defined(__FMA__) || (EIGEN_COMP_MSVC && defined(__AVX2__))
+ // MSVC does not expose a switch dedicated for FMA
+ // For MSVC, AVX2 => FMA
+ #define EIGEN_VECTORIZE_FMA
+ #endif
+ #if defined(__AVX512F__)
+ #ifndef EIGEN_VECTORIZE_FMA
+ #if EIGEN_COMP_GNUC
+ #error Please add -mfma to your compiler flags: compiling with -mavx512f alone without SSE/AVX FMA is not supported (bug 1638).
+ #else
+ #error Please enable FMA in your compiler flags (e.g. -mfma): compiling with AVX512 alone without SSE/AVX FMA is not supported (bug 1638).
+ #endif
+ #endif
+ #ifndef EIGEN_USE_SYCL
+ #define EIGEN_VECTORIZE_AVX512
+ #define EIGEN_VECTORIZE_AVX2
+ #define EIGEN_VECTORIZE_AVX
+ #endif
+ #define EIGEN_VECTORIZE_FMA
+ #define EIGEN_VECTORIZE_SSE3
+ #define EIGEN_VECTORIZE_SSSE3
+ #define EIGEN_VECTORIZE_SSE4_1
+ #define EIGEN_VECTORIZE_SSE4_2
+ #ifndef EIGEN_USE_SYCL
+ #ifdef __AVX512DQ__
+ #define EIGEN_VECTORIZE_AVX512DQ
+ #endif
+ #ifdef __AVX512ER__
+ #define EIGEN_VECTORIZE_AVX512ER
+ #endif
+ #ifdef __AVX512BF16__
+ #define EIGEN_VECTORIZE_AVX512BF16
+ #endif
+ #endif
+ #endif
+
+ // Disable AVX support on broken xcode versions
+ #if defined(__apple_build_version__) && (__apple_build_version__ == 11000033 ) && ( __MAC_OS_X_VERSION_MIN_REQUIRED == 101500 )
+ // A nasty bug in the clang compiler shipped with xcode in a common compilation situation
+ // when XCode 11.0 and Mac deployment target macOS 10.15 is https://trac.macports.org/ticket/58776#no1
+ #ifdef EIGEN_VECTORIZE_AVX
+ #undef EIGEN_VECTORIZE_AVX
+ #warning "Disabling AVX support: clang compiler shipped with XCode 11.[012] generates broken assembly with -macosx-version-min=10.15 and AVX enabled. "
+ #ifdef EIGEN_VECTORIZE_AVX2
+ #undef EIGEN_VECTORIZE_AVX2
+ #endif
+ #ifdef EIGEN_VECTORIZE_FMA
+ #undef EIGEN_VECTORIZE_FMA
+ #endif
+ #ifdef EIGEN_VECTORIZE_AVX512
+ #undef EIGEN_VECTORIZE_AVX512
+ #endif
+ #ifdef EIGEN_VECTORIZE_AVX512DQ
+ #undef EIGEN_VECTORIZE_AVX512DQ
+ #endif
+ #ifdef EIGEN_VECTORIZE_AVX512ER
+ #undef EIGEN_VECTORIZE_AVX512ER
+ #endif
+ #endif
+ // NOTE: Confirmed test failures in XCode 11.0, and XCode 11.2 with -macosx-version-min=10.15 and AVX
+ // NOTE using -macosx-version-min=10.15 with Xcode 11.0 results in runtime segmentation faults in many tests, 11.2 produce core dumps in 3 tests
+ // NOTE using -macosx-version-min=10.14 produces functioning and passing tests in all cases
+ // NOTE __clang_version__ "11.0.0 (clang-1100.0.33.8)" XCode 11.0 <- Produces many segfault and core dumping tests
+ // with -macosx-version-min=10.15 and AVX
+ // NOTE __clang_version__ "11.0.0 (clang-1100.0.33.12)" XCode 11.2 <- Produces 3 core dumping tests with
+ // -macosx-version-min=10.15 and AVX
+ #endif
+
+ // include files
+
+ // This extern "C" works around a MINGW-w64 compilation issue
+ // https://sourceforge.net/tracker/index.php?func=detail&aid=3018394&group_id=202880&atid=983354
+ // In essence, intrin.h is included by windows.h and also declares intrinsics (just as emmintrin.h etc. below do).
+ // However, intrin.h uses an extern "C" declaration, and g++ thus complains of duplicate declarations
+ // with conflicting linkage. The linkage for intrinsics doesn't matter, but at that stage the compiler doesn't know;
+ // so, to avoid compile errors when windows.h is included after Eigen/Core, ensure intrinsics are extern "C" here too.
+ // notice that since these are C headers, the extern "C" is theoretically needed anyways.
+ extern "C" {
+ // In theory we should only include immintrin.h and not the other *mmintrin.h header files directly.
+ // Doing so triggers some issues with ICC. However old gcc versions seems to not have this file, thus:
+ #if EIGEN_COMP_ICC >= 1110
+ #include <immintrin.h>
+ #else
+ #include <mmintrin.h>
+ #include <emmintrin.h>
+ #include <xmmintrin.h>
+ #ifdef EIGEN_VECTORIZE_SSE3
+ #include <pmmintrin.h>
+ #endif
+ #ifdef EIGEN_VECTORIZE_SSSE3
+ #include <tmmintrin.h>
+ #endif
+ #ifdef EIGEN_VECTORIZE_SSE4_1
+ #include <smmintrin.h>
+ #endif
+ #ifdef EIGEN_VECTORIZE_SSE4_2
+ #include <nmmintrin.h>
+ #endif
+ #if defined(EIGEN_VECTORIZE_AVX) || defined(EIGEN_VECTORIZE_AVX512)
+ #include <immintrin.h>
+ #endif
+ #endif
+ } // end extern "C"
+
+ #elif defined __VSX__
+
+ #define EIGEN_VECTORIZE
+ #define EIGEN_VECTORIZE_VSX
+ #include <altivec.h>
+ // We need to #undef all these ugly tokens defined in <altivec.h>
+ // => use __vector instead of vector
+ #undef bool
+ #undef vector
+ #undef pixel
+
+ #elif defined __ALTIVEC__
+
+ #define EIGEN_VECTORIZE
+ #define EIGEN_VECTORIZE_ALTIVEC
+ #include <altivec.h>
+ // We need to #undef all these ugly tokens defined in <altivec.h>
+ // => use __vector instead of vector
+ #undef bool
+ #undef vector
+ #undef pixel
+
+ #elif ((defined __ARM_NEON) || (defined __ARM_NEON__)) && !(defined EIGEN_ARM64_USE_SVE)
+
+ #define EIGEN_VECTORIZE
+ #define EIGEN_VECTORIZE_NEON
+ #include <arm_neon.h>
+
+ // We currently require SVE to be enabled explicitly via EIGEN_ARM64_USE_SVE and
+ // will not select the backend automatically
+ #elif (defined __ARM_FEATURE_SVE) && (defined EIGEN_ARM64_USE_SVE)
+
+ #define EIGEN_VECTORIZE
+ #define EIGEN_VECTORIZE_SVE
+ #include <arm_sve.h>
+
+ // Since we depend on knowing SVE vector lengths at compile-time, we need
+ // to ensure a fixed lengths is set
+ #if defined __ARM_FEATURE_SVE_BITS
+ #define EIGEN_ARM64_SVE_VL __ARM_FEATURE_SVE_BITS
+ #else
+#error "Eigen requires a fixed SVE lector length but EIGEN_ARM64_SVE_VL is not set."
+#endif
+
+#elif (defined __s390x__ && defined __VEC__)
+
+#define EIGEN_VECTORIZE
+#define EIGEN_VECTORIZE_ZVECTOR
+#include <vecintrin.h>
+
+#elif defined __mips_msa
+
+// Limit MSA optimizations to little-endian CPUs for now.
+// TODO: Perhaps, eventually support MSA optimizations on big-endian CPUs?
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#if defined(__LP64__)
+#define EIGEN_MIPS_64
+#else
+#define EIGEN_MIPS_32
+#endif
+#define EIGEN_VECTORIZE
+#define EIGEN_VECTORIZE_MSA
+#include <msa.h>
+#endif
+
+#endif
+#endif
+
+// Following the Arm ACLE arm_neon.h should also include arm_fp16.h but not all
+// compilers seem to follow this. We therefore include it explicitly.
+// See also: https://bugs.llvm.org/show_bug.cgi?id=47955
+#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
+ #include <arm_fp16.h>
+#endif
+
+#if defined(__F16C__) && (!defined(EIGEN_GPUCC) && (!defined(EIGEN_COMP_CLANG) || EIGEN_COMP_CLANG>=380))
+ // We can use the optimized fp16 to float and float to fp16 conversion routines
+ #define EIGEN_HAS_FP16_C
+
+ #if defined(EIGEN_COMP_CLANG)
+ // Workaround for clang: The FP16C intrinsics for clang are included by
+ // immintrin.h, as opposed to emmintrin.h as suggested by Intel:
+ // https://software.intel.com/sites/landingpage/IntrinsicsGuide/#othertechs=FP16C&expand=1711
+ #include <immintrin.h>
+ #endif
+#endif
+
+#if defined EIGEN_CUDACC
+ #define EIGEN_VECTORIZE_GPU
+ #include <vector_types.h>
+ #if EIGEN_CUDA_SDK_VER >= 70500
+ #define EIGEN_HAS_CUDA_FP16
+ #endif
+#endif
+
+#if defined(EIGEN_HAS_CUDA_FP16)
+ #include <cuda_runtime_api.h>
+ #include <cuda_fp16.h>
+#endif
+
+#if defined(EIGEN_HIPCC)
+ #define EIGEN_VECTORIZE_GPU
+ #include <hip/hip_vector_types.h>
+ #define EIGEN_HAS_HIP_FP16
+ #include <hip/hip_fp16.h>
+#endif
+
+
+/** \brief Namespace containing all symbols from the %Eigen library. */
+namespace Eigen {
+
+inline static const char *SimdInstructionSetsInUse(void) {
+#if defined(EIGEN_VECTORIZE_AVX512)
+ return "AVX512, FMA, AVX2, AVX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2";
+#elif defined(EIGEN_VECTORIZE_AVX)
+ return "AVX SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2";
+#elif defined(EIGEN_VECTORIZE_SSE4_2)
+ return "SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2";
+#elif defined(EIGEN_VECTORIZE_SSE4_1)
+ return "SSE, SSE2, SSE3, SSSE3, SSE4.1";
+#elif defined(EIGEN_VECTORIZE_SSSE3)
+ return "SSE, SSE2, SSE3, SSSE3";
+#elif defined(EIGEN_VECTORIZE_SSE3)
+ return "SSE, SSE2, SSE3";
+#elif defined(EIGEN_VECTORIZE_SSE2)
+ return "SSE, SSE2";
+#elif defined(EIGEN_VECTORIZE_ALTIVEC)
+ return "AltiVec";
+#elif defined(EIGEN_VECTORIZE_VSX)
+ return "VSX";
+#elif defined(EIGEN_VECTORIZE_NEON)
+ return "ARM NEON";
+#elif defined(EIGEN_VECTORIZE_SVE)
+ return "ARM SVE";
+#elif defined(EIGEN_VECTORIZE_ZVECTOR)
+ return "S390X ZVECTOR";
+#elif defined(EIGEN_VECTORIZE_MSA)
+ return "MIPS MSA";
+#else
+ return "None";
+#endif
+}
+
+} // end namespace Eigen
+
+
+#endif // EIGEN_CONFIGURE_VECTORIZATION_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/Constants.h b/src/3rdparty/eigen/Eigen/src/Core/util/Constants.h
new file mode 100644
index 000000000..35dcaa7b3
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/Constants.h
@@ -0,0 +1,563 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2020, Arm Limited and Contributors
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_CONSTANTS_H
+#define EIGEN_CONSTANTS_H
+
+namespace Eigen {
+
+/** This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is
+ * stored in some runtime variable.
+ *
+ * Changing the value of Dynamic breaks the ABI, as Dynamic is often used as a template parameter for Matrix.
+ */
+const int Dynamic = -1;
+
+/** This value means that a signed quantity (e.g., a signed index) is not known at compile-time, and that instead its value
+ * has to be specified at runtime.
+ */
+const int DynamicIndex = 0xffffff;
+
+/** This value means that the increment to go from one value to another in a sequence is not constant for each step.
+ */
+const int UndefinedIncr = 0xfffffe;
+
+/** This value means +Infinity; it is currently used only as the p parameter to MatrixBase::lpNorm<int>().
+ * The value Infinity there means the L-infinity norm.
+ */
+const int Infinity = -1;
+
+/** This value means that the cost to evaluate an expression coefficient is either very expensive or
+ * cannot be known at compile time.
+ *
+ * This value has to be positive to (1) simplify cost computation, and (2) allow to distinguish between a very expensive and very very expensive expressions.
+ * It thus must also be large enough to make sure unrolling won't happen and that sub expressions will be evaluated, but not too large to avoid overflow.
+ */
+const int HugeCost = 10000;
+
+/** \defgroup flags Flags
+ * \ingroup Core_Module
+ *
+ * These are the possible bits which can be OR'ed to constitute the flags of a matrix or
+ * expression.
+ *
+ * It is important to note that these flags are a purely compile-time notion. They are a compile-time property of
+ * an expression type, implemented as enum's. They are not stored in memory at runtime, and they do not incur any
+ * runtime overhead.
+ *
+ * \sa MatrixBase::Flags
+ */
+
+/** \ingroup flags
+ *
+ * for a matrix, this means that the storage order is row-major.
+ * If this bit is not set, the storage order is column-major.
+ * For an expression, this determines the storage order of
+ * the matrix created by evaluation of that expression.
+ * \sa \blank \ref TopicStorageOrders */
+const unsigned int RowMajorBit = 0x1;
+
+/** \ingroup flags
+ * means the expression should be evaluated by the calling expression */
+const unsigned int EvalBeforeNestingBit = 0x2;
+
+/** \ingroup flags
+ * \deprecated
+ * means the expression should be evaluated before any assignment */
+EIGEN_DEPRECATED
+const unsigned int EvalBeforeAssigningBit = 0x4; // FIXME deprecated
+
+/** \ingroup flags
+ *
+ * Short version: means the expression might be vectorized
+ *
+ * Long version: means that the coefficients can be handled by packets
+ * and start at a memory location whose alignment meets the requirements
+ * of the present CPU architecture for optimized packet access. In the fixed-size
+ * case, there is the additional condition that it be possible to access all the
+ * coefficients by packets (this implies the requirement that the size be a multiple of 16 bytes,
+ * and that any nontrivial strides don't break the alignment). In the dynamic-size case,
+ * there is no such condition on the total size and strides, so it might not be possible to access
+ * all coeffs by packets.
+ *
+ * \note This bit can be set regardless of whether vectorization is actually enabled.
+ * To check for actual vectorizability, see \a ActualPacketAccessBit.
+ */
+const unsigned int PacketAccessBit = 0x8;
+
+#ifdef EIGEN_VECTORIZE
+/** \ingroup flags
+ *
+ * If vectorization is enabled (EIGEN_VECTORIZE is defined) this constant
+ * is set to the value \a PacketAccessBit.
+ *
+ * If vectorization is not enabled (EIGEN_VECTORIZE is not defined) this constant
+ * is set to the value 0.
+ */
+const unsigned int ActualPacketAccessBit = PacketAccessBit;
+#else
+const unsigned int ActualPacketAccessBit = 0x0;
+#endif
+
+/** \ingroup flags
+ *
+ * Short version: means the expression can be seen as 1D vector.
+ *
+ * Long version: means that one can access the coefficients
+ * of this expression by coeff(int), and coeffRef(int) in the case of a lvalue expression. These
+ * index-based access methods are guaranteed
+ * to not have to do any runtime computation of a (row, col)-pair from the index, so that it
+ * is guaranteed that whenever it is available, index-based access is at least as fast as
+ * (row,col)-based access. Expressions for which that isn't possible don't have the LinearAccessBit.
+ *
+ * If both PacketAccessBit and LinearAccessBit are set, then the
+ * packets of this expression can be accessed by packet(int), and writePacket(int) in the case of a
+ * lvalue expression.
+ *
+ * Typically, all vector expressions have the LinearAccessBit, but there is one exception:
+ * Product expressions don't have it, because it would be troublesome for vectorization, even when the
+ * Product is a vector expression. Thus, vector Product expressions allow index-based coefficient access but
+ * not index-based packet access, so they don't have the LinearAccessBit.
+ */
+const unsigned int LinearAccessBit = 0x10;
+
+/** \ingroup flags
+ *
+ * Means the expression has a coeffRef() method, i.e. is writable as its individual coefficients are directly addressable.
+ * This rules out read-only expressions.
+ *
+ * Note that DirectAccessBit and LvalueBit are mutually orthogonal, as there are examples of expression having one but note
+ * the other:
+ * \li writable expressions that don't have a very simple memory layout as a strided array, have LvalueBit but not DirectAccessBit
+ * \li Map-to-const expressions, for example Map<const Matrix>, have DirectAccessBit but not LvalueBit
+ *
+ * Expressions having LvalueBit also have their coeff() method returning a const reference instead of returning a new value.
+ */
+const unsigned int LvalueBit = 0x20;
+
+/** \ingroup flags
+ *
+ * Means that the underlying array of coefficients can be directly accessed as a plain strided array. The memory layout
+ * of the array of coefficients must be exactly the natural one suggested by rows(), cols(),
+ * outerStride(), innerStride(), and the RowMajorBit. This rules out expressions such as Diagonal, whose coefficients,
+ * though referencable, do not have such a regular memory layout.
+ *
+ * See the comment on LvalueBit for an explanation of how LvalueBit and DirectAccessBit are mutually orthogonal.
+ */
+const unsigned int DirectAccessBit = 0x40;
+
+/** \deprecated \ingroup flags
+ *
+ * means the first coefficient packet is guaranteed to be aligned.
+ * An expression cannot have the AlignedBit without the PacketAccessBit flag.
+ * In other words, this means we are allow to perform an aligned packet access to the first element regardless
+ * of the expression kind:
+ * \code
+ * expression.packet<Aligned>(0);
+ * \endcode
+ */
+EIGEN_DEPRECATED const unsigned int AlignedBit = 0x80;
+
+const unsigned int NestByRefBit = 0x100;
+
+/** \ingroup flags
+ *
+ * for an expression, this means that the storage order
+ * can be either row-major or column-major.
+ * The precise choice will be decided at evaluation time or when
+ * combined with other expressions.
+ * \sa \blank \ref RowMajorBit, \ref TopicStorageOrders */
+const unsigned int NoPreferredStorageOrderBit = 0x200;
+
+/** \ingroup flags
+ *
+ * Means that the underlying coefficients can be accessed through pointers to the sparse (un)compressed storage format,
+ * that is, the expression provides:
+ * \code
+ inline const Scalar* valuePtr() const;
+ inline const Index* innerIndexPtr() const;
+ inline const Index* outerIndexPtr() const;
+ inline const Index* innerNonZeroPtr() const;
+ \endcode
+ */
+const unsigned int CompressedAccessBit = 0x400;
+
+
+// list of flags that are inherited by default
+const unsigned int HereditaryBits = RowMajorBit
+ | EvalBeforeNestingBit;
+
+/** \defgroup enums Enumerations
+ * \ingroup Core_Module
+ *
+ * Various enumerations used in %Eigen. Many of these are used as template parameters.
+ */
+
+/** \ingroup enums
+ * Enum containing possible values for the \c Mode or \c UpLo parameter of
+ * MatrixBase::selfadjointView() and MatrixBase::triangularView(), and selfadjoint solvers. */
+enum UpLoType {
+ /** View matrix as a lower triangular matrix. */
+ Lower=0x1,
+ /** View matrix as an upper triangular matrix. */
+ Upper=0x2,
+ /** %Matrix has ones on the diagonal; to be used in combination with #Lower or #Upper. */
+ UnitDiag=0x4,
+ /** %Matrix has zeros on the diagonal; to be used in combination with #Lower or #Upper. */
+ ZeroDiag=0x8,
+ /** View matrix as a lower triangular matrix with ones on the diagonal. */
+ UnitLower=UnitDiag|Lower,
+ /** View matrix as an upper triangular matrix with ones on the diagonal. */
+ UnitUpper=UnitDiag|Upper,
+ /** View matrix as a lower triangular matrix with zeros on the diagonal. */
+ StrictlyLower=ZeroDiag|Lower,
+ /** View matrix as an upper triangular matrix with zeros on the diagonal. */
+ StrictlyUpper=ZeroDiag|Upper,
+ /** Used in BandMatrix and SelfAdjointView to indicate that the matrix is self-adjoint. */
+ SelfAdjoint=0x10,
+ /** Used to support symmetric, non-selfadjoint, complex matrices. */
+ Symmetric=0x20
+};
+
+/** \ingroup enums
+ * Enum for indicating whether a buffer is aligned or not. */
+enum AlignmentType {
+ Unaligned=0, /**< Data pointer has no specific alignment. */
+ Aligned8=8, /**< Data pointer is aligned on a 8 bytes boundary. */
+ Aligned16=16, /**< Data pointer is aligned on a 16 bytes boundary. */
+ Aligned32=32, /**< Data pointer is aligned on a 32 bytes boundary. */
+ Aligned64=64, /**< Data pointer is aligned on a 64 bytes boundary. */
+ Aligned128=128, /**< Data pointer is aligned on a 128 bytes boundary. */
+ AlignedMask=255,
+ Aligned=16, /**< \deprecated Synonym for Aligned16. */
+#if EIGEN_MAX_ALIGN_BYTES==128
+ AlignedMax = Aligned128
+#elif EIGEN_MAX_ALIGN_BYTES==64
+ AlignedMax = Aligned64
+#elif EIGEN_MAX_ALIGN_BYTES==32
+ AlignedMax = Aligned32
+#elif EIGEN_MAX_ALIGN_BYTES==16
+ AlignedMax = Aligned16
+#elif EIGEN_MAX_ALIGN_BYTES==8
+ AlignedMax = Aligned8
+#elif EIGEN_MAX_ALIGN_BYTES==0
+ AlignedMax = Unaligned
+#else
+#error Invalid value for EIGEN_MAX_ALIGN_BYTES
+#endif
+};
+
+/** \ingroup enums
+ * Enum containing possible values for the \p Direction parameter of
+ * Reverse, PartialReduxExpr and VectorwiseOp. */
+enum DirectionType {
+ /** For Reverse, all columns are reversed;
+ * for PartialReduxExpr and VectorwiseOp, act on columns. */
+ Vertical,
+ /** For Reverse, all rows are reversed;
+ * for PartialReduxExpr and VectorwiseOp, act on rows. */
+ Horizontal,
+ /** For Reverse, both rows and columns are reversed;
+ * not used for PartialReduxExpr and VectorwiseOp. */
+ BothDirections
+};
+
+/** \internal \ingroup enums
+ * Enum to specify how to traverse the entries of a matrix. */
+enum TraversalType {
+ /** \internal Default traversal, no vectorization, no index-based access */
+ DefaultTraversal,
+ /** \internal No vectorization, use index-based access to have only one for loop instead of 2 nested loops */
+ LinearTraversal,
+ /** \internal Equivalent to a slice vectorization for fixed-size matrices having good alignment
+ * and good size */
+ InnerVectorizedTraversal,
+ /** \internal Vectorization path using a single loop plus scalar loops for the
+ * unaligned boundaries */
+ LinearVectorizedTraversal,
+ /** \internal Generic vectorization path using one vectorized loop per row/column with some
+ * scalar loops to handle the unaligned boundaries */
+ SliceVectorizedTraversal,
+ /** \internal Special case to properly handle incompatible scalar types or other defecting cases*/
+ InvalidTraversal,
+ /** \internal Evaluate all entries at once */
+ AllAtOnceTraversal
+};
+
+/** \internal \ingroup enums
+ * Enum to specify whether to unroll loops when traversing over the entries of a matrix. */
+enum UnrollingType {
+ /** \internal Do not unroll loops. */
+ NoUnrolling,
+ /** \internal Unroll only the inner loop, but not the outer loop. */
+ InnerUnrolling,
+ /** \internal Unroll both the inner and the outer loop. If there is only one loop,
+ * because linear traversal is used, then unroll that loop. */
+ CompleteUnrolling
+};
+
+/** \internal \ingroup enums
+ * Enum to specify whether to use the default (built-in) implementation or the specialization. */
+enum SpecializedType {
+ Specialized,
+ BuiltIn
+};
+
+/** \ingroup enums
+ * Enum containing possible values for the \p _Options template parameter of
+ * Matrix, Array and BandMatrix. */
+enum StorageOptions {
+ /** Storage order is column major (see \ref TopicStorageOrders). */
+ ColMajor = 0,
+ /** Storage order is row major (see \ref TopicStorageOrders). */
+ RowMajor = 0x1, // it is only a coincidence that this is equal to RowMajorBit -- don't rely on that
+ /** Align the matrix itself if it is vectorizable fixed-size */
+ AutoAlign = 0,
+ /** Don't require alignment for the matrix itself (the array of coefficients, if dynamically allocated, may still be requested to be aligned) */ // FIXME --- clarify the situation
+ DontAlign = 0x2
+};
+
+/** \ingroup enums
+ * Enum for specifying whether to apply or solve on the left or right. */
+enum SideType {
+ /** Apply transformation on the left. */
+ OnTheLeft = 1,
+ /** Apply transformation on the right. */
+ OnTheRight = 2
+};
+
+/** \ingroup enums
+ * Enum for specifying NaN-propagation behavior, e.g. for coeff-wise min/max. */
+enum NaNPropagationOptions {
+ /** Implementation defined behavior if NaNs are present. */
+ PropagateFast = 0,
+ /** Always propagate NaNs. */
+ PropagateNaN,
+ /** Always propagate not-NaNs. */
+ PropagateNumbers
+};
+
+/* the following used to be written as:
+ *
+ * struct NoChange_t {};
+ * namespace {
+ * EIGEN_UNUSED NoChange_t NoChange;
+ * }
+ *
+ * on the ground that it feels dangerous to disambiguate overloaded functions on enum/integer types.
+ * However, this leads to "variable declared but never referenced" warnings on Intel Composer XE,
+ * and we do not know how to get rid of them (bug 450).
+ */
+
+enum NoChange_t { NoChange };
+enum Sequential_t { Sequential };
+enum Default_t { Default };
+
+/** \internal \ingroup enums
+ * Used in AmbiVector. */
+enum AmbiVectorMode {
+ IsDense = 0,
+ IsSparse
+};
+
+/** \ingroup enums
+ * Used as template parameter in DenseCoeffBase and MapBase to indicate
+ * which accessors should be provided. */
+enum AccessorLevels {
+ /** Read-only access via a member function. */
+ ReadOnlyAccessors,
+ /** Read/write access via member functions. */
+ WriteAccessors,
+ /** Direct read-only access to the coefficients. */
+ DirectAccessors,
+ /** Direct read/write access to the coefficients. */
+ DirectWriteAccessors
+};
+
+/** \ingroup enums
+ * Enum with options to give to various decompositions. */
+enum DecompositionOptions {
+ /** \internal Not used (meant for LDLT?). */
+ Pivoting = 0x01,
+ /** \internal Not used (meant for LDLT?). */
+ NoPivoting = 0x02,
+ /** Used in JacobiSVD to indicate that the square matrix U is to be computed. */
+ ComputeFullU = 0x04,
+ /** Used in JacobiSVD to indicate that the thin matrix U is to be computed. */
+ ComputeThinU = 0x08,
+ /** Used in JacobiSVD to indicate that the square matrix V is to be computed. */
+ ComputeFullV = 0x10,
+ /** Used in JacobiSVD to indicate that the thin matrix V is to be computed. */
+ ComputeThinV = 0x20,
+ /** Used in SelfAdjointEigenSolver and GeneralizedSelfAdjointEigenSolver to specify
+ * that only the eigenvalues are to be computed and not the eigenvectors. */
+ EigenvaluesOnly = 0x40,
+ /** Used in SelfAdjointEigenSolver and GeneralizedSelfAdjointEigenSolver to specify
+ * that both the eigenvalues and the eigenvectors are to be computed. */
+ ComputeEigenvectors = 0x80,
+ /** \internal */
+ EigVecMask = EigenvaluesOnly | ComputeEigenvectors,
+ /** Used in GeneralizedSelfAdjointEigenSolver to indicate that it should
+ * solve the generalized eigenproblem \f$ Ax = \lambda B x \f$. */
+ Ax_lBx = 0x100,
+ /** Used in GeneralizedSelfAdjointEigenSolver to indicate that it should
+ * solve the generalized eigenproblem \f$ ABx = \lambda x \f$. */
+ ABx_lx = 0x200,
+ /** Used in GeneralizedSelfAdjointEigenSolver to indicate that it should
+ * solve the generalized eigenproblem \f$ BAx = \lambda x \f$. */
+ BAx_lx = 0x400,
+ /** \internal */
+ GenEigMask = Ax_lBx | ABx_lx | BAx_lx
+};
+
+/** \ingroup enums
+ * Possible values for the \p QRPreconditioner template parameter of JacobiSVD. */
+enum QRPreconditioners {
+ /** Do not specify what is to be done if the SVD of a non-square matrix is asked for. */
+ NoQRPreconditioner,
+ /** Use a QR decomposition without pivoting as the first step. */
+ HouseholderQRPreconditioner,
+ /** Use a QR decomposition with column pivoting as the first step. */
+ ColPivHouseholderQRPreconditioner,
+ /** Use a QR decomposition with full pivoting as the first step. */
+ FullPivHouseholderQRPreconditioner
+};
+
+#ifdef Success
+#error The preprocessor symbol 'Success' is defined, possibly by the X11 header file X.h
+#endif
+
+/** \ingroup enums
+ * Enum for reporting the status of a computation. */
+enum ComputationInfo {
+ /** Computation was successful. */
+ Success = 0,
+ /** The provided data did not satisfy the prerequisites. */
+ NumericalIssue = 1,
+ /** Iterative procedure did not converge. */
+ NoConvergence = 2,
+ /** The inputs are invalid, or the algorithm has been improperly called.
+ * When assertions are enabled, such errors trigger an assert. */
+ InvalidInput = 3
+};
+
+/** \ingroup enums
+ * Enum used to specify how a particular transformation is stored in a matrix.
+ * \sa Transform, Hyperplane::transform(). */
+enum TransformTraits {
+ /** Transformation is an isometry. */
+ Isometry = 0x1,
+ /** Transformation is an affine transformation stored as a (Dim+1)^2 matrix whose last row is
+ * assumed to be [0 ... 0 1]. */
+ Affine = 0x2,
+ /** Transformation is an affine transformation stored as a (Dim) x (Dim+1) matrix. */
+ AffineCompact = 0x10 | Affine,
+ /** Transformation is a general projective transformation stored as a (Dim+1)^2 matrix. */
+ Projective = 0x20
+};
+
+/** \internal \ingroup enums
+ * Enum used to choose between implementation depending on the computer architecture. */
+namespace Architecture
+{
+ enum Type {
+ Generic = 0x0,
+ SSE = 0x1,
+ AltiVec = 0x2,
+ VSX = 0x3,
+ NEON = 0x4,
+ MSA = 0x5,
+ SVE = 0x6,
+#if defined EIGEN_VECTORIZE_SSE
+ Target = SSE
+#elif defined EIGEN_VECTORIZE_ALTIVEC
+ Target = AltiVec
+#elif defined EIGEN_VECTORIZE_VSX
+ Target = VSX
+#elif defined EIGEN_VECTORIZE_NEON
+ Target = NEON
+#elif defined EIGEN_VECTORIZE_SVE
+ Target = SVE
+#elif defined EIGEN_VECTORIZE_MSA
+ Target = MSA
+#else
+ Target = Generic
+#endif
+ };
+}
+
+/** \internal \ingroup enums
+ * Enum used as template parameter in Product and product evaluators. */
+enum ProductImplType
+{ DefaultProduct=0, LazyProduct, AliasFreeProduct, CoeffBasedProductMode, LazyCoeffBasedProductMode, OuterProduct, InnerProduct, GemvProduct, GemmProduct };
+
+/** \internal \ingroup enums
+ * Enum used in experimental parallel implementation. */
+enum Action {GetAction, SetAction};
+
+/** The type used to identify a dense storage. */
+struct Dense {};
+
+/** The type used to identify a general sparse storage. */
+struct Sparse {};
+
+/** The type used to identify a general solver (factored) storage. */
+struct SolverStorage {};
+
+/** The type used to identify a permutation storage. */
+struct PermutationStorage {};
+
+/** The type used to identify a permutation storage. */
+struct TranspositionsStorage {};
+
+/** The type used to identify a matrix expression */
+struct MatrixXpr {};
+
+/** The type used to identify an array expression */
+struct ArrayXpr {};
+
+// An evaluator must define its shape. By default, it can be one of the following:
+struct DenseShape { static std::string debugName() { return "DenseShape"; } };
+struct SolverShape { static std::string debugName() { return "SolverShape"; } };
+struct HomogeneousShape { static std::string debugName() { return "HomogeneousShape"; } };
+struct DiagonalShape { static std::string debugName() { return "DiagonalShape"; } };
+struct BandShape { static std::string debugName() { return "BandShape"; } };
+struct TriangularShape { static std::string debugName() { return "TriangularShape"; } };
+struct SelfAdjointShape { static std::string debugName() { return "SelfAdjointShape"; } };
+struct PermutationShape { static std::string debugName() { return "PermutationShape"; } };
+struct TranspositionsShape { static std::string debugName() { return "TranspositionsShape"; } };
+struct SparseShape { static std::string debugName() { return "SparseShape"; } };
+
+namespace internal {
+
+ // random access iterators based on coeff*() accessors.
+struct IndexBased {};
+
+// evaluator based on iterators to access coefficients.
+struct IteratorBased {};
+
+/** \internal
+ * Constants for comparison functors
+ */
+enum ComparisonName {
+ cmp_EQ = 0,
+ cmp_LT = 1,
+ cmp_LE = 2,
+ cmp_UNORD = 3,
+ cmp_NEQ = 4,
+ cmp_GT = 5,
+ cmp_GE = 6
+};
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_CONSTANTS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/DisableStupidWarnings.h b/src/3rdparty/eigen/Eigen/src/Core/util/DisableStupidWarnings.h
new file mode 100644
index 000000000..fe0cfec0b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/DisableStupidWarnings.h
@@ -0,0 +1,106 @@
+#ifndef EIGEN_WARNINGS_DISABLED
+#define EIGEN_WARNINGS_DISABLED
+
+#ifdef _MSC_VER
+ // 4100 - unreferenced formal parameter (occurred e.g. in aligned_allocator::destroy(pointer p))
+ // 4101 - unreferenced local variable
+ // 4181 - qualifier applied to reference type ignored
+ // 4211 - nonstandard extension used : redefined extern to static
+ // 4244 - 'argument' : conversion from 'type1' to 'type2', possible loss of data
+ // 4273 - QtAlignedMalloc, inconsistent DLL linkage
+ // 4324 - structure was padded due to declspec(align())
+ // 4503 - decorated name length exceeded, name was truncated
+ // 4512 - assignment operator could not be generated
+ // 4522 - 'class' : multiple assignment operators specified
+ // 4700 - uninitialized local variable 'xyz' used
+ // 4714 - function marked as __forceinline not inlined
+ // 4717 - 'function' : recursive on all control paths, function will cause runtime stack overflow
+ // 4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning)
+ #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS
+ #pragma warning( push )
+ #endif
+ #pragma warning( disable : 4100 4101 4181 4211 4244 4273 4324 4503 4512 4522 4700 4714 4717 4800)
+
+#elif defined __INTEL_COMPILER
+ // 2196 - routine is both "inline" and "noinline" ("noinline" assumed)
+ // ICC 12 generates this warning even without any inline keyword, when defining class methods 'inline' i.e. inside of class body
+ // typedef that may be a reference type.
+ // 279 - controlling expression is constant
+ // ICC 12 generates this warning on assert(constant_expression_depending_on_template_params) and frankly this is a legitimate use case.
+ // 1684 - conversion from pointer to same-sized integral type (potential portability problem)
+ // 2259 - non-pointer conversion from "Eigen::Index={ptrdiff_t={long}}" to "int" may lose significant bits
+ #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS
+ #pragma warning push
+ #endif
+ #pragma warning disable 2196 279 1684 2259
+
+#elif defined __clang__
+ // -Wconstant-logical-operand - warning: use of logical && with constant operand; switch to bitwise & or remove constant
+ // this is really a stupid warning as it warns on compile-time expressions involving enums
+ #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS
+ #pragma clang diagnostic push
+ #endif
+ #pragma clang diagnostic ignored "-Wconstant-logical-operand"
+ #if __clang_major__ >= 3 && __clang_minor__ >= 5
+ #pragma clang diagnostic ignored "-Wabsolute-value"
+ #endif
+ #if __clang_major__ >= 10
+ #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
+ #endif
+ #if ( defined(__ALTIVEC__) || defined(__VSX__) ) && __cplusplus < 201103L
+ // warning: generic selections are a C11-specific feature
+ // ignoring warnings thrown at vec_ctf in Altivec/PacketMath.h
+ #pragma clang diagnostic ignored "-Wc11-extensions"
+ #endif
+
+#elif defined __GNUC__
+
+ #if (!defined(EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS)) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ #pragma GCC diagnostic push
+ #endif
+ // g++ warns about local variables shadowing member functions, which is too strict
+ #pragma GCC diagnostic ignored "-Wshadow"
+ #if __GNUC__ == 4 && __GNUC_MINOR__ < 8
+ // Until g++-4.7 there are warnings when comparing unsigned int vs 0, even in templated functions:
+ #pragma GCC diagnostic ignored "-Wtype-limits"
+ #endif
+ #if __GNUC__>=6
+ #pragma GCC diagnostic ignored "-Wignored-attributes"
+ #endif
+ #if __GNUC__==7
+ // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89325
+ #pragma GCC diagnostic ignored "-Wattributes"
+ #endif
+#endif
+
+#if defined __NVCC__
+ #pragma diag_suppress boolean_controlling_expr_is_constant
+ // Disable the "statement is unreachable" message
+ #pragma diag_suppress code_is_unreachable
+ // Disable the "dynamic initialization in unreachable code" message
+ #pragma diag_suppress initialization_not_reachable
+ // Disable the "invalid error number" message that we get with older versions of nvcc
+ #pragma diag_suppress 1222
+ // Disable the "calling a __host__ function from a __host__ __device__ function is not allowed" messages (yes, there are many of them and they seem to change with every version of the compiler)
+ #pragma diag_suppress 2527
+ #pragma diag_suppress 2529
+ #pragma diag_suppress 2651
+ #pragma diag_suppress 2653
+ #pragma diag_suppress 2668
+ #pragma diag_suppress 2669
+ #pragma diag_suppress 2670
+ #pragma diag_suppress 2671
+ #pragma diag_suppress 2735
+ #pragma diag_suppress 2737
+ #pragma diag_suppress 2739
+#endif
+
+#else
+// warnings already disabled:
+# ifndef EIGEN_WARNINGS_DISABLED_2
+# define EIGEN_WARNINGS_DISABLED_2
+# elif defined(EIGEN_INTERNAL_DEBUGGING)
+# error "Do not include \"DisableStupidWarnings.h\" recursively more than twice!"
+# endif
+
+#endif // not EIGEN_WARNINGS_DISABLED
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/ForwardDeclarations.h b/src/3rdparty/eigen/Eigen/src/Core/util/ForwardDeclarations.h
new file mode 100644
index 000000000..2f9cc4491
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/ForwardDeclarations.h
@@ -0,0 +1,322 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_FORWARDDECLARATIONS_H
+#define EIGEN_FORWARDDECLARATIONS_H
+
+namespace Eigen {
+namespace internal {
+
+template<typename T> struct traits;
+
+// here we say once and for all that traits<const T> == traits<T>
+// When constness must affect traits, it has to be constness on template parameters on which T itself depends.
+// For example, traits<Map<const T> > != traits<Map<T> >, but
+// traits<const Map<T> > == traits<Map<T> >
+template<typename T> struct traits<const T> : traits<T> {};
+
+template<typename Derived> struct has_direct_access
+{
+ enum { ret = (traits<Derived>::Flags & DirectAccessBit) ? 1 : 0 };
+};
+
+template<typename Derived> struct accessors_level
+{
+ enum { has_direct_access = (traits<Derived>::Flags & DirectAccessBit) ? 1 : 0,
+ has_write_access = (traits<Derived>::Flags & LvalueBit) ? 1 : 0,
+ value = has_direct_access ? (has_write_access ? DirectWriteAccessors : DirectAccessors)
+ : (has_write_access ? WriteAccessors : ReadOnlyAccessors)
+ };
+};
+
+template<typename T> struct evaluator_traits;
+
+template< typename T> struct evaluator;
+
+} // end namespace internal
+
+template<typename T> struct NumTraits;
+
+template<typename Derived> struct EigenBase;
+template<typename Derived> class DenseBase;
+template<typename Derived> class PlainObjectBase;
+template<typename Derived, int Level> class DenseCoeffsBase;
+
+template<typename _Scalar, int _Rows, int _Cols,
+ int _Options = AutoAlign |
+#if EIGEN_GNUC_AT(3,4)
+ // workaround a bug in at least gcc 3.4.6
+ // the innermost ?: ternary operator is misparsed. We write it slightly
+ // differently and this makes gcc 3.4.6 happy, but it's ugly.
+ // The error would only show up with EIGEN_DEFAULT_TO_ROW_MAJOR is defined
+ // (when EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION is RowMajor)
+ ( (_Rows==1 && _Cols!=1) ? Eigen::RowMajor
+ : !(_Cols==1 && _Rows!=1) ? EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION
+ : Eigen::ColMajor ),
+#else
+ ( (_Rows==1 && _Cols!=1) ? Eigen::RowMajor
+ : (_Cols==1 && _Rows!=1) ? Eigen::ColMajor
+ : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ),
+#endif
+ int _MaxRows = _Rows,
+ int _MaxCols = _Cols
+> class Matrix;
+
+template<typename Derived> class MatrixBase;
+template<typename Derived> class ArrayBase;
+
+template<typename ExpressionType, unsigned int Added, unsigned int Removed> class Flagged;
+template<typename ExpressionType, template <typename> class StorageBase > class NoAlias;
+template<typename ExpressionType> class NestByValue;
+template<typename ExpressionType> class ForceAlignedAccess;
+template<typename ExpressionType> class SwapWrapper;
+
+template<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic, bool InnerPanel = false> class Block;
+template<typename XprType, typename RowIndices, typename ColIndices> class IndexedView;
+template<typename XprType, int Rows=Dynamic, int Cols=Dynamic, int Order=0> class Reshaped;
+
+template<typename MatrixType, int Size=Dynamic> class VectorBlock;
+template<typename MatrixType> class Transpose;
+template<typename MatrixType> class Conjugate;
+template<typename NullaryOp, typename MatrixType> class CwiseNullaryOp;
+template<typename UnaryOp, typename MatrixType> class CwiseUnaryOp;
+template<typename ViewOp, typename MatrixType> class CwiseUnaryView;
+template<typename BinaryOp, typename Lhs, typename Rhs> class CwiseBinaryOp;
+template<typename TernaryOp, typename Arg1, typename Arg2, typename Arg3> class CwiseTernaryOp;
+template<typename Decomposition, typename Rhstype> class Solve;
+template<typename XprType> class Inverse;
+
+template<typename Lhs, typename Rhs, int Option = DefaultProduct> class Product;
+
+template<typename Derived> class DiagonalBase;
+template<typename _DiagonalVectorType> class DiagonalWrapper;
+template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime=SizeAtCompileTime> class DiagonalMatrix;
+template<typename MatrixType, typename DiagonalType, int ProductOrder> class DiagonalProduct;
+template<typename MatrixType, int Index = 0> class Diagonal;
+template<int SizeAtCompileTime, int MaxSizeAtCompileTime = SizeAtCompileTime, typename IndexType=int> class PermutationMatrix;
+template<int SizeAtCompileTime, int MaxSizeAtCompileTime = SizeAtCompileTime, typename IndexType=int> class Transpositions;
+template<typename Derived> class PermutationBase;
+template<typename Derived> class TranspositionsBase;
+template<typename _IndicesType> class PermutationWrapper;
+template<typename _IndicesType> class TranspositionsWrapper;
+
+template<typename Derived,
+ int Level = internal::accessors_level<Derived>::has_write_access ? WriteAccessors : ReadOnlyAccessors
+> class MapBase;
+template<int OuterStrideAtCompileTime, int InnerStrideAtCompileTime> class Stride;
+template<int Value = Dynamic> class InnerStride;
+template<int Value = Dynamic> class OuterStride;
+template<typename MatrixType, int MapOptions=Unaligned, typename StrideType = Stride<0,0> > class Map;
+template<typename Derived> class RefBase;
+template<typename PlainObjectType, int Options = 0,
+ typename StrideType = typename internal::conditional<PlainObjectType::IsVectorAtCompileTime,InnerStride<1>,OuterStride<> >::type > class Ref;
+
+template<typename Derived> class TriangularBase;
+template<typename MatrixType, unsigned int Mode> class TriangularView;
+template<typename MatrixType, unsigned int Mode> class SelfAdjointView;
+template<typename MatrixType> class SparseView;
+template<typename ExpressionType> class WithFormat;
+template<typename MatrixType> struct CommaInitializer;
+template<typename Derived> class ReturnByValue;
+template<typename ExpressionType> class ArrayWrapper;
+template<typename ExpressionType> class MatrixWrapper;
+template<typename Derived> class SolverBase;
+template<typename XprType> class InnerIterator;
+
+namespace internal {
+template<typename XprType> class generic_randaccess_stl_iterator;
+template<typename XprType> class pointer_based_stl_iterator;
+template<typename XprType, DirectionType Direction> class subvector_stl_iterator;
+template<typename XprType, DirectionType Direction> class subvector_stl_reverse_iterator;
+template<typename DecompositionType> struct kernel_retval_base;
+template<typename DecompositionType> struct kernel_retval;
+template<typename DecompositionType> struct image_retval_base;
+template<typename DecompositionType> struct image_retval;
+} // end namespace internal
+
+namespace internal {
+template<typename _Scalar, int Rows=Dynamic, int Cols=Dynamic, int Supers=Dynamic, int Subs=Dynamic, int Options=0> class BandMatrix;
+}
+
+namespace internal {
+template<typename Lhs, typename Rhs> struct product_type;
+
+template<bool> struct EnableIf;
+
+/** \internal
+ * \class product_evaluator
+ * Products need their own evaluator with more template arguments allowing for
+ * easier partial template specializations.
+ */
+template< typename T,
+ int ProductTag = internal::product_type<typename T::Lhs,typename T::Rhs>::ret,
+ typename LhsShape = typename evaluator_traits<typename T::Lhs>::Shape,
+ typename RhsShape = typename evaluator_traits<typename T::Rhs>::Shape,
+ typename LhsScalar = typename traits<typename T::Lhs>::Scalar,
+ typename RhsScalar = typename traits<typename T::Rhs>::Scalar
+ > struct product_evaluator;
+}
+
+template<typename Lhs, typename Rhs,
+ int ProductType = internal::product_type<Lhs,Rhs>::value>
+struct ProductReturnType;
+
+// this is a workaround for sun CC
+template<typename Lhs, typename Rhs> struct LazyProductReturnType;
+
+namespace internal {
+
+// Provides scalar/packet-wise product and product with accumulation
+// with optional conjugation of the arguments.
+template<typename LhsScalar, typename RhsScalar, bool ConjLhs=false, bool ConjRhs=false> struct conj_helper;
+
+template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_sum_op;
+template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_difference_op;
+template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_conj_product_op;
+template<typename LhsScalar,typename RhsScalar=LhsScalar, int NaNPropagation=PropagateFast> struct scalar_min_op;
+template<typename LhsScalar,typename RhsScalar=LhsScalar, int NaNPropagation=PropagateFast> struct scalar_max_op;
+template<typename Scalar> struct scalar_opposite_op;
+template<typename Scalar> struct scalar_conjugate_op;
+template<typename Scalar> struct scalar_real_op;
+template<typename Scalar> struct scalar_imag_op;
+template<typename Scalar> struct scalar_abs_op;
+template<typename Scalar> struct scalar_abs2_op;
+template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_absolute_difference_op;
+template<typename Scalar> struct scalar_sqrt_op;
+template<typename Scalar> struct scalar_rsqrt_op;
+template<typename Scalar> struct scalar_exp_op;
+template<typename Scalar> struct scalar_log_op;
+template<typename Scalar> struct scalar_cos_op;
+template<typename Scalar> struct scalar_sin_op;
+template<typename Scalar> struct scalar_acos_op;
+template<typename Scalar> struct scalar_asin_op;
+template<typename Scalar> struct scalar_tan_op;
+template<typename Scalar> struct scalar_inverse_op;
+template<typename Scalar> struct scalar_square_op;
+template<typename Scalar> struct scalar_cube_op;
+template<typename Scalar, typename NewType> struct scalar_cast_op;
+template<typename Scalar> struct scalar_random_op;
+template<typename Scalar> struct scalar_constant_op;
+template<typename Scalar> struct scalar_identity_op;
+template<typename Scalar,bool is_complex, bool is_integer> struct scalar_sign_op;
+template<typename Scalar,typename ScalarExponent> struct scalar_pow_op;
+template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_hypot_op;
+template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_product_op;
+template<typename LhsScalar,typename RhsScalar=LhsScalar> struct scalar_quotient_op;
+
+// SpecialFunctions module
+template<typename Scalar> struct scalar_lgamma_op;
+template<typename Scalar> struct scalar_digamma_op;
+template<typename Scalar> struct scalar_erf_op;
+template<typename Scalar> struct scalar_erfc_op;
+template<typename Scalar> struct scalar_ndtri_op;
+template<typename Scalar> struct scalar_igamma_op;
+template<typename Scalar> struct scalar_igammac_op;
+template<typename Scalar> struct scalar_zeta_op;
+template<typename Scalar> struct scalar_betainc_op;
+
+// Bessel functions in SpecialFunctions module
+template<typename Scalar> struct scalar_bessel_i0_op;
+template<typename Scalar> struct scalar_bessel_i0e_op;
+template<typename Scalar> struct scalar_bessel_i1_op;
+template<typename Scalar> struct scalar_bessel_i1e_op;
+template<typename Scalar> struct scalar_bessel_j0_op;
+template<typename Scalar> struct scalar_bessel_y0_op;
+template<typename Scalar> struct scalar_bessel_j1_op;
+template<typename Scalar> struct scalar_bessel_y1_op;
+template<typename Scalar> struct scalar_bessel_k0_op;
+template<typename Scalar> struct scalar_bessel_k0e_op;
+template<typename Scalar> struct scalar_bessel_k1_op;
+template<typename Scalar> struct scalar_bessel_k1e_op;
+
+
+} // end namespace internal
+
+struct IOFormat;
+
+// Array module
+template<typename _Scalar, int _Rows, int _Cols,
+ int _Options = AutoAlign |
+#if EIGEN_GNUC_AT(3,4)
+ // workaround a bug in at least gcc 3.4.6
+ // the innermost ?: ternary operator is misparsed. We write it slightly
+ // differently and this makes gcc 3.4.6 happy, but it's ugly.
+ // The error would only show up with EIGEN_DEFAULT_TO_ROW_MAJOR is defined
+ // (when EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION is RowMajor)
+ ( (_Rows==1 && _Cols!=1) ? Eigen::RowMajor
+ : !(_Cols==1 && _Rows!=1) ? EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION
+ : Eigen::ColMajor ),
+#else
+ ( (_Rows==1 && _Cols!=1) ? Eigen::RowMajor
+ : (_Cols==1 && _Rows!=1) ? Eigen::ColMajor
+ : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ),
+#endif
+ int _MaxRows = _Rows, int _MaxCols = _Cols> class Array;
+template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType> class Select;
+template<typename MatrixType, typename BinaryOp, int Direction> class PartialReduxExpr;
+template<typename ExpressionType, int Direction> class VectorwiseOp;
+template<typename MatrixType,int RowFactor,int ColFactor> class Replicate;
+template<typename MatrixType, int Direction = BothDirections> class Reverse;
+
+template<typename MatrixType> class FullPivLU;
+template<typename MatrixType> class PartialPivLU;
+namespace internal {
+template<typename MatrixType> struct inverse_impl;
+}
+template<typename MatrixType> class HouseholderQR;
+template<typename MatrixType> class ColPivHouseholderQR;
+template<typename MatrixType> class FullPivHouseholderQR;
+template<typename MatrixType> class CompleteOrthogonalDecomposition;
+template<typename MatrixType> class SVDBase;
+template<typename MatrixType, int QRPreconditioner = ColPivHouseholderQRPreconditioner> class JacobiSVD;
+template<typename MatrixType> class BDCSVD;
+template<typename MatrixType, int UpLo = Lower> class LLT;
+template<typename MatrixType, int UpLo = Lower> class LDLT;
+template<typename VectorsType, typename CoeffsType, int Side=OnTheLeft> class HouseholderSequence;
+template<typename Scalar> class JacobiRotation;
+
+// Geometry module:
+template<typename Derived, int _Dim> class RotationBase;
+template<typename Lhs, typename Rhs> class Cross;
+template<typename Derived> class QuaternionBase;
+template<typename Scalar> class Rotation2D;
+template<typename Scalar> class AngleAxis;
+template<typename Scalar,int Dim> class Translation;
+template<typename Scalar,int Dim> class AlignedBox;
+template<typename Scalar, int Options = AutoAlign> class Quaternion;
+template<typename Scalar,int Dim,int Mode,int _Options=AutoAlign> class Transform;
+template <typename _Scalar, int _AmbientDim, int Options=AutoAlign> class ParametrizedLine;
+template <typename _Scalar, int _AmbientDim, int Options=AutoAlign> class Hyperplane;
+template<typename Scalar> class UniformScaling;
+template<typename MatrixType,int Direction> class Homogeneous;
+
+// Sparse module:
+template<typename Derived> class SparseMatrixBase;
+
+// MatrixFunctions module
+template<typename Derived> struct MatrixExponentialReturnValue;
+template<typename Derived> class MatrixFunctionReturnValue;
+template<typename Derived> class MatrixSquareRootReturnValue;
+template<typename Derived> class MatrixLogarithmReturnValue;
+template<typename Derived> class MatrixPowerReturnValue;
+template<typename Derived> class MatrixComplexPowerReturnValue;
+
+namespace internal {
+template <typename Scalar>
+struct stem_function
+{
+ typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar;
+ typedef ComplexScalar type(ComplexScalar, int);
+};
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_FORWARDDECLARATIONS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/IndexedViewHelper.h b/src/3rdparty/eigen/Eigen/src/Core/util/IndexedViewHelper.h
new file mode 100644
index 000000000..f85de305f
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/IndexedViewHelper.h
@@ -0,0 +1,186 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#ifndef EIGEN_INDEXED_VIEW_HELPER_H
+#define EIGEN_INDEXED_VIEW_HELPER_H
+
+namespace Eigen {
+
+namespace internal {
+struct symbolic_last_tag {};
+}
+
+/** \var last
+ * \ingroup Core_Module
+ *
+ * Can be used as a parameter to Eigen::seq and Eigen::seqN functions to symbolically reference the last element/row/columns
+ * of the underlying vector or matrix once passed to DenseBase::operator()(const RowIndices&, const ColIndices&).
+ *
+ * This symbolic placeholder supports standard arithmetic operations.
+ *
+ * A typical usage example would be:
+ * \code
+ * using namespace Eigen;
+ * using Eigen::last;
+ * VectorXd v(n);
+ * v(seq(2,last-2)).setOnes();
+ * \endcode
+ *
+ * \sa end
+ */
+static const symbolic::SymbolExpr<internal::symbolic_last_tag> last; // PLEASE use Eigen::last instead of Eigen::placeholders::last
+
+/** \var lastp1
+ * \ingroup Core_Module
+ *
+ * Can be used as a parameter to Eigen::seq and Eigen::seqN functions to symbolically
+ * reference the last+1 element/row/columns of the underlying vector or matrix once
+ * passed to DenseBase::operator()(const RowIndices&, const ColIndices&).
+ *
+ * This symbolic placeholder supports standard arithmetic operations.
+ * It is essentially an alias to last+fix<1>.
+ *
+ * \sa last
+ */
+#ifdef EIGEN_PARSED_BY_DOXYGEN
+static const auto lastp1 = last+fix<1>;
+#else
+// Using a FixedExpr<1> expression is important here to make sure the compiler
+// can fully optimize the computation starting indices with zero overhead.
+static const symbolic::AddExpr<symbolic::SymbolExpr<internal::symbolic_last_tag>,symbolic::ValueExpr<Eigen::internal::FixedInt<1> > > lastp1(last+fix<1>());
+#endif
+
+namespace internal {
+
+ // Replace symbolic last/end "keywords" by their true runtime value
+inline Index eval_expr_given_size(Index x, Index /* size */) { return x; }
+
+template<int N>
+FixedInt<N> eval_expr_given_size(FixedInt<N> x, Index /*size*/) { return x; }
+
+template<typename Derived>
+Index eval_expr_given_size(const symbolic::BaseExpr<Derived> &x, Index size)
+{
+ return x.derived().eval(last=size-1);
+}
+
+// Extract increment/step at compile time
+template<typename T, typename EnableIf = void> struct get_compile_time_incr {
+ enum { value = UndefinedIncr };
+};
+
+// Analogue of std::get<0>(x), but tailored for our needs.
+template<typename T>
+EIGEN_CONSTEXPR Index first(const T& x) EIGEN_NOEXCEPT { return x.first(); }
+
+// IndexedViewCompatibleType/makeIndexedViewCompatible turn an arbitrary object of type T into something usable by MatrixSlice
+// The generic implementation is a no-op
+template<typename T,int XprSize,typename EnableIf=void>
+struct IndexedViewCompatibleType {
+ typedef T type;
+};
+
+template<typename T,typename Q>
+const T& makeIndexedViewCompatible(const T& x, Index /*size*/, Q) { return x; }
+
+//--------------------------------------------------------------------------------
+// Handling of a single Index
+//--------------------------------------------------------------------------------
+
+struct SingleRange {
+ enum {
+ SizeAtCompileTime = 1
+ };
+ SingleRange(Index val) : m_value(val) {}
+ Index operator[](Index) const { return m_value; }
+ static EIGEN_CONSTEXPR Index size() EIGEN_NOEXCEPT { return 1; }
+ Index first() const EIGEN_NOEXCEPT { return m_value; }
+ Index m_value;
+};
+
+template<> struct get_compile_time_incr<SingleRange> {
+ enum { value = 1 }; // 1 or 0 ??
+};
+
+// Turn a single index into something that looks like an array (i.e., that exposes a .size(), and operator[](int) methods)
+template<typename T, int XprSize>
+struct IndexedViewCompatibleType<T,XprSize,typename internal::enable_if<internal::is_integral<T>::value>::type> {
+ // Here we could simply use Array, but maybe it's less work for the compiler to use
+ // a simpler wrapper as SingleRange
+ //typedef Eigen::Array<Index,1,1> type;
+ typedef SingleRange type;
+};
+
+template<typename T, int XprSize>
+struct IndexedViewCompatibleType<T, XprSize, typename enable_if<symbolic::is_symbolic<T>::value>::type> {
+ typedef SingleRange type;
+};
+
+
+template<typename T>
+typename enable_if<symbolic::is_symbolic<T>::value,SingleRange>::type
+makeIndexedViewCompatible(const T& id, Index size, SpecializedType) {
+ return eval_expr_given_size(id,size);
+}
+
+//--------------------------------------------------------------------------------
+// Handling of all
+//--------------------------------------------------------------------------------
+
+struct all_t { all_t() {} };
+
+// Convert a symbolic 'all' into a usable range type
+template<int XprSize>
+struct AllRange {
+ enum { SizeAtCompileTime = XprSize };
+ AllRange(Index size = XprSize) : m_size(size) {}
+ EIGEN_CONSTEXPR Index operator[](Index i) const EIGEN_NOEXCEPT { return i; }
+ EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT { return m_size.value(); }
+ EIGEN_CONSTEXPR Index first() const EIGEN_NOEXCEPT { return 0; }
+ variable_if_dynamic<Index,XprSize> m_size;
+};
+
+template<int XprSize>
+struct IndexedViewCompatibleType<all_t,XprSize> {
+ typedef AllRange<XprSize> type;
+};
+
+template<typename XprSizeType>
+inline AllRange<get_fixed_value<XprSizeType>::value> makeIndexedViewCompatible(all_t , XprSizeType size, SpecializedType) {
+ return AllRange<get_fixed_value<XprSizeType>::value>(size);
+}
+
+template<int Size> struct get_compile_time_incr<AllRange<Size> > {
+ enum { value = 1 };
+};
+
+} // end namespace internal
+
+
+/** \var all
+ * \ingroup Core_Module
+ * Can be used as a parameter to DenseBase::operator()(const RowIndices&, const ColIndices&) to index all rows or columns
+ */
+static const Eigen::internal::all_t all; // PLEASE use Eigen::all instead of Eigen::placeholders::all
+
+
+namespace placeholders {
+ typedef symbolic::SymbolExpr<internal::symbolic_last_tag> last_t;
+ typedef symbolic::AddExpr<symbolic::SymbolExpr<internal::symbolic_last_tag>,symbolic::ValueExpr<Eigen::internal::FixedInt<1> > > end_t;
+ typedef Eigen::internal::all_t all_t;
+
+ EIGEN_DEPRECATED static const all_t all = Eigen::all; // PLEASE use Eigen::all instead of Eigen::placeholders::all
+ EIGEN_DEPRECATED static const last_t last = Eigen::last; // PLEASE use Eigen::last instead of Eigen::placeholders::last
+ EIGEN_DEPRECATED static const end_t end = Eigen::lastp1; // PLEASE use Eigen::lastp1 instead of Eigen::placeholders::end
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_INDEXED_VIEW_HELPER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/IntegralConstant.h b/src/3rdparty/eigen/Eigen/src/Core/util/IntegralConstant.h
new file mode 100644
index 000000000..945d426ea
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/IntegralConstant.h
@@ -0,0 +1,272 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#ifndef EIGEN_INTEGRAL_CONSTANT_H
+#define EIGEN_INTEGRAL_CONSTANT_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<int N> class FixedInt;
+template<int N> class VariableAndFixedInt;
+
+/** \internal
+ * \class FixedInt
+ *
+ * This class embeds a compile-time integer \c N.
+ *
+ * It is similar to c++11 std::integral_constant<int,N> but with some additional features
+ * such as:
+ * - implicit conversion to int
+ * - arithmetic and some bitwise operators: -, +, *, /, %, &, |
+ * - c++98/14 compatibility with fix<N> and fix<N>() syntax to define integral constants.
+ *
+ * It is strongly discouraged to directly deal with this class FixedInt. Instances are expcected to
+ * be created by the user using Eigen::fix<N> or Eigen::fix<N>(). In C++98-11, the former syntax does
+ * not create a FixedInt<N> instance but rather a point to function that needs to be \em cleaned-up
+ * using the generic helper:
+ * \code
+ * internal::cleanup_index_type<T>::type
+ * internal::cleanup_index_type<T,DynamicKey>::type
+ * \endcode
+ * where T can a FixedInt<N>, a pointer to function FixedInt<N> (*)(), or numerous other integer-like representations.
+ * \c DynamicKey is either Dynamic (default) or DynamicIndex and used to identify true compile-time values.
+ *
+ * For convenience, you can extract the compile-time value \c N in a generic way using the following helper:
+ * \code
+ * internal::get_fixed_value<T,DefaultVal>::value
+ * \endcode
+ * that will give you \c N if T equals FixedInt<N> or FixedInt<N> (*)(), and \c DefaultVal if T does not embed any compile-time value (e.g., T==int).
+ *
+ * \sa fix<N>, class VariableAndFixedInt
+ */
+template<int N> class FixedInt
+{
+public:
+ static const int value = N;
+ EIGEN_CONSTEXPR operator int() const { return value; }
+ FixedInt() {}
+ FixedInt( VariableAndFixedInt<N> other) {
+ #ifndef EIGEN_INTERNAL_DEBUGGING
+ EIGEN_UNUSED_VARIABLE(other);
+ #endif
+ eigen_internal_assert(int(other)==N);
+ }
+
+ FixedInt<-N> operator-() const { return FixedInt<-N>(); }
+ template<int M>
+ FixedInt<N+M> operator+( FixedInt<M>) const { return FixedInt<N+M>(); }
+ template<int M>
+ FixedInt<N-M> operator-( FixedInt<M>) const { return FixedInt<N-M>(); }
+ template<int M>
+ FixedInt<N*M> operator*( FixedInt<M>) const { return FixedInt<N*M>(); }
+ template<int M>
+ FixedInt<N/M> operator/( FixedInt<M>) const { return FixedInt<N/M>(); }
+ template<int M>
+ FixedInt<N%M> operator%( FixedInt<M>) const { return FixedInt<N%M>(); }
+ template<int M>
+ FixedInt<N|M> operator|( FixedInt<M>) const { return FixedInt<N|M>(); }
+ template<int M>
+ FixedInt<N&M> operator&( FixedInt<M>) const { return FixedInt<N&M>(); }
+
+#if EIGEN_HAS_CXX14_VARIABLE_TEMPLATES
+ // Needed in C++14 to allow fix<N>():
+ FixedInt operator() () const { return *this; }
+
+ VariableAndFixedInt<N> operator() (int val) const { return VariableAndFixedInt<N>(val); }
+#else
+ FixedInt ( FixedInt<N> (*)() ) {}
+#endif
+
+#if EIGEN_HAS_CXX11
+ FixedInt(std::integral_constant<int,N>) {}
+#endif
+};
+
+/** \internal
+ * \class VariableAndFixedInt
+ *
+ * This class embeds both a compile-time integer \c N and a runtime integer.
+ * Both values are supposed to be equal unless the compile-time value \c N has a special
+ * value meaning that the runtime-value should be used. Depending on the context, this special
+ * value can be either Eigen::Dynamic (for positive quantities) or Eigen::DynamicIndex (for
+ * quantities that can be negative).
+ *
+ * It is the return-type of the function Eigen::fix<N>(int), and most of the time this is the only
+ * way it is used. It is strongly discouraged to directly deal with instances of VariableAndFixedInt.
+ * Indeed, in order to write generic code, it is the responsibility of the callee to properly convert
+ * it to either a true compile-time quantity (i.e. a FixedInt<N>), or to a runtime quantity (e.g., an Index)
+ * using the following generic helper:
+ * \code
+ * internal::cleanup_index_type<T>::type
+ * internal::cleanup_index_type<T,DynamicKey>::type
+ * \endcode
+ * where T can be a template instantiation of VariableAndFixedInt or numerous other integer-like representations.
+ * \c DynamicKey is either Dynamic (default) or DynamicIndex and used to identify true compile-time values.
+ *
+ * For convenience, you can also extract the compile-time value \c N using the following helper:
+ * \code
+ * internal::get_fixed_value<T,DefaultVal>::value
+ * \endcode
+ * that will give you \c N if T equals VariableAndFixedInt<N>, and \c DefaultVal if T does not embed any compile-time value (e.g., T==int).
+ *
+ * \sa fix<N>(int), class FixedInt
+ */
+template<int N> class VariableAndFixedInt
+{
+public:
+ static const int value = N;
+ operator int() const { return m_value; }
+ VariableAndFixedInt(int val) { m_value = val; }
+protected:
+ int m_value;
+};
+
+template<typename T, int Default=Dynamic> struct get_fixed_value {
+ static const int value = Default;
+};
+
+template<int N,int Default> struct get_fixed_value<FixedInt<N>,Default> {
+ static const int value = N;
+};
+
+#if !EIGEN_HAS_CXX14
+template<int N,int Default> struct get_fixed_value<FixedInt<N> (*)(),Default> {
+ static const int value = N;
+};
+#endif
+
+template<int N,int Default> struct get_fixed_value<VariableAndFixedInt<N>,Default> {
+ static const int value = N ;
+};
+
+template<typename T, int N, int Default>
+struct get_fixed_value<variable_if_dynamic<T,N>,Default> {
+ static const int value = N;
+};
+
+template<typename T> EIGEN_DEVICE_FUNC Index get_runtime_value(const T &x) { return x; }
+#if !EIGEN_HAS_CXX14
+template<int N> EIGEN_DEVICE_FUNC Index get_runtime_value(FixedInt<N> (*)()) { return N; }
+#endif
+
+// Cleanup integer/FixedInt/VariableAndFixedInt/etc types:
+
+// By default, no cleanup:
+template<typename T, int DynamicKey=Dynamic, typename EnableIf=void> struct cleanup_index_type { typedef T type; };
+
+// Convert any integral type (e.g., short, int, unsigned int, etc.) to Eigen::Index
+template<typename T, int DynamicKey> struct cleanup_index_type<T,DynamicKey,typename internal::enable_if<internal::is_integral<T>::value>::type> { typedef Index type; };
+
+#if !EIGEN_HAS_CXX14
+// In c++98/c++11, fix<N> is a pointer to function that we better cleanup to a true FixedInt<N>:
+template<int N, int DynamicKey> struct cleanup_index_type<FixedInt<N> (*)(), DynamicKey> { typedef FixedInt<N> type; };
+#endif
+
+// If VariableAndFixedInt does not match DynamicKey, then we turn it to a pure compile-time value:
+template<int N, int DynamicKey> struct cleanup_index_type<VariableAndFixedInt<N>, DynamicKey> { typedef FixedInt<N> type; };
+// If VariableAndFixedInt matches DynamicKey, then we turn it to a pure runtime-value (aka Index):
+template<int DynamicKey> struct cleanup_index_type<VariableAndFixedInt<DynamicKey>, DynamicKey> { typedef Index type; };
+
+#if EIGEN_HAS_CXX11
+template<int N, int DynamicKey> struct cleanup_index_type<std::integral_constant<int,N>, DynamicKey> { typedef FixedInt<N> type; };
+#endif
+
+} // end namespace internal
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+
+#if EIGEN_HAS_CXX14_VARIABLE_TEMPLATES
+template<int N>
+static const internal::FixedInt<N> fix{};
+#else
+template<int N>
+inline internal::FixedInt<N> fix() { return internal::FixedInt<N>(); }
+
+// The generic typename T is mandatory. Otherwise, a code like fix<N> could refer to either the function above or this next overload.
+// This way a code like fix<N> can only refer to the previous function.
+template<int N,typename T>
+inline internal::VariableAndFixedInt<N> fix(T val) { return internal::VariableAndFixedInt<N>(internal::convert_index<int>(val)); }
+#endif
+
+#else // EIGEN_PARSED_BY_DOXYGEN
+
+/** \var fix<N>()
+ * \ingroup Core_Module
+ *
+ * This \em identifier permits to construct an object embedding a compile-time integer \c N.
+ *
+ * \tparam N the compile-time integer value
+ *
+ * It is typically used in conjunction with the Eigen::seq and Eigen::seqN functions to pass compile-time values to them:
+ * \code
+ * seqN(10,fix<4>,fix<-3>) // <=> [10 7 4 1]
+ * \endcode
+ *
+ * See also the function fix(int) to pass both a compile-time and runtime value.
+ *
+ * In c++14, it is implemented as:
+ * \code
+ * template<int N> static const internal::FixedInt<N> fix{};
+ * \endcode
+ * where internal::FixedInt<N> is an internal template class similar to
+ * <a href="http://en.cppreference.com/w/cpp/types/integral_constant">\c std::integral_constant </a><tt> <int,N> </tt>
+ * Here, \c fix<N> is thus an object of type \c internal::FixedInt<N>.
+ *
+ * In c++98/11, it is implemented as a function:
+ * \code
+ * template<int N> inline internal::FixedInt<N> fix();
+ * \endcode
+ * Here internal::FixedInt<N> is thus a pointer to function.
+ *
+ * If for some reason you want a true object in c++98 then you can write: \code fix<N>() \endcode which is also valid in c++14.
+ *
+ * \sa fix<N>(int), seq, seqN
+ */
+template<int N>
+static const auto fix();
+
+/** \fn fix<N>(int)
+ * \ingroup Core_Module
+ *
+ * This function returns an object embedding both a compile-time integer \c N, and a fallback runtime value \a val.
+ *
+ * \tparam N the compile-time integer value
+ * \param val the fallback runtime integer value
+ *
+ * This function is a more general version of the \ref fix identifier/function that can be used in template code
+ * where the compile-time value could turn out to actually mean "undefined at compile-time". For positive integers
+ * such as a size or a dimension, this case is identified by Eigen::Dynamic, whereas runtime signed integers
+ * (e.g., an increment/stride) are identified as Eigen::DynamicIndex. In such a case, the runtime value \a val
+ * will be used as a fallback.
+ *
+ * A typical use case would be:
+ * \code
+ * template<typename Derived> void foo(const MatrixBase<Derived> &mat) {
+ * const int N = Derived::RowsAtCompileTime==Dynamic ? Dynamic : Derived::RowsAtCompileTime/2;
+ * const int n = mat.rows()/2;
+ * ... mat( seqN(0,fix<N>(n) ) ...;
+ * }
+ * \endcode
+ * In this example, the function Eigen::seqN knows that the second argument is expected to be a size.
+ * If the passed compile-time value N equals Eigen::Dynamic, then the proxy object returned by fix will be dissmissed, and converted to an Eigen::Index of value \c n.
+ * Otherwise, the runtime-value \c n will be dissmissed, and the returned ArithmeticSequence will be of the exact same type as <tt> seqN(0,fix<N>) </tt>.
+ *
+ * \sa fix, seqN, class ArithmeticSequence
+ */
+template<int N>
+static const auto fix(int val);
+
+#endif // EIGEN_PARSED_BY_DOXYGEN
+
+} // end namespace Eigen
+
+#endif // EIGEN_INTEGRAL_CONSTANT_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/MKL_support.h b/src/3rdparty/eigen/Eigen/src/Core/util/MKL_support.h
new file mode 100644
index 000000000..17963fad4
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/MKL_support.h
@@ -0,0 +1,137 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to Intel(R) MKL
+ * Include file with common MKL declarations
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_MKL_SUPPORT_H
+#define EIGEN_MKL_SUPPORT_H
+
+#ifdef EIGEN_USE_MKL_ALL
+ #ifndef EIGEN_USE_BLAS
+ #define EIGEN_USE_BLAS
+ #endif
+ #ifndef EIGEN_USE_LAPACKE
+ #define EIGEN_USE_LAPACKE
+ #endif
+ #ifndef EIGEN_USE_MKL_VML
+ #define EIGEN_USE_MKL_VML
+ #endif
+#endif
+
+#ifdef EIGEN_USE_LAPACKE_STRICT
+ #define EIGEN_USE_LAPACKE
+#endif
+
+#if defined(EIGEN_USE_MKL_VML) && !defined(EIGEN_USE_MKL)
+ #define EIGEN_USE_MKL
+#endif
+
+
+#if defined EIGEN_USE_MKL
+# if (!defined MKL_DIRECT_CALL) && (!defined EIGEN_MKL_NO_DIRECT_CALL)
+# define MKL_DIRECT_CALL
+# define MKL_DIRECT_CALL_JUST_SET
+# endif
+# include <mkl.h>
+/*Check IMKL version for compatibility: < 10.3 is not usable with Eigen*/
+# ifndef INTEL_MKL_VERSION
+# undef EIGEN_USE_MKL /* INTEL_MKL_VERSION is not even defined on older versions */
+# elif INTEL_MKL_VERSION < 100305 /* the intel-mkl-103-release-notes say this was when the lapacke.h interface was added*/
+# undef EIGEN_USE_MKL
+# endif
+# ifndef EIGEN_USE_MKL
+ /*If the MKL version is too old, undef everything*/
+# undef EIGEN_USE_MKL_ALL
+# undef EIGEN_USE_LAPACKE
+# undef EIGEN_USE_MKL_VML
+# undef EIGEN_USE_LAPACKE_STRICT
+# undef EIGEN_USE_LAPACKE
+# ifdef MKL_DIRECT_CALL_JUST_SET
+# undef MKL_DIRECT_CALL
+# endif
+# endif
+#endif
+
+#if defined EIGEN_USE_MKL
+
+#define EIGEN_MKL_VML_THRESHOLD 128
+
+/* MKL_DOMAIN_BLAS, etc are defined only in 10.3 update 7 */
+/* MKL_BLAS, etc are not defined in 11.2 */
+#ifdef MKL_DOMAIN_ALL
+#define EIGEN_MKL_DOMAIN_ALL MKL_DOMAIN_ALL
+#else
+#define EIGEN_MKL_DOMAIN_ALL MKL_ALL
+#endif
+
+#ifdef MKL_DOMAIN_BLAS
+#define EIGEN_MKL_DOMAIN_BLAS MKL_DOMAIN_BLAS
+#else
+#define EIGEN_MKL_DOMAIN_BLAS MKL_BLAS
+#endif
+
+#ifdef MKL_DOMAIN_FFT
+#define EIGEN_MKL_DOMAIN_FFT MKL_DOMAIN_FFT
+#else
+#define EIGEN_MKL_DOMAIN_FFT MKL_FFT
+#endif
+
+#ifdef MKL_DOMAIN_VML
+#define EIGEN_MKL_DOMAIN_VML MKL_DOMAIN_VML
+#else
+#define EIGEN_MKL_DOMAIN_VML MKL_VML
+#endif
+
+#ifdef MKL_DOMAIN_PARDISO
+#define EIGEN_MKL_DOMAIN_PARDISO MKL_DOMAIN_PARDISO
+#else
+#define EIGEN_MKL_DOMAIN_PARDISO MKL_PARDISO
+#endif
+#endif
+
+#if defined(EIGEN_USE_BLAS) && !defined(EIGEN_USE_MKL)
+#include "../../misc/blas.h"
+#endif
+
+namespace Eigen {
+
+typedef std::complex<double> dcomplex;
+typedef std::complex<float> scomplex;
+
+#if defined(EIGEN_USE_MKL)
+typedef MKL_INT BlasIndex;
+#else
+typedef int BlasIndex;
+#endif
+
+} // end namespace Eigen
+
+
+#endif // EIGEN_MKL_SUPPORT_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/Macros.h b/src/3rdparty/eigen/Eigen/src/Core/util/Macros.h
new file mode 100644
index 000000000..986c3d44d
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/Macros.h
@@ -0,0 +1,1464 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MACROS_H
+#define EIGEN_MACROS_H
+
+//------------------------------------------------------------------------------------------
+// Eigen version and basic defaults
+//------------------------------------------------------------------------------------------
+
+#define EIGEN_WORLD_VERSION 3
+#define EIGEN_MAJOR_VERSION 4
+#define EIGEN_MINOR_VERSION 0
+
+#define EIGEN_VERSION_AT_LEAST(x,y,z) (EIGEN_WORLD_VERSION>x || (EIGEN_WORLD_VERSION>=x && \
+ (EIGEN_MAJOR_VERSION>y || (EIGEN_MAJOR_VERSION>=y && \
+ EIGEN_MINOR_VERSION>=z))))
+
+#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
+#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION Eigen::RowMajor
+#else
+#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION Eigen::ColMajor
+#endif
+
+#ifndef EIGEN_DEFAULT_DENSE_INDEX_TYPE
+#define EIGEN_DEFAULT_DENSE_INDEX_TYPE std::ptrdiff_t
+#endif
+
+// Upperbound on the C++ version to use.
+// Expected values are 03, 11, 14, 17, etc.
+// By default, let's use an arbitrarily large C++ version.
+#ifndef EIGEN_MAX_CPP_VER
+#define EIGEN_MAX_CPP_VER 99
+#endif
+
+/** Allows to disable some optimizations which might affect the accuracy of the result.
+ * Such optimization are enabled by default, and set EIGEN_FAST_MATH to 0 to disable them.
+ * They currently include:
+ * - single precision ArrayBase::sin() and ArrayBase::cos() for SSE and AVX vectorization.
+ */
+#ifndef EIGEN_FAST_MATH
+#define EIGEN_FAST_MATH 1
+#endif
+
+#ifndef EIGEN_STACK_ALLOCATION_LIMIT
+// 131072 == 128 KB
+#define EIGEN_STACK_ALLOCATION_LIMIT 131072
+#endif
+
+//------------------------------------------------------------------------------------------
+// Compiler identification, EIGEN_COMP_*
+//------------------------------------------------------------------------------------------
+
+/// \internal EIGEN_COMP_GNUC set to 1 for all compilers compatible with GCC
+#ifdef __GNUC__
+ #define EIGEN_COMP_GNUC (__GNUC__*10+__GNUC_MINOR__)
+#else
+ #define EIGEN_COMP_GNUC 0
+#endif
+
+/// \internal EIGEN_COMP_CLANG set to major+minor version (e.g., 307 for clang 3.7) if the compiler is clang
+#if defined(__clang__)
+ #define EIGEN_COMP_CLANG (__clang_major__*100+__clang_minor__)
+#else
+ #define EIGEN_COMP_CLANG 0
+#endif
+
+/// \internal EIGEN_COMP_CASTXML set to 1 if being preprocessed by CastXML
+#if defined(__castxml__)
+ #define EIGEN_COMP_CASTXML 1
+#else
+ #define EIGEN_COMP_CASTXML 0
+#endif
+
+/// \internal EIGEN_COMP_LLVM set to 1 if the compiler backend is llvm
+#if defined(__llvm__)
+ #define EIGEN_COMP_LLVM 1
+#else
+ #define EIGEN_COMP_LLVM 0
+#endif
+
+/// \internal EIGEN_COMP_ICC set to __INTEL_COMPILER if the compiler is Intel compiler, 0 otherwise
+#if defined(__INTEL_COMPILER)
+ #define EIGEN_COMP_ICC __INTEL_COMPILER
+#else
+ #define EIGEN_COMP_ICC 0
+#endif
+
+/// \internal EIGEN_COMP_MINGW set to 1 if the compiler is mingw
+#if defined(__MINGW32__)
+ #define EIGEN_COMP_MINGW 1
+#else
+ #define EIGEN_COMP_MINGW 0
+#endif
+
+/// \internal EIGEN_COMP_SUNCC set to 1 if the compiler is Solaris Studio
+#if defined(__SUNPRO_CC)
+ #define EIGEN_COMP_SUNCC 1
+#else
+ #define EIGEN_COMP_SUNCC 0
+#endif
+
+/// \internal EIGEN_COMP_MSVC set to _MSC_VER if the compiler is Microsoft Visual C++, 0 otherwise.
+#if defined(_MSC_VER)
+ #define EIGEN_COMP_MSVC _MSC_VER
+#else
+ #define EIGEN_COMP_MSVC 0
+#endif
+
+#if defined(__NVCC__)
+#if defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 9)
+ #define EIGEN_COMP_NVCC ((__CUDACC_VER_MAJOR__ * 10000) + (__CUDACC_VER_MINOR__ * 100))
+#elif defined(__CUDACC_VER__)
+ #define EIGEN_COMP_NVCC __CUDACC_VER__
+#else
+ #error "NVCC did not define compiler version."
+#endif
+#else
+ #define EIGEN_COMP_NVCC 0
+#endif
+
+// For the record, here is a table summarizing the possible values for EIGEN_COMP_MSVC:
+// name ver MSC_VER
+// 2008 9 1500
+// 2010 10 1600
+// 2012 11 1700
+// 2013 12 1800
+// 2015 14 1900
+// "15" 15 1900
+// 2017-14.1 15.0 1910
+// 2017-14.11 15.3 1911
+// 2017-14.12 15.5 1912
+// 2017-14.13 15.6 1913
+// 2017-14.14 15.7 1914
+
+/// \internal EIGEN_COMP_MSVC_LANG set to _MSVC_LANG if the compiler is Microsoft Visual C++, 0 otherwise.
+#if defined(_MSVC_LANG)
+ #define EIGEN_COMP_MSVC_LANG _MSVC_LANG
+#else
+ #define EIGEN_COMP_MSVC_LANG 0
+#endif
+
+// For the record, here is a table summarizing the possible values for EIGEN_COMP_MSVC_LANG:
+// MSVC option Standard MSVC_LANG
+// /std:c++14 (default as of VS 2019) C++14 201402L
+// /std:c++17 C++17 201703L
+// /std:c++latest >C++17 >201703L
+
+/// \internal EIGEN_COMP_MSVC_STRICT set to 1 if the compiler is really Microsoft Visual C++ and not ,e.g., ICC or clang-cl
+#if EIGEN_COMP_MSVC && !(EIGEN_COMP_ICC || EIGEN_COMP_LLVM || EIGEN_COMP_CLANG)
+ #define EIGEN_COMP_MSVC_STRICT _MSC_VER
+#else
+ #define EIGEN_COMP_MSVC_STRICT 0
+#endif
+
+/// \internal EIGEN_COMP_IBM set to xlc version if the compiler is IBM XL C++
+// XLC version
+// 3.1 0x0301
+// 4.5 0x0405
+// 5.0 0x0500
+// 12.1 0x0C01
+#if defined(__IBMCPP__) || defined(__xlc__) || defined(__ibmxl__)
+ #define EIGEN_COMP_IBM __xlC__
+#else
+ #define EIGEN_COMP_IBM 0
+#endif
+
+/// \internal EIGEN_COMP_PGI set to PGI version if the compiler is Portland Group Compiler
+#if defined(__PGI)
+ #define EIGEN_COMP_PGI (__PGIC__*100+__PGIC_MINOR__)
+#else
+ #define EIGEN_COMP_PGI 0
+#endif
+
+/// \internal EIGEN_COMP_ARM set to 1 if the compiler is ARM Compiler
+#if defined(__CC_ARM) || defined(__ARMCC_VERSION)
+ #define EIGEN_COMP_ARM 1
+#else
+ #define EIGEN_COMP_ARM 0
+#endif
+
+/// \internal EIGEN_COMP_EMSCRIPTEN set to 1 if the compiler is Emscripten Compiler
+#if defined(__EMSCRIPTEN__)
+ #define EIGEN_COMP_EMSCRIPTEN 1
+#else
+ #define EIGEN_COMP_EMSCRIPTEN 0
+#endif
+
+
+/// \internal EIGEN_GNUC_STRICT set to 1 if the compiler is really GCC and not a compatible compiler (e.g., ICC, clang, mingw, etc.)
+#if EIGEN_COMP_GNUC && !(EIGEN_COMP_CLANG || EIGEN_COMP_ICC || EIGEN_COMP_MINGW || EIGEN_COMP_PGI || EIGEN_COMP_IBM || EIGEN_COMP_ARM || EIGEN_COMP_EMSCRIPTEN)
+ #define EIGEN_COMP_GNUC_STRICT 1
+#else
+ #define EIGEN_COMP_GNUC_STRICT 0
+#endif
+
+
+#if EIGEN_COMP_GNUC
+ #define EIGEN_GNUC_AT_LEAST(x,y) ((__GNUC__==x && __GNUC_MINOR__>=y) || __GNUC__>x)
+ #define EIGEN_GNUC_AT_MOST(x,y) ((__GNUC__==x && __GNUC_MINOR__<=y) || __GNUC__<x)
+ #define EIGEN_GNUC_AT(x,y) ( __GNUC__==x && __GNUC_MINOR__==y )
+#else
+ #define EIGEN_GNUC_AT_LEAST(x,y) 0
+ #define EIGEN_GNUC_AT_MOST(x,y) 0
+ #define EIGEN_GNUC_AT(x,y) 0
+#endif
+
+// FIXME: could probably be removed as we do not support gcc 3.x anymore
+#if EIGEN_COMP_GNUC && (__GNUC__ <= 3)
+#define EIGEN_GCC3_OR_OLDER 1
+#else
+#define EIGEN_GCC3_OR_OLDER 0
+#endif
+
+
+
+//------------------------------------------------------------------------------------------
+// Architecture identification, EIGEN_ARCH_*
+//------------------------------------------------------------------------------------------
+
+
+#if defined(__x86_64__) || (defined(_M_X64) && !defined(_M_ARM64EC)) || defined(__amd64)
+ #define EIGEN_ARCH_x86_64 1
+#else
+ #define EIGEN_ARCH_x86_64 0
+#endif
+
+#if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__i386)
+ #define EIGEN_ARCH_i386 1
+#else
+ #define EIGEN_ARCH_i386 0
+#endif
+
+#if EIGEN_ARCH_x86_64 || EIGEN_ARCH_i386
+ #define EIGEN_ARCH_i386_OR_x86_64 1
+#else
+ #define EIGEN_ARCH_i386_OR_x86_64 0
+#endif
+
+/// \internal EIGEN_ARCH_ARM set to 1 if the architecture is ARM
+#if defined(__arm__)
+ #define EIGEN_ARCH_ARM 1
+#else
+ #define EIGEN_ARCH_ARM 0
+#endif
+
+/// \internal EIGEN_ARCH_ARM64 set to 1 if the architecture is ARM64
+#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
+ #define EIGEN_ARCH_ARM64 1
+#else
+ #define EIGEN_ARCH_ARM64 0
+#endif
+
+/// \internal EIGEN_ARCH_ARM_OR_ARM64 set to 1 if the architecture is ARM or ARM64
+#if EIGEN_ARCH_ARM || EIGEN_ARCH_ARM64
+ #define EIGEN_ARCH_ARM_OR_ARM64 1
+#else
+ #define EIGEN_ARCH_ARM_OR_ARM64 0
+#endif
+
+/// \internal EIGEN_ARCH_ARMV8 set to 1 if the architecture is armv8 or greater.
+#if EIGEN_ARCH_ARM_OR_ARM64 && defined(__ARM_ARCH) && __ARM_ARCH >= 8
+#define EIGEN_ARCH_ARMV8 1
+#else
+#define EIGEN_ARCH_ARMV8 0
+#endif
+
+
+/// \internal EIGEN_HAS_ARM64_FP16 set to 1 if the architecture provides an IEEE
+/// compliant Arm fp16 type
+#if EIGEN_ARCH_ARM64
+ #ifndef EIGEN_HAS_ARM64_FP16
+ #if defined(__ARM_FP16_FORMAT_IEEE)
+ #define EIGEN_HAS_ARM64_FP16 1
+ #else
+ #define EIGEN_HAS_ARM64_FP16 0
+ #endif
+ #endif
+#endif
+
+/// \internal EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC set to 1 if the architecture
+/// supports Neon vector intrinsics for fp16.
+#if EIGEN_ARCH_ARM64
+ #ifndef EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC
+ #if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+ #define EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC 1
+ #else
+ #define EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC 0
+ #endif
+ #endif
+#endif
+
+/// \internal EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC set to 1 if the architecture
+/// supports Neon scalar intrinsics for fp16.
+#if EIGEN_ARCH_ARM64
+ #ifndef EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC
+ #if defined(__ARM_FEATURE_FP16_SCALAR_ARITHMETIC)
+ #define EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC 1
+ #endif
+ #endif
+#endif
+
+/// \internal EIGEN_ARCH_MIPS set to 1 if the architecture is MIPS
+#if defined(__mips__) || defined(__mips)
+ #define EIGEN_ARCH_MIPS 1
+#else
+ #define EIGEN_ARCH_MIPS 0
+#endif
+
+/// \internal EIGEN_ARCH_SPARC set to 1 if the architecture is SPARC
+#if defined(__sparc__) || defined(__sparc)
+ #define EIGEN_ARCH_SPARC 1
+#else
+ #define EIGEN_ARCH_SPARC 0
+#endif
+
+/// \internal EIGEN_ARCH_IA64 set to 1 if the architecture is Intel Itanium
+#if defined(__ia64__)
+ #define EIGEN_ARCH_IA64 1
+#else
+ #define EIGEN_ARCH_IA64 0
+#endif
+
+/// \internal EIGEN_ARCH_PPC set to 1 if the architecture is PowerPC
+#if defined(__powerpc__) || defined(__ppc__) || defined(_M_PPC)
+ #define EIGEN_ARCH_PPC 1
+#else
+ #define EIGEN_ARCH_PPC 0
+#endif
+
+
+
+//------------------------------------------------------------------------------------------
+// Operating system identification, EIGEN_OS_*
+//------------------------------------------------------------------------------------------
+
+/// \internal EIGEN_OS_UNIX set to 1 if the OS is a unix variant
+#if defined(__unix__) || defined(__unix)
+ #define EIGEN_OS_UNIX 1
+#else
+ #define EIGEN_OS_UNIX 0
+#endif
+
+/// \internal EIGEN_OS_LINUX set to 1 if the OS is based on Linux kernel
+#if defined(__linux__)
+ #define EIGEN_OS_LINUX 1
+#else
+ #define EIGEN_OS_LINUX 0
+#endif
+
+/// \internal EIGEN_OS_ANDROID set to 1 if the OS is Android
+// note: ANDROID is defined when using ndk_build, __ANDROID__ is defined when using a standalone toolchain.
+#if defined(__ANDROID__) || defined(ANDROID)
+ #define EIGEN_OS_ANDROID 1
+#else
+ #define EIGEN_OS_ANDROID 0
+#endif
+
+/// \internal EIGEN_OS_GNULINUX set to 1 if the OS is GNU Linux and not Linux-based OS (e.g., not android)
+#if defined(__gnu_linux__) && !(EIGEN_OS_ANDROID)
+ #define EIGEN_OS_GNULINUX 1
+#else
+ #define EIGEN_OS_GNULINUX 0
+#endif
+
+/// \internal EIGEN_OS_BSD set to 1 if the OS is a BSD variant
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)
+ #define EIGEN_OS_BSD 1
+#else
+ #define EIGEN_OS_BSD 0
+#endif
+
+/// \internal EIGEN_OS_MAC set to 1 if the OS is MacOS
+#if defined(__APPLE__)
+ #define EIGEN_OS_MAC 1
+#else
+ #define EIGEN_OS_MAC 0
+#endif
+
+/// \internal EIGEN_OS_QNX set to 1 if the OS is QNX
+#if defined(__QNX__)
+ #define EIGEN_OS_QNX 1
+#else
+ #define EIGEN_OS_QNX 0
+#endif
+
+/// \internal EIGEN_OS_WIN set to 1 if the OS is Windows based
+#if defined(_WIN32)
+ #define EIGEN_OS_WIN 1
+#else
+ #define EIGEN_OS_WIN 0
+#endif
+
+/// \internal EIGEN_OS_WIN64 set to 1 if the OS is Windows 64bits
+#if defined(_WIN64)
+ #define EIGEN_OS_WIN64 1
+#else
+ #define EIGEN_OS_WIN64 0
+#endif
+
+/// \internal EIGEN_OS_WINCE set to 1 if the OS is Windows CE
+#if defined(_WIN32_WCE)
+ #define EIGEN_OS_WINCE 1
+#else
+ #define EIGEN_OS_WINCE 0
+#endif
+
+/// \internal EIGEN_OS_CYGWIN set to 1 if the OS is Windows/Cygwin
+#if defined(__CYGWIN__)
+ #define EIGEN_OS_CYGWIN 1
+#else
+ #define EIGEN_OS_CYGWIN 0
+#endif
+
+/// \internal EIGEN_OS_WIN_STRICT set to 1 if the OS is really Windows and not some variants
+#if EIGEN_OS_WIN && !( EIGEN_OS_WINCE || EIGEN_OS_CYGWIN )
+ #define EIGEN_OS_WIN_STRICT 1
+#else
+ #define EIGEN_OS_WIN_STRICT 0
+#endif
+
+/// \internal EIGEN_OS_SUN set to __SUNPRO_C if the OS is SUN
+// compiler solaris __SUNPRO_C
+// version studio
+// 5.7 10 0x570
+// 5.8 11 0x580
+// 5.9 12 0x590
+// 5.10 12.1 0x5100
+// 5.11 12.2 0x5110
+// 5.12 12.3 0x5120
+#if (defined(sun) || defined(__sun)) && !(defined(__SVR4) || defined(__svr4__))
+ #define EIGEN_OS_SUN __SUNPRO_C
+#else
+ #define EIGEN_OS_SUN 0
+#endif
+
+/// \internal EIGEN_OS_SOLARIS set to 1 if the OS is Solaris
+#if (defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__))
+ #define EIGEN_OS_SOLARIS 1
+#else
+ #define EIGEN_OS_SOLARIS 0
+#endif
+
+
+//------------------------------------------------------------------------------------------
+// Detect GPU compilers and architectures
+//------------------------------------------------------------------------------------------
+
+// NVCC is not supported as the target platform for HIPCC
+// Note that this also makes EIGEN_CUDACC and EIGEN_HIPCC mutually exclusive
+#if defined(__NVCC__) && defined(__HIPCC__)
+ #error "NVCC as the target platform for HIPCC is currently not supported."
+#endif
+
+#if defined(__CUDACC__) && !defined(EIGEN_NO_CUDA)
+ // Means the compiler is either nvcc or clang with CUDA enabled
+ #define EIGEN_CUDACC __CUDACC__
+#endif
+
+#if defined(__CUDA_ARCH__) && !defined(EIGEN_NO_CUDA)
+ // Means we are generating code for the device
+ #define EIGEN_CUDA_ARCH __CUDA_ARCH__
+#endif
+
+#if defined(EIGEN_CUDACC)
+#include <cuda.h>
+ #define EIGEN_CUDA_SDK_VER (CUDA_VERSION * 10)
+#else
+ #define EIGEN_CUDA_SDK_VER 0
+#endif
+
+#if defined(__HIPCC__) && !defined(EIGEN_NO_HIP)
+ // Means the compiler is HIPCC (analogous to EIGEN_CUDACC, but for HIP)
+ #define EIGEN_HIPCC __HIPCC__
+
+ // We need to include hip_runtime.h here because it pulls in
+ // ++ hip_common.h which contains the define for __HIP_DEVICE_COMPILE__
+ // ++ host_defines.h which contains the defines for the __host__ and __device__ macros
+ #include <hip/hip_runtime.h>
+
+ #if defined(__HIP_DEVICE_COMPILE__)
+ // analogous to EIGEN_CUDA_ARCH, but for HIP
+ #define EIGEN_HIP_DEVICE_COMPILE __HIP_DEVICE_COMPILE__
+ #endif
+
+ // For HIP (ROCm 3.5 and higher), we need to explicitly set the launch_bounds attribute
+ // value to 1024. The compiler assigns a default value of 256 when the attribute is not
+ // specified. This results in failures on the HIP platform, for cases when a GPU kernel
+ // without an explicit launch_bounds attribute is called with a threads_per_block value
+ // greater than 256.
+ //
+ // This is a regression in functioanlity and is expected to be fixed within the next
+ // couple of ROCm releases (compiler will go back to using 1024 value as the default)
+ //
+ // In the meantime, we will use a "only enabled for HIP" macro to set the launch_bounds
+ // attribute.
+
+ #define EIGEN_HIP_LAUNCH_BOUNDS_1024 __launch_bounds__(1024)
+
+#endif
+
+#if !defined(EIGEN_HIP_LAUNCH_BOUNDS_1024)
+#define EIGEN_HIP_LAUNCH_BOUNDS_1024
+#endif // !defined(EIGEN_HIP_LAUNCH_BOUNDS_1024)
+
+// Unify CUDA/HIPCC
+
+#if defined(EIGEN_CUDACC) || defined(EIGEN_HIPCC)
+//
+// If either EIGEN_CUDACC or EIGEN_HIPCC is defined, then define EIGEN_GPUCC
+//
+#define EIGEN_GPUCC
+//
+// EIGEN_HIPCC implies the HIP compiler and is used to tweak Eigen code for use in HIP kernels
+// EIGEN_CUDACC implies the CUDA compiler and is used to tweak Eigen code for use in CUDA kernels
+//
+// In most cases the same tweaks are required to the Eigen code to enable in both the HIP and CUDA kernels.
+// For those cases, the corresponding code should be guarded with
+// #if defined(EIGEN_GPUCC)
+// instead of
+// #if defined(EIGEN_CUDACC) || defined(EIGEN_HIPCC)
+//
+// For cases where the tweak is specific to HIP, the code should be guarded with
+// #if defined(EIGEN_HIPCC)
+//
+// For cases where the tweak is specific to CUDA, the code should be guarded with
+// #if defined(EIGEN_CUDACC)
+//
+#endif
+
+#if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIP_DEVICE_COMPILE)
+//
+// If either EIGEN_CUDA_ARCH or EIGEN_HIP_DEVICE_COMPILE is defined, then define EIGEN_GPU_COMPILE_PHASE
+//
+#define EIGEN_GPU_COMPILE_PHASE
+//
+// GPU compilers (HIPCC, NVCC) typically do two passes over the source code,
+// + one to compile the source for the "host" (ie CPU)
+// + another to compile the source for the "device" (ie. GPU)
+//
+// Code that needs to enabled only during the either the "host" or "device" compilation phase
+// needs to be guarded with a macro that indicates the current compilation phase
+//
+// EIGEN_HIP_DEVICE_COMPILE implies the device compilation phase in HIP
+// EIGEN_CUDA_ARCH implies the device compilation phase in CUDA
+//
+// In most cases, the "host" / "device" specific code is the same for both HIP and CUDA
+// For those cases, the code should be guarded with
+// #if defined(EIGEN_GPU_COMPILE_PHASE)
+// instead of
+// #if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIP_DEVICE_COMPILE)
+//
+// For cases where the tweak is specific to HIP, the code should be guarded with
+// #if defined(EIGEN_HIP_DEVICE_COMPILE)
+//
+// For cases where the tweak is specific to CUDA, the code should be guarded with
+// #if defined(EIGEN_CUDA_ARCH)
+//
+#endif
+
+#if defined(EIGEN_USE_SYCL) && defined(__SYCL_DEVICE_ONLY__)
+// EIGEN_USE_SYCL is a user-defined macro while __SYCL_DEVICE_ONLY__ is a compiler-defined macro.
+// In most cases we want to check if both macros are defined which can be done using the define below.
+#define SYCL_DEVICE_ONLY
+#endif
+
+//------------------------------------------------------------------------------------------
+// Detect Compiler/Architecture/OS specific features
+//------------------------------------------------------------------------------------------
+
+#if EIGEN_GNUC_AT_MOST(4,3) && !EIGEN_COMP_CLANG
+ // see bug 89
+ #define EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO 0
+#else
+ #define EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO 1
+#endif
+
+// Cross compiler wrapper around LLVM's __has_builtin
+#ifdef __has_builtin
+# define EIGEN_HAS_BUILTIN(x) __has_builtin(x)
+#else
+# define EIGEN_HAS_BUILTIN(x) 0
+#endif
+
+// A Clang feature extension to determine compiler features.
+// We use it to determine 'cxx_rvalue_references'
+#ifndef __has_feature
+# define __has_feature(x) 0
+#endif
+
+// Some old compilers do not support template specializations like:
+// template<typename T,int N> void foo(const T x[N]);
+#if !( EIGEN_COMP_CLANG && ( (EIGEN_COMP_CLANG<309) \
+ || (defined(__apple_build_version__) && (__apple_build_version__ < 9000000))) \
+ || EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<49)
+#define EIGEN_HAS_STATIC_ARRAY_TEMPLATE 1
+#else
+#define EIGEN_HAS_STATIC_ARRAY_TEMPLATE 0
+#endif
+
+// The macro EIGEN_CPLUSPLUS is a replacement for __cplusplus/_MSVC_LANG that
+// works for both platforms, indicating the C++ standard version number.
+//
+// With MSVC, without defining /Zc:__cplusplus, the __cplusplus macro will
+// report 199711L regardless of the language standard specified via /std.
+// We need to rely on _MSVC_LANG instead, which is only available after
+// VS2015.3.
+#if EIGEN_COMP_MSVC_LANG > 0
+#define EIGEN_CPLUSPLUS EIGEN_COMP_MSVC_LANG
+#elif EIGEN_COMP_MSVC >= 1900
+#define EIGEN_CPLUSPLUS 201103L
+#elif defined(__cplusplus)
+#define EIGEN_CPLUSPLUS __cplusplus
+#else
+#define EIGEN_CPLUSPLUS 0
+#endif
+
+// The macro EIGEN_COMP_CXXVER defines the c++ verson expected by the compiler.
+// For instance, if compiling with gcc and -std=c++17, then EIGEN_COMP_CXXVER
+// is defined to 17.
+#if EIGEN_CPLUSPLUS > 201703L
+ #define EIGEN_COMP_CXXVER 20
+#elif EIGEN_CPLUSPLUS > 201402L
+ #define EIGEN_COMP_CXXVER 17
+#elif EIGEN_CPLUSPLUS > 201103L
+ #define EIGEN_COMP_CXXVER 14
+#elif EIGEN_CPLUSPLUS >= 201103L
+ #define EIGEN_COMP_CXXVER 11
+#else
+ #define EIGEN_COMP_CXXVER 03
+#endif
+
+#ifndef EIGEN_HAS_CXX14_VARIABLE_TEMPLATES
+ #if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 && EIGEN_MAX_CPP_VER>=14
+ #define EIGEN_HAS_CXX14_VARIABLE_TEMPLATES 1
+ #else
+ #define EIGEN_HAS_CXX14_VARIABLE_TEMPLATES 0
+ #endif
+#endif
+
+
+// The macros EIGEN_HAS_CXX?? defines a rough estimate of available c++ features
+// but in practice we should not rely on them but rather on the availabilty of
+// individual features as defined later.
+// This is why there is no EIGEN_HAS_CXX17.
+// FIXME: get rid of EIGEN_HAS_CXX14 and maybe even EIGEN_HAS_CXX11.
+#if EIGEN_MAX_CPP_VER>=11 && EIGEN_COMP_CXXVER>=11
+#define EIGEN_HAS_CXX11 1
+#else
+#define EIGEN_HAS_CXX11 0
+#endif
+
+#if EIGEN_MAX_CPP_VER>=14 && EIGEN_COMP_CXXVER>=14
+#define EIGEN_HAS_CXX14 1
+#else
+#define EIGEN_HAS_CXX14 0
+#endif
+
+// Do we support r-value references?
+#ifndef EIGEN_HAS_RVALUE_REFERENCES
+#if EIGEN_MAX_CPP_VER>=11 && \
+ (__has_feature(cxx_rvalue_references) || \
+ (EIGEN_COMP_CXXVER >= 11) || (EIGEN_COMP_MSVC >= 1600))
+ #define EIGEN_HAS_RVALUE_REFERENCES 1
+#else
+ #define EIGEN_HAS_RVALUE_REFERENCES 0
+#endif
+#endif
+
+// Does the compiler support C99?
+// Need to include <cmath> to make sure _GLIBCXX_USE_C99 gets defined
+#include <cmath>
+#ifndef EIGEN_HAS_C99_MATH
+#if EIGEN_MAX_CPP_VER>=11 && \
+ ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)) \
+ || (defined(__GNUC__) && defined(_GLIBCXX_USE_C99)) \
+ || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER)) \
+ || (EIGEN_COMP_MSVC >= 1900) || defined(SYCL_DEVICE_ONLY))
+ #define EIGEN_HAS_C99_MATH 1
+#else
+ #define EIGEN_HAS_C99_MATH 0
+#endif
+#endif
+
+// Does the compiler support result_of?
+// result_of was deprecated in c++17 and removed in c++ 20
+#ifndef EIGEN_HAS_STD_RESULT_OF
+#if EIGEN_HAS_CXX11 && EIGEN_COMP_CXXVER < 17
+#define EIGEN_HAS_STD_RESULT_OF 1
+#else
+#define EIGEN_HAS_STD_RESULT_OF 0
+#endif
+#endif
+
+// Does the compiler support std::hash?
+#ifndef EIGEN_HAS_STD_HASH
+// The std::hash struct is defined in C++11 but is not labelled as a __device__
+// function and is not constexpr, so cannot be used on device.
+#if EIGEN_HAS_CXX11 && !defined(EIGEN_GPU_COMPILE_PHASE)
+#define EIGEN_HAS_STD_HASH 1
+#else
+#define EIGEN_HAS_STD_HASH 0
+#endif
+#endif // EIGEN_HAS_STD_HASH
+
+#ifndef EIGEN_HAS_STD_INVOKE_RESULT
+#if EIGEN_MAX_CPP_VER >= 17 && EIGEN_COMP_CXXVER >= 17
+#define EIGEN_HAS_STD_INVOKE_RESULT 1
+#else
+#define EIGEN_HAS_STD_INVOKE_RESULT 0
+#endif
+#endif
+
+#ifndef EIGEN_HAS_ALIGNAS
+#if EIGEN_MAX_CPP_VER>=11 && EIGEN_HAS_CXX11 && \
+ ( __has_feature(cxx_alignas) \
+ || EIGEN_HAS_CXX14 \
+ || (EIGEN_COMP_MSVC >= 1800) \
+ || (EIGEN_GNUC_AT_LEAST(4,8)) \
+ || (EIGEN_COMP_CLANG>=305) \
+ || (EIGEN_COMP_ICC>=1500) \
+ || (EIGEN_COMP_PGI>=1500) \
+ || (EIGEN_COMP_SUNCC>=0x5130))
+#define EIGEN_HAS_ALIGNAS 1
+#else
+#define EIGEN_HAS_ALIGNAS 0
+#endif
+#endif
+
+// Does the compiler support type_traits?
+// - full support of type traits was added only to GCC 5.1.0.
+// - 20150626 corresponds to the last release of 4.x libstdc++
+#ifndef EIGEN_HAS_TYPE_TRAITS
+#if EIGEN_MAX_CPP_VER>=11 && (EIGEN_HAS_CXX11 || EIGEN_COMP_MSVC >= 1700) \
+ && ((!EIGEN_COMP_GNUC_STRICT) || EIGEN_GNUC_AT_LEAST(5, 1)) \
+ && ((!defined(__GLIBCXX__)) || __GLIBCXX__ > 20150626)
+#define EIGEN_HAS_TYPE_TRAITS 1
+#define EIGEN_INCLUDE_TYPE_TRAITS
+#else
+#define EIGEN_HAS_TYPE_TRAITS 0
+#endif
+#endif
+
+// Does the compiler support variadic templates?
+#ifndef EIGEN_HAS_VARIADIC_TEMPLATES
+#if EIGEN_MAX_CPP_VER>=11 && (EIGEN_COMP_CXXVER >= 11) \
+ && (!defined(__NVCC__) || !EIGEN_ARCH_ARM_OR_ARM64 || (EIGEN_COMP_NVCC >= 80000) )
+ // ^^ Disable the use of variadic templates when compiling with versions of nvcc older than 8.0 on ARM devices:
+ // this prevents nvcc from crashing when compiling Eigen on Tegra X1
+#define EIGEN_HAS_VARIADIC_TEMPLATES 1
+#elif EIGEN_MAX_CPP_VER>=11 && (EIGEN_COMP_CXXVER >= 11) && defined(SYCL_DEVICE_ONLY)
+#define EIGEN_HAS_VARIADIC_TEMPLATES 1
+#else
+#define EIGEN_HAS_VARIADIC_TEMPLATES 0
+#endif
+#endif
+
+// Does the compiler fully support const expressions? (as in c++14)
+#ifndef EIGEN_HAS_CONSTEXPR
+ #if defined(EIGEN_CUDACC)
+ // Const expressions are supported provided that c++11 is enabled and we're using either clang or nvcc 7.5 or above
+ #if EIGEN_MAX_CPP_VER>=14 && (EIGEN_COMP_CXXVER >= 11 && (EIGEN_COMP_CLANG || EIGEN_COMP_NVCC >= 70500))
+ #define EIGEN_HAS_CONSTEXPR 1
+ #endif
+ #elif EIGEN_MAX_CPP_VER>=14 && (__has_feature(cxx_relaxed_constexpr) || (EIGEN_COMP_CXXVER >= 14) || \
+ (EIGEN_GNUC_AT_LEAST(4,8) && (EIGEN_COMP_CXXVER >= 11)) || \
+ (EIGEN_COMP_CLANG >= 306 && (EIGEN_COMP_CXXVER >= 11)))
+ #define EIGEN_HAS_CONSTEXPR 1
+ #endif
+
+ #ifndef EIGEN_HAS_CONSTEXPR
+ #define EIGEN_HAS_CONSTEXPR 0
+ #endif
+
+#endif // EIGEN_HAS_CONSTEXPR
+
+#if EIGEN_HAS_CONSTEXPR
+#define EIGEN_CONSTEXPR constexpr
+#else
+#define EIGEN_CONSTEXPR
+#endif
+
+// Does the compiler support C++11 math?
+// Let's be conservative and enable the default C++11 implementation only if we are sure it exists
+#ifndef EIGEN_HAS_CXX11_MATH
+ #if EIGEN_MAX_CPP_VER>=11 && ((EIGEN_COMP_CXXVER > 11) || (EIGEN_COMP_CXXVER == 11) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_MSVC || EIGEN_COMP_ICC) \
+ && (EIGEN_ARCH_i386_OR_x86_64) && (EIGEN_OS_GNULINUX || EIGEN_OS_WIN_STRICT || EIGEN_OS_MAC))
+ #define EIGEN_HAS_CXX11_MATH 1
+ #else
+ #define EIGEN_HAS_CXX11_MATH 0
+ #endif
+#endif
+
+// Does the compiler support proper C++11 containers?
+#ifndef EIGEN_HAS_CXX11_CONTAINERS
+ #if EIGEN_MAX_CPP_VER>=11 && \
+ ((EIGEN_COMP_CXXVER > 11) \
+ || ((EIGEN_COMP_CXXVER == 11) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_MSVC || EIGEN_COMP_ICC>=1400)))
+ #define EIGEN_HAS_CXX11_CONTAINERS 1
+ #else
+ #define EIGEN_HAS_CXX11_CONTAINERS 0
+ #endif
+#endif
+
+// Does the compiler support C++11 noexcept?
+#ifndef EIGEN_HAS_CXX11_NOEXCEPT
+ #if EIGEN_MAX_CPP_VER>=11 && \
+ (__has_feature(cxx_noexcept) \
+ || (EIGEN_COMP_CXXVER > 11) \
+ || ((EIGEN_COMP_CXXVER == 11) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_MSVC || EIGEN_COMP_ICC>=1400)))
+ #define EIGEN_HAS_CXX11_NOEXCEPT 1
+ #else
+ #define EIGEN_HAS_CXX11_NOEXCEPT 0
+ #endif
+#endif
+
+#ifndef EIGEN_HAS_CXX11_ATOMIC
+ #if EIGEN_MAX_CPP_VER>=11 && \
+ (__has_feature(cxx_atomic) \
+ || (EIGEN_COMP_CXXVER > 11) \
+ || ((EIGEN_COMP_CXXVER == 11) && (EIGEN_COMP_MSVC==0 || EIGEN_COMP_MSVC >= 1700)))
+ #define EIGEN_HAS_CXX11_ATOMIC 1
+ #else
+ #define EIGEN_HAS_CXX11_ATOMIC 0
+ #endif
+#endif
+
+#ifndef EIGEN_HAS_CXX11_OVERRIDE_FINAL
+ #if EIGEN_MAX_CPP_VER>=11 && \
+ (EIGEN_COMP_CXXVER >= 11 || EIGEN_COMP_MSVC >= 1700)
+ #define EIGEN_HAS_CXX11_OVERRIDE_FINAL 1
+ #else
+ #define EIGEN_HAS_CXX11_OVERRIDE_FINAL 0
+ #endif
+#endif
+
+// NOTE: the required Apple's clang version is very conservative
+// and it could be that XCode 9 works just fine.
+// NOTE: the MSVC version is based on https://en.cppreference.com/w/cpp/compiler_support
+// and not tested.
+#ifndef EIGEN_HAS_CXX17_OVERALIGN
+#if EIGEN_MAX_CPP_VER>=17 && EIGEN_COMP_CXXVER>=17 && ( \
+ (EIGEN_COMP_MSVC >= 1912) \
+ || (EIGEN_GNUC_AT_LEAST(7,0)) \
+ || ((!defined(__apple_build_version__)) && (EIGEN_COMP_CLANG>=500)) \
+ || (( defined(__apple_build_version__)) && (__apple_build_version__>=10000000)) \
+ )
+#define EIGEN_HAS_CXX17_OVERALIGN 1
+#else
+#define EIGEN_HAS_CXX17_OVERALIGN 0
+#endif
+#endif
+
+#if defined(EIGEN_CUDACC) && EIGEN_HAS_CONSTEXPR
+ // While available already with c++11, this is useful mostly starting with c++14 and relaxed constexpr rules
+ #if defined(__NVCC__)
+ // nvcc considers constexpr functions as __host__ __device__ with the option --expt-relaxed-constexpr
+ #ifdef __CUDACC_RELAXED_CONSTEXPR__
+ #define EIGEN_CONSTEXPR_ARE_DEVICE_FUNC
+ #endif
+ #elif defined(__clang__) && defined(__CUDA__) && __has_feature(cxx_relaxed_constexpr)
+ // clang++ always considers constexpr functions as implicitly __host__ __device__
+ #define EIGEN_CONSTEXPR_ARE_DEVICE_FUNC
+ #endif
+#endif
+
+// Does the compiler support the __int128 and __uint128_t extensions for 128-bit
+// integer arithmetic?
+//
+// Clang and GCC define __SIZEOF_INT128__ when these extensions are supported,
+// but we avoid using them in certain cases:
+//
+// * Building using Clang for Windows, where the Clang runtime library has
+// 128-bit support only on LP64 architectures, but Windows is LLP64.
+#ifndef EIGEN_HAS_BUILTIN_INT128
+#if defined(__SIZEOF_INT128__) && !(EIGEN_OS_WIN && EIGEN_COMP_CLANG)
+#define EIGEN_HAS_BUILTIN_INT128 1
+#else
+#define EIGEN_HAS_BUILTIN_INT128 0
+#endif
+#endif
+
+//------------------------------------------------------------------------------------------
+// Preprocessor programming helpers
+//------------------------------------------------------------------------------------------
+
+// This macro can be used to prevent from macro expansion, e.g.:
+// std::max EIGEN_NOT_A_MACRO(a,b)
+#define EIGEN_NOT_A_MACRO
+
+#define EIGEN_DEBUG_VAR(x) std::cerr << #x << " = " << x << std::endl;
+
+// concatenate two tokens
+#define EIGEN_CAT2(a,b) a ## b
+#define EIGEN_CAT(a,b) EIGEN_CAT2(a,b)
+
+#define EIGEN_COMMA ,
+
+// convert a token to a string
+#define EIGEN_MAKESTRING2(a) #a
+#define EIGEN_MAKESTRING(a) EIGEN_MAKESTRING2(a)
+
+// EIGEN_STRONG_INLINE is a stronger version of the inline, using __forceinline on MSVC,
+// but it still doesn't use GCC's always_inline. This is useful in (common) situations where MSVC needs forceinline
+// but GCC is still doing fine with just inline.
+#ifndef EIGEN_STRONG_INLINE
+#if (EIGEN_COMP_MSVC || EIGEN_COMP_ICC) && !defined(EIGEN_GPUCC)
+#define EIGEN_STRONG_INLINE __forceinline
+#else
+#define EIGEN_STRONG_INLINE inline
+#endif
+#endif
+
+// EIGEN_ALWAYS_INLINE is the stronget, it has the effect of making the function inline and adding every possible
+// attribute to maximize inlining. This should only be used when really necessary: in particular,
+// it uses __attribute__((always_inline)) on GCC, which most of the time is useless and can severely harm compile times.
+// FIXME with the always_inline attribute,
+// gcc 3.4.x and 4.1 reports the following compilation error:
+// Eval.h:91: sorry, unimplemented: inlining failed in call to 'const Eigen::Eval<Derived> Eigen::MatrixBase<Scalar, Derived>::eval() const'
+// : function body not available
+// See also bug 1367
+#if EIGEN_GNUC_AT_LEAST(4,2) && !defined(SYCL_DEVICE_ONLY)
+#define EIGEN_ALWAYS_INLINE __attribute__((always_inline)) inline
+#else
+#define EIGEN_ALWAYS_INLINE EIGEN_STRONG_INLINE
+#endif
+
+#if EIGEN_COMP_GNUC
+#define EIGEN_DONT_INLINE __attribute__((noinline))
+#elif EIGEN_COMP_MSVC
+#define EIGEN_DONT_INLINE __declspec(noinline)
+#else
+#define EIGEN_DONT_INLINE
+#endif
+
+#if EIGEN_COMP_GNUC
+#define EIGEN_PERMISSIVE_EXPR __extension__
+#else
+#define EIGEN_PERMISSIVE_EXPR
+#endif
+
+// GPU stuff
+
+// Disable some features when compiling with GPU compilers (NVCC/clang-cuda/SYCL/HIPCC)
+#if defined(EIGEN_CUDACC) || defined(SYCL_DEVICE_ONLY) || defined(EIGEN_HIPCC)
+ // Do not try asserts on device code
+ #ifndef EIGEN_NO_DEBUG
+ #define EIGEN_NO_DEBUG
+ #endif
+
+ #ifdef EIGEN_INTERNAL_DEBUGGING
+ #undef EIGEN_INTERNAL_DEBUGGING
+ #endif
+
+ #ifdef EIGEN_EXCEPTIONS
+ #undef EIGEN_EXCEPTIONS
+ #endif
+#endif
+
+#if defined(SYCL_DEVICE_ONLY)
+ #ifndef EIGEN_DONT_VECTORIZE
+ #define EIGEN_DONT_VECTORIZE
+ #endif
+ #define EIGEN_DEVICE_FUNC __attribute__((flatten)) __attribute__((always_inline))
+// All functions callable from CUDA/HIP code must be qualified with __device__
+#elif defined(EIGEN_GPUCC)
+ #define EIGEN_DEVICE_FUNC __host__ __device__
+#else
+ #define EIGEN_DEVICE_FUNC
+#endif
+
+
+// this macro allows to get rid of linking errors about multiply defined functions.
+// - static is not very good because it prevents definitions from different object files to be merged.
+// So static causes the resulting linked executable to be bloated with multiple copies of the same function.
+// - inline is not perfect either as it unwantedly hints the compiler toward inlining the function.
+#define EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC
+#define EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC inline
+
+#ifdef NDEBUG
+# ifndef EIGEN_NO_DEBUG
+# define EIGEN_NO_DEBUG
+# endif
+#endif
+
+// eigen_plain_assert is where we implement the workaround for the assert() bug in GCC <= 4.3, see bug 89
+#ifdef EIGEN_NO_DEBUG
+ #ifdef SYCL_DEVICE_ONLY // used to silence the warning on SYCL device
+ #define eigen_plain_assert(x) EIGEN_UNUSED_VARIABLE(x)
+ #else
+ #define eigen_plain_assert(x)
+ #endif
+#else
+ #if EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO
+ namespace Eigen {
+ namespace internal {
+ inline bool copy_bool(bool b) { return b; }
+ }
+ }
+ #define eigen_plain_assert(x) assert(x)
+ #else
+ // work around bug 89
+ #include <cstdlib> // for abort
+ #include <iostream> // for std::cerr
+
+ namespace Eigen {
+ namespace internal {
+ // trivial function copying a bool. Must be EIGEN_DONT_INLINE, so we implement it after including Eigen headers.
+ // see bug 89.
+ namespace {
+ EIGEN_DONT_INLINE bool copy_bool(bool b) { return b; }
+ }
+ inline void assert_fail(const char *condition, const char *function, const char *file, int line)
+ {
+ std::cerr << "assertion failed: " << condition << " in function " << function << " at " << file << ":" << line << std::endl;
+ abort();
+ }
+ }
+ }
+ #define eigen_plain_assert(x) \
+ do { \
+ if(!Eigen::internal::copy_bool(x)) \
+ Eigen::internal::assert_fail(EIGEN_MAKESTRING(x), __PRETTY_FUNCTION__, __FILE__, __LINE__); \
+ } while(false)
+ #endif
+#endif
+
+// eigen_assert can be overridden
+#ifndef eigen_assert
+#define eigen_assert(x) eigen_plain_assert(x)
+#endif
+
+#ifdef EIGEN_INTERNAL_DEBUGGING
+#define eigen_internal_assert(x) eigen_assert(x)
+#else
+#define eigen_internal_assert(x)
+#endif
+
+#ifdef EIGEN_NO_DEBUG
+#define EIGEN_ONLY_USED_FOR_DEBUG(x) EIGEN_UNUSED_VARIABLE(x)
+#else
+#define EIGEN_ONLY_USED_FOR_DEBUG(x)
+#endif
+
+#ifndef EIGEN_NO_DEPRECATED_WARNING
+ #if EIGEN_COMP_GNUC
+ #define EIGEN_DEPRECATED __attribute__((deprecated))
+ #elif EIGEN_COMP_MSVC
+ #define EIGEN_DEPRECATED __declspec(deprecated)
+ #else
+ #define EIGEN_DEPRECATED
+ #endif
+#else
+ #define EIGEN_DEPRECATED
+#endif
+
+#if EIGEN_COMP_GNUC
+#define EIGEN_UNUSED __attribute__((unused))
+#else
+#define EIGEN_UNUSED
+#endif
+
+// Suppresses 'unused variable' warnings.
+namespace Eigen {
+ namespace internal {
+ template<typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ignore_unused_variable(const T&) {}
+ }
+}
+#define EIGEN_UNUSED_VARIABLE(var) Eigen::internal::ignore_unused_variable(var);
+
+#if !defined(EIGEN_ASM_COMMENT)
+ #if EIGEN_COMP_GNUC && (EIGEN_ARCH_i386_OR_x86_64 || EIGEN_ARCH_ARM_OR_ARM64)
+ #define EIGEN_ASM_COMMENT(X) __asm__("#" X)
+ #else
+ #define EIGEN_ASM_COMMENT(X)
+ #endif
+#endif
+
+
+// Acts as a barrier preventing operations involving `X` from crossing. This
+// occurs, for example, in the fast rounding trick where a magic constant is
+// added then subtracted, which is otherwise compiled away with -ffast-math.
+//
+// See bug 1674
+#if !defined(EIGEN_OPTIMIZATION_BARRIER)
+ #if EIGEN_COMP_GNUC
+ // According to https://gcc.gnu.org/onlinedocs/gcc/Constraints.html:
+ // X: Any operand whatsoever.
+ // r: A register operand is allowed provided that it is in a general
+ // register.
+ // g: Any register, memory or immediate integer operand is allowed, except
+ // for registers that are not general registers.
+ // w: (AArch32/AArch64) Floating point register, Advanced SIMD vector
+ // register or SVE vector register.
+ // x: (SSE) Any SSE register.
+ // (AArch64) Like w, but restricted to registers 0 to 15 inclusive.
+ // v: (PowerPC) An Altivec vector register.
+ // wa:(PowerPC) A VSX register.
+ //
+ // "X" (uppercase) should work for all cases, though this seems to fail for
+ // some versions of GCC for arm/aarch64 with
+ // "error: inconsistent operand constraints in an 'asm'"
+ // Clang x86_64/arm/aarch64 seems to require "g" to support both scalars and
+ // vectors, otherwise
+ // "error: non-trivial scalar-to-vector conversion, possible invalid
+ // constraint for vector type"
+ //
+ // GCC for ppc64le generates an internal compiler error with x/X/g.
+ // GCC for AVX generates an internal compiler error with X.
+ //
+ // Tested on icc/gcc/clang for sse, avx, avx2, avx512dq
+ // gcc for arm, aarch64,
+ // gcc for ppc64le,
+ // both vectors and scalars.
+ //
+ // Note that this is restricted to plain types - this will not work
+ // directly for std::complex<T>, Eigen::half, Eigen::bfloat16. For these,
+ // you will need to apply to the underlying POD type.
+ #if EIGEN_ARCH_PPC && EIGEN_COMP_GNUC_STRICT
+ // This seems to be broken on clang. Packet4f is loaded into a single
+ // register rather than a vector, zeroing out some entries. Integer
+ // types also generate a compile error.
+ // General, Altivec, VSX.
+ #define EIGEN_OPTIMIZATION_BARRIER(X) __asm__ ("" : "+r,v,wa" (X));
+ #elif EIGEN_ARCH_ARM_OR_ARM64
+ // General, NEON.
+ #define EIGEN_OPTIMIZATION_BARRIER(X) __asm__ ("" : "+g,w" (X));
+ #elif EIGEN_ARCH_i386_OR_x86_64
+ // General, SSE.
+ #define EIGEN_OPTIMIZATION_BARRIER(X) __asm__ ("" : "+g,x" (X));
+ #else
+ // Not implemented for other architectures.
+ #define EIGEN_OPTIMIZATION_BARRIER(X)
+ #endif
+ #else
+ // Not implemented for other compilers.
+ #define EIGEN_OPTIMIZATION_BARRIER(X)
+ #endif
+#endif
+
+#if EIGEN_COMP_MSVC
+ // NOTE MSVC often gives C4127 warnings with compiletime if statements. See bug 1362.
+ // This workaround is ugly, but it does the job.
+# define EIGEN_CONST_CONDITIONAL(cond) (void)0, cond
+#else
+# define EIGEN_CONST_CONDITIONAL(cond) cond
+#endif
+
+#ifdef EIGEN_DONT_USE_RESTRICT_KEYWORD
+ #define EIGEN_RESTRICT
+#endif
+#ifndef EIGEN_RESTRICT
+ #define EIGEN_RESTRICT __restrict
+#endif
+
+
+#ifndef EIGEN_DEFAULT_IO_FORMAT
+#ifdef EIGEN_MAKING_DOCS
+// format used in Eigen's documentation
+// needed to define it here as escaping characters in CMake add_definition's argument seems very problematic.
+#define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat(3, 0, " ", "\n", "", "")
+#else
+#define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat()
+#endif
+#endif
+
+// just an empty macro !
+#define EIGEN_EMPTY
+
+
+// When compiling CUDA/HIP device code with NVCC or HIPCC
+// pull in math functions from the global namespace.
+// In host mode, and when device code is compiled with clang,
+// use the std versions.
+#if (defined(EIGEN_CUDA_ARCH) && defined(__NVCC__)) || defined(EIGEN_HIP_DEVICE_COMPILE)
+ #define EIGEN_USING_STD(FUNC) using ::FUNC;
+#else
+ #define EIGEN_USING_STD(FUNC) using std::FUNC;
+#endif
+
+#if EIGEN_COMP_MSVC_STRICT && (EIGEN_COMP_MSVC < 1900 || (EIGEN_COMP_MSVC == 1900 && EIGEN_COMP_NVCC))
+ // For older MSVC versions, as well as 1900 && CUDA 8, using the base operator is necessary,
+ // otherwise we get duplicate definition errors
+ // For later MSVC versions, we require explicit operator= definition, otherwise we get
+ // use of implicitly deleted operator errors.
+ // (cf Bugs 920, 1000, 1324, 2291)
+ #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
+ using Base::operator =;
+#elif EIGEN_COMP_CLANG // workaround clang bug (see http://forum.kde.org/viewtopic.php?f=74&t=102653)
+ #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
+ using Base::operator =; \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) { Base::operator=(other); return *this; } \
+ template <typename OtherDerived> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const DenseBase<OtherDerived>& other) { Base::operator=(other.derived()); return *this; }
+#else
+ #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
+ using Base::operator =; \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) \
+ { \
+ Base::operator=(other); \
+ return *this; \
+ }
+#endif
+
+
+/**
+ * \internal
+ * \brief Macro to explicitly define the default copy constructor.
+ * This is necessary, because the implicit definition is deprecated if the copy-assignment is overridden.
+ */
+#if EIGEN_HAS_CXX11
+#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS) CLASS(const CLASS&) = default;
+#else
+#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
+#endif
+
+
+
+/** \internal
+ * \brief Macro to manually inherit assignment operators.
+ * This is necessary, because the implicitly defined assignment operator gets deleted when a custom operator= is defined.
+ * With C++11 or later this also default-implements the copy-constructor
+ */
+#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
+ EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
+ EIGEN_DEFAULT_COPY_CONSTRUCTOR(Derived)
+
+/** \internal
+ * \brief Macro to manually define default constructors and destructors.
+ * This is necessary when the copy constructor is re-defined.
+ * For empty helper classes this should usually be protected, to avoid accidentally creating empty objects.
+ *
+ * Hiding the default destructor lead to problems in C++03 mode together with boost::multiprecision
+ */
+#if EIGEN_HAS_CXX11
+#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived) \
+ Derived() = default; \
+ ~Derived() = default;
+#else
+#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived) \
+ Derived() {}; \
+ /* ~Derived() {}; */
+#endif
+
+
+
+
+
+/**
+* Just a side note. Commenting within defines works only by documenting
+* behind the object (via '!<'). Comments cannot be multi-line and thus
+* we have these extra long lines. What is confusing doxygen over here is
+* that we use '\' and basically have a bunch of typedefs with their
+* documentation in a single line.
+**/
+
+#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
+ typedef typename Eigen::internal::traits<Derived>::Scalar Scalar; /*!< \brief Numeric type, e.g. float, double, int or std::complex<float>. */ \
+ typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; /*!< \brief The underlying numeric type for composed scalar types. \details In cases where Scalar is e.g. std::complex<T>, T were corresponding to RealScalar. */ \
+ typedef typename Base::CoeffReturnType CoeffReturnType; /*!< \brief The return type for coefficient access. \details Depending on whether the object allows direct coefficient access (e.g. for a MatrixXd), this type is either 'const Scalar&' or simply 'Scalar' for objects that do not allow direct coefficient access. */ \
+ typedef typename Eigen::internal::ref_selector<Derived>::type Nested; \
+ typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \
+ typedef typename Eigen::internal::traits<Derived>::StorageIndex StorageIndex; \
+ enum CompileTimeTraits \
+ { RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \
+ ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \
+ Flags = Eigen::internal::traits<Derived>::Flags, \
+ SizeAtCompileTime = Base::SizeAtCompileTime, \
+ MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
+ IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \
+ using Base::derived; \
+ using Base::const_cast_derived;
+
+
+// FIXME Maybe the EIGEN_DENSE_PUBLIC_INTERFACE could be removed as importing PacketScalar is rarely needed
+#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \
+ EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
+ typedef typename Base::PacketScalar PacketScalar;
+
+
+#define EIGEN_PLAIN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b)
+#define EIGEN_PLAIN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b)
+
+// EIGEN_SIZE_MIN_PREFER_DYNAMIC gives the min between compile-time sizes. 0 has absolute priority, followed by 1,
+// followed by Dynamic, followed by other finite values. The reason for giving Dynamic the priority over
+// finite values is that min(3, Dynamic) should be Dynamic, since that could be anything between 0 and 3.
+#define EIGEN_SIZE_MIN_PREFER_DYNAMIC(a,b) (((int)a == 0 || (int)b == 0) ? 0 \
+ : ((int)a == 1 || (int)b == 1) ? 1 \
+ : ((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
+ : ((int)a <= (int)b) ? (int)a : (int)b)
+
+// EIGEN_SIZE_MIN_PREFER_FIXED is a variant of EIGEN_SIZE_MIN_PREFER_DYNAMIC comparing MaxSizes. The difference is that finite values
+// now have priority over Dynamic, so that min(3, Dynamic) gives 3. Indeed, whatever the actual value is
+// (between 0 and 3), it is not more than 3.
+#define EIGEN_SIZE_MIN_PREFER_FIXED(a,b) (((int)a == 0 || (int)b == 0) ? 0 \
+ : ((int)a == 1 || (int)b == 1) ? 1 \
+ : ((int)a == Dynamic && (int)b == Dynamic) ? Dynamic \
+ : ((int)a == Dynamic) ? (int)b \
+ : ((int)b == Dynamic) ? (int)a \
+ : ((int)a <= (int)b) ? (int)a : (int)b)
+
+// see EIGEN_SIZE_MIN_PREFER_DYNAMIC. No need for a separate variant for MaxSizes here.
+#define EIGEN_SIZE_MAX(a,b) (((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
+ : ((int)a >= (int)b) ? (int)a : (int)b)
+
+#define EIGEN_LOGICAL_XOR(a,b) (((a) || (b)) && !((a) && (b)))
+
+#define EIGEN_IMPLIES(a,b) (!(a) || (b))
+
+#if EIGEN_HAS_BUILTIN(__builtin_expect) || EIGEN_COMP_GNUC
+#define EIGEN_PREDICT_FALSE(x) (__builtin_expect(x, false))
+#define EIGEN_PREDICT_TRUE(x) (__builtin_expect(false || (x), true))
+#else
+#define EIGEN_PREDICT_FALSE(x) (x)
+#define EIGEN_PREDICT_TRUE(x) (x)
+#endif
+
+// the expression type of a standard coefficient wise binary operation
+#define EIGEN_CWISE_BINARY_RETURN_TYPE(LHS,RHS,OPNAME) \
+ CwiseBinaryOp< \
+ EIGEN_CAT(EIGEN_CAT(internal::scalar_,OPNAME),_op)< \
+ typename internal::traits<LHS>::Scalar, \
+ typename internal::traits<RHS>::Scalar \
+ >, \
+ const LHS, \
+ const RHS \
+ >
+
+#define EIGEN_MAKE_CWISE_BINARY_OP(METHOD,OPNAME) \
+ template<typename OtherDerived> \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,OPNAME) \
+ (METHOD)(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
+ { \
+ return EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,OPNAME)(derived(), other.derived()); \
+ }
+
+#define EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,TYPEA,TYPEB) \
+ (Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<TYPEA,TYPEB,EIGEN_CAT(EIGEN_CAT(Eigen::internal::scalar_,OPNAME),_op)<TYPEA,TYPEB> > >::value)
+
+#define EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(EXPR,SCALAR,OPNAME) \
+ CwiseBinaryOp<EIGEN_CAT(EIGEN_CAT(internal::scalar_,OPNAME),_op)<typename internal::traits<EXPR>::Scalar,SCALAR>, const EXPR, \
+ const typename internal::plain_constant_type<EXPR,SCALAR>::type>
+
+#define EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(SCALAR,EXPR,OPNAME) \
+ CwiseBinaryOp<EIGEN_CAT(EIGEN_CAT(internal::scalar_,OPNAME),_op)<SCALAR,typename internal::traits<EXPR>::Scalar>, \
+ const typename internal::plain_constant_type<EXPR,SCALAR>::type, const EXPR>
+
+// Workaround for MSVC 2010 (see ML thread "patch with compile for for MSVC 2010")
+#if EIGEN_COMP_MSVC_STRICT && (EIGEN_COMP_MSVC_STRICT<=1600)
+#define EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(X) typename internal::enable_if<true,X>::type
+#else
+#define EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(X) X
+#endif
+
+#define EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(METHOD,OPNAME) \
+ template <typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
+ EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename internal::promote_scalar_arg<Scalar EIGEN_COMMA T EIGEN_COMMA EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,Scalar,T)>::type,OPNAME))\
+ (METHOD)(const T& scalar) const { \
+ typedef typename internal::promote_scalar_arg<Scalar,T,EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,Scalar,T)>::type PromotedT; \
+ return EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,PromotedT,OPNAME)(derived(), \
+ typename internal::plain_constant_type<Derived,PromotedT>::type(derived().rows(), derived().cols(), internal::scalar_constant_op<PromotedT>(scalar))); \
+ }
+
+#define EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD,OPNAME) \
+ template <typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend \
+ EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename internal::promote_scalar_arg<Scalar EIGEN_COMMA T EIGEN_COMMA EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,T,Scalar)>::type,Derived,OPNAME)) \
+ (METHOD)(const T& scalar, const StorageBaseType& matrix) { \
+ typedef typename internal::promote_scalar_arg<Scalar,T,EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,T,Scalar)>::type PromotedT; \
+ return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(PromotedT,Derived,OPNAME)( \
+ typename internal::plain_constant_type<Derived,PromotedT>::type(matrix.derived().rows(), matrix.derived().cols(), internal::scalar_constant_op<PromotedT>(scalar)), matrix.derived()); \
+ }
+
+#define EIGEN_MAKE_SCALAR_BINARY_OP(METHOD,OPNAME) \
+ EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD,OPNAME) \
+ EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(METHOD,OPNAME)
+
+
+#if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(EIGEN_CUDA_ARCH) && !defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_USE_SYCL) && !defined(EIGEN_HIP_DEVICE_COMPILE)
+ #define EIGEN_EXCEPTIONS
+#endif
+
+
+#ifdef EIGEN_EXCEPTIONS
+# define EIGEN_THROW_X(X) throw X
+# define EIGEN_THROW throw
+# define EIGEN_TRY try
+# define EIGEN_CATCH(X) catch (X)
+#else
+# if defined(EIGEN_CUDA_ARCH)
+# define EIGEN_THROW_X(X) asm("trap;")
+# define EIGEN_THROW asm("trap;")
+# elif defined(EIGEN_HIP_DEVICE_COMPILE)
+# define EIGEN_THROW_X(X) asm("s_trap 0")
+# define EIGEN_THROW asm("s_trap 0")
+# else
+# define EIGEN_THROW_X(X) std::abort()
+# define EIGEN_THROW std::abort()
+# endif
+# define EIGEN_TRY if (true)
+# define EIGEN_CATCH(X) else
+#endif
+
+
+#if EIGEN_HAS_CXX11_NOEXCEPT
+# define EIGEN_INCLUDE_TYPE_TRAITS
+# define EIGEN_NOEXCEPT noexcept
+# define EIGEN_NOEXCEPT_IF(x) noexcept(x)
+# define EIGEN_NO_THROW noexcept(true)
+# define EIGEN_EXCEPTION_SPEC(X) noexcept(false)
+#else
+# define EIGEN_NOEXCEPT
+# define EIGEN_NOEXCEPT_IF(x)
+# define EIGEN_NO_THROW throw()
+# if EIGEN_COMP_MSVC || EIGEN_COMP_CXXVER>=17
+ // MSVC does not support exception specifications (warning C4290),
+ // and they are deprecated in c++11 anyway. This is even an error in c++17.
+# define EIGEN_EXCEPTION_SPEC(X) throw()
+# else
+# define EIGEN_EXCEPTION_SPEC(X) throw(X)
+# endif
+#endif
+
+#if EIGEN_HAS_VARIADIC_TEMPLATES
+// The all function is used to enable a variadic version of eigen_assert which can take a parameter pack as its input.
+namespace Eigen {
+namespace internal {
+
+inline bool all(){ return true; }
+
+template<typename T, typename ...Ts>
+bool all(T t, Ts ... ts){ return t && all(ts...); }
+
+}
+}
+#endif
+
+#if EIGEN_HAS_CXX11_OVERRIDE_FINAL
+// provide override and final specifiers if they are available:
+# define EIGEN_OVERRIDE override
+# define EIGEN_FINAL final
+#else
+# define EIGEN_OVERRIDE
+# define EIGEN_FINAL
+#endif
+
+// Wrapping #pragma unroll in a macro since it is required for SYCL
+#if defined(SYCL_DEVICE_ONLY)
+ #if defined(_MSC_VER)
+ #define EIGEN_UNROLL_LOOP __pragma(unroll)
+ #else
+ #define EIGEN_UNROLL_LOOP _Pragma("unroll")
+ #endif
+#else
+ #define EIGEN_UNROLL_LOOP
+#endif
+
+#endif // EIGEN_MACROS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/Memory.h b/src/3rdparty/eigen/Eigen/src/Core/util/Memory.h
new file mode 100644
index 000000000..875318cdb
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/Memory.h
@@ -0,0 +1,1163 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2008-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2009 Kenneth Riddile <kfriddile@yahoo.com>
+// Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
+// Copyright (C) 2010 Thomas Capricelli <orzel@freehackers.org>
+// Copyright (C) 2013 Pavel Holoborodko <pavel@holoborodko.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+/*****************************************************************************
+*** Platform checks for aligned malloc functions ***
+*****************************************************************************/
+
+#ifndef EIGEN_MEMORY_H
+#define EIGEN_MEMORY_H
+
+#ifndef EIGEN_MALLOC_ALREADY_ALIGNED
+
+// Try to determine automatically if malloc is already aligned.
+
+// On 64-bit systems, glibc's malloc returns 16-byte-aligned pointers, see:
+// http://www.gnu.org/s/libc/manual/html_node/Aligned-Memory-Blocks.html
+// This is true at least since glibc 2.8.
+// This leaves the question how to detect 64-bit. According to this document,
+// http://gcc.fyxm.net/summit/2003/Porting%20to%2064%20bit.pdf
+// page 114, "[The] LP64 model [...] is used by all 64-bit UNIX ports" so it's indeed
+// quite safe, at least within the context of glibc, to equate 64-bit with LP64.
+#if defined(__GLIBC__) && ((__GLIBC__>=2 && __GLIBC_MINOR__ >= 8) || __GLIBC__>2) \
+ && defined(__LP64__) && ! defined( __SANITIZE_ADDRESS__ ) && (EIGEN_DEFAULT_ALIGN_BYTES == 16)
+ #define EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED 1
+#else
+ #define EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED 0
+#endif
+
+// FreeBSD 6 seems to have 16-byte aligned malloc
+// See http://svn.freebsd.org/viewvc/base/stable/6/lib/libc/stdlib/malloc.c?view=markup
+// FreeBSD 7 seems to have 16-byte aligned malloc except on ARM and MIPS architectures
+// See http://svn.freebsd.org/viewvc/base/stable/7/lib/libc/stdlib/malloc.c?view=markup
+#if defined(__FreeBSD__) && !(EIGEN_ARCH_ARM || EIGEN_ARCH_MIPS) && (EIGEN_DEFAULT_ALIGN_BYTES == 16)
+ #define EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED 1
+#else
+ #define EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED 0
+#endif
+
+#if (EIGEN_OS_MAC && (EIGEN_DEFAULT_ALIGN_BYTES == 16)) \
+ || (EIGEN_OS_WIN64 && (EIGEN_DEFAULT_ALIGN_BYTES == 16)) \
+ || EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED \
+ || EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED
+ #define EIGEN_MALLOC_ALREADY_ALIGNED 1
+#else
+ #define EIGEN_MALLOC_ALREADY_ALIGNED 0
+#endif
+
+#endif
+
+namespace Eigen {
+
+namespace internal {
+
+EIGEN_DEVICE_FUNC
+inline void throw_std_bad_alloc()
+{
+ #ifdef EIGEN_EXCEPTIONS
+ throw std::bad_alloc();
+ #else
+ std::size_t huge = static_cast<std::size_t>(-1);
+ #if defined(EIGEN_HIPCC)
+ //
+ // calls to "::operator new" are to be treated as opaque function calls (i.e no inlining),
+ // and as a consequence the code in the #else block triggers the hipcc warning :
+ // "no overloaded function has restriction specifiers that are compatible with the ambient context"
+ //
+ // "throw_std_bad_alloc" has the EIGEN_DEVICE_FUNC attribute, so it seems that hipcc expects
+ // the same on "operator new"
+ // Reverting code back to the old version in this #if block for the hipcc compiler
+ //
+ new int[huge];
+ #else
+ void* unused = ::operator new(huge);
+ EIGEN_UNUSED_VARIABLE(unused);
+ #endif
+ #endif
+}
+
+/*****************************************************************************
+*** Implementation of handmade aligned functions ***
+*****************************************************************************/
+
+/* ----- Hand made implementations of aligned malloc/free and realloc ----- */
+
+/** \internal Like malloc, but the returned pointer is guaranteed to be 16-byte aligned.
+ * Fast, but wastes 16 additional bytes of memory. Does not throw any exception.
+ */
+EIGEN_DEVICE_FUNC inline void* handmade_aligned_malloc(std::size_t size, std::size_t alignment = EIGEN_DEFAULT_ALIGN_BYTES)
+{
+ eigen_assert(alignment >= sizeof(void*) && (alignment & (alignment-1)) == 0 && "Alignment must be at least sizeof(void*) and a power of 2");
+
+ EIGEN_USING_STD(malloc)
+ void *original = malloc(size+alignment);
+
+ if (original == 0) return 0;
+ void *aligned = reinterpret_cast<void*>((reinterpret_cast<std::size_t>(original) & ~(std::size_t(alignment-1))) + alignment);
+ *(reinterpret_cast<void**>(aligned) - 1) = original;
+ return aligned;
+}
+
+/** \internal Frees memory allocated with handmade_aligned_malloc */
+EIGEN_DEVICE_FUNC inline void handmade_aligned_free(void *ptr)
+{
+ if (ptr) {
+ EIGEN_USING_STD(free)
+ free(*(reinterpret_cast<void**>(ptr) - 1));
+ }
+}
+
+/** \internal
+ * \brief Reallocates aligned memory.
+ * Since we know that our handmade version is based on std::malloc
+ * we can use std::realloc to implement efficient reallocation.
+ */
+inline void* handmade_aligned_realloc(void* ptr, std::size_t size, std::size_t = 0)
+{
+ if (ptr == 0) return handmade_aligned_malloc(size);
+ void *original = *(reinterpret_cast<void**>(ptr) - 1);
+ std::ptrdiff_t previous_offset = static_cast<char *>(ptr)-static_cast<char *>(original);
+ original = std::realloc(original,size+EIGEN_DEFAULT_ALIGN_BYTES);
+ if (original == 0) return 0;
+ void *aligned = reinterpret_cast<void*>((reinterpret_cast<std::size_t>(original) & ~(std::size_t(EIGEN_DEFAULT_ALIGN_BYTES-1))) + EIGEN_DEFAULT_ALIGN_BYTES);
+ void *previous_aligned = static_cast<char *>(original)+previous_offset;
+ if(aligned!=previous_aligned)
+ std::memmove(aligned, previous_aligned, size);
+
+ *(reinterpret_cast<void**>(aligned) - 1) = original;
+ return aligned;
+}
+
+/*****************************************************************************
+*** Implementation of portable aligned versions of malloc/free/realloc ***
+*****************************************************************************/
+
+#ifdef EIGEN_NO_MALLOC
+EIGEN_DEVICE_FUNC inline void check_that_malloc_is_allowed()
+{
+ eigen_assert(false && "heap allocation is forbidden (EIGEN_NO_MALLOC is defined)");
+}
+#elif defined EIGEN_RUNTIME_NO_MALLOC
+EIGEN_DEVICE_FUNC inline bool is_malloc_allowed_impl(bool update, bool new_value = false)
+{
+ static bool value = true;
+ if (update == 1)
+ value = new_value;
+ return value;
+}
+EIGEN_DEVICE_FUNC inline bool is_malloc_allowed() { return is_malloc_allowed_impl(false); }
+EIGEN_DEVICE_FUNC inline bool set_is_malloc_allowed(bool new_value) { return is_malloc_allowed_impl(true, new_value); }
+EIGEN_DEVICE_FUNC inline void check_that_malloc_is_allowed()
+{
+ eigen_assert(is_malloc_allowed() && "heap allocation is forbidden (EIGEN_RUNTIME_NO_MALLOC is defined and g_is_malloc_allowed is false)");
+}
+#else
+EIGEN_DEVICE_FUNC inline void check_that_malloc_is_allowed()
+{}
+#endif
+
+/** \internal Allocates \a size bytes. The returned pointer is guaranteed to have 16 or 32 bytes alignment depending on the requirements.
+ * On allocation error, the returned pointer is null, and std::bad_alloc is thrown.
+ */
+EIGEN_DEVICE_FUNC inline void* aligned_malloc(std::size_t size)
+{
+ check_that_malloc_is_allowed();
+
+ void *result;
+ #if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED
+
+ EIGEN_USING_STD(malloc)
+ result = malloc(size);
+
+ #if EIGEN_DEFAULT_ALIGN_BYTES==16
+ eigen_assert((size<16 || (std::size_t(result)%16)==0) && "System's malloc returned an unaligned pointer. Compile with EIGEN_MALLOC_ALREADY_ALIGNED=0 to fallback to handmade aligned memory allocator.");
+ #endif
+ #else
+ result = handmade_aligned_malloc(size);
+ #endif
+
+ if(!result && size)
+ throw_std_bad_alloc();
+
+ return result;
+}
+
+/** \internal Frees memory allocated with aligned_malloc. */
+EIGEN_DEVICE_FUNC inline void aligned_free(void *ptr)
+{
+ #if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED
+
+ EIGEN_USING_STD(free)
+ free(ptr);
+
+ #else
+ handmade_aligned_free(ptr);
+ #endif
+}
+
+/**
+ * \internal
+ * \brief Reallocates an aligned block of memory.
+ * \throws std::bad_alloc on allocation failure
+ */
+inline void* aligned_realloc(void *ptr, std::size_t new_size, std::size_t old_size)
+{
+ EIGEN_UNUSED_VARIABLE(old_size)
+
+ void *result;
+#if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED
+ result = std::realloc(ptr,new_size);
+#else
+ result = handmade_aligned_realloc(ptr,new_size,old_size);
+#endif
+
+ if (!result && new_size)
+ throw_std_bad_alloc();
+
+ return result;
+}
+
+/*****************************************************************************
+*** Implementation of conditionally aligned functions ***
+*****************************************************************************/
+
+/** \internal Allocates \a size bytes. If Align is true, then the returned ptr is 16-byte-aligned.
+ * On allocation error, the returned pointer is null, and a std::bad_alloc is thrown.
+ */
+template<bool Align> EIGEN_DEVICE_FUNC inline void* conditional_aligned_malloc(std::size_t size)
+{
+ return aligned_malloc(size);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void* conditional_aligned_malloc<false>(std::size_t size)
+{
+ check_that_malloc_is_allowed();
+
+ EIGEN_USING_STD(malloc)
+ void *result = malloc(size);
+
+ if(!result && size)
+ throw_std_bad_alloc();
+ return result;
+}
+
+/** \internal Frees memory allocated with conditional_aligned_malloc */
+template<bool Align> EIGEN_DEVICE_FUNC inline void conditional_aligned_free(void *ptr)
+{
+ aligned_free(ptr);
+}
+
+template<> EIGEN_DEVICE_FUNC inline void conditional_aligned_free<false>(void *ptr)
+{
+ EIGEN_USING_STD(free)
+ free(ptr);
+}
+
+template<bool Align> inline void* conditional_aligned_realloc(void* ptr, std::size_t new_size, std::size_t old_size)
+{
+ return aligned_realloc(ptr, new_size, old_size);
+}
+
+template<> inline void* conditional_aligned_realloc<false>(void* ptr, std::size_t new_size, std::size_t)
+{
+ return std::realloc(ptr, new_size);
+}
+
+/*****************************************************************************
+*** Construction/destruction of array elements ***
+*****************************************************************************/
+
+/** \internal Destructs the elements of an array.
+ * The \a size parameters tells on how many objects to call the destructor of T.
+ */
+template<typename T> EIGEN_DEVICE_FUNC inline void destruct_elements_of_array(T *ptr, std::size_t size)
+{
+ // always destruct an array starting from the end.
+ if(ptr)
+ while(size) ptr[--size].~T();
+}
+
+/** \internal Constructs the elements of an array.
+ * The \a size parameter tells on how many objects to call the constructor of T.
+ */
+template<typename T> EIGEN_DEVICE_FUNC inline T* construct_elements_of_array(T *ptr, std::size_t size)
+{
+ std::size_t i;
+ EIGEN_TRY
+ {
+ for (i = 0; i < size; ++i) ::new (ptr + i) T;
+ return ptr;
+ }
+ EIGEN_CATCH(...)
+ {
+ destruct_elements_of_array(ptr, i);
+ EIGEN_THROW;
+ }
+ return NULL;
+}
+
+/*****************************************************************************
+*** Implementation of aligned new/delete-like functions ***
+*****************************************************************************/
+
+template<typename T>
+EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void check_size_for_overflow(std::size_t size)
+{
+ if(size > std::size_t(-1) / sizeof(T))
+ throw_std_bad_alloc();
+}
+
+/** \internal Allocates \a size objects of type T. The returned pointer is guaranteed to have 16 bytes alignment.
+ * On allocation error, the returned pointer is undefined, but a std::bad_alloc is thrown.
+ * The default constructor of T is called.
+ */
+template<typename T> EIGEN_DEVICE_FUNC inline T* aligned_new(std::size_t size)
+{
+ check_size_for_overflow<T>(size);
+ T *result = reinterpret_cast<T*>(aligned_malloc(sizeof(T)*size));
+ EIGEN_TRY
+ {
+ return construct_elements_of_array(result, size);
+ }
+ EIGEN_CATCH(...)
+ {
+ aligned_free(result);
+ EIGEN_THROW;
+ }
+ return result;
+}
+
+template<typename T, bool Align> EIGEN_DEVICE_FUNC inline T* conditional_aligned_new(std::size_t size)
+{
+ check_size_for_overflow<T>(size);
+ T *result = reinterpret_cast<T*>(conditional_aligned_malloc<Align>(sizeof(T)*size));
+ EIGEN_TRY
+ {
+ return construct_elements_of_array(result, size);
+ }
+ EIGEN_CATCH(...)
+ {
+ conditional_aligned_free<Align>(result);
+ EIGEN_THROW;
+ }
+ return result;
+}
+
+/** \internal Deletes objects constructed with aligned_new
+ * The \a size parameters tells on how many objects to call the destructor of T.
+ */
+template<typename T> EIGEN_DEVICE_FUNC inline void aligned_delete(T *ptr, std::size_t size)
+{
+ destruct_elements_of_array<T>(ptr, size);
+ Eigen::internal::aligned_free(ptr);
+}
+
+/** \internal Deletes objects constructed with conditional_aligned_new
+ * The \a size parameters tells on how many objects to call the destructor of T.
+ */
+template<typename T, bool Align> EIGEN_DEVICE_FUNC inline void conditional_aligned_delete(T *ptr, std::size_t size)
+{
+ destruct_elements_of_array<T>(ptr, size);
+ conditional_aligned_free<Align>(ptr);
+}
+
+template<typename T, bool Align> EIGEN_DEVICE_FUNC inline T* conditional_aligned_realloc_new(T* pts, std::size_t new_size, std::size_t old_size)
+{
+ check_size_for_overflow<T>(new_size);
+ check_size_for_overflow<T>(old_size);
+ if(new_size < old_size)
+ destruct_elements_of_array(pts+new_size, old_size-new_size);
+ T *result = reinterpret_cast<T*>(conditional_aligned_realloc<Align>(reinterpret_cast<void*>(pts), sizeof(T)*new_size, sizeof(T)*old_size));
+ if(new_size > old_size)
+ {
+ EIGEN_TRY
+ {
+ construct_elements_of_array(result+old_size, new_size-old_size);
+ }
+ EIGEN_CATCH(...)
+ {
+ conditional_aligned_free<Align>(result);
+ EIGEN_THROW;
+ }
+ }
+ return result;
+}
+
+
+template<typename T, bool Align> EIGEN_DEVICE_FUNC inline T* conditional_aligned_new_auto(std::size_t size)
+{
+ if(size==0)
+ return 0; // short-cut. Also fixes Bug 884
+ check_size_for_overflow<T>(size);
+ T *result = reinterpret_cast<T*>(conditional_aligned_malloc<Align>(sizeof(T)*size));
+ if(NumTraits<T>::RequireInitialization)
+ {
+ EIGEN_TRY
+ {
+ construct_elements_of_array(result, size);
+ }
+ EIGEN_CATCH(...)
+ {
+ conditional_aligned_free<Align>(result);
+ EIGEN_THROW;
+ }
+ }
+ return result;
+}
+
+template<typename T, bool Align> inline T* conditional_aligned_realloc_new_auto(T* pts, std::size_t new_size, std::size_t old_size)
+{
+ check_size_for_overflow<T>(new_size);
+ check_size_for_overflow<T>(old_size);
+ if(NumTraits<T>::RequireInitialization && (new_size < old_size))
+ destruct_elements_of_array(pts+new_size, old_size-new_size);
+ T *result = reinterpret_cast<T*>(conditional_aligned_realloc<Align>(reinterpret_cast<void*>(pts), sizeof(T)*new_size, sizeof(T)*old_size));
+ if(NumTraits<T>::RequireInitialization && (new_size > old_size))
+ {
+ EIGEN_TRY
+ {
+ construct_elements_of_array(result+old_size, new_size-old_size);
+ }
+ EIGEN_CATCH(...)
+ {
+ conditional_aligned_free<Align>(result);
+ EIGEN_THROW;
+ }
+ }
+ return result;
+}
+
+template<typename T, bool Align> EIGEN_DEVICE_FUNC inline void conditional_aligned_delete_auto(T *ptr, std::size_t size)
+{
+ if(NumTraits<T>::RequireInitialization)
+ destruct_elements_of_array<T>(ptr, size);
+ conditional_aligned_free<Align>(ptr);
+}
+
+/****************************************************************************/
+
+/** \internal Returns the index of the first element of the array that is well aligned with respect to the requested \a Alignment.
+ *
+ * \tparam Alignment requested alignment in Bytes.
+ * \param array the address of the start of the array
+ * \param size the size of the array
+ *
+ * \note If no element of the array is well aligned or the requested alignment is not a multiple of a scalar,
+ * the size of the array is returned. For example with SSE, the requested alignment is typically 16-bytes. If
+ * packet size for the given scalar type is 1, then everything is considered well-aligned.
+ *
+ * \note Otherwise, if the Alignment is larger that the scalar size, we rely on the assumptions that sizeof(Scalar) is a
+ * power of 2. On the other hand, we do not assume that the array address is a multiple of sizeof(Scalar), as that fails for
+ * example with Scalar=double on certain 32-bit platforms, see bug #79.
+ *
+ * There is also the variant first_aligned(const MatrixBase&) defined in DenseCoeffsBase.h.
+ * \sa first_default_aligned()
+ */
+template<int Alignment, typename Scalar, typename Index>
+EIGEN_DEVICE_FUNC inline Index first_aligned(const Scalar* array, Index size)
+{
+ const Index ScalarSize = sizeof(Scalar);
+ const Index AlignmentSize = Alignment / ScalarSize;
+ const Index AlignmentMask = AlignmentSize-1;
+
+ if(AlignmentSize<=1)
+ {
+ // Either the requested alignment if smaller than a scalar, or it exactly match a 1 scalar
+ // so that all elements of the array have the same alignment.
+ return 0;
+ }
+ else if( (UIntPtr(array) & (sizeof(Scalar)-1)) || (Alignment%ScalarSize)!=0)
+ {
+ // The array is not aligned to the size of a single scalar, or the requested alignment is not a multiple of the scalar size.
+ // Consequently, no element of the array is well aligned.
+ return size;
+ }
+ else
+ {
+ Index first = (AlignmentSize - (Index((UIntPtr(array)/sizeof(Scalar))) & AlignmentMask)) & AlignmentMask;
+ return (first < size) ? first : size;
+ }
+}
+
+/** \internal Returns the index of the first element of the array that is well aligned with respect the largest packet requirement.
+ * \sa first_aligned(Scalar*,Index) and first_default_aligned(DenseBase<Derived>) */
+template<typename Scalar, typename Index>
+EIGEN_DEVICE_FUNC inline Index first_default_aligned(const Scalar* array, Index size)
+{
+ typedef typename packet_traits<Scalar>::type DefaultPacketType;
+ return first_aligned<unpacket_traits<DefaultPacketType>::alignment>(array, size);
+}
+
+/** \internal Returns the smallest integer multiple of \a base and greater or equal to \a size
+ */
+template<typename Index>
+inline Index first_multiple(Index size, Index base)
+{
+ return ((size+base-1)/base)*base;
+}
+
+// std::copy is much slower than memcpy, so let's introduce a smart_copy which
+// use memcpy on trivial types, i.e., on types that does not require an initialization ctor.
+template<typename T, bool UseMemcpy> struct smart_copy_helper;
+
+template<typename T> EIGEN_DEVICE_FUNC void smart_copy(const T* start, const T* end, T* target)
+{
+ smart_copy_helper<T,!NumTraits<T>::RequireInitialization>::run(start, end, target);
+}
+
+template<typename T> struct smart_copy_helper<T,true> {
+ EIGEN_DEVICE_FUNC static inline void run(const T* start, const T* end, T* target)
+ {
+ IntPtr size = IntPtr(end)-IntPtr(start);
+ if(size==0) return;
+ eigen_internal_assert(start!=0 && end!=0 && target!=0);
+ EIGEN_USING_STD(memcpy)
+ memcpy(target, start, size);
+ }
+};
+
+template<typename T> struct smart_copy_helper<T,false> {
+ EIGEN_DEVICE_FUNC static inline void run(const T* start, const T* end, T* target)
+ { std::copy(start, end, target); }
+};
+
+// intelligent memmove. falls back to std::memmove for POD types, uses std::copy otherwise.
+template<typename T, bool UseMemmove> struct smart_memmove_helper;
+
+template<typename T> void smart_memmove(const T* start, const T* end, T* target)
+{
+ smart_memmove_helper<T,!NumTraits<T>::RequireInitialization>::run(start, end, target);
+}
+
+template<typename T> struct smart_memmove_helper<T,true> {
+ static inline void run(const T* start, const T* end, T* target)
+ {
+ IntPtr size = IntPtr(end)-IntPtr(start);
+ if(size==0) return;
+ eigen_internal_assert(start!=0 && end!=0 && target!=0);
+ std::memmove(target, start, size);
+ }
+};
+
+template<typename T> struct smart_memmove_helper<T,false> {
+ static inline void run(const T* start, const T* end, T* target)
+ {
+ if (UIntPtr(target) < UIntPtr(start))
+ {
+ std::copy(start, end, target);
+ }
+ else
+ {
+ std::ptrdiff_t count = (std::ptrdiff_t(end)-std::ptrdiff_t(start)) / sizeof(T);
+ std::copy_backward(start, end, target + count);
+ }
+ }
+};
+
+#if EIGEN_HAS_RVALUE_REFERENCES
+template<typename T> EIGEN_DEVICE_FUNC T* smart_move(T* start, T* end, T* target)
+{
+ return std::move(start, end, target);
+}
+#else
+template<typename T> EIGEN_DEVICE_FUNC T* smart_move(T* start, T* end, T* target)
+{
+ return std::copy(start, end, target);
+}
+#endif
+
+/*****************************************************************************
+*** Implementation of runtime stack allocation (falling back to malloc) ***
+*****************************************************************************/
+
+// you can overwrite Eigen's default behavior regarding alloca by defining EIGEN_ALLOCA
+// to the appropriate stack allocation function
+#if ! defined EIGEN_ALLOCA && ! defined EIGEN_GPU_COMPILE_PHASE
+ #if EIGEN_OS_LINUX || EIGEN_OS_MAC || (defined alloca)
+ #define EIGEN_ALLOCA alloca
+ #elif EIGEN_COMP_MSVC
+ #define EIGEN_ALLOCA _alloca
+ #endif
+#endif
+
+// With clang -Oz -mthumb, alloca changes the stack pointer in a way that is
+// not allowed in Thumb2. -DEIGEN_STACK_ALLOCATION_LIMIT=0 doesn't work because
+// the compiler still emits bad code because stack allocation checks use "<=".
+// TODO: Eliminate after https://bugs.llvm.org/show_bug.cgi?id=23772
+// is fixed.
+#if defined(__clang__) && defined(__thumb__)
+ #undef EIGEN_ALLOCA
+#endif
+
+// This helper class construct the allocated memory, and takes care of destructing and freeing the handled data
+// at destruction time. In practice this helper class is mainly useful to avoid memory leak in case of exceptions.
+template<typename T> class aligned_stack_memory_handler : noncopyable
+{
+ public:
+ /* Creates a stack_memory_handler responsible for the buffer \a ptr of size \a size.
+ * Note that \a ptr can be 0 regardless of the other parameters.
+ * This constructor takes care of constructing/initializing the elements of the buffer if required by the scalar type T (see NumTraits<T>::RequireInitialization).
+ * In this case, the buffer elements will also be destructed when this handler will be destructed.
+ * Finally, if \a dealloc is true, then the pointer \a ptr is freed.
+ **/
+ EIGEN_DEVICE_FUNC
+ aligned_stack_memory_handler(T* ptr, std::size_t size, bool dealloc)
+ : m_ptr(ptr), m_size(size), m_deallocate(dealloc)
+ {
+ if(NumTraits<T>::RequireInitialization && m_ptr)
+ Eigen::internal::construct_elements_of_array(m_ptr, size);
+ }
+ EIGEN_DEVICE_FUNC
+ ~aligned_stack_memory_handler()
+ {
+ if(NumTraits<T>::RequireInitialization && m_ptr)
+ Eigen::internal::destruct_elements_of_array<T>(m_ptr, m_size);
+ if(m_deallocate)
+ Eigen::internal::aligned_free(m_ptr);
+ }
+ protected:
+ T* m_ptr;
+ std::size_t m_size;
+ bool m_deallocate;
+};
+
+#ifdef EIGEN_ALLOCA
+
+template<typename Xpr, int NbEvaluations,
+ bool MapExternalBuffer = nested_eval<Xpr,NbEvaluations>::Evaluate && Xpr::MaxSizeAtCompileTime==Dynamic
+ >
+struct local_nested_eval_wrapper
+{
+ static const bool NeedExternalBuffer = false;
+ typedef typename Xpr::Scalar Scalar;
+ typedef typename nested_eval<Xpr,NbEvaluations>::type ObjectType;
+ ObjectType object;
+
+ EIGEN_DEVICE_FUNC
+ local_nested_eval_wrapper(const Xpr& xpr, Scalar* ptr) : object(xpr)
+ {
+ EIGEN_UNUSED_VARIABLE(ptr);
+ eigen_internal_assert(ptr==0);
+ }
+};
+
+template<typename Xpr, int NbEvaluations>
+struct local_nested_eval_wrapper<Xpr,NbEvaluations,true>
+{
+ static const bool NeedExternalBuffer = true;
+ typedef typename Xpr::Scalar Scalar;
+ typedef typename plain_object_eval<Xpr>::type PlainObject;
+ typedef Map<PlainObject,EIGEN_DEFAULT_ALIGN_BYTES> ObjectType;
+ ObjectType object;
+
+ EIGEN_DEVICE_FUNC
+ local_nested_eval_wrapper(const Xpr& xpr, Scalar* ptr)
+ : object(ptr==0 ? reinterpret_cast<Scalar*>(Eigen::internal::aligned_malloc(sizeof(Scalar)*xpr.size())) : ptr, xpr.rows(), xpr.cols()),
+ m_deallocate(ptr==0)
+ {
+ if(NumTraits<Scalar>::RequireInitialization && object.data())
+ Eigen::internal::construct_elements_of_array(object.data(), object.size());
+ object = xpr;
+ }
+
+ EIGEN_DEVICE_FUNC
+ ~local_nested_eval_wrapper()
+ {
+ if(NumTraits<Scalar>::RequireInitialization && object.data())
+ Eigen::internal::destruct_elements_of_array(object.data(), object.size());
+ if(m_deallocate)
+ Eigen::internal::aligned_free(object.data());
+ }
+
+private:
+ bool m_deallocate;
+};
+
+#endif // EIGEN_ALLOCA
+
+template<typename T> class scoped_array : noncopyable
+{
+ T* m_ptr;
+public:
+ explicit scoped_array(std::ptrdiff_t size)
+ {
+ m_ptr = new T[size];
+ }
+ ~scoped_array()
+ {
+ delete[] m_ptr;
+ }
+ T& operator[](std::ptrdiff_t i) { return m_ptr[i]; }
+ const T& operator[](std::ptrdiff_t i) const { return m_ptr[i]; }
+ T* &ptr() { return m_ptr; }
+ const T* ptr() const { return m_ptr; }
+ operator const T*() const { return m_ptr; }
+};
+
+template<typename T> void swap(scoped_array<T> &a,scoped_array<T> &b)
+{
+ std::swap(a.ptr(),b.ptr());
+}
+
+} // end namespace internal
+
+/** \internal
+ *
+ * The macro ei_declare_aligned_stack_constructed_variable(TYPE,NAME,SIZE,BUFFER) declares, allocates,
+ * and construct an aligned buffer named NAME of SIZE elements of type TYPE on the stack
+ * if the size in bytes is smaller than EIGEN_STACK_ALLOCATION_LIMIT, and if stack allocation is supported by the platform
+ * (currently, this is Linux, OSX and Visual Studio only). Otherwise the memory is allocated on the heap.
+ * The allocated buffer is automatically deleted when exiting the scope of this declaration.
+ * If BUFFER is non null, then the declared variable is simply an alias for BUFFER, and no allocation/deletion occurs.
+ * Here is an example:
+ * \code
+ * {
+ * ei_declare_aligned_stack_constructed_variable(float,data,size,0);
+ * // use data[0] to data[size-1]
+ * }
+ * \endcode
+ * The underlying stack allocation function can controlled with the EIGEN_ALLOCA preprocessor token.
+ *
+ * The macro ei_declare_local_nested_eval(XPR_T,XPR,N,NAME) is analogue to
+ * \code
+ * typename internal::nested_eval<XPRT_T,N>::type NAME(XPR);
+ * \endcode
+ * with the advantage of using aligned stack allocation even if the maximal size of XPR at compile time is unknown.
+ * This is accomplished through alloca if this later is supported and if the required number of bytes
+ * is below EIGEN_STACK_ALLOCATION_LIMIT.
+ */
+#ifdef EIGEN_ALLOCA
+
+ #if EIGEN_DEFAULT_ALIGN_BYTES>0
+ // We always manually re-align the result of EIGEN_ALLOCA.
+ // If alloca is already aligned, the compiler should be smart enough to optimize away the re-alignment.
+ #define EIGEN_ALIGNED_ALLOCA(SIZE) reinterpret_cast<void*>((internal::UIntPtr(EIGEN_ALLOCA(SIZE+EIGEN_DEFAULT_ALIGN_BYTES-1)) + EIGEN_DEFAULT_ALIGN_BYTES-1) & ~(std::size_t(EIGEN_DEFAULT_ALIGN_BYTES-1)))
+ #else
+ #define EIGEN_ALIGNED_ALLOCA(SIZE) EIGEN_ALLOCA(SIZE)
+ #endif
+
+ #define ei_declare_aligned_stack_constructed_variable(TYPE,NAME,SIZE,BUFFER) \
+ Eigen::internal::check_size_for_overflow<TYPE>(SIZE); \
+ TYPE* NAME = (BUFFER)!=0 ? (BUFFER) \
+ : reinterpret_cast<TYPE*>( \
+ (sizeof(TYPE)*SIZE<=EIGEN_STACK_ALLOCATION_LIMIT) ? EIGEN_ALIGNED_ALLOCA(sizeof(TYPE)*SIZE) \
+ : Eigen::internal::aligned_malloc(sizeof(TYPE)*SIZE) ); \
+ Eigen::internal::aligned_stack_memory_handler<TYPE> EIGEN_CAT(NAME,_stack_memory_destructor)((BUFFER)==0 ? NAME : 0,SIZE,sizeof(TYPE)*SIZE>EIGEN_STACK_ALLOCATION_LIMIT)
+
+
+ #define ei_declare_local_nested_eval(XPR_T,XPR,N,NAME) \
+ Eigen::internal::local_nested_eval_wrapper<XPR_T,N> EIGEN_CAT(NAME,_wrapper)(XPR, reinterpret_cast<typename XPR_T::Scalar*>( \
+ ( (Eigen::internal::local_nested_eval_wrapper<XPR_T,N>::NeedExternalBuffer) && ((sizeof(typename XPR_T::Scalar)*XPR.size())<=EIGEN_STACK_ALLOCATION_LIMIT) ) \
+ ? EIGEN_ALIGNED_ALLOCA( sizeof(typename XPR_T::Scalar)*XPR.size() ) : 0 ) ) ; \
+ typename Eigen::internal::local_nested_eval_wrapper<XPR_T,N>::ObjectType NAME(EIGEN_CAT(NAME,_wrapper).object)
+
+#else
+
+ #define ei_declare_aligned_stack_constructed_variable(TYPE,NAME,SIZE,BUFFER) \
+ Eigen::internal::check_size_for_overflow<TYPE>(SIZE); \
+ TYPE* NAME = (BUFFER)!=0 ? BUFFER : reinterpret_cast<TYPE*>(Eigen::internal::aligned_malloc(sizeof(TYPE)*SIZE)); \
+ Eigen::internal::aligned_stack_memory_handler<TYPE> EIGEN_CAT(NAME,_stack_memory_destructor)((BUFFER)==0 ? NAME : 0,SIZE,true)
+
+
+#define ei_declare_local_nested_eval(XPR_T,XPR,N,NAME) typename Eigen::internal::nested_eval<XPR_T,N>::type NAME(XPR)
+
+#endif
+
+
+/*****************************************************************************
+*** Implementation of EIGEN_MAKE_ALIGNED_OPERATOR_NEW [_IF] ***
+*****************************************************************************/
+
+#if EIGEN_HAS_CXX17_OVERALIGN
+
+// C++17 -> no need to bother about alignment anymore :)
+
+#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign)
+#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
+#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW
+#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar,Size)
+
+#else
+
+// HIP does not support new/delete on device.
+#if EIGEN_MAX_ALIGN_BYTES!=0 && !defined(EIGEN_HIP_DEVICE_COMPILE)
+ #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \
+ EIGEN_DEVICE_FUNC \
+ void* operator new(std::size_t size, const std::nothrow_t&) EIGEN_NO_THROW { \
+ EIGEN_TRY { return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); } \
+ EIGEN_CATCH (...) { return 0; } \
+ }
+ #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \
+ EIGEN_DEVICE_FUNC \
+ void *operator new(std::size_t size) { \
+ return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
+ } \
+ EIGEN_DEVICE_FUNC \
+ void *operator new[](std::size_t size) { \
+ return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
+ } \
+ EIGEN_DEVICE_FUNC \
+ void operator delete(void * ptr) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
+ EIGEN_DEVICE_FUNC \
+ void operator delete[](void * ptr) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
+ EIGEN_DEVICE_FUNC \
+ void operator delete(void * ptr, std::size_t /* sz */) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
+ EIGEN_DEVICE_FUNC \
+ void operator delete[](void * ptr, std::size_t /* sz */) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
+ /* in-place new and delete. since (at least afaik) there is no actual */ \
+ /* memory allocated we can safely let the default implementation handle */ \
+ /* this particular case. */ \
+ EIGEN_DEVICE_FUNC \
+ static void *operator new(std::size_t size, void *ptr) { return ::operator new(size,ptr); } \
+ EIGEN_DEVICE_FUNC \
+ static void *operator new[](std::size_t size, void* ptr) { return ::operator new[](size,ptr); } \
+ EIGEN_DEVICE_FUNC \
+ void operator delete(void * memory, void *ptr) EIGEN_NO_THROW { return ::operator delete(memory,ptr); } \
+ EIGEN_DEVICE_FUNC \
+ void operator delete[](void * memory, void *ptr) EIGEN_NO_THROW { return ::operator delete[](memory,ptr); } \
+ /* nothrow-new (returns zero instead of std::bad_alloc) */ \
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \
+ EIGEN_DEVICE_FUNC \
+ void operator delete(void *ptr, const std::nothrow_t&) EIGEN_NO_THROW { \
+ Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); \
+ } \
+ typedef void eigen_aligned_operator_new_marker_type;
+#else
+ #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
+#endif
+
+#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(true)
+#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar,Size) \
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(bool( \
+ ((Size)!=Eigen::Dynamic) && \
+ (((EIGEN_MAX_ALIGN_BYTES>=16) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES )==0)) || \
+ ((EIGEN_MAX_ALIGN_BYTES>=32) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES/2)==0)) || \
+ ((EIGEN_MAX_ALIGN_BYTES>=64) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES/4)==0)) )))
+
+#endif
+
+/****************************************************************************/
+
+/** \class aligned_allocator
+* \ingroup Core_Module
+*
+* \brief STL compatible allocator to use with types requiring a non standrad alignment.
+*
+* The memory is aligned as for dynamically aligned matrix/array types such as MatrixXd.
+* By default, it will thus provide at least 16 bytes alignment and more in following cases:
+* - 32 bytes alignment if AVX is enabled.
+* - 64 bytes alignment if AVX512 is enabled.
+*
+* This can be controlled using the \c EIGEN_MAX_ALIGN_BYTES macro as documented
+* \link TopicPreprocessorDirectivesPerformance there \endlink.
+*
+* Example:
+* \code
+* // Matrix4f requires 16 bytes alignment:
+* std::map< int, Matrix4f, std::less<int>,
+* aligned_allocator<std::pair<const int, Matrix4f> > > my_map_mat4;
+* // Vector3f does not require 16 bytes alignment, no need to use Eigen's allocator:
+* std::map< int, Vector3f > my_map_vec3;
+* \endcode
+*
+* \sa \blank \ref TopicStlContainers.
+*/
+template<class T>
+class aligned_allocator : public std::allocator<T>
+{
+public:
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+ typedef T* pointer;
+ typedef const T* const_pointer;
+ typedef T& reference;
+ typedef const T& const_reference;
+ typedef T value_type;
+
+ template<class U>
+ struct rebind
+ {
+ typedef aligned_allocator<U> other;
+ };
+
+ aligned_allocator() : std::allocator<T>() {}
+
+ aligned_allocator(const aligned_allocator& other) : std::allocator<T>(other) {}
+
+ template<class U>
+ aligned_allocator(const aligned_allocator<U>& other) : std::allocator<T>(other) {}
+
+ ~aligned_allocator() {}
+
+ #if EIGEN_COMP_GNUC_STRICT && EIGEN_GNUC_AT_LEAST(7,0)
+ // In gcc std::allocator::max_size() is bugged making gcc triggers a warning:
+ // eigen/Eigen/src/Core/util/Memory.h:189:12: warning: argument 1 value '18446744073709551612' exceeds maximum object size 9223372036854775807
+ // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87544
+ size_type max_size() const {
+ return (std::numeric_limits<std::ptrdiff_t>::max)()/sizeof(T);
+ }
+ #endif
+
+ pointer allocate(size_type num, const void* /*hint*/ = 0)
+ {
+ internal::check_size_for_overflow<T>(num);
+ return static_cast<pointer>( internal::aligned_malloc(num * sizeof(T)) );
+ }
+
+ void deallocate(pointer p, size_type /*num*/)
+ {
+ internal::aligned_free(p);
+ }
+};
+
+//---------- Cache sizes ----------
+
+#if !defined(EIGEN_NO_CPUID)
+# if EIGEN_COMP_GNUC && EIGEN_ARCH_i386_OR_x86_64
+# if defined(__PIC__) && EIGEN_ARCH_i386
+ // Case for x86 with PIC
+# define EIGEN_CPUID(abcd,func,id) \
+ __asm__ __volatile__ ("xchgl %%ebx, %k1;cpuid; xchgl %%ebx,%k1": "=a" (abcd[0]), "=&r" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "a" (func), "c" (id));
+# elif defined(__PIC__) && EIGEN_ARCH_x86_64
+ // Case for x64 with PIC. In theory this is only a problem with recent gcc and with medium or large code model, not with the default small code model.
+ // However, we cannot detect which code model is used, and the xchg overhead is negligible anyway.
+# define EIGEN_CPUID(abcd,func,id) \
+ __asm__ __volatile__ ("xchg{q}\t{%%}rbx, %q1; cpuid; xchg{q}\t{%%}rbx, %q1": "=a" (abcd[0]), "=&r" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "0" (func), "2" (id));
+# else
+ // Case for x86_64 or x86 w/o PIC
+# define EIGEN_CPUID(abcd,func,id) \
+ __asm__ __volatile__ ("cpuid": "=a" (abcd[0]), "=b" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "0" (func), "2" (id) );
+# endif
+# elif EIGEN_COMP_MSVC
+# if (EIGEN_COMP_MSVC > 1500) && EIGEN_ARCH_i386_OR_x86_64
+# define EIGEN_CPUID(abcd,func,id) __cpuidex((int*)abcd,func,id)
+# endif
+# endif
+#endif
+
+namespace internal {
+
+#ifdef EIGEN_CPUID
+
+inline bool cpuid_is_vendor(int abcd[4], const int vendor[3])
+{
+ return abcd[1]==vendor[0] && abcd[3]==vendor[1] && abcd[2]==vendor[2];
+}
+
+inline void queryCacheSizes_intel_direct(int& l1, int& l2, int& l3)
+{
+ int abcd[4];
+ l1 = l2 = l3 = 0;
+ int cache_id = 0;
+ int cache_type = 0;
+ do {
+ abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
+ EIGEN_CPUID(abcd,0x4,cache_id);
+ cache_type = (abcd[0] & 0x0F) >> 0;
+ if(cache_type==1||cache_type==3) // data or unified cache
+ {
+ int cache_level = (abcd[0] & 0xE0) >> 5; // A[7:5]
+ int ways = (abcd[1] & 0xFFC00000) >> 22; // B[31:22]
+ int partitions = (abcd[1] & 0x003FF000) >> 12; // B[21:12]
+ int line_size = (abcd[1] & 0x00000FFF) >> 0; // B[11:0]
+ int sets = (abcd[2]); // C[31:0]
+
+ int cache_size = (ways+1) * (partitions+1) * (line_size+1) * (sets+1);
+
+ switch(cache_level)
+ {
+ case 1: l1 = cache_size; break;
+ case 2: l2 = cache_size; break;
+ case 3: l3 = cache_size; break;
+ default: break;
+ }
+ }
+ cache_id++;
+ } while(cache_type>0 && cache_id<16);
+}
+
+inline void queryCacheSizes_intel_codes(int& l1, int& l2, int& l3)
+{
+ int abcd[4];
+ abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
+ l1 = l2 = l3 = 0;
+ EIGEN_CPUID(abcd,0x00000002,0);
+ unsigned char * bytes = reinterpret_cast<unsigned char *>(abcd)+2;
+ bool check_for_p2_core2 = false;
+ for(int i=0; i<14; ++i)
+ {
+ switch(bytes[i])
+ {
+ case 0x0A: l1 = 8; break; // 0Ah data L1 cache, 8 KB, 2 ways, 32 byte lines
+ case 0x0C: l1 = 16; break; // 0Ch data L1 cache, 16 KB, 4 ways, 32 byte lines
+ case 0x0E: l1 = 24; break; // 0Eh data L1 cache, 24 KB, 6 ways, 64 byte lines
+ case 0x10: l1 = 16; break; // 10h data L1 cache, 16 KB, 4 ways, 32 byte lines (IA-64)
+ case 0x15: l1 = 16; break; // 15h code L1 cache, 16 KB, 4 ways, 32 byte lines (IA-64)
+ case 0x2C: l1 = 32; break; // 2Ch data L1 cache, 32 KB, 8 ways, 64 byte lines
+ case 0x30: l1 = 32; break; // 30h code L1 cache, 32 KB, 8 ways, 64 byte lines
+ case 0x60: l1 = 16; break; // 60h data L1 cache, 16 KB, 8 ways, 64 byte lines, sectored
+ case 0x66: l1 = 8; break; // 66h data L1 cache, 8 KB, 4 ways, 64 byte lines, sectored
+ case 0x67: l1 = 16; break; // 67h data L1 cache, 16 KB, 4 ways, 64 byte lines, sectored
+ case 0x68: l1 = 32; break; // 68h data L1 cache, 32 KB, 4 ways, 64 byte lines, sectored
+ case 0x1A: l2 = 96; break; // code and data L2 cache, 96 KB, 6 ways, 64 byte lines (IA-64)
+ case 0x22: l3 = 512; break; // code and data L3 cache, 512 KB, 4 ways (!), 64 byte lines, dual-sectored
+ case 0x23: l3 = 1024; break; // code and data L3 cache, 1024 KB, 8 ways, 64 byte lines, dual-sectored
+ case 0x25: l3 = 2048; break; // code and data L3 cache, 2048 KB, 8 ways, 64 byte lines, dual-sectored
+ case 0x29: l3 = 4096; break; // code and data L3 cache, 4096 KB, 8 ways, 64 byte lines, dual-sectored
+ case 0x39: l2 = 128; break; // code and data L2 cache, 128 KB, 4 ways, 64 byte lines, sectored
+ case 0x3A: l2 = 192; break; // code and data L2 cache, 192 KB, 6 ways, 64 byte lines, sectored
+ case 0x3B: l2 = 128; break; // code and data L2 cache, 128 KB, 2 ways, 64 byte lines, sectored
+ case 0x3C: l2 = 256; break; // code and data L2 cache, 256 KB, 4 ways, 64 byte lines, sectored
+ case 0x3D: l2 = 384; break; // code and data L2 cache, 384 KB, 6 ways, 64 byte lines, sectored
+ case 0x3E: l2 = 512; break; // code and data L2 cache, 512 KB, 4 ways, 64 byte lines, sectored
+ case 0x40: l2 = 0; break; // no integrated L2 cache (P6 core) or L3 cache (P4 core)
+ case 0x41: l2 = 128; break; // code and data L2 cache, 128 KB, 4 ways, 32 byte lines
+ case 0x42: l2 = 256; break; // code and data L2 cache, 256 KB, 4 ways, 32 byte lines
+ case 0x43: l2 = 512; break; // code and data L2 cache, 512 KB, 4 ways, 32 byte lines
+ case 0x44: l2 = 1024; break; // code and data L2 cache, 1024 KB, 4 ways, 32 byte lines
+ case 0x45: l2 = 2048; break; // code and data L2 cache, 2048 KB, 4 ways, 32 byte lines
+ case 0x46: l3 = 4096; break; // code and data L3 cache, 4096 KB, 4 ways, 64 byte lines
+ case 0x47: l3 = 8192; break; // code and data L3 cache, 8192 KB, 8 ways, 64 byte lines
+ case 0x48: l2 = 3072; break; // code and data L2 cache, 3072 KB, 12 ways, 64 byte lines
+ case 0x49: if(l2!=0) l3 = 4096; else {check_for_p2_core2=true; l3 = l2 = 4096;} break;// code and data L3 cache, 4096 KB, 16 ways, 64 byte lines (P4) or L2 for core2
+ case 0x4A: l3 = 6144; break; // code and data L3 cache, 6144 KB, 12 ways, 64 byte lines
+ case 0x4B: l3 = 8192; break; // code and data L3 cache, 8192 KB, 16 ways, 64 byte lines
+ case 0x4C: l3 = 12288; break; // code and data L3 cache, 12288 KB, 12 ways, 64 byte lines
+ case 0x4D: l3 = 16384; break; // code and data L3 cache, 16384 KB, 16 ways, 64 byte lines
+ case 0x4E: l2 = 6144; break; // code and data L2 cache, 6144 KB, 24 ways, 64 byte lines
+ case 0x78: l2 = 1024; break; // code and data L2 cache, 1024 KB, 4 ways, 64 byte lines
+ case 0x79: l2 = 128; break; // code and data L2 cache, 128 KB, 8 ways, 64 byte lines, dual-sectored
+ case 0x7A: l2 = 256; break; // code and data L2 cache, 256 KB, 8 ways, 64 byte lines, dual-sectored
+ case 0x7B: l2 = 512; break; // code and data L2 cache, 512 KB, 8 ways, 64 byte lines, dual-sectored
+ case 0x7C: l2 = 1024; break; // code and data L2 cache, 1024 KB, 8 ways, 64 byte lines, dual-sectored
+ case 0x7D: l2 = 2048; break; // code and data L2 cache, 2048 KB, 8 ways, 64 byte lines
+ case 0x7E: l2 = 256; break; // code and data L2 cache, 256 KB, 8 ways, 128 byte lines, sect. (IA-64)
+ case 0x7F: l2 = 512; break; // code and data L2 cache, 512 KB, 2 ways, 64 byte lines
+ case 0x80: l2 = 512; break; // code and data L2 cache, 512 KB, 8 ways, 64 byte lines
+ case 0x81: l2 = 128; break; // code and data L2 cache, 128 KB, 8 ways, 32 byte lines
+ case 0x82: l2 = 256; break; // code and data L2 cache, 256 KB, 8 ways, 32 byte lines
+ case 0x83: l2 = 512; break; // code and data L2 cache, 512 KB, 8 ways, 32 byte lines
+ case 0x84: l2 = 1024; break; // code and data L2 cache, 1024 KB, 8 ways, 32 byte lines
+ case 0x85: l2 = 2048; break; // code and data L2 cache, 2048 KB, 8 ways, 32 byte lines
+ case 0x86: l2 = 512; break; // code and data L2 cache, 512 KB, 4 ways, 64 byte lines
+ case 0x87: l2 = 1024; break; // code and data L2 cache, 1024 KB, 8 ways, 64 byte lines
+ case 0x88: l3 = 2048; break; // code and data L3 cache, 2048 KB, 4 ways, 64 byte lines (IA-64)
+ case 0x89: l3 = 4096; break; // code and data L3 cache, 4096 KB, 4 ways, 64 byte lines (IA-64)
+ case 0x8A: l3 = 8192; break; // code and data L3 cache, 8192 KB, 4 ways, 64 byte lines (IA-64)
+ case 0x8D: l3 = 3072; break; // code and data L3 cache, 3072 KB, 12 ways, 128 byte lines (IA-64)
+
+ default: break;
+ }
+ }
+ if(check_for_p2_core2 && l2 == l3)
+ l3 = 0;
+ l1 *= 1024;
+ l2 *= 1024;
+ l3 *= 1024;
+}
+
+inline void queryCacheSizes_intel(int& l1, int& l2, int& l3, int max_std_funcs)
+{
+ if(max_std_funcs>=4)
+ queryCacheSizes_intel_direct(l1,l2,l3);
+ else if(max_std_funcs>=2)
+ queryCacheSizes_intel_codes(l1,l2,l3);
+ else
+ l1 = l2 = l3 = 0;
+}
+
+inline void queryCacheSizes_amd(int& l1, int& l2, int& l3)
+{
+ int abcd[4];
+ abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
+
+ // First query the max supported function.
+ EIGEN_CPUID(abcd,0x80000000,0);
+ if(static_cast<numext::uint32_t>(abcd[0]) >= static_cast<numext::uint32_t>(0x80000006))
+ {
+ EIGEN_CPUID(abcd,0x80000005,0);
+ l1 = (abcd[2] >> 24) * 1024; // C[31:24] = L1 size in KB
+ abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
+ EIGEN_CPUID(abcd,0x80000006,0);
+ l2 = (abcd[2] >> 16) * 1024; // C[31;16] = l2 cache size in KB
+ l3 = ((abcd[3] & 0xFFFC000) >> 18) * 512 * 1024; // D[31;18] = l3 cache size in 512KB
+ }
+ else
+ {
+ l1 = l2 = l3 = 0;
+ }
+}
+#endif
+
+/** \internal
+ * Queries and returns the cache sizes in Bytes of the L1, L2, and L3 data caches respectively */
+inline void queryCacheSizes(int& l1, int& l2, int& l3)
+{
+ #ifdef EIGEN_CPUID
+ int abcd[4];
+ const int GenuineIntel[] = {0x756e6547, 0x49656e69, 0x6c65746e};
+ const int AuthenticAMD[] = {0x68747541, 0x69746e65, 0x444d4163};
+ const int AMDisbetter_[] = {0x69444d41, 0x74656273, 0x21726574}; // "AMDisbetter!"
+
+ // identify the CPU vendor
+ EIGEN_CPUID(abcd,0x0,0);
+ int max_std_funcs = abcd[0];
+ if(cpuid_is_vendor(abcd,GenuineIntel))
+ queryCacheSizes_intel(l1,l2,l3,max_std_funcs);
+ else if(cpuid_is_vendor(abcd,AuthenticAMD) || cpuid_is_vendor(abcd,AMDisbetter_))
+ queryCacheSizes_amd(l1,l2,l3);
+ else
+ // by default let's use Intel's API
+ queryCacheSizes_intel(l1,l2,l3,max_std_funcs);
+
+ // here is the list of other vendors:
+// ||cpuid_is_vendor(abcd,"VIA VIA VIA ")
+// ||cpuid_is_vendor(abcd,"CyrixInstead")
+// ||cpuid_is_vendor(abcd,"CentaurHauls")
+// ||cpuid_is_vendor(abcd,"GenuineTMx86")
+// ||cpuid_is_vendor(abcd,"TransmetaCPU")
+// ||cpuid_is_vendor(abcd,"RiseRiseRise")
+// ||cpuid_is_vendor(abcd,"Geode by NSC")
+// ||cpuid_is_vendor(abcd,"SiS SiS SiS ")
+// ||cpuid_is_vendor(abcd,"UMC UMC UMC ")
+// ||cpuid_is_vendor(abcd,"NexGenDriven")
+ #else
+ l1 = l2 = l3 = -1;
+ #endif
+}
+
+/** \internal
+ * \returns the size in Bytes of the L1 data cache */
+inline int queryL1CacheSize()
+{
+ int l1(-1), l2, l3;
+ queryCacheSizes(l1,l2,l3);
+ return l1;
+}
+
+/** \internal
+ * \returns the size in Bytes of the L2 or L3 cache if this later is present */
+inline int queryTopLevelCacheSize()
+{
+ int l1, l2(-1), l3(-1);
+ queryCacheSizes(l1,l2,l3);
+ return (std::max)(l2,l3);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_MEMORY_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/Meta.h b/src/3rdparty/eigen/Eigen/src/Core/util/Meta.h
new file mode 100644
index 000000000..81ae2a32d
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/Meta.h
@@ -0,0 +1,812 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_META_H
+#define EIGEN_META_H
+
+#if defined(EIGEN_GPU_COMPILE_PHASE)
+
+ #include <cfloat>
+
+ #if defined(EIGEN_CUDA_ARCH)
+ #include <math_constants.h>
+ #endif
+
+ #if defined(EIGEN_HIP_DEVICE_COMPILE)
+ #include "Eigen/src/Core/arch/HIP/hcc/math_constants.h"
+ #endif
+
+#endif
+
+// Recent versions of ICC require <cstdint> for pointer types below.
+#define EIGEN_ICC_NEEDS_CSTDINT (EIGEN_COMP_ICC>=1600 && EIGEN_COMP_CXXVER >= 11)
+
+// Define portable (u)int{32,64} types
+#if EIGEN_HAS_CXX11 || EIGEN_ICC_NEEDS_CSTDINT
+#include <cstdint>
+namespace Eigen {
+namespace numext {
+typedef std::uint8_t uint8_t;
+typedef std::int8_t int8_t;
+typedef std::uint16_t uint16_t;
+typedef std::int16_t int16_t;
+typedef std::uint32_t uint32_t;
+typedef std::int32_t int32_t;
+typedef std::uint64_t uint64_t;
+typedef std::int64_t int64_t;
+}
+}
+#else
+// Without c++11, all compilers able to compile Eigen also
+// provide the C99 stdint.h header file.
+#include <stdint.h>
+namespace Eigen {
+namespace numext {
+typedef ::uint8_t uint8_t;
+typedef ::int8_t int8_t;
+typedef ::uint16_t uint16_t;
+typedef ::int16_t int16_t;
+typedef ::uint32_t uint32_t;
+typedef ::int32_t int32_t;
+typedef ::uint64_t uint64_t;
+typedef ::int64_t int64_t;
+}
+}
+#endif
+
+namespace Eigen {
+
+typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex;
+
+/**
+ * \brief The Index type as used for the API.
+ * \details To change this, \c \#define the preprocessor symbol \c EIGEN_DEFAULT_DENSE_INDEX_TYPE.
+ * \sa \blank \ref TopicPreprocessorDirectives, StorageIndex.
+ */
+
+typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE Index;
+
+namespace internal {
+
+/** \internal
+ * \file Meta.h
+ * This file contains generic metaprogramming classes which are not specifically related to Eigen.
+ * \note In case you wonder, yes we're aware that Boost already provides all these features,
+ * we however don't want to add a dependency to Boost.
+ */
+
+// Only recent versions of ICC complain about using ptrdiff_t to hold pointers,
+// and older versions do not provide *intptr_t types.
+#if EIGEN_ICC_NEEDS_CSTDINT
+typedef std::intptr_t IntPtr;
+typedef std::uintptr_t UIntPtr;
+#else
+typedef std::ptrdiff_t IntPtr;
+typedef std::size_t UIntPtr;
+#endif
+#undef EIGEN_ICC_NEEDS_CSTDINT
+
+struct true_type { enum { value = 1 }; };
+struct false_type { enum { value = 0 }; };
+
+template<bool Condition>
+struct bool_constant;
+
+template<>
+struct bool_constant<true> : true_type {};
+
+template<>
+struct bool_constant<false> : false_type {};
+
+template<bool Condition, typename Then, typename Else>
+struct conditional { typedef Then type; };
+
+template<typename Then, typename Else>
+struct conditional <false, Then, Else> { typedef Else type; };
+
+template<typename T> struct remove_reference { typedef T type; };
+template<typename T> struct remove_reference<T&> { typedef T type; };
+
+template<typename T> struct remove_pointer { typedef T type; };
+template<typename T> struct remove_pointer<T*> { typedef T type; };
+template<typename T> struct remove_pointer<T*const> { typedef T type; };
+
+template <class T> struct remove_const { typedef T type; };
+template <class T> struct remove_const<const T> { typedef T type; };
+template <class T> struct remove_const<const T[]> { typedef T type[]; };
+template <class T, unsigned int Size> struct remove_const<const T[Size]> { typedef T type[Size]; };
+
+template<typename T> struct remove_all { typedef T type; };
+template<typename T> struct remove_all<const T> { typedef typename remove_all<T>::type type; };
+template<typename T> struct remove_all<T const&> { typedef typename remove_all<T>::type type; };
+template<typename T> struct remove_all<T&> { typedef typename remove_all<T>::type type; };
+template<typename T> struct remove_all<T const*> { typedef typename remove_all<T>::type type; };
+template<typename T> struct remove_all<T*> { typedef typename remove_all<T>::type type; };
+
+template<typename T> struct is_arithmetic { enum { value = false }; };
+template<> struct is_arithmetic<float> { enum { value = true }; };
+template<> struct is_arithmetic<double> { enum { value = true }; };
+template<> struct is_arithmetic<long double> { enum { value = true }; };
+template<> struct is_arithmetic<bool> { enum { value = true }; };
+template<> struct is_arithmetic<char> { enum { value = true }; };
+template<> struct is_arithmetic<signed char> { enum { value = true }; };
+template<> struct is_arithmetic<unsigned char> { enum { value = true }; };
+template<> struct is_arithmetic<signed short> { enum { value = true }; };
+template<> struct is_arithmetic<unsigned short>{ enum { value = true }; };
+template<> struct is_arithmetic<signed int> { enum { value = true }; };
+template<> struct is_arithmetic<unsigned int> { enum { value = true }; };
+template<> struct is_arithmetic<signed long> { enum { value = true }; };
+template<> struct is_arithmetic<unsigned long> { enum { value = true }; };
+
+template<typename T, typename U> struct is_same { enum { value = 0 }; };
+template<typename T> struct is_same<T,T> { enum { value = 1 }; };
+
+template< class T >
+struct is_void : is_same<void, typename remove_const<T>::type> {};
+
+#if EIGEN_HAS_CXX11
+template<> struct is_arithmetic<signed long long> { enum { value = true }; };
+template<> struct is_arithmetic<unsigned long long> { enum { value = true }; };
+using std::is_integral;
+#else
+template<typename T> struct is_integral { enum { value = false }; };
+template<> struct is_integral<bool> { enum { value = true }; };
+template<> struct is_integral<char> { enum { value = true }; };
+template<> struct is_integral<signed char> { enum { value = true }; };
+template<> struct is_integral<unsigned char> { enum { value = true }; };
+template<> struct is_integral<signed short> { enum { value = true }; };
+template<> struct is_integral<unsigned short> { enum { value = true }; };
+template<> struct is_integral<signed int> { enum { value = true }; };
+template<> struct is_integral<unsigned int> { enum { value = true }; };
+template<> struct is_integral<signed long> { enum { value = true }; };
+template<> struct is_integral<unsigned long> { enum { value = true }; };
+#if EIGEN_COMP_MSVC
+template<> struct is_integral<signed __int64> { enum { value = true }; };
+template<> struct is_integral<unsigned __int64> { enum { value = true }; };
+#endif
+#endif
+
+#if EIGEN_HAS_CXX11
+using std::make_unsigned;
+#else
+// TODO: Possibly improve this implementation of make_unsigned.
+// It is currently used only by
+// template<typename Scalar> struct random_default_impl<Scalar, false, true>.
+template<typename> struct make_unsigned;
+template<> struct make_unsigned<char> { typedef unsigned char type; };
+template<> struct make_unsigned<signed char> { typedef unsigned char type; };
+template<> struct make_unsigned<unsigned char> { typedef unsigned char type; };
+template<> struct make_unsigned<signed short> { typedef unsigned short type; };
+template<> struct make_unsigned<unsigned short> { typedef unsigned short type; };
+template<> struct make_unsigned<signed int> { typedef unsigned int type; };
+template<> struct make_unsigned<unsigned int> { typedef unsigned int type; };
+template<> struct make_unsigned<signed long> { typedef unsigned long type; };
+template<> struct make_unsigned<unsigned long> { typedef unsigned long type; };
+#if EIGEN_COMP_MSVC
+template<> struct make_unsigned<signed __int64> { typedef unsigned __int64 type; };
+template<> struct make_unsigned<unsigned __int64> { typedef unsigned __int64 type; };
+#endif
+
+// Some platforms define int64_t as `long long` even for C++03, where
+// `long long` is not guaranteed by the standard. In this case we are missing
+// the definition for make_unsigned. If we just define it, we run into issues
+// where `long long` doesn't exist in some compilers for C++03. We therefore add
+// the specialization for these platforms only.
+#if EIGEN_OS_MAC || EIGEN_COMP_MINGW
+template<> struct make_unsigned<unsigned long long> { typedef unsigned long long type; };
+template<> struct make_unsigned<long long> { typedef unsigned long long type; };
+#endif
+#endif
+
+template <typename T> struct add_const { typedef const T type; };
+template <typename T> struct add_const<T&> { typedef T& type; };
+
+template <typename T> struct is_const { enum { value = 0 }; };
+template <typename T> struct is_const<T const> { enum { value = 1 }; };
+
+template<typename T> struct add_const_on_value_type { typedef const T type; };
+template<typename T> struct add_const_on_value_type<T&> { typedef T const& type; };
+template<typename T> struct add_const_on_value_type<T*> { typedef T const* type; };
+template<typename T> struct add_const_on_value_type<T* const> { typedef T const* const type; };
+template<typename T> struct add_const_on_value_type<T const* const> { typedef T const* const type; };
+
+#if EIGEN_HAS_CXX11
+
+using std::is_convertible;
+
+#else
+
+template<typename From, typename To>
+struct is_convertible_impl
+{
+private:
+ struct any_conversion
+ {
+ template <typename T> any_conversion(const volatile T&);
+ template <typename T> any_conversion(T&);
+ };
+ struct yes {int a[1];};
+ struct no {int a[2];};
+
+ template<typename T>
+ static yes test(T, int);
+
+ template<typename T>
+ static no test(any_conversion, ...);
+
+public:
+ static typename internal::remove_reference<From>::type* ms_from;
+#ifdef __INTEL_COMPILER
+ #pragma warning push
+ #pragma warning ( disable : 2259 )
+#endif
+ enum { value = sizeof(test<To>(*ms_from, 0))==sizeof(yes) };
+#ifdef __INTEL_COMPILER
+ #pragma warning pop
+#endif
+};
+
+template<typename From, typename To>
+struct is_convertible
+{
+ enum { value = is_convertible_impl<From,To>::value };
+};
+
+template<typename T>
+struct is_convertible<T,T&> { enum { value = false }; };
+
+template<typename T>
+struct is_convertible<const T,const T&> { enum { value = true }; };
+
+#endif
+
+/** \internal Allows to enable/disable an overload
+ * according to a compile time condition.
+ */
+template<bool Condition, typename T=void> struct enable_if;
+
+template<typename T> struct enable_if<true,T>
+{ typedef T type; };
+
+#if defined(EIGEN_GPU_COMPILE_PHASE) && !EIGEN_HAS_CXX11
+#if !defined(__FLT_EPSILON__)
+#define __FLT_EPSILON__ FLT_EPSILON
+#define __DBL_EPSILON__ DBL_EPSILON
+#endif
+
+namespace device {
+
+template<typename T> struct numeric_limits
+{
+ EIGEN_DEVICE_FUNC
+ static EIGEN_CONSTEXPR T epsilon() { return 0; }
+ static T (max)() { assert(false && "Highest not supported for this type"); }
+ static T (min)() { assert(false && "Lowest not supported for this type"); }
+ static T infinity() { assert(false && "Infinity not supported for this type"); }
+ static T quiet_NaN() { assert(false && "quiet_NaN not supported for this type"); }
+};
+template<> struct numeric_limits<float>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static float epsilon() { return __FLT_EPSILON__; }
+ EIGEN_DEVICE_FUNC
+ static float (max)() {
+ #if defined(EIGEN_CUDA_ARCH)
+ return CUDART_MAX_NORMAL_F;
+ #else
+ return HIPRT_MAX_NORMAL_F;
+ #endif
+ }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static float (min)() { return FLT_MIN; }
+ EIGEN_DEVICE_FUNC
+ static float infinity() {
+ #if defined(EIGEN_CUDA_ARCH)
+ return CUDART_INF_F;
+ #else
+ return HIPRT_INF_F;
+ #endif
+ }
+ EIGEN_DEVICE_FUNC
+ static float quiet_NaN() {
+ #if defined(EIGEN_CUDA_ARCH)
+ return CUDART_NAN_F;
+ #else
+ return HIPRT_NAN_F;
+ #endif
+ }
+};
+template<> struct numeric_limits<double>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static double epsilon() { return __DBL_EPSILON__; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static double (max)() { return DBL_MAX; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static double (min)() { return DBL_MIN; }
+ EIGEN_DEVICE_FUNC
+ static double infinity() {
+ #if defined(EIGEN_CUDA_ARCH)
+ return CUDART_INF;
+ #else
+ return HIPRT_INF;
+ #endif
+ }
+ EIGEN_DEVICE_FUNC
+ static double quiet_NaN() {
+ #if defined(EIGEN_CUDA_ARCH)
+ return CUDART_NAN;
+ #else
+ return HIPRT_NAN;
+ #endif
+ }
+};
+template<> struct numeric_limits<int>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static int epsilon() { return 0; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static int (max)() { return INT_MAX; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static int (min)() { return INT_MIN; }
+};
+template<> struct numeric_limits<unsigned int>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static unsigned int epsilon() { return 0; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static unsigned int (max)() { return UINT_MAX; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static unsigned int (min)() { return 0; }
+};
+template<> struct numeric_limits<long>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static long epsilon() { return 0; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static long (max)() { return LONG_MAX; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static long (min)() { return LONG_MIN; }
+};
+template<> struct numeric_limits<unsigned long>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static unsigned long epsilon() { return 0; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static unsigned long (max)() { return ULONG_MAX; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static unsigned long (min)() { return 0; }
+};
+template<> struct numeric_limits<long long>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static long long epsilon() { return 0; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static long long (max)() { return LLONG_MAX; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static long long (min)() { return LLONG_MIN; }
+};
+template<> struct numeric_limits<unsigned long long>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static unsigned long long epsilon() { return 0; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static unsigned long long (max)() { return ULLONG_MAX; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static unsigned long long (min)() { return 0; }
+};
+template<> struct numeric_limits<bool>
+{
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static bool epsilon() { return false; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static bool (max)() { return true; }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ static bool (min)() { return false; }
+};
+
+}
+
+#endif // defined(EIGEN_GPU_COMPILE_PHASE) && !EIGEN_HAS_CXX11
+
+/** \internal
+ * A base class do disable default copy ctor and copy assignment operator.
+ */
+class noncopyable
+{
+ EIGEN_DEVICE_FUNC noncopyable(const noncopyable&);
+ EIGEN_DEVICE_FUNC const noncopyable& operator=(const noncopyable&);
+protected:
+ EIGEN_DEVICE_FUNC noncopyable() {}
+ EIGEN_DEVICE_FUNC ~noncopyable() {}
+};
+
+/** \internal
+ * Provides access to the number of elements in the object of as a compile-time constant expression.
+ * It "returns" Eigen::Dynamic if the size cannot be resolved at compile-time (default).
+ *
+ * Similar to std::tuple_size, but more general.
+ *
+ * It currently supports:
+ * - any types T defining T::SizeAtCompileTime
+ * - plain C arrays as T[N]
+ * - std::array (c++11)
+ * - some internal types such as SingleRange and AllRange
+ *
+ * The second template parameter eases SFINAE-based specializations.
+ */
+template<typename T, typename EnableIf = void> struct array_size {
+ enum { value = Dynamic };
+};
+
+template<typename T> struct array_size<T,typename internal::enable_if<((T::SizeAtCompileTime&0)==0)>::type> {
+ enum { value = T::SizeAtCompileTime };
+};
+
+template<typename T, int N> struct array_size<const T (&)[N]> {
+ enum { value = N };
+};
+template<typename T, int N> struct array_size<T (&)[N]> {
+ enum { value = N };
+};
+
+#if EIGEN_HAS_CXX11
+template<typename T, std::size_t N> struct array_size<const std::array<T,N> > {
+ enum { value = N };
+};
+template<typename T, std::size_t N> struct array_size<std::array<T,N> > {
+ enum { value = N };
+};
+#endif
+
+/** \internal
+ * Analogue of the std::size free function.
+ * It returns the size of the container or view \a x of type \c T
+ *
+ * It currently supports:
+ * - any types T defining a member T::size() const
+ * - plain C arrays as T[N]
+ *
+ */
+template<typename T>
+EIGEN_CONSTEXPR Index size(const T& x) { return x.size(); }
+
+template<typename T,std::size_t N>
+EIGEN_CONSTEXPR Index size(const T (&) [N]) { return N; }
+
+/** \internal
+ * Convenient struct to get the result type of a nullary, unary, binary, or
+ * ternary functor.
+ *
+ * Pre C++11:
+ * Supports both a Func::result_type member and templated
+ * Func::result<Func(ArgTypes...)>::type member.
+ *
+ * If none of these members is provided, then the type of the first
+ * argument is returned.
+ *
+ * Post C++11:
+ * This uses std::result_of. However, note the `type` member removes
+ * const and converts references/pointers to their corresponding value type.
+ */
+#if EIGEN_HAS_STD_INVOKE_RESULT
+template<typename T> struct result_of;
+
+template<typename F, typename... ArgTypes>
+struct result_of<F(ArgTypes...)> {
+ typedef typename std::invoke_result<F, ArgTypes...>::type type1;
+ typedef typename remove_all<type1>::type type;
+};
+#elif EIGEN_HAS_STD_RESULT_OF
+template<typename T> struct result_of {
+ typedef typename std::result_of<T>::type type1;
+ typedef typename remove_all<type1>::type type;
+};
+#else
+template<typename T> struct result_of { };
+
+struct has_none {int a[1];};
+struct has_std_result_type {int a[2];};
+struct has_tr1_result {int a[3];};
+
+template<typename Func, int SizeOf>
+struct nullary_result_of_select {};
+
+template<typename Func>
+struct nullary_result_of_select<Func, sizeof(has_std_result_type)> {typedef typename Func::result_type type;};
+
+template<typename Func>
+struct nullary_result_of_select<Func, sizeof(has_tr1_result)> {typedef typename Func::template result<Func()>::type type;};
+
+template<typename Func>
+struct result_of<Func()> {
+ template<typename T>
+ static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
+ template<typename T>
+ static has_tr1_result testFunctor(T const *, typename T::template result<T()>::type const * = 0);
+ static has_none testFunctor(...);
+
+ // note that the following indirection is needed for gcc-3.3
+ enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
+ typedef typename nullary_result_of_select<Func, FunctorType>::type type;
+};
+
+template<typename Func, typename ArgType, int SizeOf=sizeof(has_none)>
+struct unary_result_of_select {typedef typename internal::remove_all<ArgType>::type type;};
+
+template<typename Func, typename ArgType>
+struct unary_result_of_select<Func, ArgType, sizeof(has_std_result_type)> {typedef typename Func::result_type type;};
+
+template<typename Func, typename ArgType>
+struct unary_result_of_select<Func, ArgType, sizeof(has_tr1_result)> {typedef typename Func::template result<Func(ArgType)>::type type;};
+
+template<typename Func, typename ArgType>
+struct result_of<Func(ArgType)> {
+ template<typename T>
+ static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
+ template<typename T>
+ static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType)>::type const * = 0);
+ static has_none testFunctor(...);
+
+ // note that the following indirection is needed for gcc-3.3
+ enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
+ typedef typename unary_result_of_select<Func, ArgType, FunctorType>::type type;
+};
+
+template<typename Func, typename ArgType0, typename ArgType1, int SizeOf=sizeof(has_none)>
+struct binary_result_of_select {typedef typename internal::remove_all<ArgType0>::type type;};
+
+template<typename Func, typename ArgType0, typename ArgType1>
+struct binary_result_of_select<Func, ArgType0, ArgType1, sizeof(has_std_result_type)>
+{typedef typename Func::result_type type;};
+
+template<typename Func, typename ArgType0, typename ArgType1>
+struct binary_result_of_select<Func, ArgType0, ArgType1, sizeof(has_tr1_result)>
+{typedef typename Func::template result<Func(ArgType0,ArgType1)>::type type;};
+
+template<typename Func, typename ArgType0, typename ArgType1>
+struct result_of<Func(ArgType0,ArgType1)> {
+ template<typename T>
+ static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
+ template<typename T>
+ static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType0,ArgType1)>::type const * = 0);
+ static has_none testFunctor(...);
+
+ // note that the following indirection is needed for gcc-3.3
+ enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
+ typedef typename binary_result_of_select<Func, ArgType0, ArgType1, FunctorType>::type type;
+};
+
+template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2, int SizeOf=sizeof(has_none)>
+struct ternary_result_of_select {typedef typename internal::remove_all<ArgType0>::type type;};
+
+template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2>
+struct ternary_result_of_select<Func, ArgType0, ArgType1, ArgType2, sizeof(has_std_result_type)>
+{typedef typename Func::result_type type;};
+
+template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2>
+struct ternary_result_of_select<Func, ArgType0, ArgType1, ArgType2, sizeof(has_tr1_result)>
+{typedef typename Func::template result<Func(ArgType0,ArgType1,ArgType2)>::type type;};
+
+template<typename Func, typename ArgType0, typename ArgType1, typename ArgType2>
+struct result_of<Func(ArgType0,ArgType1,ArgType2)> {
+ template<typename T>
+ static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
+ template<typename T>
+ static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType0,ArgType1,ArgType2)>::type const * = 0);
+ static has_none testFunctor(...);
+
+ // note that the following indirection is needed for gcc-3.3
+ enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
+ typedef typename ternary_result_of_select<Func, ArgType0, ArgType1, ArgType2, FunctorType>::type type;
+};
+
+#endif
+
+#if EIGEN_HAS_STD_INVOKE_RESULT
+template<typename F, typename... ArgTypes>
+struct invoke_result {
+ typedef typename std::invoke_result<F, ArgTypes...>::type type1;
+ typedef typename remove_all<type1>::type type;
+};
+#elif EIGEN_HAS_CXX11
+template<typename F, typename... ArgTypes>
+struct invoke_result {
+ typedef typename result_of<F(ArgTypes...)>::type type1;
+ typedef typename remove_all<type1>::type type;
+};
+#else
+template<typename F, typename ArgType0 = void, typename ArgType1 = void, typename ArgType2 = void>
+struct invoke_result {
+ typedef typename result_of<F(ArgType0, ArgType1, ArgType2)>::type type1;
+ typedef typename remove_all<type1>::type type;
+};
+
+template<typename F>
+struct invoke_result<F, void, void, void> {
+ typedef typename result_of<F()>::type type1;
+ typedef typename remove_all<type1>::type type;
+};
+
+template<typename F, typename ArgType0>
+struct invoke_result<F, ArgType0, void, void> {
+ typedef typename result_of<F(ArgType0)>::type type1;
+ typedef typename remove_all<type1>::type type;
+};
+
+template<typename F, typename ArgType0, typename ArgType1>
+struct invoke_result<F, ArgType0, ArgType1, void> {
+ typedef typename result_of<F(ArgType0, ArgType1)>::type type1;
+ typedef typename remove_all<type1>::type type;
+};
+#endif
+
+struct meta_yes { char a[1]; };
+struct meta_no { char a[2]; };
+
+// Check whether T::ReturnType does exist
+template <typename T>
+struct has_ReturnType
+{
+ template <typename C> static meta_yes testFunctor(C const *, typename C::ReturnType const * = 0);
+ template <typename C> static meta_no testFunctor(...);
+
+ enum { value = sizeof(testFunctor<T>(static_cast<T*>(0))) == sizeof(meta_yes) };
+};
+
+template<typename T> const T* return_ptr();
+
+template <typename T, typename IndexType=Index>
+struct has_nullary_operator
+{
+ template <typename C> static meta_yes testFunctor(C const *,typename enable_if<(sizeof(return_ptr<C>()->operator()())>0)>::type * = 0);
+ static meta_no testFunctor(...);
+
+ enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) };
+};
+
+template <typename T, typename IndexType=Index>
+struct has_unary_operator
+{
+ template <typename C> static meta_yes testFunctor(C const *,typename enable_if<(sizeof(return_ptr<C>()->operator()(IndexType(0)))>0)>::type * = 0);
+ static meta_no testFunctor(...);
+
+ enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) };
+};
+
+template <typename T, typename IndexType=Index>
+struct has_binary_operator
+{
+ template <typename C> static meta_yes testFunctor(C const *,typename enable_if<(sizeof(return_ptr<C>()->operator()(IndexType(0),IndexType(0)))>0)>::type * = 0);
+ static meta_no testFunctor(...);
+
+ enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) };
+};
+
+/** \internal In short, it computes int(sqrt(\a Y)) with \a Y an integer.
+ * Usage example: \code meta_sqrt<1023>::ret \endcode
+ */
+template<int Y,
+ int InfX = 0,
+ int SupX = ((Y==1) ? 1 : Y/2),
+ bool Done = ((SupX-InfX)<=1 ? true : ((SupX*SupX <= Y) && ((SupX+1)*(SupX+1) > Y))) >
+ // use ?: instead of || just to shut up a stupid gcc 4.3 warning
+class meta_sqrt
+{
+ enum {
+ MidX = (InfX+SupX)/2,
+ TakeInf = MidX*MidX > Y ? 1 : 0,
+ NewInf = int(TakeInf) ? InfX : int(MidX),
+ NewSup = int(TakeInf) ? int(MidX) : SupX
+ };
+ public:
+ enum { ret = meta_sqrt<Y,NewInf,NewSup>::ret };
+};
+
+template<int Y, int InfX, int SupX>
+class meta_sqrt<Y, InfX, SupX, true> { public: enum { ret = (SupX*SupX <= Y) ? SupX : InfX }; };
+
+
+/** \internal Computes the least common multiple of two positive integer A and B
+ * at compile-time.
+ */
+template<int A, int B, int K=1, bool Done = ((A*K)%B)==0, bool Big=(A>=B)>
+struct meta_least_common_multiple
+{
+ enum { ret = meta_least_common_multiple<A,B,K+1>::ret };
+};
+template<int A, int B, int K, bool Done>
+struct meta_least_common_multiple<A,B,K,Done,false>
+{
+ enum { ret = meta_least_common_multiple<B,A,K>::ret };
+};
+template<int A, int B, int K>
+struct meta_least_common_multiple<A,B,K,true,true>
+{
+ enum { ret = A*K };
+};
+
+
+/** \internal determines whether the product of two numeric types is allowed and what the return type is */
+template<typename T, typename U> struct scalar_product_traits
+{
+ enum { Defined = 0 };
+};
+
+// FIXME quick workaround around current limitation of result_of
+// template<typename Scalar, typename ArgType0, typename ArgType1>
+// struct result_of<scalar_product_op<Scalar>(ArgType0,ArgType1)> {
+// typedef typename scalar_product_traits<typename remove_all<ArgType0>::type, typename remove_all<ArgType1>::type>::ReturnType type;
+// };
+
+/** \internal Obtains a POD type suitable to use as storage for an object of a size
+ * of at most Len bytes, aligned as specified by \c Align.
+ */
+template<unsigned Len, unsigned Align>
+struct aligned_storage {
+ struct type {
+ EIGEN_ALIGN_TO_BOUNDARY(Align) unsigned char data[Len];
+ };
+};
+
+} // end namespace internal
+
+namespace numext {
+
+#if defined(EIGEN_GPU_COMPILE_PHASE)
+template<typename T> EIGEN_DEVICE_FUNC void swap(T &a, T &b) { T tmp = b; b = a; a = tmp; }
+#else
+template<typename T> EIGEN_STRONG_INLINE void swap(T &a, T &b) { std::swap(a,b); }
+#endif
+
+#if defined(EIGEN_GPU_COMPILE_PHASE) && !EIGEN_HAS_CXX11
+using internal::device::numeric_limits;
+#else
+using std::numeric_limits;
+#endif
+
+// Integer division with rounding up.
+// T is assumed to be an integer type with a>=0, and b>0
+template<typename T>
+EIGEN_DEVICE_FUNC
+T div_ceil(const T &a, const T &b)
+{
+ return (a+b-1) / b;
+}
+
+// The aim of the following functions is to bypass -Wfloat-equal warnings
+// when we really want a strict equality comparison on floating points.
+template<typename X, typename Y> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+bool equal_strict(const X& x,const Y& y) { return x == y; }
+
+#if !defined(EIGEN_GPU_COMPILE_PHASE) || (!defined(EIGEN_CUDA_ARCH) && defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC))
+template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+bool equal_strict(const float& x,const float& y) { return std::equal_to<float>()(x,y); }
+
+template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+bool equal_strict(const double& x,const double& y) { return std::equal_to<double>()(x,y); }
+#endif
+
+template<typename X, typename Y> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+bool not_equal_strict(const X& x,const Y& y) { return x != y; }
+
+#if !defined(EIGEN_GPU_COMPILE_PHASE) || (!defined(EIGEN_CUDA_ARCH) && defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC))
+template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+bool not_equal_strict(const float& x,const float& y) { return std::not_equal_to<float>()(x,y); }
+
+template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
+bool not_equal_strict(const double& x,const double& y) { return std::not_equal_to<double>()(x,y); }
+#endif
+
+} // end namespace numext
+
+} // end namespace Eigen
+
+#endif // EIGEN_META_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/NonMPL2.h b/src/3rdparty/eigen/Eigen/src/Core/util/NonMPL2.h
new file mode 100644
index 000000000..1af67cf18
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/NonMPL2.h
@@ -0,0 +1,3 @@
+#ifdef EIGEN_MPL2_ONLY
+#error Including non-MPL2 code in EIGEN_MPL2_ONLY mode
+#endif
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h b/src/3rdparty/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h
new file mode 100644
index 000000000..1ce6fd1b0
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h
@@ -0,0 +1,31 @@
+#ifdef EIGEN_WARNINGS_DISABLED_2
+// "DisableStupidWarnings.h" was included twice recursively: Do not reenable warnings yet!
+# undef EIGEN_WARNINGS_DISABLED_2
+
+#elif defined(EIGEN_WARNINGS_DISABLED)
+#undef EIGEN_WARNINGS_DISABLED
+
+#ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS
+ #ifdef _MSC_VER
+ #pragma warning( pop )
+ #elif defined __INTEL_COMPILER
+ #pragma warning pop
+ #elif defined __clang__
+ #pragma clang diagnostic pop
+ #elif defined __GNUC__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ #pragma GCC diagnostic pop
+ #endif
+
+ #if defined __NVCC__
+// Don't reenable the diagnostic messages, as it turns out these messages need
+// to be disabled at the point of the template instantiation (i.e the user code)
+// otherwise they'll be triggered by nvcc.
+// #pragma diag_default code_is_unreachable
+// #pragma diag_default initialization_not_reachable
+// #pragma diag_default 2651
+// #pragma diag_default 2653
+ #endif
+
+#endif
+
+#endif // EIGEN_WARNINGS_DISABLED
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/ReshapedHelper.h b/src/3rdparty/eigen/Eigen/src/Core/util/ReshapedHelper.h
new file mode 100644
index 000000000..412432132
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/ReshapedHelper.h
@@ -0,0 +1,51 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#ifndef EIGEN_RESHAPED_HELPER_H
+#define EIGEN_RESHAPED_HELPER_H
+
+namespace Eigen {
+
+enum AutoSize_t { AutoSize };
+const int AutoOrder = 2;
+
+namespace internal {
+
+template<typename SizeType,typename OtherSize, int TotalSize>
+struct get_compiletime_reshape_size {
+ enum { value = get_fixed_value<SizeType>::value };
+};
+
+template<typename SizeType>
+Index get_runtime_reshape_size(SizeType size, Index /*other*/, Index /*total*/) {
+ return internal::get_runtime_value(size);
+}
+
+template<typename OtherSize, int TotalSize>
+struct get_compiletime_reshape_size<AutoSize_t,OtherSize,TotalSize> {
+ enum {
+ other_size = get_fixed_value<OtherSize>::value,
+ value = (TotalSize==Dynamic || other_size==Dynamic) ? Dynamic : TotalSize / other_size };
+};
+
+inline Index get_runtime_reshape_size(AutoSize_t /*size*/, Index other, Index total) {
+ return total/other;
+}
+
+template<int Flags, int Order>
+struct get_compiletime_reshape_order {
+ enum { value = Order == AutoOrder ? Flags & RowMajorBit : Order };
+};
+
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_RESHAPED_HELPER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/StaticAssert.h b/src/3rdparty/eigen/Eigen/src/Core/util/StaticAssert.h
new file mode 100644
index 000000000..c45de5901
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/StaticAssert.h
@@ -0,0 +1,221 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_STATIC_ASSERT_H
+#define EIGEN_STATIC_ASSERT_H
+
+/* Some notes on Eigen's static assertion mechanism:
+ *
+ * - in EIGEN_STATIC_ASSERT(CONDITION,MSG) the parameter CONDITION must be a compile time boolean
+ * expression, and MSG an enum listed in struct internal::static_assertion<true>
+ *
+ * - define EIGEN_NO_STATIC_ASSERT to disable them (and save compilation time)
+ * in that case, the static assertion is converted to the following runtime assert:
+ * eigen_assert(CONDITION && "MSG")
+ *
+ * - currently EIGEN_STATIC_ASSERT can only be used in function scope
+ *
+ */
+
+#ifndef EIGEN_STATIC_ASSERT
+#ifndef EIGEN_NO_STATIC_ASSERT
+
+ #if EIGEN_MAX_CPP_VER>=11 && (__has_feature(cxx_static_assert) || (EIGEN_COMP_CXXVER >= 11) || (EIGEN_COMP_MSVC >= 1600))
+
+ // if native static_assert is enabled, let's use it
+ #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
+
+ #else // not CXX0X
+
+ namespace Eigen {
+
+ namespace internal {
+
+ template<bool condition>
+ struct static_assertion {};
+
+ template<>
+ struct static_assertion<true>
+ {
+ enum {
+ YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX=1,
+ YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES=1,
+ YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES=1,
+ THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE=1,
+ THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE=1,
+ THIS_METHOD_IS_ONLY_FOR_OBJECTS_OF_A_SPECIFIC_SIZE=1,
+ OUT_OF_RANGE_ACCESS=1,
+ YOU_MADE_A_PROGRAMMING_MISTAKE=1,
+ EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT=1,
+ EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE=1,
+ YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR=1,
+ YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR=1,
+ UNALIGNED_LOAD_AND_STORE_OPERATIONS_UNIMPLEMENTED_ON_ALTIVEC=1,
+ THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES=1,
+ FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED=1,
+ NUMERIC_TYPE_MUST_BE_REAL=1,
+ COEFFICIENT_WRITE_ACCESS_TO_SELFADJOINT_NOT_SUPPORTED=1,
+ WRITING_TO_TRIANGULAR_PART_WITH_UNIT_DIAGONAL_IS_NOT_SUPPORTED=1,
+ THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE=1,
+ INVALID_MATRIX_PRODUCT=1,
+ INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS=1,
+ INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION=1,
+ YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY=1,
+ THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES=1,
+ THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES=1,
+ INVALID_MATRIX_TEMPLATE_PARAMETERS=1,
+ INVALID_MATRIXBASE_TEMPLATE_PARAMETERS=1,
+ BOTH_MATRICES_MUST_HAVE_THE_SAME_STORAGE_ORDER=1,
+ THIS_METHOD_IS_ONLY_FOR_DIAGONAL_MATRIX=1,
+ THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE=1,
+ THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES=1,
+ YOU_ALREADY_SPECIFIED_THIS_STRIDE=1,
+ INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION=1,
+ THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD=1,
+ PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1=1,
+ THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS=1,
+ YOU_CANNOT_MIX_ARRAYS_AND_MATRICES=1,
+ YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION=1,
+ THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY=1,
+ YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT=1,
+ THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS=1,
+ THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS=1,
+ THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL=1,
+ THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES=1,
+ YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED=1,
+ YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED=1,
+ THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE=1,
+ THE_STORAGE_ORDER_OF_BOTH_SIDES_MUST_MATCH=1,
+ OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG=1,
+ IMPLICIT_CONVERSION_TO_SCALAR_IS_FOR_INNER_PRODUCT_ONLY=1,
+ STORAGE_LAYOUT_DOES_NOT_MATCH=1,
+ EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT__INVALID_COST_VALUE=1,
+ THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS=1,
+ MATRIX_FREE_CONJUGATE_GRADIENT_IS_COMPATIBLE_WITH_UPPER_UNION_LOWER_MODE_ONLY=1,
+ THIS_TYPE_IS_NOT_SUPPORTED=1,
+ STORAGE_KIND_MUST_MATCH=1,
+ STORAGE_INDEX_MUST_MATCH=1,
+ CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY=1,
+ SELFADJOINTVIEW_ACCEPTS_UPPER_AND_LOWER_MODE_ONLY=1,
+ INVALID_TEMPLATE_PARAMETER=1,
+ GPU_TENSOR_CONTRACTION_DOES_NOT_SUPPORT_OUTPUT_KERNELS=1,
+ THE_ARRAY_SIZE_SHOULD_EQUAL_WITH_PACKET_SIZE=1
+ };
+ };
+
+ } // end namespace internal
+
+ } // end namespace Eigen
+
+ // Specialized implementation for MSVC to avoid "conditional
+ // expression is constant" warnings. This implementation doesn't
+ // appear to work under GCC, hence the multiple implementations.
+ #if EIGEN_COMP_MSVC
+
+ #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
+ {Eigen::internal::static_assertion<bool(CONDITION)>::MSG;}
+
+ #else
+ // In some cases clang interprets bool(CONDITION) as function declaration
+ #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
+ if (Eigen::internal::static_assertion<static_cast<bool>(CONDITION)>::MSG) {}
+
+ #endif
+
+ #endif // not CXX0X
+
+#else // EIGEN_NO_STATIC_ASSERT
+
+ #define EIGEN_STATIC_ASSERT(CONDITION,MSG) eigen_assert((CONDITION) && #MSG);
+
+#endif // EIGEN_NO_STATIC_ASSERT
+#endif // EIGEN_STATIC_ASSERT
+
+// static assertion failing if the type \a TYPE is not a vector type
+#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE) \
+ EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime, \
+ YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX)
+
+// static assertion failing if the type \a TYPE is not fixed-size
+#define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE) \
+ EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime!=Eigen::Dynamic, \
+ YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR)
+
+// static assertion failing if the type \a TYPE is not dynamic-size
+#define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE) \
+ EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime==Eigen::Dynamic, \
+ YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR)
+
+// static assertion failing if the type \a TYPE is not a vector type of the given size
+#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE) \
+ EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime && TYPE::SizeAtCompileTime==SIZE, \
+ THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE)
+
+// static assertion failing if the type \a TYPE is not a vector type of the given size
+#define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS) \
+ EIGEN_STATIC_ASSERT(TYPE::RowsAtCompileTime==ROWS && TYPE::ColsAtCompileTime==COLS, \
+ THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
+
+// static assertion failing if the two vector expression types are not compatible (same fixed-size or dynamic size)
+#define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0,TYPE1) \
+ EIGEN_STATIC_ASSERT( \
+ (int(TYPE0::SizeAtCompileTime)==Eigen::Dynamic \
+ || int(TYPE1::SizeAtCompileTime)==Eigen::Dynamic \
+ || int(TYPE0::SizeAtCompileTime)==int(TYPE1::SizeAtCompileTime)),\
+ YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES)
+
+#define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
+ ( \
+ (int(Eigen::internal::size_of_xpr_at_compile_time<TYPE0>::ret)==0 && int(Eigen::internal::size_of_xpr_at_compile_time<TYPE1>::ret)==0) \
+ || (\
+ (int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \
+ || int(TYPE1::RowsAtCompileTime)==Eigen::Dynamic \
+ || int(TYPE0::RowsAtCompileTime)==int(TYPE1::RowsAtCompileTime)) \
+ && (int(TYPE0::ColsAtCompileTime)==Eigen::Dynamic \
+ || int(TYPE1::ColsAtCompileTime)==Eigen::Dynamic \
+ || int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime))\
+ ) \
+ )
+
+#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
+ EIGEN_STATIC_ASSERT(!Eigen::NumTraits<TYPE>::IsInteger, THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES)
+
+
+// static assertion failing if it is guaranteed at compile-time that the two matrix expression types have different sizes
+#define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
+ EIGEN_STATIC_ASSERT( \
+ EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\
+ YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES)
+
+#define EIGEN_STATIC_ASSERT_SIZE_1x1(TYPE) \
+ EIGEN_STATIC_ASSERT((TYPE::RowsAtCompileTime == 1 || TYPE::RowsAtCompileTime == Eigen::Dynamic) && \
+ (TYPE::ColsAtCompileTime == 1 || TYPE::ColsAtCompileTime == Eigen::Dynamic), \
+ THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS)
+
+#define EIGEN_STATIC_ASSERT_LVALUE(Derived) \
+ EIGEN_STATIC_ASSERT(Eigen::internal::is_lvalue<Derived>::value, \
+ THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY)
+
+#define EIGEN_STATIC_ASSERT_ARRAYXPR(Derived) \
+ EIGEN_STATIC_ASSERT((Eigen::internal::is_same<typename Eigen::internal::traits<Derived>::XprKind, ArrayXpr>::value), \
+ THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES)
+
+#define EIGEN_STATIC_ASSERT_SAME_XPR_KIND(Derived1, Derived2) \
+ EIGEN_STATIC_ASSERT((Eigen::internal::is_same<typename Eigen::internal::traits<Derived1>::XprKind, \
+ typename Eigen::internal::traits<Derived2>::XprKind \
+ >::value), \
+ YOU_CANNOT_MIX_ARRAYS_AND_MATRICES)
+
+// Check that a cost value is positive, and that is stay within a reasonable range
+// TODO this check could be enabled for internal debugging only
+#define EIGEN_INTERNAL_CHECK_COST_VALUE(C) \
+ EIGEN_STATIC_ASSERT((C)>=0 && (C)<=HugeCost*HugeCost, EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT__INVALID_COST_VALUE);
+
+#endif // EIGEN_STATIC_ASSERT_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/SymbolicIndex.h b/src/3rdparty/eigen/Eigen/src/Core/util/SymbolicIndex.h
new file mode 100644
index 000000000..354dd9add
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/SymbolicIndex.h
@@ -0,0 +1,293 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SYMBOLIC_INDEX_H
+#define EIGEN_SYMBOLIC_INDEX_H
+
+namespace Eigen {
+
+/** \namespace Eigen::symbolic
+ * \ingroup Core_Module
+ *
+ * This namespace defines a set of classes and functions to build and evaluate symbolic expressions of scalar type Index.
+ * Here is a simple example:
+ *
+ * \code
+ * // First step, defines symbols:
+ * struct x_tag {}; static const symbolic::SymbolExpr<x_tag> x;
+ * struct y_tag {}; static const symbolic::SymbolExpr<y_tag> y;
+ * struct z_tag {}; static const symbolic::SymbolExpr<z_tag> z;
+ *
+ * // Defines an expression:
+ * auto expr = (x+3)/y+z;
+ *
+ * // And evaluate it: (c++14)
+ * std::cout << expr.eval(x=6,y=3,z=-13) << "\n";
+ *
+ * // In c++98/11, only one symbol per expression is supported for now:
+ * auto expr98 = (3-x)/2;
+ * std::cout << expr98.eval(x=6) << "\n";
+ * \endcode
+ *
+ * It is currently only used internally to define and manipulate the Eigen::last and Eigen::lastp1 symbols in Eigen::seq and Eigen::seqN.
+ *
+ */
+namespace symbolic {
+
+template<typename Tag> class Symbol;
+template<typename Arg0> class NegateExpr;
+template<typename Arg1,typename Arg2> class AddExpr;
+template<typename Arg1,typename Arg2> class ProductExpr;
+template<typename Arg1,typename Arg2> class QuotientExpr;
+
+// A simple wrapper around an integral value to provide the eval method.
+// We could also use a free-function symbolic_eval...
+template<typename IndexType=Index>
+class ValueExpr {
+public:
+ ValueExpr(IndexType val) : m_value(val) {}
+ template<typename T>
+ IndexType eval_impl(const T&) const { return m_value; }
+protected:
+ IndexType m_value;
+};
+
+// Specialization for compile-time value,
+// It is similar to ValueExpr(N) but this version helps the compiler to generate better code.
+template<int N>
+class ValueExpr<internal::FixedInt<N> > {
+public:
+ ValueExpr() {}
+ template<typename T>
+ EIGEN_CONSTEXPR Index eval_impl(const T&) const { return N; }
+};
+
+
+/** \class BaseExpr
+ * \ingroup Core_Module
+ * Common base class of any symbolic expressions
+ */
+template<typename Derived>
+class BaseExpr
+{
+public:
+ const Derived& derived() const { return *static_cast<const Derived*>(this); }
+
+ /** Evaluate the expression given the \a values of the symbols.
+ *
+ * \param values defines the values of the symbols, it can either be a SymbolValue or a std::tuple of SymbolValue
+ * as constructed by SymbolExpr::operator= operator.
+ *
+ */
+ template<typename T>
+ Index eval(const T& values) const { return derived().eval_impl(values); }
+
+#if EIGEN_HAS_CXX14
+ template<typename... Types>
+ Index eval(Types&&... values) const { return derived().eval_impl(std::make_tuple(values...)); }
+#endif
+
+ NegateExpr<Derived> operator-() const { return NegateExpr<Derived>(derived()); }
+
+ AddExpr<Derived,ValueExpr<> > operator+(Index b) const
+ { return AddExpr<Derived,ValueExpr<> >(derived(), b); }
+ AddExpr<Derived,ValueExpr<> > operator-(Index a) const
+ { return AddExpr<Derived,ValueExpr<> >(derived(), -a); }
+ ProductExpr<Derived,ValueExpr<> > operator*(Index a) const
+ { return ProductExpr<Derived,ValueExpr<> >(derived(),a); }
+ QuotientExpr<Derived,ValueExpr<> > operator/(Index a) const
+ { return QuotientExpr<Derived,ValueExpr<> >(derived(),a); }
+
+ friend AddExpr<Derived,ValueExpr<> > operator+(Index a, const BaseExpr& b)
+ { return AddExpr<Derived,ValueExpr<> >(b.derived(), a); }
+ friend AddExpr<NegateExpr<Derived>,ValueExpr<> > operator-(Index a, const BaseExpr& b)
+ { return AddExpr<NegateExpr<Derived>,ValueExpr<> >(-b.derived(), a); }
+ friend ProductExpr<ValueExpr<>,Derived> operator*(Index a, const BaseExpr& b)
+ { return ProductExpr<ValueExpr<>,Derived>(a,b.derived()); }
+ friend QuotientExpr<ValueExpr<>,Derived> operator/(Index a, const BaseExpr& b)
+ { return QuotientExpr<ValueExpr<>,Derived>(a,b.derived()); }
+
+ template<int N>
+ AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N>) const
+ { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(), ValueExpr<internal::FixedInt<N> >()); }
+ template<int N>
+ AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > > operator-(internal::FixedInt<N>) const
+ { return AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > >(derived(), ValueExpr<internal::FixedInt<-N> >()); }
+ template<int N>
+ ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator*(internal::FixedInt<N>) const
+ { return ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); }
+ template<int N>
+ QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator/(internal::FixedInt<N>) const
+ { return QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); }
+
+ template<int N>
+ friend AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N>, const BaseExpr& b)
+ { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(b.derived(), ValueExpr<internal::FixedInt<N> >()); }
+ template<int N>
+ friend AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > > operator-(internal::FixedInt<N>, const BaseExpr& b)
+ { return AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > >(-b.derived(), ValueExpr<internal::FixedInt<N> >()); }
+ template<int N>
+ friend ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator*(internal::FixedInt<N>, const BaseExpr& b)
+ { return ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); }
+ template<int N>
+ friend QuotientExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator/(internal::FixedInt<N>, const BaseExpr& b)
+ { return QuotientExpr<ValueExpr<internal::FixedInt<N> > ,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); }
+
+#if (!EIGEN_HAS_CXX14)
+ template<int N>
+ AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N> (*)()) const
+ { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(), ValueExpr<internal::FixedInt<N> >()); }
+ template<int N>
+ AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > > operator-(internal::FixedInt<N> (*)()) const
+ { return AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > >(derived(), ValueExpr<internal::FixedInt<-N> >()); }
+ template<int N>
+ ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator*(internal::FixedInt<N> (*)()) const
+ { return ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); }
+ template<int N>
+ QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator/(internal::FixedInt<N> (*)()) const
+ { return QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); }
+
+ template<int N>
+ friend AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N> (*)(), const BaseExpr& b)
+ { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(b.derived(), ValueExpr<internal::FixedInt<N> >()); }
+ template<int N>
+ friend AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > > operator-(internal::FixedInt<N> (*)(), const BaseExpr& b)
+ { return AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > >(-b.derived(), ValueExpr<internal::FixedInt<N> >()); }
+ template<int N>
+ friend ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator*(internal::FixedInt<N> (*)(), const BaseExpr& b)
+ { return ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); }
+ template<int N>
+ friend QuotientExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator/(internal::FixedInt<N> (*)(), const BaseExpr& b)
+ { return QuotientExpr<ValueExpr<internal::FixedInt<N> > ,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); }
+#endif
+
+
+ template<typename OtherDerived>
+ AddExpr<Derived,OtherDerived> operator+(const BaseExpr<OtherDerived> &b) const
+ { return AddExpr<Derived,OtherDerived>(derived(), b.derived()); }
+
+ template<typename OtherDerived>
+ AddExpr<Derived,NegateExpr<OtherDerived> > operator-(const BaseExpr<OtherDerived> &b) const
+ { return AddExpr<Derived,NegateExpr<OtherDerived> >(derived(), -b.derived()); }
+
+ template<typename OtherDerived>
+ ProductExpr<Derived,OtherDerived> operator*(const BaseExpr<OtherDerived> &b) const
+ { return ProductExpr<Derived,OtherDerived>(derived(), b.derived()); }
+
+ template<typename OtherDerived>
+ QuotientExpr<Derived,OtherDerived> operator/(const BaseExpr<OtherDerived> &b) const
+ { return QuotientExpr<Derived,OtherDerived>(derived(), b.derived()); }
+};
+
+template<typename T>
+struct is_symbolic {
+ // BaseExpr has no conversion ctor, so we only have to check whether T can be statically cast to its base class BaseExpr<T>.
+ enum { value = internal::is_convertible<T,BaseExpr<T> >::value };
+};
+
+/** Represents the actual value of a symbol identified by its tag
+ *
+ * It is the return type of SymbolValue::operator=, and most of the time this is only way it is used.
+ */
+template<typename Tag>
+class SymbolValue
+{
+public:
+ /** Default constructor from the value \a val */
+ SymbolValue(Index val) : m_value(val) {}
+
+ /** \returns the stored value of the symbol */
+ Index value() const { return m_value; }
+protected:
+ Index m_value;
+};
+
+/** Expression of a symbol uniquely identified by the template parameter type \c tag */
+template<typename tag>
+class SymbolExpr : public BaseExpr<SymbolExpr<tag> >
+{
+public:
+ /** Alias to the template parameter \c tag */
+ typedef tag Tag;
+
+ SymbolExpr() {}
+
+ /** Associate the value \a val to the given symbol \c *this, uniquely identified by its \c Tag.
+ *
+ * The returned object should be passed to ExprBase::eval() to evaluate a given expression with this specified runtime-time value.
+ */
+ SymbolValue<Tag> operator=(Index val) const {
+ return SymbolValue<Tag>(val);
+ }
+
+ Index eval_impl(const SymbolValue<Tag> &values) const { return values.value(); }
+
+#if EIGEN_HAS_CXX14
+ // C++14 versions suitable for multiple symbols
+ template<typename... Types>
+ Index eval_impl(const std::tuple<Types...>& values) const { return std::get<SymbolValue<Tag> >(values).value(); }
+#endif
+};
+
+template<typename Arg0>
+class NegateExpr : public BaseExpr<NegateExpr<Arg0> >
+{
+public:
+ NegateExpr(const Arg0& arg0) : m_arg0(arg0) {}
+
+ template<typename T>
+ Index eval_impl(const T& values) const { return -m_arg0.eval_impl(values); }
+protected:
+ Arg0 m_arg0;
+};
+
+template<typename Arg0, typename Arg1>
+class AddExpr : public BaseExpr<AddExpr<Arg0,Arg1> >
+{
+public:
+ AddExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
+
+ template<typename T>
+ Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) + m_arg1.eval_impl(values); }
+protected:
+ Arg0 m_arg0;
+ Arg1 m_arg1;
+};
+
+template<typename Arg0, typename Arg1>
+class ProductExpr : public BaseExpr<ProductExpr<Arg0,Arg1> >
+{
+public:
+ ProductExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
+
+ template<typename T>
+ Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) * m_arg1.eval_impl(values); }
+protected:
+ Arg0 m_arg0;
+ Arg1 m_arg1;
+};
+
+template<typename Arg0, typename Arg1>
+class QuotientExpr : public BaseExpr<QuotientExpr<Arg0,Arg1> >
+{
+public:
+ QuotientExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
+
+ template<typename T>
+ Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) / m_arg1.eval_impl(values); }
+protected:
+ Arg0 m_arg0;
+ Arg1 m_arg1;
+};
+
+} // end namespace symbolic
+
+} // end namespace Eigen
+
+#endif // EIGEN_SYMBOLIC_INDEX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Core/util/XprHelper.h b/src/3rdparty/eigen/Eigen/src/Core/util/XprHelper.h
new file mode 100644
index 000000000..71c32b8a1
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Core/util/XprHelper.h
@@ -0,0 +1,856 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_XPRHELPER_H
+#define EIGEN_XPRHELPER_H
+
+// just a workaround because GCC seems to not really like empty structs
+// FIXME: gcc 4.3 generates bad code when strict-aliasing is enabled
+// so currently we simply disable this optimization for gcc 4.3
+#if EIGEN_COMP_GNUC && !EIGEN_GNUC_AT(4,3)
+ #define EIGEN_EMPTY_STRUCT_CTOR(X) \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE X() {} \
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE X(const X& ) {}
+#else
+ #define EIGEN_EMPTY_STRUCT_CTOR(X)
+#endif
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename IndexDest, typename IndexSrc>
+EIGEN_DEVICE_FUNC
+inline IndexDest convert_index(const IndexSrc& idx) {
+ // for sizeof(IndexDest)>=sizeof(IndexSrc) compilers should be able to optimize this away:
+ eigen_internal_assert(idx <= NumTraits<IndexDest>::highest() && "Index value to big for target type");
+ return IndexDest(idx);
+}
+
+// true if T can be considered as an integral index (i.e., and integral type or enum)
+template<typename T> struct is_valid_index_type
+{
+ enum { value =
+#if EIGEN_HAS_TYPE_TRAITS
+ internal::is_integral<T>::value || std::is_enum<T>::value
+#elif EIGEN_COMP_MSVC
+ internal::is_integral<T>::value || __is_enum(T)
+#else
+ // without C++11, we use is_convertible to Index instead of is_integral in order to treat enums as Index.
+ internal::is_convertible<T,Index>::value && !internal::is_same<T,float>::value && !is_same<T,double>::value
+#endif
+ };
+};
+
+// true if both types are not valid index types
+template<typename RowIndices, typename ColIndices>
+struct valid_indexed_view_overload {
+ enum { value = !(internal::is_valid_index_type<RowIndices>::value && internal::is_valid_index_type<ColIndices>::value) };
+};
+
+// promote_scalar_arg is an helper used in operation between an expression and a scalar, like:
+// expression * scalar
+// Its role is to determine how the type T of the scalar operand should be promoted given the scalar type ExprScalar of the given expression.
+// The IsSupported template parameter must be provided by the caller as: internal::has_ReturnType<ScalarBinaryOpTraits<ExprScalar,T,op> >::value using the proper order for ExprScalar and T.
+// Then the logic is as follows:
+// - if the operation is natively supported as defined by IsSupported, then the scalar type is not promoted, and T is returned.
+// - otherwise, NumTraits<ExprScalar>::Literal is returned if T is implicitly convertible to NumTraits<ExprScalar>::Literal AND that this does not imply a float to integer conversion.
+// - otherwise, ExprScalar is returned if T is implicitly convertible to ExprScalar AND that this does not imply a float to integer conversion.
+// - In all other cases, the promoted type is not defined, and the respective operation is thus invalid and not available (SFINAE).
+template<typename ExprScalar,typename T, bool IsSupported>
+struct promote_scalar_arg;
+
+template<typename S,typename T>
+struct promote_scalar_arg<S,T,true>
+{
+ typedef T type;
+};
+
+// Recursively check safe conversion to PromotedType, and then ExprScalar if they are different.
+template<typename ExprScalar,typename T,typename PromotedType,
+ bool ConvertibleToLiteral = internal::is_convertible<T,PromotedType>::value,
+ bool IsSafe = NumTraits<T>::IsInteger || !NumTraits<PromotedType>::IsInteger>
+struct promote_scalar_arg_unsupported;
+
+// Start recursion with NumTraits<ExprScalar>::Literal
+template<typename S,typename T>
+struct promote_scalar_arg<S,T,false> : promote_scalar_arg_unsupported<S,T,typename NumTraits<S>::Literal> {};
+
+// We found a match!
+template<typename S,typename T, typename PromotedType>
+struct promote_scalar_arg_unsupported<S,T,PromotedType,true,true>
+{
+ typedef PromotedType type;
+};
+
+// No match, but no real-to-integer issues, and ExprScalar and current PromotedType are different,
+// so let's try to promote to ExprScalar
+template<typename ExprScalar,typename T, typename PromotedType>
+struct promote_scalar_arg_unsupported<ExprScalar,T,PromotedType,false,true>
+ : promote_scalar_arg_unsupported<ExprScalar,T,ExprScalar>
+{};
+
+// Unsafe real-to-integer, let's stop.
+template<typename S,typename T, typename PromotedType, bool ConvertibleToLiteral>
+struct promote_scalar_arg_unsupported<S,T,PromotedType,ConvertibleToLiteral,false> {};
+
+// T is not even convertible to ExprScalar, let's stop.
+template<typename S,typename T>
+struct promote_scalar_arg_unsupported<S,T,S,false,true> {};
+
+//classes inheriting no_assignment_operator don't generate a default operator=.
+class no_assignment_operator
+{
+ private:
+ no_assignment_operator& operator=(const no_assignment_operator&);
+ protected:
+ EIGEN_DEFAULT_COPY_CONSTRUCTOR(no_assignment_operator)
+ EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(no_assignment_operator)
+};
+
+/** \internal return the index type with the largest number of bits */
+template<typename I1, typename I2>
+struct promote_index_type
+{
+ typedef typename conditional<(sizeof(I1)<sizeof(I2)), I2, I1>::type type;
+};
+
+/** \internal If the template parameter Value is Dynamic, this class is just a wrapper around a T variable that
+ * can be accessed using value() and setValue().
+ * Otherwise, this class is an empty structure and value() just returns the template parameter Value.
+ */
+template<typename T, int Value> class variable_if_dynamic
+{
+ public:
+ EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(variable_if_dynamic)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit variable_if_dynamic(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); eigen_assert(v == T(Value)); }
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ T value() { return T(Value); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ operator T() const { return T(Value); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void setValue(T v) const { EIGEN_ONLY_USED_FOR_DEBUG(v); eigen_assert(v == T(Value)); }
+};
+
+template<typename T> class variable_if_dynamic<T, Dynamic>
+{
+ T m_value;
+ public:
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit variable_if_dynamic(T value = 0) EIGEN_NO_THROW : m_value(value) {}
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T value() const { return m_value; }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator T() const { return m_value; }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void setValue(T value) { m_value = value; }
+};
+
+/** \internal like variable_if_dynamic but for DynamicIndex
+ */
+template<typename T, int Value> class variable_if_dynamicindex
+{
+ public:
+ EIGEN_EMPTY_STRUCT_CTOR(variable_if_dynamicindex)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit variable_if_dynamicindex(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); eigen_assert(v == T(Value)); }
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+ T value() { return T(Value); }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ void setValue(T) {}
+};
+
+template<typename T> class variable_if_dynamicindex<T, DynamicIndex>
+{
+ T m_value;
+ EIGEN_DEVICE_FUNC variable_if_dynamicindex() { eigen_assert(false); }
+ public:
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit variable_if_dynamicindex(T value) : m_value(value) {}
+ EIGEN_DEVICE_FUNC T EIGEN_STRONG_INLINE value() const { return m_value; }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void setValue(T value) { m_value = value; }
+};
+
+template<typename T> struct functor_traits
+{
+ enum
+ {
+ Cost = 10,
+ PacketAccess = false,
+ IsRepeatable = false
+ };
+};
+
+template<typename T> struct packet_traits;
+
+template<typename T> struct unpacket_traits;
+
+template<int Size, typename PacketType,
+ bool Stop = Size==Dynamic || (Size%unpacket_traits<PacketType>::size)==0 || is_same<PacketType,typename unpacket_traits<PacketType>::half>::value>
+struct find_best_packet_helper;
+
+template< int Size, typename PacketType>
+struct find_best_packet_helper<Size,PacketType,true>
+{
+ typedef PacketType type;
+};
+
+template<int Size, typename PacketType>
+struct find_best_packet_helper<Size,PacketType,false>
+{
+ typedef typename find_best_packet_helper<Size,typename unpacket_traits<PacketType>::half>::type type;
+};
+
+template<typename T, int Size>
+struct find_best_packet
+{
+ typedef typename find_best_packet_helper<Size,typename packet_traits<T>::type>::type type;
+};
+
+#if EIGEN_MAX_STATIC_ALIGN_BYTES>0
+template<int ArrayBytes, int AlignmentBytes,
+ bool Match = bool((ArrayBytes%AlignmentBytes)==0),
+ bool TryHalf = bool(EIGEN_MIN_ALIGN_BYTES<AlignmentBytes) >
+struct compute_default_alignment_helper
+{
+ enum { value = 0 };
+};
+
+template<int ArrayBytes, int AlignmentBytes, bool TryHalf>
+struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, true, TryHalf> // Match
+{
+ enum { value = AlignmentBytes };
+};
+
+template<int ArrayBytes, int AlignmentBytes>
+struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, false, true> // Try-half
+{
+ // current packet too large, try with an half-packet
+ enum { value = compute_default_alignment_helper<ArrayBytes, AlignmentBytes/2>::value };
+};
+#else
+// If static alignment is disabled, no need to bother.
+// This also avoids a division by zero in "bool Match = bool((ArrayBytes%AlignmentBytes)==0)"
+template<int ArrayBytes, int AlignmentBytes>
+struct compute_default_alignment_helper
+{
+ enum { value = 0 };
+};
+#endif
+
+template<typename T, int Size> struct compute_default_alignment {
+ enum { value = compute_default_alignment_helper<Size*sizeof(T),EIGEN_MAX_STATIC_ALIGN_BYTES>::value };
+};
+
+template<typename T> struct compute_default_alignment<T,Dynamic> {
+ enum { value = EIGEN_MAX_ALIGN_BYTES };
+};
+
+template<typename _Scalar, int _Rows, int _Cols,
+ int _Options = AutoAlign |
+ ( (_Rows==1 && _Cols!=1) ? RowMajor
+ : (_Cols==1 && _Rows!=1) ? ColMajor
+ : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ),
+ int _MaxRows = _Rows,
+ int _MaxCols = _Cols
+> class make_proper_matrix_type
+{
+ enum {
+ IsColVector = _Cols==1 && _Rows!=1,
+ IsRowVector = _Rows==1 && _Cols!=1,
+ Options = IsColVector ? (_Options | ColMajor) & ~RowMajor
+ : IsRowVector ? (_Options | RowMajor) & ~ColMajor
+ : _Options
+ };
+ public:
+ typedef Matrix<_Scalar, _Rows, _Cols, Options, _MaxRows, _MaxCols> type;
+};
+
+template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
+class compute_matrix_flags
+{
+ enum { row_major_bit = Options&RowMajor ? RowMajorBit : 0 };
+ public:
+ // FIXME currently we still have to handle DirectAccessBit at the expression level to handle DenseCoeffsBase<>
+ // and then propagate this information to the evaluator's flags.
+ // However, I (Gael) think that DirectAccessBit should only matter at the evaluation stage.
+ enum { ret = DirectAccessBit | LvalueBit | NestByRefBit | row_major_bit };
+};
+
+template<int _Rows, int _Cols> struct size_at_compile_time
+{
+ enum { ret = (_Rows==Dynamic || _Cols==Dynamic) ? Dynamic : _Rows * _Cols };
+};
+
+template<typename XprType> struct size_of_xpr_at_compile_time
+{
+ enum { ret = size_at_compile_time<traits<XprType>::RowsAtCompileTime,traits<XprType>::ColsAtCompileTime>::ret };
+};
+
+/* plain_matrix_type : the difference from eval is that plain_matrix_type is always a plain matrix type,
+ * whereas eval is a const reference in the case of a matrix
+ */
+
+template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct plain_matrix_type;
+template<typename T, typename BaseClassType, int Flags> struct plain_matrix_type_dense;
+template<typename T> struct plain_matrix_type<T,Dense>
+{
+ typedef typename plain_matrix_type_dense<T,typename traits<T>::XprKind, traits<T>::Flags>::type type;
+};
+template<typename T> struct plain_matrix_type<T,DiagonalShape>
+{
+ typedef typename T::PlainObject type;
+};
+
+template<typename T, int Flags> struct plain_matrix_type_dense<T,MatrixXpr,Flags>
+{
+ typedef Matrix<typename traits<T>::Scalar,
+ traits<T>::RowsAtCompileTime,
+ traits<T>::ColsAtCompileTime,
+ AutoAlign | (Flags&RowMajorBit ? RowMajor : ColMajor),
+ traits<T>::MaxRowsAtCompileTime,
+ traits<T>::MaxColsAtCompileTime
+ > type;
+};
+
+template<typename T, int Flags> struct plain_matrix_type_dense<T,ArrayXpr,Flags>
+{
+ typedef Array<typename traits<T>::Scalar,
+ traits<T>::RowsAtCompileTime,
+ traits<T>::ColsAtCompileTime,
+ AutoAlign | (Flags&RowMajorBit ? RowMajor : ColMajor),
+ traits<T>::MaxRowsAtCompileTime,
+ traits<T>::MaxColsAtCompileTime
+ > type;
+};
+
+/* eval : the return type of eval(). For matrices, this is just a const reference
+ * in order to avoid a useless copy
+ */
+
+template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct eval;
+
+template<typename T> struct eval<T,Dense>
+{
+ typedef typename plain_matrix_type<T>::type type;
+// typedef typename T::PlainObject type;
+// typedef T::Matrix<typename traits<T>::Scalar,
+// traits<T>::RowsAtCompileTime,
+// traits<T>::ColsAtCompileTime,
+// AutoAlign | (traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor),
+// traits<T>::MaxRowsAtCompileTime,
+// traits<T>::MaxColsAtCompileTime
+// > type;
+};
+
+template<typename T> struct eval<T,DiagonalShape>
+{
+ typedef typename plain_matrix_type<T>::type type;
+};
+
+// for matrices, no need to evaluate, just use a const reference to avoid a useless copy
+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
+struct eval<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
+{
+ typedef const Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& type;
+};
+
+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
+struct eval<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
+{
+ typedef const Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& type;
+};
+
+
+/* similar to plain_matrix_type, but using the evaluator's Flags */
+template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct plain_object_eval;
+
+template<typename T>
+struct plain_object_eval<T,Dense>
+{
+ typedef typename plain_matrix_type_dense<T,typename traits<T>::XprKind, evaluator<T>::Flags>::type type;
+};
+
+
+/* plain_matrix_type_column_major : same as plain_matrix_type but guaranteed to be column-major
+ */
+template<typename T> struct plain_matrix_type_column_major
+{
+ enum { Rows = traits<T>::RowsAtCompileTime,
+ Cols = traits<T>::ColsAtCompileTime,
+ MaxRows = traits<T>::MaxRowsAtCompileTime,
+ MaxCols = traits<T>::MaxColsAtCompileTime
+ };
+ typedef Matrix<typename traits<T>::Scalar,
+ Rows,
+ Cols,
+ (MaxRows==1&&MaxCols!=1) ? RowMajor : ColMajor,
+ MaxRows,
+ MaxCols
+ > type;
+};
+
+/* plain_matrix_type_row_major : same as plain_matrix_type but guaranteed to be row-major
+ */
+template<typename T> struct plain_matrix_type_row_major
+{
+ enum { Rows = traits<T>::RowsAtCompileTime,
+ Cols = traits<T>::ColsAtCompileTime,
+ MaxRows = traits<T>::MaxRowsAtCompileTime,
+ MaxCols = traits<T>::MaxColsAtCompileTime
+ };
+ typedef Matrix<typename traits<T>::Scalar,
+ Rows,
+ Cols,
+ (MaxCols==1&&MaxRows!=1) ? ColMajor : RowMajor,
+ MaxRows,
+ MaxCols
+ > type;
+};
+
+/** \internal The reference selector for template expressions. The idea is that we don't
+ * need to use references for expressions since they are light weight proxy
+ * objects which should generate no copying overhead. */
+template <typename T>
+struct ref_selector
+{
+ typedef typename conditional<
+ bool(traits<T>::Flags & NestByRefBit),
+ T const&,
+ const T
+ >::type type;
+
+ typedef typename conditional<
+ bool(traits<T>::Flags & NestByRefBit),
+ T &,
+ T
+ >::type non_const_type;
+};
+
+/** \internal Adds the const qualifier on the value-type of T2 if and only if T1 is a const type */
+template<typename T1, typename T2>
+struct transfer_constness
+{
+ typedef typename conditional<
+ bool(internal::is_const<T1>::value),
+ typename internal::add_const_on_value_type<T2>::type,
+ T2
+ >::type type;
+};
+
+
+// However, we still need a mechanism to detect whether an expression which is evaluated multiple time
+// has to be evaluated into a temporary.
+// That's the purpose of this new nested_eval helper:
+/** \internal Determines how a given expression should be nested when evaluated multiple times.
+ * For example, when you do a * (b+c), Eigen will determine how the expression b+c should be
+ * evaluated into the bigger product expression. The choice is between nesting the expression b+c as-is, or
+ * evaluating that expression b+c into a temporary variable d, and nest d so that the resulting expression is
+ * a*d. Evaluating can be beneficial for example if every coefficient access in the resulting expression causes
+ * many coefficient accesses in the nested expressions -- as is the case with matrix product for example.
+ *
+ * \tparam T the type of the expression being nested.
+ * \tparam n the number of coefficient accesses in the nested expression for each coefficient access in the bigger expression.
+ * \tparam PlainObject the type of the temporary if needed.
+ */
+template<typename T, int n, typename PlainObject = typename plain_object_eval<T>::type> struct nested_eval
+{
+ enum {
+ ScalarReadCost = NumTraits<typename traits<T>::Scalar>::ReadCost,
+ CoeffReadCost = evaluator<T>::CoeffReadCost, // NOTE What if an evaluator evaluate itself into a temporary?
+ // Then CoeffReadCost will be small (e.g., 1) but we still have to evaluate, especially if n>1.
+ // This situation is already taken care by the EvalBeforeNestingBit flag, which is turned ON
+ // for all evaluator creating a temporary. This flag is then propagated by the parent evaluators.
+ // Another solution could be to count the number of temps?
+ NAsInteger = n == Dynamic ? HugeCost : n,
+ CostEval = (NAsInteger+1) * ScalarReadCost + CoeffReadCost,
+ CostNoEval = NAsInteger * CoeffReadCost,
+ Evaluate = (int(evaluator<T>::Flags) & EvalBeforeNestingBit) || (int(CostEval) < int(CostNoEval))
+ };
+
+ typedef typename conditional<Evaluate, PlainObject, typename ref_selector<T>::type>::type type;
+};
+
+template<typename T>
+EIGEN_DEVICE_FUNC
+inline T* const_cast_ptr(const T* ptr)
+{
+ return const_cast<T*>(ptr);
+}
+
+template<typename Derived, typename XprKind = typename traits<Derived>::XprKind>
+struct dense_xpr_base
+{
+ /* dense_xpr_base should only ever be used on dense expressions, thus falling either into the MatrixXpr or into the ArrayXpr cases */
+};
+
+template<typename Derived>
+struct dense_xpr_base<Derived, MatrixXpr>
+{
+ typedef MatrixBase<Derived> type;
+};
+
+template<typename Derived>
+struct dense_xpr_base<Derived, ArrayXpr>
+{
+ typedef ArrayBase<Derived> type;
+};
+
+template<typename Derived, typename XprKind = typename traits<Derived>::XprKind, typename StorageKind = typename traits<Derived>::StorageKind>
+struct generic_xpr_base;
+
+template<typename Derived, typename XprKind>
+struct generic_xpr_base<Derived, XprKind, Dense>
+{
+ typedef typename dense_xpr_base<Derived,XprKind>::type type;
+};
+
+template<typename XprType, typename CastType> struct cast_return_type
+{
+ typedef typename XprType::Scalar CurrentScalarType;
+ typedef typename remove_all<CastType>::type _CastType;
+ typedef typename _CastType::Scalar NewScalarType;
+ typedef typename conditional<is_same<CurrentScalarType,NewScalarType>::value,
+ const XprType&,CastType>::type type;
+};
+
+template <typename A, typename B> struct promote_storage_type;
+
+template <typename A> struct promote_storage_type<A,A>
+{
+ typedef A ret;
+};
+template <typename A> struct promote_storage_type<A, const A>
+{
+ typedef A ret;
+};
+template <typename A> struct promote_storage_type<const A, A>
+{
+ typedef A ret;
+};
+
+/** \internal Specify the "storage kind" of applying a coefficient-wise
+ * binary operations between two expressions of kinds A and B respectively.
+ * The template parameter Functor permits to specialize the resulting storage kind wrt to
+ * the functor.
+ * The default rules are as follows:
+ * \code
+ * A op A -> A
+ * A op dense -> dense
+ * dense op B -> dense
+ * sparse op dense -> sparse
+ * dense op sparse -> sparse
+ * \endcode
+ */
+template <typename A, typename B, typename Functor> struct cwise_promote_storage_type;
+
+template <typename A, typename Functor> struct cwise_promote_storage_type<A,A,Functor> { typedef A ret; };
+template <typename Functor> struct cwise_promote_storage_type<Dense,Dense,Functor> { typedef Dense ret; };
+template <typename A, typename Functor> struct cwise_promote_storage_type<A,Dense,Functor> { typedef Dense ret; };
+template <typename B, typename Functor> struct cwise_promote_storage_type<Dense,B,Functor> { typedef Dense ret; };
+template <typename Functor> struct cwise_promote_storage_type<Sparse,Dense,Functor> { typedef Sparse ret; };
+template <typename Functor> struct cwise_promote_storage_type<Dense,Sparse,Functor> { typedef Sparse ret; };
+
+template <typename LhsKind, typename RhsKind, int LhsOrder, int RhsOrder> struct cwise_promote_storage_order {
+ enum { value = LhsOrder };
+};
+
+template <typename LhsKind, int LhsOrder, int RhsOrder> struct cwise_promote_storage_order<LhsKind,Sparse,LhsOrder,RhsOrder> { enum { value = RhsOrder }; };
+template <typename RhsKind, int LhsOrder, int RhsOrder> struct cwise_promote_storage_order<Sparse,RhsKind,LhsOrder,RhsOrder> { enum { value = LhsOrder }; };
+template <int Order> struct cwise_promote_storage_order<Sparse,Sparse,Order,Order> { enum { value = Order }; };
+
+
+/** \internal Specify the "storage kind" of multiplying an expression of kind A with kind B.
+ * The template parameter ProductTag permits to specialize the resulting storage kind wrt to
+ * some compile-time properties of the product: GemmProduct, GemvProduct, OuterProduct, InnerProduct.
+ * The default rules are as follows:
+ * \code
+ * K * K -> K
+ * dense * K -> dense
+ * K * dense -> dense
+ * diag * K -> K
+ * K * diag -> K
+ * Perm * K -> K
+ * K * Perm -> K
+ * \endcode
+ */
+template <typename A, typename B, int ProductTag> struct product_promote_storage_type;
+
+template <typename A, int ProductTag> struct product_promote_storage_type<A, A, ProductTag> { typedef A ret;};
+template <int ProductTag> struct product_promote_storage_type<Dense, Dense, ProductTag> { typedef Dense ret;};
+template <typename A, int ProductTag> struct product_promote_storage_type<A, Dense, ProductTag> { typedef Dense ret; };
+template <typename B, int ProductTag> struct product_promote_storage_type<Dense, B, ProductTag> { typedef Dense ret; };
+
+template <typename A, int ProductTag> struct product_promote_storage_type<A, DiagonalShape, ProductTag> { typedef A ret; };
+template <typename B, int ProductTag> struct product_promote_storage_type<DiagonalShape, B, ProductTag> { typedef B ret; };
+template <int ProductTag> struct product_promote_storage_type<Dense, DiagonalShape, ProductTag> { typedef Dense ret; };
+template <int ProductTag> struct product_promote_storage_type<DiagonalShape, Dense, ProductTag> { typedef Dense ret; };
+
+template <typename A, int ProductTag> struct product_promote_storage_type<A, PermutationStorage, ProductTag> { typedef A ret; };
+template <typename B, int ProductTag> struct product_promote_storage_type<PermutationStorage, B, ProductTag> { typedef B ret; };
+template <int ProductTag> struct product_promote_storage_type<Dense, PermutationStorage, ProductTag> { typedef Dense ret; };
+template <int ProductTag> struct product_promote_storage_type<PermutationStorage, Dense, ProductTag> { typedef Dense ret; };
+
+/** \internal gives the plain matrix or array type to store a row/column/diagonal of a matrix type.
+ * \tparam Scalar optional parameter allowing to pass a different scalar type than the one of the MatrixType.
+ */
+template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
+struct plain_row_type
+{
+ typedef Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime,
+ int(ExpressionType::PlainObject::Options) | int(RowMajor), 1, ExpressionType::MaxColsAtCompileTime> MatrixRowType;
+ typedef Array<Scalar, 1, ExpressionType::ColsAtCompileTime,
+ int(ExpressionType::PlainObject::Options) | int(RowMajor), 1, ExpressionType::MaxColsAtCompileTime> ArrayRowType;
+
+ typedef typename conditional<
+ is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
+ MatrixRowType,
+ ArrayRowType
+ >::type type;
+};
+
+template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
+struct plain_col_type
+{
+ typedef Matrix<Scalar, ExpressionType::RowsAtCompileTime, 1,
+ ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> MatrixColType;
+ typedef Array<Scalar, ExpressionType::RowsAtCompileTime, 1,
+ ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> ArrayColType;
+
+ typedef typename conditional<
+ is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
+ MatrixColType,
+ ArrayColType
+ >::type type;
+};
+
+template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
+struct plain_diag_type
+{
+ enum { diag_size = EIGEN_SIZE_MIN_PREFER_DYNAMIC(ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime),
+ max_diag_size = EIGEN_SIZE_MIN_PREFER_FIXED(ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime)
+ };
+ typedef Matrix<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> MatrixDiagType;
+ typedef Array<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> ArrayDiagType;
+
+ typedef typename conditional<
+ is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
+ MatrixDiagType,
+ ArrayDiagType
+ >::type type;
+};
+
+template<typename Expr,typename Scalar = typename Expr::Scalar>
+struct plain_constant_type
+{
+ enum { Options = (traits<Expr>::Flags&RowMajorBit)?RowMajor:0 };
+
+ typedef Array<Scalar, traits<Expr>::RowsAtCompileTime, traits<Expr>::ColsAtCompileTime,
+ Options, traits<Expr>::MaxRowsAtCompileTime,traits<Expr>::MaxColsAtCompileTime> array_type;
+
+ typedef Matrix<Scalar, traits<Expr>::RowsAtCompileTime, traits<Expr>::ColsAtCompileTime,
+ Options, traits<Expr>::MaxRowsAtCompileTime,traits<Expr>::MaxColsAtCompileTime> matrix_type;
+
+ typedef CwiseNullaryOp<scalar_constant_op<Scalar>, const typename conditional<is_same< typename traits<Expr>::XprKind, MatrixXpr >::value, matrix_type, array_type>::type > type;
+};
+
+template<typename ExpressionType>
+struct is_lvalue
+{
+ enum { value = (!bool(is_const<ExpressionType>::value)) &&
+ bool(traits<ExpressionType>::Flags & LvalueBit) };
+};
+
+template<typename T> struct is_diagonal
+{ enum { ret = false }; };
+
+template<typename T> struct is_diagonal<DiagonalBase<T> >
+{ enum { ret = true }; };
+
+template<typename T> struct is_diagonal<DiagonalWrapper<T> >
+{ enum { ret = true }; };
+
+template<typename T, int S> struct is_diagonal<DiagonalMatrix<T,S> >
+{ enum { ret = true }; };
+
+
+template<typename T> struct is_identity
+{ enum { value = false }; };
+
+template<typename T> struct is_identity<CwiseNullaryOp<internal::scalar_identity_op<typename T::Scalar>, T> >
+{ enum { value = true }; };
+
+
+template<typename S1, typename S2> struct glue_shapes;
+template<> struct glue_shapes<DenseShape,TriangularShape> { typedef TriangularShape type; };
+
+template<typename T1, typename T2>
+struct possibly_same_dense {
+ enum { value = has_direct_access<T1>::ret && has_direct_access<T2>::ret && is_same<typename T1::Scalar,typename T2::Scalar>::value };
+};
+
+template<typename T1, typename T2>
+EIGEN_DEVICE_FUNC
+bool is_same_dense(const T1 &mat1, const T2 &mat2, typename enable_if<possibly_same_dense<T1,T2>::value>::type * = 0)
+{
+ return (mat1.data()==mat2.data()) && (mat1.innerStride()==mat2.innerStride()) && (mat1.outerStride()==mat2.outerStride());
+}
+
+template<typename T1, typename T2>
+EIGEN_DEVICE_FUNC
+bool is_same_dense(const T1 &, const T2 &, typename enable_if<!possibly_same_dense<T1,T2>::value>::type * = 0)
+{
+ return false;
+}
+
+// Internal helper defining the cost of a scalar division for the type T.
+// The default heuristic can be specialized for each scalar type and architecture.
+template<typename T,bool Vectorized=false,typename EnableIf = void>
+struct scalar_div_cost {
+ enum { value = 8*NumTraits<T>::MulCost };
+};
+
+template<typename T,bool Vectorized>
+struct scalar_div_cost<std::complex<T>, Vectorized> {
+ enum { value = 2*scalar_div_cost<T>::value
+ + 6*NumTraits<T>::MulCost
+ + 3*NumTraits<T>::AddCost
+ };
+};
+
+
+template<bool Vectorized>
+struct scalar_div_cost<signed long,Vectorized,typename conditional<sizeof(long)==8,void,false_type>::type> { enum { value = 24 }; };
+template<bool Vectorized>
+struct scalar_div_cost<unsigned long,Vectorized,typename conditional<sizeof(long)==8,void,false_type>::type> { enum { value = 21 }; };
+
+
+#ifdef EIGEN_DEBUG_ASSIGN
+std::string demangle_traversal(int t)
+{
+ if(t==DefaultTraversal) return "DefaultTraversal";
+ if(t==LinearTraversal) return "LinearTraversal";
+ if(t==InnerVectorizedTraversal) return "InnerVectorizedTraversal";
+ if(t==LinearVectorizedTraversal) return "LinearVectorizedTraversal";
+ if(t==SliceVectorizedTraversal) return "SliceVectorizedTraversal";
+ return "?";
+}
+std::string demangle_unrolling(int t)
+{
+ if(t==NoUnrolling) return "NoUnrolling";
+ if(t==InnerUnrolling) return "InnerUnrolling";
+ if(t==CompleteUnrolling) return "CompleteUnrolling";
+ return "?";
+}
+std::string demangle_flags(int f)
+{
+ std::string res;
+ if(f&RowMajorBit) res += " | RowMajor";
+ if(f&PacketAccessBit) res += " | Packet";
+ if(f&LinearAccessBit) res += " | Linear";
+ if(f&LvalueBit) res += " | Lvalue";
+ if(f&DirectAccessBit) res += " | Direct";
+ if(f&NestByRefBit) res += " | NestByRef";
+ if(f&NoPreferredStorageOrderBit) res += " | NoPreferredStorageOrderBit";
+
+ return res;
+}
+#endif
+
+} // end namespace internal
+
+
+/** \class ScalarBinaryOpTraits
+ * \ingroup Core_Module
+ *
+ * \brief Determines whether the given binary operation of two numeric types is allowed and what the scalar return type is.
+ *
+ * This class permits to control the scalar return type of any binary operation performed on two different scalar types through (partial) template specializations.
+ *
+ * For instance, let \c U1, \c U2 and \c U3 be three user defined scalar types for which most operations between instances of \c U1 and \c U2 returns an \c U3.
+ * You can let %Eigen knows that by defining:
+ \code
+ template<typename BinaryOp>
+ struct ScalarBinaryOpTraits<U1,U2,BinaryOp> { typedef U3 ReturnType; };
+ template<typename BinaryOp>
+ struct ScalarBinaryOpTraits<U2,U1,BinaryOp> { typedef U3 ReturnType; };
+ \endcode
+ * You can then explicitly disable some particular operations to get more explicit error messages:
+ \code
+ template<>
+ struct ScalarBinaryOpTraits<U1,U2,internal::scalar_max_op<U1,U2> > {};
+ \endcode
+ * Or customize the return type for individual operation:
+ \code
+ template<>
+ struct ScalarBinaryOpTraits<U1,U2,internal::scalar_sum_op<U1,U2> > { typedef U1 ReturnType; };
+ \endcode
+ *
+ * By default, the following generic combinations are supported:
+ <table class="manual">
+ <tr><th>ScalarA</th><th>ScalarB</th><th>BinaryOp</th><th>ReturnType</th><th>Note</th></tr>
+ <tr ><td>\c T </td><td>\c T </td><td>\c * </td><td>\c T </td><td></td></tr>
+ <tr class="alt"><td>\c NumTraits<T>::Real </td><td>\c T </td><td>\c * </td><td>\c T </td><td>Only if \c NumTraits<T>::IsComplex </td></tr>
+ <tr ><td>\c T </td><td>\c NumTraits<T>::Real </td><td>\c * </td><td>\c T </td><td>Only if \c NumTraits<T>::IsComplex </td></tr>
+ </table>
+ *
+ * \sa CwiseBinaryOp
+ */
+template<typename ScalarA, typename ScalarB, typename BinaryOp=internal::scalar_product_op<ScalarA,ScalarB> >
+struct ScalarBinaryOpTraits
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ // for backward compatibility, use the hints given by the (deprecated) internal::scalar_product_traits class.
+ : internal::scalar_product_traits<ScalarA,ScalarB>
+#endif // EIGEN_PARSED_BY_DOXYGEN
+{};
+
+template<typename T, typename BinaryOp>
+struct ScalarBinaryOpTraits<T,T,BinaryOp>
+{
+ typedef T ReturnType;
+};
+
+template <typename T, typename BinaryOp>
+struct ScalarBinaryOpTraits<T, typename NumTraits<typename internal::enable_if<NumTraits<T>::IsComplex,T>::type>::Real, BinaryOp>
+{
+ typedef T ReturnType;
+};
+template <typename T, typename BinaryOp>
+struct ScalarBinaryOpTraits<typename NumTraits<typename internal::enable_if<NumTraits<T>::IsComplex,T>::type>::Real, T, BinaryOp>
+{
+ typedef T ReturnType;
+};
+
+// For Matrix * Permutation
+template<typename T, typename BinaryOp>
+struct ScalarBinaryOpTraits<T,void,BinaryOp>
+{
+ typedef T ReturnType;
+};
+
+// For Permutation * Matrix
+template<typename T, typename BinaryOp>
+struct ScalarBinaryOpTraits<void,T,BinaryOp>
+{
+ typedef T ReturnType;
+};
+
+// for Permutation*Permutation
+template<typename BinaryOp>
+struct ScalarBinaryOpTraits<void,void,BinaryOp>
+{
+ typedef void ReturnType;
+};
+
+// We require Lhs and Rhs to have "compatible" scalar types.
+// It is tempting to always allow mixing different types but remember that this is often impossible in the vectorized paths.
+// So allowing mixing different types gives very unexpected errors when enabling vectorization, when the user tries to
+// add together a float matrix and a double matrix.
+#define EIGEN_CHECK_BINARY_COMPATIBILIY(BINOP,LHS,RHS) \
+ EIGEN_STATIC_ASSERT((Eigen::internal::has_ReturnType<ScalarBinaryOpTraits<LHS, RHS,BINOP> >::value), \
+ YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
+
+} // end namespace Eigen
+
+#endif // EIGEN_XPRHELPER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexEigenSolver.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexEigenSolver.h
new file mode 100644
index 000000000..081e918f1
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexEigenSolver.h
@@ -0,0 +1,346 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Claire Maurice
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMPLEX_EIGEN_SOLVER_H
+#define EIGEN_COMPLEX_EIGEN_SOLVER_H
+
+#include "./ComplexSchur.h"
+
+namespace Eigen {
+
+/** \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ *
+ * \class ComplexEigenSolver
+ *
+ * \brief Computes eigenvalues and eigenvectors of general complex matrices
+ *
+ * \tparam _MatrixType the type of the matrix of which we are
+ * computing the eigendecomposition; this is expected to be an
+ * instantiation of the Matrix class template.
+ *
+ * The eigenvalues and eigenvectors of a matrix \f$ A \f$ are scalars
+ * \f$ \lambda \f$ and vectors \f$ v \f$ such that \f$ Av = \lambda v
+ * \f$. If \f$ D \f$ is a diagonal matrix with the eigenvalues on
+ * the diagonal, and \f$ V \f$ is a matrix with the eigenvectors as
+ * its columns, then \f$ A V = V D \f$. The matrix \f$ V \f$ is
+ * almost always invertible, in which case we have \f$ A = V D V^{-1}
+ * \f$. This is called the eigendecomposition.
+ *
+ * The main function in this class is compute(), which computes the
+ * eigenvalues and eigenvectors of a given function. The
+ * documentation for that function contains an example showing the
+ * main features of the class.
+ *
+ * \sa class EigenSolver, class SelfAdjointEigenSolver
+ */
+template<typename _MatrixType> class ComplexEigenSolver
+{
+ public:
+
+ /** \brief Synonym for the template parameter \p _MatrixType. */
+ typedef _MatrixType MatrixType;
+
+ enum {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ Options = MatrixType::Options,
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+
+ /** \brief Scalar type for matrices of type #MatrixType. */
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+
+ /** \brief Complex scalar type for #MatrixType.
+ *
+ * This is \c std::complex<Scalar> if #Scalar is real (e.g.,
+ * \c float or \c double) and just \c Scalar if #Scalar is
+ * complex.
+ */
+ typedef std::complex<RealScalar> ComplexScalar;
+
+ /** \brief Type for vector of eigenvalues as returned by eigenvalues().
+ *
+ * This is a column vector with entries of type #ComplexScalar.
+ * The length of the vector is the size of #MatrixType.
+ */
+ typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options&(~RowMajor), MaxColsAtCompileTime, 1> EigenvalueType;
+
+ /** \brief Type for matrix of eigenvectors as returned by eigenvectors().
+ *
+ * This is a square matrix with entries of type #ComplexScalar.
+ * The size is the same as the size of #MatrixType.
+ */
+ typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> EigenvectorType;
+
+ /** \brief Default constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via compute().
+ */
+ ComplexEigenSolver()
+ : m_eivec(),
+ m_eivalues(),
+ m_schur(),
+ m_isInitialized(false),
+ m_eigenvectorsOk(false),
+ m_matX()
+ {}
+
+ /** \brief Default Constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem \a size.
+ * \sa ComplexEigenSolver()
+ */
+ explicit ComplexEigenSolver(Index size)
+ : m_eivec(size, size),
+ m_eivalues(size),
+ m_schur(size),
+ m_isInitialized(false),
+ m_eigenvectorsOk(false),
+ m_matX(size, size)
+ {}
+
+ /** \brief Constructor; computes eigendecomposition of given matrix.
+ *
+ * \param[in] matrix Square matrix whose eigendecomposition is to be computed.
+ * \param[in] computeEigenvectors If true, both the eigenvectors and the
+ * eigenvalues are computed; if false, only the eigenvalues are
+ * computed.
+ *
+ * This constructor calls compute() to compute the eigendecomposition.
+ */
+ template<typename InputType>
+ explicit ComplexEigenSolver(const EigenBase<InputType>& matrix, bool computeEigenvectors = true)
+ : m_eivec(matrix.rows(),matrix.cols()),
+ m_eivalues(matrix.cols()),
+ m_schur(matrix.rows()),
+ m_isInitialized(false),
+ m_eigenvectorsOk(false),
+ m_matX(matrix.rows(),matrix.cols())
+ {
+ compute(matrix.derived(), computeEigenvectors);
+ }
+
+ /** \brief Returns the eigenvectors of given matrix.
+ *
+ * \returns A const reference to the matrix whose columns are the eigenvectors.
+ *
+ * \pre Either the constructor
+ * ComplexEigenSolver(const MatrixType& matrix, bool) or the member
+ * function compute(const MatrixType& matrix, bool) has been called before
+ * to compute the eigendecomposition of a matrix, and
+ * \p computeEigenvectors was set to true (the default).
+ *
+ * This function returns a matrix whose columns are the eigenvectors. Column
+ * \f$ k \f$ is an eigenvector corresponding to eigenvalue number \f$ k
+ * \f$ as returned by eigenvalues(). The eigenvectors are normalized to
+ * have (Euclidean) norm equal to one. The matrix returned by this
+ * function is the matrix \f$ V \f$ in the eigendecomposition \f$ A = V D
+ * V^{-1} \f$, if it exists.
+ *
+ * Example: \include ComplexEigenSolver_eigenvectors.cpp
+ * Output: \verbinclude ComplexEigenSolver_eigenvectors.out
+ */
+ const EigenvectorType& eigenvectors() const
+ {
+ eigen_assert(m_isInitialized && "ComplexEigenSolver is not initialized.");
+ eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
+ return m_eivec;
+ }
+
+ /** \brief Returns the eigenvalues of given matrix.
+ *
+ * \returns A const reference to the column vector containing the eigenvalues.
+ *
+ * \pre Either the constructor
+ * ComplexEigenSolver(const MatrixType& matrix, bool) or the member
+ * function compute(const MatrixType& matrix, bool) has been called before
+ * to compute the eigendecomposition of a matrix.
+ *
+ * This function returns a column vector containing the
+ * eigenvalues. Eigenvalues are repeated according to their
+ * algebraic multiplicity, so there are as many eigenvalues as
+ * rows in the matrix. The eigenvalues are not sorted in any particular
+ * order.
+ *
+ * Example: \include ComplexEigenSolver_eigenvalues.cpp
+ * Output: \verbinclude ComplexEigenSolver_eigenvalues.out
+ */
+ const EigenvalueType& eigenvalues() const
+ {
+ eigen_assert(m_isInitialized && "ComplexEigenSolver is not initialized.");
+ return m_eivalues;
+ }
+
+ /** \brief Computes eigendecomposition of given matrix.
+ *
+ * \param[in] matrix Square matrix whose eigendecomposition is to be computed.
+ * \param[in] computeEigenvectors If true, both the eigenvectors and the
+ * eigenvalues are computed; if false, only the eigenvalues are
+ * computed.
+ * \returns Reference to \c *this
+ *
+ * This function computes the eigenvalues of the complex matrix \p matrix.
+ * The eigenvalues() function can be used to retrieve them. If
+ * \p computeEigenvectors is true, then the eigenvectors are also computed
+ * and can be retrieved by calling eigenvectors().
+ *
+ * The matrix is first reduced to Schur form using the
+ * ComplexSchur class. The Schur decomposition is then used to
+ * compute the eigenvalues and eigenvectors.
+ *
+ * The cost of the computation is dominated by the cost of the
+ * Schur decomposition, which is \f$ O(n^3) \f$ where \f$ n \f$
+ * is the size of the matrix.
+ *
+ * Example: \include ComplexEigenSolver_compute.cpp
+ * Output: \verbinclude ComplexEigenSolver_compute.out
+ */
+ template<typename InputType>
+ ComplexEigenSolver& compute(const EigenBase<InputType>& matrix, bool computeEigenvectors = true);
+
+ /** \brief Reports whether previous computation was successful.
+ *
+ * \returns \c Success if computation was successful, \c NoConvergence otherwise.
+ */
+ ComputationInfo info() const
+ {
+ eigen_assert(m_isInitialized && "ComplexEigenSolver is not initialized.");
+ return m_schur.info();
+ }
+
+ /** \brief Sets the maximum number of iterations allowed. */
+ ComplexEigenSolver& setMaxIterations(Index maxIters)
+ {
+ m_schur.setMaxIterations(maxIters);
+ return *this;
+ }
+
+ /** \brief Returns the maximum number of iterations. */
+ Index getMaxIterations()
+ {
+ return m_schur.getMaxIterations();
+ }
+
+ protected:
+
+ static void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ }
+
+ EigenvectorType m_eivec;
+ EigenvalueType m_eivalues;
+ ComplexSchur<MatrixType> m_schur;
+ bool m_isInitialized;
+ bool m_eigenvectorsOk;
+ EigenvectorType m_matX;
+
+ private:
+ void doComputeEigenvectors(RealScalar matrixnorm);
+ void sortEigenvalues(bool computeEigenvectors);
+};
+
+
+template<typename MatrixType>
+template<typename InputType>
+ComplexEigenSolver<MatrixType>&
+ComplexEigenSolver<MatrixType>::compute(const EigenBase<InputType>& matrix, bool computeEigenvectors)
+{
+ check_template_parameters();
+
+ // this code is inspired from Jampack
+ eigen_assert(matrix.cols() == matrix.rows());
+
+ // Do a complex Schur decomposition, A = U T U^*
+ // The eigenvalues are on the diagonal of T.
+ m_schur.compute(matrix.derived(), computeEigenvectors);
+
+ if(m_schur.info() == Success)
+ {
+ m_eivalues = m_schur.matrixT().diagonal();
+ if(computeEigenvectors)
+ doComputeEigenvectors(m_schur.matrixT().norm());
+ sortEigenvalues(computeEigenvectors);
+ }
+
+ m_isInitialized = true;
+ m_eigenvectorsOk = computeEigenvectors;
+ return *this;
+}
+
+
+template<typename MatrixType>
+void ComplexEigenSolver<MatrixType>::doComputeEigenvectors(RealScalar matrixnorm)
+{
+ const Index n = m_eivalues.size();
+
+ matrixnorm = numext::maxi(matrixnorm,(std::numeric_limits<RealScalar>::min)());
+
+ // Compute X such that T = X D X^(-1), where D is the diagonal of T.
+ // The matrix X is unit triangular.
+ m_matX = EigenvectorType::Zero(n, n);
+ for(Index k=n-1 ; k>=0 ; k--)
+ {
+ m_matX.coeffRef(k,k) = ComplexScalar(1.0,0.0);
+ // Compute X(i,k) using the (i,k) entry of the equation X T = D X
+ for(Index i=k-1 ; i>=0 ; i--)
+ {
+ m_matX.coeffRef(i,k) = -m_schur.matrixT().coeff(i,k);
+ if(k-i-1>0)
+ m_matX.coeffRef(i,k) -= (m_schur.matrixT().row(i).segment(i+1,k-i-1) * m_matX.col(k).segment(i+1,k-i-1)).value();
+ ComplexScalar z = m_schur.matrixT().coeff(i,i) - m_schur.matrixT().coeff(k,k);
+ if(z==ComplexScalar(0))
+ {
+ // If the i-th and k-th eigenvalue are equal, then z equals 0.
+ // Use a small value instead, to prevent division by zero.
+ numext::real_ref(z) = NumTraits<RealScalar>::epsilon() * matrixnorm;
+ }
+ m_matX.coeffRef(i,k) = m_matX.coeff(i,k) / z;
+ }
+ }
+
+ // Compute V as V = U X; now A = U T U^* = U X D X^(-1) U^* = V D V^(-1)
+ m_eivec.noalias() = m_schur.matrixU() * m_matX;
+ // .. and normalize the eigenvectors
+ for(Index k=0 ; k<n ; k++)
+ {
+ m_eivec.col(k).normalize();
+ }
+}
+
+
+template<typename MatrixType>
+void ComplexEigenSolver<MatrixType>::sortEigenvalues(bool computeEigenvectors)
+{
+ const Index n = m_eivalues.size();
+ for (Index i=0; i<n; i++)
+ {
+ Index k;
+ m_eivalues.cwiseAbs().tail(n-i).minCoeff(&k);
+ if (k != 0)
+ {
+ k += i;
+ std::swap(m_eivalues[k],m_eivalues[i]);
+ if(computeEigenvectors)
+ m_eivec.col(i).swap(m_eivec.col(k));
+ }
+ }
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_COMPLEX_EIGEN_SOLVER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexSchur.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexSchur.h
new file mode 100644
index 000000000..fc71468f8
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexSchur.h
@@ -0,0 +1,462 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Claire Maurice
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMPLEX_SCHUR_H
+#define EIGEN_COMPLEX_SCHUR_H
+
+#include "./HessenbergDecomposition.h"
+
+namespace Eigen {
+
+namespace internal {
+template<typename MatrixType, bool IsComplex> struct complex_schur_reduce_to_hessenberg;
+}
+
+/** \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ *
+ * \class ComplexSchur
+ *
+ * \brief Performs a complex Schur decomposition of a real or complex square matrix
+ *
+ * \tparam _MatrixType the type of the matrix of which we are
+ * computing the Schur decomposition; this is expected to be an
+ * instantiation of the Matrix class template.
+ *
+ * Given a real or complex square matrix A, this class computes the
+ * Schur decomposition: \f$ A = U T U^*\f$ where U is a unitary
+ * complex matrix, and T is a complex upper triangular matrix. The
+ * diagonal of the matrix T corresponds to the eigenvalues of the
+ * matrix A.
+ *
+ * Call the function compute() to compute the Schur decomposition of
+ * a given matrix. Alternatively, you can use the
+ * ComplexSchur(const MatrixType&, bool) constructor which computes
+ * the Schur decomposition at construction time. Once the
+ * decomposition is computed, you can use the matrixU() and matrixT()
+ * functions to retrieve the matrices U and V in the decomposition.
+ *
+ * \note This code is inspired from Jampack
+ *
+ * \sa class RealSchur, class EigenSolver, class ComplexEigenSolver
+ */
+template<typename _MatrixType> class ComplexSchur
+{
+ public:
+ typedef _MatrixType MatrixType;
+ enum {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ Options = MatrixType::Options,
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+
+ /** \brief Scalar type for matrices of type \p _MatrixType. */
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+
+ /** \brief Complex scalar type for \p _MatrixType.
+ *
+ * This is \c std::complex<Scalar> if #Scalar is real (e.g.,
+ * \c float or \c double) and just \c Scalar if #Scalar is
+ * complex.
+ */
+ typedef std::complex<RealScalar> ComplexScalar;
+
+ /** \brief Type for the matrices in the Schur decomposition.
+ *
+ * This is a square matrix with entries of type #ComplexScalar.
+ * The size is the same as the size of \p _MatrixType.
+ */
+ typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> ComplexMatrixType;
+
+ /** \brief Default constructor.
+ *
+ * \param [in] size Positive integer, size of the matrix whose Schur decomposition will be computed.
+ *
+ * The default constructor is useful in cases in which the user
+ * intends to perform decompositions via compute(). The \p size
+ * parameter is only used as a hint. It is not an error to give a
+ * wrong \p size, but it may impair performance.
+ *
+ * \sa compute() for an example.
+ */
+ explicit ComplexSchur(Index size = RowsAtCompileTime==Dynamic ? 1 : RowsAtCompileTime)
+ : m_matT(size,size),
+ m_matU(size,size),
+ m_hess(size),
+ m_isInitialized(false),
+ m_matUisUptodate(false),
+ m_maxIters(-1)
+ {}
+
+ /** \brief Constructor; computes Schur decomposition of given matrix.
+ *
+ * \param[in] matrix Square matrix whose Schur decomposition is to be computed.
+ * \param[in] computeU If true, both T and U are computed; if false, only T is computed.
+ *
+ * This constructor calls compute() to compute the Schur decomposition.
+ *
+ * \sa matrixT() and matrixU() for examples.
+ */
+ template<typename InputType>
+ explicit ComplexSchur(const EigenBase<InputType>& matrix, bool computeU = true)
+ : m_matT(matrix.rows(),matrix.cols()),
+ m_matU(matrix.rows(),matrix.cols()),
+ m_hess(matrix.rows()),
+ m_isInitialized(false),
+ m_matUisUptodate(false),
+ m_maxIters(-1)
+ {
+ compute(matrix.derived(), computeU);
+ }
+
+ /** \brief Returns the unitary matrix in the Schur decomposition.
+ *
+ * \returns A const reference to the matrix U.
+ *
+ * It is assumed that either the constructor
+ * ComplexSchur(const MatrixType& matrix, bool computeU) or the
+ * member function compute(const MatrixType& matrix, bool computeU)
+ * has been called before to compute the Schur decomposition of a
+ * matrix, and that \p computeU was set to true (the default
+ * value).
+ *
+ * Example: \include ComplexSchur_matrixU.cpp
+ * Output: \verbinclude ComplexSchur_matrixU.out
+ */
+ const ComplexMatrixType& matrixU() const
+ {
+ eigen_assert(m_isInitialized && "ComplexSchur is not initialized.");
+ eigen_assert(m_matUisUptodate && "The matrix U has not been computed during the ComplexSchur decomposition.");
+ return m_matU;
+ }
+
+ /** \brief Returns the triangular matrix in the Schur decomposition.
+ *
+ * \returns A const reference to the matrix T.
+ *
+ * It is assumed that either the constructor
+ * ComplexSchur(const MatrixType& matrix, bool computeU) or the
+ * member function compute(const MatrixType& matrix, bool computeU)
+ * has been called before to compute the Schur decomposition of a
+ * matrix.
+ *
+ * Note that this function returns a plain square matrix. If you want to reference
+ * only the upper triangular part, use:
+ * \code schur.matrixT().triangularView<Upper>() \endcode
+ *
+ * Example: \include ComplexSchur_matrixT.cpp
+ * Output: \verbinclude ComplexSchur_matrixT.out
+ */
+ const ComplexMatrixType& matrixT() const
+ {
+ eigen_assert(m_isInitialized && "ComplexSchur is not initialized.");
+ return m_matT;
+ }
+
+ /** \brief Computes Schur decomposition of given matrix.
+ *
+ * \param[in] matrix Square matrix whose Schur decomposition is to be computed.
+ * \param[in] computeU If true, both T and U are computed; if false, only T is computed.
+
+ * \returns Reference to \c *this
+ *
+ * The Schur decomposition is computed by first reducing the
+ * matrix to Hessenberg form using the class
+ * HessenbergDecomposition. The Hessenberg matrix is then reduced
+ * to triangular form by performing QR iterations with a single
+ * shift. The cost of computing the Schur decomposition depends
+ * on the number of iterations; as a rough guide, it may be taken
+ * on the number of iterations; as a rough guide, it may be taken
+ * to be \f$25n^3\f$ complex flops, or \f$10n^3\f$ complex flops
+ * if \a computeU is false.
+ *
+ * Example: \include ComplexSchur_compute.cpp
+ * Output: \verbinclude ComplexSchur_compute.out
+ *
+ * \sa compute(const MatrixType&, bool, Index)
+ */
+ template<typename InputType>
+ ComplexSchur& compute(const EigenBase<InputType>& matrix, bool computeU = true);
+
+ /** \brief Compute Schur decomposition from a given Hessenberg matrix
+ * \param[in] matrixH Matrix in Hessenberg form H
+ * \param[in] matrixQ orthogonal matrix Q that transform a matrix A to H : A = Q H Q^T
+ * \param computeU Computes the matriX U of the Schur vectors
+ * \return Reference to \c *this
+ *
+ * This routine assumes that the matrix is already reduced in Hessenberg form matrixH
+ * using either the class HessenbergDecomposition or another mean.
+ * It computes the upper quasi-triangular matrix T of the Schur decomposition of H
+ * When computeU is true, this routine computes the matrix U such that
+ * A = U T U^T = (QZ) T (QZ)^T = Q H Q^T where A is the initial matrix
+ *
+ * NOTE Q is referenced if computeU is true; so, if the initial orthogonal matrix
+ * is not available, the user should give an identity matrix (Q.setIdentity())
+ *
+ * \sa compute(const MatrixType&, bool)
+ */
+ template<typename HessMatrixType, typename OrthMatrixType>
+ ComplexSchur& computeFromHessenberg(const HessMatrixType& matrixH, const OrthMatrixType& matrixQ, bool computeU=true);
+
+ /** \brief Reports whether previous computation was successful.
+ *
+ * \returns \c Success if computation was successful, \c NoConvergence otherwise.
+ */
+ ComputationInfo info() const
+ {
+ eigen_assert(m_isInitialized && "ComplexSchur is not initialized.");
+ return m_info;
+ }
+
+ /** \brief Sets the maximum number of iterations allowed.
+ *
+ * If not specified by the user, the maximum number of iterations is m_maxIterationsPerRow times the size
+ * of the matrix.
+ */
+ ComplexSchur& setMaxIterations(Index maxIters)
+ {
+ m_maxIters = maxIters;
+ return *this;
+ }
+
+ /** \brief Returns the maximum number of iterations. */
+ Index getMaxIterations()
+ {
+ return m_maxIters;
+ }
+
+ /** \brief Maximum number of iterations per row.
+ *
+ * If not otherwise specified, the maximum number of iterations is this number times the size of the
+ * matrix. It is currently set to 30.
+ */
+ static const int m_maxIterationsPerRow = 30;
+
+ protected:
+ ComplexMatrixType m_matT, m_matU;
+ HessenbergDecomposition<MatrixType> m_hess;
+ ComputationInfo m_info;
+ bool m_isInitialized;
+ bool m_matUisUptodate;
+ Index m_maxIters;
+
+ private:
+ bool subdiagonalEntryIsNeglegible(Index i);
+ ComplexScalar computeShift(Index iu, Index iter);
+ void reduceToTriangularForm(bool computeU);
+ friend struct internal::complex_schur_reduce_to_hessenberg<MatrixType, NumTraits<Scalar>::IsComplex>;
+};
+
+/** If m_matT(i+1,i) is neglegible in floating point arithmetic
+ * compared to m_matT(i,i) and m_matT(j,j), then set it to zero and
+ * return true, else return false. */
+template<typename MatrixType>
+inline bool ComplexSchur<MatrixType>::subdiagonalEntryIsNeglegible(Index i)
+{
+ RealScalar d = numext::norm1(m_matT.coeff(i,i)) + numext::norm1(m_matT.coeff(i+1,i+1));
+ RealScalar sd = numext::norm1(m_matT.coeff(i+1,i));
+ if (internal::isMuchSmallerThan(sd, d, NumTraits<RealScalar>::epsilon()))
+ {
+ m_matT.coeffRef(i+1,i) = ComplexScalar(0);
+ return true;
+ }
+ return false;
+}
+
+
+/** Compute the shift in the current QR iteration. */
+template<typename MatrixType>
+typename ComplexSchur<MatrixType>::ComplexScalar ComplexSchur<MatrixType>::computeShift(Index iu, Index iter)
+{
+ using std::abs;
+ if (iter == 10 || iter == 20)
+ {
+ // exceptional shift, taken from http://www.netlib.org/eispack/comqr.f
+ return abs(numext::real(m_matT.coeff(iu,iu-1))) + abs(numext::real(m_matT.coeff(iu-1,iu-2)));
+ }
+
+ // compute the shift as one of the eigenvalues of t, the 2x2
+ // diagonal block on the bottom of the active submatrix
+ Matrix<ComplexScalar,2,2> t = m_matT.template block<2,2>(iu-1,iu-1);
+ RealScalar normt = t.cwiseAbs().sum();
+ t /= normt; // the normalization by sf is to avoid under/overflow
+
+ ComplexScalar b = t.coeff(0,1) * t.coeff(1,0);
+ ComplexScalar c = t.coeff(0,0) - t.coeff(1,1);
+ ComplexScalar disc = sqrt(c*c + RealScalar(4)*b);
+ ComplexScalar det = t.coeff(0,0) * t.coeff(1,1) - b;
+ ComplexScalar trace = t.coeff(0,0) + t.coeff(1,1);
+ ComplexScalar eival1 = (trace + disc) / RealScalar(2);
+ ComplexScalar eival2 = (trace - disc) / RealScalar(2);
+ RealScalar eival1_norm = numext::norm1(eival1);
+ RealScalar eival2_norm = numext::norm1(eival2);
+ // A division by zero can only occur if eival1==eival2==0.
+ // In this case, det==0, and all we have to do is checking that eival2_norm!=0
+ if(eival1_norm > eival2_norm)
+ eival2 = det / eival1;
+ else if(eival2_norm!=RealScalar(0))
+ eival1 = det / eival2;
+
+ // choose the eigenvalue closest to the bottom entry of the diagonal
+ if(numext::norm1(eival1-t.coeff(1,1)) < numext::norm1(eival2-t.coeff(1,1)))
+ return normt * eival1;
+ else
+ return normt * eival2;
+}
+
+
+template<typename MatrixType>
+template<typename InputType>
+ComplexSchur<MatrixType>& ComplexSchur<MatrixType>::compute(const EigenBase<InputType>& matrix, bool computeU)
+{
+ m_matUisUptodate = false;
+ eigen_assert(matrix.cols() == matrix.rows());
+
+ if(matrix.cols() == 1)
+ {
+ m_matT = matrix.derived().template cast<ComplexScalar>();
+ if(computeU) m_matU = ComplexMatrixType::Identity(1,1);
+ m_info = Success;
+ m_isInitialized = true;
+ m_matUisUptodate = computeU;
+ return *this;
+ }
+
+ internal::complex_schur_reduce_to_hessenberg<MatrixType, NumTraits<Scalar>::IsComplex>::run(*this, matrix.derived(), computeU);
+ computeFromHessenberg(m_matT, m_matU, computeU);
+ return *this;
+}
+
+template<typename MatrixType>
+template<typename HessMatrixType, typename OrthMatrixType>
+ComplexSchur<MatrixType>& ComplexSchur<MatrixType>::computeFromHessenberg(const HessMatrixType& matrixH, const OrthMatrixType& matrixQ, bool computeU)
+{
+ m_matT = matrixH;
+ if(computeU)
+ m_matU = matrixQ;
+ reduceToTriangularForm(computeU);
+ return *this;
+}
+namespace internal {
+
+/* Reduce given matrix to Hessenberg form */
+template<typename MatrixType, bool IsComplex>
+struct complex_schur_reduce_to_hessenberg
+{
+ // this is the implementation for the case IsComplex = true
+ static void run(ComplexSchur<MatrixType>& _this, const MatrixType& matrix, bool computeU)
+ {
+ _this.m_hess.compute(matrix);
+ _this.m_matT = _this.m_hess.matrixH();
+ if(computeU) _this.m_matU = _this.m_hess.matrixQ();
+ }
+};
+
+template<typename MatrixType>
+struct complex_schur_reduce_to_hessenberg<MatrixType, false>
+{
+ static void run(ComplexSchur<MatrixType>& _this, const MatrixType& matrix, bool computeU)
+ {
+ typedef typename ComplexSchur<MatrixType>::ComplexScalar ComplexScalar;
+
+ // Note: m_hess is over RealScalar; m_matT and m_matU is over ComplexScalar
+ _this.m_hess.compute(matrix);
+ _this.m_matT = _this.m_hess.matrixH().template cast<ComplexScalar>();
+ if(computeU)
+ {
+ // This may cause an allocation which seems to be avoidable
+ MatrixType Q = _this.m_hess.matrixQ();
+ _this.m_matU = Q.template cast<ComplexScalar>();
+ }
+ }
+};
+
+} // end namespace internal
+
+// Reduce the Hessenberg matrix m_matT to triangular form by QR iteration.
+template<typename MatrixType>
+void ComplexSchur<MatrixType>::reduceToTriangularForm(bool computeU)
+{
+ Index maxIters = m_maxIters;
+ if (maxIters == -1)
+ maxIters = m_maxIterationsPerRow * m_matT.rows();
+
+ // The matrix m_matT is divided in three parts.
+ // Rows 0,...,il-1 are decoupled from the rest because m_matT(il,il-1) is zero.
+ // Rows il,...,iu is the part we are working on (the active submatrix).
+ // Rows iu+1,...,end are already brought in triangular form.
+ Index iu = m_matT.cols() - 1;
+ Index il;
+ Index iter = 0; // number of iterations we are working on the (iu,iu) element
+ Index totalIter = 0; // number of iterations for whole matrix
+
+ while(true)
+ {
+ // find iu, the bottom row of the active submatrix
+ while(iu > 0)
+ {
+ if(!subdiagonalEntryIsNeglegible(iu-1)) break;
+ iter = 0;
+ --iu;
+ }
+
+ // if iu is zero then we are done; the whole matrix is triangularized
+ if(iu==0) break;
+
+ // if we spent too many iterations, we give up
+ iter++;
+ totalIter++;
+ if(totalIter > maxIters) break;
+
+ // find il, the top row of the active submatrix
+ il = iu-1;
+ while(il > 0 && !subdiagonalEntryIsNeglegible(il-1))
+ {
+ --il;
+ }
+
+ /* perform the QR step using Givens rotations. The first rotation
+ creates a bulge; the (il+2,il) element becomes nonzero. This
+ bulge is chased down to the bottom of the active submatrix. */
+
+ ComplexScalar shift = computeShift(iu, iter);
+ JacobiRotation<ComplexScalar> rot;
+ rot.makeGivens(m_matT.coeff(il,il) - shift, m_matT.coeff(il+1,il));
+ m_matT.rightCols(m_matT.cols()-il).applyOnTheLeft(il, il+1, rot.adjoint());
+ m_matT.topRows((std::min)(il+2,iu)+1).applyOnTheRight(il, il+1, rot);
+ if(computeU) m_matU.applyOnTheRight(il, il+1, rot);
+
+ for(Index i=il+1 ; i<iu ; i++)
+ {
+ rot.makeGivens(m_matT.coeffRef(i,i-1), m_matT.coeffRef(i+1,i-1), &m_matT.coeffRef(i,i-1));
+ m_matT.coeffRef(i+1,i-1) = ComplexScalar(0);
+ m_matT.rightCols(m_matT.cols()-i).applyOnTheLeft(i, i+1, rot.adjoint());
+ m_matT.topRows((std::min)(i+2,iu)+1).applyOnTheRight(i, i+1, rot);
+ if(computeU) m_matU.applyOnTheRight(i, i+1, rot);
+ }
+ }
+
+ if(totalIter <= maxIters)
+ m_info = Success;
+ else
+ m_info = NoConvergence;
+
+ m_isInitialized = true;
+ m_matUisUptodate = computeU;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_COMPLEX_SCHUR_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h
new file mode 100644
index 000000000..4980a3ede
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h
@@ -0,0 +1,91 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to LAPACKe
+ * Complex Schur needed to complex unsymmetrical eigenvalues/eigenvectors.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_COMPLEX_SCHUR_LAPACKE_H
+#define EIGEN_COMPLEX_SCHUR_LAPACKE_H
+
+namespace Eigen {
+
+/** \internal Specialization for the data types supported by LAPACKe */
+
+#define EIGEN_LAPACKE_SCHUR_COMPLEX(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX, LAPACKE_PREFIX_U, EIGCOLROW, LAPACKE_COLROW) \
+template<> template<typename InputType> inline \
+ComplexSchur<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >& \
+ComplexSchur<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >::compute(const EigenBase<InputType>& matrix, bool computeU) \
+{ \
+ typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> MatrixType; \
+ typedef MatrixType::RealScalar RealScalar; \
+ typedef std::complex<RealScalar> ComplexScalar; \
+\
+ eigen_assert(matrix.cols() == matrix.rows()); \
+\
+ m_matUisUptodate = false; \
+ if(matrix.cols() == 1) \
+ { \
+ m_matT = matrix.derived().template cast<ComplexScalar>(); \
+ if(computeU) m_matU = ComplexMatrixType::Identity(1,1); \
+ m_info = Success; \
+ m_isInitialized = true; \
+ m_matUisUptodate = computeU; \
+ return *this; \
+ } \
+ lapack_int n = internal::convert_index<lapack_int>(matrix.cols()), sdim, info; \
+ lapack_int matrix_order = LAPACKE_COLROW; \
+ char jobvs, sort='N'; \
+ LAPACK_##LAPACKE_PREFIX_U##_SELECT1 select = 0; \
+ jobvs = (computeU) ? 'V' : 'N'; \
+ m_matU.resize(n, n); \
+ lapack_int ldvs = internal::convert_index<lapack_int>(m_matU.outerStride()); \
+ m_matT = matrix; \
+ lapack_int lda = internal::convert_index<lapack_int>(m_matT.outerStride()); \
+ Matrix<EIGTYPE, Dynamic, Dynamic> w; \
+ w.resize(n, 1);\
+ info = LAPACKE_##LAPACKE_PREFIX##gees( matrix_order, jobvs, sort, select, n, (LAPACKE_TYPE*)m_matT.data(), lda, &sdim, (LAPACKE_TYPE*)w.data(), (LAPACKE_TYPE*)m_matU.data(), ldvs ); \
+ if(info == 0) \
+ m_info = Success; \
+ else \
+ m_info = NoConvergence; \
+\
+ m_isInitialized = true; \
+ m_matUisUptodate = computeU; \
+ return *this; \
+\
+}
+
+EIGEN_LAPACKE_SCHUR_COMPLEX(dcomplex, lapack_complex_double, z, Z, ColMajor, LAPACK_COL_MAJOR)
+EIGEN_LAPACKE_SCHUR_COMPLEX(scomplex, lapack_complex_float, c, C, ColMajor, LAPACK_COL_MAJOR)
+EIGEN_LAPACKE_SCHUR_COMPLEX(dcomplex, lapack_complex_double, z, Z, RowMajor, LAPACK_ROW_MAJOR)
+EIGEN_LAPACKE_SCHUR_COMPLEX(scomplex, lapack_complex_float, c, C, RowMajor, LAPACK_ROW_MAJOR)
+
+} // end namespace Eigen
+
+#endif // EIGEN_COMPLEX_SCHUR_LAPACKE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/EigenSolver.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/EigenSolver.h
new file mode 100644
index 000000000..572b29e4e
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/EigenSolver.h
@@ -0,0 +1,622 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_EIGENSOLVER_H
+#define EIGEN_EIGENSOLVER_H
+
+#include "./RealSchur.h"
+
+namespace Eigen {
+
+/** \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ *
+ * \class EigenSolver
+ *
+ * \brief Computes eigenvalues and eigenvectors of general matrices
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the
+ * eigendecomposition; this is expected to be an instantiation of the Matrix
+ * class template. Currently, only real matrices are supported.
+ *
+ * The eigenvalues and eigenvectors of a matrix \f$ A \f$ are scalars
+ * \f$ \lambda \f$ and vectors \f$ v \f$ such that \f$ Av = \lambda v \f$. If
+ * \f$ D \f$ is a diagonal matrix with the eigenvalues on the diagonal, and
+ * \f$ V \f$ is a matrix with the eigenvectors as its columns, then \f$ A V =
+ * V D \f$. The matrix \f$ V \f$ is almost always invertible, in which case we
+ * have \f$ A = V D V^{-1} \f$. This is called the eigendecomposition.
+ *
+ * The eigenvalues and eigenvectors of a matrix may be complex, even when the
+ * matrix is real. However, we can choose real matrices \f$ V \f$ and \f$ D
+ * \f$ satisfying \f$ A V = V D \f$, just like the eigendecomposition, if the
+ * matrix \f$ D \f$ is not required to be diagonal, but if it is allowed to
+ * have blocks of the form
+ * \f[ \begin{bmatrix} u & v \\ -v & u \end{bmatrix} \f]
+ * (where \f$ u \f$ and \f$ v \f$ are real numbers) on the diagonal. These
+ * blocks correspond to complex eigenvalue pairs \f$ u \pm iv \f$. We call
+ * this variant of the eigendecomposition the pseudo-eigendecomposition.
+ *
+ * Call the function compute() to compute the eigenvalues and eigenvectors of
+ * a given matrix. Alternatively, you can use the
+ * EigenSolver(const MatrixType&, bool) constructor which computes the
+ * eigenvalues and eigenvectors at construction time. Once the eigenvalue and
+ * eigenvectors are computed, they can be retrieved with the eigenvalues() and
+ * eigenvectors() functions. The pseudoEigenvalueMatrix() and
+ * pseudoEigenvectors() methods allow the construction of the
+ * pseudo-eigendecomposition.
+ *
+ * The documentation for EigenSolver(const MatrixType&, bool) contains an
+ * example of the typical use of this class.
+ *
+ * \note The implementation is adapted from
+ * <a href="http://math.nist.gov/javanumerics/jama/">JAMA</a> (public domain).
+ * Their code is based on EISPACK.
+ *
+ * \sa MatrixBase::eigenvalues(), class ComplexEigenSolver, class SelfAdjointEigenSolver
+ */
+template<typename _MatrixType> class EigenSolver
+{
+ public:
+
+ /** \brief Synonym for the template parameter \p _MatrixType. */
+ typedef _MatrixType MatrixType;
+
+ enum {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ Options = MatrixType::Options,
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+
+ /** \brief Scalar type for matrices of type #MatrixType. */
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+
+ /** \brief Complex scalar type for #MatrixType.
+ *
+ * This is \c std::complex<Scalar> if #Scalar is real (e.g.,
+ * \c float or \c double) and just \c Scalar if #Scalar is
+ * complex.
+ */
+ typedef std::complex<RealScalar> ComplexScalar;
+
+ /** \brief Type for vector of eigenvalues as returned by eigenvalues().
+ *
+ * This is a column vector with entries of type #ComplexScalar.
+ * The length of the vector is the size of #MatrixType.
+ */
+ typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> EigenvalueType;
+
+ /** \brief Type for matrix of eigenvectors as returned by eigenvectors().
+ *
+ * This is a square matrix with entries of type #ComplexScalar.
+ * The size is the same as the size of #MatrixType.
+ */
+ typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> EigenvectorsType;
+
+ /** \brief Default constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via EigenSolver::compute(const MatrixType&, bool).
+ *
+ * \sa compute() for an example.
+ */
+ EigenSolver() : m_eivec(), m_eivalues(), m_isInitialized(false), m_eigenvectorsOk(false), m_realSchur(), m_matT(), m_tmp() {}
+
+ /** \brief Default constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem \a size.
+ * \sa EigenSolver()
+ */
+ explicit EigenSolver(Index size)
+ : m_eivec(size, size),
+ m_eivalues(size),
+ m_isInitialized(false),
+ m_eigenvectorsOk(false),
+ m_realSchur(size),
+ m_matT(size, size),
+ m_tmp(size)
+ {}
+
+ /** \brief Constructor; computes eigendecomposition of given matrix.
+ *
+ * \param[in] matrix Square matrix whose eigendecomposition is to be computed.
+ * \param[in] computeEigenvectors If true, both the eigenvectors and the
+ * eigenvalues are computed; if false, only the eigenvalues are
+ * computed.
+ *
+ * This constructor calls compute() to compute the eigenvalues
+ * and eigenvectors.
+ *
+ * Example: \include EigenSolver_EigenSolver_MatrixType.cpp
+ * Output: \verbinclude EigenSolver_EigenSolver_MatrixType.out
+ *
+ * \sa compute()
+ */
+ template<typename InputType>
+ explicit EigenSolver(const EigenBase<InputType>& matrix, bool computeEigenvectors = true)
+ : m_eivec(matrix.rows(), matrix.cols()),
+ m_eivalues(matrix.cols()),
+ m_isInitialized(false),
+ m_eigenvectorsOk(false),
+ m_realSchur(matrix.cols()),
+ m_matT(matrix.rows(), matrix.cols()),
+ m_tmp(matrix.cols())
+ {
+ compute(matrix.derived(), computeEigenvectors);
+ }
+
+ /** \brief Returns the eigenvectors of given matrix.
+ *
+ * \returns %Matrix whose columns are the (possibly complex) eigenvectors.
+ *
+ * \pre Either the constructor
+ * EigenSolver(const MatrixType&,bool) or the member function
+ * compute(const MatrixType&, bool) has been called before, and
+ * \p computeEigenvectors was set to true (the default).
+ *
+ * Column \f$ k \f$ of the returned matrix is an eigenvector corresponding
+ * to eigenvalue number \f$ k \f$ as returned by eigenvalues(). The
+ * eigenvectors are normalized to have (Euclidean) norm equal to one. The
+ * matrix returned by this function is the matrix \f$ V \f$ in the
+ * eigendecomposition \f$ A = V D V^{-1} \f$, if it exists.
+ *
+ * Example: \include EigenSolver_eigenvectors.cpp
+ * Output: \verbinclude EigenSolver_eigenvectors.out
+ *
+ * \sa eigenvalues(), pseudoEigenvectors()
+ */
+ EigenvectorsType eigenvectors() const;
+
+ /** \brief Returns the pseudo-eigenvectors of given matrix.
+ *
+ * \returns Const reference to matrix whose columns are the pseudo-eigenvectors.
+ *
+ * \pre Either the constructor
+ * EigenSolver(const MatrixType&,bool) or the member function
+ * compute(const MatrixType&, bool) has been called before, and
+ * \p computeEigenvectors was set to true (the default).
+ *
+ * The real matrix \f$ V \f$ returned by this function and the
+ * block-diagonal matrix \f$ D \f$ returned by pseudoEigenvalueMatrix()
+ * satisfy \f$ AV = VD \f$.
+ *
+ * Example: \include EigenSolver_pseudoEigenvectors.cpp
+ * Output: \verbinclude EigenSolver_pseudoEigenvectors.out
+ *
+ * \sa pseudoEigenvalueMatrix(), eigenvectors()
+ */
+ const MatrixType& pseudoEigenvectors() const
+ {
+ eigen_assert(m_isInitialized && "EigenSolver is not initialized.");
+ eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
+ return m_eivec;
+ }
+
+ /** \brief Returns the block-diagonal matrix in the pseudo-eigendecomposition.
+ *
+ * \returns A block-diagonal matrix.
+ *
+ * \pre Either the constructor
+ * EigenSolver(const MatrixType&,bool) or the member function
+ * compute(const MatrixType&, bool) has been called before.
+ *
+ * The matrix \f$ D \f$ returned by this function is real and
+ * block-diagonal. The blocks on the diagonal are either 1-by-1 or 2-by-2
+ * blocks of the form
+ * \f$ \begin{bmatrix} u & v \\ -v & u \end{bmatrix} \f$.
+ * These blocks are not sorted in any particular order.
+ * The matrix \f$ D \f$ and the matrix \f$ V \f$ returned by
+ * pseudoEigenvectors() satisfy \f$ AV = VD \f$.
+ *
+ * \sa pseudoEigenvectors() for an example, eigenvalues()
+ */
+ MatrixType pseudoEigenvalueMatrix() const;
+
+ /** \brief Returns the eigenvalues of given matrix.
+ *
+ * \returns A const reference to the column vector containing the eigenvalues.
+ *
+ * \pre Either the constructor
+ * EigenSolver(const MatrixType&,bool) or the member function
+ * compute(const MatrixType&, bool) has been called before.
+ *
+ * The eigenvalues are repeated according to their algebraic multiplicity,
+ * so there are as many eigenvalues as rows in the matrix. The eigenvalues
+ * are not sorted in any particular order.
+ *
+ * Example: \include EigenSolver_eigenvalues.cpp
+ * Output: \verbinclude EigenSolver_eigenvalues.out
+ *
+ * \sa eigenvectors(), pseudoEigenvalueMatrix(),
+ * MatrixBase::eigenvalues()
+ */
+ const EigenvalueType& eigenvalues() const
+ {
+ eigen_assert(m_isInitialized && "EigenSolver is not initialized.");
+ return m_eivalues;
+ }
+
+ /** \brief Computes eigendecomposition of given matrix.
+ *
+ * \param[in] matrix Square matrix whose eigendecomposition is to be computed.
+ * \param[in] computeEigenvectors If true, both the eigenvectors and the
+ * eigenvalues are computed; if false, only the eigenvalues are
+ * computed.
+ * \returns Reference to \c *this
+ *
+ * This function computes the eigenvalues of the real matrix \p matrix.
+ * The eigenvalues() function can be used to retrieve them. If
+ * \p computeEigenvectors is true, then the eigenvectors are also computed
+ * and can be retrieved by calling eigenvectors().
+ *
+ * The matrix is first reduced to real Schur form using the RealSchur
+ * class. The Schur decomposition is then used to compute the eigenvalues
+ * and eigenvectors.
+ *
+ * The cost of the computation is dominated by the cost of the
+ * Schur decomposition, which is very approximately \f$ 25n^3 \f$
+ * (where \f$ n \f$ is the size of the matrix) if \p computeEigenvectors
+ * is true, and \f$ 10n^3 \f$ if \p computeEigenvectors is false.
+ *
+ * This method reuses of the allocated data in the EigenSolver object.
+ *
+ * Example: \include EigenSolver_compute.cpp
+ * Output: \verbinclude EigenSolver_compute.out
+ */
+ template<typename InputType>
+ EigenSolver& compute(const EigenBase<InputType>& matrix, bool computeEigenvectors = true);
+
+ /** \returns NumericalIssue if the input contains INF or NaN values or overflow occurred. Returns Success otherwise. */
+ ComputationInfo info() const
+ {
+ eigen_assert(m_isInitialized && "EigenSolver is not initialized.");
+ return m_info;
+ }
+
+ /** \brief Sets the maximum number of iterations allowed. */
+ EigenSolver& setMaxIterations(Index maxIters)
+ {
+ m_realSchur.setMaxIterations(maxIters);
+ return *this;
+ }
+
+ /** \brief Returns the maximum number of iterations. */
+ Index getMaxIterations()
+ {
+ return m_realSchur.getMaxIterations();
+ }
+
+ private:
+ void doComputeEigenvectors();
+
+ protected:
+
+ static void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsComplex, NUMERIC_TYPE_MUST_BE_REAL);
+ }
+
+ MatrixType m_eivec;
+ EigenvalueType m_eivalues;
+ bool m_isInitialized;
+ bool m_eigenvectorsOk;
+ ComputationInfo m_info;
+ RealSchur<MatrixType> m_realSchur;
+ MatrixType m_matT;
+
+ typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> ColumnVectorType;
+ ColumnVectorType m_tmp;
+};
+
+template<typename MatrixType>
+MatrixType EigenSolver<MatrixType>::pseudoEigenvalueMatrix() const
+{
+ eigen_assert(m_isInitialized && "EigenSolver is not initialized.");
+ const RealScalar precision = RealScalar(2)*NumTraits<RealScalar>::epsilon();
+ Index n = m_eivalues.rows();
+ MatrixType matD = MatrixType::Zero(n,n);
+ for (Index i=0; i<n; ++i)
+ {
+ if (internal::isMuchSmallerThan(numext::imag(m_eivalues.coeff(i)), numext::real(m_eivalues.coeff(i)), precision))
+ matD.coeffRef(i,i) = numext::real(m_eivalues.coeff(i));
+ else
+ {
+ matD.template block<2,2>(i,i) << numext::real(m_eivalues.coeff(i)), numext::imag(m_eivalues.coeff(i)),
+ -numext::imag(m_eivalues.coeff(i)), numext::real(m_eivalues.coeff(i));
+ ++i;
+ }
+ }
+ return matD;
+}
+
+template<typename MatrixType>
+typename EigenSolver<MatrixType>::EigenvectorsType EigenSolver<MatrixType>::eigenvectors() const
+{
+ eigen_assert(m_isInitialized && "EigenSolver is not initialized.");
+ eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
+ const RealScalar precision = RealScalar(2)*NumTraits<RealScalar>::epsilon();
+ Index n = m_eivec.cols();
+ EigenvectorsType matV(n,n);
+ for (Index j=0; j<n; ++j)
+ {
+ if (internal::isMuchSmallerThan(numext::imag(m_eivalues.coeff(j)), numext::real(m_eivalues.coeff(j)), precision) || j+1==n)
+ {
+ // we have a real eigen value
+ matV.col(j) = m_eivec.col(j).template cast<ComplexScalar>();
+ matV.col(j).normalize();
+ }
+ else
+ {
+ // we have a pair of complex eigen values
+ for (Index i=0; i<n; ++i)
+ {
+ matV.coeffRef(i,j) = ComplexScalar(m_eivec.coeff(i,j), m_eivec.coeff(i,j+1));
+ matV.coeffRef(i,j+1) = ComplexScalar(m_eivec.coeff(i,j), -m_eivec.coeff(i,j+1));
+ }
+ matV.col(j).normalize();
+ matV.col(j+1).normalize();
+ ++j;
+ }
+ }
+ return matV;
+}
+
+template<typename MatrixType>
+template<typename InputType>
+EigenSolver<MatrixType>&
+EigenSolver<MatrixType>::compute(const EigenBase<InputType>& matrix, bool computeEigenvectors)
+{
+ check_template_parameters();
+
+ using std::sqrt;
+ using std::abs;
+ using numext::isfinite;
+ eigen_assert(matrix.cols() == matrix.rows());
+
+ // Reduce to real Schur form.
+ m_realSchur.compute(matrix.derived(), computeEigenvectors);
+
+ m_info = m_realSchur.info();
+
+ if (m_info == Success)
+ {
+ m_matT = m_realSchur.matrixT();
+ if (computeEigenvectors)
+ m_eivec = m_realSchur.matrixU();
+
+ // Compute eigenvalues from matT
+ m_eivalues.resize(matrix.cols());
+ Index i = 0;
+ while (i < matrix.cols())
+ {
+ if (i == matrix.cols() - 1 || m_matT.coeff(i+1, i) == Scalar(0))
+ {
+ m_eivalues.coeffRef(i) = m_matT.coeff(i, i);
+ if(!(isfinite)(m_eivalues.coeffRef(i)))
+ {
+ m_isInitialized = true;
+ m_eigenvectorsOk = false;
+ m_info = NumericalIssue;
+ return *this;
+ }
+ ++i;
+ }
+ else
+ {
+ Scalar p = Scalar(0.5) * (m_matT.coeff(i, i) - m_matT.coeff(i+1, i+1));
+ Scalar z;
+ // Compute z = sqrt(abs(p * p + m_matT.coeff(i+1, i) * m_matT.coeff(i, i+1)));
+ // without overflow
+ {
+ Scalar t0 = m_matT.coeff(i+1, i);
+ Scalar t1 = m_matT.coeff(i, i+1);
+ Scalar maxval = numext::maxi<Scalar>(abs(p),numext::maxi<Scalar>(abs(t0),abs(t1)));
+ t0 /= maxval;
+ t1 /= maxval;
+ Scalar p0 = p/maxval;
+ z = maxval * sqrt(abs(p0 * p0 + t0 * t1));
+ }
+
+ m_eivalues.coeffRef(i) = ComplexScalar(m_matT.coeff(i+1, i+1) + p, z);
+ m_eivalues.coeffRef(i+1) = ComplexScalar(m_matT.coeff(i+1, i+1) + p, -z);
+ if(!((isfinite)(m_eivalues.coeffRef(i)) && (isfinite)(m_eivalues.coeffRef(i+1))))
+ {
+ m_isInitialized = true;
+ m_eigenvectorsOk = false;
+ m_info = NumericalIssue;
+ return *this;
+ }
+ i += 2;
+ }
+ }
+
+ // Compute eigenvectors.
+ if (computeEigenvectors)
+ doComputeEigenvectors();
+ }
+
+ m_isInitialized = true;
+ m_eigenvectorsOk = computeEigenvectors;
+
+ return *this;
+}
+
+
+template<typename MatrixType>
+void EigenSolver<MatrixType>::doComputeEigenvectors()
+{
+ using std::abs;
+ const Index size = m_eivec.cols();
+ const Scalar eps = NumTraits<Scalar>::epsilon();
+
+ // inefficient! this is already computed in RealSchur
+ Scalar norm(0);
+ for (Index j = 0; j < size; ++j)
+ {
+ norm += m_matT.row(j).segment((std::max)(j-1,Index(0)), size-(std::max)(j-1,Index(0))).cwiseAbs().sum();
+ }
+
+ // Backsubstitute to find vectors of upper triangular form
+ if (norm == Scalar(0))
+ {
+ return;
+ }
+
+ for (Index n = size-1; n >= 0; n--)
+ {
+ Scalar p = m_eivalues.coeff(n).real();
+ Scalar q = m_eivalues.coeff(n).imag();
+
+ // Scalar vector
+ if (q == Scalar(0))
+ {
+ Scalar lastr(0), lastw(0);
+ Index l = n;
+
+ m_matT.coeffRef(n,n) = Scalar(1);
+ for (Index i = n-1; i >= 0; i--)
+ {
+ Scalar w = m_matT.coeff(i,i) - p;
+ Scalar r = m_matT.row(i).segment(l,n-l+1).dot(m_matT.col(n).segment(l, n-l+1));
+
+ if (m_eivalues.coeff(i).imag() < Scalar(0))
+ {
+ lastw = w;
+ lastr = r;
+ }
+ else
+ {
+ l = i;
+ if (m_eivalues.coeff(i).imag() == Scalar(0))
+ {
+ if (w != Scalar(0))
+ m_matT.coeffRef(i,n) = -r / w;
+ else
+ m_matT.coeffRef(i,n) = -r / (eps * norm);
+ }
+ else // Solve real equations
+ {
+ Scalar x = m_matT.coeff(i,i+1);
+ Scalar y = m_matT.coeff(i+1,i);
+ Scalar denom = (m_eivalues.coeff(i).real() - p) * (m_eivalues.coeff(i).real() - p) + m_eivalues.coeff(i).imag() * m_eivalues.coeff(i).imag();
+ Scalar t = (x * lastr - lastw * r) / denom;
+ m_matT.coeffRef(i,n) = t;
+ if (abs(x) > abs(lastw))
+ m_matT.coeffRef(i+1,n) = (-r - w * t) / x;
+ else
+ m_matT.coeffRef(i+1,n) = (-lastr - y * t) / lastw;
+ }
+
+ // Overflow control
+ Scalar t = abs(m_matT.coeff(i,n));
+ if ((eps * t) * t > Scalar(1))
+ m_matT.col(n).tail(size-i) /= t;
+ }
+ }
+ }
+ else if (q < Scalar(0) && n > 0) // Complex vector
+ {
+ Scalar lastra(0), lastsa(0), lastw(0);
+ Index l = n-1;
+
+ // Last vector component imaginary so matrix is triangular
+ if (abs(m_matT.coeff(n,n-1)) > abs(m_matT.coeff(n-1,n)))
+ {
+ m_matT.coeffRef(n-1,n-1) = q / m_matT.coeff(n,n-1);
+ m_matT.coeffRef(n-1,n) = -(m_matT.coeff(n,n) - p) / m_matT.coeff(n,n-1);
+ }
+ else
+ {
+ ComplexScalar cc = ComplexScalar(Scalar(0),-m_matT.coeff(n-1,n)) / ComplexScalar(m_matT.coeff(n-1,n-1)-p,q);
+ m_matT.coeffRef(n-1,n-1) = numext::real(cc);
+ m_matT.coeffRef(n-1,n) = numext::imag(cc);
+ }
+ m_matT.coeffRef(n,n-1) = Scalar(0);
+ m_matT.coeffRef(n,n) = Scalar(1);
+ for (Index i = n-2; i >= 0; i--)
+ {
+ Scalar ra = m_matT.row(i).segment(l, n-l+1).dot(m_matT.col(n-1).segment(l, n-l+1));
+ Scalar sa = m_matT.row(i).segment(l, n-l+1).dot(m_matT.col(n).segment(l, n-l+1));
+ Scalar w = m_matT.coeff(i,i) - p;
+
+ if (m_eivalues.coeff(i).imag() < Scalar(0))
+ {
+ lastw = w;
+ lastra = ra;
+ lastsa = sa;
+ }
+ else
+ {
+ l = i;
+ if (m_eivalues.coeff(i).imag() == RealScalar(0))
+ {
+ ComplexScalar cc = ComplexScalar(-ra,-sa) / ComplexScalar(w,q);
+ m_matT.coeffRef(i,n-1) = numext::real(cc);
+ m_matT.coeffRef(i,n) = numext::imag(cc);
+ }
+ else
+ {
+ // Solve complex equations
+ Scalar x = m_matT.coeff(i,i+1);
+ Scalar y = m_matT.coeff(i+1,i);
+ Scalar vr = (m_eivalues.coeff(i).real() - p) * (m_eivalues.coeff(i).real() - p) + m_eivalues.coeff(i).imag() * m_eivalues.coeff(i).imag() - q * q;
+ Scalar vi = (m_eivalues.coeff(i).real() - p) * Scalar(2) * q;
+ if ((vr == Scalar(0)) && (vi == Scalar(0)))
+ vr = eps * norm * (abs(w) + abs(q) + abs(x) + abs(y) + abs(lastw));
+
+ ComplexScalar cc = ComplexScalar(x*lastra-lastw*ra+q*sa,x*lastsa-lastw*sa-q*ra) / ComplexScalar(vr,vi);
+ m_matT.coeffRef(i,n-1) = numext::real(cc);
+ m_matT.coeffRef(i,n) = numext::imag(cc);
+ if (abs(x) > (abs(lastw) + abs(q)))
+ {
+ m_matT.coeffRef(i+1,n-1) = (-ra - w * m_matT.coeff(i,n-1) + q * m_matT.coeff(i,n)) / x;
+ m_matT.coeffRef(i+1,n) = (-sa - w * m_matT.coeff(i,n) - q * m_matT.coeff(i,n-1)) / x;
+ }
+ else
+ {
+ cc = ComplexScalar(-lastra-y*m_matT.coeff(i,n-1),-lastsa-y*m_matT.coeff(i,n)) / ComplexScalar(lastw,q);
+ m_matT.coeffRef(i+1,n-1) = numext::real(cc);
+ m_matT.coeffRef(i+1,n) = numext::imag(cc);
+ }
+ }
+
+ // Overflow control
+ Scalar t = numext::maxi<Scalar>(abs(m_matT.coeff(i,n-1)),abs(m_matT.coeff(i,n)));
+ if ((eps * t) * t > Scalar(1))
+ m_matT.block(i, n-1, size-i, 2) /= t;
+
+ }
+ }
+
+ // We handled a pair of complex conjugate eigenvalues, so need to skip them both
+ n--;
+ }
+ else
+ {
+ eigen_assert(0 && "Internal bug in EigenSolver (INF or NaN has not been detected)"); // this should not happen
+ }
+ }
+
+ // Back transformation to get eigenvectors of original matrix
+ for (Index j = size-1; j >= 0; j--)
+ {
+ m_tmp.noalias() = m_eivec.leftCols(j+1) * m_matT.col(j).segment(0, j+1);
+ m_eivec.col(j) = m_tmp;
+ }
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_EIGENSOLVER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h
new file mode 100644
index 000000000..87d789b3f
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h
@@ -0,0 +1,418 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2012-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
+// Copyright (C) 2016 Tobias Wood <tobias@spinicist.org.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GENERALIZEDEIGENSOLVER_H
+#define EIGEN_GENERALIZEDEIGENSOLVER_H
+
+#include "./RealQZ.h"
+
+namespace Eigen {
+
+/** \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ *
+ * \class GeneralizedEigenSolver
+ *
+ * \brief Computes the generalized eigenvalues and eigenvectors of a pair of general matrices
+ *
+ * \tparam _MatrixType the type of the matrices of which we are computing the
+ * eigen-decomposition; this is expected to be an instantiation of the Matrix
+ * class template. Currently, only real matrices are supported.
+ *
+ * The generalized eigenvalues and eigenvectors of a matrix pair \f$ A \f$ and \f$ B \f$ are scalars
+ * \f$ \lambda \f$ and vectors \f$ v \f$ such that \f$ Av = \lambda Bv \f$. If
+ * \f$ D \f$ is a diagonal matrix with the eigenvalues on the diagonal, and
+ * \f$ V \f$ is a matrix with the eigenvectors as its columns, then \f$ A V =
+ * B V D \f$. The matrix \f$ V \f$ is almost always invertible, in which case we
+ * have \f$ A = B V D V^{-1} \f$. This is called the generalized eigen-decomposition.
+ *
+ * The generalized eigenvalues and eigenvectors of a matrix pair may be complex, even when the
+ * matrices are real. Moreover, the generalized eigenvalue might be infinite if the matrix B is
+ * singular. To workaround this difficulty, the eigenvalues are provided as a pair of complex \f$ \alpha \f$
+ * and real \f$ \beta \f$ such that: \f$ \lambda_i = \alpha_i / \beta_i \f$. If \f$ \beta_i \f$ is (nearly) zero,
+ * then one can consider the well defined left eigenvalue \f$ \mu = \beta_i / \alpha_i\f$ such that:
+ * \f$ \mu_i A v_i = B v_i \f$, or even \f$ \mu_i u_i^T A = u_i^T B \f$ where \f$ u_i \f$ is
+ * called the left eigenvector.
+ *
+ * Call the function compute() to compute the generalized eigenvalues and eigenvectors of
+ * a given matrix pair. Alternatively, you can use the
+ * GeneralizedEigenSolver(const MatrixType&, const MatrixType&, bool) constructor which computes the
+ * eigenvalues and eigenvectors at construction time. Once the eigenvalue and
+ * eigenvectors are computed, they can be retrieved with the eigenvalues() and
+ * eigenvectors() functions.
+ *
+ * Here is an usage example of this class:
+ * Example: \include GeneralizedEigenSolver.cpp
+ * Output: \verbinclude GeneralizedEigenSolver.out
+ *
+ * \sa MatrixBase::eigenvalues(), class ComplexEigenSolver, class SelfAdjointEigenSolver
+ */
+template<typename _MatrixType> class GeneralizedEigenSolver
+{
+ public:
+
+ /** \brief Synonym for the template parameter \p _MatrixType. */
+ typedef _MatrixType MatrixType;
+
+ enum {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ Options = MatrixType::Options,
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+
+ /** \brief Scalar type for matrices of type #MatrixType. */
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+
+ /** \brief Complex scalar type for #MatrixType.
+ *
+ * This is \c std::complex<Scalar> if #Scalar is real (e.g.,
+ * \c float or \c double) and just \c Scalar if #Scalar is
+ * complex.
+ */
+ typedef std::complex<RealScalar> ComplexScalar;
+
+ /** \brief Type for vector of real scalar values eigenvalues as returned by betas().
+ *
+ * This is a column vector with entries of type #Scalar.
+ * The length of the vector is the size of #MatrixType.
+ */
+ typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> VectorType;
+
+ /** \brief Type for vector of complex scalar values eigenvalues as returned by alphas().
+ *
+ * This is a column vector with entries of type #ComplexScalar.
+ * The length of the vector is the size of #MatrixType.
+ */
+ typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> ComplexVectorType;
+
+ /** \brief Expression type for the eigenvalues as returned by eigenvalues().
+ */
+ typedef CwiseBinaryOp<internal::scalar_quotient_op<ComplexScalar,Scalar>,ComplexVectorType,VectorType> EigenvalueType;
+
+ /** \brief Type for matrix of eigenvectors as returned by eigenvectors().
+ *
+ * This is a square matrix with entries of type #ComplexScalar.
+ * The size is the same as the size of #MatrixType.
+ */
+ typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> EigenvectorsType;
+
+ /** \brief Default constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via EigenSolver::compute(const MatrixType&, bool).
+ *
+ * \sa compute() for an example.
+ */
+ GeneralizedEigenSolver()
+ : m_eivec(),
+ m_alphas(),
+ m_betas(),
+ m_valuesOkay(false),
+ m_vectorsOkay(false),
+ m_realQZ()
+ {}
+
+ /** \brief Default constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem \a size.
+ * \sa GeneralizedEigenSolver()
+ */
+ explicit GeneralizedEigenSolver(Index size)
+ : m_eivec(size, size),
+ m_alphas(size),
+ m_betas(size),
+ m_valuesOkay(false),
+ m_vectorsOkay(false),
+ m_realQZ(size),
+ m_tmp(size)
+ {}
+
+ /** \brief Constructor; computes the generalized eigendecomposition of given matrix pair.
+ *
+ * \param[in] A Square matrix whose eigendecomposition is to be computed.
+ * \param[in] B Square matrix whose eigendecomposition is to be computed.
+ * \param[in] computeEigenvectors If true, both the eigenvectors and the
+ * eigenvalues are computed; if false, only the eigenvalues are computed.
+ *
+ * This constructor calls compute() to compute the generalized eigenvalues
+ * and eigenvectors.
+ *
+ * \sa compute()
+ */
+ GeneralizedEigenSolver(const MatrixType& A, const MatrixType& B, bool computeEigenvectors = true)
+ : m_eivec(A.rows(), A.cols()),
+ m_alphas(A.cols()),
+ m_betas(A.cols()),
+ m_valuesOkay(false),
+ m_vectorsOkay(false),
+ m_realQZ(A.cols()),
+ m_tmp(A.cols())
+ {
+ compute(A, B, computeEigenvectors);
+ }
+
+ /* \brief Returns the computed generalized eigenvectors.
+ *
+ * \returns %Matrix whose columns are the (possibly complex) right eigenvectors.
+ * i.e. the eigenvectors that solve (A - l*B)x = 0. The ordering matches the eigenvalues.
+ *
+ * \pre Either the constructor
+ * GeneralizedEigenSolver(const MatrixType&,const MatrixType&, bool) or the member function
+ * compute(const MatrixType&, const MatrixType& bool) has been called before, and
+ * \p computeEigenvectors was set to true (the default).
+ *
+ * \sa eigenvalues()
+ */
+ EigenvectorsType eigenvectors() const {
+ eigen_assert(m_vectorsOkay && "Eigenvectors for GeneralizedEigenSolver were not calculated.");
+ return m_eivec;
+ }
+
+ /** \brief Returns an expression of the computed generalized eigenvalues.
+ *
+ * \returns An expression of the column vector containing the eigenvalues.
+ *
+ * It is a shortcut for \code this->alphas().cwiseQuotient(this->betas()); \endcode
+ * Not that betas might contain zeros. It is therefore not recommended to use this function,
+ * but rather directly deal with the alphas and betas vectors.
+ *
+ * \pre Either the constructor
+ * GeneralizedEigenSolver(const MatrixType&,const MatrixType&,bool) or the member function
+ * compute(const MatrixType&,const MatrixType&,bool) has been called before.
+ *
+ * The eigenvalues are repeated according to their algebraic multiplicity,
+ * so there are as many eigenvalues as rows in the matrix. The eigenvalues
+ * are not sorted in any particular order.
+ *
+ * \sa alphas(), betas(), eigenvectors()
+ */
+ EigenvalueType eigenvalues() const
+ {
+ eigen_assert(m_valuesOkay && "GeneralizedEigenSolver is not initialized.");
+ return EigenvalueType(m_alphas,m_betas);
+ }
+
+ /** \returns A const reference to the vectors containing the alpha values
+ *
+ * This vector permits to reconstruct the j-th eigenvalues as alphas(i)/betas(j).
+ *
+ * \sa betas(), eigenvalues() */
+ ComplexVectorType alphas() const
+ {
+ eigen_assert(m_valuesOkay && "GeneralizedEigenSolver is not initialized.");
+ return m_alphas;
+ }
+
+ /** \returns A const reference to the vectors containing the beta values
+ *
+ * This vector permits to reconstruct the j-th eigenvalues as alphas(i)/betas(j).
+ *
+ * \sa alphas(), eigenvalues() */
+ VectorType betas() const
+ {
+ eigen_assert(m_valuesOkay && "GeneralizedEigenSolver is not initialized.");
+ return m_betas;
+ }
+
+ /** \brief Computes generalized eigendecomposition of given matrix.
+ *
+ * \param[in] A Square matrix whose eigendecomposition is to be computed.
+ * \param[in] B Square matrix whose eigendecomposition is to be computed.
+ * \param[in] computeEigenvectors If true, both the eigenvectors and the
+ * eigenvalues are computed; if false, only the eigenvalues are
+ * computed.
+ * \returns Reference to \c *this
+ *
+ * This function computes the eigenvalues of the real matrix \p matrix.
+ * The eigenvalues() function can be used to retrieve them. If
+ * \p computeEigenvectors is true, then the eigenvectors are also computed
+ * and can be retrieved by calling eigenvectors().
+ *
+ * The matrix is first reduced to real generalized Schur form using the RealQZ
+ * class. The generalized Schur decomposition is then used to compute the eigenvalues
+ * and eigenvectors.
+ *
+ * The cost of the computation is dominated by the cost of the
+ * generalized Schur decomposition.
+ *
+ * This method reuses of the allocated data in the GeneralizedEigenSolver object.
+ */
+ GeneralizedEigenSolver& compute(const MatrixType& A, const MatrixType& B, bool computeEigenvectors = true);
+
+ ComputationInfo info() const
+ {
+ eigen_assert(m_valuesOkay && "EigenSolver is not initialized.");
+ return m_realQZ.info();
+ }
+
+ /** Sets the maximal number of iterations allowed.
+ */
+ GeneralizedEigenSolver& setMaxIterations(Index maxIters)
+ {
+ m_realQZ.setMaxIterations(maxIters);
+ return *this;
+ }
+
+ protected:
+
+ static void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsComplex, NUMERIC_TYPE_MUST_BE_REAL);
+ }
+
+ EigenvectorsType m_eivec;
+ ComplexVectorType m_alphas;
+ VectorType m_betas;
+ bool m_valuesOkay, m_vectorsOkay;
+ RealQZ<MatrixType> m_realQZ;
+ ComplexVectorType m_tmp;
+};
+
+template<typename MatrixType>
+GeneralizedEigenSolver<MatrixType>&
+GeneralizedEigenSolver<MatrixType>::compute(const MatrixType& A, const MatrixType& B, bool computeEigenvectors)
+{
+ check_template_parameters();
+
+ using std::sqrt;
+ using std::abs;
+ eigen_assert(A.cols() == A.rows() && B.cols() == A.rows() && B.cols() == B.rows());
+ Index size = A.cols();
+ m_valuesOkay = false;
+ m_vectorsOkay = false;
+ // Reduce to generalized real Schur form:
+ // A = Q S Z and B = Q T Z
+ m_realQZ.compute(A, B, computeEigenvectors);
+ if (m_realQZ.info() == Success)
+ {
+ // Resize storage
+ m_alphas.resize(size);
+ m_betas.resize(size);
+ if (computeEigenvectors)
+ {
+ m_eivec.resize(size,size);
+ m_tmp.resize(size);
+ }
+
+ // Aliases:
+ Map<VectorType> v(reinterpret_cast<Scalar*>(m_tmp.data()), size);
+ ComplexVectorType &cv = m_tmp;
+ const MatrixType &mS = m_realQZ.matrixS();
+ const MatrixType &mT = m_realQZ.matrixT();
+
+ Index i = 0;
+ while (i < size)
+ {
+ if (i == size - 1 || mS.coeff(i+1, i) == Scalar(0))
+ {
+ // Real eigenvalue
+ m_alphas.coeffRef(i) = mS.diagonal().coeff(i);
+ m_betas.coeffRef(i) = mT.diagonal().coeff(i);
+ if (computeEigenvectors)
+ {
+ v.setConstant(Scalar(0.0));
+ v.coeffRef(i) = Scalar(1.0);
+ // For singular eigenvalues do nothing more
+ if(abs(m_betas.coeffRef(i)) >= (std::numeric_limits<RealScalar>::min)())
+ {
+ // Non-singular eigenvalue
+ const Scalar alpha = real(m_alphas.coeffRef(i));
+ const Scalar beta = m_betas.coeffRef(i);
+ for (Index j = i-1; j >= 0; j--)
+ {
+ const Index st = j+1;
+ const Index sz = i-j;
+ if (j > 0 && mS.coeff(j, j-1) != Scalar(0))
+ {
+ // 2x2 block
+ Matrix<Scalar, 2, 1> rhs = (alpha*mT.template block<2,Dynamic>(j-1,st,2,sz) - beta*mS.template block<2,Dynamic>(j-1,st,2,sz)) .lazyProduct( v.segment(st,sz) );
+ Matrix<Scalar, 2, 2> lhs = beta * mS.template block<2,2>(j-1,j-1) - alpha * mT.template block<2,2>(j-1,j-1);
+ v.template segment<2>(j-1) = lhs.partialPivLu().solve(rhs);
+ j--;
+ }
+ else
+ {
+ v.coeffRef(j) = -v.segment(st,sz).transpose().cwiseProduct(beta*mS.block(j,st,1,sz) - alpha*mT.block(j,st,1,sz)).sum() / (beta*mS.coeffRef(j,j) - alpha*mT.coeffRef(j,j));
+ }
+ }
+ }
+ m_eivec.col(i).real().noalias() = m_realQZ.matrixZ().transpose() * v;
+ m_eivec.col(i).real().normalize();
+ m_eivec.col(i).imag().setConstant(0);
+ }
+ ++i;
+ }
+ else
+ {
+ // We need to extract the generalized eigenvalues of the pair of a general 2x2 block S and a positive diagonal 2x2 block T
+ // Then taking beta=T_00*T_11, we can avoid any division, and alpha is the eigenvalues of A = (U^-1 * S * U) * diag(T_11,T_00):
+
+ // T = [a 0]
+ // [0 b]
+ RealScalar a = mT.diagonal().coeff(i),
+ b = mT.diagonal().coeff(i+1);
+ const RealScalar beta = m_betas.coeffRef(i) = m_betas.coeffRef(i+1) = a*b;
+
+ // ^^ NOTE: using diagonal()(i) instead of coeff(i,i) workarounds a MSVC bug.
+ Matrix<RealScalar,2,2> S2 = mS.template block<2,2>(i,i) * Matrix<Scalar,2,1>(b,a).asDiagonal();
+
+ Scalar p = Scalar(0.5) * (S2.coeff(0,0) - S2.coeff(1,1));
+ Scalar z = sqrt(abs(p * p + S2.coeff(1,0) * S2.coeff(0,1)));
+ const ComplexScalar alpha = ComplexScalar(S2.coeff(1,1) + p, (beta > 0) ? z : -z);
+ m_alphas.coeffRef(i) = conj(alpha);
+ m_alphas.coeffRef(i+1) = alpha;
+
+ if (computeEigenvectors) {
+ // Compute eigenvector in position (i+1) and then position (i) is just the conjugate
+ cv.setZero();
+ cv.coeffRef(i+1) = Scalar(1.0);
+ // here, the "static_cast" workaound expression template issues.
+ cv.coeffRef(i) = -(static_cast<Scalar>(beta*mS.coeffRef(i,i+1)) - alpha*mT.coeffRef(i,i+1))
+ / (static_cast<Scalar>(beta*mS.coeffRef(i,i)) - alpha*mT.coeffRef(i,i));
+ for (Index j = i-1; j >= 0; j--)
+ {
+ const Index st = j+1;
+ const Index sz = i+1-j;
+ if (j > 0 && mS.coeff(j, j-1) != Scalar(0))
+ {
+ // 2x2 block
+ Matrix<ComplexScalar, 2, 1> rhs = (alpha*mT.template block<2,Dynamic>(j-1,st,2,sz) - beta*mS.template block<2,Dynamic>(j-1,st,2,sz)) .lazyProduct( cv.segment(st,sz) );
+ Matrix<ComplexScalar, 2, 2> lhs = beta * mS.template block<2,2>(j-1,j-1) - alpha * mT.template block<2,2>(j-1,j-1);
+ cv.template segment<2>(j-1) = lhs.partialPivLu().solve(rhs);
+ j--;
+ } else {
+ cv.coeffRef(j) = cv.segment(st,sz).transpose().cwiseProduct(beta*mS.block(j,st,1,sz) - alpha*mT.block(j,st,1,sz)).sum()
+ / (alpha*mT.coeffRef(j,j) - static_cast<Scalar>(beta*mS.coeffRef(j,j)));
+ }
+ }
+ m_eivec.col(i+1).noalias() = (m_realQZ.matrixZ().transpose() * cv);
+ m_eivec.col(i+1).normalize();
+ m_eivec.col(i) = m_eivec.col(i+1).conjugate();
+ }
+ i += 2;
+ }
+ }
+
+ m_valuesOkay = true;
+ m_vectorsOkay = computeEigenvectors;
+ }
+ return *this;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_GENERALIZEDEIGENSOLVER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h
new file mode 100644
index 000000000..d0f9091be
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h
@@ -0,0 +1,226 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GENERALIZEDSELFADJOINTEIGENSOLVER_H
+#define EIGEN_GENERALIZEDSELFADJOINTEIGENSOLVER_H
+
+#include "./Tridiagonalization.h"
+
+namespace Eigen {
+
+/** \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ *
+ * \class GeneralizedSelfAdjointEigenSolver
+ *
+ * \brief Computes eigenvalues and eigenvectors of the generalized selfadjoint eigen problem
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the
+ * eigendecomposition; this is expected to be an instantiation of the Matrix
+ * class template.
+ *
+ * This class solves the generalized eigenvalue problem
+ * \f$ Av = \lambda Bv \f$. In this case, the matrix \f$ A \f$ should be
+ * selfadjoint and the matrix \f$ B \f$ should be positive definite.
+ *
+ * Only the \b lower \b triangular \b part of the input matrix is referenced.
+ *
+ * Call the function compute() to compute the eigenvalues and eigenvectors of
+ * a given matrix. Alternatively, you can use the
+ * GeneralizedSelfAdjointEigenSolver(const MatrixType&, const MatrixType&, int)
+ * constructor which computes the eigenvalues and eigenvectors at construction time.
+ * Once the eigenvalue and eigenvectors are computed, they can be retrieved with the eigenvalues()
+ * and eigenvectors() functions.
+ *
+ * The documentation for GeneralizedSelfAdjointEigenSolver(const MatrixType&, const MatrixType&, int)
+ * contains an example of the typical use of this class.
+ *
+ * \sa class SelfAdjointEigenSolver, class EigenSolver, class ComplexEigenSolver
+ */
+template<typename _MatrixType>
+class GeneralizedSelfAdjointEigenSolver : public SelfAdjointEigenSolver<_MatrixType>
+{
+ typedef SelfAdjointEigenSolver<_MatrixType> Base;
+ public:
+
+ typedef _MatrixType MatrixType;
+
+ /** \brief Default constructor for fixed-size matrices.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via compute(). This constructor
+ * can only be used if \p _MatrixType is a fixed-size matrix; use
+ * GeneralizedSelfAdjointEigenSolver(Index) for dynamic-size matrices.
+ */
+ GeneralizedSelfAdjointEigenSolver() : Base() {}
+
+ /** \brief Constructor, pre-allocates memory for dynamic-size matrices.
+ *
+ * \param [in] size Positive integer, size of the matrix whose
+ * eigenvalues and eigenvectors will be computed.
+ *
+ * This constructor is useful for dynamic-size matrices, when the user
+ * intends to perform decompositions via compute(). The \p size
+ * parameter is only used as a hint. It is not an error to give a wrong
+ * \p size, but it may impair performance.
+ *
+ * \sa compute() for an example
+ */
+ explicit GeneralizedSelfAdjointEigenSolver(Index size)
+ : Base(size)
+ {}
+
+ /** \brief Constructor; computes generalized eigendecomposition of given matrix pencil.
+ *
+ * \param[in] matA Selfadjoint matrix in matrix pencil.
+ * Only the lower triangular part of the matrix is referenced.
+ * \param[in] matB Positive-definite matrix in matrix pencil.
+ * Only the lower triangular part of the matrix is referenced.
+ * \param[in] options A or-ed set of flags {#ComputeEigenvectors,#EigenvaluesOnly} | {#Ax_lBx,#ABx_lx,#BAx_lx}.
+ * Default is #ComputeEigenvectors|#Ax_lBx.
+ *
+ * This constructor calls compute(const MatrixType&, const MatrixType&, int)
+ * to compute the eigenvalues and (if requested) the eigenvectors of the
+ * generalized eigenproblem \f$ Ax = \lambda B x \f$ with \a matA the
+ * selfadjoint matrix \f$ A \f$ and \a matB the positive definite matrix
+ * \f$ B \f$. Each eigenvector \f$ x \f$ satisfies the property
+ * \f$ x^* B x = 1 \f$. The eigenvectors are computed if
+ * \a options contains ComputeEigenvectors.
+ *
+ * In addition, the two following variants can be solved via \p options:
+ * - \c ABx_lx: \f$ ABx = \lambda x \f$
+ * - \c BAx_lx: \f$ BAx = \lambda x \f$
+ *
+ * Example: \include SelfAdjointEigenSolver_SelfAdjointEigenSolver_MatrixType2.cpp
+ * Output: \verbinclude SelfAdjointEigenSolver_SelfAdjointEigenSolver_MatrixType2.out
+ *
+ * \sa compute(const MatrixType&, const MatrixType&, int)
+ */
+ GeneralizedSelfAdjointEigenSolver(const MatrixType& matA, const MatrixType& matB,
+ int options = ComputeEigenvectors|Ax_lBx)
+ : Base(matA.cols())
+ {
+ compute(matA, matB, options);
+ }
+
+ /** \brief Computes generalized eigendecomposition of given matrix pencil.
+ *
+ * \param[in] matA Selfadjoint matrix in matrix pencil.
+ * Only the lower triangular part of the matrix is referenced.
+ * \param[in] matB Positive-definite matrix in matrix pencil.
+ * Only the lower triangular part of the matrix is referenced.
+ * \param[in] options A or-ed set of flags {#ComputeEigenvectors,#EigenvaluesOnly} | {#Ax_lBx,#ABx_lx,#BAx_lx}.
+ * Default is #ComputeEigenvectors|#Ax_lBx.
+ *
+ * \returns Reference to \c *this
+ *
+ * According to \p options, this function computes eigenvalues and (if requested)
+ * the eigenvectors of one of the following three generalized eigenproblems:
+ * - \c Ax_lBx: \f$ Ax = \lambda B x \f$
+ * - \c ABx_lx: \f$ ABx = \lambda x \f$
+ * - \c BAx_lx: \f$ BAx = \lambda x \f$
+ * with \a matA the selfadjoint matrix \f$ A \f$ and \a matB the positive definite
+ * matrix \f$ B \f$.
+ * In addition, each eigenvector \f$ x \f$ satisfies the property \f$ x^* B x = 1 \f$.
+ *
+ * The eigenvalues() function can be used to retrieve
+ * the eigenvalues. If \p options contains ComputeEigenvectors, then the
+ * eigenvectors are also computed and can be retrieved by calling
+ * eigenvectors().
+ *
+ * The implementation uses LLT to compute the Cholesky decomposition
+ * \f$ B = LL^* \f$ and computes the classical eigendecomposition
+ * of the selfadjoint matrix \f$ L^{-1} A (L^*)^{-1} \f$ if \p options contains Ax_lBx
+ * and of \f$ L^{*} A L \f$ otherwise. This solves the
+ * generalized eigenproblem, because any solution of the generalized
+ * eigenproblem \f$ Ax = \lambda B x \f$ corresponds to a solution
+ * \f$ L^{-1} A (L^*)^{-1} (L^* x) = \lambda (L^* x) \f$ of the
+ * eigenproblem for \f$ L^{-1} A (L^*)^{-1} \f$. Similar statements
+ * can be made for the two other variants.
+ *
+ * Example: \include SelfAdjointEigenSolver_compute_MatrixType2.cpp
+ * Output: \verbinclude SelfAdjointEigenSolver_compute_MatrixType2.out
+ *
+ * \sa GeneralizedSelfAdjointEigenSolver(const MatrixType&, const MatrixType&, int)
+ */
+ GeneralizedSelfAdjointEigenSolver& compute(const MatrixType& matA, const MatrixType& matB,
+ int options = ComputeEigenvectors|Ax_lBx);
+
+ protected:
+
+};
+
+
+template<typename MatrixType>
+GeneralizedSelfAdjointEigenSolver<MatrixType>& GeneralizedSelfAdjointEigenSolver<MatrixType>::
+compute(const MatrixType& matA, const MatrixType& matB, int options)
+{
+ eigen_assert(matA.cols()==matA.rows() && matB.rows()==matA.rows() && matB.cols()==matB.rows());
+ eigen_assert((options&~(EigVecMask|GenEigMask))==0
+ && (options&EigVecMask)!=EigVecMask
+ && ((options&GenEigMask)==0 || (options&GenEigMask)==Ax_lBx
+ || (options&GenEigMask)==ABx_lx || (options&GenEigMask)==BAx_lx)
+ && "invalid option parameter");
+
+ bool computeEigVecs = ((options&EigVecMask)==0) || ((options&EigVecMask)==ComputeEigenvectors);
+
+ // Compute the cholesky decomposition of matB = L L' = U'U
+ LLT<MatrixType> cholB(matB);
+
+ int type = (options&GenEigMask);
+ if(type==0)
+ type = Ax_lBx;
+
+ if(type==Ax_lBx)
+ {
+ // compute C = inv(L) A inv(L')
+ MatrixType matC = matA.template selfadjointView<Lower>();
+ cholB.matrixL().template solveInPlace<OnTheLeft>(matC);
+ cholB.matrixU().template solveInPlace<OnTheRight>(matC);
+
+ Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly );
+
+ // transform back the eigen vectors: evecs = inv(U) * evecs
+ if(computeEigVecs)
+ cholB.matrixU().solveInPlace(Base::m_eivec);
+ }
+ else if(type==ABx_lx)
+ {
+ // compute C = L' A L
+ MatrixType matC = matA.template selfadjointView<Lower>();
+ matC = matC * cholB.matrixL();
+ matC = cholB.matrixU() * matC;
+
+ Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly);
+
+ // transform back the eigen vectors: evecs = inv(U) * evecs
+ if(computeEigVecs)
+ cholB.matrixU().solveInPlace(Base::m_eivec);
+ }
+ else if(type==BAx_lx)
+ {
+ // compute C = L' A L
+ MatrixType matC = matA.template selfadjointView<Lower>();
+ matC = matC * cholB.matrixL();
+ matC = cholB.matrixU() * matC;
+
+ Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly);
+
+ // transform back the eigen vectors: evecs = L * evecs
+ if(computeEigVecs)
+ Base::m_eivec = cholB.matrixL() * Base::m_eivec;
+ }
+
+ return *this;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_GENERALIZEDSELFADJOINTEIGENSOLVER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/HessenbergDecomposition.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/HessenbergDecomposition.h
new file mode 100644
index 000000000..1f2113934
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/HessenbergDecomposition.h
@@ -0,0 +1,374 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_HESSENBERGDECOMPOSITION_H
+#define EIGEN_HESSENBERGDECOMPOSITION_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename MatrixType> struct HessenbergDecompositionMatrixHReturnType;
+template<typename MatrixType>
+struct traits<HessenbergDecompositionMatrixHReturnType<MatrixType> >
+{
+ typedef MatrixType ReturnType;
+};
+
+}
+
+/** \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ *
+ * \class HessenbergDecomposition
+ *
+ * \brief Reduces a square matrix to Hessenberg form by an orthogonal similarity transformation
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the Hessenberg decomposition
+ *
+ * This class performs an Hessenberg decomposition of a matrix \f$ A \f$. In
+ * the real case, the Hessenberg decomposition consists of an orthogonal
+ * matrix \f$ Q \f$ and a Hessenberg matrix \f$ H \f$ such that \f$ A = Q H
+ * Q^T \f$. An orthogonal matrix is a matrix whose inverse equals its
+ * transpose (\f$ Q^{-1} = Q^T \f$). A Hessenberg matrix has zeros below the
+ * subdiagonal, so it is almost upper triangular. The Hessenberg decomposition
+ * of a complex matrix is \f$ A = Q H Q^* \f$ with \f$ Q \f$ unitary (that is,
+ * \f$ Q^{-1} = Q^* \f$).
+ *
+ * Call the function compute() to compute the Hessenberg decomposition of a
+ * given matrix. Alternatively, you can use the
+ * HessenbergDecomposition(const MatrixType&) constructor which computes the
+ * Hessenberg decomposition at construction time. Once the decomposition is
+ * computed, you can use the matrixH() and matrixQ() functions to construct
+ * the matrices H and Q in the decomposition.
+ *
+ * The documentation for matrixH() contains an example of the typical use of
+ * this class.
+ *
+ * \sa class ComplexSchur, class Tridiagonalization, \ref QR_Module "QR Module"
+ */
+template<typename _MatrixType> class HessenbergDecomposition
+{
+ public:
+
+ /** \brief Synonym for the template parameter \p _MatrixType. */
+ typedef _MatrixType MatrixType;
+
+ enum {
+ Size = MatrixType::RowsAtCompileTime,
+ SizeMinusOne = Size == Dynamic ? Dynamic : Size - 1,
+ Options = MatrixType::Options,
+ MaxSize = MatrixType::MaxRowsAtCompileTime,
+ MaxSizeMinusOne = MaxSize == Dynamic ? Dynamic : MaxSize - 1
+ };
+
+ /** \brief Scalar type for matrices of type #MatrixType. */
+ typedef typename MatrixType::Scalar Scalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+
+ /** \brief Type for vector of Householder coefficients.
+ *
+ * This is column vector with entries of type #Scalar. The length of the
+ * vector is one less than the size of #MatrixType, if it is a fixed-side
+ * type.
+ */
+ typedef Matrix<Scalar, SizeMinusOne, 1, Options & ~RowMajor, MaxSizeMinusOne, 1> CoeffVectorType;
+
+ /** \brief Return type of matrixQ() */
+ typedef HouseholderSequence<MatrixType,typename internal::remove_all<typename CoeffVectorType::ConjugateReturnType>::type> HouseholderSequenceType;
+
+ typedef internal::HessenbergDecompositionMatrixHReturnType<MatrixType> MatrixHReturnType;
+
+ /** \brief Default constructor; the decomposition will be computed later.
+ *
+ * \param [in] size The size of the matrix whose Hessenberg decomposition will be computed.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via compute(). The \p size parameter is only
+ * used as a hint. It is not an error to give a wrong \p size, but it may
+ * impair performance.
+ *
+ * \sa compute() for an example.
+ */
+ explicit HessenbergDecomposition(Index size = Size==Dynamic ? 2 : Size)
+ : m_matrix(size,size),
+ m_temp(size),
+ m_isInitialized(false)
+ {
+ if(size>1)
+ m_hCoeffs.resize(size-1);
+ }
+
+ /** \brief Constructor; computes Hessenberg decomposition of given matrix.
+ *
+ * \param[in] matrix Square matrix whose Hessenberg decomposition is to be computed.
+ *
+ * This constructor calls compute() to compute the Hessenberg
+ * decomposition.
+ *
+ * \sa matrixH() for an example.
+ */
+ template<typename InputType>
+ explicit HessenbergDecomposition(const EigenBase<InputType>& matrix)
+ : m_matrix(matrix.derived()),
+ m_temp(matrix.rows()),
+ m_isInitialized(false)
+ {
+ if(matrix.rows()<2)
+ {
+ m_isInitialized = true;
+ return;
+ }
+ m_hCoeffs.resize(matrix.rows()-1,1);
+ _compute(m_matrix, m_hCoeffs, m_temp);
+ m_isInitialized = true;
+ }
+
+ /** \brief Computes Hessenberg decomposition of given matrix.
+ *
+ * \param[in] matrix Square matrix whose Hessenberg decomposition is to be computed.
+ * \returns Reference to \c *this
+ *
+ * The Hessenberg decomposition is computed by bringing the columns of the
+ * matrix successively in the required form using Householder reflections
+ * (see, e.g., Algorithm 7.4.2 in Golub \& Van Loan, <i>%Matrix
+ * Computations</i>). The cost is \f$ 10n^3/3 \f$ flops, where \f$ n \f$
+ * denotes the size of the given matrix.
+ *
+ * This method reuses of the allocated data in the HessenbergDecomposition
+ * object.
+ *
+ * Example: \include HessenbergDecomposition_compute.cpp
+ * Output: \verbinclude HessenbergDecomposition_compute.out
+ */
+ template<typename InputType>
+ HessenbergDecomposition& compute(const EigenBase<InputType>& matrix)
+ {
+ m_matrix = matrix.derived();
+ if(matrix.rows()<2)
+ {
+ m_isInitialized = true;
+ return *this;
+ }
+ m_hCoeffs.resize(matrix.rows()-1,1);
+ _compute(m_matrix, m_hCoeffs, m_temp);
+ m_isInitialized = true;
+ return *this;
+ }
+
+ /** \brief Returns the Householder coefficients.
+ *
+ * \returns a const reference to the vector of Householder coefficients
+ *
+ * \pre Either the constructor HessenbergDecomposition(const MatrixType&)
+ * or the member function compute(const MatrixType&) has been called
+ * before to compute the Hessenberg decomposition of a matrix.
+ *
+ * The Householder coefficients allow the reconstruction of the matrix
+ * \f$ Q \f$ in the Hessenberg decomposition from the packed data.
+ *
+ * \sa packedMatrix(), \ref Householder_Module "Householder module"
+ */
+ const CoeffVectorType& householderCoefficients() const
+ {
+ eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
+ return m_hCoeffs;
+ }
+
+ /** \brief Returns the internal representation of the decomposition
+ *
+ * \returns a const reference to a matrix with the internal representation
+ * of the decomposition.
+ *
+ * \pre Either the constructor HessenbergDecomposition(const MatrixType&)
+ * or the member function compute(const MatrixType&) has been called
+ * before to compute the Hessenberg decomposition of a matrix.
+ *
+ * The returned matrix contains the following information:
+ * - the upper part and lower sub-diagonal represent the Hessenberg matrix H
+ * - the rest of the lower part contains the Householder vectors that, combined with
+ * Householder coefficients returned by householderCoefficients(),
+ * allows to reconstruct the matrix Q as
+ * \f$ Q = H_{N-1} \ldots H_1 H_0 \f$.
+ * Here, the matrices \f$ H_i \f$ are the Householder transformations
+ * \f$ H_i = (I - h_i v_i v_i^T) \f$
+ * where \f$ h_i \f$ is the \f$ i \f$th Householder coefficient and
+ * \f$ v_i \f$ is the Householder vector defined by
+ * \f$ v_i = [ 0, \ldots, 0, 1, M(i+2,i), \ldots, M(N-1,i) ]^T \f$
+ * with M the matrix returned by this function.
+ *
+ * See LAPACK for further details on this packed storage.
+ *
+ * Example: \include HessenbergDecomposition_packedMatrix.cpp
+ * Output: \verbinclude HessenbergDecomposition_packedMatrix.out
+ *
+ * \sa householderCoefficients()
+ */
+ const MatrixType& packedMatrix() const
+ {
+ eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
+ return m_matrix;
+ }
+
+ /** \brief Reconstructs the orthogonal matrix Q in the decomposition
+ *
+ * \returns object representing the matrix Q
+ *
+ * \pre Either the constructor HessenbergDecomposition(const MatrixType&)
+ * or the member function compute(const MatrixType&) has been called
+ * before to compute the Hessenberg decomposition of a matrix.
+ *
+ * This function returns a light-weight object of template class
+ * HouseholderSequence. You can either apply it directly to a matrix or
+ * you can convert it to a matrix of type #MatrixType.
+ *
+ * \sa matrixH() for an example, class HouseholderSequence
+ */
+ HouseholderSequenceType matrixQ() const
+ {
+ eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
+ return HouseholderSequenceType(m_matrix, m_hCoeffs.conjugate())
+ .setLength(m_matrix.rows() - 1)
+ .setShift(1);
+ }
+
+ /** \brief Constructs the Hessenberg matrix H in the decomposition
+ *
+ * \returns expression object representing the matrix H
+ *
+ * \pre Either the constructor HessenbergDecomposition(const MatrixType&)
+ * or the member function compute(const MatrixType&) has been called
+ * before to compute the Hessenberg decomposition of a matrix.
+ *
+ * The object returned by this function constructs the Hessenberg matrix H
+ * when it is assigned to a matrix or otherwise evaluated. The matrix H is
+ * constructed from the packed matrix as returned by packedMatrix(): The
+ * upper part (including the subdiagonal) of the packed matrix contains
+ * the matrix H. It may sometimes be better to directly use the packed
+ * matrix instead of constructing the matrix H.
+ *
+ * Example: \include HessenbergDecomposition_matrixH.cpp
+ * Output: \verbinclude HessenbergDecomposition_matrixH.out
+ *
+ * \sa matrixQ(), packedMatrix()
+ */
+ MatrixHReturnType matrixH() const
+ {
+ eigen_assert(m_isInitialized && "HessenbergDecomposition is not initialized.");
+ return MatrixHReturnType(*this);
+ }
+
+ private:
+
+ typedef Matrix<Scalar, 1, Size, int(Options) | int(RowMajor), 1, MaxSize> VectorType;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ static void _compute(MatrixType& matA, CoeffVectorType& hCoeffs, VectorType& temp);
+
+ protected:
+ MatrixType m_matrix;
+ CoeffVectorType m_hCoeffs;
+ VectorType m_temp;
+ bool m_isInitialized;
+};
+
+/** \internal
+ * Performs a tridiagonal decomposition of \a matA in place.
+ *
+ * \param matA the input selfadjoint matrix
+ * \param hCoeffs returned Householder coefficients
+ *
+ * The result is written in the lower triangular part of \a matA.
+ *
+ * Implemented from Golub's "%Matrix Computations", algorithm 8.3.1.
+ *
+ * \sa packedMatrix()
+ */
+template<typename MatrixType>
+void HessenbergDecomposition<MatrixType>::_compute(MatrixType& matA, CoeffVectorType& hCoeffs, VectorType& temp)
+{
+ eigen_assert(matA.rows()==matA.cols());
+ Index n = matA.rows();
+ temp.resize(n);
+ for (Index i = 0; i<n-1; ++i)
+ {
+ // let's consider the vector v = i-th column starting at position i+1
+ Index remainingSize = n-i-1;
+ RealScalar beta;
+ Scalar h;
+ matA.col(i).tail(remainingSize).makeHouseholderInPlace(h, beta);
+ matA.col(i).coeffRef(i+1) = beta;
+ hCoeffs.coeffRef(i) = h;
+
+ // Apply similarity transformation to remaining columns,
+ // i.e., compute A = H A H'
+
+ // A = H A
+ matA.bottomRightCorner(remainingSize, remainingSize)
+ .applyHouseholderOnTheLeft(matA.col(i).tail(remainingSize-1), h, &temp.coeffRef(0));
+
+ // A = A H'
+ matA.rightCols(remainingSize)
+ .applyHouseholderOnTheRight(matA.col(i).tail(remainingSize-1), numext::conj(h), &temp.coeffRef(0));
+ }
+}
+
+namespace internal {
+
+/** \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ *
+ * \brief Expression type for return value of HessenbergDecomposition::matrixH()
+ *
+ * \tparam MatrixType type of matrix in the Hessenberg decomposition
+ *
+ * Objects of this type represent the Hessenberg matrix in the Hessenberg
+ * decomposition of some matrix. The object holds a reference to the
+ * HessenbergDecomposition class until the it is assigned or evaluated for
+ * some other reason (the reference should remain valid during the life time
+ * of this object). This class is the return type of
+ * HessenbergDecomposition::matrixH(); there is probably no other use for this
+ * class.
+ */
+template<typename MatrixType> struct HessenbergDecompositionMatrixHReturnType
+: public ReturnByValue<HessenbergDecompositionMatrixHReturnType<MatrixType> >
+{
+ public:
+ /** \brief Constructor.
+ *
+ * \param[in] hess Hessenberg decomposition
+ */
+ HessenbergDecompositionMatrixHReturnType(const HessenbergDecomposition<MatrixType>& hess) : m_hess(hess) { }
+
+ /** \brief Hessenberg matrix in decomposition.
+ *
+ * \param[out] result Hessenberg matrix in decomposition \p hess which
+ * was passed to the constructor
+ */
+ template <typename ResultType>
+ inline void evalTo(ResultType& result) const
+ {
+ result = m_hess.packedMatrix();
+ Index n = result.rows();
+ if (n>2)
+ result.bottomLeftCorner(n-2, n-2).template triangularView<Lower>().setZero();
+ }
+
+ Index rows() const { return m_hess.packedMatrix().rows(); }
+ Index cols() const { return m_hess.packedMatrix().cols(); }
+
+ protected:
+ const HessenbergDecomposition<MatrixType>& m_hess;
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_HESSENBERGDECOMPOSITION_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h
new file mode 100644
index 000000000..66e5a3dbb
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h
@@ -0,0 +1,158 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MATRIXBASEEIGENVALUES_H
+#define EIGEN_MATRIXBASEEIGENVALUES_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Derived, bool IsComplex>
+struct eigenvalues_selector
+{
+ // this is the implementation for the case IsComplex = true
+ static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
+ run(const MatrixBase<Derived>& m)
+ {
+ typedef typename Derived::PlainObject PlainObject;
+ PlainObject m_eval(m);
+ return ComplexEigenSolver<PlainObject>(m_eval, false).eigenvalues();
+ }
+};
+
+template<typename Derived>
+struct eigenvalues_selector<Derived, false>
+{
+ static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
+ run(const MatrixBase<Derived>& m)
+ {
+ typedef typename Derived::PlainObject PlainObject;
+ PlainObject m_eval(m);
+ return EigenSolver<PlainObject>(m_eval, false).eigenvalues();
+ }
+};
+
+} // end namespace internal
+
+/** \brief Computes the eigenvalues of a matrix
+ * \returns Column vector containing the eigenvalues.
+ *
+ * \eigenvalues_module
+ * This function computes the eigenvalues with the help of the EigenSolver
+ * class (for real matrices) or the ComplexEigenSolver class (for complex
+ * matrices).
+ *
+ * The eigenvalues are repeated according to their algebraic multiplicity,
+ * so there are as many eigenvalues as rows in the matrix.
+ *
+ * The SelfAdjointView class provides a better algorithm for selfadjoint
+ * matrices.
+ *
+ * Example: \include MatrixBase_eigenvalues.cpp
+ * Output: \verbinclude MatrixBase_eigenvalues.out
+ *
+ * \sa EigenSolver::eigenvalues(), ComplexEigenSolver::eigenvalues(),
+ * SelfAdjointView::eigenvalues()
+ */
+template<typename Derived>
+inline typename MatrixBase<Derived>::EigenvaluesReturnType
+MatrixBase<Derived>::eigenvalues() const
+{
+ return internal::eigenvalues_selector<Derived, NumTraits<Scalar>::IsComplex>::run(derived());
+}
+
+/** \brief Computes the eigenvalues of a matrix
+ * \returns Column vector containing the eigenvalues.
+ *
+ * \eigenvalues_module
+ * This function computes the eigenvalues with the help of the
+ * SelfAdjointEigenSolver class. The eigenvalues are repeated according to
+ * their algebraic multiplicity, so there are as many eigenvalues as rows in
+ * the matrix.
+ *
+ * Example: \include SelfAdjointView_eigenvalues.cpp
+ * Output: \verbinclude SelfAdjointView_eigenvalues.out
+ *
+ * \sa SelfAdjointEigenSolver::eigenvalues(), MatrixBase::eigenvalues()
+ */
+template<typename MatrixType, unsigned int UpLo>
+EIGEN_DEVICE_FUNC inline typename SelfAdjointView<MatrixType, UpLo>::EigenvaluesReturnType
+SelfAdjointView<MatrixType, UpLo>::eigenvalues() const
+{
+ PlainObject thisAsMatrix(*this);
+ return SelfAdjointEigenSolver<PlainObject>(thisAsMatrix, false).eigenvalues();
+}
+
+
+
+/** \brief Computes the L2 operator norm
+ * \returns Operator norm of the matrix.
+ *
+ * \eigenvalues_module
+ * This function computes the L2 operator norm of a matrix, which is also
+ * known as the spectral norm. The norm of a matrix \f$ A \f$ is defined to be
+ * \f[ \|A\|_2 = \max_x \frac{\|Ax\|_2}{\|x\|_2} \f]
+ * where the maximum is over all vectors and the norm on the right is the
+ * Euclidean vector norm. The norm equals the largest singular value, which is
+ * the square root of the largest eigenvalue of the positive semi-definite
+ * matrix \f$ A^*A \f$.
+ *
+ * The current implementation uses the eigenvalues of \f$ A^*A \f$, as computed
+ * by SelfAdjointView::eigenvalues(), to compute the operator norm of a
+ * matrix. The SelfAdjointView class provides a better algorithm for
+ * selfadjoint matrices.
+ *
+ * Example: \include MatrixBase_operatorNorm.cpp
+ * Output: \verbinclude MatrixBase_operatorNorm.out
+ *
+ * \sa SelfAdjointView::eigenvalues(), SelfAdjointView::operatorNorm()
+ */
+template<typename Derived>
+inline typename MatrixBase<Derived>::RealScalar
+MatrixBase<Derived>::operatorNorm() const
+{
+ using std::sqrt;
+ typename Derived::PlainObject m_eval(derived());
+ // FIXME if it is really guaranteed that the eigenvalues are already sorted,
+ // then we don't need to compute a maxCoeff() here, comparing the 1st and last ones is enough.
+ return sqrt((m_eval*m_eval.adjoint())
+ .eval()
+ .template selfadjointView<Lower>()
+ .eigenvalues()
+ .maxCoeff()
+ );
+}
+
+/** \brief Computes the L2 operator norm
+ * \returns Operator norm of the matrix.
+ *
+ * \eigenvalues_module
+ * This function computes the L2 operator norm of a self-adjoint matrix. For a
+ * self-adjoint matrix, the operator norm is the largest eigenvalue.
+ *
+ * The current implementation uses the eigenvalues of the matrix, as computed
+ * by eigenvalues(), to compute the operator norm of the matrix.
+ *
+ * Example: \include SelfAdjointView_operatorNorm.cpp
+ * Output: \verbinclude SelfAdjointView_operatorNorm.out
+ *
+ * \sa eigenvalues(), MatrixBase::operatorNorm()
+ */
+template<typename MatrixType, unsigned int UpLo>
+EIGEN_DEVICE_FUNC inline typename SelfAdjointView<MatrixType, UpLo>::RealScalar
+SelfAdjointView<MatrixType, UpLo>::operatorNorm() const
+{
+ return eigenvalues().cwiseAbs().maxCoeff();
+}
+
+} // end namespace Eigen
+
+#endif
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/RealQZ.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/RealQZ.h
new file mode 100644
index 000000000..509130184
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/RealQZ.h
@@ -0,0 +1,657 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2012 Alexey Korepanov <kaikaikai@yandex.ru>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_REAL_QZ_H
+#define EIGEN_REAL_QZ_H
+
+namespace Eigen {
+
+ /** \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ *
+ * \class RealQZ
+ *
+ * \brief Performs a real QZ decomposition of a pair of square matrices
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the
+ * real QZ decomposition; this is expected to be an instantiation of the
+ * Matrix class template.
+ *
+ * Given a real square matrices A and B, this class computes the real QZ
+ * decomposition: \f$ A = Q S Z \f$, \f$ B = Q T Z \f$ where Q and Z are
+ * real orthogonal matrixes, T is upper-triangular matrix, and S is upper
+ * quasi-triangular matrix. An orthogonal matrix is a matrix whose
+ * inverse is equal to its transpose, \f$ U^{-1} = U^T \f$. A quasi-triangular
+ * matrix is a block-triangular matrix whose diagonal consists of 1-by-1
+ * blocks and 2-by-2 blocks where further reduction is impossible due to
+ * complex eigenvalues.
+ *
+ * The eigenvalues of the pencil \f$ A - z B \f$ can be obtained from
+ * 1x1 and 2x2 blocks on the diagonals of S and T.
+ *
+ * Call the function compute() to compute the real QZ decomposition of a
+ * given pair of matrices. Alternatively, you can use the
+ * RealQZ(const MatrixType& B, const MatrixType& B, bool computeQZ)
+ * constructor which computes the real QZ decomposition at construction
+ * time. Once the decomposition is computed, you can use the matrixS(),
+ * matrixT(), matrixQ() and matrixZ() functions to retrieve the matrices
+ * S, T, Q and Z in the decomposition. If computeQZ==false, some time
+ * is saved by not computing matrices Q and Z.
+ *
+ * Example: \include RealQZ_compute.cpp
+ * Output: \include RealQZ_compute.out
+ *
+ * \note The implementation is based on the algorithm in "Matrix Computations"
+ * by Gene H. Golub and Charles F. Van Loan, and a paper "An algorithm for
+ * generalized eigenvalue problems" by C.B.Moler and G.W.Stewart.
+ *
+ * \sa class RealSchur, class ComplexSchur, class EigenSolver, class ComplexEigenSolver
+ */
+
+ template<typename _MatrixType> class RealQZ
+ {
+ public:
+ typedef _MatrixType MatrixType;
+ enum {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ Options = MatrixType::Options,
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+ typedef typename MatrixType::Scalar Scalar;
+ typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+
+ typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> EigenvalueType;
+ typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> ColumnVectorType;
+
+ /** \brief Default constructor.
+ *
+ * \param [in] size Positive integer, size of the matrix whose QZ decomposition will be computed.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via compute(). The \p size parameter is only
+ * used as a hint. It is not an error to give a wrong \p size, but it may
+ * impair performance.
+ *
+ * \sa compute() for an example.
+ */
+ explicit RealQZ(Index size = RowsAtCompileTime==Dynamic ? 1 : RowsAtCompileTime) :
+ m_S(size, size),
+ m_T(size, size),
+ m_Q(size, size),
+ m_Z(size, size),
+ m_workspace(size*2),
+ m_maxIters(400),
+ m_isInitialized(false),
+ m_computeQZ(true)
+ {}
+
+ /** \brief Constructor; computes real QZ decomposition of given matrices
+ *
+ * \param[in] A Matrix A.
+ * \param[in] B Matrix B.
+ * \param[in] computeQZ If false, A and Z are not computed.
+ *
+ * This constructor calls compute() to compute the QZ decomposition.
+ */
+ RealQZ(const MatrixType& A, const MatrixType& B, bool computeQZ = true) :
+ m_S(A.rows(),A.cols()),
+ m_T(A.rows(),A.cols()),
+ m_Q(A.rows(),A.cols()),
+ m_Z(A.rows(),A.cols()),
+ m_workspace(A.rows()*2),
+ m_maxIters(400),
+ m_isInitialized(false),
+ m_computeQZ(true)
+ {
+ compute(A, B, computeQZ);
+ }
+
+ /** \brief Returns matrix Q in the QZ decomposition.
+ *
+ * \returns A const reference to the matrix Q.
+ */
+ const MatrixType& matrixQ() const {
+ eigen_assert(m_isInitialized && "RealQZ is not initialized.");
+ eigen_assert(m_computeQZ && "The matrices Q and Z have not been computed during the QZ decomposition.");
+ return m_Q;
+ }
+
+ /** \brief Returns matrix Z in the QZ decomposition.
+ *
+ * \returns A const reference to the matrix Z.
+ */
+ const MatrixType& matrixZ() const {
+ eigen_assert(m_isInitialized && "RealQZ is not initialized.");
+ eigen_assert(m_computeQZ && "The matrices Q and Z have not been computed during the QZ decomposition.");
+ return m_Z;
+ }
+
+ /** \brief Returns matrix S in the QZ decomposition.
+ *
+ * \returns A const reference to the matrix S.
+ */
+ const MatrixType& matrixS() const {
+ eigen_assert(m_isInitialized && "RealQZ is not initialized.");
+ return m_S;
+ }
+
+ /** \brief Returns matrix S in the QZ decomposition.
+ *
+ * \returns A const reference to the matrix S.
+ */
+ const MatrixType& matrixT() const {
+ eigen_assert(m_isInitialized && "RealQZ is not initialized.");
+ return m_T;
+ }
+
+ /** \brief Computes QZ decomposition of given matrix.
+ *
+ * \param[in] A Matrix A.
+ * \param[in] B Matrix B.
+ * \param[in] computeQZ If false, A and Z are not computed.
+ * \returns Reference to \c *this
+ */
+ RealQZ& compute(const MatrixType& A, const MatrixType& B, bool computeQZ = true);
+
+ /** \brief Reports whether previous computation was successful.
+ *
+ * \returns \c Success if computation was successful, \c NoConvergence otherwise.
+ */
+ ComputationInfo info() const
+ {
+ eigen_assert(m_isInitialized && "RealQZ is not initialized.");
+ return m_info;
+ }
+
+ /** \brief Returns number of performed QR-like iterations.
+ */
+ Index iterations() const
+ {
+ eigen_assert(m_isInitialized && "RealQZ is not initialized.");
+ return m_global_iter;
+ }
+
+ /** Sets the maximal number of iterations allowed to converge to one eigenvalue
+ * or decouple the problem.
+ */
+ RealQZ& setMaxIterations(Index maxIters)
+ {
+ m_maxIters = maxIters;
+ return *this;
+ }
+
+ private:
+
+ MatrixType m_S, m_T, m_Q, m_Z;
+ Matrix<Scalar,Dynamic,1> m_workspace;
+ ComputationInfo m_info;
+ Index m_maxIters;
+ bool m_isInitialized;
+ bool m_computeQZ;
+ Scalar m_normOfT, m_normOfS;
+ Index m_global_iter;
+
+ typedef Matrix<Scalar,3,1> Vector3s;
+ typedef Matrix<Scalar,2,1> Vector2s;
+ typedef Matrix<Scalar,2,2> Matrix2s;
+ typedef JacobiRotation<Scalar> JRs;
+
+ void hessenbergTriangular();
+ void computeNorms();
+ Index findSmallSubdiagEntry(Index iu);
+ Index findSmallDiagEntry(Index f, Index l);
+ void splitOffTwoRows(Index i);
+ void pushDownZero(Index z, Index f, Index l);
+ void step(Index f, Index l, Index iter);
+
+ }; // RealQZ
+
+ /** \internal Reduces S and T to upper Hessenberg - triangular form */
+ template<typename MatrixType>
+ void RealQZ<MatrixType>::hessenbergTriangular()
+ {
+
+ const Index dim = m_S.cols();
+
+ // perform QR decomposition of T, overwrite T with R, save Q
+ HouseholderQR<MatrixType> qrT(m_T);
+ m_T = qrT.matrixQR();
+ m_T.template triangularView<StrictlyLower>().setZero();
+ m_Q = qrT.householderQ();
+ // overwrite S with Q* S
+ m_S.applyOnTheLeft(m_Q.adjoint());
+ // init Z as Identity
+ if (m_computeQZ)
+ m_Z = MatrixType::Identity(dim,dim);
+ // reduce S to upper Hessenberg with Givens rotations
+ for (Index j=0; j<=dim-3; j++) {
+ for (Index i=dim-1; i>=j+2; i--) {
+ JRs G;
+ // kill S(i,j)
+ if(m_S.coeff(i,j) != 0)
+ {
+ G.makeGivens(m_S.coeff(i-1,j), m_S.coeff(i,j), &m_S.coeffRef(i-1, j));
+ m_S.coeffRef(i,j) = Scalar(0.0);
+ m_S.rightCols(dim-j-1).applyOnTheLeft(i-1,i,G.adjoint());
+ m_T.rightCols(dim-i+1).applyOnTheLeft(i-1,i,G.adjoint());
+ // update Q
+ if (m_computeQZ)
+ m_Q.applyOnTheRight(i-1,i,G);
+ }
+ // kill T(i,i-1)
+ if(m_T.coeff(i,i-1)!=Scalar(0))
+ {
+ G.makeGivens(m_T.coeff(i,i), m_T.coeff(i,i-1), &m_T.coeffRef(i,i));
+ m_T.coeffRef(i,i-1) = Scalar(0.0);
+ m_S.applyOnTheRight(i,i-1,G);
+ m_T.topRows(i).applyOnTheRight(i,i-1,G);
+ // update Z
+ if (m_computeQZ)
+ m_Z.applyOnTheLeft(i,i-1,G.adjoint());
+ }
+ }
+ }
+ }
+
+ /** \internal Computes vector L1 norms of S and T when in Hessenberg-Triangular form already */
+ template<typename MatrixType>
+ inline void RealQZ<MatrixType>::computeNorms()
+ {
+ const Index size = m_S.cols();
+ m_normOfS = Scalar(0.0);
+ m_normOfT = Scalar(0.0);
+ for (Index j = 0; j < size; ++j)
+ {
+ m_normOfS += m_S.col(j).segment(0, (std::min)(size,j+2)).cwiseAbs().sum();
+ m_normOfT += m_T.row(j).segment(j, size - j).cwiseAbs().sum();
+ }
+ }
+
+
+ /** \internal Look for single small sub-diagonal element S(res, res-1) and return res (or 0) */
+ template<typename MatrixType>
+ inline Index RealQZ<MatrixType>::findSmallSubdiagEntry(Index iu)
+ {
+ using std::abs;
+ Index res = iu;
+ while (res > 0)
+ {
+ Scalar s = abs(m_S.coeff(res-1,res-1)) + abs(m_S.coeff(res,res));
+ if (s == Scalar(0.0))
+ s = m_normOfS;
+ if (abs(m_S.coeff(res,res-1)) < NumTraits<Scalar>::epsilon() * s)
+ break;
+ res--;
+ }
+ return res;
+ }
+
+ /** \internal Look for single small diagonal element T(res, res) for res between f and l, and return res (or f-1) */
+ template<typename MatrixType>
+ inline Index RealQZ<MatrixType>::findSmallDiagEntry(Index f, Index l)
+ {
+ using std::abs;
+ Index res = l;
+ while (res >= f) {
+ if (abs(m_T.coeff(res,res)) <= NumTraits<Scalar>::epsilon() * m_normOfT)
+ break;
+ res--;
+ }
+ return res;
+ }
+
+ /** \internal decouple 2x2 diagonal block in rows i, i+1 if eigenvalues are real */
+ template<typename MatrixType>
+ inline void RealQZ<MatrixType>::splitOffTwoRows(Index i)
+ {
+ using std::abs;
+ using std::sqrt;
+ const Index dim=m_S.cols();
+ if (abs(m_S.coeff(i+1,i))==Scalar(0))
+ return;
+ Index j = findSmallDiagEntry(i,i+1);
+ if (j==i-1)
+ {
+ // block of (S T^{-1})
+ Matrix2s STi = m_T.template block<2,2>(i,i).template triangularView<Upper>().
+ template solve<OnTheRight>(m_S.template block<2,2>(i,i));
+ Scalar p = Scalar(0.5)*(STi(0,0)-STi(1,1));
+ Scalar q = p*p + STi(1,0)*STi(0,1);
+ if (q>=0) {
+ Scalar z = sqrt(q);
+ // one QR-like iteration for ABi - lambda I
+ // is enough - when we know exact eigenvalue in advance,
+ // convergence is immediate
+ JRs G;
+ if (p>=0)
+ G.makeGivens(p + z, STi(1,0));
+ else
+ G.makeGivens(p - z, STi(1,0));
+ m_S.rightCols(dim-i).applyOnTheLeft(i,i+1,G.adjoint());
+ m_T.rightCols(dim-i).applyOnTheLeft(i,i+1,G.adjoint());
+ // update Q
+ if (m_computeQZ)
+ m_Q.applyOnTheRight(i,i+1,G);
+
+ G.makeGivens(m_T.coeff(i+1,i+1), m_T.coeff(i+1,i));
+ m_S.topRows(i+2).applyOnTheRight(i+1,i,G);
+ m_T.topRows(i+2).applyOnTheRight(i+1,i,G);
+ // update Z
+ if (m_computeQZ)
+ m_Z.applyOnTheLeft(i+1,i,G.adjoint());
+
+ m_S.coeffRef(i+1,i) = Scalar(0.0);
+ m_T.coeffRef(i+1,i) = Scalar(0.0);
+ }
+ }
+ else
+ {
+ pushDownZero(j,i,i+1);
+ }
+ }
+
+ /** \internal use zero in T(z,z) to zero S(l,l-1), working in block f..l */
+ template<typename MatrixType>
+ inline void RealQZ<MatrixType>::pushDownZero(Index z, Index f, Index l)
+ {
+ JRs G;
+ const Index dim = m_S.cols();
+ for (Index zz=z; zz<l; zz++)
+ {
+ // push 0 down
+ Index firstColS = zz>f ? (zz-1) : zz;
+ G.makeGivens(m_T.coeff(zz, zz+1), m_T.coeff(zz+1, zz+1));
+ m_S.rightCols(dim-firstColS).applyOnTheLeft(zz,zz+1,G.adjoint());
+ m_T.rightCols(dim-zz).applyOnTheLeft(zz,zz+1,G.adjoint());
+ m_T.coeffRef(zz+1,zz+1) = Scalar(0.0);
+ // update Q
+ if (m_computeQZ)
+ m_Q.applyOnTheRight(zz,zz+1,G);
+ // kill S(zz+1, zz-1)
+ if (zz>f)
+ {
+ G.makeGivens(m_S.coeff(zz+1, zz), m_S.coeff(zz+1,zz-1));
+ m_S.topRows(zz+2).applyOnTheRight(zz, zz-1,G);
+ m_T.topRows(zz+1).applyOnTheRight(zz, zz-1,G);
+ m_S.coeffRef(zz+1,zz-1) = Scalar(0.0);
+ // update Z
+ if (m_computeQZ)
+ m_Z.applyOnTheLeft(zz,zz-1,G.adjoint());
+ }
+ }
+ // finally kill S(l,l-1)
+ G.makeGivens(m_S.coeff(l,l), m_S.coeff(l,l-1));
+ m_S.applyOnTheRight(l,l-1,G);
+ m_T.applyOnTheRight(l,l-1,G);
+ m_S.coeffRef(l,l-1)=Scalar(0.0);
+ // update Z
+ if (m_computeQZ)
+ m_Z.applyOnTheLeft(l,l-1,G.adjoint());
+ }
+
+ /** \internal QR-like iterative step for block f..l */
+ template<typename MatrixType>
+ inline void RealQZ<MatrixType>::step(Index f, Index l, Index iter)
+ {
+ using std::abs;
+ const Index dim = m_S.cols();
+
+ // x, y, z
+ Scalar x, y, z;
+ if (iter==10)
+ {
+ // Wilkinson ad hoc shift
+ const Scalar
+ a11=m_S.coeff(f+0,f+0), a12=m_S.coeff(f+0,f+1),
+ a21=m_S.coeff(f+1,f+0), a22=m_S.coeff(f+1,f+1), a32=m_S.coeff(f+2,f+1),
+ b12=m_T.coeff(f+0,f+1),
+ b11i=Scalar(1.0)/m_T.coeff(f+0,f+0),
+ b22i=Scalar(1.0)/m_T.coeff(f+1,f+1),
+ a87=m_S.coeff(l-1,l-2),
+ a98=m_S.coeff(l-0,l-1),
+ b77i=Scalar(1.0)/m_T.coeff(l-2,l-2),
+ b88i=Scalar(1.0)/m_T.coeff(l-1,l-1);
+ Scalar ss = abs(a87*b77i) + abs(a98*b88i),
+ lpl = Scalar(1.5)*ss,
+ ll = ss*ss;
+ x = ll + a11*a11*b11i*b11i - lpl*a11*b11i + a12*a21*b11i*b22i
+ - a11*a21*b12*b11i*b11i*b22i;
+ y = a11*a21*b11i*b11i - lpl*a21*b11i + a21*a22*b11i*b22i
+ - a21*a21*b12*b11i*b11i*b22i;
+ z = a21*a32*b11i*b22i;
+ }
+ else if (iter==16)
+ {
+ // another exceptional shift
+ x = m_S.coeff(f,f)/m_T.coeff(f,f)-m_S.coeff(l,l)/m_T.coeff(l,l) + m_S.coeff(l,l-1)*m_T.coeff(l-1,l) /
+ (m_T.coeff(l-1,l-1)*m_T.coeff(l,l));
+ y = m_S.coeff(f+1,f)/m_T.coeff(f,f);
+ z = 0;
+ }
+ else if (iter>23 && !(iter%8))
+ {
+ // extremely exceptional shift
+ x = internal::random<Scalar>(-1.0,1.0);
+ y = internal::random<Scalar>(-1.0,1.0);
+ z = internal::random<Scalar>(-1.0,1.0);
+ }
+ else
+ {
+ // Compute the shifts: (x,y,z,0...) = (AB^-1 - l1 I) (AB^-1 - l2 I) e1
+ // where l1 and l2 are the eigenvalues of the 2x2 matrix C = U V^-1 where
+ // U and V are 2x2 bottom right sub matrices of A and B. Thus:
+ // = AB^-1AB^-1 + l1 l2 I - (l1+l2)(AB^-1)
+ // = AB^-1AB^-1 + det(M) - tr(M)(AB^-1)
+ // Since we are only interested in having x, y, z with a correct ratio, we have:
+ const Scalar
+ a11 = m_S.coeff(f,f), a12 = m_S.coeff(f,f+1),
+ a21 = m_S.coeff(f+1,f), a22 = m_S.coeff(f+1,f+1),
+ a32 = m_S.coeff(f+2,f+1),
+
+ a88 = m_S.coeff(l-1,l-1), a89 = m_S.coeff(l-1,l),
+ a98 = m_S.coeff(l,l-1), a99 = m_S.coeff(l,l),
+
+ b11 = m_T.coeff(f,f), b12 = m_T.coeff(f,f+1),
+ b22 = m_T.coeff(f+1,f+1),
+
+ b88 = m_T.coeff(l-1,l-1), b89 = m_T.coeff(l-1,l),
+ b99 = m_T.coeff(l,l);
+
+ x = ( (a88/b88 - a11/b11)*(a99/b99 - a11/b11) - (a89/b99)*(a98/b88) + (a98/b88)*(b89/b99)*(a11/b11) ) * (b11/a21)
+ + a12/b22 - (a11/b11)*(b12/b22);
+ y = (a22/b22-a11/b11) - (a21/b11)*(b12/b22) - (a88/b88-a11/b11) - (a99/b99-a11/b11) + (a98/b88)*(b89/b99);
+ z = a32/b22;
+ }
+
+ JRs G;
+
+ for (Index k=f; k<=l-2; k++)
+ {
+ // variables for Householder reflections
+ Vector2s essential2;
+ Scalar tau, beta;
+
+ Vector3s hr(x,y,z);
+
+ // Q_k to annihilate S(k+1,k-1) and S(k+2,k-1)
+ hr.makeHouseholderInPlace(tau, beta);
+ essential2 = hr.template bottomRows<2>();
+ Index fc=(std::max)(k-1,Index(0)); // first col to update
+ m_S.template middleRows<3>(k).rightCols(dim-fc).applyHouseholderOnTheLeft(essential2, tau, m_workspace.data());
+ m_T.template middleRows<3>(k).rightCols(dim-fc).applyHouseholderOnTheLeft(essential2, tau, m_workspace.data());
+ if (m_computeQZ)
+ m_Q.template middleCols<3>(k).applyHouseholderOnTheRight(essential2, tau, m_workspace.data());
+ if (k>f)
+ m_S.coeffRef(k+2,k-1) = m_S.coeffRef(k+1,k-1) = Scalar(0.0);
+
+ // Z_{k1} to annihilate T(k+2,k+1) and T(k+2,k)
+ hr << m_T.coeff(k+2,k+2),m_T.coeff(k+2,k),m_T.coeff(k+2,k+1);
+ hr.makeHouseholderInPlace(tau, beta);
+ essential2 = hr.template bottomRows<2>();
+ {
+ Index lr = (std::min)(k+4,dim); // last row to update
+ Map<Matrix<Scalar,Dynamic,1> > tmp(m_workspace.data(),lr);
+ // S
+ tmp = m_S.template middleCols<2>(k).topRows(lr) * essential2;
+ tmp += m_S.col(k+2).head(lr);
+ m_S.col(k+2).head(lr) -= tau*tmp;
+ m_S.template middleCols<2>(k).topRows(lr) -= (tau*tmp) * essential2.adjoint();
+ // T
+ tmp = m_T.template middleCols<2>(k).topRows(lr) * essential2;
+ tmp += m_T.col(k+2).head(lr);
+ m_T.col(k+2).head(lr) -= tau*tmp;
+ m_T.template middleCols<2>(k).topRows(lr) -= (tau*tmp) * essential2.adjoint();
+ }
+ if (m_computeQZ)
+ {
+ // Z
+ Map<Matrix<Scalar,1,Dynamic> > tmp(m_workspace.data(),dim);
+ tmp = essential2.adjoint()*(m_Z.template middleRows<2>(k));
+ tmp += m_Z.row(k+2);
+ m_Z.row(k+2) -= tau*tmp;
+ m_Z.template middleRows<2>(k) -= essential2 * (tau*tmp);
+ }
+ m_T.coeffRef(k+2,k) = m_T.coeffRef(k+2,k+1) = Scalar(0.0);
+
+ // Z_{k2} to annihilate T(k+1,k)
+ G.makeGivens(m_T.coeff(k+1,k+1), m_T.coeff(k+1,k));
+ m_S.applyOnTheRight(k+1,k,G);
+ m_T.applyOnTheRight(k+1,k,G);
+ // update Z
+ if (m_computeQZ)
+ m_Z.applyOnTheLeft(k+1,k,G.adjoint());
+ m_T.coeffRef(k+1,k) = Scalar(0.0);
+
+ // update x,y,z
+ x = m_S.coeff(k+1,k);
+ y = m_S.coeff(k+2,k);
+ if (k < l-2)
+ z = m_S.coeff(k+3,k);
+ } // loop over k
+
+ // Q_{n-1} to annihilate y = S(l,l-2)
+ G.makeGivens(x,y);
+ m_S.applyOnTheLeft(l-1,l,G.adjoint());
+ m_T.applyOnTheLeft(l-1,l,G.adjoint());
+ if (m_computeQZ)
+ m_Q.applyOnTheRight(l-1,l,G);
+ m_S.coeffRef(l,l-2) = Scalar(0.0);
+
+ // Z_{n-1} to annihilate T(l,l-1)
+ G.makeGivens(m_T.coeff(l,l),m_T.coeff(l,l-1));
+ m_S.applyOnTheRight(l,l-1,G);
+ m_T.applyOnTheRight(l,l-1,G);
+ if (m_computeQZ)
+ m_Z.applyOnTheLeft(l,l-1,G.adjoint());
+ m_T.coeffRef(l,l-1) = Scalar(0.0);
+ }
+
+ template<typename MatrixType>
+ RealQZ<MatrixType>& RealQZ<MatrixType>::compute(const MatrixType& A_in, const MatrixType& B_in, bool computeQZ)
+ {
+
+ const Index dim = A_in.cols();
+
+ eigen_assert (A_in.rows()==dim && A_in.cols()==dim
+ && B_in.rows()==dim && B_in.cols()==dim
+ && "Need square matrices of the same dimension");
+
+ m_isInitialized = true;
+ m_computeQZ = computeQZ;
+ m_S = A_in; m_T = B_in;
+ m_workspace.resize(dim*2);
+ m_global_iter = 0;
+
+ // entrance point: hessenberg triangular decomposition
+ hessenbergTriangular();
+ // compute L1 vector norms of T, S into m_normOfS, m_normOfT
+ computeNorms();
+
+ Index l = dim-1,
+ f,
+ local_iter = 0;
+
+ while (l>0 && local_iter<m_maxIters)
+ {
+ f = findSmallSubdiagEntry(l);
+ // now rows and columns f..l (including) decouple from the rest of the problem
+ if (f>0) m_S.coeffRef(f,f-1) = Scalar(0.0);
+ if (f == l) // One root found
+ {
+ l--;
+ local_iter = 0;
+ }
+ else if (f == l-1) // Two roots found
+ {
+ splitOffTwoRows(f);
+ l -= 2;
+ local_iter = 0;
+ }
+ else // No convergence yet
+ {
+ // if there's zero on diagonal of T, we can isolate an eigenvalue with Givens rotations
+ Index z = findSmallDiagEntry(f,l);
+ if (z>=f)
+ {
+ // zero found
+ pushDownZero(z,f,l);
+ }
+ else
+ {
+ // We are sure now that S.block(f,f, l-f+1,l-f+1) is underuced upper-Hessenberg
+ // and T.block(f,f, l-f+1,l-f+1) is invertible uper-triangular, which allows to
+ // apply a QR-like iteration to rows and columns f..l.
+ step(f,l, local_iter);
+ local_iter++;
+ m_global_iter++;
+ }
+ }
+ }
+ // check if we converged before reaching iterations limit
+ m_info = (local_iter<m_maxIters) ? Success : NoConvergence;
+
+ // For each non triangular 2x2 diagonal block of S,
+ // reduce the respective 2x2 diagonal block of T to positive diagonal form using 2x2 SVD.
+ // This step is not mandatory for QZ, but it does help further extraction of eigenvalues/eigenvectors,
+ // and is in par with Lapack/Matlab QZ.
+ if(m_info==Success)
+ {
+ for(Index i=0; i<dim-1; ++i)
+ {
+ if(m_S.coeff(i+1, i) != Scalar(0))
+ {
+ JacobiRotation<Scalar> j_left, j_right;
+ internal::real_2x2_jacobi_svd(m_T, i, i+1, &j_left, &j_right);
+
+ // Apply resulting Jacobi rotations
+ m_S.applyOnTheLeft(i,i+1,j_left);
+ m_S.applyOnTheRight(i,i+1,j_right);
+ m_T.applyOnTheLeft(i,i+1,j_left);
+ m_T.applyOnTheRight(i,i+1,j_right);
+ m_T(i+1,i) = m_T(i,i+1) = Scalar(0);
+
+ if(m_computeQZ) {
+ m_Q.applyOnTheRight(i,i+1,j_left.transpose());
+ m_Z.applyOnTheLeft(i,i+1,j_right.transpose());
+ }
+
+ i++;
+ }
+ }
+ }
+
+ return *this;
+ } // end compute
+
+} // end namespace Eigen
+
+#endif //EIGEN_REAL_QZ
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/RealSchur.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/RealSchur.h
new file mode 100644
index 000000000..7304ef344
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/RealSchur.h
@@ -0,0 +1,558 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_REAL_SCHUR_H
+#define EIGEN_REAL_SCHUR_H
+
+#include "./HessenbergDecomposition.h"
+
+namespace Eigen {
+
+/** \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ *
+ * \class RealSchur
+ *
+ * \brief Performs a real Schur decomposition of a square matrix
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the
+ * real Schur decomposition; this is expected to be an instantiation of the
+ * Matrix class template.
+ *
+ * Given a real square matrix A, this class computes the real Schur
+ * decomposition: \f$ A = U T U^T \f$ where U is a real orthogonal matrix and
+ * T is a real quasi-triangular matrix. An orthogonal matrix is a matrix whose
+ * inverse is equal to its transpose, \f$ U^{-1} = U^T \f$. A quasi-triangular
+ * matrix is a block-triangular matrix whose diagonal consists of 1-by-1
+ * blocks and 2-by-2 blocks with complex eigenvalues. The eigenvalues of the
+ * blocks on the diagonal of T are the same as the eigenvalues of the matrix
+ * A, and thus the real Schur decomposition is used in EigenSolver to compute
+ * the eigendecomposition of a matrix.
+ *
+ * Call the function compute() to compute the real Schur decomposition of a
+ * given matrix. Alternatively, you can use the RealSchur(const MatrixType&, bool)
+ * constructor which computes the real Schur decomposition at construction
+ * time. Once the decomposition is computed, you can use the matrixU() and
+ * matrixT() functions to retrieve the matrices U and T in the decomposition.
+ *
+ * The documentation of RealSchur(const MatrixType&, bool) contains an example
+ * of the typical use of this class.
+ *
+ * \note The implementation is adapted from
+ * <a href="http://math.nist.gov/javanumerics/jama/">JAMA</a> (public domain).
+ * Their code is based on EISPACK.
+ *
+ * \sa class ComplexSchur, class EigenSolver, class ComplexEigenSolver
+ */
+template<typename _MatrixType> class RealSchur
+{
+ public:
+ typedef _MatrixType MatrixType;
+ enum {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ Options = MatrixType::Options,
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+ typedef typename MatrixType::Scalar Scalar;
+ typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+
+ typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> EigenvalueType;
+ typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> ColumnVectorType;
+
+ /** \brief Default constructor.
+ *
+ * \param [in] size Positive integer, size of the matrix whose Schur decomposition will be computed.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via compute(). The \p size parameter is only
+ * used as a hint. It is not an error to give a wrong \p size, but it may
+ * impair performance.
+ *
+ * \sa compute() for an example.
+ */
+ explicit RealSchur(Index size = RowsAtCompileTime==Dynamic ? 1 : RowsAtCompileTime)
+ : m_matT(size, size),
+ m_matU(size, size),
+ m_workspaceVector(size),
+ m_hess(size),
+ m_isInitialized(false),
+ m_matUisUptodate(false),
+ m_maxIters(-1)
+ { }
+
+ /** \brief Constructor; computes real Schur decomposition of given matrix.
+ *
+ * \param[in] matrix Square matrix whose Schur decomposition is to be computed.
+ * \param[in] computeU If true, both T and U are computed; if false, only T is computed.
+ *
+ * This constructor calls compute() to compute the Schur decomposition.
+ *
+ * Example: \include RealSchur_RealSchur_MatrixType.cpp
+ * Output: \verbinclude RealSchur_RealSchur_MatrixType.out
+ */
+ template<typename InputType>
+ explicit RealSchur(const EigenBase<InputType>& matrix, bool computeU = true)
+ : m_matT(matrix.rows(),matrix.cols()),
+ m_matU(matrix.rows(),matrix.cols()),
+ m_workspaceVector(matrix.rows()),
+ m_hess(matrix.rows()),
+ m_isInitialized(false),
+ m_matUisUptodate(false),
+ m_maxIters(-1)
+ {
+ compute(matrix.derived(), computeU);
+ }
+
+ /** \brief Returns the orthogonal matrix in the Schur decomposition.
+ *
+ * \returns A const reference to the matrix U.
+ *
+ * \pre Either the constructor RealSchur(const MatrixType&, bool) or the
+ * member function compute(const MatrixType&, bool) has been called before
+ * to compute the Schur decomposition of a matrix, and \p computeU was set
+ * to true (the default value).
+ *
+ * \sa RealSchur(const MatrixType&, bool) for an example
+ */
+ const MatrixType& matrixU() const
+ {
+ eigen_assert(m_isInitialized && "RealSchur is not initialized.");
+ eigen_assert(m_matUisUptodate && "The matrix U has not been computed during the RealSchur decomposition.");
+ return m_matU;
+ }
+
+ /** \brief Returns the quasi-triangular matrix in the Schur decomposition.
+ *
+ * \returns A const reference to the matrix T.
+ *
+ * \pre Either the constructor RealSchur(const MatrixType&, bool) or the
+ * member function compute(const MatrixType&, bool) has been called before
+ * to compute the Schur decomposition of a matrix.
+ *
+ * \sa RealSchur(const MatrixType&, bool) for an example
+ */
+ const MatrixType& matrixT() const
+ {
+ eigen_assert(m_isInitialized && "RealSchur is not initialized.");
+ return m_matT;
+ }
+
+ /** \brief Computes Schur decomposition of given matrix.
+ *
+ * \param[in] matrix Square matrix whose Schur decomposition is to be computed.
+ * \param[in] computeU If true, both T and U are computed; if false, only T is computed.
+ * \returns Reference to \c *this
+ *
+ * The Schur decomposition is computed by first reducing the matrix to
+ * Hessenberg form using the class HessenbergDecomposition. The Hessenberg
+ * matrix is then reduced to triangular form by performing Francis QR
+ * iterations with implicit double shift. The cost of computing the Schur
+ * decomposition depends on the number of iterations; as a rough guide, it
+ * may be taken to be \f$25n^3\f$ flops if \a computeU is true and
+ * \f$10n^3\f$ flops if \a computeU is false.
+ *
+ * Example: \include RealSchur_compute.cpp
+ * Output: \verbinclude RealSchur_compute.out
+ *
+ * \sa compute(const MatrixType&, bool, Index)
+ */
+ template<typename InputType>
+ RealSchur& compute(const EigenBase<InputType>& matrix, bool computeU = true);
+
+ /** \brief Computes Schur decomposition of a Hessenberg matrix H = Z T Z^T
+ * \param[in] matrixH Matrix in Hessenberg form H
+ * \param[in] matrixQ orthogonal matrix Q that transform a matrix A to H : A = Q H Q^T
+ * \param computeU Computes the matriX U of the Schur vectors
+ * \return Reference to \c *this
+ *
+ * This routine assumes that the matrix is already reduced in Hessenberg form matrixH
+ * using either the class HessenbergDecomposition or another mean.
+ * It computes the upper quasi-triangular matrix T of the Schur decomposition of H
+ * When computeU is true, this routine computes the matrix U such that
+ * A = U T U^T = (QZ) T (QZ)^T = Q H Q^T where A is the initial matrix
+ *
+ * NOTE Q is referenced if computeU is true; so, if the initial orthogonal matrix
+ * is not available, the user should give an identity matrix (Q.setIdentity())
+ *
+ * \sa compute(const MatrixType&, bool)
+ */
+ template<typename HessMatrixType, typename OrthMatrixType>
+ RealSchur& computeFromHessenberg(const HessMatrixType& matrixH, const OrthMatrixType& matrixQ, bool computeU);
+ /** \brief Reports whether previous computation was successful.
+ *
+ * \returns \c Success if computation was successful, \c NoConvergence otherwise.
+ */
+ ComputationInfo info() const
+ {
+ eigen_assert(m_isInitialized && "RealSchur is not initialized.");
+ return m_info;
+ }
+
+ /** \brief Sets the maximum number of iterations allowed.
+ *
+ * If not specified by the user, the maximum number of iterations is m_maxIterationsPerRow times the size
+ * of the matrix.
+ */
+ RealSchur& setMaxIterations(Index maxIters)
+ {
+ m_maxIters = maxIters;
+ return *this;
+ }
+
+ /** \brief Returns the maximum number of iterations. */
+ Index getMaxIterations()
+ {
+ return m_maxIters;
+ }
+
+ /** \brief Maximum number of iterations per row.
+ *
+ * If not otherwise specified, the maximum number of iterations is this number times the size of the
+ * matrix. It is currently set to 40.
+ */
+ static const int m_maxIterationsPerRow = 40;
+
+ private:
+
+ MatrixType m_matT;
+ MatrixType m_matU;
+ ColumnVectorType m_workspaceVector;
+ HessenbergDecomposition<MatrixType> m_hess;
+ ComputationInfo m_info;
+ bool m_isInitialized;
+ bool m_matUisUptodate;
+ Index m_maxIters;
+
+ typedef Matrix<Scalar,3,1> Vector3s;
+
+ Scalar computeNormOfT();
+ Index findSmallSubdiagEntry(Index iu, const Scalar& considerAsZero);
+ void splitOffTwoRows(Index iu, bool computeU, const Scalar& exshift);
+ void computeShift(Index iu, Index iter, Scalar& exshift, Vector3s& shiftInfo);
+ void initFrancisQRStep(Index il, Index iu, const Vector3s& shiftInfo, Index& im, Vector3s& firstHouseholderVector);
+ void performFrancisQRStep(Index il, Index im, Index iu, bool computeU, const Vector3s& firstHouseholderVector, Scalar* workspace);
+};
+
+
+template<typename MatrixType>
+template<typename InputType>
+RealSchur<MatrixType>& RealSchur<MatrixType>::compute(const EigenBase<InputType>& matrix, bool computeU)
+{
+ const Scalar considerAsZero = (std::numeric_limits<Scalar>::min)();
+
+ eigen_assert(matrix.cols() == matrix.rows());
+ Index maxIters = m_maxIters;
+ if (maxIters == -1)
+ maxIters = m_maxIterationsPerRow * matrix.rows();
+
+ Scalar scale = matrix.derived().cwiseAbs().maxCoeff();
+ if(scale<considerAsZero)
+ {
+ m_matT.setZero(matrix.rows(),matrix.cols());
+ if(computeU)
+ m_matU.setIdentity(matrix.rows(),matrix.cols());
+ m_info = Success;
+ m_isInitialized = true;
+ m_matUisUptodate = computeU;
+ return *this;
+ }
+
+ // Step 1. Reduce to Hessenberg form
+ m_hess.compute(matrix.derived()/scale);
+
+ // Step 2. Reduce to real Schur form
+ // Note: we copy m_hess.matrixQ() into m_matU here and not in computeFromHessenberg
+ // to be able to pass our working-space buffer for the Householder to Dense evaluation.
+ m_workspaceVector.resize(matrix.cols());
+ if(computeU)
+ m_hess.matrixQ().evalTo(m_matU, m_workspaceVector);
+ computeFromHessenberg(m_hess.matrixH(), m_matU, computeU);
+
+ m_matT *= scale;
+
+ return *this;
+}
+template<typename MatrixType>
+template<typename HessMatrixType, typename OrthMatrixType>
+RealSchur<MatrixType>& RealSchur<MatrixType>::computeFromHessenberg(const HessMatrixType& matrixH, const OrthMatrixType& matrixQ, bool computeU)
+{
+ using std::abs;
+
+ m_matT = matrixH;
+ m_workspaceVector.resize(m_matT.cols());
+ if(computeU && !internal::is_same_dense(m_matU,matrixQ))
+ m_matU = matrixQ;
+
+ Index maxIters = m_maxIters;
+ if (maxIters == -1)
+ maxIters = m_maxIterationsPerRow * matrixH.rows();
+ Scalar* workspace = &m_workspaceVector.coeffRef(0);
+
+ // The matrix m_matT is divided in three parts.
+ // Rows 0,...,il-1 are decoupled from the rest because m_matT(il,il-1) is zero.
+ // Rows il,...,iu is the part we are working on (the active window).
+ // Rows iu+1,...,end are already brought in triangular form.
+ Index iu = m_matT.cols() - 1;
+ Index iter = 0; // iteration count for current eigenvalue
+ Index totalIter = 0; // iteration count for whole matrix
+ Scalar exshift(0); // sum of exceptional shifts
+ Scalar norm = computeNormOfT();
+ // sub-diagonal entries smaller than considerAsZero will be treated as zero.
+ // We use eps^2 to enable more precision in small eigenvalues.
+ Scalar considerAsZero = numext::maxi<Scalar>( norm * numext::abs2(NumTraits<Scalar>::epsilon()),
+ (std::numeric_limits<Scalar>::min)() );
+
+ if(norm!=Scalar(0))
+ {
+ while (iu >= 0)
+ {
+ Index il = findSmallSubdiagEntry(iu,considerAsZero);
+
+ // Check for convergence
+ if (il == iu) // One root found
+ {
+ m_matT.coeffRef(iu,iu) = m_matT.coeff(iu,iu) + exshift;
+ if (iu > 0)
+ m_matT.coeffRef(iu, iu-1) = Scalar(0);
+ iu--;
+ iter = 0;
+ }
+ else if (il == iu-1) // Two roots found
+ {
+ splitOffTwoRows(iu, computeU, exshift);
+ iu -= 2;
+ iter = 0;
+ }
+ else // No convergence yet
+ {
+ // The firstHouseholderVector vector has to be initialized to something to get rid of a silly GCC warning (-O1 -Wall -DNDEBUG )
+ Vector3s firstHouseholderVector = Vector3s::Zero(), shiftInfo;
+ computeShift(iu, iter, exshift, shiftInfo);
+ iter = iter + 1;
+ totalIter = totalIter + 1;
+ if (totalIter > maxIters) break;
+ Index im;
+ initFrancisQRStep(il, iu, shiftInfo, im, firstHouseholderVector);
+ performFrancisQRStep(il, im, iu, computeU, firstHouseholderVector, workspace);
+ }
+ }
+ }
+ if(totalIter <= maxIters)
+ m_info = Success;
+ else
+ m_info = NoConvergence;
+
+ m_isInitialized = true;
+ m_matUisUptodate = computeU;
+ return *this;
+}
+
+/** \internal Computes and returns vector L1 norm of T */
+template<typename MatrixType>
+inline typename MatrixType::Scalar RealSchur<MatrixType>::computeNormOfT()
+{
+ const Index size = m_matT.cols();
+ // FIXME to be efficient the following would requires a triangular reduxion code
+ // Scalar norm = m_matT.upper().cwiseAbs().sum()
+ // + m_matT.bottomLeftCorner(size-1,size-1).diagonal().cwiseAbs().sum();
+ Scalar norm(0);
+ for (Index j = 0; j < size; ++j)
+ norm += m_matT.col(j).segment(0, (std::min)(size,j+2)).cwiseAbs().sum();
+ return norm;
+}
+
+/** \internal Look for single small sub-diagonal element and returns its index */
+template<typename MatrixType>
+inline Index RealSchur<MatrixType>::findSmallSubdiagEntry(Index iu, const Scalar& considerAsZero)
+{
+ using std::abs;
+ Index res = iu;
+ while (res > 0)
+ {
+ Scalar s = abs(m_matT.coeff(res-1,res-1)) + abs(m_matT.coeff(res,res));
+
+ s = numext::maxi<Scalar>(s * NumTraits<Scalar>::epsilon(), considerAsZero);
+
+ if (abs(m_matT.coeff(res,res-1)) <= s)
+ break;
+ res--;
+ }
+ return res;
+}
+
+/** \internal Update T given that rows iu-1 and iu decouple from the rest. */
+template<typename MatrixType>
+inline void RealSchur<MatrixType>::splitOffTwoRows(Index iu, bool computeU, const Scalar& exshift)
+{
+ using std::sqrt;
+ using std::abs;
+ const Index size = m_matT.cols();
+
+ // The eigenvalues of the 2x2 matrix [a b; c d] are
+ // trace +/- sqrt(discr/4) where discr = tr^2 - 4*det, tr = a + d, det = ad - bc
+ Scalar p = Scalar(0.5) * (m_matT.coeff(iu-1,iu-1) - m_matT.coeff(iu,iu));
+ Scalar q = p * p + m_matT.coeff(iu,iu-1) * m_matT.coeff(iu-1,iu); // q = tr^2 / 4 - det = discr/4
+ m_matT.coeffRef(iu,iu) += exshift;
+ m_matT.coeffRef(iu-1,iu-1) += exshift;
+
+ if (q >= Scalar(0)) // Two real eigenvalues
+ {
+ Scalar z = sqrt(abs(q));
+ JacobiRotation<Scalar> rot;
+ if (p >= Scalar(0))
+ rot.makeGivens(p + z, m_matT.coeff(iu, iu-1));
+ else
+ rot.makeGivens(p - z, m_matT.coeff(iu, iu-1));
+
+ m_matT.rightCols(size-iu+1).applyOnTheLeft(iu-1, iu, rot.adjoint());
+ m_matT.topRows(iu+1).applyOnTheRight(iu-1, iu, rot);
+ m_matT.coeffRef(iu, iu-1) = Scalar(0);
+ if (computeU)
+ m_matU.applyOnTheRight(iu-1, iu, rot);
+ }
+
+ if (iu > 1)
+ m_matT.coeffRef(iu-1, iu-2) = Scalar(0);
+}
+
+/** \internal Form shift in shiftInfo, and update exshift if an exceptional shift is performed. */
+template<typename MatrixType>
+inline void RealSchur<MatrixType>::computeShift(Index iu, Index iter, Scalar& exshift, Vector3s& shiftInfo)
+{
+ using std::sqrt;
+ using std::abs;
+ shiftInfo.coeffRef(0) = m_matT.coeff(iu,iu);
+ shiftInfo.coeffRef(1) = m_matT.coeff(iu-1,iu-1);
+ shiftInfo.coeffRef(2) = m_matT.coeff(iu,iu-1) * m_matT.coeff(iu-1,iu);
+
+ // Wilkinson's original ad hoc shift
+ if (iter == 10)
+ {
+ exshift += shiftInfo.coeff(0);
+ for (Index i = 0; i <= iu; ++i)
+ m_matT.coeffRef(i,i) -= shiftInfo.coeff(0);
+ Scalar s = abs(m_matT.coeff(iu,iu-1)) + abs(m_matT.coeff(iu-1,iu-2));
+ shiftInfo.coeffRef(0) = Scalar(0.75) * s;
+ shiftInfo.coeffRef(1) = Scalar(0.75) * s;
+ shiftInfo.coeffRef(2) = Scalar(-0.4375) * s * s;
+ }
+
+ // MATLAB's new ad hoc shift
+ if (iter == 30)
+ {
+ Scalar s = (shiftInfo.coeff(1) - shiftInfo.coeff(0)) / Scalar(2.0);
+ s = s * s + shiftInfo.coeff(2);
+ if (s > Scalar(0))
+ {
+ s = sqrt(s);
+ if (shiftInfo.coeff(1) < shiftInfo.coeff(0))
+ s = -s;
+ s = s + (shiftInfo.coeff(1) - shiftInfo.coeff(0)) / Scalar(2.0);
+ s = shiftInfo.coeff(0) - shiftInfo.coeff(2) / s;
+ exshift += s;
+ for (Index i = 0; i <= iu; ++i)
+ m_matT.coeffRef(i,i) -= s;
+ shiftInfo.setConstant(Scalar(0.964));
+ }
+ }
+}
+
+/** \internal Compute index im at which Francis QR step starts and the first Householder vector. */
+template<typename MatrixType>
+inline void RealSchur<MatrixType>::initFrancisQRStep(Index il, Index iu, const Vector3s& shiftInfo, Index& im, Vector3s& firstHouseholderVector)
+{
+ using std::abs;
+ Vector3s& v = firstHouseholderVector; // alias to save typing
+
+ for (im = iu-2; im >= il; --im)
+ {
+ const Scalar Tmm = m_matT.coeff(im,im);
+ const Scalar r = shiftInfo.coeff(0) - Tmm;
+ const Scalar s = shiftInfo.coeff(1) - Tmm;
+ v.coeffRef(0) = (r * s - shiftInfo.coeff(2)) / m_matT.coeff(im+1,im) + m_matT.coeff(im,im+1);
+ v.coeffRef(1) = m_matT.coeff(im+1,im+1) - Tmm - r - s;
+ v.coeffRef(2) = m_matT.coeff(im+2,im+1);
+ if (im == il) {
+ break;
+ }
+ const Scalar lhs = m_matT.coeff(im,im-1) * (abs(v.coeff(1)) + abs(v.coeff(2)));
+ const Scalar rhs = v.coeff(0) * (abs(m_matT.coeff(im-1,im-1)) + abs(Tmm) + abs(m_matT.coeff(im+1,im+1)));
+ if (abs(lhs) < NumTraits<Scalar>::epsilon() * rhs)
+ break;
+ }
+}
+
+/** \internal Perform a Francis QR step involving rows il:iu and columns im:iu. */
+template<typename MatrixType>
+inline void RealSchur<MatrixType>::performFrancisQRStep(Index il, Index im, Index iu, bool computeU, const Vector3s& firstHouseholderVector, Scalar* workspace)
+{
+ eigen_assert(im >= il);
+ eigen_assert(im <= iu-2);
+
+ const Index size = m_matT.cols();
+
+ for (Index k = im; k <= iu-2; ++k)
+ {
+ bool firstIteration = (k == im);
+
+ Vector3s v;
+ if (firstIteration)
+ v = firstHouseholderVector;
+ else
+ v = m_matT.template block<3,1>(k,k-1);
+
+ Scalar tau, beta;
+ Matrix<Scalar, 2, 1> ess;
+ v.makeHouseholder(ess, tau, beta);
+
+ if (beta != Scalar(0)) // if v is not zero
+ {
+ if (firstIteration && k > il)
+ m_matT.coeffRef(k,k-1) = -m_matT.coeff(k,k-1);
+ else if (!firstIteration)
+ m_matT.coeffRef(k,k-1) = beta;
+
+ // These Householder transformations form the O(n^3) part of the algorithm
+ m_matT.block(k, k, 3, size-k).applyHouseholderOnTheLeft(ess, tau, workspace);
+ m_matT.block(0, k, (std::min)(iu,k+3) + 1, 3).applyHouseholderOnTheRight(ess, tau, workspace);
+ if (computeU)
+ m_matU.block(0, k, size, 3).applyHouseholderOnTheRight(ess, tau, workspace);
+ }
+ }
+
+ Matrix<Scalar, 2, 1> v = m_matT.template block<2,1>(iu-1, iu-2);
+ Scalar tau, beta;
+ Matrix<Scalar, 1, 1> ess;
+ v.makeHouseholder(ess, tau, beta);
+
+ if (beta != Scalar(0)) // if v is not zero
+ {
+ m_matT.coeffRef(iu-1, iu-2) = beta;
+ m_matT.block(iu-1, iu-1, 2, size-iu+1).applyHouseholderOnTheLeft(ess, tau, workspace);
+ m_matT.block(0, iu-1, iu+1, 2).applyHouseholderOnTheRight(ess, tau, workspace);
+ if (computeU)
+ m_matU.block(0, iu-1, size, 2).applyHouseholderOnTheRight(ess, tau, workspace);
+ }
+
+ // clean up pollution due to round-off errors
+ for (Index i = im+2; i <= iu; ++i)
+ {
+ m_matT.coeffRef(i,i-2) = Scalar(0);
+ if (i > im+2)
+ m_matT.coeffRef(i,i-3) = Scalar(0);
+ }
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_REAL_SCHUR_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h
new file mode 100644
index 000000000..2c2251715
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h
@@ -0,0 +1,77 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to LAPACKe
+ * Real Schur needed to real unsymmetrical eigenvalues/eigenvectors.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_REAL_SCHUR_LAPACKE_H
+#define EIGEN_REAL_SCHUR_LAPACKE_H
+
+namespace Eigen {
+
+/** \internal Specialization for the data types supported by LAPACKe */
+
+#define EIGEN_LAPACKE_SCHUR_REAL(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX, LAPACKE_PREFIX_U, EIGCOLROW, LAPACKE_COLROW) \
+template<> template<typename InputType> inline \
+RealSchur<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >& \
+RealSchur<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >::compute(const EigenBase<InputType>& matrix, bool computeU) \
+{ \
+ eigen_assert(matrix.cols() == matrix.rows()); \
+\
+ lapack_int n = internal::convert_index<lapack_int>(matrix.cols()), sdim, info; \
+ lapack_int matrix_order = LAPACKE_COLROW; \
+ char jobvs, sort='N'; \
+ LAPACK_##LAPACKE_PREFIX_U##_SELECT2 select = 0; \
+ jobvs = (computeU) ? 'V' : 'N'; \
+ m_matU.resize(n, n); \
+ lapack_int ldvs = internal::convert_index<lapack_int>(m_matU.outerStride()); \
+ m_matT = matrix; \
+ lapack_int lda = internal::convert_index<lapack_int>(m_matT.outerStride()); \
+ Matrix<EIGTYPE, Dynamic, Dynamic> wr, wi; \
+ wr.resize(n, 1); wi.resize(n, 1); \
+ info = LAPACKE_##LAPACKE_PREFIX##gees( matrix_order, jobvs, sort, select, n, (LAPACKE_TYPE*)m_matT.data(), lda, &sdim, (LAPACKE_TYPE*)wr.data(), (LAPACKE_TYPE*)wi.data(), (LAPACKE_TYPE*)m_matU.data(), ldvs ); \
+ if(info == 0) \
+ m_info = Success; \
+ else \
+ m_info = NoConvergence; \
+\
+ m_isInitialized = true; \
+ m_matUisUptodate = computeU; \
+ return *this; \
+\
+}
+
+EIGEN_LAPACKE_SCHUR_REAL(double, double, d, D, ColMajor, LAPACK_COL_MAJOR)
+EIGEN_LAPACKE_SCHUR_REAL(float, float, s, S, ColMajor, LAPACK_COL_MAJOR)
+EIGEN_LAPACKE_SCHUR_REAL(double, double, d, D, RowMajor, LAPACK_ROW_MAJOR)
+EIGEN_LAPACKE_SCHUR_REAL(float, float, s, S, RowMajor, LAPACK_ROW_MAJOR)
+
+} // end namespace Eigen
+
+#endif // EIGEN_REAL_SCHUR_LAPACKE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h
new file mode 100644
index 000000000..14692365f
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h
@@ -0,0 +1,904 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SELFADJOINTEIGENSOLVER_H
+#define EIGEN_SELFADJOINTEIGENSOLVER_H
+
+#include "./Tridiagonalization.h"
+
+namespace Eigen {
+
+template<typename _MatrixType>
+class GeneralizedSelfAdjointEigenSolver;
+
+namespace internal {
+template<typename SolverType,int Size,bool IsComplex> struct direct_selfadjoint_eigenvalues;
+
+template<typename MatrixType, typename DiagType, typename SubDiagType>
+EIGEN_DEVICE_FUNC
+ComputationInfo computeFromTridiagonal_impl(DiagType& diag, SubDiagType& subdiag, const Index maxIterations, bool computeEigenvectors, MatrixType& eivec);
+}
+
+/** \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ *
+ * \class SelfAdjointEigenSolver
+ *
+ * \brief Computes eigenvalues and eigenvectors of selfadjoint matrices
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the
+ * eigendecomposition; this is expected to be an instantiation of the Matrix
+ * class template.
+ *
+ * A matrix \f$ A \f$ is selfadjoint if it equals its adjoint. For real
+ * matrices, this means that the matrix is symmetric: it equals its
+ * transpose. This class computes the eigenvalues and eigenvectors of a
+ * selfadjoint matrix. These are the scalars \f$ \lambda \f$ and vectors
+ * \f$ v \f$ such that \f$ Av = \lambda v \f$. The eigenvalues of a
+ * selfadjoint matrix are always real. If \f$ D \f$ is a diagonal matrix with
+ * the eigenvalues on the diagonal, and \f$ V \f$ is a matrix with the
+ * eigenvectors as its columns, then \f$ A = V D V^{-1} \f$. This is called the
+ * eigendecomposition.
+ *
+ * For a selfadjoint matrix, \f$ V \f$ is unitary, meaning its inverse is equal
+ * to its adjoint, \f$ V^{-1} = V^{\dagger} \f$. If \f$ A \f$ is real, then
+ * \f$ V \f$ is also real and therefore orthogonal, meaning its inverse is
+ * equal to its transpose, \f$ V^{-1} = V^T \f$.
+ *
+ * The algorithm exploits the fact that the matrix is selfadjoint, making it
+ * faster and more accurate than the general purpose eigenvalue algorithms
+ * implemented in EigenSolver and ComplexEigenSolver.
+ *
+ * Only the \b lower \b triangular \b part of the input matrix is referenced.
+ *
+ * Call the function compute() to compute the eigenvalues and eigenvectors of
+ * a given matrix. Alternatively, you can use the
+ * SelfAdjointEigenSolver(const MatrixType&, int) constructor which computes
+ * the eigenvalues and eigenvectors at construction time. Once the eigenvalue
+ * and eigenvectors are computed, they can be retrieved with the eigenvalues()
+ * and eigenvectors() functions.
+ *
+ * The documentation for SelfAdjointEigenSolver(const MatrixType&, int)
+ * contains an example of the typical use of this class.
+ *
+ * To solve the \em generalized eigenvalue problem \f$ Av = \lambda Bv \f$ and
+ * the likes, see the class GeneralizedSelfAdjointEigenSolver.
+ *
+ * \sa MatrixBase::eigenvalues(), class EigenSolver, class ComplexEigenSolver
+ */
+template<typename _MatrixType> class SelfAdjointEigenSolver
+{
+ public:
+
+ typedef _MatrixType MatrixType;
+ enum {
+ Size = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ Options = MatrixType::Options,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+
+ /** \brief Scalar type for matrices of type \p _MatrixType. */
+ typedef typename MatrixType::Scalar Scalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+
+ typedef Matrix<Scalar,Size,Size,ColMajor,MaxColsAtCompileTime,MaxColsAtCompileTime> EigenvectorsType;
+
+ /** \brief Real scalar type for \p _MatrixType.
+ *
+ * This is just \c Scalar if #Scalar is real (e.g., \c float or
+ * \c double), and the type of the real part of \c Scalar if #Scalar is
+ * complex.
+ */
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ friend struct internal::direct_selfadjoint_eigenvalues<SelfAdjointEigenSolver,Size,NumTraits<Scalar>::IsComplex>;
+
+ /** \brief Type for vector of eigenvalues as returned by eigenvalues().
+ *
+ * This is a column vector with entries of type #RealScalar.
+ * The length of the vector is the size of \p _MatrixType.
+ */
+ typedef typename internal::plain_col_type<MatrixType, RealScalar>::type RealVectorType;
+ typedef Tridiagonalization<MatrixType> TridiagonalizationType;
+ typedef typename TridiagonalizationType::SubDiagonalType SubDiagonalType;
+
+ /** \brief Default constructor for fixed-size matrices.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via compute(). This constructor
+ * can only be used if \p _MatrixType is a fixed-size matrix; use
+ * SelfAdjointEigenSolver(Index) for dynamic-size matrices.
+ *
+ * Example: \include SelfAdjointEigenSolver_SelfAdjointEigenSolver.cpp
+ * Output: \verbinclude SelfAdjointEigenSolver_SelfAdjointEigenSolver.out
+ */
+ EIGEN_DEVICE_FUNC
+ SelfAdjointEigenSolver()
+ : m_eivec(),
+ m_eivalues(),
+ m_subdiag(),
+ m_hcoeffs(),
+ m_info(InvalidInput),
+ m_isInitialized(false),
+ m_eigenvectorsOk(false)
+ { }
+
+ /** \brief Constructor, pre-allocates memory for dynamic-size matrices.
+ *
+ * \param [in] size Positive integer, size of the matrix whose
+ * eigenvalues and eigenvectors will be computed.
+ *
+ * This constructor is useful for dynamic-size matrices, when the user
+ * intends to perform decompositions via compute(). The \p size
+ * parameter is only used as a hint. It is not an error to give a wrong
+ * \p size, but it may impair performance.
+ *
+ * \sa compute() for an example
+ */
+ EIGEN_DEVICE_FUNC
+ explicit SelfAdjointEigenSolver(Index size)
+ : m_eivec(size, size),
+ m_eivalues(size),
+ m_subdiag(size > 1 ? size - 1 : 1),
+ m_hcoeffs(size > 1 ? size - 1 : 1),
+ m_isInitialized(false),
+ m_eigenvectorsOk(false)
+ {}
+
+ /** \brief Constructor; computes eigendecomposition of given matrix.
+ *
+ * \param[in] matrix Selfadjoint matrix whose eigendecomposition is to
+ * be computed. Only the lower triangular part of the matrix is referenced.
+ * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly.
+ *
+ * This constructor calls compute(const MatrixType&, int) to compute the
+ * eigenvalues of the matrix \p matrix. The eigenvectors are computed if
+ * \p options equals #ComputeEigenvectors.
+ *
+ * Example: \include SelfAdjointEigenSolver_SelfAdjointEigenSolver_MatrixType.cpp
+ * Output: \verbinclude SelfAdjointEigenSolver_SelfAdjointEigenSolver_MatrixType.out
+ *
+ * \sa compute(const MatrixType&, int)
+ */
+ template<typename InputType>
+ EIGEN_DEVICE_FUNC
+ explicit SelfAdjointEigenSolver(const EigenBase<InputType>& matrix, int options = ComputeEigenvectors)
+ : m_eivec(matrix.rows(), matrix.cols()),
+ m_eivalues(matrix.cols()),
+ m_subdiag(matrix.rows() > 1 ? matrix.rows() - 1 : 1),
+ m_hcoeffs(matrix.cols() > 1 ? matrix.cols() - 1 : 1),
+ m_isInitialized(false),
+ m_eigenvectorsOk(false)
+ {
+ compute(matrix.derived(), options);
+ }
+
+ /** \brief Computes eigendecomposition of given matrix.
+ *
+ * \param[in] matrix Selfadjoint matrix whose eigendecomposition is to
+ * be computed. Only the lower triangular part of the matrix is referenced.
+ * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly.
+ * \returns Reference to \c *this
+ *
+ * This function computes the eigenvalues of \p matrix. The eigenvalues()
+ * function can be used to retrieve them. If \p options equals #ComputeEigenvectors,
+ * then the eigenvectors are also computed and can be retrieved by
+ * calling eigenvectors().
+ *
+ * This implementation uses a symmetric QR algorithm. The matrix is first
+ * reduced to tridiagonal form using the Tridiagonalization class. The
+ * tridiagonal matrix is then brought to diagonal form with implicit
+ * symmetric QR steps with Wilkinson shift. Details can be found in
+ * Section 8.3 of Golub \& Van Loan, <i>%Matrix Computations</i>.
+ *
+ * The cost of the computation is about \f$ 9n^3 \f$ if the eigenvectors
+ * are required and \f$ 4n^3/3 \f$ if they are not required.
+ *
+ * This method reuses the memory in the SelfAdjointEigenSolver object that
+ * was allocated when the object was constructed, if the size of the
+ * matrix does not change.
+ *
+ * Example: \include SelfAdjointEigenSolver_compute_MatrixType.cpp
+ * Output: \verbinclude SelfAdjointEigenSolver_compute_MatrixType.out
+ *
+ * \sa SelfAdjointEigenSolver(const MatrixType&, int)
+ */
+ template<typename InputType>
+ EIGEN_DEVICE_FUNC
+ SelfAdjointEigenSolver& compute(const EigenBase<InputType>& matrix, int options = ComputeEigenvectors);
+
+ /** \brief Computes eigendecomposition of given matrix using a closed-form algorithm
+ *
+ * This is a variant of compute(const MatrixType&, int options) which
+ * directly solves the underlying polynomial equation.
+ *
+ * Currently only 2x2 and 3x3 matrices for which the sizes are known at compile time are supported (e.g., Matrix3d).
+ *
+ * This method is usually significantly faster than the QR iterative algorithm
+ * but it might also be less accurate. It is also worth noting that
+ * for 3x3 matrices it involves trigonometric operations which are
+ * not necessarily available for all scalar types.
+ *
+ * For the 3x3 case, we observed the following worst case relative error regarding the eigenvalues:
+ * - double: 1e-8
+ * - float: 1e-3
+ *
+ * \sa compute(const MatrixType&, int options)
+ */
+ EIGEN_DEVICE_FUNC
+ SelfAdjointEigenSolver& computeDirect(const MatrixType& matrix, int options = ComputeEigenvectors);
+
+ /**
+ *\brief Computes the eigen decomposition from a tridiagonal symmetric matrix
+ *
+ * \param[in] diag The vector containing the diagonal of the matrix.
+ * \param[in] subdiag The subdiagonal of the matrix.
+ * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly.
+ * \returns Reference to \c *this
+ *
+ * This function assumes that the matrix has been reduced to tridiagonal form.
+ *
+ * \sa compute(const MatrixType&, int) for more information
+ */
+ SelfAdjointEigenSolver& computeFromTridiagonal(const RealVectorType& diag, const SubDiagonalType& subdiag , int options=ComputeEigenvectors);
+
+ /** \brief Returns the eigenvectors of given matrix.
+ *
+ * \returns A const reference to the matrix whose columns are the eigenvectors.
+ *
+ * \pre The eigenvectors have been computed before.
+ *
+ * Column \f$ k \f$ of the returned matrix is an eigenvector corresponding
+ * to eigenvalue number \f$ k \f$ as returned by eigenvalues(). The
+ * eigenvectors are normalized to have (Euclidean) norm equal to one. If
+ * this object was used to solve the eigenproblem for the selfadjoint
+ * matrix \f$ A \f$, then the matrix returned by this function is the
+ * matrix \f$ V \f$ in the eigendecomposition \f$ A = V D V^{-1} \f$.
+ *
+ * For a selfadjoint matrix, \f$ V \f$ is unitary, meaning its inverse is equal
+ * to its adjoint, \f$ V^{-1} = V^{\dagger} \f$. If \f$ A \f$ is real, then
+ * \f$ V \f$ is also real and therefore orthogonal, meaning its inverse is
+ * equal to its transpose, \f$ V^{-1} = V^T \f$.
+ *
+ * Example: \include SelfAdjointEigenSolver_eigenvectors.cpp
+ * Output: \verbinclude SelfAdjointEigenSolver_eigenvectors.out
+ *
+ * \sa eigenvalues()
+ */
+ EIGEN_DEVICE_FUNC
+ const EigenvectorsType& eigenvectors() const
+ {
+ eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
+ eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
+ return m_eivec;
+ }
+
+ /** \brief Returns the eigenvalues of given matrix.
+ *
+ * \returns A const reference to the column vector containing the eigenvalues.
+ *
+ * \pre The eigenvalues have been computed before.
+ *
+ * The eigenvalues are repeated according to their algebraic multiplicity,
+ * so there are as many eigenvalues as rows in the matrix. The eigenvalues
+ * are sorted in increasing order.
+ *
+ * Example: \include SelfAdjointEigenSolver_eigenvalues.cpp
+ * Output: \verbinclude SelfAdjointEigenSolver_eigenvalues.out
+ *
+ * \sa eigenvectors(), MatrixBase::eigenvalues()
+ */
+ EIGEN_DEVICE_FUNC
+ const RealVectorType& eigenvalues() const
+ {
+ eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
+ return m_eivalues;
+ }
+
+ /** \brief Computes the positive-definite square root of the matrix.
+ *
+ * \returns the positive-definite square root of the matrix
+ *
+ * \pre The eigenvalues and eigenvectors of a positive-definite matrix
+ * have been computed before.
+ *
+ * The square root of a positive-definite matrix \f$ A \f$ is the
+ * positive-definite matrix whose square equals \f$ A \f$. This function
+ * uses the eigendecomposition \f$ A = V D V^{-1} \f$ to compute the
+ * square root as \f$ A^{1/2} = V D^{1/2} V^{-1} \f$.
+ *
+ * Example: \include SelfAdjointEigenSolver_operatorSqrt.cpp
+ * Output: \verbinclude SelfAdjointEigenSolver_operatorSqrt.out
+ *
+ * \sa operatorInverseSqrt(), <a href="unsupported/group__MatrixFunctions__Module.html">MatrixFunctions Module</a>
+ */
+ EIGEN_DEVICE_FUNC
+ MatrixType operatorSqrt() const
+ {
+ eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
+ eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
+ return m_eivec * m_eivalues.cwiseSqrt().asDiagonal() * m_eivec.adjoint();
+ }
+
+ /** \brief Computes the inverse square root of the matrix.
+ *
+ * \returns the inverse positive-definite square root of the matrix
+ *
+ * \pre The eigenvalues and eigenvectors of a positive-definite matrix
+ * have been computed before.
+ *
+ * This function uses the eigendecomposition \f$ A = V D V^{-1} \f$ to
+ * compute the inverse square root as \f$ V D^{-1/2} V^{-1} \f$. This is
+ * cheaper than first computing the square root with operatorSqrt() and
+ * then its inverse with MatrixBase::inverse().
+ *
+ * Example: \include SelfAdjointEigenSolver_operatorInverseSqrt.cpp
+ * Output: \verbinclude SelfAdjointEigenSolver_operatorInverseSqrt.out
+ *
+ * \sa operatorSqrt(), MatrixBase::inverse(), <a href="unsupported/group__MatrixFunctions__Module.html">MatrixFunctions Module</a>
+ */
+ EIGEN_DEVICE_FUNC
+ MatrixType operatorInverseSqrt() const
+ {
+ eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
+ eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
+ return m_eivec * m_eivalues.cwiseInverse().cwiseSqrt().asDiagonal() * m_eivec.adjoint();
+ }
+
+ /** \brief Reports whether previous computation was successful.
+ *
+ * \returns \c Success if computation was successful, \c NoConvergence otherwise.
+ */
+ EIGEN_DEVICE_FUNC
+ ComputationInfo info() const
+ {
+ eigen_assert(m_isInitialized && "SelfAdjointEigenSolver is not initialized.");
+ return m_info;
+ }
+
+ /** \brief Maximum number of iterations.
+ *
+ * The algorithm terminates if it does not converge within m_maxIterations * n iterations, where n
+ * denotes the size of the matrix. This value is currently set to 30 (copied from LAPACK).
+ */
+ static const int m_maxIterations = 30;
+
+ protected:
+ static EIGEN_DEVICE_FUNC
+ void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ }
+
+ EigenvectorsType m_eivec;
+ RealVectorType m_eivalues;
+ typename TridiagonalizationType::SubDiagonalType m_subdiag;
+ typename TridiagonalizationType::CoeffVectorType m_hcoeffs;
+ ComputationInfo m_info;
+ bool m_isInitialized;
+ bool m_eigenvectorsOk;
+};
+
+namespace internal {
+/** \internal
+ *
+ * \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ * Performs a QR step on a tridiagonal symmetric matrix represented as a
+ * pair of two vectors \a diag and \a subdiag.
+ *
+ * \param diag the diagonal part of the input selfadjoint tridiagonal matrix
+ * \param subdiag the sub-diagonal part of the input selfadjoint tridiagonal matrix
+ * \param start starting index of the submatrix to work on
+ * \param end last+1 index of the submatrix to work on
+ * \param matrixQ pointer to the column-major matrix holding the eigenvectors, can be 0
+ * \param n size of the input matrix
+ *
+ * For compilation efficiency reasons, this procedure does not use eigen expression
+ * for its arguments.
+ *
+ * Implemented from Golub's "Matrix Computations", algorithm 8.3.2:
+ * "implicit symmetric QR step with Wilkinson shift"
+ */
+template<int StorageOrder,typename RealScalar, typename Scalar, typename Index>
+EIGEN_DEVICE_FUNC
+static void tridiagonal_qr_step(RealScalar* diag, RealScalar* subdiag, Index start, Index end, Scalar* matrixQ, Index n);
+}
+
+template<typename MatrixType>
+template<typename InputType>
+EIGEN_DEVICE_FUNC
+SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType>
+::compute(const EigenBase<InputType>& a_matrix, int options)
+{
+ check_template_parameters();
+
+ const InputType &matrix(a_matrix.derived());
+
+ EIGEN_USING_STD(abs);
+ eigen_assert(matrix.cols() == matrix.rows());
+ eigen_assert((options&~(EigVecMask|GenEigMask))==0
+ && (options&EigVecMask)!=EigVecMask
+ && "invalid option parameter");
+ bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors;
+ Index n = matrix.cols();
+ m_eivalues.resize(n,1);
+
+ if(n==1)
+ {
+ m_eivec = matrix;
+ m_eivalues.coeffRef(0,0) = numext::real(m_eivec.coeff(0,0));
+ if(computeEigenvectors)
+ m_eivec.setOnes(n,n);
+ m_info = Success;
+ m_isInitialized = true;
+ m_eigenvectorsOk = computeEigenvectors;
+ return *this;
+ }
+
+ // declare some aliases
+ RealVectorType& diag = m_eivalues;
+ EigenvectorsType& mat = m_eivec;
+
+ // map the matrix coefficients to [-1:1] to avoid over- and underflow.
+ mat = matrix.template triangularView<Lower>();
+ RealScalar scale = mat.cwiseAbs().maxCoeff();
+ if(scale==RealScalar(0)) scale = RealScalar(1);
+ mat.template triangularView<Lower>() /= scale;
+ m_subdiag.resize(n-1);
+ m_hcoeffs.resize(n-1);
+ internal::tridiagonalization_inplace(mat, diag, m_subdiag, m_hcoeffs, computeEigenvectors);
+
+ m_info = internal::computeFromTridiagonal_impl(diag, m_subdiag, m_maxIterations, computeEigenvectors, m_eivec);
+
+ // scale back the eigen values
+ m_eivalues *= scale;
+
+ m_isInitialized = true;
+ m_eigenvectorsOk = computeEigenvectors;
+ return *this;
+}
+
+template<typename MatrixType>
+SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType>
+::computeFromTridiagonal(const RealVectorType& diag, const SubDiagonalType& subdiag , int options)
+{
+ //TODO : Add an option to scale the values beforehand
+ bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors;
+
+ m_eivalues = diag;
+ m_subdiag = subdiag;
+ if (computeEigenvectors)
+ {
+ m_eivec.setIdentity(diag.size(), diag.size());
+ }
+ m_info = internal::computeFromTridiagonal_impl(m_eivalues, m_subdiag, m_maxIterations, computeEigenvectors, m_eivec);
+
+ m_isInitialized = true;
+ m_eigenvectorsOk = computeEigenvectors;
+ return *this;
+}
+
+namespace internal {
+/**
+ * \internal
+ * \brief Compute the eigendecomposition from a tridiagonal matrix
+ *
+ * \param[in,out] diag : On input, the diagonal of the matrix, on output the eigenvalues
+ * \param[in,out] subdiag : The subdiagonal part of the matrix (entries are modified during the decomposition)
+ * \param[in] maxIterations : the maximum number of iterations
+ * \param[in] computeEigenvectors : whether the eigenvectors have to be computed or not
+ * \param[out] eivec : The matrix to store the eigenvectors if computeEigenvectors==true. Must be allocated on input.
+ * \returns \c Success or \c NoConvergence
+ */
+template<typename MatrixType, typename DiagType, typename SubDiagType>
+EIGEN_DEVICE_FUNC
+ComputationInfo computeFromTridiagonal_impl(DiagType& diag, SubDiagType& subdiag, const Index maxIterations, bool computeEigenvectors, MatrixType& eivec)
+{
+ ComputationInfo info;
+ typedef typename MatrixType::Scalar Scalar;
+
+ Index n = diag.size();
+ Index end = n-1;
+ Index start = 0;
+ Index iter = 0; // total number of iterations
+
+ typedef typename DiagType::RealScalar RealScalar;
+ const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)();
+ const RealScalar precision_inv = RealScalar(1)/NumTraits<RealScalar>::epsilon();
+ while (end>0)
+ {
+ for (Index i = start; i<end; ++i) {
+ if (numext::abs(subdiag[i]) < considerAsZero) {
+ subdiag[i] = RealScalar(0);
+ } else {
+ // abs(subdiag[i]) <= epsilon * sqrt(abs(diag[i]) + abs(diag[i+1]))
+ // Scaled to prevent underflows.
+ const RealScalar scaled_subdiag = precision_inv * subdiag[i];
+ if (scaled_subdiag * scaled_subdiag <= (numext::abs(diag[i])+numext::abs(diag[i+1]))) {
+ subdiag[i] = RealScalar(0);
+ }
+ }
+ }
+
+ // find the largest unreduced block at the end of the matrix.
+ while (end>0 && subdiag[end-1]==RealScalar(0))
+ {
+ end--;
+ }
+ if (end<=0)
+ break;
+
+ // if we spent too many iterations, we give up
+ iter++;
+ if(iter > maxIterations * n) break;
+
+ start = end - 1;
+ while (start>0 && subdiag[start-1]!=0)
+ start--;
+
+ internal::tridiagonal_qr_step<MatrixType::Flags&RowMajorBit ? RowMajor : ColMajor>(diag.data(), subdiag.data(), start, end, computeEigenvectors ? eivec.data() : (Scalar*)0, n);
+ }
+ if (iter <= maxIterations * n)
+ info = Success;
+ else
+ info = NoConvergence;
+
+ // Sort eigenvalues and corresponding vectors.
+ // TODO make the sort optional ?
+ // TODO use a better sort algorithm !!
+ if (info == Success)
+ {
+ for (Index i = 0; i < n-1; ++i)
+ {
+ Index k;
+ diag.segment(i,n-i).minCoeff(&k);
+ if (k > 0)
+ {
+ numext::swap(diag[i], diag[k+i]);
+ if(computeEigenvectors)
+ eivec.col(i).swap(eivec.col(k+i));
+ }
+ }
+ }
+ return info;
+}
+
+template<typename SolverType,int Size,bool IsComplex> struct direct_selfadjoint_eigenvalues
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(SolverType& eig, const typename SolverType::MatrixType& A, int options)
+ { eig.compute(A,options); }
+};
+
+template<typename SolverType> struct direct_selfadjoint_eigenvalues<SolverType,3,false>
+{
+ typedef typename SolverType::MatrixType MatrixType;
+ typedef typename SolverType::RealVectorType VectorType;
+ typedef typename SolverType::Scalar Scalar;
+ typedef typename SolverType::EigenvectorsType EigenvectorsType;
+
+
+ /** \internal
+ * Computes the roots of the characteristic polynomial of \a m.
+ * For numerical stability m.trace() should be near zero and to avoid over- or underflow m should be normalized.
+ */
+ EIGEN_DEVICE_FUNC
+ static inline void computeRoots(const MatrixType& m, VectorType& roots)
+ {
+ EIGEN_USING_STD(sqrt)
+ EIGEN_USING_STD(atan2)
+ EIGEN_USING_STD(cos)
+ EIGEN_USING_STD(sin)
+ const Scalar s_inv3 = Scalar(1)/Scalar(3);
+ const Scalar s_sqrt3 = sqrt(Scalar(3));
+
+ // The characteristic equation is x^3 - c2*x^2 + c1*x - c0 = 0. The
+ // eigenvalues are the roots to this equation, all guaranteed to be
+ // real-valued, because the matrix is symmetric.
+ Scalar c0 = m(0,0)*m(1,1)*m(2,2) + Scalar(2)*m(1,0)*m(2,0)*m(2,1) - m(0,0)*m(2,1)*m(2,1) - m(1,1)*m(2,0)*m(2,0) - m(2,2)*m(1,0)*m(1,0);
+ Scalar c1 = m(0,0)*m(1,1) - m(1,0)*m(1,0) + m(0,0)*m(2,2) - m(2,0)*m(2,0) + m(1,1)*m(2,2) - m(2,1)*m(2,1);
+ Scalar c2 = m(0,0) + m(1,1) + m(2,2);
+
+ // Construct the parameters used in classifying the roots of the equation
+ // and in solving the equation for the roots in closed form.
+ Scalar c2_over_3 = c2*s_inv3;
+ Scalar a_over_3 = (c2*c2_over_3 - c1)*s_inv3;
+ a_over_3 = numext::maxi(a_over_3, Scalar(0));
+
+ Scalar half_b = Scalar(0.5)*(c0 + c2_over_3*(Scalar(2)*c2_over_3*c2_over_3 - c1));
+
+ Scalar q = a_over_3*a_over_3*a_over_3 - half_b*half_b;
+ q = numext::maxi(q, Scalar(0));
+
+ // Compute the eigenvalues by solving for the roots of the polynomial.
+ Scalar rho = sqrt(a_over_3);
+ Scalar theta = atan2(sqrt(q),half_b)*s_inv3; // since sqrt(q) > 0, atan2 is in [0, pi] and theta is in [0, pi/3]
+ Scalar cos_theta = cos(theta);
+ Scalar sin_theta = sin(theta);
+ // roots are already sorted, since cos is monotonically decreasing on [0, pi]
+ roots(0) = c2_over_3 - rho*(cos_theta + s_sqrt3*sin_theta); // == 2*rho*cos(theta+2pi/3)
+ roots(1) = c2_over_3 - rho*(cos_theta - s_sqrt3*sin_theta); // == 2*rho*cos(theta+ pi/3)
+ roots(2) = c2_over_3 + Scalar(2)*rho*cos_theta;
+ }
+
+ EIGEN_DEVICE_FUNC
+ static inline bool extract_kernel(MatrixType& mat, Ref<VectorType> res, Ref<VectorType> representative)
+ {
+ EIGEN_USING_STD(abs);
+ EIGEN_USING_STD(sqrt);
+ Index i0;
+ // Find non-zero column i0 (by construction, there must exist a non zero coefficient on the diagonal):
+ mat.diagonal().cwiseAbs().maxCoeff(&i0);
+ // mat.col(i0) is a good candidate for an orthogonal vector to the current eigenvector,
+ // so let's save it:
+ representative = mat.col(i0);
+ Scalar n0, n1;
+ VectorType c0, c1;
+ n0 = (c0 = representative.cross(mat.col((i0+1)%3))).squaredNorm();
+ n1 = (c1 = representative.cross(mat.col((i0+2)%3))).squaredNorm();
+ if(n0>n1) res = c0/sqrt(n0);
+ else res = c1/sqrt(n1);
+
+ return true;
+ }
+
+ EIGEN_DEVICE_FUNC
+ static inline void run(SolverType& solver, const MatrixType& mat, int options)
+ {
+ eigen_assert(mat.cols() == 3 && mat.cols() == mat.rows());
+ eigen_assert((options&~(EigVecMask|GenEigMask))==0
+ && (options&EigVecMask)!=EigVecMask
+ && "invalid option parameter");
+ bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors;
+
+ EigenvectorsType& eivecs = solver.m_eivec;
+ VectorType& eivals = solver.m_eivalues;
+
+ // Shift the matrix to the mean eigenvalue and map the matrix coefficients to [-1:1] to avoid over- and underflow.
+ Scalar shift = mat.trace() / Scalar(3);
+ // TODO Avoid this copy. Currently it is necessary to suppress bogus values when determining maxCoeff and for computing the eigenvectors later
+ MatrixType scaledMat = mat.template selfadjointView<Lower>();
+ scaledMat.diagonal().array() -= shift;
+ Scalar scale = scaledMat.cwiseAbs().maxCoeff();
+ if(scale > 0) scaledMat /= scale; // TODO for scale==0 we could save the remaining operations
+
+ // compute the eigenvalues
+ computeRoots(scaledMat,eivals);
+
+ // compute the eigenvectors
+ if(computeEigenvectors)
+ {
+ if((eivals(2)-eivals(0))<=Eigen::NumTraits<Scalar>::epsilon())
+ {
+ // All three eigenvalues are numerically the same
+ eivecs.setIdentity();
+ }
+ else
+ {
+ MatrixType tmp;
+ tmp = scaledMat;
+
+ // Compute the eigenvector of the most distinct eigenvalue
+ Scalar d0 = eivals(2) - eivals(1);
+ Scalar d1 = eivals(1) - eivals(0);
+ Index k(0), l(2);
+ if(d0 > d1)
+ {
+ numext::swap(k,l);
+ d0 = d1;
+ }
+
+ // Compute the eigenvector of index k
+ {
+ tmp.diagonal().array () -= eivals(k);
+ // By construction, 'tmp' is of rank 2, and its kernel corresponds to the respective eigenvector.
+ extract_kernel(tmp, eivecs.col(k), eivecs.col(l));
+ }
+
+ // Compute eigenvector of index l
+ if(d0<=2*Eigen::NumTraits<Scalar>::epsilon()*d1)
+ {
+ // If d0 is too small, then the two other eigenvalues are numerically the same,
+ // and thus we only have to ortho-normalize the near orthogonal vector we saved above.
+ eivecs.col(l) -= eivecs.col(k).dot(eivecs.col(l))*eivecs.col(l);
+ eivecs.col(l).normalize();
+ }
+ else
+ {
+ tmp = scaledMat;
+ tmp.diagonal().array () -= eivals(l);
+
+ VectorType dummy;
+ extract_kernel(tmp, eivecs.col(l), dummy);
+ }
+
+ // Compute last eigenvector from the other two
+ eivecs.col(1) = eivecs.col(2).cross(eivecs.col(0)).normalized();
+ }
+ }
+
+ // Rescale back to the original size.
+ eivals *= scale;
+ eivals.array() += shift;
+
+ solver.m_info = Success;
+ solver.m_isInitialized = true;
+ solver.m_eigenvectorsOk = computeEigenvectors;
+ }
+};
+
+// 2x2 direct eigenvalues decomposition, code from Hauke Heibel
+template<typename SolverType>
+struct direct_selfadjoint_eigenvalues<SolverType,2,false>
+{
+ typedef typename SolverType::MatrixType MatrixType;
+ typedef typename SolverType::RealVectorType VectorType;
+ typedef typename SolverType::Scalar Scalar;
+ typedef typename SolverType::EigenvectorsType EigenvectorsType;
+
+ EIGEN_DEVICE_FUNC
+ static inline void computeRoots(const MatrixType& m, VectorType& roots)
+ {
+ EIGEN_USING_STD(sqrt);
+ const Scalar t0 = Scalar(0.5) * sqrt( numext::abs2(m(0,0)-m(1,1)) + Scalar(4)*numext::abs2(m(1,0)));
+ const Scalar t1 = Scalar(0.5) * (m(0,0) + m(1,1));
+ roots(0) = t1 - t0;
+ roots(1) = t1 + t0;
+ }
+
+ EIGEN_DEVICE_FUNC
+ static inline void run(SolverType& solver, const MatrixType& mat, int options)
+ {
+ EIGEN_USING_STD(sqrt);
+ EIGEN_USING_STD(abs);
+
+ eigen_assert(mat.cols() == 2 && mat.cols() == mat.rows());
+ eigen_assert((options&~(EigVecMask|GenEigMask))==0
+ && (options&EigVecMask)!=EigVecMask
+ && "invalid option parameter");
+ bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors;
+
+ EigenvectorsType& eivecs = solver.m_eivec;
+ VectorType& eivals = solver.m_eivalues;
+
+ // Shift the matrix to the mean eigenvalue and map the matrix coefficients to [-1:1] to avoid over- and underflow.
+ Scalar shift = mat.trace() / Scalar(2);
+ MatrixType scaledMat = mat;
+ scaledMat.coeffRef(0,1) = mat.coeff(1,0);
+ scaledMat.diagonal().array() -= shift;
+ Scalar scale = scaledMat.cwiseAbs().maxCoeff();
+ if(scale > Scalar(0))
+ scaledMat /= scale;
+
+ // Compute the eigenvalues
+ computeRoots(scaledMat,eivals);
+
+ // compute the eigen vectors
+ if(computeEigenvectors)
+ {
+ if((eivals(1)-eivals(0))<=abs(eivals(1))*Eigen::NumTraits<Scalar>::epsilon())
+ {
+ eivecs.setIdentity();
+ }
+ else
+ {
+ scaledMat.diagonal().array () -= eivals(1);
+ Scalar a2 = numext::abs2(scaledMat(0,0));
+ Scalar c2 = numext::abs2(scaledMat(1,1));
+ Scalar b2 = numext::abs2(scaledMat(1,0));
+ if(a2>c2)
+ {
+ eivecs.col(1) << -scaledMat(1,0), scaledMat(0,0);
+ eivecs.col(1) /= sqrt(a2+b2);
+ }
+ else
+ {
+ eivecs.col(1) << -scaledMat(1,1), scaledMat(1,0);
+ eivecs.col(1) /= sqrt(c2+b2);
+ }
+
+ eivecs.col(0) << eivecs.col(1).unitOrthogonal();
+ }
+ }
+
+ // Rescale back to the original size.
+ eivals *= scale;
+ eivals.array() += shift;
+
+ solver.m_info = Success;
+ solver.m_isInitialized = true;
+ solver.m_eigenvectorsOk = computeEigenvectors;
+ }
+};
+
+}
+
+template<typename MatrixType>
+EIGEN_DEVICE_FUNC
+SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType>
+::computeDirect(const MatrixType& matrix, int options)
+{
+ internal::direct_selfadjoint_eigenvalues<SelfAdjointEigenSolver,Size,NumTraits<Scalar>::IsComplex>::run(*this,matrix,options);
+ return *this;
+}
+
+namespace internal {
+
+// Francis implicit QR step.
+template<int StorageOrder,typename RealScalar, typename Scalar, typename Index>
+EIGEN_DEVICE_FUNC
+static void tridiagonal_qr_step(RealScalar* diag, RealScalar* subdiag, Index start, Index end, Scalar* matrixQ, Index n)
+{
+ // Wilkinson Shift.
+ RealScalar td = (diag[end-1] - diag[end])*RealScalar(0.5);
+ RealScalar e = subdiag[end-1];
+ // Note that thanks to scaling, e^2 or td^2 cannot overflow, however they can still
+ // underflow thus leading to inf/NaN values when using the following commented code:
+ // RealScalar e2 = numext::abs2(subdiag[end-1]);
+ // RealScalar mu = diag[end] - e2 / (td + (td>0 ? 1 : -1) * sqrt(td*td + e2));
+ // This explain the following, somewhat more complicated, version:
+ RealScalar mu = diag[end];
+ if(td==RealScalar(0)) {
+ mu -= numext::abs(e);
+ } else if (e != RealScalar(0)) {
+ const RealScalar e2 = numext::abs2(e);
+ const RealScalar h = numext::hypot(td,e);
+ if(e2 == RealScalar(0)) {
+ mu -= e / ((td + (td>RealScalar(0) ? h : -h)) / e);
+ } else {
+ mu -= e2 / (td + (td>RealScalar(0) ? h : -h));
+ }
+ }
+
+ RealScalar x = diag[start] - mu;
+ RealScalar z = subdiag[start];
+ // If z ever becomes zero, the Givens rotation will be the identity and
+ // z will stay zero for all future iterations.
+ for (Index k = start; k < end && z != RealScalar(0); ++k)
+ {
+ JacobiRotation<RealScalar> rot;
+ rot.makeGivens(x, z);
+
+ // do T = G' T G
+ RealScalar sdk = rot.s() * diag[k] + rot.c() * subdiag[k];
+ RealScalar dkp1 = rot.s() * subdiag[k] + rot.c() * diag[k+1];
+
+ diag[k] = rot.c() * (rot.c() * diag[k] - rot.s() * subdiag[k]) - rot.s() * (rot.c() * subdiag[k] - rot.s() * diag[k+1]);
+ diag[k+1] = rot.s() * sdk + rot.c() * dkp1;
+ subdiag[k] = rot.c() * sdk - rot.s() * dkp1;
+
+ if (k > start)
+ subdiag[k - 1] = rot.c() * subdiag[k-1] - rot.s() * z;
+
+ // "Chasing the bulge" to return to triangular form.
+ x = subdiag[k];
+ if (k < end - 1)
+ {
+ z = -rot.s() * subdiag[k+1];
+ subdiag[k + 1] = rot.c() * subdiag[k+1];
+ }
+
+ // apply the givens rotation to the unit matrix Q = Q * G
+ if (matrixQ)
+ {
+ // FIXME if StorageOrder == RowMajor this operation is not very efficient
+ Map<Matrix<Scalar,Dynamic,Dynamic,StorageOrder> > q(matrixQ,n,n);
+ q.applyOnTheRight(k,k+1,rot);
+ }
+ }
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_SELFADJOINTEIGENSOLVER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h
new file mode 100644
index 000000000..b0c947dc0
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h
@@ -0,0 +1,87 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to LAPACKe
+ * Self-adjoint eigenvalues/eigenvectors.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_SAEIGENSOLVER_LAPACKE_H
+#define EIGEN_SAEIGENSOLVER_LAPACKE_H
+
+namespace Eigen {
+
+/** \internal Specialization for the data types supported by LAPACKe */
+
+#define EIGEN_LAPACKE_EIG_SELFADJ_2(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_NAME, EIGCOLROW ) \
+template<> template<typename InputType> inline \
+SelfAdjointEigenSolver<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >& \
+SelfAdjointEigenSolver<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >::compute(const EigenBase<InputType>& matrix, int options) \
+{ \
+ eigen_assert(matrix.cols() == matrix.rows()); \
+ eigen_assert((options&~(EigVecMask|GenEigMask))==0 \
+ && (options&EigVecMask)!=EigVecMask \
+ && "invalid option parameter"); \
+ bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors; \
+ lapack_int n = internal::convert_index<lapack_int>(matrix.cols()), lda, info; \
+ m_eivalues.resize(n,1); \
+ m_subdiag.resize(n-1); \
+ m_eivec = matrix; \
+\
+ if(n==1) \
+ { \
+ m_eivalues.coeffRef(0,0) = numext::real(m_eivec.coeff(0,0)); \
+ if(computeEigenvectors) m_eivec.setOnes(n,n); \
+ m_info = Success; \
+ m_isInitialized = true; \
+ m_eigenvectorsOk = computeEigenvectors; \
+ return *this; \
+ } \
+\
+ lda = internal::convert_index<lapack_int>(m_eivec.outerStride()); \
+ char jobz, uplo='L'/*, range='A'*/; \
+ jobz = computeEigenvectors ? 'V' : 'N'; \
+\
+ info = LAPACKE_##LAPACKE_NAME( LAPACK_COL_MAJOR, jobz, uplo, n, (LAPACKE_TYPE*)m_eivec.data(), lda, (LAPACKE_RTYPE*)m_eivalues.data() ); \
+ m_info = (info==0) ? Success : NoConvergence; \
+ m_isInitialized = true; \
+ m_eigenvectorsOk = computeEigenvectors; \
+ return *this; \
+}
+
+#define EIGEN_LAPACKE_EIG_SELFADJ(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_NAME ) \
+ EIGEN_LAPACKE_EIG_SELFADJ_2(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_NAME, ColMajor ) \
+ EIGEN_LAPACKE_EIG_SELFADJ_2(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_NAME, RowMajor )
+
+EIGEN_LAPACKE_EIG_SELFADJ(double, double, double, dsyev)
+EIGEN_LAPACKE_EIG_SELFADJ(float, float, float, ssyev)
+EIGEN_LAPACKE_EIG_SELFADJ(dcomplex, lapack_complex_double, double, zheev)
+EIGEN_LAPACKE_EIG_SELFADJ(scomplex, lapack_complex_float, float, cheev)
+
+} // end namespace Eigen
+
+#endif // EIGEN_SAEIGENSOLVER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Eigenvalues/Tridiagonalization.h b/src/3rdparty/eigen/Eigen/src/Eigenvalues/Tridiagonalization.h
new file mode 100644
index 000000000..674c92a39
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Eigenvalues/Tridiagonalization.h
@@ -0,0 +1,561 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TRIDIAGONALIZATION_H
+#define EIGEN_TRIDIAGONALIZATION_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename MatrixType> struct TridiagonalizationMatrixTReturnType;
+template<typename MatrixType>
+struct traits<TridiagonalizationMatrixTReturnType<MatrixType> >
+ : public traits<typename MatrixType::PlainObject>
+{
+ typedef typename MatrixType::PlainObject ReturnType; // FIXME shall it be a BandMatrix?
+ enum { Flags = 0 };
+};
+
+template<typename MatrixType, typename CoeffVectorType>
+EIGEN_DEVICE_FUNC
+void tridiagonalization_inplace(MatrixType& matA, CoeffVectorType& hCoeffs);
+}
+
+/** \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ *
+ * \class Tridiagonalization
+ *
+ * \brief Tridiagonal decomposition of a selfadjoint matrix
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the
+ * tridiagonal decomposition; this is expected to be an instantiation of the
+ * Matrix class template.
+ *
+ * This class performs a tridiagonal decomposition of a selfadjoint matrix \f$ A \f$ such that:
+ * \f$ A = Q T Q^* \f$ where \f$ Q \f$ is unitary and \f$ T \f$ a real symmetric tridiagonal matrix.
+ *
+ * A tridiagonal matrix is a matrix which has nonzero elements only on the
+ * main diagonal and the first diagonal below and above it. The Hessenberg
+ * decomposition of a selfadjoint matrix is in fact a tridiagonal
+ * decomposition. This class is used in SelfAdjointEigenSolver to compute the
+ * eigenvalues and eigenvectors of a selfadjoint matrix.
+ *
+ * Call the function compute() to compute the tridiagonal decomposition of a
+ * given matrix. Alternatively, you can use the Tridiagonalization(const MatrixType&)
+ * constructor which computes the tridiagonal Schur decomposition at
+ * construction time. Once the decomposition is computed, you can use the
+ * matrixQ() and matrixT() functions to retrieve the matrices Q and T in the
+ * decomposition.
+ *
+ * The documentation of Tridiagonalization(const MatrixType&) contains an
+ * example of the typical use of this class.
+ *
+ * \sa class HessenbergDecomposition, class SelfAdjointEigenSolver
+ */
+template<typename _MatrixType> class Tridiagonalization
+{
+ public:
+
+ /** \brief Synonym for the template parameter \p _MatrixType. */
+ typedef _MatrixType MatrixType;
+
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+
+ enum {
+ Size = MatrixType::RowsAtCompileTime,
+ SizeMinusOne = Size == Dynamic ? Dynamic : (Size > 1 ? Size - 1 : 1),
+ Options = MatrixType::Options,
+ MaxSize = MatrixType::MaxRowsAtCompileTime,
+ MaxSizeMinusOne = MaxSize == Dynamic ? Dynamic : (MaxSize > 1 ? MaxSize - 1 : 1)
+ };
+
+ typedef Matrix<Scalar, SizeMinusOne, 1, Options & ~RowMajor, MaxSizeMinusOne, 1> CoeffVectorType;
+ typedef typename internal::plain_col_type<MatrixType, RealScalar>::type DiagonalType;
+ typedef Matrix<RealScalar, SizeMinusOne, 1, Options & ~RowMajor, MaxSizeMinusOne, 1> SubDiagonalType;
+ typedef typename internal::remove_all<typename MatrixType::RealReturnType>::type MatrixTypeRealView;
+ typedef internal::TridiagonalizationMatrixTReturnType<MatrixTypeRealView> MatrixTReturnType;
+
+ typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
+ typename internal::add_const_on_value_type<typename Diagonal<const MatrixType>::RealReturnType>::type,
+ const Diagonal<const MatrixType>
+ >::type DiagonalReturnType;
+
+ typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
+ typename internal::add_const_on_value_type<typename Diagonal<const MatrixType, -1>::RealReturnType>::type,
+ const Diagonal<const MatrixType, -1>
+ >::type SubDiagonalReturnType;
+
+ /** \brief Return type of matrixQ() */
+ typedef HouseholderSequence<MatrixType,typename internal::remove_all<typename CoeffVectorType::ConjugateReturnType>::type> HouseholderSequenceType;
+
+ /** \brief Default constructor.
+ *
+ * \param [in] size Positive integer, size of the matrix whose tridiagonal
+ * decomposition will be computed.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via compute(). The \p size parameter is only
+ * used as a hint. It is not an error to give a wrong \p size, but it may
+ * impair performance.
+ *
+ * \sa compute() for an example.
+ */
+ explicit Tridiagonalization(Index size = Size==Dynamic ? 2 : Size)
+ : m_matrix(size,size),
+ m_hCoeffs(size > 1 ? size-1 : 1),
+ m_isInitialized(false)
+ {}
+
+ /** \brief Constructor; computes tridiagonal decomposition of given matrix.
+ *
+ * \param[in] matrix Selfadjoint matrix whose tridiagonal decomposition
+ * is to be computed.
+ *
+ * This constructor calls compute() to compute the tridiagonal decomposition.
+ *
+ * Example: \include Tridiagonalization_Tridiagonalization_MatrixType.cpp
+ * Output: \verbinclude Tridiagonalization_Tridiagonalization_MatrixType.out
+ */
+ template<typename InputType>
+ explicit Tridiagonalization(const EigenBase<InputType>& matrix)
+ : m_matrix(matrix.derived()),
+ m_hCoeffs(matrix.cols() > 1 ? matrix.cols()-1 : 1),
+ m_isInitialized(false)
+ {
+ internal::tridiagonalization_inplace(m_matrix, m_hCoeffs);
+ m_isInitialized = true;
+ }
+
+ /** \brief Computes tridiagonal decomposition of given matrix.
+ *
+ * \param[in] matrix Selfadjoint matrix whose tridiagonal decomposition
+ * is to be computed.
+ * \returns Reference to \c *this
+ *
+ * The tridiagonal decomposition is computed by bringing the columns of
+ * the matrix successively in the required form using Householder
+ * reflections. The cost is \f$ 4n^3/3 \f$ flops, where \f$ n \f$ denotes
+ * the size of the given matrix.
+ *
+ * This method reuses of the allocated data in the Tridiagonalization
+ * object, if the size of the matrix does not change.
+ *
+ * Example: \include Tridiagonalization_compute.cpp
+ * Output: \verbinclude Tridiagonalization_compute.out
+ */
+ template<typename InputType>
+ Tridiagonalization& compute(const EigenBase<InputType>& matrix)
+ {
+ m_matrix = matrix.derived();
+ m_hCoeffs.resize(matrix.rows()-1, 1);
+ internal::tridiagonalization_inplace(m_matrix, m_hCoeffs);
+ m_isInitialized = true;
+ return *this;
+ }
+
+ /** \brief Returns the Householder coefficients.
+ *
+ * \returns a const reference to the vector of Householder coefficients
+ *
+ * \pre Either the constructor Tridiagonalization(const MatrixType&) or
+ * the member function compute(const MatrixType&) has been called before
+ * to compute the tridiagonal decomposition of a matrix.
+ *
+ * The Householder coefficients allow the reconstruction of the matrix
+ * \f$ Q \f$ in the tridiagonal decomposition from the packed data.
+ *
+ * Example: \include Tridiagonalization_householderCoefficients.cpp
+ * Output: \verbinclude Tridiagonalization_householderCoefficients.out
+ *
+ * \sa packedMatrix(), \ref Householder_Module "Householder module"
+ */
+ inline CoeffVectorType householderCoefficients() const
+ {
+ eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
+ return m_hCoeffs;
+ }
+
+ /** \brief Returns the internal representation of the decomposition
+ *
+ * \returns a const reference to a matrix with the internal representation
+ * of the decomposition.
+ *
+ * \pre Either the constructor Tridiagonalization(const MatrixType&) or
+ * the member function compute(const MatrixType&) has been called before
+ * to compute the tridiagonal decomposition of a matrix.
+ *
+ * The returned matrix contains the following information:
+ * - the strict upper triangular part is equal to the input matrix A.
+ * - the diagonal and lower sub-diagonal represent the real tridiagonal
+ * symmetric matrix T.
+ * - the rest of the lower part contains the Householder vectors that,
+ * combined with Householder coefficients returned by
+ * householderCoefficients(), allows to reconstruct the matrix Q as
+ * \f$ Q = H_{N-1} \ldots H_1 H_0 \f$.
+ * Here, the matrices \f$ H_i \f$ are the Householder transformations
+ * \f$ H_i = (I - h_i v_i v_i^T) \f$
+ * where \f$ h_i \f$ is the \f$ i \f$th Householder coefficient and
+ * \f$ v_i \f$ is the Householder vector defined by
+ * \f$ v_i = [ 0, \ldots, 0, 1, M(i+2,i), \ldots, M(N-1,i) ]^T \f$
+ * with M the matrix returned by this function.
+ *
+ * See LAPACK for further details on this packed storage.
+ *
+ * Example: \include Tridiagonalization_packedMatrix.cpp
+ * Output: \verbinclude Tridiagonalization_packedMatrix.out
+ *
+ * \sa householderCoefficients()
+ */
+ inline const MatrixType& packedMatrix() const
+ {
+ eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
+ return m_matrix;
+ }
+
+ /** \brief Returns the unitary matrix Q in the decomposition
+ *
+ * \returns object representing the matrix Q
+ *
+ * \pre Either the constructor Tridiagonalization(const MatrixType&) or
+ * the member function compute(const MatrixType&) has been called before
+ * to compute the tridiagonal decomposition of a matrix.
+ *
+ * This function returns a light-weight object of template class
+ * HouseholderSequence. You can either apply it directly to a matrix or
+ * you can convert it to a matrix of type #MatrixType.
+ *
+ * \sa Tridiagonalization(const MatrixType&) for an example,
+ * matrixT(), class HouseholderSequence
+ */
+ HouseholderSequenceType matrixQ() const
+ {
+ eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
+ return HouseholderSequenceType(m_matrix, m_hCoeffs.conjugate())
+ .setLength(m_matrix.rows() - 1)
+ .setShift(1);
+ }
+
+ /** \brief Returns an expression of the tridiagonal matrix T in the decomposition
+ *
+ * \returns expression object representing the matrix T
+ *
+ * \pre Either the constructor Tridiagonalization(const MatrixType&) or
+ * the member function compute(const MatrixType&) has been called before
+ * to compute the tridiagonal decomposition of a matrix.
+ *
+ * Currently, this function can be used to extract the matrix T from internal
+ * data and copy it to a dense matrix object. In most cases, it may be
+ * sufficient to directly use the packed matrix or the vector expressions
+ * returned by diagonal() and subDiagonal() instead of creating a new
+ * dense copy matrix with this function.
+ *
+ * \sa Tridiagonalization(const MatrixType&) for an example,
+ * matrixQ(), packedMatrix(), diagonal(), subDiagonal()
+ */
+ MatrixTReturnType matrixT() const
+ {
+ eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
+ return MatrixTReturnType(m_matrix.real());
+ }
+
+ /** \brief Returns the diagonal of the tridiagonal matrix T in the decomposition.
+ *
+ * \returns expression representing the diagonal of T
+ *
+ * \pre Either the constructor Tridiagonalization(const MatrixType&) or
+ * the member function compute(const MatrixType&) has been called before
+ * to compute the tridiagonal decomposition of a matrix.
+ *
+ * Example: \include Tridiagonalization_diagonal.cpp
+ * Output: \verbinclude Tridiagonalization_diagonal.out
+ *
+ * \sa matrixT(), subDiagonal()
+ */
+ DiagonalReturnType diagonal() const;
+
+ /** \brief Returns the subdiagonal of the tridiagonal matrix T in the decomposition.
+ *
+ * \returns expression representing the subdiagonal of T
+ *
+ * \pre Either the constructor Tridiagonalization(const MatrixType&) or
+ * the member function compute(const MatrixType&) has been called before
+ * to compute the tridiagonal decomposition of a matrix.
+ *
+ * \sa diagonal() for an example, matrixT()
+ */
+ SubDiagonalReturnType subDiagonal() const;
+
+ protected:
+
+ MatrixType m_matrix;
+ CoeffVectorType m_hCoeffs;
+ bool m_isInitialized;
+};
+
+template<typename MatrixType>
+typename Tridiagonalization<MatrixType>::DiagonalReturnType
+Tridiagonalization<MatrixType>::diagonal() const
+{
+ eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
+ return m_matrix.diagonal().real();
+}
+
+template<typename MatrixType>
+typename Tridiagonalization<MatrixType>::SubDiagonalReturnType
+Tridiagonalization<MatrixType>::subDiagonal() const
+{
+ eigen_assert(m_isInitialized && "Tridiagonalization is not initialized.");
+ return m_matrix.template diagonal<-1>().real();
+}
+
+namespace internal {
+
+/** \internal
+ * Performs a tridiagonal decomposition of the selfadjoint matrix \a matA in-place.
+ *
+ * \param[in,out] matA On input the selfadjoint matrix. Only the \b lower triangular part is referenced.
+ * On output, the strict upper part is left unchanged, and the lower triangular part
+ * represents the T and Q matrices in packed format has detailed below.
+ * \param[out] hCoeffs returned Householder coefficients (see below)
+ *
+ * On output, the tridiagonal selfadjoint matrix T is stored in the diagonal
+ * and lower sub-diagonal of the matrix \a matA.
+ * The unitary matrix Q is represented in a compact way as a product of
+ * Householder reflectors \f$ H_i \f$ such that:
+ * \f$ Q = H_{N-1} \ldots H_1 H_0 \f$.
+ * The Householder reflectors are defined as
+ * \f$ H_i = (I - h_i v_i v_i^T) \f$
+ * where \f$ h_i = hCoeffs[i]\f$ is the \f$ i \f$th Householder coefficient and
+ * \f$ v_i \f$ is the Householder vector defined by
+ * \f$ v_i = [ 0, \ldots, 0, 1, matA(i+2,i), \ldots, matA(N-1,i) ]^T \f$.
+ *
+ * Implemented from Golub's "Matrix Computations", algorithm 8.3.1.
+ *
+ * \sa Tridiagonalization::packedMatrix()
+ */
+template<typename MatrixType, typename CoeffVectorType>
+EIGEN_DEVICE_FUNC
+void tridiagonalization_inplace(MatrixType& matA, CoeffVectorType& hCoeffs)
+{
+ using numext::conj;
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename MatrixType::RealScalar RealScalar;
+ Index n = matA.rows();
+ eigen_assert(n==matA.cols());
+ eigen_assert(n==hCoeffs.size()+1 || n==1);
+
+ for (Index i = 0; i<n-1; ++i)
+ {
+ Index remainingSize = n-i-1;
+ RealScalar beta;
+ Scalar h;
+ matA.col(i).tail(remainingSize).makeHouseholderInPlace(h, beta);
+
+ // Apply similarity transformation to remaining columns,
+ // i.e., A = H A H' where H = I - h v v' and v = matA.col(i).tail(n-i-1)
+ matA.col(i).coeffRef(i+1) = 1;
+
+ hCoeffs.tail(n-i-1).noalias() = (matA.bottomRightCorner(remainingSize,remainingSize).template selfadjointView<Lower>()
+ * (conj(h) * matA.col(i).tail(remainingSize)));
+
+ hCoeffs.tail(n-i-1) += (conj(h)*RealScalar(-0.5)*(hCoeffs.tail(remainingSize).dot(matA.col(i).tail(remainingSize)))) * matA.col(i).tail(n-i-1);
+
+ matA.bottomRightCorner(remainingSize, remainingSize).template selfadjointView<Lower>()
+ .rankUpdate(matA.col(i).tail(remainingSize), hCoeffs.tail(remainingSize), Scalar(-1));
+
+ matA.col(i).coeffRef(i+1) = beta;
+ hCoeffs.coeffRef(i) = h;
+ }
+}
+
+// forward declaration, implementation at the end of this file
+template<typename MatrixType,
+ int Size=MatrixType::ColsAtCompileTime,
+ bool IsComplex=NumTraits<typename MatrixType::Scalar>::IsComplex>
+struct tridiagonalization_inplace_selector;
+
+/** \brief Performs a full tridiagonalization in place
+ *
+ * \param[in,out] mat On input, the selfadjoint matrix whose tridiagonal
+ * decomposition is to be computed. Only the lower triangular part referenced.
+ * The rest is left unchanged. On output, the orthogonal matrix Q
+ * in the decomposition if \p extractQ is true.
+ * \param[out] diag The diagonal of the tridiagonal matrix T in the
+ * decomposition.
+ * \param[out] subdiag The subdiagonal of the tridiagonal matrix T in
+ * the decomposition.
+ * \param[in] extractQ If true, the orthogonal matrix Q in the
+ * decomposition is computed and stored in \p mat.
+ *
+ * Computes the tridiagonal decomposition of the selfadjoint matrix \p mat in place
+ * such that \f$ mat = Q T Q^* \f$ where \f$ Q \f$ is unitary and \f$ T \f$ a real
+ * symmetric tridiagonal matrix.
+ *
+ * The tridiagonal matrix T is passed to the output parameters \p diag and \p subdiag. If
+ * \p extractQ is true, then the orthogonal matrix Q is passed to \p mat. Otherwise the lower
+ * part of the matrix \p mat is destroyed.
+ *
+ * The vectors \p diag and \p subdiag are not resized. The function
+ * assumes that they are already of the correct size. The length of the
+ * vector \p diag should equal the number of rows in \p mat, and the
+ * length of the vector \p subdiag should be one left.
+ *
+ * This implementation contains an optimized path for 3-by-3 matrices
+ * which is especially useful for plane fitting.
+ *
+ * \note Currently, it requires two temporary vectors to hold the intermediate
+ * Householder coefficients, and to reconstruct the matrix Q from the Householder
+ * reflectors.
+ *
+ * Example (this uses the same matrix as the example in
+ * Tridiagonalization::Tridiagonalization(const MatrixType&)):
+ * \include Tridiagonalization_decomposeInPlace.cpp
+ * Output: \verbinclude Tridiagonalization_decomposeInPlace.out
+ *
+ * \sa class Tridiagonalization
+ */
+template<typename MatrixType, typename DiagonalType, typename SubDiagonalType, typename CoeffVectorType>
+EIGEN_DEVICE_FUNC
+void tridiagonalization_inplace(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag,
+ CoeffVectorType& hcoeffs, bool extractQ)
+{
+ eigen_assert(mat.cols()==mat.rows() && diag.size()==mat.rows() && subdiag.size()==mat.rows()-1);
+ tridiagonalization_inplace_selector<MatrixType>::run(mat, diag, subdiag, hcoeffs, extractQ);
+}
+
+/** \internal
+ * General full tridiagonalization
+ */
+template<typename MatrixType, int Size, bool IsComplex>
+struct tridiagonalization_inplace_selector
+{
+ typedef typename Tridiagonalization<MatrixType>::CoeffVectorType CoeffVectorType;
+ typedef typename Tridiagonalization<MatrixType>::HouseholderSequenceType HouseholderSequenceType;
+ template<typename DiagonalType, typename SubDiagonalType>
+ static EIGEN_DEVICE_FUNC
+ void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag, CoeffVectorType& hCoeffs, bool extractQ)
+ {
+ tridiagonalization_inplace(mat, hCoeffs);
+ diag = mat.diagonal().real();
+ subdiag = mat.template diagonal<-1>().real();
+ if(extractQ)
+ mat = HouseholderSequenceType(mat, hCoeffs.conjugate())
+ .setLength(mat.rows() - 1)
+ .setShift(1);
+ }
+};
+
+/** \internal
+ * Specialization for 3x3 real matrices.
+ * Especially useful for plane fitting.
+ */
+template<typename MatrixType>
+struct tridiagonalization_inplace_selector<MatrixType,3,false>
+{
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename MatrixType::RealScalar RealScalar;
+
+ template<typename DiagonalType, typename SubDiagonalType, typename CoeffVectorType>
+ static void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType& subdiag, CoeffVectorType&, bool extractQ)
+ {
+ using std::sqrt;
+ const RealScalar tol = (std::numeric_limits<RealScalar>::min)();
+ diag[0] = mat(0,0);
+ RealScalar v1norm2 = numext::abs2(mat(2,0));
+ if(v1norm2 <= tol)
+ {
+ diag[1] = mat(1,1);
+ diag[2] = mat(2,2);
+ subdiag[0] = mat(1,0);
+ subdiag[1] = mat(2,1);
+ if (extractQ)
+ mat.setIdentity();
+ }
+ else
+ {
+ RealScalar beta = sqrt(numext::abs2(mat(1,0)) + v1norm2);
+ RealScalar invBeta = RealScalar(1)/beta;
+ Scalar m01 = mat(1,0) * invBeta;
+ Scalar m02 = mat(2,0) * invBeta;
+ Scalar q = RealScalar(2)*m01*mat(2,1) + m02*(mat(2,2) - mat(1,1));
+ diag[1] = mat(1,1) + m02*q;
+ diag[2] = mat(2,2) - m02*q;
+ subdiag[0] = beta;
+ subdiag[1] = mat(2,1) - m01 * q;
+ if (extractQ)
+ {
+ mat << 1, 0, 0,
+ 0, m01, m02,
+ 0, m02, -m01;
+ }
+ }
+ }
+};
+
+/** \internal
+ * Trivial specialization for 1x1 matrices
+ */
+template<typename MatrixType, bool IsComplex>
+struct tridiagonalization_inplace_selector<MatrixType,1,IsComplex>
+{
+ typedef typename MatrixType::Scalar Scalar;
+
+ template<typename DiagonalType, typename SubDiagonalType, typename CoeffVectorType>
+ static EIGEN_DEVICE_FUNC
+ void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType&, CoeffVectorType&, bool extractQ)
+ {
+ diag(0,0) = numext::real(mat(0,0));
+ if(extractQ)
+ mat(0,0) = Scalar(1);
+ }
+};
+
+/** \internal
+ * \eigenvalues_module \ingroup Eigenvalues_Module
+ *
+ * \brief Expression type for return value of Tridiagonalization::matrixT()
+ *
+ * \tparam MatrixType type of underlying dense matrix
+ */
+template<typename MatrixType> struct TridiagonalizationMatrixTReturnType
+: public ReturnByValue<TridiagonalizationMatrixTReturnType<MatrixType> >
+{
+ public:
+ /** \brief Constructor.
+ *
+ * \param[in] mat The underlying dense matrix
+ */
+ TridiagonalizationMatrixTReturnType(const MatrixType& mat) : m_matrix(mat) { }
+
+ template <typename ResultType>
+ inline void evalTo(ResultType& result) const
+ {
+ result.setZero();
+ result.template diagonal<1>() = m_matrix.template diagonal<-1>().conjugate();
+ result.diagonal() = m_matrix.diagonal();
+ result.template diagonal<-1>() = m_matrix.template diagonal<-1>();
+ }
+
+ EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
+ EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
+
+ protected:
+ typename MatrixType::Nested m_matrix;
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRIDIAGONALIZATION_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/AlignedBox.h b/src/3rdparty/eigen/Eigen/src/Geometry/AlignedBox.h
new file mode 100644
index 000000000..55a9d0ae1
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/AlignedBox.h
@@ -0,0 +1,486 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+// Function void Eigen::AlignedBox::transform(const Transform& transform)
+// is provided under the following license agreement:
+//
+// Software License Agreement (BSD License)
+//
+// Copyright (c) 2011-2014, Willow Garage, Inc.
+// Copyright (c) 2014-2015, Open Source Robotics Foundation
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Open Source Robotics Foundation nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef EIGEN_ALIGNEDBOX_H
+#define EIGEN_ALIGNEDBOX_H
+
+namespace Eigen {
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ *
+ * \class AlignedBox
+ *
+ * \brief An axis aligned box
+ *
+ * \tparam _Scalar the type of the scalar coefficients
+ * \tparam _AmbientDim the dimension of the ambient space, can be a compile time value or Dynamic.
+ *
+ * This class represents an axis aligned box as a pair of the minimal and maximal corners.
+ * \warning The result of most methods is undefined when applied to an empty box. You can check for empty boxes using isEmpty().
+ * \sa alignedboxtypedefs
+ */
+template <typename _Scalar, int _AmbientDim>
+class AlignedBox
+{
+public:
+EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim)
+ enum { AmbientDimAtCompileTime = _AmbientDim };
+ typedef _Scalar Scalar;
+ typedef NumTraits<Scalar> ScalarTraits;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+ typedef typename ScalarTraits::Real RealScalar;
+ typedef typename ScalarTraits::NonInteger NonInteger;
+ typedef Matrix<Scalar,AmbientDimAtCompileTime,1> VectorType;
+ typedef CwiseBinaryOp<internal::scalar_sum_op<Scalar>, const VectorType, const VectorType> VectorTypeSum;
+
+ /** Define constants to name the corners of a 1D, 2D or 3D axis aligned bounding box */
+ enum CornerType
+ {
+ /** 1D names @{ */
+ Min=0, Max=1,
+ /** @} */
+
+ /** Identifier for 2D corner @{ */
+ BottomLeft=0, BottomRight=1,
+ TopLeft=2, TopRight=3,
+ /** @} */
+
+ /** Identifier for 3D corner @{ */
+ BottomLeftFloor=0, BottomRightFloor=1,
+ TopLeftFloor=2, TopRightFloor=3,
+ BottomLeftCeil=4, BottomRightCeil=5,
+ TopLeftCeil=6, TopRightCeil=7
+ /** @} */
+ };
+
+
+ /** Default constructor initializing a null box. */
+ EIGEN_DEVICE_FUNC inline AlignedBox()
+ { if (EIGEN_CONST_CONDITIONAL(AmbientDimAtCompileTime!=Dynamic)) setEmpty(); }
+
+ /** Constructs a null box with \a _dim the dimension of the ambient space. */
+ EIGEN_DEVICE_FUNC inline explicit AlignedBox(Index _dim) : m_min(_dim), m_max(_dim)
+ { setEmpty(); }
+
+ /** Constructs a box with extremities \a _min and \a _max.
+ * \warning If either component of \a _min is larger than the same component of \a _max, the constructed box is empty. */
+ template<typename OtherVectorType1, typename OtherVectorType2>
+ EIGEN_DEVICE_FUNC inline AlignedBox(const OtherVectorType1& _min, const OtherVectorType2& _max) : m_min(_min), m_max(_max) {}
+
+ /** Constructs a box containing a single point \a p. */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline explicit AlignedBox(const MatrixBase<Derived>& p) : m_min(p), m_max(m_min)
+ { }
+
+ EIGEN_DEVICE_FUNC ~AlignedBox() {}
+
+ /** \returns the dimension in which the box holds */
+ EIGEN_DEVICE_FUNC inline Index dim() const { return AmbientDimAtCompileTime==Dynamic ? m_min.size() : Index(AmbientDimAtCompileTime); }
+
+ /** \deprecated use isEmpty() */
+ EIGEN_DEVICE_FUNC inline bool isNull() const { return isEmpty(); }
+
+ /** \deprecated use setEmpty() */
+ EIGEN_DEVICE_FUNC inline void setNull() { setEmpty(); }
+
+ /** \returns true if the box is empty.
+ * \sa setEmpty */
+ EIGEN_DEVICE_FUNC inline bool isEmpty() const { return (m_min.array() > m_max.array()).any(); }
+
+ /** Makes \c *this an empty box.
+ * \sa isEmpty */
+ EIGEN_DEVICE_FUNC inline void setEmpty()
+ {
+ m_min.setConstant( ScalarTraits::highest() );
+ m_max.setConstant( ScalarTraits::lowest() );
+ }
+
+ /** \returns the minimal corner */
+ EIGEN_DEVICE_FUNC inline const VectorType& (min)() const { return m_min; }
+ /** \returns a non const reference to the minimal corner */
+ EIGEN_DEVICE_FUNC inline VectorType& (min)() { return m_min; }
+ /** \returns the maximal corner */
+ EIGEN_DEVICE_FUNC inline const VectorType& (max)() const { return m_max; }
+ /** \returns a non const reference to the maximal corner */
+ EIGEN_DEVICE_FUNC inline VectorType& (max)() { return m_max; }
+
+ /** \returns the center of the box */
+ EIGEN_DEVICE_FUNC inline const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(VectorTypeSum, RealScalar, quotient)
+ center() const
+ { return (m_min+m_max)/RealScalar(2); }
+
+ /** \returns the lengths of the sides of the bounding box.
+ * Note that this function does not get the same
+ * result for integral or floating scalar types: see
+ */
+ EIGEN_DEVICE_FUNC inline const CwiseBinaryOp< internal::scalar_difference_op<Scalar,Scalar>, const VectorType, const VectorType> sizes() const
+ { return m_max - m_min; }
+
+ /** \returns the volume of the bounding box */
+ EIGEN_DEVICE_FUNC inline Scalar volume() const
+ { return sizes().prod(); }
+
+ /** \returns an expression for the bounding box diagonal vector
+ * if the length of the diagonal is needed: diagonal().norm()
+ * will provide it.
+ */
+ EIGEN_DEVICE_FUNC inline CwiseBinaryOp< internal::scalar_difference_op<Scalar,Scalar>, const VectorType, const VectorType> diagonal() const
+ { return sizes(); }
+
+ /** \returns the vertex of the bounding box at the corner defined by
+ * the corner-id corner. It works only for a 1D, 2D or 3D bounding box.
+ * For 1D bounding boxes corners are named by 2 enum constants:
+ * BottomLeft and BottomRight.
+ * For 2D bounding boxes, corners are named by 4 enum constants:
+ * BottomLeft, BottomRight, TopLeft, TopRight.
+ * For 3D bounding boxes, the following names are added:
+ * BottomLeftCeil, BottomRightCeil, TopLeftCeil, TopRightCeil.
+ */
+ EIGEN_DEVICE_FUNC inline VectorType corner(CornerType corner) const
+ {
+ EIGEN_STATIC_ASSERT(_AmbientDim <= 3, THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE);
+
+ VectorType res;
+
+ Index mult = 1;
+ for(Index d=0; d<dim(); ++d)
+ {
+ if( mult & corner ) res[d] = m_max[d];
+ else res[d] = m_min[d];
+ mult *= 2;
+ }
+ return res;
+ }
+
+ /** \returns a random point inside the bounding box sampled with
+ * a uniform distribution */
+ EIGEN_DEVICE_FUNC inline VectorType sample() const
+ {
+ VectorType r(dim());
+ for(Index d=0; d<dim(); ++d)
+ {
+ if(!ScalarTraits::IsInteger)
+ {
+ r[d] = m_min[d] + (m_max[d]-m_min[d])
+ * internal::random<Scalar>(Scalar(0), Scalar(1));
+ }
+ else
+ r[d] = internal::random(m_min[d], m_max[d]);
+ }
+ return r;
+ }
+
+ /** \returns true if the point \a p is inside the box \c *this. */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline bool contains(const MatrixBase<Derived>& p) const
+ {
+ typename internal::nested_eval<Derived,2>::type p_n(p.derived());
+ return (m_min.array()<=p_n.array()).all() && (p_n.array()<=m_max.array()).all();
+ }
+
+ /** \returns true if the box \a b is entirely inside the box \c *this. */
+ EIGEN_DEVICE_FUNC inline bool contains(const AlignedBox& b) const
+ { return (m_min.array()<=(b.min)().array()).all() && ((b.max)().array()<=m_max.array()).all(); }
+
+ /** \returns true if the box \a b is intersecting the box \c *this.
+ * \sa intersection, clamp */
+ EIGEN_DEVICE_FUNC inline bool intersects(const AlignedBox& b) const
+ { return (m_min.array()<=(b.max)().array()).all() && ((b.min)().array()<=m_max.array()).all(); }
+
+ /** Extends \c *this such that it contains the point \a p and returns a reference to \c *this.
+ * \sa extend(const AlignedBox&) */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline AlignedBox& extend(const MatrixBase<Derived>& p)
+ {
+ typename internal::nested_eval<Derived,2>::type p_n(p.derived());
+ m_min = m_min.cwiseMin(p_n);
+ m_max = m_max.cwiseMax(p_n);
+ return *this;
+ }
+
+ /** Extends \c *this such that it contains the box \a b and returns a reference to \c *this.
+ * \sa merged, extend(const MatrixBase&) */
+ EIGEN_DEVICE_FUNC inline AlignedBox& extend(const AlignedBox& b)
+ {
+ m_min = m_min.cwiseMin(b.m_min);
+ m_max = m_max.cwiseMax(b.m_max);
+ return *this;
+ }
+
+ /** Clamps \c *this by the box \a b and returns a reference to \c *this.
+ * \note If the boxes don't intersect, the resulting box is empty.
+ * \sa intersection(), intersects() */
+ EIGEN_DEVICE_FUNC inline AlignedBox& clamp(const AlignedBox& b)
+ {
+ m_min = m_min.cwiseMax(b.m_min);
+ m_max = m_max.cwiseMin(b.m_max);
+ return *this;
+ }
+
+ /** Returns an AlignedBox that is the intersection of \a b and \c *this
+ * \note If the boxes don't intersect, the resulting box is empty.
+ * \sa intersects(), clamp, contains() */
+ EIGEN_DEVICE_FUNC inline AlignedBox intersection(const AlignedBox& b) const
+ {return AlignedBox(m_min.cwiseMax(b.m_min), m_max.cwiseMin(b.m_max)); }
+
+ /** Returns an AlignedBox that is the union of \a b and \c *this.
+ * \note Merging with an empty box may result in a box bigger than \c *this.
+ * \sa extend(const AlignedBox&) */
+ EIGEN_DEVICE_FUNC inline AlignedBox merged(const AlignedBox& b) const
+ { return AlignedBox(m_min.cwiseMin(b.m_min), m_max.cwiseMax(b.m_max)); }
+
+ /** Translate \c *this by the vector \a t and returns a reference to \c *this. */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline AlignedBox& translate(const MatrixBase<Derived>& a_t)
+ {
+ const typename internal::nested_eval<Derived,2>::type t(a_t.derived());
+ m_min += t;
+ m_max += t;
+ return *this;
+ }
+
+ /** \returns a copy of \c *this translated by the vector \a t. */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline AlignedBox translated(const MatrixBase<Derived>& a_t) const
+ {
+ AlignedBox result(m_min, m_max);
+ result.translate(a_t);
+ return result;
+ }
+
+ /** \returns the squared distance between the point \a p and the box \c *this,
+ * and zero if \a p is inside the box.
+ * \sa exteriorDistance(const MatrixBase&), squaredExteriorDistance(const AlignedBox&)
+ */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline Scalar squaredExteriorDistance(const MatrixBase<Derived>& p) const;
+
+ /** \returns the squared distance between the boxes \a b and \c *this,
+ * and zero if the boxes intersect.
+ * \sa exteriorDistance(const AlignedBox&), squaredExteriorDistance(const MatrixBase&)
+ */
+ EIGEN_DEVICE_FUNC inline Scalar squaredExteriorDistance(const AlignedBox& b) const;
+
+ /** \returns the distance between the point \a p and the box \c *this,
+ * and zero if \a p is inside the box.
+ * \sa squaredExteriorDistance(const MatrixBase&), exteriorDistance(const AlignedBox&)
+ */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline NonInteger exteriorDistance(const MatrixBase<Derived>& p) const
+ { EIGEN_USING_STD(sqrt) return sqrt(NonInteger(squaredExteriorDistance(p))); }
+
+ /** \returns the distance between the boxes \a b and \c *this,
+ * and zero if the boxes intersect.
+ * \sa squaredExteriorDistance(const AlignedBox&), exteriorDistance(const MatrixBase&)
+ */
+ EIGEN_DEVICE_FUNC inline NonInteger exteriorDistance(const AlignedBox& b) const
+ { EIGEN_USING_STD(sqrt) return sqrt(NonInteger(squaredExteriorDistance(b))); }
+
+ /**
+ * Specialization of transform for pure translation.
+ */
+ template<int Mode, int Options>
+ EIGEN_DEVICE_FUNC inline void transform(
+ const typename Transform<Scalar, AmbientDimAtCompileTime, Mode, Options>::TranslationType& translation)
+ {
+ this->translate(translation);
+ }
+
+ /**
+ * Transforms this box by \a transform and recomputes it to
+ * still be an axis-aligned box.
+ *
+ * \note This method is provided under BSD license (see the top of this file).
+ */
+ template<int Mode, int Options>
+ EIGEN_DEVICE_FUNC inline void transform(const Transform<Scalar, AmbientDimAtCompileTime, Mode, Options>& transform)
+ {
+ // Only Affine and Isometry transforms are currently supported.
+ EIGEN_STATIC_ASSERT(Mode == Affine || Mode == AffineCompact || Mode == Isometry, THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS);
+
+ // Method adapted from FCL src/shape/geometric_shapes_utility.cpp#computeBV<AABB, Box>(...)
+ // https://github.com/flexible-collision-library/fcl/blob/fcl-0.4/src/shape/geometric_shapes_utility.cpp#L292
+ //
+ // Here's a nice explanation why it works: https://zeuxcg.org/2010/10/17/aabb-from-obb-with-component-wise-abs/
+
+ // two times rotated extent
+ const VectorType rotated_extent_2 = transform.linear().cwiseAbs() * sizes();
+ // two times new center
+ const VectorType rotated_center_2 = transform.linear() * (this->m_max + this->m_min) +
+ Scalar(2) * transform.translation();
+
+ this->m_max = (rotated_center_2 + rotated_extent_2) / Scalar(2);
+ this->m_min = (rotated_center_2 - rotated_extent_2) / Scalar(2);
+ }
+
+ /**
+ * \returns a copy of \c *this transformed by \a transform and recomputed to
+ * still be an axis-aligned box.
+ */
+ template<int Mode, int Options>
+ EIGEN_DEVICE_FUNC AlignedBox transformed(const Transform<Scalar, AmbientDimAtCompileTime, Mode, Options>& transform) const
+ {
+ AlignedBox result(m_min, m_max);
+ result.transform(transform);
+ return result;
+ }
+
+ /** \returns \c *this with scalar type casted to \a NewScalarType
+ *
+ * Note that if \a NewScalarType is equal to the current scalar type of \c *this
+ * then this function smartly returns a const reference to \c *this.
+ */
+ template<typename NewScalarType>
+ EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<AlignedBox,
+ AlignedBox<NewScalarType,AmbientDimAtCompileTime> >::type cast() const
+ {
+ return typename internal::cast_return_type<AlignedBox,
+ AlignedBox<NewScalarType,AmbientDimAtCompileTime> >::type(*this);
+ }
+
+ /** Copy constructor with scalar type conversion */
+ template<typename OtherScalarType>
+ EIGEN_DEVICE_FUNC inline explicit AlignedBox(const AlignedBox<OtherScalarType,AmbientDimAtCompileTime>& other)
+ {
+ m_min = (other.min)().template cast<Scalar>();
+ m_max = (other.max)().template cast<Scalar>();
+ }
+
+ /** \returns \c true if \c *this is approximately equal to \a other, within the precision
+ * determined by \a prec.
+ *
+ * \sa MatrixBase::isApprox() */
+ EIGEN_DEVICE_FUNC bool isApprox(const AlignedBox& other, const RealScalar& prec = ScalarTraits::dummy_precision()) const
+ { return m_min.isApprox(other.m_min, prec) && m_max.isApprox(other.m_max, prec); }
+
+protected:
+
+ VectorType m_min, m_max;
+};
+
+
+
+template<typename Scalar,int AmbientDim>
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline Scalar AlignedBox<Scalar,AmbientDim>::squaredExteriorDistance(const MatrixBase<Derived>& a_p) const
+{
+ typename internal::nested_eval<Derived,2*AmbientDim>::type p(a_p.derived());
+ Scalar dist2(0);
+ Scalar aux;
+ for (Index k=0; k<dim(); ++k)
+ {
+ if( m_min[k] > p[k] )
+ {
+ aux = m_min[k] - p[k];
+ dist2 += aux*aux;
+ }
+ else if( p[k] > m_max[k] )
+ {
+ aux = p[k] - m_max[k];
+ dist2 += aux*aux;
+ }
+ }
+ return dist2;
+}
+
+template<typename Scalar,int AmbientDim>
+EIGEN_DEVICE_FUNC inline Scalar AlignedBox<Scalar,AmbientDim>::squaredExteriorDistance(const AlignedBox& b) const
+{
+ Scalar dist2(0);
+ Scalar aux;
+ for (Index k=0; k<dim(); ++k)
+ {
+ if( m_min[k] > b.m_max[k] )
+ {
+ aux = m_min[k] - b.m_max[k];
+ dist2 += aux*aux;
+ }
+ else if( b.m_min[k] > m_max[k] )
+ {
+ aux = b.m_min[k] - m_max[k];
+ dist2 += aux*aux;
+ }
+ }
+ return dist2;
+}
+
+/** \defgroup alignedboxtypedefs Global aligned box typedefs
+ *
+ * \ingroup Geometry_Module
+ *
+ * Eigen defines several typedef shortcuts for most common aligned box types.
+ *
+ * The general patterns are the following:
+ *
+ * \c AlignedBoxSizeType where \c Size can be \c 1, \c 2,\c 3,\c 4 for fixed size boxes or \c X for dynamic size,
+ * and where \c Type can be \c i for integer, \c f for float, \c d for double.
+ *
+ * For example, \c AlignedBox3d is a fixed-size 3x3 aligned box type of doubles, and \c AlignedBoxXf is a dynamic-size aligned box of floats.
+ *
+ * \sa class AlignedBox
+ */
+
+#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
+/** \ingroup alignedboxtypedefs */ \
+typedef AlignedBox<Type, Size> AlignedBox##SizeSuffix##TypeSuffix;
+
+#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
+EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 1, 1) \
+EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
+EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
+EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
+EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X)
+
+EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i)
+EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)
+EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d)
+
+#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
+#undef EIGEN_MAKE_TYPEDEFS
+
+} // end namespace Eigen
+
+#endif // EIGEN_ALIGNEDBOX_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/AngleAxis.h b/src/3rdparty/eigen/Eigen/src/Geometry/AngleAxis.h
new file mode 100644
index 000000000..78328b6b5
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/AngleAxis.h
@@ -0,0 +1,247 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ANGLEAXIS_H
+#define EIGEN_ANGLEAXIS_H
+
+namespace Eigen {
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \class AngleAxis
+ *
+ * \brief Represents a 3D rotation as a rotation angle around an arbitrary 3D axis
+ *
+ * \param _Scalar the scalar type, i.e., the type of the coefficients.
+ *
+ * \warning When setting up an AngleAxis object, the axis vector \b must \b be \b normalized.
+ *
+ * The following two typedefs are provided for convenience:
+ * \li \c AngleAxisf for \c float
+ * \li \c AngleAxisd for \c double
+ *
+ * Combined with MatrixBase::Unit{X,Y,Z}, AngleAxis can be used to easily
+ * mimic Euler-angles. Here is an example:
+ * \include AngleAxis_mimic_euler.cpp
+ * Output: \verbinclude AngleAxis_mimic_euler.out
+ *
+ * \note This class is not aimed to be used to store a rotation transformation,
+ * but rather to make easier the creation of other rotation (Quaternion, rotation Matrix)
+ * and transformation objects.
+ *
+ * \sa class Quaternion, class Transform, MatrixBase::UnitX()
+ */
+
+namespace internal {
+template<typename _Scalar> struct traits<AngleAxis<_Scalar> >
+{
+ typedef _Scalar Scalar;
+};
+}
+
+template<typename _Scalar>
+class AngleAxis : public RotationBase<AngleAxis<_Scalar>,3>
+{
+ typedef RotationBase<AngleAxis<_Scalar>,3> Base;
+
+public:
+
+ using Base::operator*;
+
+ enum { Dim = 3 };
+ /** the scalar type of the coefficients */
+ typedef _Scalar Scalar;
+ typedef Matrix<Scalar,3,3> Matrix3;
+ typedef Matrix<Scalar,3,1> Vector3;
+ typedef Quaternion<Scalar> QuaternionType;
+
+protected:
+
+ Vector3 m_axis;
+ Scalar m_angle;
+
+public:
+
+ /** Default constructor without initialization. */
+ EIGEN_DEVICE_FUNC AngleAxis() {}
+ /** Constructs and initialize the angle-axis rotation from an \a angle in radian
+ * and an \a axis which \b must \b be \b normalized.
+ *
+ * \warning If the \a axis vector is not normalized, then the angle-axis object
+ * represents an invalid rotation. */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC
+ inline AngleAxis(const Scalar& angle, const MatrixBase<Derived>& axis) : m_axis(axis), m_angle(angle) {}
+ /** Constructs and initialize the angle-axis rotation from a quaternion \a q.
+ * This function implicitly normalizes the quaternion \a q.
+ */
+ template<typename QuatDerived>
+ EIGEN_DEVICE_FUNC inline explicit AngleAxis(const QuaternionBase<QuatDerived>& q) { *this = q; }
+ /** Constructs and initialize the angle-axis rotation from a 3x3 rotation matrix. */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline explicit AngleAxis(const MatrixBase<Derived>& m) { *this = m; }
+
+ /** \returns the value of the rotation angle in radian */
+ EIGEN_DEVICE_FUNC Scalar angle() const { return m_angle; }
+ /** \returns a read-write reference to the stored angle in radian */
+ EIGEN_DEVICE_FUNC Scalar& angle() { return m_angle; }
+
+ /** \returns the rotation axis */
+ EIGEN_DEVICE_FUNC const Vector3& axis() const { return m_axis; }
+ /** \returns a read-write reference to the stored rotation axis.
+ *
+ * \warning The rotation axis must remain a \b unit vector.
+ */
+ EIGEN_DEVICE_FUNC Vector3& axis() { return m_axis; }
+
+ /** Concatenates two rotations */
+ EIGEN_DEVICE_FUNC inline QuaternionType operator* (const AngleAxis& other) const
+ { return QuaternionType(*this) * QuaternionType(other); }
+
+ /** Concatenates two rotations */
+ EIGEN_DEVICE_FUNC inline QuaternionType operator* (const QuaternionType& other) const
+ { return QuaternionType(*this) * other; }
+
+ /** Concatenates two rotations */
+ friend EIGEN_DEVICE_FUNC inline QuaternionType operator* (const QuaternionType& a, const AngleAxis& b)
+ { return a * QuaternionType(b); }
+
+ /** \returns the inverse rotation, i.e., an angle-axis with opposite rotation angle */
+ EIGEN_DEVICE_FUNC AngleAxis inverse() const
+ { return AngleAxis(-m_angle, m_axis); }
+
+ template<class QuatDerived>
+ EIGEN_DEVICE_FUNC AngleAxis& operator=(const QuaternionBase<QuatDerived>& q);
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC AngleAxis& operator=(const MatrixBase<Derived>& m);
+
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC AngleAxis& fromRotationMatrix(const MatrixBase<Derived>& m);
+ EIGEN_DEVICE_FUNC Matrix3 toRotationMatrix(void) const;
+
+ /** \returns \c *this with scalar type casted to \a NewScalarType
+ *
+ * Note that if \a NewScalarType is equal to the current scalar type of \c *this
+ * then this function smartly returns a const reference to \c *this.
+ */
+ template<typename NewScalarType>
+ EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<AngleAxis,AngleAxis<NewScalarType> >::type cast() const
+ { return typename internal::cast_return_type<AngleAxis,AngleAxis<NewScalarType> >::type(*this); }
+
+ /** Copy constructor with scalar type conversion */
+ template<typename OtherScalarType>
+ EIGEN_DEVICE_FUNC inline explicit AngleAxis(const AngleAxis<OtherScalarType>& other)
+ {
+ m_axis = other.axis().template cast<Scalar>();
+ m_angle = Scalar(other.angle());
+ }
+
+ EIGEN_DEVICE_FUNC static inline const AngleAxis Identity() { return AngleAxis(Scalar(0), Vector3::UnitX()); }
+
+ /** \returns \c true if \c *this is approximately equal to \a other, within the precision
+ * determined by \a prec.
+ *
+ * \sa MatrixBase::isApprox() */
+ EIGEN_DEVICE_FUNC bool isApprox(const AngleAxis& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
+ { return m_axis.isApprox(other.m_axis, prec) && internal::isApprox(m_angle,other.m_angle, prec); }
+};
+
+/** \ingroup Geometry_Module
+ * single precision angle-axis type */
+typedef AngleAxis<float> AngleAxisf;
+/** \ingroup Geometry_Module
+ * double precision angle-axis type */
+typedef AngleAxis<double> AngleAxisd;
+
+/** Set \c *this from a \b unit quaternion.
+ *
+ * The resulting axis is normalized, and the computed angle is in the [0,pi] range.
+ *
+ * This function implicitly normalizes the quaternion \a q.
+ */
+template<typename Scalar>
+template<typename QuatDerived>
+EIGEN_DEVICE_FUNC AngleAxis<Scalar>& AngleAxis<Scalar>::operator=(const QuaternionBase<QuatDerived>& q)
+{
+ EIGEN_USING_STD(atan2)
+ EIGEN_USING_STD(abs)
+ Scalar n = q.vec().norm();
+ if(n<NumTraits<Scalar>::epsilon())
+ n = q.vec().stableNorm();
+
+ if (n != Scalar(0))
+ {
+ m_angle = Scalar(2)*atan2(n, abs(q.w()));
+ if(q.w() < Scalar(0))
+ n = -n;
+ m_axis = q.vec() / n;
+ }
+ else
+ {
+ m_angle = Scalar(0);
+ m_axis << Scalar(1), Scalar(0), Scalar(0);
+ }
+ return *this;
+}
+
+/** Set \c *this from a 3x3 rotation matrix \a mat.
+ */
+template<typename Scalar>
+template<typename Derived>
+EIGEN_DEVICE_FUNC AngleAxis<Scalar>& AngleAxis<Scalar>::operator=(const MatrixBase<Derived>& mat)
+{
+ // Since a direct conversion would not be really faster,
+ // let's use the robust Quaternion implementation:
+ return *this = QuaternionType(mat);
+}
+
+/**
+* \brief Sets \c *this from a 3x3 rotation matrix.
+**/
+template<typename Scalar>
+template<typename Derived>
+EIGEN_DEVICE_FUNC AngleAxis<Scalar>& AngleAxis<Scalar>::fromRotationMatrix(const MatrixBase<Derived>& mat)
+{
+ return *this = QuaternionType(mat);
+}
+
+/** Constructs and \returns an equivalent 3x3 rotation matrix.
+ */
+template<typename Scalar>
+typename AngleAxis<Scalar>::Matrix3
+EIGEN_DEVICE_FUNC AngleAxis<Scalar>::toRotationMatrix(void) const
+{
+ EIGEN_USING_STD(sin)
+ EIGEN_USING_STD(cos)
+ Matrix3 res;
+ Vector3 sin_axis = sin(m_angle) * m_axis;
+ Scalar c = cos(m_angle);
+ Vector3 cos1_axis = (Scalar(1)-c) * m_axis;
+
+ Scalar tmp;
+ tmp = cos1_axis.x() * m_axis.y();
+ res.coeffRef(0,1) = tmp - sin_axis.z();
+ res.coeffRef(1,0) = tmp + sin_axis.z();
+
+ tmp = cos1_axis.x() * m_axis.z();
+ res.coeffRef(0,2) = tmp + sin_axis.y();
+ res.coeffRef(2,0) = tmp - sin_axis.y();
+
+ tmp = cos1_axis.y() * m_axis.z();
+ res.coeffRef(1,2) = tmp - sin_axis.x();
+ res.coeffRef(2,1) = tmp + sin_axis.x();
+
+ res.diagonal() = (cos1_axis.cwiseProduct(m_axis)).array() + c;
+
+ return res;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_ANGLEAXIS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/EulerAngles.h b/src/3rdparty/eigen/Eigen/src/Geometry/EulerAngles.h
new file mode 100644
index 000000000..19b734ca7
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/EulerAngles.h
@@ -0,0 +1,114 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_EULERANGLES_H
+#define EIGEN_EULERANGLES_H
+
+namespace Eigen {
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ *
+ * \returns the Euler-angles of the rotation matrix \c *this using the convention defined by the triplet (\a a0,\a a1,\a a2)
+ *
+ * Each of the three parameters \a a0,\a a1,\a a2 represents the respective rotation axis as an integer in {0,1,2}.
+ * For instance, in:
+ * \code Vector3f ea = mat.eulerAngles(2, 0, 2); \endcode
+ * "2" represents the z axis and "0" the x axis, etc. The returned angles are such that
+ * we have the following equality:
+ * \code
+ * mat == AngleAxisf(ea[0], Vector3f::UnitZ())
+ * * AngleAxisf(ea[1], Vector3f::UnitX())
+ * * AngleAxisf(ea[2], Vector3f::UnitZ()); \endcode
+ * This corresponds to the right-multiply conventions (with right hand side frames).
+ *
+ * The returned angles are in the ranges [0:pi]x[-pi:pi]x[-pi:pi].
+ *
+ * \sa class AngleAxis
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline Matrix<typename MatrixBase<Derived>::Scalar,3,1>
+MatrixBase<Derived>::eulerAngles(Index a0, Index a1, Index a2) const
+{
+ EIGEN_USING_STD(atan2)
+ EIGEN_USING_STD(sin)
+ EIGEN_USING_STD(cos)
+ /* Implemented from Graphics Gems IV */
+ EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,3,3)
+
+ Matrix<Scalar,3,1> res;
+ typedef Matrix<typename Derived::Scalar,2,1> Vector2;
+
+ const Index odd = ((a0+1)%3 == a1) ? 0 : 1;
+ const Index i = a0;
+ const Index j = (a0 + 1 + odd)%3;
+ const Index k = (a0 + 2 - odd)%3;
+
+ if (a0==a2)
+ {
+ res[0] = atan2(coeff(j,i), coeff(k,i));
+ if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0)))
+ {
+ if(res[0] > Scalar(0)) {
+ res[0] -= Scalar(EIGEN_PI);
+ }
+ else {
+ res[0] += Scalar(EIGEN_PI);
+ }
+ Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm();
+ res[1] = -atan2(s2, coeff(i,i));
+ }
+ else
+ {
+ Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm();
+ res[1] = atan2(s2, coeff(i,i));
+ }
+
+ // With a=(0,1,0), we have i=0; j=1; k=2, and after computing the first two angles,
+ // we can compute their respective rotation, and apply its inverse to M. Since the result must
+ // be a rotation around x, we have:
+ //
+ // c2 s1.s2 c1.s2 1 0 0
+ // 0 c1 -s1 * M = 0 c3 s3
+ // -s2 s1.c2 c1.c2 0 -s3 c3
+ //
+ // Thus: m11.c1 - m21.s1 = c3 & m12.c1 - m22.s1 = s3
+
+ Scalar s1 = sin(res[0]);
+ Scalar c1 = cos(res[0]);
+ res[2] = atan2(c1*coeff(j,k)-s1*coeff(k,k), c1*coeff(j,j) - s1 * coeff(k,j));
+ }
+ else
+ {
+ res[0] = atan2(coeff(j,k), coeff(k,k));
+ Scalar c2 = Vector2(coeff(i,i), coeff(i,j)).norm();
+ if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0))) {
+ if(res[0] > Scalar(0)) {
+ res[0] -= Scalar(EIGEN_PI);
+ }
+ else {
+ res[0] += Scalar(EIGEN_PI);
+ }
+ res[1] = atan2(-coeff(i,k), -c2);
+ }
+ else
+ res[1] = atan2(-coeff(i,k), c2);
+ Scalar s1 = sin(res[0]);
+ Scalar c1 = cos(res[0]);
+ res[2] = atan2(s1*coeff(k,i)-c1*coeff(j,i), c1*coeff(j,j) - s1 * coeff(k,j));
+ }
+ if (!odd)
+ res = -res;
+
+ return res;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_EULERANGLES_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/Homogeneous.h b/src/3rdparty/eigen/Eigen/src/Geometry/Homogeneous.h
new file mode 100644
index 000000000..94083ac54
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/Homogeneous.h
@@ -0,0 +1,501 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_HOMOGENEOUS_H
+#define EIGEN_HOMOGENEOUS_H
+
+namespace Eigen {
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \class Homogeneous
+ *
+ * \brief Expression of one (or a set of) homogeneous vector(s)
+ *
+ * \param MatrixType the type of the object in which we are making homogeneous
+ *
+ * This class represents an expression of one (or a set of) homogeneous vector(s).
+ * It is the return type of MatrixBase::homogeneous() and most of the time
+ * this is the only way it is used.
+ *
+ * \sa MatrixBase::homogeneous()
+ */
+
+namespace internal {
+
+template<typename MatrixType,int Direction>
+struct traits<Homogeneous<MatrixType,Direction> >
+ : traits<MatrixType>
+{
+ typedef typename traits<MatrixType>::StorageKind StorageKind;
+ typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
+ typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
+ enum {
+ RowsPlusOne = (MatrixType::RowsAtCompileTime != Dynamic) ?
+ int(MatrixType::RowsAtCompileTime) + 1 : Dynamic,
+ ColsPlusOne = (MatrixType::ColsAtCompileTime != Dynamic) ?
+ int(MatrixType::ColsAtCompileTime) + 1 : Dynamic,
+ RowsAtCompileTime = Direction==Vertical ? RowsPlusOne : MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = Direction==Horizontal ? ColsPlusOne : MatrixType::ColsAtCompileTime,
+ MaxRowsAtCompileTime = RowsAtCompileTime,
+ MaxColsAtCompileTime = ColsAtCompileTime,
+ TmpFlags = _MatrixTypeNested::Flags & HereditaryBits,
+ Flags = ColsAtCompileTime==1 ? (TmpFlags & ~RowMajorBit)
+ : RowsAtCompileTime==1 ? (TmpFlags | RowMajorBit)
+ : TmpFlags
+ };
+};
+
+template<typename MatrixType,typename Lhs> struct homogeneous_left_product_impl;
+template<typename MatrixType,typename Rhs> struct homogeneous_right_product_impl;
+
+} // end namespace internal
+
+template<typename MatrixType,int _Direction> class Homogeneous
+ : public MatrixBase<Homogeneous<MatrixType,_Direction> >, internal::no_assignment_operator
+{
+ public:
+
+ typedef MatrixType NestedExpression;
+ enum { Direction = _Direction };
+
+ typedef MatrixBase<Homogeneous> Base;
+ EIGEN_DENSE_PUBLIC_INTERFACE(Homogeneous)
+
+ EIGEN_DEVICE_FUNC explicit inline Homogeneous(const MatrixType& matrix)
+ : m_matrix(matrix)
+ {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows() + (int(Direction)==Vertical ? 1 : 0); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols() + (int(Direction)==Horizontal ? 1 : 0); }
+
+ EIGEN_DEVICE_FUNC const NestedExpression& nestedExpression() const { return m_matrix; }
+
+ template<typename Rhs>
+ EIGEN_DEVICE_FUNC inline const Product<Homogeneous,Rhs>
+ operator* (const MatrixBase<Rhs>& rhs) const
+ {
+ eigen_assert(int(Direction)==Horizontal);
+ return Product<Homogeneous,Rhs>(*this,rhs.derived());
+ }
+
+ template<typename Lhs> friend
+ EIGEN_DEVICE_FUNC inline const Product<Lhs,Homogeneous>
+ operator* (const MatrixBase<Lhs>& lhs, const Homogeneous& rhs)
+ {
+ eigen_assert(int(Direction)==Vertical);
+ return Product<Lhs,Homogeneous>(lhs.derived(),rhs);
+ }
+
+ template<typename Scalar, int Dim, int Mode, int Options> friend
+ EIGEN_DEVICE_FUNC inline const Product<Transform<Scalar,Dim,Mode,Options>, Homogeneous >
+ operator* (const Transform<Scalar,Dim,Mode,Options>& lhs, const Homogeneous& rhs)
+ {
+ eigen_assert(int(Direction)==Vertical);
+ return Product<Transform<Scalar,Dim,Mode,Options>, Homogeneous>(lhs,rhs);
+ }
+
+ template<typename Func>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::result_of<Func(Scalar,Scalar)>::type
+ redux(const Func& func) const
+ {
+ return func(m_matrix.redux(func), Scalar(1));
+ }
+
+ protected:
+ typename MatrixType::Nested m_matrix;
+};
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \returns a vector expression that is one longer than the vector argument, with the value 1 symbolically appended as the last coefficient.
+ *
+ * This can be used to convert affine coordinates to homogeneous coordinates.
+ *
+ * \only_for_vectors
+ *
+ * Example: \include MatrixBase_homogeneous.cpp
+ * Output: \verbinclude MatrixBase_homogeneous.out
+ *
+ * \sa VectorwiseOp::homogeneous(), class Homogeneous
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::HomogeneousReturnType
+MatrixBase<Derived>::homogeneous() const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
+ return HomogeneousReturnType(derived());
+}
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \returns an expression where the value 1 is symbolically appended as the final coefficient to each column (or row) of the matrix.
+ *
+ * This can be used to convert affine coordinates to homogeneous coordinates.
+ *
+ * Example: \include VectorwiseOp_homogeneous.cpp
+ * Output: \verbinclude VectorwiseOp_homogeneous.out
+ *
+ * \sa MatrixBase::homogeneous(), class Homogeneous */
+template<typename ExpressionType, int Direction>
+EIGEN_DEVICE_FUNC inline Homogeneous<ExpressionType,Direction>
+VectorwiseOp<ExpressionType,Direction>::homogeneous() const
+{
+ return HomogeneousReturnType(_expression());
+}
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \brief homogeneous normalization
+ *
+ * \returns a vector expression of the N-1 first coefficients of \c *this divided by that last coefficient.
+ *
+ * This can be used to convert homogeneous coordinates to affine coordinates.
+ *
+ * It is essentially a shortcut for:
+ * \code
+ this->head(this->size()-1)/this->coeff(this->size()-1);
+ \endcode
+ *
+ * Example: \include MatrixBase_hnormalized.cpp
+ * Output: \verbinclude MatrixBase_hnormalized.out
+ *
+ * \sa VectorwiseOp::hnormalized() */
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline const typename MatrixBase<Derived>::HNormalizedReturnType
+MatrixBase<Derived>::hnormalized() const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
+ return ConstStartMinusOne(derived(),0,0,
+ ColsAtCompileTime==1?size()-1:1,
+ ColsAtCompileTime==1?1:size()-1) / coeff(size()-1);
+}
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \brief column or row-wise homogeneous normalization
+ *
+ * \returns an expression of the first N-1 coefficients of each column (or row) of \c *this divided by the last coefficient of each column (or row).
+ *
+ * This can be used to convert homogeneous coordinates to affine coordinates.
+ *
+ * It is conceptually equivalent to calling MatrixBase::hnormalized() to each column (or row) of \c *this.
+ *
+ * Example: \include DirectionWise_hnormalized.cpp
+ * Output: \verbinclude DirectionWise_hnormalized.out
+ *
+ * \sa MatrixBase::hnormalized() */
+template<typename ExpressionType, int Direction>
+EIGEN_DEVICE_FUNC inline const typename VectorwiseOp<ExpressionType,Direction>::HNormalizedReturnType
+VectorwiseOp<ExpressionType,Direction>::hnormalized() const
+{
+ return HNormalized_Block(_expression(),0,0,
+ Direction==Vertical ? _expression().rows()-1 : _expression().rows(),
+ Direction==Horizontal ? _expression().cols()-1 : _expression().cols()).cwiseQuotient(
+ Replicate<HNormalized_Factors,
+ Direction==Vertical ? HNormalized_SizeMinusOne : 1,
+ Direction==Horizontal ? HNormalized_SizeMinusOne : 1>
+ (HNormalized_Factors(_expression(),
+ Direction==Vertical ? _expression().rows()-1:0,
+ Direction==Horizontal ? _expression().cols()-1:0,
+ Direction==Vertical ? 1 : _expression().rows(),
+ Direction==Horizontal ? 1 : _expression().cols()),
+ Direction==Vertical ? _expression().rows()-1 : 1,
+ Direction==Horizontal ? _expression().cols()-1 : 1));
+}
+
+namespace internal {
+
+template<typename MatrixOrTransformType>
+struct take_matrix_for_product
+{
+ typedef MatrixOrTransformType type;
+ EIGEN_DEVICE_FUNC static const type& run(const type &x) { return x; }
+};
+
+template<typename Scalar, int Dim, int Mode,int Options>
+struct take_matrix_for_product<Transform<Scalar, Dim, Mode, Options> >
+{
+ typedef Transform<Scalar, Dim, Mode, Options> TransformType;
+ typedef typename internal::add_const<typename TransformType::ConstAffinePart>::type type;
+ EIGEN_DEVICE_FUNC static type run (const TransformType& x) { return x.affine(); }
+};
+
+template<typename Scalar, int Dim, int Options>
+struct take_matrix_for_product<Transform<Scalar, Dim, Projective, Options> >
+{
+ typedef Transform<Scalar, Dim, Projective, Options> TransformType;
+ typedef typename TransformType::MatrixType type;
+ EIGEN_DEVICE_FUNC static const type& run (const TransformType& x) { return x.matrix(); }
+};
+
+template<typename MatrixType,typename Lhs>
+struct traits<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
+{
+ typedef typename take_matrix_for_product<Lhs>::type LhsMatrixType;
+ typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
+ typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned;
+ typedef typename make_proper_matrix_type<
+ typename traits<MatrixTypeCleaned>::Scalar,
+ LhsMatrixTypeCleaned::RowsAtCompileTime,
+ MatrixTypeCleaned::ColsAtCompileTime,
+ MatrixTypeCleaned::PlainObject::Options,
+ LhsMatrixTypeCleaned::MaxRowsAtCompileTime,
+ MatrixTypeCleaned::MaxColsAtCompileTime>::type ReturnType;
+};
+
+template<typename MatrixType,typename Lhs>
+struct homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs>
+ : public ReturnByValue<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
+{
+ typedef typename traits<homogeneous_left_product_impl>::LhsMatrixType LhsMatrixType;
+ typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned;
+ typedef typename remove_all<typename LhsMatrixTypeCleaned::Nested>::type LhsMatrixTypeNested;
+ EIGEN_DEVICE_FUNC homogeneous_left_product_impl(const Lhs& lhs, const MatrixType& rhs)
+ : m_lhs(take_matrix_for_product<Lhs>::run(lhs)),
+ m_rhs(rhs)
+ {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return m_lhs.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
+
+ template<typename Dest> EIGEN_DEVICE_FUNC void evalTo(Dest& dst) const
+ {
+ // FIXME investigate how to allow lazy evaluation of this product when possible
+ dst = Block<const LhsMatrixTypeNested,
+ LhsMatrixTypeNested::RowsAtCompileTime,
+ LhsMatrixTypeNested::ColsAtCompileTime==Dynamic?Dynamic:LhsMatrixTypeNested::ColsAtCompileTime-1>
+ (m_lhs,0,0,m_lhs.rows(),m_lhs.cols()-1) * m_rhs;
+ dst += m_lhs.col(m_lhs.cols()-1).rowwise()
+ .template replicate<MatrixType::ColsAtCompileTime>(m_rhs.cols());
+ }
+
+ typename LhsMatrixTypeCleaned::Nested m_lhs;
+ typename MatrixType::Nested m_rhs;
+};
+
+template<typename MatrixType,typename Rhs>
+struct traits<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
+{
+ typedef typename make_proper_matrix_type<typename traits<MatrixType>::Scalar,
+ MatrixType::RowsAtCompileTime,
+ Rhs::ColsAtCompileTime,
+ MatrixType::PlainObject::Options,
+ MatrixType::MaxRowsAtCompileTime,
+ Rhs::MaxColsAtCompileTime>::type ReturnType;
+};
+
+template<typename MatrixType,typename Rhs>
+struct homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs>
+ : public ReturnByValue<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
+{
+ typedef typename remove_all<typename Rhs::Nested>::type RhsNested;
+ EIGEN_DEVICE_FUNC homogeneous_right_product_impl(const MatrixType& lhs, const Rhs& rhs)
+ : m_lhs(lhs), m_rhs(rhs)
+ {}
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_lhs.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
+
+ template<typename Dest> EIGEN_DEVICE_FUNC void evalTo(Dest& dst) const
+ {
+ // FIXME investigate how to allow lazy evaluation of this product when possible
+ dst = m_lhs * Block<const RhsNested,
+ RhsNested::RowsAtCompileTime==Dynamic?Dynamic:RhsNested::RowsAtCompileTime-1,
+ RhsNested::ColsAtCompileTime>
+ (m_rhs,0,0,m_rhs.rows()-1,m_rhs.cols());
+ dst += m_rhs.row(m_rhs.rows()-1).colwise()
+ .template replicate<MatrixType::RowsAtCompileTime>(m_lhs.rows());
+ }
+
+ typename MatrixType::Nested m_lhs;
+ typename Rhs::Nested m_rhs;
+};
+
+template<typename ArgType,int Direction>
+struct evaluator_traits<Homogeneous<ArgType,Direction> >
+{
+ typedef typename storage_kind_to_evaluator_kind<typename ArgType::StorageKind>::Kind Kind;
+ typedef HomogeneousShape Shape;
+};
+
+template<> struct AssignmentKind<DenseShape,HomogeneousShape> { typedef Dense2Dense Kind; };
+
+
+template<typename ArgType,int Direction>
+struct unary_evaluator<Homogeneous<ArgType,Direction>, IndexBased>
+ : evaluator<typename Homogeneous<ArgType,Direction>::PlainObject >
+{
+ typedef Homogeneous<ArgType,Direction> XprType;
+ typedef typename XprType::PlainObject PlainObject;
+ typedef evaluator<PlainObject> Base;
+
+ EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& op)
+ : Base(), m_temp(op)
+ {
+ ::new (static_cast<Base*>(this)) Base(m_temp);
+ }
+
+protected:
+ PlainObject m_temp;
+};
+
+// dense = homogeneous
+template< typename DstXprType, typename ArgType, typename Scalar>
+struct Assignment<DstXprType, Homogeneous<ArgType,Vertical>, internal::assign_op<Scalar,typename ArgType::Scalar>, Dense2Dense>
+{
+ typedef Homogeneous<ArgType,Vertical> SrcXprType;
+ EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,typename ArgType::Scalar> &)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+
+ dst.template topRows<ArgType::RowsAtCompileTime>(src.nestedExpression().rows()) = src.nestedExpression();
+ dst.row(dst.rows()-1).setOnes();
+ }
+};
+
+// dense = homogeneous
+template< typename DstXprType, typename ArgType, typename Scalar>
+struct Assignment<DstXprType, Homogeneous<ArgType,Horizontal>, internal::assign_op<Scalar,typename ArgType::Scalar>, Dense2Dense>
+{
+ typedef Homogeneous<ArgType,Horizontal> SrcXprType;
+ EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,typename ArgType::Scalar> &)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+
+ dst.template leftCols<ArgType::ColsAtCompileTime>(src.nestedExpression().cols()) = src.nestedExpression();
+ dst.col(dst.cols()-1).setOnes();
+ }
+};
+
+template<typename LhsArg, typename Rhs, int ProductTag>
+struct generic_product_impl<Homogeneous<LhsArg,Horizontal>, Rhs, HomogeneousShape, DenseShape, ProductTag>
+{
+ template<typename Dest>
+ EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const Homogeneous<LhsArg,Horizontal>& lhs, const Rhs& rhs)
+ {
+ homogeneous_right_product_impl<Homogeneous<LhsArg,Horizontal>, Rhs>(lhs.nestedExpression(), rhs).evalTo(dst);
+ }
+};
+
+template<typename Lhs,typename Rhs>
+struct homogeneous_right_product_refactoring_helper
+{
+ enum {
+ Dim = Lhs::ColsAtCompileTime,
+ Rows = Lhs::RowsAtCompileTime
+ };
+ typedef typename Rhs::template ConstNRowsBlockXpr<Dim>::Type LinearBlockConst;
+ typedef typename remove_const<LinearBlockConst>::type LinearBlock;
+ typedef typename Rhs::ConstRowXpr ConstantColumn;
+ typedef Replicate<const ConstantColumn,Rows,1> ConstantBlock;
+ typedef Product<Lhs,LinearBlock,LazyProduct> LinearProduct;
+ typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar,typename Rhs::Scalar>, const LinearProduct, const ConstantBlock> Xpr;
+};
+
+template<typename Lhs, typename Rhs, int ProductTag>
+struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, HomogeneousShape, DenseShape>
+ : public evaluator<typename homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs>::Xpr>
+{
+ typedef Product<Lhs, Rhs, LazyProduct> XprType;
+ typedef homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs> helper;
+ typedef typename helper::ConstantBlock ConstantBlock;
+ typedef typename helper::Xpr RefactoredXpr;
+ typedef evaluator<RefactoredXpr> Base;
+
+ EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr)
+ : Base( xpr.lhs().nestedExpression() .lazyProduct( xpr.rhs().template topRows<helper::Dim>(xpr.lhs().nestedExpression().cols()) )
+ + ConstantBlock(xpr.rhs().row(xpr.rhs().rows()-1),xpr.lhs().rows(), 1) )
+ {}
+};
+
+template<typename Lhs, typename RhsArg, int ProductTag>
+struct generic_product_impl<Lhs, Homogeneous<RhsArg,Vertical>, DenseShape, HomogeneousShape, ProductTag>
+{
+ template<typename Dest>
+ EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const Lhs& lhs, const Homogeneous<RhsArg,Vertical>& rhs)
+ {
+ homogeneous_left_product_impl<Homogeneous<RhsArg,Vertical>, Lhs>(lhs, rhs.nestedExpression()).evalTo(dst);
+ }
+};
+
+// TODO: the following specialization is to address a regression from 3.2 to 3.3
+// In the future, this path should be optimized.
+template<typename Lhs, typename RhsArg, int ProductTag>
+struct generic_product_impl<Lhs, Homogeneous<RhsArg,Vertical>, TriangularShape, HomogeneousShape, ProductTag>
+{
+ template<typename Dest>
+ static void evalTo(Dest& dst, const Lhs& lhs, const Homogeneous<RhsArg,Vertical>& rhs)
+ {
+ dst.noalias() = lhs * rhs.eval();
+ }
+};
+
+template<typename Lhs,typename Rhs>
+struct homogeneous_left_product_refactoring_helper
+{
+ enum {
+ Dim = Rhs::RowsAtCompileTime,
+ Cols = Rhs::ColsAtCompileTime
+ };
+ typedef typename Lhs::template ConstNColsBlockXpr<Dim>::Type LinearBlockConst;
+ typedef typename remove_const<LinearBlockConst>::type LinearBlock;
+ typedef typename Lhs::ConstColXpr ConstantColumn;
+ typedef Replicate<const ConstantColumn,1,Cols> ConstantBlock;
+ typedef Product<LinearBlock,Rhs,LazyProduct> LinearProduct;
+ typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar,typename Rhs::Scalar>, const LinearProduct, const ConstantBlock> Xpr;
+};
+
+template<typename Lhs, typename Rhs, int ProductTag>
+struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, HomogeneousShape>
+ : public evaluator<typename homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression>::Xpr>
+{
+ typedef Product<Lhs, Rhs, LazyProduct> XprType;
+ typedef homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression> helper;
+ typedef typename helper::ConstantBlock ConstantBlock;
+ typedef typename helper::Xpr RefactoredXpr;
+ typedef evaluator<RefactoredXpr> Base;
+
+ EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr)
+ : Base( xpr.lhs().template leftCols<helper::Dim>(xpr.rhs().nestedExpression().rows()) .lazyProduct( xpr.rhs().nestedExpression() )
+ + ConstantBlock(xpr.lhs().col(xpr.lhs().cols()-1),1,xpr.rhs().cols()) )
+ {}
+};
+
+template<typename Scalar, int Dim, int Mode,int Options, typename RhsArg, int ProductTag>
+struct generic_product_impl<Transform<Scalar,Dim,Mode,Options>, Homogeneous<RhsArg,Vertical>, DenseShape, HomogeneousShape, ProductTag>
+{
+ typedef Transform<Scalar,Dim,Mode,Options> TransformType;
+ template<typename Dest>
+ EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const TransformType& lhs, const Homogeneous<RhsArg,Vertical>& rhs)
+ {
+ homogeneous_left_product_impl<Homogeneous<RhsArg,Vertical>, TransformType>(lhs, rhs.nestedExpression()).evalTo(dst);
+ }
+};
+
+template<typename ExpressionType, int Side, bool Transposed>
+struct permutation_matrix_product<ExpressionType, Side, Transposed, HomogeneousShape>
+ : public permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape>
+{};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_HOMOGENEOUS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/Hyperplane.h b/src/3rdparty/eigen/Eigen/src/Geometry/Hyperplane.h
new file mode 100644
index 000000000..cebe03557
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/Hyperplane.h
@@ -0,0 +1,282 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_HYPERPLANE_H
+#define EIGEN_HYPERPLANE_H
+
+namespace Eigen {
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \class Hyperplane
+ *
+ * \brief A hyperplane
+ *
+ * A hyperplane is an affine subspace of dimension n-1 in a space of dimension n.
+ * For example, a hyperplane in a plane is a line; a hyperplane in 3-space is a plane.
+ *
+ * \tparam _Scalar the scalar type, i.e., the type of the coefficients
+ * \tparam _AmbientDim the dimension of the ambient space, can be a compile time value or Dynamic.
+ * Notice that the dimension of the hyperplane is _AmbientDim-1.
+ *
+ * This class represents an hyperplane as the zero set of the implicit equation
+ * \f$ n \cdot x + d = 0 \f$ where \f$ n \f$ is a unit normal vector of the plane (linear part)
+ * and \f$ d \f$ is the distance (offset) to the origin.
+ */
+template <typename _Scalar, int _AmbientDim, int _Options>
+class Hyperplane
+{
+public:
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim==Dynamic ? Dynamic : _AmbientDim+1)
+ enum {
+ AmbientDimAtCompileTime = _AmbientDim,
+ Options = _Options
+ };
+ typedef _Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+ typedef Matrix<Scalar,AmbientDimAtCompileTime,1> VectorType;
+ typedef Matrix<Scalar,Index(AmbientDimAtCompileTime)==Dynamic
+ ? Dynamic
+ : Index(AmbientDimAtCompileTime)+1,1,Options> Coefficients;
+ typedef Block<Coefficients,AmbientDimAtCompileTime,1> NormalReturnType;
+ typedef const Block<const Coefficients,AmbientDimAtCompileTime,1> ConstNormalReturnType;
+
+ /** Default constructor without initialization */
+ EIGEN_DEVICE_FUNC inline Hyperplane() {}
+
+ template<int OtherOptions>
+ EIGEN_DEVICE_FUNC Hyperplane(const Hyperplane<Scalar,AmbientDimAtCompileTime,OtherOptions>& other)
+ : m_coeffs(other.coeffs())
+ {}
+
+ /** Constructs a dynamic-size hyperplane with \a _dim the dimension
+ * of the ambient space */
+ EIGEN_DEVICE_FUNC inline explicit Hyperplane(Index _dim) : m_coeffs(_dim+1) {}
+
+ /** Construct a plane from its normal \a n and a point \a e onto the plane.
+ * \warning the vector normal is assumed to be normalized.
+ */
+ EIGEN_DEVICE_FUNC inline Hyperplane(const VectorType& n, const VectorType& e)
+ : m_coeffs(n.size()+1)
+ {
+ normal() = n;
+ offset() = -n.dot(e);
+ }
+
+ /** Constructs a plane from its normal \a n and distance to the origin \a d
+ * such that the algebraic equation of the plane is \f$ n \cdot x + d = 0 \f$.
+ * \warning the vector normal is assumed to be normalized.
+ */
+ EIGEN_DEVICE_FUNC inline Hyperplane(const VectorType& n, const Scalar& d)
+ : m_coeffs(n.size()+1)
+ {
+ normal() = n;
+ offset() = d;
+ }
+
+ /** Constructs a hyperplane passing through the two points. If the dimension of the ambient space
+ * is greater than 2, then there isn't uniqueness, so an arbitrary choice is made.
+ */
+ EIGEN_DEVICE_FUNC static inline Hyperplane Through(const VectorType& p0, const VectorType& p1)
+ {
+ Hyperplane result(p0.size());
+ result.normal() = (p1 - p0).unitOrthogonal();
+ result.offset() = -p0.dot(result.normal());
+ return result;
+ }
+
+ /** Constructs a hyperplane passing through the three points. The dimension of the ambient space
+ * is required to be exactly 3.
+ */
+ EIGEN_DEVICE_FUNC static inline Hyperplane Through(const VectorType& p0, const VectorType& p1, const VectorType& p2)
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 3)
+ Hyperplane result(p0.size());
+ VectorType v0(p2 - p0), v1(p1 - p0);
+ result.normal() = v0.cross(v1);
+ RealScalar norm = result.normal().norm();
+ if(norm <= v0.norm() * v1.norm() * NumTraits<RealScalar>::epsilon())
+ {
+ Matrix<Scalar,2,3> m; m << v0.transpose(), v1.transpose();
+ JacobiSVD<Matrix<Scalar,2,3> > svd(m, ComputeFullV);
+ result.normal() = svd.matrixV().col(2);
+ }
+ else
+ result.normal() /= norm;
+ result.offset() = -p0.dot(result.normal());
+ return result;
+ }
+
+ /** Constructs a hyperplane passing through the parametrized line \a parametrized.
+ * If the dimension of the ambient space is greater than 2, then there isn't uniqueness,
+ * so an arbitrary choice is made.
+ */
+ // FIXME to be consistent with the rest this could be implemented as a static Through function ??
+ EIGEN_DEVICE_FUNC explicit Hyperplane(const ParametrizedLine<Scalar, AmbientDimAtCompileTime>& parametrized)
+ {
+ normal() = parametrized.direction().unitOrthogonal();
+ offset() = -parametrized.origin().dot(normal());
+ }
+
+ EIGEN_DEVICE_FUNC ~Hyperplane() {}
+
+ /** \returns the dimension in which the plane holds */
+ EIGEN_DEVICE_FUNC inline Index dim() const { return AmbientDimAtCompileTime==Dynamic ? m_coeffs.size()-1 : Index(AmbientDimAtCompileTime); }
+
+ /** normalizes \c *this */
+ EIGEN_DEVICE_FUNC void normalize(void)
+ {
+ m_coeffs /= normal().norm();
+ }
+
+ /** \returns the signed distance between the plane \c *this and a point \a p.
+ * \sa absDistance()
+ */
+ EIGEN_DEVICE_FUNC inline Scalar signedDistance(const VectorType& p) const { return normal().dot(p) + offset(); }
+
+ /** \returns the absolute distance between the plane \c *this and a point \a p.
+ * \sa signedDistance()
+ */
+ EIGEN_DEVICE_FUNC inline Scalar absDistance(const VectorType& p) const { return numext::abs(signedDistance(p)); }
+
+ /** \returns the projection of a point \a p onto the plane \c *this.
+ */
+ EIGEN_DEVICE_FUNC inline VectorType projection(const VectorType& p) const { return p - signedDistance(p) * normal(); }
+
+ /** \returns a constant reference to the unit normal vector of the plane, which corresponds
+ * to the linear part of the implicit equation.
+ */
+ EIGEN_DEVICE_FUNC inline ConstNormalReturnType normal() const { return ConstNormalReturnType(m_coeffs,0,0,dim(),1); }
+
+ /** \returns a non-constant reference to the unit normal vector of the plane, which corresponds
+ * to the linear part of the implicit equation.
+ */
+ EIGEN_DEVICE_FUNC inline NormalReturnType normal() { return NormalReturnType(m_coeffs,0,0,dim(),1); }
+
+ /** \returns the distance to the origin, which is also the "constant term" of the implicit equation
+ * \warning the vector normal is assumed to be normalized.
+ */
+ EIGEN_DEVICE_FUNC inline const Scalar& offset() const { return m_coeffs.coeff(dim()); }
+
+ /** \returns a non-constant reference to the distance to the origin, which is also the constant part
+ * of the implicit equation */
+ EIGEN_DEVICE_FUNC inline Scalar& offset() { return m_coeffs(dim()); }
+
+ /** \returns a constant reference to the coefficients c_i of the plane equation:
+ * \f$ c_0*x_0 + ... + c_{d-1}*x_{d-1} + c_d = 0 \f$
+ */
+ EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs; }
+
+ /** \returns a non-constant reference to the coefficients c_i of the plane equation:
+ * \f$ c_0*x_0 + ... + c_{d-1}*x_{d-1} + c_d = 0 \f$
+ */
+ EIGEN_DEVICE_FUNC inline Coefficients& coeffs() { return m_coeffs; }
+
+ /** \returns the intersection of *this with \a other.
+ *
+ * \warning The ambient space must be a plane, i.e. have dimension 2, so that \c *this and \a other are lines.
+ *
+ * \note If \a other is approximately parallel to *this, this method will return any point on *this.
+ */
+ EIGEN_DEVICE_FUNC VectorType intersection(const Hyperplane& other) const
+ {
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
+ Scalar det = coeffs().coeff(0) * other.coeffs().coeff(1) - coeffs().coeff(1) * other.coeffs().coeff(0);
+ // since the line equations ax+by=c are normalized with a^2+b^2=1, the following tests
+ // whether the two lines are approximately parallel.
+ if(internal::isMuchSmallerThan(det, Scalar(1)))
+ { // special case where the two lines are approximately parallel. Pick any point on the first line.
+ if(numext::abs(coeffs().coeff(1))>numext::abs(coeffs().coeff(0)))
+ return VectorType(coeffs().coeff(1), -coeffs().coeff(2)/coeffs().coeff(1)-coeffs().coeff(0));
+ else
+ return VectorType(-coeffs().coeff(2)/coeffs().coeff(0)-coeffs().coeff(1), coeffs().coeff(0));
+ }
+ else
+ { // general case
+ Scalar invdet = Scalar(1) / det;
+ return VectorType(invdet*(coeffs().coeff(1)*other.coeffs().coeff(2)-other.coeffs().coeff(1)*coeffs().coeff(2)),
+ invdet*(other.coeffs().coeff(0)*coeffs().coeff(2)-coeffs().coeff(0)*other.coeffs().coeff(2)));
+ }
+ }
+
+ /** Applies the transformation matrix \a mat to \c *this and returns a reference to \c *this.
+ *
+ * \param mat the Dim x Dim transformation matrix
+ * \param traits specifies whether the matrix \a mat represents an #Isometry
+ * or a more generic #Affine transformation. The default is #Affine.
+ */
+ template<typename XprType>
+ EIGEN_DEVICE_FUNC inline Hyperplane& transform(const MatrixBase<XprType>& mat, TransformTraits traits = Affine)
+ {
+ if (traits==Affine)
+ {
+ normal() = mat.inverse().transpose() * normal();
+ m_coeffs /= normal().norm();
+ }
+ else if (traits==Isometry)
+ normal() = mat * normal();
+ else
+ {
+ eigen_assert(0 && "invalid traits value in Hyperplane::transform()");
+ }
+ return *this;
+ }
+
+ /** Applies the transformation \a t to \c *this and returns a reference to \c *this.
+ *
+ * \param t the transformation of dimension Dim
+ * \param traits specifies whether the transformation \a t represents an #Isometry
+ * or a more generic #Affine transformation. The default is #Affine.
+ * Other kind of transformations are not supported.
+ */
+ template<int TrOptions>
+ EIGEN_DEVICE_FUNC inline Hyperplane& transform(const Transform<Scalar,AmbientDimAtCompileTime,Affine,TrOptions>& t,
+ TransformTraits traits = Affine)
+ {
+ transform(t.linear(), traits);
+ offset() -= normal().dot(t.translation());
+ return *this;
+ }
+
+ /** \returns \c *this with scalar type casted to \a NewScalarType
+ *
+ * Note that if \a NewScalarType is equal to the current scalar type of \c *this
+ * then this function smartly returns a const reference to \c *this.
+ */
+ template<typename NewScalarType>
+ EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Hyperplane,
+ Hyperplane<NewScalarType,AmbientDimAtCompileTime,Options> >::type cast() const
+ {
+ return typename internal::cast_return_type<Hyperplane,
+ Hyperplane<NewScalarType,AmbientDimAtCompileTime,Options> >::type(*this);
+ }
+
+ /** Copy constructor with scalar type conversion */
+ template<typename OtherScalarType,int OtherOptions>
+ EIGEN_DEVICE_FUNC inline explicit Hyperplane(const Hyperplane<OtherScalarType,AmbientDimAtCompileTime,OtherOptions>& other)
+ { m_coeffs = other.coeffs().template cast<Scalar>(); }
+
+ /** \returns \c true if \c *this is approximately equal to \a other, within the precision
+ * determined by \a prec.
+ *
+ * \sa MatrixBase::isApprox() */
+ template<int OtherOptions>
+ EIGEN_DEVICE_FUNC bool isApprox(const Hyperplane<Scalar,AmbientDimAtCompileTime,OtherOptions>& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
+ { return m_coeffs.isApprox(other.m_coeffs, prec); }
+
+protected:
+
+ Coefficients m_coeffs;
+};
+
+} // end namespace Eigen
+
+#endif // EIGEN_HYPERPLANE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/OrthoMethods.h b/src/3rdparty/eigen/Eigen/src/Geometry/OrthoMethods.h
new file mode 100644
index 000000000..524aebe1b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/OrthoMethods.h
@@ -0,0 +1,235 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ORTHOMETHODS_H
+#define EIGEN_ORTHOMETHODS_H
+
+namespace Eigen {
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \returns the cross product of \c *this and \a other
+ *
+ * Here is a very good explanation of cross-product: http://xkcd.com/199/
+ *
+ * With complex numbers, the cross product is implemented as
+ * \f$ (\mathbf{a}+i\mathbf{b}) \times (\mathbf{c}+i\mathbf{d}) = (\mathbf{a} \times \mathbf{c} - \mathbf{b} \times \mathbf{d}) - i(\mathbf{a} \times \mathbf{d} - \mathbf{b} \times \mathbf{c})\f$
+ *
+ * \sa MatrixBase::cross3()
+ */
+template<typename Derived>
+template<typename OtherDerived>
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename MatrixBase<Derived>::template cross_product_return_type<OtherDerived>::type
+#else
+typename MatrixBase<Derived>::PlainObject
+#endif
+MatrixBase<Derived>::cross(const MatrixBase<OtherDerived>& other) const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,3)
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3)
+
+ // Note that there is no need for an expression here since the compiler
+ // optimize such a small temporary very well (even within a complex expression)
+ typename internal::nested_eval<Derived,2>::type lhs(derived());
+ typename internal::nested_eval<OtherDerived,2>::type rhs(other.derived());
+ return typename cross_product_return_type<OtherDerived>::type(
+ numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
+ numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
+ numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0))
+ );
+}
+
+namespace internal {
+
+template< int Arch,typename VectorLhs,typename VectorRhs,
+ typename Scalar = typename VectorLhs::Scalar,
+ bool Vectorizable = bool((VectorLhs::Flags&VectorRhs::Flags)&PacketAccessBit)>
+struct cross3_impl {
+ EIGEN_DEVICE_FUNC static inline typename internal::plain_matrix_type<VectorLhs>::type
+ run(const VectorLhs& lhs, const VectorRhs& rhs)
+ {
+ return typename internal::plain_matrix_type<VectorLhs>::type(
+ numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
+ numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
+ numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)),
+ 0
+ );
+ }
+};
+
+}
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \returns the cross product of \c *this and \a other using only the x, y, and z coefficients
+ *
+ * The size of \c *this and \a other must be four. This function is especially useful
+ * when using 4D vectors instead of 3D ones to get advantage of SSE/AltiVec vectorization.
+ *
+ * \sa MatrixBase::cross()
+ */
+template<typename Derived>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::PlainObject
+MatrixBase<Derived>::cross3(const MatrixBase<OtherDerived>& other) const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,4)
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,4)
+
+ typedef typename internal::nested_eval<Derived,2>::type DerivedNested;
+ typedef typename internal::nested_eval<OtherDerived,2>::type OtherDerivedNested;
+ DerivedNested lhs(derived());
+ OtherDerivedNested rhs(other.derived());
+
+ return internal::cross3_impl<Architecture::Target,
+ typename internal::remove_all<DerivedNested>::type,
+ typename internal::remove_all<OtherDerivedNested>::type>::run(lhs,rhs);
+}
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \returns a matrix expression of the cross product of each column or row
+ * of the referenced expression with the \a other vector.
+ *
+ * The referenced matrix must have one dimension equal to 3.
+ * The result matrix has the same dimensions than the referenced one.
+ *
+ * \sa MatrixBase::cross() */
+template<typename ExpressionType, int Direction>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+const typename VectorwiseOp<ExpressionType,Direction>::CrossReturnType
+VectorwiseOp<ExpressionType,Direction>::cross(const MatrixBase<OtherDerived>& other) const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3)
+ EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
+ YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
+
+ typename internal::nested_eval<ExpressionType,2>::type mat(_expression());
+ typename internal::nested_eval<OtherDerived,2>::type vec(other.derived());
+
+ CrossReturnType res(_expression().rows(),_expression().cols());
+ if(Direction==Vertical)
+ {
+ eigen_assert(CrossReturnType::RowsAtCompileTime==3 && "the matrix must have exactly 3 rows");
+ res.row(0) = (mat.row(1) * vec.coeff(2) - mat.row(2) * vec.coeff(1)).conjugate();
+ res.row(1) = (mat.row(2) * vec.coeff(0) - mat.row(0) * vec.coeff(2)).conjugate();
+ res.row(2) = (mat.row(0) * vec.coeff(1) - mat.row(1) * vec.coeff(0)).conjugate();
+ }
+ else
+ {
+ eigen_assert(CrossReturnType::ColsAtCompileTime==3 && "the matrix must have exactly 3 columns");
+ res.col(0) = (mat.col(1) * vec.coeff(2) - mat.col(2) * vec.coeff(1)).conjugate();
+ res.col(1) = (mat.col(2) * vec.coeff(0) - mat.col(0) * vec.coeff(2)).conjugate();
+ res.col(2) = (mat.col(0) * vec.coeff(1) - mat.col(1) * vec.coeff(0)).conjugate();
+ }
+ return res;
+}
+
+namespace internal {
+
+template<typename Derived, int Size = Derived::SizeAtCompileTime>
+struct unitOrthogonal_selector
+{
+ typedef typename plain_matrix_type<Derived>::type VectorType;
+ typedef typename traits<Derived>::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef Matrix<Scalar,2,1> Vector2;
+ EIGEN_DEVICE_FUNC
+ static inline VectorType run(const Derived& src)
+ {
+ VectorType perp = VectorType::Zero(src.size());
+ Index maxi = 0;
+ Index sndi = 0;
+ src.cwiseAbs().maxCoeff(&maxi);
+ if (maxi==0)
+ sndi = 1;
+ RealScalar invnm = RealScalar(1)/(Vector2() << src.coeff(sndi),src.coeff(maxi)).finished().norm();
+ perp.coeffRef(maxi) = -numext::conj(src.coeff(sndi)) * invnm;
+ perp.coeffRef(sndi) = numext::conj(src.coeff(maxi)) * invnm;
+
+ return perp;
+ }
+};
+
+template<typename Derived>
+struct unitOrthogonal_selector<Derived,3>
+{
+ typedef typename plain_matrix_type<Derived>::type VectorType;
+ typedef typename traits<Derived>::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ EIGEN_DEVICE_FUNC
+ static inline VectorType run(const Derived& src)
+ {
+ VectorType perp;
+ /* Let us compute the crossed product of *this with a vector
+ * that is not too close to being colinear to *this.
+ */
+
+ /* unless the x and y coords are both close to zero, we can
+ * simply take ( -y, x, 0 ) and normalize it.
+ */
+ if((!isMuchSmallerThan(src.x(), src.z()))
+ || (!isMuchSmallerThan(src.y(), src.z())))
+ {
+ RealScalar invnm = RealScalar(1)/src.template head<2>().norm();
+ perp.coeffRef(0) = -numext::conj(src.y())*invnm;
+ perp.coeffRef(1) = numext::conj(src.x())*invnm;
+ perp.coeffRef(2) = 0;
+ }
+ /* if both x and y are close to zero, then the vector is close
+ * to the z-axis, so it's far from colinear to the x-axis for instance.
+ * So we take the crossed product with (1,0,0) and normalize it.
+ */
+ else
+ {
+ RealScalar invnm = RealScalar(1)/src.template tail<2>().norm();
+ perp.coeffRef(0) = 0;
+ perp.coeffRef(1) = -numext::conj(src.z())*invnm;
+ perp.coeffRef(2) = numext::conj(src.y())*invnm;
+ }
+
+ return perp;
+ }
+};
+
+template<typename Derived>
+struct unitOrthogonal_selector<Derived,2>
+{
+ typedef typename plain_matrix_type<Derived>::type VectorType;
+ EIGEN_DEVICE_FUNC
+ static inline VectorType run(const Derived& src)
+ { return VectorType(-numext::conj(src.y()), numext::conj(src.x())).normalized(); }
+};
+
+} // end namespace internal
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \returns a unit vector which is orthogonal to \c *this
+ *
+ * The size of \c *this must be at least 2. If the size is exactly 2,
+ * then the returned vector is a counter clock wise rotation of \c *this, i.e., (-y,x).normalized().
+ *
+ * \sa cross()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC typename MatrixBase<Derived>::PlainObject
+MatrixBase<Derived>::unitOrthogonal() const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return internal::unitOrthogonal_selector<Derived>::run(derived());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_ORTHOMETHODS_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/ParametrizedLine.h b/src/3rdparty/eigen/Eigen/src/Geometry/ParametrizedLine.h
new file mode 100644
index 000000000..584f50087
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/ParametrizedLine.h
@@ -0,0 +1,232 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PARAMETRIZEDLINE_H
+#define EIGEN_PARAMETRIZEDLINE_H
+
+namespace Eigen {
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \class ParametrizedLine
+ *
+ * \brief A parametrized line
+ *
+ * A parametrized line is defined by an origin point \f$ \mathbf{o} \f$ and a unit
+ * direction vector \f$ \mathbf{d} \f$ such that the line corresponds to
+ * the set \f$ l(t) = \mathbf{o} + t \mathbf{d} \f$, \f$ t \in \mathbf{R} \f$.
+ *
+ * \tparam _Scalar the scalar type, i.e., the type of the coefficients
+ * \tparam _AmbientDim the dimension of the ambient space, can be a compile time value or Dynamic.
+ */
+template <typename _Scalar, int _AmbientDim, int _Options>
+class ParametrizedLine
+{
+public:
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim)
+ enum {
+ AmbientDimAtCompileTime = _AmbientDim,
+ Options = _Options
+ };
+ typedef _Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+ typedef Matrix<Scalar,AmbientDimAtCompileTime,1,Options> VectorType;
+
+ /** Default constructor without initialization */
+ EIGEN_DEVICE_FUNC inline ParametrizedLine() {}
+
+ template<int OtherOptions>
+ EIGEN_DEVICE_FUNC ParametrizedLine(const ParametrizedLine<Scalar,AmbientDimAtCompileTime,OtherOptions>& other)
+ : m_origin(other.origin()), m_direction(other.direction())
+ {}
+
+ /** Constructs a dynamic-size line with \a _dim the dimension
+ * of the ambient space */
+ EIGEN_DEVICE_FUNC inline explicit ParametrizedLine(Index _dim) : m_origin(_dim), m_direction(_dim) {}
+
+ /** Initializes a parametrized line of direction \a direction and origin \a origin.
+ * \warning the vector direction is assumed to be normalized.
+ */
+ EIGEN_DEVICE_FUNC ParametrizedLine(const VectorType& origin, const VectorType& direction)
+ : m_origin(origin), m_direction(direction) {}
+
+ template <int OtherOptions>
+ EIGEN_DEVICE_FUNC explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane);
+
+ /** Constructs a parametrized line going from \a p0 to \a p1. */
+ EIGEN_DEVICE_FUNC static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1)
+ { return ParametrizedLine(p0, (p1-p0).normalized()); }
+
+ EIGEN_DEVICE_FUNC ~ParametrizedLine() {}
+
+ /** \returns the dimension in which the line holds */
+ EIGEN_DEVICE_FUNC inline Index dim() const { return m_direction.size(); }
+
+ EIGEN_DEVICE_FUNC const VectorType& origin() const { return m_origin; }
+ EIGEN_DEVICE_FUNC VectorType& origin() { return m_origin; }
+
+ EIGEN_DEVICE_FUNC const VectorType& direction() const { return m_direction; }
+ EIGEN_DEVICE_FUNC VectorType& direction() { return m_direction; }
+
+ /** \returns the squared distance of a point \a p to its projection onto the line \c *this.
+ * \sa distance()
+ */
+ EIGEN_DEVICE_FUNC RealScalar squaredDistance(const VectorType& p) const
+ {
+ VectorType diff = p - origin();
+ return (diff - direction().dot(diff) * direction()).squaredNorm();
+ }
+ /** \returns the distance of a point \a p to its projection onto the line \c *this.
+ * \sa squaredDistance()
+ */
+ EIGEN_DEVICE_FUNC RealScalar distance(const VectorType& p) const { EIGEN_USING_STD(sqrt) return sqrt(squaredDistance(p)); }
+
+ /** \returns the projection of a point \a p onto the line \c *this. */
+ EIGEN_DEVICE_FUNC VectorType projection(const VectorType& p) const
+ { return origin() + direction().dot(p-origin()) * direction(); }
+
+ EIGEN_DEVICE_FUNC VectorType pointAt(const Scalar& t) const;
+
+ template <int OtherOptions>
+ EIGEN_DEVICE_FUNC Scalar intersectionParameter(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const;
+
+ template <int OtherOptions>
+ EIGEN_DEVICE_FUNC Scalar intersection(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const;
+
+ template <int OtherOptions>
+ EIGEN_DEVICE_FUNC VectorType intersectionPoint(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const;
+
+ /** Applies the transformation matrix \a mat to \c *this and returns a reference to \c *this.
+ *
+ * \param mat the Dim x Dim transformation matrix
+ * \param traits specifies whether the matrix \a mat represents an #Isometry
+ * or a more generic #Affine transformation. The default is #Affine.
+ */
+ template<typename XprType>
+ EIGEN_DEVICE_FUNC inline ParametrizedLine& transform(const MatrixBase<XprType>& mat, TransformTraits traits = Affine)
+ {
+ if (traits==Affine)
+ direction() = (mat * direction()).normalized();
+ else if (traits==Isometry)
+ direction() = mat * direction();
+ else
+ {
+ eigen_assert(0 && "invalid traits value in ParametrizedLine::transform()");
+ }
+ origin() = mat * origin();
+ return *this;
+ }
+
+ /** Applies the transformation \a t to \c *this and returns a reference to \c *this.
+ *
+ * \param t the transformation of dimension Dim
+ * \param traits specifies whether the transformation \a t represents an #Isometry
+ * or a more generic #Affine transformation. The default is #Affine.
+ * Other kind of transformations are not supported.
+ */
+ template<int TrOptions>
+ EIGEN_DEVICE_FUNC inline ParametrizedLine& transform(const Transform<Scalar,AmbientDimAtCompileTime,Affine,TrOptions>& t,
+ TransformTraits traits = Affine)
+ {
+ transform(t.linear(), traits);
+ origin() += t.translation();
+ return *this;
+ }
+
+/** \returns \c *this with scalar type casted to \a NewScalarType
+ *
+ * Note that if \a NewScalarType is equal to the current scalar type of \c *this
+ * then this function smartly returns a const reference to \c *this.
+ */
+ template<typename NewScalarType>
+ EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<ParametrizedLine,
+ ParametrizedLine<NewScalarType,AmbientDimAtCompileTime,Options> >::type cast() const
+ {
+ return typename internal::cast_return_type<ParametrizedLine,
+ ParametrizedLine<NewScalarType,AmbientDimAtCompileTime,Options> >::type(*this);
+ }
+
+ /** Copy constructor with scalar type conversion */
+ template<typename OtherScalarType,int OtherOptions>
+ EIGEN_DEVICE_FUNC inline explicit ParametrizedLine(const ParametrizedLine<OtherScalarType,AmbientDimAtCompileTime,OtherOptions>& other)
+ {
+ m_origin = other.origin().template cast<Scalar>();
+ m_direction = other.direction().template cast<Scalar>();
+ }
+
+ /** \returns \c true if \c *this is approximately equal to \a other, within the precision
+ * determined by \a prec.
+ *
+ * \sa MatrixBase::isApprox() */
+ EIGEN_DEVICE_FUNC bool isApprox(const ParametrizedLine& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
+ { return m_origin.isApprox(other.m_origin, prec) && m_direction.isApprox(other.m_direction, prec); }
+
+protected:
+
+ VectorType m_origin, m_direction;
+};
+
+/** Constructs a parametrized line from a 2D hyperplane
+ *
+ * \warning the ambient space must have dimension 2 such that the hyperplane actually describes a line
+ */
+template <typename _Scalar, int _AmbientDim, int _Options>
+template <int OtherOptions>
+EIGEN_DEVICE_FUNC inline ParametrizedLine<_Scalar, _AmbientDim,_Options>::ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim,OtherOptions>& hyperplane)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
+ direction() = hyperplane.normal().unitOrthogonal();
+ origin() = -hyperplane.normal()*hyperplane.offset();
+}
+
+/** \returns the point at \a t along this line
+ */
+template <typename _Scalar, int _AmbientDim, int _Options>
+EIGEN_DEVICE_FUNC inline typename ParametrizedLine<_Scalar, _AmbientDim,_Options>::VectorType
+ParametrizedLine<_Scalar, _AmbientDim,_Options>::pointAt(const _Scalar& t) const
+{
+ return origin() + (direction()*t);
+}
+
+/** \returns the parameter value of the intersection between \c *this and the given \a hyperplane
+ */
+template <typename _Scalar, int _AmbientDim, int _Options>
+template <int OtherOptions>
+EIGEN_DEVICE_FUNC inline _Scalar ParametrizedLine<_Scalar, _AmbientDim,_Options>::intersectionParameter(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const
+{
+ return -(hyperplane.offset()+hyperplane.normal().dot(origin()))
+ / hyperplane.normal().dot(direction());
+}
+
+
+/** \deprecated use intersectionParameter()
+ * \returns the parameter value of the intersection between \c *this and the given \a hyperplane
+ */
+template <typename _Scalar, int _AmbientDim, int _Options>
+template <int OtherOptions>
+EIGEN_DEVICE_FUNC inline _Scalar ParametrizedLine<_Scalar, _AmbientDim,_Options>::intersection(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const
+{
+ return intersectionParameter(hyperplane);
+}
+
+/** \returns the point of the intersection between \c *this and the given hyperplane
+ */
+template <typename _Scalar, int _AmbientDim, int _Options>
+template <int OtherOptions>
+EIGEN_DEVICE_FUNC inline typename ParametrizedLine<_Scalar, _AmbientDim,_Options>::VectorType
+ParametrizedLine<_Scalar, _AmbientDim,_Options>::intersectionPoint(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const
+{
+ return pointAt(intersectionParameter(hyperplane));
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_PARAMETRIZEDLINE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/Quaternion.h b/src/3rdparty/eigen/Eigen/src/Geometry/Quaternion.h
new file mode 100644
index 000000000..3259e592d
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/Quaternion.h
@@ -0,0 +1,870 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2009 Mathieu Gautier <mathieu.gautier@cea.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_QUATERNION_H
+#define EIGEN_QUATERNION_H
+namespace Eigen {
+
+
+/***************************************************************************
+* Definition of QuaternionBase<Derived>
+* The implementation is at the end of the file
+***************************************************************************/
+
+namespace internal {
+template<typename Other,
+ int OtherRows=Other::RowsAtCompileTime,
+ int OtherCols=Other::ColsAtCompileTime>
+struct quaternionbase_assign_impl;
+}
+
+/** \geometry_module \ingroup Geometry_Module
+ * \class QuaternionBase
+ * \brief Base class for quaternion expressions
+ * \tparam Derived derived type (CRTP)
+ * \sa class Quaternion
+ */
+template<class Derived>
+class QuaternionBase : public RotationBase<Derived, 3>
+{
+ public:
+ typedef RotationBase<Derived, 3> Base;
+
+ using Base::operator*;
+ using Base::derived;
+
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef typename internal::traits<Derived>::Coefficients Coefficients;
+ typedef typename Coefficients::CoeffReturnType CoeffReturnType;
+ typedef typename internal::conditional<bool(internal::traits<Derived>::Flags&LvalueBit),
+ Scalar&, CoeffReturnType>::type NonConstCoeffReturnType;
+
+
+ enum {
+ Flags = Eigen::internal::traits<Derived>::Flags
+ };
+
+ // typedef typename Matrix<Scalar,4,1> Coefficients;
+ /** the type of a 3D vector */
+ typedef Matrix<Scalar,3,1> Vector3;
+ /** the equivalent rotation matrix type */
+ typedef Matrix<Scalar,3,3> Matrix3;
+ /** the equivalent angle-axis type */
+ typedef AngleAxis<Scalar> AngleAxisType;
+
+
+
+ /** \returns the \c x coefficient */
+ EIGEN_DEVICE_FUNC inline CoeffReturnType x() const { return this->derived().coeffs().coeff(0); }
+ /** \returns the \c y coefficient */
+ EIGEN_DEVICE_FUNC inline CoeffReturnType y() const { return this->derived().coeffs().coeff(1); }
+ /** \returns the \c z coefficient */
+ EIGEN_DEVICE_FUNC inline CoeffReturnType z() const { return this->derived().coeffs().coeff(2); }
+ /** \returns the \c w coefficient */
+ EIGEN_DEVICE_FUNC inline CoeffReturnType w() const { return this->derived().coeffs().coeff(3); }
+
+ /** \returns a reference to the \c x coefficient (if Derived is a non-const lvalue) */
+ EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType x() { return this->derived().coeffs().x(); }
+ /** \returns a reference to the \c y coefficient (if Derived is a non-const lvalue) */
+ EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType y() { return this->derived().coeffs().y(); }
+ /** \returns a reference to the \c z coefficient (if Derived is a non-const lvalue) */
+ EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType z() { return this->derived().coeffs().z(); }
+ /** \returns a reference to the \c w coefficient (if Derived is a non-const lvalue) */
+ EIGEN_DEVICE_FUNC inline NonConstCoeffReturnType w() { return this->derived().coeffs().w(); }
+
+ /** \returns a read-only vector expression of the imaginary part (x,y,z) */
+ EIGEN_DEVICE_FUNC inline const VectorBlock<const Coefficients,3> vec() const { return coeffs().template head<3>(); }
+
+ /** \returns a vector expression of the imaginary part (x,y,z) */
+ EIGEN_DEVICE_FUNC inline VectorBlock<Coefficients,3> vec() { return coeffs().template head<3>(); }
+
+ /** \returns a read-only vector expression of the coefficients (x,y,z,w) */
+ EIGEN_DEVICE_FUNC inline const typename internal::traits<Derived>::Coefficients& coeffs() const { return derived().coeffs(); }
+
+ /** \returns a vector expression of the coefficients (x,y,z,w) */
+ EIGEN_DEVICE_FUNC inline typename internal::traits<Derived>::Coefficients& coeffs() { return derived().coeffs(); }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE QuaternionBase<Derived>& operator=(const QuaternionBase<Derived>& other);
+ template<class OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const QuaternionBase<OtherDerived>& other);
+
+// disabled this copy operator as it is giving very strange compilation errors when compiling
+// test_stdvector with GCC 4.4.2. This looks like a GCC bug though, so feel free to re-enable it if it's
+// useful; however notice that we already have the templated operator= above and e.g. in MatrixBase
+// we didn't have to add, in addition to templated operator=, such a non-templated copy operator.
+// Derived& operator=(const QuaternionBase& other)
+// { return operator=<Derived>(other); }
+
+ EIGEN_DEVICE_FUNC Derived& operator=(const AngleAxisType& aa);
+ template<class OtherDerived> EIGEN_DEVICE_FUNC Derived& operator=(const MatrixBase<OtherDerived>& m);
+
+ /** \returns a quaternion representing an identity rotation
+ * \sa MatrixBase::Identity()
+ */
+ EIGEN_DEVICE_FUNC static inline Quaternion<Scalar> Identity() { return Quaternion<Scalar>(Scalar(1), Scalar(0), Scalar(0), Scalar(0)); }
+
+ /** \sa QuaternionBase::Identity(), MatrixBase::setIdentity()
+ */
+ EIGEN_DEVICE_FUNC inline QuaternionBase& setIdentity() { coeffs() << Scalar(0), Scalar(0), Scalar(0), Scalar(1); return *this; }
+
+ /** \returns the squared norm of the quaternion's coefficients
+ * \sa QuaternionBase::norm(), MatrixBase::squaredNorm()
+ */
+ EIGEN_DEVICE_FUNC inline Scalar squaredNorm() const { return coeffs().squaredNorm(); }
+
+ /** \returns the norm of the quaternion's coefficients
+ * \sa QuaternionBase::squaredNorm(), MatrixBase::norm()
+ */
+ EIGEN_DEVICE_FUNC inline Scalar norm() const { return coeffs().norm(); }
+
+ /** Normalizes the quaternion \c *this
+ * \sa normalized(), MatrixBase::normalize() */
+ EIGEN_DEVICE_FUNC inline void normalize() { coeffs().normalize(); }
+ /** \returns a normalized copy of \c *this
+ * \sa normalize(), MatrixBase::normalized() */
+ EIGEN_DEVICE_FUNC inline Quaternion<Scalar> normalized() const { return Quaternion<Scalar>(coeffs().normalized()); }
+
+ /** \returns the dot product of \c *this and \a other
+ * Geometrically speaking, the dot product of two unit quaternions
+ * corresponds to the cosine of half the angle between the two rotations.
+ * \sa angularDistance()
+ */
+ template<class OtherDerived> EIGEN_DEVICE_FUNC inline Scalar dot(const QuaternionBase<OtherDerived>& other) const { return coeffs().dot(other.coeffs()); }
+
+ template<class OtherDerived> EIGEN_DEVICE_FUNC Scalar angularDistance(const QuaternionBase<OtherDerived>& other) const;
+
+ /** \returns an equivalent 3x3 rotation matrix */
+ EIGEN_DEVICE_FUNC inline Matrix3 toRotationMatrix() const;
+
+ /** \returns the quaternion which transform \a a into \a b through a rotation */
+ template<typename Derived1, typename Derived2>
+ EIGEN_DEVICE_FUNC Derived& setFromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b);
+
+ template<class OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion<Scalar> operator* (const QuaternionBase<OtherDerived>& q) const;
+ template<class OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator*= (const QuaternionBase<OtherDerived>& q);
+
+ /** \returns the quaternion describing the inverse rotation */
+ EIGEN_DEVICE_FUNC Quaternion<Scalar> inverse() const;
+
+ /** \returns the conjugated quaternion */
+ EIGEN_DEVICE_FUNC Quaternion<Scalar> conjugate() const;
+
+ template<class OtherDerived> EIGEN_DEVICE_FUNC Quaternion<Scalar> slerp(const Scalar& t, const QuaternionBase<OtherDerived>& other) const;
+
+ /** \returns true if each coefficients of \c *this and \a other are all exactly equal.
+ * \warning When using floating point scalar values you probably should rather use a
+ * fuzzy comparison such as isApprox()
+ * \sa isApprox(), operator!= */
+ template<class OtherDerived>
+ EIGEN_DEVICE_FUNC inline bool operator==(const QuaternionBase<OtherDerived>& other) const
+ { return coeffs() == other.coeffs(); }
+
+ /** \returns true if at least one pair of coefficients of \c *this and \a other are not exactly equal to each other.
+ * \warning When using floating point scalar values you probably should rather use a
+ * fuzzy comparison such as isApprox()
+ * \sa isApprox(), operator== */
+ template<class OtherDerived>
+ EIGEN_DEVICE_FUNC inline bool operator!=(const QuaternionBase<OtherDerived>& other) const
+ { return coeffs() != other.coeffs(); }
+
+ /** \returns \c true if \c *this is approximately equal to \a other, within the precision
+ * determined by \a prec.
+ *
+ * \sa MatrixBase::isApprox() */
+ template<class OtherDerived>
+ EIGEN_DEVICE_FUNC bool isApprox(const QuaternionBase<OtherDerived>& other, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const
+ { return coeffs().isApprox(other.coeffs(), prec); }
+
+ /** return the result vector of \a v through the rotation*/
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Vector3 _transformVector(const Vector3& v) const;
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** \returns \c *this with scalar type casted to \a NewScalarType
+ *
+ * Note that if \a NewScalarType is equal to the current scalar type of \c *this
+ * then this function smartly returns a const reference to \c *this.
+ */
+ template<typename NewScalarType>
+ EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Derived,Quaternion<NewScalarType> >::type cast() const;
+
+ #else
+
+ template<typename NewScalarType>
+ EIGEN_DEVICE_FUNC inline
+ typename internal::enable_if<internal::is_same<Scalar,NewScalarType>::value,const Derived&>::type cast() const
+ {
+ return derived();
+ }
+
+ template<typename NewScalarType>
+ EIGEN_DEVICE_FUNC inline
+ typename internal::enable_if<!internal::is_same<Scalar,NewScalarType>::value,Quaternion<NewScalarType> >::type cast() const
+ {
+ return Quaternion<NewScalarType>(coeffs().template cast<NewScalarType>());
+ }
+ #endif
+
+#ifndef EIGEN_NO_IO
+ friend std::ostream& operator<<(std::ostream& s, const QuaternionBase<Derived>& q) {
+ s << q.x() << "i + " << q.y() << "j + " << q.z() << "k" << " + " << q.w();
+ return s;
+ }
+#endif
+
+#ifdef EIGEN_QUATERNIONBASE_PLUGIN
+# include EIGEN_QUATERNIONBASE_PLUGIN
+#endif
+protected:
+ EIGEN_DEFAULT_COPY_CONSTRUCTOR(QuaternionBase)
+ EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(QuaternionBase)
+};
+
+/***************************************************************************
+* Definition/implementation of Quaternion<Scalar>
+***************************************************************************/
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \class Quaternion
+ *
+ * \brief The quaternion class used to represent 3D orientations and rotations
+ *
+ * \tparam _Scalar the scalar type, i.e., the type of the coefficients
+ * \tparam _Options controls the memory alignment of the coefficients. Can be \# AutoAlign or \# DontAlign. Default is AutoAlign.
+ *
+ * This class represents a quaternion \f$ w+xi+yj+zk \f$ that is a convenient representation of
+ * orientations and rotations of objects in three dimensions. Compared to other representations
+ * like Euler angles or 3x3 matrices, quaternions offer the following advantages:
+ * \li \b compact storage (4 scalars)
+ * \li \b efficient to compose (28 flops),
+ * \li \b stable spherical interpolation
+ *
+ * The following two typedefs are provided for convenience:
+ * \li \c Quaternionf for \c float
+ * \li \c Quaterniond for \c double
+ *
+ * \warning Operations interpreting the quaternion as rotation have undefined behavior if the quaternion is not normalized.
+ *
+ * \sa class AngleAxis, class Transform
+ */
+
+namespace internal {
+template<typename _Scalar,int _Options>
+struct traits<Quaternion<_Scalar,_Options> >
+{
+ typedef Quaternion<_Scalar,_Options> PlainObject;
+ typedef _Scalar Scalar;
+ typedef Matrix<_Scalar,4,1,_Options> Coefficients;
+ enum{
+ Alignment = internal::traits<Coefficients>::Alignment,
+ Flags = LvalueBit
+ };
+};
+}
+
+template<typename _Scalar, int _Options>
+class Quaternion : public QuaternionBase<Quaternion<_Scalar,_Options> >
+{
+public:
+ typedef QuaternionBase<Quaternion<_Scalar,_Options> > Base;
+ enum { NeedsAlignment = internal::traits<Quaternion>::Alignment>0 };
+
+ typedef _Scalar Scalar;
+
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Quaternion)
+ using Base::operator*=;
+
+ typedef typename internal::traits<Quaternion>::Coefficients Coefficients;
+ typedef typename Base::AngleAxisType AngleAxisType;
+
+ /** Default constructor leaving the quaternion uninitialized. */
+ EIGEN_DEVICE_FUNC inline Quaternion() {}
+
+ /** Constructs and initializes the quaternion \f$ w+xi+yj+zk \f$ from
+ * its four coefficients \a w, \a x, \a y and \a z.
+ *
+ * \warning Note the order of the arguments: the real \a w coefficient first,
+ * while internally the coefficients are stored in the following order:
+ * [\c x, \c y, \c z, \c w]
+ */
+ EIGEN_DEVICE_FUNC inline Quaternion(const Scalar& w, const Scalar& x, const Scalar& y, const Scalar& z) : m_coeffs(x, y, z, w){}
+
+ /** Constructs and initialize a quaternion from the array data */
+ EIGEN_DEVICE_FUNC explicit inline Quaternion(const Scalar* data) : m_coeffs(data) {}
+
+ /** Copy constructor */
+ template<class Derived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion(const QuaternionBase<Derived>& other) { this->Base::operator=(other); }
+
+ /** Constructs and initializes a quaternion from the angle-axis \a aa */
+ EIGEN_DEVICE_FUNC explicit inline Quaternion(const AngleAxisType& aa) { *this = aa; }
+
+ /** Constructs and initializes a quaternion from either:
+ * - a rotation matrix expression,
+ * - a 4D vector expression representing quaternion coefficients.
+ */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC explicit inline Quaternion(const MatrixBase<Derived>& other) { *this = other; }
+
+ /** Explicit copy constructor with scalar conversion */
+ template<typename OtherScalar, int OtherOptions>
+ EIGEN_DEVICE_FUNC explicit inline Quaternion(const Quaternion<OtherScalar, OtherOptions>& other)
+ { m_coeffs = other.coeffs().template cast<Scalar>(); }
+
+#if EIGEN_HAS_RVALUE_REFERENCES
+ // We define a copy constructor, which means we don't get an implicit move constructor or assignment operator.
+ /** Default move constructor */
+ EIGEN_DEVICE_FUNC inline Quaternion(Quaternion&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
+ : m_coeffs(std::move(other.coeffs()))
+ {}
+
+ /** Default move assignment operator */
+ EIGEN_DEVICE_FUNC Quaternion& operator=(Quaternion&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
+ {
+ m_coeffs = std::move(other.coeffs());
+ return *this;
+ }
+#endif
+
+ EIGEN_DEVICE_FUNC static Quaternion UnitRandom();
+
+ template<typename Derived1, typename Derived2>
+ EIGEN_DEVICE_FUNC static Quaternion FromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b);
+
+ EIGEN_DEVICE_FUNC inline Coefficients& coeffs() { return m_coeffs;}
+ EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs;}
+
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(bool(NeedsAlignment))
+
+#ifdef EIGEN_QUATERNION_PLUGIN
+# include EIGEN_QUATERNION_PLUGIN
+#endif
+
+protected:
+ Coefficients m_coeffs;
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ static EIGEN_STRONG_INLINE void _check_template_params()
+ {
+ EIGEN_STATIC_ASSERT( (_Options & DontAlign) == _Options,
+ INVALID_MATRIX_TEMPLATE_PARAMETERS)
+ }
+#endif
+};
+
+/** \ingroup Geometry_Module
+ * single precision quaternion type */
+typedef Quaternion<float> Quaternionf;
+/** \ingroup Geometry_Module
+ * double precision quaternion type */
+typedef Quaternion<double> Quaterniond;
+
+/***************************************************************************
+* Specialization of Map<Quaternion<Scalar>>
+***************************************************************************/
+
+namespace internal {
+ template<typename _Scalar, int _Options>
+ struct traits<Map<Quaternion<_Scalar>, _Options> > : traits<Quaternion<_Scalar, (int(_Options)&Aligned)==Aligned ? AutoAlign : DontAlign> >
+ {
+ typedef Map<Matrix<_Scalar,4,1>, _Options> Coefficients;
+ };
+}
+
+namespace internal {
+ template<typename _Scalar, int _Options>
+ struct traits<Map<const Quaternion<_Scalar>, _Options> > : traits<Quaternion<_Scalar, (int(_Options)&Aligned)==Aligned ? AutoAlign : DontAlign> >
+ {
+ typedef Map<const Matrix<_Scalar,4,1>, _Options> Coefficients;
+ typedef traits<Quaternion<_Scalar, (int(_Options)&Aligned)==Aligned ? AutoAlign : DontAlign> > TraitsBase;
+ enum {
+ Flags = TraitsBase::Flags & ~LvalueBit
+ };
+ };
+}
+
+/** \ingroup Geometry_Module
+ * \brief Quaternion expression mapping a constant memory buffer
+ *
+ * \tparam _Scalar the type of the Quaternion coefficients
+ * \tparam _Options see class Map
+ *
+ * This is a specialization of class Map for Quaternion. This class allows to view
+ * a 4 scalar memory buffer as an Eigen's Quaternion object.
+ *
+ * \sa class Map, class Quaternion, class QuaternionBase
+ */
+template<typename _Scalar, int _Options>
+class Map<const Quaternion<_Scalar>, _Options >
+ : public QuaternionBase<Map<const Quaternion<_Scalar>, _Options> >
+{
+ public:
+ typedef QuaternionBase<Map<const Quaternion<_Scalar>, _Options> > Base;
+
+ typedef _Scalar Scalar;
+ typedef typename internal::traits<Map>::Coefficients Coefficients;
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
+ using Base::operator*=;
+
+ /** Constructs a Mapped Quaternion object from the pointer \a coeffs
+ *
+ * The pointer \a coeffs must reference the four coefficients of Quaternion in the following order:
+ * \code *coeffs == {x, y, z, w} \endcode
+ *
+ * If the template parameter _Options is set to #Aligned, then the pointer coeffs must be aligned. */
+ EIGEN_DEVICE_FUNC explicit EIGEN_STRONG_INLINE Map(const Scalar* coeffs) : m_coeffs(coeffs) {}
+
+ EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs;}
+
+ protected:
+ const Coefficients m_coeffs;
+};
+
+/** \ingroup Geometry_Module
+ * \brief Expression of a quaternion from a memory buffer
+ *
+ * \tparam _Scalar the type of the Quaternion coefficients
+ * \tparam _Options see class Map
+ *
+ * This is a specialization of class Map for Quaternion. This class allows to view
+ * a 4 scalar memory buffer as an Eigen's Quaternion object.
+ *
+ * \sa class Map, class Quaternion, class QuaternionBase
+ */
+template<typename _Scalar, int _Options>
+class Map<Quaternion<_Scalar>, _Options >
+ : public QuaternionBase<Map<Quaternion<_Scalar>, _Options> >
+{
+ public:
+ typedef QuaternionBase<Map<Quaternion<_Scalar>, _Options> > Base;
+
+ typedef _Scalar Scalar;
+ typedef typename internal::traits<Map>::Coefficients Coefficients;
+ EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
+ using Base::operator*=;
+
+ /** Constructs a Mapped Quaternion object from the pointer \a coeffs
+ *
+ * The pointer \a coeffs must reference the four coefficients of Quaternion in the following order:
+ * \code *coeffs == {x, y, z, w} \endcode
+ *
+ * If the template parameter _Options is set to #Aligned, then the pointer coeffs must be aligned. */
+ EIGEN_DEVICE_FUNC explicit EIGEN_STRONG_INLINE Map(Scalar* coeffs) : m_coeffs(coeffs) {}
+
+ EIGEN_DEVICE_FUNC inline Coefficients& coeffs() { return m_coeffs; }
+ EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs; }
+
+ protected:
+ Coefficients m_coeffs;
+};
+
+/** \ingroup Geometry_Module
+ * Map an unaligned array of single precision scalars as a quaternion */
+typedef Map<Quaternion<float>, 0> QuaternionMapf;
+/** \ingroup Geometry_Module
+ * Map an unaligned array of double precision scalars as a quaternion */
+typedef Map<Quaternion<double>, 0> QuaternionMapd;
+/** \ingroup Geometry_Module
+ * Map a 16-byte aligned array of single precision scalars as a quaternion */
+typedef Map<Quaternion<float>, Aligned> QuaternionMapAlignedf;
+/** \ingroup Geometry_Module
+ * Map a 16-byte aligned array of double precision scalars as a quaternion */
+typedef Map<Quaternion<double>, Aligned> QuaternionMapAlignedd;
+
+/***************************************************************************
+* Implementation of QuaternionBase methods
+***************************************************************************/
+
+// Generic Quaternion * Quaternion product
+// This product can be specialized for a given architecture via the Arch template argument.
+namespace internal {
+template<int Arch, class Derived1, class Derived2, typename Scalar> struct quat_product
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Quaternion<Scalar> run(const QuaternionBase<Derived1>& a, const QuaternionBase<Derived2>& b){
+ return Quaternion<Scalar>
+ (
+ a.w() * b.w() - a.x() * b.x() - a.y() * b.y() - a.z() * b.z(),
+ a.w() * b.x() + a.x() * b.w() + a.y() * b.z() - a.z() * b.y(),
+ a.w() * b.y() + a.y() * b.w() + a.z() * b.x() - a.x() * b.z(),
+ a.w() * b.z() + a.z() * b.w() + a.x() * b.y() - a.y() * b.x()
+ );
+ }
+};
+}
+
+/** \returns the concatenation of two rotations as a quaternion-quaternion product */
+template <class Derived>
+template <class OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Quaternion<typename internal::traits<Derived>::Scalar>
+QuaternionBase<Derived>::operator* (const QuaternionBase<OtherDerived>& other) const
+{
+ EIGEN_STATIC_ASSERT((internal::is_same<typename Derived::Scalar, typename OtherDerived::Scalar>::value),
+ YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
+ return internal::quat_product<Architecture::Target, Derived, OtherDerived,
+ typename internal::traits<Derived>::Scalar>::run(*this, other);
+}
+
+/** \sa operator*(Quaternion) */
+template <class Derived>
+template <class OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& QuaternionBase<Derived>::operator*= (const QuaternionBase<OtherDerived>& other)
+{
+ derived() = derived() * other.derived();
+ return derived();
+}
+
+/** Rotation of a vector by a quaternion.
+ * \remarks If the quaternion is used to rotate several points (>1)
+ * then it is much more efficient to first convert it to a 3x3 Matrix.
+ * Comparison of the operation cost for n transformations:
+ * - Quaternion2: 30n
+ * - Via a Matrix3: 24 + 15n
+ */
+template <class Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename QuaternionBase<Derived>::Vector3
+QuaternionBase<Derived>::_transformVector(const Vector3& v) const
+{
+ // Note that this algorithm comes from the optimization by hand
+ // of the conversion to a Matrix followed by a Matrix/Vector product.
+ // It appears to be much faster than the common algorithm found
+ // in the literature (30 versus 39 flops). It also requires two
+ // Vector3 as temporaries.
+ Vector3 uv = this->vec().cross(v);
+ uv += uv;
+ return v + this->w() * uv + this->vec().cross(uv);
+}
+
+template<class Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE QuaternionBase<Derived>& QuaternionBase<Derived>::operator=(const QuaternionBase<Derived>& other)
+{
+ coeffs() = other.coeffs();
+ return derived();
+}
+
+template<class Derived>
+template<class OtherDerived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& QuaternionBase<Derived>::operator=(const QuaternionBase<OtherDerived>& other)
+{
+ coeffs() = other.coeffs();
+ return derived();
+}
+
+/** Set \c *this from an angle-axis \a aa and returns a reference to \c *this
+ */
+template<class Derived>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& QuaternionBase<Derived>::operator=(const AngleAxisType& aa)
+{
+ EIGEN_USING_STD(cos)
+ EIGEN_USING_STD(sin)
+ Scalar ha = Scalar(0.5)*aa.angle(); // Scalar(0.5) to suppress precision loss warnings
+ this->w() = cos(ha);
+ this->vec() = sin(ha) * aa.axis();
+ return derived();
+}
+
+/** Set \c *this from the expression \a xpr:
+ * - if \a xpr is a 4x1 vector, then \a xpr is assumed to be a quaternion
+ * - if \a xpr is a 3x3 matrix, then \a xpr is assumed to be rotation matrix
+ * and \a xpr is converted to a quaternion
+ */
+
+template<class Derived>
+template<class MatrixDerived>
+EIGEN_DEVICE_FUNC inline Derived& QuaternionBase<Derived>::operator=(const MatrixBase<MatrixDerived>& xpr)
+{
+ EIGEN_STATIC_ASSERT((internal::is_same<typename Derived::Scalar, typename MatrixDerived::Scalar>::value),
+ YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
+ internal::quaternionbase_assign_impl<MatrixDerived>::run(*this, xpr.derived());
+ return derived();
+}
+
+/** Convert the quaternion to a 3x3 rotation matrix. The quaternion is required to
+ * be normalized, otherwise the result is undefined.
+ */
+template<class Derived>
+EIGEN_DEVICE_FUNC inline typename QuaternionBase<Derived>::Matrix3
+QuaternionBase<Derived>::toRotationMatrix(void) const
+{
+ // NOTE if inlined, then gcc 4.2 and 4.4 get rid of the temporary (not gcc 4.3 !!)
+ // if not inlined then the cost of the return by value is huge ~ +35%,
+ // however, not inlining this function is an order of magnitude slower, so
+ // it has to be inlined, and so the return by value is not an issue
+ Matrix3 res;
+
+ const Scalar tx = Scalar(2)*this->x();
+ const Scalar ty = Scalar(2)*this->y();
+ const Scalar tz = Scalar(2)*this->z();
+ const Scalar twx = tx*this->w();
+ const Scalar twy = ty*this->w();
+ const Scalar twz = tz*this->w();
+ const Scalar txx = tx*this->x();
+ const Scalar txy = ty*this->x();
+ const Scalar txz = tz*this->x();
+ const Scalar tyy = ty*this->y();
+ const Scalar tyz = tz*this->y();
+ const Scalar tzz = tz*this->z();
+
+ res.coeffRef(0,0) = Scalar(1)-(tyy+tzz);
+ res.coeffRef(0,1) = txy-twz;
+ res.coeffRef(0,2) = txz+twy;
+ res.coeffRef(1,0) = txy+twz;
+ res.coeffRef(1,1) = Scalar(1)-(txx+tzz);
+ res.coeffRef(1,2) = tyz-twx;
+ res.coeffRef(2,0) = txz-twy;
+ res.coeffRef(2,1) = tyz+twx;
+ res.coeffRef(2,2) = Scalar(1)-(txx+tyy);
+
+ return res;
+}
+
+/** Sets \c *this to be a quaternion representing a rotation between
+ * the two arbitrary vectors \a a and \a b. In other words, the built
+ * rotation represent a rotation sending the line of direction \a a
+ * to the line of direction \a b, both lines passing through the origin.
+ *
+ * \returns a reference to \c *this.
+ *
+ * Note that the two input vectors do \b not have to be normalized, and
+ * do not need to have the same norm.
+ */
+template<class Derived>
+template<typename Derived1, typename Derived2>
+EIGEN_DEVICE_FUNC inline Derived& QuaternionBase<Derived>::setFromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b)
+{
+ EIGEN_USING_STD(sqrt)
+ Vector3 v0 = a.normalized();
+ Vector3 v1 = b.normalized();
+ Scalar c = v1.dot(v0);
+
+ // if dot == -1, vectors are nearly opposites
+ // => accurately compute the rotation axis by computing the
+ // intersection of the two planes. This is done by solving:
+ // x^T v0 = 0
+ // x^T v1 = 0
+ // under the constraint:
+ // ||x|| = 1
+ // which yields a singular value problem
+ if (c < Scalar(-1)+NumTraits<Scalar>::dummy_precision())
+ {
+ c = numext::maxi(c,Scalar(-1));
+ Matrix<Scalar,2,3> m; m << v0.transpose(), v1.transpose();
+ JacobiSVD<Matrix<Scalar,2,3> > svd(m, ComputeFullV);
+ Vector3 axis = svd.matrixV().col(2);
+
+ Scalar w2 = (Scalar(1)+c)*Scalar(0.5);
+ this->w() = sqrt(w2);
+ this->vec() = axis * sqrt(Scalar(1) - w2);
+ return derived();
+ }
+ Vector3 axis = v0.cross(v1);
+ Scalar s = sqrt((Scalar(1)+c)*Scalar(2));
+ Scalar invs = Scalar(1)/s;
+ this->vec() = axis * invs;
+ this->w() = s * Scalar(0.5);
+
+ return derived();
+}
+
+/** \returns a random unit quaternion following a uniform distribution law on SO(3)
+ *
+ * \note The implementation is based on http://planning.cs.uiuc.edu/node198.html
+ */
+template<typename Scalar, int Options>
+EIGEN_DEVICE_FUNC Quaternion<Scalar,Options> Quaternion<Scalar,Options>::UnitRandom()
+{
+ EIGEN_USING_STD(sqrt)
+ EIGEN_USING_STD(sin)
+ EIGEN_USING_STD(cos)
+ const Scalar u1 = internal::random<Scalar>(0, 1),
+ u2 = internal::random<Scalar>(0, 2*EIGEN_PI),
+ u3 = internal::random<Scalar>(0, 2*EIGEN_PI);
+ const Scalar a = sqrt(Scalar(1) - u1),
+ b = sqrt(u1);
+ return Quaternion (a * sin(u2), a * cos(u2), b * sin(u3), b * cos(u3));
+}
+
+
+/** Returns a quaternion representing a rotation between
+ * the two arbitrary vectors \a a and \a b. In other words, the built
+ * rotation represent a rotation sending the line of direction \a a
+ * to the line of direction \a b, both lines passing through the origin.
+ *
+ * \returns resulting quaternion
+ *
+ * Note that the two input vectors do \b not have to be normalized, and
+ * do not need to have the same norm.
+ */
+template<typename Scalar, int Options>
+template<typename Derived1, typename Derived2>
+EIGEN_DEVICE_FUNC Quaternion<Scalar,Options> Quaternion<Scalar,Options>::FromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b)
+{
+ Quaternion quat;
+ quat.setFromTwoVectors(a, b);
+ return quat;
+}
+
+
+/** \returns the multiplicative inverse of \c *this
+ * Note that in most cases, i.e., if you simply want the opposite rotation,
+ * and/or the quaternion is normalized, then it is enough to use the conjugate.
+ *
+ * \sa QuaternionBase::conjugate()
+ */
+template <class Derived>
+EIGEN_DEVICE_FUNC inline Quaternion<typename internal::traits<Derived>::Scalar> QuaternionBase<Derived>::inverse() const
+{
+ // FIXME should this function be called multiplicativeInverse and conjugate() be called inverse() or opposite() ??
+ Scalar n2 = this->squaredNorm();
+ if (n2 > Scalar(0))
+ return Quaternion<Scalar>(conjugate().coeffs() / n2);
+ else
+ {
+ // return an invalid result to flag the error
+ return Quaternion<Scalar>(Coefficients::Zero());
+ }
+}
+
+// Generic conjugate of a Quaternion
+namespace internal {
+template<int Arch, class Derived, typename Scalar> struct quat_conj
+{
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Quaternion<Scalar> run(const QuaternionBase<Derived>& q){
+ return Quaternion<Scalar>(q.w(),-q.x(),-q.y(),-q.z());
+ }
+};
+}
+
+/** \returns the conjugate of the \c *this which is equal to the multiplicative inverse
+ * if the quaternion is normalized.
+ * The conjugate of a quaternion represents the opposite rotation.
+ *
+ * \sa Quaternion2::inverse()
+ */
+template <class Derived>
+EIGEN_DEVICE_FUNC inline Quaternion<typename internal::traits<Derived>::Scalar>
+QuaternionBase<Derived>::conjugate() const
+{
+ return internal::quat_conj<Architecture::Target, Derived,
+ typename internal::traits<Derived>::Scalar>::run(*this);
+
+}
+
+/** \returns the angle (in radian) between two rotations
+ * \sa dot()
+ */
+template <class Derived>
+template <class OtherDerived>
+EIGEN_DEVICE_FUNC inline typename internal::traits<Derived>::Scalar
+QuaternionBase<Derived>::angularDistance(const QuaternionBase<OtherDerived>& other) const
+{
+ EIGEN_USING_STD(atan2)
+ Quaternion<Scalar> d = (*this) * other.conjugate();
+ return Scalar(2) * atan2( d.vec().norm(), numext::abs(d.w()) );
+}
+
+
+
+/** \returns the spherical linear interpolation between the two quaternions
+ * \c *this and \a other at the parameter \a t in [0;1].
+ *
+ * This represents an interpolation for a constant motion between \c *this and \a other,
+ * see also http://en.wikipedia.org/wiki/Slerp.
+ */
+template <class Derived>
+template <class OtherDerived>
+EIGEN_DEVICE_FUNC Quaternion<typename internal::traits<Derived>::Scalar>
+QuaternionBase<Derived>::slerp(const Scalar& t, const QuaternionBase<OtherDerived>& other) const
+{
+ EIGEN_USING_STD(acos)
+ EIGEN_USING_STD(sin)
+ const Scalar one = Scalar(1) - NumTraits<Scalar>::epsilon();
+ Scalar d = this->dot(other);
+ Scalar absD = numext::abs(d);
+
+ Scalar scale0;
+ Scalar scale1;
+
+ if(absD>=one)
+ {
+ scale0 = Scalar(1) - t;
+ scale1 = t;
+ }
+ else
+ {
+ // theta is the angle between the 2 quaternions
+ Scalar theta = acos(absD);
+ Scalar sinTheta = sin(theta);
+
+ scale0 = sin( ( Scalar(1) - t ) * theta) / sinTheta;
+ scale1 = sin( ( t * theta) ) / sinTheta;
+ }
+ if(d<Scalar(0)) scale1 = -scale1;
+
+ return Quaternion<Scalar>(scale0 * coeffs() + scale1 * other.coeffs());
+}
+
+namespace internal {
+
+// set from a rotation matrix
+template<typename Other>
+struct quaternionbase_assign_impl<Other,3,3>
+{
+ typedef typename Other::Scalar Scalar;
+ template<class Derived> EIGEN_DEVICE_FUNC static inline void run(QuaternionBase<Derived>& q, const Other& a_mat)
+ {
+ const typename internal::nested_eval<Other,2>::type mat(a_mat);
+ EIGEN_USING_STD(sqrt)
+ // This algorithm comes from "Quaternion Calculus and Fast Animation",
+ // Ken Shoemake, 1987 SIGGRAPH course notes
+ Scalar t = mat.trace();
+ if (t > Scalar(0))
+ {
+ t = sqrt(t + Scalar(1.0));
+ q.w() = Scalar(0.5)*t;
+ t = Scalar(0.5)/t;
+ q.x() = (mat.coeff(2,1) - mat.coeff(1,2)) * t;
+ q.y() = (mat.coeff(0,2) - mat.coeff(2,0)) * t;
+ q.z() = (mat.coeff(1,0) - mat.coeff(0,1)) * t;
+ }
+ else
+ {
+ Index i = 0;
+ if (mat.coeff(1,1) > mat.coeff(0,0))
+ i = 1;
+ if (mat.coeff(2,2) > mat.coeff(i,i))
+ i = 2;
+ Index j = (i+1)%3;
+ Index k = (j+1)%3;
+
+ t = sqrt(mat.coeff(i,i)-mat.coeff(j,j)-mat.coeff(k,k) + Scalar(1.0));
+ q.coeffs().coeffRef(i) = Scalar(0.5) * t;
+ t = Scalar(0.5)/t;
+ q.w() = (mat.coeff(k,j)-mat.coeff(j,k))*t;
+ q.coeffs().coeffRef(j) = (mat.coeff(j,i)+mat.coeff(i,j))*t;
+ q.coeffs().coeffRef(k) = (mat.coeff(k,i)+mat.coeff(i,k))*t;
+ }
+ }
+};
+
+// set from a vector of coefficients assumed to be a quaternion
+template<typename Other>
+struct quaternionbase_assign_impl<Other,4,1>
+{
+ typedef typename Other::Scalar Scalar;
+ template<class Derived> EIGEN_DEVICE_FUNC static inline void run(QuaternionBase<Derived>& q, const Other& vec)
+ {
+ q.coeffs() = vec;
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_QUATERNION_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/Rotation2D.h b/src/3rdparty/eigen/Eigen/src/Geometry/Rotation2D.h
new file mode 100644
index 000000000..d0bd57569
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/Rotation2D.h
@@ -0,0 +1,199 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ROTATION2D_H
+#define EIGEN_ROTATION2D_H
+
+namespace Eigen {
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \class Rotation2D
+ *
+ * \brief Represents a rotation/orientation in a 2 dimensional space.
+ *
+ * \tparam _Scalar the scalar type, i.e., the type of the coefficients
+ *
+ * This class is equivalent to a single scalar representing a counter clock wise rotation
+ * as a single angle in radian. It provides some additional features such as the automatic
+ * conversion from/to a 2x2 rotation matrix. Moreover this class aims to provide a similar
+ * interface to Quaternion in order to facilitate the writing of generic algorithms
+ * dealing with rotations.
+ *
+ * \sa class Quaternion, class Transform
+ */
+
+namespace internal {
+
+template<typename _Scalar> struct traits<Rotation2D<_Scalar> >
+{
+ typedef _Scalar Scalar;
+};
+} // end namespace internal
+
+template<typename _Scalar>
+class Rotation2D : public RotationBase<Rotation2D<_Scalar>,2>
+{
+ typedef RotationBase<Rotation2D<_Scalar>,2> Base;
+
+public:
+
+ using Base::operator*;
+
+ enum { Dim = 2 };
+ /** the scalar type of the coefficients */
+ typedef _Scalar Scalar;
+ typedef Matrix<Scalar,2,1> Vector2;
+ typedef Matrix<Scalar,2,2> Matrix2;
+
+protected:
+
+ Scalar m_angle;
+
+public:
+
+ /** Construct a 2D counter clock wise rotation from the angle \a a in radian. */
+ EIGEN_DEVICE_FUNC explicit inline Rotation2D(const Scalar& a) : m_angle(a) {}
+
+ /** Default constructor wihtout initialization. The represented rotation is undefined. */
+ EIGEN_DEVICE_FUNC Rotation2D() {}
+
+ /** Construct a 2D rotation from a 2x2 rotation matrix \a mat.
+ *
+ * \sa fromRotationMatrix()
+ */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC explicit Rotation2D(const MatrixBase<Derived>& m)
+ {
+ fromRotationMatrix(m.derived());
+ }
+
+ /** \returns the rotation angle */
+ EIGEN_DEVICE_FUNC inline Scalar angle() const { return m_angle; }
+
+ /** \returns a read-write reference to the rotation angle */
+ EIGEN_DEVICE_FUNC inline Scalar& angle() { return m_angle; }
+
+ /** \returns the rotation angle in [0,2pi] */
+ EIGEN_DEVICE_FUNC inline Scalar smallestPositiveAngle() const {
+ Scalar tmp = numext::fmod(m_angle,Scalar(2*EIGEN_PI));
+ return tmp<Scalar(0) ? tmp + Scalar(2*EIGEN_PI) : tmp;
+ }
+
+ /** \returns the rotation angle in [-pi,pi] */
+ EIGEN_DEVICE_FUNC inline Scalar smallestAngle() const {
+ Scalar tmp = numext::fmod(m_angle,Scalar(2*EIGEN_PI));
+ if(tmp>Scalar(EIGEN_PI)) tmp -= Scalar(2*EIGEN_PI);
+ else if(tmp<-Scalar(EIGEN_PI)) tmp += Scalar(2*EIGEN_PI);
+ return tmp;
+ }
+
+ /** \returns the inverse rotation */
+ EIGEN_DEVICE_FUNC inline Rotation2D inverse() const { return Rotation2D(-m_angle); }
+
+ /** Concatenates two rotations */
+ EIGEN_DEVICE_FUNC inline Rotation2D operator*(const Rotation2D& other) const
+ { return Rotation2D(m_angle + other.m_angle); }
+
+ /** Concatenates two rotations */
+ EIGEN_DEVICE_FUNC inline Rotation2D& operator*=(const Rotation2D& other)
+ { m_angle += other.m_angle; return *this; }
+
+ /** Applies the rotation to a 2D vector */
+ EIGEN_DEVICE_FUNC Vector2 operator* (const Vector2& vec) const
+ { return toRotationMatrix() * vec; }
+
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC Rotation2D& fromRotationMatrix(const MatrixBase<Derived>& m);
+ EIGEN_DEVICE_FUNC Matrix2 toRotationMatrix() const;
+
+ /** Set \c *this from a 2x2 rotation matrix \a mat.
+ * In other words, this function extract the rotation angle from the rotation matrix.
+ *
+ * This method is an alias for fromRotationMatrix()
+ *
+ * \sa fromRotationMatrix()
+ */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC Rotation2D& operator=(const MatrixBase<Derived>& m)
+ { return fromRotationMatrix(m.derived()); }
+
+ /** \returns the spherical interpolation between \c *this and \a other using
+ * parameter \a t. It is in fact equivalent to a linear interpolation.
+ */
+ EIGEN_DEVICE_FUNC inline Rotation2D slerp(const Scalar& t, const Rotation2D& other) const
+ {
+ Scalar dist = Rotation2D(other.m_angle-m_angle).smallestAngle();
+ return Rotation2D(m_angle + dist*t);
+ }
+
+ /** \returns \c *this with scalar type casted to \a NewScalarType
+ *
+ * Note that if \a NewScalarType is equal to the current scalar type of \c *this
+ * then this function smartly returns a const reference to \c *this.
+ */
+ template<typename NewScalarType>
+ EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type cast() const
+ { return typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type(*this); }
+
+ /** Copy constructor with scalar type conversion */
+ template<typename OtherScalarType>
+ EIGEN_DEVICE_FUNC inline explicit Rotation2D(const Rotation2D<OtherScalarType>& other)
+ {
+ m_angle = Scalar(other.angle());
+ }
+
+ EIGEN_DEVICE_FUNC static inline Rotation2D Identity() { return Rotation2D(0); }
+
+ /** \returns \c true if \c *this is approximately equal to \a other, within the precision
+ * determined by \a prec.
+ *
+ * \sa MatrixBase::isApprox() */
+ EIGEN_DEVICE_FUNC bool isApprox(const Rotation2D& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
+ { return internal::isApprox(m_angle,other.m_angle, prec); }
+
+};
+
+/** \ingroup Geometry_Module
+ * single precision 2D rotation type */
+typedef Rotation2D<float> Rotation2Df;
+/** \ingroup Geometry_Module
+ * double precision 2D rotation type */
+typedef Rotation2D<double> Rotation2Dd;
+
+/** Set \c *this from a 2x2 rotation matrix \a mat.
+ * In other words, this function extract the rotation angle
+ * from the rotation matrix.
+ */
+template<typename Scalar>
+template<typename Derived>
+EIGEN_DEVICE_FUNC Rotation2D<Scalar>& Rotation2D<Scalar>::fromRotationMatrix(const MatrixBase<Derived>& mat)
+{
+ EIGEN_USING_STD(atan2)
+ EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime==2 && Derived::ColsAtCompileTime==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
+ m_angle = atan2(mat.coeff(1,0), mat.coeff(0,0));
+ return *this;
+}
+
+/** Constructs and \returns an equivalent 2x2 rotation matrix.
+ */
+template<typename Scalar>
+typename Rotation2D<Scalar>::Matrix2
+EIGEN_DEVICE_FUNC Rotation2D<Scalar>::toRotationMatrix(void) const
+{
+ EIGEN_USING_STD(sin)
+ EIGEN_USING_STD(cos)
+ Scalar sinA = sin(m_angle);
+ Scalar cosA = cos(m_angle);
+ return (Matrix2() << cosA, -sinA, sinA, cosA).finished();
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_ROTATION2D_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/RotationBase.h b/src/3rdparty/eigen/Eigen/src/Geometry/RotationBase.h
new file mode 100644
index 000000000..f0ee0bd03
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/RotationBase.h
@@ -0,0 +1,206 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_ROTATIONBASE_H
+#define EIGEN_ROTATIONBASE_H
+
+namespace Eigen {
+
+// forward declaration
+namespace internal {
+template<typename RotationDerived, typename MatrixType, bool IsVector=MatrixType::IsVectorAtCompileTime>
+struct rotation_base_generic_product_selector;
+}
+
+/** \class RotationBase
+ *
+ * \brief Common base class for compact rotation representations
+ *
+ * \tparam Derived is the derived type, i.e., a rotation type
+ * \tparam _Dim the dimension of the space
+ */
+template<typename Derived, int _Dim>
+class RotationBase
+{
+ public:
+ enum { Dim = _Dim };
+ /** the scalar type of the coefficients */
+ typedef typename internal::traits<Derived>::Scalar Scalar;
+
+ /** corresponding linear transformation matrix type */
+ typedef Matrix<Scalar,Dim,Dim> RotationMatrixType;
+ typedef Matrix<Scalar,Dim,1> VectorType;
+
+ public:
+ EIGEN_DEVICE_FUNC inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
+ EIGEN_DEVICE_FUNC inline Derived& derived() { return *static_cast<Derived*>(this); }
+
+ /** \returns an equivalent rotation matrix */
+ EIGEN_DEVICE_FUNC inline RotationMatrixType toRotationMatrix() const { return derived().toRotationMatrix(); }
+
+ /** \returns an equivalent rotation matrix
+ * This function is added to be conform with the Transform class' naming scheme.
+ */
+ EIGEN_DEVICE_FUNC inline RotationMatrixType matrix() const { return derived().toRotationMatrix(); }
+
+ /** \returns the inverse rotation */
+ EIGEN_DEVICE_FUNC inline Derived inverse() const { return derived().inverse(); }
+
+ /** \returns the concatenation of the rotation \c *this with a translation \a t */
+ EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Isometry> operator*(const Translation<Scalar,Dim>& t) const
+ { return Transform<Scalar,Dim,Isometry>(*this) * t; }
+
+ /** \returns the concatenation of the rotation \c *this with a uniform scaling \a s */
+ EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const UniformScaling<Scalar>& s) const
+ { return toRotationMatrix() * s.factor(); }
+
+ /** \returns the concatenation of the rotation \c *this with a generic expression \a e
+ * \a e can be:
+ * - a DimxDim linear transformation matrix
+ * - a DimxDim diagonal matrix (axis aligned scaling)
+ * - a vector of size Dim
+ */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::rotation_base_generic_product_selector<Derived,OtherDerived,OtherDerived::IsVectorAtCompileTime>::ReturnType
+ operator*(const EigenBase<OtherDerived>& e) const
+ { return internal::rotation_base_generic_product_selector<Derived,OtherDerived>::run(derived(), e.derived()); }
+
+ /** \returns the concatenation of a linear transformation \a l with the rotation \a r */
+ template<typename OtherDerived> friend
+ EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const EigenBase<OtherDerived>& l, const Derived& r)
+ { return l.derived() * r.toRotationMatrix(); }
+
+ /** \returns the concatenation of a scaling \a l with the rotation \a r */
+ EIGEN_DEVICE_FUNC friend inline Transform<Scalar,Dim,Affine> operator*(const DiagonalMatrix<Scalar,Dim>& l, const Derived& r)
+ {
+ Transform<Scalar,Dim,Affine> res(r);
+ res.linear().applyOnTheLeft(l);
+ return res;
+ }
+
+ /** \returns the concatenation of the rotation \c *this with a transformation \a t */
+ template<int Mode, int Options>
+ EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode> operator*(const Transform<Scalar,Dim,Mode,Options>& t) const
+ { return toRotationMatrix() * t; }
+
+ template<typename OtherVectorType>
+ EIGEN_DEVICE_FUNC inline VectorType _transformVector(const OtherVectorType& v) const
+ { return toRotationMatrix() * v; }
+};
+
+namespace internal {
+
+// implementation of the generic product rotation * matrix
+template<typename RotationDerived, typename MatrixType>
+struct rotation_base_generic_product_selector<RotationDerived,MatrixType,false>
+{
+ enum { Dim = RotationDerived::Dim };
+ typedef Matrix<typename RotationDerived::Scalar,Dim,Dim> ReturnType;
+ EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const MatrixType& m)
+ { return r.toRotationMatrix() * m; }
+};
+
+template<typename RotationDerived, typename Scalar, int Dim, int MaxDim>
+struct rotation_base_generic_product_selector< RotationDerived, DiagonalMatrix<Scalar,Dim,MaxDim>, false >
+{
+ typedef Transform<Scalar,Dim,Affine> ReturnType;
+ EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const DiagonalMatrix<Scalar,Dim,MaxDim>& m)
+ {
+ ReturnType res(r);
+ res.linear() *= m;
+ return res;
+ }
+};
+
+template<typename RotationDerived,typename OtherVectorType>
+struct rotation_base_generic_product_selector<RotationDerived,OtherVectorType,true>
+{
+ enum { Dim = RotationDerived::Dim };
+ typedef Matrix<typename RotationDerived::Scalar,Dim,1> ReturnType;
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE ReturnType run(const RotationDerived& r, const OtherVectorType& v)
+ {
+ return r._transformVector(v);
+ }
+};
+
+} // end namespace internal
+
+/** \geometry_module
+ *
+ * \brief Constructs a Dim x Dim rotation matrix from the rotation \a r
+ */
+template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>
+::Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
+{
+ EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
+ *this = r.toRotationMatrix();
+}
+
+/** \geometry_module
+ *
+ * \brief Set a Dim x Dim rotation matrix from the rotation \a r
+ */
+template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>&
+Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>
+::operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
+{
+ EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
+ return *this = r.toRotationMatrix();
+}
+
+namespace internal {
+
+/** \internal
+ *
+ * Helper function to return an arbitrary rotation object to a rotation matrix.
+ *
+ * \tparam Scalar the numeric type of the matrix coefficients
+ * \tparam Dim the dimension of the current space
+ *
+ * It returns a Dim x Dim fixed size matrix.
+ *
+ * Default specializations are provided for:
+ * - any scalar type (2D),
+ * - any matrix expression,
+ * - any type based on RotationBase (e.g., Quaternion, AngleAxis, Rotation2D)
+ *
+ * Currently toRotationMatrix is only used by Transform.
+ *
+ * \sa class Transform, class Rotation2D, class Quaternion, class AngleAxis
+ */
+template<typename Scalar, int Dim>
+EIGEN_DEVICE_FUNC static inline Matrix<Scalar,2,2> toRotationMatrix(const Scalar& s)
+{
+ EIGEN_STATIC_ASSERT(Dim==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
+ return Rotation2D<Scalar>(s).toRotationMatrix();
+}
+
+template<typename Scalar, int Dim, typename OtherDerived>
+EIGEN_DEVICE_FUNC static inline Matrix<Scalar,Dim,Dim> toRotationMatrix(const RotationBase<OtherDerived,Dim>& r)
+{
+ return r.toRotationMatrix();
+}
+
+template<typename Scalar, int Dim, typename OtherDerived>
+EIGEN_DEVICE_FUNC static inline const MatrixBase<OtherDerived>& toRotationMatrix(const MatrixBase<OtherDerived>& mat)
+{
+ EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime==Dim && OtherDerived::ColsAtCompileTime==Dim,
+ YOU_MADE_A_PROGRAMMING_MISTAKE)
+ return mat;
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_ROTATIONBASE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/Scaling.h b/src/3rdparty/eigen/Eigen/src/Geometry/Scaling.h
new file mode 100644
index 000000000..d352f1f2b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/Scaling.h
@@ -0,0 +1,188 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SCALING_H
+#define EIGEN_SCALING_H
+
+namespace Eigen {
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \class UniformScaling
+ *
+ * \brief Represents a generic uniform scaling transformation
+ *
+ * \tparam _Scalar the scalar type, i.e., the type of the coefficients.
+ *
+ * This class represent a uniform scaling transformation. It is the return
+ * type of Scaling(Scalar), and most of the time this is the only way it
+ * is used. In particular, this class is not aimed to be used to store a scaling transformation,
+ * but rather to make easier the constructions and updates of Transform objects.
+ *
+ * To represent an axis aligned scaling, use the DiagonalMatrix class.
+ *
+ * \sa Scaling(), class DiagonalMatrix, MatrixBase::asDiagonal(), class Translation, class Transform
+ */
+
+namespace internal
+{
+ // This helper helps nvcc+MSVC to properly parse this file.
+ // See bug 1412.
+ template <typename Scalar, int Dim, int Mode>
+ struct uniformscaling_times_affine_returntype
+ {
+ enum
+ {
+ NewMode = int(Mode) == int(Isometry) ? Affine : Mode
+ };
+ typedef Transform <Scalar, Dim, NewMode> type;
+ };
+}
+
+template<typename _Scalar>
+class UniformScaling
+{
+public:
+ /** the scalar type of the coefficients */
+ typedef _Scalar Scalar;
+
+protected:
+
+ Scalar m_factor;
+
+public:
+
+ /** Default constructor without initialization. */
+ UniformScaling() {}
+ /** Constructs and initialize a uniform scaling transformation */
+ explicit inline UniformScaling(const Scalar& s) : m_factor(s) {}
+
+ inline const Scalar& factor() const { return m_factor; }
+ inline Scalar& factor() { return m_factor; }
+
+ /** Concatenates two uniform scaling */
+ inline UniformScaling operator* (const UniformScaling& other) const
+ { return UniformScaling(m_factor * other.factor()); }
+
+ /** Concatenates a uniform scaling and a translation */
+ template<int Dim>
+ inline Transform<Scalar,Dim,Affine> operator* (const Translation<Scalar,Dim>& t) const;
+
+ /** Concatenates a uniform scaling and an affine transformation */
+ template<int Dim, int Mode, int Options>
+ inline typename
+ internal::uniformscaling_times_affine_returntype<Scalar,Dim,Mode>::type
+ operator* (const Transform<Scalar, Dim, Mode, Options>& t) const
+ {
+ typename internal::uniformscaling_times_affine_returntype<Scalar,Dim,Mode>::type res = t;
+ res.prescale(factor());
+ return res;
+ }
+
+ /** Concatenates a uniform scaling and a linear transformation matrix */
+ // TODO returns an expression
+ template<typename Derived>
+ inline typename Eigen::internal::plain_matrix_type<Derived>::type operator* (const MatrixBase<Derived>& other) const
+ { return other * m_factor; }
+
+ template<typename Derived,int Dim>
+ inline Matrix<Scalar,Dim,Dim> operator*(const RotationBase<Derived,Dim>& r) const
+ { return r.toRotationMatrix() * m_factor; }
+
+ /** \returns the inverse scaling */
+ inline UniformScaling inverse() const
+ { return UniformScaling(Scalar(1)/m_factor); }
+
+ /** \returns \c *this with scalar type casted to \a NewScalarType
+ *
+ * Note that if \a NewScalarType is equal to the current scalar type of \c *this
+ * then this function smartly returns a const reference to \c *this.
+ */
+ template<typename NewScalarType>
+ inline UniformScaling<NewScalarType> cast() const
+ { return UniformScaling<NewScalarType>(NewScalarType(m_factor)); }
+
+ /** Copy constructor with scalar type conversion */
+ template<typename OtherScalarType>
+ inline explicit UniformScaling(const UniformScaling<OtherScalarType>& other)
+ { m_factor = Scalar(other.factor()); }
+
+ /** \returns \c true if \c *this is approximately equal to \a other, within the precision
+ * determined by \a prec.
+ *
+ * \sa MatrixBase::isApprox() */
+ bool isApprox(const UniformScaling& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
+ { return internal::isApprox(m_factor, other.factor(), prec); }
+
+};
+
+/** \addtogroup Geometry_Module */
+//@{
+
+/** Concatenates a linear transformation matrix and a uniform scaling
+ * \relates UniformScaling
+ */
+// NOTE this operator is defined in MatrixBase and not as a friend function
+// of UniformScaling to fix an internal crash of Intel's ICC
+template<typename Derived,typename Scalar>
+EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,Scalar,product)
+operator*(const MatrixBase<Derived>& matrix, const UniformScaling<Scalar>& s)
+{ return matrix.derived() * s.factor(); }
+
+/** Constructs a uniform scaling from scale factor \a s */
+inline UniformScaling<float> Scaling(float s) { return UniformScaling<float>(s); }
+/** Constructs a uniform scaling from scale factor \a s */
+inline UniformScaling<double> Scaling(double s) { return UniformScaling<double>(s); }
+/** Constructs a uniform scaling from scale factor \a s */
+template<typename RealScalar>
+inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s)
+{ return UniformScaling<std::complex<RealScalar> >(s); }
+
+/** Constructs a 2D axis aligned scaling */
+template<typename Scalar>
+inline DiagonalMatrix<Scalar,2> Scaling(const Scalar& sx, const Scalar& sy)
+{ return DiagonalMatrix<Scalar,2>(sx, sy); }
+/** Constructs a 3D axis aligned scaling */
+template<typename Scalar>
+inline DiagonalMatrix<Scalar,3> Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz)
+{ return DiagonalMatrix<Scalar,3>(sx, sy, sz); }
+
+/** Constructs an axis aligned scaling expression from vector expression \a coeffs
+ * This is an alias for coeffs.asDiagonal()
+ */
+template<typename Derived>
+inline const DiagonalWrapper<const Derived> Scaling(const MatrixBase<Derived>& coeffs)
+{ return coeffs.asDiagonal(); }
+
+/** \deprecated */
+typedef DiagonalMatrix<float, 2> AlignedScaling2f;
+/** \deprecated */
+typedef DiagonalMatrix<double,2> AlignedScaling2d;
+/** \deprecated */
+typedef DiagonalMatrix<float, 3> AlignedScaling3f;
+/** \deprecated */
+typedef DiagonalMatrix<double,3> AlignedScaling3d;
+//@}
+
+template<typename Scalar>
+template<int Dim>
+inline Transform<Scalar,Dim,Affine>
+UniformScaling<Scalar>::operator* (const Translation<Scalar,Dim>& t) const
+{
+ Transform<Scalar,Dim,Affine> res;
+ res.matrix().setZero();
+ res.linear().diagonal().fill(factor());
+ res.translation() = factor() * t.vector();
+ res(Dim,Dim) = Scalar(1);
+ return res;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_SCALING_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/Transform.h b/src/3rdparty/eigen/Eigen/src/Geometry/Transform.h
new file mode 100644
index 000000000..52b8c2a4e
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/Transform.h
@@ -0,0 +1,1563 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TRANSFORM_H
+#define EIGEN_TRANSFORM_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Transform>
+struct transform_traits
+{
+ enum
+ {
+ Dim = Transform::Dim,
+ HDim = Transform::HDim,
+ Mode = Transform::Mode,
+ IsProjective = (int(Mode)==int(Projective))
+ };
+};
+
+template< typename TransformType,
+ typename MatrixType,
+ int Case = transform_traits<TransformType>::IsProjective ? 0
+ : int(MatrixType::RowsAtCompileTime) == int(transform_traits<TransformType>::HDim) ? 1
+ : 2,
+ int RhsCols = MatrixType::ColsAtCompileTime>
+struct transform_right_product_impl;
+
+template< typename Other,
+ int Mode,
+ int Options,
+ int Dim,
+ int HDim,
+ int OtherRows=Other::RowsAtCompileTime,
+ int OtherCols=Other::ColsAtCompileTime>
+struct transform_left_product_impl;
+
+template< typename Lhs,
+ typename Rhs,
+ bool AnyProjective =
+ transform_traits<Lhs>::IsProjective ||
+ transform_traits<Rhs>::IsProjective>
+struct transform_transform_product_impl;
+
+template< typename Other,
+ int Mode,
+ int Options,
+ int Dim,
+ int HDim,
+ int OtherRows=Other::RowsAtCompileTime,
+ int OtherCols=Other::ColsAtCompileTime>
+struct transform_construct_from_matrix;
+
+template<typename TransformType> struct transform_take_affine_part;
+
+template<typename _Scalar, int _Dim, int _Mode, int _Options>
+struct traits<Transform<_Scalar,_Dim,_Mode,_Options> >
+{
+ typedef _Scalar Scalar;
+ typedef Eigen::Index StorageIndex;
+ typedef Dense StorageKind;
+ enum {
+ Dim1 = _Dim==Dynamic ? _Dim : _Dim + 1,
+ RowsAtCompileTime = _Mode==Projective ? Dim1 : _Dim,
+ ColsAtCompileTime = Dim1,
+ MaxRowsAtCompileTime = RowsAtCompileTime,
+ MaxColsAtCompileTime = ColsAtCompileTime,
+ Flags = 0
+ };
+};
+
+template<int Mode> struct transform_make_affine;
+
+} // end namespace internal
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \class Transform
+ *
+ * \brief Represents an homogeneous transformation in a N dimensional space
+ *
+ * \tparam _Scalar the scalar type, i.e., the type of the coefficients
+ * \tparam _Dim the dimension of the space
+ * \tparam _Mode the type of the transformation. Can be:
+ * - #Affine: the transformation is stored as a (Dim+1)^2 matrix,
+ * where the last row is assumed to be [0 ... 0 1].
+ * - #AffineCompact: the transformation is stored as a (Dim)x(Dim+1) matrix.
+ * - #Projective: the transformation is stored as a (Dim+1)^2 matrix
+ * without any assumption.
+ * - #Isometry: same as #Affine with the additional assumption that
+ * the linear part represents a rotation. This assumption is exploited
+ * to speed up some functions such as inverse() and rotation().
+ * \tparam _Options has the same meaning as in class Matrix. It allows to specify DontAlign and/or RowMajor.
+ * These Options are passed directly to the underlying matrix type.
+ *
+ * The homography is internally represented and stored by a matrix which
+ * is available through the matrix() method. To understand the behavior of
+ * this class you have to think a Transform object as its internal
+ * matrix representation. The chosen convention is right multiply:
+ *
+ * \code v' = T * v \endcode
+ *
+ * Therefore, an affine transformation matrix M is shaped like this:
+ *
+ * \f$ \left( \begin{array}{cc}
+ * linear & translation\\
+ * 0 ... 0 & 1
+ * \end{array} \right) \f$
+ *
+ * Note that for a projective transformation the last row can be anything,
+ * and then the interpretation of different parts might be slightly different.
+ *
+ * However, unlike a plain matrix, the Transform class provides many features
+ * simplifying both its assembly and usage. In particular, it can be composed
+ * with any other transformations (Transform,Translation,RotationBase,DiagonalMatrix)
+ * and can be directly used to transform implicit homogeneous vectors. All these
+ * operations are handled via the operator*. For the composition of transformations,
+ * its principle consists to first convert the right/left hand sides of the product
+ * to a compatible (Dim+1)^2 matrix and then perform a pure matrix product.
+ * Of course, internally, operator* tries to perform the minimal number of operations
+ * according to the nature of each terms. Likewise, when applying the transform
+ * to points, the latters are automatically promoted to homogeneous vectors
+ * before doing the matrix product. The conventions to homogeneous representations
+ * are performed as follow:
+ *
+ * \b Translation t (Dim)x(1):
+ * \f$ \left( \begin{array}{cc}
+ * I & t \\
+ * 0\,...\,0 & 1
+ * \end{array} \right) \f$
+ *
+ * \b Rotation R (Dim)x(Dim):
+ * \f$ \left( \begin{array}{cc}
+ * R & 0\\
+ * 0\,...\,0 & 1
+ * \end{array} \right) \f$
+ *<!--
+ * \b Linear \b Matrix L (Dim)x(Dim):
+ * \f$ \left( \begin{array}{cc}
+ * L & 0\\
+ * 0\,...\,0 & 1
+ * \end{array} \right) \f$
+ *
+ * \b Affine \b Matrix A (Dim)x(Dim+1):
+ * \f$ \left( \begin{array}{c}
+ * A\\
+ * 0\,...\,0\,1
+ * \end{array} \right) \f$
+ *-->
+ * \b Scaling \b DiagonalMatrix S (Dim)x(Dim):
+ * \f$ \left( \begin{array}{cc}
+ * S & 0\\
+ * 0\,...\,0 & 1
+ * \end{array} \right) \f$
+ *
+ * \b Column \b point v (Dim)x(1):
+ * \f$ \left( \begin{array}{c}
+ * v\\
+ * 1
+ * \end{array} \right) \f$
+ *
+ * \b Set \b of \b column \b points V1...Vn (Dim)x(n):
+ * \f$ \left( \begin{array}{ccc}
+ * v_1 & ... & v_n\\
+ * 1 & ... & 1
+ * \end{array} \right) \f$
+ *
+ * The concatenation of a Transform object with any kind of other transformation
+ * always returns a Transform object.
+ *
+ * A little exception to the "as pure matrix product" rule is the case of the
+ * transformation of non homogeneous vectors by an affine transformation. In
+ * that case the last matrix row can be ignored, and the product returns non
+ * homogeneous vectors.
+ *
+ * Since, for instance, a Dim x Dim matrix is interpreted as a linear transformation,
+ * it is not possible to directly transform Dim vectors stored in a Dim x Dim matrix.
+ * The solution is either to use a Dim x Dynamic matrix or explicitly request a
+ * vector transformation by making the vector homogeneous:
+ * \code
+ * m' = T * m.colwise().homogeneous();
+ * \endcode
+ * Note that there is zero overhead.
+ *
+ * Conversion methods from/to Qt's QMatrix and QTransform are available if the
+ * preprocessor token EIGEN_QT_SUPPORT is defined.
+ *
+ * This class can be extended with the help of the plugin mechanism described on the page
+ * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_TRANSFORM_PLUGIN.
+ *
+ * \sa class Matrix, class Quaternion
+ */
+template<typename _Scalar, int _Dim, int _Mode, int _Options>
+class Transform
+{
+public:
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim==Dynamic ? Dynamic : (_Dim+1)*(_Dim+1))
+ enum {
+ Mode = _Mode,
+ Options = _Options,
+ Dim = _Dim, ///< space dimension in which the transformation holds
+ HDim = _Dim+1, ///< size of a respective homogeneous vector
+ Rows = int(Mode)==(AffineCompact) ? Dim : HDim
+ };
+ /** the scalar type of the coefficients */
+ typedef _Scalar Scalar;
+ typedef Eigen::Index StorageIndex;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+ /** type of the matrix used to represent the transformation */
+ typedef typename internal::make_proper_matrix_type<Scalar,Rows,HDim,Options>::type MatrixType;
+ /** constified MatrixType */
+ typedef const MatrixType ConstMatrixType;
+ /** type of the matrix used to represent the linear part of the transformation */
+ typedef Matrix<Scalar,Dim,Dim,Options> LinearMatrixType;
+ /** type of read/write reference to the linear part of the transformation */
+ typedef Block<MatrixType,Dim,Dim,int(Mode)==(AffineCompact) && (int(Options)&RowMajor)==0> LinearPart;
+ /** type of read reference to the linear part of the transformation */
+ typedef const Block<ConstMatrixType,Dim,Dim,int(Mode)==(AffineCompact) && (int(Options)&RowMajor)==0> ConstLinearPart;
+ /** type of read/write reference to the affine part of the transformation */
+ typedef typename internal::conditional<int(Mode)==int(AffineCompact),
+ MatrixType&,
+ Block<MatrixType,Dim,HDim> >::type AffinePart;
+ /** type of read reference to the affine part of the transformation */
+ typedef typename internal::conditional<int(Mode)==int(AffineCompact),
+ const MatrixType&,
+ const Block<const MatrixType,Dim,HDim> >::type ConstAffinePart;
+ /** type of a vector */
+ typedef Matrix<Scalar,Dim,1> VectorType;
+ /** type of a read/write reference to the translation part of the rotation */
+ typedef Block<MatrixType,Dim,1,!(internal::traits<MatrixType>::Flags & RowMajorBit)> TranslationPart;
+ /** type of a read reference to the translation part of the rotation */
+ typedef const Block<ConstMatrixType,Dim,1,!(internal::traits<MatrixType>::Flags & RowMajorBit)> ConstTranslationPart;
+ /** corresponding translation type */
+ typedef Translation<Scalar,Dim> TranslationType;
+
+ // this intermediate enum is needed to avoid an ICE with gcc 3.4 and 4.0
+ enum { TransformTimeDiagonalMode = ((Mode==int(Isometry))?Affine:int(Mode)) };
+ /** The return type of the product between a diagonal matrix and a transform */
+ typedef Transform<Scalar,Dim,TransformTimeDiagonalMode> TransformTimeDiagonalReturnType;
+
+protected:
+
+ MatrixType m_matrix;
+
+public:
+
+ /** Default constructor without initialization of the meaningful coefficients.
+ * If Mode==Affine or Mode==Isometry, then the last row is set to [0 ... 0 1] */
+ EIGEN_DEVICE_FUNC inline Transform()
+ {
+ check_template_params();
+ internal::transform_make_affine<(int(Mode)==Affine || int(Mode)==Isometry) ? Affine : AffineCompact>::run(m_matrix);
+ }
+
+ EIGEN_DEVICE_FUNC inline explicit Transform(const TranslationType& t)
+ {
+ check_template_params();
+ *this = t;
+ }
+ EIGEN_DEVICE_FUNC inline explicit Transform(const UniformScaling<Scalar>& s)
+ {
+ check_template_params();
+ *this = s;
+ }
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline explicit Transform(const RotationBase<Derived, Dim>& r)
+ {
+ check_template_params();
+ *this = r;
+ }
+
+ typedef internal::transform_take_affine_part<Transform> take_affine_part;
+
+ /** Constructs and initializes a transformation from a Dim^2 or a (Dim+1)^2 matrix. */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC inline explicit Transform(const EigenBase<OtherDerived>& other)
+ {
+ EIGEN_STATIC_ASSERT((internal::is_same<Scalar,typename OtherDerived::Scalar>::value),
+ YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY);
+
+ check_template_params();
+ internal::transform_construct_from_matrix<OtherDerived,Mode,Options,Dim,HDim>::run(this, other.derived());
+ }
+
+ /** Set \c *this from a Dim^2 or (Dim+1)^2 matrix. */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC inline Transform& operator=(const EigenBase<OtherDerived>& other)
+ {
+ EIGEN_STATIC_ASSERT((internal::is_same<Scalar,typename OtherDerived::Scalar>::value),
+ YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY);
+
+ internal::transform_construct_from_matrix<OtherDerived,Mode,Options,Dim,HDim>::run(this, other.derived());
+ return *this;
+ }
+
+ template<int OtherOptions>
+ EIGEN_DEVICE_FUNC inline Transform(const Transform<Scalar,Dim,Mode,OtherOptions>& other)
+ {
+ check_template_params();
+ // only the options change, we can directly copy the matrices
+ m_matrix = other.matrix();
+ }
+
+ template<int OtherMode,int OtherOptions>
+ EIGEN_DEVICE_FUNC inline Transform(const Transform<Scalar,Dim,OtherMode,OtherOptions>& other)
+ {
+ check_template_params();
+ // prevent conversions as:
+ // Affine | AffineCompact | Isometry = Projective
+ EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(OtherMode==int(Projective), Mode==int(Projective)),
+ YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
+
+ // prevent conversions as:
+ // Isometry = Affine | AffineCompact
+ EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(OtherMode==int(Affine)||OtherMode==int(AffineCompact), Mode!=int(Isometry)),
+ YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
+
+ enum { ModeIsAffineCompact = Mode == int(AffineCompact),
+ OtherModeIsAffineCompact = OtherMode == int(AffineCompact)
+ };
+
+ if(EIGEN_CONST_CONDITIONAL(ModeIsAffineCompact == OtherModeIsAffineCompact))
+ {
+ // We need the block expression because the code is compiled for all
+ // combinations of transformations and will trigger a compile time error
+ // if one tries to assign the matrices directly
+ m_matrix.template block<Dim,Dim+1>(0,0) = other.matrix().template block<Dim,Dim+1>(0,0);
+ makeAffine();
+ }
+ else if(EIGEN_CONST_CONDITIONAL(OtherModeIsAffineCompact))
+ {
+ typedef typename Transform<Scalar,Dim,OtherMode,OtherOptions>::MatrixType OtherMatrixType;
+ internal::transform_construct_from_matrix<OtherMatrixType,Mode,Options,Dim,HDim>::run(this, other.matrix());
+ }
+ else
+ {
+ // here we know that Mode == AffineCompact and OtherMode != AffineCompact.
+ // if OtherMode were Projective, the static assert above would already have caught it.
+ // So the only possibility is that OtherMode == Affine
+ linear() = other.linear();
+ translation() = other.translation();
+ }
+ }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC Transform(const ReturnByValue<OtherDerived>& other)
+ {
+ check_template_params();
+ other.evalTo(*this);
+ }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC Transform& operator=(const ReturnByValue<OtherDerived>& other)
+ {
+ other.evalTo(*this);
+ return *this;
+ }
+
+ #ifdef EIGEN_QT_SUPPORT
+ inline Transform(const QMatrix& other);
+ inline Transform& operator=(const QMatrix& other);
+ inline QMatrix toQMatrix(void) const;
+ inline Transform(const QTransform& other);
+ inline Transform& operator=(const QTransform& other);
+ inline QTransform toQTransform(void) const;
+ #endif
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return int(Mode)==int(Projective) ? m_matrix.cols() : (m_matrix.cols()-1); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
+
+ /** shortcut for m_matrix(row,col);
+ * \sa MatrixBase::operator(Index,Index) const */
+ EIGEN_DEVICE_FUNC inline Scalar operator() (Index row, Index col) const { return m_matrix(row,col); }
+ /** shortcut for m_matrix(row,col);
+ * \sa MatrixBase::operator(Index,Index) */
+ EIGEN_DEVICE_FUNC inline Scalar& operator() (Index row, Index col) { return m_matrix(row,col); }
+
+ /** \returns a read-only expression of the transformation matrix */
+ EIGEN_DEVICE_FUNC inline const MatrixType& matrix() const { return m_matrix; }
+ /** \returns a writable expression of the transformation matrix */
+ EIGEN_DEVICE_FUNC inline MatrixType& matrix() { return m_matrix; }
+
+ /** \returns a read-only expression of the linear part of the transformation */
+ EIGEN_DEVICE_FUNC inline ConstLinearPart linear() const { return ConstLinearPart(m_matrix,0,0); }
+ /** \returns a writable expression of the linear part of the transformation */
+ EIGEN_DEVICE_FUNC inline LinearPart linear() { return LinearPart(m_matrix,0,0); }
+
+ /** \returns a read-only expression of the Dim x HDim affine part of the transformation */
+ EIGEN_DEVICE_FUNC inline ConstAffinePart affine() const { return take_affine_part::run(m_matrix); }
+ /** \returns a writable expression of the Dim x HDim affine part of the transformation */
+ EIGEN_DEVICE_FUNC inline AffinePart affine() { return take_affine_part::run(m_matrix); }
+
+ /** \returns a read-only expression of the translation vector of the transformation */
+ EIGEN_DEVICE_FUNC inline ConstTranslationPart translation() const { return ConstTranslationPart(m_matrix,0,Dim); }
+ /** \returns a writable expression of the translation vector of the transformation */
+ EIGEN_DEVICE_FUNC inline TranslationPart translation() { return TranslationPart(m_matrix,0,Dim); }
+
+ /** \returns an expression of the product between the transform \c *this and a matrix expression \a other.
+ *
+ * The right-hand-side \a other can be either:
+ * \li an homogeneous vector of size Dim+1,
+ * \li a set of homogeneous vectors of size Dim+1 x N,
+ * \li a transformation matrix of size Dim+1 x Dim+1.
+ *
+ * Moreover, if \c *this represents an affine transformation (i.e., Mode!=Projective), then \a other can also be:
+ * \li a point of size Dim (computes: \code this->linear() * other + this->translation()\endcode),
+ * \li a set of N points as a Dim x N matrix (computes: \code (this->linear() * other).colwise() + this->translation()\endcode),
+ *
+ * In all cases, the return type is a matrix or vector of same sizes as the right-hand-side \a other.
+ *
+ * If you want to interpret \a other as a linear or affine transformation, then first convert it to a Transform<> type,
+ * or do your own cooking.
+ *
+ * Finally, if you want to apply Affine transformations to vectors, then explicitly apply the linear part only:
+ * \code
+ * Affine3f A;
+ * Vector3f v1, v2;
+ * v2 = A.linear() * v1;
+ * \endcode
+ *
+ */
+ // note: this function is defined here because some compilers cannot find the respective declaration
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename internal::transform_right_product_impl<Transform, OtherDerived>::ResultType
+ operator * (const EigenBase<OtherDerived> &other) const
+ { return internal::transform_right_product_impl<Transform, OtherDerived>::run(*this,other.derived()); }
+
+ /** \returns the product expression of a transformation matrix \a a times a transform \a b
+ *
+ * The left hand side \a other can be either:
+ * \li a linear transformation matrix of size Dim x Dim,
+ * \li an affine transformation matrix of size Dim x Dim+1,
+ * \li a general transformation matrix of size Dim+1 x Dim+1.
+ */
+ template<typename OtherDerived> friend
+ EIGEN_DEVICE_FUNC inline const typename internal::transform_left_product_impl<OtherDerived,Mode,Options,_Dim,_Dim+1>::ResultType
+ operator * (const EigenBase<OtherDerived> &a, const Transform &b)
+ { return internal::transform_left_product_impl<OtherDerived,Mode,Options,Dim,HDim>::run(a.derived(),b); }
+
+ /** \returns The product expression of a transform \a a times a diagonal matrix \a b
+ *
+ * The rhs diagonal matrix is interpreted as an affine scaling transformation. The
+ * product results in a Transform of the same type (mode) as the lhs only if the lhs
+ * mode is no isometry. In that case, the returned transform is an affinity.
+ */
+ template<typename DiagonalDerived>
+ EIGEN_DEVICE_FUNC inline const TransformTimeDiagonalReturnType
+ operator * (const DiagonalBase<DiagonalDerived> &b) const
+ {
+ TransformTimeDiagonalReturnType res(*this);
+ res.linearExt() *= b;
+ return res;
+ }
+
+ /** \returns The product expression of a diagonal matrix \a a times a transform \a b
+ *
+ * The lhs diagonal matrix is interpreted as an affine scaling transformation. The
+ * product results in a Transform of the same type (mode) as the lhs only if the lhs
+ * mode is no isometry. In that case, the returned transform is an affinity.
+ */
+ template<typename DiagonalDerived>
+ EIGEN_DEVICE_FUNC friend inline TransformTimeDiagonalReturnType
+ operator * (const DiagonalBase<DiagonalDerived> &a, const Transform &b)
+ {
+ TransformTimeDiagonalReturnType res;
+ res.linear().noalias() = a*b.linear();
+ res.translation().noalias() = a*b.translation();
+ if (EIGEN_CONST_CONDITIONAL(Mode!=int(AffineCompact)))
+ res.matrix().row(Dim) = b.matrix().row(Dim);
+ return res;
+ }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC inline Transform& operator*=(const EigenBase<OtherDerived>& other) { return *this = *this * other; }
+
+ /** Concatenates two transformations */
+ EIGEN_DEVICE_FUNC inline const Transform operator * (const Transform& other) const
+ {
+ return internal::transform_transform_product_impl<Transform,Transform>::run(*this,other);
+ }
+
+ #if EIGEN_COMP_ICC
+private:
+ // this intermediate structure permits to workaround a bug in ICC 11:
+ // error: template instantiation resulted in unexpected function type of "Eigen::Transform<double, 3, 32, 0>
+ // (const Eigen::Transform<double, 3, 2, 0> &) const"
+ // (the meaning of a name may have changed since the template declaration -- the type of the template is:
+ // "Eigen::internal::transform_transform_product_impl<Eigen::Transform<double, 3, 32, 0>,
+ // Eigen::Transform<double, 3, Mode, Options>, <expression>>::ResultType (const Eigen::Transform<double, 3, Mode, Options> &) const")
+ //
+ template<int OtherMode,int OtherOptions> struct icc_11_workaround
+ {
+ typedef internal::transform_transform_product_impl<Transform,Transform<Scalar,Dim,OtherMode,OtherOptions> > ProductType;
+ typedef typename ProductType::ResultType ResultType;
+ };
+
+public:
+ /** Concatenates two different transformations */
+ template<int OtherMode,int OtherOptions>
+ inline typename icc_11_workaround<OtherMode,OtherOptions>::ResultType
+ operator * (const Transform<Scalar,Dim,OtherMode,OtherOptions>& other) const
+ {
+ typedef typename icc_11_workaround<OtherMode,OtherOptions>::ProductType ProductType;
+ return ProductType::run(*this,other);
+ }
+ #else
+ /** Concatenates two different transformations */
+ template<int OtherMode,int OtherOptions>
+ EIGEN_DEVICE_FUNC inline typename internal::transform_transform_product_impl<Transform,Transform<Scalar,Dim,OtherMode,OtherOptions> >::ResultType
+ operator * (const Transform<Scalar,Dim,OtherMode,OtherOptions>& other) const
+ {
+ return internal::transform_transform_product_impl<Transform,Transform<Scalar,Dim,OtherMode,OtherOptions> >::run(*this,other);
+ }
+ #endif
+
+ /** \sa MatrixBase::setIdentity() */
+ EIGEN_DEVICE_FUNC void setIdentity() { m_matrix.setIdentity(); }
+
+ /**
+ * \brief Returns an identity transformation.
+ * \todo In the future this function should be returning a Transform expression.
+ */
+ EIGEN_DEVICE_FUNC static const Transform Identity()
+ {
+ return Transform(MatrixType::Identity());
+ }
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ inline Transform& scale(const MatrixBase<OtherDerived> &other);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ inline Transform& prescale(const MatrixBase<OtherDerived> &other);
+
+ EIGEN_DEVICE_FUNC inline Transform& scale(const Scalar& s);
+ EIGEN_DEVICE_FUNC inline Transform& prescale(const Scalar& s);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ inline Transform& translate(const MatrixBase<OtherDerived> &other);
+
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC
+ inline Transform& pretranslate(const MatrixBase<OtherDerived> &other);
+
+ template<typename RotationType>
+ EIGEN_DEVICE_FUNC
+ inline Transform& rotate(const RotationType& rotation);
+
+ template<typename RotationType>
+ EIGEN_DEVICE_FUNC
+ inline Transform& prerotate(const RotationType& rotation);
+
+ EIGEN_DEVICE_FUNC Transform& shear(const Scalar& sx, const Scalar& sy);
+ EIGEN_DEVICE_FUNC Transform& preshear(const Scalar& sx, const Scalar& sy);
+
+ EIGEN_DEVICE_FUNC inline Transform& operator=(const TranslationType& t);
+
+ EIGEN_DEVICE_FUNC
+ inline Transform& operator*=(const TranslationType& t) { return translate(t.vector()); }
+
+ EIGEN_DEVICE_FUNC inline Transform operator*(const TranslationType& t) const;
+
+ EIGEN_DEVICE_FUNC
+ inline Transform& operator=(const UniformScaling<Scalar>& t);
+
+ EIGEN_DEVICE_FUNC
+ inline Transform& operator*=(const UniformScaling<Scalar>& s) { return scale(s.factor()); }
+
+ EIGEN_DEVICE_FUNC
+ inline TransformTimeDiagonalReturnType operator*(const UniformScaling<Scalar>& s) const
+ {
+ TransformTimeDiagonalReturnType res = *this;
+ res.scale(s.factor());
+ return res;
+ }
+
+ EIGEN_DEVICE_FUNC
+ inline Transform& operator*=(const DiagonalMatrix<Scalar,Dim>& s) { linearExt() *= s; return *this; }
+
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline Transform& operator=(const RotationBase<Derived,Dim>& r);
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline Transform& operator*=(const RotationBase<Derived,Dim>& r) { return rotate(r.toRotationMatrix()); }
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline Transform operator*(const RotationBase<Derived,Dim>& r) const;
+
+ typedef typename internal::conditional<int(Mode)==Isometry,ConstLinearPart,const LinearMatrixType>::type RotationReturnType;
+ EIGEN_DEVICE_FUNC RotationReturnType rotation() const;
+
+ template<typename RotationMatrixType, typename ScalingMatrixType>
+ EIGEN_DEVICE_FUNC
+ void computeRotationScaling(RotationMatrixType *rotation, ScalingMatrixType *scaling) const;
+ template<typename ScalingMatrixType, typename RotationMatrixType>
+ EIGEN_DEVICE_FUNC
+ void computeScalingRotation(ScalingMatrixType *scaling, RotationMatrixType *rotation) const;
+
+ template<typename PositionDerived, typename OrientationType, typename ScaleDerived>
+ EIGEN_DEVICE_FUNC
+ Transform& fromPositionOrientationScale(const MatrixBase<PositionDerived> &position,
+ const OrientationType& orientation, const MatrixBase<ScaleDerived> &scale);
+
+ EIGEN_DEVICE_FUNC
+ inline Transform inverse(TransformTraits traits = (TransformTraits)Mode) const;
+
+ /** \returns a const pointer to the column major internal matrix */
+ EIGEN_DEVICE_FUNC const Scalar* data() const { return m_matrix.data(); }
+ /** \returns a non-const pointer to the column major internal matrix */
+ EIGEN_DEVICE_FUNC Scalar* data() { return m_matrix.data(); }
+
+ /** \returns \c *this with scalar type casted to \a NewScalarType
+ *
+ * Note that if \a NewScalarType is equal to the current scalar type of \c *this
+ * then this function smartly returns a const reference to \c *this.
+ */
+ template<typename NewScalarType>
+ EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Transform,Transform<NewScalarType,Dim,Mode,Options> >::type cast() const
+ { return typename internal::cast_return_type<Transform,Transform<NewScalarType,Dim,Mode,Options> >::type(*this); }
+
+ /** Copy constructor with scalar type conversion */
+ template<typename OtherScalarType>
+ EIGEN_DEVICE_FUNC inline explicit Transform(const Transform<OtherScalarType,Dim,Mode,Options>& other)
+ {
+ check_template_params();
+ m_matrix = other.matrix().template cast<Scalar>();
+ }
+
+ /** \returns \c true if \c *this is approximately equal to \a other, within the precision
+ * determined by \a prec.
+ *
+ * \sa MatrixBase::isApprox() */
+ EIGEN_DEVICE_FUNC bool isApprox(const Transform& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
+ { return m_matrix.isApprox(other.m_matrix, prec); }
+
+ /** Sets the last row to [0 ... 0 1]
+ */
+ EIGEN_DEVICE_FUNC void makeAffine()
+ {
+ internal::transform_make_affine<int(Mode)>::run(m_matrix);
+ }
+
+ /** \internal
+ * \returns the Dim x Dim linear part if the transformation is affine,
+ * and the HDim x Dim part for projective transformations.
+ */
+ EIGEN_DEVICE_FUNC inline Block<MatrixType,int(Mode)==int(Projective)?HDim:Dim,Dim> linearExt()
+ { return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,Dim>(0,0); }
+ /** \internal
+ * \returns the Dim x Dim linear part if the transformation is affine,
+ * and the HDim x Dim part for projective transformations.
+ */
+ EIGEN_DEVICE_FUNC inline const Block<MatrixType,int(Mode)==int(Projective)?HDim:Dim,Dim> linearExt() const
+ { return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,Dim>(0,0); }
+
+ /** \internal
+ * \returns the translation part if the transformation is affine,
+ * and the last column for projective transformations.
+ */
+ EIGEN_DEVICE_FUNC inline Block<MatrixType,int(Mode)==int(Projective)?HDim:Dim,1> translationExt()
+ { return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,1>(0,Dim); }
+ /** \internal
+ * \returns the translation part if the transformation is affine,
+ * and the last column for projective transformations.
+ */
+ EIGEN_DEVICE_FUNC inline const Block<MatrixType,int(Mode)==int(Projective)?HDim:Dim,1> translationExt() const
+ { return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,1>(0,Dim); }
+
+
+ #ifdef EIGEN_TRANSFORM_PLUGIN
+ #include EIGEN_TRANSFORM_PLUGIN
+ #endif
+
+protected:
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void check_template_params()
+ {
+ EIGEN_STATIC_ASSERT((Options & (DontAlign|RowMajor)) == Options, INVALID_MATRIX_TEMPLATE_PARAMETERS)
+ }
+ #endif
+
+};
+
+/** \ingroup Geometry_Module */
+typedef Transform<float,2,Isometry> Isometry2f;
+/** \ingroup Geometry_Module */
+typedef Transform<float,3,Isometry> Isometry3f;
+/** \ingroup Geometry_Module */
+typedef Transform<double,2,Isometry> Isometry2d;
+/** \ingroup Geometry_Module */
+typedef Transform<double,3,Isometry> Isometry3d;
+
+/** \ingroup Geometry_Module */
+typedef Transform<float,2,Affine> Affine2f;
+/** \ingroup Geometry_Module */
+typedef Transform<float,3,Affine> Affine3f;
+/** \ingroup Geometry_Module */
+typedef Transform<double,2,Affine> Affine2d;
+/** \ingroup Geometry_Module */
+typedef Transform<double,3,Affine> Affine3d;
+
+/** \ingroup Geometry_Module */
+typedef Transform<float,2,AffineCompact> AffineCompact2f;
+/** \ingroup Geometry_Module */
+typedef Transform<float,3,AffineCompact> AffineCompact3f;
+/** \ingroup Geometry_Module */
+typedef Transform<double,2,AffineCompact> AffineCompact2d;
+/** \ingroup Geometry_Module */
+typedef Transform<double,3,AffineCompact> AffineCompact3d;
+
+/** \ingroup Geometry_Module */
+typedef Transform<float,2,Projective> Projective2f;
+/** \ingroup Geometry_Module */
+typedef Transform<float,3,Projective> Projective3f;
+/** \ingroup Geometry_Module */
+typedef Transform<double,2,Projective> Projective2d;
+/** \ingroup Geometry_Module */
+typedef Transform<double,3,Projective> Projective3d;
+
+/**************************
+*** Optional QT support ***
+**************************/
+
+#ifdef EIGEN_QT_SUPPORT
+/** Initializes \c *this from a QMatrix assuming the dimension is 2.
+ *
+ * This function is available only if the token EIGEN_QT_SUPPORT is defined.
+ */
+template<typename Scalar, int Dim, int Mode,int Options>
+Transform<Scalar,Dim,Mode,Options>::Transform(const QMatrix& other)
+{
+ check_template_params();
+ *this = other;
+}
+
+/** Set \c *this from a QMatrix assuming the dimension is 2.
+ *
+ * This function is available only if the token EIGEN_QT_SUPPORT is defined.
+ */
+template<typename Scalar, int Dim, int Mode,int Options>
+Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(const QMatrix& other)
+{
+ EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
+ if (EIGEN_CONST_CONDITIONAL(Mode == int(AffineCompact)))
+ m_matrix << other.m11(), other.m21(), other.dx(),
+ other.m12(), other.m22(), other.dy();
+ else
+ m_matrix << other.m11(), other.m21(), other.dx(),
+ other.m12(), other.m22(), other.dy(),
+ 0, 0, 1;
+ return *this;
+}
+
+/** \returns a QMatrix from \c *this assuming the dimension is 2.
+ *
+ * \warning this conversion might loss data if \c *this is not affine
+ *
+ * This function is available only if the token EIGEN_QT_SUPPORT is defined.
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+QMatrix Transform<Scalar,Dim,Mode,Options>::toQMatrix(void) const
+{
+ check_template_params();
+ EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
+ return QMatrix(m_matrix.coeff(0,0), m_matrix.coeff(1,0),
+ m_matrix.coeff(0,1), m_matrix.coeff(1,1),
+ m_matrix.coeff(0,2), m_matrix.coeff(1,2));
+}
+
+/** Initializes \c *this from a QTransform assuming the dimension is 2.
+ *
+ * This function is available only if the token EIGEN_QT_SUPPORT is defined.
+ */
+template<typename Scalar, int Dim, int Mode,int Options>
+Transform<Scalar,Dim,Mode,Options>::Transform(const QTransform& other)
+{
+ check_template_params();
+ *this = other;
+}
+
+/** Set \c *this from a QTransform assuming the dimension is 2.
+ *
+ * This function is available only if the token EIGEN_QT_SUPPORT is defined.
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(const QTransform& other)
+{
+ check_template_params();
+ EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
+ if (EIGEN_CONST_CONDITIONAL(Mode == int(AffineCompact)))
+ m_matrix << other.m11(), other.m21(), other.dx(),
+ other.m12(), other.m22(), other.dy();
+ else
+ m_matrix << other.m11(), other.m21(), other.dx(),
+ other.m12(), other.m22(), other.dy(),
+ other.m13(), other.m23(), other.m33();
+ return *this;
+}
+
+/** \returns a QTransform from \c *this assuming the dimension is 2.
+ *
+ * This function is available only if the token EIGEN_QT_SUPPORT is defined.
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+QTransform Transform<Scalar,Dim,Mode,Options>::toQTransform(void) const
+{
+ EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
+ if (EIGEN_CONST_CONDITIONAL(Mode == int(AffineCompact)))
+ return QTransform(m_matrix.coeff(0,0), m_matrix.coeff(1,0),
+ m_matrix.coeff(0,1), m_matrix.coeff(1,1),
+ m_matrix.coeff(0,2), m_matrix.coeff(1,2));
+ else
+ return QTransform(m_matrix.coeff(0,0), m_matrix.coeff(1,0), m_matrix.coeff(2,0),
+ m_matrix.coeff(0,1), m_matrix.coeff(1,1), m_matrix.coeff(2,1),
+ m_matrix.coeff(0,2), m_matrix.coeff(1,2), m_matrix.coeff(2,2));
+}
+#endif
+
+/*********************
+*** Procedural API ***
+*********************/
+
+/** Applies on the right the non uniform scale transformation represented
+ * by the vector \a other to \c *this and returns a reference to \c *this.
+ * \sa prescale()
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>&
+Transform<Scalar,Dim,Mode,Options>::scale(const MatrixBase<OtherDerived> &other)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim))
+ EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
+ linearExt().noalias() = (linearExt() * other.asDiagonal());
+ return *this;
+}
+
+/** Applies on the right a uniform scale of a factor \a c to \c *this
+ * and returns a reference to \c *this.
+ * \sa prescale(Scalar)
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::scale(const Scalar& s)
+{
+ EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
+ linearExt() *= s;
+ return *this;
+}
+
+/** Applies on the left the non uniform scale transformation represented
+ * by the vector \a other to \c *this and returns a reference to \c *this.
+ * \sa scale()
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>&
+Transform<Scalar,Dim,Mode,Options>::prescale(const MatrixBase<OtherDerived> &other)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim))
+ EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
+ affine().noalias() = (other.asDiagonal() * affine());
+ return *this;
+}
+
+/** Applies on the left a uniform scale of a factor \a c to \c *this
+ * and returns a reference to \c *this.
+ * \sa scale(Scalar)
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::prescale(const Scalar& s)
+{
+ EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
+ m_matrix.template topRows<Dim>() *= s;
+ return *this;
+}
+
+/** Applies on the right the translation matrix represented by the vector \a other
+ * to \c *this and returns a reference to \c *this.
+ * \sa pretranslate()
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>&
+Transform<Scalar,Dim,Mode,Options>::translate(const MatrixBase<OtherDerived> &other)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim))
+ translationExt() += linearExt() * other;
+ return *this;
+}
+
+/** Applies on the left the translation matrix represented by the vector \a other
+ * to \c *this and returns a reference to \c *this.
+ * \sa translate()
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>&
+Transform<Scalar,Dim,Mode,Options>::pretranslate(const MatrixBase<OtherDerived> &other)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,int(Dim))
+ if(EIGEN_CONST_CONDITIONAL(int(Mode)==int(Projective)))
+ affine() += other * m_matrix.row(Dim);
+ else
+ translation() += other;
+ return *this;
+}
+
+/** Applies on the right the rotation represented by the rotation \a rotation
+ * to \c *this and returns a reference to \c *this.
+ *
+ * The template parameter \a RotationType is the type of the rotation which
+ * must be known by internal::toRotationMatrix<>.
+ *
+ * Natively supported types includes:
+ * - any scalar (2D),
+ * - a Dim x Dim matrix expression,
+ * - a Quaternion (3D),
+ * - a AngleAxis (3D)
+ *
+ * This mechanism is easily extendable to support user types such as Euler angles,
+ * or a pair of Quaternion for 4D rotations.
+ *
+ * \sa rotate(Scalar), class Quaternion, class AngleAxis, prerotate(RotationType)
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+template<typename RotationType>
+EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>&
+Transform<Scalar,Dim,Mode,Options>::rotate(const RotationType& rotation)
+{
+ linearExt() *= internal::toRotationMatrix<Scalar,Dim>(rotation);
+ return *this;
+}
+
+/** Applies on the left the rotation represented by the rotation \a rotation
+ * to \c *this and returns a reference to \c *this.
+ *
+ * See rotate() for further details.
+ *
+ * \sa rotate()
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+template<typename RotationType>
+EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>&
+Transform<Scalar,Dim,Mode,Options>::prerotate(const RotationType& rotation)
+{
+ m_matrix.template block<Dim,HDim>(0,0) = internal::toRotationMatrix<Scalar,Dim>(rotation)
+ * m_matrix.template block<Dim,HDim>(0,0);
+ return *this;
+}
+
+/** Applies on the right the shear transformation represented
+ * by the vector \a other to \c *this and returns a reference to \c *this.
+ * \warning 2D only.
+ * \sa preshear()
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>&
+Transform<Scalar,Dim,Mode,Options>::shear(const Scalar& sx, const Scalar& sy)
+{
+ EIGEN_STATIC_ASSERT(int(Dim)==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
+ EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
+ VectorType tmp = linear().col(0)*sy + linear().col(1);
+ linear() << linear().col(0) + linear().col(1)*sx, tmp;
+ return *this;
+}
+
+/** Applies on the left the shear transformation represented
+ * by the vector \a other to \c *this and returns a reference to \c *this.
+ * \warning 2D only.
+ * \sa shear()
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>&
+Transform<Scalar,Dim,Mode,Options>::preshear(const Scalar& sx, const Scalar& sy)
+{
+ EIGEN_STATIC_ASSERT(int(Dim)==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
+ EIGEN_STATIC_ASSERT(Mode!=int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
+ m_matrix.template block<Dim,HDim>(0,0) = LinearMatrixType(1, sx, sy, 1) * m_matrix.template block<Dim,HDim>(0,0);
+ return *this;
+}
+
+/******************************************************
+*** Scaling, Translation and Rotation compatibility ***
+******************************************************/
+
+template<typename Scalar, int Dim, int Mode, int Options>
+EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(const TranslationType& t)
+{
+ linear().setIdentity();
+ translation() = t.vector();
+ makeAffine();
+ return *this;
+}
+
+template<typename Scalar, int Dim, int Mode, int Options>
+EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options> Transform<Scalar,Dim,Mode,Options>::operator*(const TranslationType& t) const
+{
+ Transform res = *this;
+ res.translate(t.vector());
+ return res;
+}
+
+template<typename Scalar, int Dim, int Mode, int Options>
+EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(const UniformScaling<Scalar>& s)
+{
+ m_matrix.setZero();
+ linear().diagonal().fill(s.factor());
+ makeAffine();
+ return *this;
+}
+
+template<typename Scalar, int Dim, int Mode, int Options>
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(const RotationBase<Derived,Dim>& r)
+{
+ linear() = internal::toRotationMatrix<Scalar,Dim>(r);
+ translation().setZero();
+ makeAffine();
+ return *this;
+}
+
+template<typename Scalar, int Dim, int Mode, int Options>
+template<typename Derived>
+EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode,Options> Transform<Scalar,Dim,Mode,Options>::operator*(const RotationBase<Derived,Dim>& r) const
+{
+ Transform res = *this;
+ res.rotate(r.derived());
+ return res;
+}
+
+/************************
+*** Special functions ***
+************************/
+
+namespace internal {
+template<int Mode> struct transform_rotation_impl {
+ template<typename TransformType>
+ EIGEN_DEVICE_FUNC static inline
+ const typename TransformType::LinearMatrixType run(const TransformType& t)
+ {
+ typedef typename TransformType::LinearMatrixType LinearMatrixType;
+ LinearMatrixType result;
+ t.computeRotationScaling(&result, (LinearMatrixType*)0);
+ return result;
+ }
+};
+template<> struct transform_rotation_impl<Isometry> {
+ template<typename TransformType>
+ EIGEN_DEVICE_FUNC static inline
+ typename TransformType::ConstLinearPart run(const TransformType& t)
+ {
+ return t.linear();
+ }
+};
+}
+/** \returns the rotation part of the transformation
+ *
+ * If Mode==Isometry, then this method is an alias for linear(),
+ * otherwise it calls computeRotationScaling() to extract the rotation
+ * through a SVD decomposition.
+ *
+ * \svd_module
+ *
+ * \sa computeRotationScaling(), computeScalingRotation(), class SVD
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+EIGEN_DEVICE_FUNC
+typename Transform<Scalar,Dim,Mode,Options>::RotationReturnType
+Transform<Scalar,Dim,Mode,Options>::rotation() const
+{
+ return internal::transform_rotation_impl<Mode>::run(*this);
+}
+
+
+/** decomposes the linear part of the transformation as a product rotation x scaling, the scaling being
+ * not necessarily positive.
+ *
+ * If either pointer is zero, the corresponding computation is skipped.
+ *
+ *
+ *
+ * \svd_module
+ *
+ * \sa computeScalingRotation(), rotation(), class SVD
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+template<typename RotationMatrixType, typename ScalingMatrixType>
+EIGEN_DEVICE_FUNC void Transform<Scalar,Dim,Mode,Options>::computeRotationScaling(RotationMatrixType *rotation, ScalingMatrixType *scaling) const
+{
+ // Note that JacobiSVD is faster than BDCSVD for small matrices.
+ JacobiSVD<LinearMatrixType> svd(linear(), ComputeFullU | ComputeFullV);
+
+ Scalar x = (svd.matrixU() * svd.matrixV().adjoint()).determinant() < Scalar(0) ? Scalar(-1) : Scalar(1); // so x has absolute value 1
+ VectorType sv(svd.singularValues());
+ sv.coeffRef(Dim-1) *= x;
+ if(scaling) *scaling = svd.matrixV() * sv.asDiagonal() * svd.matrixV().adjoint();
+ if(rotation)
+ {
+ LinearMatrixType m(svd.matrixU());
+ m.col(Dim-1) *= x;
+ *rotation = m * svd.matrixV().adjoint();
+ }
+}
+
+/** decomposes the linear part of the transformation as a product scaling x rotation, the scaling being
+ * not necessarily positive.
+ *
+ * If either pointer is zero, the corresponding computation is skipped.
+ *
+ *
+ *
+ * \svd_module
+ *
+ * \sa computeRotationScaling(), rotation(), class SVD
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+template<typename ScalingMatrixType, typename RotationMatrixType>
+EIGEN_DEVICE_FUNC void Transform<Scalar,Dim,Mode,Options>::computeScalingRotation(ScalingMatrixType *scaling, RotationMatrixType *rotation) const
+{
+ // Note that JacobiSVD is faster than BDCSVD for small matrices.
+ JacobiSVD<LinearMatrixType> svd(linear(), ComputeFullU | ComputeFullV);
+
+ Scalar x = (svd.matrixU() * svd.matrixV().adjoint()).determinant() < Scalar(0) ? Scalar(-1) : Scalar(1); // so x has absolute value 1
+ VectorType sv(svd.singularValues());
+ sv.coeffRef(Dim-1) *= x;
+ if(scaling) *scaling = svd.matrixU() * sv.asDiagonal() * svd.matrixU().adjoint();
+ if(rotation)
+ {
+ LinearMatrixType m(svd.matrixU());
+ m.col(Dim-1) *= x;
+ *rotation = m * svd.matrixV().adjoint();
+ }
+}
+
+/** Convenient method to set \c *this from a position, orientation and scale
+ * of a 3D object.
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+template<typename PositionDerived, typename OrientationType, typename ScaleDerived>
+EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>&
+Transform<Scalar,Dim,Mode,Options>::fromPositionOrientationScale(const MatrixBase<PositionDerived> &position,
+ const OrientationType& orientation, const MatrixBase<ScaleDerived> &scale)
+{
+ linear() = internal::toRotationMatrix<Scalar,Dim>(orientation);
+ linear() *= scale.asDiagonal();
+ translation() = position;
+ makeAffine();
+ return *this;
+}
+
+namespace internal {
+
+template<int Mode>
+struct transform_make_affine
+{
+ template<typename MatrixType>
+ EIGEN_DEVICE_FUNC static void run(MatrixType &mat)
+ {
+ static const int Dim = MatrixType::ColsAtCompileTime-1;
+ mat.template block<1,Dim>(Dim,0).setZero();
+ mat.coeffRef(Dim,Dim) = typename MatrixType::Scalar(1);
+ }
+};
+
+template<>
+struct transform_make_affine<AffineCompact>
+{
+ template<typename MatrixType> EIGEN_DEVICE_FUNC static void run(MatrixType &) { }
+};
+
+// selector needed to avoid taking the inverse of a 3x4 matrix
+template<typename TransformType, int Mode=TransformType::Mode>
+struct projective_transform_inverse
+{
+ EIGEN_DEVICE_FUNC static inline void run(const TransformType&, TransformType&)
+ {}
+};
+
+template<typename TransformType>
+struct projective_transform_inverse<TransformType, Projective>
+{
+ EIGEN_DEVICE_FUNC static inline void run(const TransformType& m, TransformType& res)
+ {
+ res.matrix() = m.matrix().inverse();
+ }
+};
+
+} // end namespace internal
+
+
+/**
+ *
+ * \returns the inverse transformation according to some given knowledge
+ * on \c *this.
+ *
+ * \param hint allows to optimize the inversion process when the transformation
+ * is known to be not a general transformation (optional). The possible values are:
+ * - #Projective if the transformation is not necessarily affine, i.e., if the
+ * last row is not guaranteed to be [0 ... 0 1]
+ * - #Affine if the last row can be assumed to be [0 ... 0 1]
+ * - #Isometry if the transformation is only a concatenations of translations
+ * and rotations.
+ * The default is the template class parameter \c Mode.
+ *
+ * \warning unless \a traits is always set to NoShear or NoScaling, this function
+ * requires the generic inverse method of MatrixBase defined in the LU module. If
+ * you forget to include this module, then you will get hard to debug linking errors.
+ *
+ * \sa MatrixBase::inverse()
+ */
+template<typename Scalar, int Dim, int Mode, int Options>
+EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>
+Transform<Scalar,Dim,Mode,Options>::inverse(TransformTraits hint) const
+{
+ Transform res;
+ if (hint == Projective)
+ {
+ internal::projective_transform_inverse<Transform>::run(*this, res);
+ }
+ else
+ {
+ if (hint == Isometry)
+ {
+ res.matrix().template topLeftCorner<Dim,Dim>() = linear().transpose();
+ }
+ else if(hint&Affine)
+ {
+ res.matrix().template topLeftCorner<Dim,Dim>() = linear().inverse();
+ }
+ else
+ {
+ eigen_assert(false && "Invalid transform traits in Transform::Inverse");
+ }
+ // translation and remaining parts
+ res.matrix().template topRightCorner<Dim,1>()
+ = - res.matrix().template topLeftCorner<Dim,Dim>() * translation();
+ res.makeAffine(); // we do need this, because in the beginning res is uninitialized
+ }
+ return res;
+}
+
+namespace internal {
+
+/*****************************************************
+*** Specializations of take affine part ***
+*****************************************************/
+
+template<typename TransformType> struct transform_take_affine_part {
+ typedef typename TransformType::MatrixType MatrixType;
+ typedef typename TransformType::AffinePart AffinePart;
+ typedef typename TransformType::ConstAffinePart ConstAffinePart;
+ static inline AffinePart run(MatrixType& m)
+ { return m.template block<TransformType::Dim,TransformType::HDim>(0,0); }
+ static inline ConstAffinePart run(const MatrixType& m)
+ { return m.template block<TransformType::Dim,TransformType::HDim>(0,0); }
+};
+
+template<typename Scalar, int Dim, int Options>
+struct transform_take_affine_part<Transform<Scalar,Dim,AffineCompact, Options> > {
+ typedef typename Transform<Scalar,Dim,AffineCompact,Options>::MatrixType MatrixType;
+ static inline MatrixType& run(MatrixType& m) { return m; }
+ static inline const MatrixType& run(const MatrixType& m) { return m; }
+};
+
+/*****************************************************
+*** Specializations of construct from matrix ***
+*****************************************************/
+
+template<typename Other, int Mode, int Options, int Dim, int HDim>
+struct transform_construct_from_matrix<Other, Mode,Options,Dim,HDim, Dim,Dim>
+{
+ static inline void run(Transform<typename Other::Scalar,Dim,Mode,Options> *transform, const Other& other)
+ {
+ transform->linear() = other;
+ transform->translation().setZero();
+ transform->makeAffine();
+ }
+};
+
+template<typename Other, int Mode, int Options, int Dim, int HDim>
+struct transform_construct_from_matrix<Other, Mode,Options,Dim,HDim, Dim,HDim>
+{
+ static inline void run(Transform<typename Other::Scalar,Dim,Mode,Options> *transform, const Other& other)
+ {
+ transform->affine() = other;
+ transform->makeAffine();
+ }
+};
+
+template<typename Other, int Mode, int Options, int Dim, int HDim>
+struct transform_construct_from_matrix<Other, Mode,Options,Dim,HDim, HDim,HDim>
+{
+ static inline void run(Transform<typename Other::Scalar,Dim,Mode,Options> *transform, const Other& other)
+ { transform->matrix() = other; }
+};
+
+template<typename Other, int Options, int Dim, int HDim>
+struct transform_construct_from_matrix<Other, AffineCompact,Options,Dim,HDim, HDim,HDim>
+{
+ static inline void run(Transform<typename Other::Scalar,Dim,AffineCompact,Options> *transform, const Other& other)
+ { transform->matrix() = other.template block<Dim,HDim>(0,0); }
+};
+
+/**********************************************************
+*** Specializations of operator* with rhs EigenBase ***
+**********************************************************/
+
+template<int LhsMode,int RhsMode>
+struct transform_product_result
+{
+ enum
+ {
+ Mode =
+ (LhsMode == (int)Projective || RhsMode == (int)Projective ) ? Projective :
+ (LhsMode == (int)Affine || RhsMode == (int)Affine ) ? Affine :
+ (LhsMode == (int)AffineCompact || RhsMode == (int)AffineCompact ) ? AffineCompact :
+ (LhsMode == (int)Isometry || RhsMode == (int)Isometry ) ? Isometry : Projective
+ };
+};
+
+template< typename TransformType, typename MatrixType, int RhsCols>
+struct transform_right_product_impl< TransformType, MatrixType, 0, RhsCols>
+{
+ typedef typename MatrixType::PlainObject ResultType;
+
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType run(const TransformType& T, const MatrixType& other)
+ {
+ return T.matrix() * other;
+ }
+};
+
+template< typename TransformType, typename MatrixType, int RhsCols>
+struct transform_right_product_impl< TransformType, MatrixType, 1, RhsCols>
+{
+ enum {
+ Dim = TransformType::Dim,
+ HDim = TransformType::HDim,
+ OtherRows = MatrixType::RowsAtCompileTime,
+ OtherCols = MatrixType::ColsAtCompileTime
+ };
+
+ typedef typename MatrixType::PlainObject ResultType;
+
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType run(const TransformType& T, const MatrixType& other)
+ {
+ EIGEN_STATIC_ASSERT(OtherRows==HDim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
+
+ typedef Block<ResultType, Dim, OtherCols, int(MatrixType::RowsAtCompileTime)==Dim> TopLeftLhs;
+
+ ResultType res(other.rows(),other.cols());
+ TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() = T.affine() * other;
+ res.row(OtherRows-1) = other.row(OtherRows-1);
+
+ return res;
+ }
+};
+
+template< typename TransformType, typename MatrixType, int RhsCols>
+struct transform_right_product_impl< TransformType, MatrixType, 2, RhsCols>
+{
+ enum {
+ Dim = TransformType::Dim,
+ HDim = TransformType::HDim,
+ OtherRows = MatrixType::RowsAtCompileTime,
+ OtherCols = MatrixType::ColsAtCompileTime
+ };
+
+ typedef typename MatrixType::PlainObject ResultType;
+
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType run(const TransformType& T, const MatrixType& other)
+ {
+ EIGEN_STATIC_ASSERT(OtherRows==Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
+
+ typedef Block<ResultType, Dim, OtherCols, true> TopLeftLhs;
+ ResultType res(Replicate<typename TransformType::ConstTranslationPart, 1, OtherCols>(T.translation(),1,other.cols()));
+ TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() += T.linear() * other;
+
+ return res;
+ }
+};
+
+template< typename TransformType, typename MatrixType >
+struct transform_right_product_impl< TransformType, MatrixType, 2, 1> // rhs is a vector of size Dim
+{
+ typedef typename TransformType::MatrixType TransformMatrix;
+ enum {
+ Dim = TransformType::Dim,
+ HDim = TransformType::HDim,
+ OtherRows = MatrixType::RowsAtCompileTime,
+ WorkingRows = EIGEN_PLAIN_ENUM_MIN(TransformMatrix::RowsAtCompileTime,HDim)
+ };
+
+ typedef typename MatrixType::PlainObject ResultType;
+
+ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType run(const TransformType& T, const MatrixType& other)
+ {
+ EIGEN_STATIC_ASSERT(OtherRows==Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
+
+ Matrix<typename ResultType::Scalar, Dim+1, 1> rhs;
+ rhs.template head<Dim>() = other; rhs[Dim] = typename ResultType::Scalar(1);
+ Matrix<typename ResultType::Scalar, WorkingRows, 1> res(T.matrix() * rhs);
+ return res.template head<Dim>();
+ }
+};
+
+/**********************************************************
+*** Specializations of operator* with lhs EigenBase ***
+**********************************************************/
+
+// generic HDim x HDim matrix * T => Projective
+template<typename Other,int Mode, int Options, int Dim, int HDim>
+struct transform_left_product_impl<Other,Mode,Options,Dim,HDim, HDim,HDim>
+{
+ typedef Transform<typename Other::Scalar,Dim,Mode,Options> TransformType;
+ typedef typename TransformType::MatrixType MatrixType;
+ typedef Transform<typename Other::Scalar,Dim,Projective,Options> ResultType;
+ static ResultType run(const Other& other,const TransformType& tr)
+ { return ResultType(other * tr.matrix()); }
+};
+
+// generic HDim x HDim matrix * AffineCompact => Projective
+template<typename Other, int Options, int Dim, int HDim>
+struct transform_left_product_impl<Other,AffineCompact,Options,Dim,HDim, HDim,HDim>
+{
+ typedef Transform<typename Other::Scalar,Dim,AffineCompact,Options> TransformType;
+ typedef typename TransformType::MatrixType MatrixType;
+ typedef Transform<typename Other::Scalar,Dim,Projective,Options> ResultType;
+ static ResultType run(const Other& other,const TransformType& tr)
+ {
+ ResultType res;
+ res.matrix().noalias() = other.template block<HDim,Dim>(0,0) * tr.matrix();
+ res.matrix().col(Dim) += other.col(Dim);
+ return res;
+ }
+};
+
+// affine matrix * T
+template<typename Other,int Mode, int Options, int Dim, int HDim>
+struct transform_left_product_impl<Other,Mode,Options,Dim,HDim, Dim,HDim>
+{
+ typedef Transform<typename Other::Scalar,Dim,Mode,Options> TransformType;
+ typedef typename TransformType::MatrixType MatrixType;
+ typedef TransformType ResultType;
+ static ResultType run(const Other& other,const TransformType& tr)
+ {
+ ResultType res;
+ res.affine().noalias() = other * tr.matrix();
+ res.matrix().row(Dim) = tr.matrix().row(Dim);
+ return res;
+ }
+};
+
+// affine matrix * AffineCompact
+template<typename Other, int Options, int Dim, int HDim>
+struct transform_left_product_impl<Other,AffineCompact,Options,Dim,HDim, Dim,HDim>
+{
+ typedef Transform<typename Other::Scalar,Dim,AffineCompact,Options> TransformType;
+ typedef typename TransformType::MatrixType MatrixType;
+ typedef TransformType ResultType;
+ static ResultType run(const Other& other,const TransformType& tr)
+ {
+ ResultType res;
+ res.matrix().noalias() = other.template block<Dim,Dim>(0,0) * tr.matrix();
+ res.translation() += other.col(Dim);
+ return res;
+ }
+};
+
+// linear matrix * T
+template<typename Other,int Mode, int Options, int Dim, int HDim>
+struct transform_left_product_impl<Other,Mode,Options,Dim,HDim, Dim,Dim>
+{
+ typedef Transform<typename Other::Scalar,Dim,Mode,Options> TransformType;
+ typedef typename TransformType::MatrixType MatrixType;
+ typedef TransformType ResultType;
+ static ResultType run(const Other& other, const TransformType& tr)
+ {
+ TransformType res;
+ if(Mode!=int(AffineCompact))
+ res.matrix().row(Dim) = tr.matrix().row(Dim);
+ res.matrix().template topRows<Dim>().noalias()
+ = other * tr.matrix().template topRows<Dim>();
+ return res;
+ }
+};
+
+/**********************************************************
+*** Specializations of operator* with another Transform ***
+**********************************************************/
+
+template<typename Scalar, int Dim, int LhsMode, int LhsOptions, int RhsMode, int RhsOptions>
+struct transform_transform_product_impl<Transform<Scalar,Dim,LhsMode,LhsOptions>,Transform<Scalar,Dim,RhsMode,RhsOptions>,false >
+{
+ enum { ResultMode = transform_product_result<LhsMode,RhsMode>::Mode };
+ typedef Transform<Scalar,Dim,LhsMode,LhsOptions> Lhs;
+ typedef Transform<Scalar,Dim,RhsMode,RhsOptions> Rhs;
+ typedef Transform<Scalar,Dim,ResultMode,LhsOptions> ResultType;
+ static ResultType run(const Lhs& lhs, const Rhs& rhs)
+ {
+ ResultType res;
+ res.linear() = lhs.linear() * rhs.linear();
+ res.translation() = lhs.linear() * rhs.translation() + lhs.translation();
+ res.makeAffine();
+ return res;
+ }
+};
+
+template<typename Scalar, int Dim, int LhsMode, int LhsOptions, int RhsMode, int RhsOptions>
+struct transform_transform_product_impl<Transform<Scalar,Dim,LhsMode,LhsOptions>,Transform<Scalar,Dim,RhsMode,RhsOptions>,true >
+{
+ typedef Transform<Scalar,Dim,LhsMode,LhsOptions> Lhs;
+ typedef Transform<Scalar,Dim,RhsMode,RhsOptions> Rhs;
+ typedef Transform<Scalar,Dim,Projective> ResultType;
+ static ResultType run(const Lhs& lhs, const Rhs& rhs)
+ {
+ return ResultType( lhs.matrix() * rhs.matrix() );
+ }
+};
+
+template<typename Scalar, int Dim, int LhsOptions, int RhsOptions>
+struct transform_transform_product_impl<Transform<Scalar,Dim,AffineCompact,LhsOptions>,Transform<Scalar,Dim,Projective,RhsOptions>,true >
+{
+ typedef Transform<Scalar,Dim,AffineCompact,LhsOptions> Lhs;
+ typedef Transform<Scalar,Dim,Projective,RhsOptions> Rhs;
+ typedef Transform<Scalar,Dim,Projective> ResultType;
+ static ResultType run(const Lhs& lhs, const Rhs& rhs)
+ {
+ ResultType res;
+ res.matrix().template topRows<Dim>() = lhs.matrix() * rhs.matrix();
+ res.matrix().row(Dim) = rhs.matrix().row(Dim);
+ return res;
+ }
+};
+
+template<typename Scalar, int Dim, int LhsOptions, int RhsOptions>
+struct transform_transform_product_impl<Transform<Scalar,Dim,Projective,LhsOptions>,Transform<Scalar,Dim,AffineCompact,RhsOptions>,true >
+{
+ typedef Transform<Scalar,Dim,Projective,LhsOptions> Lhs;
+ typedef Transform<Scalar,Dim,AffineCompact,RhsOptions> Rhs;
+ typedef Transform<Scalar,Dim,Projective> ResultType;
+ static ResultType run(const Lhs& lhs, const Rhs& rhs)
+ {
+ ResultType res(lhs.matrix().template leftCols<Dim>() * rhs.matrix());
+ res.matrix().col(Dim) += lhs.matrix().col(Dim);
+ return res;
+ }
+};
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRANSFORM_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/Translation.h b/src/3rdparty/eigen/Eigen/src/Geometry/Translation.h
new file mode 100644
index 000000000..8c2290121
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/Translation.h
@@ -0,0 +1,202 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_TRANSLATION_H
+#define EIGEN_TRANSLATION_H
+
+namespace Eigen {
+
+/** \geometry_module \ingroup Geometry_Module
+ *
+ * \class Translation
+ *
+ * \brief Represents a translation transformation
+ *
+ * \tparam _Scalar the scalar type, i.e., the type of the coefficients.
+ * \tparam _Dim the dimension of the space, can be a compile time value or Dynamic
+ *
+ * \note This class is not aimed to be used to store a translation transformation,
+ * but rather to make easier the constructions and updates of Transform objects.
+ *
+ * \sa class Scaling, class Transform
+ */
+template<typename _Scalar, int _Dim>
+class Translation
+{
+public:
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim)
+ /** dimension of the space */
+ enum { Dim = _Dim };
+ /** the scalar type of the coefficients */
+ typedef _Scalar Scalar;
+ /** corresponding vector type */
+ typedef Matrix<Scalar,Dim,1> VectorType;
+ /** corresponding linear transformation matrix type */
+ typedef Matrix<Scalar,Dim,Dim> LinearMatrixType;
+ /** corresponding affine transformation type */
+ typedef Transform<Scalar,Dim,Affine> AffineTransformType;
+ /** corresponding isometric transformation type */
+ typedef Transform<Scalar,Dim,Isometry> IsometryTransformType;
+
+protected:
+
+ VectorType m_coeffs;
+
+public:
+
+ /** Default constructor without initialization. */
+ EIGEN_DEVICE_FUNC Translation() {}
+ /** */
+ EIGEN_DEVICE_FUNC inline Translation(const Scalar& sx, const Scalar& sy)
+ {
+ eigen_assert(Dim==2);
+ m_coeffs.x() = sx;
+ m_coeffs.y() = sy;
+ }
+ /** */
+ EIGEN_DEVICE_FUNC inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
+ {
+ eigen_assert(Dim==3);
+ m_coeffs.x() = sx;
+ m_coeffs.y() = sy;
+ m_coeffs.z() = sz;
+ }
+ /** Constructs and initialize the translation transformation from a vector of translation coefficients */
+ EIGEN_DEVICE_FUNC explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
+
+ /** \brief Returns the x-translation by value. **/
+ EIGEN_DEVICE_FUNC inline Scalar x() const { return m_coeffs.x(); }
+ /** \brief Returns the y-translation by value. **/
+ EIGEN_DEVICE_FUNC inline Scalar y() const { return m_coeffs.y(); }
+ /** \brief Returns the z-translation by value. **/
+ EIGEN_DEVICE_FUNC inline Scalar z() const { return m_coeffs.z(); }
+
+ /** \brief Returns the x-translation as a reference. **/
+ EIGEN_DEVICE_FUNC inline Scalar& x() { return m_coeffs.x(); }
+ /** \brief Returns the y-translation as a reference. **/
+ EIGEN_DEVICE_FUNC inline Scalar& y() { return m_coeffs.y(); }
+ /** \brief Returns the z-translation as a reference. **/
+ EIGEN_DEVICE_FUNC inline Scalar& z() { return m_coeffs.z(); }
+
+ EIGEN_DEVICE_FUNC const VectorType& vector() const { return m_coeffs; }
+ EIGEN_DEVICE_FUNC VectorType& vector() { return m_coeffs; }
+
+ EIGEN_DEVICE_FUNC const VectorType& translation() const { return m_coeffs; }
+ EIGEN_DEVICE_FUNC VectorType& translation() { return m_coeffs; }
+
+ /** Concatenates two translation */
+ EIGEN_DEVICE_FUNC inline Translation operator* (const Translation& other) const
+ { return Translation(m_coeffs + other.m_coeffs); }
+
+ /** Concatenates a translation and a uniform scaling */
+ EIGEN_DEVICE_FUNC inline AffineTransformType operator* (const UniformScaling<Scalar>& other) const;
+
+ /** Concatenates a translation and a linear transformation */
+ template<typename OtherDerived>
+ EIGEN_DEVICE_FUNC inline AffineTransformType operator* (const EigenBase<OtherDerived>& linear) const;
+
+ /** Concatenates a translation and a rotation */
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC inline IsometryTransformType operator*(const RotationBase<Derived,Dim>& r) const
+ { return *this * IsometryTransformType(r); }
+
+ /** \returns the concatenation of a linear transformation \a l with the translation \a t */
+ // its a nightmare to define a templated friend function outside its declaration
+ template<typename OtherDerived> friend
+ EIGEN_DEVICE_FUNC inline AffineTransformType operator*(const EigenBase<OtherDerived>& linear, const Translation& t)
+ {
+ AffineTransformType res;
+ res.matrix().setZero();
+ res.linear() = linear.derived();
+ res.translation() = linear.derived() * t.m_coeffs;
+ res.matrix().row(Dim).setZero();
+ res(Dim,Dim) = Scalar(1);
+ return res;
+ }
+
+ /** Concatenates a translation and a transformation */
+ template<int Mode, int Options>
+ EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode> operator* (const Transform<Scalar,Dim,Mode,Options>& t) const
+ {
+ Transform<Scalar,Dim,Mode> res = t;
+ res.pretranslate(m_coeffs);
+ return res;
+ }
+
+ /** Applies translation to vector */
+ template<typename Derived>
+ inline typename internal::enable_if<Derived::IsVectorAtCompileTime,VectorType>::type
+ operator* (const MatrixBase<Derived>& vec) const
+ { return m_coeffs + vec.derived(); }
+
+ /** \returns the inverse translation (opposite) */
+ Translation inverse() const { return Translation(-m_coeffs); }
+
+ static const Translation Identity() { return Translation(VectorType::Zero()); }
+
+ /** \returns \c *this with scalar type casted to \a NewScalarType
+ *
+ * Note that if \a NewScalarType is equal to the current scalar type of \c *this
+ * then this function smartly returns a const reference to \c *this.
+ */
+ template<typename NewScalarType>
+ EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
+ { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
+
+ /** Copy constructor with scalar type conversion */
+ template<typename OtherScalarType>
+ EIGEN_DEVICE_FUNC inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
+ { m_coeffs = other.vector().template cast<Scalar>(); }
+
+ /** \returns \c true if \c *this is approximately equal to \a other, within the precision
+ * determined by \a prec.
+ *
+ * \sa MatrixBase::isApprox() */
+ EIGEN_DEVICE_FUNC bool isApprox(const Translation& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
+ { return m_coeffs.isApprox(other.m_coeffs, prec); }
+
+};
+
+/** \addtogroup Geometry_Module */
+//@{
+typedef Translation<float, 2> Translation2f;
+typedef Translation<double,2> Translation2d;
+typedef Translation<float, 3> Translation3f;
+typedef Translation<double,3> Translation3d;
+//@}
+
+template<typename Scalar, int Dim>
+EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType
+Translation<Scalar,Dim>::operator* (const UniformScaling<Scalar>& other) const
+{
+ AffineTransformType res;
+ res.matrix().setZero();
+ res.linear().diagonal().fill(other.factor());
+ res.translation() = m_coeffs;
+ res(Dim,Dim) = Scalar(1);
+ return res;
+}
+
+template<typename Scalar, int Dim>
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType
+Translation<Scalar,Dim>::operator* (const EigenBase<OtherDerived>& linear) const
+{
+ AffineTransformType res;
+ res.matrix().setZero();
+ res.linear() = linear.derived();
+ res.translation() = m_coeffs;
+ res.matrix().row(Dim).setZero();
+ res(Dim,Dim) = Scalar(1);
+ return res;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_TRANSLATION_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/Umeyama.h b/src/3rdparty/eigen/Eigen/src/Geometry/Umeyama.h
new file mode 100644
index 000000000..6b755008f
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/Umeyama.h
@@ -0,0 +1,166 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Hauke Heibel <hauke.heibel@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_UMEYAMA_H
+#define EIGEN_UMEYAMA_H
+
+// This file requires the user to include
+// * Eigen/Core
+// * Eigen/LU
+// * Eigen/SVD
+// * Eigen/Array
+
+namespace Eigen {
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+
+// These helpers are required since it allows to use mixed types as parameters
+// for the Umeyama. The problem with mixed parameters is that the return type
+// cannot trivially be deduced when float and double types are mixed.
+namespace internal {
+
+// Compile time return type deduction for different MatrixBase types.
+// Different means here different alignment and parameters but the same underlying
+// real scalar type.
+template<typename MatrixType, typename OtherMatrixType>
+struct umeyama_transform_matrix_type
+{
+ enum {
+ MinRowsAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(MatrixType::RowsAtCompileTime, OtherMatrixType::RowsAtCompileTime),
+
+ // When possible we want to choose some small fixed size value since the result
+ // is likely to fit on the stack. So here, EIGEN_SIZE_MIN_PREFER_DYNAMIC is not what we want.
+ HomogeneousDimension = int(MinRowsAtCompileTime) == Dynamic ? Dynamic : int(MinRowsAtCompileTime)+1
+ };
+
+ typedef Matrix<typename traits<MatrixType>::Scalar,
+ HomogeneousDimension,
+ HomogeneousDimension,
+ AutoAlign | (traits<MatrixType>::Flags & RowMajorBit ? RowMajor : ColMajor),
+ HomogeneousDimension,
+ HomogeneousDimension
+ > type;
+};
+
+}
+
+#endif
+
+/**
+* \geometry_module \ingroup Geometry_Module
+*
+* \brief Returns the transformation between two point sets.
+*
+* The algorithm is based on:
+* "Least-squares estimation of transformation parameters between two point patterns",
+* Shinji Umeyama, PAMI 1991, DOI: 10.1109/34.88573
+*
+* It estimates parameters \f$ c, \mathbf{R}, \f$ and \f$ \mathbf{t} \f$ such that
+* \f{align*}
+* \frac{1}{n} \sum_{i=1}^n \vert\vert y_i - (c\mathbf{R}x_i + \mathbf{t}) \vert\vert_2^2
+* \f}
+* is minimized.
+*
+* The algorithm is based on the analysis of the covariance matrix
+* \f$ \Sigma_{\mathbf{x}\mathbf{y}} \in \mathbb{R}^{d \times d} \f$
+* of the input point sets \f$ \mathbf{x} \f$ and \f$ \mathbf{y} \f$ where
+* \f$d\f$ is corresponding to the dimension (which is typically small).
+* The analysis is involving the SVD having a complexity of \f$O(d^3)\f$
+* though the actual computational effort lies in the covariance
+* matrix computation which has an asymptotic lower bound of \f$O(dm)\f$ when
+* the input point sets have dimension \f$d \times m\f$.
+*
+* Currently the method is working only for floating point matrices.
+*
+* \todo Should the return type of umeyama() become a Transform?
+*
+* \param src Source points \f$ \mathbf{x} = \left( x_1, \hdots, x_n \right) \f$.
+* \param dst Destination points \f$ \mathbf{y} = \left( y_1, \hdots, y_n \right) \f$.
+* \param with_scaling Sets \f$ c=1 \f$ when <code>false</code> is passed.
+* \return The homogeneous transformation
+* \f{align*}
+* T = \begin{bmatrix} c\mathbf{R} & \mathbf{t} \\ \mathbf{0} & 1 \end{bmatrix}
+* \f}
+* minimizing the residual above. This transformation is always returned as an
+* Eigen::Matrix.
+*/
+template <typename Derived, typename OtherDerived>
+typename internal::umeyama_transform_matrix_type<Derived, OtherDerived>::type
+umeyama(const MatrixBase<Derived>& src, const MatrixBase<OtherDerived>& dst, bool with_scaling = true)
+{
+ typedef typename internal::umeyama_transform_matrix_type<Derived, OtherDerived>::type TransformationMatrixType;
+ typedef typename internal::traits<TransformationMatrixType>::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsComplex, NUMERIC_TYPE_MUST_BE_REAL)
+ EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename internal::traits<OtherDerived>::Scalar>::value),
+ YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
+
+ enum { Dimension = EIGEN_SIZE_MIN_PREFER_DYNAMIC(Derived::RowsAtCompileTime, OtherDerived::RowsAtCompileTime) };
+
+ typedef Matrix<Scalar, Dimension, 1> VectorType;
+ typedef Matrix<Scalar, Dimension, Dimension> MatrixType;
+ typedef typename internal::plain_matrix_type_row_major<Derived>::type RowMajorMatrixType;
+
+ const Index m = src.rows(); // dimension
+ const Index n = src.cols(); // number of measurements
+
+ // required for demeaning ...
+ const RealScalar one_over_n = RealScalar(1) / static_cast<RealScalar>(n);
+
+ // computation of mean
+ const VectorType src_mean = src.rowwise().sum() * one_over_n;
+ const VectorType dst_mean = dst.rowwise().sum() * one_over_n;
+
+ // demeaning of src and dst points
+ const RowMajorMatrixType src_demean = src.colwise() - src_mean;
+ const RowMajorMatrixType dst_demean = dst.colwise() - dst_mean;
+
+ // Eq. (36)-(37)
+ const Scalar src_var = src_demean.rowwise().squaredNorm().sum() * one_over_n;
+
+ // Eq. (38)
+ const MatrixType sigma = one_over_n * dst_demean * src_demean.transpose();
+
+ JacobiSVD<MatrixType> svd(sigma, ComputeFullU | ComputeFullV);
+
+ // Initialize the resulting transformation with an identity matrix...
+ TransformationMatrixType Rt = TransformationMatrixType::Identity(m+1,m+1);
+
+ // Eq. (39)
+ VectorType S = VectorType::Ones(m);
+
+ if ( svd.matrixU().determinant() * svd.matrixV().determinant() < 0 )
+ S(m-1) = -1;
+
+ // Eq. (40) and (43)
+ Rt.block(0,0,m,m).noalias() = svd.matrixU() * S.asDiagonal() * svd.matrixV().transpose();
+
+ if (with_scaling)
+ {
+ // Eq. (42)
+ const Scalar c = Scalar(1)/src_var * svd.singularValues().dot(S);
+
+ // Eq. (41)
+ Rt.col(m).head(m) = dst_mean;
+ Rt.col(m).head(m).noalias() -= c*Rt.topLeftCorner(m,m)*src_mean;
+ Rt.block(0,0,m,m) *= c;
+ }
+ else
+ {
+ Rt.col(m).head(m) = dst_mean;
+ Rt.col(m).head(m).noalias() -= Rt.topLeftCorner(m,m)*src_mean;
+ }
+
+ return Rt;
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_UMEYAMA_H
diff --git a/src/3rdparty/eigen/Eigen/src/Geometry/arch/Geometry_SIMD.h b/src/3rdparty/eigen/Eigen/src/Geometry/arch/Geometry_SIMD.h
new file mode 100644
index 000000000..9af6a9af7
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Geometry/arch/Geometry_SIMD.h
@@ -0,0 +1,168 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Rohit Garg <rpg.314@gmail.com>
+// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_GEOMETRY_SIMD_H
+#define EIGEN_GEOMETRY_SIMD_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<class Derived, class OtherDerived>
+struct quat_product<Architecture::Target, Derived, OtherDerived, float>
+{
+ enum {
+ AAlignment = traits<Derived>::Alignment,
+ BAlignment = traits<OtherDerived>::Alignment,
+ ResAlignment = traits<Quaternion<float> >::Alignment
+ };
+ static inline Quaternion<float> run(const QuaternionBase<Derived>& _a, const QuaternionBase<OtherDerived>& _b)
+ {
+ evaluator<typename Derived::Coefficients> ae(_a.coeffs());
+ evaluator<typename OtherDerived::Coefficients> be(_b.coeffs());
+ Quaternion<float> res;
+ const float neg_zero = numext::bit_cast<float>(0x80000000u);
+ const float arr[4] = {0.f, 0.f, 0.f, neg_zero};
+ const Packet4f mask = ploadu<Packet4f>(arr);
+ Packet4f a = ae.template packet<AAlignment,Packet4f>(0);
+ Packet4f b = be.template packet<BAlignment,Packet4f>(0);
+ Packet4f s1 = pmul(vec4f_swizzle1(a,1,2,0,2),vec4f_swizzle1(b,2,0,1,2));
+ Packet4f s2 = pmul(vec4f_swizzle1(a,3,3,3,1),vec4f_swizzle1(b,0,1,2,1));
+ pstoret<float,Packet4f,ResAlignment>(
+ &res.x(),
+ padd(psub(pmul(a,vec4f_swizzle1(b,3,3,3,3)),
+ pmul(vec4f_swizzle1(a,2,0,1,0),
+ vec4f_swizzle1(b,1,2,0,0))),
+ pxor(mask,padd(s1,s2))));
+
+ return res;
+ }
+};
+
+template<class Derived>
+struct quat_conj<Architecture::Target, Derived, float>
+{
+ enum {
+ ResAlignment = traits<Quaternion<float> >::Alignment
+ };
+ static inline Quaternion<float> run(const QuaternionBase<Derived>& q)
+ {
+ evaluator<typename Derived::Coefficients> qe(q.coeffs());
+ Quaternion<float> res;
+ const float neg_zero = numext::bit_cast<float>(0x80000000u);
+ const float arr[4] = {neg_zero, neg_zero, neg_zero,0.f};
+ const Packet4f mask = ploadu<Packet4f>(arr);
+ pstoret<float,Packet4f,ResAlignment>(&res.x(), pxor(mask, qe.template packet<traits<Derived>::Alignment,Packet4f>(0)));
+ return res;
+ }
+};
+
+
+template<typename VectorLhs,typename VectorRhs>
+struct cross3_impl<Architecture::Target,VectorLhs,VectorRhs,float,true>
+{
+ enum {
+ ResAlignment = traits<typename plain_matrix_type<VectorLhs>::type>::Alignment
+ };
+ static inline typename plain_matrix_type<VectorLhs>::type
+ run(const VectorLhs& lhs, const VectorRhs& rhs)
+ {
+ evaluator<VectorLhs> lhs_eval(lhs);
+ evaluator<VectorRhs> rhs_eval(rhs);
+ Packet4f a = lhs_eval.template packet<traits<VectorLhs>::Alignment,Packet4f>(0);
+ Packet4f b = rhs_eval.template packet<traits<VectorRhs>::Alignment,Packet4f>(0);
+ Packet4f mul1 = pmul(vec4f_swizzle1(a,1,2,0,3),vec4f_swizzle1(b,2,0,1,3));
+ Packet4f mul2 = pmul(vec4f_swizzle1(a,2,0,1,3),vec4f_swizzle1(b,1,2,0,3));
+ typename plain_matrix_type<VectorLhs>::type res;
+ pstoret<float,Packet4f,ResAlignment>(&res.x(),psub(mul1,mul2));
+ return res;
+ }
+};
+
+
+
+#if (defined EIGEN_VECTORIZE_SSE) || (EIGEN_ARCH_ARM64)
+
+template<class Derived, class OtherDerived>
+struct quat_product<Architecture::Target, Derived, OtherDerived, double>
+{
+ enum {
+ BAlignment = traits<OtherDerived>::Alignment,
+ ResAlignment = traits<Quaternion<double> >::Alignment
+ };
+
+ static inline Quaternion<double> run(const QuaternionBase<Derived>& _a, const QuaternionBase<OtherDerived>& _b)
+ {
+ Quaternion<double> res;
+
+ evaluator<typename Derived::Coefficients> ae(_a.coeffs());
+ evaluator<typename OtherDerived::Coefficients> be(_b.coeffs());
+
+ const double* a = _a.coeffs().data();
+ Packet2d b_xy = be.template packet<BAlignment,Packet2d>(0);
+ Packet2d b_zw = be.template packet<BAlignment,Packet2d>(2);
+ Packet2d a_xx = pset1<Packet2d>(a[0]);
+ Packet2d a_yy = pset1<Packet2d>(a[1]);
+ Packet2d a_zz = pset1<Packet2d>(a[2]);
+ Packet2d a_ww = pset1<Packet2d>(a[3]);
+
+ // two temporaries:
+ Packet2d t1, t2;
+
+ /*
+ * t1 = ww*xy + yy*zw
+ * t2 = zz*xy - xx*zw
+ * res.xy = t1 +/- swap(t2)
+ */
+ t1 = padd(pmul(a_ww, b_xy), pmul(a_yy, b_zw));
+ t2 = psub(pmul(a_zz, b_xy), pmul(a_xx, b_zw));
+ pstoret<double,Packet2d,ResAlignment>(&res.x(), paddsub(t1, preverse(t2)));
+
+ /*
+ * t1 = ww*zw - yy*xy
+ * t2 = zz*zw + xx*xy
+ * res.zw = t1 -/+ swap(t2) = swap( swap(t1) +/- t2)
+ */
+ t1 = psub(pmul(a_ww, b_zw), pmul(a_yy, b_xy));
+ t2 = padd(pmul(a_zz, b_zw), pmul(a_xx, b_xy));
+ pstoret<double,Packet2d,ResAlignment>(&res.z(), preverse(paddsub(preverse(t1), t2)));
+
+ return res;
+}
+};
+
+template<class Derived>
+struct quat_conj<Architecture::Target, Derived, double>
+{
+ enum {
+ ResAlignment = traits<Quaternion<double> >::Alignment
+ };
+ static inline Quaternion<double> run(const QuaternionBase<Derived>& q)
+ {
+ evaluator<typename Derived::Coefficients> qe(q.coeffs());
+ Quaternion<double> res;
+ const double neg_zero = numext::bit_cast<double>(0x8000000000000000ull);
+ const double arr1[2] = {neg_zero, neg_zero};
+ const double arr2[2] = {neg_zero, 0.0};
+ const Packet2d mask0 = ploadu<Packet2d>(arr1);
+ const Packet2d mask2 = ploadu<Packet2d>(arr2);
+ pstoret<double,Packet2d,ResAlignment>(&res.x(), pxor(mask0, qe.template packet<traits<Derived>::Alignment,Packet2d>(0)));
+ pstoret<double,Packet2d,ResAlignment>(&res.z(), pxor(mask2, qe.template packet<traits<Derived>::Alignment,Packet2d>(2)));
+ return res;
+ }
+};
+
+#endif // end EIGEN_VECTORIZE_SSE_OR_EIGEN_ARCH_ARM64
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_GEOMETRY_SIMD_H
diff --git a/src/3rdparty/eigen/Eigen/src/Householder/BlockHouseholder.h b/src/3rdparty/eigen/Eigen/src/Householder/BlockHouseholder.h
new file mode 100644
index 000000000..39ce1c2a0
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Householder/BlockHouseholder.h
@@ -0,0 +1,110 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2010 Vincent Lejeune
+// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_BLOCK_HOUSEHOLDER_H
+#define EIGEN_BLOCK_HOUSEHOLDER_H
+
+// This file contains some helper function to deal with block householder reflectors
+
+namespace Eigen {
+
+namespace internal {
+
+/** \internal */
+// template<typename TriangularFactorType,typename VectorsType,typename CoeffsType>
+// void make_block_householder_triangular_factor(TriangularFactorType& triFactor, const VectorsType& vectors, const CoeffsType& hCoeffs)
+// {
+// typedef typename VectorsType::Scalar Scalar;
+// const Index nbVecs = vectors.cols();
+// eigen_assert(triFactor.rows() == nbVecs && triFactor.cols() == nbVecs && vectors.rows()>=nbVecs);
+//
+// for(Index i = 0; i < nbVecs; i++)
+// {
+// Index rs = vectors.rows() - i;
+// // Warning, note that hCoeffs may alias with vectors.
+// // It is then necessary to copy it before modifying vectors(i,i).
+// typename CoeffsType::Scalar h = hCoeffs(i);
+// // This hack permits to pass trough nested Block<> and Transpose<> expressions.
+// Scalar *Vii_ptr = const_cast<Scalar*>(vectors.data() + vectors.outerStride()*i + vectors.innerStride()*i);
+// Scalar Vii = *Vii_ptr;
+// *Vii_ptr = Scalar(1);
+// triFactor.col(i).head(i).noalias() = -h * vectors.block(i, 0, rs, i).adjoint()
+// * vectors.col(i).tail(rs);
+// *Vii_ptr = Vii;
+// // FIXME add .noalias() once the triangular product can work inplace
+// triFactor.col(i).head(i) = triFactor.block(0,0,i,i).template triangularView<Upper>()
+// * triFactor.col(i).head(i);
+// triFactor(i,i) = hCoeffs(i);
+// }
+// }
+
+/** \internal */
+// This variant avoid modifications in vectors
+template<typename TriangularFactorType,typename VectorsType,typename CoeffsType>
+void make_block_householder_triangular_factor(TriangularFactorType& triFactor, const VectorsType& vectors, const CoeffsType& hCoeffs)
+{
+ const Index nbVecs = vectors.cols();
+ eigen_assert(triFactor.rows() == nbVecs && triFactor.cols() == nbVecs && vectors.rows()>=nbVecs);
+
+ for(Index i = nbVecs-1; i >=0 ; --i)
+ {
+ Index rs = vectors.rows() - i - 1;
+ Index rt = nbVecs-i-1;
+
+ if(rt>0)
+ {
+ triFactor.row(i).tail(rt).noalias() = -hCoeffs(i) * vectors.col(i).tail(rs).adjoint()
+ * vectors.bottomRightCorner(rs, rt).template triangularView<UnitLower>();
+
+ // FIXME use the following line with .noalias() once the triangular product can work inplace
+ // triFactor.row(i).tail(rt) = triFactor.row(i).tail(rt) * triFactor.bottomRightCorner(rt,rt).template triangularView<Upper>();
+ for(Index j=nbVecs-1; j>i; --j)
+ {
+ typename TriangularFactorType::Scalar z = triFactor(i,j);
+ triFactor(i,j) = z * triFactor(j,j);
+ if(nbVecs-j-1>0)
+ triFactor.row(i).tail(nbVecs-j-1) += z * triFactor.row(j).tail(nbVecs-j-1);
+ }
+
+ }
+ triFactor(i,i) = hCoeffs(i);
+ }
+}
+
+/** \internal
+ * if forward then perform mat = H0 * H1 * H2 * mat
+ * otherwise perform mat = H2 * H1 * H0 * mat
+ */
+template<typename MatrixType,typename VectorsType,typename CoeffsType>
+void apply_block_householder_on_the_left(MatrixType& mat, const VectorsType& vectors, const CoeffsType& hCoeffs, bool forward)
+{
+ enum { TFactorSize = MatrixType::ColsAtCompileTime };
+ Index nbVecs = vectors.cols();
+ Matrix<typename MatrixType::Scalar, TFactorSize, TFactorSize, RowMajor> T(nbVecs,nbVecs);
+
+ if(forward) make_block_householder_triangular_factor(T, vectors, hCoeffs);
+ else make_block_householder_triangular_factor(T, vectors, hCoeffs.conjugate());
+ const TriangularView<const VectorsType, UnitLower> V(vectors);
+
+ // A -= V T V^* A
+ Matrix<typename MatrixType::Scalar,VectorsType::ColsAtCompileTime,MatrixType::ColsAtCompileTime,
+ (VectorsType::MaxColsAtCompileTime==1 && MatrixType::MaxColsAtCompileTime!=1)?RowMajor:ColMajor,
+ VectorsType::MaxColsAtCompileTime,MatrixType::MaxColsAtCompileTime> tmp = V.adjoint() * mat;
+ // FIXME add .noalias() once the triangular product can work inplace
+ if(forward) tmp = T.template triangularView<Upper>() * tmp;
+ else tmp = T.template triangularView<Upper>().adjoint() * tmp;
+ mat.noalias() -= V * tmp;
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_BLOCK_HOUSEHOLDER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Householder/Householder.h b/src/3rdparty/eigen/Eigen/src/Householder/Householder.h
new file mode 100644
index 000000000..5bc037f00
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Householder/Householder.h
@@ -0,0 +1,176 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_HOUSEHOLDER_H
+#define EIGEN_HOUSEHOLDER_H
+
+namespace Eigen {
+
+namespace internal {
+template<int n> struct decrement_size
+{
+ enum {
+ ret = n==Dynamic ? n : n-1
+ };
+};
+}
+
+/** Computes the elementary reflector H such that:
+ * \f$ H *this = [ beta 0 ... 0]^T \f$
+ * where the transformation H is:
+ * \f$ H = I - tau v v^*\f$
+ * and the vector v is:
+ * \f$ v^T = [1 essential^T] \f$
+ *
+ * The essential part of the vector \c v is stored in *this.
+ *
+ * On output:
+ * \param tau the scaling factor of the Householder transformation
+ * \param beta the result of H * \c *this
+ *
+ * \sa MatrixBase::makeHouseholder(), MatrixBase::applyHouseholderOnTheLeft(),
+ * MatrixBase::applyHouseholderOnTheRight()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC
+void MatrixBase<Derived>::makeHouseholderInPlace(Scalar& tau, RealScalar& beta)
+{
+ VectorBlock<Derived, internal::decrement_size<Base::SizeAtCompileTime>::ret> essentialPart(derived(), 1, size()-1);
+ makeHouseholder(essentialPart, tau, beta);
+}
+
+/** Computes the elementary reflector H such that:
+ * \f$ H *this = [ beta 0 ... 0]^T \f$
+ * where the transformation H is:
+ * \f$ H = I - tau v v^*\f$
+ * and the vector v is:
+ * \f$ v^T = [1 essential^T] \f$
+ *
+ * On output:
+ * \param essential the essential part of the vector \c v
+ * \param tau the scaling factor of the Householder transformation
+ * \param beta the result of H * \c *this
+ *
+ * \sa MatrixBase::makeHouseholderInPlace(), MatrixBase::applyHouseholderOnTheLeft(),
+ * MatrixBase::applyHouseholderOnTheRight()
+ */
+template<typename Derived>
+template<typename EssentialPart>
+EIGEN_DEVICE_FUNC
+void MatrixBase<Derived>::makeHouseholder(
+ EssentialPart& essential,
+ Scalar& tau,
+ RealScalar& beta) const
+{
+ using std::sqrt;
+ using numext::conj;
+
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart)
+ VectorBlock<const Derived, EssentialPart::SizeAtCompileTime> tail(derived(), 1, size()-1);
+
+ RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm();
+ Scalar c0 = coeff(0);
+ const RealScalar tol = (std::numeric_limits<RealScalar>::min)();
+
+ if(tailSqNorm <= tol && numext::abs2(numext::imag(c0))<=tol)
+ {
+ tau = RealScalar(0);
+ beta = numext::real(c0);
+ essential.setZero();
+ }
+ else
+ {
+ beta = sqrt(numext::abs2(c0) + tailSqNorm);
+ if (numext::real(c0)>=RealScalar(0))
+ beta = -beta;
+ essential = tail / (c0 - beta);
+ tau = conj((beta - c0) / beta);
+ }
+}
+
+/** Apply the elementary reflector H given by
+ * \f$ H = I - tau v v^*\f$
+ * with
+ * \f$ v^T = [1 essential^T] \f$
+ * from the left to a vector or matrix.
+ *
+ * On input:
+ * \param essential the essential part of the vector \c v
+ * \param tau the scaling factor of the Householder transformation
+ * \param workspace a pointer to working space with at least
+ * this->cols() entries
+ *
+ * \sa MatrixBase::makeHouseholder(), MatrixBase::makeHouseholderInPlace(),
+ * MatrixBase::applyHouseholderOnTheRight()
+ */
+template<typename Derived>
+template<typename EssentialPart>
+EIGEN_DEVICE_FUNC
+void MatrixBase<Derived>::applyHouseholderOnTheLeft(
+ const EssentialPart& essential,
+ const Scalar& tau,
+ Scalar* workspace)
+{
+ if(rows() == 1)
+ {
+ *this *= Scalar(1)-tau;
+ }
+ else if(tau!=Scalar(0))
+ {
+ Map<typename internal::plain_row_type<PlainObject>::type> tmp(workspace,cols());
+ Block<Derived, EssentialPart::SizeAtCompileTime, Derived::ColsAtCompileTime> bottom(derived(), 1, 0, rows()-1, cols());
+ tmp.noalias() = essential.adjoint() * bottom;
+ tmp += this->row(0);
+ this->row(0) -= tau * tmp;
+ bottom.noalias() -= tau * essential * tmp;
+ }
+}
+
+/** Apply the elementary reflector H given by
+ * \f$ H = I - tau v v^*\f$
+ * with
+ * \f$ v^T = [1 essential^T] \f$
+ * from the right to a vector or matrix.
+ *
+ * On input:
+ * \param essential the essential part of the vector \c v
+ * \param tau the scaling factor of the Householder transformation
+ * \param workspace a pointer to working space with at least
+ * this->rows() entries
+ *
+ * \sa MatrixBase::makeHouseholder(), MatrixBase::makeHouseholderInPlace(),
+ * MatrixBase::applyHouseholderOnTheLeft()
+ */
+template<typename Derived>
+template<typename EssentialPart>
+EIGEN_DEVICE_FUNC
+void MatrixBase<Derived>::applyHouseholderOnTheRight(
+ const EssentialPart& essential,
+ const Scalar& tau,
+ Scalar* workspace)
+{
+ if(cols() == 1)
+ {
+ *this *= Scalar(1)-tau;
+ }
+ else if(tau!=Scalar(0))
+ {
+ Map<typename internal::plain_col_type<PlainObject>::type> tmp(workspace,rows());
+ Block<Derived, Derived::RowsAtCompileTime, EssentialPart::SizeAtCompileTime> right(derived(), 0, 1, rows(), cols()-1);
+ tmp.noalias() = right * essential;
+ tmp += this->col(0);
+ this->col(0) -= tau * tmp;
+ right.noalias() -= tau * tmp * essential.adjoint();
+ }
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_HOUSEHOLDER_H
diff --git a/src/3rdparty/eigen/Eigen/src/Householder/HouseholderSequence.h b/src/3rdparty/eigen/Eigen/src/Householder/HouseholderSequence.h
new file mode 100644
index 000000000..022f6c3db
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Householder/HouseholderSequence.h
@@ -0,0 +1,545 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_HOUSEHOLDER_SEQUENCE_H
+#define EIGEN_HOUSEHOLDER_SEQUENCE_H
+
+namespace Eigen {
+
+/** \ingroup Householder_Module
+ * \householder_module
+ * \class HouseholderSequence
+ * \brief Sequence of Householder reflections acting on subspaces with decreasing size
+ * \tparam VectorsType type of matrix containing the Householder vectors
+ * \tparam CoeffsType type of vector containing the Householder coefficients
+ * \tparam Side either OnTheLeft (the default) or OnTheRight
+ *
+ * This class represents a product sequence of Householder reflections where the first Householder reflection
+ * acts on the whole space, the second Householder reflection leaves the one-dimensional subspace spanned by
+ * the first unit vector invariant, the third Householder reflection leaves the two-dimensional subspace
+ * spanned by the first two unit vectors invariant, and so on up to the last reflection which leaves all but
+ * one dimensions invariant and acts only on the last dimension. Such sequences of Householder reflections
+ * are used in several algorithms to zero out certain parts of a matrix. Indeed, the methods
+ * HessenbergDecomposition::matrixQ(), Tridiagonalization::matrixQ(), HouseholderQR::householderQ(),
+ * and ColPivHouseholderQR::householderQ() all return a %HouseholderSequence.
+ *
+ * More precisely, the class %HouseholderSequence represents an \f$ n \times n \f$ matrix \f$ H \f$ of the
+ * form \f$ H = \prod_{i=0}^{n-1} H_i \f$ where the i-th Householder reflection is \f$ H_i = I - h_i v_i
+ * v_i^* \f$. The i-th Householder coefficient \f$ h_i \f$ is a scalar and the i-th Householder vector \f$
+ * v_i \f$ is a vector of the form
+ * \f[
+ * v_i = [\underbrace{0, \ldots, 0}_{i-1\mbox{ zeros}}, 1, \underbrace{*, \ldots,*}_{n-i\mbox{ arbitrary entries}} ].
+ * \f]
+ * The last \f$ n-i \f$ entries of \f$ v_i \f$ are called the essential part of the Householder vector.
+ *
+ * Typical usages are listed below, where H is a HouseholderSequence:
+ * \code
+ * A.applyOnTheRight(H); // A = A * H
+ * A.applyOnTheLeft(H); // A = H * A
+ * A.applyOnTheRight(H.adjoint()); // A = A * H^*
+ * A.applyOnTheLeft(H.adjoint()); // A = H^* * A
+ * MatrixXd Q = H; // conversion to a dense matrix
+ * \endcode
+ * In addition to the adjoint, you can also apply the inverse (=adjoint), the transpose, and the conjugate operators.
+ *
+ * See the documentation for HouseholderSequence(const VectorsType&, const CoeffsType&) for an example.
+ *
+ * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight()
+ */
+
+namespace internal {
+
+template<typename VectorsType, typename CoeffsType, int Side>
+struct traits<HouseholderSequence<VectorsType,CoeffsType,Side> >
+{
+ typedef typename VectorsType::Scalar Scalar;
+ typedef typename VectorsType::StorageIndex StorageIndex;
+ typedef typename VectorsType::StorageKind StorageKind;
+ enum {
+ RowsAtCompileTime = Side==OnTheLeft ? traits<VectorsType>::RowsAtCompileTime
+ : traits<VectorsType>::ColsAtCompileTime,
+ ColsAtCompileTime = RowsAtCompileTime,
+ MaxRowsAtCompileTime = Side==OnTheLeft ? traits<VectorsType>::MaxRowsAtCompileTime
+ : traits<VectorsType>::MaxColsAtCompileTime,
+ MaxColsAtCompileTime = MaxRowsAtCompileTime,
+ Flags = 0
+ };
+};
+
+struct HouseholderSequenceShape {};
+
+template<typename VectorsType, typename CoeffsType, int Side>
+struct evaluator_traits<HouseholderSequence<VectorsType,CoeffsType,Side> >
+ : public evaluator_traits_base<HouseholderSequence<VectorsType,CoeffsType,Side> >
+{
+ typedef HouseholderSequenceShape Shape;
+};
+
+template<typename VectorsType, typename CoeffsType, int Side>
+struct hseq_side_dependent_impl
+{
+ typedef Block<const VectorsType, Dynamic, 1> EssentialVectorType;
+ typedef HouseholderSequence<VectorsType, CoeffsType, OnTheLeft> HouseholderSequenceType;
+ static EIGEN_DEVICE_FUNC inline const EssentialVectorType essentialVector(const HouseholderSequenceType& h, Index k)
+ {
+ Index start = k+1+h.m_shift;
+ return Block<const VectorsType,Dynamic,1>(h.m_vectors, start, k, h.rows()-start, 1);
+ }
+};
+
+template<typename VectorsType, typename CoeffsType>
+struct hseq_side_dependent_impl<VectorsType, CoeffsType, OnTheRight>
+{
+ typedef Transpose<Block<const VectorsType, 1, Dynamic> > EssentialVectorType;
+ typedef HouseholderSequence<VectorsType, CoeffsType, OnTheRight> HouseholderSequenceType;
+ static inline const EssentialVectorType essentialVector(const HouseholderSequenceType& h, Index k)
+ {
+ Index start = k+1+h.m_shift;
+ return Block<const VectorsType,1,Dynamic>(h.m_vectors, k, start, 1, h.rows()-start).transpose();
+ }
+};
+
+template<typename OtherScalarType, typename MatrixType> struct matrix_type_times_scalar_type
+{
+ typedef typename ScalarBinaryOpTraits<OtherScalarType, typename MatrixType::Scalar>::ReturnType
+ ResultScalar;
+ typedef Matrix<ResultScalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime,
+ 0, MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime> Type;
+};
+
+} // end namespace internal
+
+template<typename VectorsType, typename CoeffsType, int Side> class HouseholderSequence
+ : public EigenBase<HouseholderSequence<VectorsType,CoeffsType,Side> >
+{
+ typedef typename internal::hseq_side_dependent_impl<VectorsType,CoeffsType,Side>::EssentialVectorType EssentialVectorType;
+
+ public:
+ enum {
+ RowsAtCompileTime = internal::traits<HouseholderSequence>::RowsAtCompileTime,
+ ColsAtCompileTime = internal::traits<HouseholderSequence>::ColsAtCompileTime,
+ MaxRowsAtCompileTime = internal::traits<HouseholderSequence>::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = internal::traits<HouseholderSequence>::MaxColsAtCompileTime
+ };
+ typedef typename internal::traits<HouseholderSequence>::Scalar Scalar;
+
+ typedef HouseholderSequence<
+ typename internal::conditional<NumTraits<Scalar>::IsComplex,
+ typename internal::remove_all<typename VectorsType::ConjugateReturnType>::type,
+ VectorsType>::type,
+ typename internal::conditional<NumTraits<Scalar>::IsComplex,
+ typename internal::remove_all<typename CoeffsType::ConjugateReturnType>::type,
+ CoeffsType>::type,
+ Side
+ > ConjugateReturnType;
+
+ typedef HouseholderSequence<
+ VectorsType,
+ typename internal::conditional<NumTraits<Scalar>::IsComplex,
+ typename internal::remove_all<typename CoeffsType::ConjugateReturnType>::type,
+ CoeffsType>::type,
+ Side
+ > AdjointReturnType;
+
+ typedef HouseholderSequence<
+ typename internal::conditional<NumTraits<Scalar>::IsComplex,
+ typename internal::remove_all<typename VectorsType::ConjugateReturnType>::type,
+ VectorsType>::type,
+ CoeffsType,
+ Side
+ > TransposeReturnType;
+
+ typedef HouseholderSequence<
+ typename internal::add_const<VectorsType>::type,
+ typename internal::add_const<CoeffsType>::type,
+ Side
+ > ConstHouseholderSequence;
+
+ /** \brief Constructor.
+ * \param[in] v %Matrix containing the essential parts of the Householder vectors
+ * \param[in] h Vector containing the Householder coefficients
+ *
+ * Constructs the Householder sequence with coefficients given by \p h and vectors given by \p v. The
+ * i-th Householder coefficient \f$ h_i \f$ is given by \p h(i) and the essential part of the i-th
+ * Householder vector \f$ v_i \f$ is given by \p v(k,i) with \p k > \p i (the subdiagonal part of the
+ * i-th column). If \p v has fewer columns than rows, then the Householder sequence contains as many
+ * Householder reflections as there are columns.
+ *
+ * \note The %HouseholderSequence object stores \p v and \p h by reference.
+ *
+ * Example: \include HouseholderSequence_HouseholderSequence.cpp
+ * Output: \verbinclude HouseholderSequence_HouseholderSequence.out
+ *
+ * \sa setLength(), setShift()
+ */
+ EIGEN_DEVICE_FUNC
+ HouseholderSequence(const VectorsType& v, const CoeffsType& h)
+ : m_vectors(v), m_coeffs(h), m_reverse(false), m_length(v.diagonalSize()),
+ m_shift(0)
+ {
+ }
+
+ /** \brief Copy constructor. */
+ EIGEN_DEVICE_FUNC
+ HouseholderSequence(const HouseholderSequence& other)
+ : m_vectors(other.m_vectors),
+ m_coeffs(other.m_coeffs),
+ m_reverse(other.m_reverse),
+ m_length(other.m_length),
+ m_shift(other.m_shift)
+ {
+ }
+
+ /** \brief Number of rows of transformation viewed as a matrix.
+ * \returns Number of rows
+ * \details This equals the dimension of the space that the transformation acts on.
+ */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ Index rows() const EIGEN_NOEXCEPT { return Side==OnTheLeft ? m_vectors.rows() : m_vectors.cols(); }
+
+ /** \brief Number of columns of transformation viewed as a matrix.
+ * \returns Number of columns
+ * \details This equals the dimension of the space that the transformation acts on.
+ */
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ Index cols() const EIGEN_NOEXCEPT { return rows(); }
+
+ /** \brief Essential part of a Householder vector.
+ * \param[in] k Index of Householder reflection
+ * \returns Vector containing non-trivial entries of k-th Householder vector
+ *
+ * This function returns the essential part of the Householder vector \f$ v_i \f$. This is a vector of
+ * length \f$ n-i \f$ containing the last \f$ n-i \f$ entries of the vector
+ * \f[
+ * v_i = [\underbrace{0, \ldots, 0}_{i-1\mbox{ zeros}}, 1, \underbrace{*, \ldots,*}_{n-i\mbox{ arbitrary entries}} ].
+ * \f]
+ * The index \f$ i \f$ equals \p k + shift(), corresponding to the k-th column of the matrix \p v
+ * passed to the constructor.
+ *
+ * \sa setShift(), shift()
+ */
+ EIGEN_DEVICE_FUNC
+ const EssentialVectorType essentialVector(Index k) const
+ {
+ eigen_assert(k >= 0 && k < m_length);
+ return internal::hseq_side_dependent_impl<VectorsType,CoeffsType,Side>::essentialVector(*this, k);
+ }
+
+ /** \brief %Transpose of the Householder sequence. */
+ TransposeReturnType transpose() const
+ {
+ return TransposeReturnType(m_vectors.conjugate(), m_coeffs)
+ .setReverseFlag(!m_reverse)
+ .setLength(m_length)
+ .setShift(m_shift);
+ }
+
+ /** \brief Complex conjugate of the Householder sequence. */
+ ConjugateReturnType conjugate() const
+ {
+ return ConjugateReturnType(m_vectors.conjugate(), m_coeffs.conjugate())
+ .setReverseFlag(m_reverse)
+ .setLength(m_length)
+ .setShift(m_shift);
+ }
+
+ /** \returns an expression of the complex conjugate of \c *this if Cond==true,
+ * returns \c *this otherwise.
+ */
+ template<bool Cond>
+ EIGEN_DEVICE_FUNC
+ inline typename internal::conditional<Cond,ConjugateReturnType,ConstHouseholderSequence>::type
+ conjugateIf() const
+ {
+ typedef typename internal::conditional<Cond,ConjugateReturnType,ConstHouseholderSequence>::type ReturnType;
+ return ReturnType(m_vectors.template conjugateIf<Cond>(), m_coeffs.template conjugateIf<Cond>());
+ }
+
+ /** \brief Adjoint (conjugate transpose) of the Householder sequence. */
+ AdjointReturnType adjoint() const
+ {
+ return AdjointReturnType(m_vectors, m_coeffs.conjugate())
+ .setReverseFlag(!m_reverse)
+ .setLength(m_length)
+ .setShift(m_shift);
+ }
+
+ /** \brief Inverse of the Householder sequence (equals the adjoint). */
+ AdjointReturnType inverse() const { return adjoint(); }
+
+ /** \internal */
+ template<typename DestType>
+ inline EIGEN_DEVICE_FUNC
+ void evalTo(DestType& dst) const
+ {
+ Matrix<Scalar, DestType::RowsAtCompileTime, 1,
+ AutoAlign|ColMajor, DestType::MaxRowsAtCompileTime, 1> workspace(rows());
+ evalTo(dst, workspace);
+ }
+
+ /** \internal */
+ template<typename Dest, typename Workspace>
+ EIGEN_DEVICE_FUNC
+ void evalTo(Dest& dst, Workspace& workspace) const
+ {
+ workspace.resize(rows());
+ Index vecs = m_length;
+ if(internal::is_same_dense(dst,m_vectors))
+ {
+ // in-place
+ dst.diagonal().setOnes();
+ dst.template triangularView<StrictlyUpper>().setZero();
+ for(Index k = vecs-1; k >= 0; --k)
+ {
+ Index cornerSize = rows() - k - m_shift;
+ if(m_reverse)
+ dst.bottomRightCorner(cornerSize, cornerSize)
+ .applyHouseholderOnTheRight(essentialVector(k), m_coeffs.coeff(k), workspace.data());
+ else
+ dst.bottomRightCorner(cornerSize, cornerSize)
+ .applyHouseholderOnTheLeft(essentialVector(k), m_coeffs.coeff(k), workspace.data());
+
+ // clear the off diagonal vector
+ dst.col(k).tail(rows()-k-1).setZero();
+ }
+ // clear the remaining columns if needed
+ for(Index k = 0; k<cols()-vecs ; ++k)
+ dst.col(k).tail(rows()-k-1).setZero();
+ }
+ else if(m_length>BlockSize)
+ {
+ dst.setIdentity(rows(), rows());
+ if(m_reverse)
+ applyThisOnTheLeft(dst,workspace,true);
+ else
+ applyThisOnTheLeft(dst,workspace,true);
+ }
+ else
+ {
+ dst.setIdentity(rows(), rows());
+ for(Index k = vecs-1; k >= 0; --k)
+ {
+ Index cornerSize = rows() - k - m_shift;
+ if(m_reverse)
+ dst.bottomRightCorner(cornerSize, cornerSize)
+ .applyHouseholderOnTheRight(essentialVector(k), m_coeffs.coeff(k), workspace.data());
+ else
+ dst.bottomRightCorner(cornerSize, cornerSize)
+ .applyHouseholderOnTheLeft(essentialVector(k), m_coeffs.coeff(k), workspace.data());
+ }
+ }
+ }
+
+ /** \internal */
+ template<typename Dest> inline void applyThisOnTheRight(Dest& dst) const
+ {
+ Matrix<Scalar,1,Dest::RowsAtCompileTime,RowMajor,1,Dest::MaxRowsAtCompileTime> workspace(dst.rows());
+ applyThisOnTheRight(dst, workspace);
+ }
+
+ /** \internal */
+ template<typename Dest, typename Workspace>
+ inline void applyThisOnTheRight(Dest& dst, Workspace& workspace) const
+ {
+ workspace.resize(dst.rows());
+ for(Index k = 0; k < m_length; ++k)
+ {
+ Index actual_k = m_reverse ? m_length-k-1 : k;
+ dst.rightCols(rows()-m_shift-actual_k)
+ .applyHouseholderOnTheRight(essentialVector(actual_k), m_coeffs.coeff(actual_k), workspace.data());
+ }
+ }
+
+ /** \internal */
+ template<typename Dest> inline void applyThisOnTheLeft(Dest& dst, bool inputIsIdentity = false) const
+ {
+ Matrix<Scalar,1,Dest::ColsAtCompileTime,RowMajor,1,Dest::MaxColsAtCompileTime> workspace;
+ applyThisOnTheLeft(dst, workspace, inputIsIdentity);
+ }
+
+ /** \internal */
+ template<typename Dest, typename Workspace>
+ inline void applyThisOnTheLeft(Dest& dst, Workspace& workspace, bool inputIsIdentity = false) const
+ {
+ if(inputIsIdentity && m_reverse)
+ inputIsIdentity = false;
+ // if the entries are large enough, then apply the reflectors by block
+ if(m_length>=BlockSize && dst.cols()>1)
+ {
+ // Make sure we have at least 2 useful blocks, otherwise it is point-less:
+ Index blockSize = m_length<Index(2*BlockSize) ? (m_length+1)/2 : Index(BlockSize);
+ for(Index i = 0; i < m_length; i+=blockSize)
+ {
+ Index end = m_reverse ? (std::min)(m_length,i+blockSize) : m_length-i;
+ Index k = m_reverse ? i : (std::max)(Index(0),end-blockSize);
+ Index bs = end-k;
+ Index start = k + m_shift;
+
+ typedef Block<typename internal::remove_all<VectorsType>::type,Dynamic,Dynamic> SubVectorsType;
+ SubVectorsType sub_vecs1(m_vectors.const_cast_derived(), Side==OnTheRight ? k : start,
+ Side==OnTheRight ? start : k,
+ Side==OnTheRight ? bs : m_vectors.rows()-start,
+ Side==OnTheRight ? m_vectors.cols()-start : bs);
+ typename internal::conditional<Side==OnTheRight, Transpose<SubVectorsType>, SubVectorsType&>::type sub_vecs(sub_vecs1);
+
+ Index dstStart = dst.rows()-rows()+m_shift+k;
+ Index dstRows = rows()-m_shift-k;
+ Block<Dest,Dynamic,Dynamic> sub_dst(dst,
+ dstStart,
+ inputIsIdentity ? dstStart : 0,
+ dstRows,
+ inputIsIdentity ? dstRows : dst.cols());
+ apply_block_householder_on_the_left(sub_dst, sub_vecs, m_coeffs.segment(k, bs), !m_reverse);
+ }
+ }
+ else
+ {
+ workspace.resize(dst.cols());
+ for(Index k = 0; k < m_length; ++k)
+ {
+ Index actual_k = m_reverse ? k : m_length-k-1;
+ Index dstStart = rows()-m_shift-actual_k;
+ dst.bottomRightCorner(dstStart, inputIsIdentity ? dstStart : dst.cols())
+ .applyHouseholderOnTheLeft(essentialVector(actual_k), m_coeffs.coeff(actual_k), workspace.data());
+ }
+ }
+ }
+
+ /** \brief Computes the product of a Householder sequence with a matrix.
+ * \param[in] other %Matrix being multiplied.
+ * \returns Expression object representing the product.
+ *
+ * This function computes \f$ HM \f$ where \f$ H \f$ is the Householder sequence represented by \p *this
+ * and \f$ M \f$ is the matrix \p other.
+ */
+ template<typename OtherDerived>
+ typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type operator*(const MatrixBase<OtherDerived>& other) const
+ {
+ typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type
+ res(other.template cast<typename internal::matrix_type_times_scalar_type<Scalar,OtherDerived>::ResultScalar>());
+ applyThisOnTheLeft(res, internal::is_identity<OtherDerived>::value && res.rows()==res.cols());
+ return res;
+ }
+
+ template<typename _VectorsType, typename _CoeffsType, int _Side> friend struct internal::hseq_side_dependent_impl;
+
+ /** \brief Sets the length of the Householder sequence.
+ * \param [in] length New value for the length.
+ *
+ * By default, the length \f$ n \f$ of the Householder sequence \f$ H = H_0 H_1 \ldots H_{n-1} \f$ is set
+ * to the number of columns of the matrix \p v passed to the constructor, or the number of rows if that
+ * is smaller. After this function is called, the length equals \p length.
+ *
+ * \sa length()
+ */
+ EIGEN_DEVICE_FUNC
+ HouseholderSequence& setLength(Index length)
+ {
+ m_length = length;
+ return *this;
+ }
+
+ /** \brief Sets the shift of the Householder sequence.
+ * \param [in] shift New value for the shift.
+ *
+ * By default, a %HouseholderSequence object represents \f$ H = H_0 H_1 \ldots H_{n-1} \f$ and the i-th
+ * column of the matrix \p v passed to the constructor corresponds to the i-th Householder
+ * reflection. After this function is called, the object represents \f$ H = H_{\mathrm{shift}}
+ * H_{\mathrm{shift}+1} \ldots H_{n-1} \f$ and the i-th column of \p v corresponds to the (shift+i)-th
+ * Householder reflection.
+ *
+ * \sa shift()
+ */
+ EIGEN_DEVICE_FUNC
+ HouseholderSequence& setShift(Index shift)
+ {
+ m_shift = shift;
+ return *this;
+ }
+
+ EIGEN_DEVICE_FUNC
+ Index length() const { return m_length; } /**< \brief Returns the length of the Householder sequence. */
+
+ EIGEN_DEVICE_FUNC
+ Index shift() const { return m_shift; } /**< \brief Returns the shift of the Householder sequence. */
+
+ /* Necessary for .adjoint() and .conjugate() */
+ template <typename VectorsType2, typename CoeffsType2, int Side2> friend class HouseholderSequence;
+
+ protected:
+
+ /** \internal
+ * \brief Sets the reverse flag.
+ * \param [in] reverse New value of the reverse flag.
+ *
+ * By default, the reverse flag is not set. If the reverse flag is set, then this object represents
+ * \f$ H^r = H_{n-1} \ldots H_1 H_0 \f$ instead of \f$ H = H_0 H_1 \ldots H_{n-1} \f$.
+ * \note For real valued HouseholderSequence this is equivalent to transposing \f$ H \f$.
+ *
+ * \sa reverseFlag(), transpose(), adjoint()
+ */
+ HouseholderSequence& setReverseFlag(bool reverse)
+ {
+ m_reverse = reverse;
+ return *this;
+ }
+
+ bool reverseFlag() const { return m_reverse; } /**< \internal \brief Returns the reverse flag. */
+
+ typename VectorsType::Nested m_vectors;
+ typename CoeffsType::Nested m_coeffs;
+ bool m_reverse;
+ Index m_length;
+ Index m_shift;
+ enum { BlockSize = 48 };
+};
+
+/** \brief Computes the product of a matrix with a Householder sequence.
+ * \param[in] other %Matrix being multiplied.
+ * \param[in] h %HouseholderSequence being multiplied.
+ * \returns Expression object representing the product.
+ *
+ * This function computes \f$ MH \f$ where \f$ M \f$ is the matrix \p other and \f$ H \f$ is the
+ * Householder sequence represented by \p h.
+ */
+template<typename OtherDerived, typename VectorsType, typename CoeffsType, int Side>
+typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar,OtherDerived>::Type operator*(const MatrixBase<OtherDerived>& other, const HouseholderSequence<VectorsType,CoeffsType,Side>& h)
+{
+ typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar,OtherDerived>::Type
+ res(other.template cast<typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar,OtherDerived>::ResultScalar>());
+ h.applyThisOnTheRight(res);
+ return res;
+}
+
+/** \ingroup Householder_Module \householder_module
+ * \brief Convenience function for constructing a Householder sequence.
+ * \returns A HouseholderSequence constructed from the specified arguments.
+ */
+template<typename VectorsType, typename CoeffsType>
+HouseholderSequence<VectorsType,CoeffsType> householderSequence(const VectorsType& v, const CoeffsType& h)
+{
+ return HouseholderSequence<VectorsType,CoeffsType,OnTheLeft>(v, h);
+}
+
+/** \ingroup Householder_Module \householder_module
+ * \brief Convenience function for constructing a Householder sequence.
+ * \returns A HouseholderSequence constructed from the specified arguments.
+ * \details This function differs from householderSequence() in that the template argument \p OnTheSide of
+ * the constructed HouseholderSequence is set to OnTheRight, instead of the default OnTheLeft.
+ */
+template<typename VectorsType, typename CoeffsType>
+HouseholderSequence<VectorsType,CoeffsType,OnTheRight> rightHouseholderSequence(const VectorsType& v, const CoeffsType& h)
+{
+ return HouseholderSequence<VectorsType,CoeffsType,OnTheRight>(v, h);
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_HOUSEHOLDER_SEQUENCE_H
diff --git a/src/3rdparty/eigen/Eigen/src/Jacobi/Jacobi.h b/src/3rdparty/eigen/Eigen/src/Jacobi/Jacobi.h
new file mode 100644
index 000000000..76668a574
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/Jacobi/Jacobi.h
@@ -0,0 +1,483 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_JACOBI_H
+#define EIGEN_JACOBI_H
+
+namespace Eigen {
+
+/** \ingroup Jacobi_Module
+ * \jacobi_module
+ * \class JacobiRotation
+ * \brief Rotation given by a cosine-sine pair.
+ *
+ * This class represents a Jacobi or Givens rotation.
+ * This is a 2D rotation in the plane \c J of angle \f$ \theta \f$ defined by
+ * its cosine \c c and sine \c s as follow:
+ * \f$ J = \left ( \begin{array}{cc} c & \overline s \\ -s & \overline c \end{array} \right ) \f$
+ *
+ * You can apply the respective counter-clockwise rotation to a column vector \c v by
+ * applying its adjoint on the left: \f$ v = J^* v \f$ that translates to the following Eigen code:
+ * \code
+ * v.applyOnTheLeft(J.adjoint());
+ * \endcode
+ *
+ * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight()
+ */
+template<typename Scalar> class JacobiRotation
+{
+ public:
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+
+ /** Default constructor without any initialization. */
+ EIGEN_DEVICE_FUNC
+ JacobiRotation() {}
+
+ /** Construct a planar rotation from a cosine-sine pair (\a c, \c s). */
+ EIGEN_DEVICE_FUNC
+ JacobiRotation(const Scalar& c, const Scalar& s) : m_c(c), m_s(s) {}
+
+ EIGEN_DEVICE_FUNC Scalar& c() { return m_c; }
+ EIGEN_DEVICE_FUNC Scalar c() const { return m_c; }
+ EIGEN_DEVICE_FUNC Scalar& s() { return m_s; }
+ EIGEN_DEVICE_FUNC Scalar s() const { return m_s; }
+
+ /** Concatenates two planar rotation */
+ EIGEN_DEVICE_FUNC
+ JacobiRotation operator*(const JacobiRotation& other)
+ {
+ using numext::conj;
+ return JacobiRotation(m_c * other.m_c - conj(m_s) * other.m_s,
+ conj(m_c * conj(other.m_s) + conj(m_s) * conj(other.m_c)));
+ }
+
+ /** Returns the transposed transformation */
+ EIGEN_DEVICE_FUNC
+ JacobiRotation transpose() const { using numext::conj; return JacobiRotation(m_c, -conj(m_s)); }
+
+ /** Returns the adjoint transformation */
+ EIGEN_DEVICE_FUNC
+ JacobiRotation adjoint() const { using numext::conj; return JacobiRotation(conj(m_c), -m_s); }
+
+ template<typename Derived>
+ EIGEN_DEVICE_FUNC
+ bool makeJacobi(const MatrixBase<Derived>&, Index p, Index q);
+ EIGEN_DEVICE_FUNC
+ bool makeJacobi(const RealScalar& x, const Scalar& y, const RealScalar& z);
+
+ EIGEN_DEVICE_FUNC
+ void makeGivens(const Scalar& p, const Scalar& q, Scalar* r=0);
+
+ protected:
+ EIGEN_DEVICE_FUNC
+ void makeGivens(const Scalar& p, const Scalar& q, Scalar* r, internal::true_type);
+ EIGEN_DEVICE_FUNC
+ void makeGivens(const Scalar& p, const Scalar& q, Scalar* r, internal::false_type);
+
+ Scalar m_c, m_s;
+};
+
+/** Makes \c *this as a Jacobi rotation \a J such that applying \a J on both the right and left sides of the selfadjoint 2x2 matrix
+ * \f$ B = \left ( \begin{array}{cc} x & y \\ \overline y & z \end{array} \right )\f$ yields a diagonal matrix \f$ A = J^* B J \f$
+ *
+ * \sa MatrixBase::makeJacobi(const MatrixBase<Derived>&, Index, Index), MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight()
+ */
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+bool JacobiRotation<Scalar>::makeJacobi(const RealScalar& x, const Scalar& y, const RealScalar& z)
+{
+ using std::sqrt;
+ using std::abs;
+
+ RealScalar deno = RealScalar(2)*abs(y);
+ if(deno < (std::numeric_limits<RealScalar>::min)())
+ {
+ m_c = Scalar(1);
+ m_s = Scalar(0);
+ return false;
+ }
+ else
+ {
+ RealScalar tau = (x-z)/deno;
+ RealScalar w = sqrt(numext::abs2(tau) + RealScalar(1));
+ RealScalar t;
+ if(tau>RealScalar(0))
+ {
+ t = RealScalar(1) / (tau + w);
+ }
+ else
+ {
+ t = RealScalar(1) / (tau - w);
+ }
+ RealScalar sign_t = t > RealScalar(0) ? RealScalar(1) : RealScalar(-1);
+ RealScalar n = RealScalar(1) / sqrt(numext::abs2(t)+RealScalar(1));
+ m_s = - sign_t * (numext::conj(y) / abs(y)) * abs(t) * n;
+ m_c = n;
+ return true;
+ }
+}
+
+/** Makes \c *this as a Jacobi rotation \c J such that applying \a J on both the right and left sides of the 2x2 selfadjoint matrix
+ * \f$ B = \left ( \begin{array}{cc} \text{this}_{pp} & \text{this}_{pq} \\ (\text{this}_{pq})^* & \text{this}_{qq} \end{array} \right )\f$ yields
+ * a diagonal matrix \f$ A = J^* B J \f$
+ *
+ * Example: \include Jacobi_makeJacobi.cpp
+ * Output: \verbinclude Jacobi_makeJacobi.out
+ *
+ * \sa JacobiRotation::makeJacobi(RealScalar, Scalar, RealScalar), MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight()
+ */
+template<typename Scalar>
+template<typename Derived>
+EIGEN_DEVICE_FUNC
+inline bool JacobiRotation<Scalar>::makeJacobi(const MatrixBase<Derived>& m, Index p, Index q)
+{
+ return makeJacobi(numext::real(m.coeff(p,p)), m.coeff(p,q), numext::real(m.coeff(q,q)));
+}
+
+/** Makes \c *this as a Givens rotation \c G such that applying \f$ G^* \f$ to the left of the vector
+ * \f$ V = \left ( \begin{array}{c} p \\ q \end{array} \right )\f$ yields:
+ * \f$ G^* V = \left ( \begin{array}{c} r \\ 0 \end{array} \right )\f$.
+ *
+ * The value of \a r is returned if \a r is not null (the default is null).
+ * Also note that G is built such that the cosine is always real.
+ *
+ * Example: \include Jacobi_makeGivens.cpp
+ * Output: \verbinclude Jacobi_makeGivens.out
+ *
+ * This function implements the continuous Givens rotation generation algorithm
+ * found in Anderson (2000), Discontinuous Plane Rotations and the Symmetric Eigenvalue Problem.
+ * LAPACK Working Note 150, University of Tennessee, UT-CS-00-454, December 4, 2000.
+ *
+ * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight()
+ */
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+void JacobiRotation<Scalar>::makeGivens(const Scalar& p, const Scalar& q, Scalar* r)
+{
+ makeGivens(p, q, r, typename internal::conditional<NumTraits<Scalar>::IsComplex, internal::true_type, internal::false_type>::type());
+}
+
+
+// specialization for complexes
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+void JacobiRotation<Scalar>::makeGivens(const Scalar& p, const Scalar& q, Scalar* r, internal::true_type)
+{
+ using std::sqrt;
+ using std::abs;
+ using numext::conj;
+
+ if(q==Scalar(0))
+ {
+ m_c = numext::real(p)<0 ? Scalar(-1) : Scalar(1);
+ m_s = 0;
+ if(r) *r = m_c * p;
+ }
+ else if(p==Scalar(0))
+ {
+ m_c = 0;
+ m_s = -q/abs(q);
+ if(r) *r = abs(q);
+ }
+ else
+ {
+ RealScalar p1 = numext::norm1(p);
+ RealScalar q1 = numext::norm1(q);
+ if(p1>=q1)
+ {
+ Scalar ps = p / p1;
+ RealScalar p2 = numext::abs2(ps);
+ Scalar qs = q / p1;
+ RealScalar q2 = numext::abs2(qs);
+
+ RealScalar u = sqrt(RealScalar(1) + q2/p2);
+ if(numext::real(p)<RealScalar(0))
+ u = -u;
+
+ m_c = Scalar(1)/u;
+ m_s = -qs*conj(ps)*(m_c/p2);
+ if(r) *r = p * u;
+ }
+ else
+ {
+ Scalar ps = p / q1;
+ RealScalar p2 = numext::abs2(ps);
+ Scalar qs = q / q1;
+ RealScalar q2 = numext::abs2(qs);
+
+ RealScalar u = q1 * sqrt(p2 + q2);
+ if(numext::real(p)<RealScalar(0))
+ u = -u;
+
+ p1 = abs(p);
+ ps = p/p1;
+ m_c = p1/u;
+ m_s = -conj(ps) * (q/u);
+ if(r) *r = ps * u;
+ }
+ }
+}
+
+// specialization for reals
+template<typename Scalar>
+EIGEN_DEVICE_FUNC
+void JacobiRotation<Scalar>::makeGivens(const Scalar& p, const Scalar& q, Scalar* r, internal::false_type)
+{
+ using std::sqrt;
+ using std::abs;
+ if(q==Scalar(0))
+ {
+ m_c = p<Scalar(0) ? Scalar(-1) : Scalar(1);
+ m_s = Scalar(0);
+ if(r) *r = abs(p);
+ }
+ else if(p==Scalar(0))
+ {
+ m_c = Scalar(0);
+ m_s = q<Scalar(0) ? Scalar(1) : Scalar(-1);
+ if(r) *r = abs(q);
+ }
+ else if(abs(p) > abs(q))
+ {
+ Scalar t = q/p;
+ Scalar u = sqrt(Scalar(1) + numext::abs2(t));
+ if(p<Scalar(0))
+ u = -u;
+ m_c = Scalar(1)/u;
+ m_s = -t * m_c;
+ if(r) *r = p * u;
+ }
+ else
+ {
+ Scalar t = p/q;
+ Scalar u = sqrt(Scalar(1) + numext::abs2(t));
+ if(q<Scalar(0))
+ u = -u;
+ m_s = -Scalar(1)/u;
+ m_c = -t * m_s;
+ if(r) *r = q * u;
+ }
+
+}
+
+/****************************************************************************************
+* Implementation of MatrixBase methods
+****************************************************************************************/
+
+namespace internal {
+/** \jacobi_module
+ * Applies the clock wise 2D rotation \a j to the set of 2D vectors of coordinates \a x and \a y:
+ * \f$ \left ( \begin{array}{cc} x \\ y \end{array} \right ) = J \left ( \begin{array}{cc} x \\ y \end{array} \right ) \f$
+ *
+ * \sa MatrixBase::applyOnTheLeft(), MatrixBase::applyOnTheRight()
+ */
+template<typename VectorX, typename VectorY, typename OtherScalar>
+EIGEN_DEVICE_FUNC
+void apply_rotation_in_the_plane(DenseBase<VectorX>& xpr_x, DenseBase<VectorY>& xpr_y, const JacobiRotation<OtherScalar>& j);
+}
+
+/** \jacobi_module
+ * Applies the rotation in the plane \a j to the rows \a p and \a q of \c *this, i.e., it computes B = J * B,
+ * with \f$ B = \left ( \begin{array}{cc} \text{*this.row}(p) \\ \text{*this.row}(q) \end{array} \right ) \f$.
+ *
+ * \sa class JacobiRotation, MatrixBase::applyOnTheRight(), internal::apply_rotation_in_the_plane()
+ */
+template<typename Derived>
+template<typename OtherScalar>
+EIGEN_DEVICE_FUNC
+inline void MatrixBase<Derived>::applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j)
+{
+ RowXpr x(this->row(p));
+ RowXpr y(this->row(q));
+ internal::apply_rotation_in_the_plane(x, y, j);
+}
+
+/** \ingroup Jacobi_Module
+ * Applies the rotation in the plane \a j to the columns \a p and \a q of \c *this, i.e., it computes B = B * J
+ * with \f$ B = \left ( \begin{array}{cc} \text{*this.col}(p) & \text{*this.col}(q) \end{array} \right ) \f$.
+ *
+ * \sa class JacobiRotation, MatrixBase::applyOnTheLeft(), internal::apply_rotation_in_the_plane()
+ */
+template<typename Derived>
+template<typename OtherScalar>
+EIGEN_DEVICE_FUNC
+inline void MatrixBase<Derived>::applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j)
+{
+ ColXpr x(this->col(p));
+ ColXpr y(this->col(q));
+ internal::apply_rotation_in_the_plane(x, y, j.transpose());
+}
+
+namespace internal {
+
+template<typename Scalar, typename OtherScalar,
+ int SizeAtCompileTime, int MinAlignment, bool Vectorizable>
+struct apply_rotation_in_the_plane_selector
+{
+ static EIGEN_DEVICE_FUNC
+ inline void run(Scalar *x, Index incrx, Scalar *y, Index incry, Index size, OtherScalar c, OtherScalar s)
+ {
+ for(Index i=0; i<size; ++i)
+ {
+ Scalar xi = *x;
+ Scalar yi = *y;
+ *x = c * xi + numext::conj(s) * yi;
+ *y = -s * xi + numext::conj(c) * yi;
+ x += incrx;
+ y += incry;
+ }
+ }
+};
+
+template<typename Scalar, typename OtherScalar,
+ int SizeAtCompileTime, int MinAlignment>
+struct apply_rotation_in_the_plane_selector<Scalar,OtherScalar,SizeAtCompileTime,MinAlignment,true /* vectorizable */>
+{
+ static inline void run(Scalar *x, Index incrx, Scalar *y, Index incry, Index size, OtherScalar c, OtherScalar s)
+ {
+ enum {
+ PacketSize = packet_traits<Scalar>::size,
+ OtherPacketSize = packet_traits<OtherScalar>::size
+ };
+ typedef typename packet_traits<Scalar>::type Packet;
+ typedef typename packet_traits<OtherScalar>::type OtherPacket;
+
+ /*** dynamic-size vectorized paths ***/
+ if(SizeAtCompileTime == Dynamic && ((incrx==1 && incry==1) || PacketSize == 1))
+ {
+ // both vectors are sequentially stored in memory => vectorization
+ enum { Peeling = 2 };
+
+ Index alignedStart = internal::first_default_aligned(y, size);
+ Index alignedEnd = alignedStart + ((size-alignedStart)/PacketSize)*PacketSize;
+
+ const OtherPacket pc = pset1<OtherPacket>(c);
+ const OtherPacket ps = pset1<OtherPacket>(s);
+ conj_helper<OtherPacket,Packet,NumTraits<OtherScalar>::IsComplex,false> pcj;
+ conj_helper<OtherPacket,Packet,false,false> pm;
+
+ for(Index i=0; i<alignedStart; ++i)
+ {
+ Scalar xi = x[i];
+ Scalar yi = y[i];
+ x[i] = c * xi + numext::conj(s) * yi;
+ y[i] = -s * xi + numext::conj(c) * yi;
+ }
+
+ Scalar* EIGEN_RESTRICT px = x + alignedStart;
+ Scalar* EIGEN_RESTRICT py = y + alignedStart;
+
+ if(internal::first_default_aligned(x, size)==alignedStart)
+ {
+ for(Index i=alignedStart; i<alignedEnd; i+=PacketSize)
+ {
+ Packet xi = pload<Packet>(px);
+ Packet yi = pload<Packet>(py);
+ pstore(px, padd(pm.pmul(pc,xi),pcj.pmul(ps,yi)));
+ pstore(py, psub(pcj.pmul(pc,yi),pm.pmul(ps,xi)));
+ px += PacketSize;
+ py += PacketSize;
+ }
+ }
+ else
+ {
+ Index peelingEnd = alignedStart + ((size-alignedStart)/(Peeling*PacketSize))*(Peeling*PacketSize);
+ for(Index i=alignedStart; i<peelingEnd; i+=Peeling*PacketSize)
+ {
+ Packet xi = ploadu<Packet>(px);
+ Packet xi1 = ploadu<Packet>(px+PacketSize);
+ Packet yi = pload <Packet>(py);
+ Packet yi1 = pload <Packet>(py+PacketSize);
+ pstoreu(px, padd(pm.pmul(pc,xi),pcj.pmul(ps,yi)));
+ pstoreu(px+PacketSize, padd(pm.pmul(pc,xi1),pcj.pmul(ps,yi1)));
+ pstore (py, psub(pcj.pmul(pc,yi),pm.pmul(ps,xi)));
+ pstore (py+PacketSize, psub(pcj.pmul(pc,yi1),pm.pmul(ps,xi1)));
+ px += Peeling*PacketSize;
+ py += Peeling*PacketSize;
+ }
+ if(alignedEnd!=peelingEnd)
+ {
+ Packet xi = ploadu<Packet>(x+peelingEnd);
+ Packet yi = pload <Packet>(y+peelingEnd);
+ pstoreu(x+peelingEnd, padd(pm.pmul(pc,xi),pcj.pmul(ps,yi)));
+ pstore (y+peelingEnd, psub(pcj.pmul(pc,yi),pm.pmul(ps,xi)));
+ }
+ }
+
+ for(Index i=alignedEnd; i<size; ++i)
+ {
+ Scalar xi = x[i];
+ Scalar yi = y[i];
+ x[i] = c * xi + numext::conj(s) * yi;
+ y[i] = -s * xi + numext::conj(c) * yi;
+ }
+ }
+
+ /*** fixed-size vectorized path ***/
+ else if(SizeAtCompileTime != Dynamic && MinAlignment>0) // FIXME should be compared to the required alignment
+ {
+ const OtherPacket pc = pset1<OtherPacket>(c);
+ const OtherPacket ps = pset1<OtherPacket>(s);
+ conj_helper<OtherPacket,Packet,NumTraits<OtherPacket>::IsComplex,false> pcj;
+ conj_helper<OtherPacket,Packet,false,false> pm;
+ Scalar* EIGEN_RESTRICT px = x;
+ Scalar* EIGEN_RESTRICT py = y;
+ for(Index i=0; i<size; i+=PacketSize)
+ {
+ Packet xi = pload<Packet>(px);
+ Packet yi = pload<Packet>(py);
+ pstore(px, padd(pm.pmul(pc,xi),pcj.pmul(ps,yi)));
+ pstore(py, psub(pcj.pmul(pc,yi),pm.pmul(ps,xi)));
+ px += PacketSize;
+ py += PacketSize;
+ }
+ }
+
+ /*** non-vectorized path ***/
+ else
+ {
+ apply_rotation_in_the_plane_selector<Scalar,OtherScalar,SizeAtCompileTime,MinAlignment,false>::run(x,incrx,y,incry,size,c,s);
+ }
+ }
+};
+
+template<typename VectorX, typename VectorY, typename OtherScalar>
+EIGEN_DEVICE_FUNC
+void /*EIGEN_DONT_INLINE*/ apply_rotation_in_the_plane(DenseBase<VectorX>& xpr_x, DenseBase<VectorY>& xpr_y, const JacobiRotation<OtherScalar>& j)
+{
+ typedef typename VectorX::Scalar Scalar;
+ const bool Vectorizable = (int(VectorX::Flags) & int(VectorY::Flags) & PacketAccessBit)
+ && (int(packet_traits<Scalar>::size) == int(packet_traits<OtherScalar>::size));
+
+ eigen_assert(xpr_x.size() == xpr_y.size());
+ Index size = xpr_x.size();
+ Index incrx = xpr_x.derived().innerStride();
+ Index incry = xpr_y.derived().innerStride();
+
+ Scalar* EIGEN_RESTRICT x = &xpr_x.derived().coeffRef(0);
+ Scalar* EIGEN_RESTRICT y = &xpr_y.derived().coeffRef(0);
+
+ OtherScalar c = j.c();
+ OtherScalar s = j.s();
+ if (c==OtherScalar(1) && s==OtherScalar(0))
+ return;
+
+ apply_rotation_in_the_plane_selector<
+ Scalar,OtherScalar,
+ VectorX::SizeAtCompileTime,
+ EIGEN_PLAIN_ENUM_MIN(evaluator<VectorX>::Alignment, evaluator<VectorY>::Alignment),
+ Vectorizable>::run(x,incrx,y,incry,size,c,s);
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_JACOBI_H
diff --git a/src/3rdparty/eigen/Eigen/src/LU/Determinant.h b/src/3rdparty/eigen/Eigen/src/LU/Determinant.h
new file mode 100644
index 000000000..3a41e6fcb
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/LU/Determinant.h
@@ -0,0 +1,117 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_DETERMINANT_H
+#define EIGEN_DETERMINANT_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename Derived>
+EIGEN_DEVICE_FUNC
+inline const typename Derived::Scalar bruteforce_det3_helper
+(const MatrixBase<Derived>& matrix, int a, int b, int c)
+{
+ return matrix.coeff(0,a)
+ * (matrix.coeff(1,b) * matrix.coeff(2,c) - matrix.coeff(1,c) * matrix.coeff(2,b));
+}
+
+template<typename Derived,
+ int DeterminantType = Derived::RowsAtCompileTime
+> struct determinant_impl
+{
+ static inline typename traits<Derived>::Scalar run(const Derived& m)
+ {
+ if(Derived::ColsAtCompileTime==Dynamic && m.rows()==0)
+ return typename traits<Derived>::Scalar(1);
+ return m.partialPivLu().determinant();
+ }
+};
+
+template<typename Derived> struct determinant_impl<Derived, 1>
+{
+ static inline EIGEN_DEVICE_FUNC
+ typename traits<Derived>::Scalar run(const Derived& m)
+ {
+ return m.coeff(0,0);
+ }
+};
+
+template<typename Derived> struct determinant_impl<Derived, 2>
+{
+ static inline EIGEN_DEVICE_FUNC
+ typename traits<Derived>::Scalar run(const Derived& m)
+ {
+ return m.coeff(0,0) * m.coeff(1,1) - m.coeff(1,0) * m.coeff(0,1);
+ }
+};
+
+template<typename Derived> struct determinant_impl<Derived, 3>
+{
+ static inline EIGEN_DEVICE_FUNC
+ typename traits<Derived>::Scalar run(const Derived& m)
+ {
+ return bruteforce_det3_helper(m,0,1,2)
+ - bruteforce_det3_helper(m,1,0,2)
+ + bruteforce_det3_helper(m,2,0,1);
+ }
+};
+
+template<typename Derived> struct determinant_impl<Derived, 4>
+{
+ typedef typename traits<Derived>::Scalar Scalar;
+ static EIGEN_DEVICE_FUNC
+ Scalar run(const Derived& m)
+ {
+ Scalar d2_01 = det2(m, 0, 1);
+ Scalar d2_02 = det2(m, 0, 2);
+ Scalar d2_03 = det2(m, 0, 3);
+ Scalar d2_12 = det2(m, 1, 2);
+ Scalar d2_13 = det2(m, 1, 3);
+ Scalar d2_23 = det2(m, 2, 3);
+ Scalar d3_0 = det3(m, 1,d2_23, 2,d2_13, 3,d2_12);
+ Scalar d3_1 = det3(m, 0,d2_23, 2,d2_03, 3,d2_02);
+ Scalar d3_2 = det3(m, 0,d2_13, 1,d2_03, 3,d2_01);
+ Scalar d3_3 = det3(m, 0,d2_12, 1,d2_02, 2,d2_01);
+ return internal::pmadd(-m(0,3),d3_0, m(1,3)*d3_1) +
+ internal::pmadd(-m(2,3),d3_2, m(3,3)*d3_3);
+ }
+protected:
+ static EIGEN_DEVICE_FUNC
+ Scalar det2(const Derived& m, Index i0, Index i1)
+ {
+ return m(i0,0) * m(i1,1) - m(i1,0) * m(i0,1);
+ }
+
+ static EIGEN_DEVICE_FUNC
+ Scalar det3(const Derived& m, Index i0, const Scalar& d0, Index i1, const Scalar& d1, Index i2, const Scalar& d2)
+ {
+ return internal::pmadd(m(i0,2), d0, internal::pmadd(-m(i1,2), d1, m(i2,2)*d2));
+ }
+};
+
+} // end namespace internal
+
+/** \lu_module
+ *
+ * \returns the determinant of this matrix
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC
+inline typename internal::traits<Derived>::Scalar MatrixBase<Derived>::determinant() const
+{
+ eigen_assert(rows() == cols());
+ typedef typename internal::nested_eval<Derived,Base::RowsAtCompileTime>::type Nested;
+ return internal::determinant_impl<typename internal::remove_all<Nested>::type>::run(derived());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_DETERMINANT_H
diff --git a/src/3rdparty/eigen/Eigen/src/LU/FullPivLU.h b/src/3rdparty/eigen/Eigen/src/LU/FullPivLU.h
new file mode 100644
index 000000000..ba1749fa6
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/LU/FullPivLU.h
@@ -0,0 +1,877 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_LU_H
+#define EIGEN_LU_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename _MatrixType> struct traits<FullPivLU<_MatrixType> >
+ : traits<_MatrixType>
+{
+ typedef MatrixXpr XprKind;
+ typedef SolverStorage StorageKind;
+ typedef int StorageIndex;
+ enum { Flags = 0 };
+};
+
+} // end namespace internal
+
+/** \ingroup LU_Module
+ *
+ * \class FullPivLU
+ *
+ * \brief LU decomposition of a matrix with complete pivoting, and related features
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the LU decomposition
+ *
+ * This class represents a LU decomposition of any matrix, with complete pivoting: the matrix A is
+ * decomposed as \f$ A = P^{-1} L U Q^{-1} \f$ where L is unit-lower-triangular, U is
+ * upper-triangular, and P and Q are permutation matrices. This is a rank-revealing LU
+ * decomposition. The eigenvalues (diagonal coefficients) of U are sorted in such a way that any
+ * zeros are at the end.
+ *
+ * This decomposition provides the generic approach to solving systems of linear equations, computing
+ * the rank, invertibility, inverse, kernel, and determinant.
+ *
+ * This LU decomposition is very stable and well tested with large matrices. However there are use cases where the SVD
+ * decomposition is inherently more stable and/or flexible. For example, when computing the kernel of a matrix,
+ * working with the SVD allows to select the smallest singular values of the matrix, something that
+ * the LU decomposition doesn't see.
+ *
+ * The data of the LU decomposition can be directly accessed through the methods matrixLU(),
+ * permutationP(), permutationQ().
+ *
+ * As an example, here is how the original matrix can be retrieved:
+ * \include class_FullPivLU.cpp
+ * Output: \verbinclude class_FullPivLU.out
+ *
+ * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism.
+ *
+ * \sa MatrixBase::fullPivLu(), MatrixBase::determinant(), MatrixBase::inverse()
+ */
+template<typename _MatrixType> class FullPivLU
+ : public SolverBase<FullPivLU<_MatrixType> >
+{
+ public:
+ typedef _MatrixType MatrixType;
+ typedef SolverBase<FullPivLU> Base;
+ friend class SolverBase<FullPivLU>;
+
+ EIGEN_GENERIC_PUBLIC_INTERFACE(FullPivLU)
+ enum {
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+ typedef typename internal::plain_row_type<MatrixType, StorageIndex>::type IntRowVectorType;
+ typedef typename internal::plain_col_type<MatrixType, StorageIndex>::type IntColVectorType;
+ typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime> PermutationQType;
+ typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationPType;
+ typedef typename MatrixType::PlainObject PlainObject;
+
+ /**
+ * \brief Default Constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via LU::compute(const MatrixType&).
+ */
+ FullPivLU();
+
+ /** \brief Default Constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem \a size.
+ * \sa FullPivLU()
+ */
+ FullPivLU(Index rows, Index cols);
+
+ /** Constructor.
+ *
+ * \param matrix the matrix of which to compute the LU decomposition.
+ * It is required to be nonzero.
+ */
+ template<typename InputType>
+ explicit FullPivLU(const EigenBase<InputType>& matrix);
+
+ /** \brief Constructs a LU factorization from a given matrix
+ *
+ * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c MatrixType is a Eigen::Ref.
+ *
+ * \sa FullPivLU(const EigenBase&)
+ */
+ template<typename InputType>
+ explicit FullPivLU(EigenBase<InputType>& matrix);
+
+ /** Computes the LU decomposition of the given matrix.
+ *
+ * \param matrix the matrix of which to compute the LU decomposition.
+ * It is required to be nonzero.
+ *
+ * \returns a reference to *this
+ */
+ template<typename InputType>
+ FullPivLU& compute(const EigenBase<InputType>& matrix) {
+ m_lu = matrix.derived();
+ computeInPlace();
+ return *this;
+ }
+
+ /** \returns the LU decomposition matrix: the upper-triangular part is U, the
+ * unit-lower-triangular part is L (at least for square matrices; in the non-square
+ * case, special care is needed, see the documentation of class FullPivLU).
+ *
+ * \sa matrixL(), matrixU()
+ */
+ inline const MatrixType& matrixLU() const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ return m_lu;
+ }
+
+ /** \returns the number of nonzero pivots in the LU decomposition.
+ * Here nonzero is meant in the exact sense, not in a fuzzy sense.
+ * So that notion isn't really intrinsically interesting, but it is
+ * still useful when implementing algorithms.
+ *
+ * \sa rank()
+ */
+ inline Index nonzeroPivots() const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ return m_nonzero_pivots;
+ }
+
+ /** \returns the absolute value of the biggest pivot, i.e. the biggest
+ * diagonal coefficient of U.
+ */
+ RealScalar maxPivot() const { return m_maxpivot; }
+
+ /** \returns the permutation matrix P
+ *
+ * \sa permutationQ()
+ */
+ EIGEN_DEVICE_FUNC inline const PermutationPType& permutationP() const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ return m_p;
+ }
+
+ /** \returns the permutation matrix Q
+ *
+ * \sa permutationP()
+ */
+ inline const PermutationQType& permutationQ() const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ return m_q;
+ }
+
+ /** \returns the kernel of the matrix, also called its null-space. The columns of the returned matrix
+ * will form a basis of the kernel.
+ *
+ * \note If the kernel has dimension zero, then the returned matrix is a column-vector filled with zeros.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ *
+ * Example: \include FullPivLU_kernel.cpp
+ * Output: \verbinclude FullPivLU_kernel.out
+ *
+ * \sa image()
+ */
+ inline const internal::kernel_retval<FullPivLU> kernel() const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ return internal::kernel_retval<FullPivLU>(*this);
+ }
+
+ /** \returns the image of the matrix, also called its column-space. The columns of the returned matrix
+ * will form a basis of the image (column-space).
+ *
+ * \param originalMatrix the original matrix, of which *this is the LU decomposition.
+ * The reason why it is needed to pass it here, is that this allows
+ * a large optimization, as otherwise this method would need to reconstruct it
+ * from the LU decomposition.
+ *
+ * \note If the image has dimension zero, then the returned matrix is a column-vector filled with zeros.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ *
+ * Example: \include FullPivLU_image.cpp
+ * Output: \verbinclude FullPivLU_image.out
+ *
+ * \sa kernel()
+ */
+ inline const internal::image_retval<FullPivLU>
+ image(const MatrixType& originalMatrix) const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ return internal::image_retval<FullPivLU>(*this, originalMatrix);
+ }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** \return a solution x to the equation Ax=b, where A is the matrix of which
+ * *this is the LU decomposition.
+ *
+ * \param b the right-hand-side of the equation to solve. Can be a vector or a matrix,
+ * the only requirement in order for the equation to make sense is that
+ * b.rows()==A.rows(), where A is the matrix of which *this is the LU decomposition.
+ *
+ * \returns a solution.
+ *
+ * \note_about_checking_solutions
+ *
+ * \note_about_arbitrary_choice_of_solution
+ * \note_about_using_kernel_to_study_multiple_solutions
+ *
+ * Example: \include FullPivLU_solve.cpp
+ * Output: \verbinclude FullPivLU_solve.out
+ *
+ * \sa TriangularView::solve(), kernel(), inverse()
+ */
+ template<typename Rhs>
+ inline const Solve<FullPivLU, Rhs>
+ solve(const MatrixBase<Rhs>& b) const;
+ #endif
+
+ /** \returns an estimate of the reciprocal condition number of the matrix of which \c *this is
+ the LU decomposition.
+ */
+ inline RealScalar rcond() const
+ {
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
+ return internal::rcond_estimate_helper(m_l1_norm, *this);
+ }
+
+ /** \returns the determinant of the matrix of which
+ * *this is the LU decomposition. It has only linear complexity
+ * (that is, O(n) where n is the dimension of the square matrix)
+ * as the LU decomposition has already been computed.
+ *
+ * \note This is only for square matrices.
+ *
+ * \note For fixed-size matrices of size up to 4, MatrixBase::determinant() offers
+ * optimized paths.
+ *
+ * \warning a determinant can be very big or small, so for matrices
+ * of large enough dimension, there is a risk of overflow/underflow.
+ *
+ * \sa MatrixBase::determinant()
+ */
+ typename internal::traits<MatrixType>::Scalar determinant() const;
+
+ /** Allows to prescribe a threshold to be used by certain methods, such as rank(),
+ * who need to determine when pivots are to be considered nonzero. This is not used for the
+ * LU decomposition itself.
+ *
+ * When it needs to get the threshold value, Eigen calls threshold(). By default, this
+ * uses a formula to automatically determine a reasonable threshold.
+ * Once you have called the present method setThreshold(const RealScalar&),
+ * your value is used instead.
+ *
+ * \param threshold The new value to use as the threshold.
+ *
+ * A pivot will be considered nonzero if its absolute value is strictly greater than
+ * \f$ \vert pivot \vert \leqslant threshold \times \vert maxpivot \vert \f$
+ * where maxpivot is the biggest pivot.
+ *
+ * If you want to come back to the default behavior, call setThreshold(Default_t)
+ */
+ FullPivLU& setThreshold(const RealScalar& threshold)
+ {
+ m_usePrescribedThreshold = true;
+ m_prescribedThreshold = threshold;
+ return *this;
+ }
+
+ /** Allows to come back to the default behavior, letting Eigen use its default formula for
+ * determining the threshold.
+ *
+ * You should pass the special object Eigen::Default as parameter here.
+ * \code lu.setThreshold(Eigen::Default); \endcode
+ *
+ * See the documentation of setThreshold(const RealScalar&).
+ */
+ FullPivLU& setThreshold(Default_t)
+ {
+ m_usePrescribedThreshold = false;
+ return *this;
+ }
+
+ /** Returns the threshold that will be used by certain methods such as rank().
+ *
+ * See the documentation of setThreshold(const RealScalar&).
+ */
+ RealScalar threshold() const
+ {
+ eigen_assert(m_isInitialized || m_usePrescribedThreshold);
+ return m_usePrescribedThreshold ? m_prescribedThreshold
+ // this formula comes from experimenting (see "LU precision tuning" thread on the list)
+ // and turns out to be identical to Higham's formula used already in LDLt.
+ : NumTraits<Scalar>::epsilon() * RealScalar(m_lu.diagonalSize());
+ }
+
+ /** \returns the rank of the matrix of which *this is the LU decomposition.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline Index rank() const
+ {
+ using std::abs;
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold();
+ Index result = 0;
+ for(Index i = 0; i < m_nonzero_pivots; ++i)
+ result += (abs(m_lu.coeff(i,i)) > premultiplied_threshold);
+ return result;
+ }
+
+ /** \returns the dimension of the kernel of the matrix of which *this is the LU decomposition.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline Index dimensionOfKernel() const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ return cols() - rank();
+ }
+
+ /** \returns true if the matrix of which *this is the LU decomposition represents an injective
+ * linear map, i.e. has trivial kernel; false otherwise.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline bool isInjective() const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ return rank() == cols();
+ }
+
+ /** \returns true if the matrix of which *this is the LU decomposition represents a surjective
+ * linear map; false otherwise.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline bool isSurjective() const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ return rank() == rows();
+ }
+
+ /** \returns true if the matrix of which *this is the LU decomposition is invertible.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline bool isInvertible() const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ return isInjective() && (m_lu.rows() == m_lu.cols());
+ }
+
+ /** \returns the inverse of the matrix of which *this is the LU decomposition.
+ *
+ * \note If this matrix is not invertible, the returned matrix has undefined coefficients.
+ * Use isInvertible() to first determine whether this matrix is invertible.
+ *
+ * \sa MatrixBase::inverse()
+ */
+ inline const Inverse<FullPivLU> inverse() const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ eigen_assert(m_lu.rows() == m_lu.cols() && "You can't take the inverse of a non-square matrix!");
+ return Inverse<FullPivLU>(*this);
+ }
+
+ MatrixType reconstructedMatrix() const;
+
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index rows() const EIGEN_NOEXCEPT { return m_lu.rows(); }
+ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
+ inline Index cols() const EIGEN_NOEXCEPT { return m_lu.cols(); }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename RhsType, typename DstType>
+ void _solve_impl(const RhsType &rhs, DstType &dst) const;
+
+ template<bool Conjugate, typename RhsType, typename DstType>
+ void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const;
+ #endif
+
+ protected:
+
+ static void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ }
+
+ void computeInPlace();
+
+ MatrixType m_lu;
+ PermutationPType m_p;
+ PermutationQType m_q;
+ IntColVectorType m_rowsTranspositions;
+ IntRowVectorType m_colsTranspositions;
+ Index m_nonzero_pivots;
+ RealScalar m_l1_norm;
+ RealScalar m_maxpivot, m_prescribedThreshold;
+ signed char m_det_pq;
+ bool m_isInitialized, m_usePrescribedThreshold;
+};
+
+template<typename MatrixType>
+FullPivLU<MatrixType>::FullPivLU()
+ : m_isInitialized(false), m_usePrescribedThreshold(false)
+{
+}
+
+template<typename MatrixType>
+FullPivLU<MatrixType>::FullPivLU(Index rows, Index cols)
+ : m_lu(rows, cols),
+ m_p(rows),
+ m_q(cols),
+ m_rowsTranspositions(rows),
+ m_colsTranspositions(cols),
+ m_isInitialized(false),
+ m_usePrescribedThreshold(false)
+{
+}
+
+template<typename MatrixType>
+template<typename InputType>
+FullPivLU<MatrixType>::FullPivLU(const EigenBase<InputType>& matrix)
+ : m_lu(matrix.rows(), matrix.cols()),
+ m_p(matrix.rows()),
+ m_q(matrix.cols()),
+ m_rowsTranspositions(matrix.rows()),
+ m_colsTranspositions(matrix.cols()),
+ m_isInitialized(false),
+ m_usePrescribedThreshold(false)
+{
+ compute(matrix.derived());
+}
+
+template<typename MatrixType>
+template<typename InputType>
+FullPivLU<MatrixType>::FullPivLU(EigenBase<InputType>& matrix)
+ : m_lu(matrix.derived()),
+ m_p(matrix.rows()),
+ m_q(matrix.cols()),
+ m_rowsTranspositions(matrix.rows()),
+ m_colsTranspositions(matrix.cols()),
+ m_isInitialized(false),
+ m_usePrescribedThreshold(false)
+{
+ computeInPlace();
+}
+
+template<typename MatrixType>
+void FullPivLU<MatrixType>::computeInPlace()
+{
+ check_template_parameters();
+
+ // the permutations are stored as int indices, so just to be sure:
+ eigen_assert(m_lu.rows()<=NumTraits<int>::highest() && m_lu.cols()<=NumTraits<int>::highest());
+
+ m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff();
+
+ const Index size = m_lu.diagonalSize();
+ const Index rows = m_lu.rows();
+ const Index cols = m_lu.cols();
+
+ // will store the transpositions, before we accumulate them at the end.
+ // can't accumulate on-the-fly because that will be done in reverse order for the rows.
+ m_rowsTranspositions.resize(m_lu.rows());
+ m_colsTranspositions.resize(m_lu.cols());
+ Index number_of_transpositions = 0; // number of NONTRIVIAL transpositions, i.e. m_rowsTranspositions[i]!=i
+
+ m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case)
+ m_maxpivot = RealScalar(0);
+
+ for(Index k = 0; k < size; ++k)
+ {
+ // First, we need to find the pivot.
+
+ // biggest coefficient in the remaining bottom-right corner (starting at row k, col k)
+ Index row_of_biggest_in_corner, col_of_biggest_in_corner;
+ typedef internal::scalar_score_coeff_op<Scalar> Scoring;
+ typedef typename Scoring::result_type Score;
+ Score biggest_in_corner;
+ biggest_in_corner = m_lu.bottomRightCorner(rows-k, cols-k)
+ .unaryExpr(Scoring())
+ .maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner);
+ row_of_biggest_in_corner += k; // correct the values! since they were computed in the corner,
+ col_of_biggest_in_corner += k; // need to add k to them.
+
+ if(biggest_in_corner==Score(0))
+ {
+ // before exiting, make sure to initialize the still uninitialized transpositions
+ // in a sane state without destroying what we already have.
+ m_nonzero_pivots = k;
+ for(Index i = k; i < size; ++i)
+ {
+ m_rowsTranspositions.coeffRef(i) = internal::convert_index<StorageIndex>(i);
+ m_colsTranspositions.coeffRef(i) = internal::convert_index<StorageIndex>(i);
+ }
+ break;
+ }
+
+ RealScalar abs_pivot = internal::abs_knowing_score<Scalar>()(m_lu(row_of_biggest_in_corner, col_of_biggest_in_corner), biggest_in_corner);
+ if(abs_pivot > m_maxpivot) m_maxpivot = abs_pivot;
+
+ // Now that we've found the pivot, we need to apply the row/col swaps to
+ // bring it to the location (k,k).
+
+ m_rowsTranspositions.coeffRef(k) = internal::convert_index<StorageIndex>(row_of_biggest_in_corner);
+ m_colsTranspositions.coeffRef(k) = internal::convert_index<StorageIndex>(col_of_biggest_in_corner);
+ if(k != row_of_biggest_in_corner) {
+ m_lu.row(k).swap(m_lu.row(row_of_biggest_in_corner));
+ ++number_of_transpositions;
+ }
+ if(k != col_of_biggest_in_corner) {
+ m_lu.col(k).swap(m_lu.col(col_of_biggest_in_corner));
+ ++number_of_transpositions;
+ }
+
+ // Now that the pivot is at the right location, we update the remaining
+ // bottom-right corner by Gaussian elimination.
+
+ if(k<rows-1)
+ m_lu.col(k).tail(rows-k-1) /= m_lu.coeff(k,k);
+ if(k<size-1)
+ m_lu.block(k+1,k+1,rows-k-1,cols-k-1).noalias() -= m_lu.col(k).tail(rows-k-1) * m_lu.row(k).tail(cols-k-1);
+ }
+
+ // the main loop is over, we still have to accumulate the transpositions to find the
+ // permutations P and Q
+
+ m_p.setIdentity(rows);
+ for(Index k = size-1; k >= 0; --k)
+ m_p.applyTranspositionOnTheRight(k, m_rowsTranspositions.coeff(k));
+
+ m_q.setIdentity(cols);
+ for(Index k = 0; k < size; ++k)
+ m_q.applyTranspositionOnTheRight(k, m_colsTranspositions.coeff(k));
+
+ m_det_pq = (number_of_transpositions%2) ? -1 : 1;
+
+ m_isInitialized = true;
+}
+
+template<typename MatrixType>
+typename internal::traits<MatrixType>::Scalar FullPivLU<MatrixType>::determinant() const
+{
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ eigen_assert(m_lu.rows() == m_lu.cols() && "You can't take the determinant of a non-square matrix!");
+ return Scalar(m_det_pq) * Scalar(m_lu.diagonal().prod());
+}
+
+/** \returns the matrix represented by the decomposition,
+ * i.e., it returns the product: \f$ P^{-1} L U Q^{-1} \f$.
+ * This function is provided for debug purposes. */
+template<typename MatrixType>
+MatrixType FullPivLU<MatrixType>::reconstructedMatrix() const
+{
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ const Index smalldim = (std::min)(m_lu.rows(), m_lu.cols());
+ // LU
+ MatrixType res(m_lu.rows(),m_lu.cols());
+ // FIXME the .toDenseMatrix() should not be needed...
+ res = m_lu.leftCols(smalldim)
+ .template triangularView<UnitLower>().toDenseMatrix()
+ * m_lu.topRows(smalldim)
+ .template triangularView<Upper>().toDenseMatrix();
+
+ // P^{-1}(LU)
+ res = m_p.inverse() * res;
+
+ // (P^{-1}LU)Q^{-1}
+ res = res * m_q.inverse();
+
+ return res;
+}
+
+/********* Implementation of kernel() **************************************************/
+
+namespace internal {
+template<typename _MatrixType>
+struct kernel_retval<FullPivLU<_MatrixType> >
+ : kernel_retval_base<FullPivLU<_MatrixType> >
+{
+ EIGEN_MAKE_KERNEL_HELPERS(FullPivLU<_MatrixType>)
+
+ enum { MaxSmallDimAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(
+ MatrixType::MaxColsAtCompileTime,
+ MatrixType::MaxRowsAtCompileTime)
+ };
+
+ template<typename Dest> void evalTo(Dest& dst) const
+ {
+ using std::abs;
+ const Index cols = dec().matrixLU().cols(), dimker = cols - rank();
+ if(dimker == 0)
+ {
+ // The Kernel is just {0}, so it doesn't have a basis properly speaking, but let's
+ // avoid crashing/asserting as that depends on floating point calculations. Let's
+ // just return a single column vector filled with zeros.
+ dst.setZero();
+ return;
+ }
+
+ /* Let us use the following lemma:
+ *
+ * Lemma: If the matrix A has the LU decomposition PAQ = LU,
+ * then Ker A = Q(Ker U).
+ *
+ * Proof: trivial: just keep in mind that P, Q, L are invertible.
+ */
+
+ /* Thus, all we need to do is to compute Ker U, and then apply Q.
+ *
+ * U is upper triangular, with eigenvalues sorted so that any zeros appear at the end.
+ * Thus, the diagonal of U ends with exactly
+ * dimKer zero's. Let us use that to construct dimKer linearly
+ * independent vectors in Ker U.
+ */
+
+ Matrix<Index, Dynamic, 1, 0, MaxSmallDimAtCompileTime, 1> pivots(rank());
+ RealScalar premultiplied_threshold = dec().maxPivot() * dec().threshold();
+ Index p = 0;
+ for(Index i = 0; i < dec().nonzeroPivots(); ++i)
+ if(abs(dec().matrixLU().coeff(i,i)) > premultiplied_threshold)
+ pivots.coeffRef(p++) = i;
+ eigen_internal_assert(p == rank());
+
+ // we construct a temporaty trapezoid matrix m, by taking the U matrix and
+ // permuting the rows and cols to bring the nonnegligible pivots to the top of
+ // the main diagonal. We need that to be able to apply our triangular solvers.
+ // FIXME when we get triangularView-for-rectangular-matrices, this can be simplified
+ Matrix<typename MatrixType::Scalar, Dynamic, Dynamic, MatrixType::Options,
+ MaxSmallDimAtCompileTime, MatrixType::MaxColsAtCompileTime>
+ m(dec().matrixLU().block(0, 0, rank(), cols));
+ for(Index i = 0; i < rank(); ++i)
+ {
+ if(i) m.row(i).head(i).setZero();
+ m.row(i).tail(cols-i) = dec().matrixLU().row(pivots.coeff(i)).tail(cols-i);
+ }
+ m.block(0, 0, rank(), rank());
+ m.block(0, 0, rank(), rank()).template triangularView<StrictlyLower>().setZero();
+ for(Index i = 0; i < rank(); ++i)
+ m.col(i).swap(m.col(pivots.coeff(i)));
+
+ // ok, we have our trapezoid matrix, we can apply the triangular solver.
+ // notice that the math behind this suggests that we should apply this to the
+ // negative of the RHS, but for performance we just put the negative sign elsewhere, see below.
+ m.topLeftCorner(rank(), rank())
+ .template triangularView<Upper>().solveInPlace(
+ m.topRightCorner(rank(), dimker)
+ );
+
+ // now we must undo the column permutation that we had applied!
+ for(Index i = rank()-1; i >= 0; --i)
+ m.col(i).swap(m.col(pivots.coeff(i)));
+
+ // see the negative sign in the next line, that's what we were talking about above.
+ for(Index i = 0; i < rank(); ++i) dst.row(dec().permutationQ().indices().coeff(i)) = -m.row(i).tail(dimker);
+ for(Index i = rank(); i < cols; ++i) dst.row(dec().permutationQ().indices().coeff(i)).setZero();
+ for(Index k = 0; k < dimker; ++k) dst.coeffRef(dec().permutationQ().indices().coeff(rank()+k), k) = Scalar(1);
+ }
+};
+
+/***** Implementation of image() *****************************************************/
+
+template<typename _MatrixType>
+struct image_retval<FullPivLU<_MatrixType> >
+ : image_retval_base<FullPivLU<_MatrixType> >
+{
+ EIGEN_MAKE_IMAGE_HELPERS(FullPivLU<_MatrixType>)
+
+ enum { MaxSmallDimAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(
+ MatrixType::MaxColsAtCompileTime,
+ MatrixType::MaxRowsAtCompileTime)
+ };
+
+ template<typename Dest> void evalTo(Dest& dst) const
+ {
+ using std::abs;
+ if(rank() == 0)
+ {
+ // The Image is just {0}, so it doesn't have a basis properly speaking, but let's
+ // avoid crashing/asserting as that depends on floating point calculations. Let's
+ // just return a single column vector filled with zeros.
+ dst.setZero();
+ return;
+ }
+
+ Matrix<Index, Dynamic, 1, 0, MaxSmallDimAtCompileTime, 1> pivots(rank());
+ RealScalar premultiplied_threshold = dec().maxPivot() * dec().threshold();
+ Index p = 0;
+ for(Index i = 0; i < dec().nonzeroPivots(); ++i)
+ if(abs(dec().matrixLU().coeff(i,i)) > premultiplied_threshold)
+ pivots.coeffRef(p++) = i;
+ eigen_internal_assert(p == rank());
+
+ for(Index i = 0; i < rank(); ++i)
+ dst.col(i) = originalMatrix().col(dec().permutationQ().indices().coeff(pivots.coeff(i)));
+ }
+};
+
+/***** Implementation of solve() *****************************************************/
+
+} // end namespace internal
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+template<typename _MatrixType>
+template<typename RhsType, typename DstType>
+void FullPivLU<_MatrixType>::_solve_impl(const RhsType &rhs, DstType &dst) const
+{
+ /* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1}.
+ * So we proceed as follows:
+ * Step 1: compute c = P * rhs.
+ * Step 2: replace c by the solution x to Lx = c. Exists because L is invertible.
+ * Step 3: replace c by the solution x to Ux = c. May or may not exist.
+ * Step 4: result = Q * c;
+ */
+
+ const Index rows = this->rows(),
+ cols = this->cols(),
+ nonzero_pivots = this->rank();
+ const Index smalldim = (std::min)(rows, cols);
+
+ if(nonzero_pivots == 0)
+ {
+ dst.setZero();
+ return;
+ }
+
+ typename RhsType::PlainObject c(rhs.rows(), rhs.cols());
+
+ // Step 1
+ c = permutationP() * rhs;
+
+ // Step 2
+ m_lu.topLeftCorner(smalldim,smalldim)
+ .template triangularView<UnitLower>()
+ .solveInPlace(c.topRows(smalldim));
+ if(rows>cols)
+ c.bottomRows(rows-cols) -= m_lu.bottomRows(rows-cols) * c.topRows(cols);
+
+ // Step 3
+ m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots)
+ .template triangularView<Upper>()
+ .solveInPlace(c.topRows(nonzero_pivots));
+
+ // Step 4
+ for(Index i = 0; i < nonzero_pivots; ++i)
+ dst.row(permutationQ().indices().coeff(i)) = c.row(i);
+ for(Index i = nonzero_pivots; i < m_lu.cols(); ++i)
+ dst.row(permutationQ().indices().coeff(i)).setZero();
+}
+
+template<typename _MatrixType>
+template<bool Conjugate, typename RhsType, typename DstType>
+void FullPivLU<_MatrixType>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const
+{
+ /* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1},
+ * and since permutations are real and unitary, we can write this
+ * as A^T = Q U^T L^T P,
+ * So we proceed as follows:
+ * Step 1: compute c = Q^T rhs.
+ * Step 2: replace c by the solution x to U^T x = c. May or may not exist.
+ * Step 3: replace c by the solution x to L^T x = c.
+ * Step 4: result = P^T c.
+ * If Conjugate is true, replace "^T" by "^*" above.
+ */
+
+ const Index rows = this->rows(), cols = this->cols(),
+ nonzero_pivots = this->rank();
+ const Index smalldim = (std::min)(rows, cols);
+
+ if(nonzero_pivots == 0)
+ {
+ dst.setZero();
+ return;
+ }
+
+ typename RhsType::PlainObject c(rhs.rows(), rhs.cols());
+
+ // Step 1
+ c = permutationQ().inverse() * rhs;
+
+ // Step 2
+ m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots)
+ .template triangularView<Upper>()
+ .transpose()
+ .template conjugateIf<Conjugate>()
+ .solveInPlace(c.topRows(nonzero_pivots));
+
+ // Step 3
+ m_lu.topLeftCorner(smalldim, smalldim)
+ .template triangularView<UnitLower>()
+ .transpose()
+ .template conjugateIf<Conjugate>()
+ .solveInPlace(c.topRows(smalldim));
+
+ // Step 4
+ PermutationPType invp = permutationP().inverse().eval();
+ for(Index i = 0; i < smalldim; ++i)
+ dst.row(invp.indices().coeff(i)) = c.row(i);
+ for(Index i = smalldim; i < rows; ++i)
+ dst.row(invp.indices().coeff(i)).setZero();
+}
+
+#endif
+
+namespace internal {
+
+
+/***** Implementation of inverse() *****************************************************/
+template<typename DstXprType, typename MatrixType>
+struct Assignment<DstXprType, Inverse<FullPivLU<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename FullPivLU<MatrixType>::Scalar>, Dense2Dense>
+{
+ typedef FullPivLU<MatrixType> LuType;
+ typedef Inverse<LuType> SrcXprType;
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename MatrixType::Scalar> &)
+ {
+ dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols()));
+ }
+};
+} // end namespace internal
+
+/******* MatrixBase methods *****************************************************************/
+
+/** \lu_module
+ *
+ * \return the full-pivoting LU decomposition of \c *this.
+ *
+ * \sa class FullPivLU
+ */
+template<typename Derived>
+inline const FullPivLU<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::fullPivLu() const
+{
+ return FullPivLU<PlainObject>(eval());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_LU_H
diff --git a/src/3rdparty/eigen/Eigen/src/LU/InverseImpl.h b/src/3rdparty/eigen/Eigen/src/LU/InverseImpl.h
new file mode 100644
index 000000000..a40cefa9e
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/LU/InverseImpl.h
@@ -0,0 +1,432 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_INVERSE_IMPL_H
+#define EIGEN_INVERSE_IMPL_H
+
+namespace Eigen {
+
+namespace internal {
+
+/**********************************
+*** General case implementation ***
+**********************************/
+
+template<typename MatrixType, typename ResultType, int Size = MatrixType::RowsAtCompileTime>
+struct compute_inverse
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(const MatrixType& matrix, ResultType& result)
+ {
+ result = matrix.partialPivLu().inverse();
+ }
+};
+
+template<typename MatrixType, typename ResultType, int Size = MatrixType::RowsAtCompileTime>
+struct compute_inverse_and_det_with_check { /* nothing! general case not supported. */ };
+
+/****************************
+*** Size 1 implementation ***
+****************************/
+
+template<typename MatrixType, typename ResultType>
+struct compute_inverse<MatrixType, ResultType, 1>
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(const MatrixType& matrix, ResultType& result)
+ {
+ typedef typename MatrixType::Scalar Scalar;
+ internal::evaluator<MatrixType> matrixEval(matrix);
+ result.coeffRef(0,0) = Scalar(1) / matrixEval.coeff(0,0);
+ }
+};
+
+template<typename MatrixType, typename ResultType>
+struct compute_inverse_and_det_with_check<MatrixType, ResultType, 1>
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(
+ const MatrixType& matrix,
+ const typename MatrixType::RealScalar& absDeterminantThreshold,
+ ResultType& result,
+ typename ResultType::Scalar& determinant,
+ bool& invertible
+ )
+ {
+ using std::abs;
+ determinant = matrix.coeff(0,0);
+ invertible = abs(determinant) > absDeterminantThreshold;
+ if(invertible) result.coeffRef(0,0) = typename ResultType::Scalar(1) / determinant;
+ }
+};
+
+/****************************
+*** Size 2 implementation ***
+****************************/
+
+template<typename MatrixType, typename ResultType>
+EIGEN_DEVICE_FUNC
+inline void compute_inverse_size2_helper(
+ const MatrixType& matrix, const typename ResultType::Scalar& invdet,
+ ResultType& result)
+{
+ typename ResultType::Scalar temp = matrix.coeff(0,0);
+ result.coeffRef(0,0) = matrix.coeff(1,1) * invdet;
+ result.coeffRef(1,0) = -matrix.coeff(1,0) * invdet;
+ result.coeffRef(0,1) = -matrix.coeff(0,1) * invdet;
+ result.coeffRef(1,1) = temp * invdet;
+}
+
+template<typename MatrixType, typename ResultType>
+struct compute_inverse<MatrixType, ResultType, 2>
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(const MatrixType& matrix, ResultType& result)
+ {
+ typedef typename ResultType::Scalar Scalar;
+ const Scalar invdet = typename MatrixType::Scalar(1) / matrix.determinant();
+ compute_inverse_size2_helper(matrix, invdet, result);
+ }
+};
+
+template<typename MatrixType, typename ResultType>
+struct compute_inverse_and_det_with_check<MatrixType, ResultType, 2>
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(
+ const MatrixType& matrix,
+ const typename MatrixType::RealScalar& absDeterminantThreshold,
+ ResultType& inverse,
+ typename ResultType::Scalar& determinant,
+ bool& invertible
+ )
+ {
+ using std::abs;
+ typedef typename ResultType::Scalar Scalar;
+ determinant = matrix.determinant();
+ invertible = abs(determinant) > absDeterminantThreshold;
+ if(!invertible) return;
+ const Scalar invdet = Scalar(1) / determinant;
+ compute_inverse_size2_helper(matrix, invdet, inverse);
+ }
+};
+
+/****************************
+*** Size 3 implementation ***
+****************************/
+
+template<typename MatrixType, int i, int j>
+EIGEN_DEVICE_FUNC
+inline typename MatrixType::Scalar cofactor_3x3(const MatrixType& m)
+{
+ enum {
+ i1 = (i+1) % 3,
+ i2 = (i+2) % 3,
+ j1 = (j+1) % 3,
+ j2 = (j+2) % 3
+ };
+ return m.coeff(i1, j1) * m.coeff(i2, j2)
+ - m.coeff(i1, j2) * m.coeff(i2, j1);
+}
+
+template<typename MatrixType, typename ResultType>
+EIGEN_DEVICE_FUNC
+inline void compute_inverse_size3_helper(
+ const MatrixType& matrix,
+ const typename ResultType::Scalar& invdet,
+ const Matrix<typename ResultType::Scalar,3,1>& cofactors_col0,
+ ResultType& result)
+{
+ // Compute cofactors in a way that avoids aliasing issues.
+ typedef typename ResultType::Scalar Scalar;
+ const Scalar c01 = cofactor_3x3<MatrixType,0,1>(matrix) * invdet;
+ const Scalar c11 = cofactor_3x3<MatrixType,1,1>(matrix) * invdet;
+ const Scalar c02 = cofactor_3x3<MatrixType,0,2>(matrix) * invdet;
+ result.coeffRef(1,2) = cofactor_3x3<MatrixType,2,1>(matrix) * invdet;
+ result.coeffRef(2,1) = cofactor_3x3<MatrixType,1,2>(matrix) * invdet;
+ result.coeffRef(2,2) = cofactor_3x3<MatrixType,2,2>(matrix) * invdet;
+ result.coeffRef(1,0) = c01;
+ result.coeffRef(1,1) = c11;
+ result.coeffRef(2,0) = c02;
+ result.row(0) = cofactors_col0 * invdet;
+}
+
+template<typename MatrixType, typename ResultType>
+struct compute_inverse<MatrixType, ResultType, 3>
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(const MatrixType& matrix, ResultType& result)
+ {
+ typedef typename ResultType::Scalar Scalar;
+ Matrix<typename MatrixType::Scalar,3,1> cofactors_col0;
+ cofactors_col0.coeffRef(0) = cofactor_3x3<MatrixType,0,0>(matrix);
+ cofactors_col0.coeffRef(1) = cofactor_3x3<MatrixType,1,0>(matrix);
+ cofactors_col0.coeffRef(2) = cofactor_3x3<MatrixType,2,0>(matrix);
+ const Scalar det = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
+ const Scalar invdet = Scalar(1) / det;
+ compute_inverse_size3_helper(matrix, invdet, cofactors_col0, result);
+ }
+};
+
+template<typename MatrixType, typename ResultType>
+struct compute_inverse_and_det_with_check<MatrixType, ResultType, 3>
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(
+ const MatrixType& matrix,
+ const typename MatrixType::RealScalar& absDeterminantThreshold,
+ ResultType& inverse,
+ typename ResultType::Scalar& determinant,
+ bool& invertible
+ )
+ {
+ typedef typename ResultType::Scalar Scalar;
+ Matrix<Scalar,3,1> cofactors_col0;
+ cofactors_col0.coeffRef(0) = cofactor_3x3<MatrixType,0,0>(matrix);
+ cofactors_col0.coeffRef(1) = cofactor_3x3<MatrixType,1,0>(matrix);
+ cofactors_col0.coeffRef(2) = cofactor_3x3<MatrixType,2,0>(matrix);
+ determinant = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
+ invertible = Eigen::numext::abs(determinant) > absDeterminantThreshold;
+ if(!invertible) return;
+ const Scalar invdet = Scalar(1) / determinant;
+ compute_inverse_size3_helper(matrix, invdet, cofactors_col0, inverse);
+ }
+};
+
+/****************************
+*** Size 4 implementation ***
+****************************/
+
+template<typename Derived>
+EIGEN_DEVICE_FUNC
+inline const typename Derived::Scalar general_det3_helper
+(const MatrixBase<Derived>& matrix, int i1, int i2, int i3, int j1, int j2, int j3)
+{
+ return matrix.coeff(i1,j1)
+ * (matrix.coeff(i2,j2) * matrix.coeff(i3,j3) - matrix.coeff(i2,j3) * matrix.coeff(i3,j2));
+}
+
+template<typename MatrixType, int i, int j>
+EIGEN_DEVICE_FUNC
+inline typename MatrixType::Scalar cofactor_4x4(const MatrixType& matrix)
+{
+ enum {
+ i1 = (i+1) % 4,
+ i2 = (i+2) % 4,
+ i3 = (i+3) % 4,
+ j1 = (j+1) % 4,
+ j2 = (j+2) % 4,
+ j3 = (j+3) % 4
+ };
+ return general_det3_helper(matrix, i1, i2, i3, j1, j2, j3)
+ + general_det3_helper(matrix, i2, i3, i1, j1, j2, j3)
+ + general_det3_helper(matrix, i3, i1, i2, j1, j2, j3);
+}
+
+template<int Arch, typename Scalar, typename MatrixType, typename ResultType>
+struct compute_inverse_size4
+{
+ EIGEN_DEVICE_FUNC
+ static void run(const MatrixType& matrix, ResultType& result)
+ {
+ result.coeffRef(0,0) = cofactor_4x4<MatrixType,0,0>(matrix);
+ result.coeffRef(1,0) = -cofactor_4x4<MatrixType,0,1>(matrix);
+ result.coeffRef(2,0) = cofactor_4x4<MatrixType,0,2>(matrix);
+ result.coeffRef(3,0) = -cofactor_4x4<MatrixType,0,3>(matrix);
+ result.coeffRef(0,2) = cofactor_4x4<MatrixType,2,0>(matrix);
+ result.coeffRef(1,2) = -cofactor_4x4<MatrixType,2,1>(matrix);
+ result.coeffRef(2,2) = cofactor_4x4<MatrixType,2,2>(matrix);
+ result.coeffRef(3,2) = -cofactor_4x4<MatrixType,2,3>(matrix);
+ result.coeffRef(0,1) = -cofactor_4x4<MatrixType,1,0>(matrix);
+ result.coeffRef(1,1) = cofactor_4x4<MatrixType,1,1>(matrix);
+ result.coeffRef(2,1) = -cofactor_4x4<MatrixType,1,2>(matrix);
+ result.coeffRef(3,1) = cofactor_4x4<MatrixType,1,3>(matrix);
+ result.coeffRef(0,3) = -cofactor_4x4<MatrixType,3,0>(matrix);
+ result.coeffRef(1,3) = cofactor_4x4<MatrixType,3,1>(matrix);
+ result.coeffRef(2,3) = -cofactor_4x4<MatrixType,3,2>(matrix);
+ result.coeffRef(3,3) = cofactor_4x4<MatrixType,3,3>(matrix);
+ result /= (matrix.col(0).cwiseProduct(result.row(0).transpose())).sum();
+ }
+};
+
+template<typename MatrixType, typename ResultType>
+struct compute_inverse<MatrixType, ResultType, 4>
+ : compute_inverse_size4<Architecture::Target, typename MatrixType::Scalar,
+ MatrixType, ResultType>
+{
+};
+
+template<typename MatrixType, typename ResultType>
+struct compute_inverse_and_det_with_check<MatrixType, ResultType, 4>
+{
+ EIGEN_DEVICE_FUNC
+ static inline void run(
+ const MatrixType& matrix,
+ const typename MatrixType::RealScalar& absDeterminantThreshold,
+ ResultType& inverse,
+ typename ResultType::Scalar& determinant,
+ bool& invertible
+ )
+ {
+ using std::abs;
+ determinant = matrix.determinant();
+ invertible = abs(determinant) > absDeterminantThreshold;
+ if(invertible && extract_data(matrix) != extract_data(inverse)) {
+ compute_inverse<MatrixType, ResultType>::run(matrix, inverse);
+ }
+ else if(invertible) {
+ MatrixType matrix_t = matrix;
+ compute_inverse<MatrixType, ResultType>::run(matrix_t, inverse);
+ }
+ }
+};
+
+/*************************
+*** MatrixBase methods ***
+*************************/
+
+} // end namespace internal
+
+namespace internal {
+
+// Specialization for "dense = dense_xpr.inverse()"
+template<typename DstXprType, typename XprType>
+struct Assignment<DstXprType, Inverse<XprType>, internal::assign_op<typename DstXprType::Scalar,typename XprType::Scalar>, Dense2Dense>
+{
+ typedef Inverse<XprType> SrcXprType;
+ EIGEN_DEVICE_FUNC
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename XprType::Scalar> &)
+ {
+ Index dstRows = src.rows();
+ Index dstCols = src.cols();
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
+ dst.resize(dstRows, dstCols);
+
+ const int Size = EIGEN_PLAIN_ENUM_MIN(XprType::ColsAtCompileTime,DstXprType::ColsAtCompileTime);
+ EIGEN_ONLY_USED_FOR_DEBUG(Size);
+ eigen_assert(( (Size<=1) || (Size>4) || (extract_data(src.nestedExpression())!=extract_data(dst)))
+ && "Aliasing problem detected in inverse(), you need to do inverse().eval() here.");
+
+ typedef typename internal::nested_eval<XprType,XprType::ColsAtCompileTime>::type ActualXprType;
+ typedef typename internal::remove_all<ActualXprType>::type ActualXprTypeCleanded;
+
+ ActualXprType actual_xpr(src.nestedExpression());
+
+ compute_inverse<ActualXprTypeCleanded, DstXprType>::run(actual_xpr, dst);
+ }
+};
+
+
+} // end namespace internal
+
+/** \lu_module
+ *
+ * \returns the matrix inverse of this matrix.
+ *
+ * For small fixed sizes up to 4x4, this method uses cofactors.
+ * In the general case, this method uses class PartialPivLU.
+ *
+ * \note This matrix must be invertible, otherwise the result is undefined. If you need an
+ * invertibility check, do the following:
+ * \li for fixed sizes up to 4x4, use computeInverseAndDetWithCheck().
+ * \li for the general case, use class FullPivLU.
+ *
+ * Example: \include MatrixBase_inverse.cpp
+ * Output: \verbinclude MatrixBase_inverse.out
+ *
+ * \sa computeInverseAndDetWithCheck()
+ */
+template<typename Derived>
+EIGEN_DEVICE_FUNC
+inline const Inverse<Derived> MatrixBase<Derived>::inverse() const
+{
+ EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsInteger,THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES)
+ eigen_assert(rows() == cols());
+ return Inverse<Derived>(derived());
+}
+
+/** \lu_module
+ *
+ * Computation of matrix inverse and determinant, with invertibility check.
+ *
+ * This is only for fixed-size square matrices of size up to 4x4.
+ *
+ * Notice that it will trigger a copy of input matrix when trying to do the inverse in place.
+ *
+ * \param inverse Reference to the matrix in which to store the inverse.
+ * \param determinant Reference to the variable in which to store the determinant.
+ * \param invertible Reference to the bool variable in which to store whether the matrix is invertible.
+ * \param absDeterminantThreshold Optional parameter controlling the invertibility check.
+ * The matrix will be declared invertible if the absolute value of its
+ * determinant is greater than this threshold.
+ *
+ * Example: \include MatrixBase_computeInverseAndDetWithCheck.cpp
+ * Output: \verbinclude MatrixBase_computeInverseAndDetWithCheck.out
+ *
+ * \sa inverse(), computeInverseWithCheck()
+ */
+template<typename Derived>
+template<typename ResultType>
+inline void MatrixBase<Derived>::computeInverseAndDetWithCheck(
+ ResultType& inverse,
+ typename ResultType::Scalar& determinant,
+ bool& invertible,
+ const RealScalar& absDeterminantThreshold
+ ) const
+{
+ // i'd love to put some static assertions there, but SFINAE means that they have no effect...
+ eigen_assert(rows() == cols());
+ // for 2x2, it's worth giving a chance to avoid evaluating.
+ // for larger sizes, evaluating has negligible cost and limits code size.
+ typedef typename internal::conditional<
+ RowsAtCompileTime == 2,
+ typename internal::remove_all<typename internal::nested_eval<Derived, 2>::type>::type,
+ PlainObject
+ >::type MatrixType;
+ internal::compute_inverse_and_det_with_check<MatrixType, ResultType>::run
+ (derived(), absDeterminantThreshold, inverse, determinant, invertible);
+}
+
+/** \lu_module
+ *
+ * Computation of matrix inverse, with invertibility check.
+ *
+ * This is only for fixed-size square matrices of size up to 4x4.
+ *
+ * Notice that it will trigger a copy of input matrix when trying to do the inverse in place.
+ *
+ * \param inverse Reference to the matrix in which to store the inverse.
+ * \param invertible Reference to the bool variable in which to store whether the matrix is invertible.
+ * \param absDeterminantThreshold Optional parameter controlling the invertibility check.
+ * The matrix will be declared invertible if the absolute value of its
+ * determinant is greater than this threshold.
+ *
+ * Example: \include MatrixBase_computeInverseWithCheck.cpp
+ * Output: \verbinclude MatrixBase_computeInverseWithCheck.out
+ *
+ * \sa inverse(), computeInverseAndDetWithCheck()
+ */
+template<typename Derived>
+template<typename ResultType>
+inline void MatrixBase<Derived>::computeInverseWithCheck(
+ ResultType& inverse,
+ bool& invertible,
+ const RealScalar& absDeterminantThreshold
+ ) const
+{
+ Scalar determinant;
+ // i'd love to put some static assertions there, but SFINAE means that they have no effect...
+ eigen_assert(rows() == cols());
+ computeInverseAndDetWithCheck(inverse,determinant,invertible,absDeterminantThreshold);
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_INVERSE_IMPL_H
diff --git a/src/3rdparty/eigen/Eigen/src/LU/PartialPivLU.h b/src/3rdparty/eigen/Eigen/src/LU/PartialPivLU.h
new file mode 100644
index 000000000..34aed7249
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/LU/PartialPivLU.h
@@ -0,0 +1,624 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PARTIALLU_H
+#define EIGEN_PARTIALLU_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename _MatrixType> struct traits<PartialPivLU<_MatrixType> >
+ : traits<_MatrixType>
+{
+ typedef MatrixXpr XprKind;
+ typedef SolverStorage StorageKind;
+ typedef int StorageIndex;
+ typedef traits<_MatrixType> BaseTraits;
+ enum {
+ Flags = BaseTraits::Flags & RowMajorBit,
+ CoeffReadCost = Dynamic
+ };
+};
+
+template<typename T,typename Derived>
+struct enable_if_ref;
+// {
+// typedef Derived type;
+// };
+
+template<typename T,typename Derived>
+struct enable_if_ref<Ref<T>,Derived> {
+ typedef Derived type;
+};
+
+} // end namespace internal
+
+/** \ingroup LU_Module
+ *
+ * \class PartialPivLU
+ *
+ * \brief LU decomposition of a matrix with partial pivoting, and related features
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the LU decomposition
+ *
+ * This class represents a LU decomposition of a \b square \b invertible matrix, with partial pivoting: the matrix A
+ * is decomposed as A = PLU where L is unit-lower-triangular, U is upper-triangular, and P
+ * is a permutation matrix.
+ *
+ * Typically, partial pivoting LU decomposition is only considered numerically stable for square invertible
+ * matrices. Thus LAPACK's dgesv and dgesvx require the matrix to be square and invertible. The present class
+ * does the same. It will assert that the matrix is square, but it won't (actually it can't) check that the
+ * matrix is invertible: it is your task to check that you only use this decomposition on invertible matrices.
+ *
+ * The guaranteed safe alternative, working for all matrices, is the full pivoting LU decomposition, provided
+ * by class FullPivLU.
+ *
+ * This is \b not a rank-revealing LU decomposition. Many features are intentionally absent from this class,
+ * such as rank computation. If you need these features, use class FullPivLU.
+ *
+ * This LU decomposition is suitable to invert invertible matrices. It is what MatrixBase::inverse() uses
+ * in the general case.
+ * On the other hand, it is \b not suitable to determine whether a given matrix is invertible.
+ *
+ * The data of the LU decomposition can be directly accessed through the methods matrixLU(), permutationP().
+ *
+ * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism.
+ *
+ * \sa MatrixBase::partialPivLu(), MatrixBase::determinant(), MatrixBase::inverse(), MatrixBase::computeInverse(), class FullPivLU
+ */
+template<typename _MatrixType> class PartialPivLU
+ : public SolverBase<PartialPivLU<_MatrixType> >
+{
+ public:
+
+ typedef _MatrixType MatrixType;
+ typedef SolverBase<PartialPivLU> Base;
+ friend class SolverBase<PartialPivLU>;
+
+ EIGEN_GENERIC_PUBLIC_INTERFACE(PartialPivLU)
+ enum {
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+ typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationType;
+ typedef Transpositions<RowsAtCompileTime, MaxRowsAtCompileTime> TranspositionType;
+ typedef typename MatrixType::PlainObject PlainObject;
+
+ /**
+ * \brief Default Constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via PartialPivLU::compute(const MatrixType&).
+ */
+ PartialPivLU();
+
+ /** \brief Default Constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem \a size.
+ * \sa PartialPivLU()
+ */
+ explicit PartialPivLU(Index size);
+
+ /** Constructor.
+ *
+ * \param matrix the matrix of which to compute the LU decomposition.
+ *
+ * \warning The matrix should have full rank (e.g. if it's square, it should be invertible).
+ * If you need to deal with non-full rank, use class FullPivLU instead.
+ */
+ template<typename InputType>
+ explicit PartialPivLU(const EigenBase<InputType>& matrix);
+
+ /** Constructor for \link InplaceDecomposition inplace decomposition \endlink
+ *
+ * \param matrix the matrix of which to compute the LU decomposition.
+ *
+ * \warning The matrix should have full rank (e.g. if it's square, it should be invertible).
+ * If you need to deal with non-full rank, use class FullPivLU instead.
+ */
+ template<typename InputType>
+ explicit PartialPivLU(EigenBase<InputType>& matrix);
+
+ template<typename InputType>
+ PartialPivLU& compute(const EigenBase<InputType>& matrix) {
+ m_lu = matrix.derived();
+ compute();
+ return *this;
+ }
+
+ /** \returns the LU decomposition matrix: the upper-triangular part is U, the
+ * unit-lower-triangular part is L (at least for square matrices; in the non-square
+ * case, special care is needed, see the documentation of class FullPivLU).
+ *
+ * \sa matrixL(), matrixU()
+ */
+ inline const MatrixType& matrixLU() const
+ {
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
+ return m_lu;
+ }
+
+ /** \returns the permutation matrix P.
+ */
+ inline const PermutationType& permutationP() const
+ {
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
+ return m_p;
+ }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** This method returns the solution x to the equation Ax=b, where A is the matrix of which
+ * *this is the LU decomposition.
+ *
+ * \param b the right-hand-side of the equation to solve. Can be a vector or a matrix,
+ * the only requirement in order for the equation to make sense is that
+ * b.rows()==A.rows(), where A is the matrix of which *this is the LU decomposition.
+ *
+ * \returns the solution.
+ *
+ * Example: \include PartialPivLU_solve.cpp
+ * Output: \verbinclude PartialPivLU_solve.out
+ *
+ * Since this PartialPivLU class assumes anyway that the matrix A is invertible, the solution
+ * theoretically exists and is unique regardless of b.
+ *
+ * \sa TriangularView::solve(), inverse(), computeInverse()
+ */
+ template<typename Rhs>
+ inline const Solve<PartialPivLU, Rhs>
+ solve(const MatrixBase<Rhs>& b) const;
+ #endif
+
+ /** \returns an estimate of the reciprocal condition number of the matrix of which \c *this is
+ the LU decomposition.
+ */
+ inline RealScalar rcond() const
+ {
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
+ return internal::rcond_estimate_helper(m_l1_norm, *this);
+ }
+
+ /** \returns the inverse of the matrix of which *this is the LU decomposition.
+ *
+ * \warning The matrix being decomposed here is assumed to be invertible. If you need to check for
+ * invertibility, use class FullPivLU instead.
+ *
+ * \sa MatrixBase::inverse(), LU::inverse()
+ */
+ inline const Inverse<PartialPivLU> inverse() const
+ {
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
+ return Inverse<PartialPivLU>(*this);
+ }
+
+ /** \returns the determinant of the matrix of which
+ * *this is the LU decomposition. It has only linear complexity
+ * (that is, O(n) where n is the dimension of the square matrix)
+ * as the LU decomposition has already been computed.
+ *
+ * \note For fixed-size matrices of size up to 4, MatrixBase::determinant() offers
+ * optimized paths.
+ *
+ * \warning a determinant can be very big or small, so for matrices
+ * of large enough dimension, there is a risk of overflow/underflow.
+ *
+ * \sa MatrixBase::determinant()
+ */
+ Scalar determinant() const;
+
+ MatrixType reconstructedMatrix() const;
+
+ EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_lu.rows(); }
+ EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_lu.cols(); }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename RhsType, typename DstType>
+ EIGEN_DEVICE_FUNC
+ void _solve_impl(const RhsType &rhs, DstType &dst) const {
+ /* The decomposition PA = LU can be rewritten as A = P^{-1} L U.
+ * So we proceed as follows:
+ * Step 1: compute c = Pb.
+ * Step 2: replace c by the solution x to Lx = c.
+ * Step 3: replace c by the solution x to Ux = c.
+ */
+
+ // Step 1
+ dst = permutationP() * rhs;
+
+ // Step 2
+ m_lu.template triangularView<UnitLower>().solveInPlace(dst);
+
+ // Step 3
+ m_lu.template triangularView<Upper>().solveInPlace(dst);
+ }
+
+ template<bool Conjugate, typename RhsType, typename DstType>
+ EIGEN_DEVICE_FUNC
+ void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const {
+ /* The decomposition PA = LU can be rewritten as A^T = U^T L^T P.
+ * So we proceed as follows:
+ * Step 1: compute c as the solution to L^T c = b
+ * Step 2: replace c by the solution x to U^T x = c.
+ * Step 3: update c = P^-1 c.
+ */
+
+ eigen_assert(rhs.rows() == m_lu.cols());
+
+ // Step 1
+ dst = m_lu.template triangularView<Upper>().transpose()
+ .template conjugateIf<Conjugate>().solve(rhs);
+ // Step 2
+ m_lu.template triangularView<UnitLower>().transpose()
+ .template conjugateIf<Conjugate>().solveInPlace(dst);
+ // Step 3
+ dst = permutationP().transpose() * dst;
+ }
+ #endif
+
+ protected:
+
+ static void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ }
+
+ void compute();
+
+ MatrixType m_lu;
+ PermutationType m_p;
+ TranspositionType m_rowsTranspositions;
+ RealScalar m_l1_norm;
+ signed char m_det_p;
+ bool m_isInitialized;
+};
+
+template<typename MatrixType>
+PartialPivLU<MatrixType>::PartialPivLU()
+ : m_lu(),
+ m_p(),
+ m_rowsTranspositions(),
+ m_l1_norm(0),
+ m_det_p(0),
+ m_isInitialized(false)
+{
+}
+
+template<typename MatrixType>
+PartialPivLU<MatrixType>::PartialPivLU(Index size)
+ : m_lu(size, size),
+ m_p(size),
+ m_rowsTranspositions(size),
+ m_l1_norm(0),
+ m_det_p(0),
+ m_isInitialized(false)
+{
+}
+
+template<typename MatrixType>
+template<typename InputType>
+PartialPivLU<MatrixType>::PartialPivLU(const EigenBase<InputType>& matrix)
+ : m_lu(matrix.rows(),matrix.cols()),
+ m_p(matrix.rows()),
+ m_rowsTranspositions(matrix.rows()),
+ m_l1_norm(0),
+ m_det_p(0),
+ m_isInitialized(false)
+{
+ compute(matrix.derived());
+}
+
+template<typename MatrixType>
+template<typename InputType>
+PartialPivLU<MatrixType>::PartialPivLU(EigenBase<InputType>& matrix)
+ : m_lu(matrix.derived()),
+ m_p(matrix.rows()),
+ m_rowsTranspositions(matrix.rows()),
+ m_l1_norm(0),
+ m_det_p(0),
+ m_isInitialized(false)
+{
+ compute();
+}
+
+namespace internal {
+
+/** \internal This is the blocked version of fullpivlu_unblocked() */
+template<typename Scalar, int StorageOrder, typename PivIndex, int SizeAtCompileTime=Dynamic>
+struct partial_lu_impl
+{
+ static const int UnBlockedBound = 16;
+ static const bool UnBlockedAtCompileTime = SizeAtCompileTime!=Dynamic && SizeAtCompileTime<=UnBlockedBound;
+ static const int ActualSizeAtCompileTime = UnBlockedAtCompileTime ? SizeAtCompileTime : Dynamic;
+ // Remaining rows and columns at compile-time:
+ static const int RRows = SizeAtCompileTime==2 ? 1 : Dynamic;
+ static const int RCols = SizeAtCompileTime==2 ? 1 : Dynamic;
+ typedef Matrix<Scalar, ActualSizeAtCompileTime, ActualSizeAtCompileTime, StorageOrder> MatrixType;
+ typedef Ref<MatrixType> MatrixTypeRef;
+ typedef Ref<Matrix<Scalar, Dynamic, Dynamic, StorageOrder> > BlockType;
+ typedef typename MatrixType::RealScalar RealScalar;
+
+ /** \internal performs the LU decomposition in-place of the matrix \a lu
+ * using an unblocked algorithm.
+ *
+ * In addition, this function returns the row transpositions in the
+ * vector \a row_transpositions which must have a size equal to the number
+ * of columns of the matrix \a lu, and an integer \a nb_transpositions
+ * which returns the actual number of transpositions.
+ *
+ * \returns The index of the first pivot which is exactly zero if any, or a negative number otherwise.
+ */
+ static Index unblocked_lu(MatrixTypeRef& lu, PivIndex* row_transpositions, PivIndex& nb_transpositions)
+ {
+ typedef scalar_score_coeff_op<Scalar> Scoring;
+ typedef typename Scoring::result_type Score;
+ const Index rows = lu.rows();
+ const Index cols = lu.cols();
+ const Index size = (std::min)(rows,cols);
+ // For small compile-time matrices it is worth processing the last row separately:
+ // speedup: +100% for 2x2, +10% for others.
+ const Index endk = UnBlockedAtCompileTime ? size-1 : size;
+ nb_transpositions = 0;
+ Index first_zero_pivot = -1;
+ for(Index k = 0; k < endk; ++k)
+ {
+ int rrows = internal::convert_index<int>(rows-k-1);
+ int rcols = internal::convert_index<int>(cols-k-1);
+
+ Index row_of_biggest_in_col;
+ Score biggest_in_corner
+ = lu.col(k).tail(rows-k).unaryExpr(Scoring()).maxCoeff(&row_of_biggest_in_col);
+ row_of_biggest_in_col += k;
+
+ row_transpositions[k] = PivIndex(row_of_biggest_in_col);
+
+ if(biggest_in_corner != Score(0))
+ {
+ if(k != row_of_biggest_in_col)
+ {
+ lu.row(k).swap(lu.row(row_of_biggest_in_col));
+ ++nb_transpositions;
+ }
+
+ lu.col(k).tail(fix<RRows>(rrows)) /= lu.coeff(k,k);
+ }
+ else if(first_zero_pivot==-1)
+ {
+ // the pivot is exactly zero, we record the index of the first pivot which is exactly 0,
+ // and continue the factorization such we still have A = PLU
+ first_zero_pivot = k;
+ }
+
+ if(k<rows-1)
+ lu.bottomRightCorner(fix<RRows>(rrows),fix<RCols>(rcols)).noalias() -= lu.col(k).tail(fix<RRows>(rrows)) * lu.row(k).tail(fix<RCols>(rcols));
+ }
+
+ // special handling of the last entry
+ if(UnBlockedAtCompileTime)
+ {
+ Index k = endk;
+ row_transpositions[k] = PivIndex(k);
+ if (Scoring()(lu(k, k)) == Score(0) && first_zero_pivot == -1)
+ first_zero_pivot = k;
+ }
+
+ return first_zero_pivot;
+ }
+
+ /** \internal performs the LU decomposition in-place of the matrix represented
+ * by the variables \a rows, \a cols, \a lu_data, and \a lu_stride using a
+ * recursive, blocked algorithm.
+ *
+ * In addition, this function returns the row transpositions in the
+ * vector \a row_transpositions which must have a size equal to the number
+ * of columns of the matrix \a lu, and an integer \a nb_transpositions
+ * which returns the actual number of transpositions.
+ *
+ * \returns The index of the first pivot which is exactly zero if any, or a negative number otherwise.
+ *
+ * \note This very low level interface using pointers, etc. is to:
+ * 1 - reduce the number of instantiations to the strict minimum
+ * 2 - avoid infinite recursion of the instantiations with Block<Block<Block<...> > >
+ */
+ static Index blocked_lu(Index rows, Index cols, Scalar* lu_data, Index luStride, PivIndex* row_transpositions, PivIndex& nb_transpositions, Index maxBlockSize=256)
+ {
+ MatrixTypeRef lu = MatrixType::Map(lu_data,rows, cols, OuterStride<>(luStride));
+
+ const Index size = (std::min)(rows,cols);
+
+ // if the matrix is too small, no blocking:
+ if(UnBlockedAtCompileTime || size<=UnBlockedBound)
+ {
+ return unblocked_lu(lu, row_transpositions, nb_transpositions);
+ }
+
+ // automatically adjust the number of subdivisions to the size
+ // of the matrix so that there is enough sub blocks:
+ Index blockSize;
+ {
+ blockSize = size/8;
+ blockSize = (blockSize/16)*16;
+ blockSize = (std::min)((std::max)(blockSize,Index(8)), maxBlockSize);
+ }
+
+ nb_transpositions = 0;
+ Index first_zero_pivot = -1;
+ for(Index k = 0; k < size; k+=blockSize)
+ {
+ Index bs = (std::min)(size-k,blockSize); // actual size of the block
+ Index trows = rows - k - bs; // trailing rows
+ Index tsize = size - k - bs; // trailing size
+
+ // partition the matrix:
+ // A00 | A01 | A02
+ // lu = A_0 | A_1 | A_2 = A10 | A11 | A12
+ // A20 | A21 | A22
+ BlockType A_0 = lu.block(0,0,rows,k);
+ BlockType A_2 = lu.block(0,k+bs,rows,tsize);
+ BlockType A11 = lu.block(k,k,bs,bs);
+ BlockType A12 = lu.block(k,k+bs,bs,tsize);
+ BlockType A21 = lu.block(k+bs,k,trows,bs);
+ BlockType A22 = lu.block(k+bs,k+bs,trows,tsize);
+
+ PivIndex nb_transpositions_in_panel;
+ // recursively call the blocked LU algorithm on [A11^T A21^T]^T
+ // with a very small blocking size:
+ Index ret = blocked_lu(trows+bs, bs, &lu.coeffRef(k,k), luStride,
+ row_transpositions+k, nb_transpositions_in_panel, 16);
+ if(ret>=0 && first_zero_pivot==-1)
+ first_zero_pivot = k+ret;
+
+ nb_transpositions += nb_transpositions_in_panel;
+ // update permutations and apply them to A_0
+ for(Index i=k; i<k+bs; ++i)
+ {
+ Index piv = (row_transpositions[i] += internal::convert_index<PivIndex>(k));
+ A_0.row(i).swap(A_0.row(piv));
+ }
+
+ if(trows)
+ {
+ // apply permutations to A_2
+ for(Index i=k;i<k+bs; ++i)
+ A_2.row(i).swap(A_2.row(row_transpositions[i]));
+
+ // A12 = A11^-1 A12
+ A11.template triangularView<UnitLower>().solveInPlace(A12);
+
+ A22.noalias() -= A21 * A12;
+ }
+ }
+ return first_zero_pivot;
+ }
+};
+
+/** \internal performs the LU decomposition with partial pivoting in-place.
+ */
+template<typename MatrixType, typename TranspositionType>
+void partial_lu_inplace(MatrixType& lu, TranspositionType& row_transpositions, typename TranspositionType::StorageIndex& nb_transpositions)
+{
+ // Special-case of zero matrix.
+ if (lu.rows() == 0 || lu.cols() == 0) {
+ nb_transpositions = 0;
+ return;
+ }
+ eigen_assert(lu.cols() == row_transpositions.size());
+ eigen_assert(row_transpositions.size() < 2 || (&row_transpositions.coeffRef(1)-&row_transpositions.coeffRef(0)) == 1);
+
+ partial_lu_impl
+ < typename MatrixType::Scalar, MatrixType::Flags&RowMajorBit?RowMajor:ColMajor,
+ typename TranspositionType::StorageIndex,
+ EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::RowsAtCompileTime,MatrixType::ColsAtCompileTime)>
+ ::blocked_lu(lu.rows(), lu.cols(), &lu.coeffRef(0,0), lu.outerStride(), &row_transpositions.coeffRef(0), nb_transpositions);
+}
+
+} // end namespace internal
+
+template<typename MatrixType>
+void PartialPivLU<MatrixType>::compute()
+{
+ check_template_parameters();
+
+ // the row permutation is stored as int indices, so just to be sure:
+ eigen_assert(m_lu.rows()<NumTraits<int>::highest());
+
+ if(m_lu.cols()>0)
+ m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff();
+ else
+ m_l1_norm = RealScalar(0);
+
+ eigen_assert(m_lu.rows() == m_lu.cols() && "PartialPivLU is only for square (and moreover invertible) matrices");
+ const Index size = m_lu.rows();
+
+ m_rowsTranspositions.resize(size);
+
+ typename TranspositionType::StorageIndex nb_transpositions;
+ internal::partial_lu_inplace(m_lu, m_rowsTranspositions, nb_transpositions);
+ m_det_p = (nb_transpositions%2) ? -1 : 1;
+
+ m_p = m_rowsTranspositions;
+
+ m_isInitialized = true;
+}
+
+template<typename MatrixType>
+typename PartialPivLU<MatrixType>::Scalar PartialPivLU<MatrixType>::determinant() const
+{
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
+ return Scalar(m_det_p) * m_lu.diagonal().prod();
+}
+
+/** \returns the matrix represented by the decomposition,
+ * i.e., it returns the product: P^{-1} L U.
+ * This function is provided for debug purpose. */
+template<typename MatrixType>
+MatrixType PartialPivLU<MatrixType>::reconstructedMatrix() const
+{
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ // LU
+ MatrixType res = m_lu.template triangularView<UnitLower>().toDenseMatrix()
+ * m_lu.template triangularView<Upper>();
+
+ // P^{-1}(LU)
+ res = m_p.inverse() * res;
+
+ return res;
+}
+
+/***** Implementation details *****************************************************/
+
+namespace internal {
+
+/***** Implementation of inverse() *****************************************************/
+template<typename DstXprType, typename MatrixType>
+struct Assignment<DstXprType, Inverse<PartialPivLU<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename PartialPivLU<MatrixType>::Scalar>, Dense2Dense>
+{
+ typedef PartialPivLU<MatrixType> LuType;
+ typedef Inverse<LuType> SrcXprType;
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename LuType::Scalar> &)
+ {
+ dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols()));
+ }
+};
+} // end namespace internal
+
+/******** MatrixBase methods *******/
+
+/** \lu_module
+ *
+ * \return the partial-pivoting LU decomposition of \c *this.
+ *
+ * \sa class PartialPivLU
+ */
+template<typename Derived>
+inline const PartialPivLU<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::partialPivLu() const
+{
+ return PartialPivLU<PlainObject>(eval());
+}
+
+/** \lu_module
+ *
+ * Synonym of partialPivLu().
+ *
+ * \return the partial-pivoting LU decomposition of \c *this.
+ *
+ * \sa class PartialPivLU
+ */
+template<typename Derived>
+inline const PartialPivLU<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::lu() const
+{
+ return PartialPivLU<PlainObject>(eval());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_PARTIALLU_H
diff --git a/src/3rdparty/eigen/Eigen/src/LU/PartialPivLU_LAPACKE.h b/src/3rdparty/eigen/Eigen/src/LU/PartialPivLU_LAPACKE.h
new file mode 100644
index 000000000..755168a94
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/LU/PartialPivLU_LAPACKE.h
@@ -0,0 +1,83 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to LAPACKe
+ * LU decomposition with partial pivoting based on LAPACKE_?getrf function.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_PARTIALLU_LAPACK_H
+#define EIGEN_PARTIALLU_LAPACK_H
+
+namespace Eigen {
+
+namespace internal {
+
+/** \internal Specialization for the data types supported by LAPACKe */
+
+#define EIGEN_LAPACKE_LU_PARTPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX) \
+template<int StorageOrder> \
+struct partial_lu_impl<EIGTYPE, StorageOrder, lapack_int> \
+{ \
+ /* \internal performs the LU decomposition in-place of the matrix represented */ \
+ static lapack_int blocked_lu(Index rows, Index cols, EIGTYPE* lu_data, Index luStride, lapack_int* row_transpositions, lapack_int& nb_transpositions, lapack_int maxBlockSize=256) \
+ { \
+ EIGEN_UNUSED_VARIABLE(maxBlockSize);\
+ lapack_int matrix_order, first_zero_pivot; \
+ lapack_int m, n, lda, *ipiv, info; \
+ EIGTYPE* a; \
+/* Set up parameters for ?getrf */ \
+ matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \
+ lda = convert_index<lapack_int>(luStride); \
+ a = lu_data; \
+ ipiv = row_transpositions; \
+ m = convert_index<lapack_int>(rows); \
+ n = convert_index<lapack_int>(cols); \
+ nb_transpositions = 0; \
+\
+ info = LAPACKE_##LAPACKE_PREFIX##getrf( matrix_order, m, n, (LAPACKE_TYPE*)a, lda, ipiv ); \
+\
+ for(int i=0;i<m;i++) { ipiv[i]--; if (ipiv[i]!=i) nb_transpositions++; } \
+\
+ eigen_assert(info >= 0); \
+/* something should be done with nb_transpositions */ \
+\
+ first_zero_pivot = info; \
+ return first_zero_pivot; \
+ } \
+};
+
+EIGEN_LAPACKE_LU_PARTPIV(double, double, d)
+EIGEN_LAPACKE_LU_PARTPIV(float, float, s)
+EIGEN_LAPACKE_LU_PARTPIV(dcomplex, lapack_complex_double, z)
+EIGEN_LAPACKE_LU_PARTPIV(scomplex, lapack_complex_float, c)
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_PARTIALLU_LAPACK_H
diff --git a/src/3rdparty/eigen/Eigen/src/LU/arch/InverseSize4.h b/src/3rdparty/eigen/Eigen/src/LU/arch/InverseSize4.h
new file mode 100644
index 000000000..a232ffc0a
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/LU/arch/InverseSize4.h
@@ -0,0 +1,351 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2001 Intel Corporation
+// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+//
+// The algorithm below is a reimplementation of former \src\LU\Inverse_SSE.h using PacketMath.
+// inv(M) = M#/|M|, where inv(M), M# and |M| denote the inverse of M,
+// adjugate of M and determinant of M respectively. M# is computed block-wise
+// using specific formulae. For proof, see:
+// https://lxjk.github.io/2017/09/03/Fast-4x4-Matrix-Inverse-with-SSE-SIMD-Explained.html
+// Variable names are adopted from \src\LU\Inverse_SSE.h.
+//
+// The SSE code for the 4x4 float and double matrix inverse in former (deprecated) \src\LU\Inverse_SSE.h
+// comes from the following Intel's library:
+// http://software.intel.com/en-us/articles/optimized-matrix-library-for-use-with-the-intel-pentiumr-4-processors-sse2-instructions/
+//
+// Here is the respective copyright and license statement:
+//
+// Copyright (c) 2001 Intel Corporation.
+//
+// Permition is granted to use, copy, distribute and prepare derivative works
+// of this library for any purpose and without fee, provided, that the above
+// copyright notice and this statement appear in all copies.
+// Intel makes no representations about the suitability of this software for
+// any purpose, and specifically disclaims all warranties.
+// See LEGAL.TXT for all the legal information.
+//
+// TODO: Unify implementations of different data types (i.e. float and double).
+#ifndef EIGEN_INVERSE_SIZE_4_H
+#define EIGEN_INVERSE_SIZE_4_H
+
+namespace Eigen
+{
+namespace internal
+{
+template <typename MatrixType, typename ResultType>
+struct compute_inverse_size4<Architecture::Target, float, MatrixType, ResultType>
+{
+ enum
+ {
+ MatrixAlignment = traits<MatrixType>::Alignment,
+ ResultAlignment = traits<ResultType>::Alignment,
+ StorageOrdersMatch = (MatrixType::Flags & RowMajorBit) == (ResultType::Flags & RowMajorBit)
+ };
+ typedef typename conditional<(MatrixType::Flags & LinearAccessBit), MatrixType const &, typename MatrixType::PlainObject>::type ActualMatrixType;
+
+ static void run(const MatrixType &mat, ResultType &result)
+ {
+ ActualMatrixType matrix(mat);
+
+ const float* data = matrix.data();
+ const Index stride = matrix.innerStride();
+ Packet4f _L1 = ploadt<Packet4f,MatrixAlignment>(data);
+ Packet4f _L2 = ploadt<Packet4f,MatrixAlignment>(data + stride*4);
+ Packet4f _L3 = ploadt<Packet4f,MatrixAlignment>(data + stride*8);
+ Packet4f _L4 = ploadt<Packet4f,MatrixAlignment>(data + stride*12);
+
+ // Four 2x2 sub-matrices of the input matrix
+ // input = [[A, B],
+ // [C, D]]
+ Packet4f A, B, C, D;
+
+ if (!StorageOrdersMatch)
+ {
+ A = vec4f_unpacklo(_L1, _L2);
+ B = vec4f_unpacklo(_L3, _L4);
+ C = vec4f_unpackhi(_L1, _L2);
+ D = vec4f_unpackhi(_L3, _L4);
+ }
+ else
+ {
+ A = vec4f_movelh(_L1, _L2);
+ B = vec4f_movehl(_L2, _L1);
+ C = vec4f_movelh(_L3, _L4);
+ D = vec4f_movehl(_L4, _L3);
+ }
+
+ Packet4f AB, DC;
+
+ // AB = A# * B, where A# denotes the adjugate of A, and * denotes matrix product.
+ AB = pmul(vec4f_swizzle2(A, A, 3, 3, 0, 0), B);
+ AB = psub(AB, pmul(vec4f_swizzle2(A, A, 1, 1, 2, 2), vec4f_swizzle2(B, B, 2, 3, 0, 1)));
+
+ // DC = D#*C
+ DC = pmul(vec4f_swizzle2(D, D, 3, 3, 0, 0), C);
+ DC = psub(DC, pmul(vec4f_swizzle2(D, D, 1, 1, 2, 2), vec4f_swizzle2(C, C, 2, 3, 0, 1)));
+
+ // determinants of the sub-matrices
+ Packet4f dA, dB, dC, dD;
+
+ dA = pmul(vec4f_swizzle2(A, A, 3, 3, 1, 1), A);
+ dA = psub(dA, vec4f_movehl(dA, dA));
+
+ dB = pmul(vec4f_swizzle2(B, B, 3, 3, 1, 1), B);
+ dB = psub(dB, vec4f_movehl(dB, dB));
+
+ dC = pmul(vec4f_swizzle2(C, C, 3, 3, 1, 1), C);
+ dC = psub(dC, vec4f_movehl(dC, dC));
+
+ dD = pmul(vec4f_swizzle2(D, D, 3, 3, 1, 1), D);
+ dD = psub(dD, vec4f_movehl(dD, dD));
+
+ Packet4f d, d1, d2;
+
+ d = pmul(vec4f_swizzle2(DC, DC, 0, 2, 1, 3), AB);
+ d = padd(d, vec4f_movehl(d, d));
+ d = padd(d, vec4f_swizzle2(d, d, 1, 0, 0, 0));
+ d1 = pmul(dA, dD);
+ d2 = pmul(dB, dC);
+
+ // determinant of the input matrix, det = |A||D| + |B||C| - trace(A#*B*D#*C)
+ Packet4f det = vec4f_duplane(psub(padd(d1, d2), d), 0);
+
+ // reciprocal of the determinant of the input matrix, rd = 1/det
+ Packet4f rd = pdiv(pset1<Packet4f>(1.0f), det);
+
+ // Four sub-matrices of the inverse
+ Packet4f iA, iB, iC, iD;
+
+ // iD = D*|A| - C*A#*B
+ iD = pmul(vec4f_swizzle2(C, C, 0, 0, 2, 2), vec4f_movelh(AB, AB));
+ iD = padd(iD, pmul(vec4f_swizzle2(C, C, 1, 1, 3, 3), vec4f_movehl(AB, AB)));
+ iD = psub(pmul(D, vec4f_duplane(dA, 0)), iD);
+
+ // iA = A*|D| - B*D#*C
+ iA = pmul(vec4f_swizzle2(B, B, 0, 0, 2, 2), vec4f_movelh(DC, DC));
+ iA = padd(iA, pmul(vec4f_swizzle2(B, B, 1, 1, 3, 3), vec4f_movehl(DC, DC)));
+ iA = psub(pmul(A, vec4f_duplane(dD, 0)), iA);
+
+ // iB = C*|B| - D * (A#B)# = C*|B| - D*B#*A
+ iB = pmul(D, vec4f_swizzle2(AB, AB, 3, 0, 3, 0));
+ iB = psub(iB, pmul(vec4f_swizzle2(D, D, 1, 0, 3, 2), vec4f_swizzle2(AB, AB, 2, 1, 2, 1)));
+ iB = psub(pmul(C, vec4f_duplane(dB, 0)), iB);
+
+ // iC = B*|C| - A * (D#C)# = B*|C| - A*C#*D
+ iC = pmul(A, vec4f_swizzle2(DC, DC, 3, 0, 3, 0));
+ iC = psub(iC, pmul(vec4f_swizzle2(A, A, 1, 0, 3, 2), vec4f_swizzle2(DC, DC, 2, 1, 2, 1)));
+ iC = psub(pmul(B, vec4f_duplane(dC, 0)), iC);
+
+ const float sign_mask[4] = {0.0f, numext::bit_cast<float>(0x80000000u), numext::bit_cast<float>(0x80000000u), 0.0f};
+ const Packet4f p4f_sign_PNNP = ploadu<Packet4f>(sign_mask);
+ rd = pxor(rd, p4f_sign_PNNP);
+ iA = pmul(iA, rd);
+ iB = pmul(iB, rd);
+ iC = pmul(iC, rd);
+ iD = pmul(iD, rd);
+
+ Index res_stride = result.outerStride();
+ float *res = result.data();
+
+ pstoret<float, Packet4f, ResultAlignment>(res + 0, vec4f_swizzle2(iA, iB, 3, 1, 3, 1));
+ pstoret<float, Packet4f, ResultAlignment>(res + res_stride, vec4f_swizzle2(iA, iB, 2, 0, 2, 0));
+ pstoret<float, Packet4f, ResultAlignment>(res + 2 * res_stride, vec4f_swizzle2(iC, iD, 3, 1, 3, 1));
+ pstoret<float, Packet4f, ResultAlignment>(res + 3 * res_stride, vec4f_swizzle2(iC, iD, 2, 0, 2, 0));
+ }
+};
+
+#if !(defined EIGEN_VECTORIZE_NEON && !(EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG))
+// same algorithm as above, except that each operand is split into
+// halves for two registers to hold.
+template <typename MatrixType, typename ResultType>
+struct compute_inverse_size4<Architecture::Target, double, MatrixType, ResultType>
+{
+ enum
+ {
+ MatrixAlignment = traits<MatrixType>::Alignment,
+ ResultAlignment = traits<ResultType>::Alignment,
+ StorageOrdersMatch = (MatrixType::Flags & RowMajorBit) == (ResultType::Flags & RowMajorBit)
+ };
+ typedef typename conditional<(MatrixType::Flags & LinearAccessBit),
+ MatrixType const &,
+ typename MatrixType::PlainObject>::type
+ ActualMatrixType;
+
+ static void run(const MatrixType &mat, ResultType &result)
+ {
+ ActualMatrixType matrix(mat);
+
+ // Four 2x2 sub-matrices of the input matrix, each is further divided into upper and lower
+ // row e.g. A1, upper row of A, A2, lower row of A
+ // input = [[A, B], = [[[A1, [B1,
+ // [C, D]] A2], B2]],
+ // [[C1, [D1,
+ // C2], D2]]]
+
+ Packet2d A1, A2, B1, B2, C1, C2, D1, D2;
+
+ const double* data = matrix.data();
+ const Index stride = matrix.innerStride();
+ if (StorageOrdersMatch)
+ {
+ A1 = ploadt<Packet2d,MatrixAlignment>(data + stride*0);
+ B1 = ploadt<Packet2d,MatrixAlignment>(data + stride*2);
+ A2 = ploadt<Packet2d,MatrixAlignment>(data + stride*4);
+ B2 = ploadt<Packet2d,MatrixAlignment>(data + stride*6);
+ C1 = ploadt<Packet2d,MatrixAlignment>(data + stride*8);
+ D1 = ploadt<Packet2d,MatrixAlignment>(data + stride*10);
+ C2 = ploadt<Packet2d,MatrixAlignment>(data + stride*12);
+ D2 = ploadt<Packet2d,MatrixAlignment>(data + stride*14);
+ }
+ else
+ {
+ Packet2d temp;
+ A1 = ploadt<Packet2d,MatrixAlignment>(data + stride*0);
+ C1 = ploadt<Packet2d,MatrixAlignment>(data + stride*2);
+ A2 = ploadt<Packet2d,MatrixAlignment>(data + stride*4);
+ C2 = ploadt<Packet2d,MatrixAlignment>(data + stride*6);
+ temp = A1;
+ A1 = vec2d_unpacklo(A1, A2);
+ A2 = vec2d_unpackhi(temp, A2);
+
+ temp = C1;
+ C1 = vec2d_unpacklo(C1, C2);
+ C2 = vec2d_unpackhi(temp, C2);
+
+ B1 = ploadt<Packet2d,MatrixAlignment>(data + stride*8);
+ D1 = ploadt<Packet2d,MatrixAlignment>(data + stride*10);
+ B2 = ploadt<Packet2d,MatrixAlignment>(data + stride*12);
+ D2 = ploadt<Packet2d,MatrixAlignment>(data + stride*14);
+
+ temp = B1;
+ B1 = vec2d_unpacklo(B1, B2);
+ B2 = vec2d_unpackhi(temp, B2);
+
+ temp = D1;
+ D1 = vec2d_unpacklo(D1, D2);
+ D2 = vec2d_unpackhi(temp, D2);
+ }
+
+ // determinants of the sub-matrices
+ Packet2d dA, dB, dC, dD;
+
+ dA = vec2d_swizzle2(A2, A2, 1);
+ dA = pmul(A1, dA);
+ dA = psub(dA, vec2d_duplane(dA, 1));
+
+ dB = vec2d_swizzle2(B2, B2, 1);
+ dB = pmul(B1, dB);
+ dB = psub(dB, vec2d_duplane(dB, 1));
+
+ dC = vec2d_swizzle2(C2, C2, 1);
+ dC = pmul(C1, dC);
+ dC = psub(dC, vec2d_duplane(dC, 1));
+
+ dD = vec2d_swizzle2(D2, D2, 1);
+ dD = pmul(D1, dD);
+ dD = psub(dD, vec2d_duplane(dD, 1));
+
+ Packet2d DC1, DC2, AB1, AB2;
+
+ // AB = A# * B, where A# denotes the adjugate of A, and * denotes matrix product.
+ AB1 = pmul(B1, vec2d_duplane(A2, 1));
+ AB2 = pmul(B2, vec2d_duplane(A1, 0));
+ AB1 = psub(AB1, pmul(B2, vec2d_duplane(A1, 1)));
+ AB2 = psub(AB2, pmul(B1, vec2d_duplane(A2, 0)));
+
+ // DC = D#*C
+ DC1 = pmul(C1, vec2d_duplane(D2, 1));
+ DC2 = pmul(C2, vec2d_duplane(D1, 0));
+ DC1 = psub(DC1, pmul(C2, vec2d_duplane(D1, 1)));
+ DC2 = psub(DC2, pmul(C1, vec2d_duplane(D2, 0)));
+
+ Packet2d d1, d2;
+
+ // determinant of the input matrix, det = |A||D| + |B||C| - trace(A#*B*D#*C)
+ Packet2d det;
+
+ // reciprocal of the determinant of the input matrix, rd = 1/det
+ Packet2d rd;
+
+ d1 = pmul(AB1, vec2d_swizzle2(DC1, DC2, 0));
+ d2 = pmul(AB2, vec2d_swizzle2(DC1, DC2, 3));
+ rd = padd(d1, d2);
+ rd = padd(rd, vec2d_duplane(rd, 1));
+
+ d1 = pmul(dA, dD);
+ d2 = pmul(dB, dC);
+
+ det = padd(d1, d2);
+ det = psub(det, rd);
+ det = vec2d_duplane(det, 0);
+ rd = pdiv(pset1<Packet2d>(1.0), det);
+
+ // rows of four sub-matrices of the inverse
+ Packet2d iA1, iA2, iB1, iB2, iC1, iC2, iD1, iD2;
+
+ // iD = D*|A| - C*A#*B
+ iD1 = pmul(AB1, vec2d_duplane(C1, 0));
+ iD2 = pmul(AB1, vec2d_duplane(C2, 0));
+ iD1 = padd(iD1, pmul(AB2, vec2d_duplane(C1, 1)));
+ iD2 = padd(iD2, pmul(AB2, vec2d_duplane(C2, 1)));
+ dA = vec2d_duplane(dA, 0);
+ iD1 = psub(pmul(D1, dA), iD1);
+ iD2 = psub(pmul(D2, dA), iD2);
+
+ // iA = A*|D| - B*D#*C
+ iA1 = pmul(DC1, vec2d_duplane(B1, 0));
+ iA2 = pmul(DC1, vec2d_duplane(B2, 0));
+ iA1 = padd(iA1, pmul(DC2, vec2d_duplane(B1, 1)));
+ iA2 = padd(iA2, pmul(DC2, vec2d_duplane(B2, 1)));
+ dD = vec2d_duplane(dD, 0);
+ iA1 = psub(pmul(A1, dD), iA1);
+ iA2 = psub(pmul(A2, dD), iA2);
+
+ // iB = C*|B| - D * (A#B)# = C*|B| - D*B#*A
+ iB1 = pmul(D1, vec2d_swizzle2(AB2, AB1, 1));
+ iB2 = pmul(D2, vec2d_swizzle2(AB2, AB1, 1));
+ iB1 = psub(iB1, pmul(vec2d_swizzle2(D1, D1, 1), vec2d_swizzle2(AB2, AB1, 2)));
+ iB2 = psub(iB2, pmul(vec2d_swizzle2(D2, D2, 1), vec2d_swizzle2(AB2, AB1, 2)));
+ dB = vec2d_duplane(dB, 0);
+ iB1 = psub(pmul(C1, dB), iB1);
+ iB2 = psub(pmul(C2, dB), iB2);
+
+ // iC = B*|C| - A * (D#C)# = B*|C| - A*C#*D
+ iC1 = pmul(A1, vec2d_swizzle2(DC2, DC1, 1));
+ iC2 = pmul(A2, vec2d_swizzle2(DC2, DC1, 1));
+ iC1 = psub(iC1, pmul(vec2d_swizzle2(A1, A1, 1), vec2d_swizzle2(DC2, DC1, 2)));
+ iC2 = psub(iC2, pmul(vec2d_swizzle2(A2, A2, 1), vec2d_swizzle2(DC2, DC1, 2)));
+ dC = vec2d_duplane(dC, 0);
+ iC1 = psub(pmul(B1, dC), iC1);
+ iC2 = psub(pmul(B2, dC), iC2);
+
+ const double sign_mask1[2] = {0.0, numext::bit_cast<double>(0x8000000000000000ull)};
+ const double sign_mask2[2] = {numext::bit_cast<double>(0x8000000000000000ull), 0.0};
+ const Packet2d sign_PN = ploadu<Packet2d>(sign_mask1);
+ const Packet2d sign_NP = ploadu<Packet2d>(sign_mask2);
+ d1 = pxor(rd, sign_PN);
+ d2 = pxor(rd, sign_NP);
+
+ Index res_stride = result.outerStride();
+ double *res = result.data();
+ pstoret<double, Packet2d, ResultAlignment>(res + 0, pmul(vec2d_swizzle2(iA2, iA1, 3), d1));
+ pstoret<double, Packet2d, ResultAlignment>(res + res_stride, pmul(vec2d_swizzle2(iA2, iA1, 0), d2));
+ pstoret<double, Packet2d, ResultAlignment>(res + 2, pmul(vec2d_swizzle2(iB2, iB1, 3), d1));
+ pstoret<double, Packet2d, ResultAlignment>(res + res_stride + 2, pmul(vec2d_swizzle2(iB2, iB1, 0), d2));
+ pstoret<double, Packet2d, ResultAlignment>(res + 2 * res_stride, pmul(vec2d_swizzle2(iC2, iC1, 3), d1));
+ pstoret<double, Packet2d, ResultAlignment>(res + 3 * res_stride, pmul(vec2d_swizzle2(iC2, iC1, 0), d2));
+ pstoret<double, Packet2d, ResultAlignment>(res + 2 * res_stride + 2, pmul(vec2d_swizzle2(iD2, iD1, 3), d1));
+ pstoret<double, Packet2d, ResultAlignment>(res + 3 * res_stride + 2, pmul(vec2d_swizzle2(iD2, iD1, 0), d2));
+ }
+};
+#endif
+} // namespace internal
+} // namespace Eigen
+#endif
diff --git a/src/3rdparty/eigen/Eigen/src/QR/ColPivHouseholderQR.h b/src/3rdparty/eigen/Eigen/src/QR/ColPivHouseholderQR.h
new file mode 100644
index 000000000..9b677e9bf
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/QR/ColPivHouseholderQR.h
@@ -0,0 +1,674 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COLPIVOTINGHOUSEHOLDERQR_H
+#define EIGEN_COLPIVOTINGHOUSEHOLDERQR_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename _MatrixType> struct traits<ColPivHouseholderQR<_MatrixType> >
+ : traits<_MatrixType>
+{
+ typedef MatrixXpr XprKind;
+ typedef SolverStorage StorageKind;
+ typedef int StorageIndex;
+ enum { Flags = 0 };
+};
+
+} // end namespace internal
+
+/** \ingroup QR_Module
+ *
+ * \class ColPivHouseholderQR
+ *
+ * \brief Householder rank-revealing QR decomposition of a matrix with column-pivoting
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the QR decomposition
+ *
+ * This class performs a rank-revealing QR decomposition of a matrix \b A into matrices \b P, \b Q and \b R
+ * such that
+ * \f[
+ * \mathbf{A} \, \mathbf{P} = \mathbf{Q} \, \mathbf{R}
+ * \f]
+ * by using Householder transformations. Here, \b P is a permutation matrix, \b Q a unitary matrix and \b R an
+ * upper triangular matrix.
+ *
+ * This decomposition performs column pivoting in order to be rank-revealing and improve
+ * numerical stability. It is slower than HouseholderQR, and faster than FullPivHouseholderQR.
+ *
+ * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism.
+ *
+ * \sa MatrixBase::colPivHouseholderQr()
+ */
+template<typename _MatrixType> class ColPivHouseholderQR
+ : public SolverBase<ColPivHouseholderQR<_MatrixType> >
+{
+ public:
+
+ typedef _MatrixType MatrixType;
+ typedef SolverBase<ColPivHouseholderQR> Base;
+ friend class SolverBase<ColPivHouseholderQR>;
+
+ EIGEN_GENERIC_PUBLIC_INTERFACE(ColPivHouseholderQR)
+ enum {
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+ typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType;
+ typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime> PermutationType;
+ typedef typename internal::plain_row_type<MatrixType, Index>::type IntRowVectorType;
+ typedef typename internal::plain_row_type<MatrixType>::type RowVectorType;
+ typedef typename internal::plain_row_type<MatrixType, RealScalar>::type RealRowVectorType;
+ typedef HouseholderSequence<MatrixType,typename internal::remove_all<typename HCoeffsType::ConjugateReturnType>::type> HouseholderSequenceType;
+ typedef typename MatrixType::PlainObject PlainObject;
+
+ private:
+
+ typedef typename PermutationType::StorageIndex PermIndexType;
+
+ public:
+
+ /**
+ * \brief Default Constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via ColPivHouseholderQR::compute(const MatrixType&).
+ */
+ ColPivHouseholderQR()
+ : m_qr(),
+ m_hCoeffs(),
+ m_colsPermutation(),
+ m_colsTranspositions(),
+ m_temp(),
+ m_colNormsUpdated(),
+ m_colNormsDirect(),
+ m_isInitialized(false),
+ m_usePrescribedThreshold(false) {}
+
+ /** \brief Default Constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem \a size.
+ * \sa ColPivHouseholderQR()
+ */
+ ColPivHouseholderQR(Index rows, Index cols)
+ : m_qr(rows, cols),
+ m_hCoeffs((std::min)(rows,cols)),
+ m_colsPermutation(PermIndexType(cols)),
+ m_colsTranspositions(cols),
+ m_temp(cols),
+ m_colNormsUpdated(cols),
+ m_colNormsDirect(cols),
+ m_isInitialized(false),
+ m_usePrescribedThreshold(false) {}
+
+ /** \brief Constructs a QR factorization from a given matrix
+ *
+ * This constructor computes the QR factorization of the matrix \a matrix by calling
+ * the method compute(). It is a short cut for:
+ *
+ * \code
+ * ColPivHouseholderQR<MatrixType> qr(matrix.rows(), matrix.cols());
+ * qr.compute(matrix);
+ * \endcode
+ *
+ * \sa compute()
+ */
+ template<typename InputType>
+ explicit ColPivHouseholderQR(const EigenBase<InputType>& matrix)
+ : m_qr(matrix.rows(), matrix.cols()),
+ m_hCoeffs((std::min)(matrix.rows(),matrix.cols())),
+ m_colsPermutation(PermIndexType(matrix.cols())),
+ m_colsTranspositions(matrix.cols()),
+ m_temp(matrix.cols()),
+ m_colNormsUpdated(matrix.cols()),
+ m_colNormsDirect(matrix.cols()),
+ m_isInitialized(false),
+ m_usePrescribedThreshold(false)
+ {
+ compute(matrix.derived());
+ }
+
+ /** \brief Constructs a QR factorization from a given matrix
+ *
+ * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c MatrixType is a Eigen::Ref.
+ *
+ * \sa ColPivHouseholderQR(const EigenBase&)
+ */
+ template<typename InputType>
+ explicit ColPivHouseholderQR(EigenBase<InputType>& matrix)
+ : m_qr(matrix.derived()),
+ m_hCoeffs((std::min)(matrix.rows(),matrix.cols())),
+ m_colsPermutation(PermIndexType(matrix.cols())),
+ m_colsTranspositions(matrix.cols()),
+ m_temp(matrix.cols()),
+ m_colNormsUpdated(matrix.cols()),
+ m_colNormsDirect(matrix.cols()),
+ m_isInitialized(false),
+ m_usePrescribedThreshold(false)
+ {
+ computeInPlace();
+ }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** This method finds a solution x to the equation Ax=b, where A is the matrix of which
+ * *this is the QR decomposition, if any exists.
+ *
+ * \param b the right-hand-side of the equation to solve.
+ *
+ * \returns a solution.
+ *
+ * \note_about_checking_solutions
+ *
+ * \note_about_arbitrary_choice_of_solution
+ *
+ * Example: \include ColPivHouseholderQR_solve.cpp
+ * Output: \verbinclude ColPivHouseholderQR_solve.out
+ */
+ template<typename Rhs>
+ inline const Solve<ColPivHouseholderQR, Rhs>
+ solve(const MatrixBase<Rhs>& b) const;
+ #endif
+
+ HouseholderSequenceType householderQ() const;
+ HouseholderSequenceType matrixQ() const
+ {
+ return householderQ();
+ }
+
+ /** \returns a reference to the matrix where the Householder QR decomposition is stored
+ */
+ const MatrixType& matrixQR() const
+ {
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ return m_qr;
+ }
+
+ /** \returns a reference to the matrix where the result Householder QR is stored
+ * \warning The strict lower part of this matrix contains internal values.
+ * Only the upper triangular part should be referenced. To get it, use
+ * \code matrixR().template triangularView<Upper>() \endcode
+ * For rank-deficient matrices, use
+ * \code
+ * matrixR().topLeftCorner(rank(), rank()).template triangularView<Upper>()
+ * \endcode
+ */
+ const MatrixType& matrixR() const
+ {
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ return m_qr;
+ }
+
+ template<typename InputType>
+ ColPivHouseholderQR& compute(const EigenBase<InputType>& matrix);
+
+ /** \returns a const reference to the column permutation matrix */
+ const PermutationType& colsPermutation() const
+ {
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ return m_colsPermutation;
+ }
+
+ /** \returns the absolute value of the determinant of the matrix of which
+ * *this is the QR decomposition. It has only linear complexity
+ * (that is, O(n) where n is the dimension of the square matrix)
+ * as the QR decomposition has already been computed.
+ *
+ * \note This is only for square matrices.
+ *
+ * \warning a determinant can be very big or small, so for matrices
+ * of large enough dimension, there is a risk of overflow/underflow.
+ * One way to work around that is to use logAbsDeterminant() instead.
+ *
+ * \sa logAbsDeterminant(), MatrixBase::determinant()
+ */
+ typename MatrixType::RealScalar absDeterminant() const;
+
+ /** \returns the natural log of the absolute value of the determinant of the matrix of which
+ * *this is the QR decomposition. It has only linear complexity
+ * (that is, O(n) where n is the dimension of the square matrix)
+ * as the QR decomposition has already been computed.
+ *
+ * \note This is only for square matrices.
+ *
+ * \note This method is useful to work around the risk of overflow/underflow that's inherent
+ * to determinant computation.
+ *
+ * \sa absDeterminant(), MatrixBase::determinant()
+ */
+ typename MatrixType::RealScalar logAbsDeterminant() const;
+
+ /** \returns the rank of the matrix of which *this is the QR decomposition.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline Index rank() const
+ {
+ using std::abs;
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold();
+ Index result = 0;
+ for(Index i = 0; i < m_nonzero_pivots; ++i)
+ result += (abs(m_qr.coeff(i,i)) > premultiplied_threshold);
+ return result;
+ }
+
+ /** \returns the dimension of the kernel of the matrix of which *this is the QR decomposition.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline Index dimensionOfKernel() const
+ {
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ return cols() - rank();
+ }
+
+ /** \returns true if the matrix of which *this is the QR decomposition represents an injective
+ * linear map, i.e. has trivial kernel; false otherwise.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline bool isInjective() const
+ {
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ return rank() == cols();
+ }
+
+ /** \returns true if the matrix of which *this is the QR decomposition represents a surjective
+ * linear map; false otherwise.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline bool isSurjective() const
+ {
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ return rank() == rows();
+ }
+
+ /** \returns true if the matrix of which *this is the QR decomposition is invertible.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline bool isInvertible() const
+ {
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ return isInjective() && isSurjective();
+ }
+
+ /** \returns the inverse of the matrix of which *this is the QR decomposition.
+ *
+ * \note If this matrix is not invertible, the returned matrix has undefined coefficients.
+ * Use isInvertible() to first determine whether this matrix is invertible.
+ */
+ inline const Inverse<ColPivHouseholderQR> inverse() const
+ {
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ return Inverse<ColPivHouseholderQR>(*this);
+ }
+
+ inline Index rows() const { return m_qr.rows(); }
+ inline Index cols() const { return m_qr.cols(); }
+
+ /** \returns a const reference to the vector of Householder coefficients used to represent the factor \c Q.
+ *
+ * For advanced uses only.
+ */
+ const HCoeffsType& hCoeffs() const { return m_hCoeffs; }
+
+ /** Allows to prescribe a threshold to be used by certain methods, such as rank(),
+ * who need to determine when pivots are to be considered nonzero. This is not used for the
+ * QR decomposition itself.
+ *
+ * When it needs to get the threshold value, Eigen calls threshold(). By default, this
+ * uses a formula to automatically determine a reasonable threshold.
+ * Once you have called the present method setThreshold(const RealScalar&),
+ * your value is used instead.
+ *
+ * \param threshold The new value to use as the threshold.
+ *
+ * A pivot will be considered nonzero if its absolute value is strictly greater than
+ * \f$ \vert pivot \vert \leqslant threshold \times \vert maxpivot \vert \f$
+ * where maxpivot is the biggest pivot.
+ *
+ * If you want to come back to the default behavior, call setThreshold(Default_t)
+ */
+ ColPivHouseholderQR& setThreshold(const RealScalar& threshold)
+ {
+ m_usePrescribedThreshold = true;
+ m_prescribedThreshold = threshold;
+ return *this;
+ }
+
+ /** Allows to come back to the default behavior, letting Eigen use its default formula for
+ * determining the threshold.
+ *
+ * You should pass the special object Eigen::Default as parameter here.
+ * \code qr.setThreshold(Eigen::Default); \endcode
+ *
+ * See the documentation of setThreshold(const RealScalar&).
+ */
+ ColPivHouseholderQR& setThreshold(Default_t)
+ {
+ m_usePrescribedThreshold = false;
+ return *this;
+ }
+
+ /** Returns the threshold that will be used by certain methods such as rank().
+ *
+ * See the documentation of setThreshold(const RealScalar&).
+ */
+ RealScalar threshold() const
+ {
+ eigen_assert(m_isInitialized || m_usePrescribedThreshold);
+ return m_usePrescribedThreshold ? m_prescribedThreshold
+ // this formula comes from experimenting (see "LU precision tuning" thread on the list)
+ // and turns out to be identical to Higham's formula used already in LDLt.
+ : NumTraits<Scalar>::epsilon() * RealScalar(m_qr.diagonalSize());
+ }
+
+ /** \returns the number of nonzero pivots in the QR decomposition.
+ * Here nonzero is meant in the exact sense, not in a fuzzy sense.
+ * So that notion isn't really intrinsically interesting, but it is
+ * still useful when implementing algorithms.
+ *
+ * \sa rank()
+ */
+ inline Index nonzeroPivots() const
+ {
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ return m_nonzero_pivots;
+ }
+
+ /** \returns the absolute value of the biggest pivot, i.e. the biggest
+ * diagonal coefficient of R.
+ */
+ RealScalar maxPivot() const { return m_maxpivot; }
+
+ /** \brief Reports whether the QR factorization was successful.
+ *
+ * \note This function always returns \c Success. It is provided for compatibility
+ * with other factorization routines.
+ * \returns \c Success
+ */
+ ComputationInfo info() const
+ {
+ eigen_assert(m_isInitialized && "Decomposition is not initialized.");
+ return Success;
+ }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename RhsType, typename DstType>
+ void _solve_impl(const RhsType &rhs, DstType &dst) const;
+
+ template<bool Conjugate, typename RhsType, typename DstType>
+ void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const;
+ #endif
+
+ protected:
+
+ friend class CompleteOrthogonalDecomposition<MatrixType>;
+
+ static void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ }
+
+ void computeInPlace();
+
+ MatrixType m_qr;
+ HCoeffsType m_hCoeffs;
+ PermutationType m_colsPermutation;
+ IntRowVectorType m_colsTranspositions;
+ RowVectorType m_temp;
+ RealRowVectorType m_colNormsUpdated;
+ RealRowVectorType m_colNormsDirect;
+ bool m_isInitialized, m_usePrescribedThreshold;
+ RealScalar m_prescribedThreshold, m_maxpivot;
+ Index m_nonzero_pivots;
+ Index m_det_pq;
+};
+
+template<typename MatrixType>
+typename MatrixType::RealScalar ColPivHouseholderQR<MatrixType>::absDeterminant() const
+{
+ using std::abs;
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!");
+ return abs(m_qr.diagonal().prod());
+}
+
+template<typename MatrixType>
+typename MatrixType::RealScalar ColPivHouseholderQR<MatrixType>::logAbsDeterminant() const
+{
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!");
+ return m_qr.diagonal().cwiseAbs().array().log().sum();
+}
+
+/** Performs the QR factorization of the given matrix \a matrix. The result of
+ * the factorization is stored into \c *this, and a reference to \c *this
+ * is returned.
+ *
+ * \sa class ColPivHouseholderQR, ColPivHouseholderQR(const MatrixType&)
+ */
+template<typename MatrixType>
+template<typename InputType>
+ColPivHouseholderQR<MatrixType>& ColPivHouseholderQR<MatrixType>::compute(const EigenBase<InputType>& matrix)
+{
+ m_qr = matrix.derived();
+ computeInPlace();
+ return *this;
+}
+
+template<typename MatrixType>
+void ColPivHouseholderQR<MatrixType>::computeInPlace()
+{
+ check_template_parameters();
+
+ // the column permutation is stored as int indices, so just to be sure:
+ eigen_assert(m_qr.cols()<=NumTraits<int>::highest());
+
+ using std::abs;
+
+ Index rows = m_qr.rows();
+ Index cols = m_qr.cols();
+ Index size = m_qr.diagonalSize();
+
+ m_hCoeffs.resize(size);
+
+ m_temp.resize(cols);
+
+ m_colsTranspositions.resize(m_qr.cols());
+ Index number_of_transpositions = 0;
+
+ m_colNormsUpdated.resize(cols);
+ m_colNormsDirect.resize(cols);
+ for (Index k = 0; k < cols; ++k) {
+ // colNormsDirect(k) caches the most recent directly computed norm of
+ // column k.
+ m_colNormsDirect.coeffRef(k) = m_qr.col(k).norm();
+ m_colNormsUpdated.coeffRef(k) = m_colNormsDirect.coeffRef(k);
+ }
+
+ RealScalar threshold_helper = numext::abs2<RealScalar>(m_colNormsUpdated.maxCoeff() * NumTraits<RealScalar>::epsilon()) / RealScalar(rows);
+ RealScalar norm_downdate_threshold = numext::sqrt(NumTraits<RealScalar>::epsilon());
+
+ m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case)
+ m_maxpivot = RealScalar(0);
+
+ for(Index k = 0; k < size; ++k)
+ {
+ // first, we look up in our table m_colNormsUpdated which column has the biggest norm
+ Index biggest_col_index;
+ RealScalar biggest_col_sq_norm = numext::abs2(m_colNormsUpdated.tail(cols-k).maxCoeff(&biggest_col_index));
+ biggest_col_index += k;
+
+ // Track the number of meaningful pivots but do not stop the decomposition to make
+ // sure that the initial matrix is properly reproduced. See bug 941.
+ if(m_nonzero_pivots==size && biggest_col_sq_norm < threshold_helper * RealScalar(rows-k))
+ m_nonzero_pivots = k;
+
+ // apply the transposition to the columns
+ m_colsTranspositions.coeffRef(k) = biggest_col_index;
+ if(k != biggest_col_index) {
+ m_qr.col(k).swap(m_qr.col(biggest_col_index));
+ std::swap(m_colNormsUpdated.coeffRef(k), m_colNormsUpdated.coeffRef(biggest_col_index));
+ std::swap(m_colNormsDirect.coeffRef(k), m_colNormsDirect.coeffRef(biggest_col_index));
+ ++number_of_transpositions;
+ }
+
+ // generate the householder vector, store it below the diagonal
+ RealScalar beta;
+ m_qr.col(k).tail(rows-k).makeHouseholderInPlace(m_hCoeffs.coeffRef(k), beta);
+
+ // apply the householder transformation to the diagonal coefficient
+ m_qr.coeffRef(k,k) = beta;
+
+ // remember the maximum absolute value of diagonal coefficients
+ if(abs(beta) > m_maxpivot) m_maxpivot = abs(beta);
+
+ // apply the householder transformation
+ m_qr.bottomRightCorner(rows-k, cols-k-1)
+ .applyHouseholderOnTheLeft(m_qr.col(k).tail(rows-k-1), m_hCoeffs.coeffRef(k), &m_temp.coeffRef(k+1));
+
+ // update our table of norms of the columns
+ for (Index j = k + 1; j < cols; ++j) {
+ // The following implements the stable norm downgrade step discussed in
+ // http://www.netlib.org/lapack/lawnspdf/lawn176.pdf
+ // and used in LAPACK routines xGEQPF and xGEQP3.
+ // See lines 278-297 in http://www.netlib.org/lapack/explore-html/dc/df4/sgeqpf_8f_source.html
+ if (m_colNormsUpdated.coeffRef(j) != RealScalar(0)) {
+ RealScalar temp = abs(m_qr.coeffRef(k, j)) / m_colNormsUpdated.coeffRef(j);
+ temp = (RealScalar(1) + temp) * (RealScalar(1) - temp);
+ temp = temp < RealScalar(0) ? RealScalar(0) : temp;
+ RealScalar temp2 = temp * numext::abs2<RealScalar>(m_colNormsUpdated.coeffRef(j) /
+ m_colNormsDirect.coeffRef(j));
+ if (temp2 <= norm_downdate_threshold) {
+ // The updated norm has become too inaccurate so re-compute the column
+ // norm directly.
+ m_colNormsDirect.coeffRef(j) = m_qr.col(j).tail(rows - k - 1).norm();
+ m_colNormsUpdated.coeffRef(j) = m_colNormsDirect.coeffRef(j);
+ } else {
+ m_colNormsUpdated.coeffRef(j) *= numext::sqrt(temp);
+ }
+ }
+ }
+ }
+
+ m_colsPermutation.setIdentity(PermIndexType(cols));
+ for(PermIndexType k = 0; k < size/*m_nonzero_pivots*/; ++k)
+ m_colsPermutation.applyTranspositionOnTheRight(k, PermIndexType(m_colsTranspositions.coeff(k)));
+
+ m_det_pq = (number_of_transpositions%2) ? -1 : 1;
+ m_isInitialized = true;
+}
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+template<typename _MatrixType>
+template<typename RhsType, typename DstType>
+void ColPivHouseholderQR<_MatrixType>::_solve_impl(const RhsType &rhs, DstType &dst) const
+{
+ const Index nonzero_pivots = nonzeroPivots();
+
+ if(nonzero_pivots == 0)
+ {
+ dst.setZero();
+ return;
+ }
+
+ typename RhsType::PlainObject c(rhs);
+
+ c.applyOnTheLeft(householderQ().setLength(nonzero_pivots).adjoint() );
+
+ m_qr.topLeftCorner(nonzero_pivots, nonzero_pivots)
+ .template triangularView<Upper>()
+ .solveInPlace(c.topRows(nonzero_pivots));
+
+ for(Index i = 0; i < nonzero_pivots; ++i) dst.row(m_colsPermutation.indices().coeff(i)) = c.row(i);
+ for(Index i = nonzero_pivots; i < cols(); ++i) dst.row(m_colsPermutation.indices().coeff(i)).setZero();
+}
+
+template<typename _MatrixType>
+template<bool Conjugate, typename RhsType, typename DstType>
+void ColPivHouseholderQR<_MatrixType>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const
+{
+ const Index nonzero_pivots = nonzeroPivots();
+
+ if(nonzero_pivots == 0)
+ {
+ dst.setZero();
+ return;
+ }
+
+ typename RhsType::PlainObject c(m_colsPermutation.transpose()*rhs);
+
+ m_qr.topLeftCorner(nonzero_pivots, nonzero_pivots)
+ .template triangularView<Upper>()
+ .transpose().template conjugateIf<Conjugate>()
+ .solveInPlace(c.topRows(nonzero_pivots));
+
+ dst.topRows(nonzero_pivots) = c.topRows(nonzero_pivots);
+ dst.bottomRows(rows()-nonzero_pivots).setZero();
+
+ dst.applyOnTheLeft(householderQ().setLength(nonzero_pivots).template conjugateIf<!Conjugate>() );
+}
+#endif
+
+namespace internal {
+
+template<typename DstXprType, typename MatrixType>
+struct Assignment<DstXprType, Inverse<ColPivHouseholderQR<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename ColPivHouseholderQR<MatrixType>::Scalar>, Dense2Dense>
+{
+ typedef ColPivHouseholderQR<MatrixType> QrType;
+ typedef Inverse<QrType> SrcXprType;
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename QrType::Scalar> &)
+ {
+ dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols()));
+ }
+};
+
+} // end namespace internal
+
+/** \returns the matrix Q as a sequence of householder transformations.
+ * You can extract the meaningful part only by using:
+ * \code qr.householderQ().setLength(qr.nonzeroPivots()) \endcode*/
+template<typename MatrixType>
+typename ColPivHouseholderQR<MatrixType>::HouseholderSequenceType ColPivHouseholderQR<MatrixType>
+ ::householderQ() const
+{
+ eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
+ return HouseholderSequenceType(m_qr, m_hCoeffs.conjugate());
+}
+
+/** \return the column-pivoting Householder QR decomposition of \c *this.
+ *
+ * \sa class ColPivHouseholderQR
+ */
+template<typename Derived>
+const ColPivHouseholderQR<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::colPivHouseholderQr() const
+{
+ return ColPivHouseholderQR<PlainObject>(eval());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_COLPIVOTINGHOUSEHOLDERQR_H
diff --git a/src/3rdparty/eigen/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h b/src/3rdparty/eigen/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h
new file mode 100644
index 000000000..4e9651f83
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h
@@ -0,0 +1,97 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to LAPACKe
+ * Householder QR decomposition of a matrix with column pivoting based on
+ * LAPACKE_?geqp3 function.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_COLPIVOTINGHOUSEHOLDERQR_LAPACKE_H
+#define EIGEN_COLPIVOTINGHOUSEHOLDERQR_LAPACKE_H
+
+namespace Eigen {
+
+/** \internal Specialization for the data types supported by LAPACKe */
+
+#define EIGEN_LAPACKE_QR_COLPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX, EIGCOLROW, LAPACKE_COLROW) \
+template<> template<typename InputType> inline \
+ColPivHouseholderQR<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> >& \
+ColPivHouseholderQR<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> >::compute( \
+ const EigenBase<InputType>& matrix) \
+\
+{ \
+ using std::abs; \
+ typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \
+ typedef MatrixType::RealScalar RealScalar; \
+ Index rows = matrix.rows();\
+ Index cols = matrix.cols();\
+\
+ m_qr = matrix;\
+ Index size = m_qr.diagonalSize();\
+ m_hCoeffs.resize(size);\
+\
+ m_colsTranspositions.resize(cols);\
+ /*Index number_of_transpositions = 0;*/ \
+\
+ m_nonzero_pivots = 0; \
+ m_maxpivot = RealScalar(0);\
+ m_colsPermutation.resize(cols); \
+ m_colsPermutation.indices().setZero(); \
+\
+ lapack_int lda = internal::convert_index<lapack_int,Index>(m_qr.outerStride()); \
+ lapack_int matrix_order = LAPACKE_COLROW; \
+ LAPACKE_##LAPACKE_PREFIX##geqp3( matrix_order, internal::convert_index<lapack_int,Index>(rows), internal::convert_index<lapack_int,Index>(cols), \
+ (LAPACKE_TYPE*)m_qr.data(), lda, (lapack_int*)m_colsPermutation.indices().data(), (LAPACKE_TYPE*)m_hCoeffs.data()); \
+ m_isInitialized = true; \
+ m_maxpivot=m_qr.diagonal().cwiseAbs().maxCoeff(); \
+ m_hCoeffs.adjointInPlace(); \
+ RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold(); \
+ lapack_int *perm = m_colsPermutation.indices().data(); \
+ for(Index i=0;i<size;i++) { \
+ m_nonzero_pivots += (abs(m_qr.coeff(i,i)) > premultiplied_threshold);\
+ } \
+ for(Index i=0;i<cols;i++) perm[i]--;\
+\
+ /*m_det_pq = (number_of_transpositions%2) ? -1 : 1; // TODO: It's not needed now; fix upon availability in Eigen */ \
+\
+ return *this; \
+}
+
+EIGEN_LAPACKE_QR_COLPIV(double, double, d, ColMajor, LAPACK_COL_MAJOR)
+EIGEN_LAPACKE_QR_COLPIV(float, float, s, ColMajor, LAPACK_COL_MAJOR)
+EIGEN_LAPACKE_QR_COLPIV(dcomplex, lapack_complex_double, z, ColMajor, LAPACK_COL_MAJOR)
+EIGEN_LAPACKE_QR_COLPIV(scomplex, lapack_complex_float, c, ColMajor, LAPACK_COL_MAJOR)
+
+EIGEN_LAPACKE_QR_COLPIV(double, double, d, RowMajor, LAPACK_ROW_MAJOR)
+EIGEN_LAPACKE_QR_COLPIV(float, float, s, RowMajor, LAPACK_ROW_MAJOR)
+EIGEN_LAPACKE_QR_COLPIV(dcomplex, lapack_complex_double, z, RowMajor, LAPACK_ROW_MAJOR)
+EIGEN_LAPACKE_QR_COLPIV(scomplex, lapack_complex_float, c, RowMajor, LAPACK_ROW_MAJOR)
+
+} // end namespace Eigen
+
+#endif // EIGEN_COLPIVOTINGHOUSEHOLDERQR_LAPACKE_H
diff --git a/src/3rdparty/eigen/Eigen/src/QR/CompleteOrthogonalDecomposition.h b/src/3rdparty/eigen/Eigen/src/QR/CompleteOrthogonalDecomposition.h
new file mode 100644
index 000000000..486d3373a
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/QR/CompleteOrthogonalDecomposition.h
@@ -0,0 +1,635 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2016 Rasmus Munk Larsen <rmlarsen@google.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H
+#define EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H
+
+namespace Eigen {
+
+namespace internal {
+template <typename _MatrixType>
+struct traits<CompleteOrthogonalDecomposition<_MatrixType> >
+ : traits<_MatrixType> {
+ typedef MatrixXpr XprKind;
+ typedef SolverStorage StorageKind;
+ typedef int StorageIndex;
+ enum { Flags = 0 };
+};
+
+} // end namespace internal
+
+/** \ingroup QR_Module
+ *
+ * \class CompleteOrthogonalDecomposition
+ *
+ * \brief Complete orthogonal decomposition (COD) of a matrix.
+ *
+ * \param MatrixType the type of the matrix of which we are computing the COD.
+ *
+ * This class performs a rank-revealing complete orthogonal decomposition of a
+ * matrix \b A into matrices \b P, \b Q, \b T, and \b Z such that
+ * \f[
+ * \mathbf{A} \, \mathbf{P} = \mathbf{Q} \,
+ * \begin{bmatrix} \mathbf{T} & \mathbf{0} \\
+ * \mathbf{0} & \mathbf{0} \end{bmatrix} \, \mathbf{Z}
+ * \f]
+ * by using Householder transformations. Here, \b P is a permutation matrix,
+ * \b Q and \b Z are unitary matrices and \b T an upper triangular matrix of
+ * size rank-by-rank. \b A may be rank deficient.
+ *
+ * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism.
+ *
+ * \sa MatrixBase::completeOrthogonalDecomposition()
+ */
+template <typename _MatrixType> class CompleteOrthogonalDecomposition
+ : public SolverBase<CompleteOrthogonalDecomposition<_MatrixType> >
+{
+ public:
+ typedef _MatrixType MatrixType;
+ typedef SolverBase<CompleteOrthogonalDecomposition> Base;
+
+ template<typename Derived>
+ friend struct internal::solve_assertion;
+
+ EIGEN_GENERIC_PUBLIC_INTERFACE(CompleteOrthogonalDecomposition)
+ enum {
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+ typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType;
+ typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime>
+ PermutationType;
+ typedef typename internal::plain_row_type<MatrixType, Index>::type
+ IntRowVectorType;
+ typedef typename internal::plain_row_type<MatrixType>::type RowVectorType;
+ typedef typename internal::plain_row_type<MatrixType, RealScalar>::type
+ RealRowVectorType;
+ typedef HouseholderSequence<
+ MatrixType, typename internal::remove_all<
+ typename HCoeffsType::ConjugateReturnType>::type>
+ HouseholderSequenceType;
+ typedef typename MatrixType::PlainObject PlainObject;
+
+ private:
+ typedef typename PermutationType::Index PermIndexType;
+
+ public:
+ /**
+ * \brief Default Constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via
+ * \c CompleteOrthogonalDecomposition::compute(const* MatrixType&).
+ */
+ CompleteOrthogonalDecomposition() : m_cpqr(), m_zCoeffs(), m_temp() {}
+
+ /** \brief Default Constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem \a size.
+ * \sa CompleteOrthogonalDecomposition()
+ */
+ CompleteOrthogonalDecomposition(Index rows, Index cols)
+ : m_cpqr(rows, cols), m_zCoeffs((std::min)(rows, cols)), m_temp(cols) {}
+
+ /** \brief Constructs a complete orthogonal decomposition from a given
+ * matrix.
+ *
+ * This constructor computes the complete orthogonal decomposition of the
+ * matrix \a matrix by calling the method compute(). The default
+ * threshold for rank determination will be used. It is a short cut for:
+ *
+ * \code
+ * CompleteOrthogonalDecomposition<MatrixType> cod(matrix.rows(),
+ * matrix.cols());
+ * cod.setThreshold(Default);
+ * cod.compute(matrix);
+ * \endcode
+ *
+ * \sa compute()
+ */
+ template <typename InputType>
+ explicit CompleteOrthogonalDecomposition(const EigenBase<InputType>& matrix)
+ : m_cpqr(matrix.rows(), matrix.cols()),
+ m_zCoeffs((std::min)(matrix.rows(), matrix.cols())),
+ m_temp(matrix.cols())
+ {
+ compute(matrix.derived());
+ }
+
+ /** \brief Constructs a complete orthogonal decomposition from a given matrix
+ *
+ * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c MatrixType is a Eigen::Ref.
+ *
+ * \sa CompleteOrthogonalDecomposition(const EigenBase&)
+ */
+ template<typename InputType>
+ explicit CompleteOrthogonalDecomposition(EigenBase<InputType>& matrix)
+ : m_cpqr(matrix.derived()),
+ m_zCoeffs((std::min)(matrix.rows(), matrix.cols())),
+ m_temp(matrix.cols())
+ {
+ computeInPlace();
+ }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** This method computes the minimum-norm solution X to a least squares
+ * problem \f[\mathrm{minimize} \|A X - B\|, \f] where \b A is the matrix of
+ * which \c *this is the complete orthogonal decomposition.
+ *
+ * \param b the right-hand sides of the problem to solve.
+ *
+ * \returns a solution.
+ *
+ */
+ template <typename Rhs>
+ inline const Solve<CompleteOrthogonalDecomposition, Rhs> solve(
+ const MatrixBase<Rhs>& b) const;
+ #endif
+
+ HouseholderSequenceType householderQ(void) const;
+ HouseholderSequenceType matrixQ(void) const { return m_cpqr.householderQ(); }
+
+ /** \returns the matrix \b Z.
+ */
+ MatrixType matrixZ() const {
+ MatrixType Z = MatrixType::Identity(m_cpqr.cols(), m_cpqr.cols());
+ applyZOnTheLeftInPlace<false>(Z);
+ return Z;
+ }
+
+ /** \returns a reference to the matrix where the complete orthogonal
+ * decomposition is stored
+ */
+ const MatrixType& matrixQTZ() const { return m_cpqr.matrixQR(); }
+
+ /** \returns a reference to the matrix where the complete orthogonal
+ * decomposition is stored.
+ * \warning The strict lower part and \code cols() - rank() \endcode right
+ * columns of this matrix contains internal values.
+ * Only the upper triangular part should be referenced. To get it, use
+ * \code matrixT().template triangularView<Upper>() \endcode
+ * For rank-deficient matrices, use
+ * \code
+ * matrixR().topLeftCorner(rank(), rank()).template triangularView<Upper>()
+ * \endcode
+ */
+ const MatrixType& matrixT() const { return m_cpqr.matrixQR(); }
+
+ template <typename InputType>
+ CompleteOrthogonalDecomposition& compute(const EigenBase<InputType>& matrix) {
+ // Compute the column pivoted QR factorization A P = Q R.
+ m_cpqr.compute(matrix);
+ computeInPlace();
+ return *this;
+ }
+
+ /** \returns a const reference to the column permutation matrix */
+ const PermutationType& colsPermutation() const {
+ return m_cpqr.colsPermutation();
+ }
+
+ /** \returns the absolute value of the determinant of the matrix of which
+ * *this is the complete orthogonal decomposition. It has only linear
+ * complexity (that is, O(n) where n is the dimension of the square matrix)
+ * as the complete orthogonal decomposition has already been computed.
+ *
+ * \note This is only for square matrices.
+ *
+ * \warning a determinant can be very big or small, so for matrices
+ * of large enough dimension, there is a risk of overflow/underflow.
+ * One way to work around that is to use logAbsDeterminant() instead.
+ *
+ * \sa logAbsDeterminant(), MatrixBase::determinant()
+ */
+ typename MatrixType::RealScalar absDeterminant() const;
+
+ /** \returns the natural log of the absolute value of the determinant of the
+ * matrix of which *this is the complete orthogonal decomposition. It has
+ * only linear complexity (that is, O(n) where n is the dimension of the
+ * square matrix) as the complete orthogonal decomposition has already been
+ * computed.
+ *
+ * \note This is only for square matrices.
+ *
+ * \note This method is useful to work around the risk of overflow/underflow
+ * that's inherent to determinant computation.
+ *
+ * \sa absDeterminant(), MatrixBase::determinant()
+ */
+ typename MatrixType::RealScalar logAbsDeterminant() const;
+
+ /** \returns the rank of the matrix of which *this is the complete orthogonal
+ * decomposition.
+ *
+ * \note This method has to determine which pivots should be considered
+ * nonzero. For that, it uses the threshold value that you can control by
+ * calling setThreshold(const RealScalar&).
+ */
+ inline Index rank() const { return m_cpqr.rank(); }
+
+ /** \returns the dimension of the kernel of the matrix of which *this is the
+ * complete orthogonal decomposition.
+ *
+ * \note This method has to determine which pivots should be considered
+ * nonzero. For that, it uses the threshold value that you can control by
+ * calling setThreshold(const RealScalar&).
+ */
+ inline Index dimensionOfKernel() const { return m_cpqr.dimensionOfKernel(); }
+
+ /** \returns true if the matrix of which *this is the decomposition represents
+ * an injective linear map, i.e. has trivial kernel; false otherwise.
+ *
+ * \note This method has to determine which pivots should be considered
+ * nonzero. For that, it uses the threshold value that you can control by
+ * calling setThreshold(const RealScalar&).
+ */
+ inline bool isInjective() const { return m_cpqr.isInjective(); }
+
+ /** \returns true if the matrix of which *this is the decomposition represents
+ * a surjective linear map; false otherwise.
+ *
+ * \note This method has to determine which pivots should be considered
+ * nonzero. For that, it uses the threshold value that you can control by
+ * calling setThreshold(const RealScalar&).
+ */
+ inline bool isSurjective() const { return m_cpqr.isSurjective(); }
+
+ /** \returns true if the matrix of which *this is the complete orthogonal
+ * decomposition is invertible.
+ *
+ * \note This method has to determine which pivots should be considered
+ * nonzero. For that, it uses the threshold value that you can control by
+ * calling setThreshold(const RealScalar&).
+ */
+ inline bool isInvertible() const { return m_cpqr.isInvertible(); }
+
+ /** \returns the pseudo-inverse of the matrix of which *this is the complete
+ * orthogonal decomposition.
+ * \warning: Do not compute \c this->pseudoInverse()*rhs to solve a linear systems.
+ * It is more efficient and numerically stable to call \c this->solve(rhs).
+ */
+ inline const Inverse<CompleteOrthogonalDecomposition> pseudoInverse() const
+ {
+ eigen_assert(m_cpqr.m_isInitialized && "CompleteOrthogonalDecomposition is not initialized.");
+ return Inverse<CompleteOrthogonalDecomposition>(*this);
+ }
+
+ inline Index rows() const { return m_cpqr.rows(); }
+ inline Index cols() const { return m_cpqr.cols(); }
+
+ /** \returns a const reference to the vector of Householder coefficients used
+ * to represent the factor \c Q.
+ *
+ * For advanced uses only.
+ */
+ inline const HCoeffsType& hCoeffs() const { return m_cpqr.hCoeffs(); }
+
+ /** \returns a const reference to the vector of Householder coefficients
+ * used to represent the factor \c Z.
+ *
+ * For advanced uses only.
+ */
+ const HCoeffsType& zCoeffs() const { return m_zCoeffs; }
+
+ /** Allows to prescribe a threshold to be used by certain methods, such as
+ * rank(), who need to determine when pivots are to be considered nonzero.
+ * Most be called before calling compute().
+ *
+ * When it needs to get the threshold value, Eigen calls threshold(). By
+ * default, this uses a formula to automatically determine a reasonable
+ * threshold. Once you have called the present method
+ * setThreshold(const RealScalar&), your value is used instead.
+ *
+ * \param threshold The new value to use as the threshold.
+ *
+ * A pivot will be considered nonzero if its absolute value is strictly
+ * greater than
+ * \f$ \vert pivot \vert \leqslant threshold \times \vert maxpivot \vert \f$
+ * where maxpivot is the biggest pivot.
+ *
+ * If you want to come back to the default behavior, call
+ * setThreshold(Default_t)
+ */
+ CompleteOrthogonalDecomposition& setThreshold(const RealScalar& threshold) {
+ m_cpqr.setThreshold(threshold);
+ return *this;
+ }
+
+ /** Allows to come back to the default behavior, letting Eigen use its default
+ * formula for determining the threshold.
+ *
+ * You should pass the special object Eigen::Default as parameter here.
+ * \code qr.setThreshold(Eigen::Default); \endcode
+ *
+ * See the documentation of setThreshold(const RealScalar&).
+ */
+ CompleteOrthogonalDecomposition& setThreshold(Default_t) {
+ m_cpqr.setThreshold(Default);
+ return *this;
+ }
+
+ /** Returns the threshold that will be used by certain methods such as rank().
+ *
+ * See the documentation of setThreshold(const RealScalar&).
+ */
+ RealScalar threshold() const { return m_cpqr.threshold(); }
+
+ /** \returns the number of nonzero pivots in the complete orthogonal
+ * decomposition. Here nonzero is meant in the exact sense, not in a
+ * fuzzy sense. So that notion isn't really intrinsically interesting,
+ * but it is still useful when implementing algorithms.
+ *
+ * \sa rank()
+ */
+ inline Index nonzeroPivots() const { return m_cpqr.nonzeroPivots(); }
+
+ /** \returns the absolute value of the biggest pivot, i.e. the biggest
+ * diagonal coefficient of R.
+ */
+ inline RealScalar maxPivot() const { return m_cpqr.maxPivot(); }
+
+ /** \brief Reports whether the complete orthogonal decomposition was
+ * successful.
+ *
+ * \note This function always returns \c Success. It is provided for
+ * compatibility
+ * with other factorization routines.
+ * \returns \c Success
+ */
+ ComputationInfo info() const {
+ eigen_assert(m_cpqr.m_isInitialized && "Decomposition is not initialized.");
+ return Success;
+ }
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ template <typename RhsType, typename DstType>
+ void _solve_impl(const RhsType& rhs, DstType& dst) const;
+
+ template<bool Conjugate, typename RhsType, typename DstType>
+ void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const;
+#endif
+
+ protected:
+ static void check_template_parameters() {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ }
+
+ template<bool Transpose_, typename Rhs>
+ void _check_solve_assertion(const Rhs& b) const {
+ EIGEN_ONLY_USED_FOR_DEBUG(b);
+ eigen_assert(m_cpqr.m_isInitialized && "CompleteOrthogonalDecomposition is not initialized.");
+ eigen_assert((Transpose_?derived().cols():derived().rows())==b.rows() && "CompleteOrthogonalDecomposition::solve(): invalid number of rows of the right hand side matrix b");
+ }
+
+ void computeInPlace();
+
+ /** Overwrites \b rhs with \f$ \mathbf{Z} * \mathbf{rhs} \f$ or
+ * \f$ \mathbf{\overline Z} * \mathbf{rhs} \f$ if \c Conjugate
+ * is set to \c true.
+ */
+ template <bool Conjugate, typename Rhs>
+ void applyZOnTheLeftInPlace(Rhs& rhs) const;
+
+ /** Overwrites \b rhs with \f$ \mathbf{Z}^* * \mathbf{rhs} \f$.
+ */
+ template <typename Rhs>
+ void applyZAdjointOnTheLeftInPlace(Rhs& rhs) const;
+
+ ColPivHouseholderQR<MatrixType> m_cpqr;
+ HCoeffsType m_zCoeffs;
+ RowVectorType m_temp;
+};
+
+template <typename MatrixType>
+typename MatrixType::RealScalar
+CompleteOrthogonalDecomposition<MatrixType>::absDeterminant() const {
+ return m_cpqr.absDeterminant();
+}
+
+template <typename MatrixType>
+typename MatrixType::RealScalar
+CompleteOrthogonalDecomposition<MatrixType>::logAbsDeterminant() const {
+ return m_cpqr.logAbsDeterminant();
+}
+
+/** Performs the complete orthogonal decomposition of the given matrix \a
+ * matrix. The result of the factorization is stored into \c *this, and a
+ * reference to \c *this is returned.
+ *
+ * \sa class CompleteOrthogonalDecomposition,
+ * CompleteOrthogonalDecomposition(const MatrixType&)
+ */
+template <typename MatrixType>
+void CompleteOrthogonalDecomposition<MatrixType>::computeInPlace()
+{
+ check_template_parameters();
+
+ // the column permutation is stored as int indices, so just to be sure:
+ eigen_assert(m_cpqr.cols() <= NumTraits<int>::highest());
+
+ const Index rank = m_cpqr.rank();
+ const Index cols = m_cpqr.cols();
+ const Index rows = m_cpqr.rows();
+ m_zCoeffs.resize((std::min)(rows, cols));
+ m_temp.resize(cols);
+
+ if (rank < cols) {
+ // We have reduced the (permuted) matrix to the form
+ // [R11 R12]
+ // [ 0 R22]
+ // where R11 is r-by-r (r = rank) upper triangular, R12 is
+ // r-by-(n-r), and R22 is empty or the norm of R22 is negligible.
+ // We now compute the complete orthogonal decomposition by applying
+ // Householder transformations from the right to the upper trapezoidal
+ // matrix X = [R11 R12] to zero out R12 and obtain the factorization
+ // [R11 R12] = [T11 0] * Z, where T11 is r-by-r upper triangular and
+ // Z = Z(0) * Z(1) ... Z(r-1) is an n-by-n orthogonal matrix.
+ // We store the data representing Z in R12 and m_zCoeffs.
+ for (Index k = rank - 1; k >= 0; --k) {
+ if (k != rank - 1) {
+ // Given the API for Householder reflectors, it is more convenient if
+ // we swap the leading parts of columns k and r-1 (zero-based) to form
+ // the matrix X_k = [X(0:k, k), X(0:k, r:n)]
+ m_cpqr.m_qr.col(k).head(k + 1).swap(
+ m_cpqr.m_qr.col(rank - 1).head(k + 1));
+ }
+ // Construct Householder reflector Z(k) to zero out the last row of X_k,
+ // i.e. choose Z(k) such that
+ // [X(k, k), X(k, r:n)] * Z(k) = [beta, 0, .., 0].
+ RealScalar beta;
+ m_cpqr.m_qr.row(k)
+ .tail(cols - rank + 1)
+ .makeHouseholderInPlace(m_zCoeffs(k), beta);
+ m_cpqr.m_qr(k, rank - 1) = beta;
+ if (k > 0) {
+ // Apply Z(k) to the first k rows of X_k
+ m_cpqr.m_qr.topRightCorner(k, cols - rank + 1)
+ .applyHouseholderOnTheRight(
+ m_cpqr.m_qr.row(k).tail(cols - rank).adjoint(), m_zCoeffs(k),
+ &m_temp(0));
+ }
+ if (k != rank - 1) {
+ // Swap X(0:k,k) back to its proper location.
+ m_cpqr.m_qr.col(k).head(k + 1).swap(
+ m_cpqr.m_qr.col(rank - 1).head(k + 1));
+ }
+ }
+ }
+}
+
+template <typename MatrixType>
+template <bool Conjugate, typename Rhs>
+void CompleteOrthogonalDecomposition<MatrixType>::applyZOnTheLeftInPlace(
+ Rhs& rhs) const {
+ const Index cols = this->cols();
+ const Index nrhs = rhs.cols();
+ const Index rank = this->rank();
+ Matrix<typename Rhs::Scalar, Dynamic, 1> temp((std::max)(cols, nrhs));
+ for (Index k = rank-1; k >= 0; --k) {
+ if (k != rank - 1) {
+ rhs.row(k).swap(rhs.row(rank - 1));
+ }
+ rhs.middleRows(rank - 1, cols - rank + 1)
+ .applyHouseholderOnTheLeft(
+ matrixQTZ().row(k).tail(cols - rank).transpose().template conjugateIf<!Conjugate>(), zCoeffs().template conjugateIf<Conjugate>()(k),
+ &temp(0));
+ if (k != rank - 1) {
+ rhs.row(k).swap(rhs.row(rank - 1));
+ }
+ }
+}
+
+template <typename MatrixType>
+template <typename Rhs>
+void CompleteOrthogonalDecomposition<MatrixType>::applyZAdjointOnTheLeftInPlace(
+ Rhs& rhs) const {
+ const Index cols = this->cols();
+ const Index nrhs = rhs.cols();
+ const Index rank = this->rank();
+ Matrix<typename Rhs::Scalar, Dynamic, 1> temp((std::max)(cols, nrhs));
+ for (Index k = 0; k < rank; ++k) {
+ if (k != rank - 1) {
+ rhs.row(k).swap(rhs.row(rank - 1));
+ }
+ rhs.middleRows(rank - 1, cols - rank + 1)
+ .applyHouseholderOnTheLeft(
+ matrixQTZ().row(k).tail(cols - rank).adjoint(), zCoeffs()(k),
+ &temp(0));
+ if (k != rank - 1) {
+ rhs.row(k).swap(rhs.row(rank - 1));
+ }
+ }
+}
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+template <typename _MatrixType>
+template <typename RhsType, typename DstType>
+void CompleteOrthogonalDecomposition<_MatrixType>::_solve_impl(
+ const RhsType& rhs, DstType& dst) const {
+ const Index rank = this->rank();
+ if (rank == 0) {
+ dst.setZero();
+ return;
+ }
+
+ // Compute c = Q^* * rhs
+ typename RhsType::PlainObject c(rhs);
+ c.applyOnTheLeft(matrixQ().setLength(rank).adjoint());
+
+ // Solve T z = c(1:rank, :)
+ dst.topRows(rank) = matrixT()
+ .topLeftCorner(rank, rank)
+ .template triangularView<Upper>()
+ .solve(c.topRows(rank));
+
+ const Index cols = this->cols();
+ if (rank < cols) {
+ // Compute y = Z^* * [ z ]
+ // [ 0 ]
+ dst.bottomRows(cols - rank).setZero();
+ applyZAdjointOnTheLeftInPlace(dst);
+ }
+
+ // Undo permutation to get x = P^{-1} * y.
+ dst = colsPermutation() * dst;
+}
+
+template<typename _MatrixType>
+template<bool Conjugate, typename RhsType, typename DstType>
+void CompleteOrthogonalDecomposition<_MatrixType>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const
+{
+ const Index rank = this->rank();
+
+ if (rank == 0) {
+ dst.setZero();
+ return;
+ }
+
+ typename RhsType::PlainObject c(colsPermutation().transpose()*rhs);
+
+ if (rank < cols()) {
+ applyZOnTheLeftInPlace<!Conjugate>(c);
+ }
+
+ matrixT().topLeftCorner(rank, rank)
+ .template triangularView<Upper>()
+ .transpose().template conjugateIf<Conjugate>()
+ .solveInPlace(c.topRows(rank));
+
+ dst.topRows(rank) = c.topRows(rank);
+ dst.bottomRows(rows()-rank).setZero();
+
+ dst.applyOnTheLeft(householderQ().setLength(rank).template conjugateIf<!Conjugate>() );
+}
+#endif
+
+namespace internal {
+
+template<typename MatrixType>
+struct traits<Inverse<CompleteOrthogonalDecomposition<MatrixType> > >
+ : traits<typename Transpose<typename MatrixType::PlainObject>::PlainObject>
+{
+ enum { Flags = 0 };
+};
+
+template<typename DstXprType, typename MatrixType>
+struct Assignment<DstXprType, Inverse<CompleteOrthogonalDecomposition<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename CompleteOrthogonalDecomposition<MatrixType>::Scalar>, Dense2Dense>
+{
+ typedef CompleteOrthogonalDecomposition<MatrixType> CodType;
+ typedef Inverse<CodType> SrcXprType;
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename CodType::Scalar> &)
+ {
+ typedef Matrix<typename CodType::Scalar, CodType::RowsAtCompileTime, CodType::RowsAtCompileTime, 0, CodType::MaxRowsAtCompileTime, CodType::MaxRowsAtCompileTime> IdentityMatrixType;
+ dst = src.nestedExpression().solve(IdentityMatrixType::Identity(src.cols(), src.cols()));
+ }
+};
+
+} // end namespace internal
+
+/** \returns the matrix Q as a sequence of householder transformations */
+template <typename MatrixType>
+typename CompleteOrthogonalDecomposition<MatrixType>::HouseholderSequenceType
+CompleteOrthogonalDecomposition<MatrixType>::householderQ() const {
+ return m_cpqr.householderQ();
+}
+
+/** \return the complete orthogonal decomposition of \c *this.
+ *
+ * \sa class CompleteOrthogonalDecomposition
+ */
+template <typename Derived>
+const CompleteOrthogonalDecomposition<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::completeOrthogonalDecomposition() const {
+ return CompleteOrthogonalDecomposition<PlainObject>(eval());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H
diff --git a/src/3rdparty/eigen/Eigen/src/QR/FullPivHouseholderQR.h b/src/3rdparty/eigen/Eigen/src/QR/FullPivHouseholderQR.h
new file mode 100644
index 000000000..d0664a1d8
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/QR/FullPivHouseholderQR.h
@@ -0,0 +1,713 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_FULLPIVOTINGHOUSEHOLDERQR_H
+#define EIGEN_FULLPIVOTINGHOUSEHOLDERQR_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename _MatrixType> struct traits<FullPivHouseholderQR<_MatrixType> >
+ : traits<_MatrixType>
+{
+ typedef MatrixXpr XprKind;
+ typedef SolverStorage StorageKind;
+ typedef int StorageIndex;
+ enum { Flags = 0 };
+};
+
+template<typename MatrixType> struct FullPivHouseholderQRMatrixQReturnType;
+
+template<typename MatrixType>
+struct traits<FullPivHouseholderQRMatrixQReturnType<MatrixType> >
+{
+ typedef typename MatrixType::PlainObject ReturnType;
+};
+
+} // end namespace internal
+
+/** \ingroup QR_Module
+ *
+ * \class FullPivHouseholderQR
+ *
+ * \brief Householder rank-revealing QR decomposition of a matrix with full pivoting
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the QR decomposition
+ *
+ * This class performs a rank-revealing QR decomposition of a matrix \b A into matrices \b P, \b P', \b Q and \b R
+ * such that
+ * \f[
+ * \mathbf{P} \, \mathbf{A} \, \mathbf{P}' = \mathbf{Q} \, \mathbf{R}
+ * \f]
+ * by using Householder transformations. Here, \b P and \b P' are permutation matrices, \b Q a unitary matrix
+ * and \b R an upper triangular matrix.
+ *
+ * This decomposition performs a very prudent full pivoting in order to be rank-revealing and achieve optimal
+ * numerical stability. The trade-off is that it is slower than HouseholderQR and ColPivHouseholderQR.
+ *
+ * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism.
+ *
+ * \sa MatrixBase::fullPivHouseholderQr()
+ */
+template<typename _MatrixType> class FullPivHouseholderQR
+ : public SolverBase<FullPivHouseholderQR<_MatrixType> >
+{
+ public:
+
+ typedef _MatrixType MatrixType;
+ typedef SolverBase<FullPivHouseholderQR> Base;
+ friend class SolverBase<FullPivHouseholderQR>;
+
+ EIGEN_GENERIC_PUBLIC_INTERFACE(FullPivHouseholderQR)
+ enum {
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+ typedef internal::FullPivHouseholderQRMatrixQReturnType<MatrixType> MatrixQReturnType;
+ typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType;
+ typedef Matrix<StorageIndex, 1,
+ EIGEN_SIZE_MIN_PREFER_DYNAMIC(ColsAtCompileTime,RowsAtCompileTime), RowMajor, 1,
+ EIGEN_SIZE_MIN_PREFER_FIXED(MaxColsAtCompileTime,MaxRowsAtCompileTime)> IntDiagSizeVectorType;
+ typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime> PermutationType;
+ typedef typename internal::plain_row_type<MatrixType>::type RowVectorType;
+ typedef typename internal::plain_col_type<MatrixType>::type ColVectorType;
+ typedef typename MatrixType::PlainObject PlainObject;
+
+ /** \brief Default Constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via FullPivHouseholderQR::compute(const MatrixType&).
+ */
+ FullPivHouseholderQR()
+ : m_qr(),
+ m_hCoeffs(),
+ m_rows_transpositions(),
+ m_cols_transpositions(),
+ m_cols_permutation(),
+ m_temp(),
+ m_isInitialized(false),
+ m_usePrescribedThreshold(false) {}
+
+ /** \brief Default Constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem \a size.
+ * \sa FullPivHouseholderQR()
+ */
+ FullPivHouseholderQR(Index rows, Index cols)
+ : m_qr(rows, cols),
+ m_hCoeffs((std::min)(rows,cols)),
+ m_rows_transpositions((std::min)(rows,cols)),
+ m_cols_transpositions((std::min)(rows,cols)),
+ m_cols_permutation(cols),
+ m_temp(cols),
+ m_isInitialized(false),
+ m_usePrescribedThreshold(false) {}
+
+ /** \brief Constructs a QR factorization from a given matrix
+ *
+ * This constructor computes the QR factorization of the matrix \a matrix by calling
+ * the method compute(). It is a short cut for:
+ *
+ * \code
+ * FullPivHouseholderQR<MatrixType> qr(matrix.rows(), matrix.cols());
+ * qr.compute(matrix);
+ * \endcode
+ *
+ * \sa compute()
+ */
+ template<typename InputType>
+ explicit FullPivHouseholderQR(const EigenBase<InputType>& matrix)
+ : m_qr(matrix.rows(), matrix.cols()),
+ m_hCoeffs((std::min)(matrix.rows(), matrix.cols())),
+ m_rows_transpositions((std::min)(matrix.rows(), matrix.cols())),
+ m_cols_transpositions((std::min)(matrix.rows(), matrix.cols())),
+ m_cols_permutation(matrix.cols()),
+ m_temp(matrix.cols()),
+ m_isInitialized(false),
+ m_usePrescribedThreshold(false)
+ {
+ compute(matrix.derived());
+ }
+
+ /** \brief Constructs a QR factorization from a given matrix
+ *
+ * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c MatrixType is a Eigen::Ref.
+ *
+ * \sa FullPivHouseholderQR(const EigenBase&)
+ */
+ template<typename InputType>
+ explicit FullPivHouseholderQR(EigenBase<InputType>& matrix)
+ : m_qr(matrix.derived()),
+ m_hCoeffs((std::min)(matrix.rows(), matrix.cols())),
+ m_rows_transpositions((std::min)(matrix.rows(), matrix.cols())),
+ m_cols_transpositions((std::min)(matrix.rows(), matrix.cols())),
+ m_cols_permutation(matrix.cols()),
+ m_temp(matrix.cols()),
+ m_isInitialized(false),
+ m_usePrescribedThreshold(false)
+ {
+ computeInPlace();
+ }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** This method finds a solution x to the equation Ax=b, where A is the matrix of which
+ * \c *this is the QR decomposition.
+ *
+ * \param b the right-hand-side of the equation to solve.
+ *
+ * \returns the exact or least-square solution if the rank is greater or equal to the number of columns of A,
+ * and an arbitrary solution otherwise.
+ *
+ * \note_about_checking_solutions
+ *
+ * \note_about_arbitrary_choice_of_solution
+ *
+ * Example: \include FullPivHouseholderQR_solve.cpp
+ * Output: \verbinclude FullPivHouseholderQR_solve.out
+ */
+ template<typename Rhs>
+ inline const Solve<FullPivHouseholderQR, Rhs>
+ solve(const MatrixBase<Rhs>& b) const;
+ #endif
+
+ /** \returns Expression object representing the matrix Q
+ */
+ MatrixQReturnType matrixQ(void) const;
+
+ /** \returns a reference to the matrix where the Householder QR decomposition is stored
+ */
+ const MatrixType& matrixQR() const
+ {
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ return m_qr;
+ }
+
+ template<typename InputType>
+ FullPivHouseholderQR& compute(const EigenBase<InputType>& matrix);
+
+ /** \returns a const reference to the column permutation matrix */
+ const PermutationType& colsPermutation() const
+ {
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ return m_cols_permutation;
+ }
+
+ /** \returns a const reference to the vector of indices representing the rows transpositions */
+ const IntDiagSizeVectorType& rowsTranspositions() const
+ {
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ return m_rows_transpositions;
+ }
+
+ /** \returns the absolute value of the determinant of the matrix of which
+ * *this is the QR decomposition. It has only linear complexity
+ * (that is, O(n) where n is the dimension of the square matrix)
+ * as the QR decomposition has already been computed.
+ *
+ * \note This is only for square matrices.
+ *
+ * \warning a determinant can be very big or small, so for matrices
+ * of large enough dimension, there is a risk of overflow/underflow.
+ * One way to work around that is to use logAbsDeterminant() instead.
+ *
+ * \sa logAbsDeterminant(), MatrixBase::determinant()
+ */
+ typename MatrixType::RealScalar absDeterminant() const;
+
+ /** \returns the natural log of the absolute value of the determinant of the matrix of which
+ * *this is the QR decomposition. It has only linear complexity
+ * (that is, O(n) where n is the dimension of the square matrix)
+ * as the QR decomposition has already been computed.
+ *
+ * \note This is only for square matrices.
+ *
+ * \note This method is useful to work around the risk of overflow/underflow that's inherent
+ * to determinant computation.
+ *
+ * \sa absDeterminant(), MatrixBase::determinant()
+ */
+ typename MatrixType::RealScalar logAbsDeterminant() const;
+
+ /** \returns the rank of the matrix of which *this is the QR decomposition.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline Index rank() const
+ {
+ using std::abs;
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold();
+ Index result = 0;
+ for(Index i = 0; i < m_nonzero_pivots; ++i)
+ result += (abs(m_qr.coeff(i,i)) > premultiplied_threshold);
+ return result;
+ }
+
+ /** \returns the dimension of the kernel of the matrix of which *this is the QR decomposition.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline Index dimensionOfKernel() const
+ {
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ return cols() - rank();
+ }
+
+ /** \returns true if the matrix of which *this is the QR decomposition represents an injective
+ * linear map, i.e. has trivial kernel; false otherwise.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline bool isInjective() const
+ {
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ return rank() == cols();
+ }
+
+ /** \returns true if the matrix of which *this is the QR decomposition represents a surjective
+ * linear map; false otherwise.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline bool isSurjective() const
+ {
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ return rank() == rows();
+ }
+
+ /** \returns true if the matrix of which *this is the QR decomposition is invertible.
+ *
+ * \note This method has to determine which pivots should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline bool isInvertible() const
+ {
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ return isInjective() && isSurjective();
+ }
+
+ /** \returns the inverse of the matrix of which *this is the QR decomposition.
+ *
+ * \note If this matrix is not invertible, the returned matrix has undefined coefficients.
+ * Use isInvertible() to first determine whether this matrix is invertible.
+ */
+ inline const Inverse<FullPivHouseholderQR> inverse() const
+ {
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ return Inverse<FullPivHouseholderQR>(*this);
+ }
+
+ inline Index rows() const { return m_qr.rows(); }
+ inline Index cols() const { return m_qr.cols(); }
+
+ /** \returns a const reference to the vector of Householder coefficients used to represent the factor \c Q.
+ *
+ * For advanced uses only.
+ */
+ const HCoeffsType& hCoeffs() const { return m_hCoeffs; }
+
+ /** Allows to prescribe a threshold to be used by certain methods, such as rank(),
+ * who need to determine when pivots are to be considered nonzero. This is not used for the
+ * QR decomposition itself.
+ *
+ * When it needs to get the threshold value, Eigen calls threshold(). By default, this
+ * uses a formula to automatically determine a reasonable threshold.
+ * Once you have called the present method setThreshold(const RealScalar&),
+ * your value is used instead.
+ *
+ * \param threshold The new value to use as the threshold.
+ *
+ * A pivot will be considered nonzero if its absolute value is strictly greater than
+ * \f$ \vert pivot \vert \leqslant threshold \times \vert maxpivot \vert \f$
+ * where maxpivot is the biggest pivot.
+ *
+ * If you want to come back to the default behavior, call setThreshold(Default_t)
+ */
+ FullPivHouseholderQR& setThreshold(const RealScalar& threshold)
+ {
+ m_usePrescribedThreshold = true;
+ m_prescribedThreshold = threshold;
+ return *this;
+ }
+
+ /** Allows to come back to the default behavior, letting Eigen use its default formula for
+ * determining the threshold.
+ *
+ * You should pass the special object Eigen::Default as parameter here.
+ * \code qr.setThreshold(Eigen::Default); \endcode
+ *
+ * See the documentation of setThreshold(const RealScalar&).
+ */
+ FullPivHouseholderQR& setThreshold(Default_t)
+ {
+ m_usePrescribedThreshold = false;
+ return *this;
+ }
+
+ /** Returns the threshold that will be used by certain methods such as rank().
+ *
+ * See the documentation of setThreshold(const RealScalar&).
+ */
+ RealScalar threshold() const
+ {
+ eigen_assert(m_isInitialized || m_usePrescribedThreshold);
+ return m_usePrescribedThreshold ? m_prescribedThreshold
+ // this formula comes from experimenting (see "LU precision tuning" thread on the list)
+ // and turns out to be identical to Higham's formula used already in LDLt.
+ : NumTraits<Scalar>::epsilon() * RealScalar(m_qr.diagonalSize());
+ }
+
+ /** \returns the number of nonzero pivots in the QR decomposition.
+ * Here nonzero is meant in the exact sense, not in a fuzzy sense.
+ * So that notion isn't really intrinsically interesting, but it is
+ * still useful when implementing algorithms.
+ *
+ * \sa rank()
+ */
+ inline Index nonzeroPivots() const
+ {
+ eigen_assert(m_isInitialized && "LU is not initialized.");
+ return m_nonzero_pivots;
+ }
+
+ /** \returns the absolute value of the biggest pivot, i.e. the biggest
+ * diagonal coefficient of U.
+ */
+ RealScalar maxPivot() const { return m_maxpivot; }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename RhsType, typename DstType>
+ void _solve_impl(const RhsType &rhs, DstType &dst) const;
+
+ template<bool Conjugate, typename RhsType, typename DstType>
+ void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const;
+ #endif
+
+ protected:
+
+ static void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ }
+
+ void computeInPlace();
+
+ MatrixType m_qr;
+ HCoeffsType m_hCoeffs;
+ IntDiagSizeVectorType m_rows_transpositions;
+ IntDiagSizeVectorType m_cols_transpositions;
+ PermutationType m_cols_permutation;
+ RowVectorType m_temp;
+ bool m_isInitialized, m_usePrescribedThreshold;
+ RealScalar m_prescribedThreshold, m_maxpivot;
+ Index m_nonzero_pivots;
+ RealScalar m_precision;
+ Index m_det_pq;
+};
+
+template<typename MatrixType>
+typename MatrixType::RealScalar FullPivHouseholderQR<MatrixType>::absDeterminant() const
+{
+ using std::abs;
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!");
+ return abs(m_qr.diagonal().prod());
+}
+
+template<typename MatrixType>
+typename MatrixType::RealScalar FullPivHouseholderQR<MatrixType>::logAbsDeterminant() const
+{
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!");
+ return m_qr.diagonal().cwiseAbs().array().log().sum();
+}
+
+/** Performs the QR factorization of the given matrix \a matrix. The result of
+ * the factorization is stored into \c *this, and a reference to \c *this
+ * is returned.
+ *
+ * \sa class FullPivHouseholderQR, FullPivHouseholderQR(const MatrixType&)
+ */
+template<typename MatrixType>
+template<typename InputType>
+FullPivHouseholderQR<MatrixType>& FullPivHouseholderQR<MatrixType>::compute(const EigenBase<InputType>& matrix)
+{
+ m_qr = matrix.derived();
+ computeInPlace();
+ return *this;
+}
+
+template<typename MatrixType>
+void FullPivHouseholderQR<MatrixType>::computeInPlace()
+{
+ check_template_parameters();
+
+ using std::abs;
+ Index rows = m_qr.rows();
+ Index cols = m_qr.cols();
+ Index size = (std::min)(rows,cols);
+
+
+ m_hCoeffs.resize(size);
+
+ m_temp.resize(cols);
+
+ m_precision = NumTraits<Scalar>::epsilon() * RealScalar(size);
+
+ m_rows_transpositions.resize(size);
+ m_cols_transpositions.resize(size);
+ Index number_of_transpositions = 0;
+
+ RealScalar biggest(0);
+
+ m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case)
+ m_maxpivot = RealScalar(0);
+
+ for (Index k = 0; k < size; ++k)
+ {
+ Index row_of_biggest_in_corner, col_of_biggest_in_corner;
+ typedef internal::scalar_score_coeff_op<Scalar> Scoring;
+ typedef typename Scoring::result_type Score;
+
+ Score score = m_qr.bottomRightCorner(rows-k, cols-k)
+ .unaryExpr(Scoring())
+ .maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner);
+ row_of_biggest_in_corner += k;
+ col_of_biggest_in_corner += k;
+ RealScalar biggest_in_corner = internal::abs_knowing_score<Scalar>()(m_qr(row_of_biggest_in_corner, col_of_biggest_in_corner), score);
+ if(k==0) biggest = biggest_in_corner;
+
+ // if the corner is negligible, then we have less than full rank, and we can finish early
+ if(internal::isMuchSmallerThan(biggest_in_corner, biggest, m_precision))
+ {
+ m_nonzero_pivots = k;
+ for(Index i = k; i < size; i++)
+ {
+ m_rows_transpositions.coeffRef(i) = internal::convert_index<StorageIndex>(i);
+ m_cols_transpositions.coeffRef(i) = internal::convert_index<StorageIndex>(i);
+ m_hCoeffs.coeffRef(i) = Scalar(0);
+ }
+ break;
+ }
+
+ m_rows_transpositions.coeffRef(k) = internal::convert_index<StorageIndex>(row_of_biggest_in_corner);
+ m_cols_transpositions.coeffRef(k) = internal::convert_index<StorageIndex>(col_of_biggest_in_corner);
+ if(k != row_of_biggest_in_corner) {
+ m_qr.row(k).tail(cols-k).swap(m_qr.row(row_of_biggest_in_corner).tail(cols-k));
+ ++number_of_transpositions;
+ }
+ if(k != col_of_biggest_in_corner) {
+ m_qr.col(k).swap(m_qr.col(col_of_biggest_in_corner));
+ ++number_of_transpositions;
+ }
+
+ RealScalar beta;
+ m_qr.col(k).tail(rows-k).makeHouseholderInPlace(m_hCoeffs.coeffRef(k), beta);
+ m_qr.coeffRef(k,k) = beta;
+
+ // remember the maximum absolute value of diagonal coefficients
+ if(abs(beta) > m_maxpivot) m_maxpivot = abs(beta);
+
+ m_qr.bottomRightCorner(rows-k, cols-k-1)
+ .applyHouseholderOnTheLeft(m_qr.col(k).tail(rows-k-1), m_hCoeffs.coeffRef(k), &m_temp.coeffRef(k+1));
+ }
+
+ m_cols_permutation.setIdentity(cols);
+ for(Index k = 0; k < size; ++k)
+ m_cols_permutation.applyTranspositionOnTheRight(k, m_cols_transpositions.coeff(k));
+
+ m_det_pq = (number_of_transpositions%2) ? -1 : 1;
+ m_isInitialized = true;
+}
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+template<typename _MatrixType>
+template<typename RhsType, typename DstType>
+void FullPivHouseholderQR<_MatrixType>::_solve_impl(const RhsType &rhs, DstType &dst) const
+{
+ const Index l_rank = rank();
+
+ // FIXME introduce nonzeroPivots() and use it here. and more generally,
+ // make the same improvements in this dec as in FullPivLU.
+ if(l_rank==0)
+ {
+ dst.setZero();
+ return;
+ }
+
+ typename RhsType::PlainObject c(rhs);
+
+ Matrix<typename RhsType::Scalar,1,RhsType::ColsAtCompileTime> temp(rhs.cols());
+ for (Index k = 0; k < l_rank; ++k)
+ {
+ Index remainingSize = rows()-k;
+ c.row(k).swap(c.row(m_rows_transpositions.coeff(k)));
+ c.bottomRightCorner(remainingSize, rhs.cols())
+ .applyHouseholderOnTheLeft(m_qr.col(k).tail(remainingSize-1),
+ m_hCoeffs.coeff(k), &temp.coeffRef(0));
+ }
+
+ m_qr.topLeftCorner(l_rank, l_rank)
+ .template triangularView<Upper>()
+ .solveInPlace(c.topRows(l_rank));
+
+ for(Index i = 0; i < l_rank; ++i) dst.row(m_cols_permutation.indices().coeff(i)) = c.row(i);
+ for(Index i = l_rank; i < cols(); ++i) dst.row(m_cols_permutation.indices().coeff(i)).setZero();
+}
+
+template<typename _MatrixType>
+template<bool Conjugate, typename RhsType, typename DstType>
+void FullPivHouseholderQR<_MatrixType>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const
+{
+ const Index l_rank = rank();
+
+ if(l_rank == 0)
+ {
+ dst.setZero();
+ return;
+ }
+
+ typename RhsType::PlainObject c(m_cols_permutation.transpose()*rhs);
+
+ m_qr.topLeftCorner(l_rank, l_rank)
+ .template triangularView<Upper>()
+ .transpose().template conjugateIf<Conjugate>()
+ .solveInPlace(c.topRows(l_rank));
+
+ dst.topRows(l_rank) = c.topRows(l_rank);
+ dst.bottomRows(rows()-l_rank).setZero();
+
+ Matrix<Scalar, 1, DstType::ColsAtCompileTime> temp(dst.cols());
+ const Index size = (std::min)(rows(), cols());
+ for (Index k = size-1; k >= 0; --k)
+ {
+ Index remainingSize = rows()-k;
+
+ dst.bottomRightCorner(remainingSize, dst.cols())
+ .applyHouseholderOnTheLeft(m_qr.col(k).tail(remainingSize-1).template conjugateIf<!Conjugate>(),
+ m_hCoeffs.template conjugateIf<Conjugate>().coeff(k), &temp.coeffRef(0));
+
+ dst.row(k).swap(dst.row(m_rows_transpositions.coeff(k)));
+ }
+}
+#endif
+
+namespace internal {
+
+template<typename DstXprType, typename MatrixType>
+struct Assignment<DstXprType, Inverse<FullPivHouseholderQR<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename FullPivHouseholderQR<MatrixType>::Scalar>, Dense2Dense>
+{
+ typedef FullPivHouseholderQR<MatrixType> QrType;
+ typedef Inverse<QrType> SrcXprType;
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename QrType::Scalar> &)
+ {
+ dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols()));
+ }
+};
+
+/** \ingroup QR_Module
+ *
+ * \brief Expression type for return value of FullPivHouseholderQR::matrixQ()
+ *
+ * \tparam MatrixType type of underlying dense matrix
+ */
+template<typename MatrixType> struct FullPivHouseholderQRMatrixQReturnType
+ : public ReturnByValue<FullPivHouseholderQRMatrixQReturnType<MatrixType> >
+{
+public:
+ typedef typename FullPivHouseholderQR<MatrixType>::IntDiagSizeVectorType IntDiagSizeVectorType;
+ typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType;
+ typedef Matrix<typename MatrixType::Scalar, 1, MatrixType::RowsAtCompileTime, RowMajor, 1,
+ MatrixType::MaxRowsAtCompileTime> WorkVectorType;
+
+ FullPivHouseholderQRMatrixQReturnType(const MatrixType& qr,
+ const HCoeffsType& hCoeffs,
+ const IntDiagSizeVectorType& rowsTranspositions)
+ : m_qr(qr),
+ m_hCoeffs(hCoeffs),
+ m_rowsTranspositions(rowsTranspositions)
+ {}
+
+ template <typename ResultType>
+ void evalTo(ResultType& result) const
+ {
+ const Index rows = m_qr.rows();
+ WorkVectorType workspace(rows);
+ evalTo(result, workspace);
+ }
+
+ template <typename ResultType>
+ void evalTo(ResultType& result, WorkVectorType& workspace) const
+ {
+ using numext::conj;
+ // compute the product H'_0 H'_1 ... H'_n-1,
+ // where H_k is the k-th Householder transformation I - h_k v_k v_k'
+ // and v_k is the k-th Householder vector [1,m_qr(k+1,k), m_qr(k+2,k), ...]
+ const Index rows = m_qr.rows();
+ const Index cols = m_qr.cols();
+ const Index size = (std::min)(rows, cols);
+ workspace.resize(rows);
+ result.setIdentity(rows, rows);
+ for (Index k = size-1; k >= 0; k--)
+ {
+ result.block(k, k, rows-k, rows-k)
+ .applyHouseholderOnTheLeft(m_qr.col(k).tail(rows-k-1), conj(m_hCoeffs.coeff(k)), &workspace.coeffRef(k));
+ result.row(k).swap(result.row(m_rowsTranspositions.coeff(k)));
+ }
+ }
+
+ Index rows() const { return m_qr.rows(); }
+ Index cols() const { return m_qr.rows(); }
+
+protected:
+ typename MatrixType::Nested m_qr;
+ typename HCoeffsType::Nested m_hCoeffs;
+ typename IntDiagSizeVectorType::Nested m_rowsTranspositions;
+};
+
+// template<typename MatrixType>
+// struct evaluator<FullPivHouseholderQRMatrixQReturnType<MatrixType> >
+// : public evaluator<ReturnByValue<FullPivHouseholderQRMatrixQReturnType<MatrixType> > >
+// {};
+
+} // end namespace internal
+
+template<typename MatrixType>
+inline typename FullPivHouseholderQR<MatrixType>::MatrixQReturnType FullPivHouseholderQR<MatrixType>::matrixQ() const
+{
+ eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
+ return MatrixQReturnType(m_qr, m_hCoeffs, m_rows_transpositions);
+}
+
+/** \return the full-pivoting Householder QR decomposition of \c *this.
+ *
+ * \sa class FullPivHouseholderQR
+ */
+template<typename Derived>
+const FullPivHouseholderQR<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::fullPivHouseholderQr() const
+{
+ return FullPivHouseholderQR<PlainObject>(eval());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_FULLPIVOTINGHOUSEHOLDERQR_H
diff --git a/src/3rdparty/eigen/Eigen/src/QR/HouseholderQR.h b/src/3rdparty/eigen/Eigen/src/QR/HouseholderQR.h
new file mode 100644
index 000000000..801739fbd
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/QR/HouseholderQR.h
@@ -0,0 +1,434 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2010 Vincent Lejeune
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_QR_H
+#define EIGEN_QR_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename _MatrixType> struct traits<HouseholderQR<_MatrixType> >
+ : traits<_MatrixType>
+{
+ typedef MatrixXpr XprKind;
+ typedef SolverStorage StorageKind;
+ typedef int StorageIndex;
+ enum { Flags = 0 };
+};
+
+} // end namespace internal
+
+/** \ingroup QR_Module
+ *
+ *
+ * \class HouseholderQR
+ *
+ * \brief Householder QR decomposition of a matrix
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the QR decomposition
+ *
+ * This class performs a QR decomposition of a matrix \b A into matrices \b Q and \b R
+ * such that
+ * \f[
+ * \mathbf{A} = \mathbf{Q} \, \mathbf{R}
+ * \f]
+ * by using Householder transformations. Here, \b Q a unitary matrix and \b R an upper triangular matrix.
+ * The result is stored in a compact way compatible with LAPACK.
+ *
+ * Note that no pivoting is performed. This is \b not a rank-revealing decomposition.
+ * If you want that feature, use FullPivHouseholderQR or ColPivHouseholderQR instead.
+ *
+ * This Householder QR decomposition is faster, but less numerically stable and less feature-full than
+ * FullPivHouseholderQR or ColPivHouseholderQR.
+ *
+ * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism.
+ *
+ * \sa MatrixBase::householderQr()
+ */
+template<typename _MatrixType> class HouseholderQR
+ : public SolverBase<HouseholderQR<_MatrixType> >
+{
+ public:
+
+ typedef _MatrixType MatrixType;
+ typedef SolverBase<HouseholderQR> Base;
+ friend class SolverBase<HouseholderQR>;
+
+ EIGEN_GENERIC_PUBLIC_INTERFACE(HouseholderQR)
+ enum {
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
+ };
+ typedef Matrix<Scalar, RowsAtCompileTime, RowsAtCompileTime, (MatrixType::Flags&RowMajorBit) ? RowMajor : ColMajor, MaxRowsAtCompileTime, MaxRowsAtCompileTime> MatrixQType;
+ typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType;
+ typedef typename internal::plain_row_type<MatrixType>::type RowVectorType;
+ typedef HouseholderSequence<MatrixType,typename internal::remove_all<typename HCoeffsType::ConjugateReturnType>::type> HouseholderSequenceType;
+
+ /**
+ * \brief Default Constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via HouseholderQR::compute(const MatrixType&).
+ */
+ HouseholderQR() : m_qr(), m_hCoeffs(), m_temp(), m_isInitialized(false) {}
+
+ /** \brief Default Constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem \a size.
+ * \sa HouseholderQR()
+ */
+ HouseholderQR(Index rows, Index cols)
+ : m_qr(rows, cols),
+ m_hCoeffs((std::min)(rows,cols)),
+ m_temp(cols),
+ m_isInitialized(false) {}
+
+ /** \brief Constructs a QR factorization from a given matrix
+ *
+ * This constructor computes the QR factorization of the matrix \a matrix by calling
+ * the method compute(). It is a short cut for:
+ *
+ * \code
+ * HouseholderQR<MatrixType> qr(matrix.rows(), matrix.cols());
+ * qr.compute(matrix);
+ * \endcode
+ *
+ * \sa compute()
+ */
+ template<typename InputType>
+ explicit HouseholderQR(const EigenBase<InputType>& matrix)
+ : m_qr(matrix.rows(), matrix.cols()),
+ m_hCoeffs((std::min)(matrix.rows(),matrix.cols())),
+ m_temp(matrix.cols()),
+ m_isInitialized(false)
+ {
+ compute(matrix.derived());
+ }
+
+
+ /** \brief Constructs a QR factorization from a given matrix
+ *
+ * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when
+ * \c MatrixType is a Eigen::Ref.
+ *
+ * \sa HouseholderQR(const EigenBase&)
+ */
+ template<typename InputType>
+ explicit HouseholderQR(EigenBase<InputType>& matrix)
+ : m_qr(matrix.derived()),
+ m_hCoeffs((std::min)(matrix.rows(),matrix.cols())),
+ m_temp(matrix.cols()),
+ m_isInitialized(false)
+ {
+ computeInPlace();
+ }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** This method finds a solution x to the equation Ax=b, where A is the matrix of which
+ * *this is the QR decomposition, if any exists.
+ *
+ * \param b the right-hand-side of the equation to solve.
+ *
+ * \returns a solution.
+ *
+ * \note_about_checking_solutions
+ *
+ * \note_about_arbitrary_choice_of_solution
+ *
+ * Example: \include HouseholderQR_solve.cpp
+ * Output: \verbinclude HouseholderQR_solve.out
+ */
+ template<typename Rhs>
+ inline const Solve<HouseholderQR, Rhs>
+ solve(const MatrixBase<Rhs>& b) const;
+ #endif
+
+ /** This method returns an expression of the unitary matrix Q as a sequence of Householder transformations.
+ *
+ * The returned expression can directly be used to perform matrix products. It can also be assigned to a dense Matrix object.
+ * Here is an example showing how to recover the full or thin matrix Q, as well as how to perform matrix products using operator*:
+ *
+ * Example: \include HouseholderQR_householderQ.cpp
+ * Output: \verbinclude HouseholderQR_householderQ.out
+ */
+ HouseholderSequenceType householderQ() const
+ {
+ eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
+ return HouseholderSequenceType(m_qr, m_hCoeffs.conjugate());
+ }
+
+ /** \returns a reference to the matrix where the Householder QR decomposition is stored
+ * in a LAPACK-compatible way.
+ */
+ const MatrixType& matrixQR() const
+ {
+ eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
+ return m_qr;
+ }
+
+ template<typename InputType>
+ HouseholderQR& compute(const EigenBase<InputType>& matrix) {
+ m_qr = matrix.derived();
+ computeInPlace();
+ return *this;
+ }
+
+ /** \returns the absolute value of the determinant of the matrix of which
+ * *this is the QR decomposition. It has only linear complexity
+ * (that is, O(n) where n is the dimension of the square matrix)
+ * as the QR decomposition has already been computed.
+ *
+ * \note This is only for square matrices.
+ *
+ * \warning a determinant can be very big or small, so for matrices
+ * of large enough dimension, there is a risk of overflow/underflow.
+ * One way to work around that is to use logAbsDeterminant() instead.
+ *
+ * \sa logAbsDeterminant(), MatrixBase::determinant()
+ */
+ typename MatrixType::RealScalar absDeterminant() const;
+
+ /** \returns the natural log of the absolute value of the determinant of the matrix of which
+ * *this is the QR decomposition. It has only linear complexity
+ * (that is, O(n) where n is the dimension of the square matrix)
+ * as the QR decomposition has already been computed.
+ *
+ * \note This is only for square matrices.
+ *
+ * \note This method is useful to work around the risk of overflow/underflow that's inherent
+ * to determinant computation.
+ *
+ * \sa absDeterminant(), MatrixBase::determinant()
+ */
+ typename MatrixType::RealScalar logAbsDeterminant() const;
+
+ inline Index rows() const { return m_qr.rows(); }
+ inline Index cols() const { return m_qr.cols(); }
+
+ /** \returns a const reference to the vector of Householder coefficients used to represent the factor \c Q.
+ *
+ * For advanced uses only.
+ */
+ const HCoeffsType& hCoeffs() const { return m_hCoeffs; }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename RhsType, typename DstType>
+ void _solve_impl(const RhsType &rhs, DstType &dst) const;
+
+ template<bool Conjugate, typename RhsType, typename DstType>
+ void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const;
+ #endif
+
+ protected:
+
+ static void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ }
+
+ void computeInPlace();
+
+ MatrixType m_qr;
+ HCoeffsType m_hCoeffs;
+ RowVectorType m_temp;
+ bool m_isInitialized;
+};
+
+template<typename MatrixType>
+typename MatrixType::RealScalar HouseholderQR<MatrixType>::absDeterminant() const
+{
+ using std::abs;
+ eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
+ eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!");
+ return abs(m_qr.diagonal().prod());
+}
+
+template<typename MatrixType>
+typename MatrixType::RealScalar HouseholderQR<MatrixType>::logAbsDeterminant() const
+{
+ eigen_assert(m_isInitialized && "HouseholderQR is not initialized.");
+ eigen_assert(m_qr.rows() == m_qr.cols() && "You can't take the determinant of a non-square matrix!");
+ return m_qr.diagonal().cwiseAbs().array().log().sum();
+}
+
+namespace internal {
+
+/** \internal */
+template<typename MatrixQR, typename HCoeffs>
+void householder_qr_inplace_unblocked(MatrixQR& mat, HCoeffs& hCoeffs, typename MatrixQR::Scalar* tempData = 0)
+{
+ typedef typename MatrixQR::Scalar Scalar;
+ typedef typename MatrixQR::RealScalar RealScalar;
+ Index rows = mat.rows();
+ Index cols = mat.cols();
+ Index size = (std::min)(rows,cols);
+
+ eigen_assert(hCoeffs.size() == size);
+
+ typedef Matrix<Scalar,MatrixQR::ColsAtCompileTime,1> TempType;
+ TempType tempVector;
+ if(tempData==0)
+ {
+ tempVector.resize(cols);
+ tempData = tempVector.data();
+ }
+
+ for(Index k = 0; k < size; ++k)
+ {
+ Index remainingRows = rows - k;
+ Index remainingCols = cols - k - 1;
+
+ RealScalar beta;
+ mat.col(k).tail(remainingRows).makeHouseholderInPlace(hCoeffs.coeffRef(k), beta);
+ mat.coeffRef(k,k) = beta;
+
+ // apply H to remaining part of m_qr from the left
+ mat.bottomRightCorner(remainingRows, remainingCols)
+ .applyHouseholderOnTheLeft(mat.col(k).tail(remainingRows-1), hCoeffs.coeffRef(k), tempData+k+1);
+ }
+}
+
+/** \internal */
+template<typename MatrixQR, typename HCoeffs,
+ typename MatrixQRScalar = typename MatrixQR::Scalar,
+ bool InnerStrideIsOne = (MatrixQR::InnerStrideAtCompileTime == 1 && HCoeffs::InnerStrideAtCompileTime == 1)>
+struct householder_qr_inplace_blocked
+{
+ // This is specialized for LAPACK-supported Scalar types in HouseholderQR_LAPACKE.h
+ static void run(MatrixQR& mat, HCoeffs& hCoeffs, Index maxBlockSize=32,
+ typename MatrixQR::Scalar* tempData = 0)
+ {
+ typedef typename MatrixQR::Scalar Scalar;
+ typedef Block<MatrixQR,Dynamic,Dynamic> BlockType;
+
+ Index rows = mat.rows();
+ Index cols = mat.cols();
+ Index size = (std::min)(rows, cols);
+
+ typedef Matrix<Scalar,Dynamic,1,ColMajor,MatrixQR::MaxColsAtCompileTime,1> TempType;
+ TempType tempVector;
+ if(tempData==0)
+ {
+ tempVector.resize(cols);
+ tempData = tempVector.data();
+ }
+
+ Index blockSize = (std::min)(maxBlockSize,size);
+
+ Index k = 0;
+ for (k = 0; k < size; k += blockSize)
+ {
+ Index bs = (std::min)(size-k,blockSize); // actual size of the block
+ Index tcols = cols - k - bs; // trailing columns
+ Index brows = rows-k; // rows of the block
+
+ // partition the matrix:
+ // A00 | A01 | A02
+ // mat = A10 | A11 | A12
+ // A20 | A21 | A22
+ // and performs the qr dec of [A11^T A12^T]^T
+ // and update [A21^T A22^T]^T using level 3 operations.
+ // Finally, the algorithm continue on A22
+
+ BlockType A11_21 = mat.block(k,k,brows,bs);
+ Block<HCoeffs,Dynamic,1> hCoeffsSegment = hCoeffs.segment(k,bs);
+
+ householder_qr_inplace_unblocked(A11_21, hCoeffsSegment, tempData);
+
+ if(tcols)
+ {
+ BlockType A21_22 = mat.block(k,k+bs,brows,tcols);
+ apply_block_householder_on_the_left(A21_22,A11_21,hCoeffsSegment, false); // false == backward
+ }
+ }
+ }
+};
+
+} // end namespace internal
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+template<typename _MatrixType>
+template<typename RhsType, typename DstType>
+void HouseholderQR<_MatrixType>::_solve_impl(const RhsType &rhs, DstType &dst) const
+{
+ const Index rank = (std::min)(rows(), cols());
+
+ typename RhsType::PlainObject c(rhs);
+
+ c.applyOnTheLeft(householderQ().setLength(rank).adjoint() );
+
+ m_qr.topLeftCorner(rank, rank)
+ .template triangularView<Upper>()
+ .solveInPlace(c.topRows(rank));
+
+ dst.topRows(rank) = c.topRows(rank);
+ dst.bottomRows(cols()-rank).setZero();
+}
+
+template<typename _MatrixType>
+template<bool Conjugate, typename RhsType, typename DstType>
+void HouseholderQR<_MatrixType>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const
+{
+ const Index rank = (std::min)(rows(), cols());
+
+ typename RhsType::PlainObject c(rhs);
+
+ m_qr.topLeftCorner(rank, rank)
+ .template triangularView<Upper>()
+ .transpose().template conjugateIf<Conjugate>()
+ .solveInPlace(c.topRows(rank));
+
+ dst.topRows(rank) = c.topRows(rank);
+ dst.bottomRows(rows()-rank).setZero();
+
+ dst.applyOnTheLeft(householderQ().setLength(rank).template conjugateIf<!Conjugate>() );
+}
+#endif
+
+/** Performs the QR factorization of the given matrix \a matrix. The result of
+ * the factorization is stored into \c *this, and a reference to \c *this
+ * is returned.
+ *
+ * \sa class HouseholderQR, HouseholderQR(const MatrixType&)
+ */
+template<typename MatrixType>
+void HouseholderQR<MatrixType>::computeInPlace()
+{
+ check_template_parameters();
+
+ Index rows = m_qr.rows();
+ Index cols = m_qr.cols();
+ Index size = (std::min)(rows,cols);
+
+ m_hCoeffs.resize(size);
+
+ m_temp.resize(cols);
+
+ internal::householder_qr_inplace_blocked<MatrixType, HCoeffsType>::run(m_qr, m_hCoeffs, 48, m_temp.data());
+
+ m_isInitialized = true;
+}
+
+/** \return the Householder QR decomposition of \c *this.
+ *
+ * \sa class HouseholderQR
+ */
+template<typename Derived>
+const HouseholderQR<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::householderQr() const
+{
+ return HouseholderQR<PlainObject>(eval());
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_QR_H
diff --git a/src/3rdparty/eigen/Eigen/src/QR/HouseholderQR_LAPACKE.h b/src/3rdparty/eigen/Eigen/src/QR/HouseholderQR_LAPACKE.h
new file mode 100644
index 000000000..1dc7d5363
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/QR/HouseholderQR_LAPACKE.h
@@ -0,0 +1,68 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to LAPACKe
+ * Householder QR decomposition of a matrix w/o pivoting based on
+ * LAPACKE_?geqrf function.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_QR_LAPACKE_H
+#define EIGEN_QR_LAPACKE_H
+
+namespace Eigen {
+
+namespace internal {
+
+/** \internal Specialization for the data types supported by LAPACKe */
+
+#define EIGEN_LAPACKE_QR_NOPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX) \
+template<typename MatrixQR, typename HCoeffs> \
+struct householder_qr_inplace_blocked<MatrixQR, HCoeffs, EIGTYPE, true> \
+{ \
+ static void run(MatrixQR& mat, HCoeffs& hCoeffs, Index = 32, \
+ typename MatrixQR::Scalar* = 0) \
+ { \
+ lapack_int m = (lapack_int) mat.rows(); \
+ lapack_int n = (lapack_int) mat.cols(); \
+ lapack_int lda = (lapack_int) mat.outerStride(); \
+ lapack_int matrix_order = (MatrixQR::IsRowMajor) ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \
+ LAPACKE_##LAPACKE_PREFIX##geqrf( matrix_order, m, n, (LAPACKE_TYPE*)mat.data(), lda, (LAPACKE_TYPE*)hCoeffs.data()); \
+ hCoeffs.adjointInPlace(); \
+ } \
+};
+
+EIGEN_LAPACKE_QR_NOPIV(double, double, d)
+EIGEN_LAPACKE_QR_NOPIV(float, float, s)
+EIGEN_LAPACKE_QR_NOPIV(dcomplex, lapack_complex_double, z)
+EIGEN_LAPACKE_QR_NOPIV(scomplex, lapack_complex_float, c)
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_QR_LAPACKE_H
diff --git a/src/3rdparty/eigen/Eigen/src/SVD/BDCSVD.h b/src/3rdparty/eigen/Eigen/src/SVD/BDCSVD.h
new file mode 100644
index 000000000..17f8e4436
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/SVD/BDCSVD.h
@@ -0,0 +1,1366 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// We used the "A Divide-And-Conquer Algorithm for the Bidiagonal SVD"
+// research report written by Ming Gu and Stanley C.Eisenstat
+// The code variable names correspond to the names they used in their
+// report
+//
+// Copyright (C) 2013 Gauthier Brun <brun.gauthier@gmail.com>
+// Copyright (C) 2013 Nicolas Carre <nicolas.carre@ensimag.fr>
+// Copyright (C) 2013 Jean Ceccato <jean.ceccato@ensimag.fr>
+// Copyright (C) 2013 Pierre Zoppitelli <pierre.zoppitelli@ensimag.fr>
+// Copyright (C) 2013 Jitse Niesen <jitse@maths.leeds.ac.uk>
+// Copyright (C) 2014-2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_BDCSVD_H
+#define EIGEN_BDCSVD_H
+// #define EIGEN_BDCSVD_DEBUG_VERBOSE
+// #define EIGEN_BDCSVD_SANITY_CHECKS
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+#undef eigen_internal_assert
+#define eigen_internal_assert(X) assert(X);
+#endif
+
+namespace Eigen {
+
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+IOFormat bdcsvdfmt(8, 0, ", ", "\n", " [", "]");
+#endif
+
+template<typename _MatrixType> class BDCSVD;
+
+namespace internal {
+
+template<typename _MatrixType>
+struct traits<BDCSVD<_MatrixType> >
+ : traits<_MatrixType>
+{
+ typedef _MatrixType MatrixType;
+};
+
+} // end namespace internal
+
+
+/** \ingroup SVD_Module
+ *
+ *
+ * \class BDCSVD
+ *
+ * \brief class Bidiagonal Divide and Conquer SVD
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the SVD decomposition
+ *
+ * This class first reduces the input matrix to bi-diagonal form using class UpperBidiagonalization,
+ * and then performs a divide-and-conquer diagonalization. Small blocks are diagonalized using class JacobiSVD.
+ * You can control the switching size with the setSwitchSize() method, default is 16.
+ * For small matrice (<16), it is thus preferable to directly use JacobiSVD. For larger ones, BDCSVD is highly
+ * recommended and can several order of magnitude faster.
+ *
+ * \warning this algorithm is unlikely to provide accurate result when compiled with unsafe math optimizations.
+ * For instance, this concerns Intel's compiler (ICC), which performs such optimization by default unless
+ * you compile with the \c -fp-model \c precise option. Likewise, the \c -ffast-math option of GCC or clang will
+ * significantly degrade the accuracy.
+ *
+ * \sa class JacobiSVD
+ */
+template<typename _MatrixType>
+class BDCSVD : public SVDBase<BDCSVD<_MatrixType> >
+{
+ typedef SVDBase<BDCSVD> Base;
+
+public:
+ using Base::rows;
+ using Base::cols;
+ using Base::computeU;
+ using Base::computeV;
+
+ typedef _MatrixType MatrixType;
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
+ typedef typename NumTraits<RealScalar>::Literal Literal;
+ enum {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ DiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime, ColsAtCompileTime),
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
+ MaxDiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(MaxRowsAtCompileTime, MaxColsAtCompileTime),
+ MatrixOptions = MatrixType::Options
+ };
+
+ typedef typename Base::MatrixUType MatrixUType;
+ typedef typename Base::MatrixVType MatrixVType;
+ typedef typename Base::SingularValuesType SingularValuesType;
+
+ typedef Matrix<Scalar, Dynamic, Dynamic, ColMajor> MatrixX;
+ typedef Matrix<RealScalar, Dynamic, Dynamic, ColMajor> MatrixXr;
+ typedef Matrix<RealScalar, Dynamic, 1> VectorType;
+ typedef Array<RealScalar, Dynamic, 1> ArrayXr;
+ typedef Array<Index,1,Dynamic> ArrayXi;
+ typedef Ref<ArrayXr> ArrayRef;
+ typedef Ref<ArrayXi> IndicesRef;
+
+ /** \brief Default Constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via BDCSVD::compute(const MatrixType&).
+ */
+ BDCSVD() : m_algoswap(16), m_isTranspose(false), m_compU(false), m_compV(false), m_numIters(0)
+ {}
+
+
+ /** \brief Default Constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem size.
+ * \sa BDCSVD()
+ */
+ BDCSVD(Index rows, Index cols, unsigned int computationOptions = 0)
+ : m_algoswap(16), m_numIters(0)
+ {
+ allocate(rows, cols, computationOptions);
+ }
+
+ /** \brief Constructor performing the decomposition of given matrix.
+ *
+ * \param matrix the matrix to decompose
+ * \param computationOptions optional parameter allowing to specify if you want full or thin U or V unitaries to be computed.
+ * By default, none is computed. This is a bit - field, the possible bits are #ComputeFullU, #ComputeThinU,
+ * #ComputeFullV, #ComputeThinV.
+ *
+ * Thin unitaries are only available if your matrix type has a Dynamic number of columns (for example MatrixXf). They also are not
+ * available with the (non - default) FullPivHouseholderQR preconditioner.
+ */
+ BDCSVD(const MatrixType& matrix, unsigned int computationOptions = 0)
+ : m_algoswap(16), m_numIters(0)
+ {
+ compute(matrix, computationOptions);
+ }
+
+ ~BDCSVD()
+ {
+ }
+
+ /** \brief Method performing the decomposition of given matrix using custom options.
+ *
+ * \param matrix the matrix to decompose
+ * \param computationOptions optional parameter allowing to specify if you want full or thin U or V unitaries to be computed.
+ * By default, none is computed. This is a bit - field, the possible bits are #ComputeFullU, #ComputeThinU,
+ * #ComputeFullV, #ComputeThinV.
+ *
+ * Thin unitaries are only available if your matrix type has a Dynamic number of columns (for example MatrixXf). They also are not
+ * available with the (non - default) FullPivHouseholderQR preconditioner.
+ */
+ BDCSVD& compute(const MatrixType& matrix, unsigned int computationOptions);
+
+ /** \brief Method performing the decomposition of given matrix using current options.
+ *
+ * \param matrix the matrix to decompose
+ *
+ * This method uses the current \a computationOptions, as already passed to the constructor or to compute(const MatrixType&, unsigned int).
+ */
+ BDCSVD& compute(const MatrixType& matrix)
+ {
+ return compute(matrix, this->m_computationOptions);
+ }
+
+ void setSwitchSize(int s)
+ {
+ eigen_assert(s>3 && "BDCSVD the size of the algo switch has to be greater than 3");
+ m_algoswap = s;
+ }
+
+private:
+ void allocate(Index rows, Index cols, unsigned int computationOptions);
+ void divide(Index firstCol, Index lastCol, Index firstRowW, Index firstColW, Index shift);
+ void computeSVDofM(Index firstCol, Index n, MatrixXr& U, VectorType& singVals, MatrixXr& V);
+ void computeSingVals(const ArrayRef& col0, const ArrayRef& diag, const IndicesRef& perm, VectorType& singVals, ArrayRef shifts, ArrayRef mus);
+ void perturbCol0(const ArrayRef& col0, const ArrayRef& diag, const IndicesRef& perm, const VectorType& singVals, const ArrayRef& shifts, const ArrayRef& mus, ArrayRef zhat);
+ void computeSingVecs(const ArrayRef& zhat, const ArrayRef& diag, const IndicesRef& perm, const VectorType& singVals, const ArrayRef& shifts, const ArrayRef& mus, MatrixXr& U, MatrixXr& V);
+ void deflation43(Index firstCol, Index shift, Index i, Index size);
+ void deflation44(Index firstColu , Index firstColm, Index firstRowW, Index firstColW, Index i, Index j, Index size);
+ void deflation(Index firstCol, Index lastCol, Index k, Index firstRowW, Index firstColW, Index shift);
+ template<typename HouseholderU, typename HouseholderV, typename NaiveU, typename NaiveV>
+ void copyUV(const HouseholderU &householderU, const HouseholderV &householderV, const NaiveU &naiveU, const NaiveV &naivev);
+ void structured_update(Block<MatrixXr,Dynamic,Dynamic> A, const MatrixXr &B, Index n1);
+ static RealScalar secularEq(RealScalar x, const ArrayRef& col0, const ArrayRef& diag, const IndicesRef &perm, const ArrayRef& diagShifted, RealScalar shift);
+
+protected:
+ MatrixXr m_naiveU, m_naiveV;
+ MatrixXr m_computed;
+ Index m_nRec;
+ ArrayXr m_workspace;
+ ArrayXi m_workspaceI;
+ int m_algoswap;
+ bool m_isTranspose, m_compU, m_compV;
+
+ using Base::m_singularValues;
+ using Base::m_diagSize;
+ using Base::m_computeFullU;
+ using Base::m_computeFullV;
+ using Base::m_computeThinU;
+ using Base::m_computeThinV;
+ using Base::m_matrixU;
+ using Base::m_matrixV;
+ using Base::m_info;
+ using Base::m_isInitialized;
+ using Base::m_nonzeroSingularValues;
+
+public:
+ int m_numIters;
+}; //end class BDCSVD
+
+
+// Method to allocate and initialize matrix and attributes
+template<typename MatrixType>
+void BDCSVD<MatrixType>::allocate(Eigen::Index rows, Eigen::Index cols, unsigned int computationOptions)
+{
+ m_isTranspose = (cols > rows);
+
+ if (Base::allocate(rows, cols, computationOptions))
+ return;
+
+ m_computed = MatrixXr::Zero(m_diagSize + 1, m_diagSize );
+ m_compU = computeV();
+ m_compV = computeU();
+ if (m_isTranspose)
+ std::swap(m_compU, m_compV);
+
+ if (m_compU) m_naiveU = MatrixXr::Zero(m_diagSize + 1, m_diagSize + 1 );
+ else m_naiveU = MatrixXr::Zero(2, m_diagSize + 1 );
+
+ if (m_compV) m_naiveV = MatrixXr::Zero(m_diagSize, m_diagSize);
+
+ m_workspace.resize((m_diagSize+1)*(m_diagSize+1)*3);
+ m_workspaceI.resize(3*m_diagSize);
+}// end allocate
+
+template<typename MatrixType>
+BDCSVD<MatrixType>& BDCSVD<MatrixType>::compute(const MatrixType& matrix, unsigned int computationOptions)
+{
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "\n\n\n======================================================================================================================\n\n\n";
+#endif
+ allocate(matrix.rows(), matrix.cols(), computationOptions);
+ using std::abs;
+
+ const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)();
+
+ //**** step -1 - If the problem is too small, directly falls back to JacobiSVD and return
+ if(matrix.cols() < m_algoswap)
+ {
+ // FIXME this line involves temporaries
+ JacobiSVD<MatrixType> jsvd(matrix,computationOptions);
+ m_isInitialized = true;
+ m_info = jsvd.info();
+ if (m_info == Success || m_info == NoConvergence) {
+ if(computeU()) m_matrixU = jsvd.matrixU();
+ if(computeV()) m_matrixV = jsvd.matrixV();
+ m_singularValues = jsvd.singularValues();
+ m_nonzeroSingularValues = jsvd.nonzeroSingularValues();
+ }
+ return *this;
+ }
+
+ //**** step 0 - Copy the input matrix and apply scaling to reduce over/under-flows
+ RealScalar scale = matrix.cwiseAbs().template maxCoeff<PropagateNaN>();
+ if (!(numext::isfinite)(scale)) {
+ m_isInitialized = true;
+ m_info = InvalidInput;
+ return *this;
+ }
+
+ if(scale==Literal(0)) scale = Literal(1);
+ MatrixX copy;
+ if (m_isTranspose) copy = matrix.adjoint()/scale;
+ else copy = matrix/scale;
+
+ //**** step 1 - Bidiagonalization
+ // FIXME this line involves temporaries
+ internal::UpperBidiagonalization<MatrixX> bid(copy);
+
+ //**** step 2 - Divide & Conquer
+ m_naiveU.setZero();
+ m_naiveV.setZero();
+ // FIXME this line involves a temporary matrix
+ m_computed.topRows(m_diagSize) = bid.bidiagonal().toDenseMatrix().transpose();
+ m_computed.template bottomRows<1>().setZero();
+ divide(0, m_diagSize - 1, 0, 0, 0);
+ if (m_info != Success && m_info != NoConvergence) {
+ m_isInitialized = true;
+ return *this;
+ }
+
+ //**** step 3 - Copy singular values and vectors
+ for (int i=0; i<m_diagSize; i++)
+ {
+ RealScalar a = abs(m_computed.coeff(i, i));
+ m_singularValues.coeffRef(i) = a * scale;
+ if (a<considerZero)
+ {
+ m_nonzeroSingularValues = i;
+ m_singularValues.tail(m_diagSize - i - 1).setZero();
+ break;
+ }
+ else if (i == m_diagSize - 1)
+ {
+ m_nonzeroSingularValues = i + 1;
+ break;
+ }
+ }
+
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+// std::cout << "m_naiveU\n" << m_naiveU << "\n\n";
+// std::cout << "m_naiveV\n" << m_naiveV << "\n\n";
+#endif
+ if(m_isTranspose) copyUV(bid.householderV(), bid.householderU(), m_naiveV, m_naiveU);
+ else copyUV(bid.householderU(), bid.householderV(), m_naiveU, m_naiveV);
+
+ m_isInitialized = true;
+ return *this;
+}// end compute
+
+
+template<typename MatrixType>
+template<typename HouseholderU, typename HouseholderV, typename NaiveU, typename NaiveV>
+void BDCSVD<MatrixType>::copyUV(const HouseholderU &householderU, const HouseholderV &householderV, const NaiveU &naiveU, const NaiveV &naiveV)
+{
+ // Note exchange of U and V: m_matrixU is set from m_naiveV and vice versa
+ if (computeU())
+ {
+ Index Ucols = m_computeThinU ? m_diagSize : householderU.cols();
+ m_matrixU = MatrixX::Identity(householderU.cols(), Ucols);
+ m_matrixU.topLeftCorner(m_diagSize, m_diagSize) = naiveV.template cast<Scalar>().topLeftCorner(m_diagSize, m_diagSize);
+ householderU.applyThisOnTheLeft(m_matrixU); // FIXME this line involves a temporary buffer
+ }
+ if (computeV())
+ {
+ Index Vcols = m_computeThinV ? m_diagSize : householderV.cols();
+ m_matrixV = MatrixX::Identity(householderV.cols(), Vcols);
+ m_matrixV.topLeftCorner(m_diagSize, m_diagSize) = naiveU.template cast<Scalar>().topLeftCorner(m_diagSize, m_diagSize);
+ householderV.applyThisOnTheLeft(m_matrixV); // FIXME this line involves a temporary buffer
+ }
+}
+
+/** \internal
+ * Performs A = A * B exploiting the special structure of the matrix A. Splitting A as:
+ * A = [A1]
+ * [A2]
+ * such that A1.rows()==n1, then we assume that at least half of the columns of A1 and A2 are zeros.
+ * We can thus pack them prior to the the matrix product. However, this is only worth the effort if the matrix is large
+ * enough.
+ */
+template<typename MatrixType>
+void BDCSVD<MatrixType>::structured_update(Block<MatrixXr,Dynamic,Dynamic> A, const MatrixXr &B, Index n1)
+{
+ Index n = A.rows();
+ if(n>100)
+ {
+ // If the matrices are large enough, let's exploit the sparse structure of A by
+ // splitting it in half (wrt n1), and packing the non-zero columns.
+ Index n2 = n - n1;
+ Map<MatrixXr> A1(m_workspace.data() , n1, n);
+ Map<MatrixXr> A2(m_workspace.data()+ n1*n, n2, n);
+ Map<MatrixXr> B1(m_workspace.data()+ n*n, n, n);
+ Map<MatrixXr> B2(m_workspace.data()+2*n*n, n, n);
+ Index k1=0, k2=0;
+ for(Index j=0; j<n; ++j)
+ {
+ if( (A.col(j).head(n1).array()!=Literal(0)).any() )
+ {
+ A1.col(k1) = A.col(j).head(n1);
+ B1.row(k1) = B.row(j);
+ ++k1;
+ }
+ if( (A.col(j).tail(n2).array()!=Literal(0)).any() )
+ {
+ A2.col(k2) = A.col(j).tail(n2);
+ B2.row(k2) = B.row(j);
+ ++k2;
+ }
+ }
+
+ A.topRows(n1).noalias() = A1.leftCols(k1) * B1.topRows(k1);
+ A.bottomRows(n2).noalias() = A2.leftCols(k2) * B2.topRows(k2);
+ }
+ else
+ {
+ Map<MatrixXr,Aligned> tmp(m_workspace.data(),n,n);
+ tmp.noalias() = A*B;
+ A = tmp;
+ }
+}
+
+// The divide algorithm is done "in place", we are always working on subsets of the same matrix. The divide methods takes as argument the
+// place of the submatrix we are currently working on.
+
+//@param firstCol : The Index of the first column of the submatrix of m_computed and for m_naiveU;
+//@param lastCol : The Index of the last column of the submatrix of m_computed and for m_naiveU;
+// lastCol + 1 - firstCol is the size of the submatrix.
+//@param firstRowW : The Index of the first row of the matrix W that we are to change. (see the reference paper section 1 for more information on W)
+//@param firstRowW : Same as firstRowW with the column.
+//@param shift : Each time one takes the left submatrix, one must add 1 to the shift. Why? Because! We actually want the last column of the U submatrix
+// to become the first column (*coeff) and to shift all the other columns to the right. There are more details on the reference paper.
+template<typename MatrixType>
+void BDCSVD<MatrixType>::divide(Eigen::Index firstCol, Eigen::Index lastCol, Eigen::Index firstRowW, Eigen::Index firstColW, Eigen::Index shift)
+{
+ // requires rows = cols + 1;
+ using std::pow;
+ using std::sqrt;
+ using std::abs;
+ const Index n = lastCol - firstCol + 1;
+ const Index k = n/2;
+ const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)();
+ RealScalar alphaK;
+ RealScalar betaK;
+ RealScalar r0;
+ RealScalar lambda, phi, c0, s0;
+ VectorType l, f;
+ // We use the other algorithm which is more efficient for small
+ // matrices.
+ if (n < m_algoswap)
+ {
+ // FIXME this line involves temporaries
+ JacobiSVD<MatrixXr> b(m_computed.block(firstCol, firstCol, n + 1, n), ComputeFullU | (m_compV ? ComputeFullV : 0));
+ m_info = b.info();
+ if (m_info != Success && m_info != NoConvergence) return;
+ if (m_compU)
+ m_naiveU.block(firstCol, firstCol, n + 1, n + 1).real() = b.matrixU();
+ else
+ {
+ m_naiveU.row(0).segment(firstCol, n + 1).real() = b.matrixU().row(0);
+ m_naiveU.row(1).segment(firstCol, n + 1).real() = b.matrixU().row(n);
+ }
+ if (m_compV) m_naiveV.block(firstRowW, firstColW, n, n).real() = b.matrixV();
+ m_computed.block(firstCol + shift, firstCol + shift, n + 1, n).setZero();
+ m_computed.diagonal().segment(firstCol + shift, n) = b.singularValues().head(n);
+ return;
+ }
+ // We use the divide and conquer algorithm
+ alphaK = m_computed(firstCol + k, firstCol + k);
+ betaK = m_computed(firstCol + k + 1, firstCol + k);
+ // The divide must be done in that order in order to have good results. Divide change the data inside the submatrices
+ // and the divide of the right submatrice reads one column of the left submatrice. That's why we need to treat the
+ // right submatrix before the left one.
+ divide(k + 1 + firstCol, lastCol, k + 1 + firstRowW, k + 1 + firstColW, shift);
+ if (m_info != Success && m_info != NoConvergence) return;
+ divide(firstCol, k - 1 + firstCol, firstRowW, firstColW + 1, shift + 1);
+ if (m_info != Success && m_info != NoConvergence) return;
+
+ if (m_compU)
+ {
+ lambda = m_naiveU(firstCol + k, firstCol + k);
+ phi = m_naiveU(firstCol + k + 1, lastCol + 1);
+ }
+ else
+ {
+ lambda = m_naiveU(1, firstCol + k);
+ phi = m_naiveU(0, lastCol + 1);
+ }
+ r0 = sqrt((abs(alphaK * lambda) * abs(alphaK * lambda)) + abs(betaK * phi) * abs(betaK * phi));
+ if (m_compU)
+ {
+ l = m_naiveU.row(firstCol + k).segment(firstCol, k);
+ f = m_naiveU.row(firstCol + k + 1).segment(firstCol + k + 1, n - k - 1);
+ }
+ else
+ {
+ l = m_naiveU.row(1).segment(firstCol, k);
+ f = m_naiveU.row(0).segment(firstCol + k + 1, n - k - 1);
+ }
+ if (m_compV) m_naiveV(firstRowW+k, firstColW) = Literal(1);
+ if (r0<considerZero)
+ {
+ c0 = Literal(1);
+ s0 = Literal(0);
+ }
+ else
+ {
+ c0 = alphaK * lambda / r0;
+ s0 = betaK * phi / r0;
+ }
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(m_naiveU.allFinite());
+ assert(m_naiveV.allFinite());
+ assert(m_computed.allFinite());
+#endif
+
+ if (m_compU)
+ {
+ MatrixXr q1 (m_naiveU.col(firstCol + k).segment(firstCol, k + 1));
+ // we shiftW Q1 to the right
+ for (Index i = firstCol + k - 1; i >= firstCol; i--)
+ m_naiveU.col(i + 1).segment(firstCol, k + 1) = m_naiveU.col(i).segment(firstCol, k + 1);
+ // we shift q1 at the left with a factor c0
+ m_naiveU.col(firstCol).segment( firstCol, k + 1) = (q1 * c0);
+ // last column = q1 * - s0
+ m_naiveU.col(lastCol + 1).segment(firstCol, k + 1) = (q1 * ( - s0));
+ // first column = q2 * s0
+ m_naiveU.col(firstCol).segment(firstCol + k + 1, n - k) = m_naiveU.col(lastCol + 1).segment(firstCol + k + 1, n - k) * s0;
+ // q2 *= c0
+ m_naiveU.col(lastCol + 1).segment(firstCol + k + 1, n - k) *= c0;
+ }
+ else
+ {
+ RealScalar q1 = m_naiveU(0, firstCol + k);
+ // we shift Q1 to the right
+ for (Index i = firstCol + k - 1; i >= firstCol; i--)
+ m_naiveU(0, i + 1) = m_naiveU(0, i);
+ // we shift q1 at the left with a factor c0
+ m_naiveU(0, firstCol) = (q1 * c0);
+ // last column = q1 * - s0
+ m_naiveU(0, lastCol + 1) = (q1 * ( - s0));
+ // first column = q2 * s0
+ m_naiveU(1, firstCol) = m_naiveU(1, lastCol + 1) *s0;
+ // q2 *= c0
+ m_naiveU(1, lastCol + 1) *= c0;
+ m_naiveU.row(1).segment(firstCol + 1, k).setZero();
+ m_naiveU.row(0).segment(firstCol + k + 1, n - k - 1).setZero();
+ }
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(m_naiveU.allFinite());
+ assert(m_naiveV.allFinite());
+ assert(m_computed.allFinite());
+#endif
+
+ m_computed(firstCol + shift, firstCol + shift) = r0;
+ m_computed.col(firstCol + shift).segment(firstCol + shift + 1, k) = alphaK * l.transpose().real();
+ m_computed.col(firstCol + shift).segment(firstCol + shift + k + 1, n - k - 1) = betaK * f.transpose().real();
+
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ ArrayXr tmp1 = (m_computed.block(firstCol+shift, firstCol+shift, n, n)).jacobiSvd().singularValues();
+#endif
+ // Second part: try to deflate singular values in combined matrix
+ deflation(firstCol, lastCol, k, firstRowW, firstColW, shift);
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ ArrayXr tmp2 = (m_computed.block(firstCol+shift, firstCol+shift, n, n)).jacobiSvd().singularValues();
+ std::cout << "\n\nj1 = " << tmp1.transpose().format(bdcsvdfmt) << "\n";
+ std::cout << "j2 = " << tmp2.transpose().format(bdcsvdfmt) << "\n\n";
+ std::cout << "err: " << ((tmp1-tmp2).abs()>1e-12*tmp2.abs()).transpose() << "\n";
+ static int count = 0;
+ std::cout << "# " << ++count << "\n\n";
+ assert((tmp1-tmp2).matrix().norm() < 1e-14*tmp2.matrix().norm());
+// assert(count<681);
+// assert(((tmp1-tmp2).abs()<1e-13*tmp2.abs()).all());
+#endif
+
+ // Third part: compute SVD of combined matrix
+ MatrixXr UofSVD, VofSVD;
+ VectorType singVals;
+ computeSVDofM(firstCol + shift, n, UofSVD, singVals, VofSVD);
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(UofSVD.allFinite());
+ assert(VofSVD.allFinite());
+#endif
+
+ if (m_compU)
+ structured_update(m_naiveU.block(firstCol, firstCol, n + 1, n + 1), UofSVD, (n+2)/2);
+ else
+ {
+ Map<Matrix<RealScalar,2,Dynamic>,Aligned> tmp(m_workspace.data(),2,n+1);
+ tmp.noalias() = m_naiveU.middleCols(firstCol, n+1) * UofSVD;
+ m_naiveU.middleCols(firstCol, n + 1) = tmp;
+ }
+
+ if (m_compV) structured_update(m_naiveV.block(firstRowW, firstColW, n, n), VofSVD, (n+1)/2);
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(m_naiveU.allFinite());
+ assert(m_naiveV.allFinite());
+ assert(m_computed.allFinite());
+#endif
+
+ m_computed.block(firstCol + shift, firstCol + shift, n, n).setZero();
+ m_computed.block(firstCol + shift, firstCol + shift, n, n).diagonal() = singVals;
+}// end divide
+
+// Compute SVD of m_computed.block(firstCol, firstCol, n + 1, n); this block only has non-zeros in
+// the first column and on the diagonal and has undergone deflation, so diagonal is in increasing
+// order except for possibly the (0,0) entry. The computed SVD is stored U, singVals and V, except
+// that if m_compV is false, then V is not computed. Singular values are sorted in decreasing order.
+//
+// TODO Opportunities for optimization: better root finding algo, better stopping criterion, better
+// handling of round-off errors, be consistent in ordering
+// For instance, to solve the secular equation using FMM, see http://www.stat.uchicago.edu/~lekheng/courses/302/classics/greengard-rokhlin.pdf
+template <typename MatrixType>
+void BDCSVD<MatrixType>::computeSVDofM(Eigen::Index firstCol, Eigen::Index n, MatrixXr& U, VectorType& singVals, MatrixXr& V)
+{
+ const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)();
+ using std::abs;
+ ArrayRef col0 = m_computed.col(firstCol).segment(firstCol, n);
+ m_workspace.head(n) = m_computed.block(firstCol, firstCol, n, n).diagonal();
+ ArrayRef diag = m_workspace.head(n);
+ diag(0) = Literal(0);
+
+ // Allocate space for singular values and vectors
+ singVals.resize(n);
+ U.resize(n+1, n+1);
+ if (m_compV) V.resize(n, n);
+
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ if (col0.hasNaN() || diag.hasNaN())
+ std::cout << "\n\nHAS NAN\n\n";
+#endif
+
+ // Many singular values might have been deflated, the zero ones have been moved to the end,
+ // but others are interleaved and we must ignore them at this stage.
+ // To this end, let's compute a permutation skipping them:
+ Index actual_n = n;
+ while(actual_n>1 && diag(actual_n-1)==Literal(0)) {--actual_n; eigen_internal_assert(col0(actual_n)==Literal(0)); }
+ Index m = 0; // size of the deflated problem
+ for(Index k=0;k<actual_n;++k)
+ if(abs(col0(k))>considerZero)
+ m_workspaceI(m++) = k;
+ Map<ArrayXi> perm(m_workspaceI.data(),m);
+
+ Map<ArrayXr> shifts(m_workspace.data()+1*n, n);
+ Map<ArrayXr> mus(m_workspace.data()+2*n, n);
+ Map<ArrayXr> zhat(m_workspace.data()+3*n, n);
+
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "computeSVDofM using:\n";
+ std::cout << " z: " << col0.transpose() << "\n";
+ std::cout << " d: " << diag.transpose() << "\n";
+#endif
+
+ // Compute singVals, shifts, and mus
+ computeSingVals(col0, diag, perm, singVals, shifts, mus);
+
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << " j: " << (m_computed.block(firstCol, firstCol, n, n)).jacobiSvd().singularValues().transpose().reverse() << "\n\n";
+ std::cout << " sing-val: " << singVals.transpose() << "\n";
+ std::cout << " mu: " << mus.transpose() << "\n";
+ std::cout << " shift: " << shifts.transpose() << "\n";
+
+ {
+ std::cout << "\n\n mus: " << mus.head(actual_n).transpose() << "\n\n";
+ std::cout << " check1 (expect0) : " << ((singVals.array()-(shifts+mus)) / singVals.array()).head(actual_n).transpose() << "\n\n";
+ assert((((singVals.array()-(shifts+mus)) / singVals.array()).head(actual_n) >= 0).all());
+ std::cout << " check2 (>0) : " << ((singVals.array()-diag) / singVals.array()).head(actual_n).transpose() << "\n\n";
+ assert((((singVals.array()-diag) / singVals.array()).head(actual_n) >= 0).all());
+ }
+#endif
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(singVals.allFinite());
+ assert(mus.allFinite());
+ assert(shifts.allFinite());
+#endif
+
+ // Compute zhat
+ perturbCol0(col0, diag, perm, singVals, shifts, mus, zhat);
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << " zhat: " << zhat.transpose() << "\n";
+#endif
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(zhat.allFinite());
+#endif
+
+ computeSingVecs(zhat, diag, perm, singVals, shifts, mus, U, V);
+
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "U^T U: " << (U.transpose() * U - MatrixXr(MatrixXr::Identity(U.cols(),U.cols()))).norm() << "\n";
+ std::cout << "V^T V: " << (V.transpose() * V - MatrixXr(MatrixXr::Identity(V.cols(),V.cols()))).norm() << "\n";
+#endif
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(m_naiveU.allFinite());
+ assert(m_naiveV.allFinite());
+ assert(m_computed.allFinite());
+ assert(U.allFinite());
+ assert(V.allFinite());
+// assert((U.transpose() * U - MatrixXr(MatrixXr::Identity(U.cols(),U.cols()))).norm() < 100*NumTraits<RealScalar>::epsilon() * n);
+// assert((V.transpose() * V - MatrixXr(MatrixXr::Identity(V.cols(),V.cols()))).norm() < 100*NumTraits<RealScalar>::epsilon() * n);
+#endif
+
+ // Because of deflation, the singular values might not be completely sorted.
+ // Fortunately, reordering them is a O(n) problem
+ for(Index i=0; i<actual_n-1; ++i)
+ {
+ if(singVals(i)>singVals(i+1))
+ {
+ using std::swap;
+ swap(singVals(i),singVals(i+1));
+ U.col(i).swap(U.col(i+1));
+ if(m_compV) V.col(i).swap(V.col(i+1));
+ }
+ }
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ {
+ bool singular_values_sorted = (((singVals.segment(1,actual_n-1)-singVals.head(actual_n-1))).array() >= 0).all();
+ if(!singular_values_sorted)
+ std::cout << "Singular values are not sorted: " << singVals.segment(1,actual_n).transpose() << "\n";
+ assert(singular_values_sorted);
+ }
+#endif
+
+ // Reverse order so that singular values in increased order
+ // Because of deflation, the zeros singular-values are already at the end
+ singVals.head(actual_n).reverseInPlace();
+ U.leftCols(actual_n).rowwise().reverseInPlace();
+ if (m_compV) V.leftCols(actual_n).rowwise().reverseInPlace();
+
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ JacobiSVD<MatrixXr> jsvd(m_computed.block(firstCol, firstCol, n, n) );
+ std::cout << " * j: " << jsvd.singularValues().transpose() << "\n\n";
+ std::cout << " * sing-val: " << singVals.transpose() << "\n";
+// std::cout << " * err: " << ((jsvd.singularValues()-singVals)>1e-13*singVals.norm()).transpose() << "\n";
+#endif
+}
+
+template <typename MatrixType>
+typename BDCSVD<MatrixType>::RealScalar BDCSVD<MatrixType>::secularEq(RealScalar mu, const ArrayRef& col0, const ArrayRef& diag, const IndicesRef &perm, const ArrayRef& diagShifted, RealScalar shift)
+{
+ Index m = perm.size();
+ RealScalar res = Literal(1);
+ for(Index i=0; i<m; ++i)
+ {
+ Index j = perm(i);
+ // The following expression could be rewritten to involve only a single division,
+ // but this would make the expression more sensitive to overflow.
+ res += (col0(j) / (diagShifted(j) - mu)) * (col0(j) / (diag(j) + shift + mu));
+ }
+ return res;
+
+}
+
+template <typename MatrixType>
+void BDCSVD<MatrixType>::computeSingVals(const ArrayRef& col0, const ArrayRef& diag, const IndicesRef &perm,
+ VectorType& singVals, ArrayRef shifts, ArrayRef mus)
+{
+ using std::abs;
+ using std::swap;
+ using std::sqrt;
+
+ Index n = col0.size();
+ Index actual_n = n;
+ // Note that here actual_n is computed based on col0(i)==0 instead of diag(i)==0 as above
+ // because 1) we have diag(i)==0 => col0(i)==0 and 2) if col0(i)==0, then diag(i) is already a singular value.
+ while(actual_n>1 && col0(actual_n-1)==Literal(0)) --actual_n;
+
+ for (Index k = 0; k < n; ++k)
+ {
+ if (col0(k) == Literal(0) || actual_n==1)
+ {
+ // if col0(k) == 0, then entry is deflated, so singular value is on diagonal
+ // if actual_n==1, then the deflated problem is already diagonalized
+ singVals(k) = k==0 ? col0(0) : diag(k);
+ mus(k) = Literal(0);
+ shifts(k) = k==0 ? col0(0) : diag(k);
+ continue;
+ }
+
+ // otherwise, use secular equation to find singular value
+ RealScalar left = diag(k);
+ RealScalar right; // was: = (k != actual_n-1) ? diag(k+1) : (diag(actual_n-1) + col0.matrix().norm());
+ if(k==actual_n-1)
+ right = (diag(actual_n-1) + col0.matrix().norm());
+ else
+ {
+ // Skip deflated singular values,
+ // recall that at this stage we assume that z[j]!=0 and all entries for which z[j]==0 have been put aside.
+ // This should be equivalent to using perm[]
+ Index l = k+1;
+ while(col0(l)==Literal(0)) { ++l; eigen_internal_assert(l<actual_n); }
+ right = diag(l);
+ }
+
+ // first decide whether it's closer to the left end or the right end
+ RealScalar mid = left + (right-left) / Literal(2);
+ RealScalar fMid = secularEq(mid, col0, diag, perm, diag, Literal(0));
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "right-left = " << right-left << "\n";
+// std::cout << "fMid = " << fMid << " " << secularEq(mid-left, col0, diag, perm, ArrayXr(diag-left), left)
+// << " " << secularEq(mid-right, col0, diag, perm, ArrayXr(diag-right), right) << "\n";
+ std::cout << " = " << secularEq(left+RealScalar(0.000001)*(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.1) *(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.2) *(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.3) *(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.4) *(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.49) *(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.5) *(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.51) *(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.6) *(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.7) *(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.8) *(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.9) *(right-left), col0, diag, perm, diag, 0)
+ << " " << secularEq(left+RealScalar(0.999999)*(right-left), col0, diag, perm, diag, 0) << "\n";
+#endif
+ RealScalar shift = (k == actual_n-1 || fMid > Literal(0)) ? left : right;
+
+ // measure everything relative to shift
+ Map<ArrayXr> diagShifted(m_workspace.data()+4*n, n);
+ diagShifted = diag - shift;
+
+ if(k!=actual_n-1)
+ {
+ // check that after the shift, f(mid) is still negative:
+ RealScalar midShifted = (right - left) / RealScalar(2);
+ if(shift==right)
+ midShifted = -midShifted;
+ RealScalar fMidShifted = secularEq(midShifted, col0, diag, perm, diagShifted, shift);
+ if(fMidShifted>0)
+ {
+ // fMid was erroneous, fix it:
+ shift = fMidShifted > Literal(0) ? left : right;
+ diagShifted = diag - shift;
+ }
+ }
+
+ // initial guess
+ RealScalar muPrev, muCur;
+ if (shift == left)
+ {
+ muPrev = (right - left) * RealScalar(0.1);
+ if (k == actual_n-1) muCur = right - left;
+ else muCur = (right - left) * RealScalar(0.5);
+ }
+ else
+ {
+ muPrev = -(right - left) * RealScalar(0.1);
+ muCur = -(right - left) * RealScalar(0.5);
+ }
+
+ RealScalar fPrev = secularEq(muPrev, col0, diag, perm, diagShifted, shift);
+ RealScalar fCur = secularEq(muCur, col0, diag, perm, diagShifted, shift);
+ if (abs(fPrev) < abs(fCur))
+ {
+ swap(fPrev, fCur);
+ swap(muPrev, muCur);
+ }
+
+ // rational interpolation: fit a function of the form a / mu + b through the two previous
+ // iterates and use its zero to compute the next iterate
+ bool useBisection = fPrev*fCur>Literal(0);
+ while (fCur!=Literal(0) && abs(muCur - muPrev) > Literal(8) * NumTraits<RealScalar>::epsilon() * numext::maxi<RealScalar>(abs(muCur), abs(muPrev)) && abs(fCur - fPrev)>NumTraits<RealScalar>::epsilon() && !useBisection)
+ {
+ ++m_numIters;
+
+ // Find a and b such that the function f(mu) = a / mu + b matches the current and previous samples.
+ RealScalar a = (fCur - fPrev) / (Literal(1)/muCur - Literal(1)/muPrev);
+ RealScalar b = fCur - a / muCur;
+ // And find mu such that f(mu)==0:
+ RealScalar muZero = -a/b;
+ RealScalar fZero = secularEq(muZero, col0, diag, perm, diagShifted, shift);
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert((numext::isfinite)(fZero));
+#endif
+
+ muPrev = muCur;
+ fPrev = fCur;
+ muCur = muZero;
+ fCur = fZero;
+
+ if (shift == left && (muCur < Literal(0) || muCur > right - left)) useBisection = true;
+ if (shift == right && (muCur < -(right - left) || muCur > Literal(0))) useBisection = true;
+ if (abs(fCur)>abs(fPrev)) useBisection = true;
+ }
+
+ // fall back on bisection method if rational interpolation did not work
+ if (useBisection)
+ {
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "useBisection for k = " << k << ", actual_n = " << actual_n << "\n";
+#endif
+ RealScalar leftShifted, rightShifted;
+ if (shift == left)
+ {
+ // to avoid overflow, we must have mu > max(real_min, |z(k)|/sqrt(real_max)),
+ // the factor 2 is to be more conservative
+ leftShifted = numext::maxi<RealScalar>( (std::numeric_limits<RealScalar>::min)(), Literal(2) * abs(col0(k)) / sqrt((std::numeric_limits<RealScalar>::max)()) );
+
+ // check that we did it right:
+ eigen_internal_assert( (numext::isfinite)( (col0(k)/leftShifted)*(col0(k)/(diag(k)+shift+leftShifted)) ) );
+ // I don't understand why the case k==0 would be special there:
+ // if (k == 0) rightShifted = right - left; else
+ rightShifted = (k==actual_n-1) ? right : ((right - left) * RealScalar(0.51)); // theoretically we can take 0.5, but let's be safe
+ }
+ else
+ {
+ leftShifted = -(right - left) * RealScalar(0.51);
+ if(k+1<n)
+ rightShifted = -numext::maxi<RealScalar>( (std::numeric_limits<RealScalar>::min)(), abs(col0(k+1)) / sqrt((std::numeric_limits<RealScalar>::max)()) );
+ else
+ rightShifted = -(std::numeric_limits<RealScalar>::min)();
+ }
+
+ RealScalar fLeft = secularEq(leftShifted, col0, diag, perm, diagShifted, shift);
+ eigen_internal_assert(fLeft<Literal(0));
+
+#if defined EIGEN_INTERNAL_DEBUGGING || defined EIGEN_BDCSVD_SANITY_CHECKS
+ RealScalar fRight = secularEq(rightShifted, col0, diag, perm, diagShifted, shift);
+#endif
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ if(!(numext::isfinite)(fLeft))
+ std::cout << "f(" << leftShifted << ") =" << fLeft << " ; " << left << " " << shift << " " << right << "\n";
+ assert((numext::isfinite)(fLeft));
+
+ if(!(numext::isfinite)(fRight))
+ std::cout << "f(" << rightShifted << ") =" << fRight << " ; " << left << " " << shift << " " << right << "\n";
+ // assert((numext::isfinite)(fRight));
+#endif
+
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ if(!(fLeft * fRight<0))
+ {
+ std::cout << "f(leftShifted) using leftShifted=" << leftShifted << " ; diagShifted(1:10):" << diagShifted.head(10).transpose() << "\n ; "
+ << "left==shift=" << bool(left==shift) << " ; left-shift = " << (left-shift) << "\n";
+ std::cout << "k=" << k << ", " << fLeft << " * " << fRight << " == " << fLeft * fRight << " ; "
+ << "[" << left << " .. " << right << "] -> [" << leftShifted << " " << rightShifted << "], shift=" << shift
+ << " , f(right)=" << secularEq(0, col0, diag, perm, diagShifted, shift)
+ << " == " << secularEq(right, col0, diag, perm, diag, 0) << " == " << fRight << "\n";
+ }
+#endif
+ eigen_internal_assert(fLeft * fRight < Literal(0));
+
+ if(fLeft<Literal(0))
+ {
+ while (rightShifted - leftShifted > Literal(2) * NumTraits<RealScalar>::epsilon() * numext::maxi<RealScalar>(abs(leftShifted), abs(rightShifted)))
+ {
+ RealScalar midShifted = (leftShifted + rightShifted) / Literal(2);
+ fMid = secularEq(midShifted, col0, diag, perm, diagShifted, shift);
+ eigen_internal_assert((numext::isfinite)(fMid));
+
+ if (fLeft * fMid < Literal(0))
+ {
+ rightShifted = midShifted;
+ }
+ else
+ {
+ leftShifted = midShifted;
+ fLeft = fMid;
+ }
+ }
+ muCur = (leftShifted + rightShifted) / Literal(2);
+ }
+ else
+ {
+ // We have a problem as shifting on the left or right give either a positive or negative value
+ // at the middle of [left,right]...
+ // Instead fo abbording or entering an infinite loop,
+ // let's just use the middle as the estimated zero-crossing:
+ muCur = (right - left) * RealScalar(0.5);
+ if(shift == right)
+ muCur = -muCur;
+ }
+ }
+
+ singVals[k] = shift + muCur;
+ shifts[k] = shift;
+ mus[k] = muCur;
+
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ if(k+1<n)
+ std::cout << "found " << singVals[k] << " == " << shift << " + " << muCur << " from " << diag(k) << " .. " << diag(k+1) << "\n";
+#endif
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(k==0 || singVals[k]>=singVals[k-1]);
+ assert(singVals[k]>=diag(k));
+#endif
+
+ // perturb singular value slightly if it equals diagonal entry to avoid division by zero later
+ // (deflation is supposed to avoid this from happening)
+ // - this does no seem to be necessary anymore -
+// if (singVals[k] == left) singVals[k] *= 1 + NumTraits<RealScalar>::epsilon();
+// if (singVals[k] == right) singVals[k] *= 1 - NumTraits<RealScalar>::epsilon();
+ }
+}
+
+
+// zhat is perturbation of col0 for which singular vectors can be computed stably (see Section 3.1)
+template <typename MatrixType>
+void BDCSVD<MatrixType>::perturbCol0
+ (const ArrayRef& col0, const ArrayRef& diag, const IndicesRef &perm, const VectorType& singVals,
+ const ArrayRef& shifts, const ArrayRef& mus, ArrayRef zhat)
+{
+ using std::sqrt;
+ Index n = col0.size();
+ Index m = perm.size();
+ if(m==0)
+ {
+ zhat.setZero();
+ return;
+ }
+ Index lastIdx = perm(m-1);
+ // The offset permits to skip deflated entries while computing zhat
+ for (Index k = 0; k < n; ++k)
+ {
+ if (col0(k) == Literal(0)) // deflated
+ zhat(k) = Literal(0);
+ else
+ {
+ // see equation (3.6)
+ RealScalar dk = diag(k);
+ RealScalar prod = (singVals(lastIdx) + dk) * (mus(lastIdx) + (shifts(lastIdx) - dk));
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ if(prod<0) {
+ std::cout << "k = " << k << " ; z(k)=" << col0(k) << ", diag(k)=" << dk << "\n";
+ std::cout << "prod = " << "(" << singVals(lastIdx) << " + " << dk << ") * (" << mus(lastIdx) << " + (" << shifts(lastIdx) << " - " << dk << "))" << "\n";
+ std::cout << " = " << singVals(lastIdx) + dk << " * " << mus(lastIdx) + (shifts(lastIdx) - dk) << "\n";
+ }
+ assert(prod>=0);
+#endif
+
+ for(Index l = 0; l<m; ++l)
+ {
+ Index i = perm(l);
+ if(i!=k)
+ {
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ if(i>=k && (l==0 || l-1>=m))
+ {
+ std::cout << "Error in perturbCol0\n";
+ std::cout << " " << k << "/" << n << " " << l << "/" << m << " " << i << "/" << n << " ; " << col0(k) << " " << diag(k) << " " << "\n";
+ std::cout << " " <<diag(i) << "\n";
+ Index j = (i<k /*|| l==0*/) ? i : perm(l-1);
+ std::cout << " " << "j=" << j << "\n";
+ }
+#endif
+ Index j = i<k ? i : perm(l-1);
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ if(!(dk!=Literal(0) || diag(i)!=Literal(0)))
+ {
+ std::cout << "k=" << k << ", i=" << i << ", l=" << l << ", perm.size()=" << perm.size() << "\n";
+ }
+ assert(dk!=Literal(0) || diag(i)!=Literal(0));
+#endif
+ prod *= ((singVals(j)+dk) / ((diag(i)+dk))) * ((mus(j)+(shifts(j)-dk)) / ((diag(i)-dk)));
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(prod>=0);
+#endif
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ if(i!=k && numext::abs(((singVals(j)+dk)*(mus(j)+(shifts(j)-dk)))/((diag(i)+dk)*(diag(i)-dk)) - 1) > 0.9 )
+ std::cout << " " << ((singVals(j)+dk)*(mus(j)+(shifts(j)-dk)))/((diag(i)+dk)*(diag(i)-dk)) << " == (" << (singVals(j)+dk) << " * " << (mus(j)+(shifts(j)-dk))
+ << ") / (" << (diag(i)+dk) << " * " << (diag(i)-dk) << ")\n";
+#endif
+ }
+ }
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "zhat(" << k << ") = sqrt( " << prod << ") ; " << (singVals(lastIdx) + dk) << " * " << mus(lastIdx) + shifts(lastIdx) << " - " << dk << "\n";
+#endif
+ RealScalar tmp = sqrt(prod);
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert((numext::isfinite)(tmp));
+#endif
+ zhat(k) = col0(k) > Literal(0) ? RealScalar(tmp) : RealScalar(-tmp);
+ }
+ }
+}
+
+// compute singular vectors
+template <typename MatrixType>
+void BDCSVD<MatrixType>::computeSingVecs
+ (const ArrayRef& zhat, const ArrayRef& diag, const IndicesRef &perm, const VectorType& singVals,
+ const ArrayRef& shifts, const ArrayRef& mus, MatrixXr& U, MatrixXr& V)
+{
+ Index n = zhat.size();
+ Index m = perm.size();
+
+ for (Index k = 0; k < n; ++k)
+ {
+ if (zhat(k) == Literal(0))
+ {
+ U.col(k) = VectorType::Unit(n+1, k);
+ if (m_compV) V.col(k) = VectorType::Unit(n, k);
+ }
+ else
+ {
+ U.col(k).setZero();
+ for(Index l=0;l<m;++l)
+ {
+ Index i = perm(l);
+ U(i,k) = zhat(i)/(((diag(i) - shifts(k)) - mus(k)) )/( (diag(i) + singVals[k]));
+ }
+ U(n,k) = Literal(0);
+ U.col(k).normalize();
+
+ if (m_compV)
+ {
+ V.col(k).setZero();
+ for(Index l=1;l<m;++l)
+ {
+ Index i = perm(l);
+ V(i,k) = diag(i) * zhat(i) / (((diag(i) - shifts(k)) - mus(k)) )/( (diag(i) + singVals[k]));
+ }
+ V(0,k) = Literal(-1);
+ V.col(k).normalize();
+ }
+ }
+ }
+ U.col(n) = VectorType::Unit(n+1, n);
+}
+
+
+// page 12_13
+// i >= 1, di almost null and zi non null.
+// We use a rotation to zero out zi applied to the left of M
+template <typename MatrixType>
+void BDCSVD<MatrixType>::deflation43(Eigen::Index firstCol, Eigen::Index shift, Eigen::Index i, Eigen::Index size)
+{
+ using std::abs;
+ using std::sqrt;
+ using std::pow;
+ Index start = firstCol + shift;
+ RealScalar c = m_computed(start, start);
+ RealScalar s = m_computed(start+i, start);
+ RealScalar r = numext::hypot(c,s);
+ if (r == Literal(0))
+ {
+ m_computed(start+i, start+i) = Literal(0);
+ return;
+ }
+ m_computed(start,start) = r;
+ m_computed(start+i, start) = Literal(0);
+ m_computed(start+i, start+i) = Literal(0);
+
+ JacobiRotation<RealScalar> J(c/r,-s/r);
+ if (m_compU) m_naiveU.middleRows(firstCol, size+1).applyOnTheRight(firstCol, firstCol+i, J);
+ else m_naiveU.applyOnTheRight(firstCol, firstCol+i, J);
+}// end deflation 43
+
+
+// page 13
+// i,j >= 1, i!=j and |di - dj| < epsilon * norm2(M)
+// We apply two rotations to have zj = 0;
+// TODO deflation44 is still broken and not properly tested
+template <typename MatrixType>
+void BDCSVD<MatrixType>::deflation44(Eigen::Index firstColu , Eigen::Index firstColm, Eigen::Index firstRowW, Eigen::Index firstColW, Eigen::Index i, Eigen::Index j, Eigen::Index size)
+{
+ using std::abs;
+ using std::sqrt;
+ using std::conj;
+ using std::pow;
+ RealScalar c = m_computed(firstColm+i, firstColm);
+ RealScalar s = m_computed(firstColm+j, firstColm);
+ RealScalar r = sqrt(numext::abs2(c) + numext::abs2(s));
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "deflation 4.4: " << i << "," << j << " -> " << c << " " << s << " " << r << " ; "
+ << m_computed(firstColm + i-1, firstColm) << " "
+ << m_computed(firstColm + i, firstColm) << " "
+ << m_computed(firstColm + i+1, firstColm) << " "
+ << m_computed(firstColm + i+2, firstColm) << "\n";
+ std::cout << m_computed(firstColm + i-1, firstColm + i-1) << " "
+ << m_computed(firstColm + i, firstColm+i) << " "
+ << m_computed(firstColm + i+1, firstColm+i+1) << " "
+ << m_computed(firstColm + i+2, firstColm+i+2) << "\n";
+#endif
+ if (r==Literal(0))
+ {
+ m_computed(firstColm + i, firstColm + i) = m_computed(firstColm + j, firstColm + j);
+ return;
+ }
+ c/=r;
+ s/=r;
+ m_computed(firstColm + i, firstColm) = r;
+ m_computed(firstColm + j, firstColm + j) = m_computed(firstColm + i, firstColm + i);
+ m_computed(firstColm + j, firstColm) = Literal(0);
+
+ JacobiRotation<RealScalar> J(c,-s);
+ if (m_compU) m_naiveU.middleRows(firstColu, size+1).applyOnTheRight(firstColu + i, firstColu + j, J);
+ else m_naiveU.applyOnTheRight(firstColu+i, firstColu+j, J);
+ if (m_compV) m_naiveV.middleRows(firstRowW, size).applyOnTheRight(firstColW + i, firstColW + j, J);
+}// end deflation 44
+
+
+// acts on block from (firstCol+shift, firstCol+shift) to (lastCol+shift, lastCol+shift) [inclusive]
+template <typename MatrixType>
+void BDCSVD<MatrixType>::deflation(Eigen::Index firstCol, Eigen::Index lastCol, Eigen::Index k, Eigen::Index firstRowW, Eigen::Index firstColW, Eigen::Index shift)
+{
+ using std::sqrt;
+ using std::abs;
+ const Index length = lastCol + 1 - firstCol;
+
+ Block<MatrixXr,Dynamic,1> col0(m_computed, firstCol+shift, firstCol+shift, length, 1);
+ Diagonal<MatrixXr> fulldiag(m_computed);
+ VectorBlock<Diagonal<MatrixXr>,Dynamic> diag(fulldiag, firstCol+shift, length);
+
+ const RealScalar considerZero = (std::numeric_limits<RealScalar>::min)();
+ RealScalar maxDiag = diag.tail((std::max)(Index(1),length-1)).cwiseAbs().maxCoeff();
+ RealScalar epsilon_strict = numext::maxi<RealScalar>(considerZero,NumTraits<RealScalar>::epsilon() * maxDiag);
+ RealScalar epsilon_coarse = Literal(8) * NumTraits<RealScalar>::epsilon() * numext::maxi<RealScalar>(col0.cwiseAbs().maxCoeff(), maxDiag);
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(m_naiveU.allFinite());
+ assert(m_naiveV.allFinite());
+ assert(m_computed.allFinite());
+#endif
+
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "\ndeflate:" << diag.head(k+1).transpose() << " | " << diag.segment(k+1,length-k-1).transpose() << "\n";
+#endif
+
+ //condition 4.1
+ if (diag(0) < epsilon_coarse)
+ {
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "deflation 4.1, because " << diag(0) << " < " << epsilon_coarse << "\n";
+#endif
+ diag(0) = epsilon_coarse;
+ }
+
+ //condition 4.2
+ for (Index i=1;i<length;++i)
+ if (abs(col0(i)) < epsilon_strict)
+ {
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "deflation 4.2, set z(" << i << ") to zero because " << abs(col0(i)) << " < " << epsilon_strict << " (diag(" << i << ")=" << diag(i) << ")\n";
+#endif
+ col0(i) = Literal(0);
+ }
+
+ //condition 4.3
+ for (Index i=1;i<length; i++)
+ if (diag(i) < epsilon_coarse)
+ {
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "deflation 4.3, cancel z(" << i << ")=" << col0(i) << " because diag(" << i << ")=" << diag(i) << " < " << epsilon_coarse << "\n";
+#endif
+ deflation43(firstCol, shift, i, length);
+ }
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(m_naiveU.allFinite());
+ assert(m_naiveV.allFinite());
+ assert(m_computed.allFinite());
+#endif
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "to be sorted: " << diag.transpose() << "\n\n";
+ std::cout << " : " << col0.transpose() << "\n\n";
+#endif
+ {
+ // Check for total deflation
+ // If we have a total deflation, then we have to consider col0(0)==diag(0) as a singular value during sorting
+ bool total_deflation = (col0.tail(length-1).array()<considerZero).all();
+
+ // Sort the diagonal entries, since diag(1:k-1) and diag(k:length) are already sorted, let's do a sorted merge.
+ // First, compute the respective permutation.
+ Index *permutation = m_workspaceI.data();
+ {
+ permutation[0] = 0;
+ Index p = 1;
+
+ // Move deflated diagonal entries at the end.
+ for(Index i=1; i<length; ++i)
+ if(abs(diag(i))<considerZero)
+ permutation[p++] = i;
+
+ Index i=1, j=k+1;
+ for( ; p < length; ++p)
+ {
+ if (i > k) permutation[p] = j++;
+ else if (j >= length) permutation[p] = i++;
+ else if (diag(i) < diag(j)) permutation[p] = j++;
+ else permutation[p] = i++;
+ }
+ }
+
+ // If we have a total deflation, then we have to insert diag(0) at the right place
+ if(total_deflation)
+ {
+ for(Index i=1; i<length; ++i)
+ {
+ Index pi = permutation[i];
+ if(abs(diag(pi))<considerZero || diag(0)<diag(pi))
+ permutation[i-1] = permutation[i];
+ else
+ {
+ permutation[i-1] = 0;
+ break;
+ }
+ }
+ }
+
+ // Current index of each col, and current column of each index
+ Index *realInd = m_workspaceI.data()+length;
+ Index *realCol = m_workspaceI.data()+2*length;
+
+ for(int pos = 0; pos< length; pos++)
+ {
+ realCol[pos] = pos;
+ realInd[pos] = pos;
+ }
+
+ for(Index i = total_deflation?0:1; i < length; i++)
+ {
+ const Index pi = permutation[length - (total_deflation ? i+1 : i)];
+ const Index J = realCol[pi];
+
+ using std::swap;
+ // swap diagonal and first column entries:
+ swap(diag(i), diag(J));
+ if(i!=0 && J!=0) swap(col0(i), col0(J));
+
+ // change columns
+ if (m_compU) m_naiveU.col(firstCol+i).segment(firstCol, length + 1).swap(m_naiveU.col(firstCol+J).segment(firstCol, length + 1));
+ else m_naiveU.col(firstCol+i).segment(0, 2) .swap(m_naiveU.col(firstCol+J).segment(0, 2));
+ if (m_compV) m_naiveV.col(firstColW + i).segment(firstRowW, length).swap(m_naiveV.col(firstColW + J).segment(firstRowW, length));
+
+ //update real pos
+ const Index realI = realInd[i];
+ realCol[realI] = J;
+ realCol[pi] = i;
+ realInd[J] = realI;
+ realInd[i] = pi;
+ }
+ }
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "sorted: " << diag.transpose().format(bdcsvdfmt) << "\n";
+ std::cout << " : " << col0.transpose() << "\n\n";
+#endif
+
+ //condition 4.4
+ {
+ Index i = length-1;
+ while(i>0 && (abs(diag(i))<considerZero || abs(col0(i))<considerZero)) --i;
+ for(; i>1;--i)
+ if( (diag(i) - diag(i-1)) < NumTraits<RealScalar>::epsilon()*maxDiag )
+ {
+#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
+ std::cout << "deflation 4.4 with i = " << i << " because " << diag(i) << " - " << diag(i-1) << " == " << (diag(i) - diag(i-1)) << " < " << NumTraits<RealScalar>::epsilon()*/*diag(i)*/maxDiag << "\n";
+#endif
+ eigen_internal_assert(abs(diag(i) - diag(i-1))<epsilon_coarse && " diagonal entries are not properly sorted");
+ deflation44(firstCol, firstCol + shift, firstRowW, firstColW, i-1, i, length);
+ }
+ }
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ for(Index j=2;j<length;++j)
+ assert(diag(j-1)<=diag(j) || abs(diag(j))<considerZero);
+#endif
+
+#ifdef EIGEN_BDCSVD_SANITY_CHECKS
+ assert(m_naiveU.allFinite());
+ assert(m_naiveV.allFinite());
+ assert(m_computed.allFinite());
+#endif
+}//end deflation
+
+/** \svd_module
+ *
+ * \return the singular value decomposition of \c *this computed by Divide & Conquer algorithm
+ *
+ * \sa class BDCSVD
+ */
+template<typename Derived>
+BDCSVD<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::bdcSvd(unsigned int computationOptions) const
+{
+ return BDCSVD<PlainObject>(*this, computationOptions);
+}
+
+} // end namespace Eigen
+
+#endif
diff --git a/src/3rdparty/eigen/Eigen/src/SVD/JacobiSVD.h b/src/3rdparty/eigen/Eigen/src/SVD/JacobiSVD.h
new file mode 100644
index 000000000..9d95acdf6
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/SVD/JacobiSVD.h
@@ -0,0 +1,812 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2013-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_JACOBISVD_H
+#define EIGEN_JACOBISVD_H
+
+namespace Eigen {
+
+namespace internal {
+// forward declaration (needed by ICC)
+// the empty body is required by MSVC
+template<typename MatrixType, int QRPreconditioner,
+ bool IsComplex = NumTraits<typename MatrixType::Scalar>::IsComplex>
+struct svd_precondition_2x2_block_to_be_real {};
+
+/*** QR preconditioners (R-SVD)
+ ***
+ *** Their role is to reduce the problem of computing the SVD to the case of a square matrix.
+ *** This approach, known as R-SVD, is an optimization for rectangular-enough matrices, and is a requirement for
+ *** JacobiSVD which by itself is only able to work on square matrices.
+ ***/
+
+enum { PreconditionIfMoreColsThanRows, PreconditionIfMoreRowsThanCols };
+
+template<typename MatrixType, int QRPreconditioner, int Case>
+struct qr_preconditioner_should_do_anything
+{
+ enum { a = MatrixType::RowsAtCompileTime != Dynamic &&
+ MatrixType::ColsAtCompileTime != Dynamic &&
+ MatrixType::ColsAtCompileTime <= MatrixType::RowsAtCompileTime,
+ b = MatrixType::RowsAtCompileTime != Dynamic &&
+ MatrixType::ColsAtCompileTime != Dynamic &&
+ MatrixType::RowsAtCompileTime <= MatrixType::ColsAtCompileTime,
+ ret = !( (QRPreconditioner == NoQRPreconditioner) ||
+ (Case == PreconditionIfMoreColsThanRows && bool(a)) ||
+ (Case == PreconditionIfMoreRowsThanCols && bool(b)) )
+ };
+};
+
+template<typename MatrixType, int QRPreconditioner, int Case,
+ bool DoAnything = qr_preconditioner_should_do_anything<MatrixType, QRPreconditioner, Case>::ret
+> struct qr_preconditioner_impl {};
+
+template<typename MatrixType, int QRPreconditioner, int Case>
+class qr_preconditioner_impl<MatrixType, QRPreconditioner, Case, false>
+{
+public:
+ void allocate(const JacobiSVD<MatrixType, QRPreconditioner>&) {}
+ bool run(JacobiSVD<MatrixType, QRPreconditioner>&, const MatrixType&)
+ {
+ return false;
+ }
+};
+
+/*** preconditioner using FullPivHouseholderQR ***/
+
+template<typename MatrixType>
+class qr_preconditioner_impl<MatrixType, FullPivHouseholderQRPreconditioner, PreconditionIfMoreRowsThanCols, true>
+{
+public:
+ typedef typename MatrixType::Scalar Scalar;
+ enum
+ {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime
+ };
+ typedef Matrix<Scalar, 1, RowsAtCompileTime, RowMajor, 1, MaxRowsAtCompileTime> WorkspaceType;
+
+ void allocate(const JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd)
+ {
+ if (svd.rows() != m_qr.rows() || svd.cols() != m_qr.cols())
+ {
+ m_qr.~QRType();
+ ::new (&m_qr) QRType(svd.rows(), svd.cols());
+ }
+ if (svd.m_computeFullU) m_workspace.resize(svd.rows());
+ }
+
+ bool run(JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix)
+ {
+ if(matrix.rows() > matrix.cols())
+ {
+ m_qr.compute(matrix);
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.cols(),matrix.cols()).template triangularView<Upper>();
+ if(svd.m_computeFullU) m_qr.matrixQ().evalTo(svd.m_matrixU, m_workspace);
+ if(svd.computeV()) svd.m_matrixV = m_qr.colsPermutation();
+ return true;
+ }
+ return false;
+ }
+private:
+ typedef FullPivHouseholderQR<MatrixType> QRType;
+ QRType m_qr;
+ WorkspaceType m_workspace;
+};
+
+template<typename MatrixType>
+class qr_preconditioner_impl<MatrixType, FullPivHouseholderQRPreconditioner, PreconditionIfMoreColsThanRows, true>
+{
+public:
+ typedef typename MatrixType::Scalar Scalar;
+ enum
+ {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
+ Options = MatrixType::Options
+ };
+
+ typedef typename internal::make_proper_matrix_type<
+ Scalar, ColsAtCompileTime, RowsAtCompileTime, Options, MaxColsAtCompileTime, MaxRowsAtCompileTime
+ >::type TransposeTypeWithSameStorageOrder;
+
+ void allocate(const JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd)
+ {
+ if (svd.cols() != m_qr.rows() || svd.rows() != m_qr.cols())
+ {
+ m_qr.~QRType();
+ ::new (&m_qr) QRType(svd.cols(), svd.rows());
+ }
+ m_adjoint.resize(svd.cols(), svd.rows());
+ if (svd.m_computeFullV) m_workspace.resize(svd.cols());
+ }
+
+ bool run(JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix)
+ {
+ if(matrix.cols() > matrix.rows())
+ {
+ m_adjoint = matrix.adjoint();
+ m_qr.compute(m_adjoint);
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.rows(),matrix.rows()).template triangularView<Upper>().adjoint();
+ if(svd.m_computeFullV) m_qr.matrixQ().evalTo(svd.m_matrixV, m_workspace);
+ if(svd.computeU()) svd.m_matrixU = m_qr.colsPermutation();
+ return true;
+ }
+ else return false;
+ }
+private:
+ typedef FullPivHouseholderQR<TransposeTypeWithSameStorageOrder> QRType;
+ QRType m_qr;
+ TransposeTypeWithSameStorageOrder m_adjoint;
+ typename internal::plain_row_type<MatrixType>::type m_workspace;
+};
+
+/*** preconditioner using ColPivHouseholderQR ***/
+
+template<typename MatrixType>
+class qr_preconditioner_impl<MatrixType, ColPivHouseholderQRPreconditioner, PreconditionIfMoreRowsThanCols, true>
+{
+public:
+ void allocate(const JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd)
+ {
+ if (svd.rows() != m_qr.rows() || svd.cols() != m_qr.cols())
+ {
+ m_qr.~QRType();
+ ::new (&m_qr) QRType(svd.rows(), svd.cols());
+ }
+ if (svd.m_computeFullU) m_workspace.resize(svd.rows());
+ else if (svd.m_computeThinU) m_workspace.resize(svd.cols());
+ }
+
+ bool run(JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix)
+ {
+ if(matrix.rows() > matrix.cols())
+ {
+ m_qr.compute(matrix);
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.cols(),matrix.cols()).template triangularView<Upper>();
+ if(svd.m_computeFullU) m_qr.householderQ().evalTo(svd.m_matrixU, m_workspace);
+ else if(svd.m_computeThinU)
+ {
+ svd.m_matrixU.setIdentity(matrix.rows(), matrix.cols());
+ m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixU, m_workspace);
+ }
+ if(svd.computeV()) svd.m_matrixV = m_qr.colsPermutation();
+ return true;
+ }
+ return false;
+ }
+
+private:
+ typedef ColPivHouseholderQR<MatrixType> QRType;
+ QRType m_qr;
+ typename internal::plain_col_type<MatrixType>::type m_workspace;
+};
+
+template<typename MatrixType>
+class qr_preconditioner_impl<MatrixType, ColPivHouseholderQRPreconditioner, PreconditionIfMoreColsThanRows, true>
+{
+public:
+ typedef typename MatrixType::Scalar Scalar;
+ enum
+ {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
+ Options = MatrixType::Options
+ };
+
+ typedef typename internal::make_proper_matrix_type<
+ Scalar, ColsAtCompileTime, RowsAtCompileTime, Options, MaxColsAtCompileTime, MaxRowsAtCompileTime
+ >::type TransposeTypeWithSameStorageOrder;
+
+ void allocate(const JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd)
+ {
+ if (svd.cols() != m_qr.rows() || svd.rows() != m_qr.cols())
+ {
+ m_qr.~QRType();
+ ::new (&m_qr) QRType(svd.cols(), svd.rows());
+ }
+ if (svd.m_computeFullV) m_workspace.resize(svd.cols());
+ else if (svd.m_computeThinV) m_workspace.resize(svd.rows());
+ m_adjoint.resize(svd.cols(), svd.rows());
+ }
+
+ bool run(JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix)
+ {
+ if(matrix.cols() > matrix.rows())
+ {
+ m_adjoint = matrix.adjoint();
+ m_qr.compute(m_adjoint);
+
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.rows(),matrix.rows()).template triangularView<Upper>().adjoint();
+ if(svd.m_computeFullV) m_qr.householderQ().evalTo(svd.m_matrixV, m_workspace);
+ else if(svd.m_computeThinV)
+ {
+ svd.m_matrixV.setIdentity(matrix.cols(), matrix.rows());
+ m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixV, m_workspace);
+ }
+ if(svd.computeU()) svd.m_matrixU = m_qr.colsPermutation();
+ return true;
+ }
+ else return false;
+ }
+
+private:
+ typedef ColPivHouseholderQR<TransposeTypeWithSameStorageOrder> QRType;
+ QRType m_qr;
+ TransposeTypeWithSameStorageOrder m_adjoint;
+ typename internal::plain_row_type<MatrixType>::type m_workspace;
+};
+
+/*** preconditioner using HouseholderQR ***/
+
+template<typename MatrixType>
+class qr_preconditioner_impl<MatrixType, HouseholderQRPreconditioner, PreconditionIfMoreRowsThanCols, true>
+{
+public:
+ void allocate(const JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd)
+ {
+ if (svd.rows() != m_qr.rows() || svd.cols() != m_qr.cols())
+ {
+ m_qr.~QRType();
+ ::new (&m_qr) QRType(svd.rows(), svd.cols());
+ }
+ if (svd.m_computeFullU) m_workspace.resize(svd.rows());
+ else if (svd.m_computeThinU) m_workspace.resize(svd.cols());
+ }
+
+ bool run(JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd, const MatrixType& matrix)
+ {
+ if(matrix.rows() > matrix.cols())
+ {
+ m_qr.compute(matrix);
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.cols(),matrix.cols()).template triangularView<Upper>();
+ if(svd.m_computeFullU) m_qr.householderQ().evalTo(svd.m_matrixU, m_workspace);
+ else if(svd.m_computeThinU)
+ {
+ svd.m_matrixU.setIdentity(matrix.rows(), matrix.cols());
+ m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixU, m_workspace);
+ }
+ if(svd.computeV()) svd.m_matrixV.setIdentity(matrix.cols(), matrix.cols());
+ return true;
+ }
+ return false;
+ }
+private:
+ typedef HouseholderQR<MatrixType> QRType;
+ QRType m_qr;
+ typename internal::plain_col_type<MatrixType>::type m_workspace;
+};
+
+template<typename MatrixType>
+class qr_preconditioner_impl<MatrixType, HouseholderQRPreconditioner, PreconditionIfMoreColsThanRows, true>
+{
+public:
+ typedef typename MatrixType::Scalar Scalar;
+ enum
+ {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
+ Options = MatrixType::Options
+ };
+
+ typedef typename internal::make_proper_matrix_type<
+ Scalar, ColsAtCompileTime, RowsAtCompileTime, Options, MaxColsAtCompileTime, MaxRowsAtCompileTime
+ >::type TransposeTypeWithSameStorageOrder;
+
+ void allocate(const JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd)
+ {
+ if (svd.cols() != m_qr.rows() || svd.rows() != m_qr.cols())
+ {
+ m_qr.~QRType();
+ ::new (&m_qr) QRType(svd.cols(), svd.rows());
+ }
+ if (svd.m_computeFullV) m_workspace.resize(svd.cols());
+ else if (svd.m_computeThinV) m_workspace.resize(svd.rows());
+ m_adjoint.resize(svd.cols(), svd.rows());
+ }
+
+ bool run(JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd, const MatrixType& matrix)
+ {
+ if(matrix.cols() > matrix.rows())
+ {
+ m_adjoint = matrix.adjoint();
+ m_qr.compute(m_adjoint);
+
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.rows(),matrix.rows()).template triangularView<Upper>().adjoint();
+ if(svd.m_computeFullV) m_qr.householderQ().evalTo(svd.m_matrixV, m_workspace);
+ else if(svd.m_computeThinV)
+ {
+ svd.m_matrixV.setIdentity(matrix.cols(), matrix.rows());
+ m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixV, m_workspace);
+ }
+ if(svd.computeU()) svd.m_matrixU.setIdentity(matrix.rows(), matrix.rows());
+ return true;
+ }
+ else return false;
+ }
+
+private:
+ typedef HouseholderQR<TransposeTypeWithSameStorageOrder> QRType;
+ QRType m_qr;
+ TransposeTypeWithSameStorageOrder m_adjoint;
+ typename internal::plain_row_type<MatrixType>::type m_workspace;
+};
+
+/*** 2x2 SVD implementation
+ ***
+ *** JacobiSVD consists in performing a series of 2x2 SVD subproblems
+ ***/
+
+template<typename MatrixType, int QRPreconditioner>
+struct svd_precondition_2x2_block_to_be_real<MatrixType, QRPreconditioner, false>
+{
+ typedef JacobiSVD<MatrixType, QRPreconditioner> SVD;
+ typedef typename MatrixType::RealScalar RealScalar;
+ static bool run(typename SVD::WorkMatrixType&, SVD&, Index, Index, RealScalar&) { return true; }
+};
+
+template<typename MatrixType, int QRPreconditioner>
+struct svd_precondition_2x2_block_to_be_real<MatrixType, QRPreconditioner, true>
+{
+ typedef JacobiSVD<MatrixType, QRPreconditioner> SVD;
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename MatrixType::RealScalar RealScalar;
+ static bool run(typename SVD::WorkMatrixType& work_matrix, SVD& svd, Index p, Index q, RealScalar& maxDiagEntry)
+ {
+ using std::sqrt;
+ using std::abs;
+ Scalar z;
+ JacobiRotation<Scalar> rot;
+ RealScalar n = sqrt(numext::abs2(work_matrix.coeff(p,p)) + numext::abs2(work_matrix.coeff(q,p)));
+
+ const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)();
+ const RealScalar precision = NumTraits<Scalar>::epsilon();
+
+ if(n==0)
+ {
+ // make sure first column is zero
+ work_matrix.coeffRef(p,p) = work_matrix.coeffRef(q,p) = Scalar(0);
+
+ if(abs(numext::imag(work_matrix.coeff(p,q)))>considerAsZero)
+ {
+ // work_matrix.coeff(p,q) can be zero if work_matrix.coeff(q,p) is not zero but small enough to underflow when computing n
+ z = abs(work_matrix.coeff(p,q)) / work_matrix.coeff(p,q);
+ work_matrix.row(p) *= z;
+ if(svd.computeU()) svd.m_matrixU.col(p) *= conj(z);
+ }
+ if(abs(numext::imag(work_matrix.coeff(q,q)))>considerAsZero)
+ {
+ z = abs(work_matrix.coeff(q,q)) / work_matrix.coeff(q,q);
+ work_matrix.row(q) *= z;
+ if(svd.computeU()) svd.m_matrixU.col(q) *= conj(z);
+ }
+ // otherwise the second row is already zero, so we have nothing to do.
+ }
+ else
+ {
+ rot.c() = conj(work_matrix.coeff(p,p)) / n;
+ rot.s() = work_matrix.coeff(q,p) / n;
+ work_matrix.applyOnTheLeft(p,q,rot);
+ if(svd.computeU()) svd.m_matrixU.applyOnTheRight(p,q,rot.adjoint());
+ if(abs(numext::imag(work_matrix.coeff(p,q)))>considerAsZero)
+ {
+ z = abs(work_matrix.coeff(p,q)) / work_matrix.coeff(p,q);
+ work_matrix.col(q) *= z;
+ if(svd.computeV()) svd.m_matrixV.col(q) *= z;
+ }
+ if(abs(numext::imag(work_matrix.coeff(q,q)))>considerAsZero)
+ {
+ z = abs(work_matrix.coeff(q,q)) / work_matrix.coeff(q,q);
+ work_matrix.row(q) *= z;
+ if(svd.computeU()) svd.m_matrixU.col(q) *= conj(z);
+ }
+ }
+
+ // update largest diagonal entry
+ maxDiagEntry = numext::maxi<RealScalar>(maxDiagEntry,numext::maxi<RealScalar>(abs(work_matrix.coeff(p,p)), abs(work_matrix.coeff(q,q))));
+ // and check whether the 2x2 block is already diagonal
+ RealScalar threshold = numext::maxi<RealScalar>(considerAsZero, precision * maxDiagEntry);
+ return abs(work_matrix.coeff(p,q))>threshold || abs(work_matrix.coeff(q,p)) > threshold;
+ }
+};
+
+template<typename _MatrixType, int QRPreconditioner>
+struct traits<JacobiSVD<_MatrixType,QRPreconditioner> >
+ : traits<_MatrixType>
+{
+ typedef _MatrixType MatrixType;
+};
+
+} // end namespace internal
+
+/** \ingroup SVD_Module
+ *
+ *
+ * \class JacobiSVD
+ *
+ * \brief Two-sided Jacobi SVD decomposition of a rectangular matrix
+ *
+ * \tparam _MatrixType the type of the matrix of which we are computing the SVD decomposition
+ * \tparam QRPreconditioner this optional parameter allows to specify the type of QR decomposition that will be used internally
+ * for the R-SVD step for non-square matrices. See discussion of possible values below.
+ *
+ * SVD decomposition consists in decomposing any n-by-p matrix \a A as a product
+ * \f[ A = U S V^* \f]
+ * where \a U is a n-by-n unitary, \a V is a p-by-p unitary, and \a S is a n-by-p real positive matrix which is zero outside of its main diagonal;
+ * the diagonal entries of S are known as the \em singular \em values of \a A and the columns of \a U and \a V are known as the left
+ * and right \em singular \em vectors of \a A respectively.
+ *
+ * Singular values are always sorted in decreasing order.
+ *
+ * This JacobiSVD decomposition computes only the singular values by default. If you want \a U or \a V, you need to ask for them explicitly.
+ *
+ * You can ask for only \em thin \a U or \a V to be computed, meaning the following. In case of a rectangular n-by-p matrix, letting \a m be the
+ * smaller value among \a n and \a p, there are only \a m singular vectors; the remaining columns of \a U and \a V do not correspond to actual
+ * singular vectors. Asking for \em thin \a U or \a V means asking for only their \a m first columns to be formed. So \a U is then a n-by-m matrix,
+ * and \a V is then a p-by-m matrix. Notice that thin \a U and \a V are all you need for (least squares) solving.
+ *
+ * Here's an example demonstrating basic usage:
+ * \include JacobiSVD_basic.cpp
+ * Output: \verbinclude JacobiSVD_basic.out
+ *
+ * This JacobiSVD class is a two-sided Jacobi R-SVD decomposition, ensuring optimal reliability and accuracy. The downside is that it's slower than
+ * bidiagonalizing SVD algorithms for large square matrices; however its complexity is still \f$ O(n^2p) \f$ where \a n is the smaller dimension and
+ * \a p is the greater dimension, meaning that it is still of the same order of complexity as the faster bidiagonalizing R-SVD algorithms.
+ * In particular, like any R-SVD, it takes advantage of non-squareness in that its complexity is only linear in the greater dimension.
+ *
+ * If the input matrix has inf or nan coefficients, the result of the computation is undefined, but the computation is guaranteed to
+ * terminate in finite (and reasonable) time.
+ *
+ * The possible values for QRPreconditioner are:
+ * \li ColPivHouseholderQRPreconditioner is the default. In practice it's very safe. It uses column-pivoting QR.
+ * \li FullPivHouseholderQRPreconditioner, is the safest and slowest. It uses full-pivoting QR.
+ * Contrary to other QRs, it doesn't allow computing thin unitaries.
+ * \li HouseholderQRPreconditioner is the fastest, and less safe and accurate than the pivoting variants. It uses non-pivoting QR.
+ * This is very similar in safety and accuracy to the bidiagonalization process used by bidiagonalizing SVD algorithms (since bidiagonalization
+ * is inherently non-pivoting). However the resulting SVD is still more reliable than bidiagonalizing SVDs because the Jacobi-based iterarive
+ * process is more reliable than the optimized bidiagonal SVD iterations.
+ * \li NoQRPreconditioner allows not to use a QR preconditioner at all. This is useful if you know that you will only be computing
+ * JacobiSVD decompositions of square matrices. Non-square matrices require a QR preconditioner. Using this option will result in
+ * faster compilation and smaller executable code. It won't significantly speed up computation, since JacobiSVD is always checking
+ * if QR preconditioning is needed before applying it anyway.
+ *
+ * \sa MatrixBase::jacobiSvd()
+ */
+template<typename _MatrixType, int QRPreconditioner> class JacobiSVD
+ : public SVDBase<JacobiSVD<_MatrixType,QRPreconditioner> >
+{
+ typedef SVDBase<JacobiSVD> Base;
+ public:
+
+ typedef _MatrixType MatrixType;
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
+ enum {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ DiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime),
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
+ MaxDiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(MaxRowsAtCompileTime,MaxColsAtCompileTime),
+ MatrixOptions = MatrixType::Options
+ };
+
+ typedef typename Base::MatrixUType MatrixUType;
+ typedef typename Base::MatrixVType MatrixVType;
+ typedef typename Base::SingularValuesType SingularValuesType;
+
+ typedef typename internal::plain_row_type<MatrixType>::type RowType;
+ typedef typename internal::plain_col_type<MatrixType>::type ColType;
+ typedef Matrix<Scalar, DiagSizeAtCompileTime, DiagSizeAtCompileTime,
+ MatrixOptions, MaxDiagSizeAtCompileTime, MaxDiagSizeAtCompileTime>
+ WorkMatrixType;
+
+ /** \brief Default Constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via JacobiSVD::compute(const MatrixType&).
+ */
+ JacobiSVD()
+ {}
+
+
+ /** \brief Default Constructor with memory preallocation
+ *
+ * Like the default constructor but with preallocation of the internal data
+ * according to the specified problem size.
+ * \sa JacobiSVD()
+ */
+ JacobiSVD(Index rows, Index cols, unsigned int computationOptions = 0)
+ {
+ allocate(rows, cols, computationOptions);
+ }
+
+ /** \brief Constructor performing the decomposition of given matrix.
+ *
+ * \param matrix the matrix to decompose
+ * \param computationOptions optional parameter allowing to specify if you want full or thin U or V unitaries to be computed.
+ * By default, none is computed. This is a bit-field, the possible bits are #ComputeFullU, #ComputeThinU,
+ * #ComputeFullV, #ComputeThinV.
+ *
+ * Thin unitaries are only available if your matrix type has a Dynamic number of columns (for example MatrixXf). They also are not
+ * available with the (non-default) FullPivHouseholderQR preconditioner.
+ */
+ explicit JacobiSVD(const MatrixType& matrix, unsigned int computationOptions = 0)
+ {
+ compute(matrix, computationOptions);
+ }
+
+ /** \brief Method performing the decomposition of given matrix using custom options.
+ *
+ * \param matrix the matrix to decompose
+ * \param computationOptions optional parameter allowing to specify if you want full or thin U or V unitaries to be computed.
+ * By default, none is computed. This is a bit-field, the possible bits are #ComputeFullU, #ComputeThinU,
+ * #ComputeFullV, #ComputeThinV.
+ *
+ * Thin unitaries are only available if your matrix type has a Dynamic number of columns (for example MatrixXf). They also are not
+ * available with the (non-default) FullPivHouseholderQR preconditioner.
+ */
+ JacobiSVD& compute(const MatrixType& matrix, unsigned int computationOptions);
+
+ /** \brief Method performing the decomposition of given matrix using current options.
+ *
+ * \param matrix the matrix to decompose
+ *
+ * This method uses the current \a computationOptions, as already passed to the constructor or to compute(const MatrixType&, unsigned int).
+ */
+ JacobiSVD& compute(const MatrixType& matrix)
+ {
+ return compute(matrix, m_computationOptions);
+ }
+
+ using Base::computeU;
+ using Base::computeV;
+ using Base::rows;
+ using Base::cols;
+ using Base::rank;
+
+ private:
+ void allocate(Index rows, Index cols, unsigned int computationOptions);
+
+ protected:
+ using Base::m_matrixU;
+ using Base::m_matrixV;
+ using Base::m_singularValues;
+ using Base::m_info;
+ using Base::m_isInitialized;
+ using Base::m_isAllocated;
+ using Base::m_usePrescribedThreshold;
+ using Base::m_computeFullU;
+ using Base::m_computeThinU;
+ using Base::m_computeFullV;
+ using Base::m_computeThinV;
+ using Base::m_computationOptions;
+ using Base::m_nonzeroSingularValues;
+ using Base::m_rows;
+ using Base::m_cols;
+ using Base::m_diagSize;
+ using Base::m_prescribedThreshold;
+ WorkMatrixType m_workMatrix;
+
+ template<typename __MatrixType, int _QRPreconditioner, bool _IsComplex>
+ friend struct internal::svd_precondition_2x2_block_to_be_real;
+ template<typename __MatrixType, int _QRPreconditioner, int _Case, bool _DoAnything>
+ friend struct internal::qr_preconditioner_impl;
+
+ internal::qr_preconditioner_impl<MatrixType, QRPreconditioner, internal::PreconditionIfMoreColsThanRows> m_qr_precond_morecols;
+ internal::qr_preconditioner_impl<MatrixType, QRPreconditioner, internal::PreconditionIfMoreRowsThanCols> m_qr_precond_morerows;
+ MatrixType m_scaledMatrix;
+};
+
+template<typename MatrixType, int QRPreconditioner>
+void JacobiSVD<MatrixType, QRPreconditioner>::allocate(Eigen::Index rows, Eigen::Index cols, unsigned int computationOptions)
+{
+ eigen_assert(rows >= 0 && cols >= 0);
+
+ if (m_isAllocated &&
+ rows == m_rows &&
+ cols == m_cols &&
+ computationOptions == m_computationOptions)
+ {
+ return;
+ }
+
+ m_rows = rows;
+ m_cols = cols;
+ m_info = Success;
+ m_isInitialized = false;
+ m_isAllocated = true;
+ m_computationOptions = computationOptions;
+ m_computeFullU = (computationOptions & ComputeFullU) != 0;
+ m_computeThinU = (computationOptions & ComputeThinU) != 0;
+ m_computeFullV = (computationOptions & ComputeFullV) != 0;
+ m_computeThinV = (computationOptions & ComputeThinV) != 0;
+ eigen_assert(!(m_computeFullU && m_computeThinU) && "JacobiSVD: you can't ask for both full and thin U");
+ eigen_assert(!(m_computeFullV && m_computeThinV) && "JacobiSVD: you can't ask for both full and thin V");
+ eigen_assert(EIGEN_IMPLIES(m_computeThinU || m_computeThinV, MatrixType::ColsAtCompileTime==Dynamic) &&
+ "JacobiSVD: thin U and V are only available when your matrix has a dynamic number of columns.");
+ if (QRPreconditioner == FullPivHouseholderQRPreconditioner)
+ {
+ eigen_assert(!(m_computeThinU || m_computeThinV) &&
+ "JacobiSVD: can't compute thin U or thin V with the FullPivHouseholderQR preconditioner. "
+ "Use the ColPivHouseholderQR preconditioner instead.");
+ }
+ m_diagSize = (std::min)(m_rows, m_cols);
+ m_singularValues.resize(m_diagSize);
+ if(RowsAtCompileTime==Dynamic)
+ m_matrixU.resize(m_rows, m_computeFullU ? m_rows
+ : m_computeThinU ? m_diagSize
+ : 0);
+ if(ColsAtCompileTime==Dynamic)
+ m_matrixV.resize(m_cols, m_computeFullV ? m_cols
+ : m_computeThinV ? m_diagSize
+ : 0);
+ m_workMatrix.resize(m_diagSize, m_diagSize);
+
+ if(m_cols>m_rows) m_qr_precond_morecols.allocate(*this);
+ if(m_rows>m_cols) m_qr_precond_morerows.allocate(*this);
+ if(m_rows!=m_cols) m_scaledMatrix.resize(rows,cols);
+}
+
+template<typename MatrixType, int QRPreconditioner>
+JacobiSVD<MatrixType, QRPreconditioner>&
+JacobiSVD<MatrixType, QRPreconditioner>::compute(const MatrixType& matrix, unsigned int computationOptions)
+{
+ using std::abs;
+ allocate(matrix.rows(), matrix.cols(), computationOptions);
+
+ // currently we stop when we reach precision 2*epsilon as the last bit of precision can require an unreasonable number of iterations,
+ // only worsening the precision of U and V as we accumulate more rotations
+ const RealScalar precision = RealScalar(2) * NumTraits<Scalar>::epsilon();
+
+ // limit for denormal numbers to be considered zero in order to avoid infinite loops (see bug 286)
+ const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)();
+
+ // Scaling factor to reduce over/under-flows
+ RealScalar scale = matrix.cwiseAbs().template maxCoeff<PropagateNaN>();
+ if (!(numext::isfinite)(scale)) {
+ m_isInitialized = true;
+ m_info = InvalidInput;
+ return *this;
+ }
+ if(scale==RealScalar(0)) scale = RealScalar(1);
+
+ /*** step 1. The R-SVD step: we use a QR decomposition to reduce to the case of a square matrix */
+
+ if(m_rows!=m_cols)
+ {
+ m_scaledMatrix = matrix / scale;
+ m_qr_precond_morecols.run(*this, m_scaledMatrix);
+ m_qr_precond_morerows.run(*this, m_scaledMatrix);
+ }
+ else
+ {
+ m_workMatrix = matrix.block(0,0,m_diagSize,m_diagSize) / scale;
+ if(m_computeFullU) m_matrixU.setIdentity(m_rows,m_rows);
+ if(m_computeThinU) m_matrixU.setIdentity(m_rows,m_diagSize);
+ if(m_computeFullV) m_matrixV.setIdentity(m_cols,m_cols);
+ if(m_computeThinV) m_matrixV.setIdentity(m_cols, m_diagSize);
+ }
+
+ /*** step 2. The main Jacobi SVD iteration. ***/
+ RealScalar maxDiagEntry = m_workMatrix.cwiseAbs().diagonal().maxCoeff();
+
+ bool finished = false;
+ while(!finished)
+ {
+ finished = true;
+
+ // do a sweep: for all index pairs (p,q), perform SVD of the corresponding 2x2 sub-matrix
+
+ for(Index p = 1; p < m_diagSize; ++p)
+ {
+ for(Index q = 0; q < p; ++q)
+ {
+ // if this 2x2 sub-matrix is not diagonal already...
+ // notice that this comparison will evaluate to false if any NaN is involved, ensuring that NaN's don't
+ // keep us iterating forever. Similarly, small denormal numbers are considered zero.
+ RealScalar threshold = numext::maxi<RealScalar>(considerAsZero, precision * maxDiagEntry);
+ if(abs(m_workMatrix.coeff(p,q))>threshold || abs(m_workMatrix.coeff(q,p)) > threshold)
+ {
+ finished = false;
+ // perform SVD decomposition of 2x2 sub-matrix corresponding to indices p,q to make it diagonal
+ // the complex to real operation returns true if the updated 2x2 block is not already diagonal
+ if(internal::svd_precondition_2x2_block_to_be_real<MatrixType, QRPreconditioner>::run(m_workMatrix, *this, p, q, maxDiagEntry))
+ {
+ JacobiRotation<RealScalar> j_left, j_right;
+ internal::real_2x2_jacobi_svd(m_workMatrix, p, q, &j_left, &j_right);
+
+ // accumulate resulting Jacobi rotations
+ m_workMatrix.applyOnTheLeft(p,q,j_left);
+ if(computeU()) m_matrixU.applyOnTheRight(p,q,j_left.transpose());
+
+ m_workMatrix.applyOnTheRight(p,q,j_right);
+ if(computeV()) m_matrixV.applyOnTheRight(p,q,j_right);
+
+ // keep track of the largest diagonal coefficient
+ maxDiagEntry = numext::maxi<RealScalar>(maxDiagEntry,numext::maxi<RealScalar>(abs(m_workMatrix.coeff(p,p)), abs(m_workMatrix.coeff(q,q))));
+ }
+ }
+ }
+ }
+ }
+
+ /*** step 3. The work matrix is now diagonal, so ensure it's positive so its diagonal entries are the singular values ***/
+
+ for(Index i = 0; i < m_diagSize; ++i)
+ {
+ // For a complex matrix, some diagonal coefficients might note have been
+ // treated by svd_precondition_2x2_block_to_be_real, and the imaginary part
+ // of some diagonal entry might not be null.
+ if(NumTraits<Scalar>::IsComplex && abs(numext::imag(m_workMatrix.coeff(i,i)))>considerAsZero)
+ {
+ RealScalar a = abs(m_workMatrix.coeff(i,i));
+ m_singularValues.coeffRef(i) = abs(a);
+ if(computeU()) m_matrixU.col(i) *= m_workMatrix.coeff(i,i)/a;
+ }
+ else
+ {
+ // m_workMatrix.coeff(i,i) is already real, no difficulty:
+ RealScalar a = numext::real(m_workMatrix.coeff(i,i));
+ m_singularValues.coeffRef(i) = abs(a);
+ if(computeU() && (a<RealScalar(0))) m_matrixU.col(i) = -m_matrixU.col(i);
+ }
+ }
+
+ m_singularValues *= scale;
+
+ /*** step 4. Sort singular values in descending order and compute the number of nonzero singular values ***/
+
+ m_nonzeroSingularValues = m_diagSize;
+ for(Index i = 0; i < m_diagSize; i++)
+ {
+ Index pos;
+ RealScalar maxRemainingSingularValue = m_singularValues.tail(m_diagSize-i).maxCoeff(&pos);
+ if(maxRemainingSingularValue == RealScalar(0))
+ {
+ m_nonzeroSingularValues = i;
+ break;
+ }
+ if(pos)
+ {
+ pos += i;
+ std::swap(m_singularValues.coeffRef(i), m_singularValues.coeffRef(pos));
+ if(computeU()) m_matrixU.col(pos).swap(m_matrixU.col(i));
+ if(computeV()) m_matrixV.col(pos).swap(m_matrixV.col(i));
+ }
+ }
+
+ m_isInitialized = true;
+ return *this;
+}
+
+/** \svd_module
+ *
+ * \return the singular value decomposition of \c *this computed by two-sided
+ * Jacobi transformations.
+ *
+ * \sa class JacobiSVD
+ */
+template<typename Derived>
+JacobiSVD<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::jacobiSvd(unsigned int computationOptions) const
+{
+ return JacobiSVD<PlainObject>(*this, computationOptions);
+}
+
+} // end namespace Eigen
+
+#endif // EIGEN_JACOBISVD_H
diff --git a/src/3rdparty/eigen/Eigen/src/SVD/JacobiSVD_LAPACKE.h b/src/3rdparty/eigen/Eigen/src/SVD/JacobiSVD_LAPACKE.h
new file mode 100644
index 000000000..ff0516f61
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/SVD/JacobiSVD_LAPACKE.h
@@ -0,0 +1,91 @@
+/*
+ Copyright (c) 2011, Intel Corporation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ********************************************************************************
+ * Content : Eigen bindings to LAPACKe
+ * Singular Value Decomposition - SVD.
+ ********************************************************************************
+*/
+
+#ifndef EIGEN_JACOBISVD_LAPACKE_H
+#define EIGEN_JACOBISVD_LAPACKE_H
+
+namespace Eigen {
+
+/** \internal Specialization for the data types supported by LAPACKe */
+
+#define EIGEN_LAPACKE_SVD(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_PREFIX, EIGCOLROW, LAPACKE_COLROW) \
+template<> inline \
+JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>& \
+JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>::compute(const Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>& matrix, unsigned int computationOptions) \
+{ \
+ typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \
+ /*typedef MatrixType::Scalar Scalar;*/ \
+ /*typedef MatrixType::RealScalar RealScalar;*/ \
+ allocate(matrix.rows(), matrix.cols(), computationOptions); \
+\
+ /*const RealScalar precision = RealScalar(2) * NumTraits<Scalar>::epsilon();*/ \
+ m_nonzeroSingularValues = m_diagSize; \
+\
+ lapack_int lda = internal::convert_index<lapack_int>(matrix.outerStride()), ldu, ldvt; \
+ lapack_int matrix_order = LAPACKE_COLROW; \
+ char jobu, jobvt; \
+ LAPACKE_TYPE *u, *vt, dummy; \
+ jobu = (m_computeFullU) ? 'A' : (m_computeThinU) ? 'S' : 'N'; \
+ jobvt = (m_computeFullV) ? 'A' : (m_computeThinV) ? 'S' : 'N'; \
+ if (computeU()) { \
+ ldu = internal::convert_index<lapack_int>(m_matrixU.outerStride()); \
+ u = (LAPACKE_TYPE*)m_matrixU.data(); \
+ } else { ldu=1; u=&dummy; }\
+ MatrixType localV; \
+ lapack_int vt_rows = (m_computeFullV) ? internal::convert_index<lapack_int>(m_cols) : (m_computeThinV) ? internal::convert_index<lapack_int>(m_diagSize) : 1; \
+ if (computeV()) { \
+ localV.resize(vt_rows, m_cols); \
+ ldvt = internal::convert_index<lapack_int>(localV.outerStride()); \
+ vt = (LAPACKE_TYPE*)localV.data(); \
+ } else { ldvt=1; vt=&dummy; }\
+ Matrix<LAPACKE_RTYPE, Dynamic, Dynamic> superb; superb.resize(m_diagSize, 1); \
+ MatrixType m_temp; m_temp = matrix; \
+ LAPACKE_##LAPACKE_PREFIX##gesvd( matrix_order, jobu, jobvt, internal::convert_index<lapack_int>(m_rows), internal::convert_index<lapack_int>(m_cols), (LAPACKE_TYPE*)m_temp.data(), lda, (LAPACKE_RTYPE*)m_singularValues.data(), u, ldu, vt, ldvt, superb.data()); \
+ if (computeV()) m_matrixV = localV.adjoint(); \
+ /* for(int i=0;i<m_diagSize;i++) if (m_singularValues.coeffRef(i) < precision) { m_nonzeroSingularValues--; m_singularValues.coeffRef(i)=RealScalar(0);}*/ \
+ m_isInitialized = true; \
+ return *this; \
+}
+
+EIGEN_LAPACKE_SVD(double, double, double, d, ColMajor, LAPACK_COL_MAJOR)
+EIGEN_LAPACKE_SVD(float, float, float , s, ColMajor, LAPACK_COL_MAJOR)
+EIGEN_LAPACKE_SVD(dcomplex, lapack_complex_double, double, z, ColMajor, LAPACK_COL_MAJOR)
+EIGEN_LAPACKE_SVD(scomplex, lapack_complex_float, float , c, ColMajor, LAPACK_COL_MAJOR)
+
+EIGEN_LAPACKE_SVD(double, double, double, d, RowMajor, LAPACK_ROW_MAJOR)
+EIGEN_LAPACKE_SVD(float, float, float , s, RowMajor, LAPACK_ROW_MAJOR)
+EIGEN_LAPACKE_SVD(dcomplex, lapack_complex_double, double, z, RowMajor, LAPACK_ROW_MAJOR)
+EIGEN_LAPACKE_SVD(scomplex, lapack_complex_float, float , c, RowMajor, LAPACK_ROW_MAJOR)
+
+} // end namespace Eigen
+
+#endif // EIGEN_JACOBISVD_LAPACKE_H
diff --git a/src/3rdparty/eigen/Eigen/src/SVD/SVDBase.h b/src/3rdparty/eigen/Eigen/src/SVD/SVDBase.h
new file mode 100644
index 000000000..bc7ab88b4
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/SVD/SVDBase.h
@@ -0,0 +1,376 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// Copyright (C) 2013 Gauthier Brun <brun.gauthier@gmail.com>
+// Copyright (C) 2013 Nicolas Carre <nicolas.carre@ensimag.fr>
+// Copyright (C) 2013 Jean Ceccato <jean.ceccato@ensimag.fr>
+// Copyright (C) 2013 Pierre Zoppitelli <pierre.zoppitelli@ensimag.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_SVDBASE_H
+#define EIGEN_SVDBASE_H
+
+namespace Eigen {
+
+namespace internal {
+template<typename Derived> struct traits<SVDBase<Derived> >
+ : traits<Derived>
+{
+ typedef MatrixXpr XprKind;
+ typedef SolverStorage StorageKind;
+ typedef int StorageIndex;
+ enum { Flags = 0 };
+};
+}
+
+/** \ingroup SVD_Module
+ *
+ *
+ * \class SVDBase
+ *
+ * \brief Base class of SVD algorithms
+ *
+ * \tparam Derived the type of the actual SVD decomposition
+ *
+ * SVD decomposition consists in decomposing any n-by-p matrix \a A as a product
+ * \f[ A = U S V^* \f]
+ * where \a U is a n-by-n unitary, \a V is a p-by-p unitary, and \a S is a n-by-p real positive matrix which is zero outside of its main diagonal;
+ * the diagonal entries of S are known as the \em singular \em values of \a A and the columns of \a U and \a V are known as the left
+ * and right \em singular \em vectors of \a A respectively.
+ *
+ * Singular values are always sorted in decreasing order.
+ *
+ *
+ * You can ask for only \em thin \a U or \a V to be computed, meaning the following. In case of a rectangular n-by-p matrix, letting \a m be the
+ * smaller value among \a n and \a p, there are only \a m singular vectors; the remaining columns of \a U and \a V do not correspond to actual
+ * singular vectors. Asking for \em thin \a U or \a V means asking for only their \a m first columns to be formed. So \a U is then a n-by-m matrix,
+ * and \a V is then a p-by-m matrix. Notice that thin \a U and \a V are all you need for (least squares) solving.
+ *
+ * The status of the computation can be retrived using the \a info() method. Unless \a info() returns \a Success, the results should be not
+ * considered well defined.
+ *
+ * If the input matrix has inf or nan coefficients, the result of the computation is undefined, and \a info() will return \a InvalidInput, but the computation is guaranteed to
+ * terminate in finite (and reasonable) time.
+ * \sa class BDCSVD, class JacobiSVD
+ */
+template<typename Derived> class SVDBase
+ : public SolverBase<SVDBase<Derived> >
+{
+public:
+
+ template<typename Derived_>
+ friend struct internal::solve_assertion;
+
+ typedef typename internal::traits<Derived>::MatrixType MatrixType;
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
+ typedef typename Eigen::internal::traits<SVDBase>::StorageIndex StorageIndex;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+ enum {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ DiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime),
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
+ MaxDiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(MaxRowsAtCompileTime,MaxColsAtCompileTime),
+ MatrixOptions = MatrixType::Options
+ };
+
+ typedef Matrix<Scalar, RowsAtCompileTime, RowsAtCompileTime, MatrixOptions, MaxRowsAtCompileTime, MaxRowsAtCompileTime> MatrixUType;
+ typedef Matrix<Scalar, ColsAtCompileTime, ColsAtCompileTime, MatrixOptions, MaxColsAtCompileTime, MaxColsAtCompileTime> MatrixVType;
+ typedef typename internal::plain_diag_type<MatrixType, RealScalar>::type SingularValuesType;
+
+ Derived& derived() { return *static_cast<Derived*>(this); }
+ const Derived& derived() const { return *static_cast<const Derived*>(this); }
+
+ /** \returns the \a U matrix.
+ *
+ * For the SVD decomposition of a n-by-p matrix, letting \a m be the minimum of \a n and \a p,
+ * the U matrix is n-by-n if you asked for \link Eigen::ComputeFullU ComputeFullU \endlink, and is n-by-m if you asked for \link Eigen::ComputeThinU ComputeThinU \endlink.
+ *
+ * The \a m first columns of \a U are the left singular vectors of the matrix being decomposed.
+ *
+ * This method asserts that you asked for \a U to be computed.
+ */
+ const MatrixUType& matrixU() const
+ {
+ _check_compute_assertions();
+ eigen_assert(computeU() && "This SVD decomposition didn't compute U. Did you ask for it?");
+ return m_matrixU;
+ }
+
+ /** \returns the \a V matrix.
+ *
+ * For the SVD decomposition of a n-by-p matrix, letting \a m be the minimum of \a n and \a p,
+ * the V matrix is p-by-p if you asked for \link Eigen::ComputeFullV ComputeFullV \endlink, and is p-by-m if you asked for \link Eigen::ComputeThinV ComputeThinV \endlink.
+ *
+ * The \a m first columns of \a V are the right singular vectors of the matrix being decomposed.
+ *
+ * This method asserts that you asked for \a V to be computed.
+ */
+ const MatrixVType& matrixV() const
+ {
+ _check_compute_assertions();
+ eigen_assert(computeV() && "This SVD decomposition didn't compute V. Did you ask for it?");
+ return m_matrixV;
+ }
+
+ /** \returns the vector of singular values.
+ *
+ * For the SVD decomposition of a n-by-p matrix, letting \a m be the minimum of \a n and \a p, the
+ * returned vector has size \a m. Singular values are always sorted in decreasing order.
+ */
+ const SingularValuesType& singularValues() const
+ {
+ _check_compute_assertions();
+ return m_singularValues;
+ }
+
+ /** \returns the number of singular values that are not exactly 0 */
+ Index nonzeroSingularValues() const
+ {
+ _check_compute_assertions();
+ return m_nonzeroSingularValues;
+ }
+
+ /** \returns the rank of the matrix of which \c *this is the SVD.
+ *
+ * \note This method has to determine which singular values should be considered nonzero.
+ * For that, it uses the threshold value that you can control by calling
+ * setThreshold(const RealScalar&).
+ */
+ inline Index rank() const
+ {
+ using std::abs;
+ _check_compute_assertions();
+ if(m_singularValues.size()==0) return 0;
+ RealScalar premultiplied_threshold = numext::maxi<RealScalar>(m_singularValues.coeff(0) * threshold(), (std::numeric_limits<RealScalar>::min)());
+ Index i = m_nonzeroSingularValues-1;
+ while(i>=0 && m_singularValues.coeff(i) < premultiplied_threshold) --i;
+ return i+1;
+ }
+
+ /** Allows to prescribe a threshold to be used by certain methods, such as rank() and solve(),
+ * which need to determine when singular values are to be considered nonzero.
+ * This is not used for the SVD decomposition itself.
+ *
+ * When it needs to get the threshold value, Eigen calls threshold().
+ * The default is \c NumTraits<Scalar>::epsilon()
+ *
+ * \param threshold The new value to use as the threshold.
+ *
+ * A singular value will be considered nonzero if its value is strictly greater than
+ * \f$ \vert singular value \vert \leqslant threshold \times \vert max singular value \vert \f$.
+ *
+ * If you want to come back to the default behavior, call setThreshold(Default_t)
+ */
+ Derived& setThreshold(const RealScalar& threshold)
+ {
+ m_usePrescribedThreshold = true;
+ m_prescribedThreshold = threshold;
+ return derived();
+ }
+
+ /** Allows to come back to the default behavior, letting Eigen use its default formula for
+ * determining the threshold.
+ *
+ * You should pass the special object Eigen::Default as parameter here.
+ * \code svd.setThreshold(Eigen::Default); \endcode
+ *
+ * See the documentation of setThreshold(const RealScalar&).
+ */
+ Derived& setThreshold(Default_t)
+ {
+ m_usePrescribedThreshold = false;
+ return derived();
+ }
+
+ /** Returns the threshold that will be used by certain methods such as rank().
+ *
+ * See the documentation of setThreshold(const RealScalar&).
+ */
+ RealScalar threshold() const
+ {
+ eigen_assert(m_isInitialized || m_usePrescribedThreshold);
+ // this temporary is needed to workaround a MSVC issue
+ Index diagSize = (std::max<Index>)(1,m_diagSize);
+ return m_usePrescribedThreshold ? m_prescribedThreshold
+ : RealScalar(diagSize)*NumTraits<Scalar>::epsilon();
+ }
+
+ /** \returns true if \a U (full or thin) is asked for in this SVD decomposition */
+ inline bool computeU() const { return m_computeFullU || m_computeThinU; }
+ /** \returns true if \a V (full or thin) is asked for in this SVD decomposition */
+ inline bool computeV() const { return m_computeFullV || m_computeThinV; }
+
+ inline Index rows() const { return m_rows; }
+ inline Index cols() const { return m_cols; }
+
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
+ /** \returns a (least squares) solution of \f$ A x = b \f$ using the current SVD decomposition of A.
+ *
+ * \param b the right-hand-side of the equation to solve.
+ *
+ * \note Solving requires both U and V to be computed. Thin U and V are enough, there is no need for full U or V.
+ *
+ * \note SVD solving is implicitly least-squares. Thus, this method serves both purposes of exact solving and least-squares solving.
+ * In other words, the returned solution is guaranteed to minimize the Euclidean norm \f$ \Vert A x - b \Vert \f$.
+ */
+ template<typename Rhs>
+ inline const Solve<Derived, Rhs>
+ solve(const MatrixBase<Rhs>& b) const;
+ #endif
+
+
+ /** \brief Reports whether previous computation was successful.
+ *
+ * \returns \c Success if computation was successful.
+ */
+ EIGEN_DEVICE_FUNC
+ ComputationInfo info() const
+ {
+ eigen_assert(m_isInitialized && "SVD is not initialized.");
+ return m_info;
+ }
+
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
+ template<typename RhsType, typename DstType>
+ void _solve_impl(const RhsType &rhs, DstType &dst) const;
+
+ template<bool Conjugate, typename RhsType, typename DstType>
+ void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const;
+ #endif
+
+protected:
+
+ static void check_template_parameters()
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
+ }
+
+ void _check_compute_assertions() const {
+ eigen_assert(m_isInitialized && "SVD is not initialized.");
+ }
+
+ template<bool Transpose_, typename Rhs>
+ void _check_solve_assertion(const Rhs& b) const {
+ EIGEN_ONLY_USED_FOR_DEBUG(b);
+ _check_compute_assertions();
+ eigen_assert(computeU() && computeV() && "SVDBase::solve(): Both unitaries U and V are required to be computed (thin unitaries suffice).");
+ eigen_assert((Transpose_?cols():rows())==b.rows() && "SVDBase::solve(): invalid number of rows of the right hand side matrix b");
+ }
+
+ // return true if already allocated
+ bool allocate(Index rows, Index cols, unsigned int computationOptions) ;
+
+ MatrixUType m_matrixU;
+ MatrixVType m_matrixV;
+ SingularValuesType m_singularValues;
+ ComputationInfo m_info;
+ bool m_isInitialized, m_isAllocated, m_usePrescribedThreshold;
+ bool m_computeFullU, m_computeThinU;
+ bool m_computeFullV, m_computeThinV;
+ unsigned int m_computationOptions;
+ Index m_nonzeroSingularValues, m_rows, m_cols, m_diagSize;
+ RealScalar m_prescribedThreshold;
+
+ /** \brief Default Constructor.
+ *
+ * Default constructor of SVDBase
+ */
+ SVDBase()
+ : m_info(Success),
+ m_isInitialized(false),
+ m_isAllocated(false),
+ m_usePrescribedThreshold(false),
+ m_computeFullU(false),
+ m_computeThinU(false),
+ m_computeFullV(false),
+ m_computeThinV(false),
+ m_computationOptions(0),
+ m_rows(-1), m_cols(-1), m_diagSize(0)
+ {
+ check_template_parameters();
+ }
+
+
+};
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+template<typename Derived>
+template<typename RhsType, typename DstType>
+void SVDBase<Derived>::_solve_impl(const RhsType &rhs, DstType &dst) const
+{
+ // A = U S V^*
+ // So A^{-1} = V S^{-1} U^*
+
+ Matrix<typename RhsType::Scalar, Dynamic, RhsType::ColsAtCompileTime, 0, MatrixType::MaxRowsAtCompileTime, RhsType::MaxColsAtCompileTime> tmp;
+ Index l_rank = rank();
+ tmp.noalias() = m_matrixU.leftCols(l_rank).adjoint() * rhs;
+ tmp = m_singularValues.head(l_rank).asDiagonal().inverse() * tmp;
+ dst = m_matrixV.leftCols(l_rank) * tmp;
+}
+
+template<typename Derived>
+template<bool Conjugate, typename RhsType, typename DstType>
+void SVDBase<Derived>::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const
+{
+ // A = U S V^*
+ // So A^{-*} = U S^{-1} V^*
+ // And A^{-T} = U_conj S^{-1} V^T
+ Matrix<typename RhsType::Scalar, Dynamic, RhsType::ColsAtCompileTime, 0, MatrixType::MaxRowsAtCompileTime, RhsType::MaxColsAtCompileTime> tmp;
+ Index l_rank = rank();
+
+ tmp.noalias() = m_matrixV.leftCols(l_rank).transpose().template conjugateIf<Conjugate>() * rhs;
+ tmp = m_singularValues.head(l_rank).asDiagonal().inverse() * tmp;
+ dst = m_matrixU.template conjugateIf<!Conjugate>().leftCols(l_rank) * tmp;
+}
+#endif
+
+template<typename MatrixType>
+bool SVDBase<MatrixType>::allocate(Index rows, Index cols, unsigned int computationOptions)
+{
+ eigen_assert(rows >= 0 && cols >= 0);
+
+ if (m_isAllocated &&
+ rows == m_rows &&
+ cols == m_cols &&
+ computationOptions == m_computationOptions)
+ {
+ return true;
+ }
+
+ m_rows = rows;
+ m_cols = cols;
+ m_info = Success;
+ m_isInitialized = false;
+ m_isAllocated = true;
+ m_computationOptions = computationOptions;
+ m_computeFullU = (computationOptions & ComputeFullU) != 0;
+ m_computeThinU = (computationOptions & ComputeThinU) != 0;
+ m_computeFullV = (computationOptions & ComputeFullV) != 0;
+ m_computeThinV = (computationOptions & ComputeThinV) != 0;
+ eigen_assert(!(m_computeFullU && m_computeThinU) && "SVDBase: you can't ask for both full and thin U");
+ eigen_assert(!(m_computeFullV && m_computeThinV) && "SVDBase: you can't ask for both full and thin V");
+ eigen_assert(EIGEN_IMPLIES(m_computeThinU || m_computeThinV, MatrixType::ColsAtCompileTime==Dynamic) &&
+ "SVDBase: thin U and V are only available when your matrix has a dynamic number of columns.");
+
+ m_diagSize = (std::min)(m_rows, m_cols);
+ m_singularValues.resize(m_diagSize);
+ if(RowsAtCompileTime==Dynamic)
+ m_matrixU.resize(m_rows, m_computeFullU ? m_rows : m_computeThinU ? m_diagSize : 0);
+ if(ColsAtCompileTime==Dynamic)
+ m_matrixV.resize(m_cols, m_computeFullV ? m_cols : m_computeThinV ? m_diagSize : 0);
+
+ return false;
+}
+
+}// end namespace
+
+#endif // EIGEN_SVDBASE_H
diff --git a/src/3rdparty/eigen/Eigen/src/SVD/UpperBidiagonalization.h b/src/3rdparty/eigen/Eigen/src/SVD/UpperBidiagonalization.h
new file mode 100644
index 000000000..997defc47
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/SVD/UpperBidiagonalization.h
@@ -0,0 +1,414 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2013-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_BIDIAGONALIZATION_H
+#define EIGEN_BIDIAGONALIZATION_H
+
+namespace Eigen {
+
+namespace internal {
+// UpperBidiagonalization will probably be replaced by a Bidiagonalization class, don't want to make it stable API.
+// At the same time, it's useful to keep for now as it's about the only thing that is testing the BandMatrix class.
+
+template<typename _MatrixType> class UpperBidiagonalization
+{
+ public:
+
+ typedef _MatrixType MatrixType;
+ enum {
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
+ ColsAtCompileTimeMinusOne = internal::decrement_size<ColsAtCompileTime>::ret
+ };
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename MatrixType::RealScalar RealScalar;
+ typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
+ typedef Matrix<Scalar, 1, ColsAtCompileTime> RowVectorType;
+ typedef Matrix<Scalar, RowsAtCompileTime, 1> ColVectorType;
+ typedef BandMatrix<RealScalar, ColsAtCompileTime, ColsAtCompileTime, 1, 0, RowMajor> BidiagonalType;
+ typedef Matrix<Scalar, ColsAtCompileTime, 1> DiagVectorType;
+ typedef Matrix<Scalar, ColsAtCompileTimeMinusOne, 1> SuperDiagVectorType;
+ typedef HouseholderSequence<
+ const MatrixType,
+ const typename internal::remove_all<typename Diagonal<const MatrixType,0>::ConjugateReturnType>::type
+ > HouseholderUSequenceType;
+ typedef HouseholderSequence<
+ const typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type,
+ Diagonal<const MatrixType,1>,
+ OnTheRight
+ > HouseholderVSequenceType;
+
+ /**
+ * \brief Default Constructor.
+ *
+ * The default constructor is useful in cases in which the user intends to
+ * perform decompositions via Bidiagonalization::compute(const MatrixType&).
+ */
+ UpperBidiagonalization() : m_householder(), m_bidiagonal(), m_isInitialized(false) {}
+
+ explicit UpperBidiagonalization(const MatrixType& matrix)
+ : m_householder(matrix.rows(), matrix.cols()),
+ m_bidiagonal(matrix.cols(), matrix.cols()),
+ m_isInitialized(false)
+ {
+ compute(matrix);
+ }
+
+ UpperBidiagonalization& compute(const MatrixType& matrix);
+ UpperBidiagonalization& computeUnblocked(const MatrixType& matrix);
+
+ const MatrixType& householder() const { return m_householder; }
+ const BidiagonalType& bidiagonal() const { return m_bidiagonal; }
+
+ const HouseholderUSequenceType householderU() const
+ {
+ eigen_assert(m_isInitialized && "UpperBidiagonalization is not initialized.");
+ return HouseholderUSequenceType(m_householder, m_householder.diagonal().conjugate());
+ }
+
+ const HouseholderVSequenceType householderV() // const here gives nasty errors and i'm lazy
+ {
+ eigen_assert(m_isInitialized && "UpperBidiagonalization is not initialized.");
+ return HouseholderVSequenceType(m_householder.conjugate(), m_householder.const_derived().template diagonal<1>())
+ .setLength(m_householder.cols()-1)
+ .setShift(1);
+ }
+
+ protected:
+ MatrixType m_householder;
+ BidiagonalType m_bidiagonal;
+ bool m_isInitialized;
+};
+
+// Standard upper bidiagonalization without fancy optimizations
+// This version should be faster for small matrix size
+template<typename MatrixType>
+void upperbidiagonalization_inplace_unblocked(MatrixType& mat,
+ typename MatrixType::RealScalar *diagonal,
+ typename MatrixType::RealScalar *upper_diagonal,
+ typename MatrixType::Scalar* tempData = 0)
+{
+ typedef typename MatrixType::Scalar Scalar;
+
+ Index rows = mat.rows();
+ Index cols = mat.cols();
+
+ typedef Matrix<Scalar,Dynamic,1,ColMajor,MatrixType::MaxRowsAtCompileTime,1> TempType;
+ TempType tempVector;
+ if(tempData==0)
+ {
+ tempVector.resize(rows);
+ tempData = tempVector.data();
+ }
+
+ for (Index k = 0; /* breaks at k==cols-1 below */ ; ++k)
+ {
+ Index remainingRows = rows - k;
+ Index remainingCols = cols - k - 1;
+
+ // construct left householder transform in-place in A
+ mat.col(k).tail(remainingRows)
+ .makeHouseholderInPlace(mat.coeffRef(k,k), diagonal[k]);
+ // apply householder transform to remaining part of A on the left
+ mat.bottomRightCorner(remainingRows, remainingCols)
+ .applyHouseholderOnTheLeft(mat.col(k).tail(remainingRows-1), mat.coeff(k,k), tempData);
+
+ if(k == cols-1) break;
+
+ // construct right householder transform in-place in mat
+ mat.row(k).tail(remainingCols)
+ .makeHouseholderInPlace(mat.coeffRef(k,k+1), upper_diagonal[k]);
+ // apply householder transform to remaining part of mat on the left
+ mat.bottomRightCorner(remainingRows-1, remainingCols)
+ .applyHouseholderOnTheRight(mat.row(k).tail(remainingCols-1).adjoint(), mat.coeff(k,k+1), tempData);
+ }
+}
+
+/** \internal
+ * Helper routine for the block reduction to upper bidiagonal form.
+ *
+ * Let's partition the matrix A:
+ *
+ * | A00 A01 |
+ * A = | |
+ * | A10 A11 |
+ *
+ * This function reduces to bidiagonal form the left \c rows x \a blockSize vertical panel [A00/A10]
+ * and the \a blockSize x \c cols horizontal panel [A00 A01] of the matrix \a A. The bottom-right block A11
+ * is updated using matrix-matrix products:
+ * A22 -= V * Y^T - X * U^T
+ * where V and U contains the left and right Householder vectors. U and V are stored in A10, and A01
+ * respectively, and the update matrices X and Y are computed during the reduction.
+ *
+ */
+template<typename MatrixType>
+void upperbidiagonalization_blocked_helper(MatrixType& A,
+ typename MatrixType::RealScalar *diagonal,
+ typename MatrixType::RealScalar *upper_diagonal,
+ Index bs,
+ Ref<Matrix<typename MatrixType::Scalar, Dynamic, Dynamic,
+ traits<MatrixType>::Flags & RowMajorBit> > X,
+ Ref<Matrix<typename MatrixType::Scalar, Dynamic, Dynamic,
+ traits<MatrixType>::Flags & RowMajorBit> > Y)
+{
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename MatrixType::RealScalar RealScalar;
+ typedef typename NumTraits<RealScalar>::Literal Literal;
+ enum { StorageOrder = traits<MatrixType>::Flags & RowMajorBit };
+ typedef InnerStride<int(StorageOrder) == int(ColMajor) ? 1 : Dynamic> ColInnerStride;
+ typedef InnerStride<int(StorageOrder) == int(ColMajor) ? Dynamic : 1> RowInnerStride;
+ typedef Ref<Matrix<Scalar, Dynamic, 1>, 0, ColInnerStride> SubColumnType;
+ typedef Ref<Matrix<Scalar, 1, Dynamic>, 0, RowInnerStride> SubRowType;
+ typedef Ref<Matrix<Scalar, Dynamic, Dynamic, StorageOrder > > SubMatType;
+
+ Index brows = A.rows();
+ Index bcols = A.cols();
+
+ Scalar tau_u, tau_u_prev(0), tau_v;
+
+ for(Index k = 0; k < bs; ++k)
+ {
+ Index remainingRows = brows - k;
+ Index remainingCols = bcols - k - 1;
+
+ SubMatType X_k1( X.block(k,0, remainingRows,k) );
+ SubMatType V_k1( A.block(k,0, remainingRows,k) );
+
+ // 1 - update the k-th column of A
+ SubColumnType v_k = A.col(k).tail(remainingRows);
+ v_k -= V_k1 * Y.row(k).head(k).adjoint();
+ if(k) v_k -= X_k1 * A.col(k).head(k);
+
+ // 2 - construct left Householder transform in-place
+ v_k.makeHouseholderInPlace(tau_v, diagonal[k]);
+
+ if(k+1<bcols)
+ {
+ SubMatType Y_k ( Y.block(k+1,0, remainingCols, k+1) );
+ SubMatType U_k1 ( A.block(0,k+1, k,remainingCols) );
+
+ // this eases the application of Householder transforAions
+ // A(k,k) will store tau_v later
+ A(k,k) = Scalar(1);
+
+ // 3 - Compute y_k^T = tau_v * ( A^T*v_k - Y_k-1*V_k-1^T*v_k - U_k-1*X_k-1^T*v_k )
+ {
+ SubColumnType y_k( Y.col(k).tail(remainingCols) );
+
+ // let's use the beginning of column k of Y as a temporary vector
+ SubColumnType tmp( Y.col(k).head(k) );
+ y_k.noalias() = A.block(k,k+1, remainingRows,remainingCols).adjoint() * v_k; // bottleneck
+ tmp.noalias() = V_k1.adjoint() * v_k;
+ y_k.noalias() -= Y_k.leftCols(k) * tmp;
+ tmp.noalias() = X_k1.adjoint() * v_k;
+ y_k.noalias() -= U_k1.adjoint() * tmp;
+ y_k *= numext::conj(tau_v);
+ }
+
+ // 4 - update k-th row of A (it will become u_k)
+ SubRowType u_k( A.row(k).tail(remainingCols) );
+ u_k = u_k.conjugate();
+ {
+ u_k -= Y_k * A.row(k).head(k+1).adjoint();
+ if(k) u_k -= U_k1.adjoint() * X.row(k).head(k).adjoint();
+ }
+
+ // 5 - construct right Householder transform in-place
+ u_k.makeHouseholderInPlace(tau_u, upper_diagonal[k]);
+
+ // this eases the application of Householder transformations
+ // A(k,k+1) will store tau_u later
+ A(k,k+1) = Scalar(1);
+
+ // 6 - Compute x_k = tau_u * ( A*u_k - X_k-1*U_k-1^T*u_k - V_k*Y_k^T*u_k )
+ {
+ SubColumnType x_k ( X.col(k).tail(remainingRows-1) );
+
+ // let's use the beginning of column k of X as a temporary vectors
+ // note that tmp0 and tmp1 overlaps
+ SubColumnType tmp0 ( X.col(k).head(k) ),
+ tmp1 ( X.col(k).head(k+1) );
+
+ x_k.noalias() = A.block(k+1,k+1, remainingRows-1,remainingCols) * u_k.transpose(); // bottleneck
+ tmp0.noalias() = U_k1 * u_k.transpose();
+ x_k.noalias() -= X_k1.bottomRows(remainingRows-1) * tmp0;
+ tmp1.noalias() = Y_k.adjoint() * u_k.transpose();
+ x_k.noalias() -= A.block(k+1,0, remainingRows-1,k+1) * tmp1;
+ x_k *= numext::conj(tau_u);
+ tau_u = numext::conj(tau_u);
+ u_k = u_k.conjugate();
+ }
+
+ if(k>0) A.coeffRef(k-1,k) = tau_u_prev;
+ tau_u_prev = tau_u;
+ }
+ else
+ A.coeffRef(k-1,k) = tau_u_prev;
+
+ A.coeffRef(k,k) = tau_v;
+ }
+
+ if(bs<bcols)
+ A.coeffRef(bs-1,bs) = tau_u_prev;
+
+ // update A22
+ if(bcols>bs && brows>bs)
+ {
+ SubMatType A11( A.bottomRightCorner(brows-bs,bcols-bs) );
+ SubMatType A10( A.block(bs,0, brows-bs,bs) );
+ SubMatType A01( A.block(0,bs, bs,bcols-bs) );
+ Scalar tmp = A01(bs-1,0);
+ A01(bs-1,0) = Literal(1);
+ A11.noalias() -= A10 * Y.topLeftCorner(bcols,bs).bottomRows(bcols-bs).adjoint();
+ A11.noalias() -= X.topLeftCorner(brows,bs).bottomRows(brows-bs) * A01;
+ A01(bs-1,0) = tmp;
+ }
+}
+
+/** \internal
+ *
+ * Implementation of a block-bidiagonal reduction.
+ * It is based on the following paper:
+ * The Design of a Parallel Dense Linear Algebra Software Library: Reduction to Hessenberg, Tridiagonal, and Bidiagonal Form.
+ * by Jaeyoung Choi, Jack J. Dongarra, David W. Walker. (1995)
+ * section 3.3
+ */
+template<typename MatrixType, typename BidiagType>
+void upperbidiagonalization_inplace_blocked(MatrixType& A, BidiagType& bidiagonal,
+ Index maxBlockSize=32,
+ typename MatrixType::Scalar* /*tempData*/ = 0)
+{
+ typedef typename MatrixType::Scalar Scalar;
+ typedef Block<MatrixType,Dynamic,Dynamic> BlockType;
+
+ Index rows = A.rows();
+ Index cols = A.cols();
+ Index size = (std::min)(rows, cols);
+
+ // X and Y are work space
+ enum { StorageOrder = traits<MatrixType>::Flags & RowMajorBit };
+ Matrix<Scalar,
+ MatrixType::RowsAtCompileTime,
+ Dynamic,
+ StorageOrder,
+ MatrixType::MaxRowsAtCompileTime> X(rows,maxBlockSize);
+ Matrix<Scalar,
+ MatrixType::ColsAtCompileTime,
+ Dynamic,
+ StorageOrder,
+ MatrixType::MaxColsAtCompileTime> Y(cols,maxBlockSize);
+ Index blockSize = (std::min)(maxBlockSize,size);
+
+ Index k = 0;
+ for(k = 0; k < size; k += blockSize)
+ {
+ Index bs = (std::min)(size-k,blockSize); // actual size of the block
+ Index brows = rows - k; // rows of the block
+ Index bcols = cols - k; // columns of the block
+
+ // partition the matrix A:
+ //
+ // | A00 A01 A02 |
+ // | |
+ // A = | A10 A11 A12 |
+ // | |
+ // | A20 A21 A22 |
+ //
+ // where A11 is a bs x bs diagonal block,
+ // and let:
+ // | A11 A12 |
+ // B = | |
+ // | A21 A22 |
+
+ BlockType B = A.block(k,k,brows,bcols);
+
+ // This stage performs the bidiagonalization of A11, A21, A12, and updating of A22.
+ // Finally, the algorithm continue on the updated A22.
+ //
+ // However, if B is too small, or A22 empty, then let's use an unblocked strategy
+ if(k+bs==cols || bcols<48) // somewhat arbitrary threshold
+ {
+ upperbidiagonalization_inplace_unblocked(B,
+ &(bidiagonal.template diagonal<0>().coeffRef(k)),
+ &(bidiagonal.template diagonal<1>().coeffRef(k)),
+ X.data()
+ );
+ break; // We're done
+ }
+ else
+ {
+ upperbidiagonalization_blocked_helper<BlockType>( B,
+ &(bidiagonal.template diagonal<0>().coeffRef(k)),
+ &(bidiagonal.template diagonal<1>().coeffRef(k)),
+ bs,
+ X.topLeftCorner(brows,bs),
+ Y.topLeftCorner(bcols,bs)
+ );
+ }
+ }
+}
+
+template<typename _MatrixType>
+UpperBidiagonalization<_MatrixType>& UpperBidiagonalization<_MatrixType>::computeUnblocked(const _MatrixType& matrix)
+{
+ Index rows = matrix.rows();
+ Index cols = matrix.cols();
+ EIGEN_ONLY_USED_FOR_DEBUG(cols);
+
+ eigen_assert(rows >= cols && "UpperBidiagonalization is only for Arices satisfying rows>=cols.");
+
+ m_householder = matrix;
+
+ ColVectorType temp(rows);
+
+ upperbidiagonalization_inplace_unblocked(m_householder,
+ &(m_bidiagonal.template diagonal<0>().coeffRef(0)),
+ &(m_bidiagonal.template diagonal<1>().coeffRef(0)),
+ temp.data());
+
+ m_isInitialized = true;
+ return *this;
+}
+
+template<typename _MatrixType>
+UpperBidiagonalization<_MatrixType>& UpperBidiagonalization<_MatrixType>::compute(const _MatrixType& matrix)
+{
+ Index rows = matrix.rows();
+ Index cols = matrix.cols();
+ EIGEN_ONLY_USED_FOR_DEBUG(rows);
+ EIGEN_ONLY_USED_FOR_DEBUG(cols);
+
+ eigen_assert(rows >= cols && "UpperBidiagonalization is only for Arices satisfying rows>=cols.");
+
+ m_householder = matrix;
+ upperbidiagonalization_inplace_blocked(m_householder, m_bidiagonal);
+
+ m_isInitialized = true;
+ return *this;
+}
+
+#if 0
+/** \return the Householder QR decomposition of \c *this.
+ *
+ * \sa class Bidiagonalization
+ */
+template<typename Derived>
+const UpperBidiagonalization<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::bidiagonalization() const
+{
+ return UpperBidiagonalization<PlainObject>(eval());
+}
+#endif
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_BIDIAGONALIZATION_H
diff --git a/src/3rdparty/eigen/Eigen/src/misc/Image.h b/src/3rdparty/eigen/Eigen/src/misc/Image.h
new file mode 100644
index 000000000..b8b8a0455
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/misc/Image.h
@@ -0,0 +1,82 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MISC_IMAGE_H
+#define EIGEN_MISC_IMAGE_H
+
+namespace Eigen {
+
+namespace internal {
+
+/** \class image_retval_base
+ *
+ */
+template<typename DecompositionType>
+struct traits<image_retval_base<DecompositionType> >
+{
+ typedef typename DecompositionType::MatrixType MatrixType;
+ typedef Matrix<
+ typename MatrixType::Scalar,
+ MatrixType::RowsAtCompileTime, // the image is a subspace of the destination space, whose
+ // dimension is the number of rows of the original matrix
+ Dynamic, // we don't know at compile time the dimension of the image (the rank)
+ MatrixType::Options,
+ MatrixType::MaxRowsAtCompileTime, // the image matrix will consist of columns from the original matrix,
+ MatrixType::MaxColsAtCompileTime // so it has the same number of rows and at most as many columns.
+ > ReturnType;
+};
+
+template<typename _DecompositionType> struct image_retval_base
+ : public ReturnByValue<image_retval_base<_DecompositionType> >
+{
+ typedef _DecompositionType DecompositionType;
+ typedef typename DecompositionType::MatrixType MatrixType;
+ typedef ReturnByValue<image_retval_base> Base;
+
+ image_retval_base(const DecompositionType& dec, const MatrixType& originalMatrix)
+ : m_dec(dec), m_rank(dec.rank()),
+ m_cols(m_rank == 0 ? 1 : m_rank),
+ m_originalMatrix(originalMatrix)
+ {}
+
+ inline Index rows() const { return m_dec.rows(); }
+ inline Index cols() const { return m_cols; }
+ inline Index rank() const { return m_rank; }
+ inline const DecompositionType& dec() const { return m_dec; }
+ inline const MatrixType& originalMatrix() const { return m_originalMatrix; }
+
+ template<typename Dest> inline void evalTo(Dest& dst) const
+ {
+ static_cast<const image_retval<DecompositionType>*>(this)->evalTo(dst);
+ }
+
+ protected:
+ const DecompositionType& m_dec;
+ Index m_rank, m_cols;
+ const MatrixType& m_originalMatrix;
+};
+
+} // end namespace internal
+
+#define EIGEN_MAKE_IMAGE_HELPERS(DecompositionType) \
+ typedef typename DecompositionType::MatrixType MatrixType; \
+ typedef typename MatrixType::Scalar Scalar; \
+ typedef typename MatrixType::RealScalar RealScalar; \
+ typedef Eigen::internal::image_retval_base<DecompositionType> Base; \
+ using Base::dec; \
+ using Base::originalMatrix; \
+ using Base::rank; \
+ using Base::rows; \
+ using Base::cols; \
+ image_retval(const DecompositionType& dec, const MatrixType& originalMatrix) \
+ : Base(dec, originalMatrix) {}
+
+} // end namespace Eigen
+
+#endif // EIGEN_MISC_IMAGE_H
diff --git a/src/3rdparty/eigen/Eigen/src/misc/Kernel.h b/src/3rdparty/eigen/Eigen/src/misc/Kernel.h
new file mode 100644
index 000000000..bef5d6ff5
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/misc/Kernel.h
@@ -0,0 +1,79 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_MISC_KERNEL_H
+#define EIGEN_MISC_KERNEL_H
+
+namespace Eigen {
+
+namespace internal {
+
+/** \class kernel_retval_base
+ *
+ */
+template<typename DecompositionType>
+struct traits<kernel_retval_base<DecompositionType> >
+{
+ typedef typename DecompositionType::MatrixType MatrixType;
+ typedef Matrix<
+ typename MatrixType::Scalar,
+ MatrixType::ColsAtCompileTime, // the number of rows in the "kernel matrix"
+ // is the number of cols of the original matrix
+ // so that the product "matrix * kernel = zero" makes sense
+ Dynamic, // we don't know at compile-time the dimension of the kernel
+ MatrixType::Options,
+ MatrixType::MaxColsAtCompileTime, // see explanation for 2nd template parameter
+ MatrixType::MaxColsAtCompileTime // the kernel is a subspace of the domain space,
+ // whose dimension is the number of columns of the original matrix
+ > ReturnType;
+};
+
+template<typename _DecompositionType> struct kernel_retval_base
+ : public ReturnByValue<kernel_retval_base<_DecompositionType> >
+{
+ typedef _DecompositionType DecompositionType;
+ typedef ReturnByValue<kernel_retval_base> Base;
+
+ explicit kernel_retval_base(const DecompositionType& dec)
+ : m_dec(dec),
+ m_rank(dec.rank()),
+ m_cols(m_rank==dec.cols() ? 1 : dec.cols() - m_rank)
+ {}
+
+ inline Index rows() const { return m_dec.cols(); }
+ inline Index cols() const { return m_cols; }
+ inline Index rank() const { return m_rank; }
+ inline const DecompositionType& dec() const { return m_dec; }
+
+ template<typename Dest> inline void evalTo(Dest& dst) const
+ {
+ static_cast<const kernel_retval<DecompositionType>*>(this)->evalTo(dst);
+ }
+
+ protected:
+ const DecompositionType& m_dec;
+ Index m_rank, m_cols;
+};
+
+} // end namespace internal
+
+#define EIGEN_MAKE_KERNEL_HELPERS(DecompositionType) \
+ typedef typename DecompositionType::MatrixType MatrixType; \
+ typedef typename MatrixType::Scalar Scalar; \
+ typedef typename MatrixType::RealScalar RealScalar; \
+ typedef Eigen::internal::kernel_retval_base<DecompositionType> Base; \
+ using Base::dec; \
+ using Base::rank; \
+ using Base::rows; \
+ using Base::cols; \
+ kernel_retval(const DecompositionType& dec) : Base(dec) {}
+
+} // end namespace Eigen
+
+#endif // EIGEN_MISC_KERNEL_H
diff --git a/src/3rdparty/eigen/Eigen/src/misc/RealSvd2x2.h b/src/3rdparty/eigen/Eigen/src/misc/RealSvd2x2.h
new file mode 100644
index 000000000..abb4d3c2f
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/misc/RealSvd2x2.h
@@ -0,0 +1,55 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+// Copyright (C) 2013-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_REALSVD2X2_H
+#define EIGEN_REALSVD2X2_H
+
+namespace Eigen {
+
+namespace internal {
+
+template<typename MatrixType, typename RealScalar, typename Index>
+void real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q,
+ JacobiRotation<RealScalar> *j_left,
+ JacobiRotation<RealScalar> *j_right)
+{
+ using std::sqrt;
+ using std::abs;
+ Matrix<RealScalar,2,2> m;
+ m << numext::real(matrix.coeff(p,p)), numext::real(matrix.coeff(p,q)),
+ numext::real(matrix.coeff(q,p)), numext::real(matrix.coeff(q,q));
+ JacobiRotation<RealScalar> rot1;
+ RealScalar t = m.coeff(0,0) + m.coeff(1,1);
+ RealScalar d = m.coeff(1,0) - m.coeff(0,1);
+
+ if(abs(d) < (std::numeric_limits<RealScalar>::min)())
+ {
+ rot1.s() = RealScalar(0);
+ rot1.c() = RealScalar(1);
+ }
+ else
+ {
+ // If d!=0, then t/d cannot overflow because the magnitude of the
+ // entries forming d are not too small compared to the ones forming t.
+ RealScalar u = t / d;
+ RealScalar tmp = sqrt(RealScalar(1) + numext::abs2(u));
+ rot1.s() = RealScalar(1) / tmp;
+ rot1.c() = u / tmp;
+ }
+ m.applyOnTheLeft(0,1,rot1);
+ j_right->makeJacobi(m,0,1);
+ *j_left = rot1 * j_right->transpose();
+}
+
+} // end namespace internal
+
+} // end namespace Eigen
+
+#endif // EIGEN_REALSVD2X2_H
diff --git a/src/3rdparty/eigen/Eigen/src/misc/blas.h b/src/3rdparty/eigen/Eigen/src/misc/blas.h
new file mode 100644
index 000000000..25215b15e
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/misc/blas.h
@@ -0,0 +1,440 @@
+#ifndef BLAS_H
+#define BLAS_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define BLASFUNC(FUNC) FUNC##_
+
+#ifdef __WIN64__
+typedef long long BLASLONG;
+typedef unsigned long long BLASULONG;
+#else
+typedef long BLASLONG;
+typedef unsigned long BLASULONG;
+#endif
+
+int BLASFUNC(xerbla)(const char *, int *info, int);
+
+float BLASFUNC(sdot) (int *, float *, int *, float *, int *);
+float BLASFUNC(sdsdot)(int *, float *, float *, int *, float *, int *);
+
+double BLASFUNC(dsdot) (int *, float *, int *, float *, int *);
+double BLASFUNC(ddot) (int *, double *, int *, double *, int *);
+double BLASFUNC(qdot) (int *, double *, int *, double *, int *);
+
+int BLASFUNC(cdotuw) (int *, float *, int *, float *, int *, float*);
+int BLASFUNC(cdotcw) (int *, float *, int *, float *, int *, float*);
+int BLASFUNC(zdotuw) (int *, double *, int *, double *, int *, double*);
+int BLASFUNC(zdotcw) (int *, double *, int *, double *, int *, double*);
+
+int BLASFUNC(saxpy) (const int *, const float *, const float *, const int *, float *, const int *);
+int BLASFUNC(daxpy) (const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(qaxpy) (const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(caxpy) (const int *, const float *, const float *, const int *, float *, const int *);
+int BLASFUNC(zaxpy) (const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(xaxpy) (const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(caxpyc)(const int *, const float *, const float *, const int *, float *, const int *);
+int BLASFUNC(zaxpyc)(const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(xaxpyc)(const int *, const double *, const double *, const int *, double *, const int *);
+
+int BLASFUNC(scopy) (int *, float *, int *, float *, int *);
+int BLASFUNC(dcopy) (int *, double *, int *, double *, int *);
+int BLASFUNC(qcopy) (int *, double *, int *, double *, int *);
+int BLASFUNC(ccopy) (int *, float *, int *, float *, int *);
+int BLASFUNC(zcopy) (int *, double *, int *, double *, int *);
+int BLASFUNC(xcopy) (int *, double *, int *, double *, int *);
+
+int BLASFUNC(sswap) (int *, float *, int *, float *, int *);
+int BLASFUNC(dswap) (int *, double *, int *, double *, int *);
+int BLASFUNC(qswap) (int *, double *, int *, double *, int *);
+int BLASFUNC(cswap) (int *, float *, int *, float *, int *);
+int BLASFUNC(zswap) (int *, double *, int *, double *, int *);
+int BLASFUNC(xswap) (int *, double *, int *, double *, int *);
+
+float BLASFUNC(sasum) (int *, float *, int *);
+float BLASFUNC(scasum)(int *, float *, int *);
+double BLASFUNC(dasum) (int *, double *, int *);
+double BLASFUNC(qasum) (int *, double *, int *);
+double BLASFUNC(dzasum)(int *, double *, int *);
+double BLASFUNC(qxasum)(int *, double *, int *);
+
+int BLASFUNC(isamax)(int *, float *, int *);
+int BLASFUNC(idamax)(int *, double *, int *);
+int BLASFUNC(iqamax)(int *, double *, int *);
+int BLASFUNC(icamax)(int *, float *, int *);
+int BLASFUNC(izamax)(int *, double *, int *);
+int BLASFUNC(ixamax)(int *, double *, int *);
+
+int BLASFUNC(ismax) (int *, float *, int *);
+int BLASFUNC(idmax) (int *, double *, int *);
+int BLASFUNC(iqmax) (int *, double *, int *);
+int BLASFUNC(icmax) (int *, float *, int *);
+int BLASFUNC(izmax) (int *, double *, int *);
+int BLASFUNC(ixmax) (int *, double *, int *);
+
+int BLASFUNC(isamin)(int *, float *, int *);
+int BLASFUNC(idamin)(int *, double *, int *);
+int BLASFUNC(iqamin)(int *, double *, int *);
+int BLASFUNC(icamin)(int *, float *, int *);
+int BLASFUNC(izamin)(int *, double *, int *);
+int BLASFUNC(ixamin)(int *, double *, int *);
+
+int BLASFUNC(ismin)(int *, float *, int *);
+int BLASFUNC(idmin)(int *, double *, int *);
+int BLASFUNC(iqmin)(int *, double *, int *);
+int BLASFUNC(icmin)(int *, float *, int *);
+int BLASFUNC(izmin)(int *, double *, int *);
+int BLASFUNC(ixmin)(int *, double *, int *);
+
+float BLASFUNC(samax) (int *, float *, int *);
+double BLASFUNC(damax) (int *, double *, int *);
+double BLASFUNC(qamax) (int *, double *, int *);
+float BLASFUNC(scamax)(int *, float *, int *);
+double BLASFUNC(dzamax)(int *, double *, int *);
+double BLASFUNC(qxamax)(int *, double *, int *);
+
+float BLASFUNC(samin) (int *, float *, int *);
+double BLASFUNC(damin) (int *, double *, int *);
+double BLASFUNC(qamin) (int *, double *, int *);
+float BLASFUNC(scamin)(int *, float *, int *);
+double BLASFUNC(dzamin)(int *, double *, int *);
+double BLASFUNC(qxamin)(int *, double *, int *);
+
+float BLASFUNC(smax) (int *, float *, int *);
+double BLASFUNC(dmax) (int *, double *, int *);
+double BLASFUNC(qmax) (int *, double *, int *);
+float BLASFUNC(scmax) (int *, float *, int *);
+double BLASFUNC(dzmax) (int *, double *, int *);
+double BLASFUNC(qxmax) (int *, double *, int *);
+
+float BLASFUNC(smin) (int *, float *, int *);
+double BLASFUNC(dmin) (int *, double *, int *);
+double BLASFUNC(qmin) (int *, double *, int *);
+float BLASFUNC(scmin) (int *, float *, int *);
+double BLASFUNC(dzmin) (int *, double *, int *);
+double BLASFUNC(qxmin) (int *, double *, int *);
+
+int BLASFUNC(sscal) (int *, float *, float *, int *);
+int BLASFUNC(dscal) (int *, double *, double *, int *);
+int BLASFUNC(qscal) (int *, double *, double *, int *);
+int BLASFUNC(cscal) (int *, float *, float *, int *);
+int BLASFUNC(zscal) (int *, double *, double *, int *);
+int BLASFUNC(xscal) (int *, double *, double *, int *);
+int BLASFUNC(csscal)(int *, float *, float *, int *);
+int BLASFUNC(zdscal)(int *, double *, double *, int *);
+int BLASFUNC(xqscal)(int *, double *, double *, int *);
+
+float BLASFUNC(snrm2) (int *, float *, int *);
+float BLASFUNC(scnrm2)(int *, float *, int *);
+
+double BLASFUNC(dnrm2) (int *, double *, int *);
+double BLASFUNC(qnrm2) (int *, double *, int *);
+double BLASFUNC(dznrm2)(int *, double *, int *);
+double BLASFUNC(qxnrm2)(int *, double *, int *);
+
+int BLASFUNC(srot) (int *, float *, int *, float *, int *, float *, float *);
+int BLASFUNC(drot) (int *, double *, int *, double *, int *, double *, double *);
+int BLASFUNC(qrot) (int *, double *, int *, double *, int *, double *, double *);
+int BLASFUNC(csrot) (int *, float *, int *, float *, int *, float *, float *);
+int BLASFUNC(zdrot) (int *, double *, int *, double *, int *, double *, double *);
+int BLASFUNC(xqrot) (int *, double *, int *, double *, int *, double *, double *);
+
+int BLASFUNC(srotg) (float *, float *, float *, float *);
+int BLASFUNC(drotg) (double *, double *, double *, double *);
+int BLASFUNC(qrotg) (double *, double *, double *, double *);
+int BLASFUNC(crotg) (float *, float *, float *, float *);
+int BLASFUNC(zrotg) (double *, double *, double *, double *);
+int BLASFUNC(xrotg) (double *, double *, double *, double *);
+
+int BLASFUNC(srotmg)(float *, float *, float *, float *, float *);
+int BLASFUNC(drotmg)(double *, double *, double *, double *, double *);
+
+int BLASFUNC(srotm) (int *, float *, int *, float *, int *, float *);
+int BLASFUNC(drotm) (int *, double *, int *, double *, int *, double *);
+int BLASFUNC(qrotm) (int *, double *, int *, double *, int *, double *);
+
+/* Level 2 routines */
+
+int BLASFUNC(sger)(int *, int *, float *, float *, int *,
+ float *, int *, float *, int *);
+int BLASFUNC(dger)(int *, int *, double *, double *, int *,
+ double *, int *, double *, int *);
+int BLASFUNC(qger)(int *, int *, double *, double *, int *,
+ double *, int *, double *, int *);
+int BLASFUNC(cgeru)(int *, int *, float *, float *, int *,
+ float *, int *, float *, int *);
+int BLASFUNC(cgerc)(int *, int *, float *, float *, int *,
+ float *, int *, float *, int *);
+int BLASFUNC(zgeru)(int *, int *, double *, double *, int *,
+ double *, int *, double *, int *);
+int BLASFUNC(zgerc)(int *, int *, double *, double *, int *,
+ double *, int *, double *, int *);
+int BLASFUNC(xgeru)(int *, int *, double *, double *, int *,
+ double *, int *, double *, int *);
+int BLASFUNC(xgerc)(int *, int *, double *, double *, int *,
+ double *, int *, double *, int *);
+
+int BLASFUNC(sgemv)(const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(dgemv)(const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(qgemv)(const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(cgemv)(const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(zgemv)(const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(xgemv)(const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+
+int BLASFUNC(strsv) (const char *, const char *, const char *, const int *, const float *, const int *, float *, const int *);
+int BLASFUNC(dtrsv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *);
+int BLASFUNC(qtrsv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *);
+int BLASFUNC(ctrsv) (const char *, const char *, const char *, const int *, const float *, const int *, float *, const int *);
+int BLASFUNC(ztrsv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *);
+int BLASFUNC(xtrsv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *);
+
+int BLASFUNC(stpsv) (char *, char *, char *, int *, float *, float *, int *);
+int BLASFUNC(dtpsv) (char *, char *, char *, int *, double *, double *, int *);
+int BLASFUNC(qtpsv) (char *, char *, char *, int *, double *, double *, int *);
+int BLASFUNC(ctpsv) (char *, char *, char *, int *, float *, float *, int *);
+int BLASFUNC(ztpsv) (char *, char *, char *, int *, double *, double *, int *);
+int BLASFUNC(xtpsv) (char *, char *, char *, int *, double *, double *, int *);
+
+int BLASFUNC(strmv) (const char *, const char *, const char *, const int *, const float *, const int *, float *, const int *);
+int BLASFUNC(dtrmv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *);
+int BLASFUNC(qtrmv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *);
+int BLASFUNC(ctrmv) (const char *, const char *, const char *, const int *, const float *, const int *, float *, const int *);
+int BLASFUNC(ztrmv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *);
+int BLASFUNC(xtrmv) (const char *, const char *, const char *, const int *, const double *, const int *, double *, const int *);
+
+int BLASFUNC(stpmv) (char *, char *, char *, int *, float *, float *, int *);
+int BLASFUNC(dtpmv) (char *, char *, char *, int *, double *, double *, int *);
+int BLASFUNC(qtpmv) (char *, char *, char *, int *, double *, double *, int *);
+int BLASFUNC(ctpmv) (char *, char *, char *, int *, float *, float *, int *);
+int BLASFUNC(ztpmv) (char *, char *, char *, int *, double *, double *, int *);
+int BLASFUNC(xtpmv) (char *, char *, char *, int *, double *, double *, int *);
+
+int BLASFUNC(stbmv) (char *, char *, char *, int *, int *, float *, int *, float *, int *);
+int BLASFUNC(dtbmv) (char *, char *, char *, int *, int *, double *, int *, double *, int *);
+int BLASFUNC(qtbmv) (char *, char *, char *, int *, int *, double *, int *, double *, int *);
+int BLASFUNC(ctbmv) (char *, char *, char *, int *, int *, float *, int *, float *, int *);
+int BLASFUNC(ztbmv) (char *, char *, char *, int *, int *, double *, int *, double *, int *);
+int BLASFUNC(xtbmv) (char *, char *, char *, int *, int *, double *, int *, double *, int *);
+
+int BLASFUNC(stbsv) (char *, char *, char *, int *, int *, float *, int *, float *, int *);
+int BLASFUNC(dtbsv) (char *, char *, char *, int *, int *, double *, int *, double *, int *);
+int BLASFUNC(qtbsv) (char *, char *, char *, int *, int *, double *, int *, double *, int *);
+int BLASFUNC(ctbsv) (char *, char *, char *, int *, int *, float *, int *, float *, int *);
+int BLASFUNC(ztbsv) (char *, char *, char *, int *, int *, double *, int *, double *, int *);
+int BLASFUNC(xtbsv) (char *, char *, char *, int *, int *, double *, int *, double *, int *);
+
+int BLASFUNC(ssymv) (const char *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(dsymv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(qsymv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+
+int BLASFUNC(sspmv) (char *, int *, float *, float *,
+ float *, int *, float *, float *, int *);
+int BLASFUNC(dspmv) (char *, int *, double *, double *,
+ double *, int *, double *, double *, int *);
+int BLASFUNC(qspmv) (char *, int *, double *, double *,
+ double *, int *, double *, double *, int *);
+
+int BLASFUNC(ssyr) (const char *, const int *, const float *, const float *, const int *, float *, const int *);
+int BLASFUNC(dsyr) (const char *, const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(qsyr) (const char *, const int *, const double *, const double *, const int *, double *, const int *);
+
+int BLASFUNC(ssyr2) (const char *, const int *, const float *, const float *, const int *, const float *, const int *, float *, const int *);
+int BLASFUNC(dsyr2) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, double *, const int *);
+int BLASFUNC(qsyr2) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, double *, const int *);
+int BLASFUNC(csyr2) (const char *, const int *, const float *, const float *, const int *, const float *, const int *, float *, const int *);
+int BLASFUNC(zsyr2) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, double *, const int *);
+int BLASFUNC(xsyr2) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, double *, const int *);
+
+int BLASFUNC(sspr) (char *, int *, float *, float *, int *,
+ float *);
+int BLASFUNC(dspr) (char *, int *, double *, double *, int *,
+ double *);
+int BLASFUNC(qspr) (char *, int *, double *, double *, int *,
+ double *);
+
+int BLASFUNC(sspr2) (char *, int *, float *,
+ float *, int *, float *, int *, float *);
+int BLASFUNC(dspr2) (char *, int *, double *,
+ double *, int *, double *, int *, double *);
+int BLASFUNC(qspr2) (char *, int *, double *,
+ double *, int *, double *, int *, double *);
+int BLASFUNC(cspr2) (char *, int *, float *,
+ float *, int *, float *, int *, float *);
+int BLASFUNC(zspr2) (char *, int *, double *,
+ double *, int *, double *, int *, double *);
+int BLASFUNC(xspr2) (char *, int *, double *,
+ double *, int *, double *, int *, double *);
+
+int BLASFUNC(cher) (char *, int *, float *, float *, int *,
+ float *, int *);
+int BLASFUNC(zher) (char *, int *, double *, double *, int *,
+ double *, int *);
+int BLASFUNC(xher) (char *, int *, double *, double *, int *,
+ double *, int *);
+
+int BLASFUNC(chpr) (char *, int *, float *, float *, int *, float *);
+int BLASFUNC(zhpr) (char *, int *, double *, double *, int *, double *);
+int BLASFUNC(xhpr) (char *, int *, double *, double *, int *, double *);
+
+int BLASFUNC(cher2) (char *, int *, float *,
+ float *, int *, float *, int *, float *, int *);
+int BLASFUNC(zher2) (char *, int *, double *,
+ double *, int *, double *, int *, double *, int *);
+int BLASFUNC(xher2) (char *, int *, double *,
+ double *, int *, double *, int *, double *, int *);
+
+int BLASFUNC(chpr2) (char *, int *, float *,
+ float *, int *, float *, int *, float *);
+int BLASFUNC(zhpr2) (char *, int *, double *,
+ double *, int *, double *, int *, double *);
+int BLASFUNC(xhpr2) (char *, int *, double *,
+ double *, int *, double *, int *, double *);
+
+int BLASFUNC(chemv) (const char *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(zhemv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(xhemv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+
+int BLASFUNC(chpmv) (char *, int *, float *, float *,
+ float *, int *, float *, float *, int *);
+int BLASFUNC(zhpmv) (char *, int *, double *, double *,
+ double *, int *, double *, double *, int *);
+int BLASFUNC(xhpmv) (char *, int *, double *, double *,
+ double *, int *, double *, double *, int *);
+
+int BLASFUNC(snorm)(char *, int *, int *, float *, int *);
+int BLASFUNC(dnorm)(char *, int *, int *, double *, int *);
+int BLASFUNC(cnorm)(char *, int *, int *, float *, int *);
+int BLASFUNC(znorm)(char *, int *, int *, double *, int *);
+
+int BLASFUNC(sgbmv)(char *, int *, int *, int *, int *, float *, float *, int *,
+ float *, int *, float *, float *, int *);
+int BLASFUNC(dgbmv)(char *, int *, int *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+int BLASFUNC(qgbmv)(char *, int *, int *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+int BLASFUNC(cgbmv)(char *, int *, int *, int *, int *, float *, float *, int *,
+ float *, int *, float *, float *, int *);
+int BLASFUNC(zgbmv)(char *, int *, int *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+int BLASFUNC(xgbmv)(char *, int *, int *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+
+int BLASFUNC(ssbmv)(char *, int *, int *, float *, float *, int *,
+ float *, int *, float *, float *, int *);
+int BLASFUNC(dsbmv)(char *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+int BLASFUNC(qsbmv)(char *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+int BLASFUNC(csbmv)(char *, int *, int *, float *, float *, int *,
+ float *, int *, float *, float *, int *);
+int BLASFUNC(zsbmv)(char *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+int BLASFUNC(xsbmv)(char *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+
+int BLASFUNC(chbmv)(char *, int *, int *, float *, float *, int *,
+ float *, int *, float *, float *, int *);
+int BLASFUNC(zhbmv)(char *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+int BLASFUNC(xhbmv)(char *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+
+/* Level 3 routines */
+
+int BLASFUNC(sgemm)(const char *, const char *, const int *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(dgemm)(const char *, const char *, const int *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(qgemm)(const char *, const char *, const int *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(cgemm)(const char *, const char *, const int *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(zgemm)(const char *, const char *, const int *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(xgemm)(const char *, const char *, const int *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+
+int BLASFUNC(cgemm3m)(char *, char *, int *, int *, int *, float *,
+ float *, int *, float *, int *, float *, float *, int *);
+int BLASFUNC(zgemm3m)(char *, char *, int *, int *, int *, double *,
+ double *, int *, double *, int *, double *, double *, int *);
+int BLASFUNC(xgemm3m)(char *, char *, int *, int *, int *, double *,
+ double *, int *, double *, int *, double *, double *, int *);
+
+int BLASFUNC(sge2mm)(char *, char *, char *, int *, int *,
+ float *, float *, int *, float *, int *,
+ float *, float *, int *);
+int BLASFUNC(dge2mm)(char *, char *, char *, int *, int *,
+ double *, double *, int *, double *, int *,
+ double *, double *, int *);
+int BLASFUNC(cge2mm)(char *, char *, char *, int *, int *,
+ float *, float *, int *, float *, int *,
+ float *, float *, int *);
+int BLASFUNC(zge2mm)(char *, char *, char *, int *, int *,
+ double *, double *, int *, double *, int *,
+ double *, double *, int *);
+
+int BLASFUNC(strsm)(const char *, const char *, const char *, const char *, const int *, const int *, const float *, const float *, const int *, float *, const int *);
+int BLASFUNC(dtrsm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(qtrsm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(ctrsm)(const char *, const char *, const char *, const char *, const int *, const int *, const float *, const float *, const int *, float *, const int *);
+int BLASFUNC(ztrsm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(xtrsm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *);
+
+int BLASFUNC(strmm)(const char *, const char *, const char *, const char *, const int *, const int *, const float *, const float *, const int *, float *, const int *);
+int BLASFUNC(dtrmm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(qtrmm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(ctrmm)(const char *, const char *, const char *, const char *, const int *, const int *, const float *, const float *, const int *, float *, const int *);
+int BLASFUNC(ztrmm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *);
+int BLASFUNC(xtrmm)(const char *, const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, double *, const int *);
+
+int BLASFUNC(ssymm)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(dsymm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(qsymm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(csymm)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(zsymm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(xsymm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+
+int BLASFUNC(csymm3m)(char *, char *, int *, int *, float *, float *, int *, float *, int *, float *, float *, int *);
+int BLASFUNC(zsymm3m)(char *, char *, int *, int *, double *, double *, int *, double *, int *, double *, double *, int *);
+int BLASFUNC(xsymm3m)(char *, char *, int *, int *, double *, double *, int *, double *, int *, double *, double *, int *);
+
+int BLASFUNC(ssyrk)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(dsyrk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(qsyrk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(csyrk)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(zsyrk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(xsyrk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *);
+
+int BLASFUNC(ssyr2k)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(dsyr2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *);
+int BLASFUNC(qsyr2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *);
+int BLASFUNC(csyr2k)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(zsyr2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *);
+int BLASFUNC(xsyr2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *);
+
+int BLASFUNC(chemm)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(zhemm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(xhemm)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+
+int BLASFUNC(chemm3m)(char *, char *, int *, int *, float *, float *, int *,
+ float *, int *, float *, float *, int *);
+int BLASFUNC(zhemm3m)(char *, char *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+int BLASFUNC(xhemm3m)(char *, char *, int *, int *, double *, double *, int *,
+ double *, int *, double *, double *, int *);
+
+int BLASFUNC(cherk)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(zherk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(xherk)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, double *, const int *);
+
+int BLASFUNC(cher2k)(const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(zher2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(xher2k)(const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(cher2m)(const char *, const char *, const char *, const int *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(zher2m)(const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *);
+int BLASFUNC(xher2m)(const char *, const char *, const char *, const int *, const int *, const double *, const double *, const int *, const double*, const int *, const double *, double *, const int *);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/3rdparty/eigen/Eigen/src/misc/lapack.h b/src/3rdparty/eigen/Eigen/src/misc/lapack.h
new file mode 100644
index 000000000..249f3575c
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/misc/lapack.h
@@ -0,0 +1,152 @@
+#ifndef LAPACK_H
+#define LAPACK_H
+
+#include "blas.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+int BLASFUNC(csymv) (const char *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *);
+int BLASFUNC(zsymv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+int BLASFUNC(xsymv) (const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *);
+
+
+int BLASFUNC(cspmv) (char *, int *, float *, float *,
+ float *, int *, float *, float *, int *);
+int BLASFUNC(zspmv) (char *, int *, double *, double *,
+ double *, int *, double *, double *, int *);
+int BLASFUNC(xspmv) (char *, int *, double *, double *,
+ double *, int *, double *, double *, int *);
+
+int BLASFUNC(csyr) (char *, int *, float *, float *, int *,
+ float *, int *);
+int BLASFUNC(zsyr) (char *, int *, double *, double *, int *,
+ double *, int *);
+int BLASFUNC(xsyr) (char *, int *, double *, double *, int *,
+ double *, int *);
+
+int BLASFUNC(cspr) (char *, int *, float *, float *, int *,
+ float *);
+int BLASFUNC(zspr) (char *, int *, double *, double *, int *,
+ double *);
+int BLASFUNC(xspr) (char *, int *, double *, double *, int *,
+ double *);
+
+int BLASFUNC(sgemt)(char *, int *, int *, float *, float *, int *,
+ float *, int *);
+int BLASFUNC(dgemt)(char *, int *, int *, double *, double *, int *,
+ double *, int *);
+int BLASFUNC(cgemt)(char *, int *, int *, float *, float *, int *,
+ float *, int *);
+int BLASFUNC(zgemt)(char *, int *, int *, double *, double *, int *,
+ double *, int *);
+
+int BLASFUNC(sgema)(char *, char *, int *, int *, float *,
+ float *, int *, float *, float *, int *, float *, int *);
+int BLASFUNC(dgema)(char *, char *, int *, int *, double *,
+ double *, int *, double*, double *, int *, double*, int *);
+int BLASFUNC(cgema)(char *, char *, int *, int *, float *,
+ float *, int *, float *, float *, int *, float *, int *);
+int BLASFUNC(zgema)(char *, char *, int *, int *, double *,
+ double *, int *, double*, double *, int *, double*, int *);
+
+int BLASFUNC(sgems)(char *, char *, int *, int *, float *,
+ float *, int *, float *, float *, int *, float *, int *);
+int BLASFUNC(dgems)(char *, char *, int *, int *, double *,
+ double *, int *, double*, double *, int *, double*, int *);
+int BLASFUNC(cgems)(char *, char *, int *, int *, float *,
+ float *, int *, float *, float *, int *, float *, int *);
+int BLASFUNC(zgems)(char *, char *, int *, int *, double *,
+ double *, int *, double*, double *, int *, double*, int *);
+
+int BLASFUNC(sgetf2)(int *, int *, float *, int *, int *, int *);
+int BLASFUNC(dgetf2)(int *, int *, double *, int *, int *, int *);
+int BLASFUNC(qgetf2)(int *, int *, double *, int *, int *, int *);
+int BLASFUNC(cgetf2)(int *, int *, float *, int *, int *, int *);
+int BLASFUNC(zgetf2)(int *, int *, double *, int *, int *, int *);
+int BLASFUNC(xgetf2)(int *, int *, double *, int *, int *, int *);
+
+int BLASFUNC(sgetrf)(int *, int *, float *, int *, int *, int *);
+int BLASFUNC(dgetrf)(int *, int *, double *, int *, int *, int *);
+int BLASFUNC(qgetrf)(int *, int *, double *, int *, int *, int *);
+int BLASFUNC(cgetrf)(int *, int *, float *, int *, int *, int *);
+int BLASFUNC(zgetrf)(int *, int *, double *, int *, int *, int *);
+int BLASFUNC(xgetrf)(int *, int *, double *, int *, int *, int *);
+
+int BLASFUNC(slaswp)(int *, float *, int *, int *, int *, int *, int *);
+int BLASFUNC(dlaswp)(int *, double *, int *, int *, int *, int *, int *);
+int BLASFUNC(qlaswp)(int *, double *, int *, int *, int *, int *, int *);
+int BLASFUNC(claswp)(int *, float *, int *, int *, int *, int *, int *);
+int BLASFUNC(zlaswp)(int *, double *, int *, int *, int *, int *, int *);
+int BLASFUNC(xlaswp)(int *, double *, int *, int *, int *, int *, int *);
+
+int BLASFUNC(sgetrs)(char *, int *, int *, float *, int *, int *, float *, int *, int *);
+int BLASFUNC(dgetrs)(char *, int *, int *, double *, int *, int *, double *, int *, int *);
+int BLASFUNC(qgetrs)(char *, int *, int *, double *, int *, int *, double *, int *, int *);
+int BLASFUNC(cgetrs)(char *, int *, int *, float *, int *, int *, float *, int *, int *);
+int BLASFUNC(zgetrs)(char *, int *, int *, double *, int *, int *, double *, int *, int *);
+int BLASFUNC(xgetrs)(char *, int *, int *, double *, int *, int *, double *, int *, int *);
+
+int BLASFUNC(sgesv)(int *, int *, float *, int *, int *, float *, int *, int *);
+int BLASFUNC(dgesv)(int *, int *, double *, int *, int *, double*, int *, int *);
+int BLASFUNC(qgesv)(int *, int *, double *, int *, int *, double*, int *, int *);
+int BLASFUNC(cgesv)(int *, int *, float *, int *, int *, float *, int *, int *);
+int BLASFUNC(zgesv)(int *, int *, double *, int *, int *, double*, int *, int *);
+int BLASFUNC(xgesv)(int *, int *, double *, int *, int *, double*, int *, int *);
+
+int BLASFUNC(spotf2)(char *, int *, float *, int *, int *);
+int BLASFUNC(dpotf2)(char *, int *, double *, int *, int *);
+int BLASFUNC(qpotf2)(char *, int *, double *, int *, int *);
+int BLASFUNC(cpotf2)(char *, int *, float *, int *, int *);
+int BLASFUNC(zpotf2)(char *, int *, double *, int *, int *);
+int BLASFUNC(xpotf2)(char *, int *, double *, int *, int *);
+
+int BLASFUNC(spotrf)(char *, int *, float *, int *, int *);
+int BLASFUNC(dpotrf)(char *, int *, double *, int *, int *);
+int BLASFUNC(qpotrf)(char *, int *, double *, int *, int *);
+int BLASFUNC(cpotrf)(char *, int *, float *, int *, int *);
+int BLASFUNC(zpotrf)(char *, int *, double *, int *, int *);
+int BLASFUNC(xpotrf)(char *, int *, double *, int *, int *);
+
+int BLASFUNC(slauu2)(char *, int *, float *, int *, int *);
+int BLASFUNC(dlauu2)(char *, int *, double *, int *, int *);
+int BLASFUNC(qlauu2)(char *, int *, double *, int *, int *);
+int BLASFUNC(clauu2)(char *, int *, float *, int *, int *);
+int BLASFUNC(zlauu2)(char *, int *, double *, int *, int *);
+int BLASFUNC(xlauu2)(char *, int *, double *, int *, int *);
+
+int BLASFUNC(slauum)(char *, int *, float *, int *, int *);
+int BLASFUNC(dlauum)(char *, int *, double *, int *, int *);
+int BLASFUNC(qlauum)(char *, int *, double *, int *, int *);
+int BLASFUNC(clauum)(char *, int *, float *, int *, int *);
+int BLASFUNC(zlauum)(char *, int *, double *, int *, int *);
+int BLASFUNC(xlauum)(char *, int *, double *, int *, int *);
+
+int BLASFUNC(strti2)(char *, char *, int *, float *, int *, int *);
+int BLASFUNC(dtrti2)(char *, char *, int *, double *, int *, int *);
+int BLASFUNC(qtrti2)(char *, char *, int *, double *, int *, int *);
+int BLASFUNC(ctrti2)(char *, char *, int *, float *, int *, int *);
+int BLASFUNC(ztrti2)(char *, char *, int *, double *, int *, int *);
+int BLASFUNC(xtrti2)(char *, char *, int *, double *, int *, int *);
+
+int BLASFUNC(strtri)(char *, char *, int *, float *, int *, int *);
+int BLASFUNC(dtrtri)(char *, char *, int *, double *, int *, int *);
+int BLASFUNC(qtrtri)(char *, char *, int *, double *, int *, int *);
+int BLASFUNC(ctrtri)(char *, char *, int *, float *, int *, int *);
+int BLASFUNC(ztrtri)(char *, char *, int *, double *, int *, int *);
+int BLASFUNC(xtrtri)(char *, char *, int *, double *, int *, int *);
+
+int BLASFUNC(spotri)(char *, int *, float *, int *, int *);
+int BLASFUNC(dpotri)(char *, int *, double *, int *, int *);
+int BLASFUNC(qpotri)(char *, int *, double *, int *, int *);
+int BLASFUNC(cpotri)(char *, int *, float *, int *, int *);
+int BLASFUNC(zpotri)(char *, int *, double *, int *, int *);
+int BLASFUNC(xpotri)(char *, int *, double *, int *, int *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/3rdparty/eigen/Eigen/src/misc/lapacke.h b/src/3rdparty/eigen/Eigen/src/misc/lapacke.h
new file mode 100644
index 000000000..3d8e24f5a
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/misc/lapacke.h
@@ -0,0 +1,16292 @@
+/*****************************************************************************
+ Copyright (c) 2010, Intel Corp.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ THE POSSIBILITY OF SUCH DAMAGE.
+******************************************************************************
+* Contents: Native C interface to LAPACK
+* Author: Intel Corporation
+* Generated November, 2011
+*****************************************************************************/
+
+#ifndef _MKL_LAPACKE_H_
+
+#ifndef _LAPACKE_H_
+#define _LAPACKE_H_
+
+/*
+* Turn on HAVE_LAPACK_CONFIG_H to redefine C-LAPACK datatypes
+*/
+#ifdef HAVE_LAPACK_CONFIG_H
+#include "lapacke_config.h"
+#endif
+
+#include <stdlib.h>
+
+#ifndef lapack_int
+#define lapack_int int
+#endif
+
+#ifndef lapack_logical
+#define lapack_logical lapack_int
+#endif
+
+/* Complex types are structures equivalent to the
+* Fortran complex types COMPLEX(4) and COMPLEX(8).
+*
+* One can also redefine the types with his own types
+* for example by including in the code definitions like
+*
+* #define lapack_complex_float std::complex<float>
+* #define lapack_complex_double std::complex<double>
+*
+* or define these types in the command line:
+*
+* -Dlapack_complex_float="std::complex<float>"
+* -Dlapack_complex_double="std::complex<double>"
+*/
+
+#ifndef LAPACK_COMPLEX_CUSTOM
+
+/* Complex type (single precision) */
+#ifndef lapack_complex_float
+#include <complex.h>
+#define lapack_complex_float float _Complex
+#endif
+
+#ifndef lapack_complex_float_real
+#define lapack_complex_float_real(z) (creal(z))
+#endif
+
+#ifndef lapack_complex_float_imag
+#define lapack_complex_float_imag(z) (cimag(z))
+#endif
+
+lapack_complex_float lapack_make_complex_float( float re, float im );
+
+/* Complex type (double precision) */
+#ifndef lapack_complex_double
+#include <complex.h>
+#define lapack_complex_double double _Complex
+#endif
+
+#ifndef lapack_complex_double_real
+#define lapack_complex_double_real(z) (creal(z))
+#endif
+
+#ifndef lapack_complex_double_imag
+#define lapack_complex_double_imag(z) (cimag(z))
+#endif
+
+lapack_complex_double lapack_make_complex_double( double re, double im );
+
+#endif
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#ifndef LAPACKE_malloc
+#define LAPACKE_malloc( size ) malloc( size )
+#endif
+#ifndef LAPACKE_free
+#define LAPACKE_free( p ) free( p )
+#endif
+
+#define LAPACK_C2INT( x ) (lapack_int)(*((float*)&x ))
+#define LAPACK_Z2INT( x ) (lapack_int)(*((double*)&x ))
+
+#define LAPACK_ROW_MAJOR 101
+#define LAPACK_COL_MAJOR 102
+
+#define LAPACK_WORK_MEMORY_ERROR -1010
+#define LAPACK_TRANSPOSE_MEMORY_ERROR -1011
+
+/* Callback logical functions of one, two, or three arguments are used
+* to select eigenvalues to sort to the top left of the Schur form.
+* The value is selected if function returns TRUE (non-zero). */
+
+typedef lapack_logical (*LAPACK_S_SELECT2) ( const float*, const float* );
+typedef lapack_logical (*LAPACK_S_SELECT3)
+ ( const float*, const float*, const float* );
+typedef lapack_logical (*LAPACK_D_SELECT2) ( const double*, const double* );
+typedef lapack_logical (*LAPACK_D_SELECT3)
+ ( const double*, const double*, const double* );
+
+typedef lapack_logical (*LAPACK_C_SELECT1) ( const lapack_complex_float* );
+typedef lapack_logical (*LAPACK_C_SELECT2)
+ ( const lapack_complex_float*, const lapack_complex_float* );
+typedef lapack_logical (*LAPACK_Z_SELECT1) ( const lapack_complex_double* );
+typedef lapack_logical (*LAPACK_Z_SELECT2)
+ ( const lapack_complex_double*, const lapack_complex_double* );
+
+#include "lapacke_mangling.h"
+
+#define LAPACK_lsame LAPACK_GLOBAL(lsame,LSAME)
+lapack_logical LAPACK_lsame( char* ca, char* cb,
+ lapack_int lca, lapack_int lcb );
+
+/* C-LAPACK function prototypes */
+
+lapack_int LAPACKE_sbdsdc( int matrix_order, char uplo, char compq,
+ lapack_int n, float* d, float* e, float* u,
+ lapack_int ldu, float* vt, lapack_int ldvt, float* q,
+ lapack_int* iq );
+lapack_int LAPACKE_dbdsdc( int matrix_order, char uplo, char compq,
+ lapack_int n, double* d, double* e, double* u,
+ lapack_int ldu, double* vt, lapack_int ldvt,
+ double* q, lapack_int* iq );
+
+lapack_int LAPACKE_sbdsqr( int matrix_order, char uplo, lapack_int n,
+ lapack_int ncvt, lapack_int nru, lapack_int ncc,
+ float* d, float* e, float* vt, lapack_int ldvt,
+ float* u, lapack_int ldu, float* c, lapack_int ldc );
+lapack_int LAPACKE_dbdsqr( int matrix_order, char uplo, lapack_int n,
+ lapack_int ncvt, lapack_int nru, lapack_int ncc,
+ double* d, double* e, double* vt, lapack_int ldvt,
+ double* u, lapack_int ldu, double* c,
+ lapack_int ldc );
+lapack_int LAPACKE_cbdsqr( int matrix_order, char uplo, lapack_int n,
+ lapack_int ncvt, lapack_int nru, lapack_int ncc,
+ float* d, float* e, lapack_complex_float* vt,
+ lapack_int ldvt, lapack_complex_float* u,
+ lapack_int ldu, lapack_complex_float* c,
+ lapack_int ldc );
+lapack_int LAPACKE_zbdsqr( int matrix_order, char uplo, lapack_int n,
+ lapack_int ncvt, lapack_int nru, lapack_int ncc,
+ double* d, double* e, lapack_complex_double* vt,
+ lapack_int ldvt, lapack_complex_double* u,
+ lapack_int ldu, lapack_complex_double* c,
+ lapack_int ldc );
+
+lapack_int LAPACKE_sdisna( char job, lapack_int m, lapack_int n, const float* d,
+ float* sep );
+lapack_int LAPACKE_ddisna( char job, lapack_int m, lapack_int n,
+ const double* d, double* sep );
+
+lapack_int LAPACKE_sgbbrd( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int ncc, lapack_int kl,
+ lapack_int ku, float* ab, lapack_int ldab, float* d,
+ float* e, float* q, lapack_int ldq, float* pt,
+ lapack_int ldpt, float* c, lapack_int ldc );
+lapack_int LAPACKE_dgbbrd( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int ncc, lapack_int kl,
+ lapack_int ku, double* ab, lapack_int ldab,
+ double* d, double* e, double* q, lapack_int ldq,
+ double* pt, lapack_int ldpt, double* c,
+ lapack_int ldc );
+lapack_int LAPACKE_cgbbrd( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int ncc, lapack_int kl,
+ lapack_int ku, lapack_complex_float* ab,
+ lapack_int ldab, float* d, float* e,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* pt, lapack_int ldpt,
+ lapack_complex_float* c, lapack_int ldc );
+lapack_int LAPACKE_zgbbrd( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int ncc, lapack_int kl,
+ lapack_int ku, lapack_complex_double* ab,
+ lapack_int ldab, double* d, double* e,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* pt, lapack_int ldpt,
+ lapack_complex_double* c, lapack_int ldc );
+
+lapack_int LAPACKE_sgbcon( int matrix_order, char norm, lapack_int n,
+ lapack_int kl, lapack_int ku, const float* ab,
+ lapack_int ldab, const lapack_int* ipiv, float anorm,
+ float* rcond );
+lapack_int LAPACKE_dgbcon( int matrix_order, char norm, lapack_int n,
+ lapack_int kl, lapack_int ku, const double* ab,
+ lapack_int ldab, const lapack_int* ipiv,
+ double anorm, double* rcond );
+lapack_int LAPACKE_cgbcon( int matrix_order, char norm, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_float* ab, lapack_int ldab,
+ const lapack_int* ipiv, float anorm, float* rcond );
+lapack_int LAPACKE_zgbcon( int matrix_order, char norm, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_double* ab, lapack_int ldab,
+ const lapack_int* ipiv, double anorm,
+ double* rcond );
+
+lapack_int LAPACKE_sgbequ( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const float* ab,
+ lapack_int ldab, float* r, float* c, float* rowcnd,
+ float* colcnd, float* amax );
+lapack_int LAPACKE_dgbequ( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const double* ab,
+ lapack_int ldab, double* r, double* c,
+ double* rowcnd, double* colcnd, double* amax );
+lapack_int LAPACKE_cgbequ( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_float* ab, lapack_int ldab,
+ float* r, float* c, float* rowcnd, float* colcnd,
+ float* amax );
+lapack_int LAPACKE_zgbequ( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_double* ab, lapack_int ldab,
+ double* r, double* c, double* rowcnd, double* colcnd,
+ double* amax );
+
+lapack_int LAPACKE_sgbequb( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const float* ab,
+ lapack_int ldab, float* r, float* c, float* rowcnd,
+ float* colcnd, float* amax );
+lapack_int LAPACKE_dgbequb( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const double* ab,
+ lapack_int ldab, double* r, double* c,
+ double* rowcnd, double* colcnd, double* amax );
+lapack_int LAPACKE_cgbequb( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_float* ab, lapack_int ldab,
+ float* r, float* c, float* rowcnd, float* colcnd,
+ float* amax );
+lapack_int LAPACKE_zgbequb( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_double* ab, lapack_int ldab,
+ double* r, double* c, double* rowcnd,
+ double* colcnd, double* amax );
+
+lapack_int LAPACKE_sgbrfs( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const float* ab, lapack_int ldab, const float* afb,
+ lapack_int ldafb, const lapack_int* ipiv,
+ const float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* ferr, float* berr );
+lapack_int LAPACKE_dgbrfs( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const double* ab, lapack_int ldab, const double* afb,
+ lapack_int ldafb, const lapack_int* ipiv,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* ferr, double* berr );
+lapack_int LAPACKE_cgbrfs( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const lapack_complex_float* ab, lapack_int ldab,
+ const lapack_complex_float* afb, lapack_int ldafb,
+ const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zgbrfs( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const lapack_complex_double* ab, lapack_int ldab,
+ const lapack_complex_double* afb, lapack_int ldafb,
+ const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_sgbrfsx( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, const float* ab, lapack_int ldab,
+ const float* afb, lapack_int ldafb,
+ const lapack_int* ipiv, const float* r,
+ const float* c, const float* b, lapack_int ldb,
+ float* x, lapack_int ldx, float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_dgbrfsx( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, const double* ab, lapack_int ldab,
+ const double* afb, lapack_int ldafb,
+ const lapack_int* ipiv, const double* r,
+ const double* c, const double* b, lapack_int ldb,
+ double* x, lapack_int ldx, double* rcond,
+ double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params );
+lapack_int LAPACKE_cgbrfsx( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, const lapack_complex_float* ab,
+ lapack_int ldab, const lapack_complex_float* afb,
+ lapack_int ldafb, const lapack_int* ipiv,
+ const float* r, const float* c,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* berr, lapack_int n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int nparams, float* params );
+lapack_int LAPACKE_zgbrfsx( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, const lapack_complex_double* ab,
+ lapack_int ldab, const lapack_complex_double* afb,
+ lapack_int ldafb, const lapack_int* ipiv,
+ const double* r, const double* c,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params );
+
+lapack_int LAPACKE_sgbsv( int matrix_order, lapack_int n, lapack_int kl,
+ lapack_int ku, lapack_int nrhs, float* ab,
+ lapack_int ldab, lapack_int* ipiv, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dgbsv( int matrix_order, lapack_int n, lapack_int kl,
+ lapack_int ku, lapack_int nrhs, double* ab,
+ lapack_int ldab, lapack_int* ipiv, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cgbsv( int matrix_order, lapack_int n, lapack_int kl,
+ lapack_int ku, lapack_int nrhs,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zgbsv( int matrix_order, lapack_int n, lapack_int kl,
+ lapack_int ku, lapack_int nrhs,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_sgbsvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, float* ab, lapack_int ldab,
+ float* afb, lapack_int ldafb, lapack_int* ipiv,
+ char* equed, float* r, float* c, float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ float* rpivot );
+lapack_int LAPACKE_dgbsvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, double* ab, lapack_int ldab,
+ double* afb, lapack_int ldafb, lapack_int* ipiv,
+ char* equed, double* r, double* c, double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ double* rpivot );
+lapack_int LAPACKE_cgbsvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, lapack_complex_float* ab,
+ lapack_int ldab, lapack_complex_float* afb,
+ lapack_int ldafb, lapack_int* ipiv, char* equed,
+ float* r, float* c, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr, float* rpivot );
+lapack_int LAPACKE_zgbsvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, lapack_complex_double* ab,
+ lapack_int ldab, lapack_complex_double* afb,
+ lapack_int ldafb, lapack_int* ipiv, char* equed,
+ double* r, double* c, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* rcond, double* ferr,
+ double* berr, double* rpivot );
+
+lapack_int LAPACKE_sgbsvxx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, float* ab, lapack_int ldab,
+ float* afb, lapack_int ldafb, lapack_int* ipiv,
+ char* equed, float* r, float* c, float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_dgbsvxx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, double* ab, lapack_int ldab,
+ double* afb, lapack_int ldafb, lapack_int* ipiv,
+ char* equed, double* r, double* c, double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params );
+lapack_int LAPACKE_cgbsvxx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, lapack_complex_float* ab,
+ lapack_int ldab, lapack_complex_float* afb,
+ lapack_int ldafb, lapack_int* ipiv, char* equed,
+ float* r, float* c, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* rpvgrw,
+ float* berr, lapack_int n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int nparams, float* params );
+lapack_int LAPACKE_zgbsvxx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, lapack_complex_double* ab,
+ lapack_int ldab, lapack_complex_double* afb,
+ lapack_int ldafb, lapack_int* ipiv, char* equed,
+ double* r, double* c, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* rcond, double* rpvgrw,
+ double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params );
+
+lapack_int LAPACKE_sgbtrf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, float* ab,
+ lapack_int ldab, lapack_int* ipiv );
+lapack_int LAPACKE_dgbtrf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, double* ab,
+ lapack_int ldab, lapack_int* ipiv );
+lapack_int LAPACKE_cgbtrf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_int* ipiv );
+lapack_int LAPACKE_zgbtrf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_int* ipiv );
+
+lapack_int LAPACKE_sgbtrs( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const float* ab, lapack_int ldab,
+ const lapack_int* ipiv, float* b, lapack_int ldb );
+lapack_int LAPACKE_dgbtrs( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const double* ab, lapack_int ldab,
+ const lapack_int* ipiv, double* b, lapack_int ldb );
+lapack_int LAPACKE_cgbtrs( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const lapack_complex_float* ab, lapack_int ldab,
+ const lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zgbtrs( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const lapack_complex_double* ab, lapack_int ldab,
+ const lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_sgebak( int matrix_order, char job, char side, lapack_int n,
+ lapack_int ilo, lapack_int ihi, const float* scale,
+ lapack_int m, float* v, lapack_int ldv );
+lapack_int LAPACKE_dgebak( int matrix_order, char job, char side, lapack_int n,
+ lapack_int ilo, lapack_int ihi, const double* scale,
+ lapack_int m, double* v, lapack_int ldv );
+lapack_int LAPACKE_cgebak( int matrix_order, char job, char side, lapack_int n,
+ lapack_int ilo, lapack_int ihi, const float* scale,
+ lapack_int m, lapack_complex_float* v,
+ lapack_int ldv );
+lapack_int LAPACKE_zgebak( int matrix_order, char job, char side, lapack_int n,
+ lapack_int ilo, lapack_int ihi, const double* scale,
+ lapack_int m, lapack_complex_double* v,
+ lapack_int ldv );
+
+lapack_int LAPACKE_sgebal( int matrix_order, char job, lapack_int n, float* a,
+ lapack_int lda, lapack_int* ilo, lapack_int* ihi,
+ float* scale );
+lapack_int LAPACKE_dgebal( int matrix_order, char job, lapack_int n, double* a,
+ lapack_int lda, lapack_int* ilo, lapack_int* ihi,
+ double* scale );
+lapack_int LAPACKE_cgebal( int matrix_order, char job, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ilo, lapack_int* ihi, float* scale );
+lapack_int LAPACKE_zgebal( int matrix_order, char job, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ilo, lapack_int* ihi, double* scale );
+
+lapack_int LAPACKE_sgebrd( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* d, float* e,
+ float* tauq, float* taup );
+lapack_int LAPACKE_dgebrd( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* d, double* e,
+ double* tauq, double* taup );
+lapack_int LAPACKE_cgebrd( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda, float* d,
+ float* e, lapack_complex_float* tauq,
+ lapack_complex_float* taup );
+lapack_int LAPACKE_zgebrd( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda, double* d,
+ double* e, lapack_complex_double* tauq,
+ lapack_complex_double* taup );
+
+lapack_int LAPACKE_sgecon( int matrix_order, char norm, lapack_int n,
+ const float* a, lapack_int lda, float anorm,
+ float* rcond );
+lapack_int LAPACKE_dgecon( int matrix_order, char norm, lapack_int n,
+ const double* a, lapack_int lda, double anorm,
+ double* rcond );
+lapack_int LAPACKE_cgecon( int matrix_order, char norm, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float anorm, float* rcond );
+lapack_int LAPACKE_zgecon( int matrix_order, char norm, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double anorm, double* rcond );
+
+lapack_int LAPACKE_sgeequ( int matrix_order, lapack_int m, lapack_int n,
+ const float* a, lapack_int lda, float* r, float* c,
+ float* rowcnd, float* colcnd, float* amax );
+lapack_int LAPACKE_dgeequ( int matrix_order, lapack_int m, lapack_int n,
+ const double* a, lapack_int lda, double* r,
+ double* c, double* rowcnd, double* colcnd,
+ double* amax );
+lapack_int LAPACKE_cgeequ( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* r, float* c, float* rowcnd, float* colcnd,
+ float* amax );
+lapack_int LAPACKE_zgeequ( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* r, double* c, double* rowcnd, double* colcnd,
+ double* amax );
+
+lapack_int LAPACKE_sgeequb( int matrix_order, lapack_int m, lapack_int n,
+ const float* a, lapack_int lda, float* r, float* c,
+ float* rowcnd, float* colcnd, float* amax );
+lapack_int LAPACKE_dgeequb( int matrix_order, lapack_int m, lapack_int n,
+ const double* a, lapack_int lda, double* r,
+ double* c, double* rowcnd, double* colcnd,
+ double* amax );
+lapack_int LAPACKE_cgeequb( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* r, float* c, float* rowcnd, float* colcnd,
+ float* amax );
+lapack_int LAPACKE_zgeequb( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* r, double* c, double* rowcnd,
+ double* colcnd, double* amax );
+
+lapack_int LAPACKE_sgees( int matrix_order, char jobvs, char sort,
+ LAPACK_S_SELECT2 select, lapack_int n, float* a,
+ lapack_int lda, lapack_int* sdim, float* wr,
+ float* wi, float* vs, lapack_int ldvs );
+lapack_int LAPACKE_dgees( int matrix_order, char jobvs, char sort,
+ LAPACK_D_SELECT2 select, lapack_int n, double* a,
+ lapack_int lda, lapack_int* sdim, double* wr,
+ double* wi, double* vs, lapack_int ldvs );
+lapack_int LAPACKE_cgees( int matrix_order, char jobvs, char sort,
+ LAPACK_C_SELECT1 select, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* sdim, lapack_complex_float* w,
+ lapack_complex_float* vs, lapack_int ldvs );
+lapack_int LAPACKE_zgees( int matrix_order, char jobvs, char sort,
+ LAPACK_Z_SELECT1 select, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* sdim, lapack_complex_double* w,
+ lapack_complex_double* vs, lapack_int ldvs );
+
+lapack_int LAPACKE_sgeesx( int matrix_order, char jobvs, char sort,
+ LAPACK_S_SELECT2 select, char sense, lapack_int n,
+ float* a, lapack_int lda, lapack_int* sdim,
+ float* wr, float* wi, float* vs, lapack_int ldvs,
+ float* rconde, float* rcondv );
+lapack_int LAPACKE_dgeesx( int matrix_order, char jobvs, char sort,
+ LAPACK_D_SELECT2 select, char sense, lapack_int n,
+ double* a, lapack_int lda, lapack_int* sdim,
+ double* wr, double* wi, double* vs, lapack_int ldvs,
+ double* rconde, double* rcondv );
+lapack_int LAPACKE_cgeesx( int matrix_order, char jobvs, char sort,
+ LAPACK_C_SELECT1 select, char sense, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* sdim, lapack_complex_float* w,
+ lapack_complex_float* vs, lapack_int ldvs,
+ float* rconde, float* rcondv );
+lapack_int LAPACKE_zgeesx( int matrix_order, char jobvs, char sort,
+ LAPACK_Z_SELECT1 select, char sense, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* sdim, lapack_complex_double* w,
+ lapack_complex_double* vs, lapack_int ldvs,
+ double* rconde, double* rcondv );
+
+lapack_int LAPACKE_sgeev( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, float* a, lapack_int lda, float* wr,
+ float* wi, float* vl, lapack_int ldvl, float* vr,
+ lapack_int ldvr );
+lapack_int LAPACKE_dgeev( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, double* a, lapack_int lda, double* wr,
+ double* wi, double* vl, lapack_int ldvl, double* vr,
+ lapack_int ldvr );
+lapack_int LAPACKE_cgeev( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* w, lapack_complex_float* vl,
+ lapack_int ldvl, lapack_complex_float* vr,
+ lapack_int ldvr );
+lapack_int LAPACKE_zgeev( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* w,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr );
+
+lapack_int LAPACKE_sgeevx( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n, float* a,
+ lapack_int lda, float* wr, float* wi, float* vl,
+ lapack_int ldvl, float* vr, lapack_int ldvr,
+ lapack_int* ilo, lapack_int* ihi, float* scale,
+ float* abnrm, float* rconde, float* rcondv );
+lapack_int LAPACKE_dgeevx( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n, double* a,
+ lapack_int lda, double* wr, double* wi, double* vl,
+ lapack_int ldvl, double* vr, lapack_int ldvr,
+ lapack_int* ilo, lapack_int* ihi, double* scale,
+ double* abnrm, double* rconde, double* rcondv );
+lapack_int LAPACKE_cgeevx( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* w, lapack_complex_float* vl,
+ lapack_int ldvl, lapack_complex_float* vr,
+ lapack_int ldvr, lapack_int* ilo, lapack_int* ihi,
+ float* scale, float* abnrm, float* rconde,
+ float* rcondv );
+lapack_int LAPACKE_zgeevx( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* w, lapack_complex_double* vl,
+ lapack_int ldvl, lapack_complex_double* vr,
+ lapack_int ldvr, lapack_int* ilo, lapack_int* ihi,
+ double* scale, double* abnrm, double* rconde,
+ double* rcondv );
+
+lapack_int LAPACKE_sgehrd( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, float* a, lapack_int lda,
+ float* tau );
+lapack_int LAPACKE_dgehrd( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, double* a, lapack_int lda,
+ double* tau );
+lapack_int LAPACKE_cgehrd( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* tau );
+lapack_int LAPACKE_zgehrd( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* tau );
+
+lapack_int LAPACKE_sgejsv( int matrix_order, char joba, char jobu, char jobv,
+ char jobr, char jobt, char jobp, lapack_int m,
+ lapack_int n, float* a, lapack_int lda, float* sva,
+ float* u, lapack_int ldu, float* v, lapack_int ldv,
+ float* stat, lapack_int* istat );
+lapack_int LAPACKE_dgejsv( int matrix_order, char joba, char jobu, char jobv,
+ char jobr, char jobt, char jobp, lapack_int m,
+ lapack_int n, double* a, lapack_int lda, double* sva,
+ double* u, lapack_int ldu, double* v, lapack_int ldv,
+ double* stat, lapack_int* istat );
+
+lapack_int LAPACKE_sgelq2( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau );
+lapack_int LAPACKE_dgelq2( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau );
+lapack_int LAPACKE_cgelq2( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_zgelq2( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_sgelqf( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau );
+lapack_int LAPACKE_dgelqf( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau );
+lapack_int LAPACKE_cgelqf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_zgelqf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_sgels( int matrix_order, char trans, lapack_int m,
+ lapack_int n, lapack_int nrhs, float* a,
+ lapack_int lda, float* b, lapack_int ldb );
+lapack_int LAPACKE_dgels( int matrix_order, char trans, lapack_int m,
+ lapack_int n, lapack_int nrhs, double* a,
+ lapack_int lda, double* b, lapack_int ldb );
+lapack_int LAPACKE_cgels( int matrix_order, char trans, lapack_int m,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zgels( int matrix_order, char trans, lapack_int m,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_sgelsd( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, float* a, lapack_int lda, float* b,
+ lapack_int ldb, float* s, float rcond,
+ lapack_int* rank );
+lapack_int LAPACKE_dgelsd( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* s, double rcond,
+ lapack_int* rank );
+lapack_int LAPACKE_cgelsd( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, float* s, float rcond,
+ lapack_int* rank );
+lapack_int LAPACKE_zgelsd( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, double* s, double rcond,
+ lapack_int* rank );
+
+lapack_int LAPACKE_sgelss( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, float* a, lapack_int lda, float* b,
+ lapack_int ldb, float* s, float rcond,
+ lapack_int* rank );
+lapack_int LAPACKE_dgelss( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* s, double rcond,
+ lapack_int* rank );
+lapack_int LAPACKE_cgelss( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, float* s, float rcond,
+ lapack_int* rank );
+lapack_int LAPACKE_zgelss( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, double* s, double rcond,
+ lapack_int* rank );
+
+lapack_int LAPACKE_sgelsy( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, float* a, lapack_int lda, float* b,
+ lapack_int ldb, lapack_int* jpvt, float rcond,
+ lapack_int* rank );
+lapack_int LAPACKE_dgelsy( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ double* b, lapack_int ldb, lapack_int* jpvt,
+ double rcond, lapack_int* rank );
+lapack_int LAPACKE_cgelsy( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, lapack_int* jpvt, float rcond,
+ lapack_int* rank );
+lapack_int LAPACKE_zgelsy( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_int* jpvt, double rcond,
+ lapack_int* rank );
+
+lapack_int LAPACKE_sgeqlf( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau );
+lapack_int LAPACKE_dgeqlf( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau );
+lapack_int LAPACKE_cgeqlf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_zgeqlf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_sgeqp3( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, lapack_int* jpvt,
+ float* tau );
+lapack_int LAPACKE_dgeqp3( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, lapack_int* jpvt,
+ double* tau );
+lapack_int LAPACKE_cgeqp3( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* jpvt, lapack_complex_float* tau );
+lapack_int LAPACKE_zgeqp3( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* jpvt, lapack_complex_double* tau );
+
+lapack_int LAPACKE_sgeqpf( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, lapack_int* jpvt,
+ float* tau );
+lapack_int LAPACKE_dgeqpf( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, lapack_int* jpvt,
+ double* tau );
+lapack_int LAPACKE_cgeqpf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* jpvt, lapack_complex_float* tau );
+lapack_int LAPACKE_zgeqpf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* jpvt, lapack_complex_double* tau );
+
+lapack_int LAPACKE_sgeqr2( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau );
+lapack_int LAPACKE_dgeqr2( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau );
+lapack_int LAPACKE_cgeqr2( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_zgeqr2( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_sgeqrf( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau );
+lapack_int LAPACKE_dgeqrf( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau );
+lapack_int LAPACKE_cgeqrf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_zgeqrf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_sgeqrfp( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau );
+lapack_int LAPACKE_dgeqrfp( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau );
+lapack_int LAPACKE_cgeqrfp( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_zgeqrfp( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_sgerfs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ const float* af, lapack_int ldaf,
+ const lapack_int* ipiv, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* ferr, float* berr );
+lapack_int LAPACKE_dgerfs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const double* a, lapack_int lda,
+ const double* af, lapack_int ldaf,
+ const lapack_int* ipiv, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* ferr, double* berr );
+lapack_int LAPACKE_cgerfs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zgerfs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_sgerfsx( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int nrhs, const float* a,
+ lapack_int lda, const float* af, lapack_int ldaf,
+ const lapack_int* ipiv, const float* r,
+ const float* c, const float* b, lapack_int ldb,
+ float* x, lapack_int ldx, float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_dgerfsx( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int nrhs, const double* a,
+ lapack_int lda, const double* af, lapack_int ldaf,
+ const lapack_int* ipiv, const double* r,
+ const double* c, const double* b, lapack_int ldb,
+ double* x, lapack_int ldx, double* rcond,
+ double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params );
+lapack_int LAPACKE_cgerfsx( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* af, lapack_int ldaf,
+ const lapack_int* ipiv, const float* r,
+ const float* c, const lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_zgerfsx( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* af, lapack_int ldaf,
+ const lapack_int* ipiv, const double* r,
+ const double* c, const lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params );
+
+lapack_int LAPACKE_sgerqf( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau );
+lapack_int LAPACKE_dgerqf( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau );
+lapack_int LAPACKE_cgerqf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_zgerqf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_sgesdd( int matrix_order, char jobz, lapack_int m,
+ lapack_int n, float* a, lapack_int lda, float* s,
+ float* u, lapack_int ldu, float* vt,
+ lapack_int ldvt );
+lapack_int LAPACKE_dgesdd( int matrix_order, char jobz, lapack_int m,
+ lapack_int n, double* a, lapack_int lda, double* s,
+ double* u, lapack_int ldu, double* vt,
+ lapack_int ldvt );
+lapack_int LAPACKE_cgesdd( int matrix_order, char jobz, lapack_int m,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, float* s, lapack_complex_float* u,
+ lapack_int ldu, lapack_complex_float* vt,
+ lapack_int ldvt );
+lapack_int LAPACKE_zgesdd( int matrix_order, char jobz, lapack_int m,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, double* s, lapack_complex_double* u,
+ lapack_int ldu, lapack_complex_double* vt,
+ lapack_int ldvt );
+
+lapack_int LAPACKE_sgesv( int matrix_order, lapack_int n, lapack_int nrhs,
+ float* a, lapack_int lda, lapack_int* ipiv, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dgesv( int matrix_order, lapack_int n, lapack_int nrhs,
+ double* a, lapack_int lda, lapack_int* ipiv,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_cgesv( int matrix_order, lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zgesv( int matrix_order, lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dsgesv( int matrix_order, lapack_int n, lapack_int nrhs,
+ double* a, lapack_int lda, lapack_int* ipiv,
+ double* b, lapack_int ldb, double* x, lapack_int ldx,
+ lapack_int* iter );
+lapack_int LAPACKE_zcgesv( int matrix_order, lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, lapack_int* iter );
+
+lapack_int LAPACKE_sgesvd( int matrix_order, char jobu, char jobvt,
+ lapack_int m, lapack_int n, float* a, lapack_int lda,
+ float* s, float* u, lapack_int ldu, float* vt,
+ lapack_int ldvt, float* superb );
+lapack_int LAPACKE_dgesvd( int matrix_order, char jobu, char jobvt,
+ lapack_int m, lapack_int n, double* a,
+ lapack_int lda, double* s, double* u, lapack_int ldu,
+ double* vt, lapack_int ldvt, double* superb );
+lapack_int LAPACKE_cgesvd( int matrix_order, char jobu, char jobvt,
+ lapack_int m, lapack_int n, lapack_complex_float* a,
+ lapack_int lda, float* s, lapack_complex_float* u,
+ lapack_int ldu, lapack_complex_float* vt,
+ lapack_int ldvt, float* superb );
+lapack_int LAPACKE_zgesvd( int matrix_order, char jobu, char jobvt,
+ lapack_int m, lapack_int n, lapack_complex_double* a,
+ lapack_int lda, double* s, lapack_complex_double* u,
+ lapack_int ldu, lapack_complex_double* vt,
+ lapack_int ldvt, double* superb );
+
+lapack_int LAPACKE_sgesvj( int matrix_order, char joba, char jobu, char jobv,
+ lapack_int m, lapack_int n, float* a, lapack_int lda,
+ float* sva, lapack_int mv, float* v, lapack_int ldv,
+ float* stat );
+lapack_int LAPACKE_dgesvj( int matrix_order, char joba, char jobu, char jobv,
+ lapack_int m, lapack_int n, double* a,
+ lapack_int lda, double* sva, lapack_int mv,
+ double* v, lapack_int ldv, double* stat );
+
+lapack_int LAPACKE_sgesvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, float* a,
+ lapack_int lda, float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* r, float* c,
+ float* b, lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ float* rpivot );
+lapack_int LAPACKE_dgesvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, double* a,
+ lapack_int lda, double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* r, double* c,
+ double* b, lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ double* rpivot );
+lapack_int LAPACKE_cgesvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* r, float* c,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ float* rpivot );
+lapack_int LAPACKE_zgesvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* r, double* c,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ double* rpivot );
+
+lapack_int LAPACKE_sgesvxx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, float* a,
+ lapack_int lda, float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* r, float* c,
+ float* b, lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_dgesvxx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, double* a,
+ lapack_int lda, double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* r, double* c,
+ double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* rcond, double* rpvgrw,
+ double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params );
+lapack_int LAPACKE_cgesvxx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* r, float* c,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_zgesvxx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* r, double* c,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params );
+
+lapack_int LAPACKE_sgetf2( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, lapack_int* ipiv );
+lapack_int LAPACKE_dgetf2( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, lapack_int* ipiv );
+lapack_int LAPACKE_cgetf2( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ipiv );
+lapack_int LAPACKE_zgetf2( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv );
+
+lapack_int LAPACKE_sgetrf( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, lapack_int* ipiv );
+lapack_int LAPACKE_dgetrf( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, lapack_int* ipiv );
+lapack_int LAPACKE_cgetrf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ipiv );
+lapack_int LAPACKE_zgetrf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv );
+
+lapack_int LAPACKE_sgetri( int matrix_order, lapack_int n, float* a,
+ lapack_int lda, const lapack_int* ipiv );
+lapack_int LAPACKE_dgetri( int matrix_order, lapack_int n, double* a,
+ lapack_int lda, const lapack_int* ipiv );
+lapack_int LAPACKE_cgetri( int matrix_order, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv );
+lapack_int LAPACKE_zgetri( int matrix_order, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv );
+
+lapack_int LAPACKE_sgetrs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ const lapack_int* ipiv, float* b, lapack_int ldb );
+lapack_int LAPACKE_dgetrs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const double* a, lapack_int lda,
+ const lapack_int* ipiv, double* b, lapack_int ldb );
+lapack_int LAPACKE_cgetrs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zgetrs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_sggbak( int matrix_order, char job, char side, lapack_int n,
+ lapack_int ilo, lapack_int ihi, const float* lscale,
+ const float* rscale, lapack_int m, float* v,
+ lapack_int ldv );
+lapack_int LAPACKE_dggbak( int matrix_order, char job, char side, lapack_int n,
+ lapack_int ilo, lapack_int ihi, const double* lscale,
+ const double* rscale, lapack_int m, double* v,
+ lapack_int ldv );
+lapack_int LAPACKE_cggbak( int matrix_order, char job, char side, lapack_int n,
+ lapack_int ilo, lapack_int ihi, const float* lscale,
+ const float* rscale, lapack_int m,
+ lapack_complex_float* v, lapack_int ldv );
+lapack_int LAPACKE_zggbak( int matrix_order, char job, char side, lapack_int n,
+ lapack_int ilo, lapack_int ihi, const double* lscale,
+ const double* rscale, lapack_int m,
+ lapack_complex_double* v, lapack_int ldv );
+
+lapack_int LAPACKE_sggbal( int matrix_order, char job, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb,
+ lapack_int* ilo, lapack_int* ihi, float* lscale,
+ float* rscale );
+lapack_int LAPACKE_dggbal( int matrix_order, char job, lapack_int n, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ lapack_int* ilo, lapack_int* ihi, double* lscale,
+ double* rscale );
+lapack_int LAPACKE_cggbal( int matrix_order, char job, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_int* ilo, lapack_int* ihi, float* lscale,
+ float* rscale );
+lapack_int LAPACKE_zggbal( int matrix_order, char job, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_int* ilo, lapack_int* ihi, double* lscale,
+ double* rscale );
+
+lapack_int LAPACKE_sgges( int matrix_order, char jobvsl, char jobvsr, char sort,
+ LAPACK_S_SELECT3 selctg, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb,
+ lapack_int* sdim, float* alphar, float* alphai,
+ float* beta, float* vsl, lapack_int ldvsl, float* vsr,
+ lapack_int ldvsr );
+lapack_int LAPACKE_dgges( int matrix_order, char jobvsl, char jobvsr, char sort,
+ LAPACK_D_SELECT3 selctg, lapack_int n, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ lapack_int* sdim, double* alphar, double* alphai,
+ double* beta, double* vsl, lapack_int ldvsl,
+ double* vsr, lapack_int ldvsr );
+lapack_int LAPACKE_cgges( int matrix_order, char jobvsl, char jobvsr, char sort,
+ LAPACK_C_SELECT2 selctg, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_int* sdim, lapack_complex_float* alpha,
+ lapack_complex_float* beta, lapack_complex_float* vsl,
+ lapack_int ldvsl, lapack_complex_float* vsr,
+ lapack_int ldvsr );
+lapack_int LAPACKE_zgges( int matrix_order, char jobvsl, char jobvsr, char sort,
+ LAPACK_Z_SELECT2 selctg, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_int* sdim, lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* vsl, lapack_int ldvsl,
+ lapack_complex_double* vsr, lapack_int ldvsr );
+
+lapack_int LAPACKE_sggesx( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_S_SELECT3 selctg, char sense,
+ lapack_int n, float* a, lapack_int lda, float* b,
+ lapack_int ldb, lapack_int* sdim, float* alphar,
+ float* alphai, float* beta, float* vsl,
+ lapack_int ldvsl, float* vsr, lapack_int ldvsr,
+ float* rconde, float* rcondv );
+lapack_int LAPACKE_dggesx( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_D_SELECT3 selctg, char sense,
+ lapack_int n, double* a, lapack_int lda, double* b,
+ lapack_int ldb, lapack_int* sdim, double* alphar,
+ double* alphai, double* beta, double* vsl,
+ lapack_int ldvsl, double* vsr, lapack_int ldvsr,
+ double* rconde, double* rcondv );
+lapack_int LAPACKE_cggesx( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_C_SELECT2 selctg, char sense,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, lapack_int* sdim,
+ lapack_complex_float* alpha,
+ lapack_complex_float* beta,
+ lapack_complex_float* vsl, lapack_int ldvsl,
+ lapack_complex_float* vsr, lapack_int ldvsr,
+ float* rconde, float* rcondv );
+lapack_int LAPACKE_zggesx( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_Z_SELECT2 selctg, char sense,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_int* sdim,
+ lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* vsl, lapack_int ldvsl,
+ lapack_complex_double* vsr, lapack_int ldvsr,
+ double* rconde, double* rcondv );
+
+lapack_int LAPACKE_sggev( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, float* a, lapack_int lda, float* b,
+ lapack_int ldb, float* alphar, float* alphai,
+ float* beta, float* vl, lapack_int ldvl, float* vr,
+ lapack_int ldvr );
+lapack_int LAPACKE_dggev( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, double* a, lapack_int lda, double* b,
+ lapack_int ldb, double* alphar, double* alphai,
+ double* beta, double* vl, lapack_int ldvl, double* vr,
+ lapack_int ldvr );
+lapack_int LAPACKE_cggev( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* alpha,
+ lapack_complex_float* beta, lapack_complex_float* vl,
+ lapack_int ldvl, lapack_complex_float* vr,
+ lapack_int ldvr );
+lapack_int LAPACKE_zggev( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr );
+
+lapack_int LAPACKE_sggevx( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb,
+ float* alphar, float* alphai, float* beta, float* vl,
+ lapack_int ldvl, float* vr, lapack_int ldvr,
+ lapack_int* ilo, lapack_int* ihi, float* lscale,
+ float* rscale, float* abnrm, float* bbnrm,
+ float* rconde, float* rcondv );
+lapack_int LAPACKE_dggevx( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ double* alphar, double* alphai, double* beta,
+ double* vl, lapack_int ldvl, double* vr,
+ lapack_int ldvr, lapack_int* ilo, lapack_int* ihi,
+ double* lscale, double* rscale, double* abnrm,
+ double* bbnrm, double* rconde, double* rcondv );
+lapack_int LAPACKE_cggevx( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* alpha,
+ lapack_complex_float* beta, lapack_complex_float* vl,
+ lapack_int ldvl, lapack_complex_float* vr,
+ lapack_int ldvr, lapack_int* ilo, lapack_int* ihi,
+ float* lscale, float* rscale, float* abnrm,
+ float* bbnrm, float* rconde, float* rcondv );
+lapack_int LAPACKE_zggevx( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr,
+ lapack_int* ilo, lapack_int* ihi, double* lscale,
+ double* rscale, double* abnrm, double* bbnrm,
+ double* rconde, double* rcondv );
+
+lapack_int LAPACKE_sggglm( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, float* a, lapack_int lda, float* b,
+ lapack_int ldb, float* d, float* x, float* y );
+lapack_int LAPACKE_dggglm( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, double* a, lapack_int lda, double* b,
+ lapack_int ldb, double* d, double* x, double* y );
+lapack_int LAPACKE_cggglm( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* d,
+ lapack_complex_float* x, lapack_complex_float* y );
+lapack_int LAPACKE_zggglm( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* d,
+ lapack_complex_double* x, lapack_complex_double* y );
+
+lapack_int LAPACKE_sgghrd( int matrix_order, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ float* a, lapack_int lda, float* b, lapack_int ldb,
+ float* q, lapack_int ldq, float* z, lapack_int ldz );
+lapack_int LAPACKE_dgghrd( int matrix_order, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ double* a, lapack_int lda, double* b, lapack_int ldb,
+ double* q, lapack_int ldq, double* z,
+ lapack_int ldz );
+lapack_int LAPACKE_cgghrd( int matrix_order, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* z, lapack_int ldz );
+lapack_int LAPACKE_zgghrd( int matrix_order, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* z, lapack_int ldz );
+
+lapack_int LAPACKE_sgglse( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int p, float* a, lapack_int lda, float* b,
+ lapack_int ldb, float* c, float* d, float* x );
+lapack_int LAPACKE_dgglse( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int p, double* a, lapack_int lda, double* b,
+ lapack_int ldb, double* c, double* d, double* x );
+lapack_int LAPACKE_cgglse( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int p, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* c,
+ lapack_complex_float* d, lapack_complex_float* x );
+lapack_int LAPACKE_zgglse( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int p, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* c,
+ lapack_complex_double* d, lapack_complex_double* x );
+
+lapack_int LAPACKE_sggqrf( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, float* a, lapack_int lda, float* taua,
+ float* b, lapack_int ldb, float* taub );
+lapack_int LAPACKE_dggqrf( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, double* a, lapack_int lda,
+ double* taua, double* b, lapack_int ldb,
+ double* taub );
+lapack_int LAPACKE_cggqrf( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* taua,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* taub );
+lapack_int LAPACKE_zggqrf( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* taua,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* taub );
+
+lapack_int LAPACKE_sggrqf( int matrix_order, lapack_int m, lapack_int p,
+ lapack_int n, float* a, lapack_int lda, float* taua,
+ float* b, lapack_int ldb, float* taub );
+lapack_int LAPACKE_dggrqf( int matrix_order, lapack_int m, lapack_int p,
+ lapack_int n, double* a, lapack_int lda,
+ double* taua, double* b, lapack_int ldb,
+ double* taub );
+lapack_int LAPACKE_cggrqf( int matrix_order, lapack_int m, lapack_int p,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* taua,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* taub );
+lapack_int LAPACKE_zggrqf( int matrix_order, lapack_int m, lapack_int p,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* taua,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* taub );
+
+lapack_int LAPACKE_sggsvd( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int n, lapack_int p,
+ lapack_int* k, lapack_int* l, float* a,
+ lapack_int lda, float* b, lapack_int ldb,
+ float* alpha, float* beta, float* u, lapack_int ldu,
+ float* v, lapack_int ldv, float* q, lapack_int ldq,
+ lapack_int* iwork );
+lapack_int LAPACKE_dggsvd( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int n, lapack_int p,
+ lapack_int* k, lapack_int* l, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ double* alpha, double* beta, double* u,
+ lapack_int ldu, double* v, lapack_int ldv, double* q,
+ lapack_int ldq, lapack_int* iwork );
+lapack_int LAPACKE_cggsvd( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int n, lapack_int p,
+ lapack_int* k, lapack_int* l,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ float* alpha, float* beta, lapack_complex_float* u,
+ lapack_int ldu, lapack_complex_float* v,
+ lapack_int ldv, lapack_complex_float* q,
+ lapack_int ldq, lapack_int* iwork );
+lapack_int LAPACKE_zggsvd( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int n, lapack_int p,
+ lapack_int* k, lapack_int* l,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ double* alpha, double* beta,
+ lapack_complex_double* u, lapack_int ldu,
+ lapack_complex_double* v, lapack_int ldv,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_int* iwork );
+
+lapack_int LAPACKE_sggsvp( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int p, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb, float tola,
+ float tolb, lapack_int* k, lapack_int* l, float* u,
+ lapack_int ldu, float* v, lapack_int ldv, float* q,
+ lapack_int ldq );
+lapack_int LAPACKE_dggsvp( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int p, lapack_int n, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ double tola, double tolb, lapack_int* k,
+ lapack_int* l, double* u, lapack_int ldu, double* v,
+ lapack_int ldv, double* q, lapack_int ldq );
+lapack_int LAPACKE_cggsvp( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int p, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb, float tola,
+ float tolb, lapack_int* k, lapack_int* l,
+ lapack_complex_float* u, lapack_int ldu,
+ lapack_complex_float* v, lapack_int ldv,
+ lapack_complex_float* q, lapack_int ldq );
+lapack_int LAPACKE_zggsvp( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int p, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ double tola, double tolb, lapack_int* k,
+ lapack_int* l, lapack_complex_double* u,
+ lapack_int ldu, lapack_complex_double* v,
+ lapack_int ldv, lapack_complex_double* q,
+ lapack_int ldq );
+
+lapack_int LAPACKE_sgtcon( char norm, lapack_int n, const float* dl,
+ const float* d, const float* du, const float* du2,
+ const lapack_int* ipiv, float anorm, float* rcond );
+lapack_int LAPACKE_dgtcon( char norm, lapack_int n, const double* dl,
+ const double* d, const double* du, const double* du2,
+ const lapack_int* ipiv, double anorm,
+ double* rcond );
+lapack_int LAPACKE_cgtcon( char norm, lapack_int n,
+ const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du,
+ const lapack_complex_float* du2,
+ const lapack_int* ipiv, float anorm, float* rcond );
+lapack_int LAPACKE_zgtcon( char norm, lapack_int n,
+ const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du,
+ const lapack_complex_double* du2,
+ const lapack_int* ipiv, double anorm,
+ double* rcond );
+
+lapack_int LAPACKE_sgtrfs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const float* dl, const float* d,
+ const float* du, const float* dlf, const float* df,
+ const float* duf, const float* du2,
+ const lapack_int* ipiv, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* ferr, float* berr );
+lapack_int LAPACKE_dgtrfs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const double* dl, const double* d,
+ const double* du, const double* dlf,
+ const double* df, const double* duf,
+ const double* du2, const lapack_int* ipiv,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* ferr, double* berr );
+lapack_int LAPACKE_cgtrfs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du,
+ const lapack_complex_float* dlf,
+ const lapack_complex_float* df,
+ const lapack_complex_float* duf,
+ const lapack_complex_float* du2,
+ const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zgtrfs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du,
+ const lapack_complex_double* dlf,
+ const lapack_complex_double* df,
+ const lapack_complex_double* duf,
+ const lapack_complex_double* du2,
+ const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_sgtsv( int matrix_order, lapack_int n, lapack_int nrhs,
+ float* dl, float* d, float* du, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dgtsv( int matrix_order, lapack_int n, lapack_int nrhs,
+ double* dl, double* d, double* du, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cgtsv( int matrix_order, lapack_int n, lapack_int nrhs,
+ lapack_complex_float* dl, lapack_complex_float* d,
+ lapack_complex_float* du, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zgtsv( int matrix_order, lapack_int n, lapack_int nrhs,
+ lapack_complex_double* dl, lapack_complex_double* d,
+ lapack_complex_double* du, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_sgtsvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, const float* dl,
+ const float* d, const float* du, float* dlf,
+ float* df, float* duf, float* du2, lapack_int* ipiv,
+ const float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr );
+lapack_int LAPACKE_dgtsvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, const double* dl,
+ const double* d, const double* du, double* dlf,
+ double* df, double* duf, double* du2,
+ lapack_int* ipiv, const double* b, lapack_int ldb,
+ double* x, lapack_int ldx, double* rcond,
+ double* ferr, double* berr );
+lapack_int LAPACKE_cgtsvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du,
+ lapack_complex_float* dlf, lapack_complex_float* df,
+ lapack_complex_float* duf, lapack_complex_float* du2,
+ lapack_int* ipiv, const lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zgtsvx( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du,
+ lapack_complex_double* dlf,
+ lapack_complex_double* df,
+ lapack_complex_double* duf,
+ lapack_complex_double* du2, lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr );
+
+lapack_int LAPACKE_sgttrf( lapack_int n, float* dl, float* d, float* du,
+ float* du2, lapack_int* ipiv );
+lapack_int LAPACKE_dgttrf( lapack_int n, double* dl, double* d, double* du,
+ double* du2, lapack_int* ipiv );
+lapack_int LAPACKE_cgttrf( lapack_int n, lapack_complex_float* dl,
+ lapack_complex_float* d, lapack_complex_float* du,
+ lapack_complex_float* du2, lapack_int* ipiv );
+lapack_int LAPACKE_zgttrf( lapack_int n, lapack_complex_double* dl,
+ lapack_complex_double* d, lapack_complex_double* du,
+ lapack_complex_double* du2, lapack_int* ipiv );
+
+lapack_int LAPACKE_sgttrs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const float* dl, const float* d,
+ const float* du, const float* du2,
+ const lapack_int* ipiv, float* b, lapack_int ldb );
+lapack_int LAPACKE_dgttrs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const double* dl, const double* d,
+ const double* du, const double* du2,
+ const lapack_int* ipiv, double* b, lapack_int ldb );
+lapack_int LAPACKE_cgttrs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du,
+ const lapack_complex_float* du2,
+ const lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zgttrs( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du,
+ const lapack_complex_double* du2,
+ const lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_chbev( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int kd, lapack_complex_float* ab,
+ lapack_int ldab, float* w, lapack_complex_float* z,
+ lapack_int ldz );
+lapack_int LAPACKE_zhbev( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int kd, lapack_complex_double* ab,
+ lapack_int ldab, double* w, lapack_complex_double* z,
+ lapack_int ldz );
+
+lapack_int LAPACKE_chbevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int kd, lapack_complex_float* ab,
+ lapack_int ldab, float* w, lapack_complex_float* z,
+ lapack_int ldz );
+lapack_int LAPACKE_zhbevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int kd, lapack_complex_double* ab,
+ lapack_int ldab, double* w, lapack_complex_double* z,
+ lapack_int ldz );
+
+lapack_int LAPACKE_chbevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_int kd,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* q, lapack_int ldq, float vl,
+ float vu, lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_int* ifail );
+lapack_int LAPACKE_zhbevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_int kd,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* q, lapack_int ldq, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_chbgst( int matrix_order, char vect, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb,
+ lapack_complex_float* ab, lapack_int ldab,
+ const lapack_complex_float* bb, lapack_int ldbb,
+ lapack_complex_float* x, lapack_int ldx );
+lapack_int LAPACKE_zhbgst( int matrix_order, char vect, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb,
+ lapack_complex_double* ab, lapack_int ldab,
+ const lapack_complex_double* bb, lapack_int ldbb,
+ lapack_complex_double* x, lapack_int ldx );
+
+lapack_int LAPACKE_chbgv( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* bb, lapack_int ldbb, float* w,
+ lapack_complex_float* z, lapack_int ldz );
+lapack_int LAPACKE_zhbgv( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* bb, lapack_int ldbb, double* w,
+ lapack_complex_double* z, lapack_int ldz );
+
+lapack_int LAPACKE_chbgvd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* bb, lapack_int ldbb, float* w,
+ lapack_complex_float* z, lapack_int ldz );
+lapack_int LAPACKE_zhbgvd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* bb, lapack_int ldbb,
+ double* w, lapack_complex_double* z,
+ lapack_int ldz );
+
+lapack_int LAPACKE_chbgvx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* bb, lapack_int ldbb,
+ lapack_complex_float* q, lapack_int ldq, float vl,
+ float vu, lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_int* ifail );
+lapack_int LAPACKE_zhbgvx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* bb, lapack_int ldbb,
+ lapack_complex_double* q, lapack_int ldq, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_chbtrd( int matrix_order, char vect, char uplo, lapack_int n,
+ lapack_int kd, lapack_complex_float* ab,
+ lapack_int ldab, float* d, float* e,
+ lapack_complex_float* q, lapack_int ldq );
+lapack_int LAPACKE_zhbtrd( int matrix_order, char vect, char uplo, lapack_int n,
+ lapack_int kd, lapack_complex_double* ab,
+ lapack_int ldab, double* d, double* e,
+ lapack_complex_double* q, lapack_int ldq );
+
+lapack_int LAPACKE_checon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv, float anorm, float* rcond );
+lapack_int LAPACKE_zhecon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv, double anorm,
+ double* rcond );
+
+lapack_int LAPACKE_cheequb( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* s, float* scond, float* amax );
+lapack_int LAPACKE_zheequb( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* s, double* scond, double* amax );
+
+lapack_int LAPACKE_cheev( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda, float* w );
+lapack_int LAPACKE_zheev( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda, double* w );
+
+lapack_int LAPACKE_cheevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda, float* w );
+lapack_int LAPACKE_zheevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ double* w );
+
+lapack_int LAPACKE_cheevr( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, float vl, float vu, lapack_int il,
+ lapack_int iu, float abstol, lapack_int* m, float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_int* isuppz );
+lapack_int LAPACKE_zheevr( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, double vl, double vu, lapack_int il,
+ lapack_int iu, double abstol, lapack_int* m,
+ double* w, lapack_complex_double* z, lapack_int ldz,
+ lapack_int* isuppz );
+
+lapack_int LAPACKE_cheevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, float vl, float vu, lapack_int il,
+ lapack_int iu, float abstol, lapack_int* m, float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_int* ifail );
+lapack_int LAPACKE_zheevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, double vl, double vu, lapack_int il,
+ lapack_int iu, double abstol, lapack_int* m,
+ double* w, lapack_complex_double* z, lapack_int ldz,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_chegst( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zhegst( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_chegv( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, float* w );
+lapack_int LAPACKE_zhegv( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, double* w );
+
+lapack_int LAPACKE_chegvd( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, float* w );
+lapack_int LAPACKE_zhegvd( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, double* w );
+
+lapack_int LAPACKE_chegvx( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb, float vl,
+ float vu, lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_int* ifail );
+lapack_int LAPACKE_zhegvx( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_cherfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zherfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_cherfsx( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* af, lapack_int ldaf,
+ const lapack_int* ipiv, const float* s,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* berr, lapack_int n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int nparams, float* params );
+lapack_int LAPACKE_zherfsx( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* af, lapack_int ldaf,
+ const lapack_int* ipiv, const double* s,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params );
+
+lapack_int LAPACKE_chesv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zhesv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_chesvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* af,
+ lapack_int ldaf, lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr );
+lapack_int LAPACKE_zhesvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* af,
+ lapack_int ldaf, lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr );
+
+lapack_int LAPACKE_chesvxx( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* s,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_zhesvxx( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* s,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params );
+
+lapack_int LAPACKE_chetrd( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda, float* d,
+ float* e, lapack_complex_float* tau );
+lapack_int LAPACKE_zhetrd( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda, double* d,
+ double* e, lapack_complex_double* tau );
+
+lapack_int LAPACKE_chetrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ipiv );
+lapack_int LAPACKE_zhetrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv );
+
+lapack_int LAPACKE_chetri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv );
+lapack_int LAPACKE_zhetri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv );
+
+lapack_int LAPACKE_chetrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zhetrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_chfrk( int matrix_order, char transr, char uplo, char trans,
+ lapack_int n, lapack_int k, float alpha,
+ const lapack_complex_float* a, lapack_int lda,
+ float beta, lapack_complex_float* c );
+lapack_int LAPACKE_zhfrk( int matrix_order, char transr, char uplo, char trans,
+ lapack_int n, lapack_int k, double alpha,
+ const lapack_complex_double* a, lapack_int lda,
+ double beta, lapack_complex_double* c );
+
+lapack_int LAPACKE_shgeqz( int matrix_order, char job, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ float* h, lapack_int ldh, float* t, lapack_int ldt,
+ float* alphar, float* alphai, float* beta, float* q,
+ lapack_int ldq, float* z, lapack_int ldz );
+lapack_int LAPACKE_dhgeqz( int matrix_order, char job, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ double* h, lapack_int ldh, double* t, lapack_int ldt,
+ double* alphar, double* alphai, double* beta,
+ double* q, lapack_int ldq, double* z,
+ lapack_int ldz );
+lapack_int LAPACKE_chgeqz( int matrix_order, char job, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ lapack_complex_float* h, lapack_int ldh,
+ lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* alpha,
+ lapack_complex_float* beta, lapack_complex_float* q,
+ lapack_int ldq, lapack_complex_float* z,
+ lapack_int ldz );
+lapack_int LAPACKE_zhgeqz( int matrix_order, char job, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ lapack_complex_double* h, lapack_int ldh,
+ lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* z, lapack_int ldz );
+
+lapack_int LAPACKE_chpcon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap,
+ const lapack_int* ipiv, float anorm, float* rcond );
+lapack_int LAPACKE_zhpcon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap,
+ const lapack_int* ipiv, double anorm,
+ double* rcond );
+
+lapack_int LAPACKE_chpev( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_complex_float* ap, float* w,
+ lapack_complex_float* z, lapack_int ldz );
+lapack_int LAPACKE_zhpev( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_complex_double* ap, double* w,
+ lapack_complex_double* z, lapack_int ldz );
+
+lapack_int LAPACKE_chpevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_complex_float* ap, float* w,
+ lapack_complex_float* z, lapack_int ldz );
+lapack_int LAPACKE_zhpevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_complex_double* ap, double* w,
+ lapack_complex_double* z, lapack_int ldz );
+
+lapack_int LAPACKE_chpevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_complex_float* ap, float vl,
+ float vu, lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_int* ifail );
+lapack_int LAPACKE_zhpevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_complex_double* ap, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_chpgst( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, lapack_complex_float* ap,
+ const lapack_complex_float* bp );
+lapack_int LAPACKE_zhpgst( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, lapack_complex_double* ap,
+ const lapack_complex_double* bp );
+
+lapack_int LAPACKE_chpgv( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, lapack_complex_float* ap,
+ lapack_complex_float* bp, float* w,
+ lapack_complex_float* z, lapack_int ldz );
+lapack_int LAPACKE_zhpgv( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, lapack_complex_double* ap,
+ lapack_complex_double* bp, double* w,
+ lapack_complex_double* z, lapack_int ldz );
+
+lapack_int LAPACKE_chpgvd( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, lapack_complex_float* ap,
+ lapack_complex_float* bp, float* w,
+ lapack_complex_float* z, lapack_int ldz );
+lapack_int LAPACKE_zhpgvd( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, lapack_complex_double* ap,
+ lapack_complex_double* bp, double* w,
+ lapack_complex_double* z, lapack_int ldz );
+
+lapack_int LAPACKE_chpgvx( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n,
+ lapack_complex_float* ap, lapack_complex_float* bp,
+ float vl, float vu, lapack_int il, lapack_int iu,
+ float abstol, lapack_int* m, float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_int* ifail );
+lapack_int LAPACKE_zhpgvx( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n,
+ lapack_complex_double* ap, lapack_complex_double* bp,
+ double vl, double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_chprfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ const lapack_complex_float* afp,
+ const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zhprfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* ap,
+ const lapack_complex_double* afp,
+ const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_chpsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* ap,
+ lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zhpsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* ap,
+ lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_chpsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ lapack_complex_float* afp, lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr );
+lapack_int LAPACKE_zhpsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* ap,
+ lapack_complex_double* afp, lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr );
+
+lapack_int LAPACKE_chptrd( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap, float* d, float* e,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_zhptrd( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap, double* d, double* e,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_chptrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap, lapack_int* ipiv );
+lapack_int LAPACKE_zhptrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap, lapack_int* ipiv );
+
+lapack_int LAPACKE_chptri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap, const lapack_int* ipiv );
+lapack_int LAPACKE_zhptri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap, const lapack_int* ipiv );
+
+lapack_int LAPACKE_chptrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ const lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zhptrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* ap,
+ const lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_shsein( int matrix_order, char job, char eigsrc, char initv,
+ lapack_logical* select, lapack_int n, const float* h,
+ lapack_int ldh, float* wr, const float* wi,
+ float* vl, lapack_int ldvl, float* vr,
+ lapack_int ldvr, lapack_int mm, lapack_int* m,
+ lapack_int* ifaill, lapack_int* ifailr );
+lapack_int LAPACKE_dhsein( int matrix_order, char job, char eigsrc, char initv,
+ lapack_logical* select, lapack_int n,
+ const double* h, lapack_int ldh, double* wr,
+ const double* wi, double* vl, lapack_int ldvl,
+ double* vr, lapack_int ldvr, lapack_int mm,
+ lapack_int* m, lapack_int* ifaill,
+ lapack_int* ifailr );
+lapack_int LAPACKE_chsein( int matrix_order, char job, char eigsrc, char initv,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_float* h, lapack_int ldh,
+ lapack_complex_float* w, lapack_complex_float* vl,
+ lapack_int ldvl, lapack_complex_float* vr,
+ lapack_int ldvr, lapack_int mm, lapack_int* m,
+ lapack_int* ifaill, lapack_int* ifailr );
+lapack_int LAPACKE_zhsein( int matrix_order, char job, char eigsrc, char initv,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_double* h, lapack_int ldh,
+ lapack_complex_double* w, lapack_complex_double* vl,
+ lapack_int ldvl, lapack_complex_double* vr,
+ lapack_int ldvr, lapack_int mm, lapack_int* m,
+ lapack_int* ifaill, lapack_int* ifailr );
+
+lapack_int LAPACKE_shseqr( int matrix_order, char job, char compz, lapack_int n,
+ lapack_int ilo, lapack_int ihi, float* h,
+ lapack_int ldh, float* wr, float* wi, float* z,
+ lapack_int ldz );
+lapack_int LAPACKE_dhseqr( int matrix_order, char job, char compz, lapack_int n,
+ lapack_int ilo, lapack_int ihi, double* h,
+ lapack_int ldh, double* wr, double* wi, double* z,
+ lapack_int ldz );
+lapack_int LAPACKE_chseqr( int matrix_order, char job, char compz, lapack_int n,
+ lapack_int ilo, lapack_int ihi,
+ lapack_complex_float* h, lapack_int ldh,
+ lapack_complex_float* w, lapack_complex_float* z,
+ lapack_int ldz );
+lapack_int LAPACKE_zhseqr( int matrix_order, char job, char compz, lapack_int n,
+ lapack_int ilo, lapack_int ihi,
+ lapack_complex_double* h, lapack_int ldh,
+ lapack_complex_double* w, lapack_complex_double* z,
+ lapack_int ldz );
+
+lapack_int LAPACKE_clacgv( lapack_int n, lapack_complex_float* x,
+ lapack_int incx );
+lapack_int LAPACKE_zlacgv( lapack_int n, lapack_complex_double* x,
+ lapack_int incx );
+
+lapack_int LAPACKE_slacpy( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, const float* a, lapack_int lda, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dlacpy( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, const double* a, lapack_int lda, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_clacpy( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, const lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zlacpy( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, const lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_zlag2c( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ lapack_complex_float* sa, lapack_int ldsa );
+
+lapack_int LAPACKE_slag2d( int matrix_order, lapack_int m, lapack_int n,
+ const float* sa, lapack_int ldsa, double* a,
+ lapack_int lda );
+
+lapack_int LAPACKE_dlag2s( int matrix_order, lapack_int m, lapack_int n,
+ const double* a, lapack_int lda, float* sa,
+ lapack_int ldsa );
+
+lapack_int LAPACKE_clag2z( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_float* sa, lapack_int ldsa,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_slagge( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const float* d,
+ float* a, lapack_int lda, lapack_int* iseed );
+lapack_int LAPACKE_dlagge( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const double* d,
+ double* a, lapack_int lda, lapack_int* iseed );
+lapack_int LAPACKE_clagge( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const float* d,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* iseed );
+lapack_int LAPACKE_zlagge( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const double* d,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* iseed );
+
+float LAPACKE_slamch( char cmach );
+double LAPACKE_dlamch( char cmach );
+
+float LAPACKE_slange( int matrix_order, char norm, lapack_int m,
+ lapack_int n, const float* a, lapack_int lda );
+double LAPACKE_dlange( int matrix_order, char norm, lapack_int m,
+ lapack_int n, const double* a, lapack_int lda );
+float LAPACKE_clange( int matrix_order, char norm, lapack_int m,
+ lapack_int n, const lapack_complex_float* a,
+ lapack_int lda );
+double LAPACKE_zlange( int matrix_order, char norm, lapack_int m,
+ lapack_int n, const lapack_complex_double* a,
+ lapack_int lda );
+
+float LAPACKE_clanhe( int matrix_order, char norm, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda );
+double LAPACKE_zlanhe( int matrix_order, char norm, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda );
+
+float LAPACKE_slansy( int matrix_order, char norm, char uplo, lapack_int n,
+ const float* a, lapack_int lda );
+double LAPACKE_dlansy( int matrix_order, char norm, char uplo, lapack_int n,
+ const double* a, lapack_int lda );
+float LAPACKE_clansy( int matrix_order, char norm, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda );
+double LAPACKE_zlansy( int matrix_order, char norm, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda );
+
+float LAPACKE_slantr( int matrix_order, char norm, char uplo, char diag,
+ lapack_int m, lapack_int n, const float* a,
+ lapack_int lda );
+double LAPACKE_dlantr( int matrix_order, char norm, char uplo, char diag,
+ lapack_int m, lapack_int n, const double* a,
+ lapack_int lda );
+float LAPACKE_clantr( int matrix_order, char norm, char uplo, char diag,
+ lapack_int m, lapack_int n, const lapack_complex_float* a,
+ lapack_int lda );
+double LAPACKE_zlantr( int matrix_order, char norm, char uplo, char diag,
+ lapack_int m, lapack_int n, const lapack_complex_double* a,
+ lapack_int lda );
+
+
+lapack_int LAPACKE_slarfb( int matrix_order, char side, char trans, char direct,
+ char storev, lapack_int m, lapack_int n,
+ lapack_int k, const float* v, lapack_int ldv,
+ const float* t, lapack_int ldt, float* c,
+ lapack_int ldc );
+lapack_int LAPACKE_dlarfb( int matrix_order, char side, char trans, char direct,
+ char storev, lapack_int m, lapack_int n,
+ lapack_int k, const double* v, lapack_int ldv,
+ const double* t, lapack_int ldt, double* c,
+ lapack_int ldc );
+lapack_int LAPACKE_clarfb( int matrix_order, char side, char trans, char direct,
+ char storev, lapack_int m, lapack_int n,
+ lapack_int k, const lapack_complex_float* v,
+ lapack_int ldv, const lapack_complex_float* t,
+ lapack_int ldt, lapack_complex_float* c,
+ lapack_int ldc );
+lapack_int LAPACKE_zlarfb( int matrix_order, char side, char trans, char direct,
+ char storev, lapack_int m, lapack_int n,
+ lapack_int k, const lapack_complex_double* v,
+ lapack_int ldv, const lapack_complex_double* t,
+ lapack_int ldt, lapack_complex_double* c,
+ lapack_int ldc );
+
+lapack_int LAPACKE_slarfg( lapack_int n, float* alpha, float* x,
+ lapack_int incx, float* tau );
+lapack_int LAPACKE_dlarfg( lapack_int n, double* alpha, double* x,
+ lapack_int incx, double* tau );
+lapack_int LAPACKE_clarfg( lapack_int n, lapack_complex_float* alpha,
+ lapack_complex_float* x, lapack_int incx,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_zlarfg( lapack_int n, lapack_complex_double* alpha,
+ lapack_complex_double* x, lapack_int incx,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_slarft( int matrix_order, char direct, char storev,
+ lapack_int n, lapack_int k, const float* v,
+ lapack_int ldv, const float* tau, float* t,
+ lapack_int ldt );
+lapack_int LAPACKE_dlarft( int matrix_order, char direct, char storev,
+ lapack_int n, lapack_int k, const double* v,
+ lapack_int ldv, const double* tau, double* t,
+ lapack_int ldt );
+lapack_int LAPACKE_clarft( int matrix_order, char direct, char storev,
+ lapack_int n, lapack_int k,
+ const lapack_complex_float* v, lapack_int ldv,
+ const lapack_complex_float* tau,
+ lapack_complex_float* t, lapack_int ldt );
+lapack_int LAPACKE_zlarft( int matrix_order, char direct, char storev,
+ lapack_int n, lapack_int k,
+ const lapack_complex_double* v, lapack_int ldv,
+ const lapack_complex_double* tau,
+ lapack_complex_double* t, lapack_int ldt );
+
+lapack_int LAPACKE_slarfx( int matrix_order, char side, lapack_int m,
+ lapack_int n, const float* v, float tau, float* c,
+ lapack_int ldc, float* work );
+lapack_int LAPACKE_dlarfx( int matrix_order, char side, lapack_int m,
+ lapack_int n, const double* v, double tau, double* c,
+ lapack_int ldc, double* work );
+lapack_int LAPACKE_clarfx( int matrix_order, char side, lapack_int m,
+ lapack_int n, const lapack_complex_float* v,
+ lapack_complex_float tau, lapack_complex_float* c,
+ lapack_int ldc, lapack_complex_float* work );
+lapack_int LAPACKE_zlarfx( int matrix_order, char side, lapack_int m,
+ lapack_int n, const lapack_complex_double* v,
+ lapack_complex_double tau, lapack_complex_double* c,
+ lapack_int ldc, lapack_complex_double* work );
+
+lapack_int LAPACKE_slarnv( lapack_int idist, lapack_int* iseed, lapack_int n,
+ float* x );
+lapack_int LAPACKE_dlarnv( lapack_int idist, lapack_int* iseed, lapack_int n,
+ double* x );
+lapack_int LAPACKE_clarnv( lapack_int idist, lapack_int* iseed, lapack_int n,
+ lapack_complex_float* x );
+lapack_int LAPACKE_zlarnv( lapack_int idist, lapack_int* iseed, lapack_int n,
+ lapack_complex_double* x );
+
+lapack_int LAPACKE_slaset( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, float alpha, float beta, float* a,
+ lapack_int lda );
+lapack_int LAPACKE_dlaset( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, double alpha, double beta, double* a,
+ lapack_int lda );
+lapack_int LAPACKE_claset( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, lapack_complex_float alpha,
+ lapack_complex_float beta, lapack_complex_float* a,
+ lapack_int lda );
+lapack_int LAPACKE_zlaset( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, lapack_complex_double alpha,
+ lapack_complex_double beta, lapack_complex_double* a,
+ lapack_int lda );
+
+lapack_int LAPACKE_slasrt( char id, lapack_int n, float* d );
+lapack_int LAPACKE_dlasrt( char id, lapack_int n, double* d );
+
+lapack_int LAPACKE_slaswp( int matrix_order, lapack_int n, float* a,
+ lapack_int lda, lapack_int k1, lapack_int k2,
+ const lapack_int* ipiv, lapack_int incx );
+lapack_int LAPACKE_dlaswp( int matrix_order, lapack_int n, double* a,
+ lapack_int lda, lapack_int k1, lapack_int k2,
+ const lapack_int* ipiv, lapack_int incx );
+lapack_int LAPACKE_claswp( int matrix_order, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int k1, lapack_int k2, const lapack_int* ipiv,
+ lapack_int incx );
+lapack_int LAPACKE_zlaswp( int matrix_order, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int k1, lapack_int k2, const lapack_int* ipiv,
+ lapack_int incx );
+
+lapack_int LAPACKE_slatms( int matrix_order, lapack_int m, lapack_int n,
+ char dist, lapack_int* iseed, char sym, float* d,
+ lapack_int mode, float cond, float dmax,
+ lapack_int kl, lapack_int ku, char pack, float* a,
+ lapack_int lda );
+lapack_int LAPACKE_dlatms( int matrix_order, lapack_int m, lapack_int n,
+ char dist, lapack_int* iseed, char sym, double* d,
+ lapack_int mode, double cond, double dmax,
+ lapack_int kl, lapack_int ku, char pack, double* a,
+ lapack_int lda );
+lapack_int LAPACKE_clatms( int matrix_order, lapack_int m, lapack_int n,
+ char dist, lapack_int* iseed, char sym, float* d,
+ lapack_int mode, float cond, float dmax,
+ lapack_int kl, lapack_int ku, char pack,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_zlatms( int matrix_order, lapack_int m, lapack_int n,
+ char dist, lapack_int* iseed, char sym, double* d,
+ lapack_int mode, double cond, double dmax,
+ lapack_int kl, lapack_int ku, char pack,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_slauum( int matrix_order, char uplo, lapack_int n, float* a,
+ lapack_int lda );
+lapack_int LAPACKE_dlauum( int matrix_order, char uplo, lapack_int n, double* a,
+ lapack_int lda );
+lapack_int LAPACKE_clauum( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_zlauum( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_sopgtr( int matrix_order, char uplo, lapack_int n,
+ const float* ap, const float* tau, float* q,
+ lapack_int ldq );
+lapack_int LAPACKE_dopgtr( int matrix_order, char uplo, lapack_int n,
+ const double* ap, const double* tau, double* q,
+ lapack_int ldq );
+
+lapack_int LAPACKE_sopmtr( int matrix_order, char side, char uplo, char trans,
+ lapack_int m, lapack_int n, const float* ap,
+ const float* tau, float* c, lapack_int ldc );
+lapack_int LAPACKE_dopmtr( int matrix_order, char side, char uplo, char trans,
+ lapack_int m, lapack_int n, const double* ap,
+ const double* tau, double* c, lapack_int ldc );
+
+lapack_int LAPACKE_sorgbr( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int k, float* a, lapack_int lda,
+ const float* tau );
+lapack_int LAPACKE_dorgbr( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int k, double* a,
+ lapack_int lda, const double* tau );
+
+lapack_int LAPACKE_sorghr( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, float* a, lapack_int lda,
+ const float* tau );
+lapack_int LAPACKE_dorghr( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, double* a, lapack_int lda,
+ const double* tau );
+
+lapack_int LAPACKE_sorglq( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, float* a, lapack_int lda,
+ const float* tau );
+lapack_int LAPACKE_dorglq( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, double* a, lapack_int lda,
+ const double* tau );
+
+lapack_int LAPACKE_sorgql( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, float* a, lapack_int lda,
+ const float* tau );
+lapack_int LAPACKE_dorgql( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, double* a, lapack_int lda,
+ const double* tau );
+
+lapack_int LAPACKE_sorgqr( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, float* a, lapack_int lda,
+ const float* tau );
+lapack_int LAPACKE_dorgqr( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, double* a, lapack_int lda,
+ const double* tau );
+
+lapack_int LAPACKE_sorgrq( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, float* a, lapack_int lda,
+ const float* tau );
+lapack_int LAPACKE_dorgrq( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, double* a, lapack_int lda,
+ const double* tau );
+
+lapack_int LAPACKE_sorgtr( int matrix_order, char uplo, lapack_int n, float* a,
+ lapack_int lda, const float* tau );
+lapack_int LAPACKE_dorgtr( int matrix_order, char uplo, lapack_int n, double* a,
+ lapack_int lda, const double* tau );
+
+lapack_int LAPACKE_sormbr( int matrix_order, char vect, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const float* a, lapack_int lda, const float* tau,
+ float* c, lapack_int ldc );
+lapack_int LAPACKE_dormbr( int matrix_order, char vect, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const double* a, lapack_int lda, const double* tau,
+ double* c, lapack_int ldc );
+
+lapack_int LAPACKE_sormhr( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int ilo,
+ lapack_int ihi, const float* a, lapack_int lda,
+ const float* tau, float* c, lapack_int ldc );
+lapack_int LAPACKE_dormhr( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int ilo,
+ lapack_int ihi, const double* a, lapack_int lda,
+ const double* tau, double* c, lapack_int ldc );
+
+lapack_int LAPACKE_sormlq( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const float* a, lapack_int lda, const float* tau,
+ float* c, lapack_int ldc );
+lapack_int LAPACKE_dormlq( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const double* a, lapack_int lda, const double* tau,
+ double* c, lapack_int ldc );
+
+lapack_int LAPACKE_sormql( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const float* a, lapack_int lda, const float* tau,
+ float* c, lapack_int ldc );
+lapack_int LAPACKE_dormql( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const double* a, lapack_int lda, const double* tau,
+ double* c, lapack_int ldc );
+
+lapack_int LAPACKE_sormqr( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const float* a, lapack_int lda, const float* tau,
+ float* c, lapack_int ldc );
+lapack_int LAPACKE_dormqr( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const double* a, lapack_int lda, const double* tau,
+ double* c, lapack_int ldc );
+
+lapack_int LAPACKE_sormrq( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const float* a, lapack_int lda, const float* tau,
+ float* c, lapack_int ldc );
+lapack_int LAPACKE_dormrq( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const double* a, lapack_int lda, const double* tau,
+ double* c, lapack_int ldc );
+
+lapack_int LAPACKE_sormrz( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, const float* a, lapack_int lda,
+ const float* tau, float* c, lapack_int ldc );
+lapack_int LAPACKE_dormrz( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, const double* a, lapack_int lda,
+ const double* tau, double* c, lapack_int ldc );
+
+lapack_int LAPACKE_sormtr( int matrix_order, char side, char uplo, char trans,
+ lapack_int m, lapack_int n, const float* a,
+ lapack_int lda, const float* tau, float* c,
+ lapack_int ldc );
+lapack_int LAPACKE_dormtr( int matrix_order, char side, char uplo, char trans,
+ lapack_int m, lapack_int n, const double* a,
+ lapack_int lda, const double* tau, double* c,
+ lapack_int ldc );
+
+lapack_int LAPACKE_spbcon( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const float* ab, lapack_int ldab,
+ float anorm, float* rcond );
+lapack_int LAPACKE_dpbcon( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const double* ab, lapack_int ldab,
+ double anorm, double* rcond );
+lapack_int LAPACKE_cpbcon( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const lapack_complex_float* ab,
+ lapack_int ldab, float anorm, float* rcond );
+lapack_int LAPACKE_zpbcon( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const lapack_complex_double* ab,
+ lapack_int ldab, double anorm, double* rcond );
+
+lapack_int LAPACKE_spbequ( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const float* ab, lapack_int ldab,
+ float* s, float* scond, float* amax );
+lapack_int LAPACKE_dpbequ( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const double* ab, lapack_int ldab,
+ double* s, double* scond, double* amax );
+lapack_int LAPACKE_cpbequ( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const lapack_complex_float* ab,
+ lapack_int ldab, float* s, float* scond,
+ float* amax );
+lapack_int LAPACKE_zpbequ( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const lapack_complex_double* ab,
+ lapack_int ldab, double* s, double* scond,
+ double* amax );
+
+lapack_int LAPACKE_spbrfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, const float* ab,
+ lapack_int ldab, const float* afb, lapack_int ldafb,
+ const float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* ferr, float* berr );
+lapack_int LAPACKE_dpbrfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, const double* ab,
+ lapack_int ldab, const double* afb, lapack_int ldafb,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* ferr, double* berr );
+lapack_int LAPACKE_cpbrfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ const lapack_complex_float* ab, lapack_int ldab,
+ const lapack_complex_float* afb, lapack_int ldafb,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zpbrfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ const lapack_complex_double* ab, lapack_int ldab,
+ const lapack_complex_double* afb, lapack_int ldafb,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_spbstf( int matrix_order, char uplo, lapack_int n,
+ lapack_int kb, float* bb, lapack_int ldbb );
+lapack_int LAPACKE_dpbstf( int matrix_order, char uplo, lapack_int n,
+ lapack_int kb, double* bb, lapack_int ldbb );
+lapack_int LAPACKE_cpbstf( int matrix_order, char uplo, lapack_int n,
+ lapack_int kb, lapack_complex_float* bb,
+ lapack_int ldbb );
+lapack_int LAPACKE_zpbstf( int matrix_order, char uplo, lapack_int n,
+ lapack_int kb, lapack_complex_double* bb,
+ lapack_int ldbb );
+
+lapack_int LAPACKE_spbsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, float* ab,
+ lapack_int ldab, float* b, lapack_int ldb );
+lapack_int LAPACKE_dpbsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, double* ab,
+ lapack_int ldab, double* b, lapack_int ldb );
+lapack_int LAPACKE_cpbsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zpbsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_spbsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, float* ab,
+ lapack_int ldab, float* afb, lapack_int ldafb,
+ char* equed, float* s, float* b, lapack_int ldb,
+ float* x, lapack_int ldx, float* rcond, float* ferr,
+ float* berr );
+lapack_int LAPACKE_dpbsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, double* ab,
+ lapack_int ldab, double* afb, lapack_int ldafb,
+ char* equed, double* s, double* b, lapack_int ldb,
+ double* x, lapack_int ldx, double* rcond,
+ double* ferr, double* berr );
+lapack_int LAPACKE_cpbsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* afb, lapack_int ldafb,
+ char* equed, float* s, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zpbsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* afb, lapack_int ldafb,
+ char* equed, double* s, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* rcond, double* ferr,
+ double* berr );
+
+lapack_int LAPACKE_spbtrf( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, float* ab, lapack_int ldab );
+lapack_int LAPACKE_dpbtrf( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, double* ab, lapack_int ldab );
+lapack_int LAPACKE_cpbtrf( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_complex_float* ab,
+ lapack_int ldab );
+lapack_int LAPACKE_zpbtrf( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_complex_double* ab,
+ lapack_int ldab );
+
+lapack_int LAPACKE_spbtrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, const float* ab,
+ lapack_int ldab, float* b, lapack_int ldb );
+lapack_int LAPACKE_dpbtrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, const double* ab,
+ lapack_int ldab, double* b, lapack_int ldb );
+lapack_int LAPACKE_cpbtrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ const lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zpbtrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ const lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_spftrf( int matrix_order, char transr, char uplo,
+ lapack_int n, float* a );
+lapack_int LAPACKE_dpftrf( int matrix_order, char transr, char uplo,
+ lapack_int n, double* a );
+lapack_int LAPACKE_cpftrf( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_complex_float* a );
+lapack_int LAPACKE_zpftrf( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_complex_double* a );
+
+lapack_int LAPACKE_spftri( int matrix_order, char transr, char uplo,
+ lapack_int n, float* a );
+lapack_int LAPACKE_dpftri( int matrix_order, char transr, char uplo,
+ lapack_int n, double* a );
+lapack_int LAPACKE_cpftri( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_complex_float* a );
+lapack_int LAPACKE_zpftri( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_complex_double* a );
+
+lapack_int LAPACKE_spftrs( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_int nrhs, const float* a,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dpftrs( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_int nrhs, const double* a,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_cpftrs( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zpftrs( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_spocon( int matrix_order, char uplo, lapack_int n,
+ const float* a, lapack_int lda, float anorm,
+ float* rcond );
+lapack_int LAPACKE_dpocon( int matrix_order, char uplo, lapack_int n,
+ const double* a, lapack_int lda, double anorm,
+ double* rcond );
+lapack_int LAPACKE_cpocon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float anorm, float* rcond );
+lapack_int LAPACKE_zpocon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double anorm, double* rcond );
+
+lapack_int LAPACKE_spoequ( int matrix_order, lapack_int n, const float* a,
+ lapack_int lda, float* s, float* scond,
+ float* amax );
+lapack_int LAPACKE_dpoequ( int matrix_order, lapack_int n, const double* a,
+ lapack_int lda, double* s, double* scond,
+ double* amax );
+lapack_int LAPACKE_cpoequ( int matrix_order, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* s, float* scond, float* amax );
+lapack_int LAPACKE_zpoequ( int matrix_order, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* s, double* scond, double* amax );
+
+lapack_int LAPACKE_spoequb( int matrix_order, lapack_int n, const float* a,
+ lapack_int lda, float* s, float* scond,
+ float* amax );
+lapack_int LAPACKE_dpoequb( int matrix_order, lapack_int n, const double* a,
+ lapack_int lda, double* s, double* scond,
+ double* amax );
+lapack_int LAPACKE_cpoequb( int matrix_order, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* s, float* scond, float* amax );
+lapack_int LAPACKE_zpoequb( int matrix_order, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* s, double* scond, double* amax );
+
+lapack_int LAPACKE_sporfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ const float* af, lapack_int ldaf, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* ferr, float* berr );
+lapack_int LAPACKE_dporfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* a, lapack_int lda,
+ const double* af, lapack_int ldaf, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* ferr, double* berr );
+lapack_int LAPACKE_cporfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* af,
+ lapack_int ldaf, const lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* ferr, float* berr );
+lapack_int LAPACKE_zporfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* af,
+ lapack_int ldaf, const lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* ferr, double* berr );
+
+lapack_int LAPACKE_sporfsx( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs, const float* a,
+ lapack_int lda, const float* af, lapack_int ldaf,
+ const float* s, const float* b, lapack_int ldb,
+ float* x, lapack_int ldx, float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_dporfsx( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs, const double* a,
+ lapack_int lda, const double* af, lapack_int ldaf,
+ const double* s, const double* b, lapack_int ldb,
+ double* x, lapack_int ldx, double* rcond,
+ double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params );
+lapack_int LAPACKE_cporfsx( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* af, lapack_int ldaf,
+ const float* s, const lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_zporfsx( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* af, lapack_int ldaf,
+ const double* s, const lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params );
+
+lapack_int LAPACKE_sposv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, float* a, lapack_int lda, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dposv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cposv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zposv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dsposv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* x, lapack_int ldx,
+ lapack_int* iter );
+lapack_int LAPACKE_zcposv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, lapack_int* iter );
+
+lapack_int LAPACKE_sposvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, float* a, lapack_int lda, float* af,
+ lapack_int ldaf, char* equed, float* s, float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr );
+lapack_int LAPACKE_dposvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ double* af, lapack_int ldaf, char* equed, double* s,
+ double* b, lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr );
+lapack_int LAPACKE_cposvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* af,
+ lapack_int ldaf, char* equed, float* s,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr );
+lapack_int LAPACKE_zposvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* af,
+ lapack_int ldaf, char* equed, double* s,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr );
+
+lapack_int LAPACKE_sposvxx( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, float* a,
+ lapack_int lda, float* af, lapack_int ldaf,
+ char* equed, float* s, float* b, lapack_int ldb,
+ float* x, lapack_int ldx, float* rcond,
+ float* rpvgrw, float* berr, lapack_int n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int nparams, float* params );
+lapack_int LAPACKE_dposvxx( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, double* a,
+ lapack_int lda, double* af, lapack_int ldaf,
+ char* equed, double* s, double* b, lapack_int ldb,
+ double* x, lapack_int ldx, double* rcond,
+ double* rpvgrw, double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params );
+lapack_int LAPACKE_cposvxx( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ char* equed, float* s, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* rpvgrw,
+ float* berr, lapack_int n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int nparams, float* params );
+lapack_int LAPACKE_zposvxx( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ char* equed, double* s, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* rcond, double* rpvgrw,
+ double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params );
+
+lapack_int LAPACKE_spotrf( int matrix_order, char uplo, lapack_int n, float* a,
+ lapack_int lda );
+lapack_int LAPACKE_dpotrf( int matrix_order, char uplo, lapack_int n, double* a,
+ lapack_int lda );
+lapack_int LAPACKE_cpotrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_zpotrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_spotri( int matrix_order, char uplo, lapack_int n, float* a,
+ lapack_int lda );
+lapack_int LAPACKE_dpotri( int matrix_order, char uplo, lapack_int n, double* a,
+ lapack_int lda );
+lapack_int LAPACKE_cpotri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_zpotri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_spotrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dpotrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* a, lapack_int lda,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_cpotrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zpotrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_sppcon( int matrix_order, char uplo, lapack_int n,
+ const float* ap, float anorm, float* rcond );
+lapack_int LAPACKE_dppcon( int matrix_order, char uplo, lapack_int n,
+ const double* ap, double anorm, double* rcond );
+lapack_int LAPACKE_cppcon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap, float anorm,
+ float* rcond );
+lapack_int LAPACKE_zppcon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap, double anorm,
+ double* rcond );
+
+lapack_int LAPACKE_sppequ( int matrix_order, char uplo, lapack_int n,
+ const float* ap, float* s, float* scond,
+ float* amax );
+lapack_int LAPACKE_dppequ( int matrix_order, char uplo, lapack_int n,
+ const double* ap, double* s, double* scond,
+ double* amax );
+lapack_int LAPACKE_cppequ( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap, float* s,
+ float* scond, float* amax );
+lapack_int LAPACKE_zppequ( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap, double* s,
+ double* scond, double* amax );
+
+lapack_int LAPACKE_spprfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* ap, const float* afp,
+ const float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* ferr, float* berr );
+lapack_int LAPACKE_dpprfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* ap, const double* afp,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* ferr, double* berr );
+lapack_int LAPACKE_cpprfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ const lapack_complex_float* afp,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zpprfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* ap,
+ const lapack_complex_double* afp,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_sppsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, float* ap, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dppsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, double* ap, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cppsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* ap,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zppsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* ap,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_sppsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, float* ap, float* afp, char* equed,
+ float* s, float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr );
+lapack_int LAPACKE_dppsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, double* ap, double* afp,
+ char* equed, double* s, double* b, lapack_int ldb,
+ double* x, lapack_int ldx, double* rcond,
+ double* ferr, double* berr );
+lapack_int LAPACKE_cppsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* ap,
+ lapack_complex_float* afp, char* equed, float* s,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr );
+lapack_int LAPACKE_zppsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* ap,
+ lapack_complex_double* afp, char* equed, double* s,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr );
+
+lapack_int LAPACKE_spptrf( int matrix_order, char uplo, lapack_int n,
+ float* ap );
+lapack_int LAPACKE_dpptrf( int matrix_order, char uplo, lapack_int n,
+ double* ap );
+lapack_int LAPACKE_cpptrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap );
+lapack_int LAPACKE_zpptrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap );
+
+lapack_int LAPACKE_spptri( int matrix_order, char uplo, lapack_int n,
+ float* ap );
+lapack_int LAPACKE_dpptri( int matrix_order, char uplo, lapack_int n,
+ double* ap );
+lapack_int LAPACKE_cpptri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap );
+lapack_int LAPACKE_zpptri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap );
+
+lapack_int LAPACKE_spptrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* ap, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dpptrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* ap, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cpptrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zpptrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* ap,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_spstrf( int matrix_order, char uplo, lapack_int n, float* a,
+ lapack_int lda, lapack_int* piv, lapack_int* rank,
+ float tol );
+lapack_int LAPACKE_dpstrf( int matrix_order, char uplo, lapack_int n, double* a,
+ lapack_int lda, lapack_int* piv, lapack_int* rank,
+ double tol );
+lapack_int LAPACKE_cpstrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* piv, lapack_int* rank, float tol );
+lapack_int LAPACKE_zpstrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* piv, lapack_int* rank, double tol );
+
+lapack_int LAPACKE_sptcon( lapack_int n, const float* d, const float* e,
+ float anorm, float* rcond );
+lapack_int LAPACKE_dptcon( lapack_int n, const double* d, const double* e,
+ double anorm, double* rcond );
+lapack_int LAPACKE_cptcon( lapack_int n, const float* d,
+ const lapack_complex_float* e, float anorm,
+ float* rcond );
+lapack_int LAPACKE_zptcon( lapack_int n, const double* d,
+ const lapack_complex_double* e, double anorm,
+ double* rcond );
+
+lapack_int LAPACKE_spteqr( int matrix_order, char compz, lapack_int n, float* d,
+ float* e, float* z, lapack_int ldz );
+lapack_int LAPACKE_dpteqr( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, double* z, lapack_int ldz );
+lapack_int LAPACKE_cpteqr( int matrix_order, char compz, lapack_int n, float* d,
+ float* e, lapack_complex_float* z, lapack_int ldz );
+lapack_int LAPACKE_zpteqr( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, lapack_complex_double* z,
+ lapack_int ldz );
+
+lapack_int LAPACKE_sptrfs( int matrix_order, lapack_int n, lapack_int nrhs,
+ const float* d, const float* e, const float* df,
+ const float* ef, const float* b, lapack_int ldb,
+ float* x, lapack_int ldx, float* ferr, float* berr );
+lapack_int LAPACKE_dptrfs( int matrix_order, lapack_int n, lapack_int nrhs,
+ const double* d, const double* e, const double* df,
+ const double* ef, const double* b, lapack_int ldb,
+ double* x, lapack_int ldx, double* ferr,
+ double* berr );
+lapack_int LAPACKE_cptrfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* d,
+ const lapack_complex_float* e, const float* df,
+ const lapack_complex_float* ef,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zptrfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* d,
+ const lapack_complex_double* e, const double* df,
+ const lapack_complex_double* ef,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_sptsv( int matrix_order, lapack_int n, lapack_int nrhs,
+ float* d, float* e, float* b, lapack_int ldb );
+lapack_int LAPACKE_dptsv( int matrix_order, lapack_int n, lapack_int nrhs,
+ double* d, double* e, double* b, lapack_int ldb );
+lapack_int LAPACKE_cptsv( int matrix_order, lapack_int n, lapack_int nrhs,
+ float* d, lapack_complex_float* e,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zptsv( int matrix_order, lapack_int n, lapack_int nrhs,
+ double* d, lapack_complex_double* e,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_sptsvx( int matrix_order, char fact, lapack_int n,
+ lapack_int nrhs, const float* d, const float* e,
+ float* df, float* ef, const float* b, lapack_int ldb,
+ float* x, lapack_int ldx, float* rcond, float* ferr,
+ float* berr );
+lapack_int LAPACKE_dptsvx( int matrix_order, char fact, lapack_int n,
+ lapack_int nrhs, const double* d, const double* e,
+ double* df, double* ef, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr );
+lapack_int LAPACKE_cptsvx( int matrix_order, char fact, lapack_int n,
+ lapack_int nrhs, const float* d,
+ const lapack_complex_float* e, float* df,
+ lapack_complex_float* ef,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr );
+lapack_int LAPACKE_zptsvx( int matrix_order, char fact, lapack_int n,
+ lapack_int nrhs, const double* d,
+ const lapack_complex_double* e, double* df,
+ lapack_complex_double* ef,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr );
+
+lapack_int LAPACKE_spttrf( lapack_int n, float* d, float* e );
+lapack_int LAPACKE_dpttrf( lapack_int n, double* d, double* e );
+lapack_int LAPACKE_cpttrf( lapack_int n, float* d, lapack_complex_float* e );
+lapack_int LAPACKE_zpttrf( lapack_int n, double* d, lapack_complex_double* e );
+
+lapack_int LAPACKE_spttrs( int matrix_order, lapack_int n, lapack_int nrhs,
+ const float* d, const float* e, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dpttrs( int matrix_order, lapack_int n, lapack_int nrhs,
+ const double* d, const double* e, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cpttrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* d,
+ const lapack_complex_float* e,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zpttrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* d,
+ const lapack_complex_double* e,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_ssbev( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int kd, float* ab, lapack_int ldab, float* w,
+ float* z, lapack_int ldz );
+lapack_int LAPACKE_dsbev( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int kd, double* ab, lapack_int ldab, double* w,
+ double* z, lapack_int ldz );
+
+lapack_int LAPACKE_ssbevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int kd, float* ab, lapack_int ldab, float* w,
+ float* z, lapack_int ldz );
+lapack_int LAPACKE_dsbevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int kd, double* ab, lapack_int ldab,
+ double* w, double* z, lapack_int ldz );
+
+lapack_int LAPACKE_ssbevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_int kd, float* ab,
+ lapack_int ldab, float* q, lapack_int ldq, float vl,
+ float vu, lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z, lapack_int ldz,
+ lapack_int* ifail );
+lapack_int LAPACKE_dsbevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_int kd, double* ab,
+ lapack_int ldab, double* q, lapack_int ldq,
+ double vl, double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w, double* z,
+ lapack_int ldz, lapack_int* ifail );
+
+lapack_int LAPACKE_ssbgst( int matrix_order, char vect, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb, float* ab,
+ lapack_int ldab, const float* bb, lapack_int ldbb,
+ float* x, lapack_int ldx );
+lapack_int LAPACKE_dsbgst( int matrix_order, char vect, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb, double* ab,
+ lapack_int ldab, const double* bb, lapack_int ldbb,
+ double* x, lapack_int ldx );
+
+lapack_int LAPACKE_ssbgv( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb, float* ab,
+ lapack_int ldab, float* bb, lapack_int ldbb, float* w,
+ float* z, lapack_int ldz );
+lapack_int LAPACKE_dsbgv( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb, double* ab,
+ lapack_int ldab, double* bb, lapack_int ldbb,
+ double* w, double* z, lapack_int ldz );
+
+lapack_int LAPACKE_ssbgvd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb, float* ab,
+ lapack_int ldab, float* bb, lapack_int ldbb,
+ float* w, float* z, lapack_int ldz );
+lapack_int LAPACKE_dsbgvd( int matrix_order, char jobz, char uplo, lapack_int n,
+ lapack_int ka, lapack_int kb, double* ab,
+ lapack_int ldab, double* bb, lapack_int ldbb,
+ double* w, double* z, lapack_int ldz );
+
+lapack_int LAPACKE_ssbgvx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ float* ab, lapack_int ldab, float* bb,
+ lapack_int ldbb, float* q, lapack_int ldq, float vl,
+ float vu, lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z, lapack_int ldz,
+ lapack_int* ifail );
+lapack_int LAPACKE_dsbgvx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ double* ab, lapack_int ldab, double* bb,
+ lapack_int ldbb, double* q, lapack_int ldq,
+ double vl, double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w, double* z,
+ lapack_int ldz, lapack_int* ifail );
+
+lapack_int LAPACKE_ssbtrd( int matrix_order, char vect, char uplo, lapack_int n,
+ lapack_int kd, float* ab, lapack_int ldab, float* d,
+ float* e, float* q, lapack_int ldq );
+lapack_int LAPACKE_dsbtrd( int matrix_order, char vect, char uplo, lapack_int n,
+ lapack_int kd, double* ab, lapack_int ldab,
+ double* d, double* e, double* q, lapack_int ldq );
+
+lapack_int LAPACKE_ssfrk( int matrix_order, char transr, char uplo, char trans,
+ lapack_int n, lapack_int k, float alpha,
+ const float* a, lapack_int lda, float beta,
+ float* c );
+lapack_int LAPACKE_dsfrk( int matrix_order, char transr, char uplo, char trans,
+ lapack_int n, lapack_int k, double alpha,
+ const double* a, lapack_int lda, double beta,
+ double* c );
+
+lapack_int LAPACKE_sspcon( int matrix_order, char uplo, lapack_int n,
+ const float* ap, const lapack_int* ipiv, float anorm,
+ float* rcond );
+lapack_int LAPACKE_dspcon( int matrix_order, char uplo, lapack_int n,
+ const double* ap, const lapack_int* ipiv,
+ double anorm, double* rcond );
+lapack_int LAPACKE_cspcon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap,
+ const lapack_int* ipiv, float anorm, float* rcond );
+lapack_int LAPACKE_zspcon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap,
+ const lapack_int* ipiv, double anorm,
+ double* rcond );
+
+lapack_int LAPACKE_sspev( int matrix_order, char jobz, char uplo, lapack_int n,
+ float* ap, float* w, float* z, lapack_int ldz );
+lapack_int LAPACKE_dspev( int matrix_order, char jobz, char uplo, lapack_int n,
+ double* ap, double* w, double* z, lapack_int ldz );
+
+lapack_int LAPACKE_sspevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ float* ap, float* w, float* z, lapack_int ldz );
+lapack_int LAPACKE_dspevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ double* ap, double* w, double* z, lapack_int ldz );
+
+lapack_int LAPACKE_sspevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, float* ap, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z, lapack_int ldz,
+ lapack_int* ifail );
+lapack_int LAPACKE_dspevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, double* ap, double vl, double vu,
+ lapack_int il, lapack_int iu, double abstol,
+ lapack_int* m, double* w, double* z, lapack_int ldz,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_sspgst( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, float* ap, const float* bp );
+lapack_int LAPACKE_dspgst( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, double* ap, const double* bp );
+
+lapack_int LAPACKE_sspgv( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, float* ap, float* bp,
+ float* w, float* z, lapack_int ldz );
+lapack_int LAPACKE_dspgv( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, double* ap, double* bp,
+ double* w, double* z, lapack_int ldz );
+
+lapack_int LAPACKE_sspgvd( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, float* ap, float* bp,
+ float* w, float* z, lapack_int ldz );
+lapack_int LAPACKE_dspgvd( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, double* ap, double* bp,
+ double* w, double* z, lapack_int ldz );
+
+lapack_int LAPACKE_sspgvx( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n, float* ap,
+ float* bp, float vl, float vu, lapack_int il,
+ lapack_int iu, float abstol, lapack_int* m, float* w,
+ float* z, lapack_int ldz, lapack_int* ifail );
+lapack_int LAPACKE_dspgvx( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n, double* ap,
+ double* bp, double vl, double vu, lapack_int il,
+ lapack_int iu, double abstol, lapack_int* m,
+ double* w, double* z, lapack_int ldz,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_ssprfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* ap, const float* afp,
+ const lapack_int* ipiv, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* ferr, float* berr );
+lapack_int LAPACKE_dsprfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* ap, const double* afp,
+ const lapack_int* ipiv, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* ferr, double* berr );
+lapack_int LAPACKE_csprfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ const lapack_complex_float* afp,
+ const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zsprfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* ap,
+ const lapack_complex_double* afp,
+ const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_sspsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, float* ap, lapack_int* ipiv,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dspsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, double* ap, lapack_int* ipiv,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_cspsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* ap,
+ lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zspsv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* ap,
+ lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_sspsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const float* ap, float* afp,
+ lapack_int* ipiv, const float* b, lapack_int ldb,
+ float* x, lapack_int ldx, float* rcond, float* ferr,
+ float* berr );
+lapack_int LAPACKE_dspsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const double* ap, double* afp,
+ lapack_int* ipiv, const double* b, lapack_int ldb,
+ double* x, lapack_int ldx, double* rcond,
+ double* ferr, double* berr );
+lapack_int LAPACKE_cspsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ lapack_complex_float* afp, lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr );
+lapack_int LAPACKE_zspsvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* ap,
+ lapack_complex_double* afp, lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr );
+
+lapack_int LAPACKE_ssptrd( int matrix_order, char uplo, lapack_int n, float* ap,
+ float* d, float* e, float* tau );
+lapack_int LAPACKE_dsptrd( int matrix_order, char uplo, lapack_int n,
+ double* ap, double* d, double* e, double* tau );
+
+lapack_int LAPACKE_ssptrf( int matrix_order, char uplo, lapack_int n, float* ap,
+ lapack_int* ipiv );
+lapack_int LAPACKE_dsptrf( int matrix_order, char uplo, lapack_int n,
+ double* ap, lapack_int* ipiv );
+lapack_int LAPACKE_csptrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap, lapack_int* ipiv );
+lapack_int LAPACKE_zsptrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap, lapack_int* ipiv );
+
+lapack_int LAPACKE_ssptri( int matrix_order, char uplo, lapack_int n, float* ap,
+ const lapack_int* ipiv );
+lapack_int LAPACKE_dsptri( int matrix_order, char uplo, lapack_int n,
+ double* ap, const lapack_int* ipiv );
+lapack_int LAPACKE_csptri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap, const lapack_int* ipiv );
+lapack_int LAPACKE_zsptri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap, const lapack_int* ipiv );
+
+lapack_int LAPACKE_ssptrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* ap,
+ const lapack_int* ipiv, float* b, lapack_int ldb );
+lapack_int LAPACKE_dsptrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* ap,
+ const lapack_int* ipiv, double* b, lapack_int ldb );
+lapack_int LAPACKE_csptrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ const lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zsptrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* ap,
+ const lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_sstebz( char range, char order, lapack_int n, float vl,
+ float vu, lapack_int il, lapack_int iu, float abstol,
+ const float* d, const float* e, lapack_int* m,
+ lapack_int* nsplit, float* w, lapack_int* iblock,
+ lapack_int* isplit );
+lapack_int LAPACKE_dstebz( char range, char order, lapack_int n, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, const double* d, const double* e,
+ lapack_int* m, lapack_int* nsplit, double* w,
+ lapack_int* iblock, lapack_int* isplit );
+
+lapack_int LAPACKE_sstedc( int matrix_order, char compz, lapack_int n, float* d,
+ float* e, float* z, lapack_int ldz );
+lapack_int LAPACKE_dstedc( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, double* z, lapack_int ldz );
+lapack_int LAPACKE_cstedc( int matrix_order, char compz, lapack_int n, float* d,
+ float* e, lapack_complex_float* z, lapack_int ldz );
+lapack_int LAPACKE_zstedc( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, lapack_complex_double* z,
+ lapack_int ldz );
+
+lapack_int LAPACKE_sstegr( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z, lapack_int ldz,
+ lapack_int* isuppz );
+lapack_int LAPACKE_dstegr( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w, double* z,
+ lapack_int ldz, lapack_int* isuppz );
+lapack_int LAPACKE_cstegr( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_int* isuppz );
+lapack_int LAPACKE_zstegr( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int* isuppz );
+
+lapack_int LAPACKE_sstein( int matrix_order, lapack_int n, const float* d,
+ const float* e, lapack_int m, const float* w,
+ const lapack_int* iblock, const lapack_int* isplit,
+ float* z, lapack_int ldz, lapack_int* ifailv );
+lapack_int LAPACKE_dstein( int matrix_order, lapack_int n, const double* d,
+ const double* e, lapack_int m, const double* w,
+ const lapack_int* iblock, const lapack_int* isplit,
+ double* z, lapack_int ldz, lapack_int* ifailv );
+lapack_int LAPACKE_cstein( int matrix_order, lapack_int n, const float* d,
+ const float* e, lapack_int m, const float* w,
+ const lapack_int* iblock, const lapack_int* isplit,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_int* ifailv );
+lapack_int LAPACKE_zstein( int matrix_order, lapack_int n, const double* d,
+ const double* e, lapack_int m, const double* w,
+ const lapack_int* iblock, const lapack_int* isplit,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int* ifailv );
+
+lapack_int LAPACKE_sstemr( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl, float vu,
+ lapack_int il, lapack_int iu, lapack_int* m,
+ float* w, float* z, lapack_int ldz, lapack_int nzc,
+ lapack_int* isuppz, lapack_logical* tryrac );
+lapack_int LAPACKE_dstemr( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ lapack_int* m, double* w, double* z, lapack_int ldz,
+ lapack_int nzc, lapack_int* isuppz,
+ lapack_logical* tryrac );
+lapack_int LAPACKE_cstemr( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl, float vu,
+ lapack_int il, lapack_int iu, lapack_int* m,
+ float* w, lapack_complex_float* z, lapack_int ldz,
+ lapack_int nzc, lapack_int* isuppz,
+ lapack_logical* tryrac );
+lapack_int LAPACKE_zstemr( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ lapack_int* m, double* w, lapack_complex_double* z,
+ lapack_int ldz, lapack_int nzc, lapack_int* isuppz,
+ lapack_logical* tryrac );
+
+lapack_int LAPACKE_ssteqr( int matrix_order, char compz, lapack_int n, float* d,
+ float* e, float* z, lapack_int ldz );
+lapack_int LAPACKE_dsteqr( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, double* z, lapack_int ldz );
+lapack_int LAPACKE_csteqr( int matrix_order, char compz, lapack_int n, float* d,
+ float* e, lapack_complex_float* z, lapack_int ldz );
+lapack_int LAPACKE_zsteqr( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, lapack_complex_double* z,
+ lapack_int ldz );
+
+lapack_int LAPACKE_ssterf( lapack_int n, float* d, float* e );
+lapack_int LAPACKE_dsterf( lapack_int n, double* d, double* e );
+
+lapack_int LAPACKE_sstev( int matrix_order, char jobz, lapack_int n, float* d,
+ float* e, float* z, lapack_int ldz );
+lapack_int LAPACKE_dstev( int matrix_order, char jobz, lapack_int n, double* d,
+ double* e, double* z, lapack_int ldz );
+
+lapack_int LAPACKE_sstevd( int matrix_order, char jobz, lapack_int n, float* d,
+ float* e, float* z, lapack_int ldz );
+lapack_int LAPACKE_dstevd( int matrix_order, char jobz, lapack_int n, double* d,
+ double* e, double* z, lapack_int ldz );
+
+lapack_int LAPACKE_sstevr( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z, lapack_int ldz,
+ lapack_int* isuppz );
+lapack_int LAPACKE_dstevr( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w, double* z,
+ lapack_int ldz, lapack_int* isuppz );
+
+lapack_int LAPACKE_sstevx( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z, lapack_int ldz,
+ lapack_int* ifail );
+lapack_int LAPACKE_dstevx( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w, double* z,
+ lapack_int ldz, lapack_int* ifail );
+
+lapack_int LAPACKE_ssycon( int matrix_order, char uplo, lapack_int n,
+ const float* a, lapack_int lda,
+ const lapack_int* ipiv, float anorm, float* rcond );
+lapack_int LAPACKE_dsycon( int matrix_order, char uplo, lapack_int n,
+ const double* a, lapack_int lda,
+ const lapack_int* ipiv, double anorm,
+ double* rcond );
+lapack_int LAPACKE_csycon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv, float anorm, float* rcond );
+lapack_int LAPACKE_zsycon( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv, double anorm,
+ double* rcond );
+
+lapack_int LAPACKE_ssyequb( int matrix_order, char uplo, lapack_int n,
+ const float* a, lapack_int lda, float* s,
+ float* scond, float* amax );
+lapack_int LAPACKE_dsyequb( int matrix_order, char uplo, lapack_int n,
+ const double* a, lapack_int lda, double* s,
+ double* scond, double* amax );
+lapack_int LAPACKE_csyequb( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* s, float* scond, float* amax );
+lapack_int LAPACKE_zsyequb( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* s, double* scond, double* amax );
+
+lapack_int LAPACKE_ssyev( int matrix_order, char jobz, char uplo, lapack_int n,
+ float* a, lapack_int lda, float* w );
+lapack_int LAPACKE_dsyev( int matrix_order, char jobz, char uplo, lapack_int n,
+ double* a, lapack_int lda, double* w );
+
+lapack_int LAPACKE_ssyevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ float* a, lapack_int lda, float* w );
+lapack_int LAPACKE_dsyevd( int matrix_order, char jobz, char uplo, lapack_int n,
+ double* a, lapack_int lda, double* w );
+
+lapack_int LAPACKE_ssyevr( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, float* a, lapack_int lda, float vl,
+ float vu, lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z, lapack_int ldz,
+ lapack_int* isuppz );
+lapack_int LAPACKE_dsyevr( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, double* a, lapack_int lda, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w, double* z,
+ lapack_int ldz, lapack_int* isuppz );
+
+lapack_int LAPACKE_ssyevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, float* a, lapack_int lda, float vl,
+ float vu, lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z, lapack_int ldz,
+ lapack_int* ifail );
+lapack_int LAPACKE_dsyevx( int matrix_order, char jobz, char range, char uplo,
+ lapack_int n, double* a, lapack_int lda, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w, double* z,
+ lapack_int ldz, lapack_int* ifail );
+
+lapack_int LAPACKE_ssygst( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, float* a, lapack_int lda,
+ const float* b, lapack_int ldb );
+lapack_int LAPACKE_dsygst( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, double* a, lapack_int lda,
+ const double* b, lapack_int ldb );
+
+lapack_int LAPACKE_ssygv( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, float* a, lapack_int lda,
+ float* b, lapack_int ldb, float* w );
+lapack_int LAPACKE_dsygv( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* w );
+
+lapack_int LAPACKE_ssygvd( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, float* a, lapack_int lda,
+ float* b, lapack_int ldb, float* w );
+lapack_int LAPACKE_dsygvd( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* w );
+
+lapack_int LAPACKE_ssygvx( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb, float vl,
+ float vu, lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z, lapack_int ldz,
+ lapack_int* ifail );
+lapack_int LAPACKE_dsygvx( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n, double* a,
+ lapack_int lda, double* b, lapack_int ldb, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w, double* z,
+ lapack_int ldz, lapack_int* ifail );
+
+lapack_int LAPACKE_ssyrfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ const float* af, lapack_int ldaf,
+ const lapack_int* ipiv, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* ferr, float* berr );
+lapack_int LAPACKE_dsyrfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* a, lapack_int lda,
+ const double* af, lapack_int ldaf,
+ const lapack_int* ipiv, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* ferr, double* berr );
+lapack_int LAPACKE_csyrfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx, float* ferr,
+ float* berr );
+lapack_int LAPACKE_zsyrfs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_ssyrfsx( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs, const float* a,
+ lapack_int lda, const float* af, lapack_int ldaf,
+ const lapack_int* ipiv, const float* s,
+ const float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_dsyrfsx( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs, const double* a,
+ lapack_int lda, const double* af, lapack_int ldaf,
+ const lapack_int* ipiv, const double* s,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params );
+lapack_int LAPACKE_csyrfsx( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* af, lapack_int ldaf,
+ const lapack_int* ipiv, const float* s,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* berr, lapack_int n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int nparams, float* params );
+lapack_int LAPACKE_zsyrfsx( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* af, lapack_int ldaf,
+ const lapack_int* ipiv, const double* s,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params );
+
+lapack_int LAPACKE_ssysv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, float* a, lapack_int lda,
+ lapack_int* ipiv, float* b, lapack_int ldb );
+lapack_int LAPACKE_dsysv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ lapack_int* ipiv, double* b, lapack_int ldb );
+lapack_int LAPACKE_csysv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zsysv( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_ssysvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ float* af, lapack_int ldaf, lapack_int* ipiv,
+ const float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr );
+lapack_int LAPACKE_dsysvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const double* a, lapack_int lda,
+ double* af, lapack_int ldaf, lapack_int* ipiv,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* rcond, double* ferr,
+ double* berr );
+lapack_int LAPACKE_csysvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* af,
+ lapack_int ldaf, lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr );
+lapack_int LAPACKE_zsysvx( int matrix_order, char fact, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* af,
+ lapack_int ldaf, lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr );
+
+lapack_int LAPACKE_ssysvxx( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, float* a,
+ lapack_int lda, float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* s, float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_dsysvxx( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, double* a,
+ lapack_int lda, double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* s, double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params );
+lapack_int LAPACKE_csysvxx( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* s,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params );
+lapack_int LAPACKE_zsysvxx( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* s,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params );
+
+lapack_int LAPACKE_ssytrd( int matrix_order, char uplo, lapack_int n, float* a,
+ lapack_int lda, float* d, float* e, float* tau );
+lapack_int LAPACKE_dsytrd( int matrix_order, char uplo, lapack_int n, double* a,
+ lapack_int lda, double* d, double* e, double* tau );
+
+lapack_int LAPACKE_ssytrf( int matrix_order, char uplo, lapack_int n, float* a,
+ lapack_int lda, lapack_int* ipiv );
+lapack_int LAPACKE_dsytrf( int matrix_order, char uplo, lapack_int n, double* a,
+ lapack_int lda, lapack_int* ipiv );
+lapack_int LAPACKE_csytrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ipiv );
+lapack_int LAPACKE_zsytrf( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv );
+
+lapack_int LAPACKE_ssytri( int matrix_order, char uplo, lapack_int n, float* a,
+ lapack_int lda, const lapack_int* ipiv );
+lapack_int LAPACKE_dsytri( int matrix_order, char uplo, lapack_int n, double* a,
+ lapack_int lda, const lapack_int* ipiv );
+lapack_int LAPACKE_csytri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv );
+lapack_int LAPACKE_zsytri( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv );
+
+lapack_int LAPACKE_ssytrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ const lapack_int* ipiv, float* b, lapack_int ldb );
+lapack_int LAPACKE_dsytrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* a, lapack_int lda,
+ const lapack_int* ipiv, double* b, lapack_int ldb );
+lapack_int LAPACKE_csytrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zsytrs( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_stbcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, lapack_int kd, const float* ab,
+ lapack_int ldab, float* rcond );
+lapack_int LAPACKE_dtbcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, lapack_int kd, const double* ab,
+ lapack_int ldab, double* rcond );
+lapack_int LAPACKE_ctbcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, lapack_int kd,
+ const lapack_complex_float* ab, lapack_int ldab,
+ float* rcond );
+lapack_int LAPACKE_ztbcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, lapack_int kd,
+ const lapack_complex_double* ab, lapack_int ldab,
+ double* rcond );
+
+lapack_int LAPACKE_stbrfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ const float* ab, lapack_int ldab, const float* b,
+ lapack_int ldb, const float* x, lapack_int ldx,
+ float* ferr, float* berr );
+lapack_int LAPACKE_dtbrfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ const double* ab, lapack_int ldab, const double* b,
+ lapack_int ldb, const double* x, lapack_int ldx,
+ double* ferr, double* berr );
+lapack_int LAPACKE_ctbrfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ const lapack_complex_float* ab, lapack_int ldab,
+ const lapack_complex_float* b, lapack_int ldb,
+ const lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr );
+lapack_int LAPACKE_ztbrfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ const lapack_complex_double* ab, lapack_int ldab,
+ const lapack_complex_double* b, lapack_int ldb,
+ const lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_stbtrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ const float* ab, lapack_int ldab, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dtbtrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ const double* ab, lapack_int ldab, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_ctbtrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ const lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_ztbtrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ const lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_stfsm( int matrix_order, char transr, char side, char uplo,
+ char trans, char diag, lapack_int m, lapack_int n,
+ float alpha, const float* a, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dtfsm( int matrix_order, char transr, char side, char uplo,
+ char trans, char diag, lapack_int m, lapack_int n,
+ double alpha, const double* a, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_ctfsm( int matrix_order, char transr, char side, char uplo,
+ char trans, char diag, lapack_int m, lapack_int n,
+ lapack_complex_float alpha,
+ const lapack_complex_float* a,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_ztfsm( int matrix_order, char transr, char side, char uplo,
+ char trans, char diag, lapack_int m, lapack_int n,
+ lapack_complex_double alpha,
+ const lapack_complex_double* a,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_stftri( int matrix_order, char transr, char uplo, char diag,
+ lapack_int n, float* a );
+lapack_int LAPACKE_dtftri( int matrix_order, char transr, char uplo, char diag,
+ lapack_int n, double* a );
+lapack_int LAPACKE_ctftri( int matrix_order, char transr, char uplo, char diag,
+ lapack_int n, lapack_complex_float* a );
+lapack_int LAPACKE_ztftri( int matrix_order, char transr, char uplo, char diag,
+ lapack_int n, lapack_complex_double* a );
+
+lapack_int LAPACKE_stfttp( int matrix_order, char transr, char uplo,
+ lapack_int n, const float* arf, float* ap );
+lapack_int LAPACKE_dtfttp( int matrix_order, char transr, char uplo,
+ lapack_int n, const double* arf, double* ap );
+lapack_int LAPACKE_ctfttp( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_float* arf,
+ lapack_complex_float* ap );
+lapack_int LAPACKE_ztfttp( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_double* arf,
+ lapack_complex_double* ap );
+
+lapack_int LAPACKE_stfttr( int matrix_order, char transr, char uplo,
+ lapack_int n, const float* arf, float* a,
+ lapack_int lda );
+lapack_int LAPACKE_dtfttr( int matrix_order, char transr, char uplo,
+ lapack_int n, const double* arf, double* a,
+ lapack_int lda );
+lapack_int LAPACKE_ctfttr( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_float* arf,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_ztfttr( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_double* arf,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_stgevc( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const float* s, lapack_int lds, const float* p,
+ lapack_int ldp, float* vl, lapack_int ldvl,
+ float* vr, lapack_int ldvr, lapack_int mm,
+ lapack_int* m );
+lapack_int LAPACKE_dtgevc( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const double* s, lapack_int lds, const double* p,
+ lapack_int ldp, double* vl, lapack_int ldvl,
+ double* vr, lapack_int ldvr, lapack_int mm,
+ lapack_int* m );
+lapack_int LAPACKE_ctgevc( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_float* s, lapack_int lds,
+ const lapack_complex_float* p, lapack_int ldp,
+ lapack_complex_float* vl, lapack_int ldvl,
+ lapack_complex_float* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m );
+lapack_int LAPACKE_ztgevc( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_double* s, lapack_int lds,
+ const lapack_complex_double* p, lapack_int ldp,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m );
+
+lapack_int LAPACKE_stgexc( int matrix_order, lapack_logical wantq,
+ lapack_logical wantz, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb, float* q,
+ lapack_int ldq, float* z, lapack_int ldz,
+ lapack_int* ifst, lapack_int* ilst );
+lapack_int LAPACKE_dtgexc( int matrix_order, lapack_logical wantq,
+ lapack_logical wantz, lapack_int n, double* a,
+ lapack_int lda, double* b, lapack_int ldb, double* q,
+ lapack_int ldq, double* z, lapack_int ldz,
+ lapack_int* ifst, lapack_int* ilst );
+lapack_int LAPACKE_ctgexc( int matrix_order, lapack_logical wantq,
+ lapack_logical wantz, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_int ifst, lapack_int ilst );
+lapack_int LAPACKE_ztgexc( int matrix_order, lapack_logical wantq,
+ lapack_logical wantz, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int ifst, lapack_int ilst );
+
+lapack_int LAPACKE_stgsen( int matrix_order, lapack_int ijob,
+ lapack_logical wantq, lapack_logical wantz,
+ const lapack_logical* select, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb,
+ float* alphar, float* alphai, float* beta, float* q,
+ lapack_int ldq, float* z, lapack_int ldz,
+ lapack_int* m, float* pl, float* pr, float* dif );
+lapack_int LAPACKE_dtgsen( int matrix_order, lapack_int ijob,
+ lapack_logical wantq, lapack_logical wantz,
+ const lapack_logical* select, lapack_int n,
+ double* a, lapack_int lda, double* b, lapack_int ldb,
+ double* alphar, double* alphai, double* beta,
+ double* q, lapack_int ldq, double* z, lapack_int ldz,
+ lapack_int* m, double* pl, double* pr, double* dif );
+lapack_int LAPACKE_ctgsen( int matrix_order, lapack_int ijob,
+ lapack_logical wantq, lapack_logical wantz,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* alpha,
+ lapack_complex_float* beta, lapack_complex_float* q,
+ lapack_int ldq, lapack_complex_float* z,
+ lapack_int ldz, lapack_int* m, float* pl, float* pr,
+ float* dif );
+lapack_int LAPACKE_ztgsen( int matrix_order, lapack_int ijob,
+ lapack_logical wantq, lapack_logical wantz,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int* m, double* pl, double* pr, double* dif );
+
+lapack_int LAPACKE_stgsja( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int p, lapack_int n,
+ lapack_int k, lapack_int l, float* a, lapack_int lda,
+ float* b, lapack_int ldb, float tola, float tolb,
+ float* alpha, float* beta, float* u, lapack_int ldu,
+ float* v, lapack_int ldv, float* q, lapack_int ldq,
+ lapack_int* ncycle );
+lapack_int LAPACKE_dtgsja( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int p, lapack_int n,
+ lapack_int k, lapack_int l, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ double tola, double tolb, double* alpha,
+ double* beta, double* u, lapack_int ldu, double* v,
+ lapack_int ldv, double* q, lapack_int ldq,
+ lapack_int* ncycle );
+lapack_int LAPACKE_ctgsja( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int p, lapack_int n,
+ lapack_int k, lapack_int l, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, float tola, float tolb, float* alpha,
+ float* beta, lapack_complex_float* u, lapack_int ldu,
+ lapack_complex_float* v, lapack_int ldv,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_int* ncycle );
+lapack_int LAPACKE_ztgsja( int matrix_order, char jobu, char jobv, char jobq,
+ lapack_int m, lapack_int p, lapack_int n,
+ lapack_int k, lapack_int l, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, double tola, double tolb,
+ double* alpha, double* beta,
+ lapack_complex_double* u, lapack_int ldu,
+ lapack_complex_double* v, lapack_int ldv,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_int* ncycle );
+
+lapack_int LAPACKE_stgsna( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const float* a, lapack_int lda, const float* b,
+ lapack_int ldb, const float* vl, lapack_int ldvl,
+ const float* vr, lapack_int ldvr, float* s,
+ float* dif, lapack_int mm, lapack_int* m );
+lapack_int LAPACKE_dtgsna( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const double* a, lapack_int lda, const double* b,
+ lapack_int ldb, const double* vl, lapack_int ldvl,
+ const double* vr, lapack_int ldvr, double* s,
+ double* dif, lapack_int mm, lapack_int* m );
+lapack_int LAPACKE_ctgsna( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* b, lapack_int ldb,
+ const lapack_complex_float* vl, lapack_int ldvl,
+ const lapack_complex_float* vr, lapack_int ldvr,
+ float* s, float* dif, lapack_int mm, lapack_int* m );
+lapack_int LAPACKE_ztgsna( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* b, lapack_int ldb,
+ const lapack_complex_double* vl, lapack_int ldvl,
+ const lapack_complex_double* vr, lapack_int ldvr,
+ double* s, double* dif, lapack_int mm,
+ lapack_int* m );
+
+lapack_int LAPACKE_stgsyl( int matrix_order, char trans, lapack_int ijob,
+ lapack_int m, lapack_int n, const float* a,
+ lapack_int lda, const float* b, lapack_int ldb,
+ float* c, lapack_int ldc, const float* d,
+ lapack_int ldd, const float* e, lapack_int lde,
+ float* f, lapack_int ldf, float* scale, float* dif );
+lapack_int LAPACKE_dtgsyl( int matrix_order, char trans, lapack_int ijob,
+ lapack_int m, lapack_int n, const double* a,
+ lapack_int lda, const double* b, lapack_int ldb,
+ double* c, lapack_int ldc, const double* d,
+ lapack_int ldd, const double* e, lapack_int lde,
+ double* f, lapack_int ldf, double* scale,
+ double* dif );
+lapack_int LAPACKE_ctgsyl( int matrix_order, char trans, lapack_int ijob,
+ lapack_int m, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* c, lapack_int ldc,
+ const lapack_complex_float* d, lapack_int ldd,
+ const lapack_complex_float* e, lapack_int lde,
+ lapack_complex_float* f, lapack_int ldf,
+ float* scale, float* dif );
+lapack_int LAPACKE_ztgsyl( int matrix_order, char trans, lapack_int ijob,
+ lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* c, lapack_int ldc,
+ const lapack_complex_double* d, lapack_int ldd,
+ const lapack_complex_double* e, lapack_int lde,
+ lapack_complex_double* f, lapack_int ldf,
+ double* scale, double* dif );
+
+lapack_int LAPACKE_stpcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, const float* ap, float* rcond );
+lapack_int LAPACKE_dtpcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, const double* ap, double* rcond );
+lapack_int LAPACKE_ctpcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, const lapack_complex_float* ap,
+ float* rcond );
+lapack_int LAPACKE_ztpcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, const lapack_complex_double* ap,
+ double* rcond );
+
+lapack_int LAPACKE_stprfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs, const float* ap,
+ const float* b, lapack_int ldb, const float* x,
+ lapack_int ldx, float* ferr, float* berr );
+lapack_int LAPACKE_dtprfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs, const double* ap,
+ const double* b, lapack_int ldb, const double* x,
+ lapack_int ldx, double* ferr, double* berr );
+lapack_int LAPACKE_ctprfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* ap,
+ const lapack_complex_float* b, lapack_int ldb,
+ const lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr );
+lapack_int LAPACKE_ztprfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* b, lapack_int ldb,
+ const lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_stptri( int matrix_order, char uplo, char diag, lapack_int n,
+ float* ap );
+lapack_int LAPACKE_dtptri( int matrix_order, char uplo, char diag, lapack_int n,
+ double* ap );
+lapack_int LAPACKE_ctptri( int matrix_order, char uplo, char diag, lapack_int n,
+ lapack_complex_float* ap );
+lapack_int LAPACKE_ztptri( int matrix_order, char uplo, char diag, lapack_int n,
+ lapack_complex_double* ap );
+
+lapack_int LAPACKE_stptrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs, const float* ap,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dtptrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs, const double* ap,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_ctptrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* ap,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_ztptrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* ap,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_stpttf( int matrix_order, char transr, char uplo,
+ lapack_int n, const float* ap, float* arf );
+lapack_int LAPACKE_dtpttf( int matrix_order, char transr, char uplo,
+ lapack_int n, const double* ap, double* arf );
+lapack_int LAPACKE_ctpttf( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_float* ap,
+ lapack_complex_float* arf );
+lapack_int LAPACKE_ztpttf( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_double* ap,
+ lapack_complex_double* arf );
+
+lapack_int LAPACKE_stpttr( int matrix_order, char uplo, lapack_int n,
+ const float* ap, float* a, lapack_int lda );
+lapack_int LAPACKE_dtpttr( int matrix_order, char uplo, lapack_int n,
+ const double* ap, double* a, lapack_int lda );
+lapack_int LAPACKE_ctpttr( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_ztpttr( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_strcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, const float* a, lapack_int lda,
+ float* rcond );
+lapack_int LAPACKE_dtrcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, const double* a, lapack_int lda,
+ double* rcond );
+lapack_int LAPACKE_ctrcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, const lapack_complex_float* a,
+ lapack_int lda, float* rcond );
+lapack_int LAPACKE_ztrcon( int matrix_order, char norm, char uplo, char diag,
+ lapack_int n, const lapack_complex_double* a,
+ lapack_int lda, double* rcond );
+
+lapack_int LAPACKE_strevc( int matrix_order, char side, char howmny,
+ lapack_logical* select, lapack_int n, const float* t,
+ lapack_int ldt, float* vl, lapack_int ldvl,
+ float* vr, lapack_int ldvr, lapack_int mm,
+ lapack_int* m );
+lapack_int LAPACKE_dtrevc( int matrix_order, char side, char howmny,
+ lapack_logical* select, lapack_int n,
+ const double* t, lapack_int ldt, double* vl,
+ lapack_int ldvl, double* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m );
+lapack_int LAPACKE_ctrevc( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* vl, lapack_int ldvl,
+ lapack_complex_float* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m );
+lapack_int LAPACKE_ztrevc( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m );
+
+lapack_int LAPACKE_strexc( int matrix_order, char compq, lapack_int n, float* t,
+ lapack_int ldt, float* q, lapack_int ldq,
+ lapack_int* ifst, lapack_int* ilst );
+lapack_int LAPACKE_dtrexc( int matrix_order, char compq, lapack_int n,
+ double* t, lapack_int ldt, double* q, lapack_int ldq,
+ lapack_int* ifst, lapack_int* ilst );
+lapack_int LAPACKE_ctrexc( int matrix_order, char compq, lapack_int n,
+ lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_int ifst, lapack_int ilst );
+lapack_int LAPACKE_ztrexc( int matrix_order, char compq, lapack_int n,
+ lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_int ifst, lapack_int ilst );
+
+lapack_int LAPACKE_strrfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs, const float* a,
+ lapack_int lda, const float* b, lapack_int ldb,
+ const float* x, lapack_int ldx, float* ferr,
+ float* berr );
+lapack_int LAPACKE_dtrrfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs, const double* a,
+ lapack_int lda, const double* b, lapack_int ldb,
+ const double* x, lapack_int ldx, double* ferr,
+ double* berr );
+lapack_int LAPACKE_ctrrfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* b, lapack_int ldb,
+ const lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr );
+lapack_int LAPACKE_ztrrfs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* b, lapack_int ldb,
+ const lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr );
+
+lapack_int LAPACKE_strsen( int matrix_order, char job, char compq,
+ const lapack_logical* select, lapack_int n, float* t,
+ lapack_int ldt, float* q, lapack_int ldq, float* wr,
+ float* wi, lapack_int* m, float* s, float* sep );
+lapack_int LAPACKE_dtrsen( int matrix_order, char job, char compq,
+ const lapack_logical* select, lapack_int n,
+ double* t, lapack_int ldt, double* q, lapack_int ldq,
+ double* wr, double* wi, lapack_int* m, double* s,
+ double* sep );
+lapack_int LAPACKE_ctrsen( int matrix_order, char job, char compq,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* w, lapack_int* m, float* s,
+ float* sep );
+lapack_int LAPACKE_ztrsen( int matrix_order, char job, char compq,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* w, lapack_int* m, double* s,
+ double* sep );
+
+lapack_int LAPACKE_strsna( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const float* t, lapack_int ldt, const float* vl,
+ lapack_int ldvl, const float* vr, lapack_int ldvr,
+ float* s, float* sep, lapack_int mm, lapack_int* m );
+lapack_int LAPACKE_dtrsna( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const double* t, lapack_int ldt, const double* vl,
+ lapack_int ldvl, const double* vr, lapack_int ldvr,
+ double* s, double* sep, lapack_int mm,
+ lapack_int* m );
+lapack_int LAPACKE_ctrsna( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_float* t, lapack_int ldt,
+ const lapack_complex_float* vl, lapack_int ldvl,
+ const lapack_complex_float* vr, lapack_int ldvr,
+ float* s, float* sep, lapack_int mm, lapack_int* m );
+lapack_int LAPACKE_ztrsna( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_double* t, lapack_int ldt,
+ const lapack_complex_double* vl, lapack_int ldvl,
+ const lapack_complex_double* vr, lapack_int ldvr,
+ double* s, double* sep, lapack_int mm,
+ lapack_int* m );
+
+lapack_int LAPACKE_strsyl( int matrix_order, char trana, char tranb,
+ lapack_int isgn, lapack_int m, lapack_int n,
+ const float* a, lapack_int lda, const float* b,
+ lapack_int ldb, float* c, lapack_int ldc,
+ float* scale );
+lapack_int LAPACKE_dtrsyl( int matrix_order, char trana, char tranb,
+ lapack_int isgn, lapack_int m, lapack_int n,
+ const double* a, lapack_int lda, const double* b,
+ lapack_int ldb, double* c, lapack_int ldc,
+ double* scale );
+lapack_int LAPACKE_ctrsyl( int matrix_order, char trana, char tranb,
+ lapack_int isgn, lapack_int m, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* c, lapack_int ldc,
+ float* scale );
+lapack_int LAPACKE_ztrsyl( int matrix_order, char trana, char tranb,
+ lapack_int isgn, lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* c, lapack_int ldc,
+ double* scale );
+
+lapack_int LAPACKE_strtri( int matrix_order, char uplo, char diag, lapack_int n,
+ float* a, lapack_int lda );
+lapack_int LAPACKE_dtrtri( int matrix_order, char uplo, char diag, lapack_int n,
+ double* a, lapack_int lda );
+lapack_int LAPACKE_ctrtri( int matrix_order, char uplo, char diag, lapack_int n,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_ztrtri( int matrix_order, char uplo, char diag, lapack_int n,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_strtrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs, const float* a,
+ lapack_int lda, float* b, lapack_int ldb );
+lapack_int LAPACKE_dtrtrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs, const double* a,
+ lapack_int lda, double* b, lapack_int ldb );
+lapack_int LAPACKE_ctrtrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_ztrtrs( int matrix_order, char uplo, char trans, char diag,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_strttf( int matrix_order, char transr, char uplo,
+ lapack_int n, const float* a, lapack_int lda,
+ float* arf );
+lapack_int LAPACKE_dtrttf( int matrix_order, char transr, char uplo,
+ lapack_int n, const double* a, lapack_int lda,
+ double* arf );
+lapack_int LAPACKE_ctrttf( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* arf );
+lapack_int LAPACKE_ztrttf( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* arf );
+
+lapack_int LAPACKE_strttp( int matrix_order, char uplo, lapack_int n,
+ const float* a, lapack_int lda, float* ap );
+lapack_int LAPACKE_dtrttp( int matrix_order, char uplo, lapack_int n,
+ const double* a, lapack_int lda, double* ap );
+lapack_int LAPACKE_ctrttp( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* ap );
+lapack_int LAPACKE_ztrttp( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* ap );
+
+lapack_int LAPACKE_stzrzf( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau );
+lapack_int LAPACKE_dtzrzf( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau );
+lapack_int LAPACKE_ctzrzf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_ztzrzf( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_cungbr( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int k, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau );
+lapack_int LAPACKE_zungbr( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int k, lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* tau );
+
+lapack_int LAPACKE_cunghr( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau );
+lapack_int LAPACKE_zunghr( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* tau );
+
+lapack_int LAPACKE_cunglq( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau );
+lapack_int LAPACKE_zunglq( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* tau );
+
+lapack_int LAPACKE_cungql( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau );
+lapack_int LAPACKE_zungql( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* tau );
+
+lapack_int LAPACKE_cungqr( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau );
+lapack_int LAPACKE_zungqr( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* tau );
+
+lapack_int LAPACKE_cungrq( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau );
+lapack_int LAPACKE_zungrq( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* tau );
+
+lapack_int LAPACKE_cungtr( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau );
+lapack_int LAPACKE_zungtr( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau );
+
+lapack_int LAPACKE_cunmbr( int matrix_order, char vect, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc );
+lapack_int LAPACKE_zunmbr( int matrix_order, char vect, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc );
+
+lapack_int LAPACKE_cunmhr( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int ilo,
+ lapack_int ihi, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc );
+lapack_int LAPACKE_zunmhr( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int ilo,
+ lapack_int ihi, const lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc );
+
+lapack_int LAPACKE_cunmlq( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc );
+lapack_int LAPACKE_zunmlq( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc );
+
+lapack_int LAPACKE_cunmql( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc );
+lapack_int LAPACKE_zunmql( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc );
+
+lapack_int LAPACKE_cunmqr( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc );
+lapack_int LAPACKE_zunmqr( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc );
+
+lapack_int LAPACKE_cunmrq( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc );
+lapack_int LAPACKE_zunmrq( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc );
+
+lapack_int LAPACKE_cunmrz( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc );
+lapack_int LAPACKE_zunmrz( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, const lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc );
+
+lapack_int LAPACKE_cunmtr( int matrix_order, char side, char uplo, char trans,
+ lapack_int m, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc );
+lapack_int LAPACKE_zunmtr( int matrix_order, char side, char uplo, char trans,
+ lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc );
+
+lapack_int LAPACKE_cupgtr( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap,
+ const lapack_complex_float* tau,
+ lapack_complex_float* q, lapack_int ldq );
+lapack_int LAPACKE_zupgtr( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* tau,
+ lapack_complex_double* q, lapack_int ldq );
+
+lapack_int LAPACKE_cupmtr( int matrix_order, char side, char uplo, char trans,
+ lapack_int m, lapack_int n,
+ const lapack_complex_float* ap,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc );
+lapack_int LAPACKE_zupmtr( int matrix_order, char side, char uplo, char trans,
+ lapack_int m, lapack_int n,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc );
+
+lapack_int LAPACKE_sbdsdc_work( int matrix_order, char uplo, char compq,
+ lapack_int n, float* d, float* e, float* u,
+ lapack_int ldu, float* vt, lapack_int ldvt,
+ float* q, lapack_int* iq, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dbdsdc_work( int matrix_order, char uplo, char compq,
+ lapack_int n, double* d, double* e, double* u,
+ lapack_int ldu, double* vt, lapack_int ldvt,
+ double* q, lapack_int* iq, double* work,
+ lapack_int* iwork );
+
+lapack_int LAPACKE_sbdsqr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int ncvt, lapack_int nru, lapack_int ncc,
+ float* d, float* e, float* vt, lapack_int ldvt,
+ float* u, lapack_int ldu, float* c,
+ lapack_int ldc, float* work );
+lapack_int LAPACKE_dbdsqr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int ncvt, lapack_int nru, lapack_int ncc,
+ double* d, double* e, double* vt,
+ lapack_int ldvt, double* u, lapack_int ldu,
+ double* c, lapack_int ldc, double* work );
+lapack_int LAPACKE_cbdsqr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int ncvt, lapack_int nru, lapack_int ncc,
+ float* d, float* e, lapack_complex_float* vt,
+ lapack_int ldvt, lapack_complex_float* u,
+ lapack_int ldu, lapack_complex_float* c,
+ lapack_int ldc, float* work );
+lapack_int LAPACKE_zbdsqr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int ncvt, lapack_int nru, lapack_int ncc,
+ double* d, double* e, lapack_complex_double* vt,
+ lapack_int ldvt, lapack_complex_double* u,
+ lapack_int ldu, lapack_complex_double* c,
+ lapack_int ldc, double* work );
+
+lapack_int LAPACKE_sdisna_work( char job, lapack_int m, lapack_int n,
+ const float* d, float* sep );
+lapack_int LAPACKE_ddisna_work( char job, lapack_int m, lapack_int n,
+ const double* d, double* sep );
+
+lapack_int LAPACKE_sgbbrd_work( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int ncc, lapack_int kl,
+ lapack_int ku, float* ab, lapack_int ldab,
+ float* d, float* e, float* q, lapack_int ldq,
+ float* pt, lapack_int ldpt, float* c,
+ lapack_int ldc, float* work );
+lapack_int LAPACKE_dgbbrd_work( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int ncc, lapack_int kl,
+ lapack_int ku, double* ab, lapack_int ldab,
+ double* d, double* e, double* q, lapack_int ldq,
+ double* pt, lapack_int ldpt, double* c,
+ lapack_int ldc, double* work );
+lapack_int LAPACKE_cgbbrd_work( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int ncc, lapack_int kl,
+ lapack_int ku, lapack_complex_float* ab,
+ lapack_int ldab, float* d, float* e,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* pt, lapack_int ldpt,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zgbbrd_work( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int ncc, lapack_int kl,
+ lapack_int ku, lapack_complex_double* ab,
+ lapack_int ldab, double* d, double* e,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* pt, lapack_int ldpt,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sgbcon_work( int matrix_order, char norm, lapack_int n,
+ lapack_int kl, lapack_int ku, const float* ab,
+ lapack_int ldab, const lapack_int* ipiv,
+ float anorm, float* rcond, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgbcon_work( int matrix_order, char norm, lapack_int n,
+ lapack_int kl, lapack_int ku, const double* ab,
+ lapack_int ldab, const lapack_int* ipiv,
+ double anorm, double* rcond, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cgbcon_work( int matrix_order, char norm, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_float* ab, lapack_int ldab,
+ const lapack_int* ipiv, float anorm,
+ float* rcond, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zgbcon_work( int matrix_order, char norm, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_double* ab,
+ lapack_int ldab, const lapack_int* ipiv,
+ double anorm, double* rcond,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sgbequ_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const float* ab,
+ lapack_int ldab, float* r, float* c,
+ float* rowcnd, float* colcnd, float* amax );
+lapack_int LAPACKE_dgbequ_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const double* ab,
+ lapack_int ldab, double* r, double* c,
+ double* rowcnd, double* colcnd, double* amax );
+lapack_int LAPACKE_cgbequ_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_float* ab, lapack_int ldab,
+ float* r, float* c, float* rowcnd,
+ float* colcnd, float* amax );
+lapack_int LAPACKE_zgbequ_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_double* ab,
+ lapack_int ldab, double* r, double* c,
+ double* rowcnd, double* colcnd, double* amax );
+
+lapack_int LAPACKE_sgbequb_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const float* ab,
+ lapack_int ldab, float* r, float* c,
+ float* rowcnd, float* colcnd, float* amax );
+lapack_int LAPACKE_dgbequb_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const double* ab,
+ lapack_int ldab, double* r, double* c,
+ double* rowcnd, double* colcnd, double* amax );
+lapack_int LAPACKE_cgbequb_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_float* ab,
+ lapack_int ldab, float* r, float* c,
+ float* rowcnd, float* colcnd, float* amax );
+lapack_int LAPACKE_zgbequb_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ const lapack_complex_double* ab,
+ lapack_int ldab, double* r, double* c,
+ double* rowcnd, double* colcnd, double* amax );
+
+lapack_int LAPACKE_sgbrfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const float* ab, lapack_int ldab,
+ const float* afb, lapack_int ldafb,
+ const lapack_int* ipiv, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* ferr, float* berr, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgbrfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const double* ab, lapack_int ldab,
+ const double* afb, lapack_int ldafb,
+ const lapack_int* ipiv, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* ferr, double* berr, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cgbrfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const lapack_complex_float* ab, lapack_int ldab,
+ const lapack_complex_float* afb,
+ lapack_int ldafb, const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zgbrfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const lapack_complex_double* ab,
+ lapack_int ldab,
+ const lapack_complex_double* afb,
+ lapack_int ldafb, const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sgbrfsx_work( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, const float* ab,
+ lapack_int ldab, const float* afb,
+ lapack_int ldafb, const lapack_int* ipiv,
+ const float* r, const float* c, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgbrfsx_work( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, const double* ab,
+ lapack_int ldab, const double* afb,
+ lapack_int ldafb, const lapack_int* ipiv,
+ const double* r, const double* c,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cgbrfsx_work( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs,
+ const lapack_complex_float* ab,
+ lapack_int ldab,
+ const lapack_complex_float* afb,
+ lapack_int ldafb, const lapack_int* ipiv,
+ const float* r, const float* c,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zgbrfsx_work( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs,
+ const lapack_complex_double* ab,
+ lapack_int ldab,
+ const lapack_complex_double* afb,
+ lapack_int ldafb, const lapack_int* ipiv,
+ const double* r, const double* c,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_sgbsv_work( int matrix_order, lapack_int n, lapack_int kl,
+ lapack_int ku, lapack_int nrhs, float* ab,
+ lapack_int ldab, lapack_int* ipiv, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dgbsv_work( int matrix_order, lapack_int n, lapack_int kl,
+ lapack_int ku, lapack_int nrhs, double* ab,
+ lapack_int ldab, lapack_int* ipiv, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cgbsv_work( int matrix_order, lapack_int n, lapack_int kl,
+ lapack_int ku, lapack_int nrhs,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zgbsv_work( int matrix_order, lapack_int n, lapack_int kl,
+ lapack_int ku, lapack_int nrhs,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_sgbsvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, float* ab, lapack_int ldab,
+ float* afb, lapack_int ldafb, lapack_int* ipiv,
+ char* equed, float* r, float* c, float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ float* work, lapack_int* iwork );
+lapack_int LAPACKE_dgbsvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, double* ab, lapack_int ldab,
+ double* afb, lapack_int ldafb, lapack_int* ipiv,
+ char* equed, double* r, double* c, double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_cgbsvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, lapack_complex_float* ab,
+ lapack_int ldab, lapack_complex_float* afb,
+ lapack_int ldafb, lapack_int* ipiv, char* equed,
+ float* r, float* c, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zgbsvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, lapack_complex_double* ab,
+ lapack_int ldab, lapack_complex_double* afb,
+ lapack_int ldafb, lapack_int* ipiv, char* equed,
+ double* r, double* c, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* rcond, double* ferr,
+ double* berr, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_sgbsvxx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, float* ab, lapack_int ldab,
+ float* afb, lapack_int ldafb, lapack_int* ipiv,
+ char* equed, float* r, float* c, float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgbsvxx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, double* ab, lapack_int ldab,
+ double* afb, lapack_int ldafb,
+ lapack_int* ipiv, char* equed, double* r,
+ double* c, double* b, lapack_int ldb,
+ double* x, lapack_int ldx, double* rcond,
+ double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cgbsvxx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, lapack_complex_float* ab,
+ lapack_int ldab, lapack_complex_float* afb,
+ lapack_int ldafb, lapack_int* ipiv,
+ char* equed, float* r, float* c,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zgbsvxx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int kl, lapack_int ku,
+ lapack_int nrhs, lapack_complex_double* ab,
+ lapack_int ldab, lapack_complex_double* afb,
+ lapack_int ldafb, lapack_int* ipiv,
+ char* equed, double* r, double* c,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_sgbtrf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, float* ab,
+ lapack_int ldab, lapack_int* ipiv );
+lapack_int LAPACKE_dgbtrf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, double* ab,
+ lapack_int ldab, lapack_int* ipiv );
+lapack_int LAPACKE_cgbtrf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_int* ipiv );
+lapack_int LAPACKE_zgbtrf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_int* ipiv );
+
+lapack_int LAPACKE_sgbtrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const float* ab, lapack_int ldab,
+ const lapack_int* ipiv, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dgbtrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const double* ab, lapack_int ldab,
+ const lapack_int* ipiv, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cgbtrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const lapack_complex_float* ab, lapack_int ldab,
+ const lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zgbtrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int kl, lapack_int ku, lapack_int nrhs,
+ const lapack_complex_double* ab,
+ lapack_int ldab, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_sgebak_work( int matrix_order, char job, char side,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ const float* scale, lapack_int m, float* v,
+ lapack_int ldv );
+lapack_int LAPACKE_dgebak_work( int matrix_order, char job, char side,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ const double* scale, lapack_int m, double* v,
+ lapack_int ldv );
+lapack_int LAPACKE_cgebak_work( int matrix_order, char job, char side,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ const float* scale, lapack_int m,
+ lapack_complex_float* v, lapack_int ldv );
+lapack_int LAPACKE_zgebak_work( int matrix_order, char job, char side,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ const double* scale, lapack_int m,
+ lapack_complex_double* v, lapack_int ldv );
+
+lapack_int LAPACKE_sgebal_work( int matrix_order, char job, lapack_int n,
+ float* a, lapack_int lda, lapack_int* ilo,
+ lapack_int* ihi, float* scale );
+lapack_int LAPACKE_dgebal_work( int matrix_order, char job, lapack_int n,
+ double* a, lapack_int lda, lapack_int* ilo,
+ lapack_int* ihi, double* scale );
+lapack_int LAPACKE_cgebal_work( int matrix_order, char job, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ilo, lapack_int* ihi,
+ float* scale );
+lapack_int LAPACKE_zgebal_work( int matrix_order, char job, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ilo, lapack_int* ihi,
+ double* scale );
+
+lapack_int LAPACKE_sgebrd_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* d, float* e,
+ float* tauq, float* taup, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dgebrd_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* d, double* e,
+ double* tauq, double* taup, double* work,
+ lapack_int lwork );
+lapack_int LAPACKE_cgebrd_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ float* d, float* e, lapack_complex_float* tauq,
+ lapack_complex_float* taup,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zgebrd_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ double* d, double* e,
+ lapack_complex_double* tauq,
+ lapack_complex_double* taup,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sgecon_work( int matrix_order, char norm, lapack_int n,
+ const float* a, lapack_int lda, float anorm,
+ float* rcond, float* work, lapack_int* iwork );
+lapack_int LAPACKE_dgecon_work( int matrix_order, char norm, lapack_int n,
+ const double* a, lapack_int lda, double anorm,
+ double* rcond, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cgecon_work( int matrix_order, char norm, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float anorm, float* rcond,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zgecon_work( int matrix_order, char norm, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double anorm, double* rcond,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sgeequ_work( int matrix_order, lapack_int m, lapack_int n,
+ const float* a, lapack_int lda, float* r,
+ float* c, float* rowcnd, float* colcnd,
+ float* amax );
+lapack_int LAPACKE_dgeequ_work( int matrix_order, lapack_int m, lapack_int n,
+ const double* a, lapack_int lda, double* r,
+ double* c, double* rowcnd, double* colcnd,
+ double* amax );
+lapack_int LAPACKE_cgeequ_work( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* r, float* c, float* rowcnd,
+ float* colcnd, float* amax );
+lapack_int LAPACKE_zgeequ_work( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* r, double* c, double* rowcnd,
+ double* colcnd, double* amax );
+
+lapack_int LAPACKE_sgeequb_work( int matrix_order, lapack_int m, lapack_int n,
+ const float* a, lapack_int lda, float* r,
+ float* c, float* rowcnd, float* colcnd,
+ float* amax );
+lapack_int LAPACKE_dgeequb_work( int matrix_order, lapack_int m, lapack_int n,
+ const double* a, lapack_int lda, double* r,
+ double* c, double* rowcnd, double* colcnd,
+ double* amax );
+lapack_int LAPACKE_cgeequb_work( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* r, float* c, float* rowcnd,
+ float* colcnd, float* amax );
+lapack_int LAPACKE_zgeequb_work( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* r, double* c, double* rowcnd,
+ double* colcnd, double* amax );
+
+lapack_int LAPACKE_sgees_work( int matrix_order, char jobvs, char sort,
+ LAPACK_S_SELECT2 select, lapack_int n, float* a,
+ lapack_int lda, lapack_int* sdim, float* wr,
+ float* wi, float* vs, lapack_int ldvs,
+ float* work, lapack_int lwork,
+ lapack_logical* bwork );
+lapack_int LAPACKE_dgees_work( int matrix_order, char jobvs, char sort,
+ LAPACK_D_SELECT2 select, lapack_int n, double* a,
+ lapack_int lda, lapack_int* sdim, double* wr,
+ double* wi, double* vs, lapack_int ldvs,
+ double* work, lapack_int lwork,
+ lapack_logical* bwork );
+lapack_int LAPACKE_cgees_work( int matrix_order, char jobvs, char sort,
+ LAPACK_C_SELECT1 select, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* sdim, lapack_complex_float* w,
+ lapack_complex_float* vs, lapack_int ldvs,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork, lapack_logical* bwork );
+lapack_int LAPACKE_zgees_work( int matrix_order, char jobvs, char sort,
+ LAPACK_Z_SELECT1 select, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* sdim, lapack_complex_double* w,
+ lapack_complex_double* vs, lapack_int ldvs,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork, lapack_logical* bwork );
+
+lapack_int LAPACKE_sgeesx_work( int matrix_order, char jobvs, char sort,
+ LAPACK_S_SELECT2 select, char sense,
+ lapack_int n, float* a, lapack_int lda,
+ lapack_int* sdim, float* wr, float* wi,
+ float* vs, lapack_int ldvs, float* rconde,
+ float* rcondv, float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork,
+ lapack_logical* bwork );
+lapack_int LAPACKE_dgeesx_work( int matrix_order, char jobvs, char sort,
+ LAPACK_D_SELECT2 select, char sense,
+ lapack_int n, double* a, lapack_int lda,
+ lapack_int* sdim, double* wr, double* wi,
+ double* vs, lapack_int ldvs, double* rconde,
+ double* rcondv, double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork,
+ lapack_logical* bwork );
+lapack_int LAPACKE_cgeesx_work( int matrix_order, char jobvs, char sort,
+ LAPACK_C_SELECT1 select, char sense,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, lapack_int* sdim,
+ lapack_complex_float* w,
+ lapack_complex_float* vs, lapack_int ldvs,
+ float* rconde, float* rcondv,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork, lapack_logical* bwork );
+lapack_int LAPACKE_zgeesx_work( int matrix_order, char jobvs, char sort,
+ LAPACK_Z_SELECT1 select, char sense,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_int* sdim,
+ lapack_complex_double* w,
+ lapack_complex_double* vs, lapack_int ldvs,
+ double* rconde, double* rcondv,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork, lapack_logical* bwork );
+
+lapack_int LAPACKE_sgeev_work( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, float* a, lapack_int lda,
+ float* wr, float* wi, float* vl, lapack_int ldvl,
+ float* vr, lapack_int ldvr, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dgeev_work( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, double* a, lapack_int lda,
+ double* wr, double* wi, double* vl,
+ lapack_int ldvl, double* vr, lapack_int ldvr,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_cgeev_work( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* w,
+ lapack_complex_float* vl, lapack_int ldvl,
+ lapack_complex_float* vr, lapack_int ldvr,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork );
+lapack_int LAPACKE_zgeev_work( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* w,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork );
+
+lapack_int LAPACKE_sgeevx_work( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n, float* a,
+ lapack_int lda, float* wr, float* wi, float* vl,
+ lapack_int ldvl, float* vr, lapack_int ldvr,
+ lapack_int* ilo, lapack_int* ihi, float* scale,
+ float* abnrm, float* rconde, float* rcondv,
+ float* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgeevx_work( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n, double* a,
+ lapack_int lda, double* wr, double* wi,
+ double* vl, lapack_int ldvl, double* vr,
+ lapack_int ldvr, lapack_int* ilo,
+ lapack_int* ihi, double* scale, double* abnrm,
+ double* rconde, double* rcondv, double* work,
+ lapack_int lwork, lapack_int* iwork );
+lapack_int LAPACKE_cgeevx_work( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* w,
+ lapack_complex_float* vl, lapack_int ldvl,
+ lapack_complex_float* vr, lapack_int ldvr,
+ lapack_int* ilo, lapack_int* ihi, float* scale,
+ float* abnrm, float* rconde, float* rcondv,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork );
+lapack_int LAPACKE_zgeevx_work( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* w,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr,
+ lapack_int* ilo, lapack_int* ihi, double* scale,
+ double* abnrm, double* rconde, double* rcondv,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork );
+
+lapack_int LAPACKE_sgehrd_work( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, float* a, lapack_int lda,
+ float* tau, float* work, lapack_int lwork );
+lapack_int LAPACKE_dgehrd_work( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, double* a, lapack_int lda,
+ double* tau, double* work, lapack_int lwork );
+lapack_int LAPACKE_cgehrd_work( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zgehrd_work( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sgejsv_work( int matrix_order, char joba, char jobu,
+ char jobv, char jobr, char jobt, char jobp,
+ lapack_int m, lapack_int n, float* a,
+ lapack_int lda, float* sva, float* u,
+ lapack_int ldu, float* v, lapack_int ldv,
+ float* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgejsv_work( int matrix_order, char joba, char jobu,
+ char jobv, char jobr, char jobt, char jobp,
+ lapack_int m, lapack_int n, double* a,
+ lapack_int lda, double* sva, double* u,
+ lapack_int ldu, double* v, lapack_int ldv,
+ double* work, lapack_int lwork,
+ lapack_int* iwork );
+
+lapack_int LAPACKE_sgelq2_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau,
+ float* work );
+lapack_int LAPACKE_dgelq2_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau,
+ double* work );
+lapack_int LAPACKE_cgelq2_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zgelq2_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_sgelqf_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dgelqf_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_cgelqf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zgelqf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sgels_work( int matrix_order, char trans, lapack_int m,
+ lapack_int n, lapack_int nrhs, float* a,
+ lapack_int lda, float* b, lapack_int ldb,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dgels_work( int matrix_order, char trans, lapack_int m,
+ lapack_int n, lapack_int nrhs, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_cgels_work( int matrix_order, char trans, lapack_int m,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zgels_work( int matrix_order, char trans, lapack_int m,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sgelsd_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, float* a, lapack_int lda,
+ float* b, lapack_int ldb, float* s, float rcond,
+ lapack_int* rank, float* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgelsd_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* s,
+ double rcond, lapack_int* rank, double* work,
+ lapack_int lwork, lapack_int* iwork );
+lapack_int LAPACKE_cgelsd_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, float* s, float rcond,
+ lapack_int* rank, lapack_complex_float* work,
+ lapack_int lwork, float* rwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_zgelsd_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, double* s, double rcond,
+ lapack_int* rank, lapack_complex_double* work,
+ lapack_int lwork, double* rwork,
+ lapack_int* iwork );
+
+lapack_int LAPACKE_sgelss_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, float* a, lapack_int lda,
+ float* b, lapack_int ldb, float* s, float rcond,
+ lapack_int* rank, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dgelss_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* s,
+ double rcond, lapack_int* rank, double* work,
+ lapack_int lwork );
+lapack_int LAPACKE_cgelss_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, float* s, float rcond,
+ lapack_int* rank, lapack_complex_float* work,
+ lapack_int lwork, float* rwork );
+lapack_int LAPACKE_zgelss_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, double* s, double rcond,
+ lapack_int* rank, lapack_complex_double* work,
+ lapack_int lwork, double* rwork );
+
+lapack_int LAPACKE_sgelsy_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, float* a, lapack_int lda,
+ float* b, lapack_int ldb, lapack_int* jpvt,
+ float rcond, lapack_int* rank, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dgelsy_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ double* b, lapack_int ldb, lapack_int* jpvt,
+ double rcond, lapack_int* rank, double* work,
+ lapack_int lwork );
+lapack_int LAPACKE_cgelsy_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, lapack_int* jpvt, float rcond,
+ lapack_int* rank, lapack_complex_float* work,
+ lapack_int lwork, float* rwork );
+lapack_int LAPACKE_zgelsy_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_int* jpvt, double rcond,
+ lapack_int* rank, lapack_complex_double* work,
+ lapack_int lwork, double* rwork );
+
+lapack_int LAPACKE_sgeqlf_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dgeqlf_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_cgeqlf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zgeqlf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sgeqp3_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, lapack_int* jpvt,
+ float* tau, float* work, lapack_int lwork );
+lapack_int LAPACKE_dgeqp3_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, lapack_int* jpvt,
+ double* tau, double* work, lapack_int lwork );
+lapack_int LAPACKE_cgeqp3_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* jpvt, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork );
+lapack_int LAPACKE_zgeqp3_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* jpvt, lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork );
+
+lapack_int LAPACKE_sgeqpf_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, lapack_int* jpvt,
+ float* tau, float* work );
+lapack_int LAPACKE_dgeqpf_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, lapack_int* jpvt,
+ double* tau, double* work );
+lapack_int LAPACKE_cgeqpf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* jpvt, lapack_complex_float* tau,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zgeqpf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* jpvt, lapack_complex_double* tau,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sgeqr2_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau,
+ float* work );
+lapack_int LAPACKE_dgeqr2_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau,
+ double* work );
+lapack_int LAPACKE_cgeqr2_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zgeqr2_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_sgeqrf_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dgeqrf_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_cgeqrf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zgeqrf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sgeqrfp_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dgeqrfp_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_cgeqrfp_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zgeqrfp_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau,
+ lapack_complex_double* work,
+ lapack_int lwork );
+
+lapack_int LAPACKE_sgerfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ const float* af, lapack_int ldaf,
+ const lapack_int* ipiv, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* ferr, float* berr, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgerfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const double* a,
+ lapack_int lda, const double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* ferr, double* berr,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_cgerfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zgerfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sgerfsx_work( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int nrhs, const float* a,
+ lapack_int lda, const float* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const float* r, const float* c, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgerfsx_work( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int nrhs, const double* a,
+ lapack_int lda, const double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const double* r, const double* c,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cgerfsx_work( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const float* r, const float* c,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zgerfsx_work( int matrix_order, char trans, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const double* r, const double* c,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_sgerqf_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dgerqf_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_cgerqf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zgerqf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sgesdd_work( int matrix_order, char jobz, lapack_int m,
+ lapack_int n, float* a, lapack_int lda,
+ float* s, float* u, lapack_int ldu, float* vt,
+ lapack_int ldvt, float* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgesdd_work( int matrix_order, char jobz, lapack_int m,
+ lapack_int n, double* a, lapack_int lda,
+ double* s, double* u, lapack_int ldu,
+ double* vt, lapack_int ldvt, double* work,
+ lapack_int lwork, lapack_int* iwork );
+lapack_int LAPACKE_cgesdd_work( int matrix_order, char jobz, lapack_int m,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, float* s,
+ lapack_complex_float* u, lapack_int ldu,
+ lapack_complex_float* vt, lapack_int ldvt,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork, lapack_int* iwork );
+lapack_int LAPACKE_zgesdd_work( int matrix_order, char jobz, lapack_int m,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, double* s,
+ lapack_complex_double* u, lapack_int ldu,
+ lapack_complex_double* vt, lapack_int ldvt,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork, lapack_int* iwork );
+
+lapack_int LAPACKE_sgesv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ float* a, lapack_int lda, lapack_int* ipiv,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dgesv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ double* a, lapack_int lda, lapack_int* ipiv,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_cgesv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zgesv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dsgesv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ double* a, lapack_int lda, lapack_int* ipiv,
+ double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* work, float* swork,
+ lapack_int* iter );
+lapack_int LAPACKE_zcgesv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, lapack_complex_double* work,
+ lapack_complex_float* swork, double* rwork,
+ lapack_int* iter );
+
+lapack_int LAPACKE_sgesvd_work( int matrix_order, char jobu, char jobvt,
+ lapack_int m, lapack_int n, float* a,
+ lapack_int lda, float* s, float* u,
+ lapack_int ldu, float* vt, lapack_int ldvt,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dgesvd_work( int matrix_order, char jobu, char jobvt,
+ lapack_int m, lapack_int n, double* a,
+ lapack_int lda, double* s, double* u,
+ lapack_int ldu, double* vt, lapack_int ldvt,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_cgesvd_work( int matrix_order, char jobu, char jobvt,
+ lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ float* s, lapack_complex_float* u,
+ lapack_int ldu, lapack_complex_float* vt,
+ lapack_int ldvt, lapack_complex_float* work,
+ lapack_int lwork, float* rwork );
+lapack_int LAPACKE_zgesvd_work( int matrix_order, char jobu, char jobvt,
+ lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ double* s, lapack_complex_double* u,
+ lapack_int ldu, lapack_complex_double* vt,
+ lapack_int ldvt, lapack_complex_double* work,
+ lapack_int lwork, double* rwork );
+
+lapack_int LAPACKE_sgesvj_work( int matrix_order, char joba, char jobu,
+ char jobv, lapack_int m, lapack_int n, float* a,
+ lapack_int lda, float* sva, lapack_int mv,
+ float* v, lapack_int ldv, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dgesvj_work( int matrix_order, char joba, char jobu,
+ char jobv, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* sva,
+ lapack_int mv, double* v, lapack_int ldv,
+ double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sgesvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, float* a,
+ lapack_int lda, float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* r,
+ float* c, float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr, float* work, lapack_int* iwork );
+lapack_int LAPACKE_dgesvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, double* a,
+ lapack_int lda, double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* r,
+ double* c, double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* rcond, double* ferr,
+ double* berr, double* work, lapack_int* iwork );
+lapack_int LAPACKE_cgesvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* r,
+ float* c, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zgesvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* r,
+ double* c, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* rcond, double* ferr,
+ double* berr, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_sgesvxx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, float* a,
+ lapack_int lda, float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* r,
+ float* c, float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* rcond, float* rpvgrw,
+ float* berr, lapack_int n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int nparams, float* params, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgesvxx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, double* a,
+ lapack_int lda, double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* r,
+ double* c, double* b, lapack_int ldb,
+ double* x, lapack_int ldx, double* rcond,
+ double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cgesvxx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* r,
+ float* c, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* rpvgrw,
+ float* berr, lapack_int n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int nparams, float* params,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zgesvxx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* r,
+ double* c, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* rcond, double* rpvgrw,
+ double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sgetf2_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, lapack_int* ipiv );
+lapack_int LAPACKE_dgetf2_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, lapack_int* ipiv );
+lapack_int LAPACKE_cgetf2_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ipiv );
+lapack_int LAPACKE_zgetf2_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv );
+
+lapack_int LAPACKE_sgetrf_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, lapack_int* ipiv );
+lapack_int LAPACKE_dgetrf_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, lapack_int* ipiv );
+lapack_int LAPACKE_cgetrf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ipiv );
+lapack_int LAPACKE_zgetrf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv );
+
+lapack_int LAPACKE_sgetri_work( int matrix_order, lapack_int n, float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dgetri_work( int matrix_order, lapack_int n, double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_cgetri_work( int matrix_order, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zgetri_work( int matrix_order, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sgetrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ const lapack_int* ipiv, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dgetrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_cgetrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zgetrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_sggbak_work( int matrix_order, char job, char side,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ const float* lscale, const float* rscale,
+ lapack_int m, float* v, lapack_int ldv );
+lapack_int LAPACKE_dggbak_work( int matrix_order, char job, char side,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ const double* lscale, const double* rscale,
+ lapack_int m, double* v, lapack_int ldv );
+lapack_int LAPACKE_cggbak_work( int matrix_order, char job, char side,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ const float* lscale, const float* rscale,
+ lapack_int m, lapack_complex_float* v,
+ lapack_int ldv );
+lapack_int LAPACKE_zggbak_work( int matrix_order, char job, char side,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ const double* lscale, const double* rscale,
+ lapack_int m, lapack_complex_double* v,
+ lapack_int ldv );
+
+lapack_int LAPACKE_sggbal_work( int matrix_order, char job, lapack_int n,
+ float* a, lapack_int lda, float* b,
+ lapack_int ldb, lapack_int* ilo,
+ lapack_int* ihi, float* lscale, float* rscale,
+ float* work );
+lapack_int LAPACKE_dggbal_work( int matrix_order, char job, lapack_int n,
+ double* a, lapack_int lda, double* b,
+ lapack_int ldb, lapack_int* ilo,
+ lapack_int* ihi, double* lscale, double* rscale,
+ double* work );
+lapack_int LAPACKE_cggbal_work( int matrix_order, char job, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_int* ilo, lapack_int* ihi, float* lscale,
+ float* rscale, float* work );
+lapack_int LAPACKE_zggbal_work( int matrix_order, char job, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_int* ilo, lapack_int* ihi,
+ double* lscale, double* rscale, double* work );
+
+lapack_int LAPACKE_sgges_work( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_S_SELECT3 selctg, lapack_int n,
+ float* a, lapack_int lda, float* b,
+ lapack_int ldb, lapack_int* sdim, float* alphar,
+ float* alphai, float* beta, float* vsl,
+ lapack_int ldvsl, float* vsr, lapack_int ldvsr,
+ float* work, lapack_int lwork,
+ lapack_logical* bwork );
+lapack_int LAPACKE_dgges_work( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_D_SELECT3 selctg, lapack_int n,
+ double* a, lapack_int lda, double* b,
+ lapack_int ldb, lapack_int* sdim, double* alphar,
+ double* alphai, double* beta, double* vsl,
+ lapack_int ldvsl, double* vsr, lapack_int ldvsr,
+ double* work, lapack_int lwork,
+ lapack_logical* bwork );
+lapack_int LAPACKE_cgges_work( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_C_SELECT2 selctg, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_int* sdim, lapack_complex_float* alpha,
+ lapack_complex_float* beta,
+ lapack_complex_float* vsl, lapack_int ldvsl,
+ lapack_complex_float* vsr, lapack_int ldvsr,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork, lapack_logical* bwork );
+lapack_int LAPACKE_zgges_work( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_Z_SELECT2 selctg, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_int* sdim, lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* vsl, lapack_int ldvsl,
+ lapack_complex_double* vsr, lapack_int ldvsr,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork, lapack_logical* bwork );
+
+lapack_int LAPACKE_sggesx_work( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_S_SELECT3 selctg, char sense,
+ lapack_int n, float* a, lapack_int lda,
+ float* b, lapack_int ldb, lapack_int* sdim,
+ float* alphar, float* alphai, float* beta,
+ float* vsl, lapack_int ldvsl, float* vsr,
+ lapack_int ldvsr, float* rconde, float* rcondv,
+ float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork,
+ lapack_logical* bwork );
+lapack_int LAPACKE_dggesx_work( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_D_SELECT3 selctg, char sense,
+ lapack_int n, double* a, lapack_int lda,
+ double* b, lapack_int ldb, lapack_int* sdim,
+ double* alphar, double* alphai, double* beta,
+ double* vsl, lapack_int ldvsl, double* vsr,
+ lapack_int ldvsr, double* rconde,
+ double* rcondv, double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork,
+ lapack_logical* bwork );
+lapack_int LAPACKE_cggesx_work( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_C_SELECT2 selctg, char sense,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, lapack_int* sdim,
+ lapack_complex_float* alpha,
+ lapack_complex_float* beta,
+ lapack_complex_float* vsl, lapack_int ldvsl,
+ lapack_complex_float* vsr, lapack_int ldvsr,
+ float* rconde, float* rcondv,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork, lapack_int* iwork,
+ lapack_int liwork, lapack_logical* bwork );
+lapack_int LAPACKE_zggesx_work( int matrix_order, char jobvsl, char jobvsr,
+ char sort, LAPACK_Z_SELECT2 selctg, char sense,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_int* sdim,
+ lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* vsl, lapack_int ldvsl,
+ lapack_complex_double* vsr, lapack_int ldvsr,
+ double* rconde, double* rcondv,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork, lapack_int* iwork,
+ lapack_int liwork, lapack_logical* bwork );
+
+lapack_int LAPACKE_sggev_work( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, float* a, lapack_int lda, float* b,
+ lapack_int ldb, float* alphar, float* alphai,
+ float* beta, float* vl, lapack_int ldvl,
+ float* vr, lapack_int ldvr, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dggev_work( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* alphar,
+ double* alphai, double* beta, double* vl,
+ lapack_int ldvl, double* vr, lapack_int ldvr,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_cggev_work( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* alpha,
+ lapack_complex_float* beta,
+ lapack_complex_float* vl, lapack_int ldvl,
+ lapack_complex_float* vr, lapack_int ldvr,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork );
+lapack_int LAPACKE_zggev_work( int matrix_order, char jobvl, char jobvr,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork );
+
+lapack_int LAPACKE_sggevx_work( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb,
+ float* alphar, float* alphai, float* beta,
+ float* vl, lapack_int ldvl, float* vr,
+ lapack_int ldvr, lapack_int* ilo,
+ lapack_int* ihi, float* lscale, float* rscale,
+ float* abnrm, float* bbnrm, float* rconde,
+ float* rcondv, float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_logical* bwork );
+lapack_int LAPACKE_dggevx_work( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ double* alphar, double* alphai, double* beta,
+ double* vl, lapack_int ldvl, double* vr,
+ lapack_int ldvr, lapack_int* ilo,
+ lapack_int* ihi, double* lscale, double* rscale,
+ double* abnrm, double* bbnrm, double* rconde,
+ double* rcondv, double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_logical* bwork );
+lapack_int LAPACKE_cggevx_work( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* alpha,
+ lapack_complex_float* beta,
+ lapack_complex_float* vl, lapack_int ldvl,
+ lapack_complex_float* vr, lapack_int ldvr,
+ lapack_int* ilo, lapack_int* ihi, float* lscale,
+ float* rscale, float* abnrm, float* bbnrm,
+ float* rconde, float* rcondv,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork, lapack_int* iwork,
+ lapack_logical* bwork );
+lapack_int LAPACKE_zggevx_work( int matrix_order, char balanc, char jobvl,
+ char jobvr, char sense, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr,
+ lapack_int* ilo, lapack_int* ihi,
+ double* lscale, double* rscale, double* abnrm,
+ double* bbnrm, double* rconde, double* rcondv,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork, lapack_int* iwork,
+ lapack_logical* bwork );
+
+lapack_int LAPACKE_sggglm_work( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, float* a, lapack_int lda,
+ float* b, lapack_int ldb, float* d, float* x,
+ float* y, float* work, lapack_int lwork );
+lapack_int LAPACKE_dggglm_work( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* d, double* x,
+ double* y, double* work, lapack_int lwork );
+lapack_int LAPACKE_cggglm_work( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* d,
+ lapack_complex_float* x,
+ lapack_complex_float* y,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zggglm_work( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* d,
+ lapack_complex_double* x,
+ lapack_complex_double* y,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sgghrd_work( int matrix_order, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ float* a, lapack_int lda, float* b,
+ lapack_int ldb, float* q, lapack_int ldq,
+ float* z, lapack_int ldz );
+lapack_int LAPACKE_dgghrd_work( int matrix_order, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ double* a, lapack_int lda, double* b,
+ lapack_int ldb, double* q, lapack_int ldq,
+ double* z, lapack_int ldz );
+lapack_int LAPACKE_cgghrd_work( int matrix_order, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* z, lapack_int ldz );
+lapack_int LAPACKE_zgghrd_work( int matrix_order, char compq, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* z, lapack_int ldz );
+
+lapack_int LAPACKE_sgglse_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int p, float* a, lapack_int lda,
+ float* b, lapack_int ldb, float* c, float* d,
+ float* x, float* work, lapack_int lwork );
+lapack_int LAPACKE_dgglse_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int p, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* c, double* d,
+ double* x, double* work, lapack_int lwork );
+lapack_int LAPACKE_cgglse_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int p, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* c,
+ lapack_complex_float* d,
+ lapack_complex_float* x,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zgglse_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int p, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* c,
+ lapack_complex_double* d,
+ lapack_complex_double* x,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sggqrf_work( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, float* a, lapack_int lda,
+ float* taua, float* b, lapack_int ldb,
+ float* taub, float* work, lapack_int lwork );
+lapack_int LAPACKE_dggqrf_work( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, double* a, lapack_int lda,
+ double* taua, double* b, lapack_int ldb,
+ double* taub, double* work, lapack_int lwork );
+lapack_int LAPACKE_cggqrf_work( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* taua,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* taub,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zggqrf_work( int matrix_order, lapack_int n, lapack_int m,
+ lapack_int p, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* taua,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* taub,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sggrqf_work( int matrix_order, lapack_int m, lapack_int p,
+ lapack_int n, float* a, lapack_int lda,
+ float* taua, float* b, lapack_int ldb,
+ float* taub, float* work, lapack_int lwork );
+lapack_int LAPACKE_dggrqf_work( int matrix_order, lapack_int m, lapack_int p,
+ lapack_int n, double* a, lapack_int lda,
+ double* taua, double* b, lapack_int ldb,
+ double* taub, double* work, lapack_int lwork );
+lapack_int LAPACKE_cggrqf_work( int matrix_order, lapack_int m, lapack_int p,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* taua,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* taub,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zggrqf_work( int matrix_order, lapack_int m, lapack_int p,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* taua,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* taub,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sggsvd_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int n,
+ lapack_int p, lapack_int* k, lapack_int* l,
+ float* a, lapack_int lda, float* b,
+ lapack_int ldb, float* alpha, float* beta,
+ float* u, lapack_int ldu, float* v,
+ lapack_int ldv, float* q, lapack_int ldq,
+ float* work, lapack_int* iwork );
+lapack_int LAPACKE_dggsvd_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int n,
+ lapack_int p, lapack_int* k, lapack_int* l,
+ double* a, lapack_int lda, double* b,
+ lapack_int ldb, double* alpha, double* beta,
+ double* u, lapack_int ldu, double* v,
+ lapack_int ldv, double* q, lapack_int ldq,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_cggsvd_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int n,
+ lapack_int p, lapack_int* k, lapack_int* l,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ float* alpha, float* beta,
+ lapack_complex_float* u, lapack_int ldu,
+ lapack_complex_float* v, lapack_int ldv,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* work, float* rwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_zggsvd_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int n,
+ lapack_int p, lapack_int* k, lapack_int* l,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ double* alpha, double* beta,
+ lapack_complex_double* u, lapack_int ldu,
+ lapack_complex_double* v, lapack_int ldv,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* work, double* rwork,
+ lapack_int* iwork );
+
+lapack_int LAPACKE_sggsvp_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int p,
+ lapack_int n, float* a, lapack_int lda,
+ float* b, lapack_int ldb, float tola,
+ float tolb, lapack_int* k, lapack_int* l,
+ float* u, lapack_int ldu, float* v,
+ lapack_int ldv, float* q, lapack_int ldq,
+ lapack_int* iwork, float* tau, float* work );
+lapack_int LAPACKE_dggsvp_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int p,
+ lapack_int n, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double tola,
+ double tolb, lapack_int* k, lapack_int* l,
+ double* u, lapack_int ldu, double* v,
+ lapack_int ldv, double* q, lapack_int ldq,
+ lapack_int* iwork, double* tau, double* work );
+lapack_int LAPACKE_cggsvp_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int p,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, float tola, float tolb,
+ lapack_int* k, lapack_int* l,
+ lapack_complex_float* u, lapack_int ldu,
+ lapack_complex_float* v, lapack_int ldv,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_int* iwork, float* rwork,
+ lapack_complex_float* tau,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zggsvp_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int p,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, double tola, double tolb,
+ lapack_int* k, lapack_int* l,
+ lapack_complex_double* u, lapack_int ldu,
+ lapack_complex_double* v, lapack_int ldv,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_int* iwork, double* rwork,
+ lapack_complex_double* tau,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_sgtcon_work( char norm, lapack_int n, const float* dl,
+ const float* d, const float* du,
+ const float* du2, const lapack_int* ipiv,
+ float anorm, float* rcond, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgtcon_work( char norm, lapack_int n, const double* dl,
+ const double* d, const double* du,
+ const double* du2, const lapack_int* ipiv,
+ double anorm, double* rcond, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cgtcon_work( char norm, lapack_int n,
+ const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du,
+ const lapack_complex_float* du2,
+ const lapack_int* ipiv, float anorm,
+ float* rcond, lapack_complex_float* work );
+lapack_int LAPACKE_zgtcon_work( char norm, lapack_int n,
+ const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du,
+ const lapack_complex_double* du2,
+ const lapack_int* ipiv, double anorm,
+ double* rcond, lapack_complex_double* work );
+
+lapack_int LAPACKE_sgtrfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const float* dl,
+ const float* d, const float* du,
+ const float* dlf, const float* df,
+ const float* duf, const float* du2,
+ const lapack_int* ipiv, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* ferr, float* berr, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dgtrfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const double* dl,
+ const double* d, const double* du,
+ const double* dlf, const double* df,
+ const double* duf, const double* du2,
+ const lapack_int* ipiv, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* ferr, double* berr, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cgtrfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du,
+ const lapack_complex_float* dlf,
+ const lapack_complex_float* df,
+ const lapack_complex_float* duf,
+ const lapack_complex_float* du2,
+ const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zgtrfs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs,
+ const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du,
+ const lapack_complex_double* dlf,
+ const lapack_complex_double* df,
+ const lapack_complex_double* duf,
+ const lapack_complex_double* du2,
+ const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sgtsv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ float* dl, float* d, float* du, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dgtsv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ double* dl, double* d, double* du, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cgtsv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ lapack_complex_float* dl,
+ lapack_complex_float* d,
+ lapack_complex_float* du,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zgtsv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ lapack_complex_double* dl,
+ lapack_complex_double* d,
+ lapack_complex_double* du,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_sgtsvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, const float* dl,
+ const float* d, const float* du, float* dlf,
+ float* df, float* duf, float* du2,
+ lapack_int* ipiv, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ float* work, lapack_int* iwork );
+lapack_int LAPACKE_dgtsvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs, const double* dl,
+ const double* d, const double* du, double* dlf,
+ double* df, double* duf, double* du2,
+ lapack_int* ipiv, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_cgtsvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du,
+ lapack_complex_float* dlf,
+ lapack_complex_float* df,
+ lapack_complex_float* duf,
+ lapack_complex_float* du2, lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zgtsvx_work( int matrix_order, char fact, char trans,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du,
+ lapack_complex_double* dlf,
+ lapack_complex_double* df,
+ lapack_complex_double* duf,
+ lapack_complex_double* du2, lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sgttrf_work( lapack_int n, float* dl, float* d, float* du,
+ float* du2, lapack_int* ipiv );
+lapack_int LAPACKE_dgttrf_work( lapack_int n, double* dl, double* d, double* du,
+ double* du2, lapack_int* ipiv );
+lapack_int LAPACKE_cgttrf_work( lapack_int n, lapack_complex_float* dl,
+ lapack_complex_float* d,
+ lapack_complex_float* du,
+ lapack_complex_float* du2, lapack_int* ipiv );
+lapack_int LAPACKE_zgttrf_work( lapack_int n, lapack_complex_double* dl,
+ lapack_complex_double* d,
+ lapack_complex_double* du,
+ lapack_complex_double* du2, lapack_int* ipiv );
+
+lapack_int LAPACKE_sgttrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const float* dl,
+ const float* d, const float* du,
+ const float* du2, const lapack_int* ipiv,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dgttrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const double* dl,
+ const double* d, const double* du,
+ const double* du2, const lapack_int* ipiv,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_cgttrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du,
+ const lapack_complex_float* du2,
+ const lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zgttrs_work( int matrix_order, char trans, lapack_int n,
+ lapack_int nrhs,
+ const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du,
+ const lapack_complex_double* du2,
+ const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_chbev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int kd,
+ lapack_complex_float* ab, lapack_int ldab,
+ float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zhbev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int kd,
+ lapack_complex_double* ab, lapack_int ldab,
+ double* w, lapack_complex_double* z,
+ lapack_int ldz, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_chbevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int kd,
+ lapack_complex_float* ab, lapack_int ldab,
+ float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_complex_float* work,
+ lapack_int lwork, float* rwork,
+ lapack_int lrwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_zhbevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int kd,
+ lapack_complex_double* ab, lapack_int ldab,
+ double* w, lapack_complex_double* z,
+ lapack_int ldz, lapack_complex_double* work,
+ lapack_int lwork, double* rwork,
+ lapack_int lrwork, lapack_int* iwork,
+ lapack_int liwork );
+
+lapack_int LAPACKE_chbevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, lapack_int kd,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* q, lapack_int ldq,
+ float vl, float vu, lapack_int il,
+ lapack_int iu, float abstol, lapack_int* m,
+ float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_complex_float* work,
+ float* rwork, lapack_int* iwork,
+ lapack_int* ifail );
+lapack_int LAPACKE_zhbevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, lapack_int kd,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* q, lapack_int ldq,
+ double vl, double vu, lapack_int il,
+ lapack_int iu, double abstol, lapack_int* m,
+ double* w, lapack_complex_double* z,
+ lapack_int ldz, lapack_complex_double* work,
+ double* rwork, lapack_int* iwork,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_chbgst_work( int matrix_order, char vect, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ lapack_complex_float* ab, lapack_int ldab,
+ const lapack_complex_float* bb, lapack_int ldbb,
+ lapack_complex_float* x, lapack_int ldx,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zhbgst_work( int matrix_order, char vect, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ lapack_complex_double* ab, lapack_int ldab,
+ const lapack_complex_double* bb,
+ lapack_int ldbb, lapack_complex_double* x,
+ lapack_int ldx, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_chbgv_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* bb, lapack_int ldbb,
+ float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zhbgv_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* bb, lapack_int ldbb,
+ double* w, lapack_complex_double* z,
+ lapack_int ldz, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_chbgvd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* bb, lapack_int ldbb,
+ float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_complex_float* work,
+ lapack_int lwork, float* rwork,
+ lapack_int lrwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_zhbgvd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* bb, lapack_int ldbb,
+ double* w, lapack_complex_double* z,
+ lapack_int ldz, lapack_complex_double* work,
+ lapack_int lwork, double* rwork,
+ lapack_int lrwork, lapack_int* iwork,
+ lapack_int liwork );
+
+lapack_int LAPACKE_chbgvx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, lapack_int ka,
+ lapack_int kb, lapack_complex_float* ab,
+ lapack_int ldab, lapack_complex_float* bb,
+ lapack_int ldbb, lapack_complex_float* q,
+ lapack_int ldq, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_complex_float* work, float* rwork,
+ lapack_int* iwork, lapack_int* ifail );
+lapack_int LAPACKE_zhbgvx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, lapack_int ka,
+ lapack_int kb, lapack_complex_double* ab,
+ lapack_int ldab, lapack_complex_double* bb,
+ lapack_int ldbb, lapack_complex_double* q,
+ lapack_int ldq, double vl, double vu,
+ lapack_int il, lapack_int iu, double abstol,
+ lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_complex_double* work, double* rwork,
+ lapack_int* iwork, lapack_int* ifail );
+
+lapack_int LAPACKE_chbtrd_work( int matrix_order, char vect, char uplo,
+ lapack_int n, lapack_int kd,
+ lapack_complex_float* ab, lapack_int ldab,
+ float* d, float* e, lapack_complex_float* q,
+ lapack_int ldq, lapack_complex_float* work );
+lapack_int LAPACKE_zhbtrd_work( int matrix_order, char vect, char uplo,
+ lapack_int n, lapack_int kd,
+ lapack_complex_double* ab, lapack_int ldab,
+ double* d, double* e, lapack_complex_double* q,
+ lapack_int ldq, lapack_complex_double* work );
+
+lapack_int LAPACKE_checon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv, float anorm,
+ float* rcond, lapack_complex_float* work );
+lapack_int LAPACKE_zhecon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv, double anorm,
+ double* rcond, lapack_complex_double* work );
+
+lapack_int LAPACKE_cheequb_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* s, float* scond, float* amax,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zheequb_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* s, double* scond, double* amax,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_cheev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, float* w,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork );
+lapack_int LAPACKE_zheev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, double* w,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork );
+
+lapack_int LAPACKE_cheevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, float* w,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork, lapack_int lrwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_zheevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, double* w,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork, lapack_int lrwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_cheevr_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ float vl, float vu, lapack_int il,
+ lapack_int iu, float abstol, lapack_int* m,
+ float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_int* isuppz,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork, lapack_int lrwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_zheevr_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ double vl, double vu, lapack_int il,
+ lapack_int iu, double abstol, lapack_int* m,
+ double* w, lapack_complex_double* z,
+ lapack_int ldz, lapack_int* isuppz,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork, lapack_int lrwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_cheevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ float vl, float vu, lapack_int il,
+ lapack_int iu, float abstol, lapack_int* m,
+ float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_complex_float* work,
+ lapack_int lwork, float* rwork,
+ lapack_int* iwork, lapack_int* ifail );
+lapack_int LAPACKE_zheevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ double vl, double vu, lapack_int il,
+ lapack_int iu, double abstol, lapack_int* m,
+ double* w, lapack_complex_double* z,
+ lapack_int ldz, lapack_complex_double* work,
+ lapack_int lwork, double* rwork,
+ lapack_int* iwork, lapack_int* ifail );
+
+lapack_int LAPACKE_chegst_work( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zhegst_work( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_chegv_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb, float* w,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork );
+lapack_int LAPACKE_zhegv_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ double* w, lapack_complex_double* work,
+ lapack_int lwork, double* rwork );
+
+lapack_int LAPACKE_chegvd_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ float* w, lapack_complex_float* work,
+ lapack_int lwork, float* rwork,
+ lapack_int lrwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_zhegvd_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ double* w, lapack_complex_double* work,
+ lapack_int lwork, double* rwork,
+ lapack_int lrwork, lapack_int* iwork,
+ lapack_int liwork );
+
+lapack_int LAPACKE_chegvx_work( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ float vl, float vu, lapack_int il,
+ lapack_int iu, float abstol, lapack_int* m,
+ float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_complex_float* work,
+ lapack_int lwork, float* rwork,
+ lapack_int* iwork, lapack_int* ifail );
+lapack_int LAPACKE_zhegvx_work( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ double vl, double vu, lapack_int il,
+ lapack_int iu, double abstol, lapack_int* m,
+ double* w, lapack_complex_double* z,
+ lapack_int ldz, lapack_complex_double* work,
+ lapack_int lwork, double* rwork,
+ lapack_int* iwork, lapack_int* ifail );
+
+lapack_int LAPACKE_cherfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zherfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_cherfsx_work( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const float* s, const lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zherfsx_work( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const double* s,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_chesv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zhesv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_chesvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ lapack_int* ipiv, const lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr, lapack_complex_float* work,
+ lapack_int lwork, float* rwork );
+lapack_int LAPACKE_zhesvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork );
+
+lapack_int LAPACKE_chesvxx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* s,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zhesvxx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* s,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_chetrd_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ float* d, float* e, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zhetrd_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ double* d, double* e,
+ lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_chetrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ipiv, lapack_complex_float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_zhetrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv, lapack_complex_double* work,
+ lapack_int lwork );
+
+lapack_int LAPACKE_chetri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zhetri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_chetrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zhetrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_chfrk_work( int matrix_order, char transr, char uplo,
+ char trans, lapack_int n, lapack_int k,
+ float alpha, const lapack_complex_float* a,
+ lapack_int lda, float beta,
+ lapack_complex_float* c );
+lapack_int LAPACKE_zhfrk_work( int matrix_order, char transr, char uplo,
+ char trans, lapack_int n, lapack_int k,
+ double alpha, const lapack_complex_double* a,
+ lapack_int lda, double beta,
+ lapack_complex_double* c );
+
+lapack_int LAPACKE_shgeqz_work( int matrix_order, char job, char compq,
+ char compz, lapack_int n, lapack_int ilo,
+ lapack_int ihi, float* h, lapack_int ldh,
+ float* t, lapack_int ldt, float* alphar,
+ float* alphai, float* beta, float* q,
+ lapack_int ldq, float* z, lapack_int ldz,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dhgeqz_work( int matrix_order, char job, char compq,
+ char compz, lapack_int n, lapack_int ilo,
+ lapack_int ihi, double* h, lapack_int ldh,
+ double* t, lapack_int ldt, double* alphar,
+ double* alphai, double* beta, double* q,
+ lapack_int ldq, double* z, lapack_int ldz,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_chgeqz_work( int matrix_order, char job, char compq,
+ char compz, lapack_int n, lapack_int ilo,
+ lapack_int ihi, lapack_complex_float* h,
+ lapack_int ldh, lapack_complex_float* t,
+ lapack_int ldt, lapack_complex_float* alpha,
+ lapack_complex_float* beta,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork );
+lapack_int LAPACKE_zhgeqz_work( int matrix_order, char job, char compq,
+ char compz, lapack_int n, lapack_int ilo,
+ lapack_int ihi, lapack_complex_double* h,
+ lapack_int ldh, lapack_complex_double* t,
+ lapack_int ldt, lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork );
+
+lapack_int LAPACKE_chpcon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap,
+ const lapack_int* ipiv, float anorm,
+ float* rcond, lapack_complex_float* work );
+lapack_int LAPACKE_zhpcon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap,
+ const lapack_int* ipiv, double anorm,
+ double* rcond, lapack_complex_double* work );
+
+lapack_int LAPACKE_chpev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_complex_float* ap, float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zhpev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_complex_double* ap,
+ double* w, lapack_complex_double* z,
+ lapack_int ldz, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_chpevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_complex_float* ap,
+ float* w, lapack_complex_float* z,
+ lapack_int ldz, lapack_complex_float* work,
+ lapack_int lwork, float* rwork,
+ lapack_int lrwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_zhpevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_complex_double* ap,
+ double* w, lapack_complex_double* z,
+ lapack_int ldz, lapack_complex_double* work,
+ lapack_int lwork, double* rwork,
+ lapack_int lrwork, lapack_int* iwork,
+ lapack_int liwork );
+
+lapack_int LAPACKE_chpevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n,
+ lapack_complex_float* ap, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_complex_float* work, float* rwork,
+ lapack_int* iwork, lapack_int* ifail );
+lapack_int LAPACKE_zhpevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n,
+ lapack_complex_double* ap, double vl, double vu,
+ lapack_int il, lapack_int iu, double abstol,
+ lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_complex_double* work, double* rwork,
+ lapack_int* iwork, lapack_int* ifail );
+
+lapack_int LAPACKE_chpgst_work( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, lapack_complex_float* ap,
+ const lapack_complex_float* bp );
+lapack_int LAPACKE_zhpgst_work( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, lapack_complex_double* ap,
+ const lapack_complex_double* bp );
+
+lapack_int LAPACKE_chpgv_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n,
+ lapack_complex_float* ap,
+ lapack_complex_float* bp, float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zhpgv_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n,
+ lapack_complex_double* ap,
+ lapack_complex_double* bp, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_chpgvd_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n,
+ lapack_complex_float* ap,
+ lapack_complex_float* bp, float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork, lapack_int lrwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_zhpgvd_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n,
+ lapack_complex_double* ap,
+ lapack_complex_double* bp, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork, lapack_int lrwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_chpgvx_work( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n,
+ lapack_complex_float* ap,
+ lapack_complex_float* bp, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_complex_float* work, float* rwork,
+ lapack_int* iwork, lapack_int* ifail );
+lapack_int LAPACKE_zhpgvx_work( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n,
+ lapack_complex_double* ap,
+ lapack_complex_double* bp, double vl, double vu,
+ lapack_int il, lapack_int iu, double abstol,
+ lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_complex_double* work, double* rwork,
+ lapack_int* iwork, lapack_int* ifail );
+
+lapack_int LAPACKE_chprfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ const lapack_complex_float* afp,
+ const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zhprfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* afp,
+ const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_chpsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* ap,
+ lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zhpsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* ap,
+ lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_chpsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* ap,
+ lapack_complex_float* afp, lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zhpsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* ap,
+ lapack_complex_double* afp, lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_chptrd_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap, float* d, float* e,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_zhptrd_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap, double* d, double* e,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_chptrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap, lapack_int* ipiv );
+lapack_int LAPACKE_zhptrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap, lapack_int* ipiv );
+
+lapack_int LAPACKE_chptri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap,
+ const lapack_int* ipiv,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zhptri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap,
+ const lapack_int* ipiv,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_chptrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ const lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zhptrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs,
+ const lapack_complex_double* ap,
+ const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_shsein_work( int matrix_order, char job, char eigsrc,
+ char initv, lapack_logical* select,
+ lapack_int n, const float* h, lapack_int ldh,
+ float* wr, const float* wi, float* vl,
+ lapack_int ldvl, float* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m, float* work,
+ lapack_int* ifaill, lapack_int* ifailr );
+lapack_int LAPACKE_dhsein_work( int matrix_order, char job, char eigsrc,
+ char initv, lapack_logical* select,
+ lapack_int n, const double* h, lapack_int ldh,
+ double* wr, const double* wi, double* vl,
+ lapack_int ldvl, double* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m, double* work,
+ lapack_int* ifaill, lapack_int* ifailr );
+lapack_int LAPACKE_chsein_work( int matrix_order, char job, char eigsrc,
+ char initv, const lapack_logical* select,
+ lapack_int n, const lapack_complex_float* h,
+ lapack_int ldh, lapack_complex_float* w,
+ lapack_complex_float* vl, lapack_int ldvl,
+ lapack_complex_float* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m,
+ lapack_complex_float* work, float* rwork,
+ lapack_int* ifaill, lapack_int* ifailr );
+lapack_int LAPACKE_zhsein_work( int matrix_order, char job, char eigsrc,
+ char initv, const lapack_logical* select,
+ lapack_int n, const lapack_complex_double* h,
+ lapack_int ldh, lapack_complex_double* w,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m,
+ lapack_complex_double* work, double* rwork,
+ lapack_int* ifaill, lapack_int* ifailr );
+
+lapack_int LAPACKE_shseqr_work( int matrix_order, char job, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ float* h, lapack_int ldh, float* wr, float* wi,
+ float* z, lapack_int ldz, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dhseqr_work( int matrix_order, char job, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ double* h, lapack_int ldh, double* wr,
+ double* wi, double* z, lapack_int ldz,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_chseqr_work( int matrix_order, char job, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ lapack_complex_float* h, lapack_int ldh,
+ lapack_complex_float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zhseqr_work( int matrix_order, char job, char compz,
+ lapack_int n, lapack_int ilo, lapack_int ihi,
+ lapack_complex_double* h, lapack_int ldh,
+ lapack_complex_double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_clacgv_work( lapack_int n, lapack_complex_float* x,
+ lapack_int incx );
+lapack_int LAPACKE_zlacgv_work( lapack_int n, lapack_complex_double* x,
+ lapack_int incx );
+
+lapack_int LAPACKE_slacpy_work( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, const float* a, lapack_int lda,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dlacpy_work( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, const double* a, lapack_int lda,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_clacpy_work( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, const lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zlacpy_work( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, const lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_zlag2c_work( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ lapack_complex_float* sa, lapack_int ldsa );
+
+lapack_int LAPACKE_slag2d_work( int matrix_order, lapack_int m, lapack_int n,
+ const float* sa, lapack_int ldsa, double* a,
+ lapack_int lda );
+
+lapack_int LAPACKE_dlag2s_work( int matrix_order, lapack_int m, lapack_int n,
+ const double* a, lapack_int lda, float* sa,
+ lapack_int ldsa );
+
+lapack_int LAPACKE_clag2z_work( int matrix_order, lapack_int m, lapack_int n,
+ const lapack_complex_float* sa, lapack_int ldsa,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_slagge_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const float* d,
+ float* a, lapack_int lda, lapack_int* iseed,
+ float* work );
+lapack_int LAPACKE_dlagge_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const double* d,
+ double* a, lapack_int lda, lapack_int* iseed,
+ double* work );
+lapack_int LAPACKE_clagge_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const float* d,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* iseed, lapack_complex_float* work );
+lapack_int LAPACKE_zlagge_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int kl, lapack_int ku, const double* d,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* iseed,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_claghe_work( int matrix_order, lapack_int n, lapack_int k,
+ const float* d, lapack_complex_float* a,
+ lapack_int lda, lapack_int* iseed,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zlaghe_work( int matrix_order, lapack_int n, lapack_int k,
+ const double* d, lapack_complex_double* a,
+ lapack_int lda, lapack_int* iseed,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_slagsy_work( int matrix_order, lapack_int n, lapack_int k,
+ const float* d, float* a, lapack_int lda,
+ lapack_int* iseed, float* work );
+lapack_int LAPACKE_dlagsy_work( int matrix_order, lapack_int n, lapack_int k,
+ const double* d, double* a, lapack_int lda,
+ lapack_int* iseed, double* work );
+lapack_int LAPACKE_clagsy_work( int matrix_order, lapack_int n, lapack_int k,
+ const float* d, lapack_complex_float* a,
+ lapack_int lda, lapack_int* iseed,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zlagsy_work( int matrix_order, lapack_int n, lapack_int k,
+ const double* d, lapack_complex_double* a,
+ lapack_int lda, lapack_int* iseed,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_slapmr_work( int matrix_order, lapack_logical forwrd,
+ lapack_int m, lapack_int n, float* x,
+ lapack_int ldx, lapack_int* k );
+lapack_int LAPACKE_dlapmr_work( int matrix_order, lapack_logical forwrd,
+ lapack_int m, lapack_int n, double* x,
+ lapack_int ldx, lapack_int* k );
+lapack_int LAPACKE_clapmr_work( int matrix_order, lapack_logical forwrd,
+ lapack_int m, lapack_int n,
+ lapack_complex_float* x, lapack_int ldx,
+ lapack_int* k );
+lapack_int LAPACKE_zlapmr_work( int matrix_order, lapack_logical forwrd,
+ lapack_int m, lapack_int n,
+ lapack_complex_double* x, lapack_int ldx,
+ lapack_int* k );
+
+lapack_int LAPACKE_slartgp_work( float f, float g, float* cs, float* sn,
+ float* r );
+lapack_int LAPACKE_dlartgp_work( double f, double g, double* cs, double* sn,
+ double* r );
+
+lapack_int LAPACKE_slartgs_work( float x, float y, float sigma, float* cs,
+ float* sn );
+lapack_int LAPACKE_dlartgs_work( double x, double y, double sigma, double* cs,
+ double* sn );
+
+float LAPACKE_slapy2_work( float x, float y );
+double LAPACKE_dlapy2_work( double x, double y );
+
+float LAPACKE_slapy3_work( float x, float y, float z );
+double LAPACKE_dlapy3_work( double x, double y, double z );
+
+float LAPACKE_slamch_work( char cmach );
+double LAPACKE_dlamch_work( char cmach );
+
+float LAPACKE_slange_work( int matrix_order, char norm, lapack_int m,
+ lapack_int n, const float* a, lapack_int lda,
+ float* work );
+double LAPACKE_dlange_work( int matrix_order, char norm, lapack_int m,
+ lapack_int n, const double* a, lapack_int lda,
+ double* work );
+float LAPACKE_clange_work( int matrix_order, char norm, lapack_int m,
+ lapack_int n, const lapack_complex_float* a,
+ lapack_int lda, float* work );
+double LAPACKE_zlange_work( int matrix_order, char norm, lapack_int m,
+ lapack_int n, const lapack_complex_double* a,
+ lapack_int lda, double* work );
+
+float LAPACKE_clanhe_work( int matrix_order, char norm, char uplo,
+ lapack_int n, const lapack_complex_float* a,
+ lapack_int lda, float* work );
+double LAPACKE_zlanhe_work( int matrix_order, char norm, char uplo,
+ lapack_int n, const lapack_complex_double* a,
+ lapack_int lda, double* work );
+
+float LAPACKE_slansy_work( int matrix_order, char norm, char uplo,
+ lapack_int n, const float* a, lapack_int lda,
+ float* work );
+double LAPACKE_dlansy_work( int matrix_order, char norm, char uplo,
+ lapack_int n, const double* a, lapack_int lda,
+ double* work );
+float LAPACKE_clansy_work( int matrix_order, char norm, char uplo,
+ lapack_int n, const lapack_complex_float* a,
+ lapack_int lda, float* work );
+double LAPACKE_zlansy_work( int matrix_order, char norm, char uplo,
+ lapack_int n, const lapack_complex_double* a,
+ lapack_int lda, double* work );
+
+float LAPACKE_slantr_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int m, lapack_int n, const float* a,
+ lapack_int lda, float* work );
+double LAPACKE_dlantr_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int m, lapack_int n,
+ const double* a, lapack_int lda, double* work );
+float LAPACKE_clantr_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int m, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* work );
+double LAPACKE_zlantr_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* work );
+
+lapack_int LAPACKE_slarfb_work( int matrix_order, char side, char trans,
+ char direct, char storev, lapack_int m,
+ lapack_int n, lapack_int k, const float* v,
+ lapack_int ldv, const float* t, lapack_int ldt,
+ float* c, lapack_int ldc, float* work,
+ lapack_int ldwork );
+lapack_int LAPACKE_dlarfb_work( int matrix_order, char side, char trans,
+ char direct, char storev, lapack_int m,
+ lapack_int n, lapack_int k, const double* v,
+ lapack_int ldv, const double* t, lapack_int ldt,
+ double* c, lapack_int ldc, double* work,
+ lapack_int ldwork );
+lapack_int LAPACKE_clarfb_work( int matrix_order, char side, char trans,
+ char direct, char storev, lapack_int m,
+ lapack_int n, lapack_int k,
+ const lapack_complex_float* v, lapack_int ldv,
+ const lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work, lapack_int ldwork );
+lapack_int LAPACKE_zlarfb_work( int matrix_order, char side, char trans,
+ char direct, char storev, lapack_int m,
+ lapack_int n, lapack_int k,
+ const lapack_complex_double* v, lapack_int ldv,
+ const lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work,
+ lapack_int ldwork );
+
+lapack_int LAPACKE_slarfg_work( lapack_int n, float* alpha, float* x,
+ lapack_int incx, float* tau );
+lapack_int LAPACKE_dlarfg_work( lapack_int n, double* alpha, double* x,
+ lapack_int incx, double* tau );
+lapack_int LAPACKE_clarfg_work( lapack_int n, lapack_complex_float* alpha,
+ lapack_complex_float* x, lapack_int incx,
+ lapack_complex_float* tau );
+lapack_int LAPACKE_zlarfg_work( lapack_int n, lapack_complex_double* alpha,
+ lapack_complex_double* x, lapack_int incx,
+ lapack_complex_double* tau );
+
+lapack_int LAPACKE_slarft_work( int matrix_order, char direct, char storev,
+ lapack_int n, lapack_int k, const float* v,
+ lapack_int ldv, const float* tau, float* t,
+ lapack_int ldt );
+lapack_int LAPACKE_dlarft_work( int matrix_order, char direct, char storev,
+ lapack_int n, lapack_int k, const double* v,
+ lapack_int ldv, const double* tau, double* t,
+ lapack_int ldt );
+lapack_int LAPACKE_clarft_work( int matrix_order, char direct, char storev,
+ lapack_int n, lapack_int k,
+ const lapack_complex_float* v, lapack_int ldv,
+ const lapack_complex_float* tau,
+ lapack_complex_float* t, lapack_int ldt );
+lapack_int LAPACKE_zlarft_work( int matrix_order, char direct, char storev,
+ lapack_int n, lapack_int k,
+ const lapack_complex_double* v, lapack_int ldv,
+ const lapack_complex_double* tau,
+ lapack_complex_double* t, lapack_int ldt );
+
+lapack_int LAPACKE_slarfx_work( int matrix_order, char side, lapack_int m,
+ lapack_int n, const float* v, float tau,
+ float* c, lapack_int ldc, float* work );
+lapack_int LAPACKE_dlarfx_work( int matrix_order, char side, lapack_int m,
+ lapack_int n, const double* v, double tau,
+ double* c, lapack_int ldc, double* work );
+lapack_int LAPACKE_clarfx_work( int matrix_order, char side, lapack_int m,
+ lapack_int n, const lapack_complex_float* v,
+ lapack_complex_float tau,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zlarfx_work( int matrix_order, char side, lapack_int m,
+ lapack_int n, const lapack_complex_double* v,
+ lapack_complex_double tau,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_slarnv_work( lapack_int idist, lapack_int* iseed,
+ lapack_int n, float* x );
+lapack_int LAPACKE_dlarnv_work( lapack_int idist, lapack_int* iseed,
+ lapack_int n, double* x );
+lapack_int LAPACKE_clarnv_work( lapack_int idist, lapack_int* iseed,
+ lapack_int n, lapack_complex_float* x );
+lapack_int LAPACKE_zlarnv_work( lapack_int idist, lapack_int* iseed,
+ lapack_int n, lapack_complex_double* x );
+
+lapack_int LAPACKE_slaset_work( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, float alpha, float beta, float* a,
+ lapack_int lda );
+lapack_int LAPACKE_dlaset_work( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, double alpha, double beta,
+ double* a, lapack_int lda );
+lapack_int LAPACKE_claset_work( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, lapack_complex_float alpha,
+ lapack_complex_float beta,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_zlaset_work( int matrix_order, char uplo, lapack_int m,
+ lapack_int n, lapack_complex_double alpha,
+ lapack_complex_double beta,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_slasrt_work( char id, lapack_int n, float* d );
+lapack_int LAPACKE_dlasrt_work( char id, lapack_int n, double* d );
+
+lapack_int LAPACKE_slaswp_work( int matrix_order, lapack_int n, float* a,
+ lapack_int lda, lapack_int k1, lapack_int k2,
+ const lapack_int* ipiv, lapack_int incx );
+lapack_int LAPACKE_dlaswp_work( int matrix_order, lapack_int n, double* a,
+ lapack_int lda, lapack_int k1, lapack_int k2,
+ const lapack_int* ipiv, lapack_int incx );
+lapack_int LAPACKE_claswp_work( int matrix_order, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int k1, lapack_int k2,
+ const lapack_int* ipiv, lapack_int incx );
+lapack_int LAPACKE_zlaswp_work( int matrix_order, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int k1, lapack_int k2,
+ const lapack_int* ipiv, lapack_int incx );
+
+lapack_int LAPACKE_slatms_work( int matrix_order, lapack_int m, lapack_int n,
+ char dist, lapack_int* iseed, char sym,
+ float* d, lapack_int mode, float cond,
+ float dmax, lapack_int kl, lapack_int ku,
+ char pack, float* a, lapack_int lda,
+ float* work );
+lapack_int LAPACKE_dlatms_work( int matrix_order, lapack_int m, lapack_int n,
+ char dist, lapack_int* iseed, char sym,
+ double* d, lapack_int mode, double cond,
+ double dmax, lapack_int kl, lapack_int ku,
+ char pack, double* a, lapack_int lda,
+ double* work );
+lapack_int LAPACKE_clatms_work( int matrix_order, lapack_int m, lapack_int n,
+ char dist, lapack_int* iseed, char sym,
+ float* d, lapack_int mode, float cond,
+ float dmax, lapack_int kl, lapack_int ku,
+ char pack, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* work );
+lapack_int LAPACKE_zlatms_work( int matrix_order, lapack_int m, lapack_int n,
+ char dist, lapack_int* iseed, char sym,
+ double* d, lapack_int mode, double cond,
+ double dmax, lapack_int kl, lapack_int ku,
+ char pack, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* work );
+
+lapack_int LAPACKE_slauum_work( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int lda );
+lapack_int LAPACKE_dlauum_work( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda );
+lapack_int LAPACKE_clauum_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_zlauum_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_sopgtr_work( int matrix_order, char uplo, lapack_int n,
+ const float* ap, const float* tau, float* q,
+ lapack_int ldq, float* work );
+lapack_int LAPACKE_dopgtr_work( int matrix_order, char uplo, lapack_int n,
+ const double* ap, const double* tau, double* q,
+ lapack_int ldq, double* work );
+
+lapack_int LAPACKE_sopmtr_work( int matrix_order, char side, char uplo,
+ char trans, lapack_int m, lapack_int n,
+ const float* ap, const float* tau, float* c,
+ lapack_int ldc, float* work );
+lapack_int LAPACKE_dopmtr_work( int matrix_order, char side, char uplo,
+ char trans, lapack_int m, lapack_int n,
+ const double* ap, const double* tau, double* c,
+ lapack_int ldc, double* work );
+
+lapack_int LAPACKE_sorgbr_work( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int k, float* a,
+ lapack_int lda, const float* tau, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dorgbr_work( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int k, double* a,
+ lapack_int lda, const double* tau, double* work,
+ lapack_int lwork );
+
+lapack_int LAPACKE_sorghr_work( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, float* a, lapack_int lda,
+ const float* tau, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dorghr_work( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, double* a, lapack_int lda,
+ const double* tau, double* work,
+ lapack_int lwork );
+
+lapack_int LAPACKE_sorglq_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, float* a, lapack_int lda,
+ const float* tau, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dorglq_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, double* a, lapack_int lda,
+ const double* tau, double* work,
+ lapack_int lwork );
+
+lapack_int LAPACKE_sorgql_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, float* a, lapack_int lda,
+ const float* tau, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dorgql_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, double* a, lapack_int lda,
+ const double* tau, double* work,
+ lapack_int lwork );
+
+lapack_int LAPACKE_sorgqr_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, float* a, lapack_int lda,
+ const float* tau, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dorgqr_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, double* a, lapack_int lda,
+ const double* tau, double* work,
+ lapack_int lwork );
+
+lapack_int LAPACKE_sorgrq_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, float* a, lapack_int lda,
+ const float* tau, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dorgrq_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, double* a, lapack_int lda,
+ const double* tau, double* work,
+ lapack_int lwork );
+
+lapack_int LAPACKE_sorgtr_work( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int lda, const float* tau,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dorgtr_work( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda, const double* tau,
+ double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sormbr_work( int matrix_order, char vect, char side,
+ char trans, lapack_int m, lapack_int n,
+ lapack_int k, const float* a, lapack_int lda,
+ const float* tau, float* c, lapack_int ldc,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dormbr_work( int matrix_order, char vect, char side,
+ char trans, lapack_int m, lapack_int n,
+ lapack_int k, const double* a, lapack_int lda,
+ const double* tau, double* c, lapack_int ldc,
+ double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sormhr_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int ilo,
+ lapack_int ihi, const float* a, lapack_int lda,
+ const float* tau, float* c, lapack_int ldc,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dormhr_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int ilo,
+ lapack_int ihi, const double* a, lapack_int lda,
+ const double* tau, double* c, lapack_int ldc,
+ double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sormlq_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const float* a, lapack_int lda,
+ const float* tau, float* c, lapack_int ldc,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dormlq_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const double* a, lapack_int lda,
+ const double* tau, double* c, lapack_int ldc,
+ double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sormql_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const float* a, lapack_int lda,
+ const float* tau, float* c, lapack_int ldc,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dormql_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const double* a, lapack_int lda,
+ const double* tau, double* c, lapack_int ldc,
+ double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sormqr_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const float* a, lapack_int lda,
+ const float* tau, float* c, lapack_int ldc,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dormqr_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const double* a, lapack_int lda,
+ const double* tau, double* c, lapack_int ldc,
+ double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sormrq_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const float* a, lapack_int lda,
+ const float* tau, float* c, lapack_int ldc,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dormrq_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const double* a, lapack_int lda,
+ const double* tau, double* c, lapack_int ldc,
+ double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sormrz_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, const float* a, lapack_int lda,
+ const float* tau, float* c, lapack_int ldc,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dormrz_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, const double* a, lapack_int lda,
+ const double* tau, double* c, lapack_int ldc,
+ double* work, lapack_int lwork );
+
+lapack_int LAPACKE_sormtr_work( int matrix_order, char side, char uplo,
+ char trans, lapack_int m, lapack_int n,
+ const float* a, lapack_int lda,
+ const float* tau, float* c, lapack_int ldc,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dormtr_work( int matrix_order, char side, char uplo,
+ char trans, lapack_int m, lapack_int n,
+ const double* a, lapack_int lda,
+ const double* tau, double* c, lapack_int ldc,
+ double* work, lapack_int lwork );
+
+lapack_int LAPACKE_spbcon_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const float* ab, lapack_int ldab,
+ float anorm, float* rcond, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dpbcon_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const double* ab,
+ lapack_int ldab, double anorm, double* rcond,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_cpbcon_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const lapack_complex_float* ab,
+ lapack_int ldab, float anorm, float* rcond,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zpbcon_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const lapack_complex_double* ab,
+ lapack_int ldab, double anorm, double* rcond,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_spbequ_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const float* ab, lapack_int ldab,
+ float* s, float* scond, float* amax );
+lapack_int LAPACKE_dpbequ_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const double* ab,
+ lapack_int ldab, double* s, double* scond,
+ double* amax );
+lapack_int LAPACKE_cpbequ_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const lapack_complex_float* ab,
+ lapack_int ldab, float* s, float* scond,
+ float* amax );
+lapack_int LAPACKE_zpbequ_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, const lapack_complex_double* ab,
+ lapack_int ldab, double* s, double* scond,
+ double* amax );
+
+lapack_int LAPACKE_spbrfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, const float* ab,
+ lapack_int ldab, const float* afb,
+ lapack_int ldafb, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* ferr, float* berr, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dpbrfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ const double* ab, lapack_int ldab,
+ const double* afb, lapack_int ldafb,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* ferr, double* berr,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_cpbrfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ const lapack_complex_float* ab, lapack_int ldab,
+ const lapack_complex_float* afb,
+ lapack_int ldafb, const lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zpbrfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ const lapack_complex_double* ab,
+ lapack_int ldab,
+ const lapack_complex_double* afb,
+ lapack_int ldafb,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_spbstf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kb, float* bb, lapack_int ldbb );
+lapack_int LAPACKE_dpbstf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kb, double* bb, lapack_int ldbb );
+lapack_int LAPACKE_cpbstf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kb, lapack_complex_float* bb,
+ lapack_int ldbb );
+lapack_int LAPACKE_zpbstf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kb, lapack_complex_double* bb,
+ lapack_int ldbb );
+
+lapack_int LAPACKE_spbsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, float* ab,
+ lapack_int ldab, float* b, lapack_int ldb );
+lapack_int LAPACKE_dpbsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, double* ab,
+ lapack_int ldab, double* b, lapack_int ldb );
+lapack_int LAPACKE_cpbsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zpbsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_spbsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ float* ab, lapack_int ldab, float* afb,
+ lapack_int ldafb, char* equed, float* s,
+ float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr, float* work, lapack_int* iwork );
+lapack_int LAPACKE_dpbsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ double* ab, lapack_int ldab, double* afb,
+ lapack_int ldafb, char* equed, double* s,
+ double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* rcond, double* ferr,
+ double* berr, double* work, lapack_int* iwork );
+lapack_int LAPACKE_cpbsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* afb, lapack_int ldafb,
+ char* equed, float* s, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zpbsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int kd, lapack_int nrhs,
+ lapack_complex_double* ab, lapack_int ldab,
+ lapack_complex_double* afb, lapack_int ldafb,
+ char* equed, double* s,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_spbtrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, float* ab, lapack_int ldab );
+lapack_int LAPACKE_dpbtrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, double* ab, lapack_int ldab );
+lapack_int LAPACKE_cpbtrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_complex_float* ab,
+ lapack_int ldab );
+lapack_int LAPACKE_zpbtrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_complex_double* ab,
+ lapack_int ldab );
+
+lapack_int LAPACKE_spbtrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs, const float* ab,
+ lapack_int ldab, float* b, lapack_int ldb );
+lapack_int LAPACKE_dpbtrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ const double* ab, lapack_int ldab, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cpbtrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ const lapack_complex_float* ab, lapack_int ldab,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zpbtrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int kd, lapack_int nrhs,
+ const lapack_complex_double* ab,
+ lapack_int ldab, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_spftrf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, float* a );
+lapack_int LAPACKE_dpftrf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, double* a );
+lapack_int LAPACKE_cpftrf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_complex_float* a );
+lapack_int LAPACKE_zpftrf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_complex_double* a );
+
+lapack_int LAPACKE_spftri_work( int matrix_order, char transr, char uplo,
+ lapack_int n, float* a );
+lapack_int LAPACKE_dpftri_work( int matrix_order, char transr, char uplo,
+ lapack_int n, double* a );
+lapack_int LAPACKE_cpftri_work( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_complex_float* a );
+lapack_int LAPACKE_zpftri_work( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_complex_double* a );
+
+lapack_int LAPACKE_spftrs_work( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_int nrhs, const float* a,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dpftrs_work( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_int nrhs, const double* a,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_cpftrs_work( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zpftrs_work( int matrix_order, char transr, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_spocon_work( int matrix_order, char uplo, lapack_int n,
+ const float* a, lapack_int lda, float anorm,
+ float* rcond, float* work, lapack_int* iwork );
+lapack_int LAPACKE_dpocon_work( int matrix_order, char uplo, lapack_int n,
+ const double* a, lapack_int lda, double anorm,
+ double* rcond, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cpocon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float anorm, float* rcond,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zpocon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double anorm, double* rcond,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_spoequ_work( int matrix_order, lapack_int n, const float* a,
+ lapack_int lda, float* s, float* scond,
+ float* amax );
+lapack_int LAPACKE_dpoequ_work( int matrix_order, lapack_int n, const double* a,
+ lapack_int lda, double* s, double* scond,
+ double* amax );
+lapack_int LAPACKE_cpoequ_work( int matrix_order, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* s, float* scond, float* amax );
+lapack_int LAPACKE_zpoequ_work( int matrix_order, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* s, double* scond, double* amax );
+
+lapack_int LAPACKE_spoequb_work( int matrix_order, lapack_int n, const float* a,
+ lapack_int lda, float* s, float* scond,
+ float* amax );
+lapack_int LAPACKE_dpoequb_work( int matrix_order, lapack_int n,
+ const double* a, lapack_int lda, double* s,
+ double* scond, double* amax );
+lapack_int LAPACKE_cpoequb_work( int matrix_order, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* s, float* scond, float* amax );
+lapack_int LAPACKE_zpoequb_work( int matrix_order, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* s, double* scond, double* amax );
+
+lapack_int LAPACKE_sporfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ const float* af, lapack_int ldaf,
+ const float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* ferr, float* berr,
+ float* work, lapack_int* iwork );
+lapack_int LAPACKE_dporfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* a,
+ lapack_int lda, const double* af,
+ lapack_int ldaf, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* ferr, double* berr, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cporfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* af,
+ lapack_int ldaf, const lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zporfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* af,
+ lapack_int ldaf, const lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sporfsx_work( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs, const float* a,
+ lapack_int lda, const float* af,
+ lapack_int ldaf, const float* s,
+ const float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dporfsx_work( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs, const double* a,
+ lapack_int lda, const double* af,
+ lapack_int ldaf, const double* s,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cporfsx_work( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* af,
+ lapack_int ldaf, const float* s,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zporfsx_work( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* af,
+ lapack_int ldaf, const double* s,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_sposv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, float* a, lapack_int lda,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dposv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_cposv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zposv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dsposv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* work, float* swork,
+ lapack_int* iter );
+lapack_int LAPACKE_zcposv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, lapack_complex_double* work,
+ lapack_complex_float* swork, double* rwork,
+ lapack_int* iter );
+
+lapack_int LAPACKE_sposvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, float* a,
+ lapack_int lda, float* af, lapack_int ldaf,
+ char* equed, float* s, float* b, lapack_int ldb,
+ float* x, lapack_int ldx, float* rcond,
+ float* ferr, float* berr, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dposvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, double* a,
+ lapack_int lda, double* af, lapack_int ldaf,
+ char* equed, double* s, double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_cposvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ char* equed, float* s, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zposvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ char* equed, double* s,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sposvxx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, float* a,
+ lapack_int lda, float* af, lapack_int ldaf,
+ char* equed, float* s, float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dposvxx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, double* a,
+ lapack_int lda, double* af, lapack_int ldaf,
+ char* equed, double* s, double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cposvxx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ char* equed, float* s, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* rpvgrw,
+ float* berr, lapack_int n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int nparams, float* params,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zposvxx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ char* equed, double* s,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_spotrf_work( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int lda );
+lapack_int LAPACKE_dpotrf_work( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda );
+lapack_int LAPACKE_cpotrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_zpotrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_spotri_work( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int lda );
+lapack_int LAPACKE_dpotri_work( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda );
+lapack_int LAPACKE_cpotri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_zpotri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_spotrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dpotrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* a,
+ lapack_int lda, double* b, lapack_int ldb );
+lapack_int LAPACKE_cpotrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zpotrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_sppcon_work( int matrix_order, char uplo, lapack_int n,
+ const float* ap, float anorm, float* rcond,
+ float* work, lapack_int* iwork );
+lapack_int LAPACKE_dppcon_work( int matrix_order, char uplo, lapack_int n,
+ const double* ap, double anorm, double* rcond,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_cppcon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap, float anorm,
+ float* rcond, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zppcon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap, double anorm,
+ double* rcond, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_sppequ_work( int matrix_order, char uplo, lapack_int n,
+ const float* ap, float* s, float* scond,
+ float* amax );
+lapack_int LAPACKE_dppequ_work( int matrix_order, char uplo, lapack_int n,
+ const double* ap, double* s, double* scond,
+ double* amax );
+lapack_int LAPACKE_cppequ_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap, float* s,
+ float* scond, float* amax );
+lapack_int LAPACKE_zppequ_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap, double* s,
+ double* scond, double* amax );
+
+lapack_int LAPACKE_spprfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* ap,
+ const float* afp, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* ferr, float* berr, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dpprfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* ap,
+ const double* afp, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* ferr, double* berr, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cpprfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ const lapack_complex_float* afp,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zpprfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* afp,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sppsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, float* ap, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dppsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, double* ap, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cppsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* ap,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zppsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* ap,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_sppsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, float* ap,
+ float* afp, char* equed, float* s, float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ float* work, lapack_int* iwork );
+lapack_int LAPACKE_dppsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, double* ap,
+ double* afp, char* equed, double* s, double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_cppsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* ap,
+ lapack_complex_float* afp, char* equed,
+ float* s, lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zppsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* ap,
+ lapack_complex_double* afp, char* equed,
+ double* s, lapack_complex_double* b,
+ lapack_int ldb, lapack_complex_double* x,
+ lapack_int ldx, double* rcond, double* ferr,
+ double* berr, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_spptrf_work( int matrix_order, char uplo, lapack_int n,
+ float* ap );
+lapack_int LAPACKE_dpptrf_work( int matrix_order, char uplo, lapack_int n,
+ double* ap );
+lapack_int LAPACKE_cpptrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap );
+lapack_int LAPACKE_zpptrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap );
+
+lapack_int LAPACKE_spptri_work( int matrix_order, char uplo, lapack_int n,
+ float* ap );
+lapack_int LAPACKE_dpptri_work( int matrix_order, char uplo, lapack_int n,
+ double* ap );
+lapack_int LAPACKE_cpptri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap );
+lapack_int LAPACKE_zpptri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap );
+
+lapack_int LAPACKE_spptrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* ap, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dpptrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* ap, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cpptrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zpptrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs,
+ const lapack_complex_double* ap,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_spstrf_work( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int lda, lapack_int* piv,
+ lapack_int* rank, float tol, float* work );
+lapack_int LAPACKE_dpstrf_work( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda, lapack_int* piv,
+ lapack_int* rank, double tol, double* work );
+lapack_int LAPACKE_cpstrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* piv, lapack_int* rank, float tol,
+ float* work );
+lapack_int LAPACKE_zpstrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* piv, lapack_int* rank, double tol,
+ double* work );
+
+lapack_int LAPACKE_sptcon_work( lapack_int n, const float* d, const float* e,
+ float anorm, float* rcond, float* work );
+lapack_int LAPACKE_dptcon_work( lapack_int n, const double* d, const double* e,
+ double anorm, double* rcond, double* work );
+lapack_int LAPACKE_cptcon_work( lapack_int n, const float* d,
+ const lapack_complex_float* e, float anorm,
+ float* rcond, float* work );
+lapack_int LAPACKE_zptcon_work( lapack_int n, const double* d,
+ const lapack_complex_double* e, double anorm,
+ double* rcond, double* work );
+
+lapack_int LAPACKE_spteqr_work( int matrix_order, char compz, lapack_int n,
+ float* d, float* e, float* z, lapack_int ldz,
+ float* work );
+lapack_int LAPACKE_dpteqr_work( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, double* z, lapack_int ldz,
+ double* work );
+lapack_int LAPACKE_cpteqr_work( int matrix_order, char compz, lapack_int n,
+ float* d, float* e, lapack_complex_float* z,
+ lapack_int ldz, float* work );
+lapack_int LAPACKE_zpteqr_work( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, lapack_complex_double* z,
+ lapack_int ldz, double* work );
+
+lapack_int LAPACKE_sptrfs_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ const float* d, const float* e, const float* df,
+ const float* ef, const float* b, lapack_int ldb,
+ float* x, lapack_int ldx, float* ferr,
+ float* berr, float* work );
+lapack_int LAPACKE_dptrfs_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ const double* d, const double* e,
+ const double* df, const double* ef,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* ferr, double* berr,
+ double* work );
+lapack_int LAPACKE_cptrfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* d,
+ const lapack_complex_float* e, const float* df,
+ const lapack_complex_float* ef,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zptrfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* d,
+ const lapack_complex_double* e,
+ const double* df,
+ const lapack_complex_double* ef,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sptsv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ float* d, float* e, float* b, lapack_int ldb );
+lapack_int LAPACKE_dptsv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ double* d, double* e, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cptsv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ float* d, lapack_complex_float* e,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zptsv_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ double* d, lapack_complex_double* e,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_sptsvx_work( int matrix_order, char fact, lapack_int n,
+ lapack_int nrhs, const float* d, const float* e,
+ float* df, float* ef, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ float* work );
+lapack_int LAPACKE_dptsvx_work( int matrix_order, char fact, lapack_int n,
+ lapack_int nrhs, const double* d,
+ const double* e, double* df, double* ef,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* rcond, double* ferr,
+ double* berr, double* work );
+lapack_int LAPACKE_cptsvx_work( int matrix_order, char fact, lapack_int n,
+ lapack_int nrhs, const float* d,
+ const lapack_complex_float* e, float* df,
+ lapack_complex_float* ef,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zptsvx_work( int matrix_order, char fact, lapack_int n,
+ lapack_int nrhs, const double* d,
+ const lapack_complex_double* e, double* df,
+ lapack_complex_double* ef,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_spttrf_work( lapack_int n, float* d, float* e );
+lapack_int LAPACKE_dpttrf_work( lapack_int n, double* d, double* e );
+lapack_int LAPACKE_cpttrf_work( lapack_int n, float* d,
+ lapack_complex_float* e );
+lapack_int LAPACKE_zpttrf_work( lapack_int n, double* d,
+ lapack_complex_double* e );
+
+lapack_int LAPACKE_spttrs_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ const float* d, const float* e, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dpttrs_work( int matrix_order, lapack_int n, lapack_int nrhs,
+ const double* d, const double* e, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_cpttrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* d,
+ const lapack_complex_float* e,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zpttrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* d,
+ const lapack_complex_double* e,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_ssbev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int kd, float* ab,
+ lapack_int ldab, float* w, float* z,
+ lapack_int ldz, float* work );
+lapack_int LAPACKE_dsbev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int kd, double* ab,
+ lapack_int ldab, double* w, double* z,
+ lapack_int ldz, double* work );
+
+lapack_int LAPACKE_ssbevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int kd, float* ab,
+ lapack_int ldab, float* w, float* z,
+ lapack_int ldz, float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_dsbevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int kd, double* ab,
+ lapack_int ldab, double* w, double* z,
+ lapack_int ldz, double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_ssbevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, lapack_int kd,
+ float* ab, lapack_int ldab, float* q,
+ lapack_int ldq, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z,
+ lapack_int ldz, float* work, lapack_int* iwork,
+ lapack_int* ifail );
+lapack_int LAPACKE_dsbevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, lapack_int kd,
+ double* ab, lapack_int ldab, double* q,
+ lapack_int ldq, double vl, double vu,
+ lapack_int il, lapack_int iu, double abstol,
+ lapack_int* m, double* w, double* z,
+ lapack_int ldz, double* work, lapack_int* iwork,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_ssbgst_work( int matrix_order, char vect, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ float* ab, lapack_int ldab, const float* bb,
+ lapack_int ldbb, float* x, lapack_int ldx,
+ float* work );
+lapack_int LAPACKE_dsbgst_work( int matrix_order, char vect, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ double* ab, lapack_int ldab, const double* bb,
+ lapack_int ldbb, double* x, lapack_int ldx,
+ double* work );
+
+lapack_int LAPACKE_ssbgv_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ float* ab, lapack_int ldab, float* bb,
+ lapack_int ldbb, float* w, float* z,
+ lapack_int ldz, float* work );
+lapack_int LAPACKE_dsbgv_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ double* ab, lapack_int ldab, double* bb,
+ lapack_int ldbb, double* w, double* z,
+ lapack_int ldz, double* work );
+
+lapack_int LAPACKE_ssbgvd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ float* ab, lapack_int ldab, float* bb,
+ lapack_int ldbb, float* w, float* z,
+ lapack_int ldz, float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_dsbgvd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, lapack_int ka, lapack_int kb,
+ double* ab, lapack_int ldab, double* bb,
+ lapack_int ldbb, double* w, double* z,
+ lapack_int ldz, double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_ssbgvx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, lapack_int ka,
+ lapack_int kb, float* ab, lapack_int ldab,
+ float* bb, lapack_int ldbb, float* q,
+ lapack_int ldq, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z,
+ lapack_int ldz, float* work, lapack_int* iwork,
+ lapack_int* ifail );
+lapack_int LAPACKE_dsbgvx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, lapack_int ka,
+ lapack_int kb, double* ab, lapack_int ldab,
+ double* bb, lapack_int ldbb, double* q,
+ lapack_int ldq, double vl, double vu,
+ lapack_int il, lapack_int iu, double abstol,
+ lapack_int* m, double* w, double* z,
+ lapack_int ldz, double* work, lapack_int* iwork,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_ssbtrd_work( int matrix_order, char vect, char uplo,
+ lapack_int n, lapack_int kd, float* ab,
+ lapack_int ldab, float* d, float* e, float* q,
+ lapack_int ldq, float* work );
+lapack_int LAPACKE_dsbtrd_work( int matrix_order, char vect, char uplo,
+ lapack_int n, lapack_int kd, double* ab,
+ lapack_int ldab, double* d, double* e,
+ double* q, lapack_int ldq, double* work );
+
+lapack_int LAPACKE_ssfrk_work( int matrix_order, char transr, char uplo,
+ char trans, lapack_int n, lapack_int k,
+ float alpha, const float* a, lapack_int lda,
+ float beta, float* c );
+lapack_int LAPACKE_dsfrk_work( int matrix_order, char transr, char uplo,
+ char trans, lapack_int n, lapack_int k,
+ double alpha, const double* a, lapack_int lda,
+ double beta, double* c );
+
+lapack_int LAPACKE_sspcon_work( int matrix_order, char uplo, lapack_int n,
+ const float* ap, const lapack_int* ipiv,
+ float anorm, float* rcond, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dspcon_work( int matrix_order, char uplo, lapack_int n,
+ const double* ap, const lapack_int* ipiv,
+ double anorm, double* rcond, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_cspcon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap,
+ const lapack_int* ipiv, float anorm,
+ float* rcond, lapack_complex_float* work );
+lapack_int LAPACKE_zspcon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap,
+ const lapack_int* ipiv, double anorm,
+ double* rcond, lapack_complex_double* work );
+
+lapack_int LAPACKE_sspev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, float* ap, float* w, float* z,
+ lapack_int ldz, float* work );
+lapack_int LAPACKE_dspev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, double* ap, double* w, double* z,
+ lapack_int ldz, double* work );
+
+lapack_int LAPACKE_sspevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, float* ap, float* w, float* z,
+ lapack_int ldz, float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_dspevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, double* ap, double* w, double* z,
+ lapack_int ldz, double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_sspevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, float* ap, float vl,
+ float vu, lapack_int il, lapack_int iu,
+ float abstol, lapack_int* m, float* w, float* z,
+ lapack_int ldz, float* work, lapack_int* iwork,
+ lapack_int* ifail );
+lapack_int LAPACKE_dspevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, double* ap, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w,
+ double* z, lapack_int ldz, double* work,
+ lapack_int* iwork, lapack_int* ifail );
+
+lapack_int LAPACKE_sspgst_work( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, float* ap, const float* bp );
+lapack_int LAPACKE_dspgst_work( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, double* ap, const double* bp );
+
+lapack_int LAPACKE_sspgv_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, float* ap, float* bp,
+ float* w, float* z, lapack_int ldz,
+ float* work );
+lapack_int LAPACKE_dspgv_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, double* ap, double* bp,
+ double* w, double* z, lapack_int ldz,
+ double* work );
+
+lapack_int LAPACKE_sspgvd_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, float* ap, float* bp,
+ float* w, float* z, lapack_int ldz, float* work,
+ lapack_int lwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_dspgvd_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, double* ap, double* bp,
+ double* w, double* z, lapack_int ldz,
+ double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_sspgvx_work( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n, float* ap,
+ float* bp, float vl, float vu, lapack_int il,
+ lapack_int iu, float abstol, lapack_int* m,
+ float* w, float* z, lapack_int ldz, float* work,
+ lapack_int* iwork, lapack_int* ifail );
+lapack_int LAPACKE_dspgvx_work( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n, double* ap,
+ double* bp, double vl, double vu, lapack_int il,
+ lapack_int iu, double abstol, lapack_int* m,
+ double* w, double* z, lapack_int ldz,
+ double* work, lapack_int* iwork,
+ lapack_int* ifail );
+
+lapack_int LAPACKE_ssprfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* ap,
+ const float* afp, const lapack_int* ipiv,
+ const float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* ferr, float* berr,
+ float* work, lapack_int* iwork );
+lapack_int LAPACKE_dsprfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* ap,
+ const double* afp, const lapack_int* ipiv,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* ferr, double* berr,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_csprfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ const lapack_complex_float* afp,
+ const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zsprfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* afp,
+ const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_sspsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, float* ap, lapack_int* ipiv,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dspsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, double* ap, lapack_int* ipiv,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_cspsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* ap,
+ lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zspsv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* ap,
+ lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_sspsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, const float* ap,
+ float* afp, lapack_int* ipiv, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ float* work, lapack_int* iwork );
+lapack_int LAPACKE_dspsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, const double* ap,
+ double* afp, lapack_int* ipiv, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_cspsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* ap,
+ lapack_complex_float* afp, lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zspsvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* ap,
+ lapack_complex_double* afp, lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_ssptrd_work( int matrix_order, char uplo, lapack_int n,
+ float* ap, float* d, float* e, float* tau );
+lapack_int LAPACKE_dsptrd_work( int matrix_order, char uplo, lapack_int n,
+ double* ap, double* d, double* e, double* tau );
+
+lapack_int LAPACKE_ssptrf_work( int matrix_order, char uplo, lapack_int n,
+ float* ap, lapack_int* ipiv );
+lapack_int LAPACKE_dsptrf_work( int matrix_order, char uplo, lapack_int n,
+ double* ap, lapack_int* ipiv );
+lapack_int LAPACKE_csptrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap, lapack_int* ipiv );
+lapack_int LAPACKE_zsptrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap, lapack_int* ipiv );
+
+lapack_int LAPACKE_ssptri_work( int matrix_order, char uplo, lapack_int n,
+ float* ap, const lapack_int* ipiv,
+ float* work );
+lapack_int LAPACKE_dsptri_work( int matrix_order, char uplo, lapack_int n,
+ double* ap, const lapack_int* ipiv,
+ double* work );
+lapack_int LAPACKE_csptri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* ap,
+ const lapack_int* ipiv,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zsptri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* ap,
+ const lapack_int* ipiv,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_ssptrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* ap,
+ const lapack_int* ipiv, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dsptrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* ap,
+ const lapack_int* ipiv, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_csptrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* ap,
+ const lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_zsptrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs,
+ const lapack_complex_double* ap,
+ const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_sstebz_work( char range, char order, lapack_int n, float vl,
+ float vu, lapack_int il, lapack_int iu,
+ float abstol, const float* d, const float* e,
+ lapack_int* m, lapack_int* nsplit, float* w,
+ lapack_int* iblock, lapack_int* isplit,
+ float* work, lapack_int* iwork );
+lapack_int LAPACKE_dstebz_work( char range, char order, lapack_int n, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, const double* d, const double* e,
+ lapack_int* m, lapack_int* nsplit, double* w,
+ lapack_int* iblock, lapack_int* isplit,
+ double* work, lapack_int* iwork );
+
+lapack_int LAPACKE_sstedc_work( int matrix_order, char compz, lapack_int n,
+ float* d, float* e, float* z, lapack_int ldz,
+ float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_dstedc_work( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, double* z, lapack_int ldz,
+ double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_cstedc_work( int matrix_order, char compz, lapack_int n,
+ float* d, float* e, lapack_complex_float* z,
+ lapack_int ldz, lapack_complex_float* work,
+ lapack_int lwork, float* rwork,
+ lapack_int lrwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_zstedc_work( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, lapack_complex_double* z,
+ lapack_int ldz, lapack_complex_double* work,
+ lapack_int lwork, double* rwork,
+ lapack_int lrwork, lapack_int* iwork,
+ lapack_int liwork );
+
+lapack_int LAPACKE_sstegr_work( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl,
+ float vu, lapack_int il, lapack_int iu,
+ float abstol, lapack_int* m, float* w, float* z,
+ lapack_int ldz, lapack_int* isuppz, float* work,
+ lapack_int lwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_dstegr_work( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w,
+ double* z, lapack_int ldz, lapack_int* isuppz,
+ double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_cstegr_work( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl,
+ float vu, lapack_int il, lapack_int iu,
+ float abstol, lapack_int* m, float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_int* isuppz, float* work,
+ lapack_int lwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_zstegr_work( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int* isuppz, double* work,
+ lapack_int lwork, lapack_int* iwork,
+ lapack_int liwork );
+
+lapack_int LAPACKE_sstein_work( int matrix_order, lapack_int n, const float* d,
+ const float* e, lapack_int m, const float* w,
+ const lapack_int* iblock,
+ const lapack_int* isplit, float* z,
+ lapack_int ldz, float* work, lapack_int* iwork,
+ lapack_int* ifailv );
+lapack_int LAPACKE_dstein_work( int matrix_order, lapack_int n, const double* d,
+ const double* e, lapack_int m, const double* w,
+ const lapack_int* iblock,
+ const lapack_int* isplit, double* z,
+ lapack_int ldz, double* work, lapack_int* iwork,
+ lapack_int* ifailv );
+lapack_int LAPACKE_cstein_work( int matrix_order, lapack_int n, const float* d,
+ const float* e, lapack_int m, const float* w,
+ const lapack_int* iblock,
+ const lapack_int* isplit,
+ lapack_complex_float* z, lapack_int ldz,
+ float* work, lapack_int* iwork,
+ lapack_int* ifailv );
+lapack_int LAPACKE_zstein_work( int matrix_order, lapack_int n, const double* d,
+ const double* e, lapack_int m, const double* w,
+ const lapack_int* iblock,
+ const lapack_int* isplit,
+ lapack_complex_double* z, lapack_int ldz,
+ double* work, lapack_int* iwork,
+ lapack_int* ifailv );
+
+lapack_int LAPACKE_sstemr_work( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl,
+ float vu, lapack_int il, lapack_int iu,
+ lapack_int* m, float* w, float* z,
+ lapack_int ldz, lapack_int nzc,
+ lapack_int* isuppz, lapack_logical* tryrac,
+ float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_dstemr_work( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ lapack_int* m, double* w, double* z,
+ lapack_int ldz, lapack_int nzc,
+ lapack_int* isuppz, lapack_logical* tryrac,
+ double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_cstemr_work( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl,
+ float vu, lapack_int il, lapack_int iu,
+ lapack_int* m, float* w,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_int nzc, lapack_int* isuppz,
+ lapack_logical* tryrac, float* work,
+ lapack_int lwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_zstemr_work( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int nzc, lapack_int* isuppz,
+ lapack_logical* tryrac, double* work,
+ lapack_int lwork, lapack_int* iwork,
+ lapack_int liwork );
+
+lapack_int LAPACKE_ssteqr_work( int matrix_order, char compz, lapack_int n,
+ float* d, float* e, float* z, lapack_int ldz,
+ float* work );
+lapack_int LAPACKE_dsteqr_work( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, double* z, lapack_int ldz,
+ double* work );
+lapack_int LAPACKE_csteqr_work( int matrix_order, char compz, lapack_int n,
+ float* d, float* e, lapack_complex_float* z,
+ lapack_int ldz, float* work );
+lapack_int LAPACKE_zsteqr_work( int matrix_order, char compz, lapack_int n,
+ double* d, double* e, lapack_complex_double* z,
+ lapack_int ldz, double* work );
+
+lapack_int LAPACKE_ssterf_work( lapack_int n, float* d, float* e );
+lapack_int LAPACKE_dsterf_work( lapack_int n, double* d, double* e );
+
+lapack_int LAPACKE_sstev_work( int matrix_order, char jobz, lapack_int n,
+ float* d, float* e, float* z, lapack_int ldz,
+ float* work );
+lapack_int LAPACKE_dstev_work( int matrix_order, char jobz, lapack_int n,
+ double* d, double* e, double* z, lapack_int ldz,
+ double* work );
+
+lapack_int LAPACKE_sstevd_work( int matrix_order, char jobz, lapack_int n,
+ float* d, float* e, float* z, lapack_int ldz,
+ float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_dstevd_work( int matrix_order, char jobz, lapack_int n,
+ double* d, double* e, double* z, lapack_int ldz,
+ double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_sstevr_work( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl,
+ float vu, lapack_int il, lapack_int iu,
+ float abstol, lapack_int* m, float* w, float* z,
+ lapack_int ldz, lapack_int* isuppz, float* work,
+ lapack_int lwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_dstevr_work( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w,
+ double* z, lapack_int ldz, lapack_int* isuppz,
+ double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_sstevx_work( int matrix_order, char jobz, char range,
+ lapack_int n, float* d, float* e, float vl,
+ float vu, lapack_int il, lapack_int iu,
+ float abstol, lapack_int* m, float* w, float* z,
+ lapack_int ldz, float* work, lapack_int* iwork,
+ lapack_int* ifail );
+lapack_int LAPACKE_dstevx_work( int matrix_order, char jobz, char range,
+ lapack_int n, double* d, double* e, double vl,
+ double vu, lapack_int il, lapack_int iu,
+ double abstol, lapack_int* m, double* w,
+ double* z, lapack_int ldz, double* work,
+ lapack_int* iwork, lapack_int* ifail );
+
+lapack_int LAPACKE_ssycon_work( int matrix_order, char uplo, lapack_int n,
+ const float* a, lapack_int lda,
+ const lapack_int* ipiv, float anorm,
+ float* rcond, float* work, lapack_int* iwork );
+lapack_int LAPACKE_dsycon_work( int matrix_order, char uplo, lapack_int n,
+ const double* a, lapack_int lda,
+ const lapack_int* ipiv, double anorm,
+ double* rcond, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_csycon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv, float anorm,
+ float* rcond, lapack_complex_float* work );
+lapack_int LAPACKE_zsycon_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv, double anorm,
+ double* rcond, lapack_complex_double* work );
+
+lapack_int LAPACKE_ssyequb_work( int matrix_order, char uplo, lapack_int n,
+ const float* a, lapack_int lda, float* s,
+ float* scond, float* amax, float* work );
+lapack_int LAPACKE_dsyequb_work( int matrix_order, char uplo, lapack_int n,
+ const double* a, lapack_int lda, double* s,
+ double* scond, double* amax, double* work );
+lapack_int LAPACKE_csyequb_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* s, float* scond, float* amax,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zsyequb_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* s, double* scond, double* amax,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_ssyev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, float* a, lapack_int lda, float* w,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dsyev_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, double* a, lapack_int lda,
+ double* w, double* work, lapack_int lwork );
+
+lapack_int LAPACKE_ssyevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, float* a, lapack_int lda,
+ float* w, float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_dsyevd_work( int matrix_order, char jobz, char uplo,
+ lapack_int n, double* a, lapack_int lda,
+ double* w, double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_ssyevr_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, float* a,
+ lapack_int lda, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z,
+ lapack_int ldz, lapack_int* isuppz, float* work,
+ lapack_int lwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_dsyevr_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, double* a,
+ lapack_int lda, double vl, double vu,
+ lapack_int il, lapack_int iu, double abstol,
+ lapack_int* m, double* w, double* z,
+ lapack_int ldz, lapack_int* isuppz,
+ double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_ssyevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, float* a,
+ lapack_int lda, float vl, float vu,
+ lapack_int il, lapack_int iu, float abstol,
+ lapack_int* m, float* w, float* z,
+ lapack_int ldz, float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int* ifail );
+lapack_int LAPACKE_dsyevx_work( int matrix_order, char jobz, char range,
+ char uplo, lapack_int n, double* a,
+ lapack_int lda, double vl, double vu,
+ lapack_int il, lapack_int iu, double abstol,
+ lapack_int* m, double* w, double* z,
+ lapack_int ldz, double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int* ifail );
+
+lapack_int LAPACKE_ssygst_work( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, float* a, lapack_int lda,
+ const float* b, lapack_int ldb );
+lapack_int LAPACKE_dsygst_work( int matrix_order, lapack_int itype, char uplo,
+ lapack_int n, double* a, lapack_int lda,
+ const double* b, lapack_int ldb );
+
+lapack_int LAPACKE_ssygv_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb,
+ float* w, float* work, lapack_int lwork );
+lapack_int LAPACKE_dsygv_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ double* w, double* work, lapack_int lwork );
+
+lapack_int LAPACKE_ssygvd_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb,
+ float* w, float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_dsygvd_work( int matrix_order, lapack_int itype, char jobz,
+ char uplo, lapack_int n, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ double* w, double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+
+lapack_int LAPACKE_ssygvx_work( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb,
+ float vl, float vu, lapack_int il,
+ lapack_int iu, float abstol, lapack_int* m,
+ float* w, float* z, lapack_int ldz, float* work,
+ lapack_int lwork, lapack_int* iwork,
+ lapack_int* ifail );
+lapack_int LAPACKE_dsygvx_work( int matrix_order, lapack_int itype, char jobz,
+ char range, char uplo, lapack_int n, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ double vl, double vu, lapack_int il,
+ lapack_int iu, double abstol, lapack_int* m,
+ double* w, double* z, lapack_int ldz,
+ double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int* ifail );
+
+lapack_int LAPACKE_ssyrfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ const float* af, lapack_int ldaf,
+ const lapack_int* ipiv, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* ferr, float* berr, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dsyrfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* a,
+ lapack_int lda, const double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* ferr, double* berr,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_csyrfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_zsyrfs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_complex_double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_ssyrfsx_work( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs, const float* a,
+ lapack_int lda, const float* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const float* s, const float* b, lapack_int ldb,
+ float* x, lapack_int ldx, float* rcond,
+ float* berr, lapack_int n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int nparams, float* params, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dsyrfsx_work( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs, const double* a,
+ lapack_int lda, const double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const double* s, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_csyrfsx_work( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const float* s, const lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zsyrfsx_work( int matrix_order, char uplo, char equed,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* af,
+ lapack_int ldaf, const lapack_int* ipiv,
+ const double* s,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_ssysv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, float* a, lapack_int lda,
+ lapack_int* ipiv, float* b, lapack_int ldb,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dsysv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, double* a, lapack_int lda,
+ lapack_int* ipiv, double* b, lapack_int ldb,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_csysv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_float* a,
+ lapack_int lda, lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zsysv_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, lapack_complex_double* a,
+ lapack_int lda, lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_ssysvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, const float* a,
+ lapack_int lda, float* af, lapack_int ldaf,
+ lapack_int* ipiv, const float* b,
+ lapack_int ldb, float* x, lapack_int ldx,
+ float* rcond, float* ferr, float* berr,
+ float* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_dsysvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, const double* a,
+ lapack_int lda, double* af, lapack_int ldaf,
+ lapack_int* ipiv, const double* b,
+ lapack_int ldb, double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ double* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_csysvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ lapack_int* ipiv, const lapack_complex_float* b,
+ lapack_int ldb, lapack_complex_float* x,
+ lapack_int ldx, float* rcond, float* ferr,
+ float* berr, lapack_complex_float* work,
+ lapack_int lwork, float* rwork );
+lapack_int LAPACKE_zsysvx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork );
+
+lapack_int LAPACKE_ssysvxx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, float* a,
+ lapack_int lda, float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* s,
+ float* b, lapack_int ldb, float* x,
+ lapack_int ldx, float* rcond, float* rpvgrw,
+ float* berr, lapack_int n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int nparams, float* params, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dsysvxx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs, double* a,
+ lapack_int lda, double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* s,
+ double* b, lapack_int ldb, double* x,
+ lapack_int ldx, double* rcond, double* rpvgrw,
+ double* berr, lapack_int n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int nparams, double* params,
+ double* work, lapack_int* iwork );
+lapack_int LAPACKE_csysvxx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, float* s,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* x, lapack_int ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int nparams,
+ float* params, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_zsysvxx_work( int matrix_order, char fact, char uplo,
+ lapack_int n, lapack_int nrhs,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* af, lapack_int ldaf,
+ lapack_int* ipiv, char* equed, double* s,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* x, lapack_int ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int nparams,
+ double* params, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_ssytrd_work( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int lda, float* d, float* e,
+ float* tau, float* work, lapack_int lwork );
+lapack_int LAPACKE_dsytrd_work( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda, double* d, double* e,
+ double* tau, double* work, lapack_int lwork );
+
+lapack_int LAPACKE_ssytrf_work( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int lda, lapack_int* ipiv,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dsytrf_work( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda, lapack_int* ipiv,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_csytrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_int* ipiv, lapack_complex_float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_zsytrf_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_int* ipiv, lapack_complex_double* work,
+ lapack_int lwork );
+
+lapack_int LAPACKE_ssytri_work( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int lda,
+ const lapack_int* ipiv, float* work );
+lapack_int LAPACKE_dsytri_work( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda,
+ const lapack_int* ipiv, double* work );
+lapack_int LAPACKE_csytri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zsytri_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_ssytrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ const lapack_int* ipiv, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dsytrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_csytrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_zsytrs_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_stbcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n, lapack_int kd,
+ const float* ab, lapack_int ldab, float* rcond,
+ float* work, lapack_int* iwork );
+lapack_int LAPACKE_dtbcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n, lapack_int kd,
+ const double* ab, lapack_int ldab,
+ double* rcond, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_ctbcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n, lapack_int kd,
+ const lapack_complex_float* ab, lapack_int ldab,
+ float* rcond, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_ztbcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n, lapack_int kd,
+ const lapack_complex_double* ab,
+ lapack_int ldab, double* rcond,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_stbrfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int kd,
+ lapack_int nrhs, const float* ab,
+ lapack_int ldab, const float* b, lapack_int ldb,
+ const float* x, lapack_int ldx, float* ferr,
+ float* berr, float* work, lapack_int* iwork );
+lapack_int LAPACKE_dtbrfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int kd,
+ lapack_int nrhs, const double* ab,
+ lapack_int ldab, const double* b,
+ lapack_int ldb, const double* x, lapack_int ldx,
+ double* ferr, double* berr, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_ctbrfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int kd,
+ lapack_int nrhs, const lapack_complex_float* ab,
+ lapack_int ldab, const lapack_complex_float* b,
+ lapack_int ldb, const lapack_complex_float* x,
+ lapack_int ldx, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_ztbrfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int kd,
+ lapack_int nrhs,
+ const lapack_complex_double* ab,
+ lapack_int ldab, const lapack_complex_double* b,
+ lapack_int ldb, const lapack_complex_double* x,
+ lapack_int ldx, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_stbtrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int kd,
+ lapack_int nrhs, const float* ab,
+ lapack_int ldab, float* b, lapack_int ldb );
+lapack_int LAPACKE_dtbtrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int kd,
+ lapack_int nrhs, const double* ab,
+ lapack_int ldab, double* b, lapack_int ldb );
+lapack_int LAPACKE_ctbtrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int kd,
+ lapack_int nrhs, const lapack_complex_float* ab,
+ lapack_int ldab, lapack_complex_float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_ztbtrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int kd,
+ lapack_int nrhs,
+ const lapack_complex_double* ab,
+ lapack_int ldab, lapack_complex_double* b,
+ lapack_int ldb );
+
+lapack_int LAPACKE_stfsm_work( int matrix_order, char transr, char side,
+ char uplo, char trans, char diag, lapack_int m,
+ lapack_int n, float alpha, const float* a,
+ float* b, lapack_int ldb );
+lapack_int LAPACKE_dtfsm_work( int matrix_order, char transr, char side,
+ char uplo, char trans, char diag, lapack_int m,
+ lapack_int n, double alpha, const double* a,
+ double* b, lapack_int ldb );
+lapack_int LAPACKE_ctfsm_work( int matrix_order, char transr, char side,
+ char uplo, char trans, char diag, lapack_int m,
+ lapack_int n, lapack_complex_float alpha,
+ const lapack_complex_float* a,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_ztfsm_work( int matrix_order, char transr, char side,
+ char uplo, char trans, char diag, lapack_int m,
+ lapack_int n, lapack_complex_double alpha,
+ const lapack_complex_double* a,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_stftri_work( int matrix_order, char transr, char uplo,
+ char diag, lapack_int n, float* a );
+lapack_int LAPACKE_dtftri_work( int matrix_order, char transr, char uplo,
+ char diag, lapack_int n, double* a );
+lapack_int LAPACKE_ctftri_work( int matrix_order, char transr, char uplo,
+ char diag, lapack_int n,
+ lapack_complex_float* a );
+lapack_int LAPACKE_ztftri_work( int matrix_order, char transr, char uplo,
+ char diag, lapack_int n,
+ lapack_complex_double* a );
+
+lapack_int LAPACKE_stfttp_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const float* arf, float* ap );
+lapack_int LAPACKE_dtfttp_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const double* arf, double* ap );
+lapack_int LAPACKE_ctfttp_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_float* arf,
+ lapack_complex_float* ap );
+lapack_int LAPACKE_ztfttp_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_double* arf,
+ lapack_complex_double* ap );
+
+lapack_int LAPACKE_stfttr_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const float* arf, float* a,
+ lapack_int lda );
+lapack_int LAPACKE_dtfttr_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const double* arf, double* a,
+ lapack_int lda );
+lapack_int LAPACKE_ctfttr_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_float* arf,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_ztfttr_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_double* arf,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_stgevc_work( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const float* s, lapack_int lds, const float* p,
+ lapack_int ldp, float* vl, lapack_int ldvl,
+ float* vr, lapack_int ldvr, lapack_int mm,
+ lapack_int* m, float* work );
+lapack_int LAPACKE_dtgevc_work( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const double* s, lapack_int lds,
+ const double* p, lapack_int ldp, double* vl,
+ lapack_int ldvl, double* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m, double* work );
+lapack_int LAPACKE_ctgevc_work( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_float* s, lapack_int lds,
+ const lapack_complex_float* p, lapack_int ldp,
+ lapack_complex_float* vl, lapack_int ldvl,
+ lapack_complex_float* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_ztgevc_work( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_double* s, lapack_int lds,
+ const lapack_complex_double* p, lapack_int ldp,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_stgexc_work( int matrix_order, lapack_logical wantq,
+ lapack_logical wantz, lapack_int n, float* a,
+ lapack_int lda, float* b, lapack_int ldb,
+ float* q, lapack_int ldq, float* z,
+ lapack_int ldz, lapack_int* ifst,
+ lapack_int* ilst, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dtgexc_work( int matrix_order, lapack_logical wantq,
+ lapack_logical wantz, lapack_int n, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ double* q, lapack_int ldq, double* z,
+ lapack_int ldz, lapack_int* ifst,
+ lapack_int* ilst, double* work,
+ lapack_int lwork );
+lapack_int LAPACKE_ctgexc_work( int matrix_order, lapack_logical wantq,
+ lapack_logical wantz, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_int ifst, lapack_int ilst );
+lapack_int LAPACKE_ztgexc_work( int matrix_order, lapack_logical wantq,
+ lapack_logical wantz, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int ifst, lapack_int ilst );
+
+lapack_int LAPACKE_stgsen_work( int matrix_order, lapack_int ijob,
+ lapack_logical wantq, lapack_logical wantz,
+ const lapack_logical* select, lapack_int n,
+ float* a, lapack_int lda, float* b,
+ lapack_int ldb, float* alphar, float* alphai,
+ float* beta, float* q, lapack_int ldq, float* z,
+ lapack_int ldz, lapack_int* m, float* pl,
+ float* pr, float* dif, float* work,
+ lapack_int lwork, lapack_int* iwork,
+ lapack_int liwork );
+lapack_int LAPACKE_dtgsen_work( int matrix_order, lapack_int ijob,
+ lapack_logical wantq, lapack_logical wantz,
+ const lapack_logical* select, lapack_int n,
+ double* a, lapack_int lda, double* b,
+ lapack_int ldb, double* alphar, double* alphai,
+ double* beta, double* q, lapack_int ldq,
+ double* z, lapack_int ldz, lapack_int* m,
+ double* pl, double* pr, double* dif,
+ double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_ctgsen_work( int matrix_order, lapack_int ijob,
+ lapack_logical wantq, lapack_logical wantz,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* alpha,
+ lapack_complex_float* beta,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* z, lapack_int ldz,
+ lapack_int* m, float* pl, float* pr, float* dif,
+ lapack_complex_float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_ztgsen_work( int matrix_order, lapack_int ijob,
+ lapack_logical wantq, lapack_logical wantz,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* alpha,
+ lapack_complex_double* beta,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* z, lapack_int ldz,
+ lapack_int* m, double* pl, double* pr,
+ double* dif, lapack_complex_double* work,
+ lapack_int lwork, lapack_int* iwork,
+ lapack_int liwork );
+
+lapack_int LAPACKE_stgsja_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int p,
+ lapack_int n, lapack_int k, lapack_int l,
+ float* a, lapack_int lda, float* b,
+ lapack_int ldb, float tola, float tolb,
+ float* alpha, float* beta, float* u,
+ lapack_int ldu, float* v, lapack_int ldv,
+ float* q, lapack_int ldq, float* work,
+ lapack_int* ncycle );
+lapack_int LAPACKE_dtgsja_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int p,
+ lapack_int n, lapack_int k, lapack_int l,
+ double* a, lapack_int lda, double* b,
+ lapack_int ldb, double tola, double tolb,
+ double* alpha, double* beta, double* u,
+ lapack_int ldu, double* v, lapack_int ldv,
+ double* q, lapack_int ldq, double* work,
+ lapack_int* ncycle );
+lapack_int LAPACKE_ctgsja_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int p,
+ lapack_int n, lapack_int k, lapack_int l,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ float tola, float tolb, float* alpha,
+ float* beta, lapack_complex_float* u,
+ lapack_int ldu, lapack_complex_float* v,
+ lapack_int ldv, lapack_complex_float* q,
+ lapack_int ldq, lapack_complex_float* work,
+ lapack_int* ncycle );
+lapack_int LAPACKE_ztgsja_work( int matrix_order, char jobu, char jobv,
+ char jobq, lapack_int m, lapack_int p,
+ lapack_int n, lapack_int k, lapack_int l,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ double tola, double tolb, double* alpha,
+ double* beta, lapack_complex_double* u,
+ lapack_int ldu, lapack_complex_double* v,
+ lapack_int ldv, lapack_complex_double* q,
+ lapack_int ldq, lapack_complex_double* work,
+ lapack_int* ncycle );
+
+lapack_int LAPACKE_stgsna_work( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const float* a, lapack_int lda, const float* b,
+ lapack_int ldb, const float* vl,
+ lapack_int ldvl, const float* vr,
+ lapack_int ldvr, float* s, float* dif,
+ lapack_int mm, lapack_int* m, float* work,
+ lapack_int lwork, lapack_int* iwork );
+lapack_int LAPACKE_dtgsna_work( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const double* a, lapack_int lda,
+ const double* b, lapack_int ldb,
+ const double* vl, lapack_int ldvl,
+ const double* vr, lapack_int ldvr, double* s,
+ double* dif, lapack_int mm, lapack_int* m,
+ double* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_ctgsna_work( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* b, lapack_int ldb,
+ const lapack_complex_float* vl, lapack_int ldvl,
+ const lapack_complex_float* vr, lapack_int ldvr,
+ float* s, float* dif, lapack_int mm,
+ lapack_int* m, lapack_complex_float* work,
+ lapack_int lwork, lapack_int* iwork );
+lapack_int LAPACKE_ztgsna_work( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* b, lapack_int ldb,
+ const lapack_complex_double* vl,
+ lapack_int ldvl,
+ const lapack_complex_double* vr,
+ lapack_int ldvr, double* s, double* dif,
+ lapack_int mm, lapack_int* m,
+ lapack_complex_double* work, lapack_int lwork,
+ lapack_int* iwork );
+
+lapack_int LAPACKE_stgsyl_work( int matrix_order, char trans, lapack_int ijob,
+ lapack_int m, lapack_int n, const float* a,
+ lapack_int lda, const float* b, lapack_int ldb,
+ float* c, lapack_int ldc, const float* d,
+ lapack_int ldd, const float* e, lapack_int lde,
+ float* f, lapack_int ldf, float* scale,
+ float* dif, float* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_dtgsyl_work( int matrix_order, char trans, lapack_int ijob,
+ lapack_int m, lapack_int n, const double* a,
+ lapack_int lda, const double* b, lapack_int ldb,
+ double* c, lapack_int ldc, const double* d,
+ lapack_int ldd, const double* e, lapack_int lde,
+ double* f, lapack_int ldf, double* scale,
+ double* dif, double* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_ctgsyl_work( int matrix_order, char trans, lapack_int ijob,
+ lapack_int m, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* c, lapack_int ldc,
+ const lapack_complex_float* d, lapack_int ldd,
+ const lapack_complex_float* e, lapack_int lde,
+ lapack_complex_float* f, lapack_int ldf,
+ float* scale, float* dif,
+ lapack_complex_float* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_ztgsyl_work( int matrix_order, char trans, lapack_int ijob,
+ lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* c, lapack_int ldc,
+ const lapack_complex_double* d, lapack_int ldd,
+ const lapack_complex_double* e, lapack_int lde,
+ lapack_complex_double* f, lapack_int ldf,
+ double* scale, double* dif,
+ lapack_complex_double* work, lapack_int lwork,
+ lapack_int* iwork );
+
+lapack_int LAPACKE_stpcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n, const float* ap,
+ float* rcond, float* work, lapack_int* iwork );
+lapack_int LAPACKE_dtpcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n, const double* ap,
+ double* rcond, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_ctpcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n,
+ const lapack_complex_float* ap, float* rcond,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_ztpcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n,
+ const lapack_complex_double* ap, double* rcond,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_stprfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const float* ap, const float* b, lapack_int ldb,
+ const float* x, lapack_int ldx, float* ferr,
+ float* berr, float* work, lapack_int* iwork );
+lapack_int LAPACKE_dtprfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const double* ap, const double* b,
+ lapack_int ldb, const double* x, lapack_int ldx,
+ double* ferr, double* berr, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_ctprfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* ap,
+ const lapack_complex_float* b, lapack_int ldb,
+ const lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_ztprfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* b, lapack_int ldb,
+ const lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_stptri_work( int matrix_order, char uplo, char diag,
+ lapack_int n, float* ap );
+lapack_int LAPACKE_dtptri_work( int matrix_order, char uplo, char diag,
+ lapack_int n, double* ap );
+lapack_int LAPACKE_ctptri_work( int matrix_order, char uplo, char diag,
+ lapack_int n, lapack_complex_float* ap );
+lapack_int LAPACKE_ztptri_work( int matrix_order, char uplo, char diag,
+ lapack_int n, lapack_complex_double* ap );
+
+lapack_int LAPACKE_stptrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const float* ap, float* b, lapack_int ldb );
+lapack_int LAPACKE_dtptrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const double* ap, double* b, lapack_int ldb );
+lapack_int LAPACKE_ctptrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* ap,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_ztptrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* ap,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_stpttf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const float* ap, float* arf );
+lapack_int LAPACKE_dtpttf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const double* ap, double* arf );
+lapack_int LAPACKE_ctpttf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_float* ap,
+ lapack_complex_float* arf );
+lapack_int LAPACKE_ztpttf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_double* ap,
+ lapack_complex_double* arf );
+
+lapack_int LAPACKE_stpttr_work( int matrix_order, char uplo, lapack_int n,
+ const float* ap, float* a, lapack_int lda );
+lapack_int LAPACKE_dtpttr_work( int matrix_order, char uplo, lapack_int n,
+ const double* ap, double* a, lapack_int lda );
+lapack_int LAPACKE_ctpttr_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_ztpttr_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_strcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n, const float* a,
+ lapack_int lda, float* rcond, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dtrcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n, const double* a,
+ lapack_int lda, double* rcond, double* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_ctrcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ float* rcond, lapack_complex_float* work,
+ float* rwork );
+lapack_int LAPACKE_ztrcon_work( int matrix_order, char norm, char uplo,
+ char diag, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ double* rcond, lapack_complex_double* work,
+ double* rwork );
+
+lapack_int LAPACKE_strevc_work( int matrix_order, char side, char howmny,
+ lapack_logical* select, lapack_int n,
+ const float* t, lapack_int ldt, float* vl,
+ lapack_int ldvl, float* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m, float* work );
+lapack_int LAPACKE_dtrevc_work( int matrix_order, char side, char howmny,
+ lapack_logical* select, lapack_int n,
+ const double* t, lapack_int ldt, double* vl,
+ lapack_int ldvl, double* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m, double* work );
+lapack_int LAPACKE_ctrevc_work( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* vl, lapack_int ldvl,
+ lapack_complex_float* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_ztrevc_work( int matrix_order, char side, char howmny,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* vl, lapack_int ldvl,
+ lapack_complex_double* vr, lapack_int ldvr,
+ lapack_int mm, lapack_int* m,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_strexc_work( int matrix_order, char compq, lapack_int n,
+ float* t, lapack_int ldt, float* q,
+ lapack_int ldq, lapack_int* ifst,
+ lapack_int* ilst, float* work );
+lapack_int LAPACKE_dtrexc_work( int matrix_order, char compq, lapack_int n,
+ double* t, lapack_int ldt, double* q,
+ lapack_int ldq, lapack_int* ifst,
+ lapack_int* ilst, double* work );
+lapack_int LAPACKE_ctrexc_work( int matrix_order, char compq, lapack_int n,
+ lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_int ifst, lapack_int ilst );
+lapack_int LAPACKE_ztrexc_work( int matrix_order, char compq, lapack_int n,
+ lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_int ifst, lapack_int ilst );
+
+lapack_int LAPACKE_strrfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const float* a, lapack_int lda, const float* b,
+ lapack_int ldb, const float* x, lapack_int ldx,
+ float* ferr, float* berr, float* work,
+ lapack_int* iwork );
+lapack_int LAPACKE_dtrrfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const double* a, lapack_int lda,
+ const double* b, lapack_int ldb,
+ const double* x, lapack_int ldx, double* ferr,
+ double* berr, double* work, lapack_int* iwork );
+lapack_int LAPACKE_ctrrfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* b, lapack_int ldb,
+ const lapack_complex_float* x, lapack_int ldx,
+ float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork );
+lapack_int LAPACKE_ztrrfs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* b, lapack_int ldb,
+ const lapack_complex_double* x, lapack_int ldx,
+ double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork );
+
+lapack_int LAPACKE_strsen_work( int matrix_order, char job, char compq,
+ const lapack_logical* select, lapack_int n,
+ float* t, lapack_int ldt, float* q,
+ lapack_int ldq, float* wr, float* wi,
+ lapack_int* m, float* s, float* sep,
+ float* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_dtrsen_work( int matrix_order, char job, char compq,
+ const lapack_logical* select, lapack_int n,
+ double* t, lapack_int ldt, double* q,
+ lapack_int ldq, double* wr, double* wi,
+ lapack_int* m, double* s, double* sep,
+ double* work, lapack_int lwork,
+ lapack_int* iwork, lapack_int liwork );
+lapack_int LAPACKE_ctrsen_work( int matrix_order, char job, char compq,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* w, lapack_int* m,
+ float* s, float* sep,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_ztrsen_work( int matrix_order, char job, char compq,
+ const lapack_logical* select, lapack_int n,
+ lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* w, lapack_int* m,
+ double* s, double* sep,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_strsna_work( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const float* t, lapack_int ldt, const float* vl,
+ lapack_int ldvl, const float* vr,
+ lapack_int ldvr, float* s, float* sep,
+ lapack_int mm, lapack_int* m, float* work,
+ lapack_int ldwork, lapack_int* iwork );
+lapack_int LAPACKE_dtrsna_work( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const double* t, lapack_int ldt,
+ const double* vl, lapack_int ldvl,
+ const double* vr, lapack_int ldvr, double* s,
+ double* sep, lapack_int mm, lapack_int* m,
+ double* work, lapack_int ldwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_ctrsna_work( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_float* t, lapack_int ldt,
+ const lapack_complex_float* vl, lapack_int ldvl,
+ const lapack_complex_float* vr, lapack_int ldvr,
+ float* s, float* sep, lapack_int mm,
+ lapack_int* m, lapack_complex_float* work,
+ lapack_int ldwork, float* rwork );
+lapack_int LAPACKE_ztrsna_work( int matrix_order, char job, char howmny,
+ const lapack_logical* select, lapack_int n,
+ const lapack_complex_double* t, lapack_int ldt,
+ const lapack_complex_double* vl,
+ lapack_int ldvl,
+ const lapack_complex_double* vr,
+ lapack_int ldvr, double* s, double* sep,
+ lapack_int mm, lapack_int* m,
+ lapack_complex_double* work, lapack_int ldwork,
+ double* rwork );
+
+lapack_int LAPACKE_strsyl_work( int matrix_order, char trana, char tranb,
+ lapack_int isgn, lapack_int m, lapack_int n,
+ const float* a, lapack_int lda, const float* b,
+ lapack_int ldb, float* c, lapack_int ldc,
+ float* scale );
+lapack_int LAPACKE_dtrsyl_work( int matrix_order, char trana, char tranb,
+ lapack_int isgn, lapack_int m, lapack_int n,
+ const double* a, lapack_int lda,
+ const double* b, lapack_int ldb, double* c,
+ lapack_int ldc, double* scale );
+lapack_int LAPACKE_ctrsyl_work( int matrix_order, char trana, char tranb,
+ lapack_int isgn, lapack_int m, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* c, lapack_int ldc,
+ float* scale );
+lapack_int LAPACKE_ztrsyl_work( int matrix_order, char trana, char tranb,
+ lapack_int isgn, lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* c, lapack_int ldc,
+ double* scale );
+
+lapack_int LAPACKE_strtri_work( int matrix_order, char uplo, char diag,
+ lapack_int n, float* a, lapack_int lda );
+lapack_int LAPACKE_dtrtri_work( int matrix_order, char uplo, char diag,
+ lapack_int n, double* a, lapack_int lda );
+lapack_int LAPACKE_ctrtri_work( int matrix_order, char uplo, char diag,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda );
+lapack_int LAPACKE_ztrtri_work( int matrix_order, char uplo, char diag,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda );
+
+lapack_int LAPACKE_strtrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const float* a, lapack_int lda, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dtrtrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const double* a, lapack_int lda, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_ctrtrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_ztrtrs_work( int matrix_order, char uplo, char trans,
+ char diag, lapack_int n, lapack_int nrhs,
+ const lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_strttf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const float* a, lapack_int lda,
+ float* arf );
+lapack_int LAPACKE_dtrttf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const double* a, lapack_int lda,
+ double* arf );
+lapack_int LAPACKE_ctrttf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* arf );
+lapack_int LAPACKE_ztrttf_work( int matrix_order, char transr, char uplo,
+ lapack_int n, const lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* arf );
+
+lapack_int LAPACKE_strttp_work( int matrix_order, char uplo, lapack_int n,
+ const float* a, lapack_int lda, float* ap );
+lapack_int LAPACKE_dtrttp_work( int matrix_order, char uplo, lapack_int n,
+ const double* a, lapack_int lda, double* ap );
+lapack_int LAPACKE_ctrttp_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* ap );
+lapack_int LAPACKE_ztrttp_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* ap );
+
+lapack_int LAPACKE_stzrzf_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* tau,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_dtzrzf_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* tau,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_ctzrzf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_ztzrzf_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cungbr_work( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int k,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zungbr_work( int matrix_order, char vect, lapack_int m,
+ lapack_int n, lapack_int k,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cunghr_work( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zunghr_work( int matrix_order, lapack_int n, lapack_int ilo,
+ lapack_int ihi, lapack_complex_double* a,
+ lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cunglq_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zunglq_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_double* a,
+ lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cungql_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zungql_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_double* a,
+ lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cungqr_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zungqr_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_double* a,
+ lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cungrq_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zungrq_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int k, lapack_complex_double* a,
+ lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cungtr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zungtr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cunmbr_work( int matrix_order, char vect, char side,
+ char trans, lapack_int m, lapack_int n,
+ lapack_int k, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zunmbr_work( int matrix_order, char vect, char side,
+ char trans, lapack_int m, lapack_int n,
+ lapack_int k, const lapack_complex_double* a,
+ lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cunmhr_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int ilo,
+ lapack_int ihi, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zunmhr_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int ilo,
+ lapack_int ihi, const lapack_complex_double* a,
+ lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cunmlq_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zunmlq_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cunmql_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zunmql_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cunmqr_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zunmqr_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cunmrq_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zunmrq_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cunmrz_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, const lapack_complex_float* a,
+ lapack_int lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zunmrz_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, const lapack_complex_double* a,
+ lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cunmtr_work( int matrix_order, char side, char uplo,
+ char trans, lapack_int m, lapack_int n,
+ const lapack_complex_float* a, lapack_int lda,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_zunmtr_work( int matrix_order, char side, char uplo,
+ char trans, lapack_int m, lapack_int n,
+ const lapack_complex_double* a, lapack_int lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work, lapack_int lwork );
+
+lapack_int LAPACKE_cupgtr_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_float* ap,
+ const lapack_complex_float* tau,
+ lapack_complex_float* q, lapack_int ldq,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zupgtr_work( int matrix_order, char uplo, lapack_int n,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* tau,
+ lapack_complex_double* q, lapack_int ldq,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_cupmtr_work( int matrix_order, char side, char uplo,
+ char trans, lapack_int m, lapack_int n,
+ const lapack_complex_float* ap,
+ const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int ldc,
+ lapack_complex_float* work );
+lapack_int LAPACKE_zupmtr_work( int matrix_order, char side, char uplo,
+ char trans, lapack_int m, lapack_int n,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int ldc,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_claghe( int matrix_order, lapack_int n, lapack_int k,
+ const float* d, lapack_complex_float* a,
+ lapack_int lda, lapack_int* iseed );
+lapack_int LAPACKE_zlaghe( int matrix_order, lapack_int n, lapack_int k,
+ const double* d, lapack_complex_double* a,
+ lapack_int lda, lapack_int* iseed );
+
+lapack_int LAPACKE_slagsy( int matrix_order, lapack_int n, lapack_int k,
+ const float* d, float* a, lapack_int lda,
+ lapack_int* iseed );
+lapack_int LAPACKE_dlagsy( int matrix_order, lapack_int n, lapack_int k,
+ const double* d, double* a, lapack_int lda,
+ lapack_int* iseed );
+lapack_int LAPACKE_clagsy( int matrix_order, lapack_int n, lapack_int k,
+ const float* d, lapack_complex_float* a,
+ lapack_int lda, lapack_int* iseed );
+lapack_int LAPACKE_zlagsy( int matrix_order, lapack_int n, lapack_int k,
+ const double* d, lapack_complex_double* a,
+ lapack_int lda, lapack_int* iseed );
+
+lapack_int LAPACKE_slapmr( int matrix_order, lapack_logical forwrd,
+ lapack_int m, lapack_int n, float* x, lapack_int ldx,
+ lapack_int* k );
+lapack_int LAPACKE_dlapmr( int matrix_order, lapack_logical forwrd,
+ lapack_int m, lapack_int n, double* x,
+ lapack_int ldx, lapack_int* k );
+lapack_int LAPACKE_clapmr( int matrix_order, lapack_logical forwrd,
+ lapack_int m, lapack_int n, lapack_complex_float* x,
+ lapack_int ldx, lapack_int* k );
+lapack_int LAPACKE_zlapmr( int matrix_order, lapack_logical forwrd,
+ lapack_int m, lapack_int n, lapack_complex_double* x,
+ lapack_int ldx, lapack_int* k );
+
+
+float LAPACKE_slapy2( float x, float y );
+double LAPACKE_dlapy2( double x, double y );
+
+float LAPACKE_slapy3( float x, float y, float z );
+double LAPACKE_dlapy3( double x, double y, double z );
+
+lapack_int LAPACKE_slartgp( float f, float g, float* cs, float* sn, float* r );
+lapack_int LAPACKE_dlartgp( double f, double g, double* cs, double* sn,
+ double* r );
+
+lapack_int LAPACKE_slartgs( float x, float y, float sigma, float* cs,
+ float* sn );
+lapack_int LAPACKE_dlartgs( double x, double y, double sigma, double* cs,
+ double* sn );
+
+
+//LAPACK 3.3.0
+lapack_int LAPACKE_cbbcsd( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans, lapack_int m,
+ lapack_int p, lapack_int q, float* theta, float* phi,
+ lapack_complex_float* u1, lapack_int ldu1,
+ lapack_complex_float* u2, lapack_int ldu2,
+ lapack_complex_float* v1t, lapack_int ldv1t,
+ lapack_complex_float* v2t, lapack_int ldv2t,
+ float* b11d, float* b11e, float* b12d, float* b12e,
+ float* b21d, float* b21e, float* b22d, float* b22e );
+lapack_int LAPACKE_cbbcsd_work( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans,
+ lapack_int m, lapack_int p, lapack_int q,
+ float* theta, float* phi,
+ lapack_complex_float* u1, lapack_int ldu1,
+ lapack_complex_float* u2, lapack_int ldu2,
+ lapack_complex_float* v1t, lapack_int ldv1t,
+ lapack_complex_float* v2t, lapack_int ldv2t,
+ float* b11d, float* b11e, float* b12d,
+ float* b12e, float* b21d, float* b21e,
+ float* b22d, float* b22e, float* rwork,
+ lapack_int lrwork );
+lapack_int LAPACKE_cheswapr( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int i1,
+ lapack_int i2 );
+lapack_int LAPACKE_cheswapr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int i1,
+ lapack_int i2 );
+lapack_int LAPACKE_chetri2( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv );
+lapack_int LAPACKE_chetri2_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_chetri2x( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv, lapack_int nb );
+lapack_int LAPACKE_chetri2x_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int nb );
+lapack_int LAPACKE_chetrs2( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_chetrs2_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* work );
+lapack_int LAPACKE_csyconv( int matrix_order, char uplo, char way, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv );
+lapack_int LAPACKE_csyconv_work( int matrix_order, char uplo, char way,
+ lapack_int n, lapack_complex_float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_float* work );
+lapack_int LAPACKE_csyswapr( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int i1,
+ lapack_int i2 );
+lapack_int LAPACKE_csyswapr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int i1,
+ lapack_int i2 );
+lapack_int LAPACKE_csytri2( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv );
+lapack_int LAPACKE_csytri2_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_csytri2x( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv, lapack_int nb );
+lapack_int LAPACKE_csytri2x_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int nb );
+lapack_int LAPACKE_csytrs2( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_csytrs2_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* work );
+lapack_int LAPACKE_cunbdb( int matrix_order, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q,
+ lapack_complex_float* x11, lapack_int ldx11,
+ lapack_complex_float* x12, lapack_int ldx12,
+ lapack_complex_float* x21, lapack_int ldx21,
+ lapack_complex_float* x22, lapack_int ldx22,
+ float* theta, float* phi,
+ lapack_complex_float* taup1,
+ lapack_complex_float* taup2,
+ lapack_complex_float* tauq1,
+ lapack_complex_float* tauq2 );
+lapack_int LAPACKE_cunbdb_work( int matrix_order, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q,
+ lapack_complex_float* x11, lapack_int ldx11,
+ lapack_complex_float* x12, lapack_int ldx12,
+ lapack_complex_float* x21, lapack_int ldx21,
+ lapack_complex_float* x22, lapack_int ldx22,
+ float* theta, float* phi,
+ lapack_complex_float* taup1,
+ lapack_complex_float* taup2,
+ lapack_complex_float* tauq1,
+ lapack_complex_float* tauq2,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_cuncsd( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q,
+ lapack_complex_float* x11, lapack_int ldx11,
+ lapack_complex_float* x12, lapack_int ldx12,
+ lapack_complex_float* x21, lapack_int ldx21,
+ lapack_complex_float* x22, lapack_int ldx22,
+ float* theta, lapack_complex_float* u1,
+ lapack_int ldu1, lapack_complex_float* u2,
+ lapack_int ldu2, lapack_complex_float* v1t,
+ lapack_int ldv1t, lapack_complex_float* v2t,
+ lapack_int ldv2t );
+lapack_int LAPACKE_cuncsd_work( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans,
+ char signs, lapack_int m, lapack_int p,
+ lapack_int q, lapack_complex_float* x11,
+ lapack_int ldx11, lapack_complex_float* x12,
+ lapack_int ldx12, lapack_complex_float* x21,
+ lapack_int ldx21, lapack_complex_float* x22,
+ lapack_int ldx22, float* theta,
+ lapack_complex_float* u1, lapack_int ldu1,
+ lapack_complex_float* u2, lapack_int ldu2,
+ lapack_complex_float* v1t, lapack_int ldv1t,
+ lapack_complex_float* v2t, lapack_int ldv2t,
+ lapack_complex_float* work, lapack_int lwork,
+ float* rwork, lapack_int lrwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_dbbcsd( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans, lapack_int m,
+ lapack_int p, lapack_int q, double* theta,
+ double* phi, double* u1, lapack_int ldu1, double* u2,
+ lapack_int ldu2, double* v1t, lapack_int ldv1t,
+ double* v2t, lapack_int ldv2t, double* b11d,
+ double* b11e, double* b12d, double* b12e,
+ double* b21d, double* b21e, double* b22d,
+ double* b22e );
+lapack_int LAPACKE_dbbcsd_work( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans,
+ lapack_int m, lapack_int p, lapack_int q,
+ double* theta, double* phi, double* u1,
+ lapack_int ldu1, double* u2, lapack_int ldu2,
+ double* v1t, lapack_int ldv1t, double* v2t,
+ lapack_int ldv2t, double* b11d, double* b11e,
+ double* b12d, double* b12e, double* b21d,
+ double* b21e, double* b22d, double* b22e,
+ double* work, lapack_int lwork );
+lapack_int LAPACKE_dorbdb( int matrix_order, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q,
+ double* x11, lapack_int ldx11, double* x12,
+ lapack_int ldx12, double* x21, lapack_int ldx21,
+ double* x22, lapack_int ldx22, double* theta,
+ double* phi, double* taup1, double* taup2,
+ double* tauq1, double* tauq2 );
+lapack_int LAPACKE_dorbdb_work( int matrix_order, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q,
+ double* x11, lapack_int ldx11, double* x12,
+ lapack_int ldx12, double* x21, lapack_int ldx21,
+ double* x22, lapack_int ldx22, double* theta,
+ double* phi, double* taup1, double* taup2,
+ double* tauq1, double* tauq2, double* work,
+ lapack_int lwork );
+lapack_int LAPACKE_dorcsd( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q,
+ double* x11, lapack_int ldx11, double* x12,
+ lapack_int ldx12, double* x21, lapack_int ldx21,
+ double* x22, lapack_int ldx22, double* theta,
+ double* u1, lapack_int ldu1, double* u2,
+ lapack_int ldu2, double* v1t, lapack_int ldv1t,
+ double* v2t, lapack_int ldv2t );
+lapack_int LAPACKE_dorcsd_work( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans,
+ char signs, lapack_int m, lapack_int p,
+ lapack_int q, double* x11, lapack_int ldx11,
+ double* x12, lapack_int ldx12, double* x21,
+ lapack_int ldx21, double* x22, lapack_int ldx22,
+ double* theta, double* u1, lapack_int ldu1,
+ double* u2, lapack_int ldu2, double* v1t,
+ lapack_int ldv1t, double* v2t, lapack_int ldv2t,
+ double* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_dsyconv( int matrix_order, char uplo, char way, lapack_int n,
+ double* a, lapack_int lda, const lapack_int* ipiv );
+lapack_int LAPACKE_dsyconv_work( int matrix_order, char uplo, char way,
+ lapack_int n, double* a, lapack_int lda,
+ const lapack_int* ipiv, double* work );
+lapack_int LAPACKE_dsyswapr( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int i1, lapack_int i2 );
+lapack_int LAPACKE_dsyswapr_work( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int i1, lapack_int i2 );
+lapack_int LAPACKE_dsytri2( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda, const lapack_int* ipiv );
+lapack_int LAPACKE_dsytri2_work( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int lwork );
+lapack_int LAPACKE_dsytri2x( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda, const lapack_int* ipiv,
+ lapack_int nb );
+lapack_int LAPACKE_dsytri2x_work( int matrix_order, char uplo, lapack_int n,
+ double* a, lapack_int lda,
+ const lapack_int* ipiv, double* work,
+ lapack_int nb );
+lapack_int LAPACKE_dsytrs2( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* a, lapack_int lda,
+ const lapack_int* ipiv, double* b, lapack_int ldb );
+lapack_int LAPACKE_dsytrs2_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ double* b, lapack_int ldb, double* work );
+lapack_int LAPACKE_sbbcsd( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans, lapack_int m,
+ lapack_int p, lapack_int q, float* theta, float* phi,
+ float* u1, lapack_int ldu1, float* u2,
+ lapack_int ldu2, float* v1t, lapack_int ldv1t,
+ float* v2t, lapack_int ldv2t, float* b11d,
+ float* b11e, float* b12d, float* b12e, float* b21d,
+ float* b21e, float* b22d, float* b22e );
+lapack_int LAPACKE_sbbcsd_work( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans,
+ lapack_int m, lapack_int p, lapack_int q,
+ float* theta, float* phi, float* u1,
+ lapack_int ldu1, float* u2, lapack_int ldu2,
+ float* v1t, lapack_int ldv1t, float* v2t,
+ lapack_int ldv2t, float* b11d, float* b11e,
+ float* b12d, float* b12e, float* b21d,
+ float* b21e, float* b22d, float* b22e,
+ float* work, lapack_int lwork );
+lapack_int LAPACKE_sorbdb( int matrix_order, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q, float* x11,
+ lapack_int ldx11, float* x12, lapack_int ldx12,
+ float* x21, lapack_int ldx21, float* x22,
+ lapack_int ldx22, float* theta, float* phi,
+ float* taup1, float* taup2, float* tauq1,
+ float* tauq2 );
+lapack_int LAPACKE_sorbdb_work( int matrix_order, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q,
+ float* x11, lapack_int ldx11, float* x12,
+ lapack_int ldx12, float* x21, lapack_int ldx21,
+ float* x22, lapack_int ldx22, float* theta,
+ float* phi, float* taup1, float* taup2,
+ float* tauq1, float* tauq2, float* work,
+ lapack_int lwork );
+lapack_int LAPACKE_sorcsd( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q, float* x11,
+ lapack_int ldx11, float* x12, lapack_int ldx12,
+ float* x21, lapack_int ldx21, float* x22,
+ lapack_int ldx22, float* theta, float* u1,
+ lapack_int ldu1, float* u2, lapack_int ldu2,
+ float* v1t, lapack_int ldv1t, float* v2t,
+ lapack_int ldv2t );
+lapack_int LAPACKE_sorcsd_work( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans,
+ char signs, lapack_int m, lapack_int p,
+ lapack_int q, float* x11, lapack_int ldx11,
+ float* x12, lapack_int ldx12, float* x21,
+ lapack_int ldx21, float* x22, lapack_int ldx22,
+ float* theta, float* u1, lapack_int ldu1,
+ float* u2, lapack_int ldu2, float* v1t,
+ lapack_int ldv1t, float* v2t, lapack_int ldv2t,
+ float* work, lapack_int lwork,
+ lapack_int* iwork );
+lapack_int LAPACKE_ssyconv( int matrix_order, char uplo, char way, lapack_int n,
+ float* a, lapack_int lda, const lapack_int* ipiv );
+lapack_int LAPACKE_ssyconv_work( int matrix_order, char uplo, char way,
+ lapack_int n, float* a, lapack_int lda,
+ const lapack_int* ipiv, float* work );
+lapack_int LAPACKE_ssyswapr( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int i1, lapack_int i2 );
+lapack_int LAPACKE_ssyswapr_work( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int i1, lapack_int i2 );
+lapack_int LAPACKE_ssytri2( int matrix_order, char uplo, lapack_int n, float* a,
+ lapack_int lda, const lapack_int* ipiv );
+lapack_int LAPACKE_ssytri2_work( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int lwork );
+lapack_int LAPACKE_ssytri2x( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int lda, const lapack_int* ipiv,
+ lapack_int nb );
+lapack_int LAPACKE_ssytri2x_work( int matrix_order, char uplo, lapack_int n,
+ float* a, lapack_int lda,
+ const lapack_int* ipiv, float* work,
+ lapack_int nb );
+lapack_int LAPACKE_ssytrs2( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* a, lapack_int lda,
+ const lapack_int* ipiv, float* b, lapack_int ldb );
+lapack_int LAPACKE_ssytrs2_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const float* a,
+ lapack_int lda, const lapack_int* ipiv,
+ float* b, lapack_int ldb, float* work );
+lapack_int LAPACKE_zbbcsd( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans, lapack_int m,
+ lapack_int p, lapack_int q, double* theta,
+ double* phi, lapack_complex_double* u1,
+ lapack_int ldu1, lapack_complex_double* u2,
+ lapack_int ldu2, lapack_complex_double* v1t,
+ lapack_int ldv1t, lapack_complex_double* v2t,
+ lapack_int ldv2t, double* b11d, double* b11e,
+ double* b12d, double* b12e, double* b21d,
+ double* b21e, double* b22d, double* b22e );
+lapack_int LAPACKE_zbbcsd_work( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans,
+ lapack_int m, lapack_int p, lapack_int q,
+ double* theta, double* phi,
+ lapack_complex_double* u1, lapack_int ldu1,
+ lapack_complex_double* u2, lapack_int ldu2,
+ lapack_complex_double* v1t, lapack_int ldv1t,
+ lapack_complex_double* v2t, lapack_int ldv2t,
+ double* b11d, double* b11e, double* b12d,
+ double* b12e, double* b21d, double* b21e,
+ double* b22d, double* b22e, double* rwork,
+ lapack_int lrwork );
+lapack_int LAPACKE_zheswapr( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int i1,
+ lapack_int i2 );
+lapack_int LAPACKE_zheswapr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int i1,
+ lapack_int i2 );
+lapack_int LAPACKE_zhetri2( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv );
+lapack_int LAPACKE_zhetri2_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int lwork );
+lapack_int LAPACKE_zhetri2x( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv, lapack_int nb );
+lapack_int LAPACKE_zhetri2x_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int nb );
+lapack_int LAPACKE_zhetrs2( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+lapack_int LAPACKE_zhetrs2_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* work );
+lapack_int LAPACKE_zsyconv( int matrix_order, char uplo, char way, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv );
+lapack_int LAPACKE_zsyconv_work( int matrix_order, char uplo, char way,
+ lapack_int n, lapack_complex_double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_double* work );
+lapack_int LAPACKE_zsyswapr( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int i1,
+ lapack_int i2 );
+lapack_int LAPACKE_zsyswapr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int i1,
+ lapack_int i2 );
+lapack_int LAPACKE_zsytri2( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv );
+lapack_int LAPACKE_zsytri2_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int lwork );
+lapack_int LAPACKE_zsytri2x( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv, lapack_int nb );
+lapack_int LAPACKE_zsytri2x_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int nb );
+lapack_int LAPACKE_zsytrs2( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb );
+lapack_int LAPACKE_zsytrs2_work( int matrix_order, char uplo, lapack_int n,
+ lapack_int nrhs, const lapack_complex_double* a,
+ lapack_int lda, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* work );
+lapack_int LAPACKE_zunbdb( int matrix_order, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q,
+ lapack_complex_double* x11, lapack_int ldx11,
+ lapack_complex_double* x12, lapack_int ldx12,
+ lapack_complex_double* x21, lapack_int ldx21,
+ lapack_complex_double* x22, lapack_int ldx22,
+ double* theta, double* phi,
+ lapack_complex_double* taup1,
+ lapack_complex_double* taup2,
+ lapack_complex_double* tauq1,
+ lapack_complex_double* tauq2 );
+lapack_int LAPACKE_zunbdb_work( int matrix_order, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q,
+ lapack_complex_double* x11, lapack_int ldx11,
+ lapack_complex_double* x12, lapack_int ldx12,
+ lapack_complex_double* x21, lapack_int ldx21,
+ lapack_complex_double* x22, lapack_int ldx22,
+ double* theta, double* phi,
+ lapack_complex_double* taup1,
+ lapack_complex_double* taup2,
+ lapack_complex_double* tauq1,
+ lapack_complex_double* tauq2,
+ lapack_complex_double* work, lapack_int lwork );
+lapack_int LAPACKE_zuncsd( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans, char signs,
+ lapack_int m, lapack_int p, lapack_int q,
+ lapack_complex_double* x11, lapack_int ldx11,
+ lapack_complex_double* x12, lapack_int ldx12,
+ lapack_complex_double* x21, lapack_int ldx21,
+ lapack_complex_double* x22, lapack_int ldx22,
+ double* theta, lapack_complex_double* u1,
+ lapack_int ldu1, lapack_complex_double* u2,
+ lapack_int ldu2, lapack_complex_double* v1t,
+ lapack_int ldv1t, lapack_complex_double* v2t,
+ lapack_int ldv2t );
+lapack_int LAPACKE_zuncsd_work( int matrix_order, char jobu1, char jobu2,
+ char jobv1t, char jobv2t, char trans,
+ char signs, lapack_int m, lapack_int p,
+ lapack_int q, lapack_complex_double* x11,
+ lapack_int ldx11, lapack_complex_double* x12,
+ lapack_int ldx12, lapack_complex_double* x21,
+ lapack_int ldx21, lapack_complex_double* x22,
+ lapack_int ldx22, double* theta,
+ lapack_complex_double* u1, lapack_int ldu1,
+ lapack_complex_double* u2, lapack_int ldu2,
+ lapack_complex_double* v1t, lapack_int ldv1t,
+ lapack_complex_double* v2t, lapack_int ldv2t,
+ lapack_complex_double* work, lapack_int lwork,
+ double* rwork, lapack_int lrwork,
+ lapack_int* iwork );
+//LAPACK 3.4.0
+lapack_int LAPACKE_sgemqrt( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int nb, const float* v, lapack_int ldv,
+ const float* t, lapack_int ldt, float* c,
+ lapack_int ldc );
+lapack_int LAPACKE_dgemqrt( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int nb, const double* v, lapack_int ldv,
+ const double* t, lapack_int ldt, double* c,
+ lapack_int ldc );
+lapack_int LAPACKE_cgemqrt( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int nb, const lapack_complex_float* v,
+ lapack_int ldv, const lapack_complex_float* t,
+ lapack_int ldt, lapack_complex_float* c,
+ lapack_int ldc );
+lapack_int LAPACKE_zgemqrt( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int nb, const lapack_complex_double* v,
+ lapack_int ldv, const lapack_complex_double* t,
+ lapack_int ldt, lapack_complex_double* c,
+ lapack_int ldc );
+
+lapack_int LAPACKE_sgeqrt( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nb, float* a, lapack_int lda, float* t,
+ lapack_int ldt );
+lapack_int LAPACKE_dgeqrt( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nb, double* a, lapack_int lda, double* t,
+ lapack_int ldt );
+lapack_int LAPACKE_cgeqrt( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nb, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* t,
+ lapack_int ldt );
+lapack_int LAPACKE_zgeqrt( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nb, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* t,
+ lapack_int ldt );
+
+lapack_int LAPACKE_sgeqrt2( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* t,
+ lapack_int ldt );
+lapack_int LAPACKE_dgeqrt2( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* t,
+ lapack_int ldt );
+lapack_int LAPACKE_cgeqrt2( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* t, lapack_int ldt );
+lapack_int LAPACKE_zgeqrt2( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* t, lapack_int ldt );
+
+lapack_int LAPACKE_sgeqrt3( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* t,
+ lapack_int ldt );
+lapack_int LAPACKE_dgeqrt3( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* t,
+ lapack_int ldt );
+lapack_int LAPACKE_cgeqrt3( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* t, lapack_int ldt );
+lapack_int LAPACKE_zgeqrt3( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* t, lapack_int ldt );
+
+lapack_int LAPACKE_stpmqrt( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, lapack_int nb, const float* v,
+ lapack_int ldv, const float* t, lapack_int ldt,
+ float* a, lapack_int lda, float* b,
+ lapack_int ldb );
+lapack_int LAPACKE_dtpmqrt( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, lapack_int nb, const double* v,
+ lapack_int ldv, const double* t, lapack_int ldt,
+ double* a, lapack_int lda, double* b,
+ lapack_int ldb );
+lapack_int LAPACKE_ctpmqrt( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, lapack_int nb,
+ const lapack_complex_float* v, lapack_int ldv,
+ const lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb );
+lapack_int LAPACKE_ztpmqrt( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, lapack_int nb,
+ const lapack_complex_double* v, lapack_int ldv,
+ const lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb );
+
+lapack_int LAPACKE_dtpqrt( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int l, lapack_int nb, double* a,
+ lapack_int lda, double* b, lapack_int ldb, double* t,
+ lapack_int ldt );
+lapack_int LAPACKE_ctpqrt( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int l, lapack_int nb, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* t,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_int ldt );
+lapack_int LAPACKE_ztpqrt( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int l, lapack_int nb,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* t, lapack_int ldt );
+
+lapack_int LAPACKE_stpqrt2( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* b, lapack_int ldb,
+ float* t, lapack_int ldt );
+lapack_int LAPACKE_dtpqrt2( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* b,
+ lapack_int ldb, double* t, lapack_int ldt );
+lapack_int LAPACKE_ctpqrt2( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* t, lapack_int ldt );
+lapack_int LAPACKE_ztpqrt2( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* t, lapack_int ldt );
+
+lapack_int LAPACKE_stprfb( int matrix_order, char side, char trans, char direct,
+ char storev, lapack_int m, lapack_int n,
+ lapack_int k, lapack_int l, const float* v,
+ lapack_int ldv, const float* t, lapack_int ldt,
+ float* a, lapack_int lda, float* b, lapack_int ldb,
+ lapack_int myldwork );
+lapack_int LAPACKE_dtprfb( int matrix_order, char side, char trans, char direct,
+ char storev, lapack_int m, lapack_int n,
+ lapack_int k, lapack_int l, const double* v,
+ lapack_int ldv, const double* t, lapack_int ldt,
+ double* a, lapack_int lda, double* b, lapack_int ldb,
+ lapack_int myldwork );
+lapack_int LAPACKE_ctprfb( int matrix_order, char side, char trans, char direct,
+ char storev, lapack_int m, lapack_int n,
+ lapack_int k, lapack_int l,
+ const lapack_complex_float* v, lapack_int ldv,
+ const lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_int myldwork );
+lapack_int LAPACKE_ztprfb( int matrix_order, char side, char trans, char direct,
+ char storev, lapack_int m, lapack_int n,
+ lapack_int k, lapack_int l,
+ const lapack_complex_double* v, lapack_int ldv,
+ const lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_int myldwork );
+
+lapack_int LAPACKE_sgemqrt_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int nb, const float* v, lapack_int ldv,
+ const float* t, lapack_int ldt, float* c,
+ lapack_int ldc, float* work );
+lapack_int LAPACKE_dgemqrt_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int nb, const double* v, lapack_int ldv,
+ const double* t, lapack_int ldt, double* c,
+ lapack_int ldc, double* work );
+lapack_int LAPACKE_cgemqrt_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int nb, const lapack_complex_float* v,
+ lapack_int ldv, const lapack_complex_float* t,
+ lapack_int ldt, lapack_complex_float* c,
+ lapack_int ldc, lapack_complex_float* work );
+lapack_int LAPACKE_zgemqrt_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int nb, const lapack_complex_double* v,
+ lapack_int ldv, const lapack_complex_double* t,
+ lapack_int ldt, lapack_complex_double* c,
+ lapack_int ldc, lapack_complex_double* work );
+
+lapack_int LAPACKE_sgeqrt_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nb, float* a, lapack_int lda,
+ float* t, lapack_int ldt, float* work );
+lapack_int LAPACKE_dgeqrt_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nb, double* a, lapack_int lda,
+ double* t, lapack_int ldt, double* work );
+lapack_int LAPACKE_cgeqrt_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nb, lapack_complex_float* a,
+ lapack_int lda, lapack_complex_float* t,
+ lapack_int ldt, lapack_complex_float* work );
+lapack_int LAPACKE_zgeqrt_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int nb, lapack_complex_double* a,
+ lapack_int lda, lapack_complex_double* t,
+ lapack_int ldt, lapack_complex_double* work );
+
+lapack_int LAPACKE_sgeqrt2_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* t,
+ lapack_int ldt );
+lapack_int LAPACKE_dgeqrt2_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* t,
+ lapack_int ldt );
+lapack_int LAPACKE_cgeqrt2_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* t, lapack_int ldt );
+lapack_int LAPACKE_zgeqrt2_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* t, lapack_int ldt );
+
+lapack_int LAPACKE_sgeqrt3_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* t,
+ lapack_int ldt );
+lapack_int LAPACKE_dgeqrt3_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* t,
+ lapack_int ldt );
+lapack_int LAPACKE_cgeqrt3_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* t, lapack_int ldt );
+lapack_int LAPACKE_zgeqrt3_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* t, lapack_int ldt );
+
+lapack_int LAPACKE_stpmqrt_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, lapack_int nb, const float* v,
+ lapack_int ldv, const float* t, lapack_int ldt,
+ float* a, lapack_int lda, float* b,
+ lapack_int ldb, float* work );
+lapack_int LAPACKE_dtpmqrt_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, lapack_int nb, const double* v,
+ lapack_int ldv, const double* t,
+ lapack_int ldt, double* a, lapack_int lda,
+ double* b, lapack_int ldb, double* work );
+lapack_int LAPACKE_ctpmqrt_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, lapack_int nb,
+ const lapack_complex_float* v, lapack_int ldv,
+ const lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* work );
+lapack_int LAPACKE_ztpmqrt_work( int matrix_order, char side, char trans,
+ lapack_int m, lapack_int n, lapack_int k,
+ lapack_int l, lapack_int nb,
+ const lapack_complex_double* v, lapack_int ldv,
+ const lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_dtpqrt_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int l, lapack_int nb, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ double* t, lapack_int ldt, double* work );
+lapack_int LAPACKE_ctpqrt_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int l, lapack_int nb,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* t,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_int ldt, lapack_complex_float* work );
+lapack_int LAPACKE_ztpqrt_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_int l, lapack_int nb,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* work );
+
+lapack_int LAPACKE_stpqrt2_work( int matrix_order, lapack_int m, lapack_int n,
+ float* a, lapack_int lda, float* b,
+ lapack_int ldb, float* t, lapack_int ldt );
+lapack_int LAPACKE_dtpqrt2_work( int matrix_order, lapack_int m, lapack_int n,
+ double* a, lapack_int lda, double* b,
+ lapack_int ldb, double* t, lapack_int ldt );
+lapack_int LAPACKE_ctpqrt2_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ lapack_complex_float* t, lapack_int ldt );
+lapack_int LAPACKE_ztpqrt2_work( int matrix_order, lapack_int m, lapack_int n,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ lapack_complex_double* t, lapack_int ldt );
+
+lapack_int LAPACKE_stprfb_work( int matrix_order, char side, char trans,
+ char direct, char storev, lapack_int m,
+ lapack_int n, lapack_int k, lapack_int l,
+ const float* v, lapack_int ldv, const float* t,
+ lapack_int ldt, float* a, lapack_int lda,
+ float* b, lapack_int ldb, const float* mywork,
+ lapack_int myldwork );
+lapack_int LAPACKE_dtprfb_work( int matrix_order, char side, char trans,
+ char direct, char storev, lapack_int m,
+ lapack_int n, lapack_int k, lapack_int l,
+ const double* v, lapack_int ldv,
+ const double* t, lapack_int ldt, double* a,
+ lapack_int lda, double* b, lapack_int ldb,
+ const double* mywork, lapack_int myldwork );
+lapack_int LAPACKE_ctprfb_work( int matrix_order, char side, char trans,
+ char direct, char storev, lapack_int m,
+ lapack_int n, lapack_int k, lapack_int l,
+ const lapack_complex_float* v, lapack_int ldv,
+ const lapack_complex_float* t, lapack_int ldt,
+ lapack_complex_float* a, lapack_int lda,
+ lapack_complex_float* b, lapack_int ldb,
+ const float* mywork, lapack_int myldwork );
+lapack_int LAPACKE_ztprfb_work( int matrix_order, char side, char trans,
+ char direct, char storev, lapack_int m,
+ lapack_int n, lapack_int k, lapack_int l,
+ const lapack_complex_double* v, lapack_int ldv,
+ const lapack_complex_double* t, lapack_int ldt,
+ lapack_complex_double* a, lapack_int lda,
+ lapack_complex_double* b, lapack_int ldb,
+ const double* mywork, lapack_int myldwork );
+//LAPACK 3.X.X
+lapack_int LAPACKE_csyr( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float alpha,
+ const lapack_complex_float* x, lapack_int incx,
+ lapack_complex_float* a, lapack_int lda );
+lapack_int LAPACKE_zsyr( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double alpha,
+ const lapack_complex_double* x, lapack_int incx,
+ lapack_complex_double* a, lapack_int lda );
+
+lapack_int LAPACKE_csyr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_float alpha,
+ const lapack_complex_float* x,
+ lapack_int incx, lapack_complex_float* a,
+ lapack_int lda );
+lapack_int LAPACKE_zsyr_work( int matrix_order, char uplo, lapack_int n,
+ lapack_complex_double alpha,
+ const lapack_complex_double* x,
+ lapack_int incx, lapack_complex_double* a,
+ lapack_int lda );
+
+
+
+#define LAPACK_sgetrf LAPACK_GLOBAL(sgetrf,SGETRF)
+#define LAPACK_dgetrf LAPACK_GLOBAL(dgetrf,DGETRF)
+#define LAPACK_cgetrf LAPACK_GLOBAL(cgetrf,CGETRF)
+#define LAPACK_zgetrf LAPACK_GLOBAL(zgetrf,ZGETRF)
+#define LAPACK_sgbtrf LAPACK_GLOBAL(sgbtrf,SGBTRF)
+#define LAPACK_dgbtrf LAPACK_GLOBAL(dgbtrf,DGBTRF)
+#define LAPACK_cgbtrf LAPACK_GLOBAL(cgbtrf,CGBTRF)
+#define LAPACK_zgbtrf LAPACK_GLOBAL(zgbtrf,ZGBTRF)
+#define LAPACK_sgttrf LAPACK_GLOBAL(sgttrf,SGTTRF)
+#define LAPACK_dgttrf LAPACK_GLOBAL(dgttrf,DGTTRF)
+#define LAPACK_cgttrf LAPACK_GLOBAL(cgttrf,CGTTRF)
+#define LAPACK_zgttrf LAPACK_GLOBAL(zgttrf,ZGTTRF)
+#define LAPACK_spotrf LAPACK_GLOBAL(spotrf,SPOTRF)
+#define LAPACK_dpotrf LAPACK_GLOBAL(dpotrf,DPOTRF)
+#define LAPACK_cpotrf LAPACK_GLOBAL(cpotrf,CPOTRF)
+#define LAPACK_zpotrf LAPACK_GLOBAL(zpotrf,ZPOTRF)
+#define LAPACK_dpstrf LAPACK_GLOBAL(dpstrf,DPSTRF)
+#define LAPACK_spstrf LAPACK_GLOBAL(spstrf,SPSTRF)
+#define LAPACK_zpstrf LAPACK_GLOBAL(zpstrf,ZPSTRF)
+#define LAPACK_cpstrf LAPACK_GLOBAL(cpstrf,CPSTRF)
+#define LAPACK_dpftrf LAPACK_GLOBAL(dpftrf,DPFTRF)
+#define LAPACK_spftrf LAPACK_GLOBAL(spftrf,SPFTRF)
+#define LAPACK_zpftrf LAPACK_GLOBAL(zpftrf,ZPFTRF)
+#define LAPACK_cpftrf LAPACK_GLOBAL(cpftrf,CPFTRF)
+#define LAPACK_spptrf LAPACK_GLOBAL(spptrf,SPPTRF)
+#define LAPACK_dpptrf LAPACK_GLOBAL(dpptrf,DPPTRF)
+#define LAPACK_cpptrf LAPACK_GLOBAL(cpptrf,CPPTRF)
+#define LAPACK_zpptrf LAPACK_GLOBAL(zpptrf,ZPPTRF)
+#define LAPACK_spbtrf LAPACK_GLOBAL(spbtrf,SPBTRF)
+#define LAPACK_dpbtrf LAPACK_GLOBAL(dpbtrf,DPBTRF)
+#define LAPACK_cpbtrf LAPACK_GLOBAL(cpbtrf,CPBTRF)
+#define LAPACK_zpbtrf LAPACK_GLOBAL(zpbtrf,ZPBTRF)
+#define LAPACK_spttrf LAPACK_GLOBAL(spttrf,SPTTRF)
+#define LAPACK_dpttrf LAPACK_GLOBAL(dpttrf,DPTTRF)
+#define LAPACK_cpttrf LAPACK_GLOBAL(cpttrf,CPTTRF)
+#define LAPACK_zpttrf LAPACK_GLOBAL(zpttrf,ZPTTRF)
+#define LAPACK_ssytrf LAPACK_GLOBAL(ssytrf,SSYTRF)
+#define LAPACK_dsytrf LAPACK_GLOBAL(dsytrf,DSYTRF)
+#define LAPACK_csytrf LAPACK_GLOBAL(csytrf,CSYTRF)
+#define LAPACK_zsytrf LAPACK_GLOBAL(zsytrf,ZSYTRF)
+#define LAPACK_chetrf LAPACK_GLOBAL(chetrf,CHETRF)
+#define LAPACK_zhetrf LAPACK_GLOBAL(zhetrf,ZHETRF)
+#define LAPACK_ssptrf LAPACK_GLOBAL(ssptrf,SSPTRF)
+#define LAPACK_dsptrf LAPACK_GLOBAL(dsptrf,DSPTRF)
+#define LAPACK_csptrf LAPACK_GLOBAL(csptrf,CSPTRF)
+#define LAPACK_zsptrf LAPACK_GLOBAL(zsptrf,ZSPTRF)
+#define LAPACK_chptrf LAPACK_GLOBAL(chptrf,CHPTRF)
+#define LAPACK_zhptrf LAPACK_GLOBAL(zhptrf,ZHPTRF)
+#define LAPACK_sgetrs LAPACK_GLOBAL(sgetrs,SGETRS)
+#define LAPACK_dgetrs LAPACK_GLOBAL(dgetrs,DGETRS)
+#define LAPACK_cgetrs LAPACK_GLOBAL(cgetrs,CGETRS)
+#define LAPACK_zgetrs LAPACK_GLOBAL(zgetrs,ZGETRS)
+#define LAPACK_sgbtrs LAPACK_GLOBAL(sgbtrs,SGBTRS)
+#define LAPACK_dgbtrs LAPACK_GLOBAL(dgbtrs,DGBTRS)
+#define LAPACK_cgbtrs LAPACK_GLOBAL(cgbtrs,CGBTRS)
+#define LAPACK_zgbtrs LAPACK_GLOBAL(zgbtrs,ZGBTRS)
+#define LAPACK_sgttrs LAPACK_GLOBAL(sgttrs,SGTTRS)
+#define LAPACK_dgttrs LAPACK_GLOBAL(dgttrs,DGTTRS)
+#define LAPACK_cgttrs LAPACK_GLOBAL(cgttrs,CGTTRS)
+#define LAPACK_zgttrs LAPACK_GLOBAL(zgttrs,ZGTTRS)
+#define LAPACK_spotrs LAPACK_GLOBAL(spotrs,SPOTRS)
+#define LAPACK_dpotrs LAPACK_GLOBAL(dpotrs,DPOTRS)
+#define LAPACK_cpotrs LAPACK_GLOBAL(cpotrs,CPOTRS)
+#define LAPACK_zpotrs LAPACK_GLOBAL(zpotrs,ZPOTRS)
+#define LAPACK_dpftrs LAPACK_GLOBAL(dpftrs,DPFTRS)
+#define LAPACK_spftrs LAPACK_GLOBAL(spftrs,SPFTRS)
+#define LAPACK_zpftrs LAPACK_GLOBAL(zpftrs,ZPFTRS)
+#define LAPACK_cpftrs LAPACK_GLOBAL(cpftrs,CPFTRS)
+#define LAPACK_spptrs LAPACK_GLOBAL(spptrs,SPPTRS)
+#define LAPACK_dpptrs LAPACK_GLOBAL(dpptrs,DPPTRS)
+#define LAPACK_cpptrs LAPACK_GLOBAL(cpptrs,CPPTRS)
+#define LAPACK_zpptrs LAPACK_GLOBAL(zpptrs,ZPPTRS)
+#define LAPACK_spbtrs LAPACK_GLOBAL(spbtrs,SPBTRS)
+#define LAPACK_dpbtrs LAPACK_GLOBAL(dpbtrs,DPBTRS)
+#define LAPACK_cpbtrs LAPACK_GLOBAL(cpbtrs,CPBTRS)
+#define LAPACK_zpbtrs LAPACK_GLOBAL(zpbtrs,ZPBTRS)
+#define LAPACK_spttrs LAPACK_GLOBAL(spttrs,SPTTRS)
+#define LAPACK_dpttrs LAPACK_GLOBAL(dpttrs,DPTTRS)
+#define LAPACK_cpttrs LAPACK_GLOBAL(cpttrs,CPTTRS)
+#define LAPACK_zpttrs LAPACK_GLOBAL(zpttrs,ZPTTRS)
+#define LAPACK_ssytrs LAPACK_GLOBAL(ssytrs,SSYTRS)
+#define LAPACK_dsytrs LAPACK_GLOBAL(dsytrs,DSYTRS)
+#define LAPACK_csytrs LAPACK_GLOBAL(csytrs,CSYTRS)
+#define LAPACK_zsytrs LAPACK_GLOBAL(zsytrs,ZSYTRS)
+#define LAPACK_chetrs LAPACK_GLOBAL(chetrs,CHETRS)
+#define LAPACK_zhetrs LAPACK_GLOBAL(zhetrs,ZHETRS)
+#define LAPACK_ssptrs LAPACK_GLOBAL(ssptrs,SSPTRS)
+#define LAPACK_dsptrs LAPACK_GLOBAL(dsptrs,DSPTRS)
+#define LAPACK_csptrs LAPACK_GLOBAL(csptrs,CSPTRS)
+#define LAPACK_zsptrs LAPACK_GLOBAL(zsptrs,ZSPTRS)
+#define LAPACK_chptrs LAPACK_GLOBAL(chptrs,CHPTRS)
+#define LAPACK_zhptrs LAPACK_GLOBAL(zhptrs,ZHPTRS)
+#define LAPACK_strtrs LAPACK_GLOBAL(strtrs,STRTRS)
+#define LAPACK_dtrtrs LAPACK_GLOBAL(dtrtrs,DTRTRS)
+#define LAPACK_ctrtrs LAPACK_GLOBAL(ctrtrs,CTRTRS)
+#define LAPACK_ztrtrs LAPACK_GLOBAL(ztrtrs,ZTRTRS)
+#define LAPACK_stptrs LAPACK_GLOBAL(stptrs,STPTRS)
+#define LAPACK_dtptrs LAPACK_GLOBAL(dtptrs,DTPTRS)
+#define LAPACK_ctptrs LAPACK_GLOBAL(ctptrs,CTPTRS)
+#define LAPACK_ztptrs LAPACK_GLOBAL(ztptrs,ZTPTRS)
+#define LAPACK_stbtrs LAPACK_GLOBAL(stbtrs,STBTRS)
+#define LAPACK_dtbtrs LAPACK_GLOBAL(dtbtrs,DTBTRS)
+#define LAPACK_ctbtrs LAPACK_GLOBAL(ctbtrs,CTBTRS)
+#define LAPACK_ztbtrs LAPACK_GLOBAL(ztbtrs,ZTBTRS)
+#define LAPACK_sgecon LAPACK_GLOBAL(sgecon,SGECON)
+#define LAPACK_dgecon LAPACK_GLOBAL(dgecon,DGECON)
+#define LAPACK_cgecon LAPACK_GLOBAL(cgecon,CGECON)
+#define LAPACK_zgecon LAPACK_GLOBAL(zgecon,ZGECON)
+#define LAPACK_sgbcon LAPACK_GLOBAL(sgbcon,SGBCON)
+#define LAPACK_dgbcon LAPACK_GLOBAL(dgbcon,DGBCON)
+#define LAPACK_cgbcon LAPACK_GLOBAL(cgbcon,CGBCON)
+#define LAPACK_zgbcon LAPACK_GLOBAL(zgbcon,ZGBCON)
+#define LAPACK_sgtcon LAPACK_GLOBAL(sgtcon,SGTCON)
+#define LAPACK_dgtcon LAPACK_GLOBAL(dgtcon,DGTCON)
+#define LAPACK_cgtcon LAPACK_GLOBAL(cgtcon,CGTCON)
+#define LAPACK_zgtcon LAPACK_GLOBAL(zgtcon,ZGTCON)
+#define LAPACK_spocon LAPACK_GLOBAL(spocon,SPOCON)
+#define LAPACK_dpocon LAPACK_GLOBAL(dpocon,DPOCON)
+#define LAPACK_cpocon LAPACK_GLOBAL(cpocon,CPOCON)
+#define LAPACK_zpocon LAPACK_GLOBAL(zpocon,ZPOCON)
+#define LAPACK_sppcon LAPACK_GLOBAL(sppcon,SPPCON)
+#define LAPACK_dppcon LAPACK_GLOBAL(dppcon,DPPCON)
+#define LAPACK_cppcon LAPACK_GLOBAL(cppcon,CPPCON)
+#define LAPACK_zppcon LAPACK_GLOBAL(zppcon,ZPPCON)
+#define LAPACK_spbcon LAPACK_GLOBAL(spbcon,SPBCON)
+#define LAPACK_dpbcon LAPACK_GLOBAL(dpbcon,DPBCON)
+#define LAPACK_cpbcon LAPACK_GLOBAL(cpbcon,CPBCON)
+#define LAPACK_zpbcon LAPACK_GLOBAL(zpbcon,ZPBCON)
+#define LAPACK_sptcon LAPACK_GLOBAL(sptcon,SPTCON)
+#define LAPACK_dptcon LAPACK_GLOBAL(dptcon,DPTCON)
+#define LAPACK_cptcon LAPACK_GLOBAL(cptcon,CPTCON)
+#define LAPACK_zptcon LAPACK_GLOBAL(zptcon,ZPTCON)
+#define LAPACK_ssycon LAPACK_GLOBAL(ssycon,SSYCON)
+#define LAPACK_dsycon LAPACK_GLOBAL(dsycon,DSYCON)
+#define LAPACK_csycon LAPACK_GLOBAL(csycon,CSYCON)
+#define LAPACK_zsycon LAPACK_GLOBAL(zsycon,ZSYCON)
+#define LAPACK_checon LAPACK_GLOBAL(checon,CHECON)
+#define LAPACK_zhecon LAPACK_GLOBAL(zhecon,ZHECON)
+#define LAPACK_sspcon LAPACK_GLOBAL(sspcon,SSPCON)
+#define LAPACK_dspcon LAPACK_GLOBAL(dspcon,DSPCON)
+#define LAPACK_cspcon LAPACK_GLOBAL(cspcon,CSPCON)
+#define LAPACK_zspcon LAPACK_GLOBAL(zspcon,ZSPCON)
+#define LAPACK_chpcon LAPACK_GLOBAL(chpcon,CHPCON)
+#define LAPACK_zhpcon LAPACK_GLOBAL(zhpcon,ZHPCON)
+#define LAPACK_strcon LAPACK_GLOBAL(strcon,STRCON)
+#define LAPACK_dtrcon LAPACK_GLOBAL(dtrcon,DTRCON)
+#define LAPACK_ctrcon LAPACK_GLOBAL(ctrcon,CTRCON)
+#define LAPACK_ztrcon LAPACK_GLOBAL(ztrcon,ZTRCON)
+#define LAPACK_stpcon LAPACK_GLOBAL(stpcon,STPCON)
+#define LAPACK_dtpcon LAPACK_GLOBAL(dtpcon,DTPCON)
+#define LAPACK_ctpcon LAPACK_GLOBAL(ctpcon,CTPCON)
+#define LAPACK_ztpcon LAPACK_GLOBAL(ztpcon,ZTPCON)
+#define LAPACK_stbcon LAPACK_GLOBAL(stbcon,STBCON)
+#define LAPACK_dtbcon LAPACK_GLOBAL(dtbcon,DTBCON)
+#define LAPACK_ctbcon LAPACK_GLOBAL(ctbcon,CTBCON)
+#define LAPACK_ztbcon LAPACK_GLOBAL(ztbcon,ZTBCON)
+#define LAPACK_sgerfs LAPACK_GLOBAL(sgerfs,SGERFS)
+#define LAPACK_dgerfs LAPACK_GLOBAL(dgerfs,DGERFS)
+#define LAPACK_cgerfs LAPACK_GLOBAL(cgerfs,CGERFS)
+#define LAPACK_zgerfs LAPACK_GLOBAL(zgerfs,ZGERFS)
+#define LAPACK_dgerfsx LAPACK_GLOBAL(dgerfsx,DGERFSX)
+#define LAPACK_sgerfsx LAPACK_GLOBAL(sgerfsx,SGERFSX)
+#define LAPACK_zgerfsx LAPACK_GLOBAL(zgerfsx,ZGERFSX)
+#define LAPACK_cgerfsx LAPACK_GLOBAL(cgerfsx,CGERFSX)
+#define LAPACK_sgbrfs LAPACK_GLOBAL(sgbrfs,SGBRFS)
+#define LAPACK_dgbrfs LAPACK_GLOBAL(dgbrfs,DGBRFS)
+#define LAPACK_cgbrfs LAPACK_GLOBAL(cgbrfs,CGBRFS)
+#define LAPACK_zgbrfs LAPACK_GLOBAL(zgbrfs,ZGBRFS)
+#define LAPACK_dgbrfsx LAPACK_GLOBAL(dgbrfsx,DGBRFSX)
+#define LAPACK_sgbrfsx LAPACK_GLOBAL(sgbrfsx,SGBRFSX)
+#define LAPACK_zgbrfsx LAPACK_GLOBAL(zgbrfsx,ZGBRFSX)
+#define LAPACK_cgbrfsx LAPACK_GLOBAL(cgbrfsx,CGBRFSX)
+#define LAPACK_sgtrfs LAPACK_GLOBAL(sgtrfs,SGTRFS)
+#define LAPACK_dgtrfs LAPACK_GLOBAL(dgtrfs,DGTRFS)
+#define LAPACK_cgtrfs LAPACK_GLOBAL(cgtrfs,CGTRFS)
+#define LAPACK_zgtrfs LAPACK_GLOBAL(zgtrfs,ZGTRFS)
+#define LAPACK_sporfs LAPACK_GLOBAL(sporfs,SPORFS)
+#define LAPACK_dporfs LAPACK_GLOBAL(dporfs,DPORFS)
+#define LAPACK_cporfs LAPACK_GLOBAL(cporfs,CPORFS)
+#define LAPACK_zporfs LAPACK_GLOBAL(zporfs,ZPORFS)
+#define LAPACK_dporfsx LAPACK_GLOBAL(dporfsx,DPORFSX)
+#define LAPACK_sporfsx LAPACK_GLOBAL(sporfsx,SPORFSX)
+#define LAPACK_zporfsx LAPACK_GLOBAL(zporfsx,ZPORFSX)
+#define LAPACK_cporfsx LAPACK_GLOBAL(cporfsx,CPORFSX)
+#define LAPACK_spprfs LAPACK_GLOBAL(spprfs,SPPRFS)
+#define LAPACK_dpprfs LAPACK_GLOBAL(dpprfs,DPPRFS)
+#define LAPACK_cpprfs LAPACK_GLOBAL(cpprfs,CPPRFS)
+#define LAPACK_zpprfs LAPACK_GLOBAL(zpprfs,ZPPRFS)
+#define LAPACK_spbrfs LAPACK_GLOBAL(spbrfs,SPBRFS)
+#define LAPACK_dpbrfs LAPACK_GLOBAL(dpbrfs,DPBRFS)
+#define LAPACK_cpbrfs LAPACK_GLOBAL(cpbrfs,CPBRFS)
+#define LAPACK_zpbrfs LAPACK_GLOBAL(zpbrfs,ZPBRFS)
+#define LAPACK_sptrfs LAPACK_GLOBAL(sptrfs,SPTRFS)
+#define LAPACK_dptrfs LAPACK_GLOBAL(dptrfs,DPTRFS)
+#define LAPACK_cptrfs LAPACK_GLOBAL(cptrfs,CPTRFS)
+#define LAPACK_zptrfs LAPACK_GLOBAL(zptrfs,ZPTRFS)
+#define LAPACK_ssyrfs LAPACK_GLOBAL(ssyrfs,SSYRFS)
+#define LAPACK_dsyrfs LAPACK_GLOBAL(dsyrfs,DSYRFS)
+#define LAPACK_csyrfs LAPACK_GLOBAL(csyrfs,CSYRFS)
+#define LAPACK_zsyrfs LAPACK_GLOBAL(zsyrfs,ZSYRFS)
+#define LAPACK_dsyrfsx LAPACK_GLOBAL(dsyrfsx,DSYRFSX)
+#define LAPACK_ssyrfsx LAPACK_GLOBAL(ssyrfsx,SSYRFSX)
+#define LAPACK_zsyrfsx LAPACK_GLOBAL(zsyrfsx,ZSYRFSX)
+#define LAPACK_csyrfsx LAPACK_GLOBAL(csyrfsx,CSYRFSX)
+#define LAPACK_cherfs LAPACK_GLOBAL(cherfs,CHERFS)
+#define LAPACK_zherfs LAPACK_GLOBAL(zherfs,ZHERFS)
+#define LAPACK_zherfsx LAPACK_GLOBAL(zherfsx,ZHERFSX)
+#define LAPACK_cherfsx LAPACK_GLOBAL(cherfsx,CHERFSX)
+#define LAPACK_ssprfs LAPACK_GLOBAL(ssprfs,SSPRFS)
+#define LAPACK_dsprfs LAPACK_GLOBAL(dsprfs,DSPRFS)
+#define LAPACK_csprfs LAPACK_GLOBAL(csprfs,CSPRFS)
+#define LAPACK_zsprfs LAPACK_GLOBAL(zsprfs,ZSPRFS)
+#define LAPACK_chprfs LAPACK_GLOBAL(chprfs,CHPRFS)
+#define LAPACK_zhprfs LAPACK_GLOBAL(zhprfs,ZHPRFS)
+#define LAPACK_strrfs LAPACK_GLOBAL(strrfs,STRRFS)
+#define LAPACK_dtrrfs LAPACK_GLOBAL(dtrrfs,DTRRFS)
+#define LAPACK_ctrrfs LAPACK_GLOBAL(ctrrfs,CTRRFS)
+#define LAPACK_ztrrfs LAPACK_GLOBAL(ztrrfs,ZTRRFS)
+#define LAPACK_stprfs LAPACK_GLOBAL(stprfs,STPRFS)
+#define LAPACK_dtprfs LAPACK_GLOBAL(dtprfs,DTPRFS)
+#define LAPACK_ctprfs LAPACK_GLOBAL(ctprfs,CTPRFS)
+#define LAPACK_ztprfs LAPACK_GLOBAL(ztprfs,ZTPRFS)
+#define LAPACK_stbrfs LAPACK_GLOBAL(stbrfs,STBRFS)
+#define LAPACK_dtbrfs LAPACK_GLOBAL(dtbrfs,DTBRFS)
+#define LAPACK_ctbrfs LAPACK_GLOBAL(ctbrfs,CTBRFS)
+#define LAPACK_ztbrfs LAPACK_GLOBAL(ztbrfs,ZTBRFS)
+#define LAPACK_sgetri LAPACK_GLOBAL(sgetri,SGETRI)
+#define LAPACK_dgetri LAPACK_GLOBAL(dgetri,DGETRI)
+#define LAPACK_cgetri LAPACK_GLOBAL(cgetri,CGETRI)
+#define LAPACK_zgetri LAPACK_GLOBAL(zgetri,ZGETRI)
+#define LAPACK_spotri LAPACK_GLOBAL(spotri,SPOTRI)
+#define LAPACK_dpotri LAPACK_GLOBAL(dpotri,DPOTRI)
+#define LAPACK_cpotri LAPACK_GLOBAL(cpotri,CPOTRI)
+#define LAPACK_zpotri LAPACK_GLOBAL(zpotri,ZPOTRI)
+#define LAPACK_dpftri LAPACK_GLOBAL(dpftri,DPFTRI)
+#define LAPACK_spftri LAPACK_GLOBAL(spftri,SPFTRI)
+#define LAPACK_zpftri LAPACK_GLOBAL(zpftri,ZPFTRI)
+#define LAPACK_cpftri LAPACK_GLOBAL(cpftri,CPFTRI)
+#define LAPACK_spptri LAPACK_GLOBAL(spptri,SPPTRI)
+#define LAPACK_dpptri LAPACK_GLOBAL(dpptri,DPPTRI)
+#define LAPACK_cpptri LAPACK_GLOBAL(cpptri,CPPTRI)
+#define LAPACK_zpptri LAPACK_GLOBAL(zpptri,ZPPTRI)
+#define LAPACK_ssytri LAPACK_GLOBAL(ssytri,SSYTRI)
+#define LAPACK_dsytri LAPACK_GLOBAL(dsytri,DSYTRI)
+#define LAPACK_csytri LAPACK_GLOBAL(csytri,CSYTRI)
+#define LAPACK_zsytri LAPACK_GLOBAL(zsytri,ZSYTRI)
+#define LAPACK_chetri LAPACK_GLOBAL(chetri,CHETRI)
+#define LAPACK_zhetri LAPACK_GLOBAL(zhetri,ZHETRI)
+#define LAPACK_ssptri LAPACK_GLOBAL(ssptri,SSPTRI)
+#define LAPACK_dsptri LAPACK_GLOBAL(dsptri,DSPTRI)
+#define LAPACK_csptri LAPACK_GLOBAL(csptri,CSPTRI)
+#define LAPACK_zsptri LAPACK_GLOBAL(zsptri,ZSPTRI)
+#define LAPACK_chptri LAPACK_GLOBAL(chptri,CHPTRI)
+#define LAPACK_zhptri LAPACK_GLOBAL(zhptri,ZHPTRI)
+#define LAPACK_strtri LAPACK_GLOBAL(strtri,STRTRI)
+#define LAPACK_dtrtri LAPACK_GLOBAL(dtrtri,DTRTRI)
+#define LAPACK_ctrtri LAPACK_GLOBAL(ctrtri,CTRTRI)
+#define LAPACK_ztrtri LAPACK_GLOBAL(ztrtri,ZTRTRI)
+#define LAPACK_dtftri LAPACK_GLOBAL(dtftri,DTFTRI)
+#define LAPACK_stftri LAPACK_GLOBAL(stftri,STFTRI)
+#define LAPACK_ztftri LAPACK_GLOBAL(ztftri,ZTFTRI)
+#define LAPACK_ctftri LAPACK_GLOBAL(ctftri,CTFTRI)
+#define LAPACK_stptri LAPACK_GLOBAL(stptri,STPTRI)
+#define LAPACK_dtptri LAPACK_GLOBAL(dtptri,DTPTRI)
+#define LAPACK_ctptri LAPACK_GLOBAL(ctptri,CTPTRI)
+#define LAPACK_ztptri LAPACK_GLOBAL(ztptri,ZTPTRI)
+#define LAPACK_sgeequ LAPACK_GLOBAL(sgeequ,SGEEQU)
+#define LAPACK_dgeequ LAPACK_GLOBAL(dgeequ,DGEEQU)
+#define LAPACK_cgeequ LAPACK_GLOBAL(cgeequ,CGEEQU)
+#define LAPACK_zgeequ LAPACK_GLOBAL(zgeequ,ZGEEQU)
+#define LAPACK_dgeequb LAPACK_GLOBAL(dgeequb,DGEEQUB)
+#define LAPACK_sgeequb LAPACK_GLOBAL(sgeequb,SGEEQUB)
+#define LAPACK_zgeequb LAPACK_GLOBAL(zgeequb,ZGEEQUB)
+#define LAPACK_cgeequb LAPACK_GLOBAL(cgeequb,CGEEQUB)
+#define LAPACK_sgbequ LAPACK_GLOBAL(sgbequ,SGBEQU)
+#define LAPACK_dgbequ LAPACK_GLOBAL(dgbequ,DGBEQU)
+#define LAPACK_cgbequ LAPACK_GLOBAL(cgbequ,CGBEQU)
+#define LAPACK_zgbequ LAPACK_GLOBAL(zgbequ,ZGBEQU)
+#define LAPACK_dgbequb LAPACK_GLOBAL(dgbequb,DGBEQUB)
+#define LAPACK_sgbequb LAPACK_GLOBAL(sgbequb,SGBEQUB)
+#define LAPACK_zgbequb LAPACK_GLOBAL(zgbequb,ZGBEQUB)
+#define LAPACK_cgbequb LAPACK_GLOBAL(cgbequb,CGBEQUB)
+#define LAPACK_spoequ LAPACK_GLOBAL(spoequ,SPOEQU)
+#define LAPACK_dpoequ LAPACK_GLOBAL(dpoequ,DPOEQU)
+#define LAPACK_cpoequ LAPACK_GLOBAL(cpoequ,CPOEQU)
+#define LAPACK_zpoequ LAPACK_GLOBAL(zpoequ,ZPOEQU)
+#define LAPACK_dpoequb LAPACK_GLOBAL(dpoequb,DPOEQUB)
+#define LAPACK_spoequb LAPACK_GLOBAL(spoequb,SPOEQUB)
+#define LAPACK_zpoequb LAPACK_GLOBAL(zpoequb,ZPOEQUB)
+#define LAPACK_cpoequb LAPACK_GLOBAL(cpoequb,CPOEQUB)
+#define LAPACK_sppequ LAPACK_GLOBAL(sppequ,SPPEQU)
+#define LAPACK_dppequ LAPACK_GLOBAL(dppequ,DPPEQU)
+#define LAPACK_cppequ LAPACK_GLOBAL(cppequ,CPPEQU)
+#define LAPACK_zppequ LAPACK_GLOBAL(zppequ,ZPPEQU)
+#define LAPACK_spbequ LAPACK_GLOBAL(spbequ,SPBEQU)
+#define LAPACK_dpbequ LAPACK_GLOBAL(dpbequ,DPBEQU)
+#define LAPACK_cpbequ LAPACK_GLOBAL(cpbequ,CPBEQU)
+#define LAPACK_zpbequ LAPACK_GLOBAL(zpbequ,ZPBEQU)
+#define LAPACK_dsyequb LAPACK_GLOBAL(dsyequb,DSYEQUB)
+#define LAPACK_ssyequb LAPACK_GLOBAL(ssyequb,SSYEQUB)
+#define LAPACK_zsyequb LAPACK_GLOBAL(zsyequb,ZSYEQUB)
+#define LAPACK_csyequb LAPACK_GLOBAL(csyequb,CSYEQUB)
+#define LAPACK_zheequb LAPACK_GLOBAL(zheequb,ZHEEQUB)
+#define LAPACK_cheequb LAPACK_GLOBAL(cheequb,CHEEQUB)
+#define LAPACK_sgesv LAPACK_GLOBAL(sgesv,SGESV)
+#define LAPACK_dgesv LAPACK_GLOBAL(dgesv,DGESV)
+#define LAPACK_cgesv LAPACK_GLOBAL(cgesv,CGESV)
+#define LAPACK_zgesv LAPACK_GLOBAL(zgesv,ZGESV)
+#define LAPACK_dsgesv LAPACK_GLOBAL(dsgesv,DSGESV)
+#define LAPACK_zcgesv LAPACK_GLOBAL(zcgesv,ZCGESV)
+#define LAPACK_sgesvx LAPACK_GLOBAL(sgesvx,SGESVX)
+#define LAPACK_dgesvx LAPACK_GLOBAL(dgesvx,DGESVX)
+#define LAPACK_cgesvx LAPACK_GLOBAL(cgesvx,CGESVX)
+#define LAPACK_zgesvx LAPACK_GLOBAL(zgesvx,ZGESVX)
+#define LAPACK_dgesvxx LAPACK_GLOBAL(dgesvxx,DGESVXX)
+#define LAPACK_sgesvxx LAPACK_GLOBAL(sgesvxx,SGESVXX)
+#define LAPACK_zgesvxx LAPACK_GLOBAL(zgesvxx,ZGESVXX)
+#define LAPACK_cgesvxx LAPACK_GLOBAL(cgesvxx,CGESVXX)
+#define LAPACK_sgbsv LAPACK_GLOBAL(sgbsv,SGBSV)
+#define LAPACK_dgbsv LAPACK_GLOBAL(dgbsv,DGBSV)
+#define LAPACK_cgbsv LAPACK_GLOBAL(cgbsv,CGBSV)
+#define LAPACK_zgbsv LAPACK_GLOBAL(zgbsv,ZGBSV)
+#define LAPACK_sgbsvx LAPACK_GLOBAL(sgbsvx,SGBSVX)
+#define LAPACK_dgbsvx LAPACK_GLOBAL(dgbsvx,DGBSVX)
+#define LAPACK_cgbsvx LAPACK_GLOBAL(cgbsvx,CGBSVX)
+#define LAPACK_zgbsvx LAPACK_GLOBAL(zgbsvx,ZGBSVX)
+#define LAPACK_dgbsvxx LAPACK_GLOBAL(dgbsvxx,DGBSVXX)
+#define LAPACK_sgbsvxx LAPACK_GLOBAL(sgbsvxx,SGBSVXX)
+#define LAPACK_zgbsvxx LAPACK_GLOBAL(zgbsvxx,ZGBSVXX)
+#define LAPACK_cgbsvxx LAPACK_GLOBAL(cgbsvxx,CGBSVXX)
+#define LAPACK_sgtsv LAPACK_GLOBAL(sgtsv,SGTSV)
+#define LAPACK_dgtsv LAPACK_GLOBAL(dgtsv,DGTSV)
+#define LAPACK_cgtsv LAPACK_GLOBAL(cgtsv,CGTSV)
+#define LAPACK_zgtsv LAPACK_GLOBAL(zgtsv,ZGTSV)
+#define LAPACK_sgtsvx LAPACK_GLOBAL(sgtsvx,SGTSVX)
+#define LAPACK_dgtsvx LAPACK_GLOBAL(dgtsvx,DGTSVX)
+#define LAPACK_cgtsvx LAPACK_GLOBAL(cgtsvx,CGTSVX)
+#define LAPACK_zgtsvx LAPACK_GLOBAL(zgtsvx,ZGTSVX)
+#define LAPACK_sposv LAPACK_GLOBAL(sposv,SPOSV)
+#define LAPACK_dposv LAPACK_GLOBAL(dposv,DPOSV)
+#define LAPACK_cposv LAPACK_GLOBAL(cposv,CPOSV)
+#define LAPACK_zposv LAPACK_GLOBAL(zposv,ZPOSV)
+#define LAPACK_dsposv LAPACK_GLOBAL(dsposv,DSPOSV)
+#define LAPACK_zcposv LAPACK_GLOBAL(zcposv,ZCPOSV)
+#define LAPACK_sposvx LAPACK_GLOBAL(sposvx,SPOSVX)
+#define LAPACK_dposvx LAPACK_GLOBAL(dposvx,DPOSVX)
+#define LAPACK_cposvx LAPACK_GLOBAL(cposvx,CPOSVX)
+#define LAPACK_zposvx LAPACK_GLOBAL(zposvx,ZPOSVX)
+#define LAPACK_dposvxx LAPACK_GLOBAL(dposvxx,DPOSVXX)
+#define LAPACK_sposvxx LAPACK_GLOBAL(sposvxx,SPOSVXX)
+#define LAPACK_zposvxx LAPACK_GLOBAL(zposvxx,ZPOSVXX)
+#define LAPACK_cposvxx LAPACK_GLOBAL(cposvxx,CPOSVXX)
+#define LAPACK_sppsv LAPACK_GLOBAL(sppsv,SPPSV)
+#define LAPACK_dppsv LAPACK_GLOBAL(dppsv,DPPSV)
+#define LAPACK_cppsv LAPACK_GLOBAL(cppsv,CPPSV)
+#define LAPACK_zppsv LAPACK_GLOBAL(zppsv,ZPPSV)
+#define LAPACK_sppsvx LAPACK_GLOBAL(sppsvx,SPPSVX)
+#define LAPACK_dppsvx LAPACK_GLOBAL(dppsvx,DPPSVX)
+#define LAPACK_cppsvx LAPACK_GLOBAL(cppsvx,CPPSVX)
+#define LAPACK_zppsvx LAPACK_GLOBAL(zppsvx,ZPPSVX)
+#define LAPACK_spbsv LAPACK_GLOBAL(spbsv,SPBSV)
+#define LAPACK_dpbsv LAPACK_GLOBAL(dpbsv,DPBSV)
+#define LAPACK_cpbsv LAPACK_GLOBAL(cpbsv,CPBSV)
+#define LAPACK_zpbsv LAPACK_GLOBAL(zpbsv,ZPBSV)
+#define LAPACK_spbsvx LAPACK_GLOBAL(spbsvx,SPBSVX)
+#define LAPACK_dpbsvx LAPACK_GLOBAL(dpbsvx,DPBSVX)
+#define LAPACK_cpbsvx LAPACK_GLOBAL(cpbsvx,CPBSVX)
+#define LAPACK_zpbsvx LAPACK_GLOBAL(zpbsvx,ZPBSVX)
+#define LAPACK_sptsv LAPACK_GLOBAL(sptsv,SPTSV)
+#define LAPACK_dptsv LAPACK_GLOBAL(dptsv,DPTSV)
+#define LAPACK_cptsv LAPACK_GLOBAL(cptsv,CPTSV)
+#define LAPACK_zptsv LAPACK_GLOBAL(zptsv,ZPTSV)
+#define LAPACK_sptsvx LAPACK_GLOBAL(sptsvx,SPTSVX)
+#define LAPACK_dptsvx LAPACK_GLOBAL(dptsvx,DPTSVX)
+#define LAPACK_cptsvx LAPACK_GLOBAL(cptsvx,CPTSVX)
+#define LAPACK_zptsvx LAPACK_GLOBAL(zptsvx,ZPTSVX)
+#define LAPACK_ssysv LAPACK_GLOBAL(ssysv,SSYSV)
+#define LAPACK_dsysv LAPACK_GLOBAL(dsysv,DSYSV)
+#define LAPACK_csysv LAPACK_GLOBAL(csysv,CSYSV)
+#define LAPACK_zsysv LAPACK_GLOBAL(zsysv,ZSYSV)
+#define LAPACK_ssysvx LAPACK_GLOBAL(ssysvx,SSYSVX)
+#define LAPACK_dsysvx LAPACK_GLOBAL(dsysvx,DSYSVX)
+#define LAPACK_csysvx LAPACK_GLOBAL(csysvx,CSYSVX)
+#define LAPACK_zsysvx LAPACK_GLOBAL(zsysvx,ZSYSVX)
+#define LAPACK_dsysvxx LAPACK_GLOBAL(dsysvxx,DSYSVXX)
+#define LAPACK_ssysvxx LAPACK_GLOBAL(ssysvxx,SSYSVXX)
+#define LAPACK_zsysvxx LAPACK_GLOBAL(zsysvxx,ZSYSVXX)
+#define LAPACK_csysvxx LAPACK_GLOBAL(csysvxx,CSYSVXX)
+#define LAPACK_chesv LAPACK_GLOBAL(chesv,CHESV)
+#define LAPACK_zhesv LAPACK_GLOBAL(zhesv,ZHESV)
+#define LAPACK_chesvx LAPACK_GLOBAL(chesvx,CHESVX)
+#define LAPACK_zhesvx LAPACK_GLOBAL(zhesvx,ZHESVX)
+#define LAPACK_zhesvxx LAPACK_GLOBAL(zhesvxx,ZHESVXX)
+#define LAPACK_chesvxx LAPACK_GLOBAL(chesvxx,CHESVXX)
+#define LAPACK_sspsv LAPACK_GLOBAL(sspsv,SSPSV)
+#define LAPACK_dspsv LAPACK_GLOBAL(dspsv,DSPSV)
+#define LAPACK_cspsv LAPACK_GLOBAL(cspsv,CSPSV)
+#define LAPACK_zspsv LAPACK_GLOBAL(zspsv,ZSPSV)
+#define LAPACK_sspsvx LAPACK_GLOBAL(sspsvx,SSPSVX)
+#define LAPACK_dspsvx LAPACK_GLOBAL(dspsvx,DSPSVX)
+#define LAPACK_cspsvx LAPACK_GLOBAL(cspsvx,CSPSVX)
+#define LAPACK_zspsvx LAPACK_GLOBAL(zspsvx,ZSPSVX)
+#define LAPACK_chpsv LAPACK_GLOBAL(chpsv,CHPSV)
+#define LAPACK_zhpsv LAPACK_GLOBAL(zhpsv,ZHPSV)
+#define LAPACK_chpsvx LAPACK_GLOBAL(chpsvx,CHPSVX)
+#define LAPACK_zhpsvx LAPACK_GLOBAL(zhpsvx,ZHPSVX)
+#define LAPACK_sgeqrf LAPACK_GLOBAL(sgeqrf,SGEQRF)
+#define LAPACK_dgeqrf LAPACK_GLOBAL(dgeqrf,DGEQRF)
+#define LAPACK_cgeqrf LAPACK_GLOBAL(cgeqrf,CGEQRF)
+#define LAPACK_zgeqrf LAPACK_GLOBAL(zgeqrf,ZGEQRF)
+#define LAPACK_sgeqpf LAPACK_GLOBAL(sgeqpf,SGEQPF)
+#define LAPACK_dgeqpf LAPACK_GLOBAL(dgeqpf,DGEQPF)
+#define LAPACK_cgeqpf LAPACK_GLOBAL(cgeqpf,CGEQPF)
+#define LAPACK_zgeqpf LAPACK_GLOBAL(zgeqpf,ZGEQPF)
+#define LAPACK_sgeqp3 LAPACK_GLOBAL(sgeqp3,SGEQP3)
+#define LAPACK_dgeqp3 LAPACK_GLOBAL(dgeqp3,DGEQP3)
+#define LAPACK_cgeqp3 LAPACK_GLOBAL(cgeqp3,CGEQP3)
+#define LAPACK_zgeqp3 LAPACK_GLOBAL(zgeqp3,ZGEQP3)
+#define LAPACK_sorgqr LAPACK_GLOBAL(sorgqr,SORGQR)
+#define LAPACK_dorgqr LAPACK_GLOBAL(dorgqr,DORGQR)
+#define LAPACK_sormqr LAPACK_GLOBAL(sormqr,SORMQR)
+#define LAPACK_dormqr LAPACK_GLOBAL(dormqr,DORMQR)
+#define LAPACK_cungqr LAPACK_GLOBAL(cungqr,CUNGQR)
+#define LAPACK_zungqr LAPACK_GLOBAL(zungqr,ZUNGQR)
+#define LAPACK_cunmqr LAPACK_GLOBAL(cunmqr,CUNMQR)
+#define LAPACK_zunmqr LAPACK_GLOBAL(zunmqr,ZUNMQR)
+#define LAPACK_sgelqf LAPACK_GLOBAL(sgelqf,SGELQF)
+#define LAPACK_dgelqf LAPACK_GLOBAL(dgelqf,DGELQF)
+#define LAPACK_cgelqf LAPACK_GLOBAL(cgelqf,CGELQF)
+#define LAPACK_zgelqf LAPACK_GLOBAL(zgelqf,ZGELQF)
+#define LAPACK_sorglq LAPACK_GLOBAL(sorglq,SORGLQ)
+#define LAPACK_dorglq LAPACK_GLOBAL(dorglq,DORGLQ)
+#define LAPACK_sormlq LAPACK_GLOBAL(sormlq,SORMLQ)
+#define LAPACK_dormlq LAPACK_GLOBAL(dormlq,DORMLQ)
+#define LAPACK_cunglq LAPACK_GLOBAL(cunglq,CUNGLQ)
+#define LAPACK_zunglq LAPACK_GLOBAL(zunglq,ZUNGLQ)
+#define LAPACK_cunmlq LAPACK_GLOBAL(cunmlq,CUNMLQ)
+#define LAPACK_zunmlq LAPACK_GLOBAL(zunmlq,ZUNMLQ)
+#define LAPACK_sgeqlf LAPACK_GLOBAL(sgeqlf,SGEQLF)
+#define LAPACK_dgeqlf LAPACK_GLOBAL(dgeqlf,DGEQLF)
+#define LAPACK_cgeqlf LAPACK_GLOBAL(cgeqlf,CGEQLF)
+#define LAPACK_zgeqlf LAPACK_GLOBAL(zgeqlf,ZGEQLF)
+#define LAPACK_sorgql LAPACK_GLOBAL(sorgql,SORGQL)
+#define LAPACK_dorgql LAPACK_GLOBAL(dorgql,DORGQL)
+#define LAPACK_cungql LAPACK_GLOBAL(cungql,CUNGQL)
+#define LAPACK_zungql LAPACK_GLOBAL(zungql,ZUNGQL)
+#define LAPACK_sormql LAPACK_GLOBAL(sormql,SORMQL)
+#define LAPACK_dormql LAPACK_GLOBAL(dormql,DORMQL)
+#define LAPACK_cunmql LAPACK_GLOBAL(cunmql,CUNMQL)
+#define LAPACK_zunmql LAPACK_GLOBAL(zunmql,ZUNMQL)
+#define LAPACK_sgerqf LAPACK_GLOBAL(sgerqf,SGERQF)
+#define LAPACK_dgerqf LAPACK_GLOBAL(dgerqf,DGERQF)
+#define LAPACK_cgerqf LAPACK_GLOBAL(cgerqf,CGERQF)
+#define LAPACK_zgerqf LAPACK_GLOBAL(zgerqf,ZGERQF)
+#define LAPACK_sorgrq LAPACK_GLOBAL(sorgrq,SORGRQ)
+#define LAPACK_dorgrq LAPACK_GLOBAL(dorgrq,DORGRQ)
+#define LAPACK_cungrq LAPACK_GLOBAL(cungrq,CUNGRQ)
+#define LAPACK_zungrq LAPACK_GLOBAL(zungrq,ZUNGRQ)
+#define LAPACK_sormrq LAPACK_GLOBAL(sormrq,SORMRQ)
+#define LAPACK_dormrq LAPACK_GLOBAL(dormrq,DORMRQ)
+#define LAPACK_cunmrq LAPACK_GLOBAL(cunmrq,CUNMRQ)
+#define LAPACK_zunmrq LAPACK_GLOBAL(zunmrq,ZUNMRQ)
+#define LAPACK_stzrzf LAPACK_GLOBAL(stzrzf,STZRZF)
+#define LAPACK_dtzrzf LAPACK_GLOBAL(dtzrzf,DTZRZF)
+#define LAPACK_ctzrzf LAPACK_GLOBAL(ctzrzf,CTZRZF)
+#define LAPACK_ztzrzf LAPACK_GLOBAL(ztzrzf,ZTZRZF)
+#define LAPACK_sormrz LAPACK_GLOBAL(sormrz,SORMRZ)
+#define LAPACK_dormrz LAPACK_GLOBAL(dormrz,DORMRZ)
+#define LAPACK_cunmrz LAPACK_GLOBAL(cunmrz,CUNMRZ)
+#define LAPACK_zunmrz LAPACK_GLOBAL(zunmrz,ZUNMRZ)
+#define LAPACK_sggqrf LAPACK_GLOBAL(sggqrf,SGGQRF)
+#define LAPACK_dggqrf LAPACK_GLOBAL(dggqrf,DGGQRF)
+#define LAPACK_cggqrf LAPACK_GLOBAL(cggqrf,CGGQRF)
+#define LAPACK_zggqrf LAPACK_GLOBAL(zggqrf,ZGGQRF)
+#define LAPACK_sggrqf LAPACK_GLOBAL(sggrqf,SGGRQF)
+#define LAPACK_dggrqf LAPACK_GLOBAL(dggrqf,DGGRQF)
+#define LAPACK_cggrqf LAPACK_GLOBAL(cggrqf,CGGRQF)
+#define LAPACK_zggrqf LAPACK_GLOBAL(zggrqf,ZGGRQF)
+#define LAPACK_sgebrd LAPACK_GLOBAL(sgebrd,SGEBRD)
+#define LAPACK_dgebrd LAPACK_GLOBAL(dgebrd,DGEBRD)
+#define LAPACK_cgebrd LAPACK_GLOBAL(cgebrd,CGEBRD)
+#define LAPACK_zgebrd LAPACK_GLOBAL(zgebrd,ZGEBRD)
+#define LAPACK_sgbbrd LAPACK_GLOBAL(sgbbrd,SGBBRD)
+#define LAPACK_dgbbrd LAPACK_GLOBAL(dgbbrd,DGBBRD)
+#define LAPACK_cgbbrd LAPACK_GLOBAL(cgbbrd,CGBBRD)
+#define LAPACK_zgbbrd LAPACK_GLOBAL(zgbbrd,ZGBBRD)
+#define LAPACK_sorgbr LAPACK_GLOBAL(sorgbr,SORGBR)
+#define LAPACK_dorgbr LAPACK_GLOBAL(dorgbr,DORGBR)
+#define LAPACK_sormbr LAPACK_GLOBAL(sormbr,SORMBR)
+#define LAPACK_dormbr LAPACK_GLOBAL(dormbr,DORMBR)
+#define LAPACK_cungbr LAPACK_GLOBAL(cungbr,CUNGBR)
+#define LAPACK_zungbr LAPACK_GLOBAL(zungbr,ZUNGBR)
+#define LAPACK_cunmbr LAPACK_GLOBAL(cunmbr,CUNMBR)
+#define LAPACK_zunmbr LAPACK_GLOBAL(zunmbr,ZUNMBR)
+#define LAPACK_sbdsqr LAPACK_GLOBAL(sbdsqr,SBDSQR)
+#define LAPACK_dbdsqr LAPACK_GLOBAL(dbdsqr,DBDSQR)
+#define LAPACK_cbdsqr LAPACK_GLOBAL(cbdsqr,CBDSQR)
+#define LAPACK_zbdsqr LAPACK_GLOBAL(zbdsqr,ZBDSQR)
+#define LAPACK_sbdsdc LAPACK_GLOBAL(sbdsdc,SBDSDC)
+#define LAPACK_dbdsdc LAPACK_GLOBAL(dbdsdc,DBDSDC)
+#define LAPACK_ssytrd LAPACK_GLOBAL(ssytrd,SSYTRD)
+#define LAPACK_dsytrd LAPACK_GLOBAL(dsytrd,DSYTRD)
+#define LAPACK_sorgtr LAPACK_GLOBAL(sorgtr,SORGTR)
+#define LAPACK_dorgtr LAPACK_GLOBAL(dorgtr,DORGTR)
+#define LAPACK_sormtr LAPACK_GLOBAL(sormtr,SORMTR)
+#define LAPACK_dormtr LAPACK_GLOBAL(dormtr,DORMTR)
+#define LAPACK_chetrd LAPACK_GLOBAL(chetrd,CHETRD)
+#define LAPACK_zhetrd LAPACK_GLOBAL(zhetrd,ZHETRD)
+#define LAPACK_cungtr LAPACK_GLOBAL(cungtr,CUNGTR)
+#define LAPACK_zungtr LAPACK_GLOBAL(zungtr,ZUNGTR)
+#define LAPACK_cunmtr LAPACK_GLOBAL(cunmtr,CUNMTR)
+#define LAPACK_zunmtr LAPACK_GLOBAL(zunmtr,ZUNMTR)
+#define LAPACK_ssptrd LAPACK_GLOBAL(ssptrd,SSPTRD)
+#define LAPACK_dsptrd LAPACK_GLOBAL(dsptrd,DSPTRD)
+#define LAPACK_sopgtr LAPACK_GLOBAL(sopgtr,SOPGTR)
+#define LAPACK_dopgtr LAPACK_GLOBAL(dopgtr,DOPGTR)
+#define LAPACK_sopmtr LAPACK_GLOBAL(sopmtr,SOPMTR)
+#define LAPACK_dopmtr LAPACK_GLOBAL(dopmtr,DOPMTR)
+#define LAPACK_chptrd LAPACK_GLOBAL(chptrd,CHPTRD)
+#define LAPACK_zhptrd LAPACK_GLOBAL(zhptrd,ZHPTRD)
+#define LAPACK_cupgtr LAPACK_GLOBAL(cupgtr,CUPGTR)
+#define LAPACK_zupgtr LAPACK_GLOBAL(zupgtr,ZUPGTR)
+#define LAPACK_cupmtr LAPACK_GLOBAL(cupmtr,CUPMTR)
+#define LAPACK_zupmtr LAPACK_GLOBAL(zupmtr,ZUPMTR)
+#define LAPACK_ssbtrd LAPACK_GLOBAL(ssbtrd,SSBTRD)
+#define LAPACK_dsbtrd LAPACK_GLOBAL(dsbtrd,DSBTRD)
+#define LAPACK_chbtrd LAPACK_GLOBAL(chbtrd,CHBTRD)
+#define LAPACK_zhbtrd LAPACK_GLOBAL(zhbtrd,ZHBTRD)
+#define LAPACK_ssterf LAPACK_GLOBAL(ssterf,SSTERF)
+#define LAPACK_dsterf LAPACK_GLOBAL(dsterf,DSTERF)
+#define LAPACK_ssteqr LAPACK_GLOBAL(ssteqr,SSTEQR)
+#define LAPACK_dsteqr LAPACK_GLOBAL(dsteqr,DSTEQR)
+#define LAPACK_csteqr LAPACK_GLOBAL(csteqr,CSTEQR)
+#define LAPACK_zsteqr LAPACK_GLOBAL(zsteqr,ZSTEQR)
+#define LAPACK_sstemr LAPACK_GLOBAL(sstemr,SSTEMR)
+#define LAPACK_dstemr LAPACK_GLOBAL(dstemr,DSTEMR)
+#define LAPACK_cstemr LAPACK_GLOBAL(cstemr,CSTEMR)
+#define LAPACK_zstemr LAPACK_GLOBAL(zstemr,ZSTEMR)
+#define LAPACK_sstedc LAPACK_GLOBAL(sstedc,SSTEDC)
+#define LAPACK_dstedc LAPACK_GLOBAL(dstedc,DSTEDC)
+#define LAPACK_cstedc LAPACK_GLOBAL(cstedc,CSTEDC)
+#define LAPACK_zstedc LAPACK_GLOBAL(zstedc,ZSTEDC)
+#define LAPACK_sstegr LAPACK_GLOBAL(sstegr,SSTEGR)
+#define LAPACK_dstegr LAPACK_GLOBAL(dstegr,DSTEGR)
+#define LAPACK_cstegr LAPACK_GLOBAL(cstegr,CSTEGR)
+#define LAPACK_zstegr LAPACK_GLOBAL(zstegr,ZSTEGR)
+#define LAPACK_spteqr LAPACK_GLOBAL(spteqr,SPTEQR)
+#define LAPACK_dpteqr LAPACK_GLOBAL(dpteqr,DPTEQR)
+#define LAPACK_cpteqr LAPACK_GLOBAL(cpteqr,CPTEQR)
+#define LAPACK_zpteqr LAPACK_GLOBAL(zpteqr,ZPTEQR)
+#define LAPACK_sstebz LAPACK_GLOBAL(sstebz,SSTEBZ)
+#define LAPACK_dstebz LAPACK_GLOBAL(dstebz,DSTEBZ)
+#define LAPACK_sstein LAPACK_GLOBAL(sstein,SSTEIN)
+#define LAPACK_dstein LAPACK_GLOBAL(dstein,DSTEIN)
+#define LAPACK_cstein LAPACK_GLOBAL(cstein,CSTEIN)
+#define LAPACK_zstein LAPACK_GLOBAL(zstein,ZSTEIN)
+#define LAPACK_sdisna LAPACK_GLOBAL(sdisna,SDISNA)
+#define LAPACK_ddisna LAPACK_GLOBAL(ddisna,DDISNA)
+#define LAPACK_ssygst LAPACK_GLOBAL(ssygst,SSYGST)
+#define LAPACK_dsygst LAPACK_GLOBAL(dsygst,DSYGST)
+#define LAPACK_chegst LAPACK_GLOBAL(chegst,CHEGST)
+#define LAPACK_zhegst LAPACK_GLOBAL(zhegst,ZHEGST)
+#define LAPACK_sspgst LAPACK_GLOBAL(sspgst,SSPGST)
+#define LAPACK_dspgst LAPACK_GLOBAL(dspgst,DSPGST)
+#define LAPACK_chpgst LAPACK_GLOBAL(chpgst,CHPGST)
+#define LAPACK_zhpgst LAPACK_GLOBAL(zhpgst,ZHPGST)
+#define LAPACK_ssbgst LAPACK_GLOBAL(ssbgst,SSBGST)
+#define LAPACK_dsbgst LAPACK_GLOBAL(dsbgst,DSBGST)
+#define LAPACK_chbgst LAPACK_GLOBAL(chbgst,CHBGST)
+#define LAPACK_zhbgst LAPACK_GLOBAL(zhbgst,ZHBGST)
+#define LAPACK_spbstf LAPACK_GLOBAL(spbstf,SPBSTF)
+#define LAPACK_dpbstf LAPACK_GLOBAL(dpbstf,DPBSTF)
+#define LAPACK_cpbstf LAPACK_GLOBAL(cpbstf,CPBSTF)
+#define LAPACK_zpbstf LAPACK_GLOBAL(zpbstf,ZPBSTF)
+#define LAPACK_sgehrd LAPACK_GLOBAL(sgehrd,SGEHRD)
+#define LAPACK_dgehrd LAPACK_GLOBAL(dgehrd,DGEHRD)
+#define LAPACK_cgehrd LAPACK_GLOBAL(cgehrd,CGEHRD)
+#define LAPACK_zgehrd LAPACK_GLOBAL(zgehrd,ZGEHRD)
+#define LAPACK_sorghr LAPACK_GLOBAL(sorghr,SORGHR)
+#define LAPACK_dorghr LAPACK_GLOBAL(dorghr,DORGHR)
+#define LAPACK_sormhr LAPACK_GLOBAL(sormhr,SORMHR)
+#define LAPACK_dormhr LAPACK_GLOBAL(dormhr,DORMHR)
+#define LAPACK_cunghr LAPACK_GLOBAL(cunghr,CUNGHR)
+#define LAPACK_zunghr LAPACK_GLOBAL(zunghr,ZUNGHR)
+#define LAPACK_cunmhr LAPACK_GLOBAL(cunmhr,CUNMHR)
+#define LAPACK_zunmhr LAPACK_GLOBAL(zunmhr,ZUNMHR)
+#define LAPACK_sgebal LAPACK_GLOBAL(sgebal,SGEBAL)
+#define LAPACK_dgebal LAPACK_GLOBAL(dgebal,DGEBAL)
+#define LAPACK_cgebal LAPACK_GLOBAL(cgebal,CGEBAL)
+#define LAPACK_zgebal LAPACK_GLOBAL(zgebal,ZGEBAL)
+#define LAPACK_sgebak LAPACK_GLOBAL(sgebak,SGEBAK)
+#define LAPACK_dgebak LAPACK_GLOBAL(dgebak,DGEBAK)
+#define LAPACK_cgebak LAPACK_GLOBAL(cgebak,CGEBAK)
+#define LAPACK_zgebak LAPACK_GLOBAL(zgebak,ZGEBAK)
+#define LAPACK_shseqr LAPACK_GLOBAL(shseqr,SHSEQR)
+#define LAPACK_dhseqr LAPACK_GLOBAL(dhseqr,DHSEQR)
+#define LAPACK_chseqr LAPACK_GLOBAL(chseqr,CHSEQR)
+#define LAPACK_zhseqr LAPACK_GLOBAL(zhseqr,ZHSEQR)
+#define LAPACK_shsein LAPACK_GLOBAL(shsein,SHSEIN)
+#define LAPACK_dhsein LAPACK_GLOBAL(dhsein,DHSEIN)
+#define LAPACK_chsein LAPACK_GLOBAL(chsein,CHSEIN)
+#define LAPACK_zhsein LAPACK_GLOBAL(zhsein,ZHSEIN)
+#define LAPACK_strevc LAPACK_GLOBAL(strevc,STREVC)
+#define LAPACK_dtrevc LAPACK_GLOBAL(dtrevc,DTREVC)
+#define LAPACK_ctrevc LAPACK_GLOBAL(ctrevc,CTREVC)
+#define LAPACK_ztrevc LAPACK_GLOBAL(ztrevc,ZTREVC)
+#define LAPACK_strsna LAPACK_GLOBAL(strsna,STRSNA)
+#define LAPACK_dtrsna LAPACK_GLOBAL(dtrsna,DTRSNA)
+#define LAPACK_ctrsna LAPACK_GLOBAL(ctrsna,CTRSNA)
+#define LAPACK_ztrsna LAPACK_GLOBAL(ztrsna,ZTRSNA)
+#define LAPACK_strexc LAPACK_GLOBAL(strexc,STREXC)
+#define LAPACK_dtrexc LAPACK_GLOBAL(dtrexc,DTREXC)
+#define LAPACK_ctrexc LAPACK_GLOBAL(ctrexc,CTREXC)
+#define LAPACK_ztrexc LAPACK_GLOBAL(ztrexc,ZTREXC)
+#define LAPACK_strsen LAPACK_GLOBAL(strsen,STRSEN)
+#define LAPACK_dtrsen LAPACK_GLOBAL(dtrsen,DTRSEN)
+#define LAPACK_ctrsen LAPACK_GLOBAL(ctrsen,CTRSEN)
+#define LAPACK_ztrsen LAPACK_GLOBAL(ztrsen,ZTRSEN)
+#define LAPACK_strsyl LAPACK_GLOBAL(strsyl,STRSYL)
+#define LAPACK_dtrsyl LAPACK_GLOBAL(dtrsyl,DTRSYL)
+#define LAPACK_ctrsyl LAPACK_GLOBAL(ctrsyl,CTRSYL)
+#define LAPACK_ztrsyl LAPACK_GLOBAL(ztrsyl,ZTRSYL)
+#define LAPACK_sgghrd LAPACK_GLOBAL(sgghrd,SGGHRD)
+#define LAPACK_dgghrd LAPACK_GLOBAL(dgghrd,DGGHRD)
+#define LAPACK_cgghrd LAPACK_GLOBAL(cgghrd,CGGHRD)
+#define LAPACK_zgghrd LAPACK_GLOBAL(zgghrd,ZGGHRD)
+#define LAPACK_sggbal LAPACK_GLOBAL(sggbal,SGGBAL)
+#define LAPACK_dggbal LAPACK_GLOBAL(dggbal,DGGBAL)
+#define LAPACK_cggbal LAPACK_GLOBAL(cggbal,CGGBAL)
+#define LAPACK_zggbal LAPACK_GLOBAL(zggbal,ZGGBAL)
+#define LAPACK_sggbak LAPACK_GLOBAL(sggbak,SGGBAK)
+#define LAPACK_dggbak LAPACK_GLOBAL(dggbak,DGGBAK)
+#define LAPACK_cggbak LAPACK_GLOBAL(cggbak,CGGBAK)
+#define LAPACK_zggbak LAPACK_GLOBAL(zggbak,ZGGBAK)
+#define LAPACK_shgeqz LAPACK_GLOBAL(shgeqz,SHGEQZ)
+#define LAPACK_dhgeqz LAPACK_GLOBAL(dhgeqz,DHGEQZ)
+#define LAPACK_chgeqz LAPACK_GLOBAL(chgeqz,CHGEQZ)
+#define LAPACK_zhgeqz LAPACK_GLOBAL(zhgeqz,ZHGEQZ)
+#define LAPACK_stgevc LAPACK_GLOBAL(stgevc,STGEVC)
+#define LAPACK_dtgevc LAPACK_GLOBAL(dtgevc,DTGEVC)
+#define LAPACK_ctgevc LAPACK_GLOBAL(ctgevc,CTGEVC)
+#define LAPACK_ztgevc LAPACK_GLOBAL(ztgevc,ZTGEVC)
+#define LAPACK_stgexc LAPACK_GLOBAL(stgexc,STGEXC)
+#define LAPACK_dtgexc LAPACK_GLOBAL(dtgexc,DTGEXC)
+#define LAPACK_ctgexc LAPACK_GLOBAL(ctgexc,CTGEXC)
+#define LAPACK_ztgexc LAPACK_GLOBAL(ztgexc,ZTGEXC)
+#define LAPACK_stgsen LAPACK_GLOBAL(stgsen,STGSEN)
+#define LAPACK_dtgsen LAPACK_GLOBAL(dtgsen,DTGSEN)
+#define LAPACK_ctgsen LAPACK_GLOBAL(ctgsen,CTGSEN)
+#define LAPACK_ztgsen LAPACK_GLOBAL(ztgsen,ZTGSEN)
+#define LAPACK_stgsyl LAPACK_GLOBAL(stgsyl,STGSYL)
+#define LAPACK_dtgsyl LAPACK_GLOBAL(dtgsyl,DTGSYL)
+#define LAPACK_ctgsyl LAPACK_GLOBAL(ctgsyl,CTGSYL)
+#define LAPACK_ztgsyl LAPACK_GLOBAL(ztgsyl,ZTGSYL)
+#define LAPACK_stgsna LAPACK_GLOBAL(stgsna,STGSNA)
+#define LAPACK_dtgsna LAPACK_GLOBAL(dtgsna,DTGSNA)
+#define LAPACK_ctgsna LAPACK_GLOBAL(ctgsna,CTGSNA)
+#define LAPACK_ztgsna LAPACK_GLOBAL(ztgsna,ZTGSNA)
+#define LAPACK_sggsvp LAPACK_GLOBAL(sggsvp,SGGSVP)
+#define LAPACK_dggsvp LAPACK_GLOBAL(dggsvp,DGGSVP)
+#define LAPACK_cggsvp LAPACK_GLOBAL(cggsvp,CGGSVP)
+#define LAPACK_zggsvp LAPACK_GLOBAL(zggsvp,ZGGSVP)
+#define LAPACK_stgsja LAPACK_GLOBAL(stgsja,STGSJA)
+#define LAPACK_dtgsja LAPACK_GLOBAL(dtgsja,DTGSJA)
+#define LAPACK_ctgsja LAPACK_GLOBAL(ctgsja,CTGSJA)
+#define LAPACK_ztgsja LAPACK_GLOBAL(ztgsja,ZTGSJA)
+#define LAPACK_sgels LAPACK_GLOBAL(sgels,SGELS)
+#define LAPACK_dgels LAPACK_GLOBAL(dgels,DGELS)
+#define LAPACK_cgels LAPACK_GLOBAL(cgels,CGELS)
+#define LAPACK_zgels LAPACK_GLOBAL(zgels,ZGELS)
+#define LAPACK_sgelsy LAPACK_GLOBAL(sgelsy,SGELSY)
+#define LAPACK_dgelsy LAPACK_GLOBAL(dgelsy,DGELSY)
+#define LAPACK_cgelsy LAPACK_GLOBAL(cgelsy,CGELSY)
+#define LAPACK_zgelsy LAPACK_GLOBAL(zgelsy,ZGELSY)
+#define LAPACK_sgelss LAPACK_GLOBAL(sgelss,SGELSS)
+#define LAPACK_dgelss LAPACK_GLOBAL(dgelss,DGELSS)
+#define LAPACK_cgelss LAPACK_GLOBAL(cgelss,CGELSS)
+#define LAPACK_zgelss LAPACK_GLOBAL(zgelss,ZGELSS)
+#define LAPACK_sgelsd LAPACK_GLOBAL(sgelsd,SGELSD)
+#define LAPACK_dgelsd LAPACK_GLOBAL(dgelsd,DGELSD)
+#define LAPACK_cgelsd LAPACK_GLOBAL(cgelsd,CGELSD)
+#define LAPACK_zgelsd LAPACK_GLOBAL(zgelsd,ZGELSD)
+#define LAPACK_sgglse LAPACK_GLOBAL(sgglse,SGGLSE)
+#define LAPACK_dgglse LAPACK_GLOBAL(dgglse,DGGLSE)
+#define LAPACK_cgglse LAPACK_GLOBAL(cgglse,CGGLSE)
+#define LAPACK_zgglse LAPACK_GLOBAL(zgglse,ZGGLSE)
+#define LAPACK_sggglm LAPACK_GLOBAL(sggglm,SGGGLM)
+#define LAPACK_dggglm LAPACK_GLOBAL(dggglm,DGGGLM)
+#define LAPACK_cggglm LAPACK_GLOBAL(cggglm,CGGGLM)
+#define LAPACK_zggglm LAPACK_GLOBAL(zggglm,ZGGGLM)
+#define LAPACK_ssyev LAPACK_GLOBAL(ssyev,SSYEV)
+#define LAPACK_dsyev LAPACK_GLOBAL(dsyev,DSYEV)
+#define LAPACK_cheev LAPACK_GLOBAL(cheev,CHEEV)
+#define LAPACK_zheev LAPACK_GLOBAL(zheev,ZHEEV)
+#define LAPACK_ssyevd LAPACK_GLOBAL(ssyevd,SSYEVD)
+#define LAPACK_dsyevd LAPACK_GLOBAL(dsyevd,DSYEVD)
+#define LAPACK_cheevd LAPACK_GLOBAL(cheevd,CHEEVD)
+#define LAPACK_zheevd LAPACK_GLOBAL(zheevd,ZHEEVD)
+#define LAPACK_ssyevx LAPACK_GLOBAL(ssyevx,SSYEVX)
+#define LAPACK_dsyevx LAPACK_GLOBAL(dsyevx,DSYEVX)
+#define LAPACK_cheevx LAPACK_GLOBAL(cheevx,CHEEVX)
+#define LAPACK_zheevx LAPACK_GLOBAL(zheevx,ZHEEVX)
+#define LAPACK_ssyevr LAPACK_GLOBAL(ssyevr,SSYEVR)
+#define LAPACK_dsyevr LAPACK_GLOBAL(dsyevr,DSYEVR)
+#define LAPACK_cheevr LAPACK_GLOBAL(cheevr,CHEEVR)
+#define LAPACK_zheevr LAPACK_GLOBAL(zheevr,ZHEEVR)
+#define LAPACK_sspev LAPACK_GLOBAL(sspev,SSPEV)
+#define LAPACK_dspev LAPACK_GLOBAL(dspev,DSPEV)
+#define LAPACK_chpev LAPACK_GLOBAL(chpev,CHPEV)
+#define LAPACK_zhpev LAPACK_GLOBAL(zhpev,ZHPEV)
+#define LAPACK_sspevd LAPACK_GLOBAL(sspevd,SSPEVD)
+#define LAPACK_dspevd LAPACK_GLOBAL(dspevd,DSPEVD)
+#define LAPACK_chpevd LAPACK_GLOBAL(chpevd,CHPEVD)
+#define LAPACK_zhpevd LAPACK_GLOBAL(zhpevd,ZHPEVD)
+#define LAPACK_sspevx LAPACK_GLOBAL(sspevx,SSPEVX)
+#define LAPACK_dspevx LAPACK_GLOBAL(dspevx,DSPEVX)
+#define LAPACK_chpevx LAPACK_GLOBAL(chpevx,CHPEVX)
+#define LAPACK_zhpevx LAPACK_GLOBAL(zhpevx,ZHPEVX)
+#define LAPACK_ssbev LAPACK_GLOBAL(ssbev,SSBEV)
+#define LAPACK_dsbev LAPACK_GLOBAL(dsbev,DSBEV)
+#define LAPACK_chbev LAPACK_GLOBAL(chbev,CHBEV)
+#define LAPACK_zhbev LAPACK_GLOBAL(zhbev,ZHBEV)
+#define LAPACK_ssbevd LAPACK_GLOBAL(ssbevd,SSBEVD)
+#define LAPACK_dsbevd LAPACK_GLOBAL(dsbevd,DSBEVD)
+#define LAPACK_chbevd LAPACK_GLOBAL(chbevd,CHBEVD)
+#define LAPACK_zhbevd LAPACK_GLOBAL(zhbevd,ZHBEVD)
+#define LAPACK_ssbevx LAPACK_GLOBAL(ssbevx,SSBEVX)
+#define LAPACK_dsbevx LAPACK_GLOBAL(dsbevx,DSBEVX)
+#define LAPACK_chbevx LAPACK_GLOBAL(chbevx,CHBEVX)
+#define LAPACK_zhbevx LAPACK_GLOBAL(zhbevx,ZHBEVX)
+#define LAPACK_sstev LAPACK_GLOBAL(sstev,SSTEV)
+#define LAPACK_dstev LAPACK_GLOBAL(dstev,DSTEV)
+#define LAPACK_sstevd LAPACK_GLOBAL(sstevd,SSTEVD)
+#define LAPACK_dstevd LAPACK_GLOBAL(dstevd,DSTEVD)
+#define LAPACK_sstevx LAPACK_GLOBAL(sstevx,SSTEVX)
+#define LAPACK_dstevx LAPACK_GLOBAL(dstevx,DSTEVX)
+#define LAPACK_sstevr LAPACK_GLOBAL(sstevr,SSTEVR)
+#define LAPACK_dstevr LAPACK_GLOBAL(dstevr,DSTEVR)
+#define LAPACK_sgees LAPACK_GLOBAL(sgees,SGEES)
+#define LAPACK_dgees LAPACK_GLOBAL(dgees,DGEES)
+#define LAPACK_cgees LAPACK_GLOBAL(cgees,CGEES)
+#define LAPACK_zgees LAPACK_GLOBAL(zgees,ZGEES)
+#define LAPACK_sgeesx LAPACK_GLOBAL(sgeesx,SGEESX)
+#define LAPACK_dgeesx LAPACK_GLOBAL(dgeesx,DGEESX)
+#define LAPACK_cgeesx LAPACK_GLOBAL(cgeesx,CGEESX)
+#define LAPACK_zgeesx LAPACK_GLOBAL(zgeesx,ZGEESX)
+#define LAPACK_sgeev LAPACK_GLOBAL(sgeev,SGEEV)
+#define LAPACK_dgeev LAPACK_GLOBAL(dgeev,DGEEV)
+#define LAPACK_cgeev LAPACK_GLOBAL(cgeev,CGEEV)
+#define LAPACK_zgeev LAPACK_GLOBAL(zgeev,ZGEEV)
+#define LAPACK_sgeevx LAPACK_GLOBAL(sgeevx,SGEEVX)
+#define LAPACK_dgeevx LAPACK_GLOBAL(dgeevx,DGEEVX)
+#define LAPACK_cgeevx LAPACK_GLOBAL(cgeevx,CGEEVX)
+#define LAPACK_zgeevx LAPACK_GLOBAL(zgeevx,ZGEEVX)
+#define LAPACK_sgesvd LAPACK_GLOBAL(sgesvd,SGESVD)
+#define LAPACK_dgesvd LAPACK_GLOBAL(dgesvd,DGESVD)
+#define LAPACK_cgesvd LAPACK_GLOBAL(cgesvd,CGESVD)
+#define LAPACK_zgesvd LAPACK_GLOBAL(zgesvd,ZGESVD)
+#define LAPACK_sgesdd LAPACK_GLOBAL(sgesdd,SGESDD)
+#define LAPACK_dgesdd LAPACK_GLOBAL(dgesdd,DGESDD)
+#define LAPACK_cgesdd LAPACK_GLOBAL(cgesdd,CGESDD)
+#define LAPACK_zgesdd LAPACK_GLOBAL(zgesdd,ZGESDD)
+#define LAPACK_dgejsv LAPACK_GLOBAL(dgejsv,DGEJSV)
+#define LAPACK_sgejsv LAPACK_GLOBAL(sgejsv,SGEJSV)
+#define LAPACK_dgesvj LAPACK_GLOBAL(dgesvj,DGESVJ)
+#define LAPACK_sgesvj LAPACK_GLOBAL(sgesvj,SGESVJ)
+#define LAPACK_sggsvd LAPACK_GLOBAL(sggsvd,SGGSVD)
+#define LAPACK_dggsvd LAPACK_GLOBAL(dggsvd,DGGSVD)
+#define LAPACK_cggsvd LAPACK_GLOBAL(cggsvd,CGGSVD)
+#define LAPACK_zggsvd LAPACK_GLOBAL(zggsvd,ZGGSVD)
+#define LAPACK_ssygv LAPACK_GLOBAL(ssygv,SSYGV)
+#define LAPACK_dsygv LAPACK_GLOBAL(dsygv,DSYGV)
+#define LAPACK_chegv LAPACK_GLOBAL(chegv,CHEGV)
+#define LAPACK_zhegv LAPACK_GLOBAL(zhegv,ZHEGV)
+#define LAPACK_ssygvd LAPACK_GLOBAL(ssygvd,SSYGVD)
+#define LAPACK_dsygvd LAPACK_GLOBAL(dsygvd,DSYGVD)
+#define LAPACK_chegvd LAPACK_GLOBAL(chegvd,CHEGVD)
+#define LAPACK_zhegvd LAPACK_GLOBAL(zhegvd,ZHEGVD)
+#define LAPACK_ssygvx LAPACK_GLOBAL(ssygvx,SSYGVX)
+#define LAPACK_dsygvx LAPACK_GLOBAL(dsygvx,DSYGVX)
+#define LAPACK_chegvx LAPACK_GLOBAL(chegvx,CHEGVX)
+#define LAPACK_zhegvx LAPACK_GLOBAL(zhegvx,ZHEGVX)
+#define LAPACK_sspgv LAPACK_GLOBAL(sspgv,SSPGV)
+#define LAPACK_dspgv LAPACK_GLOBAL(dspgv,DSPGV)
+#define LAPACK_chpgv LAPACK_GLOBAL(chpgv,CHPGV)
+#define LAPACK_zhpgv LAPACK_GLOBAL(zhpgv,ZHPGV)
+#define LAPACK_sspgvd LAPACK_GLOBAL(sspgvd,SSPGVD)
+#define LAPACK_dspgvd LAPACK_GLOBAL(dspgvd,DSPGVD)
+#define LAPACK_chpgvd LAPACK_GLOBAL(chpgvd,CHPGVD)
+#define LAPACK_zhpgvd LAPACK_GLOBAL(zhpgvd,ZHPGVD)
+#define LAPACK_sspgvx LAPACK_GLOBAL(sspgvx,SSPGVX)
+#define LAPACK_dspgvx LAPACK_GLOBAL(dspgvx,DSPGVX)
+#define LAPACK_chpgvx LAPACK_GLOBAL(chpgvx,CHPGVX)
+#define LAPACK_zhpgvx LAPACK_GLOBAL(zhpgvx,ZHPGVX)
+#define LAPACK_ssbgv LAPACK_GLOBAL(ssbgv,SSBGV)
+#define LAPACK_dsbgv LAPACK_GLOBAL(dsbgv,DSBGV)
+#define LAPACK_chbgv LAPACK_GLOBAL(chbgv,CHBGV)
+#define LAPACK_zhbgv LAPACK_GLOBAL(zhbgv,ZHBGV)
+#define LAPACK_ssbgvd LAPACK_GLOBAL(ssbgvd,SSBGVD)
+#define LAPACK_dsbgvd LAPACK_GLOBAL(dsbgvd,DSBGVD)
+#define LAPACK_chbgvd LAPACK_GLOBAL(chbgvd,CHBGVD)
+#define LAPACK_zhbgvd LAPACK_GLOBAL(zhbgvd,ZHBGVD)
+#define LAPACK_ssbgvx LAPACK_GLOBAL(ssbgvx,SSBGVX)
+#define LAPACK_dsbgvx LAPACK_GLOBAL(dsbgvx,DSBGVX)
+#define LAPACK_chbgvx LAPACK_GLOBAL(chbgvx,CHBGVX)
+#define LAPACK_zhbgvx LAPACK_GLOBAL(zhbgvx,ZHBGVX)
+#define LAPACK_sgges LAPACK_GLOBAL(sgges,SGGES)
+#define LAPACK_dgges LAPACK_GLOBAL(dgges,DGGES)
+#define LAPACK_cgges LAPACK_GLOBAL(cgges,CGGES)
+#define LAPACK_zgges LAPACK_GLOBAL(zgges,ZGGES)
+#define LAPACK_sggesx LAPACK_GLOBAL(sggesx,SGGESX)
+#define LAPACK_dggesx LAPACK_GLOBAL(dggesx,DGGESX)
+#define LAPACK_cggesx LAPACK_GLOBAL(cggesx,CGGESX)
+#define LAPACK_zggesx LAPACK_GLOBAL(zggesx,ZGGESX)
+#define LAPACK_sggev LAPACK_GLOBAL(sggev,SGGEV)
+#define LAPACK_dggev LAPACK_GLOBAL(dggev,DGGEV)
+#define LAPACK_cggev LAPACK_GLOBAL(cggev,CGGEV)
+#define LAPACK_zggev LAPACK_GLOBAL(zggev,ZGGEV)
+#define LAPACK_sggevx LAPACK_GLOBAL(sggevx,SGGEVX)
+#define LAPACK_dggevx LAPACK_GLOBAL(dggevx,DGGEVX)
+#define LAPACK_cggevx LAPACK_GLOBAL(cggevx,CGGEVX)
+#define LAPACK_zggevx LAPACK_GLOBAL(zggevx,ZGGEVX)
+#define LAPACK_dsfrk LAPACK_GLOBAL(dsfrk,DSFRK)
+#define LAPACK_ssfrk LAPACK_GLOBAL(ssfrk,SSFRK)
+#define LAPACK_zhfrk LAPACK_GLOBAL(zhfrk,ZHFRK)
+#define LAPACK_chfrk LAPACK_GLOBAL(chfrk,CHFRK)
+#define LAPACK_dtfsm LAPACK_GLOBAL(dtfsm,DTFSM)
+#define LAPACK_stfsm LAPACK_GLOBAL(stfsm,STFSM)
+#define LAPACK_ztfsm LAPACK_GLOBAL(ztfsm,ZTFSM)
+#define LAPACK_ctfsm LAPACK_GLOBAL(ctfsm,CTFSM)
+#define LAPACK_dtfttp LAPACK_GLOBAL(dtfttp,DTFTTP)
+#define LAPACK_stfttp LAPACK_GLOBAL(stfttp,STFTTP)
+#define LAPACK_ztfttp LAPACK_GLOBAL(ztfttp,ZTFTTP)
+#define LAPACK_ctfttp LAPACK_GLOBAL(ctfttp,CTFTTP)
+#define LAPACK_dtfttr LAPACK_GLOBAL(dtfttr,DTFTTR)
+#define LAPACK_stfttr LAPACK_GLOBAL(stfttr,STFTTR)
+#define LAPACK_ztfttr LAPACK_GLOBAL(ztfttr,ZTFTTR)
+#define LAPACK_ctfttr LAPACK_GLOBAL(ctfttr,CTFTTR)
+#define LAPACK_dtpttf LAPACK_GLOBAL(dtpttf,DTPTTF)
+#define LAPACK_stpttf LAPACK_GLOBAL(stpttf,STPTTF)
+#define LAPACK_ztpttf LAPACK_GLOBAL(ztpttf,ZTPTTF)
+#define LAPACK_ctpttf LAPACK_GLOBAL(ctpttf,CTPTTF)
+#define LAPACK_dtpttr LAPACK_GLOBAL(dtpttr,DTPTTR)
+#define LAPACK_stpttr LAPACK_GLOBAL(stpttr,STPTTR)
+#define LAPACK_ztpttr LAPACK_GLOBAL(ztpttr,ZTPTTR)
+#define LAPACK_ctpttr LAPACK_GLOBAL(ctpttr,CTPTTR)
+#define LAPACK_dtrttf LAPACK_GLOBAL(dtrttf,DTRTTF)
+#define LAPACK_strttf LAPACK_GLOBAL(strttf,STRTTF)
+#define LAPACK_ztrttf LAPACK_GLOBAL(ztrttf,ZTRTTF)
+#define LAPACK_ctrttf LAPACK_GLOBAL(ctrttf,CTRTTF)
+#define LAPACK_dtrttp LAPACK_GLOBAL(dtrttp,DTRTTP)
+#define LAPACK_strttp LAPACK_GLOBAL(strttp,STRTTP)
+#define LAPACK_ztrttp LAPACK_GLOBAL(ztrttp,ZTRTTP)
+#define LAPACK_ctrttp LAPACK_GLOBAL(ctrttp,CTRTTP)
+#define LAPACK_sgeqrfp LAPACK_GLOBAL(sgeqrfp,SGEQRFP)
+#define LAPACK_dgeqrfp LAPACK_GLOBAL(dgeqrfp,DGEQRFP)
+#define LAPACK_cgeqrfp LAPACK_GLOBAL(cgeqrfp,CGEQRFP)
+#define LAPACK_zgeqrfp LAPACK_GLOBAL(zgeqrfp,ZGEQRFP)
+#define LAPACK_clacgv LAPACK_GLOBAL(clacgv,CLACGV)
+#define LAPACK_zlacgv LAPACK_GLOBAL(zlacgv,ZLACGV)
+#define LAPACK_slarnv LAPACK_GLOBAL(slarnv,SLARNV)
+#define LAPACK_dlarnv LAPACK_GLOBAL(dlarnv,DLARNV)
+#define LAPACK_clarnv LAPACK_GLOBAL(clarnv,CLARNV)
+#define LAPACK_zlarnv LAPACK_GLOBAL(zlarnv,ZLARNV)
+#define LAPACK_sgeqr2 LAPACK_GLOBAL(sgeqr2,SGEQR2)
+#define LAPACK_dgeqr2 LAPACK_GLOBAL(dgeqr2,DGEQR2)
+#define LAPACK_cgeqr2 LAPACK_GLOBAL(cgeqr2,CGEQR2)
+#define LAPACK_zgeqr2 LAPACK_GLOBAL(zgeqr2,ZGEQR2)
+#define LAPACK_slacpy LAPACK_GLOBAL(slacpy,SLACPY)
+#define LAPACK_dlacpy LAPACK_GLOBAL(dlacpy,DLACPY)
+#define LAPACK_clacpy LAPACK_GLOBAL(clacpy,CLACPY)
+#define LAPACK_zlacpy LAPACK_GLOBAL(zlacpy,ZLACPY)
+#define LAPACK_sgetf2 LAPACK_GLOBAL(sgetf2,SGETF2)
+#define LAPACK_dgetf2 LAPACK_GLOBAL(dgetf2,DGETF2)
+#define LAPACK_cgetf2 LAPACK_GLOBAL(cgetf2,CGETF2)
+#define LAPACK_zgetf2 LAPACK_GLOBAL(zgetf2,ZGETF2)
+#define LAPACK_slaswp LAPACK_GLOBAL(slaswp,SLASWP)
+#define LAPACK_dlaswp LAPACK_GLOBAL(dlaswp,DLASWP)
+#define LAPACK_claswp LAPACK_GLOBAL(claswp,CLASWP)
+#define LAPACK_zlaswp LAPACK_GLOBAL(zlaswp,ZLASWP)
+#define LAPACK_slange LAPACK_GLOBAL(slange,SLANGE)
+#define LAPACK_dlange LAPACK_GLOBAL(dlange,DLANGE)
+#define LAPACK_clange LAPACK_GLOBAL(clange,CLANGE)
+#define LAPACK_zlange LAPACK_GLOBAL(zlange,ZLANGE)
+#define LAPACK_clanhe LAPACK_GLOBAL(clanhe,CLANHE)
+#define LAPACK_zlanhe LAPACK_GLOBAL(zlanhe,ZLANHE)
+#define LAPACK_slansy LAPACK_GLOBAL(slansy,SLANSY)
+#define LAPACK_dlansy LAPACK_GLOBAL(dlansy,DLANSY)
+#define LAPACK_clansy LAPACK_GLOBAL(clansy,CLANSY)
+#define LAPACK_zlansy LAPACK_GLOBAL(zlansy,ZLANSY)
+#define LAPACK_slantr LAPACK_GLOBAL(slantr,SLANTR)
+#define LAPACK_dlantr LAPACK_GLOBAL(dlantr,DLANTR)
+#define LAPACK_clantr LAPACK_GLOBAL(clantr,CLANTR)
+#define LAPACK_zlantr LAPACK_GLOBAL(zlantr,ZLANTR)
+#define LAPACK_slamch LAPACK_GLOBAL(slamch,SLAMCH)
+#define LAPACK_dlamch LAPACK_GLOBAL(dlamch,DLAMCH)
+#define LAPACK_sgelq2 LAPACK_GLOBAL(sgelq2,SGELQ2)
+#define LAPACK_dgelq2 LAPACK_GLOBAL(dgelq2,DGELQ2)
+#define LAPACK_cgelq2 LAPACK_GLOBAL(cgelq2,CGELQ2)
+#define LAPACK_zgelq2 LAPACK_GLOBAL(zgelq2,ZGELQ2)
+#define LAPACK_slarfb LAPACK_GLOBAL(slarfb,SLARFB)
+#define LAPACK_dlarfb LAPACK_GLOBAL(dlarfb,DLARFB)
+#define LAPACK_clarfb LAPACK_GLOBAL(clarfb,CLARFB)
+#define LAPACK_zlarfb LAPACK_GLOBAL(zlarfb,ZLARFB)
+#define LAPACK_slarfg LAPACK_GLOBAL(slarfg,SLARFG)
+#define LAPACK_dlarfg LAPACK_GLOBAL(dlarfg,DLARFG)
+#define LAPACK_clarfg LAPACK_GLOBAL(clarfg,CLARFG)
+#define LAPACK_zlarfg LAPACK_GLOBAL(zlarfg,ZLARFG)
+#define LAPACK_slarft LAPACK_GLOBAL(slarft,SLARFT)
+#define LAPACK_dlarft LAPACK_GLOBAL(dlarft,DLARFT)
+#define LAPACK_clarft LAPACK_GLOBAL(clarft,CLARFT)
+#define LAPACK_zlarft LAPACK_GLOBAL(zlarft,ZLARFT)
+#define LAPACK_slarfx LAPACK_GLOBAL(slarfx,SLARFX)
+#define LAPACK_dlarfx LAPACK_GLOBAL(dlarfx,DLARFX)
+#define LAPACK_clarfx LAPACK_GLOBAL(clarfx,CLARFX)
+#define LAPACK_zlarfx LAPACK_GLOBAL(zlarfx,ZLARFX)
+#define LAPACK_slatms LAPACK_GLOBAL(slatms,SLATMS)
+#define LAPACK_dlatms LAPACK_GLOBAL(dlatms,DLATMS)
+#define LAPACK_clatms LAPACK_GLOBAL(clatms,CLATMS)
+#define LAPACK_zlatms LAPACK_GLOBAL(zlatms,ZLATMS)
+#define LAPACK_slag2d LAPACK_GLOBAL(slag2d,SLAG2D)
+#define LAPACK_dlag2s LAPACK_GLOBAL(dlag2s,DLAG2S)
+#define LAPACK_clag2z LAPACK_GLOBAL(clag2z,CLAG2Z)
+#define LAPACK_zlag2c LAPACK_GLOBAL(zlag2c,ZLAG2C)
+#define LAPACK_slauum LAPACK_GLOBAL(slauum,SLAUUM)
+#define LAPACK_dlauum LAPACK_GLOBAL(dlauum,DLAUUM)
+#define LAPACK_clauum LAPACK_GLOBAL(clauum,CLAUUM)
+#define LAPACK_zlauum LAPACK_GLOBAL(zlauum,ZLAUUM)
+#define LAPACK_slagge LAPACK_GLOBAL(slagge,SLAGGE)
+#define LAPACK_dlagge LAPACK_GLOBAL(dlagge,DLAGGE)
+#define LAPACK_clagge LAPACK_GLOBAL(clagge,CLAGGE)
+#define LAPACK_zlagge LAPACK_GLOBAL(zlagge,ZLAGGE)
+#define LAPACK_slaset LAPACK_GLOBAL(slaset,SLASET)
+#define LAPACK_dlaset LAPACK_GLOBAL(dlaset,DLASET)
+#define LAPACK_claset LAPACK_GLOBAL(claset,CLASET)
+#define LAPACK_zlaset LAPACK_GLOBAL(zlaset,ZLASET)
+#define LAPACK_slasrt LAPACK_GLOBAL(slasrt,SLASRT)
+#define LAPACK_dlasrt LAPACK_GLOBAL(dlasrt,DLASRT)
+#define LAPACK_slagsy LAPACK_GLOBAL(slagsy,SLAGSY)
+#define LAPACK_dlagsy LAPACK_GLOBAL(dlagsy,DLAGSY)
+#define LAPACK_clagsy LAPACK_GLOBAL(clagsy,CLAGSY)
+#define LAPACK_zlagsy LAPACK_GLOBAL(zlagsy,ZLAGSY)
+#define LAPACK_claghe LAPACK_GLOBAL(claghe,CLAGHE)
+#define LAPACK_zlaghe LAPACK_GLOBAL(zlaghe,ZLAGHE)
+#define LAPACK_slapmr LAPACK_GLOBAL(slapmr,SLAPMR)
+#define LAPACK_dlapmr LAPACK_GLOBAL(dlapmr,DLAPMR)
+#define LAPACK_clapmr LAPACK_GLOBAL(clapmr,CLAPMR)
+#define LAPACK_zlapmr LAPACK_GLOBAL(zlapmr,ZLAPMR)
+#define LAPACK_slapy2 LAPACK_GLOBAL(slapy2,SLAPY2)
+#define LAPACK_dlapy2 LAPACK_GLOBAL(dlapy2,DLAPY2)
+#define LAPACK_slapy3 LAPACK_GLOBAL(slapy3,SLAPY3)
+#define LAPACK_dlapy3 LAPACK_GLOBAL(dlapy3,DLAPY3)
+#define LAPACK_slartgp LAPACK_GLOBAL(slartgp,SLARTGP)
+#define LAPACK_dlartgp LAPACK_GLOBAL(dlartgp,DLARTGP)
+#define LAPACK_slartgs LAPACK_GLOBAL(slartgs,SLARTGS)
+#define LAPACK_dlartgs LAPACK_GLOBAL(dlartgs,DLARTGS)
+// LAPACK 3.3.0
+#define LAPACK_cbbcsd LAPACK_GLOBAL(cbbcsd,CBBCSD)
+#define LAPACK_cheswapr LAPACK_GLOBAL(cheswapr,CHESWAPR)
+#define LAPACK_chetri2 LAPACK_GLOBAL(chetri2,CHETRI2)
+#define LAPACK_chetri2x LAPACK_GLOBAL(chetri2x,CHETRI2X)
+#define LAPACK_chetrs2 LAPACK_GLOBAL(chetrs2,CHETRS2)
+#define LAPACK_csyconv LAPACK_GLOBAL(csyconv,CSYCONV)
+#define LAPACK_csyswapr LAPACK_GLOBAL(csyswapr,CSYSWAPR)
+#define LAPACK_csytri2 LAPACK_GLOBAL(csytri2,CSYTRI2)
+#define LAPACK_csytri2x LAPACK_GLOBAL(csytri2x,CSYTRI2X)
+#define LAPACK_csytrs2 LAPACK_GLOBAL(csytrs2,CSYTRS2)
+#define LAPACK_cunbdb LAPACK_GLOBAL(cunbdb,CUNBDB)
+#define LAPACK_cuncsd LAPACK_GLOBAL(cuncsd,CUNCSD)
+#define LAPACK_dbbcsd LAPACK_GLOBAL(dbbcsd,DBBCSD)
+#define LAPACK_dorbdb LAPACK_GLOBAL(dorbdb,DORBDB)
+#define LAPACK_dorcsd LAPACK_GLOBAL(dorcsd,DORCSD)
+#define LAPACK_dsyconv LAPACK_GLOBAL(dsyconv,DSYCONV)
+#define LAPACK_dsyswapr LAPACK_GLOBAL(dsyswapr,DSYSWAPR)
+#define LAPACK_dsytri2 LAPACK_GLOBAL(dsytri2,DSYTRI2)
+#define LAPACK_dsytri2x LAPACK_GLOBAL(dsytri2x,DSYTRI2X)
+#define LAPACK_dsytrs2 LAPACK_GLOBAL(dsytrs2,DSYTRS2)
+#define LAPACK_sbbcsd LAPACK_GLOBAL(sbbcsd,SBBCSD)
+#define LAPACK_sorbdb LAPACK_GLOBAL(sorbdb,SORBDB)
+#define LAPACK_sorcsd LAPACK_GLOBAL(sorcsd,SORCSD)
+#define LAPACK_ssyconv LAPACK_GLOBAL(ssyconv,SSYCONV)
+#define LAPACK_ssyswapr LAPACK_GLOBAL(ssyswapr,SSYSWAPR)
+#define LAPACK_ssytri2 LAPACK_GLOBAL(ssytri2,SSYTRI2)
+#define LAPACK_ssytri2x LAPACK_GLOBAL(ssytri2x,SSYTRI2X)
+#define LAPACK_ssytrs2 LAPACK_GLOBAL(ssytrs2,SSYTRS2)
+#define LAPACK_zbbcsd LAPACK_GLOBAL(zbbcsd,ZBBCSD)
+#define LAPACK_zheswapr LAPACK_GLOBAL(zheswapr,ZHESWAPR)
+#define LAPACK_zhetri2 LAPACK_GLOBAL(zhetri2,ZHETRI2)
+#define LAPACK_zhetri2x LAPACK_GLOBAL(zhetri2x,ZHETRI2X)
+#define LAPACK_zhetrs2 LAPACK_GLOBAL(zhetrs2,ZHETRS2)
+#define LAPACK_zsyconv LAPACK_GLOBAL(zsyconv,ZSYCONV)
+#define LAPACK_zsyswapr LAPACK_GLOBAL(zsyswapr,ZSYSWAPR)
+#define LAPACK_zsytri2 LAPACK_GLOBAL(zsytri2,ZSYTRI2)
+#define LAPACK_zsytri2x LAPACK_GLOBAL(zsytri2x,ZSYTRI2X)
+#define LAPACK_zsytrs2 LAPACK_GLOBAL(zsytrs2,ZSYTRS2)
+#define LAPACK_zunbdb LAPACK_GLOBAL(zunbdb,ZUNBDB)
+#define LAPACK_zuncsd LAPACK_GLOBAL(zuncsd,ZUNCSD)
+// LAPACK 3.4.0
+#define LAPACK_sgemqrt LAPACK_GLOBAL(sgemqrt,SGEMQRT)
+#define LAPACK_dgemqrt LAPACK_GLOBAL(dgemqrt,DGEMQRT)
+#define LAPACK_cgemqrt LAPACK_GLOBAL(cgemqrt,CGEMQRT)
+#define LAPACK_zgemqrt LAPACK_GLOBAL(zgemqrt,ZGEMQRT)
+#define LAPACK_sgeqrt LAPACK_GLOBAL(sgeqrt,SGEQRT)
+#define LAPACK_dgeqrt LAPACK_GLOBAL(dgeqrt,DGEQRT)
+#define LAPACK_cgeqrt LAPACK_GLOBAL(cgeqrt,CGEQRT)
+#define LAPACK_zgeqrt LAPACK_GLOBAL(zgeqrt,ZGEQRT)
+#define LAPACK_sgeqrt2 LAPACK_GLOBAL(sgeqrt2,SGEQRT2)
+#define LAPACK_dgeqrt2 LAPACK_GLOBAL(dgeqrt2,DGEQRT2)
+#define LAPACK_cgeqrt2 LAPACK_GLOBAL(cgeqrt2,CGEQRT2)
+#define LAPACK_zgeqrt2 LAPACK_GLOBAL(zgeqrt2,ZGEQRT2)
+#define LAPACK_sgeqrt3 LAPACK_GLOBAL(sgeqrt3,SGEQRT3)
+#define LAPACK_dgeqrt3 LAPACK_GLOBAL(dgeqrt3,DGEQRT3)
+#define LAPACK_cgeqrt3 LAPACK_GLOBAL(cgeqrt3,CGEQRT3)
+#define LAPACK_zgeqrt3 LAPACK_GLOBAL(zgeqrt3,ZGEQRT3)
+#define LAPACK_stpmqrt LAPACK_GLOBAL(stpmqrt,STPMQRT)
+#define LAPACK_dtpmqrt LAPACK_GLOBAL(dtpmqrt,DTPMQRT)
+#define LAPACK_ctpmqrt LAPACK_GLOBAL(ctpmqrt,CTPMQRT)
+#define LAPACK_ztpmqrt LAPACK_GLOBAL(ztpmqrt,ZTPMQRT)
+#define LAPACK_dtpqrt LAPACK_GLOBAL(dtpqrt,DTPQRT)
+#define LAPACK_ctpqrt LAPACK_GLOBAL(ctpqrt,CTPQRT)
+#define LAPACK_ztpqrt LAPACK_GLOBAL(ztpqrt,ZTPQRT)
+#define LAPACK_stpqrt2 LAPACK_GLOBAL(stpqrt2,STPQRT2)
+#define LAPACK_dtpqrt2 LAPACK_GLOBAL(dtpqrt2,DTPQRT2)
+#define LAPACK_ctpqrt2 LAPACK_GLOBAL(ctpqrt2,CTPQRT2)
+#define LAPACK_ztpqrt2 LAPACK_GLOBAL(ztpqrt2,ZTPQRT2)
+#define LAPACK_stprfb LAPACK_GLOBAL(stprfb,STPRFB)
+#define LAPACK_dtprfb LAPACK_GLOBAL(dtprfb,DTPRFB)
+#define LAPACK_ctprfb LAPACK_GLOBAL(ctprfb,CTPRFB)
+#define LAPACK_ztprfb LAPACK_GLOBAL(ztprfb,ZTPRFB)
+// LAPACK 3.X.X
+#define LAPACK_csyr LAPACK_GLOBAL(csyr,CSYR)
+#define LAPACK_zsyr LAPACK_GLOBAL(zsyr,ZSYR)
+
+
+void LAPACK_sgetrf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_dgetrf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_cgetrf( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int* ipiv, lapack_int *info );
+void LAPACK_zgetrf( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* ipiv, lapack_int *info );
+void LAPACK_sgbtrf( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, float* ab, lapack_int* ldab,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_dgbtrf( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, double* ab, lapack_int* ldab,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_cgbtrf( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_complex_float* ab, lapack_int* ldab,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_zgbtrf( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_complex_double* ab, lapack_int* ldab,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_sgttrf( lapack_int* n, float* dl, float* d, float* du, float* du2,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_dgttrf( lapack_int* n, double* dl, double* d, double* du,
+ double* du2, lapack_int* ipiv, lapack_int *info );
+void LAPACK_cgttrf( lapack_int* n, lapack_complex_float* dl,
+ lapack_complex_float* d, lapack_complex_float* du,
+ lapack_complex_float* du2, lapack_int* ipiv,
+ lapack_int *info );
+void LAPACK_zgttrf( lapack_int* n, lapack_complex_double* dl,
+ lapack_complex_double* d, lapack_complex_double* du,
+ lapack_complex_double* du2, lapack_int* ipiv,
+ lapack_int *info );
+void LAPACK_spotrf( char* uplo, lapack_int* n, float* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_dpotrf( char* uplo, lapack_int* n, double* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_cpotrf( char* uplo, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_zpotrf( char* uplo, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_dpstrf( char* uplo, lapack_int* n, double* a, lapack_int* lda,
+ lapack_int* piv, lapack_int* rank, double* tol,
+ double* work, lapack_int *info );
+void LAPACK_spstrf( char* uplo, lapack_int* n, float* a, lapack_int* lda,
+ lapack_int* piv, lapack_int* rank, float* tol, float* work,
+ lapack_int *info );
+void LAPACK_zpstrf( char* uplo, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* piv, lapack_int* rank,
+ double* tol, double* work, lapack_int *info );
+void LAPACK_cpstrf( char* uplo, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int* piv, lapack_int* rank,
+ float* tol, float* work, lapack_int *info );
+void LAPACK_dpftrf( char* transr, char* uplo, lapack_int* n, double* a,
+ lapack_int *info );
+void LAPACK_spftrf( char* transr, char* uplo, lapack_int* n, float* a,
+ lapack_int *info );
+void LAPACK_zpftrf( char* transr, char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int *info );
+void LAPACK_cpftrf( char* transr, char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int *info );
+void LAPACK_spptrf( char* uplo, lapack_int* n, float* ap, lapack_int *info );
+void LAPACK_dpptrf( char* uplo, lapack_int* n, double* ap, lapack_int *info );
+void LAPACK_cpptrf( char* uplo, lapack_int* n, lapack_complex_float* ap,
+ lapack_int *info );
+void LAPACK_zpptrf( char* uplo, lapack_int* n, lapack_complex_double* ap,
+ lapack_int *info );
+void LAPACK_spbtrf( char* uplo, lapack_int* n, lapack_int* kd, float* ab,
+ lapack_int* ldab, lapack_int *info );
+void LAPACK_dpbtrf( char* uplo, lapack_int* n, lapack_int* kd, double* ab,
+ lapack_int* ldab, lapack_int *info );
+void LAPACK_cpbtrf( char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_complex_float* ab, lapack_int* ldab,
+ lapack_int *info );
+void LAPACK_zpbtrf( char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_complex_double* ab, lapack_int* ldab,
+ lapack_int *info );
+void LAPACK_spttrf( lapack_int* n, float* d, float* e, lapack_int *info );
+void LAPACK_dpttrf( lapack_int* n, double* d, double* e, lapack_int *info );
+void LAPACK_cpttrf( lapack_int* n, float* d, lapack_complex_float* e,
+ lapack_int *info );
+void LAPACK_zpttrf( lapack_int* n, double* d, lapack_complex_double* e,
+ lapack_int *info );
+void LAPACK_ssytrf( char* uplo, lapack_int* n, float* a, lapack_int* lda,
+ lapack_int* ipiv, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dsytrf( char* uplo, lapack_int* n, double* a, lapack_int* lda,
+ lapack_int* ipiv, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_csytrf( char* uplo, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zsytrf( char* uplo, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_chetrf( char* uplo, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zhetrf( char* uplo, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_ssptrf( char* uplo, lapack_int* n, float* ap, lapack_int* ipiv,
+ lapack_int *info );
+void LAPACK_dsptrf( char* uplo, lapack_int* n, double* ap, lapack_int* ipiv,
+ lapack_int *info );
+void LAPACK_csptrf( char* uplo, lapack_int* n, lapack_complex_float* ap,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_zsptrf( char* uplo, lapack_int* n, lapack_complex_double* ap,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_chptrf( char* uplo, lapack_int* n, lapack_complex_float* ap,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_zhptrf( char* uplo, lapack_int* n, lapack_complex_double* ap,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_sgetrs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const float* a, lapack_int* lda, const lapack_int* ipiv,
+ float* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_dgetrs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const double* a, lapack_int* lda, const lapack_int* ipiv,
+ double* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_cgetrs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_zgetrs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_sgbtrs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, const float* ab, lapack_int* ldab,
+ const lapack_int* ipiv, float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dgbtrs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, const double* ab, lapack_int* ldab,
+ const lapack_int* ipiv, double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_cgbtrs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, const lapack_complex_float* ab,
+ lapack_int* ldab, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_zgbtrs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, const lapack_complex_double* ab,
+ lapack_int* ldab, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_sgttrs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const float* dl, const float* d, const float* du,
+ const float* du2, const lapack_int* ipiv, float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_dgttrs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const double* dl, const double* d, const double* du,
+ const double* du2, const lapack_int* ipiv, double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_cgttrs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du,
+ const lapack_complex_float* du2, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_zgttrs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du,
+ const lapack_complex_double* du2, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_spotrs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* a,
+ lapack_int* lda, float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dpotrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* a, lapack_int* lda, double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_cpotrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_zpotrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dpftrs( char* transr, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* a, double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_spftrs( char* transr, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const float* a, float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_zpftrs( char* transr, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_complex_double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_cpftrs( char* transr, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_complex_float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_spptrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const float* ap, float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dpptrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* ap, double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_cpptrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* ap, lapack_complex_float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_zpptrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* ap, lapack_complex_double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_spbtrs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ const float* ab, lapack_int* ldab, float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_dpbtrs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ const double* ab, lapack_int* ldab, double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_cpbtrs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ const lapack_complex_float* ab, lapack_int* ldab,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_zpbtrs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ const lapack_complex_double* ab, lapack_int* ldab,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_spttrs( lapack_int* n, lapack_int* nrhs, const float* d,
+ const float* e, float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dpttrs( lapack_int* n, lapack_int* nrhs, const double* d,
+ const double* e, double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_cpttrs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* d,
+ const lapack_complex_float* e, lapack_complex_float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_zpttrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* d, const lapack_complex_double* e,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_ssytrs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* a,
+ lapack_int* lda, const lapack_int* ipiv, float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_dsytrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* a, lapack_int* lda, const lapack_int* ipiv,
+ double* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_csytrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_zsytrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_chetrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_zhetrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_ssptrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const float* ap, const lapack_int* ipiv, float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_dsptrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* ap, const lapack_int* ipiv, double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_csptrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* ap, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_zsptrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* ap, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_chptrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* ap, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_zhptrs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* ap, const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_strtrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const float* a, lapack_int* lda, float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_dtrtrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const double* a, lapack_int* lda,
+ double* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_ctrtrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_ztrtrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_stptrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const float* ap, float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_dtptrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const double* ap, double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_ctptrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const lapack_complex_float* ap,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_ztptrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const lapack_complex_double* ap,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_stbtrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* kd, lapack_int* nrhs, const float* ab,
+ lapack_int* ldab, float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dtbtrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* kd, lapack_int* nrhs, const double* ab,
+ lapack_int* ldab, double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_ctbtrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* kd, lapack_int* nrhs,
+ const lapack_complex_float* ab, lapack_int* ldab,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_ztbtrs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* kd, lapack_int* nrhs,
+ const lapack_complex_double* ab, lapack_int* ldab,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_sgecon( char* norm, lapack_int* n, const float* a, lapack_int* lda,
+ float* anorm, float* rcond, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dgecon( char* norm, lapack_int* n, const double* a, lapack_int* lda,
+ double* anorm, double* rcond, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_cgecon( char* norm, lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, float* anorm, float* rcond,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zgecon( char* norm, lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, double* anorm, double* rcond,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_sgbcon( char* norm, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ const float* ab, lapack_int* ldab, const lapack_int* ipiv,
+ float* anorm, float* rcond, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dgbcon( char* norm, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ const double* ab, lapack_int* ldab, const lapack_int* ipiv,
+ double* anorm, double* rcond, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_cgbcon( char* norm, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ const lapack_complex_float* ab, lapack_int* ldab,
+ const lapack_int* ipiv, float* anorm, float* rcond,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zgbcon( char* norm, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ const lapack_complex_double* ab, lapack_int* ldab,
+ const lapack_int* ipiv, double* anorm, double* rcond,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_sgtcon( char* norm, lapack_int* n, const float* dl, const float* d,
+ const float* du, const float* du2, const lapack_int* ipiv,
+ float* anorm, float* rcond, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dgtcon( char* norm, lapack_int* n, const double* dl,
+ const double* d, const double* du, const double* du2,
+ const lapack_int* ipiv, double* anorm, double* rcond,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_cgtcon( char* norm, lapack_int* n, const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du,
+ const lapack_complex_float* du2, const lapack_int* ipiv,
+ float* anorm, float* rcond, lapack_complex_float* work,
+ lapack_int *info );
+void LAPACK_zgtcon( char* norm, lapack_int* n, const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du,
+ const lapack_complex_double* du2, const lapack_int* ipiv,
+ double* anorm, double* rcond, lapack_complex_double* work,
+ lapack_int *info );
+void LAPACK_spocon( char* uplo, lapack_int* n, const float* a, lapack_int* lda,
+ float* anorm, float* rcond, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dpocon( char* uplo, lapack_int* n, const double* a, lapack_int* lda,
+ double* anorm, double* rcond, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_cpocon( char* uplo, lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, float* anorm, float* rcond,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zpocon( char* uplo, lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, double* anorm, double* rcond,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_sppcon( char* uplo, lapack_int* n, const float* ap, float* anorm,
+ float* rcond, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dppcon( char* uplo, lapack_int* n, const double* ap, double* anorm,
+ double* rcond, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_cppcon( char* uplo, lapack_int* n, const lapack_complex_float* ap,
+ float* anorm, float* rcond, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_zppcon( char* uplo, lapack_int* n, const lapack_complex_double* ap,
+ double* anorm, double* rcond, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_spbcon( char* uplo, lapack_int* n, lapack_int* kd, const float* ab,
+ lapack_int* ldab, float* anorm, float* rcond, float* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_dpbcon( char* uplo, lapack_int* n, lapack_int* kd, const double* ab,
+ lapack_int* ldab, double* anorm, double* rcond,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_cpbcon( char* uplo, lapack_int* n, lapack_int* kd,
+ const lapack_complex_float* ab, lapack_int* ldab,
+ float* anorm, float* rcond, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_zpbcon( char* uplo, lapack_int* n, lapack_int* kd,
+ const lapack_complex_double* ab, lapack_int* ldab,
+ double* anorm, double* rcond, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_sptcon( lapack_int* n, const float* d, const float* e, float* anorm,
+ float* rcond, float* work, lapack_int *info );
+void LAPACK_dptcon( lapack_int* n, const double* d, const double* e,
+ double* anorm, double* rcond, double* work,
+ lapack_int *info );
+void LAPACK_cptcon( lapack_int* n, const float* d,
+ const lapack_complex_float* e, float* anorm, float* rcond,
+ float* work, lapack_int *info );
+void LAPACK_zptcon( lapack_int* n, const double* d,
+ const lapack_complex_double* e, double* anorm,
+ double* rcond, double* work, lapack_int *info );
+void LAPACK_ssycon( char* uplo, lapack_int* n, const float* a, lapack_int* lda,
+ const lapack_int* ipiv, float* anorm, float* rcond,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_dsycon( char* uplo, lapack_int* n, const double* a, lapack_int* lda,
+ const lapack_int* ipiv, double* anorm, double* rcond,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_csycon( char* uplo, lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_int* ipiv, float* anorm,
+ float* rcond, lapack_complex_float* work,
+ lapack_int *info );
+void LAPACK_zsycon( char* uplo, lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, const lapack_int* ipiv, double* anorm,
+ double* rcond, lapack_complex_double* work,
+ lapack_int *info );
+void LAPACK_checon( char* uplo, lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_int* ipiv, float* anorm,
+ float* rcond, lapack_complex_float* work,
+ lapack_int *info );
+void LAPACK_zhecon( char* uplo, lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, const lapack_int* ipiv, double* anorm,
+ double* rcond, lapack_complex_double* work,
+ lapack_int *info );
+void LAPACK_sspcon( char* uplo, lapack_int* n, const float* ap,
+ const lapack_int* ipiv, float* anorm, float* rcond,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_dspcon( char* uplo, lapack_int* n, const double* ap,
+ const lapack_int* ipiv, double* anorm, double* rcond,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_cspcon( char* uplo, lapack_int* n, const lapack_complex_float* ap,
+ const lapack_int* ipiv, float* anorm, float* rcond,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zspcon( char* uplo, lapack_int* n, const lapack_complex_double* ap,
+ const lapack_int* ipiv, double* anorm, double* rcond,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_chpcon( char* uplo, lapack_int* n, const lapack_complex_float* ap,
+ const lapack_int* ipiv, float* anorm, float* rcond,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zhpcon( char* uplo, lapack_int* n, const lapack_complex_double* ap,
+ const lapack_int* ipiv, double* anorm, double* rcond,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_strcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ const float* a, lapack_int* lda, float* rcond, float* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_dtrcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ const double* a, lapack_int* lda, double* rcond,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_ctrcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ const lapack_complex_float* a, lapack_int* lda,
+ float* rcond, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_ztrcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ const lapack_complex_double* a, lapack_int* lda,
+ double* rcond, lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_stpcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ const float* ap, float* rcond, float* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_dtpcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ const double* ap, double* rcond, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_ctpcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ const lapack_complex_float* ap, float* rcond,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_ztpcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ const lapack_complex_double* ap, double* rcond,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_stbcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ lapack_int* kd, const float* ab, lapack_int* ldab,
+ float* rcond, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dtbcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ lapack_int* kd, const double* ab, lapack_int* ldab,
+ double* rcond, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_ctbcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ lapack_int* kd, const lapack_complex_float* ab,
+ lapack_int* ldab, float* rcond, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_ztbcon( char* norm, char* uplo, char* diag, lapack_int* n,
+ lapack_int* kd, const lapack_complex_double* ab,
+ lapack_int* ldab, double* rcond,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_sgerfs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const float* a, lapack_int* lda, const float* af,
+ lapack_int* ldaf, const lapack_int* ipiv, const float* b,
+ lapack_int* ldb, float* x, lapack_int* ldx, float* ferr,
+ float* berr, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dgerfs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const double* a, lapack_int* lda, const double* af,
+ lapack_int* ldaf, const lapack_int* ipiv, const double* b,
+ lapack_int* ldb, double* x, lapack_int* ldx, double* ferr,
+ double* berr, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_cgerfs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx,
+ float* ferr, float* berr, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_zgerfs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx,
+ double* ferr, double* berr, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_dgerfsx( char* trans, char* equed, lapack_int* n, lapack_int* nrhs,
+ const double* a, lapack_int* lda, const double* af,
+ lapack_int* ldaf, const lapack_int* ipiv, const double* r,
+ const double* c, const double* b, lapack_int* ldb,
+ double* x, lapack_int* ldx, double* rcond, double* berr,
+ lapack_int* n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int* nparams, double* params,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_sgerfsx( char* trans, char* equed, lapack_int* n, lapack_int* nrhs,
+ const float* a, lapack_int* lda, const float* af,
+ lapack_int* ldaf, const lapack_int* ipiv, const float* r,
+ const float* c, const float* b, lapack_int* ldb, float* x,
+ lapack_int* ldx, float* rcond, float* berr,
+ lapack_int* n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int* nparams, float* params,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_zgerfsx( char* trans, char* equed, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const double* r, const double* c,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_cgerfsx( char* trans, char* equed, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const float* r, const float* c,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* berr, lapack_int* n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int* nparams, float* params,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_sgbrfs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, const float* ab, lapack_int* ldab,
+ const float* afb, lapack_int* ldafb, const lapack_int* ipiv,
+ const float* b, lapack_int* ldb, float* x, lapack_int* ldx,
+ float* ferr, float* berr, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dgbrfs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, const double* ab, lapack_int* ldab,
+ const double* afb, lapack_int* ldafb,
+ const lapack_int* ipiv, const double* b, lapack_int* ldb,
+ double* x, lapack_int* ldx, double* ferr, double* berr,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_cgbrfs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, const lapack_complex_float* ab,
+ lapack_int* ldab, const lapack_complex_float* afb,
+ lapack_int* ldafb, const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* ferr,
+ float* berr, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zgbrfs( char* trans, lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, const lapack_complex_double* ab,
+ lapack_int* ldab, const lapack_complex_double* afb,
+ lapack_int* ldafb, const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* ferr,
+ double* berr, lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_dgbrfsx( char* trans, char* equed, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs, const double* ab,
+ lapack_int* ldab, const double* afb, lapack_int* ldafb,
+ const lapack_int* ipiv, const double* r, const double* c,
+ const double* b, lapack_int* ldb, double* x,
+ lapack_int* ldx, double* rcond, double* berr,
+ lapack_int* n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int* nparams, double* params,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_sgbrfsx( char* trans, char* equed, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs, const float* ab,
+ lapack_int* ldab, const float* afb, lapack_int* ldafb,
+ const lapack_int* ipiv, const float* r, const float* c,
+ const float* b, lapack_int* ldb, float* x, lapack_int* ldx,
+ float* rcond, float* berr, lapack_int* n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int* nparams, float* params, float* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_zgbrfsx( char* trans, char* equed, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs,
+ const lapack_complex_double* ab, lapack_int* ldab,
+ const lapack_complex_double* afb, lapack_int* ldafb,
+ const lapack_int* ipiv, const double* r, const double* c,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_cgbrfsx( char* trans, char* equed, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs,
+ const lapack_complex_float* ab, lapack_int* ldab,
+ const lapack_complex_float* afb, lapack_int* ldafb,
+ const lapack_int* ipiv, const float* r, const float* c,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* berr, lapack_int* n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int* nparams, float* params,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_sgtrfs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const float* dl, const float* d, const float* du,
+ const float* dlf, const float* df, const float* duf,
+ const float* du2, const lapack_int* ipiv, const float* b,
+ lapack_int* ldb, float* x, lapack_int* ldx, float* ferr,
+ float* berr, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dgtrfs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const double* dl, const double* d, const double* du,
+ const double* dlf, const double* df, const double* duf,
+ const double* du2, const lapack_int* ipiv, const double* b,
+ lapack_int* ldb, double* x, lapack_int* ldx, double* ferr,
+ double* berr, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_cgtrfs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du,
+ const lapack_complex_float* dlf,
+ const lapack_complex_float* df,
+ const lapack_complex_float* duf,
+ const lapack_complex_float* du2, const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* ferr,
+ float* berr, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zgtrfs( char* trans, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du,
+ const lapack_complex_double* dlf,
+ const lapack_complex_double* df,
+ const lapack_complex_double* duf,
+ const lapack_complex_double* du2, const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* ferr,
+ double* berr, lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_sporfs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* a,
+ lapack_int* lda, const float* af, lapack_int* ldaf,
+ const float* b, lapack_int* ldb, float* x, lapack_int* ldx,
+ float* ferr, float* berr, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dporfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* a, lapack_int* lda, const double* af,
+ lapack_int* ldaf, const double* b, lapack_int* ldb,
+ double* x, lapack_int* ldx, double* ferr, double* berr,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_cporfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* af, lapack_int* ldaf,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* ferr,
+ float* berr, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zporfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* af, lapack_int* ldaf,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* ferr,
+ double* berr, lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_dporfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs,
+ const double* a, lapack_int* lda, const double* af,
+ lapack_int* ldaf, const double* s, const double* b,
+ lapack_int* ldb, double* x, lapack_int* ldx, double* rcond,
+ double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_sporfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs,
+ const float* a, lapack_int* lda, const float* af,
+ lapack_int* ldaf, const float* s, const float* b,
+ lapack_int* ldb, float* x, lapack_int* ldx, float* rcond,
+ float* berr, lapack_int* n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int* nparams, float* params,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_zporfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* af, lapack_int* ldaf,
+ const double* s, const lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx,
+ double* rcond, double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_cporfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* af, lapack_int* ldaf,
+ const float* s, const lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx,
+ float* rcond, float* berr, lapack_int* n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int* nparams, float* params,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_spprfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const float* ap, const float* afp, const float* b,
+ lapack_int* ldb, float* x, lapack_int* ldx, float* ferr,
+ float* berr, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dpprfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* ap, const double* afp, const double* b,
+ lapack_int* ldb, double* x, lapack_int* ldx, double* ferr,
+ double* berr, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_cpprfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* ap,
+ const lapack_complex_float* afp,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* ferr,
+ float* berr, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zpprfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* afp,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* ferr,
+ double* berr, lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_spbrfs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ const float* ab, lapack_int* ldab, const float* afb,
+ lapack_int* ldafb, const float* b, lapack_int* ldb,
+ float* x, lapack_int* ldx, float* ferr, float* berr,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_dpbrfs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ const double* ab, lapack_int* ldab, const double* afb,
+ lapack_int* ldafb, const double* b, lapack_int* ldb,
+ double* x, lapack_int* ldx, double* ferr, double* berr,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_cpbrfs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ const lapack_complex_float* ab, lapack_int* ldab,
+ const lapack_complex_float* afb, lapack_int* ldafb,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* ferr,
+ float* berr, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zpbrfs( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ const lapack_complex_double* ab, lapack_int* ldab,
+ const lapack_complex_double* afb, lapack_int* ldafb,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* ferr,
+ double* berr, lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_sptrfs( lapack_int* n, lapack_int* nrhs, const float* d,
+ const float* e, const float* df, const float* ef,
+ const float* b, lapack_int* ldb, float* x, lapack_int* ldx,
+ float* ferr, float* berr, float* work, lapack_int *info );
+void LAPACK_dptrfs( lapack_int* n, lapack_int* nrhs, const double* d,
+ const double* e, const double* df, const double* ef,
+ const double* b, lapack_int* ldb, double* x,
+ lapack_int* ldx, double* ferr, double* berr, double* work,
+ lapack_int *info );
+void LAPACK_cptrfs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* d,
+ const lapack_complex_float* e, const float* df,
+ const lapack_complex_float* ef,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* ferr,
+ float* berr, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zptrfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* d, const lapack_complex_double* e,
+ const double* df, const lapack_complex_double* ef,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* ferr,
+ double* berr, lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_ssyrfs( char* uplo, lapack_int* n, lapack_int* nrhs, const float* a,
+ lapack_int* lda, const float* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const float* b, lapack_int* ldb,
+ float* x, lapack_int* ldx, float* ferr, float* berr,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_dsyrfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* a, lapack_int* lda, const double* af,
+ lapack_int* ldaf, const lapack_int* ipiv, const double* b,
+ lapack_int* ldb, double* x, lapack_int* ldx, double* ferr,
+ double* berr, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_csyrfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx,
+ float* ferr, float* berr, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_zsyrfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx,
+ double* ferr, double* berr, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_dsyrfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs,
+ const double* a, lapack_int* lda, const double* af,
+ lapack_int* ldaf, const lapack_int* ipiv, const double* s,
+ const double* b, lapack_int* ldb, double* x,
+ lapack_int* ldx, double* rcond, double* berr,
+ lapack_int* n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int* nparams, double* params,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_ssyrfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs,
+ const float* a, lapack_int* lda, const float* af,
+ lapack_int* ldaf, const lapack_int* ipiv, const float* s,
+ const float* b, lapack_int* ldb, float* x, lapack_int* ldx,
+ float* rcond, float* berr, lapack_int* n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int* nparams, float* params, float* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_zsyrfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const double* s,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_csyrfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const float* s,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* berr, lapack_int* n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int* nparams, float* params,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_cherfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx,
+ float* ferr, float* berr, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_zherfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx,
+ double* ferr, double* berr, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_zherfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const double* s,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_cherfsx( char* uplo, char* equed, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* af, lapack_int* ldaf,
+ const lapack_int* ipiv, const float* s,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* berr, lapack_int* n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int* nparams, float* params,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_ssprfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const float* ap, const float* afp, const lapack_int* ipiv,
+ const float* b, lapack_int* ldb, float* x, lapack_int* ldx,
+ float* ferr, float* berr, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dsprfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* ap, const double* afp, const lapack_int* ipiv,
+ const double* b, lapack_int* ldb, double* x,
+ lapack_int* ldx, double* ferr, double* berr, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_csprfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* ap,
+ const lapack_complex_float* afp, const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* ferr,
+ float* berr, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zsprfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* afp, const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* ferr,
+ double* berr, lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_chprfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* ap,
+ const lapack_complex_float* afp, const lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* ferr,
+ float* berr, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zhprfs( char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* ap,
+ const lapack_complex_double* afp, const lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* ferr,
+ double* berr, lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_strrfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const float* a, lapack_int* lda,
+ const float* b, lapack_int* ldb, const float* x,
+ lapack_int* ldx, float* ferr, float* berr, float* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_dtrrfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const double* a, lapack_int* lda,
+ const double* b, lapack_int* ldb, const double* x,
+ lapack_int* ldx, double* ferr, double* berr, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_ctrrfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_complex_float* b,
+ lapack_int* ldb, const lapack_complex_float* x,
+ lapack_int* ldx, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_ztrrfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const lapack_complex_double* a,
+ lapack_int* lda, const lapack_complex_double* b,
+ lapack_int* ldb, const lapack_complex_double* x,
+ lapack_int* ldx, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_stprfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const float* ap, const float* b,
+ lapack_int* ldb, const float* x, lapack_int* ldx,
+ float* ferr, float* berr, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dtprfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const double* ap, const double* b,
+ lapack_int* ldb, const double* x, lapack_int* ldx,
+ double* ferr, double* berr, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_ctprfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const lapack_complex_float* ap,
+ const lapack_complex_float* b, lapack_int* ldb,
+ const lapack_complex_float* x, lapack_int* ldx, float* ferr,
+ float* berr, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_ztprfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* nrhs, const lapack_complex_double* ap,
+ const lapack_complex_double* b, lapack_int* ldb,
+ const lapack_complex_double* x, lapack_int* ldx,
+ double* ferr, double* berr, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_stbrfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* kd, lapack_int* nrhs, const float* ab,
+ lapack_int* ldab, const float* b, lapack_int* ldb,
+ const float* x, lapack_int* ldx, float* ferr, float* berr,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_dtbrfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* kd, lapack_int* nrhs, const double* ab,
+ lapack_int* ldab, const double* b, lapack_int* ldb,
+ const double* x, lapack_int* ldx, double* ferr,
+ double* berr, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_ctbrfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* kd, lapack_int* nrhs,
+ const lapack_complex_float* ab, lapack_int* ldab,
+ const lapack_complex_float* b, lapack_int* ldb,
+ const lapack_complex_float* x, lapack_int* ldx, float* ferr,
+ float* berr, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_ztbrfs( char* uplo, char* trans, char* diag, lapack_int* n,
+ lapack_int* kd, lapack_int* nrhs,
+ const lapack_complex_double* ab, lapack_int* ldab,
+ const lapack_complex_double* b, lapack_int* ldb,
+ const lapack_complex_double* x, lapack_int* ldx,
+ double* ferr, double* berr, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_sgetri( lapack_int* n, float* a, lapack_int* lda,
+ const lapack_int* ipiv, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dgetri( lapack_int* n, double* a, lapack_int* lda,
+ const lapack_int* ipiv, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cgetri( lapack_int* n, lapack_complex_float* a, lapack_int* lda,
+ const lapack_int* ipiv, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zgetri( lapack_int* n, lapack_complex_double* a, lapack_int* lda,
+ const lapack_int* ipiv, lapack_complex_double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_spotri( char* uplo, lapack_int* n, float* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_dpotri( char* uplo, lapack_int* n, double* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_cpotri( char* uplo, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_zpotri( char* uplo, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_dpftri( char* transr, char* uplo, lapack_int* n, double* a,
+ lapack_int *info );
+void LAPACK_spftri( char* transr, char* uplo, lapack_int* n, float* a,
+ lapack_int *info );
+void LAPACK_zpftri( char* transr, char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int *info );
+void LAPACK_cpftri( char* transr, char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int *info );
+void LAPACK_spptri( char* uplo, lapack_int* n, float* ap, lapack_int *info );
+void LAPACK_dpptri( char* uplo, lapack_int* n, double* ap, lapack_int *info );
+void LAPACK_cpptri( char* uplo, lapack_int* n, lapack_complex_float* ap,
+ lapack_int *info );
+void LAPACK_zpptri( char* uplo, lapack_int* n, lapack_complex_double* ap,
+ lapack_int *info );
+void LAPACK_ssytri( char* uplo, lapack_int* n, float* a, lapack_int* lda,
+ const lapack_int* ipiv, float* work, lapack_int *info );
+void LAPACK_dsytri( char* uplo, lapack_int* n, double* a, lapack_int* lda,
+ const lapack_int* ipiv, double* work, lapack_int *info );
+void LAPACK_csytri( char* uplo, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zsytri( char* uplo, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_chetri( char* uplo, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zhetri( char* uplo, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_ssptri( char* uplo, lapack_int* n, float* ap,
+ const lapack_int* ipiv, float* work, lapack_int *info );
+void LAPACK_dsptri( char* uplo, lapack_int* n, double* ap,
+ const lapack_int* ipiv, double* work, lapack_int *info );
+void LAPACK_csptri( char* uplo, lapack_int* n, lapack_complex_float* ap,
+ const lapack_int* ipiv, lapack_complex_float* work,
+ lapack_int *info );
+void LAPACK_zsptri( char* uplo, lapack_int* n, lapack_complex_double* ap,
+ const lapack_int* ipiv, lapack_complex_double* work,
+ lapack_int *info );
+void LAPACK_chptri( char* uplo, lapack_int* n, lapack_complex_float* ap,
+ const lapack_int* ipiv, lapack_complex_float* work,
+ lapack_int *info );
+void LAPACK_zhptri( char* uplo, lapack_int* n, lapack_complex_double* ap,
+ const lapack_int* ipiv, lapack_complex_double* work,
+ lapack_int *info );
+void LAPACK_strtri( char* uplo, char* diag, lapack_int* n, float* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_dtrtri( char* uplo, char* diag, lapack_int* n, double* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_ctrtri( char* uplo, char* diag, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_ztrtri( char* uplo, char* diag, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_dtftri( char* transr, char* uplo, char* diag, lapack_int* n,
+ double* a, lapack_int *info );
+void LAPACK_stftri( char* transr, char* uplo, char* diag, lapack_int* n,
+ float* a, lapack_int *info );
+void LAPACK_ztftri( char* transr, char* uplo, char* diag, lapack_int* n,
+ lapack_complex_double* a, lapack_int *info );
+void LAPACK_ctftri( char* transr, char* uplo, char* diag, lapack_int* n,
+ lapack_complex_float* a, lapack_int *info );
+void LAPACK_stptri( char* uplo, char* diag, lapack_int* n, float* ap,
+ lapack_int *info );
+void LAPACK_dtptri( char* uplo, char* diag, lapack_int* n, double* ap,
+ lapack_int *info );
+void LAPACK_ctptri( char* uplo, char* diag, lapack_int* n,
+ lapack_complex_float* ap, lapack_int *info );
+void LAPACK_ztptri( char* uplo, char* diag, lapack_int* n,
+ lapack_complex_double* ap, lapack_int *info );
+void LAPACK_sgeequ( lapack_int* m, lapack_int* n, const float* a,
+ lapack_int* lda, float* r, float* c, float* rowcnd,
+ float* colcnd, float* amax, lapack_int *info );
+void LAPACK_dgeequ( lapack_int* m, lapack_int* n, const double* a,
+ lapack_int* lda, double* r, double* c, double* rowcnd,
+ double* colcnd, double* amax, lapack_int *info );
+void LAPACK_cgeequ( lapack_int* m, lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, float* r, float* c, float* rowcnd,
+ float* colcnd, float* amax, lapack_int *info );
+void LAPACK_zgeequ( lapack_int* m, lapack_int* n,
+ const lapack_complex_double* a, lapack_int* lda, double* r,
+ double* c, double* rowcnd, double* colcnd, double* amax,
+ lapack_int *info );
+void LAPACK_dgeequb( lapack_int* m, lapack_int* n, const double* a,
+ lapack_int* lda, double* r, double* c, double* rowcnd,
+ double* colcnd, double* amax, lapack_int *info );
+void LAPACK_sgeequb( lapack_int* m, lapack_int* n, const float* a,
+ lapack_int* lda, float* r, float* c, float* rowcnd,
+ float* colcnd, float* amax, lapack_int *info );
+void LAPACK_zgeequb( lapack_int* m, lapack_int* n,
+ const lapack_complex_double* a, lapack_int* lda, double* r,
+ double* c, double* rowcnd, double* colcnd, double* amax,
+ lapack_int *info );
+void LAPACK_cgeequb( lapack_int* m, lapack_int* n,
+ const lapack_complex_float* a, lapack_int* lda, float* r,
+ float* c, float* rowcnd, float* colcnd, float* amax,
+ lapack_int *info );
+void LAPACK_sgbequ( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const float* ab, lapack_int* ldab, float* r,
+ float* c, float* rowcnd, float* colcnd, float* amax,
+ lapack_int *info );
+void LAPACK_dgbequ( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const double* ab, lapack_int* ldab,
+ double* r, double* c, double* rowcnd, double* colcnd,
+ double* amax, lapack_int *info );
+void LAPACK_cgbequ( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const lapack_complex_float* ab,
+ lapack_int* ldab, float* r, float* c, float* rowcnd,
+ float* colcnd, float* amax, lapack_int *info );
+void LAPACK_zgbequ( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const lapack_complex_double* ab,
+ lapack_int* ldab, double* r, double* c, double* rowcnd,
+ double* colcnd, double* amax, lapack_int *info );
+void LAPACK_dgbequb( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const double* ab, lapack_int* ldab,
+ double* r, double* c, double* rowcnd, double* colcnd,
+ double* amax, lapack_int *info );
+void LAPACK_sgbequb( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const float* ab, lapack_int* ldab,
+ float* r, float* c, float* rowcnd, float* colcnd,
+ float* amax, lapack_int *info );
+void LAPACK_zgbequb( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const lapack_complex_double* ab,
+ lapack_int* ldab, double* r, double* c, double* rowcnd,
+ double* colcnd, double* amax, lapack_int *info );
+void LAPACK_cgbequb( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const lapack_complex_float* ab,
+ lapack_int* ldab, float* r, float* c, float* rowcnd,
+ float* colcnd, float* amax, lapack_int *info );
+void LAPACK_spoequ( lapack_int* n, const float* a, lapack_int* lda, float* s,
+ float* scond, float* amax, lapack_int *info );
+void LAPACK_dpoequ( lapack_int* n, const double* a, lapack_int* lda, double* s,
+ double* scond, double* amax, lapack_int *info );
+void LAPACK_cpoequ( lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, float* s, float* scond, float* amax,
+ lapack_int *info );
+void LAPACK_zpoequ( lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, double* s, double* scond, double* amax,
+ lapack_int *info );
+void LAPACK_dpoequb( lapack_int* n, const double* a, lapack_int* lda, double* s,
+ double* scond, double* amax, lapack_int *info );
+void LAPACK_spoequb( lapack_int* n, const float* a, lapack_int* lda, float* s,
+ float* scond, float* amax, lapack_int *info );
+void LAPACK_zpoequb( lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, double* s, double* scond, double* amax,
+ lapack_int *info );
+void LAPACK_cpoequb( lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, float* s, float* scond, float* amax,
+ lapack_int *info );
+void LAPACK_sppequ( char* uplo, lapack_int* n, const float* ap, float* s,
+ float* scond, float* amax, lapack_int *info );
+void LAPACK_dppequ( char* uplo, lapack_int* n, const double* ap, double* s,
+ double* scond, double* amax, lapack_int *info );
+void LAPACK_cppequ( char* uplo, lapack_int* n, const lapack_complex_float* ap,
+ float* s, float* scond, float* amax, lapack_int *info );
+void LAPACK_zppequ( char* uplo, lapack_int* n, const lapack_complex_double* ap,
+ double* s, double* scond, double* amax, lapack_int *info );
+void LAPACK_spbequ( char* uplo, lapack_int* n, lapack_int* kd, const float* ab,
+ lapack_int* ldab, float* s, float* scond, float* amax,
+ lapack_int *info );
+void LAPACK_dpbequ( char* uplo, lapack_int* n, lapack_int* kd, const double* ab,
+ lapack_int* ldab, double* s, double* scond, double* amax,
+ lapack_int *info );
+void LAPACK_cpbequ( char* uplo, lapack_int* n, lapack_int* kd,
+ const lapack_complex_float* ab, lapack_int* ldab, float* s,
+ float* scond, float* amax, lapack_int *info );
+void LAPACK_zpbequ( char* uplo, lapack_int* n, lapack_int* kd,
+ const lapack_complex_double* ab, lapack_int* ldab,
+ double* s, double* scond, double* amax, lapack_int *info );
+void LAPACK_dsyequb( char* uplo, lapack_int* n, const double* a,
+ lapack_int* lda, double* s, double* scond, double* amax,
+ double* work, lapack_int *info );
+void LAPACK_ssyequb( char* uplo, lapack_int* n, const float* a, lapack_int* lda,
+ float* s, float* scond, float* amax, float* work,
+ lapack_int *info );
+void LAPACK_zsyequb( char* uplo, lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, double* s, double* scond, double* amax,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_csyequb( char* uplo, lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, float* s, float* scond, float* amax,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zheequb( char* uplo, lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, double* s, double* scond, double* amax,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_cheequb( char* uplo, lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, float* s, float* scond, float* amax,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_sgesv( lapack_int* n, lapack_int* nrhs, float* a, lapack_int* lda,
+ lapack_int* ipiv, float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dgesv( lapack_int* n, lapack_int* nrhs, double* a, lapack_int* lda,
+ lapack_int* ipiv, double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_cgesv( lapack_int* n, lapack_int* nrhs, lapack_complex_float* a,
+ lapack_int* lda, lapack_int* ipiv, lapack_complex_float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_zgesv( lapack_int* n, lapack_int* nrhs, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_dsgesv( lapack_int* n, lapack_int* nrhs, double* a, lapack_int* lda,
+ lapack_int* ipiv, double* b, lapack_int* ldb, double* x,
+ lapack_int* ldx, double* work, float* swork,
+ lapack_int* iter, lapack_int *info );
+void LAPACK_zcgesv( lapack_int* n, lapack_int* nrhs, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx,
+ lapack_complex_double* work, lapack_complex_float* swork,
+ double* rwork, lapack_int* iter, lapack_int *info );
+void LAPACK_sgesvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ float* a, lapack_int* lda, float* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, float* r, float* c, float* b,
+ lapack_int* ldb, float* x, lapack_int* ldx, float* rcond,
+ float* ferr, float* berr, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dgesvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ double* a, lapack_int* lda, double* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, double* r, double* c,
+ double* b, lapack_int* ldb, double* x, lapack_int* ldx,
+ double* rcond, double* ferr, double* berr, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_cgesvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, float* r, float* c,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* ferr, float* berr, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_zgesvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, double* r, double* c,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* ferr, double* berr, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_dgesvxx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ double* a, lapack_int* lda, double* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, double* r, double* c,
+ double* b, lapack_int* ldb, double* x, lapack_int* ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int* n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int* nparams, double* params,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_sgesvxx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ float* a, lapack_int* lda, float* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, float* r, float* c,
+ float* b, lapack_int* ldb, float* x, lapack_int* ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int* n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int* nparams, float* params,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_zgesvxx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, double* r, double* c,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* rpvgrw, double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_cgesvxx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, float* r, float* c,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* rpvgrw, float* berr, lapack_int* n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int* nparams, float* params,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_sgbsv( lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, float* ab, lapack_int* ldab,
+ lapack_int* ipiv, float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dgbsv( lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, double* ab, lapack_int* ldab,
+ lapack_int* ipiv, double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_cgbsv( lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, lapack_complex_float* ab, lapack_int* ldab,
+ lapack_int* ipiv, lapack_complex_float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_zgbsv( lapack_int* n, lapack_int* kl, lapack_int* ku,
+ lapack_int* nrhs, lapack_complex_double* ab,
+ lapack_int* ldab, lapack_int* ipiv, lapack_complex_double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_sgbsvx( char* fact, char* trans, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs, float* ab,
+ lapack_int* ldab, float* afb, lapack_int* ldafb,
+ lapack_int* ipiv, char* equed, float* r, float* c, float* b,
+ lapack_int* ldb, float* x, lapack_int* ldx, float* rcond,
+ float* ferr, float* berr, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dgbsvx( char* fact, char* trans, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs, double* ab,
+ lapack_int* ldab, double* afb, lapack_int* ldafb,
+ lapack_int* ipiv, char* equed, double* r, double* c,
+ double* b, lapack_int* ldb, double* x, lapack_int* ldx,
+ double* rcond, double* ferr, double* berr, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_cgbsvx( char* fact, char* trans, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs, lapack_complex_float* ab,
+ lapack_int* ldab, lapack_complex_float* afb,
+ lapack_int* ldafb, lapack_int* ipiv, char* equed, float* r,
+ float* c, lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* ferr, float* berr, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_zgbsvx( char* fact, char* trans, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs, lapack_complex_double* ab,
+ lapack_int* ldab, lapack_complex_double* afb,
+ lapack_int* ldafb, lapack_int* ipiv, char* equed, double* r,
+ double* c, lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* ferr, double* berr, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_dgbsvxx( char* fact, char* trans, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs, double* ab,
+ lapack_int* ldab, double* afb, lapack_int* ldafb,
+ lapack_int* ipiv, char* equed, double* r, double* c,
+ double* b, lapack_int* ldb, double* x, lapack_int* ldx,
+ double* rcond, double* rpvgrw, double* berr,
+ lapack_int* n_err_bnds, double* err_bnds_norm,
+ double* err_bnds_comp, lapack_int* nparams, double* params,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_sgbsvxx( char* fact, char* trans, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs, float* ab,
+ lapack_int* ldab, float* afb, lapack_int* ldafb,
+ lapack_int* ipiv, char* equed, float* r, float* c,
+ float* b, lapack_int* ldb, float* x, lapack_int* ldx,
+ float* rcond, float* rpvgrw, float* berr,
+ lapack_int* n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int* nparams, float* params,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_zgbsvxx( char* fact, char* trans, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs,
+ lapack_complex_double* ab, lapack_int* ldab,
+ lapack_complex_double* afb, lapack_int* ldafb,
+ lapack_int* ipiv, char* equed, double* r, double* c,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* rpvgrw, double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_cgbsvxx( char* fact, char* trans, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, lapack_int* nrhs, lapack_complex_float* ab,
+ lapack_int* ldab, lapack_complex_float* afb,
+ lapack_int* ldafb, lapack_int* ipiv, char* equed, float* r,
+ float* c, lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* rpvgrw, float* berr, lapack_int* n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int* nparams, float* params,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_sgtsv( lapack_int* n, lapack_int* nrhs, float* dl, float* d,
+ float* du, float* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_dgtsv( lapack_int* n, lapack_int* nrhs, double* dl, double* d,
+ double* du, double* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_cgtsv( lapack_int* n, lapack_int* nrhs, lapack_complex_float* dl,
+ lapack_complex_float* d, lapack_complex_float* du,
+ lapack_complex_float* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_zgtsv( lapack_int* n, lapack_int* nrhs, lapack_complex_double* dl,
+ lapack_complex_double* d, lapack_complex_double* du,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_sgtsvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ const float* dl, const float* d, const float* du,
+ float* dlf, float* df, float* duf, float* du2,
+ lapack_int* ipiv, const float* b, lapack_int* ldb, float* x,
+ lapack_int* ldx, float* rcond, float* ferr, float* berr,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_dgtsvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ const double* dl, const double* d, const double* du,
+ double* dlf, double* df, double* duf, double* du2,
+ lapack_int* ipiv, const double* b, lapack_int* ldb,
+ double* x, lapack_int* ldx, double* rcond, double* ferr,
+ double* berr, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_cgtsvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* dl,
+ const lapack_complex_float* d,
+ const lapack_complex_float* du, lapack_complex_float* dlf,
+ lapack_complex_float* df, lapack_complex_float* duf,
+ lapack_complex_float* du2, lapack_int* ipiv,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* ferr, float* berr, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_zgtsvx( char* fact, char* trans, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* dl,
+ const lapack_complex_double* d,
+ const lapack_complex_double* du, lapack_complex_double* dlf,
+ lapack_complex_double* df, lapack_complex_double* duf,
+ lapack_complex_double* du2, lapack_int* ipiv,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* ferr, double* berr, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_sposv( char* uplo, lapack_int* n, lapack_int* nrhs, float* a,
+ lapack_int* lda, float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dposv( char* uplo, lapack_int* n, lapack_int* nrhs, double* a,
+ lapack_int* lda, double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_cposv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_zposv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dsposv( char* uplo, lapack_int* n, lapack_int* nrhs, double* a,
+ lapack_int* lda, double* b, lapack_int* ldb, double* x,
+ lapack_int* ldx, double* work, float* swork,
+ lapack_int* iter, lapack_int *info );
+void LAPACK_zcposv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx,
+ lapack_complex_double* work, lapack_complex_float* swork,
+ double* rwork, lapack_int* iter, lapack_int *info );
+void LAPACK_sposvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ float* a, lapack_int* lda, float* af, lapack_int* ldaf,
+ char* equed, float* s, float* b, lapack_int* ldb, float* x,
+ lapack_int* ldx, float* rcond, float* ferr, float* berr,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_dposvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ double* a, lapack_int* lda, double* af, lapack_int* ldaf,
+ char* equed, double* s, double* b, lapack_int* ldb,
+ double* x, lapack_int* ldx, double* rcond, double* ferr,
+ double* berr, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_cposvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* af, lapack_int* ldaf, char* equed,
+ float* s, lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* ferr, float* berr, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_zposvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* af, lapack_int* ldaf, char* equed,
+ double* s, lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* ferr, double* berr, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_dposvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ double* a, lapack_int* lda, double* af, lapack_int* ldaf,
+ char* equed, double* s, double* b, lapack_int* ldb,
+ double* x, lapack_int* ldx, double* rcond, double* rpvgrw,
+ double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_sposvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ float* a, lapack_int* lda, float* af, lapack_int* ldaf,
+ char* equed, float* s, float* b, lapack_int* ldb, float* x,
+ lapack_int* ldx, float* rcond, float* rpvgrw, float* berr,
+ lapack_int* n_err_bnds, float* err_bnds_norm,
+ float* err_bnds_comp, lapack_int* nparams, float* params,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_zposvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* af, lapack_int* ldaf, char* equed,
+ double* s, lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* rpvgrw, double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_cposvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* af, lapack_int* ldaf, char* equed,
+ float* s, lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* rpvgrw, float* berr, lapack_int* n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int* nparams, float* params,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_sppsv( char* uplo, lapack_int* n, lapack_int* nrhs, float* ap,
+ float* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_dppsv( char* uplo, lapack_int* n, lapack_int* nrhs, double* ap,
+ double* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_cppsv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* ap, lapack_complex_float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_zppsv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* ap, lapack_complex_double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_sppsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ float* ap, float* afp, char* equed, float* s, float* b,
+ lapack_int* ldb, float* x, lapack_int* ldx, float* rcond,
+ float* ferr, float* berr, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dppsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ double* ap, double* afp, char* equed, double* s, double* b,
+ lapack_int* ldb, double* x, lapack_int* ldx, double* rcond,
+ double* ferr, double* berr, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_cppsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* ap, lapack_complex_float* afp,
+ char* equed, float* s, lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx,
+ float* rcond, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zppsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* ap, lapack_complex_double* afp,
+ char* equed, double* s, lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_spbsv( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ float* ab, lapack_int* ldab, float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dpbsv( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ double* ab, lapack_int* ldab, double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_cpbsv( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ lapack_complex_float* ab, lapack_int* ldab,
+ lapack_complex_float* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_zpbsv( char* uplo, lapack_int* n, lapack_int* kd, lapack_int* nrhs,
+ lapack_complex_double* ab, lapack_int* ldab,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_spbsvx( char* fact, char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_int* nrhs, float* ab, lapack_int* ldab, float* afb,
+ lapack_int* ldafb, char* equed, float* s, float* b,
+ lapack_int* ldb, float* x, lapack_int* ldx, float* rcond,
+ float* ferr, float* berr, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dpbsvx( char* fact, char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_int* nrhs, double* ab, lapack_int* ldab, double* afb,
+ lapack_int* ldafb, char* equed, double* s, double* b,
+ lapack_int* ldb, double* x, lapack_int* ldx, double* rcond,
+ double* ferr, double* berr, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_cpbsvx( char* fact, char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_int* nrhs, lapack_complex_float* ab,
+ lapack_int* ldab, lapack_complex_float* afb,
+ lapack_int* ldafb, char* equed, float* s,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* ferr, float* berr, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_zpbsvx( char* fact, char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_int* nrhs, lapack_complex_double* ab,
+ lapack_int* ldab, lapack_complex_double* afb,
+ lapack_int* ldafb, char* equed, double* s,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* ferr, double* berr, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_sptsv( lapack_int* n, lapack_int* nrhs, float* d, float* e,
+ float* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_dptsv( lapack_int* n, lapack_int* nrhs, double* d, double* e,
+ double* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_cptsv( lapack_int* n, lapack_int* nrhs, float* d,
+ lapack_complex_float* e, lapack_complex_float* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_zptsv( lapack_int* n, lapack_int* nrhs, double* d,
+ lapack_complex_double* e, lapack_complex_double* b,
+ lapack_int* ldb, lapack_int *info );
+void LAPACK_sptsvx( char* fact, lapack_int* n, lapack_int* nrhs, const float* d,
+ const float* e, float* df, float* ef, const float* b,
+ lapack_int* ldb, float* x, lapack_int* ldx, float* rcond,
+ float* ferr, float* berr, float* work, lapack_int *info );
+void LAPACK_dptsvx( char* fact, lapack_int* n, lapack_int* nrhs,
+ const double* d, const double* e, double* df, double* ef,
+ const double* b, lapack_int* ldb, double* x,
+ lapack_int* ldx, double* rcond, double* ferr, double* berr,
+ double* work, lapack_int *info );
+void LAPACK_cptsvx( char* fact, lapack_int* n, lapack_int* nrhs, const float* d,
+ const lapack_complex_float* e, float* df,
+ lapack_complex_float* ef, const lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx,
+ float* rcond, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zptsvx( char* fact, lapack_int* n, lapack_int* nrhs,
+ const double* d, const lapack_complex_double* e, double* df,
+ lapack_complex_double* ef, const lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_ssysv( char* uplo, lapack_int* n, lapack_int* nrhs, float* a,
+ lapack_int* lda, lapack_int* ipiv, float* b, lapack_int* ldb,
+ float* work, lapack_int* lwork, lapack_int *info );
+void LAPACK_dsysv( char* uplo, lapack_int* n, lapack_int* nrhs, double* a,
+ lapack_int* lda, lapack_int* ipiv, double* b,
+ lapack_int* ldb, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_csysv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda, lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zsysv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda, lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_ssysvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const float* a, lapack_int* lda, float* af,
+ lapack_int* ldaf, lapack_int* ipiv, const float* b,
+ lapack_int* ldb, float* x, lapack_int* ldx, float* rcond,
+ float* ferr, float* berr, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_dsysvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* a, lapack_int* lda, double* af,
+ lapack_int* ldaf, lapack_int* ipiv, const double* b,
+ lapack_int* ldb, double* x, lapack_int* ldx, double* rcond,
+ double* ferr, double* berr, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_csysvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* af, lapack_int* ldaf,
+ lapack_int* ipiv, const lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx,
+ float* rcond, float* ferr, float* berr,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int *info );
+void LAPACK_zsysvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* af, lapack_int* ldaf,
+ lapack_int* ipiv, const lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int *info );
+void LAPACK_dsysvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ double* a, lapack_int* lda, double* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, double* s, double* b,
+ lapack_int* ldb, double* x, lapack_int* ldx, double* rcond,
+ double* rpvgrw, double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_ssysvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ float* a, lapack_int* lda, float* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, float* s, float* b,
+ lapack_int* ldb, float* x, lapack_int* ldx, float* rcond,
+ float* rpvgrw, float* berr, lapack_int* n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int* nparams, float* params, float* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_zsysvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, double* s,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* rpvgrw, double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_csysvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, float* s,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* rpvgrw, float* berr, lapack_int* n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int* nparams, float* params,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_chesv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda, lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zhesv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda, lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_chesvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* af, lapack_int* ldaf,
+ lapack_int* ipiv, const lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx,
+ float* rcond, float* ferr, float* berr,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int *info );
+void LAPACK_zhesvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* af, lapack_int* ldaf,
+ lapack_int* ipiv, const lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int *info );
+void LAPACK_zhesvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, double* s,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* x, lapack_int* ldx, double* rcond,
+ double* rpvgrw, double* berr, lapack_int* n_err_bnds,
+ double* err_bnds_norm, double* err_bnds_comp,
+ lapack_int* nparams, double* params,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_chesvxx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* af, lapack_int* ldaf,
+ lapack_int* ipiv, char* equed, float* s,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* x, lapack_int* ldx, float* rcond,
+ float* rpvgrw, float* berr, lapack_int* n_err_bnds,
+ float* err_bnds_norm, float* err_bnds_comp,
+ lapack_int* nparams, float* params,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_sspsv( char* uplo, lapack_int* n, lapack_int* nrhs, float* ap,
+ lapack_int* ipiv, float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dspsv( char* uplo, lapack_int* n, lapack_int* nrhs, double* ap,
+ lapack_int* ipiv, double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_cspsv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* ap, lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_zspsv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* ap, lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_sspsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const float* ap, float* afp, lapack_int* ipiv,
+ const float* b, lapack_int* ldb, float* x, lapack_int* ldx,
+ float* rcond, float* ferr, float* berr, float* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_dspsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const double* ap, double* afp, lapack_int* ipiv,
+ const double* b, lapack_int* ldb, double* x,
+ lapack_int* ldx, double* rcond, double* ferr, double* berr,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_cspsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* ap, lapack_complex_float* afp,
+ lapack_int* ipiv, const lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx,
+ float* rcond, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zspsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* ap, lapack_complex_double* afp,
+ lapack_int* ipiv, const lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_chpsv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* ap, lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int* ldb, lapack_int *info );
+void LAPACK_zhpsv( char* uplo, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* ap, lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_chpsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_float* ap, lapack_complex_float* afp,
+ lapack_int* ipiv, const lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* x, lapack_int* ldx,
+ float* rcond, float* ferr, float* berr,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zhpsvx( char* fact, char* uplo, lapack_int* n, lapack_int* nrhs,
+ const lapack_complex_double* ap, lapack_complex_double* afp,
+ lapack_int* ipiv, const lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* x, lapack_int* ldx,
+ double* rcond, double* ferr, double* berr,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_sgeqrf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* tau, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dgeqrf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* tau, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cgeqrf( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zgeqrf( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sgeqpf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ lapack_int* jpvt, float* tau, float* work,
+ lapack_int *info );
+void LAPACK_dgeqpf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ lapack_int* jpvt, double* tau, double* work,
+ lapack_int *info );
+void LAPACK_cgeqpf( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int* jpvt,
+ lapack_complex_float* tau, lapack_complex_float* work,
+ float* rwork, lapack_int *info );
+void LAPACK_zgeqpf( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* jpvt,
+ lapack_complex_double* tau, lapack_complex_double* work,
+ double* rwork, lapack_int *info );
+void LAPACK_sgeqp3( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ lapack_int* jpvt, float* tau, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dgeqp3( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ lapack_int* jpvt, double* tau, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cgeqp3( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int* jpvt,
+ lapack_complex_float* tau, lapack_complex_float* work,
+ lapack_int* lwork, float* rwork, lapack_int *info );
+void LAPACK_zgeqp3( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* jpvt,
+ lapack_complex_double* tau, lapack_complex_double* work,
+ lapack_int* lwork, double* rwork, lapack_int *info );
+void LAPACK_sorgqr( lapack_int* m, lapack_int* n, lapack_int* k, float* a,
+ lapack_int* lda, const float* tau, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dorgqr( lapack_int* m, lapack_int* n, lapack_int* k, double* a,
+ lapack_int* lda, const double* tau, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sormqr( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const float* a, lapack_int* lda,
+ const float* tau, float* c, lapack_int* ldc, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dormqr( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const double* a, lapack_int* lda,
+ const double* tau, double* c, lapack_int* ldc, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cungqr( lapack_int* m, lapack_int* n, lapack_int* k,
+ lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* tau, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zungqr( lapack_int* m, lapack_int* n, lapack_int* k,
+ lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cunmqr( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int* ldc,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zunmqr( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const lapack_complex_double* a,
+ lapack_int* lda, const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int* ldc,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sgelqf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* tau, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dgelqf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* tau, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cgelqf( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zgelqf( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sorglq( lapack_int* m, lapack_int* n, lapack_int* k, float* a,
+ lapack_int* lda, const float* tau, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dorglq( lapack_int* m, lapack_int* n, lapack_int* k, double* a,
+ lapack_int* lda, const double* tau, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sormlq( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const float* a, lapack_int* lda,
+ const float* tau, float* c, lapack_int* ldc, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dormlq( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const double* a, lapack_int* lda,
+ const double* tau, double* c, lapack_int* ldc, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cunglq( lapack_int* m, lapack_int* n, lapack_int* k,
+ lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* tau, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zunglq( lapack_int* m, lapack_int* n, lapack_int* k,
+ lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cunmlq( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int* ldc,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zunmlq( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const lapack_complex_double* a,
+ lapack_int* lda, const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int* ldc,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sgeqlf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* tau, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dgeqlf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* tau, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cgeqlf( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zgeqlf( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sorgql( lapack_int* m, lapack_int* n, lapack_int* k, float* a,
+ lapack_int* lda, const float* tau, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dorgql( lapack_int* m, lapack_int* n, lapack_int* k, double* a,
+ lapack_int* lda, const double* tau, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cungql( lapack_int* m, lapack_int* n, lapack_int* k,
+ lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* tau, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zungql( lapack_int* m, lapack_int* n, lapack_int* k,
+ lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sormql( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const float* a, lapack_int* lda,
+ const float* tau, float* c, lapack_int* ldc, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dormql( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const double* a, lapack_int* lda,
+ const double* tau, double* c, lapack_int* ldc, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cunmql( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int* ldc,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zunmql( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const lapack_complex_double* a,
+ lapack_int* lda, const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int* ldc,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sgerqf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* tau, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dgerqf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* tau, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cgerqf( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zgerqf( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sorgrq( lapack_int* m, lapack_int* n, lapack_int* k, float* a,
+ lapack_int* lda, const float* tau, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dorgrq( lapack_int* m, lapack_int* n, lapack_int* k, double* a,
+ lapack_int* lda, const double* tau, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cungrq( lapack_int* m, lapack_int* n, lapack_int* k,
+ lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* tau, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zungrq( lapack_int* m, lapack_int* n, lapack_int* k,
+ lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sormrq( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const float* a, lapack_int* lda,
+ const float* tau, float* c, lapack_int* ldc, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dormrq( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const double* a, lapack_int* lda,
+ const double* tau, double* c, lapack_int* ldc, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cunmrq( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int* ldc,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zunmrq( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, const lapack_complex_double* a,
+ lapack_int* lda, const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int* ldc,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_stzrzf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* tau, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dtzrzf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* tau, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_ctzrzf( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_ztzrzf( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sormrz( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* l, const float* a,
+ lapack_int* lda, const float* tau, float* c,
+ lapack_int* ldc, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dormrz( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* l, const double* a,
+ lapack_int* lda, const double* tau, double* c,
+ lapack_int* ldc, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cunmrz( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* l, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int* ldc,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zunmrz( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* l,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* tau, lapack_complex_double* c,
+ lapack_int* ldc, lapack_complex_double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sggqrf( lapack_int* n, lapack_int* m, lapack_int* p, float* a,
+ lapack_int* lda, float* taua, float* b, lapack_int* ldb,
+ float* taub, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dggqrf( lapack_int* n, lapack_int* m, lapack_int* p, double* a,
+ lapack_int* lda, double* taua, double* b, lapack_int* ldb,
+ double* taub, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cggqrf( lapack_int* n, lapack_int* m, lapack_int* p,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* taua, lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* taub,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zggqrf( lapack_int* n, lapack_int* m, lapack_int* p,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* taua, lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* taub,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sggrqf( lapack_int* m, lapack_int* p, lapack_int* n, float* a,
+ lapack_int* lda, float* taua, float* b, lapack_int* ldb,
+ float* taub, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dggrqf( lapack_int* m, lapack_int* p, lapack_int* n, double* a,
+ lapack_int* lda, double* taua, double* b, lapack_int* ldb,
+ double* taub, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cggrqf( lapack_int* m, lapack_int* p, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* taua, lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* taub,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zggrqf( lapack_int* m, lapack_int* p, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* taua, lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* taub,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sgebrd( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* d, float* e, float* tauq, float* taup, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dgebrd( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* d, double* e, double* tauq, double* taup,
+ double* work, lapack_int* lwork, lapack_int *info );
+void LAPACK_cgebrd( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, float* d, float* e,
+ lapack_complex_float* tauq, lapack_complex_float* taup,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zgebrd( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, double* d, double* e,
+ lapack_complex_double* tauq, lapack_complex_double* taup,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sgbbrd( char* vect, lapack_int* m, lapack_int* n, lapack_int* ncc,
+ lapack_int* kl, lapack_int* ku, float* ab, lapack_int* ldab,
+ float* d, float* e, float* q, lapack_int* ldq, float* pt,
+ lapack_int* ldpt, float* c, lapack_int* ldc, float* work,
+ lapack_int *info );
+void LAPACK_dgbbrd( char* vect, lapack_int* m, lapack_int* n, lapack_int* ncc,
+ lapack_int* kl, lapack_int* ku, double* ab,
+ lapack_int* ldab, double* d, double* e, double* q,
+ lapack_int* ldq, double* pt, lapack_int* ldpt, double* c,
+ lapack_int* ldc, double* work, lapack_int *info );
+void LAPACK_cgbbrd( char* vect, lapack_int* m, lapack_int* n, lapack_int* ncc,
+ lapack_int* kl, lapack_int* ku, lapack_complex_float* ab,
+ lapack_int* ldab, float* d, float* e,
+ lapack_complex_float* q, lapack_int* ldq,
+ lapack_complex_float* pt, lapack_int* ldpt,
+ lapack_complex_float* c, lapack_int* ldc,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zgbbrd( char* vect, lapack_int* m, lapack_int* n, lapack_int* ncc,
+ lapack_int* kl, lapack_int* ku, lapack_complex_double* ab,
+ lapack_int* ldab, double* d, double* e,
+ lapack_complex_double* q, lapack_int* ldq,
+ lapack_complex_double* pt, lapack_int* ldpt,
+ lapack_complex_double* c, lapack_int* ldc,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_sorgbr( char* vect, lapack_int* m, lapack_int* n, lapack_int* k,
+ float* a, lapack_int* lda, const float* tau, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dorgbr( char* vect, lapack_int* m, lapack_int* n, lapack_int* k,
+ double* a, lapack_int* lda, const double* tau, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sormbr( char* vect, char* side, char* trans, lapack_int* m,
+ lapack_int* n, lapack_int* k, const float* a,
+ lapack_int* lda, const float* tau, float* c,
+ lapack_int* ldc, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dormbr( char* vect, char* side, char* trans, lapack_int* m,
+ lapack_int* n, lapack_int* k, const double* a,
+ lapack_int* lda, const double* tau, double* c,
+ lapack_int* ldc, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cungbr( char* vect, lapack_int* m, lapack_int* n, lapack_int* k,
+ lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* tau, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zungbr( char* vect, lapack_int* m, lapack_int* n, lapack_int* k,
+ lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cunmbr( char* vect, char* side, char* trans, lapack_int* m,
+ lapack_int* n, lapack_int* k, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int* ldc,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zunmbr( char* vect, char* side, char* trans, lapack_int* m,
+ lapack_int* n, lapack_int* k,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* tau, lapack_complex_double* c,
+ lapack_int* ldc, lapack_complex_double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sbdsqr( char* uplo, lapack_int* n, lapack_int* ncvt,
+ lapack_int* nru, lapack_int* ncc, float* d, float* e,
+ float* vt, lapack_int* ldvt, float* u, lapack_int* ldu,
+ float* c, lapack_int* ldc, float* work, lapack_int *info );
+void LAPACK_dbdsqr( char* uplo, lapack_int* n, lapack_int* ncvt,
+ lapack_int* nru, lapack_int* ncc, double* d, double* e,
+ double* vt, lapack_int* ldvt, double* u, lapack_int* ldu,
+ double* c, lapack_int* ldc, double* work,
+ lapack_int *info );
+void LAPACK_cbdsqr( char* uplo, lapack_int* n, lapack_int* ncvt,
+ lapack_int* nru, lapack_int* ncc, float* d, float* e,
+ lapack_complex_float* vt, lapack_int* ldvt,
+ lapack_complex_float* u, lapack_int* ldu,
+ lapack_complex_float* c, lapack_int* ldc, float* work,
+ lapack_int *info );
+void LAPACK_zbdsqr( char* uplo, lapack_int* n, lapack_int* ncvt,
+ lapack_int* nru, lapack_int* ncc, double* d, double* e,
+ lapack_complex_double* vt, lapack_int* ldvt,
+ lapack_complex_double* u, lapack_int* ldu,
+ lapack_complex_double* c, lapack_int* ldc, double* work,
+ lapack_int *info );
+void LAPACK_sbdsdc( char* uplo, char* compq, lapack_int* n, float* d, float* e,
+ float* u, lapack_int* ldu, float* vt, lapack_int* ldvt,
+ float* q, lapack_int* iq, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dbdsdc( char* uplo, char* compq, lapack_int* n, double* d,
+ double* e, double* u, lapack_int* ldu, double* vt,
+ lapack_int* ldvt, double* q, lapack_int* iq, double* work,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_ssytrd( char* uplo, lapack_int* n, float* a, lapack_int* lda,
+ float* d, float* e, float* tau, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dsytrd( char* uplo, lapack_int* n, double* a, lapack_int* lda,
+ double* d, double* e, double* tau, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sorgtr( char* uplo, lapack_int* n, float* a, lapack_int* lda,
+ const float* tau, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dorgtr( char* uplo, lapack_int* n, double* a, lapack_int* lda,
+ const double* tau, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sormtr( char* side, char* uplo, char* trans, lapack_int* m,
+ lapack_int* n, const float* a, lapack_int* lda,
+ const float* tau, float* c, lapack_int* ldc, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dormtr( char* side, char* uplo, char* trans, lapack_int* m,
+ lapack_int* n, const double* a, lapack_int* lda,
+ const double* tau, double* c, lapack_int* ldc, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_chetrd( char* uplo, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, float* d, float* e,
+ lapack_complex_float* tau, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zhetrd( char* uplo, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, double* d, double* e,
+ lapack_complex_double* tau, lapack_complex_double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cungtr( char* uplo, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, const lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zungtr( char* uplo, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cunmtr( char* side, char* uplo, char* trans, lapack_int* m,
+ lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int* ldc,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zunmtr( char* side, char* uplo, char* trans, lapack_int* m,
+ lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, const lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int* ldc,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_ssptrd( char* uplo, lapack_int* n, float* ap, float* d, float* e,
+ float* tau, lapack_int *info );
+void LAPACK_dsptrd( char* uplo, lapack_int* n, double* ap, double* d, double* e,
+ double* tau, lapack_int *info );
+void LAPACK_sopgtr( char* uplo, lapack_int* n, const float* ap,
+ const float* tau, float* q, lapack_int* ldq, float* work,
+ lapack_int *info );
+void LAPACK_dopgtr( char* uplo, lapack_int* n, const double* ap,
+ const double* tau, double* q, lapack_int* ldq, double* work,
+ lapack_int *info );
+void LAPACK_sopmtr( char* side, char* uplo, char* trans, lapack_int* m,
+ lapack_int* n, const float* ap, const float* tau, float* c,
+ lapack_int* ldc, float* work, lapack_int *info );
+void LAPACK_dopmtr( char* side, char* uplo, char* trans, lapack_int* m,
+ lapack_int* n, const double* ap, const double* tau,
+ double* c, lapack_int* ldc, double* work,
+ lapack_int *info );
+void LAPACK_chptrd( char* uplo, lapack_int* n, lapack_complex_float* ap,
+ float* d, float* e, lapack_complex_float* tau,
+ lapack_int *info );
+void LAPACK_zhptrd( char* uplo, lapack_int* n, lapack_complex_double* ap,
+ double* d, double* e, lapack_complex_double* tau,
+ lapack_int *info );
+void LAPACK_cupgtr( char* uplo, lapack_int* n, const lapack_complex_float* ap,
+ const lapack_complex_float* tau, lapack_complex_float* q,
+ lapack_int* ldq, lapack_complex_float* work,
+ lapack_int *info );
+void LAPACK_zupgtr( char* uplo, lapack_int* n, const lapack_complex_double* ap,
+ const lapack_complex_double* tau, lapack_complex_double* q,
+ lapack_int* ldq, lapack_complex_double* work,
+ lapack_int *info );
+void LAPACK_cupmtr( char* side, char* uplo, char* trans, lapack_int* m,
+ lapack_int* n, const lapack_complex_float* ap,
+ const lapack_complex_float* tau, lapack_complex_float* c,
+ lapack_int* ldc, lapack_complex_float* work,
+ lapack_int *info );
+void LAPACK_zupmtr( char* side, char* uplo, char* trans, lapack_int* m,
+ lapack_int* n, const lapack_complex_double* ap,
+ const lapack_complex_double* tau, lapack_complex_double* c,
+ lapack_int* ldc, lapack_complex_double* work,
+ lapack_int *info );
+void LAPACK_ssbtrd( char* vect, char* uplo, lapack_int* n, lapack_int* kd,
+ float* ab, lapack_int* ldab, float* d, float* e, float* q,
+ lapack_int* ldq, float* work, lapack_int *info );
+void LAPACK_dsbtrd( char* vect, char* uplo, lapack_int* n, lapack_int* kd,
+ double* ab, lapack_int* ldab, double* d, double* e,
+ double* q, lapack_int* ldq, double* work,
+ lapack_int *info );
+void LAPACK_chbtrd( char* vect, char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_complex_float* ab, lapack_int* ldab, float* d,
+ float* e, lapack_complex_float* q, lapack_int* ldq,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zhbtrd( char* vect, char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_complex_double* ab, lapack_int* ldab, double* d,
+ double* e, lapack_complex_double* q, lapack_int* ldq,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_ssterf( lapack_int* n, float* d, float* e, lapack_int *info );
+void LAPACK_dsterf( lapack_int* n, double* d, double* e, lapack_int *info );
+void LAPACK_ssteqr( char* compz, lapack_int* n, float* d, float* e, float* z,
+ lapack_int* ldz, float* work, lapack_int *info );
+void LAPACK_dsteqr( char* compz, lapack_int* n, double* d, double* e, double* z,
+ lapack_int* ldz, double* work, lapack_int *info );
+void LAPACK_csteqr( char* compz, lapack_int* n, float* d, float* e,
+ lapack_complex_float* z, lapack_int* ldz, float* work,
+ lapack_int *info );
+void LAPACK_zsteqr( char* compz, lapack_int* n, double* d, double* e,
+ lapack_complex_double* z, lapack_int* ldz, double* work,
+ lapack_int *info );
+void LAPACK_sstemr( char* jobz, char* range, lapack_int* n, float* d, float* e,
+ float* vl, float* vu, lapack_int* il, lapack_int* iu,
+ lapack_int* m, float* w, float* z, lapack_int* ldz,
+ lapack_int* nzc, lapack_int* isuppz, lapack_logical* tryrac,
+ float* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_dstemr( char* jobz, char* range, lapack_int* n, double* d,
+ double* e, double* vl, double* vu, lapack_int* il,
+ lapack_int* iu, lapack_int* m, double* w, double* z,
+ lapack_int* ldz, lapack_int* nzc, lapack_int* isuppz,
+ lapack_logical* tryrac, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_cstemr( char* jobz, char* range, lapack_int* n, float* d, float* e,
+ float* vl, float* vu, lapack_int* il, lapack_int* iu,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int* ldz, lapack_int* nzc, lapack_int* isuppz,
+ lapack_logical* tryrac, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_zstemr( char* jobz, char* range, lapack_int* n, double* d,
+ double* e, double* vl, double* vu, lapack_int* il,
+ lapack_int* iu, lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int* ldz, lapack_int* nzc,
+ lapack_int* isuppz, lapack_logical* tryrac, double* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_int *info );
+void LAPACK_sstedc( char* compz, lapack_int* n, float* d, float* e, float* z,
+ lapack_int* ldz, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_dstedc( char* compz, lapack_int* n, double* d, double* e, double* z,
+ lapack_int* ldz, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_cstedc( char* compz, lapack_int* n, float* d, float* e,
+ lapack_complex_float* z, lapack_int* ldz,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_int *info );
+void LAPACK_zstedc( char* compz, lapack_int* n, double* d, double* e,
+ lapack_complex_double* z, lapack_int* ldz,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int* lrwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_sstegr( char* jobz, char* range, lapack_int* n, float* d, float* e,
+ float* vl, float* vu, lapack_int* il, lapack_int* iu,
+ float* abstol, lapack_int* m, float* w, float* z,
+ lapack_int* ldz, lapack_int* isuppz, float* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_int *info );
+void LAPACK_dstegr( char* jobz, char* range, lapack_int* n, double* d,
+ double* e, double* vl, double* vu, lapack_int* il,
+ lapack_int* iu, double* abstol, lapack_int* m, double* w,
+ double* z, lapack_int* ldz, lapack_int* isuppz,
+ double* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_cstegr( char* jobz, char* range, lapack_int* n, float* d, float* e,
+ float* vl, float* vu, lapack_int* il, lapack_int* iu,
+ float* abstol, lapack_int* m, float* w,
+ lapack_complex_float* z, lapack_int* ldz,
+ lapack_int* isuppz, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_zstegr( char* jobz, char* range, lapack_int* n, double* d,
+ double* e, double* vl, double* vu, lapack_int* il,
+ lapack_int* iu, double* abstol, lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int* ldz,
+ lapack_int* isuppz, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_spteqr( char* compz, lapack_int* n, float* d, float* e, float* z,
+ lapack_int* ldz, float* work, lapack_int *info );
+void LAPACK_dpteqr( char* compz, lapack_int* n, double* d, double* e, double* z,
+ lapack_int* ldz, double* work, lapack_int *info );
+void LAPACK_cpteqr( char* compz, lapack_int* n, float* d, float* e,
+ lapack_complex_float* z, lapack_int* ldz, float* work,
+ lapack_int *info );
+void LAPACK_zpteqr( char* compz, lapack_int* n, double* d, double* e,
+ lapack_complex_double* z, lapack_int* ldz, double* work,
+ lapack_int *info );
+void LAPACK_sstebz( char* range, char* order, lapack_int* n, float* vl,
+ float* vu, lapack_int* il, lapack_int* iu, float* abstol,
+ const float* d, const float* e, lapack_int* m,
+ lapack_int* nsplit, float* w, lapack_int* iblock,
+ lapack_int* isplit, float* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dstebz( char* range, char* order, lapack_int* n, double* vl,
+ double* vu, lapack_int* il, lapack_int* iu, double* abstol,
+ const double* d, const double* e, lapack_int* m,
+ lapack_int* nsplit, double* w, lapack_int* iblock,
+ lapack_int* isplit, double* work, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_sstein( lapack_int* n, const float* d, const float* e,
+ lapack_int* m, const float* w, const lapack_int* iblock,
+ const lapack_int* isplit, float* z, lapack_int* ldz,
+ float* work, lapack_int* iwork, lapack_int* ifailv,
+ lapack_int *info );
+void LAPACK_dstein( lapack_int* n, const double* d, const double* e,
+ lapack_int* m, const double* w, const lapack_int* iblock,
+ const lapack_int* isplit, double* z, lapack_int* ldz,
+ double* work, lapack_int* iwork, lapack_int* ifailv,
+ lapack_int *info );
+void LAPACK_cstein( lapack_int* n, const float* d, const float* e,
+ lapack_int* m, const float* w, const lapack_int* iblock,
+ const lapack_int* isplit, lapack_complex_float* z,
+ lapack_int* ldz, float* work, lapack_int* iwork,
+ lapack_int* ifailv, lapack_int *info );
+void LAPACK_zstein( lapack_int* n, const double* d, const double* e,
+ lapack_int* m, const double* w, const lapack_int* iblock,
+ const lapack_int* isplit, lapack_complex_double* z,
+ lapack_int* ldz, double* work, lapack_int* iwork,
+ lapack_int* ifailv, lapack_int *info );
+void LAPACK_sdisna( char* job, lapack_int* m, lapack_int* n, const float* d,
+ float* sep, lapack_int *info );
+void LAPACK_ddisna( char* job, lapack_int* m, lapack_int* n, const double* d,
+ double* sep, lapack_int *info );
+void LAPACK_ssygst( lapack_int* itype, char* uplo, lapack_int* n, float* a,
+ lapack_int* lda, const float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_dsygst( lapack_int* itype, char* uplo, lapack_int* n, double* a,
+ lapack_int* lda, const double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_chegst( lapack_int* itype, char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_zhegst( lapack_int* itype, char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_int *info );
+void LAPACK_sspgst( lapack_int* itype, char* uplo, lapack_int* n, float* ap,
+ const float* bp, lapack_int *info );
+void LAPACK_dspgst( lapack_int* itype, char* uplo, lapack_int* n, double* ap,
+ const double* bp, lapack_int *info );
+void LAPACK_chpgst( lapack_int* itype, char* uplo, lapack_int* n,
+ lapack_complex_float* ap, const lapack_complex_float* bp,
+ lapack_int *info );
+void LAPACK_zhpgst( lapack_int* itype, char* uplo, lapack_int* n,
+ lapack_complex_double* ap, const lapack_complex_double* bp,
+ lapack_int *info );
+void LAPACK_ssbgst( char* vect, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, float* ab, lapack_int* ldab,
+ const float* bb, lapack_int* ldbb, float* x,
+ lapack_int* ldx, float* work, lapack_int *info );
+void LAPACK_dsbgst( char* vect, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, double* ab, lapack_int* ldab,
+ const double* bb, lapack_int* ldbb, double* x,
+ lapack_int* ldx, double* work, lapack_int *info );
+void LAPACK_chbgst( char* vect, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, lapack_complex_float* ab, lapack_int* ldab,
+ const lapack_complex_float* bb, lapack_int* ldbb,
+ lapack_complex_float* x, lapack_int* ldx,
+ lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zhbgst( char* vect, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, lapack_complex_double* ab, lapack_int* ldab,
+ const lapack_complex_double* bb, lapack_int* ldbb,
+ lapack_complex_double* x, lapack_int* ldx,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_spbstf( char* uplo, lapack_int* n, lapack_int* kb, float* bb,
+ lapack_int* ldbb, lapack_int *info );
+void LAPACK_dpbstf( char* uplo, lapack_int* n, lapack_int* kb, double* bb,
+ lapack_int* ldbb, lapack_int *info );
+void LAPACK_cpbstf( char* uplo, lapack_int* n, lapack_int* kb,
+ lapack_complex_float* bb, lapack_int* ldbb,
+ lapack_int *info );
+void LAPACK_zpbstf( char* uplo, lapack_int* n, lapack_int* kb,
+ lapack_complex_double* bb, lapack_int* ldbb,
+ lapack_int *info );
+void LAPACK_sgehrd( lapack_int* n, lapack_int* ilo, lapack_int* ihi, float* a,
+ lapack_int* lda, float* tau, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dgehrd( lapack_int* n, lapack_int* ilo, lapack_int* ihi, double* a,
+ lapack_int* lda, double* tau, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cgehrd( lapack_int* n, lapack_int* ilo, lapack_int* ihi,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* tau, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zgehrd( lapack_int* n, lapack_int* ilo, lapack_int* ihi,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* tau, lapack_complex_double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sorghr( lapack_int* n, lapack_int* ilo, lapack_int* ihi, float* a,
+ lapack_int* lda, const float* tau, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dorghr( lapack_int* n, lapack_int* ilo, lapack_int* ihi, double* a,
+ lapack_int* lda, const double* tau, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sormhr( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* ilo, lapack_int* ihi, const float* a,
+ lapack_int* lda, const float* tau, float* c,
+ lapack_int* ldc, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dormhr( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* ilo, lapack_int* ihi, const double* a,
+ lapack_int* lda, const double* tau, double* c,
+ lapack_int* ldc, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cunghr( lapack_int* n, lapack_int* ilo, lapack_int* ihi,
+ lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* tau, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zunghr( lapack_int* n, lapack_int* ilo, lapack_int* ihi,
+ lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cunmhr( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* ilo, lapack_int* ihi,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* tau, lapack_complex_float* c,
+ lapack_int* ldc, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zunmhr( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* ilo, lapack_int* ihi,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* tau, lapack_complex_double* c,
+ lapack_int* ldc, lapack_complex_double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sgebal( char* job, lapack_int* n, float* a, lapack_int* lda,
+ lapack_int* ilo, lapack_int* ihi, float* scale,
+ lapack_int *info );
+void LAPACK_dgebal( char* job, lapack_int* n, double* a, lapack_int* lda,
+ lapack_int* ilo, lapack_int* ihi, double* scale,
+ lapack_int *info );
+void LAPACK_cgebal( char* job, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int* ilo, lapack_int* ihi,
+ float* scale, lapack_int *info );
+void LAPACK_zgebal( char* job, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* ilo, lapack_int* ihi,
+ double* scale, lapack_int *info );
+void LAPACK_sgebak( char* job, char* side, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, const float* scale, lapack_int* m,
+ float* v, lapack_int* ldv, lapack_int *info );
+void LAPACK_dgebak( char* job, char* side, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, const double* scale, lapack_int* m,
+ double* v, lapack_int* ldv, lapack_int *info );
+void LAPACK_cgebak( char* job, char* side, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, const float* scale, lapack_int* m,
+ lapack_complex_float* v, lapack_int* ldv,
+ lapack_int *info );
+void LAPACK_zgebak( char* job, char* side, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, const double* scale, lapack_int* m,
+ lapack_complex_double* v, lapack_int* ldv,
+ lapack_int *info );
+void LAPACK_shseqr( char* job, char* compz, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, float* h, lapack_int* ldh, float* wr,
+ float* wi, float* z, lapack_int* ldz, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dhseqr( char* job, char* compz, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, double* h, lapack_int* ldh, double* wr,
+ double* wi, double* z, lapack_int* ldz, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_chseqr( char* job, char* compz, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, lapack_complex_float* h, lapack_int* ldh,
+ lapack_complex_float* w, lapack_complex_float* z,
+ lapack_int* ldz, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zhseqr( char* job, char* compz, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, lapack_complex_double* h, lapack_int* ldh,
+ lapack_complex_double* w, lapack_complex_double* z,
+ lapack_int* ldz, lapack_complex_double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_shsein( char* job, char* eigsrc, char* initv,
+ lapack_logical* select, lapack_int* n, const float* h,
+ lapack_int* ldh, float* wr, const float* wi, float* vl,
+ lapack_int* ldvl, float* vr, lapack_int* ldvr,
+ lapack_int* mm, lapack_int* m, float* work,
+ lapack_int* ifaill, lapack_int* ifailr, lapack_int *info );
+void LAPACK_dhsein( char* job, char* eigsrc, char* initv,
+ lapack_logical* select, lapack_int* n, const double* h,
+ lapack_int* ldh, double* wr, const double* wi, double* vl,
+ lapack_int* ldvl, double* vr, lapack_int* ldvr,
+ lapack_int* mm, lapack_int* m, double* work,
+ lapack_int* ifaill, lapack_int* ifailr, lapack_int *info );
+void LAPACK_chsein( char* job, char* eigsrc, char* initv,
+ const lapack_logical* select, lapack_int* n,
+ const lapack_complex_float* h, lapack_int* ldh,
+ lapack_complex_float* w, lapack_complex_float* vl,
+ lapack_int* ldvl, lapack_complex_float* vr,
+ lapack_int* ldvr, lapack_int* mm, lapack_int* m,
+ lapack_complex_float* work, float* rwork,
+ lapack_int* ifaill, lapack_int* ifailr, lapack_int *info );
+void LAPACK_zhsein( char* job, char* eigsrc, char* initv,
+ const lapack_logical* select, lapack_int* n,
+ const lapack_complex_double* h, lapack_int* ldh,
+ lapack_complex_double* w, lapack_complex_double* vl,
+ lapack_int* ldvl, lapack_complex_double* vr,
+ lapack_int* ldvr, lapack_int* mm, lapack_int* m,
+ lapack_complex_double* work, double* rwork,
+ lapack_int* ifaill, lapack_int* ifailr, lapack_int *info );
+void LAPACK_strevc( char* side, char* howmny, lapack_logical* select,
+ lapack_int* n, const float* t, lapack_int* ldt, float* vl,
+ lapack_int* ldvl, float* vr, lapack_int* ldvr,
+ lapack_int* mm, lapack_int* m, float* work,
+ lapack_int *info );
+void LAPACK_dtrevc( char* side, char* howmny, lapack_logical* select,
+ lapack_int* n, const double* t, lapack_int* ldt, double* vl,
+ lapack_int* ldvl, double* vr, lapack_int* ldvr,
+ lapack_int* mm, lapack_int* m, double* work,
+ lapack_int *info );
+void LAPACK_ctrevc( char* side, char* howmny, const lapack_logical* select,
+ lapack_int* n, lapack_complex_float* t, lapack_int* ldt,
+ lapack_complex_float* vl, lapack_int* ldvl,
+ lapack_complex_float* vr, lapack_int* ldvr, lapack_int* mm,
+ lapack_int* m, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_ztrevc( char* side, char* howmny, const lapack_logical* select,
+ lapack_int* n, lapack_complex_double* t, lapack_int* ldt,
+ lapack_complex_double* vl, lapack_int* ldvl,
+ lapack_complex_double* vr, lapack_int* ldvr, lapack_int* mm,
+ lapack_int* m, lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_strsna( char* job, char* howmny, const lapack_logical* select,
+ lapack_int* n, const float* t, lapack_int* ldt,
+ const float* vl, lapack_int* ldvl, const float* vr,
+ lapack_int* ldvr, float* s, float* sep, lapack_int* mm,
+ lapack_int* m, float* work, lapack_int* ldwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_dtrsna( char* job, char* howmny, const lapack_logical* select,
+ lapack_int* n, const double* t, lapack_int* ldt,
+ const double* vl, lapack_int* ldvl, const double* vr,
+ lapack_int* ldvr, double* s, double* sep, lapack_int* mm,
+ lapack_int* m, double* work, lapack_int* ldwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_ctrsna( char* job, char* howmny, const lapack_logical* select,
+ lapack_int* n, const lapack_complex_float* t,
+ lapack_int* ldt, const lapack_complex_float* vl,
+ lapack_int* ldvl, const lapack_complex_float* vr,
+ lapack_int* ldvr, float* s, float* sep, lapack_int* mm,
+ lapack_int* m, lapack_complex_float* work,
+ lapack_int* ldwork, float* rwork, lapack_int *info );
+void LAPACK_ztrsna( char* job, char* howmny, const lapack_logical* select,
+ lapack_int* n, const lapack_complex_double* t,
+ lapack_int* ldt, const lapack_complex_double* vl,
+ lapack_int* ldvl, const lapack_complex_double* vr,
+ lapack_int* ldvr, double* s, double* sep, lapack_int* mm,
+ lapack_int* m, lapack_complex_double* work,
+ lapack_int* ldwork, double* rwork, lapack_int *info );
+void LAPACK_strexc( char* compq, lapack_int* n, float* t, lapack_int* ldt,
+ float* q, lapack_int* ldq, lapack_int* ifst,
+ lapack_int* ilst, float* work, lapack_int *info );
+void LAPACK_dtrexc( char* compq, lapack_int* n, double* t, lapack_int* ldt,
+ double* q, lapack_int* ldq, lapack_int* ifst,
+ lapack_int* ilst, double* work, lapack_int *info );
+void LAPACK_ctrexc( char* compq, lapack_int* n, lapack_complex_float* t,
+ lapack_int* ldt, lapack_complex_float* q, lapack_int* ldq,
+ lapack_int* ifst, lapack_int* ilst, lapack_int *info );
+void LAPACK_ztrexc( char* compq, lapack_int* n, lapack_complex_double* t,
+ lapack_int* ldt, lapack_complex_double* q, lapack_int* ldq,
+ lapack_int* ifst, lapack_int* ilst, lapack_int *info );
+void LAPACK_strsen( char* job, char* compq, const lapack_logical* select,
+ lapack_int* n, float* t, lapack_int* ldt, float* q,
+ lapack_int* ldq, float* wr, float* wi, lapack_int* m,
+ float* s, float* sep, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_dtrsen( char* job, char* compq, const lapack_logical* select,
+ lapack_int* n, double* t, lapack_int* ldt, double* q,
+ lapack_int* ldq, double* wr, double* wi, lapack_int* m,
+ double* s, double* sep, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_ctrsen( char* job, char* compq, const lapack_logical* select,
+ lapack_int* n, lapack_complex_float* t, lapack_int* ldt,
+ lapack_complex_float* q, lapack_int* ldq,
+ lapack_complex_float* w, lapack_int* m, float* s,
+ float* sep, lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_ztrsen( char* job, char* compq, const lapack_logical* select,
+ lapack_int* n, lapack_complex_double* t, lapack_int* ldt,
+ lapack_complex_double* q, lapack_int* ldq,
+ lapack_complex_double* w, lapack_int* m, double* s,
+ double* sep, lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_strsyl( char* trana, char* tranb, lapack_int* isgn, lapack_int* m,
+ lapack_int* n, const float* a, lapack_int* lda,
+ const float* b, lapack_int* ldb, float* c, lapack_int* ldc,
+ float* scale, lapack_int *info );
+void LAPACK_dtrsyl( char* trana, char* tranb, lapack_int* isgn, lapack_int* m,
+ lapack_int* n, const double* a, lapack_int* lda,
+ const double* b, lapack_int* ldb, double* c,
+ lapack_int* ldc, double* scale, lapack_int *info );
+void LAPACK_ctrsyl( char* trana, char* tranb, lapack_int* isgn, lapack_int* m,
+ lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_complex_float* b,
+ lapack_int* ldb, lapack_complex_float* c, lapack_int* ldc,
+ float* scale, lapack_int *info );
+void LAPACK_ztrsyl( char* trana, char* tranb, lapack_int* isgn, lapack_int* m,
+ lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, const lapack_complex_double* b,
+ lapack_int* ldb, lapack_complex_double* c, lapack_int* ldc,
+ double* scale, lapack_int *info );
+void LAPACK_sgghrd( char* compq, char* compz, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, float* a, lapack_int* lda, float* b,
+ lapack_int* ldb, float* q, lapack_int* ldq, float* z,
+ lapack_int* ldz, lapack_int *info );
+void LAPACK_dgghrd( char* compq, char* compz, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, double* a, lapack_int* lda, double* b,
+ lapack_int* ldb, double* q, lapack_int* ldq, double* z,
+ lapack_int* ldz, lapack_int *info );
+void LAPACK_cgghrd( char* compq, char* compz, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* q, lapack_int* ldq,
+ lapack_complex_float* z, lapack_int* ldz,
+ lapack_int *info );
+void LAPACK_zgghrd( char* compq, char* compz, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* q, lapack_int* ldq,
+ lapack_complex_double* z, lapack_int* ldz,
+ lapack_int *info );
+void LAPACK_sggbal( char* job, lapack_int* n, float* a, lapack_int* lda,
+ float* b, lapack_int* ldb, lapack_int* ilo, lapack_int* ihi,
+ float* lscale, float* rscale, float* work,
+ lapack_int *info );
+void LAPACK_dggbal( char* job, lapack_int* n, double* a, lapack_int* lda,
+ double* b, lapack_int* ldb, lapack_int* ilo,
+ lapack_int* ihi, double* lscale, double* rscale,
+ double* work, lapack_int *info );
+void LAPACK_cggbal( char* job, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* b, lapack_int* ldb,
+ lapack_int* ilo, lapack_int* ihi, float* lscale,
+ float* rscale, float* work, lapack_int *info );
+void LAPACK_zggbal( char* job, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* b, lapack_int* ldb,
+ lapack_int* ilo, lapack_int* ihi, double* lscale,
+ double* rscale, double* work, lapack_int *info );
+void LAPACK_sggbak( char* job, char* side, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, const float* lscale, const float* rscale,
+ lapack_int* m, float* v, lapack_int* ldv,
+ lapack_int *info );
+void LAPACK_dggbak( char* job, char* side, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, const double* lscale, const double* rscale,
+ lapack_int* m, double* v, lapack_int* ldv,
+ lapack_int *info );
+void LAPACK_cggbak( char* job, char* side, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, const float* lscale, const float* rscale,
+ lapack_int* m, lapack_complex_float* v, lapack_int* ldv,
+ lapack_int *info );
+void LAPACK_zggbak( char* job, char* side, lapack_int* n, lapack_int* ilo,
+ lapack_int* ihi, const double* lscale, const double* rscale,
+ lapack_int* m, lapack_complex_double* v, lapack_int* ldv,
+ lapack_int *info );
+void LAPACK_shgeqz( char* job, char* compq, char* compz, lapack_int* n,
+ lapack_int* ilo, lapack_int* ihi, float* h, lapack_int* ldh,
+ float* t, lapack_int* ldt, float* alphar, float* alphai,
+ float* beta, float* q, lapack_int* ldq, float* z,
+ lapack_int* ldz, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dhgeqz( char* job, char* compq, char* compz, lapack_int* n,
+ lapack_int* ilo, lapack_int* ihi, double* h,
+ lapack_int* ldh, double* t, lapack_int* ldt, double* alphar,
+ double* alphai, double* beta, double* q, lapack_int* ldq,
+ double* z, lapack_int* ldz, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_chgeqz( char* job, char* compq, char* compz, lapack_int* n,
+ lapack_int* ilo, lapack_int* ihi, lapack_complex_float* h,
+ lapack_int* ldh, lapack_complex_float* t, lapack_int* ldt,
+ lapack_complex_float* alpha, lapack_complex_float* beta,
+ lapack_complex_float* q, lapack_int* ldq,
+ lapack_complex_float* z, lapack_int* ldz,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int *info );
+void LAPACK_zhgeqz( char* job, char* compq, char* compz, lapack_int* n,
+ lapack_int* ilo, lapack_int* ihi, lapack_complex_double* h,
+ lapack_int* ldh, lapack_complex_double* t, lapack_int* ldt,
+ lapack_complex_double* alpha, lapack_complex_double* beta,
+ lapack_complex_double* q, lapack_int* ldq,
+ lapack_complex_double* z, lapack_int* ldz,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int *info );
+void LAPACK_stgevc( char* side, char* howmny, const lapack_logical* select,
+ lapack_int* n, const float* s, lapack_int* lds,
+ const float* p, lapack_int* ldp, float* vl,
+ lapack_int* ldvl, float* vr, lapack_int* ldvr,
+ lapack_int* mm, lapack_int* m, float* work,
+ lapack_int *info );
+void LAPACK_dtgevc( char* side, char* howmny, const lapack_logical* select,
+ lapack_int* n, const double* s, lapack_int* lds,
+ const double* p, lapack_int* ldp, double* vl,
+ lapack_int* ldvl, double* vr, lapack_int* ldvr,
+ lapack_int* mm, lapack_int* m, double* work,
+ lapack_int *info );
+void LAPACK_ctgevc( char* side, char* howmny, const lapack_logical* select,
+ lapack_int* n, const lapack_complex_float* s,
+ lapack_int* lds, const lapack_complex_float* p,
+ lapack_int* ldp, lapack_complex_float* vl, lapack_int* ldvl,
+ lapack_complex_float* vr, lapack_int* ldvr, lapack_int* mm,
+ lapack_int* m, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_ztgevc( char* side, char* howmny, const lapack_logical* select,
+ lapack_int* n, const lapack_complex_double* s,
+ lapack_int* lds, const lapack_complex_double* p,
+ lapack_int* ldp, lapack_complex_double* vl,
+ lapack_int* ldvl, lapack_complex_double* vr,
+ lapack_int* ldvr, lapack_int* mm, lapack_int* m,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_stgexc( lapack_logical* wantq, lapack_logical* wantz, lapack_int* n,
+ float* a, lapack_int* lda, float* b, lapack_int* ldb,
+ float* q, lapack_int* ldq, float* z, lapack_int* ldz,
+ lapack_int* ifst, lapack_int* ilst, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dtgexc( lapack_logical* wantq, lapack_logical* wantz, lapack_int* n,
+ double* a, lapack_int* lda, double* b, lapack_int* ldb,
+ double* q, lapack_int* ldq, double* z, lapack_int* ldz,
+ lapack_int* ifst, lapack_int* ilst, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_ctgexc( lapack_logical* wantq, lapack_logical* wantz, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* q, lapack_int* ldq,
+ lapack_complex_float* z, lapack_int* ldz, lapack_int* ifst,
+ lapack_int* ilst, lapack_int *info );
+void LAPACK_ztgexc( lapack_logical* wantq, lapack_logical* wantz, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* q, lapack_int* ldq,
+ lapack_complex_double* z, lapack_int* ldz, lapack_int* ifst,
+ lapack_int* ilst, lapack_int *info );
+void LAPACK_stgsen( lapack_int* ijob, lapack_logical* wantq,
+ lapack_logical* wantz, const lapack_logical* select,
+ lapack_int* n, float* a, lapack_int* lda, float* b,
+ lapack_int* ldb, float* alphar, float* alphai, float* beta,
+ float* q, lapack_int* ldq, float* z, lapack_int* ldz,
+ lapack_int* m, float* pl, float* pr, float* dif,
+ float* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_dtgsen( lapack_int* ijob, lapack_logical* wantq,
+ lapack_logical* wantz, const lapack_logical* select,
+ lapack_int* n, double* a, lapack_int* lda, double* b,
+ lapack_int* ldb, double* alphar, double* alphai,
+ double* beta, double* q, lapack_int* ldq, double* z,
+ lapack_int* ldz, lapack_int* m, double* pl, double* pr,
+ double* dif, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_ctgsen( lapack_int* ijob, lapack_logical* wantq,
+ lapack_logical* wantz, const lapack_logical* select,
+ lapack_int* n, lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* alpha, lapack_complex_float* beta,
+ lapack_complex_float* q, lapack_int* ldq,
+ lapack_complex_float* z, lapack_int* ldz, lapack_int* m,
+ float* pl, float* pr, float* dif,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_ztgsen( lapack_int* ijob, lapack_logical* wantq,
+ lapack_logical* wantz, const lapack_logical* select,
+ lapack_int* n, lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* alpha, lapack_complex_double* beta,
+ lapack_complex_double* q, lapack_int* ldq,
+ lapack_complex_double* z, lapack_int* ldz, lapack_int* m,
+ double* pl, double* pr, double* dif,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_stgsyl( char* trans, lapack_int* ijob, lapack_int* m, lapack_int* n,
+ const float* a, lapack_int* lda, const float* b,
+ lapack_int* ldb, float* c, lapack_int* ldc, const float* d,
+ lapack_int* ldd, const float* e, lapack_int* lde, float* f,
+ lapack_int* ldf, float* scale, float* dif, float* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_int *info );
+void LAPACK_dtgsyl( char* trans, lapack_int* ijob, lapack_int* m, lapack_int* n,
+ const double* a, lapack_int* lda, const double* b,
+ lapack_int* ldb, double* c, lapack_int* ldc,
+ const double* d, lapack_int* ldd, const double* e,
+ lapack_int* lde, double* f, lapack_int* ldf, double* scale,
+ double* dif, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_ctgsyl( char* trans, lapack_int* ijob, lapack_int* m, lapack_int* n,
+ const lapack_complex_float* a, lapack_int* lda,
+ const lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* c, lapack_int* ldc,
+ const lapack_complex_float* d, lapack_int* ldd,
+ const lapack_complex_float* e, lapack_int* lde,
+ lapack_complex_float* f, lapack_int* ldf, float* scale,
+ float* dif, lapack_complex_float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_ztgsyl( char* trans, lapack_int* ijob, lapack_int* m, lapack_int* n,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* c, lapack_int* ldc,
+ const lapack_complex_double* d, lapack_int* ldd,
+ const lapack_complex_double* e, lapack_int* lde,
+ lapack_complex_double* f, lapack_int* ldf, double* scale,
+ double* dif, lapack_complex_double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_stgsna( char* job, char* howmny, const lapack_logical* select,
+ lapack_int* n, const float* a, lapack_int* lda,
+ const float* b, lapack_int* ldb, const float* vl,
+ lapack_int* ldvl, const float* vr, lapack_int* ldvr,
+ float* s, float* dif, lapack_int* mm, lapack_int* m,
+ float* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dtgsna( char* job, char* howmny, const lapack_logical* select,
+ lapack_int* n, const double* a, lapack_int* lda,
+ const double* b, lapack_int* ldb, const double* vl,
+ lapack_int* ldvl, const double* vr, lapack_int* ldvr,
+ double* s, double* dif, lapack_int* mm, lapack_int* m,
+ double* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_ctgsna( char* job, char* howmny, const lapack_logical* select,
+ lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_complex_float* b,
+ lapack_int* ldb, const lapack_complex_float* vl,
+ lapack_int* ldvl, const lapack_complex_float* vr,
+ lapack_int* ldvr, float* s, float* dif, lapack_int* mm,
+ lapack_int* m, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_int *info );
+void LAPACK_ztgsna( char* job, char* howmny, const lapack_logical* select,
+ lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, const lapack_complex_double* b,
+ lapack_int* ldb, const lapack_complex_double* vl,
+ lapack_int* ldvl, const lapack_complex_double* vr,
+ lapack_int* ldvr, double* s, double* dif, lapack_int* mm,
+ lapack_int* m, lapack_complex_double* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_int *info );
+void LAPACK_sggsvp( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* p, lapack_int* n, float* a, lapack_int* lda,
+ float* b, lapack_int* ldb, float* tola, float* tolb,
+ lapack_int* k, lapack_int* l, float* u, lapack_int* ldu,
+ float* v, lapack_int* ldv, float* q, lapack_int* ldq,
+ lapack_int* iwork, float* tau, float* work,
+ lapack_int *info );
+void LAPACK_dggsvp( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* p, lapack_int* n, double* a, lapack_int* lda,
+ double* b, lapack_int* ldb, double* tola, double* tolb,
+ lapack_int* k, lapack_int* l, double* u, lapack_int* ldu,
+ double* v, lapack_int* ldv, double* q, lapack_int* ldq,
+ lapack_int* iwork, double* tau, double* work,
+ lapack_int *info );
+void LAPACK_cggsvp( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* p, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* b, lapack_int* ldb,
+ float* tola, float* tolb, lapack_int* k, lapack_int* l,
+ lapack_complex_float* u, lapack_int* ldu,
+ lapack_complex_float* v, lapack_int* ldv,
+ lapack_complex_float* q, lapack_int* ldq, lapack_int* iwork,
+ float* rwork, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zggsvp( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* p, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* b, lapack_int* ldb,
+ double* tola, double* tolb, lapack_int* k, lapack_int* l,
+ lapack_complex_double* u, lapack_int* ldu,
+ lapack_complex_double* v, lapack_int* ldv,
+ lapack_complex_double* q, lapack_int* ldq,
+ lapack_int* iwork, double* rwork,
+ lapack_complex_double* tau, lapack_complex_double* work,
+ lapack_int *info );
+void LAPACK_stgsja( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* p, lapack_int* n, lapack_int* k, lapack_int* l,
+ float* a, lapack_int* lda, float* b, lapack_int* ldb,
+ float* tola, float* tolb, float* alpha, float* beta,
+ float* u, lapack_int* ldu, float* v, lapack_int* ldv,
+ float* q, lapack_int* ldq, float* work, lapack_int* ncycle,
+ lapack_int *info );
+void LAPACK_dtgsja( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* p, lapack_int* n, lapack_int* k, lapack_int* l,
+ double* a, lapack_int* lda, double* b, lapack_int* ldb,
+ double* tola, double* tolb, double* alpha, double* beta,
+ double* u, lapack_int* ldu, double* v, lapack_int* ldv,
+ double* q, lapack_int* ldq, double* work,
+ lapack_int* ncycle, lapack_int *info );
+void LAPACK_ctgsja( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* p, lapack_int* n, lapack_int* k, lapack_int* l,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb, float* tola,
+ float* tolb, float* alpha, float* beta,
+ lapack_complex_float* u, lapack_int* ldu,
+ lapack_complex_float* v, lapack_int* ldv,
+ lapack_complex_float* q, lapack_int* ldq,
+ lapack_complex_float* work, lapack_int* ncycle,
+ lapack_int *info );
+void LAPACK_ztgsja( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* p, lapack_int* n, lapack_int* k, lapack_int* l,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb, double* tola,
+ double* tolb, double* alpha, double* beta,
+ lapack_complex_double* u, lapack_int* ldu,
+ lapack_complex_double* v, lapack_int* ldv,
+ lapack_complex_double* q, lapack_int* ldq,
+ lapack_complex_double* work, lapack_int* ncycle,
+ lapack_int *info );
+void LAPACK_sgels( char* trans, lapack_int* m, lapack_int* n, lapack_int* nrhs,
+ float* a, lapack_int* lda, float* b, lapack_int* ldb,
+ float* work, lapack_int* lwork, lapack_int *info );
+void LAPACK_dgels( char* trans, lapack_int* m, lapack_int* n, lapack_int* nrhs,
+ double* a, lapack_int* lda, double* b, lapack_int* ldb,
+ double* work, lapack_int* lwork, lapack_int *info );
+void LAPACK_cgels( char* trans, lapack_int* m, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zgels( char* trans, lapack_int* m, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_sgelsy( lapack_int* m, lapack_int* n, lapack_int* nrhs, float* a,
+ lapack_int* lda, float* b, lapack_int* ldb,
+ lapack_int* jpvt, float* rcond, lapack_int* rank,
+ float* work, lapack_int* lwork, lapack_int *info );
+void LAPACK_dgelsy( lapack_int* m, lapack_int* n, lapack_int* nrhs, double* a,
+ lapack_int* lda, double* b, lapack_int* ldb,
+ lapack_int* jpvt, double* rcond, lapack_int* rank,
+ double* work, lapack_int* lwork, lapack_int *info );
+void LAPACK_cgelsy( lapack_int* m, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb, lapack_int* jpvt,
+ float* rcond, lapack_int* rank, lapack_complex_float* work,
+ lapack_int* lwork, float* rwork, lapack_int *info );
+void LAPACK_zgelsy( lapack_int* m, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb, lapack_int* jpvt,
+ double* rcond, lapack_int* rank,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int *info );
+void LAPACK_sgelss( lapack_int* m, lapack_int* n, lapack_int* nrhs, float* a,
+ lapack_int* lda, float* b, lapack_int* ldb, float* s,
+ float* rcond, lapack_int* rank, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dgelss( lapack_int* m, lapack_int* n, lapack_int* nrhs, double* a,
+ lapack_int* lda, double* b, lapack_int* ldb, double* s,
+ double* rcond, lapack_int* rank, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cgelss( lapack_int* m, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb, float* s,
+ float* rcond, lapack_int* rank, lapack_complex_float* work,
+ lapack_int* lwork, float* rwork, lapack_int *info );
+void LAPACK_zgelss( lapack_int* m, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb, double* s,
+ double* rcond, lapack_int* rank,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int *info );
+void LAPACK_sgelsd( lapack_int* m, lapack_int* n, lapack_int* nrhs, float* a,
+ lapack_int* lda, float* b, lapack_int* ldb, float* s,
+ float* rcond, lapack_int* rank, float* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_int *info );
+void LAPACK_dgelsd( lapack_int* m, lapack_int* n, lapack_int* nrhs, double* a,
+ lapack_int* lda, double* b, lapack_int* ldb, double* s,
+ double* rcond, lapack_int* rank, double* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_int *info );
+void LAPACK_cgelsd( lapack_int* m, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb, float* s,
+ float* rcond, lapack_int* rank, lapack_complex_float* work,
+ lapack_int* lwork, float* rwork, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_zgelsd( lapack_int* m, lapack_int* n, lapack_int* nrhs,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb, double* s,
+ double* rcond, lapack_int* rank,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int* iwork, lapack_int *info );
+void LAPACK_sgglse( lapack_int* m, lapack_int* n, lapack_int* p, float* a,
+ lapack_int* lda, float* b, lapack_int* ldb, float* c,
+ float* d, float* x, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dgglse( lapack_int* m, lapack_int* n, lapack_int* p, double* a,
+ lapack_int* lda, double* b, lapack_int* ldb, double* c,
+ double* d, double* x, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cgglse( lapack_int* m, lapack_int* n, lapack_int* p,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* c, lapack_complex_float* d,
+ lapack_complex_float* x, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zgglse( lapack_int* m, lapack_int* n, lapack_int* p,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* c, lapack_complex_double* d,
+ lapack_complex_double* x, lapack_complex_double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sggglm( lapack_int* n, lapack_int* m, lapack_int* p, float* a,
+ lapack_int* lda, float* b, lapack_int* ldb, float* d,
+ float* x, float* y, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dggglm( lapack_int* n, lapack_int* m, lapack_int* p, double* a,
+ lapack_int* lda, double* b, lapack_int* ldb, double* d,
+ double* x, double* y, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cggglm( lapack_int* n, lapack_int* m, lapack_int* p,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* d, lapack_complex_float* x,
+ lapack_complex_float* y, lapack_complex_float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_zggglm( lapack_int* n, lapack_int* m, lapack_int* p,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* d, lapack_complex_double* x,
+ lapack_complex_double* y, lapack_complex_double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_ssyev( char* jobz, char* uplo, lapack_int* n, float* a,
+ lapack_int* lda, float* w, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dsyev( char* jobz, char* uplo, lapack_int* n, double* a,
+ lapack_int* lda, double* w, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cheev( char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda, float* w,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int *info );
+void LAPACK_zheev( char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda, double* w,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int *info );
+void LAPACK_ssyevd( char* jobz, char* uplo, lapack_int* n, float* a,
+ lapack_int* lda, float* w, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_dsyevd( char* jobz, char* uplo, lapack_int* n, double* a,
+ lapack_int* lda, double* w, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_cheevd( char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda, float* w,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_int *info );
+void LAPACK_zheevd( char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda, double* w,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int* lrwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_ssyevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ float* a, lapack_int* lda, float* vl, float* vu,
+ lapack_int* il, lapack_int* iu, float* abstol,
+ lapack_int* m, float* w, float* z, lapack_int* ldz,
+ float* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_dsyevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ double* a, lapack_int* lda, double* vl, double* vu,
+ lapack_int* il, lapack_int* iu, double* abstol,
+ lapack_int* m, double* w, double* z, lapack_int* ldz,
+ double* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_cheevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda, float* vl,
+ float* vu, lapack_int* il, lapack_int* iu, float* abstol,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int* ldz, lapack_complex_float* work,
+ lapack_int* lwork, float* rwork, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_zheevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda, double* vl,
+ double* vu, lapack_int* il, lapack_int* iu, double* abstol,
+ lapack_int* m, double* w, lapack_complex_double* z,
+ lapack_int* ldz, lapack_complex_double* work,
+ lapack_int* lwork, double* rwork, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_ssyevr( char* jobz, char* range, char* uplo, lapack_int* n,
+ float* a, lapack_int* lda, float* vl, float* vu,
+ lapack_int* il, lapack_int* iu, float* abstol,
+ lapack_int* m, float* w, float* z, lapack_int* ldz,
+ lapack_int* isuppz, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_dsyevr( char* jobz, char* range, char* uplo, lapack_int* n,
+ double* a, lapack_int* lda, double* vl, double* vu,
+ lapack_int* il, lapack_int* iu, double* abstol,
+ lapack_int* m, double* w, double* z, lapack_int* ldz,
+ lapack_int* isuppz, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_cheevr( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda, float* vl,
+ float* vu, lapack_int* il, lapack_int* iu, float* abstol,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int* ldz, lapack_int* isuppz,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_int *info );
+void LAPACK_zheevr( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda, double* vl,
+ double* vu, lapack_int* il, lapack_int* iu, double* abstol,
+ lapack_int* m, double* w, lapack_complex_double* z,
+ lapack_int* ldz, lapack_int* isuppz,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int* lrwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_sspev( char* jobz, char* uplo, lapack_int* n, float* ap, float* w,
+ float* z, lapack_int* ldz, float* work, lapack_int *info );
+void LAPACK_dspev( char* jobz, char* uplo, lapack_int* n, double* ap, double* w,
+ double* z, lapack_int* ldz, double* work, lapack_int *info );
+void LAPACK_chpev( char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_float* ap, float* w, lapack_complex_float* z,
+ lapack_int* ldz, lapack_complex_float* work, float* rwork,
+ lapack_int *info );
+void LAPACK_zhpev( char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_double* ap, double* w,
+ lapack_complex_double* z, lapack_int* ldz,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_sspevd( char* jobz, char* uplo, lapack_int* n, float* ap, float* w,
+ float* z, lapack_int* ldz, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_dspevd( char* jobz, char* uplo, lapack_int* n, double* ap,
+ double* w, double* z, lapack_int* ldz, double* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_int *info );
+void LAPACK_chpevd( char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_float* ap, float* w, lapack_complex_float* z,
+ lapack_int* ldz, lapack_complex_float* work,
+ lapack_int* lwork, float* rwork, lapack_int* lrwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_zhpevd( char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_double* ap, double* w,
+ lapack_complex_double* z, lapack_int* ldz,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int* lrwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_sspevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ float* ap, float* vl, float* vu, lapack_int* il,
+ lapack_int* iu, float* abstol, lapack_int* m, float* w,
+ float* z, lapack_int* ldz, float* work, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_dspevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ double* ap, double* vl, double* vu, lapack_int* il,
+ lapack_int* iu, double* abstol, lapack_int* m, double* w,
+ double* z, lapack_int* ldz, double* work, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_chpevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_complex_float* ap, float* vl, float* vu,
+ lapack_int* il, lapack_int* iu, float* abstol,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int* ldz, lapack_complex_float* work, float* rwork,
+ lapack_int* iwork, lapack_int* ifail, lapack_int *info );
+void LAPACK_zhpevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_complex_double* ap, double* vl, double* vu,
+ lapack_int* il, lapack_int* iu, double* abstol,
+ lapack_int* m, double* w, lapack_complex_double* z,
+ lapack_int* ldz, lapack_complex_double* work, double* rwork,
+ lapack_int* iwork, lapack_int* ifail, lapack_int *info );
+void LAPACK_ssbev( char* jobz, char* uplo, lapack_int* n, lapack_int* kd,
+ float* ab, lapack_int* ldab, float* w, float* z,
+ lapack_int* ldz, float* work, lapack_int *info );
+void LAPACK_dsbev( char* jobz, char* uplo, lapack_int* n, lapack_int* kd,
+ double* ab, lapack_int* ldab, double* w, double* z,
+ lapack_int* ldz, double* work, lapack_int *info );
+void LAPACK_chbev( char* jobz, char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_complex_float* ab, lapack_int* ldab, float* w,
+ lapack_complex_float* z, lapack_int* ldz,
+ lapack_complex_float* work, float* rwork, lapack_int *info );
+void LAPACK_zhbev( char* jobz, char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_complex_double* ab, lapack_int* ldab, double* w,
+ lapack_complex_double* z, lapack_int* ldz,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_ssbevd( char* jobz, char* uplo, lapack_int* n, lapack_int* kd,
+ float* ab, lapack_int* ldab, float* w, float* z,
+ lapack_int* ldz, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_dsbevd( char* jobz, char* uplo, lapack_int* n, lapack_int* kd,
+ double* ab, lapack_int* ldab, double* w, double* z,
+ lapack_int* ldz, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_chbevd( char* jobz, char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_complex_float* ab, lapack_int* ldab, float* w,
+ lapack_complex_float* z, lapack_int* ldz,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_int *info );
+void LAPACK_zhbevd( char* jobz, char* uplo, lapack_int* n, lapack_int* kd,
+ lapack_complex_double* ab, lapack_int* ldab, double* w,
+ lapack_complex_double* z, lapack_int* ldz,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int* lrwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_ssbevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_int* kd, float* ab, lapack_int* ldab, float* q,
+ lapack_int* ldq, float* vl, float* vu, lapack_int* il,
+ lapack_int* iu, float* abstol, lapack_int* m, float* w,
+ float* z, lapack_int* ldz, float* work, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_dsbevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_int* kd, double* ab, lapack_int* ldab, double* q,
+ lapack_int* ldq, double* vl, double* vu, lapack_int* il,
+ lapack_int* iu, double* abstol, lapack_int* m, double* w,
+ double* z, lapack_int* ldz, double* work, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_chbevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_int* kd, lapack_complex_float* ab, lapack_int* ldab,
+ lapack_complex_float* q, lapack_int* ldq, float* vl,
+ float* vu, lapack_int* il, lapack_int* iu, float* abstol,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int* ldz, lapack_complex_float* work, float* rwork,
+ lapack_int* iwork, lapack_int* ifail, lapack_int *info );
+void LAPACK_zhbevx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_int* kd, lapack_complex_double* ab, lapack_int* ldab,
+ lapack_complex_double* q, lapack_int* ldq, double* vl,
+ double* vu, lapack_int* il, lapack_int* iu, double* abstol,
+ lapack_int* m, double* w, lapack_complex_double* z,
+ lapack_int* ldz, lapack_complex_double* work, double* rwork,
+ lapack_int* iwork, lapack_int* ifail, lapack_int *info );
+void LAPACK_sstev( char* jobz, lapack_int* n, float* d, float* e, float* z,
+ lapack_int* ldz, float* work, lapack_int *info );
+void LAPACK_dstev( char* jobz, lapack_int* n, double* d, double* e, double* z,
+ lapack_int* ldz, double* work, lapack_int *info );
+void LAPACK_sstevd( char* jobz, lapack_int* n, float* d, float* e, float* z,
+ lapack_int* ldz, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_dstevd( char* jobz, lapack_int* n, double* d, double* e, double* z,
+ lapack_int* ldz, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_sstevx( char* jobz, char* range, lapack_int* n, float* d, float* e,
+ float* vl, float* vu, lapack_int* il, lapack_int* iu,
+ float* abstol, lapack_int* m, float* w, float* z,
+ lapack_int* ldz, float* work, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_dstevx( char* jobz, char* range, lapack_int* n, double* d,
+ double* e, double* vl, double* vu, lapack_int* il,
+ lapack_int* iu, double* abstol, lapack_int* m, double* w,
+ double* z, lapack_int* ldz, double* work, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_sstevr( char* jobz, char* range, lapack_int* n, float* d, float* e,
+ float* vl, float* vu, lapack_int* il, lapack_int* iu,
+ float* abstol, lapack_int* m, float* w, float* z,
+ lapack_int* ldz, lapack_int* isuppz, float* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_int *info );
+void LAPACK_dstevr( char* jobz, char* range, lapack_int* n, double* d,
+ double* e, double* vl, double* vu, lapack_int* il,
+ lapack_int* iu, double* abstol, lapack_int* m, double* w,
+ double* z, lapack_int* ldz, lapack_int* isuppz,
+ double* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_sgees( char* jobvs, char* sort, LAPACK_S_SELECT2 select,
+ lapack_int* n, float* a, lapack_int* lda, lapack_int* sdim,
+ float* wr, float* wi, float* vs, lapack_int* ldvs,
+ float* work, lapack_int* lwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_dgees( char* jobvs, char* sort, LAPACK_D_SELECT2 select,
+ lapack_int* n, double* a, lapack_int* lda, lapack_int* sdim,
+ double* wr, double* wi, double* vs, lapack_int* ldvs,
+ double* work, lapack_int* lwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_cgees( char* jobvs, char* sort, LAPACK_C_SELECT1 select,
+ lapack_int* n, lapack_complex_float* a, lapack_int* lda,
+ lapack_int* sdim, lapack_complex_float* w,
+ lapack_complex_float* vs, lapack_int* ldvs,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_logical* bwork, lapack_int *info );
+void LAPACK_zgees( char* jobvs, char* sort, LAPACK_Z_SELECT1 select,
+ lapack_int* n, lapack_complex_double* a, lapack_int* lda,
+ lapack_int* sdim, lapack_complex_double* w,
+ lapack_complex_double* vs, lapack_int* ldvs,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_logical* bwork, lapack_int *info );
+void LAPACK_sgeesx( char* jobvs, char* sort, LAPACK_S_SELECT2 select,
+ char* sense, lapack_int* n, float* a, lapack_int* lda,
+ lapack_int* sdim, float* wr, float* wi, float* vs,
+ lapack_int* ldvs, float* rconde, float* rcondv, float* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_logical* bwork, lapack_int *info );
+void LAPACK_dgeesx( char* jobvs, char* sort, LAPACK_D_SELECT2 select,
+ char* sense, lapack_int* n, double* a, lapack_int* lda,
+ lapack_int* sdim, double* wr, double* wi, double* vs,
+ lapack_int* ldvs, double* rconde, double* rcondv,
+ double* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_cgeesx( char* jobvs, char* sort, LAPACK_C_SELECT1 select,
+ char* sense, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int* sdim, lapack_complex_float* w,
+ lapack_complex_float* vs, lapack_int* ldvs, float* rconde,
+ float* rcondv, lapack_complex_float* work,
+ lapack_int* lwork, float* rwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_zgeesx( char* jobvs, char* sort, LAPACK_Z_SELECT1 select,
+ char* sense, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* sdim, lapack_complex_double* w,
+ lapack_complex_double* vs, lapack_int* ldvs, double* rconde,
+ double* rcondv, lapack_complex_double* work,
+ lapack_int* lwork, double* rwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_sgeev( char* jobvl, char* jobvr, lapack_int* n, float* a,
+ lapack_int* lda, float* wr, float* wi, float* vl,
+ lapack_int* ldvl, float* vr, lapack_int* ldvr, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dgeev( char* jobvl, char* jobvr, lapack_int* n, double* a,
+ lapack_int* lda, double* wr, double* wi, double* vl,
+ lapack_int* ldvl, double* vr, lapack_int* ldvr, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cgeev( char* jobvl, char* jobvr, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* w, lapack_complex_float* vl,
+ lapack_int* ldvl, lapack_complex_float* vr, lapack_int* ldvr,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int *info );
+void LAPACK_zgeev( char* jobvl, char* jobvr, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* w, lapack_complex_double* vl,
+ lapack_int* ldvl, lapack_complex_double* vr,
+ lapack_int* ldvr, lapack_complex_double* work,
+ lapack_int* lwork, double* rwork, lapack_int *info );
+void LAPACK_sgeevx( char* balanc, char* jobvl, char* jobvr, char* sense,
+ lapack_int* n, float* a, lapack_int* lda, float* wr,
+ float* wi, float* vl, lapack_int* ldvl, float* vr,
+ lapack_int* ldvr, lapack_int* ilo, lapack_int* ihi,
+ float* scale, float* abnrm, float* rconde, float* rcondv,
+ float* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_dgeevx( char* balanc, char* jobvl, char* jobvr, char* sense,
+ lapack_int* n, double* a, lapack_int* lda, double* wr,
+ double* wi, double* vl, lapack_int* ldvl, double* vr,
+ lapack_int* ldvr, lapack_int* ilo, lapack_int* ihi,
+ double* scale, double* abnrm, double* rconde,
+ double* rcondv, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_cgeevx( char* balanc, char* jobvl, char* jobvr, char* sense,
+ lapack_int* n, lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* w, lapack_complex_float* vl,
+ lapack_int* ldvl, lapack_complex_float* vr,
+ lapack_int* ldvr, lapack_int* ilo, lapack_int* ihi,
+ float* scale, float* abnrm, float* rconde, float* rcondv,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int *info );
+void LAPACK_zgeevx( char* balanc, char* jobvl, char* jobvr, char* sense,
+ lapack_int* n, lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* w, lapack_complex_double* vl,
+ lapack_int* ldvl, lapack_complex_double* vr,
+ lapack_int* ldvr, lapack_int* ilo, lapack_int* ihi,
+ double* scale, double* abnrm, double* rconde,
+ double* rcondv, lapack_complex_double* work,
+ lapack_int* lwork, double* rwork, lapack_int *info );
+void LAPACK_sgesvd( char* jobu, char* jobvt, lapack_int* m, lapack_int* n,
+ float* a, lapack_int* lda, float* s, float* u,
+ lapack_int* ldu, float* vt, lapack_int* ldvt, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_dgesvd( char* jobu, char* jobvt, lapack_int* m, lapack_int* n,
+ double* a, lapack_int* lda, double* s, double* u,
+ lapack_int* ldu, double* vt, lapack_int* ldvt, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cgesvd( char* jobu, char* jobvt, lapack_int* m, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda, float* s,
+ lapack_complex_float* u, lapack_int* ldu,
+ lapack_complex_float* vt, lapack_int* ldvt,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int *info );
+void LAPACK_zgesvd( char* jobu, char* jobvt, lapack_int* m, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda, double* s,
+ lapack_complex_double* u, lapack_int* ldu,
+ lapack_complex_double* vt, lapack_int* ldvt,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int *info );
+void LAPACK_sgesdd( char* jobz, lapack_int* m, lapack_int* n, float* a,
+ lapack_int* lda, float* s, float* u, lapack_int* ldu,
+ float* vt, lapack_int* ldvt, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_dgesdd( char* jobz, lapack_int* m, lapack_int* n, double* a,
+ lapack_int* lda, double* s, double* u, lapack_int* ldu,
+ double* vt, lapack_int* ldvt, double* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_int *info );
+void LAPACK_cgesdd( char* jobz, lapack_int* m, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda, float* s,
+ lapack_complex_float* u, lapack_int* ldu,
+ lapack_complex_float* vt, lapack_int* ldvt,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_zgesdd( char* jobz, lapack_int* m, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda, double* s,
+ lapack_complex_double* u, lapack_int* ldu,
+ lapack_complex_double* vt, lapack_int* ldvt,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int* iwork, lapack_int *info );
+void LAPACK_dgejsv( char* joba, char* jobu, char* jobv, char* jobr, char* jobt,
+ char* jobp, lapack_int* m, lapack_int* n, double* a,
+ lapack_int* lda, double* sva, double* u, lapack_int* ldu,
+ double* v, lapack_int* ldv, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_sgejsv( char* joba, char* jobu, char* jobv, char* jobr, char* jobt,
+ char* jobp, lapack_int* m, lapack_int* n, float* a,
+ lapack_int* lda, float* sva, float* u, lapack_int* ldu,
+ float* v, lapack_int* ldv, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_dgesvj( char* joba, char* jobu, char* jobv, lapack_int* m,
+ lapack_int* n, double* a, lapack_int* lda, double* sva,
+ lapack_int* mv, double* v, lapack_int* ldv, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sgesvj( char* joba, char* jobu, char* jobv, lapack_int* m,
+ lapack_int* n, float* a, lapack_int* lda, float* sva,
+ lapack_int* mv, float* v, lapack_int* ldv, float* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_sggsvd( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* n, lapack_int* p, lapack_int* k, lapack_int* l,
+ float* a, lapack_int* lda, float* b, lapack_int* ldb,
+ float* alpha, float* beta, float* u, lapack_int* ldu,
+ float* v, lapack_int* ldv, float* q, lapack_int* ldq,
+ float* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_dggsvd( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* n, lapack_int* p, lapack_int* k, lapack_int* l,
+ double* a, lapack_int* lda, double* b, lapack_int* ldb,
+ double* alpha, double* beta, double* u, lapack_int* ldu,
+ double* v, lapack_int* ldv, double* q, lapack_int* ldq,
+ double* work, lapack_int* iwork, lapack_int *info );
+void LAPACK_cggsvd( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* n, lapack_int* p, lapack_int* k, lapack_int* l,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb, float* alpha,
+ float* beta, lapack_complex_float* u, lapack_int* ldu,
+ lapack_complex_float* v, lapack_int* ldv,
+ lapack_complex_float* q, lapack_int* ldq,
+ lapack_complex_float* work, float* rwork, lapack_int* iwork,
+ lapack_int *info );
+void LAPACK_zggsvd( char* jobu, char* jobv, char* jobq, lapack_int* m,
+ lapack_int* n, lapack_int* p, lapack_int* k, lapack_int* l,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb, double* alpha,
+ double* beta, lapack_complex_double* u, lapack_int* ldu,
+ lapack_complex_double* v, lapack_int* ldv,
+ lapack_complex_double* q, lapack_int* ldq,
+ lapack_complex_double* work, double* rwork,
+ lapack_int* iwork, lapack_int *info );
+void LAPACK_ssygv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ float* a, lapack_int* lda, float* b, lapack_int* ldb,
+ float* w, float* work, lapack_int* lwork, lapack_int *info );
+void LAPACK_dsygv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ double* a, lapack_int* lda, double* b, lapack_int* ldb,
+ double* w, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_chegv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb, float* w,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int *info );
+void LAPACK_zhegv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb, double* w,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int *info );
+void LAPACK_ssygvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ float* a, lapack_int* lda, float* b, lapack_int* ldb,
+ float* w, float* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_dsygvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ double* a, lapack_int* lda, double* b, lapack_int* ldb,
+ double* w, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_chegvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb, float* w,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_int *info );
+void LAPACK_zhegvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb, double* w,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int* lrwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_ssygvx( lapack_int* itype, char* jobz, char* range, char* uplo,
+ lapack_int* n, float* a, lapack_int* lda, float* b,
+ lapack_int* ldb, float* vl, float* vu, lapack_int* il,
+ lapack_int* iu, float* abstol, lapack_int* m, float* w,
+ float* z, lapack_int* ldz, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* ifail, lapack_int *info );
+void LAPACK_dsygvx( lapack_int* itype, char* jobz, char* range, char* uplo,
+ lapack_int* n, double* a, lapack_int* lda, double* b,
+ lapack_int* ldb, double* vl, double* vu, lapack_int* il,
+ lapack_int* iu, double* abstol, lapack_int* m, double* w,
+ double* z, lapack_int* ldz, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* ifail, lapack_int *info );
+void LAPACK_chegvx( lapack_int* itype, char* jobz, char* range, char* uplo,
+ lapack_int* n, lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb, float* vl,
+ float* vu, lapack_int* il, lapack_int* iu, float* abstol,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int* ldz, lapack_complex_float* work,
+ lapack_int* lwork, float* rwork, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_zhegvx( lapack_int* itype, char* jobz, char* range, char* uplo,
+ lapack_int* n, lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb, double* vl,
+ double* vu, lapack_int* il, lapack_int* iu, double* abstol,
+ lapack_int* m, double* w, lapack_complex_double* z,
+ lapack_int* ldz, lapack_complex_double* work,
+ lapack_int* lwork, double* rwork, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_sspgv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ float* ap, float* bp, float* w, float* z, lapack_int* ldz,
+ float* work, lapack_int *info );
+void LAPACK_dspgv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ double* ap, double* bp, double* w, double* z,
+ lapack_int* ldz, double* work, lapack_int *info );
+void LAPACK_chpgv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_float* ap, lapack_complex_float* bp, float* w,
+ lapack_complex_float* z, lapack_int* ldz,
+ lapack_complex_float* work, float* rwork, lapack_int *info );
+void LAPACK_zhpgv( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_double* ap, lapack_complex_double* bp,
+ double* w, lapack_complex_double* z, lapack_int* ldz,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_sspgvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ float* ap, float* bp, float* w, float* z, lapack_int* ldz,
+ float* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_dspgvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ double* ap, double* bp, double* w, double* z,
+ lapack_int* ldz, double* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_int* liwork, lapack_int *info );
+void LAPACK_chpgvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_float* ap, lapack_complex_float* bp,
+ float* w, lapack_complex_float* z, lapack_int* ldz,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_int *info );
+void LAPACK_zhpgvd( lapack_int* itype, char* jobz, char* uplo, lapack_int* n,
+ lapack_complex_double* ap, lapack_complex_double* bp,
+ double* w, lapack_complex_double* z, lapack_int* ldz,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int* lrwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_sspgvx( lapack_int* itype, char* jobz, char* range, char* uplo,
+ lapack_int* n, float* ap, float* bp, float* vl, float* vu,
+ lapack_int* il, lapack_int* iu, float* abstol,
+ lapack_int* m, float* w, float* z, lapack_int* ldz,
+ float* work, lapack_int* iwork, lapack_int* ifail,
+ lapack_int *info );
+void LAPACK_dspgvx( lapack_int* itype, char* jobz, char* range, char* uplo,
+ lapack_int* n, double* ap, double* bp, double* vl,
+ double* vu, lapack_int* il, lapack_int* iu, double* abstol,
+ lapack_int* m, double* w, double* z, lapack_int* ldz,
+ double* work, lapack_int* iwork, lapack_int* ifail,
+ lapack_int *info );
+void LAPACK_chpgvx( lapack_int* itype, char* jobz, char* range, char* uplo,
+ lapack_int* n, lapack_complex_float* ap,
+ lapack_complex_float* bp, float* vl, float* vu,
+ lapack_int* il, lapack_int* iu, float* abstol,
+ lapack_int* m, float* w, lapack_complex_float* z,
+ lapack_int* ldz, lapack_complex_float* work, float* rwork,
+ lapack_int* iwork, lapack_int* ifail, lapack_int *info );
+void LAPACK_zhpgvx( lapack_int* itype, char* jobz, char* range, char* uplo,
+ lapack_int* n, lapack_complex_double* ap,
+ lapack_complex_double* bp, double* vl, double* vu,
+ lapack_int* il, lapack_int* iu, double* abstol,
+ lapack_int* m, double* w, lapack_complex_double* z,
+ lapack_int* ldz, lapack_complex_double* work, double* rwork,
+ lapack_int* iwork, lapack_int* ifail, lapack_int *info );
+void LAPACK_ssbgv( char* jobz, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, float* ab, lapack_int* ldab, float* bb,
+ lapack_int* ldbb, float* w, float* z, lapack_int* ldz,
+ float* work, lapack_int *info );
+void LAPACK_dsbgv( char* jobz, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, double* ab, lapack_int* ldab, double* bb,
+ lapack_int* ldbb, double* w, double* z, lapack_int* ldz,
+ double* work, lapack_int *info );
+void LAPACK_chbgv( char* jobz, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, lapack_complex_float* ab, lapack_int* ldab,
+ lapack_complex_float* bb, lapack_int* ldbb, float* w,
+ lapack_complex_float* z, lapack_int* ldz,
+ lapack_complex_float* work, float* rwork, lapack_int *info );
+void LAPACK_zhbgv( char* jobz, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, lapack_complex_double* ab, lapack_int* ldab,
+ lapack_complex_double* bb, lapack_int* ldbb, double* w,
+ lapack_complex_double* z, lapack_int* ldz,
+ lapack_complex_double* work, double* rwork,
+ lapack_int *info );
+void LAPACK_ssbgvd( char* jobz, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, float* ab, lapack_int* ldab, float* bb,
+ lapack_int* ldbb, float* w, float* z, lapack_int* ldz,
+ float* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_dsbgvd( char* jobz, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, double* ab, lapack_int* ldab, double* bb,
+ lapack_int* ldbb, double* w, double* z, lapack_int* ldz,
+ double* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_chbgvd( char* jobz, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, lapack_complex_float* ab, lapack_int* ldab,
+ lapack_complex_float* bb, lapack_int* ldbb, float* w,
+ lapack_complex_float* z, lapack_int* ldz,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork,
+ lapack_int *info );
+void LAPACK_zhbgvd( char* jobz, char* uplo, lapack_int* n, lapack_int* ka,
+ lapack_int* kb, lapack_complex_double* ab, lapack_int* ldab,
+ lapack_complex_double* bb, lapack_int* ldbb, double* w,
+ lapack_complex_double* z, lapack_int* ldz,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int* lrwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_int *info );
+void LAPACK_ssbgvx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_int* ka, lapack_int* kb, float* ab, lapack_int* ldab,
+ float* bb, lapack_int* ldbb, float* q, lapack_int* ldq,
+ float* vl, float* vu, lapack_int* il, lapack_int* iu,
+ float* abstol, lapack_int* m, float* w, float* z,
+ lapack_int* ldz, float* work, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_dsbgvx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_int* ka, lapack_int* kb, double* ab,
+ lapack_int* ldab, double* bb, lapack_int* ldbb, double* q,
+ lapack_int* ldq, double* vl, double* vu, lapack_int* il,
+ lapack_int* iu, double* abstol, lapack_int* m, double* w,
+ double* z, lapack_int* ldz, double* work, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_chbgvx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_int* ka, lapack_int* kb, lapack_complex_float* ab,
+ lapack_int* ldab, lapack_complex_float* bb,
+ lapack_int* ldbb, lapack_complex_float* q, lapack_int* ldq,
+ float* vl, float* vu, lapack_int* il, lapack_int* iu,
+ float* abstol, lapack_int* m, float* w,
+ lapack_complex_float* z, lapack_int* ldz,
+ lapack_complex_float* work, float* rwork, lapack_int* iwork,
+ lapack_int* ifail, lapack_int *info );
+void LAPACK_zhbgvx( char* jobz, char* range, char* uplo, lapack_int* n,
+ lapack_int* ka, lapack_int* kb, lapack_complex_double* ab,
+ lapack_int* ldab, lapack_complex_double* bb,
+ lapack_int* ldbb, lapack_complex_double* q, lapack_int* ldq,
+ double* vl, double* vu, lapack_int* il, lapack_int* iu,
+ double* abstol, lapack_int* m, double* w,
+ lapack_complex_double* z, lapack_int* ldz,
+ lapack_complex_double* work, double* rwork,
+ lapack_int* iwork, lapack_int* ifail, lapack_int *info );
+void LAPACK_sgges( char* jobvsl, char* jobvsr, char* sort,
+ LAPACK_S_SELECT3 selctg, lapack_int* n, float* a,
+ lapack_int* lda, float* b, lapack_int* ldb, lapack_int* sdim,
+ float* alphar, float* alphai, float* beta, float* vsl,
+ lapack_int* ldvsl, float* vsr, lapack_int* ldvsr,
+ float* work, lapack_int* lwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_dgges( char* jobvsl, char* jobvsr, char* sort,
+ LAPACK_D_SELECT3 selctg, lapack_int* n, double* a,
+ lapack_int* lda, double* b, lapack_int* ldb,
+ lapack_int* sdim, double* alphar, double* alphai,
+ double* beta, double* vsl, lapack_int* ldvsl, double* vsr,
+ lapack_int* ldvsr, double* work, lapack_int* lwork,
+ lapack_logical* bwork, lapack_int *info );
+void LAPACK_cgges( char* jobvsl, char* jobvsr, char* sort,
+ LAPACK_C_SELECT2 selctg, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb, lapack_int* sdim,
+ lapack_complex_float* alpha, lapack_complex_float* beta,
+ lapack_complex_float* vsl, lapack_int* ldvsl,
+ lapack_complex_float* vsr, lapack_int* ldvsr,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_logical* bwork, lapack_int *info );
+void LAPACK_zgges( char* jobvsl, char* jobvsr, char* sort,
+ LAPACK_Z_SELECT2 selctg, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb, lapack_int* sdim,
+ lapack_complex_double* alpha, lapack_complex_double* beta,
+ lapack_complex_double* vsl, lapack_int* ldvsl,
+ lapack_complex_double* vsr, lapack_int* ldvsr,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_logical* bwork, lapack_int *info );
+void LAPACK_sggesx( char* jobvsl, char* jobvsr, char* sort,
+ LAPACK_S_SELECT3 selctg, char* sense, lapack_int* n,
+ float* a, lapack_int* lda, float* b, lapack_int* ldb,
+ lapack_int* sdim, float* alphar, float* alphai, float* beta,
+ float* vsl, lapack_int* ldvsl, float* vsr,
+ lapack_int* ldvsr, float* rconde, float* rcondv,
+ float* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_dggesx( char* jobvsl, char* jobvsr, char* sort,
+ LAPACK_D_SELECT3 selctg, char* sense, lapack_int* n,
+ double* a, lapack_int* lda, double* b, lapack_int* ldb,
+ lapack_int* sdim, double* alphar, double* alphai,
+ double* beta, double* vsl, lapack_int* ldvsl, double* vsr,
+ lapack_int* ldvsr, double* rconde, double* rcondv,
+ double* work, lapack_int* lwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_cggesx( char* jobvsl, char* jobvsr, char* sort,
+ LAPACK_C_SELECT2 selctg, char* sense, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb, lapack_int* sdim,
+ lapack_complex_float* alpha, lapack_complex_float* beta,
+ lapack_complex_float* vsl, lapack_int* ldvsl,
+ lapack_complex_float* vsr, lapack_int* ldvsr, float* rconde,
+ float* rcondv, lapack_complex_float* work,
+ lapack_int* lwork, float* rwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_zggesx( char* jobvsl, char* jobvsr, char* sort,
+ LAPACK_Z_SELECT2 selctg, char* sense, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb, lapack_int* sdim,
+ lapack_complex_double* alpha, lapack_complex_double* beta,
+ lapack_complex_double* vsl, lapack_int* ldvsl,
+ lapack_complex_double* vsr, lapack_int* ldvsr,
+ double* rconde, double* rcondv, lapack_complex_double* work,
+ lapack_int* lwork, double* rwork, lapack_int* iwork,
+ lapack_int* liwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_sggev( char* jobvl, char* jobvr, lapack_int* n, float* a,
+ lapack_int* lda, float* b, lapack_int* ldb, float* alphar,
+ float* alphai, float* beta, float* vl, lapack_int* ldvl,
+ float* vr, lapack_int* ldvr, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dggev( char* jobvl, char* jobvr, lapack_int* n, double* a,
+ lapack_int* lda, double* b, lapack_int* ldb, double* alphar,
+ double* alphai, double* beta, double* vl, lapack_int* ldvl,
+ double* vr, lapack_int* ldvr, double* work,
+ lapack_int* lwork, lapack_int *info );
+void LAPACK_cggev( char* jobvl, char* jobvr, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* alpha, lapack_complex_float* beta,
+ lapack_complex_float* vl, lapack_int* ldvl,
+ lapack_complex_float* vr, lapack_int* ldvr,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int *info );
+void LAPACK_zggev( char* jobvl, char* jobvr, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* alpha, lapack_complex_double* beta,
+ lapack_complex_double* vl, lapack_int* ldvl,
+ lapack_complex_double* vr, lapack_int* ldvr,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int *info );
+void LAPACK_sggevx( char* balanc, char* jobvl, char* jobvr, char* sense,
+ lapack_int* n, float* a, lapack_int* lda, float* b,
+ lapack_int* ldb, float* alphar, float* alphai, float* beta,
+ float* vl, lapack_int* ldvl, float* vr, lapack_int* ldvr,
+ lapack_int* ilo, lapack_int* ihi, float* lscale,
+ float* rscale, float* abnrm, float* bbnrm, float* rconde,
+ float* rcondv, float* work, lapack_int* lwork,
+ lapack_int* iwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_dggevx( char* balanc, char* jobvl, char* jobvr, char* sense,
+ lapack_int* n, double* a, lapack_int* lda, double* b,
+ lapack_int* ldb, double* alphar, double* alphai,
+ double* beta, double* vl, lapack_int* ldvl, double* vr,
+ lapack_int* ldvr, lapack_int* ilo, lapack_int* ihi,
+ double* lscale, double* rscale, double* abnrm,
+ double* bbnrm, double* rconde, double* rcondv, double* work,
+ lapack_int* lwork, lapack_int* iwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_cggevx( char* balanc, char* jobvl, char* jobvr, char* sense,
+ lapack_int* n, lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* alpha, lapack_complex_float* beta,
+ lapack_complex_float* vl, lapack_int* ldvl,
+ lapack_complex_float* vr, lapack_int* ldvr, lapack_int* ilo,
+ lapack_int* ihi, float* lscale, float* rscale, float* abnrm,
+ float* bbnrm, float* rconde, float* rcondv,
+ lapack_complex_float* work, lapack_int* lwork, float* rwork,
+ lapack_int* iwork, lapack_logical* bwork,
+ lapack_int *info );
+void LAPACK_zggevx( char* balanc, char* jobvl, char* jobvr, char* sense,
+ lapack_int* n, lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* alpha, lapack_complex_double* beta,
+ lapack_complex_double* vl, lapack_int* ldvl,
+ lapack_complex_double* vr, lapack_int* ldvr,
+ lapack_int* ilo, lapack_int* ihi, double* lscale,
+ double* rscale, double* abnrm, double* bbnrm,
+ double* rconde, double* rcondv, lapack_complex_double* work,
+ lapack_int* lwork, double* rwork, lapack_int* iwork,
+ lapack_logical* bwork, lapack_int *info );
+void LAPACK_dsfrk( char* transr, char* uplo, char* trans, lapack_int* n,
+ lapack_int* k, double* alpha, const double* a,
+ lapack_int* lda, double* beta, double* c );
+void LAPACK_ssfrk( char* transr, char* uplo, char* trans, lapack_int* n,
+ lapack_int* k, float* alpha, const float* a, lapack_int* lda,
+ float* beta, float* c );
+void LAPACK_zhfrk( char* transr, char* uplo, char* trans, lapack_int* n,
+ lapack_int* k, double* alpha, const lapack_complex_double* a,
+ lapack_int* lda, double* beta, lapack_complex_double* c );
+void LAPACK_chfrk( char* transr, char* uplo, char* trans, lapack_int* n,
+ lapack_int* k, float* alpha, const lapack_complex_float* a,
+ lapack_int* lda, float* beta, lapack_complex_float* c );
+void LAPACK_dtfsm( char* transr, char* side, char* uplo, char* trans,
+ char* diag, lapack_int* m, lapack_int* n, double* alpha,
+ const double* a, double* b, lapack_int* ldb );
+void LAPACK_stfsm( char* transr, char* side, char* uplo, char* trans,
+ char* diag, lapack_int* m, lapack_int* n, float* alpha,
+ const float* a, float* b, lapack_int* ldb );
+void LAPACK_ztfsm( char* transr, char* side, char* uplo, char* trans,
+ char* diag, lapack_int* m, lapack_int* n,
+ lapack_complex_double* alpha, const lapack_complex_double* a,
+ lapack_complex_double* b, lapack_int* ldb );
+void LAPACK_ctfsm( char* transr, char* side, char* uplo, char* trans,
+ char* diag, lapack_int* m, lapack_int* n,
+ lapack_complex_float* alpha, const lapack_complex_float* a,
+ lapack_complex_float* b, lapack_int* ldb );
+void LAPACK_dtfttp( char* transr, char* uplo, lapack_int* n, const double* arf,
+ double* ap, lapack_int *info );
+void LAPACK_stfttp( char* transr, char* uplo, lapack_int* n, const float* arf,
+ float* ap, lapack_int *info );
+void LAPACK_ztfttp( char* transr, char* uplo, lapack_int* n,
+ const lapack_complex_double* arf, lapack_complex_double* ap,
+ lapack_int *info );
+void LAPACK_ctfttp( char* transr, char* uplo, lapack_int* n,
+ const lapack_complex_float* arf, lapack_complex_float* ap,
+ lapack_int *info );
+void LAPACK_dtfttr( char* transr, char* uplo, lapack_int* n, const double* arf,
+ double* a, lapack_int* lda, lapack_int *info );
+void LAPACK_stfttr( char* transr, char* uplo, lapack_int* n, const float* arf,
+ float* a, lapack_int* lda, lapack_int *info );
+void LAPACK_ztfttr( char* transr, char* uplo, lapack_int* n,
+ const lapack_complex_double* arf, lapack_complex_double* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_ctfttr( char* transr, char* uplo, lapack_int* n,
+ const lapack_complex_float* arf, lapack_complex_float* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_dtpttf( char* transr, char* uplo, lapack_int* n, const double* ap,
+ double* arf, lapack_int *info );
+void LAPACK_stpttf( char* transr, char* uplo, lapack_int* n, const float* ap,
+ float* arf, lapack_int *info );
+void LAPACK_ztpttf( char* transr, char* uplo, lapack_int* n,
+ const lapack_complex_double* ap, lapack_complex_double* arf,
+ lapack_int *info );
+void LAPACK_ctpttf( char* transr, char* uplo, lapack_int* n,
+ const lapack_complex_float* ap, lapack_complex_float* arf,
+ lapack_int *info );
+void LAPACK_dtpttr( char* uplo, lapack_int* n, const double* ap, double* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_stpttr( char* uplo, lapack_int* n, const float* ap, float* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_ztpttr( char* uplo, lapack_int* n, const lapack_complex_double* ap,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_ctpttr( char* uplo, lapack_int* n, const lapack_complex_float* ap,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_dtrttf( char* transr, char* uplo, lapack_int* n, const double* a,
+ lapack_int* lda, double* arf, lapack_int *info );
+void LAPACK_strttf( char* transr, char* uplo, lapack_int* n, const float* a,
+ lapack_int* lda, float* arf, lapack_int *info );
+void LAPACK_ztrttf( char* transr, char* uplo, lapack_int* n,
+ const lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* arf, lapack_int *info );
+void LAPACK_ctrttf( char* transr, char* uplo, lapack_int* n,
+ const lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* arf, lapack_int *info );
+void LAPACK_dtrttp( char* uplo, lapack_int* n, const double* a, lapack_int* lda,
+ double* ap, lapack_int *info );
+void LAPACK_strttp( char* uplo, lapack_int* n, const float* a, lapack_int* lda,
+ float* ap, lapack_int *info );
+void LAPACK_ztrttp( char* uplo, lapack_int* n, const lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* ap,
+ lapack_int *info );
+void LAPACK_ctrttp( char* uplo, lapack_int* n, const lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* ap,
+ lapack_int *info );
+void LAPACK_sgeqrfp( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* tau, float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_dgeqrfp( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* tau, double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_cgeqrfp( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_zgeqrfp( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int* lwork,
+ lapack_int *info );
+void LAPACK_clacgv( lapack_int* n, lapack_complex_float* x, lapack_int* incx );
+void LAPACK_zlacgv( lapack_int* n, lapack_complex_double* x, lapack_int* incx );
+void LAPACK_slarnv( lapack_int* idist, lapack_int* iseed, lapack_int* n,
+ float* x );
+void LAPACK_dlarnv( lapack_int* idist, lapack_int* iseed, lapack_int* n,
+ double* x );
+void LAPACK_clarnv( lapack_int* idist, lapack_int* iseed, lapack_int* n,
+ lapack_complex_float* x );
+void LAPACK_zlarnv( lapack_int* idist, lapack_int* iseed, lapack_int* n,
+ lapack_complex_double* x );
+void LAPACK_sgeqr2( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* tau, float* work, lapack_int *info );
+void LAPACK_dgeqr2( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* tau, double* work, lapack_int *info );
+void LAPACK_cgeqr2( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zgeqr2( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_slacpy( char* uplo, lapack_int* m, lapack_int* n, const float* a,
+ lapack_int* lda, float* b, lapack_int* ldb );
+void LAPACK_dlacpy( char* uplo, lapack_int* m, lapack_int* n, const double* a,
+ lapack_int* lda, double* b, lapack_int* ldb );
+void LAPACK_clacpy( char* uplo, lapack_int* m, lapack_int* n,
+ const lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb );
+void LAPACK_zlacpy( char* uplo, lapack_int* m, lapack_int* n,
+ const lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb );
+void LAPACK_sgetf2( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_dgetf2( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ lapack_int* ipiv, lapack_int *info );
+void LAPACK_cgetf2( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int* ipiv, lapack_int *info );
+void LAPACK_zgetf2( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* ipiv, lapack_int *info );
+void LAPACK_slaswp( lapack_int* n, float* a, lapack_int* lda, lapack_int* k1,
+ lapack_int* k2, const lapack_int* ipiv, lapack_int* incx );
+void LAPACK_dlaswp( lapack_int* n, double* a, lapack_int* lda, lapack_int* k1,
+ lapack_int* k2, const lapack_int* ipiv, lapack_int* incx );
+void LAPACK_claswp( lapack_int* n, lapack_complex_float* a, lapack_int* lda,
+ lapack_int* k1, lapack_int* k2, const lapack_int* ipiv,
+ lapack_int* incx );
+void LAPACK_zlaswp( lapack_int* n, lapack_complex_double* a, lapack_int* lda,
+ lapack_int* k1, lapack_int* k2, const lapack_int* ipiv,
+ lapack_int* incx );
+float LAPACK_slange( char* norm, lapack_int* m, lapack_int* n, const float* a,
+ lapack_int* lda, float* work );
+double LAPACK_dlange( char* norm, lapack_int* m, lapack_int* n, const double* a,
+ lapack_int* lda, double* work );
+float LAPACK_clange( char* norm, lapack_int* m, lapack_int* n,
+ const lapack_complex_float* a, lapack_int* lda, float* work );
+double LAPACK_zlange( char* norm, lapack_int* m, lapack_int* n,
+ const lapack_complex_double* a, lapack_int* lda, double* work );
+float LAPACK_clanhe( char* norm, char* uplo, lapack_int* n,
+ const lapack_complex_float* a, lapack_int* lda, float* work );
+double LAPACK_zlanhe( char* norm, char* uplo, lapack_int* n,
+ const lapack_complex_double* a, lapack_int* lda, double* work );
+float LAPACK_slansy( char* norm, char* uplo, lapack_int* n, const float* a,
+ lapack_int* lda, float* work );
+double LAPACK_dlansy( char* norm, char* uplo, lapack_int* n, const double* a,
+ lapack_int* lda, double* work );
+float LAPACK_clansy( char* norm, char* uplo, lapack_int* n,
+ const lapack_complex_float* a, lapack_int* lda, float* work );
+double LAPACK_zlansy( char* norm, char* uplo, lapack_int* n,
+ const lapack_complex_double* a, lapack_int* lda, double* work );
+float LAPACK_slantr( char* norm, char* uplo, char* diag, lapack_int* m,
+ lapack_int* n, const float* a, lapack_int* lda, float* work );
+double LAPACK_dlantr( char* norm, char* uplo, char* diag, lapack_int* m,
+ lapack_int* n, const double* a, lapack_int* lda, double* work );
+float LAPACK_clantr( char* norm, char* uplo, char* diag, lapack_int* m,
+ lapack_int* n, const lapack_complex_float* a, lapack_int* lda,
+ float* work );
+double LAPACK_zlantr( char* norm, char* uplo, char* diag, lapack_int* m,
+ lapack_int* n, const lapack_complex_double* a, lapack_int* lda,
+ double* work );
+float LAPACK_slamch( char* cmach );
+double LAPACK_dlamch( char* cmach );
+void LAPACK_sgelq2( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* tau, float* work, lapack_int *info );
+void LAPACK_dgelq2( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* tau, double* work, lapack_int *info );
+void LAPACK_cgelq2( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* tau,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zgelq2( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* tau,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_slarfb( char* side, char* trans, char* direct, char* storev,
+ lapack_int* m, lapack_int* n, lapack_int* k, const float* v,
+ lapack_int* ldv, const float* t, lapack_int* ldt, float* c,
+ lapack_int* ldc, float* work, lapack_int* ldwork );
+void LAPACK_dlarfb( char* side, char* trans, char* direct, char* storev,
+ lapack_int* m, lapack_int* n, lapack_int* k,
+ const double* v, lapack_int* ldv, const double* t,
+ lapack_int* ldt, double* c, lapack_int* ldc, double* work,
+ lapack_int* ldwork );
+void LAPACK_clarfb( char* side, char* trans, char* direct, char* storev,
+ lapack_int* m, lapack_int* n, lapack_int* k,
+ const lapack_complex_float* v, lapack_int* ldv,
+ const lapack_complex_float* t, lapack_int* ldt,
+ lapack_complex_float* c, lapack_int* ldc,
+ lapack_complex_float* work, lapack_int* ldwork );
+void LAPACK_zlarfb( char* side, char* trans, char* direct, char* storev,
+ lapack_int* m, lapack_int* n, lapack_int* k,
+ const lapack_complex_double* v, lapack_int* ldv,
+ const lapack_complex_double* t, lapack_int* ldt,
+ lapack_complex_double* c, lapack_int* ldc,
+ lapack_complex_double* work, lapack_int* ldwork );
+void LAPACK_slarfg( lapack_int* n, float* alpha, float* x, lapack_int* incx,
+ float* tau );
+void LAPACK_dlarfg( lapack_int* n, double* alpha, double* x, lapack_int* incx,
+ double* tau );
+void LAPACK_clarfg( lapack_int* n, lapack_complex_float* alpha,
+ lapack_complex_float* x, lapack_int* incx,
+ lapack_complex_float* tau );
+void LAPACK_zlarfg( lapack_int* n, lapack_complex_double* alpha,
+ lapack_complex_double* x, lapack_int* incx,
+ lapack_complex_double* tau );
+void LAPACK_slarft( char* direct, char* storev, lapack_int* n, lapack_int* k,
+ const float* v, lapack_int* ldv, const float* tau, float* t,
+ lapack_int* ldt );
+void LAPACK_dlarft( char* direct, char* storev, lapack_int* n, lapack_int* k,
+ const double* v, lapack_int* ldv, const double* tau,
+ double* t, lapack_int* ldt );
+void LAPACK_clarft( char* direct, char* storev, lapack_int* n, lapack_int* k,
+ const lapack_complex_float* v, lapack_int* ldv,
+ const lapack_complex_float* tau, lapack_complex_float* t,
+ lapack_int* ldt );
+void LAPACK_zlarft( char* direct, char* storev, lapack_int* n, lapack_int* k,
+ const lapack_complex_double* v, lapack_int* ldv,
+ const lapack_complex_double* tau, lapack_complex_double* t,
+ lapack_int* ldt );
+void LAPACK_slarfx( char* side, lapack_int* m, lapack_int* n, const float* v,
+ float* tau, float* c, lapack_int* ldc, float* work );
+void LAPACK_dlarfx( char* side, lapack_int* m, lapack_int* n, const double* v,
+ double* tau, double* c, lapack_int* ldc, double* work );
+void LAPACK_clarfx( char* side, lapack_int* m, lapack_int* n,
+ const lapack_complex_float* v, lapack_complex_float* tau,
+ lapack_complex_float* c, lapack_int* ldc,
+ lapack_complex_float* work );
+void LAPACK_zlarfx( char* side, lapack_int* m, lapack_int* n,
+ const lapack_complex_double* v, lapack_complex_double* tau,
+ lapack_complex_double* c, lapack_int* ldc,
+ lapack_complex_double* work );
+void LAPACK_slatms( lapack_int* m, lapack_int* n, char* dist, lapack_int* iseed,
+ char* sym, float* d, lapack_int* mode, float* cond,
+ float* dmax, lapack_int* kl, lapack_int* ku, char* pack,
+ float* a, lapack_int* lda, float* work, lapack_int *info );
+void LAPACK_dlatms( lapack_int* m, lapack_int* n, char* dist, lapack_int* iseed,
+ char* sym, double* d, lapack_int* mode, double* cond,
+ double* dmax, lapack_int* kl, lapack_int* ku, char* pack,
+ double* a, lapack_int* lda, double* work,
+ lapack_int *info );
+void LAPACK_clatms( lapack_int* m, lapack_int* n, char* dist, lapack_int* iseed,
+ char* sym, float* d, lapack_int* mode, float* cond,
+ float* dmax, lapack_int* kl, lapack_int* ku, char* pack,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zlatms( lapack_int* m, lapack_int* n, char* dist, lapack_int* iseed,
+ char* sym, double* d, lapack_int* mode, double* cond,
+ double* dmax, lapack_int* kl, lapack_int* ku, char* pack,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_slag2d( lapack_int* m, lapack_int* n, const float* sa,
+ lapack_int* ldsa, double* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_dlag2s( lapack_int* m, lapack_int* n, const double* a,
+ lapack_int* lda, float* sa, lapack_int* ldsa,
+ lapack_int *info );
+void LAPACK_clag2z( lapack_int* m, lapack_int* n,
+ const lapack_complex_float* sa, lapack_int* ldsa,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_zlag2c( lapack_int* m, lapack_int* n,
+ const lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_float* sa, lapack_int* ldsa,
+ lapack_int *info );
+void LAPACK_slauum( char* uplo, lapack_int* n, float* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_dlauum( char* uplo, lapack_int* n, double* a, lapack_int* lda,
+ lapack_int *info );
+void LAPACK_clauum( char* uplo, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_zlauum( char* uplo, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_int *info );
+void LAPACK_slagge( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const float* d, float* a, lapack_int* lda,
+ lapack_int* iseed, float* work, lapack_int *info );
+void LAPACK_dlagge( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const double* d, double* a, lapack_int* lda,
+ lapack_int* iseed, double* work, lapack_int *info );
+void LAPACK_clagge( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const float* d, lapack_complex_float* a,
+ lapack_int* lda, lapack_int* iseed,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zlagge( lapack_int* m, lapack_int* n, lapack_int* kl,
+ lapack_int* ku, const double* d, lapack_complex_double* a,
+ lapack_int* lda, lapack_int* iseed,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_slaset( char* uplo, lapack_int* m, lapack_int* n, float* alpha,
+ float* beta, float* a, lapack_int* lda );
+void LAPACK_dlaset( char* uplo, lapack_int* m, lapack_int* n, double* alpha,
+ double* beta, double* a, lapack_int* lda );
+void LAPACK_claset( char* uplo, lapack_int* m, lapack_int* n,
+ lapack_complex_float* alpha, lapack_complex_float* beta,
+ lapack_complex_float* a, lapack_int* lda );
+void LAPACK_zlaset( char* uplo, lapack_int* m, lapack_int* n,
+ lapack_complex_double* alpha, lapack_complex_double* beta,
+ lapack_complex_double* a, lapack_int* lda );
+void LAPACK_slasrt( char* id, lapack_int* n, float* d, lapack_int *info );
+void LAPACK_dlasrt( char* id, lapack_int* n, double* d, lapack_int *info );
+void LAPACK_claghe( lapack_int* n, lapack_int* k, const float* d,
+ lapack_complex_float* a, lapack_int* lda, lapack_int* iseed,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zlaghe( lapack_int* n, lapack_int* k, const double* d,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_int* iseed, lapack_complex_double* work,
+ lapack_int *info );
+void LAPACK_slagsy( lapack_int* n, lapack_int* k, const float* d, float* a,
+ lapack_int* lda, lapack_int* iseed, float* work,
+ lapack_int *info );
+void LAPACK_dlagsy( lapack_int* n, lapack_int* k, const double* d, double* a,
+ lapack_int* lda, lapack_int* iseed, double* work,
+ lapack_int *info );
+void LAPACK_clagsy( lapack_int* n, lapack_int* k, const float* d,
+ lapack_complex_float* a, lapack_int* lda, lapack_int* iseed,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zlagsy( lapack_int* n, lapack_int* k, const double* d,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_int* iseed, lapack_complex_double* work,
+ lapack_int *info );
+void LAPACK_slapmr( lapack_logical* forwrd, lapack_int* m, lapack_int* n,
+ float* x, lapack_int* ldx, lapack_int* k );
+void LAPACK_dlapmr( lapack_logical* forwrd, lapack_int* m, lapack_int* n,
+ double* x, lapack_int* ldx, lapack_int* k );
+void LAPACK_clapmr( lapack_logical* forwrd, lapack_int* m, lapack_int* n,
+ lapack_complex_float* x, lapack_int* ldx, lapack_int* k );
+void LAPACK_zlapmr( lapack_logical* forwrd, lapack_int* m, lapack_int* n,
+ lapack_complex_double* x, lapack_int* ldx, lapack_int* k );
+float LAPACK_slapy2( float* x, float* y );
+double LAPACK_dlapy2( double* x, double* y );
+float LAPACK_slapy3( float* x, float* y, float* z );
+double LAPACK_dlapy3( double* x, double* y, double* z );
+void LAPACK_slartgp( float* f, float* g, float* cs, float* sn, float* r );
+void LAPACK_dlartgp( double* f, double* g, double* cs, double* sn, double* r );
+void LAPACK_slartgs( float* x, float* y, float* sigma, float* cs, float* sn );
+void LAPACK_dlartgs( double* x, double* y, double* sigma, double* cs,
+ double* sn );
+// LAPACK 3.3.0
+void LAPACK_cbbcsd( char* jobu1, char* jobu2,
+ char* jobv1t, char* jobv2t, char* trans,
+ lapack_int* m, lapack_int* p, lapack_int* q,
+ float* theta, float* phi,
+ lapack_complex_float* u1, lapack_int* ldu1,
+ lapack_complex_float* u2, lapack_int* ldu2,
+ lapack_complex_float* v1t, lapack_int* ldv1t,
+ lapack_complex_float* v2t, lapack_int* ldv2t,
+ float* b11d, float* b11e, float* b12d,
+ float* b12e, float* b21d, float* b21e,
+ float* b22d, float* b22e, float* rwork,
+ lapack_int* lrwork , lapack_int *info );
+void LAPACK_cheswapr( char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* i1,
+ lapack_int* i2 );
+void LAPACK_chetri2( char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int* lwork , lapack_int *info );
+void LAPACK_chetri2x( char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int* nb , lapack_int *info );
+void LAPACK_chetrs2( char* uplo, lapack_int* n,
+ lapack_int* nrhs, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* work , lapack_int *info );
+void LAPACK_csyconv( char* uplo, char* way,
+ lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, const lapack_int* ipiv,
+ lapack_complex_float* work , lapack_int *info );
+void LAPACK_csyswapr( char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* i1,
+ lapack_int* i2 );
+void LAPACK_csytri2( char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int* lwork , lapack_int *info );
+void LAPACK_csytri2x( char* uplo, lapack_int* n,
+ lapack_complex_float* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int* nb , lapack_int *info );
+void LAPACK_csytrs2( char* uplo, lapack_int* n,
+ lapack_int* nrhs, const lapack_complex_float* a,
+ lapack_int* lda, const lapack_int* ipiv,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* work , lapack_int *info );
+void LAPACK_cunbdb( char* trans, char* signs,
+ lapack_int* m, lapack_int* p, lapack_int* q,
+ lapack_complex_float* x11, lapack_int* ldx11,
+ lapack_complex_float* x12, lapack_int* ldx12,
+ lapack_complex_float* x21, lapack_int* ldx21,
+ lapack_complex_float* x22, lapack_int* ldx22,
+ float* theta, float* phi,
+ lapack_complex_float* taup1,
+ lapack_complex_float* taup2,
+ lapack_complex_float* tauq1,
+ lapack_complex_float* tauq2,
+ lapack_complex_float* work, lapack_int* lwork , lapack_int *info );
+void LAPACK_cuncsd( char* jobu1, char* jobu2,
+ char* jobv1t, char* jobv2t, char* trans,
+ char* signs, lapack_int* m, lapack_int* p,
+ lapack_int* q, lapack_complex_float* x11,
+ lapack_int* ldx11, lapack_complex_float* x12,
+ lapack_int* ldx12, lapack_complex_float* x21,
+ lapack_int* ldx21, lapack_complex_float* x22,
+ lapack_int* ldx22, float* theta,
+ lapack_complex_float* u1, lapack_int* ldu1,
+ lapack_complex_float* u2, lapack_int* ldu2,
+ lapack_complex_float* v1t, lapack_int* ldv1t,
+ lapack_complex_float* v2t, lapack_int* ldv2t,
+ lapack_complex_float* work, lapack_int* lwork,
+ float* rwork, lapack_int* lrwork,
+ lapack_int* iwork , lapack_int *info );
+void LAPACK_dbbcsd( char* jobu1, char* jobu2,
+ char* jobv1t, char* jobv2t, char* trans,
+ lapack_int* m, lapack_int* p, lapack_int* q,
+ double* theta, double* phi, double* u1,
+ lapack_int* ldu1, double* u2, lapack_int* ldu2,
+ double* v1t, lapack_int* ldv1t, double* v2t,
+ lapack_int* ldv2t, double* b11d, double* b11e,
+ double* b12d, double* b12e, double* b21d,
+ double* b21e, double* b22d, double* b22e,
+ double* work, lapack_int* lwork , lapack_int *info );
+void LAPACK_dorbdb( char* trans, char* signs,
+ lapack_int* m, lapack_int* p, lapack_int* q,
+ double* x11, lapack_int* ldx11, double* x12,
+ lapack_int* ldx12, double* x21, lapack_int* ldx21,
+ double* x22, lapack_int* ldx22, double* theta,
+ double* phi, double* taup1, double* taup2,
+ double* tauq1, double* tauq2, double* work,
+ lapack_int* lwork , lapack_int *info );
+void LAPACK_dorcsd( char* jobu1, char* jobu2,
+ char* jobv1t, char* jobv2t, char* trans,
+ char* signs, lapack_int* m, lapack_int* p,
+ lapack_int* q, double* x11, lapack_int* ldx11,
+ double* x12, lapack_int* ldx12, double* x21,
+ lapack_int* ldx21, double* x22, lapack_int* ldx22,
+ double* theta, double* u1, lapack_int* ldu1,
+ double* u2, lapack_int* ldu2, double* v1t,
+ lapack_int* ldv1t, double* v2t, lapack_int* ldv2t,
+ double* work, lapack_int* lwork,
+ lapack_int* iwork , lapack_int *info );
+void LAPACK_dsyconv( char* uplo, char* way,
+ lapack_int* n, double* a, lapack_int* lda,
+ const lapack_int* ipiv, double* work , lapack_int *info );
+void LAPACK_dsyswapr( char* uplo, lapack_int* n,
+ double* a, lapack_int* i1, lapack_int* i2 );
+void LAPACK_dsytri2( char* uplo, lapack_int* n,
+ double* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int* lwork , lapack_int *info );
+void LAPACK_dsytri2x( char* uplo, lapack_int* n,
+ double* a, lapack_int* lda,
+ const lapack_int* ipiv, double* work,
+ lapack_int* nb , lapack_int *info );
+void LAPACK_dsytrs2( char* uplo, lapack_int* n,
+ lapack_int* nrhs, const double* a,
+ lapack_int* lda, const lapack_int* ipiv,
+ double* b, lapack_int* ldb, double* work , lapack_int *info );
+void LAPACK_sbbcsd( char* jobu1, char* jobu2,
+ char* jobv1t, char* jobv2t, char* trans,
+ lapack_int* m, lapack_int* p, lapack_int* q,
+ float* theta, float* phi, float* u1,
+ lapack_int* ldu1, float* u2, lapack_int* ldu2,
+ float* v1t, lapack_int* ldv1t, float* v2t,
+ lapack_int* ldv2t, float* b11d, float* b11e,
+ float* b12d, float* b12e, float* b21d,
+ float* b21e, float* b22d, float* b22e,
+ float* work, lapack_int* lwork , lapack_int *info );
+void LAPACK_sorbdb( char* trans, char* signs,
+ lapack_int* m, lapack_int* p, lapack_int* q,
+ float* x11, lapack_int* ldx11, float* x12,
+ lapack_int* ldx12, float* x21, lapack_int* ldx21,
+ float* x22, lapack_int* ldx22, float* theta,
+ float* phi, float* taup1, float* taup2,
+ float* tauq1, float* tauq2, float* work,
+ lapack_int* lwork , lapack_int *info );
+void LAPACK_sorcsd( char* jobu1, char* jobu2,
+ char* jobv1t, char* jobv2t, char* trans,
+ char* signs, lapack_int* m, lapack_int* p,
+ lapack_int* q, float* x11, lapack_int* ldx11,
+ float* x12, lapack_int* ldx12, float* x21,
+ lapack_int* ldx21, float* x22, lapack_int* ldx22,
+ float* theta, float* u1, lapack_int* ldu1,
+ float* u2, lapack_int* ldu2, float* v1t,
+ lapack_int* ldv1t, float* v2t, lapack_int* ldv2t,
+ float* work, lapack_int* lwork,
+ lapack_int* iwork , lapack_int *info );
+void LAPACK_ssyconv( char* uplo, char* way,
+ lapack_int* n, float* a, lapack_int* lda,
+ const lapack_int* ipiv, float* work , lapack_int *info );
+void LAPACK_ssyswapr( char* uplo, lapack_int* n,
+ float* a, lapack_int* i1, lapack_int* i2 );
+void LAPACK_ssytri2( char* uplo, lapack_int* n,
+ float* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_float* work, lapack_int* lwork , lapack_int *info );
+void LAPACK_ssytri2x( char* uplo, lapack_int* n,
+ float* a, lapack_int* lda,
+ const lapack_int* ipiv, float* work,
+ lapack_int* nb , lapack_int *info );
+void LAPACK_ssytrs2( char* uplo, lapack_int* n,
+ lapack_int* nrhs, const float* a,
+ lapack_int* lda, const lapack_int* ipiv,
+ float* b, lapack_int* ldb, float* work , lapack_int *info );
+void LAPACK_zbbcsd( char* jobu1, char* jobu2,
+ char* jobv1t, char* jobv2t, char* trans,
+ lapack_int* m, lapack_int* p, lapack_int* q,
+ double* theta, double* phi,
+ lapack_complex_double* u1, lapack_int* ldu1,
+ lapack_complex_double* u2, lapack_int* ldu2,
+ lapack_complex_double* v1t, lapack_int* ldv1t,
+ lapack_complex_double* v2t, lapack_int* ldv2t,
+ double* b11d, double* b11e, double* b12d,
+ double* b12e, double* b21d, double* b21e,
+ double* b22d, double* b22e, double* rwork,
+ lapack_int* lrwork , lapack_int *info );
+void LAPACK_zheswapr( char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* i1,
+ lapack_int* i2 );
+void LAPACK_zhetri2( char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int* lwork , lapack_int *info );
+void LAPACK_zhetri2x( char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int* nb , lapack_int *info );
+void LAPACK_zhetrs2( char* uplo, lapack_int* n,
+ lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* work , lapack_int *info );
+void LAPACK_zsyconv( char* uplo, char* way,
+ lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, const lapack_int* ipiv,
+ lapack_complex_double* work , lapack_int *info );
+void LAPACK_zsyswapr( char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* i1,
+ lapack_int* i2 );
+void LAPACK_zsytri2( char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int* lwork , lapack_int *info );
+void LAPACK_zsytri2x( char* uplo, lapack_int* n,
+ lapack_complex_double* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* work, lapack_int* nb , lapack_int *info );
+void LAPACK_zsytrs2( char* uplo, lapack_int* n,
+ lapack_int* nrhs,
+ const lapack_complex_double* a, lapack_int* lda,
+ const lapack_int* ipiv,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* work , lapack_int *info );
+void LAPACK_zunbdb( char* trans, char* signs,
+ lapack_int* m, lapack_int* p, lapack_int* q,
+ lapack_complex_double* x11, lapack_int* ldx11,
+ lapack_complex_double* x12, lapack_int* ldx12,
+ lapack_complex_double* x21, lapack_int* ldx21,
+ lapack_complex_double* x22, lapack_int* ldx22,
+ double* theta, double* phi,
+ lapack_complex_double* taup1,
+ lapack_complex_double* taup2,
+ lapack_complex_double* tauq1,
+ lapack_complex_double* tauq2,
+ lapack_complex_double* work, lapack_int* lwork , lapack_int *info );
+void LAPACK_zuncsd( char* jobu1, char* jobu2,
+ char* jobv1t, char* jobv2t, char* trans,
+ char* signs, lapack_int* m, lapack_int* p,
+ lapack_int* q, lapack_complex_double* x11,
+ lapack_int* ldx11, lapack_complex_double* x12,
+ lapack_int* ldx12, lapack_complex_double* x21,
+ lapack_int* ldx21, lapack_complex_double* x22,
+ lapack_int* ldx22, double* theta,
+ lapack_complex_double* u1, lapack_int* ldu1,
+ lapack_complex_double* u2, lapack_int* ldu2,
+ lapack_complex_double* v1t, lapack_int* ldv1t,
+ lapack_complex_double* v2t, lapack_int* ldv2t,
+ lapack_complex_double* work, lapack_int* lwork,
+ double* rwork, lapack_int* lrwork,
+ lapack_int* iwork , lapack_int *info );
+// LAPACK 3.4.0
+void LAPACK_sgemqrt( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* nb, const float* v,
+ lapack_int* ldv, const float* t, lapack_int* ldt, float* c,
+ lapack_int* ldc, float* work, lapack_int *info );
+void LAPACK_dgemqrt( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* nb, const double* v,
+ lapack_int* ldv, const double* t, lapack_int* ldt,
+ double* c, lapack_int* ldc, double* work,
+ lapack_int *info );
+void LAPACK_cgemqrt( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* nb,
+ const lapack_complex_float* v, lapack_int* ldv,
+ const lapack_complex_float* t, lapack_int* ldt,
+ lapack_complex_float* c, lapack_int* ldc,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zgemqrt( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* nb,
+ const lapack_complex_double* v, lapack_int* ldv,
+ const lapack_complex_double* t, lapack_int* ldt,
+ lapack_complex_double* c, lapack_int* ldc,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_sgeqrt( lapack_int* m, lapack_int* n, lapack_int* nb, float* a,
+ lapack_int* lda, float* t, lapack_int* ldt, float* work,
+ lapack_int *info );
+void LAPACK_dgeqrt( lapack_int* m, lapack_int* n, lapack_int* nb, double* a,
+ lapack_int* lda, double* t, lapack_int* ldt, double* work,
+ lapack_int *info );
+void LAPACK_cgeqrt( lapack_int* m, lapack_int* n, lapack_int* nb,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* t, lapack_int* ldt,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_zgeqrt( lapack_int* m, lapack_int* n, lapack_int* nb,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* t, lapack_int* ldt,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_sgeqrt2( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* t, lapack_int* ldt, lapack_int *info );
+void LAPACK_dgeqrt2( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* t, lapack_int* ldt, lapack_int *info );
+void LAPACK_cgeqrt2( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* t, lapack_int* ldt,
+ lapack_int *info );
+void LAPACK_zgeqrt2( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* t, lapack_int* ldt,
+ lapack_int *info );
+void LAPACK_sgeqrt3( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* t, lapack_int* ldt, lapack_int *info );
+void LAPACK_dgeqrt3( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* t, lapack_int* ldt, lapack_int *info );
+void LAPACK_cgeqrt3( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* t, lapack_int* ldt,
+ lapack_int *info );
+void LAPACK_zgeqrt3( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* t, lapack_int* ldt,
+ lapack_int *info );
+void LAPACK_stpmqrt( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* l, lapack_int* nb,
+ const float* v, lapack_int* ldv, const float* t,
+ lapack_int* ldt, float* a, lapack_int* lda, float* b,
+ lapack_int* ldb, float* work, lapack_int *info );
+void LAPACK_dtpmqrt( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* l, lapack_int* nb,
+ const double* v, lapack_int* ldv, const double* t,
+ lapack_int* ldt, double* a, lapack_int* lda, double* b,
+ lapack_int* ldb, double* work, lapack_int *info );
+void LAPACK_ctpmqrt( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* l, lapack_int* nb,
+ const lapack_complex_float* v, lapack_int* ldv,
+ const lapack_complex_float* t, lapack_int* ldt,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_ztpmqrt( char* side, char* trans, lapack_int* m, lapack_int* n,
+ lapack_int* k, lapack_int* l, lapack_int* nb,
+ const lapack_complex_double* v, lapack_int* ldv,
+ const lapack_complex_double* t, lapack_int* ldt,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_dtpqrt( lapack_int* m, lapack_int* n, lapack_int* l, lapack_int* nb,
+ double* a, lapack_int* lda, double* b, lapack_int* ldb,
+ double* t, lapack_int* ldt, double* work,
+ lapack_int *info );
+void LAPACK_ctpqrt( lapack_int* m, lapack_int* n, lapack_int* l, lapack_int* nb,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* t, lapack_complex_float* b,
+ lapack_int* ldb, lapack_int* ldt,
+ lapack_complex_float* work, lapack_int *info );
+void LAPACK_ztpqrt( lapack_int* m, lapack_int* n, lapack_int* l, lapack_int* nb,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* t, lapack_int* ldt,
+ lapack_complex_double* work, lapack_int *info );
+void LAPACK_stpqrt2( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
+ float* b, lapack_int* ldb, float* t, lapack_int* ldt,
+ lapack_int *info );
+void LAPACK_dtpqrt2( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
+ double* b, lapack_int* ldb, double* t, lapack_int* ldt,
+ lapack_int *info );
+void LAPACK_ctpqrt2( lapack_int* m, lapack_int* n, lapack_complex_float* a,
+ lapack_int* lda, lapack_complex_float* b, lapack_int* ldb,
+ lapack_complex_float* t, lapack_int* ldt,
+ lapack_int *info );
+void LAPACK_ztpqrt2( lapack_int* m, lapack_int* n, lapack_complex_double* a,
+ lapack_int* lda, lapack_complex_double* b, lapack_int* ldb,
+ lapack_complex_double* t, lapack_int* ldt,
+ lapack_int *info );
+void LAPACK_stprfb( char* side, char* trans, char* direct, char* storev,
+ lapack_int* m, lapack_int* n, lapack_int* k, lapack_int* l,
+ const float* v, lapack_int* ldv, const float* t,
+ lapack_int* ldt, float* a, lapack_int* lda, float* b,
+ lapack_int* ldb, const float* mywork,
+ lapack_int* myldwork );
+void LAPACK_dtprfb( char* side, char* trans, char* direct, char* storev,
+ lapack_int* m, lapack_int* n, lapack_int* k, lapack_int* l,
+ const double* v, lapack_int* ldv, const double* t,
+ lapack_int* ldt, double* a, lapack_int* lda, double* b,
+ lapack_int* ldb, const double* mywork,
+ lapack_int* myldwork );
+void LAPACK_ctprfb( char* side, char* trans, char* direct, char* storev,
+ lapack_int* m, lapack_int* n, lapack_int* k, lapack_int* l,
+ const lapack_complex_float* v, lapack_int* ldv,
+ const lapack_complex_float* t, lapack_int* ldt,
+ lapack_complex_float* a, lapack_int* lda,
+ lapack_complex_float* b, lapack_int* ldb,
+ const float* mywork, lapack_int* myldwork );
+void LAPACK_ztprfb( char* side, char* trans, char* direct, char* storev,
+ lapack_int* m, lapack_int* n, lapack_int* k, lapack_int* l,
+ const lapack_complex_double* v, lapack_int* ldv,
+ const lapack_complex_double* t, lapack_int* ldt,
+ lapack_complex_double* a, lapack_int* lda,
+ lapack_complex_double* b, lapack_int* ldb,
+ const double* mywork, lapack_int* myldwork );
+// LAPACK 3.X.X
+void LAPACK_csyr( char* uplo, lapack_int* n, lapack_complex_float* alpha,
+ const lapack_complex_float* x, lapack_int* incx,
+ lapack_complex_float* a, lapack_int* lda );
+void LAPACK_zsyr( char* uplo, lapack_int* n, lapack_complex_double* alpha,
+ const lapack_complex_double* x, lapack_int* incx,
+ lapack_complex_double* a, lapack_int* lda );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _LAPACKE_H_ */
+
+#endif /* _MKL_LAPACKE_H_ */
diff --git a/src/3rdparty/eigen/Eigen/src/misc/lapacke_mangling.h b/src/3rdparty/eigen/Eigen/src/misc/lapacke_mangling.h
new file mode 100644
index 000000000..6211fd144
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/misc/lapacke_mangling.h
@@ -0,0 +1,17 @@
+#ifndef LAPACK_HEADER_INCLUDED
+#define LAPACK_HEADER_INCLUDED
+
+#ifndef LAPACK_GLOBAL
+#if defined(LAPACK_GLOBAL_PATTERN_LC) || defined(ADD_)
+#define LAPACK_GLOBAL(lcname,UCNAME) lcname##_
+#elif defined(LAPACK_GLOBAL_PATTERN_UC) || defined(UPPER)
+#define LAPACK_GLOBAL(lcname,UCNAME) UCNAME
+#elif defined(LAPACK_GLOBAL_PATTERN_MC) || defined(NOCHANGE)
+#define LAPACK_GLOBAL(lcname,UCNAME) lcname
+#else
+#define LAPACK_GLOBAL(lcname,UCNAME) lcname##_
+#endif
+#endif
+
+#endif
+
diff --git a/src/3rdparty/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h b/src/3rdparty/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h
new file mode 100644
index 000000000..0e5d5445b
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h
@@ -0,0 +1,358 @@
+
+/** \returns an expression of the coefficient wise product of \c *this and \a other
+ *
+ * \sa MatrixBase::cwiseProduct
+ */
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product)
+operator*(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
+{
+ return EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product)(derived(), other.derived());
+}
+
+/** \returns an expression of the coefficient wise quotient of \c *this and \a other
+ *
+ * \sa MatrixBase::cwiseQuotient
+ */
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_quotient_op<Scalar,typename OtherDerived::Scalar>, const Derived, const OtherDerived>
+operator/(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
+{
+ return CwiseBinaryOp<internal::scalar_quotient_op<Scalar,typename OtherDerived::Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
+}
+
+/** \returns an expression of the coefficient-wise min of \c *this and \a other
+ *
+ * Example: \include Cwise_min.cpp
+ * Output: \verbinclude Cwise_min.out
+ *
+ * \sa max()
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(min,min)
+
+/** \returns an expression of the coefficient-wise min of \c *this and scalar \a other
+ *
+ * \sa max()
+ */
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived,
+ const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> >
+#ifdef EIGEN_PARSED_BY_DOXYGEN
+min
+#else
+(min)
+#endif
+(const Scalar &other) const
+{
+ return (min)(Derived::PlainObject::Constant(rows(), cols(), other));
+}
+
+/** \returns an expression of the coefficient-wise max of \c *this and \a other
+ *
+ * Example: \include Cwise_max.cpp
+ * Output: \verbinclude Cwise_max.out
+ *
+ * \sa min()
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(max,max)
+
+/** \returns an expression of the coefficient-wise max of \c *this and scalar \a other
+ *
+ * \sa min()
+ */
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived,
+ const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> >
+#ifdef EIGEN_PARSED_BY_DOXYGEN
+max
+#else
+(max)
+#endif
+(const Scalar &other) const
+{
+ return (max)(Derived::PlainObject::Constant(rows(), cols(), other));
+}
+
+/** \returns an expression of the coefficient-wise absdiff of \c *this and \a other
+ *
+ * Example: \include Cwise_absolute_difference.cpp
+ * Output: \verbinclude Cwise_absolute_difference.out
+ *
+ * \sa absolute_difference()
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(absolute_difference,absolute_difference)
+
+/** \returns an expression of the coefficient-wise absolute_difference of \c *this and scalar \a other
+ *
+ * \sa absolute_difference()
+ */
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_absolute_difference_op<Scalar,Scalar>, const Derived,
+ const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> >
+#ifdef EIGEN_PARSED_BY_DOXYGEN
+absolute_difference
+#else
+(absolute_difference)
+#endif
+(const Scalar &other) const
+{
+ return (absolute_difference)(Derived::PlainObject::Constant(rows(), cols(), other));
+}
+
+/** \returns an expression of the coefficient-wise power of \c *this to the given array of \a exponents.
+ *
+ * This function computes the coefficient-wise power.
+ *
+ * Example: \include Cwise_array_power_array.cpp
+ * Output: \verbinclude Cwise_array_power_array.out
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(pow,pow)
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(pow,pow)
+#else
+/** \returns an expression of the coefficients of \c *this rasied to the constant power \a exponent
+ *
+ * \tparam T is the scalar type of \a exponent. It must be compatible with the scalar type of the given expression.
+ *
+ * This function computes the coefficient-wise power. The function MatrixBase::pow() in the
+ * unsupported module MatrixFunctions computes the matrix power.
+ *
+ * Example: \include Cwise_pow.cpp
+ * Output: \verbinclude Cwise_pow.out
+ *
+ * \sa ArrayBase::pow(ArrayBase), square(), cube(), exp(), log()
+ */
+template<typename T>
+const CwiseBinaryOp<internal::scalar_pow_op<Scalar,T>,Derived,Constant<T> > pow(const T& exponent) const;
+#endif
+
+
+// TODO code generating macros could be moved to Macros.h and could include generation of documentation
+#define EIGEN_MAKE_CWISE_COMP_OP(OP, COMPARATOR) \
+template<typename OtherDerived> \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, typename OtherDerived::Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const OtherDerived> \
+OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
+{ \
+ return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, typename OtherDerived::Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const OtherDerived>(derived(), other.derived()); \
+}\
+typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > Cmp ## COMPARATOR ## ReturnType; \
+typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar, internal::cmp_ ## COMPARATOR>, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject>, const Derived > RCmp ## COMPARATOR ## ReturnType; \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Cmp ## COMPARATOR ## ReturnType \
+OP(const Scalar& s) const { \
+ return this->OP(Derived::PlainObject::Constant(rows(), cols(), s)); \
+} \
+EIGEN_DEVICE_FUNC friend EIGEN_STRONG_INLINE const RCmp ## COMPARATOR ## ReturnType \
+OP(const Scalar& s, const EIGEN_CURRENT_STORAGE_BASE_CLASS<Derived>& d) { \
+ return Derived::PlainObject::Constant(d.rows(), d.cols(), s).OP(d); \
+}
+
+#define EIGEN_MAKE_CWISE_COMP_R_OP(OP, R_OP, RCOMPARATOR) \
+template<typename OtherDerived> \
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<typename OtherDerived::Scalar, Scalar, internal::cmp_##RCOMPARATOR>, const OtherDerived, const Derived> \
+OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
+{ \
+ return CwiseBinaryOp<internal::scalar_cmp_op<typename OtherDerived::Scalar, Scalar, internal::cmp_##RCOMPARATOR>, const OtherDerived, const Derived>(other.derived(), derived()); \
+} \
+EIGEN_DEVICE_FUNC \
+inline const RCmp ## RCOMPARATOR ## ReturnType \
+OP(const Scalar& s) const { \
+ return Derived::PlainObject::Constant(rows(), cols(), s).R_OP(*this); \
+} \
+friend inline const Cmp ## RCOMPARATOR ## ReturnType \
+OP(const Scalar& s, const Derived& d) { \
+ return d.R_OP(Derived::PlainObject::Constant(d.rows(), d.cols(), s)); \
+}
+
+
+
+/** \returns an expression of the coefficient-wise \< operator of *this and \a other
+ *
+ * Example: \include Cwise_less.cpp
+ * Output: \verbinclude Cwise_less.out
+ *
+ * \sa all(), any(), operator>(), operator<=()
+ */
+EIGEN_MAKE_CWISE_COMP_OP(operator<, LT)
+
+/** \returns an expression of the coefficient-wise \<= operator of *this and \a other
+ *
+ * Example: \include Cwise_less_equal.cpp
+ * Output: \verbinclude Cwise_less_equal.out
+ *
+ * \sa all(), any(), operator>=(), operator<()
+ */
+EIGEN_MAKE_CWISE_COMP_OP(operator<=, LE)
+
+/** \returns an expression of the coefficient-wise \> operator of *this and \a other
+ *
+ * Example: \include Cwise_greater.cpp
+ * Output: \verbinclude Cwise_greater.out
+ *
+ * \sa all(), any(), operator>=(), operator<()
+ */
+EIGEN_MAKE_CWISE_COMP_R_OP(operator>, operator<, LT)
+
+/** \returns an expression of the coefficient-wise \>= operator of *this and \a other
+ *
+ * Example: \include Cwise_greater_equal.cpp
+ * Output: \verbinclude Cwise_greater_equal.out
+ *
+ * \sa all(), any(), operator>(), operator<=()
+ */
+EIGEN_MAKE_CWISE_COMP_R_OP(operator>=, operator<=, LE)
+
+/** \returns an expression of the coefficient-wise == operator of *this and \a other
+ *
+ * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
+ * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
+ * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
+ * isMuchSmallerThan().
+ *
+ * Example: \include Cwise_equal_equal.cpp
+ * Output: \verbinclude Cwise_equal_equal.out
+ *
+ * \sa all(), any(), isApprox(), isMuchSmallerThan()
+ */
+EIGEN_MAKE_CWISE_COMP_OP(operator==, EQ)
+
+/** \returns an expression of the coefficient-wise != operator of *this and \a other
+ *
+ * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
+ * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
+ * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
+ * isMuchSmallerThan().
+ *
+ * Example: \include Cwise_not_equal.cpp
+ * Output: \verbinclude Cwise_not_equal.out
+ *
+ * \sa all(), any(), isApprox(), isMuchSmallerThan()
+ */
+EIGEN_MAKE_CWISE_COMP_OP(operator!=, NEQ)
+
+
+#undef EIGEN_MAKE_CWISE_COMP_OP
+#undef EIGEN_MAKE_CWISE_COMP_R_OP
+
+// scalar addition
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+EIGEN_MAKE_SCALAR_BINARY_OP(operator+,sum)
+#else
+/** \returns an expression of \c *this with each coeff incremented by the constant \a scalar
+ *
+ * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression.
+ *
+ * Example: \include Cwise_plus.cpp
+ * Output: \verbinclude Cwise_plus.out
+ *
+ * \sa operator+=(), operator-()
+ */
+template<typename T>
+const CwiseBinaryOp<internal::scalar_sum_op<Scalar,T>,Derived,Constant<T> > operator+(const T& scalar) const;
+/** \returns an expression of \a expr with each coeff incremented by the constant \a scalar
+ *
+ * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression.
+ */
+template<typename T> friend
+const CwiseBinaryOp<internal::scalar_sum_op<T,Scalar>,Constant<T>,Derived> operator+(const T& scalar, const StorageBaseType& expr);
+#endif
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+EIGEN_MAKE_SCALAR_BINARY_OP(operator-,difference)
+#else
+/** \returns an expression of \c *this with each coeff decremented by the constant \a scalar
+ *
+ * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression.
+ *
+ * Example: \include Cwise_minus.cpp
+ * Output: \verbinclude Cwise_minus.out
+ *
+ * \sa operator+=(), operator-()
+ */
+template<typename T>
+const CwiseBinaryOp<internal::scalar_difference_op<Scalar,T>,Derived,Constant<T> > operator-(const T& scalar) const;
+/** \returns an expression of the constant matrix of value \a scalar decremented by the coefficients of \a expr
+ *
+ * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression.
+ */
+template<typename T> friend
+const CwiseBinaryOp<internal::scalar_difference_op<T,Scalar>,Constant<T>,Derived> operator-(const T& scalar, const StorageBaseType& expr);
+#endif
+
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(operator/,quotient)
+#else
+ /**
+ * \brief Component-wise division of the scalar \a s by array elements of \a a.
+ *
+ * \tparam Scalar is the scalar type of \a x. It must be compatible with the scalar type of the given array expression (\c Derived::Scalar).
+ */
+ template<typename T> friend
+ inline const CwiseBinaryOp<internal::scalar_quotient_op<T,Scalar>,Constant<T>,Derived>
+ operator/(const T& s,const StorageBaseType& a);
+#endif
+
+/** \returns an expression of the coefficient-wise ^ operator of *this and \a other
+ *
+ * \warning this operator is for expression of bool only.
+ *
+ * Example: \include Cwise_boolean_xor.cpp
+ * Output: \verbinclude Cwise_boolean_xor.out
+ *
+ * \sa operator&&(), select()
+ */
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+inline const CwiseBinaryOp<internal::scalar_boolean_xor_op, const Derived, const OtherDerived>
+operator^(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
+{
+ EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value),
+ THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL);
+ return CwiseBinaryOp<internal::scalar_boolean_xor_op, const Derived, const OtherDerived>(derived(),other.derived());
+}
+
+// NOTE disabled until we agree on argument order
+#if 0
+/** \cpp11 \returns an expression of the coefficient-wise polygamma function.
+ *
+ * \specialfunctions_module
+ *
+ * It returns the \a n -th derivative of the digamma(psi) evaluated at \c *this.
+ *
+ * \warning Be careful with the order of the parameters: x.polygamma(n) is equivalent to polygamma(n,x)
+ *
+ * \sa Eigen::polygamma()
+ */
+template<typename DerivedN>
+inline const CwiseBinaryOp<internal::scalar_polygamma_op<Scalar>, const DerivedN, const Derived>
+polygamma(const EIGEN_CURRENT_STORAGE_BASE_CLASS<DerivedN> &n) const
+{
+ return CwiseBinaryOp<internal::scalar_polygamma_op<Scalar>, const DerivedN, const Derived>(n.derived(), this->derived());
+}
+#endif
+
+/** \returns an expression of the coefficient-wise zeta function.
+ *
+ * \specialfunctions_module
+ *
+ * It returns the Riemann zeta function of two arguments \c *this and \a q:
+ *
+ * \param q is the shift, it must be > 0
+ *
+ * \note *this is the exponent, it must be > 1.
+ * \note This function supports only float and double scalar types. To support other scalar types, the user has
+ * to provide implementations of zeta(T,T) for any scalar type T to be supported.
+ *
+ * This method is an alias for zeta(*this,q);
+ *
+ * \sa Eigen::zeta()
+ */
+template<typename DerivedQ>
+inline const CwiseBinaryOp<internal::scalar_zeta_op<Scalar>, const Derived, const DerivedQ>
+zeta(const EIGEN_CURRENT_STORAGE_BASE_CLASS<DerivedQ> &q) const
+{
+ return CwiseBinaryOp<internal::scalar_zeta_op<Scalar>, const Derived, const DerivedQ>(this->derived(), q.derived());
+}
diff --git a/src/3rdparty/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h b/src/3rdparty/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h
new file mode 100644
index 000000000..13c55f4b1
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h
@@ -0,0 +1,696 @@
+
+
+typedef CwiseUnaryOp<internal::scalar_abs_op<Scalar>, const Derived> AbsReturnType;
+typedef CwiseUnaryOp<internal::scalar_arg_op<Scalar>, const Derived> ArgReturnType;
+typedef CwiseUnaryOp<internal::scalar_abs2_op<Scalar>, const Derived> Abs2ReturnType;
+typedef CwiseUnaryOp<internal::scalar_sqrt_op<Scalar>, const Derived> SqrtReturnType;
+typedef CwiseUnaryOp<internal::scalar_rsqrt_op<Scalar>, const Derived> RsqrtReturnType;
+typedef CwiseUnaryOp<internal::scalar_sign_op<Scalar>, const Derived> SignReturnType;
+typedef CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const Derived> InverseReturnType;
+typedef CwiseUnaryOp<internal::scalar_boolean_not_op<Scalar>, const Derived> BooleanNotReturnType;
+
+typedef CwiseUnaryOp<internal::scalar_exp_op<Scalar>, const Derived> ExpReturnType;
+typedef CwiseUnaryOp<internal::scalar_expm1_op<Scalar>, const Derived> Expm1ReturnType;
+typedef CwiseUnaryOp<internal::scalar_log_op<Scalar>, const Derived> LogReturnType;
+typedef CwiseUnaryOp<internal::scalar_log1p_op<Scalar>, const Derived> Log1pReturnType;
+typedef CwiseUnaryOp<internal::scalar_log10_op<Scalar>, const Derived> Log10ReturnType;
+typedef CwiseUnaryOp<internal::scalar_log2_op<Scalar>, const Derived> Log2ReturnType;
+typedef CwiseUnaryOp<internal::scalar_cos_op<Scalar>, const Derived> CosReturnType;
+typedef CwiseUnaryOp<internal::scalar_sin_op<Scalar>, const Derived> SinReturnType;
+typedef CwiseUnaryOp<internal::scalar_tan_op<Scalar>, const Derived> TanReturnType;
+typedef CwiseUnaryOp<internal::scalar_acos_op<Scalar>, const Derived> AcosReturnType;
+typedef CwiseUnaryOp<internal::scalar_asin_op<Scalar>, const Derived> AsinReturnType;
+typedef CwiseUnaryOp<internal::scalar_atan_op<Scalar>, const Derived> AtanReturnType;
+typedef CwiseUnaryOp<internal::scalar_tanh_op<Scalar>, const Derived> TanhReturnType;
+typedef CwiseUnaryOp<internal::scalar_logistic_op<Scalar>, const Derived> LogisticReturnType;
+typedef CwiseUnaryOp<internal::scalar_sinh_op<Scalar>, const Derived> SinhReturnType;
+#if EIGEN_HAS_CXX11_MATH
+typedef CwiseUnaryOp<internal::scalar_atanh_op<Scalar>, const Derived> AtanhReturnType;
+typedef CwiseUnaryOp<internal::scalar_asinh_op<Scalar>, const Derived> AsinhReturnType;
+typedef CwiseUnaryOp<internal::scalar_acosh_op<Scalar>, const Derived> AcoshReturnType;
+#endif
+typedef CwiseUnaryOp<internal::scalar_cosh_op<Scalar>, const Derived> CoshReturnType;
+typedef CwiseUnaryOp<internal::scalar_square_op<Scalar>, const Derived> SquareReturnType;
+typedef CwiseUnaryOp<internal::scalar_cube_op<Scalar>, const Derived> CubeReturnType;
+typedef CwiseUnaryOp<internal::scalar_round_op<Scalar>, const Derived> RoundReturnType;
+typedef CwiseUnaryOp<internal::scalar_rint_op<Scalar>, const Derived> RintReturnType;
+typedef CwiseUnaryOp<internal::scalar_floor_op<Scalar>, const Derived> FloorReturnType;
+typedef CwiseUnaryOp<internal::scalar_ceil_op<Scalar>, const Derived> CeilReturnType;
+typedef CwiseUnaryOp<internal::scalar_isnan_op<Scalar>, const Derived> IsNaNReturnType;
+typedef CwiseUnaryOp<internal::scalar_isinf_op<Scalar>, const Derived> IsInfReturnType;
+typedef CwiseUnaryOp<internal::scalar_isfinite_op<Scalar>, const Derived> IsFiniteReturnType;
+
+/** \returns an expression of the coefficient-wise absolute value of \c *this
+ *
+ * Example: \include Cwise_abs.cpp
+ * Output: \verbinclude Cwise_abs.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_abs">Math functions</a>, abs2()
+ */
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const AbsReturnType
+abs() const
+{
+ return AbsReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise phase angle of \c *this
+ *
+ * Example: \include Cwise_arg.cpp
+ * Output: \verbinclude Cwise_arg.out
+ *
+ * \sa abs()
+ */
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const ArgReturnType
+arg() const
+{
+ return ArgReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise squared absolute value of \c *this
+ *
+ * Example: \include Cwise_abs2.cpp
+ * Output: \verbinclude Cwise_abs2.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_abs2">Math functions</a>, abs(), square()
+ */
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const Abs2ReturnType
+abs2() const
+{
+ return Abs2ReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise exponential of *this.
+ *
+ * This function computes the coefficient-wise exponential. The function MatrixBase::exp() in the
+ * unsupported module MatrixFunctions computes the matrix exponential.
+ *
+ * Example: \include Cwise_exp.cpp
+ * Output: \verbinclude Cwise_exp.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_exp">Math functions</a>, pow(), log(), sin(), cos()
+ */
+EIGEN_DEVICE_FUNC
+inline const ExpReturnType
+exp() const
+{
+ return ExpReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise exponential of *this minus 1.
+ *
+ * In exact arithmetic, \c x.expm1() is equivalent to \c x.exp() - 1,
+ * however, with finite precision, this function is much more accurate when \c x is close to zero.
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_expm1">Math functions</a>, exp()
+ */
+EIGEN_DEVICE_FUNC
+inline const Expm1ReturnType
+expm1() const
+{
+ return Expm1ReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise logarithm of *this.
+ *
+ * This function computes the coefficient-wise logarithm. The function MatrixBase::log() in the
+ * unsupported module MatrixFunctions computes the matrix logarithm.
+ *
+ * Example: \include Cwise_log.cpp
+ * Output: \verbinclude Cwise_log.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_log">Math functions</a>, log()
+ */
+EIGEN_DEVICE_FUNC
+inline const LogReturnType
+log() const
+{
+ return LogReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise logarithm of 1 plus \c *this.
+ *
+ * In exact arithmetic, \c x.log() is equivalent to \c (x+1).log(),
+ * however, with finite precision, this function is much more accurate when \c x is close to zero.
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_log1p">Math functions</a>, log()
+ */
+EIGEN_DEVICE_FUNC
+inline const Log1pReturnType
+log1p() const
+{
+ return Log1pReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise base-10 logarithm of *this.
+ *
+ * This function computes the coefficient-wise base-10 logarithm.
+ *
+ * Example: \include Cwise_log10.cpp
+ * Output: \verbinclude Cwise_log10.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_log10">Math functions</a>, log()
+ */
+EIGEN_DEVICE_FUNC
+inline const Log10ReturnType
+log10() const
+{
+ return Log10ReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise base-2 logarithm of *this.
+ *
+ * This function computes the coefficient-wise base-2 logarithm.
+ *
+ */
+EIGEN_DEVICE_FUNC
+inline const Log2ReturnType
+log2() const
+{
+ return Log2ReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise square root of *this.
+ *
+ * This function computes the coefficient-wise square root. The function MatrixBase::sqrt() in the
+ * unsupported module MatrixFunctions computes the matrix square root.
+ *
+ * Example: \include Cwise_sqrt.cpp
+ * Output: \verbinclude Cwise_sqrt.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_sqrt">Math functions</a>, pow(), square()
+ */
+EIGEN_DEVICE_FUNC
+inline const SqrtReturnType
+sqrt() const
+{
+ return SqrtReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise inverse square root of *this.
+ *
+ * This function computes the coefficient-wise inverse square root.
+ *
+ * Example: \include Cwise_sqrt.cpp
+ * Output: \verbinclude Cwise_sqrt.out
+ *
+ * \sa pow(), square()
+ */
+EIGEN_DEVICE_FUNC
+inline const RsqrtReturnType
+rsqrt() const
+{
+ return RsqrtReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise signum of *this.
+ *
+ * This function computes the coefficient-wise signum.
+ *
+ * Example: \include Cwise_sign.cpp
+ * Output: \verbinclude Cwise_sign.out
+ *
+ * \sa pow(), square()
+ */
+EIGEN_DEVICE_FUNC
+inline const SignReturnType
+sign() const
+{
+ return SignReturnType(derived());
+}
+
+
+/** \returns an expression of the coefficient-wise cosine of *this.
+ *
+ * This function computes the coefficient-wise cosine. The function MatrixBase::cos() in the
+ * unsupported module MatrixFunctions computes the matrix cosine.
+ *
+ * Example: \include Cwise_cos.cpp
+ * Output: \verbinclude Cwise_cos.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_cos">Math functions</a>, sin(), acos()
+ */
+EIGEN_DEVICE_FUNC
+inline const CosReturnType
+cos() const
+{
+ return CosReturnType(derived());
+}
+
+
+/** \returns an expression of the coefficient-wise sine of *this.
+ *
+ * This function computes the coefficient-wise sine. The function MatrixBase::sin() in the
+ * unsupported module MatrixFunctions computes the matrix sine.
+ *
+ * Example: \include Cwise_sin.cpp
+ * Output: \verbinclude Cwise_sin.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_sin">Math functions</a>, cos(), asin()
+ */
+EIGEN_DEVICE_FUNC
+inline const SinReturnType
+sin() const
+{
+ return SinReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise tan of *this.
+ *
+ * Example: \include Cwise_tan.cpp
+ * Output: \verbinclude Cwise_tan.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_tan">Math functions</a>, cos(), sin()
+ */
+EIGEN_DEVICE_FUNC
+inline const TanReturnType
+tan() const
+{
+ return TanReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise arc tan of *this.
+ *
+ * Example: \include Cwise_atan.cpp
+ * Output: \verbinclude Cwise_atan.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_atan">Math functions</a>, tan(), asin(), acos()
+ */
+EIGEN_DEVICE_FUNC
+inline const AtanReturnType
+atan() const
+{
+ return AtanReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise arc cosine of *this.
+ *
+ * Example: \include Cwise_acos.cpp
+ * Output: \verbinclude Cwise_acos.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_acos">Math functions</a>, cos(), asin()
+ */
+EIGEN_DEVICE_FUNC
+inline const AcosReturnType
+acos() const
+{
+ return AcosReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise arc sine of *this.
+ *
+ * Example: \include Cwise_asin.cpp
+ * Output: \verbinclude Cwise_asin.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_asin">Math functions</a>, sin(), acos()
+ */
+EIGEN_DEVICE_FUNC
+inline const AsinReturnType
+asin() const
+{
+ return AsinReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise hyperbolic tan of *this.
+ *
+ * Example: \include Cwise_tanh.cpp
+ * Output: \verbinclude Cwise_tanh.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_tanh">Math functions</a>, tan(), sinh(), cosh()
+ */
+EIGEN_DEVICE_FUNC
+inline const TanhReturnType
+tanh() const
+{
+ return TanhReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise hyperbolic sin of *this.
+ *
+ * Example: \include Cwise_sinh.cpp
+ * Output: \verbinclude Cwise_sinh.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_sinh">Math functions</a>, sin(), tanh(), cosh()
+ */
+EIGEN_DEVICE_FUNC
+inline const SinhReturnType
+sinh() const
+{
+ return SinhReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise hyperbolic cos of *this.
+ *
+ * Example: \include Cwise_cosh.cpp
+ * Output: \verbinclude Cwise_cosh.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_cosh">Math functions</a>, tanh(), sinh(), cosh()
+ */
+EIGEN_DEVICE_FUNC
+inline const CoshReturnType
+cosh() const
+{
+ return CoshReturnType(derived());
+}
+
+#if EIGEN_HAS_CXX11_MATH
+/** \returns an expression of the coefficient-wise inverse hyperbolic tan of *this.
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_atanh">Math functions</a>, atanh(), asinh(), acosh()
+ */
+EIGEN_DEVICE_FUNC
+inline const AtanhReturnType
+atanh() const
+{
+ return AtanhReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise inverse hyperbolic sin of *this.
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_asinh">Math functions</a>, atanh(), asinh(), acosh()
+ */
+EIGEN_DEVICE_FUNC
+inline const AsinhReturnType
+asinh() const
+{
+ return AsinhReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise inverse hyperbolic cos of *this.
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_acosh">Math functions</a>, atanh(), asinh(), acosh()
+ */
+EIGEN_DEVICE_FUNC
+inline const AcoshReturnType
+acosh() const
+{
+ return AcoshReturnType(derived());
+}
+#endif
+
+/** \returns an expression of the coefficient-wise logistic of *this.
+ */
+EIGEN_DEVICE_FUNC
+inline const LogisticReturnType
+logistic() const
+{
+ return LogisticReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise inverse of *this.
+ *
+ * Example: \include Cwise_inverse.cpp
+ * Output: \verbinclude Cwise_inverse.out
+ *
+ * \sa operator/(), operator*()
+ */
+EIGEN_DEVICE_FUNC
+inline const InverseReturnType
+inverse() const
+{
+ return InverseReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise square of *this.
+ *
+ * Example: \include Cwise_square.cpp
+ * Output: \verbinclude Cwise_square.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_squareE">Math functions</a>, abs2(), cube(), pow()
+ */
+EIGEN_DEVICE_FUNC
+inline const SquareReturnType
+square() const
+{
+ return SquareReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise cube of *this.
+ *
+ * Example: \include Cwise_cube.cpp
+ * Output: \verbinclude Cwise_cube.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_cube">Math functions</a>, square(), pow()
+ */
+EIGEN_DEVICE_FUNC
+inline const CubeReturnType
+cube() const
+{
+ return CubeReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise rint of *this.
+ *
+ * Example: \include Cwise_rint.cpp
+ * Output: \verbinclude Cwise_rint.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_rint">Math functions</a>, ceil(), floor()
+ */
+EIGEN_DEVICE_FUNC
+inline const RintReturnType
+rint() const
+{
+ return RintReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise round of *this.
+ *
+ * Example: \include Cwise_round.cpp
+ * Output: \verbinclude Cwise_round.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_round">Math functions</a>, ceil(), floor()
+ */
+EIGEN_DEVICE_FUNC
+inline const RoundReturnType
+round() const
+{
+ return RoundReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise floor of *this.
+ *
+ * Example: \include Cwise_floor.cpp
+ * Output: \verbinclude Cwise_floor.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_floor">Math functions</a>, ceil(), round()
+ */
+EIGEN_DEVICE_FUNC
+inline const FloorReturnType
+floor() const
+{
+ return FloorReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise ceil of *this.
+ *
+ * Example: \include Cwise_ceil.cpp
+ * Output: \verbinclude Cwise_ceil.out
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_ceil">Math functions</a>, floor(), round()
+ */
+EIGEN_DEVICE_FUNC
+inline const CeilReturnType
+ceil() const
+{
+ return CeilReturnType(derived());
+}
+
+template<int N> struct ShiftRightXpr {
+ typedef CwiseUnaryOp<internal::scalar_shift_right_op<Scalar, N>, const Derived> Type;
+};
+
+/** \returns an expression of \c *this with the \a Scalar type arithmetically
+ * shifted right by \a N bit positions.
+ *
+ * The template parameter \a N specifies the number of bit positions to shift.
+ *
+ * \sa shiftLeft()
+ */
+template<int N>
+EIGEN_DEVICE_FUNC
+typename ShiftRightXpr<N>::Type
+shiftRight() const
+{
+ return typename ShiftRightXpr<N>::Type(derived());
+}
+
+
+template<int N> struct ShiftLeftXpr {
+ typedef CwiseUnaryOp<internal::scalar_shift_left_op<Scalar, N>, const Derived> Type;
+};
+
+/** \returns an expression of \c *this with the \a Scalar type logically
+ * shifted left by \a N bit positions.
+ *
+ * The template parameter \a N specifies the number of bit positions to shift.
+ *
+ * \sa shiftRight()
+ */
+template<int N>
+EIGEN_DEVICE_FUNC
+typename ShiftLeftXpr<N>::Type
+shiftLeft() const
+{
+ return typename ShiftLeftXpr<N>::Type(derived());
+}
+
+/** \returns an expression of the coefficient-wise isnan of *this.
+ *
+ * Example: \include Cwise_isNaN.cpp
+ * Output: \verbinclude Cwise_isNaN.out
+ *
+ * \sa isfinite(), isinf()
+ */
+EIGEN_DEVICE_FUNC
+inline const IsNaNReturnType
+isNaN() const
+{
+ return IsNaNReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise isinf of *this.
+ *
+ * Example: \include Cwise_isInf.cpp
+ * Output: \verbinclude Cwise_isInf.out
+ *
+ * \sa isnan(), isfinite()
+ */
+EIGEN_DEVICE_FUNC
+inline const IsInfReturnType
+isInf() const
+{
+ return IsInfReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise isfinite of *this.
+ *
+ * Example: \include Cwise_isFinite.cpp
+ * Output: \verbinclude Cwise_isFinite.out
+ *
+ * \sa isnan(), isinf()
+ */
+EIGEN_DEVICE_FUNC
+inline const IsFiniteReturnType
+isFinite() const
+{
+ return IsFiniteReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise ! operator of *this
+ *
+ * \warning this operator is for expression of bool only.
+ *
+ * Example: \include Cwise_boolean_not.cpp
+ * Output: \verbinclude Cwise_boolean_not.out
+ *
+ * \sa operator!=()
+ */
+EIGEN_DEVICE_FUNC
+inline const BooleanNotReturnType
+operator!() const
+{
+ EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value),
+ THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL);
+ return BooleanNotReturnType(derived());
+}
+
+
+// --- SpecialFunctions module ---
+
+typedef CwiseUnaryOp<internal::scalar_lgamma_op<Scalar>, const Derived> LgammaReturnType;
+typedef CwiseUnaryOp<internal::scalar_digamma_op<Scalar>, const Derived> DigammaReturnType;
+typedef CwiseUnaryOp<internal::scalar_erf_op<Scalar>, const Derived> ErfReturnType;
+typedef CwiseUnaryOp<internal::scalar_erfc_op<Scalar>, const Derived> ErfcReturnType;
+typedef CwiseUnaryOp<internal::scalar_ndtri_op<Scalar>, const Derived> NdtriReturnType;
+
+/** \cpp11 \returns an expression of the coefficient-wise ln(|gamma(*this)|).
+ *
+ * \specialfunctions_module
+ *
+ * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types,
+ * or float/double in non c++11 mode, the user has to provide implementations of lgamma(T) for any scalar
+ * type T to be supported.
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_lgamma">Math functions</a>, digamma()
+ */
+EIGEN_DEVICE_FUNC
+inline const LgammaReturnType
+lgamma() const
+{
+ return LgammaReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise digamma (psi, derivative of lgamma).
+ *
+ * \specialfunctions_module
+ *
+ * \note This function supports only float and double scalar types. To support other scalar types,
+ * the user has to provide implementations of digamma(T) for any scalar
+ * type T to be supported.
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_digamma">Math functions</a>, Eigen::digamma(), Eigen::polygamma(), lgamma()
+ */
+EIGEN_DEVICE_FUNC
+inline const DigammaReturnType
+digamma() const
+{
+ return DigammaReturnType(derived());
+}
+
+/** \cpp11 \returns an expression of the coefficient-wise Gauss error
+ * function of *this.
+ *
+ * \specialfunctions_module
+ *
+ * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types,
+ * or float/double in non c++11 mode, the user has to provide implementations of erf(T) for any scalar
+ * type T to be supported.
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_erf">Math functions</a>, erfc()
+ */
+EIGEN_DEVICE_FUNC
+inline const ErfReturnType
+erf() const
+{
+ return ErfReturnType(derived());
+}
+
+/** \cpp11 \returns an expression of the coefficient-wise Complementary error
+ * function of *this.
+ *
+ * \specialfunctions_module
+ *
+ * \note This function supports only float and double scalar types in c++11 mode. To support other scalar types,
+ * or float/double in non c++11 mode, the user has to provide implementations of erfc(T) for any scalar
+ * type T to be supported.
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_erfc">Math functions</a>, erf()
+ */
+EIGEN_DEVICE_FUNC
+inline const ErfcReturnType
+erfc() const
+{
+ return ErfcReturnType(derived());
+}
+
+/** \returns an expression of the coefficient-wise inverse of the CDF of the Normal distribution function
+ * function of *this.
+ *
+ * \specialfunctions_module
+ *
+ * In other words, considering `x = ndtri(y)`, it returns the argument, x, for which the area under the
+ * Gaussian probability density function (integrated from minus infinity to x) is equal to y.
+ *
+ * \note This function supports only float and double scalar types. To support other scalar types,
+ * the user has to provide implementations of ndtri(T) for any scalar type T to be supported.
+ *
+ * \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_ndtri">Math functions</a>
+ */
+EIGEN_DEVICE_FUNC
+inline const NdtriReturnType
+ndtri() const
+{
+ return NdtriReturnType(derived());
+}
diff --git a/src/3rdparty/eigen/Eigen/src/plugins/BlockMethods.h b/src/3rdparty/eigen/Eigen/src/plugins/BlockMethods.h
new file mode 100644
index 000000000..63a52a6ff
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/plugins/BlockMethods.h
@@ -0,0 +1,1442 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+
+/// \internal expression type of a column */
+typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ColXpr;
+typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ConstColXpr;
+/// \internal expression type of a row */
+typedef Block<Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowXpr;
+typedef const Block<const Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowXpr;
+/// \internal expression type of a block of whole columns */
+typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ColsBlockXpr;
+typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ConstColsBlockXpr;
+/// \internal expression type of a block of whole rows */
+typedef Block<Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowsBlockXpr;
+typedef const Block<const Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowsBlockXpr;
+/// \internal expression type of a block of whole columns */
+template<int N> struct NColsBlockXpr { typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, N, !IsRowMajor> Type; };
+template<int N> struct ConstNColsBlockXpr { typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, N, !IsRowMajor> Type; };
+/// \internal expression type of a block of whole rows */
+template<int N> struct NRowsBlockXpr { typedef Block<Derived, N, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> Type; };
+template<int N> struct ConstNRowsBlockXpr { typedef const Block<const Derived, N, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> Type; };
+/// \internal expression of a block */
+typedef Block<Derived> BlockXpr;
+typedef const Block<const Derived> ConstBlockXpr;
+/// \internal expression of a block of fixed sizes */
+template<int Rows, int Cols> struct FixedBlockXpr { typedef Block<Derived,Rows,Cols> Type; };
+template<int Rows, int Cols> struct ConstFixedBlockXpr { typedef Block<const Derived,Rows,Cols> Type; };
+
+typedef VectorBlock<Derived> SegmentReturnType;
+typedef const VectorBlock<const Derived> ConstSegmentReturnType;
+template<int Size> struct FixedSegmentReturnType { typedef VectorBlock<Derived, Size> Type; };
+template<int Size> struct ConstFixedSegmentReturnType { typedef const VectorBlock<const Derived, Size> Type; };
+
+/// \internal inner-vector
+typedef Block<Derived,IsRowMajor?1:Dynamic,IsRowMajor?Dynamic:1,true> InnerVectorReturnType;
+typedef Block<const Derived,IsRowMajor?1:Dynamic,IsRowMajor?Dynamic:1,true> ConstInnerVectorReturnType;
+
+/// \internal set of inner-vectors
+typedef Block<Derived,Dynamic,Dynamic,true> InnerVectorsReturnType;
+typedef Block<const Derived,Dynamic,Dynamic,true> ConstInnerVectorsReturnType;
+
+#endif // not EIGEN_PARSED_BY_DOXYGEN
+
+/// \returns an expression of a block in \c *this with either dynamic or fixed sizes.
+///
+/// \param startRow the first row in the block
+/// \param startCol the first column in the block
+/// \param blockRows number of rows in the block, specified at either run-time or compile-time
+/// \param blockCols number of columns in the block, specified at either run-time or compile-time
+/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index.
+/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index.
+///
+/// Example using runtime (aka dynamic) sizes: \include MatrixBase_block_int_int_int_int.cpp
+/// Output: \verbinclude MatrixBase_block_int_int_int_int.out
+///
+/// \newin{3.4}:
+///
+/// The number of rows \a blockRows and columns \a blockCols can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments. In the later case, \c n plays the role of a runtime fallback value in case \c N equals Eigen::Dynamic.
+/// Here is an example with a fixed number of rows \c NRows and dynamic number of columns \c cols:
+/// \code
+/// mat.block(i,j,fix<NRows>,cols)
+/// \endcode
+///
+/// This function thus fully covers the features offered by the following overloads block<NRows,NCols>(Index, Index),
+/// and block<NRows,NCols>(Index, Index, Index, Index) that are thus obsolete. Indeed, this generic version avoids
+/// redundancy, it preserves the argument order, and prevents the need to rely on the template keyword in templated code.
+///
+/// but with less redundancy and more consistency as it does not modify the argument order
+/// and seamlessly enable hybrid fixed/dynamic sizes.
+///
+/// \note Even in the case that the returned expression has dynamic size, in the case
+/// when it is applied to a fixed-size matrix, it inherits a fixed maximal size,
+/// which means that evaluating it does not cause a dynamic memory allocation.
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa class Block, fix, fix<N>(int)
+///
+template<typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+typename FixedBlockXpr<...,...>::Type
+#endif
+block(Index startRow, Index startCol, NRowsType blockRows, NColsType blockCols)
+{
+ return typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type(
+ derived(), startRow, startCol, internal::get_runtime_value(blockRows), internal::get_runtime_value(blockCols));
+}
+
+/// This is the const version of block(Index,Index,NRowsType,NColsType)
+template<typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+const typename ConstFixedBlockXpr<...,...>::Type
+#endif
+block(Index startRow, Index startCol, NRowsType blockRows, NColsType blockCols) const
+{
+ return typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type(
+ derived(), startRow, startCol, internal::get_runtime_value(blockRows), internal::get_runtime_value(blockCols));
+}
+
+
+
+/// \returns a expression of a top-right corner of \c *this with either dynamic or fixed sizes.
+///
+/// \param cRows the number of rows in the corner
+/// \param cCols the number of columns in the corner
+/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index.
+/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index.
+///
+/// Example with dynamic sizes: \include MatrixBase_topRightCorner_int_int.cpp
+/// Output: \verbinclude MatrixBase_topRightCorner_int_int.out
+///
+/// The number of rows \a blockRows and columns \a blockCols can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments. See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+typename FixedBlockXpr<...,...>::Type
+#endif
+topRightCorner(NRowsType cRows, NColsType cCols)
+{
+ return typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), 0, cols() - internal::get_runtime_value(cCols), internal::get_runtime_value(cRows), internal::get_runtime_value(cCols));
+}
+
+/// This is the const version of topRightCorner(NRowsType, NColsType).
+template<typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+const typename ConstFixedBlockXpr<...,...>::Type
+#endif
+topRightCorner(NRowsType cRows, NColsType cCols) const
+{
+ return typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), 0, cols() - internal::get_runtime_value(cCols), internal::get_runtime_value(cRows), internal::get_runtime_value(cCols));
+}
+
+/// \returns an expression of a fixed-size top-right corner of \c *this.
+///
+/// \tparam CRows the number of rows in the corner
+/// \tparam CCols the number of columns in the corner
+///
+/// Example: \include MatrixBase_template_int_int_topRightCorner.cpp
+/// Output: \verbinclude MatrixBase_template_int_int_topRightCorner.out
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa class Block, block<int,int>(Index,Index)
+///
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedBlockXpr<CRows,CCols>::Type topRightCorner()
+{
+ return typename FixedBlockXpr<CRows,CCols>::Type(derived(), 0, cols() - CCols);
+}
+
+/// This is the const version of topRightCorner<int, int>().
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const typename ConstFixedBlockXpr<CRows,CCols>::Type topRightCorner() const
+{
+ return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), 0, cols() - CCols);
+}
+
+/// \returns an expression of a top-right corner of \c *this.
+///
+/// \tparam CRows number of rows in corner as specified at compile-time
+/// \tparam CCols number of columns in corner as specified at compile-time
+/// \param cRows number of rows in corner as specified at run-time
+/// \param cCols number of columns in corner as specified at run-time
+///
+/// This function is mainly useful for corners where the number of rows is specified at compile-time
+/// and the number of columns is specified at run-time, or vice versa. The compile-time and run-time
+/// information should not contradict. In other words, \a cRows should equal \a CRows unless
+/// \a CRows is \a Dynamic, and the same for the number of columns.
+///
+/// Example: \include MatrixBase_template_int_int_topRightCorner_int_int.cpp
+/// Output: \verbinclude MatrixBase_template_int_int_topRightCorner_int_int.out
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa class Block
+///
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedBlockXpr<CRows,CCols>::Type topRightCorner(Index cRows, Index cCols)
+{
+ return typename FixedBlockXpr<CRows,CCols>::Type(derived(), 0, cols() - cCols, cRows, cCols);
+}
+
+/// This is the const version of topRightCorner<int, int>(Index, Index).
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const typename ConstFixedBlockXpr<CRows,CCols>::Type topRightCorner(Index cRows, Index cCols) const
+{
+ return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), 0, cols() - cCols, cRows, cCols);
+}
+
+
+
+/// \returns an expression of a top-left corner of \c *this with either dynamic or fixed sizes.
+///
+/// \param cRows the number of rows in the corner
+/// \param cCols the number of columns in the corner
+/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index.
+/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index.
+///
+/// Example: \include MatrixBase_topLeftCorner_int_int.cpp
+/// Output: \verbinclude MatrixBase_topLeftCorner_int_int.out
+///
+/// The number of rows \a blockRows and columns \a blockCols can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments. See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+typename FixedBlockXpr<...,...>::Type
+#endif
+topLeftCorner(NRowsType cRows, NColsType cCols)
+{
+ return typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), 0, 0, internal::get_runtime_value(cRows), internal::get_runtime_value(cCols));
+}
+
+/// This is the const version of topLeftCorner(Index, Index).
+template<typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+const typename ConstFixedBlockXpr<...,...>::Type
+#endif
+topLeftCorner(NRowsType cRows, NColsType cCols) const
+{
+ return typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), 0, 0, internal::get_runtime_value(cRows), internal::get_runtime_value(cCols));
+}
+
+/// \returns an expression of a fixed-size top-left corner of \c *this.
+///
+/// The template parameters CRows and CCols are the number of rows and columns in the corner.
+///
+/// Example: \include MatrixBase_template_int_int_topLeftCorner.cpp
+/// Output: \verbinclude MatrixBase_template_int_int_topLeftCorner.out
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedBlockXpr<CRows,CCols>::Type topLeftCorner()
+{
+ return typename FixedBlockXpr<CRows,CCols>::Type(derived(), 0, 0);
+}
+
+/// This is the const version of topLeftCorner<int, int>().
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const typename ConstFixedBlockXpr<CRows,CCols>::Type topLeftCorner() const
+{
+ return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), 0, 0);
+}
+
+/// \returns an expression of a top-left corner of \c *this.
+///
+/// \tparam CRows number of rows in corner as specified at compile-time
+/// \tparam CCols number of columns in corner as specified at compile-time
+/// \param cRows number of rows in corner as specified at run-time
+/// \param cCols number of columns in corner as specified at run-time
+///
+/// This function is mainly useful for corners where the number of rows is specified at compile-time
+/// and the number of columns is specified at run-time, or vice versa. The compile-time and run-time
+/// information should not contradict. In other words, \a cRows should equal \a CRows unless
+/// \a CRows is \a Dynamic, and the same for the number of columns.
+///
+/// Example: \include MatrixBase_template_int_int_topLeftCorner_int_int.cpp
+/// Output: \verbinclude MatrixBase_template_int_int_topLeftCorner_int_int.out
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa class Block
+///
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedBlockXpr<CRows,CCols>::Type topLeftCorner(Index cRows, Index cCols)
+{
+ return typename FixedBlockXpr<CRows,CCols>::Type(derived(), 0, 0, cRows, cCols);
+}
+
+/// This is the const version of topLeftCorner<int, int>(Index, Index).
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const typename ConstFixedBlockXpr<CRows,CCols>::Type topLeftCorner(Index cRows, Index cCols) const
+{
+ return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), 0, 0, cRows, cCols);
+}
+
+
+
+/// \returns an expression of a bottom-right corner of \c *this with either dynamic or fixed sizes.
+///
+/// \param cRows the number of rows in the corner
+/// \param cCols the number of columns in the corner
+/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index.
+/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index.
+///
+/// Example: \include MatrixBase_bottomRightCorner_int_int.cpp
+/// Output: \verbinclude MatrixBase_bottomRightCorner_int_int.out
+///
+/// The number of rows \a blockRows and columns \a blockCols can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments. See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+typename FixedBlockXpr<...,...>::Type
+#endif
+bottomRightCorner(NRowsType cRows, NColsType cCols)
+{
+ return typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), rows() - internal::get_runtime_value(cRows), cols() - internal::get_runtime_value(cCols),
+ internal::get_runtime_value(cRows), internal::get_runtime_value(cCols));
+}
+
+/// This is the const version of bottomRightCorner(NRowsType, NColsType).
+template<typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+const typename ConstFixedBlockXpr<...,...>::Type
+#endif
+bottomRightCorner(NRowsType cRows, NColsType cCols) const
+{
+ return typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), rows() - internal::get_runtime_value(cRows), cols() - internal::get_runtime_value(cCols),
+ internal::get_runtime_value(cRows), internal::get_runtime_value(cCols));
+}
+
+/// \returns an expression of a fixed-size bottom-right corner of \c *this.
+///
+/// The template parameters CRows and CCols are the number of rows and columns in the corner.
+///
+/// Example: \include MatrixBase_template_int_int_bottomRightCorner.cpp
+/// Output: \verbinclude MatrixBase_template_int_int_bottomRightCorner.out
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedBlockXpr<CRows,CCols>::Type bottomRightCorner()
+{
+ return typename FixedBlockXpr<CRows,CCols>::Type(derived(), rows() - CRows, cols() - CCols);
+}
+
+/// This is the const version of bottomRightCorner<int, int>().
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const typename ConstFixedBlockXpr<CRows,CCols>::Type bottomRightCorner() const
+{
+ return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), rows() - CRows, cols() - CCols);
+}
+
+/// \returns an expression of a bottom-right corner of \c *this.
+///
+/// \tparam CRows number of rows in corner as specified at compile-time
+/// \tparam CCols number of columns in corner as specified at compile-time
+/// \param cRows number of rows in corner as specified at run-time
+/// \param cCols number of columns in corner as specified at run-time
+///
+/// This function is mainly useful for corners where the number of rows is specified at compile-time
+/// and the number of columns is specified at run-time, or vice versa. The compile-time and run-time
+/// information should not contradict. In other words, \a cRows should equal \a CRows unless
+/// \a CRows is \a Dynamic, and the same for the number of columns.
+///
+/// Example: \include MatrixBase_template_int_int_bottomRightCorner_int_int.cpp
+/// Output: \verbinclude MatrixBase_template_int_int_bottomRightCorner_int_int.out
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa class Block
+///
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedBlockXpr<CRows,CCols>::Type bottomRightCorner(Index cRows, Index cCols)
+{
+ return typename FixedBlockXpr<CRows,CCols>::Type(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
+}
+
+/// This is the const version of bottomRightCorner<int, int>(Index, Index).
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const typename ConstFixedBlockXpr<CRows,CCols>::Type bottomRightCorner(Index cRows, Index cCols) const
+{
+ return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
+}
+
+
+
+/// \returns an expression of a bottom-left corner of \c *this with either dynamic or fixed sizes.
+///
+/// \param cRows the number of rows in the corner
+/// \param cCols the number of columns in the corner
+/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index.
+/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index.
+///
+/// Example: \include MatrixBase_bottomLeftCorner_int_int.cpp
+/// Output: \verbinclude MatrixBase_bottomLeftCorner_int_int.out
+///
+/// The number of rows \a blockRows and columns \a blockCols can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments. See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+typename FixedBlockXpr<...,...>::Type
+#endif
+bottomLeftCorner(NRowsType cRows, NColsType cCols)
+{
+ return typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), rows() - internal::get_runtime_value(cRows), 0,
+ internal::get_runtime_value(cRows), internal::get_runtime_value(cCols));
+}
+
+/// This is the const version of bottomLeftCorner(NRowsType, NColsType).
+template<typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+typename ConstFixedBlockXpr<...,...>::Type
+#endif
+bottomLeftCorner(NRowsType cRows, NColsType cCols) const
+{
+ return typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), rows() - internal::get_runtime_value(cRows), 0,
+ internal::get_runtime_value(cRows), internal::get_runtime_value(cCols));
+}
+
+/// \returns an expression of a fixed-size bottom-left corner of \c *this.
+///
+/// The template parameters CRows and CCols are the number of rows and columns in the corner.
+///
+/// Example: \include MatrixBase_template_int_int_bottomLeftCorner.cpp
+/// Output: \verbinclude MatrixBase_template_int_int_bottomLeftCorner.out
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedBlockXpr<CRows,CCols>::Type bottomLeftCorner()
+{
+ return typename FixedBlockXpr<CRows,CCols>::Type(derived(), rows() - CRows, 0);
+}
+
+/// This is the const version of bottomLeftCorner<int, int>().
+template<int CRows, int CCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const typename ConstFixedBlockXpr<CRows,CCols>::Type bottomLeftCorner() const
+{
+ return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), rows() - CRows, 0);
+}
+
+/// \returns an expression of a bottom-left corner of \c *this.
+///
+/// \tparam CRows number of rows in corner as specified at compile-time
+/// \tparam CCols number of columns in corner as specified at compile-time
+/// \param cRows number of rows in corner as specified at run-time
+/// \param cCols number of columns in corner as specified at run-time
+///
+/// This function is mainly useful for corners where the number of rows is specified at compile-time
+/// and the number of columns is specified at run-time, or vice versa. The compile-time and run-time
+/// information should not contradict. In other words, \a cRows should equal \a CRows unless
+/// \a CRows is \a Dynamic, and the same for the number of columns.
+///
+/// Example: \include MatrixBase_template_int_int_bottomLeftCorner_int_int.cpp
+/// Output: \verbinclude MatrixBase_template_int_int_bottomLeftCorner_int_int.out
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa class Block
+///
+template<int CRows, int CCols>
+EIGEN_STRONG_INLINE
+typename FixedBlockXpr<CRows,CCols>::Type bottomLeftCorner(Index cRows, Index cCols)
+{
+ return typename FixedBlockXpr<CRows,CCols>::Type(derived(), rows() - cRows, 0, cRows, cCols);
+}
+
+/// This is the const version of bottomLeftCorner<int, int>(Index, Index).
+template<int CRows, int CCols>
+EIGEN_STRONG_INLINE
+const typename ConstFixedBlockXpr<CRows,CCols>::Type bottomLeftCorner(Index cRows, Index cCols) const
+{
+ return typename ConstFixedBlockXpr<CRows,CCols>::Type(derived(), rows() - cRows, 0, cRows, cCols);
+}
+
+
+
+/// \returns a block consisting of the top rows of \c *this.
+///
+/// \param n the number of rows in the block
+/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index.
+///
+/// Example: \include MatrixBase_topRows_int.cpp
+/// Output: \verbinclude MatrixBase_topRows_int.out
+///
+/// The number of rows \a n can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments.
+/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<typename NRowsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+#else
+typename NRowsBlockXpr<...>::Type
+#endif
+topRows(NRowsType n)
+{
+ return typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+ (derived(), 0, 0, internal::get_runtime_value(n), cols());
+}
+
+/// This is the const version of topRows(NRowsType).
+template<typename NRowsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+#else
+const typename ConstNRowsBlockXpr<...>::Type
+#endif
+topRows(NRowsType n) const
+{
+ return typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+ (derived(), 0, 0, internal::get_runtime_value(n), cols());
+}
+
+/// \returns a block consisting of the top rows of \c *this.
+///
+/// \tparam N the number of rows in the block as specified at compile-time
+/// \param n the number of rows in the block as specified at run-time
+///
+/// The compile-time and run-time information should not contradict. In other words,
+/// \a n should equal \a N unless \a N is \a Dynamic.
+///
+/// Example: \include MatrixBase_template_int_topRows.cpp
+/// Output: \verbinclude MatrixBase_template_int_topRows.out
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename NRowsBlockXpr<N>::Type topRows(Index n = N)
+{
+ return typename NRowsBlockXpr<N>::Type(derived(), 0, 0, n, cols());
+}
+
+/// This is the const version of topRows<int>().
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename ConstNRowsBlockXpr<N>::Type topRows(Index n = N) const
+{
+ return typename ConstNRowsBlockXpr<N>::Type(derived(), 0, 0, n, cols());
+}
+
+
+
+/// \returns a block consisting of the bottom rows of \c *this.
+///
+/// \param n the number of rows in the block
+/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index.
+///
+/// Example: \include MatrixBase_bottomRows_int.cpp
+/// Output: \verbinclude MatrixBase_bottomRows_int.out
+///
+/// The number of rows \a n can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments.
+/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<typename NRowsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+#else
+typename NRowsBlockXpr<...>::Type
+#endif
+bottomRows(NRowsType n)
+{
+ return typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+ (derived(), rows() - internal::get_runtime_value(n), 0, internal::get_runtime_value(n), cols());
+}
+
+/// This is the const version of bottomRows(NRowsType).
+template<typename NRowsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+#else
+const typename ConstNRowsBlockXpr<...>::Type
+#endif
+bottomRows(NRowsType n) const
+{
+ return typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+ (derived(), rows() - internal::get_runtime_value(n), 0, internal::get_runtime_value(n), cols());
+}
+
+/// \returns a block consisting of the bottom rows of \c *this.
+///
+/// \tparam N the number of rows in the block as specified at compile-time
+/// \param n the number of rows in the block as specified at run-time
+///
+/// The compile-time and run-time information should not contradict. In other words,
+/// \a n should equal \a N unless \a N is \a Dynamic.
+///
+/// Example: \include MatrixBase_template_int_bottomRows.cpp
+/// Output: \verbinclude MatrixBase_template_int_bottomRows.out
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename NRowsBlockXpr<N>::Type bottomRows(Index n = N)
+{
+ return typename NRowsBlockXpr<N>::Type(derived(), rows() - n, 0, n, cols());
+}
+
+/// This is the const version of bottomRows<int>().
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename ConstNRowsBlockXpr<N>::Type bottomRows(Index n = N) const
+{
+ return typename ConstNRowsBlockXpr<N>::Type(derived(), rows() - n, 0, n, cols());
+}
+
+
+
+/// \returns a block consisting of a range of rows of \c *this.
+///
+/// \param startRow the index of the first row in the block
+/// \param n the number of rows in the block
+/// \tparam NRowsType the type of the value handling the number of rows in the block, typically Index.
+///
+/// Example: \include DenseBase_middleRows_int.cpp
+/// Output: \verbinclude DenseBase_middleRows_int.out
+///
+/// The number of rows \a n can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments.
+/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<typename NRowsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+#else
+typename NRowsBlockXpr<...>::Type
+#endif
+middleRows(Index startRow, NRowsType n)
+{
+ return typename NRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+ (derived(), startRow, 0, internal::get_runtime_value(n), cols());
+}
+
+/// This is the const version of middleRows(Index,NRowsType).
+template<typename NRowsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+#else
+const typename ConstNRowsBlockXpr<...>::Type
+#endif
+middleRows(Index startRow, NRowsType n) const
+{
+ return typename ConstNRowsBlockXpr<internal::get_fixed_value<NRowsType>::value>::Type
+ (derived(), startRow, 0, internal::get_runtime_value(n), cols());
+}
+
+/// \returns a block consisting of a range of rows of \c *this.
+///
+/// \tparam N the number of rows in the block as specified at compile-time
+/// \param startRow the index of the first row in the block
+/// \param n the number of rows in the block as specified at run-time
+///
+/// The compile-time and run-time information should not contradict. In other words,
+/// \a n should equal \a N unless \a N is \a Dynamic.
+///
+/// Example: \include DenseBase_template_int_middleRows.cpp
+/// Output: \verbinclude DenseBase_template_int_middleRows.out
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename NRowsBlockXpr<N>::Type middleRows(Index startRow, Index n = N)
+{
+ return typename NRowsBlockXpr<N>::Type(derived(), startRow, 0, n, cols());
+}
+
+/// This is the const version of middleRows<int>().
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename ConstNRowsBlockXpr<N>::Type middleRows(Index startRow, Index n = N) const
+{
+ return typename ConstNRowsBlockXpr<N>::Type(derived(), startRow, 0, n, cols());
+}
+
+
+
+/// \returns a block consisting of the left columns of \c *this.
+///
+/// \param n the number of columns in the block
+/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index.
+///
+/// Example: \include MatrixBase_leftCols_int.cpp
+/// Output: \verbinclude MatrixBase_leftCols_int.out
+///
+/// The number of columns \a n can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments.
+/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+#else
+typename NColsBlockXpr<...>::Type
+#endif
+leftCols(NColsType n)
+{
+ return typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), 0, 0, rows(), internal::get_runtime_value(n));
+}
+
+/// This is the const version of leftCols(NColsType).
+template<typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+#else
+const typename ConstNColsBlockXpr<...>::Type
+#endif
+leftCols(NColsType n) const
+{
+ return typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), 0, 0, rows(), internal::get_runtime_value(n));
+}
+
+/// \returns a block consisting of the left columns of \c *this.
+///
+/// \tparam N the number of columns in the block as specified at compile-time
+/// \param n the number of columns in the block as specified at run-time
+///
+/// The compile-time and run-time information should not contradict. In other words,
+/// \a n should equal \a N unless \a N is \a Dynamic.
+///
+/// Example: \include MatrixBase_template_int_leftCols.cpp
+/// Output: \verbinclude MatrixBase_template_int_leftCols.out
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename NColsBlockXpr<N>::Type leftCols(Index n = N)
+{
+ return typename NColsBlockXpr<N>::Type(derived(), 0, 0, rows(), n);
+}
+
+/// This is the const version of leftCols<int>().
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename ConstNColsBlockXpr<N>::Type leftCols(Index n = N) const
+{
+ return typename ConstNColsBlockXpr<N>::Type(derived(), 0, 0, rows(), n);
+}
+
+
+
+/// \returns a block consisting of the right columns of \c *this.
+///
+/// \param n the number of columns in the block
+/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index.
+///
+/// Example: \include MatrixBase_rightCols_int.cpp
+/// Output: \verbinclude MatrixBase_rightCols_int.out
+///
+/// The number of columns \a n can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments.
+/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+#else
+typename NColsBlockXpr<...>::Type
+#endif
+rightCols(NColsType n)
+{
+ return typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), 0, cols() - internal::get_runtime_value(n), rows(), internal::get_runtime_value(n));
+}
+
+/// This is the const version of rightCols(NColsType).
+template<typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+#else
+const typename ConstNColsBlockXpr<...>::Type
+#endif
+rightCols(NColsType n) const
+{
+ return typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), 0, cols() - internal::get_runtime_value(n), rows(), internal::get_runtime_value(n));
+}
+
+/// \returns a block consisting of the right columns of \c *this.
+///
+/// \tparam N the number of columns in the block as specified at compile-time
+/// \param n the number of columns in the block as specified at run-time
+///
+/// The compile-time and run-time information should not contradict. In other words,
+/// \a n should equal \a N unless \a N is \a Dynamic.
+///
+/// Example: \include MatrixBase_template_int_rightCols.cpp
+/// Output: \verbinclude MatrixBase_template_int_rightCols.out
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename NColsBlockXpr<N>::Type rightCols(Index n = N)
+{
+ return typename NColsBlockXpr<N>::Type(derived(), 0, cols() - n, rows(), n);
+}
+
+/// This is the const version of rightCols<int>().
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename ConstNColsBlockXpr<N>::Type rightCols(Index n = N) const
+{
+ return typename ConstNColsBlockXpr<N>::Type(derived(), 0, cols() - n, rows(), n);
+}
+
+
+
+/// \returns a block consisting of a range of columns of \c *this.
+///
+/// \param startCol the index of the first column in the block
+/// \param numCols the number of columns in the block
+/// \tparam NColsType the type of the value handling the number of columns in the block, typically Index.
+///
+/// Example: \include DenseBase_middleCols_int.cpp
+/// Output: \verbinclude DenseBase_middleCols_int.out
+///
+/// The number of columns \a n can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments.
+/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+#else
+typename NColsBlockXpr<...>::Type
+#endif
+middleCols(Index startCol, NColsType numCols)
+{
+ return typename NColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), 0, startCol, rows(), internal::get_runtime_value(numCols));
+}
+
+/// This is the const version of middleCols(Index,NColsType).
+template<typename NColsType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+#else
+const typename ConstNColsBlockXpr<...>::Type
+#endif
+middleCols(Index startCol, NColsType numCols) const
+{
+ return typename ConstNColsBlockXpr<internal::get_fixed_value<NColsType>::value>::Type
+ (derived(), 0, startCol, rows(), internal::get_runtime_value(numCols));
+}
+
+/// \returns a block consisting of a range of columns of \c *this.
+///
+/// \tparam N the number of columns in the block as specified at compile-time
+/// \param startCol the index of the first column in the block
+/// \param n the number of columns in the block as specified at run-time
+///
+/// The compile-time and run-time information should not contradict. In other words,
+/// \a n should equal \a N unless \a N is \a Dynamic.
+///
+/// Example: \include DenseBase_template_int_middleCols.cpp
+/// Output: \verbinclude DenseBase_template_int_middleCols.out
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major)
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename NColsBlockXpr<N>::Type middleCols(Index startCol, Index n = N)
+{
+ return typename NColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), n);
+}
+
+/// This is the const version of middleCols<int>().
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename ConstNColsBlockXpr<N>::Type middleCols(Index startCol, Index n = N) const
+{
+ return typename ConstNColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), n);
+}
+
+
+
+/// \returns a fixed-size expression of a block of \c *this.
+///
+/// The template parameters \a NRows and \a NCols are the number of
+/// rows and columns in the block.
+///
+/// \param startRow the first row in the block
+/// \param startCol the first column in the block
+///
+/// Example: \include MatrixBase_block_int_int.cpp
+/// Output: \verbinclude MatrixBase_block_int_int.out
+///
+/// \note The usage of of this overload is discouraged from %Eigen 3.4, better used the generic
+/// block(Index,Index,NRowsType,NColsType), here is the one-to-one equivalence:
+/// \code
+/// mat.template block<NRows,NCols>(i,j) <--> mat.block(i,j,fix<NRows>,fix<NCols>)
+/// \endcode
+///
+/// \note since block is a templated member, the keyword template has to be used
+/// if the matrix type is also a template parameter: \code m.template block<3,3>(1,1); \endcode
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<int NRows, int NCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedBlockXpr<NRows,NCols>::Type block(Index startRow, Index startCol)
+{
+ return typename FixedBlockXpr<NRows,NCols>::Type(derived(), startRow, startCol);
+}
+
+/// This is the const version of block<>(Index, Index). */
+template<int NRows, int NCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const typename ConstFixedBlockXpr<NRows,NCols>::Type block(Index startRow, Index startCol) const
+{
+ return typename ConstFixedBlockXpr<NRows,NCols>::Type(derived(), startRow, startCol);
+}
+
+/// \returns an expression of a block of \c *this.
+///
+/// \tparam NRows number of rows in block as specified at compile-time
+/// \tparam NCols number of columns in block as specified at compile-time
+/// \param startRow the first row in the block
+/// \param startCol the first column in the block
+/// \param blockRows number of rows in block as specified at run-time
+/// \param blockCols number of columns in block as specified at run-time
+///
+/// This function is mainly useful for blocks where the number of rows is specified at compile-time
+/// and the number of columns is specified at run-time, or vice versa. The compile-time and run-time
+/// information should not contradict. In other words, \a blockRows should equal \a NRows unless
+/// \a NRows is \a Dynamic, and the same for the number of columns.
+///
+/// Example: \include MatrixBase_template_int_int_block_int_int_int_int.cpp
+/// Output: \verbinclude MatrixBase_template_int_int_block_int_int_int_int.out
+///
+/// \note The usage of of this overload is discouraged from %Eigen 3.4, better used the generic
+/// block(Index,Index,NRowsType,NColsType), here is the one-to-one complete equivalence:
+/// \code
+/// mat.template block<NRows,NCols>(i,j,rows,cols) <--> mat.block(i,j,fix<NRows>(rows),fix<NCols>(cols))
+/// \endcode
+/// If we known that, e.g., NRows==Dynamic and NCols!=Dynamic, then the equivalence becomes:
+/// \code
+/// mat.template block<Dynamic,NCols>(i,j,rows,NCols) <--> mat.block(i,j,rows,fix<NCols>)
+/// \endcode
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa block(Index,Index,NRowsType,NColsType), class Block
+///
+template<int NRows, int NCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedBlockXpr<NRows,NCols>::Type block(Index startRow, Index startCol,
+ Index blockRows, Index blockCols)
+{
+ return typename FixedBlockXpr<NRows,NCols>::Type(derived(), startRow, startCol, blockRows, blockCols);
+}
+
+/// This is the const version of block<>(Index, Index, Index, Index).
+template<int NRows, int NCols>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const typename ConstFixedBlockXpr<NRows,NCols>::Type block(Index startRow, Index startCol,
+ Index blockRows, Index blockCols) const
+{
+ return typename ConstFixedBlockXpr<NRows,NCols>::Type(derived(), startRow, startCol, blockRows, blockCols);
+}
+
+/// \returns an expression of the \a i-th column of \c *this. Note that the numbering starts at 0.
+///
+/// Example: \include MatrixBase_col.cpp
+/// Output: \verbinclude MatrixBase_col.out
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major)
+/**
+ * \sa row(), class Block */
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ColXpr col(Index i)
+{
+ return ColXpr(derived(), i);
+}
+
+/// This is the const version of col().
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ConstColXpr col(Index i) const
+{
+ return ConstColXpr(derived(), i);
+}
+
+/// \returns an expression of the \a i-th row of \c *this. Note that the numbering starts at 0.
+///
+/// Example: \include MatrixBase_row.cpp
+/// Output: \verbinclude MatrixBase_row.out
+///
+EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major)
+/**
+ * \sa col(), class Block */
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+RowXpr row(Index i)
+{
+ return RowXpr(derived(), i);
+}
+
+/// This is the const version of row(). */
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+ConstRowXpr row(Index i) const
+{
+ return ConstRowXpr(derived(), i);
+}
+
+/// \returns an expression of a segment (i.e. a vector block) in \c *this with either dynamic or fixed sizes.
+///
+/// \only_for_vectors
+///
+/// \param start the first coefficient in the segment
+/// \param n the number of coefficients in the segment
+/// \tparam NType the type of the value handling the number of coefficients in the segment, typically Index.
+///
+/// Example: \include MatrixBase_segment_int_int.cpp
+/// Output: \verbinclude MatrixBase_segment_int_int.out
+///
+/// The number of coefficients \a n can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments.
+/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+/// \note Even in the case that the returned expression has dynamic size, in the case
+/// when it is applied to a fixed-size vector, it inherits a fixed maximal size,
+/// which means that evaluating it does not cause a dynamic memory allocation.
+///
+/// \sa block(Index,Index,NRowsType,NColsType), fix<N>, fix<N>(int), class Block
+///
+template<typename NType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+#else
+typename FixedSegmentReturnType<...>::Type
+#endif
+segment(Index start, NType n)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+ (derived(), start, internal::get_runtime_value(n));
+}
+
+
+/// This is the const version of segment(Index,NType).
+template<typename NType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+#else
+const typename ConstFixedSegmentReturnType<...>::Type
+#endif
+segment(Index start, NType n) const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+ (derived(), start, internal::get_runtime_value(n));
+}
+
+/// \returns an expression of the first coefficients of \c *this with either dynamic or fixed sizes.
+///
+/// \only_for_vectors
+///
+/// \param n the number of coefficients in the segment
+/// \tparam NType the type of the value handling the number of coefficients in the segment, typically Index.
+///
+/// Example: \include MatrixBase_start_int.cpp
+/// Output: \verbinclude MatrixBase_start_int.out
+///
+/// The number of coefficients \a n can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments.
+/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+/// \note Even in the case that the returned expression has dynamic size, in the case
+/// when it is applied to a fixed-size vector, it inherits a fixed maximal size,
+/// which means that evaluating it does not cause a dynamic memory allocation.
+///
+/// \sa class Block, block(Index,Index)
+///
+template<typename NType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+#else
+typename FixedSegmentReturnType<...>::Type
+#endif
+head(NType n)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+ (derived(), 0, internal::get_runtime_value(n));
+}
+
+/// This is the const version of head(NType).
+template<typename NType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+#else
+const typename ConstFixedSegmentReturnType<...>::Type
+#endif
+head(NType n) const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+ (derived(), 0, internal::get_runtime_value(n));
+}
+
+/// \returns an expression of a last coefficients of \c *this with either dynamic or fixed sizes.
+///
+/// \only_for_vectors
+///
+/// \param n the number of coefficients in the segment
+/// \tparam NType the type of the value handling the number of coefficients in the segment, typically Index.
+///
+/// Example: \include MatrixBase_end_int.cpp
+/// Output: \verbinclude MatrixBase_end_int.out
+///
+/// The number of coefficients \a n can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments.
+/// See \link block(Index,Index,NRowsType,NColsType) block() \endlink for the details.
+///
+/// \note Even in the case that the returned expression has dynamic size, in the case
+/// when it is applied to a fixed-size vector, it inherits a fixed maximal size,
+/// which means that evaluating it does not cause a dynamic memory allocation.
+///
+/// \sa class Block, block(Index,Index)
+///
+template<typename NType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+#else
+typename FixedSegmentReturnType<...>::Type
+#endif
+tail(NType n)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename FixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+ (derived(), this->size() - internal::get_runtime_value(n), internal::get_runtime_value(n));
+}
+
+/// This is the const version of tail(Index).
+template<typename NType>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+const typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+#else
+const typename ConstFixedSegmentReturnType<...>::Type
+#endif
+tail(NType n) const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename ConstFixedSegmentReturnType<internal::get_fixed_value<NType>::value>::Type
+ (derived(), this->size() - internal::get_runtime_value(n), internal::get_runtime_value(n));
+}
+
+/// \returns a fixed-size expression of a segment (i.e. a vector block) in \c *this
+///
+/// \only_for_vectors
+///
+/// \tparam N the number of coefficients in the segment as specified at compile-time
+/// \param start the index of the first element in the segment
+/// \param n the number of coefficients in the segment as specified at compile-time
+///
+/// The compile-time and run-time information should not contradict. In other words,
+/// \a n should equal \a N unless \a N is \a Dynamic.
+///
+/// Example: \include MatrixBase_template_int_segment.cpp
+/// Output: \verbinclude MatrixBase_template_int_segment.out
+///
+/// \sa segment(Index,NType), class Block
+///
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedSegmentReturnType<N>::Type segment(Index start, Index n = N)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename FixedSegmentReturnType<N>::Type(derived(), start, n);
+}
+
+/// This is the const version of segment<int>(Index).
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename ConstFixedSegmentReturnType<N>::Type segment(Index start, Index n = N) const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename ConstFixedSegmentReturnType<N>::Type(derived(), start, n);
+}
+
+/// \returns a fixed-size expression of the first coefficients of \c *this.
+///
+/// \only_for_vectors
+///
+/// \tparam N the number of coefficients in the segment as specified at compile-time
+/// \param n the number of coefficients in the segment as specified at run-time
+///
+/// The compile-time and run-time information should not contradict. In other words,
+/// \a n should equal \a N unless \a N is \a Dynamic.
+///
+/// Example: \include MatrixBase_template_int_start.cpp
+/// Output: \verbinclude MatrixBase_template_int_start.out
+///
+/// \sa head(NType), class Block
+///
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedSegmentReturnType<N>::Type head(Index n = N)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename FixedSegmentReturnType<N>::Type(derived(), 0, n);
+}
+
+/// This is the const version of head<int>().
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename ConstFixedSegmentReturnType<N>::Type head(Index n = N) const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename ConstFixedSegmentReturnType<N>::Type(derived(), 0, n);
+}
+
+/// \returns a fixed-size expression of the last coefficients of \c *this.
+///
+/// \only_for_vectors
+///
+/// \tparam N the number of coefficients in the segment as specified at compile-time
+/// \param n the number of coefficients in the segment as specified at run-time
+///
+/// The compile-time and run-time information should not contradict. In other words,
+/// \a n should equal \a N unless \a N is \a Dynamic.
+///
+/// Example: \include MatrixBase_template_int_end.cpp
+/// Output: \verbinclude MatrixBase_template_int_end.out
+///
+/// \sa tail(NType), class Block
+///
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename FixedSegmentReturnType<N>::Type tail(Index n = N)
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename FixedSegmentReturnType<N>::Type(derived(), size() - n);
+}
+
+/// This is the const version of tail<int>.
+template<int N>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename ConstFixedSegmentReturnType<N>::Type tail(Index n = N) const
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return typename ConstFixedSegmentReturnType<N>::Type(derived(), size() - n);
+}
+
+/// \returns the \a outer -th column (resp. row) of the matrix \c *this if \c *this
+/// is col-major (resp. row-major).
+///
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+InnerVectorReturnType innerVector(Index outer)
+{ return InnerVectorReturnType(derived(), outer); }
+
+/// \returns the \a outer -th column (resp. row) of the matrix \c *this if \c *this
+/// is col-major (resp. row-major). Read-only.
+///
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const ConstInnerVectorReturnType innerVector(Index outer) const
+{ return ConstInnerVectorReturnType(derived(), outer); }
+
+/// \returns the \a outer -th column (resp. row) of the matrix \c *this if \c *this
+/// is col-major (resp. row-major).
+///
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+InnerVectorsReturnType
+innerVectors(Index outerStart, Index outerSize)
+{
+ return Block<Derived,Dynamic,Dynamic,true>(derived(),
+ IsRowMajor ? outerStart : 0, IsRowMajor ? 0 : outerStart,
+ IsRowMajor ? outerSize : rows(), IsRowMajor ? cols() : outerSize);
+
+}
+
+/// \returns the \a outer -th column (resp. row) of the matrix \c *this if \c *this
+/// is col-major (resp. row-major). Read-only.
+///
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+const ConstInnerVectorsReturnType
+innerVectors(Index outerStart, Index outerSize) const
+{
+ return Block<const Derived,Dynamic,Dynamic,true>(derived(),
+ IsRowMajor ? outerStart : 0, IsRowMajor ? 0 : outerStart,
+ IsRowMajor ? outerSize : rows(), IsRowMajor ? cols() : outerSize);
+
+}
+
+/** \returns the i-th subvector (column or vector) according to the \c Direction
+ * \sa subVectors()
+ */
+template<DirectionType Direction>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename internal::conditional<Direction==Vertical,ColXpr,RowXpr>::type
+subVector(Index i)
+{
+ return typename internal::conditional<Direction==Vertical,ColXpr,RowXpr>::type(derived(),i);
+}
+
+/** This is the const version of subVector(Index) */
+template<DirectionType Direction>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
+typename internal::conditional<Direction==Vertical,ConstColXpr,ConstRowXpr>::type
+subVector(Index i) const
+{
+ return typename internal::conditional<Direction==Vertical,ConstColXpr,ConstRowXpr>::type(derived(),i);
+}
+
+/** \returns the number of subvectors (rows or columns) in the direction \c Direction
+ * \sa subVector(Index)
+ */
+template<DirectionType Direction>
+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
+Index subVectors() const
+{ return (Direction==Vertical)?cols():rows(); }
diff --git a/src/3rdparty/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h b/src/3rdparty/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h
new file mode 100644
index 000000000..8b6730ede
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h
@@ -0,0 +1,115 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+// This file is a base class plugin containing common coefficient wise functions.
+
+/** \returns an expression of the difference of \c *this and \a other
+ *
+ * \note If you want to substract a given scalar from all coefficients, see Cwise::operator-().
+ *
+ * \sa class CwiseBinaryOp, operator-=()
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(operator-,difference)
+
+/** \returns an expression of the sum of \c *this and \a other
+ *
+ * \note If you want to add a given scalar to all coefficients, see Cwise::operator+().
+ *
+ * \sa class CwiseBinaryOp, operator+=()
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(operator+,sum)
+
+/** \returns an expression of a custom coefficient-wise operator \a func of *this and \a other
+ *
+ * The template parameter \a CustomBinaryOp is the type of the functor
+ * of the custom operator (see class CwiseBinaryOp for an example)
+ *
+ * Here is an example illustrating the use of custom functors:
+ * \include class_CwiseBinaryOp.cpp
+ * Output: \verbinclude class_CwiseBinaryOp.out
+ *
+ * \sa class CwiseBinaryOp, operator+(), operator-(), cwiseProduct()
+ */
+template<typename CustomBinaryOp, typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseBinaryOp<CustomBinaryOp, const Derived, const OtherDerived>
+binaryExpr(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other, const CustomBinaryOp& func = CustomBinaryOp()) const
+{
+ return CwiseBinaryOp<CustomBinaryOp, const Derived, const OtherDerived>(derived(), other.derived(), func);
+}
+
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+EIGEN_MAKE_SCALAR_BINARY_OP(operator*,product)
+#else
+/** \returns an expression of \c *this scaled by the scalar factor \a scalar
+ *
+ * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression.
+ */
+template<typename T>
+const CwiseBinaryOp<internal::scalar_product_op<Scalar,T>,Derived,Constant<T> > operator*(const T& scalar) const;
+/** \returns an expression of \a expr scaled by the scalar factor \a scalar
+ *
+ * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression.
+ */
+template<typename T> friend
+const CwiseBinaryOp<internal::scalar_product_op<T,Scalar>,Constant<T>,Derived> operator*(const T& scalar, const StorageBaseType& expr);
+#endif
+
+
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(operator/,quotient)
+#else
+/** \returns an expression of \c *this divided by the scalar value \a scalar
+ *
+ * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression.
+ */
+template<typename T>
+const CwiseBinaryOp<internal::scalar_quotient_op<Scalar,T>,Derived,Constant<T> > operator/(const T& scalar) const;
+#endif
+
+/** \returns an expression of the coefficient-wise boolean \b and operator of \c *this and \a other
+ *
+ * \warning this operator is for expression of bool only.
+ *
+ * Example: \include Cwise_boolean_and.cpp
+ * Output: \verbinclude Cwise_boolean_and.out
+ *
+ * \sa operator||(), select()
+ */
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+inline const CwiseBinaryOp<internal::scalar_boolean_and_op, const Derived, const OtherDerived>
+operator&&(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
+{
+ EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value),
+ THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL);
+ return CwiseBinaryOp<internal::scalar_boolean_and_op, const Derived, const OtherDerived>(derived(),other.derived());
+}
+
+/** \returns an expression of the coefficient-wise boolean \b or operator of \c *this and \a other
+ *
+ * \warning this operator is for expression of bool only.
+ *
+ * Example: \include Cwise_boolean_or.cpp
+ * Output: \verbinclude Cwise_boolean_or.out
+ *
+ * \sa operator&&(), select()
+ */
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+inline const CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived>
+operator||(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
+{
+ EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value),
+ THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL);
+ return CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived>(derived(),other.derived());
+}
diff --git a/src/3rdparty/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h b/src/3rdparty/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h
new file mode 100644
index 000000000..5418dc415
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h
@@ -0,0 +1,177 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+// This file is a base class plugin containing common coefficient wise functions.
+
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+
+/** \internal the return type of conjugate() */
+typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
+ const CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const Derived>,
+ const Derived&
+ >::type ConjugateReturnType;
+/** \internal the return type of real() const */
+typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
+ const CwiseUnaryOp<internal::scalar_real_op<Scalar>, const Derived>,
+ const Derived&
+ >::type RealReturnType;
+/** \internal the return type of real() */
+typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
+ CwiseUnaryView<internal::scalar_real_ref_op<Scalar>, Derived>,
+ Derived&
+ >::type NonConstRealReturnType;
+/** \internal the return type of imag() const */
+typedef CwiseUnaryOp<internal::scalar_imag_op<Scalar>, const Derived> ImagReturnType;
+/** \internal the return type of imag() */
+typedef CwiseUnaryView<internal::scalar_imag_ref_op<Scalar>, Derived> NonConstImagReturnType;
+
+typedef CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const Derived> NegativeReturnType;
+
+#endif // not EIGEN_PARSED_BY_DOXYGEN
+
+/// \returns an expression of the opposite of \c *this
+///
+EIGEN_DOC_UNARY_ADDONS(operator-,opposite)
+///
+EIGEN_DEVICE_FUNC
+inline const NegativeReturnType
+operator-() const { return NegativeReturnType(derived()); }
+
+
+template<class NewType> struct CastXpr { typedef typename internal::cast_return_type<Derived,const CwiseUnaryOp<internal::scalar_cast_op<Scalar, NewType>, const Derived> >::type Type; };
+
+/// \returns an expression of \c *this with the \a Scalar type casted to
+/// \a NewScalar.
+///
+/// The template parameter \a NewScalar is the type we are casting the scalars to.
+///
+EIGEN_DOC_UNARY_ADDONS(cast,conversion function)
+///
+/// \sa class CwiseUnaryOp
+///
+template<typename NewType>
+EIGEN_DEVICE_FUNC
+typename CastXpr<NewType>::Type
+cast() const
+{
+ return typename CastXpr<NewType>::Type(derived());
+}
+
+/// \returns an expression of the complex conjugate of \c *this.
+///
+EIGEN_DOC_UNARY_ADDONS(conjugate,complex conjugate)
+///
+/// \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_conj">Math functions</a>, MatrixBase::adjoint()
+EIGEN_DEVICE_FUNC
+inline ConjugateReturnType
+conjugate() const
+{
+ return ConjugateReturnType(derived());
+}
+
+/// \returns an expression of the complex conjugate of \c *this if Cond==true, returns derived() otherwise.
+///
+EIGEN_DOC_UNARY_ADDONS(conjugate,complex conjugate)
+///
+/// \sa conjugate()
+template<bool Cond>
+EIGEN_DEVICE_FUNC
+inline typename internal::conditional<Cond,ConjugateReturnType,const Derived&>::type
+conjugateIf() const
+{
+ typedef typename internal::conditional<Cond,ConjugateReturnType,const Derived&>::type ReturnType;
+ return ReturnType(derived());
+}
+
+/// \returns a read-only expression of the real part of \c *this.
+///
+EIGEN_DOC_UNARY_ADDONS(real,real part function)
+///
+/// \sa imag()
+EIGEN_DEVICE_FUNC
+inline RealReturnType
+real() const { return RealReturnType(derived()); }
+
+/// \returns an read-only expression of the imaginary part of \c *this.
+///
+EIGEN_DOC_UNARY_ADDONS(imag,imaginary part function)
+///
+/// \sa real()
+EIGEN_DEVICE_FUNC
+inline const ImagReturnType
+imag() const { return ImagReturnType(derived()); }
+
+/// \brief Apply a unary operator coefficient-wise
+/// \param[in] func Functor implementing the unary operator
+/// \tparam CustomUnaryOp Type of \a func
+/// \returns An expression of a custom coefficient-wise unary operator \a func of *this
+///
+/// The function \c ptr_fun() from the C++ standard library can be used to make functors out of normal functions.
+///
+/// Example:
+/// \include class_CwiseUnaryOp_ptrfun.cpp
+/// Output: \verbinclude class_CwiseUnaryOp_ptrfun.out
+///
+/// Genuine functors allow for more possibilities, for instance it may contain a state.
+///
+/// Example:
+/// \include class_CwiseUnaryOp.cpp
+/// Output: \verbinclude class_CwiseUnaryOp.out
+///
+EIGEN_DOC_UNARY_ADDONS(unaryExpr,unary function)
+///
+/// \sa unaryViewExpr, binaryExpr, class CwiseUnaryOp
+///
+template<typename CustomUnaryOp>
+EIGEN_DEVICE_FUNC
+inline const CwiseUnaryOp<CustomUnaryOp, const Derived>
+unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const
+{
+ return CwiseUnaryOp<CustomUnaryOp, const Derived>(derived(), func);
+}
+
+/// \returns an expression of a custom coefficient-wise unary operator \a func of *this
+///
+/// The template parameter \a CustomUnaryOp is the type of the functor
+/// of the custom unary operator.
+///
+/// Example:
+/// \include class_CwiseUnaryOp.cpp
+/// Output: \verbinclude class_CwiseUnaryOp.out
+///
+EIGEN_DOC_UNARY_ADDONS(unaryViewExpr,unary function)
+///
+/// \sa unaryExpr, binaryExpr class CwiseUnaryOp
+///
+template<typename CustomViewOp>
+EIGEN_DEVICE_FUNC
+inline const CwiseUnaryView<CustomViewOp, const Derived>
+unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const
+{
+ return CwiseUnaryView<CustomViewOp, const Derived>(derived(), func);
+}
+
+/// \returns a non const expression of the real part of \c *this.
+///
+EIGEN_DOC_UNARY_ADDONS(real,real part function)
+///
+/// \sa imag()
+EIGEN_DEVICE_FUNC
+inline NonConstRealReturnType
+real() { return NonConstRealReturnType(derived()); }
+
+/// \returns a non const expression of the imaginary part of \c *this.
+///
+EIGEN_DOC_UNARY_ADDONS(imag,imaginary part function)
+///
+/// \sa real()
+EIGEN_DEVICE_FUNC
+inline NonConstImagReturnType
+imag() { return NonConstImagReturnType(derived()); }
diff --git a/src/3rdparty/eigen/Eigen/src/plugins/IndexedViewMethods.h b/src/3rdparty/eigen/Eigen/src/plugins/IndexedViewMethods.h
new file mode 100644
index 000000000..5bfb19ac6
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/plugins/IndexedViewMethods.h
@@ -0,0 +1,262 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#if !defined(EIGEN_PARSED_BY_DOXYGEN)
+
+// This file is automatically included twice to generate const and non-const versions
+
+#ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
+#define EIGEN_INDEXED_VIEW_METHOD_CONST const
+#define EIGEN_INDEXED_VIEW_METHOD_TYPE ConstIndexedViewType
+#else
+#define EIGEN_INDEXED_VIEW_METHOD_CONST
+#define EIGEN_INDEXED_VIEW_METHOD_TYPE IndexedViewType
+#endif
+
+#ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
+protected:
+
+// define some aliases to ease readability
+
+template<typename Indices>
+struct IvcRowType : public internal::IndexedViewCompatibleType<Indices,RowsAtCompileTime> {};
+
+template<typename Indices>
+struct IvcColType : public internal::IndexedViewCompatibleType<Indices,ColsAtCompileTime> {};
+
+template<typename Indices>
+struct IvcType : public internal::IndexedViewCompatibleType<Indices,SizeAtCompileTime> {};
+
+typedef typename internal::IndexedViewCompatibleType<Index,1>::type IvcIndex;
+
+template<typename Indices>
+typename IvcRowType<Indices>::type
+ivcRow(const Indices& indices) const {
+ return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,RowsAtCompileTime>(derived().rows()),Specialized);
+}
+
+template<typename Indices>
+typename IvcColType<Indices>::type
+ivcCol(const Indices& indices) const {
+ return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,ColsAtCompileTime>(derived().cols()),Specialized);
+}
+
+template<typename Indices>
+typename IvcColType<Indices>::type
+ivcSize(const Indices& indices) const {
+ return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,SizeAtCompileTime>(derived().size()),Specialized);
+}
+
+public:
+
+#endif
+
+template<typename RowIndices, typename ColIndices>
+struct EIGEN_INDEXED_VIEW_METHOD_TYPE {
+ typedef IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,
+ typename IvcRowType<RowIndices>::type,
+ typename IvcColType<ColIndices>::type> type;
+};
+
+// This is the generic version
+
+template<typename RowIndices, typename ColIndices>
+typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
+ && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsIndexedView,
+ typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type >::type
+operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ return typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type
+ (derived(), ivcRow(rowIndices), ivcCol(colIndices));
+}
+
+// The following overload returns a Block<> object
+
+template<typename RowIndices, typename ColIndices>
+typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
+ && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsBlock,
+ typename internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::BlockType>::type
+operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ typedef typename internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::BlockType BlockType;
+ typename IvcRowType<RowIndices>::type actualRowIndices = ivcRow(rowIndices);
+ typename IvcColType<ColIndices>::type actualColIndices = ivcCol(colIndices);
+ return BlockType(derived(),
+ internal::first(actualRowIndices),
+ internal::first(actualColIndices),
+ internal::size(actualRowIndices),
+ internal::size(actualColIndices));
+}
+
+// The following overload returns a Scalar
+
+template<typename RowIndices, typename ColIndices>
+typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
+ && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsScalar,
+ CoeffReturnType >::type
+operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ return Base::operator()(internal::eval_expr_given_size(rowIndices,rows()),internal::eval_expr_given_size(colIndices,cols()));
+}
+
+#if EIGEN_HAS_STATIC_ARRAY_TEMPLATE
+
+// The following three overloads are needed to handle raw Index[N] arrays.
+
+template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndices>
+IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename IvcColType<ColIndices>::type>
+operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename IvcColType<ColIndices>::type>
+ (derived(), rowIndices, ivcCol(colIndices));
+}
+
+template<typename RowIndices, typename ColIndicesT, std::size_t ColIndicesN>
+IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcRowType<RowIndices>::type, const ColIndicesT (&)[ColIndicesN]>
+operator()(const RowIndices& rowIndices, const ColIndicesT (&colIndices)[ColIndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcRowType<RowIndices>::type,const ColIndicesT (&)[ColIndicesN]>
+ (derived(), ivcRow(rowIndices), colIndices);
+}
+
+template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndicesT, std::size_t ColIndicesN>
+IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN], const ColIndicesT (&)[ColIndicesN]>
+operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndicesT (&colIndices)[ColIndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],const ColIndicesT (&)[ColIndicesN]>
+ (derived(), rowIndices, colIndices);
+}
+
+#endif // EIGEN_HAS_STATIC_ARRAY_TEMPLATE
+
+// Overloads for 1D vectors/arrays
+
+template<typename Indices>
+typename internal::enable_if<
+ IsRowMajor && (!(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1 || internal::is_valid_index_type<Indices>::value)),
+ IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,typename IvcType<Indices>::type> >::type
+operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,typename IvcType<Indices>::type>
+ (derived(), IvcIndex(0), ivcCol(indices));
+}
+
+template<typename Indices>
+typename internal::enable_if<
+ (!IsRowMajor) && (!(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1 || internal::is_valid_index_type<Indices>::value)),
+ IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcType<Indices>::type,IvcIndex> >::type
+operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcType<Indices>::type,IvcIndex>
+ (derived(), ivcRow(indices), IvcIndex(0));
+}
+
+template<typename Indices>
+typename internal::enable_if<
+ (internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1) && (!internal::is_valid_index_type<Indices>::value) && (!symbolic::is_symbolic<Indices>::value),
+ VectorBlock<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,internal::array_size<Indices>::value> >::type
+operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ typename IvcType<Indices>::type actualIndices = ivcSize(indices);
+ return VectorBlock<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,internal::array_size<Indices>::value>
+ (derived(), internal::first(actualIndices), internal::size(actualIndices));
+}
+
+template<typename IndexType>
+typename internal::enable_if<symbolic::is_symbolic<IndexType>::value, CoeffReturnType >::type
+operator()(const IndexType& id) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ return Base::operator()(internal::eval_expr_given_size(id,size()));
+}
+
+#if EIGEN_HAS_STATIC_ARRAY_TEMPLATE
+
+template<typename IndicesT, std::size_t IndicesN>
+typename internal::enable_if<IsRowMajor,
+ IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,const IndicesT (&)[IndicesN]> >::type
+operator()(const IndicesT (&indices)[IndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,const IndicesT (&)[IndicesN]>
+ (derived(), IvcIndex(0), indices);
+}
+
+template<typename IndicesT, std::size_t IndicesN>
+typename internal::enable_if<!IsRowMajor,
+ IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const IndicesT (&)[IndicesN],IvcIndex> >::type
+operator()(const IndicesT (&indices)[IndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
+{
+ EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
+ return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const IndicesT (&)[IndicesN],IvcIndex>
+ (derived(), indices, IvcIndex(0));
+}
+
+#endif // EIGEN_HAS_STATIC_ARRAY_TEMPLATE
+
+#undef EIGEN_INDEXED_VIEW_METHOD_CONST
+#undef EIGEN_INDEXED_VIEW_METHOD_TYPE
+
+#ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
+#define EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
+#include "IndexedViewMethods.h"
+#undef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
+#endif
+
+#else // EIGEN_PARSED_BY_DOXYGEN
+
+/**
+ * \returns a generic submatrix view defined by the rows and columns indexed \a rowIndices and \a colIndices respectively.
+ *
+ * Each parameter must either be:
+ * - An integer indexing a single row or column
+ * - Eigen::all indexing the full set of respective rows or columns in increasing order
+ * - An ArithmeticSequence as returned by the Eigen::seq and Eigen::seqN functions
+ * - Any %Eigen's vector/array of integers or expressions
+ * - Plain C arrays: \c int[N]
+ * - And more generally any type exposing the following two member functions:
+ * \code
+ * <integral type> operator[](<integral type>) const;
+ * <integral type> size() const;
+ * \endcode
+ * where \c <integral \c type> stands for any integer type compatible with Eigen::Index (i.e. \c std::ptrdiff_t).
+ *
+ * The last statement implies compatibility with \c std::vector, \c std::valarray, \c std::array, many of the Range-v3's ranges, etc.
+ *
+ * If the submatrix can be represented using a starting position \c (i,j) and positive sizes \c (rows,columns), then this
+ * method will returns a Block object after extraction of the relevant information from the passed arguments. This is the case
+ * when all arguments are either:
+ * - An integer
+ * - Eigen::all
+ * - An ArithmeticSequence with compile-time increment strictly equal to 1, as returned by Eigen::seq(a,b), and Eigen::seqN(a,N).
+ *
+ * Otherwise a more general IndexedView<Derived,RowIndices',ColIndices'> object will be returned, after conversion of the inputs
+ * to more suitable types \c RowIndices' and \c ColIndices'.
+ *
+ * For 1D vectors and arrays, you better use the operator()(const Indices&) overload, which behave the same way but taking a single parameter.
+ *
+ * See also this <a href="https://stackoverflow.com/questions/46110917/eigen-replicate-items-along-one-dimension-without-useless-allocations">question</a> and its answer for an example of how to duplicate coefficients.
+ *
+ * \sa operator()(const Indices&), class Block, class IndexedView, DenseBase::block(Index,Index,Index,Index)
+ */
+template<typename RowIndices, typename ColIndices>
+IndexedView_or_Block
+operator()(const RowIndices& rowIndices, const ColIndices& colIndices);
+
+/** This is an overload of operator()(const RowIndices&, const ColIndices&) for 1D vectors or arrays
+ *
+ * \only_for_vectors
+ */
+template<typename Indices>
+IndexedView_or_VectorBlock
+operator()(const Indices& indices);
+
+#endif // EIGEN_PARSED_BY_DOXYGEN
diff --git a/src/3rdparty/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h b/src/3rdparty/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h
new file mode 100644
index 000000000..a0feef871
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h
@@ -0,0 +1,152 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+// This file is a base class plugin containing matrix specifics coefficient wise functions.
+
+/** \returns an expression of the Schur product (coefficient wise product) of *this and \a other
+ *
+ * Example: \include MatrixBase_cwiseProduct.cpp
+ * Output: \verbinclude MatrixBase_cwiseProduct.out
+ *
+ * \sa class CwiseBinaryOp, cwiseAbs2
+ */
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product)
+cwiseProduct(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
+{
+ return EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product)(derived(), other.derived());
+}
+
+/** \returns an expression of the coefficient-wise == operator of *this and \a other
+ *
+ * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
+ * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
+ * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
+ * isMuchSmallerThan().
+ *
+ * Example: \include MatrixBase_cwiseEqual.cpp
+ * Output: \verbinclude MatrixBase_cwiseEqual.out
+ *
+ * \sa cwiseNotEqual(), isApprox(), isMuchSmallerThan()
+ */
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+inline const CwiseBinaryOp<numext::equal_to<Scalar>, const Derived, const OtherDerived>
+cwiseEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
+{
+ return CwiseBinaryOp<numext::equal_to<Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
+}
+
+/** \returns an expression of the coefficient-wise != operator of *this and \a other
+ *
+ * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
+ * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
+ * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
+ * isMuchSmallerThan().
+ *
+ * Example: \include MatrixBase_cwiseNotEqual.cpp
+ * Output: \verbinclude MatrixBase_cwiseNotEqual.out
+ *
+ * \sa cwiseEqual(), isApprox(), isMuchSmallerThan()
+ */
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+inline const CwiseBinaryOp<numext::not_equal_to<Scalar>, const Derived, const OtherDerived>
+cwiseNotEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
+{
+ return CwiseBinaryOp<numext::not_equal_to<Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
+}
+
+/** \returns an expression of the coefficient-wise min of *this and \a other
+ *
+ * Example: \include MatrixBase_cwiseMin.cpp
+ * Output: \verbinclude MatrixBase_cwiseMin.out
+ *
+ * \sa class CwiseBinaryOp, max()
+ */
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived, const OtherDerived>
+cwiseMin(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
+{
+ return CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
+}
+
+/** \returns an expression of the coefficient-wise min of *this and scalar \a other
+ *
+ * \sa class CwiseBinaryOp, min()
+ */
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived, const ConstantReturnType>
+cwiseMin(const Scalar &other) const
+{
+ return cwiseMin(Derived::Constant(rows(), cols(), other));
+}
+
+/** \returns an expression of the coefficient-wise max of *this and \a other
+ *
+ * Example: \include MatrixBase_cwiseMax.cpp
+ * Output: \verbinclude MatrixBase_cwiseMax.out
+ *
+ * \sa class CwiseBinaryOp, min()
+ */
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived, const OtherDerived>
+cwiseMax(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
+{
+ return CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
+}
+
+/** \returns an expression of the coefficient-wise max of *this and scalar \a other
+ *
+ * \sa class CwiseBinaryOp, min()
+ */
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived, const ConstantReturnType>
+cwiseMax(const Scalar &other) const
+{
+ return cwiseMax(Derived::Constant(rows(), cols(), other));
+}
+
+
+/** \returns an expression of the coefficient-wise quotient of *this and \a other
+ *
+ * Example: \include MatrixBase_cwiseQuotient.cpp
+ * Output: \verbinclude MatrixBase_cwiseQuotient.out
+ *
+ * \sa class CwiseBinaryOp, cwiseProduct(), cwiseInverse()
+ */
+template<typename OtherDerived>
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>
+cwiseQuotient(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
+{
+ return CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
+}
+
+typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar,internal::cmp_EQ>, const Derived, const ConstantReturnType> CwiseScalarEqualReturnType;
+
+/** \returns an expression of the coefficient-wise == operator of \c *this and a scalar \a s
+ *
+ * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
+ * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
+ * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
+ * isMuchSmallerThan().
+ *
+ * \sa cwiseEqual(const MatrixBase<OtherDerived> &) const
+ */
+EIGEN_DEVICE_FUNC
+inline const CwiseScalarEqualReturnType
+cwiseEqual(const Scalar& s) const
+{
+ return CwiseScalarEqualReturnType(derived(), Derived::Constant(rows(), cols(), s), internal::scalar_cmp_op<Scalar,Scalar,internal::cmp_EQ>());
+}
diff --git a/src/3rdparty/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h b/src/3rdparty/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h
new file mode 100644
index 000000000..0514d8f78
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h
@@ -0,0 +1,95 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+// This file is included into the body of the base classes supporting matrix specific coefficient-wise functions.
+// This include MatrixBase and SparseMatrixBase.
+
+
+typedef CwiseUnaryOp<internal::scalar_abs_op<Scalar>, const Derived> CwiseAbsReturnType;
+typedef CwiseUnaryOp<internal::scalar_abs2_op<Scalar>, const Derived> CwiseAbs2ReturnType;
+typedef CwiseUnaryOp<internal::scalar_arg_op<Scalar>, const Derived> CwiseArgReturnType;
+typedef CwiseUnaryOp<internal::scalar_sqrt_op<Scalar>, const Derived> CwiseSqrtReturnType;
+typedef CwiseUnaryOp<internal::scalar_sign_op<Scalar>, const Derived> CwiseSignReturnType;
+typedef CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const Derived> CwiseInverseReturnType;
+
+/// \returns an expression of the coefficient-wise absolute value of \c *this
+///
+/// Example: \include MatrixBase_cwiseAbs.cpp
+/// Output: \verbinclude MatrixBase_cwiseAbs.out
+///
+EIGEN_DOC_UNARY_ADDONS(cwiseAbs,absolute value)
+///
+/// \sa cwiseAbs2()
+///
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseAbsReturnType
+cwiseAbs() const { return CwiseAbsReturnType(derived()); }
+
+/// \returns an expression of the coefficient-wise squared absolute value of \c *this
+///
+/// Example: \include MatrixBase_cwiseAbs2.cpp
+/// Output: \verbinclude MatrixBase_cwiseAbs2.out
+///
+EIGEN_DOC_UNARY_ADDONS(cwiseAbs2,squared absolute value)
+///
+/// \sa cwiseAbs()
+///
+EIGEN_DEVICE_FUNC
+EIGEN_STRONG_INLINE const CwiseAbs2ReturnType
+cwiseAbs2() const { return CwiseAbs2ReturnType(derived()); }
+
+/// \returns an expression of the coefficient-wise square root of *this.
+///
+/// Example: \include MatrixBase_cwiseSqrt.cpp
+/// Output: \verbinclude MatrixBase_cwiseSqrt.out
+///
+EIGEN_DOC_UNARY_ADDONS(cwiseSqrt,square-root)
+///
+/// \sa cwisePow(), cwiseSquare()
+///
+EIGEN_DEVICE_FUNC
+inline const CwiseSqrtReturnType
+cwiseSqrt() const { return CwiseSqrtReturnType(derived()); }
+
+/// \returns an expression of the coefficient-wise signum of *this.
+///
+/// Example: \include MatrixBase_cwiseSign.cpp
+/// Output: \verbinclude MatrixBase_cwiseSign.out
+///
+EIGEN_DOC_UNARY_ADDONS(cwiseSign,sign function)
+///
+EIGEN_DEVICE_FUNC
+inline const CwiseSignReturnType
+cwiseSign() const { return CwiseSignReturnType(derived()); }
+
+
+/// \returns an expression of the coefficient-wise inverse of *this.
+///
+/// Example: \include MatrixBase_cwiseInverse.cpp
+/// Output: \verbinclude MatrixBase_cwiseInverse.out
+///
+EIGEN_DOC_UNARY_ADDONS(cwiseInverse,inverse)
+///
+/// \sa cwiseProduct()
+///
+EIGEN_DEVICE_FUNC
+inline const CwiseInverseReturnType
+cwiseInverse() const { return CwiseInverseReturnType(derived()); }
+
+/// \returns an expression of the coefficient-wise phase angle of \c *this
+///
+/// Example: \include MatrixBase_cwiseArg.cpp
+/// Output: \verbinclude MatrixBase_cwiseArg.out
+///
+EIGEN_DOC_UNARY_ADDONS(cwiseArg,arg)
+
+EIGEN_DEVICE_FUNC
+inline const CwiseArgReturnType
+cwiseArg() const { return CwiseArgReturnType(derived()); }
diff --git a/src/3rdparty/eigen/Eigen/src/plugins/ReshapedMethods.h b/src/3rdparty/eigen/Eigen/src/plugins/ReshapedMethods.h
new file mode 100644
index 000000000..482a6b045
--- /dev/null
+++ b/src/3rdparty/eigen/Eigen/src/plugins/ReshapedMethods.h
@@ -0,0 +1,149 @@
+
+#ifdef EIGEN_PARSED_BY_DOXYGEN
+
+/// \returns an expression of \c *this with reshaped sizes.
+///
+/// \param nRows the number of rows in the reshaped expression, specified at either run-time or compile-time, or AutoSize
+/// \param nCols the number of columns in the reshaped expression, specified at either run-time or compile-time, or AutoSize
+/// \tparam Order specifies whether the coefficients should be processed in column-major-order (ColMajor), in row-major-order (RowMajor),
+/// or follows the \em natural order of the nested expression (AutoOrder). The default is ColMajor.
+/// \tparam NRowsType the type of the value handling the number of rows, typically Index.
+/// \tparam NColsType the type of the value handling the number of columns, typically Index.
+///
+/// Dynamic size example: \include MatrixBase_reshaped_int_int.cpp
+/// Output: \verbinclude MatrixBase_reshaped_int_int.out
+///
+/// The number of rows \a nRows and columns \a nCols can also be specified at compile-time by passing Eigen::fix<N>,
+/// or Eigen::fix<N>(n) as arguments. In the later case, \c n plays the role of a runtime fallback value in case \c N equals Eigen::Dynamic.
+/// Here is an example with a fixed number of rows and columns:
+/// \include MatrixBase_reshaped_fixed.cpp
+/// Output: \verbinclude MatrixBase_reshaped_fixed.out
+///
+/// Finally, one of the sizes parameter can be automatically deduced from the other one by passing AutoSize as in the following example:
+/// \include MatrixBase_reshaped_auto.cpp
+/// Output: \verbinclude MatrixBase_reshaped_auto.out
+/// AutoSize does preserve compile-time sizes when possible, i.e., when the sizes of the input are known at compile time \b and
+/// that the other size is passed at compile-time using Eigen::fix<N> as above.
+///
+/// \sa class Reshaped, fix, fix<N>(int)
+///
+template<int Order = ColMajor, typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC
+inline Reshaped<Derived,...>
+reshaped(NRowsType nRows, NColsType nCols);
+
+/// This is the const version of reshaped(NRowsType,NColsType).
+template<int Order = ColMajor, typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC
+inline const Reshaped<const Derived,...>
+reshaped(NRowsType nRows, NColsType nCols) const;
+
+/// \returns an expression of \c *this with columns (or rows) stacked to a linear column vector
+///
+/// \tparam Order specifies whether the coefficients should be processed in column-major-order (ColMajor), in row-major-order (RowMajor),
+/// or follows the \em natural order of the nested expression (AutoOrder). The default is ColMajor.
+///
+/// This overloads is essentially a shortcut for `A.reshaped<Order>(AutoSize,fix<1>)`.
+///
+/// - If `Order==ColMajor` (the default), then it returns a column-vector from the stacked columns of \c *this.
+/// - If `Order==RowMajor`, then it returns a column-vector from the stacked rows of \c *this.
+/// - If `Order==AutoOrder`, then it returns a column-vector with elements stacked following the storage order of \c *this.
+/// This mode is the recommended one when the particular ordering of the element is not relevant.
+///
+/// Example:
+/// \include MatrixBase_reshaped_to_vector.cpp
+/// Output: \verbinclude MatrixBase_reshaped_to_vector.out
+///
+/// If you want more control, you can still fall back to reshaped(NRowsType,NColsType).
+///
+/// \sa reshaped(NRowsType,NColsType), class Reshaped
+///
+template<int Order = ColMajor>
+EIGEN_DEVICE_FUNC
+inline Reshaped<Derived,...>
+reshaped();
+
+/// This is the const version of reshaped().
+template<int Order = ColMajor>
+EIGEN_DEVICE_FUNC
+inline const Reshaped<const Derived,...>
+reshaped() const;
+
+#else
+
+// This file is automatically included twice to generate const and non-const versions
+
+#ifndef EIGEN_RESHAPED_METHOD_2ND_PASS
+#define EIGEN_RESHAPED_METHOD_CONST const
+#else
+#define EIGEN_RESHAPED_METHOD_CONST
+#endif
+
+#ifndef EIGEN_RESHAPED_METHOD_2ND_PASS
+
+// This part is included once
+
+#endif
+
+template<typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC
+inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived,
+ internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value,
+ internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value>
+reshaped(NRowsType nRows, NColsType nCols) EIGEN_RESHAPED_METHOD_CONST
+{
+ return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived,
+ internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value,
+ internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value>
+ (derived(),
+ internal::get_runtime_reshape_size(nRows,internal::get_runtime_value(nCols),size()),
+ internal::get_runtime_reshape_size(nCols,internal::get_runtime_value(nRows),size()));
+}
+
+template<int Order, typename NRowsType, typename NColsType>
+EIGEN_DEVICE_FUNC
+inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived,
+ internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value,
+ internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value,
+ internal::get_compiletime_reshape_order<Flags,Order>::value>
+reshaped(NRowsType nRows, NColsType nCols) EIGEN_RESHAPED_METHOD_CONST
+{
+ return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived,
+ internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value,
+ internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value,
+ internal::get_compiletime_reshape_order<Flags,Order>::value>
+ (derived(),
+ internal::get_runtime_reshape_size(nRows,internal::get_runtime_value(nCols),size()),
+ internal::get_runtime_reshape_size(nCols,internal::get_runtime_value(nRows),size()));
+}
+
+// Views as linear vectors
+
+EIGEN_DEVICE_FUNC
+inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived,SizeAtCompileTime,1>
+reshaped() EIGEN_RESHAPED_METHOD_CONST
+{
+ return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived,SizeAtCompileTime,1>(derived(),size(),1);
+}
+
+template<int Order>
+EIGEN_DEVICE_FUNC
+inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, SizeAtCompileTime, 1,
+ internal::get_compiletime_reshape_order<Flags,Order>::value>
+reshaped() EIGEN_RESHAPED_METHOD_CONST
+{
+ EIGEN_STATIC_ASSERT(Order==RowMajor || Order==ColMajor || Order==AutoOrder, INVALID_TEMPLATE_PARAMETER);
+ return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, SizeAtCompileTime, 1,
+ internal::get_compiletime_reshape_order<Flags,Order>::value>
+ (derived(), size(), 1);
+}
+
+#undef EIGEN_RESHAPED_METHOD_CONST
+
+#ifndef EIGEN_RESHAPED_METHOD_2ND_PASS
+#define EIGEN_RESHAPED_METHOD_2ND_PASS
+#include "ReshapedMethods.h"
+#undef EIGEN_RESHAPED_METHOD_2ND_PASS
+#endif
+
+#endif // EIGEN_PARSED_BY_DOXYGEN
diff --git a/src/3rdparty/eigen/INSTALL b/src/3rdparty/eigen/INSTALL
new file mode 100644
index 000000000..4f717e9c2
--- /dev/null
+++ b/src/3rdparty/eigen/INSTALL
@@ -0,0 +1,35 @@
+Installation instructions for Eigen
+***********************************
+
+Explanation before starting
+***************************
+
+Eigen consists only of header files, hence there is nothing to compile
+before you can use it. Moreover, these header files do not depend on your
+platform, they are the same for everybody.
+
+Method 1. Installing without using CMake
+****************************************
+
+You can use right away the headers in the Eigen/ subdirectory. In order
+to install, just copy this Eigen/ subdirectory to your favorite location.
+If you also want the unsupported features, copy the unsupported/
+subdirectory too.
+
+Method 2. Installing using CMake
+********************************
+
+Let's call this directory 'source_dir' (where this INSTALL file is).
+Before starting, create another directory which we will call 'build_dir'.
+
+Do:
+
+ cd build_dir
+ cmake source_dir
+ make install
+
+The "make install" step may require administrator privileges.
+
+You can adjust the installation destination (the "prefix")
+by passing the -DCMAKE_INSTALL_PREFIX=myprefix option to cmake, as is
+explained in the message that cmake prints at the end.
diff --git a/src/3rdparty/eigen/README.md b/src/3rdparty/eigen/README.md
new file mode 100644
index 000000000..9b40e9ed4
--- /dev/null
+++ b/src/3rdparty/eigen/README.md
@@ -0,0 +1,5 @@
+**Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms.**
+
+For more information go to http://eigen.tuxfamily.org/.
+
+For ***pull request***, ***bug reports***, and ***feature requests***, go to https://gitlab.com/libeigen/eigen.
diff --git a/src/3rdparty/eigen/qt_attribution.json b/src/3rdparty/eigen/qt_attribution.json
new file mode 100644
index 000000000..866a610b0
--- /dev/null
+++ b/src/3rdparty/eigen/qt_attribution.json
@@ -0,0 +1,20 @@
+{
+ "Id": "eigen",
+ "Name": "Eigen",
+ "QDocModule": "qtspatialaudio",
+ "Description": "The Eigen C++ linear algebra library.",
+ "QtUsage": "Used for mathematics to support spatial audio.",
+ "SecurityCritical": true,
+
+ "Homepage": "https://eigen.tuxfamily.org/",
+ "Version": "3.4.0",
+ "DownloadLocation": "https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.bz2",
+
+ "License": "Mozilla Public License 2.0 and BSD 3-Clause \"New\" or \"Revised\" License",
+ "LicenseId": "MPL-2.0 AND BSD-3-Clause",
+ "CopyrightFile": "COPYRIGHTS",
+ "LicenseFiles": [
+ "COPYING.MPL2",
+ "COPYING.BSD"
+ ]
+}
diff --git a/src/3rdparty/ffmpeg/qt_attribution.json b/src/3rdparty/ffmpeg/qt_attribution.json
new file mode 100644
index 000000000..6e343be65
--- /dev/null
+++ b/src/3rdparty/ffmpeg/qt_attribution.json
@@ -0,0 +1,55 @@
+[
+ {
+ "Id": "ffmpeg",
+ "Name": "FFmpeg",
+ "QDocModule": "qtmultimedia",
+ "Description": "FFmpeg is a collection of libraries and tools to process multimedia content such as audio, video, subtitles, and related metadata.",
+ "QtUsage": "The FFmpeg media backend uses the \\l {https://ffmpeg.org}{FFmpeg framework}. FFmpeg is licensed under LGPLv2.1 or later versions of the licenses. Note that, while FFmpeg also features some optional components available under GPL or LGPLv3, the binaries that ship with Qt in the online installer do not contain these components. See the \\l {https://ffmpeg.org/legal.html}{FFmpeg licensing page} for further details.",
+ "Homepage": "https://ffmpeg.org/",
+ "DownloadLocation": "https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n6.1.1.zip",
+ "SecurityCritical": true,
+ "Version": "n6.1.1",
+ "LicenseId": "LGPL-2.1-or-later AND BSD-3-Clause AND BSD-2-Clause AND BSD-Source-Code AND ISC AND MIT AND MPL-2.0",
+ "License": "GNU Lesser General Public License v2.1 or later and BSD 3-Clause \"New\" or \"Revised\" License and BSD 2-Clause \"Simplified\" License and BSD Source Code Attribution and ISC License and MIT License and Mozilla Public License 2.0",
+ "Copyright": "Copyright (c) 2000-2023 the FFmpeg developers"
+ },
+ {
+ "Id": "ffmpeg-libjpeg",
+ "Name": "libjpeg",
+ "QDocModule": "qtmultimedia",
+ "Description": "libjpeg is a widely used C library for reading and writing JPEG image files.",
+ "QtUsage": "The FFmpeg media backend uses modified code from libjpeg in `libavcodec/jfdctfst.c`, `libavcodec/jfdctint_template.c` and `libavcodec/jrevdct.c`. For list of modifications, see \\l {https://git.ffmpeg.org/ffmpeg.git}{FFmpeg source code management system}.",
+ "SecurityCritical": true,
+ "Homepage": "https://libjpeg.sourceforge.net/",
+ "DownloadLocation": "https://libjpeg.sourceforge.net/",
+ "License": "Independent JPEG Group License",
+ "LicenseId": "IJG",
+ "Copyright": "Copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding."
+ },
+ {
+ "Id": "ffmpeg-zlib",
+ "Name": "zlib",
+ "QDocModule": "qtmultimedia",
+ "Description": "Zlib is a software library used for data compression",
+ "QtUsage": "The FFmpeg media backend uses the Adler-32 algorithm from zlib",
+ "SecurityCritical": false,
+ "Homepage": "https://www.zlib.net/",
+ "DownloadLocation": "https://www.zlib.net/",
+ "License": "zlib License",
+ "LicenseId": "Zlib",
+ "Copyright": "Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler."
+ },
+ {
+ "Id": "ffmpeg-boost",
+ "Name": "boost",
+ "QDocModule": "qtmultimedia",
+ "Description": "Boost is a set of libraries for the C++ programming language ",
+ "QtUsage": "The FFmpeg media backend uses algorithms from the Boost math library",
+ "SecurityCritical": false,
+ "Homepage": "https://www.boost.org/",
+ "DownloadLocation": "https://www.boost.org/",
+ "License": "Boost Software License 1.0",
+ "LicenseId": "BSL-1.0",
+ "Copyright": "(C) Copyright John Maddock 2006. Copyright (c) 2006 Xiaogang Zhang"
+ }
+]
diff --git a/src/3rdparty/pffft/COPYRIGHTS b/src/3rdparty/pffft/COPYRIGHTS
new file mode 100644
index 000000000..1ab374b60
--- /dev/null
+++ b/src/3rdparty/pffft/COPYRIGHTS
@@ -0,0 +1,2 @@
+Copyright (c) 2013 Julien Pommier <pommier@modartt.com>
+Copyright (c) 2004 the University Corporation for Atmospheric Research 'UCAR'
diff --git a/src/3rdparty/pffft/LICENSE b/src/3rdparty/pffft/LICENSE
new file mode 100644
index 000000000..ea8623f35
--- /dev/null
+++ b/src/3rdparty/pffft/LICENSE
@@ -0,0 +1,45 @@
+Copyright (c) 2013 Julien Pommier ( pommier@modartt.com )
+
+Based on original fortran 77 code from FFTPACKv4 from NETLIB,
+authored by Dr Paul Swarztrauber of NCAR, in 1985.
+
+As confirmed by the NCAR fftpack software curators, the following
+FFTPACKv5 license applies to FFTPACKv4 sources. My changes are
+released under the same terms.
+
+FFTPACK license:
+
+http://www.cisl.ucar.edu/css/software/fftpack5/ftpk.html
+
+Copyright (c) 2004 the University Corporation for Atmospheric
+Research ("UCAR"). All rights reserved. Developed by NCAR's
+Computational and Information Systems Laboratory, UCAR,
+www.cisl.ucar.edu.
+
+Redistribution and use of the Software in source and binary forms,
+with or without modification, is permitted provided that the
+following conditions are met:
+
+- Neither the names of NCAR's Computational and Information Systems
+Laboratory, the University Corporation for Atmospheric Research,
+nor the names of its sponsors or contributors may be used to
+endorse or promote products derived from this Software without
+specific prior written permission.
+
+- Redistributions of source code must retain the above copyright
+notices, this list of conditions, and the disclaimer below.
+
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions, and the disclaimer below in the
+documentation and/or other materials provided with the
+distribution.
+
+THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+SOFTWARE.
diff --git a/src/3rdparty/pffft/README.md b/src/3rdparty/pffft/README.md
new file mode 100644
index 000000000..5f741aa6f
--- /dev/null
+++ b/src/3rdparty/pffft/README.md
@@ -0,0 +1,320 @@
+PFFFT: a pretty fast FFT.
+
+## TL;DR
+
+PFFFT does 1D Fast Fourier Transforms, of single precision real and
+complex vectors. It tries do it fast, it tries to be correct, and it
+tries to be small. Computations do take advantage of SSE1 instructions
+on x86 cpus, Altivec on powerpc cpus, and NEON on ARM cpus. The
+license is BSD-like.
+
+
+## Why does it exist:
+
+I was in search of a good performing FFT library , preferably very
+small and with a very liberal license.
+
+When one says "fft library", FFTW ("Fastest Fourier Transform in the
+West") is probably the first name that comes to mind -- I guess that
+99% of open-source projects that need a FFT do use FFTW, and are happy
+with it. However, it is quite a large library , which does everything
+fft related (2d transforms, 3d transforms, other transformations such
+as discrete cosine , or fast hartley). And it is licensed under the
+GNU GPL , which means that it cannot be used in non open-source
+products.
+
+An alternative to FFTW that is really small, is the venerable FFTPACK
+v4, which is available on NETLIB. A more recent version (v5) exists,
+but it is larger as it deals with multi-dimensional transforms. This
+is a library that is written in FORTRAN 77, a language that is now
+considered as a bit antiquated by many. FFTPACKv4 was written in 1985,
+by Dr Paul Swarztrauber of NCAR, more than 25 years ago ! And despite
+its age, benchmarks show it that it still a very good performing FFT
+library, see for example the 1d single precision benchmarks here:
+http://www.fftw.org/speed/opteron-2.2GHz-32bit/ . It is however not
+competitive with the fastest ones, such as FFTW, Intel MKL, AMD ACML,
+Apple vDSP. The reason for that is that those libraries do take
+advantage of the SSE SIMD instructions available on Intel CPUs,
+available since the days of the Pentium III. These instructions deal
+with small vectors of 4 floats at a time, instead of a single float
+for a traditionnal FPU, so when using these instructions one may expect
+a 4-fold performance improvement.
+
+The idea was to take this fortran fftpack v4 code, translate to C,
+modify it to deal with those SSE instructions, and check that the
+final performance is not completely ridiculous when compared to other
+SIMD FFT libraries. Translation to C was performed with f2c (
+http://www.netlib.org/f2c/ ). The resulting file was a bit edited in
+order to remove the thousands of gotos that were introduced by
+f2c. You will find the fftpack.h and fftpack.c sources in the
+repository, this a complete translation of
+http://www.netlib.org/fftpack/ , with the discrete cosine transform
+and the test program. There is no license information in the netlib
+repository, but it was confirmed to me by the fftpack v5 curators that
+the same terms do apply to fftpack v4:
+http://www.cisl.ucar.edu/css/software/fftpack5/ftpk.html . This is a
+"BSD-like" license, it is compatible with proprietary projects.
+
+Adapting fftpack to deal with the SIMD 4-element vectors instead of
+scalar single precision numbers was more complex than I originally
+thought, especially with the real transforms, and I ended up writing
+more code than I planned..
+
+
+## The code:
+
+Only two files, in good old C, pffft.c and pffft.h . The API is very
+very simple, just make sure that you read the comments in pffft.h.
+
+
+## Comparison with other FFTs:
+
+The idea was not to break speed records, but to get a decently fast
+fft that is at least 50% as fast as the fastest FFT -- especially on
+slowest computers . I'm more focused on getting the best performance
+on slow cpus (Atom, Intel Core 1, old Athlons, ARM Cortex-A9...), than
+on getting top performance on today fastest cpus.
+
+It can be used in a real-time context as the fft functions do not
+perform any memory allocation -- that is why they accept a 'work'
+array in their arguments.
+
+It is also a bit focused on performing 1D convolutions, that is why it
+provides "unordered" FFTs , and a fourier domain convolution
+operation.
+
+
+Benchmark results
+--
+
+The benchmark shows the performance of various fft implementations measured in
+MFlops, with the number of floating point operations being defined as 5Nlog2(N)
+for a length N complex fft, and 2.5*Nlog2(N) for a real fft.
+See http://www.fftw.org/speed/method.html for an explanation of these formulas.
+
+2021 update: I'm now including Intel MKL, and I'm removing old benchmarks results for cpu that have
+not been relevant for a very long time.. Now that most Intel cpus have AVX enabled (most but not
+all, Intel is still selling cpus with no AVX), the performance of pffft vs MKL or VDSP is a bit
+behind since pffft is only SSE2.
+
+However, performance of pffft on the Apple M1 cpu is very good (especially for the real fft), so I'll put it first :-)
+
+
+MacOS Big Sur, XCode 12, M1 cpu on a 2020 mac mini. I'm not including fftw results as they are very
+bad here, most likely Homebrew did not enable neon when building the lib.
+
+ clang -o test_pffft -DHAVE_VECLIB -O3 -Wall -W pffft.c test_pffft.c fftpack.c -framework Accelerate
+
+| input len |real FFTPack| real vDSP | real PFFFT |cplx FFTPack| cplx vDSP | cplx PFFFT |
+|-----------:|-----------:|-----------:|-----------:|-----------:|-----------:|-----------:|
+| 64 | 4835 | 15687 | 23704 | 12935 | 36222 | 33046 |
+| 96 | 9539 | n/a | 25957 | 11068 | n/a | 32703 |
+| 128 | 11119 | 33087 | 30143 | 12329 | 50866 | 36363 |
+| 160 | 11062 | n/a | 32938 | 11641 | n/a | 34945 |
+| 192 | 11784 | n/a | 35726 | 12945 | n/a | 39258 |
+| 256 | 13370 | 44880 | 40683 | 14214 | 64654 | 42522 |
+| 384 | 11059 | n/a | 40038 | 11655 | n/a | 39565 |
+| 480 | 10977 | n/a | 40895 | 10802 | n/a | 36943 |
+| 512 | 12197 | 34830 | 43353 | 12357 | 78441 | 41450 |
+| 640 | 11685 | n/a | 43393 | 11775 | n/a | 39302 |
+| 768 | 12314 | n/a | 45836 | 12756 | n/a | 43058 |
+| 800 | 11213 | n/a | 41321 | 10842 | n/a | 37382 |
+| 1024 | 13354 | 45214 | 50039 | 13759 | 93269 | 45210 |
+| 2048 | 12806 | 57047 | 49519 | 12908 | 99361 | 43719 |
+| 2400 | 10972 | n/a | 43399 | 10928 | n/a | 37574 |
+| 4096 | 13957 | 65233 | 52845 | 13851 | 105734 | 46274 |
+| 8192 | 12772 | 70108 | 49830 | 12560 | 85238 | 40252 |
+| 9216 | 12281 | n/a | 48929 | 12114 | n/a | 39202 |
+| 16384 | 13363 | 62150 | 48260 | 12910 | 79073 | 38742 |
+| 32768 | 11622 | 60809 | 32801 | 11145 | 71570 | 35607 |
+| 262144 | 11525 | 53651 | 34988 | 10818 | 63198 | 36742 |
+| 1048576 | 11167 | 46119 | 34437 | 9202 | 38823 | 31788 |
+
+So yes, the perf of the M1 cpu on the complex is really impressive...
+
+Windows 10, Ryzen 7 4800HS @ 2.9GHz, Visual c++ 2019 and Intel MKL 2018
+
+Build with:
+
+ cl /Ox -D_USE_MATH_DEFINES -DHAVE_MKL /arch:SSE test_pffft.c pffft.c fftpack.c /I c:/MKL/include c:/MKL/lib/intel64/mkl_intel_lp64.lib c:/MKL/lib/intel64/mkl_sequential.lib c:/MKL/lib/intel64/mkl_core.lib
+
+| input len |real FFTPack| real MKL | real PFFFT |cplx FFTPack| cplx MKL | cplx PFFFT |
+|-----------:|-----------:|-----------:|-----------:|-----------:|-----------:|-----------:|
+| 64 | 3938 | 7877 | 14629 | 7314 | 25600 | 19200 |
+| 96 | 5108 | 14984 | 13761 | 7329 | 20128 | 20748 |
+| 128 | 5973 | 18379 | 19911 | 7626 | 29257 | 23123 |
+| 160 | 6694 | 18287 | 19731 | 7976 | 22720 | 21120 |
+| 192 | 6472 | 16525 | 20439 | 6813 | 27252 | 25054 |
+| 256 | 7585 | 23406 | 25600 | 8715 | 33437 | 26006 |
+| 384 | 6279 | 21441 | 23759 | 7206 | 25855 | 25481 |
+| 480 | 6514 | 20267 | 22800 | 7238 | 26435 | 21976 |
+| 512 | 6776 | 26332 | 29729 | 6312 | 34777 | 25961 |
+| 640 | 7019 | 21695 | 27273 | 7232 | 26889 | 25120 |
+| 768 | 6815 | 21809 | 28865 | 7667 | 31658 | 27645 |
+| 800 | 7261 | 23513 | 25988 | 6764 | 27056 | 25001 |
+| 1024 | 7529 | 30118 | 31030 | 8127 | 38641 | 28055 |
+| 2048 | 7411 | 31289 | 33129 | 8533 | 38841 | 27812 |
+| 2400 | 7768 | 22993 | 26128 | 7563 | 26429 | 24992 |
+| 4096 | 8533 | 33211 | 34134 | 8777 | 38400 | 27007 |
+| 8192 | 6525 | 32468 | 30254 | 7924 | 39737 | 28025 |
+| 9216 | 7322 | 22835 | 28068 | 7322 | 29939 | 26945 |
+| 16384 | 7455 | 31807 | 30453 | 8132 | 37177 | 27525 |
+| 32768 | 8157 | 31949 | 30671 | 8334 | 29210 | 26214 |
+| 262144 | 7349 | 25255 | 24904 | 6844 | 22413 | 16996 |
+| 1048576 | 5115 | 19284 | 8347 | 6079 | 12906 | 9244 |
+
+(Note: MKL is not using AVX on AMD cpus)
+
+
+MacOS Catalina, Xcode 12, fftw 3.3.9 and MKL 2020.1, cpu is "i7-6920HQ CPU @ 2.90GHz"
+
+Built with:
+
+ clang -o test_pffft -DHAVE_MKL -I /opt/intel/mkl/include -DHAVE_FFTW -DHAVE_VECLIB -O3 -Wall -W pffft.c test_pffft.c fftpack.c -L/usr/local/lib -I/usr/local/include/ -lfftw3f -framework Accelerate /opt/intel/mkl/lib/libmkl_{intel_lp64,sequential,core}.
+
+| input len |real FFTPack| real vDSP | real MKL | real FFTW | real PFFFT |cplx FFTPack| cplx vDSP | cplx MKL | cplx FFTW | cplx PFFFT |
+|------------|------------|------------|------------|------------|------------|------------|------------|------------|------------|------------|
+| 64 | 4528 | 12550 | 18214 | 8237 | 10097 | 5962 | 25748 | 40865 | 32233 | 15807 |
+| 96 | 4738 | n/a | 15844 | 10749 | 11026 | 5344 | n/a | 21086 | 34678 | 15493 |
+| 128 | 5464 | 20419 | 25739 | 12371 | 13338 | 6060 | 28659 | 42419 | 38868 | 17694 |
+| 160 | 5517 | n/a | 18644 | 12361 | 13765 | 6002 | n/a | 21633 | 37726 | 17969 |
+| 192 | 5904 | n/a | 18861 | 12480 | 15134 | 6271 | n/a | 26074 | 33216 | 18525 |
+| 256 | 6618 | 24944 | 26063 | 14646 | 16895 | 6965 | 34332 | 52182 | 44496 | 20980 |
+| 384 | 5685 | n/a | 22307 | 14682 | 16969 | 5853 | n/a | 27363 | 35805 | 19841 |
+| 480 | 5757 | n/a | 21122 | 14572 | 16765 | 5836 | n/a | 26259 | 26340 | 18852 |
+| 512 | 6245 | 28100 | 27224 | 16546 | 18502 | 6240 | 37098 | 51679 | 43444 | 21519 |
+| 640 | 6110 | n/a | 22565 | 14691 | 18573 | 6376 | n/a | 29219 | 34327 | 20708 |
+| 768 | 6424 | n/a | 21496 | 15999 | 19900 | 6358 | n/a | 30168 | 36437 | 21657 |
+| 800 | 5747 | n/a | 24857 | 15068 | 18842 | 5698 | n/a | 26891 | 20249 | 18497 |
+| 1024 | 6397 | 28477 | 27520 | 13399 | 18491 | 5558 | 33632 | 44366 | 35960 | 23421 |
+| 2048 | 6563 | 37379 | 34743 | 14204 | 20854 | 5828 | 41758 | 40301 | 36469 | 18504 |
+| 2400 | 5594 | n/a | 24631 | 15496 | 16732 | 4128 | n/a | 16997 | 23421 | 16710 |
+| 4096 | 6262 | 36417 | 28150 | 17742 | 19356 | 6272 | 33534 | 31632 | 33524 | 16995 |
+| 8192 | 4142 | 24923 | 26571 | 17102 | 10104 | 5681 | 29504 | 33221 | 21803 | 15212 |
+| 9216 | 5762 | n/a | 17305 | 14870 | 14464 | 5781 | n/a | 21579 | 22174 | 17358 |
+| 16384 | 5650 | 29395 | 27201 | 15857 | 11748 | 5932 | 26534 | 31708 | 21161 | 16173 |
+| 32768 | 5441 | 23931 | 26261 | 15394 | 10334 | 5679 | 23278 | 31162 | 19966 | 14624 |
+| 262144 | 4946 | 19081 | 23591 | 9612 | 9544 | 4958 | 16362 | 20196 | 10419 | 12575 |
+| 1048576 | 3752 | 14873 | 15469 | 6673 | 6653 | 4048 | 9563 | 16681 | 4298 | 7852 |
+
+
+MacOS Lion, gcc 4.2, 64-bit, fftw 3.3 on a 3.4 GHz core i7 2600
+
+Built with:
+
+ gcc-4.2 -o test_pffft -arch x86_64 -O3 -Wall -W pffft.c test_pffft.c fftpack.c -L/usr/local/lib -I/usr/local/include/ -DHAVE_VECLIB -framework veclib -DHAVE_FFTW -lfftw3f
+
+| input len |real FFTPack| real vDSP | real FFTW | real PFFFT |cplx FFTPack| cplx vDSP | cplx FFTW | cplx PFFFT |
+|----------:|-----------:|-----------:|-----------:|-----------:|-----------:|-----------:|-----------:|-----------:|
+| 64 | 2816 | 8596 | 7329 | 8187 | 2887 | 14898 | 14668 | 11108 |
+| 96 | 3298 | n/a | 8378 | 7727 | 3953 | n/a | 15680 | 10878 |
+| 128 | 3507 | 11575 | 9266 | 10108 | 4233 | 17598 | 16427 | 12000 |
+| 160 | 3391 | n/a | 9838 | 10711 | 4220 | n/a | 16653 | 11187 |
+| 192 | 3919 | n/a | 9868 | 10956 | 4297 | n/a | 15770 | 12540 |
+| 256 | 4283 | 13179 | 10694 | 13128 | 4545 | 19550 | 16350 | 13822 |
+| 384 | 3136 | n/a | 10810 | 12061 | 3600 | n/a | 16103 | 13240 |
+| 480 | 3477 | n/a | 10632 | 12074 | 3536 | n/a | 11630 | 12522 |
+| 512 | 3783 | 15141 | 11267 | 13838 | 3649 | 20002 | 16560 | 13580 |
+| 640 | 3639 | n/a | 11164 | 13946 | 3695 | n/a | 15416 | 13890 |
+| 768 | 3800 | n/a | 11245 | 13495 | 3590 | n/a | 15802 | 14552 |
+| 800 | 3440 | n/a | 10499 | 13301 | 3659 | n/a | 12056 | 13268 |
+| 1024 | 3924 | 15605 | 11450 | 15339 | 3769 | 20963 | 13941 | 15467 |
+| 2048 | 4518 | 16195 | 11551 | 15532 | 4258 | 20413 | 13723 | 15042 |
+| 2400 | 4294 | n/a | 10685 | 13078 | 4093 | n/a | 12777 | 13119 |
+| 4096 | 4750 | 16596 | 11672 | 15817 | 4157 | 19662 | 14316 | 14336 |
+| 8192 | 3820 | 16227 | 11084 | 12555 | 3691 | 18132 | 12102 | 13813 |
+| 9216 | 3864 | n/a | 10254 | 12870 | 3586 | n/a | 12119 | 13994 |
+| 16384 | 3822 | 15123 | 10454 | 12822 | 3613 | 16874 | 12370 | 13881 |
+| 32768 | 4175 | 14512 | 10662 | 11095 | 3881 | 14702 | 11619 | 11524 |
+| 262144 | 3317 | 11429 | 6269 | 9517 | 2810 | 11729 | 7757 | 10179 |
+| 1048576 | 2913 | 10551 | 4730 | 5867 | 2661 | 7881 | 3520 | 5350 |
+
+
+Ubuntu 11.04, gcc 4.5, 32-bit, fftw 3.2 on a 2.66 core 2 quad
+
+Built with:
+
+ gcc -o test_pffft -DHAVE_FFTW -msse -mfpmath=sse -O3 -Wall -W pffft.c test_pffft.c fftpack.c -L/usr/local/lib -I/usr/local/include/ -lfftw3f -lm
+
+| input len |real FFTPack| real FFTW | real PFFFT |cplx FFTPack| cplx FFTW | cplx PFFFT |
+|----------:|-----------:|-----------:|-----------:|-----------:|-----------:|-----------:|
+| 64 | 1920 | 3614 | 5120 | 2194 | 7680 | 6467 |
+| 96 | 1873 | 3549 | 5187 | 2107 | 8429 | 5863 |
+| 128 | 2240 | 3773 | 5514 | 2560 | 7964 | 6827 |
+| 192 | 1765 | 4569 | 7767 | 2284 | 9137 | 7061 |
+| 256 | 2048 | 5461 | 7447 | 2731 | 9638 | 7802 |
+| 384 | 1998 | 5861 | 6762 | 2313 | 9253 | 7644 |
+| 512 | 2095 | 6144 | 7680 | 2194 | 10240 | 7089 |
+| 768 | 2230 | 5773 | 7549 | 2045 | 10331 | 7010 |
+| 1024 | 2133 | 6400 | 8533 | 2133 | 10779 | 7877 |
+| 2048 | 2011 | 7040 | 8665 | 1942 | 10240 | 7768 |
+| 4096 | 2194 | 6827 | 8777 | 1755 | 9452 | 6827 |
+| 8192 | 1849 | 6656 | 6656 | 1752 | 7831 | 6827 |
+| 9216 | 1871 | 5858 | 6416 | 1643 | 6909 | 6266 |
+| 16384 | 1883 | 6223 | 6506 | 1664 | 7340 | 6982 |
+| 32768 | 1826 | 6390 | 6667 | 1631 | 7481 | 6971 |
+| 262144 | 1546 | 4075 | 5977 | 1299 | 3415 | 3551 |
+| 1048576 | 1104 | 2071 | 1730 | 1104 | 1149 | 1834 |
+
+
+NVIDIA Jetson TK1 board, gcc-4.8.2. The cpu is a 2.3GHz cortex A15 (Tegra K1).
+
+Built with:
+
+ gcc -O3 -march=armv7-a -mtune=native -mfloat-abi=hard -mfpu=neon -ffast-math test_pffft.c pffft.c -o test_pffft_arm fftpack.c -lm
+
+| input len |real FFTPack| real PFFFT |cplx FFTPack| cplx PFFFT |
+|----------:|-----------:|-----------:|-----------:|-----------:|
+| 64 | 1735 | 3308 | 1994 | 3744 |
+| 96 | 1596 | 3448 | 1987 | 3572 |
+| 128 | 1807 | 4076 | 2255 | 3960 |
+| 160 | 1769 | 4083 | 2071 | 3845 |
+| 192 | 1990 | 4233 | 2017 | 3939 |
+| 256 | 2191 | 4882 | 2254 | 4346 |
+| 384 | 1878 | 4492 | 2073 | 4012 |
+| 480 | 1748 | 4398 | 1923 | 3951 |
+| 512 | 2030 | 5064 | 2267 | 4195 |
+| 640 | 1918 | 4756 | 2094 | 4184 |
+| 768 | 2099 | 4907 | 2048 | 4297 |
+| 800 | 1822 | 4555 | 1880 | 4063 |
+| 1024 | 2232 | 5355 | 2187 | 4420 |
+| 2048 | 2176 | 4983 | 2027 | 3602 |
+| 2400 | 1741 | 4256 | 1710 | 3344 |
+| 4096 | 1816 | 3914 | 1851 | 3349 |
+| 8192 | 1716 | 3481 | 1700 | 3255 |
+| 9216 | 1735 | 3589 | 1653 | 3094 |
+| 16384 | 1567 | 3483 | 1637 | 3244 |
+| 32768 | 1624 | 3240 | 1655 | 3156 |
+| 262144 | 1012 | 1898 | 983 | 1503 |
+| 1048576 | 876 | 1154 | 868 | 1341 |
+
+
+iPad Air 2 with iOS9, xcode 8.0, arm64. The cpu is an Apple A8X, supposedly running at 1.5GHz.
+
+| input len |real FFTPack| real vDSP | real PFFFT |cplx FFTPack| cplx vDSP | cplx PFFFT |
+|----------:|-----------:|-----------:|-----------:|-----------:|-----------:|-----------:|
+| 64 | 2517 | 7995 | 6086 | 2725 | 13006 | 8495 |
+| 96 | 2442 | n/a | 6691 | 2256 | n/a | 7991 |
+| 128 | 2664 | 10186 | 7877 | 2575 | 15115 | 9115 |
+| 160 | 2638 | n/a | 8283 | 2682 | n/a | 8806 |
+| 192 | 2903 | n/a | 9083 | 2634 | n/a | 8980 |
+| 256 | 3184 | 11452 | 10039 | 3026 | 15410 | 10199 |
+| 384 | 2665 | n/a | 10100 | 2275 | n/a | 9247 |
+| 480 | 2546 | n/a | 9863 | 2341 | n/a | 8892 |
+| 512 | 2832 | 12197 | 10989 | 2547 | 16768 | 10154 |
+| 640 | 2755 | n/a | 10461 | 2569 | n/a | 9666 |
+| 768 | 2998 | n/a | 11355 | 2585 | n/a | 9813 |
+| 800 | 2516 | n/a | 10332 | 2433 | n/a | 9164 |
+| 1024 | 3109 | 12965 | 12114 | 2869 | 16448 | 10519 |
+| 2048 | 3027 | 12996 | 12023 | 2648 | 17304 | 10307 |
+| 2400 | 2515 | n/a | 10372 | 2355 | n/a | 8443 |
+| 4096 | 3204 | 13603 | 12359 | 2814 | 16570 | 9780 |
+| 8192 | 2759 | 13422 | 10824 | 2153 | 15652 | 7884 |
+| 9216 | 2700 | n/a | 9938 | 2241 | n/a | 7900 |
+| 16384 | 2280 | 13057 | 7976 | 593 | 4272 | 2534 |
+| 32768 | 768 | 4269 | 2882 | 606 | 4405 | 2604 |
+| 262144 | 724 | 3527 | 2630 | 534 | 2418 | 2157 |
+| 1048576 | 674 | 1467 | 2135 | 530 | 1621 | 2055 |
+
+
+
diff --git a/src/3rdparty/pffft/fftpack.c b/src/3rdparty/pffft/fftpack.c
new file mode 100644
index 000000000..aa8135a50
--- /dev/null
+++ b/src/3rdparty/pffft/fftpack.c
@@ -0,0 +1,3111 @@
+/*
+ compile with cc -DTESTING_FFTPACK fftpack.c in order to build the
+ test application.
+
+ This is an f2c translation of the full fftpack sources as found on
+ http://www.netlib.org/fftpack/ The translated code has been
+ slightlty edited to remove the ugliest artefacts of the translation
+ (a hundred of wild GOTOs were wiped during that operation).
+
+ The original fftpack file was written by Paul N. Swarztrauber
+ (Version 4, 1985), in fortran 77.
+
+ FFTPACK license:
+
+ http://www.cisl.ucar.edu/css/software/fftpack5/ftpk.html
+
+ Copyright (c) 2004 the University Corporation for Atmospheric
+ Research ("UCAR"). All rights reserved. Developed by NCAR's
+ Computational and Information Systems Laboratory, UCAR,
+ www.cisl.ucar.edu.
+
+ Redistribution and use of the Software in source and binary forms,
+ with or without modification, is permitted provided that the
+ following conditions are met:
+
+ - Neither the names of NCAR's Computational and Information Systems
+ Laboratory, the University Corporation for Atmospheric Research,
+ nor the names of its sponsors or contributors may be used to
+ endorse or promote products derived from this Software without
+ specific prior written permission.
+
+ - Redistributions of source code must retain the above copyright
+ notices, this list of conditions, and the disclaimer below.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions, and the disclaimer below in the
+ documentation and/or other materials provided with the
+ distribution.
+
+ THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+ SOFTWARE.
+
+ ChangeLog:
+ 2011/10/02: this is my first release of this file.
+*/
+
+#include "fftpack.h"
+#include <math.h>
+
+typedef fftpack_real real;
+typedef fftpack_int integer;
+
+typedef struct f77complex {
+ real r, i;
+} f77complex;
+
+#ifdef TESTING_FFTPACK
+static real c_abs(f77complex *c) { return sqrt(c->r*c->r + c->i*c->i); }
+static double dmax(double a, double b) { return a < b ? b : a; }
+#endif
+
+/* translated by f2c (version 20061008), and slightly edited */
+
+static void passfb(integer *nac, integer ido, integer ip, integer l1, integer idl1,
+ real *cc, real *c1, real *c2, real *ch, real *ch2, const real *wa, real fsign)
+{
+ /* System generated locals */
+ integer ch_offset, cc_offset,
+ c1_offset, c2_offset, ch2_offset;
+
+ /* Local variables */
+ integer i, j, k, l, jc, lc, ik, idj, idl, inc, idp;
+ real wai, war;
+ integer ipp2, idij, idlj, idot, ipph;
+
+
+#define c1_ref(a_1,a_2,a_3) c1[((a_3)*l1 + (a_2))*ido + a_1]
+#define c2_ref(a_1,a_2) c2[(a_2)*idl1 + a_1]
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*ip + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+#define ch2_ref(a_1,a_2) ch2[(a_2)*idl1 + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ c1_offset = 1 + ido * (1 + l1);
+ c1 -= c1_offset;
+ cc_offset = 1 + ido * (1 + ip);
+ cc -= cc_offset;
+ ch2_offset = 1 + idl1;
+ ch2 -= ch2_offset;
+ c2_offset = 1 + idl1;
+ c2 -= c2_offset;
+ --wa;
+
+ /* Function Body */
+ idot = ido / 2;
+ ipp2 = ip + 2;
+ ipph = (ip + 1) / 2;
+ idp = ip * ido;
+
+ if (ido >= l1) {
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 1; i <= ido; ++i) {
+ ch_ref(i, k, j) = cc_ref(i, j, k) + cc_ref(i, jc, k);
+ ch_ref(i, k, jc) = cc_ref(i, j, k) - cc_ref(i, jc, k);
+ }
+ }
+ }
+ for (k = 1; k <= l1; ++k) {
+ for (i = 1; i <= ido; ++i) {
+ ch_ref(i, k, 1) = cc_ref(i, 1, k);
+ }
+ }
+ } else {
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ for (i = 1; i <= ido; ++i) {
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(i, k, j) = cc_ref(i, j, k) + cc_ref(i, jc, k);
+ ch_ref(i, k, jc) = cc_ref(i, j, k) - cc_ref(i, jc, k);
+ }
+ }
+ }
+ for (i = 1; i <= ido; ++i) {
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(i, k, 1) = cc_ref(i, 1, k);
+ }
+ }
+ }
+ idl = 2 - ido;
+ inc = 0;
+ for (l = 2; l <= ipph; ++l) {
+ lc = ipp2 - l;
+ idl += ido;
+ for (ik = 1; ik <= idl1; ++ik) {
+ c2_ref(ik, l) = ch2_ref(ik, 1) + wa[idl - 1] * ch2_ref(ik, 2);
+ c2_ref(ik, lc) = fsign*wa[idl] * ch2_ref(ik, ip);
+ }
+ idlj = idl;
+ inc += ido;
+ for (j = 3; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ idlj += inc;
+ if (idlj > idp) {
+ idlj -= idp;
+ }
+ war = wa[idlj - 1];
+ wai = wa[idlj];
+ for (ik = 1; ik <= idl1; ++ik) {
+ c2_ref(ik, l) = c2_ref(ik, l) + war * ch2_ref(ik, j);
+ c2_ref(ik, lc) = c2_ref(ik, lc) + fsign*wai * ch2_ref(ik, jc);
+ }
+ }
+ }
+ for (j = 2; j <= ipph; ++j) {
+ for (ik = 1; ik <= idl1; ++ik) {
+ ch2_ref(ik, 1) = ch2_ref(ik, 1) + ch2_ref(ik, j);
+ }
+ }
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ for (ik = 2; ik <= idl1; ik += 2) {
+ ch2_ref(ik - 1, j) = c2_ref(ik - 1, j) - c2_ref(ik, jc);
+ ch2_ref(ik - 1, jc) = c2_ref(ik - 1, j) + c2_ref(ik, jc);
+ ch2_ref(ik, j) = c2_ref(ik, j) + c2_ref(ik - 1, jc);
+ ch2_ref(ik, jc) = c2_ref(ik, j) - c2_ref(ik - 1, jc);
+ }
+ }
+ *nac = 1;
+ if (ido == 2) {
+ return;
+ }
+ *nac = 0;
+ for (ik = 1; ik <= idl1; ++ik) {
+ c2_ref(ik, 1) = ch2_ref(ik, 1);
+ }
+ for (j = 2; j <= ip; ++j) {
+ for (k = 1; k <= l1; ++k) {
+ c1_ref(1, k, j) = ch_ref(1, k, j);
+ c1_ref(2, k, j) = ch_ref(2, k, j);
+ }
+ }
+ if (idot <= l1) {
+ idij = 0;
+ for (j = 2; j <= ip; ++j) {
+ idij += 2;
+ for (i = 4; i <= ido; i += 2) {
+ idij += 2;
+ for (k = 1; k <= l1; ++k) {
+ c1_ref(i - 1, k, j) = wa[idij - 1] * ch_ref(i - 1, k, j) - fsign*wa[idij] * ch_ref(i, k, j);
+ c1_ref(i, k, j) = wa[idij - 1] * ch_ref(i, k, j) + fsign*wa[idij] * ch_ref(i - 1, k, j);
+ }
+ }
+ }
+ return;
+ }
+ idj = 2 - ido;
+ for (j = 2; j <= ip; ++j) {
+ idj += ido;
+ for (k = 1; k <= l1; ++k) {
+ idij = idj;
+ for (i = 4; i <= ido; i += 2) {
+ idij += 2;
+ c1_ref(i - 1, k, j) = wa[idij - 1] * ch_ref(i - 1, k, j) - fsign*wa[idij] * ch_ref(i, k, j);
+ c1_ref(i, k, j) = wa[idij - 1] * ch_ref(i, k, j) + fsign*wa[idij] * ch_ref(i - 1, k, j);
+ }
+ }
+ }
+} /* passb */
+
+#undef ch2_ref
+#undef ch_ref
+#undef cc_ref
+#undef c2_ref
+#undef c1_ref
+
+
+static void passb2(integer ido, integer l1, const real *cc, real *ch, const real *wa1)
+{
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k;
+ real ti2, tr2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*2 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + ido * 3;
+ cc -= cc_offset;
+ --wa1;
+
+ /* Function Body */
+ if (ido <= 2) {
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(1, k, 1) = cc_ref(1, 1, k) + cc_ref(1, 2, k);
+ ch_ref(1, k, 2) = cc_ref(1, 1, k) - cc_ref(1, 2, k);
+ ch_ref(2, k, 1) = cc_ref(2, 1, k) + cc_ref(2, 2, k);
+ ch_ref(2, k, 2) = cc_ref(2, 1, k) - cc_ref(2, 2, k);
+ }
+ return;
+ }
+ for (k = 1; k <= l1; ++k) {
+ for (i = 2; i <= ido; i += 2) {
+ ch_ref(i - 1, k, 1) = cc_ref(i - 1, 1, k) + cc_ref(i - 1, 2, k);
+ tr2 = cc_ref(i - 1, 1, k) - cc_ref(i - 1, 2, k);
+ ch_ref(i, k, 1) = cc_ref(i, 1, k) + cc_ref(i, 2, k);
+ ti2 = cc_ref(i, 1, k) - cc_ref(i, 2, k);
+ ch_ref(i, k, 2) = wa1[i - 1] * ti2 + wa1[i] * tr2;
+ ch_ref(i - 1, k, 2) = wa1[i - 1] * tr2 - wa1[i] * ti2;
+ }
+ }
+} /* passb2 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void passb3(integer ido, integer l1, const real *cc, real *ch, const real *wa1, const real *wa2)
+{
+ static const real taur = -.5;
+ static const real taui = .866025403784439;
+
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k;
+ real ci2, ci3, di2, di3, cr2, cr3, dr2, dr3, ti2, tr2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*3 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + (ido << 2);
+ cc -= cc_offset;
+ --wa1;
+ --wa2;
+
+ /* Function Body */
+ if (ido == 2) {
+ for (k = 1; k <= l1; ++k) {
+ tr2 = cc_ref(1, 2, k) + cc_ref(1, 3, k);
+ cr2 = cc_ref(1, 1, k) + taur * tr2;
+ ch_ref(1, k, 1) = cc_ref(1, 1, k) + tr2;
+ ti2 = cc_ref(2, 2, k) + cc_ref(2, 3, k);
+ ci2 = cc_ref(2, 1, k) + taur * ti2;
+ ch_ref(2, k, 1) = cc_ref(2, 1, k) + ti2;
+ cr3 = taui * (cc_ref(1, 2, k) - cc_ref(1, 3, k));
+ ci3 = taui * (cc_ref(2, 2, k) - cc_ref(2, 3, k));
+ ch_ref(1, k, 2) = cr2 - ci3;
+ ch_ref(1, k, 3) = cr2 + ci3;
+ ch_ref(2, k, 2) = ci2 + cr3;
+ ch_ref(2, k, 3) = ci2 - cr3;
+ }
+ } else {
+ for (k = 1; k <= l1; ++k) {
+ for (i = 2; i <= ido; i += 2) {
+ tr2 = cc_ref(i - 1, 2, k) + cc_ref(i - 1, 3, k);
+ cr2 = cc_ref(i - 1, 1, k) + taur * tr2;
+ ch_ref(i - 1, k, 1) = cc_ref(i - 1, 1, k) + tr2;
+ ti2 = cc_ref(i, 2, k) + cc_ref(i, 3, k);
+ ci2 = cc_ref(i, 1, k) + taur * ti2;
+ ch_ref(i, k, 1) = cc_ref(i, 1, k) + ti2;
+ cr3 = taui * (cc_ref(i - 1, 2, k) - cc_ref(i - 1, 3, k));
+ ci3 = taui * (cc_ref(i, 2, k) - cc_ref(i, 3, k));
+ dr2 = cr2 - ci3;
+ dr3 = cr2 + ci3;
+ di2 = ci2 + cr3;
+ di3 = ci2 - cr3;
+ ch_ref(i, k, 2) = wa1[i - 1] * di2 + wa1[i] * dr2;
+ ch_ref(i - 1, k, 2) = wa1[i - 1] * dr2 - wa1[i] * di2;
+ ch_ref(i, k, 3) = wa2[i - 1] * di3 + wa2[i] * dr3;
+ ch_ref(i - 1, k, 3) = wa2[i - 1] * dr3 - wa2[i] * di3;
+ }
+ }
+ }
+} /* passb3 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void passb4(integer ido, integer l1, const real *cc, real *ch,
+ const real *wa1, const real *wa2, const real *wa3)
+{
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k;
+ real ci2, ci3, ci4, cr2, cr3, cr4, ti1, ti2, ti3, ti4, tr1, tr2, tr3, tr4;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*4 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + ido * 5;
+ cc -= cc_offset;
+ --wa1;
+ --wa2;
+ --wa3;
+
+ /* Function Body */
+ if (ido == 2) {
+ for (k = 1; k <= l1; ++k) {
+ ti1 = cc_ref(2, 1, k) - cc_ref(2, 3, k);
+ ti2 = cc_ref(2, 1, k) + cc_ref(2, 3, k);
+ tr4 = cc_ref(2, 4, k) - cc_ref(2, 2, k);
+ ti3 = cc_ref(2, 2, k) + cc_ref(2, 4, k);
+ tr1 = cc_ref(1, 1, k) - cc_ref(1, 3, k);
+ tr2 = cc_ref(1, 1, k) + cc_ref(1, 3, k);
+ ti4 = cc_ref(1, 2, k) - cc_ref(1, 4, k);
+ tr3 = cc_ref(1, 2, k) + cc_ref(1, 4, k);
+ ch_ref(1, k, 1) = tr2 + tr3;
+ ch_ref(1, k, 3) = tr2 - tr3;
+ ch_ref(2, k, 1) = ti2 + ti3;
+ ch_ref(2, k, 3) = ti2 - ti3;
+ ch_ref(1, k, 2) = tr1 + tr4;
+ ch_ref(1, k, 4) = tr1 - tr4;
+ ch_ref(2, k, 2) = ti1 + ti4;
+ ch_ref(2, k, 4) = ti1 - ti4;
+ }
+ } else {
+ for (k = 1; k <= l1; ++k) {
+ for (i = 2; i <= ido; i += 2) {
+ ti1 = cc_ref(i, 1, k) - cc_ref(i, 3, k);
+ ti2 = cc_ref(i, 1, k) + cc_ref(i, 3, k);
+ ti3 = cc_ref(i, 2, k) + cc_ref(i, 4, k);
+ tr4 = cc_ref(i, 4, k) - cc_ref(i, 2, k);
+ tr1 = cc_ref(i - 1, 1, k) - cc_ref(i - 1, 3, k);
+ tr2 = cc_ref(i - 1, 1, k) + cc_ref(i - 1, 3, k);
+ ti4 = cc_ref(i - 1, 2, k) - cc_ref(i - 1, 4, k);
+ tr3 = cc_ref(i - 1, 2, k) + cc_ref(i - 1, 4, k);
+ ch_ref(i - 1, k, 1) = tr2 + tr3;
+ cr3 = tr2 - tr3;
+ ch_ref(i, k, 1) = ti2 + ti3;
+ ci3 = ti2 - ti3;
+ cr2 = tr1 + tr4;
+ cr4 = tr1 - tr4;
+ ci2 = ti1 + ti4;
+ ci4 = ti1 - ti4;
+ ch_ref(i - 1, k, 2) = wa1[i - 1] * cr2 - wa1[i] * ci2;
+ ch_ref(i, k, 2) = wa1[i - 1] * ci2 + wa1[i] * cr2;
+ ch_ref(i - 1, k, 3) = wa2[i - 1] * cr3 - wa2[i] * ci3;
+ ch_ref(i, k, 3) = wa2[i - 1] * ci3 + wa2[i] * cr3;
+ ch_ref(i - 1, k, 4) = wa3[i - 1] * cr4 - wa3[i] * ci4;
+ ch_ref(i, k, 4) = wa3[i - 1] * ci4 + wa3[i] * cr4;
+ }
+ }
+ }
+} /* passb4 */
+
+#undef ch_ref
+#undef cc_ref
+
+/* passf5 and passb5 merged */
+static void passfb5(integer ido, integer l1, const real *cc, real *ch,
+ const real *wa1, const real *wa2, const real *wa3, const real *wa4, real fsign)
+{
+ const real tr11 = .309016994374947;
+ const real ti11 = .951056516295154*fsign;
+ const real tr12 = -.809016994374947;
+ const real ti12 = .587785252292473*fsign;
+
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k;
+ real ci2, ci3, ci4, ci5, di3, di4, di5, di2, cr2, cr3, cr5, cr4, ti2, ti3,
+ ti4, ti5, dr3, dr4, dr5, dr2, tr2, tr3, tr4, tr5;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*5 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + ido * 6;
+ cc -= cc_offset;
+ --wa1;
+ --wa2;
+ --wa3;
+ --wa4;
+
+ /* Function Body */
+ if (ido == 2) {
+ for (k = 1; k <= l1; ++k) {
+ ti5 = cc_ref(2, 2, k) - cc_ref(2, 5, k);
+ ti2 = cc_ref(2, 2, k) + cc_ref(2, 5, k);
+ ti4 = cc_ref(2, 3, k) - cc_ref(2, 4, k);
+ ti3 = cc_ref(2, 3, k) + cc_ref(2, 4, k);
+ tr5 = cc_ref(1, 2, k) - cc_ref(1, 5, k);
+ tr2 = cc_ref(1, 2, k) + cc_ref(1, 5, k);
+ tr4 = cc_ref(1, 3, k) - cc_ref(1, 4, k);
+ tr3 = cc_ref(1, 3, k) + cc_ref(1, 4, k);
+ ch_ref(1, k, 1) = cc_ref(1, 1, k) + tr2 + tr3;
+ ch_ref(2, k, 1) = cc_ref(2, 1, k) + ti2 + ti3;
+ cr2 = cc_ref(1, 1, k) + tr11 * tr2 + tr12 * tr3;
+ ci2 = cc_ref(2, 1, k) + tr11 * ti2 + tr12 * ti3;
+ cr3 = cc_ref(1, 1, k) + tr12 * tr2 + tr11 * tr3;
+ ci3 = cc_ref(2, 1, k) + tr12 * ti2 + tr11 * ti3;
+ cr5 = ti11 * tr5 + ti12 * tr4;
+ ci5 = ti11 * ti5 + ti12 * ti4;
+ cr4 = ti12 * tr5 - ti11 * tr4;
+ ci4 = ti12 * ti5 - ti11 * ti4;
+ ch_ref(1, k, 2) = cr2 - ci5;
+ ch_ref(1, k, 5) = cr2 + ci5;
+ ch_ref(2, k, 2) = ci2 + cr5;
+ ch_ref(2, k, 3) = ci3 + cr4;
+ ch_ref(1, k, 3) = cr3 - ci4;
+ ch_ref(1, k, 4) = cr3 + ci4;
+ ch_ref(2, k, 4) = ci3 - cr4;
+ ch_ref(2, k, 5) = ci2 - cr5;
+ }
+ } else {
+ for (k = 1; k <= l1; ++k) {
+ for (i = 2; i <= ido; i += 2) {
+ ti5 = cc_ref(i, 2, k) - cc_ref(i, 5, k);
+ ti2 = cc_ref(i, 2, k) + cc_ref(i, 5, k);
+ ti4 = cc_ref(i, 3, k) - cc_ref(i, 4, k);
+ ti3 = cc_ref(i, 3, k) + cc_ref(i, 4, k);
+ tr5 = cc_ref(i - 1, 2, k) - cc_ref(i - 1, 5, k);
+ tr2 = cc_ref(i - 1, 2, k) + cc_ref(i - 1, 5, k);
+ tr4 = cc_ref(i - 1, 3, k) - cc_ref(i - 1, 4, k);
+ tr3 = cc_ref(i - 1, 3, k) + cc_ref(i - 1, 4, k);
+ ch_ref(i - 1, k, 1) = cc_ref(i - 1, 1, k) + tr2 + tr3;
+ ch_ref(i, k, 1) = cc_ref(i, 1, k) + ti2 + ti3;
+ cr2 = cc_ref(i - 1, 1, k) + tr11 * tr2 + tr12 * tr3;
+ ci2 = cc_ref(i, 1, k) + tr11 * ti2 + tr12 * ti3;
+ cr3 = cc_ref(i - 1, 1, k) + tr12 * tr2 + tr11 * tr3;
+ ci3 = cc_ref(i, 1, k) + tr12 * ti2 + tr11 * ti3;
+ cr5 = ti11 * tr5 + ti12 * tr4;
+ ci5 = ti11 * ti5 + ti12 * ti4;
+ cr4 = ti12 * tr5 - ti11 * tr4;
+ ci4 = ti12 * ti5 - ti11 * ti4;
+ dr3 = cr3 - ci4;
+ dr4 = cr3 + ci4;
+ di3 = ci3 + cr4;
+ di4 = ci3 - cr4;
+ dr5 = cr2 + ci5;
+ dr2 = cr2 - ci5;
+ di5 = ci2 - cr5;
+ di2 = ci2 + cr5;
+ ch_ref(i - 1, k, 2) = wa1[i - 1] * dr2 - fsign*wa1[i] * di2;
+ ch_ref(i, k, 2) = wa1[i - 1] * di2 + fsign*wa1[i] * dr2;
+ ch_ref(i - 1, k, 3) = wa2[i - 1] * dr3 - fsign*wa2[i] * di3;
+ ch_ref(i, k, 3) = wa2[i - 1] * di3 + fsign*wa2[i] * dr3;
+ ch_ref(i - 1, k, 4) = wa3[i - 1] * dr4 - fsign*wa3[i] * di4;
+ ch_ref(i, k, 4) = wa3[i - 1] * di4 + fsign*wa3[i] * dr4;
+ ch_ref(i - 1, k, 5) = wa4[i - 1] * dr5 - fsign*wa4[i] * di5;
+ ch_ref(i, k, 5) = wa4[i - 1] * di5 + fsign*wa4[i] * dr5;
+ }
+ }
+ }
+} /* passb5 */
+
+#undef ch_ref
+#undef cc_ref
+
+static void passf2(integer ido, integer l1, const real *cc, real *ch, const real *wa1)
+{
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k;
+ real ti2, tr2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*2 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + ido * 3;
+ cc -= cc_offset;
+ --wa1;
+
+ /* Function Body */
+ if (ido == 2) {
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(1, k, 1) = cc_ref(1, 1, k) + cc_ref(1, 2, k);
+ ch_ref(1, k, 2) = cc_ref(1, 1, k) - cc_ref(1, 2, k);
+ ch_ref(2, k, 1) = cc_ref(2, 1, k) + cc_ref(2, 2, k);
+ ch_ref(2, k, 2) = cc_ref(2, 1, k) - cc_ref(2, 2, k);
+ }
+ } else {
+ for (k = 1; k <= l1; ++k) {
+ for (i = 2; i <= ido; i += 2) {
+ ch_ref(i - 1, k, 1) = cc_ref(i - 1, 1, k) + cc_ref(i - 1, 2,
+ k);
+ tr2 = cc_ref(i - 1, 1, k) - cc_ref(i - 1, 2, k);
+ ch_ref(i, k, 1) = cc_ref(i, 1, k) + cc_ref(i, 2, k);
+ ti2 = cc_ref(i, 1, k) - cc_ref(i, 2, k);
+ ch_ref(i, k, 2) = wa1[i - 1] * ti2 - wa1[i] * tr2;
+ ch_ref(i - 1, k, 2) = wa1[i - 1] * tr2 + wa1[i] * ti2;
+ }
+ }
+ }
+} /* passf2 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void passf3(integer ido, integer l1, const real *cc, real *ch,
+ const real *wa1, const real *wa2)
+{
+ static const real taur = -.5;
+ static const real taui = -.866025403784439;
+
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k;
+ real ci2, ci3, di2, di3, cr2, cr3, dr2, dr3, ti2, tr2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*3 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + (ido << 2);
+ cc -= cc_offset;
+ --wa1;
+ --wa2;
+
+ /* Function Body */
+ if (ido == 2) {
+ for (k = 1; k <= l1; ++k) {
+ tr2 = cc_ref(1, 2, k) + cc_ref(1, 3, k);
+ cr2 = cc_ref(1, 1, k) + taur * tr2;
+ ch_ref(1, k, 1) = cc_ref(1, 1, k) + tr2;
+ ti2 = cc_ref(2, 2, k) + cc_ref(2, 3, k);
+ ci2 = cc_ref(2, 1, k) + taur * ti2;
+ ch_ref(2, k, 1) = cc_ref(2, 1, k) + ti2;
+ cr3 = taui * (cc_ref(1, 2, k) - cc_ref(1, 3, k));
+ ci3 = taui * (cc_ref(2, 2, k) - cc_ref(2, 3, k));
+ ch_ref(1, k, 2) = cr2 - ci3;
+ ch_ref(1, k, 3) = cr2 + ci3;
+ ch_ref(2, k, 2) = ci2 + cr3;
+ ch_ref(2, k, 3) = ci2 - cr3;
+ }
+ } else {
+ for (k = 1; k <= l1; ++k) {
+ for (i = 2; i <= ido; i += 2) {
+ tr2 = cc_ref(i - 1, 2, k) + cc_ref(i - 1, 3, k);
+ cr2 = cc_ref(i - 1, 1, k) + taur * tr2;
+ ch_ref(i - 1, k, 1) = cc_ref(i - 1, 1, k) + tr2;
+ ti2 = cc_ref(i, 2, k) + cc_ref(i, 3, k);
+ ci2 = cc_ref(i, 1, k) + taur * ti2;
+ ch_ref(i, k, 1) = cc_ref(i, 1, k) + ti2;
+ cr3 = taui * (cc_ref(i - 1, 2, k) - cc_ref(i - 1, 3, k));
+ ci3 = taui * (cc_ref(i, 2, k) - cc_ref(i, 3, k));
+ dr2 = cr2 - ci3;
+ dr3 = cr2 + ci3;
+ di2 = ci2 + cr3;
+ di3 = ci2 - cr3;
+ ch_ref(i, k, 2) = wa1[i - 1] * di2 - wa1[i] * dr2;
+ ch_ref(i - 1, k, 2) = wa1[i - 1] * dr2 + wa1[i] * di2;
+ ch_ref(i, k, 3) = wa2[i - 1] * di3 - wa2[i] * dr3;
+ ch_ref(i - 1, k, 3) = wa2[i - 1] * dr3 + wa2[i] * di3;
+ }
+ }
+ }
+} /* passf3 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void passf4(integer ido, integer l1, const real *cc, real *ch,
+ const real *wa1, const real *wa2, const real *wa3)
+{
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k;
+ real ci2, ci3, ci4, cr2, cr3, cr4, ti1, ti2, ti3, ti4, tr1, tr2, tr3, tr4;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*4 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + ido * 5;
+ cc -= cc_offset;
+ --wa1;
+ --wa2;
+ --wa3;
+
+ /* Function Body */
+ if (ido == 2) {
+ for (k = 1; k <= l1; ++k) {
+ ti1 = cc_ref(2, 1, k) - cc_ref(2, 3, k);
+ ti2 = cc_ref(2, 1, k) + cc_ref(2, 3, k);
+ tr4 = cc_ref(2, 2, k) - cc_ref(2, 4, k);
+ ti3 = cc_ref(2, 2, k) + cc_ref(2, 4, k);
+ tr1 = cc_ref(1, 1, k) - cc_ref(1, 3, k);
+ tr2 = cc_ref(1, 1, k) + cc_ref(1, 3, k);
+ ti4 = cc_ref(1, 4, k) - cc_ref(1, 2, k);
+ tr3 = cc_ref(1, 2, k) + cc_ref(1, 4, k);
+ ch_ref(1, k, 1) = tr2 + tr3;
+ ch_ref(1, k, 3) = tr2 - tr3;
+ ch_ref(2, k, 1) = ti2 + ti3;
+ ch_ref(2, k, 3) = ti2 - ti3;
+ ch_ref(1, k, 2) = tr1 + tr4;
+ ch_ref(1, k, 4) = tr1 - tr4;
+ ch_ref(2, k, 2) = ti1 + ti4;
+ ch_ref(2, k, 4) = ti1 - ti4;
+ }
+ } else {
+ for (k = 1; k <= l1; ++k) {
+ for (i = 2; i <= ido; i += 2) {
+ ti1 = cc_ref(i, 1, k) - cc_ref(i, 3, k);
+ ti2 = cc_ref(i, 1, k) + cc_ref(i, 3, k);
+ ti3 = cc_ref(i, 2, k) + cc_ref(i, 4, k);
+ tr4 = cc_ref(i, 2, k) - cc_ref(i, 4, k);
+ tr1 = cc_ref(i - 1, 1, k) - cc_ref(i - 1, 3, k);
+ tr2 = cc_ref(i - 1, 1, k) + cc_ref(i - 1, 3, k);
+ ti4 = cc_ref(i - 1, 4, k) - cc_ref(i - 1, 2, k);
+ tr3 = cc_ref(i - 1, 2, k) + cc_ref(i - 1, 4, k);
+ ch_ref(i - 1, k, 1) = tr2 + tr3;
+ cr3 = tr2 - tr3;
+ ch_ref(i, k, 1) = ti2 + ti3;
+ ci3 = ti2 - ti3;
+ cr2 = tr1 + tr4;
+ cr4 = tr1 - tr4;
+ ci2 = ti1 + ti4;
+ ci4 = ti1 - ti4;
+ ch_ref(i - 1, k, 2) = wa1[i - 1] * cr2 + wa1[i] * ci2;
+ ch_ref(i, k, 2) = wa1[i - 1] * ci2 - wa1[i] * cr2;
+ ch_ref(i - 1, k, 3) = wa2[i - 1] * cr3 + wa2[i] * ci3;
+ ch_ref(i, k, 3) = wa2[i - 1] * ci3 - wa2[i] * cr3;
+ ch_ref(i - 1, k, 4) = wa3[i - 1] * cr4 + wa3[i] * ci4;
+ ch_ref(i, k, 4) = wa3[i - 1] * ci4 - wa3[i] * cr4;
+ }
+ }
+ }
+} /* passf4 */
+
+#undef ch_ref
+#undef cc_ref
+
+static void radb2(integer ido, integer l1, const real *cc, real *ch, const real *wa1)
+{
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k, ic;
+ real ti2, tr2;
+ integer idp2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*2 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + ido * 3;
+ cc -= cc_offset;
+ --wa1;
+
+ /* Function Body */
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(1, k, 1) = cc_ref(1, 1, k) + cc_ref(ido, 2, k);
+ ch_ref(1, k, 2) = cc_ref(1, 1, k) - cc_ref(ido, 2, k);
+ }
+ if (ido < 2) return;
+ else if (ido != 2) {
+ idp2 = ido + 2;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ ch_ref(i - 1, k, 1) = cc_ref(i - 1, 1, k) + cc_ref(ic - 1, 2,
+ k);
+ tr2 = cc_ref(i - 1, 1, k) - cc_ref(ic - 1, 2, k);
+ ch_ref(i, k, 1) = cc_ref(i, 1, k) - cc_ref(ic, 2, k);
+ ti2 = cc_ref(i, 1, k) + cc_ref(ic, 2, k);
+ ch_ref(i - 1, k, 2) = wa1[i - 2] * tr2 - wa1[i - 1] * ti2;
+ ch_ref(i, k, 2) = wa1[i - 2] * ti2 + wa1[i - 1] * tr2;
+ }
+ }
+ if (ido % 2 == 1) return;
+ }
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(ido, k, 1) = cc_ref(ido, 1, k) + cc_ref(ido, 1, k);
+ ch_ref(ido, k, 2) = -(cc_ref(1, 2, k) + cc_ref(1, 2, k));
+ }
+} /* radb2 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void radb3(integer ido, integer l1, const real *cc, real *ch,
+ const real *wa1, const real *wa2)
+{
+ /* Initialized data */
+
+ static const real taur = -.5;
+ static const real taui = .866025403784439;
+
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k, ic;
+ real ci2, ci3, di2, di3, cr2, cr3, dr2, dr3, ti2, tr2;
+ integer idp2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*3 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + (ido << 2);
+ cc -= cc_offset;
+ --wa1;
+ --wa2;
+
+ /* Function Body */
+ for (k = 1; k <= l1; ++k) {
+ tr2 = cc_ref(ido, 2, k) + cc_ref(ido, 2, k);
+ cr2 = cc_ref(1, 1, k) + taur * tr2;
+ ch_ref(1, k, 1) = cc_ref(1, 1, k) + tr2;
+ ci3 = taui * (cc_ref(1, 3, k) + cc_ref(1, 3, k));
+ ch_ref(1, k, 2) = cr2 - ci3;
+ ch_ref(1, k, 3) = cr2 + ci3;
+ }
+ if (ido == 1) {
+ return;
+ }
+ idp2 = ido + 2;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ tr2 = cc_ref(i - 1, 3, k) + cc_ref(ic - 1, 2, k);
+ cr2 = cc_ref(i - 1, 1, k) + taur * tr2;
+ ch_ref(i - 1, k, 1) = cc_ref(i - 1, 1, k) + tr2;
+ ti2 = cc_ref(i, 3, k) - cc_ref(ic, 2, k);
+ ci2 = cc_ref(i, 1, k) + taur * ti2;
+ ch_ref(i, k, 1) = cc_ref(i, 1, k) + ti2;
+ cr3 = taui * (cc_ref(i - 1, 3, k) - cc_ref(ic - 1, 2, k));
+ ci3 = taui * (cc_ref(i, 3, k) + cc_ref(ic, 2, k));
+ dr2 = cr2 - ci3;
+ dr3 = cr2 + ci3;
+ di2 = ci2 + cr3;
+ di3 = ci2 - cr3;
+ ch_ref(i - 1, k, 2) = wa1[i - 2] * dr2 - wa1[i - 1] * di2;
+ ch_ref(i, k, 2) = wa1[i - 2] * di2 + wa1[i - 1] * dr2;
+ ch_ref(i - 1, k, 3) = wa2[i - 2] * dr3 - wa2[i - 1] * di3;
+ ch_ref(i, k, 3) = wa2[i - 2] * di3 + wa2[i - 1] * dr3;
+ }
+ }
+} /* radb3 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void radb4(integer ido, integer l1, const real *cc, real *ch,
+ const real *wa1, const real *wa2, const real *wa3)
+{
+ /* Initialized data */
+
+ static const real sqrt2 = 1.414213562373095;
+
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k, ic;
+ real ci2, ci3, ci4, cr2, cr3, cr4, ti1, ti2, ti3, ti4, tr1, tr2, tr3, tr4;
+ integer idp2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*4 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + ido * 5;
+ cc -= cc_offset;
+ --wa1;
+ --wa2;
+ --wa3;
+
+ /* Function Body */
+ for (k = 1; k <= l1; ++k) {
+ tr1 = cc_ref(1, 1, k) - cc_ref(ido, 4, k);
+ tr2 = cc_ref(1, 1, k) + cc_ref(ido, 4, k);
+ tr3 = cc_ref(ido, 2, k) + cc_ref(ido, 2, k);
+ tr4 = cc_ref(1, 3, k) + cc_ref(1, 3, k);
+ ch_ref(1, k, 1) = tr2 + tr3;
+ ch_ref(1, k, 2) = tr1 - tr4;
+ ch_ref(1, k, 3) = tr2 - tr3;
+ ch_ref(1, k, 4) = tr1 + tr4;
+ }
+ if (ido < 2) return;
+ if (ido != 2) {
+ idp2 = ido + 2;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ ti1 = cc_ref(i, 1, k) + cc_ref(ic, 4, k);
+ ti2 = cc_ref(i, 1, k) - cc_ref(ic, 4, k);
+ ti3 = cc_ref(i, 3, k) - cc_ref(ic, 2, k);
+ tr4 = cc_ref(i, 3, k) + cc_ref(ic, 2, k);
+ tr1 = cc_ref(i - 1, 1, k) - cc_ref(ic - 1, 4, k);
+ tr2 = cc_ref(i - 1, 1, k) + cc_ref(ic - 1, 4, k);
+ ti4 = cc_ref(i - 1, 3, k) - cc_ref(ic - 1, 2, k);
+ tr3 = cc_ref(i - 1, 3, k) + cc_ref(ic - 1, 2, k);
+ ch_ref(i - 1, k, 1) = tr2 + tr3;
+ cr3 = tr2 - tr3;
+ ch_ref(i, k, 1) = ti2 + ti3;
+ ci3 = ti2 - ti3;
+ cr2 = tr1 - tr4;
+ cr4 = tr1 + tr4;
+ ci2 = ti1 + ti4;
+ ci4 = ti1 - ti4;
+ ch_ref(i - 1, k, 2) = wa1[i - 2] * cr2 - wa1[i - 1] * ci2;
+ ch_ref(i, k, 2) = wa1[i - 2] * ci2 + wa1[i - 1] * cr2;
+ ch_ref(i - 1, k, 3) = wa2[i - 2] * cr3 - wa2[i - 1] * ci3;
+ ch_ref(i, k, 3) = wa2[i - 2] * ci3 + wa2[i - 1] * cr3;
+ ch_ref(i - 1, k, 4) = wa3[i - 2] * cr4 - wa3[i - 1] * ci4;
+ ch_ref(i, k, 4) = wa3[i - 2] * ci4 + wa3[i - 1] * cr4;
+ }
+ }
+ if (ido % 2 == 1) return;
+ }
+ for (k = 1; k <= l1; ++k) {
+ ti1 = cc_ref(1, 2, k) + cc_ref(1, 4, k);
+ ti2 = cc_ref(1, 4, k) - cc_ref(1, 2, k);
+ tr1 = cc_ref(ido, 1, k) - cc_ref(ido, 3, k);
+ tr2 = cc_ref(ido, 1, k) + cc_ref(ido, 3, k);
+ ch_ref(ido, k, 1) = tr2 + tr2;
+ ch_ref(ido, k, 2) = sqrt2 * (tr1 - ti1);
+ ch_ref(ido, k, 3) = ti2 + ti2;
+ ch_ref(ido, k, 4) = -sqrt2 * (tr1 + ti1);
+ }
+} /* radb4 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void radb5(integer ido, integer l1, const real *cc, real *ch,
+ const real *wa1, const real *wa2, const real *wa3, const real *wa4)
+{
+ /* Initialized data */
+
+ static const real tr11 = .309016994374947;
+ static const real ti11 = .951056516295154;
+ static const real tr12 = -.809016994374947;
+ static const real ti12 = .587785252292473;
+
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k, ic;
+ real ci2, ci3, ci4, ci5, di3, di4, di5, di2, cr2, cr3, cr5, cr4, ti2, ti3,
+ ti4, ti5, dr3, dr4, dr5, dr2, tr2, tr3, tr4, tr5;
+ integer idp2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*5 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + ido * 6;
+ cc -= cc_offset;
+ --wa1;
+ --wa2;
+ --wa3;
+ --wa4;
+
+ /* Function Body */
+ for (k = 1; k <= l1; ++k) {
+ ti5 = cc_ref(1, 3, k) + cc_ref(1, 3, k);
+ ti4 = cc_ref(1, 5, k) + cc_ref(1, 5, k);
+ tr2 = cc_ref(ido, 2, k) + cc_ref(ido, 2, k);
+ tr3 = cc_ref(ido, 4, k) + cc_ref(ido, 4, k);
+ ch_ref(1, k, 1) = cc_ref(1, 1, k) + tr2 + tr3;
+ cr2 = cc_ref(1, 1, k) + tr11 * tr2 + tr12 * tr3;
+ cr3 = cc_ref(1, 1, k) + tr12 * tr2 + tr11 * tr3;
+ ci5 = ti11 * ti5 + ti12 * ti4;
+ ci4 = ti12 * ti5 - ti11 * ti4;
+ ch_ref(1, k, 2) = cr2 - ci5;
+ ch_ref(1, k, 3) = cr3 - ci4;
+ ch_ref(1, k, 4) = cr3 + ci4;
+ ch_ref(1, k, 5) = cr2 + ci5;
+ }
+ if (ido == 1) {
+ return;
+ }
+ idp2 = ido + 2;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ ti5 = cc_ref(i, 3, k) + cc_ref(ic, 2, k);
+ ti2 = cc_ref(i, 3, k) - cc_ref(ic, 2, k);
+ ti4 = cc_ref(i, 5, k) + cc_ref(ic, 4, k);
+ ti3 = cc_ref(i, 5, k) - cc_ref(ic, 4, k);
+ tr5 = cc_ref(i - 1, 3, k) - cc_ref(ic - 1, 2, k);
+ tr2 = cc_ref(i - 1, 3, k) + cc_ref(ic - 1, 2, k);
+ tr4 = cc_ref(i - 1, 5, k) - cc_ref(ic - 1, 4, k);
+ tr3 = cc_ref(i - 1, 5, k) + cc_ref(ic - 1, 4, k);
+ ch_ref(i - 1, k, 1) = cc_ref(i - 1, 1, k) + tr2 + tr3;
+ ch_ref(i, k, 1) = cc_ref(i, 1, k) + ti2 + ti3;
+ cr2 = cc_ref(i - 1, 1, k) + tr11 * tr2 + tr12 * tr3;
+ ci2 = cc_ref(i, 1, k) + tr11 * ti2 + tr12 * ti3;
+ cr3 = cc_ref(i - 1, 1, k) + tr12 * tr2 + tr11 * tr3;
+ ci3 = cc_ref(i, 1, k) + tr12 * ti2 + tr11 * ti3;
+ cr5 = ti11 * tr5 + ti12 * tr4;
+ ci5 = ti11 * ti5 + ti12 * ti4;
+ cr4 = ti12 * tr5 - ti11 * tr4;
+ ci4 = ti12 * ti5 - ti11 * ti4;
+ dr3 = cr3 - ci4;
+ dr4 = cr3 + ci4;
+ di3 = ci3 + cr4;
+ di4 = ci3 - cr4;
+ dr5 = cr2 + ci5;
+ dr2 = cr2 - ci5;
+ di5 = ci2 - cr5;
+ di2 = ci2 + cr5;
+ ch_ref(i - 1, k, 2) = wa1[i - 2] * dr2 - wa1[i - 1] * di2;
+ ch_ref(i, k, 2) = wa1[i - 2] * di2 + wa1[i - 1] * dr2;
+ ch_ref(i - 1, k, 3) = wa2[i - 2] * dr3 - wa2[i - 1] * di3;
+ ch_ref(i, k, 3) = wa2[i - 2] * di3 + wa2[i - 1] * dr3;
+ ch_ref(i - 1, k, 4) = wa3[i - 2] * dr4 - wa3[i - 1] * di4;
+ ch_ref(i, k, 4) = wa3[i - 2] * di4 + wa3[i - 1] * dr4;
+ ch_ref(i - 1, k, 5) = wa4[i - 2] * dr5 - wa4[i - 1] * di5;
+ ch_ref(i, k, 5) = wa4[i - 2] * di5 + wa4[i - 1] * dr5;
+ }
+ }
+} /* radb5 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void radbg(integer ido, integer ip, integer l1, integer idl1,
+ const real *cc, real *c1, real *c2, real *ch, real *ch2, const real *wa)
+{
+ /* System generated locals */
+ integer ch_offset, cc_offset,
+ c1_offset, c2_offset, ch2_offset;
+
+ /* Local variables */
+ integer i, j, k, l, j2, ic, jc, lc, ik, is;
+ real dc2, ai1, ai2, ar1, ar2, ds2;
+ integer nbd;
+ real dcp, arg, dsp, ar1h, ar2h;
+ integer idp2, ipp2, idij, ipph;
+
+
+#define c1_ref(a_1,a_2,a_3) c1[((a_3)*l1 + (a_2))*ido + a_1]
+#define c2_ref(a_1,a_2) c2[(a_2)*idl1 + a_1]
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*ip + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+#define ch2_ref(a_1,a_2) ch2[(a_2)*idl1 + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ c1_offset = 1 + ido * (1 + l1);
+ c1 -= c1_offset;
+ cc_offset = 1 + ido * (1 + ip);
+ cc -= cc_offset;
+ ch2_offset = 1 + idl1;
+ ch2 -= ch2_offset;
+ c2_offset = 1 + idl1;
+ c2 -= c2_offset;
+ --wa;
+
+ /* Function Body */
+ arg = (2*M_PI) / (real) (ip);
+ dcp = cos(arg);
+ dsp = sin(arg);
+ idp2 = ido + 2;
+ nbd = (ido - 1) / 2;
+ ipp2 = ip + 2;
+ ipph = (ip + 1) / 2;
+ if (ido >= l1) {
+ for (k = 1; k <= l1; ++k) {
+ for (i = 1; i <= ido; ++i) {
+ ch_ref(i, k, 1) = cc_ref(i, 1, k);
+ }
+ }
+ } else {
+ for (i = 1; i <= ido; ++i) {
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(i, k, 1) = cc_ref(i, 1, k);
+ }
+ }
+ }
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ j2 = j + j;
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(1, k, j) = cc_ref(ido, j2 - 2, k) + cc_ref(ido, j2 - 2, k);
+ ch_ref(1, k, jc) = cc_ref(1, j2 - 1, k) + cc_ref(1, j2 - 1, k);
+ }
+ }
+ if (ido != 1) {
+ if (nbd >= l1) {
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ ch_ref(i - 1, k, j) = cc_ref(i - 1, (j << 1) - 1, k) + cc_ref(ic - 1, (j << 1) - 2, k);
+ ch_ref(i - 1, k, jc) = cc_ref(i - 1, (j << 1) - 1, k) - cc_ref(ic - 1, (j << 1) - 2, k);
+ ch_ref(i, k, j) = cc_ref(i, (j << 1) - 1, k) - cc_ref(ic, (j << 1) - 2, k);
+ ch_ref(i, k, jc) = cc_ref(i, (j << 1) - 1, k) + cc_ref(ic, (j << 1) - 2, k);
+ }
+ }
+ }
+ } else {
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(i - 1, k, j) = cc_ref(i - 1, (j << 1) - 1, k) + cc_ref(ic - 1, (j << 1) - 2, k);
+ ch_ref(i - 1, k, jc) = cc_ref(i - 1, (j << 1) - 1, k) - cc_ref(ic - 1, (j << 1) - 2, k);
+ ch_ref(i, k, j) = cc_ref(i, (j << 1) - 1, k) - cc_ref(ic, (j << 1) - 2, k);
+ ch_ref(i, k, jc) = cc_ref(i, (j << 1) - 1, k) + cc_ref(ic, (j << 1) - 2, k);
+ }
+ }
+ }
+ }
+ }
+ ar1 = 1.;
+ ai1 = 0.;
+ for (l = 2; l <= ipph; ++l) {
+ lc = ipp2 - l;
+ ar1h = dcp * ar1 - dsp * ai1;
+ ai1 = dcp * ai1 + dsp * ar1;
+ ar1 = ar1h;
+ for (ik = 1; ik <= idl1; ++ik) {
+ c2_ref(ik, l) = ch2_ref(ik, 1) + ar1 * ch2_ref(ik, 2);
+ c2_ref(ik, lc) = ai1 * ch2_ref(ik, ip);
+ }
+ dc2 = ar1;
+ ds2 = ai1;
+ ar2 = ar1;
+ ai2 = ai1;
+ for (j = 3; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ ar2h = dc2 * ar2 - ds2 * ai2;
+ ai2 = dc2 * ai2 + ds2 * ar2;
+ ar2 = ar2h;
+ for (ik = 1; ik <= idl1; ++ik) {
+ c2_ref(ik, l) = c2_ref(ik, l) + ar2 * ch2_ref(ik, j);
+ c2_ref(ik, lc) = c2_ref(ik, lc) + ai2 * ch2_ref(ik, jc);
+ }
+ }
+ }
+ for (j = 2; j <= ipph; ++j) {
+ for (ik = 1; ik <= idl1; ++ik) {
+ ch2_ref(ik, 1) = ch2_ref(ik, 1) + ch2_ref(ik, j);
+ }
+ }
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(1, k, j) = c1_ref(1, k, j) - c1_ref(1, k, jc);
+ ch_ref(1, k, jc) = c1_ref(1, k, j) + c1_ref(1, k, jc);
+ }
+ }
+ if (ido != 1) {
+ if (nbd >= l1) {
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ch_ref(i - 1, k, j) = c1_ref(i - 1, k, j) - c1_ref(i, k, jc);
+ ch_ref(i - 1, k, jc) = c1_ref(i - 1, k, j) + c1_ref(i, k, jc);
+ ch_ref(i, k, j) = c1_ref(i, k, j) + c1_ref(i - 1, k, jc);
+ ch_ref(i, k, jc) = c1_ref(i, k, j) - c1_ref(i - 1, k, jc);
+ }
+ }
+ }
+ } else {
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ for (i = 3; i <= ido; i += 2) {
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(i - 1, k, j) = c1_ref(i - 1, k, j) - c1_ref(i, k, jc);
+ ch_ref(i - 1, k, jc) = c1_ref(i - 1, k, j) + c1_ref(i, k, jc);
+ ch_ref(i, k, j) = c1_ref(i, k, j) + c1_ref(i - 1, k, jc);
+ ch_ref(i, k, jc) = c1_ref(i, k, j) - c1_ref(i - 1, k, jc);
+ }
+ }
+ }
+ }
+ }
+ if (ido == 1) {
+ return;
+ }
+ for (ik = 1; ik <= idl1; ++ik) {
+ c2_ref(ik, 1) = ch2_ref(ik, 1);
+ }
+ for (j = 2; j <= ip; ++j) {
+ for (k = 1; k <= l1; ++k) {
+ c1_ref(1, k, j) = ch_ref(1, k, j);
+ }
+ }
+ if (nbd <= l1) {
+ is = -(ido);
+ for (j = 2; j <= ip; ++j) {
+ is += ido;
+ idij = is;
+ for (i = 3; i <= ido; i += 2) {
+ idij += 2;
+ for (k = 1; k <= l1; ++k) {
+ c1_ref(i - 1, k, j) = wa[idij - 1] * ch_ref(i - 1, k, j)
+ - wa[idij] * ch_ref(i, k, j);
+ c1_ref(i, k, j) = wa[idij - 1] * ch_ref(i, k, j) + wa[idij] * ch_ref(i - 1, k, j);
+ }
+ }
+ }
+ } else {
+ is = -(ido);
+ for (j = 2; j <= ip; ++j) {
+ is += ido;
+ for (k = 1; k <= l1; ++k) {
+ idij = is;
+ for (i = 3; i <= ido; i += 2) {
+ idij += 2;
+ c1_ref(i - 1, k, j) = wa[idij - 1] * ch_ref(i - 1, k, j)
+ - wa[idij] * ch_ref(i, k, j);
+ c1_ref(i, k, j) = wa[idij - 1] * ch_ref(i, k, j) + wa[idij] * ch_ref(i - 1, k, j);
+ }
+ }
+ }
+ }
+} /* radbg */
+
+#undef ch2_ref
+#undef ch_ref
+#undef cc_ref
+#undef c2_ref
+#undef c1_ref
+
+
+static void radf2(integer ido, integer l1, const real *cc, real *ch,
+ const real *wa1)
+{
+ /* System generated locals */
+ integer ch_offset, cc_offset;
+
+ /* Local variables */
+ integer i, k, ic;
+ real ti2, tr2;
+ integer idp2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*l1 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*2 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * 3;
+ ch -= ch_offset;
+ cc_offset = 1 + ido * (1 + l1);
+ cc -= cc_offset;
+ --wa1;
+
+ /* Function Body */
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(1, 1, k) = cc_ref(1, k, 1) + cc_ref(1, k, 2);
+ ch_ref(ido, 2, k) = cc_ref(1, k, 1) - cc_ref(1, k, 2);
+ }
+ if (ido < 2) return;
+ if (ido != 2) {
+ idp2 = ido + 2;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ tr2 = wa1[i - 2] * cc_ref(i - 1, k, 2) + wa1[i - 1] *
+ cc_ref(i, k, 2);
+ ti2 = wa1[i - 2] * cc_ref(i, k, 2) - wa1[i - 1] * cc_ref(
+ i - 1, k, 2);
+ ch_ref(i, 1, k) = cc_ref(i, k, 1) + ti2;
+ ch_ref(ic, 2, k) = ti2 - cc_ref(i, k, 1);
+ ch_ref(i - 1, 1, k) = cc_ref(i - 1, k, 1) + tr2;
+ ch_ref(ic - 1, 2, k) = cc_ref(i - 1, k, 1) - tr2;
+ }
+ }
+ if (ido % 2 == 1) {
+ return;
+ }
+ }
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(1, 2, k) = -cc_ref(ido, k, 2);
+ ch_ref(ido, 1, k) = cc_ref(ido, k, 1);
+ }
+} /* radf2 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void radf3(integer ido, integer l1, const real *cc, real *ch,
+ const real *wa1, const real *wa2)
+{
+ static const real taur = -.5;
+ static const real taui = .866025403784439;
+
+ /* System generated locals */
+ integer ch_offset, cc_offset;
+
+ /* Local variables */
+ integer i, k, ic;
+ real ci2, di2, di3, cr2, dr2, dr3, ti2, ti3, tr2, tr3;
+ integer idp2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*l1 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*3 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + (ido << 2);
+ ch -= ch_offset;
+ cc_offset = 1 + ido * (1 + l1);
+ cc -= cc_offset;
+ --wa1;
+ --wa2;
+
+ /* Function Body */
+ for (k = 1; k <= l1; ++k) {
+ cr2 = cc_ref(1, k, 2) + cc_ref(1, k, 3);
+ ch_ref(1, 1, k) = cc_ref(1, k, 1) + cr2;
+ ch_ref(1, 3, k) = taui * (cc_ref(1, k, 3) - cc_ref(1, k, 2));
+ ch_ref(ido, 2, k) = cc_ref(1, k, 1) + taur * cr2;
+ }
+ if (ido == 1) {
+ return;
+ }
+ idp2 = ido + 2;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ dr2 = wa1[i - 2] * cc_ref(i - 1, k, 2) + wa1[i - 1] *
+ cc_ref(i, k, 2);
+ di2 = wa1[i - 2] * cc_ref(i, k, 2) - wa1[i - 1] * cc_ref(
+ i - 1, k, 2);
+ dr3 = wa2[i - 2] * cc_ref(i - 1, k, 3) + wa2[i - 1] *
+ cc_ref(i, k, 3);
+ di3 = wa2[i - 2] * cc_ref(i, k, 3) - wa2[i - 1] * cc_ref(
+ i - 1, k, 3);
+ cr2 = dr2 + dr3;
+ ci2 = di2 + di3;
+ ch_ref(i - 1, 1, k) = cc_ref(i - 1, k, 1) + cr2;
+ ch_ref(i, 1, k) = cc_ref(i, k, 1) + ci2;
+ tr2 = cc_ref(i - 1, k, 1) + taur * cr2;
+ ti2 = cc_ref(i, k, 1) + taur * ci2;
+ tr3 = taui * (di2 - di3);
+ ti3 = taui * (dr3 - dr2);
+ ch_ref(i - 1, 3, k) = tr2 + tr3;
+ ch_ref(ic - 1, 2, k) = tr2 - tr3;
+ ch_ref(i, 3, k) = ti2 + ti3;
+ ch_ref(ic, 2, k) = ti3 - ti2;
+ }
+ }
+} /* radf3 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void radf4(integer ido, integer l1, const real *cc, real *ch,
+ const real *wa1, const real *wa2, const real *wa3)
+{
+ /* Initialized data */
+
+ static const real hsqt2 = .7071067811865475;
+
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k, ic;
+ real ci2, ci3, ci4, cr2, cr3, cr4, ti1, ti2, ti3, ti4, tr1, tr2, tr3, tr4;
+ integer idp2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*l1 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*4 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * 5;
+ ch -= ch_offset;
+ cc_offset = 1 + ido * (1 + l1);
+ cc -= cc_offset;
+ --wa1;
+ --wa2;
+ --wa3;
+
+ /* Function Body */
+ for (k = 1; k <= l1; ++k) {
+ tr1 = cc_ref(1, k, 2) + cc_ref(1, k, 4);
+ tr2 = cc_ref(1, k, 1) + cc_ref(1, k, 3);
+ ch_ref(1, 1, k) = tr1 + tr2;
+ ch_ref(ido, 4, k) = tr2 - tr1;
+ ch_ref(ido, 2, k) = cc_ref(1, k, 1) - cc_ref(1, k, 3);
+ ch_ref(1, 3, k) = cc_ref(1, k, 4) - cc_ref(1, k, 2);
+ }
+ if (ido < 2) return;
+ if (ido != 2) {
+ idp2 = ido + 2;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ cr2 = wa1[i - 2] * cc_ref(i - 1, k, 2) + wa1[i - 1] *
+ cc_ref(i, k, 2);
+ ci2 = wa1[i - 2] * cc_ref(i, k, 2) - wa1[i - 1] * cc_ref(
+ i - 1, k, 2);
+ cr3 = wa2[i - 2] * cc_ref(i - 1, k, 3) + wa2[i - 1] *
+ cc_ref(i, k, 3);
+ ci3 = wa2[i - 2] * cc_ref(i, k, 3) - wa2[i - 1] * cc_ref(
+ i - 1, k, 3);
+ cr4 = wa3[i - 2] * cc_ref(i - 1, k, 4) + wa3[i - 1] *
+ cc_ref(i, k, 4);
+ ci4 = wa3[i - 2] * cc_ref(i, k, 4) - wa3[i - 1] * cc_ref(
+ i - 1, k, 4);
+ tr1 = cr2 + cr4;
+ tr4 = cr4 - cr2;
+ ti1 = ci2 + ci4;
+ ti4 = ci2 - ci4;
+ ti2 = cc_ref(i, k, 1) + ci3;
+ ti3 = cc_ref(i, k, 1) - ci3;
+ tr2 = cc_ref(i - 1, k, 1) + cr3;
+ tr3 = cc_ref(i - 1, k, 1) - cr3;
+ ch_ref(i - 1, 1, k) = tr1 + tr2;
+ ch_ref(ic - 1, 4, k) = tr2 - tr1;
+ ch_ref(i, 1, k) = ti1 + ti2;
+ ch_ref(ic, 4, k) = ti1 - ti2;
+ ch_ref(i - 1, 3, k) = ti4 + tr3;
+ ch_ref(ic - 1, 2, k) = tr3 - ti4;
+ ch_ref(i, 3, k) = tr4 + ti3;
+ ch_ref(ic, 2, k) = tr4 - ti3;
+ }
+ }
+ if (ido % 2 == 1) {
+ return;
+ }
+ }
+ for (k = 1; k <= l1; ++k) {
+ ti1 = -hsqt2 * (cc_ref(ido, k, 2) + cc_ref(ido, k, 4));
+ tr1 = hsqt2 * (cc_ref(ido, k, 2) - cc_ref(ido, k, 4));
+ ch_ref(ido, 1, k) = tr1 + cc_ref(ido, k, 1);
+ ch_ref(ido, 3, k) = cc_ref(ido, k, 1) - tr1;
+ ch_ref(1, 2, k) = ti1 - cc_ref(ido, k, 3);
+ ch_ref(1, 4, k) = ti1 + cc_ref(ido, k, 3);
+ }
+} /* radf4 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void radf5(integer ido, integer l1, const real *cc, real *ch,
+ const real *wa1, const real *wa2, const real *wa3, const real *wa4)
+{
+ /* Initialized data */
+
+ static const real tr11 = .309016994374947;
+ static const real ti11 = .951056516295154;
+ static const real tr12 = -.809016994374947;
+ static const real ti12 = .587785252292473;
+
+ /* System generated locals */
+ integer cc_offset, ch_offset;
+
+ /* Local variables */
+ integer i, k, ic;
+ real ci2, di2, ci4, ci5, di3, di4, di5, ci3, cr2, cr3, dr2, dr3, dr4, dr5,
+ cr5, cr4, ti2, ti3, ti5, ti4, tr2, tr3, tr4, tr5;
+ integer idp2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*l1 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*5 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * 6;
+ ch -= ch_offset;
+ cc_offset = 1 + ido * (1 + l1);
+ cc -= cc_offset;
+ --wa1;
+ --wa2;
+ --wa3;
+ --wa4;
+
+ /* Function Body */
+ for (k = 1; k <= l1; ++k) {
+ cr2 = cc_ref(1, k, 5) + cc_ref(1, k, 2);
+ ci5 = cc_ref(1, k, 5) - cc_ref(1, k, 2);
+ cr3 = cc_ref(1, k, 4) + cc_ref(1, k, 3);
+ ci4 = cc_ref(1, k, 4) - cc_ref(1, k, 3);
+ ch_ref(1, 1, k) = cc_ref(1, k, 1) + cr2 + cr3;
+ ch_ref(ido, 2, k) = cc_ref(1, k, 1) + tr11 * cr2 + tr12 * cr3;
+ ch_ref(1, 3, k) = ti11 * ci5 + ti12 * ci4;
+ ch_ref(ido, 4, k) = cc_ref(1, k, 1) + tr12 * cr2 + tr11 * cr3;
+ ch_ref(1, 5, k) = ti12 * ci5 - ti11 * ci4;
+ }
+ if (ido == 1) {
+ return;
+ }
+ idp2 = ido + 2;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ dr2 = wa1[i - 2] * cc_ref(i - 1, k, 2) + wa1[i - 1] * cc_ref(i, k, 2);
+ di2 = wa1[i - 2] * cc_ref(i, k, 2) - wa1[i - 1] * cc_ref(i - 1, k, 2);
+ dr3 = wa2[i - 2] * cc_ref(i - 1, k, 3) + wa2[i - 1] * cc_ref(i, k, 3);
+ di3 = wa2[i - 2] * cc_ref(i, k, 3) - wa2[i - 1] * cc_ref(i - 1, k, 3);
+ dr4 = wa3[i - 2] * cc_ref(i - 1, k, 4) + wa3[i - 1] * cc_ref(i, k, 4);
+ di4 = wa3[i - 2] * cc_ref(i, k, 4) - wa3[i - 1] * cc_ref(i - 1, k, 4);
+ dr5 = wa4[i - 2] * cc_ref(i - 1, k, 5) + wa4[i - 1] * cc_ref(i, k, 5);
+ di5 = wa4[i - 2] * cc_ref(i, k, 5) - wa4[i - 1] * cc_ref(i - 1, k, 5);
+ cr2 = dr2 + dr5;
+ ci5 = dr5 - dr2;
+ cr5 = di2 - di5;
+ ci2 = di2 + di5;
+ cr3 = dr3 + dr4;
+ ci4 = dr4 - dr3;
+ cr4 = di3 - di4;
+ ci3 = di3 + di4;
+ ch_ref(i - 1, 1, k) = cc_ref(i - 1, k, 1) + cr2 + cr3;
+ ch_ref(i, 1, k) = cc_ref(i, k, 1) + ci2 + ci3;
+ tr2 = cc_ref(i - 1, k, 1) + tr11 * cr2 + tr12 * cr3;
+ ti2 = cc_ref(i, k, 1) + tr11 * ci2 + tr12 * ci3;
+ tr3 = cc_ref(i - 1, k, 1) + tr12 * cr2 + tr11 * cr3;
+ ti3 = cc_ref(i, k, 1) + tr12 * ci2 + tr11 * ci3;
+ tr5 = ti11 * cr5 + ti12 * cr4;
+ ti5 = ti11 * ci5 + ti12 * ci4;
+ tr4 = ti12 * cr5 - ti11 * cr4;
+ ti4 = ti12 * ci5 - ti11 * ci4;
+ ch_ref(i - 1, 3, k) = tr2 + tr5;
+ ch_ref(ic - 1, 2, k) = tr2 - tr5;
+ ch_ref(i, 3, k) = ti2 + ti5;
+ ch_ref(ic, 2, k) = ti5 - ti2;
+ ch_ref(i - 1, 5, k) = tr3 + tr4;
+ ch_ref(ic - 1, 4, k) = tr3 - tr4;
+ ch_ref(i, 5, k) = ti3 + ti4;
+ ch_ref(ic, 4, k) = ti4 - ti3;
+ }
+ }
+} /* radf5 */
+
+#undef ch_ref
+#undef cc_ref
+
+
+static void radfg(integer ido, integer ip, integer l1, integer idl1,
+ real *cc, real *c1, real *c2, real *ch, real *ch2, const real *wa)
+{
+ /* System generated locals */
+ integer ch_offset, cc_offset,
+ c1_offset, c2_offset, ch2_offset;
+
+ /* Local variables */
+ integer i, j, k, l, j2, ic, jc, lc, ik, is;
+ real dc2, ai1, ai2, ar1, ar2, ds2;
+ integer nbd;
+ real dcp, arg, dsp, ar1h, ar2h;
+ integer idp2, ipp2, idij, ipph;
+
+
+#define c1_ref(a_1,a_2,a_3) c1[((a_3)*l1 + (a_2))*ido + a_1]
+#define c2_ref(a_1,a_2) c2[(a_2)*idl1 + a_1]
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*ip + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+#define ch2_ref(a_1,a_2) ch2[(a_2)*idl1 + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ c1_offset = 1 + ido * (1 + l1);
+ c1 -= c1_offset;
+ cc_offset = 1 + ido * (1 + ip);
+ cc -= cc_offset;
+ ch2_offset = 1 + idl1;
+ ch2 -= ch2_offset;
+ c2_offset = 1 + idl1;
+ c2 -= c2_offset;
+ --wa;
+
+ /* Function Body */
+ arg = (2*M_PI) / (real) (ip);
+ dcp = cos(arg);
+ dsp = sin(arg);
+ ipph = (ip + 1) / 2;
+ ipp2 = ip + 2;
+ idp2 = ido + 2;
+ nbd = (ido - 1) / 2;
+ if (ido == 1) {
+ for (ik = 1; ik <= idl1; ++ik) {
+ c2_ref(ik, 1) = ch2_ref(ik, 1);
+ }
+ } else {
+ for (ik = 1; ik <= idl1; ++ik) {
+ ch2_ref(ik, 1) = c2_ref(ik, 1);
+ }
+ for (j = 2; j <= ip; ++j) {
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(1, k, j) = c1_ref(1, k, j);
+ }
+ }
+ if (nbd <= l1) {
+ is = -(ido);
+ for (j = 2; j <= ip; ++j) {
+ is += ido;
+ idij = is;
+ for (i = 3; i <= ido; i += 2) {
+ idij += 2;
+ for (k = 1; k <= l1; ++k) {
+ ch_ref(i - 1, k, j) = wa[idij - 1] * c1_ref(i - 1, k, j)
+ + wa[idij] * c1_ref(i, k, j);
+ ch_ref(i, k, j) = wa[idij - 1] * c1_ref(i, k, j) - wa[
+ idij] * c1_ref(i - 1, k, j);
+ }
+ }
+ }
+ } else {
+ is = -(ido);
+ for (j = 2; j <= ip; ++j) {
+ is += ido;
+ for (k = 1; k <= l1; ++k) {
+ idij = is;
+ for (i = 3; i <= ido; i += 2) {
+ idij += 2;
+ ch_ref(i - 1, k, j) = wa[idij - 1] * c1_ref(i - 1, k, j)
+ + wa[idij] * c1_ref(i, k, j);
+ ch_ref(i, k, j) = wa[idij - 1] * c1_ref(i, k, j) - wa[
+ idij] * c1_ref(i - 1, k, j);
+ }
+ }
+ }
+ }
+ if (nbd >= l1) {
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ c1_ref(i - 1, k, j) = ch_ref(i - 1, k, j) + ch_ref(i -
+ 1, k, jc);
+ c1_ref(i - 1, k, jc) = ch_ref(i, k, j) - ch_ref(i, k,
+ jc);
+ c1_ref(i, k, j) = ch_ref(i, k, j) + ch_ref(i, k, jc);
+ c1_ref(i, k, jc) = ch_ref(i - 1, k, jc) - ch_ref(i - 1,
+ k, j);
+ }
+ }
+ }
+ } else {
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ for (i = 3; i <= ido; i += 2) {
+ for (k = 1; k <= l1; ++k) {
+ c1_ref(i - 1, k, j) = ch_ref(i - 1, k, j) + ch_ref(i -
+ 1, k, jc);
+ c1_ref(i - 1, k, jc) = ch_ref(i, k, j) - ch_ref(i, k,
+ jc);
+ c1_ref(i, k, j) = ch_ref(i, k, j) + ch_ref(i, k, jc);
+ c1_ref(i, k, jc) = ch_ref(i - 1, k, jc) - ch_ref(i - 1,
+ k, j);
+ }
+ }
+ }
+ }
+ }
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ for (k = 1; k <= l1; ++k) {
+ c1_ref(1, k, j) = ch_ref(1, k, j) + ch_ref(1, k, jc);
+ c1_ref(1, k, jc) = ch_ref(1, k, jc) - ch_ref(1, k, j);
+ }
+ }
+
+ ar1 = 1.;
+ ai1 = 0.;
+ for (l = 2; l <= ipph; ++l) {
+ lc = ipp2 - l;
+ ar1h = dcp * ar1 - dsp * ai1;
+ ai1 = dcp * ai1 + dsp * ar1;
+ ar1 = ar1h;
+ for (ik = 1; ik <= idl1; ++ik) {
+ ch2_ref(ik, l) = c2_ref(ik, 1) + ar1 * c2_ref(ik, 2);
+ ch2_ref(ik, lc) = ai1 * c2_ref(ik, ip);
+ }
+ dc2 = ar1;
+ ds2 = ai1;
+ ar2 = ar1;
+ ai2 = ai1;
+ for (j = 3; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ ar2h = dc2 * ar2 - ds2 * ai2;
+ ai2 = dc2 * ai2 + ds2 * ar2;
+ ar2 = ar2h;
+ for (ik = 1; ik <= idl1; ++ik) {
+ ch2_ref(ik, l) = ch2_ref(ik, l) + ar2 * c2_ref(ik, j);
+ ch2_ref(ik, lc) = ch2_ref(ik, lc) + ai2 * c2_ref(ik, jc);
+ }
+ }
+ }
+ for (j = 2; j <= ipph; ++j) {
+ for (ik = 1; ik <= idl1; ++ik) {
+ ch2_ref(ik, 1) = ch2_ref(ik, 1) + c2_ref(ik, j);
+ }
+ }
+
+ if (ido >= l1) {
+ for (k = 1; k <= l1; ++k) {
+ for (i = 1; i <= ido; ++i) {
+ cc_ref(i, 1, k) = ch_ref(i, k, 1);
+ }
+ }
+ } else {
+ for (i = 1; i <= ido; ++i) {
+ for (k = 1; k <= l1; ++k) {
+ cc_ref(i, 1, k) = ch_ref(i, k, 1);
+ }
+ }
+ }
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ j2 = j + j;
+ for (k = 1; k <= l1; ++k) {
+ cc_ref(ido, j2 - 2, k) = ch_ref(1, k, j);
+ cc_ref(1, j2 - 1, k) = ch_ref(1, k, jc);
+ }
+ }
+ if (ido == 1) {
+ return;
+ }
+ if (nbd >= l1) {
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ j2 = j + j;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ cc_ref(i - 1, j2 - 1, k) = ch_ref(i - 1, k, j) + ch_ref(
+ i - 1, k, jc);
+ cc_ref(ic - 1, j2 - 2, k) = ch_ref(i - 1, k, j) - ch_ref(
+ i - 1, k, jc);
+ cc_ref(i, j2 - 1, k) = ch_ref(i, k, j) + ch_ref(i, k,
+ jc);
+ cc_ref(ic, j2 - 2, k) = ch_ref(i, k, jc) - ch_ref(i, k, j)
+ ;
+ }
+ }
+ }
+ } else {
+ for (j = 2; j <= ipph; ++j) {
+ jc = ipp2 - j;
+ j2 = j + j;
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ for (k = 1; k <= l1; ++k) {
+ cc_ref(i - 1, j2 - 1, k) = ch_ref(i - 1, k, j) + ch_ref(
+ i - 1, k, jc);
+ cc_ref(ic - 1, j2 - 2, k) = ch_ref(i - 1, k, j) - ch_ref(
+ i - 1, k, jc);
+ cc_ref(i, j2 - 1, k) = ch_ref(i, k, j) + ch_ref(i, k,
+ jc);
+ cc_ref(ic, j2 - 2, k) = ch_ref(i, k, jc) - ch_ref(i, k, j)
+ ;
+ }
+ }
+ }
+ }
+} /* radfg */
+
+#undef ch2_ref
+#undef ch_ref
+#undef cc_ref
+#undef c2_ref
+#undef c1_ref
+
+
+static void cfftb1(integer n, real *c, real *ch, const real *wa, integer *ifac)
+{
+ integer i, k1, l1, l2, na, nf, ip, iw, ix2, ix3, ix4, nac, ido,
+ idl1, idot;
+
+ /* Function Body */
+ nf = ifac[1];
+ na = 0;
+ l1 = 1;
+ iw = 0;
+ for (k1 = 1; k1 <= nf; ++k1) {
+ ip = ifac[k1 + 1];
+ l2 = ip * l1;
+ ido = n / l2;
+ idot = ido + ido;
+ idl1 = idot * l1;
+ switch (ip) {
+ case 4:
+ ix2 = iw + idot;
+ ix3 = ix2 + idot;
+ passb4(idot, l1, na?ch:c, na?c:ch, &wa[iw], &wa[ix2], &wa[ix3]);
+ na = 1 - na;
+ break;
+ case 2:
+ passb2(idot, l1, na?ch:c, na?c:ch, &wa[iw]);
+ na = 1 - na;
+ break;
+ case 3:
+ ix2 = iw + idot;
+ passb3(idot, l1, na?ch:c, na?c:ch, &wa[iw], &wa[ix2]);
+ na = 1 - na;
+ break;
+ case 5:
+ ix2 = iw + idot;
+ ix3 = ix2 + idot;
+ ix4 = ix3 + idot;
+ passfb5(idot, l1, na?ch:c, na?c:ch, &wa[iw], &wa[ix2], &wa[ix3], &wa[ix4], +1);
+ na = 1 - na;
+ break;
+ default:
+ if (na == 0) {
+ passfb(&nac, idot, ip, l1, idl1, c, c, c, ch, ch, &wa[iw], +1);
+ } else {
+ passfb(&nac, idot, ip, l1, idl1, ch, ch, ch, c, c, &wa[iw], +1);
+ }
+ if (nac != 0) {
+ na = 1 - na;
+ }
+ break;
+ }
+ l1 = l2;
+ iw += (ip - 1) * idot;
+ }
+ if (na == 0) {
+ return;
+ }
+ for (i = 0; i < 2*n; ++i) {
+ c[i] = ch[i];
+ }
+} /* cfftb1 */
+
+void cfftb(integer n, real *c, real *wsave)
+{
+ integer iw1, iw2;
+
+ /* Parameter adjustments */
+ --wsave;
+ --c;
+
+ /* Function Body */
+ if (n == 1) {
+ return;
+ }
+ iw1 = 2*n + 1;
+ iw2 = iw1 + 2*n;
+ cfftb1(n, &c[1], &wsave[1], &wsave[iw1], (int*)&wsave[iw2]);
+} /* cfftb */
+
+static void cfftf1(integer n, real *c, real *ch, const real *wa, integer *ifac)
+{
+ /* Local variables */
+ integer i, k1, l1, l2, na, nf, ip, iw, ix2, ix3, ix4, nac, ido,
+ idl1, idot;
+
+ /* Function Body */
+ nf = ifac[1];
+ na = 0;
+ l1 = 1;
+ iw = 0;
+ for (k1 = 1; k1 <= nf; ++k1) {
+ ip = ifac[k1 + 1];
+ l2 = ip * l1;
+ ido = n / l2;
+ idot = ido + ido;
+ idl1 = idot * l1;
+ switch (ip) {
+ case 4:
+ ix2 = iw + idot;
+ ix3 = ix2 + idot;
+ passf4(idot, l1, na?ch:c, na?c:ch, &wa[iw], &wa[ix2], &wa[ix3]);
+ na = 1 - na;
+ break;
+ case 2:
+ passf2(idot, l1, na?ch:c, na?c:ch, &wa[iw]);
+ na = 1 - na;
+ break;
+ case 3:
+ ix2 = iw + idot;
+ passf3(idot, l1, na?ch:c, na?c:ch, &wa[iw], &wa[ix2]);
+ na = 1 - na;
+ break;
+ case 5:
+ ix2 = iw + idot;
+ ix3 = ix2 + idot;
+ ix4 = ix3 + idot;
+ passfb5(idot, l1, na?ch:c, na?c:ch, &wa[iw], &wa[ix2], &wa[ix3], &wa[ix4], -1);
+ na = 1 - na;
+ break;
+ default:
+ if (na == 0) {
+ passfb(&nac, idot, ip, l1, idl1, c, c, c, ch, ch, &wa[iw], -1);
+ } else {
+ passfb(&nac, idot, ip, l1, idl1, ch, ch, ch, c, c, &wa[iw], -1);
+ }
+ if (nac != 0) {
+ na = 1 - na;
+ }
+ break;
+ }
+ l1 = l2;
+ iw += (ip - 1)*idot;
+ }
+ if (na == 0) {
+ return;
+ }
+ for (i = 0; i < 2*n; ++i) {
+ c[i] = ch[i];
+ }
+} /* cfftf1 */
+
+void cfftf(integer n, real *c, real *wsave)
+{
+ integer iw1, iw2;
+
+ /* Parameter adjustments */
+ --wsave;
+ --c;
+
+ /* Function Body */
+ if (n == 1) {
+ return;
+ }
+ iw1 = 2*n + 1;
+ iw2 = iw1 + 2*n;
+ cfftf1(n, &c[1], &wsave[1], &wsave[iw1], (int*)&wsave[iw2]);
+} /* cfftf */
+
+static int decompose(integer n, integer *ifac, integer ntryh[4]) {
+ integer ntry=0, nl = n, nf = 0, nq, nr, i, j = 0;
+ do {
+ if (j < 4) {
+ ntry = ntryh[j];
+ } else {
+ ntry += 2;
+ }
+ ++j;
+ L104:
+ nq = nl / ntry;
+ nr = nl - ntry * nq;
+ if (nr != 0) continue;
+ ++nf;
+ ifac[nf + 2] = ntry;
+ nl = nq;
+ if (ntry == 2 && nf != 1) {
+ for (i = 2; i <= nf; ++i) {
+ integer ib = nf - i + 2;
+ ifac[ib + 2] = ifac[ib + 1];
+ }
+ ifac[3] = 2;
+ }
+ if (nl != 1) {
+ goto L104;
+ }
+ } while (nl != 1);
+ ifac[1] = n;
+ ifac[2] = nf;
+ return nf;
+}
+
+static void cffti1(integer n, real *wa, integer *ifac)
+{
+ static integer ntryh[4] = { 3,4,2,5 };
+
+ /* Local variables */
+ integer i, j, i1, k1, l1, l2;
+ real fi;
+ integer ld, ii, nf, ip;
+ real arg;
+ integer ido, ipm;
+ real argh;
+ integer idot;
+ real argld;
+
+ /* Parameter adjustments */
+ --ifac;
+ --wa;
+
+ nf = decompose(n, ifac, ntryh);
+
+ argh = (2*M_PI) / (real) (n);
+ i = 2;
+ l1 = 1;
+ for (k1 = 1; k1 <= nf; ++k1) {
+ ip = ifac[k1 + 2];
+ ld = 0;
+ l2 = l1 * ip;
+ ido = n / l2;
+ idot = ido + ido + 2;
+ ipm = ip - 1;
+ for (j = 1; j <= ipm; ++j) {
+ i1 = i;
+ wa[i - 1] = 1.;
+ wa[i] = 0.;
+ ld += l1;
+ fi = 0.;
+ argld = (real) ld * argh;
+ for (ii = 4; ii <= idot; ii += 2) {
+ i += 2;
+ fi += 1.;
+ arg = fi * argld;
+ wa[i - 1] = cos(arg);
+ wa[i] = sin(arg);
+ }
+ if (ip > 5) {
+ wa[i1 - 1] = wa[i - 1];
+ wa[i1] = wa[i];
+ };
+ }
+ l1 = l2;
+ }
+} /* cffti1 */
+
+void cffti(integer n, real *wsave)
+{
+ integer iw1, iw2;
+ /* Parameter adjustments */
+ --wsave;
+
+ /* Function Body */
+ if (n == 1) {
+ return;
+ }
+ iw1 = 2*n + 1;
+ iw2 = iw1 + 2*n;
+ cffti1(n, &wsave[iw1], (int*)&wsave[iw2]);
+ return;
+} /* cffti */
+
+static void rfftb1(integer n, real *c, real *ch, const real *wa, integer *ifac)
+{
+ /* Local variables */
+ integer i, k1, l1, l2, na, nf, ip, iw, ix2, ix3, ix4, ido, idl1;
+
+ /* Function Body */
+ nf = ifac[1];
+ na = 0;
+ l1 = 1;
+ iw = 0;
+ for (k1 = 1; k1 <= nf; ++k1) {
+ ip = ifac[k1 + 1];
+ l2 = ip * l1;
+ ido = n / l2;
+ idl1 = ido * l1;
+ switch (ip) {
+ case 4:
+ ix2 = iw + ido;
+ ix3 = ix2 + ido;
+ radb4(ido, l1, na?ch:c, na?c:ch, &wa[iw], &wa[ix2], &wa[ix3]);
+ na = 1 - na;
+ break;
+ case 2:
+ radb2(ido, l1, na?ch:c, na?c:ch, &wa[iw]);
+ na = 1 - na;
+ break;
+ case 3:
+ ix2 = iw + ido;
+ radb3(ido, l1, na?ch:c, na?c:ch, &wa[iw], &wa[ix2]);
+ na = 1 - na;
+ break;
+ case 5:
+ ix2 = iw + ido;
+ ix3 = ix2 + ido;
+ ix4 = ix3 + ido;
+ radb5(ido, l1, na?ch:c, na?c:ch, &wa[iw], &wa[ix2], &wa[ix3], &wa[ix4]);
+ na = 1 - na;
+ break;
+ default:
+ if (na == 0) {
+ radbg(ido, ip, l1, idl1, c, c, c, ch, ch, &wa[iw]);
+ } else {
+ radbg(ido, ip, l1, idl1, ch, ch, ch, c, c, &wa[iw]);
+ }
+ if (ido == 1) {
+ na = 1 - na;
+ }
+ break;
+ }
+ l1 = l2;
+ iw += (ip - 1) * ido;
+ }
+ if (na == 0) {
+ return;
+ }
+ for (i = 0; i < n; ++i) {
+ c[i] = ch[i];
+ }
+} /* rfftb1 */
+
+static void rfftf1(integer n, real *c, real *ch, const real *wa, integer *ifac)
+{
+ /* Local variables */
+ integer i, k1, l1, l2, na, kh, nf, ip, iw, ix2, ix3, ix4, ido, idl1;
+
+ /* Function Body */
+ nf = ifac[1];
+ na = 1;
+ l2 = n;
+ iw = n-1;
+ for (k1 = 1; k1 <= nf; ++k1) {
+ kh = nf - k1;
+ ip = ifac[kh + 2];
+ l1 = l2 / ip;
+ ido = n / l2;
+ idl1 = ido * l1;
+ iw -= (ip - 1) * ido;
+ na = 1 - na;
+ switch (ip) {
+ case 4:
+ ix2 = iw + ido;
+ ix3 = ix2 + ido;
+ radf4(ido, l1, na ? ch : c, na ? c : ch, &wa[iw], &wa[ix2], &wa[ix3]);
+ break;
+ case 2:
+ radf2(ido, l1, na ? ch : c, na ? c : ch, &wa[iw]);
+ break;
+ case 3:
+ ix2 = iw + ido;
+ radf3(ido, l1, na ? ch : c, na ? c : ch, &wa[iw], &wa[ix2]);
+ break;
+ case 5:
+ ix2 = iw + ido;
+ ix3 = ix2 + ido;
+ ix4 = ix3 + ido;
+ radf5(ido, l1, na ? ch : c, na ? c : ch, &wa[iw], &wa[ix2], &wa[ix3], &wa[ix4]);
+ break;
+ default:
+ if (ido == 1) {
+ na = 1 - na;
+ }
+ if (na == 0) {
+ radfg(ido, ip, l1, idl1, c, c, c, ch, ch, &wa[iw]);
+ na = 1;
+ } else {
+ radfg(ido, ip, l1, idl1, ch, ch, ch, c, c, &wa[iw]);
+ na = 0;
+ }
+ break;
+ }
+ l2 = l1;
+ }
+ if (na == 1) {
+ return;
+ }
+ for (i = 0; i < n; ++i) {
+ c[i] = ch[i];
+ }
+}
+
+void rfftb(integer n, real *r, real *wsave)
+{
+
+ /* Parameter adjustments */
+ --wsave;
+ --r;
+
+ /* Function Body */
+ if (n == 1) {
+ return;
+ }
+ rfftb1(n, &r[1], &wsave[1], &wsave[n + 1], (int*)&wsave[(n << 1) + 1]);
+} /* rfftb */
+
+static void rffti1(integer n, real *wa, integer *ifac)
+{
+ static integer ntryh[4] = { 4,2,3,5 };
+
+ /* Local variables */
+ integer i, j, k1, l1, l2;
+ real fi;
+ integer ld, ii, nf, ip, is;
+ real arg;
+ integer ido, ipm;
+ integer nfm1;
+ real argh;
+ real argld;
+
+ /* Parameter adjustments */
+ --ifac;
+ --wa;
+
+ nf = decompose(n, ifac, ntryh);
+
+ argh = (2*M_PI) / (real) (n);
+ is = 0;
+ nfm1 = nf - 1;
+ l1 = 1;
+ if (nfm1 == 0) {
+ return;
+ }
+ for (k1 = 1; k1 <= nfm1; ++k1) {
+ ip = ifac[k1 + 2];
+ ld = 0;
+ l2 = l1 * ip;
+ ido = n / l2;
+ ipm = ip - 1;
+ for (j = 1; j <= ipm; ++j) {
+ ld += l1;
+ i = is;
+ argld = (real) ld * argh;
+ fi = 0.;
+ for (ii = 3; ii <= ido; ii += 2) {
+ i += 2;
+ fi += 1.;
+ arg = fi * argld;
+ wa[i - 1] = cos(arg);
+ wa[i] = sin(arg);
+ }
+ is += ido;
+ }
+ l1 = l2;
+ }
+} /* rffti1 */
+
+void rfftf(integer n, real *r, real *wsave)
+{
+
+ /* Parameter adjustments */
+ --wsave;
+ --r;
+
+ /* Function Body */
+ if (n == 1) {
+ return;
+ }
+ rfftf1(n, &r[1], &wsave[1], &wsave[n + 1], (int*)&wsave[(n << 1) + 1]);
+} /* rfftf */
+
+void rffti(integer n, real *wsave)
+{
+ /* Parameter adjustments */
+ --wsave;
+
+ /* Function Body */
+ if (n == 1) {
+ return;
+ }
+ rffti1(n, &wsave[n + 1], (int*)&wsave[(n << 1) + 1]);
+ return;
+} /* rffti */
+
+static void cosqb1(integer n, real *x, real *w, real *xh)
+{
+ /* Local variables */
+ integer i, k, kc, np2, ns2;
+ real xim1;
+ integer modn;
+
+ /* Parameter adjustments */
+ --xh;
+ --w;
+ --x;
+
+ /* Function Body */
+ ns2 = (n + 1) / 2;
+ np2 = n + 2;
+ for (i = 3; i <= n; i += 2) {
+ xim1 = x[i - 1] + x[i];
+ x[i] -= x[i - 1];
+ x[i - 1] = xim1;
+ }
+ x[1] += x[1];
+ modn = n % 2;
+ if (modn == 0) {
+ x[n] += x[n];
+ }
+ rfftb(n, &x[1], &xh[1]);
+ for (k = 2; k <= ns2; ++k) {
+ kc = np2 - k;
+ xh[k] = w[k - 1] * x[kc] + w[kc - 1] * x[k];
+ xh[kc] = w[k - 1] * x[k] - w[kc - 1] * x[kc];
+ }
+ if (modn == 0) {
+ x[ns2 + 1] = w[ns2] * (x[ns2 + 1] + x[ns2 + 1]);
+ }
+ for (k = 2; k <= ns2; ++k) {
+ kc = np2 - k;
+ x[k] = xh[k] + xh[kc];
+ x[kc] = xh[k] - xh[kc];
+ }
+ x[1] += x[1];
+} /* cosqb1 */
+
+void cosqb(integer n, real *x, real *wsave)
+{
+ static const real tsqrt2 = 2.82842712474619;
+
+ /* Local variables */
+ real x1;
+
+ /* Parameter adjustments */
+ --wsave;
+ --x;
+
+ if (n < 2) {
+ x[1] *= 4.;
+ } else if (n == 2) {
+ x1 = (x[1] + x[2]) * 4.;
+ x[2] = tsqrt2 * (x[1] - x[2]);
+ x[1] = x1;
+ } else {
+ cosqb1(n, &x[1], &wsave[1], &wsave[n + 1]);
+ }
+} /* cosqb */
+
+static void cosqf1(integer n, real *x, real *w, real *xh)
+{
+ /* Local variables */
+ integer i, k, kc, np2, ns2;
+ real xim1;
+ integer modn;
+
+ /* Parameter adjustments */
+ --xh;
+ --w;
+ --x;
+
+ /* Function Body */
+ ns2 = (n + 1) / 2;
+ np2 = n + 2;
+ for (k = 2; k <= ns2; ++k) {
+ kc = np2 - k;
+ xh[k] = x[k] + x[kc];
+ xh[kc] = x[k] - x[kc];
+ }
+ modn = n % 2;
+ if (modn == 0) {
+ xh[ns2 + 1] = x[ns2 + 1] + x[ns2 + 1];
+ }
+ for (k = 2; k <= ns2; ++k) {
+ kc = np2 - k;
+ x[k] = w[k - 1] * xh[kc] + w[kc - 1] * xh[k];
+ x[kc] = w[k - 1] * xh[k] - w[kc - 1] * xh[kc];
+ }
+ if (modn == 0) {
+ x[ns2 + 1] = w[ns2] * xh[ns2 + 1];
+ }
+ rfftf(n, &x[1], &xh[1]);
+ for (i = 3; i <= n; i += 2) {
+ xim1 = x[i - 1] - x[i];
+ x[i] = x[i - 1] + x[i];
+ x[i - 1] = xim1;
+ }
+} /* cosqf1 */
+
+void cosqf(integer n, real *x, real *wsave)
+{
+ static const real sqrt2 = 1.4142135623731;
+
+ /* Local variables */
+ real tsqx;
+
+ /* Parameter adjustments */
+ --wsave;
+ --x;
+
+ if (n == 2) {
+ tsqx = sqrt2 * x[2];
+ x[2] = x[1] - tsqx;
+ x[1] += tsqx;
+ } else if (n > 2) {
+ cosqf1(n, &x[1], &wsave[1], &wsave[n + 1]);
+ }
+} /* cosqf */
+
+void cosqi(integer n, real *wsave)
+{
+ /* Local variables */
+ integer k;
+ real fk, dt;
+
+ /* Parameter adjustments */
+ --wsave;
+
+ dt = M_PI/2 / (real) (n);
+ fk = 0.;
+ for (k = 1; k <= n; ++k) {
+ fk += 1.;
+ wsave[k] = cos(fk * dt);
+ }
+ rffti(n, &wsave[n + 1]);
+} /* cosqi */
+
+void cost(integer n, real *x, real *wsave)
+{
+ /* Local variables */
+ integer i, k;
+ real c1, t1, t2;
+ integer kc;
+ real xi;
+ integer nm1, np1;
+ real x1h;
+ integer ns2;
+ real tx2, x1p3, xim2;
+ integer modn;
+
+ /* Parameter adjustments */
+ --wsave;
+ --x;
+
+ /* Function Body */
+ nm1 = n - 1;
+ np1 = n + 1;
+ ns2 = n / 2;
+ if (n < 2) {
+ } else if (n == 2) {
+ x1h = x[1] + x[2];
+ x[2] = x[1] - x[2];
+ x[1] = x1h;
+ } else if (n == 3) {
+ x1p3 = x[1] + x[3];
+ tx2 = x[2] + x[2];
+ x[2] = x[1] - x[3];
+ x[1] = x1p3 + tx2;
+ x[3] = x1p3 - tx2;
+ } else {
+ c1 = x[1] - x[n];
+ x[1] += x[n];
+ for (k = 2; k <= ns2; ++k) {
+ kc = np1 - k;
+ t1 = x[k] + x[kc];
+ t2 = x[k] - x[kc];
+ c1 += wsave[kc] * t2;
+ t2 = wsave[k] * t2;
+ x[k] = t1 - t2;
+ x[kc] = t1 + t2;
+ }
+ modn = n % 2;
+ if (modn != 0) {
+ x[ns2 + 1] += x[ns2 + 1];
+ }
+ rfftf(nm1, &x[1], &wsave[n + 1]);
+ xim2 = x[2];
+ x[2] = c1;
+ for (i = 4; i <= n; i += 2) {
+ xi = x[i];
+ x[i] = x[i - 2] - x[i - 1];
+ x[i - 1] = xim2;
+ xim2 = xi;
+ }
+ if (modn != 0) {
+ x[n] = xim2;
+ }
+ }
+} /* cost */
+
+void costi(integer n, real *wsave)
+{
+ /* Initialized data */
+
+ /* Local variables */
+ integer k, kc;
+ real fk, dt;
+ integer nm1, np1, ns2;
+
+ /* Parameter adjustments */
+ --wsave;
+
+ /* Function Body */
+ if (n <= 3) {
+ return;
+ }
+ nm1 = n - 1;
+ np1 = n + 1;
+ ns2 = n / 2;
+ dt = M_PI / (real) nm1;
+ fk = 0.;
+ for (k = 2; k <= ns2; ++k) {
+ kc = np1 - k;
+ fk += 1.;
+ wsave[k] = sin(fk * dt) * 2.;
+ wsave[kc] = cos(fk * dt) * 2.;
+ }
+ rffti(nm1, &wsave[n + 1]);
+} /* costi */
+
+void sinqb(integer n, real *x, real *wsave)
+{
+ /* Local variables */
+ integer k, kc, ns2;
+ real xhold;
+
+ /* Parameter adjustments */
+ --wsave;
+ --x;
+
+ /* Function Body */
+ if (n <= 1) {
+ x[1] *= 4.;
+ return;
+ }
+ ns2 = n / 2;
+ for (k = 2; k <= n; k += 2) {
+ x[k] = -x[k];
+ }
+ cosqb(n, &x[1], &wsave[1]);
+ for (k = 1; k <= ns2; ++k) {
+ kc = n - k;
+ xhold = x[k];
+ x[k] = x[kc + 1];
+ x[kc + 1] = xhold;
+ }
+} /* sinqb */
+
+void sinqf(integer n, real *x, real *wsave)
+{
+ /* Local variables */
+ integer k, kc, ns2;
+ real xhold;
+
+ /* Parameter adjustments */
+ --wsave;
+ --x;
+
+ /* Function Body */
+ if (n == 1) {
+ return;
+ }
+ ns2 = n / 2;
+ for (k = 1; k <= ns2; ++k) {
+ kc = n - k;
+ xhold = x[k];
+ x[k] = x[kc + 1];
+ x[kc + 1] = xhold;
+ }
+ cosqf(n, &x[1], &wsave[1]);
+ for (k = 2; k <= n; k += 2) {
+ x[k] = -x[k];
+ }
+} /* sinqf */
+
+void sinqi(integer n, real *wsave)
+{
+
+ /* Parameter adjustments */
+ --wsave;
+
+ /* Function Body */
+ cosqi(n, &wsave[1]);
+} /* sinqi */
+
+static void sint1(integer n, real *war, real *was, real *xh, real *
+ x, integer *ifac)
+{
+ /* Initialized data */
+
+ static const real sqrt3 = 1.73205080756888;
+
+ /* Local variables */
+ integer i, k;
+ real t1, t2;
+ integer kc, np1, ns2, modn;
+ real xhold;
+
+ /* Parameter adjustments */
+ --ifac;
+ --x;
+ --xh;
+ --was;
+ --war;
+
+ /* Function Body */
+ for (i = 1; i <= n; ++i) {
+ xh[i] = war[i];
+ war[i] = x[i];
+ }
+
+ if (n < 2) {
+ xh[1] += xh[1];
+ } else if (n == 2) {
+ xhold = sqrt3 * (xh[1] + xh[2]);
+ xh[2] = sqrt3 * (xh[1] - xh[2]);
+ xh[1] = xhold;
+ } else {
+ np1 = n + 1;
+ ns2 = n / 2;
+ x[1] = 0.;
+ for (k = 1; k <= ns2; ++k) {
+ kc = np1 - k;
+ t1 = xh[k] - xh[kc];
+ t2 = was[k] * (xh[k] + xh[kc]);
+ x[k + 1] = t1 + t2;
+ x[kc + 1] = t2 - t1;
+ }
+ modn = n % 2;
+ if (modn != 0) {
+ x[ns2 + 2] = xh[ns2 + 1] * 4.;
+ }
+ rfftf1(np1, &x[1], &xh[1], &war[1], &ifac[1]);
+ xh[1] = x[1] * .5;
+ for (i = 3; i <= n; i += 2) {
+ xh[i - 1] = -x[i];
+ xh[i] = xh[i - 2] + x[i - 1];
+ }
+ if (modn == 0) {
+ xh[n] = -x[n + 1];
+ }
+ }
+ for (i = 1; i <= n; ++i) {
+ x[i] = war[i];
+ war[i] = xh[i];
+ }
+} /* sint1 */
+
+void sinti(integer n, real *wsave)
+{
+ /* Local variables */
+ integer k;
+ real dt;
+ integer np1, ns2;
+
+ /* Parameter adjustments */
+ --wsave;
+
+ /* Function Body */
+ if (n <= 1) {
+ return;
+ }
+ ns2 = n / 2;
+ np1 = n + 1;
+ dt = M_PI / (real) np1;
+ for (k = 1; k <= ns2; ++k) {
+ wsave[k] = sin(k * dt) * 2.;
+ }
+ rffti(np1, &wsave[ns2 + 1]);
+} /* sinti */
+
+void sint(integer n, real *x, real *wsave)
+{
+ integer np1, iw1, iw2, iw3;
+
+ /* Parameter adjustments */
+ --wsave;
+ --x;
+
+ /* Function Body */
+ np1 = n + 1;
+ iw1 = n / 2 + 1;
+ iw2 = iw1 + np1;
+ iw3 = iw2 + np1;
+ sint1(n, &x[1], &wsave[1], &wsave[iw1], &wsave[iw2], (int*)&wsave[iw3]);
+} /* sint */
+
+#ifdef TESTING_FFTPACK
+#include <stdio.h>
+
+int main(void)
+{
+ static integer nd[] = { 120,91,54,49,32,28,24,8,4,3,2 };
+
+ /* System generated locals */
+ real r1, r2, r3;
+ f77complex q1, q2, q3;
+
+ /* Local variables */
+ integer i, j, k, n;
+ real w[2000], x[200], y[200], cf, fn, dt;
+ f77complex cx[200], cy[200];
+ real xh[200];
+ integer nz, nm1, np1, ns2;
+ real arg;
+ real sum, arg1, arg2;
+ real sum1, sum2, dcfb;
+ integer modn;
+ real rftb, rftf;
+ real sqrt2;
+ real rftfb;
+ real costt, sintt, dcfftb, dcfftf, cosqfb, costfb;
+ real sinqfb;
+ real sintfb;
+ real cosqbt, cosqft, sinqbt, sinqft;
+
+
+
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+ /* VERSION 4 APRIL 1985 */
+
+ /* A TEST DRIVER FOR */
+ /* A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE FAST FOURIER */
+ /* TRANSFORM OF PERIODIC AND OTHER SYMMETRIC SEQUENCES */
+
+ /* BY */
+
+ /* PAUL N SWARZTRAUBER */
+
+ /* NATIONAL CENTER FOR ATMOSPHERIC RESEARCH BOULDER,COLORADO 80307 */
+
+ /* WHICH IS SPONSORED BY THE NATIONAL SCIENCE FOUNDATION */
+
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+
+ /* THIS PROGRAM TESTS THE PACKAGE OF FAST FOURIER */
+ /* TRANSFORMS FOR BOTH COMPLEX AND REAL PERIODIC SEQUENCES AND */
+ /* CERTIAN OTHER SYMMETRIC SEQUENCES THAT ARE LISTED BELOW. */
+
+ /* 1. RFFTI INITIALIZE RFFTF AND RFFTB */
+ /* 2. RFFTF FORWARD TRANSFORM OF A REAL PERIODIC SEQUENCE */
+ /* 3. RFFTB BACKWARD TRANSFORM OF A REAL COEFFICIENT ARRAY */
+
+ /* 4. EZFFTI INITIALIZE EZFFTF AND EZFFTB */
+ /* 5. EZFFTF A SIMPLIFIED REAL PERIODIC FORWARD TRANSFORM */
+ /* 6. EZFFTB A SIMPLIFIED REAL PERIODIC BACKWARD TRANSFORM */
+
+ /* 7. SINTI INITIALIZE SINT */
+ /* 8. SINT SINE TRANSFORM OF A REAL ODD SEQUENCE */
+
+ /* 9. COSTI INITIALIZE COST */
+ /* 10. COST COSINE TRANSFORM OF A REAL EVEN SEQUENCE */
+
+ /* 11. SINQI INITIALIZE SINQF AND SINQB */
+ /* 12. SINQF FORWARD SINE TRANSFORM WITH ODD WAVE NUMBERS */
+ /* 13. SINQB UNNORMALIZED INVERSE OF SINQF */
+
+ /* 14. COSQI INITIALIZE COSQF AND COSQB */
+ /* 15. COSQF FORWARD COSINE TRANSFORM WITH ODD WAVE NUMBERS */
+ /* 16. COSQB UNNORMALIZED INVERSE OF COSQF */
+
+ /* 17. CFFTI INITIALIZE CFFTF AND CFFTB */
+ /* 18. CFFTF FORWARD TRANSFORM OF A COMPLEX PERIODIC SEQUENCE */
+ /* 19. CFFTB UNNORMALIZED INVERSE OF CFFTF */
+
+
+ sqrt2 = sqrt(2.);
+ int all_ok = 1;
+ for (nz = 1; nz <= (int)(sizeof nd/sizeof nd[0]); ++nz) {
+ n = nd[nz - 1];
+ modn = n % 2;
+ fn = (real) n;
+ np1 = n + 1;
+ nm1 = n - 1;
+ for (j = 1; j <= np1; ++j) {
+ x[j - 1] = sin((real) j * sqrt2);
+ y[j - 1] = x[j - 1];
+ xh[j - 1] = x[j - 1];
+ }
+
+ /* TEST SUBROUTINES RFFTI,RFFTF AND RFFTB */
+
+ rffti(n, w);
+ dt = (2*M_PI) / fn;
+ ns2 = (n + 1) / 2;
+ if (ns2 < 2) {
+ goto L104;
+ }
+ for (k = 2; k <= ns2; ++k) {
+ sum1 = 0.;
+ sum2 = 0.;
+ arg = (real) (k - 1) * dt;
+ for (i = 1; i <= n; ++i) {
+ arg1 = (real) (i - 1) * arg;
+ sum1 += x[i - 1] * cos(arg1);
+ sum2 += x[i - 1] * sin(arg1);
+ }
+ y[(k << 1) - 3] = sum1;
+ y[(k << 1) - 2] = -sum2;
+ }
+ L104:
+ sum1 = 0.;
+ sum2 = 0.;
+ for (i = 1; i <= nm1; i += 2) {
+ sum1 += x[i - 1];
+ sum2 += x[i];
+ }
+ if (modn == 1) {
+ sum1 += x[n - 1];
+ }
+ y[0] = sum1 + sum2;
+ if (modn == 0) {
+ y[n - 1] = sum1 - sum2;
+ }
+ rfftf(n, x, w);
+ rftf = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ r2 = rftf, r3 = (r1 = x[i - 1] - y[i - 1], fabs(r1));
+ rftf = dmax(r2,r3);
+ x[i - 1] = xh[i - 1];
+ }
+ rftf /= fn;
+ for (i = 1; i <= n; ++i) {
+ sum = x[0] * .5;
+ arg = (real) (i - 1) * dt;
+ if (ns2 < 2) {
+ goto L108;
+ }
+ for (k = 2; k <= ns2; ++k) {
+ arg1 = (real) (k - 1) * arg;
+ sum = sum + x[(k << 1) - 3] * cos(arg1) - x[(k << 1) - 2] *
+ sin(arg1);
+ }
+ L108:
+ if (modn == 0) {
+ sum += (real)pow(-1, i-1) * .5 * x[n - 1];
+ }
+ y[i - 1] = sum + sum;
+ }
+ rfftb(n, x, w);
+ rftb = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ r2 = rftb, r3 = (r1 = x[i - 1] - y[i - 1], fabs(r1));
+ rftb = dmax(r2,r3);
+ x[i - 1] = xh[i - 1];
+ y[i - 1] = xh[i - 1];
+ }
+ rfftb(n, y, w);
+ rfftf(n, y, w);
+ cf = 1. / fn;
+ rftfb = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ r2 = rftfb, r3 = (r1 = cf * y[i - 1] - x[i - 1], fabs(
+ r1));
+ rftfb = dmax(r2,r3);
+ }
+
+ /* TEST SUBROUTINES SINTI AND SINT */
+
+ dt = M_PI / fn;
+ for (i = 1; i <= nm1; ++i) {
+ x[i - 1] = xh[i - 1];
+ }
+ for (i = 1; i <= nm1; ++i) {
+ y[i - 1] = 0.;
+ arg1 = (real) i * dt;
+ for (k = 1; k <= nm1; ++k) {
+ y[i - 1] += x[k - 1] * sin((real) k * arg1);
+ }
+ y[i - 1] += y[i - 1];
+ }
+ sinti(nm1, w);
+ sint(nm1, x, w);
+ cf = .5 / fn;
+ sintt = 0.;
+ for (i = 1; i <= nm1; ++i) {
+ /* Computing MAX */
+ r2 = sintt, r3 = (r1 = x[i - 1] - y[i - 1], fabs(r1));
+ sintt = dmax(r2,r3);
+ x[i - 1] = xh[i - 1];
+ y[i - 1] = x[i - 1];
+ }
+ sintt = cf * sintt;
+ sint(nm1, x, w);
+ sint(nm1, x, w);
+ sintfb = 0.;
+ for (i = 1; i <= nm1; ++i) {
+ /* Computing MAX */
+ r2 = sintfb, r3 = (r1 = cf * x[i - 1] - y[i - 1], fabs(
+ r1));
+ sintfb = dmax(r2,r3);
+ }
+
+ /* TEST SUBROUTINES COSTI AND COST */
+
+ for (i = 1; i <= np1; ++i) {
+ x[i - 1] = xh[i - 1];
+ }
+ for (i = 1; i <= np1; ++i) {
+ y[i - 1] = (x[0] + (real) pow(-1, i+1) * x[n]) * .5;
+ arg = (real) (i - 1) * dt;
+ for (k = 2; k <= n; ++k) {
+ y[i - 1] += x[k - 1] * cos((real) (k - 1) * arg);
+ }
+ y[i - 1] += y[i - 1];
+ }
+ costi(np1, w);
+ cost(np1, x, w);
+ costt = 0.;
+ for (i = 1; i <= np1; ++i) {
+ /* Computing MAX */
+ r2 = costt, r3 = (r1 = x[i - 1] - y[i - 1], fabs(r1));
+ costt = dmax(r2,r3);
+ x[i - 1] = xh[i - 1];
+ y[i - 1] = xh[i - 1];
+ }
+ costt = cf * costt;
+ cost(np1, x, w);
+ cost(np1, x, w);
+ costfb = 0.;
+ for (i = 1; i <= np1; ++i) {
+ /* Computing MAX */
+ r2 = costfb, r3 = (r1 = cf * x[i - 1] - y[i - 1], fabs(
+ r1));
+ costfb = dmax(r2,r3);
+ }
+
+ /* TEST SUBROUTINES SINQI,SINQF AND SINQB */
+
+ cf = .25 / fn;
+ for (i = 1; i <= n; ++i) {
+ y[i - 1] = xh[i - 1];
+ }
+ dt = M_PI / (fn + fn);
+ for (i = 1; i <= n; ++i) {
+ x[i - 1] = 0.;
+ arg = dt * (real) i;
+ for (k = 1; k <= n; ++k) {
+ x[i - 1] += y[k - 1] * sin((real) (k + k - 1) * arg);
+ }
+ x[i - 1] *= 4.;
+ }
+ sinqi(n, w);
+ sinqb(n, y, w);
+ sinqbt = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ r2 = sinqbt, r3 = (r1 = y[i - 1] - x[i - 1], fabs(r1))
+ ;
+ sinqbt = dmax(r2,r3);
+ x[i - 1] = xh[i - 1];
+ }
+ sinqbt = cf * sinqbt;
+ for (i = 1; i <= n; ++i) {
+ arg = (real) (i + i - 1) * dt;
+ y[i - 1] = (real) pow(-1, i+1) * .5 * x[n - 1];
+ for (k = 1; k <= nm1; ++k) {
+ y[i - 1] += x[k - 1] * sin((real) k * arg);
+ }
+ y[i - 1] += y[i - 1];
+ }
+ sinqf(n, x, w);
+ sinqft = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ r2 = sinqft, r3 = (r1 = x[i - 1] - y[i - 1], fabs(r1))
+ ;
+ sinqft = dmax(r2,r3);
+ y[i - 1] = xh[i - 1];
+ x[i - 1] = xh[i - 1];
+ }
+ sinqf(n, y, w);
+ sinqb(n, y, w);
+ sinqfb = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ r2 = sinqfb, r3 = (r1 = cf * y[i - 1] - x[i - 1], fabs(
+ r1));
+ sinqfb = dmax(r2,r3);
+ }
+
+ /* TEST SUBROUTINES COSQI,COSQF AND COSQB */
+
+ for (i = 1; i <= n; ++i) {
+ y[i - 1] = xh[i - 1];
+ }
+ for (i = 1; i <= n; ++i) {
+ x[i - 1] = 0.;
+ arg = (real) (i - 1) * dt;
+ for (k = 1; k <= n; ++k) {
+ x[i - 1] += y[k - 1] * cos((real) (k + k - 1) * arg);
+ }
+ x[i - 1] *= 4.;
+ }
+ cosqi(n, w);
+ cosqb(n, y, w);
+ cosqbt = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ r2 = cosqbt, r3 = (r1 = x[i - 1] - y[i - 1], fabs(r1))
+ ;
+ cosqbt = dmax(r2,r3);
+ x[i - 1] = xh[i - 1];
+ }
+ cosqbt = cf * cosqbt;
+ for (i = 1; i <= n; ++i) {
+ y[i - 1] = x[0] * .5;
+ arg = (real) (i + i - 1) * dt;
+ for (k = 2; k <= n; ++k) {
+ y[i - 1] += x[k - 1] * cos((real) (k - 1) * arg);
+ }
+ y[i - 1] += y[i - 1];
+ }
+ cosqf(n, x, w);
+ cosqft = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ r2 = cosqft, r3 = (r1 = y[i - 1] - x[i - 1], fabs(r1))
+ ;
+ cosqft = dmax(r2,r3);
+ x[i - 1] = xh[i - 1];
+ y[i - 1] = xh[i - 1];
+ }
+ cosqft = cf * cosqft;
+ cosqb(n, x, w);
+ cosqf(n, x, w);
+ cosqfb = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ r2 = cosqfb, r3 = (r1 = cf * x[i - 1] - y[i - 1], fabs(r1));
+ cosqfb = dmax(r2,r3);
+ }
+
+ /* TEST CFFTI,CFFTF,CFFTB */
+
+ for (i = 1; i <= n; ++i) {
+ r1 = cos(sqrt2 * (real) i);
+ r2 = sin(sqrt2 * (real) (i * i));
+ q1.r = r1, q1.i = r2;
+ cx[i-1].r = q1.r, cx[i-1].i = q1.i;
+ }
+ dt = (2*M_PI) / fn;
+ for (i = 1; i <= n; ++i) {
+ arg1 = -((real) (i - 1)) * dt;
+ cy[i-1].r = 0., cy[i-1].i = 0.;
+ for (k = 1; k <= n; ++k) {
+ arg2 = (real) (k - 1) * arg1;
+ r1 = cos(arg2);
+ r2 = sin(arg2);
+ q3.r = r1, q3.i = r2;
+ q2.r = q3.r * cx[k-1].r - q3.i * cx[k-1].i, q2.i =
+ q3.r * cx[k-1].i + q3.i * cx[k-1].r;
+ q1.r = cy[i-1].r + q2.r, q1.i = cy[i-1].i + q2.i;
+ cy[i-1].r = q1.r, cy[i-1].i = q1.i;
+ }
+ }
+ cffti(n, w);
+ cfftf(n, (real*)cx, w);
+ dcfftf = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ q1.r = cx[i-1].r - cy[i-1].r, q1.i = cx[i-1].i - cy[i-1]
+ .i;
+ r1 = dcfftf, r2 = c_abs(&q1);
+ dcfftf = dmax(r1,r2);
+ q1.r = cx[i-1].r / fn, q1.i = cx[i-1].i / fn;
+ cx[i-1].r = q1.r, cx[i-1].i = q1.i;
+ }
+ dcfftf /= fn;
+ for (i = 1; i <= n; ++i) {
+ arg1 = (real) (i - 1) * dt;
+ cy[i-1].r = 0., cy[i-1].i = 0.;
+ for (k = 1; k <= n; ++k) {
+ arg2 = (real) (k - 1) * arg1;
+ r1 = cos(arg2);
+ r2 = sin(arg2);
+ q3.r = r1, q3.i = r2;
+ q2.r = q3.r * cx[k-1].r - q3.i * cx[k-1].i, q2.i =
+ q3.r * cx[k-1].i + q3.i * cx[k-1].r;
+ q1.r = cy[i-1].r + q2.r, q1.i = cy[i-1].i + q2.i;
+ cy[i-1].r = q1.r, cy[i-1].i = q1.i;
+ }
+ }
+ cfftb(n, (real*)cx, w);
+ dcfftb = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ q1.r = cx[i-1].r - cy[i-1].r, q1.i = cx[i-1].i - cy[i-1].i;
+ r1 = dcfftb, r2 = c_abs(&q1);
+ dcfftb = dmax(r1,r2);
+ cx[i-1].r = cy[i-1].r, cx[i-1].i = cy[i-1].i;
+ }
+ cf = 1. / fn;
+ cfftf(n, (real*)cx, w);
+ cfftb(n, (real*)cx, w);
+ dcfb = 0.;
+ for (i = 1; i <= n; ++i) {
+ /* Computing MAX */
+ q2.r = cf * cx[i-1].r, q2.i = cf * cx[i-1].i;
+ q1.r = q2.r - cy[i-1].r, q1.i = q2.i - cy[i-1].i;
+ r1 = dcfb, r2 = c_abs(&q1);
+ dcfb = dmax(r1,r2);
+ }
+ printf("%d\tRFFTF %10.3g\tRFFTB %10.ge\tRFFTFB %10.3g", n, rftf, rftb, rftfb);
+ printf( "\tSINT %10.3g\tSINTFB %10.ge\tCOST %10.3g\n", sintt, sintfb, costt);
+ printf( "\tCOSTFB %10.3g\tSINQF %10.ge\tSINQB %10.3g", costfb, sinqft, sinqbt);
+ printf( "\tSINQFB %10.3g\tCOSQF %10.ge\tCOSQB %10.3g\n", sinqfb, cosqft, cosqbt);
+ printf( "\tCOSQFB %10.3g\t", cosqfb);
+ printf( "\tCFFTF %10.ge\tCFFTB %10.3g\n", dcfftf, dcfftb);
+ printf( "\tCFFTFB %10.3g\n", dcfb);
+
+#define CHECK(x) if (x > 1e-3) { printf(#x " failed: %g\n", x); all_ok = 0; }
+ CHECK(rftf); CHECK(rftb); CHECK(rftfb); CHECK(sintt); CHECK(sintfb); CHECK(costt);
+ CHECK(costfb); CHECK(sinqft); CHECK(sinqbt); CHECK(sinqfb); CHECK(cosqft); CHECK(cosqbt);
+ CHECK(cosqfb); CHECK(dcfftf); CHECK(dcfftb);
+ }
+
+ if (all_ok) printf("Everything looks fine.\n");
+ else printf("ERRORS WERE DETECTED.\n");
+ /*
+ expected:
+ 120 RFFTF 2.786e-06 RFFTB 6.847e-04 RFFTFB 2.795e-07 SINT 1.312e-06 SINTFB 1.237e-06 COST 1.319e-06
+ COSTFB 4.355e-06 SINQF 3.281e-04 SINQB 1.876e-06 SINQFB 2.198e-07 COSQF 6.199e-07 COSQB 2.193e-06
+ COSQFB 2.300e-07 DEZF 5.573e-06 DEZB 1.363e-05 DEZFB 1.371e-06 CFFTF 5.590e-06 CFFTB 4.751e-05
+ CFFTFB 4.215e-07
+ 54 RFFTF 4.708e-07 RFFTB 3.052e-05 RFFTFB 3.439e-07 SINT 3.532e-07 SINTFB 4.145e-07 COST 3.002e-07
+ COSTFB 6.343e-07 SINQF 4.959e-05 SINQB 4.415e-07 SINQFB 2.882e-07 COSQF 2.826e-07 COSQB 2.472e-07
+ COSQFB 3.439e-07 DEZF 9.388e-07 DEZB 5.066e-06 DEZFB 5.960e-07 CFFTF 1.426e-06 CFFTB 9.482e-06
+ CFFTFB 2.980e-07
+ 49 RFFTF 4.476e-07 RFFTB 5.341e-05 RFFTFB 2.574e-07 SINT 9.196e-07 SINTFB 9.401e-07 COST 8.174e-07
+ COSTFB 1.331e-06 SINQF 4.005e-05 SINQB 9.342e-07 SINQFB 3.057e-07 COSQF 2.530e-07 COSQB 6.228e-07
+ COSQFB 4.826e-07 DEZF 9.071e-07 DEZB 4.590e-06 DEZFB 5.960e-07 CFFTF 2.095e-06 CFFTB 1.414e-05
+ CFFTFB 7.398e-07
+ 32 RFFTF 4.619e-07 RFFTB 2.861e-05 RFFTFB 1.192e-07 SINT 3.874e-07 SINTFB 4.172e-07 COST 4.172e-07
+ COSTFB 1.699e-06 SINQF 2.551e-05 SINQB 6.407e-07 SINQFB 2.980e-07 COSQF 1.639e-07 COSQB 1.714e-07
+ COSQFB 2.384e-07 DEZF 1.013e-06 DEZB 2.339e-06 DEZFB 7.749e-07 CFFTF 1.127e-06 CFFTB 6.744e-06
+ CFFTFB 2.666e-07
+ 4 RFFTF 1.490e-08 RFFTB 1.490e-07 RFFTFB 5.960e-08 SINT 7.451e-09 SINTFB 0.000e+00 COST 2.980e-08
+ COSTFB 1.192e-07 SINQF 4.768e-07 SINQB 2.980e-08 SINQFB 5.960e-08 COSQF 2.608e-08 COSQB 5.960e-08
+ COSQFB 1.192e-07 DEZF 2.980e-08 DEZB 5.960e-08 DEZFB 0.000e+00 CFFTF 6.664e-08 CFFTB 5.960e-08
+ CFFTFB 6.144e-08
+ 3 RFFTF 3.974e-08 RFFTB 1.192e-07 RFFTFB 3.303e-08 SINT 1.987e-08 SINTFB 1.069e-08 COST 4.967e-08
+ COSTFB 5.721e-08 SINQF 8.941e-08 SINQB 2.980e-08 SINQFB 1.259e-07 COSQF 7.451e-09 COSQB 4.967e-08
+ COSQFB 7.029e-08 DEZF 1.192e-07 DEZB 5.960e-08 DEZFB 5.960e-08 CFFTF 7.947e-08 CFFTB 8.429e-08
+ CFFTFB 9.064e-08
+ 2 RFFTF 0.000e+00 RFFTB 0.000e+00 RFFTFB 0.000e+00 SINT 0.000e+00 SINTFB 0.000e+00 COST 0.000e+00
+ COSTFB 0.000e+00 SINQF 1.192e-07 SINQB 2.980e-08 SINQFB 5.960e-08 COSQF 7.451e-09 COSQB 1.490e-08
+ COSQFB 0.000e+00 DEZF 0.000e+00 DEZB 0.000e+00 DEZFB 0.000e+00 CFFTF 0.000e+00 CFFTB 5.960e-08
+ CFFTFB 5.960e-08
+ Everything looks fine.
+
+ */
+
+ return all_ok ? 0 : 1;
+}
+#endif //TESTING_FFTPACK
diff --git a/src/3rdparty/pffft/fftpack.h b/src/3rdparty/pffft/fftpack.h
new file mode 100644
index 000000000..381bcc61d
--- /dev/null
+++ b/src/3rdparty/pffft/fftpack.h
@@ -0,0 +1,799 @@
+/*
+ Interface for the f2c translation of fftpack as found on http://www.netlib.org/fftpack/
+
+ FFTPACK license:
+
+ http://www.cisl.ucar.edu/css/software/fftpack5/ftpk.html
+
+ Copyright (c) 2004 the University Corporation for Atmospheric
+ Research ("UCAR"). All rights reserved. Developed by NCAR's
+ Computational and Information Systems Laboratory, UCAR,
+ www.cisl.ucar.edu.
+
+ Redistribution and use of the Software in source and binary forms,
+ with or without modification, is permitted provided that the
+ following conditions are met:
+
+ - Neither the names of NCAR's Computational and Information Systems
+ Laboratory, the University Corporation for Atmospheric Research,
+ nor the names of its sponsors or contributors may be used to
+ endorse or promote products derived from this Software without
+ specific prior written permission.
+
+ - Redistributions of source code must retain the above copyright
+ notices, this list of conditions, and the disclaimer below.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions, and the disclaimer below in the
+ documentation and/or other materials provided with the
+ distribution.
+
+ THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+ SOFTWARE.
+
+ ChangeLog:
+ 2011/10/02: this is my first release of this file.
+*/
+
+#ifndef FFTPACK_H
+#define FFTPACK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// just define FFTPACK_DOUBLE_PRECISION if you want to build it as a double precision fft
+
+#ifndef FFTPACK_DOUBLE_PRECISION
+ typedef float fftpack_real;
+ typedef int fftpack_int;
+#else
+ typedef double fftpack_real;
+ typedef int fftpack_int;
+#endif
+
+ void cffti(fftpack_int n, fftpack_real *wsave);
+
+ void cfftf(fftpack_int n, fftpack_real *c, fftpack_real *wsave);
+
+ void cfftb(fftpack_int n, fftpack_real *c, fftpack_real *wsave);
+
+ void rffti(fftpack_int n, fftpack_real *wsave);
+ void rfftf(fftpack_int n, fftpack_real *r, fftpack_real *wsave);
+ void rfftb(fftpack_int n, fftpack_real *r, fftpack_real *wsave);
+
+ void cosqi(fftpack_int n, fftpack_real *wsave);
+ void cosqf(fftpack_int n, fftpack_real *x, fftpack_real *wsave);
+ void cosqb(fftpack_int n, fftpack_real *x, fftpack_real *wsave);
+
+ void costi(fftpack_int n, fftpack_real *wsave);
+ void cost(fftpack_int n, fftpack_real *x, fftpack_real *wsave);
+
+ void sinqi(fftpack_int n, fftpack_real *wsave);
+ void sinqb(fftpack_int n, fftpack_real *x, fftpack_real *wsave);
+ void sinqf(fftpack_int n, fftpack_real *x, fftpack_real *wsave);
+
+ void sinti(fftpack_int n, fftpack_real *wsave);
+ void sint(fftpack_int n, fftpack_real *x, fftpack_real *wsave);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FFTPACK_H */
+
+/*
+
+ FFTPACK
+
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+ version 4 april 1985
+
+ a package of fortran subprograms for the fast fourier
+ transform of periodic and other symmetric sequences
+
+ by
+
+ paul n swarztrauber
+
+ national center for atmospheric research boulder,colorado 80307
+
+ which is sponsored by the national science foundation
+
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+
+this package consists of programs which perform fast fourier
+transforms for both complex and real periodic sequences and
+certain other symmetric sequences that are listed below.
+
+1. rffti initialize rfftf and rfftb
+2. rfftf forward transform of a real periodic sequence
+3. rfftb backward transform of a real coefficient array
+
+4. ezffti initialize ezfftf and ezfftb
+5. ezfftf a simplified real periodic forward transform
+6. ezfftb a simplified real periodic backward transform
+
+7. sinti initialize sint
+8. sint sine transform of a real odd sequence
+
+9. costi initialize cost
+10. cost cosine transform of a real even sequence
+
+11. sinqi initialize sinqf and sinqb
+12. sinqf forward sine transform with odd wave numbers
+13. sinqb unnormalized inverse of sinqf
+
+14. cosqi initialize cosqf and cosqb
+15. cosqf forward cosine transform with odd wave numbers
+16. cosqb unnormalized inverse of cosqf
+
+17. cffti initialize cfftf and cfftb
+18. cfftf forward transform of a complex periodic sequence
+19. cfftb unnormalized inverse of cfftf
+
+
+******************************************************************
+
+subroutine rffti(n,wsave)
+
+ ****************************************************************
+
+subroutine rffti initializes the array wsave which is used in
+both rfftf and rfftb. the prime factorization of n together with
+a tabulation of the trigonometric functions are computed and
+stored in wsave.
+
+input parameter
+
+n the length of the sequence to be transformed.
+
+output parameter
+
+wsave a work array which must be dimensioned at least 2*n+15.
+ the same work array can be used for both rfftf and rfftb
+ as long as n remains unchanged. different wsave arrays
+ are required for different values of n. the contents of
+ wsave must not be changed between calls of rfftf or rfftb.
+
+******************************************************************
+
+subroutine rfftf(n,r,wsave)
+
+******************************************************************
+
+subroutine rfftf computes the fourier coefficients of a real
+perodic sequence (fourier analysis). the transform is defined
+below at output parameter r.
+
+input parameters
+
+n the length of the array r to be transformed. the method
+ is most efficient when n is a product of small primes.
+ n may change so long as different work arrays are provided
+
+r a real array of length n which contains the sequence
+ to be transformed
+
+wsave a work array which must be dimensioned at least 2*n+15.
+ in the program that calls rfftf. the wsave array must be
+ initialized by calling subroutine rffti(n,wsave) and a
+ different wsave array must be used for each different
+ value of n. this initialization does not have to be
+ repeated so long as n remains unchanged thus subsequent
+ transforms can be obtained faster than the first.
+ the same wsave array can be used by rfftf and rfftb.
+
+
+output parameters
+
+r r(1) = the sum from i=1 to i=n of r(i)
+
+ if n is even set l =n/2 , if n is odd set l = (n+1)/2
+
+ then for k = 2,...,l
+
+ r(2*k-2) = the sum from i = 1 to i = n of
+
+ r(i)*cos((k-1)*(i-1)*2*pi/n)
+
+ r(2*k-1) = the sum from i = 1 to i = n of
+
+ -r(i)*sin((k-1)*(i-1)*2*pi/n)
+
+ if n is even
+
+ r(n) = the sum from i = 1 to i = n of
+
+ (-1)**(i-1)*r(i)
+
+ ***** note
+ this transform is unnormalized since a call of rfftf
+ followed by a call of rfftb will multiply the input
+ sequence by n.
+
+wsave contains results which must not be destroyed between
+ calls of rfftf or rfftb.
+
+
+******************************************************************
+
+subroutine rfftb(n,r,wsave)
+
+******************************************************************
+
+subroutine rfftb computes the real perodic sequence from its
+fourier coefficients (fourier synthesis). the transform is defined
+below at output parameter r.
+
+input parameters
+
+n the length of the array r to be transformed. the method
+ is most efficient when n is a product of small primes.
+ n may change so long as different work arrays are provided
+
+r a real array of length n which contains the sequence
+ to be transformed
+
+wsave a work array which must be dimensioned at least 2*n+15.
+ in the program that calls rfftb. the wsave array must be
+ initialized by calling subroutine rffti(n,wsave) and a
+ different wsave array must be used for each different
+ value of n. this initialization does not have to be
+ repeated so long as n remains unchanged thus subsequent
+ transforms can be obtained faster than the first.
+ the same wsave array can be used by rfftf and rfftb.
+
+
+output parameters
+
+r for n even and for i = 1,...,n
+
+ r(i) = r(1)+(-1)**(i-1)*r(n)
+
+ plus the sum from k=2 to k=n/2 of
+
+ 2.*r(2*k-2)*cos((k-1)*(i-1)*2*pi/n)
+
+ -2.*r(2*k-1)*sin((k-1)*(i-1)*2*pi/n)
+
+ for n odd and for i = 1,...,n
+
+ r(i) = r(1) plus the sum from k=2 to k=(n+1)/2 of
+
+ 2.*r(2*k-2)*cos((k-1)*(i-1)*2*pi/n)
+
+ -2.*r(2*k-1)*sin((k-1)*(i-1)*2*pi/n)
+
+ ***** note
+ this transform is unnormalized since a call of rfftf
+ followed by a call of rfftb will multiply the input
+ sequence by n.
+
+wsave contains results which must not be destroyed between
+ calls of rfftb or rfftf.
+
+******************************************************************
+
+subroutine sinti(n,wsave)
+
+******************************************************************
+
+subroutine sinti initializes the array wsave which is used in
+subroutine sint. the prime factorization of n together with
+a tabulation of the trigonometric functions are computed and
+stored in wsave.
+
+input parameter
+
+n the length of the sequence to be transformed. the method
+ is most efficient when n+1 is a product of small primes.
+
+output parameter
+
+wsave a work array with at least int(2.5*n+15) locations.
+ different wsave arrays are required for different values
+ of n. the contents of wsave must not be changed between
+ calls of sint.
+
+******************************************************************
+
+subroutine sint(n,x,wsave)
+
+******************************************************************
+
+subroutine sint computes the discrete fourier sine transform
+of an odd sequence x(i). the transform is defined below at
+output parameter x.
+
+sint is the unnormalized inverse of itself since a call of sint
+followed by another call of sint will multiply the input sequence
+x by 2*(n+1).
+
+the array wsave which is used by subroutine sint must be
+initialized by calling subroutine sinti(n,wsave).
+
+input parameters
+
+n the length of the sequence to be transformed. the method
+ is most efficient when n+1 is the product of small primes.
+
+x an array which contains the sequence to be transformed
+
+
+wsave a work array with dimension at least int(2.5*n+15)
+ in the program that calls sint. the wsave array must be
+ initialized by calling subroutine sinti(n,wsave) and a
+ different wsave array must be used for each different
+ value of n. this initialization does not have to be
+ repeated so long as n remains unchanged thus subsequent
+ transforms can be obtained faster than the first.
+
+output parameters
+
+x for i=1,...,n
+
+ x(i)= the sum from k=1 to k=n
+
+ 2*x(k)*sin(k*i*pi/(n+1))
+
+ a call of sint followed by another call of
+ sint will multiply the sequence x by 2*(n+1).
+ hence sint is the unnormalized inverse
+ of itself.
+
+wsave contains initialization calculations which must not be
+ destroyed between calls of sint.
+
+******************************************************************
+
+subroutine costi(n,wsave)
+
+******************************************************************
+
+subroutine costi initializes the array wsave which is used in
+subroutine cost. the prime factorization of n together with
+a tabulation of the trigonometric functions are computed and
+stored in wsave.
+
+input parameter
+
+n the length of the sequence to be transformed. the method
+ is most efficient when n-1 is a product of small primes.
+
+output parameter
+
+wsave a work array which must be dimensioned at least 3*n+15.
+ different wsave arrays are required for different values
+ of n. the contents of wsave must not be changed between
+ calls of cost.
+
+******************************************************************
+
+subroutine cost(n,x,wsave)
+
+******************************************************************
+
+subroutine cost computes the discrete fourier cosine transform
+of an even sequence x(i). the transform is defined below at output
+parameter x.
+
+cost is the unnormalized inverse of itself since a call of cost
+followed by another call of cost will multiply the input sequence
+x by 2*(n-1). the transform is defined below at output parameter x
+
+the array wsave which is used by subroutine cost must be
+initialized by calling subroutine costi(n,wsave).
+
+input parameters
+
+n the length of the sequence x. n must be greater than 1.
+ the method is most efficient when n-1 is a product of
+ small primes.
+
+x an array which contains the sequence to be transformed
+
+wsave a work array which must be dimensioned at least 3*n+15
+ in the program that calls cost. the wsave array must be
+ initialized by calling subroutine costi(n,wsave) and a
+ different wsave array must be used for each different
+ value of n. this initialization does not have to be
+ repeated so long as n remains unchanged thus subsequent
+ transforms can be obtained faster than the first.
+
+output parameters
+
+x for i=1,...,n
+
+ x(i) = x(1)+(-1)**(i-1)*x(n)
+
+ + the sum from k=2 to k=n-1
+
+ 2*x(k)*cos((k-1)*(i-1)*pi/(n-1))
+
+ a call of cost followed by another call of
+ cost will multiply the sequence x by 2*(n-1)
+ hence cost is the unnormalized inverse
+ of itself.
+
+wsave contains initialization calculations which must not be
+ destroyed between calls of cost.
+
+******************************************************************
+
+subroutine sinqi(n,wsave)
+
+******************************************************************
+
+subroutine sinqi initializes the array wsave which is used in
+both sinqf and sinqb. the prime factorization of n together with
+a tabulation of the trigonometric functions are computed and
+stored in wsave.
+
+input parameter
+
+n the length of the sequence to be transformed. the method
+ is most efficient when n is a product of small primes.
+
+output parameter
+
+wsave a work array which must be dimensioned at least 3*n+15.
+ the same work array can be used for both sinqf and sinqb
+ as long as n remains unchanged. different wsave arrays
+ are required for different values of n. the contents of
+ wsave must not be changed between calls of sinqf or sinqb.
+
+******************************************************************
+
+subroutine sinqf(n,x,wsave)
+
+******************************************************************
+
+subroutine sinqf computes the fast fourier transform of quarter
+wave data. that is , sinqf computes the coefficients in a sine
+series representation with only odd wave numbers. the transform
+is defined below at output parameter x.
+
+sinqb is the unnormalized inverse of sinqf since a call of sinqf
+followed by a call of sinqb will multiply the input sequence x
+by 4*n.
+
+the array wsave which is used by subroutine sinqf must be
+initialized by calling subroutine sinqi(n,wsave).
+
+
+input parameters
+
+n the length of the array x to be transformed. the method
+ is most efficient when n is a product of small primes.
+
+x an array which contains the sequence to be transformed
+
+wsave a work array which must be dimensioned at least 3*n+15.
+ in the program that calls sinqf. the wsave array must be
+ initialized by calling subroutine sinqi(n,wsave) and a
+ different wsave array must be used for each different
+ value of n. this initialization does not have to be
+ repeated so long as n remains unchanged thus subsequent
+ transforms can be obtained faster than the first.
+
+output parameters
+
+x for i=1,...,n
+
+ x(i) = (-1)**(i-1)*x(n)
+
+ + the sum from k=1 to k=n-1 of
+
+ 2*x(k)*sin((2*i-1)*k*pi/(2*n))
+
+ a call of sinqf followed by a call of
+ sinqb will multiply the sequence x by 4*n.
+ therefore sinqb is the unnormalized inverse
+ of sinqf.
+
+wsave contains initialization calculations which must not
+ be destroyed between calls of sinqf or sinqb.
+
+******************************************************************
+
+subroutine sinqb(n,x,wsave)
+
+******************************************************************
+
+subroutine sinqb computes the fast fourier transform of quarter
+wave data. that is , sinqb computes a sequence from its
+representation in terms of a sine series with odd wave numbers.
+the transform is defined below at output parameter x.
+
+sinqf is the unnormalized inverse of sinqb since a call of sinqb
+followed by a call of sinqf will multiply the input sequence x
+by 4*n.
+
+the array wsave which is used by subroutine sinqb must be
+initialized by calling subroutine sinqi(n,wsave).
+
+
+input parameters
+
+n the length of the array x to be transformed. the method
+ is most efficient when n is a product of small primes.
+
+x an array which contains the sequence to be transformed
+
+wsave a work array which must be dimensioned at least 3*n+15.
+ in the program that calls sinqb. the wsave array must be
+ initialized by calling subroutine sinqi(n,wsave) and a
+ different wsave array must be used for each different
+ value of n. this initialization does not have to be
+ repeated so long as n remains unchanged thus subsequent
+ transforms can be obtained faster than the first.
+
+output parameters
+
+x for i=1,...,n
+
+ x(i)= the sum from k=1 to k=n of
+
+ 4*x(k)*sin((2k-1)*i*pi/(2*n))
+
+ a call of sinqb followed by a call of
+ sinqf will multiply the sequence x by 4*n.
+ therefore sinqf is the unnormalized inverse
+ of sinqb.
+
+wsave contains initialization calculations which must not
+ be destroyed between calls of sinqb or sinqf.
+
+******************************************************************
+
+subroutine cosqi(n,wsave)
+
+******************************************************************
+
+subroutine cosqi initializes the array wsave which is used in
+both cosqf and cosqb. the prime factorization of n together with
+a tabulation of the trigonometric functions are computed and
+stored in wsave.
+
+input parameter
+
+n the length of the array to be transformed. the method
+ is most efficient when n is a product of small primes.
+
+output parameter
+
+wsave a work array which must be dimensioned at least 3*n+15.
+ the same work array can be used for both cosqf and cosqb
+ as long as n remains unchanged. different wsave arrays
+ are required for different values of n. the contents of
+ wsave must not be changed between calls of cosqf or cosqb.
+
+******************************************************************
+
+subroutine cosqf(n,x,wsave)
+
+******************************************************************
+
+subroutine cosqf computes the fast fourier transform of quarter
+wave data. that is , cosqf computes the coefficients in a cosine
+series representation with only odd wave numbers. the transform
+is defined below at output parameter x
+
+cosqf is the unnormalized inverse of cosqb since a call of cosqf
+followed by a call of cosqb will multiply the input sequence x
+by 4*n.
+
+the array wsave which is used by subroutine cosqf must be
+initialized by calling subroutine cosqi(n,wsave).
+
+
+input parameters
+
+n the length of the array x to be transformed. the method
+ is most efficient when n is a product of small primes.
+
+x an array which contains the sequence to be transformed
+
+wsave a work array which must be dimensioned at least 3*n+15
+ in the program that calls cosqf. the wsave array must be
+ initialized by calling subroutine cosqi(n,wsave) and a
+ different wsave array must be used for each different
+ value of n. this initialization does not have to be
+ repeated so long as n remains unchanged thus subsequent
+ transforms can be obtained faster than the first.
+
+output parameters
+
+x for i=1,...,n
+
+ x(i) = x(1) plus the sum from k=2 to k=n of
+
+ 2*x(k)*cos((2*i-1)*(k-1)*pi/(2*n))
+
+ a call of cosqf followed by a call of
+ cosqb will multiply the sequence x by 4*n.
+ therefore cosqb is the unnormalized inverse
+ of cosqf.
+
+wsave contains initialization calculations which must not
+ be destroyed between calls of cosqf or cosqb.
+
+******************************************************************
+
+subroutine cosqb(n,x,wsave)
+
+******************************************************************
+
+subroutine cosqb computes the fast fourier transform of quarter
+wave data. that is , cosqb computes a sequence from its
+representation in terms of a cosine series with odd wave numbers.
+the transform is defined below at output parameter x.
+
+cosqb is the unnormalized inverse of cosqf since a call of cosqb
+followed by a call of cosqf will multiply the input sequence x
+by 4*n.
+
+the array wsave which is used by subroutine cosqb must be
+initialized by calling subroutine cosqi(n,wsave).
+
+
+input parameters
+
+n the length of the array x to be transformed. the method
+ is most efficient when n is a product of small primes.
+
+x an array which contains the sequence to be transformed
+
+wsave a work array that must be dimensioned at least 3*n+15
+ in the program that calls cosqb. the wsave array must be
+ initialized by calling subroutine cosqi(n,wsave) and a
+ different wsave array must be used for each different
+ value of n. this initialization does not have to be
+ repeated so long as n remains unchanged thus subsequent
+ transforms can be obtained faster than the first.
+
+output parameters
+
+x for i=1,...,n
+
+ x(i)= the sum from k=1 to k=n of
+
+ 4*x(k)*cos((2*k-1)*(i-1)*pi/(2*n))
+
+ a call of cosqb followed by a call of
+ cosqf will multiply the sequence x by 4*n.
+ therefore cosqf is the unnormalized inverse
+ of cosqb.
+
+wsave contains initialization calculations which must not
+ be destroyed between calls of cosqb or cosqf.
+
+******************************************************************
+
+subroutine cffti(n,wsave)
+
+******************************************************************
+
+subroutine cffti initializes the array wsave which is used in
+both cfftf and cfftb. the prime factorization of n together with
+a tabulation of the trigonometric functions are computed and
+stored in wsave.
+
+input parameter
+
+n the length of the sequence to be transformed
+
+output parameter
+
+wsave a work array which must be dimensioned at least 4*n+15
+ the same work array can be used for both cfftf and cfftb
+ as long as n remains unchanged. different wsave arrays
+ are required for different values of n. the contents of
+ wsave must not be changed between calls of cfftf or cfftb.
+
+******************************************************************
+
+subroutine cfftf(n,c,wsave)
+
+******************************************************************
+
+subroutine cfftf computes the forward complex discrete fourier
+transform (the fourier analysis). equivalently , cfftf computes
+the fourier coefficients of a complex periodic sequence.
+the transform is defined below at output parameter c.
+
+the transform is not normalized. to obtain a normalized transform
+the output must be divided by n. otherwise a call of cfftf
+followed by a call of cfftb will multiply the sequence by n.
+
+the array wsave which is used by subroutine cfftf must be
+initialized by calling subroutine cffti(n,wsave).
+
+input parameters
+
+
+n the length of the complex sequence c. the method is
+ more efficient when n is the product of small primes. n
+
+c a complex array of length n which contains the sequence
+
+wsave a real work array which must be dimensioned at least 4n+15
+ in the program that calls cfftf. the wsave array must be
+ initialized by calling subroutine cffti(n,wsave) and a
+ different wsave array must be used for each different
+ value of n. this initialization does not have to be
+ repeated so long as n remains unchanged thus subsequent
+ transforms can be obtained faster than the first.
+ the same wsave array can be used by cfftf and cfftb.
+
+output parameters
+
+c for j=1,...,n
+
+ c(j)=the sum from k=1,...,n of
+
+ c(k)*exp(-i*(j-1)*(k-1)*2*pi/n)
+
+ where i=sqrt(-1)
+
+wsave contains initialization calculations which must not be
+ destroyed between calls of subroutine cfftf or cfftb
+
+******************************************************************
+
+subroutine cfftb(n,c,wsave)
+
+******************************************************************
+
+subroutine cfftb computes the backward complex discrete fourier
+transform (the fourier synthesis). equivalently , cfftb computes
+a complex periodic sequence from its fourier coefficients.
+the transform is defined below at output parameter c.
+
+a call of cfftf followed by a call of cfftb will multiply the
+sequence by n.
+
+the array wsave which is used by subroutine cfftb must be
+initialized by calling subroutine cffti(n,wsave).
+
+input parameters
+
+
+n the length of the complex sequence c. the method is
+ more efficient when n is the product of small primes.
+
+c a complex array of length n which contains the sequence
+
+wsave a real work array which must be dimensioned at least 4n+15
+ in the program that calls cfftb. the wsave array must be
+ initialized by calling subroutine cffti(n,wsave) and a
+ different wsave array must be used for each different
+ value of n. this initialization does not have to be
+ repeated so long as n remains unchanged thus subsequent
+ transforms can be obtained faster than the first.
+ the same wsave array can be used by cfftf and cfftb.
+
+output parameters
+
+c for j=1,...,n
+
+ c(j)=the sum from k=1,...,n of
+
+ c(k)*exp(i*(j-1)*(k-1)*2*pi/n)
+
+ where i=sqrt(-1)
+
+wsave contains initialization calculations which must not be
+ destroyed between calls of subroutine cfftf or cfftb
+
+*/
diff --git a/src/3rdparty/pffft/pffft.c b/src/3rdparty/pffft/pffft.c
new file mode 100644
index 000000000..9271a9ad9
--- /dev/null
+++ b/src/3rdparty/pffft/pffft.c
@@ -0,0 +1,1885 @@
+/* Copyright (c) 2013 Julien Pommier ( pommier@modartt.com )
+
+ Based on original fortran 77 code from FFTPACKv4 from NETLIB
+ (http://www.netlib.org/fftpack), authored by Dr Paul Swarztrauber
+ of NCAR, in 1985.
+
+ As confirmed by the NCAR fftpack software curators, the following
+ FFTPACKv5 license applies to FFTPACKv4 sources. My changes are
+ released under the same terms.
+
+ FFTPACK license:
+
+ http://www.cisl.ucar.edu/css/software/fftpack5/ftpk.html
+
+ Copyright (c) 2004 the University Corporation for Atmospheric
+ Research ("UCAR"). All rights reserved. Developed by NCAR's
+ Computational and Information Systems Laboratory, UCAR,
+ www.cisl.ucar.edu.
+
+ Redistribution and use of the Software in source and binary forms,
+ with or without modification, is permitted provided that the
+ following conditions are met:
+
+ - Neither the names of NCAR's Computational and Information Systems
+ Laboratory, the University Corporation for Atmospheric Research,
+ nor the names of its sponsors or contributors may be used to
+ endorse or promote products derived from this Software without
+ specific prior written permission.
+
+ - Redistributions of source code must retain the above copyright
+ notices, this list of conditions, and the disclaimer below.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions, and the disclaimer below in the
+ documentation and/or other materials provided with the
+ distribution.
+
+ THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+ SOFTWARE.
+
+
+ PFFFT : a Pretty Fast FFT.
+
+ This file is largerly based on the original FFTPACK implementation, modified in
+ order to take advantage of SIMD instructions of modern CPUs.
+*/
+
+/*
+ ChangeLog:
+ - 2011/10/02, version 1: This is the very first release of this file.
+*/
+
+#include "pffft.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <assert.h>
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846264338327950288
+#endif
+#ifndef M_SQRT2
+#define M_SQRT2 1.41421356237309504880168872420969808
+#endif
+
+/* detect compiler flavour */
+#if defined(_MSC_VER)
+# define COMPILER_MSVC
+#elif defined(__GNUC__)
+# define COMPILER_GCC
+#endif
+
+#if defined(COMPILER_GCC)
+# define ALWAYS_INLINE(return_type) inline return_type __attribute__ ((always_inline))
+# define NEVER_INLINE(return_type) return_type __attribute__ ((noinline))
+# define RESTRICT __restrict
+# define VLA_ARRAY_ON_STACK(type__, varname__, size__) type__ varname__[size__];
+#elif defined(COMPILER_MSVC)
+# define ALWAYS_INLINE(return_type) __forceinline return_type
+# define NEVER_INLINE(return_type) __declspec(noinline) return_type
+# define RESTRICT __restrict
+# define VLA_ARRAY_ON_STACK(type__, varname__, size__) type__ *varname__ = (type__*)_alloca(size__ * sizeof(type__))
+#endif
+
+
+/*
+ vector support macros: the rest of the code is independant of
+ SSE/Altivec/NEON -- adding support for other platforms with 4-element
+ vectors should be limited to these macros
+*/
+
+
+// define PFFFT_SIMD_DISABLE if you want to use scalar code instead of simd code
+//#define PFFFT_SIMD_DISABLE
+
+/*
+ Altivec support macros
+*/
+#if !defined(PFFFT_SIMD_DISABLE) && (defined(__ppc__) || defined(__ppc64__) || defined(__powerpc__) || defined(__powerpc64__))
+#include <altivec.h>
+typedef vector float v4sf;
+# define SIMD_SZ 4
+# define VZERO() ((vector float) vec_splat_u8(0))
+# define VMUL(a,b) vec_madd(a,b, VZERO())
+# define VADD(a,b) vec_add(a,b)
+# define VMADD(a,b,c) vec_madd(a,b,c)
+# define VSUB(a,b) vec_sub(a,b)
+inline v4sf ld_ps1(const float *p) { v4sf v=vec_lde(0,p); return vec_splat(vec_perm(v, v, vec_lvsl(0, p)), 0); }
+# define LD_PS1(p) ld_ps1(&p)
+# define INTERLEAVE2(in1, in2, out1, out2) { v4sf tmp__ = vec_mergeh(in1, in2); out2 = vec_mergel(in1, in2); out1 = tmp__; }
+# define UNINTERLEAVE2(in1, in2, out1, out2) { \
+ vector unsigned char vperm1 = (vector unsigned char){0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27}; \
+ vector unsigned char vperm2 = (vector unsigned char){4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31}; \
+ v4sf tmp__ = vec_perm(in1, in2, vperm1); out2 = vec_perm(in1, in2, vperm2); out1 = tmp__; \
+ }
+# define VTRANSPOSE4(x0,x1,x2,x3) { \
+ v4sf y0 = vec_mergeh(x0, x2); \
+ v4sf y1 = vec_mergel(x0, x2); \
+ v4sf y2 = vec_mergeh(x1, x3); \
+ v4sf y3 = vec_mergel(x1, x3); \
+ x0 = vec_mergeh(y0, y2); \
+ x1 = vec_mergel(y0, y2); \
+ x2 = vec_mergeh(y1, y3); \
+ x3 = vec_mergel(y1, y3); \
+ }
+# define VSWAPHL(a,b) vec_perm(a,b, (vector unsigned char){16,17,18,19,20,21,22,23,8,9,10,11,12,13,14,15})
+# define VALIGNED(ptr) ((((long long)(ptr)) & 0xF) == 0)
+
+/*
+ SSE1 support macros
+*/
+#elif !defined(PFFFT_SIMD_DISABLE) && (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(i386) || defined(_M_IX86))
+
+#include <xmmintrin.h>
+typedef __m128 v4sf;
+# define SIMD_SZ 4 // 4 floats by simd vector -- this is pretty much hardcoded in the preprocess/finalize functions anyway so you will have to work if you want to enable AVX with its 256-bit vectors.
+# define VZERO() _mm_setzero_ps()
+# define VMUL(a,b) _mm_mul_ps(a,b)
+# define VADD(a,b) _mm_add_ps(a,b)
+# define VMADD(a,b,c) _mm_add_ps(_mm_mul_ps(a,b), c)
+# define VSUB(a,b) _mm_sub_ps(a,b)
+# define LD_PS1(p) _mm_set1_ps(p)
+# define INTERLEAVE2(in1, in2, out1, out2) { v4sf tmp__ = _mm_unpacklo_ps(in1, in2); out2 = _mm_unpackhi_ps(in1, in2); out1 = tmp__; }
+# define UNINTERLEAVE2(in1, in2, out1, out2) { v4sf tmp__ = _mm_shuffle_ps(in1, in2, _MM_SHUFFLE(2,0,2,0)); out2 = _mm_shuffle_ps(in1, in2, _MM_SHUFFLE(3,1,3,1)); out1 = tmp__; }
+# define VTRANSPOSE4(x0,x1,x2,x3) _MM_TRANSPOSE4_PS(x0,x1,x2,x3)
+# define VSWAPHL(a,b) _mm_shuffle_ps(b, a, _MM_SHUFFLE(3,2,1,0))
+# define VALIGNED(ptr) ((((long long)(ptr)) & 0xF) == 0)
+
+/*
+ ARM NEON support macros
+*/
+#elif !defined(PFFFT_SIMD_DISABLE) && \
+ (((defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM)) && defined(__ARM_NEON__)) || \
+ defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__))
+# include <arm_neon.h>
+typedef float32x4_t v4sf;
+# define SIMD_SZ 4
+# define VZERO() vdupq_n_f32(0)
+# define VMUL(a,b) vmulq_f32(a,b)
+# define VADD(a,b) vaddq_f32(a,b)
+# define VMADD(a,b,c) vmlaq_f32(c,a,b)
+# define VSUB(a,b) vsubq_f32(a,b)
+# define LD_PS1(p) vld1q_dup_f32(&(p))
+# define INTERLEAVE2(in1, in2, out1, out2) { float32x4x2_t tmp__ = vzipq_f32(in1,in2); out1=tmp__.val[0]; out2=tmp__.val[1]; }
+# define UNINTERLEAVE2(in1, in2, out1, out2) { float32x4x2_t tmp__ = vuzpq_f32(in1,in2); out1=tmp__.val[0]; out2=tmp__.val[1]; }
+# define VTRANSPOSE4(x0,x1,x2,x3) { \
+ float32x4x2_t t0_ = vzipq_f32(x0, x2); \
+ float32x4x2_t t1_ = vzipq_f32(x1, x3); \
+ float32x4x2_t u0_ = vzipq_f32(t0_.val[0], t1_.val[0]); \
+ float32x4x2_t u1_ = vzipq_f32(t0_.val[1], t1_.val[1]); \
+ x0 = u0_.val[0]; x1 = u0_.val[1]; x2 = u1_.val[0]; x3 = u1_.val[1]; \
+ }
+// marginally faster version
+//# define VTRANSPOSE4(x0,x1,x2,x3) { asm("vtrn.32 %q0, %q1;\n vtrn.32 %q2,%q3\n vswp %f0,%e2\n vswp %f1,%e3" : "+w"(x0), "+w"(x1), "+w"(x2), "+w"(x3)::); }
+# define VSWAPHL(a,b) vcombine_f32(vget_low_f32(b), vget_high_f32(a))
+# define VALIGNED(ptr) ((((long long)(ptr)) & 0x3) == 0)
+#else
+# if !defined(PFFFT_SIMD_DISABLE)
+# warning "building with simd disabled !\n";
+# define PFFFT_SIMD_DISABLE // fallback to scalar code
+# endif
+#endif
+
+// fallback mode for situations where SSE/Altivec are not available, use scalar mode instead
+#ifdef PFFFT_SIMD_DISABLE
+typedef float v4sf;
+# define SIMD_SZ 1
+# define VZERO() 0.f
+# define VMUL(a,b) ((a)*(b))
+# define VADD(a,b) ((a)+(b))
+# define VMADD(a,b,c) ((a)*(b)+(c))
+# define VSUB(a,b) ((a)-(b))
+# define LD_PS1(p) (p)
+# define VALIGNED(ptr) ((((long long)(ptr)) & 0x3) == 0)
+#endif
+
+// shortcuts for complex multiplcations
+#define VCPLXMUL(ar,ai,br,bi) { v4sf tmp; tmp=VMUL(ar,bi); ar=VMUL(ar,br); ar=VSUB(ar,VMUL(ai,bi)); ai=VMUL(ai,br); ai=VADD(ai,tmp); }
+#define VCPLXMULCONJ(ar,ai,br,bi) { v4sf tmp; tmp=VMUL(ar,bi); ar=VMUL(ar,br); ar=VADD(ar,VMUL(ai,bi)); ai=VMUL(ai,br); ai=VSUB(ai,tmp); }
+#ifndef SVMUL
+// multiply a scalar with a vector
+#define SVMUL(f,v) VMUL(LD_PS1(f),v)
+#endif
+
+#if !defined(PFFFT_SIMD_DISABLE)
+typedef union v4sf_union {
+ v4sf v;
+ float f[4];
+} v4sf_union;
+
+#include <string.h>
+
+#define assertv4(v,f0,f1,f2,f3) assert(v.f[0] == (f0) && v.f[1] == (f1) && v.f[2] == (f2) && v.f[3] == (f3))
+
+/* detect bugs with the vector support macros */
+void validate_pffft_simd(void) {
+ float f[16] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
+ v4sf_union a0, a1, a2, a3, t, u;
+ memcpy(a0.f, f, 4*sizeof(float));
+ memcpy(a1.f, f+4, 4*sizeof(float));
+ memcpy(a2.f, f+8, 4*sizeof(float));
+ memcpy(a3.f, f+12, 4*sizeof(float));
+
+ t = a0; u = a1; t.v = VZERO();
+ printf("VZERO=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]); assertv4(t, 0, 0, 0, 0);
+ t.v = VADD(a1.v, a2.v);
+ printf("VADD(4:7,8:11)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]); assertv4(t, 12, 14, 16, 18);
+ t.v = VMUL(a1.v, a2.v);
+ printf("VMUL(4:7,8:11)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]); assertv4(t, 32, 45, 60, 77);
+ t.v = VMADD(a1.v, a2.v,a0.v);
+ printf("VMADD(4:7,8:11,0:3)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]); assertv4(t, 32, 46, 62, 80);
+
+ INTERLEAVE2(a1.v,a2.v,t.v,u.v);
+ printf("INTERLEAVE2(4:7,8:11)=[%2g %2g %2g %2g] [%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3], u.f[0], u.f[1], u.f[2], u.f[3]);
+ assertv4(t, 4, 8, 5, 9); assertv4(u, 6, 10, 7, 11);
+ UNINTERLEAVE2(a1.v,a2.v,t.v,u.v);
+ printf("UNINTERLEAVE2(4:7,8:11)=[%2g %2g %2g %2g] [%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3], u.f[0], u.f[1], u.f[2], u.f[3]);
+ assertv4(t, 4, 6, 8, 10); assertv4(u, 5, 7, 9, 11);
+
+ t.v=LD_PS1(f[15]);
+ printf("LD_PS1(15)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]);
+ assertv4(t, 15, 15, 15, 15);
+ t.v = VSWAPHL(a1.v, a2.v);
+ printf("VSWAPHL(4:7,8:11)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]);
+ assertv4(t, 8, 9, 6, 7);
+ VTRANSPOSE4(a0.v, a1.v, a2.v, a3.v);
+ printf("VTRANSPOSE4(0:3,4:7,8:11,12:15)=[%2g %2g %2g %2g] [%2g %2g %2g %2g] [%2g %2g %2g %2g] [%2g %2g %2g %2g]\n",
+ a0.f[0], a0.f[1], a0.f[2], a0.f[3], a1.f[0], a1.f[1], a1.f[2], a1.f[3],
+ a2.f[0], a2.f[1], a2.f[2], a2.f[3], a3.f[0], a3.f[1], a3.f[2], a3.f[3]);
+ assertv4(a0, 0, 4, 8, 12); assertv4(a1, 1, 5, 9, 13); assertv4(a2, 2, 6, 10, 14); assertv4(a3, 3, 7, 11, 15);
+}
+#else
+void validate_pffft_simd() {} // allow test_pffft.c to call this function even when simd is not available..
+#endif //!PFFFT_SIMD_DISABLE
+
+/* SSE and co like 16-bytes aligned pointers */
+#define MALLOC_V4SF_ALIGNMENT 64 // with a 64-byte alignment, we are even aligned on L2 cache lines...
+void *pffft_aligned_malloc(size_t nb_bytes) {
+ void *p, *p0 = malloc(nb_bytes + MALLOC_V4SF_ALIGNMENT);
+ if (!p0) return (void *) 0;
+ p = (void *) (((size_t) p0 + MALLOC_V4SF_ALIGNMENT) & (~((size_t) (MALLOC_V4SF_ALIGNMENT-1))));
+ *((void **) p - 1) = p0;
+ return p;
+}
+
+void pffft_aligned_free(void *p) {
+ if (p) free(*((void **) p - 1));
+}
+
+int pffft_simd_size(void) { return SIMD_SZ; }
+
+/*
+ passf2 and passb2 has been merged here, fsign = -1 for passf2, +1 for passb2
+*/
+static NEVER_INLINE(void) passf2_ps(int ido, int l1, const v4sf *cc, v4sf *ch, const float *wa1, float fsign) {
+ int k, i;
+ int l1ido = l1*ido;
+ if (ido <= 2) {
+ for (k=0; k < l1ido; k += ido, ch += ido, cc+= 2*ido) {
+ ch[0] = VADD(cc[0], cc[ido+0]);
+ ch[l1ido] = VSUB(cc[0], cc[ido+0]);
+ ch[1] = VADD(cc[1], cc[ido+1]);
+ ch[l1ido + 1] = VSUB(cc[1], cc[ido+1]);
+ }
+ } else {
+ for (k=0; k < l1ido; k += ido, ch += ido, cc += 2*ido) {
+ for (i=0; i<ido-1; i+=2) {
+ v4sf tr2 = VSUB(cc[i+0], cc[i+ido+0]);
+ v4sf ti2 = VSUB(cc[i+1], cc[i+ido+1]);
+ v4sf wr = LD_PS1(wa1[i]), wi = VMUL(LD_PS1(fsign), LD_PS1(wa1[i+1]));
+ ch[i] = VADD(cc[i+0], cc[i+ido+0]);
+ ch[i+1] = VADD(cc[i+1], cc[i+ido+1]);
+ VCPLXMUL(tr2, ti2, wr, wi);
+ ch[i+l1ido] = tr2;
+ ch[i+l1ido+1] = ti2;
+ }
+ }
+ }
+}
+
+/*
+ passf3 and passb3 has been merged here, fsign = -1 for passf3, +1 for passb3
+*/
+static NEVER_INLINE(void) passf3_ps(int ido, int l1, const v4sf *cc, v4sf *ch,
+ const float *wa1, const float *wa2, float fsign) {
+ static const float taur = -0.5f;
+ float taui = 0.866025403784439f*fsign;
+ int i, k;
+ v4sf tr2, ti2, cr2, ci2, cr3, ci3, dr2, di2, dr3, di3;
+ int l1ido = l1*ido;
+ float wr1, wi1, wr2, wi2;
+ assert(ido > 2);
+ for (k=0; k< l1ido; k += ido, cc+= 3*ido, ch +=ido) {
+ for (i=0; i<ido-1; i+=2) {
+ tr2 = VADD(cc[i+ido], cc[i+2*ido]);
+ cr2 = VADD(cc[i], SVMUL(taur,tr2));
+ ch[i] = VADD(cc[i], tr2);
+ ti2 = VADD(cc[i+ido+1], cc[i+2*ido+1]);
+ ci2 = VADD(cc[i +1], SVMUL(taur,ti2));
+ ch[i+1] = VADD(cc[i+1], ti2);
+ cr3 = SVMUL(taui, VSUB(cc[i+ido], cc[i+2*ido]));
+ ci3 = SVMUL(taui, VSUB(cc[i+ido+1], cc[i+2*ido+1]));
+ dr2 = VSUB(cr2, ci3);
+ dr3 = VADD(cr2, ci3);
+ di2 = VADD(ci2, cr3);
+ di3 = VSUB(ci2, cr3);
+ wr1=wa1[i]; wi1=fsign*wa1[i+1]; wr2=wa2[i]; wi2=fsign*wa2[i+1];
+ VCPLXMUL(dr2, di2, LD_PS1(wr1), LD_PS1(wi1));
+ ch[i+l1ido] = dr2;
+ ch[i+l1ido + 1] = di2;
+ VCPLXMUL(dr3, di3, LD_PS1(wr2), LD_PS1(wi2));
+ ch[i+2*l1ido] = dr3;
+ ch[i+2*l1ido+1] = di3;
+ }
+ }
+} /* passf3 */
+
+static NEVER_INLINE(void) passf4_ps(int ido, int l1, const v4sf *cc, v4sf *ch,
+ const float *wa1, const float *wa2, const float *wa3, float fsign) {
+ /* isign == -1 for forward transform and +1 for backward transform */
+
+ int i, k;
+ v4sf ci2, ci3, ci4, cr2, cr3, cr4, ti1, ti2, ti3, ti4, tr1, tr2, tr3, tr4;
+ int l1ido = l1*ido;
+ if (ido == 2) {
+ for (k=0; k < l1ido; k += ido, ch += ido, cc += 4*ido) {
+ tr1 = VSUB(cc[0], cc[2*ido + 0]);
+ tr2 = VADD(cc[0], cc[2*ido + 0]);
+ ti1 = VSUB(cc[1], cc[2*ido + 1]);
+ ti2 = VADD(cc[1], cc[2*ido + 1]);
+ ti4 = VMUL(VSUB(cc[1*ido + 0], cc[3*ido + 0]), LD_PS1(fsign));
+ tr4 = VMUL(VSUB(cc[3*ido + 1], cc[1*ido + 1]), LD_PS1(fsign));
+ tr3 = VADD(cc[ido + 0], cc[3*ido + 0]);
+ ti3 = VADD(cc[ido + 1], cc[3*ido + 1]);
+
+ ch[0*l1ido + 0] = VADD(tr2, tr3);
+ ch[0*l1ido + 1] = VADD(ti2, ti3);
+ ch[1*l1ido + 0] = VADD(tr1, tr4);
+ ch[1*l1ido + 1] = VADD(ti1, ti4);
+ ch[2*l1ido + 0] = VSUB(tr2, tr3);
+ ch[2*l1ido + 1] = VSUB(ti2, ti3);
+ ch[3*l1ido + 0] = VSUB(tr1, tr4);
+ ch[3*l1ido + 1] = VSUB(ti1, ti4);
+ }
+ } else {
+ for (k=0; k < l1ido; k += ido, ch+=ido, cc += 4*ido) {
+ for (i=0; i<ido-1; i+=2) {
+ float wr1, wi1, wr2, wi2, wr3, wi3;
+ tr1 = VSUB(cc[i + 0], cc[i + 2*ido + 0]);
+ tr2 = VADD(cc[i + 0], cc[i + 2*ido + 0]);
+ ti1 = VSUB(cc[i + 1], cc[i + 2*ido + 1]);
+ ti2 = VADD(cc[i + 1], cc[i + 2*ido + 1]);
+ tr4 = VMUL(VSUB(cc[i + 3*ido + 1], cc[i + 1*ido + 1]), LD_PS1(fsign));
+ ti4 = VMUL(VSUB(cc[i + 1*ido + 0], cc[i + 3*ido + 0]), LD_PS1(fsign));
+ tr3 = VADD(cc[i + ido + 0], cc[i + 3*ido + 0]);
+ ti3 = VADD(cc[i + ido + 1], cc[i + 3*ido + 1]);
+
+ ch[i] = VADD(tr2, tr3);
+ cr3 = VSUB(tr2, tr3);
+ ch[i + 1] = VADD(ti2, ti3);
+ ci3 = VSUB(ti2, ti3);
+
+ cr2 = VADD(tr1, tr4);
+ cr4 = VSUB(tr1, tr4);
+ ci2 = VADD(ti1, ti4);
+ ci4 = VSUB(ti1, ti4);
+ wr1=wa1[i]; wi1=fsign*wa1[i+1];
+ VCPLXMUL(cr2, ci2, LD_PS1(wr1), LD_PS1(wi1));
+ wr2=wa2[i]; wi2=fsign*wa2[i+1];
+ ch[i + l1ido] = cr2;
+ ch[i + l1ido + 1] = ci2;
+
+ VCPLXMUL(cr3, ci3, LD_PS1(wr2), LD_PS1(wi2));
+ wr3=wa3[i]; wi3=fsign*wa3[i+1];
+ ch[i + 2*l1ido] = cr3;
+ ch[i + 2*l1ido + 1] = ci3;
+
+ VCPLXMUL(cr4, ci4, LD_PS1(wr3), LD_PS1(wi3));
+ ch[i + 3*l1ido] = cr4;
+ ch[i + 3*l1ido + 1] = ci4;
+ }
+ }
+ }
+} /* passf4 */
+
+/*
+ passf5 and passb5 has been merged here, fsign = -1 for passf5, +1 for passb5
+*/
+static NEVER_INLINE(void) passf5_ps(int ido, int l1, const v4sf *cc, v4sf *ch,
+ const float *wa1, const float *wa2,
+ const float *wa3, const float *wa4, float fsign) {
+ static const float tr11 = .309016994374947f;
+ const float ti11 = .951056516295154f*fsign;
+ static const float tr12 = -.809016994374947f;
+ const float ti12 = .587785252292473f*fsign;
+
+ /* Local variables */
+ int i, k;
+ v4sf ci2, ci3, ci4, ci5, di3, di4, di5, di2, cr2, cr3, cr5, cr4, ti2, ti3,
+ ti4, ti5, dr3, dr4, dr5, dr2, tr2, tr3, tr4, tr5;
+
+ float wr1, wi1, wr2, wi2, wr3, wi3, wr4, wi4;
+
+#define cc_ref(a_1,a_2) cc[(a_2-1)*ido + a_1 + 1]
+#define ch_ref(a_1,a_3) ch[(a_3-1)*l1*ido + a_1 + 1]
+
+ assert(ido > 2);
+ for (k = 0; k < l1; ++k, cc += 5*ido, ch += ido) {
+ for (i = 0; i < ido-1; i += 2) {
+ ti5 = VSUB(cc_ref(i , 2), cc_ref(i , 5));
+ ti2 = VADD(cc_ref(i , 2), cc_ref(i , 5));
+ ti4 = VSUB(cc_ref(i , 3), cc_ref(i , 4));
+ ti3 = VADD(cc_ref(i , 3), cc_ref(i , 4));
+ tr5 = VSUB(cc_ref(i-1, 2), cc_ref(i-1, 5));
+ tr2 = VADD(cc_ref(i-1, 2), cc_ref(i-1, 5));
+ tr4 = VSUB(cc_ref(i-1, 3), cc_ref(i-1, 4));
+ tr3 = VADD(cc_ref(i-1, 3), cc_ref(i-1, 4));
+ ch_ref(i-1, 1) = VADD(cc_ref(i-1, 1), VADD(tr2, tr3));
+ ch_ref(i , 1) = VADD(cc_ref(i , 1), VADD(ti2, ti3));
+ cr2 = VADD(cc_ref(i-1, 1), VADD(SVMUL(tr11, tr2),SVMUL(tr12, tr3)));
+ ci2 = VADD(cc_ref(i , 1), VADD(SVMUL(tr11, ti2),SVMUL(tr12, ti3)));
+ cr3 = VADD(cc_ref(i-1, 1), VADD(SVMUL(tr12, tr2),SVMUL(tr11, tr3)));
+ ci3 = VADD(cc_ref(i , 1), VADD(SVMUL(tr12, ti2),SVMUL(tr11, ti3)));
+ cr5 = VADD(SVMUL(ti11, tr5), SVMUL(ti12, tr4));
+ ci5 = VADD(SVMUL(ti11, ti5), SVMUL(ti12, ti4));
+ cr4 = VSUB(SVMUL(ti12, tr5), SVMUL(ti11, tr4));
+ ci4 = VSUB(SVMUL(ti12, ti5), SVMUL(ti11, ti4));
+ dr3 = VSUB(cr3, ci4);
+ dr4 = VADD(cr3, ci4);
+ di3 = VADD(ci3, cr4);
+ di4 = VSUB(ci3, cr4);
+ dr5 = VADD(cr2, ci5);
+ dr2 = VSUB(cr2, ci5);
+ di5 = VSUB(ci2, cr5);
+ di2 = VADD(ci2, cr5);
+ wr1=wa1[i]; wi1=fsign*wa1[i+1]; wr2=wa2[i]; wi2=fsign*wa2[i+1];
+ wr3=wa3[i]; wi3=fsign*wa3[i+1]; wr4=wa4[i]; wi4=fsign*wa4[i+1];
+ VCPLXMUL(dr2, di2, LD_PS1(wr1), LD_PS1(wi1));
+ ch_ref(i - 1, 2) = dr2;
+ ch_ref(i, 2) = di2;
+ VCPLXMUL(dr3, di3, LD_PS1(wr2), LD_PS1(wi2));
+ ch_ref(i - 1, 3) = dr3;
+ ch_ref(i, 3) = di3;
+ VCPLXMUL(dr4, di4, LD_PS1(wr3), LD_PS1(wi3));
+ ch_ref(i - 1, 4) = dr4;
+ ch_ref(i, 4) = di4;
+ VCPLXMUL(dr5, di5, LD_PS1(wr4), LD_PS1(wi4));
+ ch_ref(i - 1, 5) = dr5;
+ ch_ref(i, 5) = di5;
+ }
+ }
+#undef ch_ref
+#undef cc_ref
+}
+
+static NEVER_INLINE(void) radf2_ps(int ido, int l1, const v4sf * RESTRICT cc, v4sf * RESTRICT ch, const float *wa1) {
+ static const float minus_one = -1.f;
+ int i, k, l1ido = l1*ido;
+ for (k=0; k < l1ido; k += ido) {
+ v4sf a = cc[k], b = cc[k + l1ido];
+ ch[2*k] = VADD(a, b);
+ ch[2*(k+ido)-1] = VSUB(a, b);
+ }
+ if (ido < 2) return;
+ if (ido != 2) {
+ for (k=0; k < l1ido; k += ido) {
+ for (i=2; i<ido; i+=2) {
+ v4sf tr2 = cc[i - 1 + k + l1ido], ti2 = cc[i + k + l1ido];
+ v4sf br = cc[i - 1 + k], bi = cc[i + k];
+ VCPLXMULCONJ(tr2, ti2, LD_PS1(wa1[i - 2]), LD_PS1(wa1[i - 1]));
+ ch[i + 2*k] = VADD(bi, ti2);
+ ch[2*(k+ido) - i] = VSUB(ti2, bi);
+ ch[i - 1 + 2*k] = VADD(br, tr2);
+ ch[2*(k+ido) - i -1] = VSUB(br, tr2);
+ }
+ }
+ if (ido % 2 == 1) return;
+ }
+ for (k=0; k < l1ido; k += ido) {
+ ch[2*k + ido] = SVMUL(minus_one, cc[ido-1 + k + l1ido]);
+ ch[2*k + ido-1] = cc[k + ido-1];
+ }
+} /* radf2 */
+
+
+static NEVER_INLINE(void) radb2_ps(int ido, int l1, const v4sf *cc, v4sf *ch, const float *wa1) {
+ static const float minus_two=-2;
+ int i, k, l1ido = l1*ido;
+ v4sf a,b,c,d, tr2, ti2;
+ for (k=0; k < l1ido; k += ido) {
+ a = cc[2*k]; b = cc[2*(k+ido) - 1];
+ ch[k] = VADD(a, b);
+ ch[k + l1ido] =VSUB(a, b);
+ }
+ if (ido < 2) return;
+ if (ido != 2) {
+ for (k = 0; k < l1ido; k += ido) {
+ for (i = 2; i < ido; i += 2) {
+ a = cc[i-1 + 2*k]; b = cc[2*(k + ido) - i - 1];
+ c = cc[i+0 + 2*k]; d = cc[2*(k + ido) - i + 0];
+ ch[i-1 + k] = VADD(a, b);
+ tr2 = VSUB(a, b);
+ ch[i+0 + k] = VSUB(c, d);
+ ti2 = VADD(c, d);
+ VCPLXMUL(tr2, ti2, LD_PS1(wa1[i - 2]), LD_PS1(wa1[i - 1]));
+ ch[i-1 + k + l1ido] = tr2;
+ ch[i+0 + k + l1ido] = ti2;
+ }
+ }
+ if (ido % 2 == 1) return;
+ }
+ for (k = 0; k < l1ido; k += ido) {
+ a = cc[2*k + ido-1]; b = cc[2*k + ido];
+ ch[k + ido-1] = VADD(a,a);
+ ch[k + ido-1 + l1ido] = SVMUL(minus_two, b);
+ }
+} /* radb2 */
+
+static void radf3_ps(int ido, int l1, const v4sf * RESTRICT cc, v4sf * RESTRICT ch,
+ const float *wa1, const float *wa2) {
+ static const float taur = -0.5f;
+ static const float taui = 0.866025403784439f;
+ int i, k, ic;
+ v4sf ci2, di2, di3, cr2, dr2, dr3, ti2, ti3, tr2, tr3, wr1, wi1, wr2, wi2;
+ for (k=0; k<l1; k++) {
+ cr2 = VADD(cc[(k + l1)*ido], cc[(k + 2*l1)*ido]);
+ ch[3*k*ido] = VADD(cc[k*ido], cr2);
+ ch[(3*k+2)*ido] = SVMUL(taui, VSUB(cc[(k + l1*2)*ido], cc[(k + l1)*ido]));
+ ch[ido-1 + (3*k + 1)*ido] = VADD(cc[k*ido], SVMUL(taur, cr2));
+ }
+ if (ido == 1) return;
+ for (k=0; k<l1; k++) {
+ for (i=2; i<ido; i+=2) {
+ ic = ido - i;
+ wr1 = LD_PS1(wa1[i - 2]); wi1 = LD_PS1(wa1[i - 1]);
+ dr2 = cc[i - 1 + (k + l1)*ido]; di2 = cc[i + (k + l1)*ido];
+ VCPLXMULCONJ(dr2, di2, wr1, wi1);
+
+ wr2 = LD_PS1(wa2[i - 2]); wi2 = LD_PS1(wa2[i - 1]);
+ dr3 = cc[i - 1 + (k + l1*2)*ido]; di3 = cc[i + (k + l1*2)*ido];
+ VCPLXMULCONJ(dr3, di3, wr2, wi2);
+
+ cr2 = VADD(dr2, dr3);
+ ci2 = VADD(di2, di3);
+ ch[i - 1 + 3*k*ido] = VADD(cc[i - 1 + k*ido], cr2);
+ ch[i + 3*k*ido] = VADD(cc[i + k*ido], ci2);
+ tr2 = VADD(cc[i - 1 + k*ido], SVMUL(taur, cr2));
+ ti2 = VADD(cc[i + k*ido], SVMUL(taur, ci2));
+ tr3 = SVMUL(taui, VSUB(di2, di3));
+ ti3 = SVMUL(taui, VSUB(dr3, dr2));
+ ch[i - 1 + (3*k + 2)*ido] = VADD(tr2, tr3);
+ ch[ic - 1 + (3*k + 1)*ido] = VSUB(tr2, tr3);
+ ch[i + (3*k + 2)*ido] = VADD(ti2, ti3);
+ ch[ic + (3*k + 1)*ido] = VSUB(ti3, ti2);
+ }
+ }
+} /* radf3 */
+
+
+static void radb3_ps(int ido, int l1, const v4sf *RESTRICT cc, v4sf *RESTRICT ch,
+ const float *wa1, const float *wa2)
+{
+ static const float taur = -0.5f;
+ static const float taui = 0.866025403784439f;
+ static const float taui_2 = 0.866025403784439f*2;
+ int i, k, ic;
+ v4sf ci2, ci3, di2, di3, cr2, cr3, dr2, dr3, ti2, tr2;
+ for (k=0; k<l1; k++) {
+ tr2 = cc[ido-1 + (3*k + 1)*ido]; tr2 = VADD(tr2,tr2);
+ cr2 = VMADD(LD_PS1(taur), tr2, cc[3*k*ido]);
+ ch[k*ido] = VADD(cc[3*k*ido], tr2);
+ ci3 = SVMUL(taui_2, cc[(3*k + 2)*ido]);
+ ch[(k + l1)*ido] = VSUB(cr2, ci3);
+ ch[(k + 2*l1)*ido] = VADD(cr2, ci3);
+ }
+ if (ido == 1) return;
+ for (k=0; k<l1; k++) {
+ for (i=2; i<ido; i+=2) {
+ ic = ido - i;
+ tr2 = VADD(cc[i - 1 + (3*k + 2)*ido], cc[ic - 1 + (3*k + 1)*ido]);
+ cr2 = VMADD(LD_PS1(taur), tr2, cc[i - 1 + 3*k*ido]);
+ ch[i - 1 + k*ido] = VADD(cc[i - 1 + 3*k*ido], tr2);
+ ti2 = VSUB(cc[i + (3*k + 2)*ido], cc[ic + (3*k + 1)*ido]);
+ ci2 = VMADD(LD_PS1(taur), ti2, cc[i + 3*k*ido]);
+ ch[i + k*ido] = VADD(cc[i + 3*k*ido], ti2);
+ cr3 = SVMUL(taui, VSUB(cc[i - 1 + (3*k + 2)*ido], cc[ic - 1 + (3*k + 1)*ido]));
+ ci3 = SVMUL(taui, VADD(cc[i + (3*k + 2)*ido], cc[ic + (3*k + 1)*ido]));
+ dr2 = VSUB(cr2, ci3);
+ dr3 = VADD(cr2, ci3);
+ di2 = VADD(ci2, cr3);
+ di3 = VSUB(ci2, cr3);
+ VCPLXMUL(dr2, di2, LD_PS1(wa1[i-2]), LD_PS1(wa1[i-1]));
+ ch[i - 1 + (k + l1)*ido] = dr2;
+ ch[i + (k + l1)*ido] = di2;
+ VCPLXMUL(dr3, di3, LD_PS1(wa2[i-2]), LD_PS1(wa2[i-1]));
+ ch[i - 1 + (k + 2*l1)*ido] = dr3;
+ ch[i + (k + 2*l1)*ido] = di3;
+ }
+ }
+} /* radb3 */
+
+static NEVER_INLINE(void) radf4_ps(int ido, int l1, const v4sf *RESTRICT cc, v4sf * RESTRICT ch,
+ const float * RESTRICT wa1, const float * RESTRICT wa2, const float * RESTRICT wa3)
+{
+ static const float minus_hsqt2 = (float)-0.7071067811865475;
+ int i, k, l1ido = l1*ido;
+ {
+ const v4sf *RESTRICT cc_ = cc, * RESTRICT cc_end = cc + l1ido;
+ v4sf * RESTRICT ch_ = ch;
+ while (cc < cc_end) {
+ // this loop represents between 25% and 40% of total radf4_ps cost !
+ v4sf a0 = cc[0], a1 = cc[l1ido];
+ v4sf a2 = cc[2*l1ido], a3 = cc[3*l1ido];
+ v4sf tr1 = VADD(a1, a3);
+ v4sf tr2 = VADD(a0, a2);
+ ch[2*ido-1] = VSUB(a0, a2);
+ ch[2*ido ] = VSUB(a3, a1);
+ ch[0 ] = VADD(tr1, tr2);
+ ch[4*ido-1] = VSUB(tr2, tr1);
+ cc += ido; ch += 4*ido;
+ }
+ cc = cc_; ch = ch_;
+ }
+ if (ido < 2) return;
+ if (ido != 2) {
+ for (k = 0; k < l1ido; k += ido) {
+ const v4sf * RESTRICT pc = (v4sf*)(cc + 1 + k);
+ for (i=2; i<ido; i += 2, pc += 2) {
+ int ic = ido - i;
+ v4sf wr, wi, cr2, ci2, cr3, ci3, cr4, ci4;
+ v4sf tr1, ti1, tr2, ti2, tr3, ti3, tr4, ti4;
+
+ cr2 = pc[1*l1ido+0];
+ ci2 = pc[1*l1ido+1];
+ wr=LD_PS1(wa1[i - 2]);
+ wi=LD_PS1(wa1[i - 1]);
+ VCPLXMULCONJ(cr2,ci2,wr,wi);
+
+ cr3 = pc[2*l1ido+0];
+ ci3 = pc[2*l1ido+1];
+ wr = LD_PS1(wa2[i-2]);
+ wi = LD_PS1(wa2[i-1]);
+ VCPLXMULCONJ(cr3, ci3, wr, wi);
+
+ cr4 = pc[3*l1ido];
+ ci4 = pc[3*l1ido+1];
+ wr = LD_PS1(wa3[i-2]);
+ wi = LD_PS1(wa3[i-1]);
+ VCPLXMULCONJ(cr4, ci4, wr, wi);
+
+ /* at this point, on SSE, five of "cr2 cr3 cr4 ci2 ci3 ci4" should be loaded in registers */
+
+ tr1 = VADD(cr2,cr4);
+ tr4 = VSUB(cr4,cr2);
+ tr2 = VADD(pc[0],cr3);
+ tr3 = VSUB(pc[0],cr3);
+ ch[i - 1 + 4*k] = VADD(tr1,tr2);
+ ch[ic - 1 + 4*k + 3*ido] = VSUB(tr2,tr1); // at this point tr1 and tr2 can be disposed
+ ti1 = VADD(ci2,ci4);
+ ti4 = VSUB(ci2,ci4);
+ ch[i - 1 + 4*k + 2*ido] = VADD(ti4,tr3);
+ ch[ic - 1 + 4*k + 1*ido] = VSUB(tr3,ti4); // dispose tr3, ti4
+ ti2 = VADD(pc[1],ci3);
+ ti3 = VSUB(pc[1],ci3);
+ ch[i + 4*k] = VADD(ti1, ti2);
+ ch[ic + 4*k + 3*ido] = VSUB(ti1, ti2);
+ ch[i + 4*k + 2*ido] = VADD(tr4, ti3);
+ ch[ic + 4*k + 1*ido] = VSUB(tr4, ti3);
+ }
+ }
+ if (ido % 2 == 1) return;
+ }
+ for (k=0; k<l1ido; k += ido) {
+ v4sf a = cc[ido-1 + k + l1ido], b = cc[ido-1 + k + 3*l1ido];
+ v4sf c = cc[ido-1 + k], d = cc[ido-1 + k + 2*l1ido];
+ v4sf ti1 = SVMUL(minus_hsqt2, VADD(a, b));
+ v4sf tr1 = SVMUL(minus_hsqt2, VSUB(b, a));
+ ch[ido-1 + 4*k] = VADD(tr1, c);
+ ch[ido-1 + 4*k + 2*ido] = VSUB(c, tr1);
+ ch[4*k + 1*ido] = VSUB(ti1, d);
+ ch[4*k + 3*ido] = VADD(ti1, d);
+ }
+} /* radf4 */
+
+
+static NEVER_INLINE(void) radb4_ps(int ido, int l1, const v4sf * RESTRICT cc, v4sf * RESTRICT ch,
+ const float * RESTRICT wa1, const float * RESTRICT wa2, const float *RESTRICT wa3)
+{
+ static const float minus_sqrt2 = (float)-1.414213562373095;
+ static const float two = 2.f;
+ int i, k, l1ido = l1*ido;
+ v4sf ci2, ci3, ci4, cr2, cr3, cr4, ti1, ti2, ti3, ti4, tr1, tr2, tr3, tr4;
+ {
+ const v4sf *RESTRICT cc_ = cc, * RESTRICT ch_end = ch + l1ido;
+ v4sf *ch_ = ch;
+ while (ch < ch_end) {
+ v4sf a = cc[0], b = cc[4*ido-1];
+ v4sf c = cc[2*ido], d = cc[2*ido-1];
+ tr3 = SVMUL(two,d);
+ tr2 = VADD(a,b);
+ tr1 = VSUB(a,b);
+ tr4 = SVMUL(two,c);
+ ch[0*l1ido] = VADD(tr2, tr3);
+ ch[2*l1ido] = VSUB(tr2, tr3);
+ ch[1*l1ido] = VSUB(tr1, tr4);
+ ch[3*l1ido] = VADD(tr1, tr4);
+
+ cc += 4*ido; ch += ido;
+ }
+ cc = cc_; ch = ch_;
+ }
+ if (ido < 2) return;
+ if (ido != 2) {
+ for (k = 0; k < l1ido; k += ido) {
+ const v4sf * RESTRICT pc = (v4sf*)(cc - 1 + 4*k);
+ v4sf * RESTRICT ph = (v4sf*)(ch + k + 1);
+ for (i = 2; i < ido; i += 2) {
+
+ tr1 = VSUB(pc[i], pc[4*ido - i]);
+ tr2 = VADD(pc[i], pc[4*ido - i]);
+ ti4 = VSUB(pc[2*ido + i], pc[2*ido - i]);
+ tr3 = VADD(pc[2*ido + i], pc[2*ido - i]);
+ ph[0] = VADD(tr2, tr3);
+ cr3 = VSUB(tr2, tr3);
+
+ ti3 = VSUB(pc[2*ido + i + 1], pc[2*ido - i + 1]);
+ tr4 = VADD(pc[2*ido + i + 1], pc[2*ido - i + 1]);
+ cr2 = VSUB(tr1, tr4);
+ cr4 = VADD(tr1, tr4);
+
+ ti1 = VADD(pc[i + 1], pc[4*ido - i + 1]);
+ ti2 = VSUB(pc[i + 1], pc[4*ido - i + 1]);
+
+ ph[1] = VADD(ti2, ti3); ph += l1ido;
+ ci3 = VSUB(ti2, ti3);
+ ci2 = VADD(ti1, ti4);
+ ci4 = VSUB(ti1, ti4);
+ VCPLXMUL(cr2, ci2, LD_PS1(wa1[i-2]), LD_PS1(wa1[i-1]));
+ ph[0] = cr2;
+ ph[1] = ci2; ph += l1ido;
+ VCPLXMUL(cr3, ci3, LD_PS1(wa2[i-2]), LD_PS1(wa2[i-1]));
+ ph[0] = cr3;
+ ph[1] = ci3; ph += l1ido;
+ VCPLXMUL(cr4, ci4, LD_PS1(wa3[i-2]), LD_PS1(wa3[i-1]));
+ ph[0] = cr4;
+ ph[1] = ci4; ph = ph - 3*l1ido + 2;
+ }
+ }
+ if (ido % 2 == 1) return;
+ }
+ for (k=0; k < l1ido; k+=ido) {
+ int i0 = 4*k + ido;
+ v4sf c = cc[i0-1], d = cc[i0 + 2*ido-1];
+ v4sf a = cc[i0+0], b = cc[i0 + 2*ido+0];
+ tr1 = VSUB(c,d);
+ tr2 = VADD(c,d);
+ ti1 = VADD(b,a);
+ ti2 = VSUB(b,a);
+ ch[ido-1 + k + 0*l1ido] = VADD(tr2,tr2);
+ ch[ido-1 + k + 1*l1ido] = SVMUL(minus_sqrt2, VSUB(ti1, tr1));
+ ch[ido-1 + k + 2*l1ido] = VADD(ti2, ti2);
+ ch[ido-1 + k + 3*l1ido] = SVMUL(minus_sqrt2, VADD(ti1, tr1));
+ }
+} /* radb4 */
+
+static void radf5_ps(int ido, int l1, const v4sf * RESTRICT cc, v4sf * RESTRICT ch,
+ const float *wa1, const float *wa2, const float *wa3, const float *wa4)
+{
+ static const float tr11 = .309016994374947f;
+ static const float ti11 = .951056516295154f;
+ static const float tr12 = -.809016994374947f;
+ static const float ti12 = .587785252292473f;
+
+ /* System generated locals */
+ int cc_offset, ch_offset;
+
+ /* Local variables */
+ int i, k, ic;
+ v4sf ci2, di2, ci4, ci5, di3, di4, di5, ci3, cr2, cr3, dr2, dr3, dr4, dr5,
+ cr5, cr4, ti2, ti3, ti5, ti4, tr2, tr3, tr4, tr5;
+ int idp2;
+
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*l1 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*5 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * 6;
+ ch -= ch_offset;
+ cc_offset = 1 + ido * (1 + l1);
+ cc -= cc_offset;
+
+ /* Function Body */
+ for (k = 1; k <= l1; ++k) {
+ cr2 = VADD(cc_ref(1, k, 5), cc_ref(1, k, 2));
+ ci5 = VSUB(cc_ref(1, k, 5), cc_ref(1, k, 2));
+ cr3 = VADD(cc_ref(1, k, 4), cc_ref(1, k, 3));
+ ci4 = VSUB(cc_ref(1, k, 4), cc_ref(1, k, 3));
+ ch_ref(1, 1, k) = VADD(cc_ref(1, k, 1), VADD(cr2, cr3));
+ ch_ref(ido, 2, k) = VADD(cc_ref(1, k, 1), VADD(SVMUL(tr11, cr2), SVMUL(tr12, cr3)));
+ ch_ref(1, 3, k) = VADD(SVMUL(ti11, ci5), SVMUL(ti12, ci4));
+ ch_ref(ido, 4, k) = VADD(cc_ref(1, k, 1), VADD(SVMUL(tr12, cr2), SVMUL(tr11, cr3)));
+ ch_ref(1, 5, k) = VSUB(SVMUL(ti12, ci5), SVMUL(ti11, ci4));
+ //printf("pffft: radf5, k=%d ch_ref=%f, ci4=%f\n", k, ch_ref(1, 5, k), ci4);
+ }
+ if (ido == 1) {
+ return;
+ }
+ idp2 = ido + 2;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ dr2 = LD_PS1(wa1[i-3]); di2 = LD_PS1(wa1[i-2]);
+ dr3 = LD_PS1(wa2[i-3]); di3 = LD_PS1(wa2[i-2]);
+ dr4 = LD_PS1(wa3[i-3]); di4 = LD_PS1(wa3[i-2]);
+ dr5 = LD_PS1(wa4[i-3]); di5 = LD_PS1(wa4[i-2]);
+ VCPLXMULCONJ(dr2, di2, cc_ref(i-1, k, 2), cc_ref(i, k, 2));
+ VCPLXMULCONJ(dr3, di3, cc_ref(i-1, k, 3), cc_ref(i, k, 3));
+ VCPLXMULCONJ(dr4, di4, cc_ref(i-1, k, 4), cc_ref(i, k, 4));
+ VCPLXMULCONJ(dr5, di5, cc_ref(i-1, k, 5), cc_ref(i, k, 5));
+ cr2 = VADD(dr2, dr5);
+ ci5 = VSUB(dr5, dr2);
+ cr5 = VSUB(di2, di5);
+ ci2 = VADD(di2, di5);
+ cr3 = VADD(dr3, dr4);
+ ci4 = VSUB(dr4, dr3);
+ cr4 = VSUB(di3, di4);
+ ci3 = VADD(di3, di4);
+ ch_ref(i - 1, 1, k) = VADD(cc_ref(i - 1, k, 1), VADD(cr2, cr3));
+ ch_ref(i, 1, k) = VSUB(cc_ref(i, k, 1), VADD(ci2, ci3));//
+ tr2 = VADD(cc_ref(i - 1, k, 1), VADD(SVMUL(tr11, cr2), SVMUL(tr12, cr3)));
+ ti2 = VSUB(cc_ref(i, k, 1), VADD(SVMUL(tr11, ci2), SVMUL(tr12, ci3)));//
+ tr3 = VADD(cc_ref(i - 1, k, 1), VADD(SVMUL(tr12, cr2), SVMUL(tr11, cr3)));
+ ti3 = VSUB(cc_ref(i, k, 1), VADD(SVMUL(tr12, ci2), SVMUL(tr11, ci3)));//
+ tr5 = VADD(SVMUL(ti11, cr5), SVMUL(ti12, cr4));
+ ti5 = VADD(SVMUL(ti11, ci5), SVMUL(ti12, ci4));
+ tr4 = VSUB(SVMUL(ti12, cr5), SVMUL(ti11, cr4));
+ ti4 = VSUB(SVMUL(ti12, ci5), SVMUL(ti11, ci4));
+ ch_ref(i - 1, 3, k) = VSUB(tr2, tr5);
+ ch_ref(ic - 1, 2, k) = VADD(tr2, tr5);
+ ch_ref(i, 3, k) = VADD(ti2, ti5);
+ ch_ref(ic, 2, k) = VSUB(ti5, ti2);
+ ch_ref(i - 1, 5, k) = VSUB(tr3, tr4);
+ ch_ref(ic - 1, 4, k) = VADD(tr3, tr4);
+ ch_ref(i, 5, k) = VADD(ti3, ti4);
+ ch_ref(ic, 4, k) = VSUB(ti4, ti3);
+ }
+ }
+#undef cc_ref
+#undef ch_ref
+} /* radf5 */
+
+static void radb5_ps(int ido, int l1, const v4sf *RESTRICT cc, v4sf *RESTRICT ch,
+ const float *wa1, const float *wa2, const float *wa3, const float *wa4)
+{
+ static const float tr11 = .309016994374947f;
+ static const float ti11 = .951056516295154f;
+ static const float tr12 = -.809016994374947f;
+ static const float ti12 = .587785252292473f;
+
+ int cc_offset, ch_offset;
+
+ /* Local variables */
+ int i, k, ic;
+ v4sf ci2, ci3, ci4, ci5, di3, di4, di5, di2, cr2, cr3, cr5, cr4, ti2, ti3,
+ ti4, ti5, dr3, dr4, dr5, dr2, tr2, tr3, tr4, tr5;
+ int idp2;
+
+#define cc_ref(a_1,a_2,a_3) cc[((a_3)*5 + (a_2))*ido + a_1]
+#define ch_ref(a_1,a_2,a_3) ch[((a_3)*l1 + (a_2))*ido + a_1]
+
+ /* Parameter adjustments */
+ ch_offset = 1 + ido * (1 + l1);
+ ch -= ch_offset;
+ cc_offset = 1 + ido * 6;
+ cc -= cc_offset;
+
+ /* Function Body */
+ for (k = 1; k <= l1; ++k) {
+ ti5 = VADD(cc_ref(1, 3, k), cc_ref(1, 3, k));
+ ti4 = VADD(cc_ref(1, 5, k), cc_ref(1, 5, k));
+ tr2 = VADD(cc_ref(ido, 2, k), cc_ref(ido, 2, k));
+ tr3 = VADD(cc_ref(ido, 4, k), cc_ref(ido, 4, k));
+ ch_ref(1, k, 1) = VADD(cc_ref(1, 1, k), VADD(tr2, tr3));
+ cr2 = VADD(cc_ref(1, 1, k), VADD(SVMUL(tr11, tr2), SVMUL(tr12, tr3)));
+ cr3 = VADD(cc_ref(1, 1, k), VADD(SVMUL(tr12, tr2), SVMUL(tr11, tr3)));
+ ci5 = VADD(SVMUL(ti11, ti5), SVMUL(ti12, ti4));
+ ci4 = VSUB(SVMUL(ti12, ti5), SVMUL(ti11, ti4));
+ ch_ref(1, k, 2) = VSUB(cr2, ci5);
+ ch_ref(1, k, 3) = VSUB(cr3, ci4);
+ ch_ref(1, k, 4) = VADD(cr3, ci4);
+ ch_ref(1, k, 5) = VADD(cr2, ci5);
+ }
+ if (ido == 1) {
+ return;
+ }
+ idp2 = ido + 2;
+ for (k = 1; k <= l1; ++k) {
+ for (i = 3; i <= ido; i += 2) {
+ ic = idp2 - i;
+ ti5 = VADD(cc_ref(i , 3, k), cc_ref(ic , 2, k));
+ ti2 = VSUB(cc_ref(i , 3, k), cc_ref(ic , 2, k));
+ ti4 = VADD(cc_ref(i , 5, k), cc_ref(ic , 4, k));
+ ti3 = VSUB(cc_ref(i , 5, k), cc_ref(ic , 4, k));
+ tr5 = VSUB(cc_ref(i-1, 3, k), cc_ref(ic-1, 2, k));
+ tr2 = VADD(cc_ref(i-1, 3, k), cc_ref(ic-1, 2, k));
+ tr4 = VSUB(cc_ref(i-1, 5, k), cc_ref(ic-1, 4, k));
+ tr3 = VADD(cc_ref(i-1, 5, k), cc_ref(ic-1, 4, k));
+ ch_ref(i - 1, k, 1) = VADD(cc_ref(i-1, 1, k), VADD(tr2, tr3));
+ ch_ref(i, k, 1) = VADD(cc_ref(i, 1, k), VADD(ti2, ti3));
+ cr2 = VADD(cc_ref(i-1, 1, k), VADD(SVMUL(tr11, tr2), SVMUL(tr12, tr3)));
+ ci2 = VADD(cc_ref(i , 1, k), VADD(SVMUL(tr11, ti2), SVMUL(tr12, ti3)));
+ cr3 = VADD(cc_ref(i-1, 1, k), VADD(SVMUL(tr12, tr2), SVMUL(tr11, tr3)));
+ ci3 = VADD(cc_ref(i , 1, k), VADD(SVMUL(tr12, ti2), SVMUL(tr11, ti3)));
+ cr5 = VADD(SVMUL(ti11, tr5), SVMUL(ti12, tr4));
+ ci5 = VADD(SVMUL(ti11, ti5), SVMUL(ti12, ti4));
+ cr4 = VSUB(SVMUL(ti12, tr5), SVMUL(ti11, tr4));
+ ci4 = VSUB(SVMUL(ti12, ti5), SVMUL(ti11, ti4));
+ dr3 = VSUB(cr3, ci4);
+ dr4 = VADD(cr3, ci4);
+ di3 = VADD(ci3, cr4);
+ di4 = VSUB(ci3, cr4);
+ dr5 = VADD(cr2, ci5);
+ dr2 = VSUB(cr2, ci5);
+ di5 = VSUB(ci2, cr5);
+ di2 = VADD(ci2, cr5);
+ VCPLXMUL(dr2, di2, LD_PS1(wa1[i-3]), LD_PS1(wa1[i-2]));
+ VCPLXMUL(dr3, di3, LD_PS1(wa2[i-3]), LD_PS1(wa2[i-2]));
+ VCPLXMUL(dr4, di4, LD_PS1(wa3[i-3]), LD_PS1(wa3[i-2]));
+ VCPLXMUL(dr5, di5, LD_PS1(wa4[i-3]), LD_PS1(wa4[i-2]));
+
+ ch_ref(i-1, k, 2) = dr2; ch_ref(i, k, 2) = di2;
+ ch_ref(i-1, k, 3) = dr3; ch_ref(i, k, 3) = di3;
+ ch_ref(i-1, k, 4) = dr4; ch_ref(i, k, 4) = di4;
+ ch_ref(i-1, k, 5) = dr5; ch_ref(i, k, 5) = di5;
+ }
+ }
+#undef cc_ref
+#undef ch_ref
+} /* radb5 */
+
+static NEVER_INLINE(v4sf *) rfftf1_ps(int n, const v4sf *input_readonly, v4sf *work1, v4sf *work2,
+ const float *wa, const int *ifac) {
+ v4sf *in = (v4sf*)input_readonly;
+ v4sf *out = (in == work2 ? work1 : work2);
+ int nf = ifac[1], k1;
+ int l2 = n;
+ int iw = n-1;
+ assert(in != out && work1 != work2);
+ for (k1 = 1; k1 <= nf; ++k1) {
+ int kh = nf - k1;
+ int ip = ifac[kh + 2];
+ int l1 = l2 / ip;
+ int ido = n / l2;
+ iw -= (ip - 1)*ido;
+ switch (ip) {
+ case 5: {
+ int ix2 = iw + ido;
+ int ix3 = ix2 + ido;
+ int ix4 = ix3 + ido;
+ radf5_ps(ido, l1, in, out, &wa[iw], &wa[ix2], &wa[ix3], &wa[ix4]);
+ } break;
+ case 4: {
+ int ix2 = iw + ido;
+ int ix3 = ix2 + ido;
+ radf4_ps(ido, l1, in, out, &wa[iw], &wa[ix2], &wa[ix3]);
+ } break;
+ case 3: {
+ int ix2 = iw + ido;
+ radf3_ps(ido, l1, in, out, &wa[iw], &wa[ix2]);
+ } break;
+ case 2:
+ radf2_ps(ido, l1, in, out, &wa[iw]);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ l2 = l1;
+ if (out == work2) {
+ out = work1; in = work2;
+ } else {
+ out = work2; in = work1;
+ }
+ }
+ return in; /* this is in fact the output .. */
+} /* rfftf1 */
+
+static NEVER_INLINE(v4sf *) rfftb1_ps(int n, const v4sf *input_readonly, v4sf *work1, v4sf *work2,
+ const float *wa, const int *ifac) {
+ v4sf *in = (v4sf*)input_readonly;
+ v4sf *out = (in == work2 ? work1 : work2);
+ int nf = ifac[1], k1;
+ int l1 = 1;
+ int iw = 0;
+ assert(in != out);
+ for (k1=1; k1<=nf; k1++) {
+ int ip = ifac[k1 + 1];
+ int l2 = ip*l1;
+ int ido = n / l2;
+ switch (ip) {
+ case 5: {
+ int ix2 = iw + ido;
+ int ix3 = ix2 + ido;
+ int ix4 = ix3 + ido;
+ radb5_ps(ido, l1, in, out, &wa[iw], &wa[ix2], &wa[ix3], &wa[ix4]);
+ } break;
+ case 4: {
+ int ix2 = iw + ido;
+ int ix3 = ix2 + ido;
+ radb4_ps(ido, l1, in, out, &wa[iw], &wa[ix2], &wa[ix3]);
+ } break;
+ case 3: {
+ int ix2 = iw + ido;
+ radb3_ps(ido, l1, in, out, &wa[iw], &wa[ix2]);
+ } break;
+ case 2:
+ radb2_ps(ido, l1, in, out, &wa[iw]);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ l1 = l2;
+ iw += (ip - 1)*ido;
+
+ if (out == work2) {
+ out = work1; in = work2;
+ } else {
+ out = work2; in = work1;
+ }
+ }
+ return in; /* this is in fact the output .. */
+}
+
+static int decompose(int n, int *ifac, const int *ntryh) {
+ int nl = n, nf = 0, i, j = 0;
+ for (j=0; ntryh[j]; ++j) {
+ int ntry = ntryh[j];
+ while (nl != 1) {
+ int nq = nl / ntry;
+ int nr = nl - ntry * nq;
+ if (nr == 0) {
+ ifac[2+nf++] = ntry;
+ nl = nq;
+ if (ntry == 2 && nf != 1) {
+ for (i = 2; i <= nf; ++i) {
+ int ib = nf - i + 2;
+ ifac[ib + 1] = ifac[ib];
+ }
+ ifac[2] = 2;
+ }
+ } else break;
+ }
+ }
+ ifac[0] = n;
+ ifac[1] = nf;
+ return nf;
+}
+
+
+
+static void rffti1_ps(int n, float *wa, int *ifac)
+{
+ static const int ntryh[] = { 4,2,3,5,0 };
+ int k1, j, ii;
+
+ int nf = decompose(n,ifac,ntryh);
+ float argh = (2*M_PI) / n;
+ int is = 0;
+ int nfm1 = nf - 1;
+ int l1 = 1;
+ for (k1 = 1; k1 <= nfm1; k1++) {
+ int ip = ifac[k1 + 1];
+ int ld = 0;
+ int l2 = l1*ip;
+ int ido = n / l2;
+ int ipm = ip - 1;
+ for (j = 1; j <= ipm; ++j) {
+ float argld;
+ int i = is, fi=0;
+ ld += l1;
+ argld = ld*argh;
+ for (ii = 3; ii <= ido; ii += 2) {
+ i += 2;
+ fi += 1;
+ wa[i - 2] = cos(fi*argld);
+ wa[i - 1] = sin(fi*argld);
+ }
+ is += ido;
+ }
+ l1 = l2;
+ }
+} /* rffti1 */
+
+void cffti1_ps(int n, float *wa, int *ifac)
+{
+ static const int ntryh[] = { 5,3,4,2,0 };
+ int k1, j, ii;
+
+ int nf = decompose(n,ifac,ntryh);
+ float argh = (2*M_PI)/(float)n;
+ int i = 1;
+ int l1 = 1;
+ for (k1=1; k1<=nf; k1++) {
+ int ip = ifac[k1+1];
+ int ld = 0;
+ int l2 = l1*ip;
+ int ido = n / l2;
+ int idot = ido + ido + 2;
+ int ipm = ip - 1;
+ for (j=1; j<=ipm; j++) {
+ float argld;
+ int i1 = i, fi = 0;
+ wa[i-1] = 1;
+ wa[i] = 0;
+ ld += l1;
+ argld = ld*argh;
+ for (ii = 4; ii <= idot; ii += 2) {
+ i += 2;
+ fi += 1;
+ wa[i-1] = cos(fi*argld);
+ wa[i] = sin(fi*argld);
+ }
+ if (ip > 5) {
+ wa[i1-1] = wa[i-1];
+ wa[i1] = wa[i];
+ }
+ }
+ l1 = l2;
+ }
+} /* cffti1 */
+
+
+v4sf *cfftf1_ps(int n, const v4sf *input_readonly, v4sf *work1, v4sf *work2, const float *wa, const int *ifac, int isign) {
+ v4sf *in = (v4sf*)input_readonly;
+ v4sf *out = (in == work2 ? work1 : work2);
+ int nf = ifac[1], k1;
+ int l1 = 1;
+ int iw = 0;
+ assert(in != out && work1 != work2);
+ for (k1=2; k1<=nf+1; k1++) {
+ int ip = ifac[k1];
+ int l2 = ip*l1;
+ int ido = n / l2;
+ int idot = ido + ido;
+ switch (ip) {
+ case 5: {
+ int ix2 = iw + idot;
+ int ix3 = ix2 + idot;
+ int ix4 = ix3 + idot;
+ passf5_ps(idot, l1, in, out, &wa[iw], &wa[ix2], &wa[ix3], &wa[ix4], isign);
+ } break;
+ case 4: {
+ int ix2 = iw + idot;
+ int ix3 = ix2 + idot;
+ passf4_ps(idot, l1, in, out, &wa[iw], &wa[ix2], &wa[ix3], isign);
+ } break;
+ case 2: {
+ passf2_ps(idot, l1, in, out, &wa[iw], isign);
+ } break;
+ case 3: {
+ int ix2 = iw + idot;
+ passf3_ps(idot, l1, in, out, &wa[iw], &wa[ix2], isign);
+ } break;
+ default:
+ assert(0);
+ }
+ l1 = l2;
+ iw += (ip - 1)*idot;
+ if (out == work2) {
+ out = work1; in = work2;
+ } else {
+ out = work2; in = work1;
+ }
+ }
+
+ return in; /* this is in fact the output .. */
+}
+
+
+struct PFFFT_Setup {
+ int N;
+ int Ncvec; // nb of complex simd vectors (N/4 if PFFFT_COMPLEX, N/8 if PFFFT_REAL)
+ int ifac[15];
+ pffft_transform_t transform;
+ v4sf *data; // allocated room for twiddle coefs
+ float *e; // points into 'data' , N/4*3 elements
+ float *twiddle; // points into 'data', N/4 elements
+};
+
+PFFFT_Setup *pffft_new_setup(int N, pffft_transform_t transform) {
+ PFFFT_Setup *s = (PFFFT_Setup*)malloc(sizeof(PFFFT_Setup));
+ int k, m;
+ /* unfortunately, the fft size must be a multiple of 16 for complex FFTs
+ and 32 for real FFTs -- a lot of stuff would need to be rewritten to
+ handle other cases (or maybe just switch to a scalar fft, I don't know..) */
+ if (transform == PFFFT_REAL) { assert((N%(2*SIMD_SZ*SIMD_SZ))==0 && N>0); }
+ if (transform == PFFFT_COMPLEX) { assert((N%(SIMD_SZ*SIMD_SZ))==0 && N>0); }
+ //assert((N % 32) == 0);
+ s->N = N;
+ s->transform = transform;
+ /* nb of complex simd vectors */
+ s->Ncvec = (transform == PFFFT_REAL ? N/2 : N)/SIMD_SZ;
+ s->data = (v4sf*)pffft_aligned_malloc(2*s->Ncvec * sizeof(v4sf));
+ s->e = (float*)s->data;
+ s->twiddle = (float*)(s->data + (2*s->Ncvec*(SIMD_SZ-1))/SIMD_SZ);
+
+ for (k=0; k < s->Ncvec; ++k) {
+ int i = k/SIMD_SZ;
+ int j = k%SIMD_SZ;
+ for (m=0; m < SIMD_SZ-1; ++m) {
+ float A = -2*M_PI*(m+1)*k / N;
+ s->e[(2*(i*3 + m) + 0) * SIMD_SZ + j] = cos(A);
+ s->e[(2*(i*3 + m) + 1) * SIMD_SZ + j] = sin(A);
+ }
+ }
+
+ if (transform == PFFFT_REAL) {
+ rffti1_ps(N/SIMD_SZ, s->twiddle, s->ifac);
+ } else {
+ cffti1_ps(N/SIMD_SZ, s->twiddle, s->ifac);
+ }
+
+ /* check that N is decomposable with allowed prime factors */
+ for (k=0, m=1; k < s->ifac[1]; ++k) { m *= s->ifac[2+k]; }
+ if (m != N/SIMD_SZ) {
+ pffft_destroy_setup(s); s = 0;
+ }
+
+ return s;
+}
+
+
+void pffft_destroy_setup(PFFFT_Setup *s) {
+ pffft_aligned_free(s->data);
+ free(s);
+}
+
+#if !defined(PFFFT_SIMD_DISABLE)
+
+/* [0 0 1 2 3 4 5 6 7 8] -> [0 8 7 6 5 4 3 2 1] */
+static void reversed_copy(int N, const v4sf *in, int in_stride, v4sf *out) {
+ v4sf g0, g1;
+ int k;
+ INTERLEAVE2(in[0], in[1], g0, g1); in += in_stride;
+
+ *--out = VSWAPHL(g0, g1); // [g0l, g0h], [g1l g1h] -> [g1l, g0h]
+ for (k=1; k < N; ++k) {
+ v4sf h0, h1;
+ INTERLEAVE2(in[0], in[1], h0, h1); in += in_stride;
+ *--out = VSWAPHL(g1, h0);
+ *--out = VSWAPHL(h0, h1);
+ g1 = h1;
+ }
+ *--out = VSWAPHL(g1, g0);
+}
+
+static void unreversed_copy(int N, const v4sf *in, v4sf *out, int out_stride) {
+ v4sf g0, g1, h0, h1;
+ int k;
+ g0 = g1 = in[0]; ++in;
+ for (k=1; k < N; ++k) {
+ h0 = *in++; h1 = *in++;
+ g1 = VSWAPHL(g1, h0);
+ h0 = VSWAPHL(h0, h1);
+ UNINTERLEAVE2(h0, g1, out[0], out[1]); out += out_stride;
+ g1 = h1;
+ }
+ h0 = *in++; h1 = g0;
+ g1 = VSWAPHL(g1, h0);
+ h0 = VSWAPHL(h0, h1);
+ UNINTERLEAVE2(h0, g1, out[0], out[1]);
+}
+
+void pffft_zreorder(PFFFT_Setup *setup, const float *in, float *out, pffft_direction_t direction) {
+ int k, N = setup->N, Ncvec = setup->Ncvec;
+ const v4sf *vin = (const v4sf*)in;
+ v4sf *vout = (v4sf*)out;
+ assert(in != out);
+ if (setup->transform == PFFFT_REAL) {
+ int dk = N/32;
+ if (direction == PFFFT_FORWARD) {
+ for (k=0; k < dk; ++k) {
+ INTERLEAVE2(vin[k*8 + 0], vin[k*8 + 1], vout[2*(0*dk + k) + 0], vout[2*(0*dk + k) + 1]);
+ INTERLEAVE2(vin[k*8 + 4], vin[k*8 + 5], vout[2*(2*dk + k) + 0], vout[2*(2*dk + k) + 1]);
+ }
+ reversed_copy(dk, vin+2, 8, (v4sf*)(out + N/2));
+ reversed_copy(dk, vin+6, 8, (v4sf*)(out + N));
+ } else {
+ for (k=0; k < dk; ++k) {
+ UNINTERLEAVE2(vin[2*(0*dk + k) + 0], vin[2*(0*dk + k) + 1], vout[k*8 + 0], vout[k*8 + 1]);
+ UNINTERLEAVE2(vin[2*(2*dk + k) + 0], vin[2*(2*dk + k) + 1], vout[k*8 + 4], vout[k*8 + 5]);
+ }
+ unreversed_copy(dk, (v4sf*)(in + N/4), (v4sf*)(out + N - 6*SIMD_SZ), -8);
+ unreversed_copy(dk, (v4sf*)(in + 3*N/4), (v4sf*)(out + N - 2*SIMD_SZ), -8);
+ }
+ } else {
+ if (direction == PFFFT_FORWARD) {
+ for (k=0; k < Ncvec; ++k) {
+ int kk = (k/4) + (k%4)*(Ncvec/4);
+ INTERLEAVE2(vin[k*2], vin[k*2+1], vout[kk*2], vout[kk*2+1]);
+ }
+ } else {
+ for (k=0; k < Ncvec; ++k) {
+ int kk = (k/4) + (k%4)*(Ncvec/4);
+ UNINTERLEAVE2(vin[kk*2], vin[kk*2+1], vout[k*2], vout[k*2+1]);
+ }
+ }
+ }
+}
+
+void pffft_cplx_finalize(int Ncvec, const v4sf *in, v4sf *out, const v4sf *e) {
+ int k, dk = Ncvec/SIMD_SZ; // number of 4x4 matrix blocks
+ v4sf r0, i0, r1, i1, r2, i2, r3, i3;
+ v4sf sr0, dr0, sr1, dr1, si0, di0, si1, di1;
+ assert(in != out);
+ for (k=0; k < dk; ++k) {
+ r0 = in[8*k+0]; i0 = in[8*k+1];
+ r1 = in[8*k+2]; i1 = in[8*k+3];
+ r2 = in[8*k+4]; i2 = in[8*k+5];
+ r3 = in[8*k+6]; i3 = in[8*k+7];
+ VTRANSPOSE4(r0,r1,r2,r3);
+ VTRANSPOSE4(i0,i1,i2,i3);
+ VCPLXMUL(r1,i1,e[k*6+0],e[k*6+1]);
+ VCPLXMUL(r2,i2,e[k*6+2],e[k*6+3]);
+ VCPLXMUL(r3,i3,e[k*6+4],e[k*6+5]);
+
+ sr0 = VADD(r0,r2); dr0 = VSUB(r0, r2);
+ sr1 = VADD(r1,r3); dr1 = VSUB(r1, r3);
+ si0 = VADD(i0,i2); di0 = VSUB(i0, i2);
+ si1 = VADD(i1,i3); di1 = VSUB(i1, i3);
+
+ /*
+ transformation for each column is:
+
+ [1 1 1 1 0 0 0 0] [r0]
+ [1 0 -1 0 0 -1 0 1] [r1]
+ [1 -1 1 -1 0 0 0 0] [r2]
+ [1 0 -1 0 0 1 0 -1] [r3]
+ [0 0 0 0 1 1 1 1] * [i0]
+ [0 1 0 -1 1 0 -1 0] [i1]
+ [0 0 0 0 1 -1 1 -1] [i2]
+ [0 -1 0 1 1 0 -1 0] [i3]
+ */
+
+ r0 = VADD(sr0, sr1); i0 = VADD(si0, si1);
+ r1 = VADD(dr0, di1); i1 = VSUB(di0, dr1);
+ r2 = VSUB(sr0, sr1); i2 = VSUB(si0, si1);
+ r3 = VSUB(dr0, di1); i3 = VADD(di0, dr1);
+
+ *out++ = r0; *out++ = i0; *out++ = r1; *out++ = i1;
+ *out++ = r2; *out++ = i2; *out++ = r3; *out++ = i3;
+ }
+}
+
+void pffft_cplx_preprocess(int Ncvec, const v4sf *in, v4sf *out, const v4sf *e) {
+ int k, dk = Ncvec/SIMD_SZ; // number of 4x4 matrix blocks
+ v4sf r0, i0, r1, i1, r2, i2, r3, i3;
+ v4sf sr0, dr0, sr1, dr1, si0, di0, si1, di1;
+ assert(in != out);
+ for (k=0; k < dk; ++k) {
+ r0 = in[8*k+0]; i0 = in[8*k+1];
+ r1 = in[8*k+2]; i1 = in[8*k+3];
+ r2 = in[8*k+4]; i2 = in[8*k+5];
+ r3 = in[8*k+6]; i3 = in[8*k+7];
+
+ sr0 = VADD(r0,r2); dr0 = VSUB(r0, r2);
+ sr1 = VADD(r1,r3); dr1 = VSUB(r1, r3);
+ si0 = VADD(i0,i2); di0 = VSUB(i0, i2);
+ si1 = VADD(i1,i3); di1 = VSUB(i1, i3);
+
+ r0 = VADD(sr0, sr1); i0 = VADD(si0, si1);
+ r1 = VSUB(dr0, di1); i1 = VADD(di0, dr1);
+ r2 = VSUB(sr0, sr1); i2 = VSUB(si0, si1);
+ r3 = VADD(dr0, di1); i3 = VSUB(di0, dr1);
+
+ VCPLXMULCONJ(r1,i1,e[k*6+0],e[k*6+1]);
+ VCPLXMULCONJ(r2,i2,e[k*6+2],e[k*6+3]);
+ VCPLXMULCONJ(r3,i3,e[k*6+4],e[k*6+5]);
+
+ VTRANSPOSE4(r0,r1,r2,r3);
+ VTRANSPOSE4(i0,i1,i2,i3);
+
+ *out++ = r0; *out++ = i0; *out++ = r1; *out++ = i1;
+ *out++ = r2; *out++ = i2; *out++ = r3; *out++ = i3;
+ }
+}
+
+
+static ALWAYS_INLINE(void) pffft_real_finalize_4x4(const v4sf *in0, const v4sf *in1, const v4sf *in,
+ const v4sf *e, v4sf *out) {
+ v4sf r0, i0, r1, i1, r2, i2, r3, i3;
+ v4sf sr0, dr0, sr1, dr1, si0, di0, si1, di1;
+ r0 = *in0; i0 = *in1;
+ r1 = *in++; i1 = *in++; r2 = *in++; i2 = *in++; r3 = *in++; i3 = *in++;
+ VTRANSPOSE4(r0,r1,r2,r3);
+ VTRANSPOSE4(i0,i1,i2,i3);
+
+ /*
+ transformation for each column is:
+
+ [1 1 1 1 0 0 0 0] [r0]
+ [1 0 -1 0 0 -1 0 1] [r1]
+ [1 0 -1 0 0 1 0 -1] [r2]
+ [1 -1 1 -1 0 0 0 0] [r3]
+ [0 0 0 0 1 1 1 1] * [i0]
+ [0 -1 0 1 -1 0 1 0] [i1]
+ [0 -1 0 1 1 0 -1 0] [i2]
+ [0 0 0 0 -1 1 -1 1] [i3]
+ */
+
+ //cerr << "matrix initial, before e , REAL:\n 1: " << r0 << "\n 1: " << r1 << "\n 1: " << r2 << "\n 1: " << r3 << "\n";
+ //cerr << "matrix initial, before e, IMAG :\n 1: " << i0 << "\n 1: " << i1 << "\n 1: " << i2 << "\n 1: " << i3 << "\n";
+
+ VCPLXMUL(r1,i1,e[0],e[1]);
+ VCPLXMUL(r2,i2,e[2],e[3]);
+ VCPLXMUL(r3,i3,e[4],e[5]);
+
+ //cerr << "matrix initial, real part:\n 1: " << r0 << "\n 1: " << r1 << "\n 1: " << r2 << "\n 1: " << r3 << "\n";
+ //cerr << "matrix initial, imag part:\n 1: " << i0 << "\n 1: " << i1 << "\n 1: " << i2 << "\n 1: " << i3 << "\n";
+
+ sr0 = VADD(r0,r2); dr0 = VSUB(r0,r2);
+ sr1 = VADD(r1,r3); dr1 = VSUB(r3,r1);
+ si0 = VADD(i0,i2); di0 = VSUB(i0,i2);
+ si1 = VADD(i1,i3); di1 = VSUB(i3,i1);
+
+ r0 = VADD(sr0, sr1);
+ r3 = VSUB(sr0, sr1);
+ i0 = VADD(si0, si1);
+ i3 = VSUB(si1, si0);
+ r1 = VADD(dr0, di1);
+ r2 = VSUB(dr0, di1);
+ i1 = VSUB(dr1, di0);
+ i2 = VADD(dr1, di0);
+
+ *out++ = r0;
+ *out++ = i0;
+ *out++ = r1;
+ *out++ = i1;
+ *out++ = r2;
+ *out++ = i2;
+ *out++ = r3;
+ *out++ = i3;
+
+}
+
+static NEVER_INLINE(void) pffft_real_finalize(int Ncvec, const v4sf *in, v4sf *out, const v4sf *e) {
+ int k, dk = Ncvec/SIMD_SZ; // number of 4x4 matrix blocks
+ /* fftpack order is f0r f1r f1i f2r f2i ... f(n-1)r f(n-1)i f(n)r */
+
+ v4sf_union cr, ci, *uout = (v4sf_union*)out;
+ v4sf save = in[7], zero=VZERO();
+ float xr0, xi0, xr1, xi1, xr2, xi2, xr3, xi3;
+ static const float s = M_SQRT2/2;
+
+ cr.v = in[0]; ci.v = in[Ncvec*2-1];
+ assert(in != out);
+ pffft_real_finalize_4x4(&zero, &zero, in+1, e, out);
+
+ /*
+ [cr0 cr1 cr2 cr3 ci0 ci1 ci2 ci3]
+
+ [Xr(1)] ] [1 1 1 1 0 0 0 0]
+ [Xr(N/4) ] [0 0 0 0 1 s 0 -s]
+ [Xr(N/2) ] [1 0 -1 0 0 0 0 0]
+ [Xr(3N/4)] [0 0 0 0 1 -s 0 s]
+ [Xi(1) ] [1 -1 1 -1 0 0 0 0]
+ [Xi(N/4) ] [0 0 0 0 0 -s -1 -s]
+ [Xi(N/2) ] [0 -1 0 1 0 0 0 0]
+ [Xi(3N/4)] [0 0 0 0 0 -s 1 -s]
+ */
+
+ xr0=(cr.f[0]+cr.f[2]) + (cr.f[1]+cr.f[3]); uout[0].f[0] = xr0;
+ xi0=(cr.f[0]+cr.f[2]) - (cr.f[1]+cr.f[3]); uout[1].f[0] = xi0;
+ xr2=(cr.f[0]-cr.f[2]); uout[4].f[0] = xr2;
+ xi2=(cr.f[3]-cr.f[1]); uout[5].f[0] = xi2;
+ xr1= ci.f[0] + s*(ci.f[1]-ci.f[3]); uout[2].f[0] = xr1;
+ xi1=-ci.f[2] - s*(ci.f[1]+ci.f[3]); uout[3].f[0] = xi1;
+ xr3= ci.f[0] - s*(ci.f[1]-ci.f[3]); uout[6].f[0] = xr3;
+ xi3= ci.f[2] - s*(ci.f[1]+ci.f[3]); uout[7].f[0] = xi3;
+
+ for (k=1; k < dk; ++k) {
+ v4sf save_next = in[8*k+7];
+ pffft_real_finalize_4x4(&save, &in[8*k+0], in + 8*k+1,
+ e + k*6, out + k*8);
+ save = save_next;
+ }
+
+}
+
+static ALWAYS_INLINE(void) pffft_real_preprocess_4x4(const v4sf *in,
+ const v4sf *e, v4sf *out, int first) {
+ v4sf r0=in[0], i0=in[1], r1=in[2], i1=in[3], r2=in[4], i2=in[5], r3=in[6], i3=in[7];
+ /*
+ transformation for each column is:
+
+ [1 1 1 1 0 0 0 0] [r0]
+ [1 0 0 -1 0 -1 -1 0] [r1]
+ [1 -1 -1 1 0 0 0 0] [r2]
+ [1 0 0 -1 0 1 1 0] [r3]
+ [0 0 0 0 1 -1 1 -1] * [i0]
+ [0 -1 1 0 1 0 0 1] [i1]
+ [0 0 0 0 1 1 -1 -1] [i2]
+ [0 1 -1 0 1 0 0 1] [i3]
+ */
+
+ v4sf sr0 = VADD(r0,r3), dr0 = VSUB(r0,r3);
+ v4sf sr1 = VADD(r1,r2), dr1 = VSUB(r1,r2);
+ v4sf si0 = VADD(i0,i3), di0 = VSUB(i0,i3);
+ v4sf si1 = VADD(i1,i2), di1 = VSUB(i1,i2);
+
+ r0 = VADD(sr0, sr1);
+ r2 = VSUB(sr0, sr1);
+ r1 = VSUB(dr0, si1);
+ r3 = VADD(dr0, si1);
+ i0 = VSUB(di0, di1);
+ i2 = VADD(di0, di1);
+ i1 = VSUB(si0, dr1);
+ i3 = VADD(si0, dr1);
+
+ VCPLXMULCONJ(r1,i1,e[0],e[1]);
+ VCPLXMULCONJ(r2,i2,e[2],e[3]);
+ VCPLXMULCONJ(r3,i3,e[4],e[5]);
+
+ VTRANSPOSE4(r0,r1,r2,r3);
+ VTRANSPOSE4(i0,i1,i2,i3);
+
+ if (!first) {
+ *out++ = r0;
+ *out++ = i0;
+ }
+ *out++ = r1;
+ *out++ = i1;
+ *out++ = r2;
+ *out++ = i2;
+ *out++ = r3;
+ *out++ = i3;
+}
+
+static NEVER_INLINE(void) pffft_real_preprocess(int Ncvec, const v4sf *in, v4sf *out, const v4sf *e) {
+ int k, dk = Ncvec/SIMD_SZ; // number of 4x4 matrix blocks
+ /* fftpack order is f0r f1r f1i f2r f2i ... f(n-1)r f(n-1)i f(n)r */
+
+ v4sf_union Xr, Xi, *uout = (v4sf_union*)out;
+ float cr0, ci0, cr1, ci1, cr2, ci2, cr3, ci3;
+ static const float s = M_SQRT2;
+ assert(in != out);
+ for (k=0; k < 4; ++k) {
+ Xr.f[k] = ((float*)in)[8*k];
+ Xi.f[k] = ((float*)in)[8*k+4];
+ }
+
+ pffft_real_preprocess_4x4(in, e, out+1, 1); // will write only 6 values
+
+ /*
+ [Xr0 Xr1 Xr2 Xr3 Xi0 Xi1 Xi2 Xi3]
+
+ [cr0] [1 0 2 0 1 0 0 0]
+ [cr1] [1 0 0 0 -1 0 -2 0]
+ [cr2] [1 0 -2 0 1 0 0 0]
+ [cr3] [1 0 0 0 -1 0 2 0]
+ [ci0] [0 2 0 2 0 0 0 0]
+ [ci1] [0 s 0 -s 0 -s 0 -s]
+ [ci2] [0 0 0 0 0 -2 0 2]
+ [ci3] [0 -s 0 s 0 -s 0 -s]
+ */
+ for (k=1; k < dk; ++k) {
+ pffft_real_preprocess_4x4(in+8*k, e + k*6, out-1+k*8, 0);
+ }
+
+ cr0=(Xr.f[0]+Xi.f[0]) + 2*Xr.f[2]; uout[0].f[0] = cr0;
+ cr1=(Xr.f[0]-Xi.f[0]) - 2*Xi.f[2]; uout[0].f[1] = cr1;
+ cr2=(Xr.f[0]+Xi.f[0]) - 2*Xr.f[2]; uout[0].f[2] = cr2;
+ cr3=(Xr.f[0]-Xi.f[0]) + 2*Xi.f[2]; uout[0].f[3] = cr3;
+ ci0= 2*(Xr.f[1]+Xr.f[3]); uout[2*Ncvec-1].f[0] = ci0;
+ ci1= s*(Xr.f[1]-Xr.f[3]) - s*(Xi.f[1]+Xi.f[3]); uout[2*Ncvec-1].f[1] = ci1;
+ ci2= 2*(Xi.f[3]-Xi.f[1]); uout[2*Ncvec-1].f[2] = ci2;
+ ci3=-s*(Xr.f[1]-Xr.f[3]) - s*(Xi.f[1]+Xi.f[3]); uout[2*Ncvec-1].f[3] = ci3;
+}
+
+
+void pffft_transform_internal(PFFFT_Setup *setup, const float *finput, float *foutput, v4sf *scratch,
+ pffft_direction_t direction, int ordered) {
+ int k, Ncvec = setup->Ncvec;
+ int nf_odd = (setup->ifac[1] & 1);
+
+ // temporary buffer is allocated on the stack if the scratch pointer is NULL
+ int stack_allocate = (scratch == 0 ? Ncvec*2 : 1);
+ VLA_ARRAY_ON_STACK(v4sf, scratch_on_stack, stack_allocate);
+
+ const v4sf *vinput = (const v4sf*)finput;
+ v4sf *voutput = (v4sf*)foutput;
+ v4sf *buff[2] = { voutput, scratch ? scratch : scratch_on_stack };
+ int ib = (nf_odd ^ ordered ? 1 : 0);
+
+ assert(VALIGNED(finput) && VALIGNED(foutput));
+
+ //assert(finput != foutput);
+ if (direction == PFFFT_FORWARD) {
+ ib = !ib;
+ if (setup->transform == PFFFT_REAL) {
+ ib = (rfftf1_ps(Ncvec*2, vinput, buff[ib], buff[!ib],
+ setup->twiddle, &setup->ifac[0]) == buff[0] ? 0 : 1);
+ pffft_real_finalize(Ncvec, buff[ib], buff[!ib], (v4sf*)setup->e);
+ } else {
+ v4sf *tmp = buff[ib];
+ for (k=0; k < Ncvec; ++k) {
+ UNINTERLEAVE2(vinput[k*2], vinput[k*2+1], tmp[k*2], tmp[k*2+1]);
+ }
+ ib = (cfftf1_ps(Ncvec, buff[ib], buff[!ib], buff[ib],
+ setup->twiddle, &setup->ifac[0], -1) == buff[0] ? 0 : 1);
+ pffft_cplx_finalize(Ncvec, buff[ib], buff[!ib], (v4sf*)setup->e);
+ }
+ if (ordered) {
+ pffft_zreorder(setup, (float*)buff[!ib], (float*)buff[ib], PFFFT_FORWARD);
+ } else ib = !ib;
+ } else {
+ if (vinput == buff[ib]) {
+ ib = !ib; // may happen when finput == foutput
+ }
+ if (ordered) {
+ pffft_zreorder(setup, (float*)vinput, (float*)buff[ib], PFFFT_BACKWARD);
+ vinput = buff[ib]; ib = !ib;
+ }
+ if (setup->transform == PFFFT_REAL) {
+ pffft_real_preprocess(Ncvec, vinput, buff[ib], (v4sf*)setup->e);
+ ib = (rfftb1_ps(Ncvec*2, buff[ib], buff[0], buff[1],
+ setup->twiddle, &setup->ifac[0]) == buff[0] ? 0 : 1);
+ } else {
+ pffft_cplx_preprocess(Ncvec, vinput, buff[ib], (v4sf*)setup->e);
+ ib = (cfftf1_ps(Ncvec, buff[ib], buff[0], buff[1],
+ setup->twiddle, &setup->ifac[0], +1) == buff[0] ? 0 : 1);
+ for (k=0; k < Ncvec; ++k) {
+ INTERLEAVE2(buff[ib][k*2], buff[ib][k*2+1], buff[ib][k*2], buff[ib][k*2+1]);
+ }
+ }
+ }
+
+ if (buff[ib] != voutput) {
+ /* extra copy required -- this situation should only happen when finput == foutput */
+ assert(finput==foutput);
+ for (k=0; k < Ncvec; ++k) {
+ v4sf a = buff[ib][2*k], b = buff[ib][2*k+1];
+ voutput[2*k] = a; voutput[2*k+1] = b;
+ }
+ ib = !ib;
+ }
+ assert(buff[ib] == voutput);
+}
+
+void pffft_zconvolve_accumulate(PFFFT_Setup *s, const float *a, const float *b, float *ab, float scaling) {
+ int Ncvec = s->Ncvec;
+ const v4sf * RESTRICT va = (const v4sf*)a;
+ const v4sf * RESTRICT vb = (const v4sf*)b;
+ v4sf * RESTRICT vab = (v4sf*)ab;
+
+#ifdef __arm__
+ __builtin_prefetch(va);
+ __builtin_prefetch(vb);
+ __builtin_prefetch(vab);
+ __builtin_prefetch(va+2);
+ __builtin_prefetch(vb+2);
+ __builtin_prefetch(vab+2);
+ __builtin_prefetch(va+4);
+ __builtin_prefetch(vb+4);
+ __builtin_prefetch(vab+4);
+ __builtin_prefetch(va+6);
+ __builtin_prefetch(vb+6);
+ __builtin_prefetch(vab+6);
+# ifndef __clang__
+# define ZCONVOLVE_USING_INLINE_NEON_ASM
+# endif
+#endif
+
+ float ar0, ai0, br0, bi0, abr0, abi0;
+#ifndef ZCONVOLVE_USING_INLINE_ASM
+ v4sf vscal = LD_PS1(scaling);
+ int i;
+#endif
+
+ assert(VALIGNED(a) && VALIGNED(b) && VALIGNED(ab));
+ ar0 = ((v4sf_union*)va)[0].f[0];
+ ai0 = ((v4sf_union*)va)[1].f[0];
+ br0 = ((v4sf_union*)vb)[0].f[0];
+ bi0 = ((v4sf_union*)vb)[1].f[0];
+ abr0 = ((v4sf_union*)vab)[0].f[0];
+ abi0 = ((v4sf_union*)vab)[1].f[0];
+
+#ifdef ZCONVOLVE_USING_INLINE_ASM // inline asm version, unfortunately miscompiled by clang 3.2, at least on ubuntu.. so this will be restricted to gcc
+ const float *a_ = a, *b_ = b; float *ab_ = ab;
+ int N = Ncvec;
+ asm volatile("mov r8, %2 \n"
+ "vdup.f32 q15, %4 \n"
+ "1: \n"
+ "pld [%0,#64] \n"
+ "pld [%1,#64] \n"
+ "pld [%2,#64] \n"
+ "pld [%0,#96] \n"
+ "pld [%1,#96] \n"
+ "pld [%2,#96] \n"
+ "vld1.f32 {q0,q1}, [%0,:128]! \n"
+ "vld1.f32 {q4,q5}, [%1,:128]! \n"
+ "vld1.f32 {q2,q3}, [%0,:128]! \n"
+ "vld1.f32 {q6,q7}, [%1,:128]! \n"
+ "vld1.f32 {q8,q9}, [r8,:128]! \n"
+
+ "vmul.f32 q10, q0, q4 \n"
+ "vmul.f32 q11, q0, q5 \n"
+ "vmul.f32 q12, q2, q6 \n"
+ "vmul.f32 q13, q2, q7 \n"
+ "vmls.f32 q10, q1, q5 \n"
+ "vmla.f32 q11, q1, q4 \n"
+ "vld1.f32 {q0,q1}, [r8,:128]! \n"
+ "vmls.f32 q12, q3, q7 \n"
+ "vmla.f32 q13, q3, q6 \n"
+ "vmla.f32 q8, q10, q15 \n"
+ "vmla.f32 q9, q11, q15 \n"
+ "vmla.f32 q0, q12, q15 \n"
+ "vmla.f32 q1, q13, q15 \n"
+ "vst1.f32 {q8,q9},[%2,:128]! \n"
+ "vst1.f32 {q0,q1},[%2,:128]! \n"
+ "subs %3, #2 \n"
+ "bne 1b \n"
+ : "+r"(a_), "+r"(b_), "+r"(ab_), "+r"(N) : "r"(scaling) : "r8", "q0","q1","q2","q3","q4","q5","q6","q7","q8","q9", "q10","q11","q12","q13","q15","memory");
+#else // default routine, works fine for non-arm cpus with current compilers
+ for (i=0; i < Ncvec; i += 2) {
+ v4sf ar, ai, br, bi;
+ ar = va[2*i+0]; ai = va[2*i+1];
+ br = vb[2*i+0]; bi = vb[2*i+1];
+ VCPLXMUL(ar, ai, br, bi);
+ vab[2*i+0] = VMADD(ar, vscal, vab[2*i+0]);
+ vab[2*i+1] = VMADD(ai, vscal, vab[2*i+1]);
+ ar = va[2*i+2]; ai = va[2*i+3];
+ br = vb[2*i+2]; bi = vb[2*i+3];
+ VCPLXMUL(ar, ai, br, bi);
+ vab[2*i+2] = VMADD(ar, vscal, vab[2*i+2]);
+ vab[2*i+3] = VMADD(ai, vscal, vab[2*i+3]);
+ }
+#endif
+ if (s->transform == PFFFT_REAL) {
+ ((v4sf_union*)vab)[0].f[0] = abr0 + ar0*br0*scaling;
+ ((v4sf_union*)vab)[1].f[0] = abi0 + ai0*bi0*scaling;
+ }
+}
+
+
+#else // defined(PFFFT_SIMD_DISABLE)
+
+// standard routine using scalar floats, without SIMD stuff.
+
+#define pffft_zreorder_nosimd pffft_zreorder
+void pffft_zreorder_nosimd(PFFFT_Setup *setup, const float *in, float *out, pffft_direction_t direction) {
+ int k, N = setup->N;
+ if (setup->transform == PFFFT_COMPLEX) {
+ for (k=0; k < 2*N; ++k) out[k] = in[k];
+ return;
+ }
+ else if (direction == PFFFT_FORWARD) {
+ float x_N = in[N-1];
+ for (k=N-1; k > 1; --k) out[k] = in[k-1];
+ out[0] = in[0];
+ out[1] = x_N;
+ } else {
+ float x_N = in[1];
+ for (k=1; k < N-1; ++k) out[k] = in[k+1];
+ out[0] = in[0];
+ out[N-1] = x_N;
+ }
+}
+
+#define pffft_transform_internal_nosimd pffft_transform_internal
+void pffft_transform_internal_nosimd(PFFFT_Setup *setup, const float *input, float *output, float *scratch,
+ pffft_direction_t direction, int ordered) {
+ int Ncvec = setup->Ncvec;
+ int nf_odd = (setup->ifac[1] & 1);
+
+ // temporary buffer is allocated on the stack if the scratch pointer is NULL
+ int stack_allocate = (scratch == 0 ? Ncvec*2 : 1);
+ VLA_ARRAY_ON_STACK(v4sf, scratch_on_stack, stack_allocate);
+ float *buff[2];
+ int ib;
+ if (scratch == 0) scratch = scratch_on_stack;
+ buff[0] = output; buff[1] = scratch;
+
+ if (setup->transform == PFFFT_COMPLEX) ordered = 0; // it is always ordered.
+ ib = (nf_odd ^ ordered ? 1 : 0);
+
+ if (direction == PFFFT_FORWARD) {
+ if (setup->transform == PFFFT_REAL) {
+ ib = (rfftf1_ps(Ncvec*2, input, buff[ib], buff[!ib],
+ setup->twiddle, &setup->ifac[0]) == buff[0] ? 0 : 1);
+ } else {
+ ib = (cfftf1_ps(Ncvec, input, buff[ib], buff[!ib],
+ setup->twiddle, &setup->ifac[0], -1) == buff[0] ? 0 : 1);
+ }
+ if (ordered) {
+ pffft_zreorder(setup, buff[ib], buff[!ib], PFFFT_FORWARD); ib = !ib;
+ }
+ } else {
+ if (input == buff[ib]) {
+ ib = !ib; // may happen when finput == foutput
+ }
+ if (ordered) {
+ pffft_zreorder(setup, input, buff[!ib], PFFFT_BACKWARD);
+ input = buff[!ib];
+ }
+ if (setup->transform == PFFFT_REAL) {
+ ib = (rfftb1_ps(Ncvec*2, input, buff[ib], buff[!ib],
+ setup->twiddle, &setup->ifac[0]) == buff[0] ? 0 : 1);
+ } else {
+ ib = (cfftf1_ps(Ncvec, input, buff[ib], buff[!ib],
+ setup->twiddle, &setup->ifac[0], +1) == buff[0] ? 0 : 1);
+ }
+ }
+ if (buff[ib] != output) {
+ int k;
+ // extra copy required -- this situation should happens only when finput == foutput
+ assert(input==output);
+ for (k=0; k < Ncvec; ++k) {
+ float a = buff[ib][2*k], b = buff[ib][2*k+1];
+ output[2*k] = a; output[2*k+1] = b;
+ }
+ ib = !ib;
+ }
+ assert(buff[ib] == output);
+}
+
+#define pffft_zconvolve_accumulate_nosimd pffft_zconvolve_accumulate
+void pffft_zconvolve_accumulate_nosimd(PFFFT_Setup *s, const float *a, const float *b,
+ float *ab, float scaling) {
+ int i, Ncvec = s->Ncvec;
+
+ if (s->transform == PFFFT_REAL) {
+ // take care of the fftpack ordering
+ ab[0] += a[0]*b[0]*scaling;
+ ab[2*Ncvec-1] += a[2*Ncvec-1]*b[2*Ncvec-1]*scaling;
+ ++ab; ++a; ++b; --Ncvec;
+ }
+ for (i=0; i < Ncvec; ++i) {
+ float ar, ai, br, bi;
+ ar = a[2*i+0]; ai = a[2*i+1];
+ br = b[2*i+0]; bi = b[2*i+1];
+ VCPLXMUL(ar, ai, br, bi);
+ ab[2*i+0] += ar*scaling;
+ ab[2*i+1] += ai*scaling;
+ }
+}
+
+#endif // defined(PFFFT_SIMD_DISABLE)
+
+void pffft_transform(PFFFT_Setup *setup, const float *input, float *output, float *work, pffft_direction_t direction) {
+ pffft_transform_internal(setup, input, output, (v4sf*)work, direction, 0);
+}
+
+void pffft_transform_ordered(PFFFT_Setup *setup, const float *input, float *output, float *work, pffft_direction_t direction) {
+ pffft_transform_internal(setup, input, output, (v4sf*)work, direction, 1);
+}
diff --git a/src/3rdparty/pffft/pffft.h b/src/3rdparty/pffft/pffft.h
new file mode 100644
index 000000000..5db3d1135
--- /dev/null
+++ b/src/3rdparty/pffft/pffft.h
@@ -0,0 +1,177 @@
+/* Copyright (c) 2013 Julien Pommier ( pommier@modartt.com )
+
+ Based on original fortran 77 code from FFTPACKv4 from NETLIB,
+ authored by Dr Paul Swarztrauber of NCAR, in 1985.
+
+ As confirmed by the NCAR fftpack software curators, the following
+ FFTPACKv5 license applies to FFTPACKv4 sources. My changes are
+ released under the same terms.
+
+ FFTPACK license:
+
+ http://www.cisl.ucar.edu/css/software/fftpack5/ftpk.html
+
+ Copyright (c) 2004 the University Corporation for Atmospheric
+ Research ("UCAR"). All rights reserved. Developed by NCAR's
+ Computational and Information Systems Laboratory, UCAR,
+ www.cisl.ucar.edu.
+
+ Redistribution and use of the Software in source and binary forms,
+ with or without modification, is permitted provided that the
+ following conditions are met:
+
+ - Neither the names of NCAR's Computational and Information Systems
+ Laboratory, the University Corporation for Atmospheric Research,
+ nor the names of its sponsors or contributors may be used to
+ endorse or promote products derived from this Software without
+ specific prior written permission.
+
+ - Redistributions of source code must retain the above copyright
+ notices, this list of conditions, and the disclaimer below.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions, and the disclaimer below in the
+ documentation and/or other materials provided with the
+ distribution.
+
+ THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+ SOFTWARE.
+*/
+
+/*
+ PFFFT : a Pretty Fast FFT.
+
+ This is basically an adaptation of the single precision fftpack
+ (v4) as found on netlib taking advantage of SIMD instruction found
+ on cpus such as intel x86 (SSE1), powerpc (Altivec), and arm (NEON).
+
+ For architectures where no SIMD instruction is available, the code
+ falls back to a scalar version.
+
+ Restrictions:
+
+ - 1D transforms only, with 32-bit single precision.
+
+ - supports only transforms for inputs of length N of the form
+ N=(2^a)*(3^b)*(5^c), a >= 5, b >=0, c >= 0 (32, 48, 64, 96, 128,
+ 144, 160, etc are all acceptable lengths). Performance is best for
+ 128<=N<=8192.
+
+ - all (float*) pointers in the functions below are expected to
+ have an "simd-compatible" alignment, that is 16 bytes on x86 and
+ powerpc CPUs.
+
+ You can allocate such buffers with the functions
+ pffft_aligned_malloc / pffft_aligned_free (or with stuff like
+ posix_memalign..)
+
+*/
+
+#ifndef PFFFT_H
+#define PFFFT_H
+
+#include <stddef.h> // for size_t
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ /* opaque struct holding internal stuff (precomputed twiddle factors)
+ this struct can be shared by many threads as it contains only
+ read-only data.
+ */
+ typedef struct PFFFT_Setup PFFFT_Setup;
+
+ /* direction of the transform */
+ typedef enum { PFFFT_FORWARD, PFFFT_BACKWARD } pffft_direction_t;
+
+ /* type of transform */
+ typedef enum { PFFFT_REAL, PFFFT_COMPLEX } pffft_transform_t;
+
+ /*
+ prepare for performing transforms of size N -- the returned
+ PFFFT_Setup structure is read-only so it can safely be shared by
+ multiple concurrent threads.
+ */
+ PFFFT_Setup *pffft_new_setup(int N, pffft_transform_t transform);
+ void pffft_destroy_setup(PFFFT_Setup *);
+ /*
+ Perform a Fourier transform , The z-domain data is stored in the
+ most efficient order for transforming it back, or using it for
+ convolution. If you need to have its content sorted in the
+ "usual" way, that is as an array of interleaved complex numbers,
+ either use pffft_transform_ordered , or call pffft_zreorder after
+ the forward fft, and before the backward fft.
+
+ Transforms are not scaled: PFFFT_BACKWARD(PFFFT_FORWARD(x)) = N*x.
+ Typically you will want to scale the backward transform by 1/N.
+
+ The 'work' pointer should point to an area of N (2*N for complex
+ fft) floats, properly aligned. If 'work' is NULL, then stack will
+ be used instead (this is probably the best strategy for small
+ FFTs, say for N < 16384).
+
+ input and output may alias.
+ */
+ void pffft_transform(PFFFT_Setup *setup, const float *input, float *output, float *work, pffft_direction_t direction);
+
+ /*
+ Similar to pffft_transform, but makes sure that the output is
+ ordered as expected (interleaved complex numbers). This is
+ similar to calling pffft_transform and then pffft_zreorder.
+
+ input and output may alias.
+ */
+ void pffft_transform_ordered(PFFFT_Setup *setup, const float *input, float *output, float *work, pffft_direction_t direction);
+
+ /*
+ call pffft_zreorder(.., PFFFT_FORWARD) after pffft_transform(...,
+ PFFFT_FORWARD) if you want to have the frequency components in
+ the correct "canonical" order, as interleaved complex numbers.
+
+ (for real transforms, both 0-frequency and half frequency
+ components, which are real, are assembled in the first entry as
+ F(0)+i*F(n/2+1). Note that the original fftpack did place
+ F(n/2+1) at the end of the arrays).
+
+ input and output should not alias.
+ */
+ void pffft_zreorder(PFFFT_Setup *setup, const float *input, float *output, pffft_direction_t direction);
+
+ /*
+ Perform a multiplication of the frequency components of dft_a and
+ dft_b and accumulate them into dft_ab. The arrays should have
+ been obtained with pffft_transform(.., PFFFT_FORWARD) and should
+ *not* have been reordered with pffft_zreorder (otherwise just
+ perform the operation yourself as the dft coefs are stored as
+ interleaved complex numbers).
+
+ the operation performed is: dft_ab += (dft_a * fdt_b)*scaling
+
+ The dft_a, dft_b and dft_ab pointers may alias.
+ */
+ void pffft_zconvolve_accumulate(PFFFT_Setup *setup, const float *dft_a, const float *dft_b, float *dft_ab, float scaling);
+
+ /*
+ the float buffers must have the correct alignment (16-byte boundary
+ on intel and powerpc). This function may be used to obtain such
+ correctly aligned buffers.
+ */
+ void *pffft_aligned_malloc(size_t nb_bytes);
+ void pffft_aligned_free(void *);
+
+ /* return 4 or 1 wether support SSE/Altivec instructions was enable when building pffft.c */
+ int pffft_simd_size(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // PFFFT_H
diff --git a/src/3rdparty/pffft/qt_attribution.json b/src/3rdparty/pffft/qt_attribution.json
new file mode 100644
index 000000000..2cf2c7264
--- /dev/null
+++ b/src/3rdparty/pffft/qt_attribution.json
@@ -0,0 +1,16 @@
+{
+ "Id": "pfft",
+ "Name": "pfft",
+ "QDocModule": "qtspatialaudio",
+ "Description": "A pretty fast FFT.",
+ "QtUsage": "Used to support spatial audio.",
+ "SecurityCritical": true,
+
+ "Homepage": "https://bitbucket.org/jpommier/pffft.git",
+ "Version": "fbc4058602803f40dc554b8a5d2bcc694c005f2f",
+ "DownloadLocation": "https://bitbucket.org/jpommier/pffft/get/fbc405860280.zip",
+ "CopyrightFile": "COPYRIGHTS",
+ "License": "BSD 3-Clause \"New\" or \"Revised\" License",
+ "LicenseId": "BSD-3-Clause",
+ "LicenseFile": "LICENSE"
+}
diff --git a/src/3rdparty/pffft/test_pffft.c b/src/3rdparty/pffft/test_pffft.c
new file mode 100644
index 000000000..b217b6bec
--- /dev/null
+++ b/src/3rdparty/pffft/test_pffft.c
@@ -0,0 +1,463 @@
+/*
+ Copyright (c) 2013 Julien Pommier.
+
+ Small test & bench for PFFFT, comparing its performance with the scalar FFTPACK, FFTW, Intel MKL, and Apple vDSP
+
+ How to build:
+
+ on linux, with fftw3:
+ gcc -o test_pffft -DHAVE_FFTW -msse -mfpmath=sse -O3 -Wall -W pffft.c test_pffft.c fftpack.c -L/usr/local/lib -I/usr/local/include/ -lfftw3f -lm
+
+ on macos, without fftw3:
+ clang -o test_pffft -DHAVE_VECLIB -O3 -Wall -W pffft.c test_pffft.c fftpack.c -L/usr/local/lib -I/usr/local/include/ -framework Accelerate
+
+ on macos, with fftw3:
+ clang -o test_pffft -DHAVE_FFTW -DHAVE_VECLIB -O3 -Wall -W pffft.c test_pffft.c fftpack.c -L/usr/local/lib -I/usr/local/include/ -lfftw3f -framework Accelerate
+
+ on macos, with fftw3 and Intel MKL:
+ clang -o test_pffft -I /opt/intel/mkl/include -DHAVE_FFTW -DHAVE_VECLIB -DHAVE_MKL -O3 -Wall -W pffft.c test_pffft.c fftpack.c -L/usr/local/lib -I/usr/local/include/ -lfftw3f -framework Accelerate /opt/intel/mkl/lib/libmkl_{intel_lp64,sequential,core}.a
+
+ on windows, with visual c++:
+ cl /Ox -D_USE_MATH_DEFINES /arch:SSE test_pffft.c pffft.c fftpack.c
+
+ build without SIMD instructions:
+ gcc -o test_pffft -DPFFFT_SIMD_DISABLE -O3 -Wall -W pffft.c test_pffft.c fftpack.c -lm
+
+ */
+
+#include "pffft.h"
+#include "fftpack.h"
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <assert.h>
+#include <string.h>
+
+#ifdef HAVE_SYS_TIMES
+# include <sys/times.h>
+# include <unistd.h>
+#endif
+
+#ifdef HAVE_VECLIB
+# include <Accelerate/Accelerate.h>
+#endif
+
+#ifdef HAVE_FFTW
+# include <fftw3.h>
+#endif
+
+#ifdef HAVE_MKL
+# include <mkl_dfti.h>
+#endif
+
+#define MAX_OF(x,y) ((x)>(y)?(x):(y))
+
+double frand() {
+ return rand()/(double)RAND_MAX;
+}
+
+#if defined(HAVE_SYS_TIMES)
+ inline double uclock_sec(void) {
+ static double ttclk = 0.;
+ if (ttclk == 0.) ttclk = sysconf(_SC_CLK_TCK);
+ struct tms t; return ((double)times(&t)) / ttclk;
+ }
+# else
+ double uclock_sec(void)
+{ return (double)clock()/(double)CLOCKS_PER_SEC; }
+#endif
+
+
+/* compare results with the regular fftpack */
+void pffft_validate_N(int N, int cplx) {
+ int Nfloat = N*(cplx?2:1);
+ int Nbytes = Nfloat * sizeof(float);
+ float *ref, *in, *out, *tmp, *tmp2;
+ PFFFT_Setup *s = pffft_new_setup(N, cplx ? PFFFT_COMPLEX : PFFFT_REAL);
+ int pass;
+
+ if (!s) { printf("Skipping N=%d, not supported\n", N); return; }
+ ref = pffft_aligned_malloc(Nbytes);
+ in = pffft_aligned_malloc(Nbytes);
+ out = pffft_aligned_malloc(Nbytes);
+ tmp = pffft_aligned_malloc(Nbytes);
+ tmp2 = pffft_aligned_malloc(Nbytes);
+
+ for (pass=0; pass < 2; ++pass) {
+ float ref_max = 0;
+ int k;
+ //printf("N=%d pass=%d cplx=%d\n", N, pass, cplx);
+ // compute reference solution with FFTPACK
+ if (pass == 0) {
+ float *wrk = malloc(2*Nbytes+15*sizeof(float));
+ for (k=0; k < Nfloat; ++k) {
+ ref[k] = in[k] = frand()*2-1;
+ out[k] = 1e30;
+ }
+ if (!cplx) {
+ rffti(N, wrk);
+ rfftf(N, ref, wrk);
+ // use our ordering for real ffts instead of the one of fftpack
+ {
+ float refN=ref[N-1];
+ for (k=N-2; k >= 1; --k) ref[k+1] = ref[k];
+ ref[1] = refN;
+ }
+ } else {
+ cffti(N, wrk);
+ cfftf(N, ref, wrk);
+ }
+ free(wrk);
+ }
+
+ for (k = 0; k < Nfloat; ++k) ref_max = MAX_OF(ref_max, fabs(ref[k]));
+
+
+ // pass 0 : non canonical ordering of transform coefficients
+ if (pass == 0) {
+ // test forward transform, with different input / output
+ pffft_transform(s, in, tmp, 0, PFFFT_FORWARD);
+ memcpy(tmp2, tmp, Nbytes);
+ memcpy(tmp, in, Nbytes);
+ pffft_transform(s, tmp, tmp, 0, PFFFT_FORWARD);
+ for (k = 0; k < Nfloat; ++k) {
+ assert(tmp2[k] == tmp[k]);
+ }
+
+ // test reordering
+ pffft_zreorder(s, tmp, out, PFFFT_FORWARD);
+ pffft_zreorder(s, out, tmp, PFFFT_BACKWARD);
+ for (k = 0; k < Nfloat; ++k) {
+ assert(tmp2[k] == tmp[k]);
+ }
+ pffft_zreorder(s, tmp, out, PFFFT_FORWARD);
+ } else {
+ // pass 1 : canonical ordering of transform coeffs.
+ pffft_transform_ordered(s, in, tmp, 0, PFFFT_FORWARD);
+ memcpy(tmp2, tmp, Nbytes);
+ memcpy(tmp, in, Nbytes);
+ pffft_transform_ordered(s, tmp, tmp, 0, PFFFT_FORWARD);
+ for (k = 0; k < Nfloat; ++k) {
+ assert(tmp2[k] == tmp[k]);
+ }
+ memcpy(out, tmp, Nbytes);
+ }
+
+ {
+ for (k=0; k < Nfloat; ++k) {
+ if (!(fabs(ref[k] - out[k]) < 1e-3*ref_max)) {
+ printf("%s forward PFFFT mismatch found for N=%d\n", (cplx?"CPLX":"REAL"), N);
+ exit(1);
+ }
+ }
+
+ if (pass == 0) pffft_transform(s, tmp, out, 0, PFFFT_BACKWARD);
+ else pffft_transform_ordered(s, tmp, out, 0, PFFFT_BACKWARD);
+ memcpy(tmp2, out, Nbytes);
+ memcpy(out, tmp, Nbytes);
+ if (pass == 0) pffft_transform(s, out, out, 0, PFFFT_BACKWARD);
+ else pffft_transform_ordered(s, out, out, 0, PFFFT_BACKWARD);
+ for (k = 0; k < Nfloat; ++k) {
+ assert(tmp2[k] == out[k]);
+ out[k] *= 1.f/N;
+ }
+ for (k = 0; k < Nfloat; ++k) {
+ if (fabs(in[k] - out[k]) > 1e-3 * ref_max) {
+ printf("pass=%d, %s IFFFT does not match for N=%d\n", pass, (cplx?"CPLX":"REAL"), N); break;
+ exit(1);
+ }
+ }
+ }
+
+ // quick test of the circular convolution in fft domain
+ {
+ float conv_err = 0, conv_max = 0;
+
+ pffft_zreorder(s, ref, tmp, PFFFT_FORWARD);
+ memset(out, 0, Nbytes);
+ pffft_zconvolve_accumulate(s, ref, ref, out, 1.0);
+ pffft_zreorder(s, out, tmp2, PFFFT_FORWARD);
+
+ for (k=0; k < Nfloat; k += 2) {
+ float ar = tmp[k], ai=tmp[k+1];
+ if (cplx || k > 0) {
+ tmp[k] = ar*ar - ai*ai;
+ tmp[k+1] = 2*ar*ai;
+ } else {
+ tmp[0] = ar*ar;
+ tmp[1] = ai*ai;
+ }
+ }
+
+ for (k=0; k < Nfloat; ++k) {
+ float d = fabs(tmp[k] - tmp2[k]), e = fabs(tmp[k]);
+ if (d > conv_err) conv_err = d;
+ if (e > conv_max) conv_max = e;
+ }
+ if (conv_err > 1e-5*conv_max) {
+ printf("zconvolve error ? %g %g\n", conv_err, conv_max); exit(1);
+ }
+ }
+
+ }
+
+ printf("%s PFFFT is OK for N=%d\n", (cplx?"CPLX":"REAL"), N); fflush(stdout);
+
+ pffft_destroy_setup(s);
+ pffft_aligned_free(ref);
+ pffft_aligned_free(in);
+ pffft_aligned_free(out);
+ pffft_aligned_free(tmp);
+ pffft_aligned_free(tmp2);
+}
+
+void pffft_validate(int cplx) {
+ static int Ntest[] = { 16, 32, 64, 96, 128, 160, 192, 256, 288, 384, 5*96, 512, 576, 5*128, 800, 864, 1024, 2048, 2592, 4000, 4096, 12000, 36864, 0};
+ int k;
+ for (k = 0; Ntest[k]; ++k) {
+ int N = Ntest[k];
+ if (N == 16 && !cplx) continue;
+ pffft_validate_N(N, cplx);
+ }
+}
+
+int array_output_format = 1;
+
+void show_output(const char *name, int N, int cplx, float flops, float t0, float t1, int max_iter) {
+ float mflops = flops/1e6/(t1 - t0 + 1e-16);
+ if (array_output_format) {
+ if (flops != -1) {
+ printf("|%9.0f ", mflops);
+ } else printf("| n/a ");
+ } else {
+ if (flops != -1) {
+ printf("N=%5d, %s %16s : %6.0f MFlops [t=%6.0f ns, %d runs]\n", N, (cplx?"CPLX":"REAL"), name, mflops, (t1-t0)/2/max_iter * 1e9, max_iter);
+ }
+ }
+ fflush(stdout);
+}
+
+void benchmark_ffts(int N, int cplx) {
+ int Nfloat = (cplx ? N*2 : N);
+ int Nbytes = Nfloat * sizeof(float);
+ float *X = pffft_aligned_malloc(Nbytes), *Y = pffft_aligned_malloc(Nbytes), *Z = pffft_aligned_malloc(Nbytes);
+
+ double t0, t1, flops;
+
+ int k;
+ int max_iter = 5120000/N*4;
+#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
+ max_iter /= 8;
+#endif
+ int iter;
+
+ for (k = 0; k < Nfloat; ++k) {
+ X[k] = 0; //sqrtf(k+1);
+ }
+
+ // FFTPack benchmark
+ {
+ float *wrk = malloc(2*Nbytes + 15*sizeof(float));
+ int max_iter_ = max_iter/pffft_simd_size(); if (max_iter_ == 0) max_iter_ = 1;
+ if (cplx) cffti(N, wrk);
+ else rffti(N, wrk);
+ t0 = uclock_sec();
+
+ for (iter = 0; iter < max_iter_; ++iter) {
+ if (cplx) {
+ cfftf(N, X, wrk);
+ cfftb(N, X, wrk);
+ } else {
+ rfftf(N, X, wrk);
+ rfftb(N, X, wrk);
+ }
+ }
+ t1 = uclock_sec();
+ free(wrk);
+
+ flops = (max_iter_*2) * ((cplx ? 5 : 2.5)*N*log((double)N)/M_LN2); // see http://www.fftw.org/speed/method.html
+ show_output("FFTPack", N, cplx, flops, t0, t1, max_iter_);
+ }
+
+#ifdef HAVE_VECLIB
+ int log2N = (int)(log(N)/log(2) + 0.5f);
+ if (N == (1<<log2N)) {
+ FFTSetup setup;
+
+ setup = vDSP_create_fftsetup(log2N, FFT_RADIX2);
+ DSPSplitComplex zsamples;
+ zsamples.realp = &X[0];
+ zsamples.imagp = &X[Nfloat/2];
+ t0 = uclock_sec();
+ for (iter = 0; iter < max_iter; ++iter) {
+ if (cplx) {
+ vDSP_fft_zip(setup, &zsamples, 1, log2N, kFFTDirection_Forward);
+ vDSP_fft_zip(setup, &zsamples, 1, log2N, kFFTDirection_Inverse);
+ } else {
+ vDSP_fft_zrip(setup, &zsamples, 1, log2N, kFFTDirection_Forward);
+ vDSP_fft_zrip(setup, &zsamples, 1, log2N, kFFTDirection_Inverse);
+ }
+ }
+ t1 = uclock_sec();
+ vDSP_destroy_fftsetup(setup);
+
+ flops = (max_iter*2) * ((cplx ? 5 : 2.5)*N*log((double)N)/M_LN2); // see http://www.fftw.org/speed/method.html
+ show_output("vDSP", N, cplx, flops, t0, t1, max_iter);
+ } else {
+ show_output("vDSP", N, cplx, -1, -1, -1, -1);
+ }
+#endif
+
+#ifdef HAVE_MKL
+ {
+ DFTI_DESCRIPTOR_HANDLE fft_handle;
+ if (DftiCreateDescriptor(&fft_handle, DFTI_SINGLE, (cplx ? DFTI_COMPLEX : DFTI_REAL), 1, N) == 0) {
+ assert(DftiSetValue(fft_handle, DFTI_PLACEMENT, DFTI_INPLACE) == 0);
+ assert(DftiCommitDescriptor(fft_handle) == 0);
+
+ t0 = uclock_sec();
+ for (iter = 0; iter < max_iter; ++iter) {
+ DftiComputeForward(fft_handle, &X[0]);
+ DftiComputeBackward(fft_handle, &X[0]);
+ }
+ t1 = uclock_sec();
+
+
+ DftiFreeDescriptor(&fft_handle);
+ flops = (max_iter*2) * ((cplx ? 5 : 2.5)*N*log((double)N)/M_LN2); // see http://www.fftw.org/speed/method.html
+ show_output("MKL ", N, cplx, flops, t0, t1, max_iter);
+ } else {
+ show_output(" MKL", N, cplx, -1, -1, -1, -1);
+ }
+ }
+#endif
+
+#ifdef HAVE_FFTW
+ {
+ fftwf_plan planf, planb;
+ fftw_complex *in = (fftw_complex*) fftwf_malloc(sizeof(fftw_complex) * N);
+ fftw_complex *out = (fftw_complex*) fftwf_malloc(sizeof(fftw_complex) * N);
+ memset(in, 0, sizeof(fftw_complex) * N);
+ int flags = (N < 40000 ? FFTW_MEASURE : FFTW_ESTIMATE); // measure takes a lot of time on largest ffts
+ //int flags = FFTW_ESTIMATE;
+ if (cplx) {
+ planf = fftwf_plan_dft_1d(N, (fftwf_complex*)in, (fftwf_complex*)out, FFTW_FORWARD, flags);
+ planb = fftwf_plan_dft_1d(N, (fftwf_complex*)in, (fftwf_complex*)out, FFTW_BACKWARD, flags);
+ } else {
+ planf = fftwf_plan_dft_r2c_1d(N, (float*)in, (fftwf_complex*)out, flags);
+ planb = fftwf_plan_dft_c2r_1d(N, (fftwf_complex*)in, (float*)out, flags);
+ }
+
+ t0 = uclock_sec();
+ for (iter = 0; iter < max_iter; ++iter) {
+ fftwf_execute(planf);
+ fftwf_execute(planb);
+ }
+ t1 = uclock_sec();
+
+ fftwf_destroy_plan(planf);
+ fftwf_destroy_plan(planb);
+ fftwf_free(in); fftwf_free(out);
+
+ flops = (max_iter*2) * ((cplx ? 5 : 2.5)*N*log((double)N)/M_LN2); // see http://www.fftw.org/speed/method.html
+ show_output((flags == FFTW_MEASURE ? "FFTW (meas.)" : " FFTW (estim)"), N, cplx, flops, t0, t1, max_iter);
+ }
+#endif
+
+ // PFFFT benchmark
+ {
+ PFFFT_Setup *s = pffft_new_setup(N, cplx ? PFFFT_COMPLEX : PFFFT_REAL);
+ if (s) {
+ t0 = uclock_sec();
+ for (iter = 0; iter < max_iter; ++iter) {
+ pffft_transform(s, X, Z, Y, PFFFT_FORWARD);
+ pffft_transform(s, X, Z, Y, PFFFT_BACKWARD);
+ }
+ t1 = uclock_sec();
+ pffft_destroy_setup(s);
+
+ flops = (max_iter*2) * ((cplx ? 5 : 2.5)*N*log((double)N)/M_LN2); // see http://www.fftw.org/speed/method.html
+ show_output("PFFFT", N, cplx, flops, t0, t1, max_iter);
+ }
+ }
+
+ if (!array_output_format) {
+ printf("--\n");
+ }
+
+ pffft_aligned_free(X);
+ pffft_aligned_free(Y);
+ pffft_aligned_free(Z);
+}
+
+#ifndef PFFFT_SIMD_DISABLE
+void validate_pffft_simd(); // a small function inside pffft.c that will detect compiler bugs with respect to simd instruction
+#endif
+
+int main(int argc, char **argv) {
+ int Nvalues[] = { 64, 96, 128, 160, 192, 256, 384, 5*96, 512, 5*128, 3*256, 800, 1024, 2048, 2400, 4096, 8192, 9*1024, 16384, 32768, 256*1024, 1024*1024, -1 };
+ int i;
+
+ if (argc > 1 && strcmp(argv[1], "--no-array-format") == 0) {
+ array_output_format = 0;
+ }
+
+#ifndef PFFFT_SIMD_DISABLE
+ validate_pffft_simd();
+#endif
+ pffft_validate(1);
+ pffft_validate(0);
+ if (!array_output_format) {
+ // display a nice markdown array
+ for (i=0; Nvalues[i] > 0; ++i) {
+ benchmark_ffts(Nvalues[i], 0 /* real fft */);
+ }
+ for (i=0; Nvalues[i] > 0; ++i) {
+ benchmark_ffts(Nvalues[i], 1 /* cplx fft */);
+ }
+ } else {
+ int columns = 0;
+ printf("| input len "); ++columns;
+ printf("|real FFTPack"); ++columns;
+#ifdef HAVE_VECLIB
+ printf("| real vDSP "); ++columns;
+#endif
+#ifdef HAVE_MKL
+ printf("| real MKL "); ++columns;
+#endif
+#ifdef HAVE_FFTW
+ printf("| real FFTW "); ++columns;
+#endif
+ printf("| real PFFFT "); ++columns;
+
+ printf("|cplx FFTPack"); ++columns;
+#ifdef HAVE_VECLIB
+ printf("| cplx vDSP "); ++columns;
+#endif
+#ifdef HAVE_MKL
+ printf("| cplx MKL "); ++columns;
+#endif
+#ifdef HAVE_FFTW
+ printf("| cplx FFTW "); ++columns;
+#endif
+ printf("| cplx PFFFT |\n"); ++columns;
+ for (i=0; i < columns; ++i) {
+ printf("|-----------:");
+ }
+ printf("|\n");
+
+ for (i=0; Nvalues[i] > 0; ++i) {
+ printf("|%9d ", Nvalues[i]);
+ benchmark_ffts(Nvalues[i], 0);
+ //printf("| ");
+ benchmark_ffts(Nvalues[i], 1);
+ printf("|\n");
+ }
+ printf(" (numbers are given in MFlops)\n");
+ }
+
+
+ return 0;
+}
diff --git a/src/3rdparty/resonance-audio/.gitignore b/src/3rdparty/resonance-audio/.gitignore
new file mode 100644
index 000000000..ec176f56d
--- /dev/null
+++ b/src/3rdparty/resonance-audio/.gitignore
@@ -0,0 +1,19 @@
+# Ignore third party directories by default
+third_party/android-cmake/
+third_party/eigen/
+third_party/embree/
+third_party/fmod/
+third_party/googletest/
+third_party/ios-cmake/
+third_party/nativeaudioplugins/
+third_party/ogg/
+third_party/pffft/
+third_party/vorbis/
+third_party/VST_SDK/
+third_party/WwiseIncludes/
+
+# Ignore build artifacts and install directories by default
+build/
+install/
+
+.DS_Store
diff --git a/src/3rdparty/resonance-audio/.travis.yml b/src/3rdparty/resonance-audio/.travis.yml
new file mode 100644
index 000000000..b37e5b05a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/.travis.yml
@@ -0,0 +1,17 @@
+language: cpp
+
+compiler:
+ - clang
+ - gcc
+
+dist: xenial
+
+os:
+ - linux
+ - osx
+
+install:
+ - ./third_party/clone_core_deps.sh
+
+script:
+ - ./build.sh -t=RESONANCE_AUDIO_TESTS
diff --git a/src/3rdparty/resonance-audio/AUTHORS b/src/3rdparty/resonance-audio/AUTHORS
new file mode 100644
index 000000000..a00d7c3fc
--- /dev/null
+++ b/src/3rdparty/resonance-audio/AUTHORS
@@ -0,0 +1,10 @@
+Google Inc.
+
+Contributors (in alphabetical order):
+Alper Gungormusler
+Dillon Cower
+Frank Boland
+Ian Kelly
+Julius Kammerl
+Marcin Gorzel
+Yero Yeh
diff --git a/src/3rdparty/resonance-audio/CMakeLists.txt b/src/3rdparty/resonance-audio/CMakeLists.txt
new file mode 100644
index 000000000..6af0b3fb3
--- /dev/null
+++ b/src/3rdparty/resonance-audio/CMakeLists.txt
@@ -0,0 +1,109 @@
+# Copyright 2018 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS-IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Static/dynamic runtime can be selected via -DSTATIC_MSVC_RUNTIME=ON|OFF
+macro(configure_msvc_runtime)
+ if (NOT BUILD_WWISE_AUTHORING_PLUGIN)
+ option(STATIC_MSVC_RUNTIME "Static linkage of MSVC runtime" ON)
+ SET(MSVC_RUNTIME_FLAG "/MT" CACHE STRING "MSVC Runtime flag")
+ if (STATIC_MSVC_RUNTIME)
+ SET(MSVC_RUNTIME_FLAG "/MT")
+ else ()
+ SET(MSVC_RUNTIME_FLAG "/MD")
+ endif ()
+ message(STATUS "MSVC Runtime flag: ${MSVC_RUNTIME_FLAG}")
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MSVC_RUNTIME_FLAG}" CACHE INTERNAL "" FORCE)
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${MSVC_RUNTIME_FLAG}d" CACHE INTERNAL "" FORCE)
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${MSVC_RUNTIME_FLAG}" CACHE INTERNAL "" FORCE)
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${MSVC_RUNTIME_FLAG}d" CACHE INTERNAL "" FORCE)
+ endif (NOT BUILD_WWISE_AUTHORING_PLUGIN)
+endmacro()
+
+macro(use_cxx11)
+ set(CMAKE_CXX_STANDARD 11)
+ set(CMAKE_CXX_STANDARD_REQUIRED on)
+endmacro(use_cxx11)
+
+project(ResonanceAudio)
+
+# Build options
+option(BUILD_RESONANCE_AUDIO_API "Build Resonance Audio API." OFF)
+option(BUILD_RESONANCE_AUDIO_TESTS "Build Resonance Audio Unit Tests" OFF)
+option(BUILD_UNITY_PLUGIN "Build Unity Resonance Audio Plugin" OFF)
+option(BUILD_GEOMETRICAL_ACOUSTICS_TESTS "Build Resonance Audio's Geometrical Acoustics Tests" OFF)
+option(BUILD_WWISE_AUTHORING_PLUGIN "Build Resonance Audio WWise Authoring Plugin" OFF)
+option(BUILD_WWISE_SOUND_ENGINE_PLUGIN "Build Resonance Audio WWise Sound Engine Plugin." OFF)
+option(BUILD_FMOD_PLUGIN "Build FMOD Resonance Audio Plugin" OFF)
+option(BUILD_VST_MONITOR_PLUGIN "Build Resonance Audio VST Monitor Plugin" OFF)
+
+if (MSVC)
+ configure_msvc_runtime()
+endif ()
+
+if (IOS_PLATFORM STREQUAL "OS" OR IOS_PLATFORM MATCHES "SIMULATOR")
+ message(STATUS "iOS toolchain detected")
+ set (IOS_DETECTED TRUE CACHE BOOL "IOS platform detected")
+ add_definitions(-DPLATFORM_IOS)
+elseif(ANDROID)
+ add_definitions(-DPLATFORM_ANDROID)
+endif ()
+
+cmake_minimum_required(VERSION 3.4.1)
+set(CMAKE_COLOR_MAKEFILE ON)
+
+set(INSTALL_DIR "${PROJECT_SOURCE_DIR}/install" CACHE PATH "Install path")
+
+set(RA_SOURCE_DIR ${PROJECT_SOURCE_DIR}/resonance_audio/)
+
+use_cxx11()
+if (BUILD_RESONANCE_AUDIO_TESTS OR BUILD_GEOMETRICAL_ACOUSTICS_TESTS)
+ enable_testing()
+
+ set(GTEST_DIR "${PROJECT_SOURCE_DIR}/third_party/googletest/" CACHE PATH "Path to GTest library")
+ # Compile Google Test as an object library
+ add_library(gtest OBJECT "${GTEST_DIR}/googlemock/src/gmock-all.cc"
+ "${GTEST_DIR}/googletest/src/gtest-all.cc"
+ "${GTEST_DIR}/googletest/src/gtest_main.cc")
+ target_include_directories(gtest PUBLIC "${GTEST_DIR}/googlemock/")
+ target_include_directories(gtest PUBLIC "${GTEST_DIR}/googlemock/include")
+ target_include_directories(gtest PUBLIC "${GTEST_DIR}/googletest/")
+ target_include_directories(gtest PUBLIC "${GTEST_DIR}/googletest/include")
+endif (BUILD_RESONANCE_AUDIO_TESTS OR BUILD_GEOMETRICAL_ACOUSTICS_TESTS)
+
+if (WIN32)
+ add_definitions(-D_USE_MATH_DEFINES)
+ add_definitions(-DNOMINMAX)
+ # Disable type conversion warnings.
+ add_definitions(/wd4244)
+ add_definitions(/wd4305)
+ add_definitions(/wd4722)
+elseif (APPLE)
+elseif (ANDROID)
+ set(NEON ON)
+elseif (UNIX)
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+ set(CMAKE_CXX_FLAGS "-fPIC -O3 -Wno-vla -msse -msse2 -msse3 -mfpmath=sse")
+endif ()
+
+# Add Eigen3.
+set(EIGEN3_DIR "${PROJECT_SOURCE_DIR}/third_party/eigen/" CACHE PATH "Path to eigen3 library")
+set(EIGEN3_INCLUDE_DIR ${EIGEN3_DIR})
+add_definitions(-DEIGEN_MPL2_ONLY)
+
+include_directories(${PROJECT_SOURCE_DIR})
+include_directories(${EIGEN3_INCLUDE_DIR})
+
+add_subdirectory(resonance_audio)
+add_subdirectory(platforms)
diff --git a/src/3rdparty/resonance-audio/CODEOWNERS b/src/3rdparty/resonance-audio/CODEOWNERS
new file mode 100644
index 000000000..6f999fe96
--- /dev/null
+++ b/src/3rdparty/resonance-audio/CODEOWNERS
@@ -0,0 +1,6 @@
+# Default owners for everything in the repo.
+* @anokta @haroonq
+
+# Wwise plugin.
+platforms/wwise/* @ralphyon
+
diff --git a/src/3rdparty/resonance-audio/CONTRIBUTING.md b/src/3rdparty/resonance-audio/CONTRIBUTING.md
new file mode 100644
index 000000000..9678067f7
--- /dev/null
+++ b/src/3rdparty/resonance-audio/CONTRIBUTING.md
@@ -0,0 +1,14 @@
+# Contributing guidelines
+
+We'd love to accept your patches! Before we can take them, we have to jump a couple of legal hurdles.
+
+## Contributor License Agreements
+
+Please fill out either the individual or corporate Contributor License Agreement (CLA).
+
+ * If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA](https://code.google.com/legal/individual-cla-v1.0.html).
+ * If you work for a company that wants to allow you to contribute your work, then you'll need to sign a [corporate CLA](https://code.google.com/legal/corporate-cla-v1.0.html).
+
+Follow either of the two links above to access the appropriate CLA and instructions for how to sign and return it. Once we receive it, we'll be able to accept your pull requests.
+
+***NOTE***: Only original source code from you and other people that have signed the CLA can be accepted into the main repository.
diff --git a/src/3rdparty/resonance-audio/COPYRIGHTS b/src/3rdparty/resonance-audio/COPYRIGHTS
new file mode 100644
index 000000000..ad864e69a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/COPYRIGHTS
@@ -0,0 +1 @@
+Copyright (c) 2015, 2017, 2018 Google Inc.
diff --git a/src/3rdparty/resonance-audio/LICENSE b/src/3rdparty/resonance-audio/LICENSE
new file mode 100644
index 000000000..d64569567
--- /dev/null
+++ b/src/3rdparty/resonance-audio/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/src/3rdparty/resonance-audio/README.md b/src/3rdparty/resonance-audio/README.md
new file mode 100644
index 000000000..1e69c48b4
--- /dev/null
+++ b/src/3rdparty/resonance-audio/README.md
@@ -0,0 +1,192 @@
+# [Resonance Audio](https://developers.google.com/resonance-audio) Source Code [![Travis CI](https://travis-ci.org/resonance-audio/resonance-audio.svg?branch=master)](https://travis-ci.org/resonance-audio/resonance-audio)
+
+This is the official open source project for the Resonance Audio SDK. This
+repository consists of the full source code of the Resonance Audio C++ library,
+as well as the platform integrations into [Unity](https://unity3d.com/),
+[FMOD](https://www.fmod.com/),
+[Wwise](https://www.audiokinetic.com/products/wwise/) and DAW tools.
+
+Resonance Audio started as a Google product and has since graduated to open
+source. It is supported by members of our [steering
+committee](#steering-committee) who are also project committers.
+
+In this document there are some quick instructions for how to build the SDK from
+source code.
+
+For more detailed documentation about using the SDK, visit our [developer
+docs](https://developers.google.com/resonance-audio/). If you are interested in
+contributing to the project, please read the [Contributing to Resonance
+Audio](#contributing-to-resonance-audio) section below.
+
+## Build Instructions
+
+Clone the repository:
+
+ git clone https://github.com/resonance-audio/resonance-audio $YOUR_LOCAL_REPO
+
+### Software Requirements
+
+In addition to the system C++ software development platform tools / toolchains,
+the following software is required to build and install the Resonance Audio
+SDKs:
+
+- [CMake](https://cmake.org/download/)
+- [Git (with Git-Bash on Windows)](https://git-scm.com/downloads)
+
+_Note: For Windows builds, [Visual Studio
+2015](https://www.visualstudio.com/vs/older-downloads/) is recommended._
+
+### Third Party Dependencies
+
+All third party dependencies must be installed into the `third_party` subfolder
+in the repository. To simplify the installation, bash scripts are located within
+the `third_party` that automatically clone, build and install the required third
+party source code.
+
+_Note: On Windows, these scripts can be executed in the Git-Bash console (which
+gets installed as part of Git for Windows)._
+
+#### Core Dependencies ([pffft](https://bitbucket.org/jpommier/pffft), [eigen](https://bitbucket.org/eigen/eigen), [googletest](https://github.com/google/googletest), [SADIE Binaural Measurements](https://www.york.ac.uk/sadie-project/database_old.html))
+
+To clone the dependencies into the repository, run:
+
+ ./$YOUR_LOCAL_REPO/third_party/clone_core_deps.sh
+
+_Note: These dependencies do *not* need to be built, since their source code is
+directly pulled in from the build scripts._
+
+#### [Unity](https://unity3d.com/) Platform Dependencies ([nativeaudioplugins](https://github.com/Unity-Technologies/NativeAudioPlugins), [embree](https://github.com/embree/embree), [ogg](https://github.com/xiph/ogg), [vorbis](https://github.com/xiph/vorbis))
+
+The Unity plugin integrates additional tools to estimate reverberation from game
+geometry and to capture Ambisonic soundfields from a game scene. These features
+require the Embree, libOgg and libVorbis libraries to be *prebuilt*.
+
+To clone and build the additional Unity dependencies, run:
+
+ ./$YOUR_LOCAL_REPO/third_party/clone_build_install_unity_deps.sh
+
+#### [FMOD](https://www.fmod.com/) Platform Dependencies ([FMOD Low Level API](https://www.fmod.com/download#fmodstudio))
+
+To add the additional FMOD dependencies, download and install the [FMOD Studio
+API](https://www.fmod.com/download#fmodstudio) (which includes the FMOD Low
+Level API).
+
+_Note: On Linux, unzip the downloaded package within the `third_party` subfolder
+and rename its folder to `fmod`._
+
+#### [Wwise](https://www.audiokinetic.com/products/wwise/) Platform Dependencies ([WwiseIncludes](https://github.com/audiokinetic/WwiseIncludes))
+
+To clone the additional Wwise dependencies, run:
+
+ ./$YOUR_LOCAL_REPO/third_party/clone_wwise_deps.sh
+
+The Wwise Authoring Plugin (Windows only) also requires the [Microsoft
+Foundation Classes SDK](https://docs.microsoft.com/en-gb/cpp/mfc/mfc-and-atl).
+To install the SDK on Windows:
+
+1. Open the `Control Panel`
+2. Select `Programs->Programs and Features`
+3. Right-click on `Microsoft Visual C++ Build Tools`, and select `Change`
+4. Install `MFC SDK`
+
+#### DAW Tools Dependencies ([VST2 Audio Plug-Ins SDK](https://www.steinberg.net/vst3sdk))
+
+To add the additional DAW Tools dependencies, download the [Steinberg's VST
+3.X.X Audio Plug-Ins SDK](https://www.steinberg.net/vst3sdk) (which
+includes the VST2 Audio Plug-Ins SDK) and extract the package into `third_party`
+subfolder.
+
+### Build Resonance Audio SDKs
+
+This repository provides the `build.sh` script in the root folder that
+configures the build targets, triggers the compilation and installs the
+artifacts for the specified platform into the target installation folder.
+
+The script provides the following flags:
+
+- t=|--target=
+ - `RESONANCE_AUDIO_API`: Builds the Resonance Audio API
+ - `RESONANCE_AUDIO_TESTS`: Runs the Resonance Audio unit tests
+ - `GEOMETRICAL_ACOUSTICS_TESTS`: Runs the geometrical acoustics specific
+ unit tests.
+ - `UNITY_PLUGIN`: Builds the Resonance Audio plugin for Unity
+ - `WWISE_AUTHORING_PLUGIN`: Builds the Resonance Audio authoring plugin
+ for Wwise
+ - `WWISE_SOUND_ENGINE_PLUGIN`: Builds the Resonance Audio sound engine
+ plugin for Wwise
+ - `FMOD_PLUGIN`: Builds the Resonance Audio plugin for FMOD
+ - `VST_MONITOR_PLUGIN`: Builds the Resonance Audio VST Monitor Plugin
+- p=|--profile=
+ - `Debug`: Debug build
+ - `RelWithDebInfo`: Release build with debug information
+ - `Release`: Release build
+- --msvc_dynamic_runtime
+ - Enables dynamic linking against the run-time library on Windows (`/MD`,
+ `/MDd`). By default, all Windows builds are statically linked against
+ the run-time library (`/MT`, `/MTd`). Note that the third party
+ dependencies must be compiled with the same options to avoid library
+ conflicts.
+- --verbose_make
+ - Enables verbose make/build output.
+- --android_toolchain
+ - Enables the Android NDK toolchain to target Android builds (may require
+ adjustments to `ANDROID_NDK`, `ANDROID_NATIVE_API_LEVEL` and
+ `ANDROID_ABI` script variables). For more information, see project
+ documentation at https://github.com/taka-no-me/android-cmake.
+- --ios_os_toolchain
+ - Enables the iOS OS toolchain. For more information, see project
+ documentation at https://github.com/leetal/ios-cmake.
+- --ios_simulator_toolchain
+ - Enables the iOS Simulator toolchain. For more information, see project
+ documentation at https://github.com/leetal/ios-cmake
+
+##### E.g.
+
+To build and run the Resonance Audio unit tests:
+
+ ./$YOUR_LOCAL_REPO/build.sh -t=RESONANCE_AUDIO_TESTS
+
+## Citations
+
+If you find Resonance Audio useful and would like to cite it in your publication, please use:
+
+Gorzel, M., Allen, A., Kelly, I., Kammerl, J., Gungormusler, A., Yeh, H., and Boland, F., *"Efficient Encoding and Decoding of Binaural Sound with Resonance Audio"*, In proc. of the AES International Conference on Immersive and Interactive Audio, March 2019
+
+The full paper is available (open access) at: http://www.aes.org/e-lib/browse.cfm?elib=20446 ([BibTeX](http://www.aes.org/e-lib/browse.cfm?elib=20446&fmt=bibtex))
+
+## Contributing to Resonance Audio
+
+If you would like to contribute changes to the Resonance Audio project, please
+make a pull request for one of our project committers to review.
+
+### Steering Committee
+
+The Resonance Audio project is overseen by a steering committee established to
+help guide the technical direction of the project in collaboration with the
+entire developer community.
+
+The intention of the steering committee is to cultivate collaboration across the
+developer community for improving the project and ensuring Resonance Audio
+continues to work well for everyone.
+
+The committee will lead the Resonance Audio project in major decisions by
+consensus and ensure that Resonance Audio can meet its goals as a truly open
+source project.
+
+The steering committee consists of the following members (company name ordered):
+
+- Martin Dufour, Audiokinetic
+- Aaron McLeran, Epic Games
+- Mathew Block, Firelight Technologies
+- Alper Gungormusler, Google
+- Eric Mauskopf, Google
+- Haroon Qureshi, Google
+- Ian Kelly, Google
+- Julius Kammerl, Google
+- Marcin Gorzel, Google
+- Damien Kelly, Google (YouTube)
+- Jean-Marc Jot, Magic Leap
+- Michael Berg, Unity Technologies
+
+Affiliations are listed for identification purposes only; steering committee
+members do not represent their employers or academic institutions.
diff --git a/src/3rdparty/resonance-audio/build.sh b/src/3rdparty/resonance-audio/build.sh
new file mode 100755
index 000000000..3b0d3aa3a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/build.sh
@@ -0,0 +1,151 @@
+#!/bin/bash
+# Copyright 2018 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS-IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Change working directory to script folder
+SCRIPT_DIR="$( cd "$(dirname "$0")" ; pwd -P )"
+cd "${SCRIPT_DIR}"
+
+
+PROFILE="Release"
+VERBOSE_MAKE=""
+
+declare -a BUILD_FLAGS
+declare -a CONFIG_FLAGS
+
+ANDROID_NDK="~/android-ndk-r15c/"
+ANDROID_NATIVE_API_LEVEL="21"
+ANDROID_ABI="armeabi-v7a with NEON"
+
+MSVC_GENERATOR="Visual Studio 14 2015 Win64"
+
+function show_help()
+{
+ cat <<EOF
+*** Resonance Audio compilation script ***
+
+Please select a build target:
+
+ -t= | --target=[RESONANCE_AUDIO_API| # Resonance Audio API C/C++ library
+ RESONANCE_AUDIO_TESTS| # Resonance Audio unit tests
+ GEOMETRICAL_ACOUSTICS_TESTS| # Geometrical Acoustics unit tests
+ UNITY_PLUGIN| # Resonance Audio Unity plugin
+ WWISE_AUTHORING_PLUGIN| # Resonance Audio Wwise authoring plugin
+ WWISE_SOUND_ENGINE_PLUGIN| # Resonance Audio Wwise sound engine plugin
+ FMOD_PLUGIN| # Resonance Audio FMOD plugin
+ VST_MONITOR_PLUGIN] # Resonance Audio VST monitor plugin
+
+ -p= | --profile=[Debug|Release], default: Release
+
+ --verbose_make # Enables verbose make/build output.
+ --android_toolchain # Use Android NDK toolchain (may need adjustments to ANDROID_NDK,
+ # ANDROID_NATIVE_API_LEVEL, ANDROID_ABI script variables).
+ --ios_os_toolchain # Use iOS ARM toolchain.
+ --ios_simulator_toolchain # Use iOS X86 simulator toolchain.
+ --msvc_dynamic_runtime # Enables dynamic runtime environment linking in MSVC builds.
+EOF
+exit
+}
+
+BUILD_TARGET=""
+
+for i in "$@"
+do
+ case $i in
+ -p=*|--profile=*)
+ PROFILE="${i#*=}"
+ shift # past argument=value
+ ;;
+
+ -t=*|--target=*)
+ BUILD_TARGET="${i#*=}"
+ shift # past argument=value
+ ;;
+
+ --verbose_make)
+ CONFIG_FLAGS+=(-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON)
+ shift # past argument with no value
+ ;;
+
+ --android_toolchain)
+ CONFIG_FLAGS+=(-DCMAKE_TOOLCHAIN_FILE=./third_party/android-cmake/android.toolchain.cmake)
+ CONFIG_FLAGS+=(-DANDROID_NDK="${ANDROID_NDK}")
+ CONFIG_FLAGS+=(-DANDROID_NATIVE_API_LEVEL="${ANDROID_NATIVE_API_LEVEL}")
+ CONFIG_FLAGS+=(-DANDROID_ABI="${ANDROID_ABI}")
+ shift # past argument with no value
+ ;;
+
+ --ios_os_toolchain)
+ CONFIG_FLAGS+=(-DCMAKE_TOOLCHAIN_FILE=./third_party/ios-cmake/ios.toolchain.cmake)
+ CONFIG_FLAGS+=(-DIOS_PLATFORM=OS)
+ shift # past argument with no value
+ ;;
+
+ --ios_simulator_toolchain)
+ CONFIG_FLAGS+=(-DCMAKE_TOOLCHAIN_FILE=./third_party/ios-cmake/ios.toolchain.cmake)
+ CONFIG_FLAGS+=(-DIOS_PLATFORM=SIMULATOR64)
+ shift # past argument with no value
+ ;;
+
+ --msvc_dynamic_runtime)
+ CONFIG_FLAGS+=(-DSTATIC_MSVC_RUNTIME:BOOL=OFF)
+ shift # past argument with no value
+ ;;
+
+ *)
+ # unknown option
+ echo "Unknown option: ${i}"
+ show_help
+ ;;
+ esac
+done
+
+[[ -z "$BUILD_TARGET" ]] && show_help
+
+# Number of CPU cores/parallel compilation instances (for Darwin/Linux builds)
+NUM_CORES=8
+
+# Create build environment.
+rm -fr build && mkdir build && cd build
+
+case "$(uname -s)" in
+ Darwin)
+ BUILD_FLAGS+=(-j "${NUM_CORES}")
+ cmake -DBUILD_"${BUILD_TARGET}":BOOL=ON\
+ "${CONFIG_FLAGS[@]}" "$@" ..
+ ;;
+
+ Linux)
+ BUILD_FLAGS+=(-j "${NUM_CORES}")
+ cmake -DBUILD_"${BUILD_TARGET}":BOOL=ON\
+ "${CONFIG_FLAGS[@]}" "$@" ..
+ ;;
+
+ CYGWIN*|MINGW*|MSYS*)
+ cmake -G"${MSVC_GENERATOR}"\
+ -DBUILD_"${BUILD_TARGET}":BOOL=ON\
+ "${CONFIG_FLAGS[@]}" "$@" ..
+ ;;
+
+ *)
+ ;;
+esac
+
+INSTALL_TARGET="install"
+if echo "${BUILD_TARGET}" | grep -q "TESTS"; then
+ INSTALL_TARGET=""
+fi
+
+cmake --build . --config "${PROFILE}" --target "${INSTALL_TARGET}" -- "${BUILD_FLAGS[@]}"
diff --git a/src/3rdparty/resonance-audio/patches/0001-resonance_audio-fix-C-20-build.patch b/src/3rdparty/resonance-audio/patches/0001-resonance_audio-fix-C-20-build.patch
new file mode 100644
index 000000000..2de42ad26
--- /dev/null
+++ b/src/3rdparty/resonance-audio/patches/0001-resonance_audio-fix-C-20-build.patch
@@ -0,0 +1,36 @@
+From f8c9ec7cfabb59977629f303edf7cf90ca8521d3 Mon Sep 17 00:00:00 2001
+From: Marc Mutz <marc.mutz@qt.io>
+Date: Tue, 28 Jun 2022 19:38:13 +0200
+Subject: [PATCH] AlignedAllocator: fix C++20 build
+
+C++17 deprecated, and C++20 removed, the nested pointer, size_type
+etc. typedefs in std::allocator. Since C++11, the way to get these
+types is to go via allocator_traits, so do that.
+
+This breaks compatibility with C++ < 11.
+
+Fixes #61
+---
+ .../resonance_audio/base/aligned_allocator.h | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/resonance_audio/base/aligned_allocator.h b/resonance_audio/base/aligned_allocator.h
+index ac60e8292..628ccaa02 100644
+--- a/resonance_audio/base/aligned_allocator.h
++++ b/resonance_audio/base/aligned_allocator.h
+@@ -72,9 +72,9 @@ void AllignedFree(PointerType mem_block_aligned) {
+ template <typename Type, size_t Alignment>
+ class AlignedAllocator : public std::allocator<Type> {
+ public:
+- typedef typename std::allocator<Type>::pointer Pointer;
+- typedef typename std::allocator<Type>::const_pointer ConstPointer;
+- typedef typename std::allocator<Type>::size_type SizeType;
++ using Pointer = typename std::allocator_traits<std::allocator<Type>>::pointer;
++ using ConstPointer = typename std::allocator_traits<std::allocator<Type>>::const_pointer;
++ using SizeType = typename std::allocator_traits<std::allocator<Type>>::size_type;
+
+ AlignedAllocator() { StaticAlignmentCheck<sizeof(Type), Alignment>(); }
+
+--
+2.25.1
+
diff --git a/src/3rdparty/resonance-audio/platforms/CMakeLists.txt b/src/3rdparty/resonance-audio/platforms/CMakeLists.txt
new file mode 100644
index 000000000..3dcdc2dfc
--- /dev/null
+++ b/src/3rdparty/resonance-audio/platforms/CMakeLists.txt
@@ -0,0 +1,30 @@
+# Copyright 2018 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS-IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+if (BUILD_VST_MONITOR_PLUGIN)
+ add_subdirectory(vst)
+endif (BUILD_VST_MONITOR_PLUGIN)
+
+if (BUILD_FMOD_PLUGIN)
+ add_subdirectory(fmod)
+endif (BUILD_FMOD_PLUGIN)
+
+if (BUILD_WWISE_AUTHORING_PLUGIN OR BUILD_WWISE_SOUND_ENGINE_PLUGIN)
+ add_subdirectory(wwise)
+endif (BUILD_WWISE_AUTHORING_PLUGIN OR BUILD_WWISE_SOUND_ENGINE_PLUGIN)
+
+if (BUILD_UNITY_PLUGIN OR BUILD_GEOMETRICAL_ACOUSTICS_TESTS)
+ add_subdirectory(unity)
+endif (BUILD_UNITY_PLUGIN OR BUILD_GEOMETRICAL_ACOUSTICS_TESTS)
diff --git a/src/3rdparty/resonance-audio/platforms/common/room_effects_utils.cc b/src/3rdparty/resonance-audio/platforms/common/room_effects_utils.cc
new file mode 100644
index 000000000..3c74f26dc
--- /dev/null
+++ b/src/3rdparty/resonance-audio/platforms/common/room_effects_utils.cc
@@ -0,0 +1,327 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "platforms/common/room_effects_utils.h"
+
+#include <algorithm>
+#include <cmath>
+#include <numeric>
+
+namespace vraudio {
+
+namespace {
+
+// Air absorption coefficients at 20 degrees Celsius and 50% relative humidity,
+// according to:
+// http://www.music.mcgill.ca/~gary/courses/papers/Moorer-Reverb-CMJ-1979.pdf
+// These coefficients have been extrapolated to other frequencies by fitting
+// an exponential curve:
+//
+// m = a + be^(-cx) where:
+//
+// a = -0.00259118
+// b = 0.003173474
+// c = -0.0002491554
+//
+const float kAirAbsorptionCoefficients[]{0.0006f, 0.0006f, 0.0007f,
+ 0.0008f, 0.0010f, 0.0015f,
+ 0.0026f, 0.0060f, 0.0207f};
+
+// Room materials with the corresponding absorption coefficients.
+const RoomMaterial kRoomMaterials[static_cast<size_t>(
+ MaterialName::kNumMaterialNames)] = {
+ {MaterialName::kTransparent,
+ // 31.25 62.5 125 250 500 1000 2000 4000 8000 Hz.
+ {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}},
+ {MaterialName::kAcousticCeilingTiles,
+ {0.672f, 0.675f, 0.700f, 0.660f, 0.720f, 0.920f, 0.880f, 0.750f, 1.000f}},
+ {MaterialName::kBrickBare,
+ {0.030f, 0.030f, 0.030f, 0.030f, 0.030f, 0.040f, 0.050f, 0.070f, 0.140f}},
+
+ {MaterialName::kBrickPainted,
+ {0.006f, 0.007f, 0.010f, 0.010f, 0.020f, 0.020f, 0.020f, 0.030f, 0.060f}},
+
+ {MaterialName::kConcreteBlockCoarse,
+ {0.360f, 0.360f, 0.360f, 0.440f, 0.310f, 0.290f, 0.390f, 0.250f, 0.500f}},
+
+ {MaterialName::kConcreteBlockPainted,
+ {0.092f, 0.090f, 0.100f, 0.050f, 0.060f, 0.070f, 0.090f, 0.080f, 0.160f}},
+
+ {MaterialName::kCurtainHeavy,
+ {0.073f, 0.106f, 0.140f, 0.350f, 0.550f, 0.720f, 0.700f, 0.650f, 1.000f}},
+
+ {MaterialName::kFiberGlassInsulation,
+ {0.193f, 0.220f, 0.220f, 0.820f, 0.990f, 0.990f, 0.990f, 0.990f, 1.000f}},
+
+ {MaterialName::kGlassThin,
+ {0.180f, 0.169f, 0.180f, 0.060f, 0.040f, 0.030f, 0.020f, 0.020f, 0.040f}},
+
+ {MaterialName::kGlassThick,
+ {0.350f, 0.350f, 0.350f, 0.250f, 0.180f, 0.120f, 0.070f, 0.040f, 0.080f}},
+
+ {MaterialName::kGrass,
+ {0.05f, 0.05f, 0.15f, 0.25f, 0.40f, 0.55f, 0.60f, 0.60f, 0.60f}},
+
+ {MaterialName::kLinoleumOnConcrete,
+ {0.020f, 0.020f, 0.020f, 0.030f, 0.030f, 0.030f, 0.030f, 0.020f, 0.040f}},
+
+ {MaterialName::kMarble,
+ {0.010f, 0.010f, 0.010f, 0.010f, 0.010f, 0.010f, 0.020f, 0.020f, 0.040f}},
+
+ {MaterialName::kMetal,
+ {0.030f, 0.035f, 0.04f, 0.04f, 0.05f, 0.05f, 0.05f, 0.07f, 0.09f}},
+
+ {MaterialName::kParquetOnConcrete,
+ {0.028f, 0.030f, 0.040f, 0.040f, 0.070f, 0.060f, 0.060f, 0.070f, 0.140f}},
+
+ {MaterialName::kPlasterRough,
+ {0.017f, 0.018f, 0.020f, 0.030f, 0.040f, 0.050f, 0.040f, 0.030f, 0.060f}},
+
+ {MaterialName::kPlasterSmooth,
+ {0.011f, 0.012f, 0.013f, 0.015f, 0.020f, 0.030f, 0.040f, 0.050f, 0.100f}},
+
+ {MaterialName::kPlywoodPanel,
+ {0.40f, 0.34f, 0.28f, 0.22f, 0.17f, 0.09f, 0.10f, 0.11f, 0.22f}},
+
+ {MaterialName::kPolishedConcreteOrTile,
+ {0.008f, 0.008f, 0.010f, 0.010f, 0.015f, 0.020f, 0.020f, 0.020f, 0.040f}},
+
+ {MaterialName::kSheetrock,
+ {0.290f, 0.279f, 0.290f, 0.100f, 0.050f, 0.040f, 0.070f, 0.090f, 0.180f}},
+
+ {MaterialName::kWaterOrIceSurface,
+ {0.006f, 0.006f, 0.008f, 0.008f, 0.013f, 0.015f, 0.020f, 0.025f, 0.050f}},
+
+ {MaterialName::kWoodCeiling,
+ {0.150f, 0.147f, 0.150f, 0.110f, 0.100f, 0.070f, 0.060f, 0.070f, 0.140f}},
+
+ {MaterialName::kWoodPanel,
+ {0.280f, 0.280f, 0.280f, 0.220f, 0.170f, 0.090f, 0.100f, 0.110f, 0.220f}},
+
+ {MaterialName::kUniform,
+ {0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f}}};
+
+// Frequency threshold for low pass filtering. This is the -3dB frequency.
+const float kCutoffFrequency = 800.0f;
+
+// Number of averaging bands for computing the average absorption coefficient.
+const int kNumAveragingBands = 3;
+
+// Average absorption coefficients are computed based on 3 octave bands (500Hz,
+// 1kHz, 2kHz) from the user specified materials. The 500Hz band has index 4.
+const int kStartingBand = 4;
+
+// Default scaling factor of the reverberation tail. This value is
+// multiplied by the user-defined factor in order to allow for the change of
+// gain in the reverb tail from the UI. Updates to the gain value are made to
+// match the previous reverb implementation's loudness.
+const float kDefaultReverbGain = 0.045f;
+
+// Constant used in Eyring's equation to compute RT60.
+const float kEyringConstant = 0.161f;
+
+// Computes RT60 time in the given frequency band according to Eyring.
+inline float ComputeRt60Eyring(float total_area, float mean_absorption,
+ size_t band, float volume) {
+ return kEyringConstant * volume /
+ (-total_area * std::log(1.0f - mean_absorption) +
+ 4.0f * kAirAbsorptionCoefficients[band] * volume);
+}
+
+inline std::vector<float> ComputeShoeBoxSurfaceAreas(
+ const RoomProperties& room_properties) {
+ const float room_width = room_properties.dimensions[0];
+ const float room_height = room_properties.dimensions[1];
+ const float room_depth = room_properties.dimensions[2];
+ const float left_right_area = room_height * room_depth;
+ const float top_bottom_area = room_width * room_depth;
+ const float front_back_area = room_width * room_height;
+ return std::vector<float>{left_right_area, left_right_area, top_bottom_area,
+ top_bottom_area, front_back_area, front_back_area};
+}
+
+// Generates average reflection coefficients for each room model surface.
+//
+// @param room_properties Struct containing properties of the shoe-box room
+// model.
+// @param coefficients Reflection coefficients for each surface.
+void GenerateReflectionCoefficients(const RoomProperties& room_properties,
+ float* coefficients) {
+ DCHECK(coefficients);
+ // Loop through all the surfaces and compute the average absorption
+ // coefficient for 3 bands (500Hz, 1kHz and 2kHz).
+ for (size_t surface = 0; surface < kNumRoomSurfaces; ++surface) {
+ const size_t material_index =
+ static_cast<size_t>(room_properties.material_names[surface]);
+ // Absorption coefficients in all bands for the current surface.
+ const auto& absorption_coefficients =
+ kRoomMaterials[material_index].absorption_coefficients;
+ // Compute average absorption coefficients for each surface.
+ float average_absorption_coefficient =
+ std::accumulate(std::begin(absorption_coefficients) + kStartingBand,
+ std::begin(absorption_coefficients) + kStartingBand +
+ kNumAveragingBands,
+ 0.0f) /
+ static_cast<float>(kNumAveragingBands);
+ // Compute a reflection coefficient for each surface.
+ coefficients[surface] =
+ std::min(1.0f, std::sqrt(1.0f - average_absorption_coefficient));
+ }
+}
+
+// Uses the Eyring's equation to estimate RT60 values (reverb time in seconds)
+// in |kNumReverbOctaveBands| octave bands, including the correction for air
+// absorption. The equation is applied as defined in:
+// https://arauacustica.com/files/publicaciones_relacionados/pdf_esp_26.pdf
+//
+
+void GenerateRt60Values(const RoomProperties& room_properties,
+ float* rt60_values) {
+ DCHECK(rt60_values);
+ // Compute the shoe-box room volume.
+ const float room_volume = room_properties.dimensions[0] *
+ room_properties.dimensions[1] *
+ room_properties.dimensions[2];
+ if (room_volume < std::numeric_limits<float>::epsilon()) {
+ // RT60 values will be all zeros, if the room volume is zero.
+ return;
+ }
+
+ // Compute surface areas of the shoe-box room.
+ const std::vector<float> all_surface_areas =
+ ComputeShoeBoxSurfaceAreas(room_properties);
+ const float total_area =
+ std::accumulate(all_surface_areas.begin(), all_surface_areas.end(), 0.0f);
+ DCHECK_GT(total_area, 0.0f);
+ // Loop through each band and compute the RT60 values.
+ for (size_t band = 0; band < kNumReverbOctaveBands; ++band) {
+ // Initialize the effective absorbing area.
+ float absorbing_area = 0.0f;
+ for (size_t surface = 0; surface < kNumRoomSurfaces; ++surface) {
+ const size_t material_index =
+ static_cast<size_t>(room_properties.material_names[surface]);
+ // Compute the effective absorbing area based on the absorption
+ // coefficients for the current band and all the surfaces.
+ absorbing_area +=
+ kRoomMaterials[material_index].absorption_coefficients[band] *
+ all_surface_areas[surface];
+ }
+ DCHECK_GT(absorbing_area, 0.0f);
+ const float mean_absorption = std::min(absorbing_area / total_area, 1.0f);
+
+ // Compute RT60 time in this band according to Eyring.
+ rt60_values[band] =
+ ComputeRt60Eyring(total_area, mean_absorption, band, room_volume);
+ }
+}
+
+// Modifies the RT60 values by the given |brightness_modifier| and
+// |time_scaler|.
+void ModifyRT60Values(float brightness_modifier, float time_scaler,
+ float* rt60_values) {
+ DCHECK(rt60_values);
+ for (size_t band = 0; band < kNumReverbOctaveBands; ++band) {
+ // Linearly scale calculated reverb times according to the user specified
+ // |brightness_modifier| and |time_scaler| values.
+ rt60_values[band] *=
+ (1.0f + brightness_modifier * static_cast<float>(band + 1) /
+ static_cast<float>(kNumReverbOctaveBands)) *
+ time_scaler;
+ }
+}
+
+} // namespace
+
+ReflectionProperties ComputeReflectionProperties(
+ const RoomProperties& room_properties) {
+ ReflectionProperties reflection_properties;
+ std::copy(std::begin(room_properties.position),
+ std::end(room_properties.position),
+ std::begin(reflection_properties.room_position));
+ std::copy(std::begin(room_properties.rotation),
+ std::end(room_properties.rotation),
+ std::begin(reflection_properties.room_rotation));
+ std::copy(std::begin(room_properties.dimensions),
+ std::end(room_properties.dimensions),
+ std::begin(reflection_properties.room_dimensions));
+ reflection_properties.cutoff_frequency = kCutoffFrequency;
+ GenerateReflectionCoefficients(room_properties,
+ reflection_properties.coefficients);
+ reflection_properties.gain = room_properties.reflection_scalar;
+ return reflection_properties;
+}
+
+ReverbProperties ComputeReverbProperties(
+ const RoomProperties& room_properties) {
+ ReverbProperties reverb_properties;
+ GenerateRt60Values(room_properties, reverb_properties.rt60_values);
+ ModifyRT60Values(room_properties.reverb_brightness,
+ room_properties.reverb_time, reverb_properties.rt60_values);
+ reverb_properties.gain = kDefaultReverbGain * room_properties.reverb_gain;
+ return reverb_properties;
+}
+
+ReverbProperties ComputeReverbPropertiesFromRT60s(const float* rt60_values,
+ float brightness_modifier,
+ float time_scalar,
+ float gain_multiplier) {
+ DCHECK(rt60_values);
+
+ ReverbProperties reverb_properties;
+ std::copy_n(rt60_values, kNumReverbOctaveBands,
+ reverb_properties.rt60_values);
+ ModifyRT60Values(brightness_modifier, time_scalar,
+ reverb_properties.rt60_values);
+ reverb_properties.gain = kDefaultReverbGain * gain_multiplier;
+ return reverb_properties;
+}
+
+float ComputeRoomEffectsGain(const WorldPosition& source_position,
+ const WorldPosition& room_position,
+ const WorldRotation& room_rotation,
+ const WorldPosition& room_dimensions) {
+ const float room_volume =
+ room_dimensions[0] * room_dimensions[1] * room_dimensions[2];
+ if (room_volume < std::numeric_limits<float>::epsilon()) {
+ // No room effects should be present when the room volume is zero.
+ return 0.0f;
+ }
+
+ // Compute the relative source position with respect to the room.
+ WorldPosition relative_source_position;
+ GetRelativeDirection(room_position, room_rotation, source_position,
+ &relative_source_position);
+ WorldPosition closest_position_in_room;
+ GetClosestPositionInAabb(relative_source_position, room_dimensions,
+ &closest_position_in_room);
+ // Shift the attenuation curve by 1.0f to avoid zero division.
+ const float distance_to_room =
+ 1.0f + (relative_source_position - closest_position_in_room).norm();
+ return 1.0f / (distance_to_room * distance_to_room);
+}
+
+RoomMaterial GetRoomMaterial(size_t material_index) {
+ DCHECK_LT(material_index,
+ static_cast<size_t>(MaterialName::kNumMaterialNames));
+ return kRoomMaterials[material_index];
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/platforms/common/room_effects_utils.h b/src/3rdparty/resonance-audio/platforms/common/room_effects_utils.h
new file mode 100644
index 000000000..edaf7849d
--- /dev/null
+++ b/src/3rdparty/resonance-audio/platforms/common/room_effects_utils.h
@@ -0,0 +1,83 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_PLATFORM_COMMON_ROOM_EFFECTS_UTILS_H_
+#define RESONANCE_AUDIO_PLATFORM_COMMON_ROOM_EFFECTS_UTILS_H_
+
+#include <vector>
+
+#include "api/resonance_audio_api.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+#include "platforms/common/room_properties.h"
+
+namespace vraudio {
+
+// Room material properties.
+struct RoomMaterial {
+ // Material surface integer identifier.
+ MaterialName name;
+
+ // An array of absorption coefficients defined in octave bands.
+ float absorption_coefficients[kNumReverbOctaveBands];
+};
+
+// Generates |ReflectionProperties| based on given |room_properties|.
+//
+// @param room_properties Room properties.
+ReflectionProperties ComputeReflectionProperties(
+ const RoomProperties& room_properties);
+
+// Generates |ReverbProperties| based on given |room_properties|.
+//
+// @param room_properties Room properties.
+ReverbProperties ComputeReverbProperties(const RoomProperties& room_properties);
+
+// Generates |ReverbProperties| by directly setting the RT60 values, subject
+// to modifications by |brightness_modifier| and |time_scaler|.
+//
+// @param rt60_values RT60 values.
+// @param brightness_modifier Modifier adjusting the brightness of reverb.
+// @param time_scalar Modifier scaling the reverb time.
+// @param gain_multiplier Modifier scaling the reverb gain.
+ReverbProperties ComputeReverbPropertiesFromRT60s(const float* rt60_values,
+ float brightness_modifier,
+ float time_scalar,
+ float gain_multiplier);
+
+// Calculates the gain value for |source_position| with respect to the given
+// room properties. The sound level for the room effects will remain the same
+// inside the room, otherwise, it will decrease with a linear ramp from the
+// closest point on the room.
+//
+// @param source_position World position of the source.
+// @param room_position Center position of the room.
+// @param room_rotation Orientation of the room.
+// @param room_dimensions Dimensions of the room..
+// @return Attenuation (gain) value in range [0.0f, 1.0f].
+float ComputeRoomEffectsGain(const WorldPosition& source_position,
+ const WorldPosition& room_position,
+ const WorldRotation& room_rotation,
+ const WorldPosition& room_dimensions);
+
+// Gets the room material properties from a material index.
+//
+// @param material_index Index of the material.
+RoomMaterial GetRoomMaterial(size_t material_index);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_PLATFORM_COMMON_ROOM_EFFECTS_UTILS_H_
diff --git a/src/3rdparty/resonance-audio/platforms/common/room_effects_utils_test.cc b/src/3rdparty/resonance-audio/platforms/common/room_effects_utils_test.cc
new file mode 100644
index 000000000..c742800ee
--- /dev/null
+++ b/src/3rdparty/resonance-audio/platforms/common/room_effects_utils_test.cc
@@ -0,0 +1,197 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "platforms/common/room_effects_utils.h"
+
+#include <memory>
+#include <string>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "platforms/common/room_properties.h"
+
+namespace vraudio {
+
+namespace {
+
+// Permitted error in the computed room effects coefficients against the
+// expected values. This value is 1e-4 as expected values are rounded for
+// readability.
+const float kCoefficientsEpsilon = 1e-4f;
+
+// Room position.
+const float kRoomPosition[3] = {10.0f, 10.0f, 10.0f};
+
+// Room dimensions (width x height x depth) of a medium size hall (shoe-box
+// model).
+const float kRoomDimensions[3] = {5.85f, 4.65f, 15.0f};
+
+// Reverb time adjustment parameters.
+const float kBrightnessModifier = 0.0f;
+
+const float kTimeModifier = 1.0f;
+
+// Expected set of reflection coefficients for given materials.
+const float kExpectedReflectionCoefficients[kNumRoomSurfaces] = {
+ 0.9381f, 0.9381f, 0.9679f, 0.9381f, 0.9381f, 0.9381f};
+
+// Expected -3dB cut-off frequency of the early reflections low-pass filter.
+const float kExpectedCutoffFrequency = 800.0f;
+
+// Expected reverb time values.
+const float kExpectedRt60Values[] = {0.47286f, 0.56928f, 0.69632f,
+ 0.89532f, 1.09418f, 1.90940f,
+ 1.67225f, 1.34293f, 0.56304f};
+
+// Expected reverb gain value.
+const float kExpectedGain = 0.045f;
+
+} // namespace
+
+class RoomEffectsUtilsTest : public ::testing::Test {
+ protected:
+ RoomEffectsUtilsTest() {}
+ // Virtual methods from ::testing::Test
+ ~RoomEffectsUtilsTest() override {}
+ void SetUp() override {
+ // Set up room properties.
+ room_properties_.position[0] = kRoomPosition[0];
+ room_properties_.position[1] = kRoomPosition[1];
+ room_properties_.position[2] = kRoomPosition[2];
+ room_properties_.dimensions[0] = kRoomDimensions[0];
+ room_properties_.dimensions[1] = kRoomDimensions[1];
+ room_properties_.dimensions[2] = kRoomDimensions[2];
+ // Set the material to 'Parquet on contrete' for the floor and 'Plywood
+ // panel' for the walls and the ceiling.
+ const std::vector<MaterialName> kMaterialNames = {
+ MaterialName::kPlywoodPanel, MaterialName::kPlywoodPanel,
+ MaterialName::kParquetOnConcrete, MaterialName::kPlywoodPanel,
+ MaterialName::kPlywoodPanel, MaterialName::kPlywoodPanel};
+ for (size_t i = 0; i < kNumRoomSurfaces; ++i) {
+ room_properties_.material_names[i] = kMaterialNames[i];
+ }
+ room_properties_.reverb_brightness = kBrightnessModifier;
+ room_properties_.reverb_time = kTimeModifier;
+ }
+ void TearDown() override {}
+
+ RoomProperties room_properties_;
+};
+
+// Tests if the ComputeReflectionProperties() function returns the same
+// reflection coefficient values as computed in MATLAB. Also, checks if other
+// ReflectionProperties data members are set up correctly.
+TEST_F(RoomEffectsUtilsTest, ComputeReflectionPropertiesTest) {
+ const auto reflection_properties =
+ ComputeReflectionProperties(room_properties_);
+
+ // Check if the cutoff frequency is correct.
+ EXPECT_NEAR(kExpectedCutoffFrequency, reflection_properties.cutoff_frequency,
+ kCoefficientsEpsilon);
+ // Check if the reflection coefficients for each surface are correct.
+ for (size_t i = 0; i < kNumRoomSurfaces; ++i) {
+ EXPECT_NEAR(kExpectedReflectionCoefficients[i],
+ reflection_properties.coefficients[i], kCoefficientsEpsilon);
+ }
+}
+
+// Tests if the ComputeReverbProperties() function returns the same reverb
+// time values as computed in MATLAB. Also, checks if other ReverbProperties
+// data members are set up correctly.
+TEST_F(RoomEffectsUtilsTest, ComputeReverbPropertiesTest) {
+ const auto reverb_properties = ComputeReverbProperties(room_properties_);
+
+ // Check if the reverb time values in the octave bands are correct.
+ for (size_t band = 0; band < kNumReverbOctaveBands; ++band) {
+ EXPECT_NEAR(kExpectedRt60Values[band], reverb_properties.rt60_values[band],
+ kCoefficientsEpsilon);
+ }
+
+ // Check the gain.
+ EXPECT_NEAR(kExpectedGain, reverb_properties.gain, kCoefficientsEpsilon);
+}
+
+// Tests if the ComputeReflectionProperties() and ComputeReverbProperties()
+// functions return reflection coefficients and RT60 values of 0 if there are no
+// materials set.
+TEST_F(RoomEffectsUtilsTest, ComputeRoomPropertiesNoMaterialsTest) {
+ for (size_t i = 0; i < kNumRoomSurfaces; ++i) {
+ room_properties_.material_names[i] = MaterialName::kTransparent;
+ }
+ const auto reflection_properties =
+ ComputeReflectionProperties(room_properties_);
+ const auto reverb_properties = ComputeReverbProperties(room_properties_);
+
+ // Check if the reflection coefficient values are near 0.
+ for (size_t surface = 0; surface < kNumRoomSurfaces; ++surface) {
+ EXPECT_NEAR(0.0f, reflection_properties.coefficients[surface],
+ kCoefficientsEpsilon);
+ }
+ // Check if the RT60 values are near 0.
+ for (size_t band = 0; band < kNumReverbOctaveBands; ++band) {
+ EXPECT_NEAR(0.0f, reverb_properties.rt60_values[band],
+ kCoefficientsEpsilon);
+ }
+}
+
+// Tests if the ComputeReverbProperties() function returns RT60 values of 0
+// seconds if all the materials are set to 'transparent' (full absorption).
+TEST_F(RoomEffectsUtilsTest, ComputeReverbPropertiesFullAbsorptionTest) {
+ for (size_t i = 0; i < kNumRoomSurfaces; ++i) {
+ room_properties_.material_names[i] = MaterialName::kTransparent;
+ }
+ const auto reverb_properties = ComputeReverbProperties(room_properties_);
+
+ // Check if the RT60 values are near 0.
+ for (size_t band = 0; band < kNumReverbOctaveBands; ++band) {
+ EXPECT_NEAR(0.0f, reverb_properties.rt60_values[band],
+ kCoefficientsEpsilon);
+ }
+ // Check the gain.
+ EXPECT_NEAR(kExpectedGain, reverb_properties.gain, kCoefficientsEpsilon);
+}
+
+// Tests the room effects gain computation against the pre-computed result when
+// source is inside the room.
+TEST_F(RoomEffectsUtilsTest, ComputeRoomEffectsGainInsideRoomTest) {
+ const WorldPosition kListenerPosition(0.0f, 0.5f, 0.0f);
+ const WorldPosition kSourcePosition(0.5f, 0.3f, 0.2f);
+ const WorldPosition kRoomPosition(0.5f, 0.5f, 0.5f);
+ const WorldRotation kRoomRotation = WorldRotation();
+ const WorldPosition kRoomDimensions(1.0f, 1.0f, 1.0f);
+ const float kExpectedGain = 1.0f;
+
+ const float gain = ComputeRoomEffectsGain(kSourcePosition, kRoomPosition,
+ kRoomRotation, kRoomDimensions);
+ EXPECT_NEAR(kExpectedGain, gain, kEpsilonFloat);
+}
+
+// Tests the room effects gain computation against the pre-computed result when
+// source is outside the room.
+TEST_F(RoomEffectsUtilsTest, ComputeRoomEffectsGainOutsideRoomTest) {
+ const WorldPosition kListenerPosition(0.0f, 0.5f, 0.0f);
+ const WorldPosition kSourcePosition(2.0f, 0.5f, 0.5f);
+ const WorldPosition kRoomPosition(0.5f, 0.5f, 0.5f);
+ const WorldRotation kRoomRotation = WorldRotation();
+ const WorldPosition kRoomDimensions(1.0f, 1.0f, 1.0f);
+ const float kExpectedGain = 0.25f;
+
+ const float gain = ComputeRoomEffectsGain(kSourcePosition, kRoomPosition,
+ kRoomRotation, kRoomDimensions);
+ EXPECT_NEAR(kExpectedGain, gain, kEpsilonFloat);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/platforms/common/room_properties.h b/src/3rdparty/resonance-audio/platforms/common/room_properties.h
new file mode 100644
index 000000000..55056c3bf
--- /dev/null
+++ b/src/3rdparty/resonance-audio/platforms/common/room_properties.h
@@ -0,0 +1,123 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Copyright 2017 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS-IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#ifndef RESONANCE_AUDIO_PLATFORM_COMMON_ROOM_PROPERTIES_H_
+#define RESONANCE_AUDIO_PLATFORM_COMMON_ROOM_PROPERTIES_H_
+
+namespace vraudio {
+
+// Room surface material names, used to set room properties.
+// Note that this enum is C-compatible by design to be used across external
+// C/C++ and C# implementations.
+enum MaterialName {
+ kTransparent = 0,
+ kAcousticCeilingTiles,
+ kBrickBare,
+ kBrickPainted,
+ kConcreteBlockCoarse,
+ kConcreteBlockPainted,
+ kCurtainHeavy,
+ kFiberGlassInsulation,
+ kGlassThin,
+ kGlassThick,
+ kGrass,
+ kLinoleumOnConcrete,
+ kMarble,
+ kMetal,
+ kParquetOnConcrete,
+ kPlasterRough,
+ kPlasterSmooth,
+ kPlywoodPanel,
+ kPolishedConcreteOrTile,
+ kSheetrock,
+ kWaterOrIceSurface,
+ kWoodCeiling,
+ kWoodPanel,
+ kUniform,
+ kNumMaterialNames
+};
+
+// Acoustic room properties. This struct can be used to describe an acoustic
+// environment with a given geometry and surface properties.
+// Note that this struct is C-compatible by design to be used across external
+// C/C++ and C# implementations.
+struct RoomProperties {
+ // Constructs |RoomProperties| with the default values.
+ RoomProperties()
+ : position{0.0f, 0.0f, 0.0f},
+ rotation{0.0f, 0.0f, 0.0f, 1.0f},
+ dimensions{0.0f, 0.0f, 0.0f},
+ material_names{MaterialName::kTransparent, MaterialName::kTransparent,
+ MaterialName::kTransparent, MaterialName::kTransparent,
+ MaterialName::kTransparent, MaterialName::kTransparent},
+ reflection_scalar(1.0f),
+ reverb_gain(1.0f),
+ reverb_time(1.0f),
+ reverb_brightness(0.0f) {}
+
+ // Center position of the room in world space, uses right-handed coordinate
+ // system.
+ float position[3];
+
+ // Rotation (quaternion) of the room in world space, uses right-handed
+ // coordinate system.
+ float rotation[4];
+
+ // Size of the shoebox room in world space, uses right-handed coordinate
+ // system.
+ float dimensions[3];
+
+ // Material name of each surface of the shoebox room in this order:
+ // [0] (-)ive x-axis wall (left)
+ // [1] (+)ive x-axis wall (right)
+ // [2] (-)ive y-axis wall (bottom)
+ // [3] (+)ive y-axis wall (top)
+ // [4] (-)ive z-axis wall (front)
+ // [5] (+)ive z-axis wall (back)
+ MaterialName material_names[6];
+
+ // User defined uniform scaling factor for all reflection coefficients.
+ float reflection_scalar;
+
+ // User defined reverb tail gain multiplier.
+ float reverb_gain;
+
+ // Adjusts the reverberation time across all frequency bands. RT60 values
+ // are multiplied by this factor. Has no effect when set to 1.0f.
+ float reverb_time;
+
+ // Controls the slope of a line from the lowest to the highest RT60 values
+ // (increases high frequency RT60s when positive, decreases when negative).
+ // Has no effect when set to 0.0f.
+ float reverb_brightness;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_PLATFORM_COMMON_ROOM_PROPERTIES_H_
diff --git a/src/3rdparty/resonance-audio/platforms/common/utils.cc b/src/3rdparty/resonance-audio/platforms/common/utils.cc
new file mode 100644
index 000000000..2b3e34ac2
--- /dev/null
+++ b/src/3rdparty/resonance-audio/platforms/common/utils.cc
@@ -0,0 +1,59 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "platforms/common/utils.h"
+
+namespace vraudio {
+
+void FlipZAxis(Eigen::Matrix4f* matrix) {
+ // This operation is equivalent to:
+ // matrix = flipZ * matrix * flipZ
+ // where flipZ is the scale(1, 1, -1) matrix.
+ (*matrix)(0, 2) *= -1.0f;
+ (*matrix)(1, 2) *= -1.0f;
+ (*matrix)(2, 0) *= -1.0f;
+ (*matrix)(2, 1) *= -1.0f;
+ (*matrix)(2, 3) *= -1.0f;
+ (*matrix)(3, 2) *= -1.0f;
+}
+
+Eigen::Quaternionf GetQuaternion(const Eigen::Matrix4f& matrix) {
+ const Eigen::Matrix3f rotation_matrix = matrix.block(0, 0, 3, 3);
+ Eigen::Quaternionf quaternion(rotation_matrix);
+ return quaternion.normalized();
+}
+
+Eigen::Vector3f GetPosition(const Eigen::Matrix4f& matrix) {
+ return Eigen::Vector3f(matrix.col(3).head<3>());
+}
+
+Eigen::Matrix4f GetTransformMatrix(const Eigen::Vector3f& position,
+ const Eigen::Vector3f& forward,
+ const Eigen::Vector3f& up) {
+ Eigen::Matrix4f transform_matrix;
+ // Compose the homogeneous vectors for the transformation matrix.
+ const Eigen::Vector3f right = up.cross(forward);
+ const Eigen::Vector4f position_4(position.x(), position.y(), position.z(),
+ 1.0f);
+ const Eigen::Vector4f forward_4(forward.x(), forward.y(), forward.z(), 0.0f);
+ const Eigen::Vector4f up_4(up.x(), up.y(), up.z(), 0.0f);
+ const Eigen::Vector4f right_4(right.x(), right.y(), right.z(), 0.0f);
+ // Fill in the transformation matrix.
+ transform_matrix << right_4, up_4, forward_4, position_4;
+ return transform_matrix;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/platforms/common/utils.h b/src/3rdparty/resonance-audio/platforms/common/utils.h
new file mode 100644
index 000000000..5273f437f
--- /dev/null
+++ b/src/3rdparty/resonance-audio/platforms/common/utils.h
@@ -0,0 +1,55 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_PLATFORM_COMMON_UTILS_H_
+#define RESONANCE_AUDIO_PLATFORM_COMMON_UTILS_H_
+
+#include "Eigen/Dense"
+
+namespace vraudio {
+
+// Flips the z-axis of a transformation matrix, which effectively allows
+// switching between the left-handed and right-handed coordinate systems.
+//
+// @param matrix 4x4 transformation matrix.
+// @return 4x4 transformation matrix with the z-axis flipped.
+void FlipZAxis(Eigen::Matrix4f* matrix);
+
+// Returns the position vector of a transformation matrix.
+//
+// @param matrix 4x4 transformation matrix.
+// @return 3D position vector.
+Eigen::Vector3f GetPosition(const Eigen::Matrix4f& matrix);
+
+// Returns the rotation quaternion of a transformation matrix.
+//
+// @param matrix 4x4 transformation matrix.
+// @return Quaternion representation of the rotation.
+Eigen::Quaternionf GetQuaternion(const Eigen::Matrix4f& matrix);
+
+// Returns a transformation matrix from position, forward & up vectors.
+//
+// @param position Position vector.
+// @param forward Forward direction vector describing rotation.
+// @param up Up direction vector describing rotation.
+// @return 4x4 transformation matrix.
+Eigen::Matrix4f GetTransformMatrix(const Eigen::Vector3f& position,
+ const Eigen::Vector3f& forward,
+ const Eigen::Vector3f& up);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_PLATFORM_COMMON_UTILS_H_
diff --git a/src/3rdparty/resonance-audio/platforms/common/utils_test.cc b/src/3rdparty/resonance-audio/platforms/common/utils_test.cc
new file mode 100644
index 000000000..40992027e
--- /dev/null
+++ b/src/3rdparty/resonance-audio/platforms/common/utils_test.cc
@@ -0,0 +1,107 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "platforms/common/utils.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// Tests that flipping the z-axis of an arbitrary transformation matrix using
+// the |FlipZAxis| method gives the expected transformation matrix.
+TEST(UtilsTest, FlipZAxisTest) {
+ // Test input values for an arbitrary 4x4 matrix.
+ const float kInput[] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f,
+ 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f,
+ 13.0f, 14.0f, 15.0f, 16.0f};
+ // Z-axis flip matrix is the TRS matrix of Scale(1, 1, -1).
+ const auto kFlipZMatrix((Eigen::Matrix4f() << 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f)
+ .finished());
+
+ // Compute the expected transformation matrix for given |kInput|.
+ const auto expected = kFlipZMatrix * Eigen::Matrix4f(kInput) * kFlipZMatrix;
+ // Compute the flipped transformation matrix of given |kInput|.
+ Eigen::Matrix4f output(kInput);
+ FlipZAxis(&output);
+
+ // Verify that the output matrix has expected number of rows & columns.
+ EXPECT_EQ(expected.rows(), output.rows());
+ EXPECT_EQ(expected.cols(), output.cols());
+ // Compare equality for all the elements in the resulting matrices.
+ const size_t num_cols = output.cols();
+ const size_t num_rows = output.rows();
+ for (size_t col = 0; col < num_cols; ++col) {
+ for (size_t row = 0; row < num_rows; ++row) {
+ EXPECT_EQ(expected(row, col), output(row, col));
+ }
+ }
+}
+
+// Tests that the |GetTransformMatrix| method gives the expected transformation
+// matrix, in which the properties remain unchanged when returned via the
+// |GetPosition| and |GetQuaternion| methods.
+TEST(UtilsTest, GetTransformMatrixAndBackTest) {
+ // Arbitrary position.
+ const Eigen::Vector3f kInputPosition(1.0f, 5.0f, -10.0f);
+ // Arbitrary directions calculated from the orientation of euler angles
+ // (45, 90, -90) in degrees.
+ const Eigen::Vector3f kInputForward(kInverseSqrtTwo, -kInverseSqrtTwo, 0.0f);
+ const Eigen::Vector3f kInputUp(0.0f, 0.0f, -1.0f);
+ // Expected values for the transformation matrix from the given
+ // |kInputPosition|, |kInputForward| & |kInputUp| vectors.
+ const float kExpectedTransform[] = {
+ -kInverseSqrtTwo, -kInverseSqrtTwo, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f,
+ kInverseSqrtTwo, -kInverseSqrtTwo, 0.0f, 0.0f, 1.0f, 5.0f, -10.0f, 1.0f};
+
+ // Calculate the transform matrix.
+ const auto output_transform =
+ GetTransformMatrix(kInputPosition, kInputForward, kInputUp);
+
+ // Test if the resulting transformation matrix has the expected values.
+ const size_t num_cols = output_transform.cols();
+ const size_t num_rows = output_transform.rows();
+ const Eigen::Matrix4f expected_transform(kExpectedTransform);
+ for (size_t col = 0; col < num_cols; ++col) {
+ for (size_t row = 0; row < num_rows; ++row) {
+ EXPECT_EQ(expected_transform(row, col), output_transform(row, col));
+ }
+ }
+
+ // Verify that the position vector remains unchanged.
+ const auto output_position = GetPosition(output_transform);
+ EXPECT_TRUE(kInputPosition.isApprox(output_position, kEpsilonFloat));
+
+ // Verify that the forward & up direction vectors remain unchanged.
+ const Eigen::Vector3f kForward(0.0f, 0.0f, 1.0f);
+ const Eigen::Vector3f kUp(0.0f, 1.0f, 0.0f);
+ const auto output_quaternion = GetQuaternion(output_transform);
+
+ const auto output_forward = (output_quaternion * kForward).normalized();
+ EXPECT_TRUE(kInputForward.isApprox(output_forward, kEpsilonFloat));
+
+ const auto output_up = (output_quaternion * kUp).normalized();
+ EXPECT_TRUE(kInputUp.isApprox(output_up, kEpsilonFloat));
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/qt_attribution.json b/src/3rdparty/resonance-audio/qt_attribution.json
new file mode 100644
index 000000000..6f56457cb
--- /dev/null
+++ b/src/3rdparty/resonance-audio/qt_attribution.json
@@ -0,0 +1,18 @@
+{
+ "Id": "resonance-audio",
+ "Name": "Resonance Audio",
+ "QDocModule": "qtspatialaudio",
+ "Description": "3D audio support.",
+ "QtUsage": "Used to implement spatial audio.",
+ "SecurityCritical": true,
+
+ "Homepage": "https://resonance-audio.github.io/resonance-audio/",
+ "Version": "e225aedb5ec7",
+ "DownloadLocation":
+ "https://github.com/resonance-audio/resonance-audio/tree/e225aedb5ec76ca6a0fe7079c0b84dbcbb490553",
+
+ "CopyrightFile": "COPYRIGHTS",
+ "License": "Apache License 2.0",
+ "LicenseId": "Apache-2.0",
+ "LicenseFile": "LICENSE"
+}
diff --git a/src/3rdparty/resonance-audio/resonance_audio/CMakeLists.txt b/src/3rdparty/resonance-audio/resonance_audio/CMakeLists.txt
new file mode 100644
index 000000000..b52e62526
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/CMakeLists.txt
@@ -0,0 +1,335 @@
+# Copyright 2018 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS-IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Build PFFFT.
+set(PFFFT_DIR "${PROJECT_SOURCE_DIR}/third_party/pffft/" CACHE PATH "Path to pffft library")
+set(PFFFT_INCLUDE_DIR ${PFFFT_DIR})
+set(PFFFT_SOURCE
+ ${PFFFT_DIR}/fftpack.c
+ ${PFFFT_DIR}/fftpack.h
+ ${PFFFT_DIR}/pffft.c
+ ${PFFFT_DIR}/pffft.h
+ )
+add_library(PffftObj OBJECT ${PFFFT_SOURCE})
+target_include_directories(PffftObj PRIVATE ${PFFFT_INCLUDE_DIR}/)
+
+if (UNIX)
+ set_target_properties(PffftObj PROPERTIES COMPILE_FLAGS -fPIC)
+endif (UNIX)
+
+# Build SADIE HRTF database.
+set(SADIE_HRTFS_DIR "${PROJECT_SOURCE_DIR}/third_party/SADIE_hrtf_database/generated/" CACHE PATH "Path to SADIE_hrtf_database library")
+set(SADIE_HRTFS_INCLUDE_DIR ${SADIE_HRTFS_DIR})
+set(SADIE_HRTFS_SOURCE
+ ${SADIE_HRTFS_DIR}/hrtf_assets.cc
+ ${SADIE_HRTFS_DIR}/hrtf_assets.h
+ )
+add_library(SadieHrtfsObj OBJECT ${SADIE_HRTFS_SOURCE})
+
+# Build Resonance Audio.
+set(RA_SOURCES
+ ${PROJECT_SOURCE_DIR}/platforms/common/utils.cc
+ ${PROJECT_SOURCE_DIR}/platforms/common/utils.h
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_binaural_decoder.h
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_binaural_decoder.cc
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_codec.h
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_codec_impl.h
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_lookup_table.cc
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_lookup_table.h
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_spread_coefficients.h
+ ${RA_SOURCE_DIR}/ambisonics/associated_legendre_polynomials_generator.cc
+ ${RA_SOURCE_DIR}/ambisonics/associated_legendre_polynomials_generator.h
+ ${RA_SOURCE_DIR}/ambisonics/foa_rotator.cc
+ ${RA_SOURCE_DIR}/ambisonics/foa_rotator.h
+ ${RA_SOURCE_DIR}/ambisonics/hoa_rotator.cc
+ ${RA_SOURCE_DIR}/ambisonics/hoa_rotator.h
+ ${RA_SOURCE_DIR}/ambisonics/stereo_from_soundfield_converter.cc
+ ${RA_SOURCE_DIR}/ambisonics/stereo_from_soundfield_converter.h
+ ${RA_SOURCE_DIR}/ambisonics/utils.h
+ ${RA_SOURCE_DIR}/api/binaural_surround_renderer.cc
+ ${RA_SOURCE_DIR}/api/binaural_surround_renderer.h
+ ${RA_SOURCE_DIR}/api/resonance_audio_api.cc
+ ${RA_SOURCE_DIR}/api/resonance_audio_api.h
+ ${RA_SOURCE_DIR}/base/aligned_allocator.h
+ ${RA_SOURCE_DIR}/base/audio_buffer.cc
+ ${RA_SOURCE_DIR}/base/audio_buffer.h
+ ${RA_SOURCE_DIR}/base/channel_view.cc
+ ${RA_SOURCE_DIR}/base/channel_view.h
+ ${RA_SOURCE_DIR}/base/constants_and_types.h
+ ${RA_SOURCE_DIR}/base/integral_types.h
+ ${RA_SOURCE_DIR}/base/logging.h
+ ${RA_SOURCE_DIR}/base/misc_math.cc
+ ${RA_SOURCE_DIR}/base/misc_math.h
+ ${RA_SOURCE_DIR}/base/object_transform.h
+ ${RA_SOURCE_DIR}/base/simd_macros.h
+ ${RA_SOURCE_DIR}/base/simd_utils.cc
+ ${RA_SOURCE_DIR}/base/simd_utils.h
+ ${RA_SOURCE_DIR}/base/source_parameters.h
+ ${RA_SOURCE_DIR}/base/spherical_angle.cc
+ ${RA_SOURCE_DIR}/base/spherical_angle.h
+ ${RA_SOURCE_DIR}/base/unique_ptr_wrapper.h
+ ${RA_SOURCE_DIR}/config/global_config.h
+ ${RA_SOURCE_DIR}/config/source_config.cc
+ ${RA_SOURCE_DIR}/config/source_config.h
+ ${RA_SOURCE_DIR}/dsp/biquad_filter.cc
+ ${RA_SOURCE_DIR}/dsp/biquad_filter.h
+ ${RA_SOURCE_DIR}/dsp/channel_converter.cc
+ ${RA_SOURCE_DIR}/dsp/channel_converter.h
+ ${RA_SOURCE_DIR}/dsp/circular_buffer.cc
+ ${RA_SOURCE_DIR}/dsp/circular_buffer.h
+ ${RA_SOURCE_DIR}/dsp/delay_filter.cc
+ ${RA_SOURCE_DIR}/dsp/delay_filter.h
+ ${RA_SOURCE_DIR}/dsp/distance_attenuation.cc
+ ${RA_SOURCE_DIR}/dsp/distance_attenuation.h
+ ${RA_SOURCE_DIR}/dsp/fft_manager.cc
+ ${RA_SOURCE_DIR}/dsp/fft_manager.h
+ ${RA_SOURCE_DIR}/dsp/filter_coefficient_generators.cc
+ ${RA_SOURCE_DIR}/dsp/filter_coefficient_generators.h
+ ${RA_SOURCE_DIR}/dsp/fir_filter.cc
+ ${RA_SOURCE_DIR}/dsp/fir_filter.h
+ ${RA_SOURCE_DIR}/dsp/gain.cc
+ ${RA_SOURCE_DIR}/dsp/gain.h
+ ${RA_SOURCE_DIR}/dsp/gain_mixer.cc
+ ${RA_SOURCE_DIR}/dsp/gain_mixer.h
+ ${RA_SOURCE_DIR}/dsp/gain_processor.cc
+ ${RA_SOURCE_DIR}/dsp/gain_processor.h
+ ${RA_SOURCE_DIR}/dsp/mixer.cc
+ ${RA_SOURCE_DIR}/dsp/mixer.h
+ ${RA_SOURCE_DIR}/dsp/mono_pole_filter.cc
+ ${RA_SOURCE_DIR}/dsp/mono_pole_filter.h
+ ${RA_SOURCE_DIR}/dsp/multi_channel_iir.cc
+ ${RA_SOURCE_DIR}/dsp/multi_channel_iir.h
+ ${RA_SOURCE_DIR}/dsp/near_field_processor.cc
+ ${RA_SOURCE_DIR}/dsp/near_field_processor.h
+ ${RA_SOURCE_DIR}/dsp/occlusion_calculator.cc
+ ${RA_SOURCE_DIR}/dsp/occlusion_calculator.h
+ ${RA_SOURCE_DIR}/dsp/partitioned_fft_filter.cc
+ ${RA_SOURCE_DIR}/dsp/partitioned_fft_filter.h
+ ${RA_SOURCE_DIR}/dsp/reflection.h
+ ${RA_SOURCE_DIR}/dsp/reflections_processor.cc
+ ${RA_SOURCE_DIR}/dsp/reflections_processor.h
+ ${RA_SOURCE_DIR}/dsp/resampler.cc
+ ${RA_SOURCE_DIR}/dsp/resampler.h
+ ${RA_SOURCE_DIR}/dsp/reverb_onset_compensator.cc
+ ${RA_SOURCE_DIR}/dsp/reverb_onset_compensator.h
+ ${RA_SOURCE_DIR}/dsp/reverb_onset_update_processor.cc
+ ${RA_SOURCE_DIR}/dsp/reverb_onset_update_processor.h
+ ${RA_SOURCE_DIR}/dsp/sh_hrir_creator.cc
+ ${RA_SOURCE_DIR}/dsp/sh_hrir_creator.h
+ ${RA_SOURCE_DIR}/dsp/shoe_box_room.cc
+ ${RA_SOURCE_DIR}/dsp/shoe_box_room.h
+ ${RA_SOURCE_DIR}/dsp/spectral_reverb.cc
+ ${RA_SOURCE_DIR}/dsp/spectral_reverb.h
+ ${RA_SOURCE_DIR}/dsp/spectral_reverb_constants_and_tables.h
+ ${RA_SOURCE_DIR}/dsp/stereo_panner.cc
+ ${RA_SOURCE_DIR}/dsp/stereo_panner.h
+ ${RA_SOURCE_DIR}/dsp/utils.cc
+ ${RA_SOURCE_DIR}/dsp/utils.h
+ ${RA_SOURCE_DIR}/graph/ambisonic_binaural_decoder_node.cc
+ ${RA_SOURCE_DIR}/graph/ambisonic_binaural_decoder_node.h
+ ${RA_SOURCE_DIR}/graph/ambisonic_mixing_encoder_node.cc
+ ${RA_SOURCE_DIR}/graph/ambisonic_mixing_encoder_node.h
+ ${RA_SOURCE_DIR}/graph/binaural_surround_renderer_impl.cc
+ ${RA_SOURCE_DIR}/graph/binaural_surround_renderer_impl.h
+ ${RA_SOURCE_DIR}/graph/buffered_source_node.cc
+ ${RA_SOURCE_DIR}/graph/buffered_source_node.h
+ ${RA_SOURCE_DIR}/graph/foa_rotator_node.cc
+ ${RA_SOURCE_DIR}/graph/foa_rotator_node.h
+ ${RA_SOURCE_DIR}/graph/gain_mixer_node.cc
+ ${RA_SOURCE_DIR}/graph/gain_mixer_node.h
+ ${RA_SOURCE_DIR}/graph/gain_node.cc
+ ${RA_SOURCE_DIR}/graph/gain_node.h
+ ${RA_SOURCE_DIR}/graph/graph_manager.cc
+ ${RA_SOURCE_DIR}/graph/graph_manager.h
+ ${RA_SOURCE_DIR}/graph/graph_manager_config.h
+ ${RA_SOURCE_DIR}/graph/hoa_rotator_node.cc
+ ${RA_SOURCE_DIR}/graph/hoa_rotator_node.h
+ ${RA_SOURCE_DIR}/graph/mixer_node.cc
+ ${RA_SOURCE_DIR}/graph/mixer_node.h
+ ${RA_SOURCE_DIR}/graph/mono_from_soundfield_node.cc
+ ${RA_SOURCE_DIR}/graph/mono_from_soundfield_node.h
+ ${RA_SOURCE_DIR}/graph/near_field_effect_node.cc
+ ${RA_SOURCE_DIR}/graph/near_field_effect_node.h
+ ${RA_SOURCE_DIR}/graph/occlusion_node.cc
+ ${RA_SOURCE_DIR}/graph/occlusion_node.h
+ ${RA_SOURCE_DIR}/graph/reflections_node.cc
+ ${RA_SOURCE_DIR}/graph/reflections_node.h
+ ${RA_SOURCE_DIR}/graph/resonance_audio_api_impl.cc
+ ${RA_SOURCE_DIR}/graph/resonance_audio_api_impl.h
+ ${RA_SOURCE_DIR}/graph/reverb_node.cc
+ ${RA_SOURCE_DIR}/graph/reverb_node.h
+ ${RA_SOURCE_DIR}/graph/source_graph_config.h
+ ${RA_SOURCE_DIR}/graph/source_parameters_manager.cc
+ ${RA_SOURCE_DIR}/graph/source_parameters_manager.h
+ ${RA_SOURCE_DIR}/graph/stereo_mixing_panner_node.cc
+ ${RA_SOURCE_DIR}/graph/stereo_mixing_panner_node.h
+ ${RA_SOURCE_DIR}/graph/system_settings.h
+ ${RA_SOURCE_DIR}/node/node.h
+ ${RA_SOURCE_DIR}/node/processing_node.cc
+ ${RA_SOURCE_DIR}/node/processing_node.h
+ ${RA_SOURCE_DIR}/node/publisher_node.h
+ ${RA_SOURCE_DIR}/node/sink_node.cc
+ ${RA_SOURCE_DIR}/node/sink_node.h
+ ${RA_SOURCE_DIR}/node/source_node.cc
+ ${RA_SOURCE_DIR}/node/source_node.h
+ ${RA_SOURCE_DIR}/node/subscriber_node.h
+ ${PROJECT_SOURCE_DIR}/platforms/common/room_effects_utils.cc
+ ${PROJECT_SOURCE_DIR}/platforms/common/room_effects_utils.h
+ ${RA_SOURCE_DIR}/utils/buffer_crossfader.cc
+ ${RA_SOURCE_DIR}/utils/buffer_crossfader.h
+ ${RA_SOURCE_DIR}/utils/buffer_partitioner.cc
+ ${RA_SOURCE_DIR}/utils/buffer_partitioner.h
+ ${RA_SOURCE_DIR}/utils/buffer_unpartitioner.cc
+ ${RA_SOURCE_DIR}/utils/buffer_unpartitioner.h
+ ${RA_SOURCE_DIR}/utils/lockless_task_queue.cc
+ ${RA_SOURCE_DIR}/utils/lockless_task_queue.h
+ ${RA_SOURCE_DIR}/utils/planar_interleaved_conversion.cc
+ ${RA_SOURCE_DIR}/utils/planar_interleaved_conversion.h
+ ${RA_SOURCE_DIR}/utils/pseudoinverse.h
+ ${RA_SOURCE_DIR}/utils/sample_type_conversion.cc
+ ${RA_SOURCE_DIR}/utils/sample_type_conversion.h
+ ${RA_SOURCE_DIR}/utils/semi_lockless_fifo.h
+ ${RA_SOURCE_DIR}/utils/sum_and_difference_processor.cc
+ ${RA_SOURCE_DIR}/utils/sum_and_difference_processor.h
+ ${RA_SOURCE_DIR}/utils/threadsafe_fifo.h
+ ${RA_SOURCE_DIR}/utils/wav.cc
+ ${RA_SOURCE_DIR}/utils/wav.h
+ ${RA_SOURCE_DIR}/utils/wav_reader.cc
+ ${RA_SOURCE_DIR}/utils/wav_reader.h
+ )
+
+add_library(ResonanceAudioObj OBJECT ${RA_SOURCES})
+target_include_directories(ResonanceAudioObj PRIVATE ${PROJECT_SOURCE_DIR}/resonance_audio/)
+target_include_directories(ResonanceAudioObj PRIVATE ${EIGEN3_INCLUDE_DIR}/)
+target_include_directories(ResonanceAudioObj PRIVATE ${PFFFT_INCLUDE_DIR}/)
+
+
+if (BUILD_RESONANCE_AUDIO_API)
+ # Build shared library
+ add_library(ResonanceAudioShared SHARED $<TARGET_OBJECTS:ResonanceAudioObj>
+ $<TARGET_OBJECTS:SadieHrtfsObj>
+ $<TARGET_OBJECTS:PffftObj>)
+
+ # Build static library
+ add_library(ResonanceAudioStatic STATIC $<TARGET_OBJECTS:ResonanceAudioObj>
+ $<TARGET_OBJECTS:SadieHrtfsObj>
+ $<TARGET_OBJECTS:PffftObj>)
+
+ set(RA_INSTALL_DIR "${INSTALL_DIR}/resonance_audio/")
+ install(TARGETS ResonanceAudioStatic ResonanceAudioShared
+ LIBRARY DESTINATION ${RA_INSTALL_DIR}/lib
+ ARCHIVE DESTINATION ${RA_INSTALL_DIR}/lib
+ RUNTIME DESTINATION ${RA_INSTALL_DIR}/lib
+ PUBLIC_HEADER DESTINATION ${RA_INSTALL_DIR}/include)
+
+ set(RA_PUBLIC_HEADERS
+ ${RA_SOURCE_DIR}/api/binaural_surround_renderer.h
+ ${RA_SOURCE_DIR}/api/resonance_audio_api.h
+ )
+ install(FILES ${RA_PUBLIC_HEADERS}
+ DESTINATION ${RA_INSTALL_DIR}/include)
+endif (BUILD_RESONANCE_AUDIO_API)
+
+
+if (BUILD_RESONANCE_AUDIO_TESTS)
+ set(RA_TESTS
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_binaural_decoder_test.cc
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_codec_impl_test.cc
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_lookup_table_test.cc
+ ${RA_SOURCE_DIR}/ambisonics/associated_legendre_polynomials_generator_test.cc
+ ${RA_SOURCE_DIR}/ambisonics/foa_rotator_test.cc
+ ${RA_SOURCE_DIR}/ambisonics/hoa_rotator_test.cc
+ ${RA_SOURCE_DIR}/ambisonics/stereo_from_soundfield_converter_test.cc
+ ${RA_SOURCE_DIR}/ambisonics/utils_test.cc
+ ${RA_SOURCE_DIR}/base/aligned_allocator_test.cc
+ ${RA_SOURCE_DIR}/base/audio_buffer_test.cc
+ ${RA_SOURCE_DIR}/base/channel_view_test.cc
+ ${RA_SOURCE_DIR}/base/misc_math_test.cc
+ ${RA_SOURCE_DIR}/base/simd_utils_test.cc
+ ${RA_SOURCE_DIR}/base/spherical_angle_test.cc
+ ${RA_SOURCE_DIR}/dsp/biquad_filter_test.cc
+ ${RA_SOURCE_DIR}/dsp/channel_converter_test.cc
+ ${RA_SOURCE_DIR}/dsp/circular_buffer_test.cc
+ ${RA_SOURCE_DIR}/dsp/delay_filter_test.cc
+ ${RA_SOURCE_DIR}/dsp/distance_attenuation_test.cc
+ ${RA_SOURCE_DIR}/dsp/fft_manager_test.cc
+ ${RA_SOURCE_DIR}/dsp/filter_coefficient_generators_test.cc
+ ${RA_SOURCE_DIR}/dsp/fir_filter_test.cc
+ ${RA_SOURCE_DIR}/dsp/gain_mixer_test.cc
+ ${RA_SOURCE_DIR}/dsp/gain_processor_test.cc
+ ${RA_SOURCE_DIR}/dsp/gain_test.cc
+ ${RA_SOURCE_DIR}/dsp/mixer_test.cc
+ ${RA_SOURCE_DIR}/dsp/mono_pole_filter_test.cc
+ ${RA_SOURCE_DIR}/dsp/multi_channel_iir_test.cc
+ ${RA_SOURCE_DIR}/dsp/occlusion_calculator_test.cc
+ ${RA_SOURCE_DIR}/dsp/partitioned_fft_filter_test.cc
+ ${RA_SOURCE_DIR}/dsp/reflections_processor_test.cc
+ ${RA_SOURCE_DIR}/dsp/resampler_test.cc
+ ${RA_SOURCE_DIR}/dsp/shoe_box_room_test.cc
+ ${RA_SOURCE_DIR}/dsp/spectral_reverb_test.cc
+ ${RA_SOURCE_DIR}/dsp/stereo_panner_test.cc
+ ${RA_SOURCE_DIR}/dsp/utils_test.cc
+ ${RA_SOURCE_DIR}/graph/ambisonic_mixing_encoder_node_test.cc
+ ${RA_SOURCE_DIR}/graph/binaural_surround_renderer_impl_test.cc
+ ${RA_SOURCE_DIR}/graph/occlusion_node_test.cc
+ ${RA_SOURCE_DIR}/graph/gain_mixer_node_test.cc
+ ${RA_SOURCE_DIR}/graph/gain_node_test.cc
+ ${RA_SOURCE_DIR}/graph/mixer_node_test.cc
+ ${RA_SOURCE_DIR}/graph/source_parameters_manager_test.cc
+ ${RA_SOURCE_DIR}/node/audio_nodes_test.cc
+ ${RA_SOURCE_DIR}/node/node_test.cc
+ ${PROJECT_SOURCE_DIR}/platforms/common/room_effects_utils_test.cc
+ ${RA_SOURCE_DIR}/utils/buffer_crossfader_test.cc
+ ${RA_SOURCE_DIR}/utils/buffer_partitioner_test.cc
+ ${RA_SOURCE_DIR}/utils/buffer_unpartitioner_test.cc
+ ${RA_SOURCE_DIR}/utils/lockless_task_queue_test.cc
+ ${RA_SOURCE_DIR}/utils/planar_interleaved_conversion_test.cc
+ ${RA_SOURCE_DIR}/utils/pseudoinverse_test.cc
+ ${RA_SOURCE_DIR}/utils/sample_type_conversion_test.cc
+ ${RA_SOURCE_DIR}/utils/sum_and_difference_processor_test.cc
+ ${RA_SOURCE_DIR}/utils/test_util.cc
+ ${RA_SOURCE_DIR}/utils/test_util.h
+ ${RA_SOURCE_DIR}/utils/test_util_test.cc
+ )
+
+ # Unit Tests target.
+ add_executable(ResonanceAudioUnitTests ${RA_TESTS}
+ $<TARGET_OBJECTS:gtest>
+ $<TARGET_OBJECTS:ResonanceAudioObj>
+ $<TARGET_OBJECTS:SadieHrtfsObj>
+ $<TARGET_OBJECTS:PffftObj>)
+
+ target_include_directories(ResonanceAudioUnitTests PRIVATE "${EIGEN3_INCLUDE_DIR}/")
+ target_include_directories(ResonanceAudioUnitTests PRIVATE "${PFFFT_INCLUDE_DIR}/")
+ target_include_directories(ResonanceAudioUnitTests PRIVATE "${PROJECT_SOURCE_DIR}/resonance_audio/")
+ target_include_directories(ResonanceAudioUnitTests PRIVATE "${GTEST_DIR}/googlemock/")
+ target_include_directories(ResonanceAudioUnitTests PRIVATE "${GTEST_DIR}/googlemock/include")
+ target_include_directories(ResonanceAudioUnitTests PRIVATE "${GTEST_DIR}/googletest/")
+ target_include_directories(ResonanceAudioUnitTests PRIVATE "${GTEST_DIR}/googletest/include")
+
+ if (NOT WIN32)
+ find_package(Threads REQUIRED)
+ target_link_libraries(ResonanceAudioUnitTests pthread)
+ endif (NOT WIN32)
+
+ add_test(NAME runResonanceAudioUnitTest COMMAND $<TARGET_FILE:ResonanceAudioUnitTests>)
+
+ add_custom_command(
+ TARGET ResonanceAudioUnitTests
+ COMMENT "Run resonance audio tests"
+ POST_BUILD
+ COMMAND ResonanceAudioUnitTests
+ )
+endif (BUILD_RESONANCE_AUDIO_TESTS)
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder.cc
new file mode 100644
index 000000000..2a278389b
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder.cc
@@ -0,0 +1,80 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/ambisonic_binaural_decoder.h"
+
+#include "ambisonics/utils.h"
+#include "base/constants_and_types.h"
+
+
+namespace vraudio {
+
+AmbisonicBinauralDecoder::AmbisonicBinauralDecoder(const AudioBuffer& sh_hrirs,
+ size_t frames_per_buffer,
+ FftManager* fft_manager)
+ : fft_manager_(fft_manager),
+ freq_input_(kNumMonoChannels, NextPowTwo(frames_per_buffer) * 2),
+ filtered_input_(kNumMonoChannels, frames_per_buffer) {
+ CHECK(fft_manager_);
+ CHECK_NE(frames_per_buffer, 0U);
+ const size_t num_channels = sh_hrirs.num_channels();
+ const size_t filter_size = sh_hrirs.num_frames();
+ CHECK_NE(num_channels, 0U);
+ CHECK_NE(filter_size, 0U);
+ sh_hrir_filters_.reserve(num_channels);
+ for (size_t i = 0; i < num_channels; ++i) {
+ sh_hrir_filters_.emplace_back(
+ new PartitionedFftFilter(filter_size, frames_per_buffer, fft_manager_));
+ sh_hrir_filters_[i]->SetTimeDomainKernel(sh_hrirs[i]);
+ }
+}
+
+void AmbisonicBinauralDecoder::Process(const AudioBuffer& input,
+ AudioBuffer* output) {
+
+ DCHECK(output);
+ DCHECK_EQ(kNumStereoChannels, output->num_channels());
+ DCHECK_EQ(input.num_frames(), output->num_frames());
+ DCHECK_EQ(input.num_channels(), sh_hrir_filters_.size());
+
+ output->Clear();
+
+ AudioBuffer::Channel* freq_input_channel = &freq_input_[0];
+ AudioBuffer::Channel* filtered_input_channel = &filtered_input_[0];
+ AudioBuffer::Channel* output_channel_0 = &(*output)[0];
+ AudioBuffer::Channel* output_channel_1 = &(*output)[1];
+ for (size_t channel = 0; channel < input.num_channels(); ++channel) {
+ const int degree = GetPeriphonicAmbisonicDegreeForChannel(channel);
+ fft_manager_->FreqFromTimeDomain(input[channel], freq_input_channel);
+ sh_hrir_filters_[channel]->Filter(*freq_input_channel);
+ sh_hrir_filters_[channel]->GetFilteredSignal(filtered_input_channel);
+ if (degree < 0) {
+ // Degree is negative: spherical harmonic is asymetric.
+ // So add contributions to the left channel and subtract from the right
+ // channel.
+ *output_channel_0 += *filtered_input_channel;
+ *output_channel_1 -= *filtered_input_channel;
+
+ } else {
+ // Degree is zero or positive: spherical harmonic is symetric.
+ // So add contributions to both left and right channels.
+ *output_channel_0 += *filtered_input_channel;
+ *output_channel_1 += *filtered_input_channel;
+ }
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder.h b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder.h
new file mode 100644
index 000000000..98a861234
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder.h
@@ -0,0 +1,71 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_AMBISONICS_AMBISONIC_BINAURAL_DECODER_H_
+#define RESONANCE_AUDIO_AMBISONICS_AMBISONIC_BINAURAL_DECODER_H_
+
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "dsp/fft_manager.h"
+#include "dsp/partitioned_fft_filter.h"
+
+namespace vraudio {
+
+// Decodes an Ambisonic sound field, of an arbitrary order, to binaural stereo,
+// by performing convolution in the spherical harmonics domain. The order (hence
+// the number of channels) of the input must match the order (hence the number
+// of channels) of the spherical harmonic-encoded Head Related Impulse Responses
+// (HRIRs). Assumes that HRIRs are symmetric with respect to the sagittal plane.
+class AmbisonicBinauralDecoder {
+ public:
+ // Constructs an |AmbisonicBinauralDecoder| from an |AudioBuffer| containing
+ // spherical harmonic representation of HRIRs. The order of spherical
+ // harmonic-encoded HRIRs (hence the number of channels) must match the order
+ // of the Ambisonic sound field input.
+ //
+ // @param sh_hrirs |AudioBuffer| containing time-domain spherical harmonic
+ // encoded symmetric HRIRs.
+ // @param frames_per_buffer Number of frames in each input/output buffer.
+ // @param fft_manager Pointer to a manager to perform FFT transformations.
+ AmbisonicBinauralDecoder(const AudioBuffer& sh_hrirs,
+ size_t frames_per_buffer, FftManager* fft_manager);
+
+ // Processes an Ambisonic sound field input and outputs a binaurally decoded
+ // stereo buffer.
+ //
+ // @param input Input buffer to be processed.
+ // @param output Pointer to a stereo output buffer.
+ void Process(const AudioBuffer& input, AudioBuffer* output);
+
+ private:
+ // Manager for all FFT related functionality (not owned).
+ FftManager* const fft_manager_;
+
+ // Spherical Harmonic HRIR filter kernels.
+ std::vector<std::unique_ptr<PartitionedFftFilter>> sh_hrir_filters_;
+
+ // Frequency domain representation of the input signal.
+ PartitionedFftFilter::FreqDomainBuffer freq_input_;
+
+ // Temporary audio buffer to store the convolution output for asymmetric or
+ // symmetric spherical harmonic HRIR.
+ AudioBuffer filtered_input_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_AMBISONICS_AMBISONIC_BINAURAL_DECODER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder_test.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder_test.cc
new file mode 100644
index 000000000..ca2b0dfca
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_binaural_decoder_test.cc
@@ -0,0 +1,162 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/ambisonic_binaural_decoder.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "dsp/fft_manager.h"
+
+namespace vraudio {
+
+namespace {
+
+// Generates sample audio data where the first sample is 0 and each consecutive
+// sample is incremented by 0.001. Then it moves to the next channel and
+// continues to increment the samples.
+std::vector<std::vector<float>> GenerateAudioData(size_t num_channels,
+ size_t num_samples) {
+ std::vector<std::vector<float>> input_data(num_channels,
+ std::vector<float>(num_samples));
+ float sample_value = 0.0f;
+ const float increment = 0.001f;
+ for (size_t channel = 0; channel < num_channels; ++channel) {
+ for (size_t sample = 0; sample < num_samples; ++sample) {
+ input_data[channel][sample] = sample_value;
+ sample_value += increment;
+ }
+ }
+ return input_data;
+}
+
+// Number of frames in each audio input/output buffer.
+const size_t kFramesPerBuffer = 18;
+
+} // namespace
+
+// Tests whether binaural docoding of Ambisonic input using short HRIR filters
+// (shorter than the number of frames per buffer) gives correct results.
+TEST(AmbisonicBinauralDecoderTest, ShortFilterTest) {
+ const std::vector<std::vector<float>> kInputData =
+ GenerateAudioData(kNumFirstOrderAmbisonicChannels, kFramesPerBuffer);
+ const std::vector<float> kExpectedOutputLeft = {
+ 0.0042840000f, 0.0087780003f, 0.013486000f, 0.018412000f, 0.023560001f,
+ 0.028934000f, 0.034538001f, 0.040376000f, 0.046452001f, 0.052770000f,
+ 0.059333999f, 0.066147998f, 0.073215999f, 0.080541998f, 0.088129997f,
+ 0.095983997f, 0.10410800f, 0.10638600f};
+ const std::vector<float> kExpectedOutputRight = {
+ 0.0036720000f, 0.0074840002f, 0.011438000f, 0.015536000f, 0.019780001f,
+ 0.024172001f, 0.028713999f, 0.033408001f, 0.038256001f, 0.043260001f,
+ 0.048422001f, 0.053743999f, 0.059227999f, 0.064875998f, 0.070689999f,
+ 0.076672003f, 0.082823999f, 0.084252000f};
+ const std::vector<std::vector<float>> kHrirDataShort =
+ GenerateAudioData(kNumFirstOrderAmbisonicChannels, kFramesPerBuffer - 1);
+
+ AudioBuffer sh_hrirs(kHrirDataShort.size(), kHrirDataShort[0].size());
+ sh_hrirs = kHrirDataShort;
+
+ AudioBuffer input(kInputData.size(), kInputData[0].size());
+ input = kInputData;
+
+ AudioBuffer output(kNumStereoChannels, kInputData[0].size());
+ output.Clear();
+
+ FftManager fft_manager(kFramesPerBuffer);
+ AmbisonicBinauralDecoder decoder(sh_hrirs, kFramesPerBuffer, &fft_manager);
+ decoder.Process(input, &output);
+
+ for (size_t sample = 0; sample < kFramesPerBuffer; ++sample) {
+ EXPECT_NEAR(kExpectedOutputLeft[sample], output[0][sample], kEpsilonFloat);
+ EXPECT_NEAR(kExpectedOutputRight[sample], output[1][sample], kEpsilonFloat);
+ }
+}
+
+// Tests whether binaural docoding of Ambisonic input using HRIR filters
+// with the same size as frames per buffer gives correct results.
+TEST(AmbisonicBinauralDecoderTest, SameSizeFilterTest) {
+ const std::vector<std::vector<float>> kInputData =
+ GenerateAudioData(kNumFirstOrderAmbisonicChannels, kFramesPerBuffer);
+ const std::vector<float> kExpectedOutputLeft = {
+ 0.0045360001f, 0.0092879999f, 0.014260001f, 0.019455999f, 0.024879999f,
+ 0.030536000f, 0.036428001f, 0.042560000f, 0.048935998f, 0.055560000f,
+ 0.062436000f, 0.069568001f, 0.076959997f, 0.084615998f, 0.092540003f,
+ 0.10073600f, 0.10920800f, 0.11796000f};
+ const std::vector<float> kExpectedOutputRight = {
+ 0.0038880000f, 0.0079199998f, 0.012098000f, 0.016424000f, 0.020900000f,
+ 0.025528001f, 0.030309999f, 0.035248000f, 0.040344000f, 0.045600001f,
+ 0.051018000f, 0.056600001f, 0.062348001f, 0.068264000f, 0.074349999f,
+ 0.080608003f, 0.087040000f, 0.093648002f};
+ const std::vector<std::vector<float>> kHrirDataSame =
+ GenerateAudioData(kNumFirstOrderAmbisonicChannels, kFramesPerBuffer);
+
+ AudioBuffer sh_hrirs(kHrirDataSame.size(), kHrirDataSame[0].size());
+ sh_hrirs = kHrirDataSame;
+
+ AudioBuffer input(kInputData.size(), kInputData[0].size());
+ input = kInputData;
+
+ AudioBuffer output(kNumStereoChannels, kInputData[0].size());
+ output.Clear();
+
+ FftManager fft_manager(kFramesPerBuffer);
+ AmbisonicBinauralDecoder decoder(sh_hrirs, kFramesPerBuffer, &fft_manager);
+ decoder.Process(input, &output);
+
+ for (size_t sample = 0; sample < kFramesPerBuffer; ++sample) {
+ EXPECT_NEAR(kExpectedOutputLeft[sample], output[0][sample], kEpsilonFloat);
+ EXPECT_NEAR(kExpectedOutputRight[sample], output[1][sample], kEpsilonFloat);
+ }
+}
+
+// Tests whether binaural docoding of Ambisonic input using long HRIR filters
+// (longer than the number of frames per buffer) gives correct results.
+TEST(AmbisonicBinauralDecoderTest, LongSizeFilterTest) {
+ const std::vector<std::vector<float>> kInputData =
+ GenerateAudioData(kNumFirstOrderAmbisonicChannels, kFramesPerBuffer);
+ const std::vector<float> kExpectedOutputLeft = {
+ 0.0047880001f, 0.0097980006f, 0.015034000f, 0.020500001f, 0.026200000f,
+ 0.032138001f, 0.038318001f, 0.044744000f, 0.051419999f, 0.058350001f,
+ 0.065537997f, 0.072987996f, 0.080704004f, 0.088689998f, 0.096950002f,
+ 0.10548800f, 0.11430800f, 0.12341400f};
+ const std::vector<float> kExpectedOutputRight = {
+ 00.0041040001f, 0.0083560003f, 0.012758000f, 0.017312000f, 0.022020001f,
+ 0.026883999f, 0.031906001f, 0.037087999f, 0.042431999f, 0.047940001f,
+ 0.053613998f, 0.059455998f, 0.065467998f, 0.071652003f, 0.078010000f,
+ 0.084543996f, 0.091256000f, 0.098148003f};
+ const std::vector<std::vector<float>> kHrirDataLong =
+ GenerateAudioData(kNumFirstOrderAmbisonicChannels, kFramesPerBuffer + 1);
+
+ AudioBuffer sh_hrirs(kHrirDataLong.size(), kHrirDataLong[0].size());
+ sh_hrirs = kHrirDataLong;
+
+ AudioBuffer input(kInputData.size(), kInputData[0].size());
+ input = kInputData;
+
+ AudioBuffer output(kNumStereoChannels, kInputData[0].size());
+ output.Clear();
+
+ FftManager fft_manager(kFramesPerBuffer);
+ AmbisonicBinauralDecoder decoder(sh_hrirs, kFramesPerBuffer, &fft_manager);
+ decoder.Process(input, &output);
+
+ for (size_t sample = 0; sample < kFramesPerBuffer; ++sample) {
+ EXPECT_NEAR(kExpectedOutputLeft[sample], output[0][sample], kEpsilonFloat);
+ EXPECT_NEAR(kExpectedOutputRight[sample], output[1][sample], kEpsilonFloat);
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec.h b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec.h
new file mode 100644
index 000000000..546a88470
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec.h
@@ -0,0 +1,62 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_AMBISONICS_AMBISONIC_CODEC_H_
+#define RESONANCE_AUDIO_AMBISONICS_AMBISONIC_CODEC_H_
+
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "base/spherical_angle.h"
+
+namespace vraudio {
+// An encoder/decoder for ambisonic sound fields. It supports variable ambisonic
+// order, ACN channel sequencing and SN3D normalization.
+class AmbisonicCodec {
+ public:
+ virtual ~AmbisonicCodec() {}
+ // Encodes the given buffer of decoded vectors (unencoded data).
+ //
+ // @param input |AudioBuffer| of decoded (unencoded) data.
+ // @param output |AudioBuffer| to store the encoded data.
+ virtual void EncodeBuffer(const AudioBuffer& input, AudioBuffer* output) = 0;
+
+ // Decodes the given |AudioBuffer| of planar (non-interleaved) encoded data.
+ //
+ // @param input |AudioBuffer| of encoded data.
+ // @param output |AudioBuffer| to store the decoded data.
+ virtual void DecodeBuffer(const AudioBuffer& input, AudioBuffer* output) = 0;
+
+ // Returns the maximum periphonic ambisonic order that this codec supports.
+ virtual int ambisonic_order() const = 0;
+
+ // Returns the number of angles for this codec.
+ virtual size_t num_angles() const = 0;
+
+ // Returns the maximum number of spherical harmonics computed by this codec.
+ virtual size_t num_spherical_harmonics() const = 0;
+
+ // Returns the spherical angles currently used to define the encoder/decoder
+ // matrices.
+ virtual const std::vector<SphericalAngle>& angles() const = 0;
+
+ // Sets the spherical angles used to build the encoder/decoder matrices.
+ virtual void set_angles(const std::vector<SphericalAngle>& angles) = 0;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_AMBISONICS_AMBISONIC_CODEC_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec_impl.h b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec_impl.h
new file mode 100644
index 000000000..03a83140f
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec_impl.h
@@ -0,0 +1,295 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_AMBISONICS_AMBISONIC_CODEC_IMPL_H_
+#define RESONANCE_AUDIO_AMBISONICS_AMBISONIC_CODEC_IMPL_H_
+
+#include <cmath>
+#include <vector>
+
+#include "Eigen/Dense"
+#include "ambisonics/ambisonic_codec.h"
+#include "ambisonics/associated_legendre_polynomials_generator.h"
+#include "ambisonics/utils.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/spherical_angle.h"
+#include "utils/pseudoinverse.h"
+
+namespace vraudio {
+// An encoder/decoder for ambisonic sound fields. It supports variable ambisonic
+// order, ACN channel sequencing and SN3D normalization.
+//
+// @tparam NumAngles Used to fix the number of angles to be encoded/decoded at
+// compile-time; use |Eigen::Dynamic| to indicate run-time variability.
+// @tparam NumSphericalHarmonics Used to fix the number of spherical harmonic
+// components at compile time; use |Eigen::Dynamic| to indicate run-time
+// variability.
+template <int NumAngles = Eigen::Dynamic,
+ int NumSphericalHarmonics = Eigen::Dynamic>
+class AmbisonicCodecImpl : public AmbisonicCodec {
+ public:
+ // Spherical harmonics encoder matrix.
+ typedef Eigen::Matrix<float, NumSphericalHarmonics, NumAngles> EncoderMatrix;
+ // Spherical harmonics decoder matrix.
+ typedef Eigen::Matrix<float, NumAngles, NumSphericalHarmonics> DecoderMatrix;
+ // Spherical harmonics encoding of a frame or collection of frames (i.e., a
+ // vector of spherical harmonics).
+ typedef Eigen::Matrix<float, NumSphericalHarmonics, 1> EncodedVector;
+ // Decoded sequence of values for each angle / mono frame (i.e., a vector with
+ // a decoded mono frame for each angle).
+ typedef Eigen::Matrix<float, NumAngles, 1> DecodedVector;
+
+ // Creates a codec with the given |ambisonic_order| and spherical |angles| to
+ // compute encoder/decoder matrices.
+ AmbisonicCodecImpl(int ambisonic_order,
+ const std::vector<SphericalAngle>& angles);
+
+ // Implements |AmbisonicCodec|.
+ void EncodeBuffer(const AudioBuffer& input, AudioBuffer* output) override;
+ void DecodeBuffer(const AudioBuffer& input, AudioBuffer* output) override;
+ int ambisonic_order() const override;
+ size_t num_angles() const override;
+ size_t num_spherical_harmonics() const override;
+ const std::vector<SphericalAngle>& angles() const override;
+ void set_angles(const std::vector<SphericalAngle>& angles) override;
+
+ // Encodes the given vector.
+
+ void Encode(const Eigen::Ref<const Eigen::MatrixXf> decoded_vector,
+ Eigen::Ref<Eigen::MatrixXf> encoded_vector);
+
+ // Decodes the given vector.
+
+ void Decode(const Eigen::Ref<const Eigen::MatrixXf> encoded_vector,
+ Eigen::Ref<Eigen::MatrixXf> decoded_vector);
+
+ // Gets the ambisonic sound field encoder matrix.
+ const Eigen::Ref<const Eigen::MatrixXf> GetEncoderMatrix();
+
+ // Gets the ambisonic sound field decoder matrix.
+ const Eigen::Ref<const Eigen::MatrixXf> GetDecoderMatrix();
+
+ // Necessary due to Eigen's alignment requirements on some platforms.
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW
+
+ private:
+ // Returns the unnormalized spherical harmonic
+ // Y_degree^order(azimuth, elevation).
+ float UnnormalizedSphericalHarmonic(int degree, int order,
+ const SphericalAngle& angle) const;
+
+ // The maximum-ordered ambisonic sound field handled by this codec. In the
+ // case of a periphonic codec, this is the order of the ambisonic sound field.
+ const int ambisonic_order_;
+ // Spherical angles used to compute spherical harmonics. For example, for a
+ // decoder, virtual loudspeaker positions; for an encoder, the position(s) of
+ // virtual sources relative to the listener.
+ std::vector<SphericalAngle> angles_;
+ // Current spherical harmonics encoder matrix if encoder_matrix_invalid_ is
+ // false.
+ EncoderMatrix encoder_matrix_;
+ // True if encoder_matrix_ needs to be recomputed.
+ bool encoder_matrix_invalid_;
+ // Current spherical harmonics decoder matrix if encoder_matrix_invalid_ is
+ // false.
+ DecoderMatrix decoder_matrix_;
+ // True if decoder_matrix_ needs to be recomputed.
+ bool decoder_matrix_invalid_;
+ // The associated Legendre polynomial generator for this codec.
+ AssociatedLegendrePolynomialsGenerator alp_generator_;
+ // Temporary storage for associated Legendre polynomials generated.
+ std::vector<float> associated_legendre_polynomials_temp_;
+};
+
+template <int NumAngles, int NumSphericalHarmonics>
+AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::AmbisonicCodecImpl(
+ int ambisonic_order, const std::vector<SphericalAngle>& angles)
+ : ambisonic_order_(ambisonic_order),
+ alp_generator_(ambisonic_order, false, false) {
+ DCHECK_GE(ambisonic_order_, 0);
+ set_angles(angles);
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+void AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::Encode(
+ const Eigen::Ref<const Eigen::MatrixXf> decoded_vector,
+ Eigen::Ref<Eigen::MatrixXf> encoded_vector) {
+ encoded_vector.noalias() = GetEncoderMatrix() * decoded_vector;
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+void AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::Decode(
+ const Eigen::Ref<const Eigen::MatrixXf> encoded_vector,
+ Eigen::Ref<Eigen::MatrixXf> decoded_vector) {
+ decoded_vector.noalias() = GetDecoderMatrix() * encoded_vector;
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+void AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::EncodeBuffer(
+ const AudioBuffer& input, AudioBuffer* output) {
+ CHECK(output);
+ CHECK_EQ(input.num_channels(), num_angles());
+ CHECK_EQ(output->num_channels(), num_spherical_harmonics());
+ CHECK_EQ(input.num_frames(), output->num_frames());
+
+ Eigen::Map<const Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic,
+ Eigen::RowMajor>,
+ Eigen::Aligned>
+ unencoded_buffer(&input[0][0], num_angles(), output->GetChannelStride());
+
+ Eigen::Map<
+ Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>,
+ Eigen::Aligned>
+ encoded_buffer(&(*output)[0][0], num_spherical_harmonics(),
+ input.GetChannelStride());
+
+ encoded_buffer.noalias() = GetEncoderMatrix() * unencoded_buffer;
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+void AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::DecodeBuffer(
+ const AudioBuffer& input, AudioBuffer* output) {
+ CHECK(output);
+ CHECK_EQ(input.num_channels(), num_spherical_harmonics());
+ CHECK_EQ(output->num_channels(), num_angles());
+ CHECK_EQ(input.num_frames(), output->num_frames());
+
+ Eigen::Map<const Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic,
+ Eigen::RowMajor>,
+ Eigen::Aligned>
+ encoded_buffer(&input[0][0], num_spherical_harmonics(),
+ input.GetChannelStride());
+
+ Eigen::Map<
+ Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>,
+ Eigen::Aligned>
+ decoded_buffer(&(*output)[0][0], num_angles(),
+ output->GetChannelStride());
+
+ decoded_buffer.noalias() = GetDecoderMatrix() * encoded_buffer;
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+const Eigen::Ref<const Eigen::MatrixXf>
+AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::GetEncoderMatrix() {
+ if (encoder_matrix_invalid_) {
+ encoder_matrix_ = EncoderMatrix(
+ GetNumPeriphonicComponents(ambisonic_order_), angles_.size());
+ for (int col = 0; col < encoder_matrix_.cols(); col++) {
+ const SphericalAngle& angle = angles_[col];
+ associated_legendre_polynomials_temp_ =
+ alp_generator_.Generate(std::sin(angle.elevation()));
+ // Compute the actual spherical harmonics using the generated polynomials.
+ for (int degree = 0; degree <= ambisonic_order_; degree++) {
+ for (int order = -degree; order <= degree; order++) {
+ const int row = AcnSequence(degree, order);
+ if (row == -1) {
+ // Skip this spherical harmonic.
+ continue;
+ }
+ encoder_matrix_(row, col) =
+ Sn3dNormalization(degree, order) *
+ UnnormalizedSphericalHarmonic(degree, order, angle);
+ }
+ }
+ }
+ encoder_matrix_invalid_ = false;
+ }
+ return encoder_matrix_;
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+const Eigen::Ref<const Eigen::MatrixXf>
+AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::GetDecoderMatrix() {
+ if (decoder_matrix_invalid_) {
+ decoder_matrix_ = Pseudoinverse<Eigen::MatrixXf>(GetEncoderMatrix());
+ // Condition number of the encoding/decoding matrices. We use the fact that
+ // the decoding matrix is already a (pseudo)-inverse of the encoding matrix.
+ const float condition_number =
+ static_cast<float>(GetEncoderMatrix().norm() * decoder_matrix_.norm());
+ const float num_rows = static_cast<float>(GetEncoderMatrix().rows());
+ const float num_cols = static_cast<float>(GetEncoderMatrix().cols());
+ if (condition_number >
+ 1.0f / (std::max(num_rows, num_cols) * kEpsilonFloat)) {
+ LOG(WARNING) << "Ambisonic decoding matrix is ill-conditioned. Results "
+ << "may be inaccurate.";
+ }
+ decoder_matrix_invalid_ = false;
+ }
+ return decoder_matrix_;
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+int AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::ambisonic_order()
+ const {
+ return ambisonic_order_;
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+size_t AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::num_angles()
+ const {
+ return angles_.size();
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+size_t AmbisonicCodecImpl<
+ NumAngles, NumSphericalHarmonics>::num_spherical_harmonics() const {
+ // Return the worst-case scenario (the number of coefficients for a
+ // periphonic sound field).
+ return GetNumPeriphonicComponents(ambisonic_order_);
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+const std::vector<SphericalAngle>&
+AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::angles() const {
+ return angles_;
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+void AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::set_angles(
+ const std::vector<SphericalAngle>& angles) {
+ CHECK_GT(angles.size(), 0);
+
+ angles_ = angles;
+ encoder_matrix_invalid_ = decoder_matrix_invalid_ = true;
+}
+
+template <int NumAngles, int NumSphericalHarmonics>
+float AmbisonicCodecImpl<NumAngles, NumSphericalHarmonics>::
+ UnnormalizedSphericalHarmonic(int degree, int order,
+ const SphericalAngle& angle) const {
+ const float last_term =
+ (order >= 0) ? std::cos(static_cast<float>(order) * angle.azimuth())
+ : std::sin(static_cast<float>(-order) * angle.azimuth());
+ return associated_legendre_polynomials_temp_[alp_generator_.GetIndex(
+ degree, std::abs(order))] *
+ last_term;
+}
+
+// Codec for a single source.
+template <int NumSphericalHarmonics = Eigen::Dynamic>
+using MonoAmbisonicCodec = AmbisonicCodecImpl<1, NumSphericalHarmonics>;
+
+// Codec for a N-speaker first-order periphonic setup.
+template <int NumAngles>
+using FirstOrderPeriphonicAmbisonicCodec =
+ AmbisonicCodecImpl<NumAngles, GetNumPeriphonicComponentsStatic<1>::value>;
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_AMBISONICS_AMBISONIC_CODEC_IMPL_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec_impl_test.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec_impl_test.cc
new file mode 100644
index 000000000..c7f0900be
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_codec_impl_test.cc
@@ -0,0 +1,354 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/ambisonic_codec_impl.h"
+
+#include <cmath>
+#include <memory>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+namespace {
+
+const int kCubeNumVertices = 8;
+const float kCubeVertices[kCubeNumVertices][3] = {
+ {-1.0f, 1.0f, -1.0f}, {1.0f, 1.0f, -1.0f}, {-1.0f, 1.0f, 1.0f},
+ {1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, -1.0f}, {1.0f, -1.0f, -1.0f},
+ {-1.0f, -1.0f, 1.0f}, {1.0f, -1.0f, 1.0f}};
+
+// Generates a third-order B-format encoder matrix.
+AmbisonicCodecImpl<>::EncoderMatrix GenerateThirdOrderBFormatEncoderMatrix(
+ const SphericalAngle& spherical_angle) {
+ const size_t kNumSphericalHarmonics = GetNumPeriphonicComponents(3);
+ const size_t kNumAngles = 1;
+ AmbisonicCodecImpl<>::EncoderMatrix encoder_matrix(kNumSphericalHarmonics,
+ kNumAngles);
+ const float azimuth_rad = spherical_angle.azimuth();
+ const float elevation_rad = spherical_angle.elevation();
+ encoder_matrix << 1.0f, std::cos(elevation_rad) * std::sin(azimuth_rad),
+ std::sin(elevation_rad), std::cos(elevation_rad) * std::cos(azimuth_rad),
+ kSqrtThree / 2.0f * std::cos(elevation_rad) * std::cos(elevation_rad) *
+ std::sin(2.0f * azimuth_rad),
+ kSqrtThree / 2.0f * std::sin(2.0f * elevation_rad) *
+ std::sin(azimuth_rad),
+ 0.5f * (3.0f * std::sin(elevation_rad) * std::sin(elevation_rad) - 1.0f),
+ kSqrtThree / 2.0f * std::sin(2.0f * elevation_rad) *
+ std::cos(azimuth_rad),
+ kSqrtThree / 2.0f * std::cos(elevation_rad) * std::cos(elevation_rad) *
+ std::cos(2.0f * azimuth_rad),
+ std::sqrt(5.0f / 8.0f) * IntegerPow(std::cos(elevation_rad), 3) *
+ std::sin(3.0f * azimuth_rad),
+ std::sqrt(15.0f) / 2.0f * std::sin(elevation_rad) *
+ std::cos(elevation_rad) * std::cos(elevation_rad) *
+ std::sin(2.0f * azimuth_rad),
+ std::sqrt(3.0f / 8.0f) * std::cos(elevation_rad) *
+ (5.0f * std::sin(elevation_rad) * std::sin(elevation_rad) - 1.0f) *
+ std::sin(azimuth_rad),
+ 0.5f * std::sin(elevation_rad) *
+ (5.0f * std::sin(elevation_rad) * std::sin(elevation_rad) - 3.0f),
+ std::sqrt(3.0f / 8.0f) * std::cos(elevation_rad) *
+ (5.0f * std::sin(elevation_rad) * std::sin(elevation_rad) - 1.0f) *
+ std::cos(azimuth_rad),
+ std::sqrt(15.0f) / 2.0f * std::sin(elevation_rad) *
+ std::cos(elevation_rad) * std::cos(elevation_rad) *
+ std::cos(2.0f * azimuth_rad),
+ std::sqrt(5.0f / 8.0f) * IntegerPow(std::cos(elevation_rad), 3) *
+ std::cos(3.0f * azimuth_rad);
+ return encoder_matrix;
+}
+
+class AmbisonicCodecTest : public ::testing::Test {
+ protected:
+ AmbisonicCodecTest() {
+ for (int i = 0; i < kCubeNumVertices; i++) {
+ const float azimuth_rad =
+ atan2f(kCubeVertices[i][2], kCubeVertices[i][0]);
+ const float elevation_rad =
+ std::asin(kCubeVertices[i][1] /
+ std::sqrt(kCubeVertices[i][0] * kCubeVertices[i][0] +
+ kCubeVertices[i][1] * kCubeVertices[i][1] +
+ kCubeVertices[i][2] * kCubeVertices[i][2]));
+
+ cube_angles_.push_back(SphericalAngle(azimuth_rad, elevation_rad));
+ }
+
+ codec_first_order_cube_ = std::unique_ptr<AmbisonicCodecImpl<>>(
+ new AmbisonicCodecImpl<>(1, cube_angles_));
+ }
+
+ std::unique_ptr<AmbisonicCodecImpl<>> codec_first_order_cube_;
+ std::vector<SphericalAngle> cube_angles_;
+};
+
+// Tests that encoder and decoder matrices are ~inverses of each other.
+TEST_F(AmbisonicCodecTest, EncoderDecoderIdentity) {
+ const auto encoder_matrix = codec_first_order_cube_->GetEncoderMatrix();
+ const auto decoder_matrix = codec_first_order_cube_->GetDecoderMatrix();
+
+ const auto should_be_identity = encoder_matrix * decoder_matrix;
+ EXPECT_TRUE(should_be_identity.isApprox(
+ decltype(should_be_identity)::Identity(should_be_identity.rows(),
+ should_be_identity.cols()),
+ kEpsilonFloat))
+ << "Matrix should be within " << kEpsilonFloat
+ << " of an identity matrix: \n"
+ << should_be_identity;
+}
+
+// Tests that Encode and Decode are ~inverse operations.
+TEST_F(AmbisonicCodecTest, EncodeDecodeIsInverse) {
+ AmbisonicCodecImpl<>::DecodedVector unencoded_vector(8);
+ unencoded_vector << 1, 2, 3, 4, 5, 6, 7, 8;
+ AmbisonicCodecImpl<>::EncodedVector encoded_vector(4);
+ codec_first_order_cube_->Encode(unencoded_vector, encoded_vector);
+ AmbisonicCodecImpl<>::DecodedVector decoded_vector(8);
+ codec_first_order_cube_->Decode(encoded_vector, decoded_vector);
+
+ EXPECT_TRUE(unencoded_vector.isApprox(decoded_vector, kEpsilonFloat))
+ << "Decoded vector should be within " << kEpsilonFloat << " of: \n"
+ << unencoded_vector;
+}
+
+// Tests that EncodeBuffer and Decode (over a buffer) are ~inverse operations.
+TEST_F(AmbisonicCodecTest, EncodeBufferDecodeVectorsIsInverse) {
+ const int kNumElements = 256;
+ const int kNumSphericalHarmonics = GetNumPeriphonicComponentsStatic<1>::value;
+
+ AudioBuffer unencoded_buffer(kCubeNumVertices, kNumElements);
+ // Produce a buffer of successive numbers between -1 and 1.
+ for (int element = 0; element < kNumElements; ++element) {
+ for (int angle = 0; angle < kCubeNumVertices; ++angle) {
+ unencoded_buffer[angle][element] =
+ static_cast<float>(element * kCubeNumVertices + angle) /
+ (0.5f * kNumElements * kCubeNumVertices) -
+ 1.0f;
+ }
+ }
+
+ AudioBuffer encoded_buffer(kNumSphericalHarmonics, kNumElements);
+ codec_first_order_cube_->EncodeBuffer(unencoded_buffer, &encoded_buffer);
+
+ // Verify the encoded buffer and decoded vectors are ~identical.
+ for (int element = 0; element < kNumElements; ++element) {
+ AmbisonicCodecImpl<>::EncodedVector encoded_vector(kNumSphericalHarmonics);
+ for (int harmonic = 0; harmonic < kNumSphericalHarmonics; ++harmonic) {
+ encoded_vector[harmonic] = encoded_buffer[harmonic][element];
+ }
+ AmbisonicCodecImpl<>::DecodedVector decoded_vector(kCubeNumVertices);
+ codec_first_order_cube_->Decode(encoded_vector, decoded_vector);
+ for (int angle = 0; angle < kCubeNumVertices; ++angle) {
+ EXPECT_NEAR(unencoded_buffer[angle][element], decoded_vector[angle],
+ kEpsilonFloat);
+ }
+ }
+}
+
+// Tests that Encode (over a buffer) and DecodeBuffer are ~inverse operations.
+TEST_F(AmbisonicCodecTest, EncodeVectorsDecodeBufferIsInverse) {
+ const int kNumElements = 256;
+ const int kNumSphericalHarmonics = GetNumPeriphonicComponentsStatic<1>::value;
+
+ AudioBuffer unencoded_buffer(kCubeNumVertices, kNumElements);
+ // Produce a buffer of successive numbers between -1 and 1.
+ for (int element = 0; element < kNumElements; ++element) {
+ for (int angle = 0; angle < kCubeNumVertices; ++angle) {
+ unencoded_buffer[angle][element] =
+ static_cast<float>(element * kCubeNumVertices + angle) /
+ (0.5f * kNumElements * kCubeNumVertices) -
+ 1.0f;
+ }
+ }
+
+ AudioBuffer encoded_buffer(kNumSphericalHarmonics, kNumElements);
+ // Produce the encoded version of unencoded_buffer.
+ for (int element = 0; element < kNumElements; ++element) {
+ AmbisonicCodecImpl<>::DecodedVector unencoded_vector(kCubeNumVertices);
+ for (int angle = 0; angle < kCubeNumVertices; ++angle) {
+ unencoded_vector[angle] = unencoded_buffer[angle][element];
+ }
+ AmbisonicCodecImpl<>::EncodedVector encoded_vector(kNumSphericalHarmonics);
+ codec_first_order_cube_->Encode(unencoded_vector, encoded_vector);
+ for (int harmonic = 0; harmonic < kNumSphericalHarmonics; ++harmonic) {
+ encoded_buffer[harmonic][element] = encoded_vector[harmonic];
+ }
+ }
+
+ AudioBuffer decoded_buffer(kCubeNumVertices, kNumElements);
+ codec_first_order_cube_->DecodeBuffer(encoded_buffer, &decoded_buffer);
+ // Verify the decoded buffer and unencoded buffer are ~identical.
+ for (int element = 0; element < kNumElements; ++element) {
+ for (int angle = 0; angle < kCubeNumVertices; ++angle) {
+ EXPECT_NEAR(unencoded_buffer[angle][element],
+ decoded_buffer[angle][element], kEpsilonFloat);
+ }
+ }
+}
+
+// Tests that EncodeBuffer and DecodeBuffer are ~inverse operations.
+TEST_F(AmbisonicCodecTest, EncodeBufferDecodeBufferIsInverse) {
+ const int kNumElements = 256;
+ const int kNumSphericalHarmonics = GetNumPeriphonicComponentsStatic<1>::value;
+
+ AudioBuffer unencoded_buffer(kCubeNumVertices, kNumElements);
+ // Produce a buffer of successive numbers between -1 and 1.
+ for (int element = 0; element < kNumElements; ++element) {
+ for (int angle = 0; angle < kCubeNumVertices; ++angle) {
+ unencoded_buffer[angle][element] =
+ static_cast<float>(element * kCubeNumVertices + angle) /
+ (0.5f * kNumElements * kCubeNumVertices) -
+ 1.0f;
+ }
+ }
+
+
+
+ AudioBuffer encoded_buffer(kNumSphericalHarmonics, kNumElements);
+ // Produce the encoded version of unencoded_buffer.
+ for (int element = 0; element < kNumElements; ++element) {
+ AmbisonicCodecImpl<>::DecodedVector unencoded_vector(kCubeNumVertices);
+ for (int angle = 0; angle < kCubeNumVertices; ++angle) {
+ unencoded_vector[angle] = unencoded_buffer[angle][element];
+ }
+ AmbisonicCodecImpl<>::EncodedVector encoded_vector(kNumSphericalHarmonics);
+ codec_first_order_cube_->Encode(unencoded_vector, encoded_vector);
+ for (int harmonic = 0; harmonic < kNumSphericalHarmonics; ++harmonic) {
+ encoded_buffer[harmonic][element] = encoded_vector[harmonic];
+ }
+ }
+
+ AudioBuffer decoded_buffer(kCubeNumVertices, kNumElements);
+ codec_first_order_cube_->DecodeBuffer(encoded_buffer, &decoded_buffer);
+ // Verify the decoded buffer and unencoded buffer are ~identical.
+ for (int element = 0; element < kNumElements; ++element) {
+ for (int angle = 0; angle < kCubeNumVertices; ++angle) {
+ EXPECT_NEAR(unencoded_buffer[angle][element],
+ decoded_buffer[angle][element], kEpsilonFloat);
+ }
+ }
+}
+
+// Tests that third-order encoding coefficients produced by Codec are correct.
+TEST_F(AmbisonicCodecTest, ThirdOrderEncodingCoefficients) {
+ const int kNumSphericalHarmonics = GetNumPeriphonicComponentsStatic<3>::value;
+
+ const float kAzimuthStart = -180.0f;
+ const float kAzimuthStop = 180.0f;
+ const float kAzimuthStep = 10.0f;
+ for (float azimuth = kAzimuthStart; azimuth <= kAzimuthStop;
+ azimuth += kAzimuthStep) {
+ const float kElevationStart = -90.0f;
+ const float kElevationStop = 90.0f;
+ const float kElevationStep = 10.0f;
+ for (float elevation = kElevationStart; elevation <= kElevationStop;
+ elevation += kElevationStep) {
+ const int kAmbisonicOrder = 3;
+
+ const SphericalAngle kSphericalAngle =
+ SphericalAngle::FromDegrees(azimuth, elevation);
+ AmbisonicCodecImpl<> mono_codec(kAmbisonicOrder, {kSphericalAngle});
+
+ AmbisonicCodecImpl<>::DecodedVector kUnencodedVector(1);
+ kUnencodedVector << 0.12345f;
+ AmbisonicCodecImpl<>::EncodedVector codec_encoded_vector(
+ kNumSphericalHarmonics);
+ mono_codec.Encode(kUnencodedVector, codec_encoded_vector);
+ const AmbisonicCodecImpl<>::EncoderMatrix
+ expected_b_format_encoder_matrix =
+ GenerateThirdOrderBFormatEncoderMatrix(kSphericalAngle);
+ const AmbisonicCodecImpl<>::EncodedVector expected_encoded_vector =
+ static_cast<AmbisonicCodecImpl<>::EncodedVector>(
+ expected_b_format_encoder_matrix * kUnencodedVector);
+ ASSERT_TRUE(
+ codec_encoded_vector.isApprox(expected_encoded_vector, kEpsilonFloat))
+ << "Codec encoded vector: \n"
+ << codec_encoded_vector << "\n should be within " << kEpsilonFloat
+ << " of expected: \n"
+ << expected_encoded_vector;
+ }
+ }
+}
+
+// Tests that Sphere16 decoding matrix (ACN/SN3D) coefficients produced by
+// Codec
+// are correct.
+TEST_F(AmbisonicCodecTest, Sphere16DecoderCoefficients) {
+ // Expected decoder coefficients for the Sphere16 setup (ACN/SN3D) obtained
+ // using //matlab/ambix/ambdecodematrix.m.
+ const std::vector<float> kExpectedDecoderCoefficients{
+ 0.0625000000000001f, 0.0625000000000000f, 0.0625000000000000f,
+ 0.0625000000000000f, 0.0625000000000000f, 0.0625000000000000f,
+ 0.0625000000000000f, 0.0625000000000000f, 0.0625000000000000f,
+ 0.0625000000000000f, 0.0625000000000000f, 0.0625000000000000f,
+ 0.0625000000000000f, 0.0625000000000000f, 0.0625000000000000f,
+ 0.0625000000000000f, -1.94257951433956e-17f, 0.128971506904330f,
+ 0.182393254223798f, 0.128971506904330f, 1.73262494006158e-16f,
+ -0.128971506904330f, -0.182393254223798f, -0.128971506904330f,
+ -2.79581233842125e-16f, 0.116817928199481f, -1.55203460683255e-16f,
+ -0.116817928199482f, 0.0826027491940168f, 0.0826027491940169f,
+ -0.0826027491940164f, -0.0826027491940165f, -0.0440164745323702f,
+ 0.0440164745323702f, -0.0440164745323703f, 0.0440164745323702f,
+ -0.0440164745323703f, 0.0440164745323702f, -0.0440164745323702f,
+ 0.0440164745323703f, 0.146497161016369f, 0.146497161016369f,
+ 0.146497161016369f, 0.146497161016369f, -0.146497161016369f,
+ -0.146497161016369f, -0.146497161016369f, -0.146497161016369f,
+ 0.182393254223799f, 0.128971506904330f, 7.26758979552257e-17f,
+ -0.128971506904330f, -0.182393254223798f, -0.128971506904330f,
+ -5.02371557522155e-17f, 0.128971506904330f, 0.116817928199482f,
+ 6.83999538850465e-17f, -0.116817928199482f, -3.47728677633385e-17f,
+ 0.0826027491940167f, -0.0826027491940166f, -0.0826027491940166f,
+ 0.0826027491940166f};
+ const int kAmbisonicOrder = 1;
+ const int kNumChannels = 4;
+ const int kNumVirtualSpeakers = 16;
+ std::vector<SphericalAngle> sphere16_angles{
+ SphericalAngle::FromDegrees(0.0f, -13.6f),
+ SphericalAngle::FromDegrees(45.0f, 13.6f),
+ SphericalAngle::FromDegrees(90.0f, -13.6f),
+ SphericalAngle::FromDegrees(135.0f, 13.6f),
+ SphericalAngle::FromDegrees(180.0f, -13.6f),
+ SphericalAngle::FromDegrees(-135.0f, 13.6f),
+ SphericalAngle::FromDegrees(-90.0f, -13.6f),
+ SphericalAngle::FromDegrees(-45.0f, 13.6f),
+ SphericalAngle::FromDegrees(0.0f, 51.5f),
+ SphericalAngle::FromDegrees(90.0f, 51.5f),
+ SphericalAngle::FromDegrees(180.0f, 51.5f),
+ SphericalAngle::FromDegrees(-90.0f, 51.5f),
+ SphericalAngle::FromDegrees(45.0f, -51.5f),
+ SphericalAngle::FromDegrees(135.0f, -51.5f),
+ SphericalAngle::FromDegrees(-135.0f, -51.5f),
+ SphericalAngle::FromDegrees(-45.0f, -51.5f)};
+
+ std::unique_ptr<AmbisonicCodecImpl<>> codec_first_order_sphere16(
+ new AmbisonicCodecImpl<>(kAmbisonicOrder, sphere16_angles));
+ const AmbisonicCodecImpl<>::DecoderMatrix decoder_matrix =
+ codec_first_order_sphere16->GetDecoderMatrix();
+ // Check if the size of the decoding matrix is correct.
+ ASSERT_EQ(decoder_matrix.size(), kNumVirtualSpeakers * kNumChannels);
+ // Check each coefficient against MATLAB.
+ for (size_t i = 0; i < kExpectedDecoderCoefficients.size(); ++i) {
+ EXPECT_NEAR(kExpectedDecoderCoefficients[i], decoder_matrix(i),
+ kEpsilonFloat);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table.cc
new file mode 100644
index 000000000..2a2bc1b68
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table.cc
@@ -0,0 +1,231 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/ambisonic_lookup_table.h"
+
+#include "ambisonics/ambisonic_spread_coefficients.h"
+#include "ambisonics/associated_legendre_polynomials_generator.h"
+#include "ambisonics/utils.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+
+
+namespace vraudio {
+
+namespace {
+
+// Number of azimuth angles to store in the pre-computed encoder lookup table
+// (for 0 - 90 degrees using 1 degree increments).
+const size_t kNumAzimuths = 91;
+
+// Number of elevation angles to store in the pre-computed encoder lookup table
+// (for 0 - 90 degrees using 1 degree increments).
+const size_t kNumElevations = 91;
+
+// Number of Cartesian axes for which to compute spherical harmonic symmetries.
+const size_t kNumAxes = 3;
+
+// Minimum angular source spreads at different orders for which we start to
+// apply spread gain correction coefficients. Array index corresponds to
+// ambisonic order. For more information about sound source spread control,
+// please refer to the Matlab code and the corresponding paper.
+const int kMinSpreads[kMaxSupportedAmbisonicOrder + 1] = {361, 54, 40, 31};
+
+// Spread coefficients are stored sequentially in a 1-d table. Therefore, to
+// access coefficients for the required ambisonic order we need to apply offsets
+// which are equal to the total number of coefficients for previous orders. For
+// example, the total number of coefficient in each ambisonic order 'n' is
+// equal to the number of unique orders multiplied by number of unique spreads,
+// i.e.: (n + 1) * (360 - kMinSpreads[n] + 1).
+const int kSpreadCoeffOffsets[kMaxSupportedAmbisonicOrder + 1] = {0, 1, 615,
+ 1578};
+
+size_t GetEncoderTableIndex(size_t i, size_t j, size_t k, size_t width,
+ size_t depth) {
+ return i * width * depth + j * depth + k;
+}
+
+size_t GetSymmetriesTableIndex(size_t i, size_t j, size_t width) {
+ return i * width + j;
+}
+
+int GetSpreadTableIndex(int ambisonic_order, float source_spread_deg) {
+ // Number of unique ambisonic orders in the sound field. For example, in a
+ // first order sound field we have components of order 0 and 1.
+ const int num_unique_orders = ambisonic_order + 1;
+ return kSpreadCoeffOffsets[ambisonic_order] +
+ num_unique_orders * (static_cast<int>(source_spread_deg) -
+ kMinSpreads[ambisonic_order]);
+}
+
+} // namespace
+
+AmbisonicLookupTable::AmbisonicLookupTable(int max_ambisonic_order)
+ : max_ambisonic_order_(max_ambisonic_order),
+ max_num_coeffs_in_table_(
+ GetNumPeriphonicComponents(max_ambisonic_order_) - 1),
+ encoder_table_(kNumAzimuths * kNumElevations * max_num_coeffs_in_table_),
+ symmetries_table_(kNumAxes * max_num_coeffs_in_table_) {
+ DCHECK_GE(max_ambisonic_order_, 0);
+ DCHECK_LE(max_ambisonic_order_, kMaxSupportedAmbisonicOrder);
+ ComputeEncoderTable();
+ ComputeSymmetriesTable();
+}
+
+void AmbisonicLookupTable::GetEncodingCoeffs(
+ int ambisonic_order, const SphericalAngle& source_direction,
+ float source_spread_deg, std::vector<float>* encoding_coeffs) const {
+
+ DCHECK_GE(ambisonic_order, 0);
+ DCHECK_LE(ambisonic_order, kMaxSupportedAmbisonicOrder);
+ DCHECK_GE(source_spread_deg, 0.0f);
+ DCHECK_LE(source_spread_deg, 360.0f);
+ DCHECK(encoding_coeffs);
+ // Raw coefficients are stored only for ambisonic orders 1 and up, since 0th
+ // order raw coefficient is always 1.
+ const size_t num_raw_coeffs = GetNumPeriphonicComponents(ambisonic_order) - 1;
+ // The actual number of returned Ambisonic coefficients is therefore
+ // |num_raw_coeffs + 1|.
+ DCHECK_EQ(encoding_coeffs->size(), num_raw_coeffs + 1);
+ DCHECK_GE(source_direction.azimuth(), -kPi);
+ DCHECK_LE(source_direction.azimuth(), kTwoPi);
+ DCHECK_GE(source_direction.elevation(), -kHalfPi);
+ DCHECK_LE(source_direction.elevation(), kHalfPi);
+ const int azimuth_deg =
+ source_direction.azimuth() < kPi
+ ? static_cast<int>(source_direction.azimuth() * kDegreesFromRadians)
+ : static_cast<int>(source_direction.azimuth() * kDegreesFromRadians) -
+ 360;
+ const int elevation_deg =
+ static_cast<int>(source_direction.elevation() * kDegreesFromRadians);
+ const size_t abs_azimuth_deg = static_cast<size_t>(std::abs(azimuth_deg));
+ const size_t azimuth_idx =
+ abs_azimuth_deg > 90 ? 180 - abs_azimuth_deg : abs_azimuth_deg;
+ const size_t elevation_idx = static_cast<size_t>(std::abs(elevation_deg));
+ (*encoding_coeffs)[0] = 1.0f;
+ for (size_t raw_coeff_idx = 0; raw_coeff_idx < num_raw_coeffs;
+ ++raw_coeff_idx) {
+ // Variable to hold information about spherical harmonic phase flip. 1 means
+ // no flip; -1 means 180 degrees flip.
+ float flip = 1.0f;
+ // The following three 'if' statements implement the logic to correct the
+ // phase of the current spherical harmonic, depending on which quadrant the
+ // sound source is located in. For more information, please see the Matlab
+ // code and the corresponding paper.
+ if (azimuth_deg < 0) {
+ flip = symmetries_table_[GetSymmetriesTableIndex(
+ 0, raw_coeff_idx, max_num_coeffs_in_table_)];
+ }
+ if (elevation_deg < 0) {
+ flip *= symmetries_table_[GetSymmetriesTableIndex(
+ 1, raw_coeff_idx, max_num_coeffs_in_table_)];
+ }
+ if (abs_azimuth_deg > 90) {
+ flip *= symmetries_table_[GetSymmetriesTableIndex(
+ 2, raw_coeff_idx, max_num_coeffs_in_table_)];
+ }
+ const size_t encoder_table_idx =
+ GetEncoderTableIndex(azimuth_idx, elevation_idx, raw_coeff_idx,
+ kNumElevations, max_num_coeffs_in_table_);
+ (*encoding_coeffs)[raw_coeff_idx + 1] =
+ encoder_table_[encoder_table_idx] * flip;
+ }
+
+ // If the spread is more than min. theoretical spread for the given
+ // |ambisonic_order|, multiply the encoding coefficients by the required
+ // spread control gains from the |kSpreadCoeffs| lookup table.
+ if (source_spread_deg >= kMinSpreads[ambisonic_order]) {
+ const int spread_table_idx =
+ GetSpreadTableIndex(ambisonic_order, source_spread_deg);
+ (*encoding_coeffs)[0] *= kSpreadCoeffs[spread_table_idx];
+ for (size_t coeff = 1; coeff < encoding_coeffs->size(); ++coeff) {
+ const int current_coefficient_degree =
+ GetPeriphonicAmbisonicOrderForChannel(coeff);
+ (*encoding_coeffs)[coeff] *=
+ kSpreadCoeffs[spread_table_idx + current_coefficient_degree];
+ }
+ }
+}
+
+void AmbisonicLookupTable::ComputeEncoderTable() {
+
+ // Associated Legendre polynomial generator.
+ AssociatedLegendrePolynomialsGenerator alp_generator(
+ max_ambisonic_order_, /*condon_shortley_phase=*/false,
+ /*compute_negative_order=*/false);
+ // Temporary storage for associated Legendre polynomials generated.
+ std::vector<float> temp_associated_legendre_polynomials;
+ for (size_t azimuth_idx = 0; azimuth_idx < kNumAzimuths; ++azimuth_idx) {
+ for (size_t elevation_idx = 0; elevation_idx < kNumElevations;
+ ++elevation_idx) {
+ const SphericalAngle angle(
+ static_cast<float>(azimuth_idx) * kRadiansFromDegrees,
+ static_cast<float>(elevation_idx) * kRadiansFromDegrees);
+ temp_associated_legendre_polynomials =
+ alp_generator.Generate(std::sin(angle.elevation()));
+ // First spherical harmonic is always equal 1 for all angles so we do not
+ // need to compute and store it.
+ for (int degree = 1; degree <= max_ambisonic_order_; ++degree) {
+ for (int order = -degree; order <= degree; ++order) {
+ const size_t alp_index =
+ alp_generator.GetIndex(degree, std::abs(order));
+ const float alp_value =
+ temp_associated_legendre_polynomials[alp_index];
+ const size_t raw_coeff_idx = AcnSequence(degree, order) - 1;
+ const size_t encoder_table_idx =
+ GetEncoderTableIndex(azimuth_idx, elevation_idx, raw_coeff_idx,
+ kNumElevations, max_num_coeffs_in_table_);
+ encoder_table_[encoder_table_idx] =
+ Sn3dNormalization(degree, order) *
+ UnnormalizedSphericalHarmonic(alp_value, order, angle.azimuth());
+ }
+ }
+ }
+ }
+}
+
+void AmbisonicLookupTable::ComputeSymmetriesTable() {
+
+ for (int degree = 1; degree <= max_ambisonic_order_; ++degree) {
+ for (int order = -degree; order <= degree; ++order) {
+ const size_t raw_coeff_idx = AcnSequence(degree, order) - 1;
+ // Symmetry wrt the left-right axis (Y).
+ symmetries_table_[GetSymmetriesTableIndex(0, raw_coeff_idx,
+ max_num_coeffs_in_table_)] =
+ order < 0 ? -1.0f : 1.0f;
+ // Symmetry wrt the up-down axis (Z).
+ symmetries_table_[GetSymmetriesTableIndex(1, raw_coeff_idx,
+ max_num_coeffs_in_table_)] =
+ static_cast<float>(IntegerPow(-1, degree + order));
+ // Symmetry wrt the front-back axis (X).
+ symmetries_table_[GetSymmetriesTableIndex(2, raw_coeff_idx,
+ max_num_coeffs_in_table_)] =
+ order < 0 ? static_cast<float>(-IntegerPow(-1, std::abs(order)))
+ : static_cast<float>(IntegerPow(-1, order));
+ }
+ }
+}
+
+float AmbisonicLookupTable::UnnormalizedSphericalHarmonic(float alp_value,
+ int order,
+ float azimuth_rad) {
+ const float horizontal_term =
+ (order >= 0) ? std::cos(static_cast<float>(order) * azimuth_rad)
+ : std::sin(static_cast<float>(-order) * azimuth_rad);
+ return alp_value * horizontal_term;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table.h b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table.h
new file mode 100644
index 000000000..096068d0a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table.h
@@ -0,0 +1,92 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_AMBISONICS_AMBISONIC_LOOKUP_TABLE_H_
+#define RESONANCE_AUDIO_AMBISONICS_AMBISONIC_LOOKUP_TABLE_H_
+
+#include <vector>
+
+#include "base/spherical_angle.h"
+
+namespace vraudio {
+
+// Represents a lookup table for encoding of Ambisonic periphonic sound fields.
+// Supports arbitrary Ambisonic order and uses AmbiX convention (ACN channel
+// sequencing, SN3D normalization).
+class AmbisonicLookupTable {
+ public:
+ // Creates Ambisonic (AmbiX) encoder lookup table given the
+ // |max_ambisonic_order| used by the client. AmbiX convention uses ACN channel
+ // sequencing and SN3D normalization.
+ explicit AmbisonicLookupTable(int max_ambisonic_order);
+
+ // Gets spherical harmonic encoding coefficients for a given order and
+ // writes them to |encoding_coeffs|.
+ //
+ // @param ambisonic_order Ambisonic order of the encoded sound source.
+ // @param source_direction Direction of a sound source in spherical
+ // coordinates.
+ // @param source_spread_deg Encoded sound source angular spread in degrees.
+ // @param encoding_coeffs Pointer to a vector of Ambisonic encoding
+ // coefficients.
+ void GetEncodingCoeffs(int ambisonic_order,
+ const SphericalAngle& source_direction,
+ float source_spread_deg,
+ std::vector<float>* encoding_coeffs) const;
+
+ private:
+ // Computes a lookup table of encoding coefficients for one quadrant of the
+ // sphere.
+ void ComputeEncoderTable();
+
+ // Computes a table of spherical harmonics symmetry information for all
+ // cartesian axes. Value of 1 indicates that the current spherical harmonic is
+ // symmetric with respect to the current axis. Value of -1 indicates that the
+ // current spherical harmonic is anti-symmetric with respect to the current
+ // axis.
+ void ComputeSymmetriesTable();
+
+ // Returns the unnormalized spherical harmonic coefficient:
+ // Y_degree^order(azimuth, elevation).
+ //
+ // @param alp_value Associated Legendre polynomial for the given degree and
+ // order evaluated at sin elevation angle: P_degree^order(sin(elevation)).
+ // @param order Order of the Associated Legendre polynomial.
+ // @param azimuth_rad Azimuth angle in radians.
+ // @return Unnormalized spherical harmonic coefficient.
+ float UnnormalizedSphericalHarmonic(float alp_value, int order,
+ float azimuth_rad);
+
+ // Ambisonic order.
+ const int max_ambisonic_order_;
+
+ // Maximum number of coefficients to be stored in the lookup table equal to
+ // the number of Ambisonic channels for |max_ambisonic_order_| - 1. This is
+ // because we do not need to store the coefficient for the first spherical
+ // harmonic coefficient as it is always 1.
+ const size_t max_num_coeffs_in_table_;
+
+ // Lookup table for storing Ambisonic encoding coefficients for one quadrant
+ // of the sphere.
+ std::vector<float> encoder_table_;
+
+ // Lookup table for storing information about spherical harmonic symmetries.
+ std::vector<float> symmetries_table_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_AMBISONICS_AMBISONIC_LOOKUP_TABLE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table_test.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table_test.cc
new file mode 100644
index 000000000..8f0c9c9a6
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_lookup_table_test.cc
@@ -0,0 +1,240 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/ambisonic_lookup_table.h"
+
+#include <cmath>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "ambisonics/utils.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+namespace {
+
+const int kSourceAmbisonicOrder0 = 0;
+const int kSourceAmbisonicOrder1 = 1;
+const int kSourceAmbisonicOrder2 = 2;
+const int kSourceAmbisonicOrder3 = 3;
+
+// Minimum angular source spread of 0 ensures that no gain correction
+// coefficients should be applied to the Ambisonic encoding coefficients.
+const float kMinSpreadDeg = 0.0f;
+
+} // namespace
+
+class AmbisonicLookupTableTest : public ::testing::TestWithParam<int> {
+ protected:
+ AmbisonicLookupTableTest()
+ : lookup_table_(kMaxSupportedAmbisonicOrder),
+ source_ambisonic_order_(GetParam()),
+ encoding_coeffs_(GetNumPeriphonicComponents(source_ambisonic_order_)) {}
+
+ // Tests whether GetEncodingCoeffs() method returns correct coefficients.
+ void TestEncodingCoefficients() {
+ for (size_t i = 0; i < kSourceDirections.size(); ++i) {
+ const std::vector<float> kExpectedCoeffs =
+ GenerateExpectedCoeffs(kSourceDirections[i]);
+ lookup_table_.GetEncodingCoeffs(source_ambisonic_order_,
+ kSourceDirections[i], kMinSpreadDeg,
+ &encoding_coeffs_);
+ for (size_t j = 0; j < encoding_coeffs_.size(); ++j) {
+ EXPECT_NEAR(kExpectedCoeffs[j], encoding_coeffs_[j], kEpsilonFloat);
+ }
+ }
+ }
+
+ // Tests whether changing the source spread results in correct gain changes in
+ // pressure and velocity ambisonic encoding coefficients.
+ void TestSpreadEnergy() {
+ // Choose an artbitrary source direction from |kSourceDirections|.
+ const SphericalAngle source_direction = kSourceDirections.back();
+ lookup_table_.GetEncodingCoeffs(source_ambisonic_order_, source_direction,
+ kMinSpreadDeg, &encoding_coeffs_);
+ float current_pressure_energy = GetPressureEnergy();
+ float current_velocity_energy = GetVelocityEnergy();
+ for (int spread_deg = 1; spread_deg <= 360; ++spread_deg) {
+ lookup_table_.GetEncodingCoeffs(source_ambisonic_order_, source_direction,
+ static_cast<float>(spread_deg),
+ &encoding_coeffs_);
+ float new_pressure_energy = GetPressureEnergy();
+ float new_velocity_energy = GetVelocityEnergy();
+ EXPECT_TRUE(new_pressure_energy >= current_pressure_energy);
+ EXPECT_TRUE(new_velocity_energy <= current_velocity_energy);
+ current_pressure_energy = new_pressure_energy;
+ current_velocity_energy = new_velocity_energy;
+ }
+ }
+
+ private:
+ // Generates expected ambisonic encoding coefficients for ambisonic orders 0
+ // to 3, according to http://ambisonics.ch/standards/channels/index.
+ std::vector<float> GenerateExpectedCoeffs(const SphericalAngle& angle) {
+ const float a = angle.azimuth();
+ const float e = angle.elevation();
+ return std::vector<float>{
+ 1.0f,
+ std::cos(e) * std::sin(a),
+ std::sin(e),
+ std::cos(e) * std::cos(a),
+ kSqrtThree / 2.0f * std::cos(e) * std::cos(e) * std::sin(2.0f * a),
+ kSqrtThree / 2.0f * std::sin(2.0f * e) * std::sin(a),
+ 0.5f * (3.0f * std::sin(e) * std::sin(e) - 1.0f),
+ kSqrtThree / 2.0f * std::sin(2.0f * e) * std::cos(a),
+ kSqrtThree / 2.0f * std::cos(e) * std::cos(e) * std::cos(2.0f * a),
+ std::sqrt(5.0f / 8.0f) * IntegerPow(std::cos(e), 3) *
+ std::sin(3.0f * a),
+ std::sqrt(15.0f) / 2.0f * std::sin(e) * std::cos(e) * std::cos(e) *
+ std::sin(2.0f * a),
+ std::sqrt(3.0f / 8.0f) * std::cos(e) *
+ (5.0f * std::sin(e) * std::sin(e) - 1.0f) * std::sin(a),
+ 0.5f * std::sin(e) * (5.0f * std::sin(e) * std::sin(e) - 3.0f),
+ std::sqrt(3.0f / 8.0f) * std::cos(e) *
+ (5.0f * std::sin(e) * std::sin(e) - 1.0f) * std::cos(a),
+ std::sqrt(15.0f) / 2.0f * std::sin(e) * std::cos(e) * std::cos(e) *
+ std::cos(2.0f * a),
+ std::sqrt(5.0f / 8.0f) * IntegerPow(std::cos(e), 3) *
+ std::cos(3.0f * a)};
+ }
+
+ // Computes energy of the pressure channel (Ambisonic channel 0).
+ float GetPressureEnergy() {
+ return encoding_coeffs_[0] * encoding_coeffs_[0];
+ }
+
+ // Computes total energy of all the velocity channels (Ambisonic channel 1 and
+ // above).
+ float GetVelocityEnergy() {
+ float velocity_energy = 0.0f;
+ for (size_t i = 1; i < encoding_coeffs_.size(); ++i) {
+ velocity_energy += encoding_coeffs_[i] * encoding_coeffs_[i];
+ }
+ return velocity_energy;
+ }
+
+ // Source angles corresponding to each Cartesian axis direction as well as
+ // some arbitrary directions (full degrees) in each quadrant of the sphere.
+ const std::vector<SphericalAngle> kSourceDirections = {
+ {SphericalAngle::FromDegrees(0.0f, 0.0f)} /* Front */,
+ {SphericalAngle::FromDegrees(90.0f, 0.0f)} /* Left */,
+ {SphericalAngle::FromDegrees(180.0f, 0.0f)} /* Back */,
+ {SphericalAngle::FromDegrees(-90.0f, 0.0f)} /* Right */,
+ {SphericalAngle::FromDegrees(0.0f, 90.0f)} /* Up */,
+ {SphericalAngle::FromDegrees(0.0f, -90.0f)} /* Down */,
+ {SphericalAngle::FromDegrees(10.0f, 20.0f)} /* Left-Top-Front */,
+ {SphericalAngle::FromDegrees(-30.0f, 40.0f)} /* Right-Top-Front */,
+ {SphericalAngle::FromDegrees(50.0f, -60.0f)} /* Left-Bottom-Front */,
+ {SphericalAngle::FromDegrees(290.0f, -80.0f)} /* Right-Bottom-Front */,
+ {SphericalAngle::FromDegrees(110.0f, 5.0f)} /* Left-Top-Back */,
+ {SphericalAngle::FromDegrees(-120.0f, 15.0f)} /* Right-Top-Back */,
+ {SphericalAngle::FromDegrees(130.0f, -25.0f)} /* Left-Bottom-Back */,
+ {SphericalAngle::FromDegrees(220.0f, -35.0f)} /* Right-Bottom-Back */,
+ };
+
+ AmbisonicLookupTable lookup_table_;
+ const int source_ambisonic_order_;
+ std::vector<float> encoding_coeffs_;
+};
+
+// Tests whether GetEncodingCoeffs() method returns correct coefficients.
+TEST_P(AmbisonicLookupTableTest, GetEncodingCoeffsTest) {
+ TestEncodingCoefficients();
+}
+
+// Tests whether changing the source spread results in correct gain changes in
+// pressure and velocity ambisonic encoding coefficients. For example,
+// increasing of the source spread should result in overall monotonic increase
+// of energy in the pressure channel and overall monotonic decrease in the
+// velocity channels.
+TEST_P(AmbisonicLookupTableTest, SpreadEnergyTest) { TestSpreadEnergy(); }
+
+INSTANTIATE_TEST_CASE_P(TestParameters, AmbisonicLookupTableTest,
+ testing::Values(kSourceAmbisonicOrder0,
+ kSourceAmbisonicOrder1,
+ kSourceAmbisonicOrder2,
+ kSourceAmbisonicOrder3));
+
+class PreComputedCoeffsTest : public ::testing::Test {
+ protected:
+ // Tests whether the lookup table returns correct coefficients for sources
+ // with arbitrary ambisonic order, direction and spread.
+ void TestSpreadCoefficients() {
+ // Test spread coefficients for each config.
+ for (const auto& config : kConfigs) {
+ const int source_ambisonic_order = config.source_ambisonic_order;
+ const SphericalAngle& source_direction = config.source_direction;
+ const float source_spread_deg = config.source_spread_deg;
+ const std::vector<float>& expected_coeffs = config.expected_coefficients;
+ std::vector<float> encoding_coeffs(
+ GetNumPeriphonicComponents(source_ambisonic_order));
+ AmbisonicLookupTable lookup_table(kMaxSupportedAmbisonicOrder);
+ lookup_table.GetEncodingCoeffs(source_ambisonic_order, source_direction,
+ source_spread_deg, &encoding_coeffs);
+ for (size_t i = 0; i < encoding_coeffs.size(); ++i) {
+ EXPECT_NEAR(expected_coeffs[i], encoding_coeffs[i], kEpsilonFloat);
+ }
+ }
+ }
+
+ private:
+ struct TestConfig {
+ int source_ambisonic_order;
+ SphericalAngle source_direction;
+ float source_spread_deg;
+ std::vector<float> expected_coefficients;
+ };
+
+ const std::vector<TestConfig> kConfigs = {
+ // Zeroth order sound source.
+ {0 /* ambisonic order */,
+ SphericalAngle::FromDegrees(0.0f, 0.0f) /* source direction */,
+ 120.0f /* source spread */,
+ {1.0f} /* expected coefficients */},
+
+ // First order sound source.
+ {1 /* ambisonic order */,
+ SphericalAngle::FromDegrees(36.0f, 45.0f) /* source direction */,
+ 70.0f /* source spread */,
+ {1.20046f, 0.310569f, 0.528372f, 0.427462f}
+ /* expected coefficients */},
+
+ // Second order sound source.
+ {2 /* ambisonic order */,
+ SphericalAngle::FromDegrees(55.0f, -66.0f) /* source direction */,
+ 41.0f /* source spread */,
+ {1.038650f, 0.337027f, -0.924096f, 0.2359899f, 0.124062f, -0.485807f,
+ 0.6928289f, -0.340166f, -0.045155f}
+ /* expected coefficients */},
+
+ // Third order sound source.
+ {3 /* ambisonic order */,
+ SphericalAngle::FromDegrees(-13.0f, 90.0f) /* source direction */,
+ 32.0f /* source spread */,
+ {1.03237f, 0.0f, 1.02119f, 0.0f, 0.0f, 0.0f, 0.990433f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.898572f, 0.0f, 0.0f, 0.0f}
+ /* expected coefficients */}};
+};
+
+// Tests whether the lookup table returns correct coefficients for sources with
+// arbitrary ambisonic order, direction and spread. The expected coefficients
+// have been pre-computed using Matlab.
+TEST_F(PreComputedCoeffsTest, SpreadCoefficientsTest) {
+ TestSpreadCoefficients();
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_spread_coefficients.h b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_spread_coefficients.h
new file mode 100644
index 000000000..0c245b87f
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/ambisonic_spread_coefficients.h
@@ -0,0 +1,610 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_AMBISONICS_AMBISONIC_SPREAD_COEFFICIENTS_H_
+#define RESONANCE_AUDIO_AMBISONICS_AMBISONIC_SPREAD_COEFFICIENTS_H_
+
+namespace vraudio {
+
+// Lookup table with gain coefficients to control Ambisonic sound source spread
+// at different orders, up to and including order 3. For information on how the
+// spread control coefficients have been derived please refer to Matlab code as
+// well as the corresponding paper.
+static const float kSpreadCoeffs[5089] = {
+ 1.0f, 1.0019f, 0.998092f, 1.01441f, 0.985357f,
+ 1.02704f, 0.972176f, 1.03975f, 0.958555f, 1.05252f,
+ 0.944499f, 1.06532f, 0.930017f, 1.07813f, 0.915119f,
+ 1.09091f, 0.899819f, 1.10365f, 0.884131f, 1.11631f,
+ 0.868073f, 1.12886f, 0.851665f, 1.14128f, 0.834929f,
+ 1.15354f, 0.817888f, 1.16561f, 0.800569f, 1.17747f,
+ 0.782999f, 1.1891f, 0.76521f, 1.20046f, 0.747231f,
+ 1.21155f, 0.729095f, 1.22234f, 0.710837f, 1.23281f,
+ 0.692489f, 1.24296f, 0.674086f, 1.25276f, 0.655664f,
+ 1.26221f, 0.637256f, 1.27131f, 0.618896f, 1.28003f,
+ 0.600619f, 1.28839f, 0.582456f, 1.29637f, 0.564439f,
+ 1.30399f, 0.546597f, 1.31123f, 0.528959f, 1.31811f,
+ 0.511551f, 1.32463f, 0.494397f, 1.3308f, 0.47752f,
+ 1.33663f, 0.46094f, 1.34212f, 0.444677f, 1.34729f,
+ 0.428746f, 1.35214f, 0.413161f, 1.3567f, 0.397935f,
+ 1.36096f, 0.383079f, 1.36495f, 0.3686f, 1.36867f,
+ 0.354505f, 1.37215f, 0.340799f, 1.37538f, 0.327486f,
+ 1.37839f, 0.314566f, 1.38118f, 0.302039f, 1.38378f,
+ 0.289906f, 1.38618f, 0.278163f, 1.38841f, 0.266808f,
+ 1.39047f, 0.255835f, 1.39238f, 0.24524f, 1.39414f,
+ 0.235017f, 1.39576f, 0.225159f, 1.39726f, 0.21566f,
+ 1.39864f, 0.206511f, 1.39991f, 0.197704f, 1.40108f,
+ 0.189232f, 1.40215f, 0.181084f, 1.40314f, 0.173254f,
+ 1.40405f, 0.165731f, 1.40488f, 0.158507f, 1.40565f,
+ 0.151572f, 1.40635f, 0.144918f, 1.40699f, 0.138535f,
+ 1.40758f, 0.132414f, 1.40812f, 0.126546f, 1.40861f,
+ 0.120923f, 1.40906f, 0.115536f, 1.40947f, 0.110376f,
+ 1.40985f, 0.105436f, 1.4102f, 0.100705f, 1.41051f,
+ 0.0961781f, 1.4108f, 0.0918459f, 1.41107f, 0.087701f,
+ 1.41131f, 0.0837362f, 1.41153f, 0.0799443f, 1.41173f,
+ 0.0763185f, 1.41191f, 0.0728519f, 1.41208f, 0.069538f,
+ 1.41223f, 0.0663707f, 1.41237f, 0.0633438f, 1.41249f,
+ 0.0604515f, 1.41261f, 0.0576881f, 1.41271f, 0.0550481f,
+ 1.41281f, 0.0525264f, 1.4129f, 0.0501178f, 1.41298f,
+ 0.0478176f, 1.41305f, 0.045621f, 1.41312f, 0.0435236f,
+ 1.41318f, 0.0415211f, 1.41323f, 0.0396092f, 1.41328f,
+ 0.0377841f, 1.41333f, 0.0360419f, 1.41337f, 0.034379f,
+ 1.4134f, 0.0327918f, 1.41344f, 0.031277f, 1.41347f,
+ 0.0298315f, 1.4135f, 0.028452f, 1.41352f, 0.0271356f,
+ 1.41355f, 0.0258796f, 1.41357f, 0.0246811f, 1.41359f,
+ 0.0235377f, 1.41361f, 0.0224468f, 1.41362f, 0.0214061f,
+ 1.41364f, 0.0204132f, 1.41365f, 0.0194661f, 1.41366f,
+ 0.0185626f, 1.41367f, 0.0177008f, 1.41368f, 0.0168787f,
+ 1.41369f, 0.0160946f, 1.4137f, 0.0153468f, 1.41371f,
+ 0.0146335f, 1.41372f, 0.0139531f, 1.41372f, 0.0133043f,
+ 1.41373f, 0.0126855f, 1.41373f, 0.0120953f, 1.41374f,
+ 0.0115325f, 1.41374f, 0.0109958f, 1.41375f, 0.0104839f,
+ 1.41375f, 0.00999584f, 1.41375f, 0.00953039f, 1.41376f,
+ 0.00908654f, 1.41376f, 0.0086633f, 1.41376f, 0.00825972f,
+ 1.41376f, 0.00787488f, 1.41376f, 0.00750793f, 1.41377f,
+ 0.00715803f, 1.41377f, 0.0068244f, 1.41377f, 0.00650628f,
+ 1.41377f, 0.00620296f, 1.41377f, 0.00591376f, 1.41377f,
+ 0.00563801f, 1.41377f, 0.00537509f, 1.41378f, 0.00512441f,
+ 1.41378f, 0.0048854f, 1.41378f, 0.00465752f, 1.41378f,
+ 0.00444026f, 1.41378f, 0.00423311f, 1.41378f, 0.00403562f,
+ 1.41378f, 0.00384732f, 1.41378f, 0.0036678f, 1.41378f,
+ 0.00349665f, 1.41378f, 0.00333348f, 1.41378f, 0.00317791f,
+ 1.41378f, 0.00302959f, 1.41378f, 0.00288819f, 1.41378f,
+ 0.00275338f, 1.41378f, 0.00262486f, 1.41378f, 0.00250233f,
+ 1.41378f, 0.00238552f, 1.41378f, 0.00227415f, 1.41378f,
+ 0.00216798f, 1.41378f, 0.00206677f, 1.41378f, 0.00197027f,
+ 1.41378f, 0.00187828f, 1.41378f, 0.00179058f, 1.41378f,
+ 0.00170697f, 1.41378f, 0.00162727f, 1.41378f, 0.00155128f,
+ 1.41378f, 0.00147884f, 1.41378f, 0.00140979f, 1.41378f,
+ 0.00134395f, 1.41378f, 0.00128119f, 1.41378f, 0.00122136f,
+ 1.41378f, 0.00116432f, 1.41378f, 0.00110994f, 1.41378f,
+ 0.0010581f, 1.41378f, 0.00100869f, 1.41378f, 0.000961575f,
+ 1.41378f, 0.000916665f, 1.41378f, 0.000873851f, 1.41378f,
+ 0.000833036f, 1.41378f, 0.000794127f, 1.41378f, 0.000757035f,
+ 1.41378f, 0.000721675f, 1.41378f, 0.000687966f, 1.41378f,
+ 0.000655831f, 1.41378f, 0.000625197f, 1.41378f, 0.000595994f,
+ 1.41378f, 0.000568154f, 1.41378f, 0.000541615f, 1.41378f,
+ 0.000516315f, 1.41378f, 0.000492197f, 1.41378f, 0.000469205f,
+ 1.41378f, 0.000447287f, 1.41378f, 0.000426393f, 1.41378f,
+ 0.000406474f, 1.41378f, 0.000387486f, 1.41378f, 0.000369385f,
+ 1.41378f, 0.000352129f, 1.41378f, 0.00033568f, 1.41378f,
+ 0.000319998f, 1.41378f, 0.00030505f, 1.41378f, 0.000290799f,
+ 1.41378f, 0.000277214f, 1.41378f, 0.000264264f, 1.41378f,
+ 0.000251918f, 1.41378f, 0.00024015f, 1.41378f, 0.000228931f,
+ 1.41378f, 0.000218236f, 1.41378f, 0.000208041f, 1.41378f,
+ 0.000198322f, 1.41378f, 0.000189056f, 1.41378f, 0.000180224f,
+ 1.41378f, 0.000171805f, 1.41378f, 0.000163778f, 1.41378f,
+ 0.000156127f, 1.41378f, 0.000148833f, 1.41378f, 0.00014188f,
+ 1.41378f, 0.000135252f, 1.41378f, 0.000128933f, 1.41378f,
+ 0.000122909f, 1.41378f, 0.000117167f, 1.41378f, 0.000111693f,
+ 1.41378f, 0.000106475f, 1.41378f, 0.000101501f, 1.41378f,
+ 9.67588e-05f, 1.41378f, 9.22384e-05f, 1.41378f, 8.79291e-05f,
+ 1.41378f, 8.38211e-05f, 1.41378f, 7.99051e-05f, 1.41378f,
+ 7.6172e-05f, 1.41378f, 7.26133e-05f, 1.41378f, 6.92209e-05f,
+ 1.41378f, 6.5987e-05f, 1.41378f, 6.29041e-05f, 1.41378f,
+ 5.99653e-05f, 1.41378f, 5.71637e-05f, 1.41378f, 5.44931e-05f,
+ 1.41378f, 5.19472e-05f, 1.41378f, 4.95202e-05f, 1.41378f,
+ 4.72067e-05f, 1.41378f, 4.50012e-05f, 1.41378f, 4.28988e-05f,
+ 1.41378f, 4.08946e-05f, 1.41378f, 3.8984e-05f, 1.41378f,
+ 3.71627e-05f, 1.41378f, 3.54264e-05f, 1.41378f, 3.37713e-05f,
+ 1.41378f, 3.21935e-05f, 1.41378f, 3.06895e-05f, 1.41378f,
+ 2.92557e-05f, 1.41378f, 2.78888e-05f, 1.41378f, 2.65859e-05f,
+ 1.41378f, 2.53438e-05f, 1.41378f, 2.41597e-05f, 1.41378f,
+ 2.3031e-05f, 1.41378f, 2.1955e-05f, 1.41378f, 2.09292e-05f,
+ 1.41378f, 1.99514e-05f, 1.41378f, 1.90193e-05f, 1.41378f,
+ 1.81307e-05f, 1.41378f, 1.72837e-05f, 1.41378f, 1.64762e-05f,
+ 1.41378f, 1.57064e-05f, 1.41378f, 1.49726e-05f, 1.41378f,
+ 1.42731e-05f, 1.41378f, 1.36062e-05f, 1.41378f, 1.29706e-05f,
+ 1.41378f, 1.23646e-05f, 1.41378f, 1.17869e-05f, 1.41378f,
+ 1.12362e-05f, 1.41378f, 1.07113e-05f, 1.41378f, 1.02108e-05f,
+ 1.41378f, 9.73377e-06f, 1.41378f, 9.27901e-06f, 1.41378f,
+ 8.84549e-06f, 1.41378f, 8.43223e-06f, 1.41378f, 8.03827e-06f,
+ 1.41378f, 7.66273e-06f, 1.41378f, 7.30472e-06f, 1.41378f,
+ 6.96344e-06f, 1.41378f, 6.63811e-06f, 1.41378f, 6.32798e-06f,
+ 1.41378f, 6.03233e-06f, 1.41378f, 5.7505e-06f, 1.41378f,
+ 5.48184e-06f, 1.41378f, 5.22572e-06f, 1.41378f, 4.98158e-06f,
+ 1.41378f, 4.74884e-06f, 1.41378f, 4.52697e-06f, 1.41378f,
+ 4.31547e-06f, 1.41378f, 4.11385e-06f, 1.41378f, 3.92165e-06f,
+ 1.41378f, 3.73843e-06f, 1.41378f, 3.56377e-06f, 1.41378f,
+ 3.39727e-06f, 1.41378f, 3.23855e-06f, 1.41378f, 3.08724e-06f,
+ 1.41378f, 2.94301e-06f, 1.41378f, 2.80551e-06f, 1.41378f,
+ 2.67443e-06f, 1.41378f, 2.54948e-06f, 1.41378f, 2.43037e-06f,
+ 1.41378f, 2.31682e-06f, 1.41378f, 2.20858e-06f, 1.41378f,
+ 2.1054e-06f, 1.41378f, 2.00703e-06f, 1.41378f, 1.91326e-06f,
+ 1.41378f, 1.82388e-06f, 1.41378f, 1.73866e-06f, 1.41378f,
+ 1.65743e-06f, 1.41378f, 1.58e-06f, 1.41378f, 1.50618e-06f,
+ 1.41378f, 1.43581e-06f, 1.41378f, 1.36873e-06f, 1.41378f,
+ 1.30478e-06f, 1.41378f, 1.24382e-06f, 1.41378f, 1.18571e-06f,
+ 1.01483f, 1.00465f, 0.970383f, 1.03865f, 1.01155f,
+ 0.9215f, 1.06314f, 1.0179f, 0.869372f, 1.08819f,
+ 1.02356f, 0.813901f, 1.11364f, 1.02839f, 0.755004f,
+ 1.13935f, 1.03225f, 0.692625f, 1.16513f, 1.03497f,
+ 0.626735f, 1.19076f, 1.0364f, 0.557346f, 1.21602f,
+ 1.03638f, 0.484517f, 1.24065f, 1.03474f, 0.408362f,
+ 1.2644f, 1.03133f, 0.329059f, 1.28697f, 1.02601f,
+ 0.246853f, 1.3081f, 1.01866f, 0.162061f, 1.3275f,
+ 1.00918f, 0.0750718f, 1.34495f, 0.99753f, 0.0f,
+ 1.36175f, 0.984802f, 0.0f, 1.37869f, 0.971629f,
+ 0.0f, 1.39575f, 0.958015f, 0.0f, 1.4129f,
+ 0.943967f, 0.0f, 1.43008f, 0.929493f, 0.0f,
+ 1.44728f, 0.914603f, 0.0f, 1.46444f, 0.899312f,
+ 0.0f, 1.48154f, 0.883633f, 0.0f, 1.49853f,
+ 0.867584f, 0.0f, 1.51538f, 0.851185f, 0.0f,
+ 1.53206f, 0.834458f, 0.0f, 1.54851f, 0.817427f,
+ 0.0f, 1.56472f, 0.800117f, 0.0f, 1.58064f,
+ 0.782558f, 0.0f, 1.59624f, 0.764779f, 0.0f,
+ 1.6115f, 0.74681f, 0.0f, 1.62638f, 0.728685f,
+ 0.0f, 1.64086f, 0.710436f, 0.0f, 1.65492f,
+ 0.692098f, 0.0f, 1.66854f, 0.673706f, 0.0f,
+ 1.6817f, 0.655294f, 0.0f, 1.69439f, 0.636896f,
+ 0.0f, 1.7066f, 0.618548f, 0.0f, 1.71831f,
+ 0.600281f, 0.0f, 1.72953f, 0.582128f, 0.0f,
+ 1.74025f, 0.564121f, 0.0f, 1.75047f, 0.546289f,
+ 0.0f, 1.76019f, 0.528661f, 0.0f, 1.76943f,
+ 0.511262f, 0.0f, 1.77819f, 0.494118f, 0.0f,
+ 1.78647f, 0.477251f, 0.0f, 1.79429f, 0.46068f,
+ 0.0f, 1.80166f, 0.444426f, 0.0f, 1.8086f,
+ 0.428504f, 0.0f, 1.81511f, 0.412928f, 0.0f,
+ 1.82123f, 0.397711f, 0.0f, 1.82695f, 0.382863f,
+ 0.0f, 1.8323f, 0.368392f, 0.0f, 1.8373f,
+ 0.354306f, 0.0f, 1.84196f, 0.340607f, 0.0f,
+ 1.84631f, 0.327301f, 0.0f, 1.85035f, 0.314388f,
+ 0.0f, 1.8541f, 0.301869f, 0.0f, 1.85758f,
+ 0.289743f, 0.0f, 1.86081f, 0.278006f, 0.0f,
+ 1.8638f, 0.266657f, 0.0f, 1.86657f, 0.255691f,
+ 0.0f, 1.86912f, 0.245102f, 0.0f, 1.87149f,
+ 0.234885f, 0.0f, 1.87367f, 0.225033f, 0.0f,
+ 1.87568f, 0.215538f, 0.0f, 1.87753f, 0.206394f,
+ 0.0f, 1.87924f, 0.197593f, 0.0f, 1.8808f,
+ 0.189125f, 0.0f, 1.88225f, 0.180982f, 0.0f,
+ 1.88357f, 0.173156f, 0.0f, 1.88479f, 0.165638f,
+ 0.0f, 1.88591f, 0.158418f, 0.0f, 1.88694f,
+ 0.151487f, 0.0f, 1.88788f, 0.144836f, 0.0f,
+ 1.88874f, 0.138457f, 0.0f, 1.88953f, 0.132339f,
+ 0.0f, 1.89025f, 0.126475f, 0.0f, 1.89091f,
+ 0.120855f, 0.0f, 1.89152f, 0.115471f, 0.0f,
+ 1.89207f, 0.110314f, 0.0f, 1.89258f, 0.105376f,
+ 0.0f, 1.89305f, 0.100649f, 0.0f, 1.89347f,
+ 0.0961239f, 0.0f, 1.89386f, 0.0917941f, 0.0f,
+ 1.89421f, 0.0876516f, 0.0f, 1.89453f, 0.083689f,
+ 0.0f, 1.89483f, 0.0798993f, 0.0f, 1.8951f,
+ 0.0762755f, 0.0f, 1.89534f, 0.0728108f, 0.0f,
+ 1.89557f, 0.0694989f, 0.0f, 1.89577f, 0.0663333f,
+ 0.0f, 1.89596f, 0.0633081f, 0.0f, 1.89613f,
+ 0.0604174f, 0.0f, 1.89628f, 0.0576555f, 0.0f,
+ 1.89642f, 0.0550171f, 0.0f, 1.89655f, 0.0524968f,
+ 0.0f, 1.89667f, 0.0500896f, 0.0f, 1.89678f,
+ 0.0477907f, 0.0f, 1.89687f, 0.0455953f, 0.0f,
+ 1.89696f, 0.0434991f, 0.0f, 1.89704f, 0.0414977f,
+ 0.0f, 1.89712f, 0.0395869f, 0.0f, 1.89718f,
+ 0.0377628f, 0.0f, 1.89724f, 0.0360216f, 0.0f,
+ 1.8973f, 0.0343596f, 0.0f, 1.89735f, 0.0327733f,
+ 0.0f, 1.8974f, 0.0312594f, 0.0f, 1.89744f,
+ 0.0298146f, 0.0f, 1.89748f, 0.0284359f, 0.0f,
+ 1.89751f, 0.0271203f, 0.0f, 1.89754f, 0.025865f,
+ 0.0f, 1.89757f, 0.0246672f, 0.0f, 1.8976f,
+ 0.0235244f, 0.0f, 1.89762f, 0.0224342f, 0.0f,
+ 1.89764f, 0.021394f, 0.0f, 1.89766f, 0.0204017f,
+ 0.0f, 1.89768f, 0.0194551f, 0.0f, 1.8977f,
+ 0.0185521f, 0.0f, 1.89771f, 0.0176908f, 0.0f,
+ 1.89773f, 0.0168692f, 0.0f, 1.89774f, 0.0160856f,
+ 0.0f, 1.89775f, 0.0153381f, 0.0f, 1.89776f,
+ 0.0146252f, 0.0f, 1.89777f, 0.0139453f, 0.0f,
+ 1.89778f, 0.0132968f, 0.0f, 1.89778f, 0.0126783f,
+ 0.0f, 1.89779f, 0.0120885f, 0.0f, 1.8978f,
+ 0.011526f, 0.0f, 1.8978f, 0.0109896f, 0.0f,
+ 1.89781f, 0.010478f, 0.0f, 1.89781f, 0.00999021f,
+ 0.0f, 1.89782f, 0.00952502f, 0.0f, 1.89782f,
+ 0.00908142f, 0.0f, 1.89782f, 0.00865842f, 0.0f,
+ 1.89783f, 0.00825506f, 0.0f, 1.89783f, 0.00787044f,
+ 0.0f, 1.89783f, 0.00750369f, 0.0f, 1.89784f,
+ 0.00715399f, 0.0f, 1.89784f, 0.00682055f, 0.0f,
+ 1.89784f, 0.00650262f, 0.0f, 1.89784f, 0.00619947f,
+ 0.0f, 1.89784f, 0.00591042f, 0.0f, 1.89785f,
+ 0.00563483f, 0.0f, 1.89785f, 0.00537206f, 0.0f,
+ 1.89785f, 0.00512152f, 0.0f, 1.89785f, 0.00488265f,
+ 0.0f, 1.89785f, 0.0046549f, 0.0f, 1.89785f,
+ 0.00443776f, 0.0f, 1.89785f, 0.00423073f, 0.0f,
+ 1.89785f, 0.00403334f, 0.0f, 1.89785f, 0.00384516f,
+ 0.0f, 1.89785f, 0.00366574f, 0.0f, 1.89785f,
+ 0.00349468f, 0.0f, 1.89786f, 0.0033316f, 0.0f,
+ 1.89786f, 0.00317612f, 0.0f, 1.89786f, 0.00302788f,
+ 0.0f, 1.89786f, 0.00288656f, 0.0f, 1.89786f,
+ 0.00275183f, 0.0f, 1.89786f, 0.00262338f, 0.0f,
+ 1.89786f, 0.00250092f, 0.0f, 1.89786f, 0.00238417f,
+ 0.0f, 1.89786f, 0.00227287f, 0.0f, 1.89786f,
+ 0.00216676f, 0.0f, 1.89786f, 0.0020656f, 0.0f,
+ 1.89786f, 0.00196916f, 0.0f, 1.89786f, 0.00187722f,
+ 0.0f, 1.89786f, 0.00178957f, 0.0f, 1.89786f,
+ 0.00170601f, 0.0f, 1.89786f, 0.00162635f, 0.0f,
+ 1.89786f, 0.00155041f, 0.0f, 1.89786f, 0.00147801f,
+ 0.0f, 1.89786f, 0.00140899f, 0.0f, 1.89786f,
+ 0.00134319f, 0.0f, 1.89786f, 0.00128047f, 0.0f,
+ 1.89786f, 0.00122067f, 0.0f, 1.89786f, 0.00116366f,
+ 0.0f, 1.89786f, 0.00110932f, 0.0f, 1.89786f,
+ 0.00105751f, 0.0f, 1.89786f, 0.00100812f, 0.0f,
+ 1.89786f, 0.000961033f, 0.0f, 1.89786f, 0.000916148f,
+ 0.0f, 1.89786f, 0.000873358f, 0.0f, 1.89786f,
+ 0.000832566f, 0.0f, 1.89786f, 0.000793679f, 0.0f,
+ 1.89786f, 0.000756608f, 0.0f, 1.89786f, 0.000721268f,
+ 0.0f, 1.89786f, 0.000687578f, 0.0f, 1.89786f,
+ 0.000655462f, 0.0f, 1.89786f, 0.000624845f, 0.0f,
+ 1.89786f, 0.000595658f, 0.0f, 1.89786f, 0.000567834f,
+ 0.0f, 1.89786f, 0.00054131f, 0.0f, 1.89786f,
+ 0.000516024f, 0.0f, 1.89786f, 0.000491919f, 0.0f,
+ 1.89786f, 0.000468941f, 0.0f, 1.89786f, 0.000447035f,
+ 0.0f, 1.89786f, 0.000426152f, 0.0f, 1.89786f,
+ 0.000406245f, 0.0f, 1.89786f, 0.000387268f, 0.0f,
+ 1.89786f, 0.000369177f, 0.0f, 1.89786f, 0.000351931f,
+ 0.0f, 1.89786f, 0.000335491f, 0.0f, 1.89786f,
+ 0.000319818f, 0.0f, 1.89786f, 0.000304878f, 0.0f,
+ 1.89786f, 0.000290635f, 0.0f, 1.89786f, 0.000277058f,
+ 0.0f, 1.89786f, 0.000264115f, 0.0f, 1.89786f,
+ 0.000251776f, 0.0f, 1.89786f, 0.000240014f, 0.0f,
+ 1.89786f, 0.000228802f, 0.0f, 1.89786f, 0.000218113f,
+ 0.0f, 1.89786f, 0.000207923f, 0.0f, 1.89786f,
+ 0.00019821f, 0.0f, 1.89786f, 0.00018895f, 0.0f,
+ 1.89786f, 0.000180123f, 0.0f, 1.89786f, 0.000171708f,
+ 0.0f, 1.89786f, 0.000163686f, 0.0f, 1.89786f,
+ 0.000156039f, 0.0f, 1.89786f, 0.000148749f, 0.0f,
+ 1.89786f, 0.0001418f, 0.0f, 1.89786f, 0.000135175f,
+ 0.0f, 1.89786f, 0.00012886f, 0.0f, 1.89786f,
+ 0.00012284f, 0.0f, 1.89786f, 0.000117101f, 0.0f,
+ 1.89786f, 0.00011163f, 0.0f, 1.89786f, 0.000106415f,
+ 0.0f, 1.89786f, 0.000101444f, 0.0f, 1.89786f,
+ 9.67043e-05f, 0.0f, 1.89786f, 9.21864e-05f, 0.0f,
+ 1.89786f, 8.78795e-05f, 0.0f, 1.89786f, 8.37739e-05f,
+ 0.0f, 1.89786f, 7.98601e-05f, 0.0f, 1.89786f,
+ 7.61291e-05f, 0.0f, 1.89786f, 7.25724e-05f, 0.0f,
+ 1.89786f, 6.91819e-05f, 0.0f, 1.89786f, 6.59498e-05f,
+ 0.0f, 1.89786f, 6.28686e-05f, 0.0f, 1.89786f,
+ 5.99315e-05f, 0.0f, 1.89786f, 5.71315e-05f, 0.0f,
+ 1.89786f, 5.44624e-05f, 0.0f, 1.89786f, 5.19179e-05f,
+ 0.0f, 1.89786f, 4.94923e-05f, 0.0f, 1.89786f,
+ 4.71801e-05f, 0.0f, 1.89786f, 4.49758e-05f, 0.0f,
+ 1.89786f, 4.28746e-05f, 0.0f, 1.89786f, 4.08715e-05f,
+ 0.0f, 1.89786f, 3.8962e-05f, 0.0f, 1.89786f,
+ 3.71417e-05f, 0.0f, 1.89786f, 3.54065e-05f, 0.0f,
+ 1.89786f, 3.37523e-05f, 0.0f, 1.89786f, 3.21754e-05f,
+ 0.0f, 1.89786f, 3.06722e-05f, 0.0f, 1.89786f,
+ 2.92392e-05f, 0.0f, 1.89786f, 2.78731e-05f, 0.0f,
+ 1.89786f, 2.65709e-05f, 0.0f, 1.89786f, 2.53295e-05f,
+ 0.0f, 1.89786f, 2.41461e-05f, 0.0f, 1.89786f,
+ 2.3018e-05f, 0.0f, 1.89786f, 2.19426e-05f, 0.0f,
+ 1.89786f, 2.09175e-05f, 0.0f, 1.89786f, 1.99402e-05f,
+ 0.0f, 1.89786f, 1.90086e-05f, 0.0f, 1.89786f,
+ 1.81205e-05f, 0.0f, 1.89786f, 1.72739e-05f, 0.0f,
+ 1.89786f, 1.64669e-05f, 0.0f, 1.89786f, 1.56975e-05f,
+ 0.0f, 1.89786f, 1.49642e-05f, 0.0f, 1.89786f,
+ 1.4265e-05f, 0.0f, 1.89786f, 1.35986e-05f, 0.0f,
+ 1.89786f, 1.29632e-05f, 0.0f, 1.89786f, 1.23576e-05f,
+ 0.0f, 1.89786f, 1.17802e-05f, 0.0f, 1.89786f,
+ 1.12299e-05f, 0.0f, 1.89786f, 1.07052e-05f, 0.0f,
+ 1.89786f, 1.02051e-05f, 0.0f, 1.89786f, 9.72828e-06f,
+ 0.0f, 1.89786f, 9.27378e-06f, 0.0f, 1.89786f,
+ 8.84051e-06f, 0.0f, 1.89786f, 8.42748e-06f, 0.0f,
+ 1.89786f, 8.03374e-06f, 0.0f, 1.89786f, 7.65841e-06f,
+ 0.0f, 1.89786f, 7.3006e-06f, 0.0f, 1.89786f,
+ 6.95952e-06f, 0.0f, 1.89786f, 6.63437e-06f, 0.0f,
+ 1.89786f, 6.32441e-06f, 0.0f, 1.89786f, 6.02893e-06f,
+ 0.0f, 1.89786f, 5.74726e-06f, 0.0f, 1.89786f,
+ 5.47875e-06f, 0.0f, 1.89786f, 5.22278e-06f, 0.0f,
+ 1.89786f, 4.97877e-06f, 0.0f, 1.89786f, 4.74616e-06f,
+ 0.0f, 1.89786f, 4.52442e-06f, 0.0f, 1.89786f,
+ 4.31304e-06f, 0.0f, 1.89786f, 4.11153e-06f, 0.0f,
+ 1.89786f, 3.91944e-06f, 0.0f, 1.89786f, 3.73632e-06f,
+ 0.0f, 1.89786f, 3.56176e-06f, 0.0f, 1.89786f,
+ 3.39536e-06f, 0.0f, 1.89786f, 3.23672e-06f, 0.0f,
+ 1.89786f, 3.0855e-06f, 0.0f, 1.89786f, 2.94135e-06f,
+ 0.0f, 1.89786f, 2.80393e-06f, 0.0f, 1.89786f,
+ 2.67293e-06f, 0.0f, 1.89786f, 2.54805e-06f, 0.0f,
+ 1.89786f, 2.429e-06f, 0.0f, 1.89786f, 2.31552e-06f,
+ 0.0f, 1.89786f, 2.20734e-06f, 0.0f, 1.89786f,
+ 2.10421e-06f, 0.0f, 1.89786f, 2.0059e-06f, 0.0f,
+ 1.89786f, 1.91218e-06f, 0.0f, 1.89786f, 1.82285e-06f,
+ 0.0f, 1.89786f, 1.73768e-06f, 0.0f, 1.89786f,
+ 1.6565e-06f, 0.0f, 1.89786f, 1.57911e-06f, 0.0f,
+ 1.89786f, 1.50533e-06f, 0.0f, 1.89786f, 1.435e-06f,
+ 0.0f, 1.89786f, 1.36796e-06f, 0.0f, 1.89786f,
+ 1.30405e-06f, 0.0f, 1.89786f, 1.24312e-06f, 0.0f,
+ 1.89786f, 1.18504e-06f, 0.0f, 1.00324f, 1.00216f,
+ 0.999152f, 0.990038f, 1.03237f, 1.02119f, 0.990433f,
+ 0.898572f, 1.06269f, 1.04023f, 0.979161f, 0.799806f,
+ 1.094f, 1.05895f, 0.964976f, 0.693603f, 1.126f,
+ 1.07701f, 0.947526f, 0.57989f, 1.15835f, 1.09398f,
+ 0.926474f, 0.45869f, 1.19059f, 1.10944f, 0.901512f,
+ 0.330158f, 1.22223f, 1.12289f, 0.87237f, 0.194621f,
+ 1.25268f, 1.13384f, 0.838839f, 0.0526136f, 1.28199f,
+ 1.14236f, 0.801199f, 0.0f, 1.31207f, 1.15021f,
+ 0.760839f, 0.0f, 1.34301f, 1.15742f, 0.717799f,
+ 0.0f, 1.37465f, 1.16386f, 0.671999f, 0.0f,
+ 1.40681f, 1.16935f, 0.623371f, 0.0f, 1.43929f,
+ 1.17374f, 0.571868f, 0.0f, 1.47185f, 1.17684f,
+ 0.517465f, 0.0f, 1.50423f, 1.17846f, 0.460174f,
+ 0.0f, 1.53613f, 1.17844f, 0.400043f, 0.0f,
+ 1.56725f, 1.17657f, 0.337165f, 0.0f, 1.59725f,
+ 1.1727f, 0.271688f, 0.0f, 1.62577f, 1.16665f,
+ 0.203815f, 0.0f, 1.65245f, 1.15828f, 0.133806f,
+ 0.0f, 1.67697f, 1.14751f, 0.0619832f, 0.0f,
+ 1.69901f, 1.13426f, 0.0f, 0.0f, 1.72022f,
+ 1.11979f, 0.0f, 0.0f, 1.74163f, 1.10481f,
+ 0.0f, 0.0f, 1.76318f, 1.08933f, 0.0f,
+ 0.0f, 1.78484f, 1.07336f, 0.0f, 0.0f,
+ 1.80655f, 1.0569f, 0.0f, 0.0f, 1.82827f,
+ 1.03997f, 0.0f, 0.0f, 1.84995f, 1.02258f,
+ 0.0f, 0.0f, 1.87155f, 1.00475f, 0.0f,
+ 0.0f, 1.89302f, 0.986504f, 0.0f, 0.0f,
+ 1.91431f, 0.967857f, 0.0f, 0.0f, 1.93537f,
+ 0.948837f, 0.0f, 0.0f, 1.95615f, 0.929471f,
+ 0.0f, 0.0f, 1.97662f, 0.90979f, 0.0f,
+ 0.0f, 1.99674f, 0.889823f, 0.0f, 0.0f,
+ 2.01645f, 0.869607f, 0.0f, 0.0f, 2.03572f,
+ 0.849175f, 0.0f, 0.0f, 2.05452f, 0.828565f,
+ 0.0f, 0.0f, 2.07282f, 0.807816f, 0.0f,
+ 0.0f, 2.09058f, 0.786964f, 0.0f, 0.0f,
+ 2.10779f, 0.766051f, 0.0f, 0.0f, 2.12441f,
+ 0.745115f, 0.0f, 0.0f, 2.14044f, 0.724196f,
+ 0.0f, 0.0f, 2.15586f, 0.703332f, 0.0f,
+ 0.0f, 2.17065f, 0.682561f, 0.0f, 0.0f,
+ 2.18482f, 0.661921f, 0.0f, 0.0f, 2.19836f,
+ 0.641445f, 0.0f, 0.0f, 2.21128f, 0.621169f,
+ 0.0f, 0.0f, 2.22356f, 0.601125f, 0.0f,
+ 0.0f, 2.23523f, 0.581341f, 0.0f, 0.0f,
+ 2.24629f, 0.561847f, 0.0f, 0.0f, 2.25675f,
+ 0.542667f, 0.0f, 0.0f, 2.26663f, 0.523826f,
+ 0.0f, 0.0f, 2.27594f, 0.505344f, 0.0f,
+ 0.0f, 2.28471f, 0.487239f, 0.0f, 0.0f,
+ 2.29294f, 0.469528f, 0.0f, 0.0f, 2.30066f,
+ 0.452225f, 0.0f, 0.0f, 2.30789f, 0.435342f,
+ 0.0f, 0.0f, 2.31465f, 0.418888f, 0.0f,
+ 0.0f, 2.32097f, 0.40287f, 0.0f, 0.0f,
+ 2.32686f, 0.387294f, 0.0f, 0.0f, 2.33234f,
+ 0.372164f, 0.0f, 0.0f, 2.33745f, 0.357481f,
+ 0.0f, 0.0f, 2.34219f, 0.343246f, 0.0f,
+ 0.0f, 2.34659f, 0.329458f, 0.0f, 0.0f,
+ 2.35066f, 0.316113f, 0.0f, 0.0f, 2.35444f,
+ 0.303208f, 0.0f, 0.0f, 2.35794f, 0.290738f,
+ 0.0f, 0.0f, 2.36117f, 0.278698f, 0.0f,
+ 0.0f, 2.36415f, 0.26708f, 0.0f, 0.0f,
+ 2.36691f, 0.255878f, 0.0f, 0.0f, 2.36945f,
+ 0.245082f, 0.0f, 0.0f, 2.37179f, 0.234685f,
+ 0.0f, 0.0f, 2.37394f, 0.224677f, 0.0f,
+ 0.0f, 2.37592f, 0.215048f, 0.0f, 0.0f,
+ 2.37775f, 0.20579f, 0.0f, 0.0f, 2.37942f,
+ 0.196891f, 0.0f, 0.0f, 2.38096f, 0.188342f,
+ 0.0f, 0.0f, 2.38237f, 0.180132f, 0.0f,
+ 0.0f, 2.38367f, 0.172251f, 0.0f, 0.0f,
+ 2.38486f, 0.164689f, 0.0f, 0.0f, 2.38595f,
+ 0.157435f, 0.0f, 0.0f, 2.38694f, 0.150479f,
+ 0.0f, 0.0f, 2.38786f, 0.143811f, 0.0f,
+ 0.0f, 2.38869f, 0.137421f, 0.0f, 0.0f,
+ 2.38946f, 0.131299f, 0.0f, 0.0f, 2.39016f,
+ 0.125435f, 0.0f, 0.0f, 2.3908f, 0.11982f,
+ 0.0f, 0.0f, 2.39139f, 0.114445f, 0.0f,
+ 0.0f, 2.39192f, 0.1093f, 0.0f, 0.0f,
+ 2.39241f, 0.104376f, 0.0f, 0.0f, 2.39286f,
+ 0.099666f, 0.0f, 0.0f, 2.39327f, 0.0951603f,
+ 0.0f, 0.0f, 2.39364f, 0.0908511f, 0.0f,
+ 0.0f, 2.39398f, 0.0867305f, 0.0f, 0.0f,
+ 2.39429f, 0.082791f, 0.0f, 0.0f, 2.39457f,
+ 0.0790251f, 0.0f, 0.0f, 2.39483f, 0.0754256f,
+ 0.0f, 0.0f, 2.39506f, 0.0719858f, 0.0f,
+ 0.0f, 2.39528f, 0.0686988f, 0.0f, 0.0f,
+ 2.39547f, 0.0655584f, 0.0f, 0.0f, 2.39565f,
+ 0.0625583f, 0.0f, 0.0f, 2.39582f, 0.0596925f,
+ 0.0f, 0.0f, 2.39596f, 0.0569554f, 0.0f,
+ 0.0f, 2.3961f, 0.0543413f, 0.0f, 0.0f,
+ 2.39622f, 0.0518451f, 0.0f, 0.0f, 2.39633f,
+ 0.0494615f, 0.0f, 0.0f, 2.39644f, 0.0471857f,
+ 0.0f, 0.0f, 2.39653f, 0.0450131f, 0.0f,
+ 0.0f, 2.39661f, 0.0429389f, 0.0f, 0.0f,
+ 2.39669f, 0.0409591f, 0.0f, 0.0f, 2.39676f,
+ 0.0390693f, 0.0f, 0.0f, 2.39682f, 0.0372656f,
+ 0.0f, 0.0f, 2.39688f, 0.0355441f, 0.0f,
+ 0.0f, 2.39694f, 0.0339013f, 0.0f, 0.0f,
+ 2.39698f, 0.0323336f, 0.0f, 0.0f, 2.39703f,
+ 0.0308377f, 0.0f, 0.0f, 2.39707f, 0.0294103f,
+ 0.0f, 0.0f, 2.3971f, 0.0280484f, 0.0f,
+ 0.0f, 2.39714f, 0.0267489f, 0.0f, 0.0f,
+ 2.39717f, 0.0255092f, 0.0f, 0.0f, 2.39719f,
+ 0.0243265f, 0.0f, 0.0f, 2.39722f, 0.0231982f,
+ 0.0f, 0.0f, 2.39724f, 0.0221218f, 0.0f,
+ 0.0f, 2.39726f, 0.0210951f, 0.0f, 0.0f,
+ 2.39728f, 0.0201157f, 0.0f, 0.0f, 2.3973f,
+ 0.0191815f, 0.0f, 0.0f, 2.39731f, 0.0182904f,
+ 0.0f, 0.0f, 2.39733f, 0.0174405f, 0.0f,
+ 0.0f, 2.39734f, 0.0166299f, 0.0f, 0.0f,
+ 2.39735f, 0.0158567f, 0.0f, 0.0f, 2.39736f,
+ 0.0151194f, 0.0f, 0.0f, 2.39737f, 0.0144161f,
+ 0.0f, 0.0f, 2.39738f, 0.0137455f, 0.0f,
+ 0.0f, 2.39739f, 0.0131059f, 0.0f, 0.0f,
+ 2.3974f, 0.0124959f, 0.0f, 0.0f, 2.3974f,
+ 0.0119143f, 0.0f, 0.0f, 2.39741f, 0.0113596f,
+ 0.0f, 0.0f, 2.39741f, 0.0108306f, 0.0f,
+ 0.0f, 2.39742f, 0.0103262f, 0.0f, 0.0f,
+ 2.39742f, 0.00984523f, 0.0f, 0.0f, 2.39743f,
+ 0.00938658f, 0.0f, 0.0f, 2.39743f, 0.00894924f,
+ 0.0f, 0.0f, 2.39744f, 0.00853223f, 0.0f,
+ 0.0f, 2.39744f, 0.00813459f, 0.0f, 0.0f,
+ 2.39744f, 0.00775545f, 0.0f, 0.0f, 2.39744f,
+ 0.00739393f, 0.0f, 0.0f, 2.39745f, 0.00704923f,
+ 0.0f, 0.0f, 2.39745f, 0.00672056f, 0.0f,
+ 0.0f, 2.39745f, 0.00640719f, 0.0f, 0.0f,
+ 2.39745f, 0.00610841f, 0.0f, 0.0f, 2.39745f,
+ 0.00582353f, 0.0f, 0.0f, 2.39745f, 0.00555191f,
+ 0.0f, 0.0f, 2.39746f, 0.00529295f, 0.0f,
+ 0.0f, 2.39746f, 0.00504604f, 0.0f, 0.0f,
+ 2.39746f, 0.00481063f, 0.0f, 0.0f, 2.39746f,
+ 0.00458619f, 0.0f, 0.0f, 2.39746f, 0.00437221f,
+ 0.0f, 0.0f, 2.39746f, 0.0041682f, 0.0f,
+ 0.0f, 2.39746f, 0.0039737f, 0.0f, 0.0f,
+ 2.39746f, 0.00378826f, 0.0f, 0.0f, 2.39746f,
+ 0.00361147f, 0.0f, 0.0f, 2.39746f, 0.00344291f,
+ 0.0f, 0.0f, 2.39746f, 0.00328222f, 0.0f,
+ 0.0f, 2.39746f, 0.00312902f, 0.0f, 0.0f,
+ 2.39746f, 0.00298297f, 0.0f, 0.0f, 2.39747f,
+ 0.00284372f, 0.0f, 0.0f, 2.39747f, 0.00271097f,
+ 0.0f, 0.0f, 2.39747f, 0.00258441f, 0.0f,
+ 0.0f, 2.39747f, 0.00246376f, 0.0f, 0.0f,
+ 2.39747f, 0.00234873f, 0.0f, 0.0f, 2.39747f,
+ 0.00223908f, 0.0f, 0.0f, 2.39747f, 0.00213453f,
+ 0.0f, 0.0f, 2.39747f, 0.00203487f, 0.0f,
+ 0.0f, 2.39747f, 0.00193986f, 0.0f, 0.0f,
+ 2.39747f, 0.00184928f, 0.0f, 0.0f, 2.39747f,
+ 0.00176292f, 0.0f, 0.0f, 2.39747f, 0.0016806f,
+ 0.0f, 0.0f, 2.39747f, 0.00160212f, 0.0f,
+ 0.0f, 2.39747f, 0.00152731f, 0.0f, 0.0f,
+ 2.39747f, 0.00145598f, 0.0f, 0.0f, 2.39747f,
+ 0.00138799f, 0.0f, 0.0f, 2.39747f, 0.00132316f,
+ 0.0f, 0.0f, 2.39747f, 0.00126137f, 0.0f,
+ 0.0f, 2.39747f, 0.00120246f, 0.0f, 0.0f,
+ 2.39747f, 0.0011463f, 0.0f, 0.0f, 2.39747f,
+ 0.00109276f, 0.0f, 0.0f, 2.39747f, 0.00104172f,
+ 0.0f, 0.0f, 2.39747f, 0.000993069f, 0.0f,
+ 0.0f, 2.39747f, 0.000946686f, 0.0f, 0.0f,
+ 2.39747f, 0.000902469f, 0.0f, 0.0f, 2.39747f,
+ 0.000860316f, 0.0f, 0.0f, 2.39747f, 0.000820132f,
+ 0.0f, 0.0f, 2.39747f, 0.000781825f, 0.0f,
+ 0.0f, 2.39747f, 0.000745306f, 0.0f, 0.0f,
+ 2.39747f, 0.000710492f, 0.0f, 0.0f, 2.39747f,
+ 0.000677305f, 0.0f, 0.0f, 2.39747f, 0.000645667f,
+ 0.0f, 0.0f, 2.39747f, 0.000615507f, 0.0f,
+ 0.0f, 2.39747f, 0.000586756f, 0.0f, 0.0f,
+ 2.39747f, 0.000559347f, 0.0f, 0.0f, 2.39747f,
+ 0.000533218f, 0.0f, 0.0f, 2.39747f, 0.00050831f,
+ 0.0f, 0.0f, 2.39747f, 0.000484565f, 0.0f,
+ 0.0f, 2.39747f, 0.000461929f, 0.0f, 0.0f,
+ 2.39747f, 0.000440351f, 0.0f, 0.0f, 2.39747f,
+ 0.00041978f, 0.0f, 0.0f, 2.39747f, 0.00040017f,
+ 0.0f, 0.0f, 2.39747f, 0.000381476f, 0.0f,
+ 0.0f, 2.39747f, 0.000363656f, 0.0f, 0.0f,
+ 2.39747f, 0.000346667f, 0.0f, 0.0f, 2.39747f,
+ 0.000330473f, 0.0f, 0.0f, 2.39747f, 0.000315034f,
+ 0.0f, 0.0f, 2.39747f, 0.000300317f, 0.0f,
+ 0.0f, 2.39747f, 0.000286287f, 0.0f, 0.0f,
+ 2.39747f, 0.000272913f, 0.0f, 0.0f, 2.39747f,
+ 0.000260164f, 0.0f, 0.0f, 2.39747f, 0.00024801f,
+ 0.0f, 0.0f, 2.39747f, 0.000236423f, 0.0f,
+ 0.0f, 2.39747f, 0.000225378f, 0.0f, 0.0f,
+ 2.39747f, 0.000214849f, 0.0f, 0.0f, 2.39747f,
+ 0.000204812f, 0.0f, 0.0f, 2.39747f, 0.000195244f,
+ 0.0f, 0.0f, 2.39747f, 0.000186122f, 0.0f,
+ 0.0f, 2.39747f, 0.000177427f, 0.0f, 0.0f,
+ 2.39747f, 0.000169138f, 0.0f, 0.0f, 2.39747f,
+ 0.000161236f, 0.0f, 0.0f, 2.39747f, 0.000153704f,
+ 0.0f, 0.0f, 2.39747f, 0.000146523f, 0.0f,
+ 0.0f, 2.39747f, 0.000139678f, 0.0f, 0.0f,
+ 2.39747f, 0.000133152f, 0.0f, 0.0f, 2.39747f,
+ 0.000126932f, 0.0f, 0.0f, 2.39747f, 0.000121001f,
+ 0.0f, 0.0f, 2.39747f, 0.000115348f, 0.0f,
+ 0.0f, 2.39747f, 0.00010996f, 0.0f, 0.0f,
+ 2.39747f, 0.000104822f, 0.0f, 0.0f, 2.39747f,
+ 9.99252e-05f, 0.0f, 0.0f, 2.39747f, 9.52568e-05f,
+ 0.0f, 0.0f, 2.39747f, 9.08065e-05f, 0.0f,
+ 0.0f, 2.39747f, 8.65641e-05f, 0.0f, 0.0f,
+ 2.39747f, 8.25199e-05f, 0.0f, 0.0f, 2.39747f,
+ 7.86646e-05f, 0.0f, 0.0f, 2.39747f, 7.49895e-05f,
+ 0.0f, 0.0f, 2.39747f, 7.1486e-05f, 0.0f,
+ 0.0f, 2.39747f, 6.81463e-05f, 0.0f, 0.0f,
+ 2.39747f, 6.49625e-05f, 0.0f, 0.0f, 2.39747f,
+ 6.19275e-05f, 0.0f, 0.0f, 2.39747f, 5.90343e-05f,
+ 0.0f, 0.0f, 2.39747f, 5.62762e-05f, 0.0f,
+ 0.0f, 2.39747f, 5.3647e-05f, 0.0f, 0.0f,
+ 2.39747f, 5.11407e-05f, 0.0f, 0.0f, 2.39747f,
+ 4.87514e-05f, 0.0f, 0.0f, 2.39747f, 4.64738e-05f,
+ 0.0f, 0.0f, 2.39747f, 4.43025e-05f, 0.0f,
+ 0.0f, 2.39747f, 4.22327e-05f, 0.0f, 0.0f,
+ 2.39747f, 4.02596e-05f, 0.0f, 0.0f, 2.39747f,
+ 3.83787e-05f, 0.0f, 0.0f, 2.39747f, 3.65857e-05f,
+ 0.0f, 0.0f, 2.39747f, 3.48764e-05f, 0.0f,
+ 0.0f, 2.39747f, 3.3247e-05f, 0.0f, 0.0f,
+ 2.39747f, 3.16937e-05f, 0.0f, 0.0f, 2.39747f,
+ 3.0213e-05f, 0.0f, 0.0f, 2.39747f, 2.88014e-05f,
+ 0.0f, 0.0f, 2.39747f, 2.74558e-05f, 0.0f,
+ 0.0f, 2.39747f, 2.61731e-05f, 0.0f, 0.0f,
+ 2.39747f, 2.49503e-05f, 0.0f, 0.0f, 2.39747f,
+ 2.37846e-05f, 0.0f, 0.0f, 2.39747f, 2.26734e-05f,
+ 0.0f, 0.0f, 2.39747f, 2.16141e-05f, 0.0f,
+ 0.0f, 2.39747f, 2.06043e-05f, 0.0f, 0.0f,
+ 2.39747f, 1.96417e-05f, 0.0f, 0.0f, 2.39747f,
+ 1.8724e-05f, 0.0f, 0.0f, 2.39747f, 1.78492e-05f,
+ 0.0f, 0.0f, 2.39747f, 1.70153e-05f, 0.0f,
+ 0.0f, 2.39747f, 1.62203e-05f, 0.0f, 0.0f,
+ 2.39747f, 1.54625e-05f, 0.0f, 0.0f, 2.39747f,
+ 1.47401e-05f, 0.0f, 0.0f, 2.39747f, 1.40515e-05f,
+ 0.0f, 0.0f, 2.39747f, 1.3395e-05f, 0.0f,
+ 0.0f, 2.39747f, 1.27692e-05f, 0.0f, 0.0f,
+ 2.39747f, 1.21726e-05f, 0.0f, 0.0f, 2.39747f,
+ 1.16039e-05f, 0.0f, 0.0f, 2.39747f, 1.10617e-05f,
+ 0.0f, 0.0f, 2.39747f, 1.05449e-05f, 0.0f,
+ 0.0f, 2.39747f, 1.00523e-05f, 0.0f, 0.0f,
+ 2.39747f, 9.58263e-06f, 0.0f, 0.0f, 2.39747f,
+ 9.13493e-06f, 0.0f, 0.0f, 2.39747f, 8.70814e-06f,
+ 0.0f, 0.0f, 2.39747f, 8.3013e-06f, 0.0f,
+ 0.0f, 2.39747f, 7.91346e-06f, 0.0f, 0.0f,
+ 2.39747f, 7.54374e-06f, 0.0f, 0.0f, 2.39747f,
+ 7.1913e-06f, 0.0f, 0.0f, 2.39747f, 6.85532e-06f,
+ 0.0f, 0.0f, 2.39747f, 6.53504e-06f, 0.0f,
+ 0.0f, 2.39747f, 6.22972e-06f, 0.0f, 0.0f,
+ 2.39747f, 5.93867e-06f, 0.0f, 0.0f, 2.39747f,
+ 5.66121e-06f, 0.0f, 0.0f, 2.39747f, 5.39672e-06f,
+ 0.0f, 0.0f, 2.39747f, 5.14458e-06f, 0.0f,
+ 0.0f, 2.39747f, 4.90423e-06f, 0.0f, 0.0f,
+ 2.39747f, 4.6751e-06f, 0.0f, 0.0f, 2.39747f,
+ 4.45668e-06f, 0.0f, 0.0f, 2.39747f, 4.24846e-06f,
+ 0.0f, 0.0f, 2.39747f, 4.04997e-06f, 0.0f,
+ 0.0f, 2.39747f, 3.86076e-06f, 0.0f, 0.0f,
+ 2.39747f, 3.68038e-06f, 0.0f, 0.0f, 2.39747f,
+ 3.50843e-06f, 0.0f, 0.0f, 2.39747f, 3.34452e-06f,
+ 0.0f, 0.0f, 2.39747f, 3.18826e-06f, 0.0f,
+ 0.0f, 2.39747f, 3.03931e-06f, 0.0f, 0.0f,
+ 2.39747f, 2.89731e-06f, 0.0f, 0.0f, 2.39747f,
+ 2.76195e-06f, 0.0f, 0.0f, 2.39747f, 2.63291e-06f,
+ 0.0f, 0.0f, 2.39747f, 2.5099e-06f, 0.0f,
+ 0.0f, 2.39747f, 2.39263e-06f, 0.0f, 0.0f,
+ 2.39747f, 2.28085e-06f, 0.0f, 0.0f, 2.39747f,
+ 2.17429e-06f, 0.0f, 0.0f, 2.39747f, 2.0727e-06f,
+ 0.0f, 0.0f, 2.39747f, 1.97587e-06f, 0.0f,
+ 0.0f, 2.39747f, 1.88355e-06f, 0.0f, 0.0f,
+ 2.39747f, 1.79555e-06f, 0.0f, 0.0f, 2.39747f,
+ 1.71167e-06f, 0.0f, 0.0f, 2.39747f, 1.6317e-06f,
+ 0.0f, 0.0f, 2.39747f, 1.55546e-06f, 0.0f,
+ 0.0f, 2.39747f, 1.48279e-06f, 0.0f, 0.0f,
+ 2.39747f, 1.41352e-06f, 0.0f, 0.0f, 2.39747f,
+ 1.34748e-06f, 0.0f, 0.0f};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_AMBISONICS_AMBISONIC_SPREAD_COEFFICIENTS_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator.cc
new file mode 100644
index 000000000..49b7abf89
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator.cc
@@ -0,0 +1,147 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/associated_legendre_polynomials_generator.h"
+
+#include <cmath>
+
+#include "base/logging.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+AssociatedLegendrePolynomialsGenerator::AssociatedLegendrePolynomialsGenerator(
+ int max_degree, bool condon_shortley_phase, bool compute_negative_order)
+ : max_degree_(max_degree),
+ condon_shortley_phase_(condon_shortley_phase),
+ compute_negative_order_(compute_negative_order) {
+ DCHECK_GE(max_degree_, 0);
+}
+
+std::vector<float> AssociatedLegendrePolynomialsGenerator::Generate(
+ float x) const {
+ std::vector<float> values(GetNumValues());
+
+ // Bases for the recurrence relations.
+ values[GetIndex(0, 0)] = ComputeValue(0, 0, x, values);
+ if (max_degree_ >= 1) values[GetIndex(1, 0)] = ComputeValue(1, 0, x, values);
+
+ // Using recurrence relations, we now compute the rest of the values needed.
+ // (degree, 0), based on (degree - 1, 0) and (degree - 2, 0):
+ for (int degree = 2; degree <= max_degree_; ++degree) {
+ const int order = 0;
+ values[GetIndex(degree, order)] = ComputeValue(degree, order, x, values);
+ }
+ // (degree, degree):
+ for (int degree = 1; degree <= max_degree_; ++degree) {
+ const int order = degree;
+ values[GetIndex(degree, order)] = ComputeValue(degree, order, x, values);
+ }
+ // (degree, degree - 1):
+ for (int degree = 2; degree <= max_degree_; ++degree) {
+ const int order = degree - 1;
+ values[GetIndex(degree, order)] = ComputeValue(degree, order, x, values);
+ }
+ // The remaining positive orders, based on (degree - 1, order) and
+ // (degree - 2, order):
+ for (int degree = 3; degree <= max_degree_; ++degree) {
+ for (int order = 1; order <= degree - 2; ++order) {
+ values[GetIndex(degree, order)] = ComputeValue(degree, order, x, values);
+ }
+ }
+ // (degree, -order):
+ if (compute_negative_order_) {
+ for (int degree = 1; degree <= max_degree_; ++degree) {
+ for (int order = 1; order <= degree; ++order) {
+ values[GetIndex(degree, -order)] =
+ ComputeValue(degree, -order, x, values);
+ }
+ }
+ }
+ if (!condon_shortley_phase_) {
+ for (int degree = 1; degree <= max_degree_; ++degree) {
+ const int start_order = compute_negative_order_ ? -degree : 0;
+ for (int order = start_order; order <= degree; ++order) {
+ // Undo the Condon-Shortley phase.
+ values[GetIndex(degree, order)] *=
+ static_cast<float>(std::pow(-1, order));
+ }
+ }
+ }
+ return values;
+}
+
+size_t AssociatedLegendrePolynomialsGenerator::GetNumValues() const {
+ if (compute_negative_order_)
+ return (max_degree_ + 1) * (max_degree_ + 1);
+ else
+ return ((max_degree_ + 1) * (max_degree_ + 2)) / 2;
+}
+
+size_t AssociatedLegendrePolynomialsGenerator::GetIndex(int degree,
+ int order) const {
+ CheckIndexValidity(degree, order);
+ size_t result;
+ if (compute_negative_order_) {
+ result = static_cast<size_t>(degree * (degree + 1) + order);
+ } else {
+ result = static_cast<size_t>((degree * (degree + 1)) / 2 + order);
+ }
+ DCHECK_GE(result, 0U);
+ DCHECK_LT(result, GetNumValues());
+ return result;
+}
+
+float AssociatedLegendrePolynomialsGenerator::ComputeValue(
+ int degree, int order, float x, const std::vector<float>& values) const {
+ CheckIndexValidity(degree, order);
+ if (degree == 0 && order == 0) {
+ return 1;
+ } else if (degree == 1 && order == 0) {
+ return x;
+ } else if (degree == order) {
+ return std::pow(-1.0f, static_cast<float>(degree)) *
+ DoubleFactorial(2 * degree - 1) *
+ std::pow((1.0f - x * x), 0.5f * static_cast<float>(degree));
+ } else if (order == degree - 1) {
+ return x * static_cast<float>(2 * degree - 1) *
+ values[GetIndex(degree - 1, degree - 1)];
+ } else if (order < 0) {
+ return std::pow(-1.0f, static_cast<float>(order)) *
+ Factorial(degree + order) / Factorial(degree - order) *
+ values[GetIndex(degree, -order)];
+ } else {
+ return (static_cast<float>(2 * degree - 1) * x *
+ values[GetIndex(degree - 1, order)] -
+ static_cast<float>(degree - 1 + order) *
+ values[GetIndex(degree - 2, order)]) /
+ static_cast<float>(degree - order);
+ }
+}
+
+void AssociatedLegendrePolynomialsGenerator::CheckIndexValidity(
+ int degree, int order) const {
+ DCHECK_GE(degree, 0);
+ DCHECK_LE(degree, max_degree_);
+ if (compute_negative_order_) {
+ DCHECK_LE(-degree, order);
+ } else {
+ DCHECK_GE(order, 0);
+ }
+ DCHECK_LE(order, degree);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator.h b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator.h
new file mode 100644
index 000000000..84eb9d2f6
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator.h
@@ -0,0 +1,89 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_AMBISONICS_ASSOCIATED_LEGENDRE_POLYNOMIALS_GENERATOR_H_
+#define RESONANCE_AUDIO_AMBISONICS_ASSOCIATED_LEGENDRE_POLYNOMIALS_GENERATOR_H_
+
+#include <stddef.h>
+#include <vector>
+
+namespace vraudio {
+
+// Generates associated Legendre polynomials.
+class AssociatedLegendrePolynomialsGenerator {
+ public:
+ // Constructs a generator for associated Legendre polynomials (ALP).
+ //
+ // @param max_degree The maximum ALP degree supported by this generator.
+ // @param condon_shortley_phase Whether the Condon-Shortley phase, (-1)^order,
+ // should be included in the polynomials generated.
+ // @param compute_negative_order Whether this generator should compute
+ // negative-ordered polynomials.
+ AssociatedLegendrePolynomialsGenerator(int max_degree,
+ bool condon_shortley_phase,
+ bool compute_negative_order);
+
+ // Generates the associated Legendre polynomials for the given |x|, returning
+ // the computed sequence.
+ //
+ // @param x The abscissa (the polynomials' variable).
+ // @return Output vector of computed values.
+ std::vector<float> Generate(float x) const;
+
+ // Gets the number of associated Legendre polynomials this generator produces.
+ //
+ // @return The number of associated Legendre polynomials this generator
+ // produces.
+ size_t GetNumValues() const;
+
+ // Gets the index into the output vector for the given |degree| and |order|.
+ //
+ // @param degree The polynomial's degree.
+ // @param order The polynomial's order.
+ // @return The index into the vector of computed values corresponding to the
+ // specified ALP.
+ size_t GetIndex(int degree, int order) const;
+
+ private:
+ // Computes the ALP for (degree, order) the given |x| using recurrence
+ // relations. It is assumed that the ALPs necessary for each computation are
+ // already computed and stored in |values|.
+ //
+ // @param degree The degree of the polynomial being computed.
+ // @param degree The order of the polynomial being computed.
+ // @param values The previously computed values.
+ // @return The computed polynomial.
+ inline float ComputeValue(int degree, int order, float x,
+ const std::vector<float>& values) const;
+
+ // Checks the validity of the given index.
+ //
+ // @param degree The polynomial's degree.
+ // @param order The polynomial's order.
+ inline void CheckIndexValidity(int degree, int order) const;
+
+ // The maximum polynomial degree that can be computed; must be >= 0.
+ int max_degree_ = 0;
+ // Whether the Condon-Shortley phase, (-1)^order, should be included in the
+ // polynomials generated.
+ bool condon_shortley_phase_ = false;
+ // Whether this generator should compute negative-ordered polynomials.
+ bool compute_negative_order_ = false;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_AMBISONICS_ASSOCIATED_LEGENDRE_POLYNOMIALS_GENERATOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator_test.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator_test.cc
new file mode 100644
index 000000000..b9b6cdec4
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator_test.cc
@@ -0,0 +1,167 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/associated_legendre_polynomials_generator.h"
+
+#include <cmath>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+namespace {
+
+// Tolerated test error margin for single-precision floating points.
+const float kEpsilon = 1e-5f;
+
+// Generates associated Legendre polynomials up to and including the 4th degree,
+// with the Condon-Shortley phase and negative orders included.
+std::vector<float> GenerateExpectedValuesFourthDegree(float x) {
+ // From http://en.wikipedia.org/wiki/Associated_Legendre_polynomials
+ // Comments are (degree, order).
+ const std::vector<float> expected_values = {
+ 1.0f, // (0, 0)
+ 0.5f * std::sqrt(1.0f - x * x), // (1, -1)
+ x, // (1, 0)
+ -std::sqrt(1.0f - x * x), // (1, 1)
+ 1.0f / 8.0f * (1.0f - x * x), // (2, -2)
+ 0.5f * x * std::sqrt(1.0f - x * x), // (2, -1)
+ 0.5f * (3.0f * x * x - 1.0f), // (2, 0)
+ -3.0f * x * std::sqrt(1.0f - x * x), // (2, 1)
+ 3.0f * (1.0f - x * x), // (2, 2)
+ 15.0f / 720.0f * std::pow(1.0f - x * x, 3.0f / 2.0f), // (3, -3)
+ 15.0f / 120.0f * x * (1.0f - x * x), // (3, -2)
+ 3.0f / 24.0f * (5.0f * x * x - 1.0f) *
+ std::sqrt(1.0f - x * x), // (3, -1)
+ 0.5f * (5.0f * IntegerPow(x, 3) - 3.0f * x), // (3, 0)
+ -3.0f / 2.0f * (5.0f * x * x - 1.0f) * std::sqrt(1.0f - x * x), // (3, 1)
+ 15.0f * x * (1.0f - x * x), // (3, 2)
+ -15.0f * std::pow(1.0f - x * x, 3.0f / 2.0f), // (3, 3)
+ 105.0f / 40320.0f * IntegerPow(1.0f - x * x, 2), // (4, -4)
+ 105.0f / 5040.0f * x * std::pow(1.0f - x * x, 3.0f / 2.0f), // (4, -3)
+ 15.0f / 720.0f * (7.0f * x * x - 1.0f) * (1.0f - x * x), // (4, -2)
+ 5.0f / 40.0f * (7.0f * IntegerPow(x, 3) - 3.0f * x) *
+ std::sqrt(1.0f - x * x), // (4, -1)
+ 1.0f / 8.0f *
+ (35.0f * IntegerPow(x, 4) - 30.0f * x * x + 3.0f), // (4, 0)
+ -5.0f / 2.0f * (7.0f * IntegerPow(x, 3) - 3.0f * x) *
+ std::sqrt(1.0f - x * x), // (4, 1)
+ 15.0f / 2.0f * (7.0f * x * x - 1.0f) * (1.0f - x * x), // (4, 2)
+ -105.0f * x * std::pow(1.0f - x * x, 3.0f / 2.0f), // (4, 3)
+ 105.0f * IntegerPow(1.0f - x * x, 2) // (4, 4)
+ };
+
+ return expected_values;
+}
+
+// Tests that the values given by GetIndex are successive indices (n, n+1, n+2,
+// and so on).
+TEST(AssociatedLegendrePolynomialsGeneratorTest, GetIndex_SuccessiveIndices) {
+ const int kMaxDegree = 5;
+ const AssociatedLegendrePolynomialsGenerator alp_generator(kMaxDegree, false,
+ true);
+ int last_index = -1;
+ for (int degree = 0; degree <= kMaxDegree; ++degree) {
+ for (int order = -degree; order <= degree; ++order) {
+ int index = static_cast<int>(alp_generator.GetIndex(degree, order));
+ EXPECT_EQ(last_index + 1, index);
+ last_index = index;
+ }
+ }
+}
+
+// Tests that the zeroth-degree, zeroth-order ALP is always 1.
+TEST(AssociatedLegendrePolynomialsGeneratorTest, Generate_ZerothElementIsOne) {
+ const int kMaxDegree = 10;
+ for (int max_degree = 0; max_degree <= kMaxDegree; ++max_degree) {
+ for (int condon_shortley_phase = 0; condon_shortley_phase <= 1;
+ ++condon_shortley_phase) {
+ for (int compute_negative_order = 0; compute_negative_order <= 1;
+ ++compute_negative_order) {
+ AssociatedLegendrePolynomialsGenerator alp_generator(
+ max_degree, condon_shortley_phase != 0,
+ compute_negative_order != 0);
+
+ const float kVariableStep = 0.2f;
+ for (float x = -1.0f; x <= 1.0f; x += kVariableStep) {
+ const std::vector<float> values = alp_generator.Generate(x);
+
+ EXPECT_NEAR(values[0], 1.0f, kEpsilon);
+ }
+ }
+ }
+ }
+}
+
+// Tests that the polynomials generated are correct until the 4th degree.
+TEST(AssociatedLegendrePolynomialsGeneratorTest, Generate_CorrectFourthDegree) {
+ const int kMaxDegree = 4;
+ const bool kCondonShortleyPhase = true;
+ const bool kComputeNegativeOrder = true;
+ const AssociatedLegendrePolynomialsGenerator alp_generator(
+ kMaxDegree, kCondonShortleyPhase, kComputeNegativeOrder);
+
+ const float kVariableStep = 0.05f;
+ for (float x = -1.0f; x <= 1.0f; x += kVariableStep) {
+ const std::vector<float> generated_values = alp_generator.Generate(x);
+ const std::vector<float> expected_values =
+ GenerateExpectedValuesFourthDegree(x);
+ ASSERT_EQ(expected_values.size(), generated_values.size());
+ for (size_t i = 0; i < expected_values.size(); ++i) {
+ EXPECT_NEAR(generated_values[i], expected_values[i], kEpsilon)
+ << " at index " << i;
+ }
+ }
+}
+
+// Tests that the Condon-Shortley phase is correctly applied.
+TEST(AssociatedLegendrePolynomialsGeneratorTest, Generate_CondonShortleyPhase) {
+ const int kMaxDegree = 10;
+ const float kValue = 0.12345f;
+ for (int max_degree = 0; max_degree <= kMaxDegree; ++max_degree) {
+ for (int compute_negative_order = 0; compute_negative_order <= 1;
+ ++compute_negative_order) {
+ const AssociatedLegendrePolynomialsGenerator alp_generator_without_phase(
+ max_degree, false, compute_negative_order != 0);
+ const std::vector<float> values_without_phase =
+ alp_generator_without_phase.Generate(kValue);
+
+ const AssociatedLegendrePolynomialsGenerator alp_generator_with_phase(
+ max_degree, true, compute_negative_order != 0);
+ const std::vector<float> values_with_phase =
+ alp_generator_with_phase.Generate(kValue);
+
+ ASSERT_EQ(values_with_phase.size(), values_without_phase.size());
+ for (int degree = 0; degree <= max_degree; ++degree) {
+ const int start_order = compute_negative_order ? -degree : 0;
+ for (int order = start_order; order <= degree; ++order) {
+ const size_t index =
+ alp_generator_without_phase.GetIndex(degree, order);
+ const float expected = values_without_phase[index] *
+ std::pow(-1.0f, static_cast<float>(order));
+ EXPECT_NEAR(values_with_phase[index], expected, kEpsilon)
+ << " at degree " << degree << " and order " << order;
+ }
+ }
+ }
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator.cc
new file mode 100644
index 000000000..f1ac68118
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator.cc
@@ -0,0 +1,117 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "ambisonics/foa_rotator.h"
+
+#include <algorithm>
+
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+bool FoaRotator::Process(const WorldRotation& target_rotation,
+ const AudioBuffer& input, AudioBuffer* output) {
+
+ DCHECK(output);
+ DCHECK_EQ(input.num_channels(), kNumFirstOrderAmbisonicChannels);
+ DCHECK_EQ(input.num_channels(), output->num_channels());
+ DCHECK_EQ(input.num_frames(), output->num_frames());
+
+ static const WorldRotation kIdentityRotation;
+
+ if (current_rotation_.AngularDifferenceRad(kIdentityRotation) <
+ kRotationQuantizationRad &&
+ target_rotation.AngularDifferenceRad(kIdentityRotation) <
+ kRotationQuantizationRad) {
+ return false;
+ }
+
+ if (current_rotation_.AngularDifferenceRad(target_rotation) <
+ kRotationQuantizationRad) {
+ // Rotate the whole input buffer frame by frame.
+ Rotate(current_rotation_, 0, input.num_frames(), input, output);
+ return true;
+ }
+
+ // In order to perform a smooth rotation, we divide the buffer into
+ // chunks of size |kSlerpFrameInterval|.
+ //
+
+ const size_t kSlerpFrameInterval = 32;
+
+ WorldRotation slerped_rotation;
+ // Rotate the input buffer at every slerp update interval. Truncate the
+ // final chunk if the input buffer is not an integer multiple of the
+ // chunk size.
+ for (size_t i = 0; i < input.num_frames(); i += kSlerpFrameInterval) {
+ const size_t duration =
+ std::min(input.num_frames() - i, kSlerpFrameInterval);
+ const float interpolation_factor = static_cast<float>(i + duration) /
+ static_cast<float>(input.num_frames());
+ slerped_rotation =
+ current_rotation_.slerp(interpolation_factor, target_rotation);
+ // Rotate the input buffer frame by frame within the current chunk.
+ Rotate(slerped_rotation, i, duration, input, output);
+ }
+
+ current_rotation_ = target_rotation;
+
+ return true;
+}
+
+void FoaRotator::Rotate(const WorldRotation& target_rotation,
+ size_t start_location, size_t duration,
+ const AudioBuffer& input, AudioBuffer* output) {
+
+ const AudioBuffer::Channel& input_channel_audio_space_w = input[0];
+ const AudioBuffer::Channel& input_channel_audio_space_y = input[1];
+ const AudioBuffer::Channel& input_channel_audio_space_z = input[2];
+ const AudioBuffer::Channel& input_channel_audio_space_x = input[3];
+ AudioBuffer::Channel* output_channel_audio_space_w = &(*output)[0];
+ AudioBuffer::Channel* output_channel_audio_space_y = &(*output)[1];
+ AudioBuffer::Channel* output_channel_audio_space_z = &(*output)[2];
+ AudioBuffer::Channel* output_channel_audio_space_x = &(*output)[3];
+
+ for (size_t frame = start_location; frame < start_location + duration;
+ ++frame) {
+ // Convert the current audio frame into world space position.
+ temp_audio_position_(0) = input_channel_audio_space_x[frame];
+ temp_audio_position_(1) = input_channel_audio_space_y[frame];
+ temp_audio_position_(2) = input_channel_audio_space_z[frame];
+ ConvertWorldFromAudioPosition(temp_audio_position_, &temp_world_position_);
+ // Apply rotation to |world_position| and return to audio space.
+ temp_rotated_world_position_ = target_rotation * temp_world_position_;
+
+ ConvertAudioFromWorldPosition(temp_rotated_world_position_,
+ &temp_rotated_audio_position_);
+ (*output_channel_audio_space_x)[frame] =
+ temp_rotated_audio_position_(0); // X
+ (*output_channel_audio_space_y)[frame] =
+ temp_rotated_audio_position_(1); // Y
+ (*output_channel_audio_space_z)[frame] =
+ temp_rotated_audio_position_(2); // Z
+ }
+ // Copy W channel.
+ std::copy_n(&input_channel_audio_space_w[start_location], duration,
+ &(*output_channel_audio_space_w)[start_location]);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator.h b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator.h
new file mode 100644
index 000000000..a91b975d4
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator.h
@@ -0,0 +1,61 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_AMBISONICS_FOA_ROTATOR_H_
+#define RESONANCE_AUDIO_AMBISONICS_FOA_ROTATOR_H_
+
+#include "base/audio_buffer.h"
+#include "base/spherical_angle.h"
+
+namespace vraudio {
+
+// Rotator for first order ambisonic soundfields. It supports ACN channel
+// ordering and SN3D normalization (AmbiX).
+class FoaRotator {
+ public:
+ // @param target_rotation Target rotation to be applied to the input buffer.
+ // @param input First order soundfield input buffer to be rotated.
+ // @param output Pointer to output buffer.
+ // @return True if rotation has been applied.
+ bool Process(const WorldRotation& target_rotation, const AudioBuffer& input,
+ AudioBuffer* output);
+
+ private:
+ // Method which rotates a specified chunk of data in the AudioBuffer.
+ //
+ // @param target_rotation Target rotation to be applied to the soundfield.
+ // @param start_location Sample index in the soundfield where the rotation
+ // should begin.
+ // @param duration Number of samples in soundfield to be rotated.
+ // @param input First order soundfield input buffer to be rotated.
+ // @param output Pointer to output buffer.
+ void Rotate(const WorldRotation& target_rotation, size_t start_location,
+ size_t duration, const AudioBuffer& input, AudioBuffer* output);
+
+ // Current rotation which is used in the interpolation process in order to
+ // perform a smooth rotation. Initialized with an identity matrix.
+ WorldRotation current_rotation_;
+
+ // Preallocation of temporary variables used during rotation.
+ AudioPosition temp_audio_position_;
+ WorldPosition temp_world_position_;
+ AudioPosition temp_rotated_audio_position_;
+ WorldPosition temp_rotated_world_position_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_AMBISONICS_FOA_ROTATOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator_test.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator_test.cc
new file mode 100644
index 000000000..e2f957fa2
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/foa_rotator_test.cc
@@ -0,0 +1,201 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/foa_rotator.h"
+
+#include <algorithm>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "ambisonics/ambisonic_codec_impl.h"
+#include "base/constants_and_types.h"
+#include "utils/planar_interleaved_conversion.h"
+
+namespace vraudio {
+
+namespace {
+
+using testing::tuple;
+using testing::Values;
+
+const int kAmbisonicOrder = 1;
+
+// Rotation angle used in the test.
+const float kAngleDegrees = 90.0f;
+
+// Initial, arbitrary direction of the encoded soundfield source.
+const SphericalAngle kInitialSourceAngle =
+ SphericalAngle::FromDegrees(22.0f, 33.0f);
+
+// Expected direction of the sound source rotated by |kAngleDegrees| against the
+// right facing axis (x in the world coordinate system).
+const SphericalAngle kXrotatedSourceAngle =
+ SphericalAngle::FromDegrees(150.021778639249f, 51.0415207997462f);
+
+// Expected direction of the sound source rotated by |kAngleDegrees| against the
+// upward facing axis (y in the world coordinate system).
+const SphericalAngle kYrotatedSourceAngle =
+ SphericalAngle::FromDegrees(112.0f, 33.0f);
+
+// Expected direction of the sound source rotated by |kAngleDegrees| against the
+// back facing axis (z in the world coordinate system).
+const SphericalAngle kZrotatedSourceAngle =
+ SphericalAngle::FromDegrees(35.0077312770459f, -18.3108067341351f);
+
+// Rotation interpolation interval in terms of frames (used by the FoaRotator).
+const size_t kSlerpFrameInterval = 32;
+
+class FoaRotatorTest : public ::testing::Test {
+ protected:
+ FoaRotatorTest() {}
+
+ // Virtual methods from ::testing::Test
+ ~FoaRotatorTest() override {}
+
+ void SetUp() override {
+ // Initialize the first order soundfield rotator.
+ foa_rotator_ = std::unique_ptr<FoaRotator>(new FoaRotator);
+ }
+
+ void TearDown() override {}
+
+ // Test method which creates a soundfield buffer, rotates it by
+ // |rotation_angle| against |rotation_axis|, and compares the output to the
+ // reference soundfield buffer (where the source is spatialized at the
+ // |expected_source_angle|).
+ void CompareRotatedAndReferenceSoundfields(
+ const std::vector<float>& input_data, float rotation_angle,
+ const WorldPosition& rotation_axis,
+ const SphericalAngle& expected_source_angle) {
+ AudioBuffer input_buffer(1, input_data.size());
+ FillAudioBuffer(input_data, 1, &input_buffer);
+ // Initialize a first order mono codec with the |kInitialSourceAngle|. This
+ // will be used to obtain the rotated soundfield.
+ std::unique_ptr<MonoAmbisonicCodec<>> rotated_source_mono_codec(
+ new MonoAmbisonicCodec<>(kAmbisonicOrder, {kInitialSourceAngle}));
+ // Initialize a first order mono codec with the expected source angle. This
+ // will be used as a reference for the rotated soundfield.
+ std::unique_ptr<MonoAmbisonicCodec<>> reference_source_mono_codec(
+ new MonoAmbisonicCodec<>(kAmbisonicOrder, {expected_source_angle}));
+ // Generate soundfield buffers representing sound sources at required
+ // angles.
+ AudioBuffer encoded_rotated_buffer(kNumFirstOrderAmbisonicChannels,
+ input_data.size());
+ AudioBuffer encoded_reference_buffer(kNumFirstOrderAmbisonicChannels,
+ input_data.size());
+ rotated_source_mono_codec->EncodeBuffer(input_buffer,
+ &encoded_rotated_buffer);
+ reference_source_mono_codec->EncodeBuffer(input_buffer,
+ &encoded_reference_buffer);
+ // Rotate the test soundfield by |rotation_angle| degrees wrt the given
+ // |rotation_axis|.
+ const WorldRotation rotation = WorldRotation(
+ AngleAxisf(rotation_angle * kRadiansFromDegrees, rotation_axis));
+ const bool result = foa_rotator_->Process(rotation, encoded_rotated_buffer,
+ &encoded_rotated_buffer);
+ EXPECT_TRUE(result);
+ // Check if the sound source in the reference and rotated buffers are in the
+ // same direction.
+ // If the buffer size is more than |kSlerpFrameInterval|, due to
+ // interpolation, we expect that the last |kSlerpFrameInterval| frames have
+ // reached the target rotation.
+ // If the buffer size is less than |kSlerpFrameInterval|, because no
+ // interpolation is applied, the rotated soundfield should result from
+ // frame 0.
+ for (size_t channel = 0; channel < encoded_rotated_buffer.num_channels();
+ ++channel) {
+ const int num_frames =
+ static_cast<int>(encoded_rotated_buffer[channel].size());
+ const int interval = static_cast<int>(kSlerpFrameInterval);
+ const int frames_to_compare =
+ (num_frames % interval) ? (num_frames % interval) : interval;
+ const int start_frame = std::max(0, num_frames - frames_to_compare);
+ ASSERT_LT(start_frame, num_frames);
+ for (int frame = start_frame; frame < num_frames; ++frame) {
+ EXPECT_NEAR(encoded_rotated_buffer[channel][frame],
+ encoded_reference_buffer[channel][frame], kEpsilonFloat);
+ }
+ }
+ }
+
+ // First Order Ambisonic rotator instance.
+ std::unique_ptr<FoaRotator> foa_rotator_;
+};
+
+// Tests that no rotation is aplied if |kRotationQuantizationRad| is not
+// exceeded.
+TEST_F(FoaRotatorTest, RotationThresholdTest) {
+ const size_t kFramesPerBuffer = 16;
+ const std::vector<float> kInputVector(
+ kFramesPerBuffer * kNumFirstOrderAmbisonicChannels, 1.0f);
+ AudioBuffer input_buffer(kNumFirstOrderAmbisonicChannels, kFramesPerBuffer);
+ FillAudioBuffer(kInputVector, kNumFirstOrderAmbisonicChannels, &input_buffer);
+ AudioBuffer output_buffer(kNumFirstOrderAmbisonicChannels, kFramesPerBuffer);
+ const WorldRotation kSmallRotation =
+ WorldRotation(1.0f, 0.001f, 0.001f, 0.001f);
+ const WorldRotation kLargeRotation = WorldRotation(1.0f, 0.1f, 0.1f, 0.1f);
+ EXPECT_FALSE(
+ foa_rotator_->Process(kSmallRotation, input_buffer, &output_buffer));
+ EXPECT_TRUE(
+ foa_rotator_->Process(kLargeRotation, input_buffer, &output_buffer));
+}
+
+typedef tuple<WorldPosition, SphericalAngle> TestParams;
+class FoaAxesRotationTest : public FoaRotatorTest,
+ public ::testing::WithParamInterface<TestParams> {};
+
+// Tests first order soundfield rotation against the x, y and z axis using long
+// input buffers (>> slerp interval).
+TEST_P(FoaAxesRotationTest, CompareWithExpectedAngleLongBuffer) {
+ const WorldPosition& rotation_axis = ::testing::get<0>(GetParam());
+ const SphericalAngle& expected_angle = ::testing::get<1>(GetParam());
+ const size_t kLongFramesPerBuffer = 512;
+ const std::vector<float> kLongInputData(kLongFramesPerBuffer, 1.0f);
+ CompareRotatedAndReferenceSoundfields(kLongInputData, kAngleDegrees,
+ rotation_axis, expected_angle);
+}
+
+// Tests first order soundfield rotation against the x, y and z axes using short
+// input buffers (< slerp interval).
+TEST_P(FoaAxesRotationTest, CompareWithExpectedAngleShortBuffer) {
+ const WorldPosition& rotation_axis = ::testing::get<0>(GetParam());
+ const SphericalAngle& expected_angle = ::testing::get<1>(GetParam());
+ const size_t kShortFramesPerBuffer = kSlerpFrameInterval / 2;
+ const std::vector<float> kShortInputData(kShortFramesPerBuffer, 1.0f);
+ CompareRotatedAndReferenceSoundfields(kShortInputData, kAngleDegrees,
+ rotation_axis, expected_angle);
+}
+
+// Tests first order soundfield rotation against the x, y and z axes using
+// buffer sizes that are (> slerp interval) and not integer multiples of
+// the slerp interval.
+TEST_P(FoaAxesRotationTest, CompareWithExpectedAngleOddBufferSizes) {
+ const WorldPosition& rotation_axis = ::testing::get<0>(GetParam());
+ const SphericalAngle& expected_angle = ::testing::get<1>(GetParam());
+ const size_t frames_per_buffer = kSlerpFrameInterval + 3U;
+ const std::vector<float> kShortInputData(frames_per_buffer, 1.0f);
+ CompareRotatedAndReferenceSoundfields(kShortInputData, kAngleDegrees,
+ rotation_axis, expected_angle);
+}
+
+INSTANTIATE_TEST_CASE_P(
+ TestParameters, FoaAxesRotationTest,
+ Values(TestParams({1.0f, 0.0f, 0.0f}, kXrotatedSourceAngle),
+ TestParams({0.0f, 1.0f, 0.0f}, kYrotatedSourceAngle),
+ TestParams({0.0f, 0.0f, 1.0f}, kZrotatedSourceAngle)));
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator.cc
new file mode 100644
index 000000000..a76575e22
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator.cc
@@ -0,0 +1,308 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/hoa_rotator.h"
+
+#include <algorithm>
+#include <cmath>
+
+#include "ambisonics/utils.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+namespace {
+
+// Below are the helper methods to compute SH rotation using recursion. The code
+// is branched / modified from:
+
+// maths described in the following papers:
+//
+// [1] R. Green, "Spherical Harmonic Lighting: The Gritty Details", GDC 2003,
+// http://www.research.scea.com/gdc2003/spherical-harmonic-lighting.pdf
+// [2] J. Ivanic and K. Ruedenberg, "Rotation Matrices for Real Spherical
+// Harmonics. Direct Determination by Recursion", J. Phys. Chem., vol. 100,
+// no. 15, pp. 6342-6347, 1996.
+// http://pubs.acs.org/doi/pdf/10.1021/jp953350u
+// [2b] Corrections to initial publication:
+// http://pubs.acs.org/doi/pdf/10.1021/jp9833350
+
+// Kronecker Delta function.
+inline float KroneckerDelta(int i, int j) { return (i == j) ? 1.0f : 0.0f; }
+
+// [2] uses an odd convention of referring to the rows and columns using
+// centered indices, so the middle row and column are (0, 0) and the upper
+// left would have negative coordinates.
+//
+// This is a convenience function to allow us to access an Eigen::MatrixXf
+// in the same manner, assuming r is a (2l+1)x(2l+1) matrix.
+float GetCenteredElement(const Eigen::MatrixXf& r, int i, int j) {
+ // The shift to go from [-l, l] to [0, 2l] is (rows - 1) / 2 = l,
+ // (since the matrix is assumed to be square, rows == cols).
+ const int offset = (static_cast<int>(r.rows()) - 1) / 2;
+ return r(i + offset, j + offset);
+}
+
+// Helper function defined in [2] that is used by the functions U, V, W.
+// This should not be called on its own, as U, V, and W (and their coefficients)
+// select the appropriate matrix elements to access arguments |a| and |b|.
+float P(int i, int a, int b, int l, const std::vector<Eigen::MatrixXf>& r) {
+ if (b == l) {
+ return GetCenteredElement(r[1], i, 1) *
+ GetCenteredElement(r[l - 1], a, l - 1) -
+ GetCenteredElement(r[1], i, -1) *
+ GetCenteredElement(r[l - 1], a, -l + 1);
+ } else if (b == -l) {
+ return GetCenteredElement(r[1], i, 1) *
+ GetCenteredElement(r[l - 1], a, -l + 1) +
+ GetCenteredElement(r[1], i, -1) *
+ GetCenteredElement(r[l - 1], a, l - 1);
+ } else {
+ return GetCenteredElement(r[1], i, 0) * GetCenteredElement(r[l - 1], a, b);
+ }
+}
+
+// The functions U, V, and W should only be called if the correspondingly
+// named coefficient u, v, w from the function ComputeUVWCoeff() is non-zero.
+// When the coefficient is 0, these would attempt to access matrix elements that
+// are out of bounds. The vector of rotations, |r|, must have the |l - 1|
+// previously completed band rotations. These functions are valid for |l >= 2|.
+
+float U(int m, int n, int l, const std::vector<Eigen::MatrixXf>& r) {
+ // Although [1, 2] split U into three cases for m == 0, m < 0, m > 0
+ // the actual values are the same for all three cases.
+ return P(0, m, n, l, r);
+}
+
+float V(int m, int n, int l, const std::vector<Eigen::MatrixXf>& r) {
+ if (m == 0) {
+ return P(1, 1, n, l, r) + P(-1, -1, n, l, r);
+ } else if (m > 0) {
+ const float d = KroneckerDelta(m, 1);
+ return P(1, m - 1, n, l, r) * std::sqrt(1 + d) -
+ P(-1, -m + 1, n, l, r) * (1 - d);
+ } else {
+ // Note there is apparent errata in [1,2,2b] dealing with this particular
+ // case. [2b] writes it should be P*(1-d)+P*(1-d)^0.5
+ // [1] writes it as P*(1+d)+P*(1-d)^0.5, but going through the math by hand,
+ // you must have it as P*(1-d)+P*(1+d)^0.5 to form a 2^.5 term, which
+ // parallels the case where m > 0.
+ const float d = KroneckerDelta(m, -1);
+ return P(1, m + 1, n, l, r) * (1 - d) +
+ P(-1, -m - 1, n, l, r) * std::sqrt(1 + d);
+ }
+}
+
+float W(int m, int n, int l, const std::vector<Eigen::MatrixXf>& r) {
+ if (m == 0) {
+ // Whenever this happens, w is also 0 so W can be anything.
+ return 0.0f;
+ } else if (m > 0) {
+ return P(1, m + 1, n, l, r) + P(-1, -m - 1, n, l, r);
+ } else {
+ return P(1, m - 1, n, l, r) - P(-1, -m + 1, n, l, r);
+ }
+}
+
+// Calculates the coefficients applied to the U, V, and W functions. Because
+// their equations share many common terms they are computed simultaneously.
+void ComputeUVWCoeff(int m, int n, int l, float* u, float* v, float* w) {
+ const float d = KroneckerDelta(m, 0);
+ const float denom = (abs(n) == l ? static_cast<float>(2 * l * (2 * l - 1))
+ : static_cast<float>((l + n) * (l - n)));
+ const float one_over_denom = 1.0f / denom;
+
+ *u = std::sqrt(static_cast<float>((l + m) * (l - m)) * one_over_denom);
+ *v = 0.5f *
+ std::sqrt((1.0f + d) * static_cast<float>(l + abs(m) - 1) *
+ (static_cast<float>(l + abs(m))) * one_over_denom) *
+ (1.0f - 2.0f * d);
+ *w = -0.5f *
+ std::sqrt(static_cast<float>(l - abs(m) - 1) *
+ (static_cast<float>(l - abs(m))) * one_over_denom) *
+ (1.0f - d);
+}
+
+// Calculates the (2l+1)x(2l+1) rotation matrix for the band l.
+// This uses the matrices computed for band 1 and band l-1 to compute the
+// matrix for band l. |rotations| must contain the previously computed l-1
+// rotation matrices.
+//
+// This implementation comes from p. 5 (6346), Table 1 and 2 in [2] taking
+// into account the corrections from [2b].
+void ComputeBandRotation(int l, std::vector<Eigen::MatrixXf>* rotations) {
+ // The lth band rotation matrix has rows and columns equal to the number of
+ // coefficients within that band (-l <= m <= l implies 2l + 1 coefficients).
+ Eigen::MatrixXf rotation(2 * l + 1, 2 * l + 1);
+ for (int m = -l; m <= l; ++m) {
+ for (int n = -l; n <= l; ++n) {
+ float u, v, w;
+ ComputeUVWCoeff(m, n, l, &u, &v, &w);
+
+ // The functions U, V, W are only safe to call if the coefficients
+ // u, v, w are not zero.
+ if (std::abs(u) > 0.0f) u *= U(m, n, l, *rotations);
+ if (std::abs(v) > 0.0f) v *= V(m, n, l, *rotations);
+ if (std::abs(w) > 0.0f) w *= W(m, n, l, *rotations);
+
+ rotation(m + l, n + l) = (u + v + w);
+ }
+ }
+ (*rotations)[l] = rotation;
+}
+
+} // namespace
+
+HoaRotator::HoaRotator(int ambisonic_order)
+ : ambisonic_order_(ambisonic_order),
+ rotation_matrices_(ambisonic_order_ + 1),
+ rotation_matrix_(
+ static_cast<int>(GetNumPeriphonicComponents(ambisonic_order)),
+ static_cast<int>(GetNumPeriphonicComponents(ambisonic_order))) {
+ DCHECK_GE(ambisonic_order_, 2);
+
+ // Initialize rotation sub-matrices.
+ // Order 0 matrix (first band) is simply the 1x1 identity.
+ Eigen::MatrixXf r(1, 1);
+ r(0, 0) = 1.0f;
+ rotation_matrices_[0] = r;
+ // All the other ambisonic orders (bands) are set to identity matrices of
+ // corresponding sizes.
+ for (int l = 1; l <= ambisonic_order_; ++l) {
+ const size_t submatrix_size = GetNumNthOrderPeriphonicComponents(l);
+ r.resize(submatrix_size, submatrix_size);
+ rotation_matrices_[l] = r.setIdentity();
+ }
+ // Initialize the final rotation matrix to an identity matrix.
+ rotation_matrix_.setIdentity();
+}
+
+bool HoaRotator::Process(const WorldRotation& target_rotation,
+ const AudioBuffer& input, AudioBuffer* output) {
+
+ DCHECK(output);
+ DCHECK_EQ(input.num_channels(), GetNumPeriphonicComponents(ambisonic_order_));
+ DCHECK_EQ(input.num_channels(), output->num_channels());
+ DCHECK_EQ(input.num_frames(), output->num_frames());
+
+ static const WorldRotation kIdentityRotation;
+
+ if (current_rotation_.AngularDifferenceRad(kIdentityRotation) <
+ kRotationQuantizationRad &&
+ target_rotation.AngularDifferenceRad(kIdentityRotation) <
+ kRotationQuantizationRad) {
+ return false;
+ }
+
+ const size_t channel_stride = input.GetChannelStride();
+
+ typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
+ RowMajorMatrixf;
+
+ const Eigen::Map<const RowMajorMatrixf, Eigen::Aligned, Eigen::OuterStride<>>
+ input_matrix(input[0].begin(), static_cast<int>(input.num_channels()),
+ static_cast<int>(input.num_frames()),
+ Eigen::OuterStride<>(static_cast<int>(channel_stride)));
+
+ Eigen::Map<RowMajorMatrixf, Eigen::Aligned, Eigen::OuterStride<>>
+ output_matrix((*output)[0].begin(),
+ static_cast<int>(input.num_channels()),
+ static_cast<int>(input.num_frames()),
+ Eigen::OuterStride<>(static_cast<int>(channel_stride)));
+
+ if (current_rotation_.AngularDifferenceRad(target_rotation) <
+ kRotationQuantizationRad) {
+ output_matrix = rotation_matrix_ * input_matrix;
+ return true;
+ }
+
+ // In order to perform a smooth rotation, we divide the buffer into
+ // chunks of size |kSlerpFrameInterval|.
+ //
+
+ const size_t kSlerpFrameInterval = 32;
+
+ WorldRotation slerped_rotation;
+ // Rotate the input buffer at every slerp update interval. Truncate the
+ // final chunk if the input buffer is not an integer multiple of the
+ // chunk size.
+ for (size_t i = 0; i < input.num_frames(); i += kSlerpFrameInterval) {
+ const size_t duration =
+ std::min(input.num_frames() - i, kSlerpFrameInterval);
+ const float interpolation_factor = static_cast<float>(i + duration) /
+ static_cast<float>(input.num_frames());
+ UpdateRotationMatrix(
+ current_rotation_.slerp(interpolation_factor, target_rotation));
+ output_matrix.block(0 /* first channel */, i, output->num_channels(),
+ duration) =
+ rotation_matrix_ * input_matrix.block(0 /* first channel */, i,
+ input.num_channels(), duration);
+ }
+ current_rotation_ = target_rotation;
+
+ return true;
+}
+
+void HoaRotator::UpdateRotationMatrix(const WorldRotation& rotation) {
+
+
+ // There is no need to update 0th order 1-element sub-matrix.
+ // First order sub-matrix can be updated directly from the WorldRotation
+ // quaternion. However, we must account for the flipped left-right and
+ // front-back axis in the World coordinates.
+ AudioRotation rotation_audio_space;
+ ConvertAudioFromWorldRotation(rotation, &rotation_audio_space);
+ rotation_matrices_[1] = rotation_audio_space.toRotationMatrix();
+ rotation_matrix_.block(1, 1, 3, 3) = rotation_matrices_[1];
+
+ // Sub-matrices for the remaining orders are updated recursively using the
+ // equations provided in [2, 2b]. An example final rotation matrix composed of
+ // sub-matrices of orders 0 to 3 has the following structure:
+ //
+ // X | 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 0 0
+ // -------------------------------------
+ // 0 | X X X | 0 0 0 0 0 | 0 0 0 0 0 0 0
+ // 0 | X X X | 0 0 0 0 0 | 0 0 0 0 0 0 0
+ // 0 | X X X | 0 0 0 0 0 | 0 0 0 0 0 0 0
+ // -------------------------------------
+ // 0 | 0 0 0 | X X X X X | 0 0 0 0 0 0 0
+ // 0 | 0 0 0 | X X X X X | 0 0 0 0 0 0 0
+ // 0 | 0 0 0 | X X X X X | 0 0 0 0 0 0 0
+ // 0 | 0 0 0 | X X X X X | 0 0 0 0 0 0 0
+ // 0 | 0 0 0 | X X X X X | 0 0 0 0 0 0 0
+ // -------------------------------------
+ // 0 | 0 0 0 | 0 0 0 0 0 | X X X X X X X
+ // 0 | 0 0 0 | 0 0 0 0 0 | X X X X X X X
+ // 0 | 0 0 0 | 0 0 0 0 0 | X X X X X X X
+ // 0 | 0 0 0 | 0 0 0 0 0 | X X X X X X X
+ // 0 | 0 0 0 | 0 0 0 0 0 | X X X X X X X
+ // 0 | 0 0 0 | 0 0 0 0 0 | X X X X X X X
+ // 0 | 0 0 0 | 0 0 0 0 0 | X X X X X X X
+ //
+ for (int current_order = 2; current_order <= ambisonic_order_;
+ ++current_order) {
+ ComputeBandRotation(current_order, &rotation_matrices_);
+ const int index = current_order * current_order;
+ const int size =
+ static_cast<int>(GetNumNthOrderPeriphonicComponents(current_order));
+ rotation_matrix_.block(index, index, size, size) =
+ rotation_matrices_[current_order];
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator.h b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator.h
new file mode 100644
index 000000000..956811df4
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator.h
@@ -0,0 +1,69 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_AMBISONICS_HOA_ROTATOR_H_
+#define RESONANCE_AUDIO_AMBISONICS_HOA_ROTATOR_H_
+
+#include <vector>
+
+#include "Eigen/Dense"
+#include "base/audio_buffer.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+// Rotator for higher order ambisonic sound fields. It supports ACN channel
+// ordering and SN3D normalization (AmbiX).
+class HoaRotator {
+ public:
+ // Constructs a sound field rotator of an arbitrary ambisonic order.
+ //
+ // @param ambisonic_order Order of ambisonic sound field.
+ explicit HoaRotator(int ambisonic_order);
+
+ // Performs a smooth inplace rotation of a sound field buffer from
+ // |current_rotation_| to |target_rotation|.
+ //
+ // @param target_rotation Target rotation to be applied to the input buffer.
+ // @param input Higher order sound field input buffer to be rotated.
+ // @param output Pointer to output buffer.
+ // @return True if rotation has been applied.
+ bool Process(const WorldRotation& target_rotation, const AudioBuffer& input,
+ AudioBuffer* output);
+
+ private:
+ // Updates the rotation matrix with using supplied WorldRotation.
+ //
+ // @param rotation World rotation.
+ void UpdateRotationMatrix(const WorldRotation& rotation);
+
+ // Order of the ambisonic sound field handled by the rotator.
+ const int ambisonic_order_;
+
+ // Current rotation which is used in the interpolation process in order to
+ // compute new rotation matrix. Initialized with an identity rotation.
+ WorldRotation current_rotation_;
+
+ // Spherical harmonics rotation sub-matrices for each order.
+ std::vector<Eigen::MatrixXf> rotation_matrices_;
+
+ // Final spherical harmonics rotation matrix.
+ Eigen::MatrixXf rotation_matrix_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_AMBISONICS_HOA_ROTATOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator_test.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator_test.cc
new file mode 100644
index 000000000..6472412c9
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/hoa_rotator_test.cc
@@ -0,0 +1,201 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/hoa_rotator.h"
+
+#include <algorithm>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "ambisonics/ambisonic_codec_impl.h"
+#include "base/constants_and_types.h"
+#include "utils/planar_interleaved_conversion.h"
+
+namespace vraudio {
+
+namespace {
+
+using testing::tuple;
+using testing::Values;
+
+const int kAmbisonicOrder = 3;
+
+// Rotation angle used in the test.
+const float kAngleDegrees = 90.0f;
+
+// Initial, arbitrary direction of the encoded soundfield source.
+const SphericalAngle kInitialSourceAngle =
+ SphericalAngle::FromDegrees(22.0f, 33.0f);
+
+// Expected direction of the sound source rotated by |kAngleDegrees| against the
+// right facing axis (x in the world coordinate system).
+const SphericalAngle kXrotatedSourceAngle =
+ SphericalAngle::FromDegrees(150.021778639249f, 51.0415207997462f);
+
+// Expected direction of the sound source rotated by |kAngleDegrees| against the
+// upward facing axis (y in the world coordinate system).
+const SphericalAngle kYrotatedSourceAngle =
+ SphericalAngle::FromDegrees(112.0f, 33.0f);
+
+// Expected direction of the sound source rotated by |kAngleDegrees| against the
+// back facing axis (z in the world coordinate system).
+const SphericalAngle kZrotatedSourceAngle =
+ SphericalAngle::FromDegrees(35.0077312770459f, -18.3108067341351f);
+
+// Rotation interpolation interval in terms of frames (used by the HoaRotator).
+const size_t kSlerpFrameInterval = 32;
+
+class HoaRotatorTest : public ::testing::Test {
+ protected:
+ HoaRotatorTest() {}
+
+ // Virtual methods from ::testing::Test
+ ~HoaRotatorTest() override {}
+
+ void SetUp() override {
+ // Initialize the third order soundfield rotator.
+ hoa_rotator_ = std::unique_ptr<HoaRotator>(new HoaRotator(kAmbisonicOrder));
+ }
+
+ void TearDown() override {}
+
+ // Test method which creates a HOA soundfield buffer, rotates it by
+ // |rotation_angle| against |rotation_axis|, and compares the output to the
+ // reference soundfield buffer (where the source is already spatialized at the
+ // |expected_source_angle|).
+ void CompareRotatedAndReferenceSoundfields(
+ const std::vector<float>& input_data, float rotation_angle,
+ const WorldPosition& rotation_axis,
+ const SphericalAngle& expected_source_angle) {
+ AudioBuffer input_buffer(1, input_data.size());
+ FillAudioBuffer(input_data, 1, &input_buffer);
+ // Initialize a third order mono codec with the |kInitialSourceAngle|. This
+ // will be used to obtain the rotated soundfield.
+ std::unique_ptr<MonoAmbisonicCodec<>> rotated_source_mono_codec(
+ new MonoAmbisonicCodec<>(kAmbisonicOrder, {kInitialSourceAngle}));
+ // Initialize a third order mono codec with the expected source angle. This
+ // will be used as a reference for the rotated soundfield.
+ std::unique_ptr<MonoAmbisonicCodec<>> reference_source_mono_codec(
+ new MonoAmbisonicCodec<>(kAmbisonicOrder, {expected_source_angle}));
+ // Generate soundfield buffers representing sound sources at required
+ // angles.
+ AudioBuffer encoded_rotated_buffer(kNumThirdOrderAmbisonicChannels,
+ input_data.size());
+ AudioBuffer encoded_reference_buffer(kNumThirdOrderAmbisonicChannels,
+ input_data.size());
+ rotated_source_mono_codec->EncodeBuffer(input_buffer,
+ &encoded_rotated_buffer);
+ reference_source_mono_codec->EncodeBuffer(input_buffer,
+ &encoded_reference_buffer);
+ // Rotate the test soundfield by |rotation_angle| degrees wrt the given
+ // |rotation_axis|.
+ const WorldRotation rotation = WorldRotation(
+ AngleAxisf(rotation_angle * kRadiansFromDegrees, rotation_axis));
+ const bool result = hoa_rotator_->Process(rotation, encoded_rotated_buffer,
+ &encoded_rotated_buffer);
+ EXPECT_TRUE(result);
+ // Check if the sound source in the reference and rotated buffers are in the
+ // same direction.
+ // If the buffer size is more than |kSlerpFrameInterval|, due to
+ // interpolation, we expect that the last |kSlerpFrameInterval| frames have
+ // undergone the full rotation.
+ // If the buffer size is less than |kSlerpFrameInterval|, because no
+ // interpolation is applied, the rotated soundfield should result from
+ // frame 0.
+ for (size_t channel = 0; channel < encoded_rotated_buffer.num_channels();
+ ++channel) {
+ const int num_frames =
+ static_cast<int>(encoded_rotated_buffer[channel].size());
+ const int interval = static_cast<int>(kSlerpFrameInterval);
+ const int frames_to_compare =
+ (num_frames % interval) ? (num_frames % interval) : interval;
+ const int start_frame = std::max(0, num_frames - frames_to_compare);
+ ASSERT_LT(start_frame, num_frames);
+ for (int frame = start_frame; frame < num_frames; ++frame) {
+ EXPECT_NEAR(encoded_rotated_buffer[channel][frame],
+ encoded_reference_buffer[channel][frame], kEpsilonFloat);
+ }
+ }
+ }
+
+ // Higher Order Ambisonic rotator instance.
+ std::unique_ptr<HoaRotator> hoa_rotator_;
+};
+
+// Tests that no rotation is aplied if |kRotationQuantizationRad| is not
+// exceeded.
+TEST_F(HoaRotatorTest, RotationThresholdTest) {
+ const size_t kFramesPerBuffer = 16;
+ const std::vector<float> kInputVector(
+ kFramesPerBuffer * kNumThirdOrderAmbisonicChannels, 1.0f);
+ AudioBuffer input_buffer(kNumThirdOrderAmbisonicChannels, kFramesPerBuffer);
+ FillAudioBuffer(kInputVector, kNumThirdOrderAmbisonicChannels, &input_buffer);
+ AudioBuffer output_buffer(kNumThirdOrderAmbisonicChannels, kFramesPerBuffer);
+ const WorldRotation kSmallRotation =
+ WorldRotation(1.0f, 0.001f, 0.001f, 0.001f);
+ const WorldRotation kLargeRotation = WorldRotation(1.0f, 0.1f, 0.1f, 0.1f);
+ EXPECT_FALSE(
+ hoa_rotator_->Process(kSmallRotation, input_buffer, &output_buffer));
+ EXPECT_TRUE(
+ hoa_rotator_->Process(kLargeRotation, input_buffer, &output_buffer));
+}
+
+typedef tuple<WorldPosition, SphericalAngle> TestParams;
+class HoaAxesRotationTest : public HoaRotatorTest,
+ public ::testing::WithParamInterface<TestParams> {};
+
+// Tests third order soundfield rotation against the x, y and z axis using long
+// input buffers (>> slerp interval).
+TEST_P(HoaAxesRotationTest, CompareWithExpectedAngleLongBuffer) {
+ const WorldPosition& rotation_axis = ::testing::get<0>(GetParam());
+ const SphericalAngle& expected_angle = ::testing::get<1>(GetParam());
+ const size_t kLongFramesPerBuffer = 512;
+ const std::vector<float> kLongInputData(kLongFramesPerBuffer, 1.0f);
+ CompareRotatedAndReferenceSoundfields(kLongInputData, kAngleDegrees,
+ rotation_axis, expected_angle);
+}
+
+// Tests third order soundfield rotation against the x, y and z axes using short
+// input buffers (< slerp interval).
+TEST_P(HoaAxesRotationTest, CompareWithExpectedAngleShortBuffer) {
+ const WorldPosition& rotation_axis = ::testing::get<0>(GetParam());
+ const SphericalAngle& expected_angle = ::testing::get<1>(GetParam());
+ const size_t kShortFramesPerBuffer = kSlerpFrameInterval / 2;
+ const std::vector<float> kShortInputData(kShortFramesPerBuffer, 1.0f);
+ CompareRotatedAndReferenceSoundfields(kShortInputData, kAngleDegrees,
+ rotation_axis, expected_angle);
+}
+
+// Tests third order soundfield rotation against the x, y and z axes using
+// buffer sizes that are (> slerp interval) and not integer multiples of
+// the slerp interval.
+TEST_P(HoaAxesRotationTest, CompareWithExpectedAngleOddBufferSizes) {
+ const WorldPosition& rotation_axis = ::testing::get<0>(GetParam());
+ const SphericalAngle& expected_angle = ::testing::get<1>(GetParam());
+ const size_t frames_per_buffer = kSlerpFrameInterval + 3U;
+ const std::vector<float> kShortInputData(frames_per_buffer, 1.0f);
+ CompareRotatedAndReferenceSoundfields(kShortInputData, kAngleDegrees,
+ rotation_axis, expected_angle);
+}
+
+INSTANTIATE_TEST_CASE_P(
+ TestParameters, HoaAxesRotationTest,
+ Values(TestParams({1.0f, 0.0f, 0.0f}, kXrotatedSourceAngle),
+ TestParams({0.0f, 1.0f, 0.0f}, kYrotatedSourceAngle),
+ TestParams({0.0f, 0.0f, 1.0f}, kZrotatedSourceAngle)));
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter.cc
new file mode 100644
index 000000000..94462a445
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter.cc
@@ -0,0 +1,52 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/stereo_from_soundfield_converter.h"
+
+#include "base/constants_and_types.h"
+#include "dsp/gain.h"
+
+namespace vraudio {
+
+namespace {
+
+const float kMidSideChannelGain = 0.5f;
+
+} // namespace
+
+void StereoFromSoundfield(const AudioBuffer& soundfield_input,
+ AudioBuffer* stereo_output) {
+ DCHECK(stereo_output);
+ DCHECK_EQ(kNumStereoChannels, stereo_output->num_channels());
+ DCHECK_EQ(soundfield_input.num_frames(), stereo_output->num_frames());
+ DCHECK_GE(soundfield_input.num_channels(), kNumFirstOrderAmbisonicChannels);
+ const AudioBuffer::Channel& channel_audio_space_w = soundfield_input[0];
+ const AudioBuffer::Channel& channel_audio_space_y = soundfield_input[1];
+ AudioBuffer::Channel* left_channel_output = &(*stereo_output)[0];
+ AudioBuffer::Channel* right_channel_output = &(*stereo_output)[1];
+ // Left = 0.5 * (Mid + Side).
+ *left_channel_output = channel_audio_space_w;
+ *left_channel_output += channel_audio_space_y;
+ ConstantGain(0 /* no offset */, kMidSideChannelGain, *left_channel_output,
+ left_channel_output, false /* accumulate_output */);
+ // Right = 0.5 * (Mid - Side).
+ *right_channel_output = channel_audio_space_w;
+ *right_channel_output -= channel_audio_space_y;
+ ConstantGain(0 /* no offset */, kMidSideChannelGain, *right_channel_output,
+ right_channel_output, false /* accumulate_output */);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter.h b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter.h
new file mode 100644
index 000000000..44d2144e7
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter.h
@@ -0,0 +1,35 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_AMBISONICS_STEREO_FROM_SOUNDFIELD_CONVERTER_H_
+#define RESONANCE_AUDIO_AMBISONICS_STEREO_FROM_SOUNDFIELD_CONVERTER_H_
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Performs Ambisonic to stereo decode by performing Mid-Side (M-S) matrixing.
+// Soundfield format assumed is Ambix (ACN/SN3D). Only first order channels
+// are used for the stereo decode.
+//
+// @param soundfield_input Soundfield of arbitrary order.
+// @param stereo_output Pointer to stereo output buffer.
+void StereoFromSoundfield(const AudioBuffer& soundfield_input,
+ AudioBuffer* stereo_output);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_AMBISONICS_STEREO_FROM_SOUNDFIELD_CONVERTER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter_test.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter_test.cc
new file mode 100644
index 000000000..aa1f5c70a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/stereo_from_soundfield_converter_test.cc
@@ -0,0 +1,103 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/stereo_from_soundfield_converter.h"
+
+#include <iterator>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "utils/planar_interleaved_conversion.h"
+
+namespace vraudio {
+
+namespace {
+
+// Number of frames per buffer.
+const size_t kFramesPerBuffer = 2;
+
+// First order ambisonic signal in the AmbiX format (W, Y, Z, X), sound source
+// in the front.
+const float kFirstOrderSourceFront[] = {1.0f, 0.0f, 0.0f, 1.0f,
+ 1.0f, 0.0f, 0.0f, 1.0f};
+
+// First order ambisonic signal in the AmbiX format (W, Y, Z, X), sound source
+// to the left.
+const float kFirstOrderSourceLeft[] = {1.0f, 1.0f, 0.0f, 0.0f,
+ 1.0f, 1.0f, 0.0f, 0.0f};
+
+// Tests whether the conversion to stereo from soundfield results in equal
+// signal in both L/R output channels when there is a single source in front of
+// the soundfield.
+TEST(StereoFromSoundfieldConverterTest, StereoFromSoundfieldFrontTest) {
+ // Initialize the soundfield input buffer.
+ const std::vector<float> soundfield_data(std::begin(kFirstOrderSourceFront),
+ std::end(kFirstOrderSourceFront));
+ AudioBuffer soundfield_buffer(
+ kNumFirstOrderAmbisonicChannels,
+ soundfield_data.size() / kNumFirstOrderAmbisonicChannels);
+ FillAudioBuffer(soundfield_data, kNumFirstOrderAmbisonicChannels,
+ &soundfield_buffer);
+
+ // Output buffer is stereo.
+ AudioBuffer output(kNumStereoChannels,
+ soundfield_data.size() / kNumFirstOrderAmbisonicChannels);
+
+ StereoFromSoundfield(soundfield_buffer, &output);
+
+ // Test for near equality.
+ ASSERT_EQ(kNumStereoChannels, output.num_channels());
+ const AudioBuffer::Channel& output_channel_left = output[0];
+ const AudioBuffer::Channel& output_channel_right = output[1];
+ for (size_t frame = 0; frame < kFramesPerBuffer; ++frame) {
+ EXPECT_NEAR(output_channel_left[frame], output_channel_right[frame],
+ kEpsilonFloat);
+ }
+}
+
+// Tests whether the conversion to stereo from soundfield, when the sound source
+// in the soundfield is to the left, results in a signal only in the L output
+// channel.
+TEST(StereoFromSoundfieldConverterTest, StereoFromSoundfieldLeftTest) {
+ // Initialize the soundfield input buffer.
+ const std::vector<float> soundfield_data(std::begin(kFirstOrderSourceLeft),
+ std::end(kFirstOrderSourceLeft));
+ AudioBuffer soundfield_buffer(
+ kNumFirstOrderAmbisonicChannels,
+ soundfield_data.size() / kNumFirstOrderAmbisonicChannels);
+ FillAudioBuffer(soundfield_data, kNumFirstOrderAmbisonicChannels,
+ &soundfield_buffer);
+
+ // Output buffer is stereo.
+ AudioBuffer output(kNumStereoChannels,
+ soundfield_data.size() / kNumFirstOrderAmbisonicChannels);
+
+ StereoFromSoundfield(soundfield_buffer, &output);
+
+ // Test for near equality.
+ ASSERT_EQ(kNumStereoChannels, output.num_channels());
+ const AudioBuffer::Channel& output_channel_left = output[0];
+ const AudioBuffer::Channel& output_channel_right = output[1];
+ for (size_t frame = 0; frame < kFramesPerBuffer; ++frame) {
+ EXPECT_NEAR(output_channel_left[frame], 1.0f, kEpsilonFloat);
+ EXPECT_NEAR(output_channel_right[frame], 0.0f, kEpsilonFloat);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/utils.h b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/utils.h
new file mode 100644
index 000000000..8c71944d6
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/utils.h
@@ -0,0 +1,120 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_AMBISONICS_UTILS_H_
+#define RESONANCE_AUDIO_AMBISONICS_UTILS_H_
+
+#include <cmath>
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+// Returns ACN channel sequence from a degree and order of a spherical harmonic.
+inline int AcnSequence(int degree, int order) {
+ DCHECK_GE(degree, 0);
+ DCHECK_LE(-degree, order);
+ DCHECK_LE(order, degree);
+
+ return degree * degree + degree + order;
+}
+
+// Returns normalization factor for Schmidt semi-normalized spherical harmonics
+// used in AmbiX.
+inline float Sn3dNormalization(int degree, int order) {
+ DCHECK_GE(degree, 0);
+ DCHECK_LE(-degree, order);
+ DCHECK_LE(order, degree);
+ return std::sqrt((2.0f - ((order == 0) ? 1.0f : 0.0f)) *
+ Factorial(degree - std::abs(order)) /
+ Factorial(degree + std::abs(order)));
+}
+
+// Returns the number of spherical harmonics for a periphonic ambisonic sound
+// field of |ambisonic_order| at compile-time.
+// We have to use template metaprogramming because MSVC12 doesn't support
+// constexpr.
+template <size_t AmbisonicOrder>
+struct GetNumPeriphonicComponentsStatic {
+ enum { value = (AmbisonicOrder + 1) * (AmbisonicOrder + 1) };
+};
+
+// Returns the number of spherical harmonics for a periphonic ambisonic sound
+// field of |ambisonic_order|.
+inline size_t GetNumPeriphonicComponents(int ambisonic_order) {
+ return static_cast<size_t>((ambisonic_order + 1) * (ambisonic_order + 1));
+}
+
+// Returns the number of periphonic spherical harmonics (SHs) for a particular
+// Ambisonic order. E.g. number of 1st, 2nd or 3rd degree SHs in a 3rd order
+// sound field.
+inline size_t GetNumNthOrderPeriphonicComponents(int ambisonic_order) {
+ if (ambisonic_order == 0) return 1;
+ return static_cast<size_t>(GetNumPeriphonicComponents(ambisonic_order) -
+ GetNumPeriphonicComponents(ambisonic_order - 1));
+}
+
+// Calculates the ambisonic order of a periphonic sound field with the given
+// number of spherical harmonics.
+inline int GetPeriphonicAmbisonicOrder(size_t num_components) {
+ DCHECK_GT(num_components, 0);
+ const int ambisonic_order = static_cast<int>(std::sqrt(num_components)) - 1;
+ // Detect when num_components is not square.
+ DCHECK_EQ((ambisonic_order + 1) * (ambisonic_order + 1),
+ static_cast<int>(num_components));
+ return ambisonic_order;
+}
+
+// Calculates the order of the current spherical harmonic channel as the integer
+// part of a square root of the channel number. Please note, that in Ambisonics
+// the terms 'order' (usually denoted as 'n') and 'degree' (usually denoted as
+// 'm') are used in the opposite meaning as in more traditional maths or physics
+// conventions:
+// [1] C. Nachbar, F. Zotter, E. Deleflie, A. Sontacchi, "AMBIX - A SUGGESTED
+// AMBISONICS FORMAT", Proc. of the 2nd Ambisonics Symposium, June 2-3 2011,
+// Lexington, KY, https://goo.gl/jzt4Yy.
+inline int GetPeriphonicAmbisonicOrderForChannel(size_t channel) {
+ return static_cast<int>(sqrtf(static_cast<float>(channel)));
+}
+
+// Calculates the degree of the current spherical harmonic channel. Please note,
+// that in Ambisonics the terms 'order' (usually denoted as 'n') and 'degree'
+// (usually denoted as 'm') are used in the opposite meaning as in more
+// traditional maths or physics conventions:
+// [1] C. Nachbar, F. Zotter, E. Deleflie, A. Sontacchi, "AMBIX - A SUGGESTED
+// AMBISONICS FORMAT", Proc. of the 2nd Ambisonics Symposium, June 2-3 2011,
+// Lexington, KY, https://goo.gl/jzt4Yy.
+inline int GetPeriphonicAmbisonicDegreeForChannel(size_t channel) {
+ const int order = GetPeriphonicAmbisonicOrderForChannel(channel);
+ return static_cast<int>(channel) - order * (order + 1);
+}
+
+// Returns whether the given |num_channels| corresponds to a valid ambisonic
+// order configuration.
+inline bool IsValidAmbisonicOrder(size_t num_channels) {
+ if (num_channels == 0) {
+ return false;
+ }
+ // Number of channels must be a square number for valid ambisonic orders.
+ const size_t sqrt_num_channels = static_cast<size_t>(std::sqrt(num_channels));
+ return num_channels == sqrt_num_channels * sqrt_num_channels;
+}
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_AMBISONICS_UTILS_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/ambisonics/utils_test.cc b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/utils_test.cc
new file mode 100644
index 000000000..51dfa13d5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/ambisonics/utils_test.cc
@@ -0,0 +1,65 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "ambisonics/utils.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// Ambisonic Channel Numbers (ACNs) used in the tests.
+const size_t kAcnChannels[] = {0, 1, 4, 8, 16, 32};
+
+// Number of different ACNs to be tested.
+const size_t kNumAcnChannels = sizeof(kAcnChannels) / sizeof(kAcnChannels[0]);
+
+// Tests that the Ambisonic order for a given channel returned by the
+// GetPeriphonicAmbisonicOrderForChannel() method is correct.
+TEST(UtilsTest, GetPeriphonicAmbisonicOrderForChannelTest) {
+ const int kExpectedOrders[] = {0, 1, 2, 2, 4, 5};
+ for (size_t channel = 0; channel < kNumAcnChannels; ++channel) {
+ EXPECT_EQ(kExpectedOrders[channel],
+ GetPeriphonicAmbisonicOrderForChannel(kAcnChannels[channel]));
+ }
+}
+
+// Tests that the Ambisonic degree for a given channel returned by the
+// GetPeriphonicAmbisonicDegreeForChannel() method is correct.
+TEST(UtilsTest, GetPeriphonicAmbisonicDegreeForChannelTest) {
+ const int kExpectedDegrees[] = {0, -1, -2, 2, -4, 2};
+ for (size_t channel = 0; channel < kNumAcnChannels; ++channel) {
+ EXPECT_EQ(kExpectedDegrees[channel],
+ GetPeriphonicAmbisonicDegreeForChannel(kAcnChannels[channel]));
+ }
+}
+
+// Tests that the ambisonic order validation returns the expected results for
+// arbitrary number of channels.
+TEST(UtilsTest, IsValidAmbisonicOrderTest) {
+ for (size_t valid_channel : {1, 4, 9, 16, 25, 36}) {
+ EXPECT_TRUE(IsValidAmbisonicOrder(valid_channel));
+ }
+ for (size_t invalid_channel : {2, 3, 5, 8, 50, 99}) {
+ EXPECT_FALSE(IsValidAmbisonicOrder(invalid_channel));
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/api/binaural_surround_renderer.cc b/src/3rdparty/resonance-audio/resonance_audio/api/binaural_surround_renderer.cc
new file mode 100644
index 000000000..96ed399ae
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/api/binaural_surround_renderer.cc
@@ -0,0 +1,35 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "api/binaural_surround_renderer.h"
+
+#include "base/logging.h"
+#include "graph/binaural_surround_renderer_impl.h"
+
+namespace vraudio {
+
+BinauralSurroundRenderer* BinauralSurroundRenderer::Create(
+ size_t frames_per_buffer, int sample_rate_hz,
+ SurroundFormat surround_format) {
+ std::unique_ptr<BinauralSurroundRendererImpl> renderer(
+ new BinauralSurroundRendererImpl(frames_per_buffer, sample_rate_hz));
+ if (!renderer->Init(surround_format)) {
+ return nullptr;
+ }
+ return renderer.release();
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/api/binaural_surround_renderer.h b/src/3rdparty/resonance-audio/resonance_audio/api/binaural_surround_renderer.h
new file mode 100644
index 000000000..31e8e3b6e
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/api/binaural_surround_renderer.h
@@ -0,0 +1,255 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_API_BINAURAL_SURROUND_RENDERER_H_
+#define RESONANCE_AUDIO_API_BINAURAL_SURROUND_RENDERER_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+// Avoid dependency to base/integral_types.h
+typedef int16_t int16;
+
+namespace vraudio {
+
+// Renders virtual surround sound as well as ambisonic soundfields to binaural
+// stereo.
+class BinauralSurroundRenderer {
+ public:
+
+ enum SurroundFormat {
+ // Enables to initialize a yet undefined rendering mode.
+ kInvalid = 0,
+
+ // Binaurally renders a single virtual speaker at 0 degrees in front.
+ kSurroundMono = 1,
+
+ // Binaurally renders virtual stereo speakers at -30 degrees and +30
+ // degrees.
+ kSurroundStereo = 2,
+
+ // Binaurally renders 5.1 surround sound according to the ITU-R BS.775-3
+ // speaker configuration recommendation:
+ // - Left (L) at 30 degrees.
+ // - Right (R) at -30 degrees.
+ // - Center (C) at 0 degrees.
+ // - Low frequency effects (LFE) at front center at 0 degrees.
+ // - Left surround (LS) at 110 degrees.
+ // - Right surround (RS) at -110 degrees.
+ //
+ // The 5.1 channel input layout must matches AAC: L, R, C, LFE, LS, RS.
+ // Note that this differs from the Vorbis/Opus 5.1 channel layout, which
+ // is: L, C, R, LS, RS, LFE.
+ kSurroundFiveDotOne = 3,
+
+ // Binaurally renders 7.1 surround sound according to the ITU-R BS.775-3
+ // speaker configuration recommendation:
+ // - Left (FL) at 30 degrees.
+ // - Right (FR) at -30 degrees.
+ // - Center (C) at 0 degrees.
+ // - Low frequency effects (LFE) at front center at 0 degrees.
+ // - Left surround 1 (LS1) at 90 degrees.
+ // - Right surround 1 (RS1) at -90 degrees.
+ // - Left surround 2 (LS2) at 150 degrees.
+ // - Right surround 2 (LS2) at -150 degrees.
+ //
+ // The 7.1 channel input layout must matches AAC: L, R, C, LFE, LS1, RS1,
+ // LS2, RS2.
+ // Note that this differs from the Vorbis/Opus 7.1 channel layout, which
+ // is: L, C, R, LS1, RS1, LS2, RS2, LFE.
+ kSurroundSevenDotOne = 10,
+
+ // Binaurally renders first-order ambisonics
+ // (AmbiX format: 4 channels, ACN channel ordering, SN3D normalization).
+ kFirstOrderAmbisonics = 4,
+
+ // Binaurally renders second-order ambisonics.
+ // (AmbiX format: 9 channels, ACN channel ordering, SN3D normalization).
+ kSecondOrderAmbisonics = 5,
+
+ // Binaurally renders third-order ambisonics.
+ // (AmbiX format: 16 channels, ACN channel ordering, SN3D normalization).
+ kThirdOrderAmbisonics = 6,
+
+ // Binaurally renders first-order ambisonics with a non-diegetic-stereo
+ // track. The first 4 channels contain ambisonic AmbiX format.
+ // (AmbiX format: 4 channels, ACN channel ordering, SN3D normalization).
+ // Channel 5 to 6 contain non-diegetic-stereo.
+ kFirstOrderAmbisonicsWithNonDiegeticStereo = 7,
+
+ // Binaurally renders second-order ambisonics with a non-diegetic-stereo
+ // track. The first 9 channels contain ambisonic AmbiX format.
+ // (AmbiX format: 9 channels, ACN channel ordering, SN3D normalization).
+ // Channel 10 to 11 contain non-diegetic-stereo.
+ kSecondOrderAmbisonicsWithNonDiegeticStereo = 8,
+
+ // Binaurally renders third-order ambisonics with a non-diegetic-stereo
+ // track. The first 16 channels contain ambisonic AmbiX format.
+ // (AmbiX format: 16 channels, ACN channel ordering, SN3D normalization).
+ // Channel 17 to 18 contain non-diegetic-stereo.
+ kThirdOrderAmbisonicsWithNonDiegeticStereo = 9,
+
+ // Note: Next available value is: 11
+ };
+
+
+ virtual ~BinauralSurroundRenderer() {}
+
+ // Factory method to create a |BinauralSurroundRenderer| instance. Caller must
+ // take ownership of returned instance and destroy it via operator delete.
+ //
+ // @param frames_per_buffer Number of frames in output buffer.
+ // @param sample_rate_hz Sample rate of audio buffers.
+ // @param surround_format Input surround sound format.
+ // @param return |BinauralSurroundRenderer| instance, nullptr if creation
+ // fails.
+ static BinauralSurroundRenderer* Create(size_t frames_per_buffer,
+ int sample_rate_hz,
+ SurroundFormat surround_format);
+
+ // Enables the stereo speaker mode. When activated, it disables HRTF-based
+ // filtering and switches to computationally cheaper stereo-panning. This
+ // helps to avoid HRTF-based coloring effects when stereo speakers are used
+ // and reduces computational complexity when headphone-based HRTF filtering is
+ // not needed. By default the stereo speaker mode is disabled.
+ //
+ // @param enabled Flag to enable stereo speaker mode.
+ virtual void SetStereoSpeakerMode(bool enabled) = 0;
+
+ // Returns the number of frames the input buffer is currently able to consume.
+ //
+ // @return Number of available frames in input buffer.
+ virtual size_t GetNumAvailableFramesInInputBuffer() const = 0;
+
+ // Adds interleaved int16 audio data to the renderer. If enough data has been
+ // provided for an output buffer to be generated then it will be immediately
+ // available via |Get[Interleaved|Planar]StereoOutputBuffer|. The input data
+ // is copied into an internal buffer which allows the caller to re-use the
+ // input buffer immediately. The available space in the internal buffer can be
+ // obtained via |GetAvailableInputSizeSamples|.
+ //
+ // @param input_buffer_ptr Pointer to interleaved input data.
+ // @param num_channels Number of channels in input buffer.
+ // @param num_frames Number of frames in input buffer.
+ // @return The number of consumed frames.
+ virtual size_t AddInterleavedInput(const int16* input_buffer_ptr,
+ size_t num_channels,
+ size_t num_frames) = 0;
+
+ // Adds interleaved floating point audio data to the renderer. If enough data
+ // has been provided for an output buffer to be generated then it will be
+ // immediately available via |Get[Interleaved|Planar]StereoOutputBuffer|. The
+ // input data is copied into an internal buffer which allows the caller to
+ // re-use the input buffer immediately. The available space in the internal
+ // buffer can be obtained via |GetAvailableInputSizeSamples|.
+ //
+ // @param input_buffer_ptr Pointer to interleaved input data.
+ // @param num_channels Number of channels in input buffer.
+ // @param num_frames Number of frames in input buffer.
+ // @return The number of consumed frames.
+ virtual size_t AddInterleavedInput(const float* input_buffer_ptr,
+ size_t num_channels,
+ size_t num_frames) = 0;
+
+ // Adds planar int16 audio data to the renderer. If enough data has
+ // been provided for an output buffer to be generated then it will be
+ // immediately available via |Get[Interleaved|Planar]StereoOutputBuffer|. The
+ // input data is copied into an internal buffer which allows the caller to
+ // re-use the input buffer immediately. The available space in the internal
+ // buffer can be obtained via |GetAvailableInputSizeSamples|.
+ //
+ // @param input_buffer_ptrs Array of pointers to planar channel data.
+ // @param num_channels Number of channels in input buffer.
+ // @param num_frames Number of frames in input buffer.
+ // @return The number of consumed frames.
+ virtual size_t AddPlanarInput(const int16* const* input_buffer_ptrs,
+ size_t num_channels, size_t num_frames) = 0;
+
+ // Adds planar floating point audio data to the renderer. If enough data has
+ // been provided for an output buffer to be generated then it will be
+ // immediately available via |Get[Interleaved|Planar]StereoOutputBuffer|. The
+ // input data is copied into an internal buffer which allows the caller to
+ // re-use the input buffer immediately. The available space in the internal
+ // buffer can be obtained via |GetAvailableInputSizeSamples|.
+ //
+ // @param input_buffer_ptrs Array of pointers to planar channel data.
+ // @param num_channels Number of channels in input buffer.
+ // @param num_frames Number of frames in input buffer.
+ // @return The number of consumed frames.
+ virtual size_t AddPlanarInput(const float* const* input_buffer_ptrs,
+ size_t num_channels, size_t num_frames) = 0;
+
+ // Returns the number of samples available in the output buffer.
+ //
+ // @return Number of available samples in output buffer.
+ virtual size_t GetAvailableFramesInStereoOutputBuffer() const = 0;
+
+ // Gets a processed output buffer in interleaved int16 format.
+ //
+ // @param output_buffer_ptr Pointer to allocated interleaved output buffer.
+ // @param num_frames Size of output buffer in frames.
+ // @return The number of consumed frames.
+ virtual size_t GetInterleavedStereoOutput(int16* output_buffer_ptr,
+ size_t num_frames) = 0;
+
+ // Gets a processed output buffer in interleaved float format.
+ //
+ // @param output_buffer_ptr Pointer to allocated interleaved output buffer.
+ // @param num_frames Size of output buffer in frames.
+ // @return The number of consumed frames.
+ virtual size_t GetInterleavedStereoOutput(float* output_buffer_ptr,
+ size_t num_frames) = 0;
+
+ // Gets a processed output buffer in planar int16 point format.
+ //
+ // @param output_buffer_ptrs Array of pointers to planar channel data.
+ // @param num_frames Number of frames in output buffer.
+ // @return The number of consumed frames.
+ virtual size_t GetPlanarStereoOutput(int16** output_buffer_ptrs,
+ size_t num_frames) = 0;
+
+ // Gets a processed output buffer in planar floating point format.
+ //
+ // @param output_buffer_ptrs Array of pointers to planar channel data.
+ // @param num_frames Number of frames in output buffer.
+ // @return The number of consumed frames.
+ virtual size_t GetPlanarStereoOutput(float** output_buffer_ptrs,
+ size_t num_frames) = 0;
+
+ // Removes all buffered input and processed output buffers from the buffer
+ // queues.
+ virtual void Clear() = 0;
+
+ // Triggers the processing of data that has been input but not yet processed.
+ // Note after calling this method, all processed output must be consumed via
+ // |Get[Interleaved|Planar]StereoOutputBuffer| before adding new input
+ // buffers.
+ //
+ // @return Whether any data was processed.
+ virtual bool TriggerProcessing() = 0;
+
+ // Updates the head rotation.
+ //
+ // @param w W component of quaternion.
+ // @param x X component of quaternion.
+ // @param y Y component of quaternion.
+ // @param z Z component of quaternion.
+ virtual void SetHeadRotation(float w, float x, float y, float z) = 0;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_API_BINAURAL_SURROUND_RENDERER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/api/resonance_audio_api.cc b/src/3rdparty/resonance-audio/resonance_audio/api/resonance_audio_api.cc
new file mode 100644
index 000000000..d7b9ccfdd
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/api/resonance_audio_api.cc
@@ -0,0 +1,30 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "api/resonance_audio_api.h"
+
+#include "base/logging.h"
+#include "graph/resonance_audio_api_impl.h"
+
+namespace vraudio {
+
+extern "C" EXPORT_API ResonanceAudioApi* CreateResonanceAudioApi(
+ size_t num_channels, size_t frames_per_buffer, int sample_rate_hz) {
+ return new ResonanceAudioApiImpl(num_channels, frames_per_buffer,
+ sample_rate_hz);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/api/resonance_audio_api.h b/src/3rdparty/resonance-audio/resonance_audio/api/resonance_audio_api.h
new file mode 100644
index 000000000..f734dbee9
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/api/resonance_audio_api.h
@@ -0,0 +1,416 @@
+
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_API_RESONANCE_AUDIO_API_H_
+#define RESONANCE_AUDIO_API_RESONANCE_AUDIO_API_H_
+
+// EXPORT_API can be used to define the dllimport storage-class attribute.
+#if !defined(EXPORT_API)
+#define EXPORT_API
+#endif
+
+#include <cstddef> // size_t declaration.
+#include <cstdint> // int16_t declaration.
+
+
+typedef int16_t int16;
+
+namespace vraudio {
+
+// Rendering modes define CPU load / rendering quality balances.
+// Note that this struct is C-compatible by design to be used across external
+// C/C++ and C# implementations.
+enum RenderingMode {
+ // Stereo panning, i.e., this disables HRTF-based rendering.
+ kStereoPanning = 0,
+ // HRTF-based rendering using First Order Ambisonics, over a virtual array of
+ // 8 loudspeakers arranged in a cube configuration around the listener's head.
+ kBinauralLowQuality,
+ // HRTF-based rendering using Second Order Ambisonics, over a virtual array of
+ // 12 loudspeakers arranged in a dodecahedral configuration (using faces of
+ // the dodecahedron).
+ kBinauralMediumQuality,
+ // HRTF-based rendering using Third Order Ambisonics, over a virtual array of
+ // 26 loudspeakers arranged in a Lebedev grid: https://goo.gl/DX1wh3.
+ kBinauralHighQuality,
+ // Room effects only rendering. This disables HRTF-based rendering and direct
+ // (dry) output of a sound object. Note that this rendering mode should *not*
+ // be used for general-purpose sound object spatialization, as it will only
+ // render the corresponding room effects of given sound objects without the
+ // direct spatialization.
+ kRoomEffectsOnly,
+};
+
+// Distance rolloff models used for distance attenuation.
+// Note that this enum is C-compatible by design to be used across external
+// C/C++ and C# implementations.
+enum DistanceRolloffModel {
+ // Logarithmic distance rolloff model.
+ kLogarithmic = 0,
+ // Linear distance rolloff model.
+ kLinear,
+ // Distance attenuation value will be explicitly set by the user.
+ kNone,
+};
+
+// Early reflection properties of an acoustic environment.
+// Note that this struct is C-compatible by design to be used across external
+// C/C++ and C# implementations.
+struct ReflectionProperties {
+ // Default constructor initializing all data members to 0.
+ ReflectionProperties()
+ : room_position{0.0f, 0.0f, 0.0f},
+ room_rotation{0.0f, 0.0f, 0.0f, 1.0f},
+ room_dimensions{0.0f, 0.0f, 0.0f},
+ cutoff_frequency(0.0f),
+ coefficients{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
+ gain(0.0f) {}
+
+ // Center position of the shoebox room in world space.
+ float room_position[3];
+
+ // Rotation (quaternion) of the shoebox room in world space.
+ float room_rotation[4];
+
+ // Size of the shoebox shoebox room in world space.
+ float room_dimensions[3];
+
+ // Frequency threshold for low pass filtering (-3dB cuttoff).
+ float cutoff_frequency;
+
+ // Reflection coefficients that are stored in world space as follows:
+ // [0] (-)ive x-axis wall (left)
+ // [1] (+)ive x-axis wall (right)
+ // [2] (-)ive y-axis wall (bottom)
+ // [3] (+)ive y-axis wall (top)
+ // [4] (-)ive z-axis wall (front)
+ // [5] (+)ive z-axis wall (back)
+ float coefficients[6];
+
+ // Uniform reflections gain which is applied to all reflections.
+ float gain;
+};
+
+// Late reverberation properties of an acoustic environment.
+// Note that this struct is C-compatible by design to be used across external
+// C/C++ and C# implementations.
+struct ReverbProperties {
+ // Default constructor initializing all data members to 0.
+ ReverbProperties()
+ : rt60_values{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
+ gain(0.0f) {}
+
+ // RT60's of the reverberation tail at different octave band centre
+ // frequencies in seconds.
+ float rt60_values[9];
+
+ // Reverb gain.
+ float gain;
+};
+
+class ResonanceAudioApi;
+
+// Factory method to create a |ResonanceAudioApi| instance. Caller must
+// take ownership of returned instance and destroy it via operator delete.
+//
+// @param num_channels Number of channels of audio output.
+// @param frames_per_buffer Number of frames per buffer.
+// @param sample_rate_hz System sample rate.
+extern "C" EXPORT_API ResonanceAudioApi* CreateResonanceAudioApi(
+ size_t num_channels, size_t frames_per_buffer, int sample_rate_hz);
+
+// The ResonanceAudioApi library renders high-quality spatial audio. It provides
+// methods to binaurally render virtual sound sources with simulated room
+// acoustics. In addition, it supports decoding and binaural rendering of
+// ambisonic soundfields. Its implementation is single-threaded, thread-safe
+// and non-blocking to be able to process raw PCM audio buffers directly on the
+// audio thread while receiving parameter updates from the main/render thread.
+class ResonanceAudioApi {
+ public:
+ // Sound object / ambisonic source identifier.
+ typedef int SourceId;
+
+ // Invalid source id that can be used to initialize handler variables during
+ // class construction.
+ static const SourceId kInvalidSourceId = -1;
+
+ virtual ~ResonanceAudioApi() {}
+
+ // Renders and outputs an interleaved output buffer in float format.
+ //
+ // @param num_frames Size of output buffer in frames.
+ // @param num_channels Number of channels in output buffer.
+ // @param buffer_ptr Raw float pointer to audio buffer.
+ // @return True if a valid output was successfully rendered, false otherwise.
+ virtual bool FillInterleavedOutputBuffer(size_t num_channels,
+ size_t num_frames,
+ float* buffer_ptr) = 0;
+
+ // Renders and outputs an interleaved output buffer in int16 format.
+ //
+ // @param num_channels Number of channels in output buffer.
+ // @param num_frames Size of output buffer in frames.
+ // @param buffer_ptr Raw int16 pointer to audio buffer.
+ // @return True if a valid output was successfully rendered, false otherwise.
+ virtual bool FillInterleavedOutputBuffer(size_t num_channels,
+ size_t num_frames,
+ int16* buffer_ptr) = 0;
+
+ // Renders and outputs a planar output buffer in float format.
+ //
+ // @param num_frames Size of output buffer in frames.
+ // @param num_channels Number of channels in output buffer.
+ // @param buffer_ptr Pointer to array of raw float pointers to each channel of
+ // the audio buffer.
+ // @return True if a valid output was successfully rendered, false otherwise.
+ virtual bool FillPlanarOutputBuffer(size_t num_channels, size_t num_frames,
+ float* const* buffer_ptr) = 0;
+
+ // Renders and outputs a planar output buffer in int16 format.
+ //
+ // @param num_channels Number of channels in output buffer.
+ // @param num_frames Size of output buffer in frames.
+ // @param buffer_ptr Pointer to array of raw int16 pointers to each channel of
+ // the audio buffer.
+ // @return True if a valid output was successfully rendered, false otherwise.
+ virtual bool FillPlanarOutputBuffer(size_t num_channels, size_t num_frames,
+ int16* const* buffer_ptr) = 0;
+
+ // Sets listener's head position.
+ //
+ // @param x X coordinate of head position in world space.
+ // @param y Y coordinate of head position in world space.
+ // @param z Z coordinate of head position in world space.
+ virtual void SetHeadPosition(float x, float y, float z) = 0;
+
+ // Sets listener's head rotation.
+ //
+ // @param x X component of quaternion.
+ // @param y Y component of quaternion.
+ // @param z Z component of quaternion.
+ // @param w W component of quaternion.
+ virtual void SetHeadRotation(float x, float y, float z, float w) = 0;
+
+ // Sets the master volume of the main audio output.
+ //
+ // @param volume Master volume (linear) in amplitude in range [0, 1] for
+ // attenuation, range [1, inf) for gain boost.
+ virtual void SetMasterVolume(float volume) = 0;
+
+ // Enables the stereo speaker mode. When activated, it disables HRTF-based
+ // filtering and switches to computationally cheaper stereo-panning. This
+ // helps to avoid HRTF-based coloring effects when stereo speakers are used
+ // and reduces computational complexity when headphone-based HRTF filtering is
+ // not needed. By default the stereo speaker mode is disabled. Note that
+ // stereo speaker mode overrides the |enable_hrtf| flag in
+ // |CreateSoundObjectSource|.
+ //
+ // @param enabled Flag to enable stereo speaker mode.
+ virtual void SetStereoSpeakerMode(bool enabled) = 0;
+
+ // Creates an ambisonic source instance.
+ //
+ // @param num_channels Number of input channels.
+ // @return Id of new ambisonic source.
+ virtual SourceId CreateAmbisonicSource(size_t num_channels) = 0;
+
+ // Creates a stereo non-spatialized source instance, which directly plays back
+ // mono or stereo audio.
+ //
+ // @param num_channels Number of input channels.
+ // @return Id of new non-spatialized source.
+ virtual SourceId CreateStereoSource(size_t num_channels) = 0;
+
+ // Creates a sound object source instance.
+ //
+ // @param rendering_mode Rendering mode which governs quality and performance.
+ // @return Id of new sound object source.
+ virtual SourceId CreateSoundObjectSource(RenderingMode rendering_mode) = 0;
+
+ // Destroys source instance.
+ //
+ // @param source_id Id of source to be destroyed.
+ virtual void DestroySource(SourceId id) = 0;
+
+ // Sets the next audio buffer in interleaved float format to a sound source.
+ //
+ // @param source_id Id of sound source.
+ // @param audio_buffer_ptr Pointer to interleaved float audio buffer.
+ // @param num_channels Number of channels in interleaved audio buffer.
+ // @param num_frames Number of frames per channel in interleaved audio buffer.
+ virtual void SetInterleavedBuffer(SourceId source_id,
+ const float* audio_buffer_ptr,
+ size_t num_channels, size_t num_frames) = 0;
+
+ // Sets the next audio buffer in interleaved int16 format to a sound source.
+ //
+ // @param source_id Id of sound source.
+ // @param audio_buffer_ptr Pointer to interleaved int16 audio buffer.
+ // @param num_channels Number of channels in interleaved audio buffer.
+ // @param num_frames Number of frames per channel in interleaved audio buffer.
+ virtual void SetInterleavedBuffer(SourceId source_id,
+ const int16* audio_buffer_ptr,
+ size_t num_channels, size_t num_frames) = 0;
+
+ // Sets the next audio buffer in planar float format to a sound source.
+ //
+ // @param source_id Id of sound source.
+ // @param audio_buffer_ptr Pointer to array of pointers referring to planar
+ // audio buffers for each channel.
+ // @param num_channels Number of planar input audio buffers.
+ // @param num_frames Number of frames per channel.
+ virtual void SetPlanarBuffer(SourceId source_id,
+ const float* const* audio_buffer_ptr,
+ size_t num_channels, size_t num_frames) = 0;
+
+ // Sets the next audio buffer in planar int16 format to a sound source.
+ //
+ // @param source_id Id of sound source.
+ // @param audio_buffer_ptr Pointer to array of pointers referring to planar
+ // audio buffers for each channel.
+ // @param num_channels Number of planar input audio buffers.
+ // @param num_frames Number of frames per channel.
+ virtual void SetPlanarBuffer(SourceId source_id,
+ const int16* const* audio_buffer_ptr,
+ size_t num_channels, size_t num_frames) = 0;
+
+ // Sets the given source's distance attenuation value explicitly. The distance
+ // rolloff model of the source must be set to |DistanceRolloffModel::kNone|
+ // for the set value to take effect.
+ //
+ // @param source_id Id of source.
+ // @param distance_attenuation Distance attenuation value.
+ virtual void SetSourceDistanceAttenuation(SourceId source_id,
+ float distance_attenuation) = 0;
+
+ // Sets the given source's distance attenuation method with minimum and
+ // maximum distances. Maximum distance must be greater than the minimum
+ // distance for the method to be set.
+ //
+ // @param source_id Id of source.
+ // @param rolloff Linear or logarithmic distance rolloff models.
+ // @param min_distance Minimum distance to apply distance attenuation method.
+ // @param max_distance Maximum distance to apply distance attenuation method.
+ virtual void SetSourceDistanceModel(SourceId source_id,
+ DistanceRolloffModel rolloff,
+ float min_distance,
+ float max_distance) = 0;
+
+ // Sets the given source's position. Note that, the given position for an
+ // ambisonic source is only used to determine the corresponding room effects
+ // to be applied.
+ //
+ // @param source_id Id of source.
+ // @param x X coordinate of source position in world space.
+ // @param y Y coordinate of source position in world space.
+ // @param z Z coordinate of source position in world space.
+ virtual void SetSourcePosition(SourceId source_id, float x, float y,
+ float z) = 0;
+
+ // Sets the room effects contribution for the given source.
+ //
+ // @param source_id Id of source.
+ // @param room_effects_gain Linear room effects volume in amplitude in range
+ // [0, 1] for attenuation, range [1, inf) for gain boost.
+ virtual void SetSourceRoomEffectsGain(SourceId source_id,
+ float room_effects_gain) = 0;
+
+ // Sets the given source's rotation.
+ //
+ // @param source_id Id of source.
+ // @param x X component of quaternion.
+ // @param y Y component of quaternion.
+ // @param z Z component of quaternion.
+ // @param w W component of quaternion.
+ virtual void SetSourceRotation(SourceId source_id, float x, float y, float z,
+ float w) = 0;
+
+ // Sets the given source's volume.
+ //
+ // @param source_id Id of source.
+ // @param volume Linear source volume in amplitude in range [0, 1] for
+ // attenuation, range [1, inf) for gain boost.
+ virtual void SetSourceVolume(SourceId source_id, float volume) = 0;
+
+ // Sets the given sound object source's directivity.
+ //
+ // @param sound_object_source_id Id of sound object source.
+ // @param alpha Weighting balance between figure of eight pattern and circular
+ // pattern for source emission in range [0, 1]. A value of 0.5 results in
+ // a cardioid pattern.
+ // @param order Order applied to computed directivity. Higher values will
+ // result in narrower and sharper directivity patterns. Range [1, inf).
+ virtual void SetSoundObjectDirectivity(SourceId sound_object_source_id,
+ float alpha, float order) = 0;
+
+ // Sets the listener's directivity with respect to the given sound object.
+ // This method could be used to simulate an angular rolloff in terms of the
+ // listener's orientation, given the polar pickup pattern with |alpha| and
+ // |order|.
+ //
+ // @param sound_object_source_id Id of sound object source.
+ // @param alpha Weighting balance between figure of eight pattern and circular
+ // pattern for listener's pickup in range [0, 1]. A value of 0.5 results
+ // in a cardioid pattern.
+ // @param order Order applied to computed pickup pattern. Higher values will
+ // result in narrower and sharper pickup patterns. Range [1, inf).
+ virtual void SetSoundObjectListenerDirectivity(
+ SourceId sound_object_source_id, float alpha, float order) = 0;
+
+ // Sets the gain (linear) of the near field effect.
+ //
+ // @param sound_object_source_id Id of sound object source.
+ // @param gain Gain of the near field effect. Range [0, 9] (corresponding to
+ // approx. (-Inf, +20dB]).
+ virtual void SetSoundObjectNearFieldEffectGain(
+ SourceId sound_object_source_id, float gain) = 0;
+
+ // Sets the given sound object source's occlusion intensity.
+ //
+ // @param sound_object_source_id Id of sound object source.
+ // @param intensity Number of occlusions occurred for the object. The value
+ // can be set to fractional for partial occlusions. Range [0, inf).
+ virtual void SetSoundObjectOcclusionIntensity(SourceId sound_object_source_id,
+ float intensity) = 0;
+
+ // Sets the given sound object source's spread.
+ //
+ // @param sound_object_source_id Id of sound object source.
+ // @param spread_deg Spread in degrees.
+ virtual void SetSoundObjectSpread(SourceId sound_object_source_id,
+ float spread_deg) = 0;
+
+ // Turns on/off the reflections and reverberation.
+ virtual void EnableRoomEffects(bool enable) = 0;
+
+ // Sets the early reflection properties of the environment.
+ //
+ // @param reflection_properties Reflection properties.
+ virtual void SetReflectionProperties(
+ const ReflectionProperties& reflection_properties) = 0;
+
+ // Sets the late reverberation properties of the environment.
+ //
+ // @param reverb_properties Reverb properties.
+ virtual void SetReverbProperties(
+ const ReverbProperties& reverb_properties) = 0;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_API_RESONANCE_AUDIO_API_H_
+
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/aligned_allocator.h b/src/3rdparty/resonance-audio/resonance_audio/base/aligned_allocator.h
new file mode 100644
index 000000000..628ccaa02
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/aligned_allocator.h
@@ -0,0 +1,117 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_BASE_ALIGNED_ALLOCATOR_H_
+#define RESONANCE_AUDIO_BASE_ALIGNED_ALLOCATOR_H_
+
+#include <stdlib.h>
+
+#include <algorithm>
+#include <cstddef>
+#include <memory>
+#include <type_traits>
+
+#include "base/simd_utils.h"
+
+
+namespace vraudio {
+
+// Performs static assert checks on the types size and alignment parameters.
+template <size_t TypeSize, size_t Alignment>
+void StaticAlignmentCheck() {
+ const bool alignment_is_power_of_two =
+ !(Alignment == 0) && !(Alignment & (Alignment - 1));
+ static_assert(alignment_is_power_of_two, "Alignment must be power of two");
+
+ const bool type_size_is_power_of_two = !(TypeSize & (TypeSize - 1));
+ static_assert(type_size_is_power_of_two, "Type size must be power of two");
+}
+
+// Returns a pointer to aligned memory.
+template <typename Type, typename SizeType, typename PointerType>
+PointerType AllignedMalloc(SizeType size, SizeType alignment) {
+ const SizeType data_size = size * sizeof(Type);
+ const SizeType offset = alignment - 1 + sizeof(PointerType);
+ void* mem_block_begin = malloc(data_size + offset);
+ if (mem_block_begin == nullptr) {
+ return nullptr;
+ }
+ // Find memory aligned address.
+ void** mem_block_aligned = reinterpret_cast<void**>(
+ ((reinterpret_cast<SizeType>(mem_block_begin) + offset) &
+ (~(alignment - 1))));
+ // Save pointer to original block right before the aligned block.
+ mem_block_aligned[-1] = mem_block_begin;
+ return reinterpret_cast<PointerType>(mem_block_aligned);
+}
+
+// Frees memory that has been aligned with |AllignedMalloc|.
+template <typename PointerType>
+void AllignedFree(PointerType mem_block_aligned) {
+ free(*(reinterpret_cast<void**>(mem_block_aligned) - 1));
+}
+
+// Class that allocates aligned memory. It is derived from std::allocator class
+// to be used with STL containers.
+//
+// @tparam Type Datatype of container to allocate.
+// @tparam Alignment Size of memory alignment.
+template <typename Type, size_t Alignment>
+class AlignedAllocator : public std::allocator<Type> {
+ public:
+ using Pointer = typename std::allocator_traits<std::allocator<Type>>::pointer;
+ using ConstPointer = typename std::allocator_traits<std::allocator<Type>>::const_pointer;
+ using SizeType = typename std::allocator_traits<std::allocator<Type>>::size_type;
+
+ AlignedAllocator() { StaticAlignmentCheck<sizeof(Type), Alignment>(); }
+
+ // Allocates memory for |size| elements and returns a pointer that is aligned
+ // to a multiple to |Alignment|.
+ //
+ // @param size Number of elements to allocate.
+ // @return Returns memory aligned pointer.
+ Pointer allocate(SizeType size) { return allocate(size, nullptr); }
+
+ // Allocates memory for |size| elements and returns a pointer that is aligned
+ // to a multiple to |Alignment|.
+ //
+ // @param size Number of elements to allocate.
+ // @return Returns memory aligned pointer.
+ Pointer allocate(SizeType size, ConstPointer /* hint */) {
+
+ return AllignedMalloc<Type, SizeType, Pointer>(size, Alignment);
+ }
+
+ void deallocate(Pointer mem_block_aligned, size_t size) {
+ AllignedFree<Pointer>(mem_block_aligned);
+ }
+
+ // Copy constructor to support rebind operation (to make MSVC happy).
+ template <typename U>
+ explicit AlignedAllocator<Type, Alignment>(
+ const AlignedAllocator<U, Alignment>& other) {}
+
+ // Rebind is used to allocate container internal variables of type |U|
+ // (which don't need to be aligned).
+ template <typename U>
+ struct rebind {
+ typedef AlignedAllocator<U, Alignment> other;
+ };
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_BASE_ALIGNED_ALLOCATOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/aligned_allocator_test.cc b/src/3rdparty/resonance-audio/resonance_audio/base/aligned_allocator_test.cc
new file mode 100644
index 000000000..c38b8a2f5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/aligned_allocator_test.cc
@@ -0,0 +1,53 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "base/aligned_allocator.h"
+
+#include <cstddef>
+#include <vector>
+
+#include "base/integral_types.h"
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/simd_utils.h"
+
+using vraudio::AlignedAllocator;
+
+namespace {
+
+// Helper method to test memory alignment.
+template <size_t Alignment>
+void TestAlignedAllocator() {
+ static const size_t kRuns = 1000;
+ for (size_t run = 0; run < kRuns; ++run) {
+ std::vector<float, AlignedAllocator<float, Alignment> > aligned_vector(1);
+ const bool is_aligned =
+ ((reinterpret_cast<size_t>(&aligned_vector[0]) & (Alignment - 1)) == 0);
+ EXPECT_TRUE(is_aligned);
+ }
+}
+
+} // namespace
+
+// Allocates multiple std::vectors using the AlignedAllocator and tests if the
+// allocated memory is aligned.
+TEST(AlignedAlocatorTest, TestAlignment) {
+ TestAlignedAllocator<2>();
+ TestAlignedAllocator<4>();
+ TestAlignedAllocator<16>();
+ TestAlignedAllocator<32>();
+ TestAlignedAllocator<64>();
+}
+
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer.cc b/src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer.cc
new file mode 100644
index 000000000..c2ad61510
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer.cc
@@ -0,0 +1,74 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+AudioBuffer::AudioBuffer() : num_frames_(0), source_id_(kInvalidSourceId) {}
+
+AudioBuffer::AudioBuffer(size_t num_channels, size_t num_frames)
+ : num_frames_(num_frames), source_id_(kInvalidSourceId) {
+
+ InitChannelViews(num_channels);
+}
+
+// Copy assignment from AudioBuffer.
+AudioBuffer& AudioBuffer::operator=(const AudioBuffer& other) {
+ if (this != &other) {
+ num_frames_ = other.num_frames_;
+ source_id_ = other.source_id_;
+ InitChannelViews(other.num_channels());
+ for (size_t i = 0; i < num_channels(); ++i) {
+ channel_views_[i] = other.channel_views_[i];
+ }
+ }
+ return *this;
+}
+
+AudioBuffer::AudioBuffer(AudioBuffer&& other) {
+ num_frames_ = other.num_frames_;
+ other.num_frames_ = 0;
+ data_ = std::move(other.data_);
+ data_size_ = other.data_size_;
+ other.data_size_ = 0;
+ channel_views_ = std::move(other.channel_views_);
+ source_id_ = other.source_id_;
+ other.source_id_ = kInvalidSourceId;
+}
+
+void AudioBuffer::InitChannelViews(size_t num_channels) {
+
+
+ const size_t num_frames_to_next_channel = FindNextAlignedArrayIndex(
+ num_frames_, sizeof(float), kMemoryAlignmentBytes);
+
+ data_size_ = num_channels * num_frames_to_next_channel;
+ data_.resize(data_size_);
+
+ channel_views_.clear();
+ channel_views_.reserve(num_channels);
+
+ float* itr = data_.data();
+
+ for (size_t i = 0; i < num_channels; ++i) {
+ ChannelView new_channel_view(itr, num_frames_);
+ channel_views_.push_back(new_channel_view);
+ itr += num_frames_to_next_channel;
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer.h b/src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer.h
new file mode 100644
index 000000000..c63fd905c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer.h
@@ -0,0 +1,222 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_BASE_AUDIO_BUFFER_H_
+#define RESONANCE_AUDIO_BASE_AUDIO_BUFFER_H_
+
+#include <algorithm>
+#include <memory>
+
+#include "base/integral_types.h"
+#include "base/aligned_allocator.h"
+#include "base/channel_view.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/simd_utils.h"
+
+
+namespace vraudio {
+
+// Audio buffer that manages multi-channel audio data in a planar data format.
+// All channels are sequentially stored within a single consecutive chunk of
+// memory. To access individual channel data, the array subscript operator can
+// be used to obtain a |AudioBuffer::Channel|. Note that the user must guarantee
+// that the AudioBuffer instance lives as long as its channel data is accessed
+// via |AudioBuffer::Channel|s. Note that allocated buffers may *not* be
+// initialized to zero.
+//
+// Examples:
+//
+// // Range-based for-loop over all channels and all samples.
+// AudioBuffer audio_buffer(...)
+// for (AudioBuffer::Channel& channel : audio_buffer) {
+// for (float& sample : channel) {
+// sample *= gain;
+// }
+// }
+//
+// // Range-based for-loop over all channels and array subscripts-based for-loop
+// // to access samples.
+// AudioBuffer audio_buffer(...)
+// for (AudioBuffer::Channel& channel : audio_buffer) {
+// for (size_t i = 0; i < channel.num_frames(); ++i) {
+// channel[i] *= gain;
+// }
+// }
+//
+// // Array subscript-based for-loops over all channels samples.
+// // AudioBuffer audio_buffer(...)
+// for (size_t c=0; c < audio_buffer.num_channels(); ++c) {
+// // First obtain a reference to AudioBuffer::Channel.
+// AudioBuffer::Channel& channel = audio_buffer[c];
+// for (size_t i = 0; i < channel.num_frames(); ++i) {
+// channel[i] *= gain;
+// }
+// }
+//
+// Note do *NOT* use double array subscripts to iterate over multiple samples
+// since it performs a channel iterator lookup for every sample:
+// for (size_t c=0; c < audio_buffer.num_channels(); ++c) {
+// for (size_t i = 0; i < channel.size(); ++i) {
+// audio_buffer[c][i] *= gain; // *BAD*
+// }
+// }
+//
+class AudioBuffer {
+ public:
+ // View on separate audio channel.
+ typedef ChannelView Channel;
+
+ // Allocator class to allocate aligned floats.
+ typedef AlignedAllocator<float, kMemoryAlignmentBytes> FloatAllocator;
+
+ // Allocator class to allocate aligned int16s.
+ typedef AlignedAllocator<int16, kMemoryAlignmentBytes> Int16Allocator;
+
+ // AlignedFloatBuffer for storing audio data.
+ typedef std::vector<float, FloatAllocator> AlignedFloatVector;
+
+ // AlignedInt16Buffer for storing audio data.
+ typedef std::vector<int16, Int16Allocator> AlignedInt16Vector;
+
+ // Default constructor initializes an empty |AudioBuffer|.
+ AudioBuffer();
+
+ // Constructor.
+ //
+ // @param num_channels Number of channels.
+ // @param num_frames Number of frames.
+ AudioBuffer(size_t num_channels, size_t num_frames);
+
+ // Move constructor.
+ AudioBuffer(AudioBuffer&& other);
+
+ // Copy constructor is explicitly deleted to prevent accidental copies.
+ // Use copy assignment operator instead.
+ AudioBuffer(const AudioBuffer& other) = delete;
+
+ // Copy assignment from AudioBuffer.
+ AudioBuffer& operator=(const AudioBuffer& other);
+
+ // Returns the number of audio channels.
+ size_t num_channels() const { return channel_views_.size(); }
+
+ // Returns the number of frames per buffer.
+ size_t num_frames() const { return num_frames_; }
+
+ // Returns this buffer's source id.
+ SourceId source_id() const { return source_id_; }
+
+ // Returns a reference to the selected ChannelView.
+ Channel& operator[](size_t channel) {
+ DCHECK_LT(channel, channel_views_.size());
+ return channel_views_[channel];
+ }
+
+ // Returns a const reference to the selected ChannelView.
+ const Channel& operator[](size_t channel) const {
+ DCHECK_LT(channel, channel_views_.size());
+ return channel_views_[channel];
+ }
+
+ // Copy assignment from std::vector<std::vector<float>>.
+ AudioBuffer& operator=(const std::vector<std::vector<float>>& other) {
+ DCHECK_EQ(other.size(), channel_views_.size());
+ for (size_t channel = 0; channel < channel_views_.size(); ++channel) {
+ channel_views_[channel] = other[channel];
+ }
+ return *this;
+ }
+
+ // += operator
+ AudioBuffer& operator+=(const AudioBuffer& other) {
+ DCHECK_EQ(other.num_channels(), num_channels());
+ DCHECK_EQ(other.num_frames(), num_frames());
+ for (size_t i = 0; i < channel_views_.size(); ++i)
+ channel_views_[i] += other[i];
+
+ return *this;
+ }
+
+ // -= operator
+ AudioBuffer& operator-=(const AudioBuffer& other) {
+ DCHECK_EQ(other.num_channels(), num_channels());
+ DCHECK_EQ(other.num_frames(), num_frames());
+ for (size_t i = 0; i < channel_views_.size(); ++i)
+ channel_views_[i] -= other[i];
+
+ return *this;
+ }
+
+ // Returns an iterator to the ChannelView of the first channel.
+ std::vector<Channel>::iterator begin() { return channel_views_.begin(); }
+
+ // Returns an iterator to the end of the ChannelView vector.
+ std::vector<Channel>::iterator end() { return channel_views_.end(); }
+
+ // Returns a const_iterator to the ChannelView of the first channel.
+ std::vector<Channel>::const_iterator begin() const {
+ return channel_views_.begin();
+ }
+
+ // Returns an const_iterator to the end of the ChannelView vector.
+ std::vector<Channel>::const_iterator end() const {
+ return channel_views_.end();
+ }
+
+ // Fills all channels with zeros and reenables |Channel|s.
+ void Clear() {
+ for (Channel& channel : channel_views_) {
+ channel.SetEnabled(true);
+ channel.Clear();
+ }
+ }
+
+ // Returns the number of allocated frames per |Channel|. Note this may
+ // differ from the actual size of the |Channel| to ensure alignment of all
+ // |Channel|s.
+ size_t GetChannelStride() const {
+ return FindNextAlignedArrayIndex(num_frames_, sizeof(float),
+ kMemoryAlignmentBytes);
+ }
+
+ // Sets the source id of which the buffer belongs to.
+ void set_source_id(SourceId source_id) { source_id_ = source_id; }
+
+ private:
+ // Allocates memory and initializes vector of |ChannelView|s.
+ void InitChannelViews(size_t num_channels);
+
+ // Number of frames per buffer.
+ size_t num_frames_;
+
+ // Audio buffer that sequentially stores multiple audio channels in a planar
+ // format.
+ AlignedFloatVector data_;
+
+ // Size of audio buffer.
+ size_t data_size_;
+
+ // Vector of |AudioBuffer::Channel|s.
+ std::vector<Channel> channel_views_;
+
+ // Id of a source that this buffer belongs to.
+ SourceId source_id_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_BASE_AUDIO_BUFFER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer_test.cc b/src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer_test.cc
new file mode 100644
index 000000000..2c8f3e20b
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/audio_buffer_test.cc
@@ -0,0 +1,144 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "base/audio_buffer.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// Tests default constructor.
+TEST(AudioBuffer, AudioBufferDefaultConstructor) {
+ AudioBuffer audio_buffer;
+ EXPECT_EQ(audio_buffer.num_channels(), 0U);
+ EXPECT_EQ(audio_buffer.num_frames(), 0U);
+}
+
+// Tests initialization of |AudioBuffer|.
+TEST(AudioBuffer, AudioBufferInitializationTest) {
+ static const size_t kNumChannels = 2;
+ static const size_t kFramesPerBuffer = 16;
+ AudioBuffer audio_buffer(kNumChannels, kFramesPerBuffer);
+
+ EXPECT_EQ(audio_buffer.num_channels(), kNumChannels);
+ EXPECT_EQ(audio_buffer.num_frames(), kFramesPerBuffer);
+ EXPECT_EQ(static_cast<size_t>(audio_buffer.end() - audio_buffer.begin()),
+ kNumChannels);
+
+ // Test range-based for-loop.
+ size_t channel_idx = 0;
+ for (const AudioBuffer::Channel& channel : audio_buffer) {
+ EXPECT_EQ(channel.begin(), audio_buffer[channel_idx].begin());
+ EXPECT_EQ(channel.end(), audio_buffer[channel_idx].end());
+ ++channel_idx;
+ }
+}
+
+// Tests assignment operator from std::vector<std::vector<float>>.
+TEST(AudioBuffer, AudioBufferAssignmentOperator) {
+ const std::vector<std::vector<float>> kTestVector = {
+ {0.0f, 1.0f, 2.0f}, {3.0f, 4.0f, 5.0f}, {6.0f, 7.0f, 8.0f}};
+
+ AudioBuffer audio_buffer(kTestVector.size(), kTestVector[0].size());
+ audio_buffer = kTestVector;
+
+ for (size_t channel = 0; channel < kTestVector.size(); ++channel) {
+ for (size_t frame = 0; frame < kTestVector[0].size(); ++frame) {
+ EXPECT_EQ(audio_buffer[channel][frame], kTestVector[channel][frame]);
+ }
+ }
+}
+
+// Tests move constructor.
+TEST(AudioBuffer, AudioBufferMoveConstructor) {
+ const std::vector<std::vector<float>> kTestVector = {
+ {0.0f, 1.0f, 2.0f}, {3.0f, 4.0f, 5.0f}, {6.0f, 7.0f, 8.0f}};
+
+ AudioBuffer audio_buffer(kTestVector.size(), kTestVector[0].size());
+ audio_buffer = kTestVector;
+ const size_t num_channels = audio_buffer.num_channels();
+ const size_t num_frames = audio_buffer.num_frames();
+
+ AudioBuffer moved_audio_buffer(std::move(audio_buffer));
+ EXPECT_EQ(audio_buffer.num_channels(), 0U);
+ EXPECT_EQ(audio_buffer.num_frames(), 0U);
+ EXPECT_EQ(moved_audio_buffer.num_channels(), num_channels);
+ EXPECT_EQ(moved_audio_buffer.num_frames(), num_frames);
+
+ for (size_t channel = 0; channel < kTestVector.size(); ++channel) {
+ for (size_t frame = 0; frame < kTestVector[0].size(); ++frame) {
+ EXPECT_EQ(moved_audio_buffer[channel][frame],
+ kTestVector[channel][frame]);
+ }
+ }
+}
+
+// Tests memory alignment of each channel buffer. The address if the first
+// element of each channel should be memory aligned.
+TEST(AudioBuffer, TestBufferAlignment) {
+ static const size_t kNumRuns = 100;
+ static const size_t kNumChannels = 16;
+
+ for (size_t run = 0; run < kNumRuns; ++run) {
+ const size_t frames_per_buffer = run + 1;
+ AudioBuffer audio_buffer(kNumChannels, frames_per_buffer);
+ for (size_t channel = 0; channel < kNumChannels; ++channel) {
+ const AudioBuffer::Channel& channel_view = audio_buffer[channel];
+ const bool is_aligned =
+ ((reinterpret_cast<size_t>(&(*channel_view.begin())) &
+ (kMemoryAlignmentBytes - 1)) == 0);
+ EXPECT_TRUE(is_aligned);
+ }
+ }
+}
+
+// Tests Clear method.
+TEST(AudioBuffer, AudioBufferClear) {
+ const std::vector<std::vector<float>> kTestVector = {
+ {0.0f, 1.0f, 2.0f}, {3.0f, 4.0f, 5.0f}, {6.0f, 7.0f, 8.0f}};
+
+ AudioBuffer audio_buffer(kTestVector.size(), kTestVector[0].size());
+ audio_buffer = kTestVector;
+
+ audio_buffer.Clear();
+
+ for (size_t channel = 0; channel < kTestVector.size(); ++channel) {
+ for (size_t frame = 0; frame < kTestVector[0].size(); ++frame) {
+ EXPECT_EQ(0.0f, audio_buffer[channel][frame]);
+ }
+ }
+}
+
+// Tests GetChannelStride method.
+TEST(AudioBuffer, GetChannelStride) {
+ const size_t num_frames_per_alignment = kMemoryAlignmentBytes / sizeof(float);
+ for (size_t num_frames = 1; num_frames < num_frames_per_alignment * 5;
+ ++num_frames) {
+ AudioBuffer buffer(1, num_frames);
+ // Fast way to ceil(frame/num_frames_per_alignment).
+ const size_t expected_num_alignment_blocks =
+ (num_frames + num_frames_per_alignment - 1) / num_frames_per_alignment;
+ EXPECT_EQ(expected_num_alignment_blocks * num_frames_per_alignment,
+ buffer.GetChannelStride());
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/channel_view.cc b/src/3rdparty/resonance-audio/resonance_audio/base/channel_view.cc
new file mode 100644
index 000000000..e3d6fe14a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/channel_view.cc
@@ -0,0 +1,50 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "base/channel_view.h"
+
+#include "base/simd_utils.h"
+
+namespace vraudio {
+
+ChannelView& ChannelView::operator+=(const ChannelView& other) {
+ DCHECK_EQ(other.size(), size_);
+ DCHECK(enabled_);
+ float* this_sample = begin();
+ const float* other_sample = other.begin();
+ AddPointwise(size_, other_sample, this_sample, this_sample);
+ return *this;
+}
+
+ChannelView& ChannelView::operator-=(const ChannelView& other) {
+ DCHECK_EQ(other.size(), size_);
+ DCHECK(enabled_);
+ float* this_sample = begin();
+ const float* other_sample = other.begin();
+ SubtractPointwise(size_, other_sample, this_sample, this_sample);
+ return *this;
+}
+
+ChannelView& ChannelView::operator*=(const ChannelView& other) {
+ DCHECK_EQ(other.size(), size_);
+ DCHECK(enabled_);
+ float* this_sample = begin();
+ const float* other_sample = other.begin();
+ MultiplyPointwise(size_, other_sample, this_sample, this_sample);
+ return *this;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/channel_view.h b/src/3rdparty/resonance-audio/resonance_audio/base/channel_view.h
new file mode 100644
index 000000000..557773a99
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/channel_view.h
@@ -0,0 +1,138 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_BASE_CHANNEL_VIEW_H_
+#define RESONANCE_AUDIO_BASE_CHANNEL_VIEW_H_
+
+#include <algorithm>
+#include <cstring>
+#include <vector>
+
+#include "base/logging.h"
+
+namespace vraudio {
+
+// Provides an interface to a single audio channel in |AudioBuffer|. Note that a
+// |ChannelView| instance does not own the data it is initialized with.
+class ChannelView {
+ public:
+ // Array subscript operator returning a reference.
+ float& operator[](size_t index) {
+ DCHECK(enabled_);
+ DCHECK_LT(index, size_);
+ return *(begin() + index);
+ }
+
+ // Const array subscript operator returning a const reference.
+ const float& operator[](size_t index) const {
+ DCHECK(enabled_);
+ DCHECK_LT(index, size_);
+ return *(begin() + index);
+ }
+
+ // Returns the size of the channel in samples.
+ size_t size() const { return size_; }
+
+ // Returns a float pointer to the begin of the channel data.
+ float* begin() {
+ DCHECK(enabled_);
+ return begin_itr_;
+ }
+
+ // Returns a float pointer to the end of the channel data.
+ float* end() {
+ DCHECK(enabled_);
+ return begin_itr_ + size_;
+ }
+
+ // Returns a const float pointer to the begin of the channel data.
+ const float* begin() const {
+ DCHECK(enabled_);
+ return begin_itr_;
+ }
+
+ // Returns a const float pointer to the end of the channel data.
+ const float* end() const {
+ DCHECK(enabled_);
+ return begin_itr_ + size_;
+ }
+
+ // Copy assignment from float vector.
+ ChannelView& operator=(const std::vector<float>& other) {
+ DCHECK(enabled_);
+ DCHECK_EQ(other.size(), size_);
+ memcpy(begin(), other.data(), sizeof(float) * size_);
+ return *this;
+ }
+
+ // Copy assignment from ChannelView.
+ ChannelView& operator=(const ChannelView& other) {
+ if (this != &other) {
+ DCHECK(enabled_);
+ DCHECK_EQ(other.size(), size_);
+ memcpy(begin(), other.begin(), sizeof(float) * size_);
+ }
+ return *this;
+ }
+
+ // Adds a |ChannelView| to this |ChannelView|.
+ ChannelView& operator+=(const ChannelView& other);
+
+ // Subtracts a |ChannelView| from this |ChannelView|.
+ ChannelView& operator-=(const ChannelView& other);
+
+ // Pointwise multiplies a |ChannelView| with this |Channelview|.
+ ChannelView& operator*=(const ChannelView& other);
+
+ // Fills channel buffer with zeros.
+ void Clear() {
+ DCHECK(enabled_);
+ memset(begin(), 0, sizeof(float) * size_);
+ }
+
+ // Allows for disabling the channel to prevent access to the channel data and
+ // channel iterators. It is used in the |Mixer| class to prevent the copies of
+ // silence |ChannelView|s. Note that |ChannelView| are enabled by default.
+ //
+ // @param enabled True to enable the channel.
+ void SetEnabled(bool enabled) { enabled_ = enabled; }
+
+ // Returns true if |ChannelView| is enabled.
+ //
+ // @return State of |enabled_| flag.
+ bool IsEnabled() const { return enabled_; }
+
+ private:
+ friend class AudioBuffer;
+
+ // Constructor is initialized with a float pointer to the first sample and the
+ // size of chunk of planar channel data.
+ ChannelView(float* begin_itr, size_t size)
+ : begin_itr_(begin_itr), size_(size), enabled_(true) {}
+
+ // Iterator of first and last element in channel.
+ float* const begin_itr_;
+
+ // Channel size.
+ const size_t size_;
+
+ // Flag indicating if the channel is enabled.
+ bool enabled_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_BASE_CHANNEL_VIEW_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/channel_view_test.cc b/src/3rdparty/resonance-audio/resonance_audio/base/channel_view_test.cc
new file mode 100644
index 000000000..24b04dfd9
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/channel_view_test.cc
@@ -0,0 +1,157 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "base/channel_view.h"
+
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+namespace {
+
+const float kTestData[] = {0.0f, 1.0f, 2.0f};
+const size_t kTestDataSize = sizeof(kTestData) / sizeof(float);
+
+typedef std::vector<float> Buffer;
+
+// Tests initialization of |ChannelView| class.
+TEST(ChannelView, InitializationTest) {
+ AudioBuffer test_buffer(1, kTestDataSize);
+ ChannelView& test_buffer_view = test_buffer[0];
+ for (size_t i = 0; i < kTestDataSize; ++i) {
+ test_buffer_view[i] = kTestData[i];
+ }
+
+ EXPECT_EQ(test_buffer.num_frames(), test_buffer_view.size());
+ EXPECT_EQ(&test_buffer[0][0], test_buffer_view.begin());
+ EXPECT_EQ(&test_buffer[0][0] + test_buffer.num_frames(),
+ test_buffer_view.end());
+}
+
+// Tests iterators and array subscript of |ChannelView|.
+TEST(ChannelView, IteratorAndArraySubscriptTest) {
+ AudioBuffer test_buffer(1, kTestDataSize);
+ ChannelView& test_buffer_view = test_buffer[0];
+ for (size_t i = 0; i < kTestDataSize; ++i) {
+ test_buffer_view[i] = kTestData[i];
+ }
+
+ for (size_t i = 0; i < test_buffer_view.size(); i++) {
+ EXPECT_EQ(test_buffer[0][i], test_buffer_view[i]);
+ EXPECT_EQ(kTestData[i], test_buffer_view[i]);
+ }
+
+ // Test range-based for-loops.
+ for (float& sample : test_buffer_view) {
+ sample *= 2.0f;
+ }
+ size_t idx = 0;
+ for (const float& sample : test_buffer_view) {
+ EXPECT_EQ(kTestData[idx] * 2.0f, sample);
+ ++idx;
+ }
+}
+
+// Tests copy-assignment operators.
+TEST(ChannelView, CopyAssignmentTest) {
+ AudioBuffer test_buffer(1, kTestDataSize);
+ ChannelView& test_buffer_view = test_buffer[0];
+ for (size_t i = 0; i < kTestDataSize; ++i) {
+ test_buffer_view[i] = kTestData[i];
+ }
+
+ AudioBuffer target_buffer(1, kTestDataSize);
+ ChannelView& target_vector_view = target_buffer[0];
+ for (size_t i = 0; i < kTestDataSize; ++i) {
+ target_vector_view[i] = -1.0f;
+ }
+
+ // Copy assignment from ChannelView.
+ target_vector_view = test_buffer_view;
+
+ for (size_t i = 0; i < test_buffer_view.size(); i++) {
+ EXPECT_EQ(test_buffer_view[i], target_vector_view[i]);
+ }
+
+ AudioBuffer target2_buffer(1, kTestDataSize);
+ ChannelView& target2_vector_view = target2_buffer[0];
+ for (size_t i = 0; i < kTestDataSize; ++i) {
+ target2_vector_view[i] = -1.0f;
+ }
+
+ // Copy assignment from AudioBuffer channel.
+ target2_vector_view = test_buffer[0];
+
+ for (size_t i = 0; i < test_buffer_view.size(); i++) {
+ EXPECT_EQ(test_buffer[0][i], target2_vector_view[i]);
+ }
+}
+
+// Tests addition-assignment operator.
+TEST(ChannelView, AdditionOperatorTest) {
+ // Here an AudioBuffer is used to ensure that the data is aligned.
+ AudioBuffer test_buffer(1, kTestDataSize);
+ ChannelView& test_buffer_view = test_buffer[0];
+ for (size_t i = 0; i < kTestDataSize; ++i) {
+ test_buffer_view[i] = kTestData[i];
+ }
+
+ // Execute |ChannelView|s addition operator.
+ test_buffer_view += test_buffer_view;
+
+ for (size_t i = 0; i < test_buffer_view.size(); i++) {
+ EXPECT_EQ(kTestData[i] * 2.0f, test_buffer_view[i]);
+ }
+}
+
+// Tests subtraction-assignment operator.
+TEST(ChannelView, SubtractionOperatorTest) {
+ // Here an AudioBuffer is used to ensure that the data is aligned.
+ AudioBuffer test_buffer(1, kTestDataSize);
+ ChannelView& test_buffer_view = test_buffer[0];
+ for (size_t i = 0; i < kTestDataSize; ++i) {
+ test_buffer_view[i] = kTestData[i];
+ }
+
+ // Execute |ChannelView|s subtraction operator.
+ test_buffer_view -= test_buffer_view;
+
+ for (size_t i = 0; i < test_buffer_view.size(); i++) {
+ EXPECT_EQ(0.0f, test_buffer_view[i]);
+ }
+}
+
+// Tests Clear method.
+TEST(ChannelView, ClearTest) {
+ AudioBuffer test_buffer(1, kTestDataSize);
+ ChannelView& test_buffer_view = test_buffer[0];
+ for (size_t i = 0; i < kTestDataSize; ++i) {
+ test_buffer_view[i] = kTestData[i];
+ }
+
+ test_buffer_view.Clear();
+
+ for (const float& sample : test_buffer_view) {
+ EXPECT_EQ(0.0f, sample);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/constants_and_types.h b/src/3rdparty/resonance-audio/resonance_audio/base/constants_and_types.h
new file mode 100644
index 000000000..591c958dd
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/constants_and_types.h
@@ -0,0 +1,176 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_BASE_CONSTANTS_AND_TYPES_H_
+#define RESONANCE_AUDIO_BASE_CONSTANTS_AND_TYPES_H_
+
+#include <cmath>
+#include <string> // for size_t
+
+namespace vraudio {
+
+// Sound object / ambisonic source identifier.
+
+typedef int SourceId;
+
+// Invalid source id that can be used to initialize handler variables during
+// class construction.
+static const SourceId kInvalidSourceId = -1;
+
+
+// Defines memory alignment of audio buffers. Note that not only the first
+// element of the |data_| buffer is memory aligned but also the address of the
+// first elements of the |ChannelView|s.
+const size_t kMemoryAlignmentBytes = 64;
+
+// Maximum Ambisonic order currently supported in vr audio, equivalent to High
+// Quality sound object rendering mode. This number is limited by a) number of
+// HRIR data points used in the binaural renderer; b) size of the lookup table
+// controlling the angular spread of a sound source in the Ambisonic Lookup
+// Table class.
+static const int kMaxSupportedAmbisonicOrder = 3;
+
+// Maximum allowed size of internal buffers.
+const size_t kMaxSupportedNumFrames = 16384;
+
+// Number of mono channels.
+static const size_t kNumMonoChannels = 1;
+
+// Number of stereo channels.
+static const size_t kNumStereoChannels = 2;
+
+// Number of surround 5.1 channels.
+static const size_t kNumSurroundFiveDotOneChannels = 6;
+
+// Number of surround 7.1 channels.
+static const size_t kNumSurroundSevenDotOneChannels = 8;
+
+// Number of first-order ambisonic channels.
+static const size_t kNumFirstOrderAmbisonicChannels = 4;
+
+// Number of second-order ambisonic channels.
+static const size_t kNumSecondOrderAmbisonicChannels = 9;
+
+// Number of third-order ambisonic channels.
+static const size_t kNumThirdOrderAmbisonicChannels = 16;
+
+// Number of first-order ambisonic with non-diegetic stereo channels.
+static const size_t kNumFirstOrderAmbisonicWithNonDiegeticStereoChannels = 6;
+
+// Number of second-order ambisonic with non-diegetic stereo channels.
+static const size_t kNumSecondOrderAmbisonicWithNonDiegeticStereoChannels = 11;
+
+// Number of third-order ambisonic with non-diegetic stereo channels.
+static const size_t kNumThirdOrderAmbisonicWithNonDiegeticStereoChannels = 18;
+
+// Negative 60dB in amplitude.
+static const float kNegative60dbInAmplitude = 0.001f;
+
+// Tolerated error margins for floating points.
+static const double kEpsilonDouble = 1e-6;
+static const float kEpsilonFloat = 1e-6f;
+
+// Inverse square root of two (equivalent to -3dB audio signal attenuation).
+static const float kInverseSqrtTwo = 1.0f / std::sqrt(2.0f);
+
+// Square roots.
+static const float kSqrtTwo = std::sqrt(2.0f);
+static const float kSqrtThree = std::sqrt(3.0f);
+
+// Pi in radians.
+static const float kPi = static_cast<float>(M_PI);
+// Half pi in radians.
+static const float kHalfPi = static_cast<float>(M_PI / 2.0);
+// Two pi in radians.
+static const float kTwoPi = static_cast<float>(2.0 * M_PI);
+
+// Defines conversion factor from degrees to radians.
+static const float kRadiansFromDegrees = static_cast<float>(M_PI / 180.0);
+
+// Defines conversion factor from radians to degrees.
+static const float kDegreesFromRadians = static_cast<float>(180.0 / M_PI);
+
+// The negated natural logarithm of 1000.
+static const float kNegativeLog1000 = -std::log(1000.0f);
+
+// The lowest octave band for computing room effects.
+static const float kLowestOctaveBandHz = 31.25f;
+
+// Number of octave bands in which room effects are computed.
+static const size_t kNumReverbOctaveBands = 9;
+
+// Centers of possible frequency bands up 8 kHz.
+// ------------------------------------
+// Band no. Low Center High [Frequencies in Hz]
+// ------------------------------------
+// 0 22 31.25 44.2
+// 1 44.2 62.5 88.4
+// 2 88.4 125 176.8
+// 3 176.8 250 353.6
+// 4 353.6 500 707.1
+// 5 707.1 1000 1414.2
+// 6 1414.2 2000 2828.4
+// 7 2828.4 4000 5656.9
+// 8 5656.9 8000 11313.7
+//--------------------------------------
+const float kOctaveBandCentres[kNumReverbOctaveBands] = {
+ 31.25f, 62.5f, 125.0f, 250.0f, 500.0f, 1000.0f, 2000.0f, 4000.0f, 8000.0f};
+
+// Number of surfaces in a shoe-box room.
+static const size_t kNumRoomSurfaces = 6;
+
+// Speed of sound in air at 20 degrees Celsius in meters per second.
+// http://www.sengpielaudio.com/calculator-speedsound.htm
+static const float kSpeedOfSound = 343.0f;
+
+// Locations of the stereo virtual loudspeakers in degrees.
+static const float kStereoLeftDegrees = 90.0f;
+static const float kStereoRightDegrees = -90.0f;
+
+// Conversion factor from seconds to milliseconds.
+static const float kMillisecondsFromSeconds = 1000.0f;
+
+// Conversion factor from milliseconds to seconds.
+static const float kSecondsFromMilliseconds = 0.001f;
+
+// Conversion factor from seconds to milliseconds.
+static const double kMicrosecondsFromSeconds = 1e6;
+
+// Conversion factor from milliseconds to seconds.
+static const double kSecondsFromMicroseconds = 1e-6;
+
+// The distance threshold where the near field effect should fade in.
+static const float kNearFieldThreshold = 1.0f;
+
+// Minimum allowed distance of a near field sound source used to cap the allowed
+// energy boost.
+static const float kMinNearFieldDistance = 0.1f;
+
+// Maximum gain applied by Near Field Effect to the mono source signal.
+static const float kMaxNearFieldEffectGain = 9.0f;
+
+// Number of samples across which the gain value should be interpolated for
+// a unit gain change of 1.0f.
+
+static const size_t kUnitRampLength = 2048;
+
+// Rotation quantization which applies in ambisonic soundfield rotators.
+
+static const float kRotationQuantizationRad = 1.0f * kRadiansFromDegrees;
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_BASE_CONSTANTS_AND_TYPES_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/integral_types.h b/src/3rdparty/resonance-audio/resonance_audio/base/integral_types.h
new file mode 100644
index 000000000..7a4d9216e
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/integral_types.h
@@ -0,0 +1,121 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Copyright 2015 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Basic integer type definitions for various platforms
+
+#ifndef BASE_INTEGRAL_TYPES_H_
+#define BASE_INTEGRAL_TYPES_H_
+
+// Standard typedefs
+typedef signed char schar;
+typedef signed char int8;
+typedef short int16;
+typedef int int32;
+#ifdef _MSC_VER
+typedef __int64 int64;
+#else
+typedef long long int64;
+#endif /* _MSC_VER */
+
+// NOTE: unsigned types are DANGEROUS in loops and other arithmetical
+// places. Use the signed types unless your variable represents a bit
+// pattern (eg a hash value) or you really need the extra bit. Do NOT
+// use 'unsigned' to express "this value should always be positive";
+// use assertions for this.
+
+typedef unsigned char uint8;
+typedef unsigned short uint16;
+typedef unsigned int uint32;
+#ifdef _MSC_VER
+typedef unsigned __int64 uint64;
+#else
+typedef unsigned long long uint64;
+#endif /* _MSC_VER */
+
+// A type to represent a Unicode code-point value. As of Unicode 4.0,
+// such values require up to 21 bits.
+// (For type-checking on pointers, make this explicitly signed,
+// and it should always be the signed version of whatever int32 is.)
+typedef signed int char32;
+
+// A type to represent a natural machine word (for e.g. efficiently
+// scanning through memory for checksums or index searching). Don't use
+// this for storing normal integers. Ideally this would be just
+// unsigned int, but our 64-bit architectures use the LP64 model
+// (http://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models), hence
+// their ints are only 32 bits. We want to use the same fundamental
+// type on all archs if possible to preserve *printf() compatability.
+typedef unsigned long uword_t;
+
+// long long macros to be used because gcc and vc++ use different suffixes,
+// and different size specifiers in format strings
+#undef GG_LONGLONG
+#undef GG_ULONGLONG
+#undef GG_LL_FORMAT
+
+#ifdef _MSC_VER /* if Visual C++ */
+
+// VC++ long long suffixes
+#define GG_LONGLONG(x) x##I64
+#define GG_ULONGLONG(x) x##UI64
+
+// Length modifier in printf format string for int64's (e.g. within %d)
+#define GG_LL_FORMAT "I64" // As in printf("%I64d", ...)
+#define GG_LL_FORMAT_W L"I64"
+
+#else /* not Visual C++ */
+
+#define GG_LONGLONG(x) x##LL
+#define GG_ULONGLONG(x) x##ULL
+#define GG_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also.
+#define GG_LL_FORMAT_W L"ll"
+
+#endif // _MSC_VER
+
+
+static const uint8 kuint8max = (( uint8) 0xFF);
+static const uint16 kuint16max = ((uint16) 0xFFFF);
+static const uint32 kuint32max = ((uint32) 0xFFFFFFFF);
+static const uint64 kuint64max = ((uint64) GG_LONGLONG(0xFFFFFFFFFFFFFFFF));
+static const int8 kint8min = (( int8) ~0x7F);
+static const int8 kint8max = (( int8) 0x7F);
+static const int16 kint16min = (( int16) ~0x7FFF);
+static const int16 kint16max = (( int16) 0x7FFF);
+static const int32 kint32min = (( int32) ~0x7FFFFFFF);
+static const int32 kint32max = (( int32) 0x7FFFFFFF);
+static const int64 kint64min = (( int64) GG_LONGLONG(~0x7FFFFFFFFFFFFFFF));
+static const int64 kint64max = (( int64) GG_LONGLONG(0x7FFFFFFFFFFFFFFF));
+
+
+typedef uint64 Fprint;
+static const Fprint kIllegalFprint = 0;
+static const Fprint kMaxFprint = GG_ULONGLONG(0xFFFFFFFFFFFFFFFF);
+
+#endif // BASE_INTEGRAL_TYPES_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/logging.h b/src/3rdparty/resonance-audio/resonance_audio/base/logging.h
new file mode 100644
index 000000000..63dd00431
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/logging.h
@@ -0,0 +1,108 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_PLATFORM_LOGGING_H_
+#define RESONANCE_AUDIO_PLATFORM_LOGGING_H_
+
+#include <cstdlib>
+
+#include <cassert>
+#include <iostream>
+#include <sstream>
+
+#undef DCHECK
+#undef DCHECK_EQ
+#undef DCHECK_NE
+#undef DCHECK_LE
+#undef DCHECK_LT
+#undef DCHECK_GE
+#undef DCHECK_GT
+#undef CHECK
+#undef CHECK_EQ
+#undef CHECK_NE
+#undef CHECK_LE
+#undef CHECK_LT
+#undef CHECK_GE
+#undef CHECK_GT
+#undef CHECK_NOTNULL
+#undef LOG
+
+// This class is used to disable logging, while still allowing for log messages
+// to contain '<<' expressions.
+class NullLogger {
+ public:
+ std::ostream& GetStream() {
+ static std::ostream kNullStream(nullptr);
+ return kNullStream;
+ }
+};
+
+// If statement prevents unused variable warnings.
+#define DCHECK(expr) \
+ if (false && (expr)) \
+ ; \
+ else \
+ NullLogger().GetStream()
+#define DCHECK_OP(val1, val2, op) DCHECK((val1)op(val2))
+
+#define DCHECK_EQ(val1, val2) DCHECK_OP((val1), (val2), ==)
+#define DCHECK_NE(val1, val2) DCHECK_OP((val1), (val2), !=)
+#define DCHECK_LE(val1, val2) DCHECK_OP((val1), (val2), <=)
+#define DCHECK_LT(val1, val2) DCHECK_OP((val1), (val2), <)
+#define DCHECK_GE(val1, val2) DCHECK_OP((val1), (val2), >=)
+#define DCHECK_GT(val1, val2) DCHECK_OP((val1), (val2), >)
+
+// This class is used to log to std::cerr.
+class FatalLogger {
+ public:
+ FatalLogger(const char* file, int line) {
+ error_string_ << file << ":" << line << ": ";
+ }
+ ~FatalLogger() {
+ const std::string error_string = error_string_.str();
+ std::cerr << error_string << std::endl;
+ abort();
+ }
+ std::ostream& GetStream() { return error_string_; }
+
+ private:
+ std::ostringstream error_string_;
+};
+
+#define CHECK(condition) \
+ !(condition) ? FatalLogger(__FILE__, __LINE__).GetStream() \
+ : NullLogger().GetStream()
+
+#define CHECK_OP(val1, val2, op) CHECK((val1)op(val2))
+
+#define CHECK_EQ(val1, val2) CHECK_OP((val1), (val2), ==)
+#define CHECK_NE(val1, val2) CHECK_OP((val1), (val2), !=)
+#define CHECK_LE(val1, val2) CHECK_OP((val1), (val2), <=)
+#define CHECK_LT(val1, val2) CHECK_OP((val1), (val2), <)
+#define CHECK_GE(val1, val2) CHECK_OP((val1), (val2), >=)
+#define CHECK_GT(val1, val2) CHECK_OP((val1), (val2), >)
+
+// Helper for CHECK_NOTNULL(), using C++11 perfect forwarding.
+template <typename T>
+T CheckNotNull(T&& t) {
+ assert(t != nullptr);
+ return std::forward<T>(t);
+}
+#define CHECK_NOTNULL(val) CheckNotNull(val)
+
+#define LOG(severity) NullLogger().GetStream()
+
+#endif // RESONANCE_AUDIO_PLATFORM_LOGGING_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/misc_math.cc b/src/3rdparty/resonance-audio/resonance_audio/base/misc_math.cc
new file mode 100644
index 000000000..4de96ba41
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/misc_math.cc
@@ -0,0 +1,94 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+WorldPosition::WorldPosition() { setZero(); }
+
+WorldRotation::WorldRotation() { setIdentity(); }
+
+bool LinearLeastSquareFitting(const std::vector<float>& x_array,
+ const std::vector<float>& y_array, float* slope,
+ float* intercept, float* r_squared) {
+ // The array sizes must agree.
+ if (x_array.size() != y_array.size()) {
+ return false;
+ }
+
+ // At least two points are needed to fit a line.
+ if (x_array.size() < 2) {
+ return false;
+ }
+
+ float x_sum = 0.0f;
+ float y_sum = 0.0f;
+ float x_square_sum = 0.0f;
+ float xy_sum = 0.0f;
+
+ for (size_t i = 0; i < x_array.size(); ++i) {
+ const float x = x_array[i];
+ const float y = y_array[i];
+ x_sum += x;
+ y_sum += y;
+ x_square_sum += x * x;
+ xy_sum += x * y;
+ }
+
+ const float n_inverse = 1.0f / static_cast<float>(x_array.size());
+ const float x_mean = x_sum * n_inverse;
+ const float y_mean = y_sum * n_inverse;
+ const float x_square_mean = x_square_sum * n_inverse;
+ const float xy_mean = xy_sum * n_inverse;
+ const float x_mean_square = x_mean * x_mean;
+
+ // Prevent division by zero, which means a vertical line and the slope is
+ // infinite.
+ if (x_square_mean == x_mean_square) {
+ return false;
+ }
+
+ *slope = (xy_mean - x_mean * y_mean) / (x_square_mean - x_mean_square);
+ *intercept = y_mean - *slope * x_mean;
+
+ // Compute the coefficient of determination.
+ float total_sum_of_squares = 0.0f;
+ float residual_sum_of_squares = 0.0f;
+ for (size_t i = 0; i < x_array.size(); ++i) {
+ const float y_i = y_array[i];
+ total_sum_of_squares += (y_i - y_mean) * (y_i - y_mean);
+ const float y_fit = *slope * x_array[i] + *intercept;
+ residual_sum_of_squares += (y_fit - y_i) * (y_fit - y_i);
+ }
+
+ if (total_sum_of_squares == 0.0f) {
+ if (residual_sum_of_squares == 0.0f) {
+ // A special case where all y's are equal, where the |r_squared| should
+ // be 1.0, and the line is a perfectly horizontal line.
+ *r_squared = 1.0f;
+ return true;
+ } else {
+ // Division by zero.
+ return false;
+ }
+ }
+
+ *r_squared = 1.0f - residual_sum_of_squares / total_sum_of_squares;
+ return true;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/misc_math.h b/src/3rdparty/resonance-audio/resonance_audio/base/misc_math.h
new file mode 100644
index 000000000..5993eb55d
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/misc_math.h
@@ -0,0 +1,385 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_BASE_MISC_MATH_H_
+#define RESONANCE_AUDIO_BASE_MISC_MATH_H_
+
+#ifndef _USE_MATH_DEFINES
+#define _USE_MATH_DEFINES // Enable MSVC math constants (e.g., M_PI).
+#endif // _USE_MATH_DEFINES
+
+#include <algorithm>
+#include <cmath>
+#include <cstdint>
+#include <limits>
+#include <utility>
+#include <vector>
+
+#include "base/integral_types.h"
+#include "Eigen/Dense"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+class WorldPosition : public Eigen::Matrix<float, 3, 1, Eigen::DontAlign> {
+ public:
+ // Inherits all constructors with 1-or-more arguments. Necessary because
+ // MSVC12 doesn't support inheriting constructors.
+ template <typename Arg1, typename... Args>
+ WorldPosition(const Arg1& arg1, Args&&... args)
+ : Matrix(arg1, std::forward<Args>(args)...) {}
+
+ // Constructs a zero vector.
+ WorldPosition();
+
+ // Returns True if other |WorldPosition| differs by at least |kEpsilonFloat|.
+ bool operator!=(const WorldPosition& other) const {
+ return std::abs(this->x() - other.x()) > kEpsilonFloat ||
+ std::abs(this->y() - other.y()) > kEpsilonFloat ||
+ std::abs(this->z() - other.z()) > kEpsilonFloat;
+ }
+};
+
+class WorldRotation : public Eigen::Quaternion<float, Eigen::DontAlign> {
+ public:
+ // Inherits all constructors with 1-or-more arguments. Necessary because
+ // MSVC12 doesn't support inheriting constructors.
+ template <typename Arg1, typename... Args>
+ WorldRotation(const Arg1& arg1, Args&&... args)
+ : Quaternion(arg1, std::forward<Args>(args)...) {}
+
+ // Constructs an identity rotation.
+ WorldRotation();
+
+ // Returns the shortest arc between two |WorldRotation|s in radians.
+ float AngularDifferenceRad(const WorldRotation& other) const {
+ const Quaternion difference = this->inverse() * other;
+ return static_cast<float>(Eigen::AngleAxisf(difference).angle());
+ }
+};
+
+typedef Eigen::AngleAxis<float> AngleAxisf;
+
+typedef WorldPosition AudioPosition;
+
+typedef WorldRotation AudioRotation;
+
+// Converts |world_position| into an equivalent audio space position.
+// The world space follows the typical CG coordinate system convention:
+// Positive x points right, positive y points up, negative z points forward.
+// The audio space follows the ambiX coordinate system convention that is
+// commonly accepted in literature [http://goo.gl/XdYNm9]:
+// Positive x points forward, negative y points right, positive z points up.
+// Positions in both world space and audio space are in meters.
+//
+// @param world_position 3D position in world space.
+// @param audio_position Output 3D position in audio space.
+inline void ConvertAudioFromWorldPosition(const WorldPosition& world_position,
+ AudioPosition* audio_position) {
+ DCHECK(audio_position);
+ (*audio_position)(0) = -world_position[2];
+ (*audio_position)(1) = -world_position[0];
+ (*audio_position)(2) = world_position[1];
+}
+
+// Converts |audio_position| into an equivalent world space position.
+// The world space follows the typical CG coordinate system convention:
+// Positive x points right, positive y points up, negative z points forward.
+// The audio space follows the ambiX coordinate system convention that is
+// commonly accepted in literature [http://goo.gl/XdYNm9]:
+// Positive x points forward, negative y points right, positive z points up.
+// Positions in both world space and audio space are in meters.
+//
+// @param audio_position 3D position in audio space.
+// @param world_position Output 3D position in world space.
+inline void ConvertWorldFromAudioPosition(const AudioPosition& audio_position,
+ AudioPosition* world_position) {
+ DCHECK(world_position);
+ (*world_position)(0) = -audio_position[1];
+ (*world_position)(1) = audio_position[2];
+ (*world_position)(2) = -audio_position[0];
+}
+
+// Converts |world_rotation| into an equivalent audio space rotation.
+// The world space follows the typical CG coordinate system convention:
+// Positive x points right, positive y points up, negative z points forward.
+// The audio space follows the ambiX coordinate system convention that is
+// commonly accepted in literature [http://goo.gl/XdYNm9]:
+// Positive x points forward, negative y points right, positive z points up.
+// Positions in both world space and audio space are in meters.
+//
+// @param world_rotation 3D rotation in world space.
+// @param audio_rotation Output 3D rotation in audio space.
+inline void ConvertAudioFromWorldRotation(const WorldRotation& world_rotation,
+ AudioRotation* audio_rotation) {
+ DCHECK(audio_rotation);
+ audio_rotation->w() = world_rotation.w();
+ audio_rotation->x() = -world_rotation.x();
+ audio_rotation->y() = world_rotation.y();
+ audio_rotation->z() = -world_rotation.z();
+}
+
+// Returns the relative direction vector |from_position| and |to_position| by
+// rotating the relative position vector with respect to |from_rotation|.
+//
+// @param from_position Origin position of the direction.
+// @param from_rotation Origin orientation of the direction.
+// @param to_position Target position of the direction.
+// @param relative_direction Relative direction vector (not normalized).
+inline void GetRelativeDirection(const WorldPosition& from_position,
+ const WorldRotation& from_rotation,
+ const WorldPosition& to_position,
+ WorldPosition* relative_direction) {
+ DCHECK(relative_direction);
+ *relative_direction =
+ from_rotation.conjugate() * (to_position - from_position);
+}
+
+// Returns the closest relative position in an axis-aligned bounding box to the
+// given |relative_position|.
+//
+// @param position Input position relative to the center of the bounding box.
+// @param aabb_dimensions Bounding box dimensions.
+// @return aabb bounded position.
+inline void GetClosestPositionInAabb(const WorldPosition& relative_position,
+ const WorldPosition& aabb_dimensions,
+ WorldPosition* closest_position) {
+ DCHECK(closest_position);
+ const WorldPosition aabb_offset = 0.5f * aabb_dimensions;
+ (*closest_position)[0] =
+ std::min(std::max(relative_position[0], -aabb_offset[0]), aabb_offset[0]);
+ (*closest_position)[1] =
+ std::min(std::max(relative_position[1], -aabb_offset[1]), aabb_offset[1]);
+ (*closest_position)[2] =
+ std::min(std::max(relative_position[2], -aabb_offset[2]), aabb_offset[2]);
+}
+
+// Returns true if given world |position| is in given axis-aligned bounding box.
+//
+// @param position Position to be tested.
+// @param aabb_center Bounding box center.
+// @param aabb_dimensions Bounding box dimensions.
+// @return True if |position| is within bounding box, false otherwise.
+inline bool IsPositionInAabb(const WorldPosition& position,
+ const WorldPosition& aabb_center,
+ const WorldPosition& aabb_dimensions) {
+ return std::abs(position[0] - aabb_center[0]) <= 0.5f * aabb_dimensions[0] &&
+ std::abs(position[1] - aabb_center[1]) <= 0.5f * aabb_dimensions[1] &&
+ std::abs(position[2] - aabb_center[2]) <= 0.5f * aabb_dimensions[2];
+}
+
+// Returns true if an integer overflow occurred during the calculation of
+// x = a * b.
+//
+// @param a First multiplicand.
+// @param b Second multiplicand.
+// @param x Product.
+// @return True if integer overflow occurred, false otherwise.
+template <typename T>
+inline bool DoesIntegerMultiplicationOverflow(T a, T b, T x) {
+ // Detects an integer overflow occurs by inverting the multiplication and
+ // testing for x / a != b.
+ return a == 0 ? false : (x / a != b);
+}
+
+// Returns true if an integer overflow occurred during the calculation of
+// a + b.
+//
+// @param a First summand.
+// @param b Second summand.
+// @return True if integer overflow occurred, false otherwise.
+template <typename T>
+inline bool DoesIntegerAdditionOverflow(T a, T b) {
+ T x = a + b;
+ return x < b;
+}
+
+// Safely converts an int to a size_t.
+//
+// @param i Integer input.
+// @param x Size_t output.
+// @return True if integer overflow occurred, false otherwise.
+inline bool DoesIntSafelyConvertToSizeT(int i, size_t* x) {
+ if (i < 0) {
+ return false;
+ }
+ *x = static_cast<size_t>(i);
+ return true;
+}
+
+// Safely converts a size_t to an int.
+//
+// @param i Size_t input.
+// @param x Integer output.
+// @return True if integer overflow occurred, false otherwise.
+inline bool DoesSizeTSafelyConvertToInt(size_t i, int* x) {
+ if (i > static_cast<size_t>(std::numeric_limits<int>::max())) {
+ return false;
+ }
+ *x = static_cast<int>(i);
+ return true;
+}
+
+// Finds the greatest common divisor between two integer values using the
+// Euclidean algorithm. Always returns a positive integer.
+//
+// @param a First of the two integer values.
+// @param b second of the two integer values.
+// @return The greatest common divisor of the two integer values.
+inline int FindGcd(int a, int b) {
+ a = std::abs(a);
+ b = std::abs(b);
+ int temp_value = 0;
+ while (b != 0) {
+ temp_value = b;
+ b = a % b;
+ a = temp_value;
+ }
+ return a;
+}
+
+// Finds the next power of two from an integer. This method works with values
+// representable by unsigned 32 bit integers.
+//
+// @param input Integer value.
+// @return The next power of two from |input|.
+inline size_t NextPowTwo(size_t input) {
+ // Ensure the value fits in a uint32_t.
+ DCHECK_LT(static_cast<uint64_t>(input),
+ static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()));
+ uint32_t number = static_cast<uint32_t>(--input);
+ number |= number >> 1; // Take care of 2 bit numbers.
+ number |= number >> 2; // Take care of 4 bit numbers.
+ number |= number >> 4; // Take care of 8 bit numbers.
+ number |= number >> 8; // Take care of 16 bit numbers.
+ number |= number >> 16; // Take care of 32 bit numbers.
+ number++;
+ return static_cast<size_t>(number);
+}
+
+// Returns the factorial (!) of x. If x < 0, it returns 0.
+inline float Factorial(int x) {
+ if (x < 0) return 0.0f;
+ float result = 1.0f;
+ for (; x > 0; --x) result *= static_cast<float>(x);
+ return result;
+}
+
+// Returns the double factorial (!!) of x.
+// For odd x: 1 * 3 * 5 * ... * (x - 2) * x
+// For even x: 2 * 4 * 6 * ... * (x - 2) * x
+// If x < 0, it returns 0.
+inline float DoubleFactorial(int x) {
+ if (x < 0) return 0.0f;
+ float result = 1.0f;
+ for (; x > 0; x -= 2) result *= static_cast<float>(x);
+ return result;
+}
+
+// This is a *safe* alternative to std::equal function as a workaround in order
+// to avoid MSVC compiler warning C4996 for unchecked iterators (see
+// https://msdn.microsoft.com/en-us/library/aa985965.aspx).
+// Also note that, an STL equivalent of this function was introduced in C++14 to
+// be replaced with this implementation (see version (5) in
+// http://en.cppreference.com/w/cpp/algorithm/equal).
+template <typename Iterator>
+inline bool EqualSafe(const Iterator& lhs_begin, const Iterator& lhs_end,
+ const Iterator& rhs_begin, const Iterator& rhs_end) {
+ auto lhs_itr = lhs_begin;
+ auto rhs_itr = rhs_begin;
+ while (lhs_itr != lhs_end && rhs_itr != rhs_end) {
+ if (*lhs_itr != *rhs_itr) {
+ return false;
+ }
+ ++lhs_itr;
+ ++rhs_itr;
+ }
+ return lhs_itr == lhs_end && rhs_itr == rhs_end;
+}
+
+// Fast reciprocal of square-root. See: https://goo.gl/fqvstz for details.
+//
+// @param input The number to be inverse rooted.
+// @return An approximation of the reciprocal square root of |input|.
+inline float FastReciprocalSqrt(float input) {
+ const float kThreeHalfs = 1.5f;
+ const uint32_t kMagicNumber = 0x5f3759df;
+
+ // Approximate a logarithm by aliasing to an integer.
+ uint32_t integer;
+ memcpy(&integer, &input, sizeof(float));
+ integer = kMagicNumber - (integer >> 1);
+ float approximation;
+ memcpy(&approximation, &integer, sizeof(float));
+ const float half_input = input * 0.5f;
+ // One iteration of Newton's method.
+ return approximation *
+ (kThreeHalfs - (half_input * approximation * approximation));
+}
+
+// Finds the best-fitting line to a given set of 2D points by minimizing the
+// sum of the squares of the vertical (along y-axis) offsets. The slope and
+// intercept of the fitted line are recorded, as well as the coefficient of
+// determination, which gives the quality of the fitting.
+// See http://mathworld.wolfram.com/LeastSquaresFitting.html for how to compute
+// these values.
+//
+// @param x_array Array of the x coordinates of the points.
+// @param y_array Array of the y coordinates of the points.
+// @param slope Output slope of the fitted line.
+// @param intercept Output slope of the fitted line.
+// @param r_squared Coefficient of determination.
+// @return False if the fitting fails.
+bool LinearLeastSquareFitting(const std::vector<float>& x_array,
+ const std::vector<float>& y_array, float* slope,
+ float* intercept, float* r_squared);
+
+// Computes |base|^|exp|, where |exp| is a *non-negative* integer, with the
+// squared exponentiation (a.k.a double-and-add) method.
+// When T is a floating point type, this has the same semantics as pow(), but
+// is much faster.
+// T can also be any integral type, in which case computations will be
+// performed in the value domain of this integral type, and overflow semantics
+// will be those of T.
+// You can also use any type for which operator*= is defined.
+// See :
+
+// This method is reproduced here so vraudio classes don't need to depend on
+// //util/math/mathutil.h
+//
+// @tparam base Input to the exponent function. Any type for which *= is
+// defined.
+// @param exp Integer exponent, must be greater than or equal to zero.
+// @return |base|^|exp|.
+template <typename T>
+static inline T IntegerPow(T base, int exp) {
+ DCHECK_GE(exp, 0);
+ T result = static_cast<T>(1);
+ while (true) {
+ if (exp & 1) {
+ result *= base;
+ }
+ exp >>= 1;
+ if (!exp) break;
+ base *= base;
+ }
+ return result;
+}
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_BASE_MISC_MATH_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/misc_math_test.cc b/src/3rdparty/resonance-audio/resonance_audio/base/misc_math_test.cc
new file mode 100644
index 000000000..e75c100c6
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/misc_math_test.cc
@@ -0,0 +1,373 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "base/misc_math.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+TEST(MiscMath, WorldPositionEqualityTest) {
+ const WorldPosition kOriginalWorldPosition(0.33f, 0.44f, 0.55f);
+ const WorldPosition kSameWorldPosition = kOriginalWorldPosition;
+ EXPECT_FALSE(kOriginalWorldPosition != kSameWorldPosition);
+}
+
+TEST(MiscMath, WorldPositionInequalityTest) {
+ const WorldPosition kOriginalWorldPosition(0.11f, 0.22f, 0.33f);
+ const std::vector<WorldPosition> kDifferentWorldPositions{
+ {-0.22f, 0.22f, 0.33f}, {0.11f, -0.33f, 0.33f}, {0.11f, 0.22f, -0.22f},
+ {0.11f, 0.33f, -0.44f}, {0.22f, 0.22f, -0.44f}, {0.22f, 0.33f, -0.55f}};
+
+ for (auto& position : kDifferentWorldPositions) {
+ EXPECT_TRUE(kOriginalWorldPosition != position);
+ }
+}
+
+TEST(MiscMath, ConvertAudioFromWorldPositionTest) {
+ static const WorldPosition kWorldPosition(0.5f, -1.2f, 10.f);
+ static const AudioPosition kExpectedAudioPosition(
+ -kWorldPosition[2], -kWorldPosition[0], kWorldPosition[1]);
+ AudioPosition test_position;
+ ConvertAudioFromWorldPosition(kWorldPosition, &test_position);
+
+ EXPECT_TRUE(kExpectedAudioPosition.isApprox(test_position, kEpsilonFloat));
+}
+
+TEST(MiscMath, ConvertWorldFromAudioPositionTest) {
+ static const AudioPosition kAudioPosition(1.0f, 2.0f, -0.2f);
+ static const WorldPosition kExpectedWorldPosition(
+ -kAudioPosition[1], kAudioPosition[2], -kAudioPosition[0]);
+
+ WorldPosition test_position;
+ ConvertWorldFromAudioPosition(kAudioPosition, &test_position);
+
+ EXPECT_TRUE(kExpectedWorldPosition.isApprox(test_position, kEpsilonFloat));
+}
+
+TEST(MiscMath, ConvertAudioFromWorldRotationTest) {
+ static const WorldRotation kWorldRotation(1.0f, 0.5f, -1.2f, 10.f);
+ static const AudioRotation kExpectedAudioRotation(
+ kWorldRotation.w(), -kWorldRotation.x(), kWorldRotation.y(),
+ -kWorldRotation.z());
+ AudioRotation test_rotation;
+ ConvertAudioFromWorldRotation(kWorldRotation, &test_rotation);
+
+ EXPECT_TRUE(kExpectedAudioRotation.isApprox(test_rotation, kEpsilonFloat));
+}
+
+TEST(MiscMath, GetRelativeDirectionTest) {
+ static const WorldPosition kFromPosition(0.0f, 0.0f, 0.0f);
+ static const WorldPosition kFromRotationAxis(0.0f, 0.0f, 1.0f);
+ static const float kFromRotationAngle = static_cast<float>(M_PI / 2.0);
+ WorldRotation kFromRotation =
+ WorldRotation(AngleAxisf(kFromRotationAngle, kFromRotationAxis));
+
+ static const WorldPosition kToPosition(1.0f, 2.0f, 3.0f);
+
+ static const WorldPosition kExpectedRelativeDirection(2.0f, -1.0f, 3.0f);
+ WorldPosition test_relative_direction;
+ GetRelativeDirection(kFromPosition, kFromRotation, kToPosition,
+ &test_relative_direction);
+
+ EXPECT_TRUE(kExpectedRelativeDirection.isApprox(test_relative_direction,
+ kEpsilonFloat));
+}
+
+TEST(MiscMath, GetClosestPositionInAabbInsideTest) {
+ static const WorldPosition kRelativeSourcePosition(0.0f, -0.2f, 0.0f);
+ static const WorldPosition kRoomDimensions(1.0f, 1.0f, 1.0f);
+ static const WorldPosition kExpectedAabbPosition = kRelativeSourcePosition;
+ WorldPosition test_position;
+ GetClosestPositionInAabb(kRelativeSourcePosition, kRoomDimensions,
+ &test_position);
+
+ EXPECT_TRUE(kExpectedAabbPosition.isApprox(test_position, kEpsilonFloat));
+}
+
+TEST(MiscMath, GetClosestPositionInAabbOutsideTest) {
+ static const WorldPosition kRelativeSourcePosition(0.2f, 0.7f, -0.5f);
+ static const WorldPosition kRoomDimensions(1.0f, 1.0f, 1.0f);
+ static const WorldPosition kExpectedAabbPosition(0.2f, 0.5f, -0.5f);
+ WorldPosition test_position;
+ GetClosestPositionInAabb(kRelativeSourcePosition, kRoomDimensions,
+ &test_position);
+
+ EXPECT_TRUE(kExpectedAabbPosition.isApprox(test_position, kEpsilonFloat));
+}
+
+TEST(MiscMath, IsPositionInAabbInsideTest) {
+ static const WorldPosition kSourcePosition(0.5f, 0.3f, 0.2f);
+ static const WorldPosition kRoomPosition(0.5f, 0.5f, 0.5f);
+ static const WorldPosition kRoomDimensions(1.0f, 1.0f, 1.0f);
+
+ EXPECT_TRUE(
+ IsPositionInAabb(kSourcePosition, kRoomPosition, kRoomDimensions));
+}
+
+TEST(MiscMath, IsPositionInAabbOutsideTest) {
+ static const WorldPosition kSourcePosition(0.7f, 1.2f, 0.0f);
+ static const WorldPosition kRoomPosition(0.5f, 0.5f, 0.5f);
+ static const WorldPosition kRoomDimensions(1.0f, 1.0f, 1.0f);
+
+ EXPECT_FALSE(
+ IsPositionInAabb(kSourcePosition, kRoomPosition, kRoomDimensions));
+}
+
+TEST(MiscMath, IntegerMultiplicationOverflowDetection) {
+ static const size_t kMaxValue = std::numeric_limits<size_t>::max();
+ static const size_t kHalfMaxValue = kMaxValue / 2;
+
+ // 2 * 3 == 6 should not lead to an integer overflow.
+ EXPECT_FALSE(DoesIntegerMultiplicationOverflow<size_t>(2, 3, 6));
+
+ EXPECT_FALSE(DoesIntegerMultiplicationOverflow<size_t>(kHalfMaxValue, 2,
+ kHalfMaxValue * 2));
+ EXPECT_TRUE(
+ DoesIntegerMultiplicationOverflow<size_t>(kMaxValue, 2, kMaxValue << 1));
+ EXPECT_FALSE(
+ DoesIntegerMultiplicationOverflow<size_t>(0, kMaxValue, 0 * kMaxValue));
+ EXPECT_FALSE(
+ DoesIntegerMultiplicationOverflow<size_t>(kMaxValue, 0, kMaxValue * 0));
+}
+
+TEST(MiscMath, DoesIntegerAdditionOverflow) {
+ static const size_t kMaxValue = std::numeric_limits<size_t>::max();
+ static const size_t kHalfMaxValue = kMaxValue / 2;
+
+ EXPECT_FALSE(
+ DoesIntegerAdditionOverflow<size_t>(kHalfMaxValue, kHalfMaxValue));
+ EXPECT_TRUE(DoesIntegerAdditionOverflow<size_t>(kMaxValue, kHalfMaxValue));
+ EXPECT_TRUE(DoesIntegerAdditionOverflow<size_t>(1, kMaxValue));
+ EXPECT_FALSE(DoesIntegerAdditionOverflow<size_t>(kMaxValue, 0));
+ EXPECT_FALSE(DoesIntegerAdditionOverflow<size_t>(0, kMaxValue));
+}
+
+TEST(MiscMath, DoesIntSafelyConvertToSizeT) {
+ static const int kMaxIntValue = std::numeric_limits<int>::max();
+ size_t test_size_t;
+ EXPECT_TRUE(DoesIntSafelyConvertToSizeT(kMaxIntValue, &test_size_t));
+ EXPECT_EQ(static_cast<size_t>(kMaxIntValue), test_size_t);
+ EXPECT_TRUE(DoesIntSafelyConvertToSizeT(0, &test_size_t));
+ EXPECT_EQ(0U, test_size_t);
+ EXPECT_FALSE(DoesIntSafelyConvertToSizeT(-1, &test_size_t));
+}
+
+TEST(MiscMath, DoesSizeTSafelyConvertToInt) {
+ static const size_t kMaxIntValue = std::numeric_limits<size_t>::max();
+ int test_int;
+
+ EXPECT_FALSE(DoesSizeTSafelyConvertToInt(kMaxIntValue, &test_int));
+ EXPECT_TRUE(
+ DoesSizeTSafelyConvertToInt(std::numeric_limits<int>::max(), &test_int));
+ EXPECT_EQ(std::numeric_limits<int>::max(), test_int);
+ EXPECT_TRUE(DoesSizeTSafelyConvertToInt(0, &test_int));
+ EXPECT_EQ(0, test_int);
+}
+
+TEST(MiscMath, GreatestCommonDivisorTest) {
+ const std::vector<int> a_values = {2, 10, 3, 5, 48000, 7, -2, 2, -3};
+ const std::vector<int> b_values = {8, 4, 1, 10, 24000, 13, 6, -6, -9};
+ const std::vector<int> expected = {2, 2, 1, 5, 24000, 1, 2, 2, 3};
+
+ for (size_t i = 0; i < expected.size(); ++i) {
+ EXPECT_EQ(expected[i], FindGcd(a_values[i], b_values[i]));
+ }
+}
+
+TEST(MiscMath, NextPowTwoTest) {
+ const std::vector<size_t> inputs = {2, 10, 3, 5, 48000, 7, 23, 32};
+ const std::vector<size_t> expected = {2, 16, 4, 8, 65536, 8, 32, 32};
+
+ for (size_t i = 0; i < inputs.size(); ++i) {
+ EXPECT_EQ(expected[i], NextPowTwo(inputs[i]));
+ }
+}
+
+TEST(MiscMath, EqualSafeEqualArraysTest) {
+ const float kOriginalArray[3] = {0.11f, 0.22f, 0.33f};
+ const float kSameArray[3] = {0.11f, 0.22f, 0.33f};
+
+ EXPECT_TRUE(EqualSafe(std::begin(kOriginalArray), std::end(kOriginalArray),
+ std::begin(kSameArray), std::end(kSameArray)));
+}
+
+TEST(MiscMath, EqualSafeUnequalArraysTest) {
+ const std::vector<float> kOriginalArray{0.11f, 0.22f, 0.33f};
+ const std::vector<std::vector<float>> kDifferentArrays{
+ {-0.22f, 0.22f, 0.33f}, {0.11f, -0.33f, 0.33f}, {0.11f, 0.22f, -0.22f},
+ {0.11f, 0.33f, -0.44f}, {0.22f, 0.22f, -0.44f}, {0.22f, 0.33f, -0.55f}};
+
+ for (auto& array : kDifferentArrays) {
+ EXPECT_FALSE(EqualSafe(std::begin(kOriginalArray), std::end(kOriginalArray),
+ std::begin(array), std::end(array)));
+ }
+}
+
+TEST(MiscMath, FastReciprocalSqrtTest) {
+ const std::vector<float> kNumbers{130.0f, 13.0f, 1.3f,
+ 0.13f, 0.013f, 0.0013f};
+ const float kSqrtEpsilon = 2e-3f;
+ for (auto& number : kNumbers) {
+ const float actual = std::sqrt(number);
+ const float approximate = 1.0f / FastReciprocalSqrt(number);
+ EXPECT_LT(std::abs(actual - approximate) / actual, kSqrtEpsilon);
+ }
+}
+
+TEST(MiscMath, LinearFittingArrayDifferentSizesFails) {
+ const std::vector<float> x_array{1.0f, 2.0f};
+ const std::vector<float> y_array{3.0f, 4.0f, 5.0f};
+ float slope = 0.0f;
+ float intercept = 0.0f;
+ float r_squared = 0.0f;
+ EXPECT_FALSE(LinearLeastSquareFitting(x_array, y_array, &slope, &intercept,
+ &r_squared));
+}
+
+TEST(MiscMath, LinearFittingFewerThanTwoPointsFails) {
+ const std::vector<float> x_array{1.0f};
+ const std::vector<float> y_array{2.0f};
+ float slope = 0.0f;
+ float intercept = 0.0f;
+ float r_squared = 0.0f;
+ EXPECT_FALSE(LinearLeastSquareFitting(x_array, y_array, &slope, &intercept,
+ &r_squared));
+}
+
+TEST(MiscMath, LinearFittingVerticalLineFails) {
+ // All points line up on the y-axis.
+ const std::vector<float> x_array{0.0f, 0.0f, 0.0f};
+ const std::vector<float> y_array{1.0f, 2.0f, 3.0f};
+ float slope = 0.0f;
+ float intercept = 0.0f;
+ float r_squared = 0.0f;
+ EXPECT_FALSE(LinearLeastSquareFitting(x_array, y_array, &slope, &intercept,
+ &r_squared));
+}
+
+TEST(MiscMath, LinearFittingHorizontalLine) {
+ // All points line up on the x-axis.
+ const std::vector<float> x_array{1.0f, 2.0f, 3.0f};
+ const std::vector<float> y_array{0.0f, 0.0f, 0.0f};
+ float slope = 0.0f;
+ float intercept = 0.0f;
+ float r_squared = 0.0f;
+ EXPECT_TRUE(LinearLeastSquareFitting(x_array, y_array, &slope, &intercept,
+ &r_squared));
+ EXPECT_FLOAT_EQ(slope, 0.0f);
+ EXPECT_FLOAT_EQ(intercept, 0.0f);
+ EXPECT_FLOAT_EQ(r_squared, 1.0f);
+}
+
+TEST(MiscMath, LinearFittingSlopedLine) {
+ // All points line up on the line y = 2.0 x + 1.0.
+ const std::vector<float> x_array{1.0f, 2.0f, 3.0f, 4.0f};
+ const std::vector<float> y_array{3.0f, 5.0f, 7.0f, 9.0f};
+ float slope = 0.0f;
+ float intercept = 0.0f;
+ float r_squared = 0.0f;
+ EXPECT_TRUE(LinearLeastSquareFitting(x_array, y_array, &slope, &intercept,
+ &r_squared));
+ EXPECT_FLOAT_EQ(slope, 2.0f);
+ EXPECT_FLOAT_EQ(intercept, 1.0f);
+ EXPECT_FLOAT_EQ(r_squared, 1.0f);
+}
+
+TEST(MiscMath, LinearFittingSlopedLineWithError) {
+ // All points lie close to the line y = 2.0 x + 1.0 with some offsets.
+ const std::vector<float> x_array{1.002f, 2.001f, 2.998f, 4.003f};
+ const std::vector<float> y_array{3.001f, 4.998f, 7.005f, 8.996f};
+ float slope = 0.0f;
+ float intercept = 0.0f;
+ float r_squared = 0.0f;
+ EXPECT_TRUE(LinearLeastSquareFitting(x_array, y_array, &slope, &intercept,
+ &r_squared));
+
+ // Expect that the fitting is close to the line with some error.
+ const float error_tolerance = 1e-3f;
+ EXPECT_NEAR(slope, 2.0f, error_tolerance);
+ EXPECT_NEAR(intercept, 1.0f, error_tolerance);
+ EXPECT_NEAR(r_squared, 1.0f, error_tolerance);
+}
+
+TEST(MiscMath, LinearFittingUncorrelatedPoints) {
+ // All points evenly distributed on a circle y^2 + x^2 = 1.0, which gives
+ // the worst coefficient of determination (almost zero).
+ const size_t num_points = 20;
+ std::vector<float> x_array(num_points, 0.0f);
+ std::vector<float> y_array(num_points, 0.0f);
+ for (size_t i = 0; i < num_points; ++i) {
+ const float theta =
+ kTwoPi * static_cast<float>(i) / static_cast<float>(num_points);
+ x_array[i] = std::cos(theta);
+ y_array[i] = std::sin(theta);
+ }
+
+ float slope = 0.0f;
+ float intercept = 0.0f;
+ float r_squared = 0.0f;
+ EXPECT_TRUE(LinearLeastSquareFitting(x_array, y_array, &slope, &intercept,
+ &r_squared));
+ EXPECT_FLOAT_EQ(r_squared, 0.0f);
+}
+
+TEST(MiscMath, WorldRotation) {
+ // Test rotation around single quaternion axis.
+ const float kAngularRandomOffsetRad = 0.5f;
+ const float kAngularDifferenceRad = 0.3f;
+ Eigen::AngleAxisf rotation_a(kAngularRandomOffsetRad,
+ Eigen::Vector3f::UnitY());
+ Eigen::AngleAxisf rotation_b(kAngularRandomOffsetRad + kAngularDifferenceRad,
+ Eigen::Vector3f::UnitY());
+ EXPECT_FLOAT_EQ(WorldRotation(rotation_a).AngularDifferenceRad(rotation_b),
+ kAngularDifferenceRad);
+
+ // Test rotation between axis.
+ Eigen::AngleAxisf rotation_c(0.0f, Eigen::Vector3f::UnitY());
+ Eigen::AngleAxisf rotation_d(kPi, Eigen::Vector3f::UnitZ());
+ EXPECT_FLOAT_EQ(WorldRotation(rotation_c).AngularDifferenceRad(rotation_d),
+ kPi);
+}
+
+TEST(MiscMath, IntegerPow) {
+ const float kFloatValue = 1.5f;
+ const float kNegativeFloatValue = -3.3f;
+ const size_t kSizeTValue = 11U;
+ const int kIntValue = 5;
+ const int kNegativeIntValue = -13;
+
+ for (int exponent = 0; exponent < 5; ++exponent) {
+ EXPECT_FLOAT_EQ(IntegerPow(kFloatValue, exponent),
+ std::pow(kFloatValue, static_cast<float>(exponent)));
+ EXPECT_FLOAT_EQ(
+ IntegerPow(kNegativeFloatValue, exponent),
+ std::pow(kNegativeFloatValue, static_cast<float>(exponent)));
+ EXPECT_EQ(IntegerPow(kSizeTValue, exponent),
+ std::pow(kSizeTValue, exponent));
+ EXPECT_EQ(IntegerPow(kIntValue, exponent), std::pow(kIntValue, exponent));
+ EXPECT_EQ(IntegerPow(kNegativeIntValue, exponent),
+ std::pow(kNegativeIntValue, exponent));
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/object_transform.h b/src/3rdparty/resonance-audio/resonance_audio/base/object_transform.h
new file mode 100644
index 000000000..1d43e72a0
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/object_transform.h
@@ -0,0 +1,31 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_BASE_OBJECT_TRANSFORM_H_
+#define RESONANCE_AUDIO_BASE_OBJECT_TRANSFORM_H_
+
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+struct ObjectTransform {
+ WorldPosition position;
+ WorldRotation rotation;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_BASE_OBJECT_TRANSFORM_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/simd_macros.h b/src/3rdparty/resonance-audio/resonance_audio/base/simd_macros.h
new file mode 100644
index 000000000..11ae40bf4
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/simd_macros.h
@@ -0,0 +1,65 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_BASE_SIMD_MACROS_H_
+#define RESONANCE_AUDIO_BASE_SIMD_MACROS_H_
+
+#if !defined(DISABLE_SIMD) && (defined(__x86_64__) || defined(_M_X64) || \
+ defined(i386) || defined(_M_IX86))
+// SSE1 is enabled.
+#include <xmmintrin.h>
+typedef __m128 SimdVector;
+#define SIMD_SSE
+#define SIMD_LENGTH 4
+#define SIMD_MULTIPLY(a, b) _mm_mul_ps(a, b)
+#define SIMD_ADD(a, b) _mm_add_ps(a, b)
+#define SIMD_SUB(a, b) _mm_sub_ps(a, b)
+#define SIMD_MULTIPLY_ADD(a, b, c) _mm_add_ps(_mm_mul_ps(a, b), c)
+#define SIMD_SQRT(a) _mm_rcp_ps(_mm_rsqrt_ps(a))
+#define SIMD_RECIPROCAL_SQRT(a) _mm_rsqrt_ps(a)
+#define SIMD_LOAD_ONE_FLOAT(p) _mm_set1_ps(p)
+#elif !defined(DISABLE_SIMD) && \
+ (((defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM)) && defined(__ARM_NEON__)) || \
+ defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__))
+// ARM NEON is enabled.
+#include <arm_neon.h>
+typedef float32x4_t SimdVector;
+#define SIMD_NEON
+#define SIMD_LENGTH 4
+#define SIMD_MULTIPLY(a, b) vmulq_f32(a, b)
+#define SIMD_ADD(a, b) vaddq_f32(a, b)
+#define SIMD_SUB(a, b) vsubq_f32(a, b)
+#define SIMD_MULTIPLY_ADD(a, b, c) vmlaq_f32(c, a, b)
+#define SIMD_SQRT(a) vrecpeq_f32(vrsqrteq_f32(a))
+#define SIMD_RECIPROCAL_SQRT(a) vrsqrteq_f32(a)
+#define SIMD_LOAD_ONE_FLOAT(p) vld1q_dup_f32(&(p))
+#else
+// No SIMD optimizations enabled.
+#include "base/misc_math.h"
+typedef float SimdVector;
+#define SIMD_DISABLED
+#define SIMD_LENGTH 1
+#define SIMD_MULTIPLY(a, b) ((a) * (b))
+#define SIMD_ADD(a, b) ((a) + (b))
+#define SIMD_SUB(a, b) ((a) - (b))
+#define SIMD_MULTIPLY_ADD(a, b, c) ((a) * (b) + (c))
+#define SIMD_SQRT(a) (1.0f / FastReciprocalSqrt(a))
+#define SIMD_RECIPROCAL_SQRT(a) FastReciprocalSqrt(a)
+#define SIMD_LOAD_ONE_FLOAT(p) (p)
+#warning "Not using SIMD optimizations!"
+#endif
+
+#endif // RESONANCE_AUDIO_BASE_SIMD_MACROS_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/simd_utils.cc b/src/3rdparty/resonance-audio/resonance_audio/base/simd_utils.cc
new file mode 100644
index 000000000..309ca7ba8
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/simd_utils.cc
@@ -0,0 +1,1299 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "base/simd_utils.h"
+
+#include <algorithm>
+#include <limits>
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/misc_math.h"
+#include "base/simd_macros.h"
+
+
+namespace vraudio {
+
+namespace {
+
+#ifdef SIMD_NEON
+// Deinterleaving operates on 8 int16s at a time.
+const size_t kSixteenBitSimdLength = SIMD_LENGTH * 2;
+#endif // SIMD_NEON
+
+// Float format of max and min values storable in an int16_t, for clamping.
+const float kInt16Max = static_cast<float>(0x7FFF);
+const float kInt16Min = static_cast<float>(-0x7FFF);
+
+// Conversion factors between float and int16_t (both directions).
+const float kFloatFromInt16 = 1.0f / kInt16Max;
+const float kInt16FromFloat = kInt16Max;
+
+// Expected SIMD alignment in bytes.
+const size_t kSimdSizeBytes = 16;
+
+inline size_t GetNumChunks(size_t length) { return length / SIMD_LENGTH; }
+
+inline size_t GetLeftoverSamples(size_t length) { return length % SIMD_LENGTH; }
+
+template <typename T>
+inline bool IsAlignedTemplated(const T* pointer) {
+ return reinterpret_cast<uintptr_t>(pointer) % kSimdSizeBytes == 0;
+}
+
+#ifdef SIMD_DISABLED
+// Calculates the approximate complex magnude of z = real + i * imaginary.
+inline void ComplexMagnitude(float real, float imaginary, float* output) {
+ *output = real * real + imaginary * imaginary;
+ // The value of |output| is not being recalculated, simply modified.
+ *output = 1.0f / FastReciprocalSqrt(*output);
+}
+#endif // defined(SIMD_DISABLED)
+
+} // namespace
+
+bool IsAligned(const float* pointer) {
+ return IsAlignedTemplated<float>(pointer);
+}
+
+bool IsAligned(const int16_t* pointer) {
+ return IsAlignedTemplated<int16_t>(pointer);
+}
+
+size_t FindNextAlignedArrayIndex(size_t length, size_t type_size_bytes,
+ size_t memory_alignment_bytes) {
+ const size_t byte_length = type_size_bytes * length;
+ const size_t unaligned_bytes = byte_length % memory_alignment_bytes;
+ const size_t bytes_to_next_aligned =
+ (unaligned_bytes == 0) ? 0 : memory_alignment_bytes - unaligned_bytes;
+ return (byte_length + bytes_to_next_aligned) / type_size_bytes;
+}
+
+void AddPointwise(size_t length, const float* input_a, const float* input_b,
+ float* output) {
+ DCHECK(input_a);
+ DCHECK(input_b);
+ DCHECK(output);
+
+ const SimdVector* input_a_vector =
+ reinterpret_cast<const SimdVector*>(input_a);
+ const SimdVector* input_b_vector =
+ reinterpret_cast<const SimdVector*>(input_b);
+ SimdVector* output_vector = reinterpret_cast<SimdVector*>(output);
+#ifdef SIMD_SSE
+ const size_t num_chunks = GetNumChunks(length);
+ const bool inputs_aligned = IsAligned(input_a) && IsAligned(input_b);
+ const bool output_aligned = IsAligned(output);
+ if (inputs_aligned && output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ output_vector[i] = SIMD_ADD(input_a_vector[i], input_b_vector[i]);
+ }
+ } else if (inputs_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector output_temp =
+ SIMD_ADD(input_a_vector[i], input_b_vector[i]);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ } else if (output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_a_temp = _mm_load_ps(&input_a[i * SIMD_LENGTH]);
+ const SimdVector input_b_temp = _mm_load_ps(&input_b[i * SIMD_LENGTH]);
+ output_vector[i] = SIMD_ADD(input_a_temp, input_b_temp);
+ }
+ } else {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_a_temp = _mm_load_ps(&input_a[i * SIMD_LENGTH]);
+ const SimdVector input_b_temp = _mm_load_ps(&input_b[i * SIMD_LENGTH]);
+ const SimdVector output_temp = SIMD_ADD(input_a_temp, input_b_temp);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ }
+#else
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ output_vector[i] = SIMD_ADD(input_a_vector[i], input_b_vector[i]);
+ }
+#endif // SIMD_SSE
+
+ // Add samples at the end that were missed by the SIMD chunking.
+ const size_t leftover_samples = GetLeftoverSamples(length);
+ DCHECK_GE(length, leftover_samples);
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ output[i] = input_a[i] + input_b[i];
+ }
+}
+
+void SubtractPointwise(size_t length, const float* input_a,
+ const float* input_b, float* output) {
+ DCHECK(input_a);
+ DCHECK(input_b);
+ DCHECK(output);
+
+ const SimdVector* input_a_vector =
+ reinterpret_cast<const SimdVector*>(input_a);
+ const SimdVector* input_b_vector =
+ reinterpret_cast<const SimdVector*>(input_b);
+ SimdVector* output_vector = reinterpret_cast<SimdVector*>(output);
+
+#ifdef SIMD_SSE
+ const size_t num_chunks = GetNumChunks(length);
+ const bool inputs_aligned = IsAligned(input_a) && IsAligned(input_b);
+ const bool output_aligned = IsAligned(output);
+ if (inputs_aligned && output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ output_vector[i] = SIMD_SUB(input_b_vector[i], input_a_vector[i]);
+ }
+ } else if (inputs_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector output_temp =
+ SIMD_SUB(input_b_vector[i], input_a_vector[i]);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ } else if (output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_a_temp = _mm_load_ps(&input_a[i * SIMD_LENGTH]);
+ const SimdVector input_b_temp = _mm_load_ps(&input_b[i * SIMD_LENGTH]);
+ output_vector[i] = SIMD_SUB(input_b_temp, input_a_temp);
+ }
+ } else {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_a_temp = _mm_load_ps(&input_a[i * SIMD_LENGTH]);
+ const SimdVector input_b_temp = _mm_load_ps(&input_b[i * SIMD_LENGTH]);
+ const SimdVector output_temp = SIMD_SUB(input_b_temp, input_a_temp);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ }
+#else
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ output_vector[i] = SIMD_SUB(input_b_vector[i], input_a_vector[i]);
+ }
+#endif // SIMD_SSE
+
+ // Subtract samples at the end that were missed by the SIMD chunking.
+ const size_t leftover_samples = GetLeftoverSamples(length);
+ DCHECK_GE(length, leftover_samples);
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ output[i] = input_b[i] - input_a[i];
+ }
+}
+
+void MultiplyPointwise(size_t length, const float* input_a,
+ const float* input_b, float* output) {
+ DCHECK(input_a);
+ DCHECK(input_b);
+ DCHECK(output);
+
+ const SimdVector* input_a_vector =
+ reinterpret_cast<const SimdVector*>(input_a);
+ const SimdVector* input_b_vector =
+ reinterpret_cast<const SimdVector*>(input_b);
+ SimdVector* output_vector = reinterpret_cast<SimdVector*>(output);
+
+#ifdef SIMD_SSE
+ const size_t num_chunks = GetNumChunks(length);
+ const bool inputs_aligned = IsAligned(input_a) && IsAligned(input_b);
+ const bool output_aligned = IsAligned(output);
+ if (inputs_aligned && output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ output_vector[i] = SIMD_MULTIPLY(input_a_vector[i], input_b_vector[i]);
+ }
+ } else if (inputs_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector output_temp =
+ SIMD_MULTIPLY(input_a_vector[i], input_b_vector[i]);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ } else if (output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_a_temp = _mm_loadu_ps(&input_a[i * SIMD_LENGTH]);
+ const SimdVector input_b_temp = _mm_loadu_ps(&input_b[i * SIMD_LENGTH]);
+ output_vector[i] = SIMD_MULTIPLY(input_a_temp, input_b_temp);
+ }
+ } else {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_a_temp = _mm_loadu_ps(&input_a[i * SIMD_LENGTH]);
+ const SimdVector input_b_temp = _mm_loadu_ps(&input_b[i * SIMD_LENGTH]);
+ const SimdVector output_temp = SIMD_MULTIPLY(input_a_temp, input_b_temp);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ }
+#else
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ output_vector[i] = SIMD_MULTIPLY(input_a_vector[i], input_b_vector[i]);
+ }
+#endif // SIMD_SSE
+
+ // Multiply samples at the end that were missed by the SIMD chunking.
+ const size_t leftover_samples = GetLeftoverSamples(length);
+ DCHECK_GE(length, leftover_samples);
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ output[i] = input_a[i] * input_b[i];
+ }
+}
+
+void MultiplyAndAccumulatePointwise(size_t length, const float* input_a,
+ const float* input_b, float* accumulator) {
+ DCHECK(input_a);
+ DCHECK(input_b);
+ DCHECK(accumulator);
+
+ const SimdVector* input_a_vector =
+ reinterpret_cast<const SimdVector*>(input_a);
+ const SimdVector* input_b_vector =
+ reinterpret_cast<const SimdVector*>(input_b);
+ SimdVector* accumulator_vector = reinterpret_cast<SimdVector*>(accumulator);
+
+#ifdef SIMD_SSE
+ const size_t num_chunks = GetNumChunks(length);
+ const bool inputs_aligned = IsAligned(input_a) && IsAligned(input_b);
+ const bool accumulator_aligned = IsAligned(accumulator);
+ if (inputs_aligned && accumulator_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ accumulator_vector[i] = SIMD_MULTIPLY_ADD(
+ input_a_vector[i], input_b_vector[i], accumulator_vector[i]);
+ }
+ } else if (inputs_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ SimdVector accumulator_temp = _mm_loadu_ps(&accumulator[i * SIMD_LENGTH]);
+ accumulator_temp = SIMD_MULTIPLY_ADD(input_a_vector[i], input_b_vector[i],
+ accumulator_temp);
+ _mm_storeu_ps(&accumulator[i * SIMD_LENGTH], accumulator_temp);
+ }
+ } else if (accumulator_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_a_temp = _mm_loadu_ps(&input_a[i * SIMD_LENGTH]);
+ const SimdVector input_b_temp = _mm_loadu_ps(&input_b[i * SIMD_LENGTH]);
+ accumulator_vector[i] =
+ SIMD_MULTIPLY_ADD(input_a_temp, input_b_temp, accumulator_vector[i]);
+ }
+ } else {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_a_temp = _mm_loadu_ps(&input_a[i * SIMD_LENGTH]);
+ const SimdVector input_b_temp = _mm_loadu_ps(&input_b[i * SIMD_LENGTH]);
+ SimdVector accumulator_temp = _mm_loadu_ps(&accumulator[i * SIMD_LENGTH]);
+ accumulator_temp =
+ SIMD_MULTIPLY_ADD(input_a_temp, input_b_temp, accumulator_temp);
+ _mm_storeu_ps(&accumulator[i * SIMD_LENGTH], accumulator_temp);
+ }
+ }
+#else
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ accumulator_vector[i] = SIMD_MULTIPLY_ADD(
+ input_a_vector[i], input_b_vector[i], accumulator_vector[i]);
+ }
+#endif // SIMD_SSE
+
+ // Apply gain and accumulate to samples at the end that were missed by the
+ // SIMD chunking.
+ const size_t leftover_samples = GetLeftoverSamples(length);
+ DCHECK_GE(length, leftover_samples);
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ accumulator[i] += input_a[i] * input_b[i];
+ }
+}
+
+void ScalarMultiply(size_t length, float gain, const float* input,
+ float* output) {
+ DCHECK(input);
+ DCHECK(output);
+
+ const SimdVector* input_vector = reinterpret_cast<const SimdVector*>(input);
+ SimdVector* output_vector = reinterpret_cast<SimdVector*>(output);
+
+ const SimdVector gain_vector = SIMD_LOAD_ONE_FLOAT(gain);
+#ifdef SIMD_SSE
+ const size_t num_chunks = GetNumChunks(length);
+ const bool input_aligned = IsAligned(input);
+ const bool output_aligned = IsAligned(output);
+ if (input_aligned && output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ output_vector[i] = SIMD_MULTIPLY(gain_vector, input_vector[i]);
+ }
+ } else if (input_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector output_temp =
+ SIMD_MULTIPLY(gain_vector, input_vector[i]);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ } else if (output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_temp = _mm_loadu_ps(&input[i * SIMD_LENGTH]);
+ output_vector[i] = SIMD_MULTIPLY(gain_vector, input_temp);
+ }
+ } else {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_temp = _mm_loadu_ps(&input[i * SIMD_LENGTH]);
+ const SimdVector output_temp = SIMD_MULTIPLY(gain_vector, input_temp);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ }
+#else
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ output_vector[i] = SIMD_MULTIPLY(gain_vector, input_vector[i]);
+ }
+#endif // SIMD_SSE
+
+ // Apply gain to samples at the end that were missed by the SIMD chunking.
+ const size_t leftover_samples = GetLeftoverSamples(length);
+ DCHECK_GE(length, leftover_samples);
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ output[i] = input[i] * gain;
+ }
+}
+
+void ScalarMultiplyAndAccumulate(size_t length, float gain, const float* input,
+ float* accumulator) {
+ DCHECK(input);
+ DCHECK(accumulator);
+
+ const SimdVector* input_vector = reinterpret_cast<const SimdVector*>(input);
+ SimdVector* accumulator_vector = reinterpret_cast<SimdVector*>(accumulator);
+
+ const SimdVector gain_vector = SIMD_LOAD_ONE_FLOAT(gain);
+#ifdef SIMD_SSE
+ const size_t num_chunks = GetNumChunks(length);
+ const bool input_aligned = IsAligned(input);
+ const bool accumulator_aligned = IsAligned(accumulator);
+ if (input_aligned && accumulator_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ accumulator_vector[i] = SIMD_MULTIPLY_ADD(gain_vector, input_vector[i],
+ accumulator_vector[i]);
+ }
+ } else if (input_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ SimdVector accumulator_temp = _mm_loadu_ps(&accumulator[i * SIMD_LENGTH]);
+ accumulator_temp =
+ SIMD_MULTIPLY_ADD(gain_vector, input_vector[i], accumulator_temp);
+ _mm_storeu_ps(&accumulator[i * SIMD_LENGTH], accumulator_temp);
+ }
+ } else if (accumulator_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_temp = _mm_loadu_ps(&input[i * SIMD_LENGTH]);
+ accumulator_vector[i] =
+ SIMD_MULTIPLY_ADD(gain_vector, input_temp, accumulator_vector[i]);
+ }
+ } else {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_temp = _mm_loadu_ps(&input[i * SIMD_LENGTH]);
+ SimdVector accumulator_temp = _mm_loadu_ps(&accumulator[i * SIMD_LENGTH]);
+ accumulator_temp =
+ SIMD_MULTIPLY_ADD(gain_vector, input_temp, accumulator_temp);
+ _mm_storeu_ps(&accumulator[i * SIMD_LENGTH], accumulator_temp);
+ }
+ }
+#else
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ accumulator_vector[i] =
+ SIMD_MULTIPLY_ADD(gain_vector, input_vector[i], accumulator_vector[i]);
+ }
+#endif // SIMD_SSE
+
+ // Apply gain and accumulate to samples at the end that were missed by the
+ // SIMD chunking.
+ const size_t leftover_samples = GetLeftoverSamples(length);
+ DCHECK_GE(length, leftover_samples);
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ accumulator[i] += input[i] * gain;
+ }
+}
+
+void ReciprocalSqrt(size_t length, const float* input, float* output) {
+ DCHECK(input);
+ DCHECK(output);
+
+#if !defined(SIMD_DISABLED)
+ const SimdVector* input_vector = reinterpret_cast<const SimdVector*>(input);
+ SimdVector* output_vector = reinterpret_cast<SimdVector*>(output);
+#endif // !defined(SIMD_DISABLED)
+
+#ifdef SIMD_SSE
+ const size_t num_chunks = GetNumChunks(length);
+ const bool input_aligned = IsAligned(input);
+ const bool output_aligned = IsAligned(output);
+ if (input_aligned && output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ output_vector[i] = SIMD_RECIPROCAL_SQRT(input_vector[i]);
+ }
+ } else if (input_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector output_temp = SIMD_RECIPROCAL_SQRT(input_vector[i]);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ } else if (output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_temp = _mm_loadu_ps(&input[i * SIMD_LENGTH]);
+ output_vector[i] = SIMD_RECIPROCAL_SQRT(input_temp);
+ }
+ } else {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_temp = _mm_loadu_ps(&input[i * SIMD_LENGTH]);
+ const SimdVector output_temp = SIMD_RECIPROCAL_SQRT(input_temp);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ }
+#elif defined SIMD_NEON
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ output_vector[i] = SIMD_RECIPROCAL_SQRT(input_vector[i]);
+ }
+#endif // SIMD_SSE
+
+ // Apply to samples at the end that were missed by the SIMD chunking.
+ const size_t leftover_samples = GetLeftoverSamples(length);
+ DCHECK_GE(length, leftover_samples);
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ output[i] = FastReciprocalSqrt(input[i]);
+ }
+}
+
+void Sqrt(size_t length, const float* input, float* output) {
+ DCHECK(input);
+ DCHECK(output);
+
+#if !defined(SIMD_DISABLED)
+ const SimdVector* input_vector = reinterpret_cast<const SimdVector*>(input);
+ SimdVector* output_vector = reinterpret_cast<SimdVector*>(output);
+#endif // !defined(SIMD_DISABLED)
+
+#ifdef SIMD_SSE
+ const size_t num_chunks = GetNumChunks(length);
+ const bool input_aligned = IsAligned(input);
+ const bool output_aligned = IsAligned(output);
+ if (input_aligned && output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ output_vector[i] = SIMD_SQRT(input_vector[i]);
+ }
+ } else if (input_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector output_temp = SIMD_SQRT(input_vector[i]);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ } else if (output_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_temp = _mm_loadu_ps(&input[i * SIMD_LENGTH]);
+ output_vector[i] = SIMD_SQRT(input_temp);
+ }
+ } else {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector input_temp = _mm_loadu_ps(&input[i * SIMD_LENGTH]);
+ const SimdVector output_temp = SIMD_SQRT(input_temp);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], output_temp);
+ }
+ }
+#elif defined SIMD_NEON
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ // This should be faster than using a sqrt method : https://goo.gl/XRKwFp
+ output_vector[i] = SIMD_SQRT(input_vector[i]);
+ }
+#endif // SIMD_SSE
+
+ // Apply to samples at the end that were missed by the SIMD chunking.
+ const size_t leftover_samples = GetLeftoverSamples(length);
+ DCHECK_GE(length, leftover_samples);
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ output[i] = 1.0f / FastReciprocalSqrt(input[i]);
+ }
+}
+
+void ApproxComplexMagnitude(size_t length, const float* input, float* output) {
+ DCHECK(input);
+ DCHECK(output);
+
+#if !defined(SIMD_DISABLED)
+ const SimdVector* input_vector = reinterpret_cast<const SimdVector*>(input);
+ SimdVector* output_vector = reinterpret_cast<SimdVector*>(output);
+ const size_t num_chunks = GetNumChunks(length);
+ const bool input_aligned = IsAligned(input);
+ const bool output_aligned = IsAligned(output);
+#endif // !defined(SIMD_DISABLED)
+
+#ifdef SIMD_SSE
+ if (input_aligned && output_aligned) {
+ for (size_t out_index = 0; out_index < num_chunks; ++out_index) {
+ const size_t first_index = out_index * 2;
+ const size_t second_index = first_index + 1;
+ const SimdVector squared_1 =
+ SIMD_MULTIPLY(input_vector[first_index], input_vector[first_index]);
+ const SimdVector squared_2 =
+ SIMD_MULTIPLY(input_vector[second_index], input_vector[second_index]);
+ const SimdVector unshuffled_1 =
+ _mm_shuffle_ps(squared_1, squared_2, _MM_SHUFFLE(2, 0, 2, 0));
+ const SimdVector unshuffled_2 =
+ _mm_shuffle_ps(squared_1, squared_2, _MM_SHUFFLE(3, 1, 3, 1));
+ output_vector[out_index] = SIMD_ADD(unshuffled_1, unshuffled_2);
+ output_vector[out_index] = SIMD_SQRT(output_vector[out_index]);
+ }
+ } else if (input_aligned) {
+ for (size_t out_index = 0; out_index < num_chunks; ++out_index) {
+ const size_t first_index = out_index * 2;
+ const size_t second_index = first_index + 1;
+ const SimdVector squared_1 =
+ SIMD_MULTIPLY(input_vector[first_index], input_vector[first_index]);
+ const SimdVector squared_2 =
+ SIMD_MULTIPLY(input_vector[second_index], input_vector[second_index]);
+ const SimdVector unshuffled_1 =
+ _mm_shuffle_ps(squared_1, squared_2, _MM_SHUFFLE(2, 0, 2, 0));
+ const SimdVector unshuffled_2 =
+ _mm_shuffle_ps(squared_1, squared_2, _MM_SHUFFLE(3, 1, 3, 1));
+ SimdVector output_temp = SIMD_ADD(unshuffled_1, unshuffled_2);
+ output_vector[out_index] = SIMD_SQRT(output_temp);
+ _mm_storeu_ps(&output[out_index * SIMD_LENGTH], output_temp);
+ }
+ } else if (output_aligned) {
+ for (size_t out_index = 0; out_index < num_chunks; ++out_index) {
+ const size_t first_index = out_index * 2;
+ const size_t second_index = first_index + 1;
+ const SimdVector first_temp =
+ _mm_loadu_ps(&input[first_index * SIMD_LENGTH]);
+ const SimdVector second_temp =
+ _mm_loadu_ps(&input[second_index * SIMD_LENGTH]);
+ const SimdVector squared_1 = SIMD_MULTIPLY(first_temp, first_temp);
+ const SimdVector squared_2 = SIMD_MULTIPLY(second_temp, second_temp);
+ const SimdVector unshuffled_1 =
+ _mm_shuffle_ps(squared_1, squared_2, _MM_SHUFFLE(2, 0, 2, 0));
+ const SimdVector unshuffled_2 =
+ _mm_shuffle_ps(squared_1, squared_2, _MM_SHUFFLE(3, 1, 3, 1));
+ output_vector[out_index] = SIMD_ADD(unshuffled_1, unshuffled_2);
+ output_vector[out_index] = SIMD_SQRT(output_vector[out_index]);
+ }
+ } else {
+ for (size_t out_index = 0; out_index < num_chunks; ++out_index) {
+ const size_t first_index = out_index * 2;
+ const size_t second_index = first_index + 1;
+ const SimdVector first_temp =
+ _mm_loadu_ps(&input[first_index * SIMD_LENGTH]);
+ const SimdVector second_temp =
+ _mm_loadu_ps(&input[second_index * SIMD_LENGTH]);
+ const SimdVector squared_1 = SIMD_MULTIPLY(first_temp, first_temp);
+ const SimdVector squared_2 = SIMD_MULTIPLY(second_temp, second_temp);
+ const SimdVector unshuffled_1 =
+ _mm_shuffle_ps(squared_1, squared_2, _MM_SHUFFLE(2, 0, 2, 0));
+ const SimdVector unshuffled_2 =
+ _mm_shuffle_ps(squared_1, squared_2, _MM_SHUFFLE(3, 1, 3, 1));
+ SimdVector output_temp = SIMD_ADD(unshuffled_1, unshuffled_2);
+ output_temp = SIMD_SQRT(output_temp);
+ _mm_storeu_ps(&output[out_index * SIMD_LENGTH], output_temp);
+ }
+ }
+#elif defined SIMD_NEON
+ if (input_aligned && output_aligned) {
+ for (size_t out_index = 0; out_index < num_chunks; ++out_index) {
+ const size_t first_index = out_index * 2;
+ const size_t second_index = first_index + 1;
+ const SimdVector squared_1 =
+ SIMD_MULTIPLY(input_vector[first_index], input_vector[first_index]);
+ const SimdVector squared_2 =
+ SIMD_MULTIPLY(input_vector[second_index], input_vector[second_index]);
+ const float32x4x2_t unshuffled = vuzpq_f32(squared_1, squared_2);
+ output_vector[out_index] = SIMD_ADD(unshuffled.val[0], unshuffled.val[1]);
+ output_vector[out_index] = SIMD_SQRT(output_vector[out_index]);
+ }
+ } else if (input_aligned) {
+ for (size_t out_index = 0; out_index < num_chunks; ++out_index) {
+ const size_t first_index = out_index * 2;
+ const size_t second_index = first_index + 1;
+ const SimdVector squared_1 =
+ SIMD_MULTIPLY(input_vector[first_index], input_vector[first_index]);
+ const SimdVector squared_2 =
+ SIMD_MULTIPLY(input_vector[second_index], input_vector[second_index]);
+ const float32x4x2_t unshuffled = vuzpq_f32(squared_1, squared_2);
+ SimdVector output_temp = SIMD_ADD(unshuffled.val[0], unshuffled.val[1]);
+ output_temp = SIMD_SQRT(output_temp);
+ vst1q_f32(&output[out_index * SIMD_LENGTH], output_temp);
+ }
+ } else if (output_aligned) {
+ for (size_t out_index = 0; out_index < num_chunks; ++out_index) {
+ const size_t first_index = out_index * 2;
+ const size_t second_index = first_index + 1;
+ const SimdVector first_temp =
+ vld1q_f32(&input[first_index * SIMD_LENGTH]);
+ const SimdVector second_temp =
+ vld1q_f32(&input[second_index * SIMD_LENGTH]);
+ const SimdVector squared_1 = SIMD_MULTIPLY(first_temp, first_temp);
+ const SimdVector squared_2 = SIMD_MULTIPLY(second_temp, second_temp);
+ const float32x4x2_t unshuffled = vuzpq_f32(squared_1, squared_2);
+ output_vector[out_index] = SIMD_ADD(unshuffled.val[0], unshuffled.val[1]);
+ output_vector[out_index] = SIMD_SQRT(output_vector[out_index]);
+ }
+ } else {
+ for (size_t out_index = 0; out_index < num_chunks; ++out_index) {
+ const size_t first_index = out_index * 2;
+ const size_t second_index = first_index + 1;
+ const SimdVector first_temp =
+ vld1q_f32(&input[first_index * SIMD_LENGTH]);
+ const SimdVector second_temp =
+ vld1q_f32(&input[second_index * SIMD_LENGTH]);
+ const SimdVector squared_1 = SIMD_MULTIPLY(first_temp, first_temp);
+ const SimdVector squared_2 = SIMD_MULTIPLY(second_temp, second_temp);
+ const float32x4x2_t unshuffled = vuzpq_f32(squared_1, squared_2);
+ SimdVector output_temp = SIMD_ADD(unshuffled.val[0], unshuffled.val[1]);
+ output_temp = SIMD_SQRT(output_temp);
+ vst1q_f32(&output[out_index * SIMD_LENGTH], output_temp);
+ }
+ }
+#endif // SIMD_SSE
+
+ // Apply to samples at the end that were missed by the SIMD chunking.
+ const size_t leftover_samples = GetLeftoverSamples(length);
+ DCHECK_GE(length, leftover_samples);
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ const size_t real_index = i * 2;
+ const size_t imag_index = real_index + 1;
+ const float squared_sum = (input[real_index] * input[real_index]) +
+ (input[imag_index] * input[imag_index]);
+ output[i] = 1.0f / FastReciprocalSqrt(squared_sum);
+ }
+}
+
+void ComplexInterleavedFormatFromMagnitudeAndSinCosPhase(
+ size_t length, const float* magnitude, const float* cos_phase,
+ const float* sin_phase, float* complex_interleaved_format_output) {
+ size_t leftover_samples = 0;
+#ifdef SIMD_NEON
+ if (IsAligned(complex_interleaved_format_output) && IsAligned(cos_phase) &&
+ IsAligned(sin_phase) && IsAligned(magnitude)) {
+ const SimdVector* cos_vec = reinterpret_cast<const SimdVector*>(cos_phase);
+ const SimdVector* sin_vec = reinterpret_cast<const SimdVector*>(sin_phase);
+ const SimdVector* magnitude_vec =
+ reinterpret_cast<const SimdVector*>(magnitude);
+
+ const size_t num_chunks = GetNumChunks(length);
+ float32x4x2_t interleaved_pair;
+
+ SimdVector* interleaved_vec =
+ reinterpret_cast<SimdVector*>(complex_interleaved_format_output);
+ for (size_t i = 0, j = 0; j < num_chunks; ++i, j += 2) {
+ interleaved_pair = vzipq_f32(cos_vec[i], sin_vec[i]);
+ interleaved_vec[j] =
+ SIMD_MULTIPLY(interleaved_pair.val[0], magnitude_vec[i]);
+ interleaved_vec[j + 1] =
+ SIMD_MULTIPLY(interleaved_pair.val[1], magnitude_vec[i]);
+ }
+
+ leftover_samples = GetLeftoverSamples(length);
+ }
+#endif // SIMD_NEON
+ DCHECK_EQ(leftover_samples % 2U, 0U);
+ for (size_t i = leftover_samples, j = leftover_samples / 2; i < length;
+ i += 2, ++j) {
+ const size_t imaginary_offset = i + 1;
+ complex_interleaved_format_output[i] = magnitude[j] * cos_phase[j];
+ complex_interleaved_format_output[imaginary_offset] =
+ magnitude[j] * sin_phase[j];
+ }
+}
+
+void StereoFromMonoSimd(size_t length, const float* mono, float* left,
+ float* right) {
+ ScalarMultiply(length, kInverseSqrtTwo, mono, left);
+ std::copy_n(left, length, right);
+}
+
+void MonoFromStereoSimd(size_t length, const float* left, const float* right,
+ float* mono) {
+ DCHECK(left);
+ DCHECK(right);
+ DCHECK(mono);
+
+ const SimdVector* left_vector = reinterpret_cast<const SimdVector*>(left);
+ const SimdVector* right_vector = reinterpret_cast<const SimdVector*>(right);
+ SimdVector* mono_vector = reinterpret_cast<SimdVector*>(mono);
+
+ const SimdVector inv_root_two_vec = SIMD_LOAD_ONE_FLOAT(kInverseSqrtTwo);
+#ifdef SIMD_SSE
+ const size_t num_chunks = GetNumChunks(length);
+ const bool inputs_aligned = IsAligned(left) && IsAligned(right);
+ const bool mono_aligned = IsAligned(mono);
+ if (inputs_aligned && mono_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ mono_vector[i] = SIMD_MULTIPLY(inv_root_two_vec,
+ SIMD_ADD(left_vector[i], right_vector[i]));
+ }
+ } else if (inputs_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector mono_temp = SIMD_MULTIPLY(
+ inv_root_two_vec, SIMD_ADD(left_vector[i], right_vector[i]));
+ _mm_storeu_ps(&mono[i * SIMD_LENGTH], mono_temp);
+ }
+ } else if (mono_aligned) {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector left_temp = _mm_loadu_ps(&left[i * SIMD_LENGTH]);
+ const SimdVector right_temp = _mm_loadu_ps(&right[i * SIMD_LENGTH]);
+ mono_vector[i] =
+ SIMD_MULTIPLY(inv_root_two_vec, SIMD_ADD(left_temp, right_temp));
+ }
+ } else {
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const SimdVector left_temp = _mm_loadu_ps(&left[i * SIMD_LENGTH]);
+ const SimdVector right_temp = _mm_loadu_ps(&right[i * SIMD_LENGTH]);
+ const SimdVector mono_temp =
+ SIMD_MULTIPLY(inv_root_two_vec, SIMD_ADD(left_temp, right_temp));
+ _mm_storeu_ps(&mono[i * SIMD_LENGTH], mono_temp);
+ }
+ }
+#else
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ mono_vector[i] = SIMD_MULTIPLY(inv_root_two_vec,
+ SIMD_ADD(left_vector[i], right_vector[i]));
+ }
+#endif // SIMD_SSE
+ const size_t leftover_samples = GetLeftoverSamples(length);
+ // Downmix samples at the end that were missed by the SIMD chunking.
+ DCHECK_GE(length, leftover_samples);
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ mono[i] = kInverseSqrtTwo * (left[i] + right[i]);
+ }
+}
+
+#ifdef SIMD_NEON
+
+void Int16FromFloat(size_t length, const float* input, int16_t* output) {
+ DCHECK(input);
+ DCHECK(output);
+
+ // if (input_aligned || output_aligned) {
+ const SimdVector* input_vector = reinterpret_cast<const SimdVector*>(input);
+ int16x4_t* output_vector = reinterpret_cast<int16x4_t*>(output);
+
+ // A temporary 32 bit integer vector is needed as we only have intrinsics to
+ // convert from 32 bit floats to 32 bit ints. Then truncate to 16 bit ints.
+ int32x4_t temporary_wide_vector;
+ SimdVector temporary_float_vector;
+
+ const SimdVector scaling_vector = SIMD_LOAD_ONE_FLOAT(kInt16FromFloat);
+
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ temporary_float_vector = SIMD_MULTIPLY(scaling_vector, input_vector[i]);
+ temporary_wide_vector = vcvtq_s32_f32(temporary_float_vector);
+ output_vector[i] = vqmovn_s32(temporary_wide_vector);
+ }
+
+ // The remainder.
+ const size_t leftover_samples = GetLeftoverSamples(length);
+ DCHECK_GE(length, leftover_samples);
+ float temp_float;
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ temp_float = input[i] * kInt16FromFloat;
+ temp_float = std::min(kInt16Max, std::max(kInt16Min, temp_float));
+ output[i] = static_cast<int16_t>(temp_float);
+ }
+}
+
+void FloatFromInt16(size_t length, const int16_t* input, float* output) {
+ DCHECK(input);
+ DCHECK(output);
+
+ size_t leftover_samples = length;
+ const bool input_aligned = IsAligned(input);
+ const bool output_aligned = IsAligned(output);
+ if (input_aligned || output_aligned) {
+ const int16x4_t* input_vector = reinterpret_cast<const int16x4_t*>(input);
+ SimdVector* output_vector = reinterpret_cast<SimdVector*>(output);
+
+ int16x4_t temporary_narrow_vector;
+ SimdVector temporary_float_vector;
+ int32x4_t temporary_wide_vector;
+ const SimdVector scaling_vector = SIMD_LOAD_ONE_FLOAT(kFloatFromInt16);
+
+ if (input_aligned && output_aligned) {
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ temporary_wide_vector = vmovl_s16(input_vector[i]);
+ output_vector[i] = vcvtq_f32_s32(temporary_wide_vector);
+ output_vector[i] = SIMD_MULTIPLY(scaling_vector, output_vector[i]);
+ }
+ } else if (input_aligned) {
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ temporary_wide_vector = vmovl_s16(input_vector[i]);
+ temporary_float_vector = vcvtq_f32_s32(temporary_wide_vector);
+ temporary_float_vector =
+ SIMD_MULTIPLY(scaling_vector, temporary_float_vector);
+ vst1q_f32(&output[i * SIMD_LENGTH], temporary_float_vector);
+ }
+ } else {
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ temporary_narrow_vector = vld1_s16(&input[i * SIMD_LENGTH]);
+ temporary_wide_vector = vmovl_s16(temporary_narrow_vector);
+ output_vector[i] = vcvtq_f32_s32(temporary_wide_vector);
+ output_vector[i] = SIMD_MULTIPLY(scaling_vector, output_vector[i]);
+ }
+ }
+ leftover_samples = GetLeftoverSamples(length);
+ }
+
+ // The remainder.
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ output[i] = static_cast<float>(input[i]) * kFloatFromInt16;
+ }
+}
+
+#elif (defined SIMD_SSE && !defined(_MSC_VER))
+
+void Int16FromFloat(size_t length, const float* input, int16_t* output) {
+ DCHECK(input);
+ DCHECK(output);
+
+ size_t leftover_samples = length;
+ const bool input_aligned = IsAligned(input);
+ const bool output_aligned = IsAligned(output);
+ if (output_aligned) {
+ const SimdVector* input_vector = reinterpret_cast<const SimdVector*>(input);
+ __m64* output_vector = reinterpret_cast<__m64*>(output);
+
+ const SimdVector scaling_vector = SIMD_LOAD_ONE_FLOAT(kInt16FromFloat);
+ const SimdVector min_vector = SIMD_LOAD_ONE_FLOAT(kInt16Min);
+ const SimdVector max_vector = SIMD_LOAD_ONE_FLOAT(kInt16Max);
+
+ SimdVector temporary_float_vector;
+
+ if (input_aligned) {
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ temporary_float_vector = SIMD_MULTIPLY(scaling_vector, input_vector[i]);
+ temporary_float_vector = _mm_max_ps(temporary_float_vector, min_vector);
+ temporary_float_vector = _mm_min_ps(temporary_float_vector, max_vector);
+ output_vector[i] = _mm_cvtps_pi16(temporary_float_vector);
+ }
+ } else {
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ temporary_float_vector = _mm_loadu_ps(&input[i * SIMD_LENGTH]);
+ temporary_float_vector =
+ SIMD_MULTIPLY(scaling_vector, temporary_float_vector);
+ temporary_float_vector = _mm_max_ps(temporary_float_vector, min_vector);
+ temporary_float_vector = _mm_min_ps(temporary_float_vector, max_vector);
+ output_vector[i] = _mm_cvtps_pi16(temporary_float_vector);
+ }
+ }
+ // There is no easy way to simply store the 16 bit ints so we dont have an
+ // |input_aligned| only case.
+ leftover_samples = GetLeftoverSamples(length);
+ }
+
+ // The remainder.
+ float temp_float;
+ for (size_t i = length - GetLeftoverSamples(length); i < length; ++i) {
+ temp_float = input[i] * kInt16FromFloat;
+ temp_float = std::min(kInt16Max, std::max(kInt16Min, temp_float));
+ output[i] = static_cast<int16_t>(temp_float);
+ }
+}
+
+void FloatFromInt16(size_t length, const int16_t* input, float* output) {
+ DCHECK(input);
+ DCHECK(output);
+
+ size_t leftover_samples = length;
+ const bool input_aligned = IsAligned(input);
+ const bool output_aligned = IsAligned(output);
+ if (input_aligned) {
+ SimdVector* output_vector = reinterpret_cast<SimdVector*>(output);
+ const __m64* input_vector = reinterpret_cast<const __m64*>(input);
+
+ const SimdVector scaling_vector = SIMD_LOAD_ONE_FLOAT(kFloatFromInt16);
+
+ if (output_aligned) {
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ output_vector[i] = _mm_cvtpi16_ps(input_vector[i]);
+ output_vector[i] = SIMD_MULTIPLY(scaling_vector, output_vector[i]);
+ }
+ } else {
+ SimdVector temporary_float_vector;
+ for (size_t i = 0; i < GetNumChunks(length); ++i) {
+ temporary_float_vector = _mm_cvtpi16_ps(input_vector[i]);
+ temporary_float_vector =
+ SIMD_MULTIPLY(scaling_vector, temporary_float_vector);
+ _mm_storeu_ps(&output[i * SIMD_LENGTH], temporary_float_vector);
+ }
+ }
+ // There is no easy way to simply load the 16 bit ints so we dont have an
+ // |output_aligned| only case.
+ leftover_samples = GetLeftoverSamples(length);
+ }
+
+ // The remainder.
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ output[i] = static_cast<float>(input[i]) * kFloatFromInt16;
+ }
+}
+
+#else // SIMD disabled or Windows build.
+
+void Int16FromFloat(size_t length, const float* input, int16_t* output) {
+ DCHECK(input);
+ DCHECK(output);
+
+ float temp_float;
+ for (size_t i = 0; i < length; ++i) {
+ temp_float = input[i] * kInt16FromFloat;
+ temp_float = std::min(kInt16Max, std::max(kInt16Min, temp_float));
+ output[i] = static_cast<int16_t>(temp_float);
+ }
+}
+
+void FloatFromInt16(size_t length, const int16_t* input, float* output) {
+ DCHECK(input);
+ DCHECK(output);
+
+ for (size_t i = 0; i < length; ++i) {
+ output[i] = static_cast<float>(input[i]) * kFloatFromInt16;
+ }
+}
+
+#endif // SIMD_NEON
+
+void InterleaveStereo(size_t length, const int16_t* channel_0,
+ const int16_t* channel_1, int16_t* interleaved_buffer) {
+ DCHECK(interleaved_buffer);
+ DCHECK(channel_0);
+ DCHECK(channel_1);
+
+ size_t leftover_samples = length;
+#ifdef SIMD_NEON
+ if (IsAligned(interleaved_buffer) && IsAligned(channel_0) &&
+ IsAligned(channel_1)) {
+ const int16x8_t* channel_0_vec =
+ reinterpret_cast<const int16x8_t*>(channel_0);
+ const int16x8_t* channel_1_vec =
+ reinterpret_cast<const int16x8_t*>(channel_1);
+
+ const size_t num_chunks = length / kSixteenBitSimdLength;
+ int16x8x2_t interleaved_pair;
+
+ int16x8_t* interleaved_vec =
+ reinterpret_cast<int16x8_t*>(interleaved_buffer);
+ for (size_t i = 0, j = 0; i < num_chunks; ++i, j += 2) {
+ interleaved_pair = vzipq_s16(channel_0_vec[i], channel_1_vec[i]);
+ interleaved_vec[j] = interleaved_pair.val[0];
+ interleaved_vec[j + 1] = interleaved_pair.val[1];
+ }
+
+ leftover_samples = length % kSixteenBitSimdLength;
+ }
+#endif // SIMD_NEON
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ const size_t interleaved_index = kNumStereoChannels * i;
+ interleaved_buffer[interleaved_index] = channel_0[i];
+ interleaved_buffer[interleaved_index + 1] = channel_1[i];
+ }
+}
+
+void InterleaveStereo(size_t length, const float* channel_0,
+ const float* channel_1, float* interleaved_buffer) {
+ DCHECK(interleaved_buffer);
+ DCHECK(channel_0);
+ DCHECK(channel_1);
+
+ size_t leftover_samples = length;
+#ifdef SIMD_NEON
+ if (IsAligned(interleaved_buffer) && IsAligned(channel_0) &&
+ IsAligned(channel_1)) {
+ const SimdVector* channel_0_vec =
+ reinterpret_cast<const SimdVector*>(channel_0);
+ const SimdVector* channel_1_vec =
+ reinterpret_cast<const SimdVector*>(channel_1);
+
+ const size_t num_chunks = GetNumChunks(length);
+ float32x4x2_t interleaved_pair;
+
+ SimdVector* interleaved_vec =
+ reinterpret_cast<SimdVector*>(interleaved_buffer);
+ for (size_t i = 0, j = 0; i < num_chunks; ++i, j += 2) {
+ interleaved_pair = vzipq_f32(channel_0_vec[i], channel_1_vec[i]);
+ interleaved_vec[j] = interleaved_pair.val[0];
+ interleaved_vec[j + 1] = interleaved_pair.val[1];
+ }
+
+ leftover_samples = GetLeftoverSamples(length);
+ }
+#endif // SIMD_NEON
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ const size_t interleaved_index = kNumStereoChannels * i;
+ interleaved_buffer[interleaved_index] = channel_0[i];
+ interleaved_buffer[interleaved_index + 1] = channel_1[i];
+ }
+}
+
+void InterleaveStereo(size_t length, const float* channel_0,
+ const float* channel_1, int16_t* interleaved_buffer) {
+ DCHECK(interleaved_buffer);
+ DCHECK(channel_0);
+ DCHECK(channel_1);
+
+ size_t leftover_samples = length;
+#ifdef SIMD_NEON
+ if (IsAligned(interleaved_buffer) && IsAligned(channel_0) &&
+ IsAligned(channel_1)) {
+ const SimdVector* channel_0_vec =
+ reinterpret_cast<const SimdVector*>(channel_0);
+ const SimdVector* channel_1_vec =
+ reinterpret_cast<const SimdVector*>(channel_1);
+
+ const size_t num_chunks = GetNumChunks(length);
+ float32x4x2_t interleaved_pair;
+ int32x4_t temporary_wide_vector;
+
+ const SimdVector scaling_vector = SIMD_LOAD_ONE_FLOAT(kInt16FromFloat);
+ const SimdVector min_vector = SIMD_LOAD_ONE_FLOAT(kInt16Min);
+ const SimdVector max_vector = SIMD_LOAD_ONE_FLOAT(kInt16Max);
+
+ int16x4_t* interleaved_vec =
+ reinterpret_cast<int16x4_t*>(interleaved_buffer);
+ for (size_t i = 0; i < num_chunks; ++i) {
+ const size_t interleaved_index = kNumStereoChannels * i;
+ interleaved_pair = vzipq_f32(channel_0_vec[i], channel_1_vec[i]);
+ interleaved_pair.val[0] =
+ SIMD_MULTIPLY(scaling_vector, interleaved_pair.val[0]);
+ interleaved_pair.val[0] = vmaxq_f32(interleaved_pair.val[0], min_vector);
+ interleaved_pair.val[0] = vminq_f32(interleaved_pair.val[0], max_vector);
+ temporary_wide_vector = vcvtq_s32_f32(interleaved_pair.val[0]);
+ interleaved_vec[interleaved_index] = vqmovn_s32(temporary_wide_vector);
+ interleaved_pair.val[1] =
+ SIMD_MULTIPLY(scaling_vector, interleaved_pair.val[1]);
+ interleaved_pair.val[1] = vmaxq_f32(interleaved_pair.val[1], min_vector);
+ interleaved_pair.val[1] = vminq_f32(interleaved_pair.val[1], max_vector);
+ temporary_wide_vector = vcvtq_s32_f32(interleaved_pair.val[1]);
+ interleaved_vec[interleaved_index + 1] =
+ vqmovn_s32(temporary_wide_vector);
+ }
+
+ leftover_samples = GetLeftoverSamples(length);
+ }
+#endif // SIMD_NEON
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ const size_t interleaved_index = kNumStereoChannels * i;
+ interleaved_buffer[interleaved_index] = static_cast<int16_t>(std::max(
+ kInt16Min, std::min(kInt16Max, kInt16FromFloat * channel_0[i])));
+ interleaved_buffer[interleaved_index + 1] = static_cast<int16_t>(std::max(
+ kInt16Min, std::min(kInt16Max, kInt16FromFloat * channel_1[i])));
+ }
+}
+
+void DeinterleaveStereo(size_t length, const int16_t* interleaved_buffer,
+ int16_t* channel_0, int16_t* channel_1) {
+ DCHECK(interleaved_buffer);
+ DCHECK(channel_0);
+ DCHECK(channel_1);
+
+ size_t leftover_samples = length;
+#ifdef SIMD_NEON
+ if (IsAligned(interleaved_buffer) && IsAligned(channel_0) &&
+ IsAligned(channel_1)) {
+ const size_t num_chunks = length / kSixteenBitSimdLength;
+ leftover_samples = length % kSixteenBitSimdLength;
+ int16x8_t* channel_0_vec = reinterpret_cast<int16x8_t*>(channel_0);
+ int16x8_t* channel_1_vec = reinterpret_cast<int16x8_t*>(channel_1);
+ int16x8x2_t deinterleaved_pair;
+ const int16x8_t* interleaved_vec =
+ reinterpret_cast<const int16x8_t*>(interleaved_buffer);
+ for (size_t chunk = 0; chunk < num_chunks; ++chunk) {
+ const size_t interleaved_index = chunk * kNumStereoChannels;
+ deinterleaved_pair = vuzpq_s16(interleaved_vec[interleaved_index],
+ interleaved_vec[interleaved_index + 1]);
+ channel_0_vec[chunk] = deinterleaved_pair.val[0];
+ channel_1_vec[chunk] = deinterleaved_pair.val[1];
+ }
+ }
+#endif // SIMD_NEON
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ const size_t interleaved_index = kNumStereoChannels * i;
+ channel_0[i] = interleaved_buffer[interleaved_index];
+ channel_1[i] = interleaved_buffer[interleaved_index + 1];
+ }
+}
+
+void DeinterleaveStereo(size_t length, const float* interleaved_buffer,
+ float* channel_0, float* channel_1) {
+ DCHECK(interleaved_buffer);
+ DCHECK(channel_0);
+ DCHECK(channel_1);
+
+ size_t leftover_samples = length;
+#ifdef SIMD_NEON
+ if (IsAligned(interleaved_buffer) && IsAligned(channel_0) &&
+ IsAligned(channel_1)) {
+ const size_t num_chunks = GetNumChunks(length);
+ leftover_samples = GetLeftoverSamples(length);
+ SimdVector* channel_0_vec = reinterpret_cast<SimdVector*>(channel_0);
+ SimdVector* channel_1_vec = reinterpret_cast<SimdVector*>(channel_1);
+ float32x4x2_t deinterleaved_pair;
+
+ const SimdVector* interleaved_vec =
+ reinterpret_cast<const SimdVector*>(interleaved_buffer);
+ for (size_t chunk = 0; chunk < num_chunks; ++chunk) {
+ const size_t interleaved_index = chunk * kNumStereoChannels;
+ deinterleaved_pair = vuzpq_f32(interleaved_vec[interleaved_index],
+ interleaved_vec[interleaved_index + 1]);
+ channel_0_vec[chunk] = deinterleaved_pair.val[0];
+ channel_1_vec[chunk] = deinterleaved_pair.val[1];
+ }
+ }
+#endif // SIMD_NEON
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ const size_t interleaved_index = kNumStereoChannels * i;
+ channel_0[i] = interleaved_buffer[interleaved_index];
+ channel_1[i] = interleaved_buffer[interleaved_index + 1];
+ }
+}
+
+void DeinterleaveStereo(size_t length, const int16_t* interleaved_buffer,
+ float* channel_0, float* channel_1) {
+ DCHECK(interleaved_buffer);
+ DCHECK(channel_0);
+ DCHECK(channel_1);
+
+ size_t leftover_samples = length;
+#ifdef SIMD_NEON
+ if (IsAligned(interleaved_buffer) && IsAligned(channel_0) &&
+ IsAligned(channel_1)) {
+ const size_t num_chunks = GetNumChunks(length);
+ leftover_samples = GetLeftoverSamples(length);
+ SimdVector* channel_0_vec = reinterpret_cast<SimdVector*>(channel_0);
+ SimdVector* channel_1_vec = reinterpret_cast<SimdVector*>(channel_1);
+ int16x4x2_t deinterleaved_pair;
+ int32x4_t temporary_wide;
+ const SimdVector scaling_vector = SIMD_LOAD_ONE_FLOAT(kFloatFromInt16);
+
+ const int16x4_t* interleaved_vec =
+ reinterpret_cast<const int16x4_t*>(interleaved_buffer);
+ for (size_t chunk = 0; chunk < num_chunks; ++chunk) {
+ const size_t interleaved_index = chunk * kNumStereoChannels;
+ deinterleaved_pair = vuzp_s16(interleaved_vec[interleaved_index],
+ interleaved_vec[interleaved_index + 1]);
+ temporary_wide = vmovl_s16(deinterleaved_pair.val[0]);
+ channel_0_vec[chunk] = vcvtq_f32_s32(temporary_wide);
+ channel_0_vec[chunk] =
+ SIMD_MULTIPLY(scaling_vector, channel_0_vec[chunk]);
+ temporary_wide = vmovl_s16(deinterleaved_pair.val[1]);
+ channel_1_vec[chunk] = vcvtq_f32_s32(temporary_wide);
+ channel_1_vec[chunk] =
+ SIMD_MULTIPLY(scaling_vector, channel_1_vec[chunk]);
+ }
+ }
+#endif // SIMD_NEON
+ for (size_t i = length - leftover_samples; i < length; ++i) {
+ const size_t interleaved_index = kNumStereoChannels * i;
+ channel_0[i] = static_cast<float>(interleaved_buffer[interleaved_index]) *
+ kFloatFromInt16;
+ channel_1[i] =
+ static_cast<float>(interleaved_buffer[interleaved_index + 1]) *
+ kFloatFromInt16;
+ }
+}
+
+void InterleaveQuad(size_t length, const int16_t* channel_0,
+ const int16_t* channel_1, const int16_t* channel_2,
+ const int16_t* channel_3, int16_t* workspace,
+ int16_t* interleaved_buffer) {
+#ifdef SIMD_NEON
+ DCHECK(IsAligned(workspace));
+ const size_t double_length = length * 2;
+ int16_t* workspace_half_point =
+ workspace + FindNextAlignedArrayIndex(double_length, sizeof(int16_t),
+ kMemoryAlignmentBytes);
+ InterleaveStereo(length, channel_0, channel_2, workspace);
+ InterleaveStereo(length, channel_1, channel_3, workspace_half_point);
+ InterleaveStereo(double_length, workspace, workspace_half_point,
+ interleaved_buffer);
+#else
+ for (size_t i = 0; i < length; ++i) {
+ const size_t interleaved_index = kNumFirstOrderAmbisonicChannels * i;
+ interleaved_buffer[interleaved_index] = channel_0[i];
+ interleaved_buffer[interleaved_index + 1] = channel_1[i];
+ interleaved_buffer[interleaved_index + 2] = channel_2[i];
+ interleaved_buffer[interleaved_index + 3] = channel_3[i];
+ }
+#endif // SIMD_NEON
+}
+
+void InterleaveQuad(size_t length, const float* channel_0,
+ const float* channel_1, const float* channel_2,
+ const float* channel_3, float* workspace,
+ float* interleaved_buffer) {
+#ifdef SIMD_NEON
+ DCHECK(IsAligned(workspace));
+ const size_t double_length = length * 2;
+ float* workspace_half_point =
+ workspace + FindNextAlignedArrayIndex(double_length, sizeof(float),
+ kMemoryAlignmentBytes);
+ DCHECK(IsAligned(workspace_half_point));
+ InterleaveStereo(length, channel_0, channel_2, workspace);
+ InterleaveStereo(length, channel_1, channel_3, workspace_half_point);
+ InterleaveStereo(double_length, workspace, workspace_half_point,
+ interleaved_buffer);
+#else
+ for (size_t i = 0; i < length; ++i) {
+ const size_t interleaved_index = kNumFirstOrderAmbisonicChannels * i;
+ interleaved_buffer[interleaved_index] = channel_0[i];
+ interleaved_buffer[interleaved_index + 1] = channel_1[i];
+ interleaved_buffer[interleaved_index + 2] = channel_2[i];
+ interleaved_buffer[interleaved_index + 3] = channel_3[i];
+ }
+#endif // SIMD_NEON
+}
+
+void DeinterleaveQuad(size_t length, const int16_t* interleaved_buffer,
+ int16_t* workspace, int16_t* channel_0,
+ int16_t* channel_1, int16_t* channel_2,
+ int16_t* channel_3) {
+#ifdef SIMD_NEON
+ DCHECK(IsAligned(workspace));
+ const size_t double_length = length * 2;
+ int16_t* workspace_half_point =
+ workspace + FindNextAlignedArrayIndex(double_length, sizeof(int16_t),
+ kMemoryAlignmentBytes);
+ DCHECK(IsAligned(workspace_half_point));
+ DeinterleaveStereo(double_length, interleaved_buffer, workspace,
+ workspace_half_point);
+ DeinterleaveStereo(length, workspace, channel_0, channel_2);
+ DeinterleaveStereo(length, workspace_half_point, channel_1, channel_3);
+#else
+ for (size_t i = 0; i < length; ++i) {
+ const size_t interleaved_index = kNumFirstOrderAmbisonicChannels * i;
+ channel_0[i] = interleaved_buffer[interleaved_index];
+ channel_1[i] = interleaved_buffer[interleaved_index + 1];
+ channel_2[i] = interleaved_buffer[interleaved_index + 2];
+ channel_3[i] = interleaved_buffer[interleaved_index + 3];
+ }
+#endif // SIMD_NEON
+}
+
+void DeinterleaveQuad(size_t length, const float* interleaved_buffer,
+ float* workspace, float* channel_0, float* channel_1,
+ float* channel_2, float* channel_3) {
+#ifdef SIMD_NEON
+ DCHECK(IsAligned(workspace));
+ const size_t double_length = length * 2;
+ float* workspace_half_point =
+ workspace + FindNextAlignedArrayIndex(double_length, sizeof(float),
+ kMemoryAlignmentBytes);
+ DCHECK(IsAligned(workspace_half_point));
+ DeinterleaveStereo(double_length, interleaved_buffer, workspace,
+ workspace_half_point);
+ DeinterleaveStereo(length, workspace, channel_0, channel_2);
+ DeinterleaveStereo(length, workspace_half_point, channel_1, channel_3);
+#else
+ for (size_t i = 0; i < length; ++i) {
+ const size_t interleaved_index = kNumFirstOrderAmbisonicChannels * i;
+ channel_0[i] = interleaved_buffer[interleaved_index];
+ channel_1[i] = interleaved_buffer[interleaved_index + 1];
+ channel_2[i] = interleaved_buffer[interleaved_index + 2];
+ channel_3[i] = interleaved_buffer[interleaved_index + 3];
+ }
+#endif // SIMD_NEON
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/simd_utils.h b/src/3rdparty/resonance-audio/resonance_audio/base/simd_utils.h
new file mode 100644
index 000000000..64fb9c6d1
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/simd_utils.h
@@ -0,0 +1,296 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_BASE_SIMD_UTILS_H_
+#define RESONANCE_AUDIO_BASE_SIMD_UTILS_H_
+
+#include <cstddef>
+#include <cstdint>
+
+namespace vraudio {
+
+// Checks if the pointer provided is correctly aligned for SIMD.
+//
+// @param pointer Pointer to check.
+// @return True if the pointer is correctly aligned.
+bool IsAligned(const float* pointer);
+bool IsAligned(const int16_t* pointer);
+
+// Rounds a number of frames up to the next aligned memory address
+// based on |memory_alignment_bytes|. This allows for aligning offset pointers
+// into a single chunk of allocated memory.
+//
+// @param length Number of samples before the desired offset pointer.
+// @param type_size_bytes Size of the type of each entry in the array.
+// @param memory_alignment_bytes Number of bytes to which an address is aligned.
+// @return Number of samples into the memory chunk to ensure aligned memory.
+size_t FindNextAlignedArrayIndex(size_t length, size_t type_size_bytes,
+ size_t memory_alignment_bytes);
+
+// Adds a float array |input_a| to another float array |input_b| and stores the
+// result in |output|.
+//
+// @param length Number of floats.
+// @param input_a Pointer to the first float in input_a array.
+// @param input_b Pointer to the first float in input_b array.
+// @param output Pointer to the first float in output array.
+void AddPointwise(size_t length, const float* input_a, const float* input_b,
+ float* output);
+
+// Subtracts a float array |input|, pointwise from another float array |output|.
+//
+// @param length Number of floats.
+// @param input Pointer to the first float in input_a array.
+// @param output Pointer to the first float in input_b array.
+// @param output Pointer to the first float in output array.
+void SubtractPointwise(size_t length, const float* input_a,
+ const float* input_b, float* output);
+
+// Pointwise multiplies a float array |input_a| with another float array
+// |input_b| and stores the result in |output|.
+//
+// @param length Number of floats.
+// @param input Pointer to the first float in input_a array.
+// @param input Pointer to the first float in input_b array.
+// @param output Pointer to the first float in output array.
+void MultiplyPointwise(size_t length, const float* input_a,
+ const float* input_b, float* output);
+
+// Pointwise multiplies a float array |input_a| with another float array
+// |input_b| and adds the result onto |accumulator|.
+//
+// @param length Number of floats.
+// @param input_a Pointer to the first float in input_a array.
+// @param input_b Pointer to the first float in input_b array.
+// @param accumulator Pointer to the first float in accumulator array.
+void MultiplyAndAccumulatePointwise(size_t length, const float* input_a,
+ const float* input_b, float* accumulator);
+
+// Multiplies a float array |input| by a scalar |gain| over |length| samples.
+//
+// @param length Number of floats.
+// @param gain Scalar value with which to multiply the input.
+// @param input Pointer to the first float in input array.
+// @param output Pointer to the first float in output array.
+void ScalarMultiply(size_t length, float gain, const float* input,
+ float* output);
+
+// Multiplies a float array |input| by a scalar |gain| over |length| samples and
+// adds the result onto |accumulator|.
+//
+// @param length Number of floats.
+// @param gain Scalar value with which to multiply the input.
+// @param input Pointer to the first float in input array.
+// @param output Pointer to the first float in accumulator array.
+void ScalarMultiplyAndAccumulate(size_t length, float gain, const float* input,
+ float* accumulator);
+
+// Calculates an approximmate reciprocal square root.
+//
+// @param length Number of floats.
+// @param input Pointer to the first float in input array.
+// @param output Pointer to the first float in output array.
+void ReciprocalSqrt(size_t length, const float* input, float* output);
+
+// Calculates an approximate square root.
+//
+// @param length Number of floats.
+// @param input Pointer to the first float in input array.
+// @param output Pointer to the first float in output array.
+void Sqrt(size_t length, const float* input, float* output);
+
+// Calculates the approximate magnitudes of interleaved complex numbers.
+//
+// @param length Number of complex numbers in the input array,
+// (i.e. half its length).
+// @param input Pointer to the first float in input array. Length: 2 * |length|.
+// @param output Pointer to the first float in output array, Length: |length|.
+void ApproxComplexMagnitude(size_t length, const float* input, float* output);
+
+// Calculates the complex values in interleaved format (real, imaginary), from a
+// vector of magnitudes and of sines and cosines of phase.
+//
+// @param length Number of total entries (real & imaginary) in the input array.
+// @param magnitude Pointer to the first float in the magnitude array, Length:
+// |length| / 2
+// @param cos_phase Pointer to the first float in the cosine phase array,
+// Length: |length| / 2
+// @param sin_phase Pointer to the first float in the sine phase array, Length:
+// |length| / 2
+// @param complex_interleaved_format_output Pointer to the first float in the
+// output array. Length: |length|.
+void ComplexInterleavedFormatFromMagnitudeAndSinCosPhase(
+ size_t length, const float* magnitude, const float* cos_phase,
+ const float* sin_phase, float* complex_interleaved_format_output);
+
+// Generates an identical left and right pair of stereo channels from a mono
+// input channel, where each channel is the mono channel times 1/sqrt(2).
+//
+// @param length Number of floats.
+// @param mono Pointer to the first float in an input mono array.
+// @param left Pointer to the first float in the left output array.
+// @param right Pointer to the first float in the right output array.
+void StereoFromMonoSimd(size_t length, const float* mono, float* left,
+ float* right);
+
+// Generates a mono downmix from a pair of stereo channels, where the output is
+// equal to the sum of the two inputs times 1/sqrt(2).
+//
+// @param length Number of floats.
+// @param left Pointer to the first float in the left input array.
+// @param right Pointer to the first float in the right input array.
+// @param mono Pointer to the first float in an output mono array.
+void MonoFromStereoSimd(size_t length, const float* left, const float* right,
+ float* mono);
+
+// Converts an array of 32 bit float input to clamped 16 bit int output.
+//
+// @param length Number of floats in the input array and int16_ts in the output.
+// @param input Float array.
+// @param output Int array.
+void Int16FromFloat(size_t length, const float* input, int16_t* output);
+
+// Converts an array of 16 bit int input to 32 bit float output.
+//
+// @param length Number of int16_ts in the input array and floats in the output.
+// @param input Int array.
+// @param output Float array.
+void FloatFromInt16(size_t length, const int16_t* input, float* output);
+
+// Interleaves a pair of mono buffers of int_16 data into a stereo buffer.
+//
+// @param length Number of frames per mono channel. The interleaved buffer must
+// be twice this size.
+// @param channel_0 Input buffer of mono data for the first channel.
+// @param channel_1 Input buffer of mono data for the second channel.
+// @param interleaved_buffer Output buffer of stereo interleaved data.
+void InterleaveStereo(size_t length, const int16_t* channel_0,
+ const int16_t* channel_1, int16_t* interleaved_buffer);
+
+// Interleaves a pair of mono buffers of float data into a stereo buffer.
+//
+// @param length Number of frames per mono channel. The interleaved buffer must
+// be twice this size.
+// @param channel_0 Input buffer of mono data for the first channel.
+// @param channel_1 Input buffer of mono data for the second channel.
+// @param interleaved_buffer Output buffer of stereo interleaved data.
+void InterleaveStereo(size_t length, const float* channel_0,
+ const float* channel_1, float* interleaved_buffer);
+
+// Interleaves a pair of mono buffers of float data into a stereo buffer of
+// int16_t data.
+//
+// @param length Number of frames per mono channel. The interleaved buffer must
+// be twice this size.
+// @param channel_0 Input buffer of mono data for the first channel (float).
+// @param channel_1 Input buffer of mono data for the second channel (float).
+// @param interleaved_buffer Output buffer of stereo interleaved data (int16_t).
+void InterleaveStereo(size_t length, const float* channel_0,
+ const float* channel_1, int16_t* interleaved_buffer);
+
+// Deinterleaves a stereo buffer of int16_t data into a pair of mono buffers.
+//
+// @param length Number of frames per mono channel. The interleaved buffer must
+// be twice this size.
+// @param interleaved_buffer Input buffer of stereo interleaved data.
+// @param channel_0 Output buffer of mono data for the first channel.
+// @param channel_1 Output buffer of mono data for the second channel.
+void DeinterleaveStereo(size_t length, const int16_t* interleaved_buffer,
+ int16_t* channel_0, int16_t* channel_1);
+
+// Deinterleaves a stereo buffer of float data into a pair of mono buffers.
+//
+// @param length Number of frames per mono channel. The interleaved buffer must
+// be twice this size.
+// @param interleaved_buffer Input buffer of stereo interleaved data.
+// @param channel_0 Output buffer of mono data for the first channel.
+// @param channel_1 Output buffer of mono data for the second channel.
+void DeinterleaveStereo(size_t length, const float* interleaved_buffer,
+ float* channel_0, float* channel_1);
+
+// Deinterleaves a stereo buffer of int16_t data into a pair of mono float
+// buffers, performing the int16 to floating point conversion.
+//
+// @param length Number of frames per mono channel. The interleaved buffer must
+// be twice this size.
+// @param interleaved_buffer Input buffer of stereo interleaved data (int16_t).
+// @param channel_0 Output buffer of mono data for the first channel (float).
+// @param channel_1 Output buffer of mono data for the second channel (float).
+void DeinterleaveStereo(size_t length, const int16_t* interleaved_buffer,
+ float* channel_0, float* channel_1);
+
+// Interleaves four mono buffers of int16_t data into a quad buffer.
+//
+// @param length Number of frames per mono channel. The interleaved buffer must
+// be four times this size and the workspace must be five times this size.
+// @param channel_0 Input buffer of mono data for the first channel.
+// @param channel_1 Input buffer of mono data for the second channel.
+// @param channel_2 Input buffer of mono data for the third channel.
+// @param channel_3 Input buffer of mono data for the fourth channel.
+// @param workspace Aligned buffer of 5 * |length| samples in length.
+// @param interleaved_buffer Output buffer of quad interleaved data.
+void InterleaveQuad(size_t length, const int16_t* channel_0,
+ const int16_t* channel_1, const int16_t* channel_2,
+ const int16_t* channel_3, int16_t* workspace,
+ int16_t* interleaved_buffer);
+
+// Interleaves four mono buffers of float data into a quad buffer.
+//
+// @param length Number of frames per mono channel. The interleaved buffer must
+// be four times this size and the workspace must be five times this size.
+// @param channel_0 Input buffer of mono data for the first channel.
+// @param channel_1 Input buffer of mono data for the second channel.
+// @param channel_2 Input buffer of mono data for the third channel.
+// @param channel_3 Input buffer of mono data for the fourth channel.
+// @param workspace Aligned buffer of 5 * |length| samples in length.
+// @param interleaved_buffer Output buffer of quad interleaved data.
+void InterleaveQuad(size_t length, const float* channel_0,
+ const float* channel_1, const float* channel_2,
+ const float* channel_3, float* workspace,
+ float* interleaved_buffer);
+
+// Deinterleaves a quad buffer of int16_t data into four mono buffers.
+//
+// @param length Number of frames per mono channel. The interleaved buffer must
+// be four times this size and the workspace must be five times this size.
+// @param interleaved_buffer Input buffer of quad interleaved data.
+// @param workspace Aligned buffer of 5 * |length| samples in length.
+// @param channel_0 Output buffer of mono data for the first channel.
+// @param channel_1 Output buffer of mono data for the second channel.
+// @param channel_2 Output buffer of mono data for the third channel.
+// @param channel_3 Output buffer of mono data for the fourth channel.
+void DeinterleaveQuad(size_t length, const int16_t* interleaved_buffer,
+ int16_t* workspace, int16_t* channel_0,
+ int16_t* channel_1, int16_t* channel_2,
+ int16_t* channel_3);
+
+// Deinterleaves a quad buffer of float data into four mono buffers.
+//
+// @param length Number of frames per mono channel. The interleaved buffer must
+// be four times this size and the workspace must be five times this size.
+// @param interleaved_buffer Input buffer of quad interleaved data.
+// @param workspace Aligned buffer of 5 * |length| samples in length.
+// @param channel_0 Output buffer of mono data for the first channel.
+// @param channel_1 Output buffer of mono data for the second channel.
+// @param channel_2 Output buffer of mono data for the third channel.
+// @param channel_3 Output buffer of mono data for the fourth channel.
+void DeinterleaveQuad(size_t length, const float* interleaved_buffer,
+ float* workspace, float* channel_0, float* channel_1,
+ float* channel_2, float* channel_3);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_BASE_SIMD_UTILS_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/simd_utils_test.cc b/src/3rdparty/resonance-audio/resonance_audio/base/simd_utils_test.cc
new file mode 100644
index 000000000..7fb8e83b5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/simd_utils_test.cc
@@ -0,0 +1,711 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "base/simd_utils.h"
+
+#include <algorithm>
+#include <cmath>
+#include <cstdint>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// Input lengths (purposefully chosen not to be a multiple of SIMD_LENGTH).
+const size_t kInputSize = 7;
+const size_t kNumTestChannels = 3;
+const size_t kNumQuadChannels = 4;
+
+// Length of deinterleaved and interleaved buffers.
+const size_t kHalfSize = 21;
+const size_t kFullSize = kHalfSize * 2;
+const size_t kQuadSize = kHalfSize * 4;
+const size_t kPentSize = kHalfSize * 5;
+
+// The int16 values for the deinterleaving test.
+const int16_t kOne = 0x0001;
+const int16_t kTwo = 0x0002;
+const int16_t kThree = 0x0003;
+const int16_t kFour = 0x0004;
+const int16_t kMax = 0x7FFF;
+const int16_t kMin = -0x7FFF;
+
+// Epsilon for conversion from int16_t back to float.
+const float kFloatEpsilon = 1e-4f;
+const int16_t kIntEpsilon = 1;
+
+// Intereleaved data.
+const int16_t kInterleavedInput[kFullSize] = {
+ kOne, kTwo, kOne, kTwo, kOne, kTwo, kOne, kTwo, kOne, kTwo, kOne,
+ kTwo, kOne, kTwo, kOne, kTwo, kOne, kTwo, kOne, kTwo, kOne, kTwo,
+ kOne, kTwo, kOne, kTwo, kOne, kTwo, kOne, kTwo, kOne, kTwo, kOne,
+ kTwo, kOne, kTwo, kOne, kTwo, kOne, kTwo, kOne, kTwo};
+
+// Corresponding values for float and 16 bit int.
+const float kFloatInput[kInputSize] = {0.5f, -0.5f, 1.0f, -1.0f,
+ 1.0f, -1.0f, 0.0f};
+const int16_t kIntInput[kInputSize] = {0x4000, -0x4000, 0x7FFF, -0x7FFF,
+ 0x7FFF, -0x7FFF, 0};
+
+TEST(SimdUtilsTest, IsAlignedTest) {
+ AudioBuffer aligned_audio_buffer(kNumMonoChannels, kInputSize);
+ const float* aligned_ptr = aligned_audio_buffer[0].begin();
+ const float* unaligned_ptr = aligned_ptr + 1;
+ EXPECT_TRUE(IsAligned(aligned_ptr));
+ EXPECT_FALSE(IsAligned(unaligned_ptr));
+}
+
+TEST(SimdUtilsTest, AddPointwiseTest) {
+ const float kResult = 3.0f;
+ AudioBuffer aligned_audio_buffer(kNumTestChannels, kInputSize);
+ aligned_audio_buffer.Clear();
+ for (size_t i = 0; i < kInputSize; ++i) {
+ aligned_audio_buffer[0][i] = 1.0f;
+ aligned_audio_buffer[1][i] = 2.0f;
+ }
+ AddPointwise(kInputSize, &aligned_audio_buffer[0][0],
+ &aligned_audio_buffer[1][0], &aligned_audio_buffer[2][0]);
+ for (size_t i = 0; i < kInputSize; ++i) {
+ EXPECT_FLOAT_EQ(aligned_audio_buffer[2][i], kResult);
+ }
+}
+
+TEST(SimdUtilsTest, AddPointwiseInPlaceTest) {
+ AudioBuffer aligned_audio_buffer(kNumStereoChannels, kInputSize);
+ aligned_audio_buffer.Clear();
+ for (size_t i = 0; i < kInputSize; ++i) {
+ aligned_audio_buffer[0][i] = static_cast<float>(i);
+ }
+ const size_t kRuns = 2;
+ for (size_t i = 0; i < kRuns; ++i) {
+ AddPointwise(kInputSize, &aligned_audio_buffer[0][0],
+ &aligned_audio_buffer[1][0], &aligned_audio_buffer[1][0]);
+ }
+ for (size_t i = 0; i < kInputSize; ++i) {
+ EXPECT_FLOAT_EQ(aligned_audio_buffer[1][i], static_cast<float>(i * kRuns));
+ }
+}
+
+TEST(SimdUtilsTest, SubtractPointwiseTest) {
+ AudioBuffer aligned_audio_buffer(kNumStereoChannels, kInputSize);
+ aligned_audio_buffer.Clear();
+ for (size_t i = 0; i < kInputSize; ++i) {
+ aligned_audio_buffer[0][i] = static_cast<float>(i);
+ aligned_audio_buffer[1][i] = static_cast<float>(2 * i);
+ }
+ SubtractPointwise(kInputSize, &aligned_audio_buffer[0][0],
+ &aligned_audio_buffer[1][0], &aligned_audio_buffer[1][0]);
+ for (size_t i = 0; i < kInputSize; ++i) {
+ EXPECT_FLOAT_EQ(aligned_audio_buffer[1][i], aligned_audio_buffer[0][i]);
+ }
+}
+
+TEST(SimdUtilsTest, MultiplyPointwiseTest) {
+ AudioBuffer aligned_audio_buffer(kNumStereoChannels, kInputSize);
+ aligned_audio_buffer.Clear();
+ for (size_t i = 0; i < kInputSize; ++i) {
+ aligned_audio_buffer[0][i] = static_cast<float>(i);
+ aligned_audio_buffer[1][i] = static_cast<float>(i);
+ }
+ MultiplyPointwise(kInputSize, &aligned_audio_buffer[0][0],
+ &aligned_audio_buffer[1][0], &aligned_audio_buffer[1][0]);
+ for (size_t i = 0; i < kInputSize; ++i) {
+ EXPECT_FLOAT_EQ(aligned_audio_buffer[1][i],
+ aligned_audio_buffer[0][i] * aligned_audio_buffer[0][i]);
+ }
+}
+
+TEST(SimdUtilsTest, MultiplyAndAccumulatePointwiseTest) {
+ const float kInitialOutput = 1.0f;
+ AudioBuffer aligned_input_buffer(kNumStereoChannels, kInputSize);
+ aligned_input_buffer.Clear();
+ AudioBuffer aligned_output_buffer(kNumMonoChannels, kInputSize);
+ aligned_output_buffer.Clear();
+ for (size_t i = 0; i < kInputSize; ++i) {
+ aligned_input_buffer[0][i] = static_cast<float>(i);
+ aligned_input_buffer[1][i] = static_cast<float>(i);
+ aligned_output_buffer[0][i] = kInitialOutput;
+ }
+ MultiplyAndAccumulatePointwise(kInputSize, &aligned_input_buffer[0][0],
+ &aligned_input_buffer[1][0],
+ &aligned_output_buffer[0][0]);
+ for (size_t i = 0; i < kInputSize; ++i) {
+ EXPECT_FLOAT_EQ(aligned_output_buffer[0][i],
+ kInitialOutput + aligned_input_buffer[0][i] *
+ aligned_input_buffer[1][i]);
+ }
+}
+
+TEST(SimdUtilsTest, ScalarMultiplyTest) {
+ AudioBuffer aligned_audio_buffer(kNumStereoChannels, kInputSize);
+ aligned_audio_buffer.Clear();
+ for (size_t i = 0; i < kInputSize; ++i) {
+ aligned_audio_buffer[0][i] = 1.0f;
+ aligned_audio_buffer[1][i] = 0.0f;
+ }
+ const float gain = 0.5f;
+ ScalarMultiply(kInputSize, gain, &aligned_audio_buffer[0][0],
+ &aligned_audio_buffer[1][0]);
+ for (size_t i = 0; i < kInputSize; ++i) {
+ EXPECT_FLOAT_EQ(aligned_audio_buffer[1][i],
+ aligned_audio_buffer[0][i] * gain);
+ }
+}
+
+TEST(SimdUtilsTest, ScalarMultiplyAndAccumuateTest) {
+ const float kResult = 2.0f;
+ AudioBuffer aligned_audio_buffer(kNumStereoChannels, kInputSize);
+ aligned_audio_buffer.Clear();
+ for (size_t i = 0; i < kInputSize; ++i) {
+ aligned_audio_buffer[0][i] = 0.5f;
+ aligned_audio_buffer[1][i] = 1.0f;
+ }
+ const float gain = 2.0f;
+ ScalarMultiplyAndAccumulate(kInputSize, gain, &aligned_audio_buffer[0][0],
+ &aligned_audio_buffer[1][0]);
+ for (size_t i = 0; i < kInputSize; ++i) {
+ EXPECT_FLOAT_EQ(aligned_audio_buffer[1][i], kResult);
+ }
+}
+
+TEST(SimdUtilsTest, SqrtTest) {
+ const std::vector<float> kNumbers{130.0f, 13.0f, 1.3f,
+ 0.13f, 0.013f, 0.0013f};
+ AudioBuffer numbers(kNumMonoChannels, kNumbers.size());
+ AudioBuffer approximate(kNumMonoChannels, kNumbers.size());
+ numbers[0] = kNumbers;
+ const float kSqrtEpsilon = 2e-3f;
+
+ Sqrt(kNumbers.size(), numbers[0].begin(), approximate[0].begin());
+
+ for (size_t i = 0; i < kNumbers.size(); ++i) {
+ const float actual = std::sqrt(kNumbers[i]);
+ EXPECT_LT(std::abs(actual - approximate[0][i]) / actual, kSqrtEpsilon);
+ }
+}
+
+TEST(SimdUtilsTest, ReciprocalSqrtTest) {
+ const std::vector<float> kNumbers{130.0f, 13.0f, 1.3f,
+ 0.13f, 0.013f, 0.0013f};
+ AudioBuffer numbers(kNumMonoChannels, kNumbers.size());
+ AudioBuffer sqrt(kNumMonoChannels, kNumbers.size());
+ AudioBuffer recip_sqrt(kNumMonoChannels, kNumbers.size());
+
+ Sqrt(kNumbers.size(), numbers[0].begin(), sqrt[0].begin());
+ ReciprocalSqrt(kNumbers.size(), numbers[0].begin(), recip_sqrt[0].begin());
+
+ for (size_t i = 0; i < kNumbers.size(); ++i) {
+ EXPECT_FLOAT_EQ(1.0f / recip_sqrt[0][i], sqrt[0][i]);
+ }
+}
+
+// Tests that the correct complex magnitudes are calculated for a range of
+// complex numbers with both positive and negative imaginary part.
+TEST(SimdUtilsTest, ApproxComplexMagnitudeTest) {
+ const size_t kFramesPerBuffer = 17;
+ // Check that we are correct to within 0.5% of each value.
+ const float kErrEpsilon = 5e-3f;
+ AudioBuffer complex_buffer(kNumMonoChannels, 2 * kFramesPerBuffer);
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ const size_t j = 2 * i;
+ complex_buffer[0][j] = static_cast<float>(i);
+ complex_buffer[0][j + 1] = ((i % 2) ? -1.0f : 1.0f) * static_cast<float>(i);
+ }
+ AudioBuffer magnitude_buffer(kNumMonoChannels, kFramesPerBuffer);
+
+ ApproxComplexMagnitude(kFramesPerBuffer, complex_buffer[0].begin(),
+ magnitude_buffer[0].begin());
+
+ for (size_t sample = 0; sample < kFramesPerBuffer; ++sample) {
+ const float expected = static_cast<float>(sample) * kSqrtTwo;
+ // Check its correct to within 0.5%.
+ EXPECT_NEAR(magnitude_buffer[0][sample], expected, kErrEpsilon * expected);
+ }
+}
+
+// Tests that the ComplexInterleavedFormatFromMagnitudeAndSinCosPhase() method
+// correctly recovers the frequency response from magnitude and phase.
+TEST(SimdUtilsTest, ComplexInterleavedFormatFromMagnitudeAndSinCosPhaseTest) {
+ // The folowing vectors contain the inverse sines and cosines of the numbers
+ // 0 to 0.75 in steps of 0.05 (calculated in MATLAB).
+ const size_t kLength = 16;
+ AudioBuffer cos_vec(kNumMonoChannels, kLength);
+ cos_vec[0] = {1.5708f, 1.5208f, 1.4706f, 1.4202f, 1.3694f, 1.3181f,
+ 1.2661f, 1.2132f, 1.1593f, 1.1040f, 1.0472f, 0.9884f,
+ 0.9273f, 0.8632f, 0.7954f, 0.7227f};
+ AudioBuffer sin_vec(kNumMonoChannels, kLength);
+ sin_vec[0] = {0.0000f, 0.0500f, 0.1002f, 0.1506f, 0.2014f, 0.2527f,
+ 0.3047f, 0.3576f, 0.4115f, 0.4668f, 0.5236f, 0.5824f,
+ 0.6435f, 0.7076f, 0.7754f, 0.8481f};
+ const float kMagnitude = 10.0f;
+ AudioBuffer magnitude(kNumMonoChannels, kLength);
+ std::fill(magnitude[0].begin(), magnitude[0].end(), kMagnitude);
+ const size_t output_size = 2 * sin_vec.num_frames();
+ AudioBuffer output(kNumMonoChannels, output_size);
+ output.Clear();
+
+ ComplexInterleavedFormatFromMagnitudeAndSinCosPhase(
+ output_size, &magnitude[0][0], &cos_vec[0][0], &sin_vec[0][0],
+ &output[0][0]);
+
+ for (size_t i = 0, j = 0; i < output_size; i += 2, ++j) {
+ EXPECT_FLOAT_EQ(output[0][i], kMagnitude * cos_vec[0][j]);
+ EXPECT_FLOAT_EQ(output[0][i + 1], kMagnitude * sin_vec[0][j]);
+ }
+}
+
+TEST(SimdUtilsTest, StereoMonoTest) {
+ const float kResult = 2.0f / std::sqrt(2.0f);
+ AudioBuffer aligned_audio_buffer(kNumTestChannels, kInputSize);
+ aligned_audio_buffer.Clear();
+ for (size_t i = 0; i < kInputSize; ++i) {
+ aligned_audio_buffer[0][i] = 1.0f;
+ aligned_audio_buffer[1][i] = 1.0f;
+ }
+ MonoFromStereoSimd(kInputSize, &aligned_audio_buffer[0][0],
+ &aligned_audio_buffer[1][0], &aligned_audio_buffer[2][0]);
+ for (size_t i = 0; i < kInputSize; ++i) {
+ EXPECT_FLOAT_EQ(aligned_audio_buffer[2][i], kResult);
+ }
+ // Perform inverse operation.
+ StereoFromMonoSimd(kInputSize, &aligned_audio_buffer[2][0],
+ &aligned_audio_buffer[0][0], &aligned_audio_buffer[1][0]);
+ for (size_t i = 0; i < kInputSize; ++i) {
+ EXPECT_FLOAT_EQ(aligned_audio_buffer[0][i], 1.0f);
+ EXPECT_FLOAT_EQ(aligned_audio_buffer[1][i], 1.0f);
+ }
+}
+
+TEST(SimdUtilsTest, InterleaveAlignedInt16Test) {
+ AudioBuffer::AlignedInt16Vector interleaved(kFullSize);
+ AudioBuffer::AlignedInt16Vector channel_0(kHalfSize);
+ AudioBuffer::AlignedInt16Vector channel_1(kHalfSize);
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ channel_0[i] = kOne;
+ channel_1[i] = kTwo;
+ }
+
+ InterleaveStereo(kHalfSize, channel_0.data(), channel_1.data(),
+ interleaved.data());
+
+ for (size_t i = 0; i < kFullSize; ++i) {
+ const int16_t value = (i % 2 == 0) ? kOne : kTwo;
+ EXPECT_EQ(interleaved[i], value);
+ }
+}
+
+TEST(SimdUtilsTest, InterleaveUnalignedInt16Test) {
+ AudioBuffer::AlignedInt16Vector interleaved(kFullSize);
+ AudioBuffer::AlignedInt16Vector channel_0(kHalfSize);
+ AudioBuffer::AlignedInt16Vector channel_1(kHalfSize);
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ channel_0[i] = kOne;
+ channel_1[i] = kTwo;
+ }
+
+ InterleaveStereo(kHalfSize, channel_0.data(), channel_1.data(),
+ interleaved.data());
+
+ for (size_t i = 0; i < kFullSize; ++i) {
+ const int16_t value = (i % 2 == 0) ? kOne : kTwo;
+ EXPECT_EQ(interleaved[i], value);
+ }
+}
+
+TEST(SimdUtilsTest, DeinterleaveAlignedInt16Test) {
+ AudioBuffer::AlignedInt16Vector interleaved(kFullSize);
+ AudioBuffer::AlignedInt16Vector channel_0(kHalfSize);
+ AudioBuffer::AlignedInt16Vector channel_1(kHalfSize);
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kFullSize; ++i) {
+ interleaved[i] = kInterleavedInput[i];
+ }
+
+ // Clear the output buffers.
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ channel_0[i] = static_cast<int16_t>(0);
+ channel_1[i] = static_cast<int16_t>(0);
+ }
+
+ // Test the case where input is aligned.
+ DeinterleaveStereo(kHalfSize, interleaved.data(), channel_0.data(),
+ channel_1.data());
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ EXPECT_EQ(channel_0[i], kOne);
+ EXPECT_EQ(channel_1[i], kTwo);
+ }
+}
+
+TEST(SimdUtilsTest, DeinterleaveUnalignedInt16Test) {
+ AudioBuffer::AlignedInt16Vector channel_0(kHalfSize);
+ AudioBuffer::AlignedInt16Vector channel_1(kHalfSize);
+
+ // Clear the output buffers.
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ channel_0[i] = static_cast<int16_t>(0);
+ channel_1[i] = static_cast<int16_t>(0);
+ }
+
+ // Test the case where input is unaligned.
+ DeinterleaveStereo(kHalfSize, kInterleavedInput, channel_0.data(),
+ channel_1.data());
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ EXPECT_EQ(channel_0[i], kOne);
+ EXPECT_EQ(channel_1[i], kTwo);
+ }
+}
+
+TEST(SimdUtilsTest, DeinterleaveAlignedInt16ConvertToFloatTest) {
+ AudioBuffer::AlignedInt16Vector interleaved(kFullSize);
+ AudioBuffer planar(kNumStereoChannels, kHalfSize);
+ AudioBuffer::Channel& channel_0 = planar[0];
+ AudioBuffer::Channel& channel_1 = planar[1];
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kFullSize; ++i) {
+ interleaved[i] = i % 2 ? kMin : kMax;
+ }
+
+ // Clear the output buffers.
+ planar.Clear();
+
+ // Test the case where input is aligned.
+ DeinterleaveStereo(kHalfSize, interleaved.data(), channel_0.begin(),
+ channel_1.begin());
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ EXPECT_NEAR(channel_0[i], 1.0f, kEpsilonFloat);
+ EXPECT_NEAR(channel_1[i], -1.0f, kEpsilonFloat);
+ }
+}
+
+TEST(SimdUtilsTest, DeinterleaveUnalignedInt16ConvertToFloatTest) {
+ int16_t interleaved[kFullSize];
+ AudioBuffer planar(kNumStereoChannels, kHalfSize);
+ AudioBuffer::Channel& channel_0 = planar[0];
+ AudioBuffer::Channel& channel_1 = planar[1];
+
+ // Fill the unaligned input buffer.
+ for (size_t i = 0; i < kFullSize; ++i) {
+ interleaved[i] = i % 2 ? kMin : kMax;
+ }
+
+ // Clear the output buffers.
+ planar.Clear();
+
+ // Test the case where input is unaligned.
+ DeinterleaveStereo(kHalfSize, interleaved, channel_0.begin(),
+ channel_1.begin());
+
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ EXPECT_NEAR(channel_0[i], 1.0f, kEpsilonFloat);
+ EXPECT_NEAR(channel_1[i], -1.0f, kEpsilonFloat);
+ }
+}
+
+TEST(SimdUtilsTest, InterleaveAlignedFloatTest) {
+ AudioBuffer interleaved(kNumMonoChannels, kFullSize);
+ AudioBuffer planar(kNumStereoChannels, kHalfSize);
+ AudioBuffer::Channel& channel_0 = planar[0];
+ AudioBuffer::Channel& channel_1 = planar[1];
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ channel_0[i] = 1.0f;
+ channel_1[i] = 2.0f;
+ }
+
+ InterleaveStereo(kHalfSize, channel_0.begin(), channel_1.begin(),
+ interleaved[0].begin());
+
+ for (size_t i = 0; i < kFullSize; ++i) {
+ const float value = (i % 2 == 0) ? 1.0f : 2.0f;
+ EXPECT_FLOAT_EQ(interleaved[0][i], value);
+ }
+}
+
+TEST(SimdUtilsTest, InterleaveUnalignedFloatTest) {
+ float interleaved[kFullSize];
+ AudioBuffer planar(kNumStereoChannels, kHalfSize);
+ AudioBuffer::Channel& channel_0 = planar[0];
+ AudioBuffer::Channel& channel_1 = planar[1];
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ channel_0[i] = 1.0f;
+ channel_1[i] = 2.0f;
+ }
+
+ InterleaveStereo(kHalfSize, channel_0.begin(), channel_1.begin(),
+ interleaved);
+
+ for (size_t i = 0; i < kFullSize; ++i) {
+ const float value = (i % 2 == 0) ? 1.0f : 2.0f;
+ EXPECT_FLOAT_EQ(interleaved[i], value);
+ }
+}
+
+TEST(SimdUtilsTest, InterleaveAlignedFloatConvertToInt16Test) {
+ AudioBuffer::AlignedInt16Vector interleaved(kFullSize);
+ AudioBuffer planar(kNumStereoChannels, kHalfSize);
+ AudioBuffer::Channel& channel_0 = planar[0];
+ AudioBuffer::Channel& channel_1 = planar[1];
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ channel_0[i] = 1.0f;
+ channel_1[i] = -1.0f;
+ }
+
+ InterleaveStereo(kHalfSize, channel_0.begin(), channel_1.begin(),
+ interleaved.data());
+
+ for (size_t i = 0; i < kFullSize; ++i) {
+ const int16_t value = i % 2 ? kMin : kMax;
+ EXPECT_NEAR(interleaved[i], value, kIntEpsilon);
+ }
+}
+
+TEST(SimdUtilsTest, InterleaveUnalignedFloatConvertToInt16Test) {
+ int16_t interleaved[kFullSize];
+ AudioBuffer planar(kNumStereoChannels, kHalfSize);
+ AudioBuffer::Channel& channel_0 = planar[0];
+ AudioBuffer::Channel& channel_1 = planar[1];
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ channel_0[i] = 1.0f;
+ channel_1[i] = -1.0f;
+ }
+
+ InterleaveStereo(kHalfSize, channel_0.begin(), channel_1.begin(),
+ interleaved);
+
+ for (size_t i = 0; i < kFullSize; ++i) {
+ const int16_t value = i % 2 ? kMin : kMax;
+ EXPECT_NEAR(interleaved[i], value, kIntEpsilon);
+ }
+}
+
+TEST(SimdUtilsTest, DeinterleaveAlignedFloatTest) {
+ AudioBuffer interleaved(kNumMonoChannels, kFullSize);
+ AudioBuffer planar(kNumStereoChannels, kHalfSize);
+ AudioBuffer::Channel& channel_0 = planar[0];
+ AudioBuffer::Channel& channel_1 = planar[1];
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kFullSize; ++i) {
+ interleaved[0][i] = (i % 2 == 0) ? 1.0f : 2.0f;
+ }
+
+ // Clear the output buffers.
+ planar.Clear();
+
+ // Test the case where input is aligned.
+ DeinterleaveStereo(kHalfSize, interleaved[0].begin(), channel_0.begin(),
+ channel_1.begin());
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ EXPECT_FLOAT_EQ(channel_0[i], 1.0f);
+ EXPECT_FLOAT_EQ(channel_1[i], 2.0f);
+ }
+}
+
+TEST(SimdUtilsTest, DeinterleaveUnalignedFloatTest) {
+ float interleaved[kFullSize];
+ AudioBuffer planar(kNumStereoChannels, kHalfSize);
+ AudioBuffer::Channel& channel_0 = planar[0];
+ AudioBuffer::Channel& channel_1 = planar[1];
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kFullSize; ++i) {
+ interleaved[i] = (i % 2 == 0) ? 1.0f : 2.0f;
+ }
+
+ // Clear the output buffers.
+ planar.Clear();
+
+ // Test the case where input is unaligned.
+ DeinterleaveStereo(kHalfSize, interleaved, channel_0.begin(),
+ channel_1.begin());
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ EXPECT_FLOAT_EQ(channel_0[i], 1.0f);
+ EXPECT_FLOAT_EQ(channel_1[i], 2.0f);
+ }
+}
+
+TEST(SimdUtilsTest, InterleaveQuadInt16Test) {
+ AudioBuffer::AlignedInt16Vector interleaved(kQuadSize);
+ AudioBuffer::AlignedInt16Vector workspace(kPentSize);
+ AudioBuffer::AlignedInt16Vector channel_0(kHalfSize);
+ AudioBuffer::AlignedInt16Vector channel_1(kHalfSize);
+ AudioBuffer::AlignedInt16Vector channel_2(kHalfSize);
+ AudioBuffer::AlignedInt16Vector channel_3(kHalfSize);
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ channel_0[i] = kOne;
+ channel_1[i] = kTwo;
+ channel_2[i] = kThree;
+ channel_3[i] = kFour;
+ }
+
+ InterleaveQuad(kHalfSize, channel_0.data(), channel_1.data(),
+ channel_2.data(), channel_3.data(), workspace.data(),
+ interleaved.data());
+
+ for (size_t i = 0; i < kQuadSize; ++i) {
+ const int16_t value = static_cast<int16_t>(1 + (i % kNumQuadChannels));
+ EXPECT_FLOAT_EQ(interleaved[i], value);
+ }
+}
+
+TEST(SimdUtilsTest, DeinterleaveQuadInt16Test) {
+ AudioBuffer::AlignedInt16Vector interleaved(kQuadSize);
+ AudioBuffer::AlignedInt16Vector workspace(kPentSize);
+ AudioBuffer::AlignedInt16Vector channel_0(kHalfSize);
+ AudioBuffer::AlignedInt16Vector channel_1(kHalfSize);
+ AudioBuffer::AlignedInt16Vector channel_2(kHalfSize);
+ AudioBuffer::AlignedInt16Vector channel_3(kHalfSize);
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kQuadSize; ++i) {
+ interleaved[i] = static_cast<int16_t>(1 + (i % kNumQuadChannels));
+ }
+
+ // Clear the output buffers.
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ channel_0[i] = static_cast<int16_t>(0);
+ channel_1[i] = static_cast<int16_t>(0);
+ channel_2[i] = static_cast<int16_t>(0);
+ channel_3[i] = static_cast<int16_t>(0);
+ }
+
+ // Test the case where input is aligned.
+ DeinterleaveQuad(kHalfSize, interleaved.data(), workspace.data(),
+ channel_0.data(), channel_1.data(), channel_2.data(),
+ channel_3.data());
+
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ EXPECT_EQ(channel_0[i], kOne);
+ EXPECT_EQ(channel_1[i], kTwo);
+ EXPECT_EQ(channel_2[i], kThree);
+ EXPECT_EQ(channel_3[i], kFour);
+ }
+}
+
+TEST(SimdUtilsTest, InterleaveQuadFloatTest) {
+ AudioBuffer interleaved(kNumMonoChannels, kQuadSize);
+ AudioBuffer workspace(kNumMonoChannels, kPentSize);
+ AudioBuffer planar(kNumQuadChannels, kHalfSize);
+ AudioBuffer::Channel& channel_0 = planar[0];
+ AudioBuffer::Channel& channel_1 = planar[1];
+ AudioBuffer::Channel& channel_2 = planar[2];
+ AudioBuffer::Channel& channel_3 = planar[3];
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ channel_0[i] = 1.0f;
+ channel_1[i] = 2.0f;
+ channel_2[i] = 3.0f;
+ channel_3[i] = 4.0f;
+ }
+
+ InterleaveQuad(kHalfSize, channel_0.begin(), channel_1.begin(),
+ channel_2.begin(), channel_3.begin(), workspace[0].begin(),
+ interleaved[0].begin());
+
+ for (size_t i = 0; i < kQuadSize; ++i) {
+ const float value = static_cast<float>(1 + (i % kNumQuadChannels));
+ EXPECT_FLOAT_EQ(interleaved[0][i], value);
+ }
+}
+
+TEST(SimdUtilsTest, DeinterleaveQuadFloatTest) {
+ AudioBuffer interleaved(kNumMonoChannels, kQuadSize);
+ AudioBuffer workspace(kNumMonoChannels, kPentSize);
+ AudioBuffer planar(kNumQuadChannels, kHalfSize);
+ AudioBuffer::Channel& channel_0 = planar[0];
+ AudioBuffer::Channel& channel_1 = planar[1];
+ AudioBuffer::Channel& channel_2 = planar[2];
+ AudioBuffer::Channel& channel_3 = planar[3];
+
+ // Fill the aligned input buffer.
+ for (size_t i = 0; i < kQuadSize; ++i) {
+ interleaved[0][i] = static_cast<float>(1 + (i % kNumQuadChannels));
+ }
+
+ // Clear the output buffers.
+ planar.Clear();
+
+ // Test the case where input is aligned.
+ DeinterleaveQuad(kHalfSize, interleaved[0].begin(), workspace[0].begin(),
+ channel_0.begin(), channel_1.begin(), channel_2.begin(),
+ channel_3.begin());
+
+ for (size_t i = 0; i < kHalfSize; ++i) {
+ EXPECT_FLOAT_EQ(channel_0[i], 1.0f);
+ EXPECT_FLOAT_EQ(channel_1[i], 2.0f);
+ EXPECT_FLOAT_EQ(channel_2[i], 3.0f);
+ EXPECT_FLOAT_EQ(channel_3[i], 4.0f);
+ }
+}
+
+TEST(SimdUtilsTest, Int16FromFloatTest) {
+ AudioBuffer float_buffer(kNumMonoChannels, kInputSize);
+ float_buffer.Clear();
+
+ AudioBuffer::AlignedInt16Vector int_buffer(kInputSize);
+
+ for (size_t i = 0; i < kInputSize; ++i) {
+ float_buffer[0][i] = kFloatInput[i];
+ }
+
+ Int16FromFloat(kInputSize, &(float_buffer[0][0]), int_buffer.data());
+
+ for (size_t i = 0; i < kInputSize; ++i) {
+ EXPECT_NEAR(int_buffer[i], kIntInput[i], kIntEpsilon);
+ }
+}
+
+TEST(SimdUtilsTest, FloatFromInt16Test) {
+ AudioBuffer float_buffer(kNumMonoChannels, kInputSize);
+ float_buffer.Clear();
+
+ AudioBuffer::AlignedInt16Vector int_buffer(kInputSize);
+
+ for (size_t i = 0; i < kInputSize; ++i) {
+ int_buffer[i] = static_cast<int16_t>(kIntInput[i]);
+ }
+
+ FloatFromInt16(kInputSize, int_buffer.data(), &(float_buffer[0][0]));
+
+ for (size_t i = 0; i < kInputSize; i += 2) {
+ EXPECT_NEAR(float_buffer[0][i], kFloatInput[i], kFloatEpsilon);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/source_parameters.h b/src/3rdparty/resonance-audio/resonance_audio/base/source_parameters.h
new file mode 100644
index 000000000..bf24a424e
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/source_parameters.h
@@ -0,0 +1,101 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_BASE_SOURCE_PARAMETERS_H_
+#define RESONANCE_AUDIO_BASE_SOURCE_PARAMETERS_H_
+
+#include "api/resonance_audio_api.h"
+
+#include "base/constants_and_types.h"
+#include "base/object_transform.h"
+
+namespace vraudio {
+
+// Gain attenuation types for audio sources.
+enum AttenuationType {
+ kInput = 0,
+ kDirect,
+ kReflections,
+ kReverb,
+ kNumAttenuationTypes
+};
+
+// Parameters describing an audio source.
+struct SourceParameters {
+ // Object transform associated with this buffer.
+ ObjectTransform object_transform;
+
+ // Angular spread in degrees. Range [0, 360].
+ float spread_deg = 0.0f;
+
+ // Source gain factor.
+ float gain = 1.0f;
+
+ // Source gain attenuation factors to be calculated per each buffer.
+ float attenuations[kNumAttenuationTypes];
+
+ // Distance attenuation. Value 1 represents no attenuation should be applied,
+ // value 0 will fully attenuate the volume. Range [0, 1].
+ float distance_attenuation = 1.0f;
+
+ // Distance attenuation rolloff model to use.
+ DistanceRolloffModel distance_rolloff_model =
+ DistanceRolloffModel::kLogarithmic;
+
+ // Minimum distance at which to apply distance attenuation.
+ float minimum_distance = 0.0f;
+
+ // Maximum distance at which to apply distance attenuation.
+ float maximum_distance = 500.0f;
+
+ // Alpha weighting of source's directivity pattern. This sets the balance
+ // between the dipole and omnidirectional directivity patterns which combine
+ // to produce the single directivity output value. Range [0, 1], where 0 is
+ // fully omnidirectional and 1 is fully dipole.
+ float directivity_alpha = 0.0f;
+
+ // Source directivity order. Increasing this value increases the directivity
+ // towards the front of the source. Range [1, inf).
+ float directivity_order = 1.0f;
+
+ // Alpha weighting of listener's directivity pattern. This sets the balance
+ // between the dipole and omnidirectional pickup patterns which combine to
+ // produce the single output value. Range [0, 1], where 0 is fully
+ // omnidirectional and 1 is fully dipole.
+ float listener_directivity_alpha = 0.0f;
+
+ // Listener directivity order. Increasing this value increases the directivity
+ // towards the front of the listener. Range [1, inf).
+ float listener_directivity_order = 1.0f;
+
+ // Occlusion intensity. Value 0 represents no occlusion, values greater than 1
+ // represent multiple occlusions. The intensity of each occlusion is scaled
+ // in range [0, 1].
+ float occlusion_intensity = 0.0f;
+
+ // Near field effect gain. Range [0, 9].
+ float near_field_gain = 0.0f;
+
+ // Source gain factor for the room effects.
+ float room_effects_gain = 1.0f;
+
+ // Whether the source uses binaural rendering or stereo panning.
+ bool enable_hrtf = true;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_BASE_SOURCE_PARAMETERS_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle.cc b/src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle.cc
new file mode 100644
index 000000000..4b028979d
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle.cc
@@ -0,0 +1,78 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "base/spherical_angle.h"
+
+#include <cmath>
+
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+SphericalAngle::SphericalAngle(float azimuth, float elevation)
+ : azimuth_(azimuth), elevation_(elevation) {}
+
+SphericalAngle::SphericalAngle() : SphericalAngle(0.0f, 0.0f) {}
+
+SphericalAngle::SphericalAngle(const SphericalAngle& other)
+ : azimuth_(other.azimuth_), elevation_(other.elevation_) {}
+
+SphericalAngle& SphericalAngle::operator=(const SphericalAngle other) {
+ if (&other == this) {
+ return *this;
+ }
+ this->azimuth_ = other.azimuth_;
+ this->elevation_ = other.elevation_;
+ return *this;
+}
+
+SphericalAngle SphericalAngle::FromWorldPosition(
+ const WorldPosition& world_position) {
+ return SphericalAngle(
+ std::atan2(-world_position[0], -world_position[2]),
+ std::atan2(world_position[1],
+ std::sqrt(world_position[0] * world_position[0] +
+ world_position[2] * world_position[2])));
+}
+
+SphericalAngle SphericalAngle::FromDegrees(float azimuth_degrees,
+ float elevation_degrees) {
+ return SphericalAngle(azimuth_degrees * kRadiansFromDegrees,
+ elevation_degrees * kRadiansFromDegrees);
+}
+
+SphericalAngle SphericalAngle::FlipAzimuth() const {
+ return SphericalAngle(-azimuth_, elevation_);
+}
+
+WorldPosition SphericalAngle::GetWorldPositionOnUnitSphere() const {
+ return WorldPosition(-std::cos(elevation_) * std::sin(azimuth_),
+ std::sin(elevation_),
+ -std::cos(elevation_) * std::cos(azimuth_));
+}
+
+SphericalAngle SphericalAngle::Rotate(const WorldRotation& rotation) const {
+ const WorldPosition original_world_position = GetWorldPositionOnUnitSphere();
+ const WorldPosition rotated_world_position =
+ rotation * original_world_position;
+ return FromWorldPosition(rotated_world_position);
+}
+
+bool SphericalAngle::operator==(const SphericalAngle& other) const {
+ return (azimuth_ == other.azimuth_) && (elevation_ == other.elevation_);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle.h b/src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle.h
new file mode 100644
index 000000000..4559f19d1
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle.h
@@ -0,0 +1,87 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_BASE_SPHERICAL_ANGLE_H_
+#define RESONANCE_AUDIO_BASE_SPHERICAL_ANGLE_H_
+
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+// Represents angular position on a sphere in terms of azimuth and elevation.
+class SphericalAngle {
+ public:
+ // Constructs a spherical angle with the given azimuth and elevation.
+ SphericalAngle(float azimuth, float elevation);
+
+ // Constructs a default spherical angle (azimuth = 0, elevation = 0).
+ SphericalAngle();
+
+ // Constructs a spherical angle from a given one.
+ SphericalAngle(const SphericalAngle& other);
+
+ SphericalAngle& operator=(const SphericalAngle other);
+
+ // Returns a spherical angle representation of given |world_position| (World
+ // Space).
+ //
+ // @param world_position 3D position in world space.
+ // @return Spherical angle that represents the |world_position|.
+ static SphericalAngle FromWorldPosition(const WorldPosition& world_position);
+
+ // Returns a spherical angle from azimuth and elevation in degrees.
+ static SphericalAngle FromDegrees(float azimuth_degrees,
+ float elevation_degrees);
+
+ // Returns another spherical angle with the same elevation but the azimuth
+ // sign flipped.
+ //
+ // @return Horizontally flipped version of the spherical angle.
+ SphericalAngle FlipAzimuth() const;
+
+ // Returns the |WorldPosition| coordinates (World Space) on the unit sphere
+ // corresponding to this spherical angle. The transformation is
+ // defined as such:
+ // x = -cos(elevation) * sin(azimuth)
+ // y = sin(elevation)
+ // z = -cos(elevation) * cos(azimuth)
+ //
+ // @return 3D position in world space.
+ WorldPosition GetWorldPositionOnUnitSphere() const;
+
+ // Returns the rotated version of the spherical angle using given
+ // |WorldRotation|.
+ //
+ // @param rotation Rotation to be applied to the spherical angle.
+ // @return Rotated version of the spherical angle.
+ SphericalAngle Rotate(const WorldRotation& rotation) const;
+
+ void set_azimuth(float azimuth) { azimuth_ = azimuth; }
+ void set_elevation(float elevation) { elevation_ = elevation; }
+
+ float azimuth() const { return azimuth_; }
+ float elevation() const { return elevation_; }
+
+ bool operator==(const SphericalAngle& other) const;
+
+ private:
+ float azimuth_;
+ float elevation_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_BASE_SPHERICAL_ANGLE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle_test.cc b/src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle_test.cc
new file mode 100644
index 000000000..49ee16d5d
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/spherical_angle_test.cc
@@ -0,0 +1,122 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "base/spherical_angle.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// Spherical angle to be used in the rotation tests.
+const float kAzimuth = 0.0f;
+const float kElevation = 0.0f;
+const SphericalAngle kSphericalAngle(0.0f, 0.0f);
+
+// Arbitrary rotation angle to be used in the rotation tests.
+const float kRotationAngle = 10.0f * kRadiansFromDegrees;
+
+// Tests that the GetWorldPositionOnUnitSphere() and FromWorldPosition()
+// functions act as perfect inverses of one another for angles defined on the
+// unit sphere (in this case the vraudio cube speaker layout).
+TEST(SphericalAngleTest, CartesianToSphericalAndBackTest) {
+ // Azimuth and elevation angles of the cubic spherical loudspeaker array.
+ const std::vector<SphericalAngle> kCubeAngles = {
+ SphericalAngle::FromDegrees(45.0f, 35.26f),
+ SphericalAngle::FromDegrees(-45.0f, 35.26f),
+ SphericalAngle::FromDegrees(-135.0f, 35.26f),
+ SphericalAngle::FromDegrees(135.0f, 35.26f),
+ SphericalAngle::FromDegrees(45.0f, -35.26f),
+ SphericalAngle::FromDegrees(-45.0f, -35.26f),
+ SphericalAngle::FromDegrees(-135.0f, -35.26f),
+ SphericalAngle::FromDegrees(135.0f, -35.26f)};
+
+ for (size_t i = 0; i < kCubeAngles.size(); ++i) {
+ const WorldPosition position =
+ kCubeAngles[i].GetWorldPositionOnUnitSphere();
+ const SphericalAngle angle = SphericalAngle::FromWorldPosition(position);
+ EXPECT_EQ(kCubeAngles[i].azimuth(), angle.azimuth());
+ EXPECT_EQ(kCubeAngles[i].elevation(), angle.elevation());
+ }
+}
+
+// Tests the horizontal angle flip across the median plane.
+TEST(SphericalAngleTest, FlipTest) {
+ const std::vector<SphericalAngle> kTestAngles = {
+ SphericalAngle::FromDegrees(45.0f, 35.26f),
+ SphericalAngle::FromDegrees(-15.0f, -10.0f)};
+
+ for (size_t i = 0; i < kTestAngles.size(); ++i) {
+ SphericalAngle flipped_spherical_angle = kTestAngles[i].FlipAzimuth();
+
+ // Check if the flipped spherical anglee is correct.
+ EXPECT_NEAR(kTestAngles[i].azimuth(), -flipped_spherical_angle.azimuth(),
+ kEpsilonFloat);
+ EXPECT_NEAR((kTestAngles[i].elevation()),
+ flipped_spherical_angle.elevation(), kEpsilonFloat);
+ }
+}
+
+// Tests that the Rotate() function correctly rotates the spherical angle
+// against the x axis (right facing).
+TEST(SphericalAngleTest, RotateXTest) {
+ const WorldPosition kAxis = {1.0f, 0.0f, 0.0f};
+ const WorldRotation kRotation(AngleAxisf(kRotationAngle, kAxis));
+ // Rotate against the x axis (right facing).
+
+ const SphericalAngle kXrotatedSphericalAngle =
+ kSphericalAngle.Rotate(kRotation);
+
+ // Check if the rotated spherical angle is correct.
+ EXPECT_NEAR(kAzimuth, kXrotatedSphericalAngle.azimuth(), kEpsilonFloat);
+ EXPECT_NEAR((kElevation + kRotationAngle),
+ kXrotatedSphericalAngle.elevation(), kEpsilonFloat);
+}
+
+// Tests that the Rotate() function correctly rotates the spherical angle
+// against the y axis (upward facing).
+TEST(SphericalAngleTest, RotateYTest) {
+ const WorldPosition kAxis(0.0f, 1.0f, 0.0f);
+ const WorldRotation kRotation(AngleAxisf(kRotationAngle, kAxis));
+ // Rotate against the y axis (upward facing).
+ const SphericalAngle kYrotatedSphericalAngle =
+ kSphericalAngle.Rotate(kRotation);
+
+ // Check if the rotated spherical angle is correct.
+ EXPECT_NEAR((kAzimuth + kRotationAngle), kYrotatedSphericalAngle.azimuth(),
+ kEpsilonFloat);
+ EXPECT_NEAR(kElevation, kYrotatedSphericalAngle.elevation(), kEpsilonFloat);
+}
+
+// Tests that the Rotate() function correctly rotates the spherical angle
+// against the Z axis (forward facing).
+TEST(SphericalAngleTest, RotateZTest) {
+ const WorldPosition kAxis = {0.0f, 0.0f, 1.0f};
+ const WorldRotation kRotation(AngleAxisf(kRotationAngle, kAxis));
+ // Rotate against the z axis (forward facing).
+ const SphericalAngle kZrotatedSphericalAngle =
+ kSphericalAngle.Rotate(kRotation);
+
+ // Check if the rotated spherical angle is correct.
+ EXPECT_NEAR(kAzimuth, kZrotatedSphericalAngle.azimuth(), kEpsilonFloat);
+ EXPECT_NEAR(kElevation, kZrotatedSphericalAngle.elevation(), kEpsilonFloat);
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/base/unique_ptr_wrapper.h b/src/3rdparty/resonance-audio/resonance_audio/base/unique_ptr_wrapper.h
new file mode 100644
index 000000000..b8e848135
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/base/unique_ptr_wrapper.h
@@ -0,0 +1,33 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_BASE_UNIQUE_PTR_WRAPPER_H_
+#define RESONANCE_AUDIO_BASE_UNIQUE_PTR_WRAPPER_H_
+
+#include <memory>
+
+// Wrapper around std::unique_ptr to enable the binding of unique_ptr buffers to
+// std:function and/or lambda function.
+template <typename T>
+struct UniquePtrWrapper {
+ UniquePtrWrapper(const UniquePtrWrapper& other) : ptr(std::move(other.ptr)) {}
+ UniquePtrWrapper(UniquePtrWrapper&& other) : ptr(std::move(other.ptr)) {}
+ explicit UniquePtrWrapper(std::unique_ptr<T> buffer)
+ : ptr(std::move(buffer)) {}
+ mutable std::unique_ptr<T> ptr;
+};
+
+#endif // RESONANCE_AUDIO_BASE_UNIQUE_PTR_WRAPPER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/config/global_config.h b/src/3rdparty/resonance-audio/resonance_audio/config/global_config.h
new file mode 100644
index 000000000..4af629e89
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/config/global_config.h
@@ -0,0 +1,37 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_CONFIG_GLOBAL_CONFIG_H_
+#define RESONANCE_AUDIO_CONFIG_GLOBAL_CONFIG_H_
+
+#include "graph/graph_manager_config.h"
+
+namespace vraudio {
+
+inline GraphManagerConfig GlobalConfig() {
+ GraphManagerConfig config;
+ config.configuration_name = "Global Config";
+
+ config.max_ambisonic_order = 3;
+ config.sh_hrir_filenames = {{1, "WAV/Subject_002/SH/sh_hrir_order_1.wav"},
+ {2, "WAV/Subject_002/SH/sh_hrir_order_2.wav"},
+ {3, "WAV/Subject_002/SH/sh_hrir_order_3.wav"}};
+ return config;
+}
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_CONFIG_GLOBAL_CONFIG_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/config/source_config.cc b/src/3rdparty/resonance-audio/resonance_audio/config/source_config.cc
new file mode 100644
index 000000000..a8e8c75f7
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/config/source_config.cc
@@ -0,0 +1,76 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "config/source_config.h"
+
+namespace vraudio {
+
+SourceGraphConfig StereoPanningConfig() {
+ SourceGraphConfig config;
+ config.configuration_name = "Stereo Panning";
+
+ config.ambisonic_order = 1;
+ config.enable_hrtf = false;
+ config.enable_direct_rendering = true;
+
+ return config;
+}
+
+SourceGraphConfig BinauralLowQualityConfig() {
+ SourceGraphConfig config;
+ config.configuration_name = "Binaural Low Quality";
+
+ config.ambisonic_order = 1;
+ config.enable_hrtf = true;
+ config.enable_direct_rendering = true;
+
+ return config;
+}
+
+SourceGraphConfig BinauralMediumQualityConfig() {
+ SourceGraphConfig config;
+ config.configuration_name = "Binaural Medium Quality";
+
+ config.ambisonic_order = 2;
+ config.enable_hrtf = true;
+ config.enable_direct_rendering = true;
+
+ return config;
+}
+
+SourceGraphConfig BinauralHighQualityConfig() {
+ SourceGraphConfig config;
+ config.configuration_name = "Binaural High Quality";
+
+ config.ambisonic_order = 3;
+ config.enable_hrtf = true;
+ config.enable_direct_rendering = true;
+
+ return config;
+}
+
+SourceGraphConfig RoomEffectsOnlyConfig() {
+ SourceGraphConfig config;
+ config.configuration_name = "Room Effects Only";
+
+ config.ambisonic_order = 1;
+ config.enable_hrtf = false;
+ config.enable_direct_rendering = false;
+
+ return config;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/config/source_config.h b/src/3rdparty/resonance-audio/resonance_audio/config/source_config.h
new file mode 100644
index 000000000..21b71fc0b
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/config/source_config.h
@@ -0,0 +1,32 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_CONFIG_SOURCE_CONFIG_H_
+#define RESONANCE_AUDIO_CONFIG_SOURCE_CONFIG_H_
+
+#include "graph/source_graph_config.h"
+
+namespace vraudio {
+
+SourceGraphConfig StereoPanningConfig();
+SourceGraphConfig BinauralLowQualityConfig();
+SourceGraphConfig BinauralMediumQualityConfig();
+SourceGraphConfig BinauralHighQualityConfig();
+SourceGraphConfig RoomEffectsOnlyConfig();
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_CONFIG_SOURCE_CONFIG_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter.cc
new file mode 100644
index 000000000..ca489cce3
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter.cc
@@ -0,0 +1,149 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/biquad_filter.h"
+
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// This value has been chosen empirically after a series of experiments
+// performed by kellyi@ and alperg@. It was found that crossfading over 256
+// samples yielded no audible glitching artefacts and an acceptable amount of
+// delay.
+
+const size_t kIdealSamplesToIterate = 256U;
+
+} // namespace
+
+BiquadFilter::BiquadFilter(const BiquadCoefficients& coefficients,
+ size_t frames_per_buffer)
+ : biquad_delay_line_({{0.0f, 0.0f}}),
+ interpolate_flag_(false),
+ interpolate_counter_(0),
+ old_delay_line_({{0.0f, 0.0f}}),
+ samples_to_iterate_over_(frames_per_buffer > kIdealSamplesToIterate
+ ? kIdealSamplesToIterate
+ : frames_per_buffer),
+ fade_scale_(1.0f / static_cast<float>(samples_to_iterate_over_)),
+ old_coefficients_() {
+ DCHECK_GT(frames_per_buffer, 0U);
+ CHECK_GT(coefficients_.a[0], kEpsilonFloat);
+ SetCoefficients(coefficients);
+}
+
+void BiquadFilter::SetCoefficients(const BiquadCoefficients& coefficients) {
+ coefficients_ = coefficients;
+ // Normalize the coefficients for use in the |FilterSample()| function.
+ coefficients_.a[1] /= coefficients_.a[0];
+ coefficients_.a[2] /= coefficients_.a[0];
+ coefficients_.b[0] /= coefficients_.a[0];
+ coefficients_.b[1] /= coefficients_.a[0];
+ coefficients_.b[2] /= coefficients_.a[0];
+}
+
+void BiquadFilter::Filter(const AudioBuffer::Channel& input_channel,
+ AudioBuffer::Channel* output_channel) {
+ DCHECK(output_channel);
+ DCHECK_EQ(input_channel.size(), output_channel->size());
+
+ if (interpolate_flag_) {
+ for (size_t frame = 0; frame < input_channel.size(); ++frame) {
+ // Biquad coefficients are updated here.
+ UpdateInterpolate();
+ (*output_channel)[frame] = InterpolateFilterSample(input_channel[frame]);
+ }
+ } else {
+ for (size_t frame = 0; frame < input_channel.size(); ++frame) {
+ (*output_channel)[frame] = FilterSample(
+ input_channel[frame], &biquad_delay_line_, coefficients_);
+ }
+ }
+}
+
+void BiquadFilter::InterpolateToCoefficients(
+ const BiquadCoefficients& coefficients) {
+ interpolate_flag_ = true;
+ // Reset the counter so we perform the update over samples_to_iterate_over_
+ // samples.
+ interpolate_counter_ = 0;
+ // Store the old coefficients, update the new ones and transfer data between
+ // delay lines.
+ old_coefficients_ = coefficients_;
+ coefficients_ = coefficients;
+ old_delay_line_ = biquad_delay_line_;
+}
+
+void BiquadFilter::Clear() {
+ biquad_delay_line_ = {{0.0f, 0.0f}};
+ interpolate_flag_ = false;
+ interpolate_counter_ = 0;
+ old_delay_line_ = {{0.0f, 0.0f}};
+}
+
+float BiquadFilter::FilterSample(float input, std::array<float, 2>* delay_line,
+ const BiquadCoefficients& coefficients) {
+ // Using A Direct Form II Implementation Difference equation:
+ // Source: Digital Signal Processing Principles Algorithms and Applications
+ // Fourth Edition. John G. Prolakis and Dimitris G. Manolakis - Chapter 9
+ // w[n] = x[n] - (a1/a0)*w[n-1] - (a2/a0)*w[n-2]
+ // y(n) = (b0/a0)*w[n] + (b1/a0)*w[n-1] + (b2/a0)*w[n-2]
+ // where x[n] is input, w[n] is storage and y[n] is output.
+ // The division by a0 has been performed in Biquad::SetCoefficients.
+
+ // define a temporary storage value w.
+ const float w = input - (*delay_line)[0] * coefficients.a[1] -
+ (*delay_line)[1] * coefficients.a[2];
+
+ // Do second half of the calculation to generate output.
+ const float output = w * coefficients.b[0] +
+ (*delay_line)[0] * coefficients.b[1] +
+ (*delay_line)[1] * coefficients.b[2];
+
+ // Update delay line.
+ (*delay_line)[1] = (*delay_line)[0];
+ (*delay_line)[0] = w;
+
+ return output;
+}
+
+void BiquadFilter::UpdateInterpolate() {
+ if (++interpolate_counter_ > samples_to_iterate_over_) {
+ interpolate_flag_ = false;
+ }
+}
+
+float BiquadFilter::InterpolateFilterSample(float input) {
+ const float new_filter_output =
+ FilterSample(input, &biquad_delay_line_, coefficients_);
+
+ if (!interpolate_flag_) {
+ return new_filter_output;
+ } else {
+ // Process the "old" filter values.
+ const float old_filter_output =
+ FilterSample(input, &old_delay_line_, old_coefficients_);
+ // A linear crossfade between old_filter_output and new_filter_output,
+ // stepsize is fade_scale_.
+ const float weight = fade_scale_ * static_cast<float>(interpolate_counter_);
+ const float sample_diff = new_filter_output - old_filter_output;
+ return weight * sample_diff + old_filter_output;
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter.h
new file mode 100644
index 000000000..2e05c3276
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter.h
@@ -0,0 +1,137 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_BIQUAD_FILTER_H_
+#define RESONANCE_AUDIO_DSP_BIQUAD_FILTER_H_
+
+#include <array>
+
+#include "base/audio_buffer.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+// Set of transfer function coefficients.
+struct BiquadCoefficients {
+ // Constructor takes as its arguments 6 floats representing the transfer
+ // function coefficients of a biquad filter.
+ BiquadCoefficients(float a0, float a1, float a2, float b0, float b1, float b2)
+ : a({{a0, a1, a2}}), b({{b0, b1, b2}}) {}
+
+ // Default constructor that sets a0 and b0 == 1 so that if the coefficients
+ // are used, the filter is stable and has no effect on input. i.e. input
+ // appears to just pass through.
+ BiquadCoefficients() : BiquadCoefficients(1.0, 0.0, 0.0, 1.0, 0.0, 0.0) {}
+
+ // The denominator quadratic coefficients.
+ std::array<float, 3> a;
+ // The numerator quadratic coefficients.
+ std::array<float, 3> b;
+};
+
+// Class representing a biquad filter as its transfer function coefficients.
+// This class also performs filtering.
+class BiquadFilter {
+ public:
+ // Constructs a BiquadFilter using a BiquadCoefficients struct.
+ //
+ // @param coefficients A BiquadCoefficients to set the internal
+ // |coefficients_|.
+ // @param frames_per_buffer The number of frames in each data buffer to be
+ // processed. This is used to set the number of samples to iterate over
+ // during a change of filter state.
+ BiquadFilter(const BiquadCoefficients& coefficients,
+ size_t frames_per_buffer);
+
+ // Filter method for use with AudioBuffer::Channel.
+ //
+ // @param input_channel An AudioBuffer::Channel of input.
+ // @param output_channel A pointer to an AudioBuffer::Channel for output.
+ void Filter(const AudioBuffer::Channel& input_channel,
+ AudioBuffer::Channel* output_channel);
+
+ // Sets the fiter's coefficents to those passed, with all
+ // coefficients bar a0 scaled by 1/a0.
+ //
+ // @param coefficients A set of BiquadCoefficients.
+ void SetCoefficients(const BiquadCoefficients& coefficients);
+
+ // Sets the target coefficients to be interpolated.
+ //
+ // @param coefficents The BiquadCoefficients we wish to interpolate to over
+ // samples_to_iterate_over_ samples of the next input buffer.
+ void InterpolateToCoefficients(const BiquadCoefficients& coefficients);
+
+ // Clears the internal state of the filter, except for coefficients.
+ void Clear();
+
+ private:
+ friend class BiquadFilterInterpolateTest;
+
+ // Filters a single sample of input.
+ //
+ // @param input A single input sample from a Planar or Interleaved buffer.
+ // @param delay_line The delay_line to use (important for interpolation).
+ // @param coefficients The biquad coeffients for use in filtering.
+ // @return An output value to be placed in a Planar or Interleaved buffer.
+ float FilterSample(float input, std::array<float, 2>* delay_line,
+ const BiquadCoefficients& coefficients);
+
+ // If InterpolateToState() has been called to assign new filter coefficients,
+ // this function will be called samples_to_iterate_over_ times within the next
+ // call of the Filter() function to slowly transition to the new coefficients
+ // which were passed to InterpolateToState() previously.
+ void UpdateInterpolate();
+
+ // Filters a single sample of input while transitioning between coefficients.
+ // Performs a linear crossfade over samples_to_iterate_over_ samples.
+ //
+ // @param input A single input sample from a Planar or Interleaved buffer.
+ // @return Output value to be placed in an audio buffer.
+ float InterpolateFilterSample(float input);
+
+ // Stores the memory state of the biquad
+ std::array<float, 2> biquad_delay_line_;
+
+ // Flag that denotes whether or not we are transitioning to another set of
+ // coefficients via interpolation.
+ bool interpolate_flag_;
+
+ // Counter that denotes how far we are into transitioning to another set of
+ // coefficients via interpolation.
+ size_t interpolate_counter_;
+
+ // Stores the memory state of the biquad.
+ std::array<float, 2> old_delay_line_;
+
+ // Number of samples over which to apply the filter coefficients.
+ size_t samples_to_iterate_over_;
+
+ // Value used to crossfade between filter outputs.
+ float fade_scale_;
+
+ // A set of coefficient which are updated as we interpolate between filter
+ // coefficients.
+ BiquadCoefficients old_coefficients_;
+
+ // Represents and maintains the state of the biquad filter in terms of its
+ // transfer function coefficients.
+ BiquadCoefficients coefficients_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_BIQUAD_FILTER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter_test.cc
new file mode 100644
index 000000000..c8ac6de78
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/biquad_filter_test.cc
@@ -0,0 +1,303 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/biquad_filter.h"
+
+#include <algorithm>
+#include <cmath>
+#include <numeric>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+const size_t kTestInputDataSize = 16;
+
+const float kTestFilterCoefficients[] = {1.0f, 0.0f, 0.0, 1.0f, 0.1f, 0.1f};
+
+const size_t kIdealSamplesToIterate = 256;
+
+// For use with std::transform in the StabilityTest.
+float operator_abs(float f) { return std::abs(f); }
+
+} // namespace
+
+// Tests that the filtering of a mono signal produces the correct output.
+TEST(BiquadFilterTest, FilterTest) {
+ const size_t kNumIterations = 1;
+
+ const BiquadCoefficients kCoefficients(
+ kTestFilterCoefficients[0], kTestFilterCoefficients[1],
+ kTestFilterCoefficients[2], kTestFilterCoefficients[3],
+ kTestFilterCoefficients[4], kTestFilterCoefficients[5]);
+
+ AudioBuffer input(kNumMonoChannels, kTestInputDataSize);
+ AudioBuffer output(kNumMonoChannels, kTestInputDataSize);
+ // Set the input AudioBuffer to a Kronecker delta.
+ input.Clear();
+ input[0][0] = 1.0f;
+
+ // This vector will accumulate the output from the filter over time (Only
+ // works with mono channel).
+ std::vector<float> output_accumulator;
+ output_accumulator.reserve(kNumIterations * kTestInputDataSize);
+
+ // Create a biquad filter initialized with transfer function coefficients.
+ BiquadFilter biquad(kCoefficients, kTestInputDataSize);
+
+ // Perform filtering.
+ for (size_t i = 0; i < kNumIterations; ++i) {
+ biquad.Filter(input[0], &output[0]);
+ output_accumulator.insert(output_accumulator.end(), output[0].begin(),
+ output[0].end());
+ }
+
+ // Since the denominator of the biquad coefficients is [1 0 0] we can expect
+ // the impulse response to be equal to the numerator.
+ for (size_t i = 0; i < output_accumulator.size(); ++i) {
+ if (i < 3U) {
+ EXPECT_NEAR(kTestFilterCoefficients[3 + i], output_accumulator[i],
+ kEpsilonFloat);
+ } else {
+ EXPECT_EQ(0.0f, output_accumulator[i]);
+ }
+ }
+}
+
+// Tests that the filtering of a mono signal produces the correct output.
+TEST(BiquadFilterTest, InplaceFilterTest) {
+ const size_t kNumIterations = 1;
+
+ const BiquadCoefficients kCoefficients(
+ kTestFilterCoefficients[0], kTestFilterCoefficients[1],
+ kTestFilterCoefficients[2], kTestFilterCoefficients[3],
+ kTestFilterCoefficients[4], kTestFilterCoefficients[5]);
+
+ AudioBuffer input(kNumMonoChannels, kTestInputDataSize);
+ // Set the input AudioBuffer to a Kronecker delta.
+ input.Clear();
+ input[0][0] = 1.0f;
+
+ // This vector will accumulate the output from the filter over time (Only
+ // works with mono channel).
+ std::vector<float> output_accumulator;
+ output_accumulator.reserve(kTestInputDataSize);
+
+ // Create a biquad filter initialized with transfer function coefficients.
+ BiquadFilter biquad(kCoefficients, kTestInputDataSize);
+
+ // Perform inplace filtering of |input| vector.
+ for (size_t i = 0; i < kNumIterations; ++i) {
+ biquad.Filter(input[0], &input[0]);
+ output_accumulator.insert(output_accumulator.end(), input[0].begin(),
+ input[0].end());
+ }
+
+ // Since the denominator of the biquad coefficients is [1 0 0] we can expect
+ // the impulse response to be equal to the numerator.
+ for (size_t i = 0; i < output_accumulator.size(); ++i) {
+ if (i < 3) {
+ EXPECT_NEAR(kTestFilterCoefficients[3 + i], output_accumulator[i],
+ kEpsilonFloat);
+ } else {
+ EXPECT_EQ(0.0f, output_accumulator[i]);
+ }
+ }
+}
+
+// Tests whether the interpolation stops after kIdealSamplesToIterate samples,
+// given a long enough buffer.
+TEST(BiquadFilterTest, InterpolationStopsTest) {
+ const size_t kFramesPerBuffer = 512;
+
+ std::vector<std::vector<float>> planar_input_data(
+ kNumMonoChannels, std::vector<float>(kFramesPerBuffer));
+ planar_input_data[0][0] = 1.0f;
+ planar_input_data[0][256] = 1.0f;
+
+ AudioBuffer input_planar(kNumMonoChannels, kFramesPerBuffer);
+ AudioBuffer output_planar(kNumMonoChannels, kFramesPerBuffer);
+ input_planar = planar_input_data;
+
+ // Instantiate Biquad for planar data. The impulse response of the default is:
+ // 1, 0, 0, ......
+ BiquadFilter biquad(BiquadCoefficients(), kFramesPerBuffer);
+
+ // Coefficients we wish to interpolate to. The impulse response of this filter
+ // is: 1, 0, 1, ......
+ const BiquadCoefficients kNextCoefficients = {1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 1.0f};
+
+ biquad.InterpolateToCoefficients(kNextCoefficients);
+ biquad.Filter(input_planar[0], &output_planar[0]);
+
+ // Based on the known impulse responses we can see that if elements 256, 257
+ // and 258 have the values 1, 0, 1, then only the new filter coefficients are
+ // contributing and we have stopped crossfading. Note: The value of 256 here
+ // comes from kIdealSamplesToIterate defined in biquad_filter.cc
+ EXPECT_EQ(1.0f, output_planar[0][kIdealSamplesToIterate]);
+ EXPECT_EQ(0.0f, output_planar[0][kIdealSamplesToIterate + 1]);
+ EXPECT_EQ(1.0f, output_planar[0][kIdealSamplesToIterate + 2]);
+}
+
+// Tests whether the |BiquadFilter| remains stable when its z-domain poles lie
+// very close to the unit circle.
+TEST(BiquadFilterTest, StabilityTest) {
+ static const size_t kBufferSize = 1024;
+ const size_t kIterations = 200;
+ // The following filter was designed in MATLAB with a very slow decay rate.
+ // (There are both poles and zeros with magnitude 0.999). Even 200'000 samples
+ // after the initial impulse the response will have only died away, in an
+ // oscillating manner, to ~1/700 of its peak value.
+ static const BiquadCoefficients kHighQCoefficients(
+ 1.0f, -0.907804951302441f, 0.999869108872718f, 15279.8745150008f, 0.0f,
+ -15279.8745150008f);
+ BiquadFilter biquad(kHighQCoefficients, kBufferSize);
+
+ AudioBuffer input(kNumMonoChannels, kBufferSize);
+ AudioBuffer output(kNumMonoChannels, kBufferSize);
+ // Set the input AudioBuffer to a Kronecker delta.
+ input.Clear();
+ input[0][0] = 1.0f;
+
+ // This vector will accumulate the output from the filter over time (Only
+ // works with mono channel).
+ std::vector<float> output_accumulator;
+ output_accumulator.reserve(kBufferSize * kIterations);
+
+ // Filter once with the Kronecker delta.
+ biquad.Filter(input[0], &output[0]);
+ output_accumulator.insert(output_accumulator.end(), output[0].begin(),
+ output[0].end());
+
+ // Perform filtering with all zero input.
+ input[0][0] = 0.0f;
+ for (size_t i = 1; i < kIterations; ++i) {
+ biquad.Filter(input[0], &output[0]);
+ output_accumulator.insert(output_accumulator.end(), output[0].begin(),
+ output[0].end());
+ }
+
+ // Test that the signal is decaying over time (i.e. filter is stable).
+ for (size_t i = 0; i < output_accumulator.size() - kBufferSize;
+ i += kBufferSize) {
+ std::vector<float> absolute_first_half(kBufferSize / 2);
+ std::transform(output_accumulator.begin() + i,
+ output_accumulator.begin() + i + kBufferSize / 2,
+ absolute_first_half.begin(), operator_abs);
+ std::vector<float> absolute_second_half(kBufferSize / 2);
+ std::transform(output_accumulator.begin() + 1 + i + kBufferSize / 2,
+ output_accumulator.begin() + i + kBufferSize,
+ absolute_second_half.begin(), operator_abs);
+ const float sum_first_half = std::accumulate(
+ absolute_first_half.begin(), absolute_first_half.end(), 0.0f);
+ const float sum_second_half = std::accumulate(
+ absolute_second_half.begin(), absolute_second_half.end(), 0.0f);
+ EXPECT_LT(sum_second_half, sum_first_half);
+ }
+}
+
+class BiquadFilterInterpolateTest : public ::testing::Test {
+ protected:
+ BiquadFilterInterpolateTest() {}
+ // Virtual methods from ::testing::Test
+ ~BiquadFilterInterpolateTest() override {}
+ void SetUp() override {}
+ void TearDown() override {}
+
+ // Returns true if |filter|'s internal coefficients are equal to those of
+ // |expected_coefficients| after scaling by a0.
+ bool TestInternalCoefficients(
+ BiquadFilter* filter, const BiquadCoefficients& expected_coefficients) {
+ bool return_value = true;
+ return_value &=
+ expected_coefficients.a[0] - filter->coefficients_.a[0] < kEpsilonFloat;
+
+ // From this point we must take account of the scaling by 1/a0.
+ const float a0 = filter->coefficients_.a[0];
+ return_value &=
+ expected_coefficients.b[0] - filter->coefficients_.b[0] * a0 <
+ kEpsilonFloat;
+ for (int i = 1; i < 3; ++i) {
+ return_value &=
+ expected_coefficients.b[i] - filter->coefficients_.b[i] * a0 <
+ kEpsilonFloat;
+ return_value &=
+ expected_coefficients.a[i] - filter->coefficients_.a[i] * a0 <
+ kEpsilonFloat;
+ }
+ return return_value;
+ }
+};
+
+// Tests whether updating the filter's coefficients with the
+// InterpolateToCoefficients reaches the correct coefficients after filtering a
+// block of data and whether the samples_to_iterate_over_ value is set
+// correctly.
+TEST_F(BiquadFilterInterpolateTest, InterpolatedUpdateTest) {
+ const size_t kFramesPerBuffer = 8;
+
+ const std::vector<std::vector<float>> kPlanarInputData = {
+ {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}};
+
+ const std::vector<float> kExpectedOutputAfterChange = {
+ 8.0f, 10.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f};
+
+ // Default constructor sets a = {1.0, 0.0, 0.0} and b = {1.0, 0.0, 0.0}.
+ const BiquadCoefficients kCoefficients;
+
+ // Create input and output AudioBuffers.
+ AudioBuffer input_planar(kNumMonoChannels, kFramesPerBuffer);
+ AudioBuffer output_planar(kNumMonoChannels, kFramesPerBuffer);
+ input_planar = kPlanarInputData;
+
+ // Instantiate Biquad for planar data.
+ BiquadFilter biquad(kCoefficients, kFramesPerBuffer);
+
+ // Perform filtering on kNumMonoChannels interleaved.
+ biquad.Filter(input_planar[0], &output_planar[0]);
+
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ EXPECT_NEAR(output_planar[0][i], kPlanarInputData[0][i], kEpsilonFloat);
+ }
+
+ // Coefficients we wish to interpolate to.
+ static const BiquadCoefficients kNextCoefficients = {1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 1.0f};
+
+ biquad.InterpolateToCoefficients(kNextCoefficients);
+
+ // Filter once to transition and once to flush out the state.
+ biquad.Filter(input_planar[0], &output_planar[0]);
+ biquad.Filter(input_planar[0], &output_planar[0]);
+
+ // Now the output should be just from the new state.
+ biquad.Filter(input_planar[0], &output_planar[0]);
+
+ // Now check that we transitioned properly, i.e. the output is as expected.
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ EXPECT_NEAR(output_planar[0][i], kExpectedOutputAfterChange[i],
+ kEpsilonFloat);
+ }
+
+ // Now check that we have the new coefficients.
+ EXPECT_TRUE(TestInternalCoefficients(&biquad, kNextCoefficients));
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter.cc
new file mode 100644
index 000000000..375001bac
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter.cc
@@ -0,0 +1,45 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/channel_converter.h"
+
+#include <cmath>
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/simd_utils.h"
+
+namespace vraudio {
+
+void ConvertStereoFromMono(const AudioBuffer& input, AudioBuffer* output) {
+ DCHECK(output);
+ DCHECK_EQ(input.num_channels(), kNumMonoChannels);
+ DCHECK_EQ(output->num_channels(), kNumStereoChannels);
+ DCHECK_EQ(input.num_frames(), output->num_frames());
+ StereoFromMonoSimd(input.num_frames(), &input[0][0], &(*output)[0][0],
+ &(*output)[1][0]);
+}
+
+void ConvertMonoFromStereo(const AudioBuffer& input, AudioBuffer* output) {
+ DCHECK(output);
+ DCHECK_EQ(input.num_channels(), kNumStereoChannels);
+ DCHECK_EQ(output->num_channels(), kNumMonoChannels);
+ DCHECK_EQ(input.num_frames(), output->num_frames());
+ MonoFromStereoSimd(input.num_frames(), &input[0][0], &input[1][0],
+ &(*output)[0][0]);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter.h
new file mode 100644
index 000000000..26d825ae4
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter.h
@@ -0,0 +1,40 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_CHANNEL_CONVERTER_H_
+#define RESONANCE_AUDIO_DSP_CHANNEL_CONVERTER_H_
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Converts a mono |input| buffer to a stereo |output| buffer by preserving the
+// signal energy.
+//
+// @param input Mono input buffer.
+// @param output Pointer to a stereo output buffer.
+void ConvertStereoFromMono(const AudioBuffer& input, AudioBuffer* output);
+
+// Converts a stereo |input| buffer to a mono |output| buffer by preserving the
+// signal energy.
+//
+// @param input Stereo input buffer.
+// @param output Pointer to a mono output buffer.
+void ConvertMonoFromStereo(const AudioBuffer& input, AudioBuffer* output);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_CHANNEL_CONVERTER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter_test.cc
new file mode 100644
index 000000000..3d6928ad5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/channel_converter_test.cc
@@ -0,0 +1,80 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/channel_converter.h"
+
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// Number of frames for test buffers.
+const size_t kNumFrames = 5;
+
+// Tests that the correct stereo output buffer is obtained from the converter
+// given an arbitrary mono input buffer.
+TEST(ChannelConverterTest, ConvertStereoFromMonoTest) {
+ const std::vector<std::vector<float>> kMonoInput = {
+ {1.0f, 2.0f, 3.0f, 4.0f, 5.0f}};
+ const std::vector<std::vector<float>> kExpectedStereoOutput = {
+ {0.707107f, 1.414214f, 2.121320f, 2.828427f, 3.535534f},
+ {0.707107f, 1.414214f, 2.121320f, 2.828427f, 3.535534f}};
+
+ // Initialize the test buffers.
+ AudioBuffer mono_input(kNumMonoChannels, kNumFrames);
+ mono_input = kMonoInput;
+ AudioBuffer stereo_output(kNumStereoChannels, kNumFrames);
+ // Process the input buffer.
+ ConvertStereoFromMono(mono_input, &stereo_output);
+ // Compare the output buffer against the expected output.
+ for (size_t channel = 0; channel < kNumStereoChannels; ++channel) {
+ for (size_t frame = 0; frame < kNumFrames; ++frame) {
+ EXPECT_NEAR(stereo_output[channel][frame],
+ kExpectedStereoOutput[channel][frame], kEpsilonFloat);
+ }
+ }
+}
+
+// Tests that the correct mono output buffer is obtained from the converter
+// given an arbitrary stereo input buffer.
+TEST(ChannelConverterTest, ConvertMonoFromStereoTest) {
+ const std::vector<std::vector<float>> kStereoInput = {
+ {0.707107f, 1.414214f, 2.121320f, 2.828427f, 3.535534f},
+ {0.707107f, 1.414214f, 2.121320f, 2.828427f, 3.535534f}};
+
+ const std::vector<std::vector<float>> kExpectedMonoOutput = {
+ {1.0f, 2.0f, 3.0f, 4.0f, 5.0f}};
+
+ // Initialize the test buffers.
+ AudioBuffer stereo_input(kNumStereoChannels, kNumFrames);
+ stereo_input = kStereoInput;
+ AudioBuffer mono_output(kNumMonoChannels, kNumFrames);
+ // Process the input buffer.
+ ConvertMonoFromStereo(stereo_input, &mono_output);
+ // Compare the output buffer against the expected output.
+ for (size_t frame = 0; frame < kNumFrames; ++frame) {
+ EXPECT_NEAR(mono_output[0][frame], kExpectedMonoOutput[0][frame],
+ kEpsilonFloat);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer.cc
new file mode 100644
index 000000000..5ef2be2c9
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer.cc
@@ -0,0 +1,120 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/circular_buffer.h"
+
+#include <algorithm>
+
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+CircularBuffer::CircularBuffer(size_t buffer_length, size_t num_input_frames,
+ size_t num_output_frames)
+ : num_input_frames_(num_input_frames),
+ num_output_frames_(num_output_frames),
+ buffer_(kNumMonoChannels, buffer_length),
+ write_cursor_(0),
+ read_cursor_(0),
+ num_valid_frames_(0) {
+ CHECK_GE(buffer_length, num_input_frames + num_output_frames);
+}
+
+bool CircularBuffer::InsertBuffer(const AudioBuffer::Channel& input) {
+ DCHECK_EQ(input.size(), num_input_frames_);
+
+ if (num_valid_frames_ + num_input_frames_ > buffer_.num_frames()) {
+ return false;
+ }
+ // Remaining space after the write cursor.
+ const size_t forward_write_space = read_cursor_ <= write_cursor_
+ ? buffer_.num_frames() - write_cursor_
+ : read_cursor_ - write_cursor_;
+
+ // Copy the input into the buffer.
+ AudioBuffer::Channel* buffer_channel = &buffer_[0];
+ if (forward_write_space >= num_input_frames_) {
+ DCHECK_LE(buffer_channel->begin() + write_cursor_ + num_input_frames_,
+ buffer_channel->end());
+ std::copy(input.begin(), input.end(),
+ buffer_channel->begin() + write_cursor_);
+ } else {
+ DCHECK_LE(buffer_channel->begin() + write_cursor_ + forward_write_space,
+ buffer_channel->end());
+ DCHECK_LT(input.begin() + forward_write_space, input.end());
+ std::copy(input.begin(), input.begin() + forward_write_space,
+ buffer_channel->begin() + write_cursor_);
+ DCHECK_LE(buffer_channel->begin() + forward_write_space,
+ buffer_channel->end());
+ std::copy(input.begin() + forward_write_space, input.end(),
+ buffer_channel->begin());
+ }
+
+ write_cursor_ = (write_cursor_ + num_input_frames_) % buffer_.num_frames();
+ num_valid_frames_ += num_input_frames_;
+ return true;
+}
+
+bool CircularBuffer::RetrieveBuffer(AudioBuffer::Channel* output) {
+ return RetrieveBufferWithOffset(/*offset=*/0, output);
+}
+
+bool CircularBuffer::RetrieveBufferWithOffset(size_t offset,
+ AudioBuffer::Channel* output) {
+ DCHECK_LE(output->begin() + num_output_frames_ + offset, output->end());
+
+ if (num_valid_frames_ < num_output_frames_) {
+ return false;
+ }
+ // Remaining space after the read cursor.
+ const size_t forward_read_space = read_cursor_ < write_cursor_
+ ? write_cursor_ - read_cursor_
+ : buffer_.num_frames() - read_cursor_;
+
+ // Copy the buffer values into the output.
+ AudioBuffer::Channel* buffer_channel = &buffer_[0];
+ if (forward_read_space >= num_output_frames_) {
+ DCHECK_LE(buffer_channel->begin() + read_cursor_ + num_output_frames_,
+ buffer_channel->end());
+ std::copy(buffer_channel->begin() + read_cursor_,
+ buffer_channel->begin() + read_cursor_ + num_output_frames_,
+ output->begin() + offset);
+ } else {
+ DCHECK_LE(buffer_channel->begin() + read_cursor_ + forward_read_space,
+ buffer_channel->end());
+ DCHECK_LE(output->begin() + forward_read_space + offset, output->end());
+ std::copy(buffer_channel->begin() + read_cursor_,
+ buffer_channel->begin() + read_cursor_ + forward_read_space,
+ output->begin() + offset);
+ DCHECK_GE(buffer_channel->begin() + num_output_frames_ - forward_read_space,
+ buffer_channel->begin());
+ DCHECK_LE(output->begin() + offset + num_output_frames_, output->end());
+ std::copy(buffer_channel->begin(),
+ buffer_channel->begin() + num_output_frames_ - forward_read_space,
+ output->begin() + offset + forward_read_space);
+ }
+ read_cursor_ = (read_cursor_ + num_output_frames_) % buffer_.num_frames();
+ num_valid_frames_ -= num_output_frames_;
+ return true;
+}
+
+void CircularBuffer::Clear() {
+ read_cursor_ = 0;
+ write_cursor_ = 0;
+ num_valid_frames_ = 0;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer.h
new file mode 100644
index 000000000..e21f5817d
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer.h
@@ -0,0 +1,96 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_CIRCULAR_BUFFER_H_
+#define RESONANCE_AUDIO_DSP_CIRCULAR_BUFFER_H_
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+// Class that implements a simple mono circular buffer, accepting input and
+// output of different length.
+class CircularBuffer {
+ public:
+ // Constructs a circular buffer.
+ //
+ // @param buffer_length The length of the Circular buffer. This value must be
+ // at least |num_input_frames| + |num_output_frames| so that we can always
+ // either add or remove data.
+ // @param num_input_frames Length of the input buffers in frames.
+ // @param num_output_frames Length of the output buffers in frames.
+ CircularBuffer(size_t buffer_length, size_t num_input_frames,
+ size_t num_output_frames);
+
+ // Inserts a buffer of mono input into the |CircularBuffer| if space permits.
+ //
+ // @param input A channel of input data |num_input_frames| in length.
+ // @return True if there was space in the buffer and the input was
+ // successfully inserted, false otherwise.
+ bool InsertBuffer(const AudioBuffer::Channel& input);
+
+ // Retrieves a buffer of output from the |CircularBuffer| if it contains
+ // sufficient data.
+ //
+ // @param output A channel to hold |num_output_frames| of output data. The
+ // channel may be greater in length than |num_output_frames|, in this
+ // case only the first |num_output_frames| will be overwritten.
+ // @return True if there was sufficient data in the buffer and the output was
+ // successfully retrieved.
+ bool RetrieveBuffer(AudioBuffer::Channel* output);
+
+ // Retrieves a buffer of output from the |CircularBuffer| to an offset
+ // location in an output channel, provided it contains sufficient data.
+ //
+ // @param offset Number of samples of offset into the |output| channel.
+ // @param output A channel to hold |num_output_frames| of output data. The
+ // channel may be greater in length than |num_output_frames| + |offset|,
+ // in this case only the first |num_output_frames| after |offset| will be
+ // overwritten.
+ // @return True if there was sufficient data in the buffer and the output was
+ // successfully retrieved.
+ bool RetrieveBufferWithOffset(size_t offset, AudioBuffer::Channel* output);
+
+ // Returns the number of samples of data currently in the |CircularBuffer|.
+ //
+ // @return The number of samples of data currently in the buffer.
+ size_t GetOccupancy() const { return num_valid_frames_; }
+
+ // Resets the |CircularBuffer|.
+ void Clear();
+
+ private:
+ // Number of input frames to be inserted into the buffer.
+ const size_t num_input_frames_;
+
+ // Number of output frames to be retrieved from the buffer.
+ const size_t num_output_frames_;
+
+ // Mono audio buffer to hold the data.
+ AudioBuffer buffer_;
+
+ // Position at which we are writing into the buffer.
+ size_t write_cursor_;
+
+ // position at which we are reading from the buffer.
+ size_t read_cursor_;
+
+ // Number of frames of data currently stored within the buffer.
+ size_t num_valid_frames_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_CIRCULAR_BUFFER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer_test.cc
new file mode 100644
index 000000000..5b53246e6
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/circular_buffer_test.cc
@@ -0,0 +1,230 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/circular_buffer.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// Tests that when the output from the circular buffer is of a smaller length
+// than the input, the |CircularBuffer|correctly accepts and rejects inserts
+// and retrievals.
+TEST(CircularBufferTest, RemainingReadSpaceTest) {
+ const size_t kInputSize = 5;
+ const size_t kOutputSize = 4;
+ const size_t kBufferSize = 9;
+ CircularBuffer circular_buffer(kBufferSize, kInputSize, kOutputSize);
+ AudioBuffer input_a(kNumMonoChannels, kInputSize);
+ input_a[0] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f};
+ AudioBuffer output(kNumMonoChannels, kOutputSize);
+ output.Clear();
+
+ EXPECT_TRUE(circular_buffer.InsertBuffer(input_a[0]));
+ // There should not be enough space to write another buffer.
+ EXPECT_FALSE(circular_buffer.InsertBuffer(input_a[0]));
+
+ EXPECT_TRUE(circular_buffer.RetrieveBuffer(&output[0]));
+ // There should not be enough data to read from the buffer.
+ EXPECT_FALSE(circular_buffer.RetrieveBuffer(&output[0]));
+
+ // The output buffer should contain the first |kOutputSize| entries from the
+ // input buffer.
+ for (size_t i = 0; i < kOutputSize; ++i) {
+ EXPECT_FLOAT_EQ(output[0][i], input_a[0][i]);
+ }
+
+ AudioBuffer input_b(kNumMonoChannels, kInputSize);
+ input_b[0] = {5.0f, 6.0f, 7.0f, 8.0f, 9.0f};
+
+ EXPECT_TRUE(circular_buffer.InsertBuffer(input_b[0]));
+ // There should not be enough space to write another buffer.
+ EXPECT_FALSE(circular_buffer.InsertBuffer(input_b[0]));
+
+ EXPECT_TRUE(circular_buffer.RetrieveBuffer(&output[0]));
+ // There should not be enough data to read from the buffer.
+ EXPECT_FALSE(circular_buffer.RetrieveBuffer(&output[0]));
+
+ // The output buffer should contain the final entry from the first input
+ // buffer and then |kOutputSize| - 1 entries from the second.
+ EXPECT_FLOAT_EQ(output[0][0], input_a[0][kInputSize - 1]);
+ for (size_t i = 1; i < kOutputSize; ++i) {
+ EXPECT_FLOAT_EQ(output[0][i], input_b[0][i - 1]);
+ }
+}
+
+// Tests that when the output from the circular buffer is of a greater length
+// than the input, the |CircularBuffer|correctly accepts and rejects inserts
+// and retrievals.
+TEST(CircularBufferTest, RemainingWriteSpaceTest) {
+ const size_t kInputSize = 4;
+ const size_t kOutputSize = 5;
+ const size_t kBufferSize = 10;
+ CircularBuffer circular_buffer(kBufferSize, kInputSize, kOutputSize);
+ AudioBuffer input_a(kNumMonoChannels, kInputSize);
+ input_a[0] = {0.0f, 1.0f, 2.0f, 3.0f};
+ AudioBuffer input_b(kNumMonoChannels, kInputSize);
+ input_b[0] = {4.0f, 5.0f, 6.0f, 7.0f};
+ AudioBuffer input_c(kNumMonoChannels, kInputSize);
+ input_c[0] = {8.0f, 9.0f, 10.0f, 11.0f};
+ AudioBuffer input_d(kNumMonoChannels, kInputSize);
+ input_d[0] = {12.0f, 13.0f, 14.0f, 15.0f};
+ AudioBuffer input_e(kNumMonoChannels, kInputSize);
+ input_e[0] = {16.0f, 17.0f, 18.0f, 19.0f};
+ AudioBuffer output(kNumMonoChannels, kOutputSize);
+ output.Clear();
+
+ EXPECT_TRUE(circular_buffer.InsertBuffer(input_a[0]));
+ EXPECT_TRUE(circular_buffer.InsertBuffer(input_b[0]));
+ // There should not be enough space to write another buffer.
+ EXPECT_FALSE(circular_buffer.InsertBuffer(input_c[0]));
+
+ EXPECT_TRUE(circular_buffer.RetrieveBuffer(&output[0]));
+ // There should not be enough data to read from the buffer.
+ EXPECT_FALSE(circular_buffer.RetrieveBuffer(&output[0]));
+
+ float value = 0.0f;
+ for (size_t i = 0; i < kOutputSize; ++i) {
+ EXPECT_FLOAT_EQ(output[0][i], value);
+ value += 1.0f;
+ }
+
+ // Add another 4 samples of input in.
+ EXPECT_TRUE(circular_buffer.InsertBuffer(input_c[0]));
+ // There should not be enough space to write another buffer.
+ EXPECT_FALSE(circular_buffer.InsertBuffer(input_d[0]));
+
+ EXPECT_TRUE(circular_buffer.RetrieveBuffer(&output[0]));
+ // There should not be enough data to read from the buffer.
+ EXPECT_FALSE(circular_buffer.RetrieveBuffer(&output[0]));
+
+ for (size_t i = 0; i < kOutputSize; ++i) {
+ EXPECT_FLOAT_EQ(output[0][i], value);
+ value += 1.0f;
+ }
+
+ // Add another 8 samples of input in.
+ EXPECT_TRUE(circular_buffer.InsertBuffer(input_d[0]));
+ EXPECT_TRUE(circular_buffer.InsertBuffer(input_e[0]));
+ // There should not be enough space to write another buffer.
+ EXPECT_FALSE(circular_buffer.InsertBuffer(input_a[0]));
+
+ // We should be able to get 10 samples of output.
+ EXPECT_TRUE(circular_buffer.RetrieveBuffer(&output[0]));
+ for (size_t i = 0; i < kOutputSize; ++i) {
+ EXPECT_FLOAT_EQ(output[0][i], value);
+ value += 1.0f;
+ }
+ EXPECT_TRUE(circular_buffer.RetrieveBuffer(&output[0]));
+ for (size_t i = 0; i < kOutputSize; ++i) {
+ EXPECT_FLOAT_EQ(output[0][i], value);
+ value += 1.0f;
+ }
+
+ // There should not be enough data to read from the buffer.
+ EXPECT_FALSE(circular_buffer.RetrieveBuffer(&output[0]));
+
+ // The buffer should now be completely empty.
+ EXPECT_EQ(circular_buffer.GetOccupancy(), 0U);
+}
+
+// Tests tha a call to RetrieveBuffer will work when the output buffer is
+// oversized, but that only the first kOutputSize samples are filled.
+TEST(CircularBufferTest, LongerWriteSpaceTest) {
+ const size_t kInputSize = 5;
+ const size_t kOutputSize = 3;
+ const size_t kBufferSize = 10;
+ CircularBuffer circular_buffer(kBufferSize, kInputSize, kOutputSize);
+ AudioBuffer input_a(kNumMonoChannels, kInputSize);
+ input_a[0] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
+ AudioBuffer output(kNumMonoChannels, kBufferSize);
+ output.Clear();
+
+ EXPECT_TRUE(circular_buffer.InsertBuffer(input_a[0]));
+ EXPECT_TRUE(circular_buffer.RetrieveBuffer(&output[0]));
+
+ for (size_t i = 0; i < kBufferSize; ++i) {
+ if (i < kOutputSize) {
+ EXPECT_FLOAT_EQ(output[0][i], input_a[0][i]);
+ } else {
+ EXPECT_FLOAT_EQ(output[0][i], 0.0f);
+ }
+ }
+}
+
+// Tests tha a call to RetrieveBufferOffset will work when the output buffer is
+// oversized, but that the first kOutputSize samples after kOffset are filled.
+TEST(CircularBufferTest, OffsetRerieveTest) {
+ const size_t kInputSize = 5;
+ const size_t kOutputSize = 3;
+ const size_t kBufferSize = 10;
+ const size_t kOffset = 2;
+ CircularBuffer circular_buffer(kBufferSize, kInputSize, kOutputSize);
+ AudioBuffer input_a(kNumMonoChannels, kInputSize);
+ input_a[0] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
+ AudioBuffer output(kNumMonoChannels, kBufferSize);
+ output.Clear();
+
+ EXPECT_TRUE(circular_buffer.InsertBuffer(input_a[0]));
+ EXPECT_TRUE(circular_buffer.RetrieveBufferWithOffset(kOffset, &output[0]));
+
+ for (size_t i = 0; i < kBufferSize; ++i) {
+ if (i < kOffset) {
+ EXPECT_FLOAT_EQ(output[0][i], 0.0f);
+ } else if (i < kOffset + kOutputSize) {
+ EXPECT_FLOAT_EQ(output[0][i], input_a[0][i - kOffset]);
+ } else {
+ EXPECT_FLOAT_EQ(output[0][i], 0.0f);
+ }
+ }
+}
+
+// Tests that the circular buffer handles odd input buffer lengths in the
+// manner that it will be passed in the spectral reverb
+// (see: dsp/spectral_reverb.cc)
+TEST(CircularBufferTest, Strange) {
+ const size_t kNumRuns = 100;
+ // An odd non pwer of two input buffer size.
+ const size_t kOddInputSize = 713;
+ // Output size is equal to the SpectralReverb's internal buffer size.
+ const size_t kOutputSize = 1024;
+ // SpectralReverb's internal forier transform length.
+ const size_t kFFTSize = 4096;
+ CircularBuffer input(kFFTSize + kOddInputSize, kOddInputSize, kOutputSize);
+ CircularBuffer output(kOutputSize + kOddInputSize, kOutputSize,
+ kOddInputSize);
+ AudioBuffer in(kNumMonoChannels, kOddInputSize);
+ AudioBuffer out(kNumMonoChannels, kOutputSize);
+
+ // AudioBuffers will be input and output in the same manner as in
+ // dsp/spectral_reverb.cc.
+ EXPECT_TRUE(output.InsertBuffer(out[0]));
+ for (size_t i = 0; i < kNumRuns; ++i) {
+ EXPECT_TRUE(input.InsertBuffer(in[0]));
+ while (input.GetOccupancy() >= kOutputSize) {
+ EXPECT_TRUE(input.RetrieveBuffer(&out[0]));
+ EXPECT_TRUE(output.InsertBuffer(out[0]));
+ }
+ EXPECT_TRUE(output.RetrieveBuffer(&in[0]));
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter.cc
new file mode 100644
index 000000000..b448de58b
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter.cc
@@ -0,0 +1,180 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/delay_filter.h"
+
+#include <cmath>
+
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+
+
+namespace vraudio {
+// The following explains the behaviour of the delay line when a change to the
+// delay length is made. Initially |delay| is 2, |frames_per_buffer_|
+// is 4, and |delay_line_| is 8 in length.
+//
+// delay = 2
+//
+// input0 [1, 2, 3, 4] output0 [0, 0, 1, 2]
+//
+// 0 1 2 3 4 5 6 7
+// delay line [1, 2, 3, 4, 0, 0, 0, 0]
+// | |
+// w r
+// ----------------------------------------------------------
+//
+// delay = 2
+//
+// input1 [5, 6, 7, 8] output1 [3, 4, 5, 6]
+//
+// 0 1 2 3 4 5 6 7
+// delay line [1, 2, 3, 4, 5, 6, 7, 8]
+// | |
+// w r
+// ----------------------------------------------------------
+//
+// delay = 1
+//
+// 0 1 2 3 4 5 6 7
+// delay line [1, 2, 3, 4, 5, 6, 7, 8]
+// | |
+// w r
+// ----------------------------------------------------------
+//
+// delay = 1
+//
+// input2 [9, 10, 11, 12] output2 [8, 9, 10, 11]
+//
+// 0 1 2 3 4 5 6 7
+// delay line [9, 10, 11, 12, 5, 6, 7, 8]
+// | |
+// w r
+// ----------------------------------------------------------
+
+DelayFilter::DelayFilter(size_t max_delay_length, size_t frames_per_buffer)
+ : frames_per_buffer_(frames_per_buffer),
+ delay_line_(nullptr),
+ write_cursor_(0) {
+ DCHECK_GT(frames_per_buffer_, 0U);
+ SetMaximumDelay(max_delay_length);
+}
+
+void DelayFilter::SetMaximumDelay(size_t max_delay_length) {
+ max_delay_length_ = max_delay_length;
+ const size_t new_buffer_size = frames_per_buffer_ + max_delay_length_;
+
+ if (delay_line_ == nullptr) {
+ delay_line_.reset(new AudioBuffer(kNumMonoChannels, new_buffer_size));
+ delay_line_->Clear();
+ return;
+ }
+ AudioBuffer::Channel* delay_channel = &(*delay_line_)[0];
+ // If |delay_line_| is not large enough, resize.
+ const size_t current_buffer_size = delay_line_->num_frames();
+ if (max_delay_length_ > current_buffer_size - frames_per_buffer_) {
+ // Allocate |new_delay_line| and populate it with the current |delay_line_|
+ // data, so that replacing the buffer does not affect the already stored
+ // samples.
+ auto new_delay_line = std::unique_ptr<AudioBuffer>(
+ new AudioBuffer(kNumMonoChannels, new_buffer_size));
+ new_delay_line->Clear();
+ std::copy(delay_channel->begin() + write_cursor_, delay_channel->end(),
+ (*new_delay_line)[0].begin());
+ if (write_cursor_ > 0) {
+ // Positive |write_cursor_| means that we still have remaining samples to
+ // be moved to |new_delay_line_| all of which reside left of the cursor.
+ std::copy(
+ delay_channel->begin(), delay_channel->begin() + write_cursor_,
+ (*new_delay_line)[0].begin() + current_buffer_size - write_cursor_);
+ write_cursor_ = current_buffer_size;
+ }
+ delay_line_ = std::move(new_delay_line);
+ }
+}
+
+void DelayFilter::InsertData(const AudioBuffer::Channel& input) {
+
+ DCHECK_EQ(input.size(), frames_per_buffer_);
+
+ const size_t delay_buffer_size = delay_line_->num_frames();
+
+ // Record the remaining space in the |delay_line_| after the write cursor.
+ const size_t remaining_size_write = delay_buffer_size - write_cursor_;
+ AudioBuffer::Channel* delay_channel = &(*delay_line_)[0];
+
+ // Copy the input into the delay line.
+ if (remaining_size_write >= frames_per_buffer_) {
+ DCHECK_LE(delay_channel->begin() + write_cursor_ + frames_per_buffer_,
+ delay_channel->end());
+ std::copy(input.begin(), input.end(),
+ delay_channel->begin() + write_cursor_);
+ } else {
+ DCHECK_LE(delay_channel->begin() + write_cursor_ + remaining_size_write,
+ delay_channel->end());
+ DCHECK_LE(input.begin() + remaining_size_write, input.end());
+ std::copy(input.begin(), input.begin() + remaining_size_write,
+ delay_channel->begin() + write_cursor_);
+ DCHECK_LE(delay_channel->begin() + remaining_size_write,
+ delay_channel->end());
+ std::copy(input.begin() + remaining_size_write, input.end(),
+ delay_channel->begin());
+ }
+
+ write_cursor_ = (write_cursor_ + frames_per_buffer_) % delay_buffer_size;
+}
+
+void DelayFilter::GetDelayedData(size_t delay_samples,
+ AudioBuffer::Channel* buffer) {
+
+ DCHECK(buffer);
+ DCHECK_GE(delay_samples, 0U);
+ DCHECK_LE(delay_samples, max_delay_length_);
+
+ const size_t delay_buffer_size = delay_line_->num_frames();
+ // Position in the delay line to begin reading from.
+ DCHECK_GE(write_cursor_ + delay_buffer_size,
+ delay_samples + frames_per_buffer_);
+ const size_t read_cursor =
+ (write_cursor_ + delay_buffer_size - delay_samples - frames_per_buffer_) %
+ delay_buffer_size;
+ // Record the remaining space in the |delay_line_| after the read cursor.
+ const size_t remaining_size_read = delay_buffer_size - read_cursor;
+ AudioBuffer::Channel* delay_channel = &(*delay_line_)[0];
+
+ // Extract a portion of the delay line into the buffer.
+ if (remaining_size_read >= frames_per_buffer_) {
+ DCHECK_LE(buffer->begin() + frames_per_buffer_, buffer->end());
+ DCHECK_LE(delay_channel->begin() + read_cursor + frames_per_buffer_,
+ delay_channel->end());
+ std::copy(delay_channel->begin() + read_cursor,
+ delay_channel->begin() + read_cursor + frames_per_buffer_,
+ buffer->begin());
+ } else {
+ DCHECK_LE(buffer->begin() + delay_channel->size() - read_cursor,
+ buffer->end());
+ std::copy(delay_channel->begin() + read_cursor, delay_channel->end(),
+ buffer->begin());
+ DCHECK_LE(buffer->begin() + frames_per_buffer_, buffer->end());
+ DCHECK_LE(delay_channel->begin() + frames_per_buffer_ - remaining_size_read,
+ delay_channel->end());
+ std::copy(delay_channel->begin(),
+ delay_channel->begin() + frames_per_buffer_ - remaining_size_read,
+ buffer->begin() + remaining_size_read);
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter.h
new file mode 100644
index 000000000..be7c49774
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter.h
@@ -0,0 +1,85 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_DELAY_FILTER_H_
+#define RESONANCE_AUDIO_DSP_DELAY_FILTER_H_
+
+#include <algorithm>
+#include <memory>
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Single channel delay line class. Delays input buffer data by a non-negative
+// integer number of samples.
+//
+// This implementation is not thread safe. The ClearBuffer() and InsertData()
+// functions should not be called by a seperate thread during GetDelayedData().
+class DelayFilter {
+ public:
+ // Constructs a DelayFilter.
+ //
+ // @param max_delay_length Maximum number of samples the input should be
+ // delayed by.
+ // @param frames_per_buffer Number of frames in each processed buffer.
+ DelayFilter(size_t max_delay_length, size_t frames_per_buffer);
+
+ // Sets the maximum delay length. It will allocate more space in the
+ // |delay_line_| if the new |max_delay_length| is more than doubled.
+ //
+ // @param max_delay_length New maximum delay in samples.
+ void SetMaximumDelay(size_t max_delay_length);
+
+ // Returns the current length of the |delay_line_|.
+ size_t GetDelayBufferLength() const { return delay_line_->num_frames(); }
+
+ // Returns the current maximum delay applicable to input buffers.
+ size_t GetMaximumDelayLength() const { return max_delay_length_; }
+
+ // Sets all of the |delay_line_| samples to zero.
+ void ClearBuffer() { delay_line_->Clear(); }
+
+ // Copies an |AudioBuffer::Channel| of data to the delay line.
+ //
+ // @param input Input data.
+ void InsertData(const AudioBuffer::Channel& input);
+
+ // Fills an |AudioBuffer::Channel| with data delayed by a specified amount
+ // less than or equal to the delay line's set |max_delay_length_|.
+ //
+ // @param delay_samples Requested delay to the data extraced from the delay
+ // line. Must be less than or equal to |max_delay_length_|.
+ // @param buffer Pointer to the output data, i.e., delayed input data.
+ void GetDelayedData(size_t delay_samples, AudioBuffer::Channel* buffer);
+
+ private:
+ // Maximum length of the delay to be applied (in samples).
+ size_t max_delay_length_;
+
+ // Number of frames in each AudioBuffer input/output.
+ size_t frames_per_buffer_;
+
+ // The delay line holding all of the delayed samples.
+ std::unique_ptr<AudioBuffer> delay_line_;
+
+ // Position in the delay line to begin writing to.
+ size_t write_cursor_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_DELAY_FILTER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter_test.cc
new file mode 100644
index 000000000..12a7a8f60
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/delay_filter_test.cc
@@ -0,0 +1,197 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/delay_filter.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// Set of delay lengths to be used in the tests below.
+const size_t kInitDelayLength = 4;
+const size_t kSecondDelayLength = 5;
+const size_t kThirdDelayLength = 2;
+const size_t kFourthDelayLength = 11;
+const size_t kZeroDelayLength = 0;
+
+// Frames for buffer for the input and output data buffers below.
+const size_t kFramesPerBuffer = 6;
+
+// Frames per buffer and channel number for the input and output data.
+const size_t kFramesPerBuffer2 = 10;
+
+// Function which passes an AudioBuffer through the delay line followed by all
+// zero AudioBuffers to flush the data out. This function then tests that the
+// input data has been delayed by the correct amount.
+//
+// @param delay A pointer to a DelayFilter which will be used in the test.
+// @param delay_length An integer delay length to be used in the test.
+void IntegerDelayTestHelper(DelayFilter* delay, size_t delay_length) {
+ std::vector<float> output_collect;
+ delay->SetMaximumDelay(delay_length);
+ delay->ClearBuffer();
+
+ // Initialize mono input buffer and fill with test data.
+ const std::vector<float> kData = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f};
+ AudioBuffer input(kNumMonoChannels, kFramesPerBuffer);
+ auto* input_channel = &input[0];
+ *input_channel = kData;
+
+ // Process input.
+ delay->InsertData(*input_channel);
+ delay->GetDelayedData(delay_length, input_channel);
+ output_collect.insert(output_collect.end(), input_channel->begin(),
+ input_channel->end());
+
+ // Keep passing zeros through till we flush all of the input data out.
+ while (delay_length + kFramesPerBuffer > output_collect.size()) {
+ // Set the |input| AudioBuffer to have all zero data.
+ input.Clear();
+ // Process input.
+ delay->InsertData(*input_channel);
+ delay->GetDelayedData(delay_length, input_channel);
+ output_collect.insert(output_collect.end(), input_channel->begin(),
+ input_channel->end());
+ }
+
+ // Check that the first GetDelayedData() call yields |delay_length| zeros at
+ // the beginning of its output.
+ for (size_t i = 0; i < delay_length; ++i) {
+ EXPECT_EQ(output_collect[i], 0.0f);
+ }
+ // Check that the output is the same data as the input but delayed by
+ // delay_length samples.
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ EXPECT_EQ(output_collect[i + delay_length], kData[i]);
+ }
+}
+
+// Tests that the maximum_delay_length_ and delay_buffer_size_ are set to the
+// correct values on construction and when SetDelay() is called.
+TEST(DelayFilterTest, DelayCorrectTest) {
+ DelayFilter delay(kInitDelayLength, kFramesPerBuffer);
+
+ EXPECT_EQ(delay.GetMaximumDelayLength(), kInitDelayLength);
+ EXPECT_EQ(delay.GetDelayBufferLength(), kInitDelayLength + kFramesPerBuffer);
+
+ delay.SetMaximumDelay(kSecondDelayLength);
+
+ EXPECT_EQ(delay.GetMaximumDelayLength(), kSecondDelayLength);
+ EXPECT_EQ(delay.GetDelayBufferLength(),
+ kSecondDelayLength + kFramesPerBuffer);
+
+ // In this next case we reduce the maximum length and thus do not expect a
+ // reallocation.
+ delay.SetMaximumDelay(kThirdDelayLength);
+
+ EXPECT_EQ(delay.GetMaximumDelayLength(), kThirdDelayLength);
+ EXPECT_EQ(delay.GetDelayBufferLength(),
+ kSecondDelayLength + kFramesPerBuffer);
+
+ delay.SetMaximumDelay(kFourthDelayLength);
+
+ EXPECT_EQ(delay.GetMaximumDelayLength(), kFourthDelayLength);
+ // Now we expect the buffer to have been reallocated.
+ EXPECT_EQ(delay.GetDelayBufferLength(),
+ kFourthDelayLength + kFramesPerBuffer);
+}
+
+// Tests whether when setting a different delay on one DelayFilter,
+// the output is correct in each case.
+TEST(DelayFilterTest, DelayTest) {
+ DelayFilter delay(kInitDelayLength, kFramesPerBuffer);
+
+ IntegerDelayTestHelper(&delay, kInitDelayLength);
+
+ // Tests the case of an increasing delay.
+ IntegerDelayTestHelper(&delay, kSecondDelayLength);
+
+ // Tests the case of a decreasing delay.
+ IntegerDelayTestHelper(&delay, kThirdDelayLength);
+
+ // Tests the case of an increasing delay with allocation of more buffer space.
+ IntegerDelayTestHelper(&delay, kFourthDelayLength);
+}
+
+// Tests that differently delayed buffers can be extracted from a single delay
+// line.
+TEST(DelayFilterTest, MultipleDelaysTest) {
+ DelayFilter delay(kFramesPerBuffer2, kFramesPerBuffer2);
+ AudioBuffer input(kNumMonoChannels, kFramesPerBuffer2);
+ for (size_t i = 0; i < kFramesPerBuffer2; ++i) {
+ input[0][i] = static_cast<float>(i + 1);
+ }
+ delay.InsertData(input[0]);
+ const size_t kDelayOne = 1;
+ const size_t kDelayTwo = 2;
+ AudioBuffer buffer_1(kNumMonoChannels, kFramesPerBuffer2);
+ AudioBuffer buffer_2(kNumMonoChannels, kFramesPerBuffer2);
+
+ delay.GetDelayedData(kDelayOne, &buffer_1[0]);
+ for (size_t i = 0; i < kFramesPerBuffer2 - kDelayOne; ++i) {
+ EXPECT_NEAR(buffer_1[0][i + kDelayOne], input[0][i], kEpsilonFloat);
+ }
+
+ delay.GetDelayedData(kDelayTwo, &buffer_2[0]);
+ for (size_t i = 0; i < kFramesPerBuffer2 - kDelayTwo; ++i) {
+ EXPECT_NEAR(buffer_2[0][i + kDelayTwo], input[0][i], kEpsilonFloat);
+ }
+}
+
+// Tests whether a zero delay length is dealt with correctly, Along with a
+// negative delay value (treated as zero delay.
+TEST(DelayFilterTest, ZeroDelayTest) {
+ DelayFilter delay(kZeroDelayLength, kFramesPerBuffer);
+ IntegerDelayTestHelper(&delay, kZeroDelayLength);
+}
+
+// Tests that output from a delay line that is initally large enough vs one that
+// is resized is the same.
+TEST(DelayFilterTest, InitialSizeVsResizeTest) {
+ const size_t kSmallMaxDelay = 2;
+ const size_t kLargeMaxDelay = 5;
+ const size_t kActualDelay = 4;
+
+ DelayFilter delay_sufficient(kLargeMaxDelay, kFramesPerBuffer);
+ DelayFilter delay_insufficient(kSmallMaxDelay, kFramesPerBuffer);
+
+ AudioBuffer input_buffer(kNumMonoChannels, kFramesPerBuffer);
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ input_buffer[0][i] = static_cast<float>(i + 1);
+ }
+
+ delay_sufficient.InsertData(input_buffer[0]);
+ delay_insufficient.InsertData(input_buffer[0]);
+ delay_insufficient.SetMaximumDelay(kLargeMaxDelay);
+
+ AudioBuffer buffer_sufficient(kNumMonoChannels, kFramesPerBuffer);
+ AudioBuffer buffer_insufficient(kNumMonoChannels, kFramesPerBuffer);
+
+ delay_sufficient.GetDelayedData(kActualDelay, &buffer_sufficient[0]);
+ delay_insufficient.GetDelayedData(kActualDelay, &buffer_insufficient[0]);
+
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ EXPECT_NEAR(buffer_sufficient[0][i], buffer_insufficient[0][i],
+ kEpsilonFloat);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation.cc
new file mode 100644
index 000000000..816053a7c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation.cc
@@ -0,0 +1,121 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/distance_attenuation.h"
+
+#include <algorithm>
+#include <cmath>
+
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+float ComputeLogarithmicDistanceAttenuation(
+ const WorldPosition& listener_position,
+ const WorldPosition& source_position, float min_distance,
+ float max_distance) {
+ const float distance = (listener_position - source_position).norm();
+ if (distance > max_distance) {
+ return 0.0f;
+ }
+ // Logarithmic attenuation.
+ const float min_distance_allowed =
+ std::max(min_distance, kNearFieldThreshold);
+ if (distance > min_distance_allowed) {
+ const float attenuation_interval = max_distance - min_distance_allowed;
+ if (attenuation_interval > kEpsilonFloat) {
+ // Compute the distance attenuation value by the logarithmic curve
+ // "1 / (d + 1)" with an offset of |min_distance_allowed|.
+ const float relative_distance = distance - min_distance_allowed;
+ const float attenuation = 1.0f / (relative_distance + 1.0f);
+ // Shift the curve downwards by the attenuation value at |max_distance|,
+ // and scale the value by the inverse of it in order to keep the curve's
+ // peak value 1 at |min_distance_allowed|.
+ const float attenuation_max = 1.0f / (1.0f + attenuation_interval);
+ return (attenuation - attenuation_max) / (1.0f - attenuation_max);
+ }
+ }
+ return 1.0f;
+}
+
+float ComputeLinearDistanceAttenuation(const WorldPosition& listener_position,
+ const WorldPosition& source_position,
+ float min_distance, float max_distance) {
+ const float distance = (listener_position - source_position).norm();
+ if (distance > max_distance) {
+ return 0.0f;
+ }
+ // Linear attenuation.
+ const float min_distance_allowed =
+ std::max(min_distance, kNearFieldThreshold);
+ if (distance > min_distance_allowed) {
+ const float attenuation_interval = max_distance - min_distance_allowed;
+ if (attenuation_interval > kEpsilonFloat) {
+ return (max_distance - distance) / attenuation_interval;
+ }
+ }
+ return 1.0f;
+}
+
+float ComputeNearFieldEffectGain(const WorldPosition& listener_position,
+ const WorldPosition& source_position) {
+ const float distance = (listener_position - source_position).norm();
+ if (distance < kNearFieldThreshold) {
+ return (1.0f / std::max(distance, kMinNearFieldDistance)) - 1.0f;
+ }
+ return 0.0f;
+}
+
+void UpdateAttenuationParameters(float master_gain, float reflections_gain,
+ float reverb_gain,
+ const WorldPosition& listener_position,
+ SourceParameters* parameters) {
+ // Compute distance attenuation.
+ const WorldPosition& source_position = parameters->object_transform.position;
+ const auto rolloff_model = parameters->distance_rolloff_model;
+ const float min_distance = parameters->minimum_distance;
+ const float max_distance = parameters->maximum_distance;
+
+ float distance_attenuation = 0.0f;
+ switch (rolloff_model) {
+ case DistanceRolloffModel::kLogarithmic:
+ distance_attenuation = ComputeLogarithmicDistanceAttenuation(
+ listener_position, source_position, min_distance, max_distance);
+ break;
+ case DistanceRolloffModel::kLinear:
+ distance_attenuation = ComputeLinearDistanceAttenuation(
+ listener_position, source_position, min_distance, max_distance);
+ break;
+ case DistanceRolloffModel::kNone:
+ default:
+ // Distance attenuation is already set by the user.
+ distance_attenuation = parameters->distance_attenuation;
+ break;
+ }
+ // Update gain attenuations.
+ const float input_gain = master_gain * parameters->gain;
+ const float direct_attenuation = input_gain * distance_attenuation;
+ const float room_effects_attenuation = parameters->room_effects_gain;
+
+ parameters->attenuations[AttenuationType::kInput] = input_gain;
+ parameters->attenuations[AttenuationType::kDirect] = direct_attenuation;
+ parameters->attenuations[AttenuationType::kReflections] =
+ room_effects_attenuation * direct_attenuation * reflections_gain;
+ parameters->attenuations[AttenuationType::kReverb] =
+ room_effects_attenuation * input_gain * reverb_gain;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation.h
new file mode 100644
index 000000000..2b98ac63c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation.h
@@ -0,0 +1,82 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_DISTANCE_ATTENUATION_H_
+#define RESONANCE_AUDIO_DSP_DISTANCE_ATTENUATION_H_
+
+#include "base/misc_math.h"
+#include "base/source_parameters.h"
+
+namespace vraudio {
+
+// Returns the distance attenuation for |source_position| with respect to
+// |listener_position|. The amplitude will decrease by approximately 6 dB every
+// time the distance is doubled, i.e., the sound pressure "p" (amplitude)
+// approximately falls inversely proportional to the distance "1/r".
+//
+// @param listener_position World position of the listener.
+// @param source_position World position of the source.
+// @param min_distance The minimum distance at which distance attenuation is
+// applied.
+// @param max_distance The maximum distance at which the direct sound has a gain
+// of 0.0.
+// @return Attenuation (gain) value in range [0.0f, 1.0f].
+float ComputeLogarithmicDistanceAttenuation(
+ const WorldPosition& listener_position,
+ const WorldPosition& source_position, float min_distance,
+ float max_distance);
+
+// Returns the distance attenuation for |source_position| with respect to
+// |listener_position|. The amplitude will decrease linearly between
+// |min_distance| and |max_distance| from 1.0 to 0.0.
+//
+// @param listener_position World position of the listener.
+// @param source_position World position of the source.
+// @param min_distance The minimum distance at which distance attenuation is
+// applied.
+// @param max_distance The maximum distance at which the direct sound has a gain
+// of 0.0.
+// @return Attenuation (gain) value in range [0.0f, 1.0f].
+float ComputeLinearDistanceAttenuation(const WorldPosition& listener_position,
+ const WorldPosition& source_position,
+ float min_distance, float max_distance);
+
+// Calculates the gain to be applied to the near field compensating stereo mix.
+// This function will return 0.0f for all sources further away than one meter
+// and will return a value between 0.0 and 9.0 for sources as they approach
+// the listener's head location.
+//
+// @param listener_position World position of the listener.
+// @param source_position World position of the source.
+// @return Gain value in range [0.0f, 9.0f].
+float ComputeNearFieldEffectGain(const WorldPosition& listener_position,
+ const WorldPosition& source_position);
+
+// Calculates and updates gain attenuations of the given source |parameters|.
+//
+// @param master_gain Global gain adjustment in amplitude.
+// @param reflections_gain Reflections gain in amplitude.
+// @param reverb_gain Reverb gain in amplitude.
+// @param listener_position World position of the listener.
+// @param parameters Source parameters to apply the gain attenuations into.
+void UpdateAttenuationParameters(float master_gain, float reflections_gain,
+ float reverb_gain,
+ const WorldPosition& listener_position,
+ SourceParameters* parameters);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_DISTANCE_ATTENUATION_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation_test.cc
new file mode 100644
index 000000000..6bccfcabf
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/distance_attenuation_test.cc
@@ -0,0 +1,132 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/distance_attenuation.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+namespace {
+
+// Tests the logarithmic distance attenuation method against the pre-computed
+// results.
+TEST(DistanceAttenuationTest, ComputeLogarithmicDistanceAttenuationTest) {
+ const WorldPosition kListenerPosition(0.0f, 3.0f, 0.0f);
+ const WorldPosition kSourcePosition(0.0f, 0.0f, -4.0f);
+ const float kMinDistance_low = 1.0f;
+ const float kMinDistance_high = 10.0f;
+ const float kMaxDistance_low = 3.0f;
+ const float kMaxDistance_high = 500.0f;
+ const float kExpectedAttenuation_a = 0.1983967f;
+ const float kExpectedAttenuation_b = 0.0f;
+ const float kExpectedAttenuation_c = 1.0f;
+
+ float attenuation = ComputeLogarithmicDistanceAttenuation(
+ kListenerPosition, kSourcePosition, kMinDistance_low, kMaxDistance_high);
+ EXPECT_NEAR(kExpectedAttenuation_a, attenuation, kEpsilonFloat);
+
+ // Test for the case where the source is beyond the maximum distance.
+ attenuation = ComputeLogarithmicDistanceAttenuation(
+ kListenerPosition, kSourcePosition, kMinDistance_low, kMaxDistance_low);
+ EXPECT_NEAR(kExpectedAttenuation_b, attenuation, kEpsilonFloat);
+
+ // Test for the case where the source is within the minimum distance.
+ attenuation = ComputeLogarithmicDistanceAttenuation(
+ kListenerPosition, kSourcePosition, kMinDistance_high, kMaxDistance_high);
+ EXPECT_NEAR(kExpectedAttenuation_c, attenuation, kEpsilonFloat);
+}
+
+// Tests the linear distance attenuation method against the pre-computed
+// results.
+TEST(DistanceAttenuationTest, ComputeLinearDistanceAttenuationTest) {
+ const WorldPosition kListenerPosition(0.0f, 3.0f, 0.0f);
+ const WorldPosition kSourcePosition(0.0f, 0.0f, -4.0f);
+ const float kMinDistance_low = 1.0f;
+ const float kMinDistance_high = 10.0f;
+ const float kMaxDistance_low = 3.0f;
+ const float kMaxDistance_high = 8.0f;
+ const float kExpectedAttenuation_a = 0.4285714f;
+ const float kExpectedAttenuation_b = 0.0f;
+ const float kExpectedAttenuation_c = 1.0f;
+
+ float attenuation = ComputeLinearDistanceAttenuation(
+ kListenerPosition, kSourcePosition, kMinDistance_low, kMaxDistance_high);
+ EXPECT_NEAR(kExpectedAttenuation_a, attenuation, kEpsilonFloat);
+
+ // Test for the case where the source is beyond the maximum distance.
+ attenuation = ComputeLinearDistanceAttenuation(
+ kListenerPosition, kSourcePosition, kMinDistance_low, kMaxDistance_low);
+ EXPECT_NEAR(kExpectedAttenuation_b, attenuation, kEpsilonFloat);
+
+ // Test for the case where the source is within the minimum distance.
+ attenuation = ComputeLinearDistanceAttenuation(
+ kListenerPosition, kSourcePosition, kMinDistance_high, kMaxDistance_high);
+ EXPECT_NEAR(kExpectedAttenuation_c, attenuation, kEpsilonFloat);
+}
+
+// Tests the gain attenuations update method against the pre-computed results.
+TEST(DistanceAttenuationTest, UpdateAttenuationParametersTest) {
+ const float kMasterGain = 0.5f;
+ const float kReflectionsGain = 0.5f;
+ const float kReverbGain = 2.0f;
+ const WorldPosition kListenerPosition(0.0f, 0.0f, 0.0f);
+ const WorldPosition kSourcePosition(0.0f, 0.0f, 1.5f);
+ const float kDistanceAttenuation = 0.2f;
+ const float kRoomEffectsGain = 0.25f;
+
+ // Initialize new |SourceParameters| with an explicit distance attenuation
+ // value to avoid extra complexity.
+ SourceParameters parameters;
+ parameters.distance_rolloff_model = DistanceRolloffModel::kNone;
+ parameters.distance_attenuation = kDistanceAttenuation;
+ parameters.object_transform.position = kSourcePosition;
+ parameters.room_effects_gain = kRoomEffectsGain;
+ // Update the gain attenuation parameters.
+ UpdateAttenuationParameters(kMasterGain, kReflectionsGain, kReverbGain,
+ kListenerPosition, &parameters);
+ // Check the attenuation parameters against the pre-computed values.
+ const size_t num_attenuations =
+ static_cast<size_t>(AttenuationType::kNumAttenuationTypes);
+ const float kExpectedAttenuations[num_attenuations] = {0.5f, 0.1f, 0.0125f,
+ 0.25f};
+ for (size_t i = 0; i < num_attenuations; ++i) {
+ EXPECT_NEAR(kExpectedAttenuations[i], parameters.attenuations[i],
+ kEpsilonFloat)
+ << "Attenuation " << i;
+ }
+}
+
+// Tests the near field effects gain computation method against the pre-computed
+// results.
+TEST(NearFieldEffectTest, ComputeNearFieldEffectTest) {
+ const WorldPosition kListenerPosition(0.0f, 3.0f, 0.0f);
+ const WorldPosition kSourcePosition_a(0.0f, 0.0f, -4.0f);
+ const WorldPosition kSourcePosition_b(0.0f, 2.5f, 0.0f);
+ const float kExpectedGain_a = 0.0f;
+ const float kExpectedGain_b = 1.0f;
+
+ float gain = ComputeNearFieldEffectGain(kListenerPosition, kSourcePosition_a);
+ EXPECT_NEAR(kExpectedGain_a, gain, kEpsilonFloat);
+ gain = ComputeNearFieldEffectGain(kListenerPosition, kSourcePosition_b);
+ EXPECT_NEAR(kExpectedGain_b, gain, kEpsilonFloat);
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager.cc
new file mode 100644
index 000000000..5be470b17
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager.cc
@@ -0,0 +1,209 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/fft_manager.h"
+
+#include <algorithm>
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/misc_math.h"
+#include "base/simd_utils.h"
+
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+namespace vraudio {
+
+namespace {
+
+// for |fft_size_|s less than 2^14, the stack is used, on the reccomendation of
+// the author of the pffft library.
+const size_t kPffftMaxStackSize = 16384;
+
+} // namespace
+
+// The pffft implementation requires a minimum fft size of 32 samples.
+const size_t FftManager::kMinFftSize = 32;
+
+FftManager::FftManager(size_t frames_per_buffer)
+ : fft_size_(std::max(NextPowTwo(frames_per_buffer) * 2, kMinFftSize)),
+ frames_per_buffer_(frames_per_buffer),
+ inverse_fft_scale_(1.0f / static_cast<float>(fft_size_)),
+ temp_zeropad_buffer_(kNumMonoChannels, fft_size_),
+ temp_freq_buffer_(kNumMonoChannels, fft_size_) {
+ DCHECK_GT(frames_per_buffer, 0U);
+ DCHECK_GE(fft_size_, kMinFftSize);
+ DCHECK(!(fft_size_ & (fft_size_ - 1))); // Ensure its a power of two.
+ // Suggested pffft initialization.
+ if (fft_size_ > kPffftMaxStackSize) {
+ // Allocate memory for work space factors etc, Size reccomended by pffft.
+ const size_t num_bytes = 2 * fft_size_ * sizeof(float);
+ pffft_workspace_ =
+ reinterpret_cast<float*>(pffft_aligned_malloc(num_bytes));
+ }
+
+ fft_ = pffft_new_setup(static_cast<int>(fft_size_), PFFFT_REAL);
+
+ temp_zeropad_buffer_.Clear();
+}
+
+FftManager::~FftManager() {
+ pffft_destroy_setup(fft_);
+ if (pffft_workspace_ != nullptr) {
+ pffft_aligned_free(pffft_workspace_);
+ }
+}
+
+void FftManager::FreqFromTimeDomain(const AudioBuffer::Channel& time_channel,
+ AudioBuffer::Channel* freq_channel) {
+
+
+ DCHECK(freq_channel);
+ DCHECK_EQ(freq_channel->size(), fft_size_);
+ DCHECK_LE(time_channel.size(), fft_size_);
+
+ // Perform forward FFT transform.
+ if (time_channel.size() == fft_size_) {
+ pffft_transform(fft_, time_channel.begin(), freq_channel->begin(),
+ pffft_workspace_, PFFFT_FORWARD);
+ } else {
+ std::copy_n(time_channel.begin(), frames_per_buffer_,
+ temp_zeropad_buffer_[0].begin());
+ pffft_transform(fft_, temp_zeropad_buffer_[0].begin(),
+ freq_channel->begin(), pffft_workspace_, PFFFT_FORWARD);
+ }
+}
+
+void FftManager::TimeFromFreqDomain(const AudioBuffer::Channel& freq_channel,
+ AudioBuffer::Channel* time_channel) {
+
+
+ DCHECK(time_channel);
+ DCHECK_EQ(freq_channel.size(), fft_size_);
+
+ // Perform reverse FFT transform.
+ const size_t time_channel_size = time_channel->size();
+ if (time_channel_size == fft_size_) {
+ pffft_transform(fft_, freq_channel.begin(), time_channel->begin(),
+ pffft_workspace_, PFFFT_BACKWARD);
+ } else {
+ DCHECK_EQ(time_channel_size, frames_per_buffer_);
+ auto& temp_channel = temp_freq_buffer_[0];
+ pffft_transform(fft_, freq_channel.begin(), temp_channel.begin(),
+ pffft_workspace_, PFFFT_BACKWARD);
+ std::copy_n(temp_channel.begin(), frames_per_buffer_,
+ time_channel->begin());
+ }
+}
+
+void FftManager::ApplyReverseFftScaling(AudioBuffer::Channel* time_channel) {
+ DCHECK(time_channel->size() == frames_per_buffer_ ||
+ time_channel->size() == fft_size_);
+ // Normalization must be performed here as we normally do this as part of the
+ // convolution.
+ ScalarMultiply(time_channel->size(), inverse_fft_scale_,
+ time_channel->begin(), time_channel->begin());
+}
+
+void FftManager::GetCanonicalFormatFreqBuffer(const AudioBuffer::Channel& input,
+ AudioBuffer::Channel* output) {
+ DCHECK_EQ(input.size(), fft_size_);
+ DCHECK_EQ(output->size(), fft_size_);
+ pffft_zreorder(fft_, input.begin(), output->begin(), PFFFT_FORWARD);
+}
+
+void FftManager::GetPffftFormatFreqBuffer(const AudioBuffer::Channel& input,
+ AudioBuffer::Channel* output) {
+ DCHECK_EQ(input.size(), fft_size_);
+ DCHECK_EQ(output->size(), fft_size_);
+ pffft_zreorder(fft_, input.begin(), output->begin(), PFFFT_BACKWARD);
+}
+
+void FftManager::MagnitudeFromCanonicalFreqBuffer(
+ const AudioBuffer::Channel& freq_channel,
+ AudioBuffer::Channel* magnitude_channel) {
+ DCHECK(magnitude_channel);
+ DCHECK_EQ(freq_channel.size(), fft_size_);
+ DCHECK_EQ(magnitude_channel->size(), frames_per_buffer_ + 1);
+
+ (*magnitude_channel)[0] = std::abs(freq_channel[0]);
+ ApproxComplexMagnitude(frames_per_buffer_ - 1, freq_channel.begin() + 2,
+ magnitude_channel->begin() + 1);
+ (*magnitude_channel)[frames_per_buffer_] = std::abs(freq_channel[1]);
+}
+
+void FftManager::CanonicalFreqBufferFromMagnitudeAndPhase(
+ const AudioBuffer::Channel& magnitude_channel,
+ const AudioBuffer::Channel& phase_channel,
+ AudioBuffer::Channel* canonical_freq_channel) {
+ DCHECK(canonical_freq_channel);
+ DCHECK_EQ(magnitude_channel.size(), frames_per_buffer_ + 1);
+ DCHECK_EQ(phase_channel.size(), frames_per_buffer_ + 1);
+ DCHECK_EQ(canonical_freq_channel->size(), fft_size_);
+
+ (*canonical_freq_channel)[0] = magnitude_channel[0];
+ (*canonical_freq_channel)[1] = -magnitude_channel[frames_per_buffer_];
+ for (size_t i = 1, j = 2; i < frames_per_buffer_; ++i, j += 2) {
+ (*canonical_freq_channel)[j] =
+ magnitude_channel[i] * std::cos(phase_channel[i]);
+ (*canonical_freq_channel)[j + 1] =
+ magnitude_channel[i] * std::sin(phase_channel[i]);
+ }
+}
+
+void FftManager::CanonicalFreqBufferFromMagnitudeAndSinCosPhase(
+ size_t phase_offset, const AudioBuffer::Channel& magnitude_channel,
+ const AudioBuffer::Channel& sin_phase_channel,
+ const AudioBuffer::Channel& cos_phase_channel,
+ AudioBuffer::Channel* canonical_freq_channel) {
+ static const size_t kSimdLength = 4;
+ DCHECK(canonical_freq_channel);
+ DCHECK_EQ(magnitude_channel.size(), frames_per_buffer_ + 1);
+ DCHECK_GE(sin_phase_channel.size() + phase_offset, frames_per_buffer_ + 1);
+ DCHECK_GE(cos_phase_channel.size() + phase_offset, frames_per_buffer_ + 1);
+ DCHECK_EQ(canonical_freq_channel->size(), fft_size_);
+
+ (*canonical_freq_channel)[0] = magnitude_channel[0];
+ (*canonical_freq_channel)[1] = -magnitude_channel[frames_per_buffer_];
+ // Continue on till we can gaurantee alignment in our audio buffer.
+ for (size_t i = 1, j = 2; i <= kSimdLength; ++i, j += 2) {
+ (*canonical_freq_channel)[j] =
+ magnitude_channel[i] * cos_phase_channel[i + phase_offset];
+ (*canonical_freq_channel)[j + 1] =
+ magnitude_channel[i] * sin_phase_channel[i + phase_offset];
+ }
+ ComplexInterleavedFormatFromMagnitudeAndSinCosPhase(
+ 2 * (frames_per_buffer_ - kSimdLength), &magnitude_channel[kSimdLength],
+ &cos_phase_channel[kSimdLength + phase_offset],
+ &sin_phase_channel[kSimdLength + phase_offset],
+ &(*canonical_freq_channel)[2 * kSimdLength]);
+}
+
+void FftManager::FreqDomainConvolution(const AudioBuffer::Channel& input_a,
+ const AudioBuffer::Channel& input_b,
+ AudioBuffer::Channel* scaled_output) {
+ DCHECK_EQ(input_a.size(), fft_size_);
+ DCHECK_EQ(input_b.size(), fft_size_);
+ DCHECK_EQ(scaled_output->size(), fft_size_);
+ pffft_zconvolve_accumulate(fft_, input_a.begin(), input_b.begin(),
+ scaled_output->begin(), inverse_fft_scale_);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager.h
new file mode 100644
index 000000000..d7869a3d7
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager.h
@@ -0,0 +1,182 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_FFT_MANAGER_H_
+#define RESONANCE_AUDIO_DSP_FFT_MANAGER_H_
+
+#include "pffft.h"
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// This class wraps the pffft library and enables reall FFT transformations to
+// be performed on aligned float buffers of data. The class also manages all
+// necessary data buffers and zero padding. This class is not thread safe.
+class FftManager {
+ public:
+ // Minimum required FFT size.
+ static const size_t kMinFftSize;
+
+ // Constructs a FftManager insatnce. One instance of this class can be shared.
+ // This class is not thread safe.
+ //
+ // @param frames_per_buffer System's number of frames per buffer.
+ explicit FftManager(size_t frames_per_buffer);
+
+ // Destroys a FftManager instance freeing associated aligned memory.
+ ~FftManager();
+
+ // Transforms a single channel of time domain input data into a frequency
+ // domain representation.
+ //
+ // @param time_channel Time domain input. If the length is less than
+ // |fft_size_|, the input is zeropadded. The max length is |fft_size_|.
+ // @param freq_channel Frequency domain output, |fft_size| samples long.
+ void FreqFromTimeDomain(const AudioBuffer::Channel& time_channel,
+ AudioBuffer::Channel* freq_channel);
+
+ // Transforms a single channel of frequency domain input data into a time
+ // domain representation. Note: The input must be in pffft format see:
+ // goo.gl/LYbgX7. This method can output to a buffer of either
+ // |frames_per_buffer_| or |fft_size_| in length. This feature ensures an
+ // additional copy is not needed where this method is to be used with an
+ // overlap add.
+ //
+ // @param freq_channel Frequency domain input, |fft_size| samples long.
+ // @param time_channel Time domain output, |frames_per_buffer_| samples long
+ // OR |fft_size_| samples long.
+ void TimeFromFreqDomain(const AudioBuffer::Channel& freq_channel,
+ AudioBuffer::Channel* time_channel);
+
+ // Applies a 1/|fft_size_| scaling to time domain output. NOTE this need not
+ // be applied where a convolution is taking place as the scaling will be
+ // included therein.
+ //
+ // @param time_channel Time domain data to be scaled.
+ void ApplyReverseFftScaling(AudioBuffer::Channel* time_channel);
+
+ // Transforms a pffft frequency domain format buffer into canonical format
+ // with alternating real and imaginary values with increasing frequency. The
+ // first two entries of |output| are the real part of the DC and Nyquist
+ // frequencies (imaginary part is zero). The alternating real and imaginary
+ // parts start from the third entry in |output|. For more info on the pffft
+ // format see: goo.gl/LYbgX7
+ //
+ // @param input Frequency domain input channel, |fft_size| samples long.
+ // @param output Frequency domain output channel,|fft_size| samples long.
+ void GetCanonicalFormatFreqBuffer(const AudioBuffer::Channel& input,
+ AudioBuffer::Channel* output);
+
+ // Transforms a canonical frequency domain format buffer into pffft format.
+ // For more info on the pffft format see: goo.gl/LYbgX7
+ //
+ // @param input Frequency domain input channel, |fft_size| samples long.
+ // @param output Frequency domain output channel, |fft_size| samples long.
+ void GetPffftFormatFreqBuffer(const AudioBuffer::Channel& input,
+ AudioBuffer::Channel* output);
+
+ // Genarates a buffer containing the single sided magnitude spectrum of a
+ // frequency domain buffer. The input must be in Canonical format. The output
+ // will have DC frequency as it's first entry and the Nyquist as it's last.
+ //
+ // @param freq_channel Canonical format frequency domain buffer,
+ // |fft_size_| samples long.
+ // @param magnitude_channel Magnitude of the |freq_channel|.
+ // |frames_per_buffer_| + 1 samples long.
+ void MagnitudeFromCanonicalFreqBuffer(
+ const AudioBuffer::Channel& freq_channel,
+ AudioBuffer::Channel* magnitude_channel);
+
+ // Combines single sided magnitude and phase spectra into a canonical format
+ // frequency domain buffer. The inputs must have DC frequency as their first
+ // entry and the Nyquist as their last.
+ //
+ // @param magnitude_channel Magnitude of the |frequency_buffer|.
+ // |frames_per_buffer_| + 1 samples long.
+ // @param phase_channel Phase of the |frequency_buffer|.
+ // |frames_per_buffer_| + 1 samples long.
+ // @param canonical_freq_channel Canonical format frequency domain buffer,
+ // |fft_size_| samples long.
+ void CanonicalFreqBufferFromMagnitudeAndPhase(
+ const AudioBuffer::Channel& magnitude_channel,
+ const AudioBuffer::Channel& phase_channel,
+ AudioBuffer::Channel* canonical_freq_channel);
+
+ // Combines single sided magnitude spectrum and the cosine and sine of a phase
+ // spectrum into a canonical format frequency domain buffer. The inputs must
+ // have DC frequency as their first entry and the Nyquist as their last.
+ // The phase spectra channels can be offset by |phase_offset|. This feature
+ // is specifically for use as an optimization in the |SpectralReverb|.
+ //
+ // @param phase_offset An offset into the channels of the phase buffer.
+ // @param magnitude_channel Magnitude of the |frequency_buffer|.
+ // |frames_per_buffer_| + 1 samples long.
+ // @param sin_phase_channel Sine of the phase of the |frequency_buffer|.
+ // |frames_per_buffer_| + 1 samples long.
+ // @param cos_phase_channel Cosine of the phase of the |frequency_buffer|.
+ // |frames_per_buffer_| + 1 samples long.
+ // @param canonical_freq_channel Canonical format frequency domain buffer,
+ // |fft_size_| samples long.
+ void CanonicalFreqBufferFromMagnitudeAndSinCosPhase(
+ size_t phase_offset, const AudioBuffer::Channel& magnitude_channel,
+ const AudioBuffer::Channel& sin_phase_channel,
+ const AudioBuffer::Channel& cos_phase_channel,
+ AudioBuffer::Channel* canonical_freq_channel);
+
+ // Performs a pointwise complex multiplication of two frequency domain buffers
+ // and applies tha inverse scaling factor of 1/|fft_size_|. This operation is
+ // equivalent to a time domain circular convolution.
+ //
+ // @param input_a Frequency domain input channel, |fft_size| samples long.
+ // @param input_b Frequency domain input channel, |fft_size| samples long.
+ // @param scaled_output Frequency domain output channel, |fft_size| samples
+ // long.
+ void FreqDomainConvolution(const AudioBuffer::Channel& input_a,
+ const AudioBuffer::Channel& input_b,
+ AudioBuffer::Channel* scaled_output);
+
+ // Returns the number of points in the FFT.
+ size_t GetFftSize() const { return fft_size_; }
+
+ private:
+ // FFT size in samples.
+ const size_t fft_size_;
+
+ // Number of frames in each buffer of input data.
+ const size_t frames_per_buffer_;
+
+ // Inverse scale to be applied to buffers transformed from frequency to time
+ // domain.
+ const float inverse_fft_scale_;
+
+ // Temporary time domain buffer to store zeropadded input.
+ AudioBuffer temp_zeropad_buffer_;
+
+ // Temporary freq domain buffer to store.
+ AudioBuffer temp_freq_buffer_;
+
+ // pffft states.
+ PFFFT_Setup* fft_;
+
+ // Workspace for pffft. This pointer should be set to null for |fft_size_|
+ // less than 2^14. In which case the stack is used. This is the recommendation
+ // by the author of the pffft library.
+ float* pffft_workspace_ = nullptr;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_FFT_MANAGER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager_test.cc
new file mode 100644
index 000000000..e96ed231c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/fft_manager_test.cc
@@ -0,0 +1,260 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/fft_manager.h"
+
+#include <cstdlib>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+namespace {
+
+const float kInverseFftEpsilon = 2e-5f;
+
+// This tests that the |FreqFromTimeDomain| and |TimeFromFreqDomain|
+// functions are the inverse of one another for a number of fft sizes and signal
+// types.
+TEST(FftManagerTest, FftIfftTest) {
+ // Generate a test signal.
+ const size_t kNumSignalTypes = 3;
+ const size_t kNumBufferLengths = 10;
+ const size_t kBufferLengths[kNumBufferLengths] = {31, 32, 63, 64, 127,
+ 128, 255, 256, 511, 512};
+
+ for (size_t length_idx = 0; length_idx < kNumBufferLengths; length_idx++) {
+ for (size_t type = 0; type < kNumSignalTypes; ++type) {
+ AudioBuffer time_signal(kNumMonoChannels, kBufferLengths[length_idx]);
+ for (size_t i = 0; i < kBufferLengths[length_idx]; ++i) {
+ switch (type) {
+ case 0:
+ time_signal[0][i] = static_cast<float>(i) /
+ static_cast<float>(kBufferLengths[length_idx]);
+ break;
+ case 1:
+ time_signal[0][i] = std::cos(static_cast<float>(i));
+ break;
+ case 2:
+ time_signal[0][i] = static_cast<float>(i % 2) * -0.5f;
+ break;
+ }
+ }
+ AudioBuffer freq_signal(kNumMonoChannels,
+ NextPowTwo(kBufferLengths[length_idx]) * 2);
+ AudioBuffer output(kNumMonoChannels, kBufferLengths[length_idx]);
+ output.Clear();
+
+ FftManager fft_manager(kBufferLengths[length_idx]);
+
+ fft_manager.FreqFromTimeDomain(time_signal[0], &freq_signal[0]);
+ fft_manager.TimeFromFreqDomain(freq_signal[0], &output[0]);
+ fft_manager.ApplyReverseFftScaling(&output[0]);
+
+ for (size_t i = 0; i < kBufferLengths[length_idx]; ++i) {
+ EXPECT_NEAR(output[0][i], time_signal[0][i], kEpsilonFloat);
+ }
+ }
+ }
+}
+
+// Tests that the result from an inverse FFT is the same whether it is written
+// into a buffer of |frames_per_buffer_| or |fft_size_| in length.
+TEST(FftManagerTest, ReverseFftOutputSizeTest) {
+ const size_t kFramesPerBuffer = 32;
+ AudioBuffer freq_buffer(kNumMonoChannels, 2 * kFramesPerBuffer);
+ freq_buffer.Clear();
+ AudioBuffer time_buffer_short(kNumMonoChannels, kFramesPerBuffer);
+ time_buffer_short.Clear();
+ AudioBuffer time_buffer_long(kNumMonoChannels, 2 * kFramesPerBuffer);
+ time_buffer_long.Clear();
+ AudioBuffer input_buffer(kNumMonoChannels, kFramesPerBuffer);
+
+ std::srand(0);
+ for (auto& sample : input_buffer[0]) {
+ sample = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
+ }
+
+ FftManager fft_manager(kFramesPerBuffer);
+ fft_manager.FreqFromTimeDomain(input_buffer[0], &freq_buffer[0]);
+ fft_manager.TimeFromFreqDomain(freq_buffer[0], &time_buffer_short[0]);
+ fft_manager.ApplyReverseFftScaling(&time_buffer_short[0]);
+ fft_manager.TimeFromFreqDomain(freq_buffer[0], &time_buffer_long[0]);
+ fft_manager.ApplyReverseFftScaling(&time_buffer_long[0]);
+
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ EXPECT_NEAR(time_buffer_short[0][i], time_buffer_long[0][i], kEpsilonFloat);
+ EXPECT_NEAR(time_buffer_long[0][i + kFramesPerBuffer], 0.0f,
+ kInverseFftEpsilon);
+ }
+}
+
+// Tests that a frequency domain buffer can be transformed into a canonical
+// format and back.
+TEST(FftManagerTest, PffftFormatToCanonicalFormatTest) {
+ const size_t kFramesPerBuffer = 32;
+ AudioBuffer time_buffer(kNumMonoChannels, kFramesPerBuffer);
+ time_buffer.Clear();
+ time_buffer[0][0] = 1.0f;
+ time_buffer[0][1] = 1.0f;
+ AudioBuffer freq_buffer(kNumMonoChannels, 2 * kFramesPerBuffer);
+ freq_buffer.Clear();
+ AudioBuffer reordered_buffer(kNumMonoChannels, 2 * kFramesPerBuffer);
+ reordered_buffer.Clear();
+ AudioBuffer final_buffer(kNumMonoChannels, 2 * kFramesPerBuffer);
+ reordered_buffer.Clear();
+
+ FftManager fft_manager(kFramesPerBuffer);
+ fft_manager.FreqFromTimeDomain(time_buffer[0], &freq_buffer[0]);
+
+ fft_manager.GetCanonicalFormatFreqBuffer(freq_buffer[0],
+ &reordered_buffer[0]);
+ fft_manager.GetPffftFormatFreqBuffer(reordered_buffer[0], &final_buffer[0]);
+
+ for (size_t i = 0; i < kFramesPerBuffer * 2; ++i) {
+ EXPECT_NEAR(final_buffer[0][i], freq_buffer[0][i], kEpsilonFloat);
+ }
+}
+
+// Tests that for a scaled kronecker delta, the magnitude response will be flat
+// and equal to the absolute magnitude of the kronecker.
+TEST(FftManagerTest, MagnitudeTest) {
+ const size_t kFramesPerBuffer = 32;
+ const size_t kMagnitudeLength = kFramesPerBuffer + 1;
+ FftManager fft_manager(kFramesPerBuffer);
+ AudioBuffer time_buffer(kNumMonoChannels, kFramesPerBuffer);
+ time_buffer.Clear();
+ AudioBuffer freq_buffer(kNumMonoChannels, 2 * kFramesPerBuffer);
+ AudioBuffer reordered_buffer(kNumMonoChannels, 2 * kFramesPerBuffer);
+ AudioBuffer magnitude_buffer(kNumMonoChannels, kMagnitudeLength);
+ const std::vector<float> magnitudes = {1.0f, 2.0f, 3.0f, -1.0f, -2.0f, -3.0f};
+
+ for (auto& magnitude : magnitudes) {
+ time_buffer[0][0] = magnitude;
+ fft_manager.FreqFromTimeDomain(time_buffer[0], &freq_buffer[0]);
+ fft_manager.GetCanonicalFormatFreqBuffer(freq_buffer[0],
+ &reordered_buffer[0]);
+ fft_manager.MagnitudeFromCanonicalFreqBuffer(reordered_buffer[0],
+ &magnitude_buffer[0]);
+ for (size_t sample = 0; sample < kMagnitudeLength; ++sample) {
+ // Check its correct to within 0.5%.
+ const float kErrEpsilon = 5e-3f;
+ const float expected = std::abs(magnitude);
+ EXPECT_NEAR(magnitude_buffer[0][sample], expected,
+ kErrEpsilon * expected);
+ }
+ }
+}
+
+// Tests that conversion from Canonical frequency domain data to phase and
+// magnitude spectra and back results in an output equal to the input.
+TEST(FftManagerTest, FreqFromMagnitudePhase) {
+ const size_t kFramesPerBuffer = 16;
+ const size_t kMagnitudePhaseLength = kFramesPerBuffer + 1;
+ FftManager fft_manager(kFramesPerBuffer);
+ AudioBuffer time_buffer(kNumMonoChannels, kFramesPerBuffer);
+ time_buffer.Clear();
+ time_buffer[0][0] = 0.5f;
+ time_buffer[0][1] = 1.0f;
+ AudioBuffer freq_buffer(kNumMonoChannels, 2 * kFramesPerBuffer);
+ AudioBuffer reordered_buffer(kNumMonoChannels, 2 * kFramesPerBuffer);
+ AudioBuffer phase_buffer(kNumMonoChannels, kMagnitudePhaseLength);
+ AudioBuffer magnitude_buffer(kNumMonoChannels, kMagnitudePhaseLength);
+ fft_manager.FreqFromTimeDomain(time_buffer[0], &freq_buffer[0]);
+ fft_manager.GetCanonicalFormatFreqBuffer(freq_buffer[0],
+ &reordered_buffer[0]);
+ fft_manager.MagnitudeFromCanonicalFreqBuffer(reordered_buffer[0],
+ &magnitude_buffer[0]);
+
+ // Calculate the phase.
+ phase_buffer[0][0] = 0.0f;
+ for (size_t i = 1, j = 2; i < kFramesPerBuffer; ++i, j += 2) {
+ phase_buffer[0][i] = std::atan2(reordered_buffer[0][j + 1] /*imag*/,
+ reordered_buffer[0][j] /*real*/);
+ }
+ phase_buffer[0][kFramesPerBuffer] = kPi;
+
+ fft_manager.CanonicalFreqBufferFromMagnitudeAndPhase(
+ magnitude_buffer[0], phase_buffer[0], &freq_buffer[0]);
+
+ for (size_t sample = 0; sample < kFramesPerBuffer * 2; ++sample) {
+ // Check its correct to within 0.5%.
+ const float kErrEpsilon = 5e-3f;
+ EXPECT_NEAR(freq_buffer[0][sample], reordered_buffer[0][sample],
+ kErrEpsilon * std::abs(reordered_buffer[0][sample]));
+ }
+}
+
+// Tests that conversion from phase and magnitude spectra and back results in
+// an output equal to that from sine and cosine phase, using SIMD on arm.
+TEST(FftManagerTest, FMagnitudePhaseAndSineCosinePhase) {
+ const size_t kFramesPerBuffer = 16;
+ const size_t kMagnitudePhaseLength = kFramesPerBuffer + 1;
+ FftManager fft_manager(kFramesPerBuffer);
+ AudioBuffer freq_buffer_one(kNumMonoChannels, 2 * kFramesPerBuffer);
+ AudioBuffer freq_buffer_two(kNumMonoChannels, 2 * kFramesPerBuffer);
+ AudioBuffer phase_buffer(kNumMonoChannels, kMagnitudePhaseLength);
+ AudioBuffer sin_phase_buffer(kNumMonoChannels, kMagnitudePhaseLength);
+ AudioBuffer cos_phase_buffer(kNumMonoChannels, kMagnitudePhaseLength);
+ AudioBuffer magnitude_buffer(kNumMonoChannels, kMagnitudePhaseLength);
+
+ std::fill(magnitude_buffer[0].begin(), magnitude_buffer[0].end(), 2.0f);
+ phase_buffer[0] = std::vector<float>(
+ {0.4720f, 1.6100f, -1.9831f, 0.7569f, 0.2799f, -1.1481f, -0.3807f,
+ 0.3008f, 3.1416f, 2.4314f, -1.1851f, 2.6645f, 0.6369f, -0.0554f, 0.6275f,
+ -0.1799f, 1.2345f});
+ for (size_t i = 0; i < phase_buffer.num_frames(); ++i) {
+ sin_phase_buffer[0][i] = std::sin(phase_buffer[0][i]);
+ cos_phase_buffer[0][i] = std::cos(phase_buffer[0][i]);
+ }
+
+ fft_manager.CanonicalFreqBufferFromMagnitudeAndPhase(
+ magnitude_buffer[0], phase_buffer[0], &freq_buffer_one[0]);
+ fft_manager.CanonicalFreqBufferFromMagnitudeAndSinCosPhase(
+ 0, /* phase_offset */
+ magnitude_buffer[0], sin_phase_buffer[0], cos_phase_buffer[0],
+ &freq_buffer_two[0]);
+
+ for (size_t i = 0; i < kFramesPerBuffer * 2; ++i) {
+ EXPECT_NEAR(freq_buffer_one[0][i], freq_buffer_two[0][i], kEpsilonFloat);
+ }
+}
+
+// Tests that the correct scaling factor is applied consistently across a time
+// domain buffer.
+TEST(FftManagerTest, ReverseScalingTest) {
+ const size_t kFramesPerBuffer = 128;
+ const float kExpectedScale = 1.0f / static_cast<float>(2 * kFramesPerBuffer);
+
+ AudioBuffer buffer(kNumMonoChannels, kFramesPerBuffer);
+ for (auto& sample : buffer[0]) {
+ sample = 1.0f;
+ }
+ FftManager fft_manager(kFramesPerBuffer);
+
+ fft_manager.ApplyReverseFftScaling(&buffer[0]);
+ for (auto& sample : buffer[0]) {
+ EXPECT_NEAR(sample, kExpectedScale, kEpsilonFloat);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators.cc
new file mode 100644
index 000000000..11d19694d
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators.cc
@@ -0,0 +1,165 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/filter_coefficient_generators.h"
+
+#include <algorithm>
+#include <cmath>
+
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// Hard coded 4th order fit calculated from:
+
+const int kPolynomialOrder = 4;
+const float kPolynomialCoefficients[] = {
+ 2.52730826376129e-06f, 0.00018737263228963f, 0.00618822707412605f,
+ 0.113947188715447f, 0.999048314740445f};
+
+// Threshold frequency for human hearing 20Hz.
+const float kTwentyHz = 20.0f;
+
+// ln(2)/2 for use in bandpass filter.
+const float kLn2over2 = 0.346573590279973f;
+
+} // namespace
+
+BiquadCoefficients ComputeBandPassBiquadCoefficients(int sample_rate,
+ float center_frequency,
+ int bandwidth) {
+ DCHECK_GT(sample_rate, 0);
+ DCHECK_GE(center_frequency, 0.0f);
+ DCHECK_GT(bandwidth, 0);
+ // Check if an invalid |center_frequency|, greater than or equal to the
+ // Nyquist rate is passed as input.
+ CHECK_LT(center_frequency, 0.5f * static_cast<float>(sample_rate));
+
+ // Frequency of interest (in radians).
+ const float w0 = kTwoPi * center_frequency / static_cast<float>(sample_rate);
+ // Intermediate storage.
+ const float cos_w0 = std::cos(w0);
+ const float sin_w0 = std::sin(w0);
+ const float alpha =
+ sin_w0 * sinhf(kLn2over2 * static_cast<float>(bandwidth) * w0 / sin_w0);
+
+ // The BiquadFilterState constructor is passed (a0, a1, a2, b0, b1, b2).
+ return BiquadCoefficients(1.0f + alpha, -2.0f * cos_w0, 1.0f - alpha, alpha,
+ 0.0f, -alpha);
+}
+
+void ComputeDualBandBiquadCoefficients(
+ int sample_rate, float crossover_frequency,
+ BiquadCoefficients* low_pass_coefficients,
+ BiquadCoefficients* high_pass_coefficients) {
+ DCHECK_GT(sample_rate, 0);
+ DCHECK_GE(crossover_frequency, 0.0f);
+ DCHECK_LE(crossover_frequency, static_cast<float>(sample_rate) / 2.0f);
+ DCHECK(low_pass_coefficients);
+ DCHECK(high_pass_coefficients);
+
+ const float k = std::tan(static_cast<float>(M_PI) * crossover_frequency /
+ static_cast<float>(sample_rate));
+ const float k_squared = k * k;
+ const float denominator = k_squared + 2.0f * k + 1.0f;
+
+ // |denominator| must not be near 0. Since |k| is always guaranteed to be in
+ // the range 0 < k < pi/2, the |denominator| should always be >=1. This is a
+ // sanity check only.
+ DCHECK_GT(denominator, kEpsilonDouble);
+
+ // Computes numerator coefficients of the low-pass |low_pass_coefficients|
+ // bi-quad.
+ low_pass_coefficients->a[0] = 1.0f;
+ low_pass_coefficients->a[1] = 2.0f * (k_squared - 1.0f) / denominator;
+ low_pass_coefficients->a[2] = (k_squared - 2.0f * k + 1.0f) / denominator;
+
+ // Numerator coefficients of the high-pass |high_pass_coefficients| bi-quad
+ // are the same.
+ BiquadCoefficients high_pass;
+ std::copy(low_pass_coefficients->a.begin(), low_pass_coefficients->a.end(),
+ high_pass_coefficients->a.begin());
+
+ // Computes denominator coefficients of the low-pass |low_pass_coefficients|
+ // bi-quad.
+ low_pass_coefficients->b[0] = k_squared / denominator;
+ low_pass_coefficients->b[1] = 2.0f * low_pass_coefficients->b[0];
+ low_pass_coefficients->b[2] = low_pass_coefficients->b[0];
+
+ // Computes denominator coefficients of the high-pass |high_pass_coefficients|
+ // bi-quad.
+ high_pass_coefficients->b[0] = 1.0f / denominator;
+ high_pass_coefficients->b[1] = -2.0f * high_pass_coefficients->b[0];
+ high_pass_coefficients->b[2] = high_pass_coefficients->b[0];
+}
+
+BiquadCoefficients ComputeLowPassBiquadCoefficients(
+ int sample_rate, float specification_frequency, float attenuation) {
+ DCHECK_GT(sample_rate, 0);
+ DCHECK_GE(specification_frequency, 0.0f);
+ DCHECK_LE(specification_frequency, static_cast<float>(sample_rate) / 2.0f);
+ DCHECK_LT(attenuation, 0.0f);
+
+ // Frequency of interest (in radians).
+ const float w0 =
+ kTwoPi * specification_frequency / static_cast<float>(sample_rate);
+
+ // Q is the Q-factor. For more information see "Digital Signal Processing" -
+ // J. G. Prolakis, D. G. Manolakis - Published by Pearson.
+ float Q = 0.0f;
+
+ // Variable to handle the growth in power as one extra mult per iteration
+ // across the polynomial coefficients.
+ float attenuation_to_a_power = 1.0f;
+
+ // Add in each term in reverse order.
+ for (int order = kPolynomialOrder; order >= 0; --order) {
+ Q += kPolynomialCoefficients[order] * attenuation_to_a_power;
+ attenuation_to_a_power *= attenuation;
+ }
+
+ // Intermediate storage of commonly used values.
+ const float alpha = std::sin(w0) / (2.0f * Q);
+ const float cos_w0 = std::cos(w0);
+
+ // Filter coefficients.
+ float a0 = 1.0f + alpha;
+ float a1 = -2.0f * cos_w0;
+ float a2 = 1.0f - alpha;
+ // Coefficients b0 and b2 will have the same value in this case.
+ float b0_b2 = (1.0f - cos_w0) / 2.0f;
+ float b1 = 1.0f - cos_w0;
+
+ return BiquadCoefficients(a0, a1, a2, b0_b2, b1, b0_b2);
+}
+
+float ComputeLowPassMonoPoleCoefficient(float cuttoff_frequency,
+ int sample_rate) {
+ float coefficient = 0.0f;
+ // Check that the cuttoff_frequency provided is not too low (below human
+ // threshold, also danger of filter instability).
+ if (cuttoff_frequency > kTwentyHz) {
+ const float inverse_time_constant = kTwoPi * cuttoff_frequency;
+ const float sample_rate_float = static_cast<float>(sample_rate);
+ coefficient =
+ sample_rate_float / (inverse_time_constant + sample_rate_float);
+ }
+ return coefficient;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators.h
new file mode 100644
index 000000000..4c7659a7a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators.h
@@ -0,0 +1,177 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_FILTER_COEFFICIENT_GENERATORS_H_
+#define RESONANCE_AUDIO_DSP_FILTER_COEFFICIENT_GENERATORS_H_
+
+#include "dsp/biquad_filter.h"
+
+// Functions for the generation of filter coefficients for various common tasks.
+// Currently supports the following filter types:
+// Low pass first-order filter.
+// Low pass biquad filter.
+// Band pass biquad filter.
+// Dual band, matched phase biquad shelf filters.
+namespace vraudio {
+
+// Computes corresponding biquad coefficients for band pass filter with respect
+// to the centre frequency and the bandwidth between -3 dB frequencies.
+//
+// b0 + b1*z^-1 + b2*z^-2
+// H(z) = ------------------------
+// a0 + a1*z^-1 + a2*z^-2
+//
+// where:
+// w0 = 2*pi*center_frequency/sample_rate
+//
+// alpha = sin(w0)*sinh( ln(2)/2 * bandwidth * w0/sin(w0) )
+//
+// b0 = alpha
+// b1 = 0
+// b2 = -alpha
+// a0 = 1 + alpha
+// a1 = -2*cos(w0)
+// a2 = 1 - alpha
+//
+// @param sample_rate Sampling rate in Hz.
+// @param centre_frequency Centre frequency of passband.
+// @param bandwidth Bandwidth in octaves between -3 dB frequencies.
+// @return Output structure of band-pass BiquadCoefficients.
+BiquadCoefficients ComputeBandPassBiquadCoefficients(int sample_rate,
+ float centre_frequency,
+ int bandwidth);
+
+// Computes two sets of transfer function coefficients to be used with a
+// pair of generic bi-quad filters. The coefficients are used to implement a
+// phase-matched low-pass |low_pass_state| and high-pass |high_pass_state|
+// filter pair with a cross-over frequency defined as |crossover_frequency|.
+//
+// Implementation of the matched bi-quad filter pair as described in:
+// http://www.ai.sri.com/ajh/ambisonics/BLaH3.pdf
+//
+// b0 + b1*z^-1 + b2*z^-2
+// H(z) = ------------------------
+// a0 + a1*z^-1 + a2*z^-2
+//
+// where:
+//
+// a0 = 1
+//
+// 2(k^2 − 1)
+// a1 = --------------
+// k^2 + 2k + 1
+//
+// k^2 - 2k + 1
+// a2 = --------------
+// k^2 + 2k + 1
+//
+// low-pass: high-pass:
+//
+// k^2 1
+// b0 = ------------- b0 = --------------
+// k^2 + 2k + 1 k^2 + 2k + 1
+//
+// b1 = 2b0 b1 = -2b0
+//
+// b2 = b0 b2 = b0
+//
+// and
+//
+// pi * crossover_frequency
+// k = tan --------------------------
+// sample_frequency
+//
+// @param sample_rate Sampling rate in [Hz]
+// @param crossover_frequency Cross-over frequency in [Hz]
+// @param low_pass_coefficients Output structure of low-pass bi-quad
+// coefficients
+// @param high_pass_coefficients Output structure of high-pass bi-quad
+// coefficients.
+void ComputeDualBandBiquadCoefficients(
+ int sample_rate, float crossover_frequency,
+ BiquadCoefficients* low_pass_coefficients,
+ BiquadCoefficients* high_pass_coefficients);
+
+// Computes biquad coefficients for low pass filter with respect to the
+// specification frequency and the attenuation value at that frequency.
+//
+// b0 + b1*z^-1 + b2*z^-2
+// H(z) = ------------------------
+// a0 + a1*z^-1 + a2*z^-2
+//
+// where:
+// Q = 2.5273e-06*attenuation^4 + 0.00018737*attenuation^3 +
+// 0.0061882*attenuation^2 + 0.11395*attenuation + 0.99905
+//
+// w0 = 2*pi*specification_frequency/sample_rate;
+//
+// alpha = sin(w0)/(2*Q);
+//
+// a0 = 1 + alpha;
+// a1 = -2*cos(w0);
+// a2 = 1 - alpha;
+// b0 = (1 - cos(w0))/2;
+// b1 = 1 - cos(w0);
+// b2 = (1 - cos(w0)/2;
+//
+// These coefficients were generated after a bilinerar transform of an
+// analogue filter H(s) = 1 / (s^2 + s/Q + 1), from:
+// www.analog.com/library/analogdialogue/archives/43-09/edch%208%20filter.pdf.
+//
+// Please note Q has been calculated by fitting a 4th order polynomial to the
+// average of Q vs attenuation curves at different f0's from 10kHz to 19kHz.
+// Please note that at differing frequencies these graphs had identical shape
+// and differed only by an overall offset of at most 0.1 (attenuation) dB from
+// the mean. This script can be found at
+
+//
+// @param sample_rate Sampling rate in Hz.
+// @param specification_frequency Frequency at which attenuation applies in Hz.
+// @param attenuation Attenuation at specification_frequency in negative dB.
+// @return low_pass Output structure of low-pass BiquadCoefficients.
+BiquadCoefficients ComputeLowPassBiquadCoefficients(
+ int sample_rate, float specification_frequency, float attenuation);
+
+// Generates a coefficient for the |MonoPoleFilterClass| based on a 3dB
+// bandwidth.
+//
+// The Laplace transfer function of a first order low pass system is:
+//
+// 1
+// ------------ where tau is the RC time constant of the system.
+// 1 + tau * s
+//
+// For a discrete moving average filter with input x[n] and output y[n],
+// the difference equation is:
+// y[n] = a * y[n - 1] + (1 - a) * x[n]
+// tau
+// a = ---------- where T is the sample period.
+// tau + T
+// since the -3dB bandwith of a first order system can be
+// 1 related to its time constant by
+// f3 = --------------
+// 2 * pi * tau we can obtain 'a' from cuttoff_frequency and
+// sample rate.
+//
+// @param cuttoff_frequency The -3dB frequency in Hz of the low pass lobe.
+// @param sample_rate System sampling rate.
+// @return A |MonoPoleFilterClass| coefficient for the specified bandwidth.
+float ComputeLowPassMonoPoleCoefficient(float cuttoff_frequency,
+ int sample_rate);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_FILTER_COEFFICIENT_GENERATORS_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators_test.cc
new file mode 100644
index 000000000..163b6a6d2
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/filter_coefficient_generators_test.cc
@@ -0,0 +1,146 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/filter_coefficient_generators.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+
+namespace vraudio {
+
+namespace {
+
+// Allowable error between filter coefficients.
+const float kErrorf = 1e-5f;
+
+// Input into the ComputeLowPassBiquadCoefficients() function.
+const int kSampleRate = 44100;
+const float kSpecificationFrequency = 13000.0f;
+const float kAttenuation = -15.0f;
+
+const float kMonoPoleCoefficient = 0.94863985f;
+
+// These filter coefficients were calculated in MATLAB with a specified Q value
+// of 0.17775. The attenuation at the specification frequency was then
+// calculated from the MATLAB freqz() calls.
+const BiquadCoefficients kIdealCoefficients(3.70224817628938f,
+ 0.555382147099001f,
+ -1.70224817628938f,
+ 0.63884553677475f, 1.2776910735495f,
+ 0.63884553677475f);
+
+// These filter coefficients were calculated in MATLAB for a centre_frequency of
+// 8kHz and a bandwidth of 1 octave.
+const BiquadCoefficients kIdealBandpassCoefficients(1.37364799922092f, -1.0f,
+ 0.626352000779082f,
+ 0.373647999220918f, 0.0f,
+ -0.373647999220918f);
+
+const float kBandPassCenterFrequency = 8000.0f;
+const int kBandPassOctaveBandwidth = 1;
+
+// Input into the ComputeDualBandBiquadCoefficients() function.
+const int kSampleRate48 = 48000;
+const float kCrossoverFrequency = 380.0f;
+
+// Pre-computed coefficients for the phase-matched filter pair (dual-band) with
+// the cross-over frequency set at 380Hz and the sample rate 48kHz.
+const float kLowPassA[] = {1.0f, -1.9029109f, 0.90526748f};
+const float kLowPassB[] = {0.00058914319f, 0.0011782864f, 0.00058914319f};
+const float kHighPassA[] = {1.0f, -1.9029109f, 0.90526748f};
+const float kHighPassB[] = {0.95204461f, -1.9040892f, 0.95204461f};
+
+TEST(FilterCoefficientGeneratorsTest, ComputeMonoPoleLowpassCoefficientTest) {
+ float coefficient =
+ ComputeLowPassMonoPoleCoefficient(kCrossoverFrequency, kSampleRate);
+ EXPECT_NEAR(kMonoPoleCoefficient, coefficient, kErrorf);
+
+ const float twenty_hertz = 20.0f;
+ coefficient = ComputeLowPassMonoPoleCoefficient(twenty_hertz, kSampleRate);
+ EXPECT_EQ(0.0f, coefficient);
+ // New test for the case where a frequency below 20Hz is passed.
+}
+
+// Tests that the BiquadCoefficients generated by
+// ComputeBandPassBiquadCoefficients() match those known to be correct as
+// directly calculated from MATLAB.
+TEST(FilterCoefficientGeneratorsTest, ComputeBandPassBiquadCoefficientsTest) {
+ // Perform computation.
+ BiquadCoefficients biquad_filter_coefficients =
+ ComputeBandPassBiquadCoefficients(kSampleRate48, kBandPassCenterFrequency,
+ kBandPassOctaveBandwidth);
+
+ // Make sure they are all equal.
+ for (size_t i = 0; i < biquad_filter_coefficients.a.size(); ++i) {
+ EXPECT_NEAR(kIdealBandpassCoefficients.a[i],
+ biquad_filter_coefficients.a[i], kErrorf);
+ EXPECT_NEAR(kIdealBandpassCoefficients.b[i],
+ biquad_filter_coefficients.b[i], kErrorf);
+ }
+}
+
+// Tests that the BiquadCoefficients generated by
+// ComputeLowPassBiquadCoefficients() match those known to be correct as
+// directly calculated from MATLAB. This also tests the validity of the inherent
+// 4th order best fit between attenuation at a specified frequency and Q factor.
+TEST(FilterCoefficientGeneratorsTest, ComputeLowPassBiquadCoefficientsTest) {
+ // Perform computation.
+ BiquadCoefficients biquad_filter_coefficients =
+ ComputeLowPassBiquadCoefficients(kSampleRate, kSpecificationFrequency,
+ kAttenuation);
+
+ // Make sure they are all equal.
+ for (size_t i = 0; i < biquad_filter_coefficients.a.size(); ++i) {
+ EXPECT_NEAR(kIdealCoefficients.a[i], biquad_filter_coefficients.a[i],
+ kErrorf);
+ EXPECT_NEAR(kIdealCoefficients.b[i], biquad_filter_coefficients.b[i],
+ kErrorf);
+ }
+}
+
+// Tests that the BiquadCoefficients generated by
+// ComputeDualBandBiquadCoefficients() match those known to be correct as
+// directly calculated from MATLAB. These coefficients are as described in:
+// http://www.ai.sri.com/ajh/ambisonics/BLaH3.pdf.
+TEST(DualBandBiquadCoefficientsTest, ComputeDualBandBiquadCoefficientsTest) {
+ // Generate default bi-quad coefficients and constructs low- and high-pass
+ // filter coefficients.
+ const BiquadCoefficients kDefaultCoefficients;
+ BiquadCoefficients low_pass_coefficients(kDefaultCoefficients);
+ BiquadCoefficients high_pass_coefficients(kDefaultCoefficients);
+
+ // Perform computation.
+ ComputeDualBandBiquadCoefficients(kSampleRate48, kCrossoverFrequency,
+ &low_pass_coefficients,
+ &high_pass_coefficients);
+
+ // Check if arrays with a and b coefficients for both filters are of the
+ // same size.
+ ASSERT_EQ(low_pass_coefficients.a.size(), low_pass_coefficients.b.size());
+ ASSERT_EQ(high_pass_coefficients.a.size(), low_pass_coefficients.a.size());
+ ASSERT_EQ(high_pass_coefficients.b.size(), low_pass_coefficients.b.size());
+
+ // Make sure they are all equal.
+ for (size_t i = 0; i < low_pass_coefficients.a.size(); ++i) {
+ EXPECT_NEAR(low_pass_coefficients.a[i], kLowPassA[i], kErrorf);
+ EXPECT_NEAR(low_pass_coefficients.b[i], kLowPassB[i], kErrorf);
+ EXPECT_NEAR(high_pass_coefficients.a[i], kHighPassA[i], kErrorf);
+ EXPECT_NEAR(high_pass_coefficients.b[i], kHighPassB[i], kErrorf);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter.cc
new file mode 100644
index 000000000..e77ab71ce
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter.cc
@@ -0,0 +1,148 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "dsp/fir_filter.h"
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/simd_macros.h"
+
+namespace vraudio {
+
+FirFilter::FirFilter(const AudioBuffer::Channel& filter_coefficients,
+ size_t frames_per_buffer) {
+ DCHECK_GE(filter_coefficients.size(), 1U);
+ // Create the kernel buffer in repeated entry representation from standard
+ // form FIR representation.
+ const size_t coefficients_length = filter_coefficients.size();
+ filter_length_ = coefficients_length +
+ ((coefficients_length % SIMD_LENGTH == 0)
+ ? 0
+ : SIMD_LENGTH - (coefficients_length % SIMD_LENGTH));
+ num_filter_chunks_ = filter_length_ / SIMD_LENGTH;
+ DCHECK_EQ(filter_length_ % SIMD_LENGTH, 0);
+ coefficients_ = AudioBuffer(kNumMonoChannels, filter_length_ * SIMD_LENGTH);
+ AudioBuffer::Channel* coefficients = &(coefficients_[0]);
+ // Store the coefficients so that each individual coefficient is repeated
+ // SIMD_LENGTH times.
+ for (size_t coeff = 0; coeff < coefficients_length; ++coeff) {
+ auto coefficient_iter = coefficients->begin() + (coeff * SIMD_LENGTH);
+ std::fill(coefficient_iter, coefficient_iter + SIMD_LENGTH,
+ filter_coefficients[coeff]);
+ }
+ std::fill(coefficients->begin() + (coefficients_length * SIMD_LENGTH),
+ coefficients->end(), 0.0f);
+ // Allocate an aligned buffer with |filter_length_| extra samples to
+ // store previous input samples.
+ state_ = AudioBuffer(kNumMonoChannels, frames_per_buffer + filter_length_);
+ state_.Clear();
+}
+
+void FirFilter::Process(const AudioBuffer::Channel& input,
+ AudioBuffer::Channel* output) {
+ DCHECK(output);
+ DCHECK_EQ(input.size(), state_.num_frames() - filter_length_);
+ // In this case we know that SIMD_LENGTH == 1, therefore we don't need to take
+ // account of it.
+ const size_t input_length = input.size();
+ std::copy_n(state_[0].end() - filter_length_, filter_length_,
+ state_[0].begin());
+ std::copy_n(input.begin(), input_length, state_[0].begin() + filter_length_);
+#if defined(SIMD_DISABLED)
+ AudioBuffer::Channel* coefficients = &(coefficients_[0]);
+ AudioBuffer::Channel* data = &(state_[0]);
+ for (size_t frame = 0; frame < input_length; ++frame) {
+ for (size_t coeff = 0; coeff < filter_length_; ++coeff) {
+ (*output)[frame] +=
+ (*coefficients)[coeff] * (*data)[filter_length_ - coeff];
+ }
+ }
+#else
+ const SimdVector* cptr_input =
+ reinterpret_cast<const SimdVector*>(&(state_[0][0]));
+ const SimdVector* cptr_filter =
+ reinterpret_cast<const SimdVector*>(&(coefficients_[0][0]));
+ SimdVector* ptr_output = reinterpret_cast<SimdVector*>(&((*output)[0]));
+
+ const size_t num_input_chunks = input_length / SIMD_LENGTH;
+ DCHECK_EQ(input_length % SIMD_LENGTH, 0);
+
+ // A pair of |SimdVector|s one for holding the input for each operation, the
+ // other to store data that needed to be copied as it straddled a four float
+ // boundary.
+ SimdVector input_use;
+ SimdVector input_split;
+ for (size_t input_position = num_filter_chunks_;
+ input_position < num_input_chunks + num_filter_chunks_;
+ ++input_position) {
+ // Replace these with the indexed pointers to save on copies.
+ SimdVector* output_now = &ptr_output[input_position - num_filter_chunks_];
+ DCHECK_GE(input_position, num_filter_chunks_);
+
+ for (size_t chunk = 0; chunk < num_filter_chunks_; ++chunk) {
+ const size_t filter_index_offset = chunk * SIMD_LENGTH;
+ const SimdVector* input_a = &cptr_input[input_position - (chunk + 1)];
+ const SimdVector* input_b = &cptr_input[input_position - chunk];
+#if defined(SIMD_SSE)
+ // Select four floats from input_a and input_b, based on the mask. Here we
+ // take the latter two entries from input_b followed by the first two
+ // entries of input_a.
+ input_split = _mm_shuffle_ps(*input_a, *input_b, _MM_SHUFFLE(1, 0, 3, 2));
+
+ // All from input_b.
+ *output_now = SIMD_MULTIPLY_ADD(
+ *input_b, cptr_filter[filter_index_offset], *output_now);
+ // One from input_a and the rest (three) from input_b.
+ input_use =
+ _mm_shuffle_ps(input_split, *input_b, _MM_SHUFFLE(2, 1, 2, 1));
+ *output_now = SIMD_MULTIPLY_ADD(
+ input_use, cptr_filter[1 + filter_index_offset], *output_now);
+ // Two from input_a and two from input_b.
+ *output_now = SIMD_MULTIPLY_ADD(
+ input_split, cptr_filter[2 + filter_index_offset], *output_now);
+ // Three from input_a and one from input_b.
+ input_use =
+ _mm_shuffle_ps(*input_a, input_split, _MM_SHUFFLE(2, 1, 2, 1));
+ *output_now = SIMD_MULTIPLY_ADD(
+ input_use, cptr_filter[3 + filter_index_offset], *output_now);
+#elif defined(SIMD_NEON)
+ // All from input_b.
+ *output_now = SIMD_MULTIPLY_ADD(
+ *input_b, cptr_filter[filter_index_offset], *output_now);
+ // One from input_a and the rest (three) from input_b.
+ input_use = vextq_f32(*input_a, *input_b, 3);
+ *output_now = SIMD_MULTIPLY_ADD(
+ input_use, cptr_filter[1 + filter_index_offset], *output_now);
+ // Two from input_a and two from input_b.
+ input_use = vextq_f32(*input_a, *input_b, 2);
+ *output_now = SIMD_MULTIPLY_ADD(
+ input_use, cptr_filter[2 + filter_index_offset], *output_now);
+ // Three from input_a and one from input_b.
+ input_use = vextq_f32(*input_a, *input_b, 1);
+ *output_now = SIMD_MULTIPLY_ADD(
+ input_use, cptr_filter[3 + filter_index_offset], *output_now);
+#endif // SIMD_SSE/SIMD_NEON
+ }
+ }
+#endif // SIMD_DISABLED
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter.h
new file mode 100644
index 000000000..46c1edde5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter.h
@@ -0,0 +1,62 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_FIR_FILTER_H_
+#define RESONANCE_AUDIO_DSP_FIR_FILTER_H_
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+class FirFilter {
+ public:
+ // Constructs a |FirFilter| from a mono |AudioBuffer| of filter coefficients.
+ //
+ // @param filter_coefficients FIR filter coefficients.
+ // @param frames_per_buffer Number of frames of data in each audio buffer.
+ FirFilter(const AudioBuffer::Channel& filter_coefficients,
+ size_t frames_per_buffer);
+
+ // Filters an array of input with a finite impulse response (FIR) filter in
+ // the time domain. All pointers and lengths passed must be SIMD compatible.
+ //
+ // @param input Pointer to an aray of input.
+ // @param output Pointer to a cleared block of memory of the input length.
+ void Process(const AudioBuffer::Channel& input, AudioBuffer::Channel* output);
+
+ // Returns the length of the filter kernel after zeropadding.
+ //
+ // @return Length of the FIR filter in frames.
+ size_t filter_length() const { return filter_length_; }
+
+ private:
+ // Length of the filter kernel in frames after zeropadding.
+ size_t filter_length_;
+
+ // Number of filter chunks equivalent to the filter length after zeropadding
+ // divided by the SIMD_LENGTH.
+ size_t num_filter_chunks_;
+
+ // Coefficients of the filter stored in a repeated format.
+ AudioBuffer coefficients_;
+
+ // Aligned buffer of previous and current input.
+ AudioBuffer state_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_FIR_FILTER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter_test.cc
new file mode 100644
index 000000000..e64a44f15
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/fir_filter_test.cc
@@ -0,0 +1,104 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/fir_filter.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/simd_macros.h"
+
+namespace vraudio {
+
+namespace {
+
+const size_t kFirFramesPerBuffer = 32;
+const size_t kFirKernelLength = 8;
+
+// Tests that the filter is resized to a length compatable with the current
+// SIMD_LENGTH whether it is one greater than or one less than a multiple of
+// SIMD_LENGTH to begin with.
+TEST(FirFilterTest, GetFilterLengthTest) {
+ const size_t twice_simd_length = (SIMD_LENGTH * 2);
+ // Divisible by the length of a SIMD vector.
+ AudioBuffer kernel_buffer1(kNumMonoChannels, twice_simd_length);
+ FirFilter filter1(kernel_buffer1[0], twice_simd_length);
+ EXPECT_EQ(twice_simd_length, filter1.filter_length());
+
+ // Shorter filter.
+ AudioBuffer kernel_buffer2(kNumMonoChannels, twice_simd_length - 1);
+ FirFilter filter2(kernel_buffer2[0], twice_simd_length - 1);
+ EXPECT_EQ(twice_simd_length, filter2.filter_length());
+
+ // Longer filter.
+ AudioBuffer kernel_buffer3(kNumMonoChannels, twice_simd_length + 1);
+ FirFilter filter3(kernel_buffer3[0], twice_simd_length + 1);
+ EXPECT_EQ(twice_simd_length + SIMD_LENGTH, filter3.filter_length());
+}
+
+// Tests that the output from a convolution between a double kronecker input and
+// a alternating 1, 0 buffer of input yields the correct output buffer.
+TEST(FirFilterTest, ProcessWithDoubleKronecker) {
+ AudioBuffer input_buffer(kNumMonoChannels, kFirFramesPerBuffer);
+ input_buffer.Clear();
+ AudioBuffer output_buffer(1, kFirFramesPerBuffer);
+ output_buffer.Clear();
+ // First create a vector containing the FIR filter coefficients in standard
+ // format.
+ AudioBuffer kernel_buffer(kNumMonoChannels, kFirKernelLength);
+ kernel_buffer.Clear();
+ kernel_buffer[0][0] = 1.0f;
+ kernel_buffer[0][kFirKernelLength / 2] = 1.0f;
+ // Now we can create the kernel buffer in its repeated entry representation
+ // from this standard form FIR representation.
+ FirFilter filter(kernel_buffer[0], kFirFramesPerBuffer);
+ // Next populate the input buffer.
+ for (size_t i = 0; i < kFirFramesPerBuffer; i += 2) {
+ input_buffer[0][i] = 1.0f;
+ }
+
+ filter.Process(input_buffer[0], &(output_buffer[0]));
+
+ for (size_t i = 0; i < kFirFramesPerBuffer; ++i) {
+ if (i % 2 != 0) {
+ EXPECT_NEAR(0.0f, output_buffer[0][i], kEpsilonFloat);
+ } else if (i <= 3) {
+ EXPECT_NEAR(1.0f, output_buffer[0][i], kEpsilonFloat);
+ } else {
+ EXPECT_NEAR(2.0f, output_buffer[0][i], kEpsilonFloat);
+ }
+ }
+
+ // Run again with a cleared buffer to flush out the filter state.
+ input_buffer.Clear();
+ output_buffer.Clear();
+
+ filter.Process(input_buffer[0], &(output_buffer[0]));
+
+ for (size_t i = 0; i < kFirFramesPerBuffer; ++i) {
+ if (i % 2 != 0) {
+ EXPECT_NEAR(0.0f, output_buffer[0][i], kEpsilonFloat);
+ } else if (i <= 3) {
+ EXPECT_NEAR(1.0f, output_buffer[0][i], kEpsilonFloat);
+ } else {
+ EXPECT_NEAR(0.0f, output_buffer[0][i], kEpsilonFloat);
+ }
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/gain.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain.cc
new file mode 100644
index 000000000..54e3fc216
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain.cc
@@ -0,0 +1,102 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/gain.h"
+
+#include "base/constants_and_types.h"
+#include "base/simd_macros.h"
+#include "base/simd_utils.h"
+
+namespace vraudio {
+
+float LinearGainRamp(size_t ramp_length, float start_gain, float end_gain,
+ const AudioBuffer::Channel& input_samples,
+ AudioBuffer::Channel* output_samples,
+ bool accumulate_output) {
+ DCHECK(output_samples);
+ DCHECK_EQ(input_samples.size(), output_samples->size());
+ DCHECK_GT(ramp_length, 0U);
+
+ const size_t process_length = std::min(ramp_length, input_samples.size());
+ const float gain_increment_per_sample =
+ (end_gain - start_gain) / static_cast<float>(ramp_length);
+
+ float current_gain = start_gain;
+ if (accumulate_output) {
+ for (size_t frame = 0; frame < process_length; ++frame) {
+ (*output_samples)[frame] += current_gain * input_samples[frame];
+ current_gain += gain_increment_per_sample;
+ }
+ } else {
+ for (size_t frame = 0; frame < process_length; ++frame) {
+ (*output_samples)[frame] = current_gain * input_samples[frame];
+ current_gain += gain_increment_per_sample;
+ }
+ }
+
+ return current_gain;
+}
+
+void ConstantGain(size_t offset_index, float gain,
+ const AudioBuffer::Channel& input_samples,
+ AudioBuffer::Channel* output_samples,
+ bool accumulate_output) {
+ DCHECK(output_samples);
+ const size_t input_size = input_samples.size();
+ DCHECK_EQ(input_size, output_samples->size());
+ DCHECK_LT(offset_index, input_size);
+
+ // Apply gain to samples at the beginning, prior to SIMD_LENGTH alignment.
+ const size_t unaligned_samples = SIMD_LENGTH - (offset_index % SIMD_LENGTH);
+ const size_t offset_index_simd =
+ std::min(input_size, offset_index + unaligned_samples);
+ if (accumulate_output) {
+ for (size_t i = offset_index; i < offset_index_simd; ++i) {
+ (*output_samples)[i] += input_samples[i] * gain;
+ }
+ } else {
+ for (size_t i = offset_index; i < offset_index_simd; ++i) {
+ (*output_samples)[i] = input_samples[i] * gain;
+ }
+ }
+
+ if (offset_index_simd == input_size) {
+ // Return if there are no remaining operations to carry out.
+ return;
+ }
+
+ const size_t aligned_length = input_size - offset_index_simd;
+ const float* aligned_input = &(input_samples[offset_index_simd]);
+ float* aligned_output = &(*output_samples)[offset_index_simd];
+
+ // Apply gain via SIMD operations.
+ if (accumulate_output) {
+ ScalarMultiplyAndAccumulate(aligned_length, gain, aligned_input,
+ aligned_output);
+ } else {
+ ScalarMultiply(aligned_length, gain, aligned_input, aligned_output);
+ }
+}
+
+bool IsGainNearZero(float gain) {
+ return std::abs(gain) < kNegative60dbInAmplitude;
+}
+
+bool IsGainNearUnity(float gain) {
+ return std::abs(1.0f - gain) < kNegative60dbInAmplitude;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/gain.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain.h
new file mode 100644
index 000000000..500af8c22
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain.h
@@ -0,0 +1,67 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_GAIN_H_
+#define RESONANCE_AUDIO_DSP_GAIN_H_
+
+#include <cstddef>
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Implements a linearly-interpolated application of gain to a buffer channel.
+//
+// @param ramp_length Length of interpolation ramp in samples. Must be > 0.
+// @param start_gain Starting gain value for ramp.
+// @param end_gain Finishing gain value for ramp.
+// @param input_samples Channel buffer to which interpolated gain is applied.
+// @param output_samples Channel buffer to contain scaled output.
+// @param accumulate_output True if the processed input should be mixed into the
+// output. Otherwise, the output will be replaced by the processed input.
+// @return Next gain value to be applied to the buffer channel.
+float LinearGainRamp(size_t ramp_length, float start_gain, float end_gain,
+ const AudioBuffer::Channel& input_samples,
+ AudioBuffer::Channel* output_samples,
+ bool accumulate_output);
+
+// Applies a gain value to a vector of buffer samples starting at some offset.
+//
+// @param offset_index Starting index for gain application in buffer.
+// @param gain Gain value applied to samples.
+// @param input_samples Channel buffer to which gain is applied.
+// @param output_samples Channel buffer to contain scaled output.
+// @param accumulate_output True if the processed input should be mixed into the
+// output. Otherwise, the output will be replaced by the processed input.
+void ConstantGain(size_t offset_index, float gain,
+ const AudioBuffer::Channel& input_samples,
+ AudioBuffer::Channel* output_samples, bool accumulate_output);
+
+// Checks if the gain factor is close enough to zero (less than -60 decibels).
+//
+// @param gain Gain value to be tested.
+// @return true if the current gain factors are near zero, false otherwise.
+bool IsGainNearZero(float gain);
+
+// Checks if the gain state is close enough to Unity (less than -60 decibels
+// below or above).
+//
+// @param gain Gain value to be tested.
+// @return true if the current gain factors are near unity, false otherwise.
+bool IsGainNearUnity(float gain);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_GAIN_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer.cc
new file mode 100644
index 000000000..06417be11
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer.cc
@@ -0,0 +1,115 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/gain_mixer.h"
+
+#include <cmath>
+
+#include "base/logging.h"
+
+namespace vraudio {
+
+GainMixer::GainMixer(size_t num_channels, size_t frames_per_buffer)
+ : num_channels_(num_channels),
+ output_(num_channels_, frames_per_buffer),
+ is_empty_(false) {
+ DCHECK_NE(num_channels_, 0U);
+ Reset();
+}
+
+void GainMixer::AddInput(const AudioBuffer& input,
+ const std::vector<float>& gains) {
+ DCHECK_EQ(gains.size(), num_channels_);
+ DCHECK_EQ(input.num_channels(), num_channels_);
+ DCHECK_EQ(input.num_frames(), output_.num_frames());
+
+ auto* gain_processors = GetOrCreateProcessors(input.source_id());
+ // Accumulate the input buffers into the output buffer.
+ for (size_t i = 0; i < num_channels_; ++i) {
+ if (input[i].IsEnabled()) {
+ (*gain_processors)[i].ApplyGain(gains[i], input[i], &output_[i],
+ true /* accumulate_output */);
+ } else {
+ // Make sure the gain processor is initialized.
+ (*gain_processors)[i].Reset(gains[i]);
+ }
+ }
+ is_empty_ = false;
+}
+
+void GainMixer::AddInputChannel(const AudioBuffer::Channel& input,
+ SourceId source_id,
+ const std::vector<float>& gains) {
+ DCHECK_EQ(gains.size(), num_channels_);
+ DCHECK_EQ(input.size(), output_.num_frames());
+
+ auto* gain_processors = GetOrCreateProcessors(source_id);
+ // Accumulate the input buffers into the output buffer.
+ for (size_t i = 0; i < num_channels_; ++i) {
+ if (input.IsEnabled()) {
+ (*gain_processors)[i].ApplyGain(gains[i], input, &output_[i],
+ true /* accumulate_output */);
+ } else {
+ // Make sure the gain processor is initialized.
+ (*gain_processors)[i].Reset(gains[i]);
+ }
+ }
+ is_empty_ = false;
+}
+
+const AudioBuffer* GainMixer::GetOutput() const {
+ if (is_empty_) {
+ return nullptr;
+ }
+ return &output_;
+}
+
+void GainMixer::Reset() {
+ if (!is_empty_) {
+ // Delete the processors for sources which no longer exist.
+ for (auto it = source_gain_processors_.begin();
+ it != source_gain_processors_.end();
+ /* no increment */) {
+ if (it->second.processors_active) {
+ it->second.processors_active = false;
+ ++it;
+ } else {
+ source_gain_processors_.erase(it++);
+ }
+ }
+ // Reset the output buffer.
+ output_.Clear();
+ }
+ is_empty_ = true;
+}
+
+GainMixer::GainProcessors::GainProcessors(size_t num_channels)
+ : processors_active(true), processors(num_channels) {}
+
+std::vector<GainProcessor>* GainMixer::GetOrCreateProcessors(
+ SourceId source_id) {
+ // Attempt to find a |ScaleAndAccumulateProcessor| for the given |source_id|,
+ // if none can be found add one. In either case mark that the processor has
+ // been used so that it is not later deleted.
+ if (source_gain_processors_.find(source_id) ==
+ source_gain_processors_.end()) {
+ source_gain_processors_.insert({source_id, GainProcessors(num_channels_)});
+ }
+ source_gain_processors_.at(source_id).processors_active = true;
+ return &(source_gain_processors_.at(source_id).processors);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer.h
new file mode 100644
index 000000000..18c785c26
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer.h
@@ -0,0 +1,96 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_GAIN_MIXER_H_
+#define RESONANCE_AUDIO_DSP_GAIN_MIXER_H_
+
+#include <memory>
+#include <unordered_map>
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "dsp/gain_processor.h"
+
+namespace vraudio {
+
+class GainMixer {
+ public:
+ GainMixer(size_t num_channels, size_t frames_per_buffer);
+
+ // Adds a separately scaled version of each channel of the input buffer to the
+ // output buffer's corresponding channels.
+ //
+ // @param input Input buffer to be added.
+ // @param gains Gains to be applied to the buffers channels. Must be equal in
+ // length to the number of channels in |input|.
+ void AddInput(const AudioBuffer& input, const std::vector<float>& gains);
+
+ // Adds a single input channel to each of the output buffer's channels, with
+ // a separate gain applied to the input channel per output channel.
+ //
+ // @param input Input channel to be added.
+ // @param source_id Identifier corresponding to the input.
+ // @param gains Gains to be applied to the buffers channels. Must be equal in
+ // length to the number of channels in the output buffer.
+ void AddInputChannel(const AudioBuffer::Channel& input, SourceId source_id,
+ const std::vector<float>& gains);
+
+ // Returns a pointer to the accumulator.
+ //
+ // @return Pointer to the processed (mixed) output buffer, or nullptr if no
+ // input has been added to the accumulator.
+ const AudioBuffer* GetOutput() const;
+
+ // Resets the state of the accumulator.
+ void Reset();
+
+ private:
+ // Comprises one |GainProcessor| per channel of a source and a boolean to
+ // denote whether that source is active.
+ struct GainProcessors {
+ explicit GainProcessors(size_t num_channels);
+
+ // Bool to signify if a given source is still passing data to a processor.
+ bool processors_active;
+
+ // Scale and accumulation processors, one per channel for each source.
+ std::vector<GainProcessor> processors;
+ };
+
+ // Returns the |GainProcessor|s associated with a |source_id| (or creates
+ // one if needed) and sets the corresponding |processors_active| flag to true.
+ //
+ // @param source_id Identifier for a given input.
+ // @return The corresponding |ScalingAccumulators|.
+ std::vector<GainProcessor>* GetOrCreateProcessors(SourceId source_id);
+
+ // Number of channels.
+ const size_t num_channels_;
+
+ // Output buffer (accumulator).
+ AudioBuffer output_;
+
+ // Denotes whether the accumulator has processed any inputs or not.
+ bool is_empty_;
+
+ // Scale and accumulation processors, one per channel for each source.
+ std::unordered_map<SourceId, GainProcessors> source_gain_processors_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_GAIN_MIXER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer_test.cc
new file mode 100644
index 000000000..70a45a692
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_mixer_test.cc
@@ -0,0 +1,188 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/gain_mixer.h"
+
+#include <iterator>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "utils/planar_interleaved_conversion.h"
+
+namespace vraudio {
+
+namespace {
+
+const int kId1 = 0;
+const int kId2 = 1;
+
+// Number of frames per output buffer.
+const size_t kFramesPerBuffer = 3;
+
+// Sample mono input data, gains, and the corresponding output data.
+const float kGain1 = 0.5f;
+const float kGain2 = 2.0f;
+const float kInput1[kFramesPerBuffer] = {0.2f, 0.4f, 0.6f};
+const float kInput2[kFramesPerBuffer] = {0.5f, 1.0f, 1.5f};
+const float kOutput[kFramesPerBuffer] = {1.1f, 2.2f, 3.3f};
+
+// Tests that the gain mixer returns null output if no input has been added.
+TEST(MixerTest, EmptyInputTest) {
+ GainMixer gain_mixer(kNumMonoChannels, kFramesPerBuffer);
+
+ const AudioBuffer* output = gain_mixer.GetOutput();
+ EXPECT_TRUE(output == nullptr);
+}
+
+// Mono processing test with two inputs. Tests the mixed output buffer against
+// the manually computed output data.
+TEST(GainMixerTest, ProcessTest) {
+ GainMixer gain_mixer(kNumMonoChannels, kFramesPerBuffer);
+
+ // Initialize input buffers.
+ AudioBuffer input1(kNumMonoChannels, kFramesPerBuffer);
+ input1.set_source_id(kId1);
+ FillAudioBuffer(std::begin(kInput1), kFramesPerBuffer, kNumMonoChannels,
+ &input1);
+ AudioBuffer input2(kNumMonoChannels, kFramesPerBuffer);
+ input2.set_source_id(kId2);
+ FillAudioBuffer(std::begin(kInput2), kFramesPerBuffer, kNumMonoChannels,
+ &input2);
+ // Initialize gain vectors.
+ const std::vector<float> kGainVector1(1, kGain1);
+ const std::vector<float> kGainVector2(1, kGain2);
+
+ // Add the input buffers to the |GainMixer| (process multiple times so the
+ // gains have reached steady state.
+ const AudioBuffer* output = nullptr;
+ for (size_t iterations = 0; iterations < kUnitRampLength; ++iterations) {
+ gain_mixer.Reset();
+ gain_mixer.AddInput(input1, kGainVector1);
+ gain_mixer.AddInput(input2, kGainVector2);
+ // Get the processed output (should contain the pre-computed output data).
+ output = gain_mixer.GetOutput();
+ }
+
+ EXPECT_FALSE(output == nullptr);
+ EXPECT_EQ(output->num_channels(), kNumMonoChannels);
+ EXPECT_EQ(output->num_frames(), kFramesPerBuffer);
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ EXPECT_NEAR((*output)[0][i], kOutput[i], kEpsilonFloat);
+ }
+}
+
+// Reset test for the |GainMixer| with single input at a time. First, adds an
+// input buffer, resets the |GainMixer|. Then, adds another input buffer and
+// tests the final output buffer against the data of the last added input buffer
+// to verify if the system has been successfully reset.
+TEST(GainMixerTest, ResetTest) {
+ GainMixer gain_mixer(kNumMonoChannels, kFramesPerBuffer);
+
+ // Initialize input buffers.
+ AudioBuffer input1(kNumMonoChannels, kFramesPerBuffer);
+ input1.set_source_id(kId1);
+ FillAudioBuffer(std::begin(kInput1), kFramesPerBuffer, kNumMonoChannels,
+ &input1);
+ AudioBuffer input2(kNumMonoChannels, kFramesPerBuffer);
+ input2.set_source_id(kId2);
+ FillAudioBuffer(std::begin(kInput2), kFramesPerBuffer, kNumMonoChannels,
+ &input2);
+ // Initialize gain vectors.
+ const std::vector<float> kGainVector1(1, kGain1);
+ const std::vector<float> kGainVector2(1, kGain2);
+
+ // Add the first input buffer to the |GainMixer|.
+ gain_mixer.AddInput(input1, kGainVector1);
+ // Reset the accumulator (and release the buffer).
+ gain_mixer.Reset();
+ // Add the second input buffers to the |GainMixer|.
+ gain_mixer.AddInput(input2, kGainVector2);
+
+ // Get the output (should only contain the second input).
+ const AudioBuffer* output = gain_mixer.GetOutput();
+
+ EXPECT_FALSE(output == nullptr);
+ EXPECT_EQ(output->num_channels(), kNumMonoChannels);
+ EXPECT_EQ(output->num_frames(), kFramesPerBuffer);
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ EXPECT_NEAR((*output)[0][i], kInput2[i] * kGain2, kEpsilonFloat);
+ }
+}
+
+// Tests that gains are correctly applied for multiple channels.
+TEST(GainMixerTest, MultiChannelTest) {
+ const std::vector<float> kGains = {0.1f, -0.2f};
+ const std::vector<float> kInputChannel = {10.0f, 10.0f, 10.0f};
+ GainMixer gain_mixer(kGains.size(), kFramesPerBuffer);
+
+ // Initialize input buffer.
+ AudioBuffer input(kGains.size(), kInputChannel.size());
+ for (size_t i = 0; i < kGains.size(); ++i) {
+ input[i] = kInputChannel;
+ }
+
+ const AudioBuffer* output = nullptr;
+ for (size_t iterations = 0; iterations < kUnitRampLength; ++iterations) {
+ gain_mixer.Reset();
+ gain_mixer.AddInput(input, kGains);
+ output = gain_mixer.GetOutput();
+ }
+
+ EXPECT_FALSE(output == nullptr);
+ EXPECT_EQ(output->num_channels(), kGains.size());
+ EXPECT_EQ(output->num_frames(), kFramesPerBuffer);
+ for (size_t channel = 0; channel < kGains.size(); ++channel) {
+ for (size_t i = 0; i < kInputChannel.size(); ++i) {
+ EXPECT_NEAR((*output)[channel][i], kInputChannel[i] * kGains[channel],
+ kEpsilonFloat);
+ }
+ }
+}
+
+// Tests that gains are correctly applied for a mono input buffer across a
+// multichannel output buffer.
+TEST(GainMixerTest, MonoChannelInputTest) {
+ const std::vector<float> kGains = {2.0f, -3.0f};
+ const std::vector<float> kInputChannel = {10.0f, 10.0f, 10.0f};
+ GainMixer gain_mixer(kGains.size(), kInputChannel.size());
+
+ // Create a mono input buffer.
+ AudioBuffer input(kNumMonoChannels, kInputChannel.size());
+ AudioBuffer::Channel* input_channel = &input[0];
+ *input_channel = kInputChannel;
+
+ const AudioBuffer* output = nullptr;
+ for (size_t iterations = 0; iterations < kUnitRampLength; ++iterations) {
+ gain_mixer.Reset();
+ gain_mixer.AddInputChannel(*input_channel, kId1, kGains);
+ output = gain_mixer.GetOutput();
+ }
+
+ EXPECT_FALSE(output == nullptr);
+ EXPECT_EQ(output->num_channels(), kGains.size());
+ EXPECT_EQ(output->num_frames(), kFramesPerBuffer);
+ for (size_t channel = 0; channel < kGains.size(); ++channel) {
+ for (size_t i = 0; i < kInputChannel.size(); ++i) {
+ EXPECT_NEAR((*output)[channel][i], kInputChannel[i] * kGains[channel],
+ kEpsilonFloat);
+ }
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor.cc
new file mode 100644
index 000000000..f5eaea22d
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor.cc
@@ -0,0 +1,94 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/gain_processor.h"
+
+#include <algorithm>
+#include <cmath>
+
+#include "base/constants_and_types.h"
+
+#include "dsp/gain.h"
+
+namespace vraudio {
+
+// Delegate default constructor.
+GainProcessor::GainProcessor() : current_gain_(0.0f), is_initialized_(false) {}
+
+GainProcessor::GainProcessor(float initial_gain)
+ : current_gain_(initial_gain), is_initialized_(true) {}
+
+void GainProcessor::ApplyGain(float target_gain,
+ const AudioBuffer::Channel& input,
+ AudioBuffer::Channel* output,
+ bool accumulate_output) {
+
+ DCHECK(output);
+
+ if (!is_initialized_) {
+ Reset(target_gain);
+ }
+
+ // Check buffer length.
+ const size_t input_length = input.size();
+ DCHECK_GT(input_length, 0U);
+ DCHECK_EQ(input_length, output->size());
+
+ // Index for where to stop interpolating.
+ size_t ramp_length =
+ static_cast<size_t>(std::abs(target_gain - current_gain_) *
+ static_cast<float>(kUnitRampLength));
+
+ // Check if there is a new gain value.
+ if (ramp_length > 0) {
+ // Apply gain ramp to buffer.
+ current_gain_ = LinearGainRamp(ramp_length, current_gain_, target_gain,
+ input, output, accumulate_output);
+ } else {
+ // No ramping needed.
+ current_gain_ = target_gain;
+ }
+
+ // Apply constant gain to the rest of the buffer.
+ if (ramp_length < input_length) {
+ if (IsGainNearZero(current_gain_)) {
+ // Skip processing if the gain is zero.
+ if (!accumulate_output) {
+ // Directly fill the remaining output with zeros.
+ std::fill(output->begin() + ramp_length, output->end(), 0.0f);
+ }
+ return;
+ } else if (IsGainNearUnity(current_gain_) && !accumulate_output) {
+ // Skip processing if the gain is unity.
+ if (&input != output) {
+ // Directly copy the remaining input samples into output.
+ std::copy(input.begin() + ramp_length, input.end(),
+ output->begin() + ramp_length);
+ }
+ return;
+ }
+ ConstantGain(ramp_length, current_gain_, input, output, accumulate_output);
+ }
+}
+
+float GainProcessor::GetGain() const { return current_gain_; }
+
+void GainProcessor::Reset(float gain) {
+ current_gain_ = gain;
+ is_initialized_ = true;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor.h
new file mode 100644
index 000000000..4baa276ea
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor.h
@@ -0,0 +1,74 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_GAIN_PROCESSOR_H_
+#define RESONANCE_AUDIO_DSP_GAIN_PROCESSOR_H_
+
+#include <cmath>
+#include <cstddef>
+#include <vector>
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Processor class which applies a gain to a vector of samples from an audio
+// buffer. A short linear ramp is applied to the gain to reduce audible
+// artifacts in the output.
+class GainProcessor {
+ public:
+ // Default constructor keeps the gain state uninitialized. The first call to
+ // |ApplyGain| sets the internal gain state.
+ GainProcessor();
+
+ // Constructs |GainProcessor| with some initial gain value.
+ //
+ // @param initial_gain Gain value used as starting point for first processing
+ // period's gain ramping.
+ explicit GainProcessor(float initial_gain);
+
+ // Applies gain supplied to the input samples.
+ //
+ // @param target_gain Target gain value.
+ // @param input Samples to which gain will be applied.
+ // @param output Samples to which gain has been applied.
+ // @param accumulate_output True if the processed input should be mixed into
+ // the output. Otherwise, the output will be replaced by the processed
+ // input.
+ void ApplyGain(float target_gain, const AudioBuffer::Channel& input,
+ AudioBuffer::Channel* output, bool accumulate_output);
+
+ // Returns the |current_gain_| value.
+ //
+ // @return Current gain applied by the |GainProcessor|.
+ float GetGain() const;
+
+ // Resets the gain processor to a new gain factor.
+ //
+ // @param gain Gain value.
+ void Reset(float gain);
+
+ private:
+ // Latest gain value to be applied to buffer values.
+ float current_gain_;
+
+ // Flag to indiciate if an initial gain has been assigned.
+ bool is_initialized_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_GAIN_PROCESSOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor_test.cc
new file mode 100644
index 000000000..e1077655a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_processor_test.cc
@@ -0,0 +1,181 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/gain_processor.h"
+
+#include <algorithm>
+#include <cmath>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+
+// A set of simple tests to confirm expected behavior when a linear gain ramp is
+// applied to a vector of samples.
+namespace vraudio {
+
+namespace {
+
+// Initial gain value.
+const float kInitialGain = 0.1f;
+
+// Target gain value.
+const float kTargetGain = 0.6f;
+
+// Test input data length.
+const size_t kInputLength = 10;
+
+// Test value of each sample of the output buffer prior to processing.
+const float kInitialOutputValue = 2.0f;
+
+class GainProcessorTest : public ::testing::TestWithParam<bool> {};
+
+// This test checks that gain value is applied to the input buffer in a linear
+// ramp when the buffer length is less than the ramp length.
+TEST_P(GainProcessorTest, ApplyGainOverBufferLengthTest) {
+ // Expected output data for ramped gain application.
+ const float kExpectedOutput[kInputLength] = {
+ 0.1f, 0.1004883f, 0.1009766f, 0.1014648f, 0.1019531f,
+ 0.1024414f, 0.1029297f, 0.1034180f, 0.1039063f, 0.1043945f};
+ const bool accumulate_output = GetParam();
+ // Initialize input buffer.
+ AudioBuffer input(kNumMonoChannels, kInputLength);
+ std::fill(input[0].begin(), input[0].end(), 1.0f);
+ // Initialize output buffer.
+ AudioBuffer output(kNumMonoChannels, kInputLength);
+ std::fill(output[0].begin(), output[0].end(), kInitialOutputValue);
+
+ // Initialize gain processor with a gain value.
+ GainProcessor gain_processor(kInitialGain);
+ // Process buffer samples with the test gain value.
+ gain_processor.ApplyGain(kTargetGain, input[0], &output[0],
+ accumulate_output);
+
+ // Check that gain values have been applied correctly to the buffer.
+ for (size_t i = 0; i < kInputLength; ++i) {
+ const float expected_value = accumulate_output
+ ? kInitialOutputValue + kExpectedOutput[i]
+ : kExpectedOutput[i];
+ EXPECT_NEAR(expected_value, output[0][i], kEpsilonFloat);
+ }
+}
+
+// This test checks that gain value is applied to the buffer samples in a linear
+// ramp. The test also confirms that the gain ramping halts at the correct index
+// for buffer lengths greater than the ramp length.
+TEST_P(GainProcessorTest, ApplyGainLongerThanRampTest) {
+ const bool accumulate_output = GetParam();
+ // Initialize input buffer.
+ AudioBuffer input(kNumMonoChannels, kUnitRampLength);
+ std::fill(input[0].begin(), input[0].end(), 1.0f);
+ // Initialize output buffer.
+ AudioBuffer output(kNumMonoChannels, kUnitRampLength);
+ std::fill(output[0].begin(), output[0].end(), kInitialOutputValue);
+
+ // Initialize gain processor with a gain value.
+ GainProcessor gain_processor(kInitialGain);
+ // Process an input buffer with the test gain value.
+ gain_processor.ApplyGain(kTargetGain, input[0], &output[0],
+ accumulate_output);
+
+ // Generate expected gain ramp. The output should consist of the linearly
+ // interpolated gain values over the ramp length, and the final (constant)
+ // gain for the rest of the buffer.
+ std::vector<float> expected_output(kUnitRampLength);
+ const size_t ramp_length =
+ static_cast<size_t>(std::abs(kTargetGain - kInitialGain) *
+ static_cast<float>(kUnitRampLength));
+ const float increment =
+ (kTargetGain - kInitialGain) / static_cast<float>(ramp_length);
+ float expected_value =
+ accumulate_output ? kInitialOutputValue + kInitialGain : kInitialGain;
+ for (size_t i = 0; i < kUnitRampLength; ++i) {
+ expected_output[i] = expected_value;
+ if (i < ramp_length) {
+ expected_value += increment;
+ }
+ }
+ // Check that gain values have been applied correctly to the buffer.
+ for (size_t i = 0; i < kUnitRampLength; ++i) {
+ // Check that ramp was applied.
+ EXPECT_NEAR(expected_output[i], output[0][i], kEpsilonFloat);
+ }
+}
+
+// This test checks that gain values are reset to initial gain after a call to
+// the |Reset()| method.
+TEST_P(GainProcessorTest, ResetGainProcessorTest) {
+ const bool accumulate_output = GetParam();
+ // Initialize input buffer.
+ AudioBuffer input(kNumMonoChannels, kUnitRampLength);
+ std::fill(input[0].begin(), input[0].end(), 1.0f);
+ // Initialize output buffer.
+ AudioBuffer output(kNumMonoChannels, kUnitRampLength);
+ std::fill(output[0].begin(), output[0].end(), 0.0f);
+
+ // Initialize gain processor with a gain of 0.0f.
+ GainProcessor gain_processor(0.0f);
+ // Reset gain to |kInitialGain|.
+ gain_processor.Reset(kInitialGain);
+ // Apply newly-reset gains (no ramp expected).
+ gain_processor.ApplyGain(kInitialGain, input[0], &output[0],
+ accumulate_output);
+
+ // Check that uniform gain has been applied correctly to the buffer.
+ for (size_t i = 0; i < kInputLength; ++i) {
+ EXPECT_NEAR(kInitialGain, output[0][i], kEpsilonFloat);
+ }
+}
+
+// Checks that the initial gain is assigned during the first call of |ApplyGain|
+// in case the |GainProcessor| instance is constructed via the default
+// constructor.
+TEST_P(GainProcessorTest, DefaultConstructorTest) {
+ const bool accumulate_output = GetParam();
+ // Initialize input buffer.
+ AudioBuffer input(kNumMonoChannels, kUnitRampLength);
+ std::fill(input[0].begin(), input[0].end(), kInitialGain);
+ // Initialize output buffer.
+ AudioBuffer output(kNumMonoChannels, kUnitRampLength);
+ std::fill(output[0].begin(), output[0].end(), 0.0f);
+
+ // Declare gain processor without specifiying a gain value.
+ GainProcessor gain_processor;
+ // Apply some new gain value.
+ gain_processor.ApplyGain(kTargetGain, input[0], &output[0],
+ accumulate_output);
+
+ // Check that uniform gain has been applied correctly to the buffer.
+ for (size_t i = 0; i < kInputLength; ++i) {
+ EXPECT_NEAR(kInitialGain * kTargetGain, output[0][i], kEpsilonFloat);
+ }
+}
+
+// Tests the |GetGain| method.
+TEST(GainProcessorTest, GetGainTest) {
+ // Test |GainProcessor| with arbitrary gain.
+ const float kGainValue = -1.5f;
+ GainProcessor gain_processor(kGainValue);
+ EXPECT_EQ(gain_processor.GetGain(), kGainValue);
+}
+
+INSTANTIATE_TEST_CASE_P(AccumulateOutput, GainProcessorTest,
+ ::testing::Values(false, true));
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_test.cc
new file mode 100644
index 000000000..01e4471f4
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/gain_test.cc
@@ -0,0 +1,132 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/gain.h"
+
+#include <algorithm>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "dsp/utils.h"
+
+namespace vraudio {
+
+namespace {
+
+// Tolerated error margin.
+const float kEpsilon = 1e-4f;
+
+class GainTest : public ::testing::TestWithParam<bool> {};
+
+// This test checks that the gain applied using ConstantGain is correct.
+TEST_P(GainTest, ConstantGainTest) {
+ const size_t kMaxInputLength = 32;
+ const float kGain = 1;
+ const bool accumulate_output = GetParam();
+
+ for (size_t length = 1; length < kMaxInputLength; ++length) {
+ AudioBuffer input_samples(kNumMonoChannels, length);
+ GenerateUniformNoise(
+ /*min=*/-1.0f, /*min=*/1.0f, static_cast<unsigned>(length),
+ &input_samples[0]);
+ for (size_t offset_index = 0; offset_index < length; ++offset_index) {
+ // Initialize input buffer.
+ AudioBuffer input(kNumMonoChannels, length);
+ input[0] = input_samples[0];
+ // Initialize output buffer with the same values.
+ AudioBuffer output(kNumMonoChannels, length);
+ output[0] = input_samples[0];
+
+ // Apply constant gain.
+ ConstantGain(offset_index, kGain, input[0], &output[0],
+ accumulate_output);
+
+ // Compute expected values.
+ AudioBuffer expected_samples_buffer(kNumMonoChannels, length);
+ expected_samples_buffer[0] = input_samples[0];
+ for (size_t i = offset_index; i < length; ++i) {
+ const float processed_input = kGain * input[0][i];
+ if (accumulate_output) {
+ expected_samples_buffer[0][i] += processed_input;
+ } else {
+ expected_samples_buffer[0][i] = processed_input;
+ }
+ }
+ // Check that the output buffer has the expected values per each sample.
+ for (size_t i = 0; i < length; ++i) {
+ EXPECT_NEAR(expected_samples_buffer[0][i], output[0][i], kEpsilon)
+ << " at index=" << i << " with input_length=" << length
+ << " and offset_index=" << offset_index;
+ }
+ }
+ }
+}
+
+// Test that checks that the gain ramp applied is correct.
+TEST_P(GainTest, LinearGainRampTest) {
+ const float kInitialOutputValue = 2.0f;
+ const float kStartGain = 0.0f;
+ const float kEndGain = 1.0f;
+ const size_t kNumSamples = 10;
+ const float kPerSampleIncrease =
+ (kEndGain - kStartGain) / static_cast<float>(kNumSamples);
+ const bool accumulate_output = GetParam();
+
+ // Create an input buffer with unity samples.
+ AudioBuffer input(kNumMonoChannels, kNumSamples);
+ std::fill(input[0].begin(), input[0].end(), 1.0f);
+ // Create an output buffer with all samples the same.
+ AudioBuffer output(kNumMonoChannels, kNumSamples);
+ std::fill(output[0].begin(), output[0].end(), kInitialOutputValue);
+
+ // Apply linear gain ramp.
+ LinearGainRamp(kNumSamples, kStartGain, kEndGain, input[0], &(output[0]),
+ accumulate_output);
+
+ // Check that the output buffer has the expected values per each sample.
+ float expected_value = accumulate_output ? kInitialOutputValue : 0.0f;
+ for (size_t i = 0; i < kNumSamples; ++i) {
+ EXPECT_NEAR(expected_value, output[0][i], kEpsilon);
+ expected_value += kPerSampleIncrease;
+ }
+}
+
+TEST(GainTest, GainUtilsTest) {
+ const float kGainUnity = 1.0f;
+ const float kGainZero = 0.0f;
+ const float kGainOther = -1.7f;
+
+ // Test the cases where each should return true.
+ EXPECT_TRUE(IsGainNearZero(kGainZero));
+ EXPECT_TRUE(IsGainNearUnity(kGainUnity));
+
+ // Test the cases where gain value is non zero, positive and negative.
+ EXPECT_FALSE(IsGainNearZero(kGainOther));
+ EXPECT_FALSE(IsGainNearZero(kGainUnity));
+
+ // Test the case where gain value is not unity, with alternate value and zero.
+ EXPECT_FALSE(IsGainNearUnity(kGainOther));
+ EXPECT_FALSE(IsGainNearUnity(kGainZero));
+}
+
+INSTANTIATE_TEST_CASE_P(AccumulateOutput, GainTest,
+ ::testing::Values(false, true));
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/mixer.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/mixer.cc
new file mode 100644
index 000000000..1b7460428
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/mixer.cc
@@ -0,0 +1,56 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/mixer.h"
+
+#include "base/logging.h"
+
+namespace vraudio {
+
+Mixer::Mixer(size_t target_num_channels, size_t frames_per_buffer)
+ : output_(target_num_channels, frames_per_buffer), is_empty_(false) {
+ Reset();
+}
+
+void Mixer::AddInput(const AudioBuffer& input) {
+ DCHECK_EQ(input.num_frames(), output_.num_frames());
+
+ // Accumulate the input buffers into the output buffer.
+ const size_t num_channels =
+ std::min(input.num_channels(), output_.num_channels());
+ for (size_t n = 0; n < num_channels; ++n) {
+ if (input[n].IsEnabled()) {
+ output_[n] += input[n];
+ }
+ }
+ is_empty_ = false;
+}
+
+const AudioBuffer* Mixer::GetOutput() const {
+ if (is_empty_) {
+ return nullptr;
+ }
+ return &output_;
+}
+
+void Mixer::Reset() {
+ if (!is_empty_) {
+ output_.Clear();
+ }
+ is_empty_ = true;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/mixer.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/mixer.h
new file mode 100644
index 000000000..b89144799
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/mixer.h
@@ -0,0 +1,62 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_MIXER_H_
+#define RESONANCE_AUDIO_DSP_MIXER_H_
+
+#include <memory>
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Accepts multiple input buffers and outputs a downmix to a single output
+// buffer. All input buffers must have the same number of frames per buffer, the
+// output will have the target number of channels regardless of the input number
+// of channels.
+class Mixer {
+ public:
+ // Constructor.
+ //
+ // @param target_num_channels Target number of channels in accumulator buffer.
+ // @param frames_per_buffer Number of frames in accumulator buffer.
+ Mixer(size_t target_num_channels, size_t frames_per_buffer);
+
+ // Adds an input buffer to the mixer, updates the output buffer accordingly.
+ //
+ // @param input Input buffer to be added.
+ void AddInput(const AudioBuffer& input);
+
+ // Returns a pointer to the accumulator.
+ //
+ // @return Pointer to the processed (mixed) output buffer, or nullptr if no
+ // input has been added to the accumulator.
+ const AudioBuffer* GetOutput() const;
+
+ // Resets the state of the accumulator.
+ void Reset();
+
+ private:
+ // Output buffer (accumulator).
+ AudioBuffer output_;
+
+ // Denotes whether the accumulator has processed any inputs or not.
+ bool is_empty_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_MIXER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/mixer_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/mixer_test.cc
new file mode 100644
index 000000000..0cfdf8675
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/mixer_test.cc
@@ -0,0 +1,163 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/mixer.h"
+
+#include <iterator>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "utils/planar_interleaved_conversion.h"
+
+namespace vraudio {
+
+namespace {
+
+// Number of frames per output buffer.
+const size_t kFramesPerBuffer = 3;
+
+// Sample two-channel interleaved input data.
+const float kStereoInput1[kNumStereoChannels * kFramesPerBuffer] = {
+ 0.5f, 0.0f, -0.25f, 0.0f, 0.25f, 0.0f};
+const float kStereoInput2[kNumStereoChannels * kFramesPerBuffer] = {
+ 0.5f, 1.0f, 0.5f, -1.0f, 0.5f, 1.0f};
+
+// Tests that the mixer returns null output if no input has been added.
+TEST(MixerTest, EmptyInputTest) {
+ Mixer mixer(kNumStereoChannels, kFramesPerBuffer);
+
+ const AudioBuffer* output = mixer.GetOutput();
+ EXPECT_TRUE(output == nullptr);
+}
+
+// This is a simple two-channel process test with two inputs. Tests the
+// mixed output buffer against the manually computed output data.
+TEST(MixerTest, ProcessUniformInputChannelsTest) {
+ Mixer mixer(kNumStereoChannels, kFramesPerBuffer);
+
+ // Initialize the input buffers.
+ AudioBuffer input1(kNumStereoChannels, kFramesPerBuffer);
+ FillAudioBuffer(std::begin(kStereoInput1), kFramesPerBuffer,
+ kNumStereoChannels, &input1);
+ AudioBuffer input2(kNumStereoChannels, kFramesPerBuffer);
+ FillAudioBuffer(std::begin(kStereoInput2), kFramesPerBuffer,
+ kNumStereoChannels, &input2);
+
+ // Add the input buffers to the mixer.
+ mixer.AddInput(input1);
+ mixer.AddInput(input2);
+ // Get the processed output.
+ const AudioBuffer* output = mixer.GetOutput();
+
+ // Test that the output channels was accumulated correctly.
+ EXPECT_FALSE(output == nullptr);
+ EXPECT_EQ(output->num_channels(), kNumStereoChannels);
+ EXPECT_EQ(output->num_frames(), kFramesPerBuffer);
+ for (size_t n = 0; n < kNumStereoChannels; ++n) {
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ EXPECT_NEAR((*output)[n][i], input1[n][i] + input2[n][i], kEpsilonFloat);
+ }
+ }
+}
+
+// This is a non-uniform process test with two inputs with arbitrary number of
+// channels. Tests the mixed output buffer with different target number of
+// channels against the manually computed output data.
+TEST(MixerTest, ProcessVaryingInputChannelsTest) {
+ // Initialize the input buffers.
+ AudioBuffer mono_input(kNumMonoChannels, kFramesPerBuffer);
+ FillAudioBuffer(std::begin(kStereoInput1), kFramesPerBuffer, kNumMonoChannels,
+ &mono_input);
+ AudioBuffer stereo_input(kNumStereoChannels, kFramesPerBuffer);
+ FillAudioBuffer(std::begin(kStereoInput2), kFramesPerBuffer,
+ kNumStereoChannels, &stereo_input);
+
+ // Initialize a mono mixer.
+ Mixer mono_mixer(kNumMonoChannels, kFramesPerBuffer);
+ // Add the input buffers to the mixer.
+ mono_mixer.AddInput(mono_input);
+ mono_mixer.AddInput(stereo_input);
+ // Get the processed output.
+ const AudioBuffer* mono_output = mono_mixer.GetOutput();
+ // Test that the mono output channel was accumulated correctly.
+ EXPECT_FALSE(mono_output == nullptr);
+ EXPECT_EQ(mono_output->num_channels(), kNumMonoChannels);
+ EXPECT_EQ(mono_output->num_frames(), kFramesPerBuffer);
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ EXPECT_NEAR((*mono_output)[0][i], mono_input[0][i] + stereo_input[0][i],
+ kEpsilonFloat);
+ }
+
+ // Initialize a stereo mixer.
+ Mixer stereo_mixer(kNumStereoChannels, kFramesPerBuffer);
+ // Add the input buffers to the mixer.
+ stereo_mixer.AddInput(mono_input);
+ stereo_mixer.AddInput(stereo_input);
+ // Get the processed output.
+ const AudioBuffer* stereo_output = stereo_mixer.GetOutput();
+ // Test that the stereo output channels were accumulated correctly.
+ EXPECT_FALSE(stereo_output == nullptr);
+ EXPECT_EQ(stereo_output->num_channels(), kNumStereoChannels);
+ EXPECT_EQ(stereo_output->num_frames(), kFramesPerBuffer);
+ for (size_t n = 0; n < kNumStereoChannels; ++n) {
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ // The second channel should only contain the samples from |stereo_input|.
+ EXPECT_NEAR(
+ (*stereo_output)[n][i],
+ (n == 0) ? mono_input[n][i] + stereo_input[n][i] : stereo_input[n][i],
+ kEpsilonFloat);
+ }
+ }
+}
+
+// This is a two-channel reset test for the mixer with single input at a time.
+// First, adds an input buffer, resets the mixer. Then, adds another input
+// buffer and tests the final output buffer against the data of the last added
+// input buffer to verify if the system has been successfully reset.
+TEST(MixerTest, ResetTest) {
+ Mixer mixer(kNumStereoChannels, kFramesPerBuffer);
+
+ // Initialize the input buffers.
+ AudioBuffer input1(kNumStereoChannels, kFramesPerBuffer);
+ FillAudioBuffer(std::begin(kStereoInput1), kFramesPerBuffer,
+ kNumStereoChannels, &input1);
+ AudioBuffer input2(kNumStereoChannels, kFramesPerBuffer);
+ FillAudioBuffer(std::begin(kStereoInput2), kFramesPerBuffer,
+ kNumStereoChannels, &input2);
+
+ // Add the first input buffer to the mixer.
+ mixer.AddInput(input1);
+ // Reset the accumulator.
+ mixer.Reset();
+ // Add the second input buffers to the mixer.
+ mixer.AddInput(input2);
+ // Get the processed output.
+ const AudioBuffer* output = mixer.GetOutput();
+ // Test that the output channels contains only the samples from |input2|.
+ EXPECT_FALSE(output == nullptr);
+ EXPECT_EQ(output->num_channels(), kNumStereoChannels);
+ EXPECT_EQ(output->num_frames(), kFramesPerBuffer);
+ for (size_t n = 0; n < kNumStereoChannels; ++n) {
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ EXPECT_NEAR((*output)[n][i], input2[n][i], kEpsilonFloat);
+ }
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter.cc
new file mode 100644
index 000000000..18c4625d5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter.cc
@@ -0,0 +1,59 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/mono_pole_filter.h"
+
+#include <algorithm>
+
+#include "base/constants_and_types.h"
+
+
+namespace vraudio {
+
+MonoPoleFilter::MonoPoleFilter(float coefficient) : previous_output_(0.0f) {
+ SetCoefficient(coefficient);
+}
+
+void MonoPoleFilter::SetCoefficient(float coefficient) {
+ coefficient_ = std::max(std::min(coefficient, 1.0f), 0.0f);
+}
+
+bool MonoPoleFilter::Filter(const AudioBuffer::Channel& input,
+ AudioBuffer::Channel* output) {
+
+ DCHECK(output);
+ const size_t num_frames = input.size();
+ DCHECK_EQ(num_frames, output->size());
+
+ // Do not perform processing if the coefficient is zero to avoid wasteful
+ // "all pass" cases.
+ if (coefficient_ < kEpsilonFloat) {
+ previous_output_ = input[num_frames - 1];
+ return false;
+ }
+
+ // The difference equation implemented here is as follows:
+ // y[n] = a * (y[n-1] - x[n]) + x[n]
+ // where y[n] is the output and x[n] is the input vector.
+ for (size_t frame = 0; frame < num_frames; ++frame) {
+ (*output)[frame] =
+ coefficient_ * (previous_output_ - input[frame]) + input[frame];
+ previous_output_ = (*output)[frame];
+ }
+ return true;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter.h
new file mode 100644
index 000000000..4ec3f75dd
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter.h
@@ -0,0 +1,57 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_MONO_POLE_FILTER_H_
+#define RESONANCE_AUDIO_DSP_MONO_POLE_FILTER_H_
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Class representing a mono pole filter. This class also performs filtering.
+class MonoPoleFilter {
+ public:
+ // Constructs a |MonoPoleFilter| given a single coefficient.
+ //
+ // @param coefficient A single coefficient between 0.0f and 1.0f.
+ explicit MonoPoleFilter(float coefficient);
+
+ // Filter method for use with AudioBuffer::Channel.
+ //
+ // @param input |AudioBuffer::Channel| of input to be processed.
+ // @param output Pointer to output |AudioBuffer::Channel|.
+ // @return Returns false if the filter has an allpass configuration. This
+ // helps to avoid copies whenever the output is expected to be identical
+ // to the input.
+ bool Filter(const AudioBuffer::Channel& input, AudioBuffer::Channel* output);
+
+ // Sets the filter's coefficent.
+ //
+ // @param coefficient A mono pole filter coefficient.
+ void SetCoefficient(float coefficient);
+
+ private:
+ // The previous frame computed by the filter.
+ float previous_output_;
+
+ // Represents and maintains the state of the filter in terms of its
+ // transfer function coefficient.
+ float coefficient_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_MONO_POLE_FILTER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter_test.cc
new file mode 100644
index 000000000..c93b4fab7
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/mono_pole_filter_test.cc
@@ -0,0 +1,59 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/mono_pole_filter.h"
+
+#include <cmath>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+namespace {
+
+const float kCoefficient = 0.5f;
+const size_t kFramesPerBuffer = 10;
+
+// Tests that the filter correctly implements the difference equation.
+TEST(MonoPoleFilterTest, ImpulseResponseTest) {
+ MonoPoleFilter filter(kCoefficient);
+ AudioBuffer buffer(1U, kFramesPerBuffer);
+ buffer.Clear();
+ buffer[0][0] = 1.0f;
+ EXPECT_TRUE(filter.Filter(buffer[0], &buffer[0]));
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ // The impulse response of this filter (for coefficient a), should be:
+ // d[n] = (1 - a) * a^n
+ const float expected =
+ (1.0f - kCoefficient) * IntegerPow(kCoefficient, static_cast<int>(i));
+ EXPECT_NEAR(buffer[0][i], expected, kEpsilonFloat);
+ }
+}
+
+// Tests that no processing is performed when the filter is allpass.
+TEST(MonoPoleFilterTest, AllPassNoProcessingTest) {
+ MonoPoleFilter filter(0.0f);
+ AudioBuffer buffer(1U, kFramesPerBuffer);
+ buffer.Clear();
+ buffer[0][0] = 1.0f;
+ EXPECT_FALSE(filter.Filter(buffer[0], &buffer[0]));
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir.cc
new file mode 100644
index 000000000..dc3bbcb8f
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir.cc
@@ -0,0 +1,152 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/multi_channel_iir.h"
+
+#include <algorithm>
+#include <limits>
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/simd_macros.h"
+
+
+namespace vraudio {
+
+std::unique_ptr<MultiChannelIir> MultiChannelIir::Create(
+ size_t num_channels, size_t frames_per_buffer,
+ const std::vector<std::vector<float>>& numerators,
+ const std::vector<std::vector<float>>& denominators) {
+ CHECK_EQ(denominators.size(), numerators.size());
+ CHECK_EQ(denominators.size(), num_channels);
+ CHECK_EQ(num_channels % SIMD_LENGTH, 0U);
+ CHECK_GT(num_channels, 0U);
+ for (size_t channel = 0; channel < num_channels; ++channel) {
+ CHECK_GT(denominators[channel].size(), 0U);
+ CHECK_GT(std::abs(denominators[channel][0]),
+ std::numeric_limits<float>::epsilon());
+ CHECK_EQ(denominators[channel].size(), numerators[channel].size());
+ }
+
+ std::unique_ptr<MultiChannelIir> multi_channel_iir(new MultiChannelIir(
+ num_channels, frames_per_buffer, numerators[0].size()));
+ CHECK(multi_channel_iir);
+
+ for (size_t channel = 0; channel < num_channels; ++channel) {
+ size_t interleaved_index = channel;
+ for (size_t i = 0; i < numerators[channel].size(); ++i) {
+ // Make the denominator polynomials monic, (divide all coefficients by the
+ // the first denominator coefficients). Furthermore negate all
+ // coefficients beyond the first (see equation in Process method).
+ // Copy the coefficients into the |numerator_| and |denominator_| buffers.
+ multi_channel_iir->numerator_[0][interleaved_index] =
+ numerators[channel][i] / denominators[channel][0];
+ multi_channel_iir->denominator_[0][interleaved_index] =
+ denominators[channel][i] /
+ ((i > 0) ? -denominators[channel][0] : denominators[channel][0]);
+ interleaved_index += num_channels;
+ }
+ }
+
+ multi_channel_iir->delay_line_.Clear();
+ return multi_channel_iir;
+}
+
+void MultiChannelIir::Process(AudioBuffer::Channel* interleaved_buffer) {
+
+ DCHECK(interleaved_buffer);
+ DCHECK_EQ(interleaved_buffer->size(), num_channels_ * frames_per_buffer_);
+ const SimdVector* simd_numerator =
+ reinterpret_cast<SimdVector*>(&(numerator_[0][0]));
+ const SimdVector* simd_denominator =
+ reinterpret_cast<SimdVector*>(&(denominator_[0][0]));
+ SimdVector* simd_delay_line =
+ reinterpret_cast<SimdVector*>(&(delay_line_[0][0]));
+ SimdVector* simd_buffer =
+ reinterpret_cast<SimdVector*>(&((*interleaved_buffer)[0]));
+
+ const size_t num_channel_chunks = num_channels_ / SIMD_LENGTH;
+ const size_t num_buffer_chunks = interleaved_buffer->size() / SIMD_LENGTH;
+ const size_t delay_length_in_chunks = num_channel_chunks * num_coefficients_;
+
+ for (size_t current_frame = 0, individual_frame = 0;
+ current_frame < num_buffer_chunks;
+ current_frame += num_channel_chunks, individual_frame += num_channels_) {
+ DCHECK_LT(individual_frame, interleaved_buffer->size());
+ // Copy the current sample into the delay line at the very start.
+ // {x[n], w[n-1], w[n-2], . . .} where each x, w represents all channels.
+ std::copy_n(interleaved_buffer->begin() + individual_frame, num_channels_,
+ delay_line_[0].begin() + (delay_line_front_ * SIMD_LENGTH));
+ // Using A Direct Form II implementation difference equation:
+ // Source: Digital Signal Processing Principles Algorithms & Applications
+ // Fourth Edition. John G. Prolakis and Dimitris G. Manolakis - Chap 9
+ // w[n] = x[n] - (a1/a0)*w[n-1] - (a2/a0)*w[n-2] - . . .
+ // y(n) = (b0/a0)*w[n] + (b1/a0)*w[n-1] + (b2/a0)*w[n-2] + . . .
+ // where x[n] is input, w[n] is storage and y[n] is output.
+ // The division by a0 has been performed in the constructor along with the
+ // negation of the denominator coefficients beyond the first. Note also
+ // that each term here refers to a set of channels.
+ for (size_t channel_chunk = 0; channel_chunk < num_channel_chunks;
+ ++channel_chunk) {
+ // First zero out the relevant section of the buffer before accumulation.
+ // Zero constant used for loading zeros into a neon simd array, as the
+ // |vld1q_dup_f32| neon intrinsic requires an lvalue parameter.
+ const float kZerof = 0.0f;
+ simd_buffer[current_frame + channel_chunk] = SIMD_LOAD_ONE_FLOAT(kZerof);
+ for (size_t coeff_offset = num_channel_chunks;
+ coeff_offset < delay_length_in_chunks;
+ coeff_offset += num_channel_chunks) {
+ // Denominator part.
+ const size_t multiplication_index = channel_chunk + coeff_offset;
+ const size_t delay_multiplication_index =
+ (multiplication_index + delay_line_front_) % delay_length_in_chunks;
+ const size_t delay_write_index = channel_chunk + delay_line_front_;
+ simd_delay_line[delay_write_index] =
+ SIMD_MULTIPLY_ADD(simd_denominator[multiplication_index],
+ simd_delay_line[delay_multiplication_index],
+ simd_delay_line[delay_write_index]);
+ }
+ for (size_t coeff_offset = 0; coeff_offset < delay_length_in_chunks;
+ coeff_offset += num_channel_chunks) {
+ // Numerator part.
+ const size_t multiplication_index = channel_chunk + coeff_offset;
+ const size_t write_index = current_frame + channel_chunk;
+ const size_t delay_multiplication_index =
+ (multiplication_index + delay_line_front_) % delay_length_in_chunks;
+ simd_buffer[write_index] =
+ SIMD_MULTIPLY_ADD(simd_numerator[multiplication_index],
+ simd_delay_line[delay_multiplication_index],
+ simd_buffer[write_index]);
+ }
+ }
+ // Update the index to the wrapped around 'front' of the delay line.
+ delay_line_front_ = ((static_cast<int>(delay_line_front_) -
+ num_channel_chunks + delay_length_in_chunks) %
+ delay_length_in_chunks);
+ }
+}
+
+MultiChannelIir::MultiChannelIir(size_t num_channels, size_t frames_per_buffer,
+ size_t num_coefficients)
+ : num_channels_(num_channels),
+ frames_per_buffer_(frames_per_buffer),
+ num_coefficients_(num_coefficients),
+ delay_line_front_(0),
+ numerator_(kNumMonoChannels, num_coefficients_ * num_channels_),
+ denominator_(kNumMonoChannels, num_coefficients_ * num_channels_),
+ delay_line_(kNumMonoChannels, num_coefficients_ * num_channels_) {}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir.h
new file mode 100644
index 000000000..fd7efe72e
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir.h
@@ -0,0 +1,88 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_MULTI_CHANNEL_IIR_H_
+#define RESONANCE_AUDIO_DSP_MULTI_CHANNEL_IIR_H_
+
+#include <memory>
+#include <vector>
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Class that performs IIR filtering on interleaved data. This class can be used
+// to implement any order of IIR filter on multichannel data where the number of
+// channels is a multiple of the SIMD vector length.
+class MultiChannelIir {
+ public:
+ // Returns a |MultiChannelIir| given valid parameters.
+ //
+ // @param num_channels Number of channels in each input buffer. The number of
+ // channels must be divisible by |SIMD_LENGTH|.
+ // @param frames_per_buffer Number of frames in each input buffer.
+ // @param numerators Numerator coefficients, one set per channel.
+ // @param denominators Denominator coefficients, should be equal in length to
+ // the |numerator| vector, one set per channel.
+ // @return A |MultiChannelIir| instance.
+ static std::unique_ptr<MultiChannelIir> Create(
+ size_t num_channels, size_t frames_per_buffer,
+ const std::vector<std::vector<float>>& numerators,
+ const std::vector<std::vector<float>>& denominators);
+
+ // Processes an interleaved buffer of input data with the given IIR filter.
+ //
+ // @param interleaved_buffer A single channel of data containing input in
+ // interleaved format, this will contain output data in interleaved format
+ // on return.
+ void Process(AudioBuffer::Channel* interleaved_buffer);
+
+ private:
+ // Constructs a |MultiChannelIir|.
+ //
+ // @param num_channels Number of channels in each input buffer. The number of
+ // channels must be divisible by |SIMD_LENGTH|.
+ // @param frames_per_buffer Number of frames in each input buffer.
+ // @param num_coefficients Number of coefficients in the numerator, which
+ // equals the number in the denominator.
+ MultiChannelIir(size_t num_channels, size_t frames_per_buffer,
+ size_t num_coefficients);
+
+ // Number of channels in each input buffer.
+ const size_t num_channels_;
+
+ // Number of frames in each input buffer.
+ const size_t frames_per_buffer_;
+
+ // Number of coefficients in the numerator and denominator polynomials.
+ const size_t num_coefficients_;
+
+ // Current front of the delay line which is circularly indexed.
+ size_t delay_line_front_;
+
+ // Stores numerator coefficients in repeated fashion.
+ AudioBuffer numerator_;
+
+ // Stores denominator coefficients in repeated fashion.
+ AudioBuffer denominator_;
+
+ // Holds previous data computed from the numerator section.
+ AudioBuffer delay_line_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_MULTI_CHANNEL_IIR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir_test.cc
new file mode 100644
index 000000000..3c291196e
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/multi_channel_iir_test.cc
@@ -0,0 +1,117 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/multi_channel_iir.h"
+
+#include <memory>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+namespace {
+
+const size_t kFramesPerBuffer = 4;
+
+// Fills a channel buffer with each of the values passed |num_channels| times.
+void FillChannels(const std::vector<float>& values, size_t num_channels,
+ AudioBuffer::Channel* buffer) {
+ DCHECK_EQ(values.size() * num_channels, buffer->size());
+ size_t offset = 0;
+ for (auto value : values) {
+ std::fill_n(buffer->begin() + offset, num_channels, value);
+ offset += num_channels;
+ }
+}
+
+// Compares the contents of the |input| to the corresponding section of the
+// |expected| vector.
+void CompareMultiChannelOutput(const std::vector<std::vector<float>>& expected,
+ size_t offset, size_t num_channels,
+ const AudioBuffer::Channel& input) {
+ DCHECK_GE(expected[0].size(), kFramesPerBuffer + offset);
+ for (size_t channel = 0; channel < num_channels; ++channel) {
+ for (size_t frame = 0; frame < kFramesPerBuffer; ++frame) {
+ EXPECT_NEAR(expected[channel][frame + offset],
+ input[frame * num_channels + channel], kEpsilonFloat);
+ }
+ }
+}
+
+// Tests that the |MultiChannelIir| can filter a single channel of input
+// simultaneously with four different biquad filters.
+TEST(MultiChannelIirTest, MultipleFilterSetProcessTest) {
+ const std::vector<std::vector<float>> numerators({{1.0f, 3.0f, 5.0f},
+ {2.0f, 2.0f, 4.0f},
+ {1.0f, 2.0f, 2.0f},
+ {2.0f, 4.0f, 2.0f}});
+ const std::vector<std::vector<float>> denominators({{1.0f, 1.0f, 0.0f},
+ {2.0f, 2.0f, 0.0f},
+ {1.0f, 1.0f, 0.0f},
+ {2.0f, 2.0f, 0.0f}});
+
+ const std::vector<float> initial_input({1.0f, 4.0f, 6.0f, 0.0f});
+ const std::vector<float> zero_input({0.0f, 0.0f, 0.0f, 0.0f});
+ // These values have been determined through the MATLAB commands:
+ // filter([1 3 5], [1 1 0], [1 4 6 0, 0 0 0 0, 0 0 0 0])
+ // filter([2 2 4], [2 2 0], [1 4 6 0, 0 0 0 0, 0 0 0 0])
+ // filter([1 2 2], [1 1 0], [1 4 6 0, 0 0 0 0, 0 0 0 0])
+ // filter([2 4 2], [2 2 0], [1 4 6 0, 0 0 0 0, 0 0 0 0])
+ const std::vector<std::vector<float>> kExpectedOutputs = {
+ {1.0f, 6.0f, 17.0f, 21.0f, 9.0f, -9.0f, 9.0f, -9.0f, 9.0f, -9.0f, 9.0f,
+ -9.0f},
+ {1.0f, 4.0f, 8.0f, 6.0f, 6.0f, -6.0f, 6.0f, -6.0f, 6.0f, -6.0f, 6.0f,
+ -6.0f},
+ {1.0f, 5.0f, 11.0f, 9.0f, 3.0f, -3.0f, 3.0f, -3.0f, 3.0f, -3.0f, 3.0f,
+ -3.0f},
+ {1.0f, 5.0f, 10.0f, 6.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f}};
+
+ const size_t num_channels = numerators.size();
+
+ AudioBuffer interleaved_buffer(kNumMonoChannels,
+ num_channels * kFramesPerBuffer);
+ std::unique_ptr<MultiChannelIir> filter = MultiChannelIir::Create(
+ num_channels, kFramesPerBuffer, numerators, denominators);
+
+ // Filter the initial buffer [1 4 6 0], and compare the output to the first
+ // kFramesPerBuffer entries in |kExpectedOutputs|.
+ FillChannels(initial_input, num_channels, &interleaved_buffer[0]);
+ filter->Process(&(interleaved_buffer[0]));
+ CompareMultiChannelOutput(kExpectedOutputs, /*offset*/ 0, num_channels,
+ interleaved_buffer[0]);
+
+ // Filter zeros [0 0 0 0], and compare the output to the next kFramesPerBuffer
+ // entries in |kExpectedOutputs|.
+ FillChannels(zero_input, num_channels, &interleaved_buffer[0]);
+ filter->Process(&(interleaved_buffer[0]));
+ CompareMultiChannelOutput(kExpectedOutputs, kFramesPerBuffer, num_channels,
+ interleaved_buffer[0]);
+
+ // Filter zeros [0 0 0 0], and compare the output to the next kFramesPerBuffer
+ // entries in |kExpectedOutputs|.
+ FillChannels(zero_input, num_channels, &interleaved_buffer[0]);
+ filter->Process(&(interleaved_buffer[0]));
+ CompareMultiChannelOutput(kExpectedOutputs, 2 * kFramesPerBuffer,
+ num_channels, interleaved_buffer[0]);
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/near_field_processor.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/near_field_processor.cc
new file mode 100644
index 000000000..90afcc472
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/near_field_processor.cc
@@ -0,0 +1,97 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/near_field_processor.h"
+
+#include "base/constants_and_types.h"
+#include "dsp/filter_coefficient_generators.h"
+#include "dsp/gain.h"
+
+namespace vraudio {
+
+namespace {
+
+// Cross-over frequency of the band-splitting filter.
+const float kCrossOverFrequencyHz = 1000.0f;
+
+// +6dB bass boost factor converted to linear scale.
+const float kBassBoost = 2.0f;
+
+// Average group delay of the HRTF filters in seconds. Please see
+// [internal ref]
+const float kMeanHrtfGroupDelaySeconds = 0.00066667f;
+
+// Average group delay of the shelf-filter in samples.
+const size_t kMeanShelfFilterGroupDelaySamples = 1;
+
+} // namespace
+
+NearFieldProcessor::NearFieldProcessor(int sample_rate,
+ size_t frames_per_buffer)
+ : frames_per_buffer_(frames_per_buffer),
+ delay_compensation_(static_cast<size_t>(kMeanHrtfGroupDelaySeconds *
+ static_cast<float>(sample_rate)) -
+ kMeanShelfFilterGroupDelaySamples),
+ lo_pass_filter_(BiquadCoefficients(), frames_per_buffer_),
+ hi_pass_filter_(BiquadCoefficients(), frames_per_buffer_),
+ low_passed_buffer_(kNumMonoChannels, frames_per_buffer_),
+ delay_filter_(delay_compensation_, frames_per_buffer_) {
+ DCHECK_GT(sample_rate, 0);
+ DCHECK_GT(frames_per_buffer, 0);
+ DCHECK_LT(kCrossOverFrequencyHz, 0.5f * static_cast<float>(sample_rate));
+
+ // Generate biquad coefficients and construct low- and high-pass filter
+ // states.
+ BiquadCoefficients lo_pass_coefficients;
+ BiquadCoefficients hi_pass_coefficients;
+ ComputeDualBandBiquadCoefficients(sample_rate, kCrossOverFrequencyHz,
+ &lo_pass_coefficients,
+ &hi_pass_coefficients);
+
+ // Create two biquad filters initialized with the above filter coefficients.
+ lo_pass_filter_.SetCoefficients(lo_pass_coefficients);
+ hi_pass_filter_.SetCoefficients(hi_pass_coefficients);
+}
+
+void NearFieldProcessor::Process(const AudioBuffer::Channel& input,
+ AudioBuffer::Channel* output,
+ bool enable_hrtf) {
+
+ DCHECK(output);
+ DCHECK_EQ(input.size(), frames_per_buffer_);
+ DCHECK_EQ(output->size(), frames_per_buffer_);
+
+ // Low-pass filter the input and put it in the temporary low-passed buffer.
+ auto* low_passed_channel = &low_passed_buffer_[0];
+ lo_pass_filter_.Filter(input, low_passed_channel);
+
+ // High-pass filter the input and put it in the output channel (unmodified).
+ hi_pass_filter_.Filter(input, output);
+ // Iterate through all the samples in the |low_passed_buffer_| and apply
+ // the bass boost. Then, combine with the high-passed part in order to form
+ // the shelf-filtered output. Note: phase flip of the low-passed signal is
+ // required to form the correct filtered output.
+ ConstantGain(/*offset_index=*/0, -kBassBoost, *low_passed_channel, output,
+ /*accumulate_output=*/true);
+
+ if (enable_hrtf) {
+ // Delay the output to compensate for the average HRTF group delay.
+ delay_filter_.InsertData(*output);
+ delay_filter_.GetDelayedData(delay_compensation_, output);
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/near_field_processor.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/near_field_processor.h
new file mode 100644
index 000000000..86a3093d5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/near_field_processor.h
@@ -0,0 +1,75 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_NEAR_FIELD_PROCESSOR_H_
+#define RESONANCE_AUDIO_DSP_NEAR_FIELD_PROCESSOR_H_
+
+#include "base/audio_buffer.h"
+#include "dsp/biquad_filter.h"
+#include "dsp/delay_filter.h"
+
+namespace vraudio {
+
+// Class which applies an approximate near field effect to a source mono input.
+// The effect consists of a +6dB bass boost (shelf-filter) as well as phase
+// correction (HRTF group delay compensation) when the signal is to be combined
+// with the binaural output.
+//
+// For more information: [internal ref]
+class NearFieldProcessor {
+ public:
+ // Constructor of the |NearFieldProcessor|, uses the following parameters:
+ //
+ // @param sample_rate Sampling rate in [Hz].
+ // @param frames_per_buffer Number of frames per buffer in the input/output
+ // signal.
+ NearFieldProcessor(int sample_rate, size_t frames_per_buffer);
+
+ // Returns currently used delay compensation in samples.
+ size_t GetDelayCompensation() const { return delay_compensation_; }
+
+ // Applies approximate near field effect to the source mono input signal.
+ //
+ // @param input Mono input channel.
+ // @param output Pointer to mono output channel.
+ // @param enable_hrtf Whether to enable delay compensation for HRTF filtering.
+ void Process(const AudioBuffer::Channel& input, AudioBuffer::Channel* output,
+ bool enable_hrtf);
+
+ private:
+ // Number of frames per buffer.
+ const size_t frames_per_buffer_;
+
+ // Delay compensation computed as average group delay of the HRTF filter
+ // minus average group delay of the shelf-filter. Should be disabled when
+ // using with stereo-panned sound sources.
+ const size_t delay_compensation_;
+
+ // Biquad filters that apply frequency splitting of the input mono signal.
+ BiquadFilter lo_pass_filter_;
+ BiquadFilter hi_pass_filter_;
+
+ // Buffer for the low-passed signal. We do not modify the high-passed signal
+ // so we can write it directly to the output channel.
+ AudioBuffer low_passed_buffer_;
+
+ // Delay filter used to delay the incoming input mono buffer.
+ DelayFilter delay_filter_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_NEAR_FIELD_PROCESSOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator.cc
new file mode 100644
index 000000000..9c8d92c1b
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator.cc
@@ -0,0 +1,52 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/occlusion_calculator.h"
+
+#include <cmath>
+
+#include "base/logging.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+float CalculateDirectivity(float alpha, float order,
+ const SphericalAngle& spherical_angle) {
+ // Clamp alpha weighting.
+ const float alpha_clamped = std::min(std::max(alpha, 0.0f), 1.0f);
+
+ // Check for zero-valued alpha (omnidirectional).
+ if (alpha_clamped < std::numeric_limits<float>::epsilon()) {
+ return 1.0f;
+ } else {
+ const float gain = (1.0f - alpha_clamped) +
+ alpha_clamped * (std::cos(spherical_angle.azimuth()) *
+ std::cos(spherical_angle.elevation()));
+
+ return std::pow(std::abs(gain), std::max(order, 1.0f));
+ }
+}
+
+float CalculateOcclusionFilterCoefficient(float directivity,
+ float occlusion_intensity) {
+ DCHECK_GE(occlusion_intensity, 0.0f);
+
+ const float occlusion_factor =
+ 1.0f / IntegerPow(occlusion_intensity + 1.0f, 4);
+ return std::max(0.0f, 1.0f - directivity * occlusion_factor);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator.h
new file mode 100644
index 000000000..924da9068
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator.h
@@ -0,0 +1,54 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_OCCLUSION_CALCULATOR_H_
+#define RESONANCE_AUDIO_DSP_OCCLUSION_CALCULATOR_H_
+
+#include "base/spherical_angle.h"
+
+namespace vraudio {
+
+// Calculates directivity gain value for supplied source and listener
+// parameters.
+//
+// @param alpha Balance between dipole pattern and omnidirectional pattern for
+// source emission. By varying this value, differing directivity patterns
+// can be formed. Value in range [0, 1]. 2D visualization for several
+// values: http://goo.gl/GhKvoc.
+// @param order Order of directivity function. Higher values will result in
+// increased directivity. Value in range [1, +inf]. 2D visualization for
+// several orders:
+// http://goo.gl/sNrm1a.
+// @param spherical_angle Spherical angle of the listener relative to the
+// audio source which is being shaped.
+// @return Gain value in range [0, 1].
+float CalculateDirectivity(float alpha, float order,
+ const SphericalAngle& spherical_angle);
+
+// This function calculates a |MonoPoleFilter| coefficient based upon the
+// directivity and occlusion values. The coefficient calculation was designed
+// via empirical methods.
+//
+// @param directivity Gain value calculated based upon the directivity.
+// @param occlusion_intensity Gain value calculated based upon the degree of
+// occlusion.
+// @return Filter coefficient for a mono pole low pass filter.
+float CalculateOcclusionFilterCoefficient(float directivity,
+ float occlusion_intensity);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_OCCLUSION_CALCULATOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator_test.cc
new file mode 100644
index 000000000..4de2d07ad
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/occlusion_calculator_test.cc
@@ -0,0 +1,139 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/occlusion_calculator.h"
+
+#include <algorithm>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+namespace {
+
+// Spherical coordinates of listener relative to source.
+const float kListenerAheadRads[2] = {0.0f, 0.0f};
+const float kListenerBesideRads[2] = {0.0f, static_cast<float>(M_PI_2)};
+const float kListenerAboveAndAheadRads[2] = {static_cast<float>(M_PI_4), 0.0f};
+
+// Test case data structure.
+struct DirectivityTestParams {
+ // Directivity function's alpha weighting.
+ const float alpha;
+ // Directivity function's order.
+ const float order;
+ // Spherical angle of the listener relative to the source.
+ const float* relative_spherical_angle;
+ // Expected value produced by the directivity function for the given input
+ // parameters.
+ const float expected_directivity;
+};
+
+// This test runs through a series of parametrized test cases and checks that
+// the directivity value calculated according to those parameters is correct.
+class DirectivityCalculatorParametrizedTest
+ : public testing::Test,
+ public testing::WithParamInterface<DirectivityTestParams> {};
+
+// Parametrized test which verifies that the directivity value calculated from
+// the test parameters matches the expected value supplied.
+TEST_P(DirectivityCalculatorParametrizedTest, CalculateDirectivityTest) {
+ // Test parameters.
+ const DirectivityTestParams test_params = GetParam();
+
+ // Construct test angle.
+ const float elevation_rad = test_params.relative_spherical_angle[0];
+ const float azimuth_rad = test_params.relative_spherical_angle[1];
+ SphericalAngle test_angle(elevation_rad, azimuth_rad);
+
+ // Calculate directivity.
+ const float directivity =
+ CalculateDirectivity(test_params.alpha, test_params.order, test_angle);
+
+ // Check calculated directivity.
+ EXPECT_NEAR(test_params.expected_directivity, directivity, kEpsilonFloat);
+}
+
+// Test parameters, according to struct |DirectivityParams|.
+DirectivityTestParams test_cases[] = {
+ // Omnidirectional.
+ {0.0f, 1.0f, &(kListenerAheadRads[0]), 1.0f},
+ {0.0f, 1.0f, &(kListenerBesideRads[0]), 1.0f},
+ {0.0f, 1.0f, &(kListenerAboveAndAheadRads[0]), 1.0f},
+ {0.0f, 2.0f, &(kListenerAboveAndAheadRads[0]), 1.0f},
+ {0.0f, 0.5f, &(kListenerAboveAndAheadRads[0]), 1.0f},
+ // Hypocardioid.
+ {0.25f, 1.0f, &(kListenerAheadRads[0]), 1.0f},
+ {0.25f, 1.0f, &(kListenerBesideRads[0]), 0.75f},
+ {0.25f, 1.0f, &(kListenerAboveAndAheadRads[0]), 0.926777f},
+ {0.25f, 2.0f, &(kListenerAboveAndAheadRads[0]), 0.858915f},
+ {0.25f, 0.5f, &(kListenerAboveAndAheadRads[0]), 0.926777f},
+ // Cardioid.
+ {0.5f, 1.0f, &(kListenerAheadRads[0]), 1.0f},
+ {0.5f, 1.0f, &(kListenerBesideRads[0]), 0.5f},
+ {0.5f, 1.0f, &(kListenerAboveAndAheadRads[0]), 0.853553f},
+ {0.5f, 2.0f, &(kListenerAboveAndAheadRads[0]), 0.728553f},
+ // Hypercardioid.
+ {0.75f, 1.0f, &(kListenerAheadRads[0]), 1.0f},
+ {0.75f, 1.0f, &(kListenerBesideRads[0]), 0.25f},
+ {0.75f, 1.0f, &(kListenerAboveAndAheadRads[0]), 0.780330f},
+ {0.75f, 2.0f, &(kListenerAboveAndAheadRads[0]), 0.608915f},
+ {0.75f, 0.5f, &(kListenerAboveAndAheadRads[0]), 0.780330f},
+ // Dipole.
+ {1.0f, 1.0f, &(kListenerAheadRads[0]), 1.0f},
+ {1.0f, 1.0f, &(kListenerBesideRads[0]), 0.0f},
+ {1.0f, 1.0f, &(kListenerAboveAndAheadRads[0]), 0.707107f},
+ {1.0f, 2.0f, &(kListenerAboveAndAheadRads[0]), 0.5f},
+ {1.0f, 0.5f, &(kListenerAboveAndAheadRads[0]), 0.707107f}};
+
+INSTANTIATE_TEST_CASE_P(Instance, DirectivityCalculatorParametrizedTest,
+ testing::ValuesIn(test_cases));
+
+TEST(DirectivityTest, CalculateOcclusionFilterCoefficientTest) {
+ // When there is no occlusion (occlusion == 0) expect the filter coefficient
+ // to be 1 - directivity.
+ const std::vector<float> directivities = {0.0f, 0.3f, 0.5f, 0.7f, 0.9f, 1.5f};
+ for (size_t i = 0; i < directivities.size() - 1; ++i) {
+ const float coefficient =
+ CalculateOcclusionFilterCoefficient(directivities[i], 0.0f);
+ EXPECT_EQ(1.0f - directivities[i], coefficient);
+ }
+ // Ensure the minimum value returned is 0.
+ const float coefficient =
+ CalculateOcclusionFilterCoefficient(directivities.back(), 0.0f);
+ EXPECT_EQ(0.0f, coefficient);
+}
+
+TEST(OcclusionTest, CalculateOcclusionFilterCoefficientTest) {
+ // When there is no effect on directivity, expect the filter coefficient
+ // to be 1 / (x + 1)^4 where x is the occlusion intensity.
+ const std::vector<float> occlusions = {0.01f, 0.1f, 1.0f, 10.0f, 100.0f};
+ std::vector<float> expected_coefficients = occlusions;
+ // Calculate 1 / (x + 1)^4 where x is the occlusion intensity.
+ std::for_each(expected_coefficients.begin(), expected_coefficients.end(),
+ [](float& n) { n = 1.0f - 1.0f / IntegerPow(n + 1.0f, 4); });
+ for (size_t i = 0; i < expected_coefficients.size(); ++i) {
+ const float coefficient =
+ CalculateOcclusionFilterCoefficient(1.0f, occlusions[i]);
+ EXPECT_EQ(expected_coefficients[i], coefficient);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter.cc
new file mode 100644
index 000000000..4a2f071f8
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter.cc
@@ -0,0 +1,267 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "dsp/partitioned_fft_filter.h"
+
+#include <algorithm>
+
+#include "pffft.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/misc_math.h"
+#include "base/simd_utils.h"
+
+#include "dsp/utils.h"
+
+namespace vraudio {
+
+PartitionedFftFilter::PartitionedFftFilter(size_t filter_size,
+ size_t frames_per_buffer,
+ FftManager* fft_manager)
+ : PartitionedFftFilter(filter_size, frames_per_buffer, filter_size,
+ fft_manager) {}
+
+PartitionedFftFilter::PartitionedFftFilter(size_t filter_size,
+ size_t frames_per_buffer,
+ size_t max_filter_size,
+ FftManager* fft_manager)
+ : fft_manager_(fft_manager),
+ fft_size_(fft_manager_->GetFftSize()),
+ chunk_size_(fft_size_ / 2),
+ frames_per_buffer_(frames_per_buffer),
+ max_filter_size_(
+ CeilToMultipleOfFramesPerBuffer(max_filter_size, frames_per_buffer_)),
+ max_num_partitions_(max_filter_size_ / frames_per_buffer_),
+ filter_size_(
+ CeilToMultipleOfFramesPerBuffer(filter_size, frames_per_buffer_)),
+ num_partitions_(filter_size_ / frames_per_buffer_),
+ kernel_freq_domain_buffer_(max_num_partitions_, fft_size_),
+ buffer_selector_(0),
+ curr_front_buffer_(0),
+ freq_domain_buffer_(max_num_partitions_, fft_size_),
+ filtered_time_domain_buffers_(kNumStereoChannels, fft_size_),
+ freq_domain_accumulator_(kNumMonoChannels, fft_size_),
+ temp_zeropad_buffer_(kNumMonoChannels, chunk_size_),
+ temp_kernel_chunk_buffer_(kNumMonoChannels, frames_per_buffer_) {
+ // Ensure that |frames_per_buffer_| is less than or equal to the final
+ // partition |chunk_size_|.
+ CHECK(fft_manager_);
+ CHECK_LE(frames_per_buffer_, chunk_size_);
+ CHECK_GE(filter_size_, filter_size);
+ CHECK_GE(max_filter_size_, max_filter_size);
+ // Ensure that |filter_size_| does not exceed |max_filter_size_|.
+ CHECK_LE(filter_size, max_filter_size_);
+ // Make sure all partitions have the same size.
+ CHECK_EQ(num_partitions_ * frames_per_buffer_, filter_size_);
+ CHECK_EQ(max_num_partitions_ * frames_per_buffer_, max_filter_size_);
+
+ Clear();
+}
+
+void PartitionedFftFilter::Clear() {
+ // Reset valid part of the filter |FreqDomainBuffer|s to zero.
+ for (size_t i = 0; i < num_partitions_; ++i) {
+ kernel_freq_domain_buffer_[i].Clear();
+ freq_domain_buffer_[i].Clear();
+ }
+ // Reset filter state to zero.
+ filtered_time_domain_buffers_.Clear();
+}
+
+void PartitionedFftFilter::ResetFreqDomainBuffers(size_t new_filter_size) {
+
+ // Update the filter size.
+ DCHECK_GT(new_filter_size, 0U);
+ filter_size_ =
+ CeilToMultipleOfFramesPerBuffer(new_filter_size, frames_per_buffer_);
+ DCHECK_LE(filter_size_, max_filter_size_);
+
+ const size_t old_num_partitions = num_partitions_;
+ num_partitions_ = filter_size_ / frames_per_buffer_;
+ const size_t min_num_partitions =
+ std::min(old_num_partitions, num_partitions_);
+
+ if (curr_front_buffer_ > 0) {
+
+ FreqDomainBuffer temp_freq_domain_buffer(min_num_partitions, fft_size_);
+ // Copy in |min_num_partitions| to |temp_freq_domain_buffer|, starting with
+ // the partition at |curr_front_buffer_| to be moved back to the beginning
+ // of |freq_domain_buffer| .
+ for (size_t i = 0; i < min_num_partitions; ++i) {
+ temp_freq_domain_buffer[i] =
+ freq_domain_buffer_[(curr_front_buffer_ + i) % old_num_partitions];
+ }
+ // Replace the partitions.
+ for (size_t i = 0; i < min_num_partitions; ++i) {
+ freq_domain_buffer_[i] = temp_freq_domain_buffer[i];
+ }
+ curr_front_buffer_ = 0;
+ }
+ // Clear out the remaining partitions in case the filter size grew.
+ for (size_t i = old_num_partitions; i < num_partitions_; ++i) {
+ freq_domain_buffer_[i].Clear();
+ }
+}
+
+void PartitionedFftFilter::ReplacePartition(
+ size_t partition_index, const AudioBuffer::Channel& kernel_chunk) {
+ DCHECK_GE(partition_index, 0U);
+ DCHECK_LT(partition_index, num_partitions_);
+ DCHECK_EQ(kernel_chunk.size(), frames_per_buffer_);
+
+ fft_manager_->FreqFromTimeDomain(
+ kernel_chunk, &kernel_freq_domain_buffer_[partition_index]);
+}
+
+void PartitionedFftFilter::SetFilterLength(size_t new_filter_size) {
+ DCHECK_GT(new_filter_size, 0U);
+ new_filter_size =
+ CeilToMultipleOfFramesPerBuffer(new_filter_size, frames_per_buffer_);
+ DCHECK_LE(new_filter_size, max_filter_size_);
+
+ const size_t new_num_partitions = new_filter_size / frames_per_buffer_;
+ DCHECK_LE(new_num_partitions, max_num_partitions_);
+
+ // Clear out the remaining partitions in case the filter size grew.
+ for (size_t i = num_partitions_; i < new_num_partitions; ++i) {
+ kernel_freq_domain_buffer_[i].Clear();
+ }
+ // Call |ResetFreqDomainBuffers| to make sure that the input buffers are also
+ // correctly resized.
+ ResetFreqDomainBuffers(new_filter_size);
+}
+
+void PartitionedFftFilter::SetTimeDomainKernel(
+ const AudioBuffer::Channel& kernel) {
+
+
+ // Precomputes a set of floor(|filter_size_|/(|fft_size|/2)) frequency domain
+ // kernels, one for each partition of the |kernel|. This allows to reduce
+ // computational complexity if a fixed set of filter kernels is needed. The
+ // size of the |kernel| can be arbitrarily long but must not be less than
+ // |fft_size_|/2. Filter lengths which are multiples of |fft_size_|/2 are most
+ // efficient.
+
+ // Calculate the new number of partitions as filter length may have changed.
+ // This number is set to 1 if the filter length is smaller than
+ // |frames_per_buffer_|.
+ const size_t new_num_partitions =
+ CeilToMultipleOfFramesPerBuffer(kernel.size(), frames_per_buffer_) /
+ frames_per_buffer_;
+
+ auto& padded_channel = temp_kernel_chunk_buffer_[0];
+ // Break up time domain filter into chunks and FFT each of these separately.
+ for (size_t partition = 0; partition < new_num_partitions; ++partition) {
+ DCHECK_LE(partition * frames_per_buffer_, kernel.size());
+ const float* chunk_begin_itr =
+ kernel.begin() + partition * frames_per_buffer_;
+ const size_t num_frames_to_copy =
+ std::min<size_t>(frames_per_buffer_, kernel.end() - chunk_begin_itr);
+
+ std::copy_n(chunk_begin_itr, num_frames_to_copy, padded_channel.begin());
+ // This fill only occurs on the very last partition.
+ std::fill(padded_channel.begin() + num_frames_to_copy, padded_channel.end(),
+ 0.0f);
+ fft_manager_->FreqFromTimeDomain(padded_channel,
+ &kernel_freq_domain_buffer_[partition]);
+ }
+
+ if (new_num_partitions != num_partitions_) {
+ const size_t new_filter_size = new_num_partitions * frames_per_buffer_;
+ ResetFreqDomainBuffers(new_filter_size);
+ }
+}
+
+void PartitionedFftFilter::SetFreqDomainKernel(const FreqDomainBuffer& kernel) {
+ DCHECK_LE(kernel.num_channels(), max_num_partitions_);
+ DCHECK_EQ(kernel.num_frames(), fft_size_);
+
+ const size_t new_num_partitions = kernel.num_channels();
+ for (size_t i = 0; i < new_num_partitions; ++i) {
+ kernel_freq_domain_buffer_[i] = kernel[i];
+ }
+ if (new_num_partitions != num_partitions_) {
+ const size_t new_filter_size = new_num_partitions * frames_per_buffer_;
+ ResetFreqDomainBuffers(new_filter_size);
+ }
+}
+
+void PartitionedFftFilter::Filter(const FreqDomainBuffer::Channel& input) {
+
+
+ DCHECK_EQ(input.size(), fft_size_);
+ std::copy_n(input.begin(), fft_size_,
+ freq_domain_buffer_[curr_front_buffer_].begin());
+ buffer_selector_ = !buffer_selector_;
+ freq_domain_accumulator_.Clear();
+ auto* accumulator_channel = &freq_domain_accumulator_[0];
+
+ for (size_t i = 0; i < num_partitions_; ++i) {
+ // Complex vector product in frequency domain with filter kernel.
+ const size_t modulo_index = (curr_front_buffer_ + i) % num_partitions_;
+
+ // Perform inverse scaling along with accumulation of last fft buffer.
+ fft_manager_->FreqDomainConvolution(freq_domain_buffer_[modulo_index],
+ kernel_freq_domain_buffer_[i],
+ accumulator_channel);
+ }
+ // Our modulo based index.
+ curr_front_buffer_ =
+ (curr_front_buffer_ + num_partitions_ - 1) % num_partitions_;
+ // Perform inverse FFT transform of |freq_domain_buffer_| and store the
+ // result back in |filtered_time_domain_buffers_|.
+ fft_manager_->TimeFromFreqDomain(
+ *accumulator_channel, &filtered_time_domain_buffers_[buffer_selector_]);
+}
+
+void PartitionedFftFilter::GetFilteredSignal(AudioBuffer::Channel* output) {
+
+ DCHECK(output);
+ DCHECK_EQ(output->size(), frames_per_buffer_);
+
+ const size_t curr_buffer = buffer_selector_;
+ const size_t prev_buffer = !buffer_selector_;
+
+ // Overlap add.
+ if (frames_per_buffer_ == chunk_size_) {
+ AddPointwise(chunk_size_, &(filtered_time_domain_buffers_[curr_buffer][0]),
+ &filtered_time_domain_buffers_[prev_buffer][chunk_size_],
+ &((*output)[0]));
+ } else {
+ // If we have a non power of two |frames_per_buffer| we will have to perform
+ // the overlap add and then a copy, as buffer lengths are not a multiple of
+ // |chunk_size_|. NOTE: Indexing into |filtered_time_domain_buffers_| for a
+ // non power of two |frames_per_buffer_| means that the |input_b| parameter
+ // of |AddPointwiseOutOfPlace| may not be aligned in memory and thus we will
+ // not be able to use SIMD for the overlap add operation.
+ const auto& first_channel = filtered_time_domain_buffers_[curr_buffer];
+ const auto& second_channel = filtered_time_domain_buffers_[prev_buffer];
+ auto& output_channel = temp_zeropad_buffer_[0];
+ for (size_t i = 0; i < frames_per_buffer_; ++i) {
+ output_channel[i] =
+ first_channel[i] + second_channel[i + frames_per_buffer_];
+ }
+ std::copy_n(temp_zeropad_buffer_[0].begin(), frames_per_buffer_,
+ output->begin());
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter.h
new file mode 100644
index 000000000..f8399922a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter.h
@@ -0,0 +1,167 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_PARTITIONED_FFT_FILTER_H_
+#define RESONANCE_AUDIO_DSP_PARTITIONED_FFT_FILTER_H_
+
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "base/misc_math.h"
+#include "dsp/fft_manager.h"
+
+struct PFFFT_Setup;
+
+namespace vraudio {
+
+// Class performing a FFT-based overlap and add FIR convolution.
+// Given an FFT size N and a filter size M > N/2; the filter is broken in to
+// floor(M/(N/2)) partitions in the time domain. This results in a set of
+// frequency domain "filters" of length (N/2)+1.
+class PartitionedFftFilter {
+ public:
+ // Typedef declares the data type for storing frequency domain buffers. Each
+ // channel stores the kernel for a partition.
+ typedef AudioBuffer FreqDomainBuffer;
+
+ // Constructor preallocates memory based on the |filter_size|. This can be
+ // used for simplicity if the filter size will be constant after creation.
+ //
+ // @param filter_size Length of the time domain filter in samples. This will
+ // be increased such that it becomes a multiple of |chunk_size_|.
+ // @param frames_per_buffer Number of points in each time domain input buffer.
+ // @param fft_manager Pointer to a manager to perform FFT transformations.
+ PartitionedFftFilter(size_t filter_size, size_t frames_per_buffer,
+ FftManager* fft_manager);
+
+ // Constructor preallocates memory based on the |max_filter_size|. The
+ // |fft_size_| will be twice |frames_per_buffer| if this is a power of two and
+ // twice the next larger power of two if it is not.
+ //
+ // @param filter_size Length of the time domain filter in samples. This will
+ // be increased such that it becomes a multiple of |chunk_size_|.
+ // @param frames_per_buffer Number of points in each time domain input buffer.
+ // @param max_filter_size Maximum length that |filter_size| can get.
+ // @param fft_manager Pointer to a manager for all fft related functionality.
+ PartitionedFftFilter(size_t filter_size, size_t frames_per_buffer,
+ size_t max_filter_size, FftManager* fft_manager);
+
+ // Initializes the FIR filter from a time domain kernel.
+ //
+ // @parem kernel Time domain filter to be used for processing.
+ void SetTimeDomainKernel(const AudioBuffer::Channel& kernel);
+
+ // Initializes the FIR filter from a precomputed frequency domain kernel.
+ //
+ // @param kernel Frequency domain filter to be used for processing.
+ void SetFreqDomainKernel(const FreqDomainBuffer& kernel);
+
+ // Replaces a partition indicated by the |partition_index| with
+ // |kernel_chunk|'s frequency domain equivalent.
+ //
+ // @param partition_index Location (partition) of the time domain filter we
+ // wish to replace.
+ // @param kernel_chunk |fft_size_|/2 length chunk of a filter used to
+ // replace the |partition_index|th partition.
+ void ReplacePartition(size_t partition_index,
+ const AudioBuffer::Channel& kernel_chunk);
+
+ // Alters the filter length by adding or removing partitions in the frequency
+ // domain. If |new_filter_size| is not a multiple of |chunk_size_| (i.e.
+ // frames per buffer), then the time domain filter kernel will be zeropadded
+ // to a multiple of |chunk_size_|.
+ //
+ // @param new_filter_size New length of the time domain filter kernel.
+ void SetFilterLength(size_t new_filter_size);
+
+ // Processes a block of frequency domain samples. The size of the input
+ // block must be |fft_size_|.
+ //
+ // @param Frequency domain input buffer.
+ void Filter(const FreqDomainBuffer::Channel& input);
+
+ // Returns block of filtered signal output of size |fft_size_|/2.
+ //
+ // @param output Time domain block filtered with the given kernel.
+ void GetFilteredSignal(AudioBuffer::Channel* output);
+
+ // Resets the filter state.
+ void Clear();
+
+ private:
+ friend class PartitionedFftFilterFrequencyBufferTest;
+
+ // Adjusts the |num_partitions_| and the size of |freq_domain_buffers_| for
+ // use with a new time domain filter kernel greater in length than the
+ // previous kernel.
+ //
+ // @param new_kernel_size Length of the time domain filter kernel.
+ void ResetFreqDomainBuffers(size_t new_kernel_size);
+
+ // Manager for all FFT related functionality (not owned).
+ FftManager* const fft_manager_;
+
+ // Number of points in the |fft_manager_|s FFT.
+ const size_t fft_size_;
+
+ // Size of each partition of the filter in time domain.
+ const size_t chunk_size_;
+
+ // Number of frames in each buffer of input data.
+ const size_t frames_per_buffer_;
+
+ // Maximum filter size in samples.
+ const size_t max_filter_size_;
+
+ // Maximum partition count.
+ const size_t max_num_partitions_;
+
+ // Filter size in samples.
+ size_t filter_size_;
+
+ // Partition Count.
+ size_t num_partitions_;
+
+ // Kernel buffer in frequency domain.
+ FreqDomainBuffer kernel_freq_domain_buffer_;
+
+ // Buffer selector to switch between two filtered signal buffers.
+ size_t buffer_selector_;
+
+ // The freq_domain_buffer we will write new incoming audio into.
+ size_t curr_front_buffer_;
+
+ // Frequency domain buffer used to perform filtering.
+ FreqDomainBuffer freq_domain_buffer_;
+
+ // Two buffers that are consecutively filled with filtered signal output.
+ AudioBuffer filtered_time_domain_buffers_;
+
+ // Accumulator for the outputs from each convolution partition
+ FreqDomainBuffer freq_domain_accumulator_;
+
+ // Temporary time domain buffer to store output when zero padding has been
+ // applied due to non power of two input buffer lengths.
+ AudioBuffer temp_zeropad_buffer_;
+
+ // Temporary time domain buffer to hold time domain kernel chunks during
+ // conversion of a kernel from time to frequency domain.
+ AudioBuffer temp_kernel_chunk_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_PARTITIONED_FFT_FILTER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter_test.cc
new file mode 100644
index 000000000..230ec2544
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/partitioned_fft_filter_test.cc
@@ -0,0 +1,761 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "dsp/partitioned_fft_filter.h"
+
+#include <cmath>
+#include <iostream>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "dsp/fft_manager.h"
+
+namespace vraudio {
+
+namespace {
+
+// Permitted error in the output relative to the expected output. This value is
+// 1e-3 as expected output is rounded for readability.
+const float kFftEpsilon = 1e-3f;
+
+// Length of input buffer for use in LongerShorterKernelTest.
+const size_t kLength = 32;
+
+// Helper function for use in LongerShorterKernelTest. Passes a dirac of length
+// kLength through a filter followed by |zeros_iteration| zero vectors of the
+// same length.
+void ProcessFilterWithImpulseSignal(PartitionedFftFilter* filter,
+ FftManager* fft_manager,
+ size_t zeros_iteration,
+ std::vector<float>* output_signal) {
+ AudioBuffer signal_buffer(kNumMonoChannels, kLength);
+ signal_buffer.Clear();
+ signal_buffer[0][0] = 1.0f;
+ AudioBuffer output_buffer(kNumMonoChannels, kLength);
+
+ // Begin filtering with the original (small) kernel.
+ PartitionedFftFilter::FreqDomainBuffer freq_domain_buffer(kNumMonoChannels,
+ kLength * 2);
+ fft_manager->FreqFromTimeDomain(signal_buffer[0], &freq_domain_buffer[0]);
+ filter->Filter(freq_domain_buffer[0]);
+ filter->GetFilteredSignal(&output_buffer[0]);
+ output_signal->insert(output_signal->end(), output_buffer[0].begin(),
+ output_buffer[0].end());
+ // Filter zeros to flush out internal buffers.
+ std::fill(signal_buffer[0].begin(), signal_buffer[0].end(), 0.0f);
+ for (size_t i = 0; i < zeros_iteration; ++i) {
+ fft_manager->FreqFromTimeDomain(signal_buffer[0], &freq_domain_buffer[0]);
+ filter->Filter(freq_domain_buffer[0]);
+ filter->GetFilteredSignal(&output_buffer[0]);
+ output_signal->insert(output_signal->end(), output_buffer[0].begin(),
+ output_buffer[0].end());
+ }
+}
+
+// Tests that convolution will work correctly when the input buffer length is
+// not a power of two.
+TEST(PartitionedFftFilterTest, NonPow2Test) {
+ // Non power of two input buffer length.
+ const size_t kMinNonPowTwo = 13;
+ const size_t kMaxNonPowTwo = 41;
+ for (size_t buffer_length = kMinNonPowTwo; buffer_length <= kMaxNonPowTwo;
+ buffer_length += 2) {
+ for (size_t filter_length = kLength; filter_length <= 3 * kLength;
+ filter_length += kLength) {
+ // Use a filter length that is a power of two.
+ AudioBuffer kernel_buffer(kNumMonoChannels, filter_length);
+ // Place to collect all of the output.
+ std::vector<float> output_signal;
+ // First set the kernel to a linear ramp.
+ for (size_t i = 0; i < filter_length; ++i) {
+ kernel_buffer[0][i] = static_cast<float>(i) / 4.0f;
+ }
+ FftManager fft_manager(buffer_length);
+ PartitionedFftFilter filter(filter_length, buffer_length, &fft_manager);
+ filter.SetTimeDomainKernel(kernel_buffer[0]);
+
+ // Kronecker delta signal.
+ AudioBuffer signal_buffer(kNumMonoChannels, buffer_length);
+ signal_buffer.Clear();
+ signal_buffer[0][0] = 1.0f;
+ AudioBuffer output_buffer(kNumMonoChannels, buffer_length);
+ // Create a freq domain buffer which should be fft_size
+ // (i.e. NextPowTwo(buffer_length) * 2).
+ PartitionedFftFilter::FreqDomainBuffer freq_domain_buffer(
+ kNumMonoChannels, NextPowTwo(buffer_length) * 2);
+ freq_domain_buffer.Clear();
+ fft_manager.FreqFromTimeDomain(signal_buffer[0], &freq_domain_buffer[0]);
+ // Perform convolution.
+ filter.Filter(freq_domain_buffer[0]);
+ filter.GetFilteredSignal(&output_buffer[0]);
+ output_signal.insert(output_signal.end(), output_buffer[0].begin(),
+ output_buffer[0].end());
+ while (output_signal.size() < kernel_buffer.num_frames()) {
+ // Flush with zeros.
+ freq_domain_buffer.Clear();
+ output_buffer.Clear();
+ filter.Filter(freq_domain_buffer[0]);
+ filter.GetFilteredSignal(&output_buffer[0]);
+ output_signal.insert(output_signal.end(), output_buffer[0].begin(),
+ output_buffer[0].end());
+ }
+ // Ensure the output is identical to the input buffer. (large epsilon
+ // needed due to large values in filter).
+ for (size_t i = 0; i < kernel_buffer.num_frames(); ++i) {
+ EXPECT_NEAR(kernel_buffer[0][i], output_signal[i],
+ kEpsilonFloat * 4.0f);
+ }
+ }
+ }
+}
+
+// Tests that the outputs from the convolution are correct based on a
+// precomputed vector from MATLAB.
+TEST(PartitionedFftFilterTest, CorrectNonPowTwoOutputTest) {
+ const size_t kBufferSize = 15;
+
+ // Create an arbirary vector of size 16 for filter and 15 for input signal.
+ const std::vector<float> kernel = {1.0f, 3.0f, 0.0f, 2.0f, 5.0f, 1.0f,
+ 3.0f, 2.0f, 0.0f, 4.0f, 1.0f, 3.0f,
+ 0.0f, 2.0f, 1.0f, 2.0f};
+ const std::vector<float> signal = {2.0f, 3.0f, 3.0f, 4.0f, 0.0f,
+ 0.0f, 2.0f, 1.0f, 2.0f, 1.0f,
+ 3.0f, 2.0f, 4.0f, 0.0f, 2.0f};
+ // Ideal output vector verified with MATLAB.
+ const std::vector<float> ideal_output = {
+ 2.0f, 9.0f, 12.0f, 17.0f, 28.0f, 23.0f, 34.0f, 43.0f, 24.0f,
+ 37.0f, 40.0f, 43.0f, 57.0f, 49.0f, 50.0f, 57.0f, 65.0f, 57.0f,
+ 60.0f, 61.0f, 47.0f, 74.0f, 59.0f, 55.0f, 48.0f, 62.0f, 51.0f,
+ 69.0f, 51.0f, 54.0f, 55.0f, 56.0f, 45.0f, 43.0f, 33.0f, 24.0f,
+ 40.0f, 16.0f, 31.0f, 11.0f, 22.0f, 8.0f, 12.0f, 2.0f, 4.0f};
+
+ AudioBuffer kernel_buffer(kNumMonoChannels, kernel.size());
+ kernel_buffer[0] = kernel;
+
+ AudioBuffer signal_buffer(kNumMonoChannels, signal.size());
+ signal_buffer[0] = signal;
+
+ AudioBuffer output_buffer(kNumMonoChannels, signal.size());
+
+ std::vector<float> output_signal;
+ output_signal.reserve(kernel.size() + signal.size() * 3);
+
+ FftManager fft_manager(kBufferSize);
+ PartitionedFftFilter filter(kernel.size(), kBufferSize, &fft_manager);
+ filter.SetTimeDomainKernel(kernel_buffer[0]);
+
+ PartitionedFftFilter::FreqDomainBuffer freq_domain_buffer(
+ 1, NextPowTwo(kBufferSize) * 2);
+ fft_manager.FreqFromTimeDomain(signal_buffer[0], &freq_domain_buffer[0]);
+ filter.Filter(freq_domain_buffer[0]);
+ filter.GetFilteredSignal(&output_buffer[0]);
+ output_signal.insert(output_signal.end(), output_buffer[0].begin(),
+ output_buffer[0].end());
+
+ // Filter again with the same input.
+ filter.Filter(freq_domain_buffer[0]);
+ filter.GetFilteredSignal(&output_buffer[0]);
+ output_signal.insert(output_signal.end(), output_buffer[0].begin(),
+ output_buffer[0].end());
+
+ // Filter zeros to flush out internal buffers.
+ signal_buffer.Clear();
+ fft_manager.FreqFromTimeDomain(signal_buffer[0], &freq_domain_buffer[0]);
+ filter.Filter(freq_domain_buffer[0]);
+ filter.GetFilteredSignal(&output_buffer[0]);
+ output_signal.insert(output_signal.end(), output_buffer[0].begin(),
+ output_buffer[0].end());
+
+ for (size_t sample = 0; sample < ideal_output.size(); ++sample) {
+ EXPECT_NEAR(output_signal[sample], ideal_output[sample], kFftEpsilon);
+ }
+}
+
+// Tests that we can switch to a time domain filter kernel of greater
+// length than the original kernal provided at instantiation. It then tests that
+// we can switch to a time domain filter kernel of lesser length than the
+// original kernel.
+TEST(PartitionedFftFilterTest, LongerShorterTimeDomainKernelTest) {
+ AudioBuffer small_kernel_buffer(kNumMonoChannels, kLength);
+ AudioBuffer big_kernel_buffer(kNumMonoChannels, kLength * 2);
+
+ // Place to collect all of the output.
+ std::vector<float> total_output_signal;
+
+ // First set the kernels to linear ramps of differing lengths.
+ for (size_t i = 0; i < kLength * 2; ++i) {
+ if (i < kLength) {
+ small_kernel_buffer[0][i] = static_cast<float>(i) / 4.0f;
+ }
+ big_kernel_buffer[0][i] = static_cast<float>(i) / 4.0f;
+ }
+
+ FftManager fft_manager(kLength);
+ PartitionedFftFilter filter(small_kernel_buffer.num_frames(), kLength,
+ big_kernel_buffer.num_frames(), &fft_manager);
+
+ filter.SetTimeDomainKernel(small_kernel_buffer[0]);
+ ProcessFilterWithImpulseSignal(&filter, &fft_manager, 2,
+ &total_output_signal);
+
+ filter.SetTimeDomainKernel(big_kernel_buffer[0]);
+ ProcessFilterWithImpulseSignal(&filter, &fft_manager, 3,
+ &total_output_signal);
+
+ filter.SetTimeDomainKernel(small_kernel_buffer[0]);
+ ProcessFilterWithImpulseSignal(&filter, &fft_manager, 2,
+ &total_output_signal);
+
+ // Test to see if output from both kernels is present kLength * 2 zeros in
+ // between.
+ for (size_t i = 0; i < kLength; ++i) {
+ EXPECT_NEAR(static_cast<float>(i) / 4.0f, total_output_signal[i],
+ kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + kLength], kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + 2 * kLength], kFftEpsilon);
+ EXPECT_NEAR(static_cast<float>(i) / 4.0f,
+ total_output_signal[i + 3 * kLength], kFftEpsilon);
+ EXPECT_NEAR(static_cast<float>(i + kLength) / 4.0f,
+ total_output_signal[i + 4 * kLength], kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + 5 * kLength], kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + 6 * kLength], kFftEpsilon);
+ EXPECT_NEAR(static_cast<float>(i) / 4.0f,
+ total_output_signal[i + 7 * kLength], kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + 8 * kLength], kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + 9 * kLength], kFftEpsilon);
+ }
+}
+
+// Tests that the outputs from the same convolution performed with different FFT
+// sizes will all return equal results, including when the FFT size is equal to
+// the kernel size.
+TEST(PartitionedFftFilterTest, PartitionSizeInvarianceTest) {
+ const std::vector<size_t> kFftSizes = {32, 64, 128};
+
+ // Create an arbirary vector of size 128 for both filter and input signal.
+ const size_t max_fft_size = kFftSizes[kFftSizes.size() - 1];
+ AudioBuffer kernel_buffer(kNumMonoChannels, max_fft_size);
+ AudioBuffer signal_buffer(kNumMonoChannels, max_fft_size);
+ for (size_t i = 0; i < max_fft_size; ++i) {
+ kernel_buffer[0][i] = static_cast<float>(static_cast<int>(i) % 13 - 7);
+ signal_buffer[0][i] = static_cast<float>(static_cast<int>(i) % 17 - 9);
+ }
+
+ std::vector<std::vector<float>> output_signal(
+ kFftSizes.size(), std::vector<float>(max_fft_size * 2));
+
+ // Iterate over 3 fft sizes.
+ for (size_t fft_idx = 0; fft_idx < kFftSizes.size(); ++fft_idx) {
+ const size_t chunk_size = kFftSizes[fft_idx] / 2;
+ FftManager fft_manager(chunk_size);
+ PartitionedFftFilter filter(max_fft_size, chunk_size, &fft_manager);
+ filter.SetTimeDomainKernel(kernel_buffer[0]);
+
+ AudioBuffer input_chunk(kNumMonoChannels, chunk_size);
+ AudioBuffer output_chunk(kNumMonoChannels, chunk_size);
+ PartitionedFftFilter::FreqDomainBuffer freq_domain_buffer(
+ 1, kFftSizes[fft_idx]);
+
+ // Break the input signal into chunks of fft size / 2.
+ for (size_t chunk = 0; chunk < (max_fft_size / chunk_size); ++chunk) {
+ AudioBuffer signal_block(kNumMonoChannels, chunk_size);
+ std::copy_n(signal_buffer[0].begin() + (chunk * chunk_size), chunk_size,
+ signal_block[0].begin());
+
+ fft_manager.FreqFromTimeDomain(signal_block[0], &freq_domain_buffer[0]);
+ filter.Filter(freq_domain_buffer[0]);
+ filter.GetFilteredSignal(&output_chunk[0]);
+ output_signal[fft_idx].insert(output_signal[fft_idx].end(),
+ output_chunk[0].begin(),
+ output_chunk[0].end());
+ }
+ }
+ // Now test the outputs are pretty much equal to one another (to the first).
+ for (size_t i = 1; i < kFftSizes.size(); ++i) {
+ for (size_t sample = 0; sample < output_signal[0].size(); ++sample) {
+ EXPECT_NEAR(output_signal[0][sample], output_signal[i][sample],
+ kFftEpsilon);
+ }
+ }
+}
+
+// Tests that the outputs from the convolution are correct based on a
+// precomputed vector from MATLAB.
+TEST(PartitionedFftFilterTest, CorrectOutputTest) {
+ const size_t kBufferSize = 32;
+
+ // Create an arbirary vector of size 32 for both filter and input signal.
+ const std::vector<float> kernel = {
+ 1.0f, 3.0f, 0.0f, 2.0f, 5.0f, 1.0f, 3.0f, 2.0f, 0.0f, 4.0f, 1.0f,
+ 3.0f, 0.0f, 2.0f, 1.0f, 2.0f, 2.0f, 1.0f, 0.0f, 3.0f, 5.0f, 2.0f,
+ 3.0f, 0.0f, 1.0f, 4.0f, 2.0f, 0.0f, 1.0f, 0.0f, 2.0f, 1.0f};
+ const std::vector<float> signal = {
+ 2.0f, 1.0f, 3.0f, 3.0f, 2.0f, 4.0f, 2.0f, 1.0f, 3.0f, 4.0f, 5.0f,
+ 3.0f, 2.0f, 2.0f, 5.0f, 4.0f, 5.0f, 3.0f, 3.0f, 4.0f, 0.0f, 0.0f,
+ 2.0f, 1.0f, 2.0f, 1.0f, 3.0f, 2.0f, 4.0f, 0.0f, 2.0f, 1.0f};
+
+ AudioBuffer kernel_buffer(kNumMonoChannels, kernel.size());
+ kernel_buffer[0] = kernel;
+
+ AudioBuffer signal_buffer(kNumMonoChannels, signal.size());
+ signal_buffer[0] = signal;
+
+ AudioBuffer output_buffer(kNumMonoChannels, kernel.size());
+
+ std::vector<float> output_signal;
+ output_signal.reserve(kernel.size() + signal.size());
+
+ FftManager fft_manager(kBufferSize);
+ PartitionedFftFilter filter(kernel.size(), kBufferSize, &fft_manager);
+ filter.SetTimeDomainKernel(kernel_buffer[0]);
+
+ PartitionedFftFilter::FreqDomainBuffer freq_domain_buffer(kNumMonoChannels,
+ kBufferSize * 2);
+ fft_manager.FreqFromTimeDomain(signal_buffer[0], &freq_domain_buffer[0]);
+ filter.Filter(freq_domain_buffer[0]);
+ filter.GetFilteredSignal(&output_buffer[0]);
+ output_signal.insert(output_signal.end(), output_buffer[0].begin(),
+ output_buffer[0].end());
+
+ // Filter zeros to flush out internal buffers.
+ signal_buffer.Clear();
+ fft_manager.FreqFromTimeDomain(signal_buffer[0], &freq_domain_buffer[0]);
+ filter.Filter(freq_domain_buffer[0]);
+ filter.GetFilteredSignal(&output_buffer[0]);
+ output_signal.insert(output_signal.end(), output_buffer[0].begin(),
+ output_buffer[0].end());
+
+ // Ideal output vector verified with MATLAB.
+ const std::vector<float> kIdeal = {
+ 2.0f, 7.0f, 6.0f, 16.0f, 23.0f, 23.0f, 42.0f, 36.0f, 38.0f,
+ 62.0f, 51.0f, 66.0f, 67.0f, 72.0f, 88.0f, 90.0f, 90.0f, 95.0f,
+ 104.0f, 118.0f, 127.0f, 113.0f, 123.0f, 131.0f, 116.0f, 144.0f, 119.0f,
+ 126.0f, 138.0f, 138.0f, 153.0f, 142.0f, 130.0f, 125.0f, 137.0f, 142.0f,
+ 121.0f, 113.0f, 99.0f, 112.0f, 84.0f, 89.0f, 68.0f, 66.0f, 74.0f,
+ 54.0f, 54.0f, 59.0f, 53.0f, 42.0f, 42.0f, 26.0f, 32.0f, 28.0f,
+ 18.0f, 15.0f, 19.0f, 9.0f, 12.0f, 5.0f, 4.0f, 4.0f, 1.0f};
+ for (size_t sample = 0; sample < kIdeal.size(); ++sample) {
+ EXPECT_NEAR(output_signal[sample], kIdeal[sample], kFftEpsilon);
+ }
+}
+
+// Tests that the outputs from the convolution are equal to zero when the inputs
+// are all zero.
+TEST(PartitionedFftFilterTest, ZeroInputZeroOutputTest) {
+ const size_t kChunkSize = 16;
+
+ // Create an arbirary vector of size 16 for filter.
+ const std::vector<float> kernel = {1.0f, 3.0f, 0.0f, 2.0f, 5.0f, 1.0f,
+ 3.0f, 2.0f, 0.0f, 4.0f, 1.0f, 3.0f,
+ 0.0f, 2.0f, 1.0f, 2.0f};
+
+ AudioBuffer kernel_buffer(kNumMonoChannels, kernel.size());
+ kernel_buffer[0] = kernel;
+
+ std::vector<float> output_signal;
+ output_signal.reserve(kernel.size() * 2);
+
+ FftManager fft_manager(kChunkSize);
+ PartitionedFftFilter filter(kernel_buffer[0].size(), kChunkSize,
+ &fft_manager);
+ filter.SetTimeDomainKernel(kernel_buffer[0]);
+
+ AudioBuffer output_chunk(kNumMonoChannels, kChunkSize);
+
+ // Filter zeros to flush out internal buffers.
+ AudioBuffer zero_signal(kNumMonoChannels, kChunkSize);
+ zero_signal.Clear();
+
+ PartitionedFftFilter::FreqDomainBuffer freq_domain_buffer(kNumMonoChannels,
+ kChunkSize * 2);
+ for (size_t j = 0; j < 2 * kernel.size() / kChunkSize; ++j) {
+ fft_manager.FreqFromTimeDomain(zero_signal[0], &freq_domain_buffer[0]);
+ filter.Filter(freq_domain_buffer[0]);
+ filter.GetFilteredSignal(&output_chunk[0]);
+ output_signal.insert(output_signal.end(), output_chunk[0].begin(),
+ output_chunk[0].end());
+ }
+
+ // Check that all output samples are practically 0.0.
+ for (size_t sample = 0; sample < output_signal.size(); ++sample) {
+ EXPECT_EQ(output_signal[sample], 0.0f);
+ }
+}
+
+// This test uses a simple shifted dirac impulse as kernel and checks the
+// resulting signal delay.
+TEST(PartitionedFftFilterTest, DiracImpulseTest) {
+ const size_t kFilterSize = 32;
+ const size_t kNumBlocks = 4;
+ const size_t kSignalSize = kFilterSize * kNumBlocks;
+
+ // Generate a saw tooth signal.
+ AudioBuffer test_signal(kNumMonoChannels, kSignalSize);
+ for (size_t i = 0; i < kSignalSize; ++i) {
+ test_signal[0][i] = static_cast<float>(i % 5);
+ }
+
+ FftManager fft_manager(kFilterSize);
+ PartitionedFftFilter fft_filter(kFilterSize, kFilterSize, &fft_manager);
+
+ AudioBuffer kernel(kNumMonoChannels, kFilterSize);
+ // Construct dirac impulse response. This kernel should result in a delay of
+ // length "|kFilterSize| / 2".
+ kernel.Clear();
+ kernel[0][kFilterSize / 2] = 1.0f;
+ fft_filter.SetTimeDomainKernel(kernel[0]);
+
+ std::vector<float> filtered_signal;
+ filtered_signal.reserve(kSignalSize);
+
+ AudioBuffer filtered_block(kNumMonoChannels, kFilterSize);
+ PartitionedFftFilter::FreqDomainBuffer freq_domain_buffer(kNumMonoChannels,
+ kFilterSize * 2);
+
+ for (size_t b = 0; b < kNumBlocks; ++b) {
+ AudioBuffer signal_block(kNumMonoChannels, kFilterSize);
+ std::copy_n(test_signal[0].begin() + b * kFilterSize, kFilterSize,
+ signal_block[0].begin());
+
+ fft_manager.FreqFromTimeDomain(signal_block[0], &freq_domain_buffer[0]);
+ fft_filter.Filter(freq_domain_buffer[0]);
+ fft_filter.GetFilteredSignal(&filtered_block[0]);
+ filtered_signal.insert(filtered_signal.end(), filtered_block[0].begin(),
+ filtered_block[0].end());
+ }
+
+ for (size_t i = 0; i < kFilterSize / 2; ++i) {
+ // First "filter_size / 2" samples should be zero padded due to the applied
+ // delay.
+ EXPECT_NEAR(filtered_signal[i], 0.0f, 1e-5f);
+ }
+ for (size_t i = kFilterSize / 2; i < kSignalSize; ++i) {
+ // Test if signal is delayed by exactly |kFilterSize| / 2 samples.
+ EXPECT_NEAR(filtered_signal[i], test_signal[0][i - kFilterSize / 2], 1e-5f);
+ }
+}
+
+} // namespace
+
+class PartitionedFftFilterFrequencyBufferTest : public ::testing::Test {
+ protected:
+ PartitionedFftFilterFrequencyBufferTest() {}
+ // Virtual methods from ::testing::Test
+ ~PartitionedFftFilterFrequencyBufferTest() override {}
+ void SetUp() override {}
+ void TearDown() override {}
+
+ void SetFreqDomainBuffer(PartitionedFftFilter* filter,
+ FftManager* fft_manager) {
+ std::vector<std::vector<float>> values_vectors(
+ filter->num_partitions_,
+ std::vector<float>(fft_manager->GetFftSize(), 0.0f));
+ for (size_t i = 0; i < filter->num_partitions_; ++i) {
+ values_vectors[i][0] = static_cast<float>(i + 1);
+ filter->freq_domain_buffer_[i] = values_vectors[i];
+ }
+ }
+
+ void SetFreqDomainKernel(PartitionedFftFilter* filter) {
+ // Put a Kronecker delta in the first partition, a kronecker delta times 2
+ // in the second, a kronecker delta times 3 in the third, etc...
+ AudioBuffer kernel(kNumMonoChannels, filter->filter_size_);
+ for (size_t i = 0; i < filter->num_partitions_; ++i) {
+ for (size_t sample = 0; sample < filter->chunk_size_; ++sample) {
+ kernel[0][i * filter->chunk_size_ + sample] = static_cast<float>(i + 1);
+ }
+ }
+ filter->SetTimeDomainKernel(kernel[0]);
+ }
+
+ void TestFrequencyBufferReset(size_t initial_size, size_t bigger_size,
+ size_t smaller_size,
+ PartitionedFftFilter* filter,
+ FftManager* fft_manager) {
+ const size_t initial_num_partitions = 2 * initial_size;
+ const size_t bigger_num_partitions = 2 * bigger_size;
+ const size_t smaller_num_partitions = 2 * smaller_size;
+ // Set the |freq_domain_buffer_| inside |filter| such that it has known
+ // values.
+ SetFreqDomainBuffer(filter, fft_manager);
+ AudioBuffer initial_freq_domain_buffer;
+ initial_freq_domain_buffer = filter->freq_domain_buffer_;
+
+ // Set the current front buffer to something other than zero and less than
+ // the number of partitions. If |num_partitions_| is 1 it is set to 0.
+ filter->curr_front_buffer_ = filter->num_partitions_ / 2;
+
+ // Reset the |freq_domain_buffers_| for a new bigger kernel size.
+ filter->ResetFreqDomainBuffers(bigger_size * fft_manager->GetFftSize());
+ AudioBuffer bigger_freq_domain_buffer;
+ bigger_freq_domain_buffer = filter->freq_domain_buffer_;
+ // Verify that the input index has been reset.
+ EXPECT_EQ(filter->curr_front_buffer_, 0U);
+
+ // Set the current front buffer to something other than zero and less than
+ // the number of partitions. If |num_partitions_| is 1 it is set to 0.
+ filter->curr_front_buffer_ = filter->num_partitions_ / 2;
+
+ // Reset the |freq_domain_buffers_| for a new smaller kernel size.
+ filter->ResetFreqDomainBuffers(smaller_size * fft_manager->GetFftSize());
+ AudioBuffer smaller_freq_domain_buffer;
+ smaller_freq_domain_buffer = filter->freq_domain_buffer_;
+ // Verify that the input index has been reset.
+ EXPECT_EQ(filter->curr_front_buffer_, 0U);
+
+ // Expect the following to have happened:
+ // Initially there are 16 partitions with the first element in each channel
+ // of the |freq_domain_buffers_| in |filter| being 1, 2, ..., 16.
+ for (size_t i = 0; i < initial_num_partitions; ++i) {
+ EXPECT_EQ(initial_freq_domain_buffer[i][0], static_cast<float>(i + 1));
+ }
+
+ // |curr_front_buffer_| is set to 8. After a reset with a larger kernel we
+ // expect all of the buffers to have been copied into the new
+ // |freq_domain_buffers_| starting from |curr_front_buffer_| and wrapping
+ // round with the remaining channels set to zero.
+ for (size_t i = 0; i < initial_num_partitions; ++i) {
+ EXPECT_EQ(bigger_freq_domain_buffer[i][0],
+ initial_freq_domain_buffer[(initial_size + i) %
+ initial_num_partitions][0]);
+ }
+ for (size_t i = initial_num_partitions; i < bigger_num_partitions; ++i) {
+ EXPECT_EQ(bigger_freq_domain_buffer[i][0], 0.0f);
+ }
+
+ // |curr_front_buffer_| is then set to 5. After a reset with a smaller
+ // kernel ammounting to 10 partitions we expect just the first 10 buffers to
+ // have been copied into the new |freq_domain_buffers_| starting from
+ // |curr_front_buffer_| and wrapping round.
+ for (size_t i = 0; i < smaller_num_partitions; ++i) {
+ EXPECT_EQ(smaller_freq_domain_buffer[i][0],
+ bigger_freq_domain_buffer[(bigger_size + i) %
+ bigger_num_partitions][0]);
+ }
+ }
+
+ void TestLongerShorterFrequencyDomainKernel(size_t buffer_size) {
+ AudioBuffer small_kernel_buffer(kNumMonoChannels, buffer_size);
+ AudioBuffer big_kernel_buffer(kNumMonoChannels, 2 * buffer_size);
+
+ // Place to collect all of the output.
+ std::vector<float> total_output_signal;
+
+ // First set the kernels to linear ramps of differing lengths.
+ for (size_t i = 0; i < 2 * buffer_size; ++i) {
+ if (i < buffer_size) {
+ small_kernel_buffer[0][i] = static_cast<float>(i) / 4.0f;
+ }
+ big_kernel_buffer[0][i] = static_cast<float>(i) / 4.0f;
+ }
+
+ FftManager fft_manager(buffer_size);
+ PartitionedFftFilter filter(buffer_size, buffer_size, 2 * buffer_size,
+ &fft_manager);
+
+ // Generate the small and large frequency domain buffers.
+ filter.SetTimeDomainKernel(small_kernel_buffer[0]);
+ const size_t small_num_partitions = filter.num_partitions_;
+ PartitionedFftFilter::FreqDomainBuffer small_freq_domain_kernel =
+ PartitionedFftFilter::FreqDomainBuffer(small_num_partitions,
+ fft_manager.GetFftSize());
+ for (size_t i = 0; i < small_num_partitions; ++i) {
+ small_freq_domain_kernel[i] = filter.kernel_freq_domain_buffer_[i];
+ }
+
+ filter.SetTimeDomainKernel(big_kernel_buffer[0]);
+ const size_t big_num_partitions = filter.num_partitions_;
+ PartitionedFftFilter::FreqDomainBuffer big_freq_domain_kernel =
+ PartitionedFftFilter::FreqDomainBuffer(big_num_partitions,
+ fft_manager.GetFftSize());
+ for (size_t i = 0; i < big_num_partitions; ++i) {
+ big_freq_domain_kernel[i] = filter.kernel_freq_domain_buffer_[i];
+ }
+
+ filter.SetFreqDomainKernel(small_freq_domain_kernel);
+ ProcessFilterWithImpulseSignal(&filter, &fft_manager, 2,
+ &total_output_signal);
+
+ filter.SetFreqDomainKernel(big_freq_domain_kernel);
+ ProcessFilterWithImpulseSignal(&filter, &fft_manager, 3,
+ &total_output_signal);
+
+ filter.SetFreqDomainKernel(small_freq_domain_kernel);
+ ProcessFilterWithImpulseSignal(&filter, &fft_manager, 2,
+ &total_output_signal);
+
+ // Test to see if output from both kernels is present |big_size| zeros in
+ // between.
+ for (size_t i = 0; i < buffer_size; ++i) {
+ EXPECT_NEAR(static_cast<float>(i) / 4.0f, total_output_signal[i],
+ kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + buffer_size], kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + 2 * buffer_size], kFftEpsilon);
+ EXPECT_NEAR(static_cast<float>(i) / 4.0f,
+ total_output_signal[i + 3 * buffer_size], kFftEpsilon);
+ EXPECT_NEAR(static_cast<float>(i + buffer_size) / 4.0f,
+ total_output_signal[i + 4 * buffer_size], kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + 5 * buffer_size], kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + 6 * buffer_size], kFftEpsilon);
+ EXPECT_NEAR(static_cast<float>(i) / 4.0f,
+ total_output_signal[i + 7 * buffer_size], kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + 8 * buffer_size], kFftEpsilon);
+ EXPECT_NEAR(0.0f, total_output_signal[i + 9 * buffer_size], kFftEpsilon);
+ }
+ }
+
+ void TestPartitionReplacement(PartitionedFftFilter* filter,
+ FftManager* fft_manager) {
+ // Fill the first partition with a kronecker delta in the first partition, a
+ // kronecker delta times 2 in the second, a kronecker delta times 3 in the
+ // third, etc...
+ SetFreqDomainKernel(filter);
+ // Get a copy of the kernel.
+ AudioBuffer initial_kernel;
+ initial_kernel = filter->kernel_freq_domain_buffer_;
+
+ // Create a freq domain kernel chunk with the same values as the final
+ // partition.
+ AudioBuffer kernel_chunk(kNumMonoChannels, filter->chunk_size_);
+ kernel_chunk.Clear();
+ AudioBuffer::Channel& kernel_chunk_channel = kernel_chunk[0];
+ for (size_t sample = 0; sample < filter->chunk_size_; ++sample) {
+ kernel_chunk_channel[sample] =
+ static_cast<float>(filter->num_partitions_);
+ }
+ // The partition we will replace.
+ const size_t kReplacePartitionIndex = 2;
+ // Replace a partition with a new time domain kernel chunk (all zeros).
+ filter->ReplacePartition(kReplacePartitionIndex, kernel_chunk_channel);
+
+ // Get a copy of the kernel after replacing the 3rd freq domain partition.
+ AudioBuffer replaced_kernel;
+ replaced_kernel = filter->kernel_freq_domain_buffer_;
+
+ for (size_t i = 0; i < filter->num_partitions_; ++i) {
+ for (size_t sample = 0; sample < fft_manager->GetFftSize(); ++sample) {
+ // Expect that all of the other partitions are unchanged.
+ if (i == kReplacePartitionIndex) {
+ // Check if the chosen partition has been altered.
+ EXPECT_EQ(initial_kernel[filter->num_partitions_ - 1][sample],
+ replaced_kernel[i][sample]);
+ } else {
+ // Check if all of the other partitions are unchanged.
+ EXPECT_EQ(initial_kernel[i][sample], replaced_kernel[i][sample]);
+ }
+ }
+ }
+ }
+
+ void TestFilterLengthSetter(PartitionedFftFilter* filter,
+ FftManager* fft_manager) {
+ // Set the |freq_domain_buffer_| inside |filter| such that it has known
+ // values (In the time domain, all value 1, then 2 etc.. per partition).
+ SetFreqDomainKernel(filter);
+
+ // Get a copy of the kernel and number of partitions before we set the
+ // filter length.
+ AudioBuffer initial_kernel;
+ initial_kernel = filter->kernel_freq_domain_buffer_;
+ const size_t initial_num_partitions = filter->num_partitions_;
+
+ filter->SetFilterLength(filter->filter_size_ / 2);
+
+ // Get a copy after we half the filter length.
+ AudioBuffer half_kernel;
+ half_kernel = filter->kernel_freq_domain_buffer_;
+ const size_t half_num_partitions = filter->num_partitions_;
+ EXPECT_EQ(initial_num_partitions, 2 * half_num_partitions);
+
+ filter->SetFilterLength(filter->filter_size_ * 2);
+
+ // Get a copy after we re-double the filter length.
+ AudioBuffer redouble_kernel;
+ redouble_kernel = filter->kernel_freq_domain_buffer_;
+ EXPECT_EQ(initial_num_partitions, filter->num_partitions_);
+
+ for (size_t i = 0; i < half_num_partitions; ++i) {
+ for (size_t sample = 0; sample < fft_manager->GetFftSize(); ++sample) {
+ // Check that the first two partitions in all 3 cases are the same.
+ EXPECT_EQ(initial_kernel[i][sample], half_kernel[i][sample]);
+ EXPECT_EQ(initial_kernel[i][sample], redouble_kernel[i][sample]);
+ // Check that the final two partitions, after resizing the filters
+ // frequency domain buffers, contain only zeros.
+ EXPECT_EQ(redouble_kernel[i + half_num_partitions][sample], 0.0f);
+ }
+ }
+ }
+};
+
+// Tests whether the reordering of the channels of |freq_domain_buffers_| is as
+// expected after calling |ResetFreqDomainBuffers| with both longer and shorter
+// filters.
+TEST_F(PartitionedFftFilterFrequencyBufferTest, FrequencyBufferResetTest) {
+ const size_t kBufferSize = 32;
+ const size_t kInitialFilterSizeFactor = 8;
+ const size_t kBiggerFilterSizeFactor = 10;
+ const size_t kSmallerFilterSizeFactor = 5;
+ // Initially there will be 16 partitions, then 20, then 10.
+ FftManager fft_manager(kBufferSize);
+ PartitionedFftFilter filter(
+ kInitialFilterSizeFactor * kBufferSize * 2, kBufferSize,
+ kBiggerFilterSizeFactor * kBufferSize * 2, &fft_manager);
+ TestFrequencyBufferReset(kInitialFilterSizeFactor, kBiggerFilterSizeFactor,
+ kSmallerFilterSizeFactor, &filter, &fft_manager);
+}
+
+// Tests that we can switch to a frequency domain filter kernel with a greater
+// number of partitions than the original kernel provided at instantiation.
+// Ensures that we can switch to a frequency domain filter kernel with less
+// partitions than the original kernel.
+TEST_F(PartitionedFftFilterFrequencyBufferTest,
+ LongerShorterFrequencyDomainKernelTest) {
+ TestLongerShorterFrequencyDomainKernel(kLength);
+}
+
+// Tests whether replacing an individual partition works correctly.
+TEST_F(PartitionedFftFilterFrequencyBufferTest, ReplacePartitionTest) {
+ const size_t kBufferSize = 32;
+ const size_t kFilterSizeFactor = 5;
+ // A filter with 5 partitions.
+ FftManager fft_manager(kBufferSize);
+ PartitionedFftFilter filter(kFilterSizeFactor * kBufferSize * 2, kBufferSize,
+ &fft_manager);
+ TestPartitionReplacement(&filter, &fft_manager);
+}
+
+// Tests whether setting the length of the filter kernel, and thus the number
+// of partitions gives the expected results.
+TEST_F(PartitionedFftFilterFrequencyBufferTest, SetFilterLengthTest) {
+ const size_t kBufferSize = 32;
+ const size_t kFilterSizeFactor = 5;
+ // A filter with 5 partitions.
+ FftManager fft_manager(kBufferSize);
+ PartitionedFftFilter filter(kFilterSizeFactor * kBufferSize * 2, kBufferSize,
+ kFilterSizeFactor * kBufferSize * 4,
+ &fft_manager);
+ TestFilterLengthSetter(&filter, &fft_manager);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/reflection.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/reflection.h
new file mode 100644
index 000000000..4b134f6f2
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/reflection.h
@@ -0,0 +1,34 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_REFLECTION_H_
+#define RESONANCE_AUDIO_DSP_REFLECTION_H_
+
+namespace vraudio {
+
+// Describes a room reflection that contains information on its time of arrival
+// and magnitude.
+struct Reflection {
+ // Time of arrival of the reflection in seconds.
+ float delay_time_seconds = 0.0f;
+
+ // Magnitude of the reflection.
+ float magnitude = 0.0f;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_REFLECTION_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor.cc
new file mode 100644
index 000000000..9a9174cdc
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor.cc
@@ -0,0 +1,177 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/reflections_processor.h"
+
+#include <algorithm>
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "dsp/filter_coefficient_generators.h"
+#include "dsp/gain.h"
+#include "dsp/shoe_box_room.h"
+
+namespace vraudio {
+
+namespace {
+
+// Maximum allowed delay time for a reflection. Above 2s, the effective output
+// level of a reflection will fall below -60dB and thus perceived dynamic
+// changes should be negligible.
+const size_t kMaxDelayTimeSeconds = 2;
+
+// Returns the maximum delay time in the given set of reflections.
+float FindMaxReflectionDelayTime(const std::vector<Reflection>& reflections) {
+ float max_delay_time = 0.0f;
+ for (const auto& reflection : reflections) {
+ max_delay_time = std::max(max_delay_time, reflection.delay_time_seconds);
+ }
+ return max_delay_time;
+}
+
+} // namespace
+
+ReflectionsProcessor::ReflectionsProcessor(int sample_rate,
+ size_t frames_per_buffer)
+ : sample_rate_(sample_rate),
+ frames_per_buffer_(frames_per_buffer),
+ max_delay_samples_(kMaxDelayTimeSeconds * sample_rate_),
+ low_pass_filter_(0.0f),
+ temp_mono_buffer_(kNumMonoChannels, frames_per_buffer_),
+ current_reflection_buffer_(kNumFirstOrderAmbisonicChannels,
+ frames_per_buffer),
+ target_reflection_buffer_(kNumFirstOrderAmbisonicChannels,
+ frames_per_buffer),
+ target_reflections_(kNumRoomSurfaces),
+ crossfade_(false),
+ crossfader_(frames_per_buffer_),
+ num_frames_to_process_on_empty_input_(0),
+ delays_(kNumRoomSurfaces),
+ delay_filter_(max_delay_samples_, frames_per_buffer),
+ delay_buffer_(kNumRoomSurfaces, frames_per_buffer),
+ gains_(kNumRoomSurfaces),
+ gain_processors_(kNumRoomSurfaces) {
+ DCHECK_GT(sample_rate_, 0);
+ DCHECK_GT(frames_per_buffer_, 0U);
+}
+
+void ReflectionsProcessor::Update(
+ const ReflectionProperties& reflection_properties,
+ const WorldPosition& listener_position) {
+
+ // Initialize the low-pass filter.
+ const float low_pass_coefficient = ComputeLowPassMonoPoleCoefficient(
+ reflection_properties.cutoff_frequency, sample_rate_);
+ low_pass_filter_.SetCoefficient(low_pass_coefficient);
+ // Update the target reflections.
+ WorldPosition relative_listener_position;
+ GetRelativeDirection(
+ WorldPosition(reflection_properties.room_position),
+ WorldRotation(reflection_properties.room_rotation).conjugate(),
+ listener_position, &relative_listener_position);
+ ComputeReflections(relative_listener_position,
+ WorldPosition(reflection_properties.room_dimensions),
+ reflection_properties.coefficients, &target_reflections_);
+ // Additional |frames_per_buffer_| to process needed to compensate the
+ // crossfade between the current and target reflections.
+ num_frames_to_process_on_empty_input_ =
+ frames_per_buffer_ +
+ static_cast<size_t>(FindMaxReflectionDelayTime(target_reflections_) *
+ static_cast<float>(sample_rate_));
+ // Reflections have been updated so crossfade is required.
+ crossfade_ = true;
+}
+
+void ReflectionsProcessor::Process(const AudioBuffer& input,
+ AudioBuffer* output) {
+ DCHECK_EQ(input.num_channels(), kNumMonoChannels);
+ DCHECK_EQ(input.num_frames(), frames_per_buffer_);
+ DCHECK(output);
+ DCHECK_GE(output->num_channels(), kNumFirstOrderAmbisonicChannels);
+ DCHECK_EQ(output->num_frames(), frames_per_buffer_);
+ // Prefilter mono input.
+ const AudioBuffer::Channel& input_channel = input[0];
+ AudioBuffer::Channel* temp_channel = &temp_mono_buffer_[0];
+ const bool filter_success =
+ low_pass_filter_.Filter(input_channel, temp_channel);
+ const AudioBuffer::Channel& low_pass_channel =
+ filter_success ? *temp_channel : input_channel;
+ delay_filter_.InsertData(low_pass_channel);
+ // Process reflections.
+ if (crossfade_) {
+ ApplyReflections(&current_reflection_buffer_);
+ UpdateGainsAndDelays();
+ ApplyReflections(&target_reflection_buffer_);
+ crossfader_.ApplyLinearCrossfade(target_reflection_buffer_,
+ current_reflection_buffer_, output);
+ crossfade_ = false;
+ } else {
+ ApplyReflections(output);
+ }
+}
+
+void ReflectionsProcessor::UpdateGainsAndDelays() {
+ for (size_t i = 0; i < kNumRoomSurfaces; ++i) {
+ delays_[i] =
+ std::min(max_delay_samples_,
+ static_cast<size_t>(target_reflections_[i].delay_time_seconds *
+ static_cast<float>(sample_rate_)));
+ gains_[i] = target_reflections_[i].magnitude;
+ }
+}
+
+void ReflectionsProcessor::ApplyReflections(AudioBuffer* output) {
+ DCHECK(output);
+ DCHECK_GE(output->num_channels(), kNumFirstOrderAmbisonicChannels);
+ (*output).Clear();
+ for (size_t i = 0; i < kNumRoomSurfaces; ++i) {
+ auto* delay_channel = &delay_buffer_[i];
+ delay_filter_.GetDelayedData(delays_[i], delay_channel);
+ const bool zero_gain = IsGainNearZero(gains_[i]) &&
+ IsGainNearZero(gain_processors_[i].GetGain());
+ if (!zero_gain) {
+ gain_processors_[i].ApplyGain(gains_[i], *delay_channel, delay_channel,
+ false /* accumulate_output */);
+ // Applies fast Ambisonic reflections encoding.
+ (*output)[0] += *delay_channel;
+ switch (i) {
+ case 0: /* left wall reflection */
+ (*output)[1] += *delay_channel;
+ break;
+ case 1: /* right wall reflection */
+ (*output)[1] -= *delay_channel;
+ break;
+ case 2: /* floor reflection */
+ (*output)[2] -= *delay_channel;
+ break;
+ case 3: /* ceiling reflection */
+ (*output)[2] += *delay_channel;
+ break;
+ case 4: /* front wall reflection */
+ (*output)[3] += *delay_channel;
+ break;
+ case 5: /* back wall reflection */
+ (*output)[3] -= *delay_channel;
+ break;
+ }
+ } else {
+ // Make sure the gain processor is initialized.
+ gain_processors_[i].Reset(0.0f);
+ }
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor.h
new file mode 100644
index 000000000..1b9765b0f
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor.h
@@ -0,0 +1,128 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_REFLECTIONS_PROCESSOR_H_
+#define RESONANCE_AUDIO_DSP_REFLECTIONS_PROCESSOR_H_
+
+#include <utility>
+#include <vector>
+
+#include "api/resonance_audio_api.h"
+#include "base/audio_buffer.h"
+#include "base/misc_math.h"
+#include "dsp/delay_filter.h"
+#include "dsp/gain_processor.h"
+#include "dsp/mono_pole_filter.h"
+#include "dsp/reflection.h"
+#include "utils/buffer_crossfader.h"
+
+namespace vraudio {
+
+// Class that accepts single mono buffer as input and outputs a first order
+// ambisonic buffer of the mix of all the rooms early reflections computed for
+// the buffer.
+//
+// The input consists of a mono mix of all the sound objects in the system. The
+// reflections are assumed to be aligned with the aabb axes and thus the first
+// order ambisonic axes.
+class ReflectionsProcessor {
+ public:
+ // Constructs a |ReflectionsProcessor|.
+ //
+ // @param sample_rate System sampling rate.
+ // @param frames_per_buffer System frames per buffer.
+ ReflectionsProcessor(int sample_rate, size_t frames_per_buffer);
+
+ // Updates reflections according to the new |ReflectionProperties|.
+ //
+ // @param reflection_properties New reflection properties.
+ // @param listener_position New listener position.
+ void Update(const ReflectionProperties& reflection_properties,
+ const WorldPosition& listener_position);
+
+ // Processes a mono |AudioBuffer| into an ambisonic |AudioBuffer|.
+ //
+ // @param input Mono input buffer.
+ // @param output Ambisonic output buffer.
+ void Process(const AudioBuffer& input, AudioBuffer* output);
+
+ // Returns the number of frames required to keep processing on empty input
+ // signal. This value can be used to avoid any potential artifacts on the
+ // final output signal when the input signal stream is empty.
+ size_t num_frames_to_process_on_empty_input() const {
+ return num_frames_to_process_on_empty_input_;
+ }
+
+ private:
+ // Updates |gains_| and |delays_| vectors of the |ReflectionsProcessor|.
+ void UpdateGainsAndDelays();
+
+ // Applies |target_reflections_| and fast-encodes them into first order
+ // ambisonics.
+ //
+ // @param output Ambisonic output buffer.
+ void ApplyReflections(AudioBuffer* output);
+
+ // System sampling rate.
+ const int sample_rate_;
+
+ // System number of frames per buffer.
+ const size_t frames_per_buffer_;
+
+ // Maximum allowed delay time for a reflection (in samples).
+ const size_t max_delay_samples_;
+
+ // Low pass filter to be applied to input signal.
+ MonoPoleFilter low_pass_filter_;
+
+ // Audio buffer to store mono low pass filtered buffers during processing.
+ AudioBuffer temp_mono_buffer_;
+
+ // Audio buffers to store FOA reflections buffers during crossfading.
+ AudioBuffer current_reflection_buffer_;
+ AudioBuffer target_reflection_buffer_;
+
+ // Target reflections filled with new data when |Update| is called.
+ std::vector<Reflection> target_reflections_;
+
+ // Indicates whether relfections have been updated and a crossfade is needed.
+ bool crossfade_;
+
+ // Buffer crossfader to apply linear crossfade during reflections update.
+ BufferCrossfader crossfader_;
+
+ // Number of frames needed to keep processing on empty input signal.
+ size_t num_frames_to_process_on_empty_input_;
+
+ // Number of samples of delay to be applied for each reflection.
+ std::vector<size_t> delays_;
+
+ // Delay filter to delay the incoming buffer.
+ DelayFilter delay_filter_;
+
+ // Delay buffer used to store delayed reflections before scaling and encoding.
+ AudioBuffer delay_buffer_;
+
+ // Gains to be applied for each reflection.
+ std::vector<float> gains_;
+
+ // |GainProcessor|s to apply |gains_|.
+ std::vector<GainProcessor> gain_processors_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_REFLECTIONS_PROCESSOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor_test.cc
new file mode 100644
index 000000000..ab1688e51
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/reflections_processor_test.cc
@@ -0,0 +1,142 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/reflections_processor.h"
+
+#include <algorithm>
+#include <utility>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "api/resonance_audio_api.h"
+#include "base/constants_and_types.h"
+#include "utils/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+const size_t kFramesPerBuffer = 512;
+const int kSampleRate = 48000;
+const float kRoomDimensions[3] = {2.0f, 2.0f, 2.0f};
+const size_t kExpectedDelaySamples = 279;
+
+} // namespace
+
+class ReflectionsProcessorTest : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ const float kReflectionCoefficients[kNumRoomSurfaces] = {0.5f, 0.5f, 0.5f,
+ 0.5f, 0.5f, 0.5f};
+ const WorldPosition kListenerPosition(0.0f, 0.0f, 0.0f);
+ std::copy(std::begin(kReflectionCoefficients),
+ std::end(kReflectionCoefficients),
+ std::begin(reflection_properties_.coefficients));
+ std::copy(std::begin(kRoomDimensions), std::end(kRoomDimensions),
+ std::begin(reflection_properties_.room_dimensions));
+ listener_position_ = kListenerPosition;
+ }
+
+ ReflectionProperties reflection_properties_;
+ WorldPosition listener_position_;
+}; // namespace vraudio
+
+// Tests that the processed output is delayed, filtered, and scaled as expected.
+TEST_F(ReflectionsProcessorTest, ProcessTest) {
+ ReflectionsProcessor reflections_processor(kSampleRate, kFramesPerBuffer);
+ reflections_processor.Update(reflection_properties_, listener_position_);
+
+ AudioBuffer input(kNumMonoChannels, kFramesPerBuffer);
+ AudioBuffer output(kNumFirstOrderAmbisonicChannels, kFramesPerBuffer);
+ // Process until we have transitioned to the specified Gain.
+ for (size_t i = 0; i < kUnitRampLength; i += kFramesPerBuffer) {
+ input.Clear();
+ output.Clear();
+ GenerateDiracImpulseFilter(0, &input[0]);
+ reflections_processor.Process(input, &output);
+ }
+
+ // The reflections calculated should be as follows:
+ // delay = 280 samples, magnitude = 0.25, direction = {azim 90, elev 0}.
+ // delay = 280 samples, magnitude = 0.25, direction = {azim -90, elev 0}.
+ // delay = 280 samples, magnitude = 0.25, direction = {azim 0, elev -90}.
+ // delay = 280 samples, magnitude = 0.25, direction = {azim 0, elev 90}.
+ // delay = 280 samples, magnitude = 0.25, direction = {azim 0, elev 0}.
+ // delay = 280 samples, magnitude = 0.25, direction = {azim 180, elev 0}.
+ const float kExpectedMagnitude = 0.25f;
+ // We expect the following ambisonic encoding coefficients:
+ // {azim 90, elev 0} = {1 1 0 0}.
+ // {azim -90, elev 0} = {1 -1 0 0}.
+ // {azim 0, elev -90} = {1 0 -1 0}.
+ // {azim 0, elev 90} = {1 0 1 0}.
+ // {azim 0, elev 0} = {1 0 0 1}.
+ // {azim 180, elev 0} = {1 0 0 -1}.
+ const std::vector<std::vector<float>> kEncodingCoefficients = {
+ {1.0f, 1.0f, 0.0f, 0.0f}, {1.0f, -1.0f, 0.0f, 0.0f},
+ {1.0f, 0.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 1.0f, 0.0f},
+ {1.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f, -1.0f}};
+
+ for (size_t j = kExpectedDelaySamples; j < kFramesPerBuffer; ++j) {
+ for (size_t k = 0; k < kNumFirstOrderAmbisonicChannels; ++k) {
+ float coefficient_sum = 0.0f;
+ for (size_t i = 0; i < kEncodingCoefficients.size(); ++i) {
+ coefficient_sum += kEncodingCoefficients[i][k];
+ }
+ const float expected_sample = input[0][j - kExpectedDelaySamples] *
+ kExpectedMagnitude * coefficient_sum;
+ EXPECT_NEAR(expected_sample, output[k][j], kEpsilonFloat);
+ }
+ }
+}
+
+// Tests that when transitioning from a reflection with zero magnitude to one
+// with non-zero magnitude, there will be a steady incremental increase in
+// the "fade in".
+TEST_F(ReflectionsProcessorTest, CrossFadeTest) {
+ ReflectionsProcessor reflections_processor(kSampleRate, kFramesPerBuffer);
+
+ AudioBuffer input(kNumMonoChannels, kFramesPerBuffer);
+ AudioBuffer output(kNumFirstOrderAmbisonicChannels, kFramesPerBuffer);
+
+ input.Clear();
+ output.Clear();
+ for (size_t i = 0; i < kFramesPerBuffer; ++i) {
+ input[0][i] = 1.0f;
+ }
+
+ reflections_processor.Process(input, &output);
+ reflections_processor.Update(reflection_properties_, listener_position_);
+ reflections_processor.Process(input, &output);
+
+ // All the reflections are expected to arrive at the listener at the same
+ // time. That is why their directional contributions are expected to cancel
+ // out. Only in first channel we will see a steady increase.
+ for (size_t channel = 0; channel < kNumFirstOrderAmbisonicChannels;
+ ++channel) {
+ if (channel < kNumMonoChannels) {
+ for (size_t frame = kExpectedDelaySamples; frame < kFramesPerBuffer;
+ ++frame) {
+ EXPECT_TRUE(output[channel][frame] > output[channel][frame - 1]);
+ }
+ } else {
+ for (size_t frame = 0; frame < kFramesPerBuffer; ++frame) {
+ EXPECT_NEAR(output[channel][frame], 0.0f, kEpsilonFloat);
+ }
+ }
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/resampler.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/resampler.cc
new file mode 100644
index 000000000..e135afcdf
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/resampler.cc
@@ -0,0 +1,335 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "dsp/resampler.h"
+
+#include <functional>
+#include <numeric>
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/misc_math.h"
+#include "base/simd_utils.h"
+
+#include "dsp/utils.h"
+
+namespace vraudio {
+
+namespace {
+
+// (kTransitionBandwidthRatio / 2) * (sample_rate / cutoff_frequency)
+// = filter_length.
+// The value below was chosen empirically as a tradeoff between execution time
+// and filter rolloff wrt. cutoff frequency.
+const size_t kTransitionBandwidthRatio = 13;
+
+// Maximum number of channels internally based upon the maximum supported
+// ambisonic order.
+const size_t kMaxNumChannels =
+ (kMaxSupportedAmbisonicOrder + 1) * (kMaxSupportedAmbisonicOrder + 1);
+
+} // namespace
+
+Resampler::Resampler()
+ : up_rate_(0),
+ down_rate_(0),
+ time_modulo_up_rate_(0),
+ last_processed_sample_(0),
+ num_channels_(0),
+ coeffs_per_phase_(0),
+ transposed_filter_coeffs_(kNumMonoChannels, kMaxSupportedNumFrames),
+ temporary_filter_coeffs_(kNumMonoChannels, kMaxSupportedNumFrames),
+ state_(kMaxNumChannels, kMaxSupportedNumFrames) {
+ state_.Clear();
+}
+
+void Resampler::Process(const AudioBuffer& input, AudioBuffer* output) {
+
+ // See "Digital Signal Processing, 4th Edition, Prolakis and Manolakis,
+ // Pearson, Chapter 11 (specificaly Figures 11.5.10 and 11.5.13).
+ DCHECK_EQ(input.num_channels(), num_channels_);
+ const size_t input_length = input.num_frames();
+ DCHECK_GE(output->num_frames(), GetNextOutputLength(input_length));
+ DCHECK_LE(output->num_frames(), GetMaxOutputLength(input_length));
+ DCHECK_EQ(output->num_channels(), num_channels_);
+ output->Clear();
+
+ if (up_rate_ == down_rate_) {
+ *output = input;
+ return;
+ }
+
+ // |input_sample| is the last processed sample.
+ size_t input_sample = last_processed_sample_;
+ // |output_sample| is the output.
+ size_t output_sample = 0;
+
+ const auto& filter_coefficients = transposed_filter_coeffs_[0];
+
+ while (input_sample < input_length) {
+ size_t filter_index = time_modulo_up_rate_ * coeffs_per_phase_;
+ size_t offset_input_index = input_sample - coeffs_per_phase_ + 1;
+ const int offset = -static_cast<int>(offset_input_index);
+
+ if (offset > 0) {
+ // We will need to draw data from the |state_| buffer.
+ const int state_num_frames = static_cast<int>(coeffs_per_phase_ - 1);
+ int state_index = state_num_frames - offset;
+ while (state_index < state_num_frames) {
+ for (size_t channel = 0; channel < num_channels_; ++channel) {
+ (*output)[channel][output_sample] +=
+ state_[channel][state_index] * filter_coefficients[filter_index];
+ }
+ state_index++;
+ filter_index++;
+ }
+ // Move along by |offset| samples up as far as |input|.
+ offset_input_index += offset;
+ }
+
+ // We now move back to where |input_sample| "points".
+ while (offset_input_index <= input_sample) {
+ for (size_t channel = 0; channel < num_channels_; ++channel) {
+ (*output)[channel][output_sample] +=
+ input[channel][offset_input_index] *
+ filter_coefficients[filter_index];
+ }
+ offset_input_index++;
+ filter_index++;
+ }
+ output_sample++;
+
+ time_modulo_up_rate_ += down_rate_;
+ // Advance the input pointer.
+ input_sample += time_modulo_up_rate_ / up_rate_;
+ // Decide which phase of the polyphase filter to use next.
+ time_modulo_up_rate_ %= up_rate_;
+ }
+ DCHECK_GE(input_sample, input_length);
+ last_processed_sample_ = input_sample - input_length;
+
+ // Take care of the |state_| buffer.
+ const int samples_left_in_input =
+ static_cast<int>(coeffs_per_phase_) - 1 - static_cast<int>(input_length);
+ if (samples_left_in_input > 0) {
+ for (size_t channel = 0; channel < num_channels_; ++channel) {
+ // Copy end of the |state_| buffer to the beginning.
+ auto& state_channel = state_[channel];
+ DCHECK_GE(static_cast<int>(state_channel.size()), samples_left_in_input);
+ std::copy_n(state_channel.end() - samples_left_in_input,
+ samples_left_in_input, state_channel.begin());
+ // Then copy input to the end of the buffer.
+ std::copy_n(input[channel].begin(), input_length,
+ state_channel.end() - input_length);
+ }
+ } else {
+ for (size_t channel = 0; channel < num_channels_; ++channel) {
+ // Copy the last of the |input| samples into the |state_| buffer.
+ DCHECK_GT(coeffs_per_phase_, 0U);
+ DCHECK_GT(input[channel].size(), coeffs_per_phase_ - 1);
+ std::copy_n(input[channel].end() - (coeffs_per_phase_ - 1),
+ coeffs_per_phase_ - 1, state_[channel].begin());
+ }
+ }
+}
+
+size_t Resampler::GetMaxOutputLength(size_t input_length) const {
+ if (up_rate_ == down_rate_) {
+ return input_length;
+ }
+ DCHECK_GT(down_rate_, 0U);
+ // The + 1 takes care of the case where:
+ // (time_modulo_up_rate_ + up_rate_ * last_processed_sample_) <
+ // ((input_length * up_rate_) % down_rate_)
+ // The output length will be equal to the return value or the return value -1.
+ return (input_length * up_rate_) / down_rate_ + 1;
+}
+
+size_t Resampler::GetNextOutputLength(size_t input_length) const {
+ if (up_rate_ == down_rate_) {
+ return input_length;
+ }
+ const size_t max_length = GetMaxOutputLength(input_length);
+ if ((time_modulo_up_rate_ + up_rate_ * last_processed_sample_) >=
+ ((input_length * up_rate_) % down_rate_)) {
+ return max_length - 1;
+ }
+ return max_length;
+}
+
+void Resampler::SetRateAndNumChannels(int source_frequency,
+ int destination_frequency,
+ size_t num_channels) {
+
+ // Convert sampling rates to be relatively prime.
+ DCHECK_GT(source_frequency, 0);
+ DCHECK_GT(destination_frequency, 0);
+ DCHECK_GT(num_channels, 0U);
+ const int greatest_common_divisor =
+ FindGcd(destination_frequency, source_frequency);
+ const size_t destination =
+ static_cast<size_t>(destination_frequency / greatest_common_divisor);
+ const size_t source =
+ static_cast<size_t>(source_frequency / greatest_common_divisor);
+
+ // Obtain the size of the |state_| before |coeffs_per_phase_| is updated in
+ // |GenerateInterpolatingFilter()|.
+ const size_t old_state_size =
+ coeffs_per_phase_ > 0 ? coeffs_per_phase_ - 1 : 0;
+ if ((destination != up_rate_) || (source != down_rate_)) {
+ up_rate_ = destination;
+ down_rate_ = source;
+ if (up_rate_ == down_rate_) {
+ return;
+ }
+ // Create transposed multirate filters from sincs.
+ GenerateInterpolatingFilter(source_frequency);
+ // Reset the time variable as it may be longer than the new filter length if
+ // we switched from upsampling to downsampling via a call to SetRate().
+ time_modulo_up_rate_ = 0;
+ }
+
+ // Update the |state_| buffer.
+ if (num_channels_ != num_channels) {
+ num_channels_ = num_channels;
+ InitializeStateBuffer(old_state_size);
+ }
+}
+
+bool Resampler::AreSampleRatesSupported(int source, int destination) {
+ DCHECK_GT(source, 0);
+ DCHECK_GT(destination, 0);
+ // Determines whether sample rates are supported based upon whether our
+ // maximul filter lenhgth is big enough to hold the corresponding
+ // interpolation filter.
+ const int max_rate =
+ std::max(source, destination) / FindGcd(source, destination);
+ size_t filter_length = max_rate * kTransitionBandwidthRatio;
+ filter_length += filter_length % 2;
+ return filter_length <= kMaxSupportedNumFrames;
+}
+
+void Resampler::ResetState() {
+
+ time_modulo_up_rate_ = 0;
+ last_processed_sample_ = 0;
+ state_.Clear();
+}
+
+void Resampler::InitializeStateBuffer(size_t old_state_num_frames) {
+ // Update the |state_| buffer if it is null or if the number of coefficients
+ // per phase in the polyphase filter has changed.
+ if (up_rate_ == down_rate_ || num_channels_ == 0) {
+ return;
+ }
+ // If the |state_| buffer is to be kept. For example in the case of a change
+ // in either source or destination sampling rate, maintaining the old |state_|
+ // buffers contents allows a glitch free transition.
+ const size_t new_state_num_frames =
+ coeffs_per_phase_ > 0 ? coeffs_per_phase_ - 1 : 0;
+ if (old_state_num_frames != new_state_num_frames) {
+ const size_t min_size =
+ std::min(new_state_num_frames, old_state_num_frames);
+ const size_t max_size =
+ std::max(new_state_num_frames, old_state_num_frames);
+ for (size_t channel = 0; channel < num_channels_; ++channel) {
+ auto& state_channel = state_[channel];
+ DCHECK_LT(state_channel.begin() + max_size, state_channel.end());
+ std::fill(state_channel.begin() + min_size,
+ state_channel.begin() + max_size, 0.0f);
+ }
+ }
+}
+
+void Resampler::GenerateInterpolatingFilter(int sample_rate) {
+ // See "Digital Signal Processing, 4th Edition, Prolakis and Manolakis,
+ // Pearson, Chapter 11 (specificaly Figures 11.5.10 and 11.5.13).
+ const size_t max_rate = std::max(up_rate_, down_rate_);
+ const float cutoff_frequency =
+ static_cast<float>(sample_rate) / static_cast<float>(2 * max_rate);
+ size_t filter_length = max_rate * kTransitionBandwidthRatio;
+ filter_length += filter_length % 2;
+ auto* filter_channel = &temporary_filter_coeffs_[0];
+ filter_channel->Clear();
+ GenerateSincFilter(cutoff_frequency, static_cast<float>(sample_rate),
+ filter_length, filter_channel);
+
+ // Pad out the filter length so that it can be arranged in polyphase fashion.
+ const size_t transposed_length =
+ filter_length + max_rate - (filter_length % max_rate);
+ coeffs_per_phase_ = transposed_length / max_rate;
+ ArrangeFilterAsPolyphase(filter_length, *filter_channel);
+}
+
+void Resampler::ArrangeFilterAsPolyphase(size_t filter_length,
+ const AudioBuffer::Channel& filter) {
+ // Coefficients are transposed and flipped.
+ // Suppose |up_rate_| is 3, and the input number of coefficients is 10,
+ // h[0], ..., h[9].
+ // Then the |transposed_filter_coeffs_| buffer will look like this:
+ // h[9], h[6], h[3], h[0], flipped phase 0 coefs.
+ // 0, h[7], h[4], h[1], flipped phase 1 coefs (zero-padded).
+ // 0, h[8], h[5], h[2], flipped phase 2 coefs (zero-padded).
+ transposed_filter_coeffs_.Clear();
+ auto& transposed_coefficients_channel = transposed_filter_coeffs_[0];
+ for (size_t i = 0; i < up_rate_; ++i) {
+ for (size_t j = 0; j < coeffs_per_phase_; ++j) {
+ if (j * up_rate_ + i < filter_length) {
+ const size_t coeff_index =
+ (coeffs_per_phase_ - 1 - j) + i * coeffs_per_phase_;
+ transposed_coefficients_channel[coeff_index] = filter[j * up_rate_ + i];
+ }
+ }
+ }
+}
+
+void Resampler::GenerateSincFilter(float cutoff_frequency, float sample_rate,
+ size_t filter_length,
+ AudioBuffer::Channel* buffer) {
+
+ DCHECK_GT(sample_rate, 0.0f);
+ const float angular_cutoff_frequency =
+ kTwoPi * cutoff_frequency / sample_rate;
+
+ const size_t half_filter_length = filter_length / 2;
+ GenerateHannWindow(true /* Full Window */, filter_length, buffer);
+ auto* buffer_channel = &buffer[0];
+
+ for (size_t i = 0; i < filter_length; ++i) {
+ if (i == half_filter_length) {
+ (*buffer_channel)[half_filter_length] *= angular_cutoff_frequency;
+ } else {
+ const float denominator =
+ static_cast<float>(i) - (static_cast<float>(filter_length) / 2.0f);
+ DCHECK_GT(std::abs(denominator), kEpsilonFloat);
+ (*buffer_channel)[i] *=
+ std::sin(angular_cutoff_frequency * denominator) / denominator;
+ }
+ }
+ // Normalize.
+ const float normalizing_factor =
+ static_cast<float>(up_rate_) /
+ std::accumulate(buffer_channel->begin(), buffer_channel->end(), 0.0f);
+ ScalarMultiply(filter_length, normalizing_factor, buffer_channel->begin(),
+ buffer_channel->begin());
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/resampler.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/resampler.h
new file mode 100644
index 000000000..c2c079a80
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/resampler.h
@@ -0,0 +1,135 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_RESAMPLER_H_
+#define RESONANCE_AUDIO_DSP_RESAMPLER_H_
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Class that provides rational resampling of audio data.
+class Resampler {
+ public:
+ Resampler();
+
+ // Resamples an |AudioBuffer| of input data sampled at |source_frequency| to
+ // |destination_frequency|.
+ //
+ // @param input Input data to be resampled.
+ // @param output Resampled output data.
+ void Process(const AudioBuffer& input, AudioBuffer* output);
+
+ // Returns the maximum length which the output buffer will be, given the
+ // current source and destination frequencies and input length. The actual
+ // output length will either be this or one less.
+ //
+ // @param input_length Length of the input.
+ // @return Maximum length of the output.
+ size_t GetMaxOutputLength(size_t input_length) const;
+
+ // Returns the next length which the output buffer will be, given the
+ // current source and destination frequencies and input length.
+ //
+ // @param input_length Length of the input.
+ // @return Next length of the output.
+ size_t GetNextOutputLength(size_t input_length) const;
+
+ // Sets the source and destination sampling rate as well as the number of
+ // channels. Note this method only resets the filter state number of channel
+ // changes.
+ //
+ // @param source_frequency Sampling rate of input data.
+ // @param destination_frequency Desired output sampling rate.
+ // @param num_channels Number of channels to process.
+ void SetRateAndNumChannels(int source_frequency, int destination_frequency,
+ size_t num_channels);
+
+ // Returns whether the sampling rates provided are supported by the resampler.
+ //
+ // @param source Source sampling rate.
+ // @param destination Destination sampling rate.
+ // @return True if the sampling rate pair are supported.
+ static bool AreSampleRatesSupported(int source, int destination);
+
+ // Resets the inner state of the |Resampler| allowing its use repeatedly on
+ // different data streams.
+ void ResetState();
+
+ private:
+ friend class PolyphaseFilterTest;
+ // Initializes the |state_| buffer. Called when sampling rate is changed or
+ // the state is reset.
+ //
+ // @param size_t old_state_num_frames Number of frames in the |state_| buffer
+ // previous to the most recent call to |GenerateInterpolatingFilter|.
+ void InitializeStateBuffer(size_t old_state_num_frames);
+
+ // Generates a windowed sinc to act as the interpolating/anti-aliasing filter.
+ //
+ // @param sample_rate The system sampling rate.
+ void GenerateInterpolatingFilter(int sample_rate);
+
+ // Arranges the anti aliasing filter coefficients in polyphase filter format.
+ //
+ // @param filter_length Number of frames in |filter| containing filter
+ // coefficients.
+ // @param filter Vector of filter coefficients.
+ void ArrangeFilterAsPolyphase(size_t filter_length,
+ const AudioBuffer::Channel& filter);
+
+ // Generates Hann windowed sinc function anti aliasing filters.
+ //
+ // @param cutoff_frequency Transition band (-3dB) frequency of the filter.
+ // @param sample_rate The system sampling rate.
+ // @param filter_length Number of frames in |buffer| containing filter
+ // coefficients.
+ // @param buffer |AudioBuffer::Channel| to contain the filter coefficients.
+ void GenerateSincFilter(float cutoff_frequency, float sample_rate,
+ size_t filter_length, AudioBuffer::Channel* buffer);
+
+ // Rate of the interpolator section of the rational sampling rate converter.
+ size_t up_rate_;
+
+ // Rate of the decimator section of the rational sampling rate convereter.
+ size_t down_rate_;
+
+ // Time variable for the polyphase filter.
+ size_t time_modulo_up_rate_;
+
+ // Marks the last processed sample of the input.
+ size_t last_processed_sample_;
+
+ // Number of channels in the |AudioBuffer|s processed.
+ size_t num_channels_;
+
+ // Number of filter coefficients in each phase of the polyphase filter.
+ size_t coeffs_per_phase_;
+
+ // Filter coefficients stored in polyphase form.
+ AudioBuffer transposed_filter_coeffs_;
+
+ // Filter coefficients in planar form, used for calculating the transposed
+ // filter.
+ AudioBuffer temporary_filter_coeffs_;
+
+ // Buffer holding the samples of input required between input buffers.
+ AudioBuffer state_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_RESAMPLER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/resampler_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/resampler_test.cc
new file mode 100644
index 000000000..5b23de58f
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/resampler_test.cc
@@ -0,0 +1,325 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/resampler.h"
+
+#include <numeric>
+#include <utility>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "utils/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+const int kToneFrequency = 1000;
+
+const size_t kInputBufferLength = 441;
+
+const int kSourceDataSampleRate = 44100;
+const int kUpDestinationDataSampleRate = 48000;
+const int kDownDestinationDataSampleRate = 24000;
+
+TEST(ResamplerTest, UpSampleTest) {
+ // Create input buffer with 1000Hz sine wave at 44100Hz, 441 samples long.
+ // This should be ten periods of a sine wave.
+ AudioBuffer input(kNumMonoChannels, kInputBufferLength);
+ GenerateSineWave(kToneFrequency, kSourceDataSampleRate, &input[0]);
+
+ Resampler resampler;
+ resampler.SetRateAndNumChannels(
+ kSourceDataSampleRate, kUpDestinationDataSampleRate, kNumMonoChannels);
+ AudioBuffer output(kNumMonoChannels,
+ resampler.GetNextOutputLength(kInputBufferLength));
+ resampler.Process(input, &output);
+
+ // Ensure the length of the output is as expected.
+ const size_t input_length_proportion =
+ kSourceDataSampleRate / kInputBufferLength;
+ const size_t expected_output_length =
+ kUpDestinationDataSampleRate / input_length_proportion;
+ EXPECT_EQ(expected_output_length, output.num_frames());
+
+ // Ensure the output also contains 10 periods of a sine wave, confirming it is
+ // still at 1000Hz given the new sampling rate.
+ AudioBuffer thresholded_output(kNumMonoChannels, output.num_frames());
+ for (size_t i = 0; i < output.num_frames(); ++i) {
+ thresholded_output[0][i] = std::abs(output[0][i]) < 0.5f ? 0.0f : 1.0f;
+ }
+ size_t num_square_wave_corners = 1;
+ // We have now generated a square wave with twice the number of corners as
+ // there are zero crossings.
+ for (size_t i = 0; i < output.num_frames() - 1; ++i) {
+ if (thresholded_output[0][i] != thresholded_output[0][i + 1]) {
+ num_square_wave_corners++;
+ }
+ }
+ const size_t zerocross_count = num_square_wave_corners / 2;
+
+ const size_t num_expected_zero_crossings =
+ 2 * kToneFrequency / (kSourceDataSampleRate / kInputBufferLength);
+ EXPECT_EQ(num_expected_zero_crossings, zerocross_count);
+}
+
+TEST(ResamplerTest, DownSampleTest) {
+ // Create input buffer with 1000Hz sine wave at 44100Hz, 441 samples long.
+ // This should be ten periods of a sine wave.
+ AudioBuffer input(kNumMonoChannels, kInputBufferLength);
+ GenerateSineWave(kToneFrequency, kSourceDataSampleRate, &input[0]);
+
+ Resampler resampler;
+ resampler.SetRateAndNumChannels(
+ kSourceDataSampleRate, kDownDestinationDataSampleRate, kNumMonoChannels);
+ AudioBuffer output(kNumMonoChannels,
+ resampler.GetNextOutputLength(kInputBufferLength));
+ resampler.Process(input, &output);
+
+ // Ensure the length of the output is as expected.
+ const size_t input_length_proportion =
+ kSourceDataSampleRate / kInputBufferLength;
+ const size_t expected_output_length =
+ kDownDestinationDataSampleRate / input_length_proportion;
+ EXPECT_EQ(expected_output_length, output.num_frames());
+
+ // Ensure the output also contains one period of a sine wave, confirming it is
+ // still at 100Hz given the new sampling rate.
+ AudioBuffer thresholded_output(kNumMonoChannels, output.num_frames());
+ for (size_t i = 0; i < output.num_frames(); ++i) {
+ thresholded_output[0][i] = std::abs(output[0][i]) < 0.5f ? 0.0f : 1.0f;
+ }
+ int zero_cross_count = 1;
+ for (size_t i = 0; i < output.num_frames() - 1; ++i) {
+ if (thresholded_output[0][i] != thresholded_output[0][i + 1]) {
+ zero_cross_count++;
+ }
+ }
+ const int num_expected_zero_crossings =
+ 4 * kToneFrequency / (kSourceDataSampleRate / kInputBufferLength);
+ EXPECT_EQ(num_expected_zero_crossings, zero_cross_count);
+}
+
+TEST(ResamplerTest, ResetStateTest) {
+ // Create input buffer with 1000Hz sine wave at 44100Hz, 441 samples long.
+ // This should be ten periods of a sine wave.
+ AudioBuffer input(kNumMonoChannels, kInputBufferLength);
+ GenerateSineWave(kToneFrequency, kSourceDataSampleRate, &input[0]);
+
+ Resampler resampler;
+ resampler.SetRateAndNumChannels(
+ kSourceDataSampleRate, kUpDestinationDataSampleRate, kNumMonoChannels);
+ AudioBuffer output_1(kNumMonoChannels,
+ resampler.GetNextOutputLength(kInputBufferLength));
+ resampler.Process(input, &output_1);
+
+ resampler.ResetState();
+ AudioBuffer output_2(kNumMonoChannels,
+ resampler.GetNextOutputLength(kInputBufferLength));
+ resampler.Process(input, &output_2);
+
+ // If the clearing of the resampler worked properly there should be no
+ // internal state between process calls and thus both outputs should be
+ // identical.
+ for (size_t sample = 0; sample < output_1.num_frames(); ++sample) {
+ EXPECT_NEAR(output_1[0][sample], output_2[0][sample], kEpsilonFloat);
+ }
+}
+
+TEST(ResamplerTest, TwoChannelTest) {
+ AudioBuffer input(kNumStereoChannels, kInputBufferLength);
+ GenerateSineWave(kToneFrequency, kSourceDataSampleRate, &input[0]);
+ GenerateSineWave(2 * kToneFrequency, kSourceDataSampleRate, &input[1]);
+
+ Resampler resampler;
+ resampler.SetRateAndNumChannels(
+ kSourceDataSampleRate, kUpDestinationDataSampleRate, kNumStereoChannels);
+ AudioBuffer output(kNumStereoChannels,
+ resampler.GetNextOutputLength(kInputBufferLength));
+ resampler.Process(input, &output);
+
+ AudioBuffer thresholded_output(kNumStereoChannels, output.num_frames());
+ for (size_t i = 0; i < output.num_frames(); ++i) {
+ thresholded_output[0][i] = std::abs(output[0][i]) < 0.5f ? 0.0f : 1.0f;
+ thresholded_output[1][i] = std::abs(output[1][i]) < 0.5f ? 0.0f : 1.0f;
+ }
+ int channel_0_zero_cross_count = 1;
+ int channel_1_zero_cross_count = 1;
+ for (size_t i = 0; i < output.num_frames() - 1; ++i) {
+ if (thresholded_output[0][i] != thresholded_output[0][i + 1]) {
+ channel_0_zero_cross_count++;
+ }
+ if (thresholded_output[1][i] != thresholded_output[1][i + 1]) {
+ channel_1_zero_cross_count++;
+ }
+ }
+ const int channel_0_expected_zero_crossings =
+ 4 * kToneFrequency / (kSourceDataSampleRate / kInputBufferLength);
+ const int channel_1_expected_zero_crossings =
+ 8 * kToneFrequency / (kSourceDataSampleRate / kInputBufferLength);
+ EXPECT_EQ(channel_0_zero_cross_count, channel_0_expected_zero_crossings);
+ EXPECT_EQ(channel_1_zero_cross_count, channel_1_expected_zero_crossings);
+}
+
+TEST(ResamplerTest, DiracImpulseUpsampleTest) {
+ const size_t kInputSignalSize = 128;
+ AudioBuffer input_signal(kNumMonoChannels, kInputSignalSize);
+ GenerateDiracImpulseFilter(kInputSignalSize / 2, &input_signal[0]);
+
+ const int kSourceSamplingRate = 100;
+ const int kDestinationSamplingRate = 200;
+
+ Resampler resampler;
+ resampler.SetRateAndNumChannels(kSourceSamplingRate, kDestinationSamplingRate,
+ kNumMonoChannels);
+
+ AudioBuffer output_signal(kNumMonoChannels,
+ resampler.GetNextOutputLength(kInputSignalSize));
+ const int resampling_factor = kDestinationSamplingRate / kSourceSamplingRate;
+ EXPECT_EQ(kInputSignalSize * resampling_factor, output_signal.num_frames());
+ // Perform resampling. Dirac impulse position should shift according to
+ // "resampling_factor".
+ resampler.Process(input_signal, &output_signal);
+ EXPECT_EQ(kInputSignalSize * resampling_factor, output_signal.num_frames());
+
+ DelayCompare(input_signal[0], output_signal[0], kInputSignalSize / 2,
+ kEpsilonFloat);
+}
+
+TEST(ResamplerTest, GetNextOutputLengthTest) {
+ const size_t input_length = 10;
+ Resampler resampler;
+ resampler.SetRateAndNumChannels(kSourceDataSampleRate,
+ kSourceDataSampleRate / 2, kNumMonoChannels);
+ // In this case the source rate is twice the destination rate, we can expect
+ // the output length to be half the input_length.
+
+ resampler.SetRateAndNumChannels(kSourceDataSampleRate,
+ kSourceDataSampleRate * 2, kNumMonoChannels);
+ // In this case the source rate is half the destination rate, we can
+ // expect the output length to be twice the input_length.
+ EXPECT_EQ(input_length * 2, resampler.GetNextOutputLength(input_length));
+}
+
+TEST(Resampler, AreSampleRatesSupportedTest) {
+ const size_t kNumPairs = 6;
+ const int kSourceRates[kNumPairs] = {4000, 16000, 44100, 96000, 41999, 48000};
+ const int kDestRates[kNumPairs] = {96000, 44100, 48000, 32000, 44100, 43210};
+ const bool kExpectedResults[kNumPairs] = {true, true, true,
+ true, false, false};
+
+ // We generally support only rates with relatively high GCD.
+ for (size_t i = 0; i < kNumPairs; ++i) {
+ const bool result =
+ Resampler::AreSampleRatesSupported(kSourceRates[i], kDestRates[i]);
+ EXPECT_EQ(result, kExpectedResults[i]);
+ }
+}
+
+class OutputLengthTest : public ::testing::TestWithParam<std::pair<int, int>> {
+};
+
+// Tests that the lengths returned by the |Process| method are always equal to
+// the length returned by |GetMaxOutputLength|, or one sample less.
+TEST_P(OutputLengthTest, OutputLengthTest) {
+ const size_t kInputSize = 512;
+ Resampler resampler;
+ const auto rates = GetParam();
+ resampler.SetRateAndNumChannels(rates.first, rates.second, kNumMonoChannels);
+ AudioBuffer input(kNumMonoChannels, kInputSize);
+ const size_t max_output_length = resampler.GetMaxOutputLength(kInputSize);
+ AudioBuffer output(kNumMonoChannels, max_output_length);
+
+ // Process 100 times and expect the lengts to be maximum length or one less.
+ const size_t kTimesToProcess = 100;
+ for (size_t i = 0; i < kTimesToProcess; ++i) {
+ const size_t next_output_length = resampler.GetNextOutputLength(kInputSize);
+ resampler.Process(input, &output);
+ EXPECT_LE(next_output_length, max_output_length);
+ EXPECT_LE(max_output_length - next_output_length, 1U);
+ }
+}
+
+INSTANTIATE_TEST_CASE_P(RatePairs, OutputLengthTest,
+ ::testing::Values(std::make_pair(44100, 48000),
+ std::make_pair(48000, 44100)));
+
+} // namespace
+
+class PolyphaseFilterTest : public ::testing::Test {
+ protected:
+ PolyphaseFilterTest() {}
+ // Virtual methods from ::testing::Test
+ ~PolyphaseFilterTest() override {}
+ void SetUp() override {}
+ void TearDown() override {}
+
+ std::unique_ptr<AudioBuffer> GetPolyphaseFilter(
+ const AudioBuffer::Channel& filter_coefficients, int coeffs_per_phase,
+ int up_rate) {
+ // Create a resampler with arbitrary source and destination sampling rates.
+ Resampler resampler;
+ resampler.SetRateAndNumChannels(kSourceDataSampleRate,
+ kSourceDataSampleRate, kNumMonoChannels);
+ resampler.up_rate_ = up_rate;
+ resampler.transposed_filter_coeffs_.Clear();
+ resampler.coeffs_per_phase_ = coeffs_per_phase;
+ resampler.ArrangeFilterAsPolyphase(filter_coefficients.size(),
+ filter_coefficients);
+ std::unique_ptr<AudioBuffer> polyphase_filter(new AudioBuffer());
+ *polyphase_filter = resampler.transposed_filter_coeffs_;
+ return polyphase_filter;
+ }
+};
+
+TEST_F(PolyphaseFilterTest, CorrectPolyphaseFilterTest) {
+ // Choose an uprate which is a factor of the filters length.
+ const int filter_length = 24;
+ const int uprate = 4;
+ const int phase_length = filter_length / uprate;
+
+ // Create a vector of ascending numbers (1:24).
+ AudioBuffer ascending(kNumMonoChannels, filter_length);
+ ascending.Clear();
+ std::iota(ascending[0].begin(), ascending[0].end(), 1.0f);
+
+ std::unique_ptr<AudioBuffer> output =
+ GetPolyphaseFilter(ascending[0], phase_length, uprate);
+
+ // In polyphase format, the filter coefficients can be thought of as a matrix
+ // with uprate columns. The last uprate coeffecients are in the first row and
+ // the first uprate coefficients are in the last row. This is stored in a
+ // vector, column by column.
+ //
+ // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
+ // becomes:
+ // 21 22 23 24
+ // 17 18 19 20
+ // 13 14 15 16
+ // 9 10 11 12
+ // 5 6 7 8
+ // 1 2 3 4
+ size_t index = 0;
+ for (int phase = uprate; phase > 0; --phase) {
+ for (int value = filter_length - phase + 1; value > uprate - phase;
+ value -= uprate) {
+ EXPECT_EQ(static_cast<float>(value), (*output)[0][index++]);
+ }
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_compensator.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_compensator.cc
new file mode 100644
index 000000000..2996d3799
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_compensator.cc
@@ -0,0 +1,214 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/reverb_onset_compensator.h"
+
+#include <algorithm>
+#include <cmath>
+#include <iterator>
+
+#include "base/constants_and_types.h"
+#include "dsp/spectral_reverb_constants_and_tables.h"
+#include "dsp/utils.h"
+
+namespace vraudio {
+
+namespace {
+
+// Number of reverb updaters. Twelve were chosen as this represents one update
+// per buffer length at 24kHz, a number we are very unlikely to exceed.
+const size_t kNumReverbUpdaters = 12;
+
+} // namespace
+
+ReverbOnsetCompensator::ReverbOnsetCompensator(int sampling_rate,
+ size_t frames_per_buffer,
+ FftManager* fft_manager)
+ : fft_manager_(fft_manager),
+ sampling_rate_(sampling_rate),
+ frames_per_buffer_(frames_per_buffer),
+ base_curves_(kNumStereoChannels, kCorrectionCurveLength),
+ adder_curves_(kNumStereoChannels, kCorrectionCurveLength),
+ left_filter_(CeilToMultipleOfFramesPerBuffer(kCorrectionCurveLength,
+ frames_per_buffer_),
+ frames_per_buffer_, fft_manager_),
+ right_filter_(CeilToMultipleOfFramesPerBuffer(kCorrectionCurveLength,
+ frames_per_buffer_),
+ frames_per_buffer_, fft_manager_),
+ delay_filter_(CeilToMultipleOfFramesPerBuffer(kCorrectionCurveLength,
+ frames_per_buffer_),
+ frames_per_buffer_),
+ num_active_processors_(0),
+ temp_kernel_buffer_(kNumStereoChannels, frames_per_buffer_),
+ temp_freq_buffer_(kNumMonoChannels, fft_manager_->GetFftSize()) {
+ CHECK(fft_manager_);
+ DCHECK_GT(sampling_rate_, 0);
+ DCHECK_GT(frames_per_buffer_, 0U);
+
+ temp_kernel_buffer_.Clear();
+ temp_freq_buffer_.Clear();
+
+ GenerateNoiseVectors();
+ GenerateCorrectionCurves();
+
+ // Insert reverb updaters.
+ for (size_t i = 0; i < kNumReverbUpdaters; ++i) {
+ update_processors_.emplace_front(new ReverbOnsetUpdateProcessor(
+ frames_per_buffer_, sampling_rate_, &base_curves_, &adder_curves_));
+ }
+}
+
+void ReverbOnsetCompensator::Process(const AudioBuffer& input,
+ AudioBuffer* output) {
+ DCHECK(output);
+ DCHECK_EQ(kNumMonoChannels, input.num_channels());
+ DCHECK_EQ(frames_per_buffer_, input.num_frames());
+ DCHECK_EQ(kNumStereoChannels, output->num_channels());
+ DCHECK_EQ(frames_per_buffer_, output->num_frames());
+
+ delay_filter_.InsertData(input[0]);
+ delay_filter_.GetDelayedData(kCompensationOnsetLength, &(*output)[0]);
+
+ // Process reverb updates.
+ AudioBuffer::Channel* kernel_channel_left = &temp_kernel_buffer_[0];
+ AudioBuffer::Channel* kernel_channel_right = &temp_kernel_buffer_[1];
+
+ size_t processor_index = 0;
+ while (processor_index < num_active_processors_) {
+ auto current_processor = update_processors_.begin();
+ std::advance(current_processor, processor_index);
+ const size_t partition_index =
+ (*current_processor)->GetCurrentPartitionIndex();
+ if ((*current_processor)
+ ->Process(bandpassed_noise_left_, bandpassed_noise_right_,
+ kernel_channel_left, kernel_channel_right)) {
+ left_filter_.ReplacePartition(partition_index, *kernel_channel_left);
+ right_filter_.ReplacePartition(partition_index, *kernel_channel_right);
+ ++processor_index;
+ } else {
+ // Update of the |current_processor| is finished, move it to the end of
+ // the list and reduce the number of active processors.
+ update_processors_.splice(update_processors_.end(), update_processors_,
+ current_processor);
+ --num_active_processors_;
+ }
+ }
+
+ // Filter the input (Using the output buffer due to the delay operation).
+ fft_manager_->FreqFromTimeDomain((*output)[0], &temp_freq_buffer_[0]);
+
+ left_filter_.Filter(temp_freq_buffer_[0]);
+ right_filter_.Filter(temp_freq_buffer_[0]);
+
+ left_filter_.GetFilteredSignal(&(*output)[0]);
+ right_filter_.GetFilteredSignal(&(*output)[1]);
+}
+
+void ReverbOnsetCompensator::Update(const float* rt60_values, float gain) {
+ DCHECK(rt60_values);
+ // Reset a reverb update processor from the end of the list and place it at
+ // the front. If the list is full, rotate the list and reuse the oldest active
+ // processor.
+ std::list<std::unique_ptr<ReverbOnsetUpdateProcessor>>::iterator
+ new_processor;
+ if (num_active_processors_ < kNumReverbUpdaters) {
+ new_processor = update_processors_.end();
+ std::advance(new_processor, -1);
+ } else {
+ new_processor = update_processors_.begin();
+ }
+
+ (*new_processor)->SetReverbTimes(rt60_values);
+ (*new_processor)->SetGain(gain);
+
+ if (new_processor != update_processors_.begin()) {
+ auto list_item = update_processors_.begin();
+ std::advance(list_item, num_active_processors_);
+ if (list_item != new_processor) {
+ update_processors_.splice(list_item, update_processors_, new_processor,
+ std::next(new_processor));
+ }
+ ++num_active_processors_;
+ } else {
+ std::rotate(update_processors_.begin(),
+ std::next(update_processors_.begin()),
+ update_processors_.end());
+ }
+}
+
+void ReverbOnsetCompensator::GenerateCorrectionCurves() {
+ // Copy into the adder curves such that the memory is aligned.
+ std::copy(kLowCorrectionCurve, kLowCorrectionCurve + kCorrectionCurveLength,
+ adder_curves_[0].begin());
+ std::copy(kHighCorrectionCurve, kHighCorrectionCurve + kCorrectionCurveLength,
+ adder_curves_[1].begin());
+
+ // Evaluate the polynomials to generate the base curves. Here the 'low' and
+ // 'high' names refer to the reverberation times.
+ AudioBuffer::Channel* low_channel = &base_curves_[0];
+ AudioBuffer::Channel* high_channel = &base_curves_[1];
+ for (size_t i = 0; i < kCorrectionCurveLength; ++i) {
+ // Scaled independent variable (Allowed better conditioning).
+ const float conditioning_scalar =
+ (static_cast<float>(i) - kCurveOffset) * kCurveScale;
+ (*low_channel)[i] = kLowReverberationCorrectionCurve[0];
+ (*high_channel)[i] = kHighReverberationCorrectionCurve[0];
+ float power = conditioning_scalar;
+ for (size_t k = 1; k < kCurvePolynomialLength; ++k) {
+ (*low_channel)[i] += power * kLowReverberationCorrectionCurve[k];
+ (*high_channel)[i] += power * kHighReverberationCorrectionCurve[k];
+ power *= conditioning_scalar;
+ }
+ (*low_channel)[i] = std::max((*low_channel)[i], 0.0f);
+ (*high_channel)[i] = std::max((*high_channel)[i], 0.0f);
+ }
+}
+
+void ReverbOnsetCompensator::GenerateNoiseVectors() {
+ const size_t num_octave_bands = GetNumReverbOctaveBands(sampling_rate_);
+ const size_t noise_length = CeilToMultipleOfFramesPerBuffer(
+ kCorrectionCurveLength, frames_per_buffer_);
+ for (size_t band = 0; band < num_octave_bands; ++band) {
+ // Generate preset tail.
+ bandpassed_noise_left_.emplace_back(kNumMonoChannels, noise_length);
+ GenerateBandLimitedGaussianNoise(kOctaveBandCentres[band], sampling_rate_,
+ /*seed=*/1U,
+ &bandpassed_noise_left_[band]);
+ bandpassed_noise_right_.emplace_back(kNumMonoChannels, noise_length);
+ GenerateBandLimitedGaussianNoise(kOctaveBandCentres[band], sampling_rate_,
+ /*seed=*/2U,
+ &bandpassed_noise_right_[band]);
+
+ auto min_max = std::minmax_element(bandpassed_noise_left_[band][0].begin(),
+ bandpassed_noise_left_[band][0].end());
+ const float left_scale =
+ std::max(std::fabs(*min_max.first), std::fabs(*min_max.second));
+ min_max = std::minmax_element(bandpassed_noise_right_[band][0].begin(),
+ bandpassed_noise_right_[band][0].end());
+ const float right_scale =
+ std::max(std::fabs(*min_max.first), std::fabs(*min_max.second));
+
+ const float scale = std::max(left_scale, right_scale);
+
+ ScalarMultiply(noise_length, scale, bandpassed_noise_left_[band][0].begin(),
+ bandpassed_noise_left_[band][0].begin());
+ ScalarMultiply(noise_length, scale,
+ bandpassed_noise_right_[band][0].begin(),
+ bandpassed_noise_right_[band][0].begin());
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_compensator.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_compensator.h
new file mode 100644
index 000000000..4bf76f8f2
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_compensator.h
@@ -0,0 +1,110 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_REVERB_ONSET_COMPENSATOR_H_
+#define RESONANCE_AUDIO_DSP_REVERB_ONSET_COMPENSATOR_H_
+
+#include <list>
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "dsp/delay_filter.h"
+#include "dsp/fft_manager.h"
+#include "dsp/partitioned_fft_filter.h"
+#include "dsp/reverb_onset_update_processor.h"
+
+namespace vraudio {
+
+// Implements a convolutional compensator for the spectral reverb onset curve.
+class ReverbOnsetCompensator {
+ public:
+ // Constructs a |ReverbOnsetCompensator|.
+ //
+ // @param sampling_rate The sampling rate in Hz.
+ // @param frames_per_buffer The number of frames per buffer in the system.
+ // @param fft_manager Pointer to a FftManager to perform FFT transformations.
+ ReverbOnsetCompensator(int sampling_rate, size_t frames_per_buffer,
+ FftManager* fft_manager);
+
+ // Resets the reverb with a new set of reverberation times. The new tail is
+ // generated by replacing the current tail buffer by buffer.
+ //
+ // @param rt60_values |kNumReverbOctaveBands| values denoting the
+ // reverberation decay time to -60dB in octave bands starting at
+ // |kLowestOctaveBand|.
+ // @param gain Gain to be applied across all frequencies.
+ void Update(const float* rt60_values, float gain);
+
+ // Processes a mono |AudioBuffer| with a reverberant tail.
+ //
+ // @param input A mono |AudioBuffer| of input data.
+ // @param output Pointer to stereo output buffer.
+ void Process(const AudioBuffer& input, AudioBuffer* output);
+
+ private:
+ // Generates the constituent curves which are combined to make up the
+ // correction curve envelopes. These envelopes ensure the initial part of the
+ // specral reverb's impulse response, which exhibits 'growing' behaviour,
+ // follows the desired exponential decay.
+ void GenerateCorrectionCurves();
+
+ // Generates a pair of |kNumOctaveBands| band, octave filtered, noise buffers.
+ void GenerateNoiseVectors();
+
+ // Manager for all FFT related functionality (not owned).
+ FftManager* const fft_manager_;
+
+ // The system sampling rate.
+ const int sampling_rate_;
+
+ // The system number of frames per buffer.
+ const size_t frames_per_buffer_;
+
+ // Pre-generated band-passed noise to be used as a base for the reverb tail.
+ std::vector<AudioBuffer> bandpassed_noise_left_;
+ std::vector<AudioBuffer> bandpassed_noise_right_;
+
+ // The constituent curves used to generate the onset compensation envelopes.
+ AudioBuffer base_curves_;
+ AudioBuffer adder_curves_;
+
+ // Filter for processing the left reverberant channel.
+ PartitionedFftFilter left_filter_;
+
+ // Filter for processing the right reverberant channel.
+ PartitionedFftFilter right_filter_;
+
+ // Delay filter used to ensure the compensation curve starts at the same point
+ // as the spectral reverb.
+ DelayFilter delay_filter_;
+
+ // Number of active update processors.
+ size_t num_active_processors_;
+
+ // Active reverb update processors to replace the corresponding filter
+ // partitions of the reverb tail within each process call.
+ std::list<std::unique_ptr<ReverbOnsetUpdateProcessor>> update_processors_;
+
+ // Temporary buffer used to process filter kernel partitions.
+ AudioBuffer temp_kernel_buffer_;
+
+ // Temporary buffer to hold FFT frequency domain output.
+ PartitionedFftFilter::FreqDomainBuffer temp_freq_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_REVERB_ONSET_COMPENSATOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_update_processor.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_update_processor.cc
new file mode 100644
index 000000000..3a5dbcf02
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_update_processor.cc
@@ -0,0 +1,184 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/reverb_onset_update_processor.h"
+
+#include <algorithm>
+
+#include "base/constants_and_types.h"
+#include "base/simd_utils.h"
+#include "dsp/spectral_reverb_constants_and_tables.h"
+#include "dsp/utils.h"
+
+namespace vraudio {
+
+namespace {
+
+// Find the absolute difference between two size_t values.
+inline size_t absdiff(size_t lhs, size_t rhs) {
+ return lhs > rhs ? lhs - rhs : rhs - lhs;
+}
+
+} // namespace
+
+ReverbOnsetUpdateProcessor::ReverbOnsetUpdateProcessor(
+ size_t frames_per_buffer, int sampling_rate, AudioBuffer* base_curves,
+ AudioBuffer* adder_curves)
+ : sampling_rate_(sampling_rate),
+ tail_update_cursor_(0),
+ tail_length_(CeilToMultipleOfFramesPerBuffer(kCorrectionCurveLength,
+ frames_per_buffer)),
+ gain_(1.0f),
+ curve_indices_(GetNumReverbOctaveBands(sampling_rate_), kInvalidIndex),
+ pure_decay_coefficients_(curve_indices_.size(), 0.0f),
+ pure_decay_exponents_(curve_indices_.size(), 0.0f),
+ band_buffer_(kNumStereoChannels, frames_per_buffer),
+ envelope_buffer_(kNumMonoChannels, frames_per_buffer),
+ base_curves_(base_curves),
+ adder_curves_(adder_curves) {}
+
+void ReverbOnsetUpdateProcessor::SetReverbTimes(const float* rt60_values) {
+ DCHECK(rt60_values);
+ const size_t num_octave_bands = curve_indices_.size();
+ const float sampling_rate_float = static_cast<float>(sampling_rate_);
+ tail_update_cursor_ = 0;
+ // Choose curves for each band.
+ for (size_t band = 0; band < num_octave_bands; ++band) {
+ curve_indices_[band] =
+ GetFeedbackIndexFromRt60(rt60_values[band], sampling_rate_float);
+ // Deal with the case where only the convolution is needed.
+ if (curve_indices_[band] == kInvalidIndex) {
+ const float min_reverb_time =
+ kMinReverbTimeForFeedback48kHz *
+ (sampling_rate_float / kDefaultSpectralReverbSampleRate);
+ const float effective_rt =
+ rt60_values[band] <= min_reverb_time ? rt60_values[band] : 0.0f;
+ pure_decay_exponents_[band] =
+ std::abs(effective_rt) > kEpsilonFloat
+ ? std::exp(kNegativeLog1000 /
+ (sampling_rate_float * effective_rt))
+ : 0.0f;
+ pure_decay_coefficients_[band] = pure_decay_exponents_[band];
+ }
+ }
+}
+
+bool ReverbOnsetUpdateProcessor::Process(
+ const std::vector<AudioBuffer>& bandpassed_noise_left,
+ const std::vector<AudioBuffer>& bandpassed_noise_right,
+ AudioBuffer::Channel* kernel_channel_left,
+ AudioBuffer::Channel* kernel_channel_right) {
+ if (tail_update_cursor_ >= tail_length_) {
+ // Processing the reverb tail is finished.
+ tail_update_cursor_ = 0;
+ return false;
+ }
+ const size_t frames_per_buffer = band_buffer_.num_frames();
+ DCHECK(kernel_channel_left);
+ DCHECK(kernel_channel_right);
+ DCHECK_EQ(bandpassed_noise_left.size(), curve_indices_.size());
+ DCHECK_EQ(bandpassed_noise_right.size(), curve_indices_.size());
+ DCHECK_EQ(bandpassed_noise_left[0].num_frames(), tail_length_);
+ DCHECK_EQ(bandpassed_noise_right[0].num_frames(), tail_length_);
+ DCHECK_GE(tail_length_, kCorrectionCurveLength);
+ DCHECK_EQ(kernel_channel_left->size(), frames_per_buffer);
+ DCHECK_EQ(kernel_channel_right->size(), frames_per_buffer);
+
+ // Clear for accumulation per frequency band.
+ kernel_channel_left->Clear();
+ kernel_channel_right->Clear();
+
+ AudioBuffer::Channel& band_channel_left = band_buffer_[0];
+ AudioBuffer::Channel& band_channel_right = band_buffer_[1];
+ // Define the number of samples we are still able to copy from the multiplier
+ // and adder curves.
+ const size_t copy_length =
+ frames_per_buffer + tail_update_cursor_ <= kCorrectionCurveLength
+ ? frames_per_buffer
+ : absdiff(kCorrectionCurveLength, tail_update_cursor_);
+ AudioBuffer::Channel* envelope_channel = &envelope_buffer_[0];
+ // Compute the band buffer for each band response.
+ for (size_t band = 0; band < curve_indices_.size(); ++band) {
+ const AudioBuffer::Channel& noise_channel_left =
+ bandpassed_noise_left[band][0];
+ const AudioBuffer::Channel& noise_channel_right =
+ bandpassed_noise_right[band][0];
+ // Fill the band buffer with the next noise buffer and apply gain.
+ ScalarMultiply(frames_per_buffer, gain_,
+ noise_channel_left.begin() + tail_update_cursor_,
+ band_channel_left.begin());
+ ScalarMultiply(frames_per_buffer, gain_,
+ noise_channel_right.begin() + tail_update_cursor_,
+ band_channel_right.begin());
+ // Skip the band if we have an invalid index
+ const int curve_index = curve_indices_[band];
+ if (curve_index != kInvalidIndex) {
+ // Apply the correct compensation curve to the buffer.
+ const float scale = kCurveCorrectionMultipliers[curve_index];
+ AudioBuffer::Channel* adder_curve_channel;
+ if (tail_update_cursor_ < kCorrectionCurveLength) {
+ // Use either the high frequency or low frequency curve.
+ if (static_cast<size_t>(curve_index) >= kCurveChangeoverIndex) {
+ adder_curve_channel = &(*adder_curves_)[1];
+ std::copy_n((*base_curves_)[1].begin() + tail_update_cursor_,
+ copy_length, envelope_channel->begin());
+ } else {
+ adder_curve_channel = &(*adder_curves_)[0];
+ std::copy_n((*base_curves_)[0].begin() + tail_update_cursor_,
+ copy_length, envelope_channel->begin());
+ }
+ // Construct the correct envelope (chunk thereof).
+ ScalarMultiplyAndAccumulate(
+ copy_length, scale,
+ adder_curve_channel->begin() + tail_update_cursor_,
+ envelope_channel->begin());
+ // Ensure the end part of the envelope does not contain spurious data.
+ std::fill(envelope_channel->begin() + copy_length,
+ envelope_channel->end(), 0.0f);
+ } else {
+ // If we have moved past the length of the correction curve, fill the
+ // envelope chunk with zeros.
+ envelope_channel->Clear();
+ }
+
+ // Apply that envelope to the given band and accumulate into the output.
+ MultiplyAndAccumulatePointwise(
+ frames_per_buffer, envelope_channel->begin(),
+ band_channel_left.begin(), kernel_channel_left->begin());
+ MultiplyAndAccumulatePointwise(
+ frames_per_buffer, envelope_channel->begin(),
+ band_channel_right.begin(), kernel_channel_right->begin());
+ } else {
+ // If the decay time is too short for the spectral reverb to make a
+ // contribution (0.15s @48kHz), the compensation filter will consist of
+ // the entire tail.
+ for (size_t frame = 0; frame < frames_per_buffer; ++frame) {
+ (*kernel_channel_left)[frame] +=
+ pure_decay_coefficients_[band] * band_channel_left[frame];
+ (*kernel_channel_right)[frame] +=
+ pure_decay_coefficients_[band] * band_channel_right[frame];
+ // Update the decay coefficient.
+ pure_decay_coefficients_[band] *= pure_decay_exponents_[band];
+ }
+ }
+ }
+ // Update the cursor.
+ tail_update_cursor_ += frames_per_buffer;
+
+ return true;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_update_processor.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_update_processor.h
new file mode 100644
index 000000000..19fee4b42
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/reverb_onset_update_processor.h
@@ -0,0 +1,113 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_REVERB_ONSET_UPDATE_PROCESSOR_H_
+#define RESONANCE_AUDIO_DSP_REVERB_ONSET_UPDATE_PROCESSOR_H_
+
+#include <vector>
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Updater for the |ReverbOnsetCompensator|.
+class ReverbOnsetUpdateProcessor {
+ public:
+ // Constructs a update processor for the sprectral reverb onset compensator.
+ //
+ // @param frames_per_buffer_ System buffer length in frames.
+ // @param sampling_rate System sample rate.
+ // @param base_curves Constituent curve used for envelope generation.
+ // @param ader_curves Constituent curve used for envelope generation.
+ ReverbOnsetUpdateProcessor(size_t frames_per_buffer, int sampling_rate,
+ AudioBuffer* base_curves,
+ AudioBuffer* adder_curves);
+
+ // Sets reverberation times in different frequency bands.
+ //
+ // @param rt60_values |kNumReverbOctaveBands| values denoting the
+ // reverberation decay time to -60dB in octave bands starting at
+ // |kLowestOctaveBand|.
+ void SetReverbTimes(const float* rt60_values);
+
+ // Sets the gain applied to the overall compensation envelope.
+ //
+ // @param gain Gain applied to overall envelope.
+ void SetGain(float gain) { gain_ = gain; }
+
+ // Processes the next tail update.
+ //
+ // @param bandpassed_noise_left Pre-computed bandpassed noise buffer.
+ // @param bandpassed_noise_right Pre-computed bandpassed noise buffer.
+ // @param kernel_channel_left Kernel channel to fill in the processed output.
+ // @param kernel_channel_right Kernel channel to fill in the processed output.
+ // @return True if the tail update continues.
+ bool Process(const std::vector<AudioBuffer>& bandpassed_noise_left,
+ const std::vector<AudioBuffer>& bandpassed_noise_right,
+ AudioBuffer::Channel* kernel_channel_left,
+ AudioBuffer::Channel* kernel_channel_right);
+
+ // Returns the partition index of the current update state.
+ //
+ // @return Current partition index.
+ size_t GetCurrentPartitionIndex() const {
+ const size_t frames_per_buffer = band_buffer_.num_frames();
+ DCHECK_NE(frames_per_buffer, 0U);
+ return tail_update_cursor_ / frames_per_buffer;
+ }
+
+ // Disable copy and assignment operator.
+ ReverbOnsetUpdateProcessor(ReverbOnsetUpdateProcessor const&) = delete;
+ void operator=(ReverbOnsetUpdateProcessor const&) = delete;
+
+ private:
+ // System sample rate.
+ int sampling_rate_;
+
+ // Current frame position of the reverb tail to be updated.
+ size_t tail_update_cursor_;
+
+ // Length of the new reverb tail to be replaced in frames.
+ size_t tail_length_;
+
+ // Gain applied to the reverb compensation.
+ float gain_;
+
+ // Indices of the multiplication factor to be used to create the onset
+ // compensation curve at each frequency band.
+ std::vector<int> curve_indices_;
+
+ // Decay coefficients per each band of the reverb tail, used below 0.15s
+ // @48kHz.
+ std::vector<float> pure_decay_coefficients_;
+
+ // Decay exponential per each band of the reverb tail, used below 0.15s
+ // @48kHz.
+ std::vector<float> pure_decay_exponents_;
+
+ // Temporary buffers used to process the decayed noise per each band.
+ AudioBuffer band_buffer_;
+ AudioBuffer envelope_buffer_;
+
+ // Pointers to audio buffers owned by the |ReverbOnsetCompensator| storing the
+ // constituent curves used to generate the onset compensation envelopes.
+ AudioBuffer* base_curves_;
+ AudioBuffer* adder_curves_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_REVERB_ONSET_UPDATE_PROCESSOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/sh_hrir_creator.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/sh_hrir_creator.cc
new file mode 100644
index 000000000..11226a6fc
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/sh_hrir_creator.cc
@@ -0,0 +1,72 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/sh_hrir_creator.h"
+
+#include "third_party/SADIE_hrtf_database/generated/hrtf_assets.h"
+#include "ambisonics/utils.h"
+#include "base/logging.h"
+#include "dsp/resampler.h"
+#include "utils/planar_interleaved_conversion.h"
+
+namespace vraudio {
+
+std::unique_ptr<AudioBuffer> CreateShHrirsFromWav(const Wav& wav,
+ int target_sample_rate_hz,
+ Resampler* resampler) {
+ DCHECK(resampler);
+ const size_t num_channels = wav.GetNumChannels();
+ CHECK(IsValidAmbisonicOrder(num_channels));
+
+ const size_t sh_hrir_length = wav.interleaved_samples().size() / num_channels;
+ std::unique_ptr<AudioBuffer> sh_hrirs(
+ new AudioBuffer(num_channels, sh_hrir_length));
+ FillAudioBuffer(wav.interleaved_samples(), num_channels, sh_hrirs.get());
+
+ const int wav_sample_rate_hz = wav.GetSampleRateHz();
+ CHECK_GT(wav_sample_rate_hz, 0);
+ CHECK_GT(target_sample_rate_hz, 0);
+ if (wav_sample_rate_hz != target_sample_rate_hz) {
+ if (!Resampler::AreSampleRatesSupported(wav_sample_rate_hz,
+ target_sample_rate_hz)) {
+ LOG(FATAL) << "Unsupported sampling rates for loading HRIRs: "
+ << wav_sample_rate_hz << ", " << target_sample_rate_hz;
+ }
+ resampler->ResetState();
+ // Resample the SH HRIRs if necessary.
+ resampler->SetRateAndNumChannels(wav_sample_rate_hz, target_sample_rate_hz,
+ num_channels);
+ std::unique_ptr<AudioBuffer> resampled_sh_hrirs(new AudioBuffer(
+ num_channels, resampler->GetNextOutputLength(sh_hrir_length)));
+ resampler->Process(*sh_hrirs, resampled_sh_hrirs.get());
+ return resampled_sh_hrirs;
+ }
+ return sh_hrirs;
+}
+
+std::unique_ptr<AudioBuffer> CreateShHrirsFromAssets(
+ const std::string& filename, int target_sample_rate_hz,
+ Resampler* resampler) {
+ // Read SH HRIR from asset store.
+ sadie::HrtfAssets hrtf_assets;
+ std::unique_ptr<std::string> sh_hrir_data = hrtf_assets.GetFile(filename);
+ CHECK_NOTNULL(sh_hrir_data.get());
+ std::istringstream wav_data_stream(*sh_hrir_data);
+ std::unique_ptr<const Wav> wav = Wav::CreateOrNull(&wav_data_stream);
+ return CreateShHrirsFromWav(*wav, target_sample_rate_hz, resampler);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/sh_hrir_creator.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/sh_hrir_creator.h
new file mode 100644
index 000000000..5a11926f5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/sh_hrir_creator.h
@@ -0,0 +1,54 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_SH_HRIR_CREATOR_H_
+#define RESONANCE_AUDIO_DSP_SH_HRIR_CREATOR_H_
+
+#include "base/audio_buffer.h"
+#include "dsp/resampler.h"
+#include "utils/wav.h"
+
+namespace vraudio {
+
+// Creates a multichannel audio buffer of Spherical Harmonic-encoded Head
+// Related Impulse Responses (SH HRIRs) from Wav SH HRIR assets. It also
+// checks if the channel count of the SH HRIR file is correct and resamples the
+// SH HRIRs if necessary to match the system (target) sampling rate.
+//
+// @param wav |Wav| instance that contains SH HRIRs.
+// @param target_sample_rate_hz Target sampling rate in Hertz.
+// @param resampler Pointer to a resampler used to convert HRIRs to the system
+// rate,
+// (This resampler's internal state will be reset on each function call).
+// @return Unique pointer to |AudioBuffer| where the SH HRIRs will be written.
+std::unique_ptr<AudioBuffer> CreateShHrirsFromWav(const Wav& wav,
+ int target_sample_rate_hz,
+ Resampler* resampler);
+
+// Creates a SH HRIR multichannel audio buffer from assets.
+//
+// @param filename Name of the Wav file that contains SH HRIRs.
+// @param target_sample_rate_hz Target sampling rate in Hertz.
+// @param resampler Pointer to a resampler used to convert HRIRs to the system
+// rate.
+// @return Unique pointer to |AudioBuffer| where the SH HRIRs will be written.
+std::unique_ptr<AudioBuffer> CreateShHrirsFromAssets(
+ const std::string& filename, int target_sample_rate_hz,
+ Resampler* resampler);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_SH_HRIR_CREATOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room.cc
new file mode 100644
index 000000000..769166248
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room.cc
@@ -0,0 +1,61 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/shoe_box_room.h"
+
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+void ComputeReflections(const WorldPosition& relative_listener_position,
+ const WorldPosition& room_dimensions,
+ const float* reflection_coefficients,
+ std::vector<Reflection>* reflections) {
+ DCHECK(reflection_coefficients);
+ DCHECK(reflections);
+ DCHECK_EQ(reflections->size(), kNumRoomSurfaces);
+ const WorldPosition kOrigin(0.0f, 0.0f, 0.0f);
+ if (!IsPositionInAabb(relative_listener_position, kOrigin, room_dimensions)) {
+ // Listener is outside the room, skip computation.
+ std::fill(reflections->begin(), reflections->end(), Reflection());
+ return;
+ }
+ // Calculate the distance of the listener to each wall.
+ // Since all the sources are 'attached' to the listener in the computation
+ // of reflections, the distance travelled is arbitrary. So, we add 1.0f to
+ // the computed distance in order to avoid delay time approaching 0 and the
+ // magnitude approaching +inf.
+ const WorldPosition offsets = 0.5f * room_dimensions;
+ const float distances_travelled[kNumRoomSurfaces] = {
+ offsets[0] + relative_listener_position[0] + 1.0f,
+ offsets[0] - relative_listener_position[0] + 1.0f,
+ offsets[1] + relative_listener_position[1] + 1.0f,
+ offsets[1] - relative_listener_position[1] + 1.0f,
+ offsets[2] + relative_listener_position[2] + 1.0f,
+ offsets[2] - relative_listener_position[2] + 1.0f};
+
+ for (size_t i = 0; i < kNumRoomSurfaces; ++i) {
+ // Convert distances to time delays in seconds.
+ (*reflections)[i].delay_time_seconds =
+ distances_travelled[i] / kSpeedOfSound;
+ // Division by distance is performed here as we don't want this applied more
+ // than once.
+ (*reflections)[i].magnitude =
+ reflection_coefficients[i] / distances_travelled[i];
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room.h
new file mode 100644
index 000000000..eab514922
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room.h
@@ -0,0 +1,44 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_SHOE_BOX_ROOM_H_
+#define RESONANCE_AUDIO_DSP_SHOE_BOX_ROOM_H_
+
+#include <vector>
+
+#include "base/misc_math.h"
+#include "dsp/reflection.h"
+
+namespace vraudio {
+
+// Computes a set of reflections from each surface of a shoe-box room model.
+// Uses a simplified calculation method which assumes that all the sources are
+// 'attached' to the listener. Also, assumes that the listener is inside the
+// shoe-box room.
+//
+// @param relative_listener_position Relative listener position to the center of
+// the room.
+// @param room_dimensions Dimensions of the room.
+// @param reflection_coefficients Reflection coefficients.
+// @return List of computed reflections by the image source method.
+void ComputeReflections(const WorldPosition& relative_listener_position,
+ const WorldPosition& room_dimensions,
+ const float* reflection_coefficients,
+ std::vector<Reflection>* reflections);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_SHOE_BOX_ROOM_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room_test.cc
new file mode 100644
index 000000000..78393604f
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/shoe_box_room_test.cc
@@ -0,0 +1,96 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/shoe_box_room.h"
+
+#include <algorithm>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// Expected reflection delay times in seconds.
+const float kExpectedDelays[kNumRoomSurfaces] = {
+ 0.011661f, 0.005830f, 0.016035f, 0.004373f, 0.020408f, 0.002915f};
+
+// Expected reflection magnitudes.
+const float kExpectedMagnitudes[kNumRoomSurfaces] = {
+ 0.25f, 0.5f, 0.181818f, 0.666666f, 0.142857f, 1.0f};
+
+// Tests that a set of single reflections arrive in from the correct directions.
+TEST(ShoeBoxRoomTest, SingleReflectionsTest) {
+ const WorldPosition kListenerPosition(1.0f, 2.0f, 3.0f);
+ const WorldPosition kRoomDimensions(4.0f, 5.0f, 6.0f);
+
+ // Perform the simplified image source method with the wall at the given index
+ // having a reflection coefficient of 1 and all of the other walls having a
+ // reflection coefficient of 0. Thus we expect one reflection in the output
+ // and we should be able to predict its magnitude, delay and direction of
+ // arrival in terms of azimuth and elevation.
+ float reflection_coefficients[kNumRoomSurfaces];
+ std::fill(std::begin(reflection_coefficients),
+ std::end(reflection_coefficients), 0.0f);
+ std::vector<Reflection> reflections(kNumRoomSurfaces);
+ for (size_t index = 0; index < kNumRoomSurfaces; ++index) {
+ reflection_coefficients[index] = 1.0f;
+
+ ComputeReflections(kListenerPosition, kRoomDimensions,
+ reflection_coefficients, &reflections);
+ EXPECT_EQ(kNumRoomSurfaces, reflections.size());
+
+ // Check that the correct reflection is returned for the given call.
+ size_t num_returned = 0;
+ for (size_t i = 0; i < kNumRoomSurfaces; ++i) {
+ if (reflections[i].magnitude > 0.0f) {
+ EXPECT_NEAR(kExpectedDelays[index], reflections[i].delay_time_seconds,
+ kEpsilonFloat);
+ EXPECT_NEAR(kExpectedMagnitudes[index], reflections[i].magnitude,
+ kEpsilonFloat);
+ ++num_returned;
+ }
+ }
+ EXPECT_EQ(1U, num_returned);
+
+ // Reset so that all reflection reflection_coefficients are 0.0f again.
+ reflection_coefficients[index] = 0.0f;
+ }
+}
+
+// Tests that no reflections arrive when the listener is outside the room.
+TEST(ShoeBoxRoomTest, ReflectionsOutsideRoomTest) {
+ const WorldPosition kListenerPosition(4.0f, 5.0f, 6.0f);
+ const WorldPosition kRoomDimensions(1.0f, 2.0f, 3.0f);
+ const float kReflectionCoefficients[] = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
+
+ std::vector<Reflection> reflections(kNumRoomSurfaces);
+ ComputeReflections(kListenerPosition, kRoomDimensions,
+ kReflectionCoefficients, &reflections);
+ EXPECT_EQ(kNumRoomSurfaces, reflections.size());
+
+ // Check that all the reflections have zeros.
+ for (size_t i = 0; i < kNumRoomSurfaces; ++i) {
+ EXPECT_NEAR(0.0f, reflections[i].delay_time_seconds, kEpsilonFloat);
+ EXPECT_NEAR(0.0f, reflections[i].magnitude, kEpsilonFloat);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb.cc
new file mode 100644
index 000000000..e03d34ccd
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb.cc
@@ -0,0 +1,350 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "dsp/spectral_reverb.h"
+
+#include <algorithm>
+#include <cstdlib>
+#include <numeric>
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/simd_utils.h"
+#include "dsp/spectral_reverb_constants_and_tables.h"
+#include "dsp/utils.h"
+
+namespace vraudio {
+
+namespace {
+
+// FFT length and length of time domain data processed.
+const size_t kFftSize = 4096;
+
+// Length of magnitude and phase buffers.
+const size_t kMagnitudeLength = kFftSize / 2 + 1;
+
+// Number of overlaps per kFftSize time domain chunk of input.
+const size_t kNumOverlap = 4;
+
+// Number of samples per overlap.
+const size_t kOverlapLength = kFftSize / kNumOverlap;
+
+// Three quarters FFT size, used for copying chunks of input.
+const size_t kThreeQuarterFftSize = kFftSize - kOverlapLength;
+
+// Number of channels needed to overlap add output data.
+const size_t kNumQuadChannels = 4;
+
+// Number of buffers of delay applies to the magnitude spectrum.
+const size_t kMagnitudeDelay = 3;
+
+// Length of a buffer of noise used to provide random phase.
+const size_t kNoiseLength = 16384;
+
+// Length of the noise buffer from which a phase buffer can start.
+const size_t kAvailableNoiselength = kNoiseLength - kMagnitudeLength;
+
+// Returns a random integer in the range provided. Used to index into the random
+// buffer for phase values.
+inline size_t GetRandomIntegerInRange(size_t min, size_t max) {
+ DCHECK_GE(max, min);
+ return min + static_cast<size_t>(std::rand()) % (max - min);
+}
+
+} // namespace
+
+SpectralReverb::SpectralReverb(int sample_rate, size_t frames_per_buffer)
+ : sample_rate_(sample_rate),
+ frames_per_buffer_(frames_per_buffer),
+ magnitude_delay_index_(0),
+ overlap_add_index_(0),
+ fft_manager_(kFftSize / 2),
+ sin_cos_random_phase_buffer_(kNumStereoChannels, kNoiseLength),
+ unscaled_window_(kNumMonoChannels, kFftSize),
+ window_(kNumMonoChannels, kFftSize),
+ feedback_(kNumMonoChannels, kMagnitudeLength),
+ magnitude_compensation_(kNumMonoChannels, kMagnitudeLength),
+ magnitude_delay_(kMagnitudeDelay, kMagnitudeLength),
+ fft_size_input_(kNumMonoChannels, kFftSize),
+ input_circular_buffer_(kFftSize + frames_per_buffer_, frames_per_buffer_,
+ kOverlapLength),
+ output_circular_buffers_(kNumStereoChannels),
+ out_time_buffer_(kNumQuadChannels, kFftSize),
+ temp_freq_buffer_(kNumStereoChannels, kFftSize),
+ scaled_magnitude_buffer_(kNumMonoChannels, kMagnitudeLength),
+ temp_magnitude_buffer_(kNumMonoChannels, kMagnitudeLength),
+ temp_phase_buffer_(kNumStereoChannels, kMagnitudeLength),
+ output_accumulator_(kNumStereoChannels),
+ is_gain_near_zero_(false),
+ is_feedback_near_zero_(false) {
+ DCHECK_GT(sample_rate, 0);
+ DCHECK_GT(frames_per_buffer_, 0U);
+
+ // Seed std::rand, used for phase selection.
+ std::srand(1);
+ GenerateRandomPhaseBuffer();
+ GenerateAnalysisWindow();
+ InitializeCircularBuffersAndAccumulators();
+ fft_size_input_.Clear();
+ magnitude_compensation_.Clear();
+}
+
+void SpectralReverb::SetGain(float gain) {
+ DCHECK_GE(gain, 0.0f);
+ ScalarMultiply(window_.num_frames(), gain, &unscaled_window_[0][0],
+ &window_[0][0]);
+ // If the gain is less than -60dB we will bypass all processing.
+ is_gain_near_zero_ = gain <= kNegative60dbInAmplitude;
+ // If we are to bypass processing we clear the circular buffer so that we
+ // don't process old input when the spectral reverb is restarted.
+ if (is_gain_near_zero_ || is_feedback_near_zero_) {
+ input_circular_buffer_.Clear();
+ }
+}
+
+void SpectralReverb::SetRt60PerOctaveBand(const float* rt60_values) {
+ DCHECK(rt60_values);
+ const float sample_rate_float = static_cast<float>(sample_rate_);
+ // Fill the entries in the feedback channel with the feedback values up to
+ // that frequency. The feedback channels entries are per frequency in the same
+ // way as the magnitude vectors. Also fill the magnitude compensation vector
+ // such that the peak value at each frequency for any given reverberation time
+ // will be |kDefaultReverbGain|.
+ AudioBuffer::Channel* feedback_channel = &feedback_[0];
+ feedback_channel->Clear();
+ AudioBuffer::Channel* magnitude_compensation_channel =
+ &magnitude_compensation_[0];
+ magnitude_compensation_channel->Clear();
+ const float frequency_step = sample_rate_float / static_cast<float>(kFftSize);
+ int index = GetFeedbackIndexFromRt60(rt60_values[0], sample_rate_float);
+ float current_feedback =
+ index == kInvalidIndex ? 0.0f : kSpectralReverbFeedback[index];
+ float magnitude_compensation_value =
+ index == kInvalidIndex ? 0.0f : kMagnitudeCompensation[index];
+ const size_t max_frequency_bin =
+ std::min(static_cast<size_t>(
+ (kOctaveBandCentres[kNumReverbOctaveBands - 1] * kSqrtTwo) /
+ frequency_step),
+ feedback_channel->size());
+ // The upper edge of the octave band is sqrt(2) * centre_frequency :
+ // https://en.wikipedia.org/wiki/Octave_band#Octave_Bands
+ float upper_octave_band_edge = kOctaveBandCentres[0] * kSqrtTwo;
+ for (size_t i = 0, j = 0; i < max_frequency_bin; ++i) {
+ const float current_freq = static_cast<float>(i) * frequency_step;
+ if (current_freq > upper_octave_band_edge) {
+ ++j;
+ DCHECK_LT(j, kNumReverbOctaveBands);
+ upper_octave_band_edge = kOctaveBandCentres[j] * kSqrtTwo;
+ index = GetFeedbackIndexFromRt60(rt60_values[j], sample_rate_float);
+ current_feedback =
+ index == kInvalidIndex ? 0.0f : kSpectralReverbFeedback[index];
+ magnitude_compensation_value =
+ index == kInvalidIndex ? 0.0f : kMagnitudeCompensation[index];
+ }
+ (*feedback_channel)[i] = current_feedback;
+ (*magnitude_compensation_channel)[i] = magnitude_compensation_value;
+ }
+ // If the sum of all feedback values is below the minimum feedback value, it
+ // is safe to assume we can bypass the spectral reverb entirely.
+ is_feedback_near_zero_ =
+ std::accumulate(feedback_channel->begin(), feedback_channel->end(),
+ 0.0f) < kSpectralReverbFeedback[0];
+ // If we are to bypass processing we clear the circular buffer so that we
+ // don't process old input when the spectral reverb is restarted.
+ if (is_gain_near_zero_ || is_feedback_near_zero_) {
+ input_circular_buffer_.Clear();
+ }
+}
+
+void SpectralReverb::Process(const AudioBuffer::Channel& input,
+ AudioBuffer::Channel* left_out,
+ AudioBuffer::Channel* right_out) {
+ DCHECK_EQ(input.size(), left_out->size());
+ DCHECK_EQ(input.size(), right_out->size());
+ DCHECK_EQ(input.size(), frames_per_buffer_);
+
+
+ if (is_gain_near_zero_ || is_feedback_near_zero_) {
+ left_out->Clear();
+ right_out->Clear();
+ return;
+ }
+
+ // Here we insert |frames_per_buffer_| samples on each function call. Then,
+ // once there are |kOverlapLength| samples in the input circular buffer we
+ // retrieve |kOverlapLength| samples from it and process |kFftSize| samples of
+ // input at a time, sliding along by |kOverlapLength| samples. We then place
+ // |kOverlapLength| samples into the output buffer and we will extract
+ // |frames_per_buffer_| samples from the output buffer on each function call.
+ input_circular_buffer_.InsertBuffer(input);
+ while (input_circular_buffer_.GetOccupancy() >= kOverlapLength) {
+ std::copy_n(&fft_size_input_[0][kOverlapLength], kThreeQuarterFftSize,
+ &fft_size_input_[0][0]);
+ input_circular_buffer_.RetrieveBufferWithOffset(kThreeQuarterFftSize,
+ &fft_size_input_[0]);
+ fft_manager_.FreqFromTimeDomain(fft_size_input_[0], &temp_freq_buffer_[0]);
+ fft_manager_.GetCanonicalFormatFreqBuffer(temp_freq_buffer_[0],
+ &temp_freq_buffer_[1]);
+ fft_manager_.MagnitudeFromCanonicalFreqBuffer(temp_freq_buffer_[1],
+ &scaled_magnitude_buffer_[0]);
+ // Apply the magnitude compensation to the input magnitude spectrum before
+ // feedback is applied.
+ MultiplyPointwise(kMagnitudeLength, magnitude_compensation_[0].begin(),
+ scaled_magnitude_buffer_[0].begin(),
+ scaled_magnitude_buffer_[0].begin());
+ // Generate time domain reverb blocks.
+ GetNextReverbBlock(magnitude_delay_index_, &out_time_buffer_[0],
+ &out_time_buffer_[1]);
+ magnitude_delay_index_ = (magnitude_delay_index_ + 1) % kMagnitudeDelay;
+ GetNextReverbBlock(magnitude_delay_index_, &out_time_buffer_[2],
+ &out_time_buffer_[3]);
+
+ // Combine the reverb blocks for both left and right output.
+ AddPointwise(kFftSize, out_time_buffer_[0].begin(),
+ out_time_buffer_[2].begin(), out_time_buffer_[0].begin());
+ AddPointwise(kFftSize, out_time_buffer_[1].begin(),
+ out_time_buffer_[3].begin(), out_time_buffer_[1].begin());
+
+ // Window the left and right output (While applying inverse FFT scaling).
+ MultiplyPointwise(kFftSize, out_time_buffer_[0].begin(), window_[0].begin(),
+ out_time_buffer_[0].begin());
+ MultiplyPointwise(kFftSize, out_time_buffer_[1].begin(), window_[0].begin(),
+ out_time_buffer_[1].begin());
+
+ // Next perform the addition and the submission into the output buffer.
+ AccumulateOverlap(0 /*channel*/, out_time_buffer_[0]);
+ AccumulateOverlap(1 /*channel*/, out_time_buffer_[1]);
+ overlap_add_index_ = (overlap_add_index_ + 1) % kNumOverlap;
+ }
+ output_circular_buffers_[0]->RetrieveBuffer(left_out);
+ output_circular_buffers_[1]->RetrieveBuffer(right_out);
+}
+
+void SpectralReverb::AccumulateOverlap(size_t channel_index,
+ const AudioBuffer::Channel& buffer) {
+ // Use a modulo indexed multi channel audio buffer with each channel of length
+ // |kOverlapLength| to perform an overlap add.
+ for (size_t i = 0, index = overlap_add_index_; i < kNumOverlap;
+ ++i, index = (index + 1) % kNumOverlap) {
+ float* accumulator_start_point =
+ output_accumulator_[channel_index][index].begin();
+ AddPointwise(kOverlapLength, buffer.begin() + i * kOverlapLength,
+ accumulator_start_point, accumulator_start_point);
+ }
+ output_circular_buffers_[channel_index]->InsertBuffer(
+ output_accumulator_[channel_index][overlap_add_index_]);
+ output_accumulator_[channel_index][overlap_add_index_].Clear();
+}
+
+void SpectralReverb::GenerateAnalysisWindow() {
+ // Genarate a pseudo tukey window from three overlapping hann windows, scaled
+ // by the inverse fft scale.
+ AudioBuffer::Channel* window_channel = &window_[0];
+ // Use the unscaled window buffer as temporary storage.
+ GenerateHannWindow(true /* full */, kMagnitudeLength, &unscaled_window_[0]);
+ float* hann_window = &unscaled_window_[0][0];
+ // Scale the hann window such that the sum of three will have unity peak.
+ const float kThreeQuarters = 0.75f;
+ ScalarMultiply(kMagnitudeLength, kThreeQuarters, hann_window, hann_window);
+ for (size_t offset = 0; offset < kThreeQuarterFftSize;
+ offset += kOverlapLength) {
+ float* tripple_hann_window = &(*window_channel)[offset];
+ AddPointwise(kMagnitudeLength, hann_window, tripple_hann_window,
+ tripple_hann_window);
+ }
+ fft_manager_.ApplyReverseFftScaling(window_channel);
+ unscaled_window_[0] = *window_channel;
+}
+
+void SpectralReverb::GenerateRandomPhaseBuffer() {
+ AudioBuffer::Channel* sin_phase_channel = &sin_cos_random_phase_buffer_[0];
+ AudioBuffer::Channel* cos_phase_channel = &sin_cos_random_phase_buffer_[1];
+ // Initially use the sin channel to store the random data before taking sine
+ // and cosine.
+ GenerateUniformNoise(/*min=*/0.0f, /*max=*/kPi, /*seed=*/1U,
+ sin_phase_channel);
+ for (size_t i = 0; i < sin_cos_random_phase_buffer_.num_frames(); ++i) {
+
+ (*cos_phase_channel)[i] = std::cos((*sin_phase_channel)[i]);
+ (*sin_phase_channel)[i] = std::sin((*sin_phase_channel)[i]);
+ }
+}
+
+void SpectralReverb::GetNextReverbBlock(size_t delay_index,
+ AudioBuffer::Channel* left_channel,
+ AudioBuffer::Channel* right_channel) {
+ DCHECK(left_channel);
+ DCHECK(right_channel);
+
+ // Generate reverb magnitude by combining the delayed magnitude with the
+ // current magnitude.
+ AudioBuffer::Channel* temp_magnitude_channel = &temp_magnitude_buffer_[0];
+ *temp_magnitude_channel = scaled_magnitude_buffer_[0];
+ MultiplyAndAccumulatePointwise(
+ kMagnitudeLength, magnitude_delay_[delay_index].begin(),
+ feedback_[0].begin(), temp_magnitude_channel->begin());
+ // Reinsert this new reverb magnitude into the delay buffer.
+ magnitude_delay_[delay_index] = *temp_magnitude_channel;
+
+ for (size_t i = 0; i < kNumStereoChannels; ++i) {
+ // Extract a random phase buffer.
+ const size_t random_offset =
+ GetRandomIntegerInRange(0, kAvailableNoiselength);
+ // We gaurantee an aligned offset as when SSE is used we need it.
+ const size_t phase_offset = FindNextAlignedArrayIndex(
+ random_offset, sizeof(float), kMemoryAlignmentBytes);
+ // Convert from magnitude and phase to a time domain output.
+ fft_manager_.CanonicalFreqBufferFromMagnitudeAndSinCosPhase(
+ phase_offset, (*temp_magnitude_channel),
+ sin_cos_random_phase_buffer_[0], sin_cos_random_phase_buffer_[1],
+ &temp_freq_buffer_[0]);
+
+ AudioBuffer::Channel* out_channel = i == 0 ? left_channel : right_channel;
+ fft_manager_.GetPffftFormatFreqBuffer(temp_freq_buffer_[0],
+ &temp_freq_buffer_[1]);
+ fft_manager_.TimeFromFreqDomain(temp_freq_buffer_[1], out_channel);
+ }
+}
+
+void SpectralReverb::InitializeCircularBuffersAndAccumulators() {
+ AudioBuffer zeros(kNumMonoChannels, kOverlapLength);
+ zeros.Clear();
+ for (size_t channel = 0; channel < kNumStereoChannels; ++channel) {
+ // Prefill the |output_circular_buffers_| with |kOverlapLength| /
+ // |frames_per_buffer_| calls worth of zeros.
+ output_circular_buffers_[channel].reset(
+ new CircularBuffer(kOverlapLength + frames_per_buffer_, kOverlapLength,
+ frames_per_buffer_));
+ // Due to differences in the |frames_per_buffer_| used for input and output
+ // and |kOverlapLength| used for processing, a certain number of buffers of
+ // zeros must be inserted into the output buffers such that enough input can
+ // build up to process |kOverlapLength| worth, and enough output will build
+ // up to return |frames_per_buffer_| worth.
+ const size_t zeroed_buffers_of_output = kOverlapLength / frames_per_buffer_;
+ for (size_t i = 0; i < zeroed_buffers_of_output; ++i) {
+ output_circular_buffers_[channel]->InsertBuffer(zeros[0]);
+ }
+ output_accumulator_[channel] = AudioBuffer(kNumOverlap, kOverlapLength);
+ output_accumulator_[channel].Clear();
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb.h
new file mode 100644
index 000000000..0734772e0
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb.h
@@ -0,0 +1,173 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_SPECTRAL_REVERB_H_
+#define RESONANCE_AUDIO_DSP_SPECTRAL_REVERB_H_
+
+#include <memory>
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "dsp/circular_buffer.h"
+#include "dsp/fft_manager.h"
+
+namespace vraudio {
+
+// Implements a spectral reverb producing a decorrelated stereo output. See:
+// [1] E. Vickers, J-L Wu, P.G. Krishnan, R. N. K. Sadanandam, "Frequency Domain
+// Artificial Reverberation using Spectral Magnitude Decay",
+// https://goo.gl/hv1pdJ.
+class SpectralReverb {
+ public:
+ // Constructs a spectral reverb.
+ //
+ // @param sample_rate The system sample rate.
+ // @param frames_per_buffer System frames per buffer of input and output.
+ // Note that this class expects power of two buffers of input and output.
+ SpectralReverb(int sample_rate, size_t frames_per_buffer);
+
+ // Sets the overall gain to be applied to the output of the reverb.
+ //
+ // @param gain Gain to be applied to the reverb output, min value 0.0f.
+ void SetGain(float gain);
+
+ // Sets the |SpectralReverb|'s reverberation times in different frequency
+ // bands. Supports times between:
+ // (0.15 * 48000 / |sample_rate|)s and (25 * 48000 / |sample_rate|)s.
+ //
+ // @param rt60_values |kNumReverbOctaveBands| values denoting the
+ // reverberation decay time to -60dB in octave bands starting at
+ // |kLowestOctaveBand|.
+ void SetRt60PerOctaveBand(const float* rt60_values);
+
+ // Applies reverb to an input channel of audio data and produces a stereo
+ // output.
+ //
+ // @param input Mono inpu data.
+ // @param left_out Left channel of reverberated output.
+ // @param right_out Right channel of reverberated output.
+ void Process(const AudioBuffer::Channel& input,
+ AudioBuffer::Channel* left_out, AudioBuffer::Channel* right_out);
+
+ private:
+ // Uses an AudioBuffer with four channels to overlap add and insert the final
+ // reverb into the output circular buffers.
+ //
+ // @param channel_index Denotes the (left or right) channel to output to.
+ // @param buffer The buffer to be added onto the pre-existing reverb output.
+ void AccumulateOverlap(size_t channel_index,
+ const AudioBuffer::Channel& buffer);
+
+ // Generates a window function which is a normalized sum of three overlapping
+ // (50%) hann windows of length (|kFftSize| / 2) that also incorporates the
+ // inverse fft scaling.
+ void GenerateAnalysisWindow();
+
+ // Generates a large buffer of sines and cosines of random noise between 0 and
+ // pi to be randomly indexed into in order to cheaply generate highly
+ // decorrelated phase buffers,
+ void GenerateRandomPhaseBuffer();
+
+ // Obtains the next stero pair of time domain reverb blocks which can then be
+ // summed together in an overlap add fashion to provide the reverb output.
+ //
+ // @param delay_index An index into the frequency domain magnitude ring
+ // buffer.
+ // @param left_channel Channel to contain the left partial reverb output.
+ // @param right_channel Channel to contain the right partial reverb output.
+ void GetNextReverbBlock(size_t delay_index,
+ AudioBuffer::Channel* left_channel,
+ AudioBuffer::Channel* right_channel);
+
+ // Initializes the output circular buffers such that they contain zeros if the
+ // value of |frames_per_buffer_| is sufficiently smaller than that of
+ // |kOverlapLength| that buffering of input will be required prior to
+ // processing. Also allocates memory for the output accumulators.
+ void InitializeCircularBuffersAndAccumulators();
+
+ // System sample rate.
+ const int sample_rate_;
+
+ // System frames per buffer.
+ const size_t frames_per_buffer_;
+
+ // Indices into the magnitude and overlap add delay lines, modulo of their
+ // respective lengths.
+ size_t magnitude_delay_index_;
+ size_t overlap_add_index_;
+
+ // Manages the time-frequency transforms and phase/magnitude-frequency
+ // transforms.
+ FftManager fft_manager_;
+
+ // Buffer containing sines and cosines of random values between 0 and pi to be
+ // used for phase.
+ AudioBuffer sin_cos_random_phase_buffer_;
+
+ // Buffer containing a triple overlapping hann window for windowing time
+ // domain data.
+ AudioBuffer unscaled_window_;
+
+ // Buffer containing a triple overlapping hann window for windowing time
+ // domain data, this window has been scaled by the output gain factor.
+ AudioBuffer window_;
+
+ // Buffer containing RT60 tuned feedback values.
+ AudioBuffer feedback_;
+
+ // Buffer used to store scaling values which account for the different initial
+ // peak magnitudes for different RT60s.
+ AudioBuffer magnitude_compensation_;
+
+ // Buffer that acts as the frequency domain magnitde delay.
+ AudioBuffer magnitude_delay_;
+
+ // Buffer to contain a linear |kFftSize| chunk of input data.
+ AudioBuffer fft_size_input_;
+
+ // Circular buffers to sit at the input and output of the |Process()| method
+ // to allow |frames_per_buffer_| to differ from |kFftSize|.
+ CircularBuffer input_circular_buffer_;
+ std::vector<std::unique_ptr<CircularBuffer>> output_circular_buffers_;
+
+ // Time domain buffer used to store reverb before the overlap add operation.
+ AudioBuffer out_time_buffer_;
+
+ // Temporary frequency domain buffer, used to store frequency domain data when
+ // transforming between Pffft and Canonical format frequency domain data.
+ AudioBuffer temp_freq_buffer_;
+
+ // Buffer used to store feedback scaled magnitude values.
+ AudioBuffer scaled_magnitude_buffer_;
+
+ // Buffer used for the accumulation of scaled magnitude buffers.
+ AudioBuffer temp_magnitude_buffer_;
+
+ // Buffer used to store randomized phase.
+ AudioBuffer temp_phase_buffer_;
+
+ // Buffers used to calculate the overlap add at the output.
+ std::vector<AudioBuffer> output_accumulator_;
+
+ // Processing of the spectral reverb is bypassed when the feedback values are
+ // all approximately zero OR when the gain is set to near zero.
+ bool is_gain_near_zero_;
+ bool is_feedback_near_zero_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_SPECTRAL_REVERB_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb_constants_and_tables.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb_constants_and_tables.h
new file mode 100644
index 000000000..84329f329
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb_constants_and_tables.h
@@ -0,0 +1,6508 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_SPECTRAL_REVERB_CONSTANTS_AND_TABLES_H_
+#define RESONANCE_AUDIO_DSP_SPECTRAL_REVERB_CONSTANTS_AND_TABLES_H_
+
+#include <algorithm>
+#include <cstddef>
+
+namespace vraudio {
+
+// Sampling rate for which the spectral reverb feedback coefficients are
+// calculated.
+static const float kDefaultSpectralReverbSampleRate = 48000.0f;
+
+// Minimum reverb time supported by the feedback table below (seconds).
+static const float kMinReverbTimeForFeedback48kHz = 0.15f;
+
+// Step size between each reverberation time supported by the feedback table
+// (seconds).
+static const float kTimeStepSizeForFeedback48kHz = 0.01f;
+
+// Number of entries in the feedback table below.
+static const size_t kNumFeedbackValues = 2485;
+
+// Value denoting an invalid index into the feedback and magnitude correction
+// tables. The feedback and magnitude correction factors will be 0.0 when this
+// value is returned from the index lookup method.
+const int kInvalidIndex = -1;
+
+// Number of frames of zeros before the reverb onset curve.
+const size_t kCompensationOnsetLength = 1024;
+
+// Length in samples of the spectral reverb onset correction curves.
+const size_t kCorrectionCurveLength = 6144;
+
+// Index of the feedback factor and curve multipliers. below which the low
+// frequency correction curves must be used.
+const size_t kCurveChangeoverIndex = 51;
+
+// Offset and scaling values for the compensation curve polynomials. Used to
+// ensure the polynomial fitting was well conditioned.
+const float kCurveOffset = 3584.5f;
+const float kCurveScale = 0.00027897893709025f;
+
+// Number of coefficients in the curve generation polynomials.
+const size_t kCurvePolynomialLength = 5;
+
+// Coefficients of the curves making up the first part of the compensation
+// envelopes, split into low and high frequency part.
+const float kHighReverberationCorrectionCurve[kCurvePolynomialLength] = {
+ 0.207891278205479f, -0.32101050261694f, 0.124608132159297f,
+ 0.0119620847734548f, -0.0093840571415877f};
+
+const float kLowReverberationCorrectionCurve[kCurvePolynomialLength] = {
+ 0.0277040197264401f, -0.0394421854392145f, 0.0519110103856154f,
+ -0.0778183422829366f, 0.0343221444553963f};
+
+// Offset from zero for indexing into the feedback array.
+const size_t kReverbLookupOffset = static_cast<size_t>(
+ kMinReverbTimeForFeedback48kHz / kTimeStepSizeForFeedback48kHz);
+
+// Returns an index to the feedback factor corresponding to the given
+// reverberation time. Supports times between:
+// (0.15 * 48000 / |sample_rate|)s and (25 * 48000 / |sample_rate|)s.
+//
+// @param reverberation_time RT60 in seconds.
+// @return Index to the closest spectral reverb feedback factor in
+// |kSpectralReverbFeedback|, or |kInvalidIndex| if |reverberation_time|
+// is too small.
+static inline int GetFeedbackIndexFromRt60(float reverberation_time,
+ float sample_rate) {
+ // Scaling factor on reverb times applied due to current |sample_rate|. All
+ // feedback factors calculated correspond to 48kHz.
+ const float scale_factor = sample_rate / kDefaultSpectralReverbSampleRate;
+ if (reverberation_time * scale_factor < kMinReverbTimeForFeedback48kHz) {
+ return kInvalidIndex;
+ }
+ return static_cast<int>(
+ std::min(kNumFeedbackValues - 1,
+ static_cast<size_t>((reverberation_time * scale_factor) /
+ kTimeStepSizeForFeedback48kHz) -
+ kReverbLookupOffset));
+}
+
+// Mapping between reverberation times at a given frequency and the
+// corresponding feedback value required in the specral reverb. This table
+// covers reverberation times between kMinReverbTimeForFeedback and
+// kNumFeedbackValues * kTimeStepSizeForFeedback, i.e. 0.15s and 25s @48kHz.
+static const float kSpectralReverbFeedback[kNumFeedbackValues] = {
+ 0.231626448720861f, 0.231626448720861f, 0.271965742827169f,
+ 0.291599040391330f, 0.313450848869688f, 0.332864905289138f,
+ 0.350285532738638f, 0.366049684043223f, 0.383143567924904f,
+ 0.398574170268545f, 0.427500186399158f, 0.441038795823222f,
+ 0.453430889363735f, 0.466397294153677f, 0.478272702354267f,
+ 0.490519904155818f, 0.501757394995813f, 0.512125955040727f,
+ 0.521739757418252f, 0.548135448526531f, 0.548135448526531f,
+ 0.563990087718933f, 0.571497329505391f, 0.578784680803617f,
+ 0.585892965998708f, 0.592858971592466f, 0.599714945736390f,
+ 0.606488097764666f, 0.613200097727167f, 0.619866575922435f,
+ 0.626496622430680f, 0.633092286646765f, 0.639648076813205f,
+ 0.646150459553150f, 0.652577359403386f, 0.658897658347319f,
+ 0.665070695347976f, 0.671045765880981f, 0.676761621467567f,
+ 0.682145969207546f, 0.682145969207546f, 0.687114971312322f,
+ 0.691572744637866f, 0.695410860217716f, 0.700728670360266f,
+ 0.701931035813262f, 0.700570291691920f, 0.718477641957808f,
+ 0.718477641957808f, 0.721948612036913f, 0.725341703212013f,
+ 0.728658944837357f, 0.731902322614612f, 0.735073779107144f,
+ 0.738175214254303f, 0.741208485885712f, 0.744175410235544f,
+ 0.747077762456819f, 0.749917277135678f, 0.752695648805674f,
+ 0.755414532462056f, 0.758075544076055f, 0.760680261109167f,
+ 0.763230223027440f, 0.765726931815758f, 0.768171852492127f,
+ 0.770566413621959f, 0.772912007832361f, 0.775209992326414f,
+ 0.777461689397460f, 0.779668386943394f, 0.781831338980938f,
+ 0.783951766159935f, 0.786030856277629f, 0.788069764792952f,
+ 0.790069615340812f, 0.792031500246373f, 0.793956481039341f,
+ 0.795845588968255f, 0.797699825514762f, 0.799520162907914f,
+ 0.801307544638442f, 0.803062885973050f, 0.804787074468694f,
+ 0.806480970486870f, 0.808145407707900f, 0.809781193645214f,
+ 0.811389110159637f, 0.812969913973676f, 0.814524337185802f,
+ 0.816053087784737f, 0.817556850163737f, 0.819036285634880f,
+ 0.820492032943351f, 0.821924708781723f, 0.823334908304248f,
+ 0.824723205641138f, 0.826090154412852f, 0.827436288244380f,
+ 0.828762121279528f, 0.830068148695207f, 0.831354847215712f,
+ 0.833872075291032f, 0.835103470659940f, 0.836317269790432f,
+ 0.837513864858018f, 0.838693632671302f, 0.841004120020598f,
+ 0.841004120020598f, 0.842135520967878f, 0.843251458511968f,
+ 0.844352240341239f, 0.846509506717154f, 0.847566547291731f,
+ 0.848609545235926f, 0.849638751975006f, 0.850654409224479f,
+ 0.851656749504368f, 0.852645996653501f, 0.853622366343797f,
+ 0.854586066594550f, 0.855537298286716f, 0.856476255677194f,
+ 0.857403126913115f, 0.858318094546124f, 0.859221336046671f,
+ 0.860113024318288f, 0.860993328211881f, 0.861862413040010f,
+ 0.862720441091179f, 0.863567572144118f, 0.864403963982066f,
+ 0.865229772907064f, 0.866045154254231f, 0.866850262906056f,
+ 0.867645253806680f, 0.868430282476178f, 0.869205505524854f,
+ 0.869971081167516f, 0.870727169737766f, 0.871473934202282f,
+ 0.872211540675109f, 0.872940158931938f, 0.873659962924396f,
+ 0.874371131294327f, 0.875073847888079f, 0.876454690240667f,
+ 0.877133214343288f, 0.877804084385866f, 0.878467517951544f,
+ 0.879123740913686f, 0.879772987950149f, 0.880415503057582f,
+ 0.881051540065697f, 0.881681363151570f, 0.882305247353907f,
+ 0.882923479087349f, 0.883536356656744f, 0.884144190771436f,
+ 0.884747305059551f, 0.885346036582283f, 0.885940736348172f,
+ 0.886531769827401f, 0.887119517466070f, 0.887704375200491f,
+ 0.888286754971462f, 0.888867085238566f, 0.889355868225441f,
+ 0.889898852584961f, 0.890436987253855f, 0.890970321870216f,
+ 0.891498905661491f, 0.892022787446309f, 0.892542015636295f,
+ 0.893056638237894f, 0.893566702854191f, 0.894072256686731f,
+ 0.894573346537340f, 0.895070018809945f, 0.895562319512397f,
+ 0.896533988268773f, 0.897013446374392f, 0.897488713016890f,
+ 0.897959832251035f, 0.898426847746442f, 0.898889802789393f,
+ 0.899348740284655f, 0.899803702757303f, 0.900254732354541f,
+ 0.900701870847520f, 0.901145159633161f, 0.901584639735976f,
+ 0.902020351809884f, 0.902452336140039f, 0.902880632644642f,
+ 0.903305280876771f, 0.903726320026192f, 0.904143788921187f,
+ 0.904557726030372f, 0.904968169464516f, 0.905375156978364f,
+ 0.905778725972456f, 0.906178913494948f, 0.906575756243433f,
+ 0.906969290566763f, 0.907359552466865f, 0.907746577600566f,
+ 0.908130401281413f, 0.908511058481491f, 0.908888583833246f,
+ 0.909263011631306f, 0.909634375834297f, 0.910002710066671f,
+ 0.910368047620521f, 0.910730421457403f, 0.911446408184725f,
+ 0.911800085361980f, 0.912150927399534f, 0.912498965633569f,
+ 0.912844231080653f, 0.913186754439560f, 0.913526566093093f,
+ 0.913863696109903f, 0.914198174246311f, 0.914530029948127f,
+ 0.914859292352470f, 0.915185990289593f, 0.915510152284696f,
+ 0.915831806559755f, 0.916150981035335f, 0.916467703332418f,
+ 0.916782000774218f, 0.917093900388001f, 0.917403428906911f,
+ 0.917710612771787f, 0.918015478132983f, 0.918318050852190f,
+ 0.918916420379010f, 0.919212267483073f, 0.919505922541691f,
+ 0.919797410000546f, 0.920086754027583f, 0.920373978514824f,
+ 0.920659107080196f, 0.920942163069346f, 0.921223169557465f,
+ 0.921502149351104f, 0.921779124990001f, 0.922054118748897f,
+ 0.922327152639358f, 0.922598248411594f, 0.922867427556284f,
+ 0.923134711306391f, 0.923400120638986f, 0.923663676277069f,
+ 0.923925398691385f, 0.924185308102252f, 0.924443424481376f,
+ 0.924699767553671f, 0.924954356799086f, 0.925207211454416f,
+ 0.925458350515133f, 0.925707792737198f, 0.925955556638886f,
+ 0.926201660502607f, 0.926446122376723f, 0.926688960077372f,
+ 0.926930191190288f, 0.927169833072619f, 0.927407902854752f,
+ 0.927644417442129f, 0.927879393517071f, 0.928112847540597f,
+ 0.928344795754244f, 0.928575254181890f, 0.928804238631573f,
+ 0.929031764697310f, 0.929257847760921f, 0.929705745358969f,
+ 0.929927589612438f, 0.930148050305480f, 0.930367141786232f,
+ 0.930584878201552f, 0.930801273498844f, 0.931016341427878f,
+ 0.931230095542612f, 0.931442549203009f, 0.931653715576860f,
+ 0.931863607641606f, 0.932072238186154f, 0.932279619812703f,
+ 0.932485764938561f, 0.932690685797968f, 0.932894394443911f,
+ 0.933096902749953f, 0.933298222412048f, 0.933498364950364f,
+ 0.933697341711099f, 0.933895163868310f, 0.934091842425725f,
+ 0.934287388218568f, 0.934481811915380f, 0.934675124019838f,
+ 0.934867334872576f, 0.935058454653005f, 0.935437460919395f,
+ 0.935625366974452f, 0.935812221099035f, 0.935998032693751f,
+ 0.936182811008910f, 0.936182811008910f, 0.936366565146343f,
+ 0.936731036563891f, 0.936911771321662f, 0.937091516860660f,
+ 0.937270281567636f, 0.937448073691783f, 0.937624901346560f,
+ 0.937800772511514f, 0.937975695034098f, 0.938149676631492f,
+ 0.938322724892425f, 0.938494847278995f, 0.938666051128488f,
+ 0.938836343655203f, 0.939005731952265f, 0.939174222993452f,
+ 0.939341823635016f, 0.939508540617498f, 0.939674380567555f,
+ 0.939839349999772f, 0.940003455318495f, 0.940166702819640f,
+ 0.940329098692519f, 0.940490649021660f, 0.940651359788628f,
+ 0.940811236873844f, 0.940970286058407f, 0.941128513025914f,
+ 0.941285923364282f, 0.941442522567564f, 0.941598316037775f,
+ 0.941753309086713f, 0.941907506937771f, 0.942060914727768f,
+ 0.942213537508766f, 0.942365380249885f, 0.942516447839133f,
+ 0.942666745085221f, 0.942816276719382f, 0.942965047397198f,
+ 0.943113061700413f, 0.943260324138759f, 0.943406839151775f,
+ 0.943552611110629f, 0.943697644319934f, 0.943841943019572f,
+ 0.944128353536651f, 0.944270473526585f, 0.944411875355484f,
+ 0.944552562966882f, 0.944692540250507f, 0.944831811044098f,
+ 0.944970379135229f, 0.945108248263126f, 0.945245422120492f,
+ 0.945381904355324f, 0.945517698572732f, 0.945652808336767f,
+ 0.945787237172233f, 0.945920988566514f, 0.946054065971390f,
+ 0.946186472804861f, 0.946318212452965f, 0.946449288271601f,
+ 0.946579703588348f, 0.946709461704285f, 0.946838565895813f,
+ 0.946967019416476f, 0.947094825498780f, 0.947221987356014f,
+ 0.947348508184070f, 0.947474391163268f, 0.947599639460168f,
+ 0.947724256229401f, 0.947848244615479f, 0.947971607754624f,
+ 0.948016355753743f, 0.948131749028067f, 0.948256528604491f,
+ 0.948381070023128f, 0.948495820690419f, 0.948619906515573f,
+ 0.948734238085242f, 0.948857871450992f, 0.948971786801436f,
+ 0.949094970810335f, 0.949208472791043f, 0.949321777358027f,
+ 0.949444301946475f, 0.949557197308729f, 0.949669897241678f,
+ 0.949782402382633f, 0.949894713365863f, 0.950016165228152f,
+ 0.950128073740068f, 0.950239790030961f, 0.950351314722867f,
+ 0.950462648434873f, 0.950573791783135f, 0.950684745380899f,
+ 0.950786286676309f, 0.950896878289179f, 0.951007281923720f,
+ 0.951117498181945f, 0.951227527663044f, 0.951328224451603f,
+ 0.951437897607799f, 0.951547385718536f, 0.951647587765244f,
+ 0.951756722847544f, 0.952281634952469f, 0.952380709437317f,
+ 0.952479632641358f, 0.952587376840327f, 0.952685985134598f,
+ 0.952784443487780f, 0.952891682098038f, 0.952989828324488f,
+ 0.953087825932233f, 0.953185675345440f, 0.953283376986503f,
+ 0.953380931276052f, 0.953478338632963f, 0.953584434118178f,
+ 0.953681535598181f, 0.953778491429264f, 0.953875302023227f,
+ 0.953963185967004f, 0.954059720427442f, 0.954156110839052f,
+ 0.954252357607017f, 0.954348461134851f, 0.954444421824404f,
+ 0.954627224309327f, 0.954627224309327f, 0.954722771738916f,
+ 0.954818177885333f, 0.954999925992284f, 0.955086293022387f,
+ 0.955181163332660f, 0.955267288091851f, 0.955361892609296f,
+ 0.955447776377266f, 0.955542116504091f, 0.955627760550641f,
+ 0.955721837678226f, 0.955807243263361f, 0.955892535735487f,
+ 0.955986227146404f, 0.956071282999438f, 0.956156226611782f,
+ 0.956241058262726f, 0.956334244095430f, 0.956418841531991f,
+ 0.956503327866496f, 0.956587703374087f, 0.956671968328910f,
+ 0.956756123004115f, 0.956840167671866f, 0.956924102603339f,
+ 0.957007928068733f, 0.957091644337270f, 0.957175251677203f,
+ 0.957258750355817f, 0.957342140639439f, 0.957425422793436f,
+ 0.957508597082225f, 0.957591663769275f, 0.957666332005129f,
+ 0.957749194971355f, 0.957831951094582f, 0.957914600634626f,
+ 0.957988894306034f, 0.958071342050505f, 0.958153683960035f,
+ 0.958227701401528f, 0.958309842929826f, 0.958383680442363f,
+ 0.958465622508191f, 0.958539280915875f, 0.958621024431827f,
+ 0.958694504553236f, 0.958776050425793f, 0.958849353074026f,
+ 0.958930702203609f, 0.959003828186335f, 0.959076870765751f,
+ 0.959157931586863f, 0.959230798681224f, 0.959303582928693f,
+ 0.959384357364767f, 0.959456967296096f, 0.959529494931521f,
+ 0.959601940447006f, 0.959674304017958f, 0.959746585819239f,
+ 0.959826803241069f, 0.959898912989265f, 0.959970941508314f,
+ 0.960042888970841f, 0.960114755548935f, 0.960186541414150f,
+ 0.960258246737504f, 0.960329871689484f, 0.960401416440053f,
+ 0.960472881158639f, 0.960544266014151f, 0.960607652309644f,
+ 0.960678886771683f, 0.960750041855675f, 0.960821117728505f,
+ 0.960892114556548f, 0.960955156623649f, 0.961026004596989f,
+ 0.961096774003302f, 0.961167465006980f, 0.961230235767696f,
+ 0.961300779124251f, 0.961433815192630f, 0.961433815192630f,
+ 0.961504133859284f, 0.961566574305389f, 0.961636746788933f,
+ 0.961699057549504f, 0.961769084422862f, 0.961901147838506f,
+ 0.961963200748498f, 0.961963200748498f, 0.962032938107125f,
+ 0.962094862846269f, 0.962164456293847f, 0.962226253361271f,
+ 0.962287990519784f, 0.962357373349702f, 0.962418983565341f,
+ 0.962480534213617f, 0.962611132054796f, 0.962672497254291f,
+ 0.962733803332908f, 0.962795050398145f, 0.962863882940590f,
+ 0.962925004958022f, 0.962986068296167f, 0.963047073061348f,
+ 0.963108019359607f, 0.963168907296701f, 0.963229736978111f,
+ 0.963290508509035f, 0.963351221994394f, 0.963411877538831f,
+ 0.963472475246711f, 0.963533015222125f, 0.963593497568891f,
+ 0.963653922390548f, 0.963714289790367f, 0.963774599871346f,
+ 0.963834852736211f, 0.963895048487418f, 0.963947672999015f,
+ 0.964007761937330f, 0.964067794055055f, 0.964127769453608f,
+ 0.964187688234142f, 0.964240070801961f, 0.964299883695432f,
+ 0.964359640260232f, 0.964471532344270f, 0.964531127521006f,
+ 0.964583227407251f, 0.964642717773864f, 0.964642717773864f,
+ 0.964702152384023f, 0.964813442340238f, 0.964865310872176f,
+ 0.964924537272103f, 0.964976315013494f, 0.965035437824303f,
+ 0.965035437824303f, 0.965146144638393f, 0.965197741696581f,
+ 0.965256658352829f, 0.965308165515470f, 0.965366979602982f,
+ 0.965418397165533f, 0.965469773015420f, 0.965528437277655f,
+ 0.965528437277655f, 0.965630969126429f, 0.965689484282883f,
+ 0.965740640709502f, 0.965791755822677f, 0.965842829685402f,
+ 0.965901149384097f, 0.965952135064471f, 0.966003079691463f,
+ 0.966053983327487f, 0.966104846034818f, 0.966155667875590f,
+ 0.966213700018171f, 0.966264434496339f, 0.966315128302334f,
+ 0.966365781497721f, 0.966416394143929f, 0.966466966302251f,
+ 0.966517498033843f, 0.966567989399724f, 0.966618440460782f,
+ 0.966668851277767f, 0.966719221911296f, 0.966769552421851f,
+ 0.966819842869783f, 0.966870093315306f, 0.966920303818505f,
+ 0.966970474439330f, 0.967020605237600f, 0.967063542843005f,
+ 0.967113599843356f, 0.967163617191341f, 0.967213594946271f,
+ 0.967263533167330f, 0.967306305935844f, 0.967356170893433f,
+ 0.967405996485532f, 0.967505529807874f, 0.967548138931234f,
+ 0.967597813233595f, 0.967647448454308f, 0.967689961867422f,
+ 0.967739524661887f, 0.967789048540268f, 0.967831466648599f,
+ 0.967880918407252f, 0.967923274783712f, 0.967972654620856f,
+ 0.968021995812854f, 0.968064257548057f, 0.968113527121939f,
+ 0.968155727554356f, 0.968204925706321f, 0.968247065003786f,
+ 0.968296191929245f, 0.968338270258917f, 0.968387326152496f,
+ 0.968429343680863f, 0.968478328736411f, 0.968520285629296f,
+ 0.968562214592319f, 0.968611096462447f, 0.968652965031151f,
+ 0.968701776537117f, 0.968743584875698f, 0.968785365470961f,
+ 0.968834074480683f, 0.968875795084627f, 0.968917488055148f,
+ 0.968959153426817f, 0.969007728191248f, 0.969090912086360f,
+ 0.969132462833532f, 0.969180904050232f, 0.969222395427913f,
+ 0.969263859458335f, 0.969305296175547f, 0.969346705613531f,
+ 0.969394982191855f, 0.969436332641141f, 0.969477655918411f,
+ 0.969518952057392f, 0.969560221091750f, 0.969601463055090f,
+ 0.969642677980956f, 0.969683865902829f, 0.969725026854133f,
+ 0.969766160868228f, 0.969807267978414f, 0.969848348217932f,
+ 0.969889401619961f, 0.969930428217621f, 0.969971428043973f,
+ 0.970012401132016f, 0.970053347514690f, 0.970094267224876f,
+ 0.970135160295395f, 0.970176026759010f, 0.970216866648424f,
+ 0.970257679996279f, 0.970298466835163f, 0.970339227197601f,
+ 0.970373173964662f, 0.970413885871233f, 0.970454571393199f,
+ 0.970495230562863f, 0.970535863412469f, 0.970650847168530f,
+ 0.970691379422253f, 0.970731885510953f, 0.970765620620724f,
+ 0.970806078823052f, 0.970846510950618f, 0.970886917035171f,
+ 0.970920568901195f, 0.970960927322491f, 0.971001259790416f,
+ 0.971034850377613f, 0.971075135346213f, 0.971115394450634f,
+ 0.971148923969595f, 0.971189135737796f, 0.971222625853735f,
+ 0.971262790390816f, 0.971302929209645f, 0.971336358601896f,
+ 0.971376450351361f, 0.971409840562608f, 0.971449885346942f,
+ 0.971483236463907f, 0.971523234387005f, 0.971556546496124f,
+ 0.971596497661541f, 0.971629770848972f, 0.971669675359932f,
+ 0.971702909711553f, 0.971742767670943f, 0.971775963272355f,
+ 0.971809141288259f, 0.971848931719255f, 0.971921815239525f,
+ 0.971954916087967f, 0.971987999445650f, 0.972027676411655f,
+ 0.972060721351105f, 0.972093748855591f, 0.972133358871293f,
+ 0.972166348080007f, 0.972199319909290f, 0.972238863187940f,
+ 0.972271796843339f, 0.972304713174582f, 0.972344189928433f,
+ 0.972377068207112f, 0.972409929216652f, 0.972442772974193f,
+ 0.972482162734699f, 0.972514968598050f, 0.972547757264083f,
+ 0.972580528749833f, 0.972613283072310f, 0.972646020248501f,
+ 0.972685282250713f, 0.972717981764744f, 0.972750664186678f,
+ 0.972783329533400f, 0.972815977821766f, 0.972848609068610f,
+ 0.972881223290743f, 0.972920337908315f, 0.972952914735131f,
+ 0.972985474590863f, 0.973018017492218f, 0.973050543455880f,
+ 0.973083052498507f, 0.973115544636735f, 0.973148019887177f,
+ 0.973180478266418f, 0.973212919791023f, 0.973245344477530f,
+ 0.973277752342457f, 0.973310143402295f, 0.973342517673512f,
+ 0.973374875172553f, 0.973407215915839f, 0.973439539919767f,
+ 0.973471847200711f, 0.973504137775022f, 0.973562218760164f,
+ 0.973594462642685f, 0.973626689880490f, 0.973658900489817f,
+ 0.973691094486881f, 0.973723271887874f, 0.973755432708964f,
+ 0.973787576966297f, 0.973813280457093f, 0.973845394940276f,
+ 0.973877492904786f, 0.973909574366681f, 0.973941639341995f,
+ 0.973967279462671f, 0.973999314802478f, 0.974031333700481f,
+ 0.974063336172629f, 0.974088926334435f, 0.974120899280163f,
+ 0.974152855844570f, 0.974184796043519f, 0.974210336430194f,
+ 0.974242247211220f, 0.974274141671084f, 0.974299645498340f,
+ 0.974331510619852f, 0.974363359464321f, 0.974388826830985f,
+ 0.974420646416359f, 0.974452449768633f, 0.974477880773140f,
+ 0.974509654945262f, 0.974541412928054f, 0.974566807668448f,
+ 0.974598536549719f, 0.974630249285257f, 0.974655607859195f,
+ 0.974687291571531f, 0.974712626946994f, 0.974744281686313f,
+ 0.974769593903399f, 0.974801219719758f, 0.974826508818462f,
+ 0.974858105761792f, 0.974889686686078f, 0.974914939902112f,
+ 0.974946492030788f, 0.974971722230190f, 0.975003245612865f,
+ 0.975028452835272f, 0.975053649858377f, 0.975085131806375f,
+ 0.975110305909561f, 0.975141759232295f, 0.975166910454954f,
+ 0.975198335201602f, 0.975223463583028f, 0.975254859802644f,
+ 0.975279965382029f, 0.975305060839729f, 0.975336415939985f,
+ 0.975361488652084f, 0.975392815344700f, 0.975417865350151f,
+ 0.975442905276238f, 0.975474191021417f, 0.975499208296949f,
+ 0.975524215518001f, 0.975555460416840f, 0.975605419639930f,
+ 0.975605419639930f, 0.975636623793157f, 0.975661575850883f,
+ 0.975686517903629f, 0.975711449958978f, 0.975742600980867f,
+ 0.975767510569758f, 0.975792410185843f, 0.975823520693185f,
+ 0.975848397898037f, 0.975898122470337f, 0.975922969852819f,
+ 0.975922969852819f, 0.975954015123685f, 0.976003655334843f,
+ 0.976028460584524f, 0.976053255940233f, 0.976084236232837f,
+ 0.976109009354376f, 0.976133772606159f, 0.976158525995621f,
+ 0.976183269530186f, 0.976208003217274f, 0.976208003217274f,
+ 0.976238906489402f, 0.976263618046739f, 0.976288319780646f,
+ 0.976313011698507f, 0.976362366115577f, 0.976387028629510f,
+ 0.976411681356846f, 0.976436324304925f, 0.976467114249117f,
+ 0.976467114249117f, 0.976491735220672f, 0.976516346436775f,
+ 0.976565539631852f, 0.976590121625417f, 0.976614693892712f,
+ 0.976639256441014f, 0.976663809277591f, 0.976688352409702f,
+ 0.976712885844598f, 0.976737409589524f, 0.976761923651714f,
+ 0.976761923651714f, 0.976786428038397f, 0.976810922756793f,
+ 0.976835407814114f, 0.976859883217562f, 0.976884348974336f,
+ 0.976908805091622f, 0.976933251576602f, 0.976957688436448f,
+ 0.977098013951529f, 0.977122386028731f, 0.977146748536122f,
+ 0.977171101480806f, 0.977195444869879f, 0.977213696145079f,
+ 0.977238022828887f, 0.977262339976560f, 0.977286647595167f,
+ 0.977310945691766f, 0.977335234273410f, 0.977353444469693f,
+ 0.977377716417114f, 0.977401978868934f, 0.977426231832178f,
+ 0.977450475313860f, 0.977474709320991f, 0.977492878612876f,
+ 0.977517096056381f, 0.977541304044568f, 0.977565502584416f,
+ 0.977583645293024f, 0.977607827315053f, 0.977631999907899f,
+ 0.977631999907899f, 0.977674279277313f, 0.977698425975728f,
+ 0.977722563270990f, 0.977722563270990f, 0.977764780932182f,
+ 0.977788892404450f, 0.977812994499489f, 0.977831064921111f,
+ 0.977855150622588f, 0.977879226965781f, 0.977897278085939f,
+ 0.977921338068673f, 0.977945388712013f, 0.977963420569662f,
+ 0.977987454885549f, 0.978011479880872f, 0.978029492514857f,
+ 0.978053501215636f, 0.978077500614628f, 0.978095494063675f,
+ 0.978119477200933f, 0.978137458461494f, 0.978161425357848f,
+ 0.978185382983022f, 0.978203345121770f, 0.978227286538691f,
+ 0.978245236529027f, 0.978269161758424f, 0.978293077747100f,
+ 0.978311008678442f, 0.978334908512089f, 0.978352827334900f,
+ 0.978376711034146f, 0.978394617763882f, 0.978418485349318f,
+ 0.978436380001407f, 0.978460231493585f, 0.978478114083426f,
+ 0.978501949502858f, 0.978519820045822f, 0.978543639412983f,
+ 0.978561497924412f, 0.978585301259738f, 0.978603147754944f,
+ 0.978626935078835f, 0.978644769573101f, 0.978668540905916f,
+ 0.978686363414501f, 0.978710118776561f, 0.978727929314691f,
+ 0.978751668726282f, 0.978769467309155f, 0.978793190790523f,
+ 0.978810977433311f, 0.978828758963556f, 0.978852459722509f,
+ 0.978870229334292f, 0.978893914212034f, 0.978911671920457f,
+ 0.978929424532057f, 0.978953086757244f, 0.978970827487009f,
+ 0.978994473879778f, 0.979012202742743f, 0.979029926524532f,
+ 0.979053550334292f, 0.979071262270710f, 0.979088969135123f,
+ 0.979112570402636f, 0.979130265443050f, 0.979147955420607f,
+ 0.979171534186528f, 0.979189212361401f, 0.979206885482540f,
+ 0.979230441787417f, 0.979248103127132f, 0.979265759422211f,
+ 0.979289293306483f, 0.979306937841341f, 0.979324577340638f,
+ 0.979348088844638f, 0.979365716604861f, 0.979383339338575f,
+ 0.979400957048490f, 0.979424439518260f, 0.979442045516508f,
+ 0.979459646499977f, 0.979477242471370f, 0.979500695974660f,
+ 0.979518280261699f, 0.979535859545650f, 0.979553433829205f,
+ 0.979576858433533f, 0.979594421059955f, 0.979611978694939f,
+ 0.979629531341168f, 0.979647079001324f, 0.979670468130047f,
+ 0.979688004166443f, 0.979723061310450f, 0.979740582423400f,
+ 0.979763936178014f, 0.979763936178014f, 0.979781445700440f,
+ 0.979816449859165f, 0.979833944500784f, 0.979851434187449f,
+ 0.979874746066551f, 0.979874746066551f, 0.979909697391286f,
+ 0.979927165637130f, 0.979944628942151f, 0.979962087308993f,
+ 0.979979540740298f, 0.979996989238702f, 0.980020246234401f,
+ 0.980037683232959f, 0.980055115307399f, 0.980072542460351f,
+ 0.980089964694443f, 0.980107382012301f, 0.980124794416549f,
+ 0.980142201909809f, 0.980159604494699f, 0.980177002173838f,
+ 0.980194394949842f, 0.980211782825323f, 0.980229165802893f,
+ 0.980252335491858f, 0.980269707051114f, 0.980287073721149f,
+ 0.980304435504567f, 0.980321792403967f, 0.980339144421948f,
+ 0.980356491561107f, 0.980373833824038f, 0.980391171213333f,
+ 0.980408503731583f, 0.980425831381378f, 0.980443154165302f,
+ 0.980460472085940f, 0.980477785145876f, 0.980495093347688f,
+ 0.980512396693956f, 0.980529695187255f, 0.980546988830161f,
+ 0.980564277625245f, 0.980581561575078f, 0.980598840682228f,
+ 0.980616114949261f, 0.980627628439596f, 0.980644894645466f,
+ 0.980662156018053f, 0.980679412559917f, 0.980696664273614f,
+ 0.980713911161699f, 0.980731153226725f, 0.980748390471244f,
+ 0.980765622897805f, 0.980782850508954f, 0.980800073307237f,
+ 0.980817291295196f, 0.980845977259090f, 0.980863182431940f,
+ 0.980880382803776f, 0.980897578377130f, 0.980914769154535f,
+ 0.980931955138521f, 0.980931955138521f, 0.980949136331616f,
+ 0.980966312736347f, 0.980994929443608f, 0.981012093091701f,
+ 0.981012093091701f, 0.981029251960675f, 0.981046406053047f,
+ 0.981063555371332f, 0.981109263565884f, 0.981126395400670f,
+ 0.981126395400670f, 0.981143522473080f, 0.981172057017508f,
+ 0.981189171402487f, 0.981206281034263f, 0.981223385915333f,
+ 0.981240486048191f, 0.981251883500099f, 0.981268975724811f,
+ 0.981286063207956f, 0.981303145952021f, 0.981320223959493f,
+ 0.981331606667595f, 0.981348676786265f, 0.981365742174963f,
+ 0.981382802836166f, 0.981394173985141f, 0.981411226772692f,
+ 0.981428274839352f, 0.981445318187591f, 0.981456677799626f,
+ 0.981473713289321f, 0.981490744067179f, 0.981507770135665f,
+ 0.981519118232888f, 0.981536136457894f, 0.981553149980093f,
+ 0.981564489716769f, 0.981581495406417f, 0.981598496399810f,
+ 0.981615492699399f, 0.981626820959334f, 0.981643809441364f,
+ 0.981660793236125f, 0.981672113163134f, 0.981689089151212f,
+ 0.981706060458539f, 0.981717372064213f, 0.981734335575712f,
+ 0.981751294412966f, 0.981762597708870f, 0.981779548761129f,
+ 0.981796495145636f, 0.981807790143312f, 0.981824728753634f,
+ 0.981841662702683f, 0.981852949413651f, 0.981869875599303f,
+ 0.981886797130148f, 0.981898075565905f, 0.981914989344119f,
+ 0.981926262613694f, 0.981943168645996f, 0.981960070033971f,
+ 0.981971335046964f, 0.981988228699756f, 0.982005117714653f,
+ 0.982016374482499f, 0.982033255772922f, 0.982044507393347f,
+ 0.982061380965979f, 0.982089493304948f, 0.982106354542990f,
+ 0.982117592800940f, 0.982134446338523f, 0.982145679465052f,
+ 0.982162525308829f, 0.982179366539510f, 0.982190591464981f,
+ 0.982207425012481f, 0.982218644818040f, 0.982235470688987f,
+ 0.982246685379053f, 0.982263503580068f, 0.982274713159051f,
+ 0.982291523696748f, 0.982302728169054f, 0.982319531050036f,
+ 0.982330730420066f, 0.982347525650929f, 0.982364316294885f,
+ 0.982375507510410f, 0.982392290514783f, 0.982403476639445f,
+ 0.982420252010811f, 0.982431433048991f, 0.982448200793916f,
+ 0.982459376749988f, 0.982476136875028f, 0.982487307753362f,
+ 0.982498476601823f, 0.982515226070027f, 0.982526389846857f,
+ 0.982543131710882f, 0.982554290420436f, 0.982571024686812f,
+ 0.982582178333442f, 0.982598905008691f, 0.982610053596740f,
+ 0.982626772687374f, 0.982637916221183f, 0.982654627733708f,
+ 0.982665766217610f, 0.982676902682761f, 0.982693603596846f,
+ 0.982704735018149f, 0.982721428369703f, 0.982732554751479f,
+ 0.982749240546979f, 0.982760361893543f, 0.982771481227230f,
+ 0.982788156455121f, 0.982799270759628f, 0.982815938446979f,
+ 0.982827047726609f, 0.982838154997492f, 0.982854812138917f,
+ 0.982865914390938f, 0.982882564007288f, 0.982893661244735f,
+ 0.982904756477552f, 0.982921395569597f, 0.982932485793838f,
+ 0.982949117376225f, 0.982960202596166f, 0.982971285815582f,
+ 0.982987906895218f, 0.982998985116313f, 0.983010061339272f,
+ 0.983026671928701f, 0.983037743159306f, 0.983048812394161f,
+ 0.983065412505902f, 0.983076476754361f, 0.983087539009450f,
+ 0.983104128656004f, 0.983115185930644f, 0.983126241214290f,
+ 0.983142820408134f, 0.983164919037780f, 0.983164919037780f,
+ 0.983181487791369f, 0.983203572508969f, 0.983203572508969f,
+ 0.983220130834737f, 0.983242201656853f, 0.983242201656853f,
+ 0.983258749567212f, 0.983280806510381f, 0.983280806510381f,
+ 0.983297344017722f, 0.983308366547671f, 0.983330405670727f,
+ 0.983330405670727f, 0.983346929820930f, 0.983368955102724f,
+ 0.983379964780070f, 0.983396475593535f, 0.983396475593535f,
+ 0.983418483103573f, 0.983418483103573f, 0.983434983558095f,
+ 0.983445981396647f, 0.983467971162045f, 0.983467971162045f,
+ 0.983484458315984f, 0.983495447291238f, 0.983517419339052f,
+ 0.983517419339052f, 0.983533893212681f, 0.983555851498819f,
+ 0.983566827695369f, 0.983577801928461f, 0.983594259598068f,
+ 0.983605228925419f, 0.983616196291637f, 0.983627161697383f,
+ 0.983627161697383f, 0.983643606131571f, 0.983654566639040f,
+ 0.983676481780187f, 0.983687436415187f, 0.983703864700081f,
+ 0.983703864700081f, 0.983714814445903f, 0.983736708074663f,
+ 0.983747651958919f, 0.983758593890641f, 0.983775003128660f,
+ 0.983785940181924f, 0.983829668899257f, 0.983846059132147f,
+ 0.983856983520667f, 0.983867905963228f, 0.983878826460486f,
+ 0.983900661621713f, 0.983917032891085f, 0.983917032891085f,
+ 0.983927944642585f, 0.983938854452384f, 0.983960668249489f,
+ 0.983971572238103f, 0.983982474287629f, 0.983998823727552f,
+ 0.983998823727552f, 0.984020616200059f, 0.984031509531754f,
+ 0.984042400927945f, 0.984053290389283f, 0.984064177916417f,
+ 0.984075063509998f, 0.984085947170676f, 0.984102269038919f,
+ 0.984113147870179f, 0.984124024770807f, 0.984134899741452f,
+ 0.984145772782762f, 0.984156643895383f, 0.984167513079964f,
+ 0.984178380337151f, 0.984189245667592f, 0.984200109071931f,
+ 0.984210970550817f, 0.984227259160331f, 0.984238115828405f,
+ 0.984248970573283f, 0.984259823395610f, 0.984270674296031f,
+ 0.984281523275189f, 0.984292370333728f, 0.984303215472291f,
+ 0.984314058691521f, 0.984324899992062f, 0.984335739374555f,
+ 0.984346576839642f, 0.984357412387966f, 0.984368246020168f,
+ 0.984379077736889f, 0.984389907538769f, 0.984400735426450f,
+ 0.984411561400571f, 0.984422385461773f, 0.984433207610695f,
+ 0.984444027847976f, 0.984460254620969f, 0.984471070081943f,
+ 0.984481883633511f, 0.984492695276311f, 0.984503505010981f,
+ 0.984514312838157f, 0.984525118758478f, 0.984535922772579f,
+ 0.984546724881096f, 0.984557525084666f, 0.984568323383925f,
+ 0.984579119779507f, 0.984589914272047f, 0.984600706862181f,
+ 0.984611497550543f, 0.984622286337767f, 0.984633073224487f,
+ 0.984643858211335f, 0.984649249992506f, 0.984670812370678f,
+ 0.984681590712963f, 0.984692367158224f, 0.984703141707094f,
+ 0.984703141707094f, 0.984713914360202f, 0.984724685118182f,
+ 0.984735453981663f, 0.984746220951275f, 0.984756986027650f,
+ 0.984767749211417f, 0.984778510503206f, 0.984789269903646f,
+ 0.984800027413365f, 0.984810783032994f, 0.984821536763160f,
+ 0.984832288604491f, 0.984843038557615f, 0.984853786623160f,
+ 0.984869905183637f, 0.984880648532976f, 0.984891389996930f,
+ 0.984902129576124f, 0.984912867271185f, 0.984923603082736f,
+ 0.984934337011405f, 0.984945069057816f, 0.984955799222593f,
+ 0.984966527506360f, 0.984977253909743f, 0.984987978433363f,
+ 0.984993339990457f, 0.985004061695604f, 0.985014781522546f,
+ 0.985025499471908f, 0.985036215544310f, 0.985046929740375f,
+ 0.985057642060725f, 0.985068352505981f, 0.985079061076764f,
+ 0.985084414659422f, 0.985095120419660f, 0.985105824306976f,
+ 0.985116526321991f, 0.985127226465325f, 0.985137924737595f,
+ 0.985148621139423f, 0.985159315671427f, 0.985164662236437f,
+ 0.985175353964864f, 0.985186043825012f, 0.985196731817500f,
+ 0.985207417942944f, 0.985218102201962f, 0.985228784595170f,
+ 0.985244804687940f, 0.985255482419322f, 0.985266158287053f,
+ 0.985266158287053f, 0.985276832291746f, 0.985292839806936f,
+ 0.985303509156728f, 0.985314176645634f, 0.985324842274270f,
+ 0.985324842274270f, 0.985335506043249f, 0.985351498211202f,
+ 0.985362157333723f, 0.985372814598732f, 0.985383470006843f,
+ 0.985383470006843f, 0.985399449638666f, 0.985410100407211f,
+ 0.985420749320998f, 0.985431396380641f, 0.985431396380641f,
+ 0.985442041586749f, 0.985458005921870f, 0.985468646496813f,
+ 0.985479285220358f, 0.985479285220358f, 0.985495239835637f,
+ 0.985505873933352f, 0.985516506181800f, 0.985527136581592f,
+ 0.985527136581592f, 0.985543078716377f, 0.985553704497184f,
+ 0.985564328431462f, 0.985574950519818f, 0.985585570762857f,
+ 0.985590880192573f, 0.985601497668777f, 0.985612113301180f,
+ 0.985622727090390f, 0.985628033293987f, 0.985638644319542f,
+ 0.985649253503417f, 0.985659860846216f, 0.985665163827402f,
+ 0.985675768409722f, 0.985686371152477f, 0.985696972056273f,
+ 0.985702271818749f, 0.985712869965236f, 0.985723466274270f,
+ 0.985734060746455f, 0.985739357293918f, 0.985749949011959f,
+ 0.985760538894657f, 0.985776420278752f, 0.985787005575724f,
+ 0.985797589039459f, 0.985802880084049f, 0.985813460799053f,
+ 0.985824039682320f, 0.985834616734451f, 0.985839904574028f,
+ 0.985850478880578f, 0.985861051357492f, 0.985866336910022f,
+ 0.985876906643602f, 0.985887474549043f, 0.985898040626941f,
+ 0.985903322980749f, 0.985913886318456f, 0.985924447830116f,
+ 0.985929727901365f, 0.985940286675075f, 0.985950843624230f,
+ 0.985956121414786f, 0.985966675628229f, 0.985977228018608f,
+ 0.985987778586520f, 0.985993053187237f, 0.986003601022566f,
+ 0.986014147036915f, 0.986019419361409f, 0.986029962645406f,
+ 0.986040504109912f, 0.986045774160041f, 0.986056312896423f,
+ 0.986066849814798f, 0.986072117592419f, 0.986082651784897f,
+ 0.986093184160851f, 0.986098449667817f, 0.986108979320098f,
+ 0.986119507157337f, 0.986124770395501f, 0.986135295511287f,
+ 0.986145818813510f, 0.986151079784721f, 0.986161600367710f,
+ 0.986166859979636f, 0.986177377844719f, 0.986187893898605f,
+ 0.986193151246533f, 0.986203664584727f, 0.986214176113198f,
+ 0.986219431198972f, 0.986229940013964f, 0.986240447020705f,
+ 0.986245699846166f, 0.986256204141637f, 0.986261455611793f,
+ 0.986271957197316f, 0.986282456976943f, 0.986287706189730f,
+ 0.986298203261614f, 0.986308698529071f, 0.986313945486323f,
+ 0.986324438048239f, 0.986329683653050f, 0.986340173510745f,
+ 0.986350661566360f, 0.986355904918569f, 0.986366390272160f,
+ 0.986382114926572f, 0.986382114926572f, 0.986392595779718f,
+ 0.986397835531571f, 0.986413552089130f, 0.986424027546565f,
+ 0.986424027546565f, 0.986434501206598f, 0.986450208327797f,
+ 0.986455443136794f, 0.986465911408123f, 0.986465911408123f,
+ 0.986481610449544f, 0.986492074234293f, 0.986497305454026f,
+ 0.986507766548573f, 0.986512996423533f, 0.986523454829188f,
+ 0.986533911442975f, 0.986539139078099f, 0.986549593005172f,
+ 0.986554819297267f, 0.986565270538934f, 0.986570495488651f,
+ 0.986580944046217f, 0.986591390815106f, 0.986596613528979f,
+ 0.986607057615941f, 0.986612278989175f, 0.986622720395512f,
+ 0.986627940428760f, 0.986638379155774f, 0.986643597849686f,
+ 0.986654033898679f, 0.986659251253905f, 0.986669684626176f,
+ 0.986680116214689f, 0.986685331340216f, 0.986695760254172f,
+ 0.986700974042745f, 0.986711400283442f, 0.986716612735710f,
+ 0.986727036304445f, 0.986732247421057f, 0.986742668319126f,
+ 0.986747878100727f, 0.986758296329425f, 0.986763504776665f,
+ 0.986773920337285f, 0.986779127450809f, 0.986789540344645f,
+ 0.986794746125101f, 0.986805156353445f, 0.986810360801477f,
+ 0.986820768365621f, 0.986831174154347f, 0.986836376383108f,
+ 0.986846779509784f, 0.986851980407841f, 0.986862380873755f,
+ 0.986867580441755f, 0.986877978248194f, 0.986883176486778f,
+ 0.986893571635030f, 0.986898768544842f, 0.986909161036194f,
+ 0.986914356617876f, 0.986924746453612f, 0.986935134519650f,
+ 0.986945520816562f, 0.986950713301773f, 0.986961096946065f,
+ 0.986966288105286f, 0.986976669098239f, 0.986981858932111f,
+ 0.986992237275006f, 0.986997425784170f, 0.987007801478288f,
+ 0.987012988663383f, 0.987023361710002f, 0.987028547571668f,
+ 0.987038917972068f, 0.987044102510944f, 0.987054470266402f,
+ 0.987059653483127f, 0.987059653483127f, 0.987070018594919f,
+ 0.987080381944977f, 0.987090743533868f, 0.987095923668051f,
+ 0.987106282616252f, 0.987111461430409f, 0.987121817739193f,
+ 0.987126995233961f, 0.987137348904601f, 0.987142525080615f,
+ 0.987147700817186f, 0.987158050972279f, 0.987163225390944f,
+ 0.987173572910860f, 0.987178746012253f, 0.987189090898262f,
+ 0.987194262683019f, 0.987204604936389f, 0.987209775405143f,
+ 0.987214945435371f, 0.987225284180528f, 0.987230452895598f,
+ 0.987240789011073f, 0.987245956411619f, 0.987256289898679f,
+ 0.987261455985333f, 0.987292443313425f, 0.987276951618636f,
+ 0.987302768922823f, 0.987313092783174f, 0.987318254057631f,
+ 0.987328575295461f, 0.987333735258974f, 0.987344053875544f,
+ 0.987349212528741f, 0.987354370745308f, 0.987364685868824f,
+ 0.987369842775915f, 0.987380155281111f, 0.987385310879356f,
+ 0.987390466041458f, 0.987400775057515f, 0.987405928911610f,
+ 0.987416235312279f, 0.987421387858994f, 0.987426539970055f,
+ 0.987436842885494f, 0.987441993690012f, 0.987447144059154f,
+ 0.987457443491593f, 0.987462592555029f, 0.987472889376680f,
+ 0.987478037135035f, 0.987483184458503f, 0.987493477801052f,
+ 0.987503769404885f, 0.987503769404885f, 0.987514059270557f,
+ 0.987519203551756f, 0.987529490811229f, 0.987534633789641f,
+ 0.987539776333929f, 0.987550060120412f, 0.987555201362745f,
+ 0.987560342171233f, 0.987570622486945f, 0.987580901068104f,
+ 0.987580901068104f, 0.987591177915262f, 0.987596315688765f,
+ 0.987606589935962f, 0.987611726409794f, 0.987616862450543f,
+ 0.987627133233060f, 0.987632267974967f, 0.987637402284067f,
+ 0.987647669604116f, 0.987652802615204f, 0.987657935193759f,
+ 0.987668199053549f, 0.987673330334921f, 0.987678461184036f,
+ 0.987688721585774f, 0.987693851138533f, 0.987698980259311f,
+ 0.987709237205201f, 0.987714365030449f, 0.987719492423992f,
+ 0.987729745916237f, 0.987734872015076f, 0.987739997682485f,
+ 0.987750247723285f, 0.987760496039188f, 0.987760496039188f,
+ 0.987770742630743f, 0.987780987498498f, 0.987780987498498f,
+ 0.987791230643004f, 0.987796351569210f, 0.987801472064809f,
+ 0.987811711764460f, 0.987816830968650f, 0.987827068086100f,
+ 0.987827068086100f, 0.987837303482766f, 0.987842420535977f,
+ 0.987847537159197f, 0.987857769115940f, 0.987862884449599f,
+ 0.987867999353541f, 0.987878227872547f, 0.987883341487748f,
+ 0.987888454673505f, 0.987898679756961f, 0.987903791654796f,
+ 0.987908903123460f, 0.987914014163022f, 0.987924234955111f,
+ 0.987929344707774f, 0.987934454031607f, 0.987944671393056f,
+ 0.987949779430808f, 0.987959994220708f, 0.987959994220708f,
+ 0.987970207296921f, 0.987975313192566f, 0.987995732493650f,
+ 0.988000836248887f, 0.988005939576247f, 0.988016144947605f,
+ 0.988021246991739f, 0.988026348608267f, 0.988031449797257f,
+ 0.988041650892892f, 0.988046750799674f, 0.988051850279188f,
+ 0.988062047956687f, 0.988067146154806f, 0.988072243925930f,
+ 0.988077341270126f, 0.988087534678001f, 0.988092630741817f,
+ 0.988097726378975f, 0.988102821589542f, 0.988113010731178f,
+ 0.988118104662380f, 0.988123198167263f, 0.988128291245894f,
+ 0.988138476124667f, 0.988143567924946f, 0.988148659299242f,
+ 0.988153750247623f, 0.988163930866911f, 0.988169020537952f,
+ 0.988174109783348f, 0.988179198603165f, 0.988189374966338f,
+ 0.988194462509826f, 0.988199549628007f, 0.988204636320946f,
+ 0.988214808431370f, 0.988219893848989f, 0.988224978841637f,
+ 0.988230063409379f, 0.988235147552284f, 0.988245314563850f,
+ 0.988250397432645f, 0.988255479876871f, 0.988260561896595f,
+ 0.988270724662807f, 0.988275805409428f, 0.988280885731816f,
+ 0.988285965630037f, 0.988296124154249f, 0.988301202780374f,
+ 0.988306280982600f, 0.988311358760995f, 0.988316436115625f,
+ 0.988331665637599f, 0.988336741297841f, 0.988341816534654f,
+ 0.988346891348103f, 0.988357039705180f, 0.988362113248942f,
+ 0.988367186369607f, 0.988372259067245f, 0.988377331341919f,
+ 0.988387474622650f, 0.988392545628840f, 0.988397616212334f,
+ 0.988402686373199f, 0.988407756111503f, 0.988417894320692f,
+ 0.988422962791711f, 0.988428030840435f, 0.988433098466929f,
+ 0.988438165671262f, 0.988448298813708f, 0.988448298813708f,
+ 0.988453364751954f, 0.988463495362826f, 0.988468560035585f,
+ 0.988478688116080f, 0.988478688116080f, 0.988488814510321f,
+ 0.988493877075263f, 0.988498939218840f, 0.988509062242168f,
+ 0.988509062242168f, 0.988514123122051f, 0.988519183580837f,
+ 0.988529303235375f, 0.988534362431262f, 0.988534362431262f,
+ 0.988544479560602f, 0.988549537494187f, 0.988554595007138f,
+ 0.988564708771400f, 0.988569765022844f, 0.988579876264688f,
+ 0.988584931255221f, 0.988589985825582f, 0.988595039975838f,
+ 0.988605147016298f, 0.988605147016298f, 0.988615252377130f,
+ 0.988620304427851f, 0.988625356058862f, 0.988630407270231f,
+ 0.988635458062022f, 0.988640508434303f, 0.988650607920595f,
+ 0.988655657034738f, 0.988660705729634f, 0.988665754005349f,
+ 0.988670801861948f, 0.988680896318064f, 0.988680896318064f,
+ 0.988690989098507f, 0.988696034860517f, 0.988701080203806f,
+ 0.988706125128441f, 0.988711169634487f, 0.988716213722009f,
+ 0.988721257391074f, 0.988731343474094f, 0.988736385888181f,
+ 0.988741427884073f, 0.988746469461837f, 0.988751510621536f,
+ 0.988761591687008f, 0.988771671081014f, 0.988771671081014f,
+ 0.988781748804078f, 0.988786787039171f, 0.988791824856726f,
+ 0.988796862256806f, 0.988801899239479f, 0.988806935804810f,
+ 0.988817007683707f, 0.988817007683707f, 0.988822042997403f,
+ 0.988827077894019f, 0.988837146436271f, 0.988842180082038f,
+ 0.988847213310986f, 0.988852246123180f, 0.988862310497568f,
+ 0.988862310497568f, 0.988867342059893f, 0.988872373205725f,
+ 0.988877403935130f, 0.988887464144920f, 0.988892493625434f,
+ 0.988897522689783f, 0.988902551338030f, 0.988912607386482f,
+ 0.988912607386482f, 0.988922661771312f, 0.988927688340031f,
+ 0.988932714493039f, 0.988937740230403f, 0.988942765552186f,
+ 0.988947790458455f, 0.988952814949272f, 0.988957839024706f,
+ 0.988967885929677f, 0.988967885929677f, 0.988972908759345f,
+ 0.988982953173371f, 0.988987974757859f, 0.988992995927416f,
+ 0.988998016682109f, 0.989003037022000f, 0.989008056947156f,
+ 0.989013076457642f, 0.989018095553521f, 0.989028132501721f,
+ 0.989033150354172f, 0.989038167792276f, 0.989043184816098f,
+ 0.989048201425703f, 0.989053217621155f, 0.989058233402521f,
+ 0.989063248769862f, 0.989068263723246f, 0.989073278262736f,
+ 0.989078292388397f, 0.989083306100294f, 0.989093332283054f,
+ 0.989093332283054f, 0.989098344754046f, 0.989103356811533f,
+ 0.989108368455578f, 0.989113379686246f, 0.989123400907711f,
+ 0.989128410898637f, 0.989133420476444f, 0.989138429641197f,
+ 0.989143438392961f, 0.989148446731799f, 0.989153454657776f,
+ 0.989158462170958f, 0.989163469271408f, 0.989173482234369f,
+ 0.989173482234369f, 0.989178488097010f, 0.989188498584932f,
+ 0.989193503210343f, 0.989198507423472f, 0.989203511224385f,
+ 0.989208514613144f, 0.989213517589816f, 0.989218520154462f,
+ 0.989223522307149f, 0.989228524047940f, 0.989233525376900f,
+ 0.989238526294092f, 0.989243526799581f, 0.989248526893431f,
+ 0.989253526575707f, 0.989258525846471f, 0.989263524705789f,
+ 0.989268523153725f, 0.989278518815704f, 0.989283516029877f,
+ 0.989288512832923f, 0.989293509224907f, 0.989298505205893f,
+ 0.989303500775945f, 0.989308495935126f, 0.989313490683502f,
+ 0.989318485021135f, 0.989323478948089f, 0.989328472464430f,
+ 0.989333465570220f, 0.989338458265524f, 0.989343450550404f,
+ 0.989348442424926f, 0.989353433889154f, 0.989358424943150f,
+ 0.989363415586979f, 0.989368405820704f, 0.989373395644390f,
+ 0.989378385058100f, 0.989383374061898f, 0.989388362655847f,
+ 0.989393350840012f, 0.989398338614456f, 0.989403325979243f,
+ 0.989408312934436f, 0.989413299480100f, 0.989418285616298f,
+ 0.989423271343093f, 0.989428256660550f, 0.989433241568731f,
+ 0.989438226067700f, 0.989443210157522f, 0.989448193838259f,
+ 0.989453177109976f, 0.989458159972735f, 0.989463142426600f,
+ 0.989468124471636f, 0.989473106107904f, 0.989478087335469f,
+ 0.989483068154395f, 0.989488048564745f, 0.989493028566581f,
+ 0.989498008159969f, 0.989502987344970f, 0.989507966121648f,
+ 0.989512944490068f, 0.989517922450292f, 0.989522900002383f,
+ 0.989527877146405f, 0.989532853882422f, 0.989537830210496f,
+ 0.989542806130691f, 0.989547781643070f, 0.989552756747697f,
+ 0.989557731444634f, 0.989562705733946f, 0.989567679615695f,
+ 0.989572653089944f, 0.989577626156756f, 0.989582598816196f,
+ 0.989587571068325f, 0.989592542913208f, 0.989597514350907f,
+ 0.989602485381486f, 0.989607456005007f, 0.989612426221533f,
+ 0.989617396031129f, 0.989622365433856f, 0.989627334429779f,
+ 0.989632303018959f, 0.989637271201460f, 0.989642238977345f,
+ 0.989647206346678f, 0.989652173309519f, 0.989657139865935f,
+ 0.989662106015986f, 0.989667071759736f, 0.989667071759736f,
+ 0.989672037097247f, 0.989677002028584f, 0.989681966553808f,
+ 0.989686930672983f, 0.989691894386171f, 0.989696857693435f,
+ 0.989701820594839f, 0.989706783090444f, 0.989711745180314f,
+ 0.989716706864512f, 0.989721668143100f, 0.989726629016141f,
+ 0.989731589483698f, 0.989736549545834f, 0.989741509202611f,
+ 0.989746468454092f, 0.989751427300340f, 0.989756385741417f,
+ 0.989761343777386f, 0.989761343777386f, 0.989766301408311f,
+ 0.989771258634252f, 0.989776215455275f, 0.989781171871439f,
+ 0.989786127882809f, 0.989791083489447f, 0.989796038691415f,
+ 0.989800993488776f, 0.989805947881593f, 0.989810901869928f,
+ 0.989815855453843f, 0.989820808633402f, 0.989825761408667f,
+ 0.989830713779699f, 0.989835665746562f, 0.989840617309318f,
+ 0.989840617309318f, 0.989845568468030f, 0.989850519222759f,
+ 0.989855469573569f, 0.989860419520521f, 0.989865369063679f,
+ 0.989870318203104f, 0.989875266938858f, 0.989880215271005f,
+ 0.989885163199606f, 0.989885163199606f, 0.989890110724724f,
+ 0.989895057846421f, 0.989900004564759f, 0.989904950879801f,
+ 0.989909896791608f, 0.989914842300244f, 0.989919787405770f,
+ 0.989924732108248f, 0.989929676407741f, 0.989934620304311f,
+ 0.989939563798019f, 0.989944506888929f, 0.989944506888929f,
+ 0.989949449577102f, 0.989954391862601f, 0.989959333745488f,
+ 0.989964275225823f, 0.989969216303671f, 0.989974156979092f,
+ 0.989979097252149f, 0.989984037122904f, 0.989988976591419f,
+ 0.989993915657756f, 0.990102473491435f, 0.989998854321976f,
+ 0.990003792584142f, 0.990008730444317f, 0.990013667902561f,
+ 0.990018604958937f, 0.990127118651726f, 0.990132046482196f,
+ 0.990136973912279f, 0.990141900942038f, 0.990146827571534f,
+ 0.990097543257357f, 0.990048218861426f, 0.990053153106457f,
+ 0.990058086950115f, 0.990166530088123f, 0.990171454717229f,
+ 0.990176378946441f, 0.990181302775822f, 0.990077818312251f,
+ 0.990082750149969f, 0.990087681586685f, 0.990092612622461f,
+ 0.990200994096251f, 0.990205915927393f, 0.990210837359071f,
+ 0.990215758391347f, 0.990220679024282f, 0.990220679024282f,
+ 0.990225599257938f, 0.990230519092376f, 0.990235438527657f,
+ 0.990240357563843f, 0.990245276200994f, 0.990250194439173f,
+ 0.990255112278440f, 0.990255112278440f, 0.990260029718857f,
+ 0.990264946760485f, 0.990269863403386f, 0.990274779647619f,
+ 0.990279695493247f, 0.990284610940331f, 0.990284610940331f,
+ 0.990289525988932f, 0.990294440639111f, 0.990299354890930f,
+ 0.990304268744449f, 0.990309182199729f, 0.990314095256832f,
+ 0.990314095256832f, 0.990319007915819f, 0.990323920176751f,
+ 0.990328832039688f, 0.990333743504692f, 0.990338654571825f,
+ 0.990338654571825f, 0.990343565241146f, 0.990348475512717f,
+ 0.990353385386600f, 0.990358294862854f, 0.990363203941541f,
+ 0.990363203941541f, 0.990368112622723f, 0.990373020906459f,
+ 0.990377928792811f, 0.990382836281839f, 0.990387743373605f,
+ 0.990387743373605f, 0.990392650068170f, 0.990397556365594f,
+ 0.990402462265938f, 0.990407367769264f, 0.990412272875631f,
+ 0.990412272875631f, 0.990417177585100f, 0.990422081897733f,
+ 0.990426985813592f, 0.990431889332734f, 0.990436792455222f,
+ 0.990441695181118f, 0.990446597510480f, 0.990446597510480f,
+ 0.990451499443371f, 0.990456400979850f, 0.990461302119979f,
+ 0.990466202863817f, 0.990471103211427f, 0.990471103211427f,
+ 0.990476003162868f, 0.990480902718201f, 0.990485801877487f,
+ 0.990490700640787f, 0.990490700640787f, 0.990495599008160f,
+ 0.990500496979667f, 0.990505394555370f, 0.990510291735329f,
+ 0.990515188519603f, 0.990515188519603f, 0.990520084908255f,
+ 0.990524980901343f, 0.990529876498930f, 0.990534771701074f,
+ 0.990539666507838f, 0.990539666507838f, 0.990544560919280f,
+ 0.990549454935462f, 0.990554348556445f, 0.990559241782288f,
+ 0.990564134613051f, 0.990564134613051f, 0.990569027048796f,
+ 0.990573919089582f, 0.990578810735471f, 0.990583701986522f,
+ 0.990583701986522f, 0.990588592842796f, 0.990593483304352f,
+ 0.990598373371253f, 0.990598373371253f, 0.990603263043557f,
+ 0.990608152321324f, 0.990613041204617f, 0.990617929693493f,
+ 0.990622817788014f, 0.990622817788014f, 0.990627705488241f,
+ 0.990632592794232f, 0.990637479706049f, 0.990642366223752f,
+ 0.990642366223752f, 0.990647252347400f, 0.990652138077054f,
+ 0.990657023412774f, 0.990661908354621f, 0.990661908354621f,
+ 0.990666792902654f, 0.990671677056933f, 0.990676560817519f,
+ 0.990681444184472f, 0.990681444184472f, 0.990686327157852f,
+ 0.990691209737718f, 0.990696091924130f, 0.990700973717151f,
+ 0.990700973717151f, 0.990705855116837f, 0.990710736123251f,
+ 0.990715616736451f, 0.990715616736451f, 0.990720496956498f,
+ 0.990725376783453f, 0.990730256217374f, 0.990735135258321f,
+ 0.990735135258321f, 0.990740013906355f, 0.990744892161536f,
+ 0.990749770023923f, 0.990754647493576f, 0.990754647493576f,
+ 0.990759524570556f, 0.990764401254922f, 0.990769277546733f,
+ 0.990774153446051f, 0.990774153446051f, 0.990779028952933f,
+ 0.990783904067441f, 0.990788778789634f, 0.990788778789634f,
+ 0.990793653119573f, 0.990798527057315f, 0.990803400602923f,
+ 0.990808273756453f, 0.990808273756453f, 0.990813146517969f,
+ 0.990818018887528f, 0.990822890865190f, 0.990827762451014f,
+ 0.990827762451014f, 0.990832633645062f, 0.990837504447392f,
+ 0.990842374858063f, 0.990842374858063f, 0.990847244877137f,
+ 0.990852114504671f, 0.990856983740726f, 0.990856983740726f,
+ 0.990861852585361f, 0.990866721038637f, 0.990871589100612f,
+ 0.990876456771346f, 0.990876456771346f, 0.990881324050898f,
+ 0.990886190939329f, 0.990891057436697f, 0.990891057436697f,
+ 0.990895923543062f, 0.990900789258484f, 0.990905654583022f,
+ 0.990905654583022f, 0.990910519516736f, 0.990915384059684f,
+ 0.990920248211927f, 0.990920248211927f, 0.990925111973523f,
+ 0.990929975344533f, 0.990934838325015f, 0.990939700915029f,
+ 0.990939700915029f, 0.990944563114635f, 0.990949424923891f,
+ 0.990954286342857f, 0.990954286342857f, 0.990959147371593f,
+ 0.990964008010157f, 0.990968868258609f, 0.990968868258609f,
+ 0.990973728117009f, 0.990978587585414f, 0.990983446663886f,
+ 0.990988305352482f, 0.990988305352482f, 0.990993163651263f,
+ 0.990998021560288f, 0.991002879079614f, 0.991002879079614f,
+ 0.991007736209303f, 0.991012592949413f, 0.991017449300003f,
+ 0.991017449300003f, 0.991022305261132f, 0.991027160832860f,
+ 0.991032016015245f, 0.991032016015245f, 0.991036870808346f,
+ 0.991041725212224f, 0.991046579226937f, 0.991046579226937f,
+ 0.991051432852543f, 0.991056286089103f, 0.991061138936675f,
+ 0.991061138936675f, 0.991065991395318f, 0.991070843465090f,
+ 0.991075695146052f, 0.991075695146052f, 0.991080546438262f,
+ 0.991085397341780f, 0.991090247856663f, 0.991090247856663f,
+ 0.991095097982971f, 0.991099947720763f, 0.991104797070098f,
+ 0.991109646031035f, 0.991109646031035f, 0.991114494603633f,
+ 0.991119342787949f, 0.991119342787949f, 0.991124190584045f,
+ 0.991129037991978f, 0.991133885011807f, 0.991133885011807f,
+ 0.991138731643591f, 0.991143577887389f, 0.991148423743260f,
+ 0.991148423743260f, 0.991153269211262f, 0.991158114291454f,
+ 0.991158114291454f, 0.991162958983895f, 0.991167803288644f,
+ 0.991172647205759f, 0.991172647205759f, 0.991177490735300f,
+ 0.991182333877324f, 0.991187176631891f, 0.991187176631891f,
+ 0.991192040874586f, 0.991196904726712f, 0.991196904726712f,
+ 0.991201768188329f, 0.991206631259494f, 0.991211493940268f,
+ 0.991211493940268f, 0.991216356230710f, 0.991221218130880f,
+ 0.991226079640835f, 0.991230940760638f, 0.991230940760638f,
+ 0.991235801490345f, 0.991240661830017f, 0.991245521779712f,
+ 0.991245521779712f, 0.991250381339491f, 0.991255240509413f,
+ 0.991260099289535f, 0.991260099289535f, 0.991264957679918f,
+ 0.991269815680622f, 0.991274673291704f, 0.991274673291704f,
+ 0.991279530513224f, 0.991284387345243f, 0.991289243787817f,
+ 0.991289243787817f, 0.991294099841006f, 0.991298955504871f,
+ 0.991303810779470f, 0.991303810779470f, 0.991308665664861f,
+ 0.991313520161105f, 0.991318374268260f, 0.991318374268260f,
+ 0.991323227986385f, 0.991328081315538f, 0.991332934255781f,
+ 0.991332934255781f, 0.991337786807170f, 0.991342638969767f,
+ 0.991347490743627f, 0.991347490743627f, 0.991352342128812f,
+ 0.991357193125380f, 0.991357193125380f, 0.991362043733390f,
+ 0.991366893952901f, 0.991371743783973f, 0.991371743783973f,
+ 0.991376593226661f, 0.991381442281029f, 0.991386290947134f,
+ 0.991386290947134f, 0.991391139225033f, 0.991395987114787f,
+ 0.991400834616454f, 0.991400834616454f, 0.991405681730093f,
+ 0.991410528455763f, 0.991410528455763f, 0.991415374793522f,
+ 0.991420220743429f, 0.991425066305544f, 0.991425066305544f,
+ 0.991429911479924f, 0.991434756266630f, 0.991439600665718f,
+ 0.991439600665718f, 0.991444444677248f, 0.991449288301280f,
+ 0.991449288301280f};
+
+// Mapping between reverberation times at a given frequency and the
+// corresponding magnitude compensation value required in the specral reverb to
+// achieve 1.0 magnitude for any decay rate when combined with the convolution
+// compensator. This table covers reverberation times between
+// kMinReverbTimeForFeedback and kNumFeedbackValues * kTimeStepSizeForFeedback,
+// i.e. 0.15s and 25s @48kHz.
+static const float kMagnitudeCompensation[kNumFeedbackValues] = {
+ 17.3996715487709f, 17.4034178858004f, 16.6795907475848f, 16.3502965109599f,
+ 15.9879028507326f, 15.6718483944106f, 15.4042251167111f, 15.1677088170684f,
+ 14.9119678952536f, 14.6906933374371f, 14.2839187463763f, 14.0999475816121f,
+ 13.9338828421032f, 13.7652114598195f, 13.6133888181873f, 13.4638764218013f,
+ 13.3247278048121f, 13.1976499042192f, 13.0833841919256f, 12.7669049046296f,
+ 12.7761019806869f, 12.7855596748707f, 12.5979372062571f, 12.5244917829334f,
+ 12.4453918694998f, 12.3672592847373f, 12.3020244979211f, 12.2257529341565f,
+ 12.1547662449381f, 12.0845455398564f, 12.0231689748723f, 11.9586881174297f,
+ 11.8906434508319f, 11.8264759328308f, 11.7652619217413f, 11.7033346037227f,
+ 11.6379964417238f, 11.5862703081324f, 11.5299758955061f, 11.4741541469989f,
+ 11.4224679633351f, 11.4302928484179f, 11.3885962828649f, 11.3488611750486f,
+ 11.3151942251170f, 11.2687417305887f, 11.2651043092380f, 11.2873091969354f,
+ 11.1115917717737f, 11.1187139401529f, 11.0873969606168f, 11.0667794924678f,
+ 11.0355838523984f, 11.0107298415034f, 10.9796516432030f, 10.9630980289917f,
+ 10.9420391333514f, 10.9144740761416f, 10.8934689087169f, 10.8708578658852f,
+ 10.8533772904939f, 10.8325917807584f, 10.8084481007036f, 10.7910279996611f,
+ 10.7720483888874f, 10.7547079194992f, 10.7374196414357f, 10.7165315149605f,
+ 10.6992241376899f, 10.6906704210781f, 10.6696884648005f, 10.6557033369952f,
+ 10.6417418339839f, 10.6206945653294f, 10.6123225679390f, 10.5984100558311f,
+ 10.5804524022014f, 10.5664834165837f, 10.5556799009337f, 10.5448786038089f,
+ 10.5294926904862f, 10.5186888881000f, 10.5078877209760f, 10.4896735339343f,
+ 10.4818821922801f, 10.4710009885916f, 10.4601237996041f, 10.4509410528977f,
+ 10.4400494357799f, 10.4322036844072f, 10.4213123997993f, 10.4058408037523f,
+ 10.3978977400326f, 10.3899444363220f, 10.3853855448482f, 10.3697415198647f,
+ 10.3617555934757f, 10.3567416154720f, 10.3487308415134f, 10.3329739194789f,
+ 10.3248849674214f, 10.3167888305905f, 10.3116328550137f, 10.2935369581880f,
+ 10.2854263705648f, 10.2802322447455f, 10.2721029640593f, 10.2668785541679f,
+ 10.2421605382004f, 10.2455580945816f, 10.2402346533852f, 10.2417289351959f,
+ 10.2364188981879f, 10.2144782407169f, 10.2091021586862f, 10.2037115797613f,
+ 10.1983068112122f, 10.1849493802464f, 10.1794698792260f, 10.1739775209827f,
+ 10.1684725944209f, 10.1699972796703f, 10.1673363396048f, 10.1537525491825f,
+ 10.1481899931936f, 10.1454318458448f, 10.1398423821346f, 10.1370496372401f,
+ 10.1314343707374f, 10.1205181210259f, 10.1148376525328f, 10.1119389454472f,
+ 10.1062355079601f, 10.1105790660401f, 10.1076676719351f, 10.1019633798750f,
+ 10.0907918971796f, 10.0877973262721f, 10.0820222224882f, 10.0790001296191f,
+ 10.0759630305115f, 10.0729111643779f, 10.0698447671938f, 10.0585205719156f,
+ 10.0553915426054f, 10.0495078552707f, 10.0463551070209f, 10.0452327409897f,
+ 10.0420899577109f, 10.0416595363245f, 10.0301423062663f, 10.0269263405620f,
+ 10.0236983112226f, 10.0204584174658f, 10.0172068557167f, 10.0139438196431f,
+ 10.0106695001895f, 10.0100859757974f, 10.0144981569414f, 10.0027240655604f,
+ 9.99940079964503f, 9.99875825234152f, 9.99541139468150f, 9.99205454764473f,
+ 9.98868788138219f, 9.98799186037639f, 9.98460299286733f, 9.98120480749684f,
+ 9.97196520049622f, 9.96851944732945f, 9.96773313504258f, 9.97209005664967f,
+ 9.97130280431796f, 9.96784064615800f, 9.96702924221558f, 9.96354778825994f,
+ 9.96271284320390f, 9.95921268399594f, 9.94972407107315f, 9.94618172696550f,
+ 9.94527759238012f, 9.93907565972122f, 9.93815157408174f, 9.93457833610339f,
+ 9.94163812518103f, 9.93806970926284f, 9.93712514990341f, 9.93616969007899f,
+ 9.92384118906784f, 9.92284379437166f, 9.92183604073516f, 9.91819656036143f,
+ 9.91716993715598f, 9.91613331652545f, 9.91508681621950f, 9.91141646117235f,
+ 9.91035202464596f, 9.90927805124168f, 9.90819465265145f, 9.90449521562619f,
+ 9.89464259105904f, 9.90163545023412f, 9.90051546012025f, 9.89938659067352f,
+ 9.89565102186460f, 9.89450616426505f, 9.89335273158198f, 9.89219082303091f,
+ 9.89102053655261f, 9.88984196883182f, 9.88865521531579f, 9.88746037023253f,
+ 9.88367272054804f, 9.88246342154956f, 9.87235666909112f, 9.87111421978793f,
+ 9.86728668752777f, 9.86603072697377f, 9.86476741507816f, 9.87181651341944f,
+ 9.87055453050722f, 9.86928534086147f, 9.86800902634652f, 9.86672566780610f,
+ 9.86543534507815f, 9.86413813700939f, 9.86283412146973f, 9.85253909146675f,
+ 9.85120575616663f, 9.84730850541530f, 9.84340913473107f, 9.83695739915978f,
+ 9.83305682291249f, 9.82661110215619f, 9.82270954762832f, 9.81627003605364f,
+ 9.81236772402631f, 9.80593460975945f, 9.79446129569662f, 9.79056524322650f,
+ 9.79518744944566f, 9.78878964277671f, 9.78490541018618f, 9.76941213950054f,
+ 9.76551357605385f, 9.76161372925909f, 9.75771265131274f, 9.75131744052475f,
+ 9.74741680228965f, 9.74351508082574f, 9.73961232562214f, 9.73322796347969f,
+ 9.72932601448363f, 9.72542317182318f, 9.72151948243115f, 9.71761499262133f,
+ 9.71124407362971f, 9.70734082271271f, 9.70343690224853f, 9.69953235617044f,
+ 9.69562722783490f, 9.69172156002971f, 9.67869145869549f, 9.67477248299185f,
+ 9.67085316486435f, 9.66693354428727f, 9.67164058015198f, 9.66773182471560f,
+ 9.66382281819403f, 9.65991359906596f, 9.65600420530895f, 9.65209467440629f,
+ 9.64818504335383f, 9.64427534866659f, 9.64036562638542f, 9.63645591208342f,
+ 9.63254624087234f, 9.62863664740886f, 9.62713438108161f, 9.61841452486423f,
+ 9.61450796945654f, 9.61060162177350f, 9.59745989603663f, 9.59593610568275f,
+ 9.59201716961870f, 9.58809863249534f, 9.58418052465712f, 9.58026287605631f,
+ 9.57872704411307f, 9.57480783656106f, 9.57088917994674f, 9.56934602396844f,
+ 9.56542599874574f, 9.56150661276656f, 9.55758789336276f, 9.55603586291498f,
+ 9.56094674392723f, 9.55703713657417f, 9.55548790574812f, 9.55157724555479f,
+ 9.54766736708134f, 9.54611162685054f, 9.54220086685072f, 9.54064051939564f,
+ 9.53672899077399f, 9.53281837539013f, 9.51720800158667f, 9.51563186381870f,
+ 9.51171473845506f, 9.51013443950261f, 9.50621695380252f, 9.50696588424213f,
+ 9.50071486073663f, 9.49214537555389f, 9.48823490695630f, 9.48432562212793f,
+ 9.48041754157442f, 9.47651068553726f, 9.47260507399707f, 9.46870072667699f,
+ 9.46479766304589f, 9.45859100251033f, 9.45469300691147f, 9.45079634803183f,
+ 9.44690104436323f, 9.44300711415882f, 9.43911457543615f, 9.43522344598003f,
+ 9.43133374334554f, 9.42744548486084f, 9.42355868763001f, 9.42195400960424f,
+ 9.41806778052289f, 9.41374743291046f, 9.40986387622231f, 9.40598186864776f,
+ 9.40210142598266f, 9.39822256381766f, 9.39434529754074f, 9.39046964233973f,
+ 9.38659561320474f, 9.38498117319374f, 9.38110807138758f, 9.37723664318189f,
+ 9.37336690279205f, 9.36949886424754f, 9.36563254139424f, 9.36401291268887f,
+ 9.36014771343569f, 9.35628427401529f, 9.35242260755338f, 9.34856272700286f,
+ 9.34693907021185f, 9.34308046758153f, 9.33922369235477f, 9.33536875680650f,
+ 9.33374195178015f, 9.32988841242305f, 9.32381510855490f, 9.31996765124740f,
+ 9.31612209259297f, 9.31227844391980f, 9.31064913327039f, 9.30680704022146f,
+ 9.29348811817957f, 9.29184974751964f, 9.28800440783775f, 9.28636432840859f,
+ 9.28252074101649f, 9.27867919003329f, 9.27703723070236f, 9.27319750721753f,
+ 9.26935985268265f, 9.26771614205892f, 9.26388038770541f, 9.26223520182348f,
+ 9.25840139650094f, 9.25675479157226f, 9.25292298305829f, 9.24909331708271f,
+ 9.25658949582583f, 9.25276798764379f, 9.25112470249905f, 9.24730525026412f,
+ 9.24566068030482f, 9.24184332892114f, 9.24019752634543f, 9.23638231973555f,
+ 9.23690246959584f, 9.23308722316596f, 9.23143799550340f, 9.22762498397928f,
+ 9.22597467697943f, 9.22432329385452f, 9.22051260344843f, 9.21886021442665f,
+ 9.21505186252288f, 9.21339851457425f, 9.20959254004180f, 9.20578887012963f,
+ 9.20198751127673f, 9.19073957709422f, 9.18693490086577f, 9.18527430481475f,
+ 9.18361278881117f, 9.17981083017848f, 9.17814860221564f, 9.17648548821270f,
+ 9.17268633214397f, 9.17102256976036f, 9.16935795435656f, 9.16556168321056f,
+ 9.16389648126049f, 9.16223045844461f, 9.15843715205156f, 9.15677060283272f,
+ 9.15510326406306f, 9.15131299980263f, 9.14964519313344f, 9.14797662741422f,
+ 9.14630731290934f, 9.13195283996486f, 9.13028849958014f, 9.12862343577599f,
+ 9.12485055311793f, 9.12318514040497f, 9.12151903298212f, 9.11985224052471f,
+ 9.11608300035933f, 9.11441593072157f, 9.11274820378056f, 9.11107982889063f,
+ 9.10941081532760f, 9.10774117228957f, 9.10397656900970f, 9.10230675285809f,
+ 9.10063633356450f, 9.10830768064681f, 9.10664083749441f, 9.10288539850849f,
+ 9.10121842744103f, 9.09955087784672f, 9.09788275836467f, 9.08651657603331f,
+ 9.08068020302688f, 9.08108732540316f, 9.07941328828146f, 9.07773874094359f,
+ 9.07398723838858f, 9.07231273992199f, 9.07063775460245f, 9.06896229034989f,
+ 9.06521511911848f, 9.06353976158507f, 9.06186394770784f, 9.06018768515226f,
+ 9.05851098152150f, 9.05683384435697f, 9.05515628113895f, 9.05347829928709f,
+ 9.05179990616104f, 9.05012110906098f, 9.04844191522816f, 9.04676233184547f,
+ 9.04302460323958f, 9.04134529301830f, 9.03966561367638f, 9.03798557216934f,
+ 9.03630517539697f, 9.03462443020383f, 9.03294334337977f, 9.03126192166043f,
+ 9.02958017172773f, 9.02789810021035f, 9.02621571368424f, 9.02453301867307f,
+ 9.02285002164873f, 9.02116672903177f, 9.01948314719191f, 9.01779928244843f,
+ 9.01611514107069f, 9.01443072927854f, 9.01274605324280f, 9.01106111908564f,
+ 9.00937593288109f, 9.00769050065541f, 9.00600482838754f, 9.00431892200953f,
+ 9.00263278740694f, 9.00094643041926f, 8.99925985684034f, 8.99757307241874f,
+ 8.99588608285818f, 8.99419889381793f, 8.99251151091317f, 8.99082393971542f,
+ 8.99116133873637f, 8.98947240095708f, 8.97807476175783f, 8.97638164966389f,
+ 8.97468839063631f, 8.97299498992199f, 8.97130145272722f, 8.96960778421804f,
+ 8.96791398952060f, 8.96622007372152f, 8.96452604186820f, 8.96283189896917f,
+ 8.96113764999443f, 8.96145642376267f, 8.95976097981039f, 8.95806544520587f,
+ 8.95636982476753f, 8.95467412327692f, 8.95297834547896f, 8.95128249608231f,
+ 8.94958657975968f, 8.95734018337137f, 8.95765278435025f, 8.95595916486210f,
+ 8.95426548584055f, 8.95257175184105f, 8.95087796738447f, 8.94918413695742f,
+ 8.94949047792581f, 8.94779558087857f, 8.94610065184975f, 8.94440569519098f,
+ 8.94271071522106f, 8.93902043601862f, 8.93932070246017f, 8.93961997400109f,
+ 8.93792395970352f, 8.93622794393283f, 8.93453193081558f, 8.93283592444736f,
+ 8.93113992889301f, 8.92944394818690f, 8.92973639134932f, 8.92803947305345f,
+ 8.92634258225175f, 8.92464572285846f, 8.92493436813772f, 8.92323660608605f,
+ 8.92153888773201f, 8.91984121687354f, 8.91814359728028f, 8.91644603269380f,
+ 8.91474852682785f, 8.91305108336851f, 8.91135370597452f, 8.91163407099939f,
+ 8.90993586525176f, 8.90823773709895f, 8.90653969009158f, 8.90681648856557f,
+ 8.90511764518828f, 8.90341889416476f, 8.90172023894098f, 8.90199353826512f,
+ 8.90029411780736f, 8.89859480404659f, 8.89689560032744f, 8.89519650996990f,
+ 8.89546552758263f, 8.89376570958158f, 8.89206601546450f, 8.88053809639265f,
+ 8.88080074152891f, 8.87909746670552f, 8.87739433859366f, 8.87765453752411f,
+ 8.87595075137300f, 8.87424712182442f, 8.87254365189478f, 8.87280064185817f,
+ 8.87109654154655f, 8.86743422965210f, 8.86768885156784f, 8.86598526773548f,
+ 8.86428186186200f, 8.86453414821111f, 8.86478566315377f, 8.86112634248555f,
+ 8.86137632515970f, 8.85967194497569f, 8.85796776101988f, 8.85626377603165f,
+ 8.85651073575462f, 8.85480620525780f, 8.85310188252331f, 8.85334661076713f,
+ 8.85164176132608f, 8.84993712826266f, 8.85017965504828f, 8.84847451372278f,
+ 8.84676959721478f, 8.84700995202877f, 8.84530454535357f, 8.84359937176427f,
+ 8.84383758357059f, 8.84213193756712f, 8.84042653275027f, 8.84066263000176f,
+ 8.83895677018950f, 8.83725115950061f, 8.83748517015020f, 8.83577912155772f,
+ 8.83407332986507f, 8.83430528137662f, 8.83259906855242f, 8.83089312024770f,
+ 8.83112303960668f, 8.82941668662965f, 8.82771060563841f, 8.82793851936218f,
+ 8.82623204985186f, 8.82645864099079f, 8.82475179379158f, 8.82304523091814f,
+ 8.82326985960455f, 8.82156293469962f, 8.81985630119355f, 8.82007899274514f,
+ 8.81837201257628f, 8.81666533073787f, 8.81688611003994f, 8.81517909662492f,
+ 8.81539861470977f, 8.82335720989358f, 8.82165261003093f, 8.82187267469875f,
+ 8.82016775424161f, 8.82038657061920f, 8.81675884387406f, 8.81697642252574f,
+ 8.81527182158995f, 8.81548817296149f, 8.81378328023903f, 8.81207870996388f,
+ 8.81229323974577f, 8.81058839169725f, 8.81080171980556f, 8.80909660340947f,
+ 8.80739182006356f, 8.80760336445859f, 8.80589832635901f, 8.80610869398147f,
+ 8.80440341027862f, 8.80461261089678f, 8.80290709063344f, 8.80120191782847f,
+ 8.80140938602084f, 8.79970398968595f, 8.79991031482745f, 8.78825930793902f,
+ 8.78846219390559f, 8.78675407755697f, 8.78504632874136f, 8.78524755053805f,
+ 8.78353962067476f, 8.78373974434793f, 8.78203164176273f, 8.78223067625635f,
+ 8.78052240917839f, 8.77881452261966f, 8.77901193990290f, 8.77730390068432f,
+ 8.77559624718409f, 8.77579206684317f, 8.77408427230694f, 8.77427903760903f,
+ 8.77257110989291f, 8.77276482931164f, 8.77105677618141f, 8.76934912094798f,
+ 8.76954128723245f, 8.76783351773637f, 8.76802465892895f, 8.76631678271580f,
+ 8.76650690697914f, 8.76479893150834f, 8.76498804691885f, 8.76327997956479f,
+ 8.76346809411380f, 8.76175994216697f, 8.76194706376180f, 8.76023883442988f,
+ 8.76042497089499f, 8.75871667130397f, 8.75890183038202f, 8.75719346757723f,
+ 8.75737765693012f, 8.75566923787733f, 8.75585246508727f, 8.75414399667368f,
+ 8.75432626924423f, 8.75261775827954f, 8.75090968234295f, 8.75109053685399f,
+ 8.75127092234682f, 8.74956234640392f, 8.74785421147492f, 8.74803320078602f,
+ 8.74632504621761f, 8.74461733673038f, 8.74291007344532f, 8.74308722620506f,
+ 8.74326392423471f, 8.74155620054932f, 8.74173199434523f, 8.74002427303862f,
+ 8.74019916951030f, 8.73849145680757f, 8.73866546279447f, 8.73695776485170f,
+ 8.73713088712407f, 8.73542321002923f, 8.73559545528903f, 8.73388780506281f,
+ 8.73405917994453f, 8.73235156254122f, 8.73252207361275f, 8.73081449492107f,
+ 8.73098414868451f, 8.72927661452841f, 8.72944541742091f, 8.72773793356043f,
+ 8.72790589195497f, 8.72619846408700f, 8.72636558429323f, 8.72653228775183f,
+ 8.72482450631728f, 8.72499038093493f, 8.72328266978537f, 8.72344772171672f,
+ 8.72174008633388f, 8.72003293816951f, 8.72019676747887f, 8.71848970287163f,
+ 8.71865272461753f, 8.71881534481493f, 8.71710796902965f, 8.71726979056008f,
+ 8.71556251187906f, 8.71572354060119f, 8.71401636421506f, 8.71417660593049f,
+ 8.71246953697379f, 8.71262899742776f, 8.71278806938804f, 8.71108072586171f,
+ 8.71123902507422f, 8.70953180189128f, 8.70968933396333f, 8.70798223606704f,
+ 8.70813900655191f, 8.70829539830896f, 8.70658805323002f, 8.70674369162996f,
+ 8.70503648428256f, 8.70519137474645f, 8.70348430989052f, 8.70363845778761f,
+ 8.70379223639875f, 8.70208495078059f, 8.70223799478307f, 8.70053086365168f,
+ 8.70068317828796f, 8.69897620622755f, 8.69912779669041f, 8.68932884670592f,
+ 8.68762000302773f, 8.68776884448380f, 8.68606017937344f, 8.68620831732905f,
+ 8.68449983514613f, 8.68464727456896f, 8.68479436657368f, 8.68308572543799f,
+ 8.68323212627427f, 8.68152367907888f, 8.68166939359894f, 8.68181476676632f,
+ 8.68010617755452f, 8.67839813079483f, 8.67854248705877f, 8.67868650672127f,
+ 8.67697833094137f, 8.67712168091770f, 8.67541371794501f, 8.67555640288794f,
+ 8.67384865672637f, 8.67399068124574f, 8.68390062160107f, 8.68219432235443f,
+ 8.68233691470609f, 8.68247917838292f, 8.68077277138796f, 8.68091438110988f,
+ 8.67920820006687f, 8.67934916032569f, 8.67948979752457f, 8.67778352432750f,
+ 8.67792351872432f, 8.67621748133180f, 8.67635683731680f, 8.67649587572979f,
+ 8.67478976139895f, 8.67492816791096f, 8.67506626008425f, 8.67336007789188f,
+ 8.67349754458695f, 8.67179161357488f, 8.67192845902535f, 8.67206499542924f,
+ 8.67035901118758f, 8.67049493262608f, 8.67063054813644f, 8.66892451939922f,
+ 8.66905952613920f, 8.66735376335083f, 8.66748816540435f, 8.66762226663473f,
+ 8.66591647342483f, 8.66421125283483f, 8.66250660524407f, 8.66263951321076f,
+ 8.66093514316382f, 8.65923134784848f, 8.65752812762827f, 8.65582548286296f,
+ 8.65412341390855f, 8.65242192111739f, 8.65072100483809f, 8.64902066541564f,
+ 8.64732090319137f, 8.64745089666342f, 8.64575142580246f, 8.64405253375412f,
+ 8.64235422084484f, 8.64065648739748f, 8.63895933373144f, 8.63726276016262f,
+ 8.63556676700344f, 8.63387135456289f, 8.63399880607199f, 8.63230369681987f,
+ 8.63060916980038f, 8.62891522530837f, 8.62722186363537f, 8.62552908506957f,
+ 8.62383688989589f, 8.62214527839595f, 8.62045425084813f, 8.62057923413287f,
+ 8.61888852099306f, 8.61719839322406f, 8.61550885109083f, 8.61381989485520f,
+ 8.61213152477584f, 8.61225490214502f, 8.61056685383226f, 8.60887939303327f,
+ 8.60719251999378f, 8.60369847555976f, 8.60382053816116f, 8.60394234032854f,
+ 8.60225697240927f, 8.59876697957841f, 8.59708363808768f, 8.59720440679893f,
+ 8.59552139839225f, 8.59383898041714f, 8.59215715308918f, 8.59047591662109f,
+ 8.58879527122275f, 8.58891451420684f, 8.58903350571243f, 8.58735294942756f,
+ 8.58567298620775f, 8.58399361624780f, 8.58231483973975f, 8.58063665687294f,
+ 8.57895906783397f, 8.57728207280678f, 8.57560567197261f, 8.57392986551003f,
+ 8.57404638533917f, 8.57237093049576f, 8.57248696522609f, 8.56902180741298f,
+ 8.56734813950615f, 8.56746345224170f, 8.56579014113883f, 8.56411742691198f,
+ 8.56244530971544f, 8.56077378970094f, 8.56088791398092f, 8.55921675580945f,
+ 8.55933040984012f, 8.55765961583721f, 8.55598942090227f, 8.55431982517126f,
+ 8.55443254737061f, 8.55276331980773f, 8.55109469242306f, 8.54942666534252f,
+ 8.54775923868966f, 8.54076218161341f, 8.53909843766319f, 8.53743529276498f,
+ 8.53754618531528f, 8.53588341401169f, 8.53422124267654f, 8.53255967141845f,
+ 8.53266966578484f, 8.53100847186734f, 8.52934787891323f, 8.52768788702179f,
+ 8.52779699406003f, 8.52613738317202f, 8.52447837420358f, 8.52281996724478f,
+ 8.52292819763660f, 8.52127017526276f, 8.51961275572668f, 8.51795593910948f,
+ 8.51806330336606f, 8.51640687483569f, 8.51475105002415f, 8.51485777147656f,
+ 8.50313962983211f, 8.50324475785744f, 8.49982824152465f, 8.49993295139312f,
+ 8.49827795948697f, 8.49838225368573f, 8.49496979858900f, 8.49507367958556f,
+ 8.49342030501101f, 8.49176753881319f, 8.49187080459044f, 8.49021844295144f,
+ 8.48856669037454f, 8.48691554689607f, 8.48701800083704f, 8.48536726502665f,
+ 8.48371713897484f, 8.48206762271016f, 8.48216927434053f, 8.48052016878301f,
+ 8.47887167364807f, 8.47897272970743f, 8.47732464765384f, 8.47567717663991f,
+ 8.47577764234150f, 8.47413058674447f, 8.47248414278601f, 8.47083831047568f,
+ 8.47093799703846f, 8.46929258301410f, 8.46764778121340f, 8.46774688934850f,
+ 8.46610250808181f, 8.46445873959686f, 8.46455727431892f, 8.46291392857930f,
+ 8.46127119616231f, 8.46136916242822f, 8.45972685493173f, 8.45808516128181f,
+ 8.45818256399157f, 8.45654129740170f, 8.45490064516572f, 8.45499748916322f,
+ 8.45335726609174f, 8.45171765786506f, 8.45007866445932f, 8.45017477094663f,
+ 8.44853620927392f, 8.44863195015821f, 8.44699382175575f, 8.44535630913176f,
+ 8.44371941225248f, 8.44381442815541f, 8.44217796702569f, 8.44054212207913f,
+ 8.44063659963106f, 8.43900119239275f, 8.43909531357936f, 8.43746034551955f,
+ 8.43582599452207f, 8.43591958492567f, 8.43428567501132f, 8.43265238255709f,
+ 8.43274544665058f, 8.43111259715250f, 8.42948036549767f, 8.42957290770386f,
+ 8.42794112084706f, 8.42630995220218f, 8.42640197689452f, 8.42477125485887f,
+ 8.42486293694762f, 8.42323266289285f, 8.42160300781375f, 8.42169417956989f,
+ 8.42006497423241f, 8.41843638820147f, 8.41852705387014f, 8.41689891931203f,
+ 8.41527140437771f, 8.41536156815713f, 8.41373450639779f, 8.41210806456602f,
+ 8.41219773060816f, 8.41057174362487f, 8.40894637685971f, 8.40903554927091f,
+ 8.40741063899950f, 8.40749948458245f, 8.40587503206534f, 8.40425120040078f,
+ 8.40433955909700f, 8.40271618678552f, 8.40109343558253f, 8.40118131137970f,
+ 8.39955902110142f, 8.39964657715982f, 8.39802474901748f, 8.39640354256068f,
+ 8.39649062227007f, 8.39486987947612f, 8.39324975859040f, 8.39163025950670f,
+ 8.39171671010196f, 8.39180300448298f, 8.39018381508821f, 8.38856524812366f,
+ 8.38694730347691f, 8.38703297721227f, 8.38711849683149f, 8.38550086657194f,
+ 8.38388385923108f, 8.38226747469047f, 8.38235238198133f, 8.38073646806615f,
+ 8.38082107165390f, 8.37920562946549f, 8.37759081052727f, 8.37767496160383f,
+ 8.37606061575931f, 8.37614446717391f, 8.37453059549704f, 8.37461414884609f,
+ 8.37300075239995f, 8.37138797988615f, 8.37147108910541f, 8.36985879313347f,
+ 8.36994160822893f, 8.36832978983540f, 8.36671859574903f, 8.36680097257521f,
+ 8.36519025733977f, 8.36527234391476f, 8.36366210854089f, 8.36205249781910f,
+ 8.36213415188276f, 8.36052502225735f, 8.36060638987481f, 8.35899774233109f,
+ 8.36906328366319f, 8.36745599896731f, 8.36584933792354f, 8.36593087269790f,
+ 8.36432469282948f, 8.36440594331694f, 8.36280024559060f, 8.36288121327418f,
+ 8.36127599864676f, 8.35967140818186f, 8.35975195441777f, 8.35814784820884f,
+ 8.35822811530357f, 8.35662449428343f, 8.35670448368437f, 8.35510134877630f,
+ 8.35518106192085f, 8.35357841403867f, 8.35365785235434f, 8.35205569240248f,
+ 8.35045415745305f, 8.35053318618056f, 8.34893214024213f, 8.34901089766681f,
+ 8.34741034162095f, 8.34581041077519f, 8.34588876385553f, 8.34428932394983f,
+ 8.34269050924751f, 8.34276846108694f, 8.34284627986358f, 8.34124782440677f,
+ 8.34132537807708f, 8.33972741611141f, 8.33813007984327f, 8.33820723838498f,
+ 8.33828426588748f, 8.33668729339379f, 8.33676405981657f, 8.33349522624397f,
+ 8.33190013122409f, 8.33197650850716f, 8.33205275673382f, 8.33045802938747f,
+ 8.32886392796943f, 8.32893979098194f, 8.32734618754917f, 8.32742179537051f,
+ 8.32582869070157f, 8.32590404461620f, 8.32431143948147f, 8.32438654076529f,
+ 8.32279443592703f, 8.32286928584740f, 8.32127768205985f, 8.32135228187567f,
+ 8.31976117988511f, 8.31983553084688f, 8.31824493139170f, 8.31831903474163f,
+ 8.31672893855239f, 8.31680279552442f, 8.31521320332393f, 8.31362423794623f,
+ 8.31369772764720f, 8.31210926707506f, 8.31218251344738f, 8.31059455838471f,
+ 8.31066756263400f, 8.30908011377724f, 8.30915287710116f, 8.30756593513926f,
+ 8.30763845872760f, 8.30605202434212f, 8.30612430937688f, 8.30453838324206f,
+ 8.30461043089745f, 8.30302501368025f, 8.30309682512281f, 8.30151191748300f,
+ 8.30158349387164f, 8.29999909646184f, 8.30007043894792f, 8.29848655241367f,
+ 8.29855766214103f, 8.29697428712085f, 8.29704516522590f, 8.29546230235136f,
+ 8.29553294996313f, 8.29395059985889f, 8.29402101809908f, 8.29243918138296f,
+ 8.29250937136602f, 8.29092804864905f, 8.29099801148223f, 8.28941720336873f,
+ 8.28948694015212f, 8.28790664723974f, 8.28797615906635f, 8.28639638194612f,
+ 8.28646566990194f, 8.28488640915835f, 8.28495547432238f, 8.28337673053339f,
+ 8.28344557397773f, 8.28186734771489f, 8.28193597050476f, 8.27017819449824f,
+ 8.27024585417908f, 8.26866792233384f, 8.26873536584578f, 8.26715795557297f,
+ 8.26722518394961f, 8.26564829578422f, 8.26571531005260f, 8.26413894452349f,
+ 8.26420574570412f, 8.26262990333412f, 8.26269649244104f, 8.26276297588936f,
+ 8.26118755178779f, 8.25961275728051f, 8.25967892525651f, 8.25810465544098f,
+ 8.25817061434708f, 8.25823646908936f, 8.25666262054728f, 8.25672826770033f,
+ 8.25515494533288f, 8.25522038587603f, 8.25364759016769f, 8.25371282507417f,
+ 8.25214055650372f, 8.25220558674063f, 8.25063384578123f, 8.25069867230963f,
+ 8.24912745942885f, 8.24919208320380f, 8.24925660595830f, 8.24768582083426f,
+ 8.24775014225673f, 8.24617988660073f, 8.24624400763143f, 8.24467428189162f,
+ 8.24473820346495f, 8.24316900808411f, 8.24323273112868f, 8.24166406654423f,
+ 8.24172759198290f, 8.24179101896291f, 8.24022278737693f, 8.24028601812464f,
+ 8.23871831864912f, 8.23878135407322f, 8.23721418712705f, 8.23727702813061f,
+ 8.23733977226080f, 8.23577304160806f, 8.23583559266193f, 8.23426939580623f,
+ 8.23433175467303f, 8.23276609201523f, 8.23282825957879f, 8.23126313151474f,
+ 8.23132510865348f, 8.22976051557408f, 8.22982230316103f, 8.22988399629783f,
+ 8.22831984435517f, 8.22838134923978f, 8.22681773347944f, 8.22687905097167f,
+ 8.22694027508851f, 8.22537710272175f, 8.22543814072614f, 8.22387550570830f,
+ 8.22393635844707f, 8.22237426113974f, 8.22243492945458f, 8.22087337021466f,
+ 8.22093385494218f, 8.22099424818818f, 8.21943313609370f, 8.21787265404081f,
+ 8.21793277408334f, 8.21799280346968f, 8.21643277007580f, 8.21649261876342f,
+ 8.21493312522628f, 8.21499279402937f, 8.21505237319400f, 8.21349333040847f,
+ 8.21355273090070f, 8.21199422903237f, 8.21205345165425f, 8.21211258564023f,
+ 8.21055453657232f, 8.20899711749525f, 8.20905598676346f, 8.20911476818710f,
+ 8.20755780332721f, 8.20761640965019f, 8.20767492871591f, 8.20611841935722f,
+ 8.20456253992591f, 8.20462079838524f, 8.20467897036231f, 8.20473705604943f,
+ 8.20318154739142f, 8.20323946107331f, 8.20168449663402f, 8.20174223907312f,
+ 8.20018781913647f, 8.20024539109073f, 8.19869151593658f, 8.19874891815950f,
+ 8.19719558806369f, 8.19725282130430f, 8.19730997033329f, 8.19736703533627f,
+ 8.19581408270369f, 8.19265325254094f, 8.19271006657415f, 8.19115900249672f,
+ 8.19121565013490f, 8.18966513207149f, 8.18650958272842f, 8.18656598214056f,
+ 8.18501734969057f, 8.18346934519575f, 8.18192196836458f, 8.17717170379845f,
+ 8.17562699749445f, 8.17408291704024f, 8.17253946214471f, 8.17099663251667f,
+ 8.16945442786483f, 8.16791284789780f, 8.16796835096100f, 8.16642731496180f,
+ 8.16488690323892f, 8.16334711550016f, 8.16180795145325f, 8.16026941080583f,
+ 8.15873149326542f, 8.15878643699898f, 8.15724906305914f, 8.15571231181225f,
+ 8.15417618296508f, 8.15264067622436f, 8.15269522559432f, 8.15116026230331f,
+ 8.14962592070057f, 8.14809220049210f, 8.14655910138382f, 8.14502662308157f,
+ 8.14508070479135f, 8.14354876964219f, 8.14201745487630f, 8.14048676019884f,
+ 8.14054053346655f, 8.13901038188417f, 8.13748084996421f, 8.13595193741119f,
+ 8.13442364392953f, 8.13289596922361f, 8.13294928474971f, 8.13142215280177f,
+ 8.12989563919925f, 8.12836974364590f, 8.12842275724862f, 8.12689740436780f,
+ 8.12537266910277f, 8.12384855115666f, 8.12390126539209f, 8.12237769002218f,
+ 8.12085473153483f, 8.11933238963259f, 8.11938480702804f, 8.11786300759498f,
+ 8.11634182430774f, 8.11482125686830f, 8.11487337992274f, 8.11335335483497f,
+ 8.11183394515285f, 8.11031515057783f, 8.10879697081129f, 8.10727940555463f,
+ 8.10733109172207f, 8.10581406839611f, 8.10429765913410f, 8.10278186363689f,
+ 8.10283326158928f, 8.10131800788042f, 8.09980336748775f, 8.09828934011163f,
+ 8.09834045225178f, 8.09682696651178f, 8.09531409333708f, 8.09380183242756f,
+ 8.09229018348308f, 8.09234094169636f, 8.09082983407241f, 8.09088045174303f,
+ 8.08780945305625f, 8.08630017906285f, 8.08635058701088f, 8.08484185400836f,
+ 8.08489212286426f, 8.08338393098375f, 8.08187634939786f, 8.08192641069197f,
+ 8.08041937019749f, 8.07891293953684f, 8.07740711840818f, 8.07745690494605f,
+ 8.07595162471175f, 8.07444695354630f, 8.07294289114748f, 8.07143943721306f,
+ 8.07148888347334f, 8.06998597006411f, 8.06848366465346f, 8.06698196693880f,
+ 8.06548087661756f, 8.06552998607523f, 8.06402943589713f, 8.06252949264403f,
+ 8.06103015601301f, 8.06107899849888f, 8.05958020178404f, 8.05808201122071f,
+ 8.05658442650561f, 8.05663300418972f, 8.05513595915549f, 8.05363951949682f,
+ 8.05368789998958f, 8.05219199993907f, 8.05069670478969f, 8.04920201423756f,
+ 8.04925013366991f, 8.04775598247604f, 8.04626243540297f, 8.04476949214651f,
+ 8.04481735262478f, 8.04332494846872f, 8.04183314765086f, 8.04188081528225f,
+ 8.04038955347468f, 8.03889889452528f, 8.03740883812929f, 8.03745625043850f,
+ 8.03596673278105f, 8.03447781719510f, 8.03452503935586f, 8.03303666240761f,
+ 8.03154888704735f, 8.03006171296983f, 8.03010868337276f, 8.02862204764774f,
+ 8.02713601272015f, 8.02565057828453f, 8.02569729893665f, 8.02421240256096f,
+ 8.02272810619019f, 8.02124440951864f, 8.02129088240572f, 8.01980772349432f,
+ 8.01985407323696f, 8.01837145214721f, 8.01688943008388f, 8.01540800674083f,
+ 8.01392718181196f, 8.01397322582548f, 8.01401920905608f, 8.01253886078973f,
+ 8.01105911056564f, 8.00957995807722f, 8.00810140301796f, 8.00814708413104f,
+ 8.00819270517784f, 8.00519164505985f, 8.00523714632877f, 8.00376026217617f,
+ 8.00380564413810f, 8.00232929694652f, 8.00085354600357f, 7.99937839100213f,
+ 7.99942353575290f, 7.99946862149134f, 7.99647489443730f, 7.99651986249756f,
+ 7.99504637603060f, 7.99357348450695f, 7.99210118761919f, 7.99214592170044f,
+ 7.99067416093170f, 7.98920299429772f, 7.98924755409054f, 7.98777692341388f,
+ 7.98782136757941f, 7.98635127289017f, 7.98488177163773f, 7.98492604320402f,
+ 7.98345707777071f, 7.98198870526966f, 7.98052092539286f, 7.98056496838578f,
+ 7.97909772395840f, 7.97914165332759f, 7.97767494437153f, 7.97620882733528f,
+ 7.97625258709119f, 7.97478700534684f, 7.97332201501439f, 7.97185761578544f,
+ 7.97039380735165f, 7.97043728659283f, 7.96897401286660f, 7.96751132942632f,
+ 7.96755464165088f, 7.96609249272969f, 7.96463093358420f, 7.96467407975223f,
+ 7.96321305493386f, 7.96325609092729f, 7.96179560044416f, 7.96033569902192f,
+ 7.96037857054268f, 7.95891920325775f, 7.95746042452055f, 7.95750313250930f,
+ 7.95604488770810f, 7.95458723094048f, 7.95462977633074f, 7.95317265329447f,
+ 7.95171611777669f, 7.95175850149487f, 7.95030249950052f, 7.95034477594852f,
+ 7.94888930747411f, 7.94743442579445f, 7.94747654209885f, 7.94602219372557f,
+ 7.94456843162926f, 7.94461038869789f, 7.94315715969122f, 7.94319901110364f,
+ 7.94174631517672f, 7.94029420479812f, 7.94033589847266f, 7.93888432095161f,
+ 7.93743332845856f, 7.93747486528495f, 7.93602440542419f, 7.93457453007028f,
+ 7.93461591093157f, 7.93316656798164f, 7.93320784535352f, 7.93175903478923f,
+ 7.93031080799686f, 7.93035193086073f, 7.92890423622049f, 7.92745712482865f,
+ 7.92749809405007f, 7.92605151457391f, 7.92609238184470f, 7.92464633425995f,
+ 7.92320086918425f, 7.92324158424087f, 7.92179665081508f, 7.92035229937259f,
+ 7.92039286306353f, 7.91894904302663f, 7.91898950627539f, 7.91754621761402f,
+ 7.91610351019241f, 7.91614382347568f, 7.91470164718040f, 7.91474186094918f,
+ 7.91330021574662f, 7.91185915103762f, 7.91041866651197f, 7.91045868235363f,
+ 7.91049864894173f, 7.90905864587311f, 7.90761922254927f, 7.90618037865992f,
+ 7.90622014914004f, 7.90625987081860f, 7.90334410091085f, 7.90338372525529f,
+ 7.90194652065353f, 7.90198604802103f, 7.90054937343709f, 7.89911327700454f,
+ 7.89915265957254f, 7.89771709289137f, 7.89775637936779f, 7.89632134239166f,
+ 7.89488688281196f, 7.89492602580883f, 7.89349209566332f, 7.89353114344322f,
+ 7.89209774268232f, 7.89213669559212f, 7.89070382416489f, 7.88927152915260f,
+ 7.88931034040396f, 7.88787857444832f, 7.88791729168944f, 7.88648605473636f,
+ 7.88652467830826f, 7.88509397030232f, 7.87347922114931f, 7.87351729104996f,
+ 7.87208727383296f, 7.87212525190789f, 7.87069576429284f, 7.86926685183945f,
+ 7.86930469279725f, 7.86787630965334f, 7.86791405961169f, 7.86648620571214f,
+ 7.86505892620407f, 7.86509654027728f, 7.86366978971717f, 7.86370731360733f,
+ 7.86228109192717f, 7.86231852595811f, 7.86089283308866f, 7.86093017758265f,
+ 7.85950501345345f, 7.85808042248116f, 7.85811763327064f, 7.85669357073507f,
+ 7.85673069278658f, 7.85530715861446f, 7.85388419682346f, 7.85392118636180f,
+ 7.85249875262700f, 7.85253565421687f, 7.85111374846223f, 7.84969241431120f,
+ 7.84972918456513f, 7.84830837808339f, 7.84834506116903f, 7.84692478227781f,
+ 7.84696137850464f, 7.84554162712403f, 7.84412244633333f, 7.84415891284905f,
+ 7.84274025925302f, 7.85141288690937f, 7.85144961512784f, 7.85003244871711f,
+ 7.85006909037938f, 7.84865244984218f, 7.84868900525374f, 7.84727289050818f,
+ 7.84730935997309f, 7.84589377093614f, 7.84593015475706f, 7.84451509134460f,
+ 7.84310059603029f, 7.84313685194958f, 7.84172288193889f, 7.84175905296461f,
+ 7.84179518165529f, 7.84038169460074f, 7.83896877493622f, 7.83900477706657f,
+ 7.83759238244247f, 7.83618055466107f, 7.83621643089471f, 7.83480512782671f,
+ 7.83484092049560f, 7.83343014204975f, 7.83346585144543f, 7.83205559752943f,
+ 7.83209122394205f, 7.83068149446259f, 7.83071703818099f, 7.82930783304372f,
+ 7.82789919324926f, 7.82793461346494f, 7.82652649767837f, 7.82656183591605f,
+ 7.82515424404068f, 7.82518950058452f, 7.82378243252265f, 7.82381760765553f,
+ 7.82241106330847f, 7.82244615731193f, 7.81815980032046f, 7.81963467968251f,
+ 7.81822978630920f, 7.81682545615005f, 7.81542168889519f, 7.81545654118684f,
+ 7.81405329648404f, 7.81408806875962f, 7.81268534650601f, 7.81272003904066f,
+ 7.81131783913241f, 7.81135245220004f, 7.80995077453237f, 7.80998530840561f,
+ 7.80858415287283f, 7.80718355872843f, 7.80721797431856f, 7.80581790196027f,
+ 7.80585223903216f, 7.80445268835214f, 7.80448694717412f, 7.80308791806361f,
+ 7.80312209890276f, 7.80172359125211f, 7.80175769437431f, 7.80035970807297f,
+ 7.80039373374288f, 7.79899626867941f, 7.79903021716051f, 7.79763327322259f,
+ 7.79766714477715f, 7.79627072185158f, 7.79630451674069f, 7.79490861471341f,
+ 7.79494233319698f, 7.79354695195305f, 7.79215212935342f, 7.79218573371345f,
+ 7.79221930016098f, 7.79082496013553f, 7.78943117826415f, 7.78946463135824f,
+ 7.78807136967477f, 7.78810474751849f, 7.78671200590435f, 7.78674530875124f,
+ 7.78677857419443f, 7.78538631518947f, 7.78399461335494f, 7.78402776696423f,
+ 7.78263658483832f, 7.78266966420460f, 7.78270270654283f, 7.78131200703774f,
+ 7.77992186396267f, 7.77995479558889f, 7.77856517185444f, 7.77859802998139f,
+ 7.77863085145093f, 7.77724171033669f, 7.77585312490987f, 7.77588583677433f,
+ 7.77449777031297f, 7.77453040941203f, 7.77456301221936f, 7.77317542836560f,
+ 7.77178839945454f, 7.77182089374904f, 7.77043438342129f, 7.77046680567449f,
+ 7.77049919199683f, 7.76911316425229f, 7.76772769070368f, 7.76775996959096f,
+ 7.76637501423668f, 7.76640722179721f, 7.76502278450610f, 7.76505492097597f,
+ 7.76367100161614f, 7.76370306723039f, 7.76373509750465f, 7.76235166066185f,
+ 7.76096877676598f, 7.76100070136998f, 7.75961833500535f, 7.75965018945267f,
+ 7.75968200890831f, 7.75830012500606f, 7.75691879329882f, 7.75695050812457f,
+ 7.75698218818832f, 7.75560133890093f, 7.75563294961187f, 7.75425261742615f,
+ 7.75287283668173f, 7.75290434378954f, 7.75152507975708f, 7.75155651807875f,
+ 7.75158792209177f, 7.75020914037975f, 7.74883090935359f, 7.74745322870535f,
+ 7.74748449604369f, 7.74610733143631f, 7.74613853077156f, 7.74476188206386f,
+ 7.74479301361756f, 7.74341688066770f, 7.74344794466043f, 7.74347897495509f,
+ 7.74210332397728f, 7.74072822211493f, 7.74075915164364f, 7.74079004769272f,
+ 7.73941542773344f, 7.73944625698609f, 7.73807215231902f, 7.73810291499155f,
+ 7.73672932547114f, 7.73676002177895f, 7.73538694725902f, 7.73541757741657f,
+ 7.73404501775030f, 7.73407558197112f, 7.73270353701110f, 7.73273403550780f,
+ 7.73136250510597f, 7.73139293809028f, 7.73142333839748f, 7.73005228978068f,
+ 7.72868178804865f, 7.72871209063963f, 7.72874236076320f, 7.72737234072627f,
+ 7.72740254607128f, 7.72603304009822f, 7.72606318087234f, 7.72469418881164f,
+ 7.72472426522164f, 7.72335578692120f, 7.72338579917296f, 7.72341577942255f,
+ 7.72204778277866f, 7.72068033154013f, 7.72071021608960f, 7.72074006884081f,
+ 7.71937309915523f, 7.71940288846195f, 7.71803643202356f, 7.71806615808777f,
+ 7.71670021474117f, 7.71672987776400f, 7.71536444735324f, 7.71399956106752f,
+ 7.71402912990351f, 7.71405866744353f, 7.71269426243436f, 7.71272373753127f,
+ 7.71135984498676f, 7.71138925783831f, 7.71002587760030f, 7.71005522840340f,
+ 7.70869236031320f, 7.70872164926393f, 7.70875090736174f, 7.70738852045593f,
+ 7.70602667618316f, 7.70605584201409f, 7.70608497718635f, 7.70472361397175f,
+ 7.70475268797144f, 7.70339183636089f, 7.70342084938044f, 7.70344983198180f,
+ 7.70208946144320f, 7.70211838335150f, 7.70075852418828f, 7.70078738559392f,
+ 7.69942803764294f, 7.69945683873552f, 7.69809800183312f, 7.69812674280145f,
+ 7.69815545377820f, 7.69679709781559f, 7.69682574894983f, 7.69546790380054f,
+ 7.69549649527912f, 7.69552505699968f, 7.69416769278661f, 7.69419619513033f,
+ 7.69283934149161f, 7.69286778464339f, 7.69151144141215f, 7.69015563785611f,
+ 7.69018399256504f, 7.69021231788464f, 7.68885699496583f, 7.68888526164366f,
+ 7.68891349906885f, 7.68755865684680f, 7.68620435356727f, 7.68623250350642f,
+ 7.68626062437385f, 7.68490680163368f, 7.68493486449261f, 7.68358155123853f,
+ 7.68360955626822f, 7.68225675232974f, 7.68228469970871f, 7.68231261832904f,
+ 7.68096029482092f, 7.68098815605693f, 7.67963634161052f, 7.67966414563891f,
+ 7.67831284008200f, 7.67834058707873f, 7.67836830562541f, 7.67701748037903f,
+ 7.67704514215666f, 7.67569482554126f, 7.67572243072402f, 7.67437262256575f,
+ 7.67440017132709f, 7.67442769194256f, 7.67307836396437f, 7.67172957219709f,
+ 7.67175700863318f, 7.67040872479895f, 7.67043610532978f, 7.67046345797203f,
+ 7.66911565404928f, 7.66914295104199f, 7.66917022027359f, 7.66782289629849f,
+ 7.66785011013471f, 7.66650329373374f, 7.66653045234317f, 7.66518414333889f,
+ 7.66521124688943f, 7.66523832297326f, 7.66389249376287f, 7.66254719901806f,
+ 7.66257419295179f, 7.66260115958519f, 7.66262809895966f, 7.66128325660027f,
+ 7.66131014158067f, 7.65996580606912f, 7.65999263682000f, 7.65864880797621f,
+ 7.65867558466144f, 7.65870233437509f, 7.65735898508777f, 7.65738568098033f,
+ 7.65604283808071f, 7.65606948031442f, 7.65472714362097f, 7.65475373235741f,
+ 7.65478029440560f, 7.65343843708835f, 7.65346494588041f, 7.65349142810445f,
+ 7.65215005018116f, 7.65080920452514f, 7.65083560728422f, 7.65086198363444f,
+ 7.64952161716499f, 7.64954794081617f, 7.64957423817702f, 7.64823435090775f,
+ 7.64826059580594f, 7.64692121388197f, 7.64694740647428f, 7.64560852971063f,
+ 7.64563467015326f, 7.64566078457940f, 7.64432238681307f, 7.64434844932262f,
+ 7.64301055642301f, 7.64303656717059f, 7.64306255209497f, 7.64172513809099f,
+ 7.64175107148420f, 7.64041416205060f, 7.64044004406572f, 7.64046590044903f,
+ 7.63912946980476f, 7.63915527503849f, 7.63918105475433f, 7.63784510290134f,
+ 7.63787083169477f, 7.63653538400034f, 7.63656106202205f, 7.63522611829733f,
+ 7.63525174569743f, 7.63527734784282f, 7.63394288268123f, 7.63396843442906f,
+ 7.63263447293292f, 7.63265997443180f, 7.63268545086176f, 7.63135196780901f,
+ 7.63137739421188f, 7.63004441451777f, 7.63006979104072f, 7.63009514267872f,
+ 7.62876264130389f, 7.62878794328165f, 7.62745594495614f, 7.62748119741940f,
+ 7.62750642517989f, 7.62617490504528f, 7.62620008350880f, 7.62622523737801f,
+ 7.62489419542260f, 7.62491930021111f, 7.62358876087232f, 7.62361381672361f,
+ 7.62228377980812f, 7.62230878686512f, 7.62233376957839f, 7.62100421058442f,
+ 7.62102914471672f, 7.61970008782946f, 7.61972497352234f, 7.61974983504840f,
+ 7.61842125594179f, 7.61844606923969f, 7.61847085847612f, 7.61714275713074f,
+ 7.61716749834905f, 7.61583989866594f, 7.61586459200549f, 7.61588926145774f,
+ 7.61456213938845f, 7.61458676116997f, 7.61326014044020f, 7.61328471468899f,
+ 7.61330926522300f, 7.61198312195571f, 7.61200762516301f, 7.61203210475825f,
+ 7.61070643892753f, 7.61073087140089f, 7.60940570645537f, 7.60943009194275f,
+ 7.60945445398794f, 7.60812976632134f, 7.60815408158342f, 7.60817837350445f,
+ 7.60685416308698f, 7.60687840842660f, 7.60555469843407f, 7.60557889732612f,
+ 7.60560307304439f, 7.60427984013719f, 7.60430396960766f, 7.60432807600398f,
+ 7.60300532014849f, 7.60302938049563f, 7.60170712459905f, 7.60173113902882f,
+ 7.60175513054917f, 7.60043335153450f, 7.60045729733421f, 7.60048122032260f,
+ 7.59915991815251f, 7.59918379561589f, 7.59786299293304f, 7.59788682500121f,
+ 7.59791063442030f, 7.59659030840635f, 7.59661407262401f, 7.59663781428919f,
+ 7.59531796490316f, 7.59534166155958f, 7.59402231118364f, 7.59404596295913f,
+ 7.59406959234195f, 7.59275071841253f, 7.59277430310528f, 7.59279786550050f,
+ 7.59147946797307f, 7.59150298586800f, 7.59018508686814f, 7.59020856038869f,
+ 7.59023201176912f, 7.58891458898425f, 7.58893799617829f, 7.58896138132594f,
+ 7.58764443470803f, 7.58766777585621f, 7.58635132727817f, 7.58637462455093f,
+ 7.58639789993235f, 7.58508192732879f, 7.58510515901996f, 7.58512836891210f,
+ 7.58515155703590f, 7.58383603861766f, 7.58385918329649f, 7.58254416248636f,
+ 7.58256726384219f, 7.58259034358211f, 7.58127579858836f, 7.58129883518735f,
+ 7.58132185026121f, 7.58000778102858f, 7.58003075314258f, 7.57871718101943f,
+ 7.57874011029371f, 7.57876301819304f, 7.57744992162713f, 7.57747278686613f,
+ 7.57749563081961f, 7.57618300975245f, 7.57620581122397f, 7.57622859149893f,
+ 7.57491644587078f, 7.57493918384116f, 7.57496190070343f, 7.57365023045334f,
+ 7.57367290518743f, 7.57369555890135f, 7.57238436396716f, 7.57240697572833f,
+ 7.57109627695034f, 7.57111884687516f, 7.57114139592532f, 7.56983117224850f,
+ 7.56985367963612f, 7.56987616623575f, 7.56856641759483f, 7.56858886270476f,
+ 7.56861128711287f, 7.56730201344145f, 7.56732439653175f, 7.56734675900595f,
+ 7.56603796023641f, 7.56606028156374f, 7.56608258236019f, 7.56477425842381f,
+ 7.56479651824339f, 7.56348868948821f, 7.56351090844373f, 7.56353310700940f,
+ 7.56355528521325f, 7.56224791073235f, 7.56227004829653f, 7.56229216558275f,
+ 7.56098526572191f, 7.56100734253566f, 7.55970093738852f, 7.55972297384077f,
+ 7.55974499015377f, 7.55843905939626f, 7.55846103551346f, 7.55848299157400f,
+ 7.55850492760535f, 7.55719945116063f, 7.55722134721568f, 7.55724322332355f,
+ 7.55593822119919f, 7.55596005749435f, 7.55465554945120f, 7.55467734604222f,
+ 7.55469912282176f, 7.55339508886160f, 7.54282966651951f, 7.55343854360594f,
+ 7.55346024140898f, 7.55215666177545f, 7.55217832025123f, 7.55087523421793f,
+ 7.54031819934936f, 7.54033979903436f, 7.53904143572760f, 7.53906299635162f,
+ 7.53908453748486f, 7.54306747979114f, 7.54837830652259f, 7.54839978934178f,
+ 7.54709812458524f, 7.53655365351434f, 7.53657507825590f, 7.53527812830351f,
+ 7.53529951445738f, 7.54588255528895f, 7.54590390295925f, 7.54460316609662f,
+ 7.54462447538711f, 7.53408833025382f, 7.53279230299647f, 7.53281355491099f,
+ 7.53151801756132f, 7.53153923135380f, 7.53156042612371f, 7.53158160189662f,
+ 7.53028651627133f, 7.53030765412677f, 7.53032877306164f, 7.52903415812099f,
+ 7.52905523929085f, 7.52776111376522f, 7.52778215727126f, 7.52780318198321f,
+ 7.52782418792625f, 7.52653051408721f, 7.52655148256772f, 7.52657243235452f,
+ 7.52527922893053f, 7.52530014140483f, 7.52532103526024f, 7.52402830215954f,
+ 7.52404915885167f, 7.52406999699933f, 7.52277773412920f, 7.52279853526202f,
+ 7.52281931792438f, 7.52284008214087f, 7.52154827098634f, 7.52156899838468f,
+ 7.52027767569381f, 7.52029836637182f, 7.52031903872623f, 7.52033969278137f,
+ 7.51904882176237f, 7.51906943929178f, 7.51909003859465f, 7.51779963749868f,
+ 7.51782020042086f, 7.51784074518883f, 7.51655081391820f, 7.51657132244977f,
+ 7.51659181289909f, 7.51530235135519f, 7.51532280571164f, 7.51534324205739f,
+ 7.51536366041622f, 7.51407465053640f, 7.51409503299255f, 7.51280651060282f,
+ 7.51282685725088f, 7.51284718603027f, 7.51286749696450f, 7.51157942617877f,
+ 7.51159970149310f, 7.51161995903261f, 7.51033235764065f, 7.51035257970054f,
+ 7.51037278405555f, 7.50908565195404f, 7.50910582096898f, 7.50912597234864f,
+ 7.50783930943340f, 7.50785942561180f, 7.50787952422413f, 7.50789960529340f,
+ 7.50661339393931f, 7.50663343999128f, 7.50534771513269f, 7.50536772625885f,
+ 7.50538771995631f, 7.50540769624784f, 7.50412242287476f, 7.50414236442252f,
+ 7.50416228863237f, 7.50418219552691f, 7.50289737369020f, 7.50291724602175f,
+ 7.50163291019824f, 7.50165274805672f, 7.50167256871229f, 7.50169237218731f,
+ 7.50040848781655f, 7.50042825699740f, 7.50044800906457f, 7.49916459326124f,
+ 7.49918431116761f, 7.49920401202679f, 7.49792106467948f, 7.49794073151054f,
+ 7.49796038136060f, 7.49667790235710f, 7.49669751831102f, 7.49671711734975f,
+ 7.49673669949516f, 7.49545467185099f, 7.49547422027520f, 7.49549375187145f,
+ 7.49421219240963f, 7.49423169041509f, 7.49425117165763f, 7.49297008026330f,
+ 7.49298952804478f, 7.49300895912805f, 7.49302837353459f, 7.49174773343687f,
+ 7.49176711455430f, 7.49178647905926f, 7.49050630686120f, 7.49052563820524f,
+ 7.49054495300073f, 7.48926524858490f, 7.48928453034700f, 7.48930379562416f,
+ 7.48932304443751f, 7.48804379124302f, 7.48806300719200f, 7.48808220674033f,
+ 7.48680342115406f, 7.48682258796403f, 7.48684173843620f, 7.48556342033819f,
+ 7.48558253819737f, 7.48560163978127f, 7.48562072511066f, 7.48434285814650f,
+ 7.48436191102906f, 7.48438094771922f, 7.48310354806328f, 7.48312255243049f,
+ 7.48314154066708f, 7.48316051279358f, 7.48188356423386f, 7.48190250420160f,
+ 7.48192142812062f, 7.48064494668490f, 7.48066383856759f, 7.48068271446260f,
+ 7.47940670002678f, 7.47942554400726f, 7.47944437206081f, 7.47946318420761f,
+ 7.47818762076032f, 7.47820640115404f, 7.47822516570133f, 7.47824391442227f,
+ 7.47696880197852f, 7.47698751910672f, 7.47571288915281f, 7.47573157476804f,
+ 7.47575024465661f, 7.47576889883838f, 7.47449471975386f, 7.47451334258139f,
+ 7.47453194976145f, 7.47455054131374f, 7.47327681310897f, 7.47329537346471f,
+ 7.47202212722719f, 7.47204065646482f, 7.47205917017273f, 7.47207766837044f,
+ 7.47080487287198f, 7.47082334010767f, 7.47084179189150f, 7.47086022824284f,
+ 7.46958788348929f, 7.46960628903368f, 7.46962467920354f, 7.46835280053496f,
+ 7.46837116001347f, 7.46838950417511f, 7.46840783303904f, 7.46713640504500f,
+ 7.46715470337084f, 7.46717298645624f, 7.46719125432022f, 7.46592027700163f,
+ 7.46593851447977f, 7.46595673679339f, 7.46597494396140f, 7.46470441731737f,
+ 7.46472259425075f, 7.46345254840048f, 7.46347069517447f, 7.46348882689689f,
+ 7.46350694358646f, 7.46223734825421f, 7.46225543493411f, 7.46227350663713f,
+ 7.46229156338184f, 7.46102241856245f, 7.46104044544623f, 7.46105845742730f,
+ 7.45978977797966f, 7.45980776021071f, 7.45982572759437f, 7.45855751338129f,
+ 7.45857545112528f, 7.45859337407692f, 7.45861128225450f, 7.45734351838243f,
+ 7.45736139706664f, 7.45737926103147f, 7.45611196217244f, 7.45612979675298f,
+ 7.45614761666857f, 7.45616542193726f, 7.45489857332325f, 7.45491634935229f,
+ 7.45493411078849f, 7.45495185764981f, 7.45368545926693f, 7.45370317703227f,
+ 7.45372088027644f, 7.45245494659468f, 7.45247262084999f, 7.45249028063757f,
+ 7.45250792597517f, 7.45124244242089f, 7.45126005891167f, 7.45127766100555f,
+ 7.45129524872019f, 7.45003021527506f, 7.45004777428398f, 7.44878321952857f,
+ 7.44880074990199f, 7.44881826598392f, 7.44883576779183f, 7.43727548639956f,
+ 7.43729277382540f, 7.43731004718073f, 7.43732730648274f, 7.43606346612857f,
+ 7.43608069737530f, 7.43609791462004f, 7.43483453871790f, 7.43485172800980f,
+ 7.43486890335078f, 7.43488606475783f, 7.43362313924374f, 7.43364027283374f,
+ 7.43365739254057f, 7.43367449838109f, 7.43241202322571f, 7.43242910138409f,
+ 7.43244616572660f, 7.43118415468149f, 7.43120119144248f, 7.43121821443777f,
+ 7.43123522368404f, 7.42997366286784f, 7.42999064466599f, 7.43000761276498f,
+ 7.43002456718139f, 7.42876345656070f, 7.42878038366152f, 7.42879729712929f,
+ 7.42753665026940f, 7.42755353652043f, 7.42757040918772f, 7.42758726828765f,
+ 7.42632707148660f, 7.42634390350084f, 7.42636072199670f, 7.42637752699047f,
+ 7.42511778021092f, 7.42513455824921f, 7.42387528831073f, 7.42389203945833f,
+ 7.42390877718483f, 7.42392550150634f, 7.42266668138160f, 7.42268337894139f,
+ 7.42270006314441f, 7.42271673400666f, 7.42145836365485f, 7.42147500788352f,
+ 7.42149163881933f, 7.42023373145931f, 7.42025033585711f, 7.42026692700973f,
+ 7.42028350493299f, 7.41902604719678f, 7.41904259870875f, 7.41905913703874f,
+ 7.41907566220248f, 7.41781865404551f, 7.41783515292387f, 7.41785163868306f,
+ 7.41659509314730f, 7.41661155271502f, 7.41662799921040f, 7.41664443264901f,
+ 7.41538833653703f, 7.41540474390869f, 7.41542113827012f, 7.41543751963679f,
+ 7.41418187290033f, 7.41419822832378f, 7.41421457079872f, 7.41295938630599f,
+ 7.41297570292999f, 7.41299200665152f, 7.41300829748587f, 7.41175356220701f,
+ 7.41176982731279f, 7.41178607957713f, 7.41180231901523f, 7.41054803289840f,
+ 7.41056424672953f, 7.40931043523787f, 7.40932662352253f, 7.40934279905659f,
+ 7.40935896185510f, 7.40937511193310f, 7.40812173667013f, 7.40813786135211f,
+ 7.40815397335853f, 7.40817007270433f, 7.40691714638039f, 7.40693322044968f,
+ 7.40568076819554f, 7.40569681704778f, 7.40571285331374f, 7.40572887700822f,
+ 7.40574488814600f};
+
+// Set of scalers, one per reverberation time, by which the
+// |kHighCorrectionCurve| and |kLowCorrectionCurve| curves are multiplied in
+// order to generate the correct onset compensation curves.
+static const float kCurveCorrectionMultipliers[kNumFeedbackValues] = {
+ 0.000249027612622225f, 0.0475827382701585f, 0.0982856973675534f,
+ 0.144077780284872f, 0.187710331328442f, 0.229214552437128f,
+ 0.268761703298196f, 0.306384317687497f, 0.342116205684862f,
+ 0.376122154314109f, 0.408019265118341f, 0.438826303187204f,
+ 0.468213758592444f, 0.496269855121223f, 0.523103160344453f,
+ 0.548734562484123f, 0.573191744554386f, 0.596776538466997f,
+ 0.619556090502133f, 0.646894092669191f, 0.661870435136273f,
+ 0.675494733319630f, 0.701821797958321f, 0.713358543560036f,
+ 0.731743894313465f, 0.749694785147017f, 0.758967096040535f,
+ 0.775801399270244f, 0.792218438223182f, 0.808206900102085f,
+ 0.815142557606016f, 0.830420164791760f, 0.845380788487056f,
+ 0.859865023229817f, 0.865296767216337f, 0.879331838452952f,
+ 0.893145291831122f, 0.897272345317607f, 0.910373690471610f,
+ 0.923470208927849f, 0.936268613920194f, 0.940724814169454f,
+ 0.943721434222406f, 0.956465808252697f, 0.959628673835810f,
+ 0.971718784707243f, 0.974554123797995f, 0.977943937294408f,
+ 0.997154666216203f, 0.999999999999996f, 0.00847079214371323f,
+ 0.0104396896429595f, 0.0383165227008017f, 0.0405943838116957f,
+ 0.0685361482242258f, 0.0701917817593536f, 0.0713216738657547f,
+ 0.0986119509733789f, 0.0995868953874107f, 0.127034424762083f,
+ 0.127777689282131f, 0.128246886910136f, 0.155790763336654f,
+ 0.156203946276228f, 0.183007628720406f, 0.182664049029335f,
+ 0.182636700276451f, 0.209980982953741f, 0.209930104556972f,
+ 0.209208261790760f, 0.236016550641923f, 0.235475840865507f,
+ 0.234825009787230f, 0.262017587951252f, 0.260795540834379f,
+ 0.259744215394585f, 0.286998748503651f, 0.286344090244485f,
+ 0.285483640041615f, 0.284539872612409f, 0.311891500333310f,
+ 0.310660815240075f, 0.309428379806926f, 0.336752370009492f,
+ 0.335612040225831f, 0.334119868753728f, 0.332881268861172f,
+ 0.360256878080152f, 0.358861080534800f, 0.357458025447185f,
+ 0.356097715473274f, 0.383869923377680f, 0.382590514632971f,
+ 0.381266229326427f, 0.379680871429225f, 0.407164010760711f,
+ 0.405597486292448f, 0.404000115485411f, 0.402266215035868f,
+ 0.429891973669762f, 0.428453570844335f, 0.426999237668900f,
+ 0.425435248817597f, 0.450978617489268f, 0.449350785137532f,
+ 0.447825393407652f, 0.446242285152424f, 0.444699143006987f,
+ 0.471928084570479f, 0.471460865818911f, 0.469975899073161f,
+ 0.468110718285786f, 0.466267910972978f, 0.492953377248067f,
+ 0.491503646910692f, 0.490004860015654f, 0.488499316392171f,
+ 0.516893492513121f, 0.515545795838069f, 0.514220820105042f,
+ 0.512893659480599f, 0.511085398658644f, 0.509264930798830f,
+ 0.537621048957386f, 0.536165057418577f, 0.534661930692635f,
+ 0.533210489850429f, 0.531756722686728f, 0.530384047322116f,
+ 0.559038131029643f, 0.557822105594252f, 0.556569707547800f,
+ 0.555271214486959f, 0.553432792863170f, 0.551315743703168f,
+ 0.549392825464220f, 0.577982280854402f, 0.576562976619477f,
+ 0.575372635620591f, 0.574072847452013f, 0.572872688648164f,
+ 0.571573384448578f, 0.570329067593286f, 0.599518572118246f,
+ 0.598348121604011f, 0.597160846836955f, 0.595942913014291f,
+ 0.592262360278945f, 0.590949984551833f, 0.589596537782439f,
+ 0.618986568059361f, 0.617798845452536f, 0.616549708449253f,
+ 0.615384701753942f, 0.614192476100642f, 0.612892560298438f,
+ 0.611692826552139f, 0.610490163023757f, 0.609174362863638f,
+ 0.638463194928117f, 0.637028017578980f, 0.635559187798163f,
+ 0.633766413298784f, 0.632208978019593f, 0.630423678935153f,
+ 0.629100361498165f, 0.627683147303628f, 0.626307825147069f,
+ 0.656136973617732f, 0.655009501850360f, 0.653877493459184f,
+ 0.652665127999537f, 0.651558827307289f, 0.650386889118506f,
+ 0.649111048361781f, 0.648028207288007f, 0.646759703278198f,
+ 0.645519124438692f, 0.675436924850795f, 0.674280803735362f,
+ 0.673132340969860f, 0.671373346843144f, 0.670134946644868f,
+ 0.668731343028307f, 0.667428990512785f, 0.666412032897529f,
+ 0.665280139756495f, 0.664193037044164f, 0.694188573172643f,
+ 0.693133764391982f, 0.692048704636038f, 0.690982103678122f,
+ 0.689946461409433f, 0.688925040506954f, 0.687918657972205f,
+ 0.686814035317773f, 0.685752672736224f, 0.684629857976692f,
+ 0.683538212068733f, 0.682502742914018f, 0.712650390189218f,
+ 0.711488074001633f, 0.710454507990280f, 0.709369576447197f,
+ 0.708293103236850f, 0.707161341261432f, 0.706142174509451f,
+ 0.705109933856033f, 0.703938122923563f, 0.702882741466471f,
+ 0.701795805729764f, 0.700970588654440f, 0.699907893809526f,
+ 0.698848748944422f, 0.729459722297675f, 0.728559828909388f,
+ 0.727267491809098f, 0.726368916168934f, 0.725549425012621f,
+ 0.724701162719866f, 0.723729724234480f, 0.722805513390802f,
+ 0.721877511846754f, 0.720923464905931f, 0.720063488137338f,
+ 0.719192489800377f, 0.718234018896418f, 0.748886813504199f,
+ 0.748055970602122f, 0.747192096825651f, 0.746255128515039f,
+ 0.745432542499951f, 0.744527975028176f, 0.743657128539979f,
+ 0.742815568594195f, 0.742016966380996f, 0.741081662145480f,
+ 0.740212516669136f, 0.738752388065193f, 0.737838959848034f,
+ 0.737079784380805f, 0.736207833150401f, 0.735328920674480f,
+ 0.766147300368082f, 0.765383964612946f, 0.764598877501888f,
+ 0.763830319512426f, 0.763071341941492f, 0.762261754967287f,
+ 0.761421505873705f, 0.760683170206014f, 0.759876633831137f,
+ 0.759111799483625f, 0.758326333824362f, 0.757541464414185f,
+ 0.756805357349899f, 0.755956399690542f, 0.755084876598806f,
+ 0.754190942656102f, 0.753440741268157f, 0.752571082952576f,
+ 0.751825304285737f, 0.782969421663051f, 0.782195656629464f,
+ 0.781491207489953f, 0.780796925868243f, 0.780038270784649f,
+ 0.779327959705502f, 0.778571499532576f, 0.777927257784694f,
+ 0.777170483964829f, 0.776461606951210f, 0.775702452890459f,
+ 0.774964094372046f, 0.774261007484278f, 0.773530800147826f,
+ 0.772829253854413f, 0.772012428008542f, 0.771256939594450f,
+ 0.770263007078531f, 0.769608778166788f, 0.768868370726016f,
+ 0.800132675567284f, 0.799414457498671f, 0.798801140955651f,
+ 0.798201875508813f, 0.797562927111111f, 0.796973690523352f,
+ 0.796325305652599f, 0.795751914017312f, 0.795062104562951f,
+ 0.794392825660217f, 0.793833580415710f, 0.793228467372150f,
+ 0.792632556794021f, 0.791987407625815f, 0.791349198936522f,
+ 0.790758300136560f, 0.790155406100658f, 0.789502309522568f,
+ 0.788850663559873f, 0.788244230667833f, 0.787690453856242f,
+ 0.787119319515071f, 0.786556345654314f, 0.785871663518153f,
+ 0.817012925306181f, 0.816430511458010f, 0.815893193830343f,
+ 0.815310874396162f, 0.814695628192059f, 0.814349340761576f,
+ 0.813807195954924f, 0.812960708290203f, 0.812353982324263f,
+ 0.811760341393159f, 0.811129283770446f, 0.810570029805507f,
+ 0.810041997821215f, 0.809539025954020f, 0.808890057582255f,
+ 0.808376532093617f, 0.807788126711313f, 0.807229044495192f,
+ 0.806691599106826f, 0.806133405950557f, 0.805529337345578f,
+ 0.804943724604441f, 0.804359069634119f, 0.803604313367394f,
+ 0.803039009317611f, 0.802427016830483f, 0.801897188869670f,
+ 0.833460875990872f, 0.832877329385786f, 0.832411116216460f,
+ 0.831855344205032f, 0.831306648690096f, 0.830826737217004f,
+ 0.830306337776770f, 0.829837395963940f, 0.829322442611281f,
+ 0.828828529233458f, 0.828227895618978f, 0.827688095121686f,
+ 0.827224825179024f, 0.826744576227558f, 0.826190089131040f,
+ 0.825644348776801f, 0.825111095394709f, 0.824576204498035f,
+ 0.824095489895994f, 0.823551761115446f, 0.823018027544573f,
+ 0.822476448619841f, 0.821809962673621f, 0.821291765423256f,
+ 0.820650961031543f, 0.819911412926238f, 0.819376250438516f,
+ 0.818827507074517f, 0.818298634930539f, 0.817837741058990f,
+ 0.817377454006327f, 0.849050771870725f, 0.848598343034601f,
+ 0.848137761126842f, 0.847720880735919f, 0.847272612414349f,
+ 0.846839043139818f, 0.846310781171764f, 0.845917411128721f,
+ 0.845432276174650f, 0.845016330807497f, 0.844560412891491f,
+ 0.844113268000604f, 0.843717326097535f, 0.843254715180455f,
+ 0.842771923047896f, 0.842317456952523f, 0.841894102789524f,
+ 0.841478900234186f, 0.841073526044248f, 0.840678089199553f,
+ 0.840282881990563f, 0.839851728795932f, 0.839437044180938f,
+ 0.839032992924171f, 0.838674041436160f, 0.838208899506653f,
+ 0.837815592964711f, 0.837413586062667f, 0.836945051441415f,
+ 0.836579931119682f, 0.836103168868015f, 0.835691507888582f,
+ 0.835190824315056f, 0.834796921260984f, 0.834397547217396f,
+ 0.833770693471246f, 0.833382919978899f, 0.865249714600488f,
+ 0.864778611194893f, 0.864359035626832f, 0.863974109667504f,
+ 0.863599275330096f, 0.863175308582704f, 0.862750738409356f,
+ 0.862410936451282f, 0.862060660613492f, 0.861703069468698f,
+ 0.861338903148747f, 0.860962071126888f, 0.860613235617068f,
+ 0.860255115049830f, 0.859941728589139f, 0.859556867553160f,
+ 0.859129368056343f, 0.858719511777174f, 0.858375007251166f,
+ 0.857991574276656f, 0.857077372527853f, 0.856709203488606f,
+ 0.856338576783691f, 0.855985971077822f, 0.855629124525839f,
+ 0.855290191537388f, 0.854966165735379f, 0.854612291162095f,
+ 0.854327456524765f, 0.854015841793238f, 0.853649356402945f,
+ 0.853317984411307f, 0.852952982901721f, 0.852579010983093f,
+ 0.852262745823692f, 0.851907995774951f, 0.851574167335807f,
+ 0.851264191083115f, 0.850902019876735f, 0.850580011598579f,
+ 0.850225307767087f, 0.849838013922043f, 0.881877389068535f,
+ 0.881425634756149f, 0.881222935599140f, 0.880862887645329f,
+ 0.880558209099982f, 0.880114949740768f, 0.879806159434422f,
+ 0.879538932468558f, 0.879173454249472f, 0.878803642529878f,
+ 0.878488774313953f, 0.878152689099870f, 0.877787934867571f,
+ 0.877472544637065f, 0.877200689447213f, 0.876929820734263f,
+ 0.876616544942982f, 0.876339352367848f, 0.876037900545338f,
+ 0.875737826612020f, 0.875450927592556f, 0.875146075620635f,
+ 0.874847876858510f, 0.874531696275083f, 0.874232625014850f,
+ 0.873956654705092f, 0.873657406655665f, 0.873376193316924f,
+ 0.873085430435485f, 0.872758743496618f, 0.872421095892080f,
+ 0.872098708018361f, 0.871788288227254f, 0.871530138982730f,
+ 0.871236056832414f, 0.870910572694844f, 0.870635091498100f,
+ 0.870312602324108f, 0.870054759273025f, 0.869714810151487f,
+ 0.869366798437594f, 0.869122644903574f, 0.868812734247120f,
+ 0.868513864159224f, 0.868223756623966f, 0.867982715181480f,
+ 0.867671997828998f, 0.867407549259445f, 0.867121915940559f,
+ 0.866777786882641f, 0.866494871692684f, 0.866169558022502f,
+ 0.865824390903947f, 0.865583948922912f, 0.865260577587179f,
+ 0.897442560230671f, 0.897197975041446f, 0.896936601622887f,
+ 0.896639930442358f, 0.896358496055820f, 0.896149517619677f,
+ 0.895865666553406f, 0.895617470802557f, 0.895302338320577f,
+ 0.895008903956437f, 0.894766131546458f, 0.894431674742994f,
+ 0.894121880084823f, 0.893833250070113f, 0.893486559142867f,
+ 0.893208534201067f, 0.892971102121326f, 0.892730883606376f,
+ 0.892486495783999f, 0.892266606766457f, 0.891912616713162f,
+ 0.891668012816153f, 0.891389344583694f, 0.891127210236977f,
+ 0.890877014364885f, 0.890647919776319f, 0.890418186238544f,
+ 0.890123493822626f, 0.889882930209191f, 0.889638857058379f,
+ 0.889365113843686f, 0.889063011963076f, 0.888904806210479f,
+ 0.888595224427484f, 0.888348740136566f, 0.888084256999739f,
+ 0.887840636004391f, 0.887568183405399f, 0.887244627634201f,
+ 0.886968902204163f, 0.886813404979471f, 0.886525300589349f,
+ 0.886292070226496f, 0.886001016727455f, 0.885775223543453f,
+ 0.885522319161176f, 0.885169241885031f, 0.884891814369998f,
+ 0.884613124661923f, 0.884274453041876f, 0.884000697538040f,
+ 0.883779270240537f, 0.883552044352765f, 0.883321450052730f,
+ 0.883113458915741f, 0.882876096712848f, 0.882646681017793f,
+ 0.882443778020906f, 0.882173341068617f, 0.881932486077329f,
+ 0.881703097548580f, 0.881512430676287f, 0.881324988614956f,
+ 0.881078415830145f, 0.880836019375906f, 0.880592380876914f,
+ 0.880399045447751f, 0.880144055756519f, 0.879916264512867f,
+ 0.912262761203549f, 0.912050025877916f, 0.911837032776423f,
+ 0.911637002893336f, 0.911410664361064f, 0.911128179710946f,
+ 0.910915857381980f, 0.910713468187444f, 0.910514321228273f,
+ 0.910306658353875f, 0.910045217950504f, 0.909852480850540f,
+ 0.909661981811356f, 0.909400554409887f, 0.909267222071404f,
+ 0.909082328173087f, 0.908854885017709f, 0.908645654905872f,
+ 0.908429066044714f, 0.908203229057788f, 0.907975524348559f,
+ 0.907844076324775f, 0.907589558754535f, 0.907386017765108f,
+ 0.907146503676051f, 0.906950671939951f, 0.906734850193100f,
+ 0.906517924929938f, 0.906308309667034f, 0.906112492983346f,
+ 0.905983410335819f, 0.905742671195132f, 0.905504049165944f,
+ 0.905260974598286f, 0.905102165719060f, 0.904889117286156f,
+ 0.904704031490403f, 0.904530549352657f, 0.904335967396413f,
+ 0.904167284044056f, 0.903943525425265f, 0.903781177741016f,
+ 0.903561239085713f, 0.903395399945175f, 0.903235371390208f,
+ 0.903016653613898f, 0.902845104975041f, 0.902610542350492f,
+ 0.902398193708679f, 0.902225960341570f, 0.902021465390646f,
+ 0.901838424668229f, 0.901655758835068f, 0.901444820937381f,
+ 0.901245949833824f, 0.901069151471710f, 0.900915074109771f,
+ 0.900760359450201f, 0.900578847724700f, 0.900395965994494f,
+ 0.900228168805928f, 0.900066616036273f, 0.899902868316372f,
+ 0.899691672138911f, 0.899502275011599f, 0.899326630297481f,
+ 0.899147517398502f, 0.898891311929557f, 0.898737589588815f,
+ 0.898516468975794f, 0.898279435824810f, 0.898133379766176f,
+ 0.897940625694500f, 0.897769012071762f, 0.897584094034260f,
+ 0.897386399090749f, 0.897204596940482f, 0.897029990887014f,
+ 0.896843984043430f, 0.896659433456950f, 0.896499592362130f,
+ 0.896326359805770f, 0.896161841889783f, 0.896002962811382f,
+ 0.895858985647756f, 0.895679053342135f, 0.895472630838065f,
+ 0.895298117862088f, 0.927754563825053f, 0.927595758579098f,
+ 0.927423098901489f, 0.927274066423043f, 0.927064318376423f,
+ 0.926889227267958f, 0.926684097147831f, 0.926538641708822f,
+ 0.926383924569828f, 0.926221023888201f, 0.926069942094448f,
+ 0.925936867669842f, 0.925764476234829f, 0.925474258843906f,
+ 0.925341480568837f, 0.925184458584946f, 0.924997556397188f,
+ 0.924807778651479f, 0.924662367744565f, 0.924518831561345f,
+ 0.924374320422518f, 0.924239452756272f, 0.924035083031803f,
+ 0.923866605961103f, 0.923708308696909f, 0.923561861399422f,
+ 0.923342111379313f, 0.923181861833928f, 0.923022655494797f,
+ 0.922830553518427f, 0.922680580975269f, 0.922530343438704f,
+ 0.922379253084900f, 0.922203220902534f, 0.922017473475193f,
+ 0.921852509706996f, 0.921632506820494f, 0.921478764462909f,
+ 0.921328663166398f, 0.921188703978730f, 0.920977965994368f,
+ 0.920847607574230f, 0.920703577888137f, 0.920525889242200f,
+ 0.920380588508078f, 0.920253615844872f, 0.920139601102595f,
+ 0.920016687689548f, 0.919852868556918f, 0.919622503761834f,
+ 0.919458278730055f, 0.919295852055926f, 0.919134591570401f,
+ 0.918979062183651f, 0.918841010886602f, 0.918716051757939f,
+ 0.918569984788460f, 0.918369062451782f, 0.918215421152890f,
+ 0.918088828939449f, 0.917919780942217f, 0.917733211893808f,
+ 0.917574574952106f, 0.917438548196200f, 0.917323625618981f,
+ 0.917182002664427f, 0.917002289446623f, 0.916827583253820f,
+ 0.916714472811547f, 0.916594418971258f, 0.916460972969900f,
+ 0.916335756364354f, 0.916196649287878f, 0.916065572511741f,
+ 0.915947599776994f, 0.915818586940659f, 0.915632981571024f,
+ 0.915459212086808f, 0.915265459093725f, 0.915128178161501f,
+ 0.914998176624468f, 0.914860825831538f, 0.914625484964234f,
+ 0.914493843678021f, 0.914371779571637f, 0.914248620563387f,
+ 0.914100275148066f, 0.913965738470841f, 0.913826791405259f,
+ 0.913703250466401f, 0.913546026990571f, 0.913439303707573f,
+ 0.913292218567478f, 0.913182541953684f, 0.913036917749445f,
+ 0.912916054634268f, 0.912755642259817f, 0.912614205240910f,
+ 0.912468319200128f, 0.912352343404882f, 0.912236216864747f,
+ 0.912140734213469f, 0.911996828465493f, 0.911863354404087f,
+ 0.911709187715872f, 0.911569284462607f, 0.911451616353229f,
+ 0.911303512456831f, 0.911177218626202f, 0.911072557873086f,
+ 0.910948265059310f, 0.910791791835805f, 0.910670891976214f,
+ 0.910537919420196f, 0.910401546439265f, 0.910274713004068f,
+ 0.942972886116868f, 0.942873255216079f, 0.942736199328047f,
+ 0.942643396902211f, 0.942519604430019f, 0.942405794729767f,
+ 0.942276761652276f, 0.942183483677777f, 0.942062466352059f,
+ 0.941936635001252f, 0.941827790721750f, 0.941701752257506f,
+ 0.941569181480861f, 0.941428171184760f, 0.941266420007758f,
+ 0.941177983355581f, 0.941068131173925f, 0.940966459861221f,
+ 0.940802771917656f, 0.940699319454695f, 0.940546307666082f,
+ 0.940436629963075f, 0.940335105964667f, 0.940233168267479f,
+ 0.940070294791264f, 0.939946864568674f, 0.939806207003117f,
+ 0.939699917303889f, 0.939575570410864f, 0.939449267180147f,
+ 0.939335059915008f, 0.939221634003170f, 0.939100130210696f,
+ 0.938992079038466f, 0.938888993643325f, 0.938794272868458f,
+ 0.938679778519673f, 0.938565198624842f, 0.938447781743272f,
+ 0.938348887694662f, 0.938231674973109f, 0.938100618555889f,
+ 0.937929151200885f, 0.937821433643558f, 0.937688230231913f,
+ 0.937566420334848f, 0.937429830160073f, 0.937311443695009f,
+ 0.937190423215931f, 0.937063169325198f, 0.936979087920893f,
+ 0.936811325718775f, 0.936731671218813f, 0.936634805076269f,
+ 0.936532298789202f, 0.936416186739817f, 0.936286492122839f,
+ 0.936179817873514f, 0.936053037111203f, 0.935955439730240f,
+ 0.935819042190242f, 0.935683118325825f, 0.935582469083303f,
+ 0.935446994096024f, 0.935322108430966f, 0.935220912945627f,
+ 0.935131513738277f, 0.934997955601702f, 0.934903645484091f,
+ 0.934768972260724f, 0.934650110711938f, 0.934559208948897f,
+ 0.934458767641773f, 0.934334472974010f, 0.934235823798025f,
+ 0.934104732808613f, 0.934019917031945f, 0.933918957071512f,
+ 0.933828574280968f, 0.933739424110845f, 0.933624421615613f,
+ 0.933536789816350f, 0.933419733757098f, 0.933286841283564f,
+ 0.933217203121627f, 0.933126139166788f, 0.933030450650661f,
+ 0.932884936176351f, 0.932779450273416f, 0.932651017715157f,
+ 0.932545945362592f, 0.932455958346926f, 0.932337686419334f,
+ 0.932227058302166f, 0.932025539224666f, 0.931920795784066f,
+ 0.931852577738301f, 0.931756049103193f, 0.931621152063621f,
+ 0.931541102847978f, 0.931464901339151f, 0.931333487828105f,
+ 0.931222317831001f, 0.931145274335559f, 0.931048712065999f,
+ 0.930944549228741f, 0.930833966893561f, 0.930767031403833f,
+ 0.930661219955564f, 0.930573682517608f, 0.930490587789090f,
+ 0.930399861447101f, 0.930260043354527f, 0.930174757179721f,
+ 0.930082735120729f, 0.929980062024817f, 0.929881070592492f,
+ 0.929815269359710f, 0.929685646724316f, 0.929601626627662f,
+ 0.929475080077155f, 0.929384083536765f, 0.929293843820907f,
+ 0.929197517689133f, 0.929071496407846f, 0.928928767504129f,
+ 0.928850812213896f, 0.928755858560461f, 0.928683595051250f,
+ 0.928619097034910f, 0.928515473276713f, 0.928415904127483f,
+ 0.928296589209896f, 0.928156514230767f, 0.928075740622194f,
+ 0.927976281024834f, 0.927893758602397f, 0.927793223751259f,
+ 0.927533278933111f, 0.927443413613116f, 0.927330462282895f,
+ 0.927224518557079f, 0.927121263013897f, 0.927032513483020f,
+ 0.926946653005310f, 0.926852163943676f, 0.926782799964173f,
+ 0.926704377754193f, 0.926593212214682f, 0.926514271256028f,
+ 0.926434387396852f, 0.926338455745648f, 0.926241793129996f,
+ 0.926151243722815f, 0.926062446007553f, 0.925975437993879f,
+ 0.925900994878278f, 0.925769198338033f, 0.925673561554096f,
+ 0.925575663106531f, 0.925500150132689f, 0.958275427245807f,
+ 0.958217720942176f, 0.958088351980738f, 0.958006794628661f,
+ 0.957895379103873f, 0.957838037581917f, 0.957720979374284f,
+ 0.957627497340097f, 0.957500947647853f, 0.957418120264750f,
+ 0.957316257911455f, 0.957217318469398f, 0.957134253993810f,
+ 0.957060018503037f, 0.956986278198766f, 0.956895348950843f,
+ 0.956777435571824f, 0.956705582605570f, 0.956594026023218f,
+ 0.956516152335888f, 0.956357855496398f, 0.956298018292689f,
+ 0.956199349632202f, 0.956126323885033f, 0.956032137481781f,
+ 0.955946413187796f, 0.955847188872627f, 0.955754430213996f,
+ 0.955687353291728f, 0.955609174338888f, 0.955480819432032f,
+ 0.955422957826911f, 0.955337878180787f, 0.955277719747449f,
+ 0.955209090297961f, 0.955115833029069f, 0.955013029263148f,
+ 0.954929052626773f, 0.954858410226777f, 0.954780241057584f,
+ 0.954681910461255f, 0.954620468882399f, 0.954550468034354f,
+ 0.954461164292287f, 0.954381926562481f, 0.954303937678699f,
+ 0.954176727439442f, 0.954102874300900f, 0.953998321230092f,
+ 0.953890423951280f, 0.953784655913618f, 0.953722369794478f,
+ 0.953623105806388f, 0.953565738290012f, 0.953492683988373f,
+ 0.953413141506086f, 0.953326969854586f, 0.953262954351555f,
+ 0.953184013301923f, 0.953101894037007f, 0.953041902190311f,
+ 0.952969534053552f, 0.952869749867014f, 0.952789835366490f,
+ 0.952716435862726f, 0.952645254649320f, 0.952542492593948f,
+ 0.952463994814448f, 0.952349666425407f, 0.952275493737817f,
+ 0.952196002674587f, 0.952116683488068f, 0.952054020589248f,
+ 0.951971212262823f, 0.951862394841917f, 0.951768820782406f,
+ 0.951688868658540f, 0.951600614570797f, 0.951492713205816f,
+ 0.951425735970941f, 0.951361524070373f, 0.951238590334566f,
+ 0.951128486638037f, 0.951065909028615f, 0.951010270116159f,
+ 0.950902781595030f, 0.950831870621427f, 0.950771893006073f,
+ 0.950692220598345f, 0.950620597115025f, 0.950534510887917f,
+ 0.950403380584764f, 0.950334478890738f, 0.950272098021135f,
+ 0.950196260665432f, 0.950113227599961f, 0.950054926159529f,
+ 0.949969340742870f, 0.949881762321030f, 0.949768876353368f,
+ 0.949694926630816f, 0.949573394239407f, 0.949506256443609f,
+ 0.949443701324821f, 0.949394489146048f, 0.949300730229581f,
+ 0.949198332808624f, 0.949133287613908f, 0.949025351436334f,
+ 0.948942100841359f, 0.948893326812499f, 0.948797799093608f,
+ 0.948739418726981f, 0.948668659827771f, 0.948605293473731f,
+ 0.948508263335470f, 0.948422283102023f, 0.948334646705041f,
+ 0.948229838411611f, 0.948135977369838f, 0.948064621226811f,
+ 0.947975836227614f, 0.947869887504853f, 0.947787963676601f,
+ 0.947725593707634f, 0.947662889604619f, 0.947606582024487f,
+ 0.947529016389140f, 0.947467718279620f, 0.947393788461035f,
+ 0.947318309358938f, 0.947265244768804f, 0.947190494072727f,
+ 0.947120952789888f, 0.947051021658373f, 0.946947790362777f,
+ 0.946867304156026f, 0.946794285196121f, 0.946721140964183f,
+ 0.946641154869108f, 0.946546018566680f, 0.946455030201867f,
+ 0.946381856581210f, 0.946325274031613f, 0.946255337478520f,
+ 0.946177270118115f, 0.946111078958173f, 0.946023514156008f,
+ 0.945959212905784f, 0.945849080079382f, 0.945786239425211f,
+ 0.945714124061532f, 0.945658743681213f, 0.945601619947753f,
+ 0.945519484258529f, 0.945455400385708f, 0.945357119411477f,
+ 0.945264635751721f, 0.945201727920235f, 0.945141917936100f,
+ 0.945079684332379f, 0.945015928228411f, 0.944946280980823f,
+ 0.944877156498061f, 0.944804451411428f, 0.944739649858619f,
+ 0.944673589496270f, 0.944611136357352f, 0.944511223725923f,
+ 0.944424321938049f, 0.944379812730986f, 0.944289367399254f,
+ 0.944211374628178f, 0.944134509881182f, 0.944064570023833f,
+ 0.944020390576029f, 0.943935471478227f, 0.943859733313642f,
+ 0.943783658792479f, 0.943611497969536f, 0.943543421957604f,
+ 0.943499628090061f, 0.943413995369032f, 0.943307061234208f,
+ 0.943209211047420f, 0.943139391056753f, 0.943036473656225f,
+ 0.942967493742562f, 0.942890220197419f, 0.942826382100022f,
+ 0.942762325628337f, 0.942694266534490f, 0.942624647563169f,
+ 0.942553430443271f, 0.942488591032619f, 0.942370472457731f,
+ 0.942305639341609f, 0.942234519293505f, 0.942182960322720f,
+ 0.942120517409552f, 0.942027480395684f, 0.941952932339245f,
+ 0.941891750910681f, 0.941835281530227f, 0.941772951246597f,
+ 0.941725887717769f, 0.941683506530303f, 0.941593394184890f,
+ 0.941515512558213f, 0.941473311245300f, 0.941404233632176f,
+ 0.941325255534943f, 0.941251396941407f, 0.941202439199741f,
+ 0.941105194862420f, 0.941038074691643f, 0.940974096891109f,
+ 0.940919561213800f, 0.940827436688845f, 0.940746282858963f,
+ 0.940672810072720f, 0.940626178969142f, 0.940581240903949f,
+ 0.940525846543147f, 0.940475217956959f, 0.940413763147880f,
+ 0.940361426762319f, 0.940301758975821f, 0.940257761802955f,
+ 0.940172669790372f, 0.940105121519804f, 0.940055180311003f,
+ 0.940010615028732f, 0.939935007349598f, 0.939881036050097f,
+ 0.939814506904525f, 0.939749695798634f, 0.939696784747100f,
+ 0.939625052341671f, 0.939556008686751f, 0.939512250891858f,
+ 0.939433258280986f, 0.939307887545587f, 0.939263971661818f,
+ 0.939215889164479f, 0.939167376618607f, 0.939121752120582f,
+ 0.971967121890630f, 0.971911994887031f, 0.971870201384295f,
+ 0.971825989837210f, 0.971772117969243f, 0.971732534447172f,
+ 0.971671680117055f, 0.971613103848265f, 0.971568277310130f,
+ 0.971497005410360f, 0.971437965611784f, 0.971374177119527f,
+ 0.971311337696788f, 0.971265675503488f, 0.971211728334830f,
+ 0.971173654659489f, 0.971097115191358f, 0.971055546830150f,
+ 0.970984778394942f, 0.970938216168554f, 0.970854927036070f,
+ 0.970811611972044f, 0.970768836659056f, 0.970693057804116f,
+ 0.970619816488717f, 0.970549808560914f, 0.970503576286217f,
+ 0.970432624714843f, 0.970388770439317f, 0.970349084551768f,
+ 0.970298841533354f, 0.970239776951519f, 0.970194884492194f,
+ 0.970152831029440f, 0.970090756146688f, 0.970000755530803f,
+ 0.969956773446540f, 0.969911684742526f, 0.969822649120895f,
+ 0.969768380795225f, 0.969704307081910f, 0.969664862298864f,
+ 0.969522047689548f, 0.969481769085865f, 0.969436588593615f,
+ 0.969381675858440f, 0.969343203466823f, 0.969266922648030f,
+ 0.969211596747585f, 0.969146961317084f, 0.969103250668287f,
+ 0.969062089905576f, 0.968999137424737f, 0.968951901823687f,
+ 0.968911916700945f, 0.968839412499583f, 0.968786327157115f,
+ 0.968751440609257f, 0.968695995382998f, 0.968656550332251f,
+ 0.968616734717366f, 0.968567111115919f, 0.968522709698953f,
+ 0.968475903432075f, 0.968425439658996f, 0.968384501083956f,
+ 0.968344193764876f, 0.968302257085111f, 0.968251151994677f,
+ 0.968211894760266f, 0.968149794153557f, 0.968115330462226f,
+ 0.968048914429886f, 0.967991768898303f, 0.967957662757341f,
+ 0.967901867217052f, 0.967842068702658f, 0.967808096936220f,
+ 0.967746019972052f, 0.967668943461478f, 0.967635103661283f,
+ 0.967593146864882f, 0.967519676893017f, 0.967485969937633f,
+ 0.967444577221587f, 0.967394666397157f, 0.967359767192470f,
+ 0.967326238566736f, 0.967269924014565f, 0.967205488183220f,
+ 0.967150317626980f, 0.967112403335753f, 0.967079092591829f,
+ 0.967028848415111f, 0.966995625287745f, 0.966944244501088f,
+ 0.966911108413841f, 0.966837881450369f, 0.966804830861701f,
+ 0.966754806420632f, 0.966711974994014f, 0.966667104208814f,
+ 0.966634226055970f, 0.966584175955802f, 0.966508735173705f,
+ 0.966412422599927f, 0.966337465181747f, 0.966304793467667f,
+ 0.966245985853935f, 0.966195744077399f, 0.966162098544657f,
+ 0.966129595993283f, 0.966065142768099f, 0.966008381118610f,
+ 0.965958352967421f, 0.965907874942570f, 0.965860700300948f,
+ 0.965828446705695f, 0.965778827683499f, 0.965702907650509f,
+ 0.965666139199334f, 0.965634050335282f, 0.965562124832480f,
+ 0.965517675557660f, 0.965436730013674f, 0.965359948253595f,
+ 0.965303173457664f, 0.965250492014372f, 0.965212160348909f,
+ 0.965170781733245f, 0.965118350471165f, 0.965086664224710f,
+ 0.965045725545761f, 0.965008421977835f, 0.964951359793605f,
+ 0.964899196027095f, 0.964824463593891f, 0.964772498398080f,
+ 0.964741091666004f, 0.964670443460613f, 0.964607787072424f,
+ 0.964551286041044f, 0.964496863047423f, 0.964465651940309f,
+ 0.964429879490986f, 0.964398594355012f, 0.964351600338458f,
+ 0.964307369250915f, 0.964271608387851f, 0.964227417766565f,
+ 0.964171256711235f, 0.964081060807346f, 0.964045880993023f,
+ 0.963985242031280f, 0.963945647749731f, 0.963907826366924f,
+ 0.963868197486238f, 0.963799938452283f, 0.963765207634998f,
+ 0.963720978726527f, 0.963684133853149f, 0.963649040588658f,
+ 0.963607534831113f, 0.963551321580042f, 0.963497204430698f,
+ 0.963424714887615f, 0.963374725409701f, 0.963344439312775f,
+ 0.963310870684628f, 0.963276090213696f, 0.963222993617856f,
+ 0.963129610624736f, 0.963090851003960f, 0.963060656182045f,
+ 0.963002655525515f, 0.962963164663654f, 0.962922597291628f,
+ 0.962882895853952f, 0.962848459982529f, 0.962771647590578f,
+ 0.962711992610457f, 0.962654371383541f, 0.962616259829856f,
+ 0.962562805802114f, 0.962525034500491f, 0.962484652724640f,
+ 0.962439417576559f, 0.962379290577768f, 0.962332639787563f,
+ 0.962297429044519f, 0.962249888365194f, 0.962200268067524f,
+ 0.962140347398233f, 0.962107323902686f, 0.962041853572779f,
+ 0.962008176643193f, 0.961975646236443f, 0.961924711249088f,
+ 0.961879023273176f, 0.961831509403864f, 0.961775868784700f,
+ 0.961746822676295f, 0.961716324502158f, 0.961640369374947f,
+ 0.961611429245648f, 0.961547547285081f, 0.961509489301074f,
+ 0.961480654833700f, 0.961447331320540f, 0.961387391917649f,
+ 0.961341468430511f, 0.961304123251159f, 0.961249351920283f,
+ 0.961212476662826f, 0.961178912062857f, 0.961090639886684f,
+ 0.961045097435303f, 0.961003493534426f, 0.960967973701429f,
+ 0.960938077569799f, 0.960884289021088f, 0.960819067244493f,
+ 0.960780320069444f, 0.960743327089429f, 0.960698279588637f,
+ 0.960667663213218f, 0.960634721461931f, 0.960594821404335f,
+ 0.960541761992586f, 0.960508945187094f, 0.960469856554093f,
+ 0.960426570022417f, 0.960387981064035f, 0.960347680867052f,
+ 0.960307472352100f, 0.960253653207329f, 0.960218687435176f,
+ 0.960186390857838f, 0.960158615758153f, 0.960112507807049f,
+ 0.960071344004724f, 0.960020983326931f, 0.959987667027966f,
+ 0.959956805300620f, 0.959927767865339f, 0.959896946101205f,
+ 0.959833975596898f, 0.959804107476303f, 0.959775204077521f,
+ 0.959747793439038f, 0.959702341797309f, 0.959634363246830f,
+ 0.959569029679109f, 0.959533052569412f, 0.959501336485215f,
+ 0.959474119229892f, 0.959419839626233f, 0.959341023507977f,
+ 0.959295438847227f, 0.959260524216600f, 0.959227089969235f,
+ 0.959200063868628f, 0.959173070436206f, 0.959125094986595f,
+ 0.959090861914065f, 0.959045960373426f, 0.959019094445528f,
+ 0.958992260803902f, 0.958954605304605f, 0.958916769209807f,
+ 0.958886764667757f, 0.958841502703832f, 0.958814827566503f,
+ 0.958777559544421f, 0.958702397967575f, 0.958671995235790f,
+ 0.958641005586528f, 0.958614486425838f, 0.958577069623433f,
+ 0.958549172046238f, 0.958512135033094f, 0.958441537076639f,
+ 0.958415172644034f, 0.958365776019084f, 0.958303096769660f,
+ 0.958263716843560f, 0.958185028692631f, 0.958145375013881f,
+ 0.958119191626474f, 0.958068694182465f, 0.958018918920774f,
+ 0.957949774071843f, 0.957901198070889f, 0.957866533472984f,
+ 0.957836112980788f, 0.957808708199475f, 0.957782766016934f,
+ 0.957746388685411f, 0.957713730335926f, 0.957680192807017f,
+ 0.957652942114070f, 0.957612146941780f, 0.957579663093048f,
+ 0.957545516193684f, 0.957506903711571f, 0.957472054074152f,
+ 0.957436503578588f, 0.957395181689988f, 0.957359417445984f,
+ 0.957311450421340f, 0.957282679922514f, 0.957209067658546f,
+ 0.957175128902001f, 0.957146509039227f, 0.957112476412398f,
+ 0.957074501733838f, 0.957036984482748f, 0.956999759246114f,
+ 0.956970851060728f, 0.956927264285104f, 0.956871217307326f,
+ 0.956844594547104f, 0.956813890060049f, 0.956780501144467f,
+ 0.956744461342733f, 0.956714994383490f, 0.956665821298225f,
+ 0.956640789566225f, 0.956610849917976f, 0.956550012130147f,
+ 0.956496846132444f, 0.956456019909584f, 0.956407330143974f,
+ 0.956337082514063f, 0.956307879496556f, 0.956240737167033f,
+ 0.956198057147075f, 0.956160694192385f, 0.956121596304570f,
+ 0.956084736949496f, 0.956060067954893f, 0.956028844508730f,
+ 0.956004232084434f, 0.955958879345404f, 0.955924575071532f,
+ 0.955883193326281f, 0.955847442906133f, 0.955813069719572f,
+ 0.955772060592762f, 0.955716387710303f, 0.955685728196237f,
+ 0.955645039455566f, 0.955586534578155f, 0.955554652983814f,
+ 0.955528968538545f, 0.955494147326420f, 0.955433145575848f,
+ 0.955398247978298f, 0.955366951631532f, 0.955341405225951f,
+ 0.955313054458997f, 0.955274786773442f, 0.955242793028928f,
+ 0.955217357860814f, 0.955166187024662f, 0.955135160237832f,
+ 0.955097685925402f, 0.955066290889999f, 0.955040052475596f,
+ 0.955002923204769f, 0.954979072001785f, 0.954946002019177f,
+ 0.954922204505984f, 0.954894464435323f, 0.954869328998638f,
+ 0.954822936955329f, 0.954799245855306f, 0.954763225287706f,
+ 0.954739587182904f, 0.954702687836680f, 0.954650651504783f,
+ 0.954627091600106f, 0.954586735039616f, 0.954543509103832f,
+ 0.954487508586822f, 0.954455423137410f, 0.954431992380845f,
+ 0.954395246407735f, 0.954368158761341f, 0.954328519361469f,
+ 0.954305192349057f, 0.954278682066255f, 0.954244790518497f,
+ 0.954210949137707f, 0.954183768594435f, 0.954155136691491f,
+ 0.954118315432295f, 0.954088453549574f, 0.954056625115569f,
+ 0.954015559093910f, 0.953982138679812f, 0.953953458629932f,
+ 0.953924167157067f, 0.953876244476431f, 0.953843277247482f,
+ 0.953820332674190f, 0.953783435648809f, 0.986922760337215f,
+ 0.986893347132258f, 0.986853719027791f, 0.986802177140835f,
+ 0.986780595774923f, 0.986735948250994f, 0.986714413193494f,
+ 0.986691544524921f, 0.986650126059355f, 0.986617659263719f,
+ 0.986574768928646f, 0.986553349155405f, 0.986509490127068f,
+ 0.986488116171129f, 0.986459808203524f, 0.986425749277674f,
+ 0.986401282919961f, 0.986377715956588f, 0.986347680503076f,
+ 0.986320259258079f, 0.986271810607144f, 0.986245050428010f,
+ 0.986223881966244f, 0.986176681328462f, 0.986145917556990f,
+ 0.986110482684939f, 0.986085509969948f, 0.986055947339547f,
+ 0.986034913700289f, 0.986000776580319f, 0.985965492876594f,
+ 0.985919261677516f, 0.985892883092507f, 0.985830609056223f,
+ 0.985801336195789f, 0.985779112009499f, 0.985758255139701f,
+ 0.985733238386015f, 0.985712426258423f, 0.985655501978720f,
+ 0.985626353966535f, 0.985590903455782f, 0.985563563636873f,
+ 0.985523439019124f, 0.985500817867769f, 0.985474456307468f,
+ 0.985449609353800f, 0.985405907406883f, 0.985360059543588f,
+ 0.985310904032878f, 0.985270714901873f, 0.985226727495785f,
+ 0.985193263279922f, 0.985172811115538f, 0.985115330253415f,
+ 0.985063087425340f, 0.985008336715826f, 0.984978613966300f,
+ 0.984941852360105f, 0.984912509332049f, 0.984850180222146f,
+ 0.984824312074071f, 0.984799854405289f, 0.984753768215678f,
+ 0.984732561511123f, 0.984706135723891f, 0.984678185530603f,
+ 0.984655684360588f, 0.984631067011433f, 0.984587731589628f,
+ 0.984558318722489f, 0.984523715071264f, 0.984502265042700f,
+ 0.984481759317740f, 0.984445908996804f, 0.984416448023547f,
+ 0.984384996037713f, 0.984346921353555f, 0.984323353794763f,
+ 0.984302492135683f, 0.984234826486034f, 0.984229190516759f,
+ 0.984189170519958f, 0.984154292087286f, 0.984130608803616f,
+ 0.984094955038999f, 0.984074738744969f, 0.984037558142149f,
+ 0.983994580486844f, 0.983967885641745f, 0.983943737430130f,
+ 0.983915944574975f, 0.983884236637719f, 0.983864172195582f,
+ 0.983831831959887f, 0.983802938958836f, 0.983775833669071f,
+ 0.983753187871529f, 0.983730105132050f, 0.983703133254244f,
+ 0.983669828705679f, 0.983644384789753f, 0.983620626656529f,
+ 0.983600307731900f, 0.983567972476239f, 0.983543210140435f,
+ 0.983491238528487f, 0.983454493564921f, 0.983367632603668f,
+ 0.983347051720359f, 0.983327810408723f, 0.983301876305209f,
+ 0.983276092919806f, 0.983251755401310f, 0.983232135834041f,
+ 0.983208069222592f, 0.983172240353604f, 0.983147868868929f,
+ 0.983081868982781f, 0.983045201512550f, 0.983012533352780f,
+ 0.982993510710699f, 0.982961813650806f, 0.982942002878203f,
+ 0.982889024861584f, 0.982867015386914f, 0.982847649649163f,
+ 0.982824371463141f, 0.982805048997046f, 0.982773218775641f,
+ 0.982748418352122f, 0.982729158100405f, 0.982703997651039f,
+ 0.982682108753123f, 0.982655505774959f, 0.982623018430868f,
+ 0.982593842523021f, 0.982573406804049f, 0.982547353367972f,
+ 0.982519585224023f, 0.982459288284645f, 0.982436394370087f,
+ 0.982415125919954f, 0.982387582740862f, 0.982367292542386f,
+ 0.982334965662622f, 0.982312635851139f, 0.982294117369415f,
+ 0.982251715517260f, 0.982224369337035f, 0.982205907157262f,
+ 0.982182761751450f, 0.982159903255411f, 0.982126373095434f,
+ 0.982107184687307f, 0.982084954430489f, 0.982041099920316f,
+ 0.982022769212310f, 0.981977331062889f, 0.981939690609133f,
+ 0.981914923334885f, 0.981856360333239f, 0.981834102582585f,
+ 0.981809598272734f, 0.981770121636027f, 0.981739618531661f,
+ 0.981717245565463f, 0.981683230681818f, 0.981652689781140f,
+ 0.981634196393471f, 0.981613495190574f, 0.981564013372326f,
+ 0.981524277410168f, 0.981498926071219f, 0.981450560157412f,
+ 0.981425266998042f, 0.981402192708996f, 0.981384225827395f,
+ 0.981365906020084f, 0.981343753206944f, 0.981300572619224f,
+ 0.981282678369968f, 0.981264437359234f, 0.981228534383292f,
+ 0.981209049239098f, 0.981182762882197f, 0.981158372244174f,
+ 0.981134700930964f, 0.981112259373601f, 0.981094152386932f,
+ 0.981068500570816f, 0.981036844052188f, 0.980986685235874f,
+ 0.980968652491355f, 0.980913591726037f, 0.980889441073170f,
+ 0.980848240136851f, 0.980807605621403f, 0.980774106571861f,
+ 0.980755251245704f, 0.980729769330780f, 0.980680692805421f,
+ 0.980654718270742f, 0.980636884095367f, 0.980615965819145f,
+ 0.980595938595629f, 0.980561974203509f, 0.980496049774783f,
+ 0.980478290932049f, 0.980460550538442f, 0.980432150774978f,
+ 0.980410648593876f, 0.980393295011126f, 0.980357014272223f,
+ 0.980326248344638f, 0.980299534184272f, 0.980264913469273f,
+ 0.980247317913468f, 0.980230066117568f, 0.980208414358917f,
+ 0.980187260862336f, 0.980132312570413f, 0.980109049768295f,
+ 0.980075371162398f, 0.980051209784426f, 0.980031865718607f,
+ 0.979994042174202f, 0.979937198188725f, 0.979920111293897f,
+ 0.979898807860237f, 0.979877564940339f, 0.979856737310176f,
+ 0.979835492266172f, 0.979818488652277f, 0.979774221453093f,
+ 0.979745444849853f, 0.979727225403310f, 0.979700314470918f,
+ 0.979683392321718f, 0.979666182005815f, 0.979611629473783f,
+ 0.979590852554355f, 0.979573692364784f, 0.979556851511248f,
+ 0.979534389742842f, 0.979506478571303f, 0.979478322317171f,
+ 0.979455398954295f, 0.979438638890386f, 0.979412895074252f,
+ 0.979392385523425f, 0.979371783642596f, 0.979355088151969f,
+ 0.979333607767233f, 0.979313189453699f, 0.979292658573124f,
+ 0.979263179385256f, 0.979246564075690f, 0.979198755309747f,
+ 0.979174516662574f, 0.979146797165384f, 0.979123464872970f,
+ 0.979106928065550f, 0.979069685325203f, 0.979053179759749f,
+ 0.979030332693243f, 0.978986657751362f, 0.978970198965351f,
+ 0.978946974036735f, 0.978926682675456f, 0.978905244289410f,
+ 0.978862765525649f, 0.978846097879915f, 0.978821788954481f,
+ 0.978803246624047f, 0.978766048702116f, 0.978746831450756f,
+ 0.978725426164543f, 0.978709138346453f, 0.978685752931826f,
+ 0.978669496205975f, 0.978649410758398f, 0.978624780793713f,
+ 0.978608570268773f, 0.978592094654600f, 0.978550920367351f,
+ 0.978513470662572f, 0.978497042038316f, 0.978480907605864f,
+ 0.978464788541799f, 0.978434611643655f, 0.978418522841283f,
+ 0.978390826033207f, 0.978374767625467f, 0.978353654444658f,
+ 0.978337626389741f, 0.978305022211732f, 0.978282789753918f,
+ 0.978266806773291f, 0.978234606202049f, 0.978203779970373f,
+ 0.978184787014873f, 0.978165052701335f, 0.978112832751907f,
+ 0.978096668038331f, 0.978058855230544f, 0.978042990406293f,
+ 0.978026872130719f, 0.978008154881375f, 0.977992335006128f,
+ 0.977968977528089f, 0.977951947084624f, 0.977932854511879f,
+ 0.977913681988638f, 0.977897936222764f, 0.977878414356271f,
+ 0.977862698102290f, 0.977844552571458f, 0.977825081855045f,
+ 0.977804621661370f, 0.977787726784343f, 0.977768071434286f,
+ 0.977752443360056f, 0.977733052522146f, 0.977717453632544f,
+ 0.977698822040011f, 0.977673199611945f, 0.977619793686062f,
+ 0.977602075088056f, 0.977576669465553f, 0.977542954045465f,
+ 0.977527455035169f, 0.977504152387557f, 0.977488682089939f,
+ 0.977472970424132f, 0.977448260145925f, 0.977398011663338f,
+ 0.977372297882134f, 0.977355666246754f, 0.977330698924145f,
+ 0.977298426353436f, 0.977283068966841f, 0.977250107782567f,
+ 0.977207119451928f, 0.977191803723299f, 0.977176502215050f,
+ 0.977161214907559f, 0.977102300457946f, 0.977063703061534f,
+ 0.977040908723148f, 0.977025676110134f, 0.977004557438028f,
+ 0.976989105443786f, 0.976970178122162f, 0.976938120674094f,
+ 0.976922957790298f, 0.976906582534861f, 0.976891202359989f,
+ 0.976872365503571f, 0.976857258525261f, 0.976833112633702f,
+ 0.976815174516876f, 0.976791566318235f, 0.976756563193258f,
+ 0.976741524718733f, 0.976698317437522f, 0.976651346433524f,
+ 0.976632645407126f, 0.976617419614971f, 0.976595534775329f,
+ 0.976576881856942f, 0.976561937972295f, 0.976546768986203f,
+ 0.976528820169054f, 0.976508065016963f, 0.976482720813795f,
+ 0.976467844882108f, 0.976446124920447f, 0.976403186250199f,
+ 0.976388350299752f, 0.976349887902191f, 0.976319445660324f,
+ 0.976304414770861f, 0.976289632025076f, 0.976264145624284f,
+ 0.976240532650802f, 0.976209273788994f, 0.976194311547957f,
+ 0.976179595220112f, 0.976161231562614f, 0.976146541915870f,
+ 0.976123701179350f, 0.976105154089893f, 0.976082960591513f,
+ 0.976042090614826f, 0.976026251263904f, 0.976007993676071f,
+ 0.975989338013885f, 0.975962781592164f, 0.975944570379698f,
+ 0.975930011937128f, 0.975907027483125f, 0.975888636596245f,
+ 0.975874117446146f, 0.975858399012390f, 0.975814767533837f,
+ 0.975770098214803f, 0.975755629917150f, 0.975740950932038f,
+ 0.975700126458313f, 0.975679056973671f, 0.975664640074239f,
+ 0.975650236167557f, 0.975580150537865f, 0.975564561643136f,
+ 0.975550195260922f, 0.975511963306388f, 0.975491182846468f,
+ 0.975476854410694f, 0.975458937949595f, 0.975441037900350f,
+ 0.975403340889900f, 0.975378834602348f, 0.975354759608012f,
+ 0.975337489516777f, 0.975321825596625f, 0.975307598487264f,
+ 0.975283675623818f, 0.975269473727394f, 0.975250515677110f,
+ 0.975222503407069f, 0.975208339209176f, 0.975185839227530f,
+ 0.975164426313621f, 0.975150299633837f, 0.975132834025883f,
+ 0.975114957906684f, 0.975095028384530f, 0.975080951799970f,
+ 0.975066887752846f, 0.975041741905158f, 0.975027702605693f,
+ 0.975005031349011f, 0.974987469475237f, 0.974973467389524f,
+ 0.974937686203278f, 0.974920168212932f, 0.974902828972747f,
+ 0.974872881920399f, 0.974855407841305f, 0.974841479047993f,
+ 0.974824552649550f, 0.974807122649889f, 0.974793024340947f,
+ 0.974779144750431f, 0.974761758864481f, 0.974743009828295f,
+ 0.974702179104436f, 0.974688347653034f, 0.974654844155268f,
+ 0.974629896769268f, 0.974609196289333f, 0.974595412768757f,
+ 0.974578144647479f, 0.974554761535420f, 0.974512105515984f,
+ 0.974493684651349f, 0.974479960679643f, 0.974445019848412f,
+ 0.974420342456999f, 0.974406653869030f, 0.974389302704651f,
+ 0.974375638158094f, 0.974356380485032f, 0.974342739773739f,
+ 0.974329111024600f, 0.974308667973371f, 0.974295062936910f,
+ 0.974277268860387f, 0.974257232359766f, 0.974243662862119f,
+ 0.974226418880396f, 0.974209427476104f, 0.974160143649720f,
+ 0.974135024493451f, 0.974121512976261f, 0.974108013252395f,
+ 0.974080630570305f, 0.974065964331530f, 0.974015781527702f,
+ 0.974002134457994f, 0.973968181110526f, 0.973941430008605f,
+ 0.973900624962740f, 0.973887216439222f, 0.973870418549401f,
+ 0.973850724231017f, 0.973837350500092f, 0.973820594740841f,
+ 0.973798522327485f, 0.973777807158058f, 0.973762348240277f,
+ 0.973720684603163f, 0.973707190440952f, 0.973690525402443f,
+ 0.973642098553068f, 0.973616296682685f, 0.973596682908872f,
+ 0.973574106353138f, 0.973560681801021f, 0.973542922676264f,
+ 0.973514709802091f, 0.973501505700315f, 0.973484979448508f,
+ 0.973471798042410f, 0.973456500215393f, 0.973431510917770f,
+ 0.973406975669394f, 0.973387629418889f, 0.973367520795037f,
+ 0.973303609216807f, 0.973284719314881f, 0.973267149528169f,
+ 0.973250597568072f, 0.973237526949800f, 0.973221187129731f,
+ 0.973199716550181f, 0.973183406462760f, 0.973164990751466f,
+ 0.973148718186700f, 0.973132284540874f, 0.973116049604857f,
+ 0.973096165761680f, 0.973079968266462f, 0.973062611300583f,
+ 0.973011998962548f, 0.972975003152676f, 0.972962075047062f,
+ 0.972945970132927f, 0.972923360946523f, 0.972900115256482f,
+ 0.972870276402172f, 0.972833571656061f, 0.972811347406848f,
+ 0.972777650857546f, 0.972760603364386f, 0.972744749946391f,
+ 0.972728915316704f, 0.972491425539914f, 0.972700300574877f,
+ 0.972657493357715f, 0.972632608746347f, 0.972616859264461f,
+ 0.972598619191692f, 0.972345186679530f, 0.972332446611726f,
+ 0.972312645617935f, 0.972296953045242f, 0.972283079206423f,
+ 0.972354259937865f, 0.972459209202242f, 0.972446537807611f,
+ 0.972430934483078f, 0.972176086196692f, 0.972163441757064f,
+ 0.972150807994720f, 0.972135323233078f, 0.972332090264623f,
+ 0.972296656512621f, 0.972281150355395f, 0.972261199146408f,
+ 0.972040937679384f, 0.972020853805726f, 0.971986352971951f,
+ 0.971970171296574f, 0.971957642162397f, 0.971945123560269f,
+ 0.971925366207946f, 0.971903023702926f, 0.971890536316386f,
+ 0.971869250638017f, 0.971845667162464f, 0.971833210739844f,
+ 0.971804277862056f, 0.971791841948099f, 0.971779416449271f,
+ 0.971764022143080f, 0.971747980164594f, 0.971735585761423f,
+ 0.971717421387968f, 0.971705047573062f, 0.971692684095817f,
+ 0.971677569616385f, 0.971654562083561f, 0.971639423267713f,
+ 0.971627100732641f, 0.971586709457336f, 0.971574406851170f,
+ 0.971562114493840f, 0.971547034241681f, 0.971528565510735f,
+ 0.971512518293816f, 0.971500266599958f, 0.971464929056654f,
+ 0.971452697226202f, 0.971418394914989f, 0.971406182921065f,
+ 0.971393981063291f, 0.971376907284318f, 0.971343341781312f,
+ 0.971331169765085f, 0.971319007835423f, 0.971298578641970f,
+ 0.971283662437030f, 0.971271530457587f, 0.971252454892243f,
+ 0.971240342827092f, 0.971225487479047f, 0.971204546317460f,
+ 0.971192464074439f, 0.971180391807126f, 0.971165370878734f,
+ 0.971153318463628f, 0.971140124638148f, 0.971123237224655f,
+ 0.971106480118568f, 0.971083157368327f, 0.971071154129043f,
+ 0.971034062159235f, 0.971018455159871f, 0.971006480918128f,
+ 0.970994516519120f, 0.970977092320320f, 0.970965003529432f,
+ 0.970950326173765f, 0.970937252551404f, 0.970925337052152f,
+ 0.970913431323699f, 0.970898580575337f, 0.970880595387861f,
+ 0.970865984305819f, 0.970854117296896f, 0.970827109552462f,
+ 0.970787121116513f, 0.970771664135147f, 0.970734868566354f,
+ 0.970720322134539f, 0.970708511741481f, 0.970696710990446f,
+ 0.970670091597675f, 0.970638391535586f, 0.970594506910305f,
+ 0.970571972858635f, 0.970560218611173f, 0.970545523090248f,
+ 0.970524813815583f, 0.970506896143813f, 0.970470838904634f,
+ 0.970456283769786f, 0.970444585924069f, 0.970432897582902f,
+ 0.970421218734771f, 0.970408406937207f, 0.970396747017460f,
+ 0.970385096556351f, 0.970370753011372f, 0.970353198100957f,
+ 0.970341440710966f, 0.970329827852595f, 0.970315487202049f,
+ 0.970303893080486f, 0.970269092080499f, 0.970251821409422f,
+ 0.970240254808422f, 0.970228697553167f, 0.970204163935976f,
+ 0.970191352781056f, 0.970179823267678f, 0.970165616505559f,
+ 0.970154105529172f, 0.970125646226645f, 0.970114153457064f,
+ 0.970102669944216f, 0.970087197011956f, 0.970075731899408f,
+ 0.970061466817810f, 0.970050020142580f, 0.970019988110384f,
+ 0.969972599795979f, 0.969961179607361f, 0.969948632115153f,
+ 0.969908746684612f, 0.969894682809931f, 0.969883170119172f,
+ 0.969871795082014f, 0.969860429159958f, 0.969846343221063f,
+ 0.969834995442697f, 0.969823656746862f, 0.969812327122728f,
+ 0.969798343939773f, 0.969787032374211f, 0.969772004681985f,
+ 0.969760711166196f, 0.969749426668237f, 0.969688426500697f,
+ 0.969677159032194f, 0.969663245949753f, 0.969651996391660f,
+ 0.969625257076576f, 0.969605977523474f, 0.969594754369765f,
+ 0.969583416110931f, 0.969572210865374f, 0.969561014532258f,
+ 0.969547180480629f, 0.969513246925795f, 0.969502076773797f,
+ 0.969485003257335f, 0.969472720232916f, 0.969461576525169f,
+ 0.969450319795174f, 0.969439193805961f, 0.969420426798349f,
+ 0.969406597238909f, 0.969395497473808f, 0.969376382415080f,
+ 0.969365300059954f, 0.969354226471582f, 0.969343161639623f,
+ 0.969325363726951f, 0.969314316299151f, 0.969299688455677f,
+ 0.969287530932357f, 0.969276509560222f, 0.969265496882931f,
+ 0.969254492890265f, 0.969243497572002f, 0.969229888366585f,
+ 0.969216720237517f, 0.969205750840223f, 0.969191858846575f,
+ 0.969172668560500f, 0.969153335935209f, 0.969142400641392f,
+ 0.969126015512418f, 0.969115097292469f, 0.969077096987749f,
+ 0.969066195393082f, 0.969054177875027f, 0.969035207922252f,
+ 0.969016820085756f, 0.969005952381187f, 0.968992380215632f,
+ 0.968981529478561f, 0.968968080712556f, 0.968955177833115f,
+ 0.968944352461800f, 0.968926930585352f, 0.968913081597044f,
+ 0.968902281458119f, 0.968891489754488f, 0.968877127176801f,
+ 0.968865230815253f, 0.968851865757681f, 0.968841107561196f,
+ 0.968827062840517f, 0.968816321345894f, 0.968790935192768f,
+ 0.968768188742240f, 0.968757471871783f, 0.968732819132344f,
+ 0.968722118670559f, 0.968708836038462f, 0.968698152157404f,
+ 0.968657086013096f, 0.968646418161465f, 0.968624158304073f,
+ 0.968613506791441f, 0.968596572545570f, 0.968579061738822f,
+ 0.968561014979841f, 0.968550396126364f, 0.968537202998056f,
+ 0.968526600536290f, 0.968516006279852f, 0.968505420219268f,
+ 0.968494842345072f, 0.968484165957274f, 0.968448598566619f,
+ 0.968438044781854f, 0.968427499146142f, 0.968390635470169f,
+ 0.968375420846665f, 0.968364899038218f, 0.968354385341824f,
+ 0.968332577679763f, 0.968322079974605f, 0.968311590353718f,
+ 0.968301004306507f, 0.968290530868138f, 1.00143961392577f,
+ 1.00142968724369f, 1.00141976816660f, 1.00140446209241f,
+ 1.00137317954622f, 1.00136328275028f, 1.00135014137470f,
+ 1.00133902200513f, 1.00131146903538f, 1.00130160207297f,
+ 1.00128450674836f, 1.00127465472096f, 1.00126481021308f,
+ 1.00125497321619f, 1.00124225940996f, 1.00122500973736f,
+ 1.00121519503829f, 1.00120538781624f, 1.00119545326034f,
+ 1.00118313784023f, 1.00117335295109f, 1.00116357550511f,
+ 1.00115380549385f, 1.00113942387171f, 1.00112966862280f,
+ 1.00109314412405f, 1.00107946844994f, 1.00106973486180f,
+ 1.00105418133174f, 1.00104229664803f, 1.00103006985615f,
+ 1.00102036557219f, 1.00100778834931f, 1.00096616031686f,
+ 1.00095647745121f, 1.00092507998694f, 1.00091541138654f,
+ 1.00090575009718f, 1.00089487173027f, 1.00087920118928f,
+ 1.00086956165688f, 1.00084041349058f, 1.00082467685478f,
+ 1.00080693845908f, 1.00079732740243f, 1.00078092556175f,
+ 1.00074906862448f, 1.00073947877630f, 1.00072989615011f,
+ 1.00072019315343f, 1.00066830628723f, 1.00065874454301f,
+ 1.00064918998899f, 1.00063246831712f, 1.00061832499982f,
+ 1.00060879176472f, 1.00059926568779f, 1.00058974676105f,
+ 1.00058023497646f, 1.00055457310189f, 1.00054507529979f,
+ 1.00049419893387f, 1.00048471465008f, 1.00044437316419f,
+ 1.00043490254958f, 1.00042341268056f, 1.00039435986397f,
+ 1.00038491011887f, 1.00037546743804f, 1.00036303684998f,
+ 1.00034636152703f, 1.00033693981721f, 1.00032504191268f,
+ 1.00031563421870f, 1.00030623354207f, 1.00029683987498f,
+ 1.00028352575811f, 1.00026603619147f, 1.00025666330226f,
+ 1.00024729739164f, 1.00023128713687f, 1.00022193504773f,
+ 1.00020066879491f, 1.00019133040773f, 1.00017618304649f,
+ 1.00016577323552f, 1.00015645552966f, 1.00013420200033f,
+ 1.00009861649226f, 1.00008931885617f, 1.00008002811490f,
+ 1.00007062639745f, 1.00005669782209f, 1.00004496048148f,
+ 1.00003569712223f, 1.00002644061987f, 1.00000924294396f,
+ 0.999999999999995f};
+
+// Curve which is scaled by |kCurveCorrectionMultipliers| and added to the curve
+// generated by the |kHighReverberationCorrectionCurve| polynomial, for
+// reverberation times which result in a feedback factor index greater than
+// |kCurveChangeoverIndex|.
+static const float kHighCorrectionCurve[kCorrectionCurveLength] = {
+ 0.00905424704513036f, 0.00926599025691877f, 0.00947778313262726f,
+ 0.00968962562016418f, 0.00990151766744984f, 0.0101134592224174f,
+ 0.0103254502330116f, 0.0105374906471899f, 0.0107495804129221f,
+ 0.0109617194781898f, 0.0111739077909878f, 0.0113861452993219f,
+ 0.0115984319512115f, 0.0118107676946871f, 0.0120231524777923f,
+ 0.0122355862485828f, 0.0124480689551263f, 0.0126606005455030f,
+ 0.0128731809678055f, 0.0130858101701389f, 0.0132984881006193f,
+ 0.0135112147073766f, 0.0137239899385524f, 0.0139368137423006f,
+ 0.0141496860667869f, 0.0143626068601902f, 0.0145755760707011f,
+ 0.0147885936465225f, 0.0150016595358697f, 0.0152147736869704f,
+ 0.0154279360480643f, 0.0156411465674036f, 0.0158544051932527f,
+ 0.0160677118738880f, 0.0162810665575990f, 0.0164944691926864f,
+ 0.0167079197274641f, 0.0169214181102577f, 0.0171349642894055f,
+ 0.0173485582132578f, 0.0175621998301772f, 0.0177758890885386f,
+ 0.0179896259367293f, 0.0182034103231487f, 0.0184172421962087f,
+ 0.0186311215043333f, 0.0188450481959587f, 0.0190590222195339f,
+ 0.0192730435235194f, 0.0194871120563886f, 0.0197012277666270f,
+ 0.0199153906027323f, 0.0201296005132146f, 0.0203438574465959f,
+ 0.0205581613514112f, 0.0207725121762073f, 0.0209869098695431f,
+ 0.0212013543799902f, 0.0214158456561324f, 0.0216303836465656f,
+ 0.0218449682998980f, 0.0220595995647505f, 0.0222742773897556f,
+ 0.0224890017235585f, 0.0227037725148169f, 0.0229185897122002f,
+ 0.0231334532643903f, 0.0233483631200817f, 0.0235633192279807f,
+ 0.0237783215368064f, 0.0239933699952896f, 0.0242084645521738f,
+ 0.0244236051562147f, 0.0246387917561803f, 0.0248540243008508f,
+ 0.0250693027390185f, 0.0252846270194886f, 0.0254999970910778f,
+ 0.0257154129026155f, 0.0259308744029435f, 0.0261463815409154f,
+ 0.0263619342653978f, 0.0265775325252690f, 0.0267931762694196f,
+ 0.0270088654467529f, 0.0272246000061842f, 0.0274403798966409f,
+ 0.0276562050670630f, 0.0278720754664027f, 0.0280879910436245f,
+ 0.0283039517477049f, 0.0285199575276330f, 0.0287360083324103f,
+ 0.0289521041110502f, 0.0291682448125785f, 0.0293844303860333f,
+ 0.0296006607804654f, 0.0298169359449371f, 0.0300332558285236f,
+ 0.0302496203803120f, 0.0304660295494019f, 0.0306824832849052f,
+ 0.0308989815359457f, 0.0311155242516602f, 0.0313321113811973f,
+ 0.0315487428737179f, 0.0317654186783949f, 0.0319821387444144f,
+ 0.0321989030209739f, 0.0324157114572834f, 0.0326325640025653f,
+ 0.0328494606060544f, 0.0330664012169974f, 0.0332833857846536f,
+ 0.0335004142582945f, 0.0337174865872039f, 0.0339346027206777f,
+ 0.0341517626080246f, 0.0343689661985646f, 0.0345862134416310f,
+ 0.0348035042865692f, 0.0350208386827363f, 0.0352382165795020f,
+ 0.0354556379262483f, 0.0356731026723698f, 0.0358906107672728f,
+ 0.0361081621603763f, 0.0363257568011115f, 0.0365433946389216f,
+ 0.0367610756232627f, 0.0369787997036024f, 0.0371965668294212f,
+ 0.0374143769502114f, 0.0376322300154781f, 0.0378501259747384f,
+ 0.0380680647775213f, 0.0382860463733691f, 0.0385040707118353f,
+ 0.0387221377424862f, 0.0389402474149004f, 0.0391583996786689f,
+ 0.0393765944833944f, 0.0395948317786927f, 0.0398131115141910f,
+ 0.0400314336395295f, 0.0402497981043605f, 0.0404682048583482f,
+ 0.0406866538511695f, 0.0409051450325135f, 0.0411236783520815f,
+ 0.0413422537595872f, 0.0415608712047565f, 0.0417795306373275f,
+ 0.0419982320070504f, 0.0422169752636886f, 0.0424357603570167f,
+ 0.0426545872368219f, 0.0428734558529040f, 0.0430923661550748f,
+ 0.0433113180931585f, 0.0435303116169914f, 0.0437493466764225f,
+ 0.0439684232213125f, 0.0441875412015349f, 0.0444067005669753f,
+ 0.0446259012675311f, 0.0448451432531127f, 0.0450644264736426f,
+ 0.0452837508790555f, 0.0455031164192982f, 0.0457225230443301f,
+ 0.0459419707041227f, 0.0461614593486596f, 0.0463809889279372f,
+ 0.0466005593919636f, 0.0468201706907599f, 0.0470398227743584f,
+ 0.0472595155928048f, 0.0474792490961565f, 0.0476990232344832f,
+ 0.0479188379578670f, 0.0481386932164022f, 0.0483585889601954f,
+ 0.0485785251393657f, 0.0487985017040441f, 0.0490185186043742f,
+ 0.0492385757905118f, 0.0494586732126247f, 0.0496788108208932f,
+ 0.0498989885655103f, 0.0501192063966806f, 0.0401356533420085f,
+ 0.0403559511969490f, 0.0405762889891309f, 0.0407966666688085f,
+ 0.0410170841862478f, 0.0412375414917278f, 0.0414580385355386f,
+ 0.0416785752679840f, 0.0418991516393793f, 0.0421197676000519f,
+ 0.0423404231003423f, 0.0425611180906021f, 0.0427818525211963f,
+ 0.0430026263425014f, 0.0432234395049069f, 0.0434442919588138f,
+ 0.0436651836546360f, 0.0438861145427996f, 0.0441070845737422f,
+ 0.0443280936979149f, 0.0445491418657804f, 0.0447702290278135f,
+ 0.0449913551345018f, 0.0452125201363448f, 0.0454337239838546f,
+ 0.0456549666275551f, 0.0458762480179831f, 0.0460975681056872f,
+ 0.0463189268412284f, 0.0465403241751802f, 0.0467617600581280f,
+ 0.0469832344406698f, 0.0472047472734157f, 0.0474262985069884f,
+ 0.0476478880920221f, 0.0478695159791643f, 0.0480911821190742f,
+ 0.0483128864624232f, 0.0485346289598951f, 0.0487564095621865f,
+ 0.0489782282200054f, 0.0492000848840726f, 0.0494219795051212f,
+ 0.0496439120338962f, 0.0498658824211554f, 0.0500878906176685f,
+ 0.0503099365742177f, 0.0505320202415973f, 0.0507541415706141f,
+ 0.0509763005120871f, 0.0511984970168471f, 0.0514207310357381f,
+ 0.0516430025196157f, 0.0518653114193479f, 0.0520876576858154f,
+ 0.0523100412699105f, 0.0525324621225380f, 0.0527549201946156f,
+ 0.0529774154370724f, 0.0531999478008504f, 0.0534225172369033f,
+ 0.0536451236961979f, 0.0538677671297125f, 0.0540904474884381f,
+ 0.0543131647233778f, 0.0545359187855472f, 0.0547587096259737f,
+ 0.0549815371956978f, 0.0552044014457715f, 0.0554273023272596f,
+ 0.0556502397912386f, 0.0558732137887982f, 0.0560962242710392f,
+ 0.0563192711890757f, 0.0565423544940334f, 0.0567654741370510f,
+ 0.0569886300692788f, 0.0572118222418796f, 0.0574350506060288f,
+ 0.0576583151129133f, 0.0578816157137332f, 0.0581049523597000f,
+ 0.0583283250020387f, 0.0585517335919851f, 0.0485713671581760f,
+ 0.0487948474970971f, 0.0490183636374095f, 0.0492419155303987f,
+ 0.0494655031273628f, 0.0496891263796120f, 0.0499127852384687f,
+ 0.0501364796552677f, 0.0503602095813560f, 0.0505839749680932f,
+ 0.0508077757668506f, 0.0510316119290123f, 0.0512554834059744f,
+ 0.0514793901491452f, 0.0517033321099457f, 0.0519273092398090f,
+ 0.0521513214901801f, 0.0523753688125170f, 0.0525994511582891f,
+ 0.0528235684789790f, 0.0530477207260808f, 0.0532719078511013f,
+ 0.0534961298055596f, 0.0537203865409869f, 0.0539446780089268f,
+ 0.0541690041609351f, 0.0543933649485798f, 0.0546177603234417f,
+ 0.0548421902371131f, 0.0550666546411992f, 0.0552911534873171f,
+ 0.0555156867270965f, 0.0557402543121789f, 0.0559648561942188f,
+ 0.0561894923248822f, 0.0564141626558481f, 0.0566388671388072f,
+ 0.0568636057254629f, 0.0570883783675304f, 0.0573131850167378f,
+ 0.0575380256248254f, 0.0577629001435447f, 0.0579878085246610f,
+ 0.0582127507199510f, 0.0584377266812042f, 0.0586627363602216f,
+ 0.0588877797088170f, 0.0591128566788167f, 0.0593379672220590f,
+ 0.0595631112903944f, 0.0597882888356857f, 0.0600134998098081f,
+ 0.0602387441646493f, 0.0604640218521088f, 0.0606893328240985f,
+ 0.0609146770325428f, 0.0611400544293785f, 0.0613654649665540f,
+ 0.0615909085960309f, 0.0618163852697822f, 0.0620418949397940f,
+ 0.0622674375580639f, 0.0624930130766024f, 0.0627186214474318f,
+ 0.0629442626225872f, 0.0631699365541155f, 0.0633956431940764f,
+ 0.0534175715719286f, 0.0536433434849815f, 0.0538691479627182f,
+ 0.0540949849572480f, 0.0543208544206912f, 0.0545467563051810f,
+ 0.0547726905628627f, 0.0549986571458940f, 0.0552246560064449f,
+ 0.0554506870966974f, 0.0556767503688461f, 0.0559028457750979f,
+ 0.0561289732676714f, 0.0563551327987983f, 0.0565813243207222f,
+ 0.0568075477856989f, 0.0570338031459965f, 0.0572600903538957f,
+ 0.0574864093616889f, 0.0577127601216814f, 0.0579391425861903f,
+ 0.0581655567075452f, 0.0583920024380880f, 0.0586184797301730f,
+ 0.0588449885361663f, 0.0590715288084468f, 0.0592981004994055f,
+ 0.0595247035614457f, 0.0597513379469827f, 0.0599780036084447f,
+ 0.0602047004982714f, 0.0604314285689156f, 0.0606581877728418f,
+ 0.0608849780625269f, 0.0611117993904601f, 0.0613386517091431f,
+ 0.0615655349710893f, 0.0617924491288254f, 0.0620193941348894f,
+ 0.0622463699418319f, 0.0624733765022160f, 0.0627004137686168f,
+ 0.0629274816936218f, 0.0631545802298307f, 0.0633817093298557f,
+ 0.0636088689463210f, 0.0638360590318633f, 0.0640632795391316f,
+ 0.0642905304207867f, 0.0645178116295023f, 0.0647451231179644f,
+ 0.0649724648388708f, 0.0651998367449316f, 0.0654272387888696f,
+ 0.0656546709234196f, 0.0658821331013287f, 0.0661096252753566f,
+ 0.0663371473982747f, 0.0665646994228671f, 0.0667922813019303f,
+ 0.0568160820656600f, 0.0570437235121022f, 0.0572713946714774f,
+ 0.0574990954966311f, 0.0577268259404211f, 0.0579545859557173f,
+ 0.0581823754954017f, 0.0584101945123692f, 0.0586380429595264f,
+ 0.0588659207897921f, 0.0590938279560984f, 0.0593217644113885f,
+ 0.0595497301086181f, 0.0597777250007558f, 0.0600057490407822f,
+ 0.0602338021816895f, 0.0604618843764834f, 0.0606899955781809f,
+ 0.0609181357398114f, 0.0611463048144174f, 0.0613745027550527f,
+ 0.0616027295147840f, 0.0618309850466897f, 0.0620592693038611f,
+ 0.0622875822394012f, 0.0625159238064261f, 0.0627442939580634f,
+ 0.0629726926474533f, 0.0632011198277480f, 0.0634295754521126f,
+ 0.0636580594737237f, 0.0638865718457710f, 0.0641151125214557f,
+ 0.0643436814539919f, 0.0645722785966058f, 0.0648009039025354f,
+ 0.0650295573250316f, 0.0652582388173575f, 0.0654869483327883f,
+ 0.0657156858246115f, 0.0659444512461268f, 0.0661732445506464f,
+ 0.0664020656914949f, 0.0666309146220087f, 0.0668597912955365f,
+ 0.0670886956654401f, 0.0673176276850925f, 0.0675465873078798f,
+ 0.0677755744872001f, 0.0680045891764636f, 0.0682336313290928f,
+ 0.0684627008985227f, 0.0686917978382008f, 0.0689209221015861f,
+ 0.0691500736421506f, 0.0693792524133784f, 0.0594046474461534f,
+ 0.0596338805392087f, 0.0598631407234532f, 0.0600924279524199f,
+ 0.0603217421796543f, 0.0605510833587138f, 0.0607804514431689f,
+ 0.0610098463866017f, 0.0612392681426066f, 0.0614687166647906f,
+ 0.0616981919067730f, 0.0619276938221849f, 0.0621572223646700f,
+ 0.0623867774878845f, 0.0626163591454967f, 0.0628459672911870f,
+ 0.0630756018786481f, 0.0633052628615854f, 0.0635349501937161f,
+ 0.0637646638287699f, 0.0639944037204887f, 0.0642241698226267f,
+ 0.0644539620889507f, 0.0646837804732392f, 0.0649136249292833f,
+ 0.0651434954108865f, 0.0653733918718643f, 0.0656033142660447f,
+ 0.0658332625472679f, 0.0660632366693863f, 0.0662932365862647f,
+ 0.0665232622517804f, 0.0667533136198224f, 0.0669833906442924f,
+ 0.0672134932791041f, 0.0674436214781841f, 0.0676737751954706f,
+ 0.0679039543849144f, 0.0681341590004783f, 0.0683643889961381f,
+ 0.0685946443258808f, 0.0688249249437064f, 0.0690552308036274f,
+ 0.0692855618596678f, 0.0695159180658648f, 0.0697462993762669f,
+ 0.0699767057449354f, 0.0702071371259442f, 0.0704375934733789f,
+ 0.0706680747413375f, 0.0708985808839306f, 0.0711291118552808f,
+ 0.0713596676095232f, 0.0715902481008047f, 0.0616170423606727f,
+ 0.0618476721885236f, 0.0620783266159294f, 0.0623090055970863f,
+ 0.0625397090862030f, 0.0627704370375001f, 0.0630011894052112f,
+ 0.0632319661435816f, 0.0634627672068692f, 0.0636935925493440f,
+ 0.0639244421252883f, 0.0641553158889967f, 0.0643862137947761f,
+ 0.0646171357969457f, 0.0648480818498370f, 0.0650790519077937f,
+ 0.0653100459251719f, 0.0655410638563397f, 0.0657721056556779f,
+ 0.0660031712775794f, 0.0662342606764491f, 0.0664653738067047f,
+ 0.0666965106227758f, 0.0669276710791043f, 0.0671588551301446f,
+ 0.0673900627303632f, 0.0676212938342389f, 0.0678525483962630f,
+ 0.0680838263709389f, 0.0683151277127820f, 0.0685464523763204f,
+ 0.0687778003160946f, 0.0690091714866568f, 0.0692405658425719f,
+ 0.0694719833384170f, 0.0697034239287815f, 0.0699348875682669f,
+ 0.0701663742114875f, 0.0703978838130692f, 0.0706294163276505f,
+ 0.0708609717098825f, 0.0710925499144278f, 0.0713241508959620f,
+ 0.0715557746091728f, 0.0717874210087600f, 0.0720190900494359f,
+ 0.0722507816859246f, 0.0724824958729632f, 0.0727142325653007f,
+ 0.0729459917176984f, 0.0731777732849299f, 0.0734095772217809f,
+ 0.0736414034830499f, 0.0738732520235469f, 0.0741051227980950f,
+ 0.0641332048389163f, 0.0643651199460837f, 0.0645970571518437f,
+ 0.0648290164110684f, 0.0650609976786417f, 0.0652930009094604f,
+ 0.0655250260584330f, 0.0657570730804803f, 0.0659891419305358f,
+ 0.0662212325635450f, 0.0664533449344658f, 0.0666854789982679f,
+ 0.0669176347099340f, 0.0671498120244587f, 0.0673820108968489f,
+ 0.0676142312821242f, 0.0678464731353154f, 0.0680787364114669f,
+ 0.0683110210656344f, 0.0685433270528865f, 0.0687756543283037f,
+ 0.0690080028469791f, 0.0692403725640174f, 0.0694727634345366f,
+ 0.0697051754136662f, 0.0699376084565483f, 0.0701700625183374f,
+ 0.0704025375541997f, 0.0706350335193146f, 0.0708675503688727f,
+ 0.0711000880580778f, 0.0713326465421456f, 0.0715652257763042f,
+ 0.0717978257157935f, 0.0720304463158665f, 0.0722630875317879f,
+ 0.0724957493188349f, 0.0727284316322967f, 0.0729611344274751f,
+ 0.0731938576596843f, 0.0734266012842503f, 0.0736593652565118f,
+ 0.0738921495318196f, 0.0741249540655367f, 0.0743577788130385f,
+ 0.0745906237297128f, 0.0748234887709595f, 0.0750563738921907f,
+ 0.0752892790488311f, 0.0755222041963173f, 0.0757551492900986f,
+ 0.0759881142856362f, 0.0762210991384039f, 0.0764541038038875f,
+ 0.0766871282375853f, 0.0769201723950076f, 0.0669494253090649f,
+ 0.0671825087805169f, 0.0674156118422988f, 0.0676487344499700f,
+ 0.0678818765591026f, 0.0681150381252804f, 0.0683482191041003f,
+ 0.0685814194511707f, 0.0688146391221127f, 0.0690478780725596f,
+ 0.0692811362581574f, 0.0695144136345632f, 0.0697477101574477f,
+ 0.0699810257824931f, 0.0702143604653941f, 0.0704477141618579f,
+ 0.0706810868276036f, 0.0709144784183627f, 0.0711478888898790f,
+ 0.0713813181979088f, 0.0716147662982205f, 0.0718482331465947f,
+ 0.0720817186988244f, 0.0723152229107147f, 0.0725487457380832f,
+ 0.0727822871367598f, 0.0730158470625864f, 0.0732494254714176f,
+ 0.0734830223191197f, 0.0737166375615722f, 0.0739502711546658f,
+ 0.0741839230543041f, 0.0744175932164030f, 0.0746512815968905f,
+ 0.0748849881517070f, 0.0751187128368048f, 0.0753524556081493f,
+ 0.0755862164217173f, 0.0758199952334984f, 0.0760537919994943f,
+ 0.0762876066757191f, 0.0765214392181990f, 0.0767552895829728f,
+ 0.0769891577260911f, 0.0772230436036172f, 0.0774569471716267f,
+ 0.0776908683862069f, 0.0779248072034582f, 0.0781587635794926f,
+ 0.0783927374704347f, 0.0786267288324215f, 0.0788607376216020f,
+ 0.0790947637941377f, 0.0793288073062022f, 0.0795628681139814f,
+ 0.0797969461736736f, 0.0800310414414898f, 0.0802651538736520f,
+ 0.0804992834263956f, 0.0807334300559682f, 0.0707637827960168f,
+ 0.0709979634480382f, 0.0712321610457045f, 0.0714663755453118f,
+ 0.0717006069031690f, 0.0719348550755973f, 0.0721691200189298f,
+ 0.0724034016895124f, 0.0726377000437030f, 0.0728720150378716f,
+ 0.0731063466284005f, 0.0733406947716849f, 0.0735750594241317f,
+ 0.0738094405421600f, 0.0740438380822017f, 0.0742782520007005f,
+ 0.0745126822541126f, 0.0747471287989061f, 0.0749815915915625f,
+ 0.0752160705885742f, 0.0754505657464466f, 0.0756850770216972f,
+ 0.0759196043708562f, 0.0761541477504655f, 0.0763887071170792f,
+ 0.0766232824272645f, 0.0768578736376001f, 0.0770924807046775f,
+ 0.0773271035850998f, 0.0775617422354831f, 0.0777963966124555f,
+ 0.0780310666726576f, 0.0782657523727417f, 0.0785004536693729f,
+ 0.0787351705192282f, 0.0789699028789975f, 0.0792046507053824f,
+ 0.0794394139550970f, 0.0796741925848675f, 0.0799089865514328f,
+ 0.0801437958115436f, 0.0803786203219632f, 0.0806134600394671f,
+ 0.0808483149208430f, 0.0810831849228909f, 0.0813180700024232f,
+ 0.0815529701162645f, 0.0817878852212516f, 0.0820228152742338f,
+ 0.0822577602320724f, 0.0824927200516413f, 0.0827276946898264f,
+ 0.0829626841035263f, 0.0831976882496509f, 0.0834327070851236f,
+ 0.0836677405668795f, 0.0839027886518659f, 0.0841378512970423f,
+ 0.0843729284593812f, 0.0846080200958663f, 0.0848431261634945f,
+ 0.0850782466192747f, 0.0853133814202278f, 0.0855485305233871f,
+ 0.0857836938857984f, 0.0860188714645199f, 0.0862540632166216f,
+ 0.0762854581765733f, 0.0765206781466951f, 0.0767559121614814f,
+ 0.0769911601780519f, 0.0772264221535377f, 0.0774616980450831f,
+ 0.0776969878098444f, 0.0779322914049897f, 0.0781676087877001f,
+ 0.0784029399151685f, 0.0786382847446002f, 0.0788736432332130f,
+ 0.0791090153382364f, 0.0793444010169132f, 0.0795798002264975f,
+ 0.0798152129242558f, 0.0800506390674675f, 0.0802860786134237f,
+ 0.0805215315194281f, 0.0807569977427964f, 0.0809924772408571f,
+ 0.0812279699709503f, 0.0814634758904288f, 0.0816989949566574f,
+ 0.0819345271270137f, 0.0821700723588872f, 0.0824056306096794f,
+ 0.0826412018368049f, 0.0828767859976898f, 0.0831123830497728f,
+ 0.0833479929505050f, 0.0835836156573494f, 0.0838192511277818f,
+ 0.0840548993192899f, 0.0842905601893735f, 0.0845262336955456f,
+ 0.0847619197953302f, 0.0849976184462647f, 0.0852333296058980f,
+ 0.0854690532317919f, 0.0857047892815197f, 0.0859405377126680f,
+ 0.0861762984828349f, 0.0864120715496310f, 0.0866478568706792f,
+ 0.0868836544036147f, 0.0871194641060850f, 0.0873552859357498f,
+ 0.0875911198502811f, 0.0878269658073632f, 0.0880628237646929f,
+ 0.0882986936799788f, 0.0885345755109422f, 0.0887704692153166f,
+ 0.0890063747508475f, 0.0892422920752930f, 0.0894782211464236f,
+ 0.0897141619220215f, 0.0899501143598818f, 0.0901860784178115f,
+ 0.0904220540536300f, 0.0906580412251691f, 0.0908940398902726f,
+ 0.0911300500067969f, 0.0913660715326105f, 0.0916021044255941f,
+ 0.0918381486436412f, 0.0920742041446566f, 0.0923102708865582f,
+ 0.0925463488272760f, 0.0927824379247522f, 0.0930185381369413f,
+ 0.0932546494218102f, 0.0934907717373377f, 0.0937269050415152f,
+ 0.0939630492923465f, 0.0941992044478474f, 0.0944353704660461f,
+ 0.0946715473049831f, 0.0949077349227112f, 0.0951439332772953f,
+ 0.0953801423268129f, 0.0956163620293533f, 0.0856487814204062f,
+ 0.0858850223033106f, 0.0861212737135806f, 0.0863575356093548f,
+ 0.0865938079487840f, 0.0868300906900319f, 0.0870663837912740f,
+ 0.0873026872106978f, 0.0875390009065038f, 0.0877753248369042f,
+ 0.0880116589601236f, 0.0882480032343993f, 0.0884843576179805f,
+ 0.0887207220691284f, 0.0889570965461172f, 0.0891934810072328f,
+ 0.0894298754107737f, 0.0896662797150505f, 0.0899026938783861f,
+ 0.0901391178591160f, 0.0903755516155873f, 0.0906119951061600f,
+ 0.0908484482892064f, 0.0910849111231104f, 0.0913213835662688f,
+ 0.0915578655770907f, 0.0917943571139971f, 0.0920308581354216f,
+ 0.0922673685998101f, 0.0925038884656203f, 0.0927404176913226f,
+ 0.0929769562353998f, 0.0932135040563467f, 0.0934500611126704f,
+ 0.0936866273628904f, 0.0939232027655385f, 0.0941597872791585f,
+ 0.0943963808623070f, 0.0946329834735524f, 0.0948695950714755f,
+ 0.0951062156146697f, 0.0953428450617401f, 0.0955794833713046f,
+ 0.0958161305019931f, 0.0960527864124481f, 0.0962894510613237f,
+ 0.0965261244072870f, 0.0967628064090171f, 0.0969994970252055f,
+ 0.0972361962145558f, 0.0974729039357838f, 0.0977096201476179f,
+ 0.0979463448087987f, 0.0981830778780787f, 0.0984198193142229f,
+ 0.0986565690760093f, 0.0988933271222270f, 0.0991300934116780f,
+ 0.0993668679031768f, 0.0996036505555495f, 0.0998404413276351f,
+ 0.100077240178285f, 0.100314047066361f, 0.100550861950741f,
+ 0.100787684790311f, 0.101024515543973f, 0.101261354170637f,
+ 0.101498200629230f, 0.101735054878688f, 0.101971916877960f,
+ 0.102208786586009f, 0.102445663961807f, 0.102682548964341f,
+ 0.102919441552610f, 0.103156341685624f, 0.103393249322406f,
+ 0.103630164421992f, 0.103867086943429f, 0.104104016845776f,
+ 0.104340954088107f, 0.104577898629505f, 0.104814850429067f,
+ 0.105051809445902f, 0.105288775639131f, 0.105525748967888f,
+ 0.105762729391318f, 0.105999716868580f, 0.106236711358845f,
+ 0.106473712821294f, 0.106710721215122f, 0.106947736499538f,
+ 0.107184758633760f, 0.107421787577020f, 0.107658823288562f,
+ 0.107895865727643f, 0.108132914853530f, 0.108369970625506f,
+ 0.108607033002864f, 0.108844101944907f, 0.109081177410956f,
+ 0.109318259360339f, 0.109555347752398f, 0.109792442546489f,
+ 0.110029543701978f, 0.110266651178245f, 0.110503764934681f,
+ 0.110740884930689f, 0.110978011125686f, 0.111215143479099f,
+ 0.111452281950370f, 0.111689426498952f, 0.111926577084308f,
+ 0.112163733665917f, 0.112400896203270f, 0.112638064655866f,
+ 0.112875238983221f, 0.113112419144862f, 0.113349605100326f,
+ 0.113586796809166f, 0.113823994230944f, 0.114061197325236f,
+ 0.114298406051631f, 0.114535620369728f, 0.114772840239140f,
+ 0.115010065619491f, 0.115247296470419f, 0.115484532751574f,
+ 0.115721774422616f, 0.115959021443219f, 0.116196273773071f,
+ 0.116433531371868f, 0.116670794199323f, 0.116908062215158f,
+ 0.117145335379108f, 0.117382613650922f, 0.117619896990358f,
+ 0.117857185357189f, 0.118094478711200f, 0.118331777012186f,
+ 0.118569080219959f, 0.118806388294337f, 0.119043701195156f,
+ 0.119281018882261f, 0.119518341315510f, 0.119755668454773f,
+ 0.119993000259933f, 0.120230336690886f, 0.120467677707538f,
+ 0.120705023269809f, 0.120942373337631f, 0.121179727870948f,
+ 0.121417086829716f, 0.121654450173904f, 0.121891817863493f,
+ 0.122129189858476f, 0.122366566118858f, 0.122603946604659f,
+ 0.122841331275906f, 0.123078720092644f, 0.123316113014926f,
+ 0.123553510002819f, 0.123790911016403f, 0.124028316015769f,
+ 0.124265724961022f, 0.124503137812276f, 0.124740554529660f,
+ 0.124977975073316f, 0.125215399403394f, 0.125452827480062f,
+ 0.125690259263497f, 0.125927694713887f, 0.126165133791435f,
+ 0.126402576456356f, 0.126640022668876f, 0.126877472389234f,
+ 0.127114925577681f, 0.127352382194480f, 0.127589842199908f,
+ 0.127827305554251f, 0.128064772217811f, 0.128302242150900f,
+ 0.128539715313843f, 0.118573380744364f, 0.118810860248038f,
+ 0.119048342862613f, 0.119285828548465f, 0.119523317265979f,
+ 0.119760808975554f, 0.119998303637600f, 0.120235801212540f,
+ 0.120473301660811f, 0.120710804942859f, 0.120948311019145f,
+ 0.121185819850140f, 0.121423331396330f, 0.121660845618210f,
+ 0.121898362476291f, 0.122135881931093f, 0.122373403943149f,
+ 0.122610928473007f, 0.122848455481224f, 0.123085984928370f,
+ 0.123323516775029f, 0.123561050981795f, 0.123798587509275f,
+ 0.124036126318090f, 0.124273667368871f, 0.124511210622262f,
+ 0.124748756038919f, 0.124986303579512f, 0.125223853204721f,
+ 0.125461404875240f, 0.125698958551774f, 0.125936514195041f,
+ 0.126174071765771f, 0.126411631224707f, 0.126649192532603f,
+ 0.126886755650226f, 0.127124320538356f, 0.127361887157783f,
+ 0.127599455469312f, 0.127837025433760f, 0.128074597011953f,
+ 0.128312170164733f, 0.128549744852953f, 0.128787321037478f,
+ 0.129024898679186f, 0.129262477738966f, 0.129500058177720f,
+ 0.129737639956363f, 0.129975223035822f, 0.130212807377034f,
+ 0.130450392940952f, 0.130687979688539f, 0.130925567580771f,
+ 0.131163156578635f, 0.131400746643133f, 0.131638337735276f,
+ 0.131875929816089f, 0.132113522846610f, 0.132351116787888f,
+ 0.132588711600985f, 0.132826307246975f, 0.133063903686944f,
+ 0.133301500881990f, 0.133539098793225f, 0.133776697381772f,
+ 0.134014296608765f, 0.134251896435354f, 0.134489496822697f,
+ 0.134727097731967f, 0.134964699124348f, 0.135202300961038f,
+ 0.135439903203245f, 0.135677505812191f, 0.135915108749109f,
+ 0.136152711975246f, 0.136390315451860f, 0.136627919140220f,
+ 0.136865523001611f, 0.137103126997326f, 0.137340731088674f,
+ 0.137578335236974f, 0.137815939403557f, 0.138053543549769f,
+ 0.138291147636965f, 0.138528751626515f, 0.138766355479799f,
+ 0.139003959158210f, 0.139241562623155f, 0.139479165836051f,
+ 0.139716768758329f, 0.139954371351430f, 0.140191973576809f,
+ 0.140429575395934f, 0.140667176770284f, 0.140904777661350f,
+ 0.141142378030637f, 0.141379977839660f, 0.141617577049948f,
+ 0.141855175623041f, 0.142092773520492f, 0.142330370703868f,
+ 0.142567967134744f, 0.142805562774712f, 0.143043157585373f,
+ 0.143280751528341f, 0.143518344565244f, 0.143755936657720f,
+ 0.143993527767421f, 0.144231117856009f, 0.144468706885161f,
+ 0.144706294816565f, 0.144943881611921f, 0.145181467232942f,
+ 0.145419051641353f, 0.145656634798891f, 0.145894216667305f,
+ 0.146131797208357f, 0.146369376383822f, 0.146606954155485f,
+ 0.146844530485146f, 0.147082105334614f, 0.147319678665714f,
+ 0.147557250440280f, 0.147794820620161f, 0.148032389167217f,
+ 0.148269956043319f, 0.148507521210353f, 0.148745084630214f,
+ 0.148982646264813f, 0.149220206076071f, 0.149457764025922f,
+ 0.149695320076311f, 0.149932874189196f, 0.150170426326549f,
+ 0.150407976450352f, 0.150645524522601f, 0.150883070505302f,
+ 0.151120614360475f, 0.151358156050152f, 0.151595695536379f,
+ 0.151833232781210f, 0.152070767746715f, 0.152308300394975f,
+ 0.152545830688083f, 0.152783358588146f, 0.153020884057280f,
+ 0.153258407057616f, 0.153495927551297f, 0.153733445500477f,
+ 0.153970960867323f, 0.154208473614016f, 0.154445983702745f,
+ 0.154683491095716f, 0.154920995755145f, 0.155158497643259f,
+ 0.155395996722300f, 0.155633492954521f, 0.155870986302186f,
+ 0.156108476727575f, 0.156345964192975f, 0.156583448660691f,
+ 0.156820930093035f, 0.157058408452335f, 0.157295883700930f,
+ 0.157533355801171f, 0.147567013792809f, 0.147804479483445f,
+ 0.148041941912855f, 0.148279401043438f, 0.148516856837608f,
+ 0.148754309257790f, 0.148991758266421f, 0.149229203825950f,
+ 0.149466645898839f, 0.149704084447562f, 0.149941519434606f,
+ 0.150178950822470f, 0.150416378573664f, 0.150653802650711f,
+ 0.150891223016147f, 0.151128639632520f, 0.151366052462390f,
+ 0.151603461468329f, 0.151840866612921f, 0.152078267858765f,
+ 0.152315665168468f, 0.152553058504653f, 0.152790447829953f,
+ 0.153027833107014f, 0.153265214298494f, 0.153502591367065f,
+ 0.153739964275408f, 0.153977332986220f, 0.154214697462207f,
+ 0.154452057666090f, 0.154689413560599f, 0.154926765108481f,
+ 0.155164112272490f, 0.155401455015396f, 0.155638793299981f,
+ 0.155876127089037f, 0.156113456345370f, 0.156350781031798f,
+ 0.156588101111152f, 0.156825416546274f, 0.157062727300019f,
+ 0.157300033335253f, 0.157537334614857f, 0.157774631101722f,
+ 0.158011922758752f, 0.158249209548862f, 0.158486491434983f,
+ 0.158723768380054f, 0.158961040347028f, 0.159198307298871f,
+ 0.159435569198561f, 0.159672826009087f, 0.159910077693452f,
+ 0.160147324214669f, 0.160384565535767f, 0.160621801619783f,
+ 0.160859032429770f, 0.161096257928790f, 0.161333478079920f,
+ 0.161570692846248f, 0.161807902190875f, 0.162045106076912f,
+ 0.162282304467485f, 0.162519497325732f, 0.162756684614802f,
+ 0.162993866297856f, 0.153027231415457f, 0.153264401776015f,
+ 0.153501566420118f, 0.153738725310976f, 0.153975878411812f,
+ 0.154213025685861f, 0.154450167096373f, 0.154687302606606f,
+ 0.154924432179834f, 0.155161555779340f, 0.155398673368422f,
+ 0.155635784910389f, 0.155872890368562f, 0.156109989706276f,
+ 0.156347082886876f, 0.156584169873721f, 0.156821250630182f,
+ 0.157058325119641f, 0.157295393305493f, 0.157532455151146f,
+ 0.157769510620020f, 0.158006559675547f, 0.158243602281171f,
+ 0.158480638400349f, 0.158717667996550f, 0.158954691033254f,
+ 0.159191707473956f, 0.159428717282161f, 0.159665720421387f,
+ 0.159902716855164f, 0.160139706547035f, 0.160376689460556f,
+ 0.160613665559292f, 0.160850634806823f, 0.161087597166742f,
+ 0.161324552602651f, 0.161561501078168f, 0.161798442556921f,
+ 0.162035377002551f, 0.162272304378710f, 0.162509224649065f,
+ 0.162746137777293f, 0.162983043727084f, 0.163219942462139f,
+ 0.163456833946175f, 0.163693718142917f, 0.163930595016105f,
+ 0.164167464529489f, 0.164404326646834f, 0.164641181331916f,
+ 0.164878028548522f, 0.165114868260454f, 0.165351700431524f,
+ 0.155384714102944f, 0.155621531083777f, 0.155858340415260f,
+ 0.156095142061255f, 0.156331935985636f, 0.156568722152290f,
+ 0.156805500525115f, 0.157042271068022f, 0.157279033744935f,
+ 0.157515788519790f, 0.157752535356533f, 0.157989274219126f,
+ 0.158226005071540f, 0.158462727877761f, 0.158699442601785f,
+ 0.158936149207623f, 0.159172847659294f, 0.159409537920833f,
+ 0.159646219956287f, 0.159882893729713f, 0.160119559205183f,
+ 0.160356216346779f, 0.160592865118596f, 0.160829505484743f,
+ 0.161066137409338f, 0.161302760856514f, 0.161539375790416f,
+ 0.161775982175200f, 0.162012579975035f, 0.162249169154102f,
+ 0.162485749676594f, 0.162722321506719f, 0.162958884608692f,
+ 0.163195438946746f, 0.163431984485122f, 0.163668521188075f,
+ 0.163905049019873f, 0.164141567944796f, 0.164378077927134f,
+ 0.164614578931192f, 0.164851070921286f, 0.165087553861745f,
+ 0.165324027716909f, 0.165560492451133f, 0.165796948028780f,
+ 0.166033394414230f, 0.156066020649259f, 0.156302448543495f,
+ 0.156538867138740f, 0.156775276399421f, 0.157011676289976f,
+ 0.157248066774858f, 0.157484447818530f, 0.157720819385467f,
+ 0.157957181440159f, 0.158193533947106f, 0.158429876870820f,
+ 0.158666210175827f, 0.158902533826663f, 0.159138847787880f,
+ 0.159375152024038f, 0.159611446499712f, 0.159847731179489f,
+ 0.160084006027966f, 0.160320271009756f, 0.160556526089482f,
+ 0.160792771231779f, 0.161029006401295f, 0.161265231562690f,
+ 0.161501446680637f, 0.161737651719821f, 0.161973846644939f,
+ 0.162210031420699f, 0.162446206011824f, 0.162682370383048f,
+ 0.162918524499116f, 0.163154668324787f, 0.163390801824832f,
+ 0.163626924964034f, 0.163863037707188f, 0.164099140019102f,
+ 0.164335231864596f, 0.164571313208501f, 0.164807384015662f,
+ 0.165043444250936f, 0.165279493879192f, 0.165515532865311f,
+ 0.165751561174187f, 0.155783767848112f, 0.156019774697231f,
+ 0.156255770763861f, 0.156491756012944f, 0.156727730409436f,
+ 0.156963693918304f, 0.157199646504527f, 0.157435588133098f,
+ 0.157671518769019f, 0.157907438377308f, 0.158143346922994f,
+ 0.158379244371116f, 0.158615130686729f, 0.158851005834898f,
+ 0.159086869780700f, 0.159322722489227f, 0.159558563925579f,
+ 0.159794394054872f, 0.160030212842232f, 0.160266020252799f,
+ 0.160501816251724f, 0.160737600804171f, 0.160973373875317f,
+ 0.161209135430348f, 0.161444885434466f, 0.161680623852884f,
+ 0.161916350650826f, 0.162152065793531f, 0.162387769246248f,
+ 0.162623460974239f, 0.162859140942778f, 0.163094809117152f,
+ 0.163330465462660f, 0.163566109944612f, 0.163801742528333f,
+ 0.164037363179157f, 0.164272971862433f, 0.164508568543521f,
+ 0.164744153187794f, 0.154775914838023f, 0.155011475304832f,
+ 0.155247023631016f, 0.155482559781998f, 0.155718083723212f,
+ 0.155953595420103f, 0.156189094838130f, 0.156424581942764f,
+ 0.156660056699488f, 0.156895519073797f, 0.157130969031199f,
+ 0.157366406537214f, 0.157601831557375f, 0.157837244057224f,
+ 0.158072644002320f, 0.158308031358231f, 0.158543406090539f,
+ 0.158778768164837f, 0.159014117546731f, 0.159249454201839f,
+ 0.159484778095791f, 0.159720089194232f, 0.159955387462814f,
+ 0.160190672867206f, 0.160425945373088f, 0.160661204946150f,
+ 0.160896451552098f, 0.161131685156647f, 0.161366905725526f,
+ 0.161602113224477f, 0.161837307619252f, 0.162072488875617f,
+ 0.162307656959350f, 0.162542811836242f, 0.162777953472093f,
+ 0.163013081832719f, 0.163248196883948f, 0.163483298591617f,
+ 0.153514575998966f, 0.153749650917085f, 0.153984712389236f,
+ 0.154219760381308f, 0.154454794859201f, 0.154689815788829f,
+ 0.154924823136117f, 0.155159816867001f, 0.155394796947432f,
+ 0.155629763343373f, 0.155864716020796f, 0.156099654945689f,
+ 0.156334580084050f, 0.156569491401892f, 0.156804388865237f,
+ 0.157039272440121f, 0.157274142092592f, 0.157508997788710f,
+ 0.157743839494548f, 0.157978667176190f, 0.158213480799735f,
+ 0.158448280331291f, 0.158683065736980f, 0.158917836982936f,
+ 0.159152594035305f, 0.159387336860246f, 0.159622065423929f,
+ 0.159856779692538f, 0.160091479632268f, 0.160326165209327f,
+ 0.160560836389934f, 0.160795493140323f, 0.161030135426737f,
+ 0.161264763215433f, 0.161499376472680f, 0.161733975164760f,
+ 0.161968559257967f, 0.151999317795992f, 0.152233872590381f,
+ 0.152468412684851f, 0.152702938045745f, 0.152937448639417f,
+ 0.153171944432235f, 0.153406425390579f, 0.153640891480840f,
+ 0.153875342669423f, 0.154109778922744f, 0.154344200207233f,
+ 0.154578606489328f, 0.154812997735486f, 0.155047373912170f,
+ 0.155281734985858f, 0.155516080923042f, 0.155750411690222f,
+ 0.155984727253915f, 0.156219027580646f, 0.156453312636956f,
+ 0.156687582389395f, 0.156921836804528f, 0.157156075848931f,
+ 0.157390299489191f, 0.157624507691911f, 0.157858700423702f,
+ 0.158092877651190f, 0.158327039341012f, 0.158561185459819f,
+ 0.158795315974272f, 0.159029430851045f, 0.159263530056826f,
+ 0.159497613558314f, 0.159731681322219f, 0.159965733315264f,
+ 0.160199769504187f, 0.150229978933122f, 0.150463983414054f,
+ 0.150697971991144f, 0.150931944631177f, 0.151165901300950f,
+ 0.151399841967272f, 0.151633766596964f, 0.151867675156863f,
+ 0.152101567613812f, 0.152335443934671f, 0.152569304086311f,
+ 0.152803148035615f, 0.153036975749479f, 0.153270787194809f,
+ 0.153504582338527f, 0.153738361147564f, 0.153972123588865f,
+ 0.154205869629387f, 0.154439599236099f, 0.154673312375982f,
+ 0.154907009016030f, 0.155140689123249f, 0.155374352664657f,
+ 0.155607999607285f, 0.155841629918175f, 0.156075243564383f,
+ 0.156308840512976f, 0.156542420731034f, 0.156775984185648f,
+ 0.157009530843923f, 0.157243060672975f, 0.157476573639934f,
+ 0.157710069711939f, 0.157943548856145f, 0.158177011039717f,
+ 0.158410456229833f, 0.158643884393684f, 0.148673484575858f,
+ 0.148906878588797f, 0.149140255477114f, 0.149373615208048f,
+ 0.149606957748852f, 0.149840283066790f, 0.150073591129136f,
+ 0.150306881903181f, 0.150540155356224f, 0.150773411455578f,
+ 0.151006650168570f, 0.151239871462536f, 0.151473075304826f,
+ 0.151706261662802f, 0.151939430503840f, 0.152172581795324f,
+ 0.152405715504656f, 0.152638831599245f, 0.152871930046515f,
+ 0.153105010813902f, 0.153338073868854f, 0.153571119178832f,
+ 0.153804146711309f, 0.154037156433768f, 0.154270148313708f,
+ 0.154503122318637f, 0.154736078416078f, 0.154969016573565f,
+ 0.155201936758644f, 0.155434838938874f, 0.155667723081826f,
+ 0.155900589155082f, 0.156133437126239f, 0.156366266962903f,
+ 0.156599078632696f, 0.156831872103249f, 0.157064647342207f,
+ 0.147093593394615f, 0.147326332073366f, 0.147559052423530f,
+ 0.147791754412800f, 0.148024438008882f, 0.148257103179495f,
+ 0.148489749892369f, 0.148722378115246f, 0.148954987815883f,
+ 0.149187578962047f, 0.149420151521517f, 0.149652705462085f,
+ 0.149885240751555f, 0.150117757357745f, 0.150350255248482f,
+ 0.150582734391608f, 0.150815194754977f, 0.151047636306454f,
+ 0.151280059013917f, 0.151512462845255f, 0.151744847768373f,
+ 0.151977213751184f, 0.152209560761616f, 0.152441888767607f,
+ 0.152674197737110f, 0.152906487638089f, 0.153138758438519f,
+ 0.153371010106390f, 0.153603242609701f, 0.153835455916467f,
+ 0.154067649994712f, 0.154299824812474f, 0.154531980337803f,
+ 0.154764116538760f, 0.154996233383421f, 0.155228330839873f,
+ 0.155460408876213f, 0.145488656537942f, 0.145720695638407f,
+ 0.145952715223132f, 0.146184715260266f, 0.146416695717967f,
+ 0.146648656564411f, 0.146880597767780f, 0.147112519296273f,
+ 0.147344421118099f, 0.147576303201479f, 0.147808165514649f,
+ 0.148040008025854f, 0.148271830703353f, 0.148503633515418f,
+ 0.148735416430330f, 0.148967179416387f, 0.149198922441895f,
+ 0.149430645475174f, 0.149662348484558f, 0.149894031438390f,
+ 0.150125694305028f, 0.150357337052841f, 0.150588959650210f,
+ 0.150820562065529f, 0.151052144267205f, 0.151283706223655f,
+ 0.151515247903310f, 0.151746769274613f, 0.151978270306019f,
+ 0.152209750965996f, 0.152441211223024f, 0.152672651045593f,
+ 0.152904070402210f, 0.153135469261390f, 0.153366847591662f,
+ 0.153598205361567f, 0.153829542539659f, 0.154060859094504f,
+ 0.154292154994679f, 0.154523430208775f, 0.144550873782782f,
+ 0.144782107530540f, 0.145013320498062f, 0.145244512653990f,
+ 0.145475683966974f, 0.145706834405678f, 0.145937963938779f,
+ 0.146169072534965f, 0.146400160162936f, 0.146631226791407f,
+ 0.146862272389103f, 0.147093296924760f, 0.147324300367130f,
+ 0.147555282684973f, 0.147786243847065f, 0.148017183822193f,
+ 0.148248102579156f, 0.148479000086764f, 0.148709876313842f,
+ 0.148940731229225f, 0.149171564801762f, 0.149402377000313f,
+ 0.149633167793751f, 0.149863937150961f, 0.150094685040840f,
+ 0.150325411432298f, 0.150556116294257f, 0.150786799595650f,
+ 0.151017461305425f, 0.151248101392539f, 0.151478719825965f,
+ 0.151709316574685f, 0.151939891607695f, 0.152170444894002f,
+ 0.152400976402628f, 0.152631486102603f, 0.152861973962974f,
+ 0.153092439952797f, 0.153322884041140f, 0.153553306197087f,
+ 0.153783706389730f, 0.154014084588175f, 0.144040629838929f,
+ 0.144270963956348f, 0.144501275986961f, 0.144731565899924f,
+ 0.144961833664404f, 0.145192079249581f, 0.145422302624648f,
+ 0.145652503758808f, 0.145882682621278f, 0.146112839181288f,
+ 0.146342973408078f, 0.146573085270901f, 0.146803174739024f,
+ 0.147033241781725f, 0.147263286368294f, 0.147493308468033f,
+ 0.147723308050258f, 0.147953285084295f, 0.148183239539485f,
+ 0.148413171385178f, 0.148643080590738f, 0.148872967125543f,
+ 0.149102830958981f, 0.149332672060452f, 0.149562490399370f,
+ 0.149792285945159f, 0.150022058667259f, 0.150251808535119f,
+ 0.150481535518200f, 0.150711239585978f, 0.150940920707939f,
+ 0.151170578853583f, 0.151400213992420f, 0.151629826093976f,
+ 0.151859415127784f, 0.152088981063395f, 0.152318523870367f,
+ 0.152548043518276f, 0.152777539976703f, 0.153007013215249f,
+ 0.153236463203521f, 0.153465889911143f, 0.153695293307748f,
+ 0.153924673362982f, 0.154154030046506f, 0.154383363327988f,
+ 0.144408862254502f, 0.144638148640966f, 0.144867411534476f,
+ 0.145096650904754f, 0.145325866721530f, 0.145555058954550f,
+ 0.145784227573570f, 0.146013372548361f, 0.146242493848704f,
+ 0.146471591444392f, 0.146700665305232f, 0.146929715401042f,
+ 0.147158741701652f, 0.147387744176907f, 0.147616722796661f,
+ 0.147845677530781f, 0.148074608349148f, 0.148303515221653f,
+ 0.148532398118202f, 0.148761257008710f, 0.148990091863106f,
+ 0.149218902651333f, 0.149447689343343f, 0.149676451909102f,
+ 0.149905190318589f, 0.150133904541793f, 0.150362594548718f,
+ 0.150591260309378f, 0.150819901793800f, 0.151048518972024f,
+ 0.151277111814102f, 0.151505680290097f, 0.151734224370087f,
+ 0.151962744024160f, 0.152191239222416f, 0.152419709934969f,
+ 0.152648156131945f, 0.152876577783480f, 0.153104974859726f,
+ 0.153333347330843f, 0.153561695167008f, 0.153790018338407f,
+ 0.154018316815238f, 0.154246590567715f, 0.154474839566059f,
+ 0.154703063780507f, 0.154931263181308f, 0.155159437738722f,
+ 0.155387587423022f, 0.155615712204492f, 0.155843812053431f,
+ 0.156071886940148f, 0.156299936834965f, 0.146324150785604f,
+ 0.146552150607636f, 0.146780125348808f, 0.147008074979490f,
+ 0.147235999470067f, 0.147463898790933f, 0.147691772912497f,
+ 0.147919621805179f, 0.148147445439411f, 0.148375243785639f,
+ 0.148603016814319f, 0.148830764495920f, 0.149058486800924f,
+ 0.149286183699826f, 0.149513855163131f, 0.149741501161358f,
+ 0.149969121665038f, 0.150196716644712f, 0.150424286070939f,
+ 0.150651829914283f, 0.150879348145326f, 0.151106840734659f,
+ 0.151334307652887f, 0.151561748870628f, 0.151789164358508f,
+ 0.152016554087171f, 0.152243918027269f, 0.152471256149469f,
+ 0.152698568424449f, 0.152925854822898f, 0.153153115315520f,
+ 0.153380349873030f, 0.153607558466155f, 0.153834741065634f,
+ 0.154061897642219f, 0.154289028166675f, 0.154516132609777f,
+ 0.154743210942315f, 0.154970263135090f, 0.155197289158914f,
+ 0.155424288984613f, 0.155651262583025f, 0.155878209925000f,
+ 0.156105130981400f, 0.156332025723100f, 0.156558894120987f,
+ 0.156785736145960f, 0.157012551768931f, 0.157239340960823f,
+ 0.157466103692572f, 0.157692839935127f, 0.157919549659449f,
+ 0.158146232836509f, 0.158372889437294f, 0.158599519432801f,
+ 0.158826122794039f, 0.159052699492031f, 0.159279249497811f,
+ 0.159505772782425f, 0.159732269316933f, 0.159958739072404f,
+ 0.160185182019924f, 0.160411598130588f, 0.160637987375502f,
+ 0.160864349725789f, 0.161090685152580f, 0.161316993627020f,
+ 0.161543275120267f, 0.151565718680876f, 0.151791946125256f,
+ 0.152018146501987f, 0.152244319782275f, 0.152470465937339f,
+ 0.152696584938411f, 0.152922676756732f, 0.153148741363559f,
+ 0.153374778730158f, 0.153600788827810f, 0.153826771627808f,
+ 0.154052727101455f, 0.154278655220068f, 0.154504555954977f,
+ 0.154730429277522f, 0.154956275159058f, 0.155182093570950f,
+ 0.155407884484577f, 0.155633647871328f, 0.155859383702607f,
+ 0.156085091949829f, 0.156310772584421f, 0.156536425577822f,
+ 0.156762050901484f, 0.156987648526872f, 0.157213218425462f,
+ 0.157438760568743f, 0.157664274928215f, 0.157889761475393f,
+ 0.158115220181800f, 0.158340651018977f, 0.158566053958471f,
+ 0.158791428971847f, 0.159016776030678f, 0.159242095106551f,
+ 0.159467386171067f, 0.159692649195835f, 0.159917884152481f,
+ 0.160143091012640f, 0.160368269747960f, 0.160593420330103f,
+ 0.160818542730740f, 0.161043636921558f, 0.161268702874254f,
+ 0.161493740560537f, 0.161718749952131f, 0.161943731020768f,
+ 0.162168683738195f, 0.162393608076173f, 0.162618504006471f,
+ 0.162843371500873f, 0.163068210531175f, 0.163293021069186f,
+ 0.163517803086724f, 0.163742556555623f, 0.163967281447728f,
+ 0.164191977734896f, 0.164416645388997f, 0.164641284381911f,
+ 0.164865894685533f, 0.165090476271770f, 0.165315029112540f,
+ 0.165539553179773f, 0.165764048445414f, 0.165988514881416f,
+ 0.166212952459749f, 0.166437361152392f, 0.166661740931336f,
+ 0.166886091768588f, 0.167110413636163f, 0.167334706506090f,
+ 0.167558970350412f, 0.167783205141181f, 0.168007410850464f,
+ 0.168231587450339f, 0.168455734912896f, 0.168679853210239f,
+ 0.168903942314481f, 0.169128002197751f, 0.169352032832189f,
+ 0.169576034189945f, 0.169800006243185f, 0.170023948964084f,
+ 0.170247862324832f, 0.170471746297630f, 0.170695600854690f,
+ 0.170919425968239f, 0.171143221610514f, 0.171366987753766f,
+ 0.171590724370256f, 0.171814431432261f, 0.172038108912066f,
+ 0.172261756781971f, 0.172485375014288f, 0.172708963581339f,
+ 0.172932522455463f, 0.173156051609007f, 0.173379551014331f,
+ 0.173603020643809f, 0.173826460469826f, 0.174049870464779f,
+ 0.174273250601078f, 0.174496600851146f, 0.174719921187417f,
+ 0.174943211582337f, 0.175166472008365f, 0.175389702437973f,
+ 0.175612902843644f, 0.175836073197874f, 0.176059213473171f,
+ 0.176282323642056f, 0.176505403677060f, 0.176728453550729f,
+ 0.176951473235621f, 0.177174462704304f, 0.177397421929360f,
+ 0.177620350883383f, 0.177843249538981f, 0.178066117868771f,
+ 0.178288955845384f, 0.178511763441463f, 0.178734540629664f,
+ 0.178957287382655f, 0.179180003673115f, 0.179402689473738f,
+ 0.179625344757226f, 0.179847969496298f, 0.180070563663683f,
+ 0.180293127232121f, 0.180515660174367f, 0.180738162463187f,
+ 0.180960634071358f, 0.181183074971672f, 0.181405485136931f,
+ 0.181627864539950f, 0.181850213153558f, 0.182072530950592f,
+ 0.182294817903906f, 0.182517073986364f, 0.182739299170841f,
+ 0.182961493430228f, 0.183183656737425f, 0.183405789065345f,
+ 0.183627890386914f, 0.183849960675070f, 0.184071999902763f,
+ 0.184294008042956f, 0.184515985068623f, 0.184737930952752f,
+ 0.184959845668342f, 0.185181729188404f, 0.185403581485962f,
+ 0.185625402534053f, 0.185847192305725f, 0.186068950774038f,
+ 0.186290677912066f, 0.186512373692895f, 0.186734038089621f,
+ 0.186955671075354f, 0.187177272623217f, 0.187398842706344f,
+ 0.187620381297882f, 0.187841888370990f, 0.188063363898839f,
+ 0.188284807854612f, 0.188506220211506f, 0.188727600942729f,
+ 0.188948950021500f, 0.189170267421053f, 0.189391553114633f,
+ 0.189612807075496f, 0.189834029276914f, 0.190055219692166f,
+ 0.190276378294547f, 0.190497505057364f, 0.190718599953936f,
+ 0.190939662957593f, 0.191160694041678f, 0.191381693179547f,
+ 0.191602660344568f, 0.181619784587509f, 0.181840687726985f,
+ 0.182061558813791f, 0.182282397821343f, 0.182503204723069f,
+ 0.182723979492412f, 0.182944722102825f, 0.183165432527773f,
+ 0.183386110740737f, 0.183606756715205f, 0.183827370424682f,
+ 0.184047951842681f, 0.184268500942731f, 0.184489017698371f,
+ 0.184709502083153f, 0.184929954070642f, 0.185150373634414f,
+ 0.185370760748058f, 0.185591115385175f, 0.185811437519379f,
+ 0.186031727124294f, 0.186251984173560f, 0.186472208640826f,
+ 0.186692400499755f, 0.186912559724022f, 0.187132686287313f,
+ 0.187352780163329f, 0.187572841325781f, 0.187792869748393f,
+ 0.188012865404900f, 0.188232828269052f, 0.188452758314610f,
+ 0.188672655515346f, 0.188892519845045f, 0.189112351277506f,
+ 0.189332149786539f, 0.189551915345965f, 0.189771647929618f,
+ 0.189991347511347f, 0.190211014065009f, 0.190430647564477f,
+ 0.190650247983633f, 0.190869815296374f, 0.191089349476607f,
+ 0.191308850498254f, 0.191528318335246f, 0.191747752961530f,
+ 0.191967154351062f, 0.192186522477811f, 0.192405857315761f,
+ 0.192625158838903f, 0.192844427021247f, 0.193063661836809f,
+ 0.193282863259621f, 0.193502031263726f, 0.193721165823180f,
+ 0.193940266912050f, 0.194159334504417f, 0.194378368574374f,
+ 0.194597369096023f, 0.194816336043484f, 0.195035269390884f,
+ 0.195254169112365f, 0.195473035182082f, 0.195691867574200f,
+ 0.195910666262898f, 0.196129431222366f, 0.196348162426807f,
+ 0.196566859850436f, 0.196785523467482f, 0.197004153252183f,
+ 0.197222749178791f, 0.197441311221572f, 0.197659839354801f,
+ 0.197878333552768f, 0.198096793789773f, 0.198315220040131f,
+ 0.198533612278166f, 0.198751970478218f, 0.198970294614635f,
+ 0.199188584661781f, 0.199406840594031f, 0.199625062385772f,
+ 0.199843250011403f, 0.200061403445335f, 0.200279522661994f,
+ 0.200497607635815f, 0.200715658341246f, 0.200933674752750f,
+ 0.201151656844797f, 0.201369604591875f, 0.201587517968481f,
+ 0.201805396949124f, 0.202023241508327f, 0.202241051620625f,
+ 0.202458827260564f, 0.202676568402703f, 0.202894275021614f,
+ 0.203111947091881f, 0.203329584588098f, 0.203547187484876f,
+ 0.203764755756833f, 0.203982289378603f, 0.204199788324830f,
+ 0.204417252570173f, 0.204634682089301f, 0.204852076856895f,
+ 0.205069436847651f, 0.205286762036273f, 0.195300241474869f,
+ 0.195517496983395f, 0.195734717613981f, 0.195951903341383f,
+ 0.196169054140369f, 0.196386169985719f, 0.196603250852226f,
+ 0.196820296714693f, 0.197037307547939f, 0.197254283326792f,
+ 0.197471224026094f, 0.197688129620699f, 0.197905000085473f,
+ 0.198121835395295f, 0.198338635525054f, 0.198555400449654f,
+ 0.198772130144011f, 0.198988824583052f, 0.199205483741716f,
+ 0.199422107594955f, 0.199638696117735f, 0.199855249285032f,
+ 0.200071767071834f, 0.200288249453143f, 0.200504696403972f,
+ 0.200721107899348f, 0.200937483914308f, 0.201153824423902f,
+ 0.201370129403194f, 0.201586398827258f, 0.201802632671180f,
+ 0.202018830910062f, 0.202234993519015f, 0.202451120473161f,
+ 0.202667211747639f, 0.202883267317596f, 0.203099287158194f,
+ 0.203315271244605f, 0.203531219552015f, 0.203747132055621f,
+ 0.203963008730634f, 0.204178849552277f, 0.204394654495782f,
+ 0.204610423536399f, 0.204826156649384f, 0.205041853810011f,
+ 0.205257514993562f, 0.205473140175333f, 0.205688729330634f,
+ 0.205904282434784f, 0.206119799463116f, 0.206335280390975f,
+ 0.206550725193719f, 0.206766133846718f, 0.206981506325353f,
+ 0.207196842605018f, 0.197208331738507f, 0.197423595546465f,
+ 0.197638823081710f, 0.197854014319685f, 0.198069169235847f,
+ 0.198284287805661f, 0.198499370004610f, 0.198714415808185f,
+ 0.198929425191892f, 0.199144398131246f, 0.199359334601778f,
+ 0.199574234579030f, 0.199789098038554f, 0.200003924955918f,
+ 0.200218715306700f, 0.200433469066490f, 0.200648186210891f,
+ 0.200862866715519f, 0.201077510556001f, 0.201292117707978f,
+ 0.201506688147100f, 0.201721221849034f, 0.201935718789455f,
+ 0.202150178944052f, 0.202364602288527f, 0.202578988798593f,
+ 0.202793338449976f, 0.203007651218415f, 0.203221927079658f,
+ 0.203436166009470f, 0.203650367983626f, 0.203864532977911f,
+ 0.204078660968127f, 0.204292751930084f, 0.204506805839607f,
+ 0.204720822672532f, 0.204934802404708f, 0.205148745011996f,
+ 0.205362650470268f, 0.205576518755411f, 0.205790349843322f,
+ 0.206004143709912f, 0.206217900331101f, 0.206431619682827f,
+ 0.196441490818421f, 0.196655135559069f, 0.196868742958131f,
+ 0.197082312991588f, 0.197295845635438f, 0.197509340865688f,
+ 0.197722798658360f, 0.197936218989487f, 0.198149601835112f,
+ 0.198362947171294f, 0.198576254974103f, 0.198789525219620f,
+ 0.199002757883940f, 0.199215952943169f, 0.199429110373427f,
+ 0.199642230150843f, 0.199855312251563f, 0.200068356651740f,
+ 0.200281363327544f, 0.200494332255154f, 0.200707263410764f,
+ 0.200920156770577f, 0.201133012310811f, 0.201345830007696f,
+ 0.201558609837472f, 0.201771351776394f, 0.201984055800729f,
+ 0.202196721886754f, 0.202409350010760f, 0.202621940149051f,
+ 0.202834492277942f, 0.203047006373760f, 0.203259482412845f,
+ 0.203471920371550f, 0.203684320226238f, 0.203896681953288f,
+ 0.204109005529087f, 0.204321290930037f, 0.204533538132551f,
+ 0.194541936190444f, 0.194754106925378f, 0.194966239391191f,
+ 0.195178333564346f, 0.195390389421317f, 0.195602406938593f,
+ 0.195814386092672f, 0.196026326860067f, 0.196238229217301f,
+ 0.196450093140911f, 0.196661918607446f, 0.196873705593467f,
+ 0.197085454075546f, 0.197297164030270f, 0.197508835434236f,
+ 0.197720468264055f, 0.197932062496348f, 0.198143618107750f,
+ 0.198355135074909f, 0.198566613374484f, 0.198778052983145f,
+ 0.198989453877578f, 0.199200816034477f, 0.199412139430552f,
+ 0.199623424042522f, 0.199834669847121f, 0.200045876821094f,
+ 0.200257044941199f, 0.200468174184204f, 0.200679264526893f,
+ 0.200890315946060f, 0.201101328418510f, 0.201312301921064f,
+ 0.201523236430552f, 0.201734131923817f, 0.191741177455104f,
+ 0.191951994846504f, 0.192162773152286f, 0.192373512349342f,
+ 0.192584212414577f, 0.192794873324908f, 0.193005495057265f,
+ 0.193216077588589f, 0.193426620895835f, 0.193637124955968f,
+ 0.193847589745967f, 0.194058015242823f, 0.194268401423539f,
+ 0.194478748265130f, 0.194689055744625f, 0.194899323839062f,
+ 0.195109552525495f, 0.195319741780988f, 0.195529891582617f,
+ 0.195740001907471f, 0.195950072732653f, 0.196160104035275f,
+ 0.196370095792464f, 0.196580047981357f, 0.196789960579106f,
+ 0.196999833562872f, 0.197209666909832f, 0.197419460597172f,
+ 0.197629214602091f, 0.197838928901803f, 0.198048603473531f,
+ 0.198258238294511f, 0.188264022419379f, 0.188473577670623f,
+ 0.188683093102902f, 0.188892568693502f, 0.189102004419720f,
+ 0.189311400258868f, 0.189520756188268f, 0.189730072185253f,
+ 0.189939348227172f, 0.190148584291383f, 0.190357780355258f,
+ 0.190566936396181f, 0.190776052391548f, 0.190985128318767f,
+ 0.191194164155259f, 0.191403159878457f, 0.191612115465806f,
+ 0.191821030894764f, 0.192029906142801f, 0.192238741187397f,
+ 0.192447536006049f, 0.192656290576263f, 0.192865004875557f,
+ 0.193073678881463f, 0.193282312571524f, 0.193490905923295f,
+ 0.193699458914346f, 0.193907971522257f, 0.194116443724619f,
+ 0.194324875499038f, 0.194533266823131f, 0.184537806751915f,
+ 0.184746117108257f, 0.184954386947198f, 0.185162616246405f,
+ 0.185370804983555f, 0.185578953136341f, 0.185787060682465f,
+ 0.185995127599643f, 0.186203153865602f, 0.186411139458082f,
+ 0.186619084354836f, 0.186826988533627f, 0.187034851972234f,
+ 0.187242674648445f, 0.187450456540062f, 0.187658197624897f,
+ 0.187865897880778f, 0.188073557285542f, 0.188281175817040f,
+ 0.188488753453134f, 0.188696290171701f, 0.188903785950626f,
+ 0.189111240767811f, 0.189318654601166f, 0.189526027428616f,
+ 0.189733359228097f, 0.189940649977559f, 0.190147899654962f,
+ 0.190355108238280f, 0.180358464782885f, 0.180565591112002f,
+ 0.180772676281026f, 0.180979720267981f, 0.181186723050902f,
+ 0.181393684607836f, 0.181600604916841f, 0.181807483955990f,
+ 0.182014321703366f, 0.182221118137065f, 0.182427873235197f,
+ 0.182634586975881f, 0.182841259337251f, 0.183047890297452f,
+ 0.183254479834642f, 0.183461027926990f, 0.183667534552678f,
+ 0.183873999689901f, 0.184080423316866f, 0.184286805411791f,
+ 0.184493145952909f, 0.184699444918461f, 0.184905702286705f,
+ 0.185111918035908f, 0.185318092144350f, 0.185524224590325f,
+ 0.185730315352137f, 0.185936364408104f, 0.175938560813942f,
+ 0.176144526393218f, 0.176350450201674f, 0.176556332217677f,
+ 0.176762172419604f, 0.176967970785847f, 0.177173727294808f,
+ 0.177379441924904f, 0.177585114654563f, 0.177790745462223f,
+ 0.177996334326338f, 0.178201881225372f, 0.178407386137802f,
+ 0.178612849042117f, 0.178818269916818f, 0.179023648740420f,
+ 0.179228985491448f, 0.179434280148441f, 0.179639532689949f,
+ 0.179844743094535f, 0.180049911340774f, 0.180255037407254f,
+ 0.180460121272574f, 0.180665162915346f, 0.180870162314195f,
+ 0.181075119447757f, 0.181280034294680f, 0.181484906833627f,
+ 0.171485926120658f, 0.171690713979683f, 0.171895459466788f,
+ 0.172100162560683f, 0.172304823240091f, 0.172509441483747f,
+ 0.172714017270397f, 0.172918550578801f, 0.173123041387730f,
+ 0.173327489675969f, 0.173531895422314f, 0.173736258605573f,
+ 0.173940579204567f, 0.174144857198129f, 0.174349092565105f,
+ 0.174553285284351f, 0.174757435334738f, 0.174961542695148f,
+ 0.175165607344476f, 0.175369629261627f, 0.175573608425522f,
+ 0.175777544815091f, 0.175981438409279f, 0.176185289187040f,
+ 0.176389097127344f, 0.176592862209170f, 0.176796584411511f,
+ 0.177000263713372f, 0.167000089171158f, 0.167203682609124f,
+ 0.167407233083699f, 0.167610740573936f, 0.167814205058903f,
+ 0.168017626517678f, 0.168221004929352f, 0.168424340273029f,
+ 0.168627632527822f, 0.168830881672862f, 0.169034087687287f,
+ 0.169237250550250f, 0.169440370240916f, 0.169643446738461f,
+ 0.169846480022075f, 0.170049470070959f, 0.170252416864327f,
+ 0.170455320381406f, 0.170658180601432f, 0.170860997503658f,
+ 0.171063771067346f, 0.171266501271771f, 0.171469188096220f,
+ 0.171671831519994f, 0.171874431522404f, 0.172076988082775f,
+ 0.172279501180443f, 0.162278159872144f, 0.162480585982465f,
+ 0.162682968568167f, 0.162885307608635f, 0.163087603083268f,
+ 0.163289854971476f, 0.163492063252680f, 0.163694227906317f,
+ 0.163896348911833f, 0.164098426248687f, 0.164300459896352f,
+ 0.164502449834311f, 0.164704396042060f, 0.164906298499108f,
+ 0.165108157184976f, 0.165309972079197f, 0.165511743161317f,
+ 0.165713470410892f, 0.165915153807493f, 0.166116793330702f,
+ 0.166318388960114f, 0.166519940675335f, 0.166721448455984f,
+ 0.166922912281694f, 0.167124332132106f, 0.167325707986878f,
+ 0.167527039825678f, 0.157524516705573f, 0.157725760451481f,
+ 0.157926960120494f, 0.158128115692331f, 0.158329227146721f,
+ 0.158530294463405f, 0.158731317622137f, 0.158932296602685f,
+ 0.159133231384826f, 0.159334121948353f, 0.159534968273067f,
+ 0.159735770338785f, 0.159936528125335f, 0.160137241612557f,
+ 0.160337910780302f, 0.160538535608436f, 0.160739116076836f,
+ 0.160939652165391f, 0.161140143854002f, 0.161340591122584f,
+ 0.161540993951062f, 0.161741352319375f, 0.161941666207473f,
+ 0.162141935595320f, 0.162342160462890f, 0.162542340790172f,
+ 0.162742476557164f, 0.162942567743880f, 0.152938803407730f,
+ 0.153138805373977f, 0.153338762700057f, 0.153538675366031f,
+ 0.153738543351972f, 0.153938366637967f, 0.154138145204113f,
+ 0.154337879030521f, 0.154537568097313f, 0.154737212384624f,
+ 0.154936811872602f, 0.155136366541405f, 0.155335876371206f,
+ 0.155535341342188f, 0.155734761434549f, 0.155934136628495f,
+ 0.156133466904249f, 0.156332752242043f, 0.156531992622123f,
+ 0.156731188024747f, 0.156930338430184f, 0.157129443818716f,
+ 0.157328504170639f, 0.157527519466260f, 0.157726489685896f,
+ 0.157925414809880f, 0.158124294818555f, 0.158323129692277f,
+ 0.148318108488803f, 0.148516853033737f, 0.148715552384859f,
+ 0.148914206522576f, 0.149112815427303f, 0.149311379079472f,
+ 0.149509897459523f, 0.149708370547911f, 0.149906798325103f,
+ 0.150105180771577f, 0.150303517867824f, 0.150501809594347f,
+ 0.150700055931663f, 0.150898256860299f, 0.151096412360795f,
+ 0.151294522413704f, 0.151492586999591f, 0.151690606099032f,
+ 0.151888579692616f, 0.152086507760946f, 0.152284390284635f,
+ 0.152482227244310f, 0.152680018620608f, 0.152877764394181f,
+ 0.153075464545691f, 0.153273119055814f, 0.153470727905238f,
+ 0.153668291074661f, 0.143661997622184f, 0.143859469373757f,
+ 0.144056895387502f, 0.144254275644170f, 0.144451610124522f,
+ 0.144648898809330f, 0.144846141679382f, 0.145043338715474f,
+ 0.145240489898417f, 0.145437595209035f, 0.145634654628161f,
+ 0.145831668136644f, 0.146028635715342f, 0.146225557345127f,
+ 0.146422433006884f, 0.146619262681509f, 0.146816046349909f,
+ 0.147012783993008f, 0.147209475591736f, 0.147406121127041f,
+ 0.147602720579879f, 0.147799273931220f, 0.147995781162048f,
+ 0.148192242253357f, 0.148388657186152f, 0.148585025941455f,
+ 0.148781348500295f, 0.148977624843717f, 0.149173854952777f,
+ 0.149370038808543f, 0.139362365469483f, 0.139558456761915f,
+ 0.139754501744331f, 0.139950500397849f, 0.140146452703599f,
+ 0.140342358642723f, 0.140538218196374f, 0.140734031345720f,
+ 0.140929798071938f, 0.141125518356222f, 0.141321192179772f,
+ 0.141516819523806f, 0.141712400369552f, 0.141907934698248f,
+ 0.142103422491149f, 0.142298863729519f, 0.142494258394634f,
+ 0.142689606467784f, 0.142884907930271f, 0.143080162763409f,
+ 0.143275370948524f, 0.143470532466954f, 0.143665647300050f,
+ 0.143860715429175f, 0.144055736835705f, 0.144250711501027f,
+ 0.144445639406540f, 0.144640520533658f, 0.144835354863804f,
+ 0.145030142378415f, 0.145224883058941f, 0.135215765964230f,
+ 0.135410412920980f, 0.135605012988065f, 0.135799566146984f,
+ 0.135994072379245f, 0.136188531666373f, 0.136382943989902f,
+ 0.136577309331380f, 0.136771627672365f, 0.136965898994431f,
+ 0.137160123279160f, 0.137354300508149f, 0.137548430663007f,
+ 0.137742513725355f, 0.137936549676826f, 0.138130538499066f,
+ 0.138324480173732f, 0.138518374682495f, 0.138712222007036f,
+ 0.138906022129051f, 0.139099775030246f, 0.139293480692340f,
+ 0.139487139097066f, 0.139680750226166f, 0.139874314061398f,
+ 0.140067830584528f, 0.140261299777338f, 0.140454721621621f,
+ 0.140648096099182f, 0.140841423191837f, 0.141034702881418f,
+ 0.141227935149766f, 0.141421119978735f, 0.131410446427580f,
+ 0.131603536323403f, 0.131796578725485f, 0.131989573615728f,
+ 0.132182520976047f, 0.132375420788372f, 0.132568273034642f,
+ 0.132761077696810f, 0.132953834756840f, 0.133146544196710f,
+ 0.133339205998410f, 0.133531820143939f, 0.133724386615314f,
+ 0.133916905394560f, 0.134109376463715f, 0.134301799804830f,
+ 0.134494175399969f, 0.134686503231206f, 0.134878783280630f,
+ 0.135071015530340f, 0.135263199962448f, 0.135455336559080f,
+ 0.135647425302371f, 0.135839466174471f, 0.136031459157541f,
+ 0.136223404233754f, 0.136415301385298f, 0.136607150594369f,
+ 0.136798951843178f, 0.136990705113949f, 0.137182410388915f,
+ 0.137374067650325f, 0.137565676880437f, 0.137757238061525f,
+ 0.137948751175871f, 0.127936405283160f, 0.128127822210926f,
+ 0.128319191018876f, 0.128510511689345f, 0.128701784204678f,
+ 0.128893008547232f, 0.129084184699378f, 0.129275312643499f,
+ 0.129466392361988f, 0.129657423837253f, 0.129848407051713f,
+ 0.130039341987800f, 0.130230228627958f, 0.130421066954641f,
+ 0.130611856950320f, 0.130802598597474f, 0.130993291878596f,
+ 0.131183936776193f, 0.131374533272780f, 0.131565081350888f,
+ 0.131755580993060f, 0.131946032181848f, 0.132136434899821f,
+ 0.132326789129556f, 0.132517094853645f, 0.132707352054692f,
+ 0.132897560715312f, 0.133087720818134f, 0.133277832345797f,
+ 0.133467895280954f, 0.133657909606270f, 0.133847875304422f,
+ 0.134037792358100f, 0.134227660750005f, 0.134417480462852f,
+ 0.134607251479366f, 0.134796973782287f, 0.134986647354364f,
+ 0.135176272178362f, 0.125162037314443f, 0.125351564590619f,
+ 0.125541043067079f, 0.125730472726634f, 0.125919853552109f,
+ 0.126109185526341f, 0.126298468632178f, 0.126487702852483f,
+ 0.126676888170129f, 0.126866024568002f, 0.127055112029000f,
+ 0.127244150536033f, 0.127433140072025f, 0.127622080619911f,
+ 0.127810972162637f, 0.127999814683163f, 0.128188608164462f,
+ 0.128377352589517f, 0.128566047941326f, 0.128754694202896f,
+ 0.128943291357249f, 0.129131839387418f, 0.129320338276448f,
+ 0.129508788007399f, 0.129697188563339f, 0.129885539927351f,
+ 0.130073842082530f, 0.130262095011983f, 0.130450298698829f,
+ 0.130638453126200f, 0.130826558277239f, 0.131014614135104f,
+ 0.131202620682961f, 0.131390577903992f, 0.131578485781390f,
+ 0.131766344298360f, 0.131954153438120f, 0.132141913183899f,
+ 0.132329623518940f, 0.132517284426497f, 0.132704895889836f,
+ 0.132892457892237f, 0.133079970416991f, 0.133267433447401f,
+ 0.133454846966783f, 0.133642210958465f, 0.123625714483175f,
+ 0.123812979369491f, 0.124000194678165f, 0.124187360392574f,
+ 0.124374476496108f, 0.124561542972168f, 0.124748559804169f,
+ 0.124935526975537f, 0.125122444469710f, 0.125309312270140f,
+ 0.125496130360289f, 0.125682898723633f, 0.125869617343660f,
+ 0.126056286203869f, 0.126242905287774f, 0.126429474578898f,
+ 0.126615994060779f, 0.126802463716965f, 0.126988883531018f,
+ 0.127175253486512f, 0.127361573567033f, 0.127547843756178f,
+ 0.127734064037559f, 0.127920234394799f, 0.128106354811532f,
+ 0.128292425271406f, 0.128478445758080f, 0.128664416255227f,
+ 0.128850336746530f, 0.129036207215687f, 0.129222027646406f,
+ 0.129407798022407f, 0.129593518327426f, 0.129779188545206f,
+ 0.129964808659507f, 0.130150378654098f, 0.130335898512761f,
+ 0.130521368219292f, 0.130706787757498f, 0.130892157111197f,
+ 0.131077476264222f, 0.131262745200416f, 0.131447963903636f,
+ 0.131633132357750f, 0.131818250546639f, 0.132003318454195f,
+ 0.132188336064325f, 0.132373303360945f, 0.132558220327986f,
+ 0.132743086949389f, 0.132927903209110f, 0.133112669091115f,
+ 0.133297384579382f, 0.133482049657903f, 0.133666664310682f,
+ 0.133851228521735f, 0.134035742275089f, 0.134220205554786f,
+ 0.134404618344876f, 0.134588980629427f, 0.124569481469902f,
+ 0.124753742695616f, 0.124937953368058f, 0.125122113471342f,
+ 0.125306222989596f, 0.125490281906956f, 0.125674290207575f,
+ 0.125858247875615f, 0.126042154895252f, 0.126226011250674f,
+ 0.126409816926081f, 0.126593571905685f, 0.126777276173711f,
+ 0.126960929714395f, 0.127144532511988f, 0.127328084550749f,
+ 0.127511585814954f, 0.127695036288888f, 0.127878435956849f,
+ 0.128061784803149f, 0.128245082812109f, 0.128428329968065f,
+ 0.128611526255365f, 0.128794671658368f, 0.128977766161446f,
+ 0.129160809748984f, 0.129343802405377f, 0.129526744115036f,
+ 0.129709634862381f, 0.129892474631845f, 0.130075263407874f,
+ 0.130258001174926f, 0.130440687917472f, 0.130623323619993f,
+ 0.130805908266985f, 0.130988441842955f, 0.131170924332422f,
+ 0.131353355719918f, 0.131535735989987f, 0.131718065127185f,
+ 0.131900343116080f, 0.132082569941253f, 0.132264745587298f,
+ 0.132446870038820f, 0.132628943280436f, 0.132810965296776f,
+ 0.132992936072482f, 0.133174855592210f, 0.133356723840624f,
+ 0.133538540802406f, 0.133720306462246f, 0.133902020804847f,
+ 0.134083683814926f, 0.134265295477211f, 0.134446855776441f,
+ 0.134628364697371f, 0.134809822224764f, 0.134991228343398f,
+ 0.135172583038063f, 0.135353886293561f, 0.135535138094705f,
+ 0.135716338426323f, 0.135897487273252f, 0.136078584620344f,
+ 0.136259630452462f, 0.136440624754481f, 0.136621567511290f,
+ 0.136802458707789f, 0.136983298328889f, 0.137164086359516f,
+ 0.137344822784607f, 0.137525507589110f, 0.137706140757987f,
+ 0.137886722276213f, 0.138067252128772f, 0.138247730300664f,
+ 0.138428156776899f, 0.138608531542500f, 0.138788854582503f,
+ 0.138969125881954f, 0.139149345425913f, 0.139329513199453f,
+ 0.139509629187658f, 0.139689693375625f, 0.139869705748462f,
+ 0.140049666291290f, 0.140229574989243f, 0.140409431827467f,
+ 0.140589236791119f, 0.140768989865371f, 0.140948691035404f,
+ 0.141128340286414f, 0.141307937603607f, 0.141487482972203f,
+ 0.141666976377434f, 0.141846417804544f, 0.142025807238789f,
+ 0.142205144665437f, 0.142384430069770f, 0.142563663437080f,
+ 0.142742844752673f, 0.142921974001866f, 0.143101051169990f,
+ 0.143280076242387f, 0.143459049204410f, 0.143637970041428f,
+ 0.143816838738820f, 0.143995655281975f, 0.144174419656299f,
+ 0.144353131847207f, 0.144531791840127f, 0.144710399620500f,
+ 0.144888955173778f, 0.145067458485427f, 0.145245909540924f,
+ 0.145424308325758f, 0.145602654825432f, 0.145780949025460f,
+ 0.145959190911367f, 0.146137380468694f, 0.146315517682990f,
+ 0.146493602539820f, 0.146671635024758f, 0.146849615123393f,
+ 0.147027542821324f, 0.147205418104165f, 0.147383240957540f,
+ 0.147561011367085f, 0.147738729318451f, 0.147916394797298f,
+ 0.148094007789301f, 0.148271568280146f, 0.148449076255531f,
+ 0.148626531701166f, 0.148803934602776f, 0.148981284946094f,
+ 0.149158582716869f, 0.149335827900860f, 0.149513020483839f,
+ 0.149690160451591f, 0.149867247789913f, 0.150044282484613f,
+ 0.150221264521513f, 0.150398193886446f, 0.150575070565257f,
+ 0.150751894543806f, 0.150928665807962f, 0.151105384343607f,
+ 0.151282050136638f, 0.151458663172960f, 0.151635223438494f,
+ 0.151811730919171f, 0.151988185600936f, 0.152164587469744f,
+ 0.152340936511564f, 0.152517232712377f, 0.152693476058176f,
+ 0.152869666534967f, 0.153045804128767f, 0.153221888825607f,
+ 0.153397920611528f, 0.153573899472585f, 0.153749825394845f,
+ 0.153925698364388f, 0.154101518367304f, 0.154277285389697f,
+ 0.154452999417684f, 0.154628660437392f, 0.154804268434962f,
+ 0.154979823396547f, 0.155155325308312f, 0.155330774156434f,
+ 0.155506169927103f, 0.155681512606521f, 0.155856802180902f,
+ 0.145828227713860f, 0.146003411036860f, 0.146178541213538f,
+ 0.146353618230160f, 0.146528642073000f, 0.146703612728346f,
+ 0.146878530182500f, 0.147053394421772f, 0.147228205432488f,
+ 0.147402963200985f, 0.147577667713612f, 0.147752318956730f,
+ 0.147926916916715f, 0.148101461579951f, 0.148275952932838f,
+ 0.148450390961786f, 0.148624775653217f, 0.148799106993568f,
+ 0.148973384969286f, 0.149147609566831f, 0.149321780772674f,
+ 0.149495898573301f, 0.149669962955208f, 0.149843973904904f,
+ 0.150017931408910f, 0.150191835453759f, 0.150365686025999f,
+ 0.150539483112186f, 0.150713226698891f, 0.150886916772697f,
+ 0.151060553320199f, 0.151234136328003f, 0.151407665782731f,
+ 0.151581141671012f, 0.151754563979492f, 0.151927932694826f,
+ 0.152101247803684f, 0.152274509292746f, 0.152447717148705f,
+ 0.152620871358268f, 0.152793971908151f, 0.152967018785084f,
+ 0.153140011975811f, 0.153312951467086f, 0.153485837245675f,
+ 0.153658669298358f, 0.153831447611926f, 0.154004172173183f,
+ 0.154176842968946f, 0.154349459986041f, 0.154522023211310f,
+ 0.154694532631606f, 0.154866988233794f, 0.155039390004751f,
+ 0.155211737931367f, 0.155384032000544f, 0.155556272199196f,
+ 0.155728458514250f, 0.155900590932645f, 0.156072669441331f,
+ 0.156244694027273f, 0.156416664677445f, 0.156588581378836f,
+ 0.156760444118446f, 0.156932252883288f, 0.157104007660386f,
+ 0.157275708436777f, 0.157447355199512f, 0.157618947935650f,
+ 0.157790486632267f, 0.157961971276449f, 0.158133401855293f,
+ 0.158304778355912f, 0.158476100765427f, 0.158647369070975f,
+ 0.158818583259702f, 0.158989743318769f, 0.159160849235348f,
+ 0.159331900996624f, 0.159502898589793f, 0.159673842002064f,
+ 0.159844731220658f, 0.160015566232809f, 0.160186347025763f,
+ 0.160357073586779f, 0.160527745903126f, 0.160698363962087f,
+ 0.160868927750957f, 0.161039437257044f, 0.161209892467666f,
+ 0.161380293370157f, 0.161550639951860f, 0.161720932200131f,
+ 0.161891170102339f, 0.151857542723253f, 0.152027671895491f,
+ 0.152197746683846f, 0.152367767075735f, 0.152537733058589f,
+ 0.152707644619850f, 0.152877501746973f, 0.153047304427424f,
+ 0.153217052648684f, 0.153386746398243f, 0.153556385663605f,
+ 0.153725970432286f, 0.153895500691816f, 0.154064976429733f,
+ 0.154234397633591f, 0.154403764290956f, 0.154573076389405f,
+ 0.154742333916527f, 0.154911536859925f, 0.155080685207213f,
+ 0.155249778946017f, 0.155418818063977f, 0.155587802548743f,
+ 0.155756732387980f, 0.155925607569361f, 0.156094428080577f,
+ 0.156263193909327f, 0.156431905043323f, 0.156600561470291f,
+ 0.156769163177967f, 0.156937710154101f, 0.157106202386455f,
+ 0.157274639862803f, 0.157443022570930f, 0.157611350498636f,
+ 0.157779623633731f, 0.157947841964038f, 0.158116005477393f,
+ 0.158284114161644f, 0.158452168004650f, 0.158620166994283f,
+ 0.158788111118428f, 0.158956000364983f, 0.159123834721855f,
+ 0.159291614176966f, 0.159459338718251f, 0.159627008333654f,
+ 0.159794623011134f, 0.159962182738662f, 0.160129687504220f,
+ 0.160297137295804f, 0.160464532101419f, 0.160631871909088f,
+ 0.160799156706840f, 0.160966386482721f, 0.150929750302173f,
+ 0.151096869998492f, 0.151263934637146f, 0.151430944206227f,
+ 0.151597898693841f, 0.151764798088106f, 0.151931642377153f,
+ 0.152098431549124f, 0.152265165592173f, 0.152431844494468f,
+ 0.152598468244187f, 0.152765036829522f, 0.152931550238678f,
+ 0.153098008459870f, 0.153264411481326f, 0.153430759291287f,
+ 0.153597051878007f, 0.153763289229750f, 0.153929471334795f,
+ 0.154095598181429f, 0.154261669757957f, 0.154427686052692f,
+ 0.154593647053961f, 0.154759552750102f, 0.154925403129467f,
+ 0.155091198180420f, 0.155256937891336f, 0.155422622250604f,
+ 0.155588251246622f, 0.155753824867805f, 0.155919343102577f,
+ 0.156084805939376f, 0.156250213366650f, 0.156415565372862f,
+ 0.156580861946485f, 0.156746103076005f, 0.156911288749923f,
+ 0.157076418956747f, 0.157241493685002f, 0.157406512923222f,
+ 0.157571476659956f, 0.157736384883764f, 0.157901237583217f,
+ 0.147862223824288f, 0.148026965440799f, 0.148191651498746f,
+ 0.148356281986751f, 0.148520856893447f, 0.148685376207480f,
+ 0.148849839917509f, 0.149014248012204f, 0.149178600480248f,
+ 0.149342897310336f, 0.149507138491175f, 0.149671324011486f,
+ 0.149835453859999f, 0.149999528025459f, 0.150163546496623f,
+ 0.150327509262259f, 0.150491416311149f, 0.150655267632085f,
+ 0.150819063213874f, 0.150982803045333f, 0.151146487115293f,
+ 0.151310115412596f, 0.151473687926096f, 0.151637204644661f,
+ 0.151800665557170f, 0.151964070652515f, 0.152127419919599f,
+ 0.152290713347339f, 0.152453950924663f, 0.152617132640512f,
+ 0.152780258483839f, 0.152943328443608f, 0.153106342508799f,
+ 0.153269300668400f, 0.153432202911413f, 0.153595049226854f,
+ 0.153757839603748f, 0.153920574031135f, 0.154083252498065f,
+ 0.144042064070991f, 0.144204630584213f, 0.144367141104205f,
+ 0.144529595620070f, 0.144691994120919f, 0.144854336595877f,
+ 0.145016623034082f, 0.145178853424683f, 0.145341027756842f,
+ 0.145503146019733f, 0.145665208202542f, 0.145827214294467f,
+ 0.145989164284721f, 0.146151058162526f, 0.146312895917117f,
+ 0.146474677537742f, 0.146636403013661f, 0.146798072334147f,
+ 0.146959685488484f, 0.147121242465970f, 0.147282743255912f,
+ 0.147444187847633f, 0.147605576230467f, 0.147766908393758f,
+ 0.147928184326867f, 0.148089404019162f, 0.148250567460028f,
+ 0.148411674638859f, 0.148572725545063f, 0.148733720168058f,
+ 0.148894658497279f, 0.149055540522167f, 0.149216366232181f,
+ 0.149377135616789f, 0.139334037742859f, 0.139494694445110f,
+ 0.139655294790435f, 0.139815838768352f, 0.139976326368392f,
+ 0.140136757580096f, 0.140297132393020f, 0.140457450796730f,
+ 0.140617712780806f, 0.140777918334840f, 0.140938067448435f,
+ 0.141098160111208f, 0.141258196312788f, 0.141418176042814f,
+ 0.141578099290940f, 0.141737966046832f, 0.141897776300166f,
+ 0.142057530040633f, 0.142217227257936f, 0.142376867941787f,
+ 0.142536452081915f, 0.142695979668058f, 0.142855450689968f,
+ 0.143014865137407f, 0.143174223000153f, 0.143333524267992f,
+ 0.143492768930726f, 0.143651956978168f, 0.143811088400141f,
+ 0.143970163186484f, 0.144129181327045f, 0.144288142811688f,
+ 0.144447047630285f, 0.134402084850112f, 0.134560876306290f,
+ 0.134719611066120f, 0.134878289119524f, 0.135036910456437f,
+ 0.135195475066808f, 0.135353982940597f, 0.135512434067775f,
+ 0.135670828438328f, 0.135829166042253f, 0.135987446869558f,
+ 0.136145670910266f, 0.136303838154409f, 0.136461948592034f,
+ 0.136620002213200f, 0.136777999007977f, 0.136935938966447f,
+ 0.137093822078707f, 0.137251648334863f, 0.137409417725035f,
+ 0.137567130239356f, 0.137724785867969f, 0.137882384601031f,
+ 0.138039926428711f, 0.138197411341190f, 0.138354839328662f,
+ 0.138512210381332f, 0.138669524489419f, 0.138826781643152f,
+ 0.138983981832774f, 0.128937314125928f, 0.129094400358105f,
+ 0.129251429596973f, 0.129408401832822f, 0.129565317055958f,
+ 0.129722175256696f, 0.129878976425365f, 0.130035720552306f,
+ 0.130192407627872f, 0.130349037642427f, 0.130505610586351f,
+ 0.130662126450032f, 0.130818585223873f, 0.130974986898289f,
+ 0.131131331463705f, 0.131287618910562f, 0.131443849229311f,
+ 0.131600022410415f, 0.131756138444350f, 0.131912197321604f,
+ 0.132068199032678f, 0.132224143568085f, 0.132380030918349f,
+ 0.132535861074008f, 0.132691634025612f, 0.132847349763722f,
+ 0.133003008278912f, 0.133158609561769f, 0.133314153602892f,
+ 0.133469640392892f, 0.123421258999779f, 0.123576631259414f,
+ 0.123731946239833f, 0.123887203931694f, 0.124042404325672f,
+ 0.124197547412451f, 0.124352633182726f, 0.124507661627209f,
+ 0.124662632736620f, 0.124817546501693f, 0.124972402913174f,
+ 0.125127201961822f, 0.125281943638407f, 0.125436627933713f,
+ 0.125591254838533f, 0.125745824343677f, 0.125900336439963f,
+ 0.126054791118225f, 0.126209188369305f, 0.126363528184061f,
+ 0.126517810553362f, 0.126672035468088f, 0.126826202919134f,
+ 0.126980312897405f, 0.127134365393820f, 0.127288360399307f,
+ 0.127442297904811f, 0.127596177901286f, 0.117546189457086f,
+ 0.117699954408416f, 0.117853661823656f, 0.118007311693808f,
+ 0.118160904009891f, 0.118314438762931f, 0.118467915943971f,
+ 0.118621335544062f, 0.118774697554272f, 0.118928001965676f,
+ 0.119081248769366f, 0.119234437956443f, 0.119387569518022f,
+ 0.119540643445230f, 0.119693659729205f, 0.119846618361101f,
+ 0.119999519332079f, 0.120152362633316f, 0.120305148256000f,
+ 0.120457876191332f, 0.120610546430524f, 0.120763158964802f,
+ 0.120915713785403f, 0.121068210883577f, 0.121220650250584f,
+ 0.121373031877701f, 0.121525355756213f, 0.121677621877418f,
+ 0.111626019310016f, 0.111778169890555f, 0.111930262687758f,
+ 0.112082297692972f, 0.112234274897559f, 0.112386194292890f,
+ 0.112538055870350f, 0.112689859621336f, 0.112841605537257f,
+ 0.112993293609536f, 0.113144923829605f, 0.113296496188912f,
+ 0.113448010678914f, 0.113599467291082f, 0.113750866016899f,
+ 0.113902206847861f, 0.114053489775474f, 0.114204714791260f,
+ 0.114355881886749f, 0.114506991053486f, 0.114658042283029f,
+ 0.114809035566945f, 0.114959970896817f, 0.115110848264237f,
+ 0.115261667660812f, 0.115412429078159f, 0.115563132507910f,
+ 0.115713777941706f, 0.105660554448589f, 0.105811083865453f,
+ 0.105961555261365f, 0.106111968628015f, 0.106262323957108f,
+ 0.106412621240361f, 0.106562860469501f, 0.106713041636271f,
+ 0.106863164732422f, 0.107013229749721f, 0.107163236679946f,
+ 0.107313185514885f, 0.107463076246342f, 0.107612908866132f,
+ 0.107762683366080f, 0.107912399738026f, 0.108062057973823f,
+ 0.108211658065332f, 0.108361200004431f, 0.108510683783007f,
+ 0.108660109392962f, 0.108809476826207f, 0.108958786074669f,
+ 0.109108037130284f, 0.109257229985002f, 0.109406364630786f,
+ 0.109555441059609f, 0.109704459263458f, 0.0996496083117188f,
+ 0.0997985100416282f, 0.0999473535225969f, 0.100096138746660f,
+ 0.100244865705867f, 0.100393534392276f, 0.100542144797961f,
+ 0.100690696915006f, 0.100839190735508f, 0.100987626251577f,
+ 0.101136003455335f, 0.101284322338914f, 0.101432582894463f,
+ 0.101580785114137f, 0.101728928990110f, 0.101877014514563f,
+ 0.102025041679692f, 0.102173010477705f, 0.102320920900821f,
+ 0.102468772941273f, 0.102616566591305f, 0.102764301843173f,
+ 0.102911978689148f, 0.103059597121509f, 0.103207157132551f,
+ 0.103354658714579f, 0.103502101859912f, 0.0934456756382679f,
+ 0.0935930018872135f, 0.0937402696764917f, 0.0938874789984700f,
+ 0.0940346298455276f, 0.0941817222100565f, 0.0943287560844607f,
+ 0.0944757314611567f, 0.0946226483325731f, 0.0947695066911507f,
+ 0.0949163065293431f, 0.0950630478396154f, 0.0952097306144455f,
+ 0.0953563548463236f, 0.0955029205277519f, 0.0956494276512452f,
+ 0.0957958762093304f, 0.0959422661945465f, 0.0960885975994451f,
+ 0.0962348704165899f, 0.0963810846385570f, 0.0965272402579347f,
+ 0.0966733372673236f, 0.0968193756593367f, 0.0969653554265990f,
+ 0.0971112765617480f, 0.0972571390574334f, 0.0974029429063172f,
+ 0.0873448771784613f, 0.0874905637117771f, 0.0876361915763511f,
+ 0.0877817607648946f, 0.0879272712701305f, 0.0880727230847950f,
+ 0.0882181162016359f, 0.0883634506134133f, 0.0885087263129001f,
+ 0.0886539432928808f, 0.0887991015461526f, 0.0889442010655249f,
+ 0.0890892418438194f, 0.0892342238738701f, 0.0893791471485232f,
+ 0.0895240116606371f, 0.0896688174030826f, 0.0898135643687430f,
+ 0.0899582525505135f, 0.0901028819413016f, 0.0902474525340274f,
+ 0.0903919643216231f, 0.0905364172970332f, 0.0906808114532143f,
+ 0.0908251467831358f, 0.0909694232797786f, 0.0911136409361365f,
+ 0.0912577997452155f, 0.0811980887774211f, 0.0813421298710088f,
+ 0.0814861120964089f, 0.0816300354466764f, 0.0817738999148785f,
+ 0.0819177054940949f, 0.0820614521774175f, 0.0822051399579502f,
+ 0.0823487688288098f, 0.0824923387831246f, 0.0826358498140358f,
+ 0.0827793019146968f, 0.0829226950782728f, 0.0830660292979419f,
+ 0.0832093045668942f, 0.0833525208783320f, 0.0834956782254701f,
+ 0.0836387766015353f, 0.0837818159997669f, 0.0839247964134165f,
+ 0.0840677178357478f, 0.0842105802600369f, 0.0843533836795723f,
+ 0.0844961280876545f, 0.0846388134775965f, 0.0847814398427233f,
+ 0.0849240071763727f, 0.0850665154718944f, 0.0852089647226503f,
+ 0.0751475439994024f, 0.0752898751407623f, 0.0754321472175162f,
+ 0.0755743602230756f, 0.0757165141508637f, 0.0758586089943163f,
+ 0.0760006447468815f, 0.0761426214020196f, 0.0762845389532032f,
+ 0.0764263973939170f, 0.0765681967176584f, 0.0767099369179366f,
+ 0.0768516179882736f, 0.0769932399222031f, 0.0771348027132715f,
+ 0.0772763063550374f, 0.0774177508410716f, 0.0775591361649572f,
+ 0.0777004623202896f, 0.0778417293006766f, 0.0779829370997380f,
+ 0.0781240857111062f, 0.0782651751284255f, 0.0784062053453531f,
+ 0.0785471763555577f, 0.0786880881527207f, 0.0788289407305362f,
+ 0.0789697340827096f, 0.0791104682029593f, 0.0792511430850161f,
+ 0.0691879478000098f, 0.0693285041869207f, 0.0694690013169037f,
+ 0.0696094391837383f, 0.0697498177812166f, 0.0698901371031425f,
+ 0.0700303971433326f, 0.0701705978956158f, 0.0703107393538329f,
+ 0.0704508215118373f, 0.0705908443634948f, 0.0707308079026829f,
+ 0.0708707121232921f, 0.0710105570192245f, 0.0711503425843951f,
+ 0.0712900688127309f, 0.0714297356981711f, 0.0715693432346672f,
+ 0.0717088914161831f, 0.0718483802366950f, 0.0719878096901912f,
+ 0.0721271797706725f, 0.0722664904721519f, 0.0724057417886545f,
+ 0.0725449337142179f, 0.0726840662428920f, 0.0728231393687387f,
+ 0.0729621530858327f, 0.0731011073882604f, 0.0732400022701208f,
+ 0.0733788377255252f, 0.0735176137485970f, 0.0634525194108596f,
+ 0.0635911765516861f, 0.0637297742426242f, 0.0638683124778465f,
+ 0.0640067912515382f, 0.0641452105578962f, 0.0642835703911301f,
+ 0.0644218707454617f, 0.0645601116151250f, 0.0646982929943664f,
+ 0.0648364148774443f, 0.0649744772586297f, 0.0651124801322058f,
+ 0.0652504234924680f, 0.0653883073337242f, 0.0655261316502941f,
+ 0.0656638964365102f, 0.0658016016867171f, 0.0659392473952715f,
+ 0.0660768335565426f, 0.0662143601649120f, 0.0663518272147731f,
+ 0.0664892347005321f, 0.0666265826166071f, 0.0667638709574289f,
+ 0.0669010997174400f, 0.0670382688910958f, 0.0671753784728635f,
+ 0.0673124284572228f, 0.0674494188386658f, 0.0675863496116965f,
+ 0.0677232207708315f, 0.0678600323105998f, 0.0679967842255422f,
+ 0.0579296655875996f, 0.0580662982365629f, 0.0582028712443972f,
+ 0.0583393846056928f, 0.0584758383150523f, 0.0586122323670904f,
+ 0.0587485667564341f, 0.0588848414777228f, 0.0590210565256080f,
+ 0.0591572118947538f, 0.0592933075798361f, 0.0594293435755436f,
+ 0.0595653198765770f, 0.0597012364776492f, 0.0598370933734855f,
+ 0.0599728905588236f, 0.0601086280284134f, 0.0602443057770169f,
+ 0.0603799237994086f, 0.0605154820903751f, 0.0606509806447155f,
+ 0.0607864194572412f, 0.0609217985227755f, 0.0610571178361543f,
+ 0.0611923773922258f, 0.0613275771858503f, 0.0614627172119006f,
+ 0.0615977974652616f, 0.0617328179408305f, 0.0618677786335169f,
+ 0.0620026795382425f, 0.0621375206499414f, 0.0622723019635602f,
+ 0.0624070234740572f, 0.0625416851764035f, 0.0626762870655824f,
+ 0.0526070182139767f, 0.0527415004618193f, 0.0528759228815178f,
+ 0.0530102854681045f, 0.0531445882166238f, 0.0532788311221330f,
+ 0.0534130141797010f, 0.0535471373844093f, 0.0536812007313518f,
+ 0.0538152042156344f, 0.0539491478323753f, 0.0540830315767053f,
+ 0.0542168554437671f, 0.0543506194287161f, 0.0544843235267195f,
+ 0.0546179677329570f, 0.0547515520426208f, 0.0548850764509150f,
+ 0.0550185409530562f, 0.0551519455442734f, 0.0552852902198074f,
+ 0.0554185749749120f, 0.0555517998048525f, 0.0556849647049072f,
+ 0.0558180696703662f, 0.0559511146965319f, 0.0560840997787193f,
+ 0.0562170249122554f, 0.0563498900924798f, 0.0564826953147438f,
+ 0.0566154405744115f, 0.0567481258668592f, 0.0568807511874753f,
+ 0.0570133165316607f, 0.0571458218948283f, 0.0572782672724036f,
+ 0.0574106526598240f, 0.0575429780525398f, 0.0576752434460127f,
+ 0.0578074488357176f, 0.0579395942171410f, 0.0478678686631696f,
+ 0.0479998940145396f, 0.0481318593441621f, 0.0482637646475730f,
+ 0.0483956099203204f, 0.0485273951579650f, 0.0486591203560793f,
+ 0.0487907855102481f, 0.0489223906160692f, 0.0490539356691518f,
+ 0.0491854206651178f, 0.0493168455996015f, 0.0494482104682491f,
+ 0.0495795152667194f, 0.0497107599906833f, 0.0498419446358243f,
+ 0.0499730691978377f, 0.0501041336724313f, 0.0502351380553253f,
+ 0.0503660823422521f, 0.0504969665289563f, 0.0506277906111949f,
+ 0.0507585545847371f, 0.0508892584453644f, 0.0510199021888707f,
+ 0.0511504858110618f, 0.0512810093077563f, 0.0514114726747848f,
+ 0.0515418759079902f, 0.0516722190032277f, 0.0518025019563648f,
+ 0.0519327247632811f, 0.0520628874198688f, 0.0521929899220323f,
+ 0.0523230322656880f, 0.0524530144467649f, 0.0525829364612041f,
+ 0.0527127983049592f, 0.0528425999739958f, 0.0529723414642920f,
+ 0.0531020227718380f, 0.0532316438926364f, 0.0533612048227022f,
+ 0.0534907055580622f, 0.0536201460947562f, 0.0537495264288357f,
+ 0.0538788465563647f, 0.0540081064734196f, 0.0541373061760887f,
+ 0.0542664456604730f, 0.0441917140000732f, 0.0443207330362394f,
+ 0.0444496918424971f, 0.0445785904149960f, 0.0447074287498985f,
+ 0.0448362068433790f, 0.0449649246916242f, 0.0450935822908335f,
+ 0.0452221796372181f, 0.0453507167270016f, 0.0454791935564199f,
+ 0.0456076101217214f, 0.0457359664191663f, 0.0458642624450276f,
+ 0.0459924981955904f, 0.0461206736671516f, 0.0462487888560214f,
+ 0.0463768437585213f, 0.0465048383709856f, 0.0466327726897607f,
+ 0.0467606467112054f, 0.0468884604316909f, 0.0470162138476001f,
+ 0.0471439069553288f, 0.0472715397512850f, 0.0473991122318885f,
+ 0.0475266243935721f, 0.0476540762327803f, 0.0477814677459702f,
+ 0.0479087989296110f, 0.0480360697801842f, 0.0481632802941839f,
+ 0.0482904304681158f, 0.0484175202984986f, 0.0485445497818628f,
+ 0.0486715189147517f, 0.0487984276937201f, 0.0489252761153358f,
+ 0.0490520641761785f, 0.0491787918728405f, 0.0493054592019259f,
+ 0.0494320661600513f, 0.0495586127438459f, 0.0496850989499509f,
+ 0.0498115247750195f, 0.0499378902157179f, 0.0500641952687237f,
+ 0.0501904399307276f, 0.0503166241984321f, 0.0504427480685521f,
+ 0.0505688115378147f, 0.0506948146029596f, 0.0508207572607382f,
+ 0.0509466395079148f, 0.0510724613412656f, 0.0511982227575792f,
+ 0.0513239237536566f, 0.0514495643263109f, 0.0515751444723674f,
+ 0.0517006641886638f, 0.0518261234720504f, 0.0519515223193892f,
+ 0.0520768607275548f, 0.0522021386934342f, 0.0523273562139263f,
+ 0.0524525132859427f, 0.0525776099064070f, 0.0527026460722553f,
+ 0.0426238108578230f, 0.0427487261052961f, 0.0428735808890346f,
+ 0.0429983752060237f, 0.0431231090532607f, 0.0432477824277554f,
+ 0.0433723953265295f, 0.0434969477466176f, 0.0436214396850659f,
+ 0.0437458711389333f, 0.0438702421052907f, 0.0439945525812217f,
+ 0.0441188025638218f, 0.0442429920501990f, 0.0443671210374733f,
+ 0.0444911895227774f, 0.0446151975032558f, 0.0447391449760657f,
+ 0.0448630319383766f, 0.0449868583873697f, 0.0451106243202392f,
+ 0.0452343297341911f, 0.0453579746264439f, 0.0454815589942283f,
+ 0.0456050828347873f, 0.0457285461453763f, 0.0458519489232627f,
+ 0.0459752911657265f, 0.0460985728700598f, 0.0462217940335669f,
+ 0.0463449546535647f, 0.0464680547273820f, 0.0465910942523600f,
+ 0.0467140732258525f, 0.0468369916452251f, 0.0469598495078560f,
+ 0.0470826468111357f, 0.0472053835524666f, 0.0473280597292639f,
+ 0.0474506753389546f, 0.0475732303789784f, 0.0476957248467870f,
+ 0.0478181587398445f, 0.0479405320556273f, 0.0480628447916239f,
+ 0.0481850969453354f, 0.0483072885142748f, 0.0484294194959678f,
+ 0.0485514898879519f, 0.0486734996877775f, 0.0487954488930066f,
+ 0.0489173375012139f, 0.0490391655099864f, 0.0491609329169232f,
+ 0.0492826397196357f, 0.0494042859157477f, 0.0495258715028952f,
+ 0.0496473964787265f, 0.0497688608409022f, 0.0498902645870951f,
+ 0.0500116077149904f, 0.0501328902222853f, 0.0502541121066900f,
+ 0.0503752733659261f, 0.0504963739977278f, 0.0506174139998419f,
+ 0.0507383933700272f, 0.0508593121060547f, 0.0509801702057078f,
+ 0.0511009676667822f, 0.0512217044870858f, 0.0513423806644390f,
+ 0.0514629961966743f, 0.0515835510816363f, 0.0517040453171823f,
+ 0.0518244789011815f, 0.0519448518315156f, 0.0520651641060786f,
+ 0.0521854157227766f, 0.0523056066795282f, 0.0524257369742641f,
+ 0.0525458066049274f, 0.0526658155694733f, 0.0527857638658696f,
+ 0.0529056514920961f, 0.0530254784461450f, 0.0531452447260207f,
+ 0.0532649503297400f, 0.0533845952553320f, 0.0535041795008378f,
+ 0.0536237030643112f, 0.0537431659438180f, 0.0538625681374362f,
+ 0.0539819096432564f, 0.0541011904593813f, 0.0542204105839259f,
+ 0.0543395700150173f, 0.0544586687507953f, 0.0545777067894117f,
+ 0.0546966841290304f, 0.0548156007678281f, 0.0549344567039931f,
+ 0.0550532519357268f, 0.0551719864612422f, 0.0552906602787649f,
+ 0.0554092733865326f, 0.0555278257827956f, 0.0556463174658160f,
+ 0.0557647484338686f, 0.0558831186852405f, 0.0560014282182306f,
+ 0.0561196770311506f, 0.0562378651223242f, 0.0563559924900874f,
+ 0.0564740591327887f, 0.0565920650487887f, 0.0567100102364602f,
+ 0.0568278946941885f, 0.0569457184203710f, 0.0570634814134173f,
+ 0.0571811836717497f, 0.0572988251938025f, 0.0574164059780221f,
+ 0.0575339260228674f, 0.0576513853268097f, 0.0577687838883325f,
+ 0.0578861217059312f, 0.0580033987781141f, 0.0581206151034013f,
+ 0.0582377706803254f, 0.0583548655074314f, 0.0584718995832763f,
+ 0.0585888729064294f, 0.0587057854754726f, 0.0588226372889998f,
+ 0.0589394283456172f, 0.0590561586439433f, 0.0591728281826091f,
+ 0.0592894369602576f, 0.0594059849755440f, 0.0595224722271363f,
+ 0.0596388987137142f, 0.0597552644339699f, 0.0598715693866082f,
+ 0.0599878135703456f, 0.0601039969839111f, 0.0602201196260463f,
+ 0.0603361814955049f, 0.0604521825910525f, 0.0605681229114674f,
+ 0.0606840024555402f, 0.0607998212220735f, 0.0609155792098825f,
+ 0.0610312764177944f, 0.0611469128446488f, 0.0612624884892977f,
+ 0.0613780033506051f, 0.0614934574274476f, 0.0616088507187138f,
+ 0.0617241832233048f, 0.0618394549401339f, 0.0619546658681265f,
+ 0.0620698160062207f, 0.0621849053533666f, 0.0622999339085263f,
+ 0.0624149016706749f, 0.0625298086387993f, 0.0626446548118985f,
+ 0.0627594401889842f, 0.0628741647690804f, 0.0629888285512230f,
+ 0.0631034315344604f, 0.0632179737178534f, 0.0633324551004748f,
+ 0.0634468756814098f, 0.0635612354597560f, 0.0636755344346234f,
+ 0.0637897726051337f, 0.0639039499704215f, 0.0640180665296333f,
+ 0.0641321222819281f, 0.0642461172264772f, 0.0643600513624639f,
+ 0.0644739246890841f, 0.0645877372055457f, 0.0647014889110692f,
+ 0.0648151798048871f, 0.0649288098862443f, 0.0650423791543980f,
+ 0.0651558876086177f, 0.0652693352481850f, 0.0653827220723941f,
+ 0.0654960480805510f, 0.0656093132719747f, 0.0657225176459958f,
+ 0.0658356612019574f, 0.0659487439392150f, 0.0660617658571363f,
+ 0.0661747269551014f, 0.0662876272325024f, 0.0664004666887441f,
+ 0.0665132453232429f, 0.0666259631354284f, 0.0667386201247416f,
+ 0.0668512162906364f, 0.0669637516325786f, 0.0670762261500467f,
+ 0.0671886398425310f, 0.0673009927095344f, 0.0674132847505718f,
+ 0.0675255159651708f, 0.0676376863528710f, 0.0677497959132243f,
+ 0.0678618446457948f, 0.0679738325501591f, 0.0680857596259061f,
+ 0.0681976258726366f, 0.0683094312899641f, 0.0684211758775141f,
+ 0.0685328596349247f, 0.0686444825618459f, 0.0687560446579401f,
+ 0.0688675459228822f, 0.0689789863563593f, 0.0690903659580705f,
+ 0.0692016847277276f, 0.0693129426650541f, 0.0694241397697866f,
+ 0.0695352760416732f, 0.0594425405578624f, 0.0595535551633519f,
+ 0.0596645089353147f, 0.0597754018735483f, 0.0598862339778625f,
+ 0.0599970052480793f, 0.0601077156840334f, 0.0602183652855713f,
+ 0.0603289540525519f, 0.0604394819848466f, 0.0605499490823388f,
+ 0.0606603553449245f, 0.0607707007725117f, 0.0608809853650206f,
+ 0.0609912091223840f, 0.0611013720445469f, 0.0612114741314665f,
+ 0.0613215153831122f, 0.0614314957994659f, 0.0615414153805216f,
+ 0.0616512741262855f, 0.0617610720367764f, 0.0618708091120252f,
+ 0.0619804853520752f, 0.0620901007569816f, 0.0621996553268123f,
+ 0.0623091490616473f, 0.0624185819615789f, 0.0625279540267118f,
+ 0.0626372652571628f, 0.0627465156530610f, 0.0628557052145480f,
+ 0.0629648339417774f, 0.0630739018349152f, 0.0631829088941397f,
+ 0.0632918551196415f, 0.0634007405116234f, 0.0635095650703006f,
+ 0.0636183287959005f, 0.0637270316886627f, 0.0638356737488393f,
+ 0.0639442549766944f, 0.0640527753725047f, 0.0641612349365589f,
+ 0.0642696336691582f, 0.0643779715706160f, 0.0644862486412577f,
+ 0.0645944648814216f, 0.0647026202914576f, 0.0648107148717285f,
+ 0.0649187486226089f, 0.0650267215444860f, 0.0651346336377590f,
+ 0.0652424849028396f, 0.0653502753401518f, 0.0654580049501316f,
+ 0.0655656737332277f, 0.0656732816899009f, 0.0657808288206239f,
+ 0.0658883151258823f, 0.0659957406061736f, 0.0661031052620077f,
+ 0.0662104090939068f, 0.0663176521024054f, 0.0664248342880501f,
+ 0.0665319556513999f, 0.0666390161930263f, 0.0667460159135127f,
+ 0.0668529548134549f, 0.0669598328934612f, 0.0670666501541520f,
+ 0.0671734065961599f, 0.0672801022201299f, 0.0673867370267193f,
+ 0.0674933110165977f, 0.0675998241904468f, 0.0677062765489609f,
+ 0.0678126680928461f, 0.0679189988228213f, 0.0680252687396174f,
+ 0.0681314778439776f, 0.0682376261366575f, 0.0683437136184247f,
+ 0.0684497402900595f, 0.0685557061523543f, 0.0686616112061134f,
+ 0.0687674554521540f, 0.0688732388913053f, 0.0689789615244086f,
+ 0.0690846233523179f, 0.0691902243758991f, 0.0692957645960306f,
+ 0.0694012440136030f, 0.0695066626295191f, 0.0696120204446942f,
+ 0.0697173174600557f, 0.0698225536765433f, 0.0699277290951092f,
+ 0.0700328437167174f, 0.0701378975423447f, 0.0702428905729799f,
+ 0.0703478228096242f, 0.0704526942532909f, 0.0705575049050059f,
+ 0.0706622547658070f, 0.0707669438367446f, 0.0708715721188812f,
+ 0.0607723286906791f, 0.0608768353984505f, 0.0609812813206822f,
+ 0.0610856664584861f, 0.0611899908129857f, 0.0612942543853178f,
+ 0.0613984571766304f, 0.0615025991880848f, 0.0616066804208537f,
+ 0.0617107008761226f, 0.0618146605550893f, 0.0619185594589635f,
+ 0.0620223975889676f, 0.0621261749463358f, 0.0622298915323152f,
+ 0.0623335473481647f, 0.0624371423951557f, 0.0625406766745718f,
+ 0.0626441501877088f, 0.0627475629358750f, 0.0628509149203909f,
+ 0.0629542061425891f, 0.0630574366038147f, 0.0631606063054251f,
+ 0.0632637152487898f, 0.0633667634352907f, 0.0634697508663218f,
+ 0.0635726775432898f, 0.0636755434676132f, 0.0637783486407231f,
+ 0.0638810930640628f, 0.0639837767390877f, 0.0640863996672659f,
+ 0.0641889618500774f, 0.0642914632890144f, 0.0643939039855820f,
+ 0.0644962839412969f, 0.0645986031576883f, 0.0647008616362979f,
+ 0.0648030593786793f, 0.0649051963863989f, 0.0650072726610348f,
+ 0.0651092882041778f, 0.0652112430174308f, 0.0653131371024089f,
+ 0.0654149704607399f, 0.0655167430940633f, 0.0656184550040314f,
+ 0.0657201061923084f, 0.0658216966605708f, 0.0659232264105077f,
+ 0.0660246954438204f, 0.0661261037622221f, 0.0662274513674386f,
+ 0.0663287382612081f, 0.0664299644452808f, 0.0665311299214192f,
+ 0.0666322346913985f, 0.0667332787570056f, 0.0668342621200399f,
+ 0.0669351847823132f, 0.0670360467456497f, 0.0671368480118855f,
+ 0.0672375885828691f, 0.0673382684604614f, 0.0674388876465356f,
+ 0.0675394461429772f, 0.0676399439516836f, 0.0677403810745650f,
+ 0.0678407575135437f, 0.0679410732705540f, 0.0680413283475430f,
+ 0.0681415227464696f, 0.0682416564693053f, 0.0683417295180337f,
+ 0.0582379309720382f, 0.0583378826785522f, 0.0584377737169835f,
+ 0.0585376040893650f, 0.0586373737977419f, 0.0587370828441713f,
+ 0.0588367312307229f, 0.0589363189594787f, 0.0590358460325329f,
+ 0.0591353124519920f, 0.0592347182199747f, 0.0593340633386119f,
+ 0.0594333478100472f, 0.0595325716364361f, 0.0596317348199464f,
+ 0.0597308373627584f, 0.0598298792670645f, 0.0599288605350693f,
+ 0.0600277811689900f, 0.0601266411710558f, 0.0602254405435084f,
+ 0.0603241792886015f, 0.0604228574086014f, 0.0605214749057863f,
+ 0.0606200317824470f, 0.0607185280408865f, 0.0608169636834202f,
+ 0.0609153387123754f, 0.0610136531300921f, 0.0611119069389223f,
+ 0.0612101001412306f, 0.0613082327393934f, 0.0614063047357998f,
+ 0.0615043161328510f, 0.0616022669329606f, 0.0617001571385542f,
+ 0.0617979867520701f, 0.0618957557759585f, 0.0619934642126822f,
+ 0.0620911120647159f, 0.0621886993345471f, 0.0622862260246751f,
+ 0.0623836921376117f, 0.0624810976758809f, 0.0625784426420190f,
+ 0.0626757270385749f, 0.0627729508681091f, 0.0628701141331951f,
+ 0.0629672168364182f, 0.0630642589803762f, 0.0631612405676790f,
+ 0.0632581616009490f, 0.0633550220828208f, 0.0634518220159413f,
+ 0.0635485614029694f, 0.0636452402465769f, 0.0637418585494472f,
+ 0.0638384163142765f, 0.0639349135437730f, 0.0640313502406572f,
+ 0.0641277264076620f, 0.0642240420475324f, 0.0643202971630261f,
+ 0.0644164917569124f, 0.0645126258319735f, 0.0544048884683912f,
+ 0.0545009015141968f, 0.0545968540495967f, 0.0546927460774221f,
+ 0.0547885776005161f, 0.0548843486217346f, 0.0549800591439455f,
+ 0.0550757091700289f, 0.0551712987028775f, 0.0552668277453958f,
+ 0.0553622963005011f, 0.0554577043711226f, 0.0555530519602019f,
+ 0.0556483390706931f, 0.0557435657055621f, 0.0558387318677877f,
+ 0.0559338375603603f, 0.0560288827862831f, 0.0561238675485714f,
+ 0.0562187918502528f, 0.0563136556943673f, 0.0564084590839668f,
+ 0.0565032020221159f, 0.0565978845118913f, 0.0566925065563819f,
+ 0.0567870681586891f, 0.0568815693219265f, 0.0569760100492198f,
+ 0.0570703903437071f, 0.0571647102085391f, 0.0572589696468781f,
+ 0.0573531686618994f, 0.0574473072567899f, 0.0575413854347496f,
+ 0.0576354031989899f, 0.0577293605527351f, 0.0578232574992215f,
+ 0.0579170940416977f, 0.0580108701834249f, 0.0581045859276761f,
+ 0.0581982412777368f, 0.0582918362369048f, 0.0583853708084903f,
+ 0.0584788449958155f, 0.0585722588022151f, 0.0586656122310360f,
+ 0.0587589052856374f, 0.0588521379693908f, 0.0589453102856798f,
+ 0.0590384222379006f, 0.0591314738294614f, 0.0592244650637830f,
+ 0.0593173959442981f, 0.0594102664744519f, 0.0595030766577018f,
+ 0.0595958264975176f, 0.0596885159973813f, 0.0597811451607873f,
+ 0.0598737139912419f, 0.0599662224922641f, 0.0498548597447726f,
+ 0.0499472475975357f, 0.0500395751314966f, 0.0501318423502235f,
+ 0.0502240492572963f, 0.0503161958563079f, 0.0504082821508629f,
+ 0.0505003081445783f, 0.0505922738410838f, 0.0506841792440209f,
+ 0.0507760243570434f, 0.0508678091838178f, 0.0509595337280224f,
+ 0.0510511979933482f, 0.0511428019834981f, 0.0512343457021875f,
+ 0.0513258291531440f, 0.0514172523401077f, 0.0515086152668306f,
+ 0.0515999179370773f, 0.0516911603546245f, 0.0517823425232611f,
+ 0.0518734644467888f, 0.0519645261290209f, 0.0520555275737834f,
+ 0.0521464687849144f, 0.0522373497662645f, 0.0523281705216963f,
+ 0.0524189310550848f, 0.0525096313703174f, 0.0526002714712936f,
+ 0.0526908513619254f, 0.0527813710461367f, 0.0528718305278641f,
+ 0.0529622298110562f, 0.0530525688996742f, 0.0531428477976911f,
+ 0.0532330665090925f, 0.0533232250378763f, 0.0534133233880527f,
+ 0.0535033615636440f, 0.0535933395686848f, 0.0536832574072221f,
+ 0.0537731150833152f, 0.0538629126010356f, 0.0539526499644671f,
+ 0.0540423271777057f, 0.0541319442448598f, 0.0542215011700501f,
+ 0.0543109979574096f, 0.0544004346110833f, 0.0544898111352288f,
+ 0.0545791275340160f, 0.0546683838116266f, 0.0547575799722552f,
+ 0.0548467160201085f, 0.0549357919594052f, 0.0448209968717641f,
+ 0.0449099526066536f, 0.0449988482457168f, 0.0450876837932221f,
+ 0.0451764592534494f, 0.0452651746306915f, 0.0453538299292532f,
+ 0.0454424251534517f, 0.0455309603076164f, 0.0456194353960890f,
+ 0.0457078504232236f, 0.0457962053933864f, 0.0458845003109558f,
+ 0.0459727351803229f, 0.0460609100058907f, 0.0461490247920745f,
+ 0.0462370795433022f, 0.0463250742640136f, 0.0464130089586610f,
+ 0.0465008836317089f, 0.0465886982876342f, 0.0466764529309258f,
+ 0.0467641475660853f, 0.0468517821976262f, 0.0469393568300745f,
+ 0.0470268714679684f, 0.0471143261158584f, 0.0472017207783073f,
+ 0.0472890554598900f, 0.0473763301651941f, 0.0474635448988190f,
+ 0.0475506996653768f, 0.0476377944694915f, 0.0477248293157998f,
+ 0.0478118042089502f, 0.0478987191536039f, 0.0479855741544340f,
+ 0.0480723692161264f, 0.0481591043433788f, 0.0482457795409013f,
+ 0.0483323948134164f, 0.0484189501656588f, 0.0485054456023757f,
+ 0.0485918811283262f, 0.0486782567482818f, 0.0487645724670264f,
+ 0.0488508282893562f, 0.0489370242200796f, 0.0490231602640172f,
+ 0.0491092364260021f, 0.0491952527108794f, 0.0492812091235068f,
+ 0.0493671056687539f, 0.0494529423515031f, 0.0495387191766484f,
+ 0.0496244361490969f, 0.0395062823511546f, 0.0395918796329782f,
+ 0.0396774170768982f, 0.0397628946878707f, 0.0398483124708638f,
+ 0.0399336704308575f, 0.0400189685728449f, 0.0401042069018306f,
+ 0.0401893854228319f, 0.0402745041408782f, 0.0403595630610115f,
+ 0.0404445621882854f, 0.0405295015277667f, 0.0406143810845336f,
+ 0.0406992008636773f, 0.0407839608703008f, 0.0408686611095195f,
+ 0.0409533015864613f, 0.0410378823062660f, 0.0411224032740861f,
+ 0.0412068644950861f, 0.0412912659744427f, 0.0413756077173453f,
+ 0.0414598897289950f, 0.0415441120146058f, 0.0416282745794035f,
+ 0.0417123774286264f, 0.0417964205675252f, 0.0418804040013625f,
+ 0.0419643277354134f, 0.0420481917749655f, 0.0421319961253183f,
+ 0.0422157407917838f, 0.0422994257796863f, 0.0423830510943621f,
+ 0.0424666167411601f, 0.0425501227254416f, 0.0426335690525796f,
+ 0.0427169557279601f, 0.0428002827569807f, 0.0428835501450517f,
+ 0.0429667578975957f, 0.0430499060200474f, 0.0431329945178538f,
+ 0.0432160233964742f, 0.0432989926613803f, 0.0433819023180559f,
+ 0.0434647523719972f, 0.0435475428287129f, 0.0436302736937234f,
+ 0.0437129449725618f, 0.0437955566707733f, 0.0438781087939159f,
+ 0.0439606013475590f, 0.0440430343372850f, 0.0441254077686882f,
+ 0.0442077216473753f, 0.0340861650563528f, 0.0341683598464772f,
+ 0.0342504951007791f, 0.0343325708249148f, 0.0344145870245521f,
+ 0.0344965437053716f, 0.0345784408730658f, 0.0346602785333397f,
+ 0.0347420566919107f, 0.0348237753545080f, 0.0349054345268737f,
+ 0.0349870342147618f, 0.0350685744239386f, 0.0351500551601828f,
+ 0.0352314764292854f, 0.0353128382370495f, 0.0353941405892905f,
+ 0.0354753834918364f, 0.0355565669505271f, 0.0356376909712150f,
+ 0.0357187555597648f, 0.0357997607220532f, 0.0358807064639694f,
+ 0.0359615927914151f, 0.0360424197103039f, 0.0361231872265616f,
+ 0.0362038953461269f, 0.0362845440749502f, 0.0363651334189943f,
+ 0.0364456633842345f, 0.0365261339766582f, 0.0366065452022649f,
+ 0.0366868970670670f, 0.0367671895770884f, 0.0368474227383658f,
+ 0.0369275965569481f, 0.0370077110388962f, 0.0370877661902839f,
+ 0.0371677620171965f, 0.0372476985257322f, 0.0373275757220012f,
+ 0.0374073936121259f, 0.0374871522022413f, 0.0375668514984943f,
+ 0.0376464915070444f, 0.0377260722340632f, 0.0378055936857347f,
+ 0.0378850558682551f, 0.0379644587878328f, 0.0380438024506888f,
+ 0.0381230868630559f, 0.0382023120311796f, 0.0382814779613175f,
+ 0.0383605846597395f, 0.0384396321327278f, 0.0385186203865768f,
+ 0.0385975494275934f, 0.0386764192620965f, 0.0387552298964174f,
+ 0.0388339813368998f, 0.0389126735898995f, 0.0287874957391723f,
+ 0.0288660696363234f, 0.0289445843651332f, 0.0290230399320067f,
+ 0.0291014363433610f, 0.0291797736056260f, 0.0292580517252432f,
+ 0.0293362707086670f, 0.0294144305623635f, 0.0294925312928117f,
+ 0.0295705729065025f, 0.0296485554099390f, 0.0297264788096369f,
+ 0.0298043431121241f, 0.0298821483239404f, 0.0299598944516384f,
+ 0.0300375815017827f, 0.0301152094809503f, 0.0301927783957304f,
+ 0.0302702882527243f, 0.0303477390585462f, 0.0304251308198219f,
+ 0.0305024635431897f, 0.0305797372353004f, 0.0306569519028170f,
+ 0.0307341075524143f, 0.0308112041907801f, 0.0308882418246141f,
+ 0.0309652204606283f, 0.0310421401055471f, 0.0311190007661070f,
+ 0.0311958024490569f, 0.0312725451611581f, 0.0313492289091839f,
+ 0.0314258536999200f, 0.0315024195401646f, 0.0315789264367278f,
+ 0.0316553743964323f, 0.0317317634261129f, 0.0318080935326168f,
+ 0.0318843647228033f, 0.0319605770035441f, 0.0320367303817234f,
+ 0.0321128248642373f, 0.0321888604579942f, 0.0322648371699152f,
+ 0.0323407550069333f, 0.0324166139759939f, 0.0324924140840545f,
+ 0.0325681553380854f, 0.0326438377450685f, 0.0327194613119984f,
+ 0.0327950260458821f, 0.0328705319537385f, 0.0329459790425989f,
+ 0.0330213673195070f, 0.0330966967915189f, 0.0331719674657026f,
+ 0.0332471793491386f, 0.0333223324489197f, 0.0333974267721510f,
+ 0.0334724623259497f, 0.0335474391174456f, 0.0336223571537804f,
+ 0.0336972164421084f, 0.0337720169895960f, 0.0338467588034219f,
+ 0.0237176309681649f, 0.0237922553362531f, 0.0238668209922893f,
+ 0.0239413279435017f, 0.0240157761971304f, 0.0240901657604278f,
+ 0.0241644966406585f, 0.0242387688450997f, 0.0243129823810404f,
+ 0.0243871372557825f, 0.0244612334766396f, 0.0245352710509378f,
+ 0.0246092499860156f, 0.0246831702892237f, 0.0247570319679249f,
+ 0.0248308350294947f, 0.0249045794813202f, 0.0249782653308016f,
+ 0.0250518925853510f, 0.0251254612523924f, 0.0251989713393627f,
+ 0.0252724228537110f, 0.0253458158028981f, 0.0254191501943977f,
+ 0.0254924260356957f, 0.0255656433342901f, 0.0256388020976910f,
+ 0.0257119023334213f, 0.0257849440490158f, 0.0258579272520216f,
+ 0.0259308519499983f, 0.0260037181505175f, 0.0260765258611635f,
+ 0.0261492750895322f, 0.0262219658432325f, 0.0262945981298852f,
+ 0.0263671719571235f, 0.0264396873325928f, 0.0265121442639506f,
+ 0.0265845427588672f, 0.0266568828250247f, 0.0267291644701179f,
+ 0.0268013877018532f, 0.0268735525279502f, 0.0269456589561400f,
+ 0.0270177069941663f, 0.0270896966497854f, 0.0271616279307651f,
+ 0.0272335008448862f, 0.0273053153999414f, 0.0273770716037359f,
+ 0.0274487694640868f, 0.0275204089888242f, 0.0275919901857897f,
+ 0.0276635130628376f, 0.0277349776278345f, 0.0278063838886591f,
+ 0.0278777318532024f, 0.0279490215293680f, 0.0280202529250712f,
+ 0.0280914260482401f, 0.0281625409068147f, 0.0282335975087478f,
+ 0.0283045958620039f, 0.0283755359745601f, 0.0284464178544057f,
+ 0.0285172415095424f, 0.0285880069479839f, 0.0286587141777566f,
+ 0.0287293632068986f, 0.0287999540434609f, 0.0288704866955066f,
+ 0.0289409611711107f, 0.0290113774783608f, 0.0290817356253569f,
+ 0.0291520356202110f, 0.0292222774710476f, 0.0292924611860035f,
+ 0.0293625867732274f, 0.0294326542408808f, 0.0295026635971371f,
+ 0.0295726148501822f, 0.0194386970856016f, 0.0195085321568307f,
+ 0.0195783091494799f, 0.0196480280717839f, 0.0197176889319899f,
+ 0.0197872917383575f, 0.0198568364991585f, 0.0199263232226770f,
+ 0.0199957519172094f, 0.0200651225910641f, 0.0201344352525623f,
+ 0.0202036899100369f, 0.0202728865718336f, 0.0203420252463102f,
+ 0.0204111059418366f, 0.0204801286667952f, 0.0205490934295804f,
+ 0.0206180002385994f, 0.0206868491022712f, 0.0207556400290274f,
+ 0.0208243730273115f, 0.0208930481055796f, 0.0209616652723001f,
+ 0.0210302245359534f, 0.0210987259050326f, 0.0211671693880426f,
+ 0.0212355549935009f, 0.0213038827299372f, 0.0213721526058936f,
+ 0.0214403646299242f, 0.0215085188105956f, 0.0215766151564867f,
+ 0.0216446536761885f, 0.0217126343783045f, 0.0217805572714503f,
+ 0.0218484223642538f, 0.0219162296653552f, 0.0219839791834073f,
+ 0.0220516709270747f, 0.0221193049050345f, 0.0221868811259760f,
+ 0.0222543995986009f, 0.0223218603316232f, 0.0223892633337690f,
+ 0.0224566086137768f, 0.0225238961803974f, 0.0225911260423939f,
+ 0.0226582982085414f, 0.0227254126876278f, 0.0227924694884529f,
+ 0.0228594686198288f, 0.0229264100905801f, 0.0229932939095435f,
+ 0.0230601200855678f, 0.0231268886275146f, 0.0231935995442573f,
+ 0.0232602528446819f, 0.0233268485376864f, 0.0233933866321813f,
+ 0.0234598671370893f, 0.0235262900613454f, 0.0235926554138970f,
+ 0.0236589632037034f, 0.0237252134397367f, 0.0237914061309807f,
+ 0.0238575412864321f, 0.0239236189150995f, 0.0239896390260038f,
+ 0.0240556016281782f, 0.0241215067306683f, 0.0241873543425319f,
+ 0.0242531444728392f, 0.0243188771306724f, 0.0243845523251262f,
+ 0.0244501700653075f, 0.0245157303603356f, 0.0245812332193420f,
+ 0.0246466786514703f, 0.0247120666658767f, 0.0247773972717296f,
+ 0.0248426704782095f, 0.0249078862945094f, 0.0249730447298344f,
+ 0.0250381457934021f, 0.0251031894944420f, 0.0251681758421963f,
+ 0.0252331048459193f, 0.0252979765148776f, 0.0253627908583501f,
+ 0.0254275478856277f, 0.0254922476060143f, 0.0255568900288252f,
+ 0.0256214751633887f, 0.0256860030190448f, 0.0257504736051463f,
+ 0.0258148869310579f, 0.0258792430061567f, 0.0259435418398322f,
+ 0.0260077834414862f, 0.0260719678205325f, 0.0261360949863972f,
+ 0.0262001649485192f, 0.0262641777163491f, 0.0263281332993501f,
+ 0.0263920317069973f, 0.0264558729487787f, 0.0265196570341941f,
+ 0.0265833839727558f, 0.0266470537739881f, 0.0267106664474281f,
+ 0.0267742220026244f, 0.0268377204491388f, 0.0269011617965448f,
+ 0.0269645460544282f, 0.0270278732323873f, 0.0270911433400325f,
+ 0.0271543563869866f, 0.0272175123828847f, 0.0272806113373739f,
+ 0.0273436532601140f, 0.0274066381607769f, 0.0274695660490466f,
+ 0.0275324369346197f, 0.0275952508272048f, 0.0276580077365231f,
+ 0.0277207076723076f, 0.0277833506443041f, 0.0278459366622703f,
+ 0.0279084657359765f, 0.0279709378752049f, 0.0280333530897504f,
+ 0.0280957113894200f, 0.0281580127840327f, 0.0282202572834203f,
+ 0.0180786339748140f, 0.0181407647132949f, 0.0182028385861189f,
+ 0.0182648556031667f, 0.0183268157743312f, 0.0183887191095176f,
+ 0.0184505656186436f, 0.0185123553116388f, 0.0185740881984453f,
+ 0.0186357642890174f, 0.0186973835933219f, 0.0187589461213378f,
+ 0.0188204518830560f, 0.0188819008884801f, 0.0189432931476259f,
+ 0.0190046286705214f, 0.0190659074672070f, 0.0191271295477353f,
+ 0.0191882949221711f, 0.0192494036005917f, 0.0193104555930864f,
+ 0.0193714509097570f, 0.0194323895607176f, 0.0194932715560944f,
+ 0.0195540969060260f, 0.0196148656206632f, 0.0196755777101692f,
+ 0.0197362331847194f, 0.0197968320545017f, 0.0198573743297157f,
+ 0.0199178600205741f, 0.0199782891373010f, 0.0200386616901335f,
+ 0.0200989776893208f, 0.0201592371451241f, 0.0202194400678171f,
+ 0.0202795864676859f, 0.0203396763550284f, 0.0203997097401555f,
+ 0.0204596866333899f, 0.0205196070450666f, 0.0205794709855330f,
+ 0.0206392784651486f, 0.0206990294942856f, 0.0207587240833281f,
+ 0.0208183622426724f, 0.0208779439827276f, 0.0209374693139144f,
+ 0.0209969382466666f, 0.0210563507914293f, 0.0211157069586608f,
+ 0.0211750067588309f, 0.0212342502024225f, 0.0212934372999299f,
+ 0.0213525680618605f, 0.0214116424987335f, 0.0214706606210802f,
+ 0.0215296224394448f, 0.0215885279643833f, 0.0216473772064642f,
+ 0.0217061701762682f, 0.0217649068843883f, 0.0218235873414297f,
+ 0.0218822115580100f, 0.0219407795447591f, 0.0219992913123190f,
+ 0.0220577468713443f, 0.0221161462325014f, 0.0221744894064695f,
+ 0.0222327764039397f, 0.0222910072356156f, 0.0223491819122130f,
+ 0.0224073004444599f, 0.0224653628430968f, 0.0225233691188765f,
+ 0.0225813192825635f, 0.0226392133449354f, 0.0226970513167814f,
+ 0.0227548332089035f, 0.0228125590321158f, 0.0228702287972445f,
+ 0.0229278425151282f, 0.0229854001966177f, 0.0230429018525766f,
+ 0.0231003474938801f, 0.0231577371314159f, 0.0232150707760841f,
+ 0.0232723484387969f, 0.0233295701304792f, 0.0233867358620675f,
+ 0.0234438456445113f, 0.0235008994887718f, 0.0235578974058227f,
+ 0.0236148394066502f, 0.0236717255022525f, 0.0237285557036400f,
+ 0.0237853300218359f, 0.0238420484678749f, 0.0238987110528048f,
+ 0.0239553177876850f, 0.0240118686835876f, 0.0240683637515969f,
+ 0.0241248030028093f, 0.0241811864483337f, 0.0242375140992912f,
+ 0.0242937859668152f, 0.0243500020620512f, 0.0244061623961573f,
+ 0.0244622669803039f, 0.0245183158256730f, 0.0245743089434599f,
+ 0.0246302463448713f, 0.0246861280411268f, 0.0247419540434580f,
+ 0.0247977243631086f, 0.0248534390113350f, 0.0249090979994056f,
+ 0.0249647013386012f, 0.0250202490402147f, 0.0250757411155516f,
+ 0.0251311775759295f, 0.0251865584326782f, 0.0252418836971398f,
+ 0.0252971533806688f, 0.0253523674946320f, 0.0254075260504084f,
+ 0.0254626290593893f, 0.0255176765329782f, 0.0255726684825909f,
+ 0.0256276049196556f, 0.0256824858556128f, 0.0257373113019150f,
+ 0.0257920812700275f, 0.0258467957714273f, 0.0259014548176039f,
+ 0.0259560584200594f, 0.0260106065903076f, 0.0260650993398752f,
+ 0.0261195366803005f, 0.0261739186231348f, 0.0262282451799411f,
+ 0.0262825163622949f, 0.0263367321817843f, 0.0263908926500090f,
+ 0.0264449977785816f, 0.0264990475791265f, 0.0265530420632809f,
+ 0.0266069812426939f, 0.0266608651290270f, 0.0267146937339538f,
+ 0.0267684670691607f, 0.0268221851463456f, 0.0268758479772194f,
+ 0.0269294555735048f, 0.0269830079469371f, 0.0270365051092639f,
+ 0.0270899470722445f, 0.0271433338476514f, 0.0271966654472685f,
+ 0.0272499418828926f, 0.0273031631663327f, 0.0273563293094096f,
+ 0.0274094403239570f, 0.0274624962218204f, 0.0275154970148579f,
+ 0.0275684427149397f, 0.0276213333339486f, 0.0276741688837791f,
+ 0.0277269493763384f, 0.0277796748235459f, 0.0278323452373335f,
+ 0.0278849606296448f, 0.0279375210124363f, 0.0279900263976765f,
+ 0.0280424767973460f, 0.0280948722234382f, 0.0281472126879581f,
+ 0.0281994982029236f, 0.0282517287803646f, 0.0283039044323233f,
+ 0.0283560251708540f, 0.0284080910080237f, 0.0284601019559115f,
+ 0.0285120580266086f, 0.0285639592322186f, 0.0286158055848575f,
+ 0.0286675970966534f, 0.0287193337797467f, 0.0287710156462904f,
+ 0.0288226427084491f, 0.0288742149784006f, 0.0289257324683340f,
+ 0.0289771951904517f, 0.0290286031569674f, 0.0290799563801078f,
+ 0.0291312548721115f, 0.0291824986452294f, 0.0292336877117249f,
+ 0.0292848220838736f, 0.0293359017739633f, 0.0293869267942941f,
+ 0.0294378971571783f, 0.0294888128749408f, 0.0295396739599185f,
+ 0.0295904804244605f, 0.0296412322809285f, 0.0296919295416962f,
+ 0.0297425722191498f, 0.0297931603256875f, 0.0298436938737202f,
+ 0.0298941728756706f, 0.0299445973439740f, 0.0299949672910779f,
+ 0.0300452827294422f, 0.0300955436715389f, 0.0301457501298522f,
+ 0.0301959021168788f, 0.0302459996451278f, 0.0302960427271200f,
+ 0.0303460313753892f, 0.0303959656024811f, 0.0304458454209537f,
+ 0.0304956708433771f, 0.0305454418823342f, 0.0305951585504198f,
+ 0.0306448208602409f, 0.0306944288244172f, 0.0307439824555803f,
+ 0.0307934817663740f, 0.0308429267694549f, 0.0308923174774914f,
+ 0.0309416539031645f, 0.0309909360591671f, 0.0310401639582047f,
+ 0.0310893376129952f, 0.0311384570362682f, 0.0311875222407662f,
+ 0.0312365332392437f, 0.0312854900444675f, 0.0313343926692167f,
+ 0.0313832411262826f, 0.0314320354284691f, 0.0314807755885919f,
+ 0.0315294616194793f, 0.0315780935339718f, 0.0316266713449223f,
+ 0.0316751950651957f, 0.0317236647076694f, 0.0317720802852332f,
+ 0.0318204418107888f, 0.0318687492972504f, 0.0319170027575447f,
+ 0.0319652022046102f, 0.0320133476513981f, 0.0320614391108717f,
+ 0.0321094765960065f, 0.0321574601197905f, 0.0322053896952238f,
+ 0.0322532653353189f, 0.0323010870531006f, 0.0323488548616057f,
+ 0.0323965687738836f, 0.0324442288029959f, 0.0324918349620166f,
+ 0.0325393872640315f, 0.0325868857221393f, 0.0326343303494504f,
+ 0.0326817211590881f, 0.0327290581641876f, 0.0327763413778963f,
+ 0.0328235708133741f, 0.0328707464837932f, 0.0329178684023379f,
+ 0.0329649365822048f, 0.0330119510366030f, 0.0330589117787536f,
+ 0.0331058188218902f, 0.0331526721792586f, 0.0331994718641168f,
+ 0.0332462178897352f, 0.0332929102693964f, 0.0333395490163956f,
+ 0.0333861341440396f, 0.0334326656656481f, 0.0334791435945528f,
+ 0.0335255679440978f, 0.0335719387276394f, 0.0336182559585463f,
+ 0.0336645196501992f, 0.0337107298159914f, 0.0337568864693283f,
+ 0.0338029896236278f, 0.0338490392923198f, 0.0338950354888466f,
+ 0.0339409782266627f, 0.0339868675192350f, 0.0340327033800429f,
+ 0.0340784858225774f, 0.0341242148603425f, 0.0341698905068542f,
+ 0.0342155127756406f, 0.0342610816802423f, 0.0343065972342121f,
+ 0.0343520594511153f, 0.0343974683445292f, 0.0344428239280434f,
+ 0.0344881262152600f, 0.0345333752197932f, 0.0345785709552694f,
+ 0.0346237134353274f, 0.0346688026736185f, 0.0347138386838059f,
+ 0.0347588214795652f, 0.0348037510745845f, 0.0348486274825640f,
+ 0.0348934507172161f, 0.0349382207922655f, 0.0349829377214494f,
+ 0.0350276015185171f, 0.0350722121972303f, 0.0351167697713627f,
+ 0.0351612742547006f, 0.0352057256610425f, 0.0352501240041991f,
+ 0.0352944692979934f, 0.0353387615562609f, 0.0353830007928488f,
+ 0.0354271870216173f, 0.0354713202564384f, 0.0355154005111967f,
+ 0.0355594277997888f, 0.0356034021361236f, 0.0356473235341225f,
+ 0.0356911920077191f, 0.0357350075708592f, 0.0357787702375008f,
+ 0.0358224800216146f, 0.0256623260145703f, 0.0257059300755882f,
+ 0.0257494812960632f, 0.0257929796900145f, 0.0258364252714742f,
+ 0.0258798180544862f, 0.0259231580531069f, 0.0259664452814049f,
+ 0.0260096797534614f, 0.0260528614833693f, 0.0260959904852343f,
+ 0.0261390667731740f, 0.0261820903613187f, 0.0262250612638107f,
+ 0.0262679794948044f, 0.0263108450684670f, 0.0263536579989775f,
+ 0.0263964183005274f, 0.0264391259873206f, 0.0264817810735729f,
+ 0.0265243835735127f, 0.0265669335013807f, 0.0266094308714296f,
+ 0.0266518756979248f, 0.0266942679951436f, 0.0267366077773757f,
+ 0.0267788950589231f, 0.0268211298541002f, 0.0268633121772335f,
+ 0.0269054420426618f, 0.0269475194647364f, 0.0269895444578204f,
+ 0.0270315170362898f, 0.0270734372145324f, 0.0271153050069485f,
+ 0.0271571204279507f, 0.0271988834919638f, 0.0272405942134248f,
+ 0.0272822526067832f, 0.0273238586865006f, 0.0273654124670510f,
+ 0.0274069139629206f, 0.0274483631886078f, 0.0274897601586236f,
+ 0.0275311048874910f, 0.0275723973897453f, 0.0276136376799340f,
+ 0.0276548257726174f, 0.0276959616823674f, 0.0277370454237685f,
+ 0.0277780770114174f, 0.0278190564599235f, 0.0278599837839078f,
+ 0.0279008589980039f, 0.0279416821168578f, 0.0279824531551276f,
+ 0.0280231721274838f, 0.0280638390486091f, 0.0281044539331986f,
+ 0.0281450167959595f, 0.0281855276516114f, 0.0282259865148862f,
+ 0.0282663934005280f, 0.0283067483232932f, 0.0283470512979505f,
+ 0.0283873023392809f, 0.0284275014620776f, 0.0284676486811463f,
+ 0.0285077440113047f, 0.0285477874673831f, 0.0285877790642237f,
+ 0.0286277188166811f, 0.0286676067396224f, 0.0287074428479268f,
+ 0.0287472271564859f, 0.0287869596802033f, 0.0288266404339953f,
+ 0.0288662694327901f, 0.0289058466915284f, 0.0289453722251632f,
+ 0.0289848460486596f, 0.0290242681769951f, 0.0290636386251596f,
+ 0.0291029574081548f, 0.0291422245409955f, 0.0291814400387080f,
+ 0.0292206039163312f, 0.0292597161889165f, 0.0292987768715272f,
+ 0.0293377859792390f, 0.0293767435271399f, 0.0294156495303304f,
+ 0.0294545040039229f, 0.0294933069630424f, 0.0295320584228259f,
+ 0.0295707583984229f, 0.0296094069049953f, 0.0296480039577166f,
+ 0.0296865495717735f, 0.0297250437623645f, 0.0297634865447003f,
+ 0.0298018779340040f, 0.0298402179455111f, 0.0298785065944694f,
+ 0.0299167438961386f, 0.0299549298657911f, 0.0299930645187115f,
+ 0.0300311478701964f, 0.0300691799355550f, 0.0301071607301086f,
+ 0.0301450902691910f, 0.0301829685681479f, 0.0302207956423377f,
+ 0.0302585715071309f, 0.0302962961779103f, 0.0303339696700707f,
+ 0.0303715919990197f, 0.0304091631801768f, 0.0304466832289741f,
+ 0.0304841521608554f, 0.0305215699912776f, 0.0305589367357091f,
+ 0.0305962524096311f, 0.0306335170285369f, 0.0306707306079320f,
+ 0.0307078931633345f, 0.0307450047102743f, 0.0307820652642940f,
+ 0.0308190748409481f, 0.0308560334558039f, 0.0308929411244405f,
+ 0.0309297978624495f, 0.0309666036854346f, 0.0310033586090122f,
+ 0.0310400626488105f, 0.0310767158204703f, 0.0311133181396446f,
+ 0.0311498696219986f, 0.0311863702832097f, 0.0210190092163552f,
+ 0.0210554082823626f, 0.0210917565743333f, 0.0211280541079942f,
+ 0.0211643008990843f, 0.0212004969633546f, 0.0212366423165687f,
+ 0.0212727369745025f, 0.0213087809529439f, 0.0213447742676934f,
+ 0.0213807169345635f, 0.0214166089693792f, 0.0214524503879776f,
+ 0.0214882412062082f, 0.0215239814399328f, 0.0215596711050254f,
+ 0.0215953102173724f, 0.0216308987928723f, 0.0216664368474359f,
+ 0.0217019243969867f, 0.0217373614574597f, 0.0217727480448030f,
+ 0.0218080841749764f, 0.0218433698639522f, 0.0218786051277151f,
+ 0.0219137899822618f, 0.0219489244436015f, 0.0219840085277557f,
+ 0.0220190422507578f, 0.0220540256286542f, 0.0220889586775028f,
+ 0.0221238414133744f, 0.0221586738523517f, 0.0221934560105297f,
+ 0.0222281879040160f, 0.0222628695489301f, 0.0222975009614039f,
+ 0.0223320821575819f, 0.0223666131536204f, 0.0224010939656882f,
+ 0.0224355246099665f, 0.0224699051026486f, 0.0225042354599400f,
+ 0.0225385156980587f, 0.0225727458332349f, 0.0226069258817113f,
+ 0.0226410558597423f, 0.0226751357835951f, 0.0227091656695491f,
+ 0.0227431455338958f, 0.0227770753929393f, 0.0228109552629954f,
+ 0.0228447851603930f, 0.0228785651014724f, 0.0229122951025869f,
+ 0.0229459751801015f, 0.0229796053503942f, 0.0230131856298546f,
+ 0.0230467160348848f, 0.0230801965818993f, 0.0231136272873249f,
+ 0.0231470081676005f, 0.0231803392391772f, 0.0232136205185188f,
+ 0.0232468520221011f, 0.0232800337664121f, 0.0233131657679523f,
+ 0.0233462480432343f, 0.0233792806087829f, 0.0234122634811357f,
+ 0.0234451966768419f, 0.0234780802124634f, 0.0235109141045745f,
+ 0.0235436983697613f, 0.0235764330246225f, 0.0236091180857689f,
+ 0.0236417535698240f, 0.0236743394934231f, 0.0237068758732141f,
+ 0.0237393627258569f, 0.0237718000680239f, 0.0238041879163996f,
+ 0.0238365262876811f, 0.0238688151985775f, 0.0239010546658102f,
+ 0.0239332447061131f, 0.0239653853362320f, 0.0239974765729254f,
+ 0.0240295184329637f, 0.0240615109331300f, 0.0240934540902192f,
+ 0.0241253479210389f, 0.0241571924424087f, 0.0241889876711606f,
+ 0.0242207336241391f, 0.0242524303182004f, 0.0242840777702138f,
+ 0.0243156759970598f, 0.0243472250156324f, 0.0243787248428368f,
+ 0.0244101754955914f, 0.0244415769908261f, 0.0244729293454835f,
+ 0.0245042325765185f, 0.0245354867008983f, 0.0245666917356021f,
+ 0.0245978476976215f, 0.0246289546039604f, 0.0246600124716354f,
+ 0.0246910213176745f, 0.0247219811591188f, 0.0247528920130213f,
+ 0.0247837538964472f, 0.0248145668264743f, 0.0248453308201923f,
+ 0.0248760458947036f, 0.0249067120671227f, 0.0249373293545762f,
+ 0.0249678977742031f, 0.0249984173431548f, 0.0148250771559823f,
+ 0.0148554990750867f, 0.0148858721950435f, 0.0149161965330530f,
+ 0.0149464721063281f, 0.0149766989320937f, 0.0150068770275872f,
+ 0.0150370064100582f, 0.0150670870967684f, 0.0150971191049919f,
+ 0.0151271024520153f, 0.0151570371551371f, 0.0151869232316685f,
+ 0.0152167606989325f, 0.0152465495742647f, 0.0152762898750130f,
+ 0.0153059816185374f, 0.0153356248222104f, 0.0153652195034166f,
+ 0.0153947656795529f, 0.0154242633680285f, 0.0154537125862650f,
+ 0.0154831133516962f, 0.0155124656817680f, 0.0155417695939390f,
+ 0.0155710251056796f, 0.0156002322344730f, 0.0156293909978140f,
+ 0.0156585014132103f, 0.0156875634981817f, 0.0157165772702601f,
+ 0.0157455427469900f, 0.0157744599459278f, 0.0158033288846426f,
+ 0.0158321495807153f, 0.0158609220517395f, 0.0158896463153209f,
+ 0.0159183223890776f, 0.0159469502906399f, 0.0159755300376501f,
+ 0.0160040616477634f, 0.0160325451386467f, 0.0160609805279795f,
+ 0.0160893678334535f, 0.0161177070727727f, 0.0161459982636532f,
+ 0.0161742414238237f, 0.0162024365710251f, 0.0162305837230104f,
+ 0.0162586828975450f, 0.0162867341124064f, 0.0163147373853849f,
+ 0.0163426927342824f, 0.0163706001769136f, 0.0163984597311053f,
+ 0.0164262714146964f, 0.0164540352455384f, 0.0164817512414950f,
+ 0.0165094194204420f, 0.0165370398002675f, 0.0165646123988723f,
+ 0.0165921372341689f, 0.0166196143240825f, 0.0166470436865503f,
+ 0.0166744253395220f, 0.0167017593009595f, 0.0167290455888369f,
+ 0.0167562842211408f, 0.0167834752158696f, 0.0168106185910347f,
+ 0.0168377143646592f, 0.0168647625547787f, 0.0168917631794411f,
+ 0.0169187162567065f, 0.0169456218046473f, 0.0169724798413484f,
+ 0.0169992903849065f, 0.0170260534534310f, 0.0170527690650435f,
+ 0.0170794372378779f, 0.0171060579900800f, 0.0171326313398085f,
+ 0.0171591573052340f, 0.0171856359045393f, 0.0172120671559199f,
+ 0.0172384510775832f, 0.0172647876877488f, 0.0172910770046491f,
+ 0.0173173190465285f, 0.0173435138316433f, 0.0173696613782627f,
+ 0.0173957617046678f, 0.0174218148291521f, 0.0174478207700215f,
+ 0.0174737795455938f, 0.0174996911741995f, 0.0175255556741812f,
+ 0.0175513730638939f, 0.0175771433617046f, 0.0176028665859928f,
+ 0.0176285427551502f, 0.0176541718875811f, 0.0176797540017015f,
+ 0.0177052891159402f, 0.0177307772487379f, 0.0177562184185478f,
+ 0.0177816126438354f, 0.0178069599430784f, 0.0178322603347666f,
+ 0.0178575138374025f, 0.0178827204695006f, 0.0179078802495878f,
+ 0.0179329931962031f, 0.0179580593278980f, 0.0179830786632361f,
+ 0.0180080512207934f, 0.0180329770191581f, 0.0180578560769309f,
+ 0.0180826884127244f, 0.0181074740451639f, 0.0181322129928866f,
+ 0.00795309435192959f, 0.00797773998617998f, 0.00800233899169950f,
+ 0.00802689138717461f, 0.00805139719130404f, 0.00807585642279884f,
+ 0.00810026910038247f, 0.00812463524279045f, 0.00814895486877063f,
+ 0.00817322799708334f, 0.00819745464650101f, 0.00822163483580835f,
+ 0.00824576858380241f, 0.00826985590929247f, 0.00829389683110024f,
+ 0.00831789136805938f, 0.00834183953901635f, 0.00836574136282939f,
+ 0.00838959685836918f, 0.00841340604451885f, 0.00843716894017363f,
+ 0.00846088556424110f, 0.00848455593564104f, 0.00850818007330578f,
+ 0.00853175799617945f, 0.00855528972321903f, 0.00857877527339326f,
+ 0.00860221466568337f, 0.00862560791908315f, 0.00864895505259825f,
+ 0.00867225608524677f, 0.00869551103605912f, 0.00871871992407797f,
+ 0.00874188276835819f, 0.00876499958796712f, 0.00878807040198421f,
+ 0.00881109522950124f, 0.00883407408962228f, 0.00885700700146366f,
+ 0.00887989398415420f, 0.00890273505683453f, 0.00892553023865803f,
+ 0.00894827954879010f, 0.00897098300640842f, 0.00899364063070327f,
+ 0.00901625244087678f, 0.00903881845614354f, 0.00906133869573070f,
+ 0.00908381317887699f, 0.00910624192483434f, 0.00912862495286607f,
+ 0.00915096228224840f, 0.00917325393226956f, 0.00919549992223012f,
+ 0.00921770027144295f, 0.00923985499923324f, 0.00926196412493843f,
+ 0.00928402766790812f, 0.00930604564750417f, 0.00932801808310113f,
+ 0.00934994499408540f, 0.00937182639985590f, 0.00939366231982353f,
+ 0.00941545277341183f, 0.00943719778005636f, 0.00945889735920535f,
+ 0.00948055153031865f, 0.00950216031286910f, 0.00952372372634122f,
+ 0.00954524179023242f, 0.00956671452405170f, 0.00958814194732097f,
+ 0.00960952407957394f, 0.00963086094035709f, 0.00965215254922858f,
+ 0.00967339892575941f, 0.00969460008953246f, 0.00971575606014319f,
+ 0.00973686685719929f, 0.00975793250032039f, 0.00977895300913892f,
+ 0.00979992840329916f, 0.00982085870245789f, 0.00984174392628431f,
+ 0.00986258409445931f, 0.00988337922667690f, 0.00990412934264276f,
+ 0.00992483446207504f, 0.00994549460470412f, 0.00996610979027271f,
+ 0.00998668003853587f, 0.0100072053692609f, 0.0100276858022273f,
+ 0.0100481213572269f, 0.0100685120540638f, 0.0100888579125544f,
+ 0.0101091589525275f, 0.0101294151938238f, 0.0101496266562968f,
+ 0.0101697933598117f, 0.0101899153242468f, 0.0102099925694918f,
+ 0.0102300251154490f, 0.0102500129820334f, 0.0102699561891717f,
+ 0.0102898547568033f, 0.0103097087048794f, 0.0103295180533639f,
+ 0.0103492828222330f, 0.0103690030314749f, 0.0103886787010901f,
+ 0.0104083098510918f, 0.0104278965015051f, 0.0104474386723672f,
+ 0.0104669363837280f, 0.0104863896556498f, 0.0105057985082065f,
+ 0.0105251629614849f, 0.0105444830355838f, 0.0105637587506144f,
+ 0.0105829901267000f, 0.0106021771839766f, 0.0106213199425919f,
+ 0.0106404184227065f, 0.0106594726444926f, 0.0106784826281353f,
+ 0.0106974483938314f, 0.0107163699617908f, 0.0107352473522349f,
+ 0.0107540805853976f, 0.0107728696815252f, 0.0107916146608764f,
+ 0.0108103155437217f, 0.0108289723503445f, 0.0108475851010400f,
+ 0.0108661538161160f, 0.0108846785158922f, 0.0109031592207011f,
+ 0.0109215959508869f, 0.0109399887268067f, 0.0109583375688294f,
+ 0.0109766424973363f, 0.0109949035327211f, 0.0110131206953896f,
+ 0.0110312940057603f, 0.0110494234842632f, 0.000863698228728893f,
+ 0.000881740104837381f, 0.000899738210443285f, 0.000917692566026501f,
+ 0.000935603192078749f, 0.000953470109104099f, 0.000971293337619111f,
+ 0.000989072898152504f, 0.00100680881124518f, 0.00102450109745059f,
+ 0.00104214977733416f, 0.00105975487147383f, 0.00107731640045972f,
+ 0.00109483438489416f, 0.00111230884539187f, 0.00112973980257991f,
+ 0.00114712727709757f, 0.00116447128959615f, 0.00118177186073964f,
+ 0.00119902901120417f, 0.00121624276167817f, 0.00123341313286207f,
+ 0.00125054014546896f, 0.00126762382022416f, 0.00128466417786494f,
+ 0.00130166123914147f, 0.00131861502481540f, 0.00133552555566130f,
+ 0.00135239285246572f, 0.00136921693602776f, 0.00138599782715843f,
+ 0.00140273554668116f, 0.00141943011543194f, 0.00143608155425867f,
+ 0.00145268988402170f, 0.00146925512559357f, 0.00148577729985921f,
+ 0.00150225642771590f, 0.00151869253007300f, 0.00153508562785212f,
+ 0.00155143574198749f, 0.00156774289342521f, 0.00158400710312404f,
+ 0.00160022839205470f, 0.00161640678120040f, 0.00163254229155643f,
+ 0.00164863494413064f, 0.00166468475994314f, 0.00168069176002578f,
+ 0.00169665596542351f, 0.00171257739719283f, 0.00172845607640326f,
+ 0.00174429202413584f, 0.00176008526148430f, 0.00177583580955454f,
+ 0.00179154368946505f, 0.00180720892234626f, 0.00182283152934076f,
+ 0.00183841153160380f, 0.00185394895030278f, 0.00186944380661724f,
+ 0.00188489612173903f, 0.00190030591687257f, 0.00191567321323430f,
+ 0.00193099803205288f, 0.00194628039456934f, 0.00196152032203714f,
+ 0.00197671783572181f, 0.00199187295690129f, 0.00200698570686583f,
+ 0.00202205610691772f, 0.00203708417837167f, 0.00205206994255494f,
+ 0.00206701342080665f, 0.00208191463447846f, 0.00209677360493415f,
+ 0.00211159035354996f, 0.00212636490171420f, 0.00214109727082776f,
+ 0.00215578748230350f, 0.00217043555756677f, 0.00218504151805510f,
+ 0.00219960538521813f, 0.00221412718051822f, 0.00222860692542973f,
+ 0.00224304464143935f, 0.00225744035004599f, 0.00227179407276090f,
+ 0.00228610583110747f, 0.00230037564662183f, 0.00231460354085172f,
+ 0.00232878953535784f, 0.00234293365171256f, 0.00235703591150094f,
+ 0.00237109633632010f, 0.00238511494777985f, 0.00239909176750147f,
+ 0.00241302681711936f, 0.00242692011827975f, 0.00244077169264129f,
+ 0.00245458156187497f, 0.00246834974766388f, 0.00248207627170341f,
+ 0.00249576115570141f, 0.00250940442137795f, 0.00252300609046513f,
+ 0.00253656618470771f, 0.00255008472586260f, 0.00256356173569897f,
+ 0.00257699723599797f, 0.00259039124855365f, 0.00260374379517186f,
+ 0.00261705489767092f, 0.00263032457788148f, 0.00264355285764614f,
+ 0.00265673975882014f, 0.00266988530327097f, 0.00268298951287835f,
+ 0.00269605240953399f, 0.00270907401514245f, 0.00272205435162004f,
+ 0.00273499344089564f, 0.00274789130491049f, 0.00276074796561768f,
+ 0.00277356344498309f, 0.00278633776498463f, 0.00279907094761245f,
+ 0.00281176301486905f, 0.00282441398876931f, 0.00283702389134027f,
+ 0.00284959274462127f, 0.00286212057066382f, 0.00287460739153189f,
+ 0.00288705322930180f, 0.00289945810606193f, 0.00291182204391308f,
+ 0.00292414506496813f, 0.00293642719135262f, 0.00294866844520389f,
+ 0.00296086884867222f, 0.00297302842391931f, 0.00298514719311982f,
+ 0.00299722517846057f, 0.00300926240214039f, 0.00302125888637081f,
+ 0.00303321465337506f, 0.00304512972538920f, 0.00305700412466148f,
+ 0.00306883787345200f, 0.00308063099403366f, 0.00309238350869140f,
+ 0.00310409543972254f, 0.00311576680943643f, 0.00312739764015507f,
+ 0.00313898795421264f, 0.00315053777395527f, 0.00316204712174176f,
+ 0.00317351601994309f, 0.00318494449094245f, 0.00319633255713528f,
+ 0.00320768024092954f, 0.00321898756474520f, 0.00323025455101456f,
+ 0.00324148122218240f, 0.00325266760070547f, 0.00326381370905315f,
+ 0.00327491956970674f, 0.00328598520516016f, 0.00329701063791929f,
+ 0.00330799589050260f, 0.00331894098544075f, 0.00332984594527644f,
+ 0.00334071079256490f, 0.00335153554987361f, 0.00336232023978234f,
+ 0.00337306488488309f, 0.00338376950778002f, 0.00339443413108997f,
+ 0.00340505877744157f, 0.00341564346947612f, 0.00342618822984689f,
+ 0.00343669308121961f, 0.00344715804627233f, 0.00345758314769543f,
+ 0.00346796840819122f, 0.00347831385047465f, 0.00348861949727269f,
+ 0.00349888537132503f, 0.00350911149538313f, 0.00351929789221103f,
+ 0.00352944458458487f, 0.00353955159529323f, 0.00354961894713696f,
+ 0.00355964666292907f, 0.00356963476549479f, 0.00357958327767202f,
+ 0.00358949222231061f, 0.00359936162227278f, 0.00360919150043287f,
+ 0.00361898187967777f, 0.00362873278290654f, 0.00363844423303059f,
+ 0.00364811625297337f, 0.00365774886567080f, 0.00366734209407113f,
+ 0.00367689596113485f, 0.00368641048983448f, 0.00369588570315532f,
+ 0.00370532162409457f, 0.00371471827566178f, 0.00372407568087890f,
+ 0.00373339386277999f, 0.00374267284441140f, 0.00375191264883207f,
+ 0.00376111329911286f, 0.00377027481833711f, 0.00377939722960025f,
+ 0.00378848055601022f, 0.00379752482068707f, 0.00380653004676323f,
+ 0.00381549625738342f, 0.00382442347570458f, 0.00383331172489607f,
+ 0.00384216102813920f, 0.00385097140862786f, 0.00385974288956820f,
+ 0.00386847549417849f, 0.00387716924568945f, 0.00388582416734407f,
+ 0.00389444028239744f, 0.00390301761411704f, 0.00391155618578290f,
+ 0.00392005602068687f, 0.00392851714213324f, 0.00393693957343871f};
+
+// Curve which is scaled by |kCurveCorrectionMultipliers| and added to the curve
+// generated by the |kLowReverberationCorrectionCurve| polynomial, for
+// reverberation times which result in a feedback factor index less than
+// |kCurveChangeoverIndex|.
+static const float kLowCorrectionCurve[kCorrectionCurveLength] = {
+ 0.0355835132858260f, 0.0361471820669677f, 0.0367104001412021f,
+ 0.0372731677107544f, 0.0378354849778072f, 0.0383973521445001f,
+ 0.0389587694129315f, 0.0395197369851564f, 0.0400802550631881f,
+ 0.0406403238489973f, 0.0411999435445122f, 0.0417591143516188f,
+ 0.0423178364721608f, 0.0428761101079397f, 0.0434339354607135f,
+ 0.0439913127321995f, 0.0445482421240714f, 0.0451047238379613f,
+ 0.0456607580754581f, 0.0462163450381097f, 0.0467714849274197f,
+ 0.0473261779448504f, 0.0478804242918223f, 0.0484342241697123f,
+ 0.0489875777798562f, 0.0495404853235463f, 0.0500929470020328f,
+ 0.0506449630165243f, 0.0511965335681860f, 0.0517476588581411f,
+ 0.0522983390874708f, 0.0528485744572133f, 0.0533983651683647f,
+ 0.0539477114218787f, 0.0544966134186670f, 0.0550450713595981f,
+ 0.0555930854454990f, 0.0561406558771536f, 0.0566877828553037f,
+ 0.0572344665806487f, 0.0577807072538459f, 0.0583265050755101f,
+ 0.0588718602462131f, 0.0594167729664848f, 0.0599612434368130f,
+ 0.0605052718576424f, 0.0610488584293762f, 0.0615920033523746f,
+ 0.0621347068269552f, 0.0626769690533939f, 0.0632187902319240f,
+ 0.0637601705627360f, 0.0643011102459783f, 0.0648416094817569f,
+ 0.0653816684701354f, 0.0659212874111350f, 0.0664604665047346f,
+ 0.0669992059508706f, 0.0675375059494370f, 0.0680753667002852f,
+ 0.0686127884032250f, 0.0691497712580228f, 0.0696863154644029f,
+ 0.0702224212220476f, 0.0707580887305970f, 0.0712933181896472f,
+ 0.0718281097987538f, 0.0723624637574293f, 0.0728963802651431f,
+ 0.0734298595213236f, 0.0739629017253557f, 0.0744955070765820f,
+ 0.0750276757743035f, 0.0755594080177776f, 0.0760907040062205f,
+ 0.0766215639388050f, 0.0771519880146623f, 0.0776819764328806f,
+ 0.0782115293925059f, 0.0787406470925415f, 0.0792693297319489f,
+ 0.0797975775096472f, 0.0803253906245122f, 0.0808527692753781f,
+ 0.0813797136610364f, 0.0819062239802365f, 0.0824323004316849f,
+ 0.0829579432140462f, 0.0834831525259416f, 0.0840079285659512f,
+ 0.0845322715326120f, 0.0850561816244186f, 0.0855796590398233f,
+ 0.0861027039772357f, 0.0866253166350237f, 0.0871474972115118f,
+ 0.0876692459049832f, 0.0881905629136774f, 0.0887114484357927f,
+ 0.0892319026694841f, 0.0897519258128650f, 0.0902715180640052f,
+ 0.0907906796209331f, 0.0913094106816348f, 0.0918277114440527f,
+ 0.0923455821060883f, 0.0928630228655998f, 0.0933800339204031f,
+ 0.0938966154682718f, 0.0944127677069371f, 0.0949284908340879f,
+ 0.0954437850473701f, 0.0959586505443875f, 0.0964730875227018f,
+ 0.0969870961798317f, 0.0975006767132541f, 0.0980138293204033f,
+ 0.0985265541986706f, 0.0990388515454054f, 0.0995507215579148f,
+ 0.100062164433463f, 0.100573180369272f, 0.101083769562521f,
+ 0.101593932210348f, 0.102103668509848f, 0.102612978658072f,
+ 0.103121862852030f, 0.103630321288690f, 0.104138354164977f,
+ 0.104645961677773f, 0.105153144023918f, 0.105659901400211f,
+ 0.106166234003407f, 0.106672142030217f, 0.107177625677312f,
+ 0.107682685141321f, 0.108187320618829f, 0.108691532306379f,
+ 0.109195320400472f, 0.109698685097565f, 0.110201626594074f,
+ 0.110704145086373f, 0.111206240770793f, 0.111707913843621f,
+ 0.112209164501105f, 0.112709992939447f, 0.113210399354808f,
+ 0.113710383943307f, 0.114209946901020f, 0.114709088423982f,
+ 0.115207808708182f, 0.115706107949571f, 0.116203986344054f,
+ 0.116701444087495f, 0.117198481375716f, 0.117695098404497f,
+ 0.118191295369573f, 0.118687072466638f, 0.119182429891344f,
+ 0.119677367839301f, 0.120171886506076f, 0.120665986087191f,
+ 0.121159666778131f, 0.121652928774333f, 0.122145772271196f,
+ 0.122638197464072f, 0.123130204548276f, 0.123621793719075f,
+ 0.124112965171697f, 0.124603719101328f, 0.125094055703108f,
+ 0.125583975172139f, 0.126073477703476f, 0.126562563492136f,
+ 0.127051232733090f, 0.127539485621269f, 0.128027322351559f,
+ 0.128514743118806f, 0.129001748117814f, 0.129488337543340f,
+ 0.129974511590103f, 0.130460270452779f, 0.130945614326000f,
+ 0.131430543404356f, 0.131915057882395f, 0.132399157954622f,
+ 0.132882843815500f, 0.133366115659450f, 0.133848973680849f,
+ 0.134331418074033f, 0.134813449033295f, 0.130933338745307f,
+ 0.131414543419434f, 0.131895335242262f, 0.132375714407915f,
+ 0.132855681110473f, 0.133335235543976f, 0.133814377902417f,
+ 0.134293108379751f, 0.134771427169888f, 0.135249334466697f,
+ 0.135726830464003f, 0.136203915355590f, 0.136680589335197f,
+ 0.137156852596525f, 0.137632705333228f, 0.138108147738920f,
+ 0.138583180007172f, 0.139057802331512f, 0.139532014905426f,
+ 0.140005817922358f, 0.140479211575709f, 0.140952196058836f,
+ 0.141424771565058f, 0.141896938287645f, 0.142368696419831f,
+ 0.142840046154803f, 0.143310987685707f, 0.143781521205648f,
+ 0.144251646907686f, 0.144721364984839f, 0.145190675630085f,
+ 0.145659579036357f, 0.146128075396545f, 0.146596164903499f,
+ 0.147063847750025f, 0.147531124128886f, 0.147997994232804f,
+ 0.148464458254458f, 0.148930516386483f, 0.149396168821473f,
+ 0.149861415751981f, 0.150326257370514f, 0.150790693869538f,
+ 0.151254725441479f, 0.151718352278716f, 0.152181574573589f,
+ 0.152644392518394f, 0.153106806305386f, 0.153568816126774f,
+ 0.154030422174728f, 0.154491624641374f, 0.154952423718796f,
+ 0.155412819599036f, 0.155872812474093f, 0.156332402535922f,
+ 0.156791589976438f, 0.157250374987511f, 0.157708757760971f,
+ 0.158166738488604f, 0.158624317362153f, 0.159081494573321f,
+ 0.159538270313766f, 0.159994644775104f, 0.160450618148909f,
+ 0.160906190626713f, 0.161361362400004f, 0.161816133660228f,
+ 0.162270504598790f, 0.162724475407050f, 0.163178046276328f,
+ 0.163631217397900f, 0.164083988962999f, 0.164536361162817f,
+ 0.164988334188502f, 0.165439908231161f, 0.165891083481858f,
+ 0.166341860131613f, 0.166792238371406f, 0.167242218392172f,
+ 0.167691800384806f, 0.168140984540158f, 0.168589771049037f,
+ 0.169038160102209f, 0.169486151890398f, 0.165572018596708f,
+ 0.166019216426932f, 0.166466017564089f, 0.166912422198731f,
+ 0.167358430521371f, 0.167804042722478f, 0.168249258992475f,
+ 0.168694079521749f, 0.169138504500638f, 0.169582534119443f,
+ 0.170026168568418f, 0.170469408037777f, 0.170912252717692f,
+ 0.171354702798289f, 0.171796758469656f, 0.172238419921836f,
+ 0.172679687344829f, 0.173120560928594f, 0.173561040863046f,
+ 0.174001127338058f, 0.174440820543462f, 0.174880120669046f,
+ 0.175319027904554f, 0.175757542439691f, 0.176195664464117f,
+ 0.176633394167450f, 0.177070731739265f, 0.177507677369096f,
+ 0.177944231246432f, 0.178380393560723f, 0.178816164501372f,
+ 0.179251544257744f, 0.179686533019159f, 0.180121130974894f,
+ 0.180555338314184f, 0.180989155226223f, 0.181422581900160f,
+ 0.181855618525104f, 0.182288265290119f, 0.182720522384228f,
+ 0.183152389996411f, 0.183583868315606f, 0.184014957530707f,
+ 0.184445657830568f, 0.184875969403997f, 0.185305892439763f,
+ 0.185735427126589f, 0.186164573653160f, 0.186593332208113f,
+ 0.187021702980047f, 0.187449686157516f, 0.187877281929033f,
+ 0.188304490483066f, 0.188731312008043f, 0.189157746692349f,
+ 0.189583794724325f, 0.190009456292270f, 0.190434731584443f,
+ 0.190859620789056f, 0.191284124094282f, 0.191708241688250f,
+ 0.192131973759046f, 0.192555320494716f, 0.192978282083259f,
+ 0.193400858712636f, 0.193823050570763f, 0.194244857845513f,
+ 0.190304552717141f, 0.190725591388591f, 0.191146246040030f,
+ 0.191566516859164f, 0.191986404033653f, 0.192405907751115f,
+ 0.192825028199128f, 0.193243765565223f, 0.193662120036893f,
+ 0.194080091801586f, 0.194497681046707f, 0.194914887959619f,
+ 0.195331712727645f, 0.195748155538060f, 0.196164216578102f,
+ 0.196579896034964f, 0.196995194095795f, 0.197410110947704f,
+ 0.197824646777756f, 0.198238801772974f, 0.198652576120338f,
+ 0.199065970006786f, 0.199478983619212f, 0.199891617144471f,
+ 0.200303870769370f, 0.200715744680679f, 0.201127239065121f,
+ 0.201538354109379f, 0.201949090000093f, 0.202359446923861f,
+ 0.202769425067235f, 0.203179024616730f, 0.203588245758813f,
+ 0.203997088679912f, 0.204405553566412f, 0.204813640604653f,
+ 0.205221349980936f, 0.205628681881516f, 0.206035636492609f,
+ 0.206442214000385f, 0.206848414590972f, 0.207254238450459f,
+ 0.207659685764888f, 0.208064756720260f, 0.208469451502535f,
+ 0.208873770297627f, 0.209277713291411f, 0.209681280669718f,
+ 0.210084472618335f, 0.210487289323009f, 0.210889730969442f,
+ 0.211291797743296f, 0.211693489830188f, 0.212094807415693f,
+ 0.212495750685345f, 0.212896319824633f, 0.213296515019006f,
+ 0.213696336453868f, 0.214095784314582f, 0.214494858786468f,
+ 0.210531832047226f, 0.210930160297245f, 0.211328115714141f,
+ 0.211725698483062f, 0.212122908789116f, 0.212519746817367f,
+ 0.212916212752837f, 0.213312306780505f, 0.213708029085308f,
+ 0.214103379852140f, 0.214498359265853f, 0.214892967511255f,
+ 0.215287204773112f, 0.215681071236149f, 0.216074567085046f,
+ 0.216467692504443f, 0.216860447678934f, 0.217252832793074f,
+ 0.217644848031373f, 0.218036493578299f, 0.218427769618278f,
+ 0.218818676335693f, 0.219209213914884f, 0.219599382540149f,
+ 0.219989182395744f, 0.220378613665880f, 0.220767676534728f,
+ 0.221156371186415f, 0.221544697805026f, 0.221932656574604f,
+ 0.222320247679147f, 0.222707471302613f, 0.223094327628916f,
+ 0.223480816841929f, 0.223866939125480f, 0.224252694663356f,
+ 0.224638083639300f, 0.225023106237015f, 0.225407762640159f,
+ 0.225792053032349f, 0.226175977597157f, 0.226559536518116f,
+ 0.226942729978713f, 0.227325558162394f, 0.227708021252562f,
+ 0.228090119432578f, 0.228471852885760f, 0.228853221795383f,
+ 0.229234226344680f, 0.229614866716842f, 0.229995143095015f,
+ 0.230375055662304f, 0.230754604601773f, 0.231133790096440f,
+ 0.231512612329282f, 0.231891071483235f, 0.227907439733612f,
+ 0.228285173278418f, 0.228662544292882f, 0.229039552959768f,
+ 0.229416199461797f, 0.229792483981648f, 0.230168406701958f,
+ 0.230543967805320f, 0.230919167474285f, 0.231294005891360f,
+ 0.231668483239013f, 0.232042599699666f, 0.232416355455699f,
+ 0.232789750689451f, 0.233162785583216f, 0.233535460319247f,
+ 0.233907775079755f, 0.234279730046907f, 0.234651325402827f,
+ 0.235022561329597f, 0.235393438009258f, 0.235763955623805f,
+ 0.236134114355194f, 0.236503914385335f, 0.236873355896098f,
+ 0.237242439069310f, 0.237611164086754f, 0.237979531130171f,
+ 0.238347540381260f, 0.238715192021677f, 0.239082486233034f,
+ 0.239449423196903f, 0.239816003094811f, 0.240182226108245f,
+ 0.240548092418646f, 0.240913602207415f, 0.241278755655909f,
+ 0.241643552945443f, 0.242007994257290f, 0.242372079772679f,
+ 0.242735809672797f, 0.243099184138788f, 0.243462203351754f,
+ 0.243824867492754f, 0.244187176742804f, 0.244549131282879f,
+ 0.244910731293909f, 0.245271976956783f, 0.245632868452347f,
+ 0.245993405961404f, 0.246353589664714f, 0.246713419742997f,
+ 0.247072896376926f, 0.247432019747135f, 0.243429062026635f,
+ 0.243787479411131f, 0.244145544073548f, 0.244503256194350f,
+ 0.244860615953955f, 0.245217623532740f, 0.245574279111040f,
+ 0.245930582869146f, 0.246286534987307f, 0.246642135645729f,
+ 0.246997385024576f, 0.247352283303969f, 0.247706830663986f,
+ 0.248061027284663f, 0.248414873345993f, 0.248768369027926f,
+ 0.249121514510370f, 0.249474309973191f, 0.249826755596210f,
+ 0.250178851559207f, 0.250530598041920f, 0.250881995224043f,
+ 0.251233043285228f, 0.251583742405084f, 0.251934092763177f,
+ 0.252284094539032f, 0.252633747912130f, 0.252983053061909f,
+ 0.253332010167765f, 0.253680619409052f, 0.254028880965080f,
+ 0.254376795015117f, 0.254724361738388f, 0.255071581314077f,
+ 0.255418453921322f, 0.255764979739221f, 0.256111158946830f,
+ 0.256456991723160f, 0.256802478247180f, 0.257147618697817f,
+ 0.257492413253955f, 0.257836862094436f, 0.258180965398058f,
+ 0.258524723343577f, 0.258868136109707f, 0.259211203875118f,
+ 0.259553926818439f, 0.259896305118254f, 0.260238338953107f,
+ 0.260580028501497f, 0.260921373941883f, 0.261262375452678f,
+ 0.261603033212256f, 0.261943347398944f, 0.262283318191031f,
+ 0.258261217759182f, 0.258600502296753f, 0.258939443974328f,
+ 0.259278042970020f, 0.259616299461904f, 0.259954213628010f,
+ 0.260291785646327f, 0.260629015694800f, 0.260965903951331f,
+ 0.261302450593780f, 0.261638655799966f, 0.261974519747662f,
+ 0.262310042614600f, 0.262645224578471f, 0.262980065816920f,
+ 0.263314566507552f, 0.263648726827928f, 0.263982546955566f,
+ 0.264316027067943f, 0.264649167342491f, 0.264981967956602f,
+ 0.265314429087624f, 0.265646550912860f, 0.265978333609575f,
+ 0.266309777354988f, 0.266640882326276f, 0.266971648700574f,
+ 0.267302076654974f, 0.267632166366524f, 0.267961918012231f,
+ 0.268291331769060f, 0.268620407813930f, 0.268949146323722f,
+ 0.269277547475269f, 0.269605611445366f, 0.269933338410763f,
+ 0.270260728548167f, 0.270587782034243f, 0.270914499045615f,
+ 0.271240879758860f, 0.271566924350517f, 0.271892632997080f,
+ 0.272218005874999f, 0.272543043160685f, 0.272867745030503f,
+ 0.273192111660776f, 0.273516143227786f, 0.273839839907771f,
+ 0.274163201876925f, 0.274486229311402f, 0.274808922387312f,
+ 0.275131281280722f, 0.275453306167657f, 0.275774997224098f,
+ 0.276096354625986f, 0.276417378549215f, 0.272376341162064f,
+ 0.272696698655497f, 0.273016723197707f, 0.273336414964418f,
+ 0.273655774131314f, 0.273974800874035f, 0.274293495368180f,
+ 0.274611857789301f, 0.274929888312913f, 0.275247587114485f,
+ 0.275564954369443f, 0.275881990253173f, 0.276198694941014f,
+ 0.276515068608266f, 0.276831111430185f, 0.277146823581984f,
+ 0.277462205238834f, 0.277777256575864f, 0.278091977768158f,
+ 0.278406368990758f, 0.278720430418665f, 0.279034162226836f,
+ 0.279347564590185f, 0.279660637683583f, 0.279973381681861f,
+ 0.280285796759803f, 0.280597883092155f, 0.280909640853616f,
+ 0.281221070218844f, 0.281532171362457f, 0.281842944459025f,
+ 0.282153389683078f, 0.282463507209106f, 0.282773297211551f,
+ 0.283082759864817f, 0.283391895343261f, 0.283700703821200f,
+ 0.284009185472909f, 0.284317340472619f, 0.284625168994516f,
+ 0.284932671212748f, 0.285239847301418f, 0.285546697434584f,
+ 0.285853221786265f, 0.286159420530436f, 0.286465293841028f,
+ 0.286770841891931f, 0.287076064856991f, 0.287380962910013f,
+ 0.287685536224756f, 0.287989784974941f, 0.288293709334242f,
+ 0.288597309476293f, 0.288900585574683f, 0.289203537802961f,
+ 0.289506166334631f, 0.289808471343155f, 0.290110453001953f,
+ 0.290412111484400f, 0.290713446963832f, 0.286652731605961f,
+ 0.286953421599191f, 0.287253789109152f, 0.287553834309004f,
+ 0.287853557371869f, 0.288152958470824f, 0.288452037778905f,
+ 0.288750795469103f, 0.289049231714367f, 0.289347346687604f,
+ 0.289645140561678f, 0.289942613509411f, 0.290239765703580f,
+ 0.290536597316922f, 0.290833108522128f, 0.291129299491851f,
+ 0.291425170398696f, 0.291720721415230f, 0.292015952713973f,
+ 0.292310864467405f, 0.292605456847963f, 0.292899730028041f,
+ 0.293193684179989f, 0.293487319476116f, 0.293780636088688f,
+ 0.294073634189927f, 0.294366313952014f, 0.294658675547085f,
+ 0.294950719147237f, 0.295242444924520f, 0.295533853050944f,
+ 0.295824943698475f, 0.296115717039037f, 0.296406173244510f,
+ 0.296696312486734f, 0.296986134937503f, 0.297275640768571f,
+ 0.297564830151647f, 0.297853703258398f, 0.298142260260449f,
+ 0.298430501329382f, 0.298718426636735f, 0.299006036354006f,
+ 0.299293330652647f, 0.299580309704069f, 0.299866973679640f,
+ 0.300153322750686f, 0.300439357088489f, 0.300725076864288f,
+ 0.301010482249282f, 0.301295573414623f, 0.301580350531424f,
+ 0.301864813770753f, 0.302148963303636f, 0.302432799301057f,
+ 0.302716321933956f, 0.302999531373231f, 0.303282427789736f,
+ 0.303565011354285f, 0.303847282237646f, 0.304129240610547f,
+ 0.304410886643670f, 0.304692220507658f, 0.304973242373109f,
+ 0.305253952410579f, 0.305534350790580f, 0.305814437683583f,
+ 0.301732485252438f, 0.302011949682684f, 0.302291103137086f,
+ 0.302569945785942f, 0.302848477799510f, 0.303126699348003f,
+ 0.303404610601592f, 0.303682211730404f, 0.303959502904526f,
+ 0.304236484294000f, 0.304513156068825f, 0.304789518398959f,
+ 0.305065571454316f, 0.305341315404768f, 0.305616750420142f,
+ 0.305891876670227f, 0.306166694324763f, 0.306441203553453f,
+ 0.306715404525953f, 0.306989297411878f, 0.307262882380802f,
+ 0.307536159602252f, 0.307809129245716f, 0.308081791480638f,
+ 0.308354146476418f, 0.308626194402416f, 0.308897935427946f,
+ 0.309169369722281f, 0.309440497454651f, 0.309711318794243f,
+ 0.309981833910203f, 0.310252042971631f, 0.310521946147587f,
+ 0.310791543607086f, 0.311060835519102f, 0.311329822052565f,
+ 0.311598503376364f, 0.311866879659343f, 0.312134951070305f,
+ 0.312402717778008f, 0.312670179951171f, 0.312937337758465f,
+ 0.313204191368524f, 0.313470740949935f, 0.313736986671243f,
+ 0.314002928700952f, 0.314268567207521f, 0.314533902359368f,
+ 0.314798934324867f, 0.315063663272350f, 0.315328089370105f,
+ 0.315592212786379f, 0.315856033689375f, 0.316119552247253f,
+ 0.316382768628132f, 0.316645683000087f, 0.316908295531148f,
+ 0.317170606389307f, 0.317432615742509f, 0.317694323758658f,
+ 0.317955730605615f, 0.318216836451199f, 0.318477641463185f,
+ 0.318738145809305f, 0.318998349657250f, 0.319258253174666f,
+ 0.319517856529158f, 0.319777159888288f, 0.320036163419573f,
+ 0.320294867290491f, 0.320553271668473f, 0.320811376720911f,
+ 0.321069182615152f, 0.321326689518500f, 0.321583897598218f,
+ 0.321840807021525f, 0.322097417955597f, 0.322353730567567f,
+ 0.322609745024527f, 0.322865461493525f, 0.323120880141565f,
+ 0.323376001135609f, 0.323630824642579f, 0.319523622821772f,
+ 0.319777851855178f, 0.320031783902010f, 0.320285419129017f,
+ 0.320538757702904f, 0.320791799790335f, 0.321044545557929f,
+ 0.321296995172263f, 0.321549148799872f, 0.321801006607247f,
+ 0.322052568760837f, 0.322303835427048f, 0.322554806772243f,
+ 0.322805482962742f, 0.323055864164824f, 0.323305950544722f,
+ 0.323555742268629f, 0.323805239502694f, 0.324054442413022f,
+ 0.324303351165679f, 0.324551965926684f, 0.324800286862015f,
+ 0.325048314137607f, 0.325296047919353f, 0.325543488373102f,
+ 0.325790635664660f, 0.326037489959792f, 0.326284051424219f,
+ 0.326530320223619f, 0.326776296523626f, 0.327021980489835f,
+ 0.327267372287794f, 0.327512472083010f, 0.327757280040949f,
+ 0.328001796327030f, 0.328246021106633f, 0.328489954545092f,
+ 0.328733596807703f, 0.328976948059713f, 0.329220008466331f,
+ 0.329462778192721f, 0.329705257404004f, 0.329947446265259f,
+ 0.330189344941523f, 0.330430953597789f, 0.330672272399006f,
+ 0.330913301510083f, 0.331154041095883f, 0.331394491321230f,
+ 0.331634652350901f, 0.331874524349634f, 0.332114107482121f,
+ 0.332353401913014f, 0.332592407806920f, 0.332831125328403f,
+ 0.333069554641987f, 0.333307695912150f, 0.333545549303328f,
+ 0.333783114979916f, 0.334020393106265f, 0.334257383846681f,
+ 0.334494087365431f, 0.334730503826737f, 0.334966633394778f,
+ 0.335202476233691f, 0.335438032507570f, 0.335673302380465f,
+ 0.335908286016386f, 0.336142983579296f, 0.336377395233120f,
+ 0.336611521141736f, 0.336845361468981f, 0.337078916378650f,
+ 0.337312186034494f, 0.337545170600220f, 0.337777870239495f,
+ 0.338010285115941f, 0.338242415393138f, 0.338474261234623f,
+ 0.338705822803890f, 0.338937100264391f, 0.339168093779534f,
+ 0.339398803512685f, 0.339629229627166f, 0.339859372286258f,
+ 0.340089231653198f, 0.340318807891179f, 0.340548101163354f,
+ 0.340777111632832f, 0.341005839462677f, 0.341234284815913f,
+ 0.341462447855520f, 0.341690328744436f, 0.341917927645554f,
+ 0.342145244721727f, 0.342372280135763f, 0.342599034050427f,
+ 0.342825506628444f, 0.343051698032493f, 0.343277608425212f,
+ 0.343503237969194f, 0.343728586826993f, 0.343953655161116f,
+ 0.344178443134029f, 0.344402950908157f, 0.344627178645878f,
+ 0.344851126509531f, 0.345074794661410f, 0.345298183263766f,
+ 0.345521292478809f, 0.345744122468705f, 0.345966673395577f,
+ 0.346188945421505f, 0.346410938708527f, 0.346632653418637f,
+ 0.346854089713787f, 0.347075247755886f, 0.347296127706800f,
+ 0.347516729728352f, 0.347737053982323f, 0.347957100630451f,
+ 0.348176869834429f, 0.348396361755910f, 0.348615576556502f,
+ 0.348834514397771f, 0.349053175441242f, 0.349271559848394f,
+ 0.349489667780664f, 0.349707499399448f, 0.349925054866097f,
+ 0.350142334341920f, 0.350359337988183f, 0.350576065966110f,
+ 0.350792518436880f, 0.351008695561632f, 0.351224597501459f,
+ 0.351440224417413f, 0.351655576470505f, 0.351870653821698f,
+ 0.352085456631918f, 0.352299985062043f, 0.352514239272912f,
+ 0.352728219425319f, 0.352941925680015f, 0.353155358197710f,
+ 0.353368517139069f, 0.353581402664716f, 0.353794014935231f,
+ 0.354006354111151f, 0.354218420352971f, 0.354430213821142f,
+ 0.354641734676074f, 0.354852983078131f, 0.355063959187638f,
+ 0.355274663164873f, 0.355485095170075f, 0.355695255363438f,
+ 0.355905143905114f, 0.356114760955211f, 0.356324106673794f,
+ 0.356533181220887f, 0.356741984756471f, 0.356950517440481f,
+ 0.357158779432813f, 0.357366770893317f, 0.357574491981803f,
+ 0.357781942858036f, 0.357989123681738f, 0.358196034612590f,
+ 0.358402675810229f, 0.358609047434249f, 0.358815149644201f,
+ 0.359020982599593f, 0.359226546459892f, 0.359431841384519f,
+ 0.359636867532855f, 0.359841625064236f, 0.360046114137957f,
+ 0.360250334913268f, 0.360454287549378f, 0.360657972205452f,
+ 0.360861389040612f, 0.356702810206361f, 0.356905691876891f,
+ 0.357108306203617f, 0.357310653345491f, 0.357512733461420f,
+ 0.357714546710270f, 0.357916093250863f, 0.358117373241979f,
+ 0.358318386842353f, 0.358519134210680f, 0.358719615505611f,
+ 0.358919830885752f, 0.359119780509670f, 0.359319464535885f,
+ 0.359518883122878f, 0.359718036429085f, 0.359916924612898f,
+ 0.360115547832669f, 0.360313906246705f, 0.360512000013271f,
+ 0.360709829290588f, 0.360907394236835f, 0.361104695010150f,
+ 0.361301731768624f, 0.361498504670307f, 0.361695013873208f,
+ 0.361891259535291f, 0.362087241814476f, 0.362282960868644f,
+ 0.362478416855630f, 0.362673609933225f, 0.362868540259182f,
+ 0.363063207991205f, 0.363257613286961f, 0.363451756304069f,
+ 0.363645637200109f, 0.363839256132616f, 0.364032613259082f,
+ 0.364225708736957f, 0.364418542723648f, 0.364611115376518f,
+ 0.364803426852889f, 0.364995477310039f, 0.365187266905203f,
+ 0.365378795795572f, 0.365570064138297f, 0.365761072090484f,
+ 0.365951819809197f, 0.366142307451455f, 0.366332535174237f,
+ 0.366522503134478f, 0.366712211489069f, 0.366901660394860f,
+ 0.367090850008657f, 0.367279780487222f, 0.367468451987276f,
+ 0.367656864665497f, 0.367845018678518f, 0.368032914182932f,
+ 0.368220551335288f, 0.368407930292089f, 0.368595051209801f,
+ 0.368781914244842f, 0.368968519553590f, 0.369154867292378f,
+ 0.369340957617498f, 0.369526790685198f, 0.369712366651684f,
+ 0.369897685673117f, 0.370082747905618f, 0.370267553505262f,
+ 0.370452102628084f, 0.370636395430075f, 0.370820432067181f,
+ 0.371004212695309f, 0.371187737470320f, 0.371371006548033f,
+ 0.371554020084224f, 0.371736778234628f, 0.371919281154933f,
+ 0.372101529000787f, 0.372283521927796f, 0.372465260091519f,
+ 0.372646743647477f, 0.372827972751145f, 0.373008947557956f,
+ 0.373189668223299f, 0.373370134902522f, 0.373550347750928f,
+ 0.373730306923778f, 0.373910012576292f, 0.374089464863644f,
+ 0.374268663940966f, 0.374447609963348f, 0.374626303085837f,
+ 0.374804743463435f, 0.374982931251104f, 0.375160866603761f,
+ 0.375338549676281f, 0.375515980623497f, 0.375693159600195f,
+ 0.375870086761124f, 0.376046762260986f, 0.376223186254440f,
+ 0.376399358896105f, 0.376575280340554f, 0.376750950742319f,
+ 0.376926370255889f, 0.377101539035708f, 0.377276457236179f,
+ 0.377451125011662f, 0.377625542516473f, 0.377799709904887f,
+ 0.377973627331134f, 0.378147294949401f, 0.378320712913835f,
+ 0.378493881378536f, 0.378666800497564f, 0.378839470424936f,
+ 0.379011891314623f, 0.379184063320557f, 0.379355986596625f,
+ 0.379527661296671f, 0.379699087574496f, 0.379870265583860f,
+ 0.380041195478477f, 0.380211877412020f, 0.380382311538119f,
+ 0.380552498010361f, 0.380722436982289f, 0.380892128607405f,
+ 0.381061573039165f, 0.381230770430986f, 0.381399720936239f,
+ 0.381568424708253f, 0.381736881900314f, 0.381905092665666f,
+ 0.382073057157508f, 0.382240775528999f, 0.382408247933252f,
+ 0.382575474523339f, 0.382742455452288f, 0.382909190873084f,
+ 0.383075680938671f, 0.383241925801948f, 0.383407925615771f,
+ 0.383573680532955f, 0.383739190706270f, 0.383904456288443f,
+ 0.384069477432160f, 0.384234254290062f, 0.384398787014749f,
+ 0.384563075758777f, 0.384727120674658f, 0.384890921914863f,
+ 0.385054479631818f, 0.385217793977909f, 0.385380865105476f,
+ 0.385543693166817f, 0.385706278314188f, 0.385868620699801f,
+ 0.386030720475826f, 0.386192577794389f, 0.386354192807573f,
+ 0.386515565667420f, 0.386676696525926f, 0.386837585535046f,
+ 0.386998232846693f, 0.387158638612734f, 0.387318802984995f,
+ 0.387478726115260f, 0.387638408155268f, 0.383436121249137f,
+ 0.383595321563679f, 0.383754281242925f, 0.383913000438444f,
+ 0.384071479301760f, 0.384229717984357f, 0.384387716637672f,
+ 0.384545475413102f, 0.384702994462001f, 0.384860273935677f,
+ 0.385017313985400f, 0.385174114762392f, 0.385330676417835f,
+ 0.385486999102868f, 0.385643082968586f, 0.385798928166041f,
+ 0.385954534846243f, 0.386109903160157f, 0.386265033258709f,
+ 0.386419925292778f, 0.386574579413201f, 0.386728995770773f,
+ 0.386883174516247f, 0.387037115800330f, 0.387190819773689f,
+ 0.387344286586945f, 0.387497516390679f, 0.387650509335427f,
+ 0.387803265571684f, 0.387955785249900f, 0.388108068520482f,
+ 0.388260115533796f, 0.388411926440164f, 0.388563501389864f,
+ 0.388714840533132f, 0.388865944020162f, 0.389016812001104f,
+ 0.389167444626063f, 0.389317842045105f, 0.389468004408251f,
+ 0.389617931865478f, 0.389767624566722f, 0.389917082661874f,
+ 0.390066306300784f, 0.390215295633258f, 0.390364050809059f,
+ 0.390512571977908f, 0.390660859289481f, 0.390808912893412f,
+ 0.390956732939294f, 0.391104319576674f, 0.391251672955058f,
+ 0.391398793223907f, 0.391545680532642f, 0.391692335030638f,
+ 0.391838756867229f, 0.391984946191705f, 0.392130903153313f,
+ 0.392276627901259f, 0.392422120584702f, 0.392567381352763f,
+ 0.392712410354515f, 0.392857207738992f, 0.393001773655183f,
+ 0.393146108252035f, 0.393290211678450f, 0.393434084083290f,
+ 0.393577725615372f, 0.393721136423470f, 0.393864316656316f,
+ 0.394007266462598f, 0.389788257983385f, 0.389930747382434f,
+ 0.390073006800726f, 0.390215036386779f, 0.390356836289067f,
+ 0.390498406656018f, 0.390639747636022f, 0.390780859377423f,
+ 0.390921742028522f, 0.391062395737578f, 0.391202820652806f,
+ 0.391343016922379f, 0.391482984694427f, 0.391622724117036f,
+ 0.391762235338250f, 0.391901518506070f, 0.392040573768452f,
+ 0.392179401273312f, 0.392318001168520f, 0.392456373601907f,
+ 0.392594518721257f, 0.392732436674313f, 0.392870127608774f,
+ 0.393007591672297f, 0.393144829012496f, 0.393281839776942f,
+ 0.393418624113161f, 0.393555182168638f, 0.393691514090816f,
+ 0.393827620027092f, 0.393963500124822f, 0.394099154531318f,
+ 0.394234583393851f, 0.394369786859647f, 0.394504765075889f,
+ 0.394639518189717f, 0.394774046348230f, 0.394908349698482f,
+ 0.395042428387484f, 0.395176282562205f, 0.395309912369570f,
+ 0.395443317956462f, 0.395576499469721f, 0.395709457056142f,
+ 0.395842190862479f, 0.395974701035442f, 0.396106987721700f,
+ 0.396239051067876f, 0.396370891220552f, 0.396502508326267f,
+ 0.396633902531515f, 0.396765073982748f, 0.396896022826377f,
+ 0.397026749208768f, 0.397157253276243f, 0.392925807167507f,
+ 0.393055867043950f, 0.393185705044190f, 0.393315321314378f,
+ 0.393444716000622f, 0.393573889248988f, 0.393702841205497f,
+ 0.393831572016130f, 0.393960081826821f, 0.394088370783464f,
+ 0.394216439031910f, 0.394344286717965f, 0.394471913987393f,
+ 0.394599320985916f, 0.394726507859211f, 0.394853474752914f,
+ 0.394980221812616f, 0.395106749183867f, 0.395233057012172f,
+ 0.395359145442995f, 0.395485014621754f, 0.395610664693828f,
+ 0.395736095804550f, 0.395861308099210f, 0.395986301723057f,
+ 0.396111076821296f, 0.396235633539087f, 0.396359972021550f,
+ 0.396484092413761f, 0.396607994860752f, 0.396731679507512f,
+ 0.396855146498989f, 0.396978395980086f, 0.397101428095663f,
+ 0.397224242990538f, 0.397346840809486f, 0.397469221697237f,
+ 0.397591385798481f, 0.397713333257862f, 0.397835064219984f,
+ 0.397956578829405f, 0.398077877230641f, 0.398198959568167f,
+ 0.398319825986412f, 0.398440476629763f, 0.398560911642564f,
+ 0.398681131169117f, 0.398801135353680f, 0.398920924340467f,
+ 0.394678770266074f, 0.394798129289784f, 0.394917273548105f,
+ 0.395036203185081f, 0.395154918344712f, 0.395273419170954f,
+ 0.395391705807720f, 0.395509778398882f, 0.395627637088268f,
+ 0.395745282019662f, 0.395862713336806f, 0.395979931183398f,
+ 0.396096935703093f, 0.396213727039505f, 0.396330305336203f,
+ 0.396446670736713f, 0.396562823384518f, 0.396678763423060f,
+ 0.396794490995734f, 0.396910006245896f, 0.397025309316857f,
+ 0.397140400351884f, 0.397255279494203f, 0.397369946886996f,
+ 0.397484402673401f, 0.397598646996516f, 0.397712679999392f,
+ 0.397826501825040f, 0.397940112616427f, 0.398053512516475f,
+ 0.398166701668066f, 0.398279680214038f, 0.398392448297186f,
+ 0.398505006060259f, 0.398617353645969f, 0.398729491196979f,
+ 0.398841418855912f, 0.398953136765347f, 0.399064645067821f,
+ 0.399175943905828f, 0.399287033421816f, 0.399397913758195f,
+ 0.399508585057326f, 0.399619047461532f, 0.399729301113091f,
+ 0.395477618146659f, 0.395587454719585f, 0.395697082966438f,
+ 0.395806503029326f, 0.395915715050310f, 0.396024719171410f,
+ 0.396133515534604f, 0.396242104281823f, 0.396350485554960f,
+ 0.396458659495860f, 0.396566626246330f, 0.396674385948129f,
+ 0.396781938742976f, 0.396889284772547f, 0.396996424178473f,
+ 0.397103357102343f, 0.397210083685704f, 0.397316604070058f,
+ 0.397422918396866f, 0.397529026807543f, 0.397634929443464f,
+ 0.397740626445960f, 0.397846117956317f, 0.397951404115781f,
+ 0.398056485065553f, 0.398161360946792f, 0.398266031900612f,
+ 0.398370498068087f, 0.398474759590244f, 0.398578816608071f,
+ 0.398682669262511f, 0.398786317694462f, 0.398889762044784f,
+ 0.398993002454288f, 0.399096039063747f, 0.399198872013887f,
+ 0.399301501445394f, 0.399403927498908f, 0.399506150315030f,
+ 0.399608170034313f, 0.399709986797270f, 0.399811600744371f,
+ 0.395551284008465f, 0.395652492745088f, 0.395753499087005f,
+ 0.395854303174512f, 0.395954905147863f, 0.396055305147269f,
+ 0.396155503312898f, 0.396255499784873f, 0.396355294703278f,
+ 0.396454888208150f, 0.396554280439485f, 0.396653471537236f,
+ 0.396752461641311f, 0.396851250891577f, 0.396949839427857f,
+ 0.397048227389931f, 0.397146414917536f, 0.397244402150366f,
+ 0.397342189228072f, 0.397439776290262f, 0.397537163476500f,
+ 0.397634350926308f, 0.397731338779165f, 0.397828127174505f,
+ 0.397924716251721f, 0.398021106150163f, 0.398117297009136f,
+ 0.398213288967904f, 0.398309082165687f, 0.398404676741662f,
+ 0.398500072834962f, 0.398595270584678f, 0.398690270129858f,
+ 0.398785071609507f, 0.398879675162585f, 0.398974080928012f,
+ 0.399068289044663f, 0.399162299651370f, 0.399256112886922f,
+ 0.399349728890064f, 0.399443147799501f, 0.395174641746314f,
+ 0.395267666884276f, 0.395360495344382f, 0.395453127265163f,
+ 0.395545562785107f, 0.395637802042658f, 0.395729845176217f,
+ 0.395821692324142f, 0.395913343624749f, 0.396004799216310f,
+ 0.396096059237054f, 0.396187123825166f, 0.396277993118789f,
+ 0.396368667256023f, 0.396459146374925f, 0.396549430613508f,
+ 0.396639520109742f, 0.396729415001555f, 0.396819115426830f,
+ 0.396908621523410f, 0.396997933429091f, 0.397087051281630f,
+ 0.397175975218736f, 0.397264705378080f, 0.397353241897287f,
+ 0.397441584913940f, 0.397529734565577f, 0.397617690989695f,
+ 0.397705454323747f, 0.397793024705144f, 0.397880402271252f,
+ 0.397967587159395f, 0.398054579506854f, 0.398141379450867f,
+ 0.398227987128627f, 0.398314402677288f, 0.398400626233956f,
+ 0.398486657935698f, 0.398572497919536f, 0.398658146322447f,
+ 0.394381875273792f, 0.394467140925618f, 0.394552215407196f,
+ 0.394637098855334f, 0.394721791406795f, 0.394806293198300f,
+ 0.394890604366525f, 0.394974725048106f, 0.395058655379632f,
+ 0.395142395497653f, 0.395225945538672f, 0.395309305639152f,
+ 0.395392475935511f, 0.395475456564125f, 0.395558247661327f,
+ 0.395640849363404f, 0.395723261806605f, 0.395805485127131f,
+ 0.395887519461143f, 0.395969364944757f, 0.396051021714048f,
+ 0.396132489905045f, 0.396213769653737f, 0.396294861096067f,
+ 0.396375764367938f, 0.396456479605206f, 0.396537006943688f,
+ 0.396617346519155f, 0.396697498467336f, 0.396777462923917f,
+ 0.396857240024539f, 0.396936829904804f, 0.397016232700266f,
+ 0.397095448546439f, 0.397174477578793f, 0.397253319932756f,
+ 0.397331975743711f, 0.397410445146998f, 0.397488728277915f,
+ 0.397566825271718f, 0.393283008256039f, 0.393360733381202f,
+ 0.393438272774754f, 0.393515626571778f, 0.393592794907312f,
+ 0.393669777916352f, 0.393746575733851f, 0.393823188494718f,
+ 0.393899616333820f, 0.393975859385979f, 0.394051917785976f,
+ 0.394127791668548f, 0.394203481168389f, 0.394278986420149f,
+ 0.394354307558436f, 0.394429444717814f, 0.394504398032805f,
+ 0.394579167637888f, 0.394653753667496f, 0.394728156256022f,
+ 0.394802375537816f, 0.394876411647182f, 0.394950264718382f,
+ 0.395023934885638f, 0.395097422283124f, 0.395170727044974f,
+ 0.395243849305278f, 0.395316789198083f, 0.395389546857393f,
+ 0.395462122417168f, 0.395534516011326f, 0.395606727773741f,
+ 0.395678757838244f, 0.395750606338623f, 0.395822273408624f,
+ 0.395893759181948f, 0.395965063792254f, 0.396036187373157f,
+ 0.396107130058230f, 0.396177891981003f, 0.396248473274960f,
+ 0.391957146065968f, 0.392027366502581f, 0.392097406710579f,
+ 0.392167266823275f, 0.392236946973940f, 0.392306447295801f,
+ 0.392375767922042f, 0.392444908985804f, 0.392513870620185f,
+ 0.392582652958240f, 0.392651256132980f, 0.392719680277373f,
+ 0.392787925524346f, 0.392855992006779f, 0.392923879857513f,
+ 0.392991589209342f, 0.393059120195020f, 0.393126472947256f,
+ 0.393193647598717f, 0.393260644282026f, 0.393327463129763f,
+ 0.393394104274464f, 0.393460567848624f, 0.393526853984694f,
+ 0.393592962815081f, 0.393658894472149f, 0.393724649088219f,
+ 0.393790226795571f, 0.393855627726437f, 0.393920852013011f,
+ 0.393985899787441f, 0.394050771181833f, 0.394115466328248f,
+ 0.394179985358706f, 0.394244328405183f, 0.394308495599612f,
+ 0.394372487073883f, 0.394436302959841f, 0.394499943389291f,
+ 0.394563408493992f, 0.394626698405663f, 0.390328085248398f,
+ 0.390391025168985f, 0.390453790291433f, 0.390516380747287f,
+ 0.390578796668047f, 0.390641038185172f, 0.390703105430078f,
+ 0.390764998534136f, 0.390826717628674f, 0.390888262844978f,
+ 0.390949634314291f, 0.391010832167811f, 0.391071856536696f,
+ 0.391132707552056f, 0.391193385344964f, 0.391253890046444f,
+ 0.391314221787480f, 0.391374380699013f, 0.391434366911939f,
+ 0.391494180557114f, 0.391553821765346f, 0.391613290667404f,
+ 0.391672587394012f, 0.391731712075852f, 0.391790664843562f,
+ 0.391849445827736f, 0.391908055158926f, 0.391966492967641f,
+ 0.392024759384347f, 0.392082854539465f, 0.392140778563375f,
+ 0.392198531586412f, 0.392256113738870f, 0.392313525150997f,
+ 0.392370765953001f, 0.392427836275045f, 0.392484736247248f,
+ 0.392541465999688f, 0.392598025662398f, 0.392654415365369f,
+ 0.392710635238548f, 0.392766685411840f, 0.392822566015106f,
+ 0.392878277178163f, 0.388572091023208f, 0.388627463695129f,
+ 0.388682667316036f, 0.388737702015574f, 0.388792567923345f,
+ 0.388847265168909f, 0.388901793881780f, 0.388956154191431f,
+ 0.389010346227292f, 0.389064370118749f, 0.389118225995145f,
+ 0.389171913985779f, 0.389225434219908f, 0.389278786826745f,
+ 0.389331971935462f, 0.389384989675184f, 0.389437840174996f,
+ 0.389490523563938f, 0.389543039971008f, 0.389595389525160f,
+ 0.389647572355306f, 0.389699588590314f, 0.389751438359007f,
+ 0.389803121790169f, 0.389854639012537f, 0.389905990154806f,
+ 0.389957175345630f, 0.390008194713615f, 0.390059048387330f,
+ 0.390109736495295f, 0.390160259165990f, 0.390210616527851f,
+ 0.390260808709272f, 0.390310835838602f, 0.390360698044147f,
+ 0.390410395454172f, 0.390459928196896f, 0.390509296400497f,
+ 0.390558500193108f, 0.390607539702819f, 0.390656415057679f,
+ 0.390705126385692f, 0.390753673814819f, 0.390802057472977f,
+ 0.390850277488041f, 0.390898333987844f, 0.390946227100173f,
+ 0.390993956952773f, 0.386679795665769f, 0.386727199381975f,
+ 0.386774440221429f, 0.386821518311702f, 0.386868433780325f,
+ 0.386915186754783f, 0.386961777362520f, 0.387008205730934f,
+ 0.387054471987382f, 0.387100576259178f, 0.387146518673590f,
+ 0.387192299357847f, 0.387237918439132f, 0.387283376044585f,
+ 0.387328672301304f, 0.387373807336342f, 0.387418781276710f,
+ 0.387463594249377f, 0.387508246381265f, 0.387552737799258f,
+ 0.387597068630192f, 0.387641239000863f, 0.387685249038022f,
+ 0.387729098868378f, 0.387772788618595f, 0.387816318415297f,
+ 0.387859688385061f, 0.387902898654424f, 0.387945949349877f,
+ 0.387988840597871f, 0.388031572524811f, 0.388074145257060f,
+ 0.388116558920937f, 0.388158813642719f, 0.388200909548640f,
+ 0.388242846764889f, 0.388284625417613f, 0.388326245632916f,
+ 0.388367707536857f, 0.388409011255455f, 0.388450156914683f,
+ 0.388491144640472f, 0.388531974558710f, 0.388572646795240f,
+ 0.388613161475865f, 0.388653518726341f, 0.388693718672384f,
+ 0.388733761439666f, 0.388773647153814f, 0.388813375940413f,
+ 0.388852947925006f, 0.388892363233092f, 0.388931621990125f,
+ 0.384608996313940f, 0.384647942345062f, 0.384686732201239f,
+ 0.384725366007753f, 0.384763843889844f, 0.384802165972708f,
+ 0.384840332381498f, 0.384878343241323f, 0.384916198677251f,
+ 0.384953898814305f, 0.384991443777464f, 0.385028833691666f,
+ 0.385066068681804f, 0.385103148872729f, 0.385140074389248f,
+ 0.385176845356125f, 0.385213461898081f, 0.385249924139793f,
+ 0.385286232205896f, 0.385322386220981f, 0.385358386309596f,
+ 0.385394232596246f, 0.385429925205392f, 0.385465464261452f,
+ 0.385500849888801f, 0.385536082211772f, 0.385571161354653f,
+ 0.385606087441689f, 0.385640860597082f, 0.385675480944992f,
+ 0.385709948609534f, 0.385744263714780f, 0.385778426384760f,
+ 0.385812436743460f, 0.385846294914823f, 0.385880001022748f,
+ 0.385913555191092f, 0.385946957543667f, 0.385980208204245f,
+ 0.386013307296550f, 0.386046254944268f, 0.386079051271037f,
+ 0.386111696400456f, 0.386144190456078f, 0.386176533561413f,
+ 0.386208725839929f, 0.386240767415049f, 0.386272658410155f,
+ 0.386304398948585f, 0.386335989153633f, 0.386367429148549f,
+ 0.386398719056542f, 0.386429859000777f, 0.386460849104374f,
+ 0.386491689490413f, 0.386522380281929f, 0.386552921601912f,
+ 0.386583313573312f, 0.386613556319033f, 0.386643649961939f,
+ 0.386673594624847f, 0.386703390430534f, 0.386733037501732f,
+ 0.386762535961129f, 0.382430157923795f, 0.382459359527486f,
+ 0.382488412887186f, 0.382517318125409f, 0.382546075364630f,
+ 0.382574684727277f, 0.382603146335737f, 0.382631460312354f,
+ 0.382659626779427f, 0.382687645859213f, 0.382715517673926f,
+ 0.382743242345736f, 0.382770819996769f, 0.382798250749110f,
+ 0.382825534724800f, 0.382852672045835f, 0.382879662834169f,
+ 0.382906507211714f, 0.382933205300338f, 0.382959757221863f,
+ 0.382986163098072f, 0.383012423050702f, 0.383038537201448f,
+ 0.383064505671961f, 0.383090328583849f, 0.383116006058678f,
+ 0.383141538217968f, 0.383166925183199f, 0.383192167075804f,
+ 0.383217264017177f, 0.383242216128666f, 0.383267023531576f,
+ 0.383291686347169f, 0.383316204696664f, 0.383340578701237f,
+ 0.383364808482021f, 0.383388894160103f, 0.383412835856531f,
+ 0.383436633692307f, 0.383460287788389f, 0.383483798265695f,
+ 0.383507165245098f, 0.383530388847426f, 0.383553469193466f,
+ 0.383576406403962f, 0.383599200599613f, 0.383621851901075f,
+ 0.383644360428963f, 0.383666726303846f, 0.383688949646252f,
+ 0.383711030576663f, 0.383732969215520f, 0.383754765683220f,
+ 0.383776420100117f, 0.383797932586521f, 0.383819303262701f,
+ 0.383840532248879f, 0.383861619665237f, 0.383882565631912f,
+ 0.383903370268999f, 0.383924033696548f, 0.383944556034568f,
+ 0.383964937403022f, 0.383985177921832f, 0.384005277710877f,
+ 0.384025236889990f, 0.384045055578963f, 0.384064733897545f,
+ 0.384084271965440f, 0.384103669902310f, 0.384122927827773f,
+ 0.384142045861405f, 0.384161024122738f, 0.384179862731259f,
+ 0.384198561806415f, 0.384217121467608f, 0.384235541834196f,
+ 0.384253823025494f, 0.384271965160776f, 0.384289968359270f,
+ 0.384307832740163f, 0.384325558422595f, 0.384343145525668f,
+ 0.384360594168436f, 0.384377904469912f, 0.384395076549067f,
+ 0.384412110524825f, 0.384429006516070f, 0.384445764641642f,
+ 0.384462385020336f, 0.384478867770907f, 0.384495213012063f,
+ 0.384511420862471f, 0.384527491440755f, 0.384543424865495f,
+ 0.384559221255226f, 0.380213152720866f, 0.380228675396019f,
+ 0.380244061391516f, 0.380259310825718f, 0.380274423816947f,
+ 0.380289400483481f, 0.380304240943551f, 0.380318945315350f,
+ 0.380333513717025f, 0.380347946266679f, 0.380362243082373f,
+ 0.380376404282125f, 0.380390429983908f, 0.380404320305654f,
+ 0.380418075365251f, 0.380431695280542f, 0.380445180169328f,
+ 0.380458530149368f, 0.380471745338376f, 0.380484825854023f,
+ 0.380497771813937f, 0.380510583335702f, 0.380523260536860f,
+ 0.380535803534910f, 0.380548212447305f, 0.380560487391458f,
+ 0.380572628484737f, 0.380584635844466f, 0.380596509587927f,
+ 0.380608249832359f, 0.380619856694957f, 0.380631330292873f,
+ 0.380642670743215f, 0.380653878163048f, 0.380664952669394f,
+ 0.380675894379233f, 0.380686703409499f, 0.380697379877085f,
+ 0.380707923898839f, 0.380718335591567f, 0.380728615072032f,
+ 0.380738762456952f, 0.380748777863002f, 0.380758661406816f,
+ 0.380768413204982f, 0.380778033374047f, 0.380787522030512f,
+ 0.380796879290837f, 0.380806105271438f, 0.380815200088688f,
+ 0.380824163858915f, 0.380832996698407f, 0.380841698723405f,
+ 0.380850270050110f, 0.380858710794677f, 0.380867021073220f,
+ 0.380875201001808f, 0.380883250696466f, 0.380891170273180f,
+ 0.380898959847887f, 0.380906619536485f, 0.380914149454827f,
+ 0.380921549718722f, 0.380928820443937f, 0.380935961746195f,
+ 0.380942973741177f, 0.380949856544519f, 0.380956610271814f,
+ 0.380963235038613f, 0.380969730960421f, 0.380976098152703f,
+ 0.380982336730880f, 0.380988446810326f, 0.380994428506377f,
+ 0.381000281934323f, 0.381006007209410f, 0.381011604446843f,
+ 0.381017073761781f, 0.381022415269341f, 0.381027629084598f,
+ 0.381032715322582f, 0.381037674098280f, 0.381042505526636f,
+ 0.381047209722551f, 0.381051786800881f, 0.381056236876441f,
+ 0.381060560064002f, 0.381064756478290f, 0.381068826233990f,
+ 0.381072769445743f, 0.381076586228145f, 0.381080276695752f,
+ 0.381083840963073f, 0.381087279144577f, 0.381090591354688f,
+ 0.381093777707787f, 0.381096838318210f, 0.381099773300253f,
+ 0.381102582768166f, 0.381105266836158f, 0.381107825618392f,
+ 0.381110259228989f, 0.381112567782028f, 0.381114751391543f,
+ 0.381116810171524f, 0.381118744235920f, 0.381120553698635f,
+ 0.381122238673531f, 0.381123799274425f, 0.381125235615091f,
+ 0.381126547809262f, 0.381127735970624f, 0.381128800212824f,
+ 0.381129740649461f, 0.381130557394094f, 0.381131250560238f,
+ 0.381131820261363f, 0.381132266610899f, 0.381132589722230f,
+ 0.381132789708696f, 0.381132866683598f, 0.381132820760188f,
+ 0.381132652051679f, 0.381132360671238f, 0.381131946731992f,
+ 0.381131410347020f, 0.381130751629362f, 0.381129970692011f,
+ 0.381129067647921f, 0.381128042609999f, 0.381126895691109f,
+ 0.381125627004075f, 0.381124236661673f, 0.381122724776639f,
+ 0.381121091461664f, 0.381119336829397f, 0.381117460992443f,
+ 0.381115464063363f, 0.381113346154677f, 0.381111107378858f,
+ 0.381108747848338f, 0.381106267675507f, 0.381103666972709f,
+ 0.381100945852245f, 0.381098104426374f, 0.381095142807312f,
+ 0.381092061107230f, 0.381088859438256f, 0.381085537912476f,
+ 0.381082096641931f, 0.381078535738620f, 0.381074855314498f,
+ 0.381071055481477f, 0.381067136351425f, 0.381063098036167f,
+ 0.381058940647486f, 0.381054664297119f, 0.381050269096762f,
+ 0.381045755158066f, 0.381041122592641f, 0.381036371512051f,
+ 0.381031502027818f, 0.381026514251421f, 0.381021408294295f,
+ 0.381016184267832f, 0.381010842283379f, 0.381005382452243f,
+ 0.380999804885685f, 0.380994109694924f, 0.380988296991135f,
+ 0.380982366885450f, 0.380976319488957f, 0.380970154912701f,
+ 0.380963873267684f, 0.380957474664866f, 0.380950959215160f,
+ 0.380944327029439f, 0.380937578218531f, 0.380930712893222f,
+ 0.380923731164253f, 0.380916633142322f, 0.380909418938086f,
+ 0.380902088662155f, 0.380894642425098f, 0.380887080337441f,
+ 0.380879402509665f, 0.380871609052208f, 0.380863700075466f,
+ 0.380855675689790f, 0.380847536005489f, 0.380839281132828f,
+ 0.380830911182028f, 0.380822426263269f, 0.380813826486684f,
+ 0.380805111962367f, 0.380796282800365f, 0.380787339110683f,
+ 0.380778281003283f, 0.380769108588083f, 0.380759821974958f,
+ 0.380750421273741f, 0.380740906594218f, 0.380731278046136f,
+ 0.380721535739195f, 0.380711679783055f, 0.380701710287330f,
+ 0.380691627361591f, 0.380681431115367f, 0.380671121658143f,
+ 0.380660699099360f, 0.380650163548417f, 0.376277787107090f,
+ 0.376267025899846f, 0.376256152028377f, 0.376245165601906f,
+ 0.376234066729615f, 0.376222855520642f, 0.376211532084083f,
+ 0.376200096528988f, 0.376188548964365f, 0.376176889499179f,
+ 0.376165118242352f, 0.376153235302761f, 0.376141240789241f,
+ 0.376129134810584f, 0.376116917475536f, 0.376104588892804f,
+ 0.376092149171047f, 0.376079598418884f, 0.376066936744890f,
+ 0.376054164257595f, 0.376041281065488f, 0.376028287277012f,
+ 0.376015183000569f, 0.376001968344516f, 0.375988643417169f,
+ 0.375975208326797f, 0.375961663181629f, 0.375948008089849f,
+ 0.375934243159598f, 0.375920368498973f, 0.375906384216028f,
+ 0.375892290418775f, 0.375878087215181f, 0.375863774713170f,
+ 0.375849353020623f, 0.375834822245377f, 0.375820182495227f,
+ 0.375805433877922f, 0.375790576501171f, 0.375775610472637f,
+ 0.375760535899941f, 0.375745352890661f, 0.375730061552329f,
+ 0.375714661992437f, 0.375699154318431f, 0.375683538637716f,
+ 0.375667815057652f, 0.375651983685556f, 0.375636044628702f,
+ 0.375619997994319f, 0.375603843889596f, 0.375587582421675f,
+ 0.375571213697657f, 0.375554737824598f, 0.375538154909513f,
+ 0.375521465059370f, 0.375504668381098f, 0.375487764981579f,
+ 0.375470754967654f, 0.375453638446118f, 0.375436415523726f,
+ 0.375419086307187f, 0.375401650903168f, 0.375384109418291f,
+ 0.375366461959138f, 0.375348708632243f, 0.375330849544101f,
+ 0.375312884801161f, 0.375294814509829f, 0.370914910768890f,
+ 0.370896629699820f, 0.370878243401316f, 0.370859751979612f,
+ 0.370841155540898f, 0.370822454191318f, 0.370803648036976f,
+ 0.370784737183932f, 0.370765721738200f, 0.370746601805755f,
+ 0.370727377492524f, 0.370708048904394f, 0.370688616147207f,
+ 0.370669079326762f, 0.370649438548815f, 0.370629693919078f,
+ 0.370609845543221f, 0.370589893526868f, 0.370569837975601f,
+ 0.370549678994961f, 0.370529416690441f, 0.370509051167494f,
+ 0.370488582531529f, 0.370468010887911f, 0.370447336341962f,
+ 0.370426558998959f, 0.370405678964140f, 0.370384696342694f,
+ 0.370363611239771f, 0.370342423760476f, 0.370321134009869f,
+ 0.370299742092970f, 0.370278248114753f, 0.370256652180149f,
+ 0.370234954394047f, 0.370213154861292f, 0.370191253686683f,
+ 0.370169250974980f, 0.370147146830898f, 0.370124941359106f,
+ 0.370102634664233f, 0.370080226850863f, 0.370057718023537f,
+ 0.370035108286753f, 0.370012397744965f, 0.369989586502583f,
+ 0.369966674663976f, 0.369943662333467f, 0.369920549615336f,
+ 0.369897336613821f, 0.369874023433116f, 0.369850610177372f,
+ 0.365465368943117f, 0.365441755849571f, 0.365418042993176f,
+ 0.365394230477909f, 0.365370318407704f, 0.365346306886452f,
+ 0.365322196017997f, 0.365297985906144f, 0.365273676654654f,
+ 0.365249268367241f, 0.365224761147580f, 0.365200155099300f,
+ 0.365175450325988f, 0.365150646931187f, 0.365125745018395f,
+ 0.365100744691070f, 0.365075646052624f, 0.365050449206426f,
+ 0.365025154255803f, 0.364999761304037f, 0.364974270454366f,
+ 0.364948681809988f, 0.364922995474054f, 0.364897211549674f,
+ 0.364871330139912f, 0.364845351347791f, 0.364819275276291f,
+ 0.364793102028345f, 0.364766831706847f, 0.364740464414645f,
+ 0.364714000254544f, 0.364687439329305f, 0.364660781741648f,
+ 0.364634027594247f, 0.364607176989734f, 0.364580230030696f,
+ 0.364553186819680f, 0.364526047459185f, 0.364498812051671f,
+ 0.364471480699551f, 0.364444053505197f, 0.364416530570936f,
+ 0.364388911999053f, 0.364361197891790f, 0.359971660343764f,
+ 0.359943755472287f, 0.359915755371891f, 0.359887660144644f,
+ 0.359859469892569f, 0.359831184717647f, 0.359802804721815f,
+ 0.359774330006967f, 0.359745760674952f, 0.359717096827579f,
+ 0.359688338566610f, 0.359659485993765f, 0.359630539210721f,
+ 0.359601498319112f, 0.359572363420526f, 0.359543134616511f,
+ 0.359513812008569f, 0.359484395698161f, 0.359454885786701f,
+ 0.359425282375564f, 0.359395585566078f, 0.359365795459529f,
+ 0.359335912157159f, 0.359305935760169f, 0.359275866369713f,
+ 0.359245704086904f, 0.359215449012811f, 0.359185101248459f,
+ 0.359154660894830f, 0.359124128052863f, 0.359093502823453f,
+ 0.359062785307452f, 0.359031975605668f, 0.359001073818866f,
+ 0.358970080047767f, 0.358938994393051f, 0.358907816955351f,
+ 0.358876547835258f, 0.358845187133321f, 0.354452006942467f,
+ 0.354420463378311f, 0.354388828533694f, 0.354357102508990f,
+ 0.354325285404530f, 0.354293377320600f, 0.354261378357445f,
+ 0.354229288615266f, 0.354197108194219f, 0.354164837194419f,
+ 0.354132475715934f, 0.354100023858793f, 0.354067481722978f,
+ 0.354034849408430f, 0.354002127015045f, 0.353969314642676f,
+ 0.353936412391133f, 0.353903420360182f, 0.353870338649546f,
+ 0.353837167358905f, 0.353803906587893f, 0.353770556436105f,
+ 0.353737117003089f, 0.353703588388350f, 0.353669970691352f,
+ 0.353636264011513f, 0.353602468448208f, 0.353568584100769f,
+ 0.353534611068485f, 0.353500549450601f, 0.353466399346319f,
+ 0.353432160854798f, 0.353397834075151f, 0.353363419106450f,
+ 0.353328916047724f, 0.353294324997957f, 0.353259646056089f,
+ 0.348863151313442f, 0.348828296884025f, 0.348793354859070f,
+ 0.348758325337345f, 0.348723208417575f, 0.348688004198440f,
+ 0.348652712778576f, 0.348617334256578f, 0.348581868730996f,
+ 0.348546316300336f, 0.348510677063062f, 0.348474951117594f,
+ 0.348439138562308f, 0.348403239495538f, 0.348367254015573f,
+ 0.348331182220659f, 0.348295024208999f, 0.348258780078753f,
+ 0.348222449928035f, 0.348186033854919f, 0.348149531957434f,
+ 0.348112944333565f, 0.348076271081254f, 0.348039512298401f,
+ 0.348002668082859f, 0.347965738532442f, 0.347928723744916f,
+ 0.347891623818009f, 0.347854438849400f, 0.347817168936728f,
+ 0.347779814177587f, 0.347742374669529f, 0.347704850510061f,
+ 0.347667241796648f, 0.343267820619132f, 0.343230043090047f,
+ 0.343192181299149f, 0.343154235343728f, 0.343116205321032f,
+ 0.343078091328263f, 0.343039893462582f, 0.343001611821106f,
+ 0.342963246500909f, 0.342924797599019f, 0.342886265212423f,
+ 0.342847649438065f, 0.342808950372843f, 0.342770168113615f,
+ 0.342731302757191f, 0.342692354400342f, 0.342653323139794f,
+ 0.342614209072227f, 0.342575012294282f, 0.342535732902554f,
+ 0.342496370993594f, 0.342456926663912f, 0.342417400009971f,
+ 0.342377791128193f, 0.342338100114958f, 0.342298327066598f,
+ 0.342258472079406f, 0.342218535249630f, 0.342178516673473f,
+ 0.342138416447096f, 0.342098234666617f, 0.342057971428110f,
+ 0.342017626827605f, 0.337615472953512f, 0.337574965916929f,
+ 0.337534377806179f, 0.337493708717118f, 0.337452958745561f,
+ 0.337412127987276f, 0.337371216537989f, 0.337330224493385f,
+ 0.337289151949102f, 0.337247999000736f, 0.337206765743839f,
+ 0.337165452273921f, 0.337124058686446f, 0.337082585076838f,
+ 0.337041031540475f, 0.336999398172692f, 0.336957685068781f,
+ 0.336915892323990f, 0.336874020033523f, 0.336832068292543f,
+ 0.336790037196167f, 0.336747926839469f, 0.336705737317481f,
+ 0.336663468725190f, 0.336621121157539f, 0.336578694709430f,
+ 0.336536189475720f, 0.336493605551223f, 0.336450943030708f,
+ 0.336408202008902f, 0.336365382580488f, 0.336322484840108f,
+ 0.336279508882355f, 0.331874726794207f, 0.331831594685327f,
+ 0.331788384642604f, 0.331745096760461f, 0.331701731133276f,
+ 0.331658287855384f, 0.331614767021079f, 0.331571168724609f,
+ 0.331527493060178f, 0.331483740121949f, 0.331439910004039f,
+ 0.331396002800524f, 0.331352018605435f, 0.331307957512759f,
+ 0.331263819616440f, 0.331219605010381f, 0.331175313788438f,
+ 0.331130946044424f, 0.331086501872111f, 0.331041981365225f,
+ 0.330997384617451f, 0.330952711722427f, 0.330907962773751f,
+ 0.330863137864976f, 0.330818237089610f, 0.330773260541122f,
+ 0.330728208312932f, 0.330683080498421f, 0.330637877190924f,
+ 0.330592598483733f, 0.330547244470097f, 0.330501815243221f,
+ 0.326094582888691f, 0.326049003514778f, 0.326003349206981f,
+ 0.325957620058331f, 0.325911816161815f, 0.325865937610379f,
+ 0.325819984496923f, 0.325773956914305f, 0.325727854955339f,
+ 0.325681678712794f, 0.325635428279400f, 0.325589103747838f,
+ 0.325542705210749f, 0.325496232760730f, 0.325449686490334f,
+ 0.325403066492070f, 0.325356372858405f, 0.325309605681762f,
+ 0.325262765054519f, 0.325215851069012f, 0.325168863817535f,
+ 0.325121803392334f, 0.325074669885617f, 0.325027463389544f,
+ 0.324980183996233f, 0.324932831797761f, 0.324885406886157f,
+ 0.324837909353411f, 0.324790339291466f, 0.324742696792224f,
+ 0.324694981947541f, 0.320285466841654f, 0.320237607581489f,
+ 0.320189676251195f, 0.320141672942456f, 0.320093597746911f,
+ 0.320045450756158f, 0.319997232061749f, 0.319948941755193f,
+ 0.319900579927957f, 0.319852146671464f, 0.319803642077092f,
+ 0.319755066236177f, 0.319706419240011f, 0.319657701179843f,
+ 0.319608912146878f, 0.319560052232277f, 0.319511121527159f,
+ 0.319462120122598f, 0.319413048109625f, 0.319363905579229f,
+ 0.319314692622353f, 0.319265409329898f, 0.319216055792721f,
+ 0.319166632101636f, 0.319117138347413f, 0.319067574620779f,
+ 0.319017941012417f, 0.318968237612967f, 0.318918464513024f,
+ 0.318868621803143f, 0.318818709573831f, 0.318768727915555f,
+ 0.314356948911160f, 0.314306828666179f, 0.314256639263369f,
+ 0.314206380793024f, 0.314156053345391f, 0.314105657010674f,
+ 0.314055191879036f, 0.314004658040593f, 0.313954055585421f,
+ 0.313903384603549f, 0.313852645184966f, 0.313801837419615f,
+ 0.313750961397396f, 0.313700017208166f, 0.313649004941739f,
+ 0.313597924687883f, 0.313546776536326f, 0.313495560576751f,
+ 0.313444276898796f, 0.313392925592057f, 0.313341506746087f,
+ 0.313290020450394f, 0.313238466794443f, 0.313186845867658f,
+ 0.313135157759415f, 0.313083402559049f, 0.313031580355852f,
+ 0.312979691239072f, 0.312927735297912f, 0.312875712621533f,
+ 0.312823623299054f, 0.312771467419547f, 0.308357517064465f,
+ 0.308305228337950f, 0.308252873321368f, 0.308200452103618f,
+ 0.308147964773557f, 0.308095411419997f, 0.308042792131707f,
+ 0.307990106997414f, 0.307937356105799f, 0.307884539545501f,
+ 0.307831657405116f, 0.307778709773194f, 0.307725696738244f,
+ 0.307672618388731f, 0.307619474813076f, 0.307566266099656f,
+ 0.307512992336805f, 0.307459653612815f, 0.307406250015931f,
+ 0.307352781634359f, 0.307299248556257f, 0.307245650869742f,
+ 0.307191988662888f, 0.307138262023724f, 0.307084471040236f,
+ 0.307030615800366f, 0.306976696392013f, 0.306922712903033f,
+ 0.306868665421238f, 0.306814554034397f, 0.306760378830233f,
+ 0.306706139896429f, 0.306651837320622f, 0.302235743182830f,
+ 0.302181313585758f, 0.302126820609336f, 0.302072264341027f,
+ 0.302017644868253f, 0.301962962278390f, 0.301908216658771f,
+ 0.301853408096686f, 0.301798536679381f, 0.301743602494059f,
+ 0.301688605627880f, 0.301633546167958f, 0.301578424201366f,
+ 0.301523239815132f, 0.301467993096242f, 0.301412684131638f,
+ 0.301357313008217f, 0.301301879812834f, 0.301246384632300f,
+ 0.301190827553382f, 0.301135208662805f, 0.301079528047249f,
+ 0.301023785793351f, 0.300967981987704f, 0.300912116716858f,
+ 0.300856190067319f, 0.300800202125552f, 0.300744152977974f,
+ 0.300688042710961f, 0.300631871410846f, 0.300575639163918f,
+ 0.300519346056422f, 0.300462992174559f, 0.300406577604487f,
+ 0.295988374424745f, 0.295931838736557f, 0.295875242618375f,
+ 0.295818586156181f, 0.295761869435917f, 0.295705092543480f,
+ 0.295648255564723f, 0.295591358585456f, 0.295534401691445f,
+ 0.295477384968414f, 0.295420308502041f, 0.295363172377963f,
+ 0.295305976681771f, 0.295248721499016f, 0.295191406915201f,
+ 0.295134033015788f, 0.295076599886197f, 0.295019107611801f,
+ 0.294961556277931f, 0.294903945969875f, 0.294846276772877f,
+ 0.294788548772138f, 0.294730762052815f, 0.294672916700020f,
+ 0.294615012798824f, 0.294557050434254f, 0.294499029691292f,
+ 0.294440950654877f, 0.294382813409906f, 0.294324618041230f,
+ 0.294266364633658f, 0.294208053271955f, 0.294149684040843f,
+ 0.294091257025001f, 0.294032772309062f, 0.293974229977617f,
+ 0.289553902107637f, 0.289495244798780f, 0.289436530127930f,
+ 0.289377758179504f, 0.289318929037873f, 0.289260042787369f,
+ 0.289201099512278f, 0.289142099296842f, 0.289083042225260f,
+ 0.289023928381689f, 0.288964757850239f, 0.288905530714981f,
+ 0.288846247059938f, 0.288786906969092f, 0.288727510526381f,
+ 0.288668057815699f, 0.288608548920898f, 0.288548983925785f,
+ 0.288489362914122f, 0.288429685969631f, 0.288369953175988f,
+ 0.288310164616827f, 0.288250320375736f, 0.288190420536262f,
+ 0.288130465181907f, 0.288070454396130f, 0.288010388262347f,
+ 0.287950266863930f, 0.287890090284206f, 0.287829858606460f,
+ 0.287769571913934f, 0.287709230289826f, 0.287648833817288f,
+ 0.287588382579433f, 0.287527876659327f, 0.287467316139992f,
+ 0.287406701104411f, 0.287346031635518f, 0.287285307816206f,
+ 0.282862801721747f, 0.282801969450102f, 0.282741083076456f,
+ 0.282680142683527f, 0.282619148353990f, 0.282558100170477f,
+ 0.282496998215576f, 0.282435842571830f, 0.282374633321742f,
+ 0.282313370547767f, 0.282252054332321f, 0.282190684757772f,
+ 0.282129261906449f, 0.282067785860633f, 0.282006256702564f,
+ 0.281944674514439f, 0.281883039378409f, 0.281821351376584f,
+ 0.281759610591029f, 0.281697817103765f, 0.281635970996772f,
+ 0.281574072351982f, 0.281512121251289f, 0.281450117776538f,
+ 0.281388062009534f, 0.281325954032037f, 0.281263793925765f,
+ 0.281201581772391f, 0.281139317653543f, 0.281077001650809f,
+ 0.281014633845731f, 0.280952214319808f, 0.280889743154496f,
+ 0.280827220431206f, 0.280764646231307f, 0.280702020636124f,
+ 0.280639343726938f, 0.280576615584986f, 0.280513836291463f,
+ 0.280451005927520f, 0.280388124574262f, 0.280325192312755f,
+ 0.275900481216440f, 0.275837447381448f, 0.275774362881135f,
+ 0.275711227796389f, 0.275648042208058f, 0.275584806196942f,
+ 0.275521519843800f, 0.275458183229346f, 0.275394796434254f,
+ 0.275331359539149f, 0.275267872624617f, 0.275204335771198f,
+ 0.275140749059389f, 0.275077112569644f, 0.275013426382372f,
+ 0.274949690577941f, 0.274885905236672f, 0.274822070438846f,
+ 0.274758186264697f, 0.274694252794419f, 0.274630270108159f,
+ 0.274566238286022f, 0.274502157408071f, 0.274438027554322f,
+ 0.274373848804750f, 0.274309621239286f, 0.274245344937817f,
+ 0.274181019980186f, 0.274116646446194f, 0.274052224415596f,
+ 0.273987753968107f, 0.273923235183394f, 0.273858668141084f,
+ 0.273794052920759f, 0.273729389601958f, 0.273664678264174f,
+ 0.273599918986861f, 0.273535111849425f, 0.273470256931231f,
+ 0.273405354311600f, 0.273340404069808f, 0.273275406285090f,
+ 0.273210361036635f, 0.273145268403589f, 0.273080128465056f,
+ 0.273014941300095f, 0.272949706987721f, 0.272884425606906f,
+ 0.272819097236579f, 0.268391993948047f, 0.268326571835307f,
+ 0.268261102969579f, 0.268195587429617f, 0.268130025294132f,
+ 0.268064416641790f, 0.267998761551216f, 0.267933060100989f,
+ 0.267867312369645f, 0.267801518435677f, 0.267735678377535f,
+ 0.267669792273623f, 0.267603860202304f, 0.267537882241896f,
+ 0.267471858470674f, 0.267405788966870f, 0.267339673808669f,
+ 0.267273513074218f, 0.267207306841617f, 0.267141055188921f,
+ 0.267074758194145f, 0.267008415935258f, 0.266942028490186f,
+ 0.266875595936813f, 0.266809118352976f, 0.266742595816472f,
+ 0.266676028405051f, 0.266609416196424f, 0.266542759268253f,
+ 0.266476057698160f, 0.266409311563722f, 0.266342520942473f,
+ 0.266275685911905f, 0.266208806549462f, 0.266141882932549f,
+ 0.266074915138525f, 0.266007903244705f, 0.265940847328363f,
+ 0.265873747466726f, 0.265806603736981f, 0.265739416216268f,
+ 0.265672184981686f, 0.265604910110289f, 0.265537591679087f,
+ 0.265470229765049f, 0.265402824445097f, 0.265335375796112f,
+ 0.265267883894930f, 0.265200348818344f, 0.265132770643102f,
+ 0.265065149445912f, 0.264997485303435f, 0.264929778292289f,
+ 0.264862028489049f, 0.264794235970247f, 0.264726400812370f,
+ 0.264658523091862f, 0.264590602885124f, 0.264522640268512f,
+ 0.264454635318341f, 0.264386588110879f, 0.264318498722353f,
+ 0.264250367228946f, 0.259820465699218f, 0.259752250224420f,
+ 0.259683992873027f, 0.259615693721046f, 0.259547352844442f,
+ 0.259478970319136f, 0.259410546221005f, 0.259342080625883f,
+ 0.259273573609560f, 0.259205025247783f, 0.259136435616255f,
+ 0.259067804790635f, 0.258999132846538f, 0.258930419859537f,
+ 0.258861665905160f, 0.258792871058893f, 0.258724035396177f,
+ 0.258655158992408f, 0.258586241922943f, 0.258517284263090f,
+ 0.258448286088117f, 0.258379247473248f, 0.258310168493662f,
+ 0.258241049224495f, 0.258171889740839f, 0.258102690117744f,
+ 0.258033450430215f, 0.257964170753213f, 0.257894851161658f,
+ 0.257825491730422f, 0.257756092534337f, 0.257686653648191f,
+ 0.257617175146727f, 0.257547657104645f, 0.257478099596601f,
+ 0.257408502697209f, 0.257338866481037f, 0.257269191022612f,
+ 0.257199476396415f, 0.257129722676885f, 0.257059929938416f,
+ 0.256990098255361f, 0.256920227702025f, 0.256850318352674f,
+ 0.256780370281527f, 0.256710383562763f, 0.256640358270512f,
+ 0.256570294478866f, 0.256500192261870f, 0.256430051693527f,
+ 0.256359872847795f, 0.256289655798589f, 0.256219400619781f,
+ 0.256149107385198f, 0.256078776168626f, 0.256008407043804f,
+ 0.255938000084429f, 0.255867555364156f, 0.255797072956594f,
+ 0.255726552935309f, 0.255655995373823f, 0.255585400345616f,
+ 0.255514767924123f, 0.255444098182735f, 0.255373391194802f,
+ 0.255302647033627f, 0.255231865772471f, 0.255161047484552f,
+ 0.255090192243042f, 0.255019300121073f, 0.254948371191731f,
+ 0.254877405528058f, 0.254806403203054f, 0.254735364289674f,
+ 0.254664288860830f, 0.254593176989391f, 0.254522028748181f,
+ 0.254450844209981f, 0.254379623447529f, 0.254308366533519f,
+ 0.254237073540600f, 0.254165744541380f, 0.254094379608422f,
+ 0.254022978814245f, 0.253951542231324f, 0.253880069932092f,
+ 0.253808561988937f, 0.253737018474204f, 0.253665439460195f,
+ 0.253593825019167f, 0.253522175223334f, 0.253450490144866f,
+ 0.253378769855891f, 0.253307014428491f, 0.253235223934706f,
+ 0.253163398446532f, 0.253091538035921f, 0.253019642774782f,
+ 0.252947712734979f, 0.252875747988335f, 0.252803748606627f,
+ 0.252731714661588f, 0.252659646224911f, 0.252587543368241f,
+ 0.252515406163181f, 0.252443234681292f, 0.252371028994090f,
+ 0.252298789173046f, 0.252226515289590f, 0.252154207415106f,
+ 0.252081865620937f, 0.252009489978380f, 0.251937080558689f,
+ 0.251864637433075f, 0.251792160672704f, 0.251719650348701f,
+ 0.251647106532145f, 0.251574529294072f, 0.251501918705475f,
+ 0.251429274837301f, 0.251356597760457f, 0.251283887545805f,
+ 0.251211144264161f, 0.251138367986300f, 0.251065558782954f,
+ 0.250992716724808f, 0.250919841882507f, 0.250846934326649f,
+ 0.250773994127792f, 0.250701021356448f, 0.250628016083085f,
+ 0.250554978378129f, 0.250481908311962f, 0.250408805954920f,
+ 0.250335671377300f, 0.250262504649351f, 0.250189305841280f,
+ 0.250116075023251f, 0.250042812265383f, 0.249969517637753f,
+ 0.249896191210394f, 0.249822833053293f, 0.249749443236397f,
+ 0.249676021829606f, 0.249602568902779f, 0.249529084525730f,
+ 0.249455568768230f, 0.249382021700006f, 0.249308443390741f,
+ 0.249234833910075f, 0.249161193327604f, 0.249087521712880f,
+ 0.249013819135412f, 0.248940085664666f, 0.248866321370063f,
+ 0.248792526320980f, 0.248718700586753f, 0.248644844236672f,
+ 0.248570957339983f, 0.248497039965891f, 0.248423092183554f,
+ 0.248349114062088f, 0.248275105670567f, 0.248201067078019f,
+ 0.248126998353429f, 0.248052899565738f, 0.247978770783845f,
+ 0.247904612076603f, 0.247830423512822f, 0.247756205161271f,
+ 0.247681957090672f, 0.247607679369705f, 0.247533372067005f,
+ 0.247459035251165f, 0.247384668990733f, 0.247310273354215f,
+ 0.247235848410072f, 0.247161394226722f, 0.247086910872538f,
+ 0.247012398415851f, 0.246937856924948f, 0.242501558460495f,
+ 0.242426959105845f, 0.242352330921577f, 0.242277673975804f,
+ 0.242202988336594f, 0.242128274071971f, 0.242053531249917f,
+ 0.241978759938370f, 0.241903960205222f, 0.241829132118326f,
+ 0.241754275745486f, 0.241679391154467f, 0.241604478412987f,
+ 0.241529537588722f, 0.241454568749305f, 0.241379571962322f,
+ 0.241304547295320f, 0.241229494815798f, 0.241154414591216f,
+ 0.241079306688985f, 0.241004171176476f, 0.240929008121016f,
+ 0.240853817589887f, 0.240778599650329f, 0.240703354369537f,
+ 0.240628081814662f, 0.240552782052813f, 0.240477455151054f,
+ 0.240402101176407f, 0.240326720195847f, 0.240251312276309f,
+ 0.240175877484683f, 0.240100415887814f, 0.240024927552506f,
+ 0.239949412545517f, 0.239873870933562f, 0.239798302783312f,
+ 0.239722708161397f, 0.239647087134399f, 0.239571439768860f,
+ 0.239495766131276f, 0.239420066288100f, 0.239344340305743f,
+ 0.239268588250570f, 0.239192810188903f, 0.239117006187022f,
+ 0.239041176311160f, 0.238965320627509f, 0.238889439202216f,
+ 0.238813532101387f, 0.238737599391080f, 0.238661641137313f,
+ 0.238585657406058f, 0.238509648263246f, 0.238433613774760f,
+ 0.238357554006444f, 0.238281469024095f, 0.238205358893469f,
+ 0.238129223680276f, 0.238053063450183f, 0.237976878268814f,
+ 0.237900668201750f, 0.237824433314526f, 0.237748173672635f,
+ 0.237671889341525f, 0.237595580386603f, 0.237519246873230f,
+ 0.237442888866723f, 0.237366506432358f, 0.237290099635364f,
+ 0.237213668540929f, 0.237137213214196f, 0.237060733720264f,
+ 0.236984230124190f, 0.236907702490985f, 0.236831150885619f,
+ 0.236754575373016f, 0.236677976018057f, 0.236601352885581f,
+ 0.236524706040380f, 0.236448035547206f, 0.236371341470764f,
+ 0.236294623875718f, 0.236217882826687f, 0.236141118388246f,
+ 0.236064330624927f, 0.235987519601219f, 0.235910685381566f,
+ 0.235833828030369f, 0.235756947611985f, 0.235680044190727f,
+ 0.235603117830866f, 0.235526168596627f, 0.235449196552193f,
+ 0.235372201761703f, 0.235295184289252f, 0.235218144198891f,
+ 0.235141081554629f, 0.235063996420428f, 0.234986888860210f,
+ 0.234909758937852f, 0.234832606717186f, 0.234755432262002f,
+ 0.234678235636045f, 0.234601016903018f, 0.234523776126579f,
+ 0.234446513370342f, 0.234369228697878f, 0.234291922172716f,
+ 0.234214593858338f, 0.234137243818184f, 0.234059872115652f,
+ 0.233982478814092f, 0.233905063976814f, 0.233827627667084f,
+ 0.233750169948123f, 0.233672690883109f, 0.233595190535175f,
+ 0.233517668967413f, 0.233440126242869f, 0.233362562424547f,
+ 0.233284977575406f, 0.233207371758361f, 0.233129745036284f,
+ 0.233052097472005f, 0.232974429128308f, 0.232896740067933f,
+ 0.232819030353578f, 0.232741300047898f, 0.232663549213500f,
+ 0.232585777912953f, 0.232507986208779f, 0.232430174163456f,
+ 0.232352341839420f, 0.232274489299062f, 0.232196616604730f,
+ 0.227756995811151f, 0.227679082995740f, 0.227601150213137f,
+ 0.227523197525514f, 0.227445224995001f, 0.227367232683684f,
+ 0.227289220653605f, 0.227211188966762f, 0.227133137685110f,
+ 0.227055066870559f, 0.226976976584978f, 0.226898866890189f,
+ 0.226820737847972f, 0.226742589520064f, 0.226664421968157f,
+ 0.226586235253900f, 0.226508029438898f, 0.226429804584713f,
+ 0.226351560752862f, 0.226273298004819f, 0.226195016402015f,
+ 0.226116716005836f, 0.226038396877625f, 0.225960059078682f,
+ 0.225881702670262f, 0.225803327713576f, 0.225724934269794f,
+ 0.225646522400040f, 0.225568092165393f, 0.225489643626893f,
+ 0.225411176845531f, 0.225332691882258f, 0.225254188797980f,
+ 0.225175667653558f, 0.225097128509812f, 0.225018571427517f,
+ 0.224939996467403f, 0.224861403690158f, 0.224782793156426f,
+ 0.224704164926808f, 0.224625519061859f, 0.224546855622093f,
+ 0.224468174667977f, 0.224389476259939f, 0.224310760458359f,
+ 0.224232027323575f, 0.224153276915881f, 0.224074509295528f,
+ 0.223995724522724f, 0.223916922657630f, 0.223838103760367f,
+ 0.223759267891009f, 0.223680415109590f, 0.223601545476097f,
+ 0.223522659050475f, 0.223443755892626f, 0.223364836062405f,
+ 0.223285899619627f, 0.223206946624062f, 0.223127977135435f,
+ 0.223048991213429f, 0.222969988917683f, 0.222890970307791f,
+ 0.222811935443306f, 0.222732884383734f, 0.222653817188539f,
+ 0.222574733917142f, 0.222495634628919f, 0.222416519383203f,
+ 0.222337388239283f, 0.222258241256404f, 0.222179078493767f,
+ 0.217738172002954f, 0.217658977858233f, 0.217579768111098f,
+ 0.217500542820575f, 0.217421302045647f, 0.217342045845254f,
+ 0.217262774278292f, 0.217183487403611f, 0.217104185280022f,
+ 0.217024867966288f, 0.216945535521129f, 0.216866188003224f,
+ 0.216786825471206f, 0.216707447983663f, 0.216628055599143f,
+ 0.216548648376148f, 0.216469226373135f, 0.216389789648521f,
+ 0.216310338260676f, 0.216230872267927f, 0.216151391728558f,
+ 0.216071896700810f, 0.215992387242879f, 0.215912863412916f,
+ 0.215833325269032f, 0.215753772869290f, 0.215674206271714f,
+ 0.215594625534279f, 0.215515030714921f, 0.215435421871530f,
+ 0.215355799061952f, 0.215276162343990f, 0.215196511775403f,
+ 0.215116847413907f, 0.215037169317173f, 0.214957477542830f,
+ 0.214877772148461f, 0.214798053191607f, 0.214718320729766f,
+ 0.214638574820389f, 0.214558815520887f, 0.214479042888626f,
+ 0.214399256980927f, 0.214319457855068f, 0.214239645568284f,
+ 0.214159820177766f, 0.214079981740661f, 0.214000130314072f,
+ 0.213920265955059f, 0.213840388720638f, 0.213760498667781f,
+ 0.213680595853417f, 0.213600680334430f, 0.213520752167662f,
+ 0.213440811409909f, 0.213360858117925f, 0.213280892348421f,
+ 0.213200914158062f, 0.213120923603470f, 0.208679192733648f,
+ 0.208599177620285f, 0.208519150312294f, 0.208439110866124f,
+ 0.208359059338178f, 0.208278995784815f, 0.208198920262354f,
+ 0.208118832827066f, 0.208038733535179f, 0.207958622442880f,
+ 0.207878499606310f, 0.207798365081566f, 0.207718218924703f,
+ 0.207638061191730f, 0.207557891938615f, 0.207477711221280f,
+ 0.207397519095604f, 0.207317315617423f, 0.207237100842528f,
+ 0.207156874826667f, 0.207076637625544f, 0.206996389294820f,
+ 0.206916129890112f, 0.206835859466992f, 0.206755578080990f,
+ 0.206675285787592f, 0.206594982642238f, 0.206514668700328f,
+ 0.206434344017215f, 0.206354008648211f, 0.206273662648582f,
+ 0.206193306073550f, 0.206112938978297f, 0.206032561417956f,
+ 0.205952173447621f, 0.205871775122340f, 0.205791366497116f,
+ 0.205710947626911f, 0.205630518566642f, 0.205550079371182f,
+ 0.205469630095361f, 0.205389170793964f, 0.205308701521733f,
+ 0.205228222333368f, 0.205147733283521f, 0.205067234426806f,
+ 0.204986725817787f, 0.204906207510990f, 0.204825679560893f,
+ 0.204745142021933f, 0.204664594948501f, 0.200222310387369f,
+ 0.200141744407996f, 0.200061169057067f, 0.199980584388797f,
+ 0.199899990457361f, 0.199819387316889f, 0.199738775021466f,
+ 0.199658153625134f, 0.199577523181893f, 0.199496883745697f,
+ 0.199416235370458f, 0.199335578110042f, 0.199254912018273f,
+ 0.199174237148931f, 0.199093553555752f, 0.199012861292428f,
+ 0.198932160412609f, 0.198851450969898f, 0.198770733017858f,
+ 0.198690006610006f, 0.198609271799814f, 0.198528528640714f,
+ 0.198447777186091f, 0.198367017489288f, 0.198286249603603f,
+ 0.198205473582292f, 0.198124689478565f, 0.198043897345590f,
+ 0.197963097236492f, 0.197882289204349f, 0.197801473302198f,
+ 0.197720649583031f, 0.197639818099798f, 0.197558978905402f,
+ 0.197478132052707f, 0.197397277594528f, 0.197316415583640f,
+ 0.197235546072773f, 0.197154669114612f, 0.197073784761801f,
+ 0.196992893066939f, 0.196911994082579f, 0.196831087861235f,
+ 0.196750174455372f, 0.196669253917415f, 0.196588326299744f,
+ 0.196507391654695f, 0.196426450034560f, 0.191983773484012f,
+ 0.191902818070409f, 0.191821855838336f, 0.191740886839911f,
+ 0.191659911127206f, 0.191578928752253f, 0.191497939767036f,
+ 0.191416944223500f, 0.191335942173542f, 0.191254933669018f,
+ 0.191173918761738f, 0.191092897503471f, 0.191011869945940f,
+ 0.190930836140826f, 0.190849796139763f, 0.190768749994346f,
+ 0.190687697756122f, 0.190606639476596f, 0.190525575207231f,
+ 0.190444504999443f, 0.190363428904605f, 0.190282346974049f,
+ 0.190201259259060f, 0.190120165810881f, 0.190039066680710f,
+ 0.189957961919703f, 0.189876851578970f, 0.189795735709579f,
+ 0.189714614362553f, 0.189633487588873f, 0.189552355439475f,
+ 0.189471217965251f, 0.189390075217050f, 0.189308927245676f,
+ 0.189227774101891f, 0.189146615836412f, 0.189065452499913f,
+ 0.188984284143024f, 0.188903110816330f, 0.188821932570374f,
+ 0.188740749455655f, 0.188659561522627f, 0.188578368821702f,
+ 0.188497171403246f, 0.188415969317584f, 0.188334762614995f,
+ 0.183891823338137f, 0.183810607552358f, 0.183729387300228f,
+ 0.183648162631853f, 0.183566933597294f, 0.183485700246567f,
+ 0.183404462629646f, 0.183323220796461f, 0.183241974796898f,
+ 0.183160724680798f, 0.183079470497960f, 0.182998212298140f,
+ 0.182916950131046f, 0.182835684046347f, 0.182754414093667f,
+ 0.182673140322583f, 0.182591862782633f, 0.182510581523309f,
+ 0.182429296594058f, 0.182348008044284f, 0.182266715923350f,
+ 0.182185420280571f, 0.182104121165221f, 0.182022818626530f,
+ 0.181941512713682f, 0.181860203475820f, 0.181778890962042f,
+ 0.181697575221403f, 0.181616256302912f, 0.181534934255536f,
+ 0.181453609128199f, 0.181372280969781f, 0.181290949829115f,
+ 0.181209615754995f, 0.181128278796168f, 0.181046939001338f,
+ 0.180965596419165f, 0.180884251098267f, 0.180802903087216f,
+ 0.180721552434541f, 0.180640199188728f, 0.180558843398218f,
+ 0.180477485111409f, 0.180396124376655f, 0.175953033234688f,
+ 0.175871667748931f, 0.175790299960027f, 0.175708929916157f,
+ 0.175627557665455f, 0.175546183256013f, 0.175464806735878f,
+ 0.175383428153054f, 0.175302047555502f, 0.175220664991136f,
+ 0.175139280507831f, 0.175057894153414f, 0.174976505975670f,
+ 0.174895116022341f, 0.174813724341124f, 0.174732330979673f,
+ 0.174650935985597f, 0.174569539406463f, 0.174488141289793f,
+ 0.174406741683064f, 0.174325340633713f, 0.174243938189129f,
+ 0.174162534396661f, 0.174081129303611f, 0.173999722957239f,
+ 0.173918315404761f, 0.173836906693349f, 0.173755496870131f,
+ 0.173674085982191f, 0.173592674076571f, 0.173511261200267f,
+ 0.173429847400233f, 0.173348432723377f, 0.173267017216566f,
+ 0.173185600926620f, 0.173104183900319f, 0.173022766184396f,
+ 0.172941347825542f, 0.172859928870403f, 0.172778509365582f,
+ 0.172697089357639f, 0.172615668893089f, 0.172534248018403f,
+ 0.172452826780009f, 0.168009677216713f, 0.167928255390010f,
+ 0.167846833338621f, 0.167765411108796f, 0.167683988746745f,
+ 0.167602566298634f, 0.167521143810582f, 0.167439721328668f,
+ 0.167358298898926f, 0.167276876567344f, 0.167195454379870f,
+ 0.167114032382406f, 0.167032610620809f, 0.166951189140896f,
+ 0.166869767988436f, 0.166788347209158f, 0.166706926848743f,
+ 0.166625506952833f, 0.166544087567022f, 0.166462668736864f,
+ 0.166381250507865f, 0.166299832925490f, 0.166218416035160f,
+ 0.166136999882253f, 0.166055584512100f, 0.165974169969991f,
+ 0.165892756301173f, 0.165811343550845f, 0.165729931764167f,
+ 0.165648520986252f, 0.165567111262170f, 0.165485702636949f,
+ 0.165404295155570f, 0.165322888862974f, 0.165241483804054f,
+ 0.165160080023663f, 0.165078677566607f, 0.164997276477651f,
+ 0.164915876801515f, 0.164834478582874f, 0.164753081866361f,
+ 0.164671686696565f, 0.164590293118030f, 0.164508901175258f,
+ 0.164427510912706f, 0.159984394367208f, 0.159903007598291f,
+ 0.159821622642703f, 0.159740239544724f, 0.159658858348595f,
+ 0.159577479098508f, 0.159496101838615f, 0.159414726613023f,
+ 0.159333353465794f, 0.159251982440948f, 0.159170613582459f,
+ 0.159089246934261f, 0.159007882540240f, 0.158926520444241f,
+ 0.158845160690063f, 0.158763803321464f, 0.158682448382156f,
+ 0.158601095915807f, 0.158519745966043f, 0.158438398576445f,
+ 0.158357053790551f, 0.158275711651853f, 0.158194372203803f,
+ 0.158113035489805f, 0.158031701553222f, 0.157950370437373f,
+ 0.157869042185531f, 0.157787716840929f, 0.157706394446753f,
+ 0.157625075046145f, 0.157543758682207f, 0.157462445397992f,
+ 0.157381135236513f, 0.157299828240738f, 0.157218524453592f,
+ 0.157137223917953f, 0.157055926676660f, 0.156974632772505f,
+ 0.156893342248236f, 0.156812055146560f, 0.156730771510136f,
+ 0.156649491381584f, 0.156568214803476f, 0.156486941818342f,
+ 0.156405672468670f, 0.156324406796900f, 0.151881416837854f,
+ 0.151800158649042f, 0.151718904265197f, 0.151637653728586f,
+ 0.151556407081432f, 0.151475164365916f, 0.151393925624172f,
+ 0.151312690898293f, 0.151231460230326f, 0.151150233662276f,
+ 0.151069011236103f, 0.150987792993723f, 0.150906578977011f,
+ 0.150825369227794f, 0.150744163787857f, 0.150662962698943f,
+ 0.150581766002748f, 0.150500573740927f, 0.150419385955089f,
+ 0.150338202686801f, 0.150257023977585f, 0.150175849868919f,
+ 0.150094680402237f, 0.150013515618932f, 0.149932355560350f,
+ 0.149851200267794f, 0.149770049782523f, 0.149688904145754f,
+ 0.149607763398657f, 0.149526627582362f, 0.149445496737952f,
+ 0.149364370906467f, 0.149283250128905f, 0.149202134446217f,
+ 0.149121023899313f, 0.149039918529058f, 0.148958818376273f,
+ 0.148877723481736f, 0.148796633886180f, 0.148715549630295f,
+ 0.148634470754727f, 0.148553397300078f, 0.148472329306907f,
+ 0.148391266815728f, 0.148310209867012f, 0.148229158501186f,
+ 0.148148112758633f, 0.148067072679692f, 0.143624310297081f,
+ 0.143543281666207f, 0.143462258819700f, 0.143381241797725f,
+ 0.143300230640400f, 0.143219225387804f, 0.143138226079968f,
+ 0.143057232756881f, 0.142976245458488f, 0.142895264224689f,
+ 0.142814289095343f, 0.142733320110263f, 0.142652357309218f,
+ 0.142571400731934f, 0.142490450418093f, 0.142409506407333f,
+ 0.142328568739249f, 0.142247637453390f, 0.142166712589265f,
+ 0.142085794186334f, 0.142004882284019f, 0.141923976921693f,
+ 0.141843078138688f, 0.141762185974292f, 0.141681300467748f,
+ 0.141600421658257f, 0.141519549584974f, 0.141438684287012f,
+ 0.141357825803438f, 0.141276974173279f, 0.141196129435513f,
+ 0.141115291629079f, 0.141034460792870f, 0.140953636965734f,
+ 0.140872820186478f, 0.140792010493862f, 0.140711207926605f,
+ 0.140630412523381f, 0.140549624322819f, 0.140468843363506f,
+ 0.140388069683985f, 0.140307303322754f, 0.140226544318269f,
+ 0.140145792708939f, 0.140065048533132f, 0.139984311829173f,
+ 0.139903582635339f, 0.139822860989867f, 0.139742146930948f,
+ 0.139661440496731f, 0.139580741725320f, 0.139500050654775f,
+ 0.139419367323112f, 0.134976963760728f, 0.134896296020705f,
+ 0.134815636133351f, 0.134734984136508f, 0.134654340067973f,
+ 0.134573703965498f, 0.134493075866795f, 0.134412455809528f,
+ 0.134331843831321f, 0.134251239969750f, 0.134170644262351f,
+ 0.134090056746613f, 0.134009477459984f, 0.133928906439867f,
+ 0.133848343723620f, 0.133767789348558f, 0.133687243351954f,
+ 0.133606705771033f, 0.133526176642981f, 0.133445656004937f,
+ 0.133365143893997f, 0.133284640347212f, 0.133204145401592f,
+ 0.133123659094101f, 0.133043181461659f, 0.132962712541143f,
+ 0.132882252369387f, 0.132801800983178f, 0.132721358419264f,
+ 0.132640924714344f, 0.132560499905078f, 0.132480084028077f,
+ 0.132399677119913f, 0.132319279217111f, 0.132238890356154f,
+ 0.132158510573480f, 0.132078139905483f, 0.131997778388515f,
+ 0.131917426058882f, 0.131837082952847f, 0.131756749106629f,
+ 0.131676424556405f, 0.131596109338304f, 0.131515803488415f,
+ 0.131435507042783f, 0.131355220037405f, 0.131274942508240f,
+ 0.131194674491199f, 0.131114416022150f, 0.131034167136919f,
+ 0.130953927871285f, 0.130873698260986f, 0.130793478341716f,
+ 0.130713268149122f, 0.130633067718811f, 0.130552877086344f,
+ 0.130472696287238f, 0.130392525356968f, 0.130312364330964f,
+ 0.130232213244611f, 0.130152072133252f, 0.130071941032186f,
+ 0.125630091969089f, 0.125549980994328f, 0.125469880135491f,
+ 0.125389789427702f, 0.125309708906040f, 0.125229638605540f,
+ 0.125149578561194f, 0.125069528807950f, 0.124989489380710f,
+ 0.124909460314337f, 0.124829441643644f, 0.124749433403405f,
+ 0.124669435628348f, 0.124589448353158f, 0.124509471612476f,
+ 0.124429505440897f, 0.124349549872976f, 0.124269604943221f,
+ 0.124189670686097f, 0.124109747136027f, 0.124029834327388f,
+ 0.123949932294513f, 0.123870041071692f, 0.123790160693172f,
+ 0.123710291193154f, 0.123630432605798f, 0.123550584965217f,
+ 0.123470748305482f, 0.123390922660619f, 0.123311108064613f,
+ 0.123231304551401f, 0.123151512154880f, 0.123071730908899f,
+ 0.122991960847268f, 0.122912202003750f, 0.122832454412063f,
+ 0.122752718105885f, 0.122672993118847f, 0.122593279484538f,
+ 0.122513577236502f, 0.122433886408239f, 0.122354207033207f,
+ 0.122274539144817f, 0.122194882776439f, 0.122115237961398f,
+ 0.122035604732975f, 0.121955983124407f, 0.121876373168889f,
+ 0.121796774899569f, 0.121717188349554f, 0.121637613551904f,
+ 0.121558050539640f, 0.121478499345734f, 0.121398960003116f,
+ 0.121319432544675f, 0.121239917003251f, 0.121160413411644f,
+ 0.121080921802609f, 0.121001442208857f, 0.120921974663054f,
+ 0.120842519197825f, 0.120763075845748f, 0.120683644639360f,
+ 0.120604225611152f, 0.120524818793572f, 0.120445424219023f,
+ 0.120366041919867f, 0.120286671928419f, 0.120207314276951f,
+ 0.120127968997693f, 0.120048636122829f, 0.119969315684500f,
+ 0.119890007714802f, 0.119810712245789f, 0.119731429309471f,
+ 0.119652158937811f, 0.119572901162733f, 0.119493656016113f,
+ 0.119414423529785f, 0.119335203735540f, 0.114894268657545f,
+ 0.114815074342658f, 0.114735892814960f, 0.114656724106065f,
+ 0.114577568247544f, 0.114498425270923f, 0.114419295207686f,
+ 0.114340178089270f, 0.114261073947072f, 0.114181982812442f,
+ 0.114102904716688f, 0.114023839691073f, 0.113944787766818f,
+ 0.113865748975096f, 0.113786723347042f, 0.113707710913742f,
+ 0.113628711706240f, 0.113549725755538f, 0.113470753092591f,
+ 0.113391793748312f, 0.113312847753569f, 0.113233915139187f,
+ 0.113154995935948f, 0.113076090174588f, 0.112997197885800f,
+ 0.112918319100234f, 0.112839453848495f, 0.112760602161145f,
+ 0.112681764068701f, 0.112602939601637f, 0.112524128790383f,
+ 0.112445331665325f, 0.112366548256805f, 0.112287778595122f,
+ 0.112209022710530f, 0.112130280633239f, 0.112051552393417f,
+ 0.111972838021186f, 0.111894137546624f, 0.111815450999768f,
+ 0.111736778410607f, 0.111658119809091f, 0.111579475225121f,
+ 0.111500844688557f, 0.111422228229216f, 0.111343625876868f,
+ 0.111265037661242f, 0.111186463612022f, 0.111107903758848f,
+ 0.111029358131316f, 0.110950826758979f, 0.110872309671346f,
+ 0.110793806897879f, 0.110715318468002f, 0.110636844411090f,
+ 0.110558384756477f, 0.110479939533451f, 0.110401508771258f,
+ 0.110323092499099f, 0.110244690746132f, 0.110166303541471f,
+ 0.110087930914184f, 0.110009572893298f, 0.109931229507795f,
+ 0.109852900786614f, 0.109774586758647f, 0.109696287452746f,
+ 0.109618002897716f, 0.109539733122321f, 0.109461478155279f,
+ 0.109383238025265f, 0.109305012760910f, 0.109226802390801f,
+ 0.109148606943480f, 0.109070426447448f, 0.108992260931160f,
+ 0.108914110423026f, 0.108835974951415f, 0.108757854544651f,
+ 0.108679749231012f, 0.108601659038736f, 0.108523583996014f,
+ 0.108445524130995f, 0.108367479471782f, 0.108289450046436f,
+ 0.108211435882973f, 0.108133437009367f, 0.108055453453546f,
+ 0.107977485243395f, 0.107899532406754f, 0.107821594971421f,
+ 0.107743672965149f, 0.107665766415648f, 0.107587875350582f,
+ 0.107509999797574f, 0.107432139784200f, 0.107354295337995f,
+ 0.107276466486449f, 0.107198653257007f, 0.107120855677072f,
+ 0.107043073774001f, 0.106965307575109f, 0.106887557107667f,
+ 0.106809822398901f, 0.106732103475993f, 0.106654400366083f,
+ 0.106576713096265f, 0.106499041693590f, 0.106421386185065f,
+ 0.106343746597653f, 0.106266122958274f, 0.106188515293803f,
+ 0.106110923631072f, 0.106033347996867f, 0.105955788417934f,
+ 0.105878244920971f, 0.105800717532635f, 0.105723206279537f,
+ 0.105645711188245f, 0.105568232285285f, 0.105490769597136f,
+ 0.105413323150235f, 0.105335892970973f, 0.105258479085701f,
+ 0.105181081520723f, 0.105103700302298f, 0.105026335456646f,
+ 0.104948987009938f, 0.104871654988304f, 0.104794339417828f,
+ 0.104717040324553f, 0.104639757734476f, 0.104562491673551f,
+ 0.104485242167686f, 0.104408009242749f, 0.104330792924560f,
+ 0.104253593238899f, 0.104176410211498f, 0.104099243868048f,
+ 0.104022094234196f, 0.103944961335543f, 0.103867845197649f,
+ 0.103790745846028f, 0.103713663306151f, 0.103636597603444f,
+ 0.103559548763290f, 0.103482516811028f, 0.103405501771954f,
+ 0.103328503671319f, 0.103251522534330f, 0.103174558386149f,
+ 0.103097611251898f, 0.103020681156651f, 0.102943768125441f,
+ 0.102866872183254f, 0.102789993355035f, 0.102713131665683f,
+ 0.102636287140056f, 0.102559459802964f, 0.102482649679177f,
+ 0.102405856793418f, 0.102329081170369f, 0.102252322834665f,
+ 0.102175581810900f, 0.102098858123621f, 0.102022151797335f,
+ 0.101945462856502f, 0.101868791325538f, 0.101792137228817f,
+ 0.101715500590669f, 0.101638881435378f, 0.101562279787186f,
+ 0.101485695670291f, 0.101409129108846f, 0.101332580126960f,
+ 0.101256048748701f, 0.101179534998088f, 0.101103038899101f,
+ 0.101026560475674f, 0.100950099751696f, 0.100873656751014f,
+ 0.100797231497430f, 0.100720824014703f, 0.100644434326547f,
+ 0.100568062456633f, 0.100491708428587f, 0.100415372265992f,
+ 0.100339053992388f, 0.100262753631269f, 0.100186471206086f,
+ 0.100110206740246f, 0.100033960257113f, 0.0999577317800052f,
+ 0.0998815213321992f, 0.0998053289369260f, 0.0997291546173731f,
+ 0.0996529983966844f, 0.0995768602979594f, 0.0995007403442542f,
+ 0.0994246385585807f, 0.0993485549639068f, 0.0992724895831567f,
+ 0.0991964424392106f, 0.0991204135549048f, 0.0990444029530317f,
+ 0.0989684106563397f, 0.0988924366875334f, 0.0988164810692734f,
+ 0.0987405438241764f, 0.0986646249748153f, 0.0985887245437189f,
+ 0.0985128425533722f, 0.0984369790262163f, 0.0983611339846482f,
+ 0.0982853074510214f, 0.0982094994476449f, 0.0981337099967844f,
+ 0.0980579391206610f, 0.0979821868414527f, 0.0979064531812928f,
+ 0.0978307381622712f, 0.0977550418064336f, 0.0976793641357820f,
+ 0.0976037051722743f, 0.0975280649378246f, 0.0974524434543029f,
+ 0.0973768407435356f, 0.0973012568273050f, 0.0972256917273493f,
+ 0.0971501454653631f, 0.0970746180629969f, 0.0969991095418574f,
+ 0.0969236199235071f, 0.0968481492294650f, 0.0967726974812058f,
+ 0.0966972647001606f, 0.0966218509077163f, 0.0965464561252159f,
+ 0.0964710803739588f, 0.0963957236752001f, 0.0963203860501512f,
+ 0.0962450675199795f, 0.0961697681058085f, 0.0960944878287176f,
+ 0.0960192267097427f, 0.0959439847698754f, 0.0958687620300635f,
+ 0.0957935585112108f, 0.0957183742341774f, 0.0956432092197791f,
+ 0.0955680634887883f, 0.0954929370619329f, 0.0954178299598974f,
+ 0.0953427422033218f, 0.0952676738128029f, 0.0951926248088929f,
+ 0.0951175952121004f, 0.0950425850428900f, 0.0949675943216825f,
+ 0.0948926230688546f, 0.0948176713047392f, 0.0947427390496252f,
+ 0.0946678263237576f, 0.0945929331473374f, 0.0945180595405218f,
+ 0.0944432055234240f, 0.0943683711161133f, 0.0942935563386150f,
+ 0.0942187612109106f, 0.0941439857529376f, 0.0940692299845894f,
+ 0.0939944939257160f, 0.0939197775961227f, 0.0938450810155716f,
+ 0.0937704042037804f, 0.0936957471804231f, 0.0936211099651296f,
+ 0.0935464925774860f, 0.0934718950370345f, 0.0933973173632733f,
+ 0.0933227595756565f, 0.0932482216935947f, 0.0931737037364541f,
+ 0.0930992057235573f, 0.0930247276741828f, 0.0929502696075653f,
+ 0.0928758315428953f, 0.0928014134993197f, 0.0927270154959413f,
+ 0.0926526375518190f, 0.0925782796859676f, 0.0925039419173584f,
+ 0.0924296242649182f, 0.0923553267475303f, 0.0922810493840339f,
+ 0.0922067921932243f, 0.0921325551938528f, 0.0920583384046269f,
+ 0.0919841418442100f, 0.0919099655312217f, 0.0918358094842375f,
+ 0.0917616737217892f, 0.0916875582623645f, 0.0916134631244072f,
+ 0.0915393883263172f, 0.0914653338864503f, 0.0913912998231188f,
+ 0.0913172861545903f, 0.0912432928990893f, 0.0911693200747959f,
+ 0.0910953676998462f, 0.0910214357923326f, 0.0909475243703036f,
+ 0.0908736334517634f, 0.0907997630546726f, 0.0907259131969478f,
+ 0.0906520838964616f, 0.0905782751710426f, 0.0905044870384756f,
+ 0.0904307195165015f, 0.0903569726228168f, 0.0902832463750749f,
+ 0.0902095407908844f, 0.0901358558878106f, 0.0900621916833744f,
+ 0.0899885481950531f, 0.0899149254402798f, 0.0898413234364439f,
+ 0.0897677422008906f, 0.0896941817509215f, 0.0896206421037937f,
+ 0.0895471232767210f, 0.0894736252868730f, 0.0894001481513751f,
+ 0.0893266918873091f, 0.0892532565117127f, 0.0891798420415798f,
+ 0.0891064484938601f, 0.0890330758854596f, 0.0889597242332403f,
+ 0.0888863935540201f, 0.0888130838645731f, 0.0887397951816295f,
+ 0.0886665275218755f, 0.0885932809019533f, 0.0885200553384611f,
+ 0.0884468508479535f, 0.0883736674469406f, 0.0883005051518891f,
+ 0.0882273639792214f, 0.0881542439453161f, 0.0880811450665078f,
+ 0.0880080673590872f, 0.0879350108393010f, 0.0878619755233519f,
+ 0.0877889614273989f, 0.0877159685675568f, 0.0876429969598966f,
+ 0.0875700466204452f, 0.0874971175651857f, 0.0874242098100572f,
+ 0.0873513233709547f, 0.0872784582637296f, 0.0872056145041890f,
+ 0.0871327921080962f, 0.0870599910911707f, 0.0869872114690878f,
+ 0.0869144532574789f, 0.0868417164719315f, 0.0867690011279892f,
+ 0.0866963072411517f, 0.0866236348268744f, 0.0865509839005692f,
+ 0.0864783544776037f, 0.0864057465733018f, 0.0863331602029433f,
+ 0.0862605953817640f, 0.0861880521249560f, 0.0861155304476673f,
+ 0.0860430303650017f, 0.0859705518920195f, 0.0858980950437366f,
+ 0.0858256598351254f, 0.0857532462811140f, 0.0856808543965868f,
+ 0.0856084841963839f, 0.0855361356953018f, 0.0854638089080928f,
+ 0.0853915038494655f, 0.0853192205340843f, 0.0852469589765697f,
+ 0.0851747191914984f, 0.0851025011934029f, 0.0850303049967719f,
+ 0.0849581306160502f, 0.0848859780656385f, 0.0848138473598935f,
+ 0.0847417385131283f, 0.0846696515396116f, 0.0845975864535684f,
+ 0.0845255432691795f, 0.0844535220005823f, 0.0843815226618695f,
+ 0.0843095452670904f, 0.0842375898302500f, 0.0841656563653097f,
+ 0.0840937448861865f, 0.0840218554067539f, 0.0839499879408410f,
+ 0.0838781425022332f, 0.0838063191046720f, 0.0837345177618548f,
+ 0.0836627384874350f, 0.0835909812950222f, 0.0835192461981819f,
+ 0.0834475332104356f, 0.0833758423452611f, 0.0833041736160921f,
+ 0.0832325270363181f, 0.0831609026192851f, 0.0830893003782947f,
+ 0.0830177203266048f, 0.0829461624774291f, 0.0828746268439379f,
+ 0.0828031134392568f, 0.0827316222764678f, 0.0826601533686091f,
+ 0.0825887067286746f, 0.0825172823696144f, 0.0824458803043347f,
+ 0.0823745005456977f, 0.0823031431065214f, 0.0822318079995802f,
+ 0.0821604952376043f, 0.0820892048332801f, 0.0820179367992499f,
+ 0.0819466911481119f, 0.0818754678924208f, 0.0818042670446868f,
+ 0.0817330886173767f, 0.0816619326229126f, 0.0815907990736732f,
+ 0.0815196879819933f, 0.0814485993601633f, 0.0813775332204299f,
+ 0.0813064895749958f, 0.0812354684360197f, 0.0811644698156163f,
+ 0.0810934937258564f, 0.0810225401787669f, 0.0809516091863306f,
+ 0.0808807007604862f, 0.0808098149131290f, 0.0807389516561096f,
+ 0.0806681110012352f, 0.0805972929602686f, 0.0805264975449289f,
+ 0.0804557247668912f, 0.0803849746377866f, 0.0803142471692022f,
+ 0.0802435423726812f, 0.0801728602597226f, 0.0801022008417819f,
+ 0.0800315641302702f, 0.0799609501365547f, 0.0798903588719589f,
+ 0.0798197903477619f, 0.0797492445751992f, 0.0796787215654622f,
+ 0.0796082213296982f, 0.0795377438790107f, 0.0794672892244592f,
+ 0.0793968573770592f, 0.0793264483477822f, 0.0792560621475557f,
+ 0.0791856987872634f, 0.0791153582777449f, 0.0790450406297956f,
+ 0.0789747458541675f, 0.0789044739615680f, 0.0788342249626610f,
+ 0.0787639988680661f, 0.0786937956883591f, 0.0786236154340719f,
+ 0.0785534581156922f, 0.0784833237436637f, 0.0784132123283866f,
+ 0.0783431238802165f, 0.0782730584094654f, 0.0782030159264013f,
+ 0.0781329964412480f, 0.0780629999641855f, 0.0779930265053501f,
+ 0.0779230760748334f, 0.0778531486826837f, 0.0777832443389050f,
+ 0.0777133630534574f, 0.0776435048362570f, 0.0775736696971760f,
+ 0.0775038576460424f, 0.0774340686926407f, 0.0773643028467107f,
+ 0.0772945601179488f, 0.0772248405160073f, 0.0771551440504945f,
+ 0.0770854707309746f, 0.0770158205669677f, 0.0769461935679505f,
+ 0.0768765897433551f, 0.0768070091025700f, 0.0767374516549394f,
+ 0.0766679174097639f, 0.0765984063762999f, 0.0765289185637596f,
+ 0.0764594539813117f, 0.0763900126380807f, 0.0763205945431470f,
+ 0.0762511997055470f, 0.0761818281342734f, 0.0761124798382747f,
+ 0.0760431548264555f, 0.0759738531076762f, 0.0759045746907537f,
+ 0.0758353195844604f, 0.0757660877975250f, 0.0756968793386320f,
+ 0.0756276942164223f, 0.0755585324394925f, 0.0754893940163953f,
+ 0.0754202789556392f, 0.0753511872656892f, 0.0752821189549660f,
+ 0.0752130740318462f, 0.0751440525046627f, 0.0750750543817043f,
+ 0.0750060796712157f, 0.0749371283813978f, 0.0748682005204073f,
+ 0.0747992960963572f, 0.0747304151173163f, 0.0746615575913094f,
+ 0.0745927235263174f, 0.0745239129302773f, 0.0744551258110818f,
+ 0.0743863621765800f, 0.0699558940269990f, 0.0698871773852553f,
+ 0.0698184842514879f, 0.0697498146333701f, 0.0696811685385305f,
+ 0.0696125459745543f, 0.0695439469489825f, 0.0694753714693121f,
+ 0.0694068195429960f, 0.0693382911774433f, 0.0692697863800191f,
+ 0.0692013051580444f, 0.0691328475187962f, 0.0690644134695077f,
+ 0.0689960030173678f, 0.0689276161695217f, 0.0688592529330704f,
+ 0.0687909133150711f, 0.0687225973225368f, 0.0686543049624368f,
+ 0.0685860362416959f, 0.0685177911671956f, 0.0684495697457728f,
+ 0.0683813719842208f, 0.0683131978892886f, 0.0682450474676814f,
+ 0.0681769207260604f, 0.0681088176710428f, 0.0680407383092017f,
+ 0.0679726826470663f, 0.0679046506911219f, 0.0678366424478096f,
+ 0.0677686579235266f, 0.0677006971246261f, 0.0676327600574174f,
+ 0.0675648467281656f, 0.0674969571430920f, 0.0674290913083737f,
+ 0.0673612492301441f, 0.0672934309144923f, 0.0672256363674636f,
+ 0.0671578655950593f, 0.0670901186032365f, 0.0670223953979085f,
+ 0.0669546959849446f, 0.0668870203701700f, 0.0668193685593660f,
+ 0.0667517405582697f, 0.0666841363725746f, 0.0666165560079299f,
+ 0.0665489994699407f, 0.0664814667641684f, 0.0664139578961303f,
+ 0.0663464728712994f, 0.0662790116951054f, 0.0662115743729332f,
+ 0.0661441609101242f, 0.0660767713119756f, 0.0660094055837408f,
+ 0.0659420637306289f, 0.0658747457578054f, 0.0658074516703914f,
+ 0.0657401814734641f, 0.0656729351720569f, 0.0656057127711590f,
+ 0.0655385142757157f, 0.0654713396906282f, 0.0654041890207538f,
+ 0.0653370622709057f, 0.0652699594458532f, 0.0652028805503216f,
+ 0.0651358255889920f, 0.0650687945665018f, 0.0650017874874442f,
+ 0.0649348043563684f, 0.0648678451777795f, 0.0648009099561390f,
+ 0.0647339986958640f, 0.0646671114013277f, 0.0646002480768593f,
+ 0.0645334087267441f, 0.0644665933552233f, 0.0643998019664940f,
+ 0.0643330345647095f, 0.0642662911539789f, 0.0641995717383674f,
+ 0.0641328763218963f, 0.0640662049085427f, 0.0639995575022397f,
+ 0.0639329341068766f, 0.0638663347262984f, 0.0637997593643063f,
+ 0.0637332080246576f, 0.0636666807110652f, 0.0636001774271983f,
+ 0.0635336981766821f, 0.0634672429630977f, 0.0634008117899821f,
+ 0.0633344046608284f, 0.0632680215790859f, 0.0632016625481595f,
+ 0.0631353275714102f, 0.0630690166521551f, 0.0630027297936674f,
+ 0.0629364669991760f, 0.0628702282718661f, 0.0628040136148784f,
+ 0.0627378230313101f, 0.0626716565242143f, 0.0626055140965999f,
+ 0.0625393957514318f, 0.0624733014916310f, 0.0624072313200746f,
+ 0.0623411852395954f, 0.0622751632529823f, 0.0622091653629804f,
+ 0.0621431915722904f, 0.0620772418835694f, 0.0620113162994302f,
+ 0.0619454148224416f, 0.0618795374551285f, 0.0618136841999718f,
+ 0.0617478550594083f, 0.0616820500358309f, 0.0616162691315882f,
+ 0.0615505123489852f, 0.0614847796902825f, 0.0614190711576971f,
+ 0.0613533867534016f, 0.0612877264795248f, 0.0612220903381512f,
+ 0.0611564783313218f, 0.0610908904610332f, 0.0610253267292380f,
+ 0.0609597871378448f, 0.0608942716887185f, 0.0608287803836795f,
+ 0.0607633132245045f, 0.0606978702129261f, 0.0606324513506329f,
+ 0.0605670566392694f, 0.0605016860804361f, 0.0604363396756896f,
+ 0.0603710174265425f, 0.0603057193344631f, 0.0602404454008760f,
+ 0.0601751956271616f, 0.0601099700146564f, 0.0600447685646528f,
+ 0.0599795912783991f, 0.0599144381570998f, 0.0598493092019153f,
+ 0.0597842044139619f, 0.0597191237943117f, 0.0596540673439933f,
+ 0.0595890350639909f, 0.0595240269552448f, 0.0594590430186511f,
+ 0.0593940832550622f, 0.0593291476652861f, 0.0592642362500872f,
+ 0.0591993490101854f, 0.0591344859462571f, 0.0590696470589343f,
+ 0.0590048323488052f, 0.0589400418164136f, 0.0588752754622598f,
+ 0.0588105332867999f, 0.0587458152904457f, 0.0586811214735651f,
+ 0.0586164518364824f, 0.0585518063794773f, 0.0584871851027858f,
+ 0.0584225880065996f, 0.0583580150910669f, 0.0582934663562913f,
+ 0.0582289418023328f, 0.0581644414292068f, 0.0580999652368856f,
+ 0.0580355132252967f, 0.0579710853943238f, 0.0579066817438065f,
+ 0.0578423022735407f, 0.0577779469832779f, 0.0577136158727258f,
+ 0.0576493089415478f, 0.0575850261893637f, 0.0575207676157490f,
+ 0.0574565332202351f, 0.0573923230023095f, 0.0573281369614158f,
+ 0.0572639750969533f, 0.0571998374082775f, 0.0571357238946997f,
+ 0.0570716345554873f, 0.0570075693898635f, 0.0569435283970079f,
+ 0.0568795115760553f, 0.0568155189260974f, 0.0567515504461811f,
+ 0.0566876061353098f, 0.0566236859924424f, 0.0565597900164942f,
+ 0.0564959182063363f, 0.0564320705607957f, 0.0563682470786554f,
+ 0.0563044477586545f, 0.0562406725994879f, 0.0561769215998064f,
+ 0.0561131947582173f, 0.0560494920732831f, 0.0559858135435229f,
+ 0.0559221591674113f, 0.0558585289433793f, 0.0557949228698135f,
+ 0.0557313409450567f, 0.0556677831674074f, 0.0556042495351205f,
+ 0.0555407400464066f, 0.0554772546994322f, 0.0554137934923198f,
+ 0.0553503564231481f, 0.0552869434899515f, 0.0552235546907205f,
+ 0.0551601900234014f, 0.0550968494858967f, 0.0550335330760648f,
+ 0.0549702407917199f, 0.0549069726306323f, 0.0548437285905283f,
+ 0.0547805086690902f, 0.0547173128639560f, 0.0546541411727200f,
+ 0.0545909935929322f, 0.0545278701220988f, 0.0544647707576817f,
+ 0.0544016954970989f, 0.0543386443377246f, 0.0542756172768886f,
+ 0.0542126143118766f, 0.0541496354399307f, 0.0540866806582487f,
+ 0.0540237499639842f, 0.0539608433542472f, 0.0538979608261031f,
+ 0.0538351023765739f, 0.0537722680026371f, 0.0537094577012262f,
+ 0.0536466714692308f, 0.0535839093034965f, 0.0535211712008247f,
+ 0.0534584571579729f, 0.0533957671716543f, 0.0533331012385385f,
+ 0.0532704593552508f, 0.0532078415183724f, 0.0531452477244405f,
+ 0.0530826779699484f, 0.0530201322513452f, 0.0529576105650360f,
+ 0.0528951129073819f, 0.0528326392746999f, 0.0527701896632632f,
+ 0.0527077640693004f, 0.0526453624889966f, 0.0525829849184928f,
+ 0.0525206313538857f, 0.0524583017912279f, 0.0523959962265285f,
+ 0.0523337146557520f, 0.0522714570748190f, 0.0522092234796062f,
+ 0.0521470138659462f, 0.0520848282296275f, 0.0520226665663946f,
+ 0.0519605288719478f, 0.0518984151419437f, 0.0518363253719946f,
+ 0.0517742595576687f, 0.0517122176944903f, 0.0516501997779397f,
+ 0.0515882058034530f, 0.0515262357664224f, 0.0514642896621959f,
+ 0.0514023674860775f, 0.0513404692333274f, 0.0512785948991613f,
+ 0.0512167444787511f, 0.0511549179672250f, 0.0510931153596663f,
+ 0.0510313366511152f, 0.0509695818365671f, 0.0509078509109738f,
+ 0.0508461438692430f, 0.0507844607062381f, 0.0507228014167787f,
+ 0.0506611659956403f, 0.0505995544375543f, 0.0505379667372080f,
+ 0.0504764028892448f, 0.0504148628882640f, 0.0503533467288209f,
+ 0.0502918544054265f, 0.0502303859125480f, 0.0501689412446085f,
+ 0.0501075203959871f, 0.0500461233610187f, 0.0499847501339942f,
+ 0.0499234007091606f, 0.0498620750807206f, 0.0498007732428331f,
+ 0.0497394951896126f, 0.0496782409151302f, 0.0496170104134122f,
+ 0.0495558036784412f, 0.0494946207041559f, 0.0494334614844505f,
+ 0.0493723260131757f, 0.0493112142841377f, 0.0492501262910988f,
+ 0.0491890620277774f, 0.0491280214878476f, 0.0490670046649396f,
+ 0.0490060115526395f, 0.0489450421444893f, 0.0488840964339871f,
+ 0.0488231744145867f, 0.0487622760796981f, 0.0487014014226872f,
+ 0.0486405504368756f, 0.0485797231155411f, 0.0485189194519174f,
+ 0.0484581394391941f, 0.0483973830705168f, 0.0483366503389869f,
+ 0.0482759412376620f, 0.0482152557595553f, 0.0481545938976364f,
+ 0.0480939556448302f, 0.0480333409940183f, 0.0479727499380377f,
+ 0.0479121824696815f, 0.0478516385816988f, 0.0477911182667946f,
+ 0.0477306215176298f, 0.0476701483268213f, 0.0476096986869419f,
+ 0.0475492725905205f, 0.0474888700300417f, 0.0474284909979461f,
+ 0.0473681354866303f, 0.0473078034884470f, 0.0472474949957045f,
+ 0.0471872100006673f, 0.0471269484955557f, 0.0470667104725461f,
+ 0.0470064959237706f, 0.0469463048413175f, 0.0468861372172308f,
+ 0.0468259930435107f, 0.0467658723121130f, 0.0467057750149499f,
+ 0.0466457011438889f, 0.0465856506907542f, 0.0465256236473254f,
+ 0.0464656200053382f, 0.0464056397564841f, 0.0463456828924109f,
+ 0.0462857494047220f, 0.0462258392849768f, 0.0461659525246906f,
+ 0.0461060891153350f, 0.0460462490483370f, 0.0459864323150799f,
+ 0.0459266389069028f, 0.0458668688151008f, 0.0458071220309249f,
+ 0.0457473985455820f, 0.0456876983502350f, 0.0456280214360027f,
+ 0.0455683677939599f, 0.0455087374151372f, 0.0454491302905213f,
+ 0.0453895464110547f, 0.0453299857676360f, 0.0452704483511194f,
+ 0.0452109341523154f, 0.0451514431619903f, 0.0450919753708663f,
+ 0.0450325307696215f, 0.0449731093488901f, 0.0449137110992621f,
+ 0.0448543360112835f, 0.0447949840754560f, 0.0447356552822377f,
+ 0.0446763496220422f, 0.0446170670852392f, 0.0445578076621543f,
+ 0.0444985713430691f, 0.0444393581182212f, 0.0443801679778039f,
+ 0.0443210009119664f, 0.0442618569108143f, 0.0442027359644086f,
+ 0.0441436380627666f, 0.0440845631958612f, 0.0440255113536215f,
+ 0.0439664825259325f, 0.0439074767026350f, 0.0438484938735257f,
+ 0.0437895340283575f, 0.0437305971568391f, 0.0436716832486349f,
+ 0.0436127922933654f, 0.0435539242806073f, 0.0434950791998928f,
+ 0.0434362570407102f, 0.0433774577925038f, 0.0433186814446737f,
+ 0.0432599279865760f, 0.0432011974075228f, 0.0431424896967819f,
+ 0.0430838048435774f, 0.0430251428370888f, 0.0429665036664521f,
+ 0.0429078873207587f, 0.0428492937890565f, 0.0427907230603488f,
+ 0.0427321751235950f, 0.0426736499677106f, 0.0426151475815668f,
+ 0.0425566679539909f, 0.0424982110737659f, 0.0424397769296309f,
+ 0.0423813655102811f, 0.0423229768043671f, 0.0422646108004960f,
+ 0.0422062674872303f, 0.0421479468530891f, 0.0420896488865467f,
+ 0.0420313735760336f, 0.0419731209099364f, 0.0419148908765975f,
+ 0.0418566834643152f, 0.0417984986613437f, 0.0417403364558930f,
+ 0.0416821968361295f, 0.0416240797901751f, 0.0415659853061075f,
+ 0.0415079133719608f, 0.0414498639757248f, 0.0413918371053450f,
+ 0.0413338327487231f, 0.0412758508937167f, 0.0412178915281392f,
+ 0.0411599546397599f, 0.0411020402163043f, 0.0410441482454534f,
+ 0.0409862787148446f, 0.0409284316120707f, 0.0408706069246808f,
+ 0.0408128046401798f, 0.0407550247460286f, 0.0406972672296439f,
+ 0.0406395320783983f, 0.0405818192796204f, 0.0405241288205948f,
+ 0.0404664606885619f, 0.0404088148707178f, 0.0403511913542151f,
+ 0.0402935901261618f, 0.0402360111736221f, 0.0401784544836158f,
+ 0.0401209200431191f, 0.0400634078390637f, 0.0400059178583375f,
+ 0.0399484500877839f, 0.0398910045142029f, 0.0398335811243497f,
+ 0.0397761799049359f, 0.0397188008426288f, 0.0396614439240516f,
+ 0.0396041091357837f, 0.0395467964643600f, 0.0394895058962715f,
+ 0.0394322374179654f, 0.0393749910158443f, 0.0393177666762671f,
+ 0.0392605643855483f, 0.0392033841299587f, 0.0391462258957247f,
+ 0.0390890896690288f, 0.0390319754360092f, 0.0389748831827604f,
+ 0.0389178128953323f, 0.0388607645597312f, 0.0388037381619189f,
+ 0.0387467336878135f, 0.0386897511232887f, 0.0386327904541742f,
+ 0.0385758516662558f, 0.0385189347452749f, 0.0384620396769291f,
+ 0.0384051664468718f, 0.0383483150407121f, 0.0382914854440155f,
+ 0.0382346776423029f, 0.0381778916210515f, 0.0381211273656940f,
+ 0.0380643848616195f, 0.0380076640941726f, 0.0379509650486541f,
+ 0.0378942877103206f, 0.0378376320643845f, 0.0377809980960143f,
+ 0.0377243857903341f, 0.0376677951324245f, 0.0376112261073215f,
+ 0.0375546787000170f, 0.0374981528954590f, 0.0374416486785515f,
+ 0.0373851660341542f, 0.0373287049470828f, 0.0372722654021088f,
+ 0.0372158473839598f, 0.0371594508773193f, 0.0371030758668266f,
+ 0.0370467223370766f, 0.0369903902726209f, 0.0369340796579662f,
+ 0.0368777904775757f, 0.0368215227158680f, 0.0367652763572181f,
+ 0.0367090513859566f, 0.0366528477863700f, 0.0365966655427007f,
+ 0.0365405046391474f, 0.0364843650598642f, 0.0364282467889613f,
+ 0.0363721498105048f, 0.0363160741085168f, 0.0362600196669752f,
+ 0.0362039864698137f, 0.0361479745009222f, 0.0360919837441462f,
+ 0.0360360141832873f, 0.0359800658021030f, 0.0359241385843064f,
+ 0.0358682325135671f, 0.0358123475735100f, 0.0357564837477163f,
+ 0.0357006410197228f, 0.0356448193730226f, 0.0355890187910643f,
+ 0.0355332392572527f, 0.0354774807549481f, 0.0354217432674673f,
+ 0.0353660267780825f, 0.0353103312700220f, 0.0352546567264699f,
+ 0.0351990031305666f, 0.0351433704654078f, 0.0350877587140454f,
+ 0.0350321678594873f, 0.0349765978846971f, 0.0349210487725945f,
+ 0.0348655205060549f, 0.0348100130679097f, 0.0347545264409461f,
+ 0.0346990606079075f, 0.0346436155514929f, 0.0345881912543573f,
+ 0.0345327876991115f, 0.0344774048683225f, 0.0344220427445127f,
+ 0.0343667013101609f, 0.0343113805477016f, 0.0342560804395250f,
+ 0.0342008009679776f, 0.0341455421153614f, 0.0340903038639347f,
+ 0.0340350861959113f, 0.0339798890934610f, 0.0339247125387098f,
+ 0.0338695565137393f, 0.0338144210005871f, 0.0337593059812464f,
+ 0.0337042114376669f, 0.0336491373517538f, 0.0335940837053681f,
+ 0.0335390504803269f, 0.0334840376584033f, 0.0334290452213260f,
+ 0.0333740731507797f, 0.0333191214284051f, 0.0332641900357988f,
+ 0.0332092789545132f, 0.0331543881660566f, 0.0330995176518931f,
+ 0.0330446673934429f, 0.0329898373720821f, 0.0329350275691426f,
+ 0.0328802379659119f, 0.0328254685436341f, 0.0327707192835085f,
+ 0.0327159901666906f, 0.0326612811742918f, 0.0326065922873795f,
+ 0.0325519234869767f, 0.0324972747540625f, 0.0324426460695717f,
+ 0.0323880374143954f, 0.0323334487693801f, 0.0322788801153286f,
+ 0.0322243314329991f, 0.0321698027031064f, 0.0321152939063204f,
+ 0.0320608050232677f, 0.0320063360345299f, 0.0319518869206454f,
+ 0.0318974576621078f, 0.0318430482393670f, 0.0317886586328284f,
+ 0.0317342888228537f, 0.0316799387897604f, 0.0316256085138217f,
+ 0.0315712979752667f, 0.0315170071542806f, 0.0314627360310044f,
+ 0.0314084845855349f, 0.0313542527979248f, 0.0313000406481829f,
+ 0.0312458481162737f, 0.0311916751821174f, 0.0311375218255906f,
+ 0.0310833880265254f, 0.0310292737647098f, 0.0309751790198877f,
+ 0.0309211037717592f, 0.0308670479999799f, 0.0308130116841615f,
+ 0.0307589948038714f, 0.0307049973386331f, 0.0306510192679259f,
+ 0.0305970605711850f, 0.0305431212278014f, 0.0304892012171220f,
+ 0.0304353005184498f, 0.0303814191110434f, 0.0303275569741174f,
+ 0.0302737140868423f, 0.0302198904283447f, 0.0301660859777065f,
+ 0.0301123007139661f, 0.0300585346161174f, 0.0300047876631105f,
+ 0.0299510598338510f, 0.0298973511072006f, 0.0298436614619771f,
+ 0.0297899908769537f, 0.0297363393308599f, 0.0296827068023808f,
+ 0.0296290932701575f, 0.0295754987127871f, 0.0295219231088224f,
+ 0.0294683664367722f, 0.0294148286751011f, 0.0293613098022296f,
+ 0.0293078097965342f, 0.0292543286363469f, 0.0292008662999562f,
+ 0.0291474227656060f, 0.0290939980114962f, 0.0290405920157826f,
+ 0.0289872047565770f, 0.0289338362119469f, 0.0288804863599157f,
+ 0.0288271551784627f, 0.0287738426455233f, 0.0287205487389884f,
+ 0.0286672734367052f, 0.0286140167164761f, 0.0285607785560604f,
+ 0.0285075589331723f, 0.0284543578254825f, 0.0284011752106171f,
+ 0.0283480110661588f, 0.0282948653696453f, 0.0282417380985708f,
+ 0.0281886292303851f, 0.0281355387424940f, 0.0280824666122592f,
+ 0.0280294128169981f, 0.0279763773339841f, 0.0279233601404466f,
+ 0.0278703612135707f, 0.0278173805304972f, 0.0277644180683234f,
+ 0.0277114738041018f, 0.0276585477148412f, 0.0276056397775058f,
+ 0.0275527499690165f, 0.0274998782662493f, 0.0274470246460364f,
+ 0.0273941890851657f, 0.0273413715603814f, 0.0272885720483831f,
+ 0.0272357905258265f, 0.0271830269693230f, 0.0271302813554403f,
+ 0.0270775536607015f, 0.0270248438615858f, 0.0269721519345281f,
+ 0.0269194778559194f, 0.0268668216021066f, 0.0268141831493923f,
+ 0.0267615624740348f, 0.0267089595522488f, 0.0266563743602045f,
+ 0.0266038068740280f, 0.0265512570698012f, 0.0264987249235622f,
+ 0.0264462104113047f, 0.0263937135089783f, 0.0263412341924885f,
+ 0.0262887724376968f, 0.0262363282204203f, 0.0261839015164322f,
+ 0.0261314923014614f, 0.0260791005511929f, 0.0260267262412675f,
+ 0.0259743693472816f, 0.0259220298447877f, 0.0258697077092944f,
+ 0.0258174029162656f, 0.0257651154411217f, 0.0257128452592383f,
+ 0.0256605923459475f, 0.0256083566765370f, 0.0255561382262503f,
+ 0.0255039369702867f, 0.0254517528838017f, 0.0253995859419064f,
+ 0.0253474361196679f, 0.0252953033921090f, 0.0252431877342086f,
+ 0.0251910891209013f, 0.0251390075270776f, 0.0250869429275840f,
+ 0.0250348952972226f, 0.0249828646107516f, 0.0249308508428848f,
+ 0.0248788539682924f, 0.0248268739615999f, 0.0247749107973889f,
+ 0.0247229644501969f, 0.0246710348945172f, 0.0246191221047991f,
+ 0.0245672260554474f, 0.0245153467208232f, 0.0244634840752433f,
+ 0.0244116380929803f, 0.0243598087482627f, 0.0243079960152748f,
+ 0.0242561998681570f, 0.0242044202810054f, 0.0241526572278720f,
+ 0.0241009106827644f, 0.0240491806196466f, 0.0239974670124380f,
+ 0.0239457698350141f, 0.0238940890612061f, 0.0238424246648012f,
+ 0.0237907766195426f, 0.0237391448991289f, 0.0236875294772150f,
+ 0.0236359303274115f, 0.0235843474232849f, 0.0235327807383576f,
+ 0.0234812302461075f, 0.0234296959199691f, 0.0233781777333319f,
+ 0.0233266756595420f, 0.0232751896719008f, 0.0232237197436660f,
+ 0.0231722658480509f, 0.0231208279582248f, 0.0230694060473126f,
+ 0.0230180000883954f, 0.0229666100545100f, 0.0229152359186491f,
+ 0.0228638776537611f, 0.0228125352327506f, 0.0227612086284777f,
+ 0.0227098978137585f, 0.0226586027613650f, 0.0226073234440251f,
+ 0.0225560598344226f, 0.0225048119051967f, 0.0224535796289430f,
+ 0.0224023629782129f, 0.0223511619255133f, 0.0222999764433073f,
+ 0.0222488065040137f, 0.0221976520800073f, 0.0221465131436186f,
+ 0.0220953896671340f, 0.0220442816227956f, 0.0219931889828018f,
+ 0.0219421117193066f, 0.0218910498044196f, 0.0218400032102066f,
+ 0.0217889719086893f, 0.0217379558718450f, 0.0216869550716069f,
+ 0.0216359694798642f, 0.0215849990684619f, 0.0215340438092009f,
+ 0.0214831036738377f, 0.0214321786340850f, 0.0213812686616112f,
+ 0.0213303737280405f, 0.0212794938049529f, 0.0212286288638847f,
+ 0.0255395068839051f, 0.0254886718213066f, 0.0254378516550702f,
+ 0.0253870463565555f, 0.0253362558970777f, 0.0252854802479078f,
+ 0.0252347193802728f, 0.0251839732653554f, 0.0251332418742945f,
+ 0.0250825251781844f, 0.0250318231480754f, 0.0249811357549739f,
+ 0.0249304629698419f, 0.0248798047635972f, 0.0248291611071137f,
+ 0.0247785319712210f, 0.0247279173267045f, 0.0246773171443056f,
+ 0.0246267313947214f, 0.0245761600486050f, 0.0245256030765652f,
+ 0.0244750604491668f, 0.0244245321369303f, 0.0243740181103322f,
+ 0.0243235183398047f, 0.0242730327957360f, 0.0242225614484700f,
+ 0.0241721042683066f, 0.0241216612255015f, 0.0240712322902661f,
+ 0.0240208174327678f, 0.0239704166231300f, 0.0239200298314316f,
+ 0.0238696570277076f, 0.0238192981819486f, 0.0237689532641015f,
+ 0.0237186222440686f, 0.0236683050917082f, 0.0236180017768345f,
+ 0.0235677122692175f, 0.0235174365385832f, 0.0234671745546130f,
+ 0.0234169262869447f, 0.0233666917051716f, 0.0233164707788430f,
+ 0.0232662634774639f, 0.0232160697704954f, 0.0231658896273542f,
+ 0.0231157230174128f, 0.0230655699099999f, 0.0230154302743997f,
+ 0.0229653040798524f, 0.0229151912955540f, 0.0228650918906563f,
+ 0.0228150058342672f, 0.0227649330954500f, 0.0227148736432244f,
+ 0.0226648274465652f, 0.0226147944744040f, 0.0225647746956273f,
+ 0.0225147680790781f, 0.0224647745935549f, 0.0224147942078123f,
+ 0.0223648268905605f, 0.0223148726104657f, 0.0222649313361497f,
+ 0.0222150030361906f, 0.0221650876791220f, 0.0221151852334334f,
+ 0.0220652956675701f, 0.0220154189499333f, 0.0219655550488802f,
+ 0.0219157039327235f, 0.0218658655697320f, 0.0218160399281303f,
+ 0.0217662269760989f, 0.0217164266817738f, 0.0216666390132473f,
+ 0.0216168639385673f, 0.0215671014257376f, 0.0215173514427178f,
+ 0.0214676139574232f, 0.0214178889377253f, 0.0213681763514512f,
+ 0.0213184761663838f, 0.0212687883502620f, 0.0212191128707804f,
+ 0.0211694496955896f, 0.0211197987922958f, 0.0210701601284612f,
+ 0.0210205336716039f, 0.0209709193891977f, 0.0209213172486724f,
+ 0.0208717272174133f, 0.0208221492627619f, 0.0207725833520154f,
+ 0.0207230294524270f, 0.0206734875312053f, 0.0206239575555151f,
+ 0.0205744394924771f, 0.0205249333091677f, 0.0204754389726188f,
+ 0.0204259564498189f, 0.0203764857077117f, 0.0203270267131969f,
+ 0.0202775794331301f, 0.0202281438343228f, 0.0201787198835422f,
+ 0.0201293075475113f, 0.0200799067929092f, 0.0200305175863706f,
+ 0.0199811398944860f, 0.0199317736838018f, 0.0198824189208204f,
+ 0.0198330755720000f, 0.0197837436037543f, 0.0197344229824530f,
+ 0.0196851136744220f, 0.0196358156459426f, 0.0195865288632520f,
+ 0.0195372532925434f, 0.0194879888999657f, 0.0194387356516237f,
+ 0.0193894935135779f, 0.0193402624518448f, 0.0192910424323968f,
+ 0.0192418334211618f, 0.0191926353840239f, 0.0191434482868227f,
+ 0.0190942720953539f, 0.0190451067753690f, 0.0189959522925752f,
+ 0.0189468086126355f, 0.0188889190431616f, 0.0188228895446890f,
+ 0.0187568748920607f, 0.0186908750819390f, 0.0186248901109865f,
+ 0.0185589199758671f, 0.0184929646732450f, 0.0184270241997851f,
+ 0.0183610985521537f, 0.0182951877270173f, 0.0182292917210430f,
+ 0.0181634105308991f, 0.0180975441532544f, 0.0180316925847787f,
+ 0.0179658558221421f, 0.0179000338620157f, 0.0178342267010716f,
+ 0.0177684343359822f, 0.0177026567634210f, 0.0176368939800620f,
+ 0.0175711459825800f, 0.0175054127676507f, 0.0174396943319504f,
+ 0.0217357186797338f, 0.0216700297925235f, 0.0216043556745757f,
+ 0.0215386963225698f, 0.0214730517331858f, 0.0214074219031045f,
+ 0.0213418068290075f, 0.0212762065075772f, 0.0212106209354964f,
+ 0.0211450501094493f, 0.0210794940261201f, 0.0210139526821943f,
+ 0.0209484260743579f, 0.0208829141992977f, 0.0208174170537012f,
+ 0.0207519346342566f, 0.0206864669376530f, 0.0206210139605803f,
+ 0.0205555756997288f, 0.0204901521517898f, 0.0204247433134555f,
+ 0.0203593491814184f, 0.0202939697523721f, 0.0202286050230107f,
+ 0.0201632549900294f, 0.0200979196501238f, 0.0200325989999903f,
+ 0.0199672930363261f, 0.0199020017558292f, 0.0198367251551984f,
+ 0.0197714632311330f, 0.0197062159803331f, 0.0196409833994998f,
+ 0.0195757654853346f, 0.0195105622345400f, 0.0194453736438190f,
+ 0.0193801997098757f, 0.0193150404294146f, 0.0192498957991409f,
+ 0.0191847658157610f, 0.0191196504759815f, 0.0190545497765102f,
+ 0.0189894637140552f, 0.0189243922853257f, 0.0188593354870315f,
+ 0.0187942933158832f, 0.0187292657685919f, 0.0186642528418697f,
+ 0.0185992545324294f, 0.0185342708369846f, 0.0184693017522493f,
+ 0.0184043472749386f, 0.0183394074017683f, 0.0182744821294548f,
+ 0.0182095714547152f, 0.0181446753742675f, 0.0180797938848304f,
+ 0.0180149269831233f, 0.0179500746658664f, 0.0178852369297804f,
+ 0.0178204137715871f, 0.0177556051880087f, 0.0176908111757684f,
+ 0.0176260317315900f, 0.0175612668521982f, 0.0174965165343181f,
+ 0.0174317807746758f, 0.0173670595699981f, 0.0173023529170125f,
+ 0.0172376608124473f, 0.0171729832530314f, 0.0171083202354946f,
+ 0.0170436717565673f, 0.0169790378129807f, 0.0169144184014667f,
+ 0.0168498135187580f, 0.0167852231615880f, 0.0167206473266909f,
+ 0.0166560860108013f, 0.0165915392106550f, 0.0165270069229884f,
+ 0.0164624891445385f, 0.0163979858720428f, 0.0163334971022403f,
+ 0.0162690228318700f, 0.0162045630576720f, 0.0161401177763870f,
+ 0.0160756869847564f, 0.0160112706795224f, 0.0159468688574280f,
+ 0.0158824815152168f, 0.0158181086496333f, 0.0157537502574225f,
+ 0.0156894063353304f, 0.0156250768801034f, 0.0155607618884889f,
+ 0.0154964613572351f, 0.0154321752830905f, 0.0153679036628048f,
+ 0.0153036464931283f, 0.0152394037708118f, 0.0151751754926072f,
+ 0.0151109616552667f, 0.0150467622555436f, 0.0149825772901918f,
+ 0.0149184067559660f, 0.0148542506496213f, 0.0147901089679141f,
+ 0.0147259817076010f, 0.0146618688654396f, 0.0145977704381882f,
+ 0.0145336864226058f, 0.0144696168154521f, 0.0144055616134876f,
+ 0.0143415208134734f, 0.0142774944121715f, 0.0142134824063446f,
+ 0.0141494847927560f, 0.0140855015681696f, 0.0140215327293505f,
+ 0.0139575782730643f, 0.0182553662036547f, 0.0181914405027335f,
+ 0.0181275291746461f, 0.0180636322161610f, 0.0179997496240473f,
+ 0.0179358813950749f, 0.0178720275260146f, 0.0178081880136376f,
+ 0.0177443628547161f, 0.0176805520460228f, 0.0176167555843314f,
+ 0.0175529734664161f, 0.0174892056890518f, 0.0174254522490144f,
+ 0.0173617131430802f, 0.0172979883680264f, 0.0172342779206310f,
+ 0.0171705817976724f, 0.0171068999959302f, 0.0170432325121844f,
+ 0.0169795793432156f, 0.0169159404858055f, 0.0168523159367363f,
+ 0.0167887056927909f, 0.0167251097507530f, 0.0166615281074072f,
+ 0.0165979607595384f, 0.0165344077039326f, 0.0164708689373761f,
+ 0.0164073444566565f, 0.0163438342585618f, 0.0162803383398807f,
+ 0.0162168566974025f, 0.0161533893279177f, 0.0160899362282169f,
+ 0.0160264973950919f, 0.0159630728253350f, 0.0158996625157394f,
+ 0.0158362664630987f, 0.0157728846642075f, 0.0157095171158610f,
+ 0.0156461638148553f, 0.0155828247579869f, 0.0155194999420533f,
+ 0.0154561893638526f, 0.0153928930201836f, 0.0153296109078459f,
+ 0.0152663430236398f, 0.0152030893643661f, 0.0151398499268268f,
+ 0.0150766247078242f, 0.0150134137041614f, 0.0149502169126424f,
+ 0.0148870343300717f, 0.0148238659532546f, 0.0147607117789972f,
+ 0.0146975718041061f, 0.0146344460253890f, 0.0145713344396539f,
+ 0.0145082370437097f, 0.0144451538343661f, 0.0143820848084334f,
+ 0.0143190299627227f, 0.0142559892940457f, 0.0141929627992148f,
+ 0.0141299504750434f, 0.0140669523183453f, 0.0140039683259351f,
+ 0.0139409984946283f, 0.0138780428212408f, 0.0138151013025895f,
+ 0.0137521739354917f, 0.0136892607167660f, 0.0136263616432309f,
+ 0.0135634767117064f, 0.0135006059190125f, 0.0134377492619707f,
+ 0.0133749067374024f, 0.0133120783421303f, 0.0132492640729776f,
+ 0.0131864639267682f, 0.0131236779003268f, 0.0130609059904787f,
+ 0.0129981481940499f, 0.0129354045078674f, 0.0128726749287585f,
+ 0.0128099594535516f, 0.0127472580790754f, 0.0126845708021597f,
+ 0.0126218976196349f, 0.0125592385283320f, 0.0124965935250826f,
+ 0.0124339626067194f, 0.0123713457700756f, 0.0123087430119851f,
+ 0.0122461543292824f, 0.0121835797188031f, 0.0121210191773830f,
+ 0.0120584727018589f, 0.0119959402890683f, 0.0119334219358495f,
+ 0.0118709176390412f, 0.0118084273954832f, 0.0117459512020156f,
+ 0.0116834890554797f, 0.0116210409527169f, 0.0115586068905700f,
+ 0.0114961868658818f, 0.0114337808754965f, 0.0113713889162585f,
+ 0.0113090109850131f, 0.0112466470786063f, 0.0111842971938848f,
+ 0.0111219613276961f, 0.0110596394768881f, 0.0109973316383098f,
+ 0.0152967658163884f, 0.0152344859928189f, 0.0151722201720297f,
+ 0.0151099683508726f, 0.0150477305262000f, 0.0149855066948649f,
+ 0.0149232968537211f, 0.0148611009996230f, 0.0147989191294260f,
+ 0.0147367512399860f, 0.0146745973281595f, 0.0146124573908037f,
+ 0.0145503314247770f, 0.0144882194269378f, 0.0144261213941456f,
+ 0.0143640373232607f, 0.0143019672111439f, 0.0142399110546566f,
+ 0.0141778688506612f, 0.0141158405960207f, 0.0140538262875987f,
+ 0.0139918259222596f, 0.0139298394968685f, 0.0138678670082912f,
+ 0.0138059084533941f, 0.0137439638290446f, 0.0136820331321104f,
+ 0.0136201163594601f, 0.0135582135079633f, 0.0134963245744897f,
+ 0.0134344495559101f, 0.0133725884490961f, 0.0133107412509195f,
+ 0.0132489079582535f, 0.0131870885679713f, 0.0131252830769473f,
+ 0.0130634914820565f, 0.0130017137801745f, 0.0129399499681775f,
+ 0.0128782000429427f, 0.0128164640013478f, 0.0127547418402713f,
+ 0.0126930335565922f, 0.0126313391471905f, 0.0125696586089468f,
+ 0.0125079919387422f, 0.0124463391334587f, 0.0123847001899790f,
+ 0.0123230751051865f, 0.0122614638759652f, 0.0121998664991998f,
+ 0.0121382829717759f, 0.0120767132905796f, 0.0120151574524978f,
+ 0.0119536154544179f, 0.0118920872932283f, 0.0118305729658180f,
+ 0.0117690724690765f, 0.0117075857998943f, 0.0116461129551625f,
+ 0.0115846539317728f, 0.0115232087266176f, 0.0114617773365900f,
+ 0.0114003597585841f, 0.0113389559894942f, 0.0112775660262157f,
+ 0.0112161898656444f, 0.0111548275046771f, 0.0110934789402111f,
+ 0.0110321441691445f, 0.0109708231883759f, 0.0109095159948048f,
+ 0.0108482225853314f, 0.0107869429568564f, 0.0107256771062815f,
+ 0.0106644250305088f, 0.0106031867264412f, 0.0105419621909824f,
+ 0.0104807514210367f, 0.0104195544135091f, 0.0103583711653052f,
+ 0.0102972016733315f, 0.0102360459344952f, 0.0101749039457040f,
+ 0.0101137757038663f, 0.0100526612058913f, 0.00999156044868904f,
+ 0.00993047342916997f, 0.00986940014424537f, 0.00980834059082714f,
+ 0.00974729476582803f, 0.00968626266616141f, 0.00962524428874123f,
+ 0.00956423963048225f, 0.00950324868829994f, 0.00944227145911042f,
+ 0.00938130793983050f, 0.00932035812737764f, 0.00925942201867014f,
+ 0.00919849961062680f, 0.00913759090016730f, 0.00907669588421184f,
+ 0.00901581455968142f, 0.00895494692349780f, 0.00889409297258320f,
+ 0.00883325270386071f, 0.00877242611425416f, 0.00871161320068786f,
+ 0.00865081396008705f, 0.00859002838937745f, 0.00852925648548564f,
+ 0.00846849824533880f, 0.00840775366586477f, 0.00834702274399218f,
+ 0.00828630547665032f, 0.00822560186076915f, 0.00816491189327928f,
+ 0.00810423557111206f, 0.00804357289119956f, 0.00798292385047450f,
+ 0.00792228844587023f, 0.00786166667432087f, 0.00780105853276131f,
+ 0.00774046401812689f, 0.00767988312735390f, 0.00761931585737907f,
+ 0.00755876220514012f, 0.00749822216757512f, 0.0117994237492008f,
+ 0.0117389109318013f, 0.0116784117198946f, 0.0116179261104218f,
+ 0.0115574541003245f, 0.0114969956865451f, 0.0114365508660266f,
+ 0.0113761196357128f, 0.0113157019925481f, 0.0112552979334775f,
+ 0.0111949074554470f, 0.0111345305554030f, 0.0110741672302926f,
+ 0.0110138174770638f, 0.0109534812926650f, 0.0108931586740455f,
+ 0.0108328496181552f, 0.0107725541219447f, 0.0107122721823654f,
+ 0.0106520037963691f, 0.0105917489609085f, 0.0105315076729371f,
+ 0.0104712799294088f, 0.0104110657272783f, 0.0103508650635009f,
+ 0.0102906779350330f, 0.0102305043388311f, 0.0101703442718527f,
+ 0.0101101977310560f, 0.0100500647133998f, 0.00998994521584351f,
+ 0.00992983923534746f, 0.00986974676887237f, 0.00980966781338000f,
+ 0.00974960236583244f, 0.00968955042319258f, 0.00962951198242412f,
+ 0.00956948704049132f, 0.00950947559435911f, 0.00944947764099319f,
+ 0.00938949317735982f, 0.00932952220042610f, 0.00926956470715973f,
+ 0.00920962069452902f, 0.00914969015950301f, 0.00908977309905157f,
+ 0.00902986951014501f, 0.00896997938975452f, 0.00891010273485171f,
+ 0.00885023954240927f, 0.00879038980940028f, 0.00873055353279850f,
+ 0.00867073070957841f, 0.00861092133671532f, 0.00855112541118508f,
+ 0.00849134292996412f, 0.00843157389002974f, 0.00837181828835992f,
+ 0.00831207612193319f, 0.00825234738772879f, 0.00819263208272664f,
+ 0.00813293020390743f, 0.00807324174825247f, 0.00801356671274367f,
+ 0.00795390509436372f, 0.00789425689009604f, 0.00783462209692454f,
+ 0.00777500071183396f, 0.00771539273180966f, 0.00765579815383771f,
+ 0.00759621697490487f, 0.00753664919199842f, 0.00747709480210662f,
+ 0.00741755380221809f, 0.00735802618932235f, 0.00729851196040943f,
+ 0.00723901111247016f, 0.00717952364249613f, 0.00712004954747930f,
+ 0.00706058882441252f, 0.00700114147028941f, 0.00694170748210410f,
+ 0.00688228685685138f, 0.00682287959152672f, 0.00676348568312646f,
+ 0.00670410512864744f, 0.00664473792508719f, 0.00658538406944387f,
+ 0.00652604355871650f, 0.00646671638990454f, 0.00640740256000838f,
+ 0.00634810206602876f, 0.00628881490496747f, 0.00622954107382667f,
+ 0.00617028056960933f, 0.00611103338931901f, 0.00605179952996010f,
+ 0.00599257898853756f, 0.00593337176205699f, 0.00587417784752470f,
+ 0.00581499724194773f, 0.00575582994233370f, 0.00569667594569095f,
+ 0.00563753524902838f, 0.00557840784935593f, 0.00551929374368371f,
+ 0.00546019292902289f, 0.00540110540238498f, 0.00534203116078258f,
+ 0.00528297020122859f, 0.00522392252073672f, 0.00516488811632138f,
+ 0.00510586698499765f, 0.00504685912378122f, 0.00498786452968852f,
+ 0.00492888319973650f, 0.00486991513094304f, 0.00481096032032652f,
+ 0.00475201876490594f, 0.00469309046170108f, 0.00463417540773242f,
+ 0.00457527360002097f, 0.00451638503558854f, 0.00445750971145748f,
+ 0.00439864762465103f, 0.00433979877219282f, 0.00428096315110732f,
+ 0.00422214075841959f, 0.00416333159115556f, 0.00410453564634156f,
+ 0.00404575292100462f, 0.00398698341217263f, 0.00392822711687407f,
+ 0.00386948403213799f, 0.00381075415499416f, 0.00375203748247305f,
+ 0.00369333401160576f, 0.00363464373942418f, 0.00357596666296056f,
+ 0.00351730277924822f, 0.00345865208532087f, 0.00340001457821293f,
+ 0.00334139025495950f, 0.00328277911259650f, 0.00322418114816031f,
+ 0.00316559635868802f, 0.00310702474121738f, 0.00304846629278699f,
+ 0.00298992101043588f, 0.00293138889120381f, 0.00287286993213121f,
+ 0.00281436413025932f, 0.00275587148262979f, 0.00269739198628516f,
+ 0.00263892563826845f, 0.00258047243562354f, 0.00252203237539478f,
+ 0.00246360545462732f, 0.00240519167036685f, 0.00234679101965996f,
+ 0.00228840349955362f, 0.00223002910709563f, 0.00217166783933437f,
+ 0.00211331969331902f, 0.00205498466609932f, 0.00199666275472560f,
+ 0.00193835395624892f, 0.00188005826772120f, 0.00182177568619468f,
+ 0.00176350620872251f, 0.00170524983235837f, 0.00164700655415667f,
+ 0.00158877637117250f, 0.00153055928046153f, 0.00147235527908007f,
+ 0.00141416436408531f, 0.00135598653253494f, 0.00129782178148719f,
+ 0.00123967010800113f, 0.00118153150913658f, 0.00112340598195376f,
+ 0.00106529352351364f, 0.00100719413087796f, 0.000949107801109128f,
+ 0.000891034531269985f, 0.000832974318424273f, 0.000774927159636230f,
+ 0.000716893051970924f, 0.000658871992493926f, 0.000600863978271471f,
+ 0.000542869006370628f, 0.000484887073858964f, 0.000426918177804714f,
+ 0.00473069032285445f, 0.00467274749092250f, 0.00461481768665678f,
+ 0.00455690090712813f, 0.00449899714940810f, 0.00444110641056905f,
+ 0.00438322868768370f, 0.00432536397782568f, 0.00426751227806910f,
+ 0.00420967358548896f, 0.00415184789716061f, 0.00409403521016033f,
+ 0.00403623552156485f, 0.00397844882845178f, 0.00392067512789918f,
+ 0.00386291441698589f, 0.00380516669279124f, 0.00374743195239552f,
+ 0.00368971019287939f, 0.00363200141132430f, 0.00357430560481226f,
+ 0.00351662277042614f, 0.00345895290524928f, 0.00340129600636568f,
+ 0.00334365207086007f, 0.00328602109581783f, 0.00322840307832495f,
+ 0.00317079801546810f, 0.00311320590433462f, 0.00305562674201249f,
+ 0.00299806052559032f, 0.00294050725215744f, 0.00288296691880374f,
+ 0.00282543952261988f, 0.00276792506069706f, 0.00271042353012718f,
+ 0.00265293492800284f, 0.00259545925141724f, 0.00253799649746422f,
+ 0.00248054666323838f, 0.00242310974583471f, 0.00236568574234924f,
+ 0.00230827464987843f, 0.00225087646551925f, 0.00219349118636958f,
+ 0.00213611880952797f, 0.00207875933209334f, 0.00202141275116546f,
+ 0.00196407906384477f, 0.00190675826723236f, 0.00184945035842982f,
+ 0.00179215533453958f, 0.00173487319266458f, 0.00167760392990851f,
+ 0.00162034754337570f, 0.00156310403017101f, 0.00150587338740016f,
+ 0.00144865561216939f, 0.00139145070158553f, 0.00133425865275616f,
+ 0.00127707946278949f, 0.00121991312879444f, 0.00116275964788048f,
+ 0.00110561901715772f, 0.00104849123373701f, 0.000991376294729840f,
+ 0.000934274197248231f, 0.000877184938404996f, 0.000820108515313556f,
+ 0.000763044925087941f, 0.000705994164842849f, 0.000648956231693587f,
+ 0.000591931122756240f, 0.000534918835147447f, 0.000477919365984458f,
+ 0.000420932712385191f, 0.000363958871468284f, 0.000306997840353040f,
+ 0.000250049616159320f, 0.000193114196007482f, 0.000136191577018996f,
+ 7.92817563154968e-05f, 2.23847310195091e-05f, 0.000000000000000000f,
+ 0.000000000000000000f, 0.000000000000000000f, 0.000000000000000000f,
+ 0.000000000000000000f, 0.000000000000000000f, 0.000000000000000000f,
+ 0.000000000000000000f, 0.000000000000000000f, 0.000000000000000000f,
+ 0.000000000000000000f, 0.000000000000000000f, 0.000000000000000000f,
+ 0.000000000000000000f, 0.000000000000000000f, 0.000000000000000000f,
+ 0.000000000000000000f, 0.000000000000000000f, 0.000000000000000000f,
+ 0.000000000000000000f, 0.000000000000000000f, 0.000000000000000000f,
+ 0.000000000000000000f, 0.000000000000000000f, 0.000000000000000000f,
+ 0.000000000000000000f, 0.000000000000000000f, 0.000000000000000000f,
+ 0.000000000000000000f, 0.000000000000000000f, 0.000000000000000000f};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_SPECTRAL_REVERB_CONSTANTS_AND_TABLES_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb_test.cc
new file mode 100644
index 000000000..015159fa1
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/spectral_reverb_test.cc
@@ -0,0 +1,324 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/spectral_reverb.h"
+
+#include <algorithm>
+#include <cmath>
+#include <numeric>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "dsp/biquad_filter.h"
+#include "dsp/fft_manager.h"
+#include "dsp/filter_coefficient_generators.h"
+#include "utils/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+const size_t kFramesPerBuffer512 = 512;
+const size_t kFramesPerBuffer2048 = 2048;
+const size_t kFramesPerBuffer713 = 713;
+const size_t kNumReverbOverlap = 4;
+const size_t kReverbFftSize = 4096;
+const int kSampleFrequency16 = 16000;
+const int kSampleFrequency24 = 24000;
+
+// A set of 9 RT60 values for each of the octave bands with center frequencies
+// between 31.25Hz and 8kHz.
+const float kRt60s[kNumReverbOctaveBands] = {0.8f, 0.8f, 0.7f, 0.7f, 0.65f,
+ 0.65f, 0.6f, 0.6f, 0.5f};
+
+void ImpulseResponse(float length_sec, int sample_frequency,
+ size_t frames_per_buffer, SpectralReverb* reverb,
+ std::vector<float>* left_response,
+ std::vector<float>* right_response) {
+ AudioBuffer input(kNumMonoChannels, frames_per_buffer);
+ input.Clear();
+ input[0][0] = 1.0f;
+ AudioBuffer output(kNumStereoChannels, frames_per_buffer);
+
+ reverb->Process(input[0], &output[0], &output[1]);
+
+ // The number of iterations required so that we will have no more than a few
+ // zeros following each of our impulse responses.
+ const float tail_length_samples =
+ kReverbFftSize + length_sec * static_cast<float>(sample_frequency);
+ const size_t num_iterations =
+ 100 + 1 +
+ static_cast<size_t>(std::ceil(tail_length_samples /
+ static_cast<float>(frames_per_buffer)));
+
+ for (size_t i = 0; i < num_iterations; ++i) {
+ left_response->insert(left_response->end(), output[0].begin(),
+ output[0].end());
+ right_response->insert(right_response->end(), output[1].begin(),
+ output[1].end());
+
+ input.Clear();
+ reverb->Process(input[0], &output[0], &output[1]);
+ }
+}
+
+void StereoOutputTestHelper(int sample_frequency, size_t frames_per_buffer) {
+ SpectralReverb reverb(sample_frequency, frames_per_buffer);
+ reverb.SetRt60PerOctaveBand(kRt60s);
+
+ std::vector<float> output_collect_left;
+ std::vector<float> output_collect_right;
+ ImpulseResponse(1.0f /*length [sec]*/, sample_frequency, frames_per_buffer,
+ &reverb, &output_collect_left, &output_collect_right);
+
+ // First test that there are kReverbFftSize / kNumReverbOverlap zeros at the
+ // beginning of the system impulse responses ONLY if this value is greater
+ // than |frames_per_buffer|, otherwise expect no onset zeros.
+ const size_t kOverlapLength = kReverbFftSize / kNumReverbOverlap;
+ const size_t onset = kOverlapLength > frames_per_buffer ? kOverlapLength : 0;
+ for (size_t i = 0; i < onset; ++i) {
+ EXPECT_NEAR(0.0f, output_collect_left[i], kEpsilonFloat);
+ EXPECT_NEAR(0.0f, output_collect_right[i], kEpsilonFloat);
+ }
+ // Test the sample five samples later is non zero. i.e. the tail has begun.
+ EXPECT_NE(0.0f, output_collect_left[onset + 5]);
+ EXPECT_NE(0.0f, output_collect_right[onset + 5]);
+}
+
+void ZeroRt60TestHelper(int sample_frequency, float rt_60) {
+ SpectralReverb reverb(sample_frequency, kFramesPerBuffer512);
+ reverb.SetRt60PerOctaveBand(kRt60s);
+
+ std::vector<float> output_collect_left;
+ std::vector<float> output_collect_right;
+ ImpulseResponse(1.0f /*length [sec]*/, sample_frequency, kFramesPerBuffer512,
+ &reverb, &output_collect_left, &output_collect_right);
+
+ // Test that all the frames of the tail buffer are zeros.
+ for (size_t i = 0; i < kFramesPerBuffer512; ++i) {
+ EXPECT_NEAR(0.0f, output_collect_left[i], kEpsilonFloat);
+ EXPECT_NEAR(0.0f, output_collect_right[i], kEpsilonFloat);
+ }
+}
+
+void TailDecayTestHelper(int sample_frequency, size_t frames_per_buffer) {
+ // Butterworth Lowpass filter with cutoff frequency at 3Hz.
+ BiquadCoefficients low_pass_coefficients(
+ 1.0f, -1.999444639647f, 0.999444793816755f, 1e-5f, 2e-5f, 1e-5f);
+ BiquadFilter low_pass_filter(low_pass_coefficients, frames_per_buffer);
+ const std::vector<float> kUniformRt60s(kNumReverbOctaveBands, kRt60s[0]);
+ SpectralReverb reverb(sample_frequency, frames_per_buffer);
+ reverb.SetRt60PerOctaveBand(kUniformRt60s.data());
+
+ std::vector<float> output_collect_left;
+ std::vector<float> output_collect_right;
+ ImpulseResponse(2.0f /*length [sec]*/, sample_frequency, frames_per_buffer,
+ &reverb, &output_collect_left, &output_collect_right);
+
+ for (size_t i = 0; i < output_collect_left.size(); ++i) {
+ output_collect_left[i] = std::abs(output_collect_left[i]);
+ output_collect_right[i] = std::abs(output_collect_right[i]);
+ }
+
+ const size_t response_length = output_collect_left.size();
+
+ AudioBuffer test_buffer(kNumMonoChannels, response_length);
+ test_buffer[0] = output_collect_left;
+
+ // Very low frequency content of tail. This should essentially just preserve
+ // the decay.
+ low_pass_filter.Filter(test_buffer[0], &test_buffer[0]);
+
+ const size_t max_location = static_cast<size_t>(
+ std::max_element(test_buffer[0].begin(), test_buffer[0].end()) -
+ test_buffer[0].begin());
+
+ // Stop before the very end of the tail as it goes to zero.
+ const size_t end_point = max_location + kReverbFftSize;
+ const size_t step_size = (end_point - max_location) / 20;
+
+ // Test for decay.
+ for (size_t i = max_location + step_size; i < end_point; i += step_size) {
+ EXPECT_GT(std::abs(test_buffer[0][i - step_size]),
+ std::abs(test_buffer[0][i]));
+ }
+}
+
+void DecorrelatedTailsTestHelper(int sample_frequency,
+ size_t frames_per_buffer) {
+ // This value has been found empirically in MATLAB.
+ const float kMaxCrossCorrelation = 12.0f;
+ const std::vector<float> kUniformRt60s(kNumReverbOctaveBands, 0.7f);
+ SpectralReverb reverb(sample_frequency, frames_per_buffer);
+ reverb.SetRt60PerOctaveBand(kUniformRt60s.data());
+
+ std::vector<float> output_collect_left;
+ std::vector<float> output_collect_right;
+ ImpulseResponse(0.7f /*length [sec]*/, sample_frequency, frames_per_buffer,
+ &reverb, &output_collect_left, &output_collect_right);
+
+ // Find the absolute maximum elements of each vector.
+ auto min_max_left = std::minmax_element(output_collect_left.begin(),
+ output_collect_left.end());
+ size_t left_max_index =
+ std::abs(*min_max_left.first) > std::abs(*min_max_left.second)
+ ? (min_max_left.first - output_collect_left.begin())
+ : (min_max_left.second - output_collect_left.begin());
+ auto min_max_right = std::minmax_element(output_collect_right.begin(),
+ output_collect_right.end());
+ size_t right_max_index =
+ std::abs(*min_max_right.first) > std::abs(*min_max_right.second)
+ ? (min_max_right.first - output_collect_right.begin())
+ : (min_max_right.second - output_collect_right.begin());
+
+ // Take a sample of the tails for cross correlation.
+ AudioBuffer pair(kNumStereoChannels, kReverbFftSize);
+ for (size_t i = 0; i < kReverbFftSize; ++i) {
+ pair[0][i] = output_collect_left[i + left_max_index] /
+ output_collect_left[left_max_index];
+ pair[1][i] = output_collect_right[i + right_max_index] /
+ output_collect_right[right_max_index];
+ }
+
+ // The cross correlation is not normalized. Thus we can expect a very small
+ // value. Naturally, if the RT60 inputs are changed the expected value would
+ // thus be different.
+ const float max_xcorr = MaxCrossCorrelation(pair[0], pair[1]);
+ EXPECT_LT(max_xcorr, kMaxCrossCorrelation);
+}
+
+} // namespace
+
+// Tests that the stereo output from the Reverbs Process fuction has the
+// expected properties of predelay and length.
+TEST(SpectralReverbTest, StereoOutputTest) {
+ StereoOutputTestHelper(kSampleFrequency24, kFramesPerBuffer512);
+ StereoOutputTestHelper(kSampleFrequency24, kFramesPerBuffer2048);
+ StereoOutputTestHelper(kSampleFrequency24, kFramesPerBuffer713);
+ StereoOutputTestHelper(kSampleFrequency16, kFramesPerBuffer512);
+ StereoOutputTestHelper(kSampleFrequency16, kFramesPerBuffer2048);
+ StereoOutputTestHelper(kSampleFrequency16, kFramesPerBuffer713);
+}
+
+// Tests that the stereo output from the Reverb's Process function has the
+// output of all zeros when the RT60 values are all zero.
+TEST(SpectralReverbTest, ZeroRt60Test) {
+ const float kZeroRt = 0.0f;
+ const float kBelowMinRt = 0.12f;
+ ZeroRt60TestHelper(kSampleFrequency24, kZeroRt);
+ ZeroRt60TestHelper(kSampleFrequency16, kBelowMinRt);
+ ZeroRt60TestHelper(kSampleFrequency16, kZeroRt);
+ ZeroRt60TestHelper(kSampleFrequency16, kBelowMinRt);
+}
+
+// Tests that the tail is decaying over time.
+TEST(SpectralReverbTest, TailDecayTest) {
+ TailDecayTestHelper(kSampleFrequency24, kFramesPerBuffer512);
+ TailDecayTestHelper(kSampleFrequency24, kFramesPerBuffer2048);
+ TailDecayTestHelper(kSampleFrequency16, kFramesPerBuffer512);
+ TailDecayTestHelper(kSampleFrequency16, kFramesPerBuffer2048);
+}
+
+// Tests that the stereo tail pairs are highy decorrelated.
+TEST(SpectralReverbTest, DecorrelatedTailsTest) {
+ DecorrelatedTailsTestHelper(kSampleFrequency24, kFramesPerBuffer512);
+ DecorrelatedTailsTestHelper(kSampleFrequency24, kFramesPerBuffer2048);
+ DecorrelatedTailsTestHelper(kSampleFrequency24, kFramesPerBuffer713);
+ DecorrelatedTailsTestHelper(kSampleFrequency16, kFramesPerBuffer512);
+ DecorrelatedTailsTestHelper(kSampleFrequency16, kFramesPerBuffer2048);
+ DecorrelatedTailsTestHelper(kSampleFrequency16, kFramesPerBuffer713);
+}
+
+// Tests that the gain parameter behaves as expected.
+TEST(SpecralReverbTest, GainTest) {
+ const float kReverbLength = 0.5f;
+ const float kGain = 100.0f;
+ const float kGainEpsilon = 0.32f;
+ const std::vector<float> kUniformRt60s(kNumReverbOctaveBands, kReverbLength);
+ SpectralReverb reverb(kSampleFrequency24, kFramesPerBuffer512);
+ reverb.SetRt60PerOctaveBand(kUniformRt60s.data());
+
+ // Calculate scaled and unscaled impulse responses.
+ std::vector<float> output_left;
+ std::vector<float> output_right;
+ ImpulseResponse(kReverbLength, kSampleFrequency24, kFramesPerBuffer512,
+ &reverb, &output_left, &output_right);
+ std::vector<float> output_left_scaled;
+ reverb.SetGain(kGain);
+ ImpulseResponse(kReverbLength, kSampleFrequency24, kFramesPerBuffer512,
+ &reverb, &output_left_scaled, &output_right);
+
+ // Determine the max absolute entry in each impulse response.
+ std::transform(output_left.begin(), output_left.end(), output_left.begin(),
+ static_cast<float (*)(float)>(&std::abs));
+ std::transform(output_left_scaled.begin(), output_left_scaled.end(),
+ output_left_scaled.begin(),
+ static_cast<float (*)(float)>(&std::abs));
+ const float max_unscaled =
+ *std::max_element(output_left.begin(), output_left.end());
+ const float max_scaled =
+ *std::max_element(output_left_scaled.begin(), output_left_scaled.end());
+ EXPECT_GT(max_scaled, max_unscaled);
+ EXPECT_NEAR((max_unscaled / max_scaled) / (1.0f / kGain), 1.0f, kGainEpsilon);
+}
+
+// Tests that when the feedback values are all ~0.0f, no processing is
+// performed (output is all zero). Also tests that if even one of the rt60s
+// result in a non zero feedback that the result will be non zero.
+TEST(SpectralReverbTest, DisabledProcessingTest) {
+ const float kReverbLength = 0.1f;
+ const std::vector<float> kUniformRt60s(kNumReverbOctaveBands, kReverbLength);
+ SpectralReverb reverb(kSampleFrequency24, kFramesPerBuffer512);
+ reverb.SetRt60PerOctaveBand(kUniformRt60s.data());
+ std::vector<float> output_left;
+ std::vector<float> output_right;
+ ImpulseResponse(kReverbLength, kSampleFrequency24, kFramesPerBuffer512,
+ &reverb, &output_left, &output_right);
+ for (size_t i = 0; i < output_left.size(); ++i) {
+ EXPECT_FLOAT_EQ(output_left[i], 0.0f);
+ EXPECT_FLOAT_EQ(output_right[i], 0.0f);
+ }
+
+ // Test a non zero case.
+ const float kLongerReverbLength = 0.4f;
+ std::vector<float> rt60s(kNumReverbOctaveBands, 0.0f);
+ rt60s[0] = kLongerReverbLength;
+ output_left.resize(0);
+ output_right.resize(0);
+ reverb.SetRt60PerOctaveBand(rt60s.data());
+ ImpulseResponse(kReverbLength, kSampleFrequency24, kFramesPerBuffer512,
+ &reverb, &output_left, &output_right);
+ const float sum_left =
+ std::accumulate(output_left.begin(), output_left.end(), 0.0f);
+ EXPECT_NE(sum_left, 0.0f);
+ const float sum_right =
+ std::accumulate(output_right.begin(), output_right.end(), 0.0f);
+ EXPECT_NE(sum_right, 0.0f);
+
+ // Set gain to zero and test again.
+ output_left.resize(0);
+ output_right.resize(0);
+ reverb.SetGain(0.0f);
+ ImpulseResponse(kReverbLength, kSampleFrequency24, kFramesPerBuffer512,
+ &reverb, &output_left, &output_right);
+ for (size_t i = 0; i < output_left.size(); ++i) {
+ EXPECT_FLOAT_EQ(output_left[i], 0.0f);
+ EXPECT_FLOAT_EQ(output_right[i], 0.0f);
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner.cc
new file mode 100644
index 000000000..373db9989
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner.cc
@@ -0,0 +1,46 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/stereo_panner.h"
+
+#include <cmath>
+
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+const float kStereoLeftRadians = kRadiansFromDegrees * kStereoLeftDegrees;
+const float kStereoRightRadians = kRadiansFromDegrees * kStereoRightDegrees;
+
+void CalculateStereoPanGains(const SphericalAngle& source_direction,
+ std::vector<float>* stereo_gains) {
+ // Note this applies the same panning law as was applied by the ambisonic
+ // equivalent panner to ensure consistency.
+ DCHECK(stereo_gains);
+ stereo_gains->resize(kNumStereoChannels);
+
+ const float cos_direction_elevation = std::cos(source_direction.elevation());
+
+ (*stereo_gains)[0] =
+ 0.5f * (1.0f + std::cos(kStereoLeftRadians - source_direction.azimuth()) *
+ cos_direction_elevation);
+ (*stereo_gains)[1] =
+ 0.5f *
+ (1.0f + std::cos(kStereoRightRadians - source_direction.azimuth()) *
+ cos_direction_elevation);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner.h
new file mode 100644
index 000000000..bf4cf1708
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner.h
@@ -0,0 +1,35 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_STEREO_PANNER_H_
+#define RESONANCE_AUDIO_DSP_STEREO_PANNER_H_
+
+#include <vector>
+
+#include "base/spherical_angle.h"
+
+namespace vraudio {
+
+// Computes a pair of stereo panner gains based on the |source_direction|.
+//
+// @param source_direction Azimuth and elevation of the sound source.
+// @param stereo_gains A pointer to vector of stereo loudspeaker gains.
+void CalculateStereoPanGains(const SphericalAngle& source_direction,
+ std::vector<float>* stereo_gains);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_STEREO_PANNER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner_test.cc
new file mode 100644
index 000000000..d24230241
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/stereo_panner_test.cc
@@ -0,0 +1,88 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/stereo_panner.h"
+
+#include <cmath>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+const float kMinusThreeDecibels = kInverseSqrtTwo;
+
+// Tests that the |CalculateStereoPanGains| method will generate correct stereo
+// pan gains.
+TEST(StereoPannerTest, StereoTest) {
+ std::vector<float> speaker_gains;
+
+ SphericalAngle source_direction = SphericalAngle::FromDegrees(-90.0f, 0.0f);
+ CalculateStereoPanGains(source_direction, &speaker_gains);
+ EXPECT_NEAR(0.0f, speaker_gains[0], kEpsilonFloat);
+ EXPECT_NEAR(1.0f, speaker_gains[1], kEpsilonFloat);
+
+ source_direction = SphericalAngle::FromDegrees(-45.0f, 0.0f);
+ CalculateStereoPanGains(source_direction, &speaker_gains);
+ EXPECT_NEAR(kMinusThreeDecibels, speaker_gains[1] - speaker_gains[0],
+ kEpsilonFloat);
+
+ source_direction = SphericalAngle::FromDegrees(0.0f, 0.0f);
+ CalculateStereoPanGains(source_direction, &speaker_gains);
+ EXPECT_NEAR(speaker_gains[0], speaker_gains[1], kEpsilonFloat);
+
+ source_direction = SphericalAngle::FromDegrees(45.0f, 0.0f);
+ CalculateStereoPanGains(source_direction, &speaker_gains);
+ EXPECT_NEAR(kMinusThreeDecibels, speaker_gains[0] - speaker_gains[1],
+ kEpsilonFloat);
+
+ source_direction = SphericalAngle::FromDegrees(90.0f, 0.0f);
+ CalculateStereoPanGains(source_direction, &speaker_gains);
+ EXPECT_NEAR(1.0f, speaker_gains[0], kEpsilonFloat);
+ EXPECT_NEAR(0.0f, speaker_gains[1], kEpsilonFloat);
+
+ source_direction = SphericalAngle::FromDegrees(0.0f, 45.0f);
+ CalculateStereoPanGains(source_direction, &speaker_gains);
+ EXPECT_NEAR(0.5f, speaker_gains[0], kEpsilonFloat);
+ EXPECT_NEAR(0.5f, speaker_gains[1], kEpsilonFloat);
+
+ source_direction = SphericalAngle::FromDegrees(0.0f, -60.0f);
+ CalculateStereoPanGains(source_direction, &speaker_gains);
+ EXPECT_NEAR(0.5f, speaker_gains[0], kEpsilonFloat);
+ EXPECT_NEAR(0.5f, speaker_gains[1], kEpsilonFloat);
+
+ source_direction = SphericalAngle::FromDegrees(0.0f, 90.0f);
+ CalculateStereoPanGains(source_direction, &speaker_gains);
+ EXPECT_NEAR(0.5f, speaker_gains[0], kEpsilonFloat);
+ EXPECT_NEAR(0.5f, speaker_gains[1], kEpsilonFloat);
+
+ source_direction = SphericalAngle::FromDegrees(0.0f, -90.0f);
+ CalculateStereoPanGains(source_direction, &speaker_gains);
+ EXPECT_NEAR(0.5f, speaker_gains[0], kEpsilonFloat);
+ EXPECT_NEAR(0.5f, speaker_gains[1], kEpsilonFloat);
+
+ source_direction = SphericalAngle::FromDegrees(45.0f, 45.0f);
+ CalculateStereoPanGains(source_direction, &speaker_gains);
+ EXPECT_NEAR(0.75f, speaker_gains[0], kEpsilonFloat);
+ EXPECT_NEAR(0.25f, speaker_gains[1], kEpsilonFloat);
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/utils.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/utils.cc
new file mode 100644
index 000000000..e1d8396a0
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/utils.cc
@@ -0,0 +1,190 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/utils.h"
+
+#include <algorithm>
+#include <cmath>
+#include <limits>
+#include <random>
+#include <vector>
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/misc_math.h"
+
+#include "dsp/biquad_filter.h"
+#include "dsp/filter_coefficient_generators.h"
+
+namespace {
+
+// The mean and standard deviation of the normal distribution for bandlimited
+// Gaussian noise.
+const float kMean = 0.0f;
+const float kStandardDeviation = 1.0f;
+
+// Maximum group delay in seconds for each filter. In order to avoid audible
+// distortion, the maximum phase shift of a re-combined stereo sequence should
+// not exceed 5ms at high frequencies. That is why, maximum phase shift of
+// each filter is set to 1/2 of that value.
+const float kMaxGroupDelaySeconds = 0.0025f;
+
+// Phase modulation depth, chosen so that for a given max group delay filters
+// provide the lowest cross-correlation coefficient.
+const float kPhaseModulationDepth = 1.18f;
+
+// Constants used in the generation of uniform random number distributions.
+// https://en.wikipedia.org/wiki/Linear_congruential_generator
+const uint64 kMultiplier = 1664525L;
+const uint64 kIncrement = 1013904223L;
+const float kInt32ToFloat =
+ 1.0f / static_cast<float>(std::numeric_limits<uint32>::max());
+
+} // namespace
+
+namespace vraudio {
+
+void GenerateGaussianNoise(float mean, float std_deviation, unsigned seed,
+ AudioBuffer::Channel* noise_channel) {
+ DCHECK(noise_channel);
+ // First generate uniform noise.
+ GenerateUniformNoise(0.0f, 1.0f, seed, noise_channel);
+ const size_t length = noise_channel->size();
+
+ // Gaussian distribution with mean and standard deviation in pairs via the
+ // box-muller transform
+ // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform.
+ for (size_t i = 0; i < length - 1; i += 2) {
+ const float part_one = std::sqrt(-2.0f * std::log((*noise_channel)[i]));
+ const float part_two = kTwoPi * (*noise_channel)[i + 1];
+ const float z0 = part_one * std::cos(part_two);
+ const float z1 = part_one * std::sin(part_two);
+ (*noise_channel)[i] = std_deviation * z0 + mean;
+ (*noise_channel)[i + 1] = std_deviation * z1 + mean;
+ }
+ // Handle the odd buffer length case cheaply.
+ if (length % 2 > 0) {
+ (*noise_channel)[length - 1] = (*noise_channel)[0];
+ }
+}
+
+void GenerateUniformNoise(float min, float max, unsigned seed,
+ AudioBuffer::Channel* noise_channel) {
+ // Simple random generator to avoid the use of std::uniform_real_distribution
+ // affected by https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56202
+ DCHECK(noise_channel);
+ DCHECK_LT(min, max);
+ const float scaled_conversion_factor = kInt32ToFloat * (max - min);
+ uint32 state = static_cast<uint32>(seed);
+ for (float& sample : *noise_channel) {
+ state = static_cast<uint32>(state * kMultiplier + kIncrement);
+ sample = min + static_cast<float>(state) * scaled_conversion_factor;
+ }
+}
+
+void GenerateBandLimitedGaussianNoise(float center_frequency, int sampling_rate,
+ unsigned seed,
+ AudioBuffer* noise_buffer) {
+
+
+ DCHECK(noise_buffer);
+ DCHECK_GT(sampling_rate, 0);
+ DCHECK_LT(center_frequency, static_cast<float>(sampling_rate) / 2.0f);
+ const size_t num_frames = noise_buffer->num_frames();
+
+ BiquadCoefficients bandpass_coefficients = ComputeBandPassBiquadCoefficients(
+ sampling_rate, center_frequency, /*bandwidth=*/1);
+ BiquadFilter bandpass_filter(bandpass_coefficients, num_frames);
+
+ for (auto& channel : *noise_buffer) {
+ GenerateGaussianNoise(kMean, kStandardDeviation, seed, &channel);
+ bandpass_filter.Filter(channel, &channel);
+ bandpass_filter.Clear();
+ }
+}
+
+std::unique_ptr<AudioBuffer> GenerateDecorrelationFilters(int sampling_rate) {
+
+ const int kMaxGroupDelaySamples = static_cast<int>(
+ roundf(kMaxGroupDelaySeconds * static_cast<float>(sampling_rate)));
+
+ // Filter coefficients according to:
+ // [1] F. Zotter, M. Frank, "Efficient Phantom Source Widening", Archives of
+ // Acoustics, Vol. 38, No. 1, pp. 27–37 (2013).
+ const float g0 = 1.0f - 0.25f * IntegerPow(kPhaseModulationDepth, 2);
+ const float g1 = 0.5f * kPhaseModulationDepth -
+ 0.0625f * IntegerPow(kPhaseModulationDepth, 3);
+ const float g2 = 0.1250f * IntegerPow(kPhaseModulationDepth, 2);
+ std::vector<float> filter1_coefficients{g2, g1, g0, -g1, g2};
+ std::vector<float> filter2_coefficients{g2, -g1, g0, g1, g2};
+
+ const size_t filter_length =
+ filter1_coefficients.size() * kMaxGroupDelaySamples;
+ std::unique_ptr<AudioBuffer> decorrelation_filters(
+ new AudioBuffer(kNumStereoChannels, filter_length));
+ decorrelation_filters->Clear();
+
+ for (size_t coefficient = 0; coefficient < filter1_coefficients.size();
+ ++coefficient) {
+ (*decorrelation_filters)[0][coefficient * kMaxGroupDelaySamples] =
+ filter1_coefficients[coefficient];
+ (*decorrelation_filters)[1][coefficient * kMaxGroupDelaySamples] =
+ filter2_coefficients[coefficient];
+ }
+
+ return decorrelation_filters;
+}
+
+size_t GetNumReverbOctaveBands(int sampling_rate) {
+ DCHECK_GT(sampling_rate, 0);
+
+ const float max_band =
+ log2f(0.5f * static_cast<float>(sampling_rate) / kLowestOctaveBandHz);
+ return std::min(kNumReverbOctaveBands, static_cast<size_t>(roundf(max_band)));
+}
+
+size_t GetNumSamplesFromMilliseconds(float milliseconds, int sampling_rate) {
+ DCHECK_GE(milliseconds, 0.0f);
+ DCHECK_GT(sampling_rate, 0);
+ return static_cast<size_t>(milliseconds * kSecondsFromMilliseconds *
+ static_cast<float>(sampling_rate));
+}
+
+size_t CeilToMultipleOfFramesPerBuffer(size_t size, size_t frames_per_buffer) {
+ DCHECK_NE(frames_per_buffer, 0U);
+ const size_t remainder = size % frames_per_buffer;
+ return remainder == 0 ? std::max(size, frames_per_buffer)
+ : size + frames_per_buffer - remainder;
+}
+
+void GenerateHannWindow(bool full_window, size_t window_length,
+ AudioBuffer::Channel* buffer) {
+
+ DCHECK(buffer);
+ DCHECK_LE(window_length, buffer->size());
+ const float full_window_scaling_factor =
+ kTwoPi / (static_cast<float>(window_length) - 1.0f);
+ const float half_window_scaling_factor =
+ kTwoPi / (2.0f * static_cast<float>(window_length) - 1.0f);
+ const float scaling_factor =
+ (full_window) ? full_window_scaling_factor : half_window_scaling_factor;
+ for (size_t i = 0; i < window_length; ++i) {
+ (*buffer)[i] =
+ 0.5f * (1.0f - std::cos(scaling_factor * static_cast<float>(i)));
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/utils.h b/src/3rdparty/resonance-audio/resonance_audio/dsp/utils.h
new file mode 100644
index 000000000..ceb3060de
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/utils.h
@@ -0,0 +1,93 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_DSP_UTILS_H_
+#define RESONANCE_AUDIO_DSP_UTILS_H_
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Generates a gaussian white noise signal.
+//
+// @param mean The mean distribution parameter.
+// @param std_deviation The standard deviation distribution parameter.
+// @param seed A seed for the random generator.
+// @param noise_channel Buffer channel in which to store the noise.
+void GenerateGaussianNoise(float mean, float std_deviation, unsigned seed,
+ AudioBuffer::Channel* noise_channel);
+
+// Generates a gaussian white noise signal.
+//
+// @param min The lowest value in the distribution.
+// @param max The highest value in te distribution, must be > min.
+// @param seed A seed for the random generator.
+// @param noise_channel Buffer channel in which to store the noise.
+void GenerateUniformNoise(float min, float max, unsigned seed,
+ AudioBuffer::Channel* noise_channel);
+
+// Generates a band limited gaussian white noise signal, one octave band wide.
+//
+// @param center_frequency Center frequency of the given octave band in Hz.
+// @param sampling_rate System sampling rate in Hz.
+// @param seed A seed for the random generator.
+// @param noise_buffer Buffer in which to store the band limited noise.
+void GenerateBandLimitedGaussianNoise(float center_frequency, int sampling_rate,
+ unsigned seed, AudioBuffer* noise_buffer);
+
+// Genarates a pair of decorrelation filters (for use in low quality/high
+// effiency mode reverb).
+//
+// @param sampling_rate System sampling rate in Hz.
+// @return Buffer containing the stereo filters.
+std::unique_ptr<AudioBuffer> GenerateDecorrelationFilters(int sampling_rate);
+
+// Returns the number of octave bands necessary for the given |sampling_rate|.
+//
+// @param sampling_rate Sampling rate in Hertz.
+// @return Number of reverb octave bands.
+size_t GetNumReverbOctaveBands(int sampling_rate);
+
+// Converts the given |milliseconds| to number of samples with the given
+// |sampling_rate|. This method should *not* be used when more precise
+// (double-precission) value is desired.
+//
+// @param milliseconds Milliseconds in single-precission floating point.
+// @param sampling_rate Sampling rate in Hertz.
+// @return Number of samples.
+size_t GetNumSamplesFromMilliseconds(float milliseconds, int sampling_rate);
+
+// Ceils the given |size| to the next multiple of given |frames_per_buffer|.
+//
+// @param size Input size in frames.
+// @param frames_per_buffer Frames per buffer.
+// @return Ceiled size in frames.
+size_t CeilToMultipleOfFramesPerBuffer(size_t size, size_t frames_per_buffer);
+
+// Generates a Hann window (used for smooth onset and tapering of the generated
+// reverb response tails).
+//
+// @param full_window True to generate a full window, false to generate a half.
+// @param window_length Length of the window to be generated. Must be less than
+// or equal to the number of frames in the |buffer|.
+// @param buffer AudioBuffer::Channel to which the window is written, the number
+// of frames will be the length in samples of the generated Hann window.
+void GenerateHannWindow(bool full_window, size_t window_length,
+ AudioBuffer::Channel* buffer);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_DSP_UTILS_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/dsp/utils_test.cc b/src/3rdparty/resonance-audio/resonance_audio/dsp/utils_test.cc
new file mode 100644
index 000000000..dffe991ec
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/dsp/utils_test.cc
@@ -0,0 +1,194 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "dsp/utils.h"
+
+#include <cmath>
+#include <limits>
+#include <memory>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "dsp/fft_manager.h"
+#include "dsp/partitioned_fft_filter.h"
+#include "utils/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+const int kSamplingRate = 48000;
+
+const size_t kHalfHannWindowLength = 8;
+const float kExpectedHalfHannWindow[] = {0.0000000f, 0.04322727f, 0.1654347f,
+ 0.3454915f, 0.55226423f, 0.7500000f,
+ 0.9045085f, 0.98907380f};
+
+const size_t kHannWindowLength = 15;
+const float kExpectedHannWindow[] = {
+ 0.0000000f, 0.0495156f, 0.1882551f, 0.3887395f, 0.6112605f,
+ 0.8117449f, 0.9504844f, 1.0000000f, 0.9504844f, 0.8117449f,
+ 0.6112605f, 0.3887395f, 0.1882551f, 0.0495156f, 0.0000000f};
+
+// Test that the noise generation functions create noise vectors with the
+// expected means etc.
+TEST(DspUtilsTest, NoiseTest) {
+ const size_t kNoiseBufferLength = 1e5;
+ // A high epsilon is used to determine if mean, std dev etc. are acurate as it
+ // would be infeasible to have enough samples to take advantage of the central
+ // limit theorem.
+ const float kEpsilon = 1e-1f;
+
+ AudioBuffer gaussian(kNumMonoChannels, kNoiseBufferLength);
+ AudioBuffer uniform(kNumMonoChannels, kNoiseBufferLength);
+
+ // Generate Gaussian Noise with mean 0 and std deviation 2.
+ const float kGaussianMean = 0.0f;
+ const float kStdDeviation = 2.0f;
+ GenerateGaussianNoise(kGaussianMean, kStdDeviation, /*seed=*/1U,
+ &gaussian[0]);
+
+ // Calculate the mean and compare to that specified.
+ float mean = 0.0f;
+ for (auto& sample : gaussian[0]) {
+ mean += sample;
+ }
+ mean /= static_cast<float>(gaussian.num_frames());
+ EXPECT_NEAR(mean, kGaussianMean, kEpsilon);
+
+ // Calculate the std deviation and compare to that specified.
+ float std_dev = 0.0f;
+ for (auto& sample : gaussian[0]) {
+ std_dev += (sample - mean) * (sample - mean);
+ }
+ std_dev /= static_cast<float>(gaussian.num_frames());
+ std_dev = std::sqrt(std_dev);
+ EXPECT_NEAR(std_dev, kStdDeviation, kEpsilon);
+
+ // Genarate uniformly distributed noise min -1, max 1 and thus mean 0.
+ const float kMin = -1.0f;
+ const float kMax = 1.0f;
+ GenerateUniformNoise(kMin, kMax, /*seed=*/1U, &uniform[0]);
+ // Calculate the mean and min/max values, compare to expected values.
+ mean = 0.0f;
+ float min = std::numeric_limits<float>::max();
+ float max = std::numeric_limits<float>::min();
+ for (auto& sample : uniform[0]) {
+ mean += sample;
+ min = sample < min ? sample : min;
+ max = sample > max ? sample : max;
+ }
+ mean /= static_cast<float>(uniform.num_frames());
+ EXPECT_NEAR(mean, (kMax + kMin) / 2.0f, kEpsilon);
+ EXPECT_GE(kMax, max);
+ EXPECT_LE(kMin, min);
+}
+
+// Tests that the ceiled input size in frames matches the expected multiple of
+// frames per buffer for arbitrary inputs.
+TEST(DspUtilsTest, CeilToMultipleOfFramesPerBufferTest) {
+ const size_t kFramesPerBuffer = 512;
+ const std::vector<size_t> kInput = {0, 100, 512, 1000, 5000, 10240};
+ const std::vector<size_t> kExpectedOutput = {512, 512, 512,
+ 1024, 5120, 10240};
+
+ for (size_t i = 0; i < kInput.size(); ++i) {
+ EXPECT_EQ(kExpectedOutput[i],
+ CeilToMultipleOfFramesPerBuffer(kInput[i], kFramesPerBuffer));
+ }
+}
+
+// Tests that on filtering a noise sample with a pair of decorrelation filters,
+// the correlation between those outputs is less than the result of an
+// autocorrelation.
+TEST(DspUtilsTest, GenerateDecorrelationFiltersTest) {
+ // Size of FFT to be used in |GenerateDecorrelationFiltersTest|.
+ const size_t kBufferSize = 512;
+ // Centre frequency for noise used in |GenerateDecorrelationFiltersTest|.
+ const float kNoiseCenter = 1000.0f;
+ std::unique_ptr<AudioBuffer> kernels =
+ GenerateDecorrelationFilters(kSamplingRate);
+ AudioBuffer noise(kNumMonoChannels, kBufferSize);
+ GenerateBandLimitedGaussianNoise(kNoiseCenter, kSamplingRate, /*seed=*/1U,
+ &noise);
+ FftManager fft_manager(kBufferSize);
+ PartitionedFftFilter fft_filter(kernels->num_frames(), kBufferSize,
+ &fft_manager);
+ fft_filter.SetTimeDomainKernel((*kernels)[0]);
+ AudioBuffer output_one(kNumMonoChannels, kBufferSize);
+
+ PartitionedFftFilter::FreqDomainBuffer freq_domain_buffer(kNumMonoChannels,
+ kBufferSize * 2);
+ fft_manager.FreqFromTimeDomain(noise[0], &freq_domain_buffer[0]);
+ fft_filter.Filter(freq_domain_buffer[0]);
+ fft_filter.GetFilteredSignal(&output_one[0]);
+ fft_filter.SetTimeDomainKernel((*kernels)[1]);
+ AudioBuffer output_two(kNumMonoChannels, kBufferSize);
+ fft_manager.FreqFromTimeDomain(noise[0], &freq_domain_buffer[0]);
+ fft_filter.Filter(freq_domain_buffer[0]);
+ fft_filter.GetFilteredSignal(&output_two[0]);
+ const float auto_correlation = MaxCrossCorrelation(noise[0], noise[0]);
+ const float decorrelated = MaxCrossCorrelation(output_one[0], output_two[0]);
+ EXPECT_LT(decorrelated, auto_correlation);
+}
+
+// Tests half-Hann window calculation against values returned by MATLAB's hann()
+// function.
+TEST(DspUtilsTest, GenerateHalfHannWindowTest) {
+ AudioBuffer half_hann_window(kNumMonoChannels, kHalfHannWindowLength);
+ GenerateHannWindow(false, kHalfHannWindowLength, &half_hann_window[0]);
+ for (size_t i = 0; i < kHalfHannWindowLength; ++i) {
+ EXPECT_NEAR(half_hann_window[0][i], kExpectedHalfHannWindow[i],
+ kEpsilonFloat);
+ }
+}
+
+// Tests Hann window generation for odd window lengths.
+TEST(DspUtilsTest, GenerateHannWindowOddLengthTest) {
+ AudioBuffer hann_window(kNumMonoChannels, kHannWindowLength);
+ GenerateHannWindow(true, kHannWindowLength, &hann_window[0]);
+ for (size_t i = 0; i < kHannWindowLength; ++i) {
+ EXPECT_NEAR(hann_window[0][i], kExpectedHannWindow[i], kEpsilonFloat);
+ }
+}
+
+// Tests that the calculated number of reverb octave bands matches the
+// pre-computed results with arbitrary sampling rates.
+TEST(DspUtilsTest, GetNumReverbOctaveBandsTest) {
+ const std::vector<int> kSamplingRates = {8000, 22050, 44100, 48000, 96000};
+ const std::vector<size_t> kExpectedOutput = {7, 8, 9, 9, 9};
+
+ for (size_t i = 0; i < kSamplingRates.size(); ++i) {
+ EXPECT_EQ(kExpectedOutput[i], GetNumReverbOctaveBands(kSamplingRates[i]));
+ }
+}
+
+// Tests that the calculated number of samples for arbitrary milliseconds values
+// matches the pre-computed results with a specific sampling rate.
+TEST(DspUtilsTest, GetNumSamplesFromMillisecondsTest) {
+ const std::vector<float> kInput = {0.0f, 2.5f, 50.0f, 123.45f, 1000.0f};
+ const std::vector<size_t> kExpectedOutput = {0, 120, 2400, 5925, 48000};
+
+ for (size_t i = 0; i < kInput.size(); ++i) {
+ EXPECT_EQ(kExpectedOutput[i],
+ GetNumSamplesFromMilliseconds(kInput[i], kSamplingRate));
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_listener.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_listener.h
new file mode 100644
index 000000000..7ae5c7a3f
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_listener.h
@@ -0,0 +1,57 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ACOUSTIC_LISTENER_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ACOUSTIC_LISTENER_H_
+
+#include <array>
+#include <cstddef>
+#include <vector>
+
+#include "Eigen/Core"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+struct AcousticListener {
+ // Constructor.
+ //
+ // @param listener_position Position of the listener.
+ // @param impulse_response_length Number of samples in the energy impulse
+ // response for each frequency band.
+ AcousticListener(const Eigen::Vector3f& listener_position,
+ size_t impulse_response_length)
+ : position(listener_position) {
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ energy_impulse_responses[i] =
+ std::vector<float>(impulse_response_length, 0.0f);
+ }
+ }
+
+ const Eigen::Vector3f position;
+
+ // Impulse responses in terms of energies for all frequency bands.
+ // Need to take square roots before applying it to an input signal, which
+ // models pressure. The reason we store response in energy instead of in
+ // pressure is because the geometrical acoustics computation is energy-based,
+ // and the following kind of operations are performed extensively:
+ // energy_impulse_responses[i][t] += <energy contribution from a ray>.
+ std::array<std::vector<float>, kNumReverbOctaveBands>
+ energy_impulse_responses;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ACOUSTIC_LISTENER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray.cc
new file mode 100644
index 000000000..6385f639b
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray.cc
@@ -0,0 +1,27 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/acoustic_ray.h"
+
+#include <limits>
+
+namespace vraudio {
+
+// Static member initialization.
+const float AcousticRay::kInfinity = std::numeric_limits<float>::infinity();
+const float AcousticRay::kRayEpsilon = 1e-4f;
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray.h
new file mode 100644
index 000000000..ffe910270
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray.h
@@ -0,0 +1,195 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ACOUSTIC_RAY_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ACOUSTIC_RAY_H_
+
+#include <array>
+#include <vector>
+
+#include "embree2/rtcore.h"
+#include "embree2/rtcore_ray.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+// A class extending Embree's RTCRay (https://embree.github.io/api.html) with
+// data needed for acoustic computations.
+// It exposes useful fields through accessors.
+class RTCORE_ALIGN(16) AcousticRay : public RTCRay {
+ public:
+ enum class RayType {
+ kSpecular,
+ kDiffuse,
+ };
+
+ // A constant used to indicate that the ray extends to infinity, if
+ // ray.t_far() == AcousticRay::kInfinity.
+ static const float kInfinity;
+
+ // Used to offset a ray's origin slightly so that it will not
+ // intersect with the same geometry/primitive that it was generated from
+ // (by reflection, transmission, diffraction, etc.).
+ static const float kRayEpsilon;
+
+ // Default constructor. Constructs a ray whose origin is at (0, 0, 0) and
+ // points in the +x direction.
+ AcousticRay()
+ : energies_(), type_(RayType::kSpecular), prior_distance_(0.0f) {
+ org[0] = 0.0f;
+ org[1] = 0.0f;
+ org[2] = 0.0f;
+ dir[0] = 1.0f;
+ dir[1] = 0.0f;
+ dir[2] = 0.0f;
+ tnear = 0.0f;
+ tfar = kInfinity;
+ Ng[0] = 0.0f;
+ Ng[1] = 0.0f;
+ Ng[2] = 0.0f;
+ geomID = RTC_INVALID_GEOMETRY_ID;
+
+ // Members in RTCRay that we do not use (or whose initial values we do not
+ // care) are not initialized:
+ // align0, align1, align2, time, mask, u, v, primID, instID.
+ }
+
+ // Constructor.
+ //
+ // @param origin Origin of the ray.
+ // @param direction Direction of the ray.
+ // @param t_near Ray parameter corresponding to the start of the ray.
+ // @param t_far Ray parameter corresponding to the end of the ray. Pass in
+ // AcousticRay::kInfinity if there is no end point.
+ // @param energies Ray energies for all frequency bands.
+ // @param ray_type Type of ray.
+ // @param prior_distance Distance traveled before this ray.
+ AcousticRay(const float origin[3], const float direction[3], float t_near,
+ float t_far,
+ const std::array<float, kNumReverbOctaveBands>& energies,
+ RayType ray_type, float prior_distance)
+ : energies_(energies), type_(ray_type), prior_distance_(prior_distance) {
+ org[0] = origin[0];
+ org[1] = origin[1];
+ org[2] = origin[2];
+ dir[0] = direction[0];
+ dir[1] = direction[1];
+ dir[2] = direction[2];
+ tnear = t_near;
+ tfar = t_far;
+ Ng[0] = 0.0f;
+ Ng[1] = 0.0f;
+ Ng[2] = 0.0f;
+ geomID = RTC_INVALID_GEOMETRY_ID;
+
+ // Members in RTCRay that we do not use (or whose initial values we do not
+ // care) are not initialized:
+ // align0, align1, align2, time, mask, u, v, primID, instID.
+ }
+
+ // Ray origin.
+ const float* origin() const { return org; }
+ void set_origin(const float origin[3]) {
+ org[0] = origin[0];
+ org[1] = origin[1];
+ org[2] = origin[2];
+ }
+
+ // Ray direction.
+ const float* direction() const { return dir; }
+ void set_direction(const float direction[3]) {
+ dir[0] = direction[0];
+ dir[1] = direction[1];
+ dir[2] = direction[2];
+ }
+
+ // Ray parameter t corresponding to the start of the ray segment.
+ const float t_near() const { return tnear; }
+ void set_t_near(float t_near) { tnear = t_near; }
+
+ // Ray parameter t corresponding to the end of the ray segment.
+ const float t_far() const { return tfar; }
+ void set_t_far(float t_far) { tfar = t_far; }
+
+ // Functions intersected_*() will only return meaningful results after
+ // Intersect() is called, otherwise they return default values as
+ // described below.
+ //
+ // Not normalized geometry normal at the intersection point.
+ // Default value: Vec3fa(0, 0, 0).
+ const float* intersected_geometry_normal() const { return Ng; }
+ void set_intersected_geometry_normal(
+ const float intersected_geometry_normal[3]) {
+ Ng[0] = intersected_geometry_normal[0];
+ Ng[1] = intersected_geometry_normal[1];
+ Ng[2] = intersected_geometry_normal[2];
+ }
+
+ // Id of the intersected geometry.
+ // Default value: kInvalidGeometryId.
+ const unsigned int intersected_geometry_id() const { return geomID; }
+
+ // Id of the intersected primitive.
+ // Default value: kInvalidPrimitiveId.
+ const unsigned int intersected_primitive_id() const { return primID; }
+
+ // Ray energies for all frequency bands.
+ const std::array<float, kNumReverbOctaveBands>& energies() const {
+ return energies_;
+ }
+ void set_energies(const std::array<float, kNumReverbOctaveBands>& energies) {
+ energies_ = energies;
+ }
+
+ // Ray type.
+ const RayType type() const { return type_; }
+ void set_type(const RayType type) { type_ = type; }
+
+ // Prior distance.
+ const float prior_distance() const { return prior_distance_; }
+ void set_prior_distance(float prior_distance) {
+ prior_distance_ = prior_distance;
+ }
+
+ // Finds the first intersection between this ray and a scene. Some fields
+ // will be filled/mutated, which can be examined by the following functions:
+ // - t_far()
+ // - intersected_geometry_normal()
+ // - intersected_geometry_id()
+ // - intersected_primitive_id()
+ //
+ // @param scene An RTCScene to test the intersection.
+ // @return True if an intersection is found.
+ bool Intersect(RTCScene scene) {
+ rtcIntersect(scene, *this);
+ return geomID != RTC_INVALID_GEOMETRY_ID;
+ }
+
+ private:
+ // Used to determine early-termination of rays. May also be used to model
+ // source strength.
+ std::array<float, kNumReverbOctaveBands> energies_;
+
+ // Ray type.
+ RayType type_ = RayType::kSpecular;
+
+ // Accumulated distance traveled on the same path before this ray starts.
+ float prior_distance_ = 0.0f;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ACOUSTIC_RAY_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray_test.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray_test.cc
new file mode 100644
index 000000000..29ef269ed
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_ray_test.cc
@@ -0,0 +1,243 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/acoustic_ray.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/logging.h"
+#include "geometrical_acoustics/test_util.h"
+
+namespace vraudio {
+
+namespace {
+const float kFloatErrorTolerance = 5e-7f;
+
+class AcousticRayTest : public testing::Test {
+ protected:
+ void SetUp() override {
+ // Use a single RTCDevice for all tests.
+ static RTCDevice device = rtcNewDevice(nullptr);
+ CHECK_NOTNULL(device);
+ scene_ = rtcDeviceNewScene(
+ device, RTC_SCENE_STATIC | RTC_SCENE_HIGH_QUALITY, RTC_INTERSECT1);
+ }
+
+ void TearDown() override { rtcDeleteScene(scene_); }
+
+ // Normalizes the vector in place.
+ void NormalizeVector(float* vector) {
+ const float norm = std::sqrt(vector[0] * vector[0] + vector[1] * vector[1] +
+ vector[2] * vector[2]);
+ ASSERT_GT(norm, 0.0f);
+ vector[0] /= norm;
+ vector[1] /= norm;
+ vector[2] /= norm;
+ }
+
+ const std::array<float, kNumReverbOctaveBands> kZeroEnergies{
+ {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}};
+ RTCScene scene_ = nullptr;
+};
+
+TEST_F(AcousticRayTest, DefaultConstructorTest) {
+ AcousticRay ray;
+ const float default_origin[3] = {0.0f, 0.0f, 0.0f};
+ const float default_direction[3] = {1.0f, 0.0f, 0.0f};
+ ExpectFloat3Close(ray.origin(), default_origin);
+ ExpectFloat3Close(ray.direction(), default_direction);
+ EXPECT_FLOAT_EQ(ray.t_near(), 0.0f);
+ EXPECT_FLOAT_EQ(ray.t_far(), AcousticRay::kInfinity);
+ for (const float energy : ray.energies()) {
+ EXPECT_FLOAT_EQ(energy, 0.0f);
+ }
+ EXPECT_EQ(ray.type(), AcousticRay::RayType::kSpecular);
+ EXPECT_FLOAT_EQ(ray.prior_distance(), 0.0f);
+}
+
+TEST_F(AcousticRayTest, AccessorsTest) {
+ const float origin[3] = {0.0f, 0.0f, 0.25f};
+ const float direction[3] = {0.0f, 0.0f, 1.0f};
+
+ const float t_near = 0.0f;
+ const float t_far = AcousticRay::kInfinity;
+ const std::array<float, kNumReverbOctaveBands> energies = {
+ {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}};
+ const AcousticRay::RayType ray_type = AcousticRay::RayType::kDiffuse;
+ const float prior_distance = 0.0f;
+ AcousticRay ray(origin, direction, t_near, t_far, energies, ray_type,
+ prior_distance);
+
+ // Validate fields passed to the constructor.
+ ExpectFloat3Close(ray.origin(), origin);
+ ExpectFloat3Close(ray.direction(), direction);
+ EXPECT_FLOAT_EQ(ray.t_near(), t_near);
+ EXPECT_FLOAT_EQ(ray.t_far(), t_far);
+ for (size_t i = 0; i < energies.size(); ++i) {
+ EXPECT_FLOAT_EQ(ray.energies().at(i), energies.at(i));
+ }
+ EXPECT_EQ(ray.type(), ray_type);
+ EXPECT_FLOAT_EQ(ray.prior_distance(), prior_distance);
+
+ // Validate explicit setters.
+ const float new_origin[3] = {1.0f, 2.0f, 3.0f};
+ ray.set_origin(new_origin);
+ ExpectFloat3Close(ray.origin(), new_origin);
+
+ const float new_direction[3] = {0.0f, 1.0f, 0.0f};
+ ray.set_direction(new_direction);
+ ExpectFloat3Close(ray.direction(), new_direction);
+
+ const float new_t_near = 2.0f;
+ ray.set_t_near(new_t_near);
+ EXPECT_FLOAT_EQ(ray.t_near(), new_t_near);
+
+ const float new_t_far = 4.0f;
+ ray.set_t_far(new_t_far);
+ EXPECT_FLOAT_EQ(ray.t_far(), new_t_far);
+
+ const float intersected_geometry_normal[3] = {0.0f, 1.0f, 2.0f};
+ ray.set_intersected_geometry_normal(intersected_geometry_normal);
+ ExpectFloat3Close(ray.intersected_geometry_normal(),
+ intersected_geometry_normal);
+
+ const std::array<float, kNumReverbOctaveBands> new_energies = {
+ {2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f, 14.0f, 16.0f, 18.0f}};
+ ray.set_energies(new_energies);
+ for (size_t i = 0; i < energies.size(); ++i) {
+ EXPECT_FLOAT_EQ(ray.energies().at(i), new_energies.at(i));
+ }
+
+ const AcousticRay::RayType new_ray_type = AcousticRay::RayType::kSpecular;
+ ray.set_type(new_ray_type);
+ EXPECT_EQ(ray.type(), new_ray_type);
+
+ const float new_prior_distance = 7.0f;
+ ray.set_prior_distance(new_prior_distance);
+ EXPECT_FLOAT_EQ(ray.prior_distance(), new_prior_distance);
+}
+
+TEST_F(AcousticRayTest, IntersectTriangleInGroundSceneTest) {
+ // Add a ground to the scene and commit.
+ AddTestGround(scene_);
+ rtcCommit(scene_);
+
+ const float t_near = 0.0f;
+ const float t_far = AcousticRay::kInfinity;
+ const float prior_distance = 0.0f;
+ {
+ // This ray should intersect the ground geometry (id: 0) and the first
+ // triangle (id: 0).
+ const float origin[3] = {0.0f, 0.0f, 0.25f};
+ float direction[3] = {1.0f, 1.0f, -1.0f};
+ NormalizeVector(direction);
+ AcousticRay ray(origin, direction, t_near, t_far, kZeroEnergies,
+ AcousticRay::RayType::kSpecular, prior_distance);
+ EXPECT_TRUE(ray.Intersect(scene_));
+ EXPECT_EQ(ray.intersected_geometry_id(), 0u);
+ EXPECT_EQ(ray.intersected_primitive_id(), 0u);
+
+ // Check the intersection point.
+ EXPECT_NEAR(0.4330127f, ray.t_far(), 1e-7);
+ float intersection_point[3];
+ intersection_point[0] = ray.origin()[0] + ray.t_far() * ray.direction()[0];
+ intersection_point[1] = ray.origin()[1] + ray.t_far() * ray.direction()[1];
+ intersection_point[2] = ray.origin()[2] + ray.t_far() * ray.direction()[2];
+
+ const float expected_intersection_point[3] = {0.25f, 0.25f, 0.0f};
+ ExpectFloat3Close(intersection_point, expected_intersection_point,
+ kFloatErrorTolerance);
+
+ // Normal at the intersection point.
+ float normal[3];
+ normal[0] = ray.intersected_geometry_normal()[0];
+ normal[1] = ray.intersected_geometry_normal()[1];
+ normal[2] = ray.intersected_geometry_normal()[2];
+ NormalizeVector(normal);
+ const float expected_normal[3] = {0.0f, 0.0f, 1.0f};
+ ExpectFloat3Close(normal, expected_normal, kFloatErrorTolerance);
+ }
+ {
+ // This ray should intersect the ground geometry (id: 0) and the second
+ // triangle (id: 1).
+ const float origin[3] = {0.0f, 0.0f, 0.75f};
+ const float direction[3] = {1.0f, 1.0f, -1.0f};
+ AcousticRay ray(origin, direction, t_near, t_far, kZeroEnergies,
+ AcousticRay::RayType::kSpecular, prior_distance);
+ EXPECT_TRUE(ray.Intersect(scene_));
+ EXPECT_EQ(ray.intersected_geometry_id(), 0u);
+ EXPECT_EQ(ray.intersected_primitive_id(), 1u);
+ }
+ {
+ // This ray shoots upward (away from the ground) and therefore should not
+ // intersect anything.
+ const float origin[3] = {0.0f, 0.0f, 0.25};
+ const float direction[3] = {1.0f, 1.0f, 1.0f};
+ AcousticRay ray(origin, direction, t_near, t_far, kZeroEnergies,
+ AcousticRay::RayType::kSpecular, prior_distance);
+ EXPECT_FALSE(ray.Intersect(scene_));
+ }
+}
+
+TEST_F(AcousticRayTest, IntersectNothingBackfaceTest) {
+ // Add a ground to the scene and commit.
+ AddTestGround(scene_);
+ rtcCommit(scene_);
+
+ // This ray is on the "back side" of the ground. So even if the ray passes
+ // through a triangle, the intersection should not be reported.
+ const float origin[3] = {0.0f, 0.0f, -0.25f};
+ const float direction[3] = {1.0f, 1.0f, 1.0f};
+ const float t_near = 0.0f;
+ const float t_far = AcousticRay::kInfinity;
+ const float prior_distance = 0.0f;
+ AcousticRay ray(origin, direction, t_near, t_far, kZeroEnergies,
+ AcousticRay::RayType::kSpecular, prior_distance);
+ EXPECT_FALSE(ray.Intersect(scene_));
+}
+
+TEST_F(AcousticRayTest, IntersectNothingInEmptySceneTest) {
+ // Commit without adding any geometry.
+ rtcCommit(scene_);
+
+ // This ray should not intersect anything.
+ const float origin[3] = {0.0f, 0.0f, 0.25f};
+ const float direction[3] = {1.0f, 1.0f, -1.0f};
+ const float t_near = 0.0f;
+ const float t_far = AcousticRay::kInfinity;
+ const float prior_distance = 0.0f;
+ AcousticRay ray(origin, direction, t_near, t_far, kZeroEnergies,
+ AcousticRay::RayType::kSpecular, prior_distance);
+ EXPECT_FALSE(ray.Intersect(scene_));
+}
+
+TEST_F(AcousticRayTest, IntersectNothingInUnCommitedSceneTest) {
+ // Add a ground to the scene but forget to commit.
+ AddTestGround(scene_);
+
+ // This ray should not intersect anything.
+ const float origin[3] = {0.0f, 0.0f, 0.25f};
+ const float direction[3] = {1.0f, 1.0f, -1.0f};
+ const float t_near = 0.0f;
+ const float t_far = AcousticRay::kInfinity;
+ const float prior_distance = 0.0f;
+ AcousticRay ray(origin, direction, t_near, t_far, kZeroEnergies,
+ AcousticRay::RayType::kSpecular, prior_distance);
+ EXPECT_FALSE(ray.Intersect(scene_));
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_source.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_source.h
new file mode 100644
index 000000000..b119df76b
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_source.h
@@ -0,0 +1,111 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ACOUSTIC_SOURCE_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ACOUSTIC_SOURCE_H_
+
+#include <array>
+#include <functional>
+#include <utility>
+#include <vector>
+
+#include "Eigen/Core"
+#include "base/constants_and_types.h"
+#include "geometrical_acoustics/acoustic_ray.h"
+#include "geometrical_acoustics/sampling.h"
+
+namespace vraudio {
+
+// A class modeling a sound source. Currently we only support point source
+// that emits rays uniformly in all directions.
+class AcousticSource {
+ public:
+ // Constructor.
+ //
+ // @param position Source position.
+ // @param energies Source energies. This will be the initial energies for
+ // all frequency bands shared by all rays generated from this source.
+ // @param random_number_generator Random number generator used to sample
+ // ray directions. It should implement operator() that returns a
+ // random value in [0.0, 1.0).
+ AcousticSource(const Eigen::Vector3f& position,
+ const std::array<float, kNumReverbOctaveBands>& energies,
+ std::function<float()> random_number_generator)
+ : position_(position),
+ energies_(energies),
+ random_number_generator_(std::move(random_number_generator)) {}
+
+ // Generates one ray.
+ //
+ // @return AcousticRay starting from this source.
+ AcousticRay GenerateRay() const {
+ const Eigen::Vector3f& direction = UniformSampleSphere(
+ random_number_generator_(), random_number_generator_());
+ return AcousticRay(position_.data(), direction.data(), 0.0f,
+ AcousticRay::kInfinity, energies_,
+ AcousticRay::RayType::kSpecular, 0.0f);
+ }
+
+ // Generates a vector of rays at once, using stratified sampling. The rays
+ // generated this way are more "evenly spaced", with fewer holes and clusters.
+ //
+ // One caveat: only the whole set of the returned rays is uniformly
+ // distributed (the expected number of rays found in a finite solid angle
+ // is the same in any direction), while any subset with fewer than
+ // |num_rays| rays is not.
+ //
+ // In contrast, the GenerateRay() above guarantees any subset is a uniformly
+ // distributed set of rays. This is why the function is designed to return
+ // a vector of rays, which are meant to be used as a whole and not partially.
+ //
+ // @param num_rays Number of rays; must be equal to |sqrt_num_rays|^2.
+ // @param sqrt_num_rays The square root of number of rays to emit.
+ // @return A vector of |sqrt_num_rays|^2 AcousticRays starting from this
+ // source.
+ std::vector<AcousticRay> GenerateStratifiedRays(size_t num_rays,
+ size_t sqrt_num_rays) const {
+ // To save computation time, it is the caller's responsibility to make sure
+ // that |num_rays| is equal to |sqrt_num_rays|^2.
+ DCHECK_EQ(sqrt_num_rays * sqrt_num_rays, num_rays);
+
+ std::vector<AcousticRay> rays;
+ rays.reserve(num_rays);
+ for (size_t ray_index = 0; ray_index < num_rays; ++ray_index) {
+ const Eigen::Vector3f& direction = StratifiedSampleSphere(
+ random_number_generator_(), random_number_generator_(), sqrt_num_rays,
+ ray_index);
+ rays.push_back(AcousticRay(position_.data(), direction.data(),
+ 0.0f /* t_near */, AcousticRay::kInfinity,
+ energies_, AcousticRay::RayType::kSpecular,
+ 0.0f /* prior_distance */));
+ }
+ return rays;
+ }
+
+ private:
+ // The position of this point source.
+ const Eigen::Vector3f position_;
+
+ // The energy of this source.
+ const std::array<float, kNumReverbOctaveBands> energies_;
+
+ // Randon number generator for sampling ray directions.
+ std::function<float()> random_number_generator_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ACOUSTIC_SOURCE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_source_test.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_source_test.cc
new file mode 100644
index 000000000..aa05a8112
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/acoustic_source_test.cc
@@ -0,0 +1,136 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/acoustic_source.h"
+
+#include <cmath>
+#include <random>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "geometrical_acoustics/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+TEST(AcousticSource, GeneratedRayNonDirectionalDataTest) {
+ std::default_random_engine engine(0);
+ std::uniform_real_distribution<float> distribution(0.0f, 1.0f);
+ const std::array<float, kNumReverbOctaveBands> energies{
+ {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}};
+ AcousticSource source({0.1f, 0.2f, 0.3f}, energies, [&engine, &distribution] {
+ return distribution(engine);
+ });
+ AcousticRay ray = source.GenerateRay();
+
+ EXPECT_EQ(ray.type(), AcousticRay::RayType::kSpecular);
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ EXPECT_FLOAT_EQ(ray.energies().at(i), energies.at(i));
+ }
+ EXPECT_FLOAT_EQ(ray.t_near(), 0.0f);
+ const float expected_origin[3] = {0.1f, 0.2f, 0.3f};
+ ExpectFloat3Close(ray.origin(), expected_origin);
+}
+
+TEST(AcousticSource, GeneratedRayDirectionDistributionTest) {
+ std::default_random_engine engine(0);
+ std::uniform_real_distribution<float> distribution(0.0f, 1.0f);
+ const std::array<float, kNumReverbOctaveBands> energies{
+ {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
+ AcousticSource source({0.0f, 0.0f, 0.0f}, energies, [&engine, &distribution] {
+ return distribution(engine);
+ });
+
+ // Check that the direction vectors on generated rays are all normalized,
+ // i.e., of unit lengths.
+ for (size_t i = 0; i < 1000; ++i) {
+ AcousticRay ray = source.GenerateRay();
+ const float direction_squared_norm =
+ ray.direction()[0] * ray.direction()[0] +
+ ray.direction()[1] * ray.direction()[1] +
+ ray.direction()[2] * ray.direction()[2];
+ EXPECT_FLOAT_EQ(direction_squared_norm, 1.0f);
+ }
+
+ // For a ray whose direction is uniformly distributed over a sphere:
+ // - The PDF of theta is sin(theta), and the CDF is (1 - cos(theta)) / 2.
+ // - The PDF of phi is 1 / 2 pi, and the CDF is 0.5 + phi / 2 pi.
+ ValidateDistribution(100000, 100, [&source]() {
+ AcousticRay ray = source.GenerateRay();
+ const float cos_theta = ray.direction()[2];
+ return 0.5f * (1.0f - cos_theta);
+ });
+
+ ValidateDistribution(100000, 100, [&source]() {
+ AcousticRay ray = source.GenerateRay();
+ const float* direction = ray.direction();
+ const float phi = std::atan2(direction[1], direction[0]);
+ return 0.5f + phi / 2.0f / static_cast<float>(M_PI);
+ });
+}
+
+// Similar to GeneratedRayDirectionDistributionTest, but tests on the whole
+// set of rays generated by AcousticSource::GenerateStratifiedRays() that they
+// are uniformly distributed.
+TEST(AcousticSource, GeneratedStratifiedRaysDirectionDistributionTest) {
+ std::default_random_engine engine(0);
+ std::uniform_real_distribution<float> distribution(0.0f, 1.0f);
+ const std::array<float, kNumReverbOctaveBands> energies{
+ {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
+ AcousticSource source({0.0f, 0.0f, 0.0f}, energies, [&engine, &distribution] {
+ return distribution(engine);
+ });
+
+ // Check that the direction vectors on generated rays are all normalized,
+ // i.e., of unit lengths.
+ const size_t num_rays = 10000;
+ const size_t sqrt_num_rays = 100;
+ std::vector<AcousticRay> rays =
+ source.GenerateStratifiedRays(num_rays, sqrt_num_rays);
+ for (const AcousticRay& ray : rays) {
+ const float direction_squared_norm =
+ ray.direction()[0] * ray.direction()[0] +
+ ray.direction()[1] * ray.direction()[1] +
+ ray.direction()[2] * ray.direction()[2];
+ EXPECT_FLOAT_EQ(direction_squared_norm, 1.0f);
+ }
+
+ // For a ray whose direction is uniformly distributed over a sphere:
+ // - The PDF of theta is sin(theta), and the CDF is (1 - cos(theta)) / 2.
+ // - The PDF of phi is 1 / 2 pi, and the CDF is 0.5 + phi / 2 pi.
+ size_t ray_index = 0;
+ ValidateDistribution(num_rays, 100, [&rays, &ray_index]() {
+ const AcousticRay& ray = rays[ray_index];
+ ++ray_index;
+ const float cos_theta = ray.direction()[2];
+ return 0.5f * (1.0f - cos_theta);
+ });
+
+ ray_index = 0;
+ ValidateDistribution(num_rays, 100, [&rays, &ray_index]() {
+ const AcousticRay& ray = rays[ray_index];
+ ++ray_index;
+ const float* direction = ray.direction();
+ const float phi = std::atan2(direction[1], direction[0]);
+ return 0.5f + phi / kTwoPi;
+ });
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel.cc
new file mode 100644
index 000000000..86b4888b2
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel.cc
@@ -0,0 +1,128 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/collection_kernel.h"
+
+#include <array>
+#include <cmath>
+#include <vector>
+
+#include "Eigen/Core"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+using Eigen::Vector3f;
+
+namespace {
+
+// Adds a response to the output |energy_impulse_responses| array at an index
+// computed based on |total_source_listener_distance| and
+// |distance_to_impulse_response_index|. The values to be added are |energies|
+// multiplied by |energy_factor|.
+void AddResponse(float total_source_listener_distance,
+ float distance_to_impulse_response_index, float energy_factor,
+ const std::array<float, kNumReverbOctaveBands>& energies,
+ std::array<std::vector<float>, kNumReverbOctaveBands>*
+ energy_impulse_responses) {
+ const size_t impulse_response_index = static_cast<size_t>(
+ total_source_listener_distance * distance_to_impulse_response_index);
+
+ // It is OK if |impulse_response_index| exceeds the size of the listener's
+ // impulse response array (e.g. if the user only cares about the first second
+ // of the response), in which case we simply discard the contribution.
+ if (impulse_response_index >= (*energy_impulse_responses)[0].size()) {
+ return;
+ }
+
+ for (size_t i = 0; i < energy_impulse_responses->size(); ++i) {
+ (*energy_impulse_responses)[i][impulse_response_index] +=
+ energy_factor * energies.at(i);
+ }
+}
+
+} // namespace
+
+// In our implementation, |sphere_size_energy_factor_| is defined such that a
+// listener 1.0 meter away from the source would give an attenuation of 1.0.
+// Therefore the value is computed by:
+// 4.0 * PI * 1.0^2 / (PI * R^2) = 4.0 / R^2.
+CollectionKernel::CollectionKernel(float listener_sphere_radius,
+ float sampling_rate)
+ : sphere_size_energy_factor_(4.0f / listener_sphere_radius /
+ listener_sphere_radius),
+ distance_to_impulse_response_index_(sampling_rate / kSpeedOfSound) {}
+
+void CollectionKernel::Collect(const AcousticRay& ray, float weight,
+ AcousticListener* listener) const {
+ CHECK_EQ(ray.energies().size(), listener->energy_impulse_responses.size());
+
+ // Collect the energy contribution to the listener's impulse response at the
+ // arrival time.
+ // The distance to listener on this ray is approximated by projecting
+ // (listener.position - sub_ray's starting point) onto the ray direction.
+ const Vector3f ray_direction(ray.direction());
+ const Vector3f ray_starting_point =
+ Vector3f(ray.origin()) + ray.t_near() * ray_direction;
+ const float distance_to_listener_on_ray =
+ (listener->position - ray_starting_point).dot(ray_direction.normalized());
+ AddResponse(ray.prior_distance() + distance_to_listener_on_ray,
+ distance_to_impulse_response_index_,
+ weight * sphere_size_energy_factor_, ray.energies(),
+ &listener->energy_impulse_responses);
+}
+
+// In a diffuse rain algorithm, instead of relying on the Monte Carlo process
+// to estimate expected energy gathered by the sphere, we directly multiply
+// the probability of a ray intersecting the sphere to the energy to be
+// collected, thus ensuring the expected gathered energies are the same (see
+// also [internal ref]
+//
+// <Energy by Monte Carlo process> = <Energy by diffuse rain>
+// sum_i (Prob[ray_i intersects sphere] * Energy_i) =
+// sum_i (factor_i * Energy_i)
+//
+// So factor_i = Prob[ray_i intersects sphere]
+// ~ PDF(ray_i in the direction pointing to the listener) *
+// (projected solid angle of the listener sphere)
+// ~ PDF * PI * R^2 / (4.0 * PI * D^2)
+// = PDF * R^2 / (4.0 * D^2),
+//
+// where PDF is the probability density function, R the radius of the
+// listener sphere, and D the distance between the listener and the
+// reflection point.
+//
+// Combining |factor_i| with |sphere_size_energy_factor_| = 4.0 / R^2,
+// the total energy factor that needs to be multiplied to the energies on a
+// diffuse-rain ray is therefore (PDF / D^2).
+void CollectionKernel::CollectDiffuseRain(const AcousticRay& diffuse_rain_ray,
+ float weight, float direction_pdf,
+ AcousticListener* listener) const {
+ // Since a diffuse-rain ray already connects to the listener, and its
+ // direction already normalized, the distance to listener is its
+ // t_far - t_near.
+ const float distance_to_listener_on_ray =
+ diffuse_rain_ray.t_far() - diffuse_rain_ray.t_near();
+ const float diffuse_rain_energy_factor =
+ direction_pdf / distance_to_listener_on_ray / distance_to_listener_on_ray;
+ AddResponse(diffuse_rain_ray.prior_distance() + distance_to_listener_on_ray,
+ distance_to_impulse_response_index_,
+ weight * diffuse_rain_energy_factor, diffuse_rain_ray.energies(),
+ &listener->energy_impulse_responses);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel.h
new file mode 100644
index 000000000..970cc8dd4
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel.h
@@ -0,0 +1,79 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_COLLECTION_KERNEL_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_COLLECTION_KERNEL_H_
+
+#include "geometrical_acoustics/acoustic_listener.h"
+#include "geometrical_acoustics/acoustic_ray.h"
+
+namespace vraudio {
+
+// A class modeling the collection of energy contributions from an acoustic ray.
+class CollectionKernel {
+ public:
+ // Constructor.
+ //
+ // @param listener_sphere_radius Radius of listener spheres (m).
+ // @param sampling_rate Sampling rate (Hz). Together with speed of sound we
+ // can convert a physical time to an index in an impulse response array.
+ CollectionKernel(float listener_sphere_radius, float sampling_rate);
+
+ // Collects contributions from a ray to a listener's impulse response.
+ //
+ // @param ray AcousticRay whose contribution is to be collected.
+ // @param weight Weight of the contribution on |ray|.
+ // @param listener AcousticListener to which the contribution from |ray| is
+ // added in-place.
+ void Collect(const AcousticRay& ray, float weight,
+ AcousticListener* listener) const;
+
+ // Collects contributions from a diffuse-rain ray to a listener's impulse
+ // response.
+ //
+ // @param diffuse_rain_ray Diffuse-rain ray whose contribution is to be
+ // collected.
+ // @param weight Weight of the contribution on |diffuse_rain_ray|.
+ // @param direction_pdf The probability density function that a ray is in
+ // the direction of |diffuse_rain_ray|, with density taken over the solid
+ // angle. Used to scale the energy contributions. The unit is
+ // 1 / steradian.
+ // @param listener AcousticListener to which the contribution from |ray| is
+ // added in-place.
+ void CollectDiffuseRain(const AcousticRay& diffuse_rain_ray, float weight,
+ float direction_pdf,
+ AcousticListener* listener) const;
+
+ private:
+ // Because we use a sphere to collect rays, the number of rays (and therefore
+ // the amount of energy) collected is proportional to the cross section area
+ // of the sphere, i.e. energy ~ R^2, where R is the sphere radius. But
+ // because the energy at a listener position should be independent of the
+ // sphere radius (which is an artificial construct), we need to factor out
+ // the radius-dependency, by multiplying the sum of energy with a constant,
+ // |sphere_size_energy_factor_|.
+ //
+ // In our implementation, this constant is defined such that a listener
+ // 1.0 meter away from the source would give an attenuation of 1.0.
+ const float sphere_size_energy_factor_;
+
+ // Converting traveled distance in meter to an index in the impulse response
+ // array: index = distance (m) / speed_of_sound (m/s) * sampling_rate (1/s).
+ const float distance_to_impulse_response_index_;
+};
+
+} // namespace vraudio
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_COLLECTION_KERNEL_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel_test.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel_test.cc
new file mode 100644
index 000000000..369c55691
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/collection_kernel_test.cc
@@ -0,0 +1,353 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/collection_kernel.h"
+
+#include <cmath>
+#include <random>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "Eigen/Core"
+#include "base/constants_and_types.h"
+#include "geometrical_acoustics/acoustic_listener.h"
+#include "geometrical_acoustics/acoustic_ray.h"
+#include "geometrical_acoustics/acoustic_source.h"
+#include "geometrical_acoustics/sphere.h"
+#include "geometrical_acoustics/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+using Eigen::Vector3f;
+
+const float kSamplingRateHz = 1000.0f;
+const size_t kImpulseResponseNumSamples = 1000;
+
+class CollectionKernelTest : public testing::Test {
+ protected:
+ const std::array<float, kNumReverbOctaveBands> kUnitEnergies{
+ {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
+};
+
+TEST_F(CollectionKernelTest, CollectOneRayTest) {
+ // A listener at (5, 0, 0).
+ AcousticListener listener({5.0f, 0.0f, 0.0f}, kImpulseResponseNumSamples);
+
+ // One ray.
+ const Vector3f origin(0.0f, 0.0f, 0.0f);
+ const Vector3f direction(1.0f, 0.0f, 0.0f);
+ const float t_near = 0.0f;
+ const float t_far = 100.0f;
+ const float prior_distance = 0.0f;
+ const AcousticRay ray(origin.data(), direction.data(), t_near, t_far,
+ kUnitEnergies, AcousticRay::RayType::kSpecular,
+ prior_distance);
+
+ // Collect impulse response.
+ const float listener_sphere_radius = 0.1f;
+ CollectionKernel collection_kernel(
+ listener_sphere_radius, kSamplingRateHz);
+ collection_kernel.Collect(ray, 1.0f, &listener);
+
+ // Validate the impulse response.
+ // The theoretical index of the single non-zero element is:
+ // floor(distance (m) / kSpeedOfSound (m/s) * kSamplingRate (1/s)).
+ const float distance = (listener.position - origin).norm();
+ const size_t expected_index = static_cast<size_t>(
+ std::floor(distance / kSpeedOfSound * kSamplingRateHz));
+
+ // The theoretical energy value is energy * sphere_size_energy_factor.
+ const float expected_sphere_size_energy_factor =
+ 4.0f / listener_sphere_radius / listener_sphere_radius;
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ ValidateSparseFloatArray(
+ listener.energy_impulse_responses.at(i), {expected_index},
+ {kUnitEnergies.at(i) * expected_sphere_size_energy_factor},
+ kEpsilonFloat);
+ }
+}
+
+TEST_F(CollectionKernelTest, DiscardContributionTest) {
+ // A listener far away that it takes 2 seconds for the ray to arrive, which
+ // is longer than the impulse response of interest, i.e.
+ // kImpulseResponseNumSamples / kSamplingRateHz = 1 second.
+ // The contribution should be discarded.
+ AcousticListener listener({kSpeedOfSound * 2.0f, 0.0f, 0.0f},
+ kImpulseResponseNumSamples);
+
+ // One ray.
+ const Vector3f origin(0.0f, 0.0f, 0.0f);
+ const Vector3f direction(1.0f, 0.0f, 0.0f);
+ const float t_near = 0.0f;
+ const float t_far = 100.0f;
+ const float prior_distance = 0.0f;
+ const AcousticRay ray(origin.data(), direction.data(), t_near, t_far,
+ kUnitEnergies, AcousticRay::RayType::kSpecular,
+ prior_distance);
+
+ // Collect impulse response.
+ const float listener_sphere_radius = 0.1f;
+ CollectionKernel collection_kernel(
+ listener_sphere_radius, kSamplingRateHz);
+ collection_kernel.Collect(ray, 1.0f, &listener);
+
+ // Validate that the impulse responses are all zero.
+ for (const std::vector<float>& energy_impulse_response :
+ listener.energy_impulse_responses) {
+ ValidateSparseFloatArray(energy_impulse_response, {}, {}, kEpsilonFloat);
+ }
+}
+
+TEST_F(CollectionKernelTest, CollectOneRayWithPriorDistanceTest) {
+ // A listener at (5, 0, 0).
+ AcousticListener listener({5.0f, 0.0f, 0.0f}, kImpulseResponseNumSamples);
+
+ // One ray.
+ const Vector3f origin(0.0f, 0.0f, 0.0f);
+ const Vector3f direction(1.0f, 0.0f, 0.0f);
+ const float t_near = 0.0f;
+ const float t_far = 100.0f;
+ const float prior_distance = 10.0f;
+ const AcousticRay ray(origin.data(), direction.data(), t_near, t_far,
+ kUnitEnergies, AcousticRay::RayType::kSpecular,
+ prior_distance);
+
+ // Collect impulse response.
+ const float listener_sphere_radius = 0.1f;
+ CollectionKernel collection_kernel(
+ listener_sphere_radius, kSamplingRateHz);
+ collection_kernel.Collect(ray, 1.0f, &listener);
+
+ // Validate the impulse response.
+ // The theoretical index of the single non-zero element is:
+ // floor(distance (m) / kSpeedOfSound (m/s) * kSamplingRate (1/s)).
+ // In this test distance = prior_distance + <distance on this ray>.
+ const float distance = prior_distance + (listener.position - origin).norm();
+ const size_t expected_index = static_cast<size_t>(
+ std::floor(distance / kSpeedOfSound * kSamplingRateHz));
+
+ // The theoretical energy value is energy * sphere_size_energy_factor.
+ const float expected_sphere_size_energy_factor =
+ 4.0f / listener_sphere_radius / listener_sphere_radius;
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ ValidateSparseFloatArray(
+ listener.energy_impulse_responses.at(i), {expected_index},
+ {kUnitEnergies.at(i) * expected_sphere_size_energy_factor},
+ kEpsilonFloat);
+ }
+}
+
+TEST_F(CollectionKernelTest, SphereSizeEnergyFactorTest) {
+ // All listeners are at (0, 1, 0).
+ const Vector3f listener_position(0.0f, 1.0f, 0.0f);
+
+ // One ray.
+ const Vector3f origin(0.0f, 0.0f, 0.0f);
+ const Vector3f direction(0.0f, 1.0f, 0.0f);
+ const float t_near = 0.0f;
+ const float t_far = 100.0f;
+ const float prior_distance = 0.0f;
+ const AcousticRay ray(origin.data(), direction.data(), t_near, t_far,
+ kUnitEnergies, AcousticRay::RayType::kSpecular,
+ prior_distance);
+
+ // All listeners' impulse responses should have a non-zero element at index
+ // floor(distance (m) / kSpeedOfSound (m/s) * kSamplingRate (1/s)).
+ const float distance = (listener_position - origin).norm();
+ const size_t expected_index = static_cast<size_t>(
+ std::floor(distance / kSpeedOfSound * kSamplingRateHz));
+
+ // Collect impulse response using spheres with different radii.
+ // Expect that the energy values are energy * (4 / radius^2).
+ for (const float listener_sphere_radius : {0.1f, 0.2f, 0.3f, 0.4f, 0.5f}) {
+ AcousticListener listener(listener_position, kImpulseResponseNumSamples);
+ CollectionKernel collection_kernel(
+ listener_sphere_radius, kSamplingRateHz);
+ collection_kernel.Collect(ray, 1.0f, &listener);
+ const float expected_sphere_size_energy_factor =
+ 4.0f / listener_sphere_radius / listener_sphere_radius;
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ ValidateSparseFloatArray(
+ listener.energy_impulse_responses.at(i), {expected_index},
+ {kUnitEnergies.at(i) * expected_sphere_size_energy_factor},
+ kEpsilonFloat);
+ }
+ }
+}
+
+TEST_F(CollectionKernelTest, CollectMultipleRaysWithWeightsTest) {
+ // A listener at (0, 0, 1).
+ AcousticListener listener({0.0f, 0.0f, 1.0f}, kImpulseResponseNumSamples);
+
+ // Add many rays with different energies.
+ const Vector3f origin(0.0f, 0.0f, 0.0f);
+ const Vector3f direction(0.0f, 0.0f, 1.0f);
+ const float t_near = 0.0f;
+ const float t_far = 100.0f;
+ const float prior_distance = 2.0f;
+ std::vector<AcousticRay> rays;
+ std::array<float, kNumReverbOctaveBands> energies = {};
+ for (const float energy : {1.0f, 2.0f, 3.0f, 4.0f, 5.0f}) {
+ energies.fill(energy);
+ rays.emplace_back(origin.data(), direction.data(), t_near, t_far, energies,
+ AcousticRay::RayType::kSpecular, prior_distance);
+ }
+
+ // Collect impulse responses with different weights.
+ const float listener_sphere_radius = 0.1f;
+ CollectionKernel collection_kernel(
+ listener_sphere_radius, kSamplingRateHz);
+ const std::vector<float> weights = {8.0f, 4.0f, 2.0f, 1.0f, 0.5f};
+ for (size_t i = 0; i < rays.size(); ++i) {
+ collection_kernel.Collect(rays[i], weights[i], &listener);
+ }
+
+ // Validate the impulse responses.
+ // The theoretical index of the single non-zero element is:
+ // floor(distance (m) / kSpeedOfSound (m/s) * kSamplingRate (1/s)).
+ const float distance = prior_distance + (listener.position - origin).norm();
+ const size_t expected_index = static_cast<size_t>(
+ std::floor(distance / kSpeedOfSound * kSamplingRateHz));
+
+ // The theoretical energy value is the sum of
+ // energy * sphere_size_energy_factor * weight for all rays.
+ const float expected_sphere_size_energy_factor =
+ 4.0f / listener_sphere_radius / listener_sphere_radius;
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ float expected_energy = 0.0f;
+ for (size_t j = 0; j < rays.size(); ++j) {
+ expected_energy += rays[j].energies().at(i) *
+ expected_sphere_size_energy_factor * weights[j];
+ }
+ ValidateSparseFloatArray(listener.energy_impulse_responses.at(i),
+ {expected_index}, {expected_energy},
+ kEpsilonFloat);
+ }
+}
+
+// This test emulates a physically meaningful setting:
+// 1. N rays are shot in uniformly distributed directions from a source.
+// 2. Some rays intersect with a listener sphere and their contributions are
+// collected, weighted by 1/N; others miss and do not contribute.
+// 3. The total effect of partial collections and the sphere size cancel out,
+// so that the energy collected is actually proportional to 1/distance^2.
+TEST_F(CollectionKernelTest, CollectRaysInMonteCarloIntegrationTest) {
+ // A listener at (0, 0, 2).
+ AcousticListener listener({0.0f, 0.0f, 2.0f}, kImpulseResponseNumSamples);
+
+ // Use AcousticSource to generate N = 100,000 rays with uniformly distributed
+ // directions.
+ const Vector3f source_position(0.0f, 0.0f, 0.0f);
+ const size_t total_num_rays = 100000;
+ std::vector<AcousticRay> rays;
+ std::default_random_engine engine(0);
+ std::uniform_real_distribution<float> distribution(0.0f, 1.0f);
+ AcousticSource source(
+ source_position, kUnitEnergies,
+ [&engine, &distribution] { return distribution(engine); });
+ for (size_t i = 0; i < total_num_rays; ++i) {
+ rays.push_back(source.GenerateRay());
+ }
+
+ // Collect impulse responses using 1/N as weights. Only those rays
+ // intersecting with the listener sphere is collected.
+ const float listener_sphere_radius = 0.1f;
+ Sphere listener_sphere;
+ listener_sphere.center[0] = listener.position[0];
+ listener_sphere.center[1] = listener.position[1];
+ listener_sphere.center[2] = listener.position[2];
+ listener_sphere.radius = listener_sphere_radius;
+ listener_sphere.geometry_id = 1;
+ CollectionKernel collection_kernel(
+ listener_sphere_radius, kSamplingRateHz);
+ const float monte_carlo_weight = 1.0f / static_cast<float>(total_num_rays);
+ for (AcousticRay& ray : rays) {
+ SphereIntersection(listener_sphere, &ray);
+ if (ray.intersected_geometry_id() == listener_sphere.geometry_id) {
+ collection_kernel.Collect(ray, monte_carlo_weight, &listener);
+ }
+ }
+
+ // Validate the impulse response.
+ // The theoretical index of the single non-zero element is:
+ // floor(distance (m) / kSpeedOfSound (m/s) * kSamplingRate (1/s)).
+ const float distance = (listener.position - source_position).norm();
+ const size_t expected_index = static_cast<size_t>(
+ std::floor(distance / kSpeedOfSound * kSamplingRateHz));
+
+ // The expected relative error of a Monte Carlo integration is O(1/sqrt(M)),
+ // where M is the expected number of samples. A listener sphere of radius R
+ // at a distance D away from the source is expected to intersect
+ // M = N * (PI * R^2) / (4 * PI * D^2) = 0.25 * N * R^2 /D^2 rays.
+ // We use 2 / sqrt(M) as the tolerance for relative errors.
+ const float expected_num_intersecting_rays =
+ 0.25f * static_cast<float>(total_num_rays) * listener_sphere_radius *
+ listener_sphere_radius / (distance * distance);
+ const float relative_error_tolerance =
+ 2.0f / std::sqrt(expected_num_intersecting_rays);
+
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ // The theoretical energy value is energy / distance^2.
+ const float expected_energy = kUnitEnergies.at(i) / (distance * distance);
+ ValidateSparseFloatArray(listener.energy_impulse_responses.at(i),
+ {expected_index}, {expected_energy},
+ relative_error_tolerance);
+ }
+}
+
+TEST_F(CollectionKernelTest, CollectOneDiffuseRainRayTest) {
+ // A listener at (5, 0, 0).
+ AcousticListener listener({5.0f, 0.0f, 0.0f}, kImpulseResponseNumSamples);
+
+ // A diffuse-rain ray.
+ const Vector3f origin(0.0f, 0.0f, 0.0f);
+ const Vector3f direction(1.0f, 0.0f, 0.0f);
+ const float t_near = 0.0f;
+ const float t_far = 5.0f;
+ const float prior_distance = 0.0f;
+ const AcousticRay diffuse_rain_ray(
+ origin.data(), direction.data(), t_near, t_far, kUnitEnergies,
+ AcousticRay::RayType::kDiffuse, prior_distance);
+
+ // Collect impulse response, assuming the ray is reflected with a PDF of 0.1.
+ const float direction_pdf = 0.1f;
+ const float listener_sphere_radius = 0.1f;
+ CollectionKernel collection_kernel(listener_sphere_radius, kSamplingRateHz);
+ collection_kernel.CollectDiffuseRain(diffuse_rain_ray, direction_pdf, 1.0f,
+ &listener);
+
+ // Validate the impulse response.
+ // The theoretical index of the single non-zero element is:
+ // floor(distance (m) / kSpeedOfSound (m/s) * kSamplingRate (1/s)).
+ const float distance = (listener.position - origin).norm();
+ const size_t expected_index =
+ static_cast<size_t>(distance / kSpeedOfSound * kSamplingRateHz);
+
+ // The theoretical energy value is energy * energy_factor, where
+ // energy_factor is PDF / distance^2.
+ const float expected_energy_factor = direction_pdf / distance / distance;
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ ValidateSparseFloatArray(
+ listener.energy_impulse_responses.at(i), {expected_index},
+ {kUnitEnergies.at(i) * expected_energy_factor}, kEpsilonFloat);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60.cc
new file mode 100644
index 000000000..547f5c1ab
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60.cc
@@ -0,0 +1,155 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include <cmath>
+
+#include "base/logging.h"
+#include "base/misc_math.h"
+#include "geometrical_acoustics/estimating_rt60.h"
+
+namespace vraudio {
+
+// The RT60 is estimated by fitting a line to the log of energy. We collect
+// energy from individual impulse responses into bins and use each bin's
+// midpoint and height (average energy inside the bin) as a data point (x, y)
+// for the line fitting algorithm. For example, for a bin that collects 100.0
+// units of energy from 0.0s to 2.0s has a midpoint of 1.0s and height of
+// log10(100.0 / 2.0).
+//
+// In general we have some liberty in how we divide the whole reverb tail as
+// bins. For example, for a reverb tail of 3.5 seconds long:
+// ----------------------------------------------------------------------->
+//
+// we may divide it into 7 bins of widths 0.5 seconds:
+// |---------|---------|---------|---------|---------|---------|---------|>
+// 0.0s 0.5s 1.0s 1.5s 2.0s 2.5s 3.0s 3.5s
+//
+// or we may divide it into 3 bins of widths {0.5s, 1.0s, 2.0s}:
+// |---------|-------------------|---------------------------------------|>
+// 0.0s 0.5s 1.5s 3.5s
+//
+// In this implementation, we adopted a scheme that lets the accumulated energy
+// determine the width. The first bin would contain 0.5 of the total energy of
+// the whole reverb tail, the second bin would contain 0.5 of the remaining
+// energy after the first bin, and so on. The number 0.5 can be replaced by any
+// value in [0.0, 1.0), which is defined as |kBinEnergyRatio| in our
+// implementation.
+//
+// The advantage of this scheme is that there will not be any empty bin (of
+// height zero), which might occur because the impulse responses can be sparse
+// at certain regions. An empty bin is a particularly bad data point and
+// will greatly reduce the efficacy of the linear fitting. (For a more
+// detailed discussion of the sparsity of impulse responses, see [internal ref]
+float EstimateRT60(const std::vector<float>& energy_impulse_responses,
+ const float sampling_rate) {
+ // First initialize the remaining energy to be the total energy.
+ float remaining_energy = 0.0f;
+ for (const float energy : energy_impulse_responses) {
+ remaining_energy += energy;
+ }
+
+ // The collected data points: the bin's midpoints and heights.
+ std::vector<float> bin_midpoints;
+ std::vector<float> bin_heights;
+
+ // The target energy (as a ratio of the remaining energy) that a bin should
+ // collect before closing.
+ const float kBinEnergyRatio = 0.5f;
+ float target_accumulated_energy = remaining_energy * kBinEnergyRatio;
+
+ // Stop when the remaining energy is below this threshold.
+ const float kRemainingThreshold = remaining_energy * 1e-3f;
+
+ // The iteration goes as follows:
+ // 1. A bin is opened.
+ // 2. Energy is accumulated from impulse responses.
+ // 3. When the accumulated energy exceeds the target, the bin is closed and
+ // its midpoint and height recorded.
+ // 4. Repeat 1-3 until the remaining energy is below a threshold.
+ float accumulated_energy = 0.0f;
+ float bin_begin = -1.0f;
+ for (size_t i = 0; i < energy_impulse_responses.size(); ++i) {
+ if (energy_impulse_responses[i] <= 0.0f) {
+ continue;
+ }
+
+ // The first non-zero response is found; set the |bin_begin|.
+ if (bin_begin < 0.0f) {
+ bin_begin = static_cast<float>(i) / sampling_rate;
+ }
+
+ accumulated_energy += energy_impulse_responses[i];
+
+ // Close the bin if the accumulated energy meets the target.
+ if (accumulated_energy > target_accumulated_energy) {
+ // Compute the bin's midpoint, in the unit of second.
+ const float bin_end = static_cast<float>(i + 1) / sampling_rate;
+ const float bin_midpoint = 0.5f * (bin_begin + bin_end);
+
+ // Compute the bin's height as the average energy inside the bin, in the
+ // unit of dB.
+ const float bin_width = bin_end - bin_begin;
+ const float bin_height =
+ 10.0f * std::log10(accumulated_energy / bin_width);
+
+ // Collect the data point.
+ bin_midpoints.push_back(bin_midpoint);
+ bin_heights.push_back(bin_height);
+
+ // Terminate the data point collection when the remaining energy is below
+ // threshold.
+ remaining_energy -= accumulated_energy;
+ if (remaining_energy < kRemainingThreshold) {
+ break;
+ }
+
+ // Start a new bin and update the remaining energy.
+ target_accumulated_energy = remaining_energy * kBinEnergyRatio;
+ bin_begin = bin_end;
+ accumulated_energy = 0.0f;
+ }
+ }
+
+ // Require at least some data points to perform linear fitting.
+ const size_t kMinNumDataPointsForFitting = 3;
+ if (bin_midpoints.size() < kMinNumDataPointsForFitting) {
+ LOG(WARNING) << "Insufficient number of data points for fitting";
+ return 0.0f;
+ }
+
+ // Perform linear fitting.
+ float slope = 0.0f;
+ float intercept = 0.0f;
+ float r_square = 0.0f;
+ if (!LinearLeastSquareFitting(bin_midpoints, bin_heights, &slope, &intercept,
+ &r_square)) {
+ LOG(WARNING) << "Linear least square fitting failed";
+ return 0.0f;
+ }
+ LOG(INFO) << "Fitted slope= " << slope << "; intercept= " << intercept
+ << "; R^2= " << r_square;
+
+ // RT60 is defined as how long it takes for the energy to decay 60 dB.
+ // Note that |slope| should be negative.
+ if (slope < 0.0f) {
+ return -60.0f / slope;
+ } else {
+ LOG(WARNING) << "Invalid RT60 from non-negative slope";
+ return 0.0f;
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60.h
new file mode 100644
index 000000000..6e7d5a12d
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60.h
@@ -0,0 +1,38 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Function to estimate RT60s.
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ESTIMATING_RT60_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ESTIMATING_RT60_H_
+
+#include <vector>
+
+namespace vraudio {
+
+// Estimates the RT60 value from collected energy impulse responses.
+//
+// @param energy_impulse_responses Energy impulse responses.
+// @param sampling_rate Sampling rate in Hz. Used to convert indices of the
+// impulse response vector to time in seconds.
+// @return Estimated RT60 value in seconds. Returns 0.0f (meaning no reverb
+// effect at all) when the estimation fails.
+float EstimateRT60(const std::vector<float>& energy_impulse_responses,
+ float sampling_rate);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_ESTIMATING_RT60_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60_test.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60_test.cc
new file mode 100644
index 000000000..e48386136
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/estimating_rt60_test.cc
@@ -0,0 +1,185 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/estimating_rt60.h"
+
+#include <cmath>
+#include <memory>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "geometrical_acoustics/impulse_response_computer.h"
+#include "geometrical_acoustics/test_util.h"
+#include "platforms/common/room_effects_utils.h"
+
+namespace vraudio {
+
+namespace {
+
+class EstimateRT60Test : public testing::Test {
+ public:
+ EstimateRT60Test() {
+ Vertex min_corner = {cube_center_[0] - 0.5f * cube_dimensions_[0],
+ cube_center_[1] - 0.5f * cube_dimensions_[1],
+ cube_center_[2] - 0.5f * cube_dimensions_[2]};
+ Vertex max_corner = {cube_center_[0] + 0.5f * cube_dimensions_[0],
+ cube_center_[1] + 0.5f * cube_dimensions_[1],
+ cube_center_[2] + 0.5f * cube_dimensions_[2]};
+
+ BuildTestBoxScene(min_corner, max_corner, &cube_vertices_, &cube_triangles_,
+ &cube_wall_triangles_);
+ }
+
+ protected:
+ std::vector<float> CollectImpulseResponsesAndEstimateRT60(
+ const std::vector<Path>& paths, SceneManager* scene_manager) {
+ // Listener and impulse response computer.
+ std::unique_ptr<std::vector<AcousticListener>> listeners(
+ new std::vector<AcousticListener>);
+ listeners->emplace_back(Eigen::Vector3f(cube_center_),
+ impulse_response_num_samples_);
+ ImpulseResponseComputer impulse_response_computer(
+ listener_sphere_radius_, sampling_rate_, std::move(listeners),
+ scene_manager);
+
+ // Collect impulse responses.
+ impulse_response_computer.CollectContributions(paths);
+ const std::array<std::vector<float>, kNumReverbOctaveBands>&
+ energy_impulse_responses =
+ impulse_response_computer.GetFinalizedListeners()
+ .at(0)
+ .energy_impulse_responses;
+
+ // Estimate RT60 values.
+ std::vector<float> output_rt60_values(kNumReverbOctaveBands, 0.0f);
+ for (size_t band = 0; band < kNumReverbOctaveBands; ++band) {
+ output_rt60_values[band] =
+ EstimateRT60(energy_impulse_responses[band], sampling_rate_);
+ }
+ return output_rt60_values;
+ }
+
+ // Ray-tracing related fields.
+ const float sampling_rate_ = 48000.0f;
+ const float listener_sphere_radius_ = 0.1f;
+ const size_t impulse_response_num_samples_ = 96000;
+ Eigen::Vector3f listener_position_;
+
+ // Data describing a cube scene.
+ std::vector<Vertex> cube_vertices_;
+ std::vector<Triangle> cube_triangles_;
+ const float cube_center_[3] = {0.5f, 0.5f, 0.5f};
+ const float cube_dimensions_[3] = {1.0f, 1.0f, 1.0f};
+
+ std::vector<MaterialName> wall_materials_;
+
+ // Triangles for six walls of a cube. Useful for assigning surface materials.
+ std::vector<std::unordered_set<unsigned int>> cube_wall_triangles_;
+};
+
+// Tests that estimating from an empty impulse responses vector fails.
+TEST_F(EstimateRT60Test, EstimateFromEmptyImpulseResponsesFails) {
+ std::vector<float> empty_energy_impulse_responses;
+
+ // Expect that the estimation function returns 0.
+ EXPECT_EQ(0.0f, EstimateRT60(empty_energy_impulse_responses, sampling_rate_));
+}
+
+// Tests that if the impulse responses are increasing in energy and therefore
+// RT60 is not defined, the estimation returns 0.
+TEST_F(EstimateRT60Test, EstimateFromIncreasingEnergyFails) {
+ std::vector<float> increasing_energy_impulse_responses(1000, 0.0f);
+ for (size_t i = 0; i < 1000; ++i) {
+ increasing_energy_impulse_responses[i] = static_cast<float>(i) * 1e-3f;
+ }
+
+ // Expect that the estimation function returns 0.
+ EXPECT_EQ(0.0f,
+ EstimateRT60(increasing_energy_impulse_responses, sampling_rate_));
+}
+
+// Tests that if estimating from perfectly-constructed, exponentially-decaying
+// impulse responses, then the known RT60 is returned.
+TEST_F(EstimateRT60Test, EstimateFromExponentiallyDecayingResponses) {
+ std::vector<float> energy_impulse_responses(1000, 0.0f);
+ const std::vector<float> expected_RT60s = {0.05f, 0.1f, 0.2f,
+ 0.5f, 1.0f, 2.0f};
+
+ for (const float expected_RT60 : expected_RT60s) {
+ // Construct an exponentially decaying reverb tail with a known RT60, whose
+ // energy at index i is 10^(6 * i / sampling_rate / RT60).
+ for (size_t i = 1; i < energy_impulse_responses.size(); ++i) {
+ energy_impulse_responses[i] = std::pow(
+ 10.0f, -(static_cast<float>(6 * i) / sampling_rate_ / expected_RT60));
+ }
+
+ // Expect that the estimated RT60 is close to the expected one.
+ EXPECT_NEAR(expected_RT60,
+ EstimateRT60(energy_impulse_responses, sampling_rate_), 0.01f);
+ }
+}
+
+// Tests that RT60s estimated from a cube scene agrees with those computed
+// using RoomEffectsUtils::ComputeReverbProperties() (which uses Eyring's
+// equation under the hood).
+TEST_F(EstimateRT60Test, EstimateFromCubeSceneAgreesWithHeuristics) {
+ wall_materials_ = std::vector<MaterialName>{
+ MaterialName::kPlasterSmooth,
+ MaterialName::kLinoleumOnConcrete,
+ MaterialName::kConcreteBlockPainted,
+ MaterialName::kGlassThin,
+ MaterialName::kBrickBare,
+ MaterialName::kPlywoodPanel,
+ };
+
+ // Trace rays in a cube scene and estimate RT60s.
+ SceneManager scene_manager;
+ std::vector<Path> paths = TracePathsInTestcene(
+ 100 /* min_num_rays */, 100 /* max_depth */,
+ 1e-12f /* energy_threshold */, cube_center_, cube_vertices_,
+ cube_triangles_, cube_wall_triangles_, wall_materials_, &scene_manager);
+ std::vector<float> estimated_rt60_values =
+ CollectImpulseResponsesAndEstimateRT60(paths, &scene_manager);
+
+ // A default room properties with some fields set to non-default values.
+ RoomProperties room_properties;
+ room_properties.position[0] = cube_center_[0];
+ room_properties.position[1] = cube_center_[1];
+ room_properties.position[2] = cube_center_[2];
+ room_properties.dimensions[0] = cube_dimensions_[0];
+ room_properties.dimensions[1] = cube_dimensions_[1];
+ room_properties.dimensions[2] = cube_dimensions_[2];
+ for (size_t wall = 0; wall < kNumRoomSurfaces; ++wall) {
+ room_properties.material_names[wall] = wall_materials_[wall];
+ }
+
+ // Reverb properties computed using heuristics.
+ const ReverbProperties reverb_properties =
+ ComputeReverbProperties(room_properties);
+
+ // Compare the two sets of RT60s.
+ const float rt60_error_tolerance = 0.05f;
+ for (size_t band = 0; band < kNumReverbOctaveBands; ++band) {
+ const float estimated_rt60 = estimated_rt60_values[band];
+ const float expected_rt60 = reverb_properties.rt60_values[band];
+ EXPECT_NEAR(estimated_rt60, expected_rt60, rt60_error_tolerance);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer.cc
new file mode 100644
index 000000000..a4771ed58
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer.cc
@@ -0,0 +1,188 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/impulse_response_computer.h"
+
+#include <utility>
+
+#include "Eigen/Core"
+#include "base/logging.h"
+#include "geometrical_acoustics/parallel_for.h"
+#include "geometrical_acoustics/reflection_kernel.h"
+
+namespace vraudio {
+
+using Eigen::Vector3f;
+
+ImpulseResponseComputer::ImpulseResponseComputer(
+ float listener_sphere_radius, float sampling_rate,
+ std::unique_ptr<std::vector<AcousticListener>> listeners,
+ SceneManager* scene_manager)
+ : listeners_(std::move(listeners)),
+ collection_kernel_(listener_sphere_radius, sampling_rate),
+ scene_manager_(scene_manager),
+ finalized_(false),
+ num_total_paths_(0) {
+ CHECK_NOTNULL(listeners_.get());
+ scene_manager->BuildListenerScene(*listeners_, listener_sphere_radius);
+}
+
+ImpulseResponseComputer::~ImpulseResponseComputer() {}
+
+void ImpulseResponseComputer::CollectContributions(
+ const std::vector<Path>& paths_batch) {
+ // Do not collect anymore if finalized.
+ if (finalized_) {
+ return;
+ }
+
+ CHECK(scene_manager_->is_scene_committed());
+ CHECK(scene_manager_->is_listener_scene_committed());
+
+ const unsigned int num_threads = GetNumberOfHardwareThreads();
+ ParallelFor(
+ num_threads, paths_batch.size(), [&paths_batch, this](size_t path_index) {
+ const Path& path = paths_batch.at(path_index);
+ const AcousticRay* previous_ray = nullptr;
+ AcousticRay diffuse_rain_ray;
+ for (const AcousticRay& ray : path.rays) {
+ // Handle diffuse reflections separately using the diffuse rain
+ // algorithm. For details, see "A Fast Reverberation Estimator for
+ // Virtual Environments" by Schroder et al., 2007.
+ if (ray.type() == AcousticRay::RayType::kDiffuse &&
+ previous_ray != nullptr) {
+ // Connect each listener from the reflection point.
+ for (AcousticListener& listener : *listeners_) {
+ const ReflectionKernel& reflection =
+ scene_manager_->GetAssociatedReflectionKernel(
+ previous_ray->intersected_primitive_id());
+
+ float reflection_pdf = 0.0f;
+ reflection.ReflectDiffuseRain(*previous_ray, ray,
+ listener.position, &reflection_pdf,
+ &diffuse_rain_ray);
+
+ if (!diffuse_rain_ray.Intersect(scene_manager_->scene())) {
+ // Get PDF from the reflection kernel that the previous ray
+ // intersects.
+ collection_kernel_.CollectDiffuseRain(
+ diffuse_rain_ray, 1.0f /* weight */, reflection_pdf,
+ &listener);
+ }
+ }
+
+ previous_ray = &ray;
+ continue;
+ }
+
+ // |ray| may intersect multiple listener spheres. We handle the
+ // intersections one-by-one as following:
+ // 1. Find the first intersected sphere S. The ray's data will be
+ // modified so that ray.t_far() corresponds to the intersection
+ // point. Terminate if no intersection is found.
+ // 2. Collect contribution to the listener associated to S.
+ // 3. Spawn a sub-ray that starts at the intersection point (moved
+ // slightly inside S) and repeat 1.
+ //
+ // Since the origin of the new sub-ray is inside sphere S, it does not
+ // intersect with S again (according to our definition of
+ // intersections; see Sphere::SphereIntersection()).
+ //
+ // Each of the sub-rays has the same origin and direction as the
+ // original ray, but with t_near and t_far partitioning the interval
+ // between the original ray's t_near and t_far. For example:
+ //
+ // ray: t_near = 0.0 ------------------------------> t_far = 5.0
+ // sub_ray_1: t_near = 0.0 -------> t_far = 2.0
+ // sub_ray_2: t_near = 2.0 ---------> t_far = 5.0
+ AcousticRay sub_ray(ray.origin(), ray.direction(), ray.t_near(),
+ ray.t_far(), ray.energies(), ray.type(),
+ ray.prior_distance());
+
+ // Norm of |ray.direction|. Useful in computing
+ // |sub_ray.prior_distance| later.
+ const float ray_direction_norm = Vector3f(ray.direction()).norm();
+
+ // In theory with sufficient AcousticRay::kRayEpsilon, the same sphere
+ // should not be intersected twice by the same ray segment. In
+ // practice, due to floating-point inaccuracy, this might still
+ // happen. We explicitly prevent double-counting by checking whether
+ // the intersected sphere id has changed.
+ unsigned int previous_intersected_sphere_id = RTC_INVALID_GEOMETRY_ID;
+
+ // To prevent an infinite loop, terminate if one ray segment has more
+ // intersections than the number of listeners, which is an upper bound
+ // of the number of actually contributing sub-rays.
+ size_t num_intersections = 0;
+ while (sub_ray.Intersect(scene_manager_->listener_scene()) &&
+ num_intersections < listeners_->size()) {
+ const unsigned int sphere_id = sub_ray.intersected_geometry_id();
+ if (sphere_id != previous_intersected_sphere_id) {
+ AcousticListener& listener = listeners_->at(
+ scene_manager_->GetListenerIndexFromSphereId(sphere_id));
+ collection_kernel_.Collect(sub_ray, 1.0f /* weight */, &listener);
+ } else {
+ LOG(WARNING) << "Double intersection with sphere[" << sphere_id
+ << "]; contribution skipped. Consider increasing "
+ << "AcousticRay::kRayEpsilon";
+ }
+ previous_intersected_sphere_id = sphere_id;
+
+ // Spawn a new sub-ray whose t_near corresponds to the intersection
+ // point. The new sub-ray's |prior_distance| field is extended by
+ // the distance traveled by the old sub-ray up to the intersection
+ // point.
+ const float new_prior_distance =
+ sub_ray.prior_distance() +
+ (sub_ray.t_far() - sub_ray.t_near()) * ray_direction_norm;
+ sub_ray = AcousticRay(ray.origin(), ray.direction(),
+ sub_ray.t_far() + AcousticRay::kRayEpsilon,
+ ray.t_far(), ray.energies(), ray.type(),
+ new_prior_distance);
+ ++num_intersections;
+ }
+
+ previous_ray = &ray;
+ }
+ });
+ num_total_paths_ += paths_batch.size();
+}
+
+const std::vector<AcousticListener>&
+ImpulseResponseComputer::GetFinalizedListeners() {
+ DCHECK_GT(num_total_paths_, 0U);
+
+ if (!finalized_) {
+ // For a Monte Carlo method that estimates a value with N samples,
+ // <estimated value> = 1/N * sum(<value of a sample>). We apply the
+ // 1/N weight after all impulse responses for all listeners are collected.
+ const float monte_carlo_weight =
+ 1.0f / static_cast<float>(num_total_paths_);
+ for (AcousticListener& listener : *listeners_) {
+ for (std::vector<float>& responses_in_band :
+ listener.energy_impulse_responses) {
+ for (float& response : responses_in_band) {
+ response *= monte_carlo_weight;
+ }
+ }
+ }
+ finalized_ = true;
+ }
+
+ return *listeners_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer.h
new file mode 100644
index 000000000..59f3d91a0
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer.h
@@ -0,0 +1,112 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_IMPULSE_RESPONSE_COMPUTER_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_IMPULSE_RESPONSE_COMPUTER_H_
+
+#include <memory>
+#include <vector>
+
+#include "geometrical_acoustics/acoustic_listener.h"
+#include "geometrical_acoustics/collection_kernel.h"
+#include "geometrical_acoustics/path.h"
+#include "geometrical_acoustics/scene_manager.h"
+
+namespace vraudio {
+
+// A class that computes impulse responses from traced sound propagation paths
+// and modifies the listener's data (namely listener.energy_impulse_response)
+// in place.
+// Each listener is associated to a sphere with finite volume, and rays that
+// intersect with the sphere contributes energy to the listener.
+//
+// This class is to be used in conjunction with a PathTracer, which produces
+// batches of sound propagation paths that this class consumes.
+// Example use (which follows a create-collect-finalize pattern):
+//
+// // Create.
+// ImpulseResponseComputer impulse_response_computer(0.1f, 44100.0f,
+// std::move(listeners));
+// // Collect.
+// for (const auto& source : sources) {
+// // Divide |total_num_paths| into |num_batch| batches, each of size
+// // |num_rays_per_batch|.
+// for (size_t i = 0; i < num_batch; ++i) {
+// paths_batch =
+// path_tracer.TracePaths(source, num_rays_per_batch, 10, 1e-6);
+// impulse_response_computer.CollectContributions(paths_batch,
+// total_num_paths);
+// }
+// }
+//
+// // Finalize and use the impulse responses in listeners e.g. write them to
+// // a file or pass them to an audio render.
+// for (const auto& listener:
+// impulse_response_computer. GetFinalizedListeners()) {
+// const auto& responses = listener.energy_impulse_responses;
+// // Do something with |responses|.
+// }
+class ImpulseResponseComputer {
+ public:
+ // Constructor.
+ //
+ // @param listener_sphere_radius Radius of listener spheres (m).
+ // @param sampling_rate Sampling rate (Hz).
+ // @param listeners Vector of AcousticListener's whose impulse responses are
+ // to be computed.
+ // @param scene_manager SceneManager.
+ ImpulseResponseComputer(
+ float listener_sphere_radius, float sampling_rate,
+ std::unique_ptr<std::vector<AcousticListener>> listeners,
+ SceneManager* scene_manager);
+ virtual ~ImpulseResponseComputer();
+
+ // Collects contributions from a batch of paths to all listeners if
+ // the collection is not finalized yet.
+ //
+ // @param paths_batch All sound propagation paths in a batch.
+ void CollectContributions(const std::vector<Path>& paths_batch);
+
+ // Finalizes the listeners and returns them. After calling this, further
+ // calls to CollectContributions() have no effect.
+ //
+ // @return Vector of finalized listeners.
+ const std::vector<AcousticListener>& GetFinalizedListeners();
+
+ private:
+ // Vector of listeners.
+ const std::unique_ptr<std::vector<AcousticListener>> listeners_;
+
+ // Collection kernel used to collect contributions from rays to listeners.
+ CollectionKernel collection_kernel_;
+
+ // Scene manager. Used to keep records of listener spheres for ray-sphere
+ // intersection tests. Also used in the diffuse rain algorithm to to test
+ // whether there is an un-obstructed path from a reflection point to a
+ // listener.
+ SceneManager* scene_manager_;
+
+ // Is the collection finalized.
+ bool finalized_;
+
+ // Total number of paths (contributing or not) that energies are collected
+ // from before the collection is finalized. This will be used to average
+ // energy contributions.
+ size_t num_total_paths_;
+};
+
+} // namespace vraudio
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_IMPULSE_RESPONSE_COMPUTER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer_test.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer_test.cc
new file mode 100644
index 000000000..f3e042586
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/impulse_response_computer_test.cc
@@ -0,0 +1,377 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/impulse_response_computer.h"
+
+#include <array>
+#include <cmath>
+#include <random>
+#include <utility>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "geometrical_acoustics/acoustic_listener.h"
+#include "geometrical_acoustics/acoustic_ray.h"
+#include "geometrical_acoustics/acoustic_source.h"
+#include "geometrical_acoustics/path.h"
+#include "geometrical_acoustics/scene_manager.h"
+#include "geometrical_acoustics/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+using Eigen::Vector3f;
+
+const float kSamplingRateHz = 1000.0f;
+const float kListenerSphereRadiusMeter = 0.1f;
+const size_t kImpulseResponseNumSamples = 1000;
+
+// The energy collected from a ray.
+// kCollectedEnergyPerRay
+// = 1.0 * CollectionKernel::sphere_size_energy_factor_
+// = 1.0 * 4.0 / kListenerSphereRadius^2 = 1.0 * 4.0 / 0.01
+// = 400.0.
+// See CollectionKernel::sphere_size_energy_factor_ for details.
+const float kCollectedEnergyPerRay = 400.0f;
+
+class ImpulseResponseComputerTest : public testing::Test {
+ public:
+ void SetUp() override { paths_.clear(); }
+
+ protected:
+ void AddListenersAtPositions(const std::vector<Vector3f>& positions,
+ std::vector<AcousticListener>* listeners) {
+ for (const Vector3f& position : positions) {
+ listeners->emplace_back(position, kImpulseResponseNumSamples);
+ }
+ }
+
+ // Validate indices and values of the impulse responses for all listeners.
+ //
+ // param@ listeners Listeners whose impulse responses are to be validated.
+ // param@ expected_indices_for_listeners Expected indices of the non-zero
+ // elements for all listeners' impulse responses. So that
+ // expected_indices_for_listeners[i][j] is the index of the j-th non-zero
+ // element in listener i's impulse response.
+ // param@ expected_energies_for_listeners Expected energy values of the
+ // non-zero elements for all listeners' impulse responses. So that
+ // the value stored in expected_energies_for_listeners[i][j] is the j-th
+ // non-zero element in listener i's impulse response.
+ // param@ relative_error_tolerance_for_listeners Tolerances of relative errors
+ // when comparing energy impulse responses for all listeners.
+ void ValidateImpulseResponses(
+ const std::vector<AcousticListener>& listeners,
+ const std::vector<std::vector<size_t>>& expected_indices_for_listeners,
+ const std::vector<std::vector<float>>& expected_energies_for_listeners,
+ const std::vector<float> relative_error_tolerances_for_listeners) {
+ ASSERT_EQ(expected_indices_for_listeners.size(), listeners.size());
+ ASSERT_EQ(expected_energies_for_listeners.size(), listeners.size());
+ ASSERT_EQ(relative_error_tolerances_for_listeners.size(), listeners.size());
+ for (size_t i = 0; i < listeners.size(); ++i) {
+ for (size_t j = 0; j < kNumReverbOctaveBands; ++j) {
+ ValidateSparseFloatArray(listeners[i].energy_impulse_responses.at(j),
+ expected_indices_for_listeners[i],
+ expected_energies_for_listeners[i],
+ relative_error_tolerances_for_listeners[i]);
+ }
+ }
+ }
+
+ const std::array<float, kNumReverbOctaveBands> kUnitEnergies{
+ {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
+
+ std::vector<Path> paths_;
+ SceneManager scene_manager_;
+};
+
+TEST_F(ImpulseResponseComputerTest, OnePathMultipleRaysOneListenerTest) {
+ // A listener at (1, 0, 0).
+ std::unique_ptr<std::vector<AcousticListener>> listeners(
+ new std::vector<AcousticListener>);
+ const Vector3f listener_position(1.0f, 0.0f, 0.0f);
+ AddListenersAtPositions({listener_position}, listeners.get());
+
+ scene_manager_.BuildScene({}, {});
+ ImpulseResponseComputer impulse_response_computer(
+ kListenerSphereRadiusMeter, kSamplingRateHz, std::move(listeners),
+ &scene_manager_);
+
+ // One path with multiple ray segments.
+ Path path;
+
+ // Imagine a scene with two specular walls parallel to the y-z plane.
+ // One (called the right wall) is at (2, 0, 0) and the other (called the
+ // left wall) at (-2, 0, 0). A ray shooting at the +x direction will reflect
+ // back-and-forth between these parallel walls.
+ //
+ // First ray segment: from source at (0, 0, 0), shooting at (1, 0, 0).
+ const Vector3f source_position(0.0f, 0.0f, 0.0f);
+ const Vector3f left_to_right_direction(1.0f, 0.0f, 0.0f);
+ const float wall_position_x = 2.0f;
+ path.rays.emplace_back(source_position.data(), left_to_right_direction.data(),
+ 0.0f, wall_position_x, kUnitEnergies,
+ AcousticRay::RayType::kSpecular, 0.0f);
+
+ // Also record the distances traveled each time the ray passes through the
+ // listener sphere. This will be used later to verify the indices of non-zero
+ // elements in the impulse response.
+ std::vector<float> source_listener_distances = {
+ (source_position - listener_position).norm()}; // First segment.
+
+ // The rest of the reflections. Half of these rays start from the left wall
+ // and stop at the right wall, and the other half start from the right wall
+ // and stop at the left wall. We compute up to order |max_order| = 10.
+ const Vector3f right_wall_origin(wall_position_x, 0.0f, 0.0f);
+ const Vector3f left_wall_origin(-wall_position_x, 0.0f, 0.0f);
+ const float distance_between_walls =
+ (right_wall_origin - left_wall_origin).norm();
+ const float listener_left_wall_distance =
+ (listener_position - left_wall_origin).norm();
+ const float listener_right_wall_distance =
+ (listener_position - right_wall_origin).norm();
+ const Vector3f right_to_left_direction = -left_to_right_direction;
+ const size_t max_order = 10;
+
+ // Prior distance corresponds to the first ray segment.
+ float prior_distance = (right_wall_origin - source_position).norm();
+ for (size_t order = 1; order < max_order; ++order) {
+ float source_listener_distance = source_listener_distances.back();
+ if (order % 2 == 0) {
+ path.rays.emplace_back(left_wall_origin.data(),
+ left_to_right_direction.data(), 0.0f,
+ distance_between_walls, kUnitEnergies,
+ AcousticRay::RayType::kSpecular, prior_distance);
+
+ // Add the distance of {listener -> left wall -> listener} to the
+ // accumulated source-listener distance.
+ source_listener_distance += 2.0f * listener_left_wall_distance;
+ } else {
+ path.rays.emplace_back(right_wall_origin.data(),
+ right_to_left_direction.data(), 0.0f,
+ distance_between_walls, kUnitEnergies,
+ AcousticRay::RayType::kSpecular, prior_distance);
+
+ // Add the distance of {listener -> right wall -> listener} to the
+ // accumulated source-listener distance.
+ source_listener_distance += 2.0f * listener_right_wall_distance;
+ }
+ source_listener_distances.push_back(source_listener_distance);
+
+ // Each reflection adds |distance_between_walls| to |prior_distance|.
+ prior_distance += distance_between_walls;
+ }
+ paths_.push_back(path);
+
+ // Compute impulse response.
+ impulse_response_computer.CollectContributions(paths_);
+
+ // Validate the impulse responses.
+ // The expected indices are
+ // floor(distance / kSpeedOfSound (m/s) * kSamplingRateHz (1/s)).
+ // The theoretical energy values are all kCollectedEnergyPerRay.
+ std::vector<std::vector<size_t>> expected_indices_for_listeners(1);
+ std::vector<std::vector<float>> expected_energies_for_listeners(1);
+ for (size_t order = 0; order < max_order; ++order) {
+ expected_indices_for_listeners.back().push_back(
+ static_cast<size_t>(std::floor(source_listener_distances[order] /
+ kSpeedOfSound * kSamplingRateHz)));
+ expected_energies_for_listeners.back().push_back(kCollectedEnergyPerRay);
+ }
+ ValidateImpulseResponses(impulse_response_computer.GetFinalizedListeners(),
+ expected_indices_for_listeners,
+ expected_energies_for_listeners, {kEpsilonFloat});
+}
+
+TEST_F(ImpulseResponseComputerTest, OnePathMultipleListenersTest) {
+ // A series of listeners along the z-axis. Some of them overlapping.
+ std::unique_ptr<std::vector<AcousticListener>> listeners(
+ new std::vector<AcousticListener>);
+ AddListenersAtPositions({{0.0f, 0.0f, 1.0f},
+ {0.0f, 0.0f, 2.0f},
+ {0.0f, 0.0f, 3.0f},
+ {0.0f, 0.0f, 3.05f},
+ {0.0f, 0.0f, 3.10f}},
+ listeners.get());
+
+ scene_manager_.BuildScene({}, {});
+ ImpulseResponseComputer impulse_response_computer(
+ kListenerSphereRadiusMeter, kSamplingRateHz, std::move(listeners),
+ &scene_manager_);
+
+ // One path with only one ray. This ray should pass through all listener
+ // spheres.
+ const Vector3f origin(0.0f, 0.0f, 0.0f);
+ const Vector3f direction(0.0f, 0.0f, 1.0f);
+ Path path;
+ path.rays.emplace_back(origin.data(), direction.data(), 0.0f, 100.0f,
+ kUnitEnergies, AcousticRay::RayType::kSpecular, 0.0f);
+ paths_.push_back(path);
+
+ // Compute impulse response.
+ impulse_response_computer.CollectContributions(paths_);
+
+ // Validate the impulse responses.
+ // The theoretical indices are
+ // floor(distance / kSpeedOfSound (m/s) * kSamplingRateHz (1/s)).
+ // The theoretical energy values are all kCollectedEnergyPerRay.
+ std::vector<std::vector<size_t>> expected_indices_for_listeners;
+ std::vector<std::vector<float>> expected_energies_for_listeners;
+ std::vector<float> relative_error_tolerances_for_listeners;
+ for (const AcousticListener& listener :
+ impulse_response_computer.GetFinalizedListeners()) {
+ const float distance = (listener.position - origin).norm();
+ expected_indices_for_listeners.push_back({static_cast<size_t>(
+ std::floor(distance / kSpeedOfSound * kSamplingRateHz))});
+ expected_energies_for_listeners.push_back({kCollectedEnergyPerRay});
+ relative_error_tolerances_for_listeners.push_back(kEpsilonFloat);
+ }
+ ValidateImpulseResponses(impulse_response_computer.GetFinalizedListeners(),
+ expected_indices_for_listeners,
+ expected_energies_for_listeners,
+ relative_error_tolerances_for_listeners);
+}
+
+// Test that the energies collected at different positions is proportional to
+// 1/D^2, where D is the source-listener distance.
+TEST_F(ImpulseResponseComputerTest,
+ EnergyInverselyProportionalDistanceSquaredTest) {
+ // A series of listeners along the y-axis.
+ std::unique_ptr<std::vector<AcousticListener>> listeners(
+ new std::vector<AcousticListener>);
+ AddListenersAtPositions(
+ {
+ {0.0f, 1.0f, 0.0f},
+ {0.0f, 1.2f, 0.0f},
+ {0.0f, 1.4f, 0.0f},
+ {0.0f, 1.6f, 0.0f},
+ {0.0f, 1.8f, 0.0f},
+ {0.0f, 2.0f, 0.0f},
+ {0.0f, 2.5f, 0.0f},
+ {0.0f, 3.0f, 0.0f},
+ },
+ listeners.get());
+
+ scene_manager_.BuildScene({}, {});
+ ImpulseResponseComputer impulse_response_computer(
+ kListenerSphereRadiusMeter, kSamplingRateHz, std::move(listeners),
+ &scene_manager_);
+
+ // Add 10,000 paths from rays with uniformly distributed directions.
+ const size_t min_num_paths = 10000;
+ const Vector3f source_position(0.0f, 0.0f, 0.0f);
+ paths_ = GenerateUniformlyDistributedRayPaths(source_position.data(),
+ min_num_paths);
+
+ // Compute impulse response.
+ impulse_response_computer.CollectContributions(paths_);
+
+ // Check the index and value of the single non-zero element for each listener.
+ std::vector<std::vector<size_t>> expected_indices_for_listeners;
+ std::vector<std::vector<float>> expected_energies_for_listeners;
+ std::vector<float> relative_error_tolerances_for_listeners;
+ for (const AcousticListener& listener :
+ impulse_response_computer.GetFinalizedListeners()) {
+ // The theoretical index is
+ // floor(distance / kSpeedOfSound (m/s) * kSamplingRateHz (1/s)).
+ const float distance = (listener.position - source_position).norm();
+ expected_indices_for_listeners.push_back({static_cast<size_t>(
+ std::floor(distance / kSpeedOfSound * kSamplingRateHz))});
+
+ // The theoretical energy value is 1.0 / distance^2.
+ expected_energies_for_listeners.push_back({1.0f / (distance * distance)});
+
+ // The expected relative error of a Monte Carlo integration is O(1/sqrt(M)),
+ // where M is the expected number of samples. A listener sphere of radius R
+ // at a distance D away from the source is expected to intersect
+ // M = N * (PI * R^2) / (4 * PI * D^2) = 0.25 * N * R^2 /D^2 rays.
+ // We use 2 / sqrt(M) as the tolerance for relative errors.
+ const float expected_num_intersecting_rays =
+ 0.25f * static_cast<float>(paths_.size()) * kListenerSphereRadiusMeter *
+ kListenerSphereRadiusMeter / (distance * distance);
+ relative_error_tolerances_for_listeners.push_back(
+ 2.0f / std::sqrt(expected_num_intersecting_rays));
+ }
+ ValidateImpulseResponses(impulse_response_computer.GetFinalizedListeners(),
+ expected_indices_for_listeners,
+ expected_energies_for_listeners,
+ relative_error_tolerances_for_listeners);
+}
+
+// Tests that collecting after GetFinalizedListeners() is called has no effect.
+TEST_F(ImpulseResponseComputerTest, CollectingAfterFinalizeHasNoEffect) {
+ // A listener at (1, 0, 0).
+ std::unique_ptr<std::vector<AcousticListener>> listeners(
+ new std::vector<AcousticListener>);
+ const Vector3f listener_position(1.0f, 0.0f, 0.0f);
+ AddListenersAtPositions({listener_position}, listeners.get());
+
+ scene_manager_.BuildScene({}, {});
+ ImpulseResponseComputer impulse_response_computer(
+ kListenerSphereRadiusMeter, kSamplingRateHz, std::move(listeners),
+ &scene_manager_);
+
+ // One path with only one ray. This ray should pass through the listener
+ // sphere.
+ const Vector3f origin(0.0f, 0.0f, 0.0f);
+ const Vector3f direction(1.0f, 0.0f, 0.0f);
+ Path path;
+ path.rays.emplace_back(origin.data(), direction.data(), 0.0f, 100.0f,
+ kUnitEnergies, AcousticRay::RayType::kSpecular, 0.0f);
+ paths_.push_back(path);
+ impulse_response_computer.CollectContributions(paths_);
+
+ // Finalize the listeners and make a copy of the energy impulse responses.
+ const std::array<std::vector<float>, kNumReverbOctaveBands>
+ old_energy_impulse_responses =
+ impulse_response_computer.GetFinalizedListeners()
+ .at(0)
+ .energy_impulse_responses;
+
+ // Try to collect another set of paths. This would change the energies if
+ // they were collected, but they are not because the collection is finalized.
+ paths_.clear();
+ const Vector3f another_origin(1.0f, -1.0f, 0.0f);
+ const Vector3f another_direction(0.0f, 1.0f, 0.0f);
+ Path another_path;
+ another_path.rays.emplace_back(
+ another_origin.data(), another_direction.data(), 0.0f, 100.0f,
+ kUnitEnergies, AcousticRay::RayType::kSpecular, 0.0f);
+ paths_.push_back(another_path);
+ impulse_response_computer.CollectContributions(paths_);
+
+ // Verify that the energy impulse responses are the same as the copy.
+ const std::array<std::vector<float>, kNumReverbOctaveBands>&
+ new_energy_impulse_responses =
+ impulse_response_computer.GetFinalizedListeners()
+ .at(0)
+ .energy_impulse_responses;
+ for (size_t band = 0; band < kNumReverbOctaveBands; ++band) {
+ const std::vector<float>& old_responses_in_band =
+ old_energy_impulse_responses[band];
+ const std::vector<float>& new_responses_in_band =
+ new_energy_impulse_responses[band];
+ for (size_t index = 0; index < old_responses_in_band.size(); ++index) {
+ EXPECT_FLOAT_EQ(old_responses_in_band[index],
+ new_responses_in_band[index]);
+ }
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/mesh.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/mesh.h
new file mode 100644
index 000000000..5582bcdfc
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/mesh.h
@@ -0,0 +1,40 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Collection of data structures useful to define a mesh.
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_MESH_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_MESH_H_
+
+namespace vraudio {
+
+// A simple vertex data structure.
+struct Vertex {
+ float x;
+ float y;
+ float z;
+};
+
+// A simple triangle data structure defined as the 3 indices of vertices.
+struct Triangle {
+ int v0;
+ int v1;
+ int v2;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_MESH_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for.cc
new file mode 100644
index 000000000..bc5eef2db
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for.cc
@@ -0,0 +1,44 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/parallel_for.h"
+
+#include <condition_variable>
+#include <memory>
+#include <mutex>
+#include <vector>
+
+#include "base/logging.h"
+#include "utils/task_thread_pool.h"
+
+namespace vraudio {
+
+void ParallelFor(unsigned int num_threads, size_t num_iterations,
+ const std::function<void(const size_t)>& function) {
+ TaskThreadPool worker_thread_pool;
+ CHECK(worker_thread_pool.StartThreadPool(num_threads));
+
+ for (size_t i = 0; i < num_iterations; ++i) {
+ while (!worker_thread_pool.WaitUntilWorkerBecomesAvailable()) {
+ }
+
+ const TaskThreadPool::TaskClosure task = [i, &function]() { function(i); };
+ CHECK(worker_thread_pool.RunOnWorkerThread(task));
+ }
+ worker_thread_pool.StopThreadPool();
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for.h
new file mode 100644
index 000000000..d2f6951c1
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for.h
@@ -0,0 +1,53 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PARALLEL_FOR_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PARALLEL_FOR_H_
+
+#include <algorithm>
+#include <functional>
+#include <thread>
+
+namespace vraudio {
+
+// Gets the number of hardware threads; always returns more than zero.
+//
+// @return Number of hardware threads.
+inline unsigned int GetNumberOfHardwareThreads() {
+ // According to the standard, hardware_concurrency() may return zero if "this
+ // value is not computable or well defined". In that case, we want to have a
+ // thread count of one (instead of zero).
+ return std::max(1U, std::thread::hardware_concurrency());
+}
+
+// Repeatedly executes |function| multiple times, specified by |num_iterations|.
+// Different executions of |function| may occur on one of the |num_threads|
+// threads.
+//
+// |function| has a function signature of void(const size_t i), with |i| taking
+// values in the range [0, |num_iterations|).
+//
+// @param num_threads Number of threads to execute |function|.
+// @param num_iterations Number of iterations for this for loop.
+// @param function Function to be run. The function should take a single
+// parameter that is of type const size_t, representing the iteration
+// index, and no return value.
+void ParallelFor(unsigned int num_threads, size_t num_iterations,
+ const std::function<void(const size_t)>& function);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PARALLEL_FOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for_test.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for_test.cc
new file mode 100644
index 000000000..2e1ec563a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/parallel_for_test.cc
@@ -0,0 +1,65 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/parallel_for.h"
+
+#include <array>
+#include <atomic>
+#include <condition_variable>
+#include <mutex>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+
+namespace vraudio {
+
+namespace {
+
+// Tests multi-threaded increment of a single variable, using increasing numbers
+// of threads.
+TEST(ParallelForTest, IncreasingThreadCounts) {
+ const size_t kNumIterations = 1000;
+ for (unsigned int num_threads = 1; num_threads < 16; ++num_threads) {
+ std::mutex mutex;
+ std::condition_variable condition_variable;
+ size_t index = 0;
+ ParallelFor(num_threads, kNumIterations, [&](const size_t i) {
+ std::unique_lock<std::mutex> lock(mutex);
+ while (i != index) {
+ condition_variable.wait(lock);
+ }
+ ++index;
+ condition_variable.notify_all();
+ });
+ EXPECT_EQ(kNumIterations, index);
+ }
+}
+
+// Tests recursive use of ParallelFor().
+TEST(ParallelForTest, RecursiveParallelFor) {
+ std::atomic<int> counter(0);
+ ParallelFor(16U, 16, [&](const size_t i) {
+ ParallelFor(16U, 16, [&](const size_t j) {
+ for (int k = 0; k < 16; ++k) {
+ ++counter;
+ }
+ });
+ });
+ EXPECT_EQ(16 * 16 * 16, counter.load());
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path.h
new file mode 100644
index 000000000..f6e3d1681
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path.h
@@ -0,0 +1,36 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PATH_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PATH_H_
+
+#include <vector>
+
+#include "geometrical_acoustics/acoustic_ray.h"
+
+namespace vraudio {
+
+// A simple data structure of modeling a sound propagation path as a vector of
+// ray segments, which contain all necessary information. For example, the
+// history of triangles on this path can be found by |ray.primID|, where |ray|
+// is an element |rays|.
+struct Path {
+ std::vector<AcousticRay> rays;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PATH_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer.cc
new file mode 100644
index 000000000..6f4c6652a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer.cc
@@ -0,0 +1,96 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/path_tracer.h"
+
+#include <cmath>
+
+#include "base/logging.h"
+#include "geometrical_acoustics/parallel_for.h"
+#include "geometrical_acoustics/reflection_kernel.h"
+
+namespace vraudio {
+
+std::vector<Path> PathTracer::TracePaths(const AcousticSource& source,
+ size_t min_num_rays, size_t max_depth,
+ float energy_threshold) {
+ // The tracing would not work if the scene is not committed.
+ CHECK(scene_manager_.is_scene_committed());
+
+ // Find the actual number of rays to trace as the next square number greater
+ // or equal to |min_num_rays|.
+ const size_t sqrt_num_rays = static_cast<size_t>(
+ std::ceil(std::sqrt(static_cast<float>(min_num_rays))));
+ const size_t num_rays = sqrt_num_rays * sqrt_num_rays;
+
+ // In the current implementation, one ray does not spawn more than one child
+ // ray, hence the number of paths is the same as the number of rays from the
+ // source.
+ std::vector<Path> paths(num_rays);
+ std::vector<AcousticRay> rays_from_source =
+ source.GenerateStratifiedRays(num_rays, sqrt_num_rays);
+ const unsigned int num_threads = GetNumberOfHardwareThreads();
+ ParallelFor(
+ num_threads, num_rays,
+ [&rays_from_source, &paths, this, max_depth,
+ energy_threshold](size_t ray_index) {
+ if (max_depth == 0) return;
+ Path& path = paths.at(ray_index);
+
+ // Pre-allocate memory space for better performance.
+ path.rays.reserve(max_depth);
+
+ path.rays.push_back(rays_from_source[ray_index]);
+ size_t depth = 0;
+ while (true) {
+ AcousticRay& current_ray = path.rays.back();
+
+ // Stop generating new rays if the current ray escapes.
+ if (!current_ray.Intersect(scene_manager_.scene())) {
+ break;
+ }
+
+ // Stop generating new rays if |depth| reaches |max_depth|.
+ ++depth;
+ if (depth >= max_depth) {
+ break;
+ }
+
+ // Handle interactions with scene geometries.
+ const ReflectionKernel& reflection =
+ scene_manager_.GetAssociatedReflectionKernel(
+ current_ray.intersected_primitive_id());
+ AcousticRay new_ray = reflection.Reflect(current_ray);
+
+ // Stop tracing if all energies in all frequency bands of the new ray
+ // are too low in energy.
+ bool is_energy_high_enough = false;
+ for (const float energy : new_ray.energies()) {
+ if (energy >= energy_threshold) {
+ is_energy_high_enough = true;
+ break;
+ }
+ }
+ if (!is_energy_high_enough) {
+ break;
+ }
+ path.rays.push_back(new_ray);
+ }
+ });
+ return paths;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer.h
new file mode 100644
index 000000000..4a8a35a7e
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer.h
@@ -0,0 +1,59 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PATH_TRACER_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PATH_TRACER_H_
+
+#include <functional>
+#include <vector>
+
+#include "geometrical_acoustics/acoustic_source.h"
+#include "geometrical_acoustics/path.h"
+#include "geometrical_acoustics/scene_manager.h"
+
+namespace vraudio {
+
+// A wrapper around Embree that finds sound propagation paths from a source.
+class PathTracer {
+ public:
+ // Constructor.
+ //
+ // @param scene_manager Scene manager.
+ explicit PathTracer(const SceneManager& scene_manager)
+ : scene_manager_(scene_manager) {}
+ ~PathTracer() {}
+
+ // Traces sound propagation paths from a source.
+ //
+ // @param source Source from which paths are traced.
+ // @param min_num_rays Minimum number of rays to be traced.
+ // @param max_depth Maximum depth of tracing performed along a path. The
+ // tracing stops when reading |max_depth| interactions with the scene
+ // geometries.
+ // @param energy_threshold Energy threshold below which the tracing stops.
+ // @return Vector of at least |min_num_rays| traced paths.
+ std::vector<Path> TracePaths(const AcousticSource& source,
+ size_t min_num_rays, size_t max_depth,
+ float energy_threshold);
+
+ private:
+ // Scene manager.
+ const SceneManager& scene_manager_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PATH_TRACER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer_test.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer_test.cc
new file mode 100644
index 000000000..a1cb67395
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/path_tracer_test.cc
@@ -0,0 +1,193 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/path_tracer.h"
+
+#include <memory>
+#include <random>
+#include <unordered_set>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "geometrical_acoustics/mesh.h"
+#include "geometrical_acoustics/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+using Eigen::Vector3f;
+
+class PathTracerTest : public testing::Test {
+ public:
+ PathTracerTest() : random_engine_(), distribution_(0.0f, 1.0f) {
+ random_number_generator_ = [this] { return distribution_(random_engine_); };
+ }
+
+ void BuildEmptyScene() {
+ scene_manager_.reset(new SceneManager);
+ scene_manager_->BuildScene(std::vector<Vertex>(), std::vector<Triangle>());
+ all_triangle_indices_.clear();
+ }
+
+ void BuildGroundScene() {
+ scene_manager_.reset(new SceneManager);
+ std::vector<Vertex> ground_vertices{{0.0f, 0.0f, 0.0f},
+ {0.0f, 1.0f, 0.0f},
+ {1.0f, 0.0f, 0.0f},
+ {1.0f, 1.0f, 0.0f}};
+ std::vector<Triangle> ground_triangles{{0, 3, 1}, {0, 2, 3}};
+ scene_manager_->BuildScene(ground_vertices, ground_triangles);
+ all_triangle_indices_ = {0, 1};
+ }
+
+ void BuildBoxScene() {
+ scene_manager_.reset(new SceneManager);
+ std::vector<Vertex> box_vertices;
+ std::vector<Triangle> box_triangles;
+ BuildTestBoxScene({0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f}, &box_vertices,
+ &box_triangles, nullptr);
+ scene_manager_->BuildScene(box_vertices, box_triangles);
+ all_triangle_indices_.clear();
+ for (unsigned int i = 0; i < 12; ++i) {
+ all_triangle_indices_.insert(i);
+ }
+ }
+
+ protected:
+ const std::array<float, kNumReverbOctaveBands> kZeroAbsorptionCoefficients = {
+ {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}};
+ std::unique_ptr<SceneManager> scene_manager_;
+ std::unordered_set<unsigned int> all_triangle_indices_;
+ std::default_random_engine random_engine_;
+ std::uniform_real_distribution<float> distribution_;
+ std::function<float()> random_number_generator_;
+};
+
+TEST_F(PathTracerTest, AllPathsHaveLengthOneInEmptySceneTest) {
+ BuildEmptyScene();
+ PathTracer path_tracer(*scene_manager_);
+
+ AcousticSource source({0.0f, 0.0f, 0.0f}, kUnitEnergies,
+ random_number_generator_);
+ const size_t min_num_rays = 100;
+ const size_t max_depth = 10;
+ const float energy_thresold = 1e-6f;
+ std::vector<Path> paths =
+ path_tracer.TracePaths(source, min_num_rays, max_depth, energy_thresold);
+
+ EXPECT_LE(paths.size(), min_num_rays);
+ for (size_t i = 0; i < paths.size(); ++i) {
+ EXPECT_EQ(static_cast<int>(paths[i].rays.size()), 1);
+ }
+}
+
+TEST_F(PathTracerTest, GroundSceneTest) {
+ BuildGroundScene();
+
+ // Associate a perfect reflection to all triangles.
+ ReflectionKernel reflection_kernel(kZeroAbsorptionCoefficients, 0.0f,
+ random_number_generator_);
+ scene_manager_->AssociateReflectionKernelToTriangles(reflection_kernel,
+ all_triangle_indices_);
+
+ PathTracer path_tracer(*scene_manager_);
+
+ AcousticSource source({0.5f, 0.5f, 0.1f}, kUnitEnergies,
+ random_number_generator_);
+ const size_t min_num_rays = 100;
+ const size_t max_depth = 10;
+ const float energy_thresold = 1e-6f;
+ std::vector<Path> paths =
+ path_tracer.TracePaths(source, min_num_rays, max_depth, energy_thresold);
+
+ // All paths have at least one ray (for those that did not hit the ground)
+ // and at most two rays (for those hitting the ground).
+ for (size_t i = 0; i < paths.size(); ++i) {
+ EXPECT_GE(static_cast<int>(paths[i].rays.size()), 1);
+ EXPECT_LE(static_cast<int>(paths[i].rays.size()), 2);
+
+ // For those with length = 2, validate that the first ray ends on the
+ // ground plane.
+ if (paths[i].rays.size() == 2) {
+ const AcousticRay& first_ray = paths[i].rays.front();
+ const Vector3f& end_point =
+ Vector3f(first_ray.origin()) +
+ first_ray.t_far() * Vector3f(first_ray.direction());
+ EXPECT_NEAR(end_point.z(), 0.0f, 1e-7f);
+ }
+ }
+}
+
+TEST_F(PathTracerTest, TerminateAtMaxDepthTest) {
+ // A box scene within which rays never escape.
+ BuildBoxScene();
+
+ // Associate a perfect reflection to all triangles. Theoretically there should
+ // be infinite reflections, but the path tracer stops once each path reaches
+ // length |max_depth|.
+ ReflectionKernel reflection_kernel(kZeroAbsorptionCoefficients, 0.0f,
+ random_number_generator_);
+ scene_manager_->AssociateReflectionKernelToTriangles(reflection_kernel,
+ all_triangle_indices_);
+ PathTracer path_tracer(*scene_manager_);
+
+ AcousticSource source({0.5f, 0.5f, 0.5f}, kUnitEnergies,
+ random_number_generator_);
+ const size_t min_num_rays = 100;
+ const size_t max_depth = 10;
+ const float energy_thresold = 1e-6f;
+ std::vector<Path> paths =
+ path_tracer.TracePaths(source, min_num_rays, max_depth, energy_thresold);
+
+ for (size_t i = 0; i < paths.size(); ++i) {
+ EXPECT_EQ(paths[i].rays.size(), max_depth);
+ }
+}
+
+TEST_F(PathTracerTest, TerminateWhenEnergyBelowThresholdTest) {
+ // A box scene within which rays never escape.
+ BuildBoxScene();
+
+ // Associate an absorptive reflection with an absorption coefficient slightly
+ // over 90% to all triangles.
+ std::array<float, kNumReverbOctaveBands> absorption_coefficients;
+ absorption_coefficients.fill(0.9001f);
+ ReflectionKernel reflection_kernel(absorption_coefficients, 0.0f,
+ random_number_generator_);
+ scene_manager_->AssociateReflectionKernelToTriangles(reflection_kernel,
+ all_triangle_indices_);
+ PathTracer path_tracer(*scene_manager_);
+
+ // Since the reflected energy is slightly below 1e-1 after each reflection,
+ // we expect the path tracer to stop after X reflections for an
+ // energy threshold of 1e-X, and that each path is of length X.
+ AcousticSource source({0.5f, 0.5f, 0.5f}, kUnitEnergies,
+ random_number_generator_);
+ const size_t min_num_rays = 100;
+ const size_t max_depth = 10;
+ const float energy_thresold = 1e-6f;
+ std::vector<Path> paths =
+ path_tracer.TracePaths(source, min_num_rays, max_depth, energy_thresold);
+
+ for (size_t i = 0; i < paths.size(); ++i) {
+ EXPECT_EQ(static_cast<int>(paths[i].rays.size()), 6);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator.cc
new file mode 100644
index 000000000..d0df0369a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator.cc
@@ -0,0 +1,438 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/proxy_room_estimator.h"
+
+#include <algorithm>
+#include <cmath>
+
+#include "Eigen/Core"
+#include "base/logging.h"
+#include "platforms/common/room_effects_utils.h"
+
+namespace vraudio {
+
+namespace {
+
+// Normals of the walls of an axis-aligned cube. Walls are indexed like this:
+// 0: Left (-x)
+// 1: Right (+x)
+// 2: Bottom (-y)
+// 3: Top (+y)
+// 4: Back (-z)
+// 5: Front (+z)
+static const float kCubeWallNormals[kNumRoomSurfaces][3] = {
+ {-1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f},
+ {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f, 1.0f}};
+
+// A helper function to determine if a ray (shooting from |ray_origin| in the
+// |ray_direction| direction) intersects with a plane (whose normal is
+// |plane_normal| and whose distance to the origin is
+// |plane_distance_to_origin|). When returning true, the intersection point is
+// stored in |intersection|.
+bool PlaneIntersection(const WorldPosition& plane_normal,
+ float plane_distance_to_origin,
+ const WorldPosition& ray_origin,
+ const WorldPosition& ray_direction,
+ WorldPosition* intersection) {
+ // Do not count if the direction is too close to parallel to the plane (i.e.,
+ // the dot product of |direction| and |plane_normal|, |d_dot_n| is too close
+ // to zero).
+ const float d_dot_n = ray_direction.dot(plane_normal);
+ if (std::abs(d_dot_n) < vraudio::kEpsilonFloat) {
+ return false;
+ }
+
+ // Find the intersection point.
+ const float t =
+ (plane_distance_to_origin - ray_origin.dot(plane_normal)) / d_dot_n;
+
+ // Do not count back-intersection, i.e., the intersection is in the negative
+ // |ray_direction|.
+ if (t < 0.0f) {
+ return false;
+ }
+
+ *intersection = ray_origin + t * ray_direction;
+ return true;
+}
+
+// A helper function to find the index of the wall with which the ray
+// intersects. Returns true if such wall is found.
+bool FindIntersectingWallIndex(const WorldPosition& dimensions,
+ const WorldPosition& origin,
+ const WorldPosition& direction,
+ size_t* wall_index) {
+ // The ray intersects a wall if:
+ // 1. It intersects the plane of the wall.
+ // 2. The intersection point lies in the bounding box of the wall.
+ const float dx = dimensions[0] * 0.5f;
+ const float dy = dimensions[1] * 0.5f;
+ const float dz = dimensions[2] * 0.5f;
+
+ // Data used to test plane intersections (1. above): normals and distances
+ // of all the walls.
+ const float wall_distances[kNumRoomSurfaces] = {dx, dx, dy, dy, dz, dz};
+
+ // Data used to test whether the intersecting point is in the bounding box
+ // of the wall (2. above). The bounding box has a small thickness
+ // |wall_thickness| along the normal direction of the wall.
+ const float wall_thickness = AcousticRay::kRayEpsilon;
+
+ // The centers and corresponding dimensions defining the bounding boxes of
+ // all the walls.
+ const WorldPosition wall_centers[kNumRoomSurfaces] = {
+ {-dx, 0.0f, 0.0f}, {+dx, 0.0f, 0.0f}, {0.0f, -dy, 0.0f},
+ {0.0f, +dy, 0.0f}, {0.0f, 0.0f, -dz}, {0.0f, 0.0f, +dz},
+ };
+ const WorldPosition wall_dimensions[kNumRoomSurfaces] = {
+ {wall_thickness, dimensions[1], dimensions[2]},
+ {wall_thickness, dimensions[1], dimensions[2]},
+ {dimensions[0], wall_thickness, dimensions[2]},
+ {dimensions[0], wall_thickness, dimensions[2]},
+ {dimensions[0], dimensions[1], wall_thickness},
+ {dimensions[0], dimensions[1], wall_thickness},
+ };
+
+ // Iterate through all the walls to find the one that the ray intersects with.
+ for (size_t wall = 0; wall < kNumRoomSurfaces; ++wall) {
+ WorldPosition intersection;
+ if (PlaneIntersection(WorldPosition(kCubeWallNormals[wall]),
+ wall_distances[wall], origin, direction,
+ &intersection) &&
+ IsPositionInAabb(intersection, wall_centers[wall],
+ wall_dimensions[wall])) {
+ *wall_index = wall;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// A helper function to sort a vector of {position, distance} pairs according
+// to the distances and exclude outliers.
+std::vector<std::pair<WorldPosition, float>>
+SortPositionsAndDistancesAndFindInliers(
+ float outlier_portion, const std::vector<std::pair<WorldPosition, float>>&
+ positions_and_distances) {
+ std::vector<std::pair<WorldPosition, float>>
+ sorted_inlier_positions_and_distances(positions_and_distances);
+
+ std::sort(sorted_inlier_positions_and_distances.begin(),
+ sorted_inlier_positions_and_distances.end(),
+ [](const std::pair<WorldPosition, float>& position_and_distance_1,
+ const std::pair<WorldPosition, float>& position_and_distance_2) {
+ return position_and_distance_1.second <
+ position_and_distance_2.second;
+ });
+
+ const float total_size =
+ static_cast<float>(sorted_inlier_positions_and_distances.size());
+ const size_t inliner_begin =
+ static_cast<size_t>(std::floor(total_size * outlier_portion));
+ const size_t inliner_end =
+ static_cast<size_t>(std::ceil(total_size * (1.0f - outlier_portion)));
+
+ std::copy(sorted_inlier_positions_and_distances.begin() + inliner_begin,
+ sorted_inlier_positions_and_distances.begin() + inliner_end,
+ sorted_inlier_positions_and_distances.begin());
+ sorted_inlier_positions_and_distances.resize(inliner_end - inliner_begin);
+
+ return sorted_inlier_positions_and_distances;
+}
+
+// A helper function to compute the average position and distance from a
+// vector of positions and distances.
+void ComputeAveragePositionAndDistance(
+ const std::vector<std::pair<WorldPosition, float>>& positions_and_distances,
+ WorldPosition* average_position, float* average_distance) {
+ DCHECK(!positions_and_distances.empty());
+ WorldPosition sum_positions(0.0f, 0.0f, 0.0f);
+ float sum_distances = 0.0f;
+ for (const std::pair<WorldPosition, float>& position_and_distance :
+ positions_and_distances) {
+ sum_positions += position_and_distance.first;
+ sum_distances += position_and_distance.second;
+ }
+
+ const float inverse_size =
+ 1.0f / static_cast<float>(positions_and_distances.size());
+ *average_position = sum_positions * inverse_size;
+ *average_distance = sum_distances * inverse_size;
+}
+
+} // namespace
+
+void ProxyRoomEstimator::CollectHitPointData(
+ const std::vector<Path>& paths_batch) {
+ // The size of already collected hit points before this batch.
+ const size_t previous_size = hit_points_.size();
+ hit_points_.resize(previous_size + paths_batch.size());
+
+ // Collect one hit point per path.
+ for (size_t path_index = 0; path_index < paths_batch.size(); ++path_index) {
+ const size_t hit_point_index = path_index + previous_size;
+ const Path& path = paths_batch.at(path_index);
+ hit_points_[hit_point_index] = CollectHitPointDataFromPath(path);
+ }
+}
+
+bool ProxyRoomEstimator::EstimateCubicProxyRoom(
+ float outlier_portion, RoomProperties* room_properties) {
+ // Check that |outlier_portion| is in the range of [0, 0.5].
+ CHECK_GE(outlier_portion, 0.0f);
+ CHECK_LE(outlier_portion, 0.5f);
+
+ // Estimation fails if there is no hit point.
+ if (hit_points_.empty()) {
+ return false;
+ }
+
+ // The geometry part (position, dimensions, and rotation) of the proxy room.
+ if (!EstimateCubeGeometry(outlier_portion, room_properties->position,
+ room_properties->dimensions,
+ room_properties->rotation)) {
+ LOG(WARNING) << "Unable to estimate a cube without a hit point with finite "
+ << "|t_far|; returning a default cube.";
+ return false;
+ }
+
+ // The surface material part of the proxy room.
+ EstimateSurfaceMaterials(WorldPosition(room_properties->position),
+ WorldPosition(room_properties->dimensions),
+ room_properties->material_names);
+ return true;
+}
+
+ProxyRoomEstimator::HitPointData
+ProxyRoomEstimator::CollectHitPointDataFromPath(const Path& path) {
+ CHECK(!path.rays.empty());
+ HitPointData hit_point;
+
+ // Common data.
+ const AcousticRay& first_order_ray = path.rays[0];
+ hit_point.origin = WorldPosition(first_order_ray.origin());
+ hit_point.direction = WorldPosition(first_order_ray.direction());
+
+ // Treating escaped and non-escaped rays differently for their |t_far| and
+ // |absorption_coefficients|.
+ if (path.rays.size() > 1) {
+ hit_point.t_far = first_order_ray.t_far();
+
+ // Figure out the absorption coefficients by examining the incoming and the
+ // reflected energy.
+ const AcousticRay& second_order_ray = path.rays[1];
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ const float incoming_energy = first_order_ray.energies().at(i);
+ const float reflected_energy = second_order_ray.energies().at(i);
+ CHECK_GT(incoming_energy, 0.0f);
+ CHECK_GE(incoming_energy, reflected_energy);
+
+ hit_point.absorption_coefficients[i] =
+ 1.0f - (reflected_energy / incoming_energy);
+ }
+ } else {
+ hit_point.t_far = AcousticRay::kInfinity;
+
+ // Escaped rays are considered as completely absorbed.
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ hit_point.absorption_coefficients[i] = 1.0f;
+ }
+ }
+
+ return hit_point;
+}
+
+bool ProxyRoomEstimator::EstimateCubeGeometry(float outlier_portion,
+ float* position,
+ float* dimensions,
+ float* rotation) {
+ // First group the hit points according to which cube wall it would hit,
+ // assuming an initial guess of a cube that
+ // 1. centers at the origin of the first ray,
+ // 2. has unit dimensions, and
+ // 3. has no rotation.
+ const WorldPosition cube_dimensions(1.0f, 1.0f, 1.0f);
+ const std::array<std::vector<HitPointData>, kNumRoomSurfaces>
+ hit_points_on_walls =
+ GroupHitPointsByWalls(hit_points_[0].origin, cube_dimensions);
+
+ // Compute the positions and distances of from the hit points on walls.
+ const std::vector<std::pair<WorldPosition, float>> positions_and_distances =
+ ComputeDistancesAndPositionsFromHitPoints(hit_points_on_walls);
+
+ // Cannot estimate if there are no valid positions and distances.
+ if (positions_and_distances.empty()) {
+ return false;
+ }
+
+ // Sort the |positions_and_distances| according to the distances and also
+ // filter out outliers (whose distances are too large or too small).
+ const std::vector<std::pair<WorldPosition, float>>
+ sorted_inlier_positions_and_distances =
+ SortPositionsAndDistancesAndFindInliers(outlier_portion,
+ positions_and_distances);
+
+ // Cannot estimate if there are no inlying positions and distances.
+ if (sorted_inlier_positions_and_distances.empty()) {
+ return false;
+ }
+
+ // Take the average distance and origin of the inlier hit points.
+ WorldPosition average_hit_point_poisition;
+ float average_distance;
+ ComputeAveragePositionAndDistance(sorted_inlier_positions_and_distances,
+ &average_hit_point_poisition,
+ &average_distance);
+
+ // Use twice the average distance as the cube's dimensions.
+ const float estimated_cube_dimension = 2.0f * average_distance;
+ dimensions[0] = estimated_cube_dimension;
+ dimensions[1] = estimated_cube_dimension;
+ dimensions[2] = estimated_cube_dimension;
+
+ // Use the average hit point position as the cube's position.
+ position[0] = average_hit_point_poisition[0];
+ position[1] = average_hit_point_poisition[1];
+ position[2] = average_hit_point_poisition[2];
+
+ // No rotation.
+ rotation[0] = 0.0f;
+ rotation[1] = 0.0f;
+ rotation[2] = 0.0f;
+ rotation[3] = 1.0f;
+
+ return true;
+}
+
+std::array<std::vector<ProxyRoomEstimator::HitPointData>, kNumRoomSurfaces>
+ProxyRoomEstimator::GroupHitPointsByWalls(
+ const WorldPosition& room_position, const WorldPosition& room_dimensions) {
+ const WorldPosition kOrigin(0.0f, 0.0f, 0.0f);
+
+ // No rotation for an axis-aligned room.
+ const WorldRotation kNoRotation(1.0f, 0.0f, 0.0f, 0.0f);
+
+ // Reserve memory space for hit points on walls.
+ std::array<std::vector<HitPointData>, kNumRoomSurfaces> hit_points_on_walls;
+ for (std::vector<HitPointData>& hit_points_on_wall : hit_points_on_walls) {
+ hit_points_on_wall.reserve(hit_points_.size());
+ }
+
+ for (const HitPointData& hit_point : hit_points_) {
+ // First transform the ray's origin and direction to the local space
+ // of the cube centered at |position|.
+ WorldPosition local_direction;
+ GetRelativeDirection(kOrigin, kNoRotation, hit_point.direction,
+ &local_direction);
+ WorldPosition local_origin;
+ GetRelativeDirection(room_position, kNoRotation, hit_point.origin,
+ &local_origin);
+
+ // Find the wall that the ray intersects.
+ size_t wall_index;
+ if (FindIntersectingWallIndex(room_dimensions, local_origin,
+ local_direction, &wall_index)) {
+ hit_points_on_walls[wall_index].push_back(hit_point);
+ }
+ }
+
+ return hit_points_on_walls;
+}
+
+std::vector<std::pair<WorldPosition, float>>
+ProxyRoomEstimator::ComputeDistancesAndPositionsFromHitPoints(
+ const std::array<std::vector<HitPointData>, kNumRoomSurfaces>&
+ hit_points_on_walls) {
+ std::vector<std::pair<WorldPosition, float>> positions_and_distances;
+ for (size_t wall = 0; wall < kNumRoomSurfaces; ++wall) {
+ const WorldPosition wall_normal(kCubeWallNormals[wall]);
+ for (const HitPointData& hit_point : hit_points_on_walls[wall]) {
+ if (hit_point.t_far == AcousticRay::kInfinity) {
+ continue;
+ }
+
+ std::pair<WorldPosition, float> position_and_distance;
+ position_and_distance.first =
+ hit_point.origin + (hit_point.t_far * hit_point.direction);
+ position_and_distance.second =
+ (position_and_distance.first - hit_point.origin).dot(wall_normal);
+ positions_and_distances.push_back(position_and_distance);
+ }
+ }
+
+ return positions_and_distances;
+}
+
+void ProxyRoomEstimator::EstimateSurfaceMaterials(
+ const WorldPosition& room_position, const WorldPosition& room_dimensions,
+ MaterialName* material_names) {
+ // Compute the average absorption coefficients on all the walls.
+ CoefficientsVector average_absorption_coefficients[kNumRoomSurfaces];
+
+ // Now that we have better estimates of the proxy room's position, dimensions,
+ // and rotation, re-group the hit points using these estimates.
+ const std::array<std::vector<HitPointData>, kNumRoomSurfaces>&
+ hit_points_on_walls =
+ GroupHitPointsByWalls(room_position, room_dimensions);
+ for (size_t wall = 0; wall < kNumRoomSurfaces; ++wall) {
+ const std::vector<HitPointData>& hit_points = hit_points_on_walls[wall];
+ for (const HitPointData& hit_point : hit_points) {
+ average_absorption_coefficients[wall] +=
+ CoefficientsVector(hit_point.absorption_coefficients.data());
+ }
+ }
+
+ for (size_t wall = 0; wall < kNumRoomSurfaces; ++wall) {
+ if (!hit_points_on_walls[wall].empty()) {
+ average_absorption_coefficients[wall] /=
+ static_cast<float>(hit_points_on_walls[wall].size());
+ } else {
+ // If no hit point is found on this wall, we consider all energy absorbed
+ // in this direction and the absorption coefficient being 1.0.
+ average_absorption_coefficients[wall].fill(1.0f);
+ }
+ }
+
+ // Find the closest surface material. The distance between two materials is
+ // defined as the simple Euclidean distance.
+ for (size_t wall = 0; wall < kNumRoomSurfaces; ++wall) {
+ MaterialName min_distance_material_name = MaterialName::kTransparent;
+ float min_material_distance = std::numeric_limits<float>::infinity();
+
+ // We want to exclude kUniform from fitting.
+ const size_t num_materials_to_fit =
+ static_cast<size_t>(MaterialName::kNumMaterialNames) - 1;
+ for (size_t material_index = 0; material_index < num_materials_to_fit;
+ ++material_index) {
+ const RoomMaterial& material = GetRoomMaterial(material_index);
+ const float material_distance =
+ (average_absorption_coefficients[wall] -
+ CoefficientsVector(material.absorption_coefficients))
+ .norm();
+ if (material_distance < min_material_distance) {
+ min_material_distance = material_distance;
+ min_distance_material_name = material.name;
+ }
+ }
+ material_names[wall] = min_distance_material_name;
+ LOG(INFO) << "Wall[" << wall << "] material= " << min_distance_material_name
+ << " distance= " << min_material_distance;
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator.h
new file mode 100644
index 000000000..63aa58998
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator.h
@@ -0,0 +1,156 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PROXY_ROOM_ESTIMATOR_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PROXY_ROOM_ESTIMATOR_H_
+
+#include <array>
+#include <utility>
+#include <vector>
+
+#include "Eigen/Core"
+#include "api/resonance_audio_api.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+#include "geometrical_acoustics/path.h"
+#include "platforms/common/room_properties.h"
+
+namespace vraudio {
+
+// A class that estimates a "proxy room" from traced sound propagation paths.
+// A proxy room is used to model dynamic early reflections as if they are
+// reflected from a box-shaped room, even though the real scene geometry is
+// arbitrarily complex. This is to complement the pre-computed late reverb
+// effects, and it takes the same input (i.e., the ray tracing results) as the
+// reverb pre-computation. The proxy room is estimated from the first order
+// ray paths (i.e., those from the source to the first hit points), and the
+// estimation has two stages:
+// 1. Fitting the geometry (currently only as an axis-aligned cube).
+// 2. Fitting the surface materials on the six walls.
+class ProxyRoomEstimator {
+ public:
+ ProxyRoomEstimator() = default;
+
+ // ProxyRoomEstimator is neither copyable nor movable.
+ ProxyRoomEstimator(const ProxyRoomEstimator&) = delete;
+ ProxyRoomEstimator& operator=(const ProxyRoomEstimator&) = delete;
+
+ // Collects hit point data from traced ray paths, batch-by-batch.
+ //
+ // @param paths_batch A batch of ray paths.
+ void CollectHitPointData(const std::vector<Path>& paths_batch);
+
+ // Estimates a cube-shaped proxy room from collected hit points. Hit points
+ // are sorted according to their traveled distance. In order to make the
+ // estimation more robust, we discard "outlier" hit points, i.e., those whose
+ // traveled distances are too large or too small.
+ //
+ // @param outlier_portion What portion of the hit points are considered as
+ // outliers. For example, a value of 0.1 means that the hit points whose
+ // distances are in the top 10% and bottom 10% are considered as outliers
+ // and discarded. The value must be in the range of [0, 0.5].
+ // @param room_properties Room properties of the estimated axis-aligned cube-
+ // shaped room, each wall having an estimated surface material.
+ // @return True if the estimation is successful.
+ bool EstimateCubicProxyRoom(float outlier_portion,
+ RoomProperties* room_properties);
+
+ private:
+ class CoefficientsVector : public Eigen::Matrix<float, kNumReverbOctaveBands,
+ 1, Eigen::DontAlign> {
+ public:
+ // Inherits all constructors with 1-or-more arguments. Necessary because
+ // MSVC12 doesn't support inheriting constructors.
+ template <typename Arg1, typename... Args>
+ CoefficientsVector(const Arg1& arg1, Args&&... args)
+ : Matrix(arg1, std::forward<Args>(args)...) {}
+
+ // Constructs a zero vector.
+ CoefficientsVector() { setZero(); }
+ };
+
+ // A struct to contain data necessary for estimating a proxy room.
+ struct HitPointData {
+ // Origin of the ray that creates this hit point.
+ WorldPosition origin;
+
+ // Direction of the ray that creates this hit point.
+ WorldPosition direction;
+
+ // Ray parameter t corresponding to the hit point. If the ray escaped the
+ // scene and did not hit anything, then |t_far| takes the value of
+ // |AcousticRay::kInfinity|. Escaped rays are still useful in estimating
+ // surface materials, because they can be considered completely absorbed
+ // and should increase the effective absorption coefficients.
+ float t_far;
+
+ // Absorption coefficients of the surface of the hit point across the
+ // frequency bands.
+ std::array<float, kNumReverbOctaveBands> absorption_coefficients;
+ };
+
+ // Collects one hit point from one traced ray path.
+ //
+ // @param path Traced ray path.
+ // @return Collected hit point.
+ HitPointData CollectHitPointDataFromPath(const Path& path);
+
+ // Estimates the geometry of the cube.
+ //
+ // @param outlier_portion Portion of all hit points to be discarded. See
+ // EstimateCube() above.
+ // @param position Output center position of the estimated cube.
+ // @param dimensions Output dimensions of the estimated cube.
+ // @return True if the estimation is successful.
+ bool EstimateCubeGeometry(float outlier_portion, float* position,
+ float* dimensions, float* rotation);
+
+ // Groups hit points by which walls they lie on in an assumed axis-aligned
+ // room.
+ //
+ // @param room_position Center position of the assumed axis-aligned room.
+ // @param room_dimensions Dimensions of the assumed axis-aligned room.
+ // @return An array of six elements, each being a vector of hit points
+ // on one of the six walls.
+ std::array<std::vector<HitPointData>, kNumRoomSurfaces> GroupHitPointsByWalls(
+ const WorldPosition& room_position, const WorldPosition& room_dimensions);
+
+ // Compute the hit point positions and distances (measured along the normal
+ // direction of the walls that they hit) from hit points on walls.
+ //
+ // @param hit_points_on_walls Hit points on walls.
+ // @return A vector of {hit point position, distance} pairs.
+ std::vector<std::pair<WorldPosition, float>>
+ ComputeDistancesAndPositionsFromHitPoints(
+ const std::array<std::vector<HitPointData>, kNumRoomSurfaces>&
+ hit_points_on_walls);
+
+ // Estimates the surface materials on the six walls of the proxy room.
+ //
+ // @param room_position Center position of the estimated proxy room.
+ // @param room_dimensions Dimensions of the estimated proxy room.
+ // @param material_names Names of the estimated surface materials.
+ void EstimateSurfaceMaterials(const WorldPosition& room_position,
+ const WorldPosition& room_dimensions,
+ MaterialName* material_names);
+
+ // Collected hit points.
+ std::vector<HitPointData> hit_points_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PROXY_ROOM_ESTIMATOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator_test.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator_test.cc
new file mode 100644
index 000000000..68f0dc030
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/proxy_room_estimator_test.cc
@@ -0,0 +1,317 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/proxy_room_estimator.h"
+
+#include <random>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "geometrical_acoustics/acoustic_source.h"
+#include "geometrical_acoustics/test_util.h"
+#include "platforms/common/room_effects_utils.h"
+#include "platforms/common/room_properties.h"
+
+namespace vraudio {
+
+namespace {
+
+using Eigen::Vector3f;
+
+class ProxyRoomEstimatorTest : public testing::Test {
+ public:
+ ProxyRoomEstimatorTest() {
+ BuildTestBoxScene({0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f}, &cube_vertices_,
+ &cube_triangles_, &cube_wall_triangles_);
+ }
+
+ protected:
+ void ReflectRaysInPaths(float t_far, std::vector<Path>* paths) {
+ for (Path& path : *paths) {
+ // Add a reflected ray to the end of each path, whose energy is half
+ // the first ray.
+ AcousticRay& ray = path.rays.back();
+ ray.set_t_far(t_far);
+ const float reflected_origin[3] = {
+ ray.origin()[0] + ray.t_far() * ray.direction()[0],
+ ray.origin()[1] + ray.t_far() * ray.direction()[1],
+ ray.origin()[2] + ray.t_far() * ray.direction()[2],
+ };
+ AcousticRay reflected_ray(reflected_origin, kZDirection, t_far,
+ AcousticRay::kInfinity, kHalfUnitEnergies,
+ AcousticRay::RayType::kSpecular, t_far);
+ path.rays.push_back(reflected_ray);
+ }
+ }
+
+ ProxyRoomEstimator estimator_;
+ SceneManager scene_manager_;
+
+ // Ray-tracing related fields.
+ const int kNumRays = 2000;
+ const int kMaxDepth = 3;
+ const float kEnergyThresold = 1e-6f;
+ const std::array<float, kNumReverbOctaveBands> kHalfUnitEnergies{
+ {0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f}};
+ const float kSourcePosition[3] = {1.0f, 2.0f, 3.0f};
+ const float kZDirection[3] = {0.0f, 0.0f, 1.0f};
+
+ // Data describing a cube scene.
+ std::vector<Vertex> cube_vertices_;
+ std::vector<Triangle> cube_triangles_;
+ const float cube_center_[3] = {0.5f, 0.5f, 0.5f};
+ std::vector<MaterialName> wall_materials_;
+
+ // Triangles for six walls of a cube. Useful for assigning surface materials.
+ std::vector<std::unordered_set<unsigned int>> cube_wall_triangles_;
+};
+
+// Tests that estimating from an empty paths batch fails.
+TEST_F(ProxyRoomEstimatorTest, EstimateFromEmptyPathsFails) {
+ // An empty paths batch.
+ std::vector<Path> empty_paths_batch;
+ estimator_.CollectHitPointData(empty_paths_batch);
+
+ // Expect that the estimation function returns false.
+ const float outlier_portion = 0.0f;
+ RoomProperties room_properties;
+ EXPECT_FALSE(
+ estimator_.EstimateCubicProxyRoom(outlier_portion, &room_properties));
+}
+
+// Tests that if all paths in a batch escape the scene before hitting anything,
+// the estimation fails.
+TEST_F(ProxyRoomEstimatorTest, EstimateFromEscapedPathsFails) {
+ // A paths batch in which all rays escape, i.e., have infinite |t_far|.
+ std::vector<Path> escaped_paths_batch;
+ for (size_t i = 0; i < 10; ++i) {
+ Path path;
+ path.rays.emplace_back(kSourcePosition, // origin
+ kZDirection, // direction
+ 0.0f, // t_near
+ AcousticRay::kInfinity, // t_far
+ kUnitEnergies, // energies
+ AcousticRay::RayType::kSpecular, // ray_type
+ 0.0f // prior_distance
+ );
+ escaped_paths_batch.push_back(path);
+ }
+ estimator_.CollectHitPointData(escaped_paths_batch);
+
+ // Expect that the estimation function returns false.
+ const float outlier_portion = 0.0f;
+ RoomProperties room_properties;
+ EXPECT_FALSE(
+ estimator_.EstimateCubicProxyRoom(outlier_portion, &room_properties));
+}
+
+// Tests that if the scene itself is a cube, then the estimated proxy room
+// can recover the same cube with a certain error below tolerance.
+TEST_F(ProxyRoomEstimatorTest, EstimateCubeFromCubeScene) {
+ wall_materials_ = std::vector<MaterialName>{
+ MaterialName::kAcousticCeilingTiles,
+ MaterialName::kWoodPanel,
+ MaterialName::kConcreteBlockPainted,
+ MaterialName::kGlassThin,
+ MaterialName::kGrass,
+ MaterialName::kMarble,
+ };
+
+ // Trace rays in a cube scene.
+ std::vector<Path> paths = TracePathsInTestcene(
+ kNumRays, kMaxDepth, kEnergyThresold, cube_center_, cube_vertices_,
+ cube_triangles_, cube_wall_triangles_, wall_materials_, &scene_manager_);
+
+ // Estimate a proxy room.
+ estimator_.CollectHitPointData(paths);
+ const float outlier_portion = 0.0f;
+ RoomProperties room_properties;
+ EXPECT_TRUE(
+ estimator_.EstimateCubicProxyRoom(outlier_portion, &room_properties));
+
+ // Expect that the estimated proxy room is the same cube, with a certain
+ // error in position and dimensions.
+ const float position_tolerance = 0.05f;
+ ExpectFloat3Close(room_properties.position, cube_center_, position_tolerance);
+ const float expected_dimensions[3] = {1.0f, 1.0f, 1.0f};
+ const float dimensions_tolerance = 0.01f;
+ ExpectFloat3Close(room_properties.dimensions, expected_dimensions,
+ dimensions_tolerance);
+
+ // Expect that the estimated surface materials are the same as the original
+ // cube.
+ for (size_t wall = 0; wall < 6; ++wall) {
+ EXPECT_EQ(room_properties.material_names[wall], wall_materials_[wall]);
+ }
+}
+
+// Tests that if the scene is a unit sphere, then the estimated proxy room
+// is a cube whose center is the same as the sphere. The dimensions cannot
+// be exactly the same as the sphere, but can be expected to be within
+// a range.
+TEST_F(ProxyRoomEstimatorTest, EstimateCubeFromUnitSphereScene) {
+ const size_t min_num_paths = 1000;
+ std::vector<Path> paths =
+ GenerateUniformlyDistributedRayPaths(kSourcePosition, min_num_paths);
+ ReflectRaysInPaths(1.0f, &paths);
+
+ estimator_.CollectHitPointData(paths);
+
+ const float outlier_portion = 0.0f;
+ RoomProperties room_properties;
+ EXPECT_TRUE(
+ estimator_.EstimateCubicProxyRoom(outlier_portion, &room_properties));
+
+ // Expect the estimated proxy room is centered at the source position.
+ const float position_tolerance = 0.005f;
+ ExpectFloat3Close(room_properties.position, kSourcePosition,
+ position_tolerance);
+
+ // Because the unit sphere is not a cube, the estimated proxy room will have
+ // dimensions between
+ // 1. the smallest cube enclosing the sphere, and
+ // 2. the largest cube inside the sphere.
+ // Specifically, the proxy room will have dimensions between 1.0 and 2.0, or
+ // 1.5 +- 0.5.
+ const float expected_dimensions[3] = {1.5f, 1.5f, 1.5f};
+ const float dimensions_tolerance = 0.5f;
+ ExpectFloat3Close(room_properties.dimensions, expected_dimensions,
+ dimensions_tolerance);
+
+ // Expect that the estimated surface materials are all kConcreteBlockCoarse,
+ // which is closest to absorbing half of the energy across all frequency
+ // bands.
+ for (size_t wall = 0; wall < 6; ++wall) {
+ EXPECT_EQ(room_properties.material_names[wall],
+ MaterialName::kConcreteBlockCoarse);
+ }
+}
+
+// Tests that if the scene is a cube with some openings (no walls in some
+// directions), then the estimated proxy room will have transparent (fully
+// absorbent) walls corresponding to those directions.
+TEST_F(ProxyRoomEstimatorTest, EstimateOpenWallsAsTransparent) {
+ // Remove the last four triangles (corresponding to the two walls facing
+ // the -z and +z directions) from the cube scene.
+ cube_triangles_.pop_back();
+ cube_triangles_.pop_back();
+ cube_triangles_.pop_back();
+ cube_triangles_.pop_back();
+
+ wall_materials_ = std::vector<MaterialName>{
+ MaterialName::kAcousticCeilingTiles,
+ MaterialName::kWoodPanel,
+ MaterialName::kConcreteBlockPainted,
+ MaterialName::kGlassThin,
+ };
+
+ cube_wall_triangles_.pop_back();
+ cube_wall_triangles_.pop_back();
+
+ // Trace rays in the semi-open cube scene.
+ std::vector<Path> paths = TracePathsInTestcene(
+ kNumRays, kMaxDepth, kEnergyThresold, cube_center_, cube_vertices_,
+ cube_triangles_, cube_wall_triangles_, wall_materials_, &scene_manager_);
+
+ // Estimate a proxy room.
+ estimator_.CollectHitPointData(paths);
+ const float outlier_portion = 0.0f;
+ RoomProperties room_properties;
+ EXPECT_TRUE(
+ estimator_.EstimateCubicProxyRoom(outlier_portion, &room_properties));
+
+ // Expect that the estimated proxy room is the same as the original cube.
+ const float position_tolerance = 0.005f;
+ ExpectFloat3Close(room_properties.position, cube_center_, position_tolerance);
+ const float expected_dimensions[3] = {1.0f, 1.0f, 1.0f};
+ const float dimensions_tolerance = 0.001f;
+ ExpectFloat3Close(room_properties.dimensions, expected_dimensions,
+ dimensions_tolerance);
+
+ // Expect that the estimated surface materials are the same as the original
+ // cube for the four remaining walls.
+ for (size_t wall = 0; wall < 4; ++wall) {
+ EXPECT_EQ(room_properties.material_names[wall], wall_materials_[wall]);
+ }
+
+ // Expect that the estimated surface material of the walls corresponding
+ // to the open directions as transparent, because rays in these directions
+ // all escape and are considered completely absorbed.
+ for (size_t wall = 4; wall < 6; ++wall) {
+ EXPECT_EQ(room_properties.material_names[wall], MaterialName::kTransparent);
+ }
+}
+
+// Tests if the scene is a cube, but some hit points are too far or too close
+// to the origin, those points can be considered as outliers (if a proper
+// |outlier_portion| is set) and will not affect the estimation result.
+// Therefore the estimated proxy room is still the same cube.
+TEST_F(ProxyRoomEstimatorTest, EstimateCubeIgnoringOutliers) {
+ wall_materials_ = std::vector<MaterialName>{
+ MaterialName::kAcousticCeilingTiles,
+ MaterialName::kWoodPanel,
+ MaterialName::kConcreteBlockPainted,
+ MaterialName::kGlassThin,
+ MaterialName::kGrass,
+ MaterialName::kMarble,
+ };
+
+ // Trace rays in a cube scene.
+ std::vector<Path> paths = TracePathsInTestcene(
+ kNumRays, kMaxDepth, kEnergyThresold, cube_center_, cube_vertices_,
+ cube_triangles_, cube_wall_triangles_, wall_materials_, &scene_manager_);
+
+ // Modify the traced paths so that some hit points are too close or too far.
+ const size_t num_points_too_close = 100;
+ const float distance_too_close = 0.1f;
+ for (size_t i = 0; i < num_points_too_close; ++i) {
+ paths[0].rays[0].tfar = distance_too_close;
+ }
+ const size_t num_points_too_far = 100;
+ const float distance_too_far = 10.0f;
+ for (size_t i = num_points_too_close;
+ i < num_points_too_far + num_points_too_close; ++i) {
+ paths[0].rays[0].tfar = distance_too_far;
+ }
+
+ // Estimate a proxy room with a |outlier_portion| carefully chosen such that
+ // the hit points too close or too far do not affect the estimation result.
+ estimator_.CollectHitPointData(paths);
+ const float outlier_portion =
+ static_cast<float>(num_points_too_close + num_points_too_far) /
+ static_cast<float>(paths.size()) / 2.0f;
+ RoomProperties room_properties;
+ EXPECT_TRUE(
+ estimator_.EstimateCubicProxyRoom(outlier_portion, &room_properties));
+
+ // Expect that the estimated proxy room is still the same as the original
+ // cube, even in the presence of the hit points too close or too far.
+ const float position_tolerance = 0.05f;
+ ExpectFloat3Close(room_properties.position, cube_center_, position_tolerance);
+ const float expected_dimensions[3] = {1.0f, 1.0f, 1.0f};
+ const float dimensions_tolerance = 0.01f;
+ ExpectFloat3Close(room_properties.dimensions, expected_dimensions,
+ dimensions_tolerance);
+
+ // Expect that the estimated surface materials are the same as the original
+ // cube.
+ for (size_t wall = 0; wall < 6; ++wall) {
+ EXPECT_EQ(room_properties.material_names[wall], wall_materials_[wall]);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel.cc
new file mode 100644
index 000000000..f55f2eb72
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel.cc
@@ -0,0 +1,99 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/reflection_kernel.h"
+
+#include "base/logging.h"
+#include "geometrical_acoustics/sampling.h"
+
+namespace vraudio {
+
+using Eigen::Vector3f;
+
+AcousticRay ReflectionKernel::Reflect(const AcousticRay& incident_ray) const {
+ // This function currently uses |random_number_generator| (which returns
+ // uniformly distributed numbers) to naively sample 1D and 2D points.
+
+ AcousticRay::RayType reflected_ray_type =
+ (random_number_generator_() >= scattering_coefficient_)
+ ? AcousticRay::RayType::kSpecular
+ : AcousticRay::RayType::kDiffuse;
+
+ // Compute the reflected direction.
+ Vector3f reflected_direction;
+ const Vector3f& unit_normal =
+ Vector3f(incident_ray.intersected_geometry_normal()).normalized();
+ const Vector3f& incident_direction = Vector3f(incident_ray.direction());
+ switch (reflected_ray_type) {
+ case AcousticRay::RayType::kSpecular:
+ reflected_direction =
+ incident_direction -
+ 2.0f * incident_direction.dot(unit_normal) * unit_normal;
+ break;
+ case AcousticRay::RayType::kDiffuse:
+ // A Lambertian reflection.
+ reflected_direction = CosineSampleHemisphere(
+ random_number_generator_(), random_number_generator_(), unit_normal);
+ break;
+ }
+ const Vector3f reflected_origin = Vector3f(incident_ray.origin()) +
+ incident_ray.t_far() * incident_direction;
+ const float reflected_ray_prior_distance =
+ incident_ray.prior_distance() +
+ incident_ray.t_far() * incident_direction.norm();
+
+ // New energies for each frequency band.
+ CHECK_EQ(reflection_coefficients_.size(), incident_ray.energies().size());
+ std::array<float, kNumReverbOctaveBands> new_energies =
+ incident_ray.energies();
+
+ for (size_t i = 0; i < new_energies.size(); ++i) {
+ new_energies[i] *= reflection_coefficients_[i];
+ }
+
+ return AcousticRay(reflected_origin.data(), reflected_direction.data(),
+ AcousticRay::kRayEpsilon, AcousticRay::kInfinity,
+ new_energies, reflected_ray_type,
+ reflected_ray_prior_distance);
+}
+
+void ReflectionKernel::ReflectDiffuseRain(
+ const AcousticRay& incident_ray, const AcousticRay& reference_reflected_ray,
+ const Eigen::Vector3f& listener_position, float* direction_pdf,
+ AcousticRay* diffuse_rain_ray) const {
+ const Vector3f reflection_point_to_listener =
+ listener_position - Vector3f(reference_reflected_ray.origin());
+ const Vector3f reflection_point_to_listener_direction =
+ reflection_point_to_listener.normalized();
+ const float diffuse_rain_ray_t_far =
+ reflection_point_to_listener.norm() + reference_reflected_ray.t_near();
+
+ *direction_pdf = CosineSampleHemispherePdf(
+ Vector3f(incident_ray.intersected_geometry_normal()).normalized(),
+ reflection_point_to_listener_direction);
+
+ diffuse_rain_ray->set_origin(reference_reflected_ray.origin());
+ diffuse_rain_ray->set_direction(
+ reflection_point_to_listener_direction.data());
+ diffuse_rain_ray->set_t_near(reference_reflected_ray.t_near());
+ diffuse_rain_ray->set_t_far(diffuse_rain_ray_t_far);
+ diffuse_rain_ray->set_energies(reference_reflected_ray.energies());
+ diffuse_rain_ray->set_type(reference_reflected_ray.type());
+ diffuse_rain_ray->set_prior_distance(
+ reference_reflected_ray.prior_distance());
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel.h
new file mode 100644
index 000000000..10b34d5c7
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel.h
@@ -0,0 +1,104 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_REFLECTION_KERNEL_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_REFLECTION_KERNEL_H_
+
+#include <array>
+#include <functional>
+#include <utility>
+
+#include "Eigen/Core"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "geometrical_acoustics/acoustic_ray.h"
+
+namespace vraudio {
+
+// A class modeling reflections of acoustic rays. It takes in an incident ray
+// and computes the corresponding reflected ray. NOTE: not to be confused with
+// vraudio:Reflection, which models the reflection properties of a room.
+//
+// This class handles specular and diffuse reflections, randomly chosen based
+// on the scattering coefficient. Besides, a certain portion of the energy is
+// absorbed based on the absorption coefficient.
+//
+
+class ReflectionKernel {
+ public:
+ // Constructor.
+ //
+ // @param absorption_coefficients Fraction of energy being absorbed for each
+ // frequency band. All values must be in [0.0, 1.0].
+ // @param scattering_coefficient Fraction of energy being scattered
+ // (diffusely reflected). Must be in [0.0, 1.0].
+ // @param random_number_generator Random number generator to randomly select
+ // reflection types as well as ray directions if needed. It should
+ // implement operator() that returns a random value in [0.0, 1.0).
+ ReflectionKernel(
+ const std::array<float, kNumReverbOctaveBands>& absorption_coefficients,
+ float scattering_coefficient,
+ std::function<float()> random_number_generator)
+ : scattering_coefficient_(scattering_coefficient),
+ random_number_generator_(std::move(random_number_generator)) {
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ reflection_coefficients_[i] = 1.0f - absorption_coefficients[i];
+ CHECK(reflection_coefficients_[i] >= 0.0f &&
+ reflection_coefficients_[i] <= 1.0f);
+ }
+ CHECK(scattering_coefficient_ >= 0.0f && scattering_coefficient_ <= 1.0f);
+ }
+
+ // Reflects a ray.
+ //
+ // @param incident_ray Incident (incoming) ray.
+ // @return Exitant (outgoing) ray, whose origin is on the intersection point,
+ // with direction and energy calculated based on the type of reflection
+ // and the incident ray.
+ AcousticRay Reflect(const AcousticRay& incident_ray) const;
+
+ // Reflects an incident ray to create a diffuse-rain ray, whose |direction|
+ // is from the reflection point to the listener position, and whose |t_far|
+ // is the distance between the reflection point and the listener position.
+ // All the other data are the copied from the provided
+ // |reference_reflected_ray|.
+ //
+ // @param incident_ray Incident ray.
+ // @param reflected_ray Reference reflected ray, from which the output
+ // diffuse-rain ray copies all the data except for |direction| and
+ // |t_far|.
+ // @param listener_position Listener position.
+ // @param direction_pdf Output probability density function that a reflected
+ // ray is in the direction of the diffuse-rain ray. Will be used to
+ // modulate the energy contribution from the diffuse-rain ray.
+ // @param diffuse_rain_ray Output diffuse-rain ray.
+ void ReflectDiffuseRain(const AcousticRay& incident_ray,
+ const AcousticRay& reference_reflected_ray,
+ const Eigen::Vector3f& listener_position,
+ float* direction_pdf,
+ AcousticRay* diffuse_rain_ray) const;
+
+ private:
+ std::array<float, kNumReverbOctaveBands> reflection_coefficients_;
+ const float scattering_coefficient_;
+
+ // Randon number generator for sampling reflection types and ray directions.
+ std::function<float()> random_number_generator_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_REFLECTION_KERNEL_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel_test.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel_test.cc
new file mode 100644
index 000000000..bf1806996
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/reflection_kernel_test.cc
@@ -0,0 +1,300 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/reflection_kernel.h"
+
+#include <cmath>
+#include <functional>
+#include <random>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "Eigen/Dense"
+#include "geometrical_acoustics/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+using Eigen::Quaternionf;
+using Eigen::Vector3f;
+
+class ReflectionKernelTest : public testing::Test {
+ public:
+ ReflectionKernelTest()
+ : incident_ray_(Vector3f(0.0f, 0.0f, 0.0f).data(),
+ Vector3f(1.0f, 1.0f, 1.0f).normalized().data(), 0.0f,
+ AcousticRay::kInfinity, kEnergies,
+ AcousticRay::RayType::kSpecular, 0.0f),
+ random_engine_(0),
+ distribution_(0.0f, 1.0f) {}
+
+ void SetUp() override {
+ // Reseed the random number generator for every test to be deterministic
+ // and remove flakiness in tests.
+ random_engine_.seed(0);
+ random_number_generator_ = [this] { return distribution_(random_engine_); };
+ }
+
+ protected:
+ const std::array<float, kNumReverbOctaveBands> kEnergies = {
+ {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}};
+ const std::array<float, kNumReverbOctaveBands> kUnitAbsorptionCoefficients = {
+ {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
+ const std::array<float, kNumReverbOctaveBands> kZeroAbsorptionCoefficients = {
+ {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}};
+
+ AcousticRay incident_ray_;
+ std::default_random_engine random_engine_;
+ std::uniform_real_distribution<float> distribution_;
+ std::function<float()> random_number_generator_;
+};
+
+TEST_F(ReflectionKernelTest, EnergyAbsorptionTest) {
+ const std::array<float, kNumReverbOctaveBands>& original_energies =
+ incident_ray_.energies();
+ {
+ // An absorption coefficient of 1 means that no energy is reflected.
+ const ReflectionKernel reflection(kUnitAbsorptionCoefficients, 0.0f,
+ random_number_generator_);
+ const AcousticRay reflected_ray = reflection.Reflect(incident_ray_);
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ EXPECT_FLOAT_EQ(reflected_ray.energies().at(i), 0.0f);
+ }
+ }
+ {
+ // An absorption coefficient of 0 means that all energy is reflected.
+ const ReflectionKernel reflection(kZeroAbsorptionCoefficients, 0.0f,
+ random_number_generator_);
+ const AcousticRay reflected_ray = reflection.Reflect(incident_ray_);
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ EXPECT_FLOAT_EQ(reflected_ray.energies().at(i), original_energies.at(i));
+ }
+ }
+ {
+ // An absorption coefficient of x means that only (1.0 - x) of the energy
+ // would be reflected.
+ std::array<float, kNumReverbOctaveBands> absorption_coefficients = {
+ {0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f}};
+ const ReflectionKernel reflection(absorption_coefficients, 0.0f,
+ random_number_generator_);
+ const AcousticRay reflected_ray = reflection.Reflect(incident_ray_);
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ EXPECT_FLOAT_EQ(
+ reflected_ray.energies().at(i),
+ (1.0f - absorption_coefficients.at(i)) * original_energies.at(i));
+ }
+ }
+}
+
+TEST_F(ReflectionKernelTest, ScatteringCoefficientTest) {
+ // Setting the scattering coefficient to 0.3 means 30% of the rays are
+ // reflected diffusely while 70% are reflected specularly.
+ const ReflectionKernel reflection(kUnitAbsorptionCoefficients, 0.3f,
+ random_number_generator_);
+
+ float specular_fraction = 0.0f;
+ float diffuse_fraction = 0.0f;
+ const int num_samples = 10000;
+ const float fraction_per_sample = 1.0f / static_cast<float>(num_samples);
+ for (int i = 0; i < num_samples; ++i) {
+ const AcousticRay reflected_ray = reflection.Reflect(incident_ray_);
+ (reflected_ray.type() == AcousticRay::RayType::kDiffuse
+ ? diffuse_fraction
+ : specular_fraction) += fraction_per_sample;
+ }
+ EXPECT_NEAR(diffuse_fraction, 0.3f, 0.01f);
+ EXPECT_NEAR(specular_fraction, 0.7f, 0.01f);
+}
+
+TEST_F(ReflectionKernelTest, MultipleReflectionsTest) {
+ const ReflectionKernel reflection(kUnitAbsorptionCoefficients, 0.0f,
+ random_number_generator_);
+
+ // Reflect |num_reflections| times. Validate that each reflected ray starts
+ // where its incident ray ends. This is to simulate the effect of a typical
+ // path tracer.
+ const size_t num_reflections = 5;
+ const float t_between_intersections = 2.0f;
+ const float distance_between_intersections = t_between_intersections *
+ Vector3f(incident_ray_.direction()).norm();
+
+ AcousticRay ray = incident_ray_;
+ float expected_prior_distance = 0.0f;
+ for (size_t i = 0; i < num_reflections; ++i) {
+ // Emulate an intersection at t = 2, with a plane whose (unnormalized)
+ // normal being (0, 0, -1) for even iterations and (0, 0, 1) for odd
+ // iterations.
+ ray.set_t_far(t_between_intersections);
+ const float even_normal[3] = {0.0f, 0.0f, -1.0f};
+ const float odd_normal[3] = {0.0f, 0.0f, 1.0f};
+ ray.set_intersected_geometry_normal((i % 2 == 0) ? even_normal
+ : odd_normal);
+ const AcousticRay reflected_ray = reflection.Reflect(ray);
+
+ // Check that the reflected ray starts where the original ray ends.
+ const Vector3f& expected_reflected_ray_origin =
+ Vector3f(ray.origin()) + ray.t_far() * Vector3f(ray.direction());
+ ExpectFloat3Close(reflected_ray.origin(),
+ expected_reflected_ray_origin.data());
+ EXPECT_FLOAT_EQ(reflected_ray.t_near(), AcousticRay::kRayEpsilon);
+
+ // Check that the |prior_distance| field accumulates the distance traveled.
+ expected_prior_distance += distance_between_intersections;
+ EXPECT_FLOAT_EQ(reflected_ray.prior_distance(), expected_prior_distance);
+
+ // Continue tracing the reflected ray.
+ ray = reflected_ray;
+ }
+}
+
+TEST_F(ReflectionKernelTest, SpecularReflectionTest) {
+ // Emulate an intersection at t = 2, with a plane whose (unnormalized) normal
+ // is (-1, -1, 0).
+ incident_ray_.set_t_far(2.0f);
+ const float normal[3] = {-1.0f, -1.0f, 0.0f};
+ incident_ray_.set_intersected_geometry_normal(normal);
+
+ // Setting the scattering coefficient to zero means to always reflect
+ // specularly.
+ const ReflectionKernel reflection(kUnitAbsorptionCoefficients, 0.0f,
+ random_number_generator_);
+ const AcousticRay reflected_ray = reflection.Reflect(incident_ray_);
+
+ // Validate non-directional data.
+ EXPECT_FLOAT_EQ(reflected_ray.t_near(), AcousticRay::kRayEpsilon);
+ EXPECT_EQ(reflected_ray.type(), AcousticRay::RayType::kSpecular);
+ const float expected_reflected_origin[3] = {1.15470053838f, 1.15470053838f,
+ 1.15470053838f};
+ ExpectFloat3Close(reflected_ray.origin(), expected_reflected_origin);
+
+ // Validate the reflected direction.
+ const Vector3f& expected_reflected_direction =
+ Vector3f(-1.0f, -1.0f, 1.0f).normalized();
+ ExpectFloat3Close(reflected_ray.direction(),
+ expected_reflected_direction.data());
+}
+
+TEST_F(ReflectionKernelTest, DiffuseReflectionTest) {
+ // Emulate an intersection at t = 2, with a plane whose (unnormalized) normal
+ // is (-1, -1, 0).
+ incident_ray_.set_t_far(2.0f);
+ const float normal[3] = {-1.0f, -1.0f, 0.0f};
+ incident_ray_.set_intersected_geometry_normal(normal);
+
+ // Setting the scattering coefficient to 1.0 means to always reflect
+ // diffusely.
+ const ReflectionKernel reflection(kUnitAbsorptionCoefficients, 1.0f,
+ random_number_generator_);
+ const AcousticRay reflected_ray = reflection.Reflect(incident_ray_);
+
+ // Validate non-directional data.
+ EXPECT_FLOAT_EQ(reflected_ray.t_near(), AcousticRay::kRayEpsilon);
+ EXPECT_EQ(reflected_ray.type(), AcousticRay::RayType::kDiffuse);
+
+ // Validate the reflected directions.
+ // For a reflected ray whose direction distribution is cosine-weighted over a
+ // hemisphere:
+ // - The PDF of theta is 2 sin(theta) cos(theta), and the CDF is sin^2(theta).
+ // - The PDF of phi is 1 / 2 pi, and the CDF is 0.5 + phi / 2 pi.
+ const Vector3f& plane_unit_normal =
+ Vector3f(incident_ray_.intersected_geometry_normal()).normalized();
+ ValidateDistribution(100000, 100, [&reflection, &plane_unit_normal, this]() {
+ const AcousticRay reflected_ray = reflection.Reflect(incident_ray_);
+ const Vector3f& local_direction =
+ Quaternionf::FromTwoVectors(plane_unit_normal, Vector3f::UnitZ()) *
+ Vector3f(reflected_ray.direction());
+ const float cos_theta = local_direction.z();
+ const float sin_theta_square = 1.0f - cos_theta * cos_theta;
+ return sin_theta_square;
+ });
+
+ ValidateDistribution(100000, 100, [&reflection, &plane_unit_normal, this]() {
+ const AcousticRay reflected_ray = reflection.Reflect(incident_ray_);
+ const Vector3f& local_direction =
+ Quaternionf::FromTwoVectors(plane_unit_normal, Vector3f::UnitZ()) *
+ Vector3f(reflected_ray.direction());
+ const float phi = std::atan2(local_direction.y(), local_direction.x());
+ return 0.5f + phi / 2.0f / static_cast<float>(M_PI);
+ });
+}
+
+TEST_F(ReflectionKernelTest, DiffuseRainReflectionTest) {
+ // Emulate an intersection at t = 2, with a plane whose (unnormalized) normal
+ // is (-1, -1, 0).
+ incident_ray_.set_t_far(2.0f);
+ const float normal[3] = {-1.0f, -1.0f, 0.0f};
+ incident_ray_.set_intersected_geometry_normal(normal);
+
+ // Setting the scattering coefficient to 1.0 means to always reflect
+ // diffusely.
+ const ReflectionKernel reflection(kUnitAbsorptionCoefficients, 1.0f,
+ random_number_generator_);
+ const AcousticRay reference_reflected_ray = reflection.Reflect(incident_ray_);
+
+ // Generate a diffuse-rain ray for a listener on the same side of the plane.
+ float direction_pdf = -1.0f;
+ const Vector3f same_side_listener_position(0.0f, 0.0f, 2.0f);
+ AcousticRay diffuse_rain_ray;
+ reflection.ReflectDiffuseRain(incident_ray_, reference_reflected_ray,
+ same_side_listener_position, &direction_pdf,
+ &diffuse_rain_ray);
+
+ // The direction of the diffuse-rain ray should be from the reflection point
+ // (the origin of the |reference_reflected_ray|) to the listener position.
+ const Vector3f reflection_point_to_listener_position =
+ same_side_listener_position - Vector3f(reference_reflected_ray.origin());
+ const Vector3f expected_direction =
+ reflection_point_to_listener_position.normalized();
+ ExpectFloat3Close(diffuse_rain_ray.direction(), expected_direction.data());
+
+ // The output |direction_pdf| should be cos(theta) / pi, where theta is the
+ // angle between the normal of the reflecting surface and the expected
+ // direction.
+ const float cos_theta = expected_direction.dot(Vector3f(normal).normalized());
+ EXPECT_FLOAT_EQ(direction_pdf, cos_theta / kPi);
+
+ // Verify that the |t_far| - |t_near| is the distance between the reflection
+ // point and the listener position.
+ EXPECT_FLOAT_EQ(diffuse_rain_ray.t_far() - diffuse_rain_ray.t_near(),
+ reflection_point_to_listener_position.norm());
+
+ // Verify that other data are the same as |reference_reflected_ray|.
+ ExpectFloat3Close(diffuse_rain_ray.origin(),
+ reference_reflected_ray.origin());
+ EXPECT_FLOAT_EQ(diffuse_rain_ray.t_near(), reference_reflected_ray.t_near());
+ ExpectFloat3Close(diffuse_rain_ray.intersected_geometry_normal(),
+ reference_reflected_ray.intersected_geometry_normal());
+ for (size_t band = 0; band < kNumReverbOctaveBands; ++band) {
+ EXPECT_FLOAT_EQ(diffuse_rain_ray.energies()[band],
+ reference_reflected_ray.energies()[band]);
+ }
+ EXPECT_EQ(diffuse_rain_ray.type(), reference_reflected_ray.type());
+ EXPECT_FLOAT_EQ(diffuse_rain_ray.prior_distance(),
+ reference_reflected_ray.prior_distance());
+
+ // Generate a diffuse-rain ray for a listener on the different side of the
+ // plane and expect that the output |direction_pdf| is zero, meaning there is
+ // no chance that the diffuse-rain ray is in that direction.
+ const Vector3f different_side_listener_position(10.0f, 10.0f, 10.0f);
+ reflection.ReflectDiffuseRain(incident_ray_, reference_reflected_ray,
+ different_side_listener_position,
+ &direction_pdf, &diffuse_rain_ray);
+ EXPECT_FLOAT_EQ(direction_pdf, 0.0f);
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sampling.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sampling.h
new file mode 100644
index 000000000..99ace88d5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sampling.h
@@ -0,0 +1,126 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Collection of sampling functions useful for in stochastic ray tracing.
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SAMPLING_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SAMPLING_H_
+
+#include <cmath>
+
+#include "Eigen/Dense"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+// Samples a vector uniformly from a unit sphere given two random variables
+// whose values are in [0, 1).
+//
+// @param u The first random variable.
+// @param v The second random variable.
+// @return The sampled vector.
+inline Eigen::Vector3f UniformSampleSphere(float u, float v) {
+ DCHECK(u >= 0.0f && u <= 1.0f);
+ DCHECK(v >= 0.0f && v <= 1.0f);
+ const float cos_theta = 1.0f - 2.0f * v;
+ const float sin_theta = 2.0f * std::sqrt(v * (1.0f - v));
+ const float phi = kTwoPi * u;
+ return Eigen::Vector3f(std::cos(phi) * sin_theta, std::sin(phi) * sin_theta,
+ cos_theta);
+}
+
+// Samples a vector from a unit sphere in a stratified fashion given two
+// random variables whose values are in [0, 1). The collective results from
+// |sample_index| iterating from 0 to |sqrt_num_samples|^2 are uniformly
+// distributed on a sphere.
+//
+// @param u The first random variable.
+// @param v The second random variable.
+// @param sqrt_num_samples The square root of the total number of samples.
+// @param sample_index The index of the currently sampled vector.
+// @return The sampled vector.
+inline Eigen::Vector3f StratifiedSampleSphere(float u, float v,
+ size_t sqrt_num_samples,
+ size_t sample_index) {
+ DCHECK(u >= 0.0f && u <= 1.0f);
+ DCHECK(v >= 0.0f && v <= 1.0f);
+
+ // Make a domain that have |sqrt_num_samples| by |sqrt_num_samples| cells.
+ // First decide which cell that this sample is in, denoted by the coordinates
+ // of the cell's top-left of corner.
+ const float cell_x = static_cast<float>(sample_index / sqrt_num_samples);
+ const float cell_y = static_cast<float>(sample_index % sqrt_num_samples);
+
+ // Then pick a point inside the cell using the two random variables u and v.
+ // Normalize the point to the [0, 1) x [0, 1) domain and send it to
+ // UniformSampleSphere().
+ const float cell_width = 1.0f / static_cast<float>(sqrt_num_samples);
+ return UniformSampleSphere((cell_x + u) * cell_width,
+ (cell_y + v) * cell_width);
+}
+
+// Samples a vector from a unit hemisphere according to the cosine-weighted
+// distribution given two random variables whose values are in [0, 1). The
+// hemisphere lies on a plane whose normal is assumed to be on the +z direction.
+//
+
+static Eigen::Vector3f CosineSampleHemisphere(float u, float v) {
+ DCHECK(u >= 0.0f && u <= 1.0f);
+ DCHECK(v >= 0.0f && v <= 1.0f);
+ const float cos_theta = std::sqrt(1.0f - v);
+ const float sin_theta = std::sqrt(v);
+ const float phi = kTwoPi * u;
+ return Eigen::Vector3f(std::cos(phi) * sin_theta, std::sin(phi) * sin_theta,
+ cos_theta);
+}
+
+// Same as above but the hemisphere lies on a plane whose normal is specified
+// by the user (instead of the +z direction).
+//
+// @param u The first random variable.
+// @param v The second random variable.
+// @param unit_normal The normal of the plane on which the hemisphere resides.
+// @return The sampled vector.
+static Eigen::Vector3f CosineSampleHemisphere(
+ float u, float v, const Eigen::Vector3f& unit_normal) {
+ Eigen::Vector3f local_vector = CosineSampleHemisphere(u, v);
+
+ return Eigen::Quaternionf::FromTwoVectors(Eigen::Vector3f::UnitZ(),
+ unit_normal) *
+ local_vector;
+}
+
+// The probability density function (PDF) that a vector is in a particular
+// direction if the vector is sampled from a cosine-weigted distribution over
+// a unit hemisphere (i.e. it is sampled from the CosineSampleHemisphere()
+// above).
+//
+// @param unit_normal The normal of the plane on which the hemisphere resides.
+// @param unit_direction The direction of the sampled vector.
+// @return Probability density that a sampled vector is in the |unit_direction|.
+static float CosineSampleHemispherePdf(const Eigen::Vector3f& unit_normal,
+ const Eigen::Vector3f& unit_direction) {
+ const float cos_theta = unit_normal.dot(unit_direction);
+
+ // Returns zero probability if the |unit_normal| and |unit_direction| lie on
+ // different sides of the plane, i.e., their inner-product is negative.
+ return cos_theta >= 0.0f ? cos_theta / kPi : 0.0f;
+}
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SAMPLING_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager.cc
new file mode 100644
index 000000000..38baeb7ab
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager.cc
@@ -0,0 +1,153 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/scene_manager.h"
+
+#include "base/aligned_allocator.h"
+#include "geometrical_acoustics/sphere.h"
+
+namespace vraudio {
+
+namespace {
+
+// A function adapter from SphereBounds() to RTCBoundsFunc in order to be
+// passed to rtcSetBoundsFunction().
+// The signature of RTCBoundsFunc does not comply with Google's C++ style,
+
+static void EmbreeSphereBoundsFunction(void* user_data, size_t index,
+ RTCBounds& output_bounds
+) {
+ Sphere* spheres = static_cast<Sphere*>(user_data);
+ const Sphere& sphere = spheres[index];
+ SphereBounds(sphere, &output_bounds);
+}
+
+// A function adapter from SphereIntersections() to RTCIntersectFunc in order
+// to be passed to rtcSetIntersectFunction().
+// The signature of RTCIntersectFunc does not comply with Google's C++ style,
+
+static void EmbreeSphereIntersectFunction(void* user_data,
+ RTCRay& ray,
+ size_t index) {
+ Sphere* const spheres = static_cast<Sphere*>(user_data);
+ const Sphere& sphere = spheres[index];
+ SphereIntersection(sphere, &ray);
+}
+
+} // namespace
+
+SceneManager::SceneManager() {
+ // Use a single RTCDevice for all scenes.
+ device_ = rtcNewDevice(nullptr);
+ CHECK_NOTNULL(device_);
+ scene_ = rtcDeviceNewScene(device_, RTC_SCENE_STATIC | RTC_SCENE_HIGH_QUALITY,
+ RTC_INTERSECT1);
+ listener_scene_ = rtcDeviceNewScene(
+ device_, RTC_SCENE_STATIC | RTC_SCENE_HIGH_QUALITY, RTC_INTERSECT1);
+}
+
+SceneManager::~SceneManager() {
+ rtcDeleteScene(scene_);
+ rtcDeleteScene(listener_scene_);
+ rtcDeleteDevice(device_);
+}
+
+void SceneManager::BuildScene(const std::vector<Vertex>& vertex_buffer,
+ const std::vector<Triangle>& triangle_buffer) {
+ num_vertices_ = vertex_buffer.size();
+ num_triangles_ = triangle_buffer.size();
+ unsigned int mesh_id = rtcNewTriangleMesh(scene_, RTC_GEOMETRY_STATIC,
+ num_triangles_, num_vertices_);
+ struct EmbreeVertex {
+ // Embree uses 4 floats for each vertex for alignment. The last value
+ // is for padding only.
+ float x, y, z, a;
+ };
+ EmbreeVertex* const embree_vertex_array = static_cast<EmbreeVertex*>(
+ rtcMapBuffer(scene_, mesh_id, RTC_VERTEX_BUFFER));
+ for (size_t i = 0; i < num_vertices_; ++i) {
+ embree_vertex_array[i].x = vertex_buffer[i].x;
+ embree_vertex_array[i].y = vertex_buffer[i].y;
+ embree_vertex_array[i].z = vertex_buffer[i].z;
+ }
+ rtcUnmapBuffer(scene_, mesh_id, RTC_VERTEX_BUFFER);
+
+ // Triangles. Somehow Embree is a left-handed system, so we re-order all
+ // triangle indices here, i.e. {v0, v1, v2} -> {v0, v2, v1}.
+ int* const embree_index_array =
+ static_cast<int*>(rtcMapBuffer(scene_, mesh_id, RTC_INDEX_BUFFER));
+ for (size_t i = 0; i < num_triangles_; ++i) {
+ embree_index_array[3 * i + 0] = triangle_buffer[i].v0;
+ embree_index_array[3 * i + 1] = triangle_buffer[i].v2;
+ embree_index_array[3 * i + 2] = triangle_buffer[i].v1;
+ }
+ rtcUnmapBuffer(scene_, mesh_id, RTC_INDEX_BUFFER);
+ rtcCommit(scene_);
+ is_scene_committed_ = true;
+}
+
+bool SceneManager::AssociateReflectionKernelToTriangles(
+ const ReflectionKernel& reflection,
+ const std::unordered_set<unsigned int>& triangle_indices) {
+ const size_t reflection_index = reflections_.size();
+ reflections_.push_back(reflection);
+ for (const unsigned int triangle_index : triangle_indices) {
+ if (triangle_index >= num_triangles_) {
+ return false;
+ }
+ triangle_to_reflection_map_[triangle_index] = reflection_index;
+ }
+ return true;
+}
+
+void SceneManager::BuildListenerScene(
+ const std::vector<AcousticListener>& listeners,
+ float listener_sphere_radius) {
+ rtcDeleteScene(listener_scene_);
+ listener_scene_ = rtcDeviceNewScene(
+ device_, RTC_SCENE_STATIC | RTC_SCENE_HIGH_QUALITY, RTC_INTERSECT1);
+
+ for (size_t listener_index = 0; listener_index < listeners.size();
+ ++listener_index) {
+ // Create a sphere per listener and add to |listener_scene_|.
+ const AcousticListener& listener = listeners.at(listener_index);
+ const unsigned int sphere_id = rtcNewUserGeometry(listener_scene_, 1);
+ Sphere* const sphere =
+ AllignedMalloc<Sphere, size_t, Sphere*>(sizeof(Sphere),
+ /*alignment=*/64);
+ sphere->center[0] = listener.position[0];
+ sphere->center[1] = listener.position[1];
+ sphere->center[2] = listener.position[2];
+ sphere->radius = listener_sphere_radius;
+ sphere->geometry_id = sphere_id;
+
+ // rtcSetUserData() takes ownership of |sphere|.
+ rtcSetUserData(listener_scene_, sphere_id, sphere);
+ rtcSetBoundsFunction(listener_scene_, sphere_id,
+ &EmbreeSphereBoundsFunction);
+ rtcSetIntersectFunction(listener_scene_, sphere_id,
+ &EmbreeSphereIntersectFunction);
+
+ // Associate the listener to |sphere_id| through its index in the vector
+ // of listeners.
+ sphere_to_listener_map_[sphere_id] = listener_index;
+ }
+
+ rtcCommit(listener_scene_);
+ is_listener_scene_committed_ = true;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager.h
new file mode 100644
index 000000000..85d6eb5dd
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager.h
@@ -0,0 +1,130 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SCENE_MANAGER_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SCENE_MANAGER_H_
+
+#include <functional>
+#include <unordered_map>
+#include <unordered_set>
+#include <vector>
+
+#include "embree2/rtcore.h"
+#include "embree2/rtcore_ray.h"
+#include "base/logging.h"
+#include "geometrical_acoustics/acoustic_listener.h"
+#include "geometrical_acoustics/mesh.h"
+#include "geometrical_acoustics/reflection_kernel.h"
+
+namespace vraudio {
+
+// A class to manage a scene modeling an acoustic environment and a scene
+// modeling listeners.
+class SceneManager {
+ public:
+ SceneManager();
+ virtual ~SceneManager();
+
+ // Builds a scene with triangles describing the acoustic environment.
+ //
+ // @param vertex_buffer A vector of vertices.
+ // @param triangle_buffer A vector of triangles. The triangles should be
+ // right-handed, i.e. if a triangle is defined by {v0, v1, v2},
+ // then its normal is along the right-handed cross product of (v1 - v0)
+ // and (v2 - v0).
+ void BuildScene(const std::vector<Vertex>& vertex_buffer,
+ const std::vector<Triangle>& triangle_buffer);
+
+ // Associates a reflection kernel to a set of triangles.
+ //
+ // @param reflection Reflection kernel.
+ // @param triangle_indices Indices of triangles to be associated with
+ // the reflection .
+ // @return True on success.
+ bool AssociateReflectionKernelToTriangles(
+ const ReflectionKernel& reflection_kernel,
+ const std::unordered_set<unsigned int>& triangle_indices);
+
+ // Gets the reflection kernel associated to a triangle.
+ //
+ // @param triangle_index The index of the triangle to get the reflection
+ // kernel from.
+ // @return The reflection kernel associated to the triangle; a default
+ // reflection if no reflection kernel is associated to the triangle.
+ const ReflectionKernel& GetAssociatedReflectionKernel(
+ unsigned int triangle_index) const {
+ if (triangle_to_reflection_map_.count(triangle_index) == 0) {
+ return kDefaultReflection;
+ }
+ return reflections_.at(triangle_to_reflection_map_.at(triangle_index));
+ }
+
+ RTCScene scene() const { return scene_; }
+ bool is_scene_committed() const { return is_scene_committed_; }
+ size_t num_vertices() const { return num_vertices_; }
+ size_t num_triangles() const { return num_triangles_; }
+
+ // Builds a scene with only listener spheres, one sphere per listener.
+ //
+ // @param listeners Vector of AcousticListeners.
+ // @param listener_sphere_radius Radius of listener spheres (m).
+ void BuildListenerScene(const std::vector<AcousticListener>& listeners,
+ float listener_sphere_radius);
+
+ // Gets the listener index associated to a sphere id.
+ //
+ // @param sphere_id Sphere id.
+ // @return listener_index Listener index associated to the sphere id.
+ size_t GetListenerIndexFromSphereId(unsigned int sphere_id) {
+ DCHECK_GT(sphere_to_listener_map_.count(sphere_id), 0);
+ return sphere_to_listener_map_.at(sphere_id);
+ }
+
+ RTCScene listener_scene() const { return listener_scene_; }
+ bool is_listener_scene_committed() const {
+ return is_listener_scene_committed_;
+ }
+
+ private:
+ // Perfect absorption. No randomness needed.
+ const std::array<float, kNumReverbOctaveBands>
+ kPerfectReflectionCoefficients = {
+ {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
+ const ReflectionKernel kDefaultReflection = ReflectionKernel(
+ kPerfectReflectionCoefficients, 0.0f, []() { return 0.5f; });
+
+ // Embree device.
+ RTCDevice device_;
+
+ // Scene modeling an acoustic environment.
+ RTCScene scene_;
+ bool is_scene_committed_ = false;
+ size_t num_vertices_ = 0;
+ size_t num_triangles_ = 0;
+ std::vector<ReflectionKernel> reflections_;
+ std::unordered_map<unsigned int, size_t> triangle_to_reflection_map_;
+
+ // Scene with only listener spheres.
+ RTCScene listener_scene_;
+ bool is_listener_scene_committed_ = false;
+
+ // Map from a sphere's id to the index of a listener.
+ std::unordered_map<unsigned int, size_t> sphere_to_listener_map_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SCENE_MANAGER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager_test.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager_test.cc
new file mode 100644
index 000000000..7810e100a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/scene_manager_test.cc
@@ -0,0 +1,202 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/scene_manager.h"
+
+#include <functional>
+#include <random>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "Eigen/Core"
+#include "geometrical_acoustics/acoustic_listener.h"
+#include "geometrical_acoustics/acoustic_ray.h"
+#include "geometrical_acoustics/reflection_kernel.h"
+#include "geometrical_acoustics/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+using Eigen::Vector3f;
+
+class SceneManagerTest : public testing::Test {
+ public:
+ SceneManagerTest() : random_engine_(0), distribution_(0.0f, 1.0f) {}
+
+ void SetUp() override {
+ ground_vertices_ = {{0.0f, 0.0f, 0.0f},
+ {0.0f, 1.0f, 0.0f},
+ {1.0f, 0.0f, 0.0f},
+ {1.0f, 1.0f, 0.0f}};
+ ground_triangles_ = {{0, 2, 1}, {1, 2, 3}};
+
+ // Reseed the random number generator for every test to be deterministic
+ // and remove flakiness in tests.
+ random_engine_.seed(0);
+ random_number_generator_ = [this] { return distribution_(random_engine_); };
+ }
+
+ protected:
+ const std::array<float, kNumReverbOctaveBands> kUnitEnergies{
+ {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
+ const std::array<float, kNumReverbOctaveBands> kZeroAbsorptionCoefficients{
+ {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}};
+ std::vector<Vertex> ground_vertices_;
+ std::vector<Triangle> ground_triangles_;
+ SceneManager scene_manager_;
+ std::default_random_engine random_engine_;
+ std::uniform_real_distribution<float> distribution_;
+ std::function<float()> random_number_generator_;
+};
+
+TEST_F(SceneManagerTest, UncommittedSceneTest) {
+ EXPECT_FALSE(scene_manager_.is_scene_committed());
+ EXPECT_FALSE(scene_manager_.is_listener_scene_committed());
+}
+
+TEST_F(SceneManagerTest, BuildEmptySceneTest) {
+ scene_manager_.BuildScene({}, {});
+ EXPECT_TRUE(scene_manager_.is_scene_committed());
+ EXPECT_EQ(scene_manager_.num_vertices(), 0U);
+ EXPECT_EQ(scene_manager_.num_triangles(), 0U);
+}
+
+TEST_F(SceneManagerTest, BuildSceneWithTwoTrianglesTest) {
+ scene_manager_.BuildScene(ground_vertices_, ground_triangles_);
+ EXPECT_TRUE(scene_manager_.is_scene_committed());
+ EXPECT_EQ(scene_manager_.num_vertices(), 4U);
+ EXPECT_EQ(scene_manager_.num_triangles(), 2U);
+}
+
+TEST_F(SceneManagerTest, ReturnDefaultReflectionIfNotAssociatedTest) {
+ scene_manager_.BuildScene(ground_vertices_, ground_triangles_);
+
+ // Get a reflection of triangle 0; since nothing has been associated to it,
+ // a default reflection is returned.
+ const ReflectionKernel& reflection =
+ scene_manager_.GetAssociatedReflectionKernel(0);
+
+ // Test that this default reflection absorbs all energy.
+ AcousticRay ray(Vector3f(0.0f, 0.0f, 0.0f).data(),
+ Vector3f(1.0f, 0.0f, 0.0f).data(), 0.0f, 1.0f, kUnitEnergies,
+ AcousticRay::RayType::kSpecular, 0.0f);
+ AcousticRay reflected_ray = reflection.Reflect(ray);
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ EXPECT_FLOAT_EQ(reflected_ray.energies().at(i), 0.0f);
+ }
+}
+
+TEST_F(SceneManagerTest, ReturnFalseAssociatingToNonExistentTriangleTest) {
+ scene_manager_.BuildScene(ground_vertices_, ground_triangles_);
+
+ // A non-absorptive, purely specular reflection.
+ ReflectionKernel reflection(kZeroAbsorptionCoefficients, 0.0f,
+ random_number_generator_);
+
+ // Associate the reflection to triangle 2, which does not exist.
+ EXPECT_FALSE(
+ scene_manager_.AssociateReflectionKernelToTriangles(reflection, {2}));
+}
+
+TEST_F(SceneManagerTest, ReturnAssociatedReflectionsTest) {
+ scene_manager_.BuildScene(ground_vertices_, ground_triangles_);
+
+ // A half-absorptive, purely diffuse reflection.
+ std::array<float, kNumReverbOctaveBands> absorption_coefficients;
+ absorption_coefficients.fill(0.5f);
+ ReflectionKernel reflection_1(absorption_coefficients, 1.0f,
+ random_number_generator_);
+
+ // A non-absorptive, purely specular reflection.
+ ReflectionKernel reflection_2(kZeroAbsorptionCoefficients, 0.0f,
+ random_number_generator_);
+
+ // Associate them to triangle 1 and 0 respectively.
+ EXPECT_TRUE(
+ scene_manager_.AssociateReflectionKernelToTriangles(reflection_1, {1}));
+ EXPECT_TRUE(
+ scene_manager_.AssociateReflectionKernelToTriangles(reflection_2, {0}));
+
+ AcousticRay ray(Vector3f(0.0f, 0.0f, 0.0f).data(),
+ Vector3f(1.0f, 0.0f, 0.0f).data(), 0.0f, 1.0f, kUnitEnergies,
+ AcousticRay::RayType::kSpecular, 0.0f);
+ {
+ // Test that the reflection from triangle 0, which should be |reflection_2|,
+ // absorbs none of the energy and reflects specularly.
+
+ const ReflectionKernel& reflection =
+ scene_manager_.GetAssociatedReflectionKernel(0);
+ AcousticRay reflected_ray = reflection.Reflect(ray);
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ EXPECT_FLOAT_EQ(reflected_ray.energies().at(i), 1.0f);
+ }
+ EXPECT_EQ(reflected_ray.type(), AcousticRay::RayType::kSpecular);
+ }
+ {
+ // Test that the reflection from triangle 1, which should be |reflection_1|,
+ // absorbs half of the energy and reflects diffusely.
+ const ReflectionKernel& reflection =
+ scene_manager_.GetAssociatedReflectionKernel(1);
+ AcousticRay reflected_ray = reflection.Reflect(ray);
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ EXPECT_FLOAT_EQ(reflected_ray.energies().at(i), 0.5f);
+ }
+ EXPECT_EQ(reflected_ray.type(), AcousticRay::RayType::kDiffuse);
+ }
+}
+
+TEST_F(SceneManagerTest, BuildEmptyListenerSceneTest) {
+ const float listener_sphere_radius = 0.1f;
+ scene_manager_.BuildListenerScene({}, listener_sphere_radius);
+ EXPECT_TRUE(scene_manager_.is_listener_scene_committed());
+}
+
+TEST_F(SceneManagerTest, RayIntersectListenerSceneTest) {
+ // Five AcousticListeners, lining up on the x-axis, with positions (i, 0, 0).
+ std::vector<AcousticListener> listeners;
+ const size_t impulse_response_length = 1000;
+ for (size_t i = 0; i < 5; ++i) {
+ const Vector3f listener_position(static_cast<float>(i), 0.0f, 0.0f);
+ listeners.emplace_back(listener_position, impulse_response_length);
+ }
+
+ // Build the scene.
+ const float listener_sphere_radius = 0.1f;
+ scene_manager_.BuildListenerScene(listeners, listener_sphere_radius);
+ EXPECT_TRUE(scene_manager_.is_listener_scene_committed());
+
+ // Shoot 5 rays from (i, -1, 0), all with direction (0, 1, 0). Ray i is
+ // expected to intersect with listener i's sphere.
+ const float direction[3] = {0.0f, 1.0f, 0.0f};
+ for (size_t i = 0; i < 5; ++i) {
+ const float origin[3] = {static_cast<float>(i), -1.0f, 0.0f};
+ AcousticRay ray_i(origin, direction, 0.0f /* t_near */,
+ AcousticRay::kInfinity /* t_far */, kUnitEnergies,
+ AcousticRay::RayType::kDiffuse,
+ 0.0f /* prior_distance */);
+
+ // Verify that |ray_i| intersects with listener i's sphere.
+ EXPECT_TRUE(ray_i.Intersect(scene_manager_.listener_scene()));
+ const unsigned int intersected_sphere_id = ray_i.intersected_geometry_id();
+ EXPECT_EQ(
+ scene_manager_.GetListenerIndexFromSphereId(intersected_sphere_id), i);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere.cc
new file mode 100644
index 000000000..b0f0d141c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere.cc
@@ -0,0 +1,120 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/sphere.h"
+
+#include <cmath>
+#include <utility>
+
+#include "Eigen/Core"
+
+namespace vraudio {
+
+using Eigen::Vector3f;
+
+namespace {
+// Fills intersection data in an RTCRay.
+//
+// @param sphere Sphere that intersects with the ray.
+// @param t0 Ray parameter corresponding to the first intersection point.
+// @param t1 Ray parameter corresponding to the second intersection point.
+// @param ray RTCRay that potentially intersects with |sphere|, whose data
+// fields are to be filled.
+inline void FillRaySphereIntersectionData(const Sphere& sphere, float t0,
+ float t1, RTCRay* ray) {
+ // For convenience we enforce that t0 <= t1.
+ if (t0 > t1) {
+ std::swap(t0, t1);
+ }
+
+ // In our application we only consider "intersecting" if the ray starts and
+ // ends outside the sphere, i.e. only if ray.tnear < t0 and ray.tfar > t1.
+ if ((ray->tnear >= t0) || (ray->tfar <= t1)) {
+ return;
+ }
+
+ // Set intersection-related data.
+ ray->tfar = t0;
+ ray->geomID = sphere.geometry_id;
+
+ // ray.Ng is the normal at the intersection point. For a sphere the normal is
+ // always pointing radially outward, i.e. normal = p - sphere.center, where
+ // p is the intersection point. Of the two intersection points, We use the
+ // first.
+ ray->Ng[0] = ray->org[0] + t0 * ray->dir[0] - sphere.center[0];
+ ray->Ng[1] = ray->org[1] + t0 * ray->dir[1] - sphere.center[1];
+ ray->Ng[2] = ray->org[2] + t0 * ray->dir[2] - sphere.center[2];
+}
+
+} // namespace
+
+void SphereIntersection(const Sphere& sphere, RTCRay* ray) {
+ // The intersection is tested by finding if there exists a point p that is
+ // both on the ray and on the sphere:
+ // - Point on the ray: p = ray.origin + t * ray.direction, where t is a
+ // parameter.
+ // - Point on the sphere: || p - sphere.center || = sphere.radius.
+ //
+ // Solving the above two equations for t leads to solving a quadratic
+ // equation:
+ // at^2 + bt + c = 0,
+ // where
+ // a = || ray.direction, ray.direction ||^2
+ // b = 2 * Dot(ray.direction, ray.origin - sphere.center)
+ // c = || ray.origin - sphere.center ||^2.
+ // The two possible solutions to this quadratic equation are:
+ // t0 = - b - sqrt(b^2 - 4ac) / 2a
+ // t1 = - b + sqrt(b^2 - 4ac) / 2a.
+ // The existence of real solutions can be tested if a discriminant value,
+ // b^2 - 4ac, is greater than 0 (we treat discriminant == 0, which corresponds
+ // to the ray touching the sphere at a single point, as not intersecting).
+
+ // Vector pointing from the sphere's center to the ray's origin, i.e.
+ // (ray.origin - sphere.center) in the above equations.
+ const Vector3f center_ray_origin_vector(ray->org[0] - sphere.center[0],
+ ray->org[1] - sphere.center[1],
+ ray->org[2] - sphere.center[2]);
+ const Vector3f ray_direction(ray->dir);
+ const float a = ray_direction.squaredNorm();
+ const float b = 2.0f * center_ray_origin_vector.dot(ray_direction);
+ const float c =
+ center_ray_origin_vector.squaredNorm() - sphere.radius * sphere.radius;
+ const float discriminant = b * b - 4.0f * a * c;
+
+ // No intersection; do nothing.
+ if (discriminant <= 0.0f) {
+ return;
+ }
+
+ // Solve for t0 and t1. As suggested in "Physically Based Rendering" by Pharr
+ // and Humphreys, directly computing - b +- sqrt(b^2 - 4ac) / 2a gives poor
+ // numeric precision when b is close to +- sqrt(b^2 - 4ac), and a more stable
+ // form is used instead:
+ // t0 = q / a
+ // t1 = c / q,
+ // where
+ // q = -(b - sqrt(b^2 - 4ac)) / 2 for b < 0
+ // -(b + sqrt(b^2 - 4ac)) / 2 otherwise.
+ const float sqrt_discriminant = std::sqrt(discriminant);
+ const float q = (b < 0.0f) ? -0.5f * (b - sqrt_discriminant)
+ : -0.5f * (b + sqrt_discriminant);
+ const float t0 = q / a;
+ const float t1 = c / q;
+
+ FillRaySphereIntersectionData(sphere, t0, t1, ray);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere.h
new file mode 100644
index 000000000..bea49ccde
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere.h
@@ -0,0 +1,69 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SPHERE_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SPHERE_H_
+
+#include "embree2/rtcore.h"
+#include "embree2/rtcore_ray.h"
+
+namespace vraudio {
+
+// A user defined sphere geometry that enables Embree to test ray intersections.
+struct RTCORE_ALIGN(16) Sphere {
+ // Center of the sphere.
+ float center[3];
+
+ // Radius of the sphere.
+ float radius;
+
+ // Geometry Id. This will be reported by ray intersections.
+ unsigned int geometry_id;
+};
+
+// The following functions are to be called by Embree internally to enable fast
+// ray-sphere intersections tests.
+
+// Calculates the RTCBounds (essentially a bounding box) of a given sphere.
+//
+// @param sphere Sphere of interest.
+// @param output_bounds Output RTCBounds of the sphere.
+inline void SphereBounds(const Sphere& sphere, RTCBounds* output_bounds) {
+ output_bounds->lower_x = sphere.center[0] - sphere.radius;
+ output_bounds->lower_y = sphere.center[1] - sphere.radius;
+ output_bounds->lower_z = sphere.center[2] - sphere.radius;
+ output_bounds->upper_x = sphere.center[0] + sphere.radius;
+ output_bounds->upper_y = sphere.center[1] + sphere.radius;
+ output_bounds->upper_z = sphere.center[2] + sphere.radius;
+}
+
+// Tests whether a sphere and a ray intersects and sets the related data for
+// the ray when an intersection is found:
+// - |ray.tfar| will be set to corresponding to the first intersection point.
+// - |ray.geomID| will be set to the geometry id of the sphere.
+// - |ray.Ng| will be set to the normal at the first intersection point,
+// pointing radially outward
+//
+// Because this function will be called internally by Embree, it works on
+// Embree's native type RTCRay as opposed to AcousticRay.
+//
+// @param spheres Sphere of interest.
+// @param ray RTCRay with which intersections are tested and related data set.
+void SphereIntersection(const Sphere& sphere, RTCRay* ray);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SPHERE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere_test.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere_test.cc
new file mode 100644
index 000000000..d0daea12e
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/sphere_test.cc
@@ -0,0 +1,267 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/sphere.h"
+
+#include <cmath>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/aligned_allocator.h"
+#include "base/logging.h"
+#include "geometrical_acoustics/acoustic_ray.h"
+#include "geometrical_acoustics/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+// A function adapter from SphereBounds() to RTCBoundsFunc in order to be
+// passed to rtcSetBoundsFunction().
+// The signature of RTCBoundsFunc does not comply with Google's C++ style,
+
+static void EmbreeSphereBoundsFunction(void* user_data, size_t index,
+ RTCBounds& output_bounds
+ ) {
+ Sphere* spheres = static_cast<Sphere*>(user_data);
+ const Sphere& sphere = spheres[index];
+ SphereBounds(sphere, &output_bounds);
+}
+
+// A function adapter from SphereIntersections() to RTCIntersectFunc in order
+// to be passed to rtcSetIntersectFunction().
+// The signature of RTCIntersectFunc does not comply with Google's C++ style,
+
+static void EmbreeSphereIntersectFunction(void* user_data,
+ RTCRay& ray,
+ size_t index) {
+ Sphere* spheres = static_cast<Sphere*>(user_data);
+ const Sphere& sphere = spheres[index];
+ SphereIntersection(sphere, &ray);
+}
+
+void SetSphereData(const float center[3], float radius,
+ unsigned int geometry_id, Sphere* sphere) {
+ sphere->center[0] = center[0];
+ sphere->center[1] = center[1];
+ sphere->center[2] = center[2];
+ sphere->radius = radius;
+ sphere->geometry_id = geometry_id;
+}
+
+TEST(Sphere, SphereBoundsTest) {
+ const float center[3] = {1.0f, 2.0f, 3.0f};
+ const float radius = 3.0f;
+ Sphere sphere;
+ SetSphereData(center, radius, 0u, &sphere);
+
+ RTCBounds bounds;
+ SphereBounds(sphere, &bounds);
+ EXPECT_FLOAT_EQ(bounds.lower_x, -2.0f);
+ EXPECT_FLOAT_EQ(bounds.lower_y, -1.0f);
+ EXPECT_FLOAT_EQ(bounds.lower_z, 0.0f);
+ EXPECT_FLOAT_EQ(bounds.upper_x, 4.0f);
+ EXPECT_FLOAT_EQ(bounds.upper_y, 5.0f);
+ EXPECT_FLOAT_EQ(bounds.upper_z, 6.0f);
+}
+
+TEST(Sphere, RayIntersectSphereTest) {
+ const float center[3] = {0.0f, 0.0f, 0.0f};
+ const float radius = 1.0f;
+ const unsigned sphere_geometry_id = 1u;
+ Sphere sphere;
+ SetSphereData(center, radius, sphere_geometry_id, &sphere);
+
+ // This ray passes through the sphere.
+ const float origin[3] = {0.5f, 0.0f, -2.0f};
+ const float direction[3] = {0.0f, 0.0f, 1.0f};
+ AcousticRay ray(origin, direction, 0.0f, AcousticRay::kInfinity, {},
+ AcousticRay::RayType::kSpecular, 0.0f);
+
+ SphereIntersection(sphere, &ray);
+
+ // Expect an intersection, so that ray.intersected_geometry_id() returns
+ // |sphere_geometry_id|.
+ EXPECT_EQ(ray.intersected_geometry_id(), sphere_geometry_id);
+
+ // Expect that the intersection point is at (0.5, 0, -sqrt(3)/2).
+ const float expected_intersection_point[3] = {0.5f, 0.0f,
+ -0.5f * kSqrtThree};
+ float intersection_point[3];
+ intersection_point[0] = ray.origin()[0] + ray.t_far() * ray.direction()[0];
+ intersection_point[1] = ray.origin()[1] + ray.t_far() * ray.direction()[1];
+ intersection_point[2] = ray.origin()[2] + ray.t_far() * ray.direction()[2];
+ ExpectFloat3Close(intersection_point, expected_intersection_point);
+
+ // Expect that the normal at the intersection point is (0.5, 0, -sqrt(3)/2).
+ const float expected_normal[3] = {0.5f, 0.0f, -0.5f * kSqrtThree};
+ ExpectFloat3Close(ray.intersected_geometry_normal(), expected_normal);
+}
+
+TEST(Sphere, RayOutsideSphereNotIntersectTest) {
+ const float center[3] = {0.0f, 0.0f, 0.0f};
+ const float radius = 1.0f;
+ Sphere sphere;
+ SetSphereData(center, radius, 1u, &sphere);
+
+ // This ray completely lies outside of the sphere.
+ const float origin[3] = {2.0f, 2.0f, 2.0f};
+ const float direction[3] = {0.0f, 0.0f, 1.0f};
+ AcousticRay ray(origin, direction, 0.0f, AcousticRay::kInfinity, {},
+ AcousticRay::RayType::kSpecular, 0.0f);
+
+ SphereIntersection(sphere, &ray);
+
+ // Expect no intersection, i.e. so that ray.intersected_geometry_id() returns
+ // RTC_INVALID_GEOMETRY_ID.
+ EXPECT_EQ(ray.intersected_geometry_id(), RTC_INVALID_GEOMETRY_ID);
+}
+
+TEST(Sphere, RayStartingInsideSphereNotIntersectTest) {
+ const float center[3] = {0.0f, 0.0f, 0.0f};
+ const float radius = 1.0f;
+ Sphere sphere;
+ SetSphereData(center, radius, 1u, &sphere);
+
+ // This ray theoretically intersects with the sphere, but as its starting
+ // point is inside the sphere, our intersection test regards it as
+ // non-intersecting.
+ const float origin[3] = {0.5f, 0.5f, 0.0f};
+ const float direction[3] = {0.0f, 0.0f, 1.0f};
+ AcousticRay ray(origin, direction, 0.0f, AcousticRay::kInfinity, {},
+ AcousticRay::RayType::kSpecular, 0.0f);
+
+ SphereIntersection(sphere, &ray);
+
+ // Expect no intersection, i.e. so that ray.intersected_geometry_id() returns
+ // RTC_INVALID_GEOMETRY_ID.
+ EXPECT_EQ(ray.intersected_geometry_id(), RTC_INVALID_GEOMETRY_ID);
+}
+
+TEST(Sphere, RayEndingInsideSphereNotIntersectTest) {
+ const float center[3] = {0.0f, 0.0f, 0.0f};
+ const float radius = 1.0f;
+ Sphere sphere;
+ SetSphereData(center, radius, 1u, &sphere);
+
+ // This ray theoretically intersects with the sphere, but as its end point
+ // (controlled by |ray.tfar| is inside the sphere, our intersection test
+ // regards it as non-intersecting.
+ const float origin[3] = {0.5f, 0.0f, -2.0f};
+ const float direction[3] = {0.0f, 0.0f, 1.0f};
+ AcousticRay ray(origin, direction, 0.0f, 2.0f, {},
+ AcousticRay::RayType::kSpecular, 0.0f);
+
+ SphereIntersection(sphere, &ray);
+
+ // Expect no intersection, i.e. so that ray.intersected_geometry_id() returns
+ // RTC_INVALID_GEOMETRY_ID.
+ EXPECT_EQ(ray.intersected_geometry_id(), RTC_INVALID_GEOMETRY_ID);
+}
+
+// The following test fixture and tests mimic real use cases of ray-sphere
+// intersections in our acoustics computation:
+//
+// 1) A sphere is constructed.
+// 2) The sphere is registered to the scene as user data. Two callback
+// functions of types RTCBoundsFunc and RTCIntersectFunc are registered
+// to the scene as well.
+// 2) An AcousticRay is constructed.
+// 3) The intersection is found by AcousticRay.Intersect().
+//
+// This is different from previous tests in that we do not directly invoke
+// SphereBounds() and SphereIntersection(); Embree does it for us.
+
+class SphereTest : public testing::Test {
+ protected:
+ void SetUp() override {
+ // Use a single RTCDevice for all tests.
+ static RTCDevice device = rtcNewDevice(nullptr);
+ CHECK_NOTNULL(device);
+ scene_ = rtcDeviceNewScene(
+ device, RTC_SCENE_STATIC | RTC_SCENE_HIGH_QUALITY, RTC_INTERSECT1);
+ }
+
+ void TearDown() override { rtcDeleteScene(scene_); }
+
+ unsigned int AddSphereToScene() {
+ const unsigned int geometry_id = rtcNewUserGeometry(scene_, 1);
+
+ const float center[3] = {0.0f, 0.0f, 0.0f};
+ const float radius = 1.0f;
+ Sphere* const sphere =
+ AllignedMalloc<Sphere, size_t, Sphere*>(sizeof(Sphere),
+ /*alignment=*/64);
+
+ SetSphereData(center, radius, geometry_id, sphere);
+
+ // rtcSetUserData() takes ownership of |sphere|.
+ rtcSetUserData(scene_, geometry_id, sphere);
+ rtcSetBoundsFunction(scene_, geometry_id, &EmbreeSphereBoundsFunction);
+ rtcSetIntersectFunction(scene_, geometry_id,
+ &EmbreeSphereIntersectFunction);
+ return geometry_id;
+ }
+
+ const std::array<float, kNumReverbOctaveBands> kUnitEnergies{
+ {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
+ RTCScene scene_ = nullptr;
+};
+
+TEST_F(SphereTest, AcousticRayIntersectSphereTest) {
+ const unsigned int sphere_geometry_id = AddSphereToScene();
+ rtcCommit(scene_);
+
+ // Construct an AcousticRay that passes through the sphere.
+ const float origin[3] = {0.5f, 0.0f, -2.0f};
+ const float direction[3] = {0.0f, 0.0f, 1.0f};
+ AcousticRay ray(origin, direction, 0.0f, AcousticRay::kInfinity,
+ kUnitEnergies, AcousticRay::RayType::kSpecular, 0.0f);
+
+ // Expect intersection happens and the intersected geometry id set to
+ // |sphere_geometry_id|.
+ EXPECT_TRUE(ray.Intersect(scene_));
+ EXPECT_EQ(ray.intersected_geometry_id(), sphere_geometry_id);
+
+ // Expect that the intersection point is at (0.5, 0, -sqrt(3)/2).
+ const float expected_intersection_point[3] = {0.5f, 0.0f,
+ -0.5f * kSqrtThree};
+ float intersection_point[3];
+ intersection_point[0] = ray.origin()[0] + ray.t_far() * ray.direction()[0];
+ intersection_point[1] = ray.origin()[1] + ray.t_far() * ray.direction()[1];
+ intersection_point[2] = ray.origin()[2] + ray.t_far() * ray.direction()[2];
+ ExpectFloat3Close(intersection_point, expected_intersection_point);
+
+ // Expect that the normal at the intersection point is (0.5, 0, -sqrt(3)/2).
+ const float expected_normal[3] = {0.5f, 0.0f, -0.5f * kSqrtThree};
+ ExpectFloat3Close(ray.intersected_geometry_normal(), expected_normal);
+}
+
+TEST_F(SphereTest, AcousticRayIntersectNothingTest) {
+ rtcCommit(scene_);
+
+ // Construct an AcousticRay completely outside of the sphere.
+ const float origin[3] = {2.0f, 2.0f, 2.0f};
+ const float direction[3] = {0.0f, 0.0f, 1.0f};
+ AcousticRay ray(origin, direction, 0.0f, AcousticRay::kInfinity,
+ kUnitEnergies, AcousticRay::RayType::kSpecular, 0.0f);
+
+ // Expect no intersection.
+ EXPECT_FALSE(ray.Intersect(scene_));
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/test_util.cc b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/test_util.cc
new file mode 100644
index 000000000..b407f6f07
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/test_util.cc
@@ -0,0 +1,231 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "geometrical_acoustics/test_util.h"
+
+#include <algorithm>
+#include <random>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/logging.h"
+#include "geometrical_acoustics/path_tracer.h"
+
+namespace vraudio {
+
+namespace {
+// Given N bins each having some count, validates that the counts are almost the
+// same across all bins.
+void ValidateUniformDistribution(const std::vector<int>& count_in_bins,
+ const int total_count) {
+ const float expected_fraction =
+ 1.0f / static_cast<float>(count_in_bins.size());
+ const float tolerance = static_cast<float>(count_in_bins.size()) /
+ static_cast<float>(total_count);
+ for (const int count : count_in_bins) {
+ const float actual_fraction =
+ static_cast<float>(count) / static_cast<float>(total_count);
+ const float error = actual_fraction - expected_fraction;
+ const float chi_square = error * error / expected_fraction;
+ EXPECT_NEAR(chi_square, 0.0f, tolerance);
+ }
+}
+
+// Assigns surface materials to groups of triangles, one material to one group.
+void AssignSurfaceMaterialsToTriangleGroups(
+ const std::vector<std::unordered_set<unsigned int>>& triangle_groups,
+ const std::vector<MaterialName>& materials,
+ const std::function<float()>& random_number_generator,
+ SceneManager* scene_manager) {
+ CHECK_EQ(triangle_groups.size(), materials.size());
+
+ const float scattering_coefficient = 1.0f;
+ std::array<float, kNumReverbOctaveBands> absorption_coefficients;
+ for (size_t group = 0; group < materials.size(); ++group) {
+ const size_t material_index = static_cast<size_t>(materials[group]);
+ const RoomMaterial& room_material = GetRoomMaterial(material_index);
+ for (size_t band = 0; band < kNumReverbOctaveBands; ++band) {
+ absorption_coefficients[band] =
+ room_material.absorption_coefficients[band];
+ }
+ ReflectionKernel reflection_kernel(absorption_coefficients,
+ scattering_coefficient,
+ random_number_generator);
+ scene_manager->AssociateReflectionKernelToTriangles(reflection_kernel,
+ triangle_groups[group]);
+ }
+}
+
+} // namespace
+
+void ValidateDistribution(const int num_samples, const int num_bins,
+ std::function<float()> cdf) {
+ DCHECK_GT(num_bins, 0);
+ std::vector<int> cdf_bins(num_bins, 0);
+ for (int i = 0; i < num_samples; ++i) {
+ const float cdf_value = cdf();
+ const int cdf_bin_index = std::min(
+ num_bins - 1, std::max(0, static_cast<int>(cdf_value * num_bins)));
+ ++cdf_bins[cdf_bin_index];
+ }
+ ValidateUniformDistribution(cdf_bins, num_samples);
+}
+
+void AddTestGround(RTCScene scene) {
+ unsigned int mesh_id = rtcNewTriangleMesh(scene, RTC_GEOMETRY_STATIC, 2, 4);
+
+ // Vertices. Each vertex has 4 floats: x, y, z, and a padding float whose
+ // value we do not care.
+ float ground_vertices[] = {
+ 0.0f, 0.0f, 0.0f, 0.0f, // Vertex_0.
+ 0.0f, 1.0f, 0.0f, 0.0f, // Vertex_1.
+ 1.0f, 0.0f, 0.0f, 0.0f, // Vertex_2.
+ 1.0f, 1.0f, 0.0f, 0.0f, // Vertex_3.
+ };
+
+ // Triangles. Somehow Embree is a left-handed system.
+ int ground_indices[] = {
+ 0, 1, 2, // Triangle_0.
+ 1, 3, 2, // Triangle_1.
+ };
+ float* const embree_vertices =
+ static_cast<float*>(rtcMapBuffer(scene, mesh_id, RTC_VERTEX_BUFFER));
+ std::copy(ground_vertices, ground_vertices + 16, embree_vertices);
+ rtcUnmapBuffer(scene, mesh_id, RTC_VERTEX_BUFFER);
+ int* const embree_indices =
+ static_cast<int*>(rtcMapBuffer(scene, mesh_id, RTC_INDEX_BUFFER));
+ std::copy(ground_indices, ground_indices + 6, embree_indices);
+ rtcUnmapBuffer(scene, mesh_id, RTC_INDEX_BUFFER);
+}
+
+void BuildTestBoxScene(
+ const Vertex& min_corner, const Vertex& max_corner,
+ std::vector<Vertex>* box_vertices, std::vector<Triangle>* box_triangles,
+ std::vector<std::unordered_set<unsigned int>>* box_wall_triangles) {
+ const float min_x = min_corner.x;
+ const float min_y = min_corner.y;
+ const float min_z = min_corner.z;
+ const float max_x = max_corner.x;
+ const float max_y = max_corner.y;
+ const float max_z = max_corner.z;
+ CHECK_LT(min_x, max_x);
+ CHECK_LT(min_y, max_y);
+ CHECK_LT(min_z, max_z);
+
+ if (box_vertices != nullptr) {
+ *box_vertices = std::vector<Vertex>{
+ {min_x, min_y, min_z}, {min_x, max_y, min_z}, {max_x, min_y, min_z},
+ {max_x, max_y, min_z}, {min_x, min_y, max_z}, {min_x, max_y, max_z},
+ {max_x, min_y, max_z}, {max_x, max_y, max_z}};
+ }
+ if (box_vertices != nullptr) {
+ *box_triangles = std::vector<Triangle>{
+ {0, 1, 4}, {1, 5, 4}, // wall facing the -x direction.
+ {2, 6, 3}, {3, 6, 7}, // wall facing the +x direction.
+ {0, 6, 2}, {0, 4, 6}, // wall facing the -y direction.
+ {1, 3, 7}, {1, 7, 5}, // wall facing the +y direction.
+ {0, 3, 1}, {0, 2, 3}, // wall facing the -z direction.
+ {4, 7, 6}, {4, 5, 7}, // wall facing the +z direction.
+ };
+ }
+ if (box_wall_triangles != nullptr) {
+ *box_wall_triangles = std::vector<std::unordered_set<unsigned int>>{
+ {0, 1}, {2, 3}, {4, 5}, {6, 7}, {8, 9}, {10, 11}};
+ }
+}
+
+std::vector<Path> TracePathsInTestcene(
+ size_t min_num_rays, size_t max_depth, float energy_threshold,
+ const float source_position[3], const std::vector<Vertex>& scene_vertices,
+ const std::vector<Triangle>& scene_triangles,
+ const std::vector<std::unordered_set<unsigned int>>& scene_triangle_groups,
+ const std::vector<MaterialName>& materials, SceneManager* scene_manager) {
+ // Build the scene.
+ scene_manager->BuildScene(scene_vertices, scene_triangles);
+
+ // Assign materials.
+ std::default_random_engine engine(0);
+ std::uniform_real_distribution<float> distribution(0.0f, 1.0f);
+ std::function<float()> random_number_generator = [&engine, &distribution] {
+ return distribution(engine);
+ };
+ AssignSurfaceMaterialsToTriangleGroups(
+ scene_triangle_groups, materials, random_number_generator, scene_manager);
+
+ // Trace paths.
+ AcousticSource source(Eigen::Vector3f(source_position), kUnitEnergies,
+ random_number_generator);
+ PathTracer path_tracer(*scene_manager);
+ return path_tracer.TracePaths(source, min_num_rays, max_depth,
+ energy_threshold);
+}
+
+std::vector<Path> GenerateUniformlyDistributedRayPaths(
+ const float source_position[3], size_t min_num_rays) {
+ // Use AcousticSource to generate rays in uniformly distributed directions.
+ std::default_random_engine engine(0);
+ std::uniform_real_distribution<float> distribution(0.0f, 1.0f);
+ AcousticSource source(
+ Eigen::Vector3f(source_position), kUnitEnergies,
+ [&engine, &distribution] { return distribution(engine); });
+
+ const size_t sqrt_num_rays = static_cast<size_t>(
+ std::ceil(std::sqrt(static_cast<float>(min_num_rays))));
+ const size_t num_rays = sqrt_num_rays * sqrt_num_rays;
+ std::vector<Path> paths(num_rays);
+ const std::vector<AcousticRay>& rays =
+ source.GenerateStratifiedRays(num_rays, sqrt_num_rays);
+ for (size_t i = 0; i < num_rays; ++i) {
+ Path path;
+ path.rays.push_back(rays[i]);
+ paths[i] = path;
+ }
+
+ return paths;
+}
+
+void ExpectFloat3Close(const float actual_vector[3],
+ const float expected_vector[3]) {
+ EXPECT_FLOAT_EQ(actual_vector[0], expected_vector[0]);
+ EXPECT_FLOAT_EQ(actual_vector[1], expected_vector[1]);
+ EXPECT_FLOAT_EQ(actual_vector[2], expected_vector[2]);
+}
+
+void ExpectFloat3Close(const float actual_vector[3],
+ const float expected_vector[3], float tolerance) {
+ EXPECT_NEAR(actual_vector[0], expected_vector[0], tolerance);
+ EXPECT_NEAR(actual_vector[1], expected_vector[1], tolerance);
+ EXPECT_NEAR(actual_vector[2], expected_vector[2], tolerance);
+}
+
+void ValidateSparseFloatArray(const std::vector<float>& actual_array,
+ const std::vector<size_t>& expected_indices,
+ const std::vector<float>& expected_values,
+ float relative_error_tolerance) {
+ // First construct the expected array.
+ std::vector<float> expected_array(actual_array.size(), 0.0f);
+ for (size_t i = 0; i < expected_indices.size(); ++i) {
+ expected_array[expected_indices[i]] = expected_values[i];
+ }
+
+ // Compare with the actual array element-by-element.
+ for (size_t i = 0; i < actual_array.size(); ++i) {
+ EXPECT_NEAR(actual_array[i], expected_array[i],
+ expected_array[i] * relative_error_tolerance);
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/test_util.h b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/test_util.h
new file mode 100644
index 000000000..8d9382b35
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/geometrical_acoustics/test_util.h
@@ -0,0 +1,131 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Utilities useful for testing Geometrical Acoustics related classes.
+#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_TEST_UTIL_H_
+#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_TEST_UTIL_H_
+
+#include <cstddef>
+#include <functional>
+#include <unordered_set>
+#include <vector>
+
+#include "embree2/rtcore.h"
+#include "api/resonance_audio_api.h"
+#include "base/constants_and_types.h"
+#include "geometrical_acoustics/mesh.h"
+#include "geometrical_acoustics/path.h"
+#include "geometrical_acoustics/scene_manager.h"
+#include "platforms/common/room_effects_utils.h"
+
+namespace vraudio {
+
+// Array of |kNumReverbOctaveBands| of unit energies. Useful to set as initial
+// energies of sound sources in tests.
+static const std::array<float, kNumReverbOctaveBands> kUnitEnergies{
+ {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
+
+// Validates a distribution given the cumulative distribution function (CDF).
+// For any probability density function (PDF), its CDF should be uniformly
+// distributed. So we generate some samples, gather them into bins based on
+// their CDF values, and verify that the number of samples are almost the
+// same across all bins.
+//
+// @param num_samples Number of samples to generate.
+// @param num_bins Number of bins to gather the samples.
+// @param cdf Cumulative distribution function of the distribution to test.
+void ValidateDistribution(const int num_samples, const int num_bins,
+ std::function<float()> cdf);
+
+// Adds a ground (a rectangle consisting of two triangles) to a test scene.
+//
+// @param scene Test scene to which the ground is added.
+void AddTestGround(RTCScene scene);
+
+// Builds a box scene with 8 vertices, 12 triangles, and 6 walls.
+//
+// @param min_corner Corner of the box with minimum x-, y-, z-components.
+// @param max_corner Corner of the box with maximum x-, y-, z-components.
+// @param box_vertices Output vertices of the box. Not filled if nullptr is
+// passed in.
+// @param box_triangles Output triangles of the box. Not filled if nullptr is
+// passed in.
+// @param box_wall_triangles Output wall-to-triangles mapping, with six walls
+// each having two triangles. Not filled if nullptr is passed in.
+void BuildTestBoxScene(
+ const Vertex& min_corner, const Vertex& max_corner,
+ std::vector<Vertex>* box_vertices, std::vector<Triangle>* box_triangles,
+ std::vector<std::unordered_set<unsigned int>>* box_wall_triangles);
+
+// Traces ray paths in a created test scene.
+//
+// @param num_rays Number of rays.
+// @param max_depth Maximum depth of tracing performed along a path.
+// @param energy_threshold Energy threshold below which the tracing stops.
+// @param source_position Position from which to shoot rays.
+// @param scene_vertices Vertices of the scene.
+// @param scene_triangles Triangles of the scene.
+// @param scene_triangle_groups Groups of triangles that share the same
+// material.
+// @param materials Materials for each triangle group.
+// @param scene_manager Scene manager that holds the created test scene.
+// @return Vector of traced paths.
+std::vector<Path> TracePathsInTestcene(
+ size_t num_rays, size_t max_depth, float energy_threshold,
+ const float source_position[3], const std::vector<Vertex>& scene_vertices,
+ const std::vector<Triangle>& scene_triangles,
+ const std::vector<std::unordered_set<unsigned int>>& scene_triangle_groups,
+ const std::vector<MaterialName>& materials, SceneManager* scene_manager);
+
+// Generated ray paths in uniformly distributed directions.
+//
+// @param source_position Position from which to shoot rays.
+// @param min_num_rays Minimum number of rays generated.
+// @return Vector of traced paths.
+std::vector<Path> GenerateUniformlyDistributedRayPaths(
+ const float source_position[3], size_t min_num_rays);
+
+// Compares two float vectors[3]s and expect that their components are close.
+//
+// @param actual_vector Actual vector.
+// @param expected_vector Expected vector.
+void ExpectFloat3Close(const float actual_vector[3],
+ const float expected_vector[3]);
+
+// Same as above but with a user-specified tolerance.
+//
+// @param actual_vector Actual vector.
+// @param expected_vector Expected vector.
+// @param tolerance Tolerance for comparisons.
+void ExpectFloat3Close(const float actual_vector[3],
+ const float expected_vector[3], float tolerance);
+
+// Validates a sparse float array using the indices and values of its
+// non-zero elements.
+//
+// @param actual_array Actual array to be validated.
+// @param expected_indices Indices of the non-zero elements of the expected
+// array.
+// @param expected_values Values of the non-zero elements of the expected array.
+// @param relative_error_tolerance Tolerance of relative errors for element
+// comparisons.
+void ValidateSparseFloatArray(const std::vector<float>& actual_array,
+ const std::vector<size_t>& expected_indices,
+ const std::vector<float>& expected_values,
+ float relative_error_tolerance);
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_TEST_UTIL_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_binaural_decoder_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_binaural_decoder_node.cc
new file mode 100644
index 000000000..a3c8ff0cb
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_binaural_decoder_node.cc
@@ -0,0 +1,111 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/ambisonic_binaural_decoder_node.h"
+
+#include "ambisonics/stereo_from_soundfield_converter.h"
+#include "ambisonics/utils.h"
+#include "base/constants_and_types.h"
+
+#include "dsp/sh_hrir_creator.h"
+
+namespace vraudio {
+
+AmbisonicBinauralDecoderNode::AmbisonicBinauralDecoderNode(
+ const SystemSettings& system_settings, int ambisonic_order,
+ const std::string& sh_hrir_filename, FftManager* fft_manager,
+ Resampler* resampler)
+ : system_settings_(system_settings),
+ num_ambisonic_channels_(GetNumPeriphonicComponents(ambisonic_order)),
+ is_stereo_speaker_mode_(system_settings_.IsStereoSpeakerModeEnabled()),
+ num_frames_processed_on_empty_input_(
+ system_settings_.GetFramesPerBuffer()),
+ stereo_output_buffer_(kNumStereoChannels,
+ system_settings.GetFramesPerBuffer()),
+ silence_input_buffer_(num_ambisonic_channels_,
+ system_settings.GetFramesPerBuffer()),
+ crossfader_(system_settings_.GetFramesPerBuffer()),
+ crossfaded_output_buffer_(kNumStereoChannels,
+ system_settings.GetFramesPerBuffer()),
+ temp_crossfade_buffer_(kNumStereoChannels,
+ system_settings.GetFramesPerBuffer()) {
+ silence_input_buffer_.Clear();
+ EnableProcessOnEmptyInput(true);
+ std::unique_ptr<AudioBuffer> sh_hrirs = CreateShHrirsFromAssets(
+ sh_hrir_filename, system_settings_.GetSampleRateHz(), resampler);
+ CHECK_EQ(sh_hrirs->num_channels(), num_ambisonic_channels_);
+ ambisonic_binaural_decoder_.reset(new AmbisonicBinauralDecoder(
+ *sh_hrirs, system_settings_.GetFramesPerBuffer(), fft_manager));
+}
+
+AmbisonicBinauralDecoderNode::~AmbisonicBinauralDecoderNode() {}
+
+const AudioBuffer* AmbisonicBinauralDecoderNode::AudioProcess(
+ const NodeInput& input) {
+
+
+ const bool was_stereo_speaker_mode_enabled = is_stereo_speaker_mode_;
+ is_stereo_speaker_mode_ = system_settings_.IsStereoSpeakerModeEnabled();
+
+ const size_t num_frames = system_settings_.GetFramesPerBuffer();
+ const AudioBuffer* input_buffer = input.GetSingleInput();
+ if (input_buffer == nullptr) {
+ if (num_frames_processed_on_empty_input_ < num_frames &&
+ !was_stereo_speaker_mode_enabled) {
+ // If we have no input, generate a silent input buffer until the node
+ // states are cleared.
+ num_frames_processed_on_empty_input_ += num_frames;
+ ambisonic_binaural_decoder_->Process(silence_input_buffer_,
+ &stereo_output_buffer_);
+ return &stereo_output_buffer_;
+ } else {
+ // Skip processing entirely when the states are fully cleared.
+ return nullptr;
+ }
+ }
+
+ num_frames_processed_on_empty_input_ = 0;
+
+ DCHECK_EQ(input_buffer->num_channels(), num_ambisonic_channels_);
+ DCHECK_EQ(input_buffer->num_frames(), num_frames);
+
+ // If stereo speaker mode is enabled, perform M-S stereo decode. Otherwise,
+ // perform binaural decode.
+ if (is_stereo_speaker_mode_) {
+ StereoFromSoundfield(*input_buffer, &stereo_output_buffer_);
+ } else {
+ ambisonic_binaural_decoder_->Process(*input_buffer, &stereo_output_buffer_);
+ }
+
+ if (is_stereo_speaker_mode_ != was_stereo_speaker_mode_enabled) {
+ // Apply linear crossfade between binaural decode and stereo decode outputs.
+ if (was_stereo_speaker_mode_enabled) {
+ StereoFromSoundfield(*input_buffer, &temp_crossfade_buffer_);
+ } else {
+ ambisonic_binaural_decoder_->Process(*input_buffer,
+ &temp_crossfade_buffer_);
+ }
+ crossfader_.ApplyLinearCrossfade(stereo_output_buffer_,
+ temp_crossfade_buffer_,
+ &crossfaded_output_buffer_);
+ return &crossfaded_output_buffer_;
+ }
+
+ // Return the rendered output directly.
+ return &stereo_output_buffer_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_binaural_decoder_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_binaural_decoder_node.h
new file mode 100644
index 000000000..548d44e01
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_binaural_decoder_node.h
@@ -0,0 +1,88 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_AMBISONIC_BINAURAL_DECODER_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_AMBISONIC_BINAURAL_DECODER_NODE_H_
+
+#include <memory>
+#include <string>
+
+#include "ambisonics/ambisonic_binaural_decoder.h"
+#include "base/audio_buffer.h"
+#include "dsp/fft_manager.h"
+#include "dsp/resampler.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+#include "utils/buffer_crossfader.h"
+
+namespace vraudio {
+
+// Node that takes an ambisonic soundfield as input and renders a binaural
+// stereo buffer as output.
+class AmbisonicBinauralDecoderNode : public ProcessingNode {
+ public:
+ // Initializes AmbisonicBinauralDecoderNode class.
+ //
+ // @param system_settings Global system configuration.
+ // @param ambisonic_order Ambisonic order.
+ // @param sh_hrir_filename Filename to load the HRIR data from.
+ // @param fft_manager Pointer to a manager to perform FFT transformations.
+ // @resampler Pointer to a resampler used to convert HRIRs to the system rate.
+ AmbisonicBinauralDecoderNode(const SystemSettings& system_settings,
+ int ambisonic_order,
+ const std::string& sh_hrir_filename,
+ FftManager* fft_manager, Resampler* resampler);
+
+ ~AmbisonicBinauralDecoderNode() override;
+
+ protected:
+ // Implements ProcessingNode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ const SystemSettings& system_settings_;
+
+ // Number of Ambisonic channels.
+ const size_t num_ambisonic_channels_;
+
+ // Denotes if the stereo speaker mode is enabled.
+ bool is_stereo_speaker_mode_;
+
+ // Ambisonic decoder used to render binaural output.
+ std::unique_ptr<AmbisonicBinauralDecoder> ambisonic_binaural_decoder_;
+
+ size_t num_frames_processed_on_empty_input_;
+
+ // Stereo output buffer.
+ AudioBuffer stereo_output_buffer_;
+
+ // Silence mono buffer to render reverb tails.
+ AudioBuffer silence_input_buffer_;
+
+ // Buffer crossfader to apply linear crossfade when the stereo speaker mode is
+ // changed.
+ BufferCrossfader crossfader_;
+
+ // Stereo output buffer to store the crossfaded decode output when necessary.
+ AudioBuffer crossfaded_output_buffer_;
+
+ // Temporary crossfade buffer to store the intermediate stereo output.
+ AudioBuffer temp_crossfade_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_AMBISONIC_BINAURAL_DECODER_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node.cc
new file mode 100644
index 000000000..88405464c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node.cc
@@ -0,0 +1,69 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/ambisonic_mixing_encoder_node.h"
+
+#include "ambisonics/utils.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+
+
+namespace vraudio {
+
+AmbisonicMixingEncoderNode::AmbisonicMixingEncoderNode(
+ const SystemSettings& system_settings,
+ const AmbisonicLookupTable& lookup_table, int ambisonic_order)
+ : system_settings_(system_settings),
+ lookup_table_(lookup_table),
+ ambisonic_order_(ambisonic_order),
+ gain_mixer_(GetNumPeriphonicComponents(ambisonic_order_),
+ system_settings_.GetFramesPerBuffer()),
+ coefficients_(GetNumPeriphonicComponents(ambisonic_order_)) {}
+
+const AudioBuffer* AmbisonicMixingEncoderNode::AudioProcess(
+ const NodeInput& input) {
+
+
+ const WorldPosition& listener_position = system_settings_.GetHeadPosition();
+ const WorldRotation& listener_rotation = system_settings_.GetHeadRotation();
+
+ gain_mixer_.Reset();
+ for (auto& input_buffer : input.GetInputBuffers()) {
+ const int source_id = input_buffer->source_id();
+ const auto source_parameters =
+ system_settings_.GetSourceParameters(source_id);
+ DCHECK_NE(source_id, kInvalidSourceId);
+ DCHECK_EQ(input_buffer->num_channels(), 1U);
+
+ // Compute the relative source direction in spherical angles.
+ const ObjectTransform& source_transform =
+ source_parameters->object_transform;
+ WorldPosition relative_direction;
+ GetRelativeDirection(listener_position, listener_rotation,
+ source_transform.position, &relative_direction);
+ const SphericalAngle source_direction =
+ SphericalAngle::FromWorldPosition(relative_direction);
+
+ lookup_table_.GetEncodingCoeffs(ambisonic_order_, source_direction,
+ source_parameters->spread_deg,
+ &coefficients_);
+
+ gain_mixer_.AddInputChannel((*input_buffer)[0], source_id, coefficients_);
+ }
+ return gain_mixer_.GetOutput();
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node.h
new file mode 100644
index 000000000..865677571
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node.h
@@ -0,0 +1,71 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_AMBISONIC_MIXING_ENCODER_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_AMBISONIC_MIXING_ENCODER_NODE_H_
+
+#include <vector>
+
+#include "ambisonics/ambisonic_lookup_table.h"
+#include "base/audio_buffer.h"
+#include "base/spherical_angle.h"
+#include "dsp/gain_mixer.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Node that accepts single mono sound object buffer as input and encodes it
+// into an Ambisonic sound field.
+class AmbisonicMixingEncoderNode : public ProcessingNode {
+ public:
+ // Initializes AmbisonicMixingEncoderNode class.
+ //
+ // @param system_settings Global system configuration.
+ // @param lookup_table Ambisonic encoding lookup table.
+ // @param ambisonic_order Order of Ambisonic sources.
+ AmbisonicMixingEncoderNode(const SystemSettings& system_settings,
+ const AmbisonicLookupTable& lookup_table,
+ int ambisonic_order);
+
+ // Node implementation.
+ bool CleanUp() final {
+ CallCleanUpOnInputNodes();
+ // Prevent node from being disconnected when all sources are removed.
+ return false;
+ }
+
+ protected:
+ // Implements ProcessingNode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ const SystemSettings& system_settings_;
+ const AmbisonicLookupTable& lookup_table_;
+
+ // Ambisonic order of encoded sources.
+ const int ambisonic_order_;
+
+ // |GainMixer| instance.
+ GainMixer gain_mixer_;
+
+ // Encoding coefficient values to be applied to encode the input.
+ std::vector<float> coefficients_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_AMBISONIC_MIXING_ENCODER_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node_test.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node_test.cc
new file mode 100644
index 000000000..1977ab646
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/ambisonic_mixing_encoder_node_test.cc
@@ -0,0 +1,150 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/ambisonic_mixing_encoder_node.h"
+
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "ambisonics/ambisonic_lookup_table.h"
+#include "ambisonics/utils.h"
+#include "api/resonance_audio_api.h"
+#include "base/constants_and_types.h"
+#include "base/object_transform.h"
+#include "config/source_config.h"
+#include "graph/buffered_source_node.h"
+#include "node/sink_node.h"
+#include "node/source_node.h"
+#include "utils/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+// Number of frames per input buffer.
+const size_t kFramesPerBuffer = 16;
+
+// Simulated system sample rate.
+const int kSampleRate = 48000;
+
+} // namespace
+
+// Provides unit tests for |AmbisonicMixingEncoderNode|.
+class AmbisonicMixingEncoderNodeTest
+ : public ::testing::TestWithParam<SourceGraphConfig> {
+ protected:
+ AmbisonicMixingEncoderNodeTest()
+ : system_settings_(kNumStereoChannels, kFramesPerBuffer, kSampleRate),
+ lookup_table_(kMaxSupportedAmbisonicOrder) {}
+
+ void SetUp() override {
+ const auto source_config = GetParam();
+ ambisonic_order_ = source_config.ambisonic_order;
+ ambisonic_mixing_encoder_node_ =
+ std::make_shared<AmbisonicMixingEncoderNode>(
+ system_settings_, lookup_table_, ambisonic_order_);
+ }
+
+ const AudioBuffer* ProcessMultipleInputs(size_t num_sources,
+ const WorldPosition& position,
+ float spread_deg) {
+ // Create the node graph, adding input nodes to the Ambisonic Mixing Encoder
+ // Node.
+ buffered_source_nodes_.clear();
+ auto parameters_manager = system_settings_.GetSourceParametersManager();
+ for (size_t i = 0; i < num_sources; ++i) {
+ buffered_source_nodes_.emplace_back(std::make_shared<BufferedSourceNode>(
+ static_cast<SourceId>(i) /*source id*/, kNumMonoChannels,
+ kFramesPerBuffer));
+ parameters_manager->Register(static_cast<SourceId>(i));
+ }
+ const AudioBuffer* output_buffer = nullptr;
+
+ for (auto& input_node : buffered_source_nodes_) {
+ ambisonic_mixing_encoder_node_->Connect(input_node);
+ }
+ auto output_node = std::make_shared<SinkNode>();
+ output_node->Connect(ambisonic_mixing_encoder_node_);
+
+ // Input data containing unit pulses.
+ const std::vector<float> kInputData(kFramesPerBuffer, 1.0f);
+
+ for (size_t index = 0; index < buffered_source_nodes_.size(); ++index) {
+ AudioBuffer* input_buffer =
+ buffered_source_nodes_[index]
+ ->GetMutableAudioBufferAndSetNewBufferFlag();
+ (*input_buffer)[0] = kInputData;
+ auto source_parameters = parameters_manager->GetMutableParameters(
+ static_cast<SourceId>(index));
+ source_parameters->object_transform.position = position;
+ source_parameters->spread_deg = spread_deg;
+ }
+
+ const std::vector<const AudioBuffer*>& buffer_vector =
+ output_node->ReadInputs();
+ if (!buffer_vector.empty()) {
+ DCHECK_EQ(buffer_vector.size(), 1U);
+ output_buffer = buffer_vector.front();
+ }
+
+ return output_buffer;
+ }
+
+ SystemSettings system_settings_;
+ int ambisonic_order_;
+ AmbisonicLookupTable lookup_table_;
+ std::shared_ptr<AmbisonicMixingEncoderNode> ambisonic_mixing_encoder_node_;
+ std::vector<std::shared_ptr<BufferedSourceNode>> buffered_source_nodes_;
+};
+
+// Tests that a number of sound objects encoded in the same direction are
+// correctly combined into an output buffer.
+TEST_P(AmbisonicMixingEncoderNodeTest, TestEncodeAndMix) {
+ // Number of sources to encode and mix.
+ const size_t kNumSources = 4;
+ // Minimum angular source spread of 0 ensures that no gain correction
+ // coefficients are to be applied to the Ambisonic encoding coefficients.
+ const float kSpreadDeg = 0.0f;
+ // Arbitrary world position of sound sources corresponding to the 36 degrees
+ // azimuth and 18 degrees elevation.
+ const WorldPosition kPosition =
+ WorldPosition(-0.55901699f, 0.30901699f, -0.76942088f);
+ // Expected Ambisonic output for a single source at the above position (as
+ // generated using /matlab/ambisonics/ambix/ambencode.m Matlab function):
+ const std::vector<float> kExpectedSingleSourceOutput = {
+ 1.0f, 0.55901699f, 0.30901699f, 0.76942088f,
+ 0.74498856f, 0.29920441f, -0.35676274f, 0.41181955f,
+ 0.24206145f, 0.64679299f, 0.51477443f, -0.17888019f,
+ -0.38975424f, -0.24620746f, 0.16726035f, -0.21015578f};
+
+ const AudioBuffer* output_buffer =
+ ProcessMultipleInputs(kNumSources, kPosition, kSpreadDeg);
+
+ const size_t num_channels = GetNumPeriphonicComponents(ambisonic_order_);
+
+ for (size_t i = 0; i < num_channels; ++i) {
+ EXPECT_NEAR(
+ kExpectedSingleSourceOutput[i] * static_cast<float>(kNumSources),
+ (*output_buffer)[i][kFramesPerBuffer - 1], kEpsilonFloat);
+ }
+}
+
+INSTANTIATE_TEST_CASE_P(TestParameters, AmbisonicMixingEncoderNodeTest,
+ testing::Values(BinauralLowQualityConfig(),
+ BinauralMediumQualityConfig(),
+ BinauralHighQualityConfig()));
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl.cc
new file mode 100644
index 000000000..79889fabd
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl.cc
@@ -0,0 +1,495 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/binaural_surround_renderer_impl.h"
+
+#include <algorithm>
+#include <functional>
+
+#include "base/misc_math.h"
+#include "base/simd_utils.h"
+#include "base/spherical_angle.h"
+#include "graph/resonance_audio_api_impl.h"
+#include "platforms/common/room_effects_utils.h"
+#include "platforms/common/room_properties.h"
+#include "utils/planar_interleaved_conversion.h"
+
+namespace vraudio {
+
+namespace {
+
+// Maximum number of audio buffers in buffer queue.
+const size_t kNumMaxBuffers = 64;
+
+// Output gain, to avoid clipping of individual virtual speaker channels.
+const float kGain = 0.5f;
+
+} // namespace
+
+BinauralSurroundRendererImpl::BinauralSurroundRendererImpl(
+ size_t frames_per_buffer, int sample_rate_hz)
+ :
+ resonance_audio_api_(nullptr),
+ frames_per_buffer_(frames_per_buffer),
+ sample_rate_hz_(sample_rate_hz),
+ surround_format_(kInvalid),
+ num_input_channels_(0),
+ output_buffer_(kNumStereoChannels, frames_per_buffer),
+ total_frames_buffered_(0),
+ num_zero_padded_frames_(0),
+ output_gain_(1.0f) {
+}
+
+bool BinauralSurroundRendererImpl::Init(SurroundFormat surround_format) {
+ surround_format_ = surround_format;
+ num_input_channels_ =
+ GetExpectedNumChannelsFromSurroundFormat(surround_format);
+
+ temp_planar_buffer_ptrs_.resize(num_input_channels_);
+
+ input_audio_buffer_queue_.reset(new ThreadsafeFifo<AudioBuffer>(
+ kNumMaxBuffers, AudioBuffer(num_input_channels_, frames_per_buffer_)));
+
+ buffer_partitioner_.reset(new BufferPartitioner(
+ num_input_channels_, frames_per_buffer_,
+ std::bind(&BinauralSurroundRendererImpl::BufferPartitionerCallback, this,
+ std::placeholders::_1)));
+
+ buffer_unpartitioner_.reset(new BufferUnpartitioner(
+ kNumStereoChannels, frames_per_buffer_,
+ std::bind(&BinauralSurroundRendererImpl::ProcessBuffer, this)));
+
+ resonance_audio_api_.reset(CreateResonanceAudioApi(
+ kNumStereoChannels, frames_per_buffer_, sample_rate_hz_));
+
+ if (surround_format == kSurroundMono || surround_format == kSurroundStereo ||
+ surround_format == kSurroundFiveDotOne ||
+ surround_format == kSurroundSevenDotOne) {
+ InitializeRoomReverb();
+ }
+ // Initialize rendering mode.
+ switch (surround_format) {
+ case kSurroundMono:
+ InitializeBinauralMono();
+ break;
+ case kSurroundStereo:
+ InitializeBinauralStereo();
+ break;
+ case kSurroundFiveDotOne:
+ InitializeBinauralSurround5dot1();
+ break;
+ case kSurroundSevenDotOne:
+ InitializeBinauralSurround7dot1();
+ break;
+ case kFirstOrderAmbisonics:
+ case kSecondOrderAmbisonics:
+ case kThirdOrderAmbisonics:
+ InitializeAmbisonics();
+ break;
+ case kFirstOrderAmbisonicsWithNonDiegeticStereo:
+ case kSecondOrderAmbisonicsWithNonDiegeticStereo:
+ case kThirdOrderAmbisonicsWithNonDiegeticStereo:
+ InitializeAmbisonicsWithNonDiegeticStereo();
+ break;
+ default:
+ LOG(FATAL) << "Undefined rendering mode";
+ return false;
+ break;
+ }
+ return true;
+}
+
+BinauralSurroundRendererImpl::BinauralSurroundRendererImpl()
+ :
+ resonance_audio_api_(nullptr),
+ frames_per_buffer_(0),
+ sample_rate_hz_(0),
+ total_frames_buffered_(0),
+ num_zero_padded_frames_(0) {
+}
+
+AudioBuffer* BinauralSurroundRendererImpl::BufferPartitionerCallback(
+ AudioBuffer* processed_buffer) {
+ if (processed_buffer != nullptr) {
+ input_audio_buffer_queue_->ReleaseInputObject(processed_buffer);
+ }
+ DCHECK(!input_audio_buffer_queue_->Full());
+ return input_audio_buffer_queue_->AcquireInputObject();
+}
+
+void BinauralSurroundRendererImpl::SetStereoSpeakerMode(bool enabled) {
+ resonance_audio_api_->SetStereoSpeakerMode(enabled);
+}
+
+size_t BinauralSurroundRendererImpl::GetExpectedNumChannelsFromSurroundFormat(
+ SurroundFormat surround_format) {
+ switch (surround_format) {
+ case kSurroundMono:
+ return kNumMonoChannels;
+ case kSurroundStereo:
+ return kNumStereoChannels;
+ case kSurroundFiveDotOne:
+ return kNumSurroundFiveDotOneChannels;
+ case kSurroundSevenDotOne:
+ return kNumSurroundSevenDotOneChannels;
+ case kFirstOrderAmbisonics:
+ return kNumFirstOrderAmbisonicChannels;
+ case kSecondOrderAmbisonics:
+ return kNumSecondOrderAmbisonicChannels;
+ case kThirdOrderAmbisonics:
+ return kNumThirdOrderAmbisonicChannels;
+ case kFirstOrderAmbisonicsWithNonDiegeticStereo:
+ return kNumFirstOrderAmbisonicChannels + kNumStereoChannels;
+ case kSecondOrderAmbisonicsWithNonDiegeticStereo:
+ return kNumSecondOrderAmbisonicChannels + kNumStereoChannels;
+ case kThirdOrderAmbisonicsWithNonDiegeticStereo:
+ return kNumThirdOrderAmbisonicChannels + kNumStereoChannels;
+ default:
+ LOG(FATAL) << "Undefined surround format mode";
+ return false;
+ break;
+ }
+ return 0;
+}
+
+void BinauralSurroundRendererImpl::InitializeBinauralMono() {
+ source_ids_.resize(kNumMonoChannels);
+ // Front (0 degrees):
+ source_ids_[0] = CreateSoundObject(0.0f);
+ output_gain_ = kGain;
+}
+
+void BinauralSurroundRendererImpl::InitializeBinauralStereo() {
+
+ source_ids_.resize(kNumStereoChannels);
+ // Front left (30 degrees):
+ source_ids_[0] = CreateSoundObject(30.0f);
+ // Front right (-30 degrees):
+ source_ids_[1] = CreateSoundObject(-30.0f);
+ output_gain_ = kGain;
+}
+
+void BinauralSurroundRendererImpl::InitializeBinauralSurround5dot1() {
+ source_ids_.resize(kNumSurroundFiveDotOneChannels);
+ // Left (30 degrees):
+ source_ids_[0] = CreateSoundObject(30.0f);
+ // Right (-30 degrees):
+ source_ids_[1] = CreateSoundObject(-30.0f);
+ // Center (0 degrees):
+ source_ids_[2] = CreateSoundObject(0.0f);
+ // Low frequency effects at front center:
+ source_ids_[3] = CreateSoundObject(0.0f);
+ // Left surround (110 degrees):
+ source_ids_[4] = CreateSoundObject(110.0f);
+ // Right surround (-110 degrees):
+ source_ids_[5] = CreateSoundObject(-110.0f);
+ output_gain_ = kGain;
+}
+
+void BinauralSurroundRendererImpl::InitializeBinauralSurround7dot1() {
+ source_ids_.resize(kNumSurroundSevenDotOneChannels);
+ // Left (30 degrees):
+ source_ids_[0] = CreateSoundObject(30.0f);
+ // Right (-30 degrees):
+ source_ids_[1] = CreateSoundObject(-30.0f);
+ // Center (0 degrees):
+ source_ids_[2] = CreateSoundObject(0.0f);
+ // Low frequency effects at front center:
+ source_ids_[3] = CreateSoundObject(0.0f);
+ // Left surround 1 (90 degrees):
+ source_ids_[4] = CreateSoundObject(90.0f);
+ // Right surround 1 (-90 degrees):
+ source_ids_[5] = CreateSoundObject(-90.0f);
+ // Left surround 2 (150 degrees):
+ source_ids_[6] = CreateSoundObject(150.0f);
+ // Right surround 2 (-150 degrees):
+ source_ids_[7] = CreateSoundObject(-150.0f);
+ output_gain_ = kGain;
+}
+
+void BinauralSurroundRendererImpl::InitializeAmbisonics() {
+ source_ids_.resize(1);
+ source_ids_[0] =
+ resonance_audio_api_->CreateAmbisonicSource(num_input_channels_);
+}
+
+void BinauralSurroundRendererImpl::InitializeAmbisonicsWithNonDiegeticStereo() {
+ source_ids_.resize(2);
+ CHECK_GT(num_input_channels_, kNumStereoChannels);
+ source_ids_[0] = resonance_audio_api_->CreateAmbisonicSource(
+ num_input_channels_ - kNumStereoChannels);
+ source_ids_[1] = resonance_audio_api_->CreateStereoSource(kNumStereoChannels);
+}
+
+SourceId BinauralSurroundRendererImpl::CreateSoundObject(float azimuth_deg) {
+ static const float kZeroElevation = 0.0f;
+ auto speaker_position =
+ vraudio::SphericalAngle::FromDegrees(azimuth_deg, kZeroElevation)
+ .GetWorldPositionOnUnitSphere();
+ const SourceId source_id = resonance_audio_api_->CreateSoundObjectSource(
+ RenderingMode::kBinauralHighQuality);
+ resonance_audio_api_->SetSourcePosition(
+ source_id, speaker_position[0], speaker_position[1], speaker_position[2]);
+ return source_id;
+}
+
+void BinauralSurroundRendererImpl::InitializeRoomReverb() {
+ // The following settings has been applied based on AESTD1001.1.01-10.
+ RoomProperties room_properties;
+ room_properties.dimensions[0] = 9.54f;
+ room_properties.dimensions[1] = 6.0f;
+ room_properties.dimensions[2] = 15.12f;
+ room_properties.reverb_brightness = 0.0f;
+ room_properties.reflection_scalar = 1.0f;
+ // Reduce reverb gain to compensate for virtual speakers gain.
+ room_properties.reverb_gain = output_gain_;
+ for (size_t i = 0; i < kNumRoomSurfaces; ++i) {
+ room_properties.material_names[i] = MaterialName::kUniform;
+ }
+ resonance_audio_api_->SetReflectionProperties(
+ ComputeReflectionProperties(room_properties));
+ resonance_audio_api_->SetReverbProperties(
+ ComputeReverbProperties(room_properties));
+ resonance_audio_api_->EnableRoomEffects(true);
+}
+
+size_t BinauralSurroundRendererImpl::GetNumAvailableFramesInInputBuffer()
+ const {
+ DCHECK_NE(surround_format_, kInvalid);
+ if (num_zero_padded_frames_ > 0) {
+ // Zero padded output buffers must be consumed prior to
+ // |AddInterleavedBuffer| calls;
+ return 0;
+ }
+ if (input_audio_buffer_queue_->Full()) {
+ return 0;
+ }
+ // Subtract two buffers from the available input slots to ensure the buffer
+ // partitioner can be flushed at any time while keeping an extra buffer
+ // available in the |buffer_partitioner_| callback for the next incoming data.
+ const size_t num_frames_available_in_input_slots =
+ (kNumMaxBuffers - input_audio_buffer_queue_->Size() - 2) *
+ frames_per_buffer_;
+ DCHECK_GT(frames_per_buffer_, buffer_partitioner_->GetNumBufferedFrames());
+ const size_t num_frames_available_in_buffer_partitioner =
+ frames_per_buffer_ - buffer_partitioner_->GetNumBufferedFrames();
+ return num_frames_available_in_input_slots +
+ num_frames_available_in_buffer_partitioner;
+}
+
+size_t BinauralSurroundRendererImpl::AddInterleavedInput(
+ const int16* input_buffer_ptr, size_t num_channels, size_t num_frames) {
+ return AddInputBufferTemplated<const int16*>(input_buffer_ptr, num_channels,
+ num_frames);
+}
+
+size_t BinauralSurroundRendererImpl::AddInterleavedInput(
+ const float* input_buffer_ptr, size_t num_channels, size_t num_frames) {
+ return AddInputBufferTemplated<const float*>(input_buffer_ptr, num_channels,
+ num_frames);
+}
+
+size_t BinauralSurroundRendererImpl::AddPlanarInput(
+ const int16* const* input_buffer_ptrs, size_t num_channels,
+ size_t num_frames) {
+ return AddInputBufferTemplated<const int16* const*>(input_buffer_ptrs,
+ num_channels, num_frames);
+}
+
+size_t BinauralSurroundRendererImpl::AddPlanarInput(
+ const float* const* input_buffer_ptrs, size_t num_channels,
+ size_t num_frames) {
+ return AddInputBufferTemplated<const float* const*>(input_buffer_ptrs,
+ num_channels, num_frames);
+}
+
+template <typename BufferType>
+size_t BinauralSurroundRendererImpl::AddInputBufferTemplated(
+ const BufferType input_buffer_ptr, size_t num_channels, size_t num_frames) {
+ DCHECK_NE(surround_format_, kInvalid);
+ if (num_channels != num_input_channels_) {
+ LOG(WARNING) << "Invalid number of input channels";
+ return 0;
+ }
+
+ if (num_zero_padded_frames_ > 0) {
+ LOG(WARNING) << "Zero padded output buffers must be consumed prior to "
+ "|AddInterleavedBuffer| calls";
+ return 0;
+ }
+ const size_t num_available_input_frames =
+ std::min(num_frames, GetNumAvailableFramesInInputBuffer());
+
+ buffer_partitioner_->AddBuffer(input_buffer_ptr, num_input_channels_,
+ num_available_input_frames);
+ total_frames_buffered_ += num_available_input_frames;
+ return num_available_input_frames;
+}
+
+size_t BinauralSurroundRendererImpl::GetAvailableFramesInStereoOutputBuffer()
+ const {
+ const size_t num_available_samples_in_buffers =
+ (input_audio_buffer_queue_->Size() * frames_per_buffer_) +
+ buffer_unpartitioner_->GetNumBufferedFrames();
+ return std::min(total_frames_buffered_, num_available_samples_in_buffers);
+}
+
+size_t BinauralSurroundRendererImpl::GetInterleavedStereoOutput(
+ int16* output_buffer_ptr, size_t num_frames) {
+ return GetStereoOutputBufferTemplated<int16*>(output_buffer_ptr, num_frames);
+}
+
+size_t BinauralSurroundRendererImpl::GetInterleavedStereoOutput(
+ float* output_buffer_ptr, size_t num_frames) {
+ return GetStereoOutputBufferTemplated<float*>(output_buffer_ptr, num_frames);
+}
+
+size_t BinauralSurroundRendererImpl::GetPlanarStereoOutput(
+ int16** output_buffer_ptrs, size_t num_frames) {
+ return GetStereoOutputBufferTemplated<int16**>(output_buffer_ptrs,
+ num_frames);
+}
+
+size_t BinauralSurroundRendererImpl::GetPlanarStereoOutput(
+ float** output_buffer_ptrs, size_t num_frames) {
+ return GetStereoOutputBufferTemplated<float**>(output_buffer_ptrs,
+ num_frames);
+}
+
+template <typename BufferType>
+size_t BinauralSurroundRendererImpl::GetStereoOutputBufferTemplated(
+ BufferType output_buffer_ptr, size_t num_frames) {
+ DCHECK_NE(surround_format_, kInvalid);
+ const size_t num_frames_available = GetAvailableFramesInStereoOutputBuffer();
+ size_t num_frames_to_be_processed =
+ std::min(num_frames_available, num_frames);
+ if (num_frames_to_be_processed > total_frames_buffered_) {
+ // Avoid outputting zero padded input frames from |TriggerProcessing|
+ // calls.
+ num_frames_to_be_processed = total_frames_buffered_;
+ }
+
+ const size_t num_frames_written = buffer_unpartitioner_->GetBuffer(
+ output_buffer_ptr, kNumStereoChannels, num_frames_to_be_processed);
+
+ DCHECK_GE(total_frames_buffered_, num_frames_written);
+ total_frames_buffered_ -= num_frames_written;
+
+ if (total_frames_buffered_ == 0) {
+ // Clear zero padded frames from |TriggerProcessing| calls.
+ buffer_unpartitioner_->Clear();
+ num_zero_padded_frames_ = 0;
+ }
+
+ return num_frames_written;
+}
+
+void BinauralSurroundRendererImpl::Clear() {
+ input_audio_buffer_queue_->Clear();
+ buffer_partitioner_->Clear();
+ buffer_unpartitioner_->Clear();
+ total_frames_buffered_ = 0;
+ num_zero_padded_frames_ = 0;
+}
+
+bool BinauralSurroundRendererImpl::TriggerProcessing() {
+ if (num_zero_padded_frames_ > 0) {
+ LOG(WARNING) << "Zero padded output buffers must be consumed prior to "
+ "|TriggerProcessing| calls";
+ return false;
+ }
+ num_zero_padded_frames_ = buffer_partitioner_->Flush();
+ return num_zero_padded_frames_ > 0;
+}
+
+void BinauralSurroundRendererImpl::SetHeadRotation(float w, float x, float y,
+ float z) {
+ resonance_audio_api_->SetHeadRotation(x, y, z, w);
+}
+
+AudioBuffer* BinauralSurroundRendererImpl::ProcessBuffer() {
+ if (input_audio_buffer_queue_->Size() == 0) {
+ LOG(WARNING) << "Buffer underflow detected";
+ return nullptr;
+ }
+
+ const AudioBuffer* input = input_audio_buffer_queue_->AcquireOutputObject();
+ DCHECK_EQ(input->num_frames(), frames_per_buffer_);
+ DCHECK_EQ(num_input_channels_, input->num_channels());
+ GetRawChannelDataPointersFromAudioBuffer(*input, &temp_planar_buffer_ptrs_);
+ // Initialize surround rendering.
+ const float* planar_ptr;
+
+ switch (surround_format_) {
+ case kSurroundMono:
+ case kSurroundStereo:
+ case kSurroundFiveDotOne:
+ case kSurroundSevenDotOne:
+ DCHECK_EQ(input->num_channels(), source_ids_.size());
+ for (size_t source_itr = 0; source_itr < source_ids_.size();
+ ++source_itr) {
+ planar_ptr = (*input)[source_itr].begin();
+ resonance_audio_api_->SetPlanarBuffer(source_ids_[source_itr],
+ &planar_ptr, kNumMonoChannels,
+ input->num_frames());
+ }
+ break;
+ case kFirstOrderAmbisonics:
+ case kSecondOrderAmbisonics:
+ case kThirdOrderAmbisonics:
+ DCHECK_EQ(source_ids_.size(), 1U);
+ resonance_audio_api_->SetPlanarBuffer(
+ source_ids_[0], temp_planar_buffer_ptrs_.data(),
+ input->num_channels(), input->num_frames());
+ break;
+ case kFirstOrderAmbisonicsWithNonDiegeticStereo:
+ case kSecondOrderAmbisonicsWithNonDiegeticStereo:
+ case kThirdOrderAmbisonicsWithNonDiegeticStereo:
+ DCHECK_EQ(source_ids_.size(), 2U);
+ DCHECK_GT(input->num_channels(), kNumStereoChannels);
+ static_cast<ResonanceAudioApiImpl*>(resonance_audio_api_.get())
+ ->SetPlanarBuffer(source_ids_[0], temp_planar_buffer_ptrs_.data(),
+ input->num_channels() - kNumStereoChannels,
+ input->num_frames());
+ static_cast<ResonanceAudioApiImpl*>(resonance_audio_api_.get())
+ ->SetPlanarBuffer(source_ids_[1],
+ temp_planar_buffer_ptrs_.data() +
+ (input->num_channels() - kNumStereoChannels),
+ kNumStereoChannels, input->num_frames());
+ break;
+ default:
+ LOG(FATAL) << "Undefined surround format";
+ break;
+ }
+
+ // Create a copy of the processed |AudioBuffer| to pass it to output buffer
+ // queue.
+ auto* const vraudio_api_impl =
+ static_cast<ResonanceAudioApiImpl*>(resonance_audio_api_.get());
+ vraudio_api_impl->ProcessNextBuffer();
+ output_buffer_ = *vraudio_api_impl->GetStereoOutputBuffer();
+
+ if (output_gain_ != 1.0f) {
+ for (AudioBuffer::Channel& channel : output_buffer_) {
+ ScalarMultiply(output_buffer_.num_frames(), output_gain_, channel.begin(),
+ channel.begin());
+ }
+ }
+ input_audio_buffer_queue_->ReleaseOutputObject(input);
+ return &output_buffer_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl.h b/src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl.h
new file mode 100644
index 000000000..c4916d664
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl.h
@@ -0,0 +1,190 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_BINAURAL_SURROUND_RENDERER_IMPL_H_
+#define RESONANCE_AUDIO_GRAPH_BINAURAL_SURROUND_RENDERER_IMPL_H_
+
+#include <memory>
+#include <string>
+
+#include "api/binaural_surround_renderer.h"
+#include "api/resonance_audio_api.h"
+#include "base/constants_and_types.h"
+#include "utils/buffer_partitioner.h"
+#include "utils/buffer_unpartitioner.h"
+#include "utils/threadsafe_fifo.h"
+
+namespace vraudio {
+
+// Renders virtual surround sound as well as ambisonic soundfields to binaural
+// stereo.
+class BinauralSurroundRendererImpl : public BinauralSurroundRenderer {
+ public:
+ // Constructor.
+ //
+ // @param frames_per_buffer Number of frames in output buffer.
+ // @param sample_rate_hz Sample rate of audio buffers.
+ BinauralSurroundRendererImpl(size_t frames_per_buffer, int sample_rate_hz);
+
+ ~BinauralSurroundRendererImpl() override{};
+
+ // Initializes surround sound decoding.
+ //
+ // @param surround_format Surround sound input format.
+ // @return True on success.
+ bool Init(SurroundFormat surround_format);
+
+ // Implements |AudioRenderer| interface.
+ void SetStereoSpeakerMode(bool enabled) override;
+ size_t GetNumAvailableFramesInInputBuffer() const override;
+ size_t AddInterleavedInput(const int16* input_buffer_ptr, size_t num_channels,
+ size_t num_frames) override;
+ size_t AddInterleavedInput(const float* input_buffer_ptr, size_t num_channels,
+ size_t num_frames) override;
+ size_t AddPlanarInput(const int16* const* input_buffer_ptrs,
+ size_t num_channels, size_t num_frames) override;
+ size_t AddPlanarInput(const float* const* input_buffer_ptrs,
+ size_t num_channels, size_t num_frames) override;
+ size_t GetAvailableFramesInStereoOutputBuffer() const override;
+ size_t GetInterleavedStereoOutput(int16* output_buffer_ptr,
+ size_t num_frames) override;
+ size_t GetInterleavedStereoOutput(float* output_buffer_ptr,
+ size_t num_frames) override;
+ size_t GetPlanarStereoOutput(int16** output_buffer_ptrs,
+ size_t num_frames) override;
+ size_t GetPlanarStereoOutput(float** output_buffer_ptrs,
+ size_t num_frames) override;
+ bool TriggerProcessing() override;
+ void Clear() override;
+ void SetHeadRotation(float w, float x, float y, float z) override;
+
+ protected:
+ // Protected default constructor for mock tests.
+ BinauralSurroundRendererImpl();
+
+ private:
+ // Callback triggered by |buffer_partitioner_| whenever a new |AudioBuffer|
+ // has been generated.
+ //
+ // @param processed_buffer Pointer to processed buffer.
+ // @return Pointer to next |AudioBuffer| to be filled up.
+ AudioBuffer* BufferPartitionerCallback(AudioBuffer* processed_buffer);
+
+ // Helper method to implement |AddInterleavedInput| independently from the
+ // sample type.
+ //
+ // @tparam BufferType Input buffer type.
+ // @param input_buffer_ptr Pointer to interleaved input data.
+ // @param num_channels Number of channels in input buffer.
+ // @param num_frames Number of frames in input buffer.
+ // @return The number of consumed samples.
+ template <typename BufferType>
+ size_t AddInputBufferTemplated(const BufferType input_buffer_ptr,
+ size_t num_channels, size_t num_frames);
+
+ // Helper method to implement |GetInterleavedOutput| independently from the
+ // sample type.
+ //
+ // @tparam BufferType Output buffer type.
+ // @param output_buffer_ptr Pointer to allocated interleaved output buffer.
+ // @param num_frames Size of output buffer in frames.
+ // @return The number of consumed frames.
+ template <typename BufferType>
+ size_t GetStereoOutputBufferTemplated(BufferType output_buffer_ptr,
+ size_t num_frames);
+
+ // Helper method to obtain the expected number of audio channels for a given
+ // surround format.
+ //
+ // @param surround_format Surround format query.
+ // @return Number of audio channels.
+ static size_t GetExpectedNumChannelsFromSurroundFormat(
+ SurroundFormat surround_format);
+
+ // Process method executed by |buffer_unpartitioner_|.
+ AudioBuffer* ProcessBuffer();
+
+ // Initializes binaural mono rendering.
+ void InitializeBinauralMono();
+
+ // Initializes binaural stereo rendering.
+ void InitializeBinauralStereo();
+
+ // Initializes binaural 5.1 rendering.
+ void InitializeBinauralSurround5dot1();
+
+ // Initializes binaural 7.1 rendering.
+ void InitializeBinauralSurround7dot1();
+
+ // Initializes binaural ambisonic rendering.
+ void InitializeAmbisonics();
+
+ // Initializes binaural ambisonic rendering with non-diegetic stereo.
+ void InitializeAmbisonicsWithNonDiegeticStereo();
+
+ // Creates a sound object at given angle within the horizontal listener plane.
+ SourceId CreateSoundObject(float azimuth_deg);
+
+ // Initializes room reverb for virtual surround sound rendering.
+ void InitializeRoomReverb();
+
+ // ResonanceAudioApi instance.
+ std::unique_ptr<ResonanceAudioApi> resonance_audio_api_;
+
+ // Frames per buffer.
+ const size_t frames_per_buffer_;
+
+ // System sample rate.
+ const int sample_rate_hz_;
+
+ // Selected surround sound format.
+ SurroundFormat surround_format_;
+
+ // Number of input channels.
+ size_t num_input_channels_;
+
+ // Partitions input buffers into |AudioBuffer|s.
+ std::unique_ptr<BufferPartitioner> buffer_partitioner_;
+
+ // Buffer queue containing partitioned input |AudioBuffer|s.
+ std::unique_ptr<ThreadsafeFifo<AudioBuffer>> input_audio_buffer_queue_;
+
+ // Binaural stereo output buffer.
+ AudioBuffer output_buffer_;
+
+ // Unpartitions processed |AudioBuffer|s into interleaved output buffers.
+ std::unique_ptr<BufferUnpartitioner> buffer_unpartitioner_;
+
+ // Vector containing the source ids of all rendered sound sources.
+ std::vector<SourceId> source_ids_;
+
+ // Total number of frames currently buffered.
+ size_t total_frames_buffered_;
+
+ // Total number of zero padded frames from |TriggerProcessing| calls.
+ size_t num_zero_padded_frames_;
+
+ // Temporary buffer to store pointers to planar ambisonic and stereo channels.
+ std::vector<const float*> temp_planar_buffer_ptrs_;
+
+ // Global output gain adjustment, to avoid clipping of individual channels
+ // in virtual speaker modes.
+ float output_gain_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_BINAURAL_SURROUND_RENDERER_IMPL_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl_test.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl_test.cc
new file mode 100644
index 000000000..98652ca3e
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/binaural_surround_renderer_impl_test.cc
@@ -0,0 +1,202 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/binaural_surround_renderer_impl.h"
+
+#include <algorithm>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+class BinauralSurroundRendererTest
+ : public ::testing::TestWithParam<
+ BinauralSurroundRenderer::SurroundFormat> {
+ protected:
+ BinauralSurroundRendererTest() {}
+
+ // Virtual methods from ::testing::Test
+ ~BinauralSurroundRendererTest() override {}
+ void SetUp() override {}
+ void TearDown() override {}
+
+ void InitBinauralSurroundRenderer(size_t frames_per_buffer,
+ int sample_rate_hz) {
+ binaural_surround_renderer_api_.reset(
+ new BinauralSurroundRendererImpl(frames_per_buffer, sample_rate_hz));
+ }
+
+ // Processes an interleaved input vector and returns interleaved binaural
+ // stereo output.
+ std::vector<float> ProcessInterleaved(
+ const std::vector<float>& interleaved_input, size_t num_channels,
+ size_t frames_per_buffer) {
+ EXPECT_EQ(interleaved_input.size() % (num_channels * frames_per_buffer),
+ 0U);
+ std::vector<float> interleaved_output;
+ const size_t num_buffers =
+ interleaved_input.size() / (num_channels * frames_per_buffer);
+ for (size_t b = 0; b < num_buffers; ++b) {
+ const float* interleaved_input_ptr =
+ interleaved_input.data() + b * num_channels * frames_per_buffer;
+ binaural_surround_renderer_api_->AddInterleavedInput(
+ interleaved_input_ptr, num_channels, frames_per_buffer);
+
+ interleaved_output.resize((b + 1) * kNumStereoChannels *
+ frames_per_buffer);
+ float* interleaved_output_ptr =
+ interleaved_output.data() +
+ b * kNumStereoChannels * frames_per_buffer;
+
+ EXPECT_EQ(binaural_surround_renderer_api_->GetInterleavedStereoOutput(
+ interleaved_output_ptr, frames_per_buffer),
+ frames_per_buffer);
+ }
+ return interleaved_output;
+ }
+
+ // Calculates the maximum absolute difference between adjacent samples in an
+ // interleaved audio buffer.
+ float GetMaximumSampleDiff(const std::vector<float>& interleaved_input,
+ size_t num_channels) {
+ if (interleaved_input.size() <= num_channels) {
+ return 0.0f;
+ }
+
+ float max_sample_diff = 0.0f;
+ std::vector<float> prev_samples(num_channels);
+ for (size_t i = 0; i < num_channels; ++i) {
+ prev_samples[i] = interleaved_input[i];
+ }
+ for (size_t i = num_channels; i < interleaved_input.size(); ++i) {
+ const size_t channel = i % num_channels;
+ max_sample_diff =
+ std::max(max_sample_diff,
+ std::abs(interleaved_input[i] - prev_samples[channel]));
+ prev_samples[channel] = interleaved_input[i];
+ }
+ return max_sample_diff;
+ }
+
+ // Helper to return the number of input channels for a given surround format.
+ size_t GetNumInputChannelsForSurroundFormat(
+ BinauralSurroundRenderer::SurroundFormat format) {
+ switch (format) {
+ case BinauralSurroundRenderer::SurroundFormat::kSurroundMono:
+ return kNumMonoChannels;
+ break;
+ case BinauralSurroundRenderer::SurroundFormat::kSurroundStereo:
+ return kNumStereoChannels;
+ break;
+ case BinauralSurroundRenderer::SurroundFormat::kSurroundFiveDotOne:
+ return kNumSurroundFiveDotOneChannels;
+ break;
+ case BinauralSurroundRenderer::SurroundFormat::kSurroundSevenDotOne:
+ return kNumSurroundSevenDotOneChannels;
+ break;
+ case BinauralSurroundRenderer::SurroundFormat::kFirstOrderAmbisonics:
+ return kNumFirstOrderAmbisonicChannels;
+ break;
+ case BinauralSurroundRenderer::SurroundFormat::
+ kFirstOrderAmbisonicsWithNonDiegeticStereo:
+ return kNumFirstOrderAmbisonicWithNonDiegeticStereoChannels;
+ break;
+ case BinauralSurroundRenderer::SurroundFormat::kSecondOrderAmbisonics:
+ return kNumSecondOrderAmbisonicChannels;
+ break;
+ case BinauralSurroundRenderer::SurroundFormat::
+ kSecondOrderAmbisonicsWithNonDiegeticStereo:
+ return kNumSecondOrderAmbisonicWithNonDiegeticStereoChannels;
+ break;
+ case BinauralSurroundRenderer::SurroundFormat::kThirdOrderAmbisonics:
+ return kNumThirdOrderAmbisonicChannels;
+ break;
+ case BinauralSurroundRenderer::SurroundFormat::
+ kThirdOrderAmbisonicsWithNonDiegeticStereo:
+ return kNumThirdOrderAmbisonicWithNonDiegeticStereoChannels;
+ break;
+ default:
+ break;
+ }
+ LOG(FATAL) << "Unexpected format";
+ return 0;
+ }
+
+ // VR Audio API instance to test.
+ std::unique_ptr<BinauralSurroundRendererImpl> binaural_surround_renderer_api_;
+};
+
+// Processes an input signal with constant DC offset and scans the output for
+// drop outs and noise.
+TEST_P(BinauralSurroundRendererTest, DropOutGlitchTesting) {
+
+ const std::vector<int> kTestSampleRates = {44100, 48000};
+ const std::vector<int> kTestBufferSizes = {256, 413, 512};
+ const size_t kNumTestBuffers = 16;
+ const size_t kNumNumChannels =
+ GetNumInputChannelsForSurroundFormat(GetParam());
+
+ for (int sample_rate : kTestSampleRates) {
+ for (int buffer_size : kTestBufferSizes) {
+ InitBinauralSurroundRenderer(buffer_size, sample_rate);
+ binaural_surround_renderer_api_->Init(GetParam());
+
+ // Create DC input signal with magnitude 0.5f.
+ const std::vector<float> interleaved_dc_signal(
+ buffer_size * kNumNumChannels * kNumTestBuffers, 0.5f);
+
+ std::vector<float> interleaved_output = ProcessInterleaved(
+ interleaved_dc_signal, kNumNumChannels, buffer_size);
+
+ // Remove first half of samples from output vector to remove initial
+ // filter ringing effects and initial gain ramps.
+ interleaved_output.erase(
+ interleaved_output.begin(),
+ interleaved_output.begin() + interleaved_output.size() / 2);
+
+ const float kMaxExpectedMagnitudeDiff = 0.07f;
+ const float maximum_adjacent_frames_magnitude_diff =
+ GetMaximumSampleDiff(interleaved_output, kNumStereoChannels);
+ EXPECT_LT(maximum_adjacent_frames_magnitude_diff,
+ kMaxExpectedMagnitudeDiff);
+ }
+ }
+}
+
+INSTANTIATE_TEST_CASE_P(
+ SurroundFormatInstances, BinauralSurroundRendererTest,
+ ::testing::Values(
+ BinauralSurroundRenderer::SurroundFormat::kSurroundMono,
+ BinauralSurroundRenderer::SurroundFormat::kSurroundStereo,
+ BinauralSurroundRenderer::SurroundFormat::kSurroundFiveDotOne,
+ BinauralSurroundRenderer::SurroundFormat::kSurroundSevenDotOne,
+ BinauralSurroundRenderer::SurroundFormat::kFirstOrderAmbisonics,
+ BinauralSurroundRenderer::SurroundFormat::
+ kFirstOrderAmbisonicsWithNonDiegeticStereo,
+ BinauralSurroundRenderer::SurroundFormat::kSecondOrderAmbisonics,
+ BinauralSurroundRenderer::SurroundFormat::
+ kSecondOrderAmbisonicsWithNonDiegeticStereo,
+ BinauralSurroundRenderer::SurroundFormat::kThirdOrderAmbisonics,
+ BinauralSurroundRenderer::SurroundFormat::
+ kThirdOrderAmbisonicsWithNonDiegeticStereo));
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/buffered_source_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/buffered_source_node.cc
new file mode 100644
index 000000000..ab3e49d73
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/buffered_source_node.cc
@@ -0,0 +1,46 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/buffered_source_node.h"
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+BufferedSourceNode::BufferedSourceNode(SourceId source_id, size_t num_channels,
+ size_t frames_per_buffer)
+ : source_id_(source_id),
+ input_audio_buffer_(num_channels, frames_per_buffer),
+ new_buffer_flag_(false) {
+ input_audio_buffer_.Clear();
+}
+
+AudioBuffer* BufferedSourceNode::GetMutableAudioBufferAndSetNewBufferFlag() {
+ new_buffer_flag_ = true;
+ return &input_audio_buffer_;
+}
+
+const AudioBuffer* BufferedSourceNode::AudioProcess() {
+ if (!new_buffer_flag_) {
+ return nullptr;
+ }
+ new_buffer_flag_ = false;
+ input_audio_buffer_.set_source_id(source_id_);
+ return &input_audio_buffer_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/buffered_source_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/buffered_source_node.h
new file mode 100644
index 000000000..3d5ce0b4a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/buffered_source_node.h
@@ -0,0 +1,62 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_BUFFERED_SOURCE_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_BUFFERED_SOURCE_NODE_H_
+
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "node/source_node.h"
+
+namespace vraudio {
+
+// Node that sets the |AudioBuffer| of a source. This class is *not*
+// thread-safe and calls to this class must be synchronized with the graph
+// processing.
+class BufferedSourceNode : public SourceNode {
+ public:
+ // Constructor.
+ //
+ // @param source_id Source id.
+ // @param num_channel Number of channels in output buffers.
+ BufferedSourceNode(SourceId source_id, size_t num_channels,
+ size_t frames_per_buffer);
+
+ // Returns a mutable pointer to the internal |AudioBuffer| and sets a flag to
+ // process the buffer in the next graph processing iteration. Calls to this
+ // method must be synchronized with the audio graph processing.
+ //
+ // @return Mutable audio buffer pointer.
+ AudioBuffer* GetMutableAudioBufferAndSetNewBufferFlag();
+
+ protected:
+ // Implements SourceNode.
+ const AudioBuffer* AudioProcess() override;
+
+ // Source id.
+ const SourceId source_id_;
+
+ // Input audio buffer.
+ AudioBuffer input_audio_buffer_;
+
+ // Flag indicating if an new audio buffer has been set via
+ // |GetMutableAudioBufferAndSetNewBufferFlag|.
+ bool new_buffer_flag_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_BUFFERED_SOURCE_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/foa_rotator_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/foa_rotator_node.cc
new file mode 100644
index 000000000..71c81d017
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/foa_rotator_node.cc
@@ -0,0 +1,67 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/foa_rotator_node.h"
+
+#include "base/logging.h"
+
+
+namespace vraudio {
+
+FoaRotatorNode::FoaRotatorNode(SourceId source_id,
+ const SystemSettings& system_settings)
+ : system_settings_(system_settings),
+ output_buffer_(kNumFirstOrderAmbisonicChannels,
+ system_settings.GetFramesPerBuffer()) {
+ output_buffer_.Clear();
+ output_buffer_.set_source_id(source_id);
+}
+
+const AudioBuffer* FoaRotatorNode::AudioProcess(const NodeInput& input) {
+
+
+ // Get the soundfield input buffer.
+ const AudioBuffer* input_buffer = input.GetSingleInput();
+ DCHECK(input_buffer);
+ DCHECK_GT(input_buffer->num_frames(), 0U);
+ DCHECK_EQ(input_buffer->num_channels(), 4U);
+ DCHECK_EQ(input_buffer->source_id(), output_buffer_.source_id());
+
+ // Rotate soundfield buffer by the inverse head orientation.
+ const auto source_parameters =
+ system_settings_.GetSourceParameters(input_buffer->source_id());
+ if (source_parameters == nullptr) {
+ LOG(WARNING) << "Could not find source parameters";
+ return nullptr;
+ }
+
+ const WorldRotation& source_rotation =
+ source_parameters->object_transform.rotation;
+ const WorldRotation inverse_head_rotation =
+ system_settings_.GetHeadRotation().conjugate();
+ const WorldRotation rotation = inverse_head_rotation * source_rotation;
+ const bool rotation_applied =
+ foa_rotator_.Process(rotation, *input_buffer, &output_buffer_);
+
+ if (!rotation_applied) {
+ return input_buffer;
+ }
+
+ // Copy buffer parameters.
+ return &output_buffer_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/foa_rotator_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/foa_rotator_node.h
new file mode 100644
index 000000000..802478a0a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/foa_rotator_node.h
@@ -0,0 +1,54 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_FOA_ROTATOR_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_FOA_ROTATOR_NODE_H_
+
+#include <memory>
+
+#include "ambisonics/foa_rotator.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Node that accepts a single first order PeriphonicSoundfieldBuffer as input
+// and outputs a rotated PeriphonicSoundfieldBuffer of the corresponding
+// soundfield input using head rotation information from the system settings.
+class FoaRotatorNode : public ProcessingNode {
+ public:
+ FoaRotatorNode(SourceId source_id, const SystemSettings& system_settings);
+
+ protected:
+ // Implements ProcessingNode. Returns a null pointer if we are in stereo
+ // loudspeaker or stereo pan mode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ const SystemSettings& system_settings_;
+
+ // Soundfield rotator used to rotate first order soundfields.
+ FoaRotator foa_rotator_;
+
+ // Output buffer.
+ AudioBuffer output_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_FOA_ROTATOR_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node.cc
new file mode 100644
index 000000000..26ab2982f
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node.cc
@@ -0,0 +1,66 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/gain_mixer_node.h"
+
+#include <vector>
+
+#include "base/constants_and_types.h"
+
+
+namespace vraudio {
+
+GainMixerNode::GainMixerNode(const AttenuationType& attenuation_type,
+ const SystemSettings& system_settings,
+ size_t num_channels)
+ : mute_enabled_(false),
+ attenuation_type_(attenuation_type),
+ gain_mixer_(num_channels, system_settings.GetFramesPerBuffer()),
+ system_settings_(system_settings) {}
+
+void GainMixerNode::SetMute(bool mute_enabled) { mute_enabled_ = mute_enabled; }
+
+bool GainMixerNode::CleanUp() {
+ CallCleanUpOnInputNodes();
+ // Prevent node from being disconnected when all sources are removed.
+ return false;
+}
+
+const AudioBuffer* GainMixerNode::AudioProcess(const NodeInput& input) {
+
+
+ if (mute_enabled_) {
+ // Skip processing and output nullptr audio buffer.
+ return nullptr;
+ }
+
+ // Apply the gain to each input buffer channel.
+ gain_mixer_.Reset();
+ for (auto input_buffer : input.GetInputBuffers()) {
+ const auto source_parameters =
+ system_settings_.GetSourceParameters(input_buffer->source_id());
+ if (source_parameters != nullptr) {
+ const float target_gain =
+ source_parameters->attenuations[attenuation_type_];
+ const size_t num_channels = input_buffer->num_channels();
+ gain_mixer_.AddInput(*input_buffer,
+ std::vector<float>(num_channels, target_gain));
+ }
+ }
+ return gain_mixer_.GetOutput();
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node.h
new file mode 100644
index 000000000..df569ccdd
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node.h
@@ -0,0 +1,68 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_GAIN_MIXER_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_GAIN_MIXER_NODE_H_
+
+#include "base/audio_buffer.h"
+#include "base/source_parameters.h"
+#include "dsp/gain_mixer.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Node that accepts multiple input buffers, calculates and applies a gain
+// value to each buffer based upon the given |AttenuationType| and then mixes
+// the results together.
+class GainMixerNode : public ProcessingNode {
+ public:
+ // Constructs |GainMixerNode| with given gain calculation method.
+ //
+ // @param attenuation_type Gain attenuation type to be used.
+ // @param system_settings Global system settings.
+ // @param num_channels Number of channels.
+ GainMixerNode(const AttenuationType& attenuation_type,
+ const SystemSettings& system_settings, size_t num_channels);
+
+ // Mute the mixer node by skipping the audio processing and outputting nullptr
+ // buffers.
+ void SetMute(bool mute_enabled);
+
+ // Node implementation.
+ bool CleanUp() final;
+
+ protected:
+ // Implements ProcessingNode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ // Flag indicating the mute status.
+ bool mute_enabled_;
+
+ // Gain attenuation type.
+ const AttenuationType attenuation_type_;
+
+ // Gain mixer.
+ GainMixer gain_mixer_;
+
+ // Global system settings.
+ const SystemSettings& system_settings_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_GAIN_MIXER_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node_test.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node_test.cc
new file mode 100644
index 000000000..6e2a98f81
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node_test.cc
@@ -0,0 +1,246 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/gain_mixer_node.h"
+
+#include <algorithm>
+#include <limits>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "graph/buffered_source_node.h"
+#include "node/sink_node.h"
+#include "node/source_node.h"
+
+namespace vraudio {
+
+namespace {
+
+// Values to initialize a |SystemSettings| instance.
+const size_t kNumFrames = 4;
+const size_t kSampleRate = 44100;
+
+// Helper class to detect deletion.
+class DeletionDetector {
+ public:
+ explicit DeletionDetector(bool* node_deletion_flag)
+ : node_deletion_flag_(node_deletion_flag) {}
+ ~DeletionDetector() {
+ if (node_deletion_flag_ != nullptr) {
+ *node_deletion_flag_ = true;
+ }
+ }
+
+ private:
+ bool* node_deletion_flag_;
+};
+
+// Wraps |SourceNode| to detect its deletion.
+class MySourceNode : public SourceNode, DeletionDetector {
+ public:
+ explicit MySourceNode(bool* node_deletion_flag)
+ : DeletionDetector(node_deletion_flag) {}
+
+ protected:
+ const AudioBuffer* AudioProcess() final { return nullptr; }
+};
+
+// Wraps |GainMixerNode| to detect its deletion.
+class MyGainMixerNode : public GainMixerNode, DeletionDetector {
+ public:
+ MyGainMixerNode(bool* node_deletion_flag,
+ const AttenuationType& attenuation_type,
+ const SystemSettings& system_settings)
+ : GainMixerNode(attenuation_type, system_settings, kNumMonoChannels),
+ DeletionDetector(node_deletion_flag) {}
+};
+
+// Wraps |SinkNode| to detect its deletion.
+class MySinkNode : public SinkNode, DeletionDetector {
+ public:
+ explicit MySinkNode(bool* node_deletion_flag)
+ : DeletionDetector(node_deletion_flag) {}
+};
+
+// Tests that the |GainMixerNode| keeps connected at the moment all of its
+// sources are removed.
+TEST(AudioNodesTest, CleanUpOnEmptyInputTest) {
+ bool source_node_deleted = false;
+ bool gain_mixer_node_deleted = false;
+ bool sink_node_deleted = false;
+
+ SystemSettings system_settings(kNumMonoChannels, kNumFrames, kSampleRate);
+ auto sink_node = std::make_shared<MySinkNode>(&sink_node_deleted);
+
+ {
+ // Create a source and mixer node and connect it to sink node.
+ auto source_node = std::make_shared<MySourceNode>(&source_node_deleted);
+ auto gain_mixer_node = std::make_shared<MyGainMixerNode>(
+ &gain_mixer_node_deleted, AttenuationType::kInput, system_settings);
+
+ // Connect nodes.
+ sink_node->Connect(gain_mixer_node);
+ gain_mixer_node->Connect(source_node);
+
+ // End of stream is marked in source node. Do not expect any data anymore.
+ source_node->MarkEndOfStream();
+ }
+
+ EXPECT_FALSE(source_node_deleted);
+ EXPECT_FALSE(gain_mixer_node_deleted);
+ EXPECT_FALSE(sink_node_deleted);
+
+ sink_node->CleanUp();
+
+ EXPECT_TRUE(source_node_deleted);
+ EXPECT_FALSE(gain_mixer_node_deleted);
+ EXPECT_FALSE(sink_node_deleted);
+}
+
+// Provides unit tests for |GainMixerNode|.
+class GainMixerNodeTest : public ::testing::Test {
+ protected:
+ GainMixerNodeTest()
+ : system_settings_(kNumMonoChannels, kNumFrames, kSampleRate) {}
+
+ // Helper method to create a new input buffer.
+ //
+ // @return Mono audio buffer filled with test data.
+ std::unique_ptr<AudioBuffer> CreateInputBuffer(
+ const std::vector<float>& input_data) {
+ auto buffer = std::unique_ptr<AudioBuffer>(
+ new AudioBuffer(kNumMonoChannels, input_data.size()));
+ (*buffer)[0] = input_data;
+ return buffer;
+ }
+
+ // Helper method that generates a node graph and returns the processed
+ // output.
+ //
+ // @param num_inputs Number of input buffers to be processed.
+ void CreateGraph(size_t num_inputs) {
+ // Tests will use |AttenuationType::kInput| which directly returns the
+ // local
+ // gain value in order to avoid extra complexity.
+ gain_mixer_node_ = std::make_shared<GainMixerNode>(
+ AttenuationType::kInput, system_settings_, kNumMonoChannels);
+
+ output_node_ = std::make_shared<SinkNode>();
+ output_node_->Connect(gain_mixer_node_);
+
+ buffered_source_nodes_.resize(num_inputs);
+ auto parameters_manager = system_settings_.GetSourceParametersManager();
+ for (size_t i = 0; i < num_inputs; ++i) {
+ const auto source_id = static_cast<SourceId>(i);
+ buffered_source_nodes_[i] = std::make_shared<BufferedSourceNode>(
+ source_id, kNumMonoChannels, kNumFrames);
+ gain_mixer_node_->Connect(buffered_source_nodes_[i]);
+ parameters_manager->Register(source_id);
+ }
+ }
+
+ // Processes input buuffers with gains returning the mixed output.
+ //
+ // @param input_gains Gains to be processed.
+ // @param input_buffers Buffers to be processed.
+ // @return Processed output buffer.
+ const AudioBuffer* Process(
+ float input_gain, const std::vector<std::vector<float>>& input_buffers) {
+ DCHECK_EQ(buffered_source_nodes_.size(), input_buffers.size());
+ for (size_t i = 0; i < input_buffers.size(); ++i) {
+ const auto source_id = static_cast<SourceId>(i);
+ auto input = CreateInputBuffer(input_buffers[i]);
+ // Set the input gain.
+ auto parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ source_id);
+ parameters->attenuations[AttenuationType::kInput] = input_gain;
+ // Process the buffer.
+ AudioBuffer* const input_node_buffer =
+ buffered_source_nodes_[i]->GetMutableAudioBufferAndSetNewBufferFlag();
+ *input_node_buffer = *input;
+ }
+ const std::vector<const AudioBuffer*>& outputs = output_node_->ReadInputs();
+ if (!outputs.empty()) {
+ DCHECK_EQ(outputs.size(), 1U);
+ return outputs.front();
+ }
+ return nullptr;
+ }
+
+ // System settings.
+ SystemSettings system_settings_;
+
+ // Component nodes for the simple audio graph.
+ std::shared_ptr<GainMixerNode> gain_mixer_node_;
+ std::vector<std::shared_ptr<BufferedSourceNode>> buffered_source_nodes_;
+ std::shared_ptr<SinkNode> output_node_;
+};
+
+// Tests that the |GainMixerNode| returns the expected output buffers with
+// different gain values.
+TEST_F(GainMixerNodeTest, GainTest) {
+ const float kGain = 0.5f;
+ const std::vector<std::vector<float>> inputs({{1.0f, 1.0f, 1.0f, 1.0f},
+ {2.0f, 2.0f, 2.0f, 2.0f},
+ {3.0f, 3.0f, 3.0f, 3.0f},
+ {4.0f, 4.0f, 4.0f, 4.0f}});
+ // Zero buffer should be returned when the gain value's zero from the start.
+ CreateGraph(inputs.size());
+ auto output = Process(0.0f, inputs);
+ for (size_t i = 0; i < inputs[0].size(); ++i) {
+ EXPECT_NEAR((*output)[0][i], 0.0f, kEpsilonFloat);
+ }
+
+ // A valid output buffer should be returned when the gain value is non-zero.
+ output = Process(kGain, inputs);
+ EXPECT_NEAR((*output)[0][0], 0.0f, kEpsilonFloat);
+ for (size_t i = 1; i < inputs[0].size(); ++i) {
+ EXPECT_FALSE(std::abs((*output)[0][i]) <=
+ std::numeric_limits<float>::epsilon());
+ }
+
+ // Correct values should be returned after gain processor interpolation.
+ for (size_t i = 0; i < kUnitRampLength / 2; ++i) {
+ output = Process(kGain, inputs);
+ }
+ const float output_value =
+ kGain * (inputs[0][0] + inputs[1][0] + inputs[2][0] + inputs[3][0]);
+ for (size_t i = 0; i < inputs[0].size(); ++i) {
+ EXPECT_NEAR((*output)[0][i], output_value, kEpsilonFloat);
+ }
+
+ // A valid output buffer should be returned even when the gain value is zero
+ // while gain processor interpolation.
+ output = Process(0.0f, inputs);
+ for (size_t i = 0; i < inputs[0].size(); ++i) {
+ EXPECT_NE((*output)[0][i], 0.0f);
+ }
+
+ // Zero buffer should be returned after the interpolation is completed.
+ for (size_t i = 0; i < kUnitRampLength / 2; ++i) {
+ output = Process(0.0f, inputs);
+ }
+ for (size_t i = 0; i < inputs[0].size(); ++i) {
+ EXPECT_NEAR((*output)[0][i], 0.0f, kEpsilonFloat);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/gain_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_node.cc
new file mode 100644
index 000000000..ca1c8edb2
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_node.cc
@@ -0,0 +1,82 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/gain_node.h"
+
+#include <cmath>
+
+
+#include "dsp/gain.h"
+
+namespace vraudio {
+
+GainNode::GainNode(SourceId source_id, size_t num_channels,
+ const AttenuationType& attenuation_type,
+ const SystemSettings& system_settings)
+ : num_channels_(num_channels),
+ attenuation_type_(attenuation_type),
+ gain_processors_(num_channels_),
+ system_settings_(system_settings),
+ output_buffer_(num_channels, system_settings.GetFramesPerBuffer()) {
+ DCHECK_GT(num_channels, 0U);
+ output_buffer_.set_source_id(source_id);
+}
+
+const AudioBuffer* GainNode::AudioProcess(const NodeInput& input) {
+
+
+ const AudioBuffer* input_buffer = input.GetSingleInput();
+ DCHECK(input_buffer);
+ DCHECK_EQ(input_buffer->num_channels(), num_channels_);
+ DCHECK_EQ(input_buffer->source_id(), output_buffer_.source_id());
+
+ const auto source_parameters =
+ system_settings_.GetSourceParameters(input_buffer->source_id());
+ if (source_parameters == nullptr) {
+ LOG(WARNING) << "Could not find source parameters";
+ return nullptr;
+ }
+
+ const float current_gain = gain_processors_[0].GetGain();
+ const float target_gain = source_parameters->attenuations[attenuation_type_];
+ if (IsGainNearZero(target_gain) && IsGainNearZero(current_gain)) {
+ // Make sure the gain processors are initialized.
+ for (size_t i = 0; i < num_channels_; ++i) {
+ gain_processors_[i].Reset(0.0f);
+ }
+ // Skip processing in case of zero gain.
+ return nullptr;
+ }
+ if (IsGainNearUnity(target_gain) && IsGainNearUnity(current_gain)) {
+ // Make sure the gain processors are initialized.
+ for (size_t i = 0; i < num_channels_; ++i) {
+ gain_processors_[i].Reset(1.0f);
+ }
+ // Skip processing in case of unity gain.
+ return input_buffer;
+ }
+
+ // Apply the gain to each input buffer channel.
+ for (size_t i = 0; i < num_channels_; ++i) {
+ gain_processors_[i].ApplyGain(target_gain, (*input_buffer)[i],
+ &output_buffer_[i],
+ false /* accumulate_output */);
+ }
+
+ return &output_buffer_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/gain_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_node.h
new file mode 100644
index 000000000..35f8c62b8
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_node.h
@@ -0,0 +1,69 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_GAIN_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_GAIN_NODE_H_
+
+#include <memory>
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/source_parameters.h"
+#include "dsp/gain_processor.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Node that calculates and applies a gain value to each channel of an input
+// buffer based upon the given |GainCalculator|.
+class GainNode : public ProcessingNode {
+ public:
+ // Constructs |GainNode| with given gain attenuation method.
+ //
+ // @param source_id Output buffer source id.
+ // @param num_channels Number of channels in the input buffer.
+ // @param attenuation_type Gain attenuation type to be used.
+ // @param system_settings Global system settings.
+ GainNode(SourceId source_id, size_t num_channels,
+ const AttenuationType& attenuation_type,
+ const SystemSettings& system_settings);
+
+ protected:
+ // Implements ProcessingNode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ // Number of channels of the audio buffer.
+ const size_t num_channels_;
+
+ // Gain attenuation type.
+ const AttenuationType attenuation_type_;
+
+ // Gain processors per each channel.
+ std::vector<GainProcessor> gain_processors_;
+
+ // Global system settings.
+ const SystemSettings& system_settings_;
+
+ // Output buffer.
+ AudioBuffer output_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_GAIN_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/gain_node_test.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_node_test.cc
new file mode 100644
index 000000000..97391f876
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/gain_node_test.cc
@@ -0,0 +1,138 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/gain_node.h"
+
+#include <iterator>
+#include <memory>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "graph/buffered_source_node.h"
+#include "node/sink_node.h"
+
+namespace vraudio {
+
+namespace {
+
+// Values to initialize a |SystemSettings| instance.
+const size_t kNumFrames = 4;
+const size_t kSampleRate = 44100;
+
+// Source id.
+const SourceId kSourceId = 1;
+
+const float kInputData[kNumFrames] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+// Provides unit tests for |GainNode|.
+class GainNodeTest : public ::testing::Test {
+ protected:
+ GainNodeTest()
+ : input_data_(std::begin(kInputData), std::end(kInputData)),
+ system_settings_(kNumMonoChannels, kNumFrames, kSampleRate) {}
+
+ void SetUp() override {
+ // Tests will use |AttenuationType::kInput| which directly returns the input
+ // gain value in order to avoid extra complexity.
+ gain_node_ = std::make_shared<GainNode>(
+ kSourceId, kNumMonoChannels, AttenuationType::kInput, system_settings_);
+ input_buffer_node_ = std::make_shared<BufferedSourceNode>(
+ kSourceId, kNumMonoChannels, kNumFrames);
+ gain_node_->Connect(input_buffer_node_);
+ output_node_ = std::make_shared<SinkNode>();
+ output_node_->Connect(gain_node_);
+ // Register the source parameters.
+ system_settings_.GetSourceParametersManager()->Register(kSourceId);
+ }
+
+ // Helper method to create a new input buffer.
+ //
+ // @return Mono audio buffer filled with test data.
+ std::unique_ptr<AudioBuffer> CreateInputBuffer() {
+ std::unique_ptr<AudioBuffer> buffer(
+ new AudioBuffer(kNumMonoChannels, kNumFrames));
+ (*buffer)[0] = input_data_;
+ return buffer;
+ }
+
+ // Helper method that generates a node graph and returns the processed output.
+ //
+ // @param input_gain Input gain value to be processed.
+ // @return Processed output buffer.
+
+ const AudioBuffer* ProcessGainNode(float input_gain) {
+ // Create a new audio buffer.
+ auto input = CreateInputBuffer();
+ // Update the input gain parameter.
+ auto parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ kSourceId);
+ parameters->attenuations[AttenuationType::kInput] = input_gain;
+ // Process the buffer.
+ AudioBuffer* const input_node_buffer =
+ input_buffer_node_->GetMutableAudioBufferAndSetNewBufferFlag();
+ *input_node_buffer = *input;
+
+ const std::vector<const AudioBuffer*>& outputs = output_node_->ReadInputs();
+ if (!outputs.empty()) {
+ DCHECK_EQ(outputs.size(), 1U);
+ return outputs.front();
+ }
+ return nullptr;
+ }
+
+ private:
+ std::vector<float> input_data_;
+
+ std::shared_ptr<GainNode> gain_node_;
+ std::shared_ptr<BufferedSourceNode> input_buffer_node_;
+ std::shared_ptr<SinkNode> output_node_;
+
+ SystemSettings system_settings_;
+};
+
+// Tests that the gain node returns the expected output buffers with different
+// gain values.
+TEST_F(GainNodeTest, GainTest) {
+ // nullptr should be returned when the gain value is zero from the start.
+ auto output = ProcessGainNode(0.0f);
+
+ EXPECT_TRUE(output == nullptr);
+
+ // A valid output buffer should be returned when the gain value is non-zero.
+ output = ProcessGainNode(0.5f);
+
+ EXPECT_FALSE(output == nullptr);
+
+ // A valid output buffer should be returned even when the gain value is zero
+ // while gain processor interpolation.
+ output = ProcessGainNode(0.0f);
+
+ EXPECT_FALSE(output == nullptr);
+
+ // nullptr should be returned after the interpolation is completed.
+ for (size_t i = 0; i < kUnitRampLength; ++i) {
+ output = ProcessGainNode(0.0f);
+ }
+
+ EXPECT_TRUE(output == nullptr);
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager.cc
new file mode 100644
index 000000000..cb5b85590
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager.cc
@@ -0,0 +1,290 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/graph_manager.h"
+
+#include <functional>
+
+#include "ambisonics/utils.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "graph/foa_rotator_node.h"
+#include "graph/gain_node.h"
+#include "graph/hoa_rotator_node.h"
+#include "graph/mono_from_soundfield_node.h"
+#include "graph/near_field_effect_node.h"
+#include "graph/occlusion_node.h"
+
+namespace vraudio {
+
+GraphManager::GraphManager(const SystemSettings& system_settings)
+ :
+ room_effects_enabled_(true),
+ config_(GlobalConfig()),
+ system_settings_(system_settings),
+ fft_manager_(system_settings.GetFramesPerBuffer()),
+ output_node_(std::make_shared<SinkNode>()) {
+ CHECK_LE(system_settings.GetFramesPerBuffer(), kMaxSupportedNumFrames);
+
+ stereo_mixer_node_ =
+ std::make_shared<MixerNode>(system_settings_, kNumStereoChannels);
+ output_node_->Connect(stereo_mixer_node_);
+
+ /// Initialize the Ambisonic Lookup Table.
+ lookup_table_.reset(new AmbisonicLookupTable(config_.max_ambisonic_order));
+ // Initialize the Ambisonic Renderer subgraphs.
+ for (const auto& sh_hrir_filename_itr : config_.sh_hrir_filenames) {
+ const int ambisonic_order = sh_hrir_filename_itr.first;
+ const auto& sh_hrir_filename = sh_hrir_filename_itr.second;
+ InitializeAmbisonicRendererGraph(ambisonic_order, sh_hrir_filename);
+ // Initialize the Ambisonic Mixing Encoders for HRTF sound object rendering.
+ ambisonic_mixing_encoder_nodes_[ambisonic_order] =
+ std::make_shared<AmbisonicMixingEncoderNode>(
+ system_settings_, *lookup_table_, ambisonic_order);
+ ambisonic_mixer_nodes_[ambisonic_order]->Connect(
+ ambisonic_mixing_encoder_nodes_[ambisonic_order]);
+ }
+
+ // Stereo mixing panner node used in non-HRTF sound object rendering.
+ stereo_mixing_panner_node_ =
+ std::make_shared<StereoMixingPannerNode>(system_settings_);
+ stereo_mixer_node_->Connect(stereo_mixing_panner_node_);
+
+ // Initialize room effects graphs.
+ InitializeReflectionsGraph();
+ InitializeReverbGraph();
+ // Initialize ambisonic output mixer.
+ ambisonic_output_mixer_.reset(
+ new Mixer(GetNumPeriphonicComponents(config_.max_ambisonic_order),
+ system_settings.GetFramesPerBuffer()));
+}
+
+void GraphManager::CreateAmbisonicSource(SourceId ambisonic_source_id,
+ size_t num_channels) {
+ DCHECK(source_nodes_.find(ambisonic_source_id) == source_nodes_.end());
+ // Create a new |ambisonic_source_node| and register to |source_nodes_|.
+ auto ambisonic_source_node = std::make_shared<BufferedSourceNode>(
+ ambisonic_source_id, num_channels, system_settings_.GetFramesPerBuffer());
+ source_nodes_[ambisonic_source_id] = ambisonic_source_node;
+
+ // Connect |ambisonic_source_node| to the ambisonic decoding pipeline.
+ const int ambisonic_order = GetPeriphonicAmbisonicOrder(num_channels);
+ auto direct_attenuation_node =
+ std::make_shared<GainNode>(ambisonic_source_id, num_channels,
+ AttenuationType::kDirect, system_settings_);
+ direct_attenuation_node->Connect(ambisonic_source_node);
+ if (ambisonic_order == 1) {
+ // First order case.
+ auto foa_rotator_node =
+ std::make_shared<FoaRotatorNode>(ambisonic_source_id, system_settings_);
+ foa_rotator_node->Connect(direct_attenuation_node);
+ ambisonic_mixer_nodes_[ambisonic_order]->Connect(foa_rotator_node);
+ } else {
+ // Higher orders case.
+ auto hoa_rotator_node = std::make_shared<HoaRotatorNode>(
+ ambisonic_source_id, system_settings_, ambisonic_order);
+ hoa_rotator_node->Connect(direct_attenuation_node);
+ ambisonic_mixer_nodes_[ambisonic_order]->Connect(hoa_rotator_node);
+ }
+ // Connect to room effects rendering pipeline.
+ auto mono_from_soundfield_node = std::make_shared<MonoFromSoundfieldNode>(
+ ambisonic_source_id, system_settings_);
+ mono_from_soundfield_node->Connect(ambisonic_source_node);
+ reflections_gain_mixer_node_->Connect(mono_from_soundfield_node);
+ reverb_gain_mixer_node_->Connect(mono_from_soundfield_node);
+}
+
+void GraphManager::CreateSoundObjectSource(SourceId sound_object_source_id,
+ int ambisonic_order,
+ bool enable_hrtf,
+ bool enable_direct_rendering) {
+ DCHECK(source_nodes_.find(sound_object_source_id) == source_nodes_.end());
+ // Create a new |sound_object_source_node| and register to |source_nodes_|.
+ auto sound_object_source_node = std::make_shared<BufferedSourceNode>(
+ sound_object_source_id, kNumMonoChannels,
+ system_settings_.GetFramesPerBuffer());
+ source_nodes_[sound_object_source_id] = sound_object_source_node;
+
+ // Create direct rendering pipeline.
+ if (enable_direct_rendering) {
+ auto direct_attenuation_node =
+ std::make_shared<GainNode>(sound_object_source_id, kNumMonoChannels,
+ AttenuationType::kDirect, system_settings_);
+ direct_attenuation_node->Connect(sound_object_source_node);
+ auto occlusion_node = std::make_shared<OcclusionNode>(
+ sound_object_source_id, system_settings_);
+ occlusion_node->Connect(direct_attenuation_node);
+ auto near_field_effect_node = std::make_shared<NearFieldEffectNode>(
+ sound_object_source_id, system_settings_);
+
+ if (enable_hrtf) {
+ ambisonic_mixing_encoder_nodes_[ambisonic_order]->Connect(occlusion_node);
+ } else {
+ stereo_mixing_panner_node_->Connect(occlusion_node);
+ }
+
+ near_field_effect_node->Connect(occlusion_node);
+ stereo_mixer_node_->Connect(near_field_effect_node);
+ }
+
+ // Connect to room effects rendering pipeline.
+ reflections_gain_mixer_node_->Connect(sound_object_source_node);
+ reverb_gain_mixer_node_->Connect(sound_object_source_node);
+}
+
+void GraphManager::EnableRoomEffects(bool enable) {
+ room_effects_enabled_ = enable;
+ reflections_gain_mixer_node_->SetMute(!room_effects_enabled_);
+ reverb_gain_mixer_node_->SetMute(!room_effects_enabled_);
+}
+
+const AudioBuffer* GraphManager::GetAmbisonicBuffer() const {
+ ambisonic_output_mixer_->Reset();
+ for (const auto& ambisonic_mixer_node_itr : ambisonic_mixer_nodes_) {
+ const auto* ambisonic_buffer =
+ ambisonic_mixer_node_itr.second->GetOutputBuffer();
+ if (ambisonic_buffer != nullptr) {
+ ambisonic_output_mixer_->AddInput(*ambisonic_buffer);
+ }
+ }
+ return ambisonic_output_mixer_->GetOutput();
+}
+
+const AudioBuffer* GraphManager::GetStereoBuffer() const {
+ return stereo_mixer_node_->GetOutputBuffer();
+}
+
+const AudioBuffer *GraphManager::GetReverbBuffer() const
+{
+ return reverb_node_->GetOutputBuffer();
+}
+
+size_t GraphManager::GetNumMaxAmbisonicChannels() const {
+ return GetNumPeriphonicComponents(config_.max_ambisonic_order);
+}
+
+bool GraphManager::GetRoomEffectsEnabled() const {
+ return room_effects_enabled_;
+}
+
+void GraphManager::UpdateRoomReflections() { reflections_node_->Update(); }
+
+void GraphManager::UpdateRoomReverb() { reverb_node_->Update(); }
+
+void GraphManager::InitializeReverbGraph() {
+ reverb_gain_mixer_node_ = std::make_shared<GainMixerNode>(
+ AttenuationType::kReverb, system_settings_, kNumMonoChannels);
+ reverb_node_ = std::make_shared<ReverbNode>(system_settings_, &fft_manager_);
+ reverb_node_->Connect(reverb_gain_mixer_node_);
+ stereo_mixer_node_->Connect(reverb_node_);
+}
+
+void GraphManager::InitializeReflectionsGraph() {
+ reflections_gain_mixer_node_ = std::make_shared<GainMixerNode>(
+ AttenuationType::kReflections, system_settings_, kNumMonoChannels);
+ reflections_node_ = std::make_shared<ReflectionsNode>(system_settings_);
+ reflections_node_->Connect(reflections_gain_mixer_node_);
+ // Reflections are limited to First Order Ambisonics to reduce complexity.
+ const int kAmbisonicOrder1 = 1;
+ ambisonic_mixer_nodes_[kAmbisonicOrder1]->Connect(reflections_node_);
+}
+
+void GraphManager::CreateAmbisonicPannerSource(SourceId sound_object_source_id,
+ bool enable_hrtf) {
+ DCHECK(source_nodes_.find(sound_object_source_id) == source_nodes_.end());
+ // Create a new |sound_object_source_node| and register to |source_nodes_|.
+ auto sound_object_source_node = std::make_shared<BufferedSourceNode>(
+ sound_object_source_id, kNumMonoChannels,
+ system_settings_.GetFramesPerBuffer());
+ source_nodes_[sound_object_source_id] = sound_object_source_node;
+
+ if (enable_hrtf) {
+ ambisonic_mixing_encoder_nodes_[config_.max_ambisonic_order]->Connect(
+ sound_object_source_node);
+ } else {
+ stereo_mixing_panner_node_->Connect(sound_object_source_node);
+ }
+}
+
+void GraphManager::CreateStereoSource(SourceId stereo_source_id) {
+ DCHECK(source_nodes_.find(stereo_source_id) == source_nodes_.end());
+ // Create a new |stereo_source_node| and register to |source_nodes_|.
+ auto stereo_source_node = std::make_shared<BufferedSourceNode>(
+ stereo_source_id, kNumStereoChannels,
+ system_settings_.GetFramesPerBuffer());
+ source_nodes_[stereo_source_id] = stereo_source_node;
+
+ // Connect |stereo_source_node| to the stereo rendering pipeline.
+ auto gain_node =
+ std::make_shared<GainNode>(stereo_source_id, kNumStereoChannels,
+ AttenuationType::kInput, system_settings_);
+ gain_node->Connect(stereo_source_node);
+ stereo_mixer_node_->Connect(gain_node);
+}
+
+void GraphManager::DestroySource(SourceId source_id) {
+ auto source_node = LookupSourceNode(source_id);
+ if (source_node != nullptr) {
+ // Disconnect the source from the graph.
+ source_node->MarkEndOfStream();
+ output_node_->CleanUp();
+ // Unregister the source from |source_nodes_|.
+ source_nodes_.erase(source_id);
+ }
+}
+
+std::shared_ptr<SinkNode> GraphManager::GetSinkNode() { return output_node_; }
+
+void GraphManager::Process() {
+
+ output_node_->ReadInputs();
+}
+
+AudioBuffer* GraphManager::GetMutableAudioBuffer(SourceId source_id) {
+ auto source_node = LookupSourceNode(source_id);
+ if (source_node == nullptr) {
+ return nullptr;
+ }
+ return source_node->GetMutableAudioBufferAndSetNewBufferFlag();
+}
+
+void GraphManager::InitializeAmbisonicRendererGraph(
+ int ambisonic_order, const std::string& sh_hrir_filename) {
+ CHECK_LE(ambisonic_order, config_.max_ambisonic_order);
+ const size_t num_channels = GetNumPeriphonicComponents(ambisonic_order);
+ // Create binaural decoder pipeline.
+ ambisonic_mixer_nodes_[ambisonic_order] =
+ std::make_shared<MixerNode>(system_settings_, num_channels);
+ auto ambisonic_binaural_decoder_node =
+ std::make_shared<AmbisonicBinauralDecoderNode>(
+ system_settings_, ambisonic_order, sh_hrir_filename, &fft_manager_,
+ &resampler_);
+ ambisonic_binaural_decoder_node->Connect(
+ ambisonic_mixer_nodes_[ambisonic_order]);
+ stereo_mixer_node_->Connect(ambisonic_binaural_decoder_node);
+}
+
+std::shared_ptr<BufferedSourceNode> GraphManager::LookupSourceNode(
+ SourceId source_id) {
+ auto source_node_itr = source_nodes_.find(source_id);
+ if (source_node_itr == source_nodes_.end()) {
+ LOG(WARNING) << "Source node " << source_id << " not found";
+ return nullptr;
+ }
+ return source_node_itr->second;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager.h b/src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager.h
new file mode 100644
index 000000000..818b6fa01
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager.h
@@ -0,0 +1,404 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_GRAPH_MANAGER_H_
+#define RESONANCE_AUDIO_GRAPH_GRAPH_MANAGER_H_
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+
+#include "ambisonics/ambisonic_lookup_table.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "config/global_config.h"
+#include "dsp/fft_manager.h"
+#include "dsp/resampler.h"
+#include "graph/ambisonic_binaural_decoder_node.h"
+#include "graph/ambisonic_mixing_encoder_node.h"
+#include "graph/buffered_source_node.h"
+#include "graph/gain_mixer_node.h"
+#include "graph/mixer_node.h"
+#include "graph/reflections_node.h"
+#include "graph/reverb_node.h"
+#include "graph/stereo_mixing_panner_node.h"
+#include "graph/system_settings.h"
+#include "node/sink_node.h"
+
+namespace vraudio {
+
+// The GraphManager class manages the construction and lifetime of the audio
+// processing graph. It owns the output node that connects the audio processing
+// graph to the audio hardware.
+class GraphManager {
+ public:
+ // Initializes GraphManager class.
+ //
+ // @param system_settings Global system configuration.
+ explicit GraphManager(const SystemSettings& system_settings);
+
+ // Returns the sink node the audio graph is connected to.
+ //
+ // @return Shared pointer of the sink node.
+ std::shared_ptr<SinkNode> GetSinkNode();
+
+ // Triggers processing of the audio graph for all the connected nodes.
+ void Process();
+
+ // Returns a mutable pointer to the |AudioBuffer| of an audio source with
+ // given |source_id|. Calls to this method must be synchronized with the audio
+ // graph processing.
+ //
+ // @param source_id Source id.
+ // @return Mutable audio buffer pointer. Nullptr if source_id not found.
+ AudioBuffer* GetMutableAudioBuffer(SourceId source_id);
+
+ // Creates an ambisonic panner source with given |sound_object_source_id|.
+ //
+ // Processing graph:
+ //
+ // +-------------------+
+ // | |
+ // +------------+ SoundObjectSource +----------+
+ // | | | |
+ // | +---------+---------+ |
+ // | |
+ // +-----------v-----------+ +---------v----------+
+ // | | | |
+ // | AmbisonicMixingPanner | | StereoMixingPanner |
+ // | | | |
+ // +-----------+-----------+ +---------+----------+
+ // | |
+ // +-----------v-----------+ +---------v----------+
+ // | | | |
+ // | AmbisonicMixer | | StereoMixer |
+ // | | | |
+ // +-----------+-----------+ +--------------------+
+ //
+ //
+ // @param sound_object_source_id Id of sound object source.
+ // @param enable_hrtf Flag to enable HRTF-based spatialization.
+ void CreateAmbisonicPannerSource(SourceId sound_object_source_id,
+ bool enable_hrtf);
+
+ // Creates a new stereo non-spatialized source with given |stereo_source_id|.
+ //
+ // Processing graph:
+ //
+ // +--------------+
+ // | |
+ // | StereoSource |
+ // | |
+ // +-------+------+
+ // |
+ // +-------v------+
+ // | |
+ // | Gain |
+ // | |
+ // +-------+------+
+ // |
+ // +-------V------+
+ // | |
+ // | StereoMixer |
+ // | |
+ // +--------------+
+ //
+ // @param stereo_source_id Id of new stereo source.
+ void CreateStereoSource(SourceId stereo_source_id);
+
+ // Destroys source with given |source_id|. Note that this call only sets a
+ // flag to indicate that this source can be removed. The actual disconnect
+ // happens from the audio processing thread the next time the processing graph
+ // is triggered.
+ //
+ // @param source_id Id of source to be destroyed.
+ void DestroySource(SourceId source_id);
+
+ // Creates a new ambisonic source subgraph with given |ambisonic_source_id|.
+ // Note: Ambisonic source subgraph is only created if the rendering mode is
+ // HRTF.
+ //
+ // Processing graph (all the graphs created using http://asciiflow.com/):
+ //
+ // +-----------------+
+ // | |
+ // +-------+ AmbisonicSource +-------+
+ // | | | |
+ // | +-----------------+ |
+ // | |
+ // +----v---+ +----------v---------+
+ // | | | |
+ // | Gain | +--+ MonoFromSoundfield +--+
+ // | | | | | |
+ // +----+---+ | +--------------------+ |
+ // | | |
+ // | | |
+ // +--------v-------+ +--------v---------+ +------v------+
+ // | | | | | |
+ // | Foa/HoaRotator | | ReflectionsMixer | | ReverbMixer |
+ // | | | | | |
+ // +--------+-------+ +--------+---------+ +------+------+
+ // |
+ // +--------v-------+
+ // | |
+ // | AmbisonicMixer |
+ // | |
+ // +--------+-------+
+ //
+ // @param ambisonic_source_id Id of new ambisonic source.
+ // @param num_channels Number of input channels of ambisonic source node.
+ void CreateAmbisonicSource(SourceId ambisonic_source_id, size_t num_channels);
+
+ // Creates a new sound object source with given |sound_object_source_id|.
+ //
+ // Processing graph:
+ //
+ // +-------------------+
+ // | |
+ // +-------------+ SoundObjectSource +----------+
+ // | | | |
+ // | +---------+---------+ |
+ // | | |
+ // +----------v-----------+ +---------v---------+ +--------v--------+
+ // | | | | | |
+ // | ReflectionsGainMixer | | DirectAttenuation | | ReverbGainMixer |
+ // | | | | | |
+ // +----------+-----------+ +---------+---------+ +--------+--------+
+ // |
+ // +---------v---------+
+ // HRTF | | Stereo Panning
+ // +------------+ Occlusion +----------+
+ // | | | |
+ // | +---------+---------+ |
+ // | | |
+ // +-----------v-----------+ +--------v--------+ +---------v----------+
+ // | | | | | |
+ // | AmbisonicMixingPanner | | NearFieldEffect | | StereoMixingPanner |
+ // | | | | | |
+ // +-----------+-----------+ +--------+--------+ +---------+----------+
+ // | | |
+ // +-----------v-----------+ +--------v--------+ |
+ // | | | | |
+ // | AmbisonicMixer | | StereoMixer <-----------+
+ // | | | |
+ // +-----------+-----------+ +-----------------+
+ //
+ //
+ // @param sound_object_source_id Id of sound object source.
+ // @param ambisonic_order Ambisonic order to encode the sound object source.
+ // @param enable_hrtf Flag to enable HRTF-based rendering.
+ // @param enable_direct_rendering Flag to enable direct source rendering.
+ void CreateSoundObjectSource(SourceId sound_object_source_id,
+ int ambisonic_order, bool enable_hrtf,
+ bool enable_direct_rendering);
+
+ // Mutes on/off the room effects mixers.
+ //
+ // @param Whether to enable room effects.
+ void EnableRoomEffects(bool enable);
+
+ // Returns the last processed output audio buffer of the ambisonic mix with
+ // the highest possible ambisonic channel configuration. Note that, this
+ // method will *not* trigger the processing of the audio graph.
+ // |GraphManager::Process| must be called prior to this method call to ensure
+ // that the output buffer is up-to-date.
+ //
+ // @return Output audio buffer of the ambisonic mix, or nullptr if no output.
+ const AudioBuffer* GetAmbisonicBuffer() const;
+
+ // Returns the last processed output audio buffer of the stereo (binaural)
+ // mix. Note that, this method will *not* trigger the processing of the audio
+ // graph. |GraphManager::Process| must be called prior to this method call to
+ // ensure that the output buffer is up-to-date.
+ //
+ // @return Output audio buffer of the stereo mix, or nullptr if no output.
+ const AudioBuffer* GetStereoBuffer() const;
+
+ // Returns the last processed buffer containing the reverb data for the room.
+ // The buffer contains stereo data.
+ // Note that, this method will *not* trigger the processing of the audio
+ // graph. |GraphManager::Process| must be called prior to this method call to
+ // ensure that the buffer is up-to-date.
+ //
+ // @return Room reverb audio buffer, or nullptr if no output.
+ const AudioBuffer* GetReverbBuffer() const;
+
+ // Returns the maximum allowed number of ambisonic channels.
+ //
+ // @return Number of channels based on Ambisonic order in the global config.
+ size_t GetNumMaxAmbisonicChannels() const;
+
+ // Returns whether the room effects graph is enabled.
+ //
+ // @return True if room effects are enabled.
+ bool GetRoomEffectsEnabled() const;
+
+ // Updates the room reflections with the current properties for room effects
+ // processing.
+ void UpdateRoomReflections();
+
+ // Updates the room reverb.
+ void UpdateRoomReverb();
+
+ private:
+ // Initializes the Ambisonic renderer subgraph for the speficied Ambisonic
+ // order and connects it to the |StereoMixerNode|.
+ //
+ // Processing graph:
+ //
+ // +------------------+
+ // | |
+ // | AmbisonicMixer |
+ // | |
+ // +--------+---------+
+ // |
+ // |
+ // +------------v-------------+
+ // | |
+ // | AmbisonicBinauralDecoder |
+ // | |
+ // +------------+-------------+
+ // |
+ // |
+ // +-----------v------------+
+ // | |
+ // | StereoMixer |
+ // | |
+ // +------------------------+
+ //
+ // @param ambisonic_order Ambisonic order.
+ // @param sh_hrir_filename Filename to load the HRIR data from.
+ void InitializeAmbisonicRendererGraph(int ambisonic_order,
+ const std::string& sh_hrir_filename);
+
+ // Helper method to lookup a source node with given |source_id|.
+ //
+ // @param source_id Source id.
+ // @returns Shared pointer to source node instance, nullptr if not found.
+ std::shared_ptr<BufferedSourceNode> LookupSourceNode(SourceId source_id);
+
+ // Creates an audio subgraph that renders early reflections based on a room
+ // model on a single mix.
+ //
+ // Processing graph:
+ //
+ // +---------------------------+
+ // | |
+ // | ReflectionsGainMixer |
+ // | |
+ // +-------------+-------------+
+ // |
+ // +----------v----------+
+ // | |
+ // | Reflections |
+ // | |
+ // +----------+----------+
+ // |
+ // +----------v----------+
+ // | |
+ // | AmbisonicMixer |
+ // | |
+ // +----------+----------+
+ //
+ void InitializeReflectionsGraph();
+
+ // Creates an audio subgraph that renders a reverb from a mono mix of all the
+ // sound objects based on a room model.
+ //
+ // Processing graph:
+ //
+ // +-----------------+
+ // | |
+ // | ReverbGainMixer |
+ // | |
+ // +--------+--------+
+ // |
+ // +--------v--------+
+ // | |
+ // | Reverb |
+ // | |
+ // +--------+--------+
+ // |
+ // +--------v--------+
+ // | |
+ // | StereoMixer |
+ // | |
+ // +-----------------+
+ //
+ void InitializeReverbGraph();
+
+ // Flag indicating if room effects are enabled.
+ bool room_effects_enabled_;
+
+ // Mono mixer to accumulate all reverb sources.
+ std::shared_ptr<GainMixerNode> reverb_gain_mixer_node_;
+
+ // Reflections node.
+ std::shared_ptr<ReflectionsNode> reflections_node_;
+
+ // Mono mixer node to accumulate the early reflection sources.
+ std::shared_ptr<GainMixerNode> reflections_gain_mixer_node_;
+
+ // Reverb node.
+ std::shared_ptr<ReverbNode> reverb_node_;
+
+ // Ambisonic output mixer to accumulate incoming ambisonic inputs into a
+ // single ambisonic output buffer.
+ std::unique_ptr<Mixer> ambisonic_output_mixer_;
+
+ // Global config passed in during construction.
+ const GraphManagerConfig config_;
+
+ // Manages system wide settings.
+ const SystemSettings& system_settings_;
+
+ // Provides Ambisonic encoding coefficients.
+ std::unique_ptr<AmbisonicLookupTable> lookup_table_;
+
+ // |FftManager| to be used in nodes that require FFT transformations.
+ FftManager fft_manager_;
+
+ // |Resampler| to be used to convert HRIRs to the system sample rate.
+ Resampler resampler_;
+
+ // Ambisonic mixer nodes per each ambisonic order to accumulate the
+ // ambisonic sources for the corresponding binaural Ambisonic decoders.
+ std::unordered_map<int, std::shared_ptr<MixerNode>> ambisonic_mixer_nodes_;
+
+ // Stereo mixer to combine all the stereo and binaural output.
+ std::shared_ptr<MixerNode> stereo_mixer_node_;
+
+ // Ambisonic mixing encoder node to apply encoding coefficients and accumulate
+ // the Ambisonic buffers.
+ std::unordered_map<int, std::shared_ptr<AmbisonicMixingEncoderNode>>
+ ambisonic_mixing_encoder_nodes_;
+
+ // Stereo mixing panner node to apply stereo panning gains and accumulate the
+ // buffers.
+ std::shared_ptr<StereoMixingPannerNode> stereo_mixing_panner_node_;
+
+ // Output node that enables audio playback of a single audio stream.
+ std::shared_ptr<SinkNode> output_node_;
+
+ // Holds all registered source nodes (independently of their type) and
+ // allows look up by id.
+ std::unordered_map<SourceId, std::shared_ptr<BufferedSourceNode>>
+ source_nodes_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_GRAPH_MANAGER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager_config.h b/src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager_config.h
new file mode 100644
index 000000000..f3c310a06
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/graph_manager_config.h
@@ -0,0 +1,40 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_GRAPH_MANAGER_CONFIG_H_
+#define RESONANCE_AUDIO_GRAPH_GRAPH_MANAGER_CONFIG_H_
+
+#include <string>
+#include <utility>
+#include <vector>
+
+namespace vraudio {
+
+// Configuration of the GraphManager and the nodes it is instantiating.
+struct GraphManagerConfig {
+ // Configuration name.
+ std::string configuration_name;
+
+ // Maximum ambisonic order allowed.
+ int max_ambisonic_order = 1;
+
+ // HRIR filenames (second element) per ambisonic order (first element).
+ std::vector<std::pair<int, std::string>> sh_hrir_filenames = {};
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_GRAPH_MANAGER_CONFIG_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/hoa_rotator_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/hoa_rotator_node.cc
new file mode 100644
index 000000000..4ffae89c3
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/hoa_rotator_node.cc
@@ -0,0 +1,69 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/hoa_rotator_node.h"
+
+#include "ambisonics/utils.h"
+#include "base/logging.h"
+
+
+namespace vraudio {
+
+HoaRotatorNode::HoaRotatorNode(SourceId source_id,
+ const SystemSettings& system_settings,
+ int ambisonic_order)
+ : system_settings_(system_settings),
+ hoa_rotator_(ambisonic_order),
+ output_buffer_(GetNumPeriphonicComponents(ambisonic_order),
+ system_settings.GetFramesPerBuffer()) {
+ output_buffer_.Clear();
+ output_buffer_.set_source_id(source_id);
+}
+
+const AudioBuffer* HoaRotatorNode::AudioProcess(const NodeInput& input) {
+
+
+ const AudioBuffer* input_buffer = input.GetSingleInput();
+ DCHECK(input_buffer);
+ DCHECK_GT(input_buffer->num_frames(), 0U);
+ DCHECK_GE(input_buffer->num_channels(), 4U);
+ DCHECK_EQ(input_buffer->source_id(), output_buffer_.source_id());
+
+ // Rotate soundfield buffer by the inverse head orientation.
+ const auto source_parameters =
+ system_settings_.GetSourceParameters(input_buffer->source_id());
+ if (source_parameters == nullptr) {
+ LOG(WARNING) << "Could not find source parameters";
+ return nullptr;
+ }
+
+ const WorldRotation& source_rotation =
+ source_parameters->object_transform.rotation;
+ const WorldRotation inverse_head_rotation =
+ system_settings_.GetHeadRotation().conjugate();
+ const WorldRotation rotation = inverse_head_rotation * source_rotation;
+ const bool rotation_applied =
+ hoa_rotator_.Process(rotation, *input_buffer, &output_buffer_);
+
+ if (!rotation_applied) {
+ return input_buffer;
+ }
+
+ // Copy buffer parameters.
+ return &output_buffer_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/hoa_rotator_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/hoa_rotator_node.h
new file mode 100644
index 000000000..1ad3442be
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/hoa_rotator_node.h
@@ -0,0 +1,55 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_HOA_ROTATOR_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_HOA_ROTATOR_NODE_H_
+
+#include <memory>
+
+#include "ambisonics/hoa_rotator.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Node that accepts a single PeriphonicSoundfieldBuffer as input and outputs a
+// rotated PeriphonicSoundfieldBuffer of the corresponding soundfield input
+// using head rotation information from the system settings.
+class HoaRotatorNode : public ProcessingNode {
+ public:
+ HoaRotatorNode(SourceId source_id, const SystemSettings& system_settings,
+ int ambisonic_order);
+
+ protected:
+ // Implements ProcessingNode. Returns a null pointer if we are in stereo
+ // loudspeaker or stereo pan mode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ const SystemSettings& system_settings_;
+
+ // Soundfield rotator used to rotate higher order soundfields.
+ HoaRotator hoa_rotator_;
+
+ // Output buffer.
+ AudioBuffer output_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_HOA_ROTATOR_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node.cc
new file mode 100644
index 000000000..8bb91c767
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node.cc
@@ -0,0 +1,57 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/mixer_node.h"
+
+
+
+namespace vraudio {
+
+MixerNode::MixerNode(const SystemSettings& system_settings, size_t num_channels)
+ : num_channels_(num_channels),
+ mixer_(num_channels_, system_settings.GetFramesPerBuffer()) {
+ DCHECK_NE(num_channels_, 0U);
+ EnableProcessOnEmptyInput(true);
+}
+
+const AudioBuffer* MixerNode::GetOutputBuffer() const {
+ return mixer_.GetOutput();
+}
+
+bool MixerNode::CleanUp() {
+ CallCleanUpOnInputNodes();
+ // Prevent node from being disconnected when all sources are removed.
+ return false;
+}
+
+const AudioBuffer* MixerNode::AudioProcess(const NodeInput& input) {
+
+
+ mixer_.Reset();
+
+ const auto& input_buffers = input.GetInputBuffers();
+ if (input_buffers.empty()) {
+ return nullptr;
+ }
+
+ for (auto input_buffer : input_buffers) {
+ DCHECK_EQ(input_buffer->num_channels(), num_channels_);
+ mixer_.AddInput(*input_buffer);
+ }
+ return mixer_.GetOutput();
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node.h
new file mode 100644
index 000000000..0fe88f98b
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node.h
@@ -0,0 +1,54 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_MIXER_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_MIXER_NODE_H_
+
+#include "base/audio_buffer.h"
+#include "dsp/mixer.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Accepts multiple input buffers and outputs a downmix to a single output
+// buffer. All input buffers must have the same number of channels and the same
+// number of frames per buffer.
+class MixerNode : public ProcessingNode {
+ public:
+ MixerNode(const SystemSettings& system_settings, size_t num_channels);
+
+ // Returns the current output buffer of the mixer.
+ //
+ // @return Output audio buffer.
+ const AudioBuffer* GetOutputBuffer() const;
+
+ // Node implementation.
+ bool CleanUp() final;
+
+ protected:
+ // Implements ProcessingNode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ const size_t num_channels_;
+
+ Mixer mixer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_MIXER_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node_test.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node_test.cc
new file mode 100644
index 000000000..db9e72e17
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/mixer_node_test.cc
@@ -0,0 +1,112 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/mixer_node.h"
+
+#include <algorithm>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/logging.h"
+#include "graph/system_settings.h"
+#include "node/sink_node.h"
+#include "node/source_node.h"
+
+namespace vraudio {
+
+namespace {
+
+// Helper class to detect destruction.
+class DeletionDetector {
+ public:
+ explicit DeletionDetector(bool* node_deletion_flag)
+ : node_deletion_flag_(node_deletion_flag) {}
+ ~DeletionDetector() {
+ if (node_deletion_flag_ != nullptr) {
+ *node_deletion_flag_ = true;
+ }
+ }
+
+ private:
+ bool* node_deletion_flag_;
+};
+
+// Wraps |SourceNode| to detect its deletion.
+class MySourceNode : public SourceNode, DeletionDetector {
+ public:
+ explicit MySourceNode(bool* node_deletion_flag)
+ : SourceNode(), DeletionDetector(node_deletion_flag) {}
+
+ protected:
+ const AudioBuffer* AudioProcess() final { return nullptr; }
+};
+
+// Wraps |MixerNode| to detect its deletion.
+class MyAudioMixerNode : public MixerNode, DeletionDetector {
+ public:
+ explicit MyAudioMixerNode(bool* node_deletion_flag,
+ const SystemSettings& system_settings)
+ : MixerNode(system_settings, kNumMonoChannels),
+ DeletionDetector(node_deletion_flag) {}
+};
+
+// Wraps |SinkNode| to detect its deletion.
+class MySinkNode : public SinkNode, DeletionDetector {
+ public:
+ explicit MySinkNode(bool* node_deletion_flag)
+ : SinkNode(), DeletionDetector(node_deletion_flag) {}
+};
+
+// Tests that the |MixerNode| keeps connected at the moment all of its sources
+// are removed.
+TEST(AudioNodesTest, cleanUpOnEmptyInputTest) {
+ SystemSettings system_settings_(kNumMonoChannels, 128 /* frames_per_buffer */,
+ 48000 /* sample_rate_hz */);
+
+ bool source_node_deleted = false;
+ bool mixer_node_deleted = false;
+ bool sink_node_deleted = false;
+
+ auto sink_node = std::make_shared<MySinkNode>(&sink_node_deleted);
+
+ {
+ // Create a source and mixer node and connect it to sink node.
+ auto source_node = std::make_shared<MySourceNode>(&source_node_deleted);
+ auto mixer_node = std::make_shared<MyAudioMixerNode>(&mixer_node_deleted,
+ system_settings_);
+
+ // Connect nodes.
+ sink_node->Connect(mixer_node);
+ mixer_node->Connect(source_node);
+
+ // End of stream is marked in source node. Do not expect any data anymore.
+ source_node->MarkEndOfStream();
+ }
+
+ EXPECT_FALSE(source_node_deleted);
+ EXPECT_FALSE(mixer_node_deleted);
+ EXPECT_FALSE(sink_node_deleted);
+
+ sink_node->CleanUp();
+
+ EXPECT_TRUE(source_node_deleted);
+ EXPECT_FALSE(mixer_node_deleted);
+ EXPECT_FALSE(sink_node_deleted);
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/mono_from_soundfield_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/mono_from_soundfield_node.cc
new file mode 100644
index 000000000..0519be5ef
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/mono_from_soundfield_node.cc
@@ -0,0 +1,45 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/mono_from_soundfield_node.h"
+
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+MonoFromSoundfieldNode::MonoFromSoundfieldNode(
+ SourceId source_id, const SystemSettings& system_settings)
+ : output_buffer_(kNumMonoChannels, system_settings.GetFramesPerBuffer()) {
+ output_buffer_.set_source_id(source_id);
+ output_buffer_.Clear();
+}
+
+const AudioBuffer* MonoFromSoundfieldNode::AudioProcess(
+ const NodeInput& input) {
+
+
+ const AudioBuffer* input_buffer = input.GetSingleInput();
+ DCHECK(input_buffer);
+ DCHECK_EQ(input_buffer->source_id(), output_buffer_.source_id());
+ DCHECK_NE(input_buffer->num_channels(), 0U);
+ DCHECK_EQ(input_buffer->num_frames(), output_buffer_.num_frames());
+ // Get W channel of the ambisonic input.
+ output_buffer_[0] = (*input_buffer)[0];
+
+ return &output_buffer_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/mono_from_soundfield_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/mono_from_soundfield_node.h
new file mode 100644
index 000000000..6e8525e17
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/mono_from_soundfield_node.h
@@ -0,0 +1,44 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_MONO_FROM_SOUNDFIELD_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_MONO_FROM_SOUNDFIELD_NODE_H_
+
+#include "base/audio_buffer.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Node that accepts an ambisonic buffer as input and extracts its W channel
+// onto a mono output buffer.
+class MonoFromSoundfieldNode : public ProcessingNode {
+ public:
+ MonoFromSoundfieldNode(SourceId source_id,
+ const SystemSettings& system_settings);
+
+ protected:
+ // Implements |ProcessingNode|.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ // Mono audio buffer to store output data.
+ AudioBuffer output_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_MONO_FROM_SOUNDFIELD_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node.cc
new file mode 100644
index 000000000..2b75ae6e9
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node.cc
@@ -0,0 +1,117 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/near_field_effect_node.h"
+
+#include <algorithm>
+#include <cmath>
+
+#include "base/logging.h"
+#include "base/spherical_angle.h"
+
+#include "dsp/distance_attenuation.h"
+#include "dsp/gain.h"
+#include "dsp/stereo_panner.h"
+
+namespace vraudio {
+
+NearFieldEffectNode::NearFieldEffectNode(SourceId source_id,
+ const SystemSettings& system_settings)
+ : pan_gains_({0.0f, 0.0f}),
+ near_field_processor_(system_settings.GetSampleRateHz(),
+ system_settings.GetFramesPerBuffer()),
+ system_settings_(system_settings),
+ output_buffer_(kNumStereoChannels, system_settings.GetFramesPerBuffer()) {
+ output_buffer_.set_source_id(source_id);
+}
+
+const AudioBuffer* NearFieldEffectNode::AudioProcess(const NodeInput& input) {
+
+
+ const AudioBuffer* input_buffer = input.GetSingleInput();
+ DCHECK(input_buffer);
+ DCHECK_EQ(input_buffer->num_channels(), 1U);
+ DCHECK_EQ(input_buffer->source_id(), output_buffer_.source_id());
+
+ const auto source_parameters =
+ system_settings_.GetSourceParameters(input_buffer->source_id());
+ if (source_parameters == nullptr) {
+ LOG(WARNING) << "Could not find source parameters";
+ return nullptr;
+ }
+
+
+ DCHECK_EQ(pan_gains_.size(), kNumStereoChannels);
+ const float near_field_gain = source_parameters->near_field_gain;
+ if (near_field_gain > 0.0f) {
+ const auto& listener_position = system_settings_.GetHeadPosition();
+ const auto& listener_rotation = system_settings_.GetHeadRotation();
+ const auto& source_transform = source_parameters->object_transform;
+ // Compute the relative source direction in spherical angles to calculate
+ // the left and right panner gains.
+ WorldPosition relative_direction;
+ GetRelativeDirection(listener_position, listener_rotation,
+ source_transform.position, &relative_direction);
+ const auto source_direction =
+ SphericalAngle::FromWorldPosition(relative_direction);
+ CalculateStereoPanGains(source_direction, &pan_gains_);
+ // Combine pan gains with per-source near field gain.
+ const float total_near_field_gain =
+ ComputeNearFieldEffectGain(listener_position,
+ source_transform.position) *
+ near_field_gain / kMaxNearFieldEffectGain;
+ for (size_t i = 0; i < pan_gains_.size(); ++i) {
+ pan_gains_[i] *= total_near_field_gain;
+ }
+ } else {
+ // Disable near field effect if |near_field_gain| is zero.
+ std::fill(pan_gains_.begin(), pan_gains_.end(), 0.0f);
+ }
+
+ const float left_current_gain = left_panner_.GetGain();
+ const float right_current_gain = right_panner_.GetGain();
+ const float left_target_gain = pan_gains_[0];
+ const float right_target_gain = pan_gains_[1];
+ const bool is_left_zero_gain =
+ IsGainNearZero(left_current_gain) && IsGainNearZero(left_target_gain);
+ const bool is_right_zero_gain =
+ IsGainNearZero(right_current_gain) && IsGainNearZero(right_target_gain);
+
+ if (is_left_zero_gain && is_right_zero_gain) {
+ // Make sure gain processors are initialized.
+ left_panner_.Reset(0.0f);
+ right_panner_.Reset(0.0f);
+ // Both channels go to zero, there is no need for further processing.
+ return nullptr;
+ }
+
+ const auto& input_channel = (*input_buffer)[0];
+ auto* left_output_channel = &output_buffer_[0];
+ auto* right_output_channel = &output_buffer_[1];
+ // Apply bass boost and delay compensation (if necessary) to the input signal
+ // and place it temporarily in the right output channel. This way we avoid
+ // allocating a temporary buffer.
+ near_field_processor_.Process(input_channel, right_output_channel,
+ source_parameters->enable_hrtf);
+ left_panner_.ApplyGain(left_target_gain, *right_output_channel,
+ left_output_channel, /*accumulate_output=*/false);
+ right_panner_.ApplyGain(right_target_gain, *right_output_channel,
+ right_output_channel, /*accumulate_output=*/false);
+
+ return &output_buffer_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node.h
new file mode 100644
index 000000000..83b8c6d69
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node.h
@@ -0,0 +1,69 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_NEAR_FIELD_EFFECT_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_NEAR_FIELD_EFFECT_NODE_H_
+
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "dsp/gain_processor.h"
+#include "dsp/near_field_processor.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Node that accepts a single mono audio buffer as input, applies an appoximate
+// near field effect and outputs a processed stereo audio buffer. The stereo
+// output buffer can then be combined with a binaural output in order to
+// simulate a sound source which is close (<1m) to the listener's head.
+class NearFieldEffectNode : public ProcessingNode {
+ public:
+ // Constructor.
+ //
+ // @param source_id Output buffer source id.
+ // @param system_settings Global system settings.
+ NearFieldEffectNode(SourceId source_id,
+ const SystemSettings& system_settings);
+
+ protected:
+ // Implements ProcessingNode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ // Left and right processors apply both near field gain and panner gains.
+ GainProcessor left_panner_;
+ GainProcessor right_panner_;
+
+ // Left and right gains for near field and panning combined.
+ std::vector<float> pan_gains_;
+
+ // Near field processor used to apply approximate near field effect to the
+ // mono source signal.
+ NearFieldProcessor near_field_processor_;
+
+ // Used to obtain head rotation.
+ const SystemSettings& system_settings_;
+
+ // Output buffer.
+ AudioBuffer output_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_NEAR_FIELD_EFFECT_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node_test.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node_test.cc
new file mode 100644
index 000000000..1117ccd21
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/near_field_effect_node_test.cc
@@ -0,0 +1,127 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/near_field_effect_node.h"
+
+#include <memory>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "dsp/distance_attenuation.h"
+#include "dsp/stereo_panner.h"
+#include "graph/buffered_source_node.h"
+#include "node/sink_node.h"
+#include "node/source_node.h"
+#include "utils/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+// Source Id for use with |BufferedSourceNode|.
+const SourceId kSourceId = 0;
+
+// Number of frames per buffer.
+const size_t kFramesPerBuffer = kUnitRampLength;
+
+// Sampling rate.
+const int kSampleRate = 48000;
+
+// Source distances.
+const size_t kNumDistances = 5;
+const float kDistances[kNumDistances] = {0.0f, 0.25f, 0.5f, 0.75f, 10.0f};
+
+// Maximum expected gain change determines the number of buffers we need to wait
+// for the output sample values to settle.
+const size_t kMaxExpectedGainChange = 9;
+
+// Expected offset due to near field processor delay compensation at 48000kHz.
+const size_t kExpectedDelay = 31;
+
+// Expected Dirac pulse attenuation due to shelf-filtering at 48000kHz.
+const float KExpectedPeakReduction = 0.87319273f;
+
+} // namespace
+
+TEST(NearFieldEffectNodeTest, VariousDistanceTest) {
+ const size_t kDiracOffset = kFramesPerBuffer / 2;
+ // We add one extra buffer since the Dirac is in the middle of the buffer.
+ const size_t kBuffersToSettle = kMaxExpectedGainChange + 1;
+ const auto kIdentityRotation = WorldRotation();
+ SystemSettings system_settings(kNumStereoChannels, kFramesPerBuffer,
+ kSampleRate);
+
+ // Create the simple audio graph.
+ auto near_field_effect_node =
+ std::make_shared<NearFieldEffectNode>(kSourceId, system_settings);
+ auto input_node = std::make_shared<BufferedSourceNode>(
+ kSourceId, kNumMonoChannels, kFramesPerBuffer);
+ auto output_node = std::make_shared<SinkNode>();
+ near_field_effect_node->Connect(input_node);
+ output_node->Connect(near_field_effect_node);
+ auto parameters_manager = system_settings.GetSourceParametersManager();
+ parameters_manager->Register(kSourceId);
+
+ const AudioBuffer* output_buffer;
+ for (size_t i = 0; i < kNumDistances; ++i) {
+ const WorldPosition input_position(kDistances[i], 0.0f, 0.0f);
+ // Loop till gain processors have reached steady state.
+ for (size_t settle = 0; settle < kBuffersToSettle; ++settle) {
+ AudioBuffer* const input_node_buffer =
+ input_node->GetMutableAudioBufferAndSetNewBufferFlag();
+ GenerateDiracImpulseFilter(kDiracOffset, &(*input_node_buffer)[0]);
+
+ auto source_parameters =
+ parameters_manager->GetMutableParameters(kSourceId);
+ source_parameters->object_transform.position = input_position;
+ source_parameters->near_field_gain = kMaxNearFieldEffectGain;
+ // Retrieve the output.
+ const auto& buffer_vector = output_node->ReadInputs();
+ if (!buffer_vector.empty()) {
+ EXPECT_EQ(buffer_vector.size(), 1U);
+ output_buffer = buffer_vector.front();
+ } else {
+ output_buffer = nullptr;
+ }
+ }
+
+ std::vector<float> stereo_pan_gains(kNumStereoChannels, 0.0f);
+ // These methods are tested elsewhere. Their output will be used to
+ // determine if the output from the |NearfieldEffectNode| is correct.
+ WorldPosition relative_direction;
+ GetRelativeDirection(system_settings.GetHeadPosition(), kIdentityRotation,
+ input_position, &relative_direction);
+ const SphericalAngle source_direction =
+ SphericalAngle::FromWorldPosition(relative_direction);
+ CalculateStereoPanGains(source_direction, &stereo_pan_gains);
+ const float near_field_gain = ComputeNearFieldEffectGain(
+ system_settings.GetHeadPosition(), input_position);
+ if (i < kNumDistances - 1) {
+ EXPECT_FALSE(output_buffer == nullptr);
+ EXPECT_NEAR(
+ near_field_gain * stereo_pan_gains[0] * KExpectedPeakReduction,
+ (*output_buffer)[0][kDiracOffset + kExpectedDelay], kEpsilonFloat);
+ EXPECT_NEAR(
+ near_field_gain * stereo_pan_gains[1] * KExpectedPeakReduction,
+ (*output_buffer)[1][kDiracOffset + kExpectedDelay], kEpsilonFloat);
+ } else {
+ EXPECT_TRUE(output_buffer == nullptr);
+ }
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node.cc
new file mode 100644
index 000000000..3805836f5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node.cc
@@ -0,0 +1,101 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/occlusion_node.h"
+
+#include <cmath>
+
+#include "base/logging.h"
+#include "base/spherical_angle.h"
+
+#include "dsp/occlusion_calculator.h"
+
+namespace vraudio {
+
+namespace {
+
+// Low pass filter coefficient for smoothing the applied occlusion. This avoids
+// sudden unrealistic changes in the volume of a sound object. Range [0, 1].
+// The value below has been calculated empirically.
+const float kOcclusionSmoothingCoefficient = 0.75f;
+
+// This function provides first order low-pass filtering. It is used to smooth
+// the occlusion parameter.
+float Interpolate(float coefficient, float previous_value, float target_value) {
+ return target_value + coefficient * (previous_value - target_value);
+}
+
+} // namespace
+
+OcclusionNode::OcclusionNode(SourceId source_id,
+ const SystemSettings& system_settings)
+ : system_settings_(system_settings),
+ low_pass_filter_(0.0f),
+ current_occlusion_(0.0f),
+ output_buffer_(kNumMonoChannels, system_settings.GetFramesPerBuffer()) {
+ output_buffer_.Clear();
+ output_buffer_.set_source_id(source_id);
+}
+
+const AudioBuffer* OcclusionNode::AudioProcess(const NodeInput& input) {
+
+ const AudioBuffer* input_buffer = input.GetSingleInput();
+ DCHECK(input_buffer);
+ DCHECK_EQ(input_buffer->source_id(), output_buffer_.source_id());
+
+ const auto source_parameters =
+ system_settings_.GetSourceParameters(input_buffer->source_id());
+ if (source_parameters == nullptr) {
+ LOG(WARNING) << "Could not find source parameters";
+ return nullptr;
+ }
+
+ const WorldPosition& listener_position = system_settings_.GetHeadPosition();
+ const WorldRotation& listener_rotation = system_settings_.GetHeadRotation();
+ const ObjectTransform& source_transform = source_parameters->object_transform;
+ // Compute the relative listener/source direction in spherical angles.
+ WorldPosition relative_direction;
+ GetRelativeDirection(listener_position, listener_rotation,
+ source_transform.position, &relative_direction);
+ const SphericalAngle listener_direction =
+ SphericalAngle::FromWorldPosition(relative_direction);
+
+ GetRelativeDirection(source_transform.position, source_transform.rotation,
+ listener_position, &relative_direction);
+ const SphericalAngle source_direction =
+ SphericalAngle::FromWorldPosition(relative_direction);
+ // Calculate low-pass filter coefficient based on listener/source directivity
+ // and occlusion values.
+ const float listener_directivity = CalculateDirectivity(
+ source_parameters->listener_directivity_alpha,
+ source_parameters->listener_directivity_order, listener_direction);
+ const float source_directivity = CalculateDirectivity(
+ source_parameters->directivity_alpha,
+ source_parameters->directivity_order, source_direction);
+ current_occlusion_ =
+ Interpolate(kOcclusionSmoothingCoefficient, current_occlusion_,
+ source_parameters->occlusion_intensity);
+ const float filter_coefficient = CalculateOcclusionFilterCoefficient(
+ listener_directivity * source_directivity, current_occlusion_);
+ low_pass_filter_.SetCoefficient(filter_coefficient);
+ if (!low_pass_filter_.Filter((*input_buffer)[0], &output_buffer_[0])) {
+ return input_buffer;
+ }
+ // Copy buffer parameters.
+ return &output_buffer_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node.h
new file mode 100644
index 000000000..316788751
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node.h
@@ -0,0 +1,59 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_OCCLUSION_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_OCCLUSION_NODE_H_
+
+#include "base/audio_buffer.h"
+#include "dsp/mono_pole_filter.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Node that accepts a single audio buffer as input and outputs the input buffer
+// with its cuttoff frequency scaled by listener/source directivity and
+// occlusion intensity.
+class OcclusionNode : public ProcessingNode {
+ public:
+ // Constructor.
+ //
+ // @param source_id Output buffer source id.
+ // @param system_settings Global system settings.
+ OcclusionNode(SourceId source_id, const SystemSettings& system_settings);
+
+ protected:
+ // Implements ProcessingNode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ friend class OcclusionNodeTest;
+
+ const SystemSettings& system_settings_;
+
+ // Used to low-pass input audio when a source is occluded or self-occluded.
+ MonoPoleFilter low_pass_filter_;
+
+ // Occlusion intensity value for the current input buffer.
+ float current_occlusion_;
+
+ // Output buffer.
+ AudioBuffer output_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_OCCLUSION_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node_test.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node_test.cc
new file mode 100644
index 000000000..3dac808c3
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/occlusion_node_test.cc
@@ -0,0 +1,186 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/occlusion_node.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+#include "utils/test_util.h"
+
+namespace vraudio {
+
+namespace {
+
+// Number of frames per buffer.
+const size_t kFramesPerBuffer = 256;
+
+// Sampling rate.
+const int kSampleRate = 48000;
+
+// Generated sawtooth length for test buffers.
+const size_t kSawtoothLength = 16;
+
+// Source id.
+const SourceId kSourceId = 1;
+
+} // namespace
+
+class OcclusionNodeTest : public ::testing::Test {
+ protected:
+ OcclusionNodeTest()
+ : system_settings_(kNumStereoChannels, kFramesPerBuffer, kSampleRate) {}
+
+ void SetUp() override {
+ system_settings_.GetSourceParametersManager()->Register(kSourceId);
+ }
+
+ // Function which wraps the buffer passed in a vector for processing and
+ // returns the output of the occlusion nodes AudioProcess method.
+ const AudioBuffer* GetProcessedData(const AudioBuffer* input_buffer,
+ OcclusionNode* occlusion_node) {
+ std::vector<const AudioBuffer*> input_buffers;
+ input_buffers.push_back(input_buffer);
+ return occlusion_node->AudioProcess(
+ ProcessingNode::NodeInput(input_buffers));
+ }
+
+ // Returns a pointer to the parameters of the source.
+ SourceParameters* GetParameters() {
+ return system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ kSourceId);
+ }
+
+ // System settings.
+ SystemSettings system_settings_;
+};
+
+// Test to ensure that no effect is made on a buffer of input if both occlusion
+// and self-occlusion are absent.
+TEST_F(OcclusionNodeTest, NoOcclusionTest) {
+ OcclusionNode occlusion_processor(kSourceId, system_settings_);
+
+ AudioBuffer input(1, kFramesPerBuffer);
+ input.set_source_id(kSourceId);
+ GenerateSawToothSignal(kSawtoothLength, &input[0]);
+
+ const AudioBuffer* output = GetProcessedData(&input, &occlusion_processor);
+ const bool buffers_identical =
+ CompareAudioBuffers((*output)[0], input[0], kEpsilonFloat);
+ EXPECT_TRUE(buffers_identical);
+}
+
+// Test to ensure that a more heavily occluded object shows a lower energy
+// output.
+TEST_F(OcclusionNodeTest, OcclusionTest) {
+ OcclusionNode occlusion_processor_1(kSourceId, system_settings_);
+ OcclusionNode occlusion_processor_2(kSourceId, system_settings_);
+
+ AudioBuffer input(kNumMonoChannels, kFramesPerBuffer);
+ GenerateSawToothSignal(kSawtoothLength, &input[0]);
+ AudioBuffer input_1;
+ input_1 = input;
+ input_1.set_source_id(kSourceId);
+ AudioBuffer input_2;
+ input_2 = input;
+ input_2.set_source_id(kSourceId);
+
+ SourceParameters* parameters = GetParameters();
+
+ parameters->occlusion_intensity = 0.5f;
+ const AudioBuffer* output_1 =
+ GetProcessedData(&input_1, &occlusion_processor_1);
+ parameters->occlusion_intensity = 1.0f;
+ const AudioBuffer* output_2 =
+ GetProcessedData(&input_2, &occlusion_processor_2);
+ const double output_1_energy = CalculateSignalRms((*output_1)[0]);
+ const double output_2_energy = CalculateSignalRms((*output_2)[0]);
+ const double input_energy = CalculateSignalRms(input[0]);
+
+ EXPECT_LT(output_1_energy, input_energy);
+ EXPECT_LT(output_2_energy, output_1_energy);
+}
+
+// Test to ensure that setting a non-omnidirectional listener directivity
+// pattern shows a lower energy output when the listener orientation is pointing
+// away from a source.
+TEST_F(OcclusionNodeTest, ListenerDirectivityTest) {
+ OcclusionNode occlusion_processor(kSourceId, system_settings_);
+
+ AudioBuffer input(kNumMonoChannels, kFramesPerBuffer);
+ input.set_source_id(kSourceId);
+ GenerateSawToothSignal(kSawtoothLength, &input[0]);
+
+ // Set a hyper-cardioid shaped listener directivity for the source input.
+ SourceParameters* parameters = GetParameters();
+ parameters->listener_directivity_alpha = 0.5f;
+ parameters->listener_directivity_order = 2.0f;
+ // Set listener position to one meter away from the origin in Z axis. This is
+ // required for the listener directivity properties to take effect.
+ system_settings_.SetHeadPosition(WorldPosition(0.0f, 0.0f, 1.0f));
+
+ const double input_energy = CalculateSignalRms(input[0]);
+ // Process input with identity listener orientation.
+ const AudioBuffer* output_default =
+ GetProcessedData(&input, &occlusion_processor);
+ const double output_default_energy = CalculateSignalRms((*output_default)[0]);
+ // Process input with 90 degrees rotated listener orientation about Y axis.
+ system_settings_.SetHeadRotation(
+ WorldRotation(0.0f, kInverseSqrtTwo, 0.0f, kInverseSqrtTwo));
+ const AudioBuffer* output_rotated =
+ GetProcessedData(&input, &occlusion_processor);
+ const double output_rotated_energy = CalculateSignalRms((*output_rotated)[0]);
+
+ // Test if the output energy is lower when the listener was rotated away from
+ // the source.
+ EXPECT_NEAR(output_default_energy, input_energy, kEpsilonFloat);
+ EXPECT_LT(output_rotated_energy, output_default_energy);
+}
+
+// Test to ensure that a more heavily self occluded source shows a lower energy
+// output.
+TEST_F(OcclusionNodeTest, SourceDirectivityTest) {
+ OcclusionNode occlusion_processor_1(kSourceId, system_settings_);
+ OcclusionNode occlusion_processor_2(kSourceId, system_settings_);
+
+ AudioBuffer input(kNumMonoChannels, kFramesPerBuffer);
+ input.set_source_id(kSourceId);
+ GenerateSawToothSignal(kSawtoothLength, &input[0]);
+ AudioBuffer input_1;
+ input_1 = input;
+ AudioBuffer input_2;
+ input_2 = input;
+
+ SourceParameters* parameters = GetParameters();
+
+ parameters->directivity_alpha = 0.25f;
+ parameters->directivity_order = 2.0f;
+ const AudioBuffer* output_1 =
+ GetProcessedData(&input_1, &occlusion_processor_1);
+
+ parameters->directivity_order = 4.0f;
+ parameters->directivity_alpha = 0.25f;
+ const AudioBuffer* output_2 =
+ GetProcessedData(&input_2, &occlusion_processor_2);
+
+ const double output_1_energy = CalculateSignalRms((*output_1)[0]);
+ const double output_2_energy = CalculateSignalRms((*output_2)[0]);
+ const double input_energy = CalculateSignalRms(input[0]);
+
+ EXPECT_LT(output_1_energy, input_energy);
+ EXPECT_LT(output_2_energy, output_1_energy);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/reflections_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/reflections_node.cc
new file mode 100644
index 000000000..1223fe7e8
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/reflections_node.cc
@@ -0,0 +1,113 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/reflections_node.h"
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/misc_math.h"
+
+
+namespace vraudio {
+
+ReflectionsNode::ReflectionsNode(const SystemSettings& system_settings)
+ : system_settings_(system_settings),
+ reflections_processor_(system_settings_.GetSampleRateHz(),
+ system_settings_.GetFramesPerBuffer()),
+ num_frames_processed_on_empty_input_(
+ system_settings_.GetFramesPerBuffer()),
+ output_buffer_(kNumFirstOrderAmbisonicChannels,
+ system_settings_.GetFramesPerBuffer()),
+ silence_mono_buffer_(kNumMonoChannels,
+ system_settings_.GetFramesPerBuffer()) {
+ silence_mono_buffer_.Clear();
+ EnableProcessOnEmptyInput(true);
+}
+
+void ReflectionsNode::Update() {
+
+ const auto& current_reflection_properties = reflection_properties_;
+ const auto& new_reflection_properties =
+ system_settings_.GetReflectionProperties();
+ const bool room_position_changed =
+ !EqualSafe(std::begin(current_reflection_properties.room_position),
+ std::end(current_reflection_properties.room_position),
+ std::begin(new_reflection_properties.room_position),
+ std::end(new_reflection_properties.room_position));
+ const bool room_rotation_changed =
+ !EqualSafe(std::begin(current_reflection_properties.room_rotation),
+ std::end(current_reflection_properties.room_rotation),
+ std::begin(new_reflection_properties.room_rotation),
+ std::end(new_reflection_properties.room_rotation));
+ const bool room_dimensions_changed =
+ !EqualSafe(std::begin(current_reflection_properties.room_dimensions),
+ std::end(current_reflection_properties.room_dimensions),
+ std::begin(new_reflection_properties.room_dimensions),
+ std::end(new_reflection_properties.room_dimensions));
+ const bool cutoff_frequency_changed =
+ current_reflection_properties.cutoff_frequency !=
+ new_reflection_properties.cutoff_frequency;
+ const bool coefficients_changed =
+ !EqualSafe(std::begin(current_reflection_properties.coefficients),
+ std::end(current_reflection_properties.coefficients),
+ std::begin(new_reflection_properties.coefficients),
+ std::end(new_reflection_properties.coefficients));
+ const auto& current_listener_position = listener_position_;
+ const auto& new_listener_position = system_settings_.GetHeadPosition();
+ const bool listener_position_changed =
+ current_listener_position != new_listener_position;
+ if (room_position_changed || room_rotation_changed ||
+ room_dimensions_changed || cutoff_frequency_changed ||
+ coefficients_changed || listener_position_changed) {
+ // Update reflections processor if necessary.
+ reflection_properties_ = new_reflection_properties;
+ listener_position_ = new_listener_position;
+ reflections_processor_.Update(reflection_properties_, listener_position_);
+ }
+}
+
+const AudioBuffer* ReflectionsNode::AudioProcess(const NodeInput& input) {
+
+ const AudioBuffer* input_buffer = input.GetSingleInput();
+ const size_t num_frames = system_settings_.GetFramesPerBuffer();
+ if (input_buffer == nullptr) {
+ // If we have no input, generate a silent input buffer until the node states
+ // are cleared.
+ if (num_frames_processed_on_empty_input_ <
+ reflections_processor_.num_frames_to_process_on_empty_input()) {
+ num_frames_processed_on_empty_input_ += num_frames;
+ input_buffer = &silence_mono_buffer_;
+ } else {
+ // Skip processing entirely when the states are fully cleared.
+ return nullptr;
+ }
+ } else {
+ num_frames_processed_on_empty_input_ = 0;
+ DCHECK_EQ(input_buffer->num_channels(), kNumMonoChannels);
+ }
+ output_buffer_.Clear();
+ reflections_processor_.Process(*input_buffer, &output_buffer_);
+
+ // Rotate the reflections with respect to listener's orientation.
+ const WorldRotation inverse_head_rotation =
+ system_settings_.GetHeadRotation().conjugate();
+ foa_rotator_.Process(inverse_head_rotation, output_buffer_, &output_buffer_);
+
+ // Copy buffer parameters.
+ return &output_buffer_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/reflections_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/reflections_node.h
new file mode 100644
index 000000000..8685759b9
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/reflections_node.h
@@ -0,0 +1,78 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_REFLECTIONS_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_REFLECTIONS_NODE_H_
+
+#include <vector>
+
+#include "ambisonics/foa_rotator.h"
+#include "api/resonance_audio_api.h"
+#include "base/audio_buffer.h"
+#include "base/misc_math.h"
+#include "dsp/reflections_processor.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Node that accepts a single mono buffer as input and outputs an ambisonically
+// encoded sound field buffer of the mix of all the early room reflections.
+class ReflectionsNode : public ProcessingNode {
+ public:
+ // Initializes |ReflectionsNode| class.
+ //
+ // @param system_settings Global system configuration.
+ explicit ReflectionsNode(const SystemSettings& system_settings);
+
+ // Updates the reflections. Depending on whether to use RT60s for reverb
+ // according to the global system settings, the reflections are calculated
+ // either by the current room properties or the proxy room properties.
+ void Update();
+
+ protected:
+ // Implements ProcessingNode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ const SystemSettings& system_settings_;
+
+ // First-order-ambisonics rotator to be used to rotate the reflections with
+ // respect to the listener's orientation.
+ FoaRotator foa_rotator_;
+
+ // Processes and encodes reflections into an ambisonic buffer.
+ ReflectionsProcessor reflections_processor_;
+
+ // Most recently updated reflection properties.
+ ReflectionProperties reflection_properties_;
+
+ // Most recently updated listener position.
+ WorldPosition listener_position_;
+
+ size_t num_frames_processed_on_empty_input_;
+
+ // Ambisonic output buffer.
+ AudioBuffer output_buffer_;
+
+ // Silence mono buffer to render reflection tails during the absence of input
+ // buffers.
+ AudioBuffer silence_mono_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_REFLECTIONS_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/resonance_audio_api_impl.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/resonance_audio_api_impl.cc
new file mode 100644
index 000000000..f8cc6731b
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/resonance_audio_api_impl.cc
@@ -0,0 +1,586 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/resonance_audio_api_impl.h"
+
+#include <algorithm>
+#include <numeric>
+
+#include "ambisonics/utils.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/misc_math.h"
+#include "base/source_parameters.h"
+
+#include "base/unique_ptr_wrapper.h"
+#include "config/source_config.h"
+#include "dsp/channel_converter.h"
+#include "dsp/distance_attenuation.h"
+#include "graph/source_parameters_manager.h"
+#include "utils/planar_interleaved_conversion.h"
+#include "utils/sample_type_conversion.h"
+
+namespace vraudio {
+
+namespace {
+
+// Support 50 setter calls for 512 sources.
+const size_t kMaxNumTasksOnTaskQueue = 50 * 512;
+
+// User warning/notification messages.
+static const char* kBadInputPointerMessage = "Ignoring nullptr buffer";
+static const char* kBufferSizeMustMatchNumFramesMessage =
+ "Number of frames must match the frames per buffer specified during "
+ "construction - ignoring buffer";
+
+// Helper method to fetch |SourceGraphConfig| from |RenderingMode|.
+SourceGraphConfig GetSourceGraphConfigFromRenderingMode(
+ RenderingMode rendering_mode) {
+ switch (rendering_mode) {
+ case RenderingMode::kStereoPanning:
+ return StereoPanningConfig();
+ case RenderingMode::kBinauralLowQuality:
+ return BinauralLowQualityConfig();
+ case RenderingMode::kBinauralMediumQuality:
+ return BinauralMediumQualityConfig();
+ case RenderingMode::kBinauralHighQuality:
+ return BinauralHighQualityConfig();
+ case RenderingMode::kRoomEffectsOnly:
+ return RoomEffectsOnlyConfig();
+ default:
+ LOG(FATAL) << "Unknown rendering mode";
+ break;
+ }
+ return BinauralHighQualityConfig();
+}
+
+} // namespace
+
+ResonanceAudioApiImpl::ResonanceAudioApiImpl(size_t num_channels,
+ size_t frames_per_buffer,
+ int sample_rate_hz)
+ : system_settings_(num_channels, frames_per_buffer, sample_rate_hz),
+ task_queue_(kMaxNumTasksOnTaskQueue),
+ source_id_counter_(0) {
+ if (num_channels != kNumStereoChannels) {
+ LOG(FATAL) << "Only stereo output is supported";
+ return;
+ }
+
+ if (frames_per_buffer > kMaxSupportedNumFrames) {
+ LOG(FATAL) << "Only frame lengths up to " << kMaxSupportedNumFrames
+ << " are supported.";
+ return;
+ }
+
+ // The pffft library requires a minimum buffer size of 32 samples.
+ if (frames_per_buffer < FftManager::kMinFftSize) {
+ LOG(FATAL) << "The minimum number of frames per buffer is "
+ << FftManager::kMinFftSize << " samples";
+ return;
+ }
+ graph_manager_.reset(new GraphManager(system_settings_));
+}
+
+ResonanceAudioApiImpl::~ResonanceAudioApiImpl() {
+ // Clear task queue before shutting down.
+ task_queue_.Execute();
+}
+
+bool ResonanceAudioApiImpl::FillInterleavedOutputBuffer(size_t num_channels,
+ size_t num_frames,
+ float* buffer_ptr) {
+ DCHECK(buffer_ptr);
+ return FillOutputBuffer<float*>(num_channels, num_frames, buffer_ptr);
+}
+
+bool ResonanceAudioApiImpl::FillInterleavedOutputBuffer(size_t num_channels,
+ size_t num_frames,
+ int16* buffer_ptr) {
+ DCHECK(buffer_ptr);
+ return FillOutputBuffer<int16*>(num_channels, num_frames, buffer_ptr);
+}
+
+bool ResonanceAudioApiImpl::FillPlanarOutputBuffer(size_t num_channels,
+ size_t num_frames,
+ float* const* buffer_ptr) {
+ DCHECK(buffer_ptr);
+ return FillOutputBuffer<float* const*>(num_channels, num_frames, buffer_ptr);
+}
+
+bool ResonanceAudioApiImpl::FillPlanarOutputBuffer(size_t num_channels,
+ size_t num_frames,
+ int16* const* buffer_ptr) {
+ DCHECK(buffer_ptr);
+ return FillOutputBuffer<int16* const*>(num_channels, num_frames, buffer_ptr);
+}
+
+void ResonanceAudioApiImpl::SetHeadPosition(float x, float y, float z) {
+ auto task = [this, x, y, z]() {
+ const WorldPosition head_position(x, y, z);
+ system_settings_.SetHeadPosition(head_position);
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetHeadRotation(float x, float y, float z,
+ float w) {
+ auto task = [this, w, x, y, z]() {
+ const WorldRotation head_rotation(w, x, y, z);
+ system_settings_.SetHeadRotation(head_rotation);
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetMasterVolume(float volume) {
+ auto task = [this, volume]() { system_settings_.SetMasterGain(volume); };
+ task_queue_.Post(task);
+}
+
+int ResonanceAudioApiImpl::CreateAmbisonicSource(size_t num_channels) {
+ if (num_channels < kNumFirstOrderAmbisonicChannels ||
+ !IsValidAmbisonicOrder(num_channels)) {
+ // Invalid number of input channels, don't create the ambisonic source.
+ LOG(ERROR) << "Invalid number of channels for the ambisonic source: "
+ << num_channels;
+ return kInvalidSourceId;
+ }
+
+ const int ambisonic_source_id = source_id_counter_.fetch_add(1);
+
+ const size_t num_valid_channels =
+ std::min(num_channels, graph_manager_->GetNumMaxAmbisonicChannels());
+ if (num_valid_channels < num_channels) {
+ LOG(WARNING) << "Number of ambisonic channels will be diminished to "
+ << num_valid_channels;
+ }
+
+ auto task = [this, ambisonic_source_id, num_valid_channels]() {
+ graph_manager_->CreateAmbisonicSource(ambisonic_source_id,
+ num_valid_channels);
+ system_settings_.GetSourceParametersManager()->Register(
+ ambisonic_source_id);
+ // Overwrite default source parameters for ambisonic source.
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ ambisonic_source_id);
+ source_parameters->room_effects_gain = 0.0f;
+ source_parameters->distance_rolloff_model = DistanceRolloffModel::kNone;
+ source_parameters->distance_attenuation = 1.0f;
+ };
+ task_queue_.Post(task);
+ return ambisonic_source_id;
+}
+
+int ResonanceAudioApiImpl::CreateStereoSource(size_t num_channels) {
+ if (num_channels > kNumStereoChannels) {
+ LOG(ERROR) << "Unsupported number of input channels";
+ return kInvalidSourceId;
+ }
+ const int stereo_source_id = source_id_counter_.fetch_add(1);
+
+ auto task = [this, stereo_source_id]() {
+ graph_manager_->CreateStereoSource(stereo_source_id);
+ system_settings_.GetSourceParametersManager()->Register(stereo_source_id);
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ stereo_source_id);
+ source_parameters->enable_hrtf = false;
+ };
+ task_queue_.Post(task);
+ return stereo_source_id;
+}
+
+int ResonanceAudioApiImpl::CreateSoundObjectSource(
+ RenderingMode rendering_mode) {
+ const int sound_object_source_id = source_id_counter_.fetch_add(1);
+
+ const auto config = GetSourceGraphConfigFromRenderingMode(rendering_mode);
+ auto task = [this, sound_object_source_id, config]() {
+ graph_manager_->CreateSoundObjectSource(
+ sound_object_source_id, config.ambisonic_order, config.enable_hrtf,
+ config.enable_direct_rendering);
+ system_settings_.GetSourceParametersManager()->Register(
+ sound_object_source_id);
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ sound_object_source_id);
+ source_parameters->enable_hrtf = config.enable_hrtf;
+ };
+ task_queue_.Post(task);
+ return sound_object_source_id;
+}
+
+void ResonanceAudioApiImpl::DestroySource(SourceId source_id) {
+ auto task = [this, source_id]() {
+ graph_manager_->DestroySource(source_id);
+ system_settings_.GetSourceParametersManager()->Unregister(source_id);
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetInterleavedBuffer(SourceId source_id,
+ const float* audio_buffer_ptr,
+ size_t num_channels,
+ size_t num_frames) {
+ SetSourceBuffer<const float*>(source_id, audio_buffer_ptr, num_channels,
+ num_frames);
+}
+
+void ResonanceAudioApiImpl::SetInterleavedBuffer(SourceId source_id,
+ const int16* audio_buffer_ptr,
+ size_t num_channels,
+ size_t num_frames) {
+ SetSourceBuffer<const int16*>(source_id, audio_buffer_ptr, num_channels,
+ num_frames);
+}
+
+void ResonanceAudioApiImpl::SetPlanarBuffer(
+ SourceId source_id, const float* const* audio_buffer_ptr,
+ size_t num_channels, size_t num_frames) {
+ SetSourceBuffer<const float* const*>(source_id, audio_buffer_ptr,
+ num_channels, num_frames);
+}
+
+void ResonanceAudioApiImpl::SetPlanarBuffer(
+ SourceId source_id, const int16* const* audio_buffer_ptr,
+ size_t num_channels, size_t num_frames) {
+ SetSourceBuffer<const int16* const*>(source_id, audio_buffer_ptr,
+ num_channels, num_frames);
+}
+
+void ResonanceAudioApiImpl::SetSourceDistanceAttenuation(
+ SourceId source_id, float distance_attenuation) {
+ auto task = [this, source_id, distance_attenuation]() {
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ source_id);
+ if (source_parameters != nullptr) {
+ const auto& rolloff_model = source_parameters->distance_rolloff_model;
+ DCHECK_EQ(rolloff_model, DistanceRolloffModel::kNone);
+ if (rolloff_model != DistanceRolloffModel::kNone) {
+ LOG(WARNING) << "Implicit distance rolloff model is set. The value "
+ "will be overwritten.";
+ }
+ source_parameters->distance_attenuation = distance_attenuation;
+ }
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetSourceDistanceModel(SourceId source_id,
+ DistanceRolloffModel rolloff,
+ float min_distance,
+ float max_distance) {
+ if (max_distance < min_distance && rolloff != DistanceRolloffModel::kNone) {
+ LOG(WARNING) << "max_distance must be larger than min_distance";
+ return;
+ }
+ auto task = [this, source_id, rolloff, min_distance, max_distance]() {
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ source_id);
+ if (source_parameters != nullptr) {
+ source_parameters->distance_rolloff_model = rolloff;
+ source_parameters->minimum_distance = min_distance;
+ source_parameters->maximum_distance = max_distance;
+ }
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetSourcePosition(SourceId source_id, float x,
+ float y, float z) {
+ const WorldPosition position(x, y, z);
+ auto task = [this, source_id, position]() {
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ source_id);
+ if (source_parameters != nullptr) {
+ source_parameters->object_transform.position = position;
+ }
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetSourceRoomEffectsGain(SourceId source_id,
+ float room_effects_gain) {
+ auto task = [this, source_id, room_effects_gain]() {
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ source_id);
+ if (source_parameters != nullptr) {
+ source_parameters->room_effects_gain = room_effects_gain;
+ }
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetSourceRotation(SourceId source_id, float x,
+ float y, float z, float w) {
+ const WorldRotation rotation(w, x, y, z);
+ auto task = [this, source_id, rotation]() {
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ source_id);
+ if (source_parameters != nullptr) {
+ source_parameters->object_transform.rotation = rotation;
+ }
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetSourceVolume(SourceId source_id, float volume) {
+ auto task = [this, source_id, volume]() {
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ source_id);
+ if (source_parameters != nullptr) {
+ source_parameters->gain = volume;
+ }
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetSoundObjectDirectivity(
+ SourceId sound_object_source_id, float alpha, float order) {
+ auto task = [this, sound_object_source_id, alpha, order]() {
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ sound_object_source_id);
+ if (source_parameters != nullptr) {
+ source_parameters->directivity_alpha = alpha;
+ source_parameters->directivity_order = order;
+ }
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetSoundObjectListenerDirectivity(
+ SourceId sound_object_source_id, float alpha, float order) {
+ auto task = [this, sound_object_source_id, alpha, order]() {
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ sound_object_source_id);
+ if (source_parameters != nullptr) {
+ source_parameters->listener_directivity_alpha = alpha;
+ source_parameters->listener_directivity_order = order;
+ }
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetSoundObjectNearFieldEffectGain(
+ SourceId sound_object_source_id, float gain) {
+ auto task = [this, sound_object_source_id, gain]() {
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ sound_object_source_id);
+ if (source_parameters != nullptr) {
+ source_parameters->near_field_gain = gain;
+ }
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetSoundObjectOcclusionIntensity(
+ SourceId sound_object_source_id, float intensity) {
+ auto task = [this, sound_object_source_id, intensity]() {
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ sound_object_source_id);
+ if (source_parameters != nullptr) {
+ source_parameters->occlusion_intensity = intensity;
+ }
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetSoundObjectSpread(
+ SourceId sound_object_source_id, float spread_deg) {
+ auto task = [this, sound_object_source_id, spread_deg]() {
+ auto source_parameters =
+ system_settings_.GetSourceParametersManager()->GetMutableParameters(
+ sound_object_source_id);
+ if (source_parameters != nullptr) {
+ source_parameters->spread_deg = spread_deg;
+ }
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::EnableRoomEffects(bool enable) {
+ auto task = [this, enable]() { graph_manager_->EnableRoomEffects(enable); };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetReflectionProperties(
+ const ReflectionProperties& reflection_properties) {
+ auto task = [this, reflection_properties]() {
+ system_settings_.SetReflectionProperties(reflection_properties);
+ };
+ task_queue_.Post(task);
+}
+
+void ResonanceAudioApiImpl::SetReverbProperties(
+ const ReverbProperties& reverb_properties) {
+ auto task = [this, reverb_properties]() {
+ system_settings_.SetReverbProperties(reverb_properties);
+ };
+ task_queue_.Post(task);
+}
+
+const AudioBuffer* ResonanceAudioApiImpl::GetAmbisonicOutputBuffer() const {
+ return graph_manager_->GetAmbisonicBuffer();
+}
+
+const AudioBuffer* ResonanceAudioApiImpl::GetStereoOutputBuffer() const {
+ return graph_manager_->GetStereoBuffer();
+}
+
+const AudioBuffer *ResonanceAudioApiImpl::GetReverbBuffer() const {
+ return graph_manager_->GetReverbBuffer();
+}
+
+void ResonanceAudioApiImpl::ProcessNextBuffer() {
+#if defined(ENABLE_TRACING) && !ION_PRODUCTION
+ // This enables tracing on the audio thread.
+ auto task = []() { ENABLE_TRACING_ON_CURRENT_THREAD("AudioThread"); };
+ task_queue_.Post(task);
+#endif // defined(ENABLE_TRACING) && !ION_PRODUCTION
+
+
+ task_queue_.Execute();
+
+ // Update room effects only if the pipeline is initialized.
+ if (graph_manager_->GetRoomEffectsEnabled()) {
+ graph_manager_->UpdateRoomReflections();
+ graph_manager_->UpdateRoomReverb();
+ }
+ // Update source attenuation parameters.
+ const auto process = [this](SourceParameters* parameters) {
+ const float master_gain = system_settings_.GetMasterGain();
+ const auto& listener_position = system_settings_.GetHeadPosition();
+ const auto& reflection_properties =
+ system_settings_.GetReflectionProperties();
+ const auto& reverb_properties = system_settings_.GetReverbProperties();
+ UpdateAttenuationParameters(master_gain, reflection_properties.gain,
+ reverb_properties.gain, listener_position,
+ parameters);
+ };
+ system_settings_.GetSourceParametersManager()->ProcessAllParameters(process);
+
+ graph_manager_->Process();
+}
+
+void ResonanceAudioApiImpl::SetStereoSpeakerMode(bool enabled) {
+ auto task = [this, enabled]() {
+ system_settings_.SetStereoSpeakerMode(enabled);
+ };
+ task_queue_.Post(task);
+}
+
+template <typename OutputType>
+bool ResonanceAudioApiImpl::FillOutputBuffer(size_t num_channels,
+ size_t num_frames,
+ OutputType buffer_ptr) {
+
+
+ if (buffer_ptr == nullptr) {
+ LOG(WARNING) << kBadInputPointerMessage;
+ return false;
+ }
+ if (num_channels != kNumStereoChannels) {
+ LOG(WARNING) << "Output buffer must be stereo";
+ return false;
+ }
+ const size_t num_input_samples = num_frames * num_channels;
+ const size_t num_expected_output_samples =
+ system_settings_.GetFramesPerBuffer() * system_settings_.GetNumChannels();
+ if (num_input_samples != num_expected_output_samples) {
+ LOG(WARNING) << "Output buffer size must be " << num_expected_output_samples
+ << " samples";
+ return false;
+ }
+
+ // Get the processed output buffer.
+ ProcessNextBuffer();
+ const AudioBuffer* output_buffer = GetStereoOutputBuffer();
+ if (output_buffer == nullptr) {
+ // This indicates that the graph processing is triggered without having any
+ // connected sources.
+ return false;
+ }
+
+ FillExternalBuffer(*output_buffer, buffer_ptr, num_frames, num_channels);
+ return true;
+}
+
+template <typename SampleType>
+void ResonanceAudioApiImpl::SetSourceBuffer(SourceId source_id,
+ SampleType audio_buffer_ptr,
+ size_t num_input_channels,
+ size_t num_frames) {
+ // Execute task queue to ensure newly created sound sources are initialized.
+ task_queue_.Execute();
+
+ if (audio_buffer_ptr == nullptr) {
+ LOG(WARNING) << kBadInputPointerMessage;
+ return;
+ }
+ if (num_frames != system_settings_.GetFramesPerBuffer()) {
+ LOG(WARNING) << kBufferSizeMustMatchNumFramesMessage;
+ return;
+ }
+
+ AudioBuffer* const output_buffer =
+ graph_manager_->GetMutableAudioBuffer(source_id);
+ if (output_buffer == nullptr) {
+ LOG(WARNING) << "Source audio buffer not found";
+ return;
+ }
+ const size_t num_output_channels = output_buffer->num_channels();
+
+ if (num_input_channels == num_output_channels) {
+ FillAudioBuffer(audio_buffer_ptr, num_frames, num_input_channels,
+ output_buffer);
+
+ return;
+ }
+
+ if ((num_input_channels == kNumMonoChannels) &&
+ (num_output_channels == kNumStereoChannels)) {
+ FillAudioBufferWithChannelRemapping(
+ audio_buffer_ptr, num_frames, num_input_channels,
+ {0, 0} /* channel_map */, output_buffer);
+ return;
+ }
+
+ if (num_input_channels > num_output_channels) {
+ std::vector<size_t> channel_map(num_output_channels);
+ // Fill channel map with increasing indices.
+ std::iota(std::begin(channel_map), std::end(channel_map), 0);
+ FillAudioBufferWithChannelRemapping(audio_buffer_ptr, num_frames,
+ num_input_channels, channel_map,
+ output_buffer);
+ return;
+ }
+
+ LOG(WARNING) << "Number of input channels does not match the number of "
+ "output channels";
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/resonance_audio_api_impl.h b/src/3rdparty/resonance-audio/resonance_audio/graph/resonance_audio_api_impl.h
new file mode 100644
index 000000000..0adbc1c67
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/resonance_audio_api_impl.h
@@ -0,0 +1,175 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_RESONANCE_AUDIO_API_IMPL_H_
+#define RESONANCE_AUDIO_GRAPH_RESONANCE_AUDIO_API_IMPL_H_
+
+#include <atomic>
+#include <memory>
+#include <vector>
+
+#include "base/integral_types.h"
+#include "api/resonance_audio_api.h"
+#include "base/audio_buffer.h"
+#include "graph/graph_manager.h"
+#include "graph/system_settings.h"
+#include "utils/lockless_task_queue.h"
+
+namespace vraudio {
+
+// Implementation of ResonanceAudioApi interface.
+class ResonanceAudioApiImpl : public ResonanceAudioApi {
+ public:
+ // Constructor that initializes |ResonanceAudioApi| with system configuration.
+ //
+ // @param num_channels Number of channels of audio output.
+ // @param frames_per_buffer Number of frames per buffer.
+ // @param sample_rate_hz System sample rate.
+ ResonanceAudioApiImpl(size_t num_channels, size_t frames_per_buffer,
+ int sample_rate_hz);
+
+ ~ResonanceAudioApiImpl() override;
+
+ //////////////////////////////////
+ // ResonanceAudioApi implementation.
+ //////////////////////////////////
+
+ // Obtain processed output buffers.
+ bool FillInterleavedOutputBuffer(size_t num_channels, size_t num_frames,
+ float* buffer_ptr) override;
+ bool FillInterleavedOutputBuffer(size_t num_channels, size_t num_frames,
+ int16* buffer_ptr) override;
+ bool FillPlanarOutputBuffer(size_t num_channels, size_t num_frames,
+ float* const* buffer_ptr) override;
+ bool FillPlanarOutputBuffer(size_t num_channels, size_t num_frames,
+ int16* const* buffer_ptr) override;
+
+ // Listener configuration.
+ void SetHeadPosition(float x, float y, float z) override;
+ void SetHeadRotation(float x, float y, float z, float w) override;
+ void SetMasterVolume(float volume) override;
+ void SetStereoSpeakerMode(bool enabled) override;
+
+ // Create and destroy sources.
+ SourceId CreateAmbisonicSource(size_t num_channels) override;
+ SourceId CreateStereoSource(size_t num_channels) override;
+ SourceId CreateSoundObjectSource(RenderingMode rendering_mode) override;
+ void DestroySource(SourceId source_id) override;
+
+ // Set source data.
+ void SetInterleavedBuffer(SourceId source_id, const float* audio_buffer_ptr,
+ size_t num_channels, size_t num_frames) override;
+ void SetInterleavedBuffer(SourceId source_id, const int16* audio_buffer_ptr,
+ size_t num_channels, size_t num_frames) override;
+ void SetPlanarBuffer(SourceId source_id, const float* const* audio_buffer_ptr,
+ size_t num_channels, size_t num_frames) override;
+ void SetPlanarBuffer(SourceId source_id, const int16* const* audio_buffer_ptr,
+ size_t num_channels, size_t num_frames) override;
+
+ // Source configuration.
+ void SetSourceDistanceAttenuation(SourceId source_id,
+ float distance_attenuation) override;
+ void SetSourceDistanceModel(SourceId source_id, DistanceRolloffModel rolloff,
+ float min_distance, float max_distance) override;
+ void SetSourcePosition(SourceId source_id, float x, float y,
+ float z) override;
+ void SetSourceRoomEffectsGain(SourceId source_id,
+ float room_effects_gain) override;
+ void SetSourceRotation(SourceId source_id, float x, float y, float z,
+ float w) override;
+ void SetSourceVolume(SourceId source_id, float volume) override;
+
+ // Sound object configuration.
+ void SetSoundObjectDirectivity(SourceId sound_object_source_id, float alpha,
+ float order) override;
+ void SetSoundObjectListenerDirectivity(SourceId sound_object_source_id,
+ float alpha, float order) override;
+ void SetSoundObjectNearFieldEffectGain(SourceId sound_object_source_id,
+ float gain) override;
+ void SetSoundObjectOcclusionIntensity(SourceId sound_object_source_id,
+ float intensity) override;
+ void SetSoundObjectSpread(SourceId sound_object_source_id,
+ float spread_deg) override;
+
+ // Room effects configuration.
+ void EnableRoomEffects(bool enable) override;
+ void SetReflectionProperties(
+ const ReflectionProperties& reflection_properties) override;
+ void SetReverbProperties(const ReverbProperties& reverb_properties) override;
+
+ //////////////////////////////////
+ // Internal API methods.
+ //////////////////////////////////
+
+ // Returns the last processed output buffer of the ambisonic mix.
+ //
+ // @return Pointer to ambisonic output buffer.
+ const AudioBuffer* GetAmbisonicOutputBuffer() const;
+
+ // Returns the last processed output buffer of the stereo (binaural) mix.
+ //
+ // @return Pointer to stereo output buffer.
+ const AudioBuffer* GetStereoOutputBuffer() const;
+
+ // Returns the last processed buffer containing stereo data for the room reverb
+ //
+ // @return Pointer to room reverb stereo buffer.
+ const AudioBuffer* GetReverbBuffer() const;
+
+ // Triggers processing of the audio graph with the updated system properties.
+ void ProcessNextBuffer();
+
+ private:
+ // This method triggers the processing of the audio graph and outputs a
+ // binaural stereo output buffer.
+ //
+ // @tparam OutputType Output sample format, only float and int16 are
+ // supported.
+ // @param num_channels Number of channels in output buffer.
+ // @param num_frames Size of buffer in frames.
+ // @param buffer_ptr Raw pointer to audio buffer.
+ // @return True if a valid output was successfully rendered, false otherwise.
+ template <typename OutputType>
+ bool FillOutputBuffer(size_t num_channels, size_t num_frames,
+ OutputType buffer_ptr);
+
+ // Sets the next audio buffer to a sound source.
+ //
+ // @param source_id Id of sound source.
+ // @param audio_buffer_ptr Pointer to planar or interleaved audio buffer.
+ // @param num_input_channels Number of input channels.
+ // @param num_frames Number of frames per channel / audio buffer.
+ template <typename SampleType>
+ void SetSourceBuffer(SourceId source_id, SampleType audio_buffer_ptr,
+ size_t num_input_channels, size_t num_frames);
+
+ // Graph manager used to create and destroy sound objects.
+ std::unique_ptr<GraphManager> graph_manager_;
+
+ // Manages system wide settings.
+ SystemSettings system_settings_;
+
+ // Task queue to cache manipulation of all the entities in the system. All
+ // tasks are executed from the audio thread.
+ LocklessTaskQueue task_queue_;
+
+ // Incremental source id counter.
+ std::atomic<int> source_id_counter_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_RESONANCE_AUDIO_API_IMPL_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/reverb_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/reverb_node.cc
new file mode 100644
index 000000000..6a9999881
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/reverb_node.cc
@@ -0,0 +1,162 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/reverb_node.h"
+
+#include <algorithm>
+#include <cmath>
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+
+
+namespace vraudio {
+
+namespace {
+
+// Default time in seconds to update the rt60s over.
+const float kUpdateTimeSeconds = 1.0f;
+
+// Interpolates between the current and target values in steps of |update_step|,
+// will set |current| to |target| when the diff between them is less than
+// |update_step|.
+inline void InterpolateFloatParam(float update_step, float target,
+ float* current) {
+ if (std::abs(target - *current) <= std::abs(update_step)) {
+ *current = target;
+ } else {
+ *current += update_step;
+ }
+}
+
+} // namespace
+
+ReverbNode::ReverbNode(const SystemSettings& system_settings,
+ FftManager* fft_manager)
+ : system_settings_(system_settings),
+ rt60_band_update_steps_(kNumReverbOctaveBands, 0.0f),
+ gain_update_step_(0.0f),
+ rt60_updating_(false),
+ gain_updating_(false),
+ buffers_to_update_(
+ static_cast<float>(system_settings_.GetSampleRateHz()) *
+ kUpdateTimeSeconds /
+ static_cast<float>(system_settings_.GetFramesPerBuffer())),
+ spectral_reverb_(system_settings_.GetSampleRateHz(),
+ system_settings_.GetFramesPerBuffer()),
+ onset_compensator_(system_settings_.GetSampleRateHz(),
+ system_settings_.GetFramesPerBuffer(), fft_manager),
+ num_frames_processed_on_empty_input_(0),
+ reverb_length_frames_(0),
+ output_buffer_(kNumStereoChannels, system_settings_.GetFramesPerBuffer()),
+ compensator_output_buffer_(kNumStereoChannels,
+ system_settings_.GetFramesPerBuffer()),
+ silence_mono_buffer_(kNumMonoChannels,
+ system_settings_.GetFramesPerBuffer()) {
+ EnableProcessOnEmptyInput(true);
+ output_buffer_.Clear();
+ silence_mono_buffer_.Clear();
+ Update();
+}
+
+void ReverbNode::Update() {
+ new_reverb_properties_ = system_settings_.GetReverbProperties();
+
+ rt60_updating_ = !EqualSafe(std::begin(reverb_properties_.rt60_values),
+ std::end(reverb_properties_.rt60_values),
+ std::begin(new_reverb_properties_.rt60_values),
+ std::end(new_reverb_properties_.rt60_values));
+ if (rt60_updating_) {
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ rt60_band_update_steps_[i] = (new_reverb_properties_.rt60_values[i] -
+ reverb_properties_.rt60_values[i]) /
+ buffers_to_update_;
+ }
+ }
+ // Update the reverb gain if necessary.
+ gain_updating_ = reverb_properties_.gain != new_reverb_properties_.gain;
+ if (gain_updating_) {
+ gain_update_step_ =
+ (new_reverb_properties_.gain - reverb_properties_.gain) /
+ buffers_to_update_;
+ }
+}
+
+const AudioBuffer* ReverbNode::GetOutputBuffer() const
+{
+ return &output_buffer_;
+}
+
+const AudioBuffer* ReverbNode::AudioProcess(const NodeInput& input) {
+ if (rt60_updating_) {
+ for (size_t i = 0; i < kNumReverbOctaveBands; ++i) {
+ InterpolateFloatParam(rt60_band_update_steps_[i],
+ new_reverb_properties_.rt60_values[i],
+ &reverb_properties_.rt60_values[i]);
+ }
+ spectral_reverb_.SetRt60PerOctaveBand(reverb_properties_.rt60_values);
+ const auto max_rt_it =
+ std::max_element(std::begin(reverb_properties_.rt60_values),
+ std::end(reverb_properties_.rt60_values));
+ reverb_length_frames_ = static_cast<size_t>(
+ *max_rt_it * static_cast<float>(system_settings_.GetSampleRateHz()));
+ onset_compensator_.Update(reverb_properties_.rt60_values,
+ reverb_properties_.gain);
+ // |InterpolateFloatParam| will set the two values below to be equal on
+ // completion of interpolation.
+ rt60_updating_ = !EqualSafe(std::begin(reverb_properties_.rt60_values),
+ std::end(reverb_properties_.rt60_values),
+ std::begin(new_reverb_properties_.rt60_values),
+ std::end(new_reverb_properties_.rt60_values));
+ }
+
+ if (gain_updating_) {
+ InterpolateFloatParam(gain_update_step_, new_reverb_properties_.gain,
+ &reverb_properties_.gain);
+ spectral_reverb_.SetGain(reverb_properties_.gain);
+ onset_compensator_.Update(reverb_properties_.rt60_values,
+ reverb_properties_.gain);
+ // |InterpolateFloatParam| will set the two values below to be equal on
+ // completion of interpolation.
+ gain_updating_ = reverb_properties_.gain != new_reverb_properties_.gain;
+ }
+
+ const AudioBuffer* input_buffer = input.GetSingleInput();
+ if (input_buffer == nullptr) {
+ // If we have no input, generate a silent input buffer until the node states
+ // are cleared.
+ if (num_frames_processed_on_empty_input_ < reverb_length_frames_) {
+ const size_t num_frames = system_settings_.GetFramesPerBuffer();
+ num_frames_processed_on_empty_input_ += num_frames;
+ spectral_reverb_.Process(silence_mono_buffer_[0], &output_buffer_[0],
+ &output_buffer_[1]);
+ return &output_buffer_;
+ } else {
+ // Skip processing entirely when the states are fully cleared.
+ return nullptr;
+ }
+ }
+ DCHECK_EQ(input_buffer->num_channels(), kNumMonoChannels);
+ num_frames_processed_on_empty_input_ = 0;
+ spectral_reverb_.Process((*input_buffer)[0], &output_buffer_[0],
+ &output_buffer_[1]);
+ onset_compensator_.Process(*input_buffer, &compensator_output_buffer_);
+ output_buffer_[0] += compensator_output_buffer_[0];
+ output_buffer_[1] += compensator_output_buffer_[1];
+ return &output_buffer_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/reverb_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/reverb_node.h
new file mode 100644
index 000000000..f9921fa66
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/reverb_node.h
@@ -0,0 +1,99 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_REVERB_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_REVERB_NODE_H_
+
+#include "api/resonance_audio_api.h"
+#include "base/audio_buffer.h"
+#include "dsp/fft_manager.h"
+#include "dsp/reverb_onset_compensator.h"
+#include "dsp/spectral_reverb.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Implements a spectral reverb producing a decorrelated stereo output with
+// onset compensated by a pair of convolution filters.
+class ReverbNode : public ProcessingNode {
+ public:
+ // Constructs a |ReverbNode|.
+ //
+ // @param system_settings Global system configuration.
+ // @param fft_manager Pointer to a manager to perform FFT transformations.
+ ReverbNode(const SystemSettings& system_settings, FftManager* fft_manager);
+
+ // Updates the |SpectralReverb| using the current room properties or RT60
+ // values depending on the system settings.
+ void Update();
+
+ const AudioBuffer *GetOutputBuffer() const;
+
+ protected:
+ // Implements ProcessingNode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ // Global system configuration.
+ const SystemSettings& system_settings_;
+
+ // Current reverb properties.
+ ReverbProperties reverb_properties_;
+
+ // New reverb properties.
+ ReverbProperties new_reverb_properties_;
+
+ // Per band reverb time update step sizes.
+ std::vector<float> rt60_band_update_steps_;
+
+ // Update step size for the gain parameter.
+ float gain_update_step_;
+
+ // Denotes whether the rt60s are currently being updated.
+ bool rt60_updating_;
+
+ // Denotes whether the gain is currently being updated.
+ bool gain_updating_;
+
+ // Number of buffers to updae rt60s over.
+ float buffers_to_update_;
+
+ // DSP class to perform filtering associated with the reverb.
+ SpectralReverb spectral_reverb_;
+
+ // DSP class to perform spectral reverb onset compensation.
+ ReverbOnsetCompensator onset_compensator_;
+
+ // Number of frames of zeroed out data to be processed by the node to ensure
+ // the entire tail is rendered after input has ceased.
+ size_t num_frames_processed_on_empty_input_;
+
+ // Longest current reverb time, across all bands, in frames.
+ size_t reverb_length_frames_;
+
+ // Output buffers for mixing spectral reverb and compensator output.
+ AudioBuffer output_buffer_;
+ AudioBuffer compensator_output_buffer_;
+
+ // Silence mono buffer to render reverb tails during the absence of input
+ // buffers.
+ AudioBuffer silence_mono_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_REVERB_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/source_graph_config.h b/src/3rdparty/resonance-audio/resonance_audio/graph/source_graph_config.h
new file mode 100644
index 000000000..513f9b087
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/source_graph_config.h
@@ -0,0 +1,43 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_SOURCE_GRAPH_CONFIG_H_
+#define RESONANCE_AUDIO_GRAPH_SOURCE_GRAPH_CONFIG_H_
+
+#include <string>
+#include <utility>
+#include <vector>
+
+namespace vraudio {
+
+// Configuration of a source and the nodes it is instantiating.
+struct SourceGraphConfig {
+ // Configuration name.
+ std::string configuration_name;
+
+ // Ambisonic order to encode to/decode from source.
+ int ambisonic_order = 1;
+
+ // Flag to enable HRTF-based rendering of source.
+ bool enable_hrtf = true;
+
+ // Flag to enable direct rendering of source.
+ bool enable_direct_rendering = true;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_SOURCE_GRAPH_CONFIG_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager.cc
new file mode 100644
index 000000000..edc903cc5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager.cc
@@ -0,0 +1,58 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/source_parameters_manager.h"
+
+#include "base/logging.h"
+
+namespace vraudio {
+
+void SourceParametersManager::Register(SourceId source_id) {
+ DCHECK(parameters_.find(source_id) == parameters_.end());
+ parameters_[source_id] = SourceParameters();
+}
+
+void SourceParametersManager::Unregister(SourceId source_id) {
+ parameters_.erase(source_id);
+}
+
+const SourceParameters* SourceParametersManager::GetParameters(
+ SourceId source_id) const {
+ const auto source_parameters_itr = parameters_.find(source_id);
+ if (source_parameters_itr == parameters_.end()) {
+ LOG(ERROR) << "Source " << source_id << " not found";
+ return nullptr;
+ }
+ return &source_parameters_itr->second;
+}
+
+SourceParameters* SourceParametersManager::GetMutableParameters(
+ SourceId source_id) {
+ auto source_parameters_itr = parameters_.find(source_id);
+ if (source_parameters_itr == parameters_.end()) {
+ LOG(ERROR) << "Source " << source_id << " not found";
+ return nullptr;
+ }
+ return &source_parameters_itr->second;
+}
+
+void SourceParametersManager::ProcessAllParameters(const Process& process) {
+ for (auto& source_parameters_itr : parameters_) {
+ process(&source_parameters_itr.second);
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager.h b/src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager.h
new file mode 100644
index 000000000..a6b394fd7
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager.h
@@ -0,0 +1,68 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_SOURCE_PARAMETERS_MANAGER_H_
+#define RESONANCE_AUDIO_GRAPH_SOURCE_PARAMETERS_MANAGER_H_
+
+#include <functional>
+#include <unordered_map>
+
+#include "base/constants_and_types.h"
+#include "base/source_parameters.h"
+
+namespace vraudio {
+
+// Class that manages the corresponding parameters of each registered source.
+class SourceParametersManager {
+ public:
+ // Alias for the parameters process closure type.
+ using Process = std::function<void(SourceParameters*)>;
+
+ // Registers new source parameters for given |source_id|.
+ //
+ // @param source_id Source id.
+ void Register(SourceId source_id);
+
+ // Unregisters the source parameters for given |source_id|.
+ //
+ // @param source_id Source id.
+ void Unregister(SourceId source_id);
+
+ // Returns read-only source parameters for given |source_id|.
+ //
+ // @param source_id Source id.
+ // @return Read-only source parameters, nullptr if |source_id| not found.
+ const SourceParameters* GetParameters(SourceId source_id) const;
+
+ // Returns mutable source parameters for given |source_id|.
+ //
+ // @param source_id Source id.
+ // @return Mutable source parameters, nullptr if |source_id| not found.
+ SourceParameters* GetMutableParameters(SourceId source_id);
+
+ // Executes given |process| for the parameters of each registered source.
+ //
+ // @param process Parameters processing method.
+ void ProcessAllParameters(const Process& process);
+
+ private:
+ // Registered source parameters.
+ std::unordered_map<SourceId, SourceParameters> parameters_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_SOURCE_PARAMETERS_MANAGER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager_test.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager_test.cc
new file mode 100644
index 000000000..59c69eaed
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/source_parameters_manager_test.cc
@@ -0,0 +1,91 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/source_parameters_manager.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+
+namespace vraudio {
+
+namespace {
+
+// Tests that the manager registers/unregisters source parameters as expected
+// for given arbitrary source ids.
+TEST(SourceParametersManagerTest, RegisterUnregisterTest) {
+ const SourceId kSourceIds[] = {0, 1, 5, 10};
+
+ // Initialize a new |SourceParametersManager|.
+ SourceParametersManager source_parameters_manager;
+ for (const auto source_id : kSourceIds) {
+ // Verify that no parameters are registered for given |source_id|.
+ EXPECT_TRUE(source_parameters_manager.GetParameters(source_id) == nullptr);
+ // Verify that the parameters are initialized after |Register|.
+ source_parameters_manager.Register(source_id);
+ EXPECT_FALSE(source_parameters_manager.GetParameters(source_id) == nullptr);
+ // Verify that the parameters are destroyed after |Unregister|.
+ source_parameters_manager.Unregister(source_id);
+ EXPECT_TRUE(source_parameters_manager.GetParameters(source_id) == nullptr);
+ }
+}
+
+// Tests that the manager correctly applies and returns parameter values of a
+// source for a given arbitrary modifier.
+TEST(SourceParametersManagerTest, ParametersAccessTest) {
+ const SourceId kSourceId = 1;
+ const float kSourceGain = 0.25f;
+
+ // Initialize a new |SourceParametersManager| and register the source.
+ SourceParametersManager source_parameters_manager;
+ source_parameters_manager.Register(kSourceId);
+ // Modify the gain parameter.
+ auto mutable_parameters =
+ source_parameters_manager.GetMutableParameters(kSourceId);
+ EXPECT_TRUE(mutable_parameters != nullptr);
+ mutable_parameters->gain = kSourceGain;
+ // Access the parameters to verify the gain value was applied correctly.
+ const auto parameters = source_parameters_manager.GetParameters(kSourceId);
+ EXPECT_TRUE(parameters != nullptr);
+ EXPECT_EQ(kSourceGain, parameters->gain);
+}
+
+// Tests that the manager correctly executes a given arbitrary call to process
+// all parameters for all the sources contained within.
+TEST(SourceParametersManagerTest, ProcessAllParametersTest) {
+ const SourceId kSourceIds[] = {0, 1, 2, 3, 4, 5};
+ const float kDistanceAttenuation = 0.75f;
+ const auto kProcess = [kDistanceAttenuation](SourceParameters* parameters) {
+ parameters->distance_attenuation = kDistanceAttenuation;
+ };
+
+ // Initialize a new |SourceParametersManager| and register all the sources.
+ SourceParametersManager source_parameters_manager;
+ for (const auto source_id : kSourceIds) {
+ source_parameters_manager.Register(source_id);
+ }
+ // Process all parameters to apply the distance attenuation.
+ source_parameters_manager.ProcessAllParameters(kProcess);
+ // Verify that the distance attenuation value was applied correctly to all the
+ // sources.
+ for (const auto source_id : kSourceIds) {
+ const auto parameters = source_parameters_manager.GetParameters(source_id);
+ EXPECT_TRUE(parameters != nullptr);
+ EXPECT_EQ(kDistanceAttenuation, parameters->distance_attenuation);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/stereo_mixing_panner_node.cc b/src/3rdparty/resonance-audio/resonance_audio/graph/stereo_mixing_panner_node.cc
new file mode 100644
index 000000000..d919e94c1
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/stereo_mixing_panner_node.cc
@@ -0,0 +1,65 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "graph/stereo_mixing_panner_node.h"
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/spherical_angle.h"
+
+#include "dsp/stereo_panner.h"
+
+namespace vraudio {
+
+StereoMixingPannerNode::StereoMixingPannerNode(
+ const SystemSettings& system_settings)
+ : system_settings_(system_settings),
+ gain_mixer_(kNumStereoChannels, system_settings_.GetFramesPerBuffer()),
+ coefficients_(kNumStereoChannels) {}
+
+const AudioBuffer* StereoMixingPannerNode::AudioProcess(
+ const NodeInput& input) {
+
+
+ const WorldPosition& listener_position = system_settings_.GetHeadPosition();
+ const WorldRotation& listener_rotation = system_settings_.GetHeadRotation();
+
+ gain_mixer_.Reset();
+ for (auto& input_buffer : input.GetInputBuffers()) {
+ const int source_id = input_buffer->source_id();
+ const auto source_parameters =
+ system_settings_.GetSourceParameters(source_id);
+ DCHECK_NE(source_id, kInvalidSourceId);
+ DCHECK_EQ(input_buffer->num_channels(), 1U);
+
+ // Compute the relative source direction in spherical angles.
+ const ObjectTransform& source_transform =
+ source_parameters->object_transform;
+ WorldPosition relative_direction;
+ GetRelativeDirection(listener_position, listener_rotation,
+ source_transform.position, &relative_direction);
+ const SphericalAngle source_direction =
+ SphericalAngle::FromWorldPosition(relative_direction);
+
+
+ CalculateStereoPanGains(source_direction, &coefficients_);
+
+ gain_mixer_.AddInputChannel((*input_buffer)[0], source_id, coefficients_);
+ }
+ return gain_mixer_.GetOutput();
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/stereo_mixing_panner_node.h b/src/3rdparty/resonance-audio/resonance_audio/graph/stereo_mixing_panner_node.h
new file mode 100644
index 000000000..b465917bd
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/stereo_mixing_panner_node.h
@@ -0,0 +1,61 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_STEREO_MIXING_PANNER_NODE_H_
+#define RESONANCE_AUDIO_GRAPH_STEREO_MIXING_PANNER_NODE_H_
+
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "dsp/gain_mixer.h"
+#include "graph/system_settings.h"
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+// Node that accepts single mono sound object buffer as input and pans into a
+// stereo panorama.
+class StereoMixingPannerNode : public ProcessingNode {
+ public:
+ // Initializes StereoMixingPannerNode class.
+ //
+ // @param system_settings Global system configuration.
+ explicit StereoMixingPannerNode(const SystemSettings& system_settings);
+
+ // Node implementation.
+ bool CleanUp() final {
+ CallCleanUpOnInputNodes();
+ // Prevent node from being disconnected when all sources are removed.
+ return false;
+ }
+
+ protected:
+ // Implements ProcessingNode.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override;
+
+ private:
+ const SystemSettings& system_settings_;
+
+ // |GainMixer| instance.
+ GainMixer gain_mixer_;
+
+ // Panning coefficients to be applied the input.
+ std::vector<float> coefficients_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_STEREO_MIXING_PANNER_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/graph/system_settings.h b/src/3rdparty/resonance-audio/resonance_audio/graph/system_settings.h
new file mode 100644
index 000000000..48573be54
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/graph/system_settings.h
@@ -0,0 +1,189 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_GRAPH_SYSTEM_SETTINGS_H_
+#define RESONANCE_AUDIO_GRAPH_SYSTEM_SETTINGS_H_
+
+#include "api/resonance_audio_api.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+#include "graph/source_parameters_manager.h"
+
+namespace vraudio {
+
+// Contains system-wide settings and parameters. Note that this class is not
+// thread-safe. Updating system parameters must be avoided during the audio
+// graph processing.
+class SystemSettings {
+ public:
+ // Constructor initializes the system configuration.
+ //
+ // @param num_output_channels Number of output channels.
+ // @param frames_per_buffer Buffer size in frames.
+ // @param sample_rate_hz Sample rate.
+ SystemSettings(size_t num_output_channels, size_t frames_per_buffer,
+ int sample_rate_hz)
+ : sample_rate_hz_(sample_rate_hz),
+ frames_per_buffer_(frames_per_buffer),
+ num_channels_(num_output_channels),
+ head_rotation_(WorldRotation::Identity()),
+ head_position_(WorldPosition::Zero()),
+ master_gain_(1.0f),
+ stereo_speaker_mode_(false) {}
+
+ // Sets the listener head orientation.
+ //
+ // @param head_rotation Listener head orientation.
+ void SetHeadRotation(const WorldRotation& head_rotation) {
+ head_rotation_ = head_rotation;
+ }
+
+ // Sets the listener head position.
+ //
+ // @param head_position Listener head position.
+ void SetHeadPosition(const WorldPosition& head_position) {
+ head_position_ = head_position;
+ }
+
+ // Sets the global stereo speaker mode flag. This flag enforces stereo panning
+ // and disables HRTF-based binauralization. The stereo speaker mode is
+ // disabled by default.
+ //
+ // @param enabled Defines the stereo speaker mode state.
+ void SetStereoSpeakerMode(bool enabled) { stereo_speaker_mode_ = enabled; }
+
+ // Returns the source parameters manager.
+ //
+ // @return Mutable source parameters manager.
+ SourceParametersManager* GetSourceParametersManager() {
+ return &source_parameters_manager_;
+ }
+
+ // Returns the parameters of source with given |source_id|.
+ //
+ // @param source_id Source id.
+ // @return Pointer to source parameters, nullptr if |source_id| not found.
+ const SourceParameters* GetSourceParameters(SourceId source_id) const {
+ return source_parameters_manager_.GetParameters(source_id);
+ }
+
+ // Returns the sample rate.
+ //
+ // @return Sample rate in Hertz.
+ int GetSampleRateHz() const { return sample_rate_hz_; }
+
+ // Returns the frames per buffer.
+ //
+ // @return Buffer size in frames.
+ size_t GetFramesPerBuffer() const { return frames_per_buffer_; }
+
+ // Returns the number of output channels.
+ //
+ // @return Number of output channels.
+ size_t GetNumChannels() const { return num_channels_; }
+
+ // Returns the head rotation.
+ //
+ // @return Head orientation.
+ const WorldRotation& GetHeadRotation() const { return head_rotation_; }
+
+ // Returns the head position.
+ //
+ // @return Head position.
+ const WorldPosition& GetHeadPosition() const { return head_position_; }
+
+ // Returns the stereo speaker mode state.
+ //
+ // @return Current stereo speaker mode state.
+ bool IsStereoSpeakerModeEnabled() const { return stereo_speaker_mode_; }
+
+ // Sets the master gain.
+ //
+ // @param master_gain Master output gain.
+ void SetMasterGain(float master_gain) { master_gain_ = master_gain; }
+
+ // Sets current reflection properties.
+ //
+ // @param reflection_properties Reflection properties.
+ void SetReflectionProperties(
+ const ReflectionProperties& reflection_properties) {
+ reflection_properties_ = reflection_properties;
+ }
+
+ // Sets current reverb properties.
+ //
+ // @param reverb_properties Reflection properties.
+ void SetReverbProperties(const ReverbProperties& reverb_properties) {
+ reverb_properties_ = reverb_properties;
+ }
+
+ // Returns the master gain.
+ //
+ // @return Master output gain.
+ float GetMasterGain() const { return master_gain_; }
+
+ // Returns the current reflection properties of the environment.
+ //
+ // @return Current reflection properties.
+ const ReflectionProperties& GetReflectionProperties() const {
+ return reflection_properties_;
+ }
+
+ // Returns the current reverb properties of the environment.
+ //
+ // @return Current reverb properties.
+ const ReverbProperties& GetReverbProperties() const {
+ return reverb_properties_;
+ }
+
+ // Disable copy and assignment operator. Since |SystemSettings| serves as a
+ // global parameter storage, it should never be copied.
+ SystemSettings& operator=(const SystemSettings&) = delete;
+ SystemSettings(const SystemSettings&) = delete;
+
+ private:
+ // Sampling rate.
+ const int sample_rate_hz_;
+
+ // Frames per buffer.
+ const size_t frames_per_buffer_;
+
+ // Number of channels per buffer.
+ const size_t num_channels_;
+
+ // The most recently updated head rotation and position.
+ WorldRotation head_rotation_;
+ WorldPosition head_position_;
+
+ // Source parameters manager.
+ SourceParametersManager source_parameters_manager_;
+
+ // Master gain in amplitude.
+ float master_gain_;
+
+ // Current reflection properties of the environment.
+ ReflectionProperties reflection_properties_;
+
+ // Current reverb properties of the environment.
+ ReverbProperties reverb_properties_;
+
+ // Defines the state of the global speaker mode.
+ bool stereo_speaker_mode_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_GRAPH_SYSTEM_SETTINGS_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/node/audio_nodes_test.cc b/src/3rdparty/resonance-audio/resonance_audio/node/audio_nodes_test.cc
new file mode 100644
index 000000000..a623f5d1c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/node/audio_nodes_test.cc
@@ -0,0 +1,407 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include <algorithm>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/logging.h"
+#include "node/processing_node.h"
+#include "node/sink_node.h"
+#include "node/source_node.h"
+
+namespace vraudio {
+
+namespace {
+
+// Number of channels in test buffers.
+static const size_t kNumChannels = 5;
+
+// Number of frames in test buffers.
+static const size_t kNumFrames = 7;
+
+// Helper method to compare two audio buffers.
+bool CompareAudioBuffer(const AudioBuffer& buffer_a,
+ const AudioBuffer& buffer_b) {
+ if (buffer_a.num_channels() != buffer_b.num_channels() ||
+ buffer_a.num_frames() != buffer_b.num_frames()) {
+ return false;
+ }
+ for (size_t channel = 0; channel < buffer_a.num_channels(); ++channel) {
+ const AudioBuffer::Channel& channel_a = buffer_a[channel];
+ const AudioBuffer::Channel& channel_b = buffer_b[channel];
+ for (size_t frame = 0; frame < buffer_a.num_frames(); ++frame) {
+ if (channel_a[frame] != channel_b[frame]) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+// Helper method to generate a test AudioBuffer.
+std::unique_ptr<AudioBuffer> GenerateTestAudioBuffer(float factor) {
+ std::unique_ptr<AudioBuffer> new_buffer(
+ new AudioBuffer(kNumChannels, kNumFrames));
+ for (size_t channel = 0; channel < kNumChannels; ++channel) {
+ std::fill((*new_buffer)[channel].begin(), (*new_buffer)[channel].end(),
+ static_cast<float>(channel) * factor);
+ }
+ return new_buffer;
+}
+
+// Simple audio source node that generates AudioData buffers.
+class MySourceNode : public SourceNode {
+ public:
+ MySourceNode(bool output_empty_buffer, bool* node_deletion_flag)
+ : output_empty_buffer_(output_empty_buffer),
+ node_deletion_flag_(node_deletion_flag),
+ audio_buffer_(GenerateTestAudioBuffer(1.0f)) {}
+ ~MySourceNode() final {
+ if (node_deletion_flag_ != nullptr) {
+ *node_deletion_flag_ = true;
+ }
+ }
+
+ protected:
+ // AudioProcess methods outputs kTestAudioData data.
+ const AudioBuffer* AudioProcess() override {
+ if (output_empty_buffer_) {
+ return nullptr;
+ }
+ return audio_buffer_.get();
+ }
+
+ private:
+ const bool output_empty_buffer_;
+ bool* node_deletion_flag_;
+
+ std::unique_ptr<AudioBuffer> audio_buffer_;
+};
+
+// Simple audio processing node that reads from a single input and passes the
+// data to the output.
+class MyProcessingNode : public ProcessingNode {
+ public:
+ MyProcessingNode(bool process_on_empty_input, bool* audio_process_called_flag,
+ bool* node_deletion_flag)
+ : process_on_empty_input_(process_on_empty_input),
+ audio_process_called_flag_(audio_process_called_flag),
+ node_deletion_flag_(node_deletion_flag) {
+ EnableProcessOnEmptyInput(process_on_empty_input_);
+ }
+
+ ~MyProcessingNode() final {
+ if (node_deletion_flag_ != nullptr) {
+ *node_deletion_flag_ = true;
+ }
+ }
+
+ protected:
+ const AudioBuffer* AudioProcess(const NodeInput& input) override {
+ if (audio_process_called_flag_ != nullptr) {
+ *audio_process_called_flag_ = true;
+ }
+
+ if (!process_on_empty_input_) {
+ EXPECT_GT(input.GetInputBuffers().size(), 0U);
+ } else {
+ if (input.GetInputBuffers().empty()) {
+ return nullptr;
+ }
+ }
+
+ return input.GetInputBuffers()[0];
+ }
+
+ private:
+ const bool process_on_empty_input_;
+ bool* const audio_process_called_flag_;
+ bool* const node_deletion_flag_;
+};
+
+// Simple audio mixer node that connects to multiple nodes and outputs the sum
+// of all inputs.
+class MyAudioMixerNode : public ProcessingNode {
+ public:
+ explicit MyAudioMixerNode(bool* node_deletion_flag)
+ : node_deletion_flag_(node_deletion_flag) {}
+ ~MyAudioMixerNode() final {
+ if (node_deletion_flag_ != nullptr) {
+ *node_deletion_flag_ = true;
+ }
+ }
+
+ protected:
+ // AudioProcess performs an element-wise sum from all inputs and outputs a new
+ // AudioData buffer.
+ const AudioBuffer* AudioProcess(const NodeInput& input) override {
+ const auto& input_buffers = input.GetInputBuffers();
+ output_data_ = *input_buffers[0];
+
+ // Iterate over all inputs and add its data to |output_data|.
+ for (size_t buffer = 1; buffer < input_buffers.size(); ++buffer) {
+ const AudioBuffer* accumulate_data = input_buffers[buffer];
+ for (size_t channel = 0; channel < accumulate_data->num_channels();
+ ++channel) {
+ const AudioBuffer::Channel& accumulate_channel =
+ (*accumulate_data)[channel];
+ AudioBuffer::Channel* output_channel = &output_data_[channel];
+ EXPECT_EQ(accumulate_channel.size(), output_channel->size());
+ for (size_t frame = 0; frame < accumulate_channel.size(); ++frame) {
+ (*output_channel)[frame] += accumulate_channel[frame];
+ }
+ }
+ }
+ return &output_data_;
+ }
+
+ private:
+ bool* node_deletion_flag_;
+ AudioBuffer output_data_;
+};
+
+// Simple audio sink node that expects a single input.
+class MySinkNode : public SinkNode {
+ public:
+ explicit MySinkNode(bool* node_deletion_flag)
+ : node_deletion_flag_(node_deletion_flag) {}
+
+ ~MySinkNode() final {
+ if (node_deletion_flag_ != nullptr) {
+ *node_deletion_flag_ = true;
+ }
+ }
+
+ private:
+ bool* node_deletion_flag_;
+};
+
+// Tests a chain of an |SinkNode|, |ProcessingNode| and
+// |SourceNode|.
+TEST(AudioNodesTest, SourceProcessingSinkConnectionTest) {
+ static const bool kOutputEmptyBuffer = false;
+ static const bool kEnableProcessOnEmptyInput = true;
+
+ auto source_node =
+ std::make_shared<MySourceNode>(kOutputEmptyBuffer, nullptr);
+ auto processing_node = std::make_shared<MyProcessingNode>(
+ kEnableProcessOnEmptyInput, nullptr, nullptr);
+ auto sink_node = std::make_shared<MySinkNode>(nullptr);
+
+ // Create chain of nodes.
+ sink_node->Connect(processing_node);
+ processing_node->Connect(source_node);
+
+ // Test output data.
+ const auto& data = sink_node->ReadInputs();
+ EXPECT_GT(data.size(), 0U);
+ EXPECT_TRUE(CompareAudioBuffer(*data[0], *GenerateTestAudioBuffer(1.0f)));
+}
+
+// Tests a chain of an |SinkNode| and |AudioMixerNode| connected to two
+// |SourceNodes|.
+TEST(AudioNodesTest, MixerProcessingConnectionTest) {
+ static const bool kOutputEmptyBuffer = false;
+ auto source_node_a =
+ std::make_shared<MySourceNode>(kOutputEmptyBuffer, nullptr);
+ auto source_node_b =
+ std::make_shared<MySourceNode>(kOutputEmptyBuffer, nullptr);
+ auto mixer_node = std::make_shared<MyAudioMixerNode>(nullptr);
+ auto sink_node = std::make_shared<MySinkNode>(nullptr);
+
+ // Create chain of nodes.
+ sink_node->Connect(mixer_node);
+ mixer_node->Connect(source_node_a);
+ mixer_node->Connect(source_node_b);
+
+ // Test output data.
+ const auto& data = sink_node->ReadInputs();
+ EXPECT_GT(data.size(), 0U);
+ EXPECT_TRUE(CompareAudioBuffer(*data[0], *GenerateTestAudioBuffer(2.0f)));
+}
+
+// Tests if ProcessingNode::AudioProcess() calls are skipped in case of
+// empty input buffers.
+TEST(AudioNodesTest, SkipProcessingOnEmptyInputTest) {
+ static const bool kEnableProcessOnEmptyInput = true;
+
+ bool audio_process_called = false;
+
+ // Tests that ProcessingNode::AudioProcess() is called in case source
+ // nodes do generate output.
+ {
+ static const bool kOutputEmptyBuffer = false;
+ auto source_node_a =
+ std::make_shared<MySourceNode>(kOutputEmptyBuffer, nullptr);
+ auto source_node_b =
+ std::make_shared<MySourceNode>(kOutputEmptyBuffer, nullptr);
+ auto processing_node = std::make_shared<MyProcessingNode>(
+ kEnableProcessOnEmptyInput, &audio_process_called, nullptr);
+ auto sink_node = std::make_shared<MySinkNode>(nullptr);
+
+ // Create chain of nodes.
+ sink_node->Connect(processing_node);
+ processing_node->Connect(source_node_a);
+ processing_node->Connect(source_node_b);
+
+ EXPECT_FALSE(audio_process_called);
+ const auto& data = sink_node->ReadInputs();
+ EXPECT_TRUE(audio_process_called);
+ EXPECT_GT(data.size(), 0U);
+ }
+
+ audio_process_called = false;
+
+ // Tests that ProcessingNode::AudioProcess() is *not* called in case
+ // source nodes do *not* generate output.
+ {
+ static const bool kOutputEmptyBuffer = true;
+ auto source_node_a =
+ std::make_shared<MySourceNode>(kOutputEmptyBuffer, nullptr);
+ auto source_node_b =
+ std::make_shared<MySourceNode>(kOutputEmptyBuffer, nullptr);
+ auto processing_node = std::make_shared<MyProcessingNode>(
+ false, &audio_process_called, nullptr);
+ auto sink_node = std::make_shared<MySinkNode>(nullptr);
+
+ // Create chain of nodes.
+ sink_node->Connect(processing_node);
+ processing_node->Connect(source_node_a);
+ processing_node->Connect(source_node_b);
+
+ EXPECT_FALSE(audio_process_called);
+ const auto& data = sink_node->ReadInputs();
+ EXPECT_FALSE(audio_process_called);
+ EXPECT_EQ(data.size(), 0U);
+ }
+}
+
+// Tests a chain of an |SinkNode|, |ProcessingNode| and
+// |SourceNode| and runs the node clean-up procedure with sources being
+// *not* marked with end-of-stream.
+TEST(AudioNodesTest, NodeCleanUpWithoutMarkEndOfStreamCallTest) {
+ static const bool kEnableProcessOnEmptyInput = true;
+
+ bool source_node_deleted = false;
+ bool processing_node_deleted = false;
+ bool sink_node_deleted = false;
+
+ auto sink_node = std::make_shared<MySinkNode>(&sink_node_deleted);
+
+ {
+ // Create a source and processing node and connect it to sink node.
+ auto source_node = std::make_shared<MySourceNode>(
+ /*output_empty_buffer=*/false, &source_node_deleted);
+ auto processing_node = std::make_shared<MyProcessingNode>(
+ kEnableProcessOnEmptyInput, nullptr, &processing_node_deleted);
+
+ // Connect nodes.
+ sink_node->Connect(processing_node);
+ processing_node->Connect(source_node);
+
+ // End-of-stream is not marked in source node.
+ // source_node->MarkEndOfStream();
+ }
+
+ EXPECT_FALSE(source_node_deleted);
+ EXPECT_FALSE(processing_node_deleted);
+ EXPECT_FALSE(sink_node_deleted);
+
+ sink_node->CleanUp();
+
+ EXPECT_FALSE(source_node_deleted);
+ EXPECT_FALSE(processing_node_deleted);
+ EXPECT_FALSE(sink_node_deleted);
+}
+
+// Tests a chain of an SinkNode, ProcessingNode and SourceNode
+// and runs the node clean-up procedure with sources being marked with
+// end-of-stream.
+TEST(AudioNodesTest, NodeCleanUpTest) {
+ static const bool kEnableProcessOnEmptyInput = true;
+
+ bool source_node_deleted = false;
+ bool processing_node_deleted = false;
+ bool sink_node_deleted = false;
+
+ auto sink_node = std::make_shared<MySinkNode>(&sink_node_deleted);
+
+ {
+ // Create a source and processing node and connect it to sink node.
+ auto source_node = std::make_shared<MySourceNode>(
+ /*output_empty_buffer=*/false, &source_node_deleted);
+ auto processing_node = std::make_shared<MyProcessingNode>(
+ kEnableProcessOnEmptyInput, nullptr, &processing_node_deleted);
+
+ // Connect nodes.
+ sink_node->Connect(processing_node);
+ processing_node->Connect(source_node);
+
+ // End of stream is marked in source node. Do not expect any data anymore.
+ source_node->MarkEndOfStream();
+ }
+
+ EXPECT_FALSE(source_node_deleted);
+ EXPECT_FALSE(processing_node_deleted);
+ EXPECT_FALSE(sink_node_deleted);
+
+ sink_node->CleanUp();
+
+ EXPECT_TRUE(source_node_deleted);
+ EXPECT_TRUE(processing_node_deleted);
+ EXPECT_FALSE(sink_node_deleted);
+}
+
+// Tests ProcessingNode::EnableProcessOnEmptyInput().
+TEST(AudioNodesTest, ProcessOnEmptyInputFlagTest) {
+ bool audio_process_called = false;
+
+ static const bool kEnableProcessOnEmptyInput = true;
+ static const bool kOutputEmptyBuffer = true;
+
+ auto source_node =
+ std::make_shared<MySourceNode>(kOutputEmptyBuffer, nullptr);
+ auto processing_node = std::make_shared<MyProcessingNode>(
+ kEnableProcessOnEmptyInput, &audio_process_called, nullptr);
+ auto sink_node = std::make_shared<MySinkNode>(nullptr);
+
+ // Create chain of nodes.
+ sink_node->Connect(processing_node);
+ processing_node->Connect(source_node);
+
+ EXPECT_FALSE(audio_process_called);
+ const auto& data = sink_node->ReadInputs();
+ EXPECT_TRUE(audio_process_called);
+ EXPECT_EQ(data.size(), 0U);
+}
+
+// Tests a chain of an |SinkNode| and |AudioMixerNode| without a |SourceNode|.
+TEST(AudioNodesTest, MissingSourceConnectionTest) {
+ auto mixer_node = std::make_shared<MyAudioMixerNode>(nullptr);
+ auto sink_node = std::make_shared<MySinkNode>(nullptr);
+
+ // Create chain of nodes.
+ sink_node->Connect(mixer_node);
+
+ // Test output data.
+ const auto& data = sink_node->ReadInputs();
+ EXPECT_EQ(data.size(), 0U);
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/node/node.h b/src/3rdparty/resonance-audio/resonance_audio/node/node.h
new file mode 100644
index 000000000..e6e10e39d
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/node/node.h
@@ -0,0 +1,258 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_NODE_NODE_H_
+#define RESONANCE_AUDIO_NODE_NODE_H_
+
+#include <memory>
+#include <set>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include "base/logging.h"
+
+namespace vraudio {
+
+// Implements a processing node in a synchronous processing graph.
+// This processing graph is expected to be directed, acyclic, and
+// accessed from a single thread.
+//
+// Subclasses are expected to implement Process(), which will read
+// from all of the instance's inputs, process the data as necessary,
+// and then write to all of its outputs.
+//
+// Data is passed through unique_ptrs, so nodes are expected to
+// modify data in place whenever it suits their purposes. If an
+// outputs is connected to more than one input, copies will be made for
+// each input.
+//
+// Graphs are managed through shared_ptrs. Orphaned nodes are kept
+// alive as long as they output to a living input. Ownership is
+// unidirectional -- from input to output -- in order to avoid
+// circular dependencies.
+class Node : public std::enable_shared_from_this<Node> {
+ public:
+ virtual ~Node() {}
+ virtual void Process() = 0;
+
+ // Disconnects from input nodes that are marked to be at the end of data
+ // stream.
+ //
+ // @return True if node is does not have any inputs and can be removed, false
+ // otherwise.
+ virtual bool CleanUp() = 0;
+
+ template <class T>
+ class Output;
+
+ // An endpoint for a node, this object consumes data from any connected
+ // outputs. Because an input may be connected to more than one output, it
+ // returns a vector of read data. All outputs must be of the same type.
+ template <typename T>
+ class Input {
+ public:
+ // Unordered map that stores pairs of input Node instances and their
+ // |Output| member.
+ typedef std::unordered_map<Output<T>*, std::shared_ptr<Node>> OutputNodeMap;
+
+ Input() {}
+ ~Input();
+
+ // Returns a vector of computed data, one for each connected output.
+ const std::vector<T>& Read();
+
+ // Connects this input to the specified output.
+ //
+ // @param node The parent of the output.
+ // @param output The output to connect to.
+ void Connect(const std::shared_ptr<Node>& node, Output<T>* output);
+
+ // Disconnects this input from the specified output.
+ //
+ // @param output The output to be disconnected.
+ void Disconnect(Output<T>* output);
+
+ // Returns the number of connected outputs.
+ //
+ // @return Number of connected outputs.
+ size_t GetNumConnections() const;
+
+ // Returns reference to OutputNodeMap map to obtain all connected nodes and
+ // their outputs.
+ const OutputNodeMap& GetConnectedNodeOutputPairs();
+
+ // Disable copy constructor.
+ Input(const Input& that) = delete;
+
+ private:
+ friend class Node::Output<T>;
+
+ void AddOutput(const std::shared_ptr<Node>& node, Output<T>* output);
+ void RemoveOutput(Output<T>* output);
+
+ OutputNodeMap outputs_;
+ std::vector<T> read_data_;
+ };
+
+ // An endpoint for a node, this object produces data for any connected inputs.
+ // Because an output may have more than one input, this object will duplicate
+ // any computed data, once for each connected input. All inputs must be of the
+ // same type.
+ //
+ // If an output does not have any data to deliver, it will ask its parent node
+ // to process more data. It is assumed that after processing, some new data
+ // will be written to this output.
+ template <typename T>
+ class Output {
+ public:
+ explicit Output(Node* node) : parent_(node) {}
+
+ // Parent nodes should call this function to push new data to any connected
+ // inputs. This data will be copied once for each connected input.
+ //
+ // @param data New data to pass to all connected inputs.
+ void Write(T data);
+
+ // Disable copy constructor.
+ Output(const Output& that) = delete;
+
+ private:
+ friend class Node::Input<T>;
+
+ // Signature of copy operator.
+ typedef T (*CopyOperator)(const T&);
+
+ // Returns a single piece of stored processed data. If no data exists,
+ // the parent node is processed to produce more data.
+ T PullData();
+
+ void AddInput(Input<T>* input);
+ bool RemoveInput(Input<T>* input);
+
+ std::set<Input<T>*> inputs_;
+ std::vector<T> written_data_;
+ Node* parent_;
+ };
+};
+
+template <class T>
+Node::Input<T>::~Input() {
+ for (auto& o : outputs_) {
+ CHECK(o.first->RemoveInput(this));
+ }
+}
+
+template <class T>
+const std::vector<T>& Node::Input<T>::Read() {
+ read_data_.clear();
+
+ for (auto& o : outputs_) {
+ // Obtain processed data.
+ T processed_data = o.first->PullData();
+ if (processed_data != nullptr) {
+ read_data_.emplace_back(std::move(processed_data));
+ }
+ }
+
+ return read_data_;
+}
+
+template <class T>
+void Node::Input<T>::Connect(const std::shared_ptr<Node>& node,
+ Output<T>* output) {
+ output->AddInput(this);
+ AddOutput(node, output);
+}
+
+// RemoveOutput(output) may trigger *output be destructed,
+// so we need to call output->RemoveInput(this) first.
+template <class T>
+void Node::Input<T>::Disconnect(Output<T>* output) {
+ output->RemoveInput(this);
+ RemoveOutput(output);
+}
+
+template <class T>
+size_t Node::Input<T>::GetNumConnections() const {
+ return outputs_.size();
+}
+
+template <class T>
+const typename Node::Input<T>::OutputNodeMap&
+Node::Input<T>::GetConnectedNodeOutputPairs() {
+ return outputs_;
+}
+
+template <class T>
+void Node::Input<T>::AddOutput(const std::shared_ptr<Node>& node,
+ Output<T>* output) {
+ outputs_[output] = node;
+
+ DCHECK(outputs_.find(output) != outputs_.end());
+}
+
+template <class T>
+void Node::Input<T>::RemoveOutput(Output<T>* output) {
+ outputs_.erase(output);
+}
+
+template <class T>
+T Node::Output<T>::PullData() {
+ if (written_data_.empty()) {
+ parent_->Process();
+ }
+
+ DCHECK(!written_data_.empty());
+
+ T return_value = std::move(written_data_.back());
+ written_data_.pop_back();
+ return return_value;
+}
+
+template <class T>
+void Node::Output<T>::Write(T data) {
+ DCHECK(written_data_.empty());
+ written_data_.clear();
+ written_data_.emplace_back(std::move(data));
+
+ // If we have more than one connected input, copy the data for each input.
+ for (size_t i = 1; i < inputs_.size(); i++) {
+ written_data_.push_back(written_data_[0]);
+ }
+
+ DCHECK(written_data_.size() == inputs_.size());
+}
+
+template <class T>
+void Node::Output<T>::AddInput(Input<T>* input) {
+ inputs_.insert(input);
+}
+
+template <class T>
+bool Node::Output<T>::RemoveInput(Input<T>* input) {
+ auto it = inputs_.find(input);
+ if (it == inputs_.end()) {
+ return false;
+ }
+
+ inputs_.erase(it);
+ return true;
+}
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_NODE_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/node/node_test.cc b/src/3rdparty/resonance-audio/resonance_audio/node/node_test.cc
new file mode 100644
index 000000000..e95a68a1c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/node/node_test.cc
@@ -0,0 +1,330 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "node/node.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+
+namespace vraudio {
+
+namespace {
+
+class SourceNode : public Node {
+ public:
+ explicit SourceNode(bool output_nullptr)
+ : output_nullptr_(output_nullptr), output_(this), next_value_(0) {}
+
+ void Process() final {
+ if (output_nullptr_) {
+ // Output nullptr.
+ output_.Write(nullptr);
+ } else {
+ output_.Write(&next_value_);
+ next_value_++;
+ }
+ }
+
+ bool CleanUp() final { return false; }
+
+ const bool output_nullptr_;
+ Node::Output<int*> output_;
+
+ private:
+ int next_value_;
+};
+
+class PassThrough : public Node {
+ public:
+ PassThrough() : output_(this) {}
+
+ void Process() final { output_.Write(input_.Read()[0]); }
+
+ bool CleanUp() final { return false; }
+
+ Node::Input<int*> input_;
+ Node::Output<int*> output_;
+};
+
+class IncNode : public Node {
+ public:
+ IncNode() : output_(this), inc_value_(0) {}
+
+ void Process() final {
+ inc_value_ = *input_.Read()[0];
+ ++inc_value_;
+ output_.Write(&inc_value_);
+ }
+
+ bool CleanUp() final { return false; }
+
+ Node::Input<int*> input_;
+ Node::Output<int*> output_;
+
+ private:
+ int inc_value_;
+};
+
+class SinkNode : public Node {
+ public:
+ void Process() final {}
+ bool CleanUp() final { return false; }
+
+ Node::Input<int*> input_;
+};
+
+// Class for testing multiple subscriber streams.
+class NodeTest : public ::testing::Test {
+ public:
+ void SetUp() override {}
+};
+
+TEST_F(NodeTest, SourceSink) {
+ static const bool kOutputNullptr = false;
+ auto source_node = std::make_shared<SourceNode>(kOutputNullptr);
+ auto sink_node = std::make_shared<SinkNode>();
+ sink_node->input_.Connect(source_node, &source_node->output_);
+
+ auto& data0 = sink_node->input_.Read();
+ EXPECT_EQ(data0.size(), 1U);
+ EXPECT_EQ(*data0[0], 1);
+
+ auto& data1 = sink_node->input_.Read();
+ EXPECT_EQ(data1.size(), 1U);
+ EXPECT_EQ(*data1[0], 2);
+}
+
+TEST_F(NodeTest, SourcePassThroughSink) {
+ static const bool kOutputNullptr = false;
+ auto source_node = std::make_shared<SourceNode>(kOutputNullptr);
+ auto copy_node = std::make_shared<PassThrough>();
+ auto sink_node = std::make_shared<SinkNode>();
+ sink_node->input_.Connect(copy_node, &copy_node->output_);
+ copy_node->input_.Connect(source_node, &source_node->output_);
+
+ auto& data0 = sink_node->input_.Read();
+ EXPECT_EQ(data0.size(), 1U);
+ EXPECT_EQ(*data0[0], 1);
+
+ auto& data1 = sink_node->input_.Read();
+ EXPECT_EQ(data1.size(), 1U);
+ EXPECT_EQ(*data1[0], 2);
+}
+
+TEST_F(NodeTest, TwoSources) {
+ static const bool kOutputNullptr = false;
+ auto source_node_a = std::make_shared<SourceNode>(kOutputNullptr);
+ auto source_node_b = std::make_shared<SourceNode>(kOutputNullptr);
+ auto sink_node = std::make_shared<SinkNode>();
+
+ sink_node->input_.Connect(source_node_a, &source_node_a->output_);
+ sink_node->input_.Connect(source_node_b, &source_node_b->output_);
+ EXPECT_EQ(source_node_a.use_count(), 2);
+ EXPECT_EQ(source_node_b.use_count(), 2);
+ EXPECT_EQ(sink_node.use_count(), 1);
+
+ auto& data0 = sink_node->input_.Read();
+ EXPECT_EQ(data0.size(), 2U);
+ EXPECT_EQ(*data0[0], 1);
+ EXPECT_EQ(*data0[1], 1);
+
+ auto& data1 = sink_node->input_.Read();
+ EXPECT_EQ(data1.size(), 2U);
+ EXPECT_EQ(*data1[0], 2);
+ EXPECT_EQ(*data1[1], 2);
+
+ sink_node.reset();
+ EXPECT_EQ(source_node_a.use_count(), 1);
+ EXPECT_EQ(source_node_b.use_count(), 1);
+}
+
+TEST_F(NodeTest, DoubleSink) {
+ static const bool kOutputNullptr = false;
+ auto source_node = std::make_shared<SourceNode>(kOutputNullptr);
+ auto sink_node_a = std::make_shared<SinkNode>();
+ auto sink_node_b = std::make_shared<SinkNode>();
+
+ sink_node_a->input_.Connect(source_node, &source_node->output_);
+ sink_node_b->input_.Connect(source_node, &source_node->output_);
+ EXPECT_EQ(sink_node_a.use_count(), 1);
+ EXPECT_EQ(sink_node_b.use_count(), 1);
+ EXPECT_EQ(source_node.use_count(), 3);
+
+ auto& dataA0 = sink_node_a->input_.Read();
+ auto& dataB0 = sink_node_b->input_.Read();
+ EXPECT_EQ(dataA0.size(), 1U);
+ EXPECT_EQ(dataB0.size(), 1U);
+ EXPECT_EQ(*dataA0[0], 1);
+ EXPECT_EQ(*dataB0[0], 1);
+
+ auto& dataA1 = sink_node_a->input_.Read();
+ auto& dataB1 = sink_node_b->input_.Read();
+ EXPECT_EQ(dataA1.size(), 1U);
+ EXPECT_EQ(dataB1.size(), 1U);
+ EXPECT_EQ(*dataA1[0], 2);
+ EXPECT_EQ(*dataB1[0], 2);
+
+ sink_node_a.reset();
+ EXPECT_EQ(source_node.use_count(), 2);
+ sink_node_b.reset();
+ EXPECT_EQ(source_node.use_count(), 1);
+}
+
+TEST_F(NodeTest, DoubleSinkWithIncrement) {
+ static const bool kOutputNullptr = false;
+ auto source_node = std::make_shared<SourceNode>(kOutputNullptr);
+ auto inc_node = std::make_shared<IncNode>();
+ auto sink_node_a = std::make_shared<SinkNode>();
+ auto sink_node_b = std::make_shared<SinkNode>();
+
+ sink_node_a->input_.Connect(source_node, &source_node->output_);
+ sink_node_b->input_.Connect(inc_node, &inc_node->output_);
+ inc_node->input_.Connect(source_node, &source_node->output_);
+
+ auto& dataA0 = sink_node_a->input_.Read();
+ auto& dataB0 = sink_node_b->input_.Read();
+ EXPECT_EQ(dataA0.size(), 1U);
+ EXPECT_EQ(dataB0.size(), 1U);
+ EXPECT_EQ(*dataA0[0], 1);
+ EXPECT_EQ(*dataB0[0], 2);
+
+ auto& dataA1 = sink_node_a->input_.Read();
+ auto& dataB1 = sink_node_b->input_.Read();
+ EXPECT_EQ(dataA1.size(), 1U);
+ EXPECT_EQ(dataB1.size(), 1U);
+ EXPECT_EQ(*dataA1[0], 2);
+ EXPECT_EQ(*dataB1[0], 3);
+}
+
+TEST_F(NodeTest, DisconnectSingleLink) {
+ static const bool kOutputNullptr = false;
+ auto source_node = std::make_shared<SourceNode>(kOutputNullptr);
+ auto sink_node = std::make_shared<SinkNode>();
+
+ sink_node->input_.Connect(source_node, &source_node->output_);
+ EXPECT_EQ(sink_node.use_count(), 1);
+ EXPECT_EQ(source_node.use_count(), 2);
+
+ auto& data0 = sink_node->input_.Read();
+ EXPECT_EQ(data0.size(), 1U);
+ EXPECT_EQ(*data0[0], 1);
+
+ sink_node->input_.Disconnect(&source_node->output_);
+ EXPECT_EQ(sink_node.use_count(), 1);
+ EXPECT_EQ(source_node.use_count(), 1);
+
+ auto& data1 = sink_node->input_.Read();
+ EXPECT_EQ(data1.size(), 0U);
+}
+
+TEST_F(NodeTest, DisconnectIntermediate) {
+ static const bool kOutputNullptr = false;
+ auto source_node = std::make_shared<SourceNode>(kOutputNullptr);
+ auto inc_node = std::make_shared<IncNode>();
+ auto sink_node = std::make_shared<SinkNode>();
+
+ sink_node->input_.Connect(inc_node, &inc_node->output_);
+ inc_node->input_.Connect(source_node, &source_node->output_);
+
+ inc_node->input_.Disconnect(&source_node->output_);
+ inc_node.reset();
+ EXPECT_EQ(sink_node.use_count(), 1);
+ EXPECT_EQ(source_node.use_count(), 1);
+}
+
+TEST_F(NodeTest, DisconnectMultiLink) {
+ static const bool kOutputNullptr = false;
+ auto source_node = std::make_shared<SourceNode>(kOutputNullptr);
+ auto inc_node = std::make_shared<IncNode>();
+ auto sink_node_a = std::make_shared<SinkNode>();
+ auto sink_node_b = std::make_shared<SinkNode>();
+ auto sink_node_c = std::make_shared<SinkNode>();
+
+ sink_node_a->input_.Connect(source_node, &source_node->output_);
+ sink_node_b->input_.Connect(inc_node, &inc_node->output_);
+ sink_node_c->input_.Connect(inc_node, &inc_node->output_);
+ inc_node->input_.Connect(source_node, &source_node->output_);
+
+ sink_node_a->input_.Disconnect(&source_node->output_);
+ EXPECT_EQ(sink_node_a.use_count(), 1);
+ EXPECT_EQ(sink_node_b.use_count(), 1);
+ EXPECT_EQ(sink_node_c.use_count(), 1);
+ EXPECT_EQ(inc_node.use_count(), 3);
+ EXPECT_EQ(source_node.use_count(), 2);
+
+ auto& dataA0 = sink_node_a->input_.Read();
+ auto& dataB0 = sink_node_b->input_.Read();
+ auto& dataC0 = sink_node_c->input_.Read();
+ EXPECT_EQ(dataA0.size(), 0U);
+ EXPECT_EQ(dataB0.size(), 1U);
+ EXPECT_EQ(*dataB0[0], 2);
+ EXPECT_EQ(dataC0.size(), 1U);
+ EXPECT_EQ(*dataC0[0], 2);
+
+ sink_node_b->input_.Disconnect(&inc_node->output_);
+ EXPECT_EQ(sink_node_a.use_count(), 1);
+ EXPECT_EQ(sink_node_b.use_count(), 1);
+ EXPECT_EQ(sink_node_c.use_count(), 1);
+ EXPECT_EQ(inc_node.use_count(), 2);
+ EXPECT_EQ(source_node.use_count(), 2);
+
+ auto& dataA1 = sink_node_a->input_.Read();
+ auto& dataB1 = sink_node_b->input_.Read();
+ auto& dataC1 = sink_node_c->input_.Read();
+ EXPECT_EQ(dataA1.size(), 0U);
+ EXPECT_EQ(dataB1.size(), 0U);
+ EXPECT_EQ(dataC1.size(), 1U);
+ EXPECT_EQ(*dataC1[0], 3);
+
+ sink_node_c->input_.Disconnect(&inc_node->output_);
+ EXPECT_EQ(sink_node_a.use_count(), 1);
+ EXPECT_EQ(sink_node_b.use_count(), 1);
+ EXPECT_EQ(sink_node_c.use_count(), 1);
+ EXPECT_EQ(inc_node.use_count(), 1);
+ EXPECT_EQ(source_node.use_count(), 2);
+
+ auto& dataA2 = sink_node_a->input_.Read();
+ auto& dataB2 = sink_node_b->input_.Read();
+ auto& dataC2 = sink_node_c->input_.Read();
+ EXPECT_EQ(dataA2.size(), 0U);
+ EXPECT_EQ(dataB2.size(), 0U);
+ EXPECT_EQ(dataC2.size(), 0U);
+
+ inc_node->input_.Disconnect(&source_node->output_);
+ EXPECT_EQ(sink_node_a.use_count(), 1);
+ EXPECT_EQ(sink_node_b.use_count(), 1);
+ EXPECT_EQ(inc_node.use_count(), 1);
+ EXPECT_EQ(source_node.use_count(), 1);
+}
+
+TEST_F(NodeTest, NullPtrSourceMultipleClients) {
+ static const bool kOutputNullptr = true;
+ auto source_node = std::make_shared<SourceNode>(kOutputNullptr);
+ auto sink_node_a = std::make_shared<SinkNode>();
+ auto sink_node_b = std::make_shared<SinkNode>();
+
+ sink_node_a->input_.Connect(source_node, &source_node->output_);
+ sink_node_b->input_.Connect(source_node, &source_node->output_);
+
+ auto& dataA = sink_node_a->input_.Read();
+ auto& dataB = sink_node_b->input_.Read();
+
+ EXPECT_TRUE(dataA.empty());
+ EXPECT_TRUE(dataB.empty());
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/node/processing_node.cc b/src/3rdparty/resonance-audio/resonance_audio/node/processing_node.cc
new file mode 100644
index 000000000..3053e8e6b
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/node/processing_node.cc
@@ -0,0 +1,89 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "node/processing_node.h"
+
+namespace vraudio {
+
+ProcessingNode::NodeInput::NodeInput(
+ const std::vector<const AudioBuffer*>& input_vector)
+ : input_vector_(input_vector) {}
+
+const AudioBuffer* ProcessingNode::NodeInput::GetSingleInput() const {
+ if (input_vector_.size() == 1) {
+ return input_vector_[0];
+ }
+ if (input_vector_.size() > 1) {
+ LOG(WARNING) << "GetSingleInput() called on multi buffer input";
+ }
+ return nullptr;
+}
+
+const std::vector<const AudioBuffer*>&
+ProcessingNode::NodeInput::GetInputBuffers() const {
+ return input_vector_;
+}
+
+ProcessingNode::ProcessingNode()
+ : Node(), output_stream_(this), process_on_no_input_(false) {}
+
+void ProcessingNode::Connect(
+ const std::shared_ptr<PublisherNodeType>& publisher_node) {
+ input_stream_.Connect(publisher_node->GetSharedNodePtr(),
+ publisher_node->GetOutput());
+}
+
+void ProcessingNode::Process() {
+ NodeInput input(input_stream_.Read());
+ const AudioBuffer* output = nullptr;
+ // Only call AudioProcess if input data is available.
+ if (process_on_no_input_ || !input.GetInputBuffers().empty()) {
+ output = AudioProcess(input);
+ }
+ output_stream_.Write(output);
+}
+
+bool ProcessingNode::CleanUp() {
+ CallCleanUpOnInputNodes();
+ return (input_stream_.GetNumConnections() == 0);
+}
+
+void ProcessingNode::EnableProcessOnEmptyInput(bool enable) {
+ process_on_no_input_ = enable;
+}
+
+void ProcessingNode::CallCleanUpOnInputNodes() {
+ // We need to make a copy of the OutputNodeMap map since it changes due to
+ // Disconnect() calls.
+ const auto connected_nodes = input_stream_.GetConnectedNodeOutputPairs();
+ for (const auto& input_node : connected_nodes) {
+ Output<const AudioBuffer*>* output = input_node.first;
+ std::shared_ptr<Node> node = input_node.second;
+ const bool is_ready_to_be_disconnected = node->CleanUp();
+ if (is_ready_to_be_disconnected) {
+ input_stream_.Disconnect(output);
+ }
+ }
+}
+
+std::shared_ptr<Node> ProcessingNode::GetSharedNodePtr() {
+ return shared_from_this();
+}
+Node::Output<const AudioBuffer*>* ProcessingNode::GetOutput() {
+ return &output_stream_;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/node/processing_node.h b/src/3rdparty/resonance-audio/resonance_audio/node/processing_node.h
new file mode 100644
index 000000000..6142c794c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/node/processing_node.h
@@ -0,0 +1,115 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_NODE_PROCESSING_NODE_H_
+#define RESONANCE_AUDIO_NODE_PROCESSING_NODE_H_
+
+#include <memory>
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "node/publisher_node.h"
+#include "node/subscriber_node.h"
+
+namespace vraudio {
+
+// Audio processing node that reads from multiple inputs, processes the
+// received data and outputs its result.
+class ProcessingNode : public Node,
+ public SubscriberNode<const AudioBuffer*>,
+ public PublisherNode<const AudioBuffer*> {
+ public:
+ typedef SubscriberNode<const AudioBuffer*> SubscriberNodeType;
+ typedef PublisherNode<const AudioBuffer*> PublisherNodeType;
+
+ // Helper class to manage incoming |AudioBuffer|s.
+ class NodeInput {
+ public:
+ // Constructor.
+ //
+ // @param input_vector Vector containing pointers to incoming
+ // |AudioBuffer|s.
+ explicit NodeInput(const std::vector<const AudioBuffer*>& input_vector);
+
+ // Returns a nullptr if zero or more than one input buffers are available.
+ // Otherwise a pointer to the single input |AudioBuffer| is returned. This
+ // method should be used if only a single input |AudioBuffer| is expected.
+ //
+ // @return Pointer to single input |AudioBuffer|.
+ const AudioBuffer* GetSingleInput() const;
+
+ // Returns vector with input |AudioBuffer|s.
+ //
+ // @return Pointer to single input |AudioBuffer|.
+ const std::vector<const AudioBuffer*>& GetInputBuffers() const;
+
+ // Delete copy constructor.
+ NodeInput(const NodeInput& that) = delete;
+
+ private:
+ // Const reference to vector of input |AudioBuffer|s.
+ const std::vector<const AudioBuffer*>& input_vector_;
+ };
+
+ ProcessingNode();
+
+ // SubscriberNode<InputType> implementation.
+ void Connect(
+ const std::shared_ptr<PublisherNodeType>& publisher_node) override;
+
+ // Node implementation.
+ void Process() final;
+ bool CleanUp() override;
+
+ // By default, calls to AudioProcess() are skipped in case of empty input
+ // buffers. This enables this node to process audio buffers in the absence of
+ // input data (which is needed for instance for a reverberation effect).
+ void EnableProcessOnEmptyInput(bool enable);
+
+ // Disable copy constructor.
+ ProcessingNode(const ProcessingNode& that) = delete;
+
+ protected:
+ // Calls |CleanUp| on all connected input nodes.
+ void CallCleanUpOnInputNodes();
+
+ // Pure virtual method to implement the audio processing method. This method
+ // receives a vector of all input arguments to be processed and requires to
+ // output a single output buffer.
+ //
+ // @param input Input instance to receive pointers to input |AudioBuffer|s.
+ // @return Returns output data.
+ virtual const AudioBuffer* AudioProcess(const NodeInput& input) = 0;
+
+ private:
+ // PublisherNode<OutputType> implementation.
+ std::shared_ptr<Node> GetSharedNodePtr() final;
+ Node::Output<const AudioBuffer*>* GetOutput() final;
+
+ // Input stream to poll for incoming data.
+ Node::Input<const AudioBuffer*> input_stream_;
+
+ // Output stream to write processed data to.
+ Node::Output<const AudioBuffer*> output_stream_;
+
+ // Flag that indicates if |AudioProcess| should be called in case no input
+ // data is available.
+ bool process_on_no_input_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_NODE_PROCESSING_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/node/publisher_node.h b/src/3rdparty/resonance-audio/resonance_audio/node/publisher_node.h
new file mode 100644
index 000000000..a6935da75
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/node/publisher_node.h
@@ -0,0 +1,51 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_NODE_PUBLISHER_NODE_H_
+#define RESONANCE_AUDIO_NODE_PUBLISHER_NODE_H_
+
+#include <memory>
+
+#include "base/logging.h"
+#include "node/node.h"
+
+namespace vraudio {
+
+// Interface for publisher nodes that declares helper methods required to
+// connect to a publisher node. All publishing nodes need to implement this
+// interface.
+//
+// @tparam OutputType Type of the output container being streamed.
+// @interface
+template <typename OutputType>
+class PublisherNode {
+ public:
+ virtual ~PublisherNode() {}
+
+ // Creates a shared pointer of the Node instance.
+ //
+ // @return Returns a shared pointer the of Node instance.
+ virtual std::shared_ptr<Node> GetSharedNodePtr() = 0;
+
+ // Get internal Node::Output instance.
+ //
+ // @return Returns a pointer to the internal Node::Output instance.
+ virtual Node::Output<OutputType>* GetOutput() = 0;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_NODE_PUBLISHER_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/node/sink_node.cc b/src/3rdparty/resonance-audio/resonance_audio/node/sink_node.cc
new file mode 100644
index 000000000..2d003009c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/node/sink_node.cc
@@ -0,0 +1,54 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "node/sink_node.h"
+
+#include "base/logging.h"
+
+namespace vraudio {
+
+SinkNode::SinkNode() : Node() {}
+
+const std::vector<const AudioBuffer*>& SinkNode::ReadInputs() {
+ return input_stream_.Read();
+}
+
+void SinkNode::Connect(
+ const std::shared_ptr<PublisherNodeType>& publisher_node) {
+ input_stream_.Connect(publisher_node->GetSharedNodePtr(),
+ publisher_node->GetOutput());
+}
+
+void SinkNode::Process() {
+ LOG(FATAL) << "Process should not be called on audio sink node.";
+}
+
+bool SinkNode::CleanUp() {
+ // We need to make a copy of the OutputNodeMap map since it might change due
+ // to Disconnect() calls.
+ const auto connected_nodes = input_stream_.GetConnectedNodeOutputPairs();
+ for (const auto& input_node : connected_nodes) {
+ Output<const AudioBuffer*>* output = input_node.first;
+ std::shared_ptr<Node> node = input_node.second;
+ const bool is_orphaned = node->CleanUp();
+ if (is_orphaned) {
+ input_stream_.Disconnect(output);
+ }
+ }
+ return false;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/node/sink_node.h b/src/3rdparty/resonance-audio/resonance_audio/node/sink_node.h
new file mode 100644
index 000000000..4bb3ade06
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/node/sink_node.h
@@ -0,0 +1,59 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_NODE_SINK_NODE_H_
+#define RESONANCE_AUDIO_NODE_SINK_NODE_H_
+
+#include <memory>
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "node/publisher_node.h"
+#include "node/subscriber_node.h"
+
+namespace vraudio {
+
+// Audio sink node that reads from multiple inputs.
+class SinkNode : public Node, public SubscriberNode<const AudioBuffer*> {
+ public:
+ typedef PublisherNode<const AudioBuffer*> PublisherNodeType;
+
+ SinkNode();
+
+ // Polls for data on all inputs of the sink node.
+ //
+ // @return A vector of input data.
+ const std::vector<const AudioBuffer*>& ReadInputs();
+
+ // SubscriberNode<AudioBuffer> implementation.
+ void Connect(
+ const std::shared_ptr<PublisherNodeType>& publisher_node) override;
+
+ // Node implementation.
+ void Process() final;
+ bool CleanUp() final;
+
+ // Disable copy constructor.
+ SinkNode(const SinkNode& that) = delete;
+
+ private:
+ // Input stream to poll for incoming data.
+ Node::Input<const AudioBuffer*> input_stream_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_NODE_SINK_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/node/source_node.cc b/src/3rdparty/resonance-audio/resonance_audio/node/source_node.cc
new file mode 100644
index 000000000..8567df6c6
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/node/source_node.cc
@@ -0,0 +1,41 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "node/source_node.h"
+
+namespace vraudio {
+
+SourceNode::SourceNode()
+ : Node(), output_stream_(this), end_of_stream_(false) {}
+
+void SourceNode::Process() {
+ const AudioBuffer* output = AudioProcess();
+ output_stream_.Write(output);
+}
+
+bool SourceNode::CleanUp() { return end_of_stream_; }
+
+std::shared_ptr<Node> SourceNode::GetSharedNodePtr() {
+ return shared_from_this();
+}
+
+Node::Output<const AudioBuffer*>* SourceNode::GetOutput() {
+ return &output_stream_;
+}
+
+void SourceNode::MarkEndOfStream() { end_of_stream_ = true; }
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/node/source_node.h b/src/3rdparty/resonance-audio/resonance_audio/node/source_node.h
new file mode 100644
index 000000000..73a598637
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/node/source_node.h
@@ -0,0 +1,68 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_NODE_SOURCE_NODE_H_
+#define RESONANCE_AUDIO_NODE_SOURCE_NODE_H_
+
+#include <atomic>
+#include <memory>
+
+#include "base/audio_buffer.h"
+#include "node/publisher_node.h"
+
+namespace vraudio {
+
+// Audio source node that outputs data via the AudioProcess() method.
+class SourceNode : public Node, public PublisherNode<const AudioBuffer*> {
+ public:
+ typedef PublisherNode<const AudioBuffer*> PublisherNodeType;
+
+ SourceNode();
+
+ // Node implementation.
+ void Process() final;
+ bool CleanUp() final;
+
+ // PublisherNode<OutputType> implementation.
+ std::shared_ptr<Node> GetSharedNodePtr() final;
+ Node::Output<const AudioBuffer*>* GetOutput() final;
+
+ // Marks this node as being out of data and to be removed during the next
+ // clean-up cycle.
+ void MarkEndOfStream();
+
+ // Disable copy constructor.
+ SourceNode(const SourceNode& that) = delete;
+
+ protected:
+ // Pure virtual method to implement the audio processing method. This method
+ // requires to return a single output buffer that can be processed by the node
+ // subscribers.
+ //
+ // @return Returns output data.
+ virtual const AudioBuffer* AudioProcess() = 0;
+
+ private:
+ // Output stream to write processed data to.
+ Node::Output<const AudioBuffer*> output_stream_;
+
+ // Flag indicating if this source node can be removed.
+ std::atomic<bool> end_of_stream_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_NODE_SOURCE_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/node/subscriber_node.h b/src/3rdparty/resonance-audio/resonance_audio/node/subscriber_node.h
new file mode 100644
index 000000000..f297ce9e4
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/node/subscriber_node.h
@@ -0,0 +1,48 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_NODE_SUBSCRIBER_NODE_H_
+#define RESONANCE_AUDIO_NODE_SUBSCRIBER_NODE_H_
+
+#include <memory>
+
+#include "base/logging.h"
+#include "node/publisher_node.h"
+
+namespace vraudio {
+
+// Interface for subscriber nodes that declares the connection and
+// disconnection methods. All subscribing nodes need to implement this
+// interface.
+//
+// @tparam InputType Input data type, i. e., the output data type of nodes to
+// connect to.
+// @interface
+template <typename InputType>
+class SubscriberNode {
+ public:
+ virtual ~SubscriberNode() {}
+
+ // Connects this node to |publisher_node|.
+ //
+ // @param publisher_node Publisher node to connect to.
+ virtual void Connect(
+ const std::shared_ptr<PublisherNode<InputType>>& publisher_node) = 0;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_NODE_SUBSCRIBER_NODE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader.cc
new file mode 100644
index 000000000..01aa0f473
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader.cc
@@ -0,0 +1,66 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/buffer_crossfader.h"
+
+#include "base/constants_and_types.h"
+#include "base/simd_utils.h"
+
+namespace vraudio {
+
+BufferCrossfader::BufferCrossfader(size_t num_frames)
+ : crossfade_buffer_(kNumStereoChannels, num_frames) {
+ DCHECK_NE(num_frames, 0);
+ // Initialize the |crossfade_buffer_|.
+ auto* fade_in_channel = &crossfade_buffer_[0];
+ auto* fade_out_channel = &crossfade_buffer_[1];
+ for (size_t frame = 0; frame < num_frames; ++frame) {
+ const float crossfade_factor =
+ static_cast<float>(frame) / static_cast<float>(num_frames);
+ (*fade_in_channel)[frame] = crossfade_factor;
+ (*fade_out_channel)[frame] = 1.0f - crossfade_factor;
+ }
+}
+
+void BufferCrossfader::ApplyLinearCrossfade(const AudioBuffer& input_fade_in,
+ const AudioBuffer& input_fade_out,
+ AudioBuffer* output) const {
+ DCHECK(output);
+ DCHECK_NE(output, &input_fade_in);
+ DCHECK_NE(output, &input_fade_out);
+
+ const size_t num_channels = input_fade_in.num_channels();
+ const size_t num_frames = input_fade_in.num_frames();
+ DCHECK_EQ(num_channels, input_fade_out.num_channels());
+ DCHECK_EQ(num_channels, output->num_channels());
+ DCHECK_EQ(num_frames, input_fade_out.num_frames());
+ DCHECK_EQ(num_frames, output->num_frames());
+ DCHECK_EQ(num_frames, crossfade_buffer_.num_frames());
+
+ const auto* gain_fade_in_channel = crossfade_buffer_[0].begin();
+ const auto* gain_fade_out_channel = crossfade_buffer_[1].begin();
+ for (size_t channel = 0; channel < num_channels; ++channel) {
+ const auto* input_fade_in_channel = input_fade_in[channel].begin();
+ const auto* input_fade_out_channel = input_fade_out[channel].begin();
+ auto* output_channel = ((*output)[channel]).begin();
+ MultiplyPointwise(num_frames, gain_fade_in_channel, input_fade_in_channel,
+ output_channel);
+ MultiplyAndAccumulatePointwise(num_frames, gain_fade_out_channel,
+ input_fade_out_channel, output_channel);
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader.h b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader.h
new file mode 100644
index 000000000..25502df3a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader.h
@@ -0,0 +1,48 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_BUFFER_CROSSFADER_H_
+#define RESONANCE_AUDIO_UTILS_BUFFER_CROSSFADER_H_
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Class that takes two input buffers and produces an output buffer by applying
+// linear crossfade between the inputs.
+class BufferCrossfader {
+ public:
+ explicit BufferCrossfader(size_t num_frames);
+
+ // Applies linear crossfade for given input buffers and stores the result in
+ // |output| buffer. Note that, in-place processing is *not* supported by this
+ // method, the output buffer must be different than the input buffers.
+ //
+ // @param input_fade_in Input buffer to fade-in to.
+ // @param input_fade_out Input buffer to fade-out from.
+ // @param output Output buffer to store the crossfaded result.
+ void ApplyLinearCrossfade(const AudioBuffer& input_fade_in,
+ const AudioBuffer& input_fade_out,
+ AudioBuffer* output) const;
+
+ private:
+ // Stereo audio buffer to store crossfade decay and growth multipliers.
+ AudioBuffer crossfade_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_BUFFER_CROSSFADER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader_test.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader_test.cc
new file mode 100644
index 000000000..c14a0e950
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_crossfader_test.cc
@@ -0,0 +1,53 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/buffer_crossfader.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+namespace {
+
+// Tests that the linear crossfade is correctly applied to an input pair.
+TEST(BufferCrossfaderTest, ApplyLinearCrossfadeTest) {
+ const size_t kNumFrames = 5;
+ const size_t kTestValue = 1.0f;
+ // Initialize input buffers.
+ AudioBuffer input_fade_in(kNumMonoChannels, kNumFrames);
+ AudioBuffer input_fade_out(kNumMonoChannels, kNumFrames);
+ for (size_t i = 0; i < kNumFrames; ++i) {
+ input_fade_in[0][i] = kTestValue;
+ input_fade_out[0][i] = kTestValue;
+ }
+ // Initialize output buffer.
+ AudioBuffer output(kNumMonoChannels, kNumFrames);
+ output.Clear();
+ // Initialize a new crossfader and apply linear crossfade.
+ BufferCrossfader crossfader(kNumFrames);
+ crossfader.ApplyLinearCrossfade(input_fade_in, input_fade_out, &output);
+ // Verify that the output buffer is correctly filled in as expected.
+ for (size_t i = 0; i < kNumFrames; ++i) {
+ EXPECT_FLOAT_EQ(kTestValue, output[0][i]);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner.cc
new file mode 100644
index 000000000..91023fed5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner.cc
@@ -0,0 +1,160 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "utils/buffer_partitioner.h"
+
+#include "utils/planar_interleaved_conversion.h"
+
+namespace vraudio {
+
+BufferPartitioner::BufferPartitioner(size_t num_channels,
+ size_t frames_per_buffer,
+ NewBufferCallback buffer_callback)
+ : num_channels_(num_channels),
+ frames_per_buffer_(frames_per_buffer),
+ buffer_callback_(std::move(buffer_callback)),
+ current_buffer_ptr_(nullptr),
+ current_buffer_write_position_frames_(0),
+ planar_channel_ptrs_(num_channels) {}
+
+size_t BufferPartitioner::GetNumGeneratedBuffersForNumInputFrames(
+ size_t num_input_frames) const {
+ return (current_buffer_write_position_frames_ + num_input_frames) /
+ frames_per_buffer_;
+}
+
+void BufferPartitioner::AddBuffer(const int16* interleaved_buffer,
+ size_t num_channels, size_t num_frames) {
+ AddBufferTemplated<const int16*>(interleaved_buffer, num_channels,
+ num_frames);
+}
+
+void BufferPartitioner::AddBuffer(const float* interleaved_buffer,
+ size_t num_channels, size_t num_frames) {
+ AddBufferTemplated<const float*>(interleaved_buffer, num_channels,
+ num_frames);
+}
+
+void BufferPartitioner::AddBuffer(const float* const* planar_buffer,
+ size_t num_channels, size_t num_frames) {
+ AddBufferTemplated<const float* const*>(planar_buffer, num_channels,
+ num_frames);
+}
+
+void BufferPartitioner::AddBuffer(const int16* const* planar_buffer,
+ size_t num_channels, size_t num_frames) {
+ AddBufferTemplated<const int16* const*>(planar_buffer, num_channels,
+ num_frames);
+}
+
+void BufferPartitioner::AddBuffer(const AudioBuffer& audio_buffer) {
+ AddBuffer(audio_buffer.num_frames(), audio_buffer);
+}
+
+void BufferPartitioner::AddBuffer(size_t num_valid_frames,
+ const AudioBuffer& audio_buffer) {
+ DCHECK_EQ(audio_buffer.num_channels(), num_channels_);
+ DCHECK_LE(num_valid_frames, audio_buffer.num_frames());
+ for (size_t channel = 0; channel < num_channels_; ++channel) {
+ planar_channel_ptrs_[channel] = &audio_buffer[channel][0];
+ }
+ AddBuffer(planar_channel_ptrs_.data(), audio_buffer.num_channels(),
+ num_valid_frames);
+}
+
+size_t BufferPartitioner::GetNumBufferedFrames() const {
+ return current_buffer_write_position_frames_;
+}
+
+size_t BufferPartitioner::Flush() {
+ if (current_buffer_write_position_frames_ == 0 ||
+ current_buffer_ptr_ == nullptr) {
+ return 0;
+ }
+ DCHECK_LE(current_buffer_write_position_frames_,
+ current_buffer_ptr_->num_frames());
+ const size_t num_zeropadded_frames =
+ current_buffer_ptr_->num_frames() - current_buffer_write_position_frames_;
+ for (AudioBuffer::Channel& channel : *current_buffer_ptr_) {
+ DCHECK_LE(current_buffer_write_position_frames_, channel.size());
+ std::fill(channel.begin() + current_buffer_write_position_frames_,
+ channel.end(), 0.0f);
+ }
+ current_buffer_ptr_ = buffer_callback_(current_buffer_ptr_);
+ current_buffer_write_position_frames_ = 0;
+ return num_zeropadded_frames;
+}
+
+void BufferPartitioner::Clear() {
+ current_buffer_ptr_ = nullptr;
+ current_buffer_write_position_frames_ = 0;
+}
+
+template <typename BufferType>
+void BufferPartitioner::AddBufferTemplated(BufferType buffer,
+ size_t num_channels,
+ size_t num_frames) {
+ DCHECK_EQ(num_channels, num_channels_);
+
+ size_t input_read_frame = 0;
+ while (input_read_frame < num_frames) {
+ if (current_buffer_ptr_ == nullptr) {
+ current_buffer_ptr_ = buffer_callback_(nullptr);
+ if (current_buffer_ptr_ == nullptr) {
+ LOG(WARNING) << "No input buffer received";
+ return;
+ }
+ DCHECK_EQ(current_buffer_ptr_->num_frames(), frames_per_buffer_);
+ DCHECK_EQ(current_buffer_ptr_->num_channels(), num_channels_);
+ current_buffer_write_position_frames_ = 0;
+ }
+ DCHECK_GT(frames_per_buffer_, current_buffer_write_position_frames_);
+ const size_t remaining_frames_in_temp_buffer =
+ frames_per_buffer_ - current_buffer_write_position_frames_;
+ const size_t remaining_frames_in_input_buffer =
+ num_frames - input_read_frame;
+ const size_t num_frames_to_process = std::min(
+ remaining_frames_in_temp_buffer, remaining_frames_in_input_buffer);
+
+ FillAudioBufferWithOffset(buffer, num_frames, num_channels_,
+ input_read_frame,
+ current_buffer_write_position_frames_,
+ num_frames_to_process, current_buffer_ptr_);
+
+ input_read_frame += num_frames_to_process;
+
+ // Update write pointers in temporary buffer.
+ current_buffer_write_position_frames_ += num_frames_to_process;
+ if (current_buffer_write_position_frames_ == frames_per_buffer_) {
+ // Current buffer is filled with data -> pass it to callback.
+ current_buffer_ptr_ = buffer_callback_(current_buffer_ptr_);
+ current_buffer_write_position_frames_ = 0;
+ if (current_buffer_ptr_ == nullptr) {
+ LOG(WARNING) << "No input buffer received";
+ return;
+ }
+ DCHECK_EQ(current_buffer_ptr_->num_frames(), frames_per_buffer_);
+ DCHECK_EQ(current_buffer_ptr_->num_channels(), num_channels_);
+ }
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner.h b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner.h
new file mode 100644
index 000000000..208ad886c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner.h
@@ -0,0 +1,152 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_BUFFER_PARTITIONER_H_
+#define RESONANCE_AUDIO_UTILS_BUFFER_PARTITIONER_H_
+
+#include <functional>
+#include <memory>
+
+#include "base/audio_buffer.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+// Packages input buffers of arbitrary sizes into fixed size |AudioBuffer|s.
+class BufferPartitioner {
+ public:
+ // Callback to receive processed and assign empty |AudioBuffer|s while
+ // processing input buffers.
+ //
+ // @param output Pointer to partitioned |AudioBuffer| with input audio data.
+ // @return Pointer to the next |AudioBuffer| to be filled.
+ typedef std::function<AudioBuffer*(AudioBuffer* output)> NewBufferCallback;
+
+ // Constructor.
+ //
+ // @param num_channels Number of audio channels in input and output buffers.
+ // @param frames_per_buffer Number of frames in output |AudioBuffer|s.
+ // @param buffer_callback Callback to receive output |AudioBuffer|s.
+ BufferPartitioner(size_t num_channels, size_t frames_per_buffer,
+ NewBufferCallback buffer_callback);
+
+ // Predicts the number of generated buffers for a given number of input frames
+ // and based on the current fill state of the internal |temp_buffer_|.
+ //
+ // @param num_input_frames Number of input frames.
+ // @return Number of generated output buffers.
+ size_t GetNumGeneratedBuffersForNumInputFrames(size_t num_input_frames) const;
+
+ // Returns the number of buffered frames in internal |temp_buffer_|.
+ size_t GetNumBufferedFrames() const;
+
+ // Adds an interleaved int16 input buffer. This method triggers
+ // |NewBufferCallback| whenever a new |AudioBuffer| has been generated.
+ //
+ // @param interleaved_buffer Interleaved input buffer.
+ // @param num_channels Number of channels in input buffer.
+ // @param num_frames Number of frames in input buffer.
+ void AddBuffer(const int16* interleaved_buffer, size_t num_channels,
+ size_t num_frames);
+
+ // Adds an interleaved float input buffer. This method triggers
+ // |NewBufferCallback| whenever a new |AudioBuffer| has been generated.
+ //
+ // @param interleaved_buffer Interleaved input buffer.
+ // @param num_channels Number of channels in input buffer.
+ // @param num_frames Number of frames in input buffer.
+ void AddBuffer(const float* interleaved_buffer, size_t num_channels,
+ size_t num_frames);
+
+ // Adds a planar float input buffer. This method triggers
+ // |NewBufferCallback| whenever a new |AudioBuffer| has been generated.
+ //
+ // @param planar_buffer Pointer to array of pointers for each audio channel.
+ // @param num_channels Number of channels in input buffer.
+ // @param num_frames Number of frames in input buffer.
+ void AddBuffer(const float* const* planar_buffer, size_t num_channels,
+ size_t num_frames);
+
+ // Adds a planar int16 input buffer. This method triggers
+ // |NewBufferCallback| whenever a new |AudioBuffer| has been generated.
+ //
+ // @param planar_buffer Pointer to array of pointers for each audio channel.
+ // @param num_channels Number of channels in input buffer.
+ // @param num_frames Number of frames in input buffer.
+ void AddBuffer(const int16* const* planar_buffer, size_t num_channels,
+ size_t num_frames);
+
+ // Adds an |AudioBuffer|. This method triggers |NewBufferCallback| whenever a
+ // new |AudioBuffer| has been generated.
+ //
+ // @param audio_buffer Planar |AudioBuffer| input.
+ void AddBuffer(const AudioBuffer& audio_buffer);
+
+ // Adds an |AudioBuffer| and specifies how many of that audio buffers frames
+ // are valid. This method triggers |NewBufferCallback| whenever a new
+ // |AudioBuffer| has been generated.
+ //
+ // @param num_valid_frames Indicates the number of frames which are actually
+ // valid in the audio buffer passed. Frames after this will be ignored.
+ // @param audio_buffer Planar |AudioBuffer| input.
+ void AddBuffer(size_t num_valid_frames, const AudioBuffer& audio_buffer);
+
+ // Flushes the internal temporary |AudioBuffer| by filling the remaining
+ // audio frames with silence.
+ //
+ // @return Number of zero padded audio frames. Zero if the internal buffer
+ // is empty.
+ size_t Flush();
+
+ // Clears internal temporary buffer that holds remaining audio frames.
+ void Clear();
+
+ private:
+ // Adds an interleaved and planar float and int16 input buffer as well as
+ // planar |AudioBuffer| input. This method triggers |NewBufferCallback|
+ // whenever a new |AudioBuffer| has been generated.
+ //
+ // @tparam BufferType Input buffer type.
+ // @param buffer Input buffer.
+ // @param num_channels Number of channels in input buffer.
+ // @param num_frames Number of frames in input buffer.
+ template <typename BufferType>
+ void AddBufferTemplated(BufferType buffer, size_t num_channels,
+ size_t num_frames);
+
+ // Number of channels in input buffers.
+ const size_t num_channels_;
+
+ // Number of frames per buffer in output buffers.
+ const size_t frames_per_buffer_;
+
+ // Callback to output generated |AudioBuffer|s.
+ const NewBufferCallback buffer_callback_;
+
+ // Temporary buffer to remaining samples from input buffers.
+ AudioBuffer* current_buffer_ptr_; // Not owned.
+
+ // Current write position in frames in temporary buffer.
+ size_t current_buffer_write_position_frames_;
+
+ // Helper vector to obtain an array of planar channel pointers from an
+ // |AudioBuffer|.
+ std::vector<const float*> planar_channel_ptrs_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_BUFFER_PARTITIONER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner_test.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner_test.cc
new file mode 100644
index 000000000..a486b1f23
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_partitioner_test.cc
@@ -0,0 +1,241 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/buffer_partitioner.h"
+
+#include <memory>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+#include "utils/planar_interleaved_conversion.h"
+#include "utils/test_util.h"
+
+namespace vraudio {
+
+const size_t kNumFramesPerBuffer = 64;
+
+using vraudio::AudioBuffer;
+
+class BufferPartitionerTest : public ::testing::Test {
+ public:
+ // Public validation method. This is called for every generated |AudioBuffer|.
+ AudioBuffer* ValidateAudioBufferCallback(AudioBuffer* audio_buffer) {
+ if (audio_buffer != nullptr) {
+ std::vector<float> received_buffer_interleaved;
+ FillExternalBuffer(*audio_buffer, &received_buffer_interleaved);
+ total_received_buffer_interleaved_.insert(
+ total_received_buffer_interleaved_.end(),
+ received_buffer_interleaved.begin(),
+ received_buffer_interleaved.end());
+
+ ++num_total_buffers_received_;
+ num_total_frames_received_ += audio_buffer->num_frames();
+ }
+ ++num_total_callbacks_triggered_;
+ return &partitioned_buffer_;
+ }
+
+ protected:
+ BufferPartitionerTest()
+ : partitioned_buffer_(kNumMonoChannels, kNumFramesPerBuffer),
+ partitioner_(
+ kNumMonoChannels, kNumFramesPerBuffer,
+ std::bind(&BufferPartitionerTest::ValidateAudioBufferCallback, this,
+ std::placeholders::_1)),
+ num_total_frames_received_(0),
+ num_total_buffers_received_(0),
+ num_total_callbacks_triggered_(0) {}
+ ~BufferPartitionerTest() override {}
+
+ // Returns a section of an |AudioBuffer| in interleaved format.
+ template <typename T>
+ std::vector<T> GetInterleavedVectorFromAudioBufferSection(
+ const AudioBuffer& planar_buffer, size_t frame_offset,
+ size_t num_frames) {
+ CHECK_GE(planar_buffer.num_frames(), frame_offset + num_frames);
+ std::vector<T> return_vector(planar_buffer.num_channels() * num_frames);
+
+ FillExternalBufferWithOffset(
+ planar_buffer, frame_offset, return_vector.data(), num_frames,
+ planar_buffer.num_channels(), 0 /* output_offset_frames */, num_frames);
+
+ return return_vector;
+ }
+
+ template <typename T>
+ void SmallBufferInputTest(float buffer_epsilon) {
+ ResetTest();
+
+ const size_t kNumInputBuffers = 8;
+ const size_t kNumFramesPerTestBuffer =
+ kNumFramesPerBuffer / kNumInputBuffers;
+
+ AudioBuffer test_buffer(vraudio::kNumMonoChannels, kNumFramesPerBuffer);
+ GenerateSawToothSignal(kNumFramesPerBuffer, &test_buffer[0]);
+
+ for (size_t i = 0; i < kNumInputBuffers; ++i) {
+ const std::vector<T> input_interleaved =
+ GetInterleavedVectorFromAudioBufferSection<T>(
+ test_buffer, kNumFramesPerTestBuffer * i,
+ kNumFramesPerTestBuffer);
+
+ partitioner_.AddBuffer(input_interleaved.data(), kNumMonoChannels,
+ kNumFramesPerTestBuffer);
+ }
+ EXPECT_EQ(num_total_buffers_received_, 1U);
+ EXPECT_EQ(num_total_callbacks_triggered_, num_total_buffers_received_ + 1);
+ EXPECT_EQ(num_total_frames_received_, kNumFramesPerBuffer);
+
+ AudioBuffer reconstructed_buffer(kNumMonoChannels, kNumFramesPerBuffer);
+ FillAudioBuffer(total_received_buffer_interleaved_, kNumMonoChannels,
+ &reconstructed_buffer);
+
+ EXPECT_TRUE(CompareAudioBuffers(test_buffer[0], reconstructed_buffer[0],
+ buffer_epsilon));
+ }
+
+ template <typename T>
+ void LargeBufferTest(float buffer_epsilon) {
+ ResetTest();
+ const size_t kNumOutputBuffers = 8;
+ const size_t kNumFramesPerTestBuffer =
+ kNumFramesPerBuffer * kNumOutputBuffers;
+
+ AudioBuffer test_buffer(vraudio::kNumMonoChannels, kNumFramesPerTestBuffer);
+ GenerateSawToothSignal(kNumFramesPerTestBuffer, &test_buffer[0]);
+
+ const std::vector<T> input_interleaved =
+ GetInterleavedVectorFromAudioBufferSection<T>(test_buffer, 0,
+ kNumFramesPerTestBuffer);
+
+ partitioner_.AddBuffer(input_interleaved.data(), kNumMonoChannels,
+ kNumFramesPerTestBuffer);
+
+ EXPECT_EQ(num_total_buffers_received_, kNumOutputBuffers);
+ EXPECT_EQ(num_total_callbacks_triggered_, num_total_buffers_received_ + 1);
+ EXPECT_EQ(num_total_frames_received_, kNumFramesPerTestBuffer);
+
+ AudioBuffer reconstructed_buffer(kNumMonoChannels, kNumFramesPerTestBuffer);
+ FillAudioBuffer(total_received_buffer_interleaved_, kNumMonoChannels,
+ &reconstructed_buffer);
+
+ EXPECT_TRUE(CompareAudioBuffers(test_buffer[0], reconstructed_buffer[0],
+ buffer_epsilon));
+ }
+
+ void ResetTest() {
+ num_total_frames_received_ = 0;
+ num_total_buffers_received_ = 0;
+ num_total_callbacks_triggered_ = 0;
+ total_received_buffer_interleaved_.clear();
+
+ partitioner_.Clear();
+ }
+
+ AudioBuffer partitioned_buffer_;
+ std::vector<float> total_received_buffer_interleaved_;
+
+ BufferPartitioner partitioner_;
+
+ // Stores the total number of frames received in
+ // |ValidateAudioBufferCallback|.
+ size_t num_total_frames_received_;
+
+ // Stores the total number of buffers received in
+ // |ValidateAudioBufferCallback|.
+ size_t num_total_buffers_received_;
+
+ // Stores the total number of callbacks being triggered in
+ // |ValidateAudioBufferCallback|.
+ size_t num_total_callbacks_triggered_;
+};
+
+// Tests the concatenation of multiple small buffers into a single
+// |AudioBuffer|.
+TEST_F(BufferPartitionerTest, TestSmallBufferInput) {
+ // int16 to float conversions introduce rounding errors.
+ SmallBufferInputTest<int16>(1e-4f /* buffer_epsilon */);
+ SmallBufferInputTest<float>(1e-6f /* buffer_epsilon */);
+}
+
+// Tests the splitting of a large input buffer into multiple |AudioBuffer|s.
+TEST_F(BufferPartitionerTest, TestLargeBufferInput) {
+ // int16 to float conversions introduce rounding errors.
+ LargeBufferTest<int16>(1e-4f /* buffer_epsilon */);
+ LargeBufferTest<float>(1e-6f /* buffer_epsilon */);
+}
+
+// Tests the GetNumBufferedFramesTest() and
+// GetNumGeneratedBuffersForNumInputFrames() methods.
+TEST_F(BufferPartitionerTest, GetNumBufferedFramesTest) {
+ const std::vector<float> input_interleaved(1, 1.0f);
+
+ EXPECT_EQ(partitioner_.GetNumGeneratedBuffersForNumInputFrames(
+ kNumFramesPerBuffer - 1),
+ 0U);
+ EXPECT_EQ(
+ partitioner_.GetNumGeneratedBuffersForNumInputFrames(kNumFramesPerBuffer),
+ 1U);
+
+ for (size_t i = 0; i < kNumFramesPerBuffer * 2; ++i) {
+ EXPECT_EQ(partitioner_.GetNumBufferedFrames(), i % kNumFramesPerBuffer);
+
+ const size_t large_random_frame_number =
+ i * 7 * kNumFramesPerBuffer + 13 * i;
+ // Expected number of generated buffers is based on
+ // |large_random_frame_number| and the internally stored remainder |i %
+ // kNumFramesPerBuffer|.
+ const size_t expected_num_generated_buffers =
+ (large_random_frame_number + partitioner_.GetNumBufferedFrames()) /
+ kNumFramesPerBuffer;
+
+ EXPECT_EQ(partitioner_.GetNumGeneratedBuffersForNumInputFrames(
+ large_random_frame_number),
+ expected_num_generated_buffers);
+
+ // Add single frame to |partinioner_|.
+ partitioner_.AddBuffer(input_interleaved.data(), kNumMonoChannels, 1);
+ }
+}
+
+// Tests the Flush() method.
+TEST_F(BufferPartitionerTest, FlushTest) {
+ AudioBuffer test_buffer(vraudio::kNumMonoChannels, kNumFramesPerBuffer);
+ GenerateDiracImpulseFilter(0, &test_buffer[0]);
+
+ const std::vector<float> input_interleaved =
+ GetInterleavedVectorFromAudioBufferSection<float>(
+ test_buffer, 0 /* frame_offset */, kNumFramesPerBuffer);
+
+ // Add only the first sample that contains the dirac impulse.
+ partitioner_.AddBuffer(input_interleaved.data(), kNumMonoChannels, 1);
+ partitioner_.Flush();
+
+ EXPECT_EQ(num_total_buffers_received_, 1U);
+ EXPECT_EQ(num_total_callbacks_triggered_, num_total_buffers_received_ + 1);
+ EXPECT_EQ(num_total_frames_received_, kNumFramesPerBuffer);
+
+ AudioBuffer reconstructed_buffer(kNumMonoChannels, kNumFramesPerBuffer);
+ FillAudioBuffer(total_received_buffer_interleaved_, kNumMonoChannels,
+ &reconstructed_buffer);
+
+ EXPECT_TRUE(CompareAudioBuffers(test_buffer[0], reconstructed_buffer[0],
+ kEpsilonFloat));
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner.cc
new file mode 100644
index 000000000..fb4f51b36
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner.cc
@@ -0,0 +1,132 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "utils/buffer_unpartitioner.h"
+
+#include "utils/planar_interleaved_conversion.h"
+#include "utils/sample_type_conversion.h"
+
+namespace vraudio {
+
+BufferUnpartitioner::BufferUnpartitioner(size_t num_channels,
+ size_t frames_per_buffer,
+ GetBufferCallback buffer_callback)
+ : num_channels_(num_channels),
+ frames_per_buffer_(frames_per_buffer),
+ buffer_callback_(std::move(buffer_callback)),
+ current_input_buffer_(nullptr),
+ current_buffer_read_offset_frames_(0) {
+ DCHECK_GT(frames_per_buffer_, 0);
+ DCHECK_GT(num_channels, 0);
+}
+
+size_t BufferUnpartitioner::GetNumBuffersRequestedForNumInputFrames(
+ size_t num_output_frames) const {
+ if (num_output_frames == 0) {
+ return 0;
+ }
+ return (num_output_frames - GetNumFramesAvailableInBuffer() +
+ frames_per_buffer_ - 1) /
+ frames_per_buffer_;
+}
+
+size_t BufferUnpartitioner::GetBuffer(int16* output_buffer, size_t num_channels,
+ size_t num_frames) {
+ return GetBufferTemplated<int16*>(output_buffer, num_channels, num_frames);
+}
+
+size_t BufferUnpartitioner::GetBuffer(float* output_buffer, size_t num_channels,
+ size_t num_frames) {
+ return GetBufferTemplated<float*>(output_buffer, num_channels, num_frames);
+}
+
+size_t BufferUnpartitioner::GetBuffer(int16** output_buffer,
+ size_t num_channels, size_t num_frames) {
+ return GetBufferTemplated<int16**>(output_buffer, num_channels, num_frames);
+}
+
+size_t BufferUnpartitioner::GetBuffer(float** output_buffer,
+ size_t num_channels, size_t num_frames) {
+ return GetBufferTemplated<float**>(output_buffer, num_channels, num_frames);
+}
+
+size_t BufferUnpartitioner::GetNumBufferedFrames() const {
+ return current_buffer_read_offset_frames_;
+}
+
+size_t BufferUnpartitioner::GetNumFramesAvailableInBuffer() const {
+ if (current_input_buffer_ == nullptr) {
+ return 0;
+ }
+ DCHECK_GE(current_input_buffer_->num_frames(),
+ current_buffer_read_offset_frames_);
+ return current_input_buffer_->num_frames() -
+ current_buffer_read_offset_frames_;
+}
+
+void BufferUnpartitioner::Clear() {
+ current_input_buffer_ = nullptr;
+ current_buffer_read_offset_frames_ = 0;
+}
+
+template <typename BufferType>
+size_t BufferUnpartitioner::GetBufferTemplated(BufferType buffer,
+ size_t num_channels,
+ size_t num_frames) {
+ DCHECK_EQ(num_channels, num_channels_);
+
+ size_t num_copied_frames = 0;
+ while (num_copied_frames < num_frames) {
+ if (current_input_buffer_ == nullptr) {
+ current_input_buffer_ = buffer_callback_();
+ if (current_input_buffer_ == nullptr) {
+ // No more input |AudioBuffer|s are available.
+ return num_copied_frames;
+ }
+ DCHECK_EQ(frames_per_buffer_, current_input_buffer_->num_frames());
+ current_buffer_read_offset_frames_ = 0;
+ }
+ DCHECK_GE(frames_per_buffer_, current_buffer_read_offset_frames_);
+ const size_t remaining_frames_in_input_buffer =
+ num_frames - num_copied_frames;
+ DCHECK_GE(current_input_buffer_->num_frames(),
+ current_buffer_read_offset_frames_);
+ const size_t num_frames_to_process =
+ std::min(current_input_buffer_->num_frames() -
+ current_buffer_read_offset_frames_,
+ remaining_frames_in_input_buffer);
+
+ FillExternalBufferWithOffset(
+ *current_input_buffer_, current_buffer_read_offset_frames_, buffer,
+ num_frames, num_channels, num_copied_frames, num_frames_to_process);
+
+ num_copied_frames += num_frames_to_process;
+
+ current_buffer_read_offset_frames_ += num_frames_to_process;
+ if (current_buffer_read_offset_frames_ ==
+ current_input_buffer_->num_frames()) {
+ current_input_buffer_ = nullptr;
+ }
+ }
+ return num_copied_frames;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner.h b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner.h
new file mode 100644
index 000000000..51a5793d3
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner.h
@@ -0,0 +1,135 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_BUFFER_UNPARTITIONER_H_
+#define RESONANCE_AUDIO_UTILS_BUFFER_UNPARTITIONER_H_
+
+#include <functional>
+#include <memory>
+
+#include "base/audio_buffer.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+// Unpackages |AudioBuffer| into output buffers of arbitrary sizes.
+class BufferUnpartitioner {
+ public:
+ // Callback to obtain input |AudioBuffer|s. Returns a nullptr if no buffers
+ // are available.
+ typedef std::function<const AudioBuffer*()> GetBufferCallback;
+
+ // Constructor.
+ //
+ // @param num_channels Number of audio channels in input and output buffers.
+ // @param frames_per_buffer Number of frames per input buffer.
+ // @param buffer_callback Callback to receive output |AudioBuffer|s.
+ BufferUnpartitioner(size_t num_channels, size_t frames_per_buffer,
+ GetBufferCallback buffer_callback);
+
+ // Returns the number of input buffers required for a given number of output
+ // frames and based on the current fill state of the internal |temp_buffer_|.
+ //
+ // @param num_output_frames Number of output frames.
+ // @return Number of required input |AudioBuffer|s.
+ size_t GetNumBuffersRequestedForNumInputFrames(
+ size_t num_output_frames) const;
+
+ // Returns the number of buffered frames in internal |temp_buffer_|.
+ size_t GetNumBufferedFrames() const;
+
+ // Requests an interleaved int16 output buffer. This method triggers
+ // |GetBufferCallback|.
+ //
+ // @param output_buffer Interleaved output buffer to write to.
+ // @param num_channels Number of channels in output buffer.
+ // @param num_frames Number of frames in output buffer.
+ // @return Number of frames actually written.
+ size_t GetBuffer(int16* output_buffer, size_t num_channels,
+ size_t num_frames);
+
+ // Requests an interleaved float output buffer. This method triggers
+ // |GetBufferCallback|.
+ //
+ // @param output_buffer Interleaved output buffer to write to.
+ // @param num_channels Number of channels in output buffer.
+ // @param num_frames Number of frames in output buffer.
+ // @return Number of frames actually written.
+ size_t GetBuffer(float* output_buffer, size_t num_channels,
+ size_t num_frames);
+
+ // Requests a planar int16 output buffer. This method triggers
+ // |GetBufferCallback|.
+ //
+ // @param output_buffer Planar output buffer to write to.
+ // @param num_channels Number of channels in output buffer.
+ // @param num_frames Number of frames in output buffer.
+ // @return Number of frames actually written.
+ size_t GetBuffer(int16** output_buffer, size_t num_channels,
+ size_t num_frames);
+
+ // Requests a planar float output buffer. This method triggers
+ // |GetBufferCallback|.
+ //
+ // @param output_buffer Planar output buffer to write to.
+ // @param num_channels Number of channels in output buffer.
+ // @param num_frames Number of frames in output buffer.
+ // @return Number of frames actually written.
+ size_t GetBuffer(float** output_buffer, size_t num_channels,
+ size_t num_frames);
+
+ // Clears internal temporary buffer that holds remaining audio frames.
+ void Clear();
+
+ private:
+ // Returns the number of frames that are buffered in |current_input_buffer_|.
+ //
+ // @return Number of frames in |current_input_buffer_|. If
+ // |current_input_buffer_| is undefined, it returns 0.
+ size_t GetNumFramesAvailableInBuffer() const;
+
+ // Writes output buffer into target buffer. Supported buffer types are planar
+ // and interleaved floating point abd interleaved int16 output. This method
+ // triggers |GetBufferCallback|.
+ //
+ // @tparam BufferType Output buffer type.
+ // @param buffer Output buffer to write to.
+ // @param num_channels Number of channels in output buffer.
+ // @param num_frames Number of frames in output buffer.
+ // @return Number of frames actually written.
+ template <typename BufferType>
+ size_t GetBufferTemplated(BufferType buffer, size_t num_channels,
+ size_t num_frames);
+
+ // Number of channels in output buffers.
+ const size_t num_channels_;
+
+ // Number of frames per buffer in output buffers.
+ const size_t frames_per_buffer_;
+
+ // Callback to request input |AudioBuffer|s.
+ const GetBufferCallback buffer_callback_;
+
+ // Temporary buffer containing remaining audio frames.
+ const AudioBuffer* current_input_buffer_; // Not owned.
+
+ // Current read position in |current_input_buffer_|.
+ size_t current_buffer_read_offset_frames_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_BUFFER_UNPARTITIONER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner_test.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner_test.cc
new file mode 100644
index 000000000..48f5701fa
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/buffer_unpartitioner_test.cc
@@ -0,0 +1,294 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/buffer_unpartitioner.h"
+
+#include <memory>
+#include <numeric>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+#include "utils/planar_interleaved_conversion.h"
+#include "utils/sample_type_conversion.h"
+#include "utils/test_util.h"
+
+namespace vraudio {
+
+// Number of channels in test audio buffers.
+const size_t kNumChannels = vraudio::kNumStereoChannels;
+
+// Number of frames per test audio buffer.
+const size_t kNumFramesPerBuffer = 64;
+
+using vraudio::AudioBuffer;
+
+class BufferUnpartitionerTest : public ::testing::Test {
+ public:
+ // Generates a vector of int16 values with arbitrary data (vec[i] = i).
+ std::vector<int16> GenerateTestData(size_t num_channels, size_t num_frames) {
+ std::vector<int16> test_data(num_channels * num_frames);
+ std::iota(std::begin(test_data), std::end(test_data), 0);
+ return test_data;
+ }
+
+ // Generates an AudioBuffer from a segment of an interleaved std::vector.
+ AudioBuffer GetAudioBufferFromTestData(const std::vector<int16>& test_data,
+ size_t num_channels,
+ size_t num_frame_offset,
+ size_t num_audio_buffer_frames) {
+ const size_t num_input_frames = test_data.size() / num_channels;
+ AudioBuffer test_audio_buffer(num_channels, num_audio_buffer_frames);
+ FillAudioBufferWithOffset(&test_data[0], num_input_frames, num_channels,
+ num_frame_offset, 0 /* output_frame_offset */,
+ num_audio_buffer_frames, &test_audio_buffer);
+ return test_audio_buffer;
+ }
+
+ protected:
+ BufferUnpartitionerTest() {}
+ ~BufferUnpartitionerTest() override {}
+
+ const AudioBuffer* PassNextAudioBufferToBufferUnpartitioner(
+ size_t num_input_buffer_size_frames) {
+ input_audio_buffer_ = GetAudioBufferFromTestData(
+ input_audio_vector_, kNumChannels,
+ num_input_buffer_size_frames * num_callback_calls_,
+ num_input_buffer_size_frames);
+ ++num_callback_calls_;
+ return &input_audio_buffer_;
+ }
+
+ void InitBufferUnpartitioner(size_t num_total_frames_to_test,
+ size_t num_input_buffer_size_frames) {
+ input_audio_vector_ =
+ GenerateTestData(kNumChannels, num_total_frames_to_test);
+
+ num_callback_calls_ = 0;
+ unpartitioner_.reset(new BufferUnpartitioner(
+ kNumChannels, num_input_buffer_size_frames,
+ std::bind(
+ &BufferUnpartitionerTest::PassNextAudioBufferToBufferUnpartitioner,
+ this, num_input_buffer_size_frames)));
+ }
+
+ // Returns the number of triggered callback calls.
+ template <typename T>
+ size_t TestInterleavedBufferOutputTest(size_t num_input_buffer_size_frames,
+ size_t num_output_buffer_size_frames,
+ size_t num_total_frames_to_test,
+ float buffer_epsilon) {
+ InitBufferUnpartitioner(num_total_frames_to_test,
+ num_input_buffer_size_frames);
+
+ std::vector<T> output_vector(input_audio_vector_.size(), static_cast<T>(0));
+ for (size_t b = 0;
+ b < num_total_frames_to_test / num_output_buffer_size_frames; ++b) {
+ EXPECT_EQ(
+ num_output_buffer_size_frames,
+ unpartitioner_->GetBuffer(
+ &output_vector[b * num_output_buffer_size_frames * kNumChannels],
+ kNumChannels, num_output_buffer_size_frames));
+ }
+
+ AudioBuffer input(kNumChannels, num_total_frames_to_test);
+ FillAudioBuffer(input_audio_vector_, kNumChannels, &input);
+
+ AudioBuffer output(kNumChannels, num_total_frames_to_test);
+ FillAudioBuffer(output_vector, kNumChannels, &output);
+
+ for (size_t channel = 0; channel < kNumChannels; ++channel) {
+ EXPECT_TRUE(
+ CompareAudioBuffers(input[channel], output[channel], buffer_epsilon));
+ }
+
+ EXPECT_EQ(unpartitioner_->GetNumBuffersRequestedForNumInputFrames(
+ num_total_frames_to_test),
+ num_callback_calls_);
+ return num_callback_calls_;
+ }
+
+ // Returns the number of triggered callback calls.
+ template <typename T>
+ size_t TestPlanarBufferOutputTest(size_t input_buffer_size_frames,
+ size_t num_output_buffer_size_frames,
+ size_t num_total_frames_to_test,
+ float buffer_epsilon) {
+ InitBufferUnpartitioner(num_total_frames_to_test, input_buffer_size_frames);
+
+ std::vector<std::vector<T>> planar_output_vector(
+ kNumChannels,
+ std::vector<T>(num_total_frames_to_test, static_cast<T>(0)));
+ std::vector<T*> planar_output_vector_ptrs(kNumChannels);
+ for (size_t channel = 0; channel < kNumChannels; ++channel) {
+ planar_output_vector_ptrs[channel] = &planar_output_vector[channel][0];
+ }
+
+ const size_t num_total_buffers =
+ num_total_frames_to_test / num_output_buffer_size_frames;
+ for (size_t buffer = 0; buffer < num_total_buffers; ++buffer) {
+ EXPECT_EQ(num_output_buffer_size_frames,
+ unpartitioner_->GetBuffer(planar_output_vector_ptrs.data(),
+ kNumChannels,
+ num_output_buffer_size_frames));
+ for (T*& planar_output_vector_ptr : planar_output_vector_ptrs) {
+ planar_output_vector_ptr += num_output_buffer_size_frames;
+ }
+ }
+ AudioBuffer input(kNumChannels, num_total_frames_to_test);
+ FillAudioBuffer(input_audio_vector_, kNumChannels, &input);
+
+ AudioBuffer output(kNumChannels, num_total_frames_to_test);
+ for (size_t channel = 0; channel < kNumChannels; ++channel) {
+ ConvertPlanarSamples(num_total_frames_to_test,
+ &planar_output_vector[channel][0],
+ &output[channel][0]);
+ }
+
+ for (size_t channel = 0; channel < kNumChannels; ++channel) {
+ EXPECT_TRUE(
+ CompareAudioBuffers(input[channel], output[channel], buffer_epsilon));
+ }
+
+ EXPECT_EQ(unpartitioner_->GetNumBuffersRequestedForNumInputFrames(
+ num_total_frames_to_test),
+ num_callback_calls_);
+ return num_callback_calls_;
+ }
+
+ size_t num_callback_calls_;
+ AudioBuffer input_audio_buffer_;
+ std::vector<int16> input_audio_vector_;
+
+ std::unique_ptr<BufferUnpartitioner> unpartitioner_;
+};
+
+TEST_F(BufferUnpartitionerTest, TestInterleavedBufferOutputTest) {
+ const size_t kNumInputBuffers = 8;
+ EXPECT_EQ(kNumInputBuffers,
+ TestInterleavedBufferOutputTest<int16>(
+ kNumFramesPerBuffer / kNumInputBuffers /* input_buffer_size */,
+ kNumFramesPerBuffer /* output_buffer_size */,
+ kNumFramesPerBuffer /* num_frames_to_test */,
+ 1e-4f /* buffer_epsilon */));
+
+ EXPECT_EQ(kNumInputBuffers,
+ TestInterleavedBufferOutputTest<float>(
+ kNumFramesPerBuffer / kNumInputBuffers /* input_buffer_size */,
+ kNumFramesPerBuffer /* output_buffer_size */,
+ kNumFramesPerBuffer /* num_frames_to_test */,
+ 1e-6f /* buffer_epsilon */));
+
+ EXPECT_EQ(1U, // Single callback expected.
+ TestInterleavedBufferOutputTest<int16>(
+ kNumFramesPerBuffer /* input_buffer_size */,
+ kNumFramesPerBuffer / kNumInputBuffers /* output_buffer_size */,
+ kNumFramesPerBuffer /* num_frames_to_test */,
+ 1e-4f /* buffer_epsilon */));
+
+ EXPECT_EQ(1U, // Single callback expected.
+ TestInterleavedBufferOutputTest<float>(
+ kNumFramesPerBuffer /* input_buffer_size */,
+ kNumFramesPerBuffer / kNumInputBuffers /* output_buffer_size */,
+ kNumFramesPerBuffer /* num_frames_to_test */,
+ 1e-6f /* buffer_epsilon */));
+}
+
+TEST_F(BufferUnpartitionerTest, TestPlanarBufferOutputTest) {
+ const size_t kNumInputBuffers = 8;
+ EXPECT_EQ(kNumInputBuffers,
+ TestPlanarBufferOutputTest<int16>(
+ kNumFramesPerBuffer / kNumInputBuffers /* input_buffer_size */,
+ kNumFramesPerBuffer /* output_buffer_size */,
+ kNumFramesPerBuffer /* num_frames_to_test */,
+ 5e-3f /* buffer_epsilon */));
+
+ EXPECT_EQ(kNumInputBuffers,
+ TestPlanarBufferOutputTest<float>(
+ kNumFramesPerBuffer / kNumInputBuffers /* input_buffer_size */,
+ kNumFramesPerBuffer /* output_buffer_size */,
+ kNumFramesPerBuffer /* num_frames_to_test */,
+ 1e-6f /* buffer_epsilon */));
+
+ EXPECT_EQ(1U, // Single callback expected.
+ TestPlanarBufferOutputTest<int16>(
+ kNumFramesPerBuffer /* input_buffer_size */,
+ kNumFramesPerBuffer / kNumInputBuffers /* output_buffer_size */,
+ kNumFramesPerBuffer /* num_frames_to_test */,
+ 5e-3f /* buffer_epsilon */));
+
+ EXPECT_EQ(1U, // Single callback expected.
+ TestPlanarBufferOutputTest<float>(
+ kNumFramesPerBuffer /* input_buffer_size */,
+ kNumFramesPerBuffer / kNumInputBuffers /* output_buffer_size */,
+ kNumFramesPerBuffer /* num_frames_to_test */,
+ 1e-6f /* buffer_epsilon */));
+}
+
+TEST_F(BufferUnpartitionerTest, GetNumBuffersRequestedForNumInputFramesTest) {
+ AudioBuffer input_audio_buffer(kNumChannels, kNumFramesPerBuffer);
+ size_t num_callback_calls = 0;
+ const auto input_callback = [this, &input_audio_buffer,
+ &num_callback_calls]() -> AudioBuffer* {
+ ++num_callback_calls;
+ return &input_audio_buffer;
+ };
+ unpartitioner_.reset(new BufferUnpartitioner(
+ kNumChannels, kNumFramesPerBuffer, input_callback));
+
+ EXPECT_EQ(unpartitioner_->GetNumBuffersRequestedForNumInputFrames(0), 0U);
+ EXPECT_EQ(unpartitioner_->GetNumBuffersRequestedForNumInputFrames(1), 1U);
+ EXPECT_EQ(unpartitioner_->GetNumBuffersRequestedForNumInputFrames(
+ kNumFramesPerBuffer - 1),
+ 1U);
+ EXPECT_EQ(unpartitioner_->GetNumBuffersRequestedForNumInputFrames(
+ kNumFramesPerBuffer),
+ 1U);
+ EXPECT_EQ(unpartitioner_->GetNumBuffersRequestedForNumInputFrames(
+ kNumFramesPerBuffer + 1),
+ 2U);
+
+ const auto GetLargeRandomFrameNumber = [](size_t i) -> size_t {
+ return i * 7 * kNumFramesPerBuffer + 13 * i;
+ };
+
+ const size_t kMaximumInputSize =
+ kNumChannels * GetLargeRandomFrameNumber(kNumFramesPerBuffer * 2);
+ std::vector<float> input(kMaximumInputSize);
+
+ for (size_t i = 0; i < kNumFramesPerBuffer * 2; ++i) {
+ // Reset unpartitioner.
+ unpartitioner_->Clear();
+
+ // Simulate initial read of |i| frames.
+ EXPECT_EQ(i, unpartitioner_->GetBuffer(&input[0], kNumChannels, i));
+
+ const size_t large_random_frame_number = GetLargeRandomFrameNumber(i);
+ const size_t expected_num_buffer_requests =
+ unpartitioner_->GetNumBuffersRequestedForNumInputFrames(
+ large_random_frame_number);
+
+ num_callback_calls = 0;
+ EXPECT_EQ(large_random_frame_number,
+ unpartitioner_->GetBuffer(&input[0], kNumChannels,
+ large_random_frame_number));
+
+ EXPECT_EQ(expected_num_buffer_requests, num_callback_calls);
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue.cc
new file mode 100644
index 000000000..3edb75dc3
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue.cc
@@ -0,0 +1,156 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/lockless_task_queue.h"
+
+#include <limits>
+
+#include "base/logging.h"
+
+namespace vraudio {
+
+namespace {
+
+// Reserved index representing an invalid list index.
+constexpr uint64_t kInvalidIndex = std::numeric_limits<uint32_t>::max();
+
+// Maximum number of producers.
+constexpr uint64_t kMaxProducers = kInvalidIndex - 1;
+
+} // namespace
+
+LocklessTaskQueue::LocklessTaskQueue(size_t max_tasks) {
+ CHECK_GT(max_tasks, 0U);
+ CHECK_LE(max_tasks, kMaxProducers);
+ Init(max_tasks);
+}
+
+LocklessTaskQueue::~LocklessTaskQueue() { Clear(); }
+
+void LocklessTaskQueue::Post(Task&& task) {
+ const TagAndIndex free_node_idx = PopNodeFromList(&free_list_head_idx_);
+ if (GetIndex(free_node_idx) == kInvalidIndex) {
+ LOG(WARNING) << "Queue capacity reached - dropping task";
+ return;
+ }
+ nodes_[GetIndex(free_node_idx)].task = std::move(task);
+ PushNodeToList(&task_list_head_idx_, free_node_idx);
+}
+
+void LocklessTaskQueue::Execute() {
+ const TagAndIndex old_flag_with_invalid_index =
+ (GetFlag(task_list_head_idx_) << 32) + kInvalidIndex;
+ const TagAndIndex old_task_list_head_idx =
+ task_list_head_idx_.exchange(old_flag_with_invalid_index);
+ ProcessTaskList(old_task_list_head_idx, true /*execute_tasks*/);
+}
+
+void LocklessTaskQueue::Clear() {
+ const TagAndIndex old_flag_with_invalid_index =
+ (GetFlag(task_list_head_idx_) << 32) + kInvalidIndex;
+ const TagAndIndex old_task_list_head_idx =
+ task_list_head_idx_.exchange(old_flag_with_invalid_index);
+ ProcessTaskList(old_task_list_head_idx, false /*execute_tasks*/);
+}
+
+LocklessTaskQueue::TagAndIndex LocklessTaskQueue::IncreaseTag(
+ TagAndIndex tag_and_index) {
+ // The most significant 32 bits a reserved for tagging. Overflows are
+ // acceptable.
+ return tag_and_index + (static_cast<uint64_t>(1) << 32);
+}
+
+LocklessTaskQueue::TagAndIndex LocklessTaskQueue::GetIndex(
+ TagAndIndex tag_and_index) {
+ // The least significant 32 bits a reserved for the index.
+ return tag_and_index & std::numeric_limits<uint32_t>::max();
+}
+
+// Extracts the flag in the most significant 32 bits from a TagAndIndex;
+LocklessTaskQueue::TagAndIndex LocklessTaskQueue::GetFlag(
+ TagAndIndex tag_and_index) {
+ // The most significant 32 bits a reserved for the flag.
+ return tag_and_index >> 32;
+}
+
+void LocklessTaskQueue::PushNodeToList(
+ std::atomic<TagAndIndex>* list_head_idx_ptr, TagAndIndex node_idx) {
+ DCHECK(list_head_idx_ptr);
+ TagAndIndex list_head_idx;
+ do {
+ list_head_idx = list_head_idx_ptr->load();
+ nodes_[GetIndex(node_idx)].next = list_head_idx;
+ } while (!std::atomic_compare_exchange_strong(list_head_idx_ptr,
+ &list_head_idx, node_idx));
+}
+
+LocklessTaskQueue::TagAndIndex LocklessTaskQueue::PopNodeFromList(
+ std::atomic<TagAndIndex>* list_head_idx_ptr) {
+ DCHECK(list_head_idx_ptr);
+ TagAndIndex list_head_idx;
+ TagAndIndex list_head_next;
+ do {
+ list_head_idx = list_head_idx_ptr->load();
+ if (GetIndex(list_head_idx) == kInvalidIndex) {
+ // End of list reached.
+ return kInvalidIndex;
+ }
+ list_head_next = nodes_[GetIndex(list_head_idx)].next;
+ } while (!std::atomic_compare_exchange_strong(
+ list_head_idx_ptr, &list_head_idx, list_head_next));
+ return IncreaseTag(list_head_idx);
+}
+
+void LocklessTaskQueue::ProcessTaskList(TagAndIndex list_head_idx,
+ bool execute) {
+ TagAndIndex node_itr = list_head_idx;
+ while (GetIndex(node_itr) != kInvalidIndex) {
+ Node* node = &nodes_[GetIndex(node_itr)];
+ TagAndIndex next_node = node->next;
+ temp_tasks_.emplace_back(std::move(node->task));
+ node->task = nullptr;
+ PushNodeToList(&free_list_head_idx_, node_itr);
+ node_itr = next_node;
+ }
+
+ if (execute) {
+ // Execute tasks in reverse order.
+ for (std::vector<Task>::reverse_iterator task_itr = temp_tasks_.rbegin();
+ task_itr != temp_tasks_.rend(); ++task_itr) {
+ if (*task_itr != nullptr) {
+ (*task_itr)();
+ }
+ }
+ }
+ temp_tasks_.clear();
+}
+
+void LocklessTaskQueue::Init(size_t num_nodes) {
+ nodes_.resize(num_nodes);
+ temp_tasks_.reserve(num_nodes);
+
+ // Initialize free list.
+ free_list_head_idx_ = 0;
+ for (size_t i = 0; i < num_nodes - 1; ++i) {
+ nodes_[i].next = i + 1;
+ }
+ nodes_[num_nodes - 1].next = kInvalidIndex;
+
+ // Initialize task list.
+ task_list_head_idx_ = kInvalidIndex;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue.h b/src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue.h
new file mode 100644
index 000000000..e041c1fa4
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue.h
@@ -0,0 +1,124 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_LOCKLESS_TASK_QUEUE_H_
+#define RESONANCE_AUDIO_UTILS_LOCKLESS_TASK_QUEUE_H_
+
+#include <atomic>
+#include <cstddef>
+#include <cstdint>
+#include <functional>
+#include <vector>
+
+namespace vraudio {
+
+// Lock-less task queue which is thread safe for concurrent task producers and
+// single task consumers.
+class LocklessTaskQueue {
+ public:
+ // Alias for the task closure type.
+ typedef std::function<void()> Task;
+
+ // Constructor. Preallocates nodes on the task queue list.
+ //
+ // @param max_tasks Maximum number of tasks on the task queue.
+ explicit LocklessTaskQueue(size_t max_tasks);
+
+ ~LocklessTaskQueue();
+
+ // Posts a new task to task queue.
+ //
+ // @param task Task to process.
+ void Post(Task&& task);
+
+ // Executes all tasks on the task queue.
+ void Execute();
+
+ // Removes all tasks on the task queue.
+ void Clear();
+
+ private:
+ // To prevent ABA problems during thread synchronization, the most significant
+ // 32 bits of this index type are reserved for a continuously increasing
+ // tag counter. This prevents cases where nodes on the head appears to be
+ // untouched during the preparation of a push operation but instead they have
+ // been popped and pushed back during a context switch.
+ typedef uint64_t TagAndIndex;
+
+ // Node to model a single-linked list.
+ struct Node {
+ Node() = default;
+
+ // Dummy copy constructor to enable vector::resize allocation.
+ Node(const Node& node) : next() {}
+
+ // User task.
+ LocklessTaskQueue::Task task;
+
+ // Index to next node.
+ std::atomic<TagAndIndex> next;
+ };
+
+ // Returned a TagAndIndex with increased tag.
+ TagAndIndex IncreaseTag(TagAndIndex tag_and_index);
+
+ // Extracts the index in the least significant 32 bits from a TagAndIndex.
+ TagAndIndex GetIndex(TagAndIndex tag_and_index);
+
+ // Extracts the flag in the most significant 32 bits from a TagAndIndex.
+ TagAndIndex GetFlag(TagAndIndex tag_and_index);
+
+ // Pushes a node to the front of a list.
+ //
+ // @param list_head Index to list head.
+ // @param node Index of node to be pushed to the front of the list.
+ void PushNodeToList(std::atomic<TagAndIndex>* list_head, TagAndIndex node);
+
+ // Pops a node from the front of a list.
+ //
+ // @param list_head Index to list head.
+ // @return Index of front node, kInvalidIndex if list is empty.
+ TagAndIndex PopNodeFromList(std::atomic<TagAndIndex>* list_head);
+
+ // Iterates over list and moves all tasks to |temp_tasks_| to be executed in
+ // FIFO order. All processed nodes are pushed back to the free list.
+ //
+ // @param list_head Index of head node of list to be processed.
+ // @param execute If true, tasks on task list are executed.
+ void ProcessTaskList(TagAndIndex list_head, bool execute);
+
+ // Initializes task queue structures and preallocates task queue nodes.
+ //
+ // @param num_nodes Number of nodes to be initialized on free list.
+ void Init(size_t num_nodes);
+
+ // Index to head node of free list.
+ std::atomic<TagAndIndex> free_list_head_idx_;
+
+ // Index to head node of task list.
+ std::atomic<TagAndIndex> task_list_head_idx_;
+
+ // Holds preallocated nodes.
+ std::vector<Node> nodes_;
+
+ // Temporary vector to hold |Task|s in order to execute them in reverse order
+ // (FIFO, instead of LIFO).
+ std::vector<Task> temp_tasks_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_LOCKLESS_TASK_QUEUE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue_test.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue_test.cc
new file mode 100644
index 000000000..3168a92a1
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/lockless_task_queue_test.cc
@@ -0,0 +1,215 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/lockless_task_queue.h"
+
+#include <atomic>
+#include <condition_variable>
+#include <memory>
+#include <mutex>
+#include <thread>
+#include <vector>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+namespace {
+// Number of task producer threads.
+static const size_t kNumTaskProducers = 5;
+
+// Atomic thread counter used to trigger a simultaneous execution of all
+// threads.
+static std::atomic<size_t> s_thread_count(0);
+
+// Waits until all threads are initialized.
+static void WaitForProducerThreads() {
+ static std::mutex mutex;
+ static std::condition_variable cond_var;
+ std::unique_lock<std::mutex> lock(mutex);
+
+ if (++s_thread_count < kNumTaskProducers) {
+ cond_var.wait(lock);
+ } else {
+ cond_var.notify_all();
+ }
+}
+
+static void IncVectorAtIndex(std::vector<size_t>* work_vector_ptr,
+ size_t index) {
+ ++(*work_vector_ptr)[index];
+}
+
+class TaskProducer {
+ public:
+ TaskProducer(LocklessTaskQueue* queue, std::vector<size_t>* work_vector_ptr,
+ int delay_ms)
+ : producer_thread_(new std::thread(std::bind(
+ &TaskProducer::Produce, this, queue, work_vector_ptr, delay_ms))) {
+ }
+
+ TaskProducer(TaskProducer&& task)
+ : producer_thread_(std::move(task.producer_thread_)) {}
+
+ void Join() {
+ if (producer_thread_->joinable()) {
+ producer_thread_->join();
+ }
+ }
+
+ private:
+ void Produce(LocklessTaskQueue* queue, std::vector<size_t>* work_vector_ptr,
+ int delay_ms) {
+ WaitForProducerThreads();
+
+ for (size_t i = 0; i < work_vector_ptr->size(); ++i) {
+ queue->Post(std::bind(IncVectorAtIndex, work_vector_ptr, i));
+ if (delay_ms > 0) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(delay_ms));
+ }
+ }
+ }
+ std::unique_ptr<std::thread> producer_thread_;
+};
+
+} // namespace
+
+class LocklessTaskQueueTest : public ::testing::Test {
+ protected:
+ // Virtual methods from ::testing::Test
+ ~LocklessTaskQueueTest() override {}
+ void SetUp() override {}
+ void TearDown() override {}
+
+ // Helper method to initialize and run the concurrency test with multiple
+ // task producers and a single task executor.
+ void ConcurrentThreadsMultipleTaskProducerSingleTaskExecutorTest(
+ int producer_delay_ms) {
+ s_thread_count = 0;
+ const size_t kTasksPerProducer = 50;
+ work_vector_.resize(kNumTaskProducers);
+ std::fill(work_vector_.begin(), work_vector_.end(), 0);
+
+ LocklessTaskQueue task_queue(kNumTaskProducers * kTasksPerProducer);
+
+ std::vector<TaskProducer> task_producer_tasks;
+ for (size_t i = 0; i < kNumTaskProducers; ++i) {
+ task_producer_tasks.emplace_back(&task_queue, &work_vector_,
+ producer_delay_ms);
+ }
+ WaitForProducerThreads();
+ task_queue.Execute();
+
+ for (auto& producer : task_producer_tasks) {
+ producer.Join();
+ }
+ task_queue.Execute();
+
+ for (size_t worker_count : work_vector_) {
+ EXPECT_EQ(worker_count, kNumTaskProducers);
+ }
+ }
+
+ std::vector<size_t> work_vector_;
+};
+
+TEST_F(LocklessTaskQueueTest, MaxTasks) {
+ LocklessTaskQueue task_queue(1);
+
+ work_vector_.resize(1, 0);
+
+ task_queue.Execute();
+
+ task_queue.Post(std::bind(IncVectorAtIndex, &work_vector_, 0));
+ // Second task should be dropped since queue is initialized with size 1.
+ task_queue.Post(std::bind(IncVectorAtIndex, &work_vector_, 0));
+ task_queue.Execute();
+
+ EXPECT_EQ(work_vector_[0], 1U);
+
+ task_queue.Post(std::bind(IncVectorAtIndex, &work_vector_, 0));
+ // Second task should be dropped since queue is initialized with size 1.
+ task_queue.Post(std::bind(IncVectorAtIndex, &work_vector_, 0));
+ task_queue.Execute();
+
+ EXPECT_EQ(work_vector_[0], 2U);
+}
+
+TEST_F(LocklessTaskQueueTest, Clear) {
+ LocklessTaskQueue task_queue(1);
+
+ work_vector_.resize(1, 0);
+
+ task_queue.Post(std::bind(IncVectorAtIndex, &work_vector_, 0));
+ task_queue.Clear();
+ task_queue.Execute();
+
+ EXPECT_EQ(work_vector_[0], 0U);
+}
+
+TEST_F(LocklessTaskQueueTest, SynchronousTaskExecution) {
+ const size_t kNumRounds = 5;
+ const size_t kNumTasksPerRound = 20;
+
+ LocklessTaskQueue task_queue(kNumTasksPerRound);
+
+ work_vector_.resize(kNumTasksPerRound, 0);
+
+ for (size_t r = 0; r < kNumRounds; ++r) {
+ for (size_t t = 0; t < kNumTasksPerRound; ++t) {
+ task_queue.Post(std::bind(IncVectorAtIndex, &work_vector_, t));
+ }
+ task_queue.Execute();
+ }
+
+ for (size_t t = 0; t < kNumTasksPerRound; ++t) {
+ EXPECT_EQ(work_vector_[t], kNumRounds);
+ }
+}
+
+TEST_F(LocklessTaskQueueTest, SynchronousInOrderTaskExecution) {
+ const size_t kNumTasksPerRound = 20;
+
+ LocklessTaskQueue task_queue(kNumTasksPerRound);
+
+ work_vector_.resize(kNumTasksPerRound, 0);
+ work_vector_[0] = 1;
+
+ const auto accumulate_from_lower_index_task = [this](size_t index) {
+ work_vector_[index] += work_vector_[index - 1];
+ };
+ for (size_t t = 1; t < kNumTasksPerRound; ++t) {
+ task_queue.Post(std::bind(accumulate_from_lower_index_task, t));
+ }
+ task_queue.Execute();
+
+ for (size_t t = 0; t < kNumTasksPerRound; ++t) {
+ EXPECT_EQ(work_vector_[t], 1U);
+ }
+}
+
+// Tests concurrency of multiple producers and a single executor.
+TEST_F(LocklessTaskQueueTest,
+ ConcurrentThreadsMultipleFastProducersSingleExecutor) {
+ // Test fast producers and a fast consumer.
+ ConcurrentThreadsMultipleTaskProducerSingleTaskExecutorTest(
+ 0 /* producer delay in ms */);
+ ConcurrentThreadsMultipleTaskProducerSingleTaskExecutorTest(
+ 1 /* producer delay in ms */);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/ogg_vorbis_recorder.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/ogg_vorbis_recorder.cc
new file mode 100644
index 000000000..26596abab
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/ogg_vorbis_recorder.cc
@@ -0,0 +1,107 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/ogg_vorbis_recorder.h"
+
+#include "base/logging.h"
+#include "utils/planar_interleaved_conversion.h"
+
+namespace vraudio {
+
+OggVorbisRecorder::OggVorbisRecorder(int sample_rate_hz, size_t num_channels,
+ size_t num_frames, size_t max_num_buffers)
+ : sample_rate_hz_(sample_rate_hz),
+ num_channels_(num_channels),
+ num_frames_(num_frames),
+ max_num_buffers_(max_num_buffers),
+ temp_data_channel_ptrs_(num_channels),
+ crossfader_(num_frames_),
+ crossfade_buffer_(num_channels_, num_frames_) {
+ DCHECK_GT(sample_rate_hz_, 0);
+ DCHECK_NE(num_channels_, 0U);
+ DCHECK_NE(num_frames_, 0U);
+ CHECK_NE(max_num_buffers_, 0U);
+}
+
+void OggVorbisRecorder::AddInput(std::unique_ptr<AudioBuffer> input_buffer) {
+ DCHECK(input_buffer);
+ DCHECK_EQ(input_buffer->num_channels(), num_channels_);
+ DCHECK_EQ(input_buffer->num_frames(), num_frames_);
+
+ if (data_.size() == max_num_buffers_) {
+ LOG(WARNING) << "Maximum input buffer limit reached, overwriting data";
+ data_.erase(data_.begin());
+ }
+ data_.push_back(std::move(input_buffer));
+}
+
+void OggVorbisRecorder::Reset() { data_.clear(); }
+
+bool OggVorbisRecorder::WriteToFile(const std::string& file_path, float quality,
+ bool seamless) {
+ if (data_.empty()) {
+ LOG(WARNING) << "No recorded data";
+ return false;
+ }
+
+ if (seamless) {
+ MakeSeamless();
+ }
+
+ if (!encoder_.InitializeForFile(
+ file_path, num_channels_, sample_rate_hz_,
+ VorbisStreamEncoder::EncodingMode::kVariableBitRate, 0 /* bitrate */,
+ quality)) {
+ LOG(WARNING) << "Cannot initialize file to record: " << file_path;
+ Reset();
+ return false;
+ }
+ for (const auto& audio_buffer : data_) {
+ GetRawChannelDataPointersFromAudioBuffer(*audio_buffer,
+ &temp_data_channel_ptrs_);
+ if (!encoder_.AddPlanarBuffer(temp_data_channel_ptrs_.data(), num_channels_,
+ num_frames_)) {
+ LOG(WARNING) << "Failed to write buffer into file: " << file_path;
+ Reset();
+ return false;
+ }
+ }
+ if (!encoder_.FlushAndClose()) {
+ LOG(WARNING) << "Failed to safely close file: " << file_path;
+ Reset();
+ return false;
+ }
+
+ Reset();
+ return true;
+}
+
+void OggVorbisRecorder::MakeSeamless() {
+ if (data_.size() == 1) {
+ LOG(WARNING) << "Not enough data to make seamless file";
+ return;
+ }
+ // Apply crossfade between the beginning and the end buffers of |data_|.
+ auto* front_buffer = data_.front().get();
+ const auto& back_buffer = *data_.back();
+ crossfader_.ApplyLinearCrossfade(*front_buffer, back_buffer,
+ &crossfade_buffer_);
+
+ *front_buffer = crossfade_buffer_;
+ data_.pop_back();
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/ogg_vorbis_recorder.h b/src/3rdparty/resonance-audio/resonance_audio/utils/ogg_vorbis_recorder.h
new file mode 100644
index 000000000..2e47947ff
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/ogg_vorbis_recorder.h
@@ -0,0 +1,94 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_OGG_VORBIS_RECORDER_H_
+#define RESONANCE_AUDIO_UTILS_OGG_VORBIS_RECORDER_H_
+
+#include <memory>
+#include <vector>
+
+#include "base/audio_buffer.h"
+#include "utils/buffer_crossfader.h"
+#include "utils/vorbis_stream_encoder.h"
+
+namespace vraudio {
+
+// Class that takes audio buffers as input and writes them into a compressed OGG
+// Vorbis file.
+
+class OggVorbisRecorder {
+ public:
+ // Constructs a new recorder with given sampling rate and number of channels.
+
+ OggVorbisRecorder(int sample_rate_hz, size_t num_channels, size_t num_frames,
+ size_t max_num_buffers);
+
+ // Adds next input buffer at the end of the record data.
+ //
+ // @param input_buffer Next audio buffer to be recorded.
+ void AddInput(std::unique_ptr<AudioBuffer> input_buffer);
+
+ // Flushes the record data.
+ void Reset();
+
+ // Writes the current record data into a file and resets the recorder.
+ //
+ // @param file_path Full path of the file to be recorded into.
+ // @param quality Compression quality of the record. The usable range is from
+ // -0.1 (lowest quality, smallest file) to 1.0 (highest quality, largest
+ // file).
+ // @param seamless True to record seamlessly for looping. Note that this
+ // option will truncate the record length by |num_frames_| samples.
+ // @return False if fails to successfully write data into |file_path|.
+ bool WriteToFile(const std::string& file_path, float quality, bool seamless);
+
+ private:
+ // Helper method to make record data seamless.
+ void MakeSeamless();
+
+ // Record sampling rate.
+ const int sample_rate_hz_;
+
+ // Record number of channels.
+ const size_t num_channels_;
+
+ // Record number of frames per buffer.
+ const size_t num_frames_;
+
+ // Maximum number of input buffers allowed to record.
+ const size_t max_num_buffers_;
+
+ // Record data that is stored as a list of planar audio buffers.
+ std::vector<std::unique_ptr<AudioBuffer>> data_;
+
+ // Temporary vector to extract pointers to planar channels in an
+ // |AudioBuffer|.
+ std::vector<const float*> temp_data_channel_ptrs_;
+
+ // Buffer crossfader that is used to create seamless loop.
+ BufferCrossfader crossfader_;
+
+ // Temporary buffer to store the crossfaded output.
+
+ AudioBuffer crossfade_buffer_;
+
+ // OGG Vorbis encoder to write record data into file in compressed format.
+ VorbisStreamEncoder encoder_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_OGG_VORBIS_RECORDER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion.cc
new file mode 100644
index 000000000..be50b23f7
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion.cc
@@ -0,0 +1,505 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "utils/planar_interleaved_conversion.h"
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/simd_utils.h"
+
+#include "utils/sample_type_conversion.h"
+
+namespace vraudio {
+
+namespace {
+
+template <typename InputType, typename OutputType>
+void ConvertInterleavedToPlanarTemplated(
+ InputType interleaved_buffer, size_t num_input_frames,
+ size_t num_input_channels, size_t input_offset_frames,
+ const std::vector<size_t>* channel_map, OutputType output_buffer,
+ size_t num_output_frames, size_t num_output_channels,
+ size_t output_offset_frames, size_t num_frames_to_copy) {
+ DCHECK_GE(num_input_frames, input_offset_frames);
+ const size_t max_num_input_frames = num_input_frames - input_offset_frames;
+ DCHECK_GE(num_output_frames, output_offset_frames);
+ const size_t max_num_output_frames = num_output_frames - output_offset_frames;
+ DCHECK_GE(max_num_input_frames, num_frames_to_copy);
+ DCHECK_GE(max_num_output_frames, num_frames_to_copy);
+
+ if (channel_map == nullptr) {
+ DCHECK_EQ(num_input_channels, num_output_channels);
+ } else {
+ DCHECK_GE(channel_map->size(), num_output_channels);
+ }
+
+ InputType interleaved_buffer_with_offset =
+ interleaved_buffer + input_offset_frames * num_input_channels;
+
+ if (num_input_channels == kNumStereoChannels &&
+ num_output_channels == kNumStereoChannels) {
+ if (channel_map == nullptr) {
+ DeinterleaveStereo(num_frames_to_copy, interleaved_buffer_with_offset,
+ &output_buffer[0][output_offset_frames],
+ &output_buffer[1][output_offset_frames]);
+ } else {
+ DCHECK_LT((*channel_map)[0], kNumStereoChannels);
+ DCHECK_LT((*channel_map)[1], kNumStereoChannels);
+ DeinterleaveStereo(
+ num_input_frames, interleaved_buffer_with_offset,
+ &output_buffer[(*channel_map)[0]][output_offset_frames],
+ &output_buffer[(*channel_map)[1]][output_offset_frames]);
+ }
+ } else {
+ for (size_t channel_idx = 0; channel_idx < num_output_channels;
+ ++channel_idx) {
+ const size_t input_channel =
+ channel_map != nullptr ? (*channel_map)[channel_idx] : channel_idx;
+ DCHECK_LT(input_channel, num_input_channels);
+ InputType input_ptr = &interleaved_buffer_with_offset[input_channel];
+ float* output_ptr = &output_buffer[channel_idx][output_offset_frames];
+ for (size_t frame = 0; frame < num_frames_to_copy; ++frame) {
+ ConvertSampleToFloatFormat(*input_ptr, output_ptr);
+ input_ptr += num_input_channels;
+ ++output_ptr;
+ }
+ }
+ }
+}
+
+template <typename PlanarInputType, typename PlanarOutputType>
+void ConvertPlanarToPlanarTemplated(
+ PlanarInputType input, size_t num_input_frames, size_t num_input_channels,
+ size_t input_offset_frames, const std::vector<size_t>* channel_map,
+ PlanarOutputType planar_output_ptrs, size_t num_output_frames,
+ size_t num_output_channels, size_t output_offset_frames,
+ size_t num_frames_convert_and_copy) {
+ DCHECK_GE(num_input_frames, input_offset_frames);
+ const size_t max_num_input_frames = num_input_frames - input_offset_frames;
+ DCHECK_GE(num_output_frames, output_offset_frames);
+ const size_t max_num_output_frames = num_output_frames - output_offset_frames;
+ DCHECK_GE(max_num_input_frames, num_frames_convert_and_copy);
+ DCHECK_GE(max_num_output_frames, num_frames_convert_and_copy);
+
+ if (channel_map == nullptr) {
+ DCHECK_EQ(num_input_channels, num_output_channels);
+ } else {
+ DCHECK_GE(channel_map->size(), num_output_channels);
+ }
+
+ for (size_t channel = 0; channel < num_output_channels; ++channel) {
+ const size_t input_channel =
+ channel_map != nullptr ? (*channel_map)[channel] : channel;
+ DCHECK_LT(input_channel, num_input_channels);
+ ConvertPlanarSamples(num_frames_convert_and_copy,
+ &input[input_channel][input_offset_frames],
+ &planar_output_ptrs[channel][output_offset_frames]);
+ }
+}
+
+template <typename PlanarInputType, typename InterleavedOutputType>
+void ConvertPlanarToInterleavedTemplated(
+ PlanarInputType input, size_t num_input_frames, size_t num_input_channels,
+ size_t input_offset_frames, InterleavedOutputType interleaved_output_ptr,
+ size_t num_output_frames, size_t num_output_channels,
+ size_t output_offset_frames, size_t num_frames_convert_and_copy) {
+ DCHECK(interleaved_output_ptr);
+ DCHECK_GE(num_input_frames, input_offset_frames);
+ const size_t max_num_input_frames = num_input_frames - input_offset_frames;
+ DCHECK_GE(num_output_frames, output_offset_frames);
+ const size_t max_num_output_frames = num_output_frames - output_offset_frames;
+ DCHECK_GE(max_num_input_frames, num_frames_convert_and_copy);
+ DCHECK_GE(max_num_output_frames, num_frames_convert_and_copy);
+ DCHECK_EQ(num_input_channels, num_output_channels);
+
+ InterleavedOutputType interleaved_output_ptr_with_offset =
+ interleaved_output_ptr + output_offset_frames * num_output_channels;
+
+ if (num_input_channels == kNumStereoChannels &&
+ num_output_channels == kNumStereoChannels) {
+ const float* left_ptr = &input[0][input_offset_frames];
+ const float* right_ptr = &input[1][input_offset_frames];
+ InterleaveStereo(num_frames_convert_and_copy, left_ptr, right_ptr,
+ interleaved_output_ptr_with_offset);
+ } else {
+ for (size_t channel = 0; channel < num_output_channels; ++channel) {
+ const float* input_channel_ptr = &input[channel][input_offset_frames];
+ size_t interleaved_index = channel;
+ for (size_t frame = 0; frame < num_frames_convert_and_copy; ++frame) {
+ ConvertSampleFromFloatFormat(
+ input_channel_ptr[frame],
+ &interleaved_output_ptr_with_offset[interleaved_index]);
+ interleaved_index += num_output_channels;
+ }
+ }
+ }
+}
+
+} // namespace
+
+void PlanarFromInterleaved(const float* interleaved_buffer,
+ size_t num_input_frames, size_t num_input_channels,
+ const std::vector<float*>& planar_buffer_ptr,
+ size_t num_output_frames) {
+ DCHECK(interleaved_buffer);
+ DCHECK_GT(planar_buffer_ptr.size(), 0);
+
+ const size_t num_frames_to_copy =
+ std::min(num_input_frames, num_output_frames);
+ ConvertInterleavedToPlanarTemplated<const float*, float* const*>(
+ interleaved_buffer, num_input_frames, num_input_channels,
+ 0 /* input_offset_frames */, nullptr /* channel_map*/,
+ planar_buffer_ptr.data(), num_output_frames, planar_buffer_ptr.size(),
+ 0 /* output_offset_frames */, num_frames_to_copy);
+}
+
+void PlanarFromInterleaved(const int16* interleaved_buffer,
+ size_t num_input_frames, size_t num_input_channels,
+ const std::vector<float*>& planar_buffer_ptr,
+ size_t num_output_frames) {
+ DCHECK(interleaved_buffer);
+ DCHECK_GT(planar_buffer_ptr.size(), 0);
+
+ const size_t num_frames_to_copy =
+ std::min(num_input_frames, num_output_frames);
+ ConvertInterleavedToPlanarTemplated<const int16*, float* const*>(
+ interleaved_buffer, num_input_frames, num_input_channels,
+ 0 /* input_offset_frames */, nullptr /* channel_map*/,
+ planar_buffer_ptr.data(), num_output_frames, planar_buffer_ptr.size(),
+ 0 /* output_offset_frames */, num_frames_to_copy);
+}
+
+void FillAudioBuffer(const float* interleaved_buffer, size_t num_input_frames,
+ size_t num_input_channels, AudioBuffer* output) {
+ DCHECK(interleaved_buffer);
+ DCHECK(output);
+ const size_t num_frames_to_copy =
+ std::min(num_input_frames, output->num_frames());
+ ConvertInterleavedToPlanarTemplated<const float*, AudioBuffer&>(
+ interleaved_buffer, num_input_frames, num_input_channels,
+ 0 /* input_offset_frames */, nullptr /* channel_map*/, *output,
+ output->num_frames(), output->num_channels(),
+ 0 /* output_offset_frames */, num_frames_to_copy);
+}
+
+void FillAudioBuffer(const int16* interleaved_buffer, size_t num_input_frames,
+ size_t num_input_channels, AudioBuffer* output) {
+ DCHECK(interleaved_buffer);
+ DCHECK(output);
+ const size_t num_frames_to_copy =
+ std::min(num_input_frames, output->num_frames());
+
+ ConvertInterleavedToPlanarTemplated<const int16*, AudioBuffer&>(
+ interleaved_buffer, num_input_frames, num_input_channels,
+ 0 /* input_offset_frames */, nullptr /* channel_map*/, *output,
+ output->num_frames(), output->num_channels(),
+ 0 /* output_offset_frames */, num_frames_to_copy);
+}
+
+void FillAudioBuffer(const std::vector<float>& interleaved_buffer,
+ size_t num_input_channels, AudioBuffer* output) {
+ DCHECK(output);
+ DCHECK_EQ(interleaved_buffer.size() % num_input_channels, 0);
+ const size_t num_frames_to_copy = std::min(
+ interleaved_buffer.size() / num_input_channels, output->num_frames());
+ FillAudioBuffer(&interleaved_buffer[0], num_frames_to_copy,
+ num_input_channels, output);
+}
+
+void FillAudioBuffer(const std::vector<int16>& interleaved_buffer,
+ size_t num_input_channels, AudioBuffer* output) {
+ DCHECK(output);
+ DCHECK_EQ(interleaved_buffer.size() % num_input_channels, 0);
+ const size_t num_frames_to_copy = std::min(
+ interleaved_buffer.size() / num_input_channels, output->num_frames());
+ FillAudioBuffer(&interleaved_buffer[0], num_frames_to_copy,
+ num_input_channels, output);
+}
+
+void FillAudioBuffer(const float* const* planar_ptrs, size_t num_input_frames,
+ size_t num_input_channels, AudioBuffer* output) {
+ DCHECK(planar_ptrs);
+ DCHECK(output);
+ const size_t num_frames_to_copy =
+ std::min(num_input_frames, output->num_frames());
+ ConvertPlanarToPlanarTemplated<const float* const*, AudioBuffer&>(
+ planar_ptrs, num_input_frames, num_input_channels,
+ 0 /* input_offset_frames */, nullptr /* channel_map*/, *output,
+ output->num_frames(), output->num_channels(),
+ 0 /* output_offset_frames */, num_frames_to_copy);
+}
+
+void FillAudioBuffer(const int16* const* planar_ptrs, size_t num_input_frames,
+ size_t num_input_channels, AudioBuffer* output) {
+ DCHECK(planar_ptrs);
+ DCHECK(output);
+ const size_t num_frames_to_copy =
+ std::min(num_input_frames, output->num_frames());
+ ConvertPlanarToPlanarTemplated<const int16* const*, AudioBuffer&>(
+ planar_ptrs, num_input_frames, num_input_channels,
+ 0 /* input_offset_frames */, nullptr /* channel_map*/, *output,
+ output->num_frames(), output->num_channels(),
+ 0 /* output_offset_frames */, num_frames_to_copy);
+}
+
+void FillAudioBufferWithOffset(const float* interleaved_buffer,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ size_t input_frame_offset,
+ size_t output_frame_offset,
+ size_t num_frames_to_copy, AudioBuffer* output) {
+ DCHECK(interleaved_buffer);
+ DCHECK(output);
+ ConvertInterleavedToPlanarTemplated<const float*, AudioBuffer&>(
+ interleaved_buffer, num_input_frames, num_input_channels,
+ input_frame_offset, nullptr /* channel_map*/, *output,
+ output->num_frames(), output->num_channels(), output_frame_offset,
+ num_frames_to_copy);
+}
+
+void FillAudioBufferWithOffset(const int16* interleaved_buffer,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ size_t input_frame_offset,
+ size_t output_frame_offset,
+ size_t num_frames_to_copy, AudioBuffer* output) {
+ DCHECK(interleaved_buffer);
+ DCHECK(output);
+ ConvertInterleavedToPlanarTemplated<const int16*, AudioBuffer&>(
+ interleaved_buffer, num_input_frames, num_input_channels,
+ input_frame_offset, nullptr /* channel_map*/, *output,
+ output->num_frames(), output->num_channels(), output_frame_offset,
+ num_frames_to_copy);
+}
+
+void FillAudioBufferWithOffset(const float* const* planar_ptrs,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ size_t input_frame_offset,
+ size_t output_frame_offset,
+ size_t num_frames_to_copy, AudioBuffer* output) {
+ DCHECK(planar_ptrs);
+ DCHECK(output);
+ ConvertPlanarToPlanarTemplated<const float* const*, AudioBuffer&>(
+ planar_ptrs, num_input_frames, num_input_channels, input_frame_offset,
+ nullptr /* channel_map*/, *output, output->num_frames(),
+ output->num_channels(), output_frame_offset, num_frames_to_copy);
+}
+
+void FillAudioBufferWithOffset(const int16* const* planar_ptrs,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ size_t input_frame_offset,
+ size_t output_frame_offset,
+ size_t num_frames_to_copy, AudioBuffer* output) {
+ DCHECK(planar_ptrs);
+ DCHECK(output);
+ ConvertPlanarToPlanarTemplated<const int16* const*, AudioBuffer&>(
+ planar_ptrs, num_input_frames, num_input_channels, input_frame_offset,
+ nullptr /* channel_map*/, *output, output->num_frames(),
+ output->num_channels(), output_frame_offset, num_frames_to_copy);
+}
+
+void FillAudioBufferWithChannelRemapping(const int16* interleaved_buffer,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ const std::vector<size_t>& channel_map,
+ AudioBuffer* output) {
+ DCHECK(interleaved_buffer);
+ DCHECK(output);
+ const size_t num_frames_to_copy =
+ std::min(num_input_frames, output->num_frames());
+ ConvertInterleavedToPlanarTemplated<const int16*, AudioBuffer&>(
+ interleaved_buffer, num_input_frames, num_input_channels,
+ 0 /*input_frame_offset*/, &channel_map, *output, output->num_frames(),
+ output->num_channels(), 0 /*output_frame_offset*/, num_frames_to_copy);
+}
+
+void FillAudioBufferWithChannelRemapping(const float* interleaved_buffer,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ const std::vector<size_t>& channel_map,
+ AudioBuffer* output) {
+ DCHECK(interleaved_buffer);
+ DCHECK(output);
+ const size_t num_frames_to_copy =
+ std::min(num_input_frames, output->num_frames());
+ ConvertInterleavedToPlanarTemplated<const float*, AudioBuffer&>(
+ interleaved_buffer, num_input_frames, num_input_channels,
+ 0 /*input_frame_offset*/, &channel_map, *output, output->num_frames(),
+ output->num_channels(), 0 /*output_frame_offset*/, num_frames_to_copy);
+}
+
+void FillAudioBufferWithChannelRemapping(const float* const* planar_ptrs,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ const std::vector<size_t>& channel_map,
+ AudioBuffer* output) {
+ DCHECK(planar_ptrs);
+ DCHECK(output);
+ const size_t num_frames_to_copy =
+ std::min(num_input_frames, output->num_frames());
+ ConvertPlanarToPlanarTemplated<const float* const*, AudioBuffer&>(
+ planar_ptrs, num_input_frames, num_input_channels,
+ 0 /*input_offset_frames*/, &channel_map, *output, output->num_frames(),
+ output->num_channels(), 0 /* output_offset_frames*/, num_frames_to_copy);
+}
+
+void FillAudioBufferWithChannelRemapping(const int16* const* planar_ptr,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ const std::vector<size_t>& channel_map,
+ AudioBuffer* output) {
+ DCHECK(planar_ptr);
+ DCHECK(output);
+ const size_t num_frames_to_copy =
+ std::min(num_input_frames, output->num_frames());
+ ConvertPlanarToPlanarTemplated<const int16* const*, AudioBuffer&>(
+ planar_ptr, num_input_frames, num_input_channels,
+ 0 /*input_offset_frames*/, &channel_map, *output, output->num_frames(),
+ output->num_channels(), 0 /* output_offset_frames*/, num_frames_to_copy);
+}
+
+void FillExternalBuffer(const AudioBuffer& input, std::vector<float>* output) {
+ DCHECK(output);
+ output->resize(input.num_frames() * input.num_channels());
+ FillExternalBuffer(input, output->data(), input.num_frames(),
+ input.num_channels());
+}
+
+void FillExternalBuffer(const AudioBuffer& input, std::vector<int16>* output) {
+ DCHECK(output);
+ output->resize(input.num_frames() * input.num_channels());
+ FillExternalBuffer(input, output->data(), input.num_frames(),
+ input.num_channels());
+}
+
+void FillExternalBuffer(const AudioBuffer& input,
+ int16* const* planar_output_ptrs,
+ size_t num_output_frames, size_t num_output_channels) {
+ ConvertPlanarToPlanarTemplated<const AudioBuffer&, int16* const*>(
+ input, input.num_frames(), input.num_channels(),
+ 0 /*input_offset_frames*/, nullptr /* channel_map*/, planar_output_ptrs,
+ num_output_frames, num_output_channels, 0 /* output_offset_frames*/,
+ num_output_frames);
+}
+
+void FillExternalBuffer(const AudioBuffer& input,
+ float* const* planar_output_ptrs,
+ size_t num_output_frames, size_t num_output_channels) {
+ ConvertPlanarToPlanarTemplated<const AudioBuffer&, float* const*>(
+ input, input.num_frames(), input.num_channels(),
+ 0 /*input_offset_frames*/, nullptr /* channel_map*/, planar_output_ptrs,
+ num_output_frames, num_output_channels, 0 /* output_offset_frames*/,
+ num_output_frames);
+}
+
+void FillExternalBuffer(const AudioBuffer& input,
+ int16* interleaved_output_buffer,
+ size_t num_output_frames, size_t num_output_channels) {
+ ConvertPlanarToInterleavedTemplated<const AudioBuffer&, int16*>(
+ input, input.num_frames(), input.num_channels(),
+ 0 /*input_offset_frames*/, interleaved_output_buffer, num_output_frames,
+ num_output_channels, 0 /* output_offset_frames*/, num_output_frames);
+}
+
+void FillExternalBuffer(const AudioBuffer& input,
+ float* interleaved_output_buffer,
+ size_t num_output_frames, size_t num_output_channels) {
+ ConvertPlanarToInterleavedTemplated<const AudioBuffer&, float*>(
+ input, input.num_frames(), input.num_channels(),
+ 0 /*input_offset_frames*/, interleaved_output_buffer, num_output_frames,
+ num_output_channels, 0 /* output_offset_frames*/, num_output_frames);
+}
+
+void FillExternalBufferWithOffset(const AudioBuffer& input,
+ size_t input_offset_frames,
+ int16* const* planar_output_ptrs,
+ size_t num_output_frames,
+ size_t num_output_channels,
+ size_t output_offset_frames,
+ size_t num_frames_convert_and_copy) {
+ ConvertPlanarToPlanarTemplated<const AudioBuffer&, int16* const*>(
+ input, input.num_frames(), input.num_channels(), input_offset_frames,
+ nullptr /* channel_map */, planar_output_ptrs, num_output_frames,
+ num_output_channels, output_offset_frames, num_frames_convert_and_copy);
+}
+
+void FillExternalBufferWithOffset(const AudioBuffer& input,
+ size_t input_offset_frames,
+ float* const* planar_output_ptrs,
+ size_t num_output_frames,
+ size_t num_output_channels,
+ size_t output_offset_frames,
+ size_t num_frames_convert_and_copy) {
+ ConvertPlanarToPlanarTemplated<const AudioBuffer&, float* const*>(
+ input, input.num_frames(), input.num_channels(), input_offset_frames,
+ nullptr /* channel_map */, planar_output_ptrs, num_output_frames,
+ num_output_channels, output_offset_frames, num_frames_convert_and_copy);
+}
+
+void FillExternalBufferWithOffset(const AudioBuffer& input,
+ size_t input_offset_frames,
+ int16* interleaved_output_buffer,
+ size_t num_output_frames,
+ size_t num_output_channels,
+ size_t output_offset_frames,
+ size_t num_frames_convert_and_copy) {
+ ConvertPlanarToInterleavedTemplated<const AudioBuffer&, int16*>(
+ input, input.num_frames(), input.num_channels(), input_offset_frames,
+ interleaved_output_buffer, num_output_frames, num_output_channels,
+ output_offset_frames, num_frames_convert_and_copy);
+}
+
+void FillExternalBufferWithOffset(const AudioBuffer& input,
+ size_t input_offset_frames,
+ float* interleaved_output_buffer,
+ size_t num_output_frames,
+ size_t num_output_channels,
+ size_t output_offset_frames,
+ size_t num_frames_convert_and_copy) {
+ ConvertPlanarToInterleavedTemplated<const AudioBuffer&, float*>(
+ input, input.num_frames(), input.num_channels(), input_offset_frames,
+ interleaved_output_buffer, num_output_frames, num_output_channels,
+ output_offset_frames, num_frames_convert_and_copy);
+}
+
+void GetRawChannelDataPointersFromAudioBuffer(
+ AudioBuffer* audio_buffer, std::vector<float*>* channel_ptr_vector) {
+ DCHECK(audio_buffer);
+ DCHECK(channel_ptr_vector);
+ DCHECK_EQ(audio_buffer->num_channels(), channel_ptr_vector->size());
+ for (size_t i = 0; i < audio_buffer->num_channels(); ++i) {
+ (*channel_ptr_vector)[i] = &(*audio_buffer)[i][0];
+ }
+}
+
+void GetRawChannelDataPointersFromAudioBuffer(
+ const AudioBuffer& audio_buffer,
+ std::vector<const float*>* channel_ptr_vector) {
+ DCHECK(channel_ptr_vector);
+ DCHECK_EQ(audio_buffer.num_channels(), channel_ptr_vector->size());
+ for (size_t i = 0; i < audio_buffer.num_channels(); ++i) {
+ (*channel_ptr_vector)[i] = &audio_buffer[i][0];
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion.h b/src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion.h
new file mode 100644
index 000000000..ed30be30e
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion.h
@@ -0,0 +1,421 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_PLANAR_INTERLEAVED_CONVERSION_H_
+#define RESONANCE_AUDIO_UTILS_PLANAR_INTERLEAVED_CONVERSION_H_
+
+#include <vector>
+
+#include "base/integral_types.h"
+#include "base/audio_buffer.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+// Copies interleaved audio data from a raw float pointer into separate channel
+// buffers specified by a vector of raw float pointers.
+//
+// @param interleaved_buffer Raw float pointer to interleaved audio data.
+// @param num_input_frames Size of |interleaved_buffer| in frames.
+// @param num_input_channels Number of channels in interleaved audio data.
+// @param planar_buffer_ptr Raw float pointers to each planar channel buffer.
+// @param num_output_frames Number of frames per channel in output buffer.
+void PlanarFromInterleaved(const float* interleaved_buffer,
+ size_t num_input_frames, size_t num_input_channels,
+ const std::vector<float*>& planar_buffer_ptr,
+ size_t num_output_frames);
+
+// Copies interleaved audio data from a raw int16 pointer into separate channel
+// buffers specified by a vector of raw float pointers.
+//
+// @param interleaved_buffer Raw int16 pointer to interleaved audio data.
+// @param num_input_frames Size of |interleaved_buffer| in frames.
+// @param num_input_channels Number of channels in interleaved audio data.
+// @param planar_buffer_ptr Raw float pointers to each planar channel buffer.
+// @param num_output_frames Number of frames per channel in output buffer.
+void PlanarFromInterleaved(const int16* interleaved_buffer,
+ size_t num_input_frames, size_t num_input_channels,
+ const std::vector<float*>& planar_buffer_ptr,
+ size_t num_output_frames);
+
+// Copies interleaved audio data from a raw float pointer into a planar
+// |AudioBuffer|. Note that the number of output channels and frames is defined
+// by the target |AudioBuffer| instance.
+//
+// @param interleaved_buffer Raw float pointer to interleaved audio data.
+// @param num_input_frames Size of interleaved_buffer in frames.
+// @param num_input_channels Number of channels in interleaved audio data.
+// @param output Target output buffer.
+void FillAudioBuffer(const float* interleaved_buffer, size_t num_input_frames,
+ size_t num_input_channels, AudioBuffer* output);
+
+// Copies interleaved audio data from a raw int16 pointer into a planar
+// |AudioBuffer|. Note that the number of output channels and frames is defined
+// by the target |AudioBuffer| instance.
+//
+// @param interleaved_buffer Raw int16 pointer to interleaved audio data.
+// @param num_input_frames Size of interleaved_buffer in frames.
+// @param num_input_channels Number of channels in interleaved audio data.
+// @param output Target output buffer.
+void FillAudioBuffer(const int16* interleaved_buffer, size_t num_input_frames,
+ size_t num_input_channels, AudioBuffer* output);
+
+// Copies interleaved audio data from a float vector into a planar
+// |AudioBuffer|. Note that the number of output channels and frames is defined
+// by the target |AudioBuffer| instance.
+//
+// @param interleaved_buffer Interleaved audio data.
+// @param num_input_channels Number of channels in interleaved audio data.
+// @param output Target output buffer.
+void FillAudioBuffer(const std::vector<float>& interleaved_buffer,
+ size_t num_input_channels, AudioBuffer* output);
+
+// Copies interleaved audio data from a int16 vector into a planar
+// |AudioBuffer|. Note that the number of output channels and frames is defined
+// by the target |AudioBuffer| instance.
+//
+// @param interleaved_buffer Interleaved audio data.
+// @param num_input_channels Number of channels in interleaved audio data.
+// @param output Target output buffer.
+void FillAudioBuffer(const std::vector<int16>& interleaved_buffer,
+ size_t num_input_channels, AudioBuffer* output);
+
+// Copies raw planar float audio data into a planar |AudioBuffer|. Note that the
+// number of output channels and frames is defined by the target |AudioBuffer|
+// instance.
+//
+// @param planar_ptrs Pointer to an array of pointers to raw float channel data.
+// @param num_input_frames Size of planar input in frames.
+// @param num_input_channels Number of channels in planar input buffer.
+// @param output Target output buffer.
+void FillAudioBuffer(const float* const* planar_ptrs, size_t num_input_frames,
+ size_t num_input_channels, AudioBuffer* output);
+
+// Copies raw planar int16 audio data into a planar |AudioBuffer|. Note that the
+// number of output channels and frames is defined by the target |AudioBuffer|
+// instance.
+//
+// @param planar_ptrs Pointer to an array of pointers to raw int16 channel data.
+// @param num_input_frames Size of planar input in frames.
+// @param num_input_channels Number of channels in planar input buffer.
+// @param output Target output buffer.
+void FillAudioBuffer(const int16* const* planar_ptrs, size_t num_input_frames,
+ size_t num_input_channels, AudioBuffer* output);
+
+// Copies interleaved audio data from a raw float pointer into a planar
+// |AudioBuffer| with a specified output frame offset. Note that the
+// number of output channels is defined by the target |AudioBuffer| instance.
+//
+// @param interleaved_buffer Raw float pointer to interleaved audio data.
+// @param num_input_frames Size of |interleaved_buffer| in frames.
+// @param num_input_channels Number of channels in interleaved audio data.
+// @param input_frame_offset First source frame position in input.
+// @param output_frame_offset First frame destination in output.
+// @param num_frames_to_copy Number of frames per copy.
+// @param output Target output buffer.
+void FillAudioBufferWithOffset(const float* interleaved_buffer,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ size_t input_frame_offset,
+ size_t output_frame_offset,
+ size_t num_frames_to_copy, AudioBuffer* output);
+
+// Copies interleaved audio data from a raw int16 pointer into a planar
+// |AudioBuffer| with a specified output frame offset. Note that the
+// number of output channels is defined by the target |AudioBuffer| instance.
+//
+// @param interleaved_buffer Raw int16 pointer to interleaved audio data.
+// @param num_input_frames Size of |interleaved_buffer| in frames.
+// @param num_input_channels Number of channels in interleaved audio data.
+// @param input_frame_offset First source frame position in input.
+// @param output_frame_offset First frame destination in output.
+// @param num_frames_to_copy Number of frames per copy.
+// @param output Target output buffer.
+void FillAudioBufferWithOffset(const int16* interleaved_buffer,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ size_t input_frame_offset,
+ size_t output_frame_offset,
+ size_t num_frames_to_copy, AudioBuffer* output);
+
+// Copies raw planar float audio data into a planar |AudioBuffer| with a
+// specified output frame offset. Note that the number of output channels is
+// defined by the target |AudioBuffer| instance.
+//
+// @param planar_ptrs Pointer to an array of pointers to raw float channel data.
+// @param num_input_frames Size of |interleaved_buffer| in frames.
+// @param num_input_channels Number of channels in interleaved audio data.
+// @param input_frame_offset First source frame position in input.
+// @param output_frame_offset First frame destination in output.
+// @param num_frames_to_copy Number of frames per copy.
+// @param output Target output buffer.
+void FillAudioBufferWithOffset(const float* const* planar_ptrs,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ size_t input_frame_offset,
+ size_t output_frame_offset,
+ size_t num_frames_to_copy, AudioBuffer* output);
+
+// Copies raw planar int16 audio data into a planar |AudioBuffer| with a
+// specified output frame offset. Note that the number of output channels is
+// defined by the target |AudioBuffer| instance.
+//
+// @param planar_ptrs Pointer to an array of pointers to raw int16 channel data.
+// @param num_input_frames Size of |interleaved_buffer| in frames.
+// @param num_input_channels Number of channels in interleaved audio data.
+// @param input_frame_offset First source frame position in input.
+// @param output_frame_offset First frame destination in output.
+// @param num_frames_to_copy Number of frames per copy.
+// @param output Target output buffer.
+void FillAudioBufferWithOffset(const int16* const* planar_ptrs,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ size_t input_frame_offset,
+ size_t output_frame_offset,
+ size_t num_frames_to_copy, AudioBuffer* output);
+
+// Copies interleaved audio data from a raw int16 pointer into a planar
+// |AudioBuffer|. The |channel_map| argument allows to reorder the channel
+// mapping between the interleaved input and output buffer. The i'th channel in
+// the output buffer corresponds to the |channel_map[i]|'th input channel. Note
+// that the number of output channels and frames is derived from the target
+// |AudioBuffer| instance.
+//
+// @param interleaved_buffer Raw int16 pointer to interleaved audio data.
+// @param num_input_frames Size of interleaved_buffer in frames.
+// @param num_input_channels Number of input channels.
+// @param channel_map Mapping that maps output channels to input channels
+// @param output Target output buffer.
+void FillAudioBufferWithChannelRemapping(const int16* interleaved_buffer,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ const std::vector<size_t>& channel_map,
+ AudioBuffer* output);
+
+// Copies interleaved audio data from a raw float pointer into a planar
+// |AudioBuffer|. The |channel_map| argument allows to reorder the channel
+// mapping between the interleaved input and output buffer. The i'th channel in
+// the output buffer corresponds to the |channel_map[i]| input channel. Note
+// that the number of output channels and frames is derived from the target
+// |AudioBuffer| instance.
+//
+// @param interleaved_buffer Raw float pointer to interleaved audio data.
+// @param num_input_frames Size of interleaved_buffer in frames.
+// @param num_input_channels Number of input channels.
+// @param channel_map Mapping that maps output channels to input channels
+// @param output Target output buffer.
+void FillAudioBufferWithChannelRemapping(const float* interleaved_buffer,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ const std::vector<size_t>& channel_map,
+ AudioBuffer* output);
+
+// Copies raw planar float audio data into a planar |AudioBuffer|. The
+// |channel_map| argument allows to reorder the channel mapping between the
+// planar input and output buffer. The i'th channel in the output buffer
+// corresponds to the |channel_map[i]| input channel. Note that the number of
+// output channels and frames is derived from the target |AudioBuffer| instance.
+//
+// @param planar_ptrs Pointer to an array of pointers to raw float channel data.
+// @param num_input_frames Size of interleaved_buffer in frames.
+// @param num_input_channels Number of input channels.
+// @param channel_map Mapping that maps output channels to input channels
+// @param output Target output buffer.
+void FillAudioBufferWithChannelRemapping(const float* const* planar_ptr,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ const std::vector<size_t>& channel_map,
+ AudioBuffer* output);
+
+// Copies raw planar int16 audio data into a planar |AudioBuffer|. The
+// |channel_map| argument allows to reorder the channel mapping between the
+// planar input and output buffer. The i'th channel in the output buffer
+// corresponds to the |channel_map[i]| input channel. Note that the number of
+// output channels and frames is derived from the target |AudioBuffer| instance.
+//
+// @param planar_ptrs Pointer to an array of pointers to raw int16 channel data.
+// @param num_input_frames Size of interleaved_buffer in frames.
+// @param num_input_channels Number of input channels.
+// @param channel_map Mapping that maps output channels to input channels
+// @param output Target output buffer.
+void FillAudioBufferWithChannelRemapping(const int16* const* planar_ptr,
+ size_t num_input_frames,
+ size_t num_input_channels,
+ const std::vector<size_t>& channel_map,
+ AudioBuffer* output);
+
+// Copies planar audio data from an |AudioBuffer| to an external interleaved
+// float vector. Note this method resizes the target vector to match number of
+// input samples.
+//
+// @param input Input audio buffer.
+// @param output interleaved output vector.
+void FillExternalBuffer(const AudioBuffer& input, std::vector<float>* output);
+
+// Copies and converts planar audio data from an |AudioBuffer| to an external
+// interleaved int16 vector. Note this method resizes the target vector to match
+// number of input samples.
+//
+// @param input Input audio buffer.
+// @param output interleaved output vector.
+void FillExternalBuffer(const AudioBuffer& input, std::vector<int16>* output);
+
+// Copies planar audio data from an |AudioBuffer| to an external planar raw
+// float buffer. Note that the input and output buffer must match in terms of
+// number of channels and frames.
+//
+// @param input Input audio buffer.
+// @param planar_output_ptrs Planar output vector.
+// @param num_output_frames Number of frames in output buffer.
+// @param num_output_channels Number of channels in output buffer.
+void FillExternalBuffer(const AudioBuffer& input,
+ float* const* planar_output_ptrs,
+ size_t num_output_frames, size_t num_output_channels);
+
+// Copies and converts audio data from an |AudioBuffer| to an external planar
+// int16 buffer. Note that the input and output buffer must match in terms of
+// number of channels and frames.
+//
+// @param input Input audio buffer.
+// @param planar_output_ptrs Planar output vector.
+// @param num_output_frames Number of frames in output buffer.
+// @param num_output_channels Number of channels in output buffer.
+void FillExternalBuffer(const AudioBuffer& input,
+ int16* const* planar_output_ptrs,
+ size_t num_output_frames, size_t num_output_channels);
+
+// Copies and converts planar audio data from an |AudioBuffer| to an external
+// interleaved raw int16 buffer. Note that the input and output buffer must
+// match in terms of number of channels and frames.
+//
+// @param input Input audio buffer.
+// @param interleaved_output_buffer Interleaved output vector.
+// @param num_output_frames Number of frames in output buffer.
+// @param num_output_channels Number of channels in output buffer.
+void FillExternalBuffer(const AudioBuffer& input,
+ int16* interleaved_output_buffer,
+ size_t num_output_frames, size_t num_output_channels);
+
+// Copies planar audio data from an |AudioBuffer| to an external interleaved
+// raw float buffer. Note that the input and output buffer must match in terms
+// of number of channels and frames.
+//
+// @param input Input audio buffer.
+// @param interleaved_output_buffer Interleaved output vector.
+// @param num_output_frames Number of frames in output buffer.
+// @param num_output_channels Number of channels in output buffer.
+void FillExternalBuffer(const AudioBuffer& input,
+ float* interleaved_output_buffer,
+ size_t num_output_frames, size_t num_output_channels);
+
+// Copies and converts audio data from an |AudioBuffer| to an external
+// planar raw int16 buffer with the ability to specify an offset into the
+// input and output buffer.
+//
+// @param input Input audio buffer.
+// @param input_offset_frames Offset into input buffer in frames.
+// @param planar_output_ptrs Planar output vector.
+// @param num_output_frames Number of frames in output buffer.
+// @param num_output_channels Number of channels in output buffer.
+// @param output_offset_frames Offset into the output buffer in frames.
+// @param num_frames_convert_and_copy Number of frames to be processed.
+void FillExternalBufferWithOffset(const AudioBuffer& input,
+ size_t input_offset_frames,
+ int16* const* planar_output_ptrs,
+ size_t num_output_frames,
+ size_t num_output_channels,
+ size_t output_offset_frames,
+ size_t num_frames_convert_and_copy);
+
+// Copies audio data from an |AudioBuffer| to an external planar raw float
+// buffer with the ability to specify an offset into the input and output
+// buffer.
+//
+// @param input Input audio buffer.
+// @param input_offset_frames Offset into input buffer in frames.
+// @param planar_output_ptrs Planar output vector.
+// @param num_output_frames Number of frames in output buffer.
+// @param num_output_channels Number of channels in output buffer.
+// @param output_offset_frames Offset into the output buffer in frames.
+// @param num_frames_convert_and_copy Number of frames to be processed.
+void FillExternalBufferWithOffset(const AudioBuffer& input,
+ size_t input_offset_frames,
+ float* const* planar_output_ptrs,
+ size_t num_output_frames,
+ size_t num_output_channels,
+ size_t output_offset_frames,
+ size_t num_frames_convert_and_copy);
+
+// Copies and converts audio data from an |AudioBuffer| to an external
+// interleaved raw int16 buffer with the ability to specify an offset into the
+// input and output buffer.
+//
+// @param input Input audio buffer.
+// @param input_offset_frames Offset into input buffer in frames.
+// @param interleaved_output_buffer Interleaved output vector.
+// @param num_output_frames Number of frames in output buffer.
+// @param num_output_channels Number of channels in output buffer.
+// @param output_offset_frames Offset into the output buffer in frames.
+// @param num_frames_convert_and_copy Number of frames to be processed.
+void FillExternalBufferWithOffset(const AudioBuffer& input,
+ size_t input_offset_frames,
+ int16* interleaved_output_buffer,
+ size_t num_output_frames,
+ size_t num_output_channels,
+ size_t output_offset_frames,
+ size_t num_frames_convert_and_copy);
+
+// Copies and audio data from an |AudioBuffer| to an external interleaved raw
+// float buffer with the ability to specify an offset into the input and output
+// buffer.
+//
+// @param input Input audio buffer.
+// @param input_offset_frames Offset into input buffer in frames.
+// @param interleaved_output_buffer Interleaved output vector.
+// @param num_output_frames Number of frames in output buffer.
+// @param num_output_channels Number of channels in output buffer.
+// @param output_offset_frames Offset into the output buffer in frames.
+// @param num_frames_convert_and_copy Number of frames to be processed.
+void FillExternalBufferWithOffset(const AudioBuffer& input,
+ size_t input_offset_frames,
+ float* interleaved_output_buffer,
+ size_t num_output_frames,
+ size_t num_output_channels,
+ size_t output_offset_frames,
+ size_t num_frames_convert_and_copy);
+
+// Generates a vector of mutable float pointers to the beginning of each channel
+// buffer in an |AudioBuffer|. The size of the |channel_ptr_vector| output
+// vector must match the number of channels in |audio_buffer|.
+//
+// @param audio_buffer Audio buffer.
+// @param channel_ptr_vector Output std::vector<float*> vector.
+void GetRawChannelDataPointersFromAudioBuffer(
+ AudioBuffer* audio_buffer, std::vector<float*>* channel_ptr_vector);
+
+// Generates a vector of immutable float pointers to the beginning of each
+// channel buffer in an |AudioBuffer|. The size of the |channel_ptr_vector|
+// output vector must match the number of channels in |audio_buffer|.
+//
+// @param audio_buffer Audio buffer.
+// @param channel_ptr_vector Output std::vector<const float*> vector.
+void GetRawChannelDataPointersFromAudioBuffer(
+ const AudioBuffer& audio_buffer,
+ std::vector<const float*>* channel_ptr_vector);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_PLANAR_INTERLEAVED_CONVERSION_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion_test.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion_test.cc
new file mode 100644
index 000000000..abfd31b82
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion_test.cc
@@ -0,0 +1,875 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/planar_interleaved_conversion.h"
+
+#include <algorithm>
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+namespace {
+
+// Epsilon for conversion from int16_t back to float.
+const float kFloatEpsilon = 1e-4f;
+const int16_t kIntEpsilon = 1;
+
+const int kMemoryAlignmentBytesInt = static_cast<int>(kMemoryAlignmentBytes);
+
+const size_t kMaxNumFrames = 16;
+const size_t kMaxNumChannels = 8;
+
+int16_t SingleFloatToInt16(float value) {
+ const float kInt16Min = static_cast<float>(-0x7FFF);
+ const float kInt16Max = static_cast<float>(0x7FFF);
+ const float scaled_value = value * kInt16Max;
+ const float clamped_value =
+ std::min(kInt16Max, std::max(kInt16Min, scaled_value));
+ return static_cast<int16_t>(clamped_value);
+}
+
+// Creates a trivial channel map, i.e. no mapping.
+std::vector<size_t> GetTrivialChannelMap(size_t size) {
+ std::vector<size_t> channel_map(size);
+ for (size_t i = 0; i < size; ++i) {
+ channel_map[i] = i;
+ }
+ return channel_map;
+}
+
+// Fills an interleaved buffer with the channel number / 10, in each frame
+// (converted to integer format).
+void FillInterleaved(size_t num_channels, size_t num_frames, int16_t* buffer) {
+ for (size_t f = 0; f < num_frames; ++f) {
+ for (size_t c = 0; c < num_channels; ++c) {
+ buffer[f * num_channels + c] =
+ SingleFloatToInt16(static_cast<float>(c) * 0.1f);
+ }
+ }
+}
+
+// Fills an interleaved buffer with the channel number / 10, in each frame.
+void FillInterleaved(size_t num_channels, size_t num_frames, float* buffer) {
+ for (size_t f = 0; f < num_frames; ++f) {
+ for (size_t c = 0; c < num_channels; ++c) {
+ buffer[f * num_channels + c] = static_cast<float>(c) * 0.1f;
+ }
+ }
+}
+
+// Fills a planar buffer with the channel number / 10, in each frame.
+void FillPlanar(AudioBuffer* buffer) {
+ for (size_t c = 0; c < buffer->num_channels(); ++c) {
+ std::fill_n(&(*buffer)[c][0], buffer->num_frames(),
+ static_cast<float>(c) * 0.1f);
+ }
+}
+
+// Fills a planar buffer with the channel number / 10, in each frame.
+void FillPlanar(size_t num_frames, std::vector<float*>* buffer) {
+ for (size_t c = 0; c < buffer->size(); ++c) {
+ std::fill_n((*buffer)[c], num_frames, static_cast<float>(c) * 0.1f);
+ }
+}
+
+// Fills a planar buffer with the channel number / 10, in each frame (converted
+// to integer format).
+void FillPlanar(size_t num_frames, int16_t** buffer, size_t num_channels) {
+ for (size_t c = 0; c < num_channels; ++c) {
+ std::fill_n(buffer[c], num_frames,
+ SingleFloatToInt16(static_cast<float>(c) * 0.1f));
+ }
+}
+
+// Fills a planar buffer with the channel number / 10, in each frame (converted
+// to integer format).
+void FillPlanar(size_t num_frames, std::vector<int16_t*>* buffer) {
+ FillPlanar(num_frames, buffer->data(), buffer->size());
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t num_channels, size_t num_frames,
+ const std::vector<int16_t*>& expected_output,
+ const std::vector<int16_t*>& output) {
+ for (size_t c = 0; c < num_channels; ++c) {
+ for (size_t f = 0; f < num_frames; ++f) {
+ EXPECT_NEAR(expected_output[c][f], output[c][f], kIntEpsilon);
+ }
+ }
+}
+
+// Verifies that the output and expected output match.
+template <typename InputType, typename OutputType>
+void VerifyOutputFloatTemplated(size_t num_channels, size_t num_frames,
+ const InputType& expected_output,
+ const OutputType& output,
+ const std::vector<size_t>& channel_map,
+ size_t output_offset) {
+ for (size_t c = 0; c < num_channels; ++c) {
+ for (size_t f = output_offset; f < output_offset + num_frames; ++f) {
+ EXPECT_NEAR(expected_output[channel_map[c]][f], output[c][f],
+ kFloatEpsilon);
+ }
+ }
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t num_channels, size_t num_frames,
+ const AudioBuffer& expected_output,
+ const AudioBuffer& output) {
+ VerifyOutputFloatTemplated<AudioBuffer, AudioBuffer>(
+ num_channels, num_frames, expected_output, output,
+ GetTrivialChannelMap(num_channels), 0);
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t num_channels, size_t num_frames,
+ const std::vector<float*>& expected_output,
+ const AudioBuffer& output) {
+ VerifyOutputFloatTemplated<std::vector<float*>, AudioBuffer>(
+ num_channels, num_frames, expected_output, output,
+ GetTrivialChannelMap(num_channels), 0);
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t num_channels, size_t num_frames,
+ const AudioBuffer& expected_output,
+ const std::vector<float*>& output) {
+ VerifyOutputFloatTemplated<AudioBuffer, std::vector<float*>>(
+ num_channels, num_frames, expected_output, output,
+ GetTrivialChannelMap(num_channels), 0);
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t num_channels, size_t num_frames,
+ const std::vector<float*>& expected_output,
+ const std::vector<float*>& output) {
+ VerifyOutputFloatTemplated<std::vector<float*>, std::vector<float*>>(
+ num_channels, num_frames, expected_output, output,
+ GetTrivialChannelMap(num_channels), 0);
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t num_channels, size_t num_frames,
+ const std::vector<const float*>& expected_output,
+ const std::vector<const float*>& output) {
+ VerifyOutputFloatTemplated<std::vector<const float*>,
+ std::vector<const float*>>(
+ num_channels, num_frames, expected_output, output,
+ GetTrivialChannelMap(num_channels), 0);
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t num_channels, size_t num_frames,
+ const AudioBuffer& expected_output, const AudioBuffer& output,
+ const std::vector<size_t>& channel_map) {
+ VerifyOutputFloatTemplated<AudioBuffer, AudioBuffer>(
+ num_channels, num_frames, expected_output, output, channel_map, 0);
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t num_channels, size_t num_frames, size_t output_offset,
+ const AudioBuffer& expected_output,
+ const AudioBuffer& output) {
+ VerifyOutputFloatTemplated<AudioBuffer, AudioBuffer>(
+ num_channels, num_frames, expected_output, output,
+ GetTrivialChannelMap(num_channels), output_offset);
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t length, const std::vector<float>& expected_output,
+ int16_t* output) {
+ for (size_t f = 0; f < length; ++f) {
+ EXPECT_NEAR(SingleFloatToInt16(expected_output[f]), output[f], kIntEpsilon);
+ }
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t length, const std::vector<float>& expected_output,
+ const std::vector<int16_t>& output) {
+ for (size_t f = 0; f < length; ++f) {
+ EXPECT_NEAR(SingleFloatToInt16(expected_output[f]), output[f], kIntEpsilon);
+ }
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t length, const std::vector<float>& expected_output,
+ float* output) {
+ for (size_t f = 0; f < length; ++f) {
+ EXPECT_NEAR(expected_output[f], output[f], kIntEpsilon);
+ }
+}
+
+// Verifies that the output and expected output match.
+void VerifyOutput(size_t length, const std::vector<float>& expected_output,
+ const std::vector<float>& output) {
+ for (size_t f = 0; f < length; ++f) {
+ EXPECT_NEAR(expected_output[f], output[f], kIntEpsilon);
+ }
+}
+
+typedef std::tuple<size_t, size_t> TestParams;
+class PlanarInterleavedConverterTest
+ : public ::testing::Test,
+ public ::testing::WithParamInterface<TestParams> {
+ protected:
+ PlanarInterleavedConverterTest() {}
+
+ // Virtual methods from ::testing::Test
+ ~PlanarInterleavedConverterTest() override {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+};
+
+// Tests that interleaved (float/int16_t) data can be correctly written into
+// vectors of float pointers.
+TEST_P(PlanarInterleavedConverterTest, TestInterleavedIntoVectorFloatPtr) {
+ const size_t num_channels = ::testing::get<0>(GetParam());
+ const size_t num_frames = ::testing::get<1>(GetParam());
+ const size_t num_interleaved_samples = num_frames * num_channels;
+
+ AudioBuffer expected_output(kMaxNumChannels, num_frames);
+ FillPlanar(&expected_output);
+
+ // Create output buffers memory.
+ AudioBuffer aligned_output_buffer(kMaxNumChannels, num_frames);
+ std::vector<float> unaligned_output_memory(num_interleaved_samples);
+
+ // Create output planar buffers.
+ std::vector<float*> aligned_output(num_channels);
+ std::vector<float*> unaligned_output(num_channels);
+ for (size_t c = 0; c < num_channels; ++c) {
+ aligned_output[c] = &aligned_output_buffer[c][0];
+ unaligned_output[c] = &unaligned_output_memory[num_frames * c];
+ }
+
+ // Integer.
+ AudioBuffer::AlignedInt16Vector interleaved_aligned_int(
+ num_interleaved_samples);
+ std::vector<int16_t> interleaved_unaligned_int(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, interleaved_aligned_int.data());
+ FillInterleaved(num_channels, num_frames, &interleaved_unaligned_int[0]);
+
+ // Aligned Input, Aligned Output.
+ aligned_output_buffer.Clear();
+ LOG(INFO) << "aligned_output.size()" << aligned_output.size();
+ LOG(INFO) << "num_frames" << num_frames;
+ PlanarFromInterleaved(interleaved_aligned_int.data(), num_frames,
+ num_channels, aligned_output, num_frames);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ aligned_output);
+
+ // Unaligned Input, Aligned Output.
+ aligned_output_buffer.Clear();
+ PlanarFromInterleaved(interleaved_unaligned_int.data(), num_frames,
+ num_channels, aligned_output, num_frames);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ aligned_output);
+
+ // Aligned Input. Unaligned Output.
+ std::fill(unaligned_output_memory.begin(), unaligned_output_memory.end(),
+ 0.0f);
+ PlanarFromInterleaved(interleaved_aligned_int.data(), num_frames,
+ num_channels, unaligned_output, num_frames);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ unaligned_output);
+ // Unligned Input. Unaligned Output.
+ std::fill(unaligned_output_memory.begin(), unaligned_output_memory.end(),
+ 0.0f);
+ PlanarFromInterleaved(&interleaved_unaligned_int[0], num_frames, num_channels,
+ unaligned_output, num_frames);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ unaligned_output);
+
+ // Floating point.
+ AudioBuffer::AlignedFloatVector interleaved_aligned_float(
+ num_interleaved_samples);
+ std::vector<float> interleaved_plane_float(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, interleaved_aligned_float.data());
+ FillInterleaved(num_channels, num_frames, &interleaved_plane_float[0]);
+ // Aligned Input, Aligned Output.
+ aligned_output_buffer.Clear();
+ PlanarFromInterleaved(interleaved_aligned_float.data(), num_frames,
+ num_channels, aligned_output, num_frames);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ aligned_output);
+ // Unaligned Input, Aligned Output.
+ aligned_output_buffer.Clear();
+ PlanarFromInterleaved(&interleaved_plane_float[0], num_frames, num_channels,
+ aligned_output, num_frames);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ aligned_output);
+ // Aligned Input. Unaligned Output.
+ std::fill(unaligned_output_memory.begin(), unaligned_output_memory.end(),
+ 0.0f);
+ PlanarFromInterleaved(interleaved_aligned_float.data(), num_frames,
+ num_channels, unaligned_output, num_frames);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ unaligned_output);
+ // Unligned Input. Unaligned Output.
+ std::fill(unaligned_output_memory.begin(), unaligned_output_memory.end(),
+ 0.0f);
+ PlanarFromInterleaved(&interleaved_plane_float[0], num_frames, num_channels,
+ unaligned_output, num_frames);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ unaligned_output);
+}
+
+// Tests that interleaved (float/int16_t) data can be correctly written into
+// |AudioBuffer|s.
+TEST_P(PlanarInterleavedConverterTest, TestInterleavedIntoAudioBuffer) {
+ const size_t num_channels = ::testing::get<0>(GetParam());
+ const size_t num_frames = ::testing::get<1>(GetParam());
+ const size_t num_interleaved_samples = num_frames * num_channels;
+
+ AudioBuffer expected_output(num_channels, num_frames);
+ FillPlanar(&expected_output);
+
+ // Create output buffers memory.
+ AudioBuffer output_buffer(num_channels, num_frames);
+
+ // Integer.
+ AudioBuffer::AlignedInt16Vector interleaved_aligned_int(
+ num_interleaved_samples);
+ std::vector<int16_t> interleaved_unaligned_int(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, interleaved_aligned_int.data());
+ FillInterleaved(num_channels, num_frames, &interleaved_unaligned_int[0]);
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBuffer(interleaved_aligned_int.data(), num_frames, num_channels,
+ &output_buffer);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ output_buffer);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBuffer(&interleaved_unaligned_int[0], num_frames, num_channels,
+ &output_buffer);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ output_buffer);
+
+ // Floating point.
+ AudioBuffer::AlignedFloatVector interleaved_aligned_float(
+ num_interleaved_samples);
+ std::vector<float> interleaved_plane_float(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, interleaved_aligned_float.data());
+ FillInterleaved(num_channels, num_frames, &interleaved_plane_float[0]);
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBuffer(interleaved_aligned_float.data(), num_frames, num_channels,
+ &output_buffer);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ output_buffer);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBuffer(&interleaved_plane_float[0], num_frames, num_channels,
+ &output_buffer);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ output_buffer);
+}
+
+// Tests that interleaved (float/int16_t) vectors can be correctly written into
+// |AudioBuffer|s.
+TEST_P(PlanarInterleavedConverterTest, TestInterleavedVectorIntoAudioBuffer) {
+ const size_t num_channels = ::testing::get<0>(GetParam());
+ const size_t num_frames = ::testing::get<1>(GetParam());
+ const size_t num_interleaved_samples = num_frames * num_channels;
+
+ AudioBuffer expected_output(num_channels, num_frames);
+ FillPlanar(&expected_output);
+
+ // Create output buffers memory.
+ AudioBuffer output_buffer(num_channels, num_frames);
+
+ // Integer.
+ std::vector<int16_t> interleaved_unaligned_int(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, &interleaved_unaligned_int[0]);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBuffer(&interleaved_unaligned_int[0], num_frames, num_channels,
+ &output_buffer);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ output_buffer);
+
+ // Floating point.
+ std::vector<float> interleaved_plane_float(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, &interleaved_plane_float[0]);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBuffer(&interleaved_plane_float[0], num_frames, num_channels,
+ &output_buffer);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ output_buffer);
+}
+
+// Tests that vectors of planar (float/int16_t) pointers can be correctly
+// written into |AudioBuffer|s.
+TEST_P(PlanarInterleavedConverterTest, TestPlanarPtrsIntoAudioBuffer) {
+ const size_t num_channels = ::testing::get<0>(GetParam());
+ const size_t num_frames = ::testing::get<1>(GetParam());
+
+ AudioBuffer expected_output(kMaxNumChannels, num_frames);
+ FillPlanar(&expected_output);
+
+ // Create output buffers memory.
+ AudioBuffer output_buffer(num_channels, num_frames);
+
+ // Integer.
+ std::vector<AudioBuffer::AlignedInt16Vector> planar_aligned_channels_int_buf(
+ num_channels, AudioBuffer::AlignedInt16Vector(num_frames));
+ std::vector<std::vector<int16_t>> planar_unaligned_channels_int_buffers(
+ num_channels, std::vector<int16_t>(num_frames));
+ std::vector<int16_t*> planar_aligned_channels_int(num_channels);
+ std::vector<int16_t*> planar_unaligned_channels_int(num_channels);
+ for (size_t c = 0; c < num_channels; ++c) {
+ planar_aligned_channels_int[c] = planar_aligned_channels_int_buf[c].data();
+ planar_unaligned_channels_int[c] =
+ planar_unaligned_channels_int_buffers[c].data();
+ }
+ FillPlanar(num_frames, &planar_aligned_channels_int);
+ FillPlanar(num_frames, &planar_unaligned_channels_int);
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBuffer(&planar_aligned_channels_int[0], num_frames, num_channels,
+ &output_buffer);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ output_buffer);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBuffer(&planar_unaligned_channels_int[0], num_frames, num_channels,
+ &output_buffer);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ output_buffer);
+
+ // Floating point.
+ std::vector<AudioBuffer::AlignedFloatVector>
+ planar_aligned_channels_float_buf(
+ num_channels, AudioBuffer::AlignedFloatVector(num_frames));
+ std::vector<std::vector<float>> planar_unaligned_channels_float_buffers(
+ num_channels, std::vector<float>(num_frames));
+ std::vector<float*> planar_aligned_channels_float(num_channels);
+ std::vector<float*> planar_unaligned_channels_float(num_channels);
+ for (size_t c = 0; c < num_channels; ++c) {
+ planar_aligned_channels_float[c] =
+ planar_aligned_channels_float_buf[c].data();
+ planar_unaligned_channels_float[c] =
+ planar_unaligned_channels_float_buffers[c].data();
+ }
+ FillPlanar(num_frames, &planar_aligned_channels_float);
+ FillPlanar(num_frames, &planar_unaligned_channels_float);
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBuffer(&planar_aligned_channels_float[0], num_frames, num_channels,
+ &output_buffer);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ output_buffer);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBuffer(&planar_unaligned_channels_float[0], num_frames, num_channels,
+ &output_buffer);
+ VerifyOutput(num_channels, std::min(num_frames, num_frames), expected_output,
+ output_buffer);
+}
+
+// Tests that interleaved (float/int16_t) data can be correctly written into
+// |AudioBuffer|s, with offsets into both the input and output data.
+TEST_P(PlanarInterleavedConverterTest,
+ TestInterleavedIntoAudioBufferWithOffset) {
+ const size_t num_channels = ::testing::get<0>(GetParam());
+ const size_t num_frames = ::testing::get<1>(GetParam());
+
+ AudioBuffer expected_output(kMaxNumChannels, num_frames);
+ FillPlanar(&expected_output);
+
+ const size_t num_interleaved_samples = num_frames * num_channels;
+ // Create output buffers memory.
+ AudioBuffer output_buffer(num_channels, num_frames);
+
+ AudioBuffer::AlignedInt16Vector interleaved_aligned_int(
+ num_interleaved_samples);
+ std::vector<int16_t> interleaved_unaligned_int(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, interleaved_aligned_int.data());
+ FillInterleaved(num_channels, num_frames, &interleaved_unaligned_int[0]);
+
+ AudioBuffer::AlignedFloatVector interleaved_aligned_float(
+ num_interleaved_samples);
+ std::vector<float> interleaved_plane_float(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, interleaved_aligned_float.data());
+ FillInterleaved(num_channels, num_frames, &interleaved_plane_float[0]);
+
+ for (size_t output_offset = 1; output_offset <= 4; ++output_offset) {
+ for (size_t input_offset = 1; input_offset <= 4; ++input_offset) {
+ const size_t num_frames_to_copy =
+ std::min(num_frames - input_offset, num_frames - output_offset);
+ // Integer.
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithOffset(interleaved_aligned_int.data(), num_frames,
+ num_channels, input_offset, output_offset,
+ num_frames_to_copy, &output_buffer);
+ VerifyOutput(num_channels, num_frames_to_copy, output_offset,
+ expected_output, output_buffer);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithOffset(&interleaved_unaligned_int[0], num_frames,
+ num_channels, input_offset, output_offset,
+ num_frames_to_copy, &output_buffer);
+ VerifyOutput(num_channels, num_frames_to_copy, output_offset,
+ expected_output, output_buffer);
+
+ // Floating point.
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithOffset(interleaved_aligned_float.data(), num_frames,
+ num_channels, input_offset, output_offset,
+ num_frames_to_copy, &output_buffer);
+ VerifyOutput(num_channels, num_frames_to_copy, output_offset,
+ expected_output, output_buffer);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithOffset(&interleaved_plane_float[0], num_frames,
+ num_channels, input_offset, output_offset,
+ num_frames_to_copy, &output_buffer);
+ VerifyOutput(num_channels, num_frames_to_copy, output_offset,
+ expected_output, output_buffer);
+ }
+ }
+}
+
+// Tests that planar (float/int16_t) data can be correctly written into
+// |AudioBuffer|s, with offsets into both the input and output data.
+TEST_P(PlanarInterleavedConverterTest,
+ TestPlanarPtrsIntoAudioBufferWithOffset) {
+ const size_t num_channels = ::testing::get<0>(GetParam());
+ const size_t num_frames = ::testing::get<1>(GetParam());
+
+ AudioBuffer expected_output(num_channels, num_frames);
+ FillPlanar(&expected_output);
+
+ // Create output buffers memory.
+ AudioBuffer output_buffer(num_channels, num_frames);
+
+ std::vector<AudioBuffer::AlignedInt16Vector>
+ planar_aligned_channels_int_buffers(
+ num_channels, AudioBuffer::AlignedInt16Vector(num_frames));
+ std::vector<std::vector<int16_t>> planar_unaligned_channels_int_buffers(
+ num_channels, std::vector<int16_t>(num_frames));
+
+ std::vector<int16_t*> planar_aligned_channels_int(num_channels);
+ std::vector<int16_t*> planar_unaligned_channels_int(num_channels);
+ for (size_t c = 0; c < num_channels; ++c) {
+ planar_aligned_channels_int[c] =
+ planar_aligned_channels_int_buffers[c].data();
+ planar_unaligned_channels_int[c] =
+ planar_unaligned_channels_int_buffers[c].data();
+ }
+ FillPlanar(num_frames, &planar_aligned_channels_int);
+ FillPlanar(num_frames, &planar_unaligned_channels_int);
+
+ std::vector<AudioBuffer::AlignedFloatVector>
+ planar_aligned_channels_float_buffer(
+ num_channels, AudioBuffer::AlignedFloatVector(num_frames));
+ std::vector<std::vector<float>> planar_unaligned_channels_float_buffers(
+ num_channels, std::vector<float>(num_frames));
+
+ std::vector<float*> planar_aligned_channels_float(num_channels);
+ std::vector<float*> planar_unaligned_channels_float(num_channels);
+
+ for (size_t c = 0; c < num_channels; ++c) {
+ planar_aligned_channels_float[c] =
+ planar_aligned_channels_float_buffer[c].data();
+ planar_unaligned_channels_float[c] =
+ planar_unaligned_channels_float_buffers[c].data();
+ }
+ FillPlanar(num_frames, &planar_aligned_channels_float);
+ FillPlanar(num_frames, &planar_unaligned_channels_float);
+
+ for (size_t output_offset = 1; output_offset <= 4; ++output_offset) {
+ for (size_t input_offset = 1; input_offset <= 4; ++input_offset) {
+ const size_t num_frames_to_copy =
+ std::min(num_frames - input_offset, num_frames - output_offset);
+ // Integer.
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithOffset(&planar_aligned_channels_int[0], num_frames,
+ num_channels, input_offset, output_offset,
+ num_frames_to_copy, &output_buffer);
+ VerifyOutput(num_channels, num_frames_to_copy, output_offset,
+ expected_output, output_buffer);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithOffset(&planar_unaligned_channels_int[0], num_frames,
+ num_channels, input_offset, output_offset,
+ num_frames_to_copy, &output_buffer);
+ VerifyOutput(num_channels, num_frames_to_copy, output_offset,
+ expected_output, output_buffer);
+
+ // Floating point.
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithOffset(&planar_aligned_channels_float[0], num_frames,
+ num_channels, input_offset, output_offset,
+ num_frames_to_copy, &output_buffer);
+ VerifyOutput(num_channels, num_frames_to_copy, output_offset,
+ expected_output, output_buffer);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithOffset(&planar_unaligned_channels_float[0], num_frames,
+ num_channels, input_offset, output_offset,
+ num_frames_to_copy, &output_buffer);
+ VerifyOutput(num_channels, num_frames_to_copy, output_offset,
+ expected_output, output_buffer);
+ }
+ }
+}
+
+// Tests that interleaved (float/int16_t) data can be correctly written into
+// |AudioBuffer|s, with remapping of channels.
+TEST_P(PlanarInterleavedConverterTest,
+ TestInterleavedIntoAudioBufferRemapping) {
+ const size_t num_channels = ::testing::get<0>(GetParam());
+ const size_t num_frames = ::testing::get<1>(GetParam());
+
+ AudioBuffer expected_output(num_channels, num_frames);
+ FillPlanar(&expected_output);
+
+ std::vector<size_t> channel_map(num_channels);
+ for (size_t c = 0; c < num_channels; ++c) {
+ channel_map[c] = c;
+ }
+
+ // Permute the channel map.
+ std::next_permutation(channel_map.begin(), channel_map.end());
+ const size_t num_interleaved_samples = num_frames * num_channels;
+
+ // Create output buffers memory.
+ AudioBuffer output_buffer(num_channels, num_frames);
+
+ // Integer.
+ AudioBuffer::AlignedInt16Vector interleaved_aligned_int(
+ num_interleaved_samples);
+ std::vector<int16_t> interleaved_unaligned_int(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, interleaved_aligned_int.data());
+ FillInterleaved(num_channels, num_frames, &interleaved_unaligned_int[0]);
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithChannelRemapping(interleaved_aligned_int.data(),
+ num_frames, num_channels, channel_map,
+ &output_buffer);
+ VerifyOutput(num_channels, num_frames, expected_output, output_buffer,
+ channel_map);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithChannelRemapping(&interleaved_unaligned_int[0], num_frames,
+ num_channels, channel_map,
+ &output_buffer);
+ VerifyOutput(num_channels, num_frames, expected_output, output_buffer,
+ channel_map);
+
+ // Floating point.
+ AudioBuffer::AlignedFloatVector interleaved_aligned_float(
+ num_interleaved_samples);
+ std::vector<float> interleaved_plane_float(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, interleaved_aligned_float.data());
+ FillInterleaved(num_channels, num_frames, &interleaved_plane_float[0]);
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithChannelRemapping(interleaved_aligned_float.data(),
+ num_frames, num_channels, channel_map,
+ &output_buffer);
+ VerifyOutput(num_channels, num_frames, expected_output, output_buffer,
+ channel_map);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithChannelRemapping(&interleaved_plane_float[0], num_frames,
+ num_channels, channel_map,
+ &output_buffer);
+ VerifyOutput(num_channels, num_frames, expected_output, output_buffer,
+ channel_map);
+}
+
+// Tests that planar (float/int16_t) data can be correctly written into
+// |AudioBuffer|s, with remapping of channels.
+TEST_P(PlanarInterleavedConverterTest, TestPlanarPtrsIntoAudioBufferRemapping) {
+ const size_t num_channels = ::testing::get<0>(GetParam());
+ const size_t num_frames = ::testing::get<1>(GetParam());
+
+ AudioBuffer expected_output(num_channels, num_frames);
+ FillPlanar(&expected_output);
+
+ std::vector<size_t> channel_map(num_channels);
+ for (size_t c = 0; c < num_channels; ++c) {
+ channel_map[c] = c;
+ }
+ // Permute the channel map.
+ std::next_permutation(channel_map.begin(), channel_map.end());
+ // Create output buffers memory.
+ AudioBuffer output_buffer(num_channels, num_frames);
+
+ // Integer.
+ std::vector<AudioBuffer::AlignedInt16Vector>
+ planar_aligned_channels_int_bufferss(
+ num_channels, AudioBuffer::AlignedInt16Vector(num_frames));
+ std::vector<std::vector<int16_t>> planar_unaligned_channels_int_buffers(
+ num_channels, std::vector<int16_t>(num_frames));
+
+ std::vector<int16_t*> planar_aligned_channels_int(num_channels);
+ std::vector<int16_t*> planar_unaligned_channels_int(num_channels);
+ for (size_t c = 0; c < num_channels; ++c) {
+ planar_aligned_channels_int[c] =
+ planar_aligned_channels_int_bufferss[c].data();
+ planar_unaligned_channels_int[c] =
+ planar_unaligned_channels_int_buffers[c].data();
+ }
+
+ FillPlanar(num_frames, &planar_aligned_channels_int);
+ FillPlanar(num_frames, &planar_unaligned_channels_int);
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithChannelRemapping(&planar_aligned_channels_int[0],
+ num_frames, num_channels, channel_map,
+ &output_buffer);
+ VerifyOutput(num_channels, num_frames, expected_output, output_buffer,
+ channel_map);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithChannelRemapping(&planar_unaligned_channels_int[0],
+ num_frames, num_channels, channel_map,
+ &output_buffer);
+ VerifyOutput(num_channels, num_frames, expected_output, output_buffer,
+ channel_map);
+
+ // Floating point.
+ std::vector<AudioBuffer::AlignedFloatVector>
+ planar_aligned_channels_float_buffers(
+ num_channels, AudioBuffer::AlignedFloatVector(num_frames));
+ std::vector<std::vector<float>> planar_unaligned_channels_float_buffers(
+ num_channels, std::vector<float>(num_frames));
+
+ std::vector<float*> planar_aligned_channels_float(num_channels);
+ std::vector<float*> planar_unaligned_channels_float(num_channels);
+ for (size_t c = 0; c < num_channels; ++c) {
+ planar_aligned_channels_float[c] =
+ planar_aligned_channels_float_buffers[c].data();
+ planar_unaligned_channels_float[c] =
+ planar_unaligned_channels_float_buffers[c].data();
+ }
+ FillPlanar(num_frames, &planar_aligned_channels_float);
+ FillPlanar(num_frames, &planar_unaligned_channels_float);
+ // Aligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithChannelRemapping(&planar_aligned_channels_float[0],
+ num_frames, num_channels, channel_map,
+ &output_buffer);
+ VerifyOutput(num_channels, num_frames, expected_output, output_buffer,
+ channel_map);
+ // Unaligned Input, Aligned Output.
+ output_buffer.Clear();
+ FillAudioBufferWithChannelRemapping(&planar_unaligned_channels_float[0],
+ num_frames, num_channels, channel_map,
+ &output_buffer);
+ VerifyOutput(num_channels, num_frames, expected_output, output_buffer,
+ channel_map);
+}
+
+// Tests that an |AudioBuffer| can be correctly written into an interleaved
+// vector of (float/int16_t) data.
+TEST_P(PlanarInterleavedConverterTest, TestAudioBufferIntoInterleavedVector) {
+ const size_t num_channels = ::testing::get<0>(GetParam());
+ const size_t num_frames = ::testing::get<1>(GetParam());
+ const size_t num_interleaved_samples = num_frames * num_channels;
+ std::vector<float> expected_output(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, &expected_output[0]);
+
+ // Floating point.
+ AudioBuffer planar_input(num_channels, num_frames);
+ FillPlanar(&planar_input);
+ // Aligned Input, Unaligned Output.
+ std::vector<float> interleaved_output;
+ FillExternalBuffer(planar_input, &interleaved_output);
+ VerifyOutput(num_frames * num_channels, expected_output, interleaved_output);
+}
+
+// Tests that an |AudioBuffer| can be correctly written into an interleaved
+// (float/int16_t) array.
+TEST_P(PlanarInterleavedConverterTest, TestAudioBufferIntoInterleavedPtr) {
+ const size_t num_channels = ::testing::get<0>(GetParam());
+ const size_t num_frames = ::testing::get<1>(GetParam());
+ const size_t num_interleaved_samples = num_frames * num_channels;
+
+ std::vector<float> expected_output(num_interleaved_samples);
+ FillInterleaved(num_channels, num_frames, &expected_output[0]);
+
+ AudioBuffer planar_input(num_channels, num_frames);
+ FillPlanar(&planar_input);
+
+ // Integer.
+ AudioBuffer::AlignedInt16Vector interleaved_aligned_int(
+ num_interleaved_samples);
+ std::vector<int16_t> interleaved_unaligned_int(num_interleaved_samples);
+
+ // Aligned Input, Aligned Output.
+ DCHECK_EQ(interleaved_aligned_int.size(),
+ planar_input.num_frames() * planar_input.num_channels());
+ FillExternalBuffer(planar_input, interleaved_aligned_int.data(),
+ planar_input.num_frames(), planar_input.num_channels());
+ VerifyOutput(num_frames * num_channels, expected_output,
+ interleaved_aligned_int.data());
+ // Aligned Input, Unaligned Output.
+ DCHECK_EQ(interleaved_unaligned_int.size(),
+ planar_input.num_frames() * planar_input.num_channels());
+ FillExternalBuffer(planar_input, interleaved_unaligned_int.data(),
+ planar_input.num_frames(), planar_input.num_channels());
+ VerifyOutput(num_frames * num_channels, expected_output,
+ interleaved_unaligned_int);
+
+ // Floating point.
+ AudioBuffer::AlignedFloatVector interleaved_aligned_float(
+ num_interleaved_samples);
+ std::vector<float> interleaved_plane_float(num_interleaved_samples);
+
+ // Aligned Input, Aligned Output.
+ DCHECK_EQ(interleaved_aligned_float.size(),
+ planar_input.num_frames() * planar_input.num_channels());
+ FillExternalBuffer(planar_input, interleaved_aligned_float.data(),
+ planar_input.num_frames(), planar_input.num_channels());
+ VerifyOutput(num_frames * num_channels, expected_output,
+ interleaved_aligned_float.data());
+ // Aligned Input, Unaligned Output.
+ FillExternalBuffer(planar_input, &interleaved_plane_float[0],
+ planar_input.num_frames(), planar_input.num_channels());
+ VerifyOutput(num_frames * num_channels, expected_output,
+ interleaved_plane_float);
+}
+
+// Test Params define: channels, frames
+INSTANTIATE_TEST_CASE_P(
+ TestParameters, PlanarInterleavedConverterTest,
+ testing::Values(
+ TestParams(2, 8), TestParams(2, 13), TestParams(2, kMaxNumFrames),
+ TestParams(4, 8), TestParams(4, 13), TestParams(4, kMaxNumFrames),
+ TestParams(5, 8), TestParams(5, 13), TestParams(5, kMaxNumFrames),
+ TestParams(kMaxNumChannels, 8), TestParams(kMaxNumChannels, 13),
+ TestParams(kMaxNumChannels, kMaxNumFrames)));
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/pseudoinverse.h b/src/3rdparty/resonance-audio/resonance_audio/utils/pseudoinverse.h
new file mode 100644
index 000000000..17b4b2934
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/pseudoinverse.h
@@ -0,0 +1,45 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_PSEUDOINVERSE_H_
+#define RESONANCE_AUDIO_UTILS_PSEUDOINVERSE_H_
+
+#include "Eigen/Dense"
+
+namespace vraudio {
+
+// Computes the Moore-Penrose pseudoinverse of |matrix|.
+//
+// @tparam MatrixType The type of the input matrix (an Eigen::Matrix).
+// @param matrix The input matrix to compute the pseudoinverse of.
+// @return The Moore-Penrose pseudoinverse of |matrix|.
+template <typename MatrixType>
+Eigen::Matrix<typename MatrixType::Scalar, MatrixType::ColsAtCompileTime,
+ MatrixType::RowsAtCompileTime>
+Pseudoinverse(const MatrixType& matrix) {
+ Eigen::JacobiSVD<Eigen::Matrix<typename MatrixType::Scalar, Eigen::Dynamic,
+ Eigen::Dynamic>> svd(matrix,
+ Eigen::ComputeThinU |
+ Eigen::ComputeThinV);
+ return svd.solve(
+ Eigen::Matrix<typename MatrixType::Scalar, MatrixType::RowsAtCompileTime,
+ MatrixType::RowsAtCompileTime>::Identity(matrix.rows(),
+ matrix.rows()));
+}
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_PSEUDOINVERSE_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/pseudoinverse_test.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/pseudoinverse_test.cc
new file mode 100644
index 000000000..c71e97595
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/pseudoinverse_test.cc
@@ -0,0 +1,87 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/pseudoinverse.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/constants_and_types.h"
+
+namespace vraudio {
+
+namespace {
+
+// Tests that the pseudoinverse of an invertible square matrix is equal to the
+// inverse of that matrix.
+TEST(PseudoinverseTest, SquareInverse) {
+ Eigen::Matrix<double, 5, 5> invertible_matrix;
+ invertible_matrix << 0.8478, 0.1676, 0.1961, 0.2654, 0.7662, 0.0279, 0.5309,
+ 0.2043, 0.4947, 0.0918, 0.1367, 0.4714, 0.7113, 0.246, 0.8048, 0.9617,
+ 0.4378, 0.0259, 0.536, 0.9565, 0.1541, 0.6275, 0.8471, 0.1133, 0.8074;
+ ASSERT_NE(0.0, invertible_matrix.determinant());
+
+ auto pseudoinverse = Pseudoinverse(invertible_matrix);
+ auto inverse = invertible_matrix.inverse();
+
+ EXPECT_TRUE(pseudoinverse.isApprox(inverse, kEpsilonDouble))
+ << "Pseudoinverse: \n"
+ << pseudoinverse << " should be within " << kEpsilonDouble
+ << " of inverse: \n"
+ << inverse;
+}
+
+// Tests that the pseudoinverse of a full-rank matrix with more rows than
+// columns works successfully.
+TEST(PseudoinverseTest, PseudoinverseMoreRows) {
+ Eigen::Matrix<double, 5, 4> invertible_matrix;
+ invertible_matrix << 0.8478, 0.1676, 0.1961, 0.2654, 0.0279, 0.5309, 0.2043,
+ 0.4947, 0.1367, 0.4714, 0.7113, 0.246, 0.9617, 0.4378, 0.0259, 0.536,
+ 0.1541, 0.6275, 0.8471, 0.1133;
+
+ auto pseudoinverse = Pseudoinverse(invertible_matrix);
+ auto should_be_identity = pseudoinverse * invertible_matrix;
+
+ EXPECT_TRUE(should_be_identity.isApprox(
+ decltype(should_be_identity)::Identity(should_be_identity.rows(),
+ should_be_identity.cols()),
+ kEpsilonDouble))
+ << "Matrix should be within " << kEpsilonDouble
+ << " of an identity matrix: \n"
+ << should_be_identity;
+}
+
+// Tests that the pseudoinverse of a full-rank matrix with more columns than
+// rows works successfully.
+TEST(PseudoinverseTest, PseudoinverseMoreColumns) {
+ Eigen::Matrix<double, 4, 5> invertible_matrix;
+ invertible_matrix << 0.8478, 0.1676, 0.1961, 0.2654, 0.7662, 0.0279, 0.5309,
+ 0.2043, 0.4947, 0.0918, 0.1367, 0.4714, 0.7113, 0.246, 0.8048, 0.9617,
+ 0.4378, 0.0259, 0.536, 0.9565;
+
+ auto pseudoinverse = Pseudoinverse(invertible_matrix);
+ auto should_be_identity = invertible_matrix * pseudoinverse;
+
+ EXPECT_TRUE(should_be_identity.isApprox(
+ decltype(should_be_identity)::Identity(should_be_identity.rows(),
+ should_be_identity.cols()),
+ kEpsilonDouble))
+ << "Matrix should be within " << kEpsilonDouble
+ << " of an identity matrix: \n"
+ << should_be_identity;
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion.cc
new file mode 100644
index 000000000..fdd010cb9
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion.cc
@@ -0,0 +1,40 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "utils/sample_type_conversion.h"
+
+#include "base/simd_utils.h"
+
+namespace vraudio {
+
+void ConvertPlanarSamples(size_t length, const int16* input, float* output) {
+ FloatFromInt16(length, input, output);
+}
+
+void ConvertPlanarSamples(size_t length, const float* input, float* output) {
+ std::copy_n(input, length, output);
+}
+
+void ConvertPlanarSamples(size_t length, const float* input, int16* output) {
+ Int16FromFloat(length, input, output);
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion.h b/src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion.h
new file mode 100644
index 000000000..5fcb1a33c
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion.h
@@ -0,0 +1,79 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_SAMPLE_TYPE_CONVERSION_H_
+#define RESONANCE_AUDIO_UTILS_SAMPLE_TYPE_CONVERSION_H_
+
+#include <algorithm>
+
+#include "base/integral_types.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+// Convert the given int16 to a float in the range [-1.0f, 1.0f].
+inline void ConvertSampleToFloatFormat(int16 input, float* output) {
+ DCHECK(output);
+ static const float kInt16Max = static_cast<float>(0x7FFF);
+ static const float kInt16ToFloat = 1.0f / kInt16Max;
+ *output = input * kInt16ToFloat;
+}
+
+// Overloaded input argument to support sample type templated methods.
+inline void ConvertSampleToFloatFormat(float input, float* output) {
+ DCHECK(output);
+ *output = input;
+}
+
+// Saturating if the float is not in [-1.0f, 1.0f].
+inline void ConvertSampleFromFloatFormat(float input, int16* output) {
+ DCHECK(output);
+ // Convert the given float to an int16 in the range
+ // [-32767 (0x7FFF), 32767 (0x7FFF)],
+ static const float kInt16Min = static_cast<float>(-0x7FFF);
+ static const float kInt16Max = static_cast<float>(0x7FFF);
+ static const float kFloatToInt16 = kInt16Max;
+ const float scaled_value = input * kFloatToInt16;
+ const float clamped_value =
+ std::min(kInt16Max, std::max(kInt16Min, scaled_value));
+ *output = static_cast<int16>(clamped_value);
+}
+
+// Overloaded output argument to support sample type templated methods.
+inline void ConvertSampleFromFloatFormat(float input, float* output) {
+ DCHECK(output);
+ *output = input;
+}
+
+// Convert a vector of int16 samples to float format in the range [-1.0f, 1.0f].
+void ConvertPlanarSamples(size_t length, const int16* input,
+ float* output);
+
+// Overloaded input argument to support sample type templated methods.
+void ConvertPlanarSamples(size_t length, const float* input,
+ float* output);
+
+// Overloaded method to support methods templated against the input sample type.
+void ConvertPlanarSamples(size_t length, const float* input,
+ int16* output);
+
+// Overloaded output argument to support sample type templated methods.
+void ConvertPlanarSamples(size_t length, const float* input,
+ float* output);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_SAMPLE_TYPE_CONVERSION_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion_test.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion_test.cc
new file mode 100644
index 000000000..8d4e84243
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/sample_type_conversion_test.cc
@@ -0,0 +1,80 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/sample_type_conversion.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+
+namespace vraudio {
+
+namespace {
+
+TEST(MiscMath, Int16ToFloatTest) {
+ static const int16 kMinInt16 = -0x7FFF;
+ static const int16 kMaxInt16 = 0x7FFF;
+ static const float kMinFloat = -1.0f;
+ static const float kMaxFloat = 1.0f;
+
+ static const float kFloatRange = kMaxFloat - kMinFloat;
+ static const uint16 kInt16Range = kMaxInt16 - kMinInt16;
+
+ for (int16 i = kMinInt16; i < kMaxInt16; i = static_cast<int16>(i + 0xFF)) {
+ const float mapped_float =
+ static_cast<float>(i) / static_cast<float>(kInt16Range) * kFloatRange;
+ float float_result = 0.0f;
+ ConvertSampleToFloatFormat(i, &float_result);
+ EXPECT_FLOAT_EQ(mapped_float, float_result);
+ }
+}
+
+TEST(MiscMath, FloatToInt16Test) {
+ static const int16 kMinInt16 = -0x7FFF;
+ static const int16 kMaxInt16 = 0x7FFF;
+ static const float kMinFloat = -1.0f;
+ static const float kMaxFloat = 1.0f;
+ // NOTE: Int16 maximum is 0x7FFF, NOT 0x8000; see scheme 2) in
+ // http://goo.gl/NTRQ1a for background.
+ static const float kFloatRange = kMaxFloat - kMinFloat;
+ static const uint16 kInt16Range = kMaxInt16 - kMinInt16;
+
+ for (float i = kMinFloat; i < kMaxFloat; i += 0.005f) {
+ const int16 mapped_int = static_cast<int16>(i * kInt16Range / kFloatRange);
+ int16 int16_result = 0;
+ ConvertSampleFromFloatFormat(i, &int16_result);
+ EXPECT_EQ(mapped_int, int16_result);
+ }
+}
+
+TEST(MiscMath, FloatToInt16TestPositiveSaturate) {
+ // Maximum positive value is 2^15 - 1
+ static const int16 kMaxInt16 = 0x7FFF;
+ static const float kMaxFloat = 1.0f;
+ int16 int16_result = 0;
+ ConvertSampleFromFloatFormat(2 * kMaxFloat, &int16_result);
+ EXPECT_EQ(kMaxInt16, int16_result);
+}
+
+TEST(MiscMath, FloatToInt16TestNegativeSaturate) {
+ static const int16 kMinInt16 = -0x7FFF;
+ static const float kMinFloat = -1.0f;
+ int16 int16_result = 0;
+ ConvertSampleFromFloatFormat(2 * kMinFloat, &int16_result);
+ EXPECT_EQ(kMinInt16, int16_result);
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/semi_lockless_fifo.h b/src/3rdparty/resonance-audio/resonance_audio/utils/semi_lockless_fifo.h
new file mode 100644
index 000000000..81950036b
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/semi_lockless_fifo.h
@@ -0,0 +1,232 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_SEMI_LOCKLESS_FIFO_H_
+#define RESONANCE_AUDIO_UTILS_SEMI_LOCKLESS_FIFO_H_
+
+#include <atomic>
+#include <chrono>
+#include <condition_variable>
+#include <mutex>
+#include <vector>
+
+#include "base/logging.h"
+
+namespace vraudio {
+
+// Thread-safe multiple producer - single consumer FIFO queue to share data
+// between threads. The FIFO takes over ownership of the queue elements. Note
+// that |PushBack| calls are synchronized with a mutex and may block. Calls to
+// |PopFront| are lockless and never block.
+//
+// @tparam DataType Object type that the FIFO handles.
+template <typename DataType>
+class SemiLocklessFifo {
+ public:
+ typedef std::chrono::steady_clock::duration ClockDuration;
+
+ SemiLocklessFifo();
+
+ ~SemiLocklessFifo();
+
+ // Takes over ownership of |input| and pushes it to the FIFO queue back.
+ //
+ // @param input Input element to be added to the FIFO queue.
+ void PushBack(DataType&& input);
+
+ // Pops element from FIFO queue front.
+ //
+ // @return Element from FIFO queue front. Must not be called if the queue is
+ // empty.
+ DataType PopFront();
+
+ // Returns true if FIFO queue is empty, false otherwise. This method is *not*
+ // thread-safe and should only be called from the consumer thread.
+ bool Empty() const;
+
+ // Clears the FIFO queue and deletes all its elements. This method is *not*
+ // thread-safe and should only be called from the consumer thread.
+ void Clear();
+
+ // Sleeps until the number of elements in the FIFO queue drop below a target
+ // threshold. This method can be used to synchronize the producer and the
+ // consumer. Sleeping is enabled by default and can be disabled via
+ // |EnableBlockingSleepUntilMethods|.
+ //
+ // @param target_size Target size of FIFO queue.
+ // @param max_wait Maximum waiting period.
+ // @return True if number of FIFO elements is below target size.
+ bool SleepUntilBelowSizeTarget(size_t target_size,
+ const ClockDuration& max_wait);
+
+ // Sleeps until the number of elements in the FIFO queue is greater or equal a
+ // target threshold. This method can be used to synchronize the producer and
+ // the consumer. Sleeping is enabled by default and can be disabled via
+ // |EnableBlockingSleepUntilMethods|.
+ //
+ // @param target_size Target size of FIFO queue.
+ // @param max_wait Maximum waiting period.
+ // @return True if number of FIFO elements is greater or equal the target
+ // size.
+ bool SleepUntilNumElementsInQueue(size_t target_size,
+ const ClockDuration& max_wait);
+
+ // Allows for unblocking |SleepUntil[BelowSizeTarget|NumElementsInQueue]|
+ // method.
+ void EnableBlockingSleepUntilMethods(bool enable);
+
+ private:
+ // Node in single-linked list.
+ struct Node {
+ Node() : next(nullptr) {}
+ std::atomic<Node*> next;
+ DataType data;
+ };
+
+ // Head of linked list.
+ Node* head_;
+
+ // Tail of linked list.
+ Node* tail_;
+
+ // Number of elements.
+ std::atomic<size_t> fifo_size_;
+
+ // Mutex to synchronize |PushBack| calls from multiple threads.
+ std::mutex push_mutex_;
+
+ // Conditional to signal consumption.
+ std::condition_variable pop_conditional_;
+
+ // Mutex to block on until signal consumption occurs.
+ std::mutex pop_conditional_mutex_;
+
+ // Conditional to signal new elements on the FIFO.
+ std::condition_variable push_conditional_;
+
+ // Mutex to block on until new elements have been added to the FIFO.
+ std::mutex push_conditional_mutex_;
+
+ // Flag to enable and disable blocking sleeping calls.
+ std::atomic<bool> enable_sleeping_;
+};
+
+template <typename DataType>
+SemiLocklessFifo<DataType>::SemiLocklessFifo()
+ : fifo_size_(0), enable_sleeping_(true) {
+ head_ = tail_ = new Node();
+}
+
+template <typename DataType>
+SemiLocklessFifo<DataType>::~SemiLocklessFifo() {
+ Clear();
+ DCHECK_EQ(head_, tail_);
+ DCHECK(head_->next.load() == nullptr);
+ delete head_;
+}
+
+template <typename DataType>
+void SemiLocklessFifo<DataType>::PushBack(DataType&& input) {
+ std::lock_guard<std::mutex> lock(push_mutex_);
+ tail_->data = std::move(input);
+ Node* const new_node = new Node();
+ DCHECK(tail_->next.load() == nullptr);
+ tail_->next = new_node;
+ tail_ = new_node;
+ ++fifo_size_;
+
+ {
+ // Taking the lock and dropping it immediately assure that the notify
+ // cannot happen between the check of the predicate and wait of the
+ // |push_conditional_|.
+ std::lock_guard<std::mutex> lock(push_conditional_mutex_);
+ }
+ push_conditional_.notify_all();
+}
+
+template <typename DataType>
+DataType SemiLocklessFifo<DataType>::PopFront() {
+ DCHECK(!Empty());
+
+ Node* const front_node = head_;
+ head_ = front_node->next;
+
+ DataType output = std::move(front_node->data);
+ delete front_node;
+
+ DCHECK_GT(fifo_size_.load(), 0u);
+ --fifo_size_;
+
+ {
+ // Taking the lock and dropping it immediately assure that the notify
+ // cannot happen between the check of the predicate and wait of the
+ // |pop_conditional_|.
+ std::lock_guard<std::mutex> lock(pop_conditional_mutex_);
+ }
+ pop_conditional_.notify_one();
+ return output;
+}
+
+template <typename DataType>
+bool SemiLocklessFifo<DataType>::Empty() const {
+ return fifo_size_.load() == 0;
+}
+
+template <typename DataType>
+void SemiLocklessFifo<DataType>::Clear() {
+ while (!Empty()) {
+ PopFront();
+ }
+ DCHECK_EQ(fifo_size_, 0u);
+}
+
+template <typename DataType>
+bool SemiLocklessFifo<DataType>::SleepUntilBelowSizeTarget(
+ size_t target_size, const ClockDuration& max_wait) {
+ DCHECK_GT(target_size, 0);
+ std::unique_lock<std::mutex> lock(pop_conditional_mutex_);
+ pop_conditional_.wait_for(lock, max_wait, [this, target_size]() {
+ return fifo_size_ < target_size || !enable_sleeping_.load();
+ });
+ return fifo_size_ < target_size;
+}
+
+template <typename DataType>
+bool SemiLocklessFifo<DataType>::SleepUntilNumElementsInQueue(
+ size_t target_size, const ClockDuration& max_wait) {
+ DCHECK_GT(target_size, 0u);
+ std::unique_lock<std::mutex> lock(push_conditional_mutex_);
+ push_conditional_.wait_for(lock, max_wait, [this, target_size]() {
+ return fifo_size_ >= target_size || !enable_sleeping_.load();
+ });
+ return fifo_size_ >= target_size;
+}
+
+template <typename DataType>
+void SemiLocklessFifo<DataType>::EnableBlockingSleepUntilMethods(bool enable) {
+ enable_sleeping_ = enable;
+ // Taking the lock and dropping it immediately assure that the notify
+ // cannot happen between the check of the predicate and wait of the
+ // |pop_conditional_| and |push_conditional_|.
+ { std::lock_guard<std::mutex> lock(pop_conditional_mutex_); }
+ { std::lock_guard<std::mutex> lock(push_conditional_mutex_); }
+ pop_conditional_.notify_one();
+ push_conditional_.notify_one();
+}
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_SEMI_LOCKLESS_FIFO_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor.cc
new file mode 100644
index 000000000..e6d9fe862
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor.cc
@@ -0,0 +1,40 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/sum_and_difference_processor.h"
+
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+
+
+namespace vraudio {
+
+SumAndDifferenceProcessor::SumAndDifferenceProcessor(size_t num_frames)
+ : temp_buffer_(kNumMonoChannels, num_frames) {}
+
+void SumAndDifferenceProcessor::Process(AudioBuffer* stereo_buffer) {
+
+ DCHECK_EQ(stereo_buffer->num_channels(), kNumStereoChannels);
+ AudioBuffer::Channel* temp_channel = &temp_buffer_[0];
+ // channel_1' = channel_1 + channel_2;
+ // channel_2' = channel_1 - channel_2;
+ *temp_channel = (*stereo_buffer)[0];
+ *temp_channel -= (*stereo_buffer)[1];
+ (*stereo_buffer)[0] += (*stereo_buffer)[1];
+ (*stereo_buffer)[1] = *temp_channel;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor.h b/src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor.h
new file mode 100644
index 000000000..76804a9c7
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor.h
@@ -0,0 +1,44 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_SUM_AND_DIFFERENCE_PROCESSOR_H_
+#define RESONANCE_AUDIO_UTILS_SUM_AND_DIFFERENCE_PROCESSOR_H_
+
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Class which converts a 2-channel input audio buffer into its sum and
+// difference signals and stores them in the left and right channel
+// respectively.
+class SumAndDifferenceProcessor {
+ public:
+ // Constructs a stereo sum and difference processor.
+ //
+ // @param num_frames Number of frames in the stereo input audio buffer.
+ explicit SumAndDifferenceProcessor(size_t num_frames);
+
+ // Converts a 2-channel buffer signals into their sum and difference.
+ void Process(AudioBuffer* stereo_buffer);
+
+ private:
+ // Temporary audio buffer to store left channel input data during conversion.
+ AudioBuffer temp_buffer_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_SUM_AND_DIFFERENCE_PROCESSOR_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor_test.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor_test.cc
new file mode 100644
index 000000000..e80acbdb5
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/sum_and_difference_processor_test.cc
@@ -0,0 +1,42 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/sum_and_difference_processor.h"
+
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+
+namespace vraudio {
+
+// Tests Process method.
+TEST(SumAndDifferenceProcessor, TestProcessMethod) {
+ static const std::vector<std::vector<float>> kTestVector = {
+ {0.0f, 1.0f, 2.0f}, {3.0f, 4.0f, 5.0f}};
+
+ AudioBuffer audio_buffer(kTestVector.size(), kTestVector[0].size());
+ audio_buffer = kTestVector;
+
+ SumAndDifferenceProcessor processor(audio_buffer.num_frames());
+ processor.Process(&audio_buffer);
+
+ for (size_t frame = 0; frame < kTestVector[0].size(); ++frame) {
+ EXPECT_EQ(kTestVector[0][frame] + kTestVector[1][frame],
+ audio_buffer[0][frame]);
+ EXPECT_EQ(kTestVector[0][frame] - kTestVector[1][frame],
+ audio_buffer[1][frame]);
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool.cc
new file mode 100644
index 000000000..485e834df
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool.cc
@@ -0,0 +1,249 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/task_thread_pool.h"
+
+#include <thread>
+
+#include "base/integral_types.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+// A simple worker thread wrapper, to be used by TaskThreadPool.
+class TaskThreadPool::WorkerThread {
+ public:
+ // Constructor.
+ //
+ // @param parent_pool The |TaskThreadPool| which owns and manages this
+ // |WorkerThread| instance.
+ WorkerThread()
+ : parent_pool_(), task_closure_(), task_loop_triggered_(false) {}
+
+ // Copy constructor. Necessary for allowing this class to be storied in
+ // std::vector<WorkerThread> container class.
+ //
+ // @param other |WorkerThread| instance this instance will be copied from.
+ WorkerThread(const TaskThreadPool::WorkerThread& other)
+ : parent_pool_(), task_closure_(), task_loop_triggered_(false) {}
+
+ // Destructor.
+ ~WorkerThread();
+
+ // Sets the parent pool for this |WorkerThread|.
+ //
+ // @param parent_pool The |TaskThreadPool| which owns this |WorkerThread|.
+ // @return True indicates that the thread could be started.
+ bool SetParentAndStart(TaskThreadPool* parent_pool);
+
+ // Indicates that the worker thread should run the |TaskClosure| task.
+ //
+ // @param task_closure The task function which |TaskThreadPool| assigns to
+ // this |WorkerThread|.
+ void Run(TaskClosure task_closure);
+
+ // Waits for the |WorkerThread| task loop to exit, for shutdown.
+ void Join();
+
+ // Checks whether this |WorkerThread| is available for a task assignment.
+ bool IsAvailable() const;
+
+ private:
+ // The task loop for this |WorkerThread|. This function will wait for an
+ // assigned task, execute the task, and then reset itself to wait for the next
+ // task.
+ void TaskLoop();
+
+ // This |WorkerThread|'s parent |TaskThreadPool|.
+ TaskThreadPool* parent_pool_;
+
+ // Condition allowing the |TaskThreadPool| to trigger this worker thread to
+ // continue once it has been given a work assignment.
+ std::condition_variable execute_task_condition_;
+
+ // Mutex for receiving |execute_task_condition_| notification.
+ std::mutex execute_task_mutex_;
+
+ // The current task binding which the Worker Thread has been asked to
+ // execute.
+ TaskClosure task_closure_;
+
+ // An atomic boolean to indicate that a task loop trigger has occurred. This
+ // may happen even when a task has not been assigned during shutdown.
+ std::atomic<bool> task_loop_triggered_;
+
+ // The worker thread.
+ std::thread task_thread_;
+};
+
+TaskThreadPool::TaskThreadPool()
+ : num_worker_threads_available_(0),
+ is_pool_running_(false) {}
+
+TaskThreadPool::~TaskThreadPool() { StopThreadPool(); }
+
+bool TaskThreadPool::StartThreadPool(size_t num_worker_threads) {
+ if (is_pool_running_) {
+ return true;
+ }
+ is_pool_running_ = true;
+ worker_threads_.resize(num_worker_threads);
+
+ // Start all worker threads.
+ for (auto& worker_thread : worker_threads_) {
+ bool thread_started = worker_thread.SetParentAndStart(this);
+ if (!thread_started) {
+ StopThreadPool();
+ return false;
+ }
+ }
+
+ // Wait for all worker threads to be launched.
+ std::unique_lock<std::mutex> worker_lock(worker_available_mutex_);
+ worker_available_condition_.wait(worker_lock, [this, num_worker_threads]() {
+ return !is_pool_running_.load() || num_worker_threads_available_.load() ==
+ static_cast<int>(num_worker_threads);
+ });
+
+ return true;
+}
+
+void TaskThreadPool::StopThreadPool() {
+ if (!is_pool_running_) {
+ return;
+ }
+ // Shut down all active worker threads.
+ {
+ std::lock_guard<std::mutex> worker_lock(worker_available_mutex_);
+ is_pool_running_ = false;
+ }
+ worker_available_condition_.notify_one();
+
+ // Join and destruct workers.
+ worker_threads_.resize(0);
+}
+
+bool TaskThreadPool::WaitUntilWorkerBecomesAvailable() {
+ if (!is_pool_running_.load()) {
+ return false;
+ }
+ if (num_worker_threads_available_.load() > 0) {
+ return true;
+ }
+ std::unique_lock<std::mutex> worker_lock(worker_available_mutex_);
+ worker_available_condition_.wait(worker_lock, [this]() {
+ return (num_worker_threads_available_.load() > 0) ||
+ !is_pool_running_.load();
+ });
+ return num_worker_threads_available_.load() > 0 && is_pool_running_.load();
+}
+
+bool TaskThreadPool::RunOnWorkerThread(TaskThreadPool::TaskClosure closure) {
+ if (!is_pool_running_.load() || num_worker_threads_available_.load() == 0) {
+ return false;
+ }
+ // Find the first available worker thread.
+ WorkerThread* available_worker_thread = nullptr;
+ for (auto& worker_thread : worker_threads_) {
+ if (worker_thread.IsAvailable()) {
+ available_worker_thread = &worker_thread;
+ break;
+ }
+ }
+ DCHECK(available_worker_thread);
+ {
+ std::lock_guard<std::mutex> lock(worker_available_mutex_);
+ --num_worker_threads_available_;
+ }
+ available_worker_thread->Run(std::move(closure));
+ return true;
+}
+
+size_t TaskThreadPool::GetAvailableTaskThreadCount() const {
+ return num_worker_threads_available_.load();
+}
+
+bool TaskThreadPool::IsPoolRunning() { return is_pool_running_.load(); }
+
+void TaskThreadPool::SignalWorkerAvailable() {
+ {
+ std::lock_guard<std::mutex> lock(worker_available_mutex_);
+ ++num_worker_threads_available_;
+ }
+ worker_available_condition_.notify_one();
+}
+
+TaskThreadPool::WorkerThread::~WorkerThread() { Join(); }
+
+bool TaskThreadPool::WorkerThread::SetParentAndStart(
+ TaskThreadPool* parent_pool) {
+ parent_pool_ = parent_pool;
+
+ // Start the worker thread.
+ task_thread_ = std::thread(std::bind(&WorkerThread::TaskLoop, this));
+ return true;
+}
+
+void TaskThreadPool::WorkerThread::Run(TaskThreadPool::TaskClosure closure) {
+ if (closure) {
+ task_closure_ = std::move(closure);
+ {
+ std::lock_guard<std::mutex> lock(execute_task_mutex_);
+ task_loop_triggered_ = true;
+ }
+ execute_task_condition_.notify_one();
+ }
+}
+
+void TaskThreadPool::WorkerThread::Join() {
+ DCHECK(!parent_pool_->IsPoolRunning());
+ // Aquire and release lock to assure that the notify cannot happen between the
+ // check of the predicate and wait of the |push_conditional_|.
+ { std::lock_guard<std::mutex> lock(execute_task_mutex_); }
+ execute_task_condition_.notify_one();
+ if (task_thread_.joinable()) {
+ task_thread_.join();
+ }
+}
+
+bool TaskThreadPool::WorkerThread::IsAvailable() const {
+ return !task_loop_triggered_.load();
+}
+
+void TaskThreadPool::WorkerThread::TaskLoop() {
+ // Signal back to the parent thread pool that this thread has started and is
+ // ready for use.
+ task_loop_triggered_ = false;
+
+ while (parent_pool_->IsPoolRunning() || task_closure_ != nullptr) {
+ parent_pool_->SignalWorkerAvailable();
+ std::unique_lock<std::mutex> task_lock(execute_task_mutex_);
+ execute_task_condition_.wait(task_lock, [this]() {
+ return task_loop_triggered_.load() || !parent_pool_->IsPoolRunning();
+ });
+
+ // Execute the assigned task.
+ if (task_closure_ != nullptr) {
+ task_closure_();
+
+ // Clear the assigned task and return to ready state.
+ task_closure_ = nullptr;
+ }
+ task_loop_triggered_ = false;
+ }
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool.h b/src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool.h
new file mode 100644
index 000000000..e9db083f9
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool.h
@@ -0,0 +1,121 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_TASK_THREAD_POOL_H_
+#define RESONANCE_AUDIO_UTILS_TASK_THREAD_POOL_H_
+
+#include <atomic>
+#include <chrono>
+#include <condition_variable>
+#include <functional>
+#include <mutex>
+#include <vector>
+
+namespace vraudio {
+
+class TaskThreadPool;
+
+// A very basic thread pool for launching discrete encapsulated task functions
+// on a configurable number of task threads. Note that this pool expects tasks
+// to complete their work with no management by the pool itself. Any means of
+// managing or terminating tasks must be designed into the task contexts and
+// managed externally in a thread-safe way.
+class TaskThreadPool {
+ friend class WorkerThread;
+
+ public:
+ // Type definition for task function which may be assigned to a |WorkerThread|
+ // in this pool. Note that tasks should be self-contained and not require
+ // communication with other tasks.
+ typedef std::function<void()> TaskClosure;
+
+ // Constructor.
+ //
+ TaskThreadPool();
+
+ ~TaskThreadPool();
+
+ // Creates and initializes thread pool. This method blocks until all threads
+ // are loaded and initialized.
+ //
+ // @param num_worker_threads The number of worker threads to make available in
+ // the pool.
+ // @return true on success or if thread pool has been already started.
+ bool StartThreadPool(size_t num_worker_threads);
+
+ // Signals all |WorkerThread|s to stop and waits for completion.
+ void StopThreadPool();
+
+ // Waits until a |WorkerThread| becomes available. It is assumed that only a
+ // single thread will dispatch threads using this function, and therefore this
+ // function should not itself be considered thread safe.
+ //
+ // @return True if a |WorkerThread| is available.
+ bool WaitUntilWorkerBecomesAvailable();
+
+ // Executes a |TaskClosure| on a |WorkerThread|. It is assumed that only a
+ // signal thread will dispatch threads using this function, and therefore this
+ // function should not itself be considered thread safe.
+ //
+ // @param closure The client task which will begin execution if and when this
+ // function returns True.
+ // @return True if a |WorkerThread| is allocated to execute the closure
+ // function, false if no |WorkerThread| is available.
+ bool RunOnWorkerThread(TaskClosure closure);
+
+ // Query the number of |WorkerThread|s current available to do work.
+ size_t GetAvailableTaskThreadCount() const;
+
+ private:
+ // Forward declaration of |WorkerThread| class. See implementation file for
+ // class details.
+ class WorkerThread;
+
+ // Query whether the |TaskThreadPool| is active.
+ //
+ // @return True if the pool is still running.
+ bool IsPoolRunning();
+
+ // Signals to thread pool that a worker thread has become available for
+ // task assignment.
+ void SignalWorkerAvailable();
+
+ // Closure reusable task loop to be executed by each |WorkerThread|.
+ void WorkerLoopFunction();
+
+ // Task Loop executed by each worker thread.
+ void WorkerThreadLoop();
+
+ // Number of worker threads currently available to execute tasks.
+ std::atomic<int> num_worker_threads_available_;
+
+ // Control of all worker thread loops.
+ std::atomic<bool> is_pool_running_;
+
+ // Container of available worker threads, waiting to be used.
+
+ std::vector<WorkerThread> worker_threads_;
+
+ // Condition to indicate that a worker thread has become available.
+ std::condition_variable worker_available_condition_;
+
+ // Mutex for the worker thread available condition notification receiver.
+ std::mutex worker_available_mutex_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_TASK_THREAD_POOL_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool_test.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool_test.cc
new file mode 100644
index 000000000..61e83f2d9
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/task_thread_pool_test.cc
@@ -0,0 +1,185 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include <atomic>
+#include <chrono>
+#include <mutex>
+#include <thread>
+#include <vector>
+
+#include "base/integral_types.h"
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/logging.h"
+#include "utils/task_thread_pool.h"
+
+namespace vraudio {
+
+namespace {
+
+// The number of simultaneous worker threads to run for these tests.
+const size_t kNumberOfThreads = 5;
+
+// An extremely large number of worker threads to use when attempting to shut
+// down the |TaskThreadPool| while it is still being initialized.
+const size_t kHugeThreadCount = 64;
+
+// An arbitrary numeric value to set when testing worker threads.
+const int kModifiedValue = 113;
+
+// A limited number of iterations to perform when testing worker threads which
+// do continuous work over time.
+const size_t kNumberOfIncrementOperations = 50;
+
+// The number of times to repeat test loops in functions to insure reuse of
+// worker threads.
+const size_t kNumTestLoops = 3;
+
+class TaskThreadPoolTest : public ::testing::Test {
+ protected:
+ TaskThreadPoolTest() {}
+ ~TaskThreadPoolTest() override {}
+
+ void SetUp() override { modified_values_.resize(kNumberOfThreads, 0); }
+
+ public:
+ // Helper worker task to asynchronously set values in worker threads.
+ void ModifyValue(int* value_to_set) {
+ std::lock_guard<std::mutex> worker_lock(modification_mutex_);
+ EXPECT_NE(value_to_set, nullptr);
+ *value_to_set = kModifiedValue;
+ }
+
+ // Helper worker task to asynchronously increment modified values over time
+ // with enough interior delay to measure results.
+ void IncrementValue(int* value_to_increment) {
+ EXPECT_NE(value_to_increment, nullptr);
+ for (size_t i = 0; i < kNumberOfIncrementOperations; ++i) {
+ // Sleep briefly so this doesn't finish too quickly.
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ std::lock_guard<std::mutex> worker_lock(modification_mutex_);
+ *value_to_increment += 1;
+ }
+ }
+
+ protected:
+ // Vector of numbers used for testing asynchronous threading results.
+ std::vector<int> modified_values_;
+
+ // A mutex for protecting modified_values_ from tsan (Thread Sanitizer)
+ // failures.
+ std::mutex modification_mutex_;
+};
+
+// This test verifies that TaskThreadPool actually executes tasks.
+TEST_F(TaskThreadPoolTest, SetValuesInWorkerThreads) {
+ TaskThreadPool thread_pool;
+ EXPECT_TRUE(thread_pool.StartThreadPool(kNumberOfThreads));
+
+ // Run this several times to insure that worker threads can be reused.
+ for (size_t loop = 0; loop < kNumTestLoops; ++loop) {
+ // Verify that all worker threads are available again.
+ EXPECT_EQ(thread_pool.GetAvailableTaskThreadCount(), kNumberOfThreads);
+
+ for (size_t i = 0; i < kNumberOfThreads; ++i) {
+ modified_values_[i] = 0;
+ const bool task_available = thread_pool.WaitUntilWorkerBecomesAvailable();
+ EXPECT_TRUE(task_available);
+ const bool task_submitted = thread_pool.RunOnWorkerThread(
+ std::bind(&vraudio::TaskThreadPoolTest::ModifyValue, this,
+ &modified_values_[i]));
+ EXPECT_TRUE(task_submitted);
+ }
+
+ // Wait until all threads become available again (trying to time their
+ // completion seems to cause flakey tests).
+ while (thread_pool.GetAvailableTaskThreadCount() < kNumberOfThreads) {
+ // Wait briefly to allow tasks to execute.
+ std::this_thread::sleep_for(std::chrono::milliseconds(5));
+ }
+
+ // Check results.
+ for (size_t i = 0; i < kNumberOfThreads; ++i) {
+ std::lock_guard<std::mutex> worker_lock(modification_mutex_);
+ EXPECT_EQ(modified_values_[i], kModifiedValue);
+ }
+ }
+}
+
+// This test verifies that the |TaskThreadPool| cannot be shut down until all of
+// its worker threads are brought to a ready state.
+TEST_F(TaskThreadPoolTest, VerifyRapidShutdownWithLargeThreadCount) {
+ TaskThreadPool thread_pool;
+ EXPECT_TRUE(thread_pool.StartThreadPool(kHugeThreadCount));
+}
+
+// This test verifies the timeout features of assigning worker threads, as well
+// as the continuous asynchronous operation of threads..
+TEST_F(TaskThreadPoolTest, VerifyTimeoutsAndContinuousOperation) {
+ // Preset |modified_values_| to known state.
+ for (size_t i = 0; i < kNumberOfThreads; ++i) {
+ modified_values_[i] = 0;
+ }
+
+ {
+ TaskThreadPool thread_pool;
+ EXPECT_TRUE(thread_pool.StartThreadPool(kNumberOfThreads));
+
+ // Verify that all worker threads are available again.
+ EXPECT_EQ(thread_pool.GetAvailableTaskThreadCount(), kNumberOfThreads);
+
+ for (size_t i = 0; i < kNumberOfThreads; ++i) {
+ modified_values_[i] = 0;
+ const bool task_available = thread_pool.WaitUntilWorkerBecomesAvailable();
+ EXPECT_TRUE(task_available);
+ const bool task_submitted = thread_pool.RunOnWorkerThread(
+ std::bind(&vraudio::TaskThreadPoolTest::IncrementValue, this,
+ &modified_values_[i]));
+ EXPECT_TRUE(task_submitted);
+ }
+
+ // Verify that all worker threads are available again.
+ EXPECT_EQ(thread_pool.GetAvailableTaskThreadCount(), 0U);
+
+ // Trying to add one more task should fail.
+ int extra_modified;
+ EXPECT_FALSE(thread_pool.RunOnWorkerThread(std::bind(
+ &vraudio::TaskThreadPoolTest::IncrementValue, this, &extra_modified)));
+
+ // Wait briefly to allow tasks to execute.
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+
+ // Verify that all of the tasks are still doing some work.
+ for (size_t i = 0; i < kNumberOfThreads; ++i) {
+ std::lock_guard<std::mutex> worker_lock(modification_mutex_);
+ EXPECT_GT(modified_values_[i], 0);
+ }
+ }
+ // To verify that all threads are shut down correctly, record the
+ // |modified_values_|, wait briefly, and then make sure theyΩ have not
+ // changed.
+ std::vector<int> copy_of_modified_values = modified_values_;
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
+ for (size_t i = 0; i < kNumberOfThreads; ++i) {
+ // NOTE: modification_mutex_ is intentionally not used for this block so
+ // that any race conditions might be caught if for some reason the worker
+ // threads have not yet shut down.
+ EXPECT_EQ(copy_of_modified_values[i], modified_values_[i]);
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/test_util.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/test_util.cc
new file mode 100644
index 000000000..4912ab8cb
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/test_util.cc
@@ -0,0 +1,190 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/test_util.h"
+
+#include <algorithm>
+#include <cmath>
+#include <string>
+
+#include "third_party/googletest/googlemock/include/gmock/gmock.h"
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/logging.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+namespace {
+
+using ::testing::NotNull;
+
+} // namespace
+
+void GenerateSilence(AudioBuffer::Channel* output) {
+ ASSERT_THAT(output, ::testing::NotNull());
+ output->Clear();
+}
+
+void GenerateSineWave(float frequency_hz, int sample_rate,
+ AudioBuffer::Channel* output) {
+ ASSERT_GE(frequency_hz, 0.0f);
+ ASSERT_GT(sample_rate, 0);
+ ASSERT_THAT(output, ::testing::NotNull());
+
+ for (size_t i = 0; i < output->size(); ++i) {
+ const float phase = static_cast<float>(i) * kTwoPi /
+ static_cast<float>(sample_rate) * frequency_hz;
+ (*output)[i] = std::sin(phase);
+ }
+}
+
+void GenerateSawToothSignal(size_t tooth_length_samples,
+ AudioBuffer::Channel* output) {
+ ASSERT_GT(tooth_length_samples, 0U);
+ ASSERT_THAT(output, ::testing::NotNull());
+ for (size_t i = 0; i < output->size(); ++i) {
+ (*output)[i] = static_cast<float>(i % tooth_length_samples) /
+ static_cast<float>(tooth_length_samples) * 2.0f -
+ 1.0f;
+ }
+}
+
+void GenerateDiracImpulseFilter(size_t delay_samples,
+ AudioBuffer::Channel* output) {
+ ASSERT_THAT(output, ::testing::NotNull());
+ ASSERT_LT(delay_samples, output->size());
+ ASSERT_THAT(output, ::testing::NotNull());
+ output->Clear();
+ (*output)[delay_samples] = 1.0f;
+}
+
+void GenerateIncreasingSignal(AudioBuffer::Channel* output) {
+ ASSERT_THAT(output, ::testing::NotNull());
+ for (size_t i = 0; i < output->size(); ++i) {
+ (*output)[i] =
+ static_cast<float>(i) / static_cast<float>(output->size()) * 2.0f -
+ 1.0f;
+ }
+}
+
+size_t ZeroCompare(const AudioBuffer::Channel& signal, float epsilon) {
+ for (size_t i = 0; i < signal.size(); ++i) {
+ if (std::abs(signal[i]) > epsilon) {
+ return i;
+ }
+ }
+ return signal.size();
+}
+
+bool CompareAudioBuffers(const AudioBuffer::Channel& buffer_a,
+ const AudioBuffer::Channel& buffer_b, float epsilon) {
+ if (buffer_a.size() != buffer_b.size()) {
+ return false;
+ }
+ for (size_t i = 0; i < buffer_a.size(); ++i) {
+ if (std::abs(buffer_a[i] - buffer_b[i]) > epsilon) {
+ return false;
+ }
+ }
+ return true;
+}
+
+size_t DelayCompare(const AudioBuffer::Channel& original_signal,
+ const AudioBuffer::Channel& delayed_signal, size_t delay,
+ float epsilon) {
+ if (delay > delayed_signal.size() ||
+ (delayed_signal.size() > original_signal.size() + delay)) {
+ return 0;
+ }
+ for (size_t i = delay; i < delayed_signal.size(); ++i) {
+ const size_t original_index = i - delay;
+ const float difference =
+ std::abs(delayed_signal[i] - original_signal[original_index]);
+ if (difference > epsilon) {
+ return i;
+ }
+ }
+ return delayed_signal.size();
+}
+
+bool TestZeroPaddedDelay(const AudioBuffer::Channel& original_signal,
+ const AudioBuffer::Channel& delayed_signal,
+ size_t delay_samples, float epsilon) {
+ size_t temp = ZeroCompare(delayed_signal, epsilon);
+ if (delay_samples != temp) {
+ return false;
+ }
+ temp = DelayCompare(original_signal, delayed_signal, delay_samples, epsilon);
+ if (original_signal.size() != temp) {
+ return false;
+ }
+ return true;
+}
+
+double CalculateSignalPeak(const AudioBuffer::Channel& channel) {
+ double peak = 0.0;
+ for (const float& sample : channel) {
+ if (std::abs(sample) > peak) peak = std::abs(sample);
+ }
+
+ DCHECK_GT(channel.size(), 0);
+ return peak;
+}
+
+double CalculateSignalEnergy(const AudioBuffer::Channel& channel) {
+ double energy = 0.0;
+ for (const float& sample : channel) {
+ energy += sample * sample;
+ }
+ return energy;
+}
+
+double CalculateSignalRms(const AudioBuffer::Channel& channel) {
+ const double energy = CalculateSignalEnergy(channel);
+ DCHECK_GT(channel.size(), 0);
+ return std::sqrt(energy / static_cast<double>(channel.size()));
+}
+
+double DbFromMagnitude(double magnitude) {
+ DCHECK_GT(magnitude, 0.0);
+ const double decibel = 20.0 * std::log10(magnitude);
+ return decibel;
+}
+
+double DbFromPower(double power) {
+ DCHECK_GT(power, 0.0);
+ const double decibel = 10.0 * std::log10(power);
+ return decibel;
+}
+
+float MaxCrossCorrelation(const AudioBuffer::Channel& signal_a,
+ const AudioBuffer::Channel& signal_b) {
+ CHECK_EQ(signal_a.size(), signal_b.size());
+ float output = 0.0f;
+ const size_t length = signal_a.size();
+ for (size_t i = 0; i < length; ++i) {
+ float current = 0.0f;
+ for (size_t j = 0; j < length - i - 1; ++j) {
+ current += signal_a[j + i] * signal_b[j];
+ }
+ output = std::max(output, current);
+ }
+ return output;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/test_util.h b/src/3rdparty/resonance-audio/resonance_audio/utils/test_util.h
new file mode 100644
index 000000000..3ce9db5d2
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/test_util.h
@@ -0,0 +1,91 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_TEST_UTIL_H_
+#define RESONANCE_AUDIO_UTILS_TEST_UTIL_H_
+
+#include <cstddef>
+#include <vector>
+
+#include "base/integral_types.h"
+#include "base/audio_buffer.h"
+
+namespace vraudio {
+
+// Silences an audio channel.
+void GenerateSilence(AudioBuffer::Channel* output);
+
+// Generates a sine wave at the specified frequency in hertz at the given
+// sampling rate in hertz.
+void GenerateSineWave(float frequency_hz, int sample_rate,
+ AudioBuffer::Channel* output);
+
+// Generates a saw tooth signal between -1 and 1 for the given wave form length.
+void GenerateSawToothSignal(size_t tooth_length_samples,
+ AudioBuffer::Channel* output);
+
+// Generates a Dirac impulse filter kernel, which delays filtered signals by
+// the given delay.
+void GenerateDiracImpulseFilter(size_t delay_samples,
+ AudioBuffer::Channel* output);
+
+// Generates a linear ramp signal between -1 and 1.
+void GenerateIncreasingSignal(AudioBuffer::Channel* output);
+
+// Returns the index of the first non-zero element.
+size_t ZeroCompare(const AudioBuffer::Channel& signal, float epsilon);
+
+// Compares the content of two audio channels. Returns true if the absolute
+// difference between all samples is below epsion.
+bool CompareAudioBuffers(const AudioBuffer::Channel& buffer_a,
+ const AudioBuffer::Channel& buffer_b, float epsilon);
+
+// Returns delayed_signal.size() in output if delayed_signal is approximately
+// equal to original_signal delayed by the given amount; otherwise, returns the
+// index of the first unequal element in delayed_signal.
+size_t DelayCompare(const AudioBuffer::Channel& original_signal,
+ const AudioBuffer::Channel& delayed_signal, size_t delay,
+ float epsilon);
+
+// Test if two signals are shifted by a fixed number of samples with zero
+// padding.
+bool TestZeroPaddedDelay(const AudioBuffer::Channel& original_signal,
+ const AudioBuffer::Channel& delayed_signal,
+ size_t delay_samples, float epsilon);
+
+// Returns absolute peak amplitude of a signal.
+double CalculateSignalPeak(const AudioBuffer::Channel& channel);
+
+// Returns energy of a signal.
+double CalculateSignalEnergy(const AudioBuffer::Channel& channel);
+
+// Returns Root Mean Square (RMS) of a signal.
+double CalculateSignalRms(const AudioBuffer::Channel& channel);
+
+// Expresses a magnitude measurement in dB.
+double DbFromMagnitude(double magnitude);
+
+// Expresses a power measurement in dB.
+double DbFromPower(double power);
+
+// Returns the maximum cross correlation value between two signals.
+// To be used only with signals of the same length.
+float MaxCrossCorrelation(const AudioBuffer::Channel& signal_a,
+ const AudioBuffer::Channel& signal_b);
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_TEST_UTIL_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/test_util_test.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/test_util_test.cc
new file mode 100644
index 000000000..e92f55632
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/test_util_test.cc
@@ -0,0 +1,249 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/test_util.h"
+
+#include <cmath>
+#include <string>
+
+#include "third_party/googletest/googlemock/include/gmock/gmock.h"
+#include "third_party/googletest/googletest/include/gtest/gtest.h"
+#include "base/audio_buffer.h"
+#include "base/constants_and_types.h"
+#include "base/misc_math.h"
+
+namespace vraudio {
+
+namespace {
+
+TEST(TestUtilTest, GenerateSineWave_SuccessfulGeneration) {
+ const size_t kLengthStart = 1;
+ const size_t kLengthStop = 200;
+ const size_t kLengthStep = 10;
+ for (size_t length = kLengthStart; length <= kLengthStop;
+ length += kLengthStep) {
+ const float kFrequencyStart = 0.0f;
+ const float kFrequencyStop = 2000.0f;
+ const float kFrequencyStep = 100.0f;
+ for (float frequency = kFrequencyStart; frequency <= kFrequencyStop;
+ frequency += kFrequencyStep) {
+ const int kSampleRate = 2000;
+ AudioBuffer expected_signal(1, length);
+ AudioBuffer::Channel& expected_signal_view = expected_signal[0];
+ for (size_t i = 0; i < length; i++) {
+ const float phase = static_cast<float>(i) * 2.0f *
+ static_cast<float>(M_PI) / kSampleRate * frequency;
+ const float expected_value_float = std::sin(phase);
+ expected_signal_view[i] = expected_value_float;
+ }
+
+ AudioBuffer sine_wave(1U, length);
+ GenerateSineWave(frequency, kSampleRate, &sine_wave[0]);
+ EXPECT_TRUE(CompareAudioBuffers(sine_wave[0], expected_signal_view,
+ kEpsilonFloat));
+ }
+ }
+}
+
+TEST(TestUtilTest, GenerateSawToothSignal_SuccessfulGeneration) {
+ const size_t kLengthStart = 1;
+ const size_t kLengthStop = 200;
+ const size_t kLengthStep = 10;
+ for (size_t length = kLengthStart; length <= kLengthStop;
+ length += kLengthStep) {
+ const size_t kToothLengthStart = 1;
+ const size_t kToothLengthStop = 20;
+ const size_t kToothLengthStep = 3;
+ for (size_t tooth_length = kToothLengthStart;
+ tooth_length <= kToothLengthStop; tooth_length += kToothLengthStep) {
+ AudioBuffer expected_signal(1, length);
+ AudioBuffer::Channel& expected_signal_view = expected_signal[0];
+ for (size_t i = 0; i < length; i++) {
+ const float expected_value = static_cast<float>(i % tooth_length) /
+ static_cast<float>(tooth_length) *
+ 2.0f -
+ 1.0f;
+ expected_signal_view[i] = expected_value;
+ }
+
+ AudioBuffer signal(1, length);
+ GenerateSawToothSignal(tooth_length, &signal[0]);
+ EXPECT_TRUE(
+ CompareAudioBuffers(signal[0], expected_signal_view, kEpsilonFloat));
+ }
+ }
+}
+
+TEST(TestUtilTest, GenerateDiracImpulseFilterFloat_SuccessfulGeneration) {
+ const size_t kLengthStart = 1;
+ const size_t kLengthStop = 100;
+ const size_t kLengthStep = 10;
+ for (size_t length = kLengthStart; length <= kLengthStop;
+ length += kLengthStep) {
+ const size_t kDelayStart = 1;
+ const size_t kDelayStop = length - 1;
+ const size_t kDelayStep = 3;
+ for (size_t delay = kDelayStart; delay <= kDelayStop; delay += kDelayStep) {
+ AudioBuffer expected_signal(1, length);
+ GenerateSilence(&expected_signal[0]);
+ expected_signal[0][delay] = 1.0f;
+
+ AudioBuffer dirac_buffer(1, length);
+ GenerateDiracImpulseFilter(delay, &dirac_buffer[0]);
+ EXPECT_TRUE(CompareAudioBuffers(dirac_buffer[0], expected_signal[0],
+ kEpsilonFloat));
+ }
+ }
+}
+
+TEST(TestUtilTest, GenerateIncreasingSignal_SuccessfulGeneration) {
+ const size_t kLengthStart = 1;
+ const size_t kLengthStop = 200;
+ const size_t kLengthStep = 10;
+ for (size_t length = kLengthStart; length <= kLengthStop;
+ length += kLengthStep) {
+ AudioBuffer expected_signal(1, length);
+ AudioBuffer::Channel& expected_signal_view = expected_signal[0];
+ for (size_t i = 0; i < length; i++) {
+ const float expected_value =
+ static_cast<float>(i) / static_cast<float>(length) * 2.0f - 1.0f;
+ expected_signal_view[i] = expected_value;
+ }
+
+ AudioBuffer signal(1, length);
+ GenerateIncreasingSignal(&signal[0]);
+ EXPECT_TRUE(
+ CompareAudioBuffers(signal[0], expected_signal[0], kEpsilonFloat));
+ }
+}
+
+TEST(TestUtilTest, ZeroCompare_SuccessfulZeroSignal) {
+ const size_t kLengthStart = 1;
+ const size_t kLengthStop = 100;
+ const size_t kLengthStep = 10;
+ for (size_t length = kLengthStart; length <= kLengthStop;
+ length += kLengthStep) {
+ const size_t kZeroLengthStart = 0;
+ const size_t kZeroLengthStop = length - 1;
+ const size_t kZeroLengthStep = 3;
+ for (size_t zero_length = kZeroLengthStart; zero_length <= kZeroLengthStop;
+ zero_length += kZeroLengthStep) {
+ AudioBuffer signal(1, length);
+ AudioBuffer::Channel& signal_view = signal[0];
+ GenerateSilence(&signal_view);
+ for (size_t i = zero_length; i < length; i++) {
+ signal_view[i] = 123.0f * static_cast<float>(i) + 1.0f;
+ }
+ const size_t result = ZeroCompare(signal_view, kEpsilonFloat);
+ EXPECT_EQ(zero_length, result);
+ }
+ }
+}
+
+TEST(TestUtilTest, ZeroCompare_SuccessfulNonzeroSignal) {
+ const size_t kLengthStart = 1;
+ const size_t kLengthStop = 100;
+ const size_t kLengthStep = 10;
+ for (size_t length = kLengthStart; length <= kLengthStop;
+ length += kLengthStep) {
+ const size_t kZeroLengthStart = 1;
+ const size_t kZeroLengthStop = length - 1;
+ const size_t kZeroLengthStep = 3;
+ for (size_t zero_length = kZeroLengthStart; zero_length <= kZeroLengthStop;
+ zero_length += kZeroLengthStep) {
+ AudioBuffer signal(1, length);
+ AudioBuffer::Channel& signal_view = signal[0];
+ std::fill(signal_view.begin(), signal_view.end(), 100.0f);
+ for (size_t i = 0; i < zero_length - 1; i++) {
+ signal_view[i] = 0.0f;
+ const size_t result = ZeroCompare(signal_view, kEpsilonFloat);
+ EXPECT_NE(zero_length, result);
+ }
+ }
+ }
+}
+
+TEST(TestUtilTest, DelayCompare_SuccessfulEqualDelay) {
+ const size_t kLengthStart = 1;
+ const size_t kLengthStop = 100;
+ const size_t kLengthStep = 10;
+ for (size_t length = kLengthStart; length <= kLengthStop;
+ length += kLengthStep) {
+ AudioBuffer original_signal(1, length);
+ AudioBuffer::Channel& original_signal_view = original_signal[0];
+
+ GenerateIncreasingSignal(&original_signal_view);
+
+ const size_t kDelayStart = 0;
+ const size_t kDelayStop = length - 1;
+ const size_t kDelayStep = 3;
+ for (size_t delay = kDelayStart; delay <= kDelayStop; delay += kDelayStep) {
+ AudioBuffer delayed_signal(1, length + delay);
+ AudioBuffer::Channel& delayed_signal_view = delayed_signal[0];
+ GenerateSilence(&delayed_signal_view);
+ std::copy(original_signal_view.begin(), original_signal_view.end(),
+ delayed_signal_view.begin() + delay);
+ const size_t result = DelayCompare(
+ original_signal_view, delayed_signal_view, delay, kEpsilonFloat);
+ EXPECT_EQ(delayed_signal_view.size(), result);
+ }
+ }
+}
+
+TEST(TestUtilTest, DelayCompare_SuccessfulNotEqualDelay) {
+ const size_t kLengthStart = 1;
+ const size_t kLengthStop = 20;
+ const size_t kLengthStep = 10;
+ for (size_t length = kLengthStart; length <= kLengthStop;
+ length += kLengthStep) {
+ AudioBuffer original_signal(1, length);
+ AudioBuffer::Channel& original_signal_view = original_signal[0];
+
+ GenerateIncreasingSignal(&original_signal_view);
+
+ const size_t kDelayStart = 1;
+ const size_t kDelayStop = length - 1;
+ const size_t kDelayStep = 3;
+ for (size_t delay = kDelayStart; delay <= kDelayStop; delay += kDelayStep) {
+ // Test altering first delayed element.
+ {
+ AudioBuffer delayed_signal(1, length + delay);
+ AudioBuffer::Channel& delayed_signal_view = delayed_signal[0];
+ std::copy(original_signal_view.begin(), original_signal_view.end(),
+ delayed_signal_view.begin() + delay);
+ delayed_signal_view[delay] = -100.0f;
+ const size_t result = DelayCompare(
+ original_signal_view, delayed_signal_view, delay, kEpsilonFloat);
+ EXPECT_NE(delayed_signal_view.size(), result);
+ }
+ // Test altering last delayed element.
+ {
+ AudioBuffer delayed_signal(1, length + delay);
+ AudioBuffer::Channel& delayed_signal_view = delayed_signal[0];
+ std::copy(original_signal_view.begin(), original_signal_view.end(),
+ delayed_signal_view.begin() + delay);
+ delayed_signal_view[delayed_signal_view.size() - 1] = -100.0f;
+ const size_t result = DelayCompare(
+ original_signal_view, delayed_signal_view, delay, kEpsilonFloat);
+ EXPECT_NE(delayed_signal_view.size(), result);
+ }
+ }
+ }
+}
+
+} // namespace
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/threadsafe_fifo.h b/src/3rdparty/resonance-audio/resonance_audio/utils/threadsafe_fifo.h
new file mode 100644
index 000000000..a8c863714
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/threadsafe_fifo.h
@@ -0,0 +1,258 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_THREADSAFE_FIFO_H_
+#define RESONANCE_AUDIO_UTILS_THREADSAFE_FIFO_H_
+
+#include <atomic>
+#include <chrono>
+#include <condition_variable>
+#include <memory>
+#include <mutex>
+#include <thread>
+#include <vector>
+
+#include "base/logging.h"
+
+namespace vraudio {
+
+// Container to share preallocated data between threads. It is thread-safe for
+// single producer - single consumer FIFO usage.
+//
+// @tparam T Object type that the FIFO handles.
+template <typename T>
+class ThreadsafeFifo {
+ public:
+ // Constructor preallocates the maximum number of objects in the FIFO queue
+ // and defines the maximum waiting period before triggering a buffer underflow
+ // or overflow event. Sleeping is enabled by default and can be disabled via
+ // |EnableBlockingSleepUntilMethods|.
+ //
+ // @param max_objects Maximum number of objects in FIFO queue.
+ explicit ThreadsafeFifo(size_t max_objects);
+
+ // Constructor preallocates the maximum number of objects in the FIFO queue.
+ // Sleeping is enabled by default and can be disabled via
+ // |EnableBlockingSleepUntilMethods|.
+ //
+ // @param max_objects Maximum number of objects in FIFO queue.
+ // @param init Initializer to be assigned to allocated objects.
+ ThreadsafeFifo(size_t max_objects, const T& init);
+
+ // Returns a pointer to an available input object T. If the queue is full, a
+ // nullptr is returned.
+ //
+ // @return Pointer to an available input object. Nullptr if no input object is
+ // available.
+ T* AcquireInputObject();
+
+ // Releases a previously acquired input object to be pushed onto the FIFO
+ // front.
+ void ReleaseInputObject(const T* object);
+
+ // Returns a pointer to an output object T. If the queue is empty, a nullptr
+ // is returned.
+ //
+ // @return Pointer to the output object. Nullptr on empty queue.
+ T* AcquireOutputObject();
+
+ // Releases a previously acquired output object back to the FIFO.
+ void ReleaseOutputObject(const T* object);
+
+ // Blocks until the FIFO queue has an input object available or
+ // |EnableBlockingSleepUntilMethods(false)| is called.
+ //
+ // Returns true if free slot is available.
+ bool SleepUntilInputObjectIsAvailable() const;
+
+ // Blocks until the FIFO queue has an output object available or
+ // |EnableBlockingSleepUntilMethods(false)| is called.
+ //
+ // Returns true if an object is available.
+ bool SleepUntilOutputObjectIsAvailable() const;
+
+ // Allows for unblocking |SleepUntil[Input|Output]ObjectIsAvailable|
+ // method.
+ void EnableBlockingSleepUntilMethods(bool enable);
+
+ // Returns the number of objects in the FIFO queue.
+ size_t Size() const;
+
+ // Returns true if FIFO queue is empty, false otherwise.
+ bool Empty() const;
+
+ // Returns true if FIFO queue is full, false otherwise.
+ bool Full() const;
+
+ // Clears the FIFO queue. This call is only thread-safe if called by the
+ // consumer.
+ void Clear();
+
+ private:
+ // Conditional to signal empty/full queue events.
+ mutable std::mutex fifo_empty_mutex_;
+ mutable std::condition_variable fifo_empty_conditional_;
+
+ mutable std::mutex fifo_full_mutex_;
+ mutable std::condition_variable fifo_full_conditional_;
+
+ // Vector that stores all objects.
+ std::vector<T> fifo_;
+ size_t read_pos_;
+ size_t write_pos_;
+
+ // Atomic counter that reflects the size of |fifo_|.
+ std::atomic<size_t> fifo_size_;
+
+ std::atomic<bool> enable_sleeping_;
+};
+
+template <typename T>
+ThreadsafeFifo<T>::ThreadsafeFifo(size_t max_objects)
+ : fifo_(max_objects),
+ read_pos_(0),
+ write_pos_(0),
+ fifo_size_(0),
+ enable_sleeping_(true) {
+ CHECK_GT(max_objects, 0) << "FIFO size must be greater than zero";
+}
+
+template <typename T>
+ThreadsafeFifo<T>::ThreadsafeFifo(size_t max_objects, const T& init)
+ : ThreadsafeFifo(max_objects) {
+ for (auto& object : fifo_) {
+ object = init;
+ }
+}
+
+template <typename T>
+T* ThreadsafeFifo<T>::AcquireInputObject() {
+ if (Full()) {
+ return nullptr;
+ }
+ CHECK_LT(fifo_size_, fifo_.size());
+
+ // Add object to FIFO queue.
+ return &fifo_[write_pos_];
+}
+
+template <typename T>
+void ThreadsafeFifo<T>::ReleaseInputObject(const T* object) {
+ DCHECK_EQ(object, &fifo_[write_pos_]);
+
+ ++write_pos_;
+ write_pos_ = write_pos_ % fifo_.size();
+ if (fifo_size_.fetch_add(1) == 0) {
+ {
+ // Taking the lock and dropping it immediately assure that the notify
+ // cannot happen between the check of the predicate and wait of the
+ // |fifo_empty_conditional_|.
+ std::lock_guard<std::mutex> lock(fifo_empty_mutex_);
+ }
+ // In case of an empty queue, notify reader.
+ fifo_empty_conditional_.notify_one();
+ }
+}
+
+template <typename T>
+T* ThreadsafeFifo<T>::AcquireOutputObject() {
+ if (Empty()) {
+ return nullptr;
+ }
+ CHECK_GT(fifo_size_, 0);
+ return &fifo_[read_pos_];
+}
+
+template <typename T>
+void ThreadsafeFifo<T>::ReleaseOutputObject(const T* object) {
+ DCHECK_EQ(object, &fifo_[read_pos_]);
+
+ ++read_pos_;
+ read_pos_ = read_pos_ % fifo_.size();
+
+ if (fifo_size_.fetch_sub(1) == fifo_.size()) {
+ {
+ // Taking the lock and dropping it immediately assure that the notify
+ // cannot happen between the check of the predicate and wait of the
+ // |fifo_full_conditional_|.
+ std::lock_guard<std::mutex> lock(fifo_full_mutex_);
+ }
+ // In case of a previously full queue, notify writer.
+ fifo_full_conditional_.notify_one();
+ }
+}
+
+template <typename T>
+bool ThreadsafeFifo<T>::SleepUntilInputObjectIsAvailable() const {
+ // In case of a full queue, wait to allow objects to be popped from the
+ // FIFO queue.
+ std::unique_lock<std::mutex> lock(fifo_full_mutex_);
+ fifo_full_conditional_.wait(lock, [this]() {
+ return fifo_size_.load() < fifo_.size() || !enable_sleeping_.load();
+ });
+ return fifo_size_.load() < fifo_.size();
+}
+
+template <typename T>
+bool ThreadsafeFifo<T>::SleepUntilOutputObjectIsAvailable() const {
+ // In case of an empty queue, wait for new objects to be added.
+ std::unique_lock<std::mutex> lock(fifo_empty_mutex_);
+ fifo_empty_conditional_.wait(lock, [this]() {
+ return fifo_size_.load() > 0 || !enable_sleeping_.load();
+ });
+ return fifo_size_.load() > 0;
+}
+
+template <typename T>
+void ThreadsafeFifo<T>::EnableBlockingSleepUntilMethods(bool enable) {
+ enable_sleeping_ = enable;
+ // Taking the lock and dropping it immediately assure that the notify
+ // cannot happen between the check of the predicate and wait of the
+ // |fifo_empty_conditional_| and |fifo_full_conditional_|.
+ { std::lock_guard<std::mutex> lock(fifo_empty_mutex_); }
+ { std::lock_guard<std::mutex> lock(fifo_full_mutex_); }
+ fifo_empty_conditional_.notify_one();
+ fifo_full_conditional_.notify_one();
+}
+
+template <typename T>
+size_t ThreadsafeFifo<T>::Size() const {
+ return fifo_size_.load();
+}
+
+template <typename T>
+bool ThreadsafeFifo<T>::Empty() const {
+ return fifo_size_.load() == 0;
+}
+
+template <typename T>
+bool ThreadsafeFifo<T>::Full() const {
+ return fifo_size_.load() == fifo_.size();
+}
+
+template <typename T>
+void ThreadsafeFifo<T>::Clear() {
+ while (!Empty()) {
+ T* output = AcquireOutputObject();
+ if (output != nullptr) {
+ ReleaseOutputObject(output);
+ }
+ }
+}
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_THREADSAFE_FIFO_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/vorbis_stream_encoder.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/vorbis_stream_encoder.cc
new file mode 100644
index 000000000..f8b2f2287
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/vorbis_stream_encoder.cc
@@ -0,0 +1,174 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Prevent Visual Studio from complaining about std::copy_n.
+#if defined(_WIN32)
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include "utils/vorbis_stream_encoder.h"
+
+#include "vorbis/vorbisenc.h"
+#include "base/audio_buffer.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+VorbisStreamEncoder::VorbisStreamEncoder() : init_(false) {}
+
+bool VorbisStreamEncoder::InitializeForFile(const std::string& filename,
+ size_t num_channels,
+ int sample_rate,
+ EncodingMode encoding_mode,
+ int bitrate, float quality) {
+ output_file_stream_.open(filename,
+ std::ios::out | std::ios::trunc | std::ios::binary);
+ if (!output_file_stream_.good()) {
+ LOG(ERROR) << "Could not open output file: " << filename;
+ return false;
+ }
+
+ int return_value = 1;
+ vorbis_info_init(&vorbis_info_);
+
+ switch (encoding_mode) {
+ case EncodingMode::kVariableBitRate:
+ return_value = vorbis_encode_init_vbr(
+ &vorbis_info_, static_cast<long>(num_channels),
+ sample_rate, quality);
+ break;
+ case EncodingMode::kAverageBitRate:
+ return_value = vorbis_encode_init(
+ &vorbis_info_, static_cast<long>(num_channels),
+ sample_rate, -1 /* max_bitrate */, bitrate, -1 /* quality */);
+ break;
+ case EncodingMode::kUndefined:
+ default:
+ break;
+ }
+
+ if (return_value != 0) {
+ return false;
+ }
+
+ vorbis_comment_init(&vorbis_comment_);
+ vorbis_comment_add_tag(&vorbis_comment_, "ENCODER", "VrAudio");
+ vorbis_analysis_init(&vorbis_state_, &vorbis_info_);
+ vorbis_block_init(&vorbis_state_, &vorbis_block_);
+ ogg_stream_init(&stream_state_, 1 /* serial_number */);
+
+ // Generate Ogg header
+ ogg_packet header;
+ ogg_packet header_comments;
+ ogg_packet header_code;
+
+ vorbis_analysis_headerout(&vorbis_state_, &vorbis_comment_, &header,
+ &header_comments, &header_code);
+ ogg_stream_packetin(&stream_state_, &header);
+ ogg_stream_packetin(&stream_state_, &header_comments);
+ ogg_stream_packetin(&stream_state_, &header_code);
+
+ while (true) {
+ return_value = ogg_stream_flush(&stream_state_, &ogg_page_);
+ if (return_value == 0) {
+ break;
+ }
+ if (!WriteOggPage()) {
+ return false;
+ }
+ }
+ init_ = true;
+ return true;
+}
+
+bool VorbisStreamEncoder::AddPlanarBuffer(const float* const* input_ptrs,
+ size_t num_channels,
+ size_t num_frames) {
+ CHECK(init_);
+ PrepareVorbisBuffer(input_ptrs, num_channels, num_frames);
+ return PerformEncoding();
+}
+
+bool VorbisStreamEncoder::FlushAndClose() {
+ // Signal end of stream.
+ vorbis_analysis_wrote(&vorbis_state_, 0);
+ if (!PerformEncoding()) {
+ return false;
+ }
+
+ output_file_stream_.close();
+
+ vorbis_comment_clear(&vorbis_comment_);
+ vorbis_dsp_clear(&vorbis_state_);
+ vorbis_block_clear(&vorbis_block_);
+ ogg_stream_clear(&stream_state_);
+ vorbis_info_clear(&vorbis_info_);
+
+ init_ = false;
+ return true;
+}
+
+void VorbisStreamEncoder::PrepareVorbisBuffer(const float* const* input_ptrs,
+ size_t num_channels,
+ size_t num_frames) {
+ float** buffer = vorbis_analysis_buffer(
+ &vorbis_state_, static_cast<int>(num_channels * num_frames));
+ for (size_t channel = 0; channel < num_channels; ++channel) {
+ std::copy_n(input_ptrs[channel], num_frames, buffer[channel]);
+ }
+
+ vorbis_analysis_wrote(&vorbis_state_, static_cast<int>(num_frames));
+}
+
+bool VorbisStreamEncoder::PerformEncoding() {
+ CHECK(init_);
+ while (vorbis_analysis_blockout(&vorbis_state_, &vorbis_block_) == 1) {
+ vorbis_analysis(&vorbis_block_, nullptr);
+ vorbis_bitrate_addblock(&vorbis_block_);
+
+ while (vorbis_bitrate_flushpacket(&vorbis_state_, &ogg_packet_)) {
+ ogg_stream_packetin(&stream_state_, &ogg_packet_);
+
+ bool end_of_stream = false;
+ while (!end_of_stream) {
+ int result = ogg_stream_pageout(&stream_state_, &ogg_page_);
+ if (result == 0) {
+ break;
+ }
+ if (!WriteOggPage()) {
+ return false;
+ }
+ if (ogg_page_eos(&ogg_page_)) {
+ end_of_stream = true;
+ }
+ }
+ }
+ }
+ return true;
+}
+
+bool VorbisStreamEncoder::WriteOggPage() {
+ output_file_stream_.write(reinterpret_cast<char*>(ogg_page_.header),
+ ogg_page_.header_len);
+ output_file_stream_.write(reinterpret_cast<char*>(ogg_page_.body),
+ ogg_page_.body_len);
+ if (!output_file_stream_.good()) {
+ return false;
+ }
+ return true;
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/vorbis_stream_encoder.h b/src/3rdparty/resonance-audio/resonance_audio/utils/vorbis_stream_encoder.h
new file mode 100644
index 000000000..cf66d2ad2
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/vorbis_stream_encoder.h
@@ -0,0 +1,114 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_VORBIS_STREAM_ENCODER_H_
+#define RESONANCE_AUDIO_UTILS_VORBIS_STREAM_ENCODER_H_
+
+#include <fstream>
+#include <iostream>
+
+#include "base/integral_types.h"
+
+#include "ogg/ogg.h"
+#include "vorbis/codec.h"
+
+namespace vraudio {
+
+class VorbisStreamEncoder {
+ public:
+ // Supported encoding modes.
+ enum class EncodingMode {
+ kUndefined,
+ // Variable bit rate mode (VBR).
+ kVariableBitRate,
+ // Average bit rate mode (ABR).
+ kAverageBitRate,
+ };
+
+ VorbisStreamEncoder();
+
+ // Initializes Vorbis encoding.
+ //
+ // @param filename Ogg vorbis output file. If it doesn't exist, it will be
+ // created. Existing files will be overwritten.
+ // @param num_channels Number of input channels.
+ // @param sample_rate Sample rate of input audio buffers.
+ // @param encoding_mode Selects variable (VBR) or average encoding (ABR).
+ // @param bitrate Target bitrate (only used when selecting ABR encoding).
+ // @param quality Target quality (only used when selecting VBR encoding). The
+ // usable range is -.1 (lowest quality, smallest file) to 1. (highest
+ // quality, largest file).
+ // @return False in case of file I/O errors or libvorbis initialization
+ // failures like non-supported channel/sample rate configuration.
+ bool InitializeForFile(const std::string& filename, size_t num_channels,
+ int sample_rate, EncodingMode encoding_mode,
+ int bitrate, float quality);
+
+ // Feeds input audio data into libvorbis encoder and triggers encoding.
+ //
+ // @param Array of pointers to planar channel data.
+ // @param num_channels Number of input channels.
+ // @param num_frames Number of input frames.
+ // @return False in case of file I/O errors or missing encoder initialization.
+ bool AddPlanarBuffer(const float* const* input_ptrs, size_t num_channels,
+ size_t num_frames);
+
+ // Flushes the remaining audio buffers and closes the output file.
+ //
+ // @return False in case of file I/O errors or missing encoder initialization.
+ bool FlushAndClose();
+
+ private:
+ // Copies input audio data into libvorbis encoder buffer.
+ //
+ // @param Array of pointers to planar channel data.
+ // @param num_channels Number of input channels.
+ // @param num_frames Number of input frames.
+ void PrepareVorbisBuffer(const float* const* input_ptrs, size_t num_channels,
+ size_t num_frames);
+
+ // Performs encoding of audio data prepared via |PrepareVorbisBuffer| or when
+ // the end of stream has been signaled.
+ //
+ // @return False in case of file I/O errors or missing encoder initialization.
+ bool PerformEncoding();
+
+ // Dumps data from |ogg_page_| struct to |output_file_stream_|.
+ //
+ // @return False in case of file I/O errors or missing encoder initialization.
+ bool WriteOggPage();
+
+ // Flag indicating if encoder has been successfully initialized.
+ bool init_;
+
+ // Output file stream.
+ std::ofstream output_file_stream_;
+
+ // libogg structs.
+ ogg_stream_state stream_state_;
+ ogg_page ogg_page_;
+ ogg_packet ogg_packet_;
+
+ // libvorbis structs.
+ vorbis_info vorbis_info_;
+ vorbis_comment vorbis_comment_;
+ vorbis_dsp_state vorbis_state_;
+ vorbis_block vorbis_block_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_VORBIS_STREAM_ENCODER_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/wav.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/wav.cc
new file mode 100644
index 000000000..5edbbc7bd
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/wav.cc
@@ -0,0 +1,53 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/wav.h"
+
+#include <cerrno>
+#include <fstream>
+#include <string>
+
+#include "base/integral_types.h"
+#include "base/logging.h"
+#include "utils/wav_reader.h"
+
+namespace vraudio {
+
+Wav::Wav(size_t num_channels, int sample_rate,
+ std::vector<int16_t>&& interleaved_samples)
+ : num_channels_(num_channels),
+ sample_rate_(sample_rate),
+ interleaved_samples_(interleaved_samples) {}
+
+Wav::~Wav() {}
+
+std::unique_ptr<const Wav> Wav::CreateOrNull(std::istream* binary_stream) {
+ WavReader wav_reader(binary_stream);
+ const size_t num_total_samples = wav_reader.GetNumTotalSamples();
+ if (!wav_reader.IsHeaderValid() || num_total_samples == 0) {
+ return nullptr;
+ }
+ std::vector<int16> interleaved_samples(num_total_samples);
+ if (wav_reader.ReadSamples(num_total_samples, &interleaved_samples[0]) !=
+ num_total_samples) {
+ return nullptr;
+ }
+ return std::unique_ptr<Wav>(new Wav(wav_reader.GetNumChannels(),
+ wav_reader.GetSampleRateHz(),
+ std::move(interleaved_samples)));
+}
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/wav.h b/src/3rdparty/resonance-audio/resonance_audio/utils/wav.h
new file mode 100644
index 000000000..c76bd8f3a
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/wav.h
@@ -0,0 +1,66 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_WAV_H_
+#define RESONANCE_AUDIO_UTILS_WAV_H_
+
+#include <cstdint>
+#include <memory>
+#include <vector>
+
+namespace vraudio {
+
+// Wraps WavReader class to decode a wav file into memory.
+class Wav {
+ public:
+ ~Wav();
+
+ // Reads a RIFF WAVE from an opened binary stream.
+ static std::unique_ptr<const Wav> CreateOrNull(std::istream* binary_stream);
+
+ // Returns reference to interleaved samples.
+ const std::vector<int16_t>& interleaved_samples() const {
+ return interleaved_samples_;
+ }
+
+ // Returns number of channels.
+ size_t GetNumChannels() const { return num_channels_; }
+
+ // Returns sample rate.
+ int GetSampleRateHz() const { return sample_rate_; }
+
+ private:
+ // Private constructor used by static factory methods.
+ //
+ // @param num_channels Number of audio channels.
+ // @param sample_rate Sample rate.
+ // @param interleaved_samples Decoded interleaved samples.
+ Wav(size_t num_channels, int sample_rate,
+ std::vector<int16_t>&& interleaved_samples);
+
+ // Number of channels.
+ size_t num_channels_;
+
+ // Sample rate.
+ int sample_rate_;
+
+ // Interleaved samples.
+ std::vector<int16_t> interleaved_samples_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_WAV_H_
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/wav_reader.cc b/src/3rdparty/resonance-audio/resonance_audio/utils/wav_reader.cc
new file mode 100644
index 000000000..ca1078467
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/wav_reader.cc
@@ -0,0 +1,214 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils/wav_reader.h"
+
+#include <algorithm>
+#include <string>
+
+#include "base/integral_types.h"
+#include "base/logging.h"
+
+namespace vraudio {
+
+namespace {
+
+struct ChunkHeader {
+ char id[4];
+ uint32 size;
+};
+
+struct WavFormat {
+ ChunkHeader header;
+ uint16 format_tag; // Integer identifier of the format
+ uint16 num_channels; // Number of audio channels
+ uint32 samples_rate; // Audio sample rate
+ uint32 average_bytes_per_second; // Bytes per second (possibly approximate)
+ uint16 block_align; // Size in bytes of a sample block (all channels)
+ uint16 bits_per_sample; // Size in bits of a single per-channel sample
+};
+static_assert(sizeof(WavFormat) == 24, "Padding in WavFormat struct detected");
+
+struct WavHeader {
+ struct {
+ ChunkHeader header;
+ char format[4];
+ } riff;
+ WavFormat format;
+ struct {
+ ChunkHeader header;
+ } data;
+};
+
+// Size of WAV header.
+const size_t kWavHeaderSize = 44;
+
+static_assert(sizeof(WavHeader) == kWavHeaderSize,
+ "Padding in WavHeader struct detected");
+
+// Supported WAV encoding formats.
+static const uint16 kExtensibleWavFormat = 0xfffe;
+static const uint16 kPcmFormat = 0x1;
+} // namespace
+
+WavReader::WavReader(std::istream* binary_stream)
+ : binary_stream_(CHECK_NOTNULL(binary_stream)),
+ num_channels_(0),
+ sample_rate_hz_(-1),
+ num_total_samples_(0),
+ num_remaining_samples_(0),
+ pcm_offset_bytes_(0) {
+ init_ = ParseHeader();
+}
+
+size_t WavReader::ReadBinaryDataFromStream(void* target_ptr, size_t size) {
+ if (!binary_stream_->good()) {
+ return 0;
+ }
+ binary_stream_->read(static_cast<char*>(target_ptr), size);
+ return static_cast<size_t>(binary_stream_->gcount());
+}
+
+bool WavReader::ParseHeader() {
+ WavHeader header;
+ // Exclude data field to be able to optionally parse the two-byte extension
+ // field.
+ if (ReadBinaryDataFromStream(&header, kWavHeaderSize - sizeof(header.data)) !=
+ kWavHeaderSize - sizeof(header.data))
+ return false;
+ const uint32 format_size = header.format.header.size;
+ // Size of |WavFormat| without |ChunkHeader|.
+ static const uint32 kFormatSubChunkHeader =
+ sizeof(WavFormat) - sizeof(ChunkHeader);
+ if (format_size < kFormatSubChunkHeader) {
+ return false;
+ }
+ if (format_size != kFormatSubChunkHeader) {
+ // Parse optional extension fields.
+ int16 extension_size;
+ if (ReadBinaryDataFromStream(&extension_size, sizeof(extension_size)) !=
+ sizeof(extension_size))
+ return false;
+ int8 extension_data;
+ for (size_t i = 0; i < static_cast<size_t>(extension_size); ++i) {
+ if (ReadBinaryDataFromStream(&extension_data, sizeof(extension_data)) !=
+ sizeof(extension_data))
+ return false;
+ }
+ }
+ if (header.format.format_tag == kExtensibleWavFormat) {
+ // Skip extensible wav format "fact" header.
+ ChunkHeader fact_header;
+ if (ReadBinaryDataFromStream(&fact_header, sizeof(fact_header)) !=
+ sizeof(fact_header)) {
+ return false;
+ }
+ if (std::string(fact_header.id, 4) != "fact") {
+ return false;
+ }
+ int8 fact_data;
+ for (size_t i = 0; i < static_cast<size_t>(fact_header.size); ++i) {
+ if (ReadBinaryDataFromStream(&fact_data, sizeof(fact_data)) !=
+ sizeof(fact_data))
+ return false;
+ }
+ }
+
+ // Read the "data" header.
+ if (ReadBinaryDataFromStream(&header.data, sizeof(header.data)) !=
+ sizeof(header.data)) {
+ return false;
+ }
+
+ num_channels_ = header.format.num_channels;
+ sample_rate_hz_ = header.format.samples_rate;
+
+ bytes_per_sample_ = header.format.bits_per_sample / 8;
+ if (bytes_per_sample_ == 0 || bytes_per_sample_ != sizeof(int16)) {
+ return false;
+ }
+ const size_t bytes_in_payload = header.data.header.size;
+ num_total_samples_ = bytes_in_payload / bytes_per_sample_;
+ num_remaining_samples_ = num_total_samples_;
+
+ if (header.format.num_channels == 0 || num_total_samples_ == 0 ||
+ bytes_in_payload % bytes_per_sample_ != 0 ||
+ (header.format.format_tag != kPcmFormat &&
+ header.format.format_tag != kExtensibleWavFormat) ||
+ (std::string(header.riff.header.id, 4) != "RIFF") ||
+ (std::string(header.riff.format, 4) != "WAVE") ||
+ (std::string(header.format.header.id, 4) != "fmt ") ||
+ (std::string(header.data.header.id, 4) != "data")) {
+ return false;
+ }
+
+ int64 current_position = binary_stream_->tellg();
+ if (current_position < 0) {
+ return false;
+ }
+ pcm_offset_bytes_ = static_cast<uint64>(current_position);
+ return true;
+}
+
+size_t WavReader::ReadSamples(size_t num_samples, int16* target_buffer) {
+ const size_t num_samples_to_read =
+ std::min(num_remaining_samples_, num_samples);
+ if (num_samples_to_read == 0) {
+ return 0;
+ }
+ const size_t num_bytes_read =
+ ReadBinaryDataFromStream(target_buffer, num_samples * sizeof(int16));
+ const size_t num_samples_read = num_bytes_read / bytes_per_sample_;
+
+ num_remaining_samples_ -= num_samples_read;
+ return num_samples_read;
+}
+
+int64 WavReader::SeekToFrame(const uint64 frame_position) {
+ DCHECK_GT(num_channels_, 0U);
+ if (frame_position <= (num_total_samples_ / num_channels_)) {
+ const uint64 seek_position_byte =
+ pcm_offset_bytes_ + frame_position * num_channels_ * bytes_per_sample_;
+ binary_stream_->seekg(seek_position_byte, binary_stream_->beg);
+ }
+
+ int64 binary_stream_position_byte =
+ static_cast<int64>(binary_stream_->tellg());
+ if (binary_stream_position_byte < 0) {
+ // Return an error status if the actual bitstream position could not be
+ // queried.
+ return binary_stream_position_byte;
+ }
+
+ if (static_cast<uint64>(binary_stream_position_byte) > pcm_offset_bytes_) {
+ DCHECK_GT(bytes_per_sample_, 0U);
+ return (static_cast<uint64>(binary_stream_position_byte) -
+ pcm_offset_bytes_) /
+ (bytes_per_sample_ * num_channels_);
+ }
+
+ return 0;
+}
+
+size_t WavReader::GetNumTotalSamples() const { return num_total_samples_; }
+
+size_t WavReader::GetNumChannels() const { return num_channels_; }
+
+int WavReader::GetSampleRateHz() const { return sample_rate_hz_; }
+
+bool WavReader::IsHeaderValid() const { return init_; }
+
+} // namespace vraudio
diff --git a/src/3rdparty/resonance-audio/resonance_audio/utils/wav_reader.h b/src/3rdparty/resonance-audio/resonance_audio/utils/wav_reader.h
new file mode 100644
index 000000000..513853c30
--- /dev/null
+++ b/src/3rdparty/resonance-audio/resonance_audio/utils/wav_reader.h
@@ -0,0 +1,103 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef RESONANCE_AUDIO_UTILS_WAV_READER_H_
+#define RESONANCE_AUDIO_UTILS_WAV_READER_H_
+
+#include <cstdint>
+#include <istream>
+
+#include "base/integral_types.h"
+
+namespace vraudio {
+
+// Basic RIFF WAVE decoder that supports multichannel 16-bit PCM.
+class WavReader {
+ public:
+ // Constructor decodes WAV header.
+ //
+ // @param binary_stream Binary input stream to read from.
+ explicit WavReader(std::istream* binary_stream);
+
+ // True if WAV header was successfully parsed.
+ bool IsHeaderValid() const;
+
+ // Returns the total number of samples defined in the WAV header. Note that
+ // the actual number of samples in the file can differ.
+ size_t GetNumTotalSamples() const;
+
+ // Returns number of channels.
+ size_t GetNumChannels() const;
+
+ // Returns sample rate in Hertz.
+ int GetSampleRateHz() const;
+
+ // Seek to a specific frame position within the wave file. If frame_position
+ // is not a valid address, then the internal read position remains unchanged.
+ //
+ // @param frame_position Destination frame position for play cursor.
+ // @return Actual frame position of cursor after this seek operation. A
+ // negative return value indicates a stream failure.
+ int64 SeekToFrame(const uint64 frame_position);
+
+ // Reads samples from WAV file into target buffer.
+ //
+ // @param num_samples Number of samples to read.
+ // @param target_buffer Target buffer to write to.
+ // @return Number of decoded samples.
+ size_t ReadSamples(size_t num_samples, int16_t* target_buffer);
+
+ private:
+ // Parses WAV header.
+ //
+ // @return True on success.
+ bool ParseHeader();
+
+ // Helper method to read binary data from input stream.
+ //
+ // @param size Number of bytes to read.
+ // @param target_ptr Target buffer to write to.
+ // @return Number of bytes read.
+ size_t ReadBinaryDataFromStream(void* target_ptr, size_t size);
+
+ // Binary input stream.
+ std::istream* binary_stream_;
+
+ // Flag indicating if the WAV header was parsed successfully.
+ bool init_;
+
+ // Number of audio channels.
+ size_t num_channels_;
+
+ // Sample rate in Hertz.
+ int sample_rate_hz_;
+
+ // Total number of samples.
+ size_t num_total_samples_;
+
+ // Number of remaining samples in WAV file.
+ size_t num_remaining_samples_;
+
+ // Bytes per sample as defined in the WAV header.
+ size_t bytes_per_sample_;
+
+ // Offset into data stream where PCM data begins.
+ uint64 pcm_offset_bytes_;
+};
+
+} // namespace vraudio
+
+#endif // RESONANCE_AUDIO_UTILS_WAV_READER_H_
diff --git a/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/LICENSE b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/LICENSE
new file mode 100644
index 000000000..a59c8797f
--- /dev/null
+++ b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/LICENSE
@@ -0,0 +1,157 @@
+Apache License
+
+Version 2.0, January 2004
+
+http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and
+distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright
+owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities
+that control, are controlled by, or are under common control with that entity.
+For the purposes of this definition, "control" means (i) the power, direct or
+indirect, to cause the direction or management of such entity, whether by
+contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
+outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising
+permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including
+but not limited to software source code, documentation source, and configuration
+files.
+
+"Object" form shall mean any form resulting from mechanical transformation or
+translation of a Source form, including but not limited to compiled object code,
+generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made
+available under the License, as indicated by a copyright notice that is included
+in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that
+is based on (or derived from) the Work and for which the editorial revisions,
+annotations, elaborations, or other modifications represent, as a whole, an
+original work of authorship. For the purposes of this License, Derivative Works
+shall not include works that remain separable from, or merely link (or bind by
+name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version
+of the Work and any modifications or additions to that Work or Derivative Works
+thereof, that is intentionally submitted to Licensor for inclusion in the Work
+by the copyright owner or by an individual or Legal Entity authorized to submit
+on behalf of the copyright owner. For the purposes of this definition,
+"submitted" means any form of electronic, verbal, or written communication sent
+to the Licensor or its representatives, including but not limited to
+communication on electronic mailing lists, source code control systems, and
+issue tracking systems that are managed by, or on behalf of, the Licensor for
+the purpose of discussing and improving the Work, but excluding communication
+that is conspicuously marked or otherwise designated in writing by the copyright
+owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
+of whom a Contribution has been received by Licensor and subsequently
+incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of this
+License, each Contributor hereby grants to You a perpetual, worldwide,
+non-exclusive, no-charge, royalty-free, irrevocable copyright license to
+reproduce, prepare Derivative Works of, publicly display, publicly perform,
+sublicense, and distribute the Work and such Derivative Works in Source or
+Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of this License,
+each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
+no-charge, royalty-free, irrevocable (except as stated in this section) patent
+license to make, have made, use, offer to sell, sell, import, and otherwise
+transfer the Work, where such license applies only to those patent claims
+licensable by such Contributor that are necessarily infringed by their
+Contribution(s) alone or by combination of their Contribution(s) with the Work
+to which such Contribution(s) was submitted. If You institute patent litigation
+against any entity (including a cross-claim or counterclaim in a lawsuit)
+alleging that the Work or a Contribution incorporated within the Work
+constitutes direct or contributory patent infringement, then any patent licenses
+granted to You under this License for that Work shall terminate as of the date
+such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the Work or
+Derivative Works thereof in any medium, with or without modifications, and in
+Source or Object form, provided that You meet the following conditions:
+
+You must give any other recipients of the Work or Derivative Works a copy of
+this License; and
+You must cause any modified files to carry prominent notices stating that You
+changed the files; and
+You must retain, in the Source form of any Derivative Works that You distribute,
+all copyright, patent, trademark, and attribution notices from the Source form
+of the Work, excluding those notices that do not pertain to any part of the
+Derivative Works; and
+If the Work includes a "NOTICE" text file as part of its distribution, then any
+Derivative Works that You distribute must include a readable copy of the
+attribution notices contained within such NOTICE file, excluding those notices
+that do not pertain to any part of the Derivative Works, in at least one of the
+following places: within a NOTICE text file distributed as part of the
+Derivative Works; within the Source form or documentation, if provided along
+with the Derivative Works; or, within a display generated by the Derivative
+Works, if and wherever such third-party notices normally appear. The contents of
+the NOTICE file are for informational purposes only and do not modify the
+License. You may add Your own attribution notices within Derivative Works that
+You distribute, alongside or as an addendum to the NOTICE text from the Work,
+provided that such additional attribution notices cannot be construed as
+modifying the License.
+
+You may add Your own copyright statement to Your modifications and may provide
+additional or different license terms and conditions for use, reproduction, or
+distribution of Your modifications, or for any such Derivative Works as a whole,
+provided Your use, reproduction, and distribution of the Work otherwise complies
+with the conditions stated in this License.
+5. Submission of Contributions. Unless You explicitly state otherwise, any
+Contribution intentionally submitted for inclusion in the Work by You to the
+Licensor shall be under the terms and conditions of this License, without any
+additional terms or conditions. Notwithstanding the above, nothing herein shall
+supersede or modify the terms of any separate license agreement you may have
+executed with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade names,
+trademarks, service marks, or product names of the Licensor, except as required
+for reasonable and customary use in describing the origin of the Work and
+reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
+writing, Licensor provides the Work (and each Contributor provides its
+Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied, including, without limitation, any warranties
+or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+PARTICULAR PURPOSE. You are solely responsible for determining the
+appropriateness of using or redistributing the Work and assume any risks
+associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory, whether in
+tort (including negligence), contract, or otherwise, unless required by
+applicable law (such as deliberate and grossly negligent acts) or agreed to in
+writing, shall any Contributor be liable to You for damages, including any
+direct, indirect, special, incidental, or consequential damages of any character
+arising as a result of this License or out of the use or inability to use the
+Work (including but not limited to damages for loss of goodwill, work stoppage,
+computer failure or malfunction, or any and all other commercial damages or
+losses), even if such Contributor has been advised of the possibility of such
+damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing the Work or
+Derivative Works thereof, You may choose to offer, and charge a fee for,
+acceptance of support, warranty, indemnity, or other liability obligations
+and/or rights consistent with this License. However, in accepting such
+obligations, You may act only on Your own behalf and on Your sole
+responsibility, not on behalf of any other Contributor, and only if You agree to
+indemnify, defend, and hold each Contributor harmless for any liability incurred
+by, or claims asserted against, such Contributor by reason of your accepting any
+such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
diff --git a/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generate_hrtf_assets.py b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generate_hrtf_assets.py
new file mode 100755
index 000000000..5272d3855
--- /dev/null
+++ b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generate_hrtf_assets.py
@@ -0,0 +1,287 @@
+"""
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+
+#!/usr/bin/python
+"""Generates a C++ class that statically stores raw asset data.
+
+Usage: generate_hrtf_assets.py <asset file> <output_path>
+
+Parses an asset file and generates a compilable C++ class that statically
+defines the content of all files declared in the asset file.
+
+An asset file is an XML file that lists group of files. See below for an
+example:
+
+<?xml version="1.0"?>
+<IAD name="Assets">
+ <assets>
+ <file>file1.txt</file>
+ <file>file2.txt</file>
+ <file name="dir/file1.txt">file1.txt</file>
+ <file name="dir/file2.txt">file2.txt</file>
+ </assets>
+ <assets prefix="path">
+ <file name="file1.txt">file1.txt</file>
+ <file name="file2.txt">file2.txt</file>
+ </assets>
+</IAD>
+
+Below that are any number of <assets> blocks which define groups of files with
+similar paths. The filename to be added is the text of each <file> block, and
+path to the file relative to the definition file. If an <asset> has a "prefix"
+tag then that prefix is prepended to the filename.
+"""
+
+import array
+import os
+import re
+import sys
+import textwrap
+from xml.etree import ElementTree
+
+
+class Error(Exception):
+ """Base class for errors."""
+
+
+class InvalidAssetSyntaxError(Error):
+ """Error representing an asset file with invalid syntax."""
+
+
+#------------------------------------------------------------------------------
+def BuildManifest(asset_file):
+ """Builds a list of (filename, asset) pairs from an asset file.
+
+ Args:
+ asset_file: string - a file containing asset definitions.
+
+ Returns:
+ A tuple containing:
+ - an asset class name
+ - an list of (filename, asset) pairs, where filename is the absolute path
+ to the file on local disk, and asset is the name the stored asset should
+ be given.
+
+ Raises:
+ InvalidAssetSyntaxError: if asset_file has syntax errors.
+ IOError: if asset_file or any files it references are not found.
+ """
+ if not os.path.exists(asset_file):
+ raise IOError('Could not find asset file "%s"' % asset_file)
+
+ # Load the xml.
+ root = ElementTree.parse(asset_file).getroot()
+ if root.tag != 'IAD':
+ raise InvalidAssetSyntaxError('Root tag should be "IAD" not "%s"' %
+ root.tag)
+ if 'name' not in root.attrib:
+ raise InvalidAssetSyntaxError('Root tag requires a "name" attribute')
+
+ path_to_asset_file = os.path.abspath(os.path.dirname(asset_file))
+
+ manifest = []
+ for group in root.findall('assets'):
+ # Get the path prefix if there is one.
+ prefix = group.attrib.get('prefix', '')
+ for asset in group.findall('file'):
+ # See if the file exists.
+ asset_filename = os.path.join(path_to_asset_file,
+ os.path.normcase(asset.text))
+ if not os.path.exists(asset_filename):
+ raise IOError('Asset "%s" does not exist, searched in %s' %
+ (asset.text, path_to_asset_file))
+
+ # The filename is either the asset text appended to the prefix, or a
+ # requested name appended to the prefix.
+ filename = os.path.join(prefix, asset.attrib.get('name', asset.text))
+ # Add the full path to the file to the manifest.
+ manifest += [(os.path.abspath(asset_filename), filename)]
+
+ return root.attrib['name'], manifest
+
+
+#------------------------------------------------------------------------------
+def CamelCaseToUnderscore(name):
+ """Converts a camel-case formatted string to an underscore format.
+
+ Example: TestAssetClass -> test_asset_class
+ HTTPServer -> http_server
+
+ Args:
+ name: string - the camel-case formatted string.
+
+ Returns:
+ The underscore formatted input string.
+ """
+ s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
+ return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
+
+#------------------------------------------------------------------------------
+
+
+def GenerateAssetHeaderString(asset_class_name):
+ """Generates C++ header of asset class.
+
+ Args:
+ asset_class_name: string - the asset class name.
+
+ Returns:
+ String of generated asset class header.
+ """
+ header_guard = asset_class_name.upper().replace(
+ '/', '_').replace('.', '_') + '_'
+ output_string = []
+ output_string.append('#ifndef %s\n' % header_guard)
+ output_string.append('#define %s\n\n' % header_guard)
+ output_string.append('#include <memory>\n')
+ output_string.append('#include <string>\n')
+ output_string.append('#include <unordered_map>\n')
+ output_string.append('#include <vector>\n\n')
+ output_string.append('namespace sadie {\n\n')
+ output_string.append(
+ '// Note this class is automatically generated. Do not modify.\n')
+ output_string.append('class %s {\n' % asset_class_name)
+ output_string.append(' public:\n')
+ output_string.append(' // Lookups and retrieves a file from an asset class.\n')
+ output_string.append(' //\n')
+ output_string.append(' // @param filename: Filename to be retrieved.\n')
+ output_string.append(' // @return std::string with raw file data. In case of an error, a nullptr is\n')
+ output_string.append(' // returned. Caller must take over the ownership of the returned data.\n')
+ output_string.append(
+ ' std::unique_ptr<std::string> GetFile(const std::string& filename) '
+ 'const;\n\n')
+ output_string.append(' private:\n')
+ output_string.append(
+ ' typedef std::unordered_map<std::string, std::vector<unsigned char>>\n')
+ output_string.append(' AssetDataMap;\n')
+ output_string.append(' static const AssetDataMap kAssetMap;\n')
+ output_string.append('};\n\n')
+ output_string.append('} // namespace sadie\n\n')
+ output_string.append('#endif // %s\n' % header_guard)
+ return ''.join(output_string)
+
+
+#------------------------------------------------------------------------------
+def GenerateMapEntryDataString(manifest_entry):
+ """Generates formatted string of hexadecimal integers from a manifest entry.
+
+ Generates a formatted string of comma-separated hexadecimal integers that
+ define a C++ std::pair<std::string, std::vector<char>> map entry.
+
+ Args:
+ manifest_entry: a (filename, asset_name) pair, where filename is
+ the absolute path to the file on local disk, and asset_name is the name
+ the stored asset should be given.
+
+ Returns:
+ Formatted string containing asset name and binary file data:
+ {"asset_name", {0x.., 0x..}}
+ """
+ with open(manifest_entry[0], 'rb') as f:
+ file_data = f.read()
+ ints = array.array('B', file_data)
+ data_string = '{' + ', '.join('0x%x' % value for value in ints) + '}}'
+
+ wrapper = textwrap.TextWrapper(initial_indent=' ' * 5,
+ width=80,
+ subsequent_indent=' ' * 6)
+ wrapped_data_string = wrapper.fill(data_string)
+ return ' {\"%s\",\n%s' % (manifest_entry[1], wrapped_data_string)
+
+
+#------------------------------------------------------------------------------
+def GenerateAssetImplementationString(manifest, asset_class_name,
+ header_filename):
+ """Generates C++ implementation of asset class.
+
+ Args:
+ manifest: list of lists of (filename, asset_name) pairs, where filename is
+ the absolute path to the file on local disk, and asset_name is the name
+ the stored asset should be given.
+ asset_class_name: string - the asset class name.
+ header_filename: string - header file name.
+
+ Returns:
+ String of generated asset class implementation.
+ """
+ output_string = []
+ output_string.append('#include \"%s\"\n\n' %
+ header_filename.lower())
+ output_string.append('namespace sadie {\n\n')
+ output_string.append(
+ 'std::unique_ptr<std::string> %s::GetFile(\n' % asset_class_name)
+ output_string.append(' const std::string& filename) const {\n')
+ output_string.append(' AssetDataMap::const_iterator map_entry_itr = '
+ 'kAssetMap.find(filename);\n')
+ output_string.append(' if (map_entry_itr == kAssetMap.end()) {\n')
+ output_string.append(' return nullptr;\n')
+ output_string.append(' }\n')
+ output_string.append(' const char* data =\n')
+ output_string.append(' reinterpret_cast<const char*>('
+ 'map_entry_itr->second.data());\n')
+ output_string.append(
+ ' const size_t data_size = map_entry_itr->second.size();\n')
+ output_string.append(' return std::unique_ptr<std::string>('
+ 'new std::string(data, data_size));\n')
+ output_string.append('}\n\n')
+ # Generate map definition.
+ output_string.append('const %s::AssetDataMap %s::kAssetMap = {\n' %
+ (asset_class_name, asset_class_name))
+ output_string.append(
+ ',\n'.join(GenerateMapEntryDataString(f) for f in manifest))
+ output_string.append('};\n\n')
+ output_string.append('} // namespace sadie\n')
+ return ''.join(output_string)
+
+
+#------------------------------------------------------------------------------
+def main():
+ if len(sys.argv) != 3:
+ print 'Usage: %s <asset definition file> <output_path>' % sys.argv[0]
+ return
+
+ cur_dir = os.getcwd()
+ asset_file_path = os.path.normcase(os.path.join(cur_dir, sys.argv[1]))
+ output_dir_path = os.path.normcase(os.path.join(cur_dir, sys.argv[2]))
+
+ # Parse manifest.
+ classname, manifest = BuildManifest(asset_file_path)
+ if not manifest:
+ raise InvalidAssetSyntaxError(
+ '"%s" does not contain any asset definitions' % asset_file_path)
+
+ # Define class name, file names, output paths, etc.
+ classname_underscore = CamelCaseToUnderscore(classname)
+ header_filename = '%s.h' % classname_underscore
+ implementation_filename = '%s.cc' % classname_underscore
+ header_output_file_path = os.path.join(output_dir_path, header_filename)
+ implementation_output_file_path = os.path.join(output_dir_path,
+ implementation_filename)
+
+ # Render asset class and write output to .cc/.h files.
+ header_content = GenerateAssetHeaderString(
+ classname)
+ cc_content = GenerateAssetImplementationString(
+ manifest, classname, header_filename)
+
+ with open(header_output_file_path, 'w') as text_file:
+ text_file.write(header_content)
+ with open(implementation_output_file_path, 'w') as text_file:
+ text_file.write(cc_content)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/README b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/README
new file mode 100644
index 000000000..41101e044
--- /dev/null
+++ b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/README
@@ -0,0 +1,5 @@
+These files have been automatically generated using:
+
+$./generate_hrtf_assets.py hrtf_assets.iad generated
+
+Do not modify manually these automatically generated files. \ No newline at end of file
diff --git a/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/hrtf_assets.cc b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/hrtf_assets.cc
new file mode 100644
index 000000000..50c0a9921
--- /dev/null
+++ b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/hrtf_assets.cc
@@ -0,0 +1,1200 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "hrtf_assets.h"
+
+namespace sadie {
+
+std::unique_ptr<std::string> HrtfAssets::GetFile(
+ const std::string& filename) const {
+ AssetDataMap::const_iterator map_entry_itr = kAssetMap.find(filename);
+ if (map_entry_itr == kAssetMap.end()) {
+ return nullptr;
+ }
+ const char* data =
+ reinterpret_cast<const char*>(map_entry_itr->second.data());
+ const size_t data_size = map_entry_itr->second.size();
+ return std::unique_ptr<std::string>(new std::string(data, data_size));
+}
+
+const HrtfAssets::AssetDataMap HrtfAssets::kAssetMap = {
+ {"WAV/Subject_002/SH/sh_hrir_order_1.wav",
+ {0x52, 0x49, 0x46, 0x46, 0x24, 0x8, 0x0, 0x0, 0x57, 0x41, 0x56, 0x45, 0x66,
+ 0x6d, 0x74, 0x20, 0x10, 0x0, 0x0, 0x0, 0x1, 0x0, 0x4, 0x0, 0x80, 0xbb,
+ 0x0, 0x0, 0x0, 0xdc, 0x5, 0x0, 0x8, 0x0, 0x10, 0x0, 0x64, 0x61, 0x74,
+ 0x61, 0x0, 0x8, 0x0, 0x0, 0xfe, 0xff, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf6,
+ 0xff, 0x10, 0x0, 0xfd, 0xff, 0x2, 0x0, 0xfb, 0xff, 0xb, 0x0, 0xff, 0xff,
+ 0x1, 0x0, 0xfe, 0xff, 0x7, 0x0, 0xff, 0xff, 0x1, 0x0, 0xfe, 0xff, 0xc,
+ 0x0, 0xff, 0xff, 0x1, 0x0, 0xff, 0xff, 0x1, 0x0, 0xfd, 0xff, 0x0, 0x0,
+ 0xfb, 0xff, 0x1, 0x0, 0x2, 0x0, 0xfe, 0xff, 0x8, 0x0, 0x4, 0x0, 0xf9,
+ 0xff, 0x0, 0x0, 0xf8, 0xff, 0xfa, 0xff, 0x2, 0x0, 0xfc, 0xff, 0x18, 0x0,
+ 0x10, 0x0, 0x5, 0x0, 0x4, 0x0, 0xee, 0xff, 0xe7, 0xff, 0xf3, 0xff, 0x0,
+ 0x0, 0xfb, 0xff, 0xf4, 0xff, 0x1a, 0x0, 0xf9, 0xff, 0xcc, 0xff, 0xc0,
+ 0xff, 0xd5, 0xff, 0x4, 0x0, 0xfd, 0xfd, 0xf8, 0xfd, 0x1d, 0x0, 0xce, 0xff,
+ 0x1d, 0xfc, 0x12, 0xfc, 0x1a, 0x0, 0x41, 0x0, 0xf1, 0x1, 0xf1, 0x1, 0x4e,
+ 0xfe, 0x87, 0x0, 0xb4, 0xd, 0xa5, 0xd, 0xd0, 0xfc, 0x75, 0xfe, 0x37, 0x1,
+ 0x25, 0x1, 0xe7, 0x7, 0x5b, 0xfe, 0x49, 0xf5, 0x3e, 0xf5, 0x14, 0xa, 0x6f,
+ 0x7, 0x14, 0xfd, 0x3, 0xfd, 0x2c, 0xee, 0xa4, 0x2, 0xc0, 0xf5, 0xb5, 0xf5,
+ 0x3b, 0xfc, 0xfd, 0xf0, 0x68, 0xfd, 0x6b, 0xfd, 0x91, 0xd, 0xd0, 0x0,
+ 0xb8, 0xf4, 0xce, 0xf4, 0x61, 0xf3, 0xe2, 0x4, 0xf3, 0xe6, 0x3a, 0xe7,
+ 0x88, 0x5, 0x5e, 0xf7, 0xdc, 0xfd, 0x4f, 0xfe, 0x94, 0x8, 0xcd, 0x6, 0x6a,
+ 0x2, 0xf7, 0x2, 0x6, 0xf8, 0x7a, 0xfe, 0x2b, 0x1c, 0xfd, 0x1c, 0x7c, 0xfb,
+ 0xad, 0xfd, 0x6e, 0x18, 0xa1, 0x19, 0x9, 0xfd, 0x7, 0x10, 0x6, 0xfd, 0xe3,
+ 0xfe, 0x49, 0x15, 0x5d, 0x6, 0x26, 0xc, 0xcd, 0xd, 0xa, 0x1, 0x4a, 0x1,
+ 0xa0, 0x3, 0x3b, 0x4, 0x51, 0xeb, 0x6a, 0xfd, 0x41, 0x5, 0x0, 0x6, 0x34,
+ 0xff, 0x26, 0xf8, 0x24, 0x5, 0xac, 0x4, 0xba, 0x4, 0x2, 0xfa, 0xb3, 0x3,
+ 0x97, 0x1, 0xe2, 0x5, 0x50, 0x0, 0xd9, 0x9, 0xb2, 0xb, 0x88, 0x3, 0xe6,
+ 0x0, 0x2d, 0x0, 0xb6, 0x4, 0x11, 0x6, 0x31, 0xfd, 0x78, 0x1, 0xe6, 0x6,
+ 0xa5, 0xf9, 0x2c, 0x1, 0xb5, 0xf8, 0x0, 0x3, 0x8e, 0xf6, 0xba, 0xfc, 0x68,
+ 0xf9, 0x39, 0x1, 0x6e, 0x0, 0xff, 0xff, 0xcf, 0xfa, 0xc7, 0x0, 0xf, 0xfc,
+ 0x26, 0x3, 0xac, 0xfb, 0xc, 0x4, 0x32, 0x5, 0xe6, 0xfd, 0x98, 0x4, 0x82,
+ 0x2, 0x1d, 0x2, 0x28, 0x1, 0x4, 0x6, 0xdc, 0xfa, 0x3a, 0xfd, 0xf7, 0x1,
+ 0xf9, 0x5, 0x6a, 0xfe, 0x7, 0x0, 0x2d, 0x0, 0x98, 0xff, 0x68, 0xf8, 0xd0,
+ 0xfe, 0x91, 0x0, 0x3c, 0x4, 0xf3, 0xf7, 0x34, 0x3, 0x95, 0x3, 0x81, 0x1,
+ 0x22, 0xfa, 0x87, 0x1, 0x6c, 0xff, 0x31, 0x0, 0xa1, 0xfd, 0xc2, 0x1, 0xf1,
+ 0xfc, 0x1f, 0x3, 0x5b, 0xfd, 0x9d, 0x0, 0x43, 0xff, 0xfb, 0xfe, 0xd2,
+ 0xfb, 0x3, 0xff, 0x2f, 0xfd, 0xc2, 0x1, 0x8e, 0xfc, 0xee, 0xff, 0x98,
+ 0xff, 0x1d, 0xff, 0x10, 0xf8, 0x23, 0xff, 0x66, 0x1, 0x20, 0x0, 0xcb,
+ 0xfc, 0x23, 0x1, 0x37, 0x2, 0xf7, 0xfd, 0xce, 0xfb, 0xfd, 0x0, 0x62, 0xff,
+ 0x3e, 0xfe, 0x5d, 0xfe, 0xae, 0x0, 0xe0, 0xfc, 0xc2, 0x0, 0x7b, 0xff,
+ 0x96, 0x0, 0x20, 0xff, 0xe2, 0xfe, 0xed, 0xfc, 0xc, 0x0, 0x21, 0xff, 0xc5,
+ 0x0, 0x31, 0xfd, 0xcb, 0xfe, 0x7d, 0x0, 0x91, 0xfe, 0x80, 0xfa, 0x7b,
+ 0xff, 0xce, 0x0, 0x7d, 0xfe, 0xc, 0xfe, 0x93, 0x1, 0xdc, 0xff, 0xbe, 0xfd,
+ 0x33, 0xfd, 0xd7, 0x0, 0x5f, 0xff, 0xc4, 0xfe, 0xbc, 0xfe, 0x5f, 0x0,
+ 0x8c, 0xff, 0x99, 0xfe, 0xc3, 0xfd, 0x4f, 0x0, 0x7, 0xff, 0xba, 0xfe,
+ 0x2d, 0xfd, 0xd, 0x0, 0x47, 0xff, 0x62, 0x0, 0x34, 0xfe, 0xad, 0xfe, 0x23,
+ 0x1, 0xee, 0xfd, 0xd0, 0xfb, 0x3d, 0xff, 0x96, 0x0, 0x7d, 0xfe, 0x40,
+ 0xfe, 0x9, 0x0, 0xfe, 0x0, 0xee, 0xfd, 0x6c, 0xfd, 0x1e, 0x0, 0xe9, 0x0,
+ 0x66, 0xfe, 0xf1, 0xfe, 0xef, 0x0, 0x51, 0xff, 0x2, 0xff, 0x53, 0xfe,
+ 0x4b, 0xff, 0x4e, 0xff, 0xa5, 0xff, 0xf1, 0xfd, 0x41, 0xff, 0xa, 0x0,
+ 0xc4, 0xfe, 0xeb, 0xfd, 0xe0, 0xff, 0xc7, 0xff, 0xe9, 0xfd, 0x7c, 0xfd,
+ 0x83, 0xff, 0x7b, 0x0, 0x7d, 0xfe, 0x45, 0xff, 0x4d, 0x0, 0x83, 0x0, 0x47,
+ 0xfd, 0x1b, 0xfe, 0xca, 0x0, 0xd1, 0xfe, 0x2b, 0xff, 0xab, 0xff, 0xfd,
+ 0xff, 0xe2, 0xff, 0xe0, 0xfe, 0x4b, 0xfe, 0x11, 0x0, 0xed, 0xff, 0xc2,
+ 0xfe, 0x7d, 0xfe, 0xb1, 0x0, 0xaa, 0xff, 0xdc, 0xfe, 0x98, 0xfe, 0x92,
+ 0xff, 0xb2, 0x0, 0x3a, 0xfe, 0xd7, 0xfd, 0xba, 0xff, 0xe8, 0xff, 0x44,
+ 0xfe, 0xf4, 0xfe, 0x8, 0x0, 0x73, 0xff, 0x46, 0xfe, 0x8c, 0xfe, 0xd7,
+ 0xff, 0xf1, 0xff, 0xea, 0xfe, 0x80, 0xff, 0x4b, 0x0, 0xa6, 0xff, 0x60,
+ 0xfe, 0xf7, 0xfe, 0xed, 0xff, 0x61, 0xff, 0x8f, 0xff, 0xca, 0xff, 0xc1,
+ 0xff, 0x2a, 0x0, 0x6c, 0xfe, 0xe6, 0xfe, 0x0, 0x0, 0xc8, 0xff, 0x28, 0xfe,
+ 0xb, 0xff, 0xb5, 0xff, 0x3, 0x0, 0xde, 0xfe, 0xd8, 0xff, 0x60, 0xff, 0x91,
+ 0x0, 0x19, 0xfe, 0x1e, 0xff, 0x4e, 0x0, 0x97, 0xff, 0xdb, 0xfe, 0x17, 0x0,
+ 0x16, 0x0, 0xfc, 0xff, 0xcf, 0xfe, 0x5c, 0xff, 0xaa, 0xff, 0x4d, 0x0,
+ 0xb0, 0xfe, 0xc5, 0xff, 0x54, 0x0, 0x98, 0xff, 0x61, 0xfe, 0xae, 0xff,
+ 0xab, 0xff, 0x4, 0x0, 0xc6, 0xfe, 0xce, 0xff, 0xc3, 0xff, 0x3c, 0x0, 0x1d,
+ 0xfe, 0xf2, 0xff, 0x2d, 0x0, 0x8d, 0xff, 0x83, 0xfe, 0x34, 0x0, 0xcc,
+ 0xff, 0x29, 0x0, 0xfd, 0xfe, 0x4d, 0x0, 0xee, 0xff, 0x28, 0x0, 0x2b, 0xfe,
+ 0xb0, 0xff, 0x12, 0x0, 0x99, 0xff, 0x33, 0xff, 0x84, 0x0, 0xa7, 0xff,
+ 0x55, 0x0, 0xa1, 0xfe, 0xc5, 0xff, 0xc2, 0xff, 0xf4, 0xff, 0x81, 0xfe,
+ 0x38, 0x0, 0x29, 0x0, 0xac, 0xff, 0xe3, 0xfe, 0x76, 0x0, 0xb3, 0xff, 0x52,
+ 0x0, 0xa6, 0xfe, 0x25, 0x0, 0x1f, 0x0, 0xee, 0xff, 0x93, 0xfe, 0x6a, 0x0,
+ 0x36, 0x0, 0xbc, 0xff, 0xe0, 0xfe, 0x3f, 0x0, 0x9e, 0xff, 0x6b, 0x0, 0xbe,
+ 0xfe, 0x31, 0x0, 0x19, 0x0, 0xf3, 0xff, 0x58, 0xfe, 0x2, 0x0, 0xf8, 0xff,
+ 0xd5, 0xff, 0xa, 0xff, 0x6d, 0x0, 0xcc, 0xff, 0x6d, 0x0, 0x70, 0xfe, 0xfb,
+ 0xff, 0x41, 0x0, 0xbf, 0xff, 0xcd, 0xfe, 0x62, 0x0, 0xe, 0x0, 0xf4, 0xff,
+ 0x20, 0xff, 0x3a, 0x0, 0xe4, 0xff, 0x4c, 0x0, 0x92, 0xfe, 0xe0, 0xff,
+ 0x41, 0x0, 0xcc, 0xff, 0xa, 0xff, 0x68, 0x0, 0xb, 0x0, 0x31, 0x0, 0x6,
+ 0xff, 0xa, 0x0, 0xfc, 0xff, 0x49, 0x0, 0xca, 0xfe, 0x4c, 0x0, 0x6a, 0x0,
+ 0xb9, 0xff, 0xff, 0xfe, 0x6d, 0x0, 0x6, 0x0, 0xb, 0x0, 0x21, 0xff, 0x4e,
+ 0x0, 0xfc, 0xff, 0x10, 0x0, 0xa0, 0xfe, 0x1e, 0x0, 0x3b, 0x0, 0x8c, 0xff,
+ 0x1c, 0xff, 0x5a, 0x0, 0xdf, 0xff, 0x22, 0x0, 0x13, 0xff, 0x24, 0x0, 0x5,
+ 0x0, 0xff, 0xff, 0xcf, 0xfe, 0x11, 0x0, 0x24, 0x0, 0xb7, 0xff, 0x62, 0xff,
+ 0x60, 0x0, 0xcb, 0xff, 0x55, 0x0, 0x8, 0xff, 0xdd, 0xff, 0x14, 0x0, 0xfa,
+ 0xff, 0x26, 0xff, 0x2b, 0x0, 0x35, 0x0, 0xe8, 0xff, 0x62, 0xff, 0x20, 0x0,
+ 0xd0, 0xff, 0x5c, 0x0, 0x25, 0xff, 0xf3, 0xff, 0x1e, 0x0, 0xf9, 0xff,
+ 0x24, 0xff, 0x2b, 0x0, 0x16, 0x0, 0xea, 0xff, 0x5e, 0xff, 0x1b, 0x0, 0xbe,
+ 0xff, 0x37, 0x0, 0x11, 0xff, 0xfe, 0xff, 0x18, 0x0, 0xc3, 0xff, 0x23,
+ 0xff, 0x28, 0x0, 0x9, 0x0, 0xe8, 0xff, 0x6b, 0xff, 0x2a, 0x0, 0xe1, 0xff,
+ 0x27, 0x0, 0x0, 0xff, 0xf5, 0xff, 0x22, 0x0, 0xb1, 0xff, 0x60, 0xff, 0x56,
+ 0x0, 0xf2, 0xff, 0xe, 0x0, 0x59, 0xff, 0x9, 0x0, 0xde, 0xff, 0x20, 0x0,
+ 0x21, 0xff, 0x2, 0x0, 0x24, 0x0, 0xc4, 0xff, 0x76, 0xff, 0x3e, 0x0, 0xe7,
+ 0xff, 0x27, 0x0, 0x5c, 0xff, 0xf0, 0xff, 0xec, 0xff, 0x16, 0x0, 0x3d,
+ 0xff, 0x16, 0x0, 0x2d, 0x0, 0xc9, 0xff, 0x76, 0xff, 0x29, 0x0, 0xd4, 0xff,
+ 0x27, 0x0, 0x5f, 0xff, 0xfd, 0xff, 0xf6, 0xff, 0xfb, 0xff, 0x3f, 0xff,
+ 0x13, 0x0, 0x25, 0x0, 0xd0, 0xff, 0x95, 0xff, 0x35, 0x0, 0xcf, 0xff, 0x35,
+ 0x0, 0x4b, 0xff, 0xe7, 0xff, 0x4, 0x0, 0xdc, 0xff, 0x54, 0xff, 0x18, 0x0,
+ 0x15, 0x0, 0xe4, 0xff, 0x8a, 0xff, 0x1e, 0x0, 0xc9, 0xff, 0x37, 0x0, 0x4e,
+ 0xff, 0xf4, 0xff, 0xb, 0x0, 0xd2, 0xff, 0x83, 0xff, 0x41, 0x0, 0x15, 0x0,
+ 0xf4, 0xff, 0x78, 0xff, 0xfb, 0xff, 0xe6, 0xff, 0x30, 0x0, 0x58, 0xff,
+ 0xf6, 0xff, 0x9, 0x0, 0xd7, 0xff, 0x75, 0xff, 0x1c, 0x0, 0xed, 0xff, 0xf6,
+ 0xff, 0x7c, 0xff, 0xf3, 0xff, 0xf6, 0xff, 0x24, 0x0, 0x57, 0xff, 0xf7,
+ 0xff, 0xa, 0x0, 0xd9, 0xff, 0x67, 0xff, 0x1, 0x0, 0xe3, 0xff, 0x3, 0x0,
+ 0x61, 0xff, 0xdb, 0xff, 0xa, 0x0, 0x16, 0x0, 0x4d, 0xff, 0xf1, 0xff, 0xff,
+ 0xff, 0xdb, 0xff, 0x93, 0xff, 0x23, 0x0, 0xd8, 0xff, 0x11, 0x0, 0x88,
+ 0xff, 0x3, 0x0, 0xb, 0x0, 0x19, 0x0, 0x7f, 0xff, 0x21, 0x0, 0xe, 0x0,
+ 0xfa, 0xff, 0xa3, 0xff, 0x24, 0x0, 0xee, 0xff, 0x1b, 0x0, 0x99, 0xff,
+ 0x15, 0x0, 0xf8, 0xff, 0xe, 0x0, 0x8a, 0xff, 0x27, 0x0, 0xf0, 0xff, 0xf0,
+ 0xff, 0xaf, 0xff, 0x1e, 0x0, 0xf8, 0xff, 0x12, 0x0, 0xab, 0xff, 0x23, 0x0,
+ 0x4, 0x0, 0x5, 0x0, 0x9b, 0xff, 0x2e, 0x0, 0xf5, 0xff, 0xf5, 0xff, 0xcc,
+ 0xff, 0x38, 0x0, 0x4, 0x0, 0x1a, 0x0, 0xa2, 0xff, 0x24, 0x0, 0xf8, 0xff,
+ 0x0, 0x0, 0xa9, 0xff, 0x3b, 0x0, 0xe7, 0xff, 0xff, 0xff, 0xc4, 0xff, 0x33,
+ 0x0, 0x0, 0x0, 0x19, 0x0, 0x98, 0xff, 0x25, 0x0, 0xf5, 0xff, 0xff, 0xff,
+ 0xb4, 0xff, 0x45, 0x0, 0xed, 0xff, 0x5, 0x0, 0xc1, 0xff, 0x2a, 0x0, 0x5,
+ 0x0, 0x15, 0x0, 0xae, 0xff, 0x27, 0x0, 0xef, 0xff, 0x0, 0x0, 0xc8, 0xff,
+ 0x39, 0x0, 0xea, 0xff, 0xb, 0x0, 0xcb, 0xff, 0x23, 0x0, 0x7, 0x0, 0x15,
+ 0x0, 0xb3, 0xff, 0x1a, 0x0, 0xec, 0xff, 0x1, 0x0, 0xd5, 0xff, 0x2a, 0x0,
+ 0xf4, 0xff, 0x12, 0x0, 0xc9, 0xff, 0x16, 0x0, 0x6, 0x0, 0xb, 0x0, 0xbc,
+ 0xff, 0x14, 0x0, 0xeb, 0xff, 0xfe, 0xff, 0xe3, 0xff, 0x27, 0x0, 0x1, 0x0,
+ 0x12, 0x0, 0xc5, 0xff, 0xb, 0x0, 0x6, 0x0, 0x5, 0x0, 0xc9, 0xff, 0x14,
+ 0x0, 0xef, 0xff, 0x2, 0x0, 0xe1, 0xff, 0x19, 0x0, 0x3, 0x0, 0x16, 0x0,
+ 0xc1, 0xff, 0x6, 0x0, 0x2, 0x0, 0x2, 0x0, 0xce, 0xff, 0x14, 0x0, 0xef,
+ 0xff, 0x0, 0x0, 0xe1, 0xff, 0x16, 0x0, 0x6, 0x0, 0x13, 0x0, 0xc3, 0xff,
+ 0x7, 0x0, 0x1, 0x0, 0xfd, 0xff, 0xd4, 0xff, 0x14, 0x0, 0xee, 0xff, 0x4,
+ 0x0, 0xe0, 0xff, 0x10, 0x0, 0x6, 0x0, 0x10, 0x0, 0xc1, 0xff, 0x1, 0x0,
+ 0xfa, 0xff, 0xf8, 0xff, 0xdb, 0xff, 0x14, 0x0, 0xf3, 0xff, 0x5, 0x0, 0xdc,
+ 0xff, 0x9, 0x0, 0x9, 0x0, 0xb, 0x0, 0xc3, 0xff, 0x2, 0x0, 0xf8, 0xff,
+ 0xf7, 0xff, 0xe1, 0xff, 0x12, 0x0, 0xf8, 0xff, 0x8, 0x0, 0xda, 0xff, 0x4,
+ 0x0, 0x7, 0x0, 0xa, 0x0, 0xc8, 0xff, 0x2, 0x0, 0xf4, 0xff, 0xf9, 0xff,
+ 0xe4, 0xff, 0xd, 0x0, 0xf9, 0xff, 0xe, 0x0, 0xd5, 0xff, 0xfe, 0xff, 0x7,
+ 0x0, 0x8, 0x0, 0xcb, 0xff, 0x3, 0x0, 0xf4, 0xff, 0xfb, 0xff, 0xe6, 0xff,
+ 0xc, 0x0, 0xfd, 0xff, 0xe, 0x0, 0xd2, 0xff, 0xfe, 0xff, 0x3, 0x0, 0x3,
+ 0x0, 0xd1, 0xff, 0x6, 0x0, 0xf1, 0xff, 0xfd, 0xff, 0xe5, 0xff, 0x9, 0x0,
+ 0xff, 0xff, 0xf, 0x0, 0xce, 0xff, 0xfc, 0xff, 0xff, 0xff, 0x1, 0x0, 0xd4,
+ 0xff, 0x7, 0x0, 0xf3, 0xff, 0xff, 0xff, 0xe4, 0xff, 0x7, 0x0, 0x1, 0x0,
+ 0xd, 0x0, 0xce, 0xff, 0xfc, 0xff, 0xfd, 0xff, 0xfe, 0xff, 0xda, 0xff, 0x9,
+ 0x0, 0xf5, 0xff, 0x2, 0x0, 0xe2, 0xff, 0x4, 0x0, 0x2, 0x0, 0xd, 0x0, 0xcd,
+ 0xff, 0xfc, 0xff, 0xfb, 0xff, 0xfc, 0xff, 0xdf, 0xff, 0x8, 0x0, 0xf6,
+ 0xff, 0x4, 0x0, 0xdf, 0xff, 0xff, 0xff, 0x3, 0x0, 0xa, 0x0, 0xd0, 0xff,
+ 0xfd, 0xff, 0xf9, 0xff, 0xfb, 0xff, 0xe2, 0xff, 0x7, 0x0, 0xf9, 0xff, 0x6,
+ 0x0, 0xdd, 0xff, 0xfe, 0xff, 0x3, 0x0, 0x7, 0x0, 0xd3, 0xff, 0xff, 0xff,
+ 0xf8, 0xff, 0xfb, 0xff, 0xe4, 0xff, 0x6, 0x0, 0xfb, 0xff, 0x7, 0x0, 0xdb,
+ 0xff, 0xfc, 0xff, 0x1, 0x0, 0x4, 0x0, 0xd5, 0xff, 0x0, 0x0, 0xf8, 0xff,
+ 0xfc, 0xff, 0xe7, 0xff, 0x5, 0x0, 0xfd, 0xff, 0x9, 0x0, 0xd9, 0xff, 0xfb,
+ 0xff, 0x1, 0x0, 0x2, 0x0, 0xda, 0xff, 0x2, 0x0, 0xf7, 0xff, 0xfd, 0xff,
+ 0xe6, 0xff, 0x3, 0x0, 0xff, 0xff, 0x9, 0x0, 0xd8, 0xff, 0xfb, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xde, 0xff, 0x4, 0x0, 0xf8, 0xff, 0xff, 0xff, 0xe6,
+ 0xff, 0x2, 0x0, 0x0, 0x0, 0x8, 0x0, 0xd8, 0xff, 0xfd, 0xff, 0xfd, 0xff,
+ 0xfe, 0xff, 0xe1, 0xff, 0x5, 0x0, 0xf9, 0xff, 0x0, 0x0, 0xe5, 0xff, 0x1,
+ 0x0, 0x0, 0x0, 0x7, 0x0, 0xd9, 0xff, 0xfe, 0xff, 0xfc, 0xff, 0xfd, 0xff,
+ 0xe4, 0xff, 0x6, 0x0, 0xfa, 0xff, 0x2, 0x0, 0xe3, 0xff, 0x0, 0x0, 0x0,
+ 0x0, 0x6, 0x0, 0xdb, 0xff, 0x0, 0x0, 0xfb, 0xff, 0xfc, 0xff, 0xe7, 0xff,
+ 0x6, 0x0, 0xfc, 0xff, 0x4, 0x0, 0xe1, 0xff, 0xff, 0xff, 0x0, 0x0, 0x4,
+ 0x0, 0xdd, 0xff, 0x2, 0x0, 0xfa, 0xff, 0xfd, 0xff, 0xe7, 0xff, 0x5, 0x0,
+ 0xfc, 0xff, 0x5, 0x0, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x2, 0x0, 0xdf,
+ 0xff, 0x3, 0x0, 0xfa, 0xff, 0xfe, 0xff, 0xe8, 0xff, 0x5, 0x0, 0xfe, 0xff,
+ 0x5, 0x0, 0xe0, 0xff, 0xff, 0xff, 0xfe, 0xff, 0x1, 0x0, 0xe1, 0xff, 0x4,
+ 0x0, 0xfb, 0xff, 0xff, 0xff, 0xe8, 0xff, 0x4, 0x0, 0xff, 0xff, 0x6, 0x0,
+ 0xde, 0xff, 0xff, 0xff, 0xfe, 0xff, 0x0, 0x0, 0xe1, 0xff, 0x5, 0x0, 0xfb,
+ 0xff, 0x1, 0x0, 0xe2, 0xff, 0x3, 0x0, 0xff, 0xff, 0x4, 0x0, 0xdb, 0xff,
+ 0x1, 0x0, 0xfd, 0xff, 0x0, 0x0, 0xdd, 0xff, 0x4, 0x0, 0xfd, 0xff, 0x1,
+ 0x0, 0xdc, 0xff, 0x2, 0x0, 0xfe, 0xff, 0x3, 0x0, 0xd9, 0xff, 0x2, 0x0,
+ 0xfd, 0xff, 0x0, 0x0, 0xdb, 0xff, 0x3, 0x0, 0xfd, 0xff, 0x2, 0x0, 0xdb,
+ 0xff, 0x2, 0x0, 0xfe, 0xff, 0x2, 0x0, 0xdb, 0xff, 0x2, 0x0, 0xfd, 0xff,
+ 0x1, 0x0, 0xdd, 0xff, 0x2, 0x0, 0xfd, 0xff, 0x2, 0x0, 0xde, 0xff, 0x2,
+ 0x0, 0xfe, 0xff, 0x2, 0x0, 0xe1, 0xff, 0x1, 0x0, 0xfe, 0xff, 0x1, 0x0,
+ 0xe3, 0xff, 0x1, 0x0, 0xfe, 0xff, 0x1, 0x0}},
+ {"WAV/Subject_002/SH/sh_hrir_order_2.wav",
+ {0x52, 0x49, 0x46, 0x46, 0x24, 0x12, 0x0, 0x0, 0x57, 0x41, 0x56, 0x45,
+ 0x66, 0x6d, 0x74, 0x20, 0x10, 0x0, 0x0, 0x0, 0x1, 0x0, 0x9, 0x0, 0x80,
+ 0xbb, 0x0, 0x0, 0x0, 0x2f, 0xd, 0x0, 0x12, 0x0, 0x10, 0x0, 0x64, 0x61,
+ 0x74, 0x61, 0x0, 0x12, 0x0, 0x0, 0xfe, 0xff, 0x4, 0x0, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xf3,
+ 0xff, 0x19, 0x0, 0xfd, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0x0, 0x0, 0xff, 0xff,
+ 0xfe, 0xff, 0xfa, 0xff, 0xfa, 0xff, 0xc, 0x0, 0xfe, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xfe, 0xff,
+ 0x3, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0xff, 0xff, 0xfe, 0xff, 0xa, 0x0, 0xff, 0xff, 0x1, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0xfe, 0xff, 0xfe, 0xff, 0xfd, 0xff, 0x4, 0x0, 0xfd, 0xff, 0x1, 0x0,
+ 0xfd, 0xff, 0xfe, 0xff, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x3, 0x0,
+ 0x3, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0xfc, 0xff, 0xfd, 0xff,
+ 0xfe, 0xff, 0x4, 0x0, 0xec, 0xff, 0x1, 0x0, 0x5, 0x0, 0x7, 0x0, 0xff,
+ 0xff, 0x9, 0x0, 0x9, 0x0, 0x9, 0x0, 0xfc, 0xff, 0xf2, 0xff, 0x5, 0x0,
+ 0xf7, 0xff, 0xf5, 0xff, 0x5, 0x0, 0xfd, 0xff, 0xfa, 0xff, 0x4, 0x0, 0xf3,
+ 0xff, 0xc7, 0xff, 0xfa, 0xff, 0x1d, 0x0, 0x23, 0x0, 0xf2, 0xff, 0xf, 0x0,
+ 0x7, 0x0, 0x19, 0x0, 0x47, 0xff, 0x74, 0xfe, 0xd9, 0xff, 0xfd, 0xff, 0x9,
+ 0x0, 0xdb, 0xff, 0xa4, 0x0, 0x65, 0x0, 0xb6, 0x0, 0x86, 0xfe, 0xff, 0xfc,
+ 0x13, 0x0, 0xdc, 0xff, 0xd0, 0xff, 0x18, 0x0, 0x19, 0x1, 0x93, 0x0, 0x5b,
+ 0x1, 0xc0, 0x1, 0x6b, 0x3, 0xa3, 0x0, 0x4f, 0xff, 0x1b, 0xff, 0xbb, 0x0,
+ 0x8e, 0xfe, 0x2f, 0xff, 0x56, 0xfe, 0x3, 0x6, 0x37, 0xc, 0xa1, 0xff, 0x47,
+ 0x0, 0x63, 0x0, 0x96, 0xff, 0x95, 0xfa, 0x9a, 0xfc, 0x1f, 0xfa, 0xa9,
+ 0xfd, 0xff, 0xfb, 0xa3, 0xff, 0xfe, 0x0, 0x3d, 0x1, 0x70, 0xff, 0x74, 0x0,
+ 0x71, 0xff, 0x67, 0x1, 0x6e, 0xf7, 0x70, 0xef, 0xa3, 0xff, 0xbe, 0xff,
+ 0xd7, 0xff, 0xb4, 0xff, 0xf7, 0x5, 0xd9, 0x2, 0x68, 0x7, 0x93, 0x2, 0x3a,
+ 0x2, 0x67, 0xfb, 0xe2, 0xff, 0xd9, 0x0, 0xd6, 0xfb, 0xcf, 0x2, 0x5c, 0x4,
+ 0x94, 0x0, 0x7e, 0x2, 0xbb, 0x2, 0x6f, 0x3, 0xf7, 0xfc, 0x1, 0xfc, 0xc8,
+ 0x3, 0x23, 0x2, 0xd3, 0x3, 0xed, 0xff, 0x74, 0xfc, 0x11, 0xfb, 0xb0, 0xc,
+ 0x90, 0x9, 0x42, 0x8, 0x25, 0x9, 0xd, 0xff, 0xdf, 0xfd, 0x11, 0x1, 0x54,
+ 0xfb, 0xb1, 0xf7, 0x22, 0xfa, 0xfa, 0x2, 0xe5, 0x4, 0xfe, 0xf9, 0xc2, 0x2,
+ 0x3b, 0x1, 0xfb, 0x2, 0x65, 0xf4, 0x1a, 0xee, 0xc5, 0xf4, 0x5d, 0xe7,
+ 0x45, 0xe6, 0x84, 0xfc, 0xa1, 0x2, 0x61, 0xfc, 0x4a, 0x4, 0xcd, 0xfc,
+ 0x45, 0xfd, 0x38, 0x6, 0x17, 0x6, 0x21, 0x3, 0xbf, 0x5, 0x55, 0xfd, 0x37,
+ 0xfc, 0x9e, 0xfe, 0x9a, 0x7, 0xea, 0xa, 0xcd, 0xfd, 0xb7, 0xd, 0xb8, 0xc,
+ 0x47, 0xfa, 0xde, 0xf8, 0x67, 0xff, 0x8a, 0xfe, 0x49, 0x8, 0x89, 0x13,
+ 0x93, 0xfb, 0xc9, 0xf6, 0x9e, 0xfc, 0x89, 0xfb, 0x1a, 0xed, 0xf0, 0xec,
+ 0xb0, 0xf4, 0x20, 0x5, 0xde, 0xd, 0x7a, 0xb, 0x5f, 0xff, 0x9d, 0x6, 0x50,
+ 0x6, 0x31, 0xff, 0xc9, 0xfb, 0xc9, 0xf3, 0x41, 0x1, 0x8b, 0xfd, 0x9f, 0x0,
+ 0x43, 0x4, 0xf6, 0xf9, 0xae, 0xfe, 0x72, 0x1, 0xc0, 0x5, 0x91, 0x4, 0xcd,
+ 0x6, 0xff, 0x10, 0x81, 0xf2, 0x62, 0xa, 0x50, 0xa, 0xd9, 0xf7, 0x86, 0xf8,
+ 0xdd, 0x7, 0x5d, 0xf8, 0x71, 0x0, 0xa1, 0xb, 0x1b, 0xfd, 0x37, 0xf7, 0x65,
+ 0x7, 0xff, 0xff, 0x19, 0xe, 0x1e, 0x16, 0x62, 0xf1, 0x64, 0x4, 0xd4, 0x3,
+ 0xb1, 0xe, 0x35, 0x0, 0x71, 0xf8, 0xe8, 0x9, 0xba, 0x3, 0x6b, 0x3, 0x3d,
+ 0x0, 0xfb, 0x8, 0x1d, 0x14, 0xda, 0xa, 0x44, 0xf, 0xad, 0x4, 0xec, 0x9,
+ 0xb3, 0xfb, 0xe2, 0x1, 0x1, 0xf6, 0xb1, 0xf9, 0xf9, 0x2, 0xc0, 0xf8, 0x4e,
+ 0xf2, 0x27, 0xf5, 0x86, 0xff, 0xee, 0xff, 0xdc, 0xff, 0xf5, 0xf4, 0xc8,
+ 0x5, 0x26, 0x4, 0x7d, 0xf0, 0x1a, 0xf6, 0xce, 0xf6, 0xda, 0xf8, 0xce,
+ 0xfd, 0x2d, 0xfd, 0xc, 0x3, 0xd1, 0x9, 0x20, 0x4, 0x0, 0xf9, 0x11, 0x5,
+ 0x9, 0x0, 0x1c, 0xfc, 0xa7, 0x2, 0x89, 0x1, 0x9c, 0x6, 0x65, 0x1, 0xd1,
+ 0xf3, 0x1, 0xc, 0xcc, 0xc, 0xb0, 0x4, 0x61, 0x1, 0xd8, 0xfe, 0x2b, 0xf8,
+ 0x93, 0x10, 0xd8, 0x8, 0xcd, 0x0, 0xca, 0x8, 0xaa, 0x0, 0x17, 0x5, 0xd,
+ 0x0, 0xa9, 0x3, 0xa5, 0xff, 0xd0, 0xc, 0x27, 0x8, 0xb0, 0x5, 0x73, 0x0,
+ 0xa8, 0xfa, 0xbf, 0x0, 0x5c, 0x0, 0x2b, 0x2, 0x13, 0xfd, 0x99, 0x7, 0xb8,
+ 0x2, 0x51, 0x2, 0xa1, 0x0, 0x65, 0x1, 0x6, 0x3, 0x6d, 0x3, 0x3f, 0xfd,
+ 0x74, 0xfd, 0x8e, 0x7, 0xb2, 0xfb, 0x49, 0xfc, 0xdb, 0xf8, 0x4, 0xf9,
+ 0x16, 0xf9, 0x91, 0xfe, 0x49, 0xfe, 0xe, 0xff, 0xb9, 0x1, 0xff, 0xfb,
+ 0x2b, 0xfb, 0xae, 0xfc, 0x1f, 0xff, 0x4c, 0xfe, 0x17, 0xfd, 0xf8, 0xfd,
+ 0xc5, 0xfb, 0xd7, 0x3, 0x5f, 0xfb, 0xe9, 0xfc, 0xb8, 0x0, 0xf4, 0xfa,
+ 0x3a, 0x2, 0xf, 0xfe, 0xa9, 0x2, 0x7d, 0xfd, 0xba, 0x2, 0x68, 0xfe, 0x16,
+ 0xfa, 0xf, 0x2, 0x14, 0x0, 0x1b, 0x1, 0xe5, 0xff, 0xe2, 0x1, 0xce, 0xfa,
+ 0x1f, 0x5, 0xd, 0x5, 0x5c, 0x1, 0xd, 0x7, 0x37, 0x3, 0x91, 0x4, 0x2a, 0x2,
+ 0xbb, 0x2, 0x5c, 0x1, 0x71, 0x5, 0x25, 0x0, 0xc9, 0xfc, 0x21, 0x5, 0xf2,
+ 0xfc, 0x5d, 0xfe, 0xad, 0x0, 0x48, 0x3, 0x14, 0x2, 0x74, 0x3, 0x9d, 0x1,
+ 0xe7, 0xfe, 0x13, 0xff, 0x74, 0x3, 0x3f, 0xfc, 0xa6, 0xff, 0xf7, 0x2,
+ 0x17, 0x6, 0x6e, 0x1, 0xc4, 0xfe, 0x66, 0xfe, 0x99, 0xfb, 0x74, 0xff,
+ 0xd9, 0xfa, 0x11, 0xfc, 0x7, 0x3, 0xd8, 0x4, 0x3c, 0xfe, 0xcd, 0xfb, 0xd5,
+ 0xf6, 0x5c, 0x0, 0xb2, 0x2, 0x58, 0xff, 0x61, 0xfe, 0x2e, 0x2, 0x76, 0xff,
+ 0xd8, 0x1, 0xc6, 0xfc, 0xcc, 0xfc, 0xfa, 0xfe, 0x42, 0xfe, 0xfd, 0x1,
+ 0x6d, 0x0, 0xf6, 0x2, 0x61, 0xff, 0x18, 0x0, 0xed, 0xfe, 0x12, 0xfa, 0xad,
+ 0x0, 0x3a, 0xff, 0x2e, 0x2, 0xe9, 0x0, 0xac, 0x0, 0x55, 0xfc, 0x9c, 0x2,
+ 0x6a, 0x4, 0x10, 0xfb, 0x64, 0x2, 0x88, 0x1, 0x43, 0x1, 0xa3, 0x2, 0x44,
+ 0x0, 0x8e, 0x1, 0xe0, 0x0, 0x49, 0x2, 0xdd, 0xfa, 0x1e, 0xfd, 0x35, 0xff,
+ 0xa3, 0xfd, 0xb4, 0xff, 0xbd, 0xfe, 0xe8, 0x0, 0xff, 0xfd, 0xf6, 0xff,
+ 0xb0, 0xf9, 0xed, 0xff, 0xa8, 0x4, 0xed, 0xff, 0xdd, 0xff, 0x5b, 0xff,
+ 0x6c, 0x2, 0xc9, 0xfe, 0x70, 0xfc, 0x90, 0xfb, 0x3, 0xfe, 0xe6, 0xfc,
+ 0xe9, 0xfd, 0xf2, 0xfd, 0xec, 0x0, 0xc4, 0x1, 0x13, 0xfc, 0xdb, 0xfd,
+ 0xe7, 0xf9, 0x4f, 0xfe, 0x2f, 0x0, 0xae, 0xff, 0x55, 0xff, 0x7b, 0xff,
+ 0x3c, 0xfe, 0xc0, 0xff, 0x1a, 0xfe, 0x2f, 0xfc, 0xe5, 0x0, 0xe4, 0xfe,
+ 0xa7, 0x1, 0x85, 0x1, 0x3a, 0x0, 0x4f, 0xfe, 0xe9, 0xfd, 0x12, 0xfe, 0xfc,
+ 0xfa, 0x8a, 0x1, 0x3b, 0xfe, 0xee, 0x1, 0x7e, 0x0, 0x1d, 0x0, 0x7d, 0xfd,
+ 0x9, 0x0, 0x51, 0x1, 0xa0, 0xfc, 0xcb, 0x1, 0x18, 0x1, 0x73, 0x2, 0x58,
+ 0x1, 0xfe, 0xff, 0x4b, 0x1, 0x7b, 0x1, 0xd7, 0xfe, 0x2, 0xfe, 0xe4, 0xfe,
+ 0x28, 0xfe, 0xa1, 0xff, 0x20, 0xff, 0x79, 0xff, 0x83, 0x0, 0xe9, 0xfe,
+ 0x4b, 0xff, 0x95, 0xfd, 0xa2, 0xff, 0x78, 0x2, 0xcf, 0xfe, 0xb, 0x0, 0xc8,
+ 0xff, 0xf4, 0x1, 0x8d, 0xff, 0x1a, 0xfd, 0xbf, 0xfd, 0x14, 0xfe, 0xa1,
+ 0xfe, 0xa4, 0xfd, 0xb, 0x1, 0x74, 0x0, 0x5c, 0x0, 0x3a, 0xfd, 0x23, 0xfe,
+ 0x99, 0xfd, 0x1a, 0xff, 0xf8, 0xff, 0xee, 0xff, 0xb1, 0x0, 0xd, 0x0, 0xed,
+ 0xfe, 0xed, 0xfe, 0xe3, 0xfe, 0x57, 0xfe, 0x37, 0x0, 0x22, 0xff, 0x6e,
+ 0x0, 0x8d, 0x0, 0x25, 0x0, 0xc9, 0xff, 0xcd, 0xfe, 0xbf, 0xfd, 0x81, 0xfd,
+ 0x54, 0x0, 0xe7, 0xff, 0x2, 0x1, 0x83, 0x0, 0xff, 0xff, 0xbd, 0xfe, 0x70,
+ 0xff, 0x91, 0xff, 0xe4, 0xfd, 0xc5, 0x0, 0x45, 0x2, 0x4e, 0x1, 0xcc, 0x0,
+ 0xdb, 0xff, 0x88, 0x0, 0x28, 0xff, 0x39, 0xfe, 0x22, 0xfd, 0x48, 0xff,
+ 0x83, 0x0, 0x9e, 0xff, 0x95, 0xff, 0x69, 0xff, 0x5d, 0xff, 0xaa, 0xfe,
+ 0x30, 0xff, 0x45, 0xfe, 0xbb, 0xff, 0x2a, 0x2, 0xfe, 0xff, 0xaf, 0xff,
+ 0xa4, 0xff, 0xdd, 0x0, 0xf9, 0xfe, 0xe7, 0xfd, 0x50, 0xfe, 0x58, 0xfe,
+ 0xc1, 0xfe, 0xe7, 0xfe, 0x65, 0xff, 0xbb, 0xff, 0xc3, 0xff, 0xc2, 0xfd,
+ 0x2f, 0xfe, 0xab, 0xfd, 0x22, 0x0, 0xf6, 0xff, 0xa0, 0x0, 0xeb, 0xff, 0xc,
+ 0x0, 0x7b, 0xff, 0x9a, 0xff, 0x9a, 0xfe, 0xe8, 0xfd, 0x2e, 0x1, 0x49,
+ 0xff, 0xe5, 0x0, 0x61, 0x0, 0xfd, 0xff, 0xb2, 0xff, 0xfd, 0xfe, 0x79,
+ 0xfe, 0xc0, 0xfd, 0xc4, 0x0, 0x50, 0x0, 0xe2, 0x0, 0xa4, 0x0, 0xaf, 0xff,
+ 0xff, 0xfe, 0xde, 0xff, 0xa4, 0xff, 0xc2, 0xfe, 0x40, 0x0, 0x8e, 0x0, 0xd,
+ 0x1, 0x26, 0x0, 0xd4, 0xff, 0x90, 0x0, 0x68, 0xff, 0xb8, 0xfe, 0x49, 0xfe,
+ 0x5, 0xff, 0xa4, 0xff, 0xb8, 0xff, 0xa1, 0xff, 0x64, 0xff, 0x99, 0xff,
+ 0xeb, 0xfe, 0xd0, 0xfe, 0xe, 0xff, 0x75, 0xff, 0x62, 0x1, 0xc6, 0xff,
+ 0x1d, 0x0, 0xca, 0xff, 0x9d, 0x0, 0x4f, 0xff, 0xd8, 0xfd, 0xb2, 0xfe,
+ 0x4a, 0xfe, 0x28, 0xff, 0x6b, 0xff, 0xdf, 0xff, 0xd1, 0xff, 0x9a, 0xff,
+ 0x2, 0xff, 0x98, 0xfe, 0xf6, 0xfe, 0x8f, 0xff, 0x47, 0x0, 0x6c, 0x0, 0x96,
+ 0x0, 0xf, 0x0, 0xeb, 0xff, 0x11, 0x0, 0x7d, 0xfe, 0xa4, 0xff, 0x3a, 0x0,
+ 0x8b, 0xff, 0x61, 0x0, 0x14, 0x0, 0x10, 0x0, 0xe2, 0xff, 0x75, 0xff, 0xbb,
+ 0xfe, 0x10, 0x0, 0x96, 0x0, 0xd, 0x1, 0x79, 0x0, 0x3d, 0x0, 0xac, 0xff,
+ 0x7c, 0xff, 0x74, 0x0, 0xfb, 0xfe, 0x73, 0x0, 0x57, 0x0, 0xbf, 0x0, 0x59,
+ 0x0, 0xd4, 0xff, 0xf8, 0xff, 0x6e, 0x0, 0xe5, 0xff, 0x61, 0xfe, 0x67,
+ 0xff, 0x22, 0xff, 0x2c, 0x0, 0xe0, 0xff, 0x61, 0xff, 0xeb, 0xff, 0xb7,
+ 0xff, 0x4c, 0x0, 0xae, 0xfe, 0xf, 0x0, 0x9e, 0xff, 0xf7, 0x0, 0xe9, 0xff,
+ 0xf0, 0xff, 0x36, 0x0, 0x67, 0x0, 0x77, 0x0, 0xce, 0xfd, 0xb2, 0xff, 0x46,
+ 0xff, 0x62, 0xff, 0xb3, 0xff, 0x91, 0xff, 0x1e, 0x0, 0x9b, 0xff, 0xe7,
+ 0xff, 0xa2, 0xfe, 0xff, 0xff, 0x18, 0x0, 0x52, 0x0, 0x84, 0x0, 0x31, 0x0,
+ 0x24, 0x0, 0x15, 0x0, 0xc2, 0x0, 0x68, 0xfe, 0x22, 0x0, 0x34, 0x0, 0x28,
+ 0xff, 0x6f, 0x0, 0x11, 0x0, 0x46, 0x0, 0xce, 0xff, 0x42, 0x0, 0xc, 0xff,
+ 0x15, 0x0, 0x16, 0x0, 0x60, 0x0, 0x91, 0x0, 0x5f, 0x0, 0xa, 0x0, 0xf7,
+ 0xff, 0xce, 0x0, 0x2c, 0xff, 0xb, 0x0, 0x88, 0xff, 0xe4, 0xff, 0x14, 0x0,
+ 0x26, 0x0, 0x1a, 0x0, 0x7a, 0x0, 0x4f, 0x0, 0x8d, 0xfe, 0x96, 0xff, 0x4c,
+ 0xff, 0xbc, 0xff, 0xd6, 0xff, 0xc, 0x0, 0x1a, 0x0, 0xec, 0xff, 0x77, 0x0,
+ 0xd6, 0xfe, 0x32, 0x0, 0xce, 0xff, 0x3f, 0x0, 0xf3, 0xff, 0x17, 0x0, 0xa,
+ 0x0, 0x47, 0x0, 0x28, 0x0, 0x53, 0xfe, 0xc1, 0xff, 0xac, 0xff, 0x82, 0xff,
+ 0xbc, 0xff, 0xbd, 0xff, 0xf, 0x0, 0x76, 0xff, 0x33, 0x0, 0xb8, 0xfe, 0x3b,
+ 0x0, 0x2c, 0x0, 0x44, 0x0, 0x33, 0x0, 0x50, 0x0, 0x3f, 0x0, 0x0, 0x0,
+ 0xaa, 0x0, 0x71, 0xfe, 0x55, 0x0, 0xeb, 0xff, 0x88, 0xff, 0x2b, 0x0, 0xf5,
+ 0xff, 0x5, 0x0, 0xb6, 0xff, 0x2f, 0x0, 0xfd, 0xfe, 0x6c, 0x0, 0x26, 0x0,
+ 0x6b, 0x0, 0x31, 0x0, 0x3f, 0x0, 0x12, 0x0, 0x0, 0x0, 0xae, 0x0, 0xda,
+ 0xfe, 0x73, 0x0, 0xcb, 0xff, 0xb4, 0xff, 0xc9, 0xff, 0x1d, 0x0, 0x3b, 0x0,
+ 0x14, 0x0, 0x12, 0x0, 0xe9, 0xfe, 0x2c, 0x0, 0xc5, 0xff, 0x2a, 0x0, 0xef,
+ 0xff, 0xb, 0x0, 0x2a, 0x0, 0xa3, 0xff, 0x56, 0x0, 0xe4, 0xfe, 0x21, 0x0,
+ 0xeb, 0xff, 0x15, 0x0, 0xe5, 0xff, 0x17, 0x0, 0x3e, 0x0, 0x1, 0x0, 0x28,
+ 0x0, 0x5d, 0xfe, 0xfe, 0xff, 0xae, 0xff, 0x99, 0xff, 0xd1, 0xff, 0xf1,
+ 0xff, 0x17, 0x0, 0x9c, 0xff, 0x2d, 0x0, 0xee, 0xfe, 0x9a, 0x0, 0x12, 0x0,
+ 0x32, 0x0, 0x11, 0x0, 0x1d, 0x0, 0x24, 0x0, 0x3, 0x0, 0x4c, 0x0, 0x82,
+ 0xfe, 0x40, 0x0, 0xed, 0xff, 0x8b, 0xff, 0xef, 0xff, 0xe8, 0xff, 0x7, 0x0,
+ 0xf1, 0xff, 0xfd, 0xff, 0xde, 0xfe, 0x71, 0x0, 0x4b, 0x0, 0x4e, 0x0, 0x10,
+ 0x0, 0x51, 0x0, 0xf5, 0xff, 0x60, 0x0, 0x3b, 0x0, 0xd0, 0xfe, 0x32, 0x0,
+ 0xfb, 0xff, 0xd1, 0xff, 0xd9, 0xff, 0x16, 0x0, 0x1, 0x0, 0x25, 0x0, 0xdb,
+ 0xff, 0xac, 0xfe, 0x9, 0x0, 0xf3, 0xff, 0x16, 0x0, 0x11, 0x0, 0x32, 0x0,
+ 0xf0, 0xff, 0x36, 0x0, 0x24, 0x0, 0xa8, 0xfe, 0x6a, 0x0, 0xde, 0xff, 0xcc,
+ 0xff, 0xf2, 0xff, 0x12, 0x0, 0xf1, 0xff, 0x5c, 0x0, 0xf0, 0xff, 0xb9,
+ 0xfe, 0x71, 0x0, 0xbb, 0xff, 0x3, 0x0, 0xf9, 0xff, 0xec, 0xff, 0xee, 0xff,
+ 0xf8, 0xff, 0x2d, 0x0, 0xde, 0xfe, 0x98, 0x0, 0x32, 0x0, 0x2c, 0x0, 0x10,
+ 0x0, 0x2e, 0x0, 0x3, 0x0, 0x64, 0x0, 0x31, 0x0, 0xbc, 0xfe, 0x37, 0x0,
+ 0x19, 0x0, 0xb2, 0xff, 0xef, 0xff, 0xff, 0xff, 0xef, 0xff, 0xfd, 0xff,
+ 0x25, 0x0, 0x35, 0xff, 0x5e, 0x0, 0x4c, 0x0, 0x3c, 0x0, 0x1d, 0x0, 0x2f,
+ 0x0, 0x1d, 0x0, 0x24, 0x0, 0x6c, 0x0, 0xf5, 0xfe, 0x20, 0x0, 0x1c, 0x0,
+ 0xa3, 0xff, 0xf4, 0xff, 0xf9, 0xff, 0x5a, 0x0, 0xf0, 0xff, 0x33, 0x0,
+ 0x35, 0xff, 0x59, 0x0, 0xf5, 0xff, 0x1c, 0x0, 0x22, 0x0, 0x6, 0x0, 0x45,
+ 0x0, 0xfb, 0xff, 0x54, 0x0, 0x0, 0xff, 0x61, 0x0, 0xfc, 0xff, 0xcb, 0xff,
+ 0x12, 0x0, 0x5, 0x0, 0x16, 0x0, 0x48, 0x0, 0x10, 0x0, 0xcc, 0xfe, 0x3d,
+ 0x0, 0x3d, 0x0, 0xe8, 0xff, 0x1a, 0x0, 0x1a, 0x0, 0xf7, 0xff, 0x59, 0x0,
+ 0x28, 0x0, 0xf9, 0xfe, 0x6d, 0x0, 0x23, 0x0, 0xde, 0xff, 0xff, 0xff, 0xd,
+ 0x0, 0x7, 0x0, 0x45, 0x0, 0xf5, 0xff, 0xdb, 0xfe, 0x20, 0x0, 0xee, 0xff,
+ 0x9a, 0xff, 0xf9, 0xff, 0xf4, 0xff, 0x9, 0x0, 0xf4, 0xff, 0xf6, 0xff,
+ 0xfa, 0xfe, 0x51, 0x0, 0x30, 0x0, 0xc1, 0xff, 0x1b, 0x0, 0x1e, 0x0, 0x12,
+ 0x0, 0x43, 0x0, 0xfa, 0xff, 0xe1, 0xfe, 0x34, 0x0, 0xfb, 0xff, 0x7f, 0xff,
+ 0xf1, 0xff, 0xd7, 0xff, 0xee, 0xff, 0x3, 0x0, 0xee, 0xff, 0x12, 0xff,
+ 0x41, 0x0, 0x29, 0x0, 0x2e, 0x0, 0x18, 0x0, 0x2, 0x0, 0xc0, 0xff, 0x55,
+ 0x0, 0x2e, 0x0, 0xf1, 0xfe, 0x14, 0x0, 0x2c, 0x0, 0xf6, 0xff, 0xf1, 0xff,
+ 0xf1, 0xff, 0xb9, 0xff, 0x5f, 0x0, 0x12, 0x0, 0x4d, 0xff, 0x39, 0x0, 0x11,
+ 0x0, 0x66, 0x0, 0x9, 0x0, 0xf7, 0xff, 0xb0, 0xff, 0x21, 0x0, 0x54, 0x0,
+ 0x4a, 0xff, 0x43, 0x0, 0x23, 0x0, 0x4d, 0x0, 0x1b, 0x0, 0xb, 0x0, 0xe5,
+ 0xff, 0x2c, 0x0, 0x44, 0x0, 0x33, 0xff, 0x4, 0x0, 0x38, 0x0, 0x2a, 0x0,
+ 0x11, 0x0, 0xef, 0xff, 0xf8, 0xff, 0x16, 0x0, 0x65, 0x0, 0x5e, 0xff, 0x52,
+ 0x0, 0x12, 0x0, 0x5d, 0x0, 0x1c, 0x0, 0xf4, 0xff, 0xc3, 0xff, 0x56, 0x0,
+ 0x46, 0x0, 0x19, 0xff, 0x28, 0x0, 0xe, 0x0, 0xd, 0x0, 0xa, 0x0, 0xf6,
+ 0xff, 0xca, 0xff, 0x2b, 0x0, 0x38, 0x0, 0x4d, 0xff, 0x45, 0x0, 0x21, 0x0,
+ 0x31, 0x0, 0xf8, 0xff, 0x5, 0x0, 0xe5, 0xff, 0x1d, 0x0, 0x60, 0x0, 0x30,
+ 0xff, 0x32, 0x0, 0xc7, 0xff, 0xf1, 0xff, 0xfc, 0xff, 0xed, 0xff, 0xe8,
+ 0xff, 0xf8, 0xff, 0x2e, 0x0, 0x41, 0xff, 0x26, 0x0, 0x2d, 0x0, 0x2, 0x0,
+ 0x3a, 0x0, 0x20, 0x0, 0x21, 0x0, 0x10, 0x0, 0x45, 0x0, 0x39, 0xff, 0x1a,
+ 0x0, 0x1d, 0x0, 0xcb, 0xff, 0x6, 0x0, 0xf5, 0xff, 0x20, 0x0, 0x1f, 0x0,
+ 0x21, 0x0, 0x44, 0xff, 0x12, 0x0, 0xff, 0xff, 0x1d, 0x0, 0xf, 0x0, 0xde,
+ 0xff, 0xfd, 0xff, 0x24, 0x0, 0x1f, 0x0, 0x47, 0xff, 0x21, 0x0, 0x3c, 0x0,
+ 0x1, 0x0, 0xe, 0x0, 0xfd, 0xff, 0x1d, 0x0, 0x40, 0x0, 0x0, 0x0, 0x3e,
+ 0xff, 0x4, 0x0, 0x4, 0x0, 0xda, 0xff, 0xda, 0xff, 0xd7, 0xff, 0x18, 0x0,
+ 0x5, 0x0, 0x9, 0x0, 0x72, 0xff, 0x31, 0x0, 0x22, 0x0, 0x7, 0x0, 0xf7,
+ 0xff, 0xed, 0xff, 0x22, 0x0, 0x5, 0x0, 0x10, 0x0, 0x28, 0xff, 0xf4, 0xff,
+ 0x12, 0x0, 0xc4, 0xff, 0xf7, 0xff, 0xf5, 0xff, 0x28, 0x0, 0xf7, 0xff, 0x3,
+ 0x0, 0x4e, 0xff, 0x1b, 0x0, 0xeb, 0xff, 0x15, 0x0, 0xf6, 0xff, 0xf3, 0xff,
+ 0x9, 0x0, 0xb, 0x0, 0x12, 0x0, 0x57, 0xff, 0x3e, 0x0, 0xfe, 0xff, 0xe3,
+ 0xff, 0xf9, 0xff, 0xf7, 0xff, 0xa, 0x0, 0x3, 0x0, 0xec, 0xff, 0x45, 0xff,
+ 0x26, 0x0, 0xc, 0x0, 0xf5, 0xff, 0x2, 0x0, 0x9, 0x0, 0x7, 0x0, 0x9, 0x0,
+ 0x10, 0x0, 0x5a, 0xff, 0x41, 0x0, 0xde, 0xff, 0xea, 0xff, 0xe7, 0xff,
+ 0xfa, 0xff, 0xf6, 0xff, 0xf9, 0xff, 0x6, 0x0, 0x55, 0xff, 0x35, 0x0, 0xf8,
+ 0xff, 0xf5, 0xff, 0xe, 0x0, 0x3, 0x0, 0x6, 0x0, 0xea, 0xff, 0x12, 0x0,
+ 0x54, 0xff, 0x1e, 0x0, 0x13, 0x0, 0xf8, 0xff, 0xb, 0x0, 0xfd, 0xff, 0x25,
+ 0x0, 0x7, 0x0, 0x22, 0x0, 0x5c, 0xff, 0x24, 0x0, 0xee, 0xff, 0xe4, 0xff,
+ 0xee, 0xff, 0xe5, 0xff, 0x13, 0x0, 0xe8, 0xff, 0x11, 0x0, 0x6d, 0xff,
+ 0x41, 0x0, 0x1c, 0x0, 0xd, 0x0, 0x1e, 0x0, 0x1, 0x0, 0x13, 0x0, 0xe, 0x0,
+ 0x3, 0x0, 0x50, 0xff, 0xc, 0x0, 0x9, 0x0, 0xc7, 0xff, 0xf7, 0xff, 0xea,
+ 0xff, 0x1a, 0x0, 0xff, 0xff, 0x4, 0x0, 0x7c, 0xff, 0x2a, 0x0, 0xfe, 0xff,
+ 0x9, 0x0, 0xfe, 0xff, 0xf0, 0xff, 0xa, 0x0, 0xf3, 0xff, 0xf, 0x0, 0x6b,
+ 0xff, 0x27, 0x0, 0x17, 0x0, 0x1, 0x0, 0x16, 0x0, 0xfe, 0xff, 0x19, 0x0,
+ 0xff, 0xff, 0xf8, 0xff, 0x62, 0xff, 0x4, 0x0, 0xfc, 0xff, 0xf9, 0xff,
+ 0xfb, 0xff, 0xf8, 0xff, 0x18, 0x0, 0xee, 0xff, 0x1d, 0x0, 0x7d, 0xff,
+ 0x30, 0x0, 0xf8, 0xff, 0xb, 0x0, 0x2, 0x0, 0xf9, 0xff, 0xd, 0x0, 0xf6,
+ 0xff, 0xb, 0x0, 0x65, 0xff, 0x1f, 0x0, 0x16, 0x0, 0x1, 0x0, 0x13, 0x0,
+ 0x2, 0x0, 0x12, 0x0, 0x3, 0x0, 0x8, 0x0, 0x82, 0xff, 0x1b, 0x0, 0x5, 0x0,
+ 0xfd, 0xff, 0xf5, 0xff, 0xf9, 0xff, 0x7, 0x0, 0xf8, 0xff, 0xe, 0x0, 0x88,
+ 0xff, 0x1a, 0x0, 0xf9, 0xff, 0x1, 0x0, 0x7, 0x0, 0xf8, 0xff, 0x4, 0x0,
+ 0xe4, 0xff, 0xff, 0xff, 0x6f, 0xff, 0xfc, 0xff, 0x16, 0x0, 0x1d, 0x0,
+ 0x22, 0x0, 0x8, 0x0, 0x17, 0x0, 0x4, 0x0, 0x1c, 0x0, 0x7d, 0xff, 0x0, 0x0,
+ 0xee, 0xff, 0xe4, 0xff, 0xf6, 0xff, 0xe7, 0xff, 0xa, 0x0, 0xea, 0xff, 0xf,
+ 0x0, 0x95, 0xff, 0x20, 0x0, 0x0, 0x0, 0x9, 0x0, 0x1a, 0x0, 0xff, 0xff,
+ 0x5, 0x0, 0xfb, 0xff, 0x6, 0x0, 0x6e, 0xff, 0xe4, 0xff, 0x26, 0x0, 0xff,
+ 0xff, 0x20, 0x0, 0x5, 0x0, 0x15, 0x0, 0x7, 0x0, 0x12, 0x0, 0x8e, 0xff,
+ 0xeb, 0xff, 0xf7, 0xff, 0x0, 0x0, 0x7, 0x0, 0xe3, 0xff, 0x8, 0x0, 0xec,
+ 0xff, 0x17, 0x0, 0x8c, 0xff, 0xf7, 0xff, 0xf9, 0xff, 0xf3, 0xff, 0x0, 0x0,
+ 0xf6, 0xff, 0x12, 0x0, 0x0, 0x0, 0x3, 0x0, 0x67, 0xff, 0xbe, 0xff, 0x1a,
+ 0x0, 0xef, 0xff, 0x1, 0x0, 0x5, 0x0, 0x13, 0x0, 0xf1, 0xff, 0x18, 0x0,
+ 0xa4, 0xff, 0x9, 0x0, 0xeb, 0xff, 0x1f, 0x0, 0x15, 0x0, 0xe7, 0xff, 0xfa,
+ 0xff, 0xf5, 0xff, 0x12, 0x0, 0x90, 0xff, 0x11, 0x0, 0xeb, 0xff, 0xe6,
+ 0xff, 0x3, 0x0, 0xee, 0xff, 0xf4, 0xff, 0xed, 0xff, 0xfa, 0xff, 0x89,
+ 0xff, 0xfa, 0xff, 0x21, 0x0, 0xff, 0xff, 0x10, 0x0, 0x10, 0x0, 0xff, 0xff,
+ 0xec, 0xff, 0x10, 0x0, 0xab, 0xff, 0x16, 0x0, 0xe7, 0xff, 0xf, 0x0, 0x11,
+ 0x0, 0xe6, 0xff, 0xfa, 0xff, 0xf2, 0xff, 0xd, 0x0, 0x9f, 0xff, 0x19, 0x0,
+ 0xe7, 0xff, 0x0, 0x0, 0xc, 0x0, 0xf1, 0xff, 0xef, 0xff, 0xf7, 0xff, 0xa,
+ 0x0, 0x94, 0xff, 0x16, 0x0, 0x6, 0x0, 0xf9, 0xff, 0x1a, 0x0, 0x0, 0x0,
+ 0xa, 0x0, 0x7, 0x0, 0xf7, 0xff, 0xb6, 0xff, 0x2a, 0x0, 0xea, 0xff, 0x9,
+ 0x0, 0x7, 0x0, 0xee, 0xff, 0xa, 0x0, 0x9, 0x0, 0x6, 0x0, 0xaa, 0xff, 0x3d,
+ 0x0, 0x6, 0x0, 0x6, 0x0, 0x7, 0x0, 0xa, 0x0, 0xf4, 0xff, 0x4, 0x0, 0xf6,
+ 0xff, 0x96, 0xff, 0x2b, 0x0, 0x1, 0x0, 0xeb, 0xff, 0x12, 0x0, 0x1, 0x0,
+ 0xa, 0x0, 0x0, 0x0, 0xdf, 0xff, 0xc1, 0xff, 0x3e, 0x0, 0xd7, 0xff, 0xf5,
+ 0xff, 0xef, 0xff, 0xf0, 0xff, 0x6, 0x0, 0x8, 0x0, 0xfe, 0xff, 0xb6, 0xff,
+ 0x3a, 0x0, 0xf2, 0xff, 0xf8, 0xff, 0xf7, 0xff, 0x6, 0x0, 0xf2, 0xff, 0xf6,
+ 0xff, 0xf2, 0xff, 0xb7, 0xff, 0x28, 0x0, 0x3, 0x0, 0x17, 0x0, 0x11, 0x0,
+ 0x9, 0x0, 0xa, 0x0, 0x3, 0x0, 0xfa, 0xff, 0xcf, 0xff, 0x2e, 0x0, 0xe9,
+ 0xff, 0xfc, 0xff, 0xe8, 0xff, 0xf7, 0xff, 0x4, 0x0, 0x2, 0x0, 0x14, 0x0,
+ 0xce, 0xff, 0x3a, 0x0, 0x3, 0x0, 0xa, 0x0, 0x7, 0x0, 0xe, 0x0, 0xfa, 0xff,
+ 0xf6, 0xff, 0x4, 0x0, 0xc7, 0xff, 0x28, 0x0, 0xfb, 0xff, 0x10, 0x0, 0xa,
+ 0x0, 0x6, 0x0, 0xe, 0x0, 0x2, 0x0, 0x4, 0x0, 0xcf, 0xff, 0x24, 0x0, 0xde,
+ 0xff, 0xf6, 0xff, 0xe1, 0xff, 0xf8, 0xff, 0xf8, 0xff, 0xf1, 0xff, 0x1b,
+ 0x0, 0xcc, 0xff, 0x3a, 0x0, 0xfc, 0xff, 0xc, 0x0, 0x6, 0x0, 0xe, 0x0,
+ 0xfb, 0xff, 0xf9, 0xff, 0x1, 0x0, 0xbf, 0xff, 0x1b, 0x0, 0xee, 0xff, 0xfc,
+ 0xff, 0x0, 0x0, 0xfa, 0xff, 0xc, 0x0, 0xf6, 0xff, 0xc, 0x0, 0xd5, 0xff,
+ 0x2a, 0x0, 0xe6, 0xff, 0xf9, 0xff, 0xf0, 0xff, 0xfd, 0xff, 0xf8, 0xff,
+ 0xf0, 0xff, 0x20, 0x0, 0xc9, 0xff, 0x2f, 0x0, 0x1, 0x0, 0xfc, 0xff, 0x14,
+ 0x0, 0xa, 0x0, 0x4, 0x0, 0xf5, 0xff, 0x2, 0x0, 0xcd, 0xff, 0x17, 0x0,
+ 0xfa, 0xff, 0xfe, 0xff, 0x7, 0x0, 0xf9, 0xff, 0xc, 0x0, 0xf9, 0xff, 0x1d,
+ 0x0, 0xd5, 0xff, 0x28, 0x0, 0xee, 0xff, 0xf1, 0xff, 0xef, 0xff, 0xfd,
+ 0xff, 0xff, 0xff, 0xfb, 0xff, 0x18, 0x0, 0xcb, 0xff, 0x25, 0x0, 0x4, 0x0,
+ 0x6, 0x0, 0x11, 0x0, 0x2, 0x0, 0xa, 0x0, 0xfe, 0xff, 0x2, 0x0, 0xd1, 0xff,
+ 0x13, 0x0, 0xf9, 0xff, 0x0, 0x0, 0xfe, 0xff, 0xf2, 0xff, 0xf, 0x0, 0x1,
+ 0x0, 0x1c, 0x0, 0xcd, 0xff, 0x1b, 0x0, 0xf2, 0xff, 0xf0, 0xff, 0xf2, 0xff,
+ 0xfc, 0xff, 0x2, 0x0, 0xf5, 0xff, 0x12, 0x0, 0xcf, 0xff, 0x1e, 0x0, 0x9,
+ 0x0, 0x11, 0x0, 0x15, 0x0, 0x3, 0x0, 0x10, 0x0, 0x1, 0x0, 0x7, 0x0, 0xd4,
+ 0xff, 0x5, 0x0, 0xf6, 0xff, 0xf8, 0xff, 0xf0, 0xff, 0xf1, 0xff, 0xf, 0x0,
+ 0xff, 0xff, 0x1e, 0x0, 0xda, 0xff, 0x19, 0x0, 0xfa, 0xff, 0x4, 0x0, 0xf5,
+ 0xff, 0x2, 0x0, 0x3, 0x0, 0xff, 0xff, 0xf, 0x0, 0xd2, 0xff, 0x13, 0x0,
+ 0x7, 0x0, 0x10, 0x0, 0xb, 0x0, 0xfe, 0xff, 0x14, 0x0, 0x7, 0x0, 0x4, 0x0,
+ 0xd6, 0xff, 0x1, 0x0, 0xf7, 0xff, 0xfb, 0xff, 0xea, 0xff, 0xf2, 0xff, 0xb,
+ 0x0, 0x0, 0x0, 0x1e, 0x0, 0xd5, 0xff, 0x19, 0x0, 0xfa, 0xff, 0x2, 0x0,
+ 0xf9, 0xff, 0x5, 0x0, 0x6, 0x0, 0x3, 0x0, 0x4, 0x0, 0xcc, 0xff, 0x7, 0x0,
+ 0x0, 0x0, 0x9, 0x0, 0x6, 0x0, 0xfc, 0xff, 0x10, 0x0, 0x2, 0x0, 0x6, 0x0,
+ 0xd7, 0xff, 0x2, 0x0, 0xf7, 0xff, 0xfb, 0xff, 0xeb, 0xff, 0xf8, 0xff, 0x7,
+ 0x0, 0x0, 0x0, 0x19, 0x0, 0xd2, 0xff, 0x12, 0x0, 0xfe, 0xff, 0xfd, 0xff,
+ 0xff, 0xff, 0x6, 0x0, 0x8, 0x0, 0x1, 0x0, 0x1, 0x0, 0xd4, 0xff, 0x5, 0x0,
+ 0x5, 0x0, 0xc, 0x0, 0x9, 0x0, 0xfb, 0xff, 0xf, 0x0, 0x5, 0x0, 0xe, 0x0,
+ 0xd6, 0xff, 0x3, 0x0, 0xf6, 0xff, 0xf5, 0xff, 0xe8, 0xff, 0xf8, 0xff, 0x5,
+ 0x0, 0x3, 0x0, 0x13, 0x0, 0xd3, 0xff, 0xf, 0x0, 0x2, 0x0, 0x7, 0x0, 0x1,
+ 0x0, 0x8, 0x0, 0x7, 0x0, 0x4, 0x0, 0xfe, 0xff, 0xd4, 0xff, 0x0, 0x0, 0x0,
+ 0x0, 0x7, 0x0, 0xff, 0xff, 0xfa, 0xff, 0xe, 0x0, 0x7, 0x0, 0xa, 0x0, 0xd8,
+ 0xff, 0x2, 0x0, 0xf6, 0xff, 0xf4, 0xff, 0xe8, 0xff, 0xfb, 0xff, 0x3, 0x0,
+ 0x1, 0x0, 0xe, 0x0, 0xd5, 0xff, 0xc, 0x0, 0x6, 0x0, 0xa, 0x0, 0x8, 0x0,
+ 0x8, 0x0, 0x9, 0x0, 0x5, 0x0, 0xfb, 0xff, 0xd5, 0xff, 0xf9, 0xff, 0xfe,
+ 0xff, 0x1, 0x0, 0xfb, 0xff, 0xf8, 0xff, 0xa, 0x0, 0x3, 0x0, 0xb, 0x0,
+ 0xda, 0xff, 0x5, 0x0, 0xf8, 0xff, 0xfa, 0xff, 0xf0, 0xff, 0x1, 0x0, 0xff,
+ 0xff, 0x0, 0x0, 0x9, 0x0, 0xd2, 0xff, 0x8, 0x0, 0x4, 0x0, 0x8, 0x0, 0x9,
+ 0x0, 0x7, 0x0, 0x9, 0x0, 0x3, 0x0, 0xf9, 0xff, 0xd7, 0xff, 0xfb, 0xff,
+ 0xf9, 0xff, 0x0, 0x0, 0xf8, 0xff, 0xf9, 0xff, 0x5, 0x0, 0x1, 0x0, 0xb,
+ 0x0, 0xd8, 0xff, 0x5, 0x0, 0xf7, 0xff, 0xf7, 0xff, 0xf4, 0xff, 0x2, 0x0,
+ 0xff, 0xff, 0xff, 0xff, 0x1, 0x0, 0xd3, 0xff, 0x3, 0x0, 0x5, 0x0, 0x7,
+ 0x0, 0xb, 0x0, 0x5, 0x0, 0x8, 0x0, 0x1, 0x0, 0xf9, 0xff, 0xda, 0xff, 0xf9,
+ 0xff, 0xfb, 0xff, 0xfe, 0xff, 0xf6, 0xff, 0xf9, 0xff, 0x3, 0x0, 0x0, 0x0,
+ 0xa, 0x0, 0xd8, 0xff, 0x4, 0x0, 0xfb, 0xff, 0xf9, 0xff, 0xf8, 0xff, 0x4,
+ 0x0, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xd6, 0xff, 0x1, 0x0, 0x5, 0x0,
+ 0x9, 0x0, 0xb, 0x0, 0x2, 0x0, 0x7, 0x0, 0x2, 0x0, 0xfa, 0xff, 0xda, 0xff,
+ 0xf9, 0xff, 0xf8, 0xff, 0xfa, 0xff, 0xf3, 0xff, 0xf9, 0xff, 0x1, 0x0, 0x0,
+ 0x0, 0x7, 0x0, 0xd9, 0xff, 0x5, 0x0, 0xfd, 0xff, 0xfe, 0xff, 0xfe, 0xff,
+ 0x6, 0x0, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xd7, 0xff, 0xfc, 0xff, 0x2,
+ 0x0, 0x6, 0x0, 0x8, 0x0, 0xff, 0xff, 0x7, 0x0, 0x2, 0x0, 0xfa, 0xff, 0xdc,
+ 0xff, 0xfa, 0xff, 0xf8, 0xff, 0xf9, 0xff, 0xf2, 0xff, 0xfb, 0xff, 0xfe,
+ 0xff, 0xff, 0xff, 0x5, 0x0, 0xd8, 0xff, 0x6, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1,
+ 0x0, 0x6, 0x0, 0x1, 0x0, 0x0, 0x0, 0xf7, 0xff, 0xd9, 0xff, 0xfc, 0xff,
+ 0x2, 0x0, 0x5, 0x0, 0x5, 0x0, 0xfd, 0xff, 0x6, 0x0, 0x1, 0x0, 0xfd, 0xff,
+ 0xdd, 0xff, 0xfe, 0xff, 0xf9, 0xff, 0xfa, 0xff, 0xf3, 0xff, 0xfc, 0xff,
+ 0xfe, 0xff, 0xff, 0xff, 0x4, 0x0, 0xd8, 0xff, 0x5, 0x0, 0x1, 0x0, 0x2,
+ 0x0, 0x5, 0x0, 0x5, 0x0, 0x2, 0x0, 0x0, 0x0, 0xf6, 0xff, 0xda, 0xff, 0xfd,
+ 0xff, 0x0, 0x0, 0x4, 0x0, 0x2, 0x0, 0xfb, 0xff, 0x4, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0xdd, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xf9, 0xff, 0xf4, 0xff, 0xfd,
+ 0xff, 0xfe, 0xff, 0xff, 0xff, 0x1, 0x0, 0xd9, 0xff, 0x5, 0x0, 0x2, 0x0,
+ 0x4, 0x0, 0x7, 0x0, 0x4, 0x0, 0x3, 0x0, 0x0, 0x0, 0xf7, 0xff, 0xdc, 0xff,
+ 0xfc, 0xff, 0xfe, 0xff, 0x1, 0x0, 0xff, 0xff, 0xfb, 0xff, 0x3, 0x0, 0x0,
+ 0x0, 0x2, 0x0, 0xde, 0xff, 0x2, 0x0, 0xfa, 0xff, 0xfa, 0xff, 0xf7, 0xff,
+ 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0x0, 0x0, 0xda, 0xff, 0x3, 0x0, 0x2,
+ 0x0, 0x4, 0x0, 0x8, 0x0, 0x3, 0x0, 0x3, 0x0, 0x0, 0x0, 0xf8, 0xff, 0xde,
+ 0xff, 0xfc, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xfa, 0xff, 0x1,
+ 0x0, 0x0, 0x0, 0x3, 0x0, 0xde, 0xff, 0x3, 0x0, 0xfb, 0xff, 0xfc, 0xff,
+ 0xfa, 0xff, 0x1, 0x0, 0xfd, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xdb, 0xff, 0x2,
+ 0x0, 0x2, 0x0, 0x4, 0x0, 0x8, 0x0, 0x1, 0x0, 0x4, 0x0, 0x0, 0x0, 0xfa,
+ 0xff, 0xdf, 0xff, 0xfd, 0xff, 0xfb, 0xff, 0xfe, 0xff, 0xfa, 0xff, 0xfa,
+ 0xff, 0x0, 0x0, 0xfe, 0xff, 0x4, 0x0, 0xde, 0xff, 0x4, 0x0, 0xfd, 0xff,
+ 0xfd, 0xff, 0xfd, 0xff, 0x2, 0x0, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xff,
+ 0xdd, 0xff, 0x1, 0x0, 0x2, 0x0, 0x5, 0x0, 0x7, 0x0, 0x0, 0x0, 0x4, 0x0,
+ 0xff, 0xff, 0xfc, 0xff, 0xe1, 0xff, 0xff, 0xff, 0xfa, 0xff, 0xfd, 0xff,
+ 0xf9, 0xff, 0xfb, 0xff, 0xff, 0xff, 0xfe, 0xff, 0x4, 0x0, 0xdf, 0xff, 0x5,
+ 0x0, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0xfe, 0xff,
+ 0xfb, 0xff, 0xdf, 0xff, 0x0, 0x0, 0x0, 0x0, 0x4, 0x0, 0x5, 0x0, 0xfe,
+ 0xff, 0x4, 0x0, 0xff, 0xff, 0xfe, 0xff, 0xe2, 0xff, 0x0, 0x0, 0xfa, 0xff,
+ 0xfc, 0xff, 0xf8, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfe, 0xff, 0x3, 0x0,
+ 0xdf, 0xff, 0x5, 0x0, 0xff, 0xff, 0x0, 0x0, 0x2, 0x0, 0x2, 0x0, 0x1, 0x0,
+ 0xfe, 0xff, 0xfb, 0xff, 0xdf, 0xff, 0x0, 0x0, 0xff, 0xff, 0x2, 0x0, 0x2,
+ 0x0, 0xfd, 0xff, 0x4, 0x0, 0xff, 0xff, 0xff, 0xff, 0xe3, 0xff, 0x2, 0x0,
+ 0xfb, 0xff, 0xfc, 0xff, 0xf9, 0xff, 0xfd, 0xff, 0xfe, 0xff, 0xfe, 0xff,
+ 0x1, 0x0, 0xdf, 0xff, 0x4, 0x0, 0x0, 0x0, 0x1, 0x0, 0x3, 0x0, 0x3, 0x0,
+ 0x2, 0x0, 0xff, 0xff, 0xfb, 0xff, 0xe1, 0xff, 0x0, 0x0, 0xfe, 0xff, 0x1,
+ 0x0, 0x0, 0x0, 0xfc, 0xff, 0x3, 0x0, 0xff, 0xff, 0x0, 0x0, 0xe3, 0xff,
+ 0x3, 0x0, 0xfb, 0xff, 0xfc, 0xff, 0xfa, 0xff, 0xfe, 0xff, 0xfe, 0xff,
+ 0xfe, 0xff, 0x0, 0x0, 0xe0, 0xff, 0x4, 0x0, 0x0, 0x0, 0x2, 0x0, 0x4, 0x0,
+ 0x2, 0x0, 0x2, 0x0, 0xff, 0xff, 0xfb, 0xff, 0xe2, 0xff, 0xff, 0xff, 0xfd,
+ 0xff, 0xff, 0xff, 0xfe, 0xff, 0xfc, 0xff, 0x1, 0x0, 0xff, 0xff, 0x2, 0x0,
+ 0xe3, 0xff, 0x3, 0x0, 0xfc, 0xff, 0xfd, 0xff, 0xfb, 0xff, 0x0, 0x0, 0xfe,
+ 0xff, 0xfe, 0xff, 0xff, 0xff, 0xe1, 0xff, 0x3, 0x0, 0x1, 0x0, 0x2, 0x0,
+ 0x4, 0x0, 0x1, 0x0, 0x3, 0x0, 0xff, 0xff, 0xfc, 0xff, 0xe4, 0xff, 0x0,
+ 0x0, 0xfc, 0xff, 0xfe, 0xff, 0xfc, 0xff, 0xfc, 0xff, 0x1, 0x0, 0xff, 0xff,
+ 0x2, 0x0, 0xe4, 0xff, 0x5, 0x0, 0xfd, 0xff, 0xfd, 0xff, 0xfd, 0xff, 0x1,
+ 0x0, 0xff, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xe2, 0xff, 0x2, 0x0, 0x0, 0x0,
+ 0x2, 0x0, 0x4, 0x0, 0x0, 0x0, 0x3, 0x0, 0xff, 0xff, 0xfd, 0xff, 0xe5,
+ 0xff, 0x1, 0x0, 0xfc, 0xff, 0xfd, 0xff, 0xfb, 0xff, 0xfd, 0xff, 0x0, 0x0,
+ 0xff, 0xff, 0x2, 0x0, 0xe4, 0xff, 0x5, 0x0, 0xfe, 0xff, 0xfe, 0xff, 0xff,
+ 0xff, 0x1, 0x0, 0x0, 0x0, 0xfe, 0xff, 0xfd, 0xff, 0xe2, 0xff, 0x1, 0x0,
+ 0xff, 0xff, 0x1, 0x0, 0x3, 0x0, 0xff, 0xff, 0x4, 0x0, 0xff, 0xff, 0xfe,
+ 0xff, 0xe5, 0xff, 0x1, 0x0, 0xfc, 0xff, 0xfc, 0xff, 0xfb, 0xff, 0xfd,
+ 0xff, 0x0, 0x0, 0xfe, 0xff, 0x1, 0x0, 0xe3, 0xff, 0x4, 0x0, 0xff, 0xff,
+ 0xff, 0xff, 0x0, 0x0, 0x2, 0x0, 0x1, 0x0, 0xff, 0xff, 0xfd, 0xff, 0xe2,
+ 0xff, 0x1, 0x0, 0xff, 0xff, 0x0, 0x0, 0x1, 0x0, 0xfe, 0xff, 0x2, 0x0,
+ 0xff, 0xff, 0xff, 0xff, 0xe3, 0xff, 0x2, 0x0, 0xfc, 0xff, 0xfd, 0xff,
+ 0xfb, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1, 0x0, 0xe0, 0xff, 0x3,
+ 0x0, 0xff, 0xff, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0xff, 0xff, 0xfd,
+ 0xff, 0xdf, 0xff, 0x0, 0x0, 0xfe, 0xff, 0x0, 0x0, 0x0, 0x0, 0xfe, 0xff,
+ 0x2, 0x0, 0xff, 0xff, 0x0, 0x0, 0xe0, 0xff, 0x2, 0x0, 0xfd, 0xff, 0xfe,
+ 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0xde,
+ 0xff, 0x2, 0x0, 0xff, 0xff, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0,
+ 0x0, 0xfe, 0xff, 0xe0, 0xff, 0x0, 0x0, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xfe, 0xff, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0xe1, 0xff, 0x1, 0x0, 0xfe,
+ 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0,
+ 0xe2, 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0x1,
+ 0x0, 0xff, 0xff, 0xff, 0xff, 0xe3, 0xff, 0x0, 0x0, 0xfe, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe6, 0xff, 0x0,
+ 0x0, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff,
+ 0x0, 0x0, 0xe8, 0xff, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0xec, 0xff, 0x0, 0x0, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0xee,
+ 0xff, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0}},
+ {"WAV/Subject_002/SH/sh_hrir_order_3.wav",
+ {0x52, 0x49, 0x46, 0x46, 0x24, 0x20, 0x0, 0x0, 0x57, 0x41, 0x56, 0x45,
+ 0x66, 0x6d, 0x74, 0x20, 0x10, 0x0, 0x0, 0x0, 0x1, 0x0, 0x10, 0x0, 0x80,
+ 0xbb, 0x0, 0x0, 0x0, 0x70, 0x17, 0x0, 0x20, 0x0, 0x10, 0x0, 0x64, 0x61,
+ 0x74, 0x61, 0x0, 0x20, 0x0, 0x0, 0xfe, 0xff, 0x4, 0x0, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff,
+ 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff,
+ 0xf3, 0xff, 0x18, 0x0, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff,
+ 0xfc, 0xff, 0xfd, 0xff, 0xf9, 0xff, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0x0,
+ 0x0, 0x1, 0x0, 0x0, 0x0, 0xff, 0xff, 0xfd, 0xff, 0xa, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xfe,
+ 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0x2,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0x0,
+ 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff,
+ 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0x2, 0x0, 0x1, 0x0, 0x0, 0x0, 0xff, 0xff,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x6, 0x0, 0xf3, 0xff,
+ 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x2, 0x0, 0x2, 0x0, 0x5, 0x0,
+ 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0x0,
+ 0x0, 0x0, 0x0, 0xf1, 0xff, 0xfd, 0xff, 0x0, 0x0, 0x0, 0x0, 0xfc, 0xff,
+ 0x2, 0x0, 0xff, 0xff, 0x8, 0x0, 0x2, 0x0, 0xfe, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xfd, 0xff, 0x2, 0x0, 0x0, 0x0, 0xa, 0x0, 0xef, 0xff, 0x4, 0x0,
+ 0xfe, 0xff, 0xfd, 0xff, 0x8, 0x0, 0x8, 0x0, 0x4, 0x0, 0x7, 0x0, 0x2, 0x0,
+ 0x0, 0x0, 0x6, 0x0, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0x1, 0x0, 0xde,
+ 0xff, 0x7b, 0xff, 0xf9, 0xff, 0x2, 0x0, 0x3, 0x0, 0xf7, 0xff, 0x41, 0x0,
+ 0xff, 0xff, 0x79, 0x0, 0x4c, 0x0, 0xfd, 0xff, 0x38, 0x0, 0xff, 0xff, 0xfb,
+ 0xff, 0x6, 0x0, 0xff, 0xff, 0xb2, 0xff, 0xd3, 0xfe, 0x9, 0x0, 0x0, 0x0,
+ 0xff, 0xff, 0xe, 0x0, 0x9c, 0x0, 0x5, 0x0, 0xe, 0x1, 0xa3, 0x0, 0x1, 0x0,
+ 0x82, 0x0, 0xfc, 0xff, 0xff, 0xff, 0xf8, 0xff, 0x2, 0x0, 0x51, 0x0, 0xf0,
+ 0x0, 0xfa, 0xff, 0xfe, 0xff, 0x1, 0x0, 0xfa, 0xff, 0x6f, 0xff, 0x7, 0x0,
+ 0x1, 0xff, 0x42, 0xff, 0x3, 0x0, 0x6f, 0xff, 0x1, 0x0, 0xfd, 0xff, 0xff,
+ 0xff, 0x0, 0x0, 0x75, 0x1, 0x13, 0x5, 0xf7, 0xff, 0xc, 0x0, 0xc, 0x0,
+ 0xf3, 0xff, 0x1, 0xfd, 0xf8, 0xff, 0xd5, 0xfa, 0x42, 0xfc, 0xf7, 0xff,
+ 0x13, 0xfd, 0xfc, 0xff, 0xf5, 0xff, 0xf, 0x0, 0xfe, 0xff, 0x7b, 0xfe,
+ 0x93, 0xfc, 0x1d, 0x0, 0xfb, 0xff, 0xfe, 0xff, 0x2f, 0x0, 0x5e, 0x1, 0x19,
+ 0x0, 0x21, 0x2, 0xb0, 0x0, 0x10, 0x0, 0xad, 0x0, 0x1, 0x0, 0x2, 0x0, 0xd5,
+ 0xff, 0x1, 0x0, 0x3f, 0xfc, 0xb4, 0xf5, 0xfa, 0xff, 0xa5, 0xff, 0x7e,
+ 0xff, 0xf4, 0xff, 0xa2, 0x4, 0x14, 0x0, 0xb6, 0x8, 0x40, 0x5, 0xd, 0x0,
+ 0xb3, 0x3, 0xf9, 0xff, 0x1d, 0x0, 0x13, 0x0, 0x3d, 0x0, 0xbb, 0x3, 0xc0,
+ 0x7, 0xc2, 0xfe, 0x8d, 0xff, 0x61, 0xff, 0x50, 0xfe, 0x99, 0xfc, 0x7, 0x0,
+ 0x6d, 0xfb, 0x9e, 0xff, 0xfe, 0xff, 0xf0, 0xfe, 0x28, 0x0, 0x59, 0x0, 0x1,
+ 0x1, 0x47, 0x0, 0xcd, 0x4, 0x66, 0x8, 0xf8, 0xfe, 0xf8, 0x0, 0x60, 0x1,
+ 0xb1, 0xfe, 0x9d, 0xfe, 0x5, 0xff, 0xf2, 0xfb, 0x4c, 0x0, 0x2e, 0xff,
+ 0x47, 0x1, 0x71, 0x0, 0x95, 0xff, 0x36, 0x0, 0x5e, 0xff, 0x15, 0xff, 0xd8,
+ 0xfb, 0x77, 0x5, 0x4f, 0x1, 0xd9, 0x1, 0xb5, 0x7, 0xf9, 0x4, 0xd, 0x0,
+ 0x59, 0x3, 0x5c, 0x0, 0xd, 0x0, 0x89, 0x3, 0xaa, 0xff, 0x98, 0xfe, 0x91,
+ 0xfa, 0x20, 0xff, 0xbd, 0xfa, 0xf9, 0xf3, 0x0, 0x2, 0x2d, 0x0, 0x67, 0x0,
+ 0x54, 0x2, 0xaa, 0x2, 0xf6, 0x1, 0x4f, 0x9, 0x47, 0x4, 0xa0, 0x1, 0x6d,
+ 0x0, 0xec, 0xfd, 0x68, 0xff, 0x78, 0x1, 0xc2, 0xff, 0xfc, 0xf7, 0x41,
+ 0xef, 0x68, 0xf9, 0x8, 0xff, 0x21, 0xfe, 0x5d, 0xf6, 0x5d, 0x2, 0xd6,
+ 0xff, 0x8e, 0xb, 0xa0, 0x4, 0xe0, 0xff, 0xe, 0xff, 0x64, 0xff, 0xb5, 0x3,
+ 0x7d, 0x8, 0x36, 0x1, 0xf0, 0x1, 0x9c, 0xb, 0x12, 0xfe, 0xe8, 0xfc, 0x14,
+ 0xfc, 0x8c, 0xfe, 0x6f, 0xfb, 0xdd, 0xff, 0x25, 0xef, 0xf, 0xf1, 0xcf,
+ 0xff, 0x68, 0xf9, 0x51, 0x4, 0x1, 0x2, 0x53, 0xfa, 0xad, 0x1, 0x74, 0xff,
+ 0xbf, 0x6, 0xdd, 0xff, 0x56, 0x0, 0x70, 0x2, 0x3d, 0x0, 0xdd, 0xfa, 0x4c,
+ 0xff, 0x2f, 0xf3, 0xac, 0xf5, 0x59, 0xff, 0x48, 0xf9, 0x24, 0x0, 0xe0,
+ 0xf8, 0x45, 0xff, 0x0, 0xfe, 0x32, 0xf9, 0x2e, 0xf4, 0x9b, 0x3, 0x4f, 0x1,
+ 0xd5, 0xff, 0xe5, 0x4, 0xfa, 0x2, 0xc0, 0xff, 0x9a, 0x4, 0x8f, 0xfe, 0xcb,
+ 0xff, 0x5f, 0xff, 0x22, 0xfc, 0x9, 0x1, 0xce, 0x1, 0xf9, 0x0, 0x0, 0x2,
+ 0x2, 0x3, 0xc5, 0xff, 0x8b, 0xfb, 0xa3, 0xf4, 0x3a, 0x1, 0x9d, 0xfa, 0xa7,
+ 0xfe, 0x2d, 0x0, 0x3f, 0xfb, 0x11, 0xff, 0xb6, 0xfa, 0xd2, 0x2, 0x9a, 0x6,
+ 0x5f, 0xfa, 0x3d, 0x7, 0x70, 0x3, 0xe0, 0x6, 0x29, 0xfd, 0x27, 0xfd, 0xc,
+ 0x2, 0xbb, 0xfa, 0xe9, 0xf5, 0x5b, 0xfd, 0x42, 0xfe, 0x3f, 0xfe, 0x3a,
+ 0xfd, 0x45, 0xf6, 0xc0, 0xff, 0xf9, 0xfc, 0x7f, 0x5, 0x49, 0xfc, 0xa0,
+ 0x7, 0xd, 0x11, 0x87, 0x9, 0x4f, 0x5, 0xb, 0xf, 0xd9, 0x5, 0x1d, 0x3,
+ 0xc2, 0x4, 0xa, 0xf0, 0x8, 0x0, 0x60, 0x3, 0x94, 0x5, 0x69, 0xfe, 0xfc,
+ 0xfd, 0x1a, 0x2, 0xe4, 0xf5, 0xe3, 0xd, 0xd9, 0x10, 0x9a, 0x0, 0x6f, 0xd,
+ 0xf1, 0x2, 0x40, 0xfd, 0xb1, 0x2, 0xef, 0x0, 0x6f, 0xff, 0x2e, 0xa, 0x67,
+ 0x2, 0xb, 0xc, 0x9, 0x4, 0xa9, 0xfc, 0xe3, 0xfe, 0xb4, 0x4, 0x7, 0xd,
+ 0xf1, 0x15, 0xed, 0xf4, 0x46, 0xfe, 0x4c, 0xfe, 0x59, 0xfd, 0x9b, 0xf6,
+ 0x6c, 0xfe, 0x1e, 0xfc, 0x5, 0xb, 0x58, 0xfe, 0x3c, 0x6, 0x8f, 0xfe, 0xcb,
+ 0x0, 0xa, 0xfc, 0x9, 0x0, 0x58, 0x1, 0x5f, 0x10, 0x61, 0xfc, 0xb4, 0xf4,
+ 0x8a, 0x8, 0xe7, 0x2, 0xf6, 0xf9, 0x63, 0x0, 0x42, 0xeb, 0x5e, 0x6, 0xf6,
+ 0xfe, 0x71, 0x5, 0xce, 0xfa, 0xf3, 0x3, 0x8, 0xfe, 0xd7, 0xf2, 0xf0, 0xfd,
+ 0xb3, 0xfa, 0xf6, 0x8, 0xb9, 0xb, 0xfb, 0x5, 0xa, 0x6, 0x90, 0xff, 0x1d,
+ 0x1, 0x69, 0x5, 0x9f, 0x2, 0x2a, 0x2, 0xa4, 0xfd, 0xd1, 0xfc, 0xca, 0xfc,
+ 0x21, 0x4, 0xf3, 0x1, 0x41, 0x2, 0x1f, 0x7, 0x19, 0x0, 0xe6, 0x3, 0xc2,
+ 0xf9, 0x69, 0x0, 0xc5, 0xfe, 0x9d, 0x3, 0x29, 0xf9, 0x51, 0xfc, 0x1d, 0x3,
+ 0x96, 0xfe, 0xf0, 0x1, 0x72, 0x0, 0x73, 0xfe, 0x7a, 0x7, 0x4a, 0xfe, 0x32,
+ 0x6, 0xa2, 0xf3, 0xfd, 0xf4, 0x50, 0xf7, 0xba, 0xf0, 0xb6, 0x0, 0x8a,
+ 0xfa, 0xcd, 0xf1, 0x37, 0xfe, 0x9b, 0xfc, 0x55, 0x3, 0x5e, 0x5, 0xfa, 0x1,
+ 0x54, 0x4, 0x1c, 0x1, 0xd1, 0x3, 0x4a, 0x1, 0x93, 0x1, 0xc, 0xfb, 0x38,
+ 0xf8, 0x8f, 0x2, 0x6c, 0xff, 0xc4, 0x0, 0x19, 0x8, 0xb3, 0x1, 0xb0, 0xfe,
+ 0x98, 0x2, 0xbf, 0xff, 0xae, 0x2, 0xa1, 0xfe, 0xd3, 0x4, 0x85, 0x4, 0x95,
+ 0xff, 0x86, 0x9, 0x31, 0xfd, 0xf9, 0xf9, 0x8, 0x9, 0x15, 0xfe, 0x36, 0x2,
+ 0x9e, 0xc, 0x9, 0x3, 0x88, 0xfd, 0x4a, 0x0, 0xe1, 0xfd, 0x49, 0xfe, 0xc4,
+ 0xfc, 0x6c, 0x5, 0x8, 0xa, 0x58, 0xfb, 0xa7, 0x6, 0x69, 0x9, 0x7c, 0x0,
+ 0x71, 0x3, 0xbf, 0x5, 0xd8, 0xf6, 0x1b, 0x18, 0x9e, 0x1, 0x13, 0xfe, 0x22,
+ 0xff, 0x60, 0x3, 0x2d, 0xfd, 0xa2, 0xff, 0x91, 0x4, 0x6, 0x8, 0xd7, 0xfb,
+ 0x24, 0x4, 0x10, 0x4, 0x91, 0x3, 0xdc, 0x0, 0x21, 0xb, 0xf6, 0x0, 0xa1,
+ 0x14, 0xbb, 0x2, 0xb4, 0x3, 0xf0, 0x2, 0x6b, 0x3, 0x26, 0x5, 0x5b, 0x0,
+ 0x51, 0x0, 0xf7, 0xfc, 0x8f, 0xf9, 0xba, 0x5, 0xb6, 0xfb, 0xf, 0x1, 0x9f,
+ 0xf9, 0x4e, 0x4, 0x50, 0x8, 0xf7, 0x7, 0xc9, 0x0, 0xff, 0x0, 0xd0, 0xfe,
+ 0x65, 0x1, 0xb8, 0xff, 0x0, 0xa, 0xc9, 0xfc, 0x77, 0xff, 0x97, 0xff, 0xef,
+ 0xfa, 0x6e, 0x0, 0x48, 0x1, 0xdc, 0xfb, 0x83, 0xff, 0x14, 0x0, 0x11, 0x3,
+ 0xa9, 0xfd, 0xb3, 0x2, 0xbe, 0xff, 0x5f, 0x3, 0xdf, 0xfd, 0x44, 0xff,
+ 0xc6, 0xfc, 0xe9, 0xf9, 0xa, 0xfb, 0xec, 0xf1, 0x7a, 0xfd, 0x1d, 0x1,
+ 0x75, 0xfb, 0x9f, 0x2, 0x26, 0xfc, 0x67, 0x1, 0xd9, 0xff, 0x77, 0x0, 0x27,
+ 0x1, 0x7e, 0x0, 0xe3, 0xff, 0xf2, 0xfa, 0x7a, 0x0, 0x1c, 0xfc, 0x14, 0xfd,
+ 0x1d, 0x1, 0x89, 0xfd, 0x1c, 0xfd, 0x70, 0x3, 0x1d, 0x1, 0xff, 0x1, 0x3e,
+ 0x3, 0xbf, 0x0, 0xfd, 0xfd, 0xb8, 0xfd, 0x6f, 0xfe, 0x10, 0x0, 0x23, 0xfe,
+ 0x3c, 0x1, 0x2f, 0xfe, 0x78, 0xff, 0xea, 0x2, 0xe7, 0xfc, 0x38, 0xff,
+ 0xde, 0x4, 0x8d, 0x2, 0x81, 0xfb, 0x19, 0x2, 0x50, 0x1, 0xb6, 0xfe, 0xc9,
+ 0x0, 0x9a, 0x0, 0x27, 0x2, 0x78, 0xfe, 0xa0, 0xfc, 0x31, 0xff, 0xe7, 0xfc,
+ 0x58, 0x4, 0x40, 0x1, 0xe2, 0x0, 0xca, 0x2, 0xb1, 0x6, 0x8f, 0xfd, 0xea,
+ 0x6, 0xcd, 0x1, 0xda, 0xff, 0xff, 0xff, 0x4a, 0xff, 0x59, 0xff, 0x31, 0x3,
+ 0x4c, 0xff, 0x57, 0x1, 0x3d, 0xfb, 0xfe, 0x6, 0xc8, 0x0, 0xe9, 0xfe, 0x72,
+ 0x3, 0xbf, 0x2, 0x89, 0x6, 0x2e, 0x6, 0x14, 0x0, 0x66, 0x2, 0xa0, 0xfe,
+ 0x68, 0xff, 0xae, 0xfe, 0x28, 0x2, 0x27, 0xfd, 0xc7, 0xff, 0x51, 0xf7,
+ 0x46, 0xfc, 0x12, 0x0, 0xd8, 0x1, 0x8a, 0xfd, 0xa4, 0x2, 0xa0, 0xfe, 0xc5,
+ 0x1, 0x32, 0xfb, 0x14, 0x1, 0x4b, 0x0, 0xe1, 0x0, 0xd, 0x0, 0x97, 0x0,
+ 0xf0, 0xfd, 0xfa, 0x0, 0x4f, 0xfc, 0xc2, 0xfa, 0xf8, 0x1, 0x26, 0x2, 0x6b,
+ 0xfd, 0x47, 0xff, 0x71, 0x3, 0x13, 0xfd, 0x8a, 0xfa, 0x66, 0x1, 0x76, 0x0,
+ 0x59, 0xfe, 0x79, 0xff, 0x90, 0xfe, 0x60, 0x1, 0x77, 0xfc, 0x71, 0xf8,
+ 0xcb, 0xfc, 0x53, 0xff, 0xb7, 0xfe, 0x8a, 0xfc, 0x8e, 0xfb, 0x29, 0x2,
+ 0x3d, 0xfb, 0xb, 0xfc, 0x91, 0xfe, 0xe0, 0xfe, 0xb2, 0xfc, 0xe0, 0xfe,
+ 0x54, 0xff, 0x88, 0xff, 0x82, 0x1, 0x1f, 0xf9, 0xdc, 0xff, 0x22, 0x2,
+ 0x73, 0xfc, 0xca, 0x1, 0xff, 0xff, 0xaa, 0xfb, 0x69, 0xfd, 0x20, 0xfd,
+ 0xf4, 0xfe, 0xbc, 0xfd, 0xc4, 0xfd, 0x22, 0x0, 0x48, 0xfe, 0x51, 0x1,
+ 0xe1, 0x0, 0x61, 0xf9, 0xf0, 0x1, 0x27, 0xfc, 0x82, 0xfe, 0x54, 0x3, 0xe6,
+ 0xff, 0xce, 0xfe, 0x52, 0xfd, 0x15, 0x0, 0xf9, 0xff, 0x94, 0xfd, 0x4f,
+ 0xfe, 0xbb, 0x0, 0xe0, 0xff, 0x2a, 0x0, 0x44, 0x0, 0x72, 0xf9, 0x1f, 0x3,
+ 0x69, 0xfd, 0xc1, 0x1, 0x4a, 0x0, 0x97, 0x2, 0x81, 0x0, 0xeb, 0x3, 0xb3,
+ 0xff, 0x7b, 0xff, 0xf2, 0xfe, 0xcb, 0xff, 0xb5, 0xff, 0x3d, 0x1, 0x14,
+ 0x1, 0x33, 0x1, 0x62, 0xfc, 0x82, 0x2, 0x3, 0x1, 0x10, 0x0, 0x9e, 0xff,
+ 0xad, 0x2, 0x23, 0x2, 0xd6, 0x1, 0xdd, 0xfe, 0xc2, 0x1, 0xc6, 0xfe, 0x85,
+ 0x0, 0xe, 0xff, 0x9a, 0xff, 0xee, 0xff, 0x4c, 0xfd, 0x77, 0xfa, 0x1, 0xfd,
+ 0xcc, 0x0, 0x52, 0x1, 0x24, 0xfd, 0x5, 0x0, 0x24, 0x0, 0x6e, 0xfe, 0xc5,
+ 0xfd, 0x4c, 0x0, 0x92, 0xfe, 0xd6, 0xff, 0xbb, 0xfe, 0xe, 0x0, 0x76, 0x0,
+ 0x20, 0xff, 0x57, 0xfe, 0xdd, 0xfc, 0xbe, 0x2, 0xc4, 0x1, 0xed, 0xfe,
+ 0xd0, 0x0, 0x47, 0x1, 0xfe, 0xfd, 0x98, 0xfd, 0x4c, 0x0, 0xbf, 0xff, 0xb,
+ 0xff, 0x20, 0xff, 0xe3, 0xfd, 0xf2, 0x1, 0xf7, 0xfb, 0xb, 0xfd, 0xca,
+ 0xfd, 0x44, 0xff, 0xb7, 0xfe, 0xc0, 0xff, 0xdf, 0xff, 0xfd, 0xfd, 0x97,
+ 0xfc, 0xa1, 0xfe, 0xb1, 0xfe, 0xd5, 0xfd, 0x84, 0xfe, 0xc4, 0x0, 0x66,
+ 0xfe, 0xef, 0xfe, 0x2a, 0xff, 0x98, 0xfe, 0x43, 0x0, 0xb2, 0x0, 0xbd,
+ 0xfe, 0x17, 0x2, 0x86, 0x0, 0x65, 0xfe, 0x17, 0x0, 0xb4, 0xff, 0xa0, 0xfe,
+ 0xf5, 0xfe, 0xf8, 0xfe, 0x5a, 0x1, 0x56, 0xfe, 0x7f, 0x0, 0x1b, 0xfe,
+ 0xc4, 0xfc, 0xf6, 0x2, 0x94, 0xfc, 0x14, 0xff, 0x5, 0x1, 0x45, 0x0, 0x26,
+ 0x1, 0x59, 0xfe, 0x56, 0x1, 0x82, 0xff, 0xd5, 0xff, 0x7c, 0xff, 0xb4,
+ 0xff, 0x6f, 0x0, 0x48, 0xff, 0xfb, 0xfd, 0x42, 0xfc, 0xaf, 0x1, 0x6f,
+ 0xfe, 0x42, 0x0, 0x36, 0x0, 0x2d, 0x1, 0x41, 0x0, 0x5c, 0x1, 0x30, 0x1,
+ 0x27, 0x0, 0x45, 0x0, 0x57, 0x0, 0x55, 0xff, 0x60, 0x0, 0xcf, 0xff, 0xdf,
+ 0xff, 0xda, 0xff, 0xa5, 0x0, 0x28, 0x1, 0x9d, 0x1, 0x88, 0xff, 0x4e, 0x0,
+ 0x3f, 0x2, 0x1d, 0x1, 0x9a, 0x0, 0x67, 0x1, 0xad, 0x0, 0xb4, 0xff, 0x28,
+ 0xff, 0xaa, 0xff, 0x70, 0xff, 0x3f, 0xfd, 0x0, 0xfe, 0x20, 0xfe, 0xcc,
+ 0xff, 0xd1, 0x1, 0xb6, 0xfd, 0xa, 0x0, 0x48, 0x0, 0x44, 0xfe, 0x9d, 0xff,
+ 0x8, 0x0, 0x22, 0x0, 0x8a, 0xff, 0x8f, 0xff, 0xfa, 0x0, 0x72, 0xff, 0x91,
+ 0xff, 0x92, 0xfe, 0x91, 0xfc, 0x86, 0x2, 0xe1, 0x0, 0xb0, 0xff, 0xca,
+ 0xff, 0x35, 0x0, 0x18, 0xfe, 0x1a, 0x0, 0xbf, 0x0, 0x3e, 0x1, 0xde, 0xff,
+ 0x24, 0x0, 0xb6, 0xfe, 0x32, 0x1, 0x8d, 0xfd, 0xba, 0xfc, 0xd5, 0xfe,
+ 0xc2, 0xfe, 0xbc, 0xff, 0x9c, 0xff, 0x26, 0xfd, 0xbd, 0xfe, 0xa2, 0xfa,
+ 0x6a, 0x1, 0x68, 0xff, 0x6, 0x0, 0x32, 0xff, 0x66, 0x0, 0x1e, 0x0, 0x3b,
+ 0xff, 0xfd, 0xfe, 0xac, 0xfd, 0x71, 0x1, 0x40, 0xff, 0x71, 0xff, 0x4e,
+ 0x2, 0xf2, 0xfe, 0x97, 0xff, 0x78, 0xfd, 0x9, 0x2, 0x61, 0xff, 0x75, 0x0,
+ 0x94, 0xff, 0xae, 0x0, 0xa0, 0xff, 0xa0, 0x0, 0xba, 0xfe, 0xd0, 0xfc,
+ 0x7a, 0x1, 0x96, 0xfe, 0xd, 0xff, 0x5b, 0x1, 0x5c, 0xff, 0x47, 0x0, 0x96,
+ 0xfe, 0x5b, 0x2, 0xc5, 0xff, 0xae, 0x0, 0xab, 0xff, 0xd5, 0xff, 0x6, 0x0,
+ 0xa1, 0xff, 0x9c, 0xfe, 0xc1, 0xfc, 0xd5, 0x0, 0x8, 0x0, 0xa5, 0xff, 0x32,
+ 0x0, 0x53, 0x0, 0x41, 0x0, 0x97, 0xfe, 0x11, 0x2, 0xad, 0xff, 0x27, 0x1,
+ 0x13, 0x0, 0x9b, 0xff, 0x94, 0x0, 0xd3, 0xff, 0xfb, 0xfe, 0x58, 0xfd,
+ 0xcf, 0xff, 0xc9, 0x1, 0xfd, 0xff, 0xe1, 0xff, 0x4f, 0x0, 0xe9, 0x1, 0x98,
+ 0xfe, 0x6c, 0x1, 0xa9, 0x0, 0x84, 0x1, 0xf1, 0xff, 0xf5, 0xfe, 0x0, 0x0,
+ 0x82, 0x0, 0x55, 0xfe, 0xc3, 0xfd, 0x3b, 0xfe, 0xd9, 0x0, 0x2a, 0x0, 0x1a,
+ 0xfe, 0x39, 0xff, 0xce, 0xff, 0xe4, 0xfd, 0x17, 0x0, 0xfd, 0xff, 0xe9,
+ 0x0, 0xc5, 0xff, 0xa0, 0xff, 0xbc, 0x0, 0x6, 0x0, 0x82, 0xff, 0x75, 0xff,
+ 0x67, 0xfe, 0xd3, 0x1, 0xd5, 0xff, 0xe, 0x0, 0x5a, 0xff, 0x4d, 0x0, 0x96,
+ 0xfe, 0x1, 0x0, 0x41, 0x0, 0xf7, 0x0, 0x10, 0x0, 0x28, 0x0, 0x90, 0xff,
+ 0x72, 0x0, 0x73, 0xfd, 0xc4, 0xfd, 0x72, 0xff, 0xc3, 0xff, 0x9d, 0xff,
+ 0x77, 0x0, 0xe7, 0xfe, 0xe6, 0xfe, 0x6f, 0xfe, 0xe, 0x0, 0x56, 0xff, 0xab,
+ 0xff, 0xad, 0xff, 0xfe, 0xff, 0x47, 0x0, 0x91, 0xff, 0xc9, 0xfe, 0x7b,
+ 0xff, 0x3e, 0x0, 0x8b, 0x0, 0x6, 0x0, 0x31, 0x1, 0xcf, 0xff, 0x93, 0xff,
+ 0xe2, 0xff, 0xfd, 0xff, 0x29, 0xff, 0x22, 0x0, 0x9e, 0xff, 0x3b, 0x0, 0x1,
+ 0x0, 0xe0, 0xff, 0x18, 0xfe, 0x52, 0xfe, 0xb7, 0x0, 0x7b, 0xff, 0x9e,
+ 0xff, 0x49, 0x0, 0xe3, 0xff, 0x41, 0x0, 0x1b, 0x0, 0xe, 0x0, 0x47, 0xff,
+ 0x5, 0x0, 0x87, 0xff, 0x81, 0xff, 0x44, 0x0, 0x2b, 0xff, 0xc6, 0xfe, 0x20,
+ 0xff, 0x6e, 0x0, 0xe2, 0xff, 0xfc, 0xff, 0x21, 0x0, 0xa6, 0x0, 0x43, 0x0,
+ 0x42, 0x0, 0xab, 0xff, 0xf0, 0xff, 0x64, 0x0, 0xba, 0xff, 0x89, 0xff,
+ 0x35, 0x0, 0x37, 0x0, 0x2f, 0xff, 0xd8, 0xff, 0x5a, 0xff, 0x3e, 0x0, 0x70,
+ 0x0, 0x81, 0xff, 0xc3, 0xff, 0x36, 0x1, 0xb2, 0xff, 0x7c, 0xff, 0x3f, 0x0,
+ 0x86, 0x0, 0xc2, 0xff, 0x6a, 0xff, 0xed, 0xff, 0x14, 0x0, 0x76, 0xfe,
+ 0xd4, 0xfe, 0xee, 0xfe, 0x22, 0x0, 0x8e, 0x0, 0x12, 0xff, 0xe6, 0xff,
+ 0xab, 0xff, 0xf2, 0xff, 0x3e, 0xff, 0xde, 0xff, 0x2d, 0x0, 0xe0, 0xff,
+ 0xf3, 0xff, 0x25, 0x0, 0x24, 0x0, 0x9a, 0xfe, 0xea, 0xff, 0x36, 0xff,
+ 0x77, 0x0, 0x8c, 0x0, 0xb0, 0x0, 0x36, 0x0, 0x4f, 0x0, 0xb4, 0xff, 0x4e,
+ 0xff, 0x34, 0x0, 0xd, 0x0, 0xaf, 0xff, 0x1f, 0x0, 0xc4, 0xff, 0xcf, 0x0,
+ 0xae, 0xfd, 0x9d, 0xff, 0xa3, 0xff, 0x6d, 0xff, 0x93, 0x0, 0xe9, 0xff,
+ 0x29, 0xff, 0x5b, 0xff, 0x3f, 0xff, 0x6e, 0xff, 0x69, 0xff, 0x77, 0xff,
+ 0xb2, 0xff, 0x42, 0x0, 0x3f, 0x0, 0xe1, 0xff, 0xb2, 0xfe, 0x5c, 0x0, 0x92,
+ 0x0, 0x4e, 0x0, 0xd, 0x0, 0xc2, 0x0, 0x59, 0x0, 0x4, 0x0, 0x9a, 0x0, 0xd9,
+ 0xff, 0xb, 0x0, 0x1, 0x0, 0xef, 0xff, 0x59, 0x0, 0xc6, 0xff, 0x73, 0x0,
+ 0xea, 0xfd, 0x43, 0xff, 0xd5, 0x0, 0x22, 0xff, 0xb9, 0xff, 0x65, 0x0,
+ 0x1d, 0x0, 0x87, 0x0, 0x5b, 0x0, 0xf8, 0xff, 0xfd, 0xff, 0x59, 0xff, 0xb4,
+ 0xff, 0xcb, 0xff, 0x6b, 0x0, 0x35, 0x0, 0x37, 0xff, 0xe9, 0xff, 0x25, 0x0,
+ 0xa1, 0x0, 0x92, 0x0, 0x2, 0x0, 0x34, 0x0, 0xd, 0x0, 0x9c, 0x0, 0x0, 0x0,
+ 0xe, 0x0, 0xd8, 0xff, 0x34, 0x0, 0x28, 0x0, 0x53, 0x0, 0x87, 0x0, 0xcc,
+ 0xfe, 0x71, 0xff, 0xc4, 0xff, 0x60, 0x0, 0x3, 0x0, 0xf5, 0xff, 0x20, 0x0,
+ 0x37, 0x0, 0xfc, 0xff, 0xe2, 0xff, 0x5b, 0x0, 0xc7, 0xff, 0xf6, 0xff,
+ 0xc9, 0xff, 0x2c, 0x0, 0x2f, 0x0, 0x9e, 0xfe, 0xdb, 0xff, 0xae, 0xff, 0x7,
+ 0x0, 0xdf, 0xff, 0x8e, 0xff, 0x1, 0x0, 0xce, 0xff, 0x23, 0x0, 0x8b, 0xff,
+ 0x1a, 0x0, 0x7b, 0xff, 0xdf, 0xff, 0xe, 0x0, 0x22, 0x0, 0x4c, 0x0, 0xe4,
+ 0xfe, 0x7c, 0x0, 0x8f, 0xff, 0x99, 0x0, 0x5a, 0x0, 0x34, 0x0, 0xee, 0xff,
+ 0xef, 0xff, 0x39, 0x0, 0xc3, 0xff, 0x3, 0x0, 0xac, 0xff, 0x39, 0x0, 0x35,
+ 0x0, 0xb2, 0xff, 0x13, 0x0, 0xfe, 0xfd, 0x35, 0xff, 0xef, 0xff, 0x6f,
+ 0xff, 0xfe, 0xff, 0x44, 0x0, 0xe6, 0xff, 0x66, 0xff, 0x2a, 0x0, 0xcc,
+ 0xff, 0xce, 0xff, 0x7a, 0xff, 0x2d, 0x0, 0x11, 0x0, 0xc, 0x0, 0xe0, 0xff,
+ 0xf2, 0xfe, 0x48, 0x0, 0x4c, 0x0, 0xce, 0xff, 0x1d, 0x0, 0x7e, 0x0, 0x3c,
+ 0x0, 0x20, 0x0, 0xd3, 0x0, 0xf4, 0xff, 0x3f, 0x0, 0xdd, 0xff, 0x32, 0x0,
+ 0xb, 0x0, 0x17, 0x0, 0x58, 0x0, 0x81, 0xfe, 0xc0, 0xff, 0x43, 0x0, 0x64,
+ 0xff, 0x3c, 0x0, 0x4, 0x0, 0xd0, 0xff, 0xc4, 0xff, 0x90, 0x0, 0x1a, 0x0,
+ 0xc9, 0xff, 0x95, 0xff, 0x1f, 0x0, 0xe7, 0xff, 0x6f, 0x0, 0x92, 0xff,
+ 0x15, 0xff, 0x35, 0x0, 0xdf, 0xff, 0x6f, 0x0, 0xa, 0x0, 0x7d, 0x0, 0x48,
+ 0x0, 0x62, 0x0, 0xe1, 0x0, 0x22, 0x0, 0x20, 0x0, 0xf9, 0xff, 0x36, 0x0,
+ 0x2b, 0x0, 0xed, 0xff, 0x55, 0x0, 0x94, 0xfe, 0x4e, 0x0, 0x7b, 0xff, 0xe8,
+ 0xff, 0xfa, 0xff, 0x20, 0x0, 0xd6, 0xff, 0x4b, 0x0, 0x2c, 0x0, 0xb, 0x0,
+ 0xf8, 0xff, 0xab, 0xff, 0x23, 0x0, 0x9, 0x0, 0xf6, 0xff, 0x12, 0x0, 0xe9,
+ 0xfe, 0x87, 0x0, 0xaa, 0xff, 0x15, 0x0, 0x11, 0x0, 0xf4, 0xff, 0x1b, 0x0,
+ 0x57, 0xff, 0x5d, 0x0, 0xfe, 0xff, 0xdc, 0xff, 0xef, 0xff, 0x41, 0x0,
+ 0x47, 0x0, 0xed, 0xff, 0x7, 0x0, 0x9b, 0xfe, 0x5d, 0x0, 0xec, 0xff, 0x17,
+ 0x0, 0xe6, 0xff, 0x71, 0x0, 0x31, 0x0, 0xd7, 0xff, 0x4d, 0x0, 0xdb, 0xff,
+ 0x44, 0x0, 0xea, 0xff, 0x18, 0x0, 0x23, 0x0, 0xe1, 0xff, 0x24, 0x0, 0x54,
+ 0xfe, 0x32, 0x0, 0xef, 0xff, 0xba, 0xff, 0x20, 0x0, 0x4, 0x0, 0xb2, 0xff,
+ 0x84, 0xff, 0x2d, 0x0, 0xc9, 0xff, 0xf0, 0xff, 0xbe, 0xff, 0x2e, 0x0,
+ 0x59, 0x0, 0xf3, 0xff, 0xe4, 0xff, 0xfe, 0xfe, 0x93, 0x0, 0xe0, 0xff,
+ 0x65, 0x0, 0x7, 0x0, 0x65, 0x0, 0x13, 0x0, 0xfa, 0xff, 0x92, 0x0, 0xd,
+ 0x0, 0x29, 0x0, 0x35, 0x0, 0x54, 0x0, 0x77, 0x0, 0xa1, 0xff, 0x8, 0x0,
+ 0x5b, 0xfe, 0xe8, 0xff, 0x12, 0x0, 0x95, 0xff, 0xb7, 0xff, 0x3d, 0x0, 0x2,
+ 0x0, 0xc, 0x0, 0x67, 0x0, 0xe0, 0xff, 0x15, 0x0, 0xc8, 0xff, 0x0, 0x0,
+ 0x1f, 0x0, 0x9, 0x0, 0xf2, 0xff, 0x21, 0xff, 0xc5, 0x0, 0x1, 0x0, 0x4c,
+ 0x0, 0x2e, 0x0, 0xa, 0x0, 0xb, 0x0, 0x1f, 0x0, 0x8c, 0x0, 0xfb, 0xff,
+ 0x2f, 0x0, 0x8, 0x0, 0x21, 0x0, 0x20, 0x0, 0xfa, 0xff, 0x2e, 0x0, 0xc0,
+ 0xfe, 0x49, 0x0, 0xcc, 0xff, 0xee, 0xff, 0x23, 0x0, 0xc3, 0xff, 0x19, 0x0,
+ 0x8d, 0xff, 0x3f, 0x0, 0x3, 0x0, 0x1b, 0x0, 0xd6, 0xff, 0x1c, 0x0, 0xf8,
+ 0xff, 0x10, 0x0, 0xc9, 0xff, 0xf4, 0xfe, 0x8b, 0x0, 0xfb, 0xff, 0xe3,
+ 0xff, 0xfa, 0xff, 0xfd, 0xff, 0x56, 0x0, 0xc2, 0xff, 0x81, 0x0, 0xe9,
+ 0xff, 0x3b, 0x0, 0xf7, 0xff, 0x8, 0x0, 0xe4, 0xff, 0xf3, 0xff, 0x42, 0x0,
+ 0xbd, 0xfe, 0xa4, 0x0, 0xe0, 0xff, 0xf6, 0xff, 0x16, 0x0, 0xed, 0xff,
+ 0xdb, 0xff, 0xe7, 0xff, 0xd, 0x0, 0xc, 0x0, 0xed, 0xff, 0xf5, 0xff, 0x24,
+ 0x0, 0xee, 0xff, 0xe5, 0xff, 0xe6, 0xff, 0xb4, 0xfe, 0x24, 0x0, 0xe2,
+ 0xff, 0xf8, 0xff, 0xf5, 0xff, 0xe0, 0xff, 0xf1, 0xff, 0xa3, 0xff, 0x10,
+ 0x0, 0xa, 0x0, 0xde, 0xff, 0x7, 0x0, 0x3d, 0x0, 0x41, 0x0, 0xd2, 0xff,
+ 0xdf, 0xff, 0xcf, 0xfe, 0x54, 0x0, 0x22, 0x0, 0xfe, 0xff, 0xec, 0xff,
+ 0x3b, 0x0, 0x3, 0x0, 0x65, 0x0, 0x36, 0x0, 0x20, 0x0, 0x20, 0x0, 0x1e,
+ 0x0, 0x17, 0x0, 0xf9, 0xff, 0xdc, 0xff, 0x29, 0x0, 0xb0, 0xfe, 0x53, 0x0,
+ 0x1a, 0x0, 0xc5, 0xff, 0x2d, 0x0, 0xba, 0xff, 0xcb, 0xff, 0xc9, 0xff, 0xe,
+ 0x0, 0x28, 0x0, 0xc1, 0xff, 0xf3, 0xff, 0x16, 0x0, 0xe9, 0xff, 0x16, 0x0,
+ 0xb8, 0xff, 0x2d, 0xff, 0x75, 0x0, 0xfa, 0xff, 0x3e, 0x0, 0x11, 0x0, 0x7,
+ 0x0, 0x36, 0x0, 0x1e, 0x0, 0x48, 0x0, 0x1e, 0x0, 0x31, 0x0, 0x2d, 0x0,
+ 0x1a, 0x0, 0xe5, 0xff, 0xec, 0xff, 0xf, 0x0, 0x85, 0xfe, 0x14, 0x0, 0xe7,
+ 0xff, 0xbc, 0xff, 0xf7, 0xff, 0x5, 0x0, 0xf8, 0xff, 0x56, 0x0, 0xe2, 0xff,
+ 0xf7, 0xff, 0x10, 0x0, 0xd6, 0xff, 0x0, 0x0, 0xc5, 0xff, 0x16, 0x0, 0xed,
+ 0xff, 0xf, 0xff, 0xa7, 0x0, 0xd0, 0xff, 0x43, 0x0, 0x2f, 0x0, 0xdb, 0xff,
+ 0xf8, 0xff, 0x37, 0x0, 0xe7, 0xff, 0xfa, 0xff, 0xed, 0xff, 0x1c, 0x0,
+ 0x34, 0x0, 0xf, 0x0, 0xed, 0xff, 0xee, 0xff, 0xbe, 0xfe, 0x3a, 0x0, 0xea,
+ 0xff, 0xed, 0xff, 0xf2, 0xff, 0x12, 0x0, 0xe2, 0xff, 0x51, 0x0, 0xdc,
+ 0xff, 0xe9, 0xff, 0x3, 0x0, 0xfb, 0xff, 0x14, 0x0, 0xe4, 0xff, 0xf0, 0xff,
+ 0xd8, 0xff, 0xcf, 0xfe, 0x5a, 0x0, 0x39, 0x0, 0xd3, 0xff, 0x13, 0x0, 0x1a,
+ 0x0, 0xd2, 0xff, 0x49, 0x0, 0x10, 0x0, 0xe7, 0xff, 0xf0, 0xff, 0x3, 0x0,
+ 0x5, 0x0, 0xeb, 0xff, 0xe7, 0xff, 0x6, 0x0, 0xb, 0xff, 0x7f, 0x0, 0x35,
+ 0x0, 0x22, 0x0, 0x34, 0x0, 0x24, 0x0, 0xd8, 0xff, 0x27, 0x0, 0x8, 0x0,
+ 0x14, 0x0, 0xe2, 0xff, 0x3b, 0x0, 0x25, 0x0, 0xe8, 0xff, 0xe7, 0xff, 0xd8,
+ 0xff, 0xd8, 0xfe, 0x23, 0x0, 0x3f, 0x0, 0xf3, 0xff, 0xe9, 0xff, 0x3a, 0x0,
+ 0x1c, 0x0, 0x1, 0x0, 0x2a, 0x0, 0xec, 0xff, 0xf7, 0xff, 0x17, 0x0, 0x17,
+ 0x0, 0xe7, 0xff, 0xf6, 0xff, 0xf3, 0xff, 0x21, 0xff, 0xae, 0x0, 0x3e, 0x0,
+ 0x23, 0x0, 0x2, 0x0, 0x1f, 0x0, 0xc, 0x0, 0x58, 0x0, 0x23, 0x0, 0xdc,
+ 0xff, 0x9, 0x0, 0x7, 0x0, 0x1c, 0x0, 0xd1, 0xff, 0xfe, 0xff, 0x24, 0x0,
+ 0xf3, 0xfe, 0x64, 0x0, 0xf0, 0xff, 0x7, 0x0, 0x12, 0x0, 0xd9, 0xff, 0xd8,
+ 0xff, 0xe1, 0xff, 0xdf, 0xff, 0xdd, 0xff, 0xcf, 0xff, 0xe5, 0xff, 0x40,
+ 0x0, 0xf0, 0xff, 0x13, 0x0, 0xb9, 0xff, 0x1c, 0xff, 0x44, 0x0, 0x6, 0x0,
+ 0x20, 0x0, 0xde, 0xff, 0x35, 0x0, 0xc, 0x0, 0x4c, 0x0, 0x17, 0x0, 0xd0,
+ 0xff, 0x17, 0x0, 0x7, 0x0, 0x27, 0x0, 0x8, 0x0, 0xe6, 0xff, 0x1a, 0x0,
+ 0xcb, 0xfe, 0x31, 0x0, 0xc, 0x0, 0xb7, 0xff, 0xf8, 0xff, 0xfa, 0xff, 0x98,
+ 0xff, 0x36, 0x0, 0xda, 0xff, 0xda, 0xff, 0xcf, 0xff, 0xd3, 0xff, 0x9, 0x0,
+ 0xed, 0xff, 0xc, 0x0, 0xd9, 0xff, 0x1e, 0xff, 0x4e, 0x0, 0xf6, 0xff, 0x1c,
+ 0x0, 0xe, 0x0, 0xf7, 0xff, 0xdf, 0xff, 0xdc, 0xff, 0xd, 0x0, 0xe6, 0xff,
+ 0xd0, 0xff, 0x1e, 0x0, 0x27, 0x0, 0x28, 0x0, 0xea, 0xff, 0xdc, 0xff, 0xec,
+ 0xfe, 0xa, 0x0, 0x37, 0x0, 0xdf, 0xff, 0xc0, 0xff, 0x37, 0x0, 0x14, 0x0,
+ 0x36, 0x0, 0x1, 0x0, 0xd6, 0xff, 0xfd, 0xff, 0xff, 0xff, 0x7, 0x0, 0xf1,
+ 0xff, 0xa, 0x0, 0x5, 0x0, 0xc, 0xff, 0x30, 0x0, 0x46, 0x0, 0xcd, 0xff,
+ 0xe3, 0xff, 0xcf, 0xff, 0xef, 0xff, 0xfa, 0xff, 0xf4, 0xff, 0xe6, 0xff,
+ 0xc9, 0xff, 0xde, 0xff, 0x21, 0x0, 0xf3, 0xff, 0x2b, 0x0, 0xde, 0xff,
+ 0x42, 0xff, 0x37, 0x0, 0xf, 0x0, 0x20, 0x0, 0xf4, 0xff, 0xe5, 0xff, 0x2,
+ 0x0, 0x8, 0x0, 0x0, 0x0, 0xf0, 0xff, 0xfb, 0xff, 0x2, 0x0, 0x1b, 0x0, 0x8,
+ 0x0, 0xb, 0x0, 0xdc, 0xff, 0xe8, 0xfe, 0xe6, 0xff, 0x2, 0x0, 0xdf, 0xff,
+ 0xd1, 0xff, 0xff, 0xff, 0xd4, 0xff, 0x28, 0x0, 0x19, 0x0, 0xdd, 0xff,
+ 0xff, 0xff, 0xd1, 0xff, 0xe7, 0xff, 0xf9, 0xff, 0x15, 0x0, 0x0, 0x0, 0x51,
+ 0xff, 0x41, 0x0, 0x19, 0x0, 0x43, 0x0, 0x13, 0x0, 0xdb, 0xff, 0xca, 0xff,
+ 0x36, 0x0, 0x47, 0x0, 0x6, 0x0, 0xeb, 0xff, 0xff, 0xff, 0xe, 0x0, 0x3,
+ 0x0, 0xe, 0x0, 0x1f, 0x0, 0x2d, 0xff, 0xfa, 0xff, 0x21, 0x0, 0x23, 0x0,
+ 0xe, 0x0, 0xf3, 0xff, 0xde, 0xff, 0xf6, 0xff, 0x4b, 0x0, 0x6, 0x0, 0xf1,
+ 0xff, 0xfb, 0xff, 0xe, 0x0, 0xf0, 0xff, 0x1d, 0x0, 0x8, 0x0, 0x45, 0xff,
+ 0x2e, 0x0, 0x3e, 0x0, 0x2a, 0x0, 0x1, 0x0, 0x19, 0x0, 0xf6, 0xff, 0x28,
+ 0x0, 0x7f, 0x0, 0xfe, 0xff, 0x21, 0x0, 0x2, 0x0, 0xff, 0xff, 0xcc, 0xff,
+ 0xc, 0x0, 0x5e, 0x0, 0x44, 0xff, 0x47, 0x0, 0x25, 0x0, 0x1e, 0x0, 0x34,
+ 0x0, 0xe1, 0xff, 0xc6, 0xff, 0xfd, 0xff, 0x34, 0x0, 0x12, 0x0, 0xf7, 0xff,
+ 0xfb, 0xff, 0x1a, 0x0, 0xcd, 0xff, 0x1a, 0x0, 0x21, 0x0, 0x53, 0xff, 0x11,
+ 0x0, 0xfc, 0xff, 0x2a, 0x0, 0x11, 0x0, 0xf9, 0xff, 0xed, 0xff, 0xe7, 0xff,
+ 0x48, 0x0, 0x4, 0x0, 0xd, 0x0, 0x16, 0x0, 0x23, 0x0, 0xfd, 0xff, 0xf2,
+ 0xff, 0x33, 0x0, 0x37, 0xff, 0x13, 0x0, 0x18, 0x0, 0xfa, 0xff, 0xf4, 0xff,
+ 0x2, 0x0, 0xe7, 0xff, 0x35, 0x0, 0x37, 0x0, 0xfd, 0xff, 0x10, 0x0, 0xf2,
+ 0xff, 0x10, 0x0, 0xd8, 0xff, 0xf3, 0xff, 0x49, 0x0, 0x4c, 0xff, 0x35, 0x0,
+ 0xe, 0x0, 0x4, 0x0, 0x1c, 0x0, 0xdc, 0xff, 0xeb, 0xff, 0xe0, 0xff, 0x2a,
+ 0x0, 0xfd, 0xff, 0xda, 0xff, 0xfc, 0xff, 0x33, 0x0, 0x2, 0x0, 0x4, 0x0,
+ 0xa, 0x0, 0x6d, 0xff, 0x1d, 0x0, 0x16, 0x0, 0x22, 0x0, 0xf8, 0xff, 0x1b,
+ 0x0, 0x2e, 0x0, 0xe, 0x0, 0x5b, 0x0, 0xf0, 0xff, 0x1b, 0x0, 0x19, 0x0,
+ 0x2d, 0x0, 0xb, 0x0, 0xf5, 0xff, 0x2f, 0x0, 0x2e, 0xff, 0x8, 0x0, 0x1c,
+ 0x0, 0xc4, 0xff, 0xf5, 0xff, 0xf7, 0xff, 0xf9, 0xff, 0xb, 0x0, 0x25, 0x0,
+ 0xea, 0xff, 0x1, 0x0, 0xdc, 0xff, 0xe, 0x0, 0xed, 0xff, 0x1b, 0x0, 0x9,
+ 0x0, 0x68, 0xff, 0x45, 0x0, 0xed, 0xff, 0xe, 0x0, 0x18, 0x0, 0xec, 0xff,
+ 0x7, 0x0, 0xef, 0xff, 0x16, 0x0, 0xf5, 0xff, 0xf4, 0xff, 0x18, 0x0, 0x26,
+ 0x0, 0x19, 0x0, 0xf6, 0xff, 0xec, 0xff, 0x26, 0xff, 0xf5, 0xff, 0xe2,
+ 0xff, 0xe4, 0xff, 0xeb, 0xff, 0x10, 0x0, 0x12, 0x0, 0xf, 0x0, 0x10, 0x0,
+ 0xe3, 0xff, 0x4, 0x0, 0xfe, 0xff, 0x5, 0x0, 0xa, 0x0, 0xed, 0xff, 0xf3,
+ 0xff, 0x41, 0xff, 0x2d, 0x0, 0xf6, 0xff, 0xf2, 0xff, 0x0, 0x0, 0xfc, 0xff,
+ 0x6, 0x0, 0x2a, 0x0, 0x24, 0x0, 0xeb, 0xff, 0xf2, 0xff, 0x3, 0x0, 0x0,
+ 0x0, 0xe, 0x0, 0x2, 0x0, 0x10, 0x0, 0x50, 0xff, 0x2b, 0x0, 0xf4, 0xff,
+ 0x6, 0x0, 0x12, 0x0, 0xf7, 0xff, 0x25, 0x0, 0xf7, 0xff, 0x3, 0x0, 0xf8,
+ 0xff, 0xe6, 0xff, 0x18, 0x0, 0x22, 0x0, 0x1a, 0x0, 0x0, 0x0, 0xe6, 0xff,
+ 0x40, 0xff, 0xb, 0x0, 0xf4, 0xff, 0xee, 0xff, 0xea, 0xff, 0x16, 0x0, 0x32,
+ 0x0, 0xfb, 0xff, 0x11, 0x0, 0xe5, 0xff, 0x9, 0x0, 0x0, 0x0, 0x9, 0x0, 0xf,
+ 0x0, 0xf9, 0xff, 0x5, 0x0, 0x55, 0xff, 0x3e, 0x0, 0xfc, 0xff, 0xee, 0xff,
+ 0xc, 0x0, 0x9, 0x0, 0x5, 0x0, 0x1b, 0x0, 0xd, 0x0, 0xf4, 0xff, 0x0, 0x0,
+ 0x3, 0x0, 0x2, 0x0, 0x0, 0x0, 0xb, 0x0, 0x5, 0x0, 0x5b, 0xff, 0x13, 0x0,
+ 0xea, 0xff, 0xed, 0xff, 0x18, 0x0, 0xfd, 0xff, 0x16, 0x0, 0xce, 0xff,
+ 0xfa, 0xff, 0xf7, 0xff, 0xef, 0xff, 0xa, 0x0, 0x1d, 0x0, 0x13, 0x0, 0x1,
+ 0x0, 0xe3, 0xff, 0x61, 0xff, 0x5, 0x0, 0xfc, 0xff, 0x2, 0x0, 0xec, 0xff,
+ 0x21, 0x0, 0x30, 0x0, 0x1c, 0x0, 0x1f, 0x0, 0xed, 0xff, 0x18, 0x0, 0xf,
+ 0x0, 0x5, 0x0, 0x5, 0x0, 0xf9, 0xff, 0x25, 0x0, 0x4a, 0xff, 0x1b, 0x0,
+ 0x14, 0x0, 0xe2, 0xff, 0x10, 0x0, 0xf1, 0xff, 0x8, 0x0, 0x14, 0x0, 0xf,
+ 0x0, 0xf8, 0xff, 0xec, 0xff, 0xf8, 0xff, 0x2, 0x0, 0x8, 0x0, 0x15, 0x0,
+ 0xf5, 0xff, 0x7e, 0xff, 0x1e, 0x0, 0xfc, 0xff, 0x15, 0x0, 0x19, 0x0, 0xf7,
+ 0xff, 0x2c, 0x0, 0xe9, 0xff, 0x23, 0x0, 0xf9, 0xff, 0x7, 0x0, 0x13, 0x0,
+ 0xb, 0x0, 0x23, 0x0, 0xf6, 0xff, 0xfe, 0xff, 0x59, 0xff, 0x2, 0x0, 0x3,
+ 0x0, 0xe3, 0xff, 0xfc, 0xff, 0xa, 0x0, 0x17, 0x0, 0x8, 0x0, 0x20, 0x0,
+ 0xf7, 0xff, 0x1b, 0x0, 0xf0, 0xff, 0xef, 0xff, 0xff, 0xff, 0x2, 0x0, 0x11,
+ 0x0, 0x77, 0xff, 0x3c, 0x0, 0x8, 0x0, 0xf6, 0xff, 0x1f, 0x0, 0xe5, 0xff,
+ 0x0, 0x0, 0xf1, 0xff, 0x19, 0x0, 0x1, 0x0, 0xf5, 0xff, 0xfc, 0xff, 0x0,
+ 0x0, 0xf, 0x0, 0x1, 0x0, 0xf3, 0xff, 0x7d, 0xff, 0x11, 0x0, 0xf8, 0xff,
+ 0xc, 0x0, 0x2, 0x0, 0xfc, 0xff, 0x18, 0x0, 0xec, 0xff, 0x1a, 0x0, 0xf8,
+ 0xff, 0x4, 0x0, 0xc, 0x0, 0x5, 0x0, 0xf, 0x0, 0xf0, 0xff, 0xf5, 0xff,
+ 0x68, 0xff, 0xfe, 0xff, 0xa, 0x0, 0xe6, 0xff, 0xf1, 0xff, 0x4, 0x0, 0x9,
+ 0x0, 0x9, 0x0, 0x1a, 0x0, 0xf5, 0xff, 0x0, 0x0, 0xf4, 0xff, 0xf2, 0xff,
+ 0xfd, 0xff, 0x0, 0x0, 0x6, 0x0, 0x84, 0xff, 0x20, 0x0, 0xd, 0x0, 0xb, 0x0,
+ 0x13, 0x0, 0xeb, 0xff, 0x5, 0x0, 0x8, 0x0, 0x7, 0x0, 0x3, 0x0, 0xec, 0xff,
+ 0x10, 0x0, 0x6, 0x0, 0xb, 0x0, 0xfa, 0xff, 0xed, 0xff, 0x6f, 0xff, 0xf4,
+ 0xff, 0xf6, 0xff, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xff, 0x15, 0x0, 0xe9,
+ 0xff, 0x8, 0x0, 0xf4, 0xff, 0xfe, 0xff, 0x6, 0x0, 0x6, 0x0, 0x6, 0x0,
+ 0xef, 0xff, 0xe8, 0xff, 0x79, 0xff, 0x17, 0x0, 0x1, 0x0, 0x0, 0x0, 0x2,
+ 0x0, 0x4, 0x0, 0x2, 0x0, 0x1c, 0x0, 0x18, 0x0, 0xf8, 0xff, 0x9, 0x0, 0xfe,
+ 0xff, 0xf0, 0xff, 0xf2, 0xff, 0xf8, 0xff, 0xc, 0x0, 0x73, 0xff, 0x17, 0x0,
+ 0xfd, 0xff, 0xf9, 0xff, 0x1d, 0x0, 0xe8, 0xff, 0xf5, 0xff, 0xf3, 0xff,
+ 0x0, 0x0, 0xfa, 0xff, 0xe9, 0xff, 0x3, 0x0, 0x6, 0x0, 0xfc, 0xff, 0xfc,
+ 0xff, 0xe6, 0xff, 0x8a, 0xff, 0xf, 0x0, 0xf7, 0xff, 0x9, 0x0, 0x5, 0x0,
+ 0xf, 0x0, 0x11, 0x0, 0xf0, 0xff, 0x21, 0x0, 0xe9, 0xff, 0xb, 0x0, 0xb,
+ 0x0, 0x8, 0x0, 0xfa, 0xff, 0xf0, 0xff, 0x8, 0x0, 0x79, 0xff, 0x15, 0x0,
+ 0x6, 0x0, 0xee, 0xff, 0x7, 0x0, 0x1, 0x0, 0xed, 0xff, 0x18, 0x0, 0xe, 0x0,
+ 0xf2, 0xff, 0xfe, 0xff, 0xf4, 0xff, 0xf1, 0xff, 0xea, 0xff, 0x9, 0x0, 0x6,
+ 0x0, 0x89, 0xff, 0x18, 0x0, 0xfa, 0xff, 0x3, 0x0, 0x13, 0x0, 0xec, 0xff,
+ 0xfd, 0xff, 0xe7, 0xff, 0x7, 0x0, 0xf5, 0xff, 0xe9, 0xff, 0x7, 0x0, 0xf,
+ 0x0, 0x8, 0x0, 0xf8, 0xff, 0xf0, 0xff, 0x83, 0xff, 0xf1, 0xff, 0xf9, 0xff,
+ 0x6, 0x0, 0xf3, 0xff, 0x9, 0x0, 0x1c, 0x0, 0xfc, 0xff, 0x22, 0x0, 0xf5,
+ 0xff, 0xd, 0x0, 0x5, 0x0, 0x6, 0x0, 0xf8, 0xff, 0xf0, 0xff, 0x14, 0x0,
+ 0x78, 0xff, 0x11, 0x0, 0x1, 0x0, 0xed, 0xff, 0x9, 0x0, 0xe9, 0xff, 0xf4,
+ 0xff, 0xc, 0x0, 0x6, 0x0, 0xf8, 0xff, 0xf6, 0xff, 0xef, 0xff, 0xfd, 0xff,
+ 0xf6, 0xff, 0xa, 0x0, 0x3, 0x0, 0x9a, 0xff, 0x27, 0x0, 0xfb, 0xff, 0x18,
+ 0x0, 0x15, 0x0, 0xeb, 0xff, 0x10, 0x0, 0xf1, 0xff, 0x6, 0x0, 0xf5, 0xff,
+ 0xf8, 0xff, 0xd, 0x0, 0x1a, 0x0, 0x8, 0x0, 0xf8, 0xff, 0x0, 0x0, 0x7d,
+ 0xff, 0xf0, 0xff, 0x8, 0x0, 0xf8, 0xff, 0xf9, 0xff, 0x10, 0x0, 0x1f, 0x0,
+ 0xf8, 0xff, 0x1a, 0x0, 0xf7, 0xff, 0x8, 0x0, 0xfc, 0xff, 0x7, 0x0, 0xf5,
+ 0xff, 0xf9, 0xff, 0xe, 0x0, 0x8e, 0xff, 0x1f, 0x0, 0xf, 0x0, 0xff, 0xff,
+ 0x15, 0x0, 0xfe, 0xff, 0xfa, 0xff, 0xf, 0x0, 0xa, 0x0, 0x5, 0x0, 0xf6,
+ 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0x7, 0x0, 0x0, 0x0, 0x88, 0xff,
+ 0xf5, 0xff, 0xf7, 0xff, 0xd, 0x0, 0xe, 0x0, 0xed, 0xff, 0xf, 0x0, 0xe8,
+ 0xff, 0x12, 0x0, 0x7, 0x0, 0xf5, 0xff, 0x3, 0x0, 0x10, 0x0, 0xa, 0x0, 0x5,
+ 0x0, 0xf5, 0xff, 0x8a, 0xff, 0xfb, 0xff, 0xf9, 0xff, 0x1, 0x0, 0xf8, 0xff,
+ 0xa, 0x0, 0x11, 0x0, 0x2, 0x0, 0x19, 0x0, 0xf0, 0xff, 0xb, 0x0, 0xf5,
+ 0xff, 0x8, 0x0, 0xff, 0xff, 0xf6, 0xff, 0x13, 0x0, 0x8d, 0xff, 0x25, 0x0,
+ 0x2, 0x0, 0xfc, 0xff, 0x15, 0x0, 0xf5, 0xff, 0xe9, 0xff, 0xc, 0x0, 0xeb,
+ 0xff, 0xf4, 0xff, 0xf4, 0xff, 0xf0, 0xff, 0x5, 0x0, 0xf6, 0xff, 0x9, 0x0,
+ 0xf2, 0xff, 0x8c, 0xff, 0xe9, 0xff, 0xf9, 0xff, 0x12, 0x0, 0x5, 0x0, 0xfb,
+ 0xff, 0x17, 0x0, 0xe5, 0xff, 0x1b, 0x0, 0xfd, 0xff, 0xfc, 0xff, 0x0, 0x0,
+ 0x10, 0x0, 0xa, 0x0, 0x4, 0x0, 0xf6, 0xff, 0x90, 0xff, 0x0, 0x0, 0xff,
+ 0xff, 0xfd, 0xff, 0xe7, 0xff, 0x13, 0x0, 0x4, 0x0, 0xe, 0x0, 0x1c, 0x0,
+ 0xec, 0xff, 0x9, 0x0, 0xf3, 0xff, 0x4, 0x0, 0x5, 0x0, 0xf7, 0xff, 0x1d,
+ 0x0, 0x96, 0xff, 0x24, 0x0, 0xfa, 0xff, 0xee, 0xff, 0xd, 0x0, 0xed, 0xff,
+ 0xd1, 0xff, 0xf7, 0xff, 0xe7, 0xff, 0xef, 0xff, 0xe7, 0xff, 0xe4, 0xff,
+ 0x8, 0x0, 0x2, 0x0, 0xd, 0x0, 0xef, 0xff, 0xa3, 0xff, 0xfe, 0xff, 0xfe,
+ 0xff, 0x16, 0x0, 0x17, 0x0, 0x9, 0x0, 0xc, 0x0, 0xef, 0xff, 0xb, 0x0,
+ 0xfa, 0xff, 0x6, 0x0, 0x9, 0x0, 0x9, 0x0, 0xa, 0x0, 0x2, 0x0, 0xf9, 0xff,
+ 0xa0, 0xff, 0x19, 0x0, 0x9, 0x0, 0xff, 0xff, 0x1, 0x0, 0x9, 0x0, 0xf5,
+ 0xff, 0xb, 0x0, 0xfe, 0xff, 0xf4, 0xff, 0x5, 0x0, 0xf9, 0xff, 0x3, 0x0,
+ 0xff, 0xff, 0xf9, 0xff, 0x12, 0x0, 0xc2, 0xff, 0x4b, 0x0, 0xf1, 0xff, 0xb,
+ 0x0, 0x16, 0x0, 0xe3, 0xff, 0xd4, 0xff, 0xf5, 0xff, 0xf4, 0xff, 0x2, 0x0,
+ 0xf0, 0xff, 0xfa, 0xff, 0xd, 0x0, 0x2, 0x0, 0x4, 0x0, 0xf3, 0xff, 0xa8,
+ 0xff, 0xe, 0x0, 0xf3, 0xff, 0x1, 0x0, 0x16, 0x0, 0x7, 0x0, 0x4, 0x0, 0xef,
+ 0xff, 0xf6, 0xff, 0xb, 0x0, 0x5, 0x0, 0xd, 0x0, 0xff, 0xff, 0x7, 0x0, 0x2,
+ 0x0, 0xe7, 0xff, 0xb6, 0xff, 0x2d, 0x0, 0xe, 0x0, 0x7, 0x0, 0xa, 0x0, 0xd,
+ 0x0, 0xe9, 0xff, 0xd, 0x0, 0xe8, 0xff, 0xff, 0xff, 0x3, 0x0, 0xff, 0xff,
+ 0xfe, 0xff, 0x3, 0x0, 0xfa, 0xff, 0x3, 0x0, 0xc6, 0xff, 0x3c, 0x0, 0xf3,
+ 0xff, 0x14, 0x0, 0x11, 0x0, 0xee, 0xff, 0xd6, 0xff, 0xf8, 0xff, 0xe3,
+ 0xff, 0x8, 0x0, 0xf4, 0xff, 0x2, 0x0, 0xa, 0x0, 0x5, 0x0, 0x8, 0x0, 0xf4,
+ 0xff, 0xab, 0xff, 0x17, 0x0, 0xe7, 0xff, 0xed, 0xff, 0x4, 0x0, 0xfe, 0xff,
+ 0xa, 0x0, 0xec, 0xff, 0xd8, 0xff, 0xfe, 0xff, 0x2, 0x0, 0x10, 0x0, 0x5,
+ 0x0, 0x15, 0x0, 0xff, 0xff, 0xf1, 0xff, 0xc0, 0xff, 0x47, 0x0, 0x1, 0x0,
+ 0xf9, 0xff, 0x0, 0x0, 0xfe, 0xff, 0xe6, 0xff, 0xc, 0x0, 0xe6, 0xff, 0xf7,
+ 0xff, 0xfe, 0xff, 0x2, 0x0, 0x4, 0x0, 0xa, 0x0, 0xfc, 0xff, 0x8, 0x0,
+ 0xc3, 0xff, 0x38, 0x0, 0xf7, 0xff, 0x2, 0x0, 0x3, 0x0, 0xf7, 0xff, 0xe0,
+ 0xff, 0xed, 0xff, 0x4, 0x0, 0xfe, 0xff, 0xf0, 0xff, 0xfb, 0xff, 0x6, 0x0,
+ 0x7, 0x0, 0x5, 0x0, 0xf3, 0xff, 0xc5, 0xff, 0x2e, 0x0, 0xfb, 0xff, 0x1,
+ 0x0, 0xfb, 0xff, 0x10, 0x0, 0x14, 0x0, 0xef, 0xff, 0xb, 0x0, 0xf0, 0xff,
+ 0x5, 0x0, 0xa, 0x0, 0x7, 0x0, 0xf, 0x0, 0xf4, 0xff, 0x2, 0x0, 0xd1, 0xff,
+ 0x48, 0x0, 0x7, 0x0, 0xc, 0x0, 0x1, 0x0, 0xfc, 0xff, 0xef, 0xff, 0xfe,
+ 0xff, 0x1a, 0x0, 0xf5, 0xff, 0xf5, 0xff, 0xf7, 0xff, 0xa, 0x0, 0x6, 0x0,
+ 0x1, 0x0, 0x6, 0x0, 0xd2, 0xff, 0x37, 0x0, 0x1, 0x0, 0xd, 0x0, 0x4, 0x0,
+ 0xf9, 0xff, 0xfe, 0xff, 0xf6, 0xff, 0x23, 0x0, 0xfc, 0xff, 0xf7, 0xff,
+ 0xfe, 0xff, 0xc, 0x0, 0xf, 0x0, 0x8, 0x0, 0xf7, 0xff, 0xbf, 0xff, 0x31,
+ 0x0, 0xfc, 0xff, 0xf9, 0xff, 0xfb, 0xff, 0x3, 0x0, 0x18, 0x0, 0xf8, 0xff,
+ 0x10, 0x0, 0xeb, 0xff, 0x6, 0x0, 0xfe, 0xff, 0xc, 0x0, 0x9, 0x0, 0xfb,
+ 0xff, 0x0, 0x0, 0xd1, 0xff, 0x4b, 0x0, 0xf1, 0xff, 0xe, 0x0, 0x6, 0x0,
+ 0xea, 0xff, 0xf5, 0xff, 0xf3, 0xff, 0x2c, 0x0, 0xf0, 0xff, 0xf6, 0xff,
+ 0xed, 0xff, 0x10, 0x0, 0x9, 0x0, 0xfb, 0xff, 0x4, 0x0, 0xc6, 0xff, 0x30,
+ 0x0, 0xf5, 0xff, 0x4, 0x0, 0x0, 0x0, 0xfa, 0xff, 0xb, 0x0, 0xfa, 0xff,
+ 0x24, 0x0, 0xf8, 0xff, 0xfc, 0xff, 0xf9, 0xff, 0x8, 0x0, 0xf, 0x0, 0xff,
+ 0xff, 0xf8, 0xff, 0xbc, 0xff, 0x2e, 0x0, 0xfe, 0xff, 0xf5, 0xff, 0xf7,
+ 0xff, 0x6, 0x0, 0x12, 0x0, 0xf0, 0xff, 0x17, 0x0, 0xee, 0xff, 0x0, 0x0,
+ 0xf8, 0xff, 0xc, 0x0, 0x8, 0x0, 0xfe, 0xff, 0xff, 0xff, 0xdd, 0xff, 0x46,
+ 0x0, 0xfa, 0xff, 0x16, 0x0, 0x9, 0x0, 0xf5, 0xff, 0xfa, 0xff, 0xf1, 0xff,
+ 0x31, 0x0, 0xfd, 0xff, 0xfa, 0xff, 0xf7, 0xff, 0xe, 0x0, 0x9, 0x0, 0x2,
+ 0x0, 0x2, 0x0, 0xc1, 0xff, 0x15, 0x0, 0x4, 0x0, 0xf9, 0xff, 0xfd, 0xff,
+ 0x4, 0x0, 0x16, 0x0, 0xf9, 0xff, 0x21, 0x0, 0x1, 0x0, 0x1, 0x0, 0xfa,
+ 0xff, 0x5, 0x0, 0x9, 0x0, 0xb, 0x0, 0xf2, 0xff, 0xd0, 0xff, 0x26, 0x0,
+ 0x2, 0x0, 0x1, 0x0, 0xfd, 0xff, 0x8, 0x0, 0x12, 0x0, 0xf6, 0xff, 0x1c,
+ 0x0, 0xf0, 0xff, 0x7, 0x0, 0xfa, 0xff, 0xf, 0x0, 0x5, 0x0, 0xfe, 0xff,
+ 0x2, 0x0, 0xdb, 0xff, 0x2c, 0x0, 0xef, 0xff, 0x10, 0x0, 0xe, 0x0, 0xf0,
+ 0xff, 0xf7, 0xff, 0xf7, 0xff, 0x22, 0x0, 0xfd, 0xff, 0xfc, 0xff, 0xf9,
+ 0xff, 0xb, 0x0, 0x7, 0x0, 0x5, 0x0, 0xfb, 0xff, 0xc4, 0xff, 0x3, 0x0, 0x1,
+ 0x0, 0xfc, 0xff, 0xfa, 0xff, 0x2, 0x0, 0x11, 0x0, 0x5, 0x0, 0x13, 0x0,
+ 0xfb, 0xff, 0x4, 0x0, 0xff, 0xff, 0x1, 0x0, 0x6, 0x0, 0x8, 0x0, 0xf6,
+ 0xff, 0xd7, 0xff, 0x19, 0x0, 0x3, 0x0, 0x5, 0x0, 0xfa, 0xff, 0x1, 0x0,
+ 0x2, 0x0, 0xf9, 0xff, 0xe, 0x0, 0xef, 0xff, 0x3, 0x0, 0xfa, 0xff, 0x8,
+ 0x0, 0x1, 0x0, 0xfb, 0xff, 0x3, 0x0, 0xde, 0xff, 0x12, 0x0, 0xf5, 0xff,
+ 0xa, 0x0, 0x8, 0x0, 0xef, 0xff, 0xf7, 0xff, 0xf2, 0xff, 0x15, 0x0, 0x1,
+ 0x0, 0xf8, 0xff, 0xf7, 0xff, 0x4, 0x0, 0x6, 0x0, 0x4, 0x0, 0xf9, 0xff,
+ 0xcd, 0xff, 0xf6, 0xff, 0xc, 0x0, 0xf6, 0xff, 0xf8, 0xff, 0x5, 0x0, 0x14,
+ 0x0, 0x9, 0x0, 0xa, 0x0, 0xfb, 0xff, 0x6, 0x0, 0xff, 0xff, 0xff, 0xff,
+ 0x2, 0x0, 0x0, 0x0, 0xfc, 0xff, 0xdc, 0xff, 0xf, 0x0, 0x3, 0x0, 0x5, 0x0,
+ 0xff, 0xff, 0xf5, 0xff, 0xff, 0xff, 0xf6, 0xff, 0xf, 0x0, 0xf3, 0xff,
+ 0xfe, 0xff, 0xf5, 0xff, 0x9, 0x0, 0x0, 0x0, 0xf7, 0xff, 0x1, 0x0, 0xe1,
+ 0xff, 0xb, 0x0, 0xf9, 0xff, 0xe, 0x0, 0x7, 0x0, 0xee, 0xff, 0xfe, 0xff,
+ 0xfb, 0xff, 0x15, 0x0, 0x1, 0x0, 0xfb, 0xff, 0xf9, 0xff, 0x2, 0x0, 0x4,
+ 0x0, 0x1, 0x0, 0xfb, 0xff, 0xc8, 0xff, 0xf1, 0xff, 0xa, 0x0, 0xf5, 0xff,
+ 0xf8, 0xff, 0x2, 0x0, 0x12, 0x0, 0x9, 0x0, 0x4, 0x0, 0xf7, 0xff, 0x4, 0x0,
+ 0xfd, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xfc, 0xff, 0xe1, 0xff,
+ 0x14, 0x0, 0xfb, 0xff, 0xd, 0x0, 0x2, 0x0, 0xf3, 0xff, 0xfd, 0xff, 0xf1,
+ 0xff, 0xf, 0x0, 0xf5, 0xff, 0xfb, 0xff, 0xf5, 0xff, 0x8, 0x0, 0x2, 0x0,
+ 0xf5, 0xff, 0x4, 0x0, 0xd8, 0xff, 0x2, 0x0, 0xfa, 0xff, 0x4, 0x0, 0x4,
+ 0x0, 0xf6, 0xff, 0x0, 0x0, 0xfb, 0xff, 0x8, 0x0, 0x3, 0x0, 0xfb, 0xff,
+ 0xf8, 0xff, 0xff, 0xff, 0x6, 0x0, 0xff, 0xff, 0xf7, 0xff, 0xc9, 0xff,
+ 0xf3, 0xff, 0x8, 0x0, 0xf0, 0xff, 0xf9, 0xff, 0x4, 0x0, 0x11, 0x0, 0x2,
+ 0x0, 0x1, 0x0, 0xf8, 0xff, 0x3, 0x0, 0xfd, 0xff, 0x1, 0x0, 0x1, 0x0, 0xfa,
+ 0xff, 0xff, 0xff, 0xe3, 0xff, 0x14, 0x0, 0xfa, 0xff, 0xa, 0x0, 0x6, 0x0,
+ 0xf6, 0xff, 0xf9, 0xff, 0xf3, 0xff, 0xd, 0x0, 0xfb, 0xff, 0xfc, 0xff,
+ 0xf8, 0xff, 0x9, 0x0, 0x2, 0x0, 0xf7, 0xff, 0x3, 0x0, 0xd2, 0xff, 0xfb,
+ 0xff, 0xfb, 0xff, 0xfc, 0xff, 0x4, 0x0, 0xfc, 0xff, 0x3, 0x0, 0xfd, 0xff,
+ 0x8, 0x0, 0x6, 0x0, 0xfe, 0xff, 0xfd, 0xff, 0xfe, 0xff, 0x4, 0x0, 0x3,
+ 0x0, 0xf5, 0xff, 0xd1, 0xff, 0xfc, 0xff, 0x9, 0x0, 0xf8, 0xff, 0xfd, 0xff,
+ 0x5, 0x0, 0xf, 0x0, 0x2, 0x0, 0x5, 0x0, 0xf7, 0xff, 0x6, 0x0, 0xff, 0xff,
+ 0x3, 0x0, 0xff, 0xff, 0xfa, 0xff, 0x3, 0x0, 0xe2, 0xff, 0x11, 0x0, 0xf7,
+ 0xff, 0xa, 0x0, 0x9, 0x0, 0xf2, 0xff, 0xf7, 0xff, 0xf0, 0xff, 0x9, 0x0,
+ 0xff, 0xff, 0xfc, 0xff, 0xf7, 0xff, 0x9, 0x0, 0x1, 0x0, 0xfa, 0xff, 0xff,
+ 0xff, 0xd2, 0xff, 0xf5, 0xff, 0xfb, 0xff, 0xfc, 0xff, 0x3, 0x0, 0xfe,
+ 0xff, 0x4, 0x0, 0xff, 0xff, 0x0, 0x0, 0x5, 0x0, 0x2, 0x0, 0x0, 0x0, 0xfe,
+ 0xff, 0x3, 0x0, 0x2, 0x0, 0xf8, 0xff, 0xd2, 0xff, 0xfd, 0xff, 0x7, 0x0,
+ 0xf7, 0xff, 0xfd, 0xff, 0x4, 0x0, 0x5, 0x0, 0xfe, 0xff, 0xfc, 0xff, 0xf9,
+ 0xff, 0x5, 0x0, 0xfd, 0xff, 0x3, 0x0, 0xfe, 0xff, 0xf9, 0xff, 0x3, 0x0,
+ 0xe3, 0xff, 0xd, 0x0, 0xf5, 0xff, 0xa, 0x0, 0x8, 0x0, 0xf3, 0xff, 0xf4,
+ 0xff, 0xf0, 0xff, 0x7, 0x0, 0x4, 0x0, 0xfa, 0xff, 0xf9, 0xff, 0x7, 0x0,
+ 0x3, 0x0, 0xfc, 0xff, 0xfe, 0xff, 0xd1, 0xff, 0xf1, 0xff, 0x3, 0x0, 0xf9,
+ 0xff, 0xfd, 0xff, 0x3, 0x0, 0x6, 0x0, 0x3, 0x0, 0xfd, 0xff, 0x5, 0x0, 0x3,
+ 0x0, 0x2, 0x0, 0xfd, 0xff, 0x1, 0x0, 0x2, 0x0, 0xf8, 0xff, 0xd7, 0xff,
+ 0xfe, 0xff, 0x7, 0x0, 0xfc, 0xff, 0xfc, 0xff, 0x0, 0x0, 0x3, 0x0, 0xfc,
+ 0xff, 0xfd, 0xff, 0xfc, 0xff, 0x2, 0x0, 0xfd, 0xff, 0x5, 0x0, 0xfe, 0xff,
+ 0xf9, 0xff, 0x3, 0x0, 0xe4, 0xff, 0x8, 0x0, 0xf7, 0xff, 0xd, 0x0, 0x6,
+ 0x0, 0xf3, 0xff, 0xf6, 0xff, 0xf7, 0xff, 0x5, 0x0, 0x6, 0x0, 0xfb, 0xff,
+ 0xfc, 0xff, 0x5, 0x0, 0x3, 0x0, 0xfe, 0xff, 0xfd, 0xff, 0xcf, 0xff, 0xee,
+ 0xff, 0x3, 0x0, 0xf7, 0xff, 0xfb, 0xff, 0x2, 0x0, 0x7, 0x0, 0x6, 0x0,
+ 0xf8, 0xff, 0x3, 0x0, 0x3, 0x0, 0x2, 0x0, 0xfe, 0xff, 0x1, 0x0, 0x1, 0x0,
+ 0xf8, 0xff, 0xdc, 0xff, 0x3, 0x0, 0x1, 0x0, 0x4, 0x0, 0xfe, 0xff, 0xfd,
+ 0xff, 0xfe, 0xff, 0xfb, 0xff, 0xfe, 0xff, 0xfb, 0xff, 0x0, 0x0, 0xfd,
+ 0xff, 0x7, 0x0, 0xff, 0xff, 0xf9, 0xff, 0x5, 0x0, 0xe0, 0xff, 0x3, 0x0,
+ 0xf6, 0xff, 0x9, 0x0, 0x5, 0x0, 0xf5, 0xff, 0xf6, 0xff, 0xf8, 0xff, 0x0,
+ 0x0, 0x7, 0x0, 0xfa, 0xff, 0xfd, 0xff, 0x3, 0x0, 0x3, 0x0, 0xff, 0xff,
+ 0xf9, 0xff, 0xd0, 0xff, 0xef, 0xff, 0x6, 0x0, 0xf7, 0xff, 0xf9, 0xff, 0x3,
+ 0x0, 0x8, 0x0, 0x5, 0x0, 0xf7, 0xff, 0x1, 0x0, 0x2, 0x0, 0x3, 0x0, 0xfe,
+ 0xff, 0x1, 0x0, 0x0, 0x0, 0xfa, 0xff, 0xdf, 0xff, 0x5, 0x0, 0x1, 0x0, 0x5,
+ 0x0, 0x0, 0x0, 0xfc, 0xff, 0xfb, 0xff, 0xf9, 0xff, 0xff, 0xff, 0xfd, 0xff,
+ 0xfe, 0xff, 0xfd, 0xff, 0x6, 0x0, 0xff, 0xff, 0xf8, 0xff, 0x4, 0x0, 0xdf,
+ 0xff, 0xff, 0xff, 0xf7, 0xff, 0x5, 0x0, 0x4, 0x0, 0xf7, 0xff, 0xf9, 0xff,
+ 0xfb, 0xff, 0xff, 0xff, 0x8, 0x0, 0xfb, 0xff, 0x0, 0x0, 0x2, 0x0, 0x3,
+ 0x0, 0x1, 0x0, 0xf8, 0xff, 0xd2, 0xff, 0xf2, 0xff, 0x5, 0x0, 0xf7, 0xff,
+ 0xfa, 0xff, 0x6, 0x0, 0x7, 0x0, 0x7, 0x0, 0xf7, 0xff, 0xfe, 0xff, 0x3,
+ 0x0, 0x5, 0x0, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0xfd, 0xff, 0xe0, 0xff,
+ 0x8, 0x0, 0xfb, 0xff, 0x7, 0x0, 0x3, 0x0, 0xfb, 0xff, 0xf9, 0xff, 0xf7,
+ 0xff, 0x0, 0x0, 0xfe, 0xff, 0xfc, 0xff, 0xff, 0xff, 0x7, 0x0, 0x0, 0x0,
+ 0xfb, 0xff, 0x3, 0x0, 0xdc, 0xff, 0xfd, 0xff, 0xf7, 0xff, 0x3, 0x0, 0x4,
+ 0x0, 0xfb, 0xff, 0xfb, 0xff, 0xfe, 0xff, 0xfc, 0xff, 0x5, 0x0, 0xfc, 0xff,
+ 0x3, 0x0, 0x0, 0x0, 0x3, 0x0, 0x3, 0x0, 0xf8, 0xff, 0xd2, 0xff, 0xf6,
+ 0xff, 0x5, 0x0, 0xf7, 0xff, 0xfb, 0xff, 0x6, 0x0, 0x5, 0x0, 0x5, 0x0,
+ 0xf7, 0xff, 0xfc, 0xff, 0x2, 0x0, 0x4, 0x0, 0x0, 0x0, 0xff, 0xff, 0xfe,
+ 0xff, 0xfe, 0xff, 0xe2, 0xff, 0xa, 0x0, 0xfa, 0xff, 0x9, 0x0, 0x4, 0x0,
+ 0xfa, 0xff, 0xf7, 0xff, 0xf7, 0xff, 0x2, 0x0, 0xff, 0xff, 0xfb, 0xff,
+ 0xfe, 0xff, 0x6, 0x0, 0x1, 0x0, 0xfc, 0xff, 0x3, 0x0, 0xda, 0xff, 0xfa,
+ 0xff, 0xfb, 0xff, 0xff, 0xff, 0x2, 0x0, 0xff, 0xff, 0xfe, 0xff, 0x1, 0x0,
+ 0xfb, 0xff, 0x5, 0x0, 0xfe, 0xff, 0x3, 0x0, 0xfe, 0xff, 0x3, 0x0, 0x4,
+ 0x0, 0xf8, 0xff, 0xd6, 0xff, 0xf9, 0xff, 0x5, 0x0, 0xfa, 0xff, 0xfc, 0xff,
+ 0x4, 0x0, 0x4, 0x0, 0x2, 0x0, 0xfa, 0xff, 0xfb, 0xff, 0x2, 0x0, 0x3, 0x0,
+ 0x1, 0x0, 0xff, 0xff, 0xfe, 0xff, 0x1, 0x0, 0xe4, 0xff, 0xa, 0x0, 0xf9,
+ 0xff, 0x9, 0x0, 0x5, 0x0, 0xf9, 0xff, 0xf7, 0xff, 0xf8, 0xff, 0x2, 0x0,
+ 0x0, 0x0, 0xfb, 0xff, 0xfe, 0xff, 0x5, 0x0, 0x1, 0x0, 0xfe, 0xff, 0x1,
+ 0x0, 0xd8, 0xff, 0xf8, 0xff, 0xfd, 0xff, 0xfd, 0xff, 0x0, 0x0, 0xff, 0xff,
+ 0x1, 0x0, 0x2, 0x0, 0xfa, 0xff, 0x3, 0x0, 0xff, 0xff, 0x3, 0x0, 0xfe,
+ 0xff, 0x2, 0x0, 0x3, 0x0, 0xf8, 0xff, 0xd9, 0xff, 0xfd, 0xff, 0x4, 0x0,
+ 0xfd, 0xff, 0xfd, 0xff, 0x2, 0x0, 0x2, 0x0, 0x0, 0x0, 0xfc, 0xff, 0xfa,
+ 0xff, 0x1, 0x0, 0x1, 0x0, 0x2, 0x0, 0xff, 0xff, 0xfd, 0xff, 0x2, 0x0,
+ 0xe4, 0xff, 0x8, 0x0, 0xf8, 0xff, 0x7, 0x0, 0x5, 0x0, 0xf8, 0xff, 0xf8,
+ 0xff, 0xf7, 0xff, 0x1, 0x0, 0x1, 0x0, 0xfb, 0xff, 0xfd, 0xff, 0x4, 0x0,
+ 0x2, 0x0, 0xff, 0xff, 0xff, 0xff, 0xd8, 0xff, 0xf7, 0xff, 0x0, 0x0, 0xfb,
+ 0xff, 0xff, 0xff, 0x1, 0x0, 0x2, 0x0, 0x3, 0x0, 0xfa, 0xff, 0x1, 0x0, 0x0,
+ 0x0, 0x2, 0x0, 0xfe, 0xff, 0x1, 0x0, 0x4, 0x0, 0xfa, 0xff, 0xdc, 0xff,
+ 0x0, 0x0, 0x3, 0x0, 0xff, 0xff, 0xfe, 0xff, 0x1, 0x0, 0x0, 0x0, 0xfe,
+ 0xff, 0xfe, 0xff, 0xfb, 0xff, 0x0, 0x0, 0xff, 0xff, 0x3, 0x0, 0xff, 0xff,
+ 0xfc, 0xff, 0x3, 0x0, 0xe4, 0xff, 0x7, 0x0, 0xf8, 0xff, 0x7, 0x0, 0x5,
+ 0x0, 0xf9, 0xff, 0xf9, 0xff, 0xf9, 0xff, 0x2, 0x0, 0x2, 0x0, 0xfb, 0xff,
+ 0xfd, 0xff, 0x3, 0x0, 0x3, 0x0, 0x0, 0x0, 0xfe, 0xff, 0xd8, 0xff, 0xf7,
+ 0xff, 0x1, 0x0, 0xf9, 0xff, 0xfe, 0xff, 0x2, 0x0, 0x4, 0x0, 0x4, 0x0,
+ 0xfa, 0xff, 0xff, 0xff, 0x1, 0x0, 0x2, 0x0, 0xfe, 0xff, 0x1, 0x0, 0x2,
+ 0x0, 0xfb, 0xff, 0xe0, 0xff, 0x4, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0xff,
+ 0xff, 0xfe, 0xff, 0xfc, 0xff, 0x0, 0x0, 0xfb, 0xff, 0xff, 0xff, 0xfe,
+ 0xff, 0x3, 0x0, 0xff, 0xff, 0xfc, 0xff, 0x3, 0x0, 0xe3, 0xff, 0x4, 0x0,
+ 0xf9, 0xff, 0x5, 0x0, 0x5, 0x0, 0xfa, 0xff, 0xfa, 0xff, 0xfb, 0xff, 0x1,
+ 0x0, 0x2, 0x0, 0xfc, 0xff, 0xfe, 0xff, 0x2, 0x0, 0x3, 0x0, 0x1, 0x0, 0xfd,
+ 0xff, 0xd9, 0xff, 0xf8, 0xff, 0x2, 0x0, 0xf9, 0xff, 0xfd, 0xff, 0x3, 0x0,
+ 0x4, 0x0, 0x3, 0x0, 0xfb, 0xff, 0xfe, 0xff, 0x2, 0x0, 0x2, 0x0, 0xff,
+ 0xff, 0x1, 0x0, 0x1, 0x0, 0xfd, 0xff, 0xe2, 0xff, 0x6, 0x0, 0xff, 0xff,
+ 0x3, 0x0, 0x1, 0x0, 0xfd, 0xff, 0xfc, 0xff, 0xfb, 0xff, 0x1, 0x0, 0xfc,
+ 0xff, 0xfe, 0xff, 0xfd, 0xff, 0x4, 0x0, 0x0, 0x0, 0xfd, 0xff, 0x3, 0x0,
+ 0xe2, 0xff, 0x3, 0x0, 0xfa, 0xff, 0x3, 0x0, 0x4, 0x0, 0xfb, 0xff, 0xfc,
+ 0xff, 0xfc, 0xff, 0x0, 0x0, 0x3, 0x0, 0xfd, 0xff, 0xff, 0xff, 0x1, 0x0,
+ 0x4, 0x0, 0x2, 0x0, 0xfc, 0xff, 0xda, 0xff, 0xfa, 0xff, 0x3, 0x0, 0xfa,
+ 0xff, 0xfd, 0xff, 0x3, 0x0, 0x4, 0x0, 0x2, 0x0, 0xfc, 0xff, 0xfd, 0xff,
+ 0x2, 0x0, 0x1, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0xfe, 0xff, 0xe5,
+ 0xff, 0x8, 0x0, 0xfe, 0xff, 0x4, 0x0, 0x2, 0x0, 0xfc, 0xff, 0xfc, 0xff,
+ 0xf9, 0xff, 0x3, 0x0, 0xfd, 0xff, 0xfe, 0xff, 0xfd, 0xff, 0x4, 0x0, 0x1,
+ 0x0, 0xfd, 0xff, 0x3, 0x0, 0xe1, 0xff, 0x1, 0x0, 0xfb, 0xff, 0x1, 0x0,
+ 0x3, 0x0, 0xfc, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0x0, 0x0, 0x2, 0x0, 0xfe,
+ 0xff, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x2, 0x0, 0xfc, 0xff, 0xdc, 0xff,
+ 0xfd, 0xff, 0x3, 0x0, 0xfb, 0xff, 0xfd, 0xff, 0x3, 0x0, 0x3, 0x0, 0x1,
+ 0x0, 0xfd, 0xff, 0xfc, 0xff, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff,
+ 0xff, 0x0, 0x0, 0xe6, 0xff, 0x9, 0x0, 0xfc, 0xff, 0x5, 0x0, 0x3, 0x0,
+ 0xfb, 0xff, 0xfb, 0xff, 0xf9, 0xff, 0x3, 0x0, 0xff, 0xff, 0xfe, 0xff,
+ 0xfd, 0xff, 0x4, 0x0, 0x1, 0x0, 0xfd, 0xff, 0x1, 0x0, 0xe0, 0xff, 0xfe,
+ 0xff, 0xfd, 0xff, 0xff, 0xff, 0x1, 0x0, 0xfe, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0x2, 0x0, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0x3, 0x0,
+ 0x2, 0x0, 0xfb, 0xff, 0xdf, 0xff, 0xff, 0xff, 0x3, 0x0, 0xfc, 0xff, 0xfe,
+ 0xff, 0x2, 0x0, 0x2, 0x0, 0x0, 0x0, 0xfe, 0xff, 0xfc, 0xff, 0x1, 0x0, 0x0,
+ 0x0, 0x1, 0x0, 0x0, 0x0, 0xfe, 0xff, 0x1, 0x0, 0xe6, 0xff, 0x8, 0x0, 0xfb,
+ 0xff, 0x5, 0x0, 0x3, 0x0, 0xfa, 0xff, 0xfb, 0xff, 0xf9, 0xff, 0x3, 0x0,
+ 0x0, 0x0, 0xfd, 0xff, 0xfd, 0xff, 0x3, 0x0, 0x2, 0x0, 0xff, 0xff, 0x0,
+ 0x0, 0xe0, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfd, 0xff, 0x1, 0x0, 0xff, 0xff,
+ 0x1, 0x0, 0x0, 0x0, 0xfe, 0xff, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0xff, 0xff,
+ 0x2, 0x0, 0x1, 0x0, 0xfb, 0xff, 0xe1, 0xff, 0x2, 0x0, 0x2, 0x0, 0xfe,
+ 0xff, 0xfe, 0xff, 0x0, 0x0, 0x1, 0x0, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xff,
+ 0x1, 0x0, 0xff, 0xff, 0x2, 0x0, 0x0, 0x0, 0xfe, 0xff, 0x1, 0x0, 0xe7,
+ 0xff, 0x7, 0x0, 0xfb, 0xff, 0x4, 0x0, 0x4, 0x0, 0xfa, 0xff, 0xfb, 0xff,
+ 0xfa, 0xff, 0x2, 0x0, 0x1, 0x0, 0xfd, 0xff, 0xfe, 0xff, 0x3, 0x0, 0x2,
+ 0x0, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xfc,
+ 0xff, 0x0, 0x0, 0x1, 0x0, 0x2, 0x0, 0x1, 0x0, 0xfd, 0xff, 0x0, 0x0, 0x1,
+ 0x0, 0x1, 0x0, 0xff, 0xff, 0x2, 0x0, 0x1, 0x0, 0xfc, 0xff, 0xe3, 0xff,
+ 0x3, 0x0, 0x1, 0x0, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0xfd,
+ 0xff, 0x0, 0x0, 0xfd, 0xff, 0x0, 0x0, 0xff, 0xff, 0x2, 0x0, 0x0, 0x0,
+ 0xfe, 0xff, 0x1, 0x0, 0xe7, 0xff, 0x6, 0x0, 0xfb, 0xff, 0x3, 0x0, 0x3,
+ 0x0, 0xfb, 0xff, 0xfc, 0xff, 0xfb, 0xff, 0x2, 0x0, 0x2, 0x0, 0xfe, 0xff,
+ 0xfe, 0xff, 0x2, 0x0, 0x2, 0x0, 0xff, 0xff, 0xfe, 0xff, 0xe0, 0xff, 0xfd,
+ 0xff, 0x1, 0x0, 0xfb, 0xff, 0xff, 0xff, 0x1, 0x0, 0x3, 0x0, 0x1, 0x0,
+ 0xfc, 0xff, 0xff, 0xff, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0,
+ 0xfd, 0xff, 0xe5, 0xff, 0x6, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0xff,
+ 0xff, 0xff, 0xff, 0xfd, 0xff, 0x1, 0x0, 0xfd, 0xff, 0xff, 0xff, 0xfe,
+ 0xff, 0x3, 0x0, 0x0, 0x0, 0xfd, 0xff, 0x1, 0x0, 0xe6, 0xff, 0x4, 0x0,
+ 0xfb, 0xff, 0x2, 0x0, 0x3, 0x0, 0xfc, 0xff, 0xfd, 0xff, 0xfd, 0xff, 0x1,
+ 0x0, 0x2, 0x0, 0xfe, 0xff, 0xff, 0xff, 0x1, 0x0, 0x2, 0x0, 0x0, 0x0, 0xfd,
+ 0xff, 0xe0, 0xff, 0xfe, 0xff, 0x2, 0x0, 0xfb, 0xff, 0xfe, 0xff, 0x2, 0x0,
+ 0x2, 0x0, 0x1, 0x0, 0xfd, 0xff, 0xfe, 0xff, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0,
+ 0x1, 0x0, 0x0, 0x0, 0xfd, 0xff, 0xe6, 0xff, 0x6, 0x0, 0xff, 0xff, 0x2,
+ 0x0, 0x1, 0x0, 0xfd, 0xff, 0xfd, 0xff, 0xfd, 0xff, 0x1, 0x0, 0xfe, 0xff,
+ 0xff, 0xff, 0xfe, 0xff, 0x3, 0x0, 0x0, 0x0, 0xfe, 0xff, 0x1, 0x0, 0xe5,
+ 0xff, 0x2, 0x0, 0xfd, 0xff, 0x0, 0x0, 0x2, 0x0, 0xfd, 0xff, 0xfe, 0xff,
+ 0xfd, 0xff, 0x0, 0x0, 0x1, 0x0, 0xfe, 0xff, 0xff, 0xff, 0x1, 0x0, 0x2,
+ 0x0, 0x1, 0x0, 0xfc, 0xff, 0xe2, 0xff, 0xff, 0xff, 0x2, 0x0, 0xfc, 0xff,
+ 0xfe, 0xff, 0x1, 0x0, 0x3, 0x0, 0x1, 0x0, 0xfd, 0xff, 0xfe, 0xff, 0x1,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xfe, 0xff, 0xe7, 0xff,
+ 0x6, 0x0, 0xfe, 0xff, 0x2, 0x0, 0x1, 0x0, 0xfd, 0xff, 0xfd, 0xff, 0xfc,
+ 0xff, 0x2, 0x0, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0x2, 0x0, 0x1, 0x0,
+ 0xfe, 0xff, 0x0, 0x0, 0xe4, 0xff, 0x1, 0x0, 0xfd, 0xff, 0x0, 0x0, 0x1,
+ 0x0, 0xfe, 0xff, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0x1, 0x0, 0xff, 0xff,
+ 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x1, 0x0, 0xfc, 0xff, 0xe1, 0xff, 0x0, 0x0,
+ 0x2, 0x0, 0xfd, 0xff, 0xfe, 0xff, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0xfe,
+ 0xff, 0xfd, 0xff, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0xff, 0xff,
+ 0xff, 0xff, 0xe5, 0xff, 0x5, 0x0, 0xfd, 0xff, 0x3, 0x0, 0x2, 0x0, 0xfc,
+ 0xff, 0xfd, 0xff, 0xfc, 0xff, 0x2, 0x0, 0xff, 0xff, 0xfe, 0xff, 0xfe,
+ 0xff, 0x2, 0x0, 0x1, 0x0, 0xff, 0xff, 0xff, 0xff, 0xe1, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0xfe, 0xff, 0x0, 0x0, 0x0, 0x0, 0xff,
+ 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0xfd,
+ 0xff, 0xe1, 0xff, 0x1, 0x0, 0x1, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xfe, 0xff, 0x0, 0x0, 0xff, 0xff, 0x1,
+ 0x0, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xe4, 0xff, 0x3, 0x0, 0xfe, 0xff,
+ 0x2, 0x0, 0x1, 0x0, 0xfd, 0xff, 0xfd, 0xff, 0xfd, 0xff, 0x2, 0x0, 0x0,
+ 0x0, 0xfe, 0xff, 0xfe, 0xff, 0x1, 0x0, 0x1, 0x0, 0xff, 0xff, 0xff, 0xff,
+ 0xe1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0x0,
+ 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x1,
+ 0x0, 0x0, 0x0, 0xfe, 0xff, 0xe4, 0xff, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0xff, 0xff, 0x0, 0x0, 0xfe, 0xff, 0x0, 0x0, 0xfe, 0xff, 0x0, 0x0,
+ 0xff, 0xff, 0x1, 0x0, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xe6, 0xff, 0x1,
+ 0x0, 0xfe, 0xff, 0x0, 0x0, 0x1, 0x0, 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff,
+ 0x1, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0,
+ 0xff, 0xff, 0xe7, 0xff, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xff,
+ 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x1, 0x0, 0x0, 0x0, 0xff, 0xff, 0xea, 0xff, 0x0, 0x0, 0xff, 0xff,
+ 0x0, 0x0, 0x0, 0x0, 0xfe, 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0x1, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff,
+ 0xed, 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0xfe, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1, 0x0,
+ 0x1, 0x0, 0x0, 0x0, 0xff, 0xff, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0,
+ 0x0, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff,
+ 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xf3,
+ 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0,
+ 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0xff, 0xff, 0xf5, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0,
+ 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff}}};
+
+} // namespace sadie
diff --git a/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/hrtf_assets.h b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/hrtf_assets.h
new file mode 100644
index 000000000..77bfa225e
--- /dev/null
+++ b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/hrtf_assets.h
@@ -0,0 +1,45 @@
+/*
+Copyright 2018 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef THIRD_PARTY_SADIE_HRTF_DATABASE_GENERATED_HRTF_ASSETS_H_
+#define THIRD_PARTY_SADIE_HRTF_DATABASE_GENERATED_HRTF_ASSETS_H_
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+namespace sadie {
+
+// Note this class is automatically generated. Do not modify.
+class HrtfAssets {
+ public:
+ // Lookups and retrieves a file from an asset class.
+ //
+ // @param filename: Filename to be retrieved.
+ // @return std::string with raw file data. In case of an error, a nullptr is
+ // returned. Caller must take over the ownership of the returned data.
+ std::unique_ptr<std::string> GetFile(const std::string& filename) const;
+
+ private:
+ typedef std::unordered_map<std::string, std::vector<unsigned char>>
+ AssetDataMap;
+ static const AssetDataMap kAssetMap;
+};
+
+} // namespace sadie
+
+#endif // THIRD_PARTY_SADIE_HRTF_DATABASE_GENERATED_HRTF_ASSETS_H_
diff --git a/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/hrtf_assets.iad b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/hrtf_assets.iad
new file mode 100644
index 000000000..d5e546977
--- /dev/null
+++ b/src/3rdparty/resonance-audio/third_party/SADIE_hrtf_database/hrtf_assets.iad
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<IAD name="HrtfAssets">
+ <assets>
+ <file>WAV/Subject_002/SH/sh_hrir_order_1.wav</file>
+ <file>WAV/Subject_002/SH/sh_hrir_order_2.wav</file>
+ <file>WAV/Subject_002/SH/sh_hrir_order_3.wav</file>
+ </assets>
+</IAD>
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 000000000..7d5f3b8e8
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,28 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Generated from src.pro.
+
+add_subdirectory(resonance-audio)
+add_subdirectory(multimedia)
+if(ANDROID)
+ add_subdirectory(android)
+endif()
+if(QT_FEATURE_spatialaudio)
+ add_subdirectory(spatialaudio)
+endif()
+
+# special case begin
+if(TARGET Qt::Quick)
+ add_subdirectory(multimediaquick)
+endif()
+if(TARGET Qt::Quick3D AND QT_FEATURE_spatialaudio)
+ add_subdirectory(spatialaudioquick3d)
+endif()
+
+if(TARGET Qt::Widgets)
+ add_subdirectory(multimediawidgets)
+endif()
+
+add_subdirectory(plugins)
+#special case end
diff --git a/src/android/CMakeLists.txt b/src/android/CMakeLists.txt
new file mode 100644
index 000000000..7fb5207ba
--- /dev/null
+++ b/src/android/CMakeLists.txt
@@ -0,0 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Generated from android.pro.
+
+add_subdirectory(jar)
diff --git a/src/plugins/android/jar/AndroidManifest.xml b/src/android/jar/AndroidManifest.xml
index 17019fb34..17019fb34 100644
--- a/src/plugins/android/jar/AndroidManifest.xml
+++ b/src/android/jar/AndroidManifest.xml
diff --git a/src/android/jar/CMakeLists.txt b/src/android/jar/CMakeLists.txt
new file mode 100644
index 000000000..01e0e5a08
--- /dev/null
+++ b/src/android/jar/CMakeLists.txt
@@ -0,0 +1,32 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Generated from jar.pro.
+
+set(java_sources
+ src/org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer.java
+ src/org/qtproject/qt/android/multimedia/QtCameraListener.java
+ src/org/qtproject/qt/android/multimedia/QtCamera2.java
+ src/org/qtproject/qt/android/multimedia/QtExifDataHandler.java
+ src/org/qtproject/qt/android/multimedia/QtAudioDeviceManager.java
+ src/org/qtproject/qt/android/multimedia/QtVideoDeviceManager.java
+ src/org/qtproject/qt/android/multimedia/QtMediaRecorderListener.java
+ src/org/qtproject/qt/android/multimedia/QtMultimediaUtils.java
+ src/org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback.java
+ src/org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder.java
+ src/org/qtproject/qt/android/multimedia/QtSurfaceTextureListener.java
+)
+
+qt_internal_add_jar(Qt${QtMultimedia_VERSION_MAJOR}AndroidMultimedia
+ INCLUDE_JARS ${QT_ANDROID_JAR}
+ SOURCES ${java_sources}
+ OUTPUT_DIR "${QT_BUILD_DIR}/jar"
+)
+
+qt_path_join(destination ${INSTALL_DATADIR} "jar")
+
+install_jar(Qt${QtMultimedia_VERSION_MAJOR}AndroidMultimedia
+ DESTINATION ${destination}
+ COMPONENT Devel
+)
+
diff --git a/src/android/jar/src/org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer.java b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer.java
new file mode 100644
index 000000000..6ddc64dc2
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer.java
@@ -0,0 +1,751 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+package org.qtproject.qt.android.multimedia;
+
+import java.io.IOException;
+import java.lang.String;
+import java.util.HashMap;
+import java.io.FileInputStream;
+
+// API is level is < 9 unless marked otherwise.
+import android.content.Context;
+import android.media.MediaPlayer;
+import android.media.MediaFormat;
+import android.media.PlaybackParams;
+import android.media.AudioAttributes;
+import android.media.TimedText;
+import android.net.Uri;
+import android.util.Log;
+import java.io.FileDescriptor;
+import android.content.res.AssetFileDescriptor;
+import android.content.res.AssetManager;
+import android.view.SurfaceHolder;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+public class QtAndroidMediaPlayer
+{
+ // Native callback functions for MediaPlayer
+ native public void onErrorNative(int what, int extra, long id);
+ native public void onBufferingUpdateNative(int percent, long id);
+ native public void onProgressUpdateNative(int progress, long id);
+ native public void onDurationChangedNative(int duration, long id);
+ native public void onInfoNative(int what, int extra, long id);
+ native public void onVideoSizeChangedNative(int width, int height, long id);
+ native public void onStateChangedNative(int state, long id);
+
+ native public void onTrackInfoChangedNative(long id);
+ native public void onTimedTextChangedNative(String text, int time, long id);
+
+ private MediaPlayer mMediaPlayer = null;
+ private AudioAttributes mAudioAttributes = null;
+ private HashMap<String, String> mHeaders = null;
+ private Uri mUri = null;
+ private final long mID;
+ private final Context mContext;
+ private boolean mMuted = false;
+ private int mVolume = 100;
+ private static final String TAG = "Qt MediaPlayer";
+ private SurfaceHolder mSurfaceHolder = null;
+ private ScheduledExecutorService mProgressScheduler = null;
+ private ScheduledFuture mProgressWatcherHandle = null;
+
+ private class State {
+ final static int Uninitialized = 0x1 /* End */;
+ final static int Idle = 0x2;
+ final static int Preparing = 0x4;
+ final static int Prepared = 0x8;
+ final static int Initialized = 0x10;
+ final static int Started = 0x20;
+ final static int Stopped = 0x40;
+ final static int Paused = 0x80;
+ final static int PlaybackCompleted = 0x100;
+ final static int Error = 0x200;
+ }
+
+ public class TrackInfo
+ {
+ private int type;
+ private String mime, language;
+
+ TrackInfo(int type, String mime, String language)
+ {
+ this.type = type;
+ this.mime = mime;
+ this.language = language;
+ }
+
+ int getType() { return this.type; }
+ String getMime() { return this.mime; }
+ String getLanguage() { return this.language; }
+ }
+
+ private volatile int mState = State.Uninitialized;
+
+ /**
+ * MediaPlayer OnErrorListener
+ */
+ private class MediaPlayerErrorListener
+ implements MediaPlayer.OnErrorListener
+ {
+ @Override
+ public boolean onError(final MediaPlayer mp,
+ final int what,
+ final int extra)
+ {
+ setState(State.Error);
+ onErrorNative(what, extra, mID);
+ return true;
+ }
+ }
+
+ /**
+ * MediaPlayer OnBufferingListener
+ */
+ private class MediaPlayerBufferingListener
+ implements MediaPlayer.OnBufferingUpdateListener
+ {
+ private int mBufferPercent = -1;
+ @Override
+ public void onBufferingUpdate(final android.media.MediaPlayer mp,
+ final int percent)
+ {
+ // Avoid updates when percent is unchanged.
+ // E.g., we keep getting updates when percent == 100
+ if (mBufferPercent == percent)
+ return;
+
+ onBufferingUpdateNative((mBufferPercent = percent), mID);
+ }
+
+ }
+
+ /**
+ * MediaPlayer OnCompletionListener
+ */
+ private class MediaPlayerCompletionListener
+ implements MediaPlayer.OnCompletionListener
+ {
+ @Override
+ public void onCompletion(final MediaPlayer mp)
+ {
+ setState(State.PlaybackCompleted);
+ }
+
+ }
+
+ /**
+ * MediaPlayer OnInfoListener
+ */
+ private class MediaPlayerInfoListener
+ implements MediaPlayer.OnInfoListener
+ {
+ @Override
+ public boolean onInfo(final MediaPlayer mp,
+ final int what,
+ final int extra)
+ {
+ onInfoNative(what, extra, mID);
+ return true;
+ }
+
+ }
+
+ /**
+ * MediaPlayer OnPreparedListener
+ */
+ private class MediaPlayerPreparedListener
+ implements MediaPlayer.OnPreparedListener
+ {
+
+ @Override
+ public void onPrepared(final MediaPlayer mp)
+ {
+ setState(State.Prepared);
+ onDurationChangedNative(getDuration(), mID);
+ onTrackInfoChangedNative(mID);
+ }
+
+ }
+
+ /**
+ * MediaPlayer OnSeekCompleteListener
+ */
+ private class MediaPlayerSeekCompleteListener
+ implements MediaPlayer.OnSeekCompleteListener
+ {
+
+ @Override
+ public void onSeekComplete(final MediaPlayer mp)
+ {
+ onProgressUpdateNative(getCurrentPosition(), mID);
+ }
+
+ }
+
+ /**
+ * MediaPlayer OnVideoSizeChangedListener
+ */
+ private class MediaPlayerVideoSizeChangedListener
+ implements MediaPlayer.OnVideoSizeChangedListener
+ {
+
+ @Override
+ public void onVideoSizeChanged(final MediaPlayer mp,
+ final int width,
+ final int height)
+ {
+ onVideoSizeChangedNative(width, height, mID);
+ }
+
+ }
+
+ private class MediaPlayerTimedTextListener implements MediaPlayer.OnTimedTextListener
+ {
+ @Override public void onTimedText(MediaPlayer mp, TimedText text)
+ {
+ onTimedTextChangedNative(text.getText(), mp.getCurrentPosition(), mID);
+ }
+ }
+
+ public QtAndroidMediaPlayer(final Context context, final long id)
+ {
+ mID = id;
+ mContext = context;
+ }
+
+ public MediaPlayer getMediaPlayerHandle()
+ {
+ return mMediaPlayer;
+ }
+
+ private void setState(int state)
+ {
+ if (mState == state)
+ return;
+
+ mState = state;
+
+ onStateChangedNative(mState, mID);
+ }
+
+ private void init()
+ {
+ if (mMediaPlayer != null)
+ return;
+
+ mMediaPlayer = new MediaPlayer();
+ setState(State.Idle);
+ // Make sure the new media player has the volume that was set on the QMediaPlayer
+ setVolumeHelper(mMuted ? 0 : mVolume);
+ setAudioAttributes(mMediaPlayer, mAudioAttributes);
+
+ mMediaPlayer.setOnBufferingUpdateListener(new MediaPlayerBufferingListener());
+ mMediaPlayer.setOnCompletionListener(new MediaPlayerCompletionListener());
+ mMediaPlayer.setOnInfoListener(new MediaPlayerInfoListener());
+ mMediaPlayer.setOnSeekCompleteListener(new MediaPlayerSeekCompleteListener());
+ mMediaPlayer.setOnVideoSizeChangedListener(new MediaPlayerVideoSizeChangedListener());
+ mMediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
+ mMediaPlayer.setOnPreparedListener(new MediaPlayerPreparedListener());
+ mMediaPlayer.setOnTimedTextListener(new MediaPlayerTimedTextListener());
+ // Report playback position since there is no default listner for that in MediaPlayer
+ mProgressScheduler = Executors.newScheduledThreadPool(1);
+ }
+
+ public void startProgressWatcher()
+ {
+ // if it was shutdown, request new thread
+ if (mProgressScheduler.isTerminated() || mProgressScheduler == null)
+ mProgressScheduler = Executors.newScheduledThreadPool(1);
+
+ mProgressWatcherHandle = mProgressScheduler.scheduleAtFixedRate(new Runnable() {
+ @Override
+ public void run() {
+ if (isPlaying())
+ onProgressUpdateNative(getCurrentPosition(), mID);
+ }
+ }, 10, 100, TimeUnit.MILLISECONDS);
+ }
+
+ public void cancelProgressWatcher()
+ {
+ if (mProgressScheduler != null)
+ mProgressScheduler.shutdown();
+ }
+
+ public void start()
+ {
+ if ((mState & (State.Prepared
+ | State.Started
+ | State.Paused
+ | State.PlaybackCompleted)) == 0) {
+ return;
+ }
+
+ try {
+ mMediaPlayer.start();
+ setState(State.Started);
+ startProgressWatcher();
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+ }
+
+ public void pause()
+ {
+ if ((mState & (State.Started | State.Paused | State.PlaybackCompleted)) == 0)
+ return;
+
+ try {
+ mMediaPlayer.pause();
+ setState(State.Paused);
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+ }
+
+
+ public void stop()
+ {
+ if ((mState & (State.Prepared
+ | State.Started
+ | State.Stopped
+ | State.Paused
+ | State.PlaybackCompleted)) == 0) {
+ return;
+ }
+
+ try {
+ mMediaPlayer.stop();
+ setState(State.Stopped);
+ cancelProgressWatcher();
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+ }
+
+
+ public void seekTo(final int msec)
+ {
+ if ((mState & (State.Prepared
+ | State.Started
+ | State.Paused
+ | State.PlaybackCompleted)) == 0) {
+ return;
+ }
+
+ try {
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
+ // seekTo to closest frame of the provided msec is only available for devices
+ // with api level over 26
+ mMediaPlayer.seekTo(msec, MediaPlayer.SEEK_CLOSEST);
+ } else {
+ mMediaPlayer.seekTo(msec);
+ }
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+ }
+
+ public boolean isPlaying()
+ {
+ boolean playing = false;
+ if ((mState & (State.Idle
+ | State.Initialized
+ | State.Prepared
+ | State.Started
+ | State.Paused
+ | State.Stopped
+ | State.PlaybackCompleted)) == 0) {
+ return playing;
+ }
+
+ try {
+ playing = mMediaPlayer.isPlaying();
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+
+ return playing;
+ }
+
+ public void prepareAsync()
+ {
+ if ((mState & (State.Initialized | State.Stopped)) == 0)
+ return;
+
+ try {
+ mMediaPlayer.prepareAsync();
+ setState(State.Preparing);
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+ }
+
+ public void initHeaders()
+ {
+ mHeaders = new HashMap<String, String>();
+ }
+
+ public void setHeader(final String header, final String value)
+ {
+ mHeaders.put(header, value);
+ }
+
+ public void setDataSource(final String path)
+ {
+ if (mState == State.Uninitialized)
+ init();
+
+ if (mState != State.Idle)
+ reset();
+
+ // mediaplayer can only setDataSource if it is on State.Idle
+ if (mState != State.Idle) {
+ Log.w(TAG, "Trying to set data source of a media player that is not idle!");
+ return;
+ }
+
+ if (mSurfaceHolder != null)
+ mMediaPlayer.setDisplay(mSurfaceHolder);
+
+ AssetFileDescriptor afd = null;
+ FileInputStream fis = null;
+ try {
+ mUri = Uri.parse(path);
+ if (mUri.getScheme().compareTo("assets") == 0) {
+ final String asset = mUri.getPath().substring(1 /* Remove first '/' */);
+ final AssetManager am = mContext.getAssets();
+ afd = am.openFd(asset);
+ final long offset = afd.getStartOffset();
+ final long length = afd.getLength();
+ FileDescriptor fd = afd.getFileDescriptor();
+ mMediaPlayer.setDataSource(fd, offset, length);
+ } else if (mUri.getScheme().compareTo("file") == 0) {
+ fis = new FileInputStream(mUri.getPath());
+ FileDescriptor fd = fis.getFD();
+ mMediaPlayer.setDataSource(fd);
+ } else if (mUri.getScheme().compareTo("content") == 0) {
+ mMediaPlayer.setDataSource(mContext, mUri, mHeaders);
+ } else {
+ mMediaPlayer.setDataSource(path);
+ }
+ setState(State.Initialized);
+ } catch (final Exception exception) {
+ Log.w(TAG, exception);
+ } finally {
+ try {
+ if (afd != null)
+ afd.close();
+ if (fis != null)
+ fis.close();
+ } catch (final IOException ioe) { /* Ignore... */ }
+
+ if ((mState & State.Initialized) == 0) {
+ setState(State.Error);
+ onErrorNative(MediaPlayer.MEDIA_ERROR_UNKNOWN,
+ -1004 /*MEDIA_ERROR_IO*/,
+ mID);
+ return;
+ }
+ }
+ }
+
+ private boolean isMediaPlayerPrepared()
+ {
+ int preparedState = (State.Prepared | State.Started | State.Paused | State.Stopped
+ | State.PlaybackCompleted);
+ return ((mState & preparedState) != 0);
+ }
+
+ public TrackInfo[] getAllTrackInfo()
+ {
+ if (!isMediaPlayerPrepared()) {
+ Log.w(TAG, "Trying to get track info of a media player that is not prepared!");
+ return new TrackInfo[0];
+ }
+
+ MediaPlayer.TrackInfo[] tracks = new MediaPlayer.TrackInfo[0];
+
+ try {
+ // media player will ignore if this a out bounds index.
+ tracks = mMediaPlayer.getTrackInfo();
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+
+ int numberOfTracks = tracks.length;
+ TrackInfo[] qtTracksInfo = new TrackInfo[numberOfTracks];
+
+ for (int index = 0; index < numberOfTracks; index++) {
+
+ MediaPlayer.TrackInfo track = tracks[index];
+
+ int type = track.getTrackType();
+ String mimeType = getMimeType(track);
+ String language = track.getLanguage();
+
+ qtTracksInfo[index] = new TrackInfo(type, mimeType, language);
+ }
+
+ return qtTracksInfo;
+ }
+
+ private String getMimeType(MediaPlayer.TrackInfo trackInfo)
+ {
+ // The "octet-stream" subtype is used to indicate that a body contains arbitrary binary
+ // data.
+ String defaultMimeType = "application/octet-stream";
+
+ String mimeType = defaultMimeType;
+
+ MediaFormat mediaFormat = trackInfo.getFormat();
+ if (mediaFormat != null) {
+ mimeType = mediaFormat.getString(MediaFormat.KEY_MIME, defaultMimeType);
+ }
+
+ return mimeType;
+ }
+
+ public void selectTrack(int index)
+ {
+ if (!isMediaPlayerPrepared()) {
+ Log.d(TAG, "Trying to select a track of a media player that is not prepared!");
+ return;
+ }
+ try {
+ // media player will ignore if this a out bounds index.
+ mMediaPlayer.selectTrack(index);
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+ }
+
+ public void deselectTrack(int index)
+ {
+ if (!isMediaPlayerPrepared()) {
+ Log.d(TAG, "Trying to deselect track of a media player that is not prepared!");
+ return;
+ }
+
+ try {
+ // media player will ignore if this a out bounds index.
+ mMediaPlayer.deselectTrack(index);
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+ }
+
+ public int getSelectedTrack(int type)
+ {
+
+ int InvalidTrack = -1;
+ if (!isMediaPlayerPrepared()) {
+ Log.d(TAG, "Trying to get the selected track of a media player that is not prepared!");
+ return InvalidTrack;
+ }
+
+ boolean isVideoTrackType = (type == MediaPlayer.TrackInfo.MEDIA_TRACK_TYPE_VIDEO);
+ boolean isAudioTrackType = (type == MediaPlayer.TrackInfo.MEDIA_TRACK_TYPE_AUDIO);
+ boolean isTimedTextTrackType = (type == MediaPlayer.TrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT);
+ boolean isSubtitleTrackType = (type == MediaPlayer.TrackInfo.MEDIA_TRACK_TYPE_SUBTITLE);
+
+ if (!(isVideoTrackType || isAudioTrackType || isSubtitleTrackType
+ || isTimedTextTrackType)) {
+ Log.w(TAG,
+ "Trying to get a selected track of a invalid type"
+ + " Only Video,Audio, TimedText and Subtitle tracks are selectable.");
+ return InvalidTrack;
+ }
+
+ try {
+ return mMediaPlayer.getSelectedTrack(type);
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+
+ return InvalidTrack;
+ }
+
+ public int getCurrentPosition()
+ {
+ int currentPosition = 0;
+ if ((mState & (State.Idle
+ | State.Initialized
+ | State.Prepared
+ | State.Started
+ | State.Paused
+ | State.Stopped
+ | State.PlaybackCompleted)) == 0) {
+ return currentPosition;
+ }
+
+ try {
+ currentPosition = mMediaPlayer.getCurrentPosition();
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+
+ return currentPosition;
+ }
+
+
+ public int getDuration()
+ {
+ int duration = 0;
+ if ((mState & (State.Prepared
+ | State.Started
+ | State.Paused
+ | State.Stopped
+ | State.PlaybackCompleted)) == 0) {
+ return duration;
+ }
+
+ try {
+ duration = mMediaPlayer.getDuration();
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+
+ return duration;
+ }
+
+ public void setVolume(int volume)
+ {
+ if (volume < 0)
+ volume = 0;
+
+ if (volume > 100)
+ volume = 100;
+
+ mVolume = volume;
+
+ if (!mMuted)
+ setVolumeHelper(mVolume);
+ }
+
+ private void setVolumeHelper(int volume)
+ {
+ if ((mState & (State.Idle
+ | State.Initialized
+ | State.Stopped
+ | State.Prepared
+ | State.Started
+ | State.Paused
+ | State.PlaybackCompleted)) == 0) {
+ return;
+ }
+
+ try {
+ float newVolume = (float)volume / 100;
+ mMediaPlayer.setVolume(newVolume, newVolume);
+ } catch (final IllegalStateException exception) {
+ Log.w(TAG, exception);
+ }
+ }
+
+ public SurfaceHolder display()
+ {
+ return mSurfaceHolder;
+ }
+
+ public void setDisplay(SurfaceHolder sh)
+ {
+ mSurfaceHolder = sh;
+
+ if ((mState & State.Uninitialized) != 0)
+ return;
+
+ mMediaPlayer.setDisplay(mSurfaceHolder);
+ }
+
+
+ public int getVolume()
+ {
+ return mVolume;
+ }
+
+ public void mute(final boolean mute)
+ {
+ mMuted = mute;
+ setVolumeHelper(mute ? 0 : mVolume);
+ }
+
+ public boolean isMuted()
+ {
+ return mMuted;
+ }
+
+ public void reset()
+ {
+ if (mState == State.Uninitialized) {
+ return;
+ }
+
+ mMediaPlayer.reset();
+ setState(State.Idle);
+ cancelProgressWatcher();
+ }
+
+ public void release()
+ {
+ if (mMediaPlayer != null) {
+ mMediaPlayer.reset();
+ mMediaPlayer.release();
+ mMediaPlayer = null;
+ }
+
+ setState(State.Uninitialized);
+ cancelProgressWatcher();
+ }
+
+ public void setAudioAttributes(int type, int usage)
+ {
+ mAudioAttributes = new AudioAttributes.Builder()
+ .setUsage(usage)
+ .setContentType(type)
+ .build();
+
+ setAudioAttributes(mMediaPlayer, mAudioAttributes);
+ }
+
+ static private void setAudioAttributes(MediaPlayer player, AudioAttributes attr)
+ {
+ if (player == null || attr == null)
+ return;
+
+ try {
+ player.setAudioAttributes(attr);
+ } catch (final IllegalArgumentException exception) {
+ Log.w(TAG, exception);
+ }
+ }
+
+ public boolean setPlaybackRate(float rate)
+ {
+ PlaybackParams playbackParams = mMediaPlayer.getPlaybackParams();
+ playbackParams.setSpeed(rate);
+ // According to discussion under the patch from QTBUG-61115: At least with DirectShow
+ // and GStreamer, it changes both speed and pitch. (...) need to be consistent
+ if (rate != 0.0)
+ playbackParams.setPitch(Math.abs(rate));
+
+ try {
+ mMediaPlayer.setPlaybackParams(playbackParams);
+ } catch (IllegalStateException | IllegalArgumentException e) {
+ Log.e(TAG, "Cannot set playback rate " + rate + " :" + e.toString());
+ return false;
+ }
+
+ if ((mState & State.Started) == 0 && mMediaPlayer.isPlaying()) {
+ setState(State.Started);
+ startProgressWatcher();
+ }
+
+ return true;
+ }
+}
diff --git a/src/android/jar/src/org/qtproject/qt/android/multimedia/QtAudioDeviceManager.java b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtAudioDeviceManager.java
new file mode 100644
index 000000000..2b6fcc2dc
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtAudioDeviceManager.java
@@ -0,0 +1,361 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+package org.qtproject.qt.android.multimedia;
+
+import java.util.ArrayList;
+import android.content.Context;
+import android.media.AudioDeviceCallback;
+import android.media.AudioDeviceInfo;
+import android.media.AudioFormat;
+import android.media.AudioManager;
+import android.media.AudioRecord;
+import android.media.AudioTrack;
+import android.media.MediaRecorder;
+import android.os.Handler;
+import android.os.Looper;
+import android.util.Log;
+
+public class QtAudioDeviceManager
+{
+ private static final String TAG = "QtAudioDeviceManager";
+ static private AudioManager m_audioManager = null;
+ static private final AudioDevicesReceiver m_audioDevicesReceiver = new AudioDevicesReceiver();
+ static private Handler handler = new Handler(Looper.getMainLooper());
+ static private AudioRecord m_recorder = null;
+ static private AudioTrack m_streamPlayer = null;
+ static private Thread m_streamingThread = null;
+ static private boolean m_isStreaming = false;
+ static private boolean m_useSpeaker = false;
+ static private final int m_sampleRate = 8000;
+ static private final int m_channels = AudioFormat.CHANNEL_CONFIGURATION_MONO;
+ static private final int m_audioFormat = AudioFormat.ENCODING_PCM_16BIT;
+ static private final int m_bufferSize = AudioRecord.getMinBufferSize(m_sampleRate, m_channels, m_audioFormat);
+
+ public static native void onAudioInputDevicesUpdated();
+ public static native void onAudioOutputDevicesUpdated();
+
+ static private void updateDeviceList() {
+ onAudioInputDevicesUpdated();
+ onAudioOutputDevicesUpdated();
+ if (m_useSpeaker) {
+ final AudioDeviceInfo[] audioDevices =
+ m_audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
+ setAudioOutput(getModeForSpeaker(audioDevices), false, true);
+ }
+ }
+
+ private static class AudioDevicesReceiver extends AudioDeviceCallback {
+ @Override
+ public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
+ updateDeviceList();
+ }
+
+ @Override
+ public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
+ updateDeviceList();
+ }
+ }
+
+
+ public static void registerAudioHeadsetStateReceiver()
+ {
+ m_audioManager.registerAudioDeviceCallback(m_audioDevicesReceiver, handler);
+ }
+
+ public static void unregisterAudioHeadsetStateReceiver()
+ {
+ m_audioManager.unregisterAudioDeviceCallback(m_audioDevicesReceiver);
+ }
+
+ static public void setContext(Context context)
+ {
+ m_audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
+ }
+
+ private static String[] getAudioOutputDevices()
+ {
+ return getAudioDevices(AudioManager.GET_DEVICES_OUTPUTS);
+ }
+
+ private static String[] getAudioInputDevices()
+ {
+ return getAudioDevices(AudioManager.GET_DEVICES_INPUTS);
+ }
+
+ private static boolean isBluetoothDevice(AudioDeviceInfo deviceInfo)
+ {
+ switch (deviceInfo.getType()) {
+ case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
+ case AudioDeviceInfo.TYPE_BLUETOOTH_SCO:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ private static boolean setAudioInput(MediaRecorder recorder, int id)
+ {
+ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.P)
+ return false;
+
+ final AudioDeviceInfo[] audioDevices =
+ m_audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);
+
+ for (AudioDeviceInfo deviceInfo : audioDevices) {
+ if (deviceInfo.getId() != id)
+ continue;
+
+ boolean isPreferred = recorder.setPreferredDevice(deviceInfo);
+ if (isPreferred && isBluetoothDevice(deviceInfo)) {
+ m_audioManager.startBluetoothSco();
+ m_audioManager.setBluetoothScoOn(true);
+ }
+
+ return isPreferred;
+ }
+
+ return false;
+ }
+
+ private static void setInputMuted(boolean mute)
+ {
+ // This method mutes the microphone across the entire platform
+ m_audioManager.setMicrophoneMute(mute);
+ }
+
+ private static boolean isMicrophoneMute()
+ {
+ return m_audioManager.isMicrophoneMute();
+ }
+
+ private static String audioDeviceTypeToString(int type)
+ {
+ // API <= 23 types
+ switch (type)
+ {
+ case AudioDeviceInfo.TYPE_AUX_LINE:
+ return "AUX Line";
+ case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
+ case AudioDeviceInfo.TYPE_BLUETOOTH_SCO:
+ return "Bluetooth";
+ case AudioDeviceInfo.TYPE_BUILTIN_EARPIECE:
+ return "Built in earpiece";
+ case AudioDeviceInfo.TYPE_BUILTIN_MIC:
+ return "Built in microphone";
+ case AudioDeviceInfo.TYPE_BUILTIN_SPEAKER:
+ return "Built in speaker";
+ case AudioDeviceInfo.TYPE_DOCK:
+ return "Dock";
+ case AudioDeviceInfo.TYPE_FM:
+ return "FM";
+ case AudioDeviceInfo.TYPE_FM_TUNER:
+ return "FM TUNER";
+ case AudioDeviceInfo.TYPE_HDMI:
+ return "HDMI";
+ case AudioDeviceInfo.TYPE_HDMI_ARC:
+ return "HDMI ARC";
+ case AudioDeviceInfo.TYPE_IP:
+ return "IP";
+ case AudioDeviceInfo.TYPE_LINE_ANALOG:
+ return "Line analog";
+ case AudioDeviceInfo.TYPE_LINE_DIGITAL:
+ return "Line digital";
+ case AudioDeviceInfo.TYPE_TV_TUNER:
+ return "TV tuner";
+ case AudioDeviceInfo.TYPE_USB_ACCESSORY:
+ return "USB accessory";
+ case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
+ return "Wired headphones";
+ case AudioDeviceInfo.TYPE_WIRED_HEADSET:
+ return "Wired headset";
+ }
+
+ // API 24
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
+ if (type == AudioDeviceInfo.TYPE_BUS)
+ return "Bus";
+ }
+
+ return "Unknown-Type";
+
+ }
+
+ private static String[] getAudioDevices(int type)
+ {
+ ArrayList<String> devices = new ArrayList<>();
+
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
+ boolean builtInMicAdded = false;
+ boolean bluetoothDeviceAdded = false;
+ for (AudioDeviceInfo deviceInfo : m_audioManager.getDevices(type)) {
+ String deviceType = audioDeviceTypeToString(deviceInfo.getType());
+
+ if (deviceType.equals(audioDeviceTypeToString(AudioDeviceInfo.TYPE_UNKNOWN))) {
+ // Not supported device type
+ continue;
+ } else if (deviceType.equals(audioDeviceTypeToString(AudioDeviceInfo.TYPE_BUILTIN_MIC))) {
+ if (builtInMicAdded) {
+ // Built in mic already added. Second built in mic is CAMCORDER, but there
+ // is no reliable way of selecting it. AudioSource.MIC usually means the
+ // primary mic. AudioSource.CAMCORDER source might mean the secondary mic,
+ // but there's no guarantee. It depends e.g. on the physical placement
+ // of the mics. That's why we will not add built in microphone twice.
+ // Should we?
+ continue;
+ }
+ builtInMicAdded = true;
+ } else if (isBluetoothDevice(deviceInfo)) {
+ if (bluetoothDeviceAdded) {
+ // Bluetooth device already added. Second device is just a different
+ // technology profille (like A2DP or SCO). We should not add the same
+ // device twice. Should we?
+ continue;
+ }
+ bluetoothDeviceAdded = true;
+ }
+
+ devices.add(deviceInfo.getId() + ":" + deviceType + " ("
+ + deviceInfo.getProductName().toString() +")");
+ }
+ }
+
+ String[] ret = new String[devices.size()];
+ ret = devices.toArray(ret);
+ return ret;
+ }
+
+ private static int getModeForSpeaker(AudioDeviceInfo[] audioDevices)
+ {
+ // If we want to force device to use speaker when Bluetooth or Wiread headset is connected,
+ // we need to use MODE_IN_COMMUNICATION. Otherwise the MODE_NORMAL can be used.
+ for (AudioDeviceInfo deviceInfo : audioDevices) {
+ switch (deviceInfo.getType()) {
+ case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
+ case AudioDeviceInfo.TYPE_BLUETOOTH_SCO:
+ case AudioDeviceInfo.TYPE_WIRED_HEADSET:
+ case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
+ return AudioManager.MODE_IN_COMMUNICATION;
+ default: break;
+ }
+ }
+ return AudioManager.MODE_NORMAL;
+ }
+
+
+ private static boolean setAudioOutput(int id)
+ {
+ m_useSpeaker = false;
+ final AudioDeviceInfo[] audioDevices =
+ m_audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
+ for (AudioDeviceInfo deviceInfo : audioDevices) {
+ if (deviceInfo.getId() == id) {
+ switch (deviceInfo.getType())
+ {
+ case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
+ case AudioDeviceInfo.TYPE_BLUETOOTH_SCO:
+ setAudioOutput(AudioManager.MODE_IN_COMMUNICATION, true, false);
+ return true;
+ case AudioDeviceInfo.TYPE_BUILTIN_SPEAKER:
+ m_useSpeaker = true;
+ setAudioOutput(getModeForSpeaker(audioDevices), false, true);
+ return true;
+ case AudioDeviceInfo.TYPE_WIRED_HEADSET:
+ case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
+ setAudioOutput(AudioManager.MODE_IN_COMMUNICATION, false, false);
+ return true;
+ case AudioDeviceInfo.TYPE_BUILTIN_EARPIECE:
+ // It doesn't work when WIRED HEADPHONES are connected
+ // Earpiece has the lowest priority and setWiredHeadsetOn(boolean)
+ // method to force it is deprecated
+ Log.w(TAG, "Built in Earpiece may not work when "
+ + "Wired Headphones are connected");
+ setAudioOutput(AudioManager.MODE_IN_CALL, false, false);
+ return true;
+ case AudioDeviceInfo.TYPE_HDMI:
+ case AudioDeviceInfo.TYPE_HDMI_ARC:
+ case AudioDeviceInfo.TYPE_HDMI_EARC:
+ setAudioOutput(AudioManager.MODE_NORMAL, false, false);
+ return true;
+ default:
+ return false;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static void setAudioOutput(int mode, boolean bluetoothOn, boolean speakerOn)
+ {
+ m_audioManager.setMode(mode);
+ if (bluetoothOn) {
+ m_audioManager.startBluetoothSco();
+ } else {
+ m_audioManager.stopBluetoothSco();
+ }
+ m_audioManager.setBluetoothScoOn(bluetoothOn);
+ m_audioManager.setSpeakerphoneOn(speakerOn);
+
+ }
+
+ private static void streamSound()
+ {
+ byte data[] = new byte[m_bufferSize];
+ while (m_isStreaming) {
+ m_recorder.read(data, 0, m_bufferSize);
+ m_streamPlayer.play();
+ m_streamPlayer.write(data, 0, m_bufferSize);
+ m_streamPlayer.stop();
+ }
+ }
+
+ private static void startSoundStreaming(int inputId, int outputId)
+ {
+ if (m_isStreaming)
+ stopSoundStreaming();
+
+ m_recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, m_sampleRate, m_channels,
+ m_audioFormat, m_bufferSize);
+ m_streamPlayer = new AudioTrack(AudioManager.STREAM_MUSIC, m_sampleRate, m_channels,
+ m_audioFormat, m_bufferSize, AudioTrack.MODE_STREAM);
+
+ final AudioDeviceInfo[] devices = m_audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
+ for (AudioDeviceInfo deviceInfo : devices) {
+ if (deviceInfo.getId() == outputId) {
+ m_streamPlayer.setPreferredDevice(deviceInfo);
+ } else if (deviceInfo.getId() == inputId) {
+ m_recorder.setPreferredDevice(deviceInfo);
+ }
+ }
+
+ m_recorder.startRecording();
+ m_isStreaming = true;
+
+ m_streamingThread = new Thread(new Runnable() {
+ public void run() {
+ streamSound();
+ }
+ });
+
+ m_streamingThread.start();
+ }
+
+ private static void stopSoundStreaming()
+ {
+ if (!m_isStreaming)
+ return;
+
+ m_isStreaming = false;
+ try {
+ m_streamingThread.join();
+ m_streamingThread = null;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ m_recorder.stop();
+ m_recorder.release();
+ m_streamPlayer.release();
+ m_streamPlayer = null;
+ m_recorder = null;
+ }
+}
diff --git a/src/android/jar/src/org/qtproject/qt/android/multimedia/QtCamera2.java b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtCamera2.java
new file mode 100644
index 000000000..ac8140197
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtCamera2.java
@@ -0,0 +1,526 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+package org.qtproject.qt.android.multimedia;
+
+import org.qtproject.qt.android.multimedia.QtVideoDeviceManager;
+import org.qtproject.qt.android.multimedia.QtExifDataHandler;
+
+import android.annotation.SuppressLint;
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.graphics.Rect;
+import android.hardware.camera2.CameraAccessException;
+import android.hardware.camera2.CameraCaptureSession;
+import android.hardware.camera2.CameraDevice;
+import android.hardware.camera2.CameraMetadata;
+import android.hardware.camera2.CameraManager;
+import android.hardware.camera2.CaptureFailure;
+import android.hardware.camera2.CaptureResult;
+import android.hardware.camera2.CaptureRequest;
+import android.hardware.camera2.TotalCaptureResult;
+import android.media.Image;
+import android.media.ImageReader;
+import android.graphics.ImageFormat;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.util.Log;
+import android.util.Range;
+import android.view.Surface;
+import android.media.MediaCodec;
+import android.media.MediaCodecInfo;
+import android.media.MediaFormat;
+import java.lang.Thread;
+import java.util.ArrayList;
+import java.util.List;
+
+@TargetApi(23)
+public class QtCamera2 {
+
+ CameraDevice mCameraDevice = null;
+ QtVideoDeviceManager mVideoDeviceManager = null;
+ HandlerThread mBackgroundThread;
+ Handler mBackgroundHandler;
+ ImageReader mImageReader = null;
+ ImageReader mCapturedPhotoReader = null;
+ CameraManager mCameraManager;
+ CameraCaptureSession mCaptureSession;
+ CaptureRequest.Builder mPreviewRequestBuilder;
+ CaptureRequest mPreviewRequest;
+ String mCameraId;
+ List<Surface> mTargetSurfaces = new ArrayList<>();
+
+ private static final int STATE_PREVIEW = 0;
+ private static final int STATE_WAITING_LOCK = 1;
+ private static final int STATE_WAITING_PRECAPTURE = 2;
+ private static final int STATE_WAITING_NON_PRECAPTURE = 3;
+ private static final int STATE_PICTURE_TAKEN = 4;
+
+ private int mState = STATE_PREVIEW;
+ private Object mStartMutex = new Object();
+ private boolean mIsStarted = false;
+ private static int MaxNumberFrames = 12;
+ private int mFlashMode = CaptureRequest.CONTROL_AE_MODE_ON;
+ private int mTorchMode = CameraMetadata.FLASH_MODE_OFF;
+ private int mAFMode = CaptureRequest.CONTROL_AF_MODE_OFF;
+ private float mZoomFactor = 1.0f;
+ private Range<Integer> mFpsRange = null;
+ private QtExifDataHandler mExifDataHandler = null;
+
+ native void onCameraOpened(String cameraId);
+ native void onCameraDisconnect(String cameraId);
+ native void onCameraError(String cameraId, int error);
+ CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
+ @Override
+ public void onOpened(CameraDevice cameraDevice) {
+ if (mCameraDevice != null)
+ mCameraDevice.close();
+ mCameraDevice = cameraDevice;
+ onCameraOpened(mCameraId);
+ }
+ @Override
+ public void onDisconnected(CameraDevice cameraDevice) {
+ cameraDevice.close();
+ if (mCameraDevice == cameraDevice)
+ mCameraDevice = null;
+ onCameraDisconnect(mCameraId);
+ }
+ @Override
+ public void onError(CameraDevice cameraDevice, int error) {
+ cameraDevice.close();
+ if (mCameraDevice == cameraDevice)
+ mCameraDevice = null;
+ onCameraError(mCameraId, error);
+ }
+ };
+
+ native void onCaptureSessionConfigured(String cameraId);
+ native void onCaptureSessionConfigureFailed(String cameraId);
+ CameraCaptureSession.StateCallback mCaptureStateCallback = new CameraCaptureSession.StateCallback() {
+ @Override
+ public void onConfigured(CameraCaptureSession cameraCaptureSession) {
+ mCaptureSession = cameraCaptureSession;
+ onCaptureSessionConfigured(mCameraId);
+ }
+
+ @Override
+ public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
+ onCaptureSessionConfigureFailed(mCameraId);
+ }
+
+ @Override
+ public void onActive(CameraCaptureSession cameraCaptureSession) {
+ super.onActive(cameraCaptureSession);
+ onSessionActive(mCameraId);
+ }
+
+ @Override
+ public void onClosed(CameraCaptureSession cameraCaptureSession) {
+ super.onClosed(cameraCaptureSession);
+ onSessionClosed(mCameraId);
+ }
+ };
+
+ native void onSessionActive(String cameraId);
+ native void onSessionClosed(String cameraId);
+ native void onCaptureSessionFailed(String cameraId, int reason, long frameNumber);
+ CameraCaptureSession.CaptureCallback mCaptureCallback = new CameraCaptureSession.CaptureCallback() {
+ public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure failure) {
+ super.onCaptureFailed(session, request, failure);
+ onCaptureSessionFailed(mCameraId, failure.getReason(), failure.getFrameNumber());
+ }
+
+ private void process(CaptureResult result) {
+ switch (mState) {
+ case STATE_WAITING_LOCK: {
+ Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
+ if (afState == null) {
+ capturePhoto();
+ } else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
+ CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
+ Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
+ if (aeState == null ||
+ aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
+ mState = STATE_PICTURE_TAKEN;
+ capturePhoto();
+ } else {
+ try {
+ mPreviewRequestBuilder.set(
+ CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
+ CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
+ mState = STATE_WAITING_PRECAPTURE;
+ mCaptureSession.capture(mPreviewRequestBuilder.build(),
+ mCaptureCallback,
+ mBackgroundHandler);
+ } catch (CameraAccessException e) {
+ Log.w("QtCamera2", "Cannot get access to the camera: " + e);
+ }
+ }
+ }
+ break;
+ }
+ case STATE_WAITING_PRECAPTURE: {
+ Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
+ if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
+ mState = STATE_WAITING_NON_PRECAPTURE;
+ }
+ break;
+ }
+ case STATE_WAITING_NON_PRECAPTURE: {
+ Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
+ if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
+ mState = STATE_PICTURE_TAKEN;
+ capturePhoto();
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ @Override
+ public void onCaptureProgressed(CameraCaptureSession s, CaptureRequest r, CaptureResult partialResult) {
+ process(partialResult);
+ }
+
+ @Override
+ public void onCaptureCompleted(CameraCaptureSession s, CaptureRequest r, TotalCaptureResult result) {
+ process(result);
+ }
+ };
+
+ public QtCamera2(Context context) {
+ mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
+ mVideoDeviceManager = new QtVideoDeviceManager(context);
+ startBackgroundThread();
+ }
+
+ void startBackgroundThread() {
+ mBackgroundThread = new HandlerThread("CameraBackground");
+ mBackgroundThread.start();
+ mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
+ }
+
+ void stopBackgroundThread() {
+ mBackgroundThread.quitSafely();
+ try {
+ mBackgroundThread.join();
+ mBackgroundThread = null;
+ mBackgroundHandler = null;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @SuppressLint("MissingPermission")
+ public boolean open(String cameraId) {
+ try {
+ mCameraId = cameraId;
+ mCameraManager.openCamera(cameraId,mStateCallback,mBackgroundHandler);
+ return true;
+ } catch (Exception e){
+ Log.w("QtCamera2", "Failed to open camera:" + e);
+ }
+
+ return false;
+ }
+
+ native void onPhotoAvailable(String cameraId, Image frame);
+
+ ImageReader.OnImageAvailableListener mOnPhotoAvailableListener = new ImageReader.OnImageAvailableListener() {
+ @Override
+ public void onImageAvailable(ImageReader reader) {
+ QtCamera2.this.onPhotoAvailable(mCameraId, reader.acquireLatestImage());
+ }
+ };
+
+ native void onFrameAvailable(String cameraId, Image frame);
+
+ ImageReader.OnImageAvailableListener mOnImageAvailableListener = new ImageReader.OnImageAvailableListener() {
+ @Override
+ public void onImageAvailable(ImageReader reader) {
+ try {
+ Image img = reader.acquireLatestImage();
+ if (img != null)
+ QtCamera2.this.onFrameAvailable(mCameraId, img);
+ } catch (IllegalStateException e) {
+ // It seems that ffmpeg is processing images for too long (and does not close it)
+ // Give it a little more time. Restarting the camera session if it doesn't help
+ Log.e("QtCamera2", "Image processing taking too long. Let's wait 0,5s more " + e);
+ try {
+ Thread.sleep(500);
+ QtCamera2.this.onFrameAvailable(mCameraId, reader.acquireLatestImage());
+ } catch (IllegalStateException | InterruptedException e2) {
+ Log.e("QtCamera2", "Will not wait anymore. Restart camera session. " + e2);
+ // Remember current used camera ID, because stopAndClose will clear the value
+ String cameraId = mCameraId;
+ stopAndClose();
+ addImageReader(mImageReader.getWidth(), mImageReader.getHeight(),
+ mImageReader.getImageFormat());
+ open(cameraId);
+ }
+ }
+ }
+ };
+
+
+ public void prepareCamera(int width, int height, int format, int minFps, int maxFps) {
+
+ addImageReader(width, height, format);
+ setFrameRate(minFps, maxFps);
+ }
+
+ private void addImageReader(int width, int height, int format) {
+
+ if (mImageReader != null)
+ removeSurface(mImageReader.getSurface());
+
+ if (mCapturedPhotoReader != null)
+ removeSurface(mCapturedPhotoReader.getSurface());
+
+ mImageReader = ImageReader.newInstance(width, height, format, MaxNumberFrames);
+ mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);
+ addSurface(mImageReader.getSurface());
+
+ mCapturedPhotoReader = ImageReader.newInstance(width, height, format, MaxNumberFrames);
+ mCapturedPhotoReader.setOnImageAvailableListener(mOnPhotoAvailableListener, mBackgroundHandler);
+ addSurface(mCapturedPhotoReader.getSurface());
+ }
+
+ private void setFrameRate(int minFrameRate, int maxFrameRate) {
+
+ if (minFrameRate <= 0 || maxFrameRate <= 0)
+ mFpsRange = null;
+ else
+ mFpsRange = new Range<>(minFrameRate, maxFrameRate);
+ }
+
+ public boolean addSurface(Surface surface) {
+ if (mTargetSurfaces.contains(surface))
+ return true;
+
+ return mTargetSurfaces.add(surface);
+ }
+
+ public boolean removeSurface(Surface surface) {
+ return mTargetSurfaces.remove(surface);
+ }
+
+ public void clearSurfaces() {
+ mTargetSurfaces.clear();
+ }
+
+ public boolean createSession() {
+ if (mCameraDevice == null)
+ return false;
+
+ try {
+ mCameraDevice.createCaptureSession(mTargetSurfaces, mCaptureStateCallback, mBackgroundHandler);
+ return true;
+ } catch (Exception exception) {
+ Log.w("QtCamera2", "Failed to create a capture session:" + exception);
+ }
+ return false;
+ }
+
+ public boolean start(int template) {
+
+ if (mCameraDevice == null)
+ return false;
+
+ if (mCaptureSession == null)
+ return false;
+
+ synchronized (mStartMutex) {
+ try {
+ mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(template);
+ mPreviewRequestBuilder.addTarget(mImageReader.getSurface());
+ mAFMode = CaptureRequest.CONTROL_AF_MODE_OFF;
+ for (int mode : mVideoDeviceManager.getSupportedAfModes(mCameraId)) {
+ if (mode == CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE) {
+ mAFMode = mode;
+ break;
+ }
+ }
+
+ mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, mFlashMode);
+ mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE, mTorchMode);
+ mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_IDLE);
+ mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, mAFMode);
+ mPreviewRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CameraMetadata.CONTROL_CAPTURE_INTENT_VIDEO_RECORD);
+ if (mZoomFactor != 1.0f)
+ mPreviewRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, getScalerCropRegion());
+ if (mFpsRange != null)
+ mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, mFpsRange);
+ mPreviewRequest = mPreviewRequestBuilder.build();
+ mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
+ mIsStarted = true;
+ return true;
+
+ } catch (Exception exception) {
+ Log.w("QtCamera2", "Failed to start preview:" + exception);
+ }
+ return false;
+ }
+ }
+
+ public void stopAndClose() {
+ synchronized (mStartMutex) {
+ try {
+ if (null != mCaptureSession) {
+ mCaptureSession.close();
+ mCaptureSession = null;
+ }
+ if (null != mCameraDevice) {
+ mCameraDevice.close();
+ mCameraDevice = null;
+ }
+ mCameraId = "";
+ mTargetSurfaces.clear();
+ } catch (Exception exception) {
+ Log.w("QtCamera2", "Failed to stop and close:" + exception);
+ }
+ mIsStarted = false;
+ }
+ }
+
+ private void capturePhoto() {
+ try {
+ final CaptureRequest.Builder captureBuilder =
+ mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
+ captureBuilder.addTarget(mCapturedPhotoReader.getSurface());
+ captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, mFlashMode);
+ if (mZoomFactor != 1.0f)
+ captureBuilder.set(CaptureRequest.SCALER_CROP_REGION, getScalerCropRegion());
+
+ CameraCaptureSession.CaptureCallback captureCallback
+ = new CameraCaptureSession.CaptureCallback() {
+ @Override
+ public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
+ TotalCaptureResult result) {
+ try {
+ mExifDataHandler = new QtExifDataHandler(result);
+ // Reset the focus/flash and go back to the normal state of preview.
+ mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
+ CameraMetadata.CONTROL_AF_TRIGGER_IDLE);
+ mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
+ CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_IDLE);
+ mPreviewRequest = mPreviewRequestBuilder.build();
+ mState = STATE_PREVIEW;
+ mCaptureSession.setRepeatingRequest(mPreviewRequest,
+ mCaptureCallback,
+ mBackgroundHandler);
+ } catch (CameraAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ };
+
+ mCaptureSession.capture(captureBuilder.build(), captureCallback, mBackgroundHandler);
+ } catch (CameraAccessException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void takePhoto() {
+ try {
+ if (mAFMode == CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE) {
+ mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
+ mState = STATE_WAITING_LOCK;
+ mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
+ } else {
+ capturePhoto();
+ }
+ } catch (CameraAccessException e) {
+ Log.w("QtCamera2", "Cannot get access to the camera: " + e);
+ }
+ }
+
+ public void saveExifToFile(String path)
+ {
+ if (mExifDataHandler != null)
+ mExifDataHandler.save(path);
+ else
+ Log.e("QtCamera2", "No Exif data that could be saved to " + path);
+ }
+
+ private Rect getScalerCropRegion()
+ {
+ Rect activePixels = mVideoDeviceManager.getActiveArraySize(mCameraId);
+ float zoomRatio = 1.0f;
+ if (mZoomFactor != 0.0f)
+ zoomRatio = 1.0f/mZoomFactor;
+ int croppedWidth = activePixels.width() - (int)(activePixels.width() * zoomRatio);
+ int croppedHeight = activePixels.height() - (int)(activePixels.height() * zoomRatio);
+ return new Rect(croppedWidth/2, croppedHeight/2, activePixels.width() - croppedWidth/2,
+ activePixels.height() - croppedHeight/2);
+ }
+
+ public void zoomTo(float factor)
+ {
+ synchronized (mStartMutex) {
+ mZoomFactor = factor;
+
+ if (!mIsStarted) {
+ Log.w("QtCamera2", "Cannot set zoom on invalid camera");
+ return;
+ }
+
+ mPreviewRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, getScalerCropRegion());
+ mPreviewRequest = mPreviewRequestBuilder.build();
+
+ try {
+ mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
+ } catch (Exception exception) {
+ Log.w("QtCamera2", "Failed to set zoom:" + exception);
+ }
+ }
+ }
+ public void setFlashMode(String flashMode)
+ {
+ synchronized (mStartMutex) {
+
+ int flashModeValue = mVideoDeviceManager.stringToControlAEMode(flashMode);
+ if (flashModeValue < 0) {
+ Log.w("QtCamera2", "Unknown flash mode");
+ return;
+ }
+ mFlashMode = flashModeValue;
+
+ if (!mIsStarted)
+ return;
+
+ mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, mFlashMode);
+ mPreviewRequest = mPreviewRequestBuilder.build();
+
+ try {
+ mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
+ } catch (Exception exception) {
+ Log.w("QtCamera2", "Failed to set flash mode:" + exception);
+ }
+ }
+ }
+
+ private int getTorchModeValue(boolean mode)
+ {
+ return mode ? CameraMetadata.FLASH_MODE_TORCH : CameraMetadata.FLASH_MODE_OFF;
+ }
+
+ public void setTorchMode(boolean torchMode)
+ {
+ synchronized (mStartMutex) {
+ mTorchMode = getTorchModeValue(torchMode);
+
+ if (mIsStarted) {
+ mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE, mTorchMode);
+ mPreviewRequest = mPreviewRequestBuilder.build();
+
+ try {
+ mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
+ } catch (Exception exception) {
+ Log.w("QtCamera2", "Failed to set flash mode:" + exception);
+ }
+ }
+ }
+ }
+}
diff --git a/src/android/jar/src/org/qtproject/qt/android/multimedia/QtCameraListener.java b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtCameraListener.java
new file mode 100644
index 000000000..3e35eb416
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtCameraListener.java
@@ -0,0 +1,207 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+package org.qtproject.qt.android.multimedia;
+
+import android.hardware.Camera;
+import android.hardware.Camera.CameraInfo;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.ImageFormat;
+import android.graphics.Matrix;
+import android.graphics.SurfaceTexture;
+import android.util.Log;
+import java.lang.Math;
+import java.io.ByteArrayOutputStream;
+
+public class QtCameraListener implements Camera.ShutterCallback,
+ Camera.PictureCallback,
+ Camera.AutoFocusCallback,
+ Camera.PreviewCallback
+{
+ private static final String TAG = "Qt Camera";
+
+ private static final int BUFFER_POOL_SIZE = 2;
+
+ private int m_cameraId = -1;
+
+ private boolean m_notifyNewFrames = false;
+ private boolean m_notifyWhenFrameAvailable = false;
+ private byte[][] m_previewBuffers = null;
+ private byte[] m_lastPreviewBuffer = null;
+ private Camera.Size m_previewSize = null;
+ private int m_previewFormat = ImageFormat.NV21; // Default preview format on all devices
+ private int m_previewBytesPerLine = -1;
+ private int m_rotation = 0;
+
+ private QtCameraListener(int id)
+ {
+ m_cameraId = id;
+ }
+
+ public void notifyNewFrames(boolean notify)
+ {
+ m_notifyNewFrames = notify;
+ }
+
+ public void notifyWhenFrameAvailable(boolean notify)
+ {
+ m_notifyWhenFrameAvailable = notify;
+ }
+
+ public byte[] lastPreviewBuffer()
+ {
+ return m_lastPreviewBuffer;
+ }
+
+ public int previewWidth()
+ {
+ if (m_previewSize == null)
+ return -1;
+
+ return m_previewSize.width;
+ }
+
+ public int previewHeight()
+ {
+ if (m_previewSize == null)
+ return -1;
+
+ return m_previewSize.height;
+ }
+
+ public int previewFormat()
+ {
+ return m_previewFormat;
+ }
+
+ public int previewBytesPerLine()
+ {
+ return m_previewBytesPerLine;
+ }
+
+ public void clearPreviewCallback(Camera camera)
+ {
+ camera.setPreviewCallbackWithBuffer(null);
+ }
+
+ public void setPhotoRotation(int rotation)
+ {
+ m_rotation = rotation;
+ }
+
+ public void setupPreviewCallback(Camera camera)
+ {
+ // Clear previous callback (also clears added buffers)
+ clearPreviewCallback(camera);
+ m_lastPreviewBuffer = null;
+
+ final Camera.Parameters params = camera.getParameters();
+ m_previewSize = params.getPreviewSize();
+ m_previewFormat = params.getPreviewFormat();
+
+ int bufferSizeNeeded = 0;
+ if (m_previewFormat == ImageFormat.YV12) {
+ // For YV12, bytes per line must be a multiple of 16
+ final int yStride = (int) Math.ceil(m_previewSize.width / 16.0) * 16;
+ final int uvStride = (int) Math.ceil((yStride / 2) / 16.0) * 16;
+ final int ySize = yStride * m_previewSize.height;
+ final int uvSize = uvStride * m_previewSize.height / 2;
+ bufferSizeNeeded = ySize + uvSize * 2;
+
+ m_previewBytesPerLine = yStride;
+
+ } else {
+ double bytesPerPixel = ImageFormat.getBitsPerPixel(m_previewFormat) / 8.0;
+ bufferSizeNeeded = (int) Math.ceil(bytesPerPixel * m_previewSize.width * m_previewSize.height);
+
+ // bytes per line are calculated only for the first plane
+ switch (m_previewFormat) {
+ case ImageFormat.NV21:
+ m_previewBytesPerLine = m_previewSize.width; // 1 byte per sample and tightly packed
+ break;
+ case ImageFormat.RGB_565:
+ case ImageFormat.YUY2:
+ m_previewBytesPerLine = m_previewSize.width * 2; // 2 bytes per pixel
+ break;
+ default:
+ m_previewBytesPerLine = -1;
+ break;
+ }
+ }
+
+ // We could keep the same buffers when they are already bigger than the required size
+ // but the Android doc says the size must match, so in doubt just replace them.
+ if (m_previewBuffers == null || m_previewBuffers[0].length != bufferSizeNeeded)
+ m_previewBuffers = new byte[BUFFER_POOL_SIZE][bufferSizeNeeded];
+
+ // Add callback and queue all buffers
+ camera.setPreviewCallbackWithBuffer(this);
+ for (byte[] buffer : m_previewBuffers)
+ camera.addCallbackBuffer(buffer);
+ }
+
+ @Override
+ public void onPreviewFrame(byte[] data, Camera camera)
+ {
+ // Re-enqueue the last buffer
+ if (m_lastPreviewBuffer != null)
+ camera.addCallbackBuffer(m_lastPreviewBuffer);
+
+ m_lastPreviewBuffer = data;
+
+ if (data != null) {
+ if (m_notifyWhenFrameAvailable) {
+ m_notifyWhenFrameAvailable = false;
+ notifyFrameAvailable(m_cameraId);
+ }
+ if (m_notifyNewFrames) {
+ notifyNewPreviewFrame(m_cameraId, data,
+ m_previewSize.width, m_previewSize.height,
+ m_previewFormat,
+ m_previewBytesPerLine);
+ }
+ }
+ }
+
+ @Override
+ public void onShutter()
+ {
+ notifyPictureExposed(m_cameraId);
+ }
+
+ @Override
+ public void onPictureTaken(byte[] data, Camera camera)
+ {
+ Camera.CameraInfo info = new Camera.CameraInfo();
+ Camera.getCameraInfo(m_cameraId, info);
+ Bitmap source = BitmapFactory.decodeByteArray(data, 0, data.length);
+ Matrix matrix = new Matrix();
+ matrix.postRotate(m_rotation);
+ if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
+ matrix.postScale(-1, 1, source.getWidth() / 2.0f, source.getHeight() / 2.0f);
+ }
+ Bitmap rotatedBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(),
+ source.getHeight(), matrix, true);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ rotatedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
+ byte[] byteArray = outputStream.toByteArray();
+ rotatedBitmap.recycle();
+ source.recycle();
+ notifyPictureCaptured(m_cameraId, byteArray);
+ }
+
+ @Override
+ public void onAutoFocus(boolean success, Camera camera)
+ {
+ notifyAutoFocusComplete(m_cameraId, success);
+ }
+
+ private static native void notifyAutoFocusComplete(int id, boolean success);
+ private static native void notifyPictureExposed(int id);
+ private static native void notifyPictureCaptured(int id, byte[] data);
+ private static native void notifyNewPreviewFrame(int id, byte[] data, int width, int height,
+ int pixelFormat, int bytesPerLine);
+ private static native void notifyFrameAvailable(int id);
+}
diff --git a/src/android/jar/src/org/qtproject/qt/android/multimedia/QtExifDataHandler.java b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtExifDataHandler.java
new file mode 100644
index 000000000..c2699eb1d
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtExifDataHandler.java
@@ -0,0 +1,51 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+package org.qtproject.qt.android.multimedia;
+
+import android.hardware.camera2.CaptureResult;
+import android.media.ExifInterface;
+import android.os.Build;
+import android.util.Log;
+
+import java.io.IOException;
+
+public class QtExifDataHandler {
+
+ private int mFlashFired = 0;
+ private long mExposureTime = 0L;
+ private float mFocalLength = 0;
+ private static String mModel = Build.MANUFACTURER + " " + Build.MODEL;
+
+ public QtExifDataHandler(CaptureResult r)
+ {
+ Integer flash = r.get(CaptureResult.FLASH_STATE);
+ if (flash != null && flash == CaptureResult.FLASH_STATE_FIRED)
+ mFlashFired = 1;
+
+ Long exposureTime = r.get(CaptureResult.SENSOR_EXPOSURE_TIME);
+ if (exposureTime != null)
+ mExposureTime = exposureTime/1000000000;
+ mFocalLength = r.get(CaptureResult.LENS_FOCAL_LENGTH);
+ }
+
+ public void save(String path)
+ {
+ ExifInterface exif;
+ try {
+ exif = new ExifInterface(path);
+ } catch ( IOException e ) {
+ Log.e("QtExifDataHandler", "Cannot open file: " + path + "\n" + e);
+ return;
+ }
+ exif.setAttribute(ExifInterface.TAG_FLASH, String.valueOf(mFlashFired));
+ exif.setAttribute(ExifInterface.TAG_EXPOSURE_TIME, String.valueOf(mExposureTime));
+ exif.setAttribute(ExifInterface.TAG_FOCAL_LENGTH, String.valueOf(mFocalLength));
+ exif.setAttribute(ExifInterface.TAG_MODEL, mModel);
+
+ try {
+ exif.saveAttributes();
+ } catch ( IOException e ) {
+ Log.e("QtExifDataHandler", "Cannot save file: " + path + "\n" + e);
+ }
+ }
+}
diff --git a/src/android/jar/src/org/qtproject/qt/android/multimedia/QtMediaRecorderListener.java b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtMediaRecorderListener.java
new file mode 100644
index 000000000..97d317119
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtMediaRecorderListener.java
@@ -0,0 +1,31 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+package org.qtproject.qt.android.multimedia;
+
+import android.media.MediaRecorder;
+
+public class QtMediaRecorderListener implements MediaRecorder.OnErrorListener, MediaRecorder.OnInfoListener
+{
+ private long m_id = -1;
+
+ public QtMediaRecorderListener(long id)
+ {
+ m_id = id;
+ }
+
+ @Override
+ public void onError(MediaRecorder mr, int what, int extra)
+ {
+ notifyError(m_id, what, extra);
+ }
+
+ @Override
+ public void onInfo(MediaRecorder mr, int what, int extra)
+ {
+ notifyInfo(m_id, what, extra);
+ }
+
+ private static native void notifyError(long id, int what, int extra);
+ private static native void notifyInfo(long id, int what, int extra);
+}
diff --git a/src/android/jar/src/org/qtproject/qt/android/multimedia/QtMultimediaUtils.java b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtMultimediaUtils.java
new file mode 100644
index 000000000..bfac6670f
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtMultimediaUtils.java
@@ -0,0 +1,148 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+package org.qtproject.qt.android.multimedia;
+
+import android.app.Activity;
+import android.content.Context;
+import android.media.MediaCodecInfo;
+import android.media.MediaCodecList;
+import android.view.OrientationEventListener;
+import android.webkit.MimeTypeMap;
+import android.net.Uri;
+import android.content.ContentResolver;
+import android.os.Environment;
+import android.media.MediaScannerConnection;
+import java.lang.String;
+import java.io.File;
+import android.util.Log;
+
+public class QtMultimediaUtils
+{
+ static private class OrientationListener extends OrientationEventListener
+ {
+ static public int deviceOrientation = 0;
+
+ public OrientationListener(Context context)
+ {
+ super(context);
+ }
+
+ @Override
+ public void onOrientationChanged(int orientation)
+ {
+ if (orientation == ORIENTATION_UNKNOWN)
+ return;
+
+ deviceOrientation = orientation;
+ }
+ }
+
+ static private Context m_context = null;
+ static private OrientationListener m_orientationListener = null;
+ private static final String QtTAG = "Qt QtMultimediaUtils";
+
+ static public void setActivity(Activity qtMainActivity, Object qtActivityDelegate)
+ {
+ }
+
+ static public void setContext(Context context)
+ {
+ m_context = context;
+ m_orientationListener = new OrientationListener(context);
+ }
+
+ public QtMultimediaUtils()
+ {
+ }
+
+ static void enableOrientationListener(boolean enable)
+ {
+ if (enable)
+ m_orientationListener.enable();
+ else
+ m_orientationListener.disable();
+ }
+
+ static int getDeviceOrientation()
+ {
+ return m_orientationListener.deviceOrientation;
+ }
+
+ static String getDefaultMediaDirectory(int type)
+ {
+ String dirType = new String();
+ switch (type) {
+ case 0:
+ dirType = Environment.DIRECTORY_MUSIC;
+ break;
+ case 1:
+ dirType = Environment.DIRECTORY_MOVIES;
+ break;
+ case 2:
+ dirType = Environment.DIRECTORY_DCIM;
+ break;
+ default:
+ break;
+ }
+
+ File path = new File("");
+ if (type == 3) {
+ // There is no API for knowing the standard location for sounds
+ // such as voice recording. Though, it's typically in the 'Sounds'
+ // directory at the root of the external storage
+ path = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ + File.separator + "Sounds");
+ } else {
+ path = Environment.getExternalStoragePublicDirectory(dirType);
+ }
+
+ path.mkdirs(); // make sure the directory exists
+
+ return path.getAbsolutePath();
+ }
+
+ static void registerMediaFile(String file)
+ {
+ MediaScannerConnection.scanFile(m_context, new String[] { file }, null, null);
+ }
+
+ static File getCacheDirectory() { return m_context.getCacheDir(); }
+
+ /*
+ The array of codecs is in the form:
+ c2.qti.vp9.decoder
+ c2.android.opus.encoder
+ OMX.google.opus.decoder
+ */
+ private static String[] getMediaCodecs()
+ {
+ final MediaCodecList codecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
+ final MediaCodecInfo[] codecInfoArray = codecList.getCodecInfos();
+ String[] codecs = new String[codecInfoArray.length];
+ for (int i = 0; i < codecInfoArray.length; ++i)
+ codecs[i] = codecInfoArray[i].getName();
+ return codecs;
+ }
+
+public static String getMimeType(Context context, String url)
+{
+ Uri parsedUri = Uri.parse(url);
+ String type = null;
+
+ try {
+ String scheme = parsedUri.getScheme();
+ if (scheme != null && scheme.contains("content")) {
+ ContentResolver cR = context.getContentResolver();
+ type = cR.getType(parsedUri);
+ } else {
+ String extension = MimeTypeMap.getFileExtensionFromUrl(url);
+ if (extension != null)
+ type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
+ }
+ } catch (Exception e) {
+ Log.e(QtTAG, "getMimeType(): " + e.toString());
+ }
+ return type;
+}
+}
diff --git a/src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback.java b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback.java
new file mode 100644
index 000000000..30dad68d5
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback.java
@@ -0,0 +1,37 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+package org.qtproject.qt.android.multimedia;
+
+import android.view.SurfaceHolder;
+
+public class QtSurfaceHolderCallback implements SurfaceHolder.Callback
+{
+ private long m_id = -1;
+
+ public QtSurfaceHolderCallback(long id)
+ {
+ m_id = id;
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
+ {
+ }
+
+ @Override
+ public void surfaceCreated(SurfaceHolder holder)
+ {
+ notifySurfaceCreated(m_id);
+ }
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder)
+ {
+ notifySurfaceDestroyed(m_id);
+ }
+
+
+ private static native void notifySurfaceCreated(long id);
+ private static native void notifySurfaceDestroyed(long id);
+}
diff --git a/src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder.java b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder.java
new file mode 100644
index 000000000..59406ca59
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder.java
@@ -0,0 +1,89 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+package org.qtproject.qt.android.multimedia;
+
+import android.view.SurfaceHolder;
+import android.view.Surface;
+import android.graphics.Rect;
+import android.graphics.Canvas;
+
+public class QtSurfaceTextureHolder implements SurfaceHolder
+{
+ private Surface surfaceTexture;
+
+ public QtSurfaceTextureHolder(Surface surface)
+ {
+ surfaceTexture = surface;
+ }
+
+ @Override
+ public void addCallback(SurfaceHolder.Callback callback)
+ {
+ }
+
+ @Override
+ public Surface getSurface()
+ {
+ return surfaceTexture;
+ }
+
+ @Override
+ public Rect getSurfaceFrame()
+ {
+ return new Rect();
+ }
+
+ @Override
+ public boolean isCreating()
+ {
+ return false;
+ }
+
+ @Override
+ public Canvas lockCanvas(Rect dirty)
+ {
+ return new Canvas();
+ }
+
+ @Override
+ public Canvas lockCanvas()
+ {
+ return new Canvas();
+ }
+
+ @Override
+ public void removeCallback(SurfaceHolder.Callback callback)
+ {
+ }
+
+ @Override
+ public void setFixedSize(int width, int height)
+ {
+ }
+
+ @Override
+ public void setFormat(int format)
+ {
+ }
+
+ @Override
+ public void setKeepScreenOn(boolean screenOn)
+ {
+ }
+
+ @Override
+ public void setSizeFromLayout()
+ {
+ }
+
+ @Override
+ public void setType(int type)
+ {
+ }
+
+ @Override
+ public void unlockCanvasAndPost(Canvas canvas)
+ {
+ }
+}
diff --git a/src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureListener.java b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureListener.java
new file mode 100644
index 000000000..4974f9301
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureListener.java
@@ -0,0 +1,24 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+package org.qtproject.qt.android.multimedia;
+
+import android.graphics.SurfaceTexture;
+
+public class QtSurfaceTextureListener implements SurfaceTexture.OnFrameAvailableListener
+{
+ private final long m_id;
+
+ public QtSurfaceTextureListener(long id)
+ {
+ m_id = id;
+ }
+
+ @Override
+ public void onFrameAvailable(SurfaceTexture surfaceTexture)
+ {
+ notifyFrameAvailable(m_id);
+ }
+
+ private static native void notifyFrameAvailable(long id);
+}
diff --git a/src/android/jar/src/org/qtproject/qt/android/multimedia/QtVideoDeviceManager.java b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtVideoDeviceManager.java
new file mode 100644
index 000000000..2e11e62a2
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt/android/multimedia/QtVideoDeviceManager.java
@@ -0,0 +1,247 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+package org.qtproject.qt.android.multimedia;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.graphics.ImageFormat;
+import android.graphics.Rect;
+import android.hardware.camera2.CameraCharacteristics;
+import android.hardware.camera2.CameraManager;
+import android.hardware.camera2.CaptureRequest;
+import android.hardware.camera2.params.StreamConfigurationMap;
+import android.media.MediaCodecList;
+import android.media.MediaCodecInfo;
+import android.os.Build;
+import android.util.Range;
+import android.util.Size;
+import android.util.Log;
+
+import java.lang.String;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+public class QtVideoDeviceManager {
+
+ CameraManager mCameraManager;
+ Map<String, CameraCharacteristics> cache;
+
+ public QtVideoDeviceManager(Context context) {
+ mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
+ cache = new WeakHashMap<String, CameraCharacteristics>();
+ }
+
+ public CameraCharacteristics getCameraCharacteristics(String cameraId) {
+
+ if (cache.containsKey(cameraId))
+ return cache.get(cameraId);
+
+ try {
+ CameraCharacteristics cameraCharacteristics = mCameraManager.getCameraCharacteristics(cameraId);
+ cache.put(cameraId, cameraCharacteristics);
+ return cameraCharacteristics;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ static private boolean isSoftwareCodec(String longCodecName) {
+ longCodecName = longCodecName.toLowerCase();
+ return longCodecName.startsWith("omx.google.") || longCodecName.startsWith("c2.android.")
+ || !(longCodecName.startsWith("omx.") || longCodecName.startsWith("c2."));
+ }
+
+ private enum CODEC {
+ DECODER,
+ ENCODER
+ }
+ static private String[] getHWVideoCodecs(CODEC expectedType) {
+ MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
+ MediaCodecInfo[] mediaCodecInfo = mediaCodecList.getCodecInfos();
+ Set<String> codecs = new HashSet<String>();
+
+ for (MediaCodecInfo codecInfo : mediaCodecInfo) {
+ CODEC currentType = codecInfo.isEncoder() ? CODEC.ENCODER : CODEC.DECODER;
+ if (currentType == expectedType && !isSoftwareCodec(codecInfo.getName())) {
+ String[] supportedTypes = codecInfo.getSupportedTypes();
+ for (String type : supportedTypes) {
+ if (type.startsWith("video/"))
+ codecs.add(type.substring(6));
+ }
+ }
+ }
+ return codecs.toArray(new String[codecs.size()]);
+ }
+
+ static public String[] getHWVideoDecoders() { return getHWVideoCodecs(CODEC.DECODER); }
+ static public String[] getHWVideoEncoders() { return getHWVideoCodecs(CODEC.ENCODER); }
+
+ public String[] getCameraIdList() {
+ try {
+ return mCameraManager.getCameraIdList();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public int getSensorOrientation(String cameraId) {
+ CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
+ if (characteristics == null)
+ return 0;
+ return characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
+ }
+
+ public int getLensFacing(String cameraId) {
+ CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
+ if (characteristics == null)
+ return 0;
+ return characteristics.get(CameraCharacteristics.LENS_FACING);
+ }
+
+ public String[] getFpsRange(String cameraId) {
+
+ CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
+ if (characteristics == null)
+ return new String[0];
+
+ Range<Integer>[] ranges = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
+
+ String[] fps = new String[ranges.length];
+
+ for (int index = 0; index < ranges.length; index++) {
+ fps[index] = ranges[index].toString();
+ }
+
+ return fps;
+ }
+
+ public float getMaxZoom(String cameraId) {
+
+ float maxZoom = 1.0f;
+ final CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
+ if (characteristics != null)
+ maxZoom = characteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
+ return maxZoom;
+ }
+
+ public Rect getActiveArraySize(String cameraId) {
+ Rect activeArraySize = new Rect();
+ final CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
+ if (characteristics != null)
+ activeArraySize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
+ return activeArraySize;
+ }
+
+ static final int maxResolution = 3840*2160; // 4k resolution
+ public String[] getStreamConfigurationsSizes(String cameraId, int imageFormat) {
+
+ CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
+ if (characteristics == null)
+ return new String[0];
+
+ StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
+ Size[] sizes = map.getOutputSizes(imageFormat);
+ if (sizes == null)
+ return new String[0];
+
+ ArrayList<String> stream = new ArrayList<>();
+
+ for (int index = 0; index < sizes.length; index++) {
+ if (sizes[index].getWidth() * sizes[index].getHeight() <= maxResolution)
+ stream.add(sizes[index].toString());
+ }
+
+ return stream.toArray(new String[0]);
+ }
+
+ public int stringToControlAEMode(String mode) {
+ switch (mode) {
+ case "off":
+ return CaptureRequest.CONTROL_AE_MODE_ON;
+ case "auto":
+ return CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH;
+ case "on":
+ return CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH;
+ case "redeye":
+ return CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE;
+ case "external":
+ return CaptureRequest.CONTROL_AE_MODE_ON_EXTERNAL_FLASH;
+ default:
+ return -1;
+ }
+ }
+
+ public String controlAEModeToString(int mode) {
+ switch (mode) {
+ case CaptureRequest.CONTROL_AE_MODE_ON:
+ return "off";
+ case CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH:
+ return "auto";
+ case CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH:
+ return "on";
+ case CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE:
+ return "redeye";
+ case CaptureRequest.CONTROL_AE_MODE_ON_EXTERNAL_FLASH:
+ return "external";
+ case CaptureRequest.CONTROL_AE_MODE_OFF:
+ default:
+ return "unknown";
+ }
+ }
+
+ public int[] getSupportedAfModes(String cameraId) {
+
+ CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
+ if (characteristics == null)
+ return new int[0];
+
+ return characteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
+ }
+
+ public String[] getSupportedFlashModes(String cameraId) {
+
+ CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
+ if (characteristics == null)
+ return new String[0];
+
+ int supportedFlashModes[] = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES);
+ ArrayList<String> supportedFlashModesList = new ArrayList<String>();
+ for (int index = 0; index < supportedFlashModes.length; index++) {
+ supportedFlashModesList.add(controlAEModeToString(supportedFlashModes[index]));
+ }
+
+ String[] ret = new String[ supportedFlashModesList.size() ];
+ return supportedFlashModesList.toArray(ret);
+ }
+
+ static public boolean isEmulator()
+ {
+ return ((Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
+ || Build.FINGERPRINT.startsWith("generic")
+ || Build.FINGERPRINT.startsWith("unknown")
+ || Build.HARDWARE.contains("goldfish")
+ || Build.HARDWARE.contains("ranchu")
+ || Build.MODEL.contains("google_sdk")
+ || Build.MODEL.contains("Emulator")
+ || Build.MODEL.contains("Android SDK built for x86")
+ || Build.MANUFACTURER.contains("Genymotion")
+ || Build.PRODUCT.contains("sdk")
+ || Build.PRODUCT.contains("vbox86p")
+ || Build.PRODUCT.contains("emulator")
+ || Build.PRODUCT.contains("simulator"));
+ }
+
+ public boolean isTorchModeSupported(String cameraId) {
+ boolean ret = false;
+ final CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
+ if (characteristics != null)
+ ret = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
+ return ret;
+ }
+}
diff --git a/src/gsttools/gsttools.pro b/src/gsttools/gsttools.pro
deleted file mode 100644
index 0127cbe92..000000000
--- a/src/gsttools/gsttools.pro
+++ /dev/null
@@ -1,104 +0,0 @@
-TARGET = QtMultimediaGstTools
-MODULE = multimediagsttools
-CONFIG += internal_module
-
-QT = core-private multimedia-private gui-private
-
-!static:DEFINES += QT_MAKEDLL
-DEFINES += GLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_26
-
-qtConfig(alsa): \
- QMAKE_USE += alsa
-
-QMAKE_USE += gstreamer
-
-qtConfig(resourcepolicy): \
- QMAKE_USE += libresourceqt5
-
-PRIVATE_HEADERS += \
- qgstreamerbushelper_p.h \
- qgstreamermessage_p.h \
- qgstutils_p.h \
- qgstvideobuffer_p.h \
- qgstreamerbufferprobe_p.h \
- qgstreamervideorendererinterface_p.h \
- qgstreameraudioinputselector_p.h \
- qgstreamervideorenderer_p.h \
- qgstreamervideoinputdevicecontrol_p.h \
- qgstcodecsinfo_p.h \
- qgstreamervideoprobecontrol_p.h \
- qgstreameraudioprobecontrol_p.h \
- qgstreamervideowindow_p.h \
- qgstreamervideooverlay_p.h \
- qgsttools_global_p.h \
- qgstreamerplayersession_p.h \
- qgstreamerplayercontrol_p.h
-
-SOURCES += \
- qgstreamerbushelper.cpp \
- qgstreamermessage.cpp \
- qgstutils.cpp \
- qgstvideobuffer.cpp \
- qgstreamerbufferprobe.cpp \
- qgstreamervideorendererinterface.cpp \
- qgstreameraudioinputselector.cpp \
- qgstreamervideorenderer.cpp \
- qgstreamervideoinputdevicecontrol.cpp \
- qgstcodecsinfo.cpp \
- qgstreamervideoprobecontrol.cpp \
- qgstreameraudioprobecontrol.cpp \
- qgstreamervideowindow.cpp \
- qgstreamervideooverlay.cpp \
- qgstreamerplayersession.cpp \
- qgstreamerplayercontrol.cpp
-
-qtHaveModule(widgets) {
- QT += multimediawidgets
-
- PRIVATE_HEADERS += \
- qgstreamervideowidget_p.h
-
- SOURCES += \
- qgstreamervideowidget.cpp
-}
-
-qtConfig(gstreamer_0_10) {
- PRIVATE_HEADERS += \
- qgstbufferpoolinterface_p.h \
- qvideosurfacegstsink_p.h \
- gstvideoconnector_p.h
-
- SOURCES += \
- qgstbufferpoolinterface.cpp \
- qvideosurfacegstsink.cpp \
- gstvideoconnector.c
-} else {
- PRIVATE_HEADERS += \
- qgstvideorendererplugin_p.h \
- qgstvideorenderersink_p.h
-
- SOURCES += \
- qgstvideorendererplugin.cpp \
- qgstvideorenderersink.cpp
-}
-
-qtConfig(gstreamer_gl): QMAKE_USE += gstreamer_gl
-
-qtConfig(gstreamer_app) {
- QMAKE_USE += gstreamer_app
- PRIVATE_HEADERS += qgstappsrc_p.h
- SOURCES += qgstappsrc.cpp
-}
-
-android {
- LIBS_PRIVATE += \
- -L$$(GSTREAMER_ROOT_ANDROID)/armv7/lib \
- -Wl,--whole-archive \
- -lgstapp-1.0 -lgstreamer-1.0 -lgstaudio-1.0 -lgsttag-1.0 -lgstvideo-1.0 -lgstbase-1.0 -lgstpbutils-1.0 \
- -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lffi -lintl -liconv -lorc-0.4 \
- -Wl,--no-whole-archive
-}
-
-HEADERS += $$PRIVATE_HEADERS
-
-load(qt_module)
diff --git a/src/gsttools/gstvideoconnector.c b/src/gsttools/gstvideoconnector.c
deleted file mode 100644
index b85f5bdbe..000000000
--- a/src/gsttools/gstvideoconnector.c
+++ /dev/null
@@ -1,471 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "gstvideoconnector_p.h"
-#include <unistd.h>
-
-/* signals */
-enum
-{
- SIGNAL_RESEND_NEW_SEGMENT,
- SIGNAL_CONNECTION_FAILED,
- LAST_SIGNAL
-};
-static guint gst_video_connector_signals[LAST_SIGNAL] = { 0 };
-
-
-GST_DEBUG_CATEGORY_STATIC (video_connector_debug);
-#define GST_CAT_DEFAULT video_connector_debug
-
-static GstStaticPadTemplate gst_video_connector_sink_factory =
-GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS_ANY);
-
-static GstStaticPadTemplate gst_video_connector_src_factory =
-GST_STATIC_PAD_TEMPLATE ("src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS_ANY);
-
-#define _do_init(bla) \
- GST_DEBUG_CATEGORY_INIT (video_connector_debug, \
- "video-connector", 0, "An identity like element for reconnecting video stream");
-
-GST_BOILERPLATE_FULL (GstVideoConnector, gst_video_connector, GstElement,
- GST_TYPE_ELEMENT, _do_init);
-
-static void gst_video_connector_dispose (GObject * object);
-static GstFlowReturn gst_video_connector_chain (GstPad * pad, GstBuffer * buf);
-static GstFlowReturn gst_video_connector_buffer_alloc (GstPad * pad,
- guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
-static GstStateChangeReturn gst_video_connector_change_state (GstElement *
- element, GstStateChange transition);
-static gboolean gst_video_connector_handle_sink_event (GstPad * pad,
- GstEvent * event);
-static gboolean gst_video_connector_new_buffer_probe(GstObject *pad, GstBuffer *buffer, guint * object);
-static void gst_video_connector_resend_new_segment(GstElement * element, gboolean emitFailedSignal);
-static gboolean gst_video_connector_setcaps (GstPad *pad, GstCaps *caps);
-static GstCaps *gst_video_connector_getcaps (GstPad * pad);
-static gboolean gst_video_connector_acceptcaps (GstPad * pad, GstCaps * caps);
-
-static void
-gst_video_connector_base_init (gpointer g_class)
-{
- GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
-
- gst_element_class_set_details_simple (element_class, "Video Connector",
- "Generic",
- "An identity like element used for reconnecting video stream",
- "Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>");
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&gst_video_connector_sink_factory));
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&gst_video_connector_src_factory));
-}
-
-static void
-gst_video_connector_class_init (GstVideoConnectorClass * klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
-
- parent_class = g_type_class_peek_parent (klass);
-
- gobject_class->dispose = gst_video_connector_dispose;
- gstelement_class->change_state = gst_video_connector_change_state;
- klass->resend_new_segment = gst_video_connector_resend_new_segment;
-
- gst_video_connector_signals[SIGNAL_RESEND_NEW_SEGMENT] =
- g_signal_new ("resend-new-segment", G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GstVideoConnectorClass, resend_new_segment), NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
-
- gst_video_connector_signals[SIGNAL_CONNECTION_FAILED] =
- g_signal_new ("connection-failed", G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
-}
-
-static void
-gst_video_connector_init (GstVideoConnector *element,
- GstVideoConnectorClass *g_class)
-{
- (void) g_class;
- element->sinkpad =
- gst_pad_new_from_static_template (&gst_video_connector_sink_factory,
- "sink");
- gst_pad_set_chain_function(element->sinkpad,
- GST_DEBUG_FUNCPTR (gst_video_connector_chain));
- gst_pad_set_event_function(element->sinkpad,
- GST_DEBUG_FUNCPTR (gst_video_connector_handle_sink_event));
- gst_pad_set_bufferalloc_function(element->sinkpad,
- GST_DEBUG_FUNCPTR (gst_video_connector_buffer_alloc));
- gst_pad_set_setcaps_function(element->sinkpad,
- GST_DEBUG_FUNCPTR (gst_video_connector_setcaps));
- gst_pad_set_getcaps_function(element->sinkpad,
- GST_DEBUG_FUNCPTR(gst_video_connector_getcaps));
- gst_pad_set_acceptcaps_function(element->sinkpad,
- GST_DEBUG_FUNCPTR(gst_video_connector_acceptcaps));
-
- gst_element_add_pad (GST_ELEMENT (element), element->sinkpad);
-
- element->srcpad =
- gst_pad_new_from_static_template (&gst_video_connector_src_factory,
- "src");
- gst_pad_add_buffer_probe(element->srcpad,
- G_CALLBACK(gst_video_connector_new_buffer_probe), element);
- gst_element_add_pad (GST_ELEMENT (element), element->srcpad);
-
- element->relinked = FALSE;
- element->failedSignalEmited = FALSE;
- gst_segment_init (&element->segment, GST_FORMAT_TIME);
- element->latest_buffer = NULL;
-}
-
-static void
-gst_video_connector_reset (GstVideoConnector * element)
-{
- element->relinked = FALSE;
- element->failedSignalEmited = FALSE;
- if (element->latest_buffer != NULL) {
- gst_buffer_unref (element->latest_buffer);
- element->latest_buffer = NULL;
- }
- gst_segment_init (&element->segment, GST_FORMAT_UNDEFINED);
-}
-
-static void
-gst_video_connector_dispose (GObject * object)
-{
- GstVideoConnector *element = GST_VIDEO_CONNECTOR (object);
-
- gst_video_connector_reset (element);
-
- G_OBJECT_CLASS (parent_class)->dispose (object);
-}
-
-// "When this function returns anything else than GST_FLOW_OK,
-// the buffer allocation failed and buf does not contain valid data."
-static GstFlowReturn
-gst_video_connector_buffer_alloc (GstPad * pad, guint64 offset, guint size,
- GstCaps * caps, GstBuffer ** buf)
-{
- GstVideoConnector *element;
- GstFlowReturn res = GST_FLOW_OK;
- element = GST_VIDEO_CONNECTOR (GST_PAD_PARENT (pad));
-
- if (!buf)
- return GST_FLOW_ERROR;
- *buf = NULL;
-
- gboolean isFailed = FALSE;
- while (1) {
- GST_OBJECT_LOCK (element);
- gst_object_ref(element->srcpad);
- GST_OBJECT_UNLOCK (element);
-
- // Check if downstream element is in NULL state
- // and wait for up to 1 second for it to switch.
- GstPad *peerPad = gst_pad_get_peer(element->srcpad);
- if (peerPad) {
- GstElement *parent = gst_pad_get_parent_element(peerPad);
- gst_object_unref (peerPad);
- if (parent) {
- GstState state;
- GstState pending;
- int totalTimeout = 0;
- // This seems to sleep for about 10ms usually.
- while (totalTimeout < 1000000) {
- gst_element_get_state(parent, &state, &pending, 0);
- if (state != GST_STATE_NULL)
- break;
- usleep(5000);
- totalTimeout += 5000;
- }
-
- gst_object_unref (parent);
- if (state == GST_STATE_NULL) {
- GST_DEBUG_OBJECT (element, "Downstream element is in NULL state");
- // Downstream filter seems to be in the wrong state
- return GST_FLOW_UNEXPECTED;
- }
- }
- }
-
- res = gst_pad_alloc_buffer(element->srcpad, offset, size, caps, buf);
- gst_object_unref (element->srcpad);
-
- GST_DEBUG_OBJECT (element, "buffer alloc finished: %s", gst_flow_get_name (res));
-
- if (res == GST_FLOW_WRONG_STATE) {
- // Just in case downstream filter is still somehow in the wrong state.
- // Pipeline stalls if we report GST_FLOW_WRONG_STATE.
- return GST_FLOW_UNEXPECTED;
- }
-
- if (res >= GST_FLOW_OK || isFailed == TRUE)
- break;
-
- //if gst_pad_alloc_buffer failed, emit "connection-failed" signal
- //so colorspace transformation element can be inserted
- GST_INFO_OBJECT(element, "gst_video_connector_buffer_alloc failed, emit connection-failed signal");
- g_signal_emit(G_OBJECT(element), gst_video_connector_signals[SIGNAL_CONNECTION_FAILED], 0);
- isFailed = TRUE;
- }
-
- return res;
-}
-
-static gboolean
-gst_video_connector_setcaps (GstPad *pad, GstCaps *caps)
-{
- GstVideoConnector *element;
- element = GST_VIDEO_CONNECTOR (GST_PAD_PARENT (pad));
-
- /* forward-negotiate */
- gboolean res = gst_pad_set_caps(element->srcpad, caps);
-
- gchar * debugmsg = NULL;
- GST_DEBUG_OBJECT(element, "gst_video_connector_setcaps %s %i", debugmsg = gst_caps_to_string(caps), res);
- if (debugmsg)
- g_free(debugmsg);
-
- if (!res) {
- //if set_caps failed, emit "connection-failed" signal
- //so colorspace transformation element can be inserted
- GST_INFO_OBJECT(element, "gst_video_connector_setcaps failed, emit connection-failed signal");
- g_signal_emit(G_OBJECT(element), gst_video_connector_signals[SIGNAL_CONNECTION_FAILED], 0);
-
- return gst_pad_set_caps(element->srcpad, caps);
- }
-
- return TRUE;
-}
-
-static GstCaps *gst_video_connector_getcaps (GstPad * pad)
-{
- GstVideoConnector *element;
- element = GST_VIDEO_CONNECTOR (GST_PAD_PARENT (pad));
-
-#if (GST_VERSION_MICRO > 25)
- GstCaps *caps = gst_pad_peer_get_caps_reffed(element->srcpad);
-#else
- GstCaps *caps = gst_pad_peer_get_caps(element->srcpad);
-#endif
-
- if (!caps)
- caps = gst_caps_new_any();
-
- return caps;
-}
-
-static gboolean gst_video_connector_acceptcaps (GstPad * pad, GstCaps * caps)
-{
- GstVideoConnector *element;
- element = GST_VIDEO_CONNECTOR (GST_PAD_PARENT (pad));
-
- return gst_pad_peer_accept_caps(element->srcpad, caps);
-}
-
-static void
-gst_video_connector_resend_new_segment(GstElement * element, gboolean emitFailedSignal)
-{
- GST_INFO_OBJECT(element, "New segment requested, failed signal enabled: %i", emitFailedSignal);
- GstVideoConnector *connector = GST_VIDEO_CONNECTOR(element);
- connector->relinked = TRUE;
- if (emitFailedSignal)
- connector->failedSignalEmited = FALSE;
-}
-
-
-static gboolean gst_video_connector_new_buffer_probe(GstObject *pad, GstBuffer *buffer, guint * object)
-{
- (void) pad;
- (void) buffer;
-
- GstVideoConnector *element = GST_VIDEO_CONNECTOR (object);
-
- /*
- If relinking is requested, the current buffer should be rejected and
- the new segment + previous buffer should be pushed first
- */
-
- if (element->relinked)
- GST_LOG_OBJECT(element, "rejected buffer because of new segment request");
-
- return !element->relinked;
-}
-
-
-static GstFlowReturn
-gst_video_connector_chain (GstPad * pad, GstBuffer * buf)
-{
- GstFlowReturn res;
- GstVideoConnector *element;
-
- element = GST_VIDEO_CONNECTOR (gst_pad_get_parent (pad));
-
- do {
- /*
- Resend the segment message and last buffer to preroll the new sink.
- Sinks can be changed multiple times while paused,
- while loop allows to send the segment message and preroll
- all of them with the same buffer.
- */
- while (element->relinked) {
- element->relinked = FALSE;
-
- gint64 pos = element->segment.last_stop;
-
- if (element->latest_buffer && GST_BUFFER_TIMESTAMP_IS_VALID(element->latest_buffer)) {
- pos = GST_BUFFER_TIMESTAMP (element->latest_buffer);
- }
-
- //push a new segment and last buffer
- GstEvent *ev = gst_event_new_new_segment (TRUE,
- element->segment.rate,
- element->segment.format,
- pos, //start
- element->segment.stop,
- pos);
-
- GST_DEBUG_OBJECT (element, "Pushing new segment event");
- if (!gst_pad_push_event (element->srcpad, ev)) {
- GST_WARNING_OBJECT (element,
- "Newsegment handling failed in %" GST_PTR_FORMAT,
- element->srcpad);
- }
-
- if (element->latest_buffer) {
- GST_DEBUG_OBJECT (element, "Pushing latest buffer...");
- gst_buffer_ref(element->latest_buffer);
- gst_pad_push(element->srcpad, element->latest_buffer);
- }
- }
-
- gst_buffer_ref(buf);
-
- //it's possible video sink is changed during gst_pad_push blocked by
- //pad lock, in this case ( element->relinked == TRUE )
- //the buffer should be rejected by the buffer probe and
- //the new segment + prev buffer should be sent before
-
- GST_LOG_OBJECT (element, "Pushing buffer...");
- res = gst_pad_push (element->srcpad, buf);
- GST_LOG_OBJECT (element, "Pushed buffer: %s", gst_flow_get_name (res));
-
- //if gst_pad_push failed give the service another chance,
- //it may still work with the colorspace element added
- if (!element->failedSignalEmited && res == GST_FLOW_NOT_NEGOTIATED) {
- element->failedSignalEmited = TRUE;
- GST_INFO_OBJECT(element, "gst_pad_push failed, emit connection-failed signal");
- g_signal_emit(G_OBJECT(element), gst_video_connector_signals[SIGNAL_CONNECTION_FAILED], 0);
- }
-
- } while (element->relinked);
-
-
- if (element->latest_buffer) {
- gst_buffer_unref (element->latest_buffer);
- element->latest_buffer = NULL;
- }
-
- element->latest_buffer = gst_buffer_ref(buf);
-
- gst_buffer_unref(buf);
- gst_object_unref (element);
-
- return res;
-}
-
-static GstStateChangeReturn
-gst_video_connector_change_state (GstElement * element,
- GstStateChange transition)
-{
- GstVideoConnector *connector;
- GstStateChangeReturn result;
-
- connector = GST_VIDEO_CONNECTOR(element);
- result = GST_ELEMENT_CLASS (parent_class)->change_state(element, transition);
-
- switch (transition) {
- case GST_STATE_CHANGE_PAUSED_TO_READY:
- gst_video_connector_reset (connector);
- break;
- case GST_STATE_CHANGE_READY_TO_PAUSED:
- connector->relinked = FALSE;
- break;
- default:
- break;
- }
-
- return result;
-}
-
-static gboolean
-gst_video_connector_handle_sink_event (GstPad * pad, GstEvent * event)
-{
- if (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT) {
- GstVideoConnector *element = GST_VIDEO_CONNECTOR (gst_pad_get_parent (pad));
-
- gboolean update;
- GstFormat format;
- gdouble rate, arate;
- gint64 start, stop, time;
-
- gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
- &start, &stop, &time);
-
- GST_LOG_OBJECT (element,
- "NEWSEGMENT update %d, rate %lf, applied rate %lf, "
- "format %d, " "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
- G_GINT64_FORMAT, update, rate, arate, format, start, stop, time);
-
- gst_segment_set_newsegment_full (&element->segment, update,
- rate, arate, format, start, stop, time);
-
- gst_object_unref (element);
- }
-
- return gst_pad_event_default (pad, event);
-}
diff --git a/src/gsttools/gstvideoconnector_p.h b/src/gsttools/gstvideoconnector_p.h
deleted file mode 100644
index a38ca2e65..000000000
--- a/src/gsttools/gstvideoconnector_p.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTVIDEOCONNECTOR_H
-#define QGSTVIDEOCONNECTOR_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-
-#include <gst/gst.h>
-
-G_BEGIN_DECLS
-
-#define GST_TYPE_VIDEO_CONNECTOR \
- (gst_video_connector_get_type())
-#define GST_VIDEO_CONNECTOR(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VIDEO_CONNECTOR, GstVideoConnector))
-#define GST_VIDEO_CONNECTOR_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VIDEO_CONNECTOR, GstVideoConnectorClass))
-#define GST_IS_VIDEO_CONNECTOR(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VIDEO_CONNECTOR))
-#define GST_IS_VIDEO_CONNECTOR_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VIDEO_CONNECTOR))
-
-typedef struct _GstVideoConnector GstVideoConnector;
-typedef struct _GstVideoConnectorClass GstVideoConnectorClass;
-
-struct Q_GSTTOOLS_EXPORT _GstVideoConnector {
- GstElement element;
-
- GstPad *srcpad;
- GstPad *sinkpad;
-
- gboolean relinked;
- gboolean failedSignalEmited;
- GstSegment segment;
- GstBuffer *latest_buffer;
-};
-
-struct Q_GSTTOOLS_EXPORT _GstVideoConnectorClass {
- GstElementClass parent_class;
-
- /* action signal to resend new segment */
- void (*resend_new_segment) (GstElement * element, gboolean emitFailedSignal);
-};
-
-GType Q_GSTTOOLS_EXPORT gst_video_connector_get_type (void);
-
-G_END_DECLS
-
-#endif
-
diff --git a/src/gsttools/qgstappsrc.cpp b/src/gsttools/qgstappsrc.cpp
deleted file mode 100644
index f6ecd48be..000000000
--- a/src/gsttools/qgstappsrc.cpp
+++ /dev/null
@@ -1,253 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QDebug>
-
-#include "qgstappsrc_p.h"
-
-QGstAppSrc::QGstAppSrc(QObject *parent)
- : QObject(parent)
-{
- m_callbacks.need_data = &QGstAppSrc::on_need_data;
- m_callbacks.enough_data = &QGstAppSrc::on_enough_data;
- m_callbacks.seek_data = &QGstAppSrc::on_seek_data;
-}
-
-QGstAppSrc::~QGstAppSrc()
-{
- if (m_appSrc)
- gst_object_unref(G_OBJECT(m_appSrc));
-}
-
-bool QGstAppSrc::setup(GstElement* appsrc)
-{
- if (m_appSrc) {
- gst_object_unref(G_OBJECT(m_appSrc));
- m_appSrc = 0;
- }
-
- if (!appsrc || !m_stream)
- return false;
-
- m_appSrc = GST_APP_SRC(appsrc);
- gst_object_ref(G_OBJECT(m_appSrc));
- gst_app_src_set_callbacks(m_appSrc, (GstAppSrcCallbacks*)&m_callbacks, this, (GDestroyNotify)&QGstAppSrc::destroy_notify);
-
- g_object_get(G_OBJECT(m_appSrc), "max-bytes", &m_maxBytes, nullptr);
-
- if (m_sequential)
- m_streamType = GST_APP_STREAM_TYPE_STREAM;
- else
- m_streamType = GST_APP_STREAM_TYPE_RANDOM_ACCESS;
- gst_app_src_set_stream_type(m_appSrc, m_streamType);
- gst_app_src_set_size(m_appSrc, (m_sequential) ? -1 : m_stream->size());
-
- return true;
-}
-
-void QGstAppSrc::setStream(QIODevice *stream)
-{
- if (m_stream) {
- disconnect(m_stream, SIGNAL(readyRead()), this, SLOT(onDataReady()));
- disconnect(m_stream, SIGNAL(destroyed()), this, SLOT(streamDestroyed()));
- m_stream = 0;
- }
-
- if (m_appSrc) {
- gst_object_unref(G_OBJECT(m_appSrc));
- m_appSrc = 0;
- }
-
- m_dataRequestSize = ~0;
- m_dataRequested = false;
- m_enoughData = false;
- m_forceData = false;
- m_sequential = false;
- m_maxBytes = 0;
-
- if (stream) {
- m_stream = stream;
- connect(m_stream, SIGNAL(destroyed()), SLOT(streamDestroyed()));
- connect(m_stream, SIGNAL(readyRead()), this, SLOT(onDataReady()));
- m_sequential = m_stream->isSequential();
- }
-}
-
-QIODevice *QGstAppSrc::stream() const
-{
- return m_stream;
-}
-
-GstAppSrc *QGstAppSrc::element()
-{
- return m_appSrc;
-}
-
-void QGstAppSrc::onDataReady()
-{
- if (!m_enoughData) {
- m_dataRequested = true;
- pushDataToAppSrc();
- }
-}
-
-void QGstAppSrc::streamDestroyed()
-{
- if (sender() == m_stream) {
- m_stream = 0;
- sendEOS();
- }
-}
-
-void QGstAppSrc::pushDataToAppSrc()
-{
- if (!isStreamValid() || !m_appSrc)
- return;
-
- if (m_dataRequested && !m_enoughData) {
- qint64 size;
- if (m_dataRequestSize == ~0u)
- size = qMin(m_stream->bytesAvailable(), queueSize());
- else
- size = qMin(m_stream->bytesAvailable(), (qint64)m_dataRequestSize);
-
- if (size) {
- GstBuffer* buffer = gst_buffer_new_and_alloc(size);
-
-#if GST_CHECK_VERSION(1,0,0)
- GstMapInfo mapInfo;
- gst_buffer_map(buffer, &mapInfo, GST_MAP_WRITE);
- void* bufferData = mapInfo.data;
-#else
- void* bufferData = GST_BUFFER_DATA(buffer);
-#endif
-
- buffer->offset = m_stream->pos();
- qint64 bytesRead = m_stream->read((char*)bufferData, size);
- buffer->offset_end = buffer->offset + bytesRead - 1;
-
-#if GST_CHECK_VERSION(1,0,0)
- gst_buffer_unmap(buffer, &mapInfo);
-#endif
-
- if (bytesRead > 0) {
- m_dataRequested = false;
- m_enoughData = false;
- GstFlowReturn ret = gst_app_src_push_buffer (GST_APP_SRC (element()), buffer);
- if (ret == GST_FLOW_ERROR) {
- qWarning()<<"appsrc: push buffer error";
-#if GST_CHECK_VERSION(1,0,0)
- } else if (ret == GST_FLOW_FLUSHING) {
- qWarning()<<"appsrc: push buffer wrong state";
- }
-#else
- } else if (ret == GST_FLOW_WRONG_STATE) {
- qWarning()<<"appsrc: push buffer wrong state";
- }
-#endif
-#if GST_VERSION_MAJOR < 1
- else if (ret == GST_FLOW_RESEND) {
- qWarning()<<"appsrc: push buffer resend";
- }
-#endif
- }
- } else if (!m_sequential) {
- sendEOS();
- }
- } else if (m_stream->atEnd() && !m_sequential) {
- sendEOS();
- }
-}
-
-bool QGstAppSrc::doSeek(qint64 value)
-{
- if (isStreamValid())
- return stream()->seek(value);
- return false;
-}
-
-
-gboolean QGstAppSrc::on_seek_data(GstAppSrc *element, guint64 arg0, gpointer userdata)
-{
- Q_UNUSED(element);
- QGstAppSrc *self = reinterpret_cast<QGstAppSrc*>(userdata);
- if (self && self->isStreamValid()) {
- if (!self->stream()->isSequential())
- QMetaObject::invokeMethod(self, "doSeek", Qt::AutoConnection, Q_ARG(qint64, arg0));
- }
- else
- return false;
-
- return true;
-}
-
-void QGstAppSrc::on_enough_data(GstAppSrc *element, gpointer userdata)
-{
- Q_UNUSED(element);
- QGstAppSrc *self = reinterpret_cast<QGstAppSrc*>(userdata);
- if (self)
- self->enoughData() = true;
-}
-
-void QGstAppSrc::on_need_data(GstAppSrc *element, guint arg0, gpointer userdata)
-{
- Q_UNUSED(element);
- QGstAppSrc *self = reinterpret_cast<QGstAppSrc*>(userdata);
- if (self) {
- self->dataRequested() = true;
- self->enoughData() = false;
- self->dataRequestSize()= arg0;
- QMetaObject::invokeMethod(self, "pushDataToAppSrc", Qt::AutoConnection);
- }
-}
-
-void QGstAppSrc::destroy_notify(gpointer data)
-{
- Q_UNUSED(data);
-}
-
-void QGstAppSrc::sendEOS()
-{
- if (!m_appSrc)
- return;
-
- gst_app_src_end_of_stream(GST_APP_SRC(m_appSrc));
- if (isStreamValid() && !stream()->isSequential())
- stream()->reset();
-}
diff --git a/src/gsttools/qgstappsrc_p.h b/src/gsttools/qgstappsrc_p.h
deleted file mode 100644
index c1c8cdabe..000000000
--- a/src/gsttools/qgstappsrc_p.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTAPPSRC_H
-#define QGSTAPPSRC_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <QtCore/qobject.h>
-#include <QtCore/qiodevice.h>
-
-#include <gst/gst.h>
-#include <gst/app/gstappsrc.h>
-
-#if GST_VERSION_MAJOR < 1
-#include <gst/app/gstappbuffer.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class Q_GSTTOOLS_EXPORT QGstAppSrc : public QObject
-{
- Q_OBJECT
-public:
- QGstAppSrc(QObject *parent = 0);
- ~QGstAppSrc();
-
- bool setup(GstElement *);
-
- void setStream(QIODevice *);
- QIODevice *stream() const;
-
- GstAppSrc *element();
-
- qint64 queueSize() const { return m_maxBytes; }
-
- bool& enoughData() { return m_enoughData; }
- bool& dataRequested() { return m_dataRequested; }
- unsigned int& dataRequestSize() { return m_dataRequestSize; }
-
- bool isStreamValid() const
- {
- return m_stream != 0 &&
- m_stream->isOpen();
- }
-
-private slots:
- void pushDataToAppSrc();
- bool doSeek(qint64);
- void onDataReady();
-
- void streamDestroyed();
-private:
- static gboolean on_seek_data(GstAppSrc *element, guint64 arg0, gpointer userdata);
- static void on_enough_data(GstAppSrc *element, gpointer userdata);
- static void on_need_data(GstAppSrc *element, uint arg0, gpointer userdata);
- static void destroy_notify(gpointer data);
-
- void sendEOS();
-
- QIODevice *m_stream = nullptr;
- GstAppSrc *m_appSrc = nullptr;
- bool m_sequential = false;
- GstAppStreamType m_streamType = GST_APP_STREAM_TYPE_RANDOM_ACCESS;
- GstAppSrcCallbacks m_callbacks;
- qint64 m_maxBytes = 0;
- unsigned int m_dataRequestSize = ~0;
- bool m_dataRequested = false;
- bool m_enoughData = false;
- bool m_forceData = false;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gsttools/qgstbufferpoolinterface.cpp b/src/gsttools/qgstbufferpoolinterface.cpp
deleted file mode 100644
index be8a2e116..000000000
--- a/src/gsttools/qgstbufferpoolinterface.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstbufferpoolinterface_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QGstBufferPoolPlugin::QGstBufferPoolPlugin(QObject *parent) :
- QObject(parent)
-{
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qgstbufferpoolinterface_p.cpp"
diff --git a/src/gsttools/qgstbufferpoolinterface_p.h b/src/gsttools/qgstbufferpoolinterface_p.h
deleted file mode 100644
index f5cbc35aa..000000000
--- a/src/gsttools/qgstbufferpoolinterface_p.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTBUFFERPOOLINTERFACE_P_H
-#define QGSTBUFFERPOOLINTERFACE_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <qabstractvideobuffer.h>
-#include <qvideosurfaceformat.h>
-#include <QtCore/qobject.h>
-#include <QtCore/qplugin.h>
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-const QLatin1String QGstBufferPoolPluginKey("bufferpool");
-
-/*!
- Abstract interface for video buffers allocation.
-*/
-class Q_GSTTOOLS_EXPORT QGstBufferPoolInterface
-{
-public:
- virtual ~QGstBufferPoolInterface() {}
-
- virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const = 0;
- virtual GstBuffer *takeBuffer(const QVideoSurfaceFormat &format, GstCaps *caps) = 0;
- virtual void clear() = 0;
-
- virtual QAbstractVideoBuffer::HandleType handleType() const = 0;
-
- /*!
- Build an QAbstractVideoBuffer instance from GstBuffer.
- Returns nullptr if GstBuffer is not compatible with this buffer pool.
-
- This method is called from gstreamer video sink thread.
- */
- virtual QAbstractVideoBuffer *prepareVideoBuffer(GstBuffer *buffer, int bytesPerLine) = 0;
-};
-
-#define QGstBufferPoolInterface_iid "org.qt-project.qt.gstbufferpool/5.0"
-Q_DECLARE_INTERFACE(QGstBufferPoolInterface, QGstBufferPoolInterface_iid)
-
-class QGstBufferPoolPlugin : public QObject, public QGstBufferPoolInterface
-{
- Q_OBJECT
- Q_INTERFACES(QGstBufferPoolInterface)
-public:
- explicit QGstBufferPoolPlugin(QObject *parent = 0);
- virtual ~QGstBufferPoolPlugin() {}
-
- bool isFormatSupported(const QVideoSurfaceFormat &format) const override = 0;
- GstBuffer *takeBuffer(const QVideoSurfaceFormat &format, GstCaps *caps) override = 0;
- void clear() override = 0;
-
- QAbstractVideoBuffer::HandleType handleType() const override = 0;
-
- /*!
- Build an QAbstractVideoBuffer instance from compatible GstBuffer.
- Returns nullptr if GstBuffer is not compatible with this buffer pool.
-
- This method is called from gstreamer video sink thread.
- */
- QAbstractVideoBuffer *prepareVideoBuffer(GstBuffer *buffer, int bytesPerLine) override = 0;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gsttools/qgstcodecsinfo.cpp b/src/gsttools/qgstcodecsinfo.cpp
deleted file mode 100644
index 2522ee19c..000000000
--- a/src/gsttools/qgstcodecsinfo.cpp
+++ /dev/null
@@ -1,300 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstcodecsinfo_p.h"
-#include "qgstutils_p.h"
-#include <QtCore/qset.h>
-
-#include <gst/pbutils/pbutils.h>
-
-static QSet<QString> streamTypes(GstElementFactory *factory, GstPadDirection direction)
-{
- QSet<QString> types;
- const GList *pads = gst_element_factory_get_static_pad_templates(factory);
- for (const GList *pad = pads; pad; pad = g_list_next(pad)) {
- GstStaticPadTemplate *templ = reinterpret_cast<GstStaticPadTemplate *>(pad->data);
- if (templ->direction == direction) {
- GstCaps *caps = gst_static_caps_get(&templ->static_caps);
- for (uint i = 0; i < gst_caps_get_size(caps); ++i) {
- GstStructure *structure = gst_caps_get_structure(caps, i);
- types.insert(QString::fromUtf8(gst_structure_get_name(structure)));
- }
- gst_caps_unref(caps);
- }
- }
-
- return types;
-}
-
-QGstCodecsInfo::QGstCodecsInfo(QGstCodecsInfo::ElementType elementType)
-{
- updateCodecs(elementType);
- for (auto &codec : supportedCodecs()) {
- GstElementFactory *factory = gst_element_factory_find(codecElement(codec).constData());
- if (factory) {
- GstPadDirection direction = elementType == Muxer ? GST_PAD_SINK : GST_PAD_SRC;
- m_streamTypes.insert(codec, streamTypes(factory, direction));
- gst_object_unref(GST_OBJECT(factory));
- }
- }
-}
-
-QStringList QGstCodecsInfo::supportedCodecs() const
-{
- return m_codecs;
-}
-
-QString QGstCodecsInfo::codecDescription(const QString &codec) const
-{
- return m_codecInfo.value(codec).description;
-}
-
-QByteArray QGstCodecsInfo::codecElement(const QString &codec) const
-
-{
- return m_codecInfo.value(codec).elementName;
-}
-
-QStringList QGstCodecsInfo::codecOptions(const QString &codec) const
-{
- QStringList options;
-
- QByteArray elementName = m_codecInfo.value(codec).elementName;
- if (elementName.isEmpty())
- return options;
-
- GstElement *element = gst_element_factory_make(elementName, nullptr);
- if (element) {
- guint numProperties;
- GParamSpec **properties = g_object_class_list_properties(G_OBJECT_GET_CLASS(element),
- &numProperties);
- for (guint j = 0; j < numProperties; ++j) {
- GParamSpec *property = properties[j];
- // ignore some properties
- if (strcmp(property->name, "name") == 0 || strcmp(property->name, "parent") == 0)
- continue;
-
- options.append(QLatin1String(property->name));
- }
- g_free(properties);
- gst_object_unref(element);
- }
-
- return options;
-}
-
-void QGstCodecsInfo::updateCodecs(ElementType elementType)
-{
- m_codecs.clear();
- m_codecInfo.clear();
-
- GList *elements = elementFactories(elementType);
-
- QSet<QByteArray> fakeEncoderMimeTypes;
- fakeEncoderMimeTypes << "unknown/unknown"
- << "audio/x-raw-int" << "audio/x-raw-float"
- << "video/x-raw-yuv" << "video/x-raw-rgb";
-
- QSet<QByteArray> fieldsToAdd;
- fieldsToAdd << "mpegversion" << "layer" << "layout" << "raversion"
- << "wmaversion" << "wmvversion" << "variant" << "systemstream";
-
- GList *element = elements;
- while (element) {
- GstElementFactory *factory = (GstElementFactory *)element->data;
- element = element->next;
-
- const GList *padTemplates = gst_element_factory_get_static_pad_templates(factory);
- while (padTemplates) {
- GstStaticPadTemplate *padTemplate = (GstStaticPadTemplate *)padTemplates->data;
- padTemplates = padTemplates->next;
-
- if (padTemplate->direction == GST_PAD_SRC) {
- GstCaps *caps = gst_static_caps_get(&padTemplate->static_caps);
- for (uint i=0; i<gst_caps_get_size(caps); i++) {
- const GstStructure *structure = gst_caps_get_structure(caps, i);
-
- //skip "fake" encoders
- if (fakeEncoderMimeTypes.contains(gst_structure_get_name(structure)))
- continue;
-
- GstStructure *newStructure = qt_gst_structure_new_empty(gst_structure_get_name(structure));
-
- //add structure fields to distinguish between formats with similar mime types,
- //like audio/mpeg
- for (int j=0; j<gst_structure_n_fields(structure); j++) {
- const gchar* fieldName = gst_structure_nth_field_name(structure, j);
- if (fieldsToAdd.contains(fieldName)) {
- const GValue *value = gst_structure_get_value(structure, fieldName);
- GType valueType = G_VALUE_TYPE(value);
-
- //don't add values of range type,
- //gst_pb_utils_get_codec_description complains about not fixed caps
-
- if (valueType != GST_TYPE_INT_RANGE && valueType != GST_TYPE_DOUBLE_RANGE &&
- valueType != GST_TYPE_FRACTION_RANGE && valueType != GST_TYPE_LIST &&
- valueType != GST_TYPE_ARRAY)
- gst_structure_set_value(newStructure, fieldName, value);
- }
- }
-
- GstCaps *newCaps = gst_caps_new_full(newStructure, nullptr);
-
- gchar *capsString = gst_caps_to_string(newCaps);
- QString codec = QLatin1String(capsString);
- if (capsString)
- g_free(capsString);
- GstRank rank = GstRank(gst_plugin_feature_get_rank(GST_PLUGIN_FEATURE(factory)));
-
- // If two elements provide the same codec, use the highest ranked one
- QMap<QString, CodecInfo>::const_iterator it = m_codecInfo.constFind(codec);
- if (it == m_codecInfo.constEnd() || it->rank < rank) {
- if (it == m_codecInfo.constEnd())
- m_codecs.append(codec);
-
- CodecInfo info;
- info.elementName = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory));
-
- gchar *description = gst_pb_utils_get_codec_description(newCaps);
- info.description = QString::fromUtf8(description);
- if (description)
- g_free(description);
-
- info.rank = rank;
-
- m_codecInfo.insert(codec, info);
- }
-
- gst_caps_unref(newCaps);
- }
- gst_caps_unref(caps);
- }
- }
- }
-
- gst_plugin_feature_list_free(elements);
-}
-
-#if !GST_CHECK_VERSION(0, 10, 31)
-static gboolean element_filter(GstPluginFeature *feature, gpointer user_data)
-{
- if (Q_UNLIKELY(!GST_IS_ELEMENT_FACTORY(feature)))
- return FALSE;
-
- const QGstCodecsInfo::ElementType type = *reinterpret_cast<QGstCodecsInfo::ElementType *>(user_data);
-
- const gchar *klass = gst_element_factory_get_klass(GST_ELEMENT_FACTORY(feature));
- if (type == QGstCodecsInfo::AudioEncoder && !(strstr(klass, "Encoder") && strstr(klass, "Audio")))
- return FALSE;
- if (type == QGstCodecsInfo::VideoEncoder && !(strstr(klass, "Encoder") && strstr(klass, "Video")))
- return FALSE;
- if (type == QGstCodecsInfo::Muxer && !strstr(klass, "Muxer"))
- return FALSE;
-
- guint rank = gst_plugin_feature_get_rank(feature);
- if (rank < GST_RANK_MARGINAL)
- return FALSE;
-
- return TRUE;
-}
-
-static gint compare_plugin_func(const void *item1, const void *item2)
-{
- GstPluginFeature *f1 = reinterpret_cast<GstPluginFeature *>(const_cast<void *>(item1));
- GstPluginFeature *f2 = reinterpret_cast<GstPluginFeature *>(const_cast<void *>(item2));
-
- gint diff = gst_plugin_feature_get_rank(f2) - gst_plugin_feature_get_rank(f1);
- if (diff != 0)
- return diff;
-
- return strcmp(gst_plugin_feature_get_name(f1), gst_plugin_feature_get_name (f2));
-}
-#endif
-
-GList *QGstCodecsInfo::elementFactories(ElementType elementType) const
-{
-#if GST_CHECK_VERSION(0,10,31)
- GstElementFactoryListType gstElementType = 0;
- switch (elementType) {
- case AudioEncoder:
- gstElementType = GST_ELEMENT_FACTORY_TYPE_AUDIO_ENCODER;
- break;
- case VideoEncoder:
- gstElementType = GST_ELEMENT_FACTORY_TYPE_VIDEO_ENCODER;
- break;
- case Muxer:
- gstElementType = GST_ELEMENT_FACTORY_TYPE_MUXER;
- break;
- }
-
- GList *list = gst_element_factory_list_get_elements(gstElementType, GST_RANK_MARGINAL);
- if (elementType == AudioEncoder) {
- // Manually add "audioconvert" to the list
- // to allow linking with various containers.
- auto factory = gst_element_factory_find("audioconvert");
- if (factory)
- list = g_list_prepend(list, factory);
- }
-
- return list;
-#else
- GList *result = gst_registry_feature_filter(gst_registry_get_default(),
- element_filter,
- FALSE, &elementType);
- result = g_list_sort(result, compare_plugin_func);
- return result;
-#endif
-}
-
-QSet<QString> QGstCodecsInfo::supportedStreamTypes(const QString &codec) const
-{
- return m_streamTypes.value(codec);
-}
-
-QStringList QGstCodecsInfo::supportedCodecs(const QSet<QString> &types) const
-{
- QStringList result;
- for (auto &candidate : supportedCodecs()) {
- auto candidateTypes = supportedStreamTypes(candidate);
- if (candidateTypes.intersects(types))
- result << candidate;
- }
-
- return result;
-}
diff --git a/src/gsttools/qgstcodecsinfo_p.h b/src/gsttools/qgstcodecsinfo_p.h
deleted file mode 100644
index d7aadef21..000000000
--- a/src/gsttools/qgstcodecsinfo_p.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTCODECSINFO_H
-#define QGSTCODECSINFO_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <QtCore/qmap.h>
-#include <QtCore/qstringlist.h>
-#include <QSet>
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q_GSTTOOLS_EXPORT QGstCodecsInfo
-{
-public:
- enum ElementType { AudioEncoder, VideoEncoder, Muxer };
-
- struct CodecInfo {
- QString description;
- QByteArray elementName;
- GstRank rank;
- };
-
- QGstCodecsInfo(ElementType elementType);
-
- QStringList supportedCodecs() const;
- QString codecDescription(const QString &codec) const;
- QByteArray codecElement(const QString &codec) const;
- QStringList codecOptions(const QString &codec) const;
- QSet<QString> supportedStreamTypes(const QString &codec) const;
- QStringList supportedCodecs(const QSet<QString> &types) const;
-
-private:
- void updateCodecs(ElementType elementType);
- GList *elementFactories(ElementType elementType) const;
-
- QStringList m_codecs;
- QMap<QString, CodecInfo> m_codecInfo;
- QMap<QString, QSet<QString>> m_streamTypes;
-};
-
-Q_DECLARE_TYPEINFO(QGstCodecsInfo::CodecInfo, Q_MOVABLE_TYPE);
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gsttools/qgstreameraudioinputselector.cpp b/src/gsttools/qgstreameraudioinputselector.cpp
deleted file mode 100644
index 3bf5538c2..000000000
--- a/src/gsttools/qgstreameraudioinputselector.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "qgstreameraudioinputselector_p.h"
-
-#include <QtCore/QDir>
-#include <QtCore/QDebug>
-
-#include <gst/gst.h>
-
-#if QT_CONFIG(alsa)
-#include <alsa/asoundlib.h>
-#endif
-
-QGstreamerAudioInputSelector::QGstreamerAudioInputSelector(QObject *parent)
- :QAudioInputSelectorControl(parent)
-{
- update();
-}
-
-QGstreamerAudioInputSelector::~QGstreamerAudioInputSelector()
-{
-}
-
-QList<QString> QGstreamerAudioInputSelector::availableInputs() const
-{
- return m_names;
-}
-
-QString QGstreamerAudioInputSelector::inputDescription(const QString& name) const
-{
- QString desc;
-
- for (int i = 0; i < m_names.size(); i++) {
- if (m_names.at(i).compare(name) == 0) {
- desc = m_descriptions.at(i);
- break;
- }
- }
- return desc;
-}
-
-QString QGstreamerAudioInputSelector::defaultInput() const
-{
- if (m_names.size() > 0)
- return m_names.at(0);
-
- return QString();
-}
-
-QString QGstreamerAudioInputSelector::activeInput() const
-{
- return m_audioInput;
-}
-
-void QGstreamerAudioInputSelector::setActiveInput(const QString& name)
-{
- if (m_audioInput.compare(name) != 0) {
- m_audioInput = name;
- emit activeInputChanged(name);
- }
-}
-
-void QGstreamerAudioInputSelector::update()
-{
- m_names.clear();
- m_descriptions.clear();
-
- //use autoaudiosrc as the first default device
- m_names.append(QLatin1String("default:"));
- m_descriptions.append(tr("System default device"));
-
- updatePulseDevices();
- updateAlsaDevices();
- updateOssDevices();
- if (m_names.size() > 0)
- m_audioInput = m_names.at(0);
-}
-
-void QGstreamerAudioInputSelector::updateAlsaDevices()
-{
-#if QT_CONFIG(alsa)
- void **hints, **n;
- if (snd_device_name_hint(-1, "pcm", &hints) < 0) {
- qWarning()<<"no alsa devices available";
- return;
- }
- n = hints;
-
- while (*n != nullptr) {
- char *name = snd_device_name_get_hint(*n, "NAME");
- char *descr = snd_device_name_get_hint(*n, "DESC");
- char *io = snd_device_name_get_hint(*n, "IOID");
-
- if ((name != nullptr) && (descr != nullptr)) {
- if (io == nullptr || qstrcmp(io, "Input") == 0) {
- m_names.append(QLatin1String("alsa:")+QString::fromUtf8(name));
- m_descriptions.append(QString::fromUtf8(descr));
- }
- }
-
- free(name);
- free(descr);
- free(io);
- n++;
- }
- snd_device_name_free_hint(hints);
-#endif
-}
-
-void QGstreamerAudioInputSelector::updateOssDevices()
-{
- QDir devDir(QStringLiteral("/dev"));
- devDir.setFilter(QDir::System);
- const QFileInfoList entries = devDir.entryInfoList(QStringList() << QLatin1String("dsp*"));
- for (const QFileInfo& entryInfo : entries) {
- m_names.append(QLatin1String("oss:")+entryInfo.filePath());
- m_descriptions.append(QString::fromLatin1("OSS device %1").arg(entryInfo.fileName()));
- }
-}
-
-void QGstreamerAudioInputSelector::updatePulseDevices()
-{
- GstElementFactory *factory = gst_element_factory_find("pulsesrc");
- if (factory) {
- m_names.append(QLatin1String("pulseaudio:"));
- m_descriptions.append(QLatin1String("PulseAudio device."));
- gst_object_unref(GST_OBJECT(factory));
- }
-}
diff --git a/src/gsttools/qgstreameraudioinputselector_p.h b/src/gsttools/qgstreameraudioinputselector_p.h
deleted file mode 100644
index 0c193fda9..000000000
--- a/src/gsttools/qgstreameraudioinputselector_p.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERAUDIOINPUTSELECTOR_H
-#define QGSTREAMERAUDIOINPUTSELECTOR_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <qaudioinputselectorcontrol.h>
-#include <QtCore/qstringlist.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q_GSTTOOLS_EXPORT QGstreamerAudioInputSelector : public QAudioInputSelectorControl
-{
-Q_OBJECT
-public:
- QGstreamerAudioInputSelector(QObject *parent);
- ~QGstreamerAudioInputSelector();
-
- QList<QString> availableInputs() const override;
- QString inputDescription(const QString &name) const override;
- QString defaultInput() const override;
- QString activeInput() const override;
-
-public Q_SLOTS:
- void setActiveInput(const QString &name) override;
-
-private:
- void update();
- void updateAlsaDevices();
- void updateOssDevices();
- void updatePulseDevices();
-
- QString m_audioInput;
- QList<QString> m_names;
- QList<QString> m_descriptions;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERAUDIOINPUTSELECTOR_H
diff --git a/src/gsttools/qgstreameraudioprobecontrol.cpp b/src/gsttools/qgstreameraudioprobecontrol.cpp
deleted file mode 100644
index d40b39939..000000000
--- a/src/gsttools/qgstreameraudioprobecontrol.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreameraudioprobecontrol_p.h"
-#include <private/qgstutils_p.h>
-
-QGstreamerAudioProbeControl::QGstreamerAudioProbeControl(QObject *parent)
- : QMediaAudioProbeControl(parent)
-{
-}
-
-QGstreamerAudioProbeControl::~QGstreamerAudioProbeControl()
-{
-}
-
-void QGstreamerAudioProbeControl::probeCaps(GstCaps *caps)
-{
- QAudioFormat format = QGstUtils::audioFormatForCaps(caps);
-
- QMutexLocker locker(&m_bufferMutex);
- m_format = format;
-}
-
-bool QGstreamerAudioProbeControl::probeBuffer(GstBuffer *buffer)
-{
- qint64 position = GST_BUFFER_TIMESTAMP(buffer);
- position = position >= 0
- ? position / G_GINT64_CONSTANT(1000) // microseconds
- : -1;
-
- QByteArray data;
-#if GST_CHECK_VERSION(1,0,0)
- GstMapInfo info;
- if (gst_buffer_map(buffer, &info, GST_MAP_READ)) {
- data = QByteArray(reinterpret_cast<const char *>(info.data), info.size);
- gst_buffer_unmap(buffer, &info);
- } else {
- return true;
- }
-#else
- data = QByteArray(reinterpret_cast<const char *>(buffer->data), buffer->size);
-#endif
-
- QMutexLocker locker(&m_bufferMutex);
- if (m_format.isValid()) {
- if (!m_pendingBuffer.isValid())
- QMetaObject::invokeMethod(this, "bufferProbed", Qt::QueuedConnection);
- m_pendingBuffer = QAudioBuffer(data, m_format, position);
- }
-
- return true;
-}
-
-void QGstreamerAudioProbeControl::bufferProbed()
-{
- QAudioBuffer audioBuffer;
- {
- QMutexLocker locker(&m_bufferMutex);
- if (!m_pendingBuffer.isValid())
- return;
- audioBuffer = m_pendingBuffer;
- m_pendingBuffer = QAudioBuffer();
- }
- emit audioBufferProbed(audioBuffer);
-}
diff --git a/src/gsttools/qgstreameraudioprobecontrol_p.h b/src/gsttools/qgstreameraudioprobecontrol_p.h
deleted file mode 100644
index 4fc5c7704..000000000
--- a/src/gsttools/qgstreameraudioprobecontrol_p.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERAUDIOPROBECONTROL_H
-#define QGSTREAMERAUDIOPROBECONTROL_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <gst/gst.h>
-#include <qmediaaudioprobecontrol.h>
-#include <QtCore/qmutex.h>
-#include <qaudiobuffer.h>
-#include <qshareddata.h>
-
-#include <private/qgstreamerbufferprobe_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q_GSTTOOLS_EXPORT QGstreamerAudioProbeControl
- : public QMediaAudioProbeControl
- , public QGstreamerBufferProbe
- , public QSharedData
-{
- Q_OBJECT
-public:
- explicit QGstreamerAudioProbeControl(QObject *parent);
- virtual ~QGstreamerAudioProbeControl();
-
-protected:
- void probeCaps(GstCaps *caps) override;
- bool probeBuffer(GstBuffer *buffer) override;
-
-private slots:
- void bufferProbed();
-
-private:
- QAudioBuffer m_pendingBuffer;
- QAudioFormat m_format;
- QMutex m_bufferMutex;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERAUDIOPROBECONTROL_H
diff --git a/src/gsttools/qgstreamerbufferprobe.cpp b/src/gsttools/qgstreamerbufferprobe.cpp
deleted file mode 100644
index e2956eadd..000000000
--- a/src/gsttools/qgstreamerbufferprobe.cpp
+++ /dev/null
@@ -1,166 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamerbufferprobe_p.h"
-#include "qgstutils_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QGstreamerBufferProbe::QGstreamerBufferProbe(Flags flags)
- : m_flags(flags)
-{
-}
-
-QGstreamerBufferProbe::~QGstreamerBufferProbe()
-{
-#if !GST_CHECK_VERSION(1,0,0)
- if (m_caps)
- gst_caps_unref(m_caps);
-#endif
-}
-
-void QGstreamerBufferProbe::addProbeToPad(GstPad *pad, bool downstream)
-{
- if (GstCaps *caps = qt_gst_pad_get_current_caps(pad)) {
- probeCaps(caps);
- gst_caps_unref(caps);
- }
-#if GST_CHECK_VERSION(1,0,0)
- if (m_flags & ProbeCaps) {
- m_capsProbeId = gst_pad_add_probe(
- pad,
- downstream
- ? GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM
- : GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
- capsProbe,
- this,
- nullptr);
- }
- if (m_flags & ProbeBuffers) {
- m_bufferProbeId = gst_pad_add_probe(
- pad, GST_PAD_PROBE_TYPE_BUFFER, bufferProbe, this, nullptr);
- }
-#else
- Q_UNUSED(downstream);
-
- m_bufferProbeId = gst_pad_add_buffer_probe(pad, G_CALLBACK(bufferProbe), this);
-#endif
-}
-
-void QGstreamerBufferProbe::removeProbeFromPad(GstPad *pad)
-{
-#if GST_CHECK_VERSION(1,0,0)
- if (m_capsProbeId != -1) {
- gst_pad_remove_probe(pad, m_capsProbeId);
- m_capsProbeId = -1;
- }
- if (m_bufferProbeId != -1) {
- gst_pad_remove_probe(pad, m_bufferProbeId);
- m_bufferProbeId = -1;
- }
-#else
- if (m_bufferProbeId != -1) {
- gst_pad_remove_buffer_probe(pad, m_bufferProbeId);
- m_bufferProbeId = -1;
- if (m_caps) {
- gst_caps_unref(m_caps);
- m_caps = 0;
- }
- }
-#endif
-}
-
-void QGstreamerBufferProbe::probeCaps(GstCaps *)
-{
-}
-
-bool QGstreamerBufferProbe::probeBuffer(GstBuffer *)
-{
- return true;
-}
-
-#if GST_CHECK_VERSION(1,0,0)
-GstPadProbeReturn QGstreamerBufferProbe::capsProbe(
- GstPad *, GstPadProbeInfo *info, gpointer user_data)
-{
- QGstreamerBufferProbe * const control = static_cast<QGstreamerBufferProbe *>(user_data);
-
- if (GstEvent * const event = gst_pad_probe_info_get_event(info)) {
- if (GST_EVENT_TYPE(event) == GST_EVENT_CAPS) {
- GstCaps *caps;
- gst_event_parse_caps(event, &caps);
-
- control->probeCaps(caps);
- }
- }
- return GST_PAD_PROBE_OK;
-}
-
-GstPadProbeReturn QGstreamerBufferProbe::bufferProbe(
- GstPad *, GstPadProbeInfo *info, gpointer user_data)
-{
- QGstreamerBufferProbe * const control = static_cast<QGstreamerBufferProbe *>(user_data);
- if (GstBuffer * const buffer = gst_pad_probe_info_get_buffer(info))
- return control->probeBuffer(buffer) ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP;
- return GST_PAD_PROBE_OK;
-}
-#else
-gboolean QGstreamerBufferProbe::bufferProbe(GstElement *, GstBuffer *buffer, gpointer user_data)
-{
- QGstreamerBufferProbe * const control = static_cast<QGstreamerBufferProbe *>(user_data);
-
- if (control->m_flags & ProbeCaps) {
- GstCaps *caps = gst_buffer_get_caps(buffer);
- if (caps && (!control->m_caps || !gst_caps_is_equal(control->m_caps, caps))) {
- qSwap(caps, control->m_caps);
- control->probeCaps(control->m_caps);
- }
- if (caps)
- gst_caps_unref(caps);
- }
-
- if (control->m_flags & ProbeBuffers) {
- return control->probeBuffer(buffer) ? TRUE : FALSE;
- } else {
- return TRUE;
- }
-}
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/gsttools/qgstreamerbufferprobe_p.h b/src/gsttools/qgstreamerbufferprobe_p.h
deleted file mode 100644
index 2dda73e40..000000000
--- a/src/gsttools/qgstreamerbufferprobe_p.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERBUFFERPROBE_H
-#define QGSTREAMERBUFFERPROBE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <gst/gst.h>
-
-#include <QtCore/qglobal.h>
-
-
-QT_BEGIN_NAMESPACE
-
-class Q_GSTTOOLS_EXPORT QGstreamerBufferProbe
-{
-public:
- enum Flags
- {
- ProbeCaps = 0x01,
- ProbeBuffers = 0x02,
- ProbeAll = ProbeCaps | ProbeBuffers
- };
-
- explicit QGstreamerBufferProbe(Flags flags = ProbeAll);
- virtual ~QGstreamerBufferProbe();
-
- void addProbeToPad(GstPad *pad, bool downstream = true);
- void removeProbeFromPad(GstPad *pad);
-
-protected:
- virtual void probeCaps(GstCaps *caps);
- virtual bool probeBuffer(GstBuffer *buffer);
-
-private:
-#if GST_CHECK_VERSION(1,0,0)
- static GstPadProbeReturn capsProbe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
- static GstPadProbeReturn bufferProbe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
- int m_capsProbeId = -1;
-#else
- static gboolean bufferProbe(GstElement *element, GstBuffer *buffer, gpointer user_data);
- GstCaps *m_caps = nullptr;
-#endif
- int m_bufferProbeId = -1;
- const Flags m_flags;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERAUDIOPROBECONTROL_H
diff --git a/src/gsttools/qgstreamerbushelper.cpp b/src/gsttools/qgstreamerbushelper.cpp
deleted file mode 100644
index 1a4034eee..000000000
--- a/src/gsttools/qgstreamerbushelper.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qmap.h>
-#include <QtCore/qtimer.h>
-#include <QtCore/qmutex.h>
-#include <QtCore/qlist.h>
-#include <QtCore/qabstracteventdispatcher.h>
-#include <QtCore/qcoreapplication.h>
-
-#include "qgstreamerbushelper_p.h"
-
-QT_BEGIN_NAMESPACE
-
-
-class QGstreamerBusHelperPrivate : public QObject
-{
- Q_OBJECT
-public:
- QGstreamerBusHelperPrivate(QGstreamerBusHelper *parent, GstBus* bus) :
- QObject(parent),
- m_tag(0),
- m_bus(bus),
- m_helper(parent),
- m_intervalTimer(nullptr)
- {
- // glib event loop can be disabled either by env variable or QT_NO_GLIB define, so check the dispacher
- QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher();
- const bool hasGlib = dispatcher && dispatcher->inherits("QEventDispatcherGlib");
- if (!hasGlib) {
- m_intervalTimer = new QTimer(this);
- m_intervalTimer->setInterval(250);
- connect(m_intervalTimer, SIGNAL(timeout()), SLOT(interval()));
- m_intervalTimer->start();
- } else {
- m_tag = gst_bus_add_watch_full(bus, G_PRIORITY_DEFAULT, busCallback, this, nullptr);
- }
- }
-
- ~QGstreamerBusHelperPrivate()
- {
- m_helper = 0;
- delete m_intervalTimer;
-
- if (m_tag)
-#if GST_CHECK_VERSION(1, 6, 0)
- gst_bus_remove_watch(m_bus);
-#else
- g_source_remove(m_tag);
-#endif
- }
-
- GstBus* bus() const { return m_bus; }
-
-private slots:
- void interval()
- {
- GstMessage* message;
- while ((message = gst_bus_poll(m_bus, GST_MESSAGE_ANY, 0)) != 0) {
- processMessage(message);
- gst_message_unref(message);
- }
- }
-
-private:
- void processMessage(GstMessage* message)
- {
- QGstreamerMessage msg(message);
- doProcessMessage(msg);
- }
-
- void queueMessage(GstMessage* message)
- {
- QGstreamerMessage msg(message);
- QMetaObject::invokeMethod(this, "doProcessMessage", Qt::QueuedConnection,
- Q_ARG(QGstreamerMessage, msg));
- }
-
- static gboolean busCallback(GstBus *bus, GstMessage *message, gpointer data)
- {
- Q_UNUSED(bus);
- reinterpret_cast<QGstreamerBusHelperPrivate*>(data)->queueMessage(message);
- return TRUE;
- }
-
- guint m_tag;
- GstBus* m_bus;
- QGstreamerBusHelper* m_helper;
- QTimer* m_intervalTimer;
-
-private slots:
- void doProcessMessage(const QGstreamerMessage& msg)
- {
- for (QGstreamerBusMessageFilter *filter : qAsConst(busFilters)) {
- if (filter->processBusMessage(msg))
- break;
- }
- emit m_helper->message(msg);
- }
-
-public:
- QMutex filterMutex;
- QList<QGstreamerSyncMessageFilter*> syncFilters;
- QList<QGstreamerBusMessageFilter*> busFilters;
-};
-
-
-static GstBusSyncReply syncGstBusFilter(GstBus* bus, GstMessage* message, QGstreamerBusHelperPrivate *d)
-{
- Q_UNUSED(bus);
- QMutexLocker lock(&d->filterMutex);
-
- for (QGstreamerSyncMessageFilter *filter : qAsConst(d->syncFilters)) {
- if (filter->processSyncMessage(QGstreamerMessage(message))) {
- gst_message_unref(message);
- return GST_BUS_DROP;
- }
- }
-
- return GST_BUS_PASS;
-}
-
-
-/*!
- \class QGstreamerBusHelper
- \internal
-*/
-
-QGstreamerBusHelper::QGstreamerBusHelper(GstBus* bus, QObject* parent):
- QObject(parent)
-{
- d = new QGstreamerBusHelperPrivate(this, bus);
-#if GST_CHECK_VERSION(1,0,0)
- gst_bus_set_sync_handler(bus, (GstBusSyncHandler)syncGstBusFilter, d, 0);
-#else
- gst_bus_set_sync_handler(bus, (GstBusSyncHandler)syncGstBusFilter, d);
-#endif
- gst_object_ref(GST_OBJECT(bus));
-}
-
-QGstreamerBusHelper::~QGstreamerBusHelper()
-{
-#if GST_CHECK_VERSION(1,0,0)
- gst_bus_set_sync_handler(d->bus(), 0, 0, 0);
-#else
- gst_bus_set_sync_handler(d->bus(),0,0);
-#endif
- gst_object_unref(GST_OBJECT(d->bus()));
-}
-
-void QGstreamerBusHelper::installMessageFilter(QObject *filter)
-{
- auto syncFilter = qobject_cast<QGstreamerSyncMessageFilter*>(filter);
- if (syncFilter) {
- QMutexLocker lock(&d->filterMutex);
- if (!d->syncFilters.contains(syncFilter))
- d->syncFilters.append(syncFilter);
- }
-
- auto busFilter = qobject_cast<QGstreamerBusMessageFilter*>(filter);
- if (busFilter && !d->busFilters.contains(busFilter))
- d->busFilters.append(busFilter);
-}
-
-void QGstreamerBusHelper::removeMessageFilter(QObject *filter)
-{
- auto syncFilter = qobject_cast<QGstreamerSyncMessageFilter*>(filter);
- if (syncFilter) {
- QMutexLocker lock(&d->filterMutex);
- d->syncFilters.removeAll(syncFilter);
- }
-
- auto busFilter = qobject_cast<QGstreamerBusMessageFilter*>(filter);
- if (busFilter)
- d->busFilters.removeAll(busFilter);
-}
-
-QT_END_NAMESPACE
-
-#include "qgstreamerbushelper.moc"
diff --git a/src/gsttools/qgstreamerbushelper_p.h b/src/gsttools/qgstreamerbushelper_p.h
deleted file mode 100644
index e784f6e41..000000000
--- a/src/gsttools/qgstreamerbushelper_p.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERBUSHELPER_P_H
-#define QGSTREAMERBUSHELPER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <QObject>
-
-#include "qgstreamermessage_p.h"
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerSyncMessageFilter {
-public:
- //returns true if message was processed and should be dropped, false otherwise
- virtual bool processSyncMessage(const QGstreamerMessage &message) = 0;
-};
-#define QGstreamerSyncMessageFilter_iid "org.qt-project.qt.gstreamersyncmessagefilter/5.0"
-Q_DECLARE_INTERFACE(QGstreamerSyncMessageFilter, QGstreamerSyncMessageFilter_iid)
-
-
-class QGstreamerBusMessageFilter {
-public:
- //returns true if message was processed and should be dropped, false otherwise
- virtual bool processBusMessage(const QGstreamerMessage &message) = 0;
-};
-#define QGstreamerBusMessageFilter_iid "org.qt-project.qt.gstreamerbusmessagefilter/5.0"
-Q_DECLARE_INTERFACE(QGstreamerBusMessageFilter, QGstreamerBusMessageFilter_iid)
-
-
-class QGstreamerBusHelperPrivate;
-
-class Q_GSTTOOLS_EXPORT QGstreamerBusHelper : public QObject
-{
- Q_OBJECT
- friend class QGstreamerBusHelperPrivate;
-
-public:
- QGstreamerBusHelper(GstBus* bus, QObject* parent = 0);
- ~QGstreamerBusHelper();
-
- void installMessageFilter(QObject *filter);
- void removeMessageFilter(QObject *filter);
-
-signals:
- void message(QGstreamerMessage const& message);
-
-private:
- QGstreamerBusHelperPrivate *d = nullptr;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gsttools/qgstreamermessage.cpp b/src/gsttools/qgstreamermessage.cpp
deleted file mode 100644
index 7191565e1..000000000
--- a/src/gsttools/qgstreamermessage.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <gst/gst.h>
-
-#include "qgstreamermessage_p.h"
-
-QT_BEGIN_NAMESPACE
-
-static int wuchi = qRegisterMetaType<QGstreamerMessage>();
-
-
-/*!
- \class QGstreamerMessage
- \internal
-*/
-
-QGstreamerMessage::QGstreamerMessage(GstMessage* message):
- m_message(message)
-{
- gst_message_ref(m_message);
-}
-
-QGstreamerMessage::QGstreamerMessage(QGstreamerMessage const& m):
- m_message(m.m_message)
-{
- gst_message_ref(m_message);
-}
-
-
-QGstreamerMessage::~QGstreamerMessage()
-{
- if (m_message != 0)
- gst_message_unref(m_message);
-}
-
-GstMessage* QGstreamerMessage::rawMessage() const
-{
- return m_message;
-}
-
-QGstreamerMessage& QGstreamerMessage::operator=(QGstreamerMessage const& rhs)
-{
- if (rhs.m_message != m_message) {
- if (rhs.m_message != 0)
- gst_message_ref(rhs.m_message);
-
- if (m_message != 0)
- gst_message_unref(m_message);
-
- m_message = rhs.m_message;
- }
-
- return *this;
-}
-
-QT_END_NAMESPACE
diff --git a/src/gsttools/qgstreamermessage_p.h b/src/gsttools/qgstreamermessage_p.h
deleted file mode 100644
index baeecc360..000000000
--- a/src/gsttools/qgstreamermessage_p.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERMESSAGE_P_H
-#define QGSTREAMERMESSAGE_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <QMetaType>
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_GSTTOOLS_EXPORT QGstreamerMessage
-{
-public:
- QGstreamerMessage() = default;
- QGstreamerMessage(GstMessage* message);
- QGstreamerMessage(QGstreamerMessage const& m);
- ~QGstreamerMessage();
-
- GstMessage* rawMessage() const;
-
- QGstreamerMessage& operator=(QGstreamerMessage const& rhs);
-
-private:
- GstMessage* m_message = nullptr;
-};
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QGstreamerMessage);
-
-#endif
diff --git a/src/gsttools/qgstreamerplayercontrol.cpp b/src/gsttools/qgstreamerplayercontrol.cpp
deleted file mode 100644
index 689467db8..000000000
--- a/src/gsttools/qgstreamerplayercontrol.cpp
+++ /dev/null
@@ -1,613 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <private/qgstreamerplayercontrol_p.h>
-#include <private/qgstreamerplayersession_p.h>
-
-#include <private/qmediaplaylistnavigator_p.h>
-#include <private/qmediaresourcepolicy_p.h>
-#include <private/qmediaresourceset_p.h>
-
-#include <QtCore/qdir.h>
-#include <QtCore/qsocketnotifier.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qdebug.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-//#define DEBUG_PLAYBIN
-
-QT_BEGIN_NAMESPACE
-
-QGstreamerPlayerControl::QGstreamerPlayerControl(QGstreamerPlayerSession *session, QObject *parent)
- : QMediaPlayerControl(parent)
- , m_session(session)
-{
- m_resources = QMediaResourcePolicy::createResourceSet<QMediaPlayerResourceSetInterface>();
- Q_ASSERT(m_resources);
-
- connect(m_session, &QGstreamerPlayerSession::positionChanged, this, &QGstreamerPlayerControl::positionChanged);
- connect(m_session, &QGstreamerPlayerSession::durationChanged, this, &QGstreamerPlayerControl::durationChanged);
- connect(m_session, &QGstreamerPlayerSession::mutedStateChanged, this, &QGstreamerPlayerControl::mutedChanged);
- connect(m_session, &QGstreamerPlayerSession::volumeChanged, this, &QGstreamerPlayerControl::volumeChanged);
- connect(m_session, &QGstreamerPlayerSession::stateChanged, this, &QGstreamerPlayerControl::updateSessionState);
- connect(m_session, &QGstreamerPlayerSession::bufferingProgressChanged, this, &QGstreamerPlayerControl::setBufferProgress);
- connect(m_session, &QGstreamerPlayerSession::playbackFinished, this, &QGstreamerPlayerControl::processEOS);
- connect(m_session, &QGstreamerPlayerSession::audioAvailableChanged, this, &QGstreamerPlayerControl::audioAvailableChanged);
- connect(m_session, &QGstreamerPlayerSession::videoAvailableChanged, this, &QGstreamerPlayerControl::videoAvailableChanged);
- connect(m_session, &QGstreamerPlayerSession::seekableChanged, this, &QGstreamerPlayerControl::seekableChanged);
- connect(m_session, &QGstreamerPlayerSession::error, this, &QGstreamerPlayerControl::error);
- connect(m_session, &QGstreamerPlayerSession::invalidMedia, this, &QGstreamerPlayerControl::handleInvalidMedia);
- connect(m_session, &QGstreamerPlayerSession::playbackRateChanged, this, &QGstreamerPlayerControl::playbackRateChanged);
-
- connect(m_resources, &QMediaPlayerResourceSetInterface::resourcesGranted, this, &QGstreamerPlayerControl::handleResourcesGranted);
- //denied signal should be queued to have correct state update process,
- //since in playOrPause, when acquire is call on resource set, it may trigger a resourcesDenied signal immediately,
- //so handleResourcesDenied should be processed later, otherwise it will be overwritten by state update later in playOrPause.
- connect(m_resources, &QMediaPlayerResourceSetInterface::resourcesDenied,
- this, &QGstreamerPlayerControl::handleResourcesDenied, Qt::QueuedConnection);
- connect(m_resources, &QMediaPlayerResourceSetInterface::resourcesLost, this, &QGstreamerPlayerControl::handleResourcesLost);
-}
-
-QGstreamerPlayerControl::~QGstreamerPlayerControl()
-{
- QMediaResourcePolicy::destroyResourceSet(m_resources);
-}
-
-QMediaPlayerResourceSetInterface* QGstreamerPlayerControl::resources() const
-{
- return m_resources;
-}
-
-qint64 QGstreamerPlayerControl::position() const
-{
- if (m_mediaStatus == QMediaPlayer::EndOfMedia)
- return m_session->duration();
-
- return m_pendingSeekPosition != -1 ? m_pendingSeekPosition : m_session->position();
-}
-
-qint64 QGstreamerPlayerControl::duration() const
-{
- return m_session->duration();
-}
-
-QMediaPlayer::State QGstreamerPlayerControl::state() const
-{
- return m_currentState;
-}
-
-QMediaPlayer::MediaStatus QGstreamerPlayerControl::mediaStatus() const
-{
- return m_mediaStatus;
-}
-
-int QGstreamerPlayerControl::bufferStatus() const
-{
- if (m_bufferProgress == -1) {
- return m_session->state() == QMediaPlayer::StoppedState ? 0 : 100;
- } else
- return m_bufferProgress;
-}
-
-int QGstreamerPlayerControl::volume() const
-{
- return m_session->volume();
-}
-
-bool QGstreamerPlayerControl::isMuted() const
-{
- return m_session->isMuted();
-}
-
-bool QGstreamerPlayerControl::isSeekable() const
-{
- return m_session->isSeekable();
-}
-
-QMediaTimeRange QGstreamerPlayerControl::availablePlaybackRanges() const
-{
- return m_session->availablePlaybackRanges();
-}
-
-qreal QGstreamerPlayerControl::playbackRate() const
-{
- return m_session->playbackRate();
-}
-
-void QGstreamerPlayerControl::setPlaybackRate(qreal rate)
-{
- m_session->setPlaybackRate(rate);
-}
-
-void QGstreamerPlayerControl::setPosition(qint64 pos)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << pos/1000.0;
-#endif
-
- pushState();
-
- if (m_mediaStatus == QMediaPlayer::EndOfMedia) {
- m_mediaStatus = QMediaPlayer::LoadedMedia;
- }
-
- if (m_currentState == QMediaPlayer::StoppedState) {
- m_pendingSeekPosition = pos;
- emit positionChanged(m_pendingSeekPosition);
- } else if (m_session->isSeekable()) {
- m_session->showPrerollFrames(true);
- m_session->seek(pos);
- m_pendingSeekPosition = -1;
- } else if (m_session->state() == QMediaPlayer::StoppedState) {
- m_pendingSeekPosition = pos;
- emit positionChanged(m_pendingSeekPosition);
- } else if (m_pendingSeekPosition != -1) {
- m_pendingSeekPosition = -1;
- emit positionChanged(m_pendingSeekPosition);
- }
-
- popAndNotifyState();
-}
-
-void QGstreamerPlayerControl::play()
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
- //m_userRequestedState is needed to know that we need to resume playback when resource-policy
- //regranted the resources after lost, since m_currentState will become paused when resources are
- //lost.
- m_userRequestedState = QMediaPlayer::PlayingState;
- playOrPause(QMediaPlayer::PlayingState);
-}
-
-void QGstreamerPlayerControl::pause()
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
- m_userRequestedState = QMediaPlayer::PausedState;
- // If the playback has not been started yet but pause is requested.
- // Seek to the beginning to show first frame.
- if (m_pendingSeekPosition == -1 && m_session->position() == 0)
- m_pendingSeekPosition = 0;
-
- playOrPause(QMediaPlayer::PausedState);
-}
-
-void QGstreamerPlayerControl::playOrPause(QMediaPlayer::State newState)
-{
- if (m_mediaStatus == QMediaPlayer::NoMedia)
- return;
-
- pushState();
-
- if (m_setMediaPending) {
- m_mediaStatus = QMediaPlayer::LoadingMedia;
- setMedia(m_currentResource, m_stream);
- }
-
- if (m_mediaStatus == QMediaPlayer::EndOfMedia && m_pendingSeekPosition == -1) {
- m_pendingSeekPosition = 0;
- }
-
- if (!m_resources->isGranted())
- m_resources->acquire();
-
- if (m_resources->isGranted()) {
- // show prerolled frame if switching from stopped state
- if (m_pendingSeekPosition == -1) {
- m_session->showPrerollFrames(true);
- } else if (m_session->state() == QMediaPlayer::StoppedState) {
- // Don't evaluate the next two conditions.
- } else if (m_session->isSeekable()) {
- m_session->pause();
- m_session->showPrerollFrames(true);
- m_session->seek(m_pendingSeekPosition);
- m_pendingSeekPosition = -1;
- } else {
- m_pendingSeekPosition = -1;
- }
-
- bool ok = false;
-
- //To prevent displaying the first video frame when playback is resumed
- //the pipeline is paused instead of playing, seeked to requested position,
- //and after seeking is finished (position updated) playback is restarted
- //with show-preroll-frame enabled.
- if (newState == QMediaPlayer::PlayingState && m_pendingSeekPosition == -1)
- ok = m_session->play();
- else
- ok = m_session->pause();
-
- if (!ok)
- newState = QMediaPlayer::StoppedState;
- }
-
- if (m_mediaStatus == QMediaPlayer::InvalidMedia)
- m_mediaStatus = QMediaPlayer::LoadingMedia;
-
- m_currentState = newState;
-
- if (m_mediaStatus == QMediaPlayer::EndOfMedia || m_mediaStatus == QMediaPlayer::LoadedMedia) {
- if (m_bufferProgress == -1 || m_bufferProgress == 100)
- m_mediaStatus = QMediaPlayer::BufferedMedia;
- else
- m_mediaStatus = QMediaPlayer::BufferingMedia;
- }
-
- popAndNotifyState();
-
- emit positionChanged(position());
-}
-
-void QGstreamerPlayerControl::stop()
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
- m_userRequestedState = QMediaPlayer::StoppedState;
-
- pushState();
-
- if (m_currentState != QMediaPlayer::StoppedState) {
- m_currentState = QMediaPlayer::StoppedState;
- m_session->showPrerollFrames(false); // stop showing prerolled frames in stop state
- // Since gst is not going to send GST_STATE_PAUSED
- // when pipeline is already paused,
- // needs to update media status directly.
- if (m_session->state() == QMediaPlayer::PausedState)
- updateMediaStatus();
- else if (m_resources->isGranted())
- m_session->pause();
-
- if (m_mediaStatus != QMediaPlayer::EndOfMedia) {
- m_pendingSeekPosition = 0;
- emit positionChanged(position());
- }
- }
-
- popAndNotifyState();
-}
-
-void QGstreamerPlayerControl::setVolume(int volume)
-{
- m_session->setVolume(volume);
-}
-
-void QGstreamerPlayerControl::setMuted(bool muted)
-{
- m_session->setMuted(muted);
-}
-
-QMediaContent QGstreamerPlayerControl::media() const
-{
- return m_currentResource;
-}
-
-const QIODevice *QGstreamerPlayerControl::mediaStream() const
-{
- return m_stream;
-}
-
-void QGstreamerPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
-
- pushState();
-
- m_currentState = QMediaPlayer::StoppedState;
- QMediaContent oldMedia = m_currentResource;
- m_pendingSeekPosition = -1;
- m_session->showPrerollFrames(false); // do not show prerolled frames until pause() or play() explicitly called
- m_setMediaPending = false;
-
- if (!content.isNull() || stream) {
- if (!m_resources->isGranted())
- m_resources->acquire();
- } else {
- m_resources->release();
- }
-
- m_session->stop();
-
- bool userStreamValid = false;
-
- if (m_bufferProgress != -1) {
- m_bufferProgress = -1;
- emit bufferStatusChanged(0);
- }
-
- m_currentResource = content;
- m_stream = stream;
-
- QNetworkRequest request = content.request();
-
- if (m_stream)
- userStreamValid = stream->isOpen() && m_stream->isReadable();
-
-#if !QT_CONFIG(gstreamer_app)
- m_session->loadFromUri(request);
-#else
- if (m_stream) {
- if (userStreamValid){
- m_session->loadFromStream(request, m_stream);
- } else {
- m_mediaStatus = QMediaPlayer::InvalidMedia;
- emit error(QMediaPlayer::FormatError, tr("Attempting to play invalid user stream"));
- if (m_currentState != QMediaPlayer::PlayingState)
- m_resources->release();
- popAndNotifyState();
- return;
- }
- } else
- m_session->loadFromUri(request);
-#endif
-
-#if QT_CONFIG(gstreamer_app)
- if (!request.url().isEmpty() || userStreamValid) {
-#else
- if (!request.url().isEmpty()) {
-#endif
- m_mediaStatus = QMediaPlayer::LoadingMedia;
- m_session->pause();
- } else {
- m_mediaStatus = QMediaPlayer::NoMedia;
- setBufferProgress(0);
- }
-
- if (m_currentResource != oldMedia)
- emit mediaChanged(m_currentResource);
-
- emit positionChanged(position());
-
- if (content.isNull() && !stream)
- m_resources->release();
-
- popAndNotifyState();
-}
-
-void QGstreamerPlayerControl::setVideoOutput(QObject *output)
-{
- m_session->setVideoRenderer(output);
-}
-
-bool QGstreamerPlayerControl::isAudioAvailable() const
-{
- return m_session->isAudioAvailable();
-}
-
-bool QGstreamerPlayerControl::isVideoAvailable() const
-{
- return m_session->isVideoAvailable();
-}
-
-void QGstreamerPlayerControl::updateSessionState(QMediaPlayer::State state)
-{
- pushState();
-
- if (state == QMediaPlayer::StoppedState) {
- m_session->showPrerollFrames(false);
- m_currentState = QMediaPlayer::StoppedState;
- }
-
- if (state == QMediaPlayer::PausedState && m_currentState != QMediaPlayer::StoppedState) {
- if (m_pendingSeekPosition != -1 && m_session->isSeekable()) {
- m_session->showPrerollFrames(true);
- m_session->seek(m_pendingSeekPosition);
- }
- m_pendingSeekPosition = -1;
-
- if (m_currentState == QMediaPlayer::PlayingState) {
- if (m_bufferProgress == -1 || m_bufferProgress == 100)
- m_session->play();
- }
- }
-
- updateMediaStatus();
-
- popAndNotifyState();
-}
-
-void QGstreamerPlayerControl::updateMediaStatus()
-{
- //EndOfMedia status should be kept, until reset by pause, play or setMedia
- if (m_mediaStatus == QMediaPlayer::EndOfMedia)
- return;
-
- pushState();
- QMediaPlayer::MediaStatus oldStatus = m_mediaStatus;
-
- switch (m_session->state()) {
- case QMediaPlayer::StoppedState:
- if (m_currentResource.isNull())
- m_mediaStatus = QMediaPlayer::NoMedia;
- else if (oldStatus != QMediaPlayer::InvalidMedia)
- m_mediaStatus = QMediaPlayer::LoadingMedia;
- break;
-
- case QMediaPlayer::PlayingState:
- case QMediaPlayer::PausedState:
- if (m_currentState == QMediaPlayer::StoppedState) {
- m_mediaStatus = QMediaPlayer::LoadedMedia;
- } else {
- if (m_bufferProgress == -1 || m_bufferProgress == 100)
- m_mediaStatus = QMediaPlayer::BufferedMedia;
- else
- m_mediaStatus = QMediaPlayer::StalledMedia;
- }
- break;
- }
-
- if (m_currentState == QMediaPlayer::PlayingState && !m_resources->isGranted())
- m_mediaStatus = QMediaPlayer::StalledMedia;
-
- popAndNotifyState();
-}
-
-void QGstreamerPlayerControl::processEOS()
-{
- pushState();
- m_mediaStatus = QMediaPlayer::EndOfMedia;
- emit positionChanged(position());
- m_session->endOfMediaReset();
-
- if (m_currentState != QMediaPlayer::StoppedState) {
- m_currentState = QMediaPlayer::StoppedState;
- m_session->showPrerollFrames(false); // stop showing prerolled frames in stop state
- }
-
- popAndNotifyState();
-}
-
-void QGstreamerPlayerControl::setBufferProgress(int progress)
-{
- if (m_bufferProgress == progress || m_mediaStatus == QMediaPlayer::NoMedia)
- return;
-
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << progress;
-#endif
- m_bufferProgress = progress;
-
- if (m_resources->isGranted()) {
- if (m_currentState == QMediaPlayer::PlayingState &&
- m_bufferProgress == 100 &&
- m_session->state() != QMediaPlayer::PlayingState)
- m_session->play();
-
- if (!m_session->isLiveSource() && m_bufferProgress < 100 &&
- (m_session->state() == QMediaPlayer::PlayingState ||
- m_session->pendingState() == QMediaPlayer::PlayingState))
- m_session->pause();
- }
-
- updateMediaStatus();
-
- emit bufferStatusChanged(m_bufferProgress);
-}
-
-void QGstreamerPlayerControl::handleInvalidMedia()
-{
- pushState();
- m_mediaStatus = QMediaPlayer::InvalidMedia;
- m_currentState = QMediaPlayer::StoppedState;
- m_setMediaPending = true;
- popAndNotifyState();
-}
-
-void QGstreamerPlayerControl::handleResourcesGranted()
-{
- pushState();
-
- //This may be triggered when there is an auto resume
- //from resource-policy, we need to take action according to m_userRequestedState
- //rather than m_currentState
- m_currentState = m_userRequestedState;
- if (m_currentState != QMediaPlayer::StoppedState)
- playOrPause(m_currentState);
- else
- updateMediaStatus();
-
- popAndNotifyState();
-}
-
-void QGstreamerPlayerControl::handleResourcesLost()
-{
- //on resource lost the pipeline should be paused
- //player status is changed to paused
- pushState();
- QMediaPlayer::State oldState = m_currentState;
-
- m_session->pause();
-
- if (oldState != QMediaPlayer::StoppedState )
- m_currentState = QMediaPlayer::PausedState;
-
- popAndNotifyState();
-}
-
-void QGstreamerPlayerControl::handleResourcesDenied()
-{
- //on resource denied the pipeline should stay paused
- //player status is changed to paused
- pushState();
-
- if (m_currentState != QMediaPlayer::StoppedState )
- m_currentState = QMediaPlayer::PausedState;
-
- popAndNotifyState();
-}
-
-void QGstreamerPlayerControl::pushState()
-{
- m_stateStack.push(m_currentState);
- m_mediaStatusStack.push(m_mediaStatus);
-}
-
-void QGstreamerPlayerControl::popAndNotifyState()
-{
- Q_ASSERT(!m_stateStack.isEmpty());
-
- QMediaPlayer::State oldState = m_stateStack.pop();
- QMediaPlayer::MediaStatus oldMediaStatus = m_mediaStatusStack.pop();
-
- if (m_stateStack.isEmpty()) {
- if (m_mediaStatus != oldMediaStatus) {
-#ifdef DEBUG_PLAYBIN
- qDebug() << "Media status changed:" << m_mediaStatus;
-#endif
- emit mediaStatusChanged(m_mediaStatus);
- }
-
- if (m_currentState != oldState) {
-#ifdef DEBUG_PLAYBIN
- qDebug() << "State changed:" << m_currentState;
-#endif
- emit stateChanged(m_currentState);
- }
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/gsttools/qgstreamerplayercontrol_p.h b/src/gsttools/qgstreamerplayercontrol_p.h
deleted file mode 100644
index ef94df925..000000000
--- a/src/gsttools/qgstreamerplayercontrol_p.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERPLAYERCONTROL_P_H
-#define QGSTREAMERPLAYERCONTROL_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qstack.h>
-#include <qmediaplayercontrol.h>
-#include <private/qgsttools_global_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QMediaPlayerResourceSetInterface;
-class QGstreamerPlayerSession;
-class Q_GSTTOOLS_EXPORT QGstreamerPlayerControl : public QMediaPlayerControl
-{
- Q_OBJECT
-
-public:
- QGstreamerPlayerControl(QGstreamerPlayerSession *session, QObject *parent = 0);
- ~QGstreamerPlayerControl();
-
- QGstreamerPlayerSession *session() { return m_session; }
-
- QMediaPlayer::State state() const override;
- QMediaPlayer::MediaStatus mediaStatus() const override;
-
- qint64 position() const override;
- qint64 duration() const override;
-
- int bufferStatus() const override;
-
- int volume() const override;
- bool isMuted() const override;
-
- bool isAudioAvailable() const override;
- bool isVideoAvailable() const override;
- void setVideoOutput(QObject *output);
-
- bool isSeekable() const override;
- QMediaTimeRange availablePlaybackRanges() const override;
-
- qreal playbackRate() const override;
- void setPlaybackRate(qreal rate) override;
-
- QMediaContent media() const override;
- const QIODevice *mediaStream() const override;
- void setMedia(const QMediaContent&, QIODevice *) override;
-
- QMediaPlayerResourceSetInterface* resources() const;
-
-public Q_SLOTS:
- void setPosition(qint64 pos) override;
-
- void play() override;
- void pause() override;
- void stop() override;
-
- void setVolume(int volume) override;
- void setMuted(bool muted) override;
-
-private Q_SLOTS:
- void updateSessionState(QMediaPlayer::State state);
- void updateMediaStatus();
- void processEOS();
- void setBufferProgress(int progress);
-
- void handleInvalidMedia();
-
- void handleResourcesGranted();
- void handleResourcesLost();
- void handleResourcesDenied();
-
-private:
- void playOrPause(QMediaPlayer::State state);
-
- void pushState();
- void popAndNotifyState();
-
- QGstreamerPlayerSession *m_session = nullptr;
- QMediaPlayer::State m_userRequestedState = QMediaPlayer::StoppedState;
- QMediaPlayer::State m_currentState = QMediaPlayer::StoppedState;
- QMediaPlayer::MediaStatus m_mediaStatus = QMediaPlayer::NoMedia;
- QStack<QMediaPlayer::State> m_stateStack;
- QStack<QMediaPlayer::MediaStatus> m_mediaStatusStack;
-
- int m_bufferProgress = -1;
- qint64 m_pendingSeekPosition = -1;
- bool m_setMediaPending = false;
- QMediaContent m_currentResource;
- QIODevice *m_stream = nullptr;
-
- QMediaPlayerResourceSetInterface *m_resources = nullptr;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gsttools/qgstreamerplayersession.cpp b/src/gsttools/qgstreamerplayersession.cpp
deleted file mode 100644
index adf11b022..000000000
--- a/src/gsttools/qgstreamerplayersession.cpp
+++ /dev/null
@@ -1,2016 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <private/qgstreamerplayersession_p.h>
-#include <private/qgstreamerbushelper_p.h>
-
-#include <private/qgstreameraudioprobecontrol_p.h>
-#include <private/qgstreamervideoprobecontrol_p.h>
-#include <private/qgstreamervideorendererinterface_p.h>
-#if !GST_CHECK_VERSION(1,0,0)
-#include <private/gstvideoconnector_p.h>
-#endif
-#include <private/qgstutils_p.h>
-#include <private/qvideosurfacegstsink_p.h>
-
-#include <gst/gstvalue.h>
-#include <gst/base/gstbasesrc.h>
-
-#include <QtMultimedia/qmediametadata.h>
-#include <QtCore/qdatetime.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qsize.h>
-#include <QtCore/qtimer.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qdir.h>
-#include <QtCore/qstandardpaths.h>
-#include <qvideorenderercontrol.h>
-#include <QUrlQuery>
-
-//#define DEBUG_PLAYBIN
-
-QT_BEGIN_NAMESPACE
-
-static bool usePlaybinVolume()
-{
- static enum { Yes, No, Unknown } status = Unknown;
- if (status == Unknown) {
- QByteArray v = qgetenv("QT_GSTREAMER_USE_PLAYBIN_VOLUME");
- bool value = !v.isEmpty() && v != "0" && v != "false";
- if (value)
- status = Yes;
- else
- status = No;
- }
- return status == Yes;
-}
-
-typedef enum {
- GST_PLAY_FLAG_VIDEO = 0x00000001,
- GST_PLAY_FLAG_AUDIO = 0x00000002,
- GST_PLAY_FLAG_TEXT = 0x00000004,
- GST_PLAY_FLAG_VIS = 0x00000008,
- GST_PLAY_FLAG_SOFT_VOLUME = 0x00000010,
- GST_PLAY_FLAG_NATIVE_AUDIO = 0x00000020,
- GST_PLAY_FLAG_NATIVE_VIDEO = 0x00000040,
- GST_PLAY_FLAG_DOWNLOAD = 0x00000080,
- GST_PLAY_FLAG_BUFFERING = 0x000000100
-} GstPlayFlags;
-
-#if !GST_CHECK_VERSION(1,0,0)
-#define DEFAULT_RAW_CAPS \
- "video/x-raw-yuv; " \
- "video/x-raw-rgb; " \
- "video/x-raw-gray; " \
- "video/x-surface; " \
- "video/x-android-buffer; " \
- "audio/x-raw-int; " \
- "audio/x-raw-float; " \
- "text/plain; " \
- "text/x-pango-markup; " \
- "video/x-dvd-subpicture; " \
- "subpicture/x-pgs"
-
-static GstStaticCaps static_RawCaps = GST_STATIC_CAPS(DEFAULT_RAW_CAPS);
-#endif
-
-QGstreamerPlayerSession::QGstreamerPlayerSession(QObject *parent)
- : QObject(parent)
-{
- initPlaybin();
-}
-
-void QGstreamerPlayerSession::initPlaybin()
-{
- m_playbin = gst_element_factory_make(QT_GSTREAMER_PLAYBIN_ELEMENT_NAME, nullptr);
- if (m_playbin) {
- //GST_PLAY_FLAG_NATIVE_VIDEO omits configuration of ffmpegcolorspace and videoscale,
- //since those elements are included in the video output bin when necessary.
- int flags = GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO;
- QByteArray envFlags = qgetenv("QT_GSTREAMER_PLAYBIN_FLAGS");
- if (!envFlags.isEmpty()) {
- flags |= envFlags.toInt();
-#if !GST_CHECK_VERSION(1,0,0)
- } else {
- flags |= GST_PLAY_FLAG_NATIVE_VIDEO;
-#endif
- }
- g_object_set(G_OBJECT(m_playbin), "flags", flags, nullptr);
-
- const QByteArray envAudioSink = qgetenv("QT_GSTREAMER_PLAYBIN_AUDIOSINK");
- GstElement *audioSink = gst_element_factory_make(envAudioSink.isEmpty() ? "autoaudiosink" : envAudioSink, "audiosink");
- if (audioSink) {
- if (usePlaybinVolume()) {
- m_audioSink = audioSink;
- m_volumeElement = m_playbin;
- } else {
- m_volumeElement = gst_element_factory_make("volume", "volumeelement");
- if (m_volumeElement) {
- m_audioSink = gst_bin_new("audio-output-bin");
-
- gst_bin_add_many(GST_BIN(m_audioSink), m_volumeElement, audioSink, nullptr);
- gst_element_link(m_volumeElement, audioSink);
-
- GstPad *pad = gst_element_get_static_pad(m_volumeElement, "sink");
- gst_element_add_pad(GST_ELEMENT(m_audioSink), gst_ghost_pad_new("sink", pad));
- gst_object_unref(GST_OBJECT(pad));
- } else {
- m_audioSink = audioSink;
- m_volumeElement = m_playbin;
- }
- }
-
- g_object_set(G_OBJECT(m_playbin), "audio-sink", m_audioSink, nullptr);
- addAudioBufferProbe();
- }
- }
-
-#if GST_CHECK_VERSION(1,0,0)
- static const auto convDesc = qEnvironmentVariable("QT_GSTREAMER_PLAYBIN_CONVERT");
- GError *err = nullptr;
- auto convPipeline = !convDesc.isEmpty() ? convDesc.toLatin1().constData() : "identity";
- auto convElement = gst_parse_launch(convPipeline, &err);
- if (err) {
- qWarning() << "Error:" << convDesc << ":" << QLatin1String(err->message);
- g_clear_error(&err);
- }
- m_videoIdentity = convElement;
-#else
- m_videoIdentity = GST_ELEMENT(g_object_new(gst_video_connector_get_type(), 0)); // floating ref
- g_signal_connect(G_OBJECT(m_videoIdentity), "connection-failed", G_CALLBACK(insertColorSpaceElement), (gpointer)this);
- m_colorSpace = gst_element_factory_make(QT_GSTREAMER_COLORCONVERSION_ELEMENT_NAME, "ffmpegcolorspace-vo");
-
- // might not get a parent, take ownership to avoid leak
- qt_gst_object_ref_sink(GST_OBJECT(m_colorSpace));
-#endif
-
- m_nullVideoSink = gst_element_factory_make("fakesink", nullptr);
- g_object_set(G_OBJECT(m_nullVideoSink), "sync", true, nullptr);
- gst_object_ref(GST_OBJECT(m_nullVideoSink));
-
- m_videoOutputBin = gst_bin_new("video-output-bin");
- // might not get a parent, take ownership to avoid leak
- qt_gst_object_ref_sink(GST_OBJECT(m_videoOutputBin));
-
- GstElement *videoOutputSink = m_videoIdentity;
-#if QT_CONFIG(gstreamer_gl)
- if (QGstUtils::useOpenGL()) {
- videoOutputSink = gst_element_factory_make("glupload", nullptr);
- GstElement *colorConvert = gst_element_factory_make("glcolorconvert", nullptr);
- gst_bin_add_many(GST_BIN(m_videoOutputBin), videoOutputSink, colorConvert, m_videoIdentity, m_nullVideoSink, nullptr);
- gst_element_link_many(videoOutputSink, colorConvert, m_videoIdentity, nullptr);
- } else {
- gst_bin_add_many(GST_BIN(m_videoOutputBin), m_videoIdentity, m_nullVideoSink, nullptr);
- }
-#else
- gst_bin_add_many(GST_BIN(m_videoOutputBin), m_videoIdentity, m_nullVideoSink, nullptr);
-#endif
- gst_element_link(m_videoIdentity, m_nullVideoSink);
-
- m_videoSink = m_nullVideoSink;
-
- // add ghostpads
- GstPad *pad = gst_element_get_static_pad(videoOutputSink, "sink");
- gst_element_add_pad(GST_ELEMENT(m_videoOutputBin), gst_ghost_pad_new("sink", pad));
- gst_object_unref(GST_OBJECT(pad));
-
- if (m_playbin != 0) {
- // Sort out messages
- setBus(gst_element_get_bus(m_playbin));
-
- g_object_set(G_OBJECT(m_playbin), "video-sink", m_videoOutputBin, nullptr);
-
- g_signal_connect(G_OBJECT(m_playbin), "notify::source", G_CALLBACK(playbinNotifySource), this);
- g_signal_connect(G_OBJECT(m_playbin), "element-added", G_CALLBACK(handleElementAdded), this);
-
- if (usePlaybinVolume()) {
- updateVolume();
- updateMuted();
- g_signal_connect(G_OBJECT(m_playbin), "notify::volume", G_CALLBACK(handleVolumeChange), this);
- g_signal_connect(G_OBJECT(m_playbin), "notify::mute", G_CALLBACK(handleMutedChange), this);
- }
-
- g_signal_connect(G_OBJECT(m_playbin), "video-changed", G_CALLBACK(handleStreamsChange), this);
- g_signal_connect(G_OBJECT(m_playbin), "audio-changed", G_CALLBACK(handleStreamsChange), this);
- g_signal_connect(G_OBJECT(m_playbin), "text-changed", G_CALLBACK(handleStreamsChange), this);
-
-#if QT_CONFIG(gstreamer_app)
- g_signal_connect(G_OBJECT(m_playbin), "deep-notify::source", G_CALLBACK(configureAppSrcElement), this);
-#endif
-
- m_pipeline = m_playbin;
- gst_object_ref(GST_OBJECT(m_pipeline));
- }
-}
-
-QGstreamerPlayerSession::~QGstreamerPlayerSession()
-{
- if (m_pipeline) {
- stop();
-
- removeVideoBufferProbe();
- removeAudioBufferProbe();
-
- delete m_busHelper;
- m_busHelper = nullptr;
- resetElements();
- }
-}
-
-template <class T>
-static inline void resetGstObject(T *&obj, T *v = nullptr)
-{
- if (obj)
- gst_object_unref(GST_OBJECT(obj));
-
- obj = v;
-}
-
-void QGstreamerPlayerSession::resetElements()
-{
- setBus(nullptr);
- resetGstObject(m_playbin);
- resetGstObject(m_pipeline);
-#if !GST_CHECK_VERSION(1,0,0)
- resetGstObject(m_colorSpace);
-#endif
- resetGstObject(m_nullVideoSink);
- resetGstObject(m_videoOutputBin);
-
- m_audioSink = nullptr;
- m_volumeElement = nullptr;
- m_videoIdentity = nullptr;
- m_pendingVideoSink = nullptr;
- m_videoSink = nullptr;
-}
-
-GstElement *QGstreamerPlayerSession::playbin() const
-{
- return m_playbin;
-}
-
-#if QT_CONFIG(gstreamer_app)
-void QGstreamerPlayerSession::configureAppSrcElement(GObject* object, GObject *orig, GParamSpec *pspec, QGstreamerPlayerSession* self)
-{
- Q_UNUSED(object);
- Q_UNUSED(pspec);
-
- if (!self->appsrc())
- return;
-
- GstElement *appsrc;
- g_object_get(orig, "source", &appsrc, nullptr);
-
- if (!self->appsrc()->setup(appsrc))
- qWarning()<<"Could not setup appsrc element";
-
- g_object_unref(G_OBJECT(appsrc));
-}
-#endif
-
-void QGstreamerPlayerSession::loadFromStream(const QNetworkRequest &request, QIODevice *appSrcStream)
-{
-#if QT_CONFIG(gstreamer_app)
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
- m_request = request;
- m_duration = 0;
- m_lastPosition = 0;
-
- if (!m_appSrc)
- m_appSrc = new QGstAppSrc(this);
- m_appSrc->setStream(appSrcStream);
-
- if (!parsePipeline() && m_playbin) {
- m_tags.clear();
- emit tagsChanged();
-
- g_object_set(G_OBJECT(m_playbin), "uri", "appsrc://", nullptr);
-
- if (!m_streamTypes.isEmpty()) {
- m_streamProperties.clear();
- m_streamTypes.clear();
-
- emit streamsChanged();
- }
- }
-#endif
-}
-
-void QGstreamerPlayerSession::loadFromUri(const QNetworkRequest &request)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << request.url();
-#endif
- m_request = request;
- m_duration = 0;
- m_lastPosition = 0;
-
-#if QT_CONFIG(gstreamer_app)
- if (m_appSrc) {
- m_appSrc->deleteLater();
- m_appSrc = 0;
- }
-#endif
-
- if (!parsePipeline() && m_playbin) {
- m_tags.clear();
- emit tagsChanged();
-
- g_object_set(G_OBJECT(m_playbin), "uri", m_request.url().toEncoded().constData(), nullptr);
-
- if (!m_streamTypes.isEmpty()) {
- m_streamProperties.clear();
- m_streamTypes.clear();
-
- emit streamsChanged();
- }
- }
-}
-
-bool QGstreamerPlayerSession::parsePipeline()
-{
- if (m_request.url().scheme() != QLatin1String("gst-pipeline")) {
- if (!m_playbin) {
- resetElements();
- initPlaybin();
- updateVideoRenderer();
- }
- return false;
- }
-
- // Set current surface to video sink before creating a pipeline.
- auto renderer = qobject_cast<QVideoRendererControl *>(m_videoOutput);
- if (renderer)
- QVideoSurfaceGstSink::setSurface(renderer->surface());
-
- QString url = m_request.url().toString(QUrl::RemoveScheme);
- QString desc = QUrl::fromPercentEncoding(url.toLatin1().constData());
- GError *err = nullptr;
- GstElement *pipeline = gst_parse_launch(desc.toLatin1().constData(), &err);
- if (err) {
- auto errstr = QLatin1String(err->message);
- qWarning() << "Error:" << desc << ":" << errstr;
- emit error(QMediaPlayer::FormatError, errstr);
- g_clear_error(&err);
- }
-
- return setPipeline(pipeline);
-}
-
-static void gst_foreach(GstIterator *it, const std::function<bool(GstElement *)> &cmp)
-{
-#if GST_CHECK_VERSION(1,0,0)
- GValue value = G_VALUE_INIT;
- while (gst_iterator_next (it, &value) == GST_ITERATOR_OK) {
- auto child = static_cast<GstElement*>(g_value_get_object(&value));
-#else
- GstElement *child = nullptr;
- while (gst_iterator_next(it, reinterpret_cast<gpointer *>(&child)) == GST_ITERATOR_OK) {
-#endif
- if (cmp(child))
- break;
- }
-
- gst_iterator_free(it);
-#if GST_CHECK_VERSION(1,0,0)
- g_value_unset(&value);
-#endif
-}
-
-bool QGstreamerPlayerSession::setPipeline(GstElement *pipeline)
-{
- GstBus *bus = pipeline ? gst_element_get_bus(pipeline) : nullptr;
- if (!bus)
- return false;
-
- if (m_playbin)
- gst_element_set_state(m_playbin, GST_STATE_NULL);
-
- resetElements();
- setBus(bus);
- m_pipeline = pipeline;
-
- if (m_renderer) {
- gst_foreach(gst_bin_iterate_sinks(GST_BIN(pipeline)),
- [this](GstElement *child) {
- if (qstrcmp(GST_OBJECT_NAME(child), "qtvideosink") == 0) {
- m_renderer->setVideoSink(child);
- return true;
- }
- return false;
- });
- }
-
-#if QT_CONFIG(gstreamer_app)
- if (m_appSrc) {
- gst_foreach(gst_bin_iterate_sources(GST_BIN(pipeline)),
- [this](GstElement *child) {
- if (qstrcmp(qt_gst_element_get_factory_name(child), "appsrc") == 0) {
- m_appSrc->setup(child);
- return true;
- }
- return false;
- });
- }
-#endif
-
- emit pipelineChanged();
- return true;
-}
-
-void QGstreamerPlayerSession::setBus(GstBus *bus)
-{
- resetGstObject(m_bus, bus);
-
- // It might still accept gst messages.
- if (m_busHelper)
- m_busHelper->deleteLater();
- m_busHelper = nullptr;
-
- if (!m_bus)
- return;
-
- m_busHelper = new QGstreamerBusHelper(m_bus, this);
- m_busHelper->installMessageFilter(this);
-
- if (m_videoOutput)
- m_busHelper->installMessageFilter(m_videoOutput);
-}
-
-qint64 QGstreamerPlayerSession::duration() const
-{
- return m_duration;
-}
-
-qint64 QGstreamerPlayerSession::position() const
-{
- gint64 position = 0;
-
- if (m_pipeline && qt_gst_element_query_position(m_pipeline, GST_FORMAT_TIME, &position))
- m_lastPosition = position / 1000000;
- return m_lastPosition;
-}
-
-qreal QGstreamerPlayerSession::playbackRate() const
-{
- return m_playbackRate;
-}
-
-void QGstreamerPlayerSession::setPlaybackRate(qreal rate)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << rate;
-#endif
- if (!qFuzzyCompare(m_playbackRate, rate)) {
- m_playbackRate = rate;
- if (m_pipeline && m_seekable) {
- qint64 from = rate > 0 ? position() : 0;
- qint64 to = rate > 0 ? duration() : position();
- gst_element_seek(m_pipeline, rate, GST_FORMAT_TIME,
- GstSeekFlags(GST_SEEK_FLAG_FLUSH),
- GST_SEEK_TYPE_SET, from * 1000000,
- GST_SEEK_TYPE_SET, to * 1000000);
- }
- emit playbackRateChanged(m_playbackRate);
- }
-}
-
-QMediaTimeRange QGstreamerPlayerSession::availablePlaybackRanges() const
-{
- QMediaTimeRange ranges;
-
- if (duration() <= 0)
- return ranges;
-
-#if GST_CHECK_VERSION(0, 10, 31)
- //GST_FORMAT_TIME would be more appropriate, but unfortunately it's not supported.
- //with GST_FORMAT_PERCENT media is treated as encoded with constant bitrate.
- GstQuery* query = gst_query_new_buffering(GST_FORMAT_PERCENT);
-
- if (!gst_element_query(m_pipeline, query)) {
- gst_query_unref(query);
- return ranges;
- }
-
- gint64 rangeStart = 0;
- gint64 rangeStop = 0;
- for (guint index = 0; index < gst_query_get_n_buffering_ranges(query); index++) {
- if (gst_query_parse_nth_buffering_range(query, index, &rangeStart, &rangeStop))
- ranges.addInterval(rangeStart * duration() / 100,
- rangeStop * duration() / 100);
- }
-
- gst_query_unref(query);
-#endif
-
- if (ranges.isEmpty() && !isLiveSource() && isSeekable())
- ranges.addInterval(0, duration());
-
-#ifdef DEBUG_PLAYBIN
- qDebug() << ranges;
-#endif
-
- return ranges;
-}
-
-int QGstreamerPlayerSession::activeStream(QMediaStreamsControl::StreamType streamType) const
-{
- int streamNumber = -1;
- if (m_playbin) {
- switch (streamType) {
- case QMediaStreamsControl::AudioStream:
- g_object_get(G_OBJECT(m_playbin), "current-audio", &streamNumber, nullptr);
- break;
- case QMediaStreamsControl::VideoStream:
- g_object_get(G_OBJECT(m_playbin), "current-video", &streamNumber, nullptr);
- break;
- case QMediaStreamsControl::SubPictureStream:
- g_object_get(G_OBJECT(m_playbin), "current-text", &streamNumber, nullptr);
- break;
- default:
- break;
- }
- }
-
- if (streamNumber >= 0)
- streamNumber += m_playbin2StreamOffset.value(streamType,0);
-
- return streamNumber;
-}
-
-void QGstreamerPlayerSession::setActiveStream(QMediaStreamsControl::StreamType streamType, int streamNumber)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << streamType << streamNumber;
-#endif
-
- if (streamNumber >= 0)
- streamNumber -= m_playbin2StreamOffset.value(streamType,0);
-
- if (m_playbin) {
- switch (streamType) {
- case QMediaStreamsControl::AudioStream:
- g_object_set(G_OBJECT(m_playbin), "current-audio", streamNumber, nullptr);
- break;
- case QMediaStreamsControl::VideoStream:
- g_object_set(G_OBJECT(m_playbin), "current-video", streamNumber, nullptr);
- break;
- case QMediaStreamsControl::SubPictureStream:
- g_object_set(G_OBJECT(m_playbin), "current-text", streamNumber, nullptr);
- break;
- default:
- break;
- }
- }
-}
-
-int QGstreamerPlayerSession::volume() const
-{
- return m_volume;
-}
-
-bool QGstreamerPlayerSession::isMuted() const
-{
- return m_muted;
-}
-
-bool QGstreamerPlayerSession::isAudioAvailable() const
-{
- return m_audioAvailable;
-}
-
-#if GST_CHECK_VERSION(1,0,0)
-static GstPadProbeReturn block_pad_cb(GstPad *pad, GstPadProbeInfo *info, gpointer user_data)
-#else
-static void block_pad_cb(GstPad *pad, gboolean blocked, gpointer user_data)
-#endif
-{
- Q_UNUSED(pad);
-#if GST_CHECK_VERSION(1,0,0)
- Q_UNUSED(info);
- Q_UNUSED(user_data);
- return GST_PAD_PROBE_OK;
-#else
-#ifdef DEBUG_PLAYBIN
- qDebug() << "block_pad_cb, blocked:" << blocked;
-#endif
- if (blocked && user_data) {
- QGstreamerPlayerSession *session = reinterpret_cast<QGstreamerPlayerSession*>(user_data);
- QMetaObject::invokeMethod(session, "finishVideoOutputChange", Qt::QueuedConnection);
- }
-#endif
-}
-
-void QGstreamerPlayerSession::updateVideoRenderer()
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << "Video sink has chaged, reload video output";
-#endif
-
- if (m_videoOutput)
- setVideoRenderer(m_videoOutput);
-}
-
-void QGstreamerPlayerSession::setVideoRenderer(QObject *videoOutput)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
- if (m_videoOutput != videoOutput) {
- if (m_videoOutput) {
- disconnect(m_videoOutput, SIGNAL(sinkChanged()),
- this, SLOT(updateVideoRenderer()));
- disconnect(m_videoOutput, SIGNAL(readyChanged(bool)),
- this, SLOT(updateVideoRenderer()));
-
- m_busHelper->removeMessageFilter(m_videoOutput);
- }
-
- m_videoOutput = videoOutput;
-
- if (m_videoOutput) {
- connect(m_videoOutput, SIGNAL(sinkChanged()),
- this, SLOT(updateVideoRenderer()));
- connect(m_videoOutput, SIGNAL(readyChanged(bool)),
- this, SLOT(updateVideoRenderer()));
-
- m_busHelper->installMessageFilter(m_videoOutput);
- }
- }
-
- m_renderer = qobject_cast<QGstreamerVideoRendererInterface*>(videoOutput);
- emit rendererChanged();
-
- // No sense to continue if custom pipeline requested.
- if (!m_playbin)
- return;
-
- GstElement *videoSink = 0;
- if (m_renderer && m_renderer->isReady())
- videoSink = m_renderer->videoSink();
-
- if (!videoSink)
- videoSink = m_nullVideoSink;
-
-#ifdef DEBUG_PLAYBIN
- qDebug() << "Set video output:" << videoOutput;
- qDebug() << "Current sink:" << (m_videoSink ? GST_ELEMENT_NAME(m_videoSink) : "") << m_videoSink
- << "pending:" << (m_pendingVideoSink ? GST_ELEMENT_NAME(m_pendingVideoSink) : "") << m_pendingVideoSink
- << "new sink:" << (videoSink ? GST_ELEMENT_NAME(videoSink) : "") << videoSink;
-#endif
-
- if (m_pendingVideoSink == videoSink ||
- (m_pendingVideoSink == 0 && m_videoSink == videoSink)) {
-#ifdef DEBUG_PLAYBIN
- qDebug() << "Video sink has not changed, skip video output reconfiguration";
-#endif
- return;
- }
-
-#ifdef DEBUG_PLAYBIN
- qDebug() << "Reconfigure video output";
-#endif
-
- if (m_state == QMediaPlayer::StoppedState) {
-#ifdef DEBUG_PLAYBIN
- qDebug() << "The pipeline has not started yet, pending state:" << m_pendingState;
-#endif
- //the pipeline has not started yet
- flushVideoProbes();
- m_pendingVideoSink = 0;
- gst_element_set_state(m_videoSink, GST_STATE_NULL);
- gst_element_set_state(m_playbin, GST_STATE_NULL);
-
-#if !GST_CHECK_VERSION(1,0,0)
- if (m_usingColorspaceElement) {
- gst_element_unlink(m_colorSpace, m_videoSink);
- gst_bin_remove(GST_BIN(m_videoOutputBin), m_colorSpace);
- } else {
- gst_element_unlink(m_videoIdentity, m_videoSink);
- }
-#endif
-
- removeVideoBufferProbe();
-
- gst_bin_remove(GST_BIN(m_videoOutputBin), m_videoSink);
-
- m_videoSink = videoSink;
-
- gst_bin_add(GST_BIN(m_videoOutputBin), m_videoSink);
-
- bool linked = gst_element_link(m_videoIdentity, m_videoSink);
-#if !GST_CHECK_VERSION(1,0,0)
- m_usingColorspaceElement = false;
- if (!linked) {
- m_usingColorspaceElement = true;
-#ifdef DEBUG_PLAYBIN
- qDebug() << "Failed to connect video output, inserting the colorspace element.";
-#endif
- gst_bin_add(GST_BIN(m_videoOutputBin), m_colorSpace);
- linked = gst_element_link_many(m_videoIdentity, m_colorSpace, m_videoSink, nullptr);
- }
-#endif
-
- if (!linked)
- qWarning() << "Linking video output element failed";
-
- if (g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "show-preroll-frame") != 0) {
- gboolean value = m_displayPrerolledFrame;
- g_object_set(G_OBJECT(m_videoSink), "show-preroll-frame", value, nullptr);
- }
-
- addVideoBufferProbe();
-
- switch (m_pendingState) {
- case QMediaPlayer::PausedState:
- gst_element_set_state(m_playbin, GST_STATE_PAUSED);
- break;
- case QMediaPlayer::PlayingState:
- gst_element_set_state(m_playbin, GST_STATE_PLAYING);
- break;
- default:
- break;
- }
-
- resumeVideoProbes();
-
- } else {
- if (m_pendingVideoSink) {
-#ifdef DEBUG_PLAYBIN
- qDebug() << "already waiting for pad to be blocked, just change the pending sink";
-#endif
- m_pendingVideoSink = videoSink;
- return;
- }
-
- m_pendingVideoSink = videoSink;
-
-#ifdef DEBUG_PLAYBIN
- qDebug() << "Blocking the video output pad...";
-#endif
-
- //block pads, async to avoid locking in paused state
- GstPad *srcPad = gst_element_get_static_pad(m_videoIdentity, "src");
-#if GST_CHECK_VERSION(1,0,0)
- this->pad_probe_id = gst_pad_add_probe(srcPad, (GstPadProbeType)(GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BLOCKING), block_pad_cb, this, nullptr);
-#else
- gst_pad_set_blocked_async(srcPad, true, &block_pad_cb, this);
-#endif
- gst_object_unref(GST_OBJECT(srcPad));
-
- //Unpause the sink to avoid waiting until the buffer is processed
- //while the sink is paused. The pad will be blocked as soon as the current
- //buffer is processed.
- if (m_state == QMediaPlayer::PausedState) {
-#ifdef DEBUG_PLAYBIN
- qDebug() << "Starting video output to avoid blocking in paused state...";
-#endif
- gst_element_set_state(m_videoSink, GST_STATE_PLAYING);
- }
- }
-}
-
-void QGstreamerPlayerSession::finishVideoOutputChange()
-{
- if (!m_playbin || !m_pendingVideoSink)
- return;
-
-#ifdef DEBUG_PLAYBIN
- qDebug() << "finishVideoOutputChange" << m_pendingVideoSink;
-#endif
-
- GstPad *srcPad = gst_element_get_static_pad(m_videoIdentity, "src");
-
- if (!gst_pad_is_blocked(srcPad)) {
- //pad is not blocked, it's possible to swap outputs only in the null state
- qWarning() << "Pad is not blocked yet, could not switch video sink";
- GstState identityElementState = GST_STATE_NULL;
- gst_element_get_state(m_videoIdentity, &identityElementState, nullptr, GST_CLOCK_TIME_NONE);
- if (identityElementState != GST_STATE_NULL) {
- gst_object_unref(GST_OBJECT(srcPad));
- return; //can't change vo yet, received async call from the previous change
- }
- }
-
- if (m_pendingVideoSink == m_videoSink) {
- qDebug() << "Abort, no change";
- //video output was change back to the current one,
- //no need to torment the pipeline, just unblock the pad
- if (gst_pad_is_blocked(srcPad))
-#if GST_CHECK_VERSION(1,0,0)
- gst_pad_remove_probe(srcPad, this->pad_probe_id);
-#else
- gst_pad_set_blocked_async(srcPad, false, &block_pad_cb, 0);
-#endif
-
- m_pendingVideoSink = 0;
- gst_object_unref(GST_OBJECT(srcPad));
- return;
- }
-
-#if !GST_CHECK_VERSION(1,0,0)
- if (m_usingColorspaceElement) {
- gst_element_set_state(m_colorSpace, GST_STATE_NULL);
- gst_element_set_state(m_videoSink, GST_STATE_NULL);
-
- gst_element_unlink(m_colorSpace, m_videoSink);
- gst_bin_remove(GST_BIN(m_videoOutputBin), m_colorSpace);
- } else {
-#else
- {
-#endif
- gst_element_set_state(m_videoSink, GST_STATE_NULL);
- gst_element_unlink(m_videoIdentity, m_videoSink);
- }
-
- removeVideoBufferProbe();
-
- gst_bin_remove(GST_BIN(m_videoOutputBin), m_videoSink);
-
- m_videoSink = m_pendingVideoSink;
- m_pendingVideoSink = 0;
-
- gst_bin_add(GST_BIN(m_videoOutputBin), m_videoSink);
-
- addVideoBufferProbe();
-
- bool linked = gst_element_link(m_videoIdentity, m_videoSink);
-#if !GST_CHECK_VERSION(1,0,0)
- m_usingColorspaceElement = false;
- if (!linked) {
- m_usingColorspaceElement = true;
-#ifdef DEBUG_PLAYBIN
- qDebug() << "Failed to connect video output, inserting the colorspace element.";
-#endif
- gst_bin_add(GST_BIN(m_videoOutputBin), m_colorSpace);
- linked = gst_element_link_many(m_videoIdentity, m_colorSpace, m_videoSink, nullptr);
- }
-#endif
-
- if (!linked)
- qWarning() << "Linking video output element failed";
-
-#ifdef DEBUG_PLAYBIN
- qDebug() << "notify the video connector it has to emit a new segment message...";
-#endif
-
-#if !GST_CHECK_VERSION(1,0,0)
- //it's necessary to send a new segment event just before
- //the first buffer pushed to the new sink
- g_signal_emit_by_name(m_videoIdentity,
- "resend-new-segment",
- true //emit connection-failed signal
- //to have a chance to insert colorspace element
- );
-#endif
-
- GstState state = GST_STATE_VOID_PENDING;
-
- switch (m_pendingState) {
- case QMediaPlayer::StoppedState:
- state = GST_STATE_NULL;
- break;
- case QMediaPlayer::PausedState:
- state = GST_STATE_PAUSED;
- break;
- case QMediaPlayer::PlayingState:
- state = GST_STATE_PLAYING;
- break;
- }
-
-#if !GST_CHECK_VERSION(1,0,0)
- if (m_usingColorspaceElement)
- gst_element_set_state(m_colorSpace, state);
-#endif
-
- gst_element_set_state(m_videoSink, state);
-
- if (state == GST_STATE_NULL)
- flushVideoProbes();
-
- // Set state change that was deferred due the video output
- // change being pending
- gst_element_set_state(m_playbin, state);
-
- if (state != GST_STATE_NULL)
- resumeVideoProbes();
-
- //don't have to wait here, it will unblock eventually
- if (gst_pad_is_blocked(srcPad))
-#if GST_CHECK_VERSION(1,0,0)
- gst_pad_remove_probe(srcPad, this->pad_probe_id);
-#else
- gst_pad_set_blocked_async(srcPad, false, &block_pad_cb, 0);
-#endif
-
- gst_object_unref(GST_OBJECT(srcPad));
-
-}
-
-#if !GST_CHECK_VERSION(1,0,0)
-
-void QGstreamerPlayerSession::insertColorSpaceElement(GstElement *element, gpointer data)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
- Q_UNUSED(element);
- QGstreamerPlayerSession* session = reinterpret_cast<QGstreamerPlayerSession*>(data);
-
- if (session->m_usingColorspaceElement)
- return;
- session->m_usingColorspaceElement = true;
-
-#ifdef DEBUG_PLAYBIN
- qDebug() << "Failed to connect video output, inserting the colorspace elemnt.";
- qDebug() << "notify the video connector it has to emit a new segment message...";
-#endif
- //it's necessary to send a new segment event just before
- //the first buffer pushed to the new sink
- g_signal_emit_by_name(session->m_videoIdentity,
- "resend-new-segment",
- false // don't emit connection-failed signal
- );
-
- gst_element_unlink(session->m_videoIdentity, session->m_videoSink);
- gst_bin_add(GST_BIN(session->m_videoOutputBin), session->m_colorSpace);
- gst_element_link_many(session->m_videoIdentity, session->m_colorSpace, session->m_videoSink, nullptr);
-
- GstState state = GST_STATE_VOID_PENDING;
-
- switch (session->m_pendingState) {
- case QMediaPlayer::StoppedState:
- state = GST_STATE_NULL;
- break;
- case QMediaPlayer::PausedState:
- state = GST_STATE_PAUSED;
- break;
- case QMediaPlayer::PlayingState:
- state = GST_STATE_PLAYING;
- break;
- }
-
- gst_element_set_state(session->m_colorSpace, state);
-}
-
-#endif
-
-bool QGstreamerPlayerSession::isVideoAvailable() const
-{
- return m_videoAvailable;
-}
-
-bool QGstreamerPlayerSession::isSeekable() const
-{
- return m_seekable;
-}
-
-bool QGstreamerPlayerSession::play()
-{
-#if GST_CHECK_VERSION(1,0,0)
- static bool dumpDot = qEnvironmentVariableIsSet("GST_DEBUG_DUMP_DOT_DIR");
- if (dumpDot)
- gst_debug_bin_to_dot_file_with_ts(GST_BIN(m_pipeline), GstDebugGraphDetails(GST_DEBUG_GRAPH_SHOW_ALL), "gst.play");
-#endif
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
-
- m_everPlayed = false;
- if (m_pipeline) {
- m_pendingState = QMediaPlayer::PlayingState;
- if (gst_element_set_state(m_pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
- qWarning() << "GStreamer; Unable to play -" << m_request.url().toString();
- m_pendingState = m_state = QMediaPlayer::StoppedState;
- emit stateChanged(m_state);
- } else {
- resumeVideoProbes();
- return true;
- }
- }
-
- return false;
-}
-
-bool QGstreamerPlayerSession::pause()
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
- if (m_pipeline) {
- m_pendingState = QMediaPlayer::PausedState;
- if (m_pendingVideoSink != 0)
- return true;
-
- if (gst_element_set_state(m_pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE) {
- qWarning() << "GStreamer; Unable to pause -" << m_request.url().toString();
- m_pendingState = m_state = QMediaPlayer::StoppedState;
- emit stateChanged(m_state);
- } else {
- resumeVideoProbes();
- return true;
- }
- }
-
- return false;
-}
-
-void QGstreamerPlayerSession::stop()
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
- m_everPlayed = false;
- if (m_pipeline) {
-
- if (m_renderer)
- m_renderer->stopRenderer();
-
- flushVideoProbes();
- gst_element_set_state(m_pipeline, GST_STATE_NULL);
-
- m_lastPosition = 0;
- QMediaPlayer::State oldState = m_state;
- m_pendingState = m_state = QMediaPlayer::StoppedState;
-
- finishVideoOutputChange();
-
- //we have to do it here, since gstreamer will not emit bus messages any more
- setSeekable(false);
- if (oldState != m_state)
- emit stateChanged(m_state);
- }
-}
-
-bool QGstreamerPlayerSession::seek(qint64 ms)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << ms;
-#endif
- //seek locks when the video output sink is changing and pad is blocked
- if (m_pipeline && !m_pendingVideoSink && m_state != QMediaPlayer::StoppedState && m_seekable) {
- ms = qMax(ms,qint64(0));
- qint64 from = m_playbackRate > 0 ? ms : 0;
- qint64 to = m_playbackRate > 0 ? duration() : ms;
-
- bool isSeeking = gst_element_seek(m_pipeline, m_playbackRate, GST_FORMAT_TIME,
- GstSeekFlags(GST_SEEK_FLAG_FLUSH),
- GST_SEEK_TYPE_SET, from * 1000000,
- GST_SEEK_TYPE_SET, to * 1000000);
- if (isSeeking)
- m_lastPosition = ms;
-
- return isSeeking;
- }
-
- return false;
-}
-
-void QGstreamerPlayerSession::setVolume(int volume)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << volume;
-#endif
-
- if (m_volume != volume) {
- m_volume = volume;
-
- if (m_volumeElement)
- g_object_set(G_OBJECT(m_volumeElement), "volume", m_volume / 100.0, nullptr);
-
- emit volumeChanged(m_volume);
- }
-}
-
-void QGstreamerPlayerSession::setMuted(bool muted)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << muted;
-#endif
- if (m_muted != muted) {
- m_muted = muted;
-
- if (m_volumeElement)
- g_object_set(G_OBJECT(m_volumeElement), "mute", m_muted ? TRUE : FALSE, nullptr);
-
- emit mutedStateChanged(m_muted);
- }
-}
-
-
-void QGstreamerPlayerSession::setSeekable(bool seekable)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << seekable;
-#endif
- if (seekable != m_seekable) {
- m_seekable = seekable;
- emit seekableChanged(m_seekable);
- }
-}
-
-bool QGstreamerPlayerSession::processBusMessage(const QGstreamerMessage &message)
-{
- GstMessage* gm = message.rawMessage();
- if (gm) {
- //tag message comes from elements inside playbin, not from playbin itself
- if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_TAG) {
- GstTagList *tag_list;
- gst_message_parse_tag(gm, &tag_list);
-
- QMap<QByteArray, QVariant> newTags = QGstUtils::gstTagListToMap(tag_list);
- QMap<QByteArray, QVariant>::const_iterator it = newTags.constBegin();
- for ( ; it != newTags.constEnd(); ++it)
- m_tags.insert(it.key(), it.value()); // overwrite existing tags
-
- gst_tag_list_free(tag_list);
-
- emit tagsChanged();
- } else if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_DURATION) {
- updateDuration();
- }
-
-#ifdef DEBUG_PLAYBIN
- if (m_sourceType == MMSSrc && qstrcmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)), "source") == 0) {
- qDebug() << "Message from MMSSrc: " << GST_MESSAGE_TYPE(gm);
- } else if (m_sourceType == RTSPSrc && qstrcmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)), "source") == 0) {
- qDebug() << "Message from RTSPSrc: " << GST_MESSAGE_TYPE(gm);
- } else {
- qDebug() << "Message from " << GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)) << ":" << GST_MESSAGE_TYPE(gm);
- }
-#endif
-
- if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_BUFFERING) {
- int progress = 0;
- gst_message_parse_buffering(gm, &progress);
- emit bufferingProgressChanged(progress);
- }
-
- bool handlePlaybin2 = false;
- if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_pipeline)) {
- switch (GST_MESSAGE_TYPE(gm)) {
- case GST_MESSAGE_STATE_CHANGED:
- {
- GstState oldState;
- GstState newState;
- GstState pending;
-
- gst_message_parse_state_changed(gm, &oldState, &newState, &pending);
-
-#ifdef DEBUG_PLAYBIN
- static QStringList states = {
- QStringLiteral("GST_STATE_VOID_PENDING"), QStringLiteral("GST_STATE_NULL"),
- QStringLiteral("GST_STATE_READY"), QStringLiteral("GST_STATE_PAUSED"),
- QStringLiteral("GST_STATE_PLAYING") };
-
- qDebug() << QStringLiteral("state changed: old: %1 new: %2 pending: %3") \
- .arg(states[oldState]) \
- .arg(states[newState]) \
- .arg(states[pending]);
-#endif
-
- switch (newState) {
- case GST_STATE_VOID_PENDING:
- case GST_STATE_NULL:
- setSeekable(false);
- finishVideoOutputChange();
- if (m_state != QMediaPlayer::StoppedState)
- emit stateChanged(m_state = QMediaPlayer::StoppedState);
- break;
- case GST_STATE_READY:
- setSeekable(false);
- if (m_state != QMediaPlayer::StoppedState)
- emit stateChanged(m_state = QMediaPlayer::StoppedState);
- break;
- case GST_STATE_PAUSED:
- {
- QMediaPlayer::State prevState = m_state;
- m_state = QMediaPlayer::PausedState;
-
- //check for seekable
- if (oldState == GST_STATE_READY) {
- if (m_sourceType == SoupHTTPSrc || m_sourceType == MMSSrc) {
- //since udpsrc is a live source, it is not applicable here
- m_everPlayed = true;
- }
-
- getStreamsInfo();
- updateVideoResolutionTag();
-
- //gstreamer doesn't give a reliable indication the duration
- //information is ready, GST_MESSAGE_DURATION is not sent by most elements
- //the duration is queried up to 5 times with increasing delay
- m_durationQueries = 5;
- // This should also update the seekable flag.
- updateDuration();
-
- if (!qFuzzyCompare(m_playbackRate, qreal(1.0))) {
- qreal rate = m_playbackRate;
- m_playbackRate = 1.0;
- setPlaybackRate(rate);
- }
- }
-
- if (m_state != prevState)
- emit stateChanged(m_state);
-
- break;
- }
- case GST_STATE_PLAYING:
- m_everPlayed = true;
- if (m_state != QMediaPlayer::PlayingState) {
- emit stateChanged(m_state = QMediaPlayer::PlayingState);
-
- // For rtsp streams duration information might not be available
- // until playback starts.
- if (m_duration <= 0) {
- m_durationQueries = 5;
- updateDuration();
- }
- }
-
- break;
- }
- }
- break;
-
- case GST_MESSAGE_EOS:
- emit playbackFinished();
- break;
-
- case GST_MESSAGE_TAG:
- case GST_MESSAGE_STREAM_STATUS:
- case GST_MESSAGE_UNKNOWN:
- break;
- case GST_MESSAGE_ERROR: {
- GError *err;
- gchar *debug;
- gst_message_parse_error(gm, &err, &debug);
- if (err->domain == GST_STREAM_ERROR && err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND)
- processInvalidMedia(QMediaPlayer::FormatError, tr("Cannot play stream of type: <unknown>"));
- else
- processInvalidMedia(QMediaPlayer::ResourceError, QString::fromUtf8(err->message));
- qWarning() << "Error:" << QString::fromUtf8(err->message);
- g_error_free(err);
- g_free(debug);
- }
- break;
- case GST_MESSAGE_WARNING:
- {
- GError *err;
- gchar *debug;
- gst_message_parse_warning (gm, &err, &debug);
- qWarning() << "Warning:" << QString::fromUtf8(err->message);
- g_error_free (err);
- g_free (debug);
- }
- break;
- case GST_MESSAGE_INFO:
-#ifdef DEBUG_PLAYBIN
- {
- GError *err;
- gchar *debug;
- gst_message_parse_info (gm, &err, &debug);
- qDebug() << "Info:" << QString::fromUtf8(err->message);
- g_error_free (err);
- g_free (debug);
- }
-#endif
- break;
- case GST_MESSAGE_BUFFERING:
- case GST_MESSAGE_STATE_DIRTY:
- case GST_MESSAGE_STEP_DONE:
- case GST_MESSAGE_CLOCK_PROVIDE:
- case GST_MESSAGE_CLOCK_LOST:
- case GST_MESSAGE_NEW_CLOCK:
- case GST_MESSAGE_STRUCTURE_CHANGE:
- case GST_MESSAGE_APPLICATION:
- case GST_MESSAGE_ELEMENT:
- break;
- case GST_MESSAGE_SEGMENT_START:
- {
- const GstStructure *structure = gst_message_get_structure(gm);
- qint64 position = g_value_get_int64(gst_structure_get_value(structure, "position"));
- position /= 1000000;
- m_lastPosition = position;
- emit positionChanged(position);
- }
- break;
- case GST_MESSAGE_SEGMENT_DONE:
- break;
- case GST_MESSAGE_LATENCY:
-#if GST_CHECK_VERSION(0,10,13)
- case GST_MESSAGE_ASYNC_START:
- break;
- case GST_MESSAGE_ASYNC_DONE:
- {
- gint64 position = 0;
- if (qt_gst_element_query_position(m_pipeline, GST_FORMAT_TIME, &position)) {
- position /= 1000000;
- m_lastPosition = position;
- emit positionChanged(position);
- }
- break;
- }
-#if GST_CHECK_VERSION(0,10,23)
- case GST_MESSAGE_REQUEST_STATE:
-#endif
-#endif
- case GST_MESSAGE_ANY:
- break;
- default:
- break;
- }
- } else if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ERROR) {
- GError *err;
- gchar *debug;
- gst_message_parse_error(gm, &err, &debug);
- // If the source has given up, so do we.
- if (qstrcmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)), "source") == 0) {
- bool everPlayed = m_everPlayed;
- // Try and differentiate network related resource errors from the others
- if (!m_request.url().isRelative() && m_request.url().scheme().compare(QLatin1String("file"), Qt::CaseInsensitive) != 0 ) {
- if (everPlayed ||
- (err->domain == GST_RESOURCE_ERROR && (
- err->code == GST_RESOURCE_ERROR_BUSY ||
- err->code == GST_RESOURCE_ERROR_OPEN_READ ||
- err->code == GST_RESOURCE_ERROR_READ ||
- err->code == GST_RESOURCE_ERROR_SEEK ||
- err->code == GST_RESOURCE_ERROR_SYNC))) {
- processInvalidMedia(QMediaPlayer::NetworkError, QString::fromUtf8(err->message));
- } else {
- processInvalidMedia(QMediaPlayer::ResourceError, QString::fromUtf8(err->message));
- }
- }
- else
- processInvalidMedia(QMediaPlayer::ResourceError, QString::fromUtf8(err->message));
- } else if (err->domain == GST_STREAM_ERROR
- && (err->code == GST_STREAM_ERROR_DECRYPT || err->code == GST_STREAM_ERROR_DECRYPT_NOKEY)) {
- processInvalidMedia(QMediaPlayer::AccessDeniedError, QString::fromUtf8(err->message));
- } else {
- handlePlaybin2 = true;
- }
- if (!handlePlaybin2)
- qWarning() << "Error:" << QString::fromUtf8(err->message);
- g_error_free(err);
- g_free(debug);
- } else if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT
- && qstrcmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)), "source") == 0
- && m_sourceType == UDPSrc
- && gst_structure_has_name(gst_message_get_structure(gm), "GstUDPSrcTimeout")) {
- //since udpsrc will not generate an error for the timeout event,
- //we need to process its element message here and treat it as an error.
- processInvalidMedia(m_everPlayed ? QMediaPlayer::NetworkError : QMediaPlayer::ResourceError,
- tr("UDP source timeout"));
- } else {
- handlePlaybin2 = true;
- }
-
- if (handlePlaybin2) {
- if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_WARNING) {
- GError *err;
- gchar *debug;
- gst_message_parse_warning(gm, &err, &debug);
- if (err->domain == GST_STREAM_ERROR && err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND)
- emit error(int(QMediaPlayer::FormatError), tr("Cannot play stream of type: <unknown>"));
- // GStreamer shows warning for HTTP playlists
- if (err && err->message)
- qWarning() << "Warning:" << QString::fromUtf8(err->message);
- g_error_free(err);
- g_free(debug);
- } else if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ERROR) {
- GError *err;
- gchar *debug;
- gst_message_parse_error(gm, &err, &debug);
-
- // Nearly all errors map to ResourceError
- QMediaPlayer::Error qerror = QMediaPlayer::ResourceError;
- if (err->domain == GST_STREAM_ERROR
- && (err->code == GST_STREAM_ERROR_DECRYPT
- || err->code == GST_STREAM_ERROR_DECRYPT_NOKEY)) {
- qerror = QMediaPlayer::AccessDeniedError;
- }
- processInvalidMedia(qerror, QString::fromUtf8(err->message));
- if (err && err->message)
- qWarning() << "Error:" << QString::fromUtf8(err->message);
-
- g_error_free(err);
- g_free(debug);
- }
- }
- }
-
- return false;
-}
-
-void QGstreamerPlayerSession::getStreamsInfo()
-{
- if (!m_playbin)
- return;
-
- QList< QMap<QString,QVariant> > oldProperties = m_streamProperties;
- QList<QMediaStreamsControl::StreamType> oldTypes = m_streamTypes;
- QMap<QMediaStreamsControl::StreamType, int> oldOffset = m_playbin2StreamOffset;
-
- //check if video is available:
- bool haveAudio = false;
- bool haveVideo = false;
- m_streamProperties.clear();
- m_streamTypes.clear();
- m_playbin2StreamOffset.clear();
-
- gint audioStreamsCount = 0;
- gint videoStreamsCount = 0;
- gint textStreamsCount = 0;
-
- g_object_get(G_OBJECT(m_playbin), "n-audio", &audioStreamsCount, nullptr);
- g_object_get(G_OBJECT(m_playbin), "n-video", &videoStreamsCount, nullptr);
- g_object_get(G_OBJECT(m_playbin), "n-text", &textStreamsCount, nullptr);
-
- haveAudio = audioStreamsCount > 0;
- haveVideo = videoStreamsCount > 0;
-
- m_playbin2StreamOffset[QMediaStreamsControl::AudioStream] = 0;
- m_playbin2StreamOffset[QMediaStreamsControl::VideoStream] = audioStreamsCount;
- m_playbin2StreamOffset[QMediaStreamsControl::SubPictureStream] = audioStreamsCount+videoStreamsCount;
-
- for (int i=0; i<audioStreamsCount; i++)
- m_streamTypes.append(QMediaStreamsControl::AudioStream);
-
- for (int i=0; i<videoStreamsCount; i++)
- m_streamTypes.append(QMediaStreamsControl::VideoStream);
-
- for (int i=0; i<textStreamsCount; i++)
- m_streamTypes.append(QMediaStreamsControl::SubPictureStream);
-
- for (int i=0; i<m_streamTypes.count(); i++) {
- QMediaStreamsControl::StreamType streamType = m_streamTypes[i];
- QMap<QString, QVariant> streamProperties;
-
- int streamIndex = i - m_playbin2StreamOffset[streamType];
-
- GstTagList *tags = 0;
- switch (streamType) {
- case QMediaStreamsControl::AudioStream:
- g_signal_emit_by_name(G_OBJECT(m_playbin), "get-audio-tags", streamIndex, &tags);
- break;
- case QMediaStreamsControl::VideoStream:
- g_signal_emit_by_name(G_OBJECT(m_playbin), "get-video-tags", streamIndex, &tags);
- break;
- case QMediaStreamsControl::SubPictureStream:
- g_signal_emit_by_name(G_OBJECT(m_playbin), "get-text-tags", streamIndex, &tags);
- break;
- default:
- break;
- }
-#if GST_CHECK_VERSION(1,0,0)
- if (tags && GST_IS_TAG_LIST(tags)) {
-#else
- if (tags && gst_is_tag_list(tags)) {
-#endif
- gchar *languageCode = 0;
- if (gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &languageCode))
- streamProperties[QMediaMetaData::Language] = QString::fromUtf8(languageCode);
-
- //qDebug() << "language for setream" << i << QString::fromUtf8(languageCode);
- g_free (languageCode);
- gst_tag_list_free(tags);
- }
-
- m_streamProperties.append(streamProperties);
- }
-
- bool emitAudioChanged = (haveAudio != m_audioAvailable);
- bool emitVideoChanged = (haveVideo != m_videoAvailable);
-
- m_audioAvailable = haveAudio;
- m_videoAvailable = haveVideo;
-
- if (emitAudioChanged) {
- emit audioAvailableChanged(m_audioAvailable);
- }
- if (emitVideoChanged) {
- emit videoAvailableChanged(m_videoAvailable);
- }
-
- if (oldProperties != m_streamProperties || oldTypes != m_streamTypes || oldOffset != m_playbin2StreamOffset)
- emit streamsChanged();
-}
-
-void QGstreamerPlayerSession::updateVideoResolutionTag()
-{
- if (!m_videoIdentity)
- return;
-
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
- QSize size;
- QSize aspectRatio;
- GstPad *pad = gst_element_get_static_pad(m_videoIdentity, "src");
- GstCaps *caps = qt_gst_pad_get_current_caps(pad);
-
- if (caps) {
- const GstStructure *structure = gst_caps_get_structure(caps, 0);
- gst_structure_get_int(structure, "width", &size.rwidth());
- gst_structure_get_int(structure, "height", &size.rheight());
-
- gint aspectNum = 0;
- gint aspectDenum = 0;
- if (!size.isEmpty() && gst_structure_get_fraction(
- structure, "pixel-aspect-ratio", &aspectNum, &aspectDenum)) {
- if (aspectDenum > 0)
- aspectRatio = QSize(aspectNum, aspectDenum);
- }
- gst_caps_unref(caps);
- }
-
- gst_object_unref(GST_OBJECT(pad));
-
- QSize currentSize = m_tags.value("resolution").toSize();
- QSize currentAspectRatio = m_tags.value("pixel-aspect-ratio").toSize();
-
- if (currentSize != size || currentAspectRatio != aspectRatio) {
- if (aspectRatio.isEmpty())
- m_tags.remove("pixel-aspect-ratio");
-
- if (size.isEmpty()) {
- m_tags.remove("resolution");
- } else {
- m_tags.insert("resolution", QVariant(size));
- if (!aspectRatio.isEmpty())
- m_tags.insert("pixel-aspect-ratio", QVariant(aspectRatio));
- }
-
- emit tagsChanged();
- }
-}
-
-void QGstreamerPlayerSession::updateDuration()
-{
- gint64 gstDuration = 0;
- int duration = 0;
-
- if (m_pipeline && qt_gst_element_query_duration(m_pipeline, GST_FORMAT_TIME, &gstDuration))
- duration = gstDuration / 1000000;
-
- if (m_duration != duration) {
- m_duration = duration;
- emit durationChanged(m_duration);
- }
-
- gboolean seekable = false;
- if (m_duration > 0) {
- m_durationQueries = 0;
- GstQuery *query = gst_query_new_seeking(GST_FORMAT_TIME);
- if (gst_element_query(m_pipeline, query))
- gst_query_parse_seeking(query, 0, &seekable, 0, 0);
- gst_query_unref(query);
- }
- setSeekable(seekable);
-
- if (m_durationQueries > 0) {
- //increase delay between duration requests
- int delay = 25 << (5 - m_durationQueries);
- QTimer::singleShot(delay, this, SLOT(updateDuration()));
- m_durationQueries--;
- }
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << m_duration;
-#endif
-}
-
-void QGstreamerPlayerSession::playbinNotifySource(GObject *o, GParamSpec *p, gpointer d)
-{
- Q_UNUSED(p);
-
- GstElement *source = 0;
- g_object_get(o, "source", &source, nullptr);
- if (source == 0)
- return;
-
-#ifdef DEBUG_PLAYBIN
- qDebug() << "Playbin source added:" << G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source));
-#endif
-
- // Set Headers
- const QByteArray userAgentString("User-Agent");
-
- QGstreamerPlayerSession *self = reinterpret_cast<QGstreamerPlayerSession *>(d);
-
- // User-Agent - special case, souphhtpsrc will always set something, even if
- // defined in extra-headers
- if (g_object_class_find_property(G_OBJECT_GET_CLASS(source), "user-agent") != 0) {
- g_object_set(G_OBJECT(source), "user-agent",
- self->m_request.rawHeader(userAgentString).constData(), nullptr);
- }
-
- // The rest
- if (g_object_class_find_property(G_OBJECT_GET_CLASS(source), "extra-headers") != 0) {
- GstStructure *extras = qt_gst_structure_new_empty("extras");
-
- const auto rawHeaderList = self->m_request.rawHeaderList();
- for (const QByteArray &rawHeader : rawHeaderList) {
- if (rawHeader == userAgentString) // Filter User-Agent
- continue;
- else {
- GValue headerValue;
-
- memset(&headerValue, 0, sizeof(GValue));
- g_value_init(&headerValue, G_TYPE_STRING);
-
- g_value_set_string(&headerValue,
- self->m_request.rawHeader(rawHeader).constData());
-
- gst_structure_set_value(extras, rawHeader.constData(), &headerValue);
- }
- }
-
- if (gst_structure_n_fields(extras) > 0)
- g_object_set(G_OBJECT(source), "extra-headers", extras, nullptr);
-
- gst_structure_free(extras);
- }
-
- //set timeout property to 30 seconds
- const int timeout = 30;
- if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstUDPSrc") == 0) {
- quint64 convertedTimeout = timeout;
-#if GST_CHECK_VERSION(1,0,0)
- // Gst 1.x -> nanosecond
- convertedTimeout *= 1000000000;
-#else
- // Gst 0.10 -> microsecond
- convertedTimeout *= 1000000;
-#endif
- g_object_set(G_OBJECT(source), "timeout", convertedTimeout, nullptr);
- self->m_sourceType = UDPSrc;
- //The udpsrc is always a live source.
- self->m_isLiveSource = true;
-
- QUrlQuery query(self->m_request.url());
- const QString var = QLatin1String("udpsrc.caps");
- if (query.hasQueryItem(var)) {
- GstCaps *caps = gst_caps_from_string(query.queryItemValue(var).toLatin1().constData());
- g_object_set(G_OBJECT(source), "caps", caps, nullptr);
- gst_caps_unref(caps);
- }
- } else if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstSoupHTTPSrc") == 0) {
- //souphttpsrc timeout unit = second
- g_object_set(G_OBJECT(source), "timeout", guint(timeout), nullptr);
- self->m_sourceType = SoupHTTPSrc;
- //since gst_base_src_is_live is not reliable, so we check the source property directly
- gboolean isLive = false;
- g_object_get(G_OBJECT(source), "is-live", &isLive, nullptr);
- self->m_isLiveSource = isLive;
- } else if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstMMSSrc") == 0) {
- self->m_sourceType = MMSSrc;
- self->m_isLiveSource = gst_base_src_is_live(GST_BASE_SRC(source));
- g_object_set(G_OBJECT(source), "tcp-timeout", G_GUINT64_CONSTANT(timeout*1000000), nullptr);
- } else if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstRTSPSrc") == 0) {
- //rtspsrc acts like a live source and will therefore only generate data in the PLAYING state.
- self->m_sourceType = RTSPSrc;
- self->m_isLiveSource = true;
- g_object_set(G_OBJECT(source), "buffer-mode", 1, nullptr);
- } else {
- self->m_sourceType = UnknownSrc;
- self->m_isLiveSource = gst_base_src_is_live(GST_BASE_SRC(source));
- }
-
-#ifdef DEBUG_PLAYBIN
- if (self->m_isLiveSource)
- qDebug() << "Current source is a live source";
- else
- qDebug() << "Current source is a non-live source";
-#endif
-
- if (self->m_videoSink)
- g_object_set(G_OBJECT(self->m_videoSink), "sync", !self->m_isLiveSource, nullptr);
-
- gst_object_unref(source);
-}
-
-bool QGstreamerPlayerSession::isLiveSource() const
-{
- return m_isLiveSource;
-}
-
-void QGstreamerPlayerSession::handleVolumeChange(GObject *o, GParamSpec *p, gpointer d)
-{
- Q_UNUSED(o);
- Q_UNUSED(p);
- QGstreamerPlayerSession *session = reinterpret_cast<QGstreamerPlayerSession *>(d);
- QMetaObject::invokeMethod(session, "updateVolume", Qt::QueuedConnection);
-}
-
-void QGstreamerPlayerSession::updateVolume()
-{
- double volume = 1.0;
- g_object_get(m_playbin, "volume", &volume, nullptr);
-
- if (m_volume != int(volume*100 + 0.5)) {
- m_volume = int(volume*100 + 0.5);
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << m_volume;
-#endif
- emit volumeChanged(m_volume);
- }
-}
-
-void QGstreamerPlayerSession::handleMutedChange(GObject *o, GParamSpec *p, gpointer d)
-{
- Q_UNUSED(o);
- Q_UNUSED(p);
- QGstreamerPlayerSession *session = reinterpret_cast<QGstreamerPlayerSession *>(d);
- QMetaObject::invokeMethod(session, "updateMuted", Qt::QueuedConnection);
-}
-
-void QGstreamerPlayerSession::updateMuted()
-{
- gboolean muted = FALSE;
- g_object_get(G_OBJECT(m_playbin), "mute", &muted, nullptr);
- if (m_muted != muted) {
- m_muted = muted;
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << m_muted;
-#endif
- emit mutedStateChanged(muted);
- }
-}
-
-#if !GST_CHECK_VERSION(0, 10, 33)
-static gboolean factory_can_src_any_caps (GstElementFactory *factory, const GstCaps *caps)
-{
- GList *templates;
-
- g_return_val_if_fail(factory != nullptr, FALSE);
- g_return_val_if_fail(caps != nullptr, FALSE);
-
- templates = factory->staticpadtemplates;
-
- while (templates) {
- GstStaticPadTemplate *templ = (GstStaticPadTemplate *)templates->data;
-
- if (templ->direction == GST_PAD_SRC) {
- GstCaps *templcaps = gst_static_caps_get(&templ->static_caps);
-
- if (qt_gst_caps_can_intersect(caps, templcaps)) {
- gst_caps_unref(templcaps);
- return TRUE;
- }
- gst_caps_unref(templcaps);
- }
- templates = g_list_next(templates);
- }
-
- return FALSE;
-}
-#endif
-
-GstAutoplugSelectResult QGstreamerPlayerSession::handleAutoplugSelect(GstBin *bin, GstPad *pad, GstCaps *caps, GstElementFactory *factory, QGstreamerPlayerSession *session)
-{
- Q_UNUSED(bin);
- Q_UNUSED(pad);
- Q_UNUSED(caps);
-
- GstAutoplugSelectResult res = GST_AUTOPLUG_SELECT_TRY;
-
- // if VAAPI is available and can be used to decode but the current video sink cannot handle
- // the decoded format, don't use it
- const gchar *factoryName = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory));
- if (g_str_has_prefix(factoryName, "vaapi")) {
- GstPad *sinkPad = gst_element_get_static_pad(session->m_videoSink, "sink");
-#if GST_CHECK_VERSION(1,0,0)
- GstCaps *sinkCaps = gst_pad_query_caps(sinkPad, nullptr);
-#else
- GstCaps *sinkCaps = gst_pad_get_caps(sinkPad);
-#endif
-
-#if !GST_CHECK_VERSION(0, 10, 33)
- if (!factory_can_src_any_caps(factory, sinkCaps))
-#else
- if (!gst_element_factory_can_src_any_caps(factory, sinkCaps))
-#endif
- res = GST_AUTOPLUG_SELECT_SKIP;
-
- gst_object_unref(sinkPad);
- gst_caps_unref(sinkCaps);
- }
-
- return res;
-}
-
-void QGstreamerPlayerSession::handleElementAdded(GstBin *bin, GstElement *element, QGstreamerPlayerSession *session)
-{
- Q_UNUSED(bin);
- //we have to configure queue2 element to enable media downloading
- //and reporting available ranges,
- //but it's added dynamically to playbin2
-
- gchar *elementName = gst_element_get_name(element);
-
- if (g_str_has_prefix(elementName, "queue2")) {
- // Disable on-disk buffering.
- g_object_set(G_OBJECT(element), "temp-template", nullptr, nullptr);
- } else if (g_str_has_prefix(elementName, "uridecodebin") ||
-#if GST_CHECK_VERSION(1,0,0)
- g_str_has_prefix(elementName, "decodebin")) {
-#else
- g_str_has_prefix(elementName, "decodebin2")) {
- if (g_str_has_prefix(elementName, "uridecodebin")) {
- // Add video/x-surface (VAAPI) to default raw formats
- g_object_set(G_OBJECT(element), "caps", gst_static_caps_get(&static_RawCaps), nullptr);
- // listen for uridecodebin autoplug-select to skip VAAPI usage when the current
- // video sink doesn't support it
- g_signal_connect(element, "autoplug-select", G_CALLBACK(handleAutoplugSelect), session);
- }
-#endif
- //listen for queue2 element added to uridecodebin/decodebin2 as well.
- //Don't touch other bins since they may have unrelated queues
- g_signal_connect(element, "element-added",
- G_CALLBACK(handleElementAdded), session);
- }
-
- g_free(elementName);
-}
-
-void QGstreamerPlayerSession::handleStreamsChange(GstBin *bin, gpointer user_data)
-{
- Q_UNUSED(bin);
-
- QGstreamerPlayerSession* session = reinterpret_cast<QGstreamerPlayerSession*>(user_data);
- QMetaObject::invokeMethod(session, "getStreamsInfo", Qt::QueuedConnection);
-}
-
-//doing proper operations when detecting an invalidMedia: change media status before signal the erorr
-void QGstreamerPlayerSession::processInvalidMedia(QMediaPlayer::Error errorCode, const QString& errorString)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO;
-#endif
- emit invalidMedia();
- stop();
- emit error(int(errorCode), errorString);
-}
-
-void QGstreamerPlayerSession::showPrerollFrames(bool enabled)
-{
-#ifdef DEBUG_PLAYBIN
- qDebug() << Q_FUNC_INFO << enabled;
-#endif
- if (enabled != m_displayPrerolledFrame && m_videoSink &&
- g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "show-preroll-frame") != 0) {
-
- gboolean value = enabled;
- g_object_set(G_OBJECT(m_videoSink), "show-preroll-frame", value, nullptr);
- m_displayPrerolledFrame = enabled;
- }
-}
-
-void QGstreamerPlayerSession::addProbe(QGstreamerVideoProbeControl* probe)
-{
- Q_ASSERT(!m_videoProbe);
- m_videoProbe = probe;
- addVideoBufferProbe();
-}
-
-void QGstreamerPlayerSession::removeProbe(QGstreamerVideoProbeControl* probe)
-{
- Q_ASSERT(m_videoProbe == probe);
- removeVideoBufferProbe();
- m_videoProbe = 0;
-}
-
-void QGstreamerPlayerSession::addProbe(QGstreamerAudioProbeControl* probe)
-{
- Q_ASSERT(!m_audioProbe);
- m_audioProbe = probe;
- addAudioBufferProbe();
-}
-
-void QGstreamerPlayerSession::removeProbe(QGstreamerAudioProbeControl* probe)
-{
- Q_ASSERT(m_audioProbe == probe);
- removeAudioBufferProbe();
- m_audioProbe = 0;
-}
-
-// This function is similar to stop(),
-// but does not set m_everPlayed, m_lastPosition,
-// and setSeekable() values.
-void QGstreamerPlayerSession::endOfMediaReset()
-{
- if (m_renderer)
- m_renderer->stopRenderer();
-
- flushVideoProbes();
- gst_element_set_state(m_pipeline, GST_STATE_PAUSED);
-
- QMediaPlayer::State oldState = m_state;
- m_pendingState = m_state = QMediaPlayer::StoppedState;
-
- finishVideoOutputChange();
-
- if (oldState != m_state)
- emit stateChanged(m_state);
-}
-
-void QGstreamerPlayerSession::removeVideoBufferProbe()
-{
- if (!m_videoProbe)
- return;
-
- GstPad *pad = gst_element_get_static_pad(m_videoSink, "sink");
- if (pad) {
- m_videoProbe->removeProbeFromPad(pad);
- gst_object_unref(GST_OBJECT(pad));
- }
-}
-
-void QGstreamerPlayerSession::addVideoBufferProbe()
-{
- if (!m_videoProbe)
- return;
-
- GstPad *pad = gst_element_get_static_pad(m_videoSink, "sink");
- if (pad) {
- m_videoProbe->addProbeToPad(pad);
- gst_object_unref(GST_OBJECT(pad));
- }
-}
-
-void QGstreamerPlayerSession::removeAudioBufferProbe()
-{
- if (!m_audioProbe)
- return;
-
- GstPad *pad = gst_element_get_static_pad(m_audioSink, "sink");
- if (pad) {
- m_audioProbe->removeProbeFromPad(pad);
- gst_object_unref(GST_OBJECT(pad));
- }
-}
-
-void QGstreamerPlayerSession::addAudioBufferProbe()
-{
- if (!m_audioProbe)
- return;
-
- GstPad *pad = gst_element_get_static_pad(m_audioSink, "sink");
- if (pad) {
- m_audioProbe->addProbeToPad(pad);
- gst_object_unref(GST_OBJECT(pad));
- }
-}
-
-void QGstreamerPlayerSession::flushVideoProbes()
-{
- if (m_videoProbe)
- m_videoProbe->startFlushing();
-}
-
-void QGstreamerPlayerSession::resumeVideoProbes()
-{
- if (m_videoProbe)
- m_videoProbe->stopFlushing();
-}
-
-QT_END_NAMESPACE
diff --git a/src/gsttools/qgstreamerplayersession_p.h b/src/gsttools/qgstreamerplayersession_p.h
deleted file mode 100644
index 797229e69..000000000
--- a/src/gsttools/qgstreamerplayersession_p.h
+++ /dev/null
@@ -1,284 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERPLAYERSESSION_P_H
-#define QGSTREAMERPLAYERSESSION_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <QObject>
-#include <QtCore/qmutex.h>
-#include <QtNetwork/qnetworkrequest.h>
-#include <private/qgstreamerplayercontrol_p.h>
-#include <private/qgstreamerbushelper_p.h>
-#include <qmediaplayer.h>
-#include <qmediastreamscontrol.h>
-#include <qaudioformat.h>
-
-#if QT_CONFIG(gstreamer_app)
-#include <private/qgstappsrc_p.h>
-#endif
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerBusHelper;
-class QGstreamerMessage;
-
-class QGstreamerVideoRendererInterface;
-class QGstreamerVideoProbeControl;
-class QGstreamerAudioProbeControl;
-
-typedef enum {
- GST_AUTOPLUG_SELECT_TRY,
- GST_AUTOPLUG_SELECT_EXPOSE,
- GST_AUTOPLUG_SELECT_SKIP
-} GstAutoplugSelectResult;
-
-class Q_GSTTOOLS_EXPORT QGstreamerPlayerSession
- : public QObject
- , public QGstreamerBusMessageFilter
-{
-Q_OBJECT
-Q_INTERFACES(QGstreamerBusMessageFilter)
-
-public:
- QGstreamerPlayerSession(QObject *parent);
- virtual ~QGstreamerPlayerSession();
-
- GstElement *playbin() const;
- GstElement *pipeline() const { return m_pipeline; }
- QGstreamerBusHelper *bus() const { return m_busHelper; }
-
- QNetworkRequest request() const;
-
- QMediaPlayer::State state() const { return m_state; }
- QMediaPlayer::State pendingState() const { return m_pendingState; }
-
- qint64 duration() const;
- qint64 position() const;
-
- int volume() const;
- bool isMuted() const;
-
- bool isAudioAvailable() const;
-
- void setVideoRenderer(QObject *renderer);
- QGstreamerVideoRendererInterface *renderer() const { return m_renderer; }
- bool isVideoAvailable() const;
-
- bool isSeekable() const;
-
- qreal playbackRate() const;
- void setPlaybackRate(qreal rate);
-
- QMediaTimeRange availablePlaybackRanges() const;
-
- QMap<QByteArray ,QVariant> tags() const { return m_tags; }
- QMap<QString,QVariant> streamProperties(int streamNumber) const { return m_streamProperties[streamNumber]; }
- int streamCount() const { return m_streamProperties.count(); }
- QMediaStreamsControl::StreamType streamType(int streamNumber) { return m_streamTypes.value(streamNumber, QMediaStreamsControl::UnknownStream); }
-
- int activeStream(QMediaStreamsControl::StreamType streamType) const;
- void setActiveStream(QMediaStreamsControl::StreamType streamType, int streamNumber);
-
- bool processBusMessage(const QGstreamerMessage &message) override;
-
-#if QT_CONFIG(gstreamer_app)
- QGstAppSrc *appsrc() const { return m_appSrc; }
- static void configureAppSrcElement(GObject*, GObject*, GParamSpec*,QGstreamerPlayerSession* _this);
-#endif
-
- bool isLiveSource() const;
-
- void addProbe(QGstreamerVideoProbeControl* probe);
- void removeProbe(QGstreamerVideoProbeControl* probe);
-
- void addProbe(QGstreamerAudioProbeControl* probe);
- void removeProbe(QGstreamerAudioProbeControl* probe);
-
- void endOfMediaReset();
-
-public slots:
- void loadFromUri(const QNetworkRequest &url);
- void loadFromStream(const QNetworkRequest &url, QIODevice *stream);
- bool play();
- bool pause();
- void stop();
-
- bool seek(qint64 pos);
-
- void setVolume(int volume);
- void setMuted(bool muted);
-
- void showPrerollFrames(bool enabled);
-
-signals:
- void durationChanged(qint64 duration);
- void positionChanged(qint64 position);
- void stateChanged(QMediaPlayer::State state);
- void volumeChanged(int volume);
- void mutedStateChanged(bool muted);
- void audioAvailableChanged(bool audioAvailable);
- void videoAvailableChanged(bool videoAvailable);
- void bufferingProgressChanged(int percentFilled);
- void playbackFinished();
- void tagsChanged();
- void streamsChanged();
- void seekableChanged(bool);
- void error(int error, const QString &errorString);
- void invalidMedia();
- void playbackRateChanged(qreal);
- void rendererChanged();
- void pipelineChanged();
-
-private slots:
- void getStreamsInfo();
- void setSeekable(bool);
- void finishVideoOutputChange();
- void updateVideoRenderer();
- void updateVideoResolutionTag();
- void updateVolume();
- void updateMuted();
- void updateDuration();
-
-private:
- static void playbinNotifySource(GObject *o, GParamSpec *p, gpointer d);
- static void handleVolumeChange(GObject *o, GParamSpec *p, gpointer d);
- static void handleMutedChange(GObject *o, GParamSpec *p, gpointer d);
-#if !GST_CHECK_VERSION(1,0,0)
- static void insertColorSpaceElement(GstElement *element, gpointer data);
-#endif
- static void handleElementAdded(GstBin *bin, GstElement *element, QGstreamerPlayerSession *session);
- static void handleStreamsChange(GstBin *bin, gpointer user_data);
- static GstAutoplugSelectResult handleAutoplugSelect(GstBin *bin, GstPad *pad, GstCaps *caps, GstElementFactory *factory, QGstreamerPlayerSession *session);
-
- void processInvalidMedia(QMediaPlayer::Error errorCode, const QString& errorString);
-
- void removeVideoBufferProbe();
- void addVideoBufferProbe();
- void removeAudioBufferProbe();
- void addAudioBufferProbe();
- void flushVideoProbes();
- void resumeVideoProbes();
- bool parsePipeline();
- bool setPipeline(GstElement *pipeline);
- void resetElements();
- void initPlaybin();
- void setBus(GstBus *bus);
-
- QNetworkRequest m_request;
- QMediaPlayer::State m_state = QMediaPlayer::StoppedState;
- QMediaPlayer::State m_pendingState = QMediaPlayer::StoppedState;
- QGstreamerBusHelper *m_busHelper = nullptr;
- GstElement *m_playbin = nullptr;
- GstElement *m_pipeline = nullptr;
-
- GstElement *m_videoSink = nullptr;
-
- GstElement *m_videoOutputBin = nullptr;
- GstElement *m_videoIdentity = nullptr;
-#if !GST_CHECK_VERSION(1,0,0)
- GstElement *m_colorSpace = nullptr;
- bool m_usingColorspaceElement = false;
-#endif
- GstElement *m_pendingVideoSink = nullptr;
- GstElement *m_nullVideoSink = nullptr;
-
- GstElement *m_audioSink = nullptr;
- GstElement *m_volumeElement = nullptr;
-
- GstBus *m_bus = nullptr;
- QObject *m_videoOutput = nullptr;
- QGstreamerVideoRendererInterface *m_renderer = nullptr;
-
-#if QT_CONFIG(gstreamer_app)
- QGstAppSrc *m_appSrc = nullptr;
-#endif
-
- QMap<QByteArray, QVariant> m_tags;
- QList< QMap<QString,QVariant> > m_streamProperties;
- QList<QMediaStreamsControl::StreamType> m_streamTypes;
- QMap<QMediaStreamsControl::StreamType, int> m_playbin2StreamOffset;
-
- QGstreamerVideoProbeControl *m_videoProbe = nullptr;
- QGstreamerAudioProbeControl *m_audioProbe = nullptr;
-
- int m_volume = 100;
- qreal m_playbackRate = 1.0;
- bool m_muted = false;
- bool m_audioAvailable = false;
- bool m_videoAvailable = false;
- bool m_seekable = false;
-
- mutable qint64 m_lastPosition = 0;
- qint64 m_duration = 0;
- int m_durationQueries = 0;
-
- bool m_displayPrerolledFrame = true;
-
- enum SourceType
- {
- UnknownSrc,
- SoupHTTPSrc,
- UDPSrc,
- MMSSrc,
- RTSPSrc,
- };
- SourceType m_sourceType = UnknownSrc;
- bool m_everPlayed = false;
- bool m_isLiveSource = false;
-
- gulong pad_probe_id = 0;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERPLAYERSESSION_H
diff --git a/src/gsttools/qgstreamervideoinputdevicecontrol.cpp b/src/gsttools/qgstreamervideoinputdevicecontrol.cpp
deleted file mode 100644
index 4d98afa62..000000000
--- a/src/gsttools/qgstreamervideoinputdevicecontrol.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamervideoinputdevicecontrol_p.h"
-
-#include <QtCore/QDir>
-#include <QtCore/QDebug>
-
-#include <private/qgstutils_p.h>
-
-QGstreamerVideoInputDeviceControl::QGstreamerVideoInputDeviceControl(QObject *parent)
- : QVideoDeviceSelectorControl(parent)
-{
-}
-
-QGstreamerVideoInputDeviceControl::QGstreamerVideoInputDeviceControl(
- GstElementFactory *factory, QObject *parent)
- : QVideoDeviceSelectorControl(parent)
- , m_factory(factory)
-{
- if (m_factory)
- gst_object_ref(GST_OBJECT(m_factory));
-}
-
-QGstreamerVideoInputDeviceControl::~QGstreamerVideoInputDeviceControl()
-{
- if (m_factory)
- gst_object_unref(GST_OBJECT(m_factory));
-}
-
-int QGstreamerVideoInputDeviceControl::deviceCount() const
-{
- return QGstUtils::enumerateCameras(m_factory).count();
-}
-
-QString QGstreamerVideoInputDeviceControl::deviceName(int index) const
-{
- return QGstUtils::enumerateCameras(m_factory).value(index).name;
-}
-
-QString QGstreamerVideoInputDeviceControl::deviceDescription(int index) const
-{
- return QGstUtils::enumerateCameras(m_factory).value(index).description;
-}
-
-int QGstreamerVideoInputDeviceControl::defaultDevice() const
-{
- return 0;
-}
-
-int QGstreamerVideoInputDeviceControl::selectedDevice() const
-{
- return m_selectedDevice;
-}
-
-void QGstreamerVideoInputDeviceControl::setSelectedDevice(int index)
-{
- // Always update selected device and proxy it to clients
- m_selectedDevice = index;
- emit selectedDeviceChanged(index);
- emit selectedDeviceChanged(deviceName(index));
-}
diff --git a/src/gsttools/qgstreamervideoinputdevicecontrol_p.h b/src/gsttools/qgstreamervideoinputdevicecontrol_p.h
deleted file mode 100644
index 9d8dffd72..000000000
--- a/src/gsttools/qgstreamervideoinputdevicecontrol_p.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERVIDEOINPUTDEVICECONTROL_H
-#define QGSTREAMERVIDEOINPUTDEVICECONTROL_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <qvideodeviceselectorcontrol.h>
-#include <QtCore/qstringlist.h>
-
-#include <gst/gst.h>
-#include <qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q_GSTTOOLS_EXPORT QGstreamerVideoInputDeviceControl : public QVideoDeviceSelectorControl
-{
-Q_OBJECT
-public:
- QGstreamerVideoInputDeviceControl(QObject *parent);
- QGstreamerVideoInputDeviceControl(GstElementFactory *factory, QObject *parent);
- ~QGstreamerVideoInputDeviceControl();
-
- int deviceCount() const override;
-
- QString deviceName(int index) const override;
- QString deviceDescription(int index) const override;
-
- int defaultDevice() const override;
- int selectedDevice() const override;
-
- static QString primaryCamera() { return tr("Main camera"); }
- static QString secondaryCamera() { return tr("Front camera"); }
-
-public Q_SLOTS:
- void setSelectedDevice(int index) override;
-
-private:
- GstElementFactory *m_factory = nullptr;
-
- int m_selectedDevice = 0;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERAUDIOINPUTDEVICECONTROL_H
diff --git a/src/gsttools/qgstreamervideooverlay.cpp b/src/gsttools/qgstreamervideooverlay.cpp
deleted file mode 100644
index ea8149442..000000000
--- a/src/gsttools/qgstreamervideooverlay.cpp
+++ /dev/null
@@ -1,639 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamervideooverlay_p.h"
-
-#include <QtGui/qguiapplication.h>
-#include "qgstutils_p.h"
-
-#if !GST_CHECK_VERSION(1,0,0)
-#include <gst/interfaces/xoverlay.h>
-#else
-#include <gst/video/videooverlay.h>
-#endif
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-
-QT_BEGIN_NAMESPACE
-
-struct ElementMap
-{
- const char *qtPlatform;
- const char *gstreamerElement;
-};
-
-// Ordered by descending priority
-static const ElementMap elementMap[] =
-{
-#if QT_CONFIG(gstreamer_gl)
- { "xcb", "glimagesink" },
-#endif
- { "xcb", "vaapisink" },
- { "xcb", "xvimagesink" },
- { "xcb", "ximagesink" }
-};
-
-class QGstreamerSinkProperties
-{
-public:
- virtual ~QGstreamerSinkProperties()
- {
- }
-
- virtual bool hasShowPrerollFrame() const = 0;
- virtual void reset() = 0;
- virtual int brightness() const = 0;
- virtual bool setBrightness(int brightness) = 0;
- virtual int contrast() const = 0;
- virtual bool setContrast(int contrast) = 0;
- virtual int hue() const = 0;
- virtual bool setHue(int hue) = 0;
- virtual int saturation() const = 0;
- virtual bool setSaturation(int saturation) = 0;
- virtual Qt::AspectRatioMode aspectRatioMode() const = 0;
- virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0;
-};
-
-class QXVImageSinkProperties : public QGstreamerSinkProperties
-{
-public:
- QXVImageSinkProperties(GstElement *sink)
- : m_videoSink(sink)
- {
- m_hasForceAspectRatio = g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "force-aspect-ratio");
- m_hasBrightness = g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "brightness");
- m_hasContrast = g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "contrast");
- m_hasHue = g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "hue");
- m_hasSaturation = g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "saturation");
- m_hasShowPrerollFrame = g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "show-preroll-frame");
- }
-
- bool hasShowPrerollFrame() const override
- {
- return m_hasShowPrerollFrame;
- }
-
- void reset() override
- {
- setAspectRatioMode(m_aspectRatioMode);
- setBrightness(m_brightness);
- setContrast(m_contrast);
- setHue(m_hue);
- setSaturation(m_saturation);
- }
-
- int brightness() const override
- {
- int brightness = 0;
- if (m_hasBrightness)
- g_object_get(G_OBJECT(m_videoSink), "brightness", &brightness, nullptr);
-
- return brightness / 10;
- }
-
- bool setBrightness(int brightness) override
- {
- m_brightness = brightness;
- if (m_hasBrightness)
- g_object_set(G_OBJECT(m_videoSink), "brightness", brightness * 10, nullptr);
-
- return m_hasBrightness;
- }
-
- int contrast() const override
- {
- int contrast = 0;
- if (m_hasContrast)
- g_object_get(G_OBJECT(m_videoSink), "contrast", &contrast, nullptr);
-
- return contrast / 10;
- }
-
- bool setContrast(int contrast) override
- {
- m_contrast = contrast;
- if (m_hasContrast)
- g_object_set(G_OBJECT(m_videoSink), "contrast", contrast * 10, nullptr);
-
- return m_hasContrast;
- }
-
- int hue() const override
- {
- int hue = 0;
- if (m_hasHue)
- g_object_get(G_OBJECT(m_videoSink), "hue", &hue, nullptr);
-
- return hue / 10;
- }
-
- bool setHue(int hue) override
- {
- m_hue = hue;
- if (m_hasHue)
- g_object_set(G_OBJECT(m_videoSink), "hue", hue * 10, nullptr);
-
- return m_hasHue;
- }
-
- int saturation() const override
- {
- int saturation = 0;
- if (m_hasSaturation)
- g_object_get(G_OBJECT(m_videoSink), "saturation", &saturation, nullptr);
-
- return saturation / 10;
- }
-
- bool setSaturation(int saturation) override
- {
- m_saturation = saturation;
- if (m_hasSaturation)
- g_object_set(G_OBJECT(m_videoSink), "saturation", saturation * 10, nullptr);
-
- return m_hasSaturation;
- }
-
- Qt::AspectRatioMode aspectRatioMode() const override
- {
- Qt::AspectRatioMode mode = Qt::KeepAspectRatio;
- if (m_hasForceAspectRatio) {
- gboolean forceAR = false;
- g_object_get(G_OBJECT(m_videoSink), "force-aspect-ratio", &forceAR, nullptr);
- if (!forceAR)
- mode = Qt::IgnoreAspectRatio;
- }
-
- return mode;
- }
-
- void setAspectRatioMode(Qt::AspectRatioMode mode) override
- {
- m_aspectRatioMode = mode;
- if (m_hasForceAspectRatio) {
- g_object_set(G_OBJECT(m_videoSink),
- "force-aspect-ratio",
- (mode == Qt::KeepAspectRatio),
- nullptr);
- }
- }
-
-protected:
-
- GstElement *m_videoSink = nullptr;
- bool m_hasForceAspectRatio = false;
- bool m_hasBrightness = false;
- bool m_hasContrast = false;
- bool m_hasHue = false;
- bool m_hasSaturation = false;
- bool m_hasShowPrerollFrame = false;
- Qt::AspectRatioMode m_aspectRatioMode = Qt::KeepAspectRatio;
- int m_brightness = 0;
- int m_contrast = 0;
- int m_hue = 0;
- int m_saturation = 0;
-};
-
-class QVaapiSinkProperties : public QXVImageSinkProperties
-{
-public:
- QVaapiSinkProperties(GstElement *sink)
- : QXVImageSinkProperties(sink)
- {
- // Set default values.
- m_contrast = 1;
- m_saturation = 1;
- }
-
- int brightness() const override
- {
- gfloat brightness = 0;
- if (m_hasBrightness)
- g_object_get(G_OBJECT(m_videoSink), "brightness", &brightness, nullptr);
-
- return brightness * 100; // [-1,1] -> [-100,100]
- }
-
- bool setBrightness(int brightness) override
- {
- m_brightness = brightness;
- if (m_hasBrightness) {
- gfloat v = brightness / 100.0; // [-100,100] -> [-1,1]
- g_object_set(G_OBJECT(m_videoSink), "brightness", v, nullptr);
- }
-
- return m_hasBrightness;
- }
-
- int contrast() const override
- {
- gfloat contrast = 1;
- if (m_hasContrast)
- g_object_get(G_OBJECT(m_videoSink), "contrast", &contrast, nullptr);
-
- return (contrast - 1) * 100; // [0,2] -> [-100,100]
- }
-
- bool setContrast(int contrast) override
- {
- m_contrast = contrast;
- if (m_hasContrast) {
- gfloat v = (contrast / 100.0) + 1; // [-100,100] -> [0,2]
- g_object_set(G_OBJECT(m_videoSink), "contrast", v, nullptr);
- }
-
- return m_hasContrast;
- }
-
- int hue() const override
- {
- gfloat hue = 0;
- if (m_hasHue)
- g_object_get(G_OBJECT(m_videoSink), "hue", &hue, nullptr);
-
- return hue / 180 * 100; // [-180,180] -> [-100,100]
- }
-
- bool setHue(int hue) override
- {
- m_hue = hue;
- if (m_hasHue) {
- gfloat v = hue / 100.0 * 180; // [-100,100] -> [-180,180]
- g_object_set(G_OBJECT(m_videoSink), "hue", v, nullptr);
- }
-
- return m_hasHue;
- }
-
- int saturation() const override
- {
- gfloat saturation = 1;
- if (m_hasSaturation)
- g_object_get(G_OBJECT(m_videoSink), "saturation", &saturation, nullptr);
-
- return (saturation - 1) * 100; // [0,2] -> [-100,100]
- }
-
- bool setSaturation(int saturation) override
- {
- m_saturation = saturation;
- if (m_hasSaturation) {
- gfloat v = (saturation / 100.0) + 1; // [-100,100] -> [0,2]
- g_object_set(G_OBJECT(m_videoSink), "saturation", v, nullptr);
- }
-
- return m_hasSaturation;
- }
-};
-
-static bool qt_gst_element_is_functioning(GstElement *element)
-{
- GstStateChangeReturn ret = gst_element_set_state(element, GST_STATE_READY);
- if (ret == GST_STATE_CHANGE_SUCCESS) {
- gst_element_set_state(element, GST_STATE_NULL);
- return true;
- }
-
- return false;
-}
-
-static GstElement *findBestVideoSink()
-{
- GstElement *choice = 0;
- QString platform = QGuiApplication::platformName();
-
- // We need a native window ID to use the GstVideoOverlay interface.
- // Bail out if the Qt platform plugin in use cannot provide a sensible WId.
- if (platform != QLatin1String("xcb"))
- return 0;
-
- // First, try some known video sinks, depending on the Qt platform plugin in use.
- for (quint32 i = 0; i < (sizeof(elementMap) / sizeof(ElementMap)); ++i) {
-#if QT_CONFIG(gstreamer_gl)
- if (!QGstUtils::useOpenGL() && qstrcmp(elementMap[i].gstreamerElement, "glimagesink") == 0)
- continue;
-#endif
- if (platform == QLatin1String(elementMap[i].qtPlatform)
- && (choice = gst_element_factory_make(elementMap[i].gstreamerElement, nullptr))) {
-
- if (qt_gst_element_is_functioning(choice))
- return choice;
-
- gst_object_unref(choice);
- choice = 0;
- }
- }
-
- // If none of the known video sinks are available, try to find one that implements the
- // GstVideoOverlay interface and has autoplugging rank.
- GList *list = qt_gst_video_sinks();
- for (GList *item = list; item != nullptr; item = item->next) {
- GstElementFactory *f = GST_ELEMENT_FACTORY(item->data);
-
- if (!gst_element_factory_has_interface(f, QT_GSTREAMER_VIDEOOVERLAY_INTERFACE_NAME))
- continue;
-
- if (GstElement *el = gst_element_factory_create(f, nullptr)) {
- if (qt_gst_element_is_functioning(el)) {
- choice = el;
- break;
- }
-
- gst_object_unref(el);
- }
- }
-
- gst_plugin_feature_list_free(list);
-
- return choice;
-}
-
-QGstreamerVideoOverlay::QGstreamerVideoOverlay(QObject *parent, const QByteArray &elementName)
- : QObject(parent)
- , QGstreamerBufferProbe(QGstreamerBufferProbe::ProbeCaps)
-{
- GstElement *sink = nullptr;
- if (!elementName.isEmpty())
- sink = gst_element_factory_make(elementName.constData(), nullptr);
- else
- sink = findBestVideoSink();
-
- setVideoSink(sink);
-}
-
-QGstreamerVideoOverlay::~QGstreamerVideoOverlay()
-{
- if (m_videoSink) {
- delete m_sinkProperties;
- GstPad *pad = gst_element_get_static_pad(m_videoSink, "sink");
- removeProbeFromPad(pad);
- gst_object_unref(GST_OBJECT(pad));
- gst_object_unref(GST_OBJECT(m_videoSink));
- }
-}
-
-GstElement *QGstreamerVideoOverlay::videoSink() const
-{
- return m_videoSink;
-}
-
-void QGstreamerVideoOverlay::setVideoSink(GstElement *sink)
-{
- if (!sink)
- return;
-
- if (m_videoSink)
- gst_object_unref(GST_OBJECT(m_videoSink));
-
- m_videoSink = sink;
- qt_gst_object_ref_sink(GST_OBJECT(m_videoSink));
-
- GstPad *pad = gst_element_get_static_pad(m_videoSink, "sink");
- addProbeToPad(pad);
- gst_object_unref(GST_OBJECT(pad));
-
- QString sinkName(QLatin1String(GST_OBJECT_NAME(sink)));
- bool isVaapi = sinkName.startsWith(QLatin1String("vaapisink"));
- delete m_sinkProperties;
- m_sinkProperties = isVaapi ? new QVaapiSinkProperties(sink) : new QXVImageSinkProperties(sink);
-
- if (m_sinkProperties->hasShowPrerollFrame())
- g_signal_connect(m_videoSink, "notify::show-preroll-frame",
- G_CALLBACK(showPrerollFrameChanged), this);
-}
-
-QSize QGstreamerVideoOverlay::nativeVideoSize() const
-{
- return m_nativeVideoSize;
-}
-
-void QGstreamerVideoOverlay::setWindowHandle(WId id)
-{
- m_windowId = id;
-
- if (isActive())
- setWindowHandle_helper(id);
-}
-
-void QGstreamerVideoOverlay::setWindowHandle_helper(WId id)
-{
-#if GST_CHECK_VERSION(1,0,0)
- if (m_videoSink && GST_IS_VIDEO_OVERLAY(m_videoSink)) {
- gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(m_videoSink), id);
-#else
- if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) {
-# if GST_CHECK_VERSION(0,10,31)
- gst_x_overlay_set_window_handle(GST_X_OVERLAY(m_videoSink), id);
-# else
- gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(m_videoSink), id);
-# endif
-#endif
-
- // Properties need to be reset when changing the winId.
- m_sinkProperties->reset();
- }
-}
-
-void QGstreamerVideoOverlay::expose()
-{
- if (!isActive())
- return;
-
-#if !GST_CHECK_VERSION(1,0,0)
- if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink))
- gst_x_overlay_expose(GST_X_OVERLAY(m_videoSink));
-#else
- if (m_videoSink && GST_IS_VIDEO_OVERLAY(m_videoSink)) {
- gst_video_overlay_expose(GST_VIDEO_OVERLAY(m_videoSink));
- }
-#endif
-}
-
-void QGstreamerVideoOverlay::setRenderRectangle(const QRect &rect)
-{
- int x = -1;
- int y = -1;
- int w = -1;
- int h = -1;
-
- if (!rect.isEmpty()) {
- x = rect.x();
- y = rect.y();
- w = rect.width();
- h = rect.height();
- }
-
-#if GST_CHECK_VERSION(1,0,0)
- if (m_videoSink && GST_IS_VIDEO_OVERLAY(m_videoSink))
- gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(m_videoSink), x, y, w, h);
-#elif GST_CHECK_VERSION(0, 10, 29)
- if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink))
- gst_x_overlay_set_render_rectangle(GST_X_OVERLAY(m_videoSink), x, y , w , h);
-#else
- Q_UNUSED(x);
- Q_UNUSED(y);
- Q_UNUSED(w);
- Q_UNUSED(h);
-#endif
-}
-
-bool QGstreamerVideoOverlay::processSyncMessage(const QGstreamerMessage &message)
-{
- GstMessage* gm = message.rawMessage();
-
-#if !GST_CHECK_VERSION(1,0,0)
- if (gm && (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT) &&
- gst_structure_has_name(gm->structure, "prepare-xwindow-id")) {
-#else
- if (gm && (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT) &&
- gst_structure_has_name(gst_message_get_structure(gm), "prepare-window-handle")) {
-#endif
- setWindowHandle_helper(m_windowId);
- return true;
- }
-
- return false;
-}
-
-bool QGstreamerVideoOverlay::processBusMessage(const QGstreamerMessage &message)
-{
- GstMessage* gm = message.rawMessage();
-
- if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_STATE_CHANGED &&
- GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_videoSink)) {
-
- updateIsActive();
- }
-
- return false;
-}
-
-void QGstreamerVideoOverlay::probeCaps(GstCaps *caps)
-{
- QSize size = QGstUtils::capsCorrectedResolution(caps);
- if (size != m_nativeVideoSize) {
- m_nativeVideoSize = size;
- emit nativeVideoSizeChanged();
- }
-}
-
-bool QGstreamerVideoOverlay::isActive() const
-{
- return m_isActive;
-}
-
-void QGstreamerVideoOverlay::updateIsActive()
-{
- if (!m_videoSink)
- return;
-
- GstState state = GST_STATE(m_videoSink);
- gboolean showPreroll = true;
-
- if (m_sinkProperties->hasShowPrerollFrame())
- g_object_get(G_OBJECT(m_videoSink), "show-preroll-frame", &showPreroll, nullptr);
-
- bool newIsActive = (state == GST_STATE_PLAYING || (state == GST_STATE_PAUSED && showPreroll));
-
- if (newIsActive != m_isActive) {
- m_isActive = newIsActive;
- emit activeChanged();
- }
-}
-
-void QGstreamerVideoOverlay::showPrerollFrameChanged(GObject *, GParamSpec *, QGstreamerVideoOverlay *overlay)
-{
- overlay->updateIsActive();
-}
-
-Qt::AspectRatioMode QGstreamerVideoOverlay::aspectRatioMode() const
-{
- return m_sinkProperties->aspectRatioMode();
-}
-
-void QGstreamerVideoOverlay::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- m_sinkProperties->setAspectRatioMode(mode);
-}
-
-int QGstreamerVideoOverlay::brightness() const
-{
- return m_sinkProperties->brightness();
-}
-
-void QGstreamerVideoOverlay::setBrightness(int brightness)
-{
- if (m_sinkProperties->setBrightness(brightness))
- emit brightnessChanged(brightness);
-}
-
-int QGstreamerVideoOverlay::contrast() const
-{
- return m_sinkProperties->contrast();
-}
-
-void QGstreamerVideoOverlay::setContrast(int contrast)
-{
- if (m_sinkProperties->setContrast(contrast))
- emit contrastChanged(contrast);
-}
-
-int QGstreamerVideoOverlay::hue() const
-{
- return m_sinkProperties->hue();
-}
-
-void QGstreamerVideoOverlay::setHue(int hue)
-{
- if (m_sinkProperties->setHue(hue))
- emit hueChanged(hue);
-}
-
-int QGstreamerVideoOverlay::saturation() const
-{
- return m_sinkProperties->saturation();
-}
-
-void QGstreamerVideoOverlay::setSaturation(int saturation)
-{
- if (m_sinkProperties->setSaturation(saturation))
- emit saturationChanged(saturation);
-}
-
-QT_END_NAMESPACE
diff --git a/src/gsttools/qgstreamervideooverlay_p.h b/src/gsttools/qgstreamervideooverlay_p.h
deleted file mode 100644
index f2ca8a23b..000000000
--- a/src/gsttools/qgstreamervideooverlay_p.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERVIDEOOVERLAY_P_H
-#define QGSTREAMERVIDEOOVERLAY_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgstreamerbushelper_p.h>
-#include <private/qgstreamerbufferprobe_p.h>
-#include <QtGui/qwindowdefs.h>
-#include <QtCore/qsize.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerSinkProperties;
-class QGstreamerVideoOverlay
- : public QObject
- , public QGstreamerSyncMessageFilter
- , public QGstreamerBusMessageFilter
- , private QGstreamerBufferProbe
-{
- Q_OBJECT
- Q_INTERFACES(QGstreamerSyncMessageFilter QGstreamerBusMessageFilter)
-public:
- explicit QGstreamerVideoOverlay(QObject *parent = 0, const QByteArray &elementName = QByteArray());
- virtual ~QGstreamerVideoOverlay();
-
- GstElement *videoSink() const;
- void setVideoSink(GstElement *);
- QSize nativeVideoSize() const;
-
- void setWindowHandle(WId id);
- void expose();
- void setRenderRectangle(const QRect &rect);
-
- bool isActive() const;
-
- Qt::AspectRatioMode aspectRatioMode() const;
- void setAspectRatioMode(Qt::AspectRatioMode mode);
-
- int brightness() const;
- void setBrightness(int brightness);
-
- int contrast() const;
- void setContrast(int contrast);
-
- int hue() const;
- void setHue(int hue);
-
- int saturation() const;
- void setSaturation(int saturation);
-
- bool processSyncMessage(const QGstreamerMessage &message) override;
- bool processBusMessage(const QGstreamerMessage &message) override;
-
-Q_SIGNALS:
- void nativeVideoSizeChanged();
- void activeChanged();
- void brightnessChanged(int brightness);
- void contrastChanged(int contrast);
- void hueChanged(int hue);
- void saturationChanged(int saturation);
-
-private:
- void setWindowHandle_helper(WId id);
- void updateIsActive();
- void probeCaps(GstCaps *caps) override;
- static void showPrerollFrameChanged(GObject *, GParamSpec *, QGstreamerVideoOverlay *);
-
- GstElement *m_videoSink = nullptr;
- QSize m_nativeVideoSize;
- bool m_isActive = false;
-
- QGstreamerSinkProperties *m_sinkProperties = nullptr;
- WId m_windowId = 0;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERVIDEOOVERLAY_P_H
-
diff --git a/src/gsttools/qgstreamervideoprobecontrol.cpp b/src/gsttools/qgstreamervideoprobecontrol.cpp
deleted file mode 100644
index f9ce4e412..000000000
--- a/src/gsttools/qgstreamervideoprobecontrol.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamervideoprobecontrol_p.h"
-
-#include "qgstutils_p.h"
-#include <private/qgstvideobuffer_p.h>
-
-QGstreamerVideoProbeControl::QGstreamerVideoProbeControl(QObject *parent)
- : QMediaVideoProbeControl(parent)
-{
-}
-
-QGstreamerVideoProbeControl::~QGstreamerVideoProbeControl()
-{
-}
-
-void QGstreamerVideoProbeControl::startFlushing()
-{
- m_flushing = true;
-
- {
- QMutexLocker locker(&m_frameMutex);
- m_pendingFrame = QVideoFrame();
- }
-
- // only emit flush if at least one frame was probed
- if (m_frameProbed)
- emit flush();
-}
-
-void QGstreamerVideoProbeControl::stopFlushing()
-{
- m_flushing = false;
-}
-
-void QGstreamerVideoProbeControl::probeCaps(GstCaps *caps)
-{
-#if GST_CHECK_VERSION(1,0,0)
- GstVideoInfo videoInfo;
- QVideoSurfaceFormat format = QGstUtils::formatForCaps(caps, &videoInfo);
-
- QMutexLocker locker(&m_frameMutex);
- m_videoInfo = videoInfo;
-#else
- int bytesPerLine = 0;
- QVideoSurfaceFormat format = QGstUtils::formatForCaps(caps, &bytesPerLine);
-
- QMutexLocker locker(&m_frameMutex);
- m_bytesPerLine = bytesPerLine;
-#endif
- m_format = format;
-}
-
-bool QGstreamerVideoProbeControl::probeBuffer(GstBuffer *buffer)
-{
- QMutexLocker locker(&m_frameMutex);
-
- if (m_flushing || !m_format.isValid())
- return true;
-
- QVideoFrame frame(
-#if GST_CHECK_VERSION(1,0,0)
- new QGstVideoBuffer(buffer, m_videoInfo),
-#else
- new QGstVideoBuffer(buffer, m_bytesPerLine),
-#endif
- m_format.frameSize(),
- m_format.pixelFormat());
-
- QGstUtils::setFrameTimeStamps(&frame, buffer);
-
- m_frameProbed = true;
-
- if (!m_pendingFrame.isValid())
- QMetaObject::invokeMethod(this, "frameProbed", Qt::QueuedConnection);
- m_pendingFrame = frame;
-
- return true;
-}
-
-void QGstreamerVideoProbeControl::frameProbed()
-{
- QVideoFrame frame;
- {
- QMutexLocker locker(&m_frameMutex);
- if (!m_pendingFrame.isValid())
- return;
- frame = m_pendingFrame;
- m_pendingFrame = QVideoFrame();
- }
- emit videoFrameProbed(frame);
-}
diff --git a/src/gsttools/qgstreamervideoprobecontrol_p.h b/src/gsttools/qgstreamervideoprobecontrol_p.h
deleted file mode 100644
index 8f2101d74..000000000
--- a/src/gsttools/qgstreamervideoprobecontrol_p.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERVIDEOPROBECONTROL_H
-#define QGSTREAMERVIDEOPROBECONTROL_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <gst/gst.h>
-#include <gst/video/video.h>
-#include <qmediavideoprobecontrol.h>
-#include <QtCore/qmutex.h>
-#include <qvideoframe.h>
-#include <qvideosurfaceformat.h>
-
-#include <private/qgstreamerbufferprobe_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q_GSTTOOLS_EXPORT QGstreamerVideoProbeControl
- : public QMediaVideoProbeControl
- , public QGstreamerBufferProbe
- , public QSharedData
-{
- Q_OBJECT
-public:
- explicit QGstreamerVideoProbeControl(QObject *parent);
- virtual ~QGstreamerVideoProbeControl();
-
- void probeCaps(GstCaps *caps) override;
- bool probeBuffer(GstBuffer *buffer) override;
-
- void startFlushing();
- void stopFlushing();
-
-private slots:
- void frameProbed();
-
-private:
- QVideoSurfaceFormat m_format;
- QVideoFrame m_pendingFrame;
- QMutex m_frameMutex;
-#if GST_CHECK_VERSION(1,0,0)
- GstVideoInfo m_videoInfo;
-#else
- int m_bytesPerLine = 0;
-#endif
- bool m_flushing = false;
- bool m_frameProbed = false; // true if at least one frame was probed
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERVIDEOPROBECONTROL_H
diff --git a/src/gsttools/qgstreamervideorenderer.cpp b/src/gsttools/qgstreamervideorenderer.cpp
deleted file mode 100644
index c2226d658..000000000
--- a/src/gsttools/qgstreamervideorenderer.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamervideorenderer_p.h"
-#include <private/qvideosurfacegstsink_p.h>
-#include <private/qgstutils_p.h>
-#include <qabstractvideosurface.h>
-#include <QtCore/qdebug.h>
-
-#include <gst/gst.h>
-
-static inline void resetSink(GstElement *&element, GstElement *v = nullptr)
-{
- if (element)
- gst_object_unref(GST_OBJECT(element));
-
- if (v)
- qt_gst_object_ref_sink(GST_OBJECT(v));
-
- element = v;
-}
-
-QGstreamerVideoRenderer::QGstreamerVideoRenderer(QObject *parent)
- : QVideoRendererControl(parent)
-{
-}
-
-QGstreamerVideoRenderer::~QGstreamerVideoRenderer()
-{
- resetSink(m_videoSink);
-}
-
-void QGstreamerVideoRenderer::setVideoSink(GstElement *sink)
-{
- if (!sink)
- return;
-
- resetSink(m_videoSink, sink);
- emit sinkChanged();
-}
-
-GstElement *QGstreamerVideoRenderer::videoSink()
-{
- if (!m_videoSink && m_surface) {
- auto sink = reinterpret_cast<GstElement *>(QVideoSurfaceGstSink::createSink(m_surface));
- resetSink(m_videoSink, sink);
- }
-
- return m_videoSink;
-}
-
-void QGstreamerVideoRenderer::stopRenderer()
-{
- if (m_surface)
- m_surface->stop();
-}
-
-QAbstractVideoSurface *QGstreamerVideoRenderer::surface() const
-{
- return m_surface;
-}
-
-void QGstreamerVideoRenderer::setSurface(QAbstractVideoSurface *surface)
-{
- if (m_surface != surface) {
- resetSink(m_videoSink);
-
- if (m_surface) {
- disconnect(m_surface.data(), SIGNAL(supportedFormatsChanged()),
- this, SLOT(handleFormatChange()));
- }
-
- bool wasReady = isReady();
-
- m_surface = surface;
-
- if (m_surface) {
- connect(m_surface.data(), SIGNAL(supportedFormatsChanged()),
- this, SLOT(handleFormatChange()));
- }
-
- if (wasReady != isReady())
- emit readyChanged(isReady());
-
- emit sinkChanged();
- }
-}
-
-void QGstreamerVideoRenderer::handleFormatChange()
-{
- setVideoSink(nullptr);
-}
diff --git a/src/gsttools/qgstreamervideorenderer_p.h b/src/gsttools/qgstreamervideorenderer_p.h
deleted file mode 100644
index d87bfcb8f..000000000
--- a/src/gsttools/qgstreamervideorenderer_p.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERVIDEORENDERER_H
-#define QGSTREAMERVIDEORENDERER_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <qvideorenderercontrol.h>
-#include <private/qvideosurfacegstsink_p.h>
-#include <qabstractvideosurface.h>
-
-#include "qgstreamervideorendererinterface_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class Q_GSTTOOLS_EXPORT QGstreamerVideoRenderer : public QVideoRendererControl, public QGstreamerVideoRendererInterface
-{
- Q_OBJECT
- Q_INTERFACES(QGstreamerVideoRendererInterface)
-public:
- QGstreamerVideoRenderer(QObject *parent = 0);
- virtual ~QGstreamerVideoRenderer();
-
- QAbstractVideoSurface *surface() const override;
- void setSurface(QAbstractVideoSurface *surface) override;
-
- GstElement *videoSink() override;
- void setVideoSink(GstElement *) override;
-
- void stopRenderer() override;
- bool isReady() const override { return m_surface != 0; }
-
-signals:
- void sinkChanged();
- void readyChanged(bool);
-
-private slots:
- void handleFormatChange();
-
-private:
- GstElement *m_videoSink = nullptr;
- QPointer<QAbstractVideoSurface> m_surface;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERVIDEORENDRER_H
diff --git a/src/gsttools/qgstreamervideorendererinterface.cpp b/src/gsttools/qgstreamervideorendererinterface.cpp
deleted file mode 100644
index ae7de06f1..000000000
--- a/src/gsttools/qgstreamervideorendererinterface.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamervideorendererinterface_p.h"
-
-QGstreamerVideoRendererInterface::~QGstreamerVideoRendererInterface()
-{
-}
diff --git a/src/gsttools/qgstreamervideorendererinterface_p.h b/src/gsttools/qgstreamervideorendererinterface_p.h
deleted file mode 100644
index 231c843db..000000000
--- a/src/gsttools/qgstreamervideorendererinterface_p.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERVIDEOOUTPUTCONTROL_H
-#define QGSTREAMERVIDEOOUTPUTCONTROL_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <gst/gst.h>
-
-#include <QtCore/qobject.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerVideoRendererInterface
-{
-public:
- virtual ~QGstreamerVideoRendererInterface();
- virtual GstElement *videoSink() = 0;
- virtual void setVideoSink(GstElement *) {};
-
- //stopRenderer() is called when the renderer element is stopped.
- //it can be reimplemented when video renderer can't detect
- //changes to NULL state but has to free video resources.
- virtual void stopRenderer() {}
-
- //the video output is configured, usually after the first paint event
- //(winId is known,
- virtual bool isReady() const { return true; }
-
- //signals:
- //void sinkChanged();
- //void readyChanged(bool);
-};
-
-#define QGstreamerVideoRendererInterface_iid "org.qt-project.qt.gstreamervideorenderer/5.0"
-Q_DECLARE_INTERFACE(QGstreamerVideoRendererInterface, QGstreamerVideoRendererInterface_iid)
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gsttools/qgstreamervideowidget.cpp b/src/gsttools/qgstreamervideowidget.cpp
deleted file mode 100644
index 4137aff32..000000000
--- a/src/gsttools/qgstreamervideowidget.cpp
+++ /dev/null
@@ -1,280 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamervideowidget_p.h"
-#include "qgstutils_p.h"
-
-#include <QtCore/qcoreevent.h>
-#include <QtCore/qdebug.h>
-#include <QtGui/qpainter.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerVideoWidget : public QWidget
-{
-public:
- QGstreamerVideoWidget(QWidget *parent = 0)
- :QWidget(parent)
- {
- setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- QPalette palette;
- palette.setColor(QPalette::Window, Qt::black);
- setPalette(palette);
- }
-
- virtual ~QGstreamerVideoWidget() {}
-
- QSize sizeHint() const override
- {
- return m_nativeSize;
- }
-
- void setNativeSize( const QSize &size)
- {
- if (size != m_nativeSize) {
- m_nativeSize = size;
- if (size.isEmpty())
- setMinimumSize(0,0);
- else
- setMinimumSize(160,120);
-
- updateGeometry();
- }
- }
-
- void paint_helper()
- {
- QPainter painter(this);
- painter.fillRect(rect(), palette().window());
- }
-
-protected:
- void paintEvent(QPaintEvent *) override
- {
- paint_helper();
- }
-
- QSize m_nativeSize;
-};
-
-QGstreamerVideoWidgetControl::QGstreamerVideoWidgetControl(QObject *parent, const QByteArray &elementName)
- : QVideoWidgetControl(parent)
- , m_videoOverlay(this, !elementName.isEmpty() ? elementName : qgetenv("QT_GSTREAMER_WIDGET_VIDEOSINK"))
-{
- connect(&m_videoOverlay, &QGstreamerVideoOverlay::activeChanged,
- this, &QGstreamerVideoWidgetControl::onOverlayActiveChanged);
- connect(&m_videoOverlay, &QGstreamerVideoOverlay::nativeVideoSizeChanged,
- this, &QGstreamerVideoWidgetControl::onNativeVideoSizeChanged);
- connect(&m_videoOverlay, &QGstreamerVideoOverlay::brightnessChanged,
- this, &QGstreamerVideoWidgetControl::brightnessChanged);
- connect(&m_videoOverlay, &QGstreamerVideoOverlay::contrastChanged,
- this, &QGstreamerVideoWidgetControl::contrastChanged);
- connect(&m_videoOverlay, &QGstreamerVideoOverlay::hueChanged,
- this, &QGstreamerVideoWidgetControl::hueChanged);
- connect(&m_videoOverlay, &QGstreamerVideoOverlay::saturationChanged,
- this, &QGstreamerVideoWidgetControl::saturationChanged);
-}
-
-QGstreamerVideoWidgetControl::~QGstreamerVideoWidgetControl()
-{
- delete m_widget;
-}
-
-void QGstreamerVideoWidgetControl::createVideoWidget()
-{
- if (m_widget)
- return;
-
- m_widget = new QGstreamerVideoWidget;
-
- m_widget->installEventFilter(this);
- m_videoOverlay.setWindowHandle(m_windowId = m_widget->winId());
-}
-
-GstElement *QGstreamerVideoWidgetControl::videoSink()
-{
- return m_videoOverlay.videoSink();
-}
-
-void QGstreamerVideoWidgetControl::setVideoSink(GstElement *sink)
-{
- m_videoOverlay.setVideoSink(sink);
-}
-
-void QGstreamerVideoWidgetControl::onOverlayActiveChanged()
-{
- updateWidgetAttributes();
-}
-
-void QGstreamerVideoWidgetControl::stopRenderer()
-{
- m_stopped = true;
- updateWidgetAttributes();
- m_widget->setNativeSize(QSize());
-}
-
-void QGstreamerVideoWidgetControl::onNativeVideoSizeChanged()
-{
- const QSize &size = m_videoOverlay.nativeVideoSize();
-
- if (size.isValid())
- m_stopped = false;
-
- if (m_widget)
- m_widget->setNativeSize(size);
-}
-
-bool QGstreamerVideoWidgetControl::eventFilter(QObject *object, QEvent *e)
-{
- if (m_widget && object == m_widget) {
- if (e->type() == QEvent::ParentChange || e->type() == QEvent::Show || e->type() == QEvent::WinIdChange) {
- WId newWId = m_widget->winId();
- if (newWId != m_windowId)
- m_videoOverlay.setWindowHandle(m_windowId = newWId);
- }
-
- if (e->type() == QEvent::Paint) {
- // Update overlay by new size if any.
- if (QGstUtils::useOpenGL())
- m_videoOverlay.setRenderRectangle(QRect(0, 0, m_widget->width(), m_widget->height()));
- if (m_videoOverlay.isActive())
- m_videoOverlay.expose(); // triggers a repaint of the last frame
- else
- m_widget->paint_helper(); // paints the black background
-
- return true;
- }
- }
-
- return false;
-}
-
-void QGstreamerVideoWidgetControl::updateWidgetAttributes()
-{
- // When frames are being rendered (sink is active), we need the WA_PaintOnScreen attribute to
- // be set in order to avoid flickering when the widget is repainted (for example when resized).
- // We need to clear that flag when the the sink is inactive to allow the widget to paint its
- // background, otherwise some garbage will be displayed.
- if (m_videoOverlay.isActive() && !m_stopped) {
- m_widget->setAttribute(Qt::WA_NoSystemBackground, true);
- m_widget->setAttribute(Qt::WA_PaintOnScreen, true);
- } else {
- m_widget->setAttribute(Qt::WA_NoSystemBackground, false);
- m_widget->setAttribute(Qt::WA_PaintOnScreen, false);
- m_widget->update();
- }
-}
-
-bool QGstreamerVideoWidgetControl::processSyncMessage(const QGstreamerMessage &message)
-{
- return m_videoOverlay.processSyncMessage(message);
-}
-
-bool QGstreamerVideoWidgetControl::processBusMessage(const QGstreamerMessage &message)
-{
- return m_videoOverlay.processBusMessage(message);
-}
-
-QWidget *QGstreamerVideoWidgetControl::videoWidget()
-{
- createVideoWidget();
- return m_widget;
-}
-
-Qt::AspectRatioMode QGstreamerVideoWidgetControl::aspectRatioMode() const
-{
- return m_videoOverlay.aspectRatioMode();
-}
-
-void QGstreamerVideoWidgetControl::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- m_videoOverlay.setAspectRatioMode(mode);
-}
-
-bool QGstreamerVideoWidgetControl::isFullScreen() const
-{
- return m_fullScreen;
-}
-
-void QGstreamerVideoWidgetControl::setFullScreen(bool fullScreen)
-{
- emit fullScreenChanged(m_fullScreen = fullScreen);
-}
-
-int QGstreamerVideoWidgetControl::brightness() const
-{
- return m_videoOverlay.brightness();
-}
-
-void QGstreamerVideoWidgetControl::setBrightness(int brightness)
-{
- m_videoOverlay.setBrightness(brightness);
-}
-
-int QGstreamerVideoWidgetControl::contrast() const
-{
- return m_videoOverlay.contrast();
-}
-
-void QGstreamerVideoWidgetControl::setContrast(int contrast)
-{
- m_videoOverlay.setContrast(contrast);
-}
-
-int QGstreamerVideoWidgetControl::hue() const
-{
- return m_videoOverlay.hue();
-}
-
-void QGstreamerVideoWidgetControl::setHue(int hue)
-{
- m_videoOverlay.setHue(hue);
-}
-
-int QGstreamerVideoWidgetControl::saturation() const
-{
- return m_videoOverlay.saturation();
-}
-
-void QGstreamerVideoWidgetControl::setSaturation(int saturation)
-{
- m_videoOverlay.setSaturation(saturation);
-}
-
-QT_END_NAMESPACE
diff --git a/src/gsttools/qgstreamervideowidget_p.h b/src/gsttools/qgstreamervideowidget_p.h
deleted file mode 100644
index 6eec6ae52..000000000
--- a/src/gsttools/qgstreamervideowidget_p.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERVIDEOWIDGET_H
-#define QGSTREAMERVIDEOWIDGET_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <qvideowidgetcontrol.h>
-
-#include "qgstreamervideorendererinterface_p.h"
-#include <private/qgstreamerbushelper_p.h>
-#include <private/qgstreamervideooverlay_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q_GSTTOOLS_EXPORT QGstreamerVideoWidget;
-
-class Q_GSTTOOLS_EXPORT QGstreamerVideoWidgetControl
- : public QVideoWidgetControl
- , public QGstreamerVideoRendererInterface
- , public QGstreamerSyncMessageFilter
- , public QGstreamerBusMessageFilter
-{
- Q_OBJECT
- Q_INTERFACES(QGstreamerVideoRendererInterface QGstreamerSyncMessageFilter QGstreamerBusMessageFilter)
-public:
- explicit QGstreamerVideoWidgetControl(QObject *parent = 0, const QByteArray &elementName = QByteArray());
- virtual ~QGstreamerVideoWidgetControl();
-
- GstElement *videoSink() override;
- void setVideoSink(GstElement *) override;
-
- QWidget *videoWidget() override;
-
- void stopRenderer() override;
-
- Qt::AspectRatioMode aspectRatioMode() const override;
- void setAspectRatioMode(Qt::AspectRatioMode mode) override;
-
- bool isFullScreen() const override;
- void setFullScreen(bool fullScreen) override;
-
- int brightness() const override;
- void setBrightness(int brightness) override;
-
- int contrast() const override;
- void setContrast(int contrast) override;
-
- int hue() const override;
- void setHue(int hue) override;
-
- int saturation() const override;
- void setSaturation(int saturation) override;
-
- bool eventFilter(QObject *object, QEvent *event) override;
-
-signals:
- void sinkChanged();
- void readyChanged(bool);
-
-private Q_SLOTS:
- void onOverlayActiveChanged();
- void onNativeVideoSizeChanged();
-
-private:
- void createVideoWidget();
- void updateWidgetAttributes();
-
- bool processSyncMessage(const QGstreamerMessage &message) override;
- bool processBusMessage(const QGstreamerMessage &message) override;
-
- QGstreamerVideoOverlay m_videoOverlay;
- QGstreamerVideoWidget *m_widget = nullptr;
- bool m_stopped = false;
- WId m_windowId = 0;
- bool m_fullScreen = false;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERVIDEOWIDGET_H
diff --git a/src/gsttools/qgstreamervideowindow.cpp b/src/gsttools/qgstreamervideowindow.cpp
deleted file mode 100644
index e7e3c5044..000000000
--- a/src/gsttools/qgstreamervideowindow.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamervideowindow_p.h"
-#include <private/qgstutils_p.h>
-
-#include <QtCore/qdebug.h>
-
-QGstreamerVideoWindow::QGstreamerVideoWindow(QObject *parent, const QByteArray &elementName)
- : QVideoWindowControl(parent)
- , m_videoOverlay(this, !elementName.isEmpty() ? elementName : qgetenv("QT_GSTREAMER_WINDOW_VIDEOSINK"))
-{
- connect(&m_videoOverlay, &QGstreamerVideoOverlay::nativeVideoSizeChanged,
- this, &QGstreamerVideoWindow::nativeSizeChanged);
- connect(&m_videoOverlay, &QGstreamerVideoOverlay::brightnessChanged,
- this, &QGstreamerVideoWindow::brightnessChanged);
- connect(&m_videoOverlay, &QGstreamerVideoOverlay::contrastChanged,
- this, &QGstreamerVideoWindow::contrastChanged);
- connect(&m_videoOverlay, &QGstreamerVideoOverlay::hueChanged,
- this, &QGstreamerVideoWindow::hueChanged);
- connect(&m_videoOverlay, &QGstreamerVideoOverlay::saturationChanged,
- this, &QGstreamerVideoWindow::saturationChanged);
-}
-
-QGstreamerVideoWindow::~QGstreamerVideoWindow()
-{
-}
-
-GstElement *QGstreamerVideoWindow::videoSink()
-{
- return m_videoOverlay.videoSink();
-}
-
-WId QGstreamerVideoWindow::winId() const
-{
- return m_windowId;
-}
-
-void QGstreamerVideoWindow::setWinId(WId id)
-{
- if (m_windowId == id)
- return;
-
- WId oldId = m_windowId;
- m_videoOverlay.setWindowHandle(m_windowId = id);
-
- if (!oldId)
- emit readyChanged(true);
-
- if (!id)
- emit readyChanged(false);
-}
-
-bool QGstreamerVideoWindow::processSyncMessage(const QGstreamerMessage &message)
-{
- return m_videoOverlay.processSyncMessage(message);
-}
-
-bool QGstreamerVideoWindow::processBusMessage(const QGstreamerMessage &message)
-{
- return m_videoOverlay.processBusMessage(message);
-}
-
-QRect QGstreamerVideoWindow::displayRect() const
-{
- return m_displayRect;
-}
-
-void QGstreamerVideoWindow::setDisplayRect(const QRect &rect)
-{
- m_videoOverlay.setRenderRectangle(m_displayRect = rect);
- repaint();
-}
-
-Qt::AspectRatioMode QGstreamerVideoWindow::aspectRatioMode() const
-{
- return m_videoOverlay.aspectRatioMode();
-}
-
-void QGstreamerVideoWindow::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- m_videoOverlay.setAspectRatioMode(mode);
-}
-
-void QGstreamerVideoWindow::repaint()
-{
- m_videoOverlay.expose();
-}
-
-int QGstreamerVideoWindow::brightness() const
-{
- return m_videoOverlay.brightness();
-}
-
-void QGstreamerVideoWindow::setBrightness(int brightness)
-{
- m_videoOverlay.setBrightness(brightness);
-}
-
-int QGstreamerVideoWindow::contrast() const
-{
- return m_videoOverlay.contrast();
-}
-
-void QGstreamerVideoWindow::setContrast(int contrast)
-{
- m_videoOverlay.setContrast(contrast);
-}
-
-int QGstreamerVideoWindow::hue() const
-{
- return m_videoOverlay.hue();
-}
-
-void QGstreamerVideoWindow::setHue(int hue)
-{
- m_videoOverlay.setHue(hue);
-}
-
-int QGstreamerVideoWindow::saturation() const
-{
- return m_videoOverlay.saturation();
-}
-
-void QGstreamerVideoWindow::setSaturation(int saturation)
-{
- m_videoOverlay.setSaturation(saturation);
-}
-
-bool QGstreamerVideoWindow::isFullScreen() const
-{
- return m_fullScreen;
-}
-
-void QGstreamerVideoWindow::setFullScreen(bool fullScreen)
-{
- emit fullScreenChanged(m_fullScreen = fullScreen);
-}
-
-QSize QGstreamerVideoWindow::nativeSize() const
-{
- return m_videoOverlay.nativeVideoSize();
-}
diff --git a/src/gsttools/qgstreamervideowindow_p.h b/src/gsttools/qgstreamervideowindow_p.h
deleted file mode 100644
index a0ed8599b..000000000
--- a/src/gsttools/qgstreamervideowindow_p.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERVIDEOWINDOW_H
-#define QGSTREAMERVIDEOWINDOW_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <qvideowindowcontrol.h>
-
-#include "qgstreamervideorendererinterface_p.h"
-#include <private/qgstreamerbushelper_p.h>
-#include <private/qgstreamervideooverlay_p.h>
-#include <QtGui/qcolor.h>
-
-QT_BEGIN_NAMESPACE
-class QAbstractVideoSurface;
-
-class Q_GSTTOOLS_EXPORT QGstreamerVideoWindow :
- public QVideoWindowControl,
- public QGstreamerVideoRendererInterface,
- public QGstreamerSyncMessageFilter,
- public QGstreamerBusMessageFilter
-{
- Q_OBJECT
- Q_INTERFACES(QGstreamerVideoRendererInterface QGstreamerSyncMessageFilter QGstreamerBusMessageFilter)
-public:
- explicit QGstreamerVideoWindow(QObject *parent = 0, const QByteArray &elementName = QByteArray());
- ~QGstreamerVideoWindow();
-
- WId winId() const override;
- void setWinId(WId id) override;
-
- QRect displayRect() const override;
- void setDisplayRect(const QRect &rect) override;
-
- bool isFullScreen() const override;
- void setFullScreen(bool fullScreen) override;
-
- QSize nativeSize() const override;
-
- Qt::AspectRatioMode aspectRatioMode() const override;
- void setAspectRatioMode(Qt::AspectRatioMode mode) override;
-
- void repaint() override;
-
- int brightness() const override;
- void setBrightness(int brightness) override;
-
- int contrast() const override;
- void setContrast(int contrast) override;
-
- int hue() const override;
- void setHue(int hue) override;
-
- int saturation() const override;
- void setSaturation(int saturation) override;
-
- QAbstractVideoSurface *surface() const;
-
- GstElement *videoSink() override;
-
- bool processSyncMessage(const QGstreamerMessage &message) override;
- bool processBusMessage(const QGstreamerMessage &message) override;
- bool isReady() const override { return m_windowId != 0; }
-
-signals:
- void sinkChanged();
- void readyChanged(bool);
-
-private:
- QGstreamerVideoOverlay m_videoOverlay;
- WId m_windowId = 0;
- QRect m_displayRect;
- bool m_fullScreen = false;
- mutable QColor m_colorKey = QColor::Invalid;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gsttools/qgsttools_global_p.h b/src/gsttools/qgsttools_global_p.h
deleted file mode 100644
index babcd3aaf..000000000
--- a/src/gsttools/qgsttools_global_p.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTTOOLS_GLOBAL_H
-#define QGSTTOOLS_GLOBAL_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_STATIC
-# if defined(QT_BUILD_MULTIMEDIAGSTTOOLS_LIB)
-# define Q_GSTTOOLS_EXPORT Q_DECL_EXPORT
-# else
-# define Q_GSTTOOLS_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define Q_GSTTOOLS_EXPORT
-#endif
-
-QT_END_NAMESPACE
-
-#endif // QGSTTOOLS_GLOBAL_H
diff --git a/src/gsttools/qgstutils.cpp b/src/gsttools/qgstutils.cpp
deleted file mode 100644
index 5c8d4c90c..000000000
--- a/src/gsttools/qgstutils.cpp
+++ /dev/null
@@ -1,1746 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "qgstutils_p.h"
-
-#include <QtCore/qdatetime.h>
-#include <QtCore/qdir.h>
-#include <QtCore/qbytearray.h>
-#include <QtCore/qvariant.h>
-#include <QtCore/qregularexpression.h>
-#include <QtCore/qsize.h>
-#include <QtCore/qset.h>
-#include <QtCore/qstringlist.h>
-#include <QtGui/qimage.h>
-#include <qaudioformat.h>
-#include <QtCore/qelapsedtimer.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
-#include <private/qmultimediautils_p.h>
-
-#include <gst/audio/audio.h>
-#include <gst/video/video.h>
-
-template<typename T, int N> static int lengthOf(const T (&)[N]) { return N; }
-
-#if QT_CONFIG(linux_v4l)
-# include <private/qcore_unix_p.h>
-# include <linux/videodev2.h>
-#endif
-
-#include "qgstreamervideoinputdevicecontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-//internal
-static void addTagToMap(const GstTagList *list,
- const gchar *tag,
- gpointer user_data)
-{
- QMap<QByteArray, QVariant> *map = reinterpret_cast<QMap<QByteArray, QVariant>* >(user_data);
-
- GValue val;
- val.g_type = 0;
- gst_tag_list_copy_value(&val,list,tag);
-
- switch( G_VALUE_TYPE(&val) ) {
- case G_TYPE_STRING:
- {
- const gchar *str_value = g_value_get_string(&val);
- map->insert(QByteArray(tag), QString::fromUtf8(str_value));
- break;
- }
- case G_TYPE_INT:
- map->insert(QByteArray(tag), g_value_get_int(&val));
- break;
- case G_TYPE_UINT:
- map->insert(QByteArray(tag), g_value_get_uint(&val));
- break;
- case G_TYPE_LONG:
- map->insert(QByteArray(tag), qint64(g_value_get_long(&val)));
- break;
- case G_TYPE_BOOLEAN:
- map->insert(QByteArray(tag), g_value_get_boolean(&val));
- break;
- case G_TYPE_CHAR:
-#if GLIB_CHECK_VERSION(2,32,0)
- map->insert(QByteArray(tag), g_value_get_schar(&val));
-#else
- map->insert(QByteArray(tag), g_value_get_char(&val));
-#endif
- break;
- case G_TYPE_DOUBLE:
- map->insert(QByteArray(tag), g_value_get_double(&val));
- break;
- default:
- // GST_TYPE_DATE is a function, not a constant, so pull it out of the switch
-#if GST_CHECK_VERSION(1,0,0)
- if (G_VALUE_TYPE(&val) == G_TYPE_DATE) {
- const GDate *date = (const GDate *)g_value_get_boxed(&val);
-#else
- if (G_VALUE_TYPE(&val) == GST_TYPE_DATE) {
- const GDate *date = gst_value_get_date(&val);
-#endif
- if (g_date_valid(date)) {
- int year = g_date_get_year(date);
- int month = g_date_get_month(date);
- int day = g_date_get_day(date);
- map->insert(QByteArray(tag), QDate(year,month,day));
- if (!map->contains("year"))
- map->insert("year", year);
- }
-#if GST_CHECK_VERSION(1,0,0)
- } else if (G_VALUE_TYPE(&val) == GST_TYPE_DATE_TIME) {
- const GstDateTime *dateTime = (const GstDateTime *)g_value_get_boxed(&val);
- int year = gst_date_time_has_year(dateTime) ? gst_date_time_get_year(dateTime) : 0;
- int month = gst_date_time_has_month(dateTime) ? gst_date_time_get_month(dateTime) : 0;
- int day = gst_date_time_has_day(dateTime) ? gst_date_time_get_day(dateTime) : 0;
- if (gst_date_time_has_time(dateTime)) {
- int hour = gst_date_time_get_hour(dateTime);
- int minute = gst_date_time_get_minute(dateTime);
- int second = gst_date_time_get_second(dateTime);
- float tz = gst_date_time_get_time_zone_offset(dateTime);
- QDateTime dateTime(QDate(year, month, day), QTime(hour, minute, second),
- Qt::OffsetFromUTC, tz * 60 * 60);
- map->insert(QByteArray(tag), dateTime);
- } else if (year > 0 && month > 0 && day > 0) {
- map->insert(QByteArray(tag), QDate(year,month,day));
- }
- if (!map->contains("year") && year > 0)
- map->insert("year", year);
- } else if (G_VALUE_TYPE(&val) == GST_TYPE_SAMPLE) {
- GstSample *sample = (GstSample *)g_value_get_boxed(&val);
- GstCaps* caps = gst_sample_get_caps(sample);
- if (caps && !gst_caps_is_empty(caps)) {
- GstStructure *structure = gst_caps_get_structure(caps, 0);
- const gchar *name = gst_structure_get_name(structure);
- if (QByteArray(name).startsWith("image/")) {
- GstBuffer *buffer = gst_sample_get_buffer(sample);
- if (buffer) {
- GstMapInfo info;
- gst_buffer_map(buffer, &info, GST_MAP_READ);
- map->insert(QByteArray(tag), QImage::fromData(info.data, info.size, name));
- gst_buffer_unmap(buffer, &info);
- }
- }
- }
-#endif
- } else if (G_VALUE_TYPE(&val) == GST_TYPE_FRACTION) {
- int nom = gst_value_get_fraction_numerator(&val);
- int denom = gst_value_get_fraction_denominator(&val);
-
- if (denom > 0) {
- map->insert(QByteArray(tag), double(nom)/denom);
- }
- }
- break;
- }
-
- g_value_unset(&val);
-}
-
-/*!
- \class QGstUtils
- \internal
-*/
-
-/*!
- Convert GstTagList structure to QMap<QByteArray, QVariant>.
-
- Mapping to int, bool, char, string, fractions and date are supported.
- Fraction values are converted to doubles.
-*/
-QMap<QByteArray, QVariant> QGstUtils::gstTagListToMap(const GstTagList *tags)
-{
- QMap<QByteArray, QVariant> res;
- gst_tag_list_foreach(tags, addTagToMap, &res);
-
- return res;
-}
-
-/*!
- Returns resolution of \a caps.
- If caps doesn't have a valid size, an empty QSize is returned.
-*/
-QSize QGstUtils::capsResolution(const GstCaps *caps)
-{
- if (gst_caps_get_size(caps) == 0)
- return QSize();
-
- return structureResolution(gst_caps_get_structure(caps, 0));
-}
-
-/*!
- Returns aspect ratio corrected resolution of \a caps.
- If caps doesn't have a valid size, an empty QSize is returned.
-*/
-QSize QGstUtils::capsCorrectedResolution(const GstCaps *caps)
-{
- QSize size;
-
- if (caps) {
- size = capsResolution(caps);
-
- gint aspectNum = 0;
- gint aspectDenum = 0;
- if (!size.isEmpty() && gst_structure_get_fraction(
- gst_caps_get_structure(caps, 0), "pixel-aspect-ratio", &aspectNum, &aspectDenum)) {
- if (aspectDenum > 0)
- size.setWidth(size.width()*aspectNum/aspectDenum);
- }
- }
-
- return size;
-}
-
-
-#if GST_CHECK_VERSION(1,0,0)
-namespace {
-
-struct AudioFormat
-{
- GstAudioFormat format;
- QAudioFormat::SampleType sampleType;
- QAudioFormat::Endian byteOrder;
- int sampleSize;
-};
-static const AudioFormat qt_audioLookup[] =
-{
- { GST_AUDIO_FORMAT_S8 , QAudioFormat::SignedInt , QAudioFormat::LittleEndian, 8 },
- { GST_AUDIO_FORMAT_U8 , QAudioFormat::UnSignedInt, QAudioFormat::LittleEndian, 8 },
- { GST_AUDIO_FORMAT_S16LE, QAudioFormat::SignedInt , QAudioFormat::LittleEndian, 16 },
- { GST_AUDIO_FORMAT_S16BE, QAudioFormat::SignedInt , QAudioFormat::BigEndian , 16 },
- { GST_AUDIO_FORMAT_U16LE, QAudioFormat::UnSignedInt, QAudioFormat::LittleEndian, 16 },
- { GST_AUDIO_FORMAT_U16BE, QAudioFormat::UnSignedInt, QAudioFormat::BigEndian , 16 },
- { GST_AUDIO_FORMAT_S32LE, QAudioFormat::SignedInt , QAudioFormat::LittleEndian, 32 },
- { GST_AUDIO_FORMAT_S32BE, QAudioFormat::SignedInt , QAudioFormat::BigEndian , 32 },
- { GST_AUDIO_FORMAT_U32LE, QAudioFormat::UnSignedInt, QAudioFormat::LittleEndian, 32 },
- { GST_AUDIO_FORMAT_U32BE, QAudioFormat::UnSignedInt, QAudioFormat::BigEndian , 32 },
- { GST_AUDIO_FORMAT_S24LE, QAudioFormat::SignedInt , QAudioFormat::LittleEndian, 24 },
- { GST_AUDIO_FORMAT_S24BE, QAudioFormat::SignedInt , QAudioFormat::BigEndian , 24 },
- { GST_AUDIO_FORMAT_U24LE, QAudioFormat::UnSignedInt, QAudioFormat::LittleEndian, 24 },
- { GST_AUDIO_FORMAT_U24BE, QAudioFormat::UnSignedInt, QAudioFormat::BigEndian , 24 },
- { GST_AUDIO_FORMAT_F32LE, QAudioFormat::Float , QAudioFormat::LittleEndian, 32 },
- { GST_AUDIO_FORMAT_F32BE, QAudioFormat::Float , QAudioFormat::BigEndian , 32 },
- { GST_AUDIO_FORMAT_F64LE, QAudioFormat::Float , QAudioFormat::LittleEndian, 64 },
- { GST_AUDIO_FORMAT_F64BE, QAudioFormat::Float , QAudioFormat::BigEndian , 64 }
-};
-
-}
-#endif
-
-/*!
- Returns audio format for caps.
- If caps doesn't have a valid audio format, an empty QAudioFormat is returned.
-*/
-
-QAudioFormat QGstUtils::audioFormatForCaps(const GstCaps *caps)
-{
- QAudioFormat format;
-#if GST_CHECK_VERSION(1,0,0)
- GstAudioInfo info;
- if (gst_audio_info_from_caps(&info, caps)) {
- for (int i = 0; i < lengthOf(qt_audioLookup); ++i) {
- if (qt_audioLookup[i].format != info.finfo->format)
- continue;
-
- format.setSampleType(qt_audioLookup[i].sampleType);
- format.setByteOrder(qt_audioLookup[i].byteOrder);
- format.setSampleSize(qt_audioLookup[i].sampleSize);
- format.setSampleRate(info.rate);
- format.setChannelCount(info.channels);
- format.setCodec(QStringLiteral("audio/pcm"));
-
- return format;
- }
- }
-#else
- const GstStructure *structure = gst_caps_get_structure(caps, 0);
-
- if (qstrcmp(gst_structure_get_name(structure), "audio/x-raw-int") == 0) {
-
- format.setCodec("audio/pcm");
-
- int endianness = 0;
- gst_structure_get_int(structure, "endianness", &endianness);
- if (endianness == 1234)
- format.setByteOrder(QAudioFormat::LittleEndian);
- else if (endianness == 4321)
- format.setByteOrder(QAudioFormat::BigEndian);
-
- gboolean isSigned = FALSE;
- gst_structure_get_boolean(structure, "signed", &isSigned);
- if (isSigned)
- format.setSampleType(QAudioFormat::SignedInt);
- else
- format.setSampleType(QAudioFormat::UnSignedInt);
-
- // Number of bits allocated per sample.
- int width = 0;
- gst_structure_get_int(structure, "width", &width);
-
- // The number of bits used per sample. This must be less than or equal to the width.
- int depth = 0;
- gst_structure_get_int(structure, "depth", &depth);
-
- if (width != depth) {
- // Unsupported sample layout.
- return QAudioFormat();
- }
- format.setSampleSize(width);
-
- int rate = 0;
- gst_structure_get_int(structure, "rate", &rate);
- format.setSampleRate(rate);
-
- int channels = 0;
- gst_structure_get_int(structure, "channels", &channels);
- format.setChannelCount(channels);
-
- } else if (qstrcmp(gst_structure_get_name(structure), "audio/x-raw-float") == 0) {
-
- format.setCodec("audio/pcm");
-
- int endianness = 0;
- gst_structure_get_int(structure, "endianness", &endianness);
- if (endianness == 1234)
- format.setByteOrder(QAudioFormat::LittleEndian);
- else if (endianness == 4321)
- format.setByteOrder(QAudioFormat::BigEndian);
-
- format.setSampleType(QAudioFormat::Float);
-
- int width = 0;
- gst_structure_get_int(structure, "width", &width);
-
- format.setSampleSize(width);
-
- int rate = 0;
- gst_structure_get_int(structure, "rate", &rate);
- format.setSampleRate(rate);
-
- int channels = 0;
- gst_structure_get_int(structure, "channels", &channels);
- format.setChannelCount(channels);
-
- } else {
- return QAudioFormat();
- }
-#endif
- return format;
-}
-
-#if GST_CHECK_VERSION(1,0,0)
-/*
- Returns audio format for a sample.
- If the buffer doesn't have a valid audio format, an empty QAudioFormat is returned.
-*/
-QAudioFormat QGstUtils::audioFormatForSample(GstSample *sample)
-{
- GstCaps* caps = gst_sample_get_caps(sample);
- if (!caps)
- return QAudioFormat();
-
- return QGstUtils::audioFormatForCaps(caps);
-}
-#else
-/*!
- Returns audio format for a buffer.
- If the buffer doesn't have a valid audio format, an empty QAudioFormat is returned.
-*/
-QAudioFormat QGstUtils::audioFormatForBuffer(GstBuffer *buffer)
-{
- GstCaps* caps = gst_buffer_get_caps(buffer);
- if (!caps)
- return QAudioFormat();
-
- QAudioFormat format = QGstUtils::audioFormatForCaps(caps);
- gst_caps_unref(caps);
- return format;
-}
-#endif
-
-/*!
- Builds GstCaps for an audio format.
- Returns 0 if the audio format is not valid.
- Caller must unref GstCaps.
-*/
-
-GstCaps *QGstUtils::capsForAudioFormat(const QAudioFormat &format)
-{
- if (!format.isValid())
- return 0;
-
-#if GST_CHECK_VERSION(1,0,0)
- const QAudioFormat::SampleType sampleType = format.sampleType();
- const QAudioFormat::Endian byteOrder = format.byteOrder();
- const int sampleSize = format.sampleSize();
-
- for (int i = 0; i < lengthOf(qt_audioLookup); ++i) {
- if (qt_audioLookup[i].sampleType != sampleType
- || qt_audioLookup[i].byteOrder != byteOrder
- || qt_audioLookup[i].sampleSize != sampleSize) {
- continue;
- }
-
- return gst_caps_new_simple(
- "audio/x-raw",
- "format" , G_TYPE_STRING, gst_audio_format_to_string(qt_audioLookup[i].format),
- "rate" , G_TYPE_INT , format.sampleRate(),
- "channels", G_TYPE_INT , format.channelCount(),
- nullptr);
- }
- return 0;
-#else
- GstStructure *structure = 0;
-
- if (format.isValid()) {
- if (format.sampleType() == QAudioFormat::SignedInt || format.sampleType() == QAudioFormat::UnSignedInt) {
- structure = gst_structure_new("audio/x-raw-int", nullptr);
- } else if (format.sampleType() == QAudioFormat::Float) {
- structure = gst_structure_new("audio/x-raw-float", nullptr);
- }
- }
-
- GstCaps *caps = 0;
-
- if (structure) {
- gst_structure_set(structure, "rate", G_TYPE_INT, format.sampleRate(), nullptr);
- gst_structure_set(structure, "channels", G_TYPE_INT, format.channelCount(), nullptr);
- gst_structure_set(structure, "width", G_TYPE_INT, format.sampleSize(), nullptr);
- gst_structure_set(structure, "depth", G_TYPE_INT, format.sampleSize(), nullptr);
-
- if (format.byteOrder() == QAudioFormat::LittleEndian)
- gst_structure_set(structure, "endianness", G_TYPE_INT, 1234, nullptr);
- else if (format.byteOrder() == QAudioFormat::BigEndian)
- gst_structure_set(structure, "endianness", G_TYPE_INT, 4321, nullptr);
-
- if (format.sampleType() == QAudioFormat::SignedInt)
- gst_structure_set(structure, "signed", G_TYPE_BOOLEAN, TRUE, nullptr);
- else if (format.sampleType() == QAudioFormat::UnSignedInt)
- gst_structure_set(structure, "signed", G_TYPE_BOOLEAN, FALSE, nullptr);
-
- caps = gst_caps_new_empty();
- Q_ASSERT(caps);
- gst_caps_append_structure(caps, structure);
- }
-
- return caps;
-#endif
-}
-
-void QGstUtils::initializeGst()
-{
- static bool initialized = false;
- if (!initialized) {
- initialized = true;
- gst_init(nullptr, nullptr);
- }
-}
-
-namespace {
- const char* getCodecAlias(const QString &codec)
- {
- if (codec.startsWith(QLatin1String("avc1.")))
- return "video/x-h264";
-
- if (codec.startsWith(QLatin1String("mp4a.")))
- return "audio/mpeg4";
-
- if (codec.startsWith(QLatin1String("mp4v.20.")))
- return "video/mpeg4";
-
- if (codec == QLatin1String("samr"))
- return "audio/amr";
-
- return 0;
- }
-
- const char* getMimeTypeAlias(const QString &mimeType)
- {
- if (mimeType == QLatin1String("video/mp4"))
- return "video/mpeg4";
-
- if (mimeType == QLatin1String("audio/mp4"))
- return "audio/mpeg4";
-
- if (mimeType == QLatin1String("video/ogg")
- || mimeType == QLatin1String("audio/ogg"))
- return "application/ogg";
-
- return 0;
- }
-}
-
-QMultimedia::SupportEstimate QGstUtils::hasSupport(const QString &mimeType,
- const QStringList &codecs,
- const QSet<QString> &supportedMimeTypeSet)
-{
- if (supportedMimeTypeSet.isEmpty())
- return QMultimedia::NotSupported;
-
- QString mimeTypeLowcase = mimeType.toLower();
- bool containsMimeType = supportedMimeTypeSet.contains(mimeTypeLowcase);
- if (!containsMimeType) {
- const char* mimeTypeAlias = getMimeTypeAlias(mimeTypeLowcase);
- containsMimeType = supportedMimeTypeSet.contains(QLatin1String(mimeTypeAlias));
- if (!containsMimeType) {
- containsMimeType = supportedMimeTypeSet.contains(QLatin1String("video/") + mimeTypeLowcase)
- || supportedMimeTypeSet.contains(QLatin1String("video/x-") + mimeTypeLowcase)
- || supportedMimeTypeSet.contains(QLatin1String("audio/") + mimeTypeLowcase)
- || supportedMimeTypeSet.contains(QLatin1String("audio/x-") + mimeTypeLowcase);
- }
- }
-
- int supportedCodecCount = 0;
- for (const QString &codec : codecs) {
- QString codecLowcase = codec.toLower();
- const char* codecAlias = getCodecAlias(codecLowcase);
- if (codecAlias) {
- if (supportedMimeTypeSet.contains(QLatin1String(codecAlias)))
- supportedCodecCount++;
- } else if (supportedMimeTypeSet.contains(QLatin1String("video/") + codecLowcase)
- || supportedMimeTypeSet.contains(QLatin1String("video/x-") + codecLowcase)
- || supportedMimeTypeSet.contains(QLatin1String("audio/") + codecLowcase)
- || supportedMimeTypeSet.contains(QLatin1String("audio/x-") + codecLowcase)) {
- supportedCodecCount++;
- }
- }
- if (supportedCodecCount > 0 && supportedCodecCount == codecs.size())
- return QMultimedia::ProbablySupported;
-
- if (supportedCodecCount == 0 && !containsMimeType)
- return QMultimedia::NotSupported;
-
- return QMultimedia::MaybeSupported;
-}
-
-namespace {
-
-typedef QHash<GstElementFactory *, QList<QGstUtils::CameraInfo>> FactoryCameraInfoMap;
-
-Q_GLOBAL_STATIC(FactoryCameraInfoMap, qt_camera_device_info);
-
-}
-
-QList<QGstUtils::CameraInfo> QGstUtils::enumerateCameras(GstElementFactory *factory)
-{
- static QElapsedTimer camerasCacheAgeTimer;
- if (camerasCacheAgeTimer.isValid() && camerasCacheAgeTimer.elapsed() > 500) // ms
- qt_camera_device_info()->clear();
-
- FactoryCameraInfoMap::const_iterator it = qt_camera_device_info()->constFind(factory);
- if (it != qt_camera_device_info()->constEnd())
- return *it;
-
- QList<CameraInfo> &devices = (*qt_camera_device_info())[factory];
-
- if (factory) {
- bool hasVideoSource = false;
-
- const GType type = gst_element_factory_get_element_type(factory);
- GObjectClass * const objectClass = type
- ? static_cast<GObjectClass *>(g_type_class_ref(type))
- : 0;
- if (objectClass) {
- if (g_object_class_find_property(objectClass, "camera-device")) {
- const CameraInfo primary = {
- QStringLiteral("primary"),
- QGstreamerVideoInputDeviceControl::primaryCamera(),
- 0,
- QCamera::BackFace,
- QByteArray()
- };
- const CameraInfo secondary = {
- QStringLiteral("secondary"),
- QGstreamerVideoInputDeviceControl::secondaryCamera(),
- 0,
- QCamera::FrontFace,
- QByteArray()
- };
-
- devices.append(primary);
- devices.append(secondary);
-
- GstElement *camera = g_object_class_find_property(objectClass, "sensor-mount-angle")
- ? gst_element_factory_create(factory, 0)
- : 0;
- if (camera) {
- if (gst_element_set_state(camera, GST_STATE_READY) != GST_STATE_CHANGE_SUCCESS) {
- // no-op
- } else for (int i = 0; i < 2; ++i) {
- gint orientation = 0;
- g_object_set(G_OBJECT(camera), "camera-device", i, nullptr);
- g_object_get(G_OBJECT(camera), "sensor-mount-angle", &orientation, nullptr);
-
- devices[i].orientation = (720 - orientation) % 360;
- }
- gst_element_set_state(camera, GST_STATE_NULL);
- gst_object_unref(GST_OBJECT(camera));
-
- }
- } else if (g_object_class_find_property(objectClass, "video-source")) {
- hasVideoSource = true;
- }
-
- g_type_class_unref(objectClass);
- }
-
- if (!devices.isEmpty() || !hasVideoSource) {
- camerasCacheAgeTimer.restart();
- return devices;
- }
- }
-
-#if QT_CONFIG(linux_v4l)
- QDir devDir(QStringLiteral("/dev"));
- devDir.setFilter(QDir::System);
-
- const QFileInfoList entries = devDir.entryInfoList(QStringList()
- << QStringLiteral("video*"));
-
- for (const QFileInfo &entryInfo : entries) {
- //qDebug() << "Try" << entryInfo.filePath();
-
- int fd = qt_safe_open(entryInfo.filePath().toLatin1().constData(), O_RDWR );
- if (fd == -1)
- continue;
-
- bool isCamera = false;
-
- v4l2_input input;
- memset(&input, 0, sizeof(input));
- for (; ::ioctl(fd, VIDIOC_ENUMINPUT, &input) >= 0; ++input.index) {
- if (input.type == V4L2_INPUT_TYPE_CAMERA || input.type == 0) {
- const int ret = ::ioctl(fd, VIDIOC_S_INPUT, &input.index);
- isCamera = (ret == 0 || errno == ENOTTY || errno == EBUSY);
- break;
- }
- }
-
- if (isCamera) {
- // find out its driver "name"
- QByteArray driver;
- QString name;
- struct v4l2_capability vcap;
- memset(&vcap, 0, sizeof(struct v4l2_capability));
-
- if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) != 0) {
- name = entryInfo.fileName();
- } else {
- driver = QByteArray((const char*)vcap.driver);
- name = QString::fromUtf8((const char*)vcap.card);
- if (name.isEmpty())
- name = entryInfo.fileName();
- }
- //qDebug() << "found camera: " << name;
-
-
- CameraInfo device = {
- entryInfo.absoluteFilePath(),
- name,
- 0,
- QCamera::UnspecifiedPosition,
- driver
- };
- devices.append(device);
- }
- qt_safe_close(fd);
- }
- camerasCacheAgeTimer.restart();
-#endif // linux_v4l
-
-#if GST_CHECK_VERSION(1,4,0) && (defined(Q_OS_WIN) || defined(Q_OS_MACOS))
- if (!devices.isEmpty())
- return devices;
-
-#if defined(Q_OS_WIN)
- const char *propName = "device-path";
- auto deviceDesc = [](GValue *value) {
- gchar *desc = g_value_dup_string(value);
- const QString id = QLatin1String(desc);
- g_free(desc);
- return id;
- };
-#elif defined(Q_OS_MACOS)
- const char *propName = "device-index";
- auto deviceDesc = [](GValue *value) {
- return QString::number(g_value_get_int(value));
- };
-#endif
-
- QGstUtils::initializeGst();
- GstDeviceMonitor *monitor = gst_device_monitor_new();
- auto caps = gst_caps_new_empty_simple("video/x-raw");
- gst_device_monitor_add_filter(monitor, "Video/Source", caps);
- gst_caps_unref(caps);
-
- GList *devs = gst_device_monitor_get_devices(monitor);
- while (devs) {
- GstDevice *dev = reinterpret_cast<GstDevice*>(devs->data);
- GstElement *element = gst_device_create_element(dev, nullptr);
- if (element) {
- gchar *name = gst_device_get_display_name(dev);
- const QString deviceName = QLatin1String(name);
- g_free(name);
- GParamSpec *prop = g_object_class_find_property(G_OBJECT_GET_CLASS(element), propName);
- if (prop) {
- GValue value = G_VALUE_INIT;
- g_value_init(&value, prop->value_type);
- g_object_get_property(G_OBJECT(element), prop->name, &value);
- const QString deviceId = deviceDesc(&value);
- g_value_unset(&value);
-
- CameraInfo device = {
- deviceId,
- deviceName,
- 0,
- QCamera::UnspecifiedPosition,
- QByteArray()
- };
-
- devices.append(device);
- }
-
- gst_object_unref(element);
- }
-
- gst_object_unref(dev);
- devs = g_list_delete_link(devs, devs);
- }
- gst_object_unref(monitor);
-#endif // GST_CHECK_VERSION(1,4,0) && (defined(Q_OS_WIN) || defined(Q_OS_MACOS))
-
- return devices;
-}
-
-QList<QByteArray> QGstUtils::cameraDevices(GstElementFactory * factory)
-{
- QList<QByteArray> devices;
-
- const auto cameras = enumerateCameras(factory);
- devices.reserve(cameras.size());
- for (const CameraInfo &camera : cameras)
- devices.append(camera.name.toUtf8());
-
- return devices;
-}
-
-QString QGstUtils::cameraDescription(const QString &device, GstElementFactory * factory)
-{
- const auto cameras = enumerateCameras(factory);
- for (const CameraInfo &camera : cameras) {
- if (camera.name == device)
- return camera.description;
- }
- return QString();
-}
-
-QCamera::Position QGstUtils::cameraPosition(const QString &device, GstElementFactory * factory)
-{
- const auto cameras = enumerateCameras(factory);
- for (const CameraInfo &camera : cameras) {
- if (camera.name == device)
- return camera.position;
- }
- return QCamera::UnspecifiedPosition;
-}
-
-int QGstUtils::cameraOrientation(const QString &device, GstElementFactory * factory)
-{
- const auto cameras = enumerateCameras(factory);
- for (const CameraInfo &camera : cameras) {
- if (camera.name == device)
- return camera.orientation;
- }
- return 0;
-}
-
-QByteArray QGstUtils::cameraDriver(const QString &device, GstElementFactory *factory)
-{
- const auto cameras = enumerateCameras(factory);
- for (const CameraInfo &camera : cameras) {
- if (camera.name == device)
- return camera.driver;
- }
- return QByteArray();
-}
-
-QSet<QString> QGstUtils::supportedMimeTypes(bool (*isValidFactory)(GstElementFactory *factory))
-{
- QSet<QString> supportedMimeTypes;
-
- //enumerate supported mime types
- gst_init(nullptr, nullptr);
-
-#if GST_CHECK_VERSION(1,0,0)
- GstRegistry *registry = gst_registry_get();
- GList *orig_plugins = gst_registry_get_plugin_list(registry);
-#else
- GstRegistry *registry = gst_registry_get_default();
- GList *orig_plugins = gst_default_registry_get_plugin_list ();
-#endif
- for (GList *plugins = orig_plugins; plugins; plugins = g_list_next(plugins)) {
- GstPlugin *plugin = (GstPlugin *) (plugins->data);
-#if GST_CHECK_VERSION(1,0,0)
- if (GST_OBJECT_FLAG_IS_SET(GST_OBJECT(plugin), GST_PLUGIN_FLAG_BLACKLISTED))
- continue;
-#else
- if (plugin->flags & (1<<1)) //GST_PLUGIN_FLAG_BLACKLISTED
- continue;
-#endif
-
- GList *orig_features = gst_registry_get_feature_list_by_plugin(
- registry, gst_plugin_get_name(plugin));
- for (GList *features = orig_features; features; features = g_list_next(features)) {
- if (G_UNLIKELY(features->data == nullptr))
- continue;
-
- GstPluginFeature *feature = GST_PLUGIN_FEATURE(features->data);
- GstElementFactory *factory;
-
- if (GST_IS_TYPE_FIND_FACTORY(feature)) {
- QString name(QLatin1String(gst_plugin_feature_get_name(feature)));
- if (name.contains(QLatin1Char('/'))) //filter out any string without '/' which is obviously not a mime type
- supportedMimeTypes.insert(name.toLower());
- continue;
- } else if (!GST_IS_ELEMENT_FACTORY (feature)
- || !(factory = GST_ELEMENT_FACTORY(gst_plugin_feature_load(feature)))) {
- continue;
- } else if (!isValidFactory(factory)) {
- // Do nothing
- } else for (const GList *pads = gst_element_factory_get_static_pad_templates(factory);
- pads;
- pads = g_list_next(pads)) {
- GstStaticPadTemplate *padtemplate = static_cast<GstStaticPadTemplate *>(pads->data);
-
- if (padtemplate->direction == GST_PAD_SINK && padtemplate->static_caps.string) {
- GstCaps *caps = gst_static_caps_get(&padtemplate->static_caps);
- if (gst_caps_is_any(caps) || gst_caps_is_empty(caps)) {
- } else for (guint i = 0; i < gst_caps_get_size(caps); i++) {
- GstStructure *structure = gst_caps_get_structure(caps, i);
- QString nameLowcase = QString::fromLatin1(gst_structure_get_name(structure)).toLower();
-
- supportedMimeTypes.insert(nameLowcase);
- if (nameLowcase.contains(QLatin1String("mpeg"))) {
- //Because mpeg version number is only included in the detail
- //description, it is necessary to manually extract this information
- //in order to match the mime type of mpeg4.
- const GValue *value = gst_structure_get_value(structure, "mpegversion");
- if (value) {
- gchar *str = gst_value_serialize(value);
- QString versions = QLatin1String(str);
- const QStringList elements = versions.split(QRegularExpression(QLatin1String("\\D+")), Qt::SkipEmptyParts);
- for (const QString &e : elements)
- supportedMimeTypes.insert(nameLowcase + e);
- g_free(str);
- }
- }
- }
- }
- }
- gst_object_unref(factory);
- }
- gst_plugin_feature_list_free(orig_features);
- }
- gst_plugin_list_free (orig_plugins);
-
-#if defined QT_SUPPORTEDMIMETYPES_DEBUG
- QStringList list = supportedMimeTypes.toList();
- list.sort();
- if (qgetenv("QT_DEBUG_PLUGINS").toInt() > 0) {
- for (const QString &type : qAsConst(list))
- qDebug() << type;
- }
-#endif
- return supportedMimeTypes;
-}
-
-#if GST_CHECK_VERSION(1, 0, 0)
-namespace {
-
-struct ColorFormat { QImage::Format imageFormat; GstVideoFormat gstFormat; };
-static const ColorFormat qt_colorLookup[] =
-{
- { QImage::Format_RGBX8888, GST_VIDEO_FORMAT_RGBx },
- { QImage::Format_RGBA8888, GST_VIDEO_FORMAT_RGBA },
- { QImage::Format_RGB888 , GST_VIDEO_FORMAT_RGB },
- { QImage::Format_RGB16 , GST_VIDEO_FORMAT_RGB16 }
-};
-
-}
-#endif
-
-#if GST_CHECK_VERSION(1,0,0)
-QImage QGstUtils::bufferToImage(GstBuffer *buffer, const GstVideoInfo &videoInfo)
-#else
-QImage QGstUtils::bufferToImage(GstBuffer *buffer)
-#endif
-{
- QImage img;
-
-#if GST_CHECK_VERSION(1,0,0)
- GstVideoInfo info = videoInfo;
- GstVideoFrame frame;
- if (!gst_video_frame_map(&frame, &info, buffer, GST_MAP_READ))
- return img;
-#else
- GstCaps *caps = gst_buffer_get_caps(buffer);
- if (!caps)
- return img;
-
- GstStructure *structure = gst_caps_get_structure (caps, 0);
- gint width = 0;
- gint height = 0;
-
- if (!structure
- || !gst_structure_get_int(structure, "width", &width)
- || !gst_structure_get_int(structure, "height", &height)
- || width <= 0
- || height <= 0) {
- gst_caps_unref(caps);
- return img;
- }
- gst_caps_unref(caps);
-#endif
-
-#if GST_CHECK_VERSION(1,0,0)
- if (videoInfo.finfo->format == GST_VIDEO_FORMAT_I420) {
- const int width = videoInfo.width;
- const int height = videoInfo.height;
-
- const int stride[] = { frame.info.stride[0], frame.info.stride[1], frame.info.stride[2] };
- const uchar *data[] = {
- static_cast<const uchar *>(frame.data[0]),
- static_cast<const uchar *>(frame.data[1]),
- static_cast<const uchar *>(frame.data[2])
- };
-#else
- if (qstrcmp(gst_structure_get_name(structure), "video/x-raw-yuv") == 0) {
- const int stride[] = { width, width / 2, width / 2 };
- const uchar *data[] = {
- (const uchar *)buffer->data,
- (const uchar *)buffer->data + width * height,
- (const uchar *)buffer->data + width * height * 5 / 4
- };
-#endif
- img = QImage(width/2, height/2, QImage::Format_RGB32);
-
- for (int y=0; y<height; y+=2) {
- const uchar *yLine = data[0] + (y * stride[0]);
- const uchar *uLine = data[1] + (y * stride[1] / 2);
- const uchar *vLine = data[2] + (y * stride[2] / 2);
-
- for (int x=0; x<width; x+=2) {
- const qreal Y = 1.164*(yLine[x]-16);
- const int U = uLine[x/2]-128;
- const int V = vLine[x/2]-128;
-
- int b = qBound(0, int(Y + 2.018*U), 255);
- int g = qBound(0, int(Y - 0.813*V - 0.391*U), 255);
- int r = qBound(0, int(Y + 1.596*V), 255);
-
- img.setPixel(x/2,y/2,qRgb(r,g,b));
- }
- }
-#if GST_CHECK_VERSION(1,0,0)
- } else for (int i = 0; i < lengthOf(qt_colorLookup); ++i) {
- if (qt_colorLookup[i].gstFormat != videoInfo.finfo->format)
- continue;
-
- const QImage image(
- static_cast<const uchar *>(frame.data[0]),
- videoInfo.width,
- videoInfo.height,
- frame.info.stride[0],
- qt_colorLookup[i].imageFormat);
- img = image;
- img.detach();
-
- break;
- }
-
- gst_video_frame_unmap(&frame);
-#else
- } else if (qstrcmp(gst_structure_get_name(structure), "video/x-raw-rgb") == 0) {
- QImage::Format format = QImage::Format_Invalid;
- int bpp = 0;
- gst_structure_get_int(structure, "bpp", &bpp);
-
- if (bpp == 24)
- format = QImage::Format_RGB888;
- else if (bpp == 32)
- format = QImage::Format_RGB32;
-
- if (format != QImage::Format_Invalid) {
- img = QImage((const uchar *)buffer->data,
- width,
- height,
- format);
- img.bits(); //detach
- }
- }
-#endif
- return img;
-}
-
-
-namespace {
-
-#if GST_CHECK_VERSION(1,0,0)
-
-struct VideoFormat
-{
- QVideoFrame::PixelFormat pixelFormat;
- GstVideoFormat gstFormat;
-};
-
-static const VideoFormat qt_videoFormatLookup[] =
-{
- { QVideoFrame::Format_YUV420P, GST_VIDEO_FORMAT_I420 },
- { QVideoFrame::Format_YUV422P, GST_VIDEO_FORMAT_Y42B },
- { QVideoFrame::Format_YV12 , GST_VIDEO_FORMAT_YV12 },
- { QVideoFrame::Format_UYVY , GST_VIDEO_FORMAT_UYVY },
- { QVideoFrame::Format_YUYV , GST_VIDEO_FORMAT_YUY2 },
- { QVideoFrame::Format_NV12 , GST_VIDEO_FORMAT_NV12 },
- { QVideoFrame::Format_NV21 , GST_VIDEO_FORMAT_NV21 },
- { QVideoFrame::Format_AYUV444, GST_VIDEO_FORMAT_AYUV },
-#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
- { QVideoFrame::Format_RGB32 , GST_VIDEO_FORMAT_BGRx },
- { QVideoFrame::Format_BGR32 , GST_VIDEO_FORMAT_RGBx },
- { QVideoFrame::Format_ARGB32, GST_VIDEO_FORMAT_BGRA },
- { QVideoFrame::Format_ABGR32, GST_VIDEO_FORMAT_RGBA },
- { QVideoFrame::Format_BGRA32, GST_VIDEO_FORMAT_ARGB },
-#else
- { QVideoFrame::Format_RGB32 , GST_VIDEO_FORMAT_xRGB },
- { QVideoFrame::Format_BGR32 , GST_VIDEO_FORMAT_xBGR },
- { QVideoFrame::Format_ARGB32, GST_VIDEO_FORMAT_ARGB },
- { QVideoFrame::Format_ABGR32, GST_VIDEO_FORMAT_ABGR },
- { QVideoFrame::Format_BGRA32, GST_VIDEO_FORMAT_BGRA },
-#endif
- { QVideoFrame::Format_RGB24 , GST_VIDEO_FORMAT_RGB },
- { QVideoFrame::Format_BGR24 , GST_VIDEO_FORMAT_BGR },
- { QVideoFrame::Format_RGB565, GST_VIDEO_FORMAT_RGB16 }
-};
-
-static int indexOfVideoFormat(QVideoFrame::PixelFormat format)
-{
- for (int i = 0; i < lengthOf(qt_videoFormatLookup); ++i)
- if (qt_videoFormatLookup[i].pixelFormat == format)
- return i;
-
- return -1;
-}
-
-static int indexOfVideoFormat(GstVideoFormat format)
-{
- for (int i = 0; i < lengthOf(qt_videoFormatLookup); ++i)
- if (qt_videoFormatLookup[i].gstFormat == format)
- return i;
-
- return -1;
-}
-
-#else
-
-struct YuvFormat
-{
- QVideoFrame::PixelFormat pixelFormat;
- guint32 fourcc;
- int bitsPerPixel;
-};
-
-static const YuvFormat qt_yuvColorLookup[] =
-{
- { QVideoFrame::Format_YUV420P, GST_MAKE_FOURCC('I','4','2','0'), 8 },
- { QVideoFrame::Format_YUV422P, GST_MAKE_FOURCC('Y','4','2','B'), 8 },
- { QVideoFrame::Format_YV12, GST_MAKE_FOURCC('Y','V','1','2'), 8 },
- { QVideoFrame::Format_UYVY, GST_MAKE_FOURCC('U','Y','V','Y'), 16 },
- { QVideoFrame::Format_YUYV, GST_MAKE_FOURCC('Y','U','Y','2'), 16 },
- { QVideoFrame::Format_NV12, GST_MAKE_FOURCC('N','V','1','2'), 8 },
- { QVideoFrame::Format_NV21, GST_MAKE_FOURCC('N','V','2','1'), 8 },
- { QVideoFrame::Format_AYUV444, GST_MAKE_FOURCC('A','Y','U','V'), 32 }
-};
-
-static int indexOfYuvColor(QVideoFrame::PixelFormat format)
-{
- const int count = sizeof(qt_yuvColorLookup) / sizeof(YuvFormat);
-
- for (int i = 0; i < count; ++i)
- if (qt_yuvColorLookup[i].pixelFormat == format)
- return i;
-
- return -1;
-}
-
-static int indexOfYuvColor(guint32 fourcc)
-{
- const int count = sizeof(qt_yuvColorLookup) / sizeof(YuvFormat);
-
- for (int i = 0; i < count; ++i)
- if (qt_yuvColorLookup[i].fourcc == fourcc)
- return i;
-
- return -1;
-}
-
-struct RgbFormat
-{
- QVideoFrame::PixelFormat pixelFormat;
- int bitsPerPixel;
- int depth;
- int endianness;
- int red;
- int green;
- int blue;
- int alpha;
-};
-
-static const RgbFormat qt_rgbColorLookup[] =
-{
- { QVideoFrame::Format_RGB32 , 32, 24, 4321, 0x0000FF00, 0x00FF0000, int(0xFF000000), 0x00000000 },
- { QVideoFrame::Format_RGB32 , 32, 24, 1234, 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 },
- { QVideoFrame::Format_BGR32 , 32, 24, 4321, int(0xFF000000), 0x00FF0000, 0x0000FF00, 0x00000000 },
- { QVideoFrame::Format_BGR32 , 32, 24, 1234, 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 },
- { QVideoFrame::Format_ARGB32, 32, 24, 4321, 0x0000FF00, 0x00FF0000, int(0xFF000000), 0x000000FF },
- { QVideoFrame::Format_ARGB32, 32, 24, 1234, 0x00FF0000, 0x0000FF00, 0x000000FF, int(0xFF000000) },
- { QVideoFrame::Format_RGB24 , 24, 24, 4321, 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 },
- { QVideoFrame::Format_BGR24 , 24, 24, 4321, 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 },
- { QVideoFrame::Format_RGB565, 16, 16, 1234, 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }
-};
-
-static int indexOfRgbColor(
- int bits, int depth, int endianness, int red, int green, int blue, int alpha)
-{
- const int count = sizeof(qt_rgbColorLookup) / sizeof(RgbFormat);
-
- for (int i = 0; i < count; ++i) {
- if (qt_rgbColorLookup[i].bitsPerPixel == bits
- && qt_rgbColorLookup[i].depth == depth
- && qt_rgbColorLookup[i].endianness == endianness
- && qt_rgbColorLookup[i].red == red
- && qt_rgbColorLookup[i].green == green
- && qt_rgbColorLookup[i].blue == blue
- && qt_rgbColorLookup[i].alpha == alpha) {
- return i;
- }
- }
- return -1;
-}
-#endif
-
-}
-
-#if GST_CHECK_VERSION(1,0,0)
-
-QVideoSurfaceFormat QGstUtils::formatForCaps(
- GstCaps *caps, GstVideoInfo *info, QAbstractVideoBuffer::HandleType handleType)
-{
- GstVideoInfo vidInfo;
- GstVideoInfo *infoPtr = info ? info : &vidInfo;
-
- if (gst_video_info_from_caps(infoPtr, caps)) {
- int index = indexOfVideoFormat(infoPtr->finfo->format);
-
- if (index != -1) {
- QVideoSurfaceFormat format(
- QSize(infoPtr->width, infoPtr->height),
- qt_videoFormatLookup[index].pixelFormat,
- handleType);
-
- if (infoPtr->fps_d > 0)
- format.setFrameRate(qreal(infoPtr->fps_n) / infoPtr->fps_d);
-
- if (infoPtr->par_d > 0)
- format.setPixelAspectRatio(infoPtr->par_n, infoPtr->par_d);
-
- return format;
- }
- }
- return QVideoSurfaceFormat();
-}
-
-#else
-
-QVideoSurfaceFormat QGstUtils::formatForCaps(
- GstCaps *caps, int *bytesPerLine, QAbstractVideoBuffer::HandleType handleType)
-{
- const GstStructure *structure = gst_caps_get_structure(caps, 0);
-
- int bitsPerPixel = 0;
- QSize size = structureResolution(structure);
- QVideoFrame::PixelFormat pixelFormat = structurePixelFormat(structure, &bitsPerPixel);
-
- if (pixelFormat != QVideoFrame::Format_Invalid) {
- QVideoSurfaceFormat format(size, pixelFormat, handleType);
-
- QPair<qreal, qreal> rate = structureFrameRateRange(structure);
- if (rate.second)
- format.setFrameRate(rate.second);
-
- format.setPixelAspectRatio(structurePixelAspectRatio(structure));
-
- if (bytesPerLine)
- *bytesPerLine = ((size.width() * bitsPerPixel / 8) + 3) & ~3;
-
- return format;
- }
- return QVideoSurfaceFormat();
-}
-
-#endif
-
-GstCaps *QGstUtils::capsForFormats(const QList<QVideoFrame::PixelFormat> &formats)
-{
- GstCaps *caps = gst_caps_new_empty();
-
-#if GST_CHECK_VERSION(1,0,0)
- for (QVideoFrame::PixelFormat format : formats) {
- int index = indexOfVideoFormat(format);
-
- if (index != -1) {
- gst_caps_append_structure(caps, gst_structure_new(
- "video/x-raw",
- "format" , G_TYPE_STRING, gst_video_format_to_string(qt_videoFormatLookup[index].gstFormat),
- nullptr));
- }
- }
-#else
- for (QVideoFrame::PixelFormat format : formats) {
- int index = indexOfYuvColor(format);
-
- if (index != -1) {
- gst_caps_append_structure(caps, gst_structure_new(
- "video/x-raw-yuv",
- "format", GST_TYPE_FOURCC, qt_yuvColorLookup[index].fourcc,
- nullptr));
- continue;
- }
-
- const int count = sizeof(qt_rgbColorLookup) / sizeof(RgbFormat);
-
- for (int i = 0; i < count; ++i) {
- if (qt_rgbColorLookup[i].pixelFormat == format) {
- GstStructure *structure = gst_structure_new(
- "video/x-raw-rgb",
- "bpp" , G_TYPE_INT, qt_rgbColorLookup[i].bitsPerPixel,
- "depth" , G_TYPE_INT, qt_rgbColorLookup[i].depth,
- "endianness", G_TYPE_INT, qt_rgbColorLookup[i].endianness,
- "red_mask" , G_TYPE_INT, qt_rgbColorLookup[i].red,
- "green_mask", G_TYPE_INT, qt_rgbColorLookup[i].green,
- "blue_mask" , G_TYPE_INT, qt_rgbColorLookup[i].blue,
- nullptr);
-
- if (qt_rgbColorLookup[i].alpha != 0) {
- gst_structure_set(
- structure, "alpha_mask", G_TYPE_INT, qt_rgbColorLookup[i].alpha, nullptr);
- }
- gst_caps_append_structure(caps, structure);
- }
- }
- }
-#endif
-
- gst_caps_set_simple(
- caps,
- "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, INT_MAX, 1,
- "width" , GST_TYPE_INT_RANGE, 1, INT_MAX,
- "height" , GST_TYPE_INT_RANGE, 1, INT_MAX,
- nullptr);
-
- return caps;
-}
-
-void QGstUtils::setFrameTimeStamps(QVideoFrame *frame, GstBuffer *buffer)
-{
- // GStreamer uses nanoseconds, Qt uses microseconds
- qint64 startTime = GST_BUFFER_TIMESTAMP(buffer);
- if (startTime >= 0) {
- frame->setStartTime(startTime/G_GINT64_CONSTANT (1000));
-
- qint64 duration = GST_BUFFER_DURATION(buffer);
- if (duration >= 0)
- frame->setEndTime((startTime + duration)/G_GINT64_CONSTANT (1000));
- }
-}
-
-void QGstUtils::setMetaData(GstElement *element, const QMap<QByteArray, QVariant> &data)
-{
- if (!GST_IS_TAG_SETTER(element))
- return;
-
- gst_tag_setter_reset_tags(GST_TAG_SETTER(element));
-
- for (auto it = data.cbegin(), end = data.cend(); it != end; ++it) {
- const QString tagName = QString::fromLatin1(it.key());
- const QVariant &tagValue = it.value();
-
- switch (tagValue.type()) {
- case QVariant::String:
- gst_tag_setter_add_tags(GST_TAG_SETTER(element),
- GST_TAG_MERGE_REPLACE,
- tagName.toUtf8().constData(),
- tagValue.toString().toUtf8().constData(),
- nullptr);
- break;
- case QVariant::Int:
- case QVariant::LongLong:
- gst_tag_setter_add_tags(GST_TAG_SETTER(element),
- GST_TAG_MERGE_REPLACE,
- tagName.toUtf8().constData(),
- tagValue.toInt(),
- nullptr);
- break;
- case QVariant::Double:
- gst_tag_setter_add_tags(GST_TAG_SETTER(element),
- GST_TAG_MERGE_REPLACE,
- tagName.toUtf8().constData(),
- tagValue.toDouble(),
- nullptr);
- break;
-#if GST_CHECK_VERSION(0, 10, 31)
- case QVariant::DateTime: {
- QDateTime date = tagValue.toDateTime().toLocalTime();
- gst_tag_setter_add_tags(GST_TAG_SETTER(element),
- GST_TAG_MERGE_REPLACE,
- tagName.toUtf8().constData(),
- gst_date_time_new_local_time(
- date.date().year(), date.date().month(), date.date().day(),
- date.time().hour(), date.time().minute(), date.time().second()),
- nullptr);
- break;
- }
-#endif
- default:
- break;
- }
- }
-}
-
-void QGstUtils::setMetaData(GstBin *bin, const QMap<QByteArray, QVariant> &data)
-{
- GstIterator *elements = gst_bin_iterate_all_by_interface(bin, GST_TYPE_TAG_SETTER);
-#if GST_CHECK_VERSION(1,0,0)
- GValue item = G_VALUE_INIT;
- while (gst_iterator_next(elements, &item) == GST_ITERATOR_OK) {
- GstElement * const element = GST_ELEMENT(g_value_get_object(&item));
-#else
- GstElement *element = 0;
- while (gst_iterator_next(elements, (void**)&element) == GST_ITERATOR_OK) {
-#endif
- setMetaData(element, data);
- }
- gst_iterator_free(elements);
-}
-
-
-GstCaps *QGstUtils::videoFilterCaps()
-{
- const char *caps =
-#if GST_CHECK_VERSION(1,2,0)
- "video/x-raw(ANY);"
-#elif GST_CHECK_VERSION(1,0,0)
- "video/x-raw;"
-#else
- "video/x-raw-yuv;"
- "video/x-raw-rgb;"
- "video/x-raw-data;"
- "video/x-android-buffer;"
-#endif
- "image/jpeg;"
- "video/x-h264";
- static GstStaticCaps staticCaps = GST_STATIC_CAPS(caps);
-
- return gst_caps_make_writable(gst_static_caps_get(&staticCaps));
-}
-
-QSize QGstUtils::structureResolution(const GstStructure *s)
-{
- QSize size;
-
- int w, h;
- if (s && gst_structure_get_int(s, "width", &w) && gst_structure_get_int(s, "height", &h)) {
- size.rwidth() = w;
- size.rheight() = h;
- }
-
- return size;
-}
-
-QVideoFrame::PixelFormat QGstUtils::structurePixelFormat(const GstStructure *structure, int *bpp)
-{
- QVideoFrame::PixelFormat pixelFormat = QVideoFrame::Format_Invalid;
-
- if (!structure)
- return pixelFormat;
-
-#if GST_CHECK_VERSION(1,0,0)
- Q_UNUSED(bpp);
-
- if (gst_structure_has_name(structure, "video/x-raw")) {
- const gchar *s = gst_structure_get_string(structure, "format");
- if (s) {
- GstVideoFormat format = gst_video_format_from_string(s);
- int index = indexOfVideoFormat(format);
-
- if (index != -1)
- pixelFormat = qt_videoFormatLookup[index].pixelFormat;
- }
- }
-#else
- if (qstrcmp(gst_structure_get_name(structure), "video/x-raw-yuv") == 0) {
- guint32 fourcc = 0;
- gst_structure_get_fourcc(structure, "format", &fourcc);
-
- int index = indexOfYuvColor(fourcc);
- if (index != -1) {
- pixelFormat = qt_yuvColorLookup[index].pixelFormat;
- if (bpp)
- *bpp = qt_yuvColorLookup[index].bitsPerPixel;
- }
- } else if (qstrcmp(gst_structure_get_name(structure), "video/x-raw-rgb") == 0) {
- int bitsPerPixel = 0;
- int depth = 0;
- int endianness = 0;
- int red = 0;
- int green = 0;
- int blue = 0;
- int alpha = 0;
-
- gst_structure_get_int(structure, "bpp", &bitsPerPixel);
- gst_structure_get_int(structure, "depth", &depth);
- gst_structure_get_int(structure, "endianness", &endianness);
- gst_structure_get_int(structure, "red_mask", &red);
- gst_structure_get_int(structure, "green_mask", &green);
- gst_structure_get_int(structure, "blue_mask", &blue);
- gst_structure_get_int(structure, "alpha_mask", &alpha);
-
- int index = indexOfRgbColor(bitsPerPixel, depth, endianness, red, green, blue, alpha);
-
- if (index != -1) {
- pixelFormat = qt_rgbColorLookup[index].pixelFormat;
- if (bpp)
- *bpp = qt_rgbColorLookup[index].bitsPerPixel;
- }
- }
-#endif
-
- return pixelFormat;
-}
-
-QSize QGstUtils::structurePixelAspectRatio(const GstStructure *s)
-{
- QSize ratio(1, 1);
-
- gint aspectNum = 0;
- gint aspectDenum = 0;
- if (s && gst_structure_get_fraction(s, "pixel-aspect-ratio", &aspectNum, &aspectDenum)) {
- if (aspectDenum > 0) {
- ratio.rwidth() = aspectNum;
- ratio.rheight() = aspectDenum;
- }
- }
-
- return ratio;
-}
-
-QPair<qreal, qreal> QGstUtils::structureFrameRateRange(const GstStructure *s)
-{
- QPair<qreal, qreal> rate;
-
- if (!s)
- return rate;
-
- int n, d;
- if (gst_structure_get_fraction(s, "framerate", &n, &d)) {
- rate.second = qreal(n) / d;
- rate.first = rate.second;
- } else if (gst_structure_get_fraction(s, "max-framerate", &n, &d)) {
- rate.second = qreal(n) / d;
- if (gst_structure_get_fraction(s, "min-framerate", &n, &d))
- rate.first = qreal(n) / d;
- else
- rate.first = qreal(1);
- }
-
- return rate;
-}
-
-typedef QMap<QString, QString> FileExtensionMap;
-Q_GLOBAL_STATIC(FileExtensionMap, fileExtensionMap)
-
-QString QGstUtils::fileExtensionForMimeType(const QString &mimeType)
-{
- if (fileExtensionMap->isEmpty()) {
- //extension for containers hard to guess from mimetype
- fileExtensionMap->insert(QStringLiteral("video/x-matroska"), QLatin1String("mkv"));
- fileExtensionMap->insert(QStringLiteral("video/quicktime"), QLatin1String("mov"));
- fileExtensionMap->insert(QStringLiteral("video/x-msvideo"), QLatin1String("avi"));
- fileExtensionMap->insert(QStringLiteral("video/msvideo"), QLatin1String("avi"));
- fileExtensionMap->insert(QStringLiteral("audio/mpeg"), QLatin1String("mp3"));
- fileExtensionMap->insert(QStringLiteral("application/x-shockwave-flash"), QLatin1String("swf"));
- fileExtensionMap->insert(QStringLiteral("application/x-pn-realmedia"), QLatin1String("rm"));
- }
-
- //for container names like avi instead of video/x-msvideo, use it as extension
- if (!mimeType.contains(QLatin1Char('/')))
- return mimeType;
-
- QString format = mimeType.left(mimeType.indexOf(QLatin1Char(',')));
- QString extension = fileExtensionMap->value(format);
-
- if (!extension.isEmpty() || format.isEmpty())
- return extension;
-
- QRegularExpression rx(QStringLiteral("[-/]([\\w]+)$"));
- QRegularExpressionMatch match = rx.match(format);
-
- if (match.hasMatch())
- extension = match.captured(1);
-
- return extension;
-}
-
-#if GST_CHECK_VERSION(0,10,30)
-QVariant QGstUtils::fromGStreamerOrientation(const QVariant &value)
-{
- // Note gstreamer tokens either describe the counter clockwise rotation of the
- // image or the clockwise transform to apply to correct the image. The orientation
- // value returned is the clockwise rotation of the image.
- const QString token = value.toString();
- if (token == QStringLiteral("rotate-90"))
- return 270;
- if (token == QStringLiteral("rotate-180"))
- return 180;
- if (token == QStringLiteral("rotate-270"))
- return 90;
- return 0;
-}
-
-QVariant QGstUtils::toGStreamerOrientation(const QVariant &value)
-{
- switch (value.toInt()) {
- case 90:
- return QStringLiteral("rotate-270");
- case 180:
- return QStringLiteral("rotate-180");
- case 270:
- return QStringLiteral("rotate-90");
- default:
- return QStringLiteral("rotate-0");
- }
-}
-#endif
-
-bool QGstUtils::useOpenGL()
-{
- static bool result = qEnvironmentVariableIntValue("QT_GSTREAMER_USE_OPENGL_PLUGIN");
- return result;
-}
-
-void qt_gst_object_ref_sink(gpointer object)
-{
-#if GST_CHECK_VERSION(0,10,24)
- gst_object_ref_sink(object);
-#else
- g_return_if_fail (GST_IS_OBJECT(object));
-
- GST_OBJECT_LOCK(object);
- if (G_LIKELY(GST_OBJECT_IS_FLOATING(object))) {
- GST_OBJECT_FLAG_UNSET(object, GST_OBJECT_FLOATING);
- GST_OBJECT_UNLOCK(object);
- } else {
- GST_OBJECT_UNLOCK(object);
- gst_object_ref(object);
- }
-#endif
-}
-
-GstCaps *qt_gst_pad_get_current_caps(GstPad *pad)
-{
-#if GST_CHECK_VERSION(1,0,0)
- return gst_pad_get_current_caps(pad);
-#else
- return gst_pad_get_negotiated_caps(pad);
-#endif
-}
-
-GstCaps *qt_gst_pad_get_caps(GstPad *pad)
-{
-#if GST_CHECK_VERSION(1,0,0)
- return gst_pad_query_caps(pad, nullptr);
-#elif GST_CHECK_VERSION(0, 10, 26)
- return gst_pad_get_caps_reffed(pad);
-#else
- return gst_pad_get_caps(pad);
-#endif
-}
-
-GstStructure *qt_gst_structure_new_empty(const char *name)
-{
-#if GST_CHECK_VERSION(1,0,0)
- return gst_structure_new_empty(name);
-#else
- return gst_structure_new(name, nullptr);
-#endif
-}
-
-gboolean qt_gst_element_query_position(GstElement *element, GstFormat format, gint64 *cur)
-{
-#if GST_CHECK_VERSION(1,0,0)
- return gst_element_query_position(element, format, cur);
-#else
- return gst_element_query_position(element, &format, cur);
-#endif
-}
-
-gboolean qt_gst_element_query_duration(GstElement *element, GstFormat format, gint64 *cur)
-{
-#if GST_CHECK_VERSION(1,0,0)
- return gst_element_query_duration(element, format, cur);
-#else
- return gst_element_query_duration(element, &format, cur);
-#endif
-}
-
-GstCaps *qt_gst_caps_normalize(GstCaps *caps)
-{
-#if GST_CHECK_VERSION(1,0,0)
- // gst_caps_normalize() takes ownership of the argument in 1.0
- return gst_caps_normalize(caps);
-#else
- // in 0.10, it doesn't. Unref the argument to mimic the 1.0 behavior
- GstCaps *res = gst_caps_normalize(caps);
- gst_caps_unref(caps);
- return res;
-#endif
-}
-
-const gchar *qt_gst_element_get_factory_name(GstElement *element)
-{
- const gchar *name = 0;
- const GstElementFactory *factory = 0;
-
- if (element && (factory = gst_element_get_factory(element)))
- name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory));
-
- return name;
-}
-
-gboolean qt_gst_caps_can_intersect(const GstCaps * caps1, const GstCaps * caps2)
-{
-#if GST_CHECK_VERSION(0, 10, 25)
- return gst_caps_can_intersect(caps1, caps2);
-#else
- GstCaps *intersection = gst_caps_intersect(caps1, caps2);
- gboolean res = !gst_caps_is_empty(intersection);
- gst_caps_unref(intersection);
- return res;
-#endif
-}
-
-#if !GST_CHECK_VERSION(0, 10, 31)
-static gboolean qt_gst_videosink_factory_filter(GstPluginFeature *feature, gpointer)
-{
- guint rank;
- const gchar *klass;
-
- if (!GST_IS_ELEMENT_FACTORY(feature))
- return FALSE;
-
- klass = gst_element_factory_get_klass(GST_ELEMENT_FACTORY(feature));
- if (!(strstr(klass, "Sink") && strstr(klass, "Video")))
- return FALSE;
-
- rank = gst_plugin_feature_get_rank(feature);
- if (rank < GST_RANK_MARGINAL)
- return FALSE;
-
- return TRUE;
-}
-
-static gint qt_gst_compare_ranks(GstPluginFeature *f1, GstPluginFeature *f2)
-{
- gint diff;
-
- diff = gst_plugin_feature_get_rank(f2) - gst_plugin_feature_get_rank(f1);
- if (diff != 0)
- return diff;
-
- return strcmp(gst_plugin_feature_get_name(f2), gst_plugin_feature_get_name (f1));
-}
-#endif
-
-GList *qt_gst_video_sinks()
-{
- GList *list = nullptr;
-
-#if GST_CHECK_VERSION(0, 10, 31)
- list = gst_element_factory_list_get_elements(GST_ELEMENT_FACTORY_TYPE_SINK | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO,
- GST_RANK_MARGINAL);
-#else
- list = gst_registry_feature_filter(gst_registry_get_default(),
- (GstPluginFeatureFilter)qt_gst_videosink_factory_filter,
- FALSE, nullptr);
- list = g_list_sort(list, (GCompareFunc)qt_gst_compare_ranks);
-#endif
-
- return list;
-}
-
-void qt_gst_util_double_to_fraction(gdouble src, gint *dest_n, gint *dest_d)
-{
-#if GST_CHECK_VERSION(0, 10, 26)
- gst_util_double_to_fraction(src, dest_n, dest_d);
-#else
- qt_real_to_fraction(src, dest_n, dest_d);
-#endif
-}
-
-QDebug operator <<(QDebug debug, GstCaps *caps)
-{
- if (caps) {
- gchar *string = gst_caps_to_string(caps);
- debug = debug << string;
- g_free(string);
- }
- return debug;
-}
-
-QT_END_NAMESPACE
diff --git a/src/gsttools/qgstutils_p.h b/src/gsttools/qgstutils_p.h
deleted file mode 100644
index 9ecf2e92c..000000000
--- a/src/gsttools/qgstutils_p.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTUTILS_P_H
-#define QGSTUTILS_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <QtCore/qlist.h>
-#include <QtCore/qmap.h>
-#include <QtCore/qset.h>
-#include <gst/gst.h>
-#include <gst/video/video.h>
-#include <qaudioformat.h>
-#include <qcamera.h>
-#include <qabstractvideobuffer.h>
-#include <qvideoframe.h>
-#include <QDebug>
-
-#if GST_CHECK_VERSION(1,0,0)
-# define QT_GSTREAMER_PLAYBIN_ELEMENT_NAME "playbin"
-# define QT_GSTREAMER_CAMERABIN_ELEMENT_NAME "camerabin"
-# define QT_GSTREAMER_COLORCONVERSION_ELEMENT_NAME "videoconvert"
-# define QT_GSTREAMER_RAW_AUDIO_MIME "audio/x-raw"
-# define QT_GSTREAMER_VIDEOOVERLAY_INTERFACE_NAME "GstVideoOverlay"
-#else
-# define QT_GSTREAMER_PLAYBIN_ELEMENT_NAME "playbin2"
-# define QT_GSTREAMER_CAMERABIN_ELEMENT_NAME "camerabin2"
-# define QT_GSTREAMER_COLORCONVERSION_ELEMENT_NAME "ffmpegcolorspace"
-# define QT_GSTREAMER_RAW_AUDIO_MIME "audio/x-raw-int"
-# define QT_GSTREAMER_VIDEOOVERLAY_INTERFACE_NAME "GstXOverlay"
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class QSize;
-class QVariant;
-class QByteArray;
-class QImage;
-class QVideoSurfaceFormat;
-
-namespace QGstUtils {
- struct Q_GSTTOOLS_EXPORT CameraInfo
- {
- QString name;
- QString description;
- int orientation;
- QCamera::Position position;
- QByteArray driver;
- };
-
- Q_GSTTOOLS_EXPORT QMap<QByteArray, QVariant> gstTagListToMap(const GstTagList *list);
-
- Q_GSTTOOLS_EXPORT QSize capsResolution(const GstCaps *caps);
- Q_GSTTOOLS_EXPORT QSize capsCorrectedResolution(const GstCaps *caps);
- Q_GSTTOOLS_EXPORT QAudioFormat audioFormatForCaps(const GstCaps *caps);
-#if GST_CHECK_VERSION(1,0,0)
- Q_GSTTOOLS_EXPORT QAudioFormat audioFormatForSample(GstSample *sample);
-#else
- Q_GSTTOOLS_EXPORT QAudioFormat audioFormatForBuffer(GstBuffer *buffer);
-#endif
- Q_GSTTOOLS_EXPORT GstCaps *capsForAudioFormat(const QAudioFormat &format);
- Q_GSTTOOLS_EXPORT void initializeGst();
- Q_GSTTOOLS_EXPORT QMultimedia::SupportEstimate hasSupport(const QString &mimeType,
- const QStringList &codecs,
- const QSet<QString> &supportedMimeTypeSet);
-
- Q_GSTTOOLS_EXPORT QList<CameraInfo> enumerateCameras(GstElementFactory *factory = 0);
- Q_GSTTOOLS_EXPORT QList<QByteArray> cameraDevices(GstElementFactory * factory = 0);
- Q_GSTTOOLS_EXPORT QString cameraDescription(const QString &device, GstElementFactory * factory = 0);
- Q_GSTTOOLS_EXPORT QCamera::Position cameraPosition(const QString &device, GstElementFactory * factory = 0);
- Q_GSTTOOLS_EXPORT int cameraOrientation(const QString &device, GstElementFactory * factory = 0);
- Q_GSTTOOLS_EXPORT QByteArray cameraDriver(const QString &device, GstElementFactory * factory = 0);
-
- Q_GSTTOOLS_EXPORT QSet<QString> supportedMimeTypes(bool (*isValidFactory)(GstElementFactory *factory));
-
-#if GST_CHECK_VERSION(1,0,0)
- Q_GSTTOOLS_EXPORT QImage bufferToImage(GstBuffer *buffer, const GstVideoInfo &info);
- Q_GSTTOOLS_EXPORT QVideoSurfaceFormat formatForCaps(
- GstCaps *caps,
- GstVideoInfo *info = 0,
- QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle);
-#else
- Q_GSTTOOLS_EXPORT QImage bufferToImage(GstBuffer *buffer);
- Q_GSTTOOLS_EXPORT QVideoSurfaceFormat formatForCaps(
- GstCaps *caps,
- int *bytesPerLine = 0,
- QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle);
-#endif
-
- Q_GSTTOOLS_EXPORT GstCaps *capsForFormats(const QList<QVideoFrame::PixelFormat> &formats);
- void setFrameTimeStamps(QVideoFrame *frame, GstBuffer *buffer);
-
- Q_GSTTOOLS_EXPORT void setMetaData(GstElement *element, const QMap<QByteArray, QVariant> &data);
- Q_GSTTOOLS_EXPORT void setMetaData(GstBin *bin, const QMap<QByteArray, QVariant> &data);
-
- Q_GSTTOOLS_EXPORT GstCaps *videoFilterCaps();
-
- Q_GSTTOOLS_EXPORT QSize structureResolution(const GstStructure *s);
- Q_GSTTOOLS_EXPORT QVideoFrame::PixelFormat structurePixelFormat(const GstStructure *s, int *bpp = 0);
- Q_GSTTOOLS_EXPORT QSize structurePixelAspectRatio(const GstStructure *s);
- Q_GSTTOOLS_EXPORT QPair<qreal, qreal> structureFrameRateRange(const GstStructure *s);
-
- Q_GSTTOOLS_EXPORT QString fileExtensionForMimeType(const QString &mimeType);
-
-#if GST_CHECK_VERSION(0,10,30)
- Q_GSTTOOLS_EXPORT QVariant fromGStreamerOrientation(const QVariant &value);
- Q_GSTTOOLS_EXPORT QVariant toGStreamerOrientation(const QVariant &value);
-#endif
-
- Q_GSTTOOLS_EXPORT bool useOpenGL();
-}
-
-Q_GSTTOOLS_EXPORT void qt_gst_object_ref_sink(gpointer object);
-Q_GSTTOOLS_EXPORT GstCaps *qt_gst_pad_get_current_caps(GstPad *pad);
-Q_GSTTOOLS_EXPORT GstCaps *qt_gst_pad_get_caps(GstPad *pad);
-Q_GSTTOOLS_EXPORT GstStructure *qt_gst_structure_new_empty(const char *name);
-Q_GSTTOOLS_EXPORT gboolean qt_gst_element_query_position(GstElement *element, GstFormat format, gint64 *cur);
-Q_GSTTOOLS_EXPORT gboolean qt_gst_element_query_duration(GstElement *element, GstFormat format, gint64 *cur);
-Q_GSTTOOLS_EXPORT GstCaps *qt_gst_caps_normalize(GstCaps *caps);
-Q_GSTTOOLS_EXPORT const gchar *qt_gst_element_get_factory_name(GstElement *element);
-Q_GSTTOOLS_EXPORT gboolean qt_gst_caps_can_intersect(const GstCaps * caps1, const GstCaps * caps2);
-Q_GSTTOOLS_EXPORT GList *qt_gst_video_sinks();
-Q_GSTTOOLS_EXPORT void qt_gst_util_double_to_fraction(gdouble src, gint *dest_n, gint *dest_d);
-
-Q_GSTTOOLS_EXPORT QDebug operator <<(QDebug debug, GstCaps *caps);
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gsttools/qgstvideobuffer.cpp b/src/gsttools/qgstvideobuffer.cpp
deleted file mode 100644
index 245b7e024..000000000
--- a/src/gsttools/qgstvideobuffer.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstvideobuffer_p.h"
-
-QT_BEGIN_NAMESPACE
-
-#if GST_CHECK_VERSION(1,0,0)
-QGstVideoBuffer::QGstVideoBuffer(GstBuffer *buffer, const GstVideoInfo &info)
- : QAbstractPlanarVideoBuffer(NoHandle)
- , m_videoInfo(info)
-#else
-QGstVideoBuffer::QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine)
- : QAbstractVideoBuffer(NoHandle)
- , m_bytesPerLine(bytesPerLine)
-#endif
- , m_buffer(buffer)
-{
- gst_buffer_ref(m_buffer);
-}
-
-#if GST_CHECK_VERSION(1,0,0)
-QGstVideoBuffer::QGstVideoBuffer(GstBuffer *buffer, const GstVideoInfo &info,
- QGstVideoBuffer::HandleType handleType,
- const QVariant &handle)
- : QAbstractPlanarVideoBuffer(handleType)
- , m_videoInfo(info)
-#else
-QGstVideoBuffer::QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine,
- QGstVideoBuffer::HandleType handleType,
- const QVariant &handle)
- : QAbstractVideoBuffer(handleType)
- , m_bytesPerLine(bytesPerLine)
-#endif
- , m_buffer(buffer)
- , m_handle(handle)
-{
- gst_buffer_ref(m_buffer);
-}
-
-QGstVideoBuffer::~QGstVideoBuffer()
-{
- unmap();
-
- gst_buffer_unref(m_buffer);
-}
-
-
-QAbstractVideoBuffer::MapMode QGstVideoBuffer::mapMode() const
-{
- return m_mode;
-}
-
-#if GST_CHECK_VERSION(1,0,0)
-
-int QGstVideoBuffer::map(MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4])
-{
- const GstMapFlags flags = GstMapFlags(((mode & ReadOnly) ? GST_MAP_READ : 0)
- | ((mode & WriteOnly) ? GST_MAP_WRITE : 0));
-
- if (mode == NotMapped || m_mode != NotMapped) {
- return 0;
- } else if (m_videoInfo.finfo->n_planes == 0) { // Encoded
- if (gst_buffer_map(m_buffer, &m_frame.map[0], flags)) {
- if (numBytes)
- *numBytes = m_frame.map[0].size;
- bytesPerLine[0] = -1;
- data[0] = static_cast<uchar *>(m_frame.map[0].data);
-
- m_mode = mode;
-
- return 1;
- }
- } else if (gst_video_frame_map(&m_frame, &m_videoInfo, m_buffer, flags)) {
- if (numBytes)
- *numBytes = m_frame.info.size;
-
- for (guint i = 0; i < m_frame.info.finfo->n_planes; ++i) {
- bytesPerLine[i] = m_frame.info.stride[i];
- data[i] = static_cast<uchar *>(m_frame.data[i]);
- }
-
- m_mode = mode;
-
- return m_frame.info.finfo->n_planes;
- }
- return 0;
-}
-
-#else
-
-uchar *QGstVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
-{
- if (mode != NotMapped && m_mode == NotMapped) {
- if (numBytes)
- *numBytes = m_buffer->size;
- if (bytesPerLine)
- *bytesPerLine = m_bytesPerLine;
-
- m_mode = mode;
-
- return m_buffer->data;
- } else {
- return 0;
- }
-}
-
-#endif
-
-void QGstVideoBuffer::unmap()
-{
-#if GST_CHECK_VERSION(1,0,0)
- if (m_mode != NotMapped) {
- if (m_videoInfo.finfo->n_planes == 0)
- gst_buffer_unmap(m_buffer, &m_frame.map[0]);
- else
- gst_video_frame_unmap(&m_frame);
- }
-#endif
- m_mode = NotMapped;
-}
-
-QT_END_NAMESPACE
diff --git a/src/gsttools/qgstvideobuffer_p.h b/src/gsttools/qgstvideobuffer_p.h
deleted file mode 100644
index b7de17e19..000000000
--- a/src/gsttools/qgstvideobuffer_p.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTVIDEOBUFFER_P_H
-#define QGSTVIDEOBUFFER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <qabstractvideobuffer.h>
-#include <QtCore/qvariant.h>
-
-#include <gst/gst.h>
-#include <gst/video/video.h>
-
-QT_BEGIN_NAMESPACE
-
-#if GST_CHECK_VERSION(1,0,0)
-class Q_GSTTOOLS_EXPORT QGstVideoBuffer : public QAbstractPlanarVideoBuffer
-{
-public:
- QGstVideoBuffer(GstBuffer *buffer, const GstVideoInfo &info);
- QGstVideoBuffer(GstBuffer *buffer, const GstVideoInfo &info,
- HandleType handleType, const QVariant &handle);
-#else
-class Q_GSTTOOLS_EXPORT QGstVideoBuffer : public QAbstractVideoBuffer
-{
-public:
- QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine);
- QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine,
- HandleType handleType, const QVariant &handle);
-#endif
-
- ~QGstVideoBuffer();
-
- GstBuffer *buffer() const { return m_buffer; }
- MapMode mapMode() const override;
-
-#if GST_CHECK_VERSION(1,0,0)
- int map(MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4]) override;
-#else
- uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) override;
-#endif
-
- void unmap() override;
-
- QVariant handle() const override { return m_handle; }
-private:
-#if GST_CHECK_VERSION(1,0,0)
- GstVideoInfo m_videoInfo;
- GstVideoFrame m_frame;
-#else
- int m_bytesPerLine = 0;
-#endif
- GstBuffer *m_buffer = nullptr;
- MapMode m_mode = NotMapped;
- QVariant m_handle;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gsttools/qgstvideorendererplugin.cpp b/src/gsttools/qgstvideorendererplugin.cpp
deleted file mode 100644
index 22028ac0e..000000000
--- a/src/gsttools/qgstvideorendererplugin.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstvideorendererplugin_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QGstVideoRendererPlugin::QGstVideoRendererPlugin(QObject *parent) :
- QObject(parent)
-{
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qgstvideorendererplugin_p.cpp"
diff --git a/src/gsttools/qgstvideorendererplugin_p.h b/src/gsttools/qgstvideorendererplugin_p.h
deleted file mode 100644
index df36dbe09..000000000
--- a/src/gsttools/qgstvideorendererplugin_p.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTVIDEORENDERERPLUGIN_P_H
-#define QGSTVIDEORENDERERPLUGIN_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qgsttools_global_p.h>
-#include <qabstractvideobuffer.h>
-#include <qvideosurfaceformat.h>
-#include <QtCore/qobject.h>
-#include <QtCore/qplugin.h>
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAbstractVideoSurface;
-
-const QLatin1String QGstVideoRendererPluginKey("gstvideorenderer");
-
-class Q_GSTTOOLS_EXPORT QGstVideoRenderer
-{
-public:
- virtual ~QGstVideoRenderer() {}
-
- virtual GstCaps *getCaps(QAbstractVideoSurface *surface) = 0;
- virtual bool start(QAbstractVideoSurface *surface, GstCaps *caps) = 0;
- virtual void stop(QAbstractVideoSurface *surface) = 0; // surface may be null if unexpectedly deleted.
- virtual bool proposeAllocation(GstQuery *query) = 0; // may be called from a thread.
-
- virtual bool present(QAbstractVideoSurface *surface, GstBuffer *buffer) = 0;
- virtual void flush(QAbstractVideoSurface *surface) = 0; // surface may be null if unexpectedly deleted.
-};
-
-/*
- Abstract interface for video buffers allocation.
-*/
-class Q_GSTTOOLS_EXPORT QGstVideoRendererInterface
-{
-public:
- virtual ~QGstVideoRendererInterface() {}
-
- virtual QGstVideoRenderer *createRenderer() = 0;
-};
-
-#define QGstVideoRendererInterface_iid "org.qt-project.qt.gstvideorenderer/5.4"
-Q_DECLARE_INTERFACE(QGstVideoRendererInterface, QGstVideoRendererInterface_iid)
-
-class Q_GSTTOOLS_EXPORT QGstVideoRendererPlugin : public QObject, public QGstVideoRendererInterface
-{
- Q_OBJECT
- Q_INTERFACES(QGstVideoRendererInterface)
-public:
- explicit QGstVideoRendererPlugin(QObject *parent = 0);
- virtual ~QGstVideoRendererPlugin() {}
-
- QGstVideoRenderer *createRenderer() override = 0;
-
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gsttools/qgstvideorenderersink.cpp b/src/gsttools/qgstvideorenderersink.cpp
deleted file mode 100644
index 4000f2178..000000000
--- a/src/gsttools/qgstvideorenderersink.cpp
+++ /dev/null
@@ -1,810 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qabstractvideosurface.h>
-#include <qvideoframe.h>
-#include <QDebug>
-#include <QMap>
-#include <QThread>
-#include <QEvent>
-#include <QCoreApplication>
-
-#include <private/qmediapluginloader_p.h>
-#include "qgstvideobuffer_p.h"
-
-#include "qgstvideorenderersink_p.h"
-
-#include <gst/video/video.h>
-
-#include "qgstutils_p.h"
-
-#if QT_CONFIG(gstreamer_gl)
-#include <QOpenGLContext>
-#include <QGuiApplication>
-#include <QWindow>
-#include <qpa/qplatformnativeinterface.h>
-
-#include <gst/gl/gstglconfig.h>
-
-#if GST_GL_HAVE_WINDOW_X11
-# include <gst/gl/x11/gstgldisplay_x11.h>
-#endif
-#if GST_GL_HAVE_PLATFORM_EGL
-# include <gst/gl/egl/gstgldisplay_egl.h>
-#endif
-#if GST_CHECK_VERSION(1,11,1) && GST_GL_HAVE_WINDOW_WAYLAND
-# include <gst/gl/wayland/gstgldisplay_wayland.h>
-#endif
-#endif // #if QT_CONFIG(gstreamer_gl)
-
-//#define DEBUG_VIDEO_SURFACE_SINK
-
-QT_BEGIN_NAMESPACE
-
-QGstDefaultVideoRenderer::QGstDefaultVideoRenderer()
-{
-}
-
-QGstDefaultVideoRenderer::~QGstDefaultVideoRenderer()
-{
-}
-
-GstCaps *QGstDefaultVideoRenderer::getCaps(QAbstractVideoSurface *surface)
-{
-#if QT_CONFIG(gstreamer_gl)
- if (QGstUtils::useOpenGL()) {
- m_handleType = QAbstractVideoBuffer::GLTextureHandle;
- auto formats = surface->supportedPixelFormats(m_handleType);
- // Even if the surface does not support gl textures,
- // glupload will be added to the pipeline and GLMemory will be requested.
- // This will lead to upload data to gl textures
- // and download it when the buffer will be used within rendering.
- if (formats.isEmpty()) {
- m_handleType = QAbstractVideoBuffer::NoHandle;
- formats = surface->supportedPixelFormats(m_handleType);
- }
-
- GstCaps *caps = QGstUtils::capsForFormats(formats);
- for (guint i = 0; i < gst_caps_get_size(caps); ++i)
- gst_caps_set_features(caps, i, gst_caps_features_from_string("memory:GLMemory"));
-
- return caps;
- }
-#endif
- return QGstUtils::capsForFormats(surface->supportedPixelFormats(QAbstractVideoBuffer::NoHandle));
-}
-
-bool QGstDefaultVideoRenderer::start(QAbstractVideoSurface *surface, GstCaps *caps)
-{
- m_flushed = true;
- m_format = QGstUtils::formatForCaps(caps, &m_videoInfo, m_handleType);
-
- return m_format.isValid() && surface->start(m_format);
-}
-
-void QGstDefaultVideoRenderer::stop(QAbstractVideoSurface *surface)
-{
- m_flushed = true;
- if (surface)
- surface->stop();
-}
-
-bool QGstDefaultVideoRenderer::present(QAbstractVideoSurface *surface, GstBuffer *buffer)
-{
- m_flushed = false;
-
- QGstVideoBuffer *videoBuffer = nullptr;
-#if QT_CONFIG(gstreamer_gl)
- if (m_format.handleType() == QAbstractVideoBuffer::GLTextureHandle) {
- GstGLMemory *glmem = GST_GL_MEMORY_CAST(gst_buffer_peek_memory(buffer, 0));
- guint textureId = gst_gl_memory_get_texture_id(glmem);
- videoBuffer = new QGstVideoBuffer(buffer, m_videoInfo, m_format.handleType(), textureId);
- }
-#endif
-
- if (!videoBuffer)
- videoBuffer = new QGstVideoBuffer(buffer, m_videoInfo);
-
- auto meta = gst_buffer_get_video_crop_meta (buffer);
- if (meta) {
- QRect vp(meta->x, meta->y, meta->width, meta->height);
- if (m_format.viewport() != vp) {
-#ifdef DEBUG_VIDEO_SURFACE_SINK
- qDebug() << Q_FUNC_INFO << " Update viewport on Metadata: [" << meta->height << "x" << meta->width << " | " << meta->x << "x" << meta->y << "]";
-#endif
- //Update viewport if data is not the same
- m_format.setViewport(vp);
- surface->start(m_format);
- }
- }
-
- QVideoFrame frame(
- videoBuffer,
- m_format.frameSize(),
- m_format.pixelFormat());
- QGstUtils::setFrameTimeStamps(&frame, buffer);
-
- return surface->present(frame);
-}
-
-void QGstDefaultVideoRenderer::flush(QAbstractVideoSurface *surface)
-{
- if (surface && !m_flushed)
- surface->present(QVideoFrame());
- m_flushed = true;
-}
-
-bool QGstDefaultVideoRenderer::proposeAllocation(GstQuery *)
-{
- return true;
-}
-
-Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, rendererLoader,
- (QGstVideoRendererInterface_iid, QLatin1String("video/gstvideorenderer"), Qt::CaseInsensitive))
-
-QVideoSurfaceGstDelegate::QVideoSurfaceGstDelegate(QAbstractVideoSurface *surface)
- : m_surface(surface)
-{
- const auto instances = rendererLoader()->instances(QGstVideoRendererPluginKey);
- for (QObject *instance : instances) {
- auto plugin = qobject_cast<QGstVideoRendererInterface*>(instance);
- if (QGstVideoRenderer *renderer = plugin ? plugin->createRenderer() : nullptr)
- m_renderers.append(renderer);
- }
-
- m_renderers.append(new QGstDefaultVideoRenderer);
- updateSupportedFormats();
- connect(m_surface, SIGNAL(supportedFormatsChanged()), this, SLOT(updateSupportedFormats()));
-}
-
-QVideoSurfaceGstDelegate::~QVideoSurfaceGstDelegate()
-{
- qDeleteAll(m_renderers);
-
- if (m_surfaceCaps)
- gst_caps_unref(m_surfaceCaps);
- if (m_startCaps)
- gst_caps_unref(m_startCaps);
-#if QT_CONFIG(gstreamer_gl)
- if (m_gstGLDisplayContext)
- gst_object_unref(m_gstGLDisplayContext);
-#endif
-}
-
-GstCaps *QVideoSurfaceGstDelegate::caps()
-{
- QMutexLocker locker(&m_mutex);
-
- gst_caps_ref(m_surfaceCaps);
-
- return m_surfaceCaps;
-}
-
-bool QVideoSurfaceGstDelegate::start(GstCaps *caps)
-{
- QMutexLocker locker(&m_mutex);
-
- if (m_activeRenderer) {
- m_flush = true;
- m_stop = true;
- }
-
- if (m_startCaps)
- gst_caps_unref(m_startCaps);
- m_startCaps = caps;
- gst_caps_ref(m_startCaps);
-
- /*
- Waiting for start() to be invoked in the main thread may block
- if gstreamer blocks the main thread until this call is finished.
- This situation is rare and usually caused by setState(Null)
- while pipeline is being prerolled.
-
- The proper solution to this involves controlling gstreamer pipeline from
- other thread than video surface.
-
- Currently start() fails if wait() timed out.
- */
- if (!waitForAsyncEvent(&locker, &m_setupCondition, 1000) && m_startCaps) {
- qWarning() << "Failed to start video surface due to main thread blocked.";
- gst_caps_unref(m_startCaps);
- m_startCaps = 0;
- }
-
- return m_activeRenderer != 0;
-}
-
-void QVideoSurfaceGstDelegate::stop()
-{
- QMutexLocker locker(&m_mutex);
-
- if (!m_activeRenderer)
- return;
-
- m_flush = true;
- m_stop = true;
-
- if (m_startCaps) {
- gst_caps_unref(m_startCaps);
- m_startCaps = 0;
- }
-
- waitForAsyncEvent(&locker, &m_setupCondition, 500);
-}
-
-void QVideoSurfaceGstDelegate::unlock()
-{
- QMutexLocker locker(&m_mutex);
-
- m_setupCondition.wakeAll();
- m_renderCondition.wakeAll();
-}
-
-bool QVideoSurfaceGstDelegate::proposeAllocation(GstQuery *query)
-{
- QMutexLocker locker(&m_mutex);
-
- if (QGstVideoRenderer *pool = m_activeRenderer) {
- locker.unlock();
-
- return pool->proposeAllocation(query);
- } else {
- return false;
- }
-}
-
-void QVideoSurfaceGstDelegate::flush()
-{
- QMutexLocker locker(&m_mutex);
-
- m_flush = true;
- m_renderBuffer = 0;
- m_renderCondition.wakeAll();
-
- notify();
-}
-
-GstFlowReturn QVideoSurfaceGstDelegate::render(GstBuffer *buffer)
-{
- QMutexLocker locker(&m_mutex);
-
- m_renderReturn = GST_FLOW_OK;
- m_renderBuffer = buffer;
-
- waitForAsyncEvent(&locker, &m_renderCondition, 300);
-
- m_renderBuffer = 0;
-
- return m_renderReturn;
-}
-
-#if QT_CONFIG(gstreamer_gl)
-static GstGLContext *gstGLDisplayContext(QAbstractVideoSurface *surface)
-{
- auto glContext = qobject_cast<QOpenGLContext*>(surface->property("GLContext").value<QObject*>());
- // Context is not ready yet.
- if (!glContext)
- return nullptr;
-
- GstGLDisplay *display = nullptr;
- const QString platform = QGuiApplication::platformName();
- const char *contextName = "eglcontext";
- GstGLPlatform glPlatform = GST_GL_PLATFORM_EGL;
- QPlatformNativeInterface *pni = QGuiApplication::platformNativeInterface();
-
-#if GST_GL_HAVE_WINDOW_X11
- if (platform == QLatin1String("xcb")) {
- if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
- contextName = "glxcontext";
- glPlatform = GST_GL_PLATFORM_GLX;
- }
-
- display = (GstGLDisplay *)gst_gl_display_x11_new_with_display(
- (Display *)pni->nativeResourceForIntegration("display"));
- }
-#endif
-
-#if GST_GL_HAVE_PLATFORM_EGL
- if (!display && platform == QLatin1String("eglfs")) {
- display = (GstGLDisplay *)gst_gl_display_egl_new_with_egl_display(
- pni->nativeResourceForIntegration("egldisplay"));
- }
-#endif
-
-#if GST_CHECK_VERSION(1,11,1)
-#if GST_GL_HAVE_WINDOW_WAYLAND
- if (!display && platform.startsWith(QLatin1String("wayland"))) {
- const char *displayName = (platform == QLatin1String("wayland"))
- ? "display" : "egldisplay";
-
- display = (GstGLDisplay *)gst_gl_display_wayland_new_with_display(
- (struct wl_display *)pni->nativeResourceForIntegration(displayName));
- }
-#endif
-#endif
-
- if (!display) {
- qWarning() << "Could not create GstGLDisplay";
- return nullptr;
- }
-
- void *nativeContext = pni->nativeResourceForContext(contextName, glContext);
- if (!nativeContext)
- qWarning() << "Could not find resource for" << contextName;
-
- GstGLContext *appContext = gst_gl_context_new_wrapped(display, (guintptr)nativeContext, glPlatform, GST_GL_API_ANY);
- if (!appContext)
- qWarning() << "Could not create wrappped context for platform:" << glPlatform;
-
- GstGLContext *displayContext = nullptr;
- GError *error = nullptr;
- gst_gl_display_create_context(display, appContext, &displayContext, &error);
- if (error) {
- qWarning() << "Could not create display context:" << error->message;
- g_clear_error(&error);
- }
-
- if (appContext)
- gst_object_unref(appContext);
-
- gst_object_unref(display);
-
- return displayContext;
-}
-#endif // #if QT_CONFIG(gstreamer_gl)
-
-bool QVideoSurfaceGstDelegate::query(GstQuery *query)
-{
-#if QT_CONFIG(gstreamer_gl)
- if (GST_QUERY_TYPE(query) == GST_QUERY_CONTEXT) {
- const gchar *type;
- gst_query_parse_context_type(query, &type);
-
- if (strcmp(type, "gst.gl.local_context") != 0)
- return false;
-
- if (!m_gstGLDisplayContext)
- m_gstGLDisplayContext = gstGLDisplayContext(m_surface);
-
- // No context yet.
- if (!m_gstGLDisplayContext)
- return false;
-
- GstContext *context = nullptr;
- gst_query_parse_context(query, &context);
- context = context ? gst_context_copy(context) : gst_context_new(type, FALSE);
- GstStructure *structure = gst_context_writable_structure(context);
-#if GST_CHECK_VERSION(1,11,1)
- gst_structure_set(structure, "context", GST_TYPE_GL_CONTEXT, m_gstGLDisplayContext, nullptr);
-#else
- gst_structure_set(structure, "context", GST_GL_TYPE_CONTEXT, m_gstGLDisplayContext, nullptr);
-#endif
- gst_query_set_context(query, context);
- gst_context_unref(context);
-
- return m_gstGLDisplayContext;
- }
-#else
- Q_UNUSED(query);
-#endif
- return false;
-}
-
-bool QVideoSurfaceGstDelegate::event(QEvent *event)
-{
- if (event->type() == QEvent::UpdateRequest) {
- QMutexLocker locker(&m_mutex);
-
- if (m_notified) {
- while (handleEvent(&locker)) {}
- m_notified = false;
- }
- return true;
- } else {
- return QObject::event(event);
- }
-}
-
-bool QVideoSurfaceGstDelegate::handleEvent(QMutexLocker *locker)
-{
- if (m_flush) {
- m_flush = false;
- if (m_activeRenderer) {
- locker->unlock();
-
- m_activeRenderer->flush(m_surface);
- }
- } else if (m_stop) {
- m_stop = false;
-
- if (QGstVideoRenderer * const activePool = m_activeRenderer) {
- m_activeRenderer = 0;
- locker->unlock();
-
- activePool->stop(m_surface);
-
- locker->relock();
- }
- } else if (m_startCaps) {
- Q_ASSERT(!m_activeRenderer);
-
- GstCaps * const startCaps = m_startCaps;
- m_startCaps = 0;
-
- if (m_renderer && m_surface) {
- locker->unlock();
-
- const bool started = m_renderer->start(m_surface, startCaps);
-
- locker->relock();
-
- m_activeRenderer = started
- ? m_renderer
- : 0;
- } else if (QGstVideoRenderer * const activePool = m_activeRenderer) {
- m_activeRenderer = 0;
- locker->unlock();
-
- activePool->stop(m_surface);
-
- locker->relock();
- }
-
- gst_caps_unref(startCaps);
- } else if (m_renderBuffer) {
- GstBuffer *buffer = m_renderBuffer;
- m_renderBuffer = 0;
- m_renderReturn = GST_FLOW_ERROR;
-
- if (m_activeRenderer && m_surface) {
- gst_buffer_ref(buffer);
-
- locker->unlock();
-
- const bool rendered = m_activeRenderer->present(m_surface, buffer);
-
- gst_buffer_unref(buffer);
-
- locker->relock();
-
- if (rendered)
- m_renderReturn = GST_FLOW_OK;
- }
-
- m_renderCondition.wakeAll();
- } else {
- m_setupCondition.wakeAll();
-
- return false;
- }
- return true;
-}
-
-void QVideoSurfaceGstDelegate::notify()
-{
- if (!m_notified) {
- m_notified = true;
- QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
- }
-}
-
-bool QVideoSurfaceGstDelegate::waitForAsyncEvent(
- QMutexLocker *locker, QWaitCondition *condition, unsigned long time)
-{
- if (QThread::currentThread() == thread()) {
- while (handleEvent(locker)) {}
- m_notified = false;
-
- return true;
- } else {
- notify();
-
- return condition->wait(&m_mutex, time);
- }
-}
-
-void QVideoSurfaceGstDelegate::updateSupportedFormats()
-{
- if (m_surfaceCaps) {
- gst_caps_unref(m_surfaceCaps);
- m_surfaceCaps = 0;
- }
-
- for (QGstVideoRenderer *pool : qAsConst(m_renderers)) {
- if (GstCaps *caps = pool->getCaps(m_surface)) {
- if (gst_caps_is_empty(caps)) {
- gst_caps_unref(caps);
- continue;
- }
-
- if (m_surfaceCaps)
- gst_caps_unref(m_surfaceCaps);
-
- m_renderer = pool;
- m_surfaceCaps = caps;
- break;
- } else {
- gst_caps_unref(caps);
- }
- }
-}
-
-static GstVideoSinkClass *sink_parent_class;
-static QAbstractVideoSurface *current_surface;
-
-#define VO_SINK(s) QGstVideoRendererSink *sink(reinterpret_cast<QGstVideoRendererSink *>(s))
-
-QGstVideoRendererSink *QGstVideoRendererSink::createSink(QAbstractVideoSurface *surface)
-{
- setSurface(surface);
- QGstVideoRendererSink *sink = reinterpret_cast<QGstVideoRendererSink *>(
- g_object_new(QGstVideoRendererSink::get_type(), 0));
-
- g_signal_connect(G_OBJECT(sink), "notify::show-preroll-frame", G_CALLBACK(handleShowPrerollChange), sink);
-
- return sink;
-}
-
-void QGstVideoRendererSink::setSurface(QAbstractVideoSurface *surface)
-{
- current_surface = surface;
- get_type();
-}
-
-GType QGstVideoRendererSink::get_type()
-{
- static GType type = 0;
-
- if (type == 0) {
- static const GTypeInfo info =
- {
- sizeof(QGstVideoRendererSinkClass), // class_size
- base_init, // base_init
- nullptr, // base_finalize
- class_init, // class_init
- nullptr, // class_finalize
- nullptr, // class_data
- sizeof(QGstVideoRendererSink), // instance_size
- 0, // n_preallocs
- instance_init, // instance_init
- 0 // value_table
- };
-
- type = g_type_register_static(
- GST_TYPE_VIDEO_SINK, "QGstVideoRendererSink", &info, GTypeFlags(0));
-
- // Register the sink type to be used in custom piplines.
- // When surface is ready the sink can be used.
- gst_element_register(nullptr, "qtvideosink", GST_RANK_PRIMARY, type);
- }
-
- return type;
-}
-
-void QGstVideoRendererSink::class_init(gpointer g_class, gpointer class_data)
-{
- Q_UNUSED(class_data);
-
- sink_parent_class = reinterpret_cast<GstVideoSinkClass *>(g_type_class_peek_parent(g_class));
-
- GstVideoSinkClass *video_sink_class = reinterpret_cast<GstVideoSinkClass *>(g_class);
- video_sink_class->show_frame = QGstVideoRendererSink::show_frame;
-
- GstBaseSinkClass *base_sink_class = reinterpret_cast<GstBaseSinkClass *>(g_class);
- base_sink_class->get_caps = QGstVideoRendererSink::get_caps;
- base_sink_class->set_caps = QGstVideoRendererSink::set_caps;
- base_sink_class->propose_allocation = QGstVideoRendererSink::propose_allocation;
- base_sink_class->stop = QGstVideoRendererSink::stop;
- base_sink_class->unlock = QGstVideoRendererSink::unlock;
- base_sink_class->query = QGstVideoRendererSink::query;
-
- GstElementClass *element_class = reinterpret_cast<GstElementClass *>(g_class);
- element_class->change_state = QGstVideoRendererSink::change_state;
- gst_element_class_set_metadata(element_class,
- "Qt built-in video renderer sink",
- "Sink/Video",
- "Qt default built-in video renderer sink",
- "The Qt Company");
-
- GObjectClass *object_class = reinterpret_cast<GObjectClass *>(g_class);
- object_class->finalize = QGstVideoRendererSink::finalize;
-}
-
-void QGstVideoRendererSink::base_init(gpointer g_class)
-{
- static GstStaticPadTemplate sink_pad_template = GST_STATIC_PAD_TEMPLATE(
- "sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS(
- "video/x-raw, "
- "framerate = (fraction) [ 0, MAX ], "
- "width = (int) [ 1, MAX ], "
- "height = (int) [ 1, MAX ]"));
-
- gst_element_class_add_pad_template(
- GST_ELEMENT_CLASS(g_class), gst_static_pad_template_get(&sink_pad_template));
-}
-
-struct NullSurface : QAbstractVideoSurface
-{
- NullSurface(QObject *parent = nullptr) : QAbstractVideoSurface(parent) { }
-
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType) const override
- {
- return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB32;
- }
-
- bool present(const QVideoFrame &) override
- {
- return true;
- }
-};
-
-void QGstVideoRendererSink::instance_init(GTypeInstance *instance, gpointer g_class)
-{
- Q_UNUSED(g_class);
- VO_SINK(instance);
-
- if (!current_surface) {
- qWarning() << "Using qtvideosink element without video surface";
- static NullSurface nullSurface;
- current_surface = &nullSurface;
- }
-
- sink->delegate = new QVideoSurfaceGstDelegate(current_surface);
- sink->delegate->moveToThread(current_surface->thread());
- current_surface = nullptr;
-}
-
-void QGstVideoRendererSink::finalize(GObject *object)
-{
- VO_SINK(object);
-
- delete sink->delegate;
-
- // Chain up
- G_OBJECT_CLASS(sink_parent_class)->finalize(object);
-}
-
-void QGstVideoRendererSink::handleShowPrerollChange(GObject *o, GParamSpec *p, gpointer d)
-{
- Q_UNUSED(o);
- Q_UNUSED(p);
- QGstVideoRendererSink *sink = reinterpret_cast<QGstVideoRendererSink *>(d);
-
- gboolean showPrerollFrame = true; // "show-preroll-frame" property is true by default
- g_object_get(G_OBJECT(sink), "show-preroll-frame", &showPrerollFrame, nullptr);
-
- if (!showPrerollFrame) {
- GstState state = GST_STATE_VOID_PENDING;
- GstClockTime timeout = 10000000; // 10 ms
- gst_element_get_state(GST_ELEMENT(sink), &state, nullptr, timeout);
- // show-preroll-frame being set to 'false' while in GST_STATE_PAUSED means
- // the QMediaPlayer was stopped from the paused state.
- // We need to flush the current frame.
- if (state == GST_STATE_PAUSED)
- sink->delegate->flush();
- }
-}
-
-GstStateChangeReturn QGstVideoRendererSink::change_state(
- GstElement *element, GstStateChange transition)
-{
- QGstVideoRendererSink *sink = reinterpret_cast<QGstVideoRendererSink *>(element);
-
- gboolean showPrerollFrame = true; // "show-preroll-frame" property is true by default
- g_object_get(G_OBJECT(element), "show-preroll-frame", &showPrerollFrame, nullptr);
-
- // If show-preroll-frame is 'false' when transitioning from GST_STATE_PLAYING to
- // GST_STATE_PAUSED, it means the QMediaPlayer was stopped.
- // We need to flush the current frame.
- if (transition == GST_STATE_CHANGE_PLAYING_TO_PAUSED && !showPrerollFrame)
- sink->delegate->flush();
-
- return GST_ELEMENT_CLASS(sink_parent_class)->change_state(element, transition);
-}
-
-GstCaps *QGstVideoRendererSink::get_caps(GstBaseSink *base, GstCaps *filter)
-{
- VO_SINK(base);
-
- GstCaps *caps = sink->delegate->caps();
- GstCaps *unfiltered = caps;
- if (filter) {
- caps = gst_caps_intersect(unfiltered, filter);
- gst_caps_unref(unfiltered);
- }
-
- return caps;
-}
-
-gboolean QGstVideoRendererSink::set_caps(GstBaseSink *base, GstCaps *caps)
-{
- VO_SINK(base);
-
-#ifdef DEBUG_VIDEO_SURFACE_SINK
- qDebug() << "set_caps:";
- qDebug() << caps;
-#endif
-
- if (!caps) {
- sink->delegate->stop();
-
- return TRUE;
- } else if (sink->delegate->start(caps)) {
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-gboolean QGstVideoRendererSink::propose_allocation(GstBaseSink *base, GstQuery *query)
-{
- VO_SINK(base);
- return sink->delegate->proposeAllocation(query);
-}
-
-gboolean QGstVideoRendererSink::stop(GstBaseSink *base)
-{
- VO_SINK(base);
- sink->delegate->stop();
- return TRUE;
-}
-
-gboolean QGstVideoRendererSink::unlock(GstBaseSink *base)
-{
- VO_SINK(base);
- sink->delegate->unlock();
- return TRUE;
-}
-
-GstFlowReturn QGstVideoRendererSink::show_frame(GstVideoSink *base, GstBuffer *buffer)
-{
- VO_SINK(base);
- return sink->delegate->render(buffer);
-}
-
-gboolean QGstVideoRendererSink::query(GstBaseSink *base, GstQuery *query)
-{
- VO_SINK(base);
- if (sink->delegate->query(query))
- return TRUE;
-
- return GST_BASE_SINK_CLASS(sink_parent_class)->query(base, query);
-}
-
-QT_END_NAMESPACE
diff --git a/src/gsttools/qgstvideorenderersink_p.h b/src/gsttools/qgstvideorenderersink_p.h
deleted file mode 100644
index 84162814c..000000000
--- a/src/gsttools/qgstvideorenderersink_p.h
+++ /dev/null
@@ -1,199 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTVIDEORENDERERSINK_P_H
-#define QGSTVIDEORENDERERSINK_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <gst/video/gstvideosink.h>
-#include <gst/video/video.h>
-
-#include <QtCore/qlist.h>
-#include <QtCore/qmutex.h>
-#include <QtCore/qqueue.h>
-#include <QtCore/qpointer.h>
-#include <QtCore/qwaitcondition.h>
-#include <qvideosurfaceformat.h>
-#include <qvideoframe.h>
-#include <qabstractvideobuffer.h>
-
-#include "qgstvideorendererplugin_p.h"
-
-#include "qgstvideorendererplugin_p.h"
-
-#if QT_CONFIG(gstreamer_gl)
-#ifndef GST_USE_UNSTABLE_API
-#define GST_USE_UNSTABLE_API
-#endif
-#include <gst/gl/gl.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-class QAbstractVideoSurface;
-
-class QGstDefaultVideoRenderer : public QGstVideoRenderer
-{
-public:
- QGstDefaultVideoRenderer();
- ~QGstDefaultVideoRenderer();
-
- GstCaps *getCaps(QAbstractVideoSurface *surface) override;
- bool start(QAbstractVideoSurface *surface, GstCaps *caps) override;
- void stop(QAbstractVideoSurface *surface) override;
-
- bool proposeAllocation(GstQuery *query) override;
-
- bool present(QAbstractVideoSurface *surface, GstBuffer *buffer) override;
- void flush(QAbstractVideoSurface *surface) override;
-
-private:
- QVideoSurfaceFormat m_format;
- GstVideoInfo m_videoInfo;
- bool m_flushed = true;
- QAbstractVideoBuffer::HandleType m_handleType = QAbstractVideoBuffer::NoHandle;
-};
-
-class QVideoSurfaceGstDelegate : public QObject
-{
- Q_OBJECT
-public:
- QVideoSurfaceGstDelegate(QAbstractVideoSurface *surface);
- ~QVideoSurfaceGstDelegate();
-
- GstCaps *caps();
-
- bool start(GstCaps *caps);
- void stop();
- void unlock();
- bool proposeAllocation(GstQuery *query);
-
- void flush();
-
- GstFlowReturn render(GstBuffer *buffer);
-
- bool event(QEvent *event) override;
- bool query(GstQuery *query);
-
-private slots:
- bool handleEvent(QMutexLocker *locker);
- void updateSupportedFormats();
-
-private:
- void notify();
- bool waitForAsyncEvent(QMutexLocker *locker, QWaitCondition *condition, unsigned long time);
-
- QPointer<QAbstractVideoSurface> m_surface;
-
- QMutex m_mutex;
- QWaitCondition m_setupCondition;
- QWaitCondition m_renderCondition;
- GstFlowReturn m_renderReturn = GST_FLOW_OK;
- QList<QGstVideoRenderer *> m_renderers;
- QGstVideoRenderer *m_renderer = nullptr;
- QGstVideoRenderer *m_activeRenderer = nullptr;
-
- GstCaps *m_surfaceCaps = nullptr;
- GstCaps *m_startCaps = nullptr;
- GstBuffer *m_renderBuffer = nullptr;
-#if QT_CONFIG(gstreamer_gl)
- GstGLContext *m_gstGLDisplayContext = nullptr;
-#endif
-
- bool m_notified = false;
- bool m_stop = false;
- bool m_flush = false;
-};
-
-class Q_GSTTOOLS_EXPORT QGstVideoRendererSink
-{
-public:
- GstVideoSink parent;
-
- static QGstVideoRendererSink *createSink(QAbstractVideoSurface *surface);
- static void setSurface(QAbstractVideoSurface *surface);
-
-private:
- static GType get_type();
- static void class_init(gpointer g_class, gpointer class_data);
- static void base_init(gpointer g_class);
- static void instance_init(GTypeInstance *instance, gpointer g_class);
-
- static void finalize(GObject *object);
-
- static void handleShowPrerollChange(GObject *o, GParamSpec *p, gpointer d);
-
- static GstStateChangeReturn change_state(GstElement *element, GstStateChange transition);
-
- static GstCaps *get_caps(GstBaseSink *sink, GstCaps *filter);
- static gboolean set_caps(GstBaseSink *sink, GstCaps *caps);
-
- static gboolean propose_allocation(GstBaseSink *sink, GstQuery *query);
-
- static gboolean stop(GstBaseSink *sink);
-
- static gboolean unlock(GstBaseSink *sink);
-
- static GstFlowReturn show_frame(GstVideoSink *sink, GstBuffer *buffer);
- static gboolean query(GstBaseSink *element, GstQuery *query);
-
-private:
- QVideoSurfaceGstDelegate *delegate = nullptr;
-};
-
-
-class QGstVideoRendererSinkClass
-{
-public:
- GstVideoSinkClass parent_class;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gsttools/qvideosurfacegstsink.cpp b/src/gsttools/qvideosurfacegstsink.cpp
deleted file mode 100644
index c6951bdef..000000000
--- a/src/gsttools/qvideosurfacegstsink.cpp
+++ /dev/null
@@ -1,712 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qabstractvideosurface.h>
-#include <qvideoframe.h>
-#include <QDebug>
-#include <QMap>
-#include <QDebug>
-#include <QThread>
-
-#include <private/qmediapluginloader_p.h>
-#include "qgstvideobuffer_p.h"
-
-#include "qgstutils_p.h"
-#include "qvideosurfacegstsink_p.h"
-
-#if GST_VERSION_MAJOR >=1
-#include <gst/video/video.h>
-#endif
-
-//#define DEBUG_VIDEO_SURFACE_SINK
-
-QT_BEGIN_NAMESPACE
-
-Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, bufferPoolLoader,
- (QGstBufferPoolInterface_iid, QLatin1String("video/bufferpool"), Qt::CaseInsensitive))
-
-
-QVideoSurfaceGstDelegate::QVideoSurfaceGstDelegate(
- QAbstractVideoSurface *surface)
- : m_surface(surface)
-{
- if (m_surface) {
- const auto instances = bufferPoolLoader()->instances(QGstBufferPoolPluginKey);
- for (QObject *instance : instances) {
- auto plugin = qobject_cast<QGstBufferPoolInterface*>(instance);
-
- if (plugin) {
- m_pools.append(plugin);
- }
- }
-
- updateSupportedFormats();
- connect(m_surface, SIGNAL(supportedFormatsChanged()), this, SLOT(updateSupportedFormats()));
- }
-}
-
-QVideoSurfaceGstDelegate::~QVideoSurfaceGstDelegate()
-{
-}
-
-QList<QVideoFrame::PixelFormat> QVideoSurfaceGstDelegate::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
-{
- QMutexLocker locker(const_cast<QMutex *>(&m_mutex));
-
- if (!m_surface)
- return QList<QVideoFrame::PixelFormat>();
- else if (handleType == QAbstractVideoBuffer::NoHandle)
- return m_supportedPixelFormats;
- else if (handleType == m_pool->handleType())
- return m_supportedPoolPixelFormats;
- else
- return m_surface->supportedPixelFormats(handleType);
-}
-
-QVideoSurfaceFormat QVideoSurfaceGstDelegate::surfaceFormat() const
-{
- QMutexLocker locker(const_cast<QMutex *>(&m_mutex));
- return m_format;
-}
-
-bool QVideoSurfaceGstDelegate::start(const QVideoSurfaceFormat &format, int bytesPerLine)
-{
- if (!m_surface)
- return false;
-
- QMutexLocker locker(&m_mutex);
-
- m_format = format;
- m_bytesPerLine = bytesPerLine;
-
- if (QThread::currentThread() == thread()) {
- m_started = !m_surface.isNull() ? m_surface->start(m_format) : false;
- } else {
- m_started = false;
- m_startCanceled = false;
- QMetaObject::invokeMethod(this, "queuedStart", Qt::QueuedConnection);
-
- /*
- Waiting for start() to be invoked in the main thread may block
- if gstreamer blocks the main thread until this call is finished.
- This situation is rare and usually caused by setState(Null)
- while pipeline is being prerolled.
-
- The proper solution to this involves controlling gstreamer pipeline from
- other thread than video surface.
-
- Currently start() fails if wait() timed out.
- */
- if (!m_setupCondition.wait(&m_mutex, 1000)) {
- qWarning() << "Failed to start video surface due to main thread blocked.";
- m_startCanceled = true;
- }
- }
-
- m_format = m_surface->surfaceFormat();
-
- return m_started;
-}
-
-void QVideoSurfaceGstDelegate::stop()
-{
- if (!m_surface)
- return;
-
- QMutexLocker locker(&m_mutex);
-
- if (QThread::currentThread() == thread()) {
- if (!m_surface.isNull())
- m_surface->stop();
- } else {
- QMetaObject::invokeMethod(this, "queuedStop", Qt::QueuedConnection);
-
- // Waiting for stop() to be invoked in the main thread may block
- // if gstreamer blocks the main thread until this call is finished.
- m_setupCondition.wait(&m_mutex, 500);
- }
-
- m_started = false;
-}
-
-void QVideoSurfaceGstDelegate::unlock()
-{
- QMutexLocker locker(&m_mutex);
-
- m_startCanceled = true;
- m_setupCondition.wakeAll();
- m_renderCondition.wakeAll();
-}
-
-bool QVideoSurfaceGstDelegate::isActive()
-{
- QMutexLocker locker(&m_mutex);
- return !m_surface.isNull() && m_surface->isActive();
-}
-
-void QVideoSurfaceGstDelegate::clearPoolBuffers()
-{
- QMutexLocker locker(&m_poolMutex);
- if (m_pool)
- m_pool->clear();
-}
-
-void QVideoSurfaceGstDelegate::flush()
-{
- QMutexLocker locker(&m_mutex);
-
- m_frame = QVideoFrame();
- m_renderCondition.wakeAll();
-
- if (QThread::currentThread() == thread()) {
- if (!m_surface.isNull())
- m_surface->present(m_frame);
- } else {
- QMetaObject::invokeMethod(this, "queuedFlush", Qt::QueuedConnection);
- }
-}
-
-GstFlowReturn QVideoSurfaceGstDelegate::render(GstBuffer *buffer)
-{
- if (!m_surface) {
- qWarning() << "Rendering video frame to deleted surface, skip.";
- //return GST_FLOW_NOT_NEGOTIATED;
- return GST_FLOW_OK;
- }
-
- QMutexLocker locker(&m_mutex);
-
- QAbstractVideoBuffer *videoBuffer = 0;
-
- if (m_pool)
- videoBuffer = m_pool->prepareVideoBuffer(buffer, m_bytesPerLine);
-
- if (!videoBuffer)
- videoBuffer = new QGstVideoBuffer(buffer, m_bytesPerLine);
-
- m_frame = QVideoFrame(
- videoBuffer,
- m_format.frameSize(),
- m_format.pixelFormat());
-
- QGstUtils::setFrameTimeStamps(&m_frame, buffer);
-
- m_renderReturn = GST_FLOW_OK;
-
- if (QThread::currentThread() == thread()) {
- if (!m_surface.isNull())
- m_surface->present(m_frame);
- else
- qWarning() << "m_surface.isNull().";
- } else {
- QMetaObject::invokeMethod(this, "queuedRender", Qt::QueuedConnection);
- m_renderCondition.wait(&m_mutex, 300);
- }
-
- m_frame = QVideoFrame();
- return m_renderReturn;
-}
-
-void QVideoSurfaceGstDelegate::queuedStart()
-{
- QMutexLocker locker(&m_mutex);
-
- if (!m_startCanceled) {
- m_started = m_surface->start(m_format);
- m_setupCondition.wakeAll();
- }
-}
-
-void QVideoSurfaceGstDelegate::queuedStop()
-{
- QMutexLocker locker(&m_mutex);
-
- m_surface->stop();
-
- m_setupCondition.wakeAll();
-}
-
-void QVideoSurfaceGstDelegate::queuedFlush()
-{
- QMutexLocker locker(&m_mutex);
-
- if (!m_surface.isNull())
- m_surface->present(QVideoFrame());
-}
-
-void QVideoSurfaceGstDelegate::queuedRender()
-{
- QMutexLocker locker(&m_mutex);
-
- if (!m_frame.isValid())
- return;
-
- if (m_surface.isNull()) {
- qWarning() << "Rendering video frame to deleted surface, skip the frame";
- m_renderReturn = GST_FLOW_OK;
- } else if (m_surface->present(m_frame)) {
- m_renderReturn = GST_FLOW_OK;
- } else {
- switch (m_surface->error()) {
- case QAbstractVideoSurface::NoError:
- m_renderReturn = GST_FLOW_OK;
- break;
- case QAbstractVideoSurface::StoppedError:
- //It's likely we are in process of changing video output
- //and the surface is already stopped, ignore the frame
- m_renderReturn = GST_FLOW_OK;
- break;
- default:
- qWarning() << "Failed to render video frame:" << m_surface->error();
- m_renderReturn = GST_FLOW_OK;
- break;
- }
- }
-
- m_renderCondition.wakeAll();
-}
-
-void QVideoSurfaceGstDelegate::updateSupportedFormats()
-{
- QGstBufferPoolInterface *newPool = 0;
- for (QGstBufferPoolInterface *pool : qAsConst(m_pools)) {
- if (!m_surface->supportedPixelFormats(pool->handleType()).isEmpty()) {
- newPool = pool;
- break;
- }
- }
-
- if (newPool != m_pool) {
- QMutexLocker lock(&m_poolMutex);
-
- if (m_pool)
- m_pool->clear();
- m_pool = newPool;
- }
-
- QMutexLocker locker(&m_mutex);
-
- m_supportedPixelFormats.clear();
- m_supportedPoolPixelFormats.clear();
- if (m_surface) {
- m_supportedPixelFormats = m_surface->supportedPixelFormats();
- if (m_pool)
- m_supportedPoolPixelFormats = m_surface->supportedPixelFormats(m_pool->handleType());
- }
-}
-
-static GstVideoSinkClass *sink_parent_class;
-
-#define VO_SINK(s) QVideoSurfaceGstSink *sink(reinterpret_cast<QVideoSurfaceGstSink *>(s))
-
-QVideoSurfaceGstSink *QVideoSurfaceGstSink::createSink(QAbstractVideoSurface *surface)
-{
- QVideoSurfaceGstSink *sink = reinterpret_cast<QVideoSurfaceGstSink *>(
- g_object_new(QVideoSurfaceGstSink::get_type(), 0));
-
- sink->delegate = new QVideoSurfaceGstDelegate(surface);
-
- g_signal_connect(G_OBJECT(sink), "notify::show-preroll-frame", G_CALLBACK(handleShowPrerollChange), sink);
-
- return sink;
-}
-
-GType QVideoSurfaceGstSink::get_type()
-{
- static GType type = 0;
-
- if (type == 0) {
- static const GTypeInfo info =
- {
- sizeof(QVideoSurfaceGstSinkClass), // class_size
- base_init, // base_init
- nullptr, // base_finalize
- class_init, // class_init
- nullptr, // class_finalize
- nullptr, // class_data
- sizeof(QVideoSurfaceGstSink), // instance_size
- 0, // n_preallocs
- instance_init, // instance_init
- 0 // value_table
- };
-
- type = g_type_register_static(
- GST_TYPE_VIDEO_SINK, "QVideoSurfaceGstSink", &info, GTypeFlags(0));
- }
-
- return type;
-}
-
-void QVideoSurfaceGstSink::class_init(gpointer g_class, gpointer class_data)
-{
- Q_UNUSED(class_data);
-
- sink_parent_class = reinterpret_cast<GstVideoSinkClass *>(g_type_class_peek_parent(g_class));
-
- GstBaseSinkClass *base_sink_class = reinterpret_cast<GstBaseSinkClass *>(g_class);
- base_sink_class->get_caps = QVideoSurfaceGstSink::get_caps;
- base_sink_class->set_caps = QVideoSurfaceGstSink::set_caps;
- base_sink_class->buffer_alloc = QVideoSurfaceGstSink::buffer_alloc;
- base_sink_class->start = QVideoSurfaceGstSink::start;
- base_sink_class->stop = QVideoSurfaceGstSink::stop;
- base_sink_class->unlock = QVideoSurfaceGstSink::unlock;
-
-#if GST_CHECK_VERSION(0, 10, 25)
- GstVideoSinkClass *video_sink_class = reinterpret_cast<GstVideoSinkClass *>(g_class);
- video_sink_class->show_frame = QVideoSurfaceGstSink::show_frame;
-#else
- base_sink_class->preroll = QVideoSurfaceGstSink::preroll;
- base_sink_class->render = QVideoSurfaceGstSink::render;
-#endif
-
- GstElementClass *element_class = reinterpret_cast<GstElementClass *>(g_class);
- element_class->change_state = QVideoSurfaceGstSink::change_state;
-
- GObjectClass *object_class = reinterpret_cast<GObjectClass *>(g_class);
- object_class->finalize = QVideoSurfaceGstSink::finalize;
-}
-
-void QVideoSurfaceGstSink::base_init(gpointer g_class)
-{
- static GstStaticPadTemplate sink_pad_template = GST_STATIC_PAD_TEMPLATE(
- "sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS(
- "video/x-raw-rgb, "
- "framerate = (fraction) [ 0, MAX ], "
- "width = (int) [ 1, MAX ], "
- "height = (int) [ 1, MAX ]; "
- "video/x-raw-yuv, "
- "framerate = (fraction) [ 0, MAX ], "
- "width = (int) [ 1, MAX ], "
- "height = (int) [ 1, MAX ]"));
-
- gst_element_class_add_pad_template(
- GST_ELEMENT_CLASS(g_class), gst_static_pad_template_get(&sink_pad_template));
-}
-
-void QVideoSurfaceGstSink::instance_init(GTypeInstance *instance, gpointer g_class)
-{
- VO_SINK(instance);
-
- Q_UNUSED(g_class);
-
- sink->delegate = 0;
-
- sink->lastRequestedCaps = 0;
- sink->lastBufferCaps = 0;
- sink->lastSurfaceFormat = new QVideoSurfaceFormat;
-}
-
-void QVideoSurfaceGstSink::finalize(GObject *object)
-{
- VO_SINK(object);
-
- delete sink->lastSurfaceFormat;
- sink->lastSurfaceFormat = 0;
-
- if (sink->lastBufferCaps)
- gst_caps_unref(sink->lastBufferCaps);
- sink->lastBufferCaps = 0;
-
- if (sink->lastRequestedCaps)
- gst_caps_unref(sink->lastRequestedCaps);
- sink->lastRequestedCaps = 0;
-
- delete sink->delegate;
-
- // Chain up
- G_OBJECT_CLASS(sink_parent_class)->finalize(object);
-}
-
-void QVideoSurfaceGstSink::handleShowPrerollChange(GObject *o, GParamSpec *p, gpointer d)
-{
- Q_UNUSED(o);
- Q_UNUSED(p);
- QVideoSurfaceGstSink *sink = reinterpret_cast<QVideoSurfaceGstSink *>(d);
-
- gboolean showPrerollFrame = true; // "show-preroll-frame" property is true by default
- g_object_get(G_OBJECT(sink), "show-preroll-frame", &showPrerollFrame, nullptr);
-
- if (!showPrerollFrame) {
- GstState state = GST_STATE_VOID_PENDING;
- gst_element_get_state(GST_ELEMENT(sink), &state, nullptr, GST_CLOCK_TIME_NONE);
- // show-preroll-frame being set to 'false' while in GST_STATE_PAUSED means
- // the QMediaPlayer was stopped from the paused state.
- // We need to flush the current frame.
- if (state == GST_STATE_PAUSED)
- sink->delegate->flush();
- }
-}
-
-GstStateChangeReturn QVideoSurfaceGstSink::change_state(GstElement *element, GstStateChange transition)
-{
- QVideoSurfaceGstSink *sink = reinterpret_cast<QVideoSurfaceGstSink *>(element);
-
- gboolean showPrerollFrame = true; // "show-preroll-frame" property is true by default
- g_object_get(G_OBJECT(element), "show-preroll-frame", &showPrerollFrame, nullptr);
-
- // If show-preroll-frame is 'false' when transitioning from GST_STATE_PLAYING to
- // GST_STATE_PAUSED, it means the QMediaPlayer was stopped.
- // We need to flush the current frame.
- if (transition == GST_STATE_CHANGE_PLAYING_TO_PAUSED && !showPrerollFrame)
- sink->delegate->flush();
-
- return GST_ELEMENT_CLASS(sink_parent_class)->change_state(element, transition);
-}
-
-GstCaps *QVideoSurfaceGstSink::get_caps(GstBaseSink *base)
-{
- VO_SINK(base);
-
- // Find the supported pixel formats
- // with buffer pool specific formats listed first
- QList<QVideoFrame::PixelFormat> supportedFormats;
-
- QList<QVideoFrame::PixelFormat> poolHandleFormats;
- sink->delegate->poolMutex()->lock();
- QGstBufferPoolInterface *pool = sink->delegate->pool();
-
- if (pool)
- poolHandleFormats = sink->delegate->supportedPixelFormats(pool->handleType());
- sink->delegate->poolMutex()->unlock();
-
- supportedFormats = poolHandleFormats;
- const auto supportedPixelFormats = sink->delegate->supportedPixelFormats();
- for (QVideoFrame::PixelFormat format : supportedPixelFormats) {
- if (!poolHandleFormats.contains(format))
- supportedFormats.append(format);
- }
-
- return QGstUtils::capsForFormats(supportedFormats);
-}
-
-gboolean QVideoSurfaceGstSink::set_caps(GstBaseSink *base, GstCaps *caps)
-{
- VO_SINK(base);
-
-#ifdef DEBUG_VIDEO_SURFACE_SINK
- qDebug() << "set_caps:";
- qDebug() << gst_caps_to_string(caps);
-#endif
-
- if (!caps) {
- sink->delegate->stop();
-
- return TRUE;
- } else {
- int bytesPerLine = 0;
- QGstBufferPoolInterface *pool = sink->delegate->pool();
- QAbstractVideoBuffer::HandleType handleType =
- pool ? pool->handleType() : QAbstractVideoBuffer::NoHandle;
-
- QVideoSurfaceFormat format = QGstUtils::formatForCaps(caps, &bytesPerLine, handleType);
-
- if (sink->delegate->isActive()) {
- QVideoSurfaceFormat surfaceFormst = sink->delegate->surfaceFormat();
-
- if (format.pixelFormat() == surfaceFormst.pixelFormat() &&
- format.frameSize() == surfaceFormst.frameSize())
- return TRUE;
- else
- sink->delegate->stop();
- }
-
- if (sink->lastRequestedCaps)
- gst_caps_unref(sink->lastRequestedCaps);
- sink->lastRequestedCaps = 0;
-
-#ifdef DEBUG_VIDEO_SURFACE_SINK
- qDebug() << "Starting video surface, format:";
- qDebug() << format;
- qDebug() << "bytesPerLine:" << bytesPerLine;
-#endif
-
- if (sink->delegate->start(format, bytesPerLine))
- return TRUE;
- else
- qWarning() << "Failed to start video surface";
- }
-
- return FALSE;
-}
-
-GstFlowReturn QVideoSurfaceGstSink::buffer_alloc(
- GstBaseSink *base, guint64 offset, guint size, GstCaps *caps, GstBuffer **buffer)
-{
- VO_SINK(base);
-
- Q_UNUSED(offset);
- Q_UNUSED(size);
-
- if (!buffer)
- return GST_FLOW_ERROR;
-
- *buffer = nullptr;
-
- if (!sink->delegate->pool())
- return GST_FLOW_OK;
-
- QMutexLocker poolLock(sink->delegate->poolMutex());
- QGstBufferPoolInterface *pool = sink->delegate->pool();
-
- if (!pool)
- return GST_FLOW_OK;
-
- if (sink->lastRequestedCaps && gst_caps_is_equal(sink->lastRequestedCaps, caps)) {
- //qDebug() << "reusing last caps";
- *buffer = GST_BUFFER(pool->takeBuffer(*sink->lastSurfaceFormat, sink->lastBufferCaps));
- return GST_FLOW_OK;
- }
-
- if (sink->delegate->supportedPixelFormats(pool->handleType()).isEmpty()) {
- //qDebug() << "sink doesn't support native pool buffers, skip buffers allocation";
- return GST_FLOW_OK;
- }
-
- poolLock.unlock();
-
- GstCaps *intersection = gst_caps_intersect(get_caps(GST_BASE_SINK(sink)), caps);
-
- if (gst_caps_is_empty (intersection)) {
- gst_caps_unref(intersection);
- return GST_FLOW_NOT_NEGOTIATED;
- }
-
- if (sink->delegate->isActive()) {
- //if format was changed, restart the surface
- QVideoSurfaceFormat format = QGstUtils::formatForCaps(intersection);
- QVideoSurfaceFormat surfaceFormat = sink->delegate->surfaceFormat();
-
- if (format.pixelFormat() != surfaceFormat.pixelFormat() ||
- format.frameSize() != surfaceFormat.frameSize()) {
-#ifdef DEBUG_VIDEO_SURFACE_SINK
- qDebug() << "new format requested, restart video surface";
-#endif
- sink->delegate->stop();
- }
- }
-
- if (!sink->delegate->isActive()) {
- int bytesPerLine = 0;
- QGstBufferPoolInterface *pool = sink->delegate->pool();
- QAbstractVideoBuffer::HandleType handleType =
- pool ? pool->handleType() : QAbstractVideoBuffer::NoHandle;
-
- QVideoSurfaceFormat format = QGstUtils::formatForCaps(intersection, &bytesPerLine, handleType);
-
- if (!sink->delegate->start(format, bytesPerLine)) {
- qWarning() << "failed to start video surface";
- return GST_FLOW_NOT_NEGOTIATED;
- }
- }
-
- poolLock.relock();
- pool = sink->delegate->pool();
-
- QVideoSurfaceFormat surfaceFormat = sink->delegate->surfaceFormat();
-
- if (!pool->isFormatSupported(surfaceFormat)) {
- qDebug() << "sink doesn't support native pool format, skip custom buffers allocation";
- return GST_FLOW_OK;
- }
-
- if (sink->lastRequestedCaps)
- gst_caps_unref(sink->lastRequestedCaps);
- sink->lastRequestedCaps = caps;
- gst_caps_ref(sink->lastRequestedCaps);
-
- if (sink->lastBufferCaps)
- gst_caps_unref(sink->lastBufferCaps);
- sink->lastBufferCaps = intersection;
- gst_caps_ref(sink->lastBufferCaps);
-
- *sink->lastSurfaceFormat = surfaceFormat;
-
- *buffer = GST_BUFFER(pool->takeBuffer(surfaceFormat, intersection));
-
- return GST_FLOW_OK;
-}
-
-gboolean QVideoSurfaceGstSink::start(GstBaseSink *base)
-{
- Q_UNUSED(base);
- return TRUE;
-}
-
-gboolean QVideoSurfaceGstSink::stop(GstBaseSink *base)
-{
- VO_SINK(base);
- sink->delegate->clearPoolBuffers();
-
- return TRUE;
-}
-
-gboolean QVideoSurfaceGstSink::unlock(GstBaseSink *base)
-{
- VO_SINK(base);
- sink->delegate->unlock();
- return TRUE;
-}
-
-#if GST_CHECK_VERSION(0, 10, 25)
-GstFlowReturn QVideoSurfaceGstSink::show_frame(GstVideoSink *base, GstBuffer *buffer)
-{
- VO_SINK(base);
- return sink->delegate->render(buffer);
-}
-#else
-GstFlowReturn QVideoSurfaceGstSink::preroll(GstBaseSink *base, GstBuffer *buffer)
-{
- VO_SINK(base);
- gboolean showPrerollFrame = true;
- g_object_get(G_OBJECT(sink), "show-preroll-frame", &showPrerollFrame, nullptr);
-
- if (showPrerollFrame)
- return sink->delegate->render(buffer);
-
- return GST_FLOW_OK;
-}
-
-GstFlowReturn QVideoSurfaceGstSink::render(GstBaseSink *base, GstBuffer *buffer)
-{
- VO_SINK(base);
- return sink->delegate->render(buffer);
-}
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/gsttools/qvideosurfacegstsink_p.h b/src/gsttools/qvideosurfacegstsink_p.h
deleted file mode 100644
index dd758ff82..000000000
--- a/src/gsttools/qvideosurfacegstsink_p.h
+++ /dev/null
@@ -1,192 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef VIDEOSURFACEGSTSINK_P_H
-#define VIDEOSURFACEGSTSINK_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <gst/gst.h>
-
-#if GST_CHECK_VERSION(1,0,0)
-
-#include "qgstvideorenderersink_p.h"
-
-QT_BEGIN_NAMESPACE
-typedef QGstVideoRendererSink QVideoSurfaceGstSink;
-QT_END_NAMESPACE
-
-#else
-
-#include <gst/video/gstvideosink.h>
-
-#include <QtCore/qlist.h>
-#include <QtCore/qmutex.h>
-#include <QtCore/qqueue.h>
-#include <QtCore/qpointer.h>
-#include <QtCore/qwaitcondition.h>
-#include <qvideosurfaceformat.h>
-#include <qvideoframe.h>
-#include <qabstractvideobuffer.h>
-
-#include "qgstbufferpoolinterface_p.h"
-
-QT_BEGIN_NAMESPACE
-class QAbstractVideoSurface;
-
-class QVideoSurfaceGstDelegate : public QObject
-{
- Q_OBJECT
-public:
- QVideoSurfaceGstDelegate(QAbstractVideoSurface *surface);
- ~QVideoSurfaceGstDelegate();
-
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const;
-
- QVideoSurfaceFormat surfaceFormat() const;
-
- bool start(const QVideoSurfaceFormat &format, int bytesPerLine);
- void stop();
-
- void unlock();
-
- bool isActive();
-
- QGstBufferPoolInterface *pool() { return m_pool; }
- QMutex *poolMutex() { return &m_poolMutex; }
- void clearPoolBuffers();
-
- void flush();
-
- GstFlowReturn render(GstBuffer *buffer);
-
-private slots:
- void queuedStart();
- void queuedStop();
- void queuedFlush();
- void queuedRender();
-
- void updateSupportedFormats();
-
-private:
- QPointer<QAbstractVideoSurface> m_surface;
- QList<QVideoFrame::PixelFormat> m_supportedPixelFormats;
- //pixel formats of buffers pool native type
- QList<QVideoFrame::PixelFormat> m_supportedPoolPixelFormats;
- QGstBufferPoolInterface *m_pool = nullptr;
- QList<QGstBufferPoolInterface *> m_pools;
- QMutex m_poolMutex;
- QMutex m_mutex;
- QWaitCondition m_setupCondition;
- QWaitCondition m_renderCondition;
- QVideoSurfaceFormat m_format;
- QVideoFrame m_frame;
- GstFlowReturn m_renderReturn = GST_FLOW_ERROR;
- int m_bytesPerLine = 0;
- bool m_started = false;
- bool m_startCanceled = false;
-};
-
-class QVideoSurfaceGstSink
-{
-public:
- GstVideoSink parent;
-
- static QVideoSurfaceGstSink *createSink(QAbstractVideoSurface *surface);
- static void setSurface(QAbstractVideoSurface *surface) { Q_UNUSED(surface); }
-
-private:
- static GType get_type();
- static void class_init(gpointer g_class, gpointer class_data);
- static void base_init(gpointer g_class);
- static void instance_init(GTypeInstance *instance, gpointer g_class);
-
- static void finalize(GObject *object);
-
- static void handleShowPrerollChange(GObject *o, GParamSpec *p, gpointer d);
-
- static GstStateChangeReturn change_state(GstElement *element, GstStateChange transition);
-
- static GstCaps *get_caps(GstBaseSink *sink);
- static gboolean set_caps(GstBaseSink *sink, GstCaps *caps);
-
- static GstFlowReturn buffer_alloc(
- GstBaseSink *sink, guint64 offset, guint size, GstCaps *caps, GstBuffer **buffer);
-
- static gboolean start(GstBaseSink *sink);
- static gboolean stop(GstBaseSink *sink);
-
- static gboolean unlock(GstBaseSink *sink);
-
-#if GST_CHECK_VERSION(0, 10, 25)
- static GstFlowReturn show_frame(GstVideoSink *sink, GstBuffer *buffer);
-#else
- static GstFlowReturn preroll(GstBaseSink *sink, GstBuffer *buffer);
- static GstFlowReturn render(GstBaseSink *sink, GstBuffer *buffer);
-#endif
-
-private:
- QVideoSurfaceGstDelegate *delegate = nullptr;
-
- GstCaps *lastRequestedCaps = nullptr;
- GstCaps *lastBufferCaps = nullptr;
- QVideoSurfaceFormat *lastSurfaceFormat = nullptr;
-};
-
-class QVideoSurfaceGstSinkClass
-{
-public:
- GstVideoSinkClass parent_class;
-};
-
-QT_END_NAMESPACE
-
-#endif
-
-#endif
diff --git a/src/imports/imports.pro b/src/imports/imports.pro
deleted file mode 100644
index 4d081d9d7..000000000
--- a/src/imports/imports.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-TEMPLATE = subdirs
-QT_FOR_CONFIG += multimedia-private
-
-SUBDIRS += multimedia
diff --git a/src/imports/multimedia/Video.qml b/src/imports/multimedia/Video.qml
deleted file mode 100644
index 24fde22e1..000000000
--- a/src/imports/multimedia/Video.qml
+++ /dev/null
@@ -1,545 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-import QtQuick 2.0
-import QtMultimedia 5.13
-
-/*!
- \qmltype Video
- \inherits Item
- \ingroup multimedia_qml
- \ingroup multimedia_video_qml
- \inqmlmodule QtMultimedia
- \brief A convenience type for showing a specified video.
-
- \c Video is a convenience type combining the functionality
- of a \l MediaPlayer and a \l VideoOutput into one. It provides
- simple video playback functionality without having to declare multiple
- types.
-
- \qml
- Video {
- id: video
- width : 800
- height : 600
- source: "video.avi"
-
- MouseArea {
- anchors.fill: parent
- onClicked: {
- video.play()
- }
- }
-
- focus: true
- Keys.onSpacePressed: video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
- Keys.onLeftPressed: video.seek(video.position - 5000)
- Keys.onRightPressed: video.seek(video.position + 5000)
- }
- \endqml
-
- \c Video supports untransformed, stretched, and uniformly scaled
- video presentation. For a description of stretched uniformly scaled
- presentation, see the \l fillMode property description.
-
- \sa MediaPlayer, VideoOutput
-
-\omit
- \section1 Screen Saver
-
- If it is likely that an application will be playing video for an extended
- period of time without user interaction, it may be necessary to disable
- the platform's screen saver. The \l ScreenSaver (from \l QtSystemInfo)
- may be used to disable the screensaver in this fashion:
-
- \qml
- import QtSystemInfo 5.0
-
- ScreenSaver { screenSaverEnabled: false }
- \endqml
-\endomit
-*/
-
-// TODO: Restore Qt System Info docs when the module is released
-
-Item {
- id: video
-
- /*** Properties of VideoOutput ***/
- /*!
- \qmlproperty enumeration Video::fillMode
-
- Set this property to define how the video is scaled to fit the target
- area.
-
- \list
- \li VideoOutput.Stretch - the video is scaled to fit
- \li VideoOutput.PreserveAspectFit - the video is scaled uniformly to fit without
- cropping
- \li VideoOutput.PreserveAspectCrop - the video is scaled uniformly to fill, cropping
- if necessary
- \endlist
-
- Because this type is for convenience in QML, it does not
- support enumerations directly, so enumerations from \c VideoOutput are
- used to access the available fill modes.
-
- The default fill mode is preserveAspectFit.
- */
- property alias fillMode: videoOut.fillMode
-
- /*!
- \qmlproperty enumeration Video::flushMode
-
- Set this property to define what \c Video should show
- when playback is finished or stopped.
-
- \list
- \li VideoOutput.EmptyFrame - clears video output.
- \li VideoOutput.FirstFrame - shows the first valid frame.
- \li VideoOutput.LastFrame - shows the last valid frame.
- \endlist
-
- The default flush mode is EmptyFrame.
- \since 5.15
- */
- property alias flushMode: videoOut.flushMode
-
- /*!
- \qmlproperty int Video::orientation
-
- The orientation of the \c Video in degrees. Only multiples of 90
- degrees is supported, that is 0, 90, 180, 270, 360, etc.
- */
- property alias orientation: videoOut.orientation
-
-
- /*** Properties of MediaPlayer ***/
-
- /*!
- \qmlproperty enumeration Video::playbackState
-
- This read only property indicates the playback state of the media.
-
- \list
- \li MediaPlayer.PlayingState - the media is playing
- \li MediaPlayer.PausedState - the media is paused
- \li MediaPlayer.StoppedState - the media is stopped
- \endlist
-
- The default state is MediaPlayer.StoppedState.
- */
- property alias playbackState: player.playbackState
-
- /*!
- \qmlproperty bool Video::autoLoad
-
- This property indicates if loading of media should begin immediately.
-
- Defaults to true, if false media will not be loaded until playback is
- started.
- */
- property alias autoLoad: player.autoLoad
-
- /*!
- \qmlproperty real Video::bufferProgress
-
- This property holds how much of the data buffer is currently filled,
- from 0.0 (empty) to 1.0
- (full).
- */
- property alias bufferProgress: player.bufferProgress
-
- /*!
- \qmlproperty int Video::duration
-
- This property holds the duration of the media in milliseconds.
-
- If the media doesn't have a fixed duration (a live stream for example)
- this will be 0.
- */
- property alias duration: player.duration
-
- /*!
- \qmlproperty enumeration Video::error
-
- This property holds the error state of the video. It can be one of:
-
- \list
- \li MediaPlayer.NoError - there is no current error.
- \li MediaPlayer.ResourceError - the video cannot be played due to a problem
- allocating resources.
- \li MediaPlayer.FormatError - the video format is not supported.
- \li MediaPlayer.NetworkError - the video cannot be played due to network issues.
- \li MediaPlayer.AccessDenied - the video cannot be played due to insufficient
- permissions.
- \li MediaPlayer.ServiceMissing - the video cannot be played because the media
- service could not be
- instantiated.
- \endlist
- */
- property alias error: player.error
-
- /*!
- \qmlproperty string Video::errorString
-
- This property holds a string describing the current error condition in more detail.
- */
- property alias errorString: player.errorString
-
- /*!
- \qmlproperty enumeration Video::availability
-
- Returns the availability state of the video instance.
-
- This is one of:
- \table
- \header \li Value \li Description
- \row \li MediaPlayer.Available
- \li The video player is available to use.
- \row \li MediaPlayer.Busy
- \li The video player is usually available, but some other
- process is utilizing the hardware necessary to play media.
- \row \li MediaPlayer.Unavailable
- \li There are no supported video playback facilities.
- \row \li MediaPlayer.ResourceMissing
- \li There is one or more resources missing, so the video player cannot
- be used. It may be possible to try again at a later time.
- \endtable
- */
- property alias availability: player.availability
-
- /*!
- \qmlproperty bool Video::hasAudio
-
- This property holds whether the current media has audio content.
- */
- property alias hasAudio: player.hasAudio
-
- /*!
- \qmlproperty bool Video::hasVideo
-
- This property holds whether the current media has video content.
- */
- property alias hasVideo: player.hasVideo
-
- /*!
- \qmlproperty object Video::metaData
-
- This property holds the meta data for the current media.
-
- See \l{MediaPlayer::metaData}{MediaPlayer.metaData} for details about each meta data key.
-
- \sa {QMediaMetaData}
- */
- property alias metaData: player.metaData
-
- /*!
- \qmlproperty bool Video::muted
-
- This property holds whether the audio output is muted.
- */
- property alias muted: player.muted
-
- /*!
- \qmlproperty real Video::playbackRate
-
- This property holds the rate at which video is played at as a multiple
- of the normal rate.
- */
- property alias playbackRate: player.playbackRate
-
- /*!
- \qmlproperty int Video::position
-
- This property holds the current playback position in milliseconds.
-
- To change this position, use the \l seek() method.
-
- \sa seek()
- */
- property alias position: player.position
-
- /*!
- \qmlproperty enumeration Video::audioRole
-
- This property holds the role of the audio stream. It can be set to specify the type of audio
- being played, allowing the system to make appropriate decisions when it comes to volume,
- routing or post-processing.
-
- The audio role must be set before setting the source property.
-
- Supported values can be retrieved with supportedAudioRoles().
-
- The value can be one of:
- \list
- \li MediaPlayer.UnknownRole - the role is unknown or undefined.
- \li MediaPlayer.MusicRole - music.
- \li MediaPlayer.VideoRole - soundtrack from a movie or a video.
- \li MediaPlayer.VoiceCommunicationRole - voice communications, such as telephony.
- \li MediaPlayer.AlarmRole - alarm.
- \li MediaPlayer.NotificationRole - notification, such as an incoming e-mail or a chat request.
- \li MediaPlayer.RingtoneRole - ringtone.
- \li MediaPlayer.AccessibilityRole - for accessibility, such as with a screen reader.
- \li MediaPlayer.SonificationRole - sonification, such as with user interface sounds.
- \li MediaPlayer.GameRole - game audio.
- \li MediaPlayer.CustomRole - The role is specified by customAudioRole.
- \endlist
-
- customAudioRole is cleared when this property is set to anything other than CustomRole.
-
- \since 5.6
- */
- property alias audioRole: player.audioRole
-
- /*!
- \qmlproperty string Video::customAudioRole
-
- This property holds the role of the audio stream when the backend supports audio roles
- unknown to Qt. It can be set to specify the type of audio being played, allowing the
- system to make appropriate decisions when it comes to volume, routing or post-processing.
-
- The audio role must be set before setting the source property.
-
- audioRole is set to CustomRole when this property is set.
-
- \since 5.11
- */
- property alias customAudioRole: player.customAudioRole
-
- /*!
- \qmlproperty bool Video::seekable
-
- This property holds whether the playback position of the video can be
- changed.
-
- If true, calling the \l seek() method will cause playback to seek to the new position.
- */
- property alias seekable: player.seekable
-
- /*!
- \qmlproperty url Video::source
-
- This property holds the source URL of the media.
-
- Setting the \l source property clears the current \l playlist, if any.
- */
- property alias source: player.source
-
- /*!
- \qmlproperty Playlist Video::playlist
-
- This property holds the playlist used by the media player.
-
- Setting the \l playlist property resets the \l source to an empty string.
-
- \since 5.6
- */
- property alias playlist: player.playlist
-
- /*!
- \qmlproperty enumeration Video::status
-
- This property holds the status of media loading. It can be one of:
-
- \list
- \li MediaPlayer.NoMedia - no media has been set.
- \li MediaPlayer.Loading - the media is currently being loaded.
- \li MediaPlayer.Loaded - the media has been loaded.
- \li MediaPlayer.Buffering - the media is buffering data.
- \li MediaPlayer.Stalled - playback has been interrupted while the media is buffering data.
- \li MediaPlayer.Buffered - the media has buffered data.
- \li MediaPlayer.EndOfMedia - the media has played to the end.
- \li MediaPlayer.InvalidMedia - the media cannot be played.
- \li MediaPlayer.UnknownStatus - the status of the media cannot be determined.
- \endlist
- */
- property alias status: player.status
-
- /*!
- \qmlproperty real Video::volume
-
- This property holds the audio volume.
-
- The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside
- this range will be clamped.
-
- The default volume is \c 1.0.
-
- UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic
- scale will produce linear changes in perceived loudness, which is what a user would normally
- expect from a volume control. See \l {QtMultimedia::QtMultimedia::convertVolume()}{QtMultimedia.convertVolume()}
- for more details.
- */
- property alias volume: player.volume
-
- /*!
- \qmlproperty bool Video::autoPlay
-
- This property determines whether the media should begin playback automatically.
-
- Setting to \c true also sets \l autoLoad to \c true. The default is \c false.
- */
- property alias autoPlay: player.autoPlay
-
- /*!
- \qmlproperty int Video::notifyInterval
-
- The interval at which notifiable properties will update.
-
- The notifiable properties are \l position and \l bufferProgress.
-
- The interval is expressed in milliseconds, the default value is 1000.
-
- \since 5.9
- */
- property alias notifyInterval: player.notifyInterval
-
- /*!
- \qmlproperty int Video::loops
-
- This property holds the number of times the media is played. A value of \c 0 or \c 1 means
- the media will be played only once; set to \c MediaPlayer.Infinite to enable infinite looping.
-
- The value can be changed while the media is playing, in which case it will update
- the remaining loops to the new value.
-
- The default is \c 1.
-
- \since 5.9
- */
- property alias loops: player.loops
-
- /*!
- \qmlsignal Video::paused()
-
- This signal is emitted when playback is paused.
-
- The corresponding handler is \c onPaused.
- */
- signal paused
-
- /*!
- \qmlsignal Video::stopped()
-
- This signal is emitted when playback is stopped.
-
- The corresponding handler is \c onStopped.
- */
- signal stopped
-
- /*!
- \qmlsignal Video::playing()
-
- This signal is emitted when playback is started or continued.
-
- The corresponding handler is \c onPlaying.
- */
- signal playing
-
- VideoOutput {
- id: videoOut
- anchors.fill: video
- source: player
- }
-
- MediaPlayer {
- id: player
- onPaused: video.paused()
- onStopped: video.stopped()
- onPlaying: video.playing()
- }
-
- /*!
- \qmlmethod Video::play()
-
- Starts playback of the media.
- */
- function play() {
- player.play();
- }
-
- /*!
- \qmlmethod Video::pause()
-
- Pauses playback of the media.
- */
- function pause() {
- player.pause();
- }
-
- /*!
- \qmlmethod Video::stop()
-
- Stops playback of the media.
- */
- function stop() {
- player.stop();
- }
-
- /*!
- \qmlmethod Video::seek(offset)
-
- If the \l seekable property is true, seeks the current
- playback position to \a offset.
-
- Seeking may be asynchronous, so the \l position property
- may not be updated immediately.
-
- \sa seekable, position
- */
- function seek(offset) {
- player.seek(offset);
- }
-
- /*!
- \qmlmethod list<int> Video::supportedAudioRoles()
-
- Returns a list of supported audio roles.
-
- If setting the audio role is not supported, an empty list is returned.
-
- \since 5.6
- \sa audioRole
- */
- function supportedAudioRoles() {
- return player.supportedAudioRoles();
- }
-
-}
diff --git a/src/imports/multimedia/multimedia.cpp b/src/imports/multimedia/multimedia.cpp
deleted file mode 100644
index eca1f7591..000000000
--- a/src/imports/multimedia/multimedia.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtQml/qqmlextensionplugin.h>
-#include <QtQml/qqml.h>
-#include <QtQml/qqmlengine.h>
-#include <QtQml/qqmlcomponent.h>
-#include "qsoundeffect.h"
-
-#include <private/qdeclarativevideooutput_p.h>
-#include "qabstractvideofilter.h"
-
-#include "qdeclarativemultimediaglobal_p.h"
-#include "qdeclarativemediametadata_p.h"
-#include "qdeclarativeaudio_p.h"
-#include "qdeclarativeplaylist_p.h"
-#include "qdeclarativecamera_p.h"
-#include "qdeclarativecamerapreviewprovider_p.h"
-#include "qdeclarativecameraexposure_p.h"
-#include "qdeclarativecameraflash_p.h"
-#include "qdeclarativecamerafocus_p.h"
-#include "qdeclarativecameraimageprocessing_p.h"
-#include "qdeclarativecameraviewfinder_p.h"
-#include "qdeclarativetorch_p.h"
-#include <QAbstractVideoSurface>
-
-QML_DECLARE_TYPE(QSoundEffect)
-
-QT_BEGIN_NAMESPACE
-
-static QObject *multimedia_global_object(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
-{
- Q_UNUSED(qmlEngine);
- return new QDeclarativeMultimediaGlobal(jsEngine);
-}
-
-class QMultimediaDeclarativeModule : public QQmlExtensionPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
-
-public:
- QMultimediaDeclarativeModule(QObject *parent = 0) : QQmlExtensionPlugin(parent) { }
- void registerTypes(const char *uri) override
- {
- Q_ASSERT(QLatin1String(uri) == QLatin1String("QtMultimedia"));
-
- // 5.0 types
- qmlRegisterType<QSoundEffect>(uri, 5, 0, "SoundEffect");
- qmlRegisterType<QDeclarativeAudio>(uri, 5, 0, "Audio");
- qmlRegisterType<QDeclarativeAudio>(uri, 5, 0, "MediaPlayer");
- qmlRegisterType<QDeclarativeVideoOutput>(uri, 5, 0, "VideoOutput");
- qmlRegisterType<QDeclarativeCamera>(uri, 5, 0, "Camera");
- qmlRegisterType<QDeclarativeTorch>(uri, 5, 0, "Torch");
- qmlRegisterUncreatableType<QDeclarativeCameraCapture>(uri, 5, 0, "CameraCapture",
- tr("CameraCapture is provided by Camera"));
- qmlRegisterUncreatableType<QDeclarativeCameraRecorder>(uri, 5, 0, "CameraRecorder",
- tr("CameraRecorder is provided by Camera"));
- qmlRegisterUncreatableType<QDeclarativeCameraExposure>(uri, 5, 0, "CameraExposure",
- tr("CameraExposure is provided by Camera"));
- qmlRegisterUncreatableType<QDeclarativeCameraFocus>(uri, 5, 0, "CameraFocus",
- tr("CameraFocus is provided by Camera"));
- qmlRegisterUncreatableType<QDeclarativeCameraFlash>(uri, 5, 0, "CameraFlash",
- tr("CameraFlash is provided by Camera"));
- qmlRegisterUncreatableType<QDeclarativeCameraImageProcessing>(uri, 5, 0, "CameraImageProcessing",
- tr("CameraImageProcessing is provided by Camera"));
-
- // 5.2 types
- qmlRegisterType<QDeclarativeVideoOutput, 2>(uri, 5, 2, "VideoOutput");
-
- // 5.3 types
- // Nothing changed, but adding "import QtMultimedia 5.3" in QML will fail unless at
- // least one type is registered for that version.
- qmlRegisterType<QSoundEffect>(uri, 5, 3, "SoundEffect");
-
- // 5.4 types
- qmlRegisterSingletonType<QDeclarativeMultimediaGlobal>(uri, 5, 4, "QtMultimedia", multimedia_global_object);
- qmlRegisterType<QDeclarativeCamera, 1>(uri, 5, 4, "Camera");
- qmlRegisterUncreatableType<QDeclarativeCameraViewfinder>(uri, 5, 4, "CameraViewfinder",
- tr("CameraViewfinder is provided by Camera"));
-
- // 5.5 types
- qmlRegisterUncreatableType<QDeclarativeCameraImageProcessing, 1>(uri, 5, 5, "CameraImageProcessing", tr("CameraImageProcessing is provided by Camera"));
- qmlRegisterType<QDeclarativeCamera, 2>(uri, 5, 5, "Camera");
-
- // 5.6 types
- qmlRegisterType<QDeclarativeAudio, 1>(uri, 5, 6, "Audio");
- qmlRegisterType<QDeclarativeAudio, 1>(uri, 5, 6, "MediaPlayer");
- qmlRegisterType<QDeclarativePlaylist>(uri, 5, 6, "Playlist");
- qmlRegisterType<QDeclarativePlaylistItem>(uri, 5, 6, "PlaylistItem");
-
- // 5.7 types
- qmlRegisterType<QDeclarativePlaylist, 1>(uri, 5, 7, "Playlist");
- qmlRegisterUncreatableType<QDeclarativeCameraImageProcessing, 2>(uri, 5, 7, "CameraImageProcessing",
- tr("CameraImageProcessing is provided by Camera"));
-
- // 5.8 types (nothing new, re-register one of the types)
- qmlRegisterType<QSoundEffect>(uri, 5, 8, "SoundEffect");
-
- // 5.9 types
- qmlRegisterType<QDeclarativeAudio, 2>(uri, 5, 9, "Audio");
- qmlRegisterType<QDeclarativeAudio, 2>(uri, 5, 9, "MediaPlayer");
- qmlRegisterUncreatableType<QDeclarativeCameraCapture, 1>(uri, 5, 9, "CameraCapture",
- tr("CameraCapture is provided by Camera"));
- qmlRegisterUncreatableType<QDeclarativeCameraFlash, 1>(uri, 5, 9, "CameraFlash",
- tr("CameraFlash is provided by Camera"));
-
- // 5.11 types
- qmlRegisterType<QDeclarativeAudio, 3>(uri, 5, 11, "Audio");
- qmlRegisterType<QDeclarativeAudio, 3>(uri, 5, 11, "MediaPlayer");
- qmlRegisterUncreatableType<QDeclarativeCameraFocus, 1>(uri, 5, 11, "CameraFocus",
- tr("CameraFocus is provided by Camera"));
- qmlRegisterUncreatableType<QDeclarativeCameraExposure, 1>(uri, 5, 11, "CameraExposure",
- tr("CameraExposure is provided by Camera"));
- qmlRegisterUncreatableType<QDeclarativeCameraImageProcessing, 3>(uri, 5, 11, "CameraImageProcessing",
- tr("CameraImageProcessing is provided by Camera"));
-
- qmlRegisterAnonymousType<QDeclarativeMediaMetaData>(uri, 5);
- qmlRegisterAnonymousType<QAbstractVideoFilter>(uri, 5);
-
- // 5.13 types
- qmlRegisterType<QDeclarativeVideoOutput, 13>(uri, 5, 13, "VideoOutput");
-
- // 5.15 types
- qmlRegisterType<QDeclarativeAudio, 15>(uri, 5, 15, "MediaPlayer");
- qmlRegisterType<QDeclarativeVideoOutput, 15>(uri, 5, 15, "VideoOutput");
- qmlRegisterAnonymousType<QAbstractVideoSurface>(uri, 5);
-
- // The minor version used to be the current Qt 5 minor. For compatibility it is the last
- // Qt 5 release.
- qmlRegisterModule(uri, 5, 15);
- }
-
- void initializeEngine(QQmlEngine *engine, const char *uri) override
- {
- Q_UNUSED(uri);
- engine->addImageProvider("camera", new QDeclarativeCameraPreviewProvider);
- }
-};
-
-QT_END_NAMESPACE
-
-#include "multimedia.moc"
-
diff --git a/src/imports/multimedia/multimedia.pro b/src/imports/multimedia/multimedia.pro
deleted file mode 100644
index 4fa911d54..000000000
--- a/src/imports/multimedia/multimedia.pro
+++ /dev/null
@@ -1,44 +0,0 @@
-CXX_MODULE = multimedia
-TARGET = declarative_multimedia
-TARGETPATH = QtMultimedia
-
-QT += qml quick network multimedia-private qtmultimediaquicktools-private
-
-HEADERS += \
- qdeclarativeaudio_p.h \
- qdeclarativemediametadata_p.h \
- qdeclarativeplaylist_p.h \
- qdeclarativecamera_p.h \
- qdeclarativecameracapture_p.h \
- qdeclarativecamerarecorder_p.h \
- qdeclarativecameraexposure_p.h \
- qdeclarativecameraflash_p.h \
- qdeclarativecamerafocus_p.h \
- qdeclarativecameraimageprocessing_p.h \
- qdeclarativecamerapreviewprovider_p.h \
- qdeclarativetorch_p.h \
- qdeclarativecameraviewfinder_p.h \
- qdeclarativemultimediaglobal_p.h
-
-SOURCES += \
- multimedia.cpp \
- qdeclarativeaudio.cpp \
- qdeclarativeplaylist.cpp \
- qdeclarativecamera.cpp \
- qdeclarativecameracapture.cpp \
- qdeclarativecamerarecorder.cpp \
- qdeclarativecameraexposure.cpp \
- qdeclarativecameraflash.cpp \
- qdeclarativecamerafocus.cpp \
- qdeclarativecameraimageprocessing.cpp \
- qdeclarativecamerapreviewprovider.cpp \
- qdeclarativetorch.cpp \
- qdeclarativecameraviewfinder.cpp \
- qdeclarativemultimediaglobal.cpp
-
-QML_FILES += \
- Video.qml
-
-DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
-
-load(qml_plugin)
diff --git a/src/imports/multimedia/plugins.qmltypes b/src/imports/multimedia/plugins.qmltypes
deleted file mode 100644
index 06fb8918b..000000000
--- a/src/imports/multimedia/plugins.qmltypes
+++ /dev/null
@@ -1,2194 +0,0 @@
-import QtQuick.tooling 1.2
-
-// This file describes the plugin-supplied types contained in the library.
-// It is used for QML tooling purposes only.
-//
-// This file was auto-generated by:
-// 'qmlplugindump -nonrelocatable QtMultimedia 5.15'
-
-Module {
- dependencies: ["QtQuick 2.0"]
- Component {
- name: "QAbstractItemModel"
- prototype: "QObject"
- Enum {
- name: "LayoutChangeHint"
- values: {
- "NoLayoutChangeHint": 0,
- "VerticalSortHint": 1,
- "HorizontalSortHint": 2
- }
- }
- Enum {
- name: "CheckIndexOption"
- values: {
- "NoOption": 0,
- "IndexIsValid": 1,
- "DoNotUseParent": 2,
- "ParentIsInvalid": 4
- }
- }
- Signal {
- name: "dataChanged"
- Parameter { name: "topLeft"; type: "QModelIndex" }
- Parameter { name: "bottomRight"; type: "QModelIndex" }
- Parameter { name: "roles"; type: "QVector<int>" }
- }
- Signal {
- name: "dataChanged"
- Parameter { name: "topLeft"; type: "QModelIndex" }
- Parameter { name: "bottomRight"; type: "QModelIndex" }
- }
- Signal {
- name: "headerDataChanged"
- Parameter { name: "orientation"; type: "Qt::Orientation" }
- Parameter { name: "first"; type: "int" }
- Parameter { name: "last"; type: "int" }
- }
- Signal {
- name: "layoutChanged"
- Parameter { name: "parents"; type: "QList<QPersistentModelIndex>" }
- Parameter { name: "hint"; type: "QAbstractItemModel::LayoutChangeHint" }
- }
- Signal {
- name: "layoutChanged"
- Parameter { name: "parents"; type: "QList<QPersistentModelIndex>" }
- }
- Signal { name: "layoutChanged" }
- Signal {
- name: "layoutAboutToBeChanged"
- Parameter { name: "parents"; type: "QList<QPersistentModelIndex>" }
- Parameter { name: "hint"; type: "QAbstractItemModel::LayoutChangeHint" }
- }
- Signal {
- name: "layoutAboutToBeChanged"
- Parameter { name: "parents"; type: "QList<QPersistentModelIndex>" }
- }
- Signal { name: "layoutAboutToBeChanged" }
- Signal {
- name: "rowsAboutToBeInserted"
- Parameter { name: "parent"; type: "QModelIndex" }
- Parameter { name: "first"; type: "int" }
- Parameter { name: "last"; type: "int" }
- }
- Signal {
- name: "rowsInserted"
- Parameter { name: "parent"; type: "QModelIndex" }
- Parameter { name: "first"; type: "int" }
- Parameter { name: "last"; type: "int" }
- }
- Signal {
- name: "rowsAboutToBeRemoved"
- Parameter { name: "parent"; type: "QModelIndex" }
- Parameter { name: "first"; type: "int" }
- Parameter { name: "last"; type: "int" }
- }
- Signal {
- name: "rowsRemoved"
- Parameter { name: "parent"; type: "QModelIndex" }
- Parameter { name: "first"; type: "int" }
- Parameter { name: "last"; type: "int" }
- }
- Signal {
- name: "columnsAboutToBeInserted"
- Parameter { name: "parent"; type: "QModelIndex" }
- Parameter { name: "first"; type: "int" }
- Parameter { name: "last"; type: "int" }
- }
- Signal {
- name: "columnsInserted"
- Parameter { name: "parent"; type: "QModelIndex" }
- Parameter { name: "first"; type: "int" }
- Parameter { name: "last"; type: "int" }
- }
- Signal {
- name: "columnsAboutToBeRemoved"
- Parameter { name: "parent"; type: "QModelIndex" }
- Parameter { name: "first"; type: "int" }
- Parameter { name: "last"; type: "int" }
- }
- Signal {
- name: "columnsRemoved"
- Parameter { name: "parent"; type: "QModelIndex" }
- Parameter { name: "first"; type: "int" }
- Parameter { name: "last"; type: "int" }
- }
- Signal { name: "modelAboutToBeReset" }
- Signal { name: "modelReset" }
- Signal {
- name: "rowsAboutToBeMoved"
- Parameter { name: "sourceParent"; type: "QModelIndex" }
- Parameter { name: "sourceStart"; type: "int" }
- Parameter { name: "sourceEnd"; type: "int" }
- Parameter { name: "destinationParent"; type: "QModelIndex" }
- Parameter { name: "destinationRow"; type: "int" }
- }
- Signal {
- name: "rowsMoved"
- Parameter { name: "parent"; type: "QModelIndex" }
- Parameter { name: "start"; type: "int" }
- Parameter { name: "end"; type: "int" }
- Parameter { name: "destination"; type: "QModelIndex" }
- Parameter { name: "row"; type: "int" }
- }
- Signal {
- name: "columnsAboutToBeMoved"
- Parameter { name: "sourceParent"; type: "QModelIndex" }
- Parameter { name: "sourceStart"; type: "int" }
- Parameter { name: "sourceEnd"; type: "int" }
- Parameter { name: "destinationParent"; type: "QModelIndex" }
- Parameter { name: "destinationColumn"; type: "int" }
- }
- Signal {
- name: "columnsMoved"
- Parameter { name: "parent"; type: "QModelIndex" }
- Parameter { name: "start"; type: "int" }
- Parameter { name: "end"; type: "int" }
- Parameter { name: "destination"; type: "QModelIndex" }
- Parameter { name: "column"; type: "int" }
- }
- Method { name: "submit"; type: "bool" }
- Method { name: "revert" }
- Method {
- name: "hasIndex"
- type: "bool"
- Parameter { name: "row"; type: "int" }
- Parameter { name: "column"; type: "int" }
- Parameter { name: "parent"; type: "QModelIndex" }
- }
- Method {
- name: "hasIndex"
- type: "bool"
- Parameter { name: "row"; type: "int" }
- Parameter { name: "column"; type: "int" }
- }
- Method {
- name: "index"
- type: "QModelIndex"
- Parameter { name: "row"; type: "int" }
- Parameter { name: "column"; type: "int" }
- Parameter { name: "parent"; type: "QModelIndex" }
- }
- Method {
- name: "index"
- type: "QModelIndex"
- Parameter { name: "row"; type: "int" }
- Parameter { name: "column"; type: "int" }
- }
- Method {
- name: "parent"
- type: "QModelIndex"
- Parameter { name: "child"; type: "QModelIndex" }
- }
- Method {
- name: "sibling"
- type: "QModelIndex"
- Parameter { name: "row"; type: "int" }
- Parameter { name: "column"; type: "int" }
- Parameter { name: "idx"; type: "QModelIndex" }
- }
- Method {
- name: "rowCount"
- type: "int"
- Parameter { name: "parent"; type: "QModelIndex" }
- }
- Method { name: "rowCount"; type: "int" }
- Method {
- name: "columnCount"
- type: "int"
- Parameter { name: "parent"; type: "QModelIndex" }
- }
- Method { name: "columnCount"; type: "int" }
- Method {
- name: "hasChildren"
- type: "bool"
- Parameter { name: "parent"; type: "QModelIndex" }
- }
- Method { name: "hasChildren"; type: "bool" }
- Method {
- name: "data"
- type: "QVariant"
- Parameter { name: "index"; type: "QModelIndex" }
- Parameter { name: "role"; type: "int" }
- }
- Method {
- name: "data"
- type: "QVariant"
- Parameter { name: "index"; type: "QModelIndex" }
- }
- Method {
- name: "setData"
- type: "bool"
- Parameter { name: "index"; type: "QModelIndex" }
- Parameter { name: "value"; type: "QVariant" }
- Parameter { name: "role"; type: "int" }
- }
- Method {
- name: "setData"
- type: "bool"
- Parameter { name: "index"; type: "QModelIndex" }
- Parameter { name: "value"; type: "QVariant" }
- }
- Method {
- name: "headerData"
- type: "QVariant"
- Parameter { name: "section"; type: "int" }
- Parameter { name: "orientation"; type: "Qt::Orientation" }
- Parameter { name: "role"; type: "int" }
- }
- Method {
- name: "headerData"
- type: "QVariant"
- Parameter { name: "section"; type: "int" }
- Parameter { name: "orientation"; type: "Qt::Orientation" }
- }
- Method {
- name: "fetchMore"
- Parameter { name: "parent"; type: "QModelIndex" }
- }
- Method {
- name: "canFetchMore"
- type: "bool"
- Parameter { name: "parent"; type: "QModelIndex" }
- }
- Method {
- name: "flags"
- type: "Qt::ItemFlags"
- Parameter { name: "index"; type: "QModelIndex" }
- }
- Method {
- name: "match"
- type: "QModelIndexList"
- Parameter { name: "start"; type: "QModelIndex" }
- Parameter { name: "role"; type: "int" }
- Parameter { name: "value"; type: "QVariant" }
- Parameter { name: "hits"; type: "int" }
- Parameter { name: "flags"; type: "Qt::MatchFlags" }
- }
- Method {
- name: "match"
- type: "QModelIndexList"
- Parameter { name: "start"; type: "QModelIndex" }
- Parameter { name: "role"; type: "int" }
- Parameter { name: "value"; type: "QVariant" }
- Parameter { name: "hits"; type: "int" }
- }
- Method {
- name: "match"
- type: "QModelIndexList"
- Parameter { name: "start"; type: "QModelIndex" }
- Parameter { name: "role"; type: "int" }
- Parameter { name: "value"; type: "QVariant" }
- }
- }
- Component { name: "QAbstractListModel"; prototype: "QAbstractItemModel" }
- Component {
- name: "QAbstractVideoFilter"
- prototype: "QObject"
- Property { name: "active"; type: "bool" }
- }
- Component {
- name: "QAbstractVideoSurface"
- prototype: "QObject"
- Property { name: "nativeResolution"; type: "QSize"; isReadonly: true }
- Signal {
- name: "activeChanged"
- Parameter { name: "active"; type: "bool" }
- }
- Signal {
- name: "surfaceFormatChanged"
- Parameter { name: "format"; type: "QVideoSurfaceFormat" }
- }
- Signal { name: "supportedFormatsChanged" }
- Signal {
- name: "nativeResolutionChanged"
- Parameter { name: "resolution"; type: "QSize" }
- }
- }
- Component {
- name: "QCamera"
- prototype: "QMediaObject"
- Enum {
- name: "Status"
- values: {
- "UnavailableStatus": 0,
- "UnloadedStatus": 1,
- "LoadingStatus": 2,
- "UnloadingStatus": 3,
- "LoadedStatus": 4,
- "StandbyStatus": 5,
- "StartingStatus": 6,
- "StoppingStatus": 7,
- "ActiveStatus": 8
- }
- }
- Enum {
- name: "State"
- values: {
- "UnloadedState": 0,
- "LoadedState": 1,
- "ActiveState": 2
- }
- }
- Enum {
- name: "CaptureMode"
- values: {
- "CaptureViewfinder": 0,
- "CaptureStillImage": 1,
- "CaptureVideo": 2
- }
- }
- Enum {
- name: "Error"
- values: {
- "NoError": 0,
- "CameraError": 1,
- "InvalidRequestError": 2,
- "ServiceMissingError": 3,
- "NotSupportedFeatureError": 4
- }
- }
- Enum {
- name: "LockStatus"
- values: {
- "Unlocked": 0,
- "Searching": 1,
- "Locked": 2
- }
- }
- Enum {
- name: "LockChangeReason"
- values: {
- "UserRequest": 0,
- "LockAcquired": 1,
- "LockFailed": 2,
- "LockLost": 3,
- "LockTemporaryLost": 4
- }
- }
- Enum {
- name: "LockType"
- values: {
- "NoLock": 0,
- "LockExposure": 1,
- "LockWhiteBalance": 2,
- "LockFocus": 4
- }
- }
- Enum {
- name: "Position"
- values: {
- "UnspecifiedPosition": 0,
- "BackFace": 1,
- "FrontFace": 2
- }
- }
- Property { name: "state"; type: "QCamera::State"; isReadonly: true }
- Property { name: "status"; type: "QCamera::Status"; isReadonly: true }
- Property { name: "captureMode"; type: "QCamera::CaptureModes" }
- Property { name: "lockStatus"; type: "QCamera::LockStatus"; isReadonly: true }
- Signal {
- name: "stateChanged"
- Parameter { name: "state"; type: "QCamera::State" }
- }
- Signal {
- name: "captureModeChanged"
- Parameter { type: "QCamera::CaptureModes" }
- }
- Signal {
- name: "statusChanged"
- Parameter { name: "status"; type: "QCamera::Status" }
- }
- Signal { name: "locked" }
- Signal { name: "lockFailed" }
- Signal {
- name: "lockStatusChanged"
- Parameter { name: "status"; type: "QCamera::LockStatus" }
- Parameter { name: "reason"; type: "QCamera::LockChangeReason" }
- }
- Signal {
- name: "lockStatusChanged"
- Parameter { name: "lock"; type: "QCamera::LockType" }
- Parameter { name: "status"; type: "QCamera::LockStatus" }
- Parameter { name: "reason"; type: "QCamera::LockChangeReason" }
- }
- Signal {
- name: "error"
- Parameter { type: "QCamera::Error" }
- }
- Method {
- name: "setCaptureMode"
- Parameter { name: "mode"; type: "QCamera::CaptureModes" }
- }
- Method { name: "load" }
- Method { name: "unload" }
- Method { name: "start" }
- Method { name: "stop" }
- Method { name: "searchAndLock" }
- Method { name: "unlock" }
- Method {
- name: "searchAndLock"
- Parameter { name: "locks"; type: "QCamera::LockTypes" }
- }
- Method {
- name: "unlock"
- Parameter { name: "locks"; type: "QCamera::LockTypes" }
- }
- }
- Component {
- name: "QDeclarativeAudio"
- prototype: "QObject"
- exports: [
- "QtMultimedia/Audio 5.0",
- "QtMultimedia/Audio 5.11",
- "QtMultimedia/Audio 5.6",
- "QtMultimedia/Audio 5.9",
- "QtMultimedia/MediaPlayer 5.0",
- "QtMultimedia/MediaPlayer 5.11",
- "QtMultimedia/MediaPlayer 5.15",
- "QtMultimedia/MediaPlayer 5.6",
- "QtMultimedia/MediaPlayer 5.9"
- ]
- exportMetaObjectRevisions: [0, 3, 1, 2, 0, 3, 15, 1, 2]
- Enum {
- name: "Status"
- values: {
- "UnknownStatus": 0,
- "NoMedia": 1,
- "Loading": 2,
- "Loaded": 3,
- "Stalled": 4,
- "Buffering": 5,
- "Buffered": 6,
- "EndOfMedia": 7,
- "InvalidMedia": 8
- }
- }
- Enum {
- name: "Error"
- values: {
- "NoError": 0,
- "ResourceError": 1,
- "FormatError": 2,
- "NetworkError": 3,
- "AccessDenied": 4,
- "ServiceMissing": 5
- }
- }
- Enum {
- name: "Loop"
- values: {
- "Infinite": -1
- }
- }
- Enum {
- name: "PlaybackState"
- values: {
- "PlayingState": 1,
- "PausedState": 2,
- "StoppedState": 0
- }
- }
- Enum {
- name: "Availability"
- values: {
- "Available": 0,
- "Busy": 2,
- "Unavailable": 1,
- "ResourceMissing": 3
- }
- }
- Enum {
- name: "AudioRole"
- values: {
- "UnknownRole": 0,
- "AccessibilityRole": 7,
- "AlarmRole": 4,
- "CustomRole": 10,
- "GameRole": 9,
- "MusicRole": 1,
- "NotificationRole": 5,
- "RingtoneRole": 6,
- "SonificationRole": 8,
- "VideoRole": 2,
- "VoiceCommunicationRole": 3
- }
- }
- Property { name: "source"; type: "QUrl" }
- Property { name: "playlist"; revision: 1; type: "QDeclarativePlaylist"; isPointer: true }
- Property { name: "loops"; type: "int" }
- Property { name: "playbackState"; type: "PlaybackState"; isReadonly: true }
- Property { name: "autoPlay"; type: "bool" }
- Property { name: "autoLoad"; type: "bool" }
- Property { name: "status"; type: "Status"; isReadonly: true }
- Property { name: "duration"; type: "int"; isReadonly: true }
- Property { name: "position"; type: "int"; isReadonly: true }
- Property { name: "volume"; type: "double" }
- Property { name: "muted"; type: "bool" }
- Property { name: "hasAudio"; type: "bool"; isReadonly: true }
- Property { name: "hasVideo"; type: "bool"; isReadonly: true }
- Property { name: "bufferProgress"; type: "double"; isReadonly: true }
- Property { name: "seekable"; type: "bool"; isReadonly: true }
- Property { name: "playbackRate"; type: "double" }
- Property { name: "error"; type: "Error"; isReadonly: true }
- Property { name: "errorString"; type: "string"; isReadonly: true }
- Property {
- name: "metaData"
- type: "QDeclarativeMediaMetaData"
- isReadonly: true
- isPointer: true
- }
- Property { name: "mediaObject"; type: "QObject"; isReadonly: true; isPointer: true }
- Property { name: "availability"; type: "Availability"; isReadonly: true }
- Property { name: "audioRole"; revision: 1; type: "AudioRole" }
- Property { name: "customAudioRole"; revision: 3; type: "string" }
- Property { name: "notifyInterval"; revision: 2; type: "int" }
- Property { name: "videoOutput"; revision: 15; type: "QVariant" }
- Signal { name: "playlistChanged"; revision: 1 }
- Signal { name: "loopCountChanged" }
- Signal { name: "paused" }
- Signal { name: "stopped" }
- Signal { name: "playing" }
- Signal { name: "audioRoleChanged"; revision: 1 }
- Signal { name: "customAudioRoleChanged"; revision: 3 }
- Signal {
- name: "availabilityChanged"
- Parameter { name: "availability"; type: "Availability" }
- }
- Signal {
- name: "error"
- Parameter { name: "error"; type: "QDeclarativeAudio::Error" }
- Parameter { name: "errorString"; type: "string" }
- }
- Signal { name: "notifyIntervalChanged"; revision: 2 }
- Signal { name: "videoOutputChanged"; revision: 15 }
- Method { name: "play" }
- Method { name: "pause" }
- Method { name: "stop" }
- Method {
- name: "seek"
- Parameter { name: "position"; type: "int" }
- }
- Method { name: "supportedAudioRoles"; revision: 1; type: "QJSValue" }
- }
- Component {
- name: "QDeclarativeCamera"
- prototype: "QObject"
- exports: [
- "QtMultimedia/Camera 5.0",
- "QtMultimedia/Camera 5.4",
- "QtMultimedia/Camera 5.5"
- ]
- exportMetaObjectRevisions: [0, 1, 2]
- Enum {
- name: "Position"
- values: {
- "UnspecifiedPosition": 0,
- "BackFace": 1,
- "FrontFace": 2
- }
- }
- Enum {
- name: "CaptureMode"
- values: {
- "CaptureViewfinder": 0,
- "CaptureStillImage": 1,
- "CaptureVideo": 2
- }
- }
- Enum {
- name: "State"
- values: {
- "ActiveState": 2,
- "LoadedState": 1,
- "UnloadedState": 0
- }
- }
- Enum {
- name: "Status"
- values: {
- "UnavailableStatus": 0,
- "UnloadedStatus": 1,
- "LoadingStatus": 2,
- "UnloadingStatus": 3,
- "LoadedStatus": 4,
- "StandbyStatus": 5,
- "StartingStatus": 6,
- "StoppingStatus": 7,
- "ActiveStatus": 8
- }
- }
- Enum {
- name: "LockStatus"
- values: {
- "Unlocked": 0,
- "Searching": 1,
- "Locked": 2
- }
- }
- Enum {
- name: "Error"
- values: {
- "NoError": 0,
- "CameraError": 1,
- "InvalidRequestError": 2,
- "ServiceMissingError": 3,
- "NotSupportedFeatureError": 4
- }
- }
- Enum {
- name: "FlashMode"
- values: {
- "FlashAuto": 1,
- "FlashOff": 2,
- "FlashOn": 4,
- "FlashRedEyeReduction": 8,
- "FlashFill": 16,
- "FlashTorch": 32,
- "FlashVideoLight": 64,
- "FlashSlowSyncFrontCurtain": 128,
- "FlashSlowSyncRearCurtain": 256,
- "FlashManual": 512
- }
- }
- Enum {
- name: "ExposureMode"
- values: {
- "ExposureAuto": 0,
- "ExposureManual": 1,
- "ExposurePortrait": 2,
- "ExposureNight": 3,
- "ExposureBacklight": 4,
- "ExposureSpotlight": 5,
- "ExposureSports": 6,
- "ExposureSnow": 7,
- "ExposureBeach": 8,
- "ExposureLargeAperture": 9,
- "ExposureSmallAperture": 10,
- "ExposureAction": 11,
- "ExposureLandscape": 12,
- "ExposureNightPortrait": 13,
- "ExposureTheatre": 14,
- "ExposureSunset": 15,
- "ExposureSteadyPhoto": 16,
- "ExposureFireworks": 17,
- "ExposureParty": 18,
- "ExposureCandlelight": 19,
- "ExposureBarcode": 20,
- "ExposureModeVendor": 1000
- }
- }
- Enum {
- name: "MeteringMode"
- values: {
- "MeteringMatrix": 1,
- "MeteringAverage": 2,
- "MeteringSpot": 3
- }
- }
- Enum {
- name: "FocusMode"
- values: {
- "FocusManual": 1,
- "FocusHyperfocal": 2,
- "FocusInfinity": 4,
- "FocusAuto": 8,
- "FocusContinuous": 16,
- "FocusMacro": 32
- }
- }
- Enum {
- name: "FocusPointMode"
- values: {
- "FocusPointAuto": 0,
- "FocusPointCenter": 1,
- "FocusPointFaceDetection": 2,
- "FocusPointCustom": 3
- }
- }
- Enum {
- name: "FocusAreaStatus"
- values: {
- "FocusAreaUnused": 1,
- "FocusAreaSelected": 2,
- "FocusAreaFocused": 3
- }
- }
- Enum {
- name: "Availability"
- values: {
- "Available": 0,
- "Busy": 2,
- "Unavailable": 1,
- "ResourceMissing": 3
- }
- }
- Property { name: "deviceId"; revision: 1; type: "string" }
- Property { name: "position"; revision: 1; type: "Position" }
- Property { name: "displayName"; revision: 1; type: "string"; isReadonly: true }
- Property { name: "orientation"; revision: 1; type: "int"; isReadonly: true }
- Property { name: "captureMode"; type: "CaptureMode" }
- Property { name: "cameraState"; type: "State" }
- Property { name: "cameraStatus"; type: "Status"; isReadonly: true }
- Property { name: "lockStatus"; type: "LockStatus"; isReadonly: true }
- Property { name: "errorCode"; type: "Error"; isReadonly: true }
- Property { name: "errorString"; type: "string"; isReadonly: true }
- Property { name: "availability"; type: "Availability"; isReadonly: true }
- Property { name: "opticalZoom"; type: "double" }
- Property { name: "maximumOpticalZoom"; type: "double"; isReadonly: true }
- Property { name: "digitalZoom"; type: "double" }
- Property { name: "maximumDigitalZoom"; type: "double"; isReadonly: true }
- Property { name: "mediaObject"; type: "QObject"; isReadonly: true; isPointer: true }
- Property {
- name: "imageCapture"
- type: "QDeclarativeCameraCapture"
- isReadonly: true
- isPointer: true
- }
- Property {
- name: "videoRecorder"
- type: "QDeclarativeCameraRecorder"
- isReadonly: true
- isPointer: true
- }
- Property {
- name: "exposure"
- type: "QDeclarativeCameraExposure"
- isReadonly: true
- isPointer: true
- }
- Property { name: "flash"; type: "QDeclarativeCameraFlash"; isReadonly: true; isPointer: true }
- Property { name: "focus"; type: "QDeclarativeCameraFocus"; isReadonly: true; isPointer: true }
- Property {
- name: "imageProcessing"
- type: "QDeclarativeCameraImageProcessing"
- isReadonly: true
- isPointer: true
- }
- Property {
- name: "metaData"
- revision: 1
- type: "QDeclarativeMediaMetaData"
- isReadonly: true
- isPointer: true
- }
- Property {
- name: "viewfinder"
- revision: 1
- type: "QDeclarativeCameraViewfinder"
- isReadonly: true
- isPointer: true
- }
- Signal { name: "errorChanged" }
- Signal {
- name: "error"
- Parameter { name: "errorCode"; type: "QDeclarativeCamera::Error" }
- Parameter { name: "errorString"; type: "string" }
- }
- Signal { name: "deviceIdChanged"; revision: 1 }
- Signal { name: "positionChanged"; revision: 1 }
- Signal { name: "displayNameChanged"; revision: 1 }
- Signal { name: "orientationChanged"; revision: 1 }
- Signal {
- name: "cameraStateChanged"
- Parameter { type: "QDeclarativeCamera::State" }
- }
- Signal {
- name: "opticalZoomChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "digitalZoomChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "maximumOpticalZoomChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "maximumDigitalZoomChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "availabilityChanged"
- Parameter { name: "availability"; type: "Availability" }
- }
- Method {
- name: "setCaptureMode"
- Parameter { name: "mode"; type: "CaptureMode" }
- }
- Method { name: "start" }
- Method { name: "stop" }
- Method {
- name: "setCameraState"
- Parameter { name: "state"; type: "State" }
- }
- Method { name: "searchAndLock" }
- Method { name: "unlock" }
- Method {
- name: "setOpticalZoom"
- Parameter { type: "double" }
- }
- Method {
- name: "setDigitalZoom"
- Parameter { type: "double" }
- }
- Method {
- name: "supportedViewfinderResolutions"
- revision: 2
- type: "QJSValue"
- Parameter { name: "minimumFrameRate"; type: "double" }
- Parameter { name: "maximumFrameRate"; type: "double" }
- }
- Method {
- name: "supportedViewfinderResolutions"
- revision: 2
- type: "QJSValue"
- Parameter { name: "minimumFrameRate"; type: "double" }
- }
- Method { name: "supportedViewfinderResolutions"; revision: 2; type: "QJSValue" }
- Method {
- name: "supportedViewfinderFrameRateRanges"
- revision: 2
- type: "QJSValue"
- Parameter { name: "resolution"; type: "QJSValue" }
- }
- Method { name: "supportedViewfinderFrameRateRanges"; revision: 2; type: "QJSValue" }
- }
- Component {
- name: "QDeclarativeCameraCapture"
- prototype: "QObject"
- exports: [
- "QtMultimedia/CameraCapture 5.0",
- "QtMultimedia/CameraCapture 5.9"
- ]
- isCreatable: false
- exportMetaObjectRevisions: [0, 1]
- Property { name: "ready"; type: "bool"; isReadonly: true }
- Property { name: "capturedImagePath"; type: "string"; isReadonly: true }
- Property { name: "resolution"; type: "QSize" }
- Property { name: "errorString"; type: "string"; isReadonly: true }
- Property { name: "supportedResolutions"; revision: 1; type: "QVariantList"; isReadonly: true }
- Signal {
- name: "readyForCaptureChanged"
- Parameter { type: "bool" }
- }
- Signal {
- name: "imageExposed"
- Parameter { name: "requestId"; type: "int" }
- }
- Signal {
- name: "imageCaptured"
- Parameter { name: "requestId"; type: "int" }
- Parameter { name: "preview"; type: "string" }
- }
- Signal {
- name: "imageMetadataAvailable"
- Parameter { name: "requestId"; type: "int" }
- Parameter { name: "key"; type: "string" }
- Parameter { name: "value"; type: "QVariant" }
- }
- Signal {
- name: "imageSaved"
- Parameter { name: "requestId"; type: "int" }
- Parameter { name: "path"; type: "string" }
- }
- Signal {
- name: "captureFailed"
- Parameter { name: "requestId"; type: "int" }
- Parameter { name: "message"; type: "string" }
- }
- Signal {
- name: "resolutionChanged"
- Parameter { type: "QSize" }
- }
- Method { name: "capture"; type: "int" }
- Method {
- name: "captureToLocation"
- type: "int"
- Parameter { name: "location"; type: "string" }
- }
- Method { name: "cancelCapture" }
- Method {
- name: "setResolution"
- Parameter { name: "resolution"; type: "QSize" }
- }
- Method {
- name: "setMetadata"
- Parameter { name: "key"; type: "string" }
- Parameter { name: "value"; type: "QVariant" }
- }
- }
- Component {
- name: "QDeclarativeCameraExposure"
- prototype: "QObject"
- exports: [
- "QtMultimedia/CameraExposure 5.0",
- "QtMultimedia/CameraExposure 5.11"
- ]
- isCreatable: false
- exportMetaObjectRevisions: [0, 1]
- Enum {
- name: "ExposureMode"
- values: {
- "ExposureAuto": 0,
- "ExposureManual": 1,
- "ExposurePortrait": 2,
- "ExposureNight": 3,
- "ExposureBacklight": 4,
- "ExposureSpotlight": 5,
- "ExposureSports": 6,
- "ExposureSnow": 7,
- "ExposureBeach": 8,
- "ExposureLargeAperture": 9,
- "ExposureSmallAperture": 10,
- "ExposureAction": 11,
- "ExposureLandscape": 12,
- "ExposureNightPortrait": 13,
- "ExposureTheatre": 14,
- "ExposureSunset": 15,
- "ExposureSteadyPhoto": 16,
- "ExposureFireworks": 17,
- "ExposureParty": 18,
- "ExposureCandlelight": 19,
- "ExposureBarcode": 20,
- "ExposureModeVendor": 1000
- }
- }
- Enum {
- name: "MeteringMode"
- values: {
- "MeteringMatrix": 1,
- "MeteringAverage": 2,
- "MeteringSpot": 3
- }
- }
- Property { name: "exposureCompensation"; type: "double" }
- Property { name: "iso"; type: "int"; isReadonly: true }
- Property { name: "shutterSpeed"; type: "double"; isReadonly: true }
- Property { name: "aperture"; type: "double"; isReadonly: true }
- Property { name: "manualShutterSpeed"; type: "double" }
- Property { name: "manualAperture"; type: "double" }
- Property { name: "manualIso"; type: "double" }
- Property { name: "exposureMode"; type: "ExposureMode" }
- Property { name: "supportedExposureModes"; revision: 1; type: "QVariantList"; isReadonly: true }
- Property { name: "spotMeteringPoint"; type: "QPointF" }
- Property { name: "meteringMode"; type: "MeteringMode" }
- Signal {
- name: "isoSensitivityChanged"
- Parameter { type: "int" }
- }
- Signal {
- name: "apertureChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "shutterSpeedChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "manualIsoSensitivityChanged"
- Parameter { type: "int" }
- }
- Signal {
- name: "manualApertureChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "manualShutterSpeedChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "exposureCompensationChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "exposureModeChanged"
- Parameter { type: "ExposureMode" }
- }
- Signal {
- name: "meteringModeChanged"
- Parameter { type: "MeteringMode" }
- }
- Signal {
- name: "spotMeteringPointChanged"
- Parameter { type: "QPointF" }
- }
- Method {
- name: "setExposureMode"
- Parameter { type: "ExposureMode" }
- }
- Method {
- name: "setExposureCompensation"
- Parameter { name: "ev"; type: "double" }
- }
- Method {
- name: "setManualAperture"
- Parameter { type: "double" }
- }
- Method {
- name: "setManualShutterSpeed"
- Parameter { type: "double" }
- }
- Method {
- name: "setManualIsoSensitivity"
- Parameter { name: "iso"; type: "int" }
- }
- Method { name: "setAutoAperture" }
- Method { name: "setAutoShutterSpeed" }
- Method { name: "setAutoIsoSensitivity" }
- }
- Component {
- name: "QDeclarativeCameraFlash"
- prototype: "QObject"
- exports: [
- "QtMultimedia/CameraFlash 5.0",
- "QtMultimedia/CameraFlash 5.9"
- ]
- isCreatable: false
- exportMetaObjectRevisions: [0, 1]
- Enum {
- name: "FlashMode"
- values: {
- "FlashAuto": 1,
- "FlashOff": 2,
- "FlashOn": 4,
- "FlashRedEyeReduction": 8,
- "FlashFill": 16,
- "FlashTorch": 32,
- "FlashVideoLight": 64,
- "FlashSlowSyncFrontCurtain": 128,
- "FlashSlowSyncRearCurtain": 256,
- "FlashManual": 512
- }
- }
- Property { name: "ready"; type: "bool"; isReadonly: true }
- Property { name: "mode"; type: "FlashMode" }
- Property { name: "supportedModes"; revision: 1; type: "QVariantList"; isReadonly: true }
- Signal {
- name: "flashReady"
- Parameter { name: "status"; type: "bool" }
- }
- Signal {
- name: "flashModeChanged"
- Parameter { type: "FlashMode" }
- }
- Method {
- name: "setFlashMode"
- Parameter { type: "FlashMode" }
- }
- }
- Component {
- name: "QDeclarativeCameraFocus"
- prototype: "QObject"
- exports: [
- "QtMultimedia/CameraFocus 5.0",
- "QtMultimedia/CameraFocus 5.11"
- ]
- isCreatable: false
- exportMetaObjectRevisions: [0, 1]
- Enum {
- name: "FocusMode"
- values: {
- "FocusManual": 1,
- "FocusHyperfocal": 2,
- "FocusInfinity": 4,
- "FocusAuto": 8,
- "FocusContinuous": 16,
- "FocusMacro": 32
- }
- }
- Enum {
- name: "FocusPointMode"
- values: {
- "FocusPointAuto": 0,
- "FocusPointCenter": 1,
- "FocusPointFaceDetection": 2,
- "FocusPointCustom": 3
- }
- }
- Property { name: "focusMode"; type: "FocusMode" }
- Property { name: "supportedFocusModes"; revision: 1; type: "QVariantList"; isReadonly: true }
- Property { name: "focusPointMode"; type: "FocusPointMode" }
- Property { name: "supportedFocusPointModes"; revision: 1; type: "QVariantList"; isReadonly: true }
- Property { name: "customFocusPoint"; type: "QPointF" }
- Property { name: "focusZones"; type: "QObject"; isReadonly: true; isPointer: true }
- Signal {
- name: "focusModeChanged"
- Parameter { type: "FocusMode" }
- }
- Signal {
- name: "focusPointModeChanged"
- Parameter { type: "FocusPointMode" }
- }
- Signal {
- name: "customFocusPointChanged"
- Parameter { type: "QPointF" }
- }
- Method {
- name: "setFocusMode"
- Parameter { type: "FocusMode" }
- }
- Method {
- name: "setFocusPointMode"
- Parameter { name: "mode"; type: "FocusPointMode" }
- }
- Method {
- name: "setCustomFocusPoint"
- Parameter { name: "point"; type: "QPointF" }
- }
- Method {
- name: "isFocusModeSupported"
- type: "bool"
- Parameter { name: "mode"; type: "FocusMode" }
- }
- Method {
- name: "isFocusPointModeSupported"
- type: "bool"
- Parameter { name: "mode"; type: "FocusPointMode" }
- }
- }
- Component {
- name: "QDeclarativeCameraImageProcessing"
- prototype: "QObject"
- exports: [
- "QtMultimedia/CameraImageProcessing 5.0",
- "QtMultimedia/CameraImageProcessing 5.11",
- "QtMultimedia/CameraImageProcessing 5.5",
- "QtMultimedia/CameraImageProcessing 5.7"
- ]
- isCreatable: false
- exportMetaObjectRevisions: [0, 3, 1, 2]
- Enum {
- name: "WhiteBalanceMode"
- values: {
- "WhiteBalanceAuto": 0,
- "WhiteBalanceManual": 1,
- "WhiteBalanceSunlight": 2,
- "WhiteBalanceCloudy": 3,
- "WhiteBalanceShade": 4,
- "WhiteBalanceTungsten": 5,
- "WhiteBalanceFluorescent": 6,
- "WhiteBalanceFlash": 7,
- "WhiteBalanceSunset": 8,
- "WhiteBalanceVendor": 1000
- }
- }
- Enum {
- name: "ColorFilter"
- values: {
- "ColorFilterNone": 0,
- "ColorFilterGrayscale": 1,
- "ColorFilterNegative": 2,
- "ColorFilterSolarize": 3,
- "ColorFilterSepia": 4,
- "ColorFilterPosterize": 5,
- "ColorFilterWhiteboard": 6,
- "ColorFilterBlackboard": 7,
- "ColorFilterAqua": 8,
- "ColorFilterVendor": 1000
- }
- }
- Property { name: "whiteBalanceMode"; type: "WhiteBalanceMode" }
- Property { name: "manualWhiteBalance"; type: "double" }
- Property { name: "brightness"; revision: 2; type: "double" }
- Property { name: "contrast"; type: "double" }
- Property { name: "saturation"; type: "double" }
- Property { name: "sharpeningLevel"; type: "double" }
- Property { name: "denoisingLevel"; type: "double" }
- Property { name: "colorFilter"; revision: 1; type: "ColorFilter" }
- Property { name: "available"; revision: 3; type: "bool"; isReadonly: true }
- Property { name: "supportedColorFilters"; revision: 3; type: "QVariantList"; isReadonly: true }
- Property {
- name: "supportedWhiteBalanceModes"
- revision: 3
- type: "QVariantList"
- isReadonly: true
- }
- Signal {
- name: "whiteBalanceModeChanged"
- Parameter { type: "QDeclarativeCameraImageProcessing::WhiteBalanceMode" }
- }
- Signal {
- name: "manualWhiteBalanceChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "brightnessChanged"
- revision: 2
- Parameter { type: "double" }
- }
- Signal {
- name: "contrastChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "saturationChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "sharpeningLevelChanged"
- Parameter { type: "double" }
- }
- Signal {
- name: "denoisingLevelChanged"
- Parameter { type: "double" }
- }
- Method {
- name: "setWhiteBalanceMode"
- Parameter { name: "mode"; type: "QDeclarativeCameraImageProcessing::WhiteBalanceMode" }
- }
- Method {
- name: "setManualWhiteBalance"
- Parameter { name: "colorTemp"; type: "double" }
- }
- Method {
- name: "setBrightness"
- revision: 2
- Parameter { name: "value"; type: "double" }
- }
- Method {
- name: "setContrast"
- Parameter { name: "value"; type: "double" }
- }
- Method {
- name: "setSaturation"
- Parameter { name: "value"; type: "double" }
- }
- Method {
- name: "setSharpeningLevel"
- Parameter { name: "value"; type: "double" }
- }
- Method {
- name: "setDenoisingLevel"
- Parameter { name: "value"; type: "double" }
- }
- Method {
- name: "setColorFilter"
- Parameter { name: "colorFilter"; type: "ColorFilter" }
- }
- }
- Component {
- name: "QDeclarativeCameraRecorder"
- prototype: "QObject"
- exports: ["QtMultimedia/CameraRecorder 5.0"]
- isCreatable: false
- exportMetaObjectRevisions: [0]
- Enum {
- name: "RecorderState"
- values: {
- "StoppedState": 0,
- "RecordingState": 1
- }
- }
- Enum {
- name: "RecorderStatus"
- values: {
- "UnavailableStatus": 0,
- "UnloadedStatus": 1,
- "LoadingStatus": 2,
- "LoadedStatus": 3,
- "StartingStatus": 4,
- "RecordingStatus": 5,
- "PausedStatus": 6,
- "FinalizingStatus": 7
- }
- }
- Enum {
- name: "EncodingMode"
- values: {
- "ConstantQualityEncoding": 0,
- "ConstantBitRateEncoding": 1,
- "AverageBitRateEncoding": 2
- }
- }
- Enum {
- name: "Error"
- values: {
- "NoError": 0,
- "ResourceError": 1,
- "FormatError": 2,
- "OutOfSpaceError": 3
- }
- }
- Property { name: "recorderState"; type: "RecorderState" }
- Property { name: "recorderStatus"; type: "RecorderStatus"; isReadonly: true }
- Property { name: "videoCodec"; type: "string" }
- Property { name: "resolution"; type: "QSize" }
- Property { name: "frameRate"; type: "double" }
- Property { name: "videoBitRate"; type: "int" }
- Property { name: "videoEncodingMode"; type: "EncodingMode" }
- Property { name: "audioCodec"; type: "string" }
- Property { name: "audioBitRate"; type: "int" }
- Property { name: "audioChannels"; type: "int" }
- Property { name: "audioSampleRate"; type: "int" }
- Property { name: "audioEncodingMode"; type: "EncodingMode" }
- Property { name: "mediaContainer"; type: "string" }
- Property { name: "duration"; type: "qlonglong"; isReadonly: true }
- Property { name: "outputLocation"; type: "string" }
- Property { name: "actualLocation"; type: "string"; isReadonly: true }
- Property { name: "muted"; type: "bool" }
- Property { name: "errorString"; type: "string"; isReadonly: true }
- Property { name: "errorCode"; type: "Error"; isReadonly: true }
- Signal {
- name: "recorderStateChanged"
- Parameter { name: "state"; type: "QDeclarativeCameraRecorder::RecorderState" }
- }
- Signal {
- name: "durationChanged"
- Parameter { name: "duration"; type: "qlonglong" }
- }
- Signal {
- name: "mutedChanged"
- Parameter { name: "muted"; type: "bool" }
- }
- Signal {
- name: "outputLocationChanged"
- Parameter { name: "location"; type: "string" }
- }
- Signal {
- name: "actualLocationChanged"
- Parameter { name: "location"; type: "string" }
- }
- Signal {
- name: "error"
- Parameter { name: "errorCode"; type: "QDeclarativeCameraRecorder::Error" }
- Parameter { name: "errorString"; type: "string" }
- }
- Signal {
- name: "metaDataChanged"
- Parameter { name: "key"; type: "string" }
- Parameter { name: "value"; type: "QVariant" }
- }
- Signal {
- name: "captureResolutionChanged"
- Parameter { type: "QSize" }
- }
- Signal {
- name: "audioCodecChanged"
- Parameter { name: "codec"; type: "string" }
- }
- Signal {
- name: "videoCodecChanged"
- Parameter { name: "codec"; type: "string" }
- }
- Signal {
- name: "mediaContainerChanged"
- Parameter { name: "container"; type: "string" }
- }
- Signal {
- name: "frameRateChanged"
- Parameter { name: "arg"; type: "double" }
- }
- Signal {
- name: "videoBitRateChanged"
- Parameter { name: "arg"; type: "int" }
- }
- Signal {
- name: "audioBitRateChanged"
- Parameter { name: "arg"; type: "int" }
- }
- Signal {
- name: "audioChannelsChanged"
- Parameter { name: "arg"; type: "int" }
- }
- Signal {
- name: "audioSampleRateChanged"
- Parameter { name: "arg"; type: "int" }
- }
- Signal {
- name: "audioEncodingModeChanged"
- Parameter { name: "encodingMode"; type: "EncodingMode" }
- }
- Signal {
- name: "videoEncodingModeChanged"
- Parameter { name: "encodingMode"; type: "EncodingMode" }
- }
- Method {
- name: "setOutputLocation"
- Parameter { name: "location"; type: "string" }
- }
- Method { name: "record" }
- Method { name: "stop" }
- Method {
- name: "setRecorderState"
- Parameter { name: "state"; type: "QDeclarativeCameraRecorder::RecorderState" }
- }
- Method {
- name: "setMuted"
- Parameter { name: "muted"; type: "bool" }
- }
- Method {
- name: "setMetadata"
- Parameter { name: "key"; type: "string" }
- Parameter { name: "value"; type: "QVariant" }
- }
- Method {
- name: "setCaptureResolution"
- Parameter { name: "resolution"; type: "QSize" }
- }
- Method {
- name: "setAudioCodec"
- Parameter { name: "codec"; type: "string" }
- }
- Method {
- name: "setVideoCodec"
- Parameter { name: "codec"; type: "string" }
- }
- Method {
- name: "setMediaContainer"
- Parameter { name: "container"; type: "string" }
- }
- Method {
- name: "setFrameRate"
- Parameter { name: "frameRate"; type: "double" }
- }
- Method {
- name: "setVideoBitRate"
- Parameter { name: "rate"; type: "int" }
- }
- Method {
- name: "setAudioBitRate"
- Parameter { name: "rate"; type: "int" }
- }
- Method {
- name: "setAudioChannels"
- Parameter { name: "channels"; type: "int" }
- }
- Method {
- name: "setAudioSampleRate"
- Parameter { name: "rate"; type: "int" }
- }
- Method {
- name: "setVideoEncodingMode"
- Parameter { name: "encodingMode"; type: "EncodingMode" }
- }
- Method {
- name: "setAudioEncodingMode"
- Parameter { name: "encodingMode"; type: "EncodingMode" }
- }
- }
- Component {
- name: "QDeclarativeCameraViewfinder"
- prototype: "QObject"
- exports: ["QtMultimedia/CameraViewfinder 5.4"]
- isCreatable: false
- exportMetaObjectRevisions: [0]
- Property { name: "resolution"; type: "QSize" }
- Property { name: "minimumFrameRate"; type: "double" }
- Property { name: "maximumFrameRate"; type: "double" }
- }
- Component {
- name: "QDeclarativeMediaMetaData"
- prototype: "QObject"
- Property { name: "title"; type: "QVariant" }
- Property { name: "subTitle"; type: "QVariant" }
- Property { name: "author"; type: "QVariant" }
- Property { name: "comment"; type: "QVariant" }
- Property { name: "description"; type: "QVariant" }
- Property { name: "category"; type: "QVariant" }
- Property { name: "genre"; type: "QVariant" }
- Property { name: "year"; type: "QVariant" }
- Property { name: "date"; type: "QVariant" }
- Property { name: "userRating"; type: "QVariant" }
- Property { name: "keywords"; type: "QVariant" }
- Property { name: "language"; type: "QVariant" }
- Property { name: "publisher"; type: "QVariant" }
- Property { name: "copyright"; type: "QVariant" }
- Property { name: "parentalRating"; type: "QVariant" }
- Property { name: "ratingOrganization"; type: "QVariant" }
- Property { name: "size"; type: "QVariant" }
- Property { name: "mediaType"; type: "QVariant" }
- Property { name: "duration"; type: "QVariant" }
- Property { name: "audioBitRate"; type: "QVariant" }
- Property { name: "audioCodec"; type: "QVariant" }
- Property { name: "averageLevel"; type: "QVariant" }
- Property { name: "channelCount"; type: "QVariant" }
- Property { name: "peakValue"; type: "QVariant" }
- Property { name: "sampleRate"; type: "QVariant" }
- Property { name: "albumTitle"; type: "QVariant" }
- Property { name: "albumArtist"; type: "QVariant" }
- Property { name: "contributingArtist"; type: "QVariant" }
- Property { name: "composer"; type: "QVariant" }
- Property { name: "conductor"; type: "QVariant" }
- Property { name: "lyrics"; type: "QVariant" }
- Property { name: "mood"; type: "QVariant" }
- Property { name: "trackNumber"; type: "QVariant" }
- Property { name: "trackCount"; type: "QVariant" }
- Property { name: "coverArtUrlSmall"; type: "QVariant" }
- Property { name: "coverArtUrlLarge"; type: "QVariant" }
- Property { name: "resolution"; type: "QVariant" }
- Property { name: "pixelAspectRatio"; type: "QVariant" }
- Property { name: "videoFrameRate"; type: "QVariant" }
- Property { name: "videoBitRate"; type: "QVariant" }
- Property { name: "videoCodec"; type: "QVariant" }
- Property { name: "posterUrl"; type: "QVariant" }
- Property { name: "chapterNumber"; type: "QVariant" }
- Property { name: "director"; type: "QVariant" }
- Property { name: "leadPerformer"; type: "QVariant" }
- Property { name: "writer"; type: "QVariant" }
- Property { name: "cameraManufacturer"; type: "QVariant" }
- Property { name: "cameraModel"; type: "QVariant" }
- Property { name: "event"; type: "QVariant" }
- Property { name: "subject"; type: "QVariant" }
- Property { name: "orientation"; type: "QVariant" }
- Property { name: "exposureTime"; type: "QVariant" }
- Property { name: "fNumber"; type: "QVariant" }
- Property { name: "exposureProgram"; type: "QVariant" }
- Property { name: "isoSpeedRatings"; type: "QVariant" }
- Property { name: "exposureBiasValue"; type: "QVariant" }
- Property { name: "dateTimeOriginal"; type: "QVariant" }
- Property { name: "dateTimeDigitized"; type: "QVariant" }
- Property { name: "subjectDistance"; type: "QVariant" }
- Property { name: "meteringMode"; type: "QVariant" }
- Property { name: "lightSource"; type: "QVariant" }
- Property { name: "flash"; type: "QVariant" }
- Property { name: "focalLength"; type: "QVariant" }
- Property { name: "exposureMode"; type: "QVariant" }
- Property { name: "whiteBalance"; type: "QVariant" }
- Property { name: "digitalZoomRatio"; type: "QVariant" }
- Property { name: "focalLengthIn35mmFilm"; type: "QVariant" }
- Property { name: "sceneCaptureType"; type: "QVariant" }
- Property { name: "gainControl"; type: "QVariant" }
- Property { name: "contrast"; type: "QVariant" }
- Property { name: "saturation"; type: "QVariant" }
- Property { name: "sharpness"; type: "QVariant" }
- Property { name: "deviceSettingDescription"; type: "QVariant" }
- Property { name: "gpsLatitude"; type: "QVariant" }
- Property { name: "gpsLongitude"; type: "QVariant" }
- Property { name: "gpsAltitude"; type: "QVariant" }
- Property { name: "gpsTimeStamp"; type: "QVariant" }
- Property { name: "gpsSatellites"; type: "QVariant" }
- Property { name: "gpsStatus"; type: "QVariant" }
- Property { name: "gpsDOP"; type: "QVariant" }
- Property { name: "gpsSpeed"; type: "QVariant" }
- Property { name: "gpsTrack"; type: "QVariant" }
- Property { name: "gpsTrackRef"; type: "QVariant" }
- Property { name: "gpsImgDirection"; type: "QVariant" }
- Property { name: "gpsImgDirectionRef"; type: "QVariant" }
- Property { name: "gpsMapDatum"; type: "QVariant" }
- Property { name: "gpsProcessingMethod"; type: "QVariant" }
- Property { name: "gpsAreaInformation"; type: "QVariant" }
- Signal { name: "metaDataChanged" }
- }
- Component {
- name: "QDeclarativeMultimediaGlobal"
- prototype: "QObject"
- exports: ["QtMultimedia/QtMultimedia 5.4"]
- isCreatable: false
- isSingleton: true
- exportMetaObjectRevisions: [0]
- Enum {
- name: "VolumeScale"
- values: {
- "LinearVolumeScale": 0,
- "CubicVolumeScale": 1,
- "LogarithmicVolumeScale": 2,
- "DecibelVolumeScale": 3
- }
- }
- Property { name: "defaultCamera"; type: "QJSValue"; isReadonly: true }
- Property { name: "availableCameras"; type: "QJSValue"; isReadonly: true }
- Method {
- name: "convertVolume"
- type: "double"
- Parameter { name: "volume"; type: "double" }
- Parameter { name: "from"; type: "VolumeScale" }
- Parameter { name: "to"; type: "VolumeScale" }
- }
- }
- Component {
- name: "QDeclarativePlaylist"
- defaultProperty: "items"
- prototype: "QAbstractListModel"
- exports: ["QtMultimedia/Playlist 5.6", "QtMultimedia/Playlist 5.7"]
- exportMetaObjectRevisions: [0, 1]
- Enum {
- name: "PlaybackMode"
- values: {
- "CurrentItemOnce": 0,
- "CurrentItemInLoop": 1,
- "Sequential": 2,
- "Loop": 3,
- "Random": 4
- }
- }
- Enum {
- name: "Error"
- values: {
- "NoError": 0,
- "FormatError": 1,
- "FormatNotSupportedError": 2,
- "NetworkError": 3,
- "AccessDeniedError": 4
- }
- }
- Property { name: "playbackMode"; type: "PlaybackMode" }
- Property { name: "currentItemSource"; type: "QUrl"; isReadonly: true }
- Property { name: "currentIndex"; type: "int" }
- Property { name: "itemCount"; type: "int"; isReadonly: true }
- Property { name: "readOnly"; type: "bool"; isReadonly: true }
- Property { name: "error"; type: "Error"; isReadonly: true }
- Property { name: "errorString"; type: "string"; isReadonly: true }
- Property { name: "items"; type: "QDeclarativePlaylistItem"; isList: true; isReadonly: true }
- Signal {
- name: "itemAboutToBeInserted"
- Parameter { name: "start"; type: "int" }
- Parameter { name: "end"; type: "int" }
- }
- Signal {
- name: "itemInserted"
- Parameter { name: "start"; type: "int" }
- Parameter { name: "end"; type: "int" }
- }
- Signal {
- name: "itemAboutToBeRemoved"
- Parameter { name: "start"; type: "int" }
- Parameter { name: "end"; type: "int" }
- }
- Signal {
- name: "itemRemoved"
- Parameter { name: "start"; type: "int" }
- Parameter { name: "end"; type: "int" }
- }
- Signal {
- name: "itemChanged"
- Parameter { name: "start"; type: "int" }
- Parameter { name: "end"; type: "int" }
- }
- Signal { name: "loaded" }
- Signal { name: "loadFailed" }
- Signal {
- name: "error"
- Parameter { name: "error"; type: "QDeclarativePlaylist::Error" }
- Parameter { name: "errorString"; type: "string" }
- }
- Method {
- name: "itemSource"
- type: "QUrl"
- Parameter { name: "index"; type: "int" }
- }
- Method {
- name: "nextIndex"
- type: "int"
- Parameter { name: "steps"; type: "int" }
- }
- Method { name: "nextIndex"; type: "int" }
- Method {
- name: "previousIndex"
- type: "int"
- Parameter { name: "steps"; type: "int" }
- }
- Method { name: "previousIndex"; type: "int" }
- Method { name: "next" }
- Method { name: "previous" }
- Method { name: "shuffle" }
- Method {
- name: "load"
- Parameter { name: "location"; type: "QUrl" }
- Parameter { name: "format"; type: "string" }
- }
- Method {
- name: "load"
- Parameter { name: "location"; type: "QUrl" }
- }
- Method {
- name: "save"
- type: "bool"
- Parameter { name: "location"; type: "QUrl" }
- Parameter { name: "format"; type: "string" }
- }
- Method {
- name: "save"
- type: "bool"
- Parameter { name: "location"; type: "QUrl" }
- }
- Method {
- name: "addItem"
- type: "bool"
- Parameter { name: "source"; type: "QUrl" }
- }
- Method {
- name: "addItems"
- revision: 1
- type: "bool"
- Parameter { name: "sources"; type: "QList<QUrl>" }
- }
- Method {
- name: "insertItem"
- type: "bool"
- Parameter { name: "index"; type: "int" }
- Parameter { name: "source"; type: "QUrl" }
- }
- Method {
- name: "insertItems"
- revision: 1
- type: "bool"
- Parameter { name: "index"; type: "int" }
- Parameter { name: "sources"; type: "QList<QUrl>" }
- }
- Method {
- name: "moveItem"
- revision: 1
- type: "bool"
- Parameter { name: "from"; type: "int" }
- Parameter { name: "to"; type: "int" }
- }
- Method {
- name: "removeItem"
- type: "bool"
- Parameter { name: "index"; type: "int" }
- }
- Method {
- name: "removeItems"
- revision: 1
- type: "bool"
- Parameter { name: "start"; type: "int" }
- Parameter { name: "end"; type: "int" }
- }
- Method { name: "clear"; type: "bool" }
- }
- Component {
- name: "QDeclarativePlaylistItem"
- prototype: "QObject"
- exports: ["QtMultimedia/PlaylistItem 5.6"]
- exportMetaObjectRevisions: [0]
- Property { name: "source"; type: "QUrl" }
- }
- Component {
- name: "QDeclarativeRadio"
- prototype: "QObject"
- exports: ["QtMultimedia/Radio 5.0"]
- exportMetaObjectRevisions: [0]
- Enum {
- name: "State"
- values: {
- "ActiveState": 0,
- "StoppedState": 1
- }
- }
- Enum {
- name: "Band"
- values: {
- "AM": 0,
- "FM": 1,
- "SW": 2,
- "LW": 3,
- "FM2": 4
- }
- }
- Enum {
- name: "Error"
- values: {
- "NoError": 0,
- "ResourceError": 1,
- "OpenError": 2,
- "OutOfRangeError": 3
- }
- }
- Enum {
- name: "StereoMode"
- values: {
- "ForceStereo": 0,
- "ForceMono": 1,
- "Auto": 2
- }
- }
- Enum {
- name: "SearchMode"
- values: {
- "SearchFast": 0,
- "SearchGetStationId": 1
- }
- }
- Enum {
- name: "Availability"
- values: {
- "Available": 0,
- "Busy": 2,
- "Unavailable": 1,
- "ResourceMissing": 3
- }
- }
- Property { name: "state"; type: "State"; isReadonly: true }
- Property { name: "band"; type: "Band" }
- Property { name: "frequency"; type: "int" }
- Property { name: "stereo"; type: "bool"; isReadonly: true }
- Property { name: "stereoMode"; type: "StereoMode" }
- Property { name: "signalStrength"; type: "int"; isReadonly: true }
- Property { name: "volume"; type: "int" }
- Property { name: "muted"; type: "bool" }
- Property { name: "searching"; type: "bool"; isReadonly: true }
- Property { name: "frequencyStep"; type: "int"; isReadonly: true }
- Property { name: "minimumFrequency"; type: "int"; isReadonly: true }
- Property { name: "maximumFrequency"; type: "int"; isReadonly: true }
- Property { name: "antennaConnected"; type: "bool"; isReadonly: true }
- Property { name: "availability"; type: "Availability"; isReadonly: true }
- Property { name: "radioData"; type: "QDeclarativeRadioData"; isReadonly: true; isPointer: true }
- Signal {
- name: "stateChanged"
- Parameter { name: "state"; type: "QDeclarativeRadio::State" }
- }
- Signal {
- name: "bandChanged"
- Parameter { name: "band"; type: "QDeclarativeRadio::Band" }
- }
- Signal {
- name: "frequencyChanged"
- Parameter { name: "frequency"; type: "int" }
- }
- Signal {
- name: "stereoStatusChanged"
- Parameter { name: "stereo"; type: "bool" }
- }
- Signal {
- name: "searchingChanged"
- Parameter { name: "searching"; type: "bool" }
- }
- Signal {
- name: "signalStrengthChanged"
- Parameter { name: "signalStrength"; type: "int" }
- }
- Signal {
- name: "volumeChanged"
- Parameter { name: "volume"; type: "int" }
- }
- Signal {
- name: "mutedChanged"
- Parameter { name: "muted"; type: "bool" }
- }
- Signal {
- name: "stationFound"
- Parameter { name: "frequency"; type: "int" }
- Parameter { name: "stationId"; type: "string" }
- }
- Signal {
- name: "antennaConnectedChanged"
- Parameter { name: "connectionStatus"; type: "bool" }
- }
- Signal {
- name: "availabilityChanged"
- Parameter { name: "availability"; type: "Availability" }
- }
- Signal { name: "errorChanged" }
- Signal {
- name: "error"
- Parameter { name: "errorCode"; type: "QDeclarativeRadio::Error" }
- }
- Method {
- name: "setBand"
- Parameter { name: "band"; type: "QDeclarativeRadio::Band" }
- }
- Method {
- name: "setFrequency"
- Parameter { name: "frequency"; type: "int" }
- }
- Method {
- name: "setStereoMode"
- Parameter { name: "stereoMode"; type: "QDeclarativeRadio::StereoMode" }
- }
- Method {
- name: "setVolume"
- Parameter { name: "volume"; type: "int" }
- }
- Method {
- name: "setMuted"
- Parameter { name: "muted"; type: "bool" }
- }
- Method { name: "cancelScan" }
- Method { name: "scanDown" }
- Method { name: "scanUp" }
- Method { name: "tuneUp" }
- Method { name: "tuneDown" }
- Method {
- name: "searchAllStations"
- Parameter { name: "searchMode"; type: "QDeclarativeRadio::SearchMode" }
- }
- Method { name: "searchAllStations" }
- Method { name: "start" }
- Method { name: "stop" }
- Method { name: "isAvailable"; type: "bool" }
- }
- Component {
- name: "QDeclarativeRadioData"
- prototype: "QObject"
- exports: ["QtMultimedia/RadioData 5.0"]
- exportMetaObjectRevisions: [0]
- Enum {
- name: "Error"
- values: {
- "NoError": 0,
- "ResourceError": 1,
- "OpenError": 2,
- "OutOfRangeError": 3
- }
- }
- Enum {
- name: "ProgramType"
- values: {
- "Undefined": 0,
- "News": 1,
- "CurrentAffairs": 2,
- "Information": 3,
- "Sport": 4,
- "Education": 5,
- "Drama": 6,
- "Culture": 7,
- "Science": 8,
- "Varied": 9,
- "PopMusic": 10,
- "RockMusic": 11,
- "EasyListening": 12,
- "LightClassical": 13,
- "SeriousClassical": 14,
- "OtherMusic": 15,
- "Weather": 16,
- "Finance": 17,
- "ChildrensProgrammes": 18,
- "SocialAffairs": 19,
- "Religion": 20,
- "PhoneIn": 21,
- "Travel": 22,
- "Leisure": 23,
- "JazzMusic": 24,
- "CountryMusic": 25,
- "NationalMusic": 26,
- "OldiesMusic": 27,
- "FolkMusic": 28,
- "Documentary": 29,
- "AlarmTest": 30,
- "Alarm": 31,
- "Talk": 32,
- "ClassicRock": 33,
- "AdultHits": 34,
- "SoftRock": 35,
- "Top40": 36,
- "Soft": 37,
- "Nostalgia": 38,
- "Classical": 39,
- "RhythmAndBlues": 40,
- "SoftRhythmAndBlues": 41,
- "Language": 42,
- "ReligiousMusic": 43,
- "ReligiousTalk": 44,
- "Personality": 45,
- "Public": 46,
- "College": 47
- }
- }
- Enum {
- name: "Availability"
- values: {
- "Available": 0,
- "Busy": 2,
- "Unavailable": 1,
- "ResourceMissing": 3
- }
- }
- Property { name: "stationId"; type: "string"; isReadonly: true }
- Property { name: "programType"; type: "QDeclarativeRadioData::ProgramType"; isReadonly: true }
- Property { name: "programTypeName"; type: "string"; isReadonly: true }
- Property { name: "stationName"; type: "string"; isReadonly: true }
- Property { name: "radioText"; type: "string"; isReadonly: true }
- Property { name: "alternativeFrequenciesEnabled"; type: "bool" }
- Property { name: "availability"; type: "Availability"; isReadonly: true }
- Signal {
- name: "stationIdChanged"
- Parameter { name: "stationId"; type: "string" }
- }
- Signal {
- name: "programTypeChanged"
- Parameter { name: "programType"; type: "QDeclarativeRadioData::ProgramType" }
- }
- Signal {
- name: "programTypeNameChanged"
- Parameter { name: "programTypeName"; type: "string" }
- }
- Signal {
- name: "stationNameChanged"
- Parameter { name: "stationName"; type: "string" }
- }
- Signal {
- name: "radioTextChanged"
- Parameter { name: "radioText"; type: "string" }
- }
- Signal {
- name: "alternativeFrequenciesEnabledChanged"
- Parameter { name: "enabled"; type: "bool" }
- }
- Signal {
- name: "availabilityChanged"
- Parameter { name: "availability"; type: "Availability" }
- }
- Signal { name: "errorChanged" }
- Signal {
- name: "error"
- Parameter { name: "errorCode"; type: "QDeclarativeRadioData::Error" }
- }
- Method {
- name: "setAlternativeFrequenciesEnabled"
- Parameter { name: "enabled"; type: "bool" }
- }
- Method { name: "isAvailable"; type: "bool" }
- }
- Component {
- name: "QDeclarativeTorch"
- prototype: "QObject"
- exports: ["QtMultimedia/Torch 5.0"]
- exportMetaObjectRevisions: [0]
- Property { name: "enabled"; type: "bool" }
- Property { name: "power"; type: "int" }
- }
- Component {
- name: "QDeclarativeVideoOutput"
- defaultProperty: "data"
- prototype: "QQuickItem"
- exports: [
- "QtMultimedia/VideoOutput 5.0",
- "QtMultimedia/VideoOutput 5.13",
- "QtMultimedia/VideoOutput 5.15",
- "QtMultimedia/VideoOutput 5.2"
- ]
- exportMetaObjectRevisions: [0, 13, 15, 2]
- Enum {
- name: "FlushMode"
- values: {
- "EmptyFrame": 0,
- "FirstFrame": 1,
- "LastFrame": 2
- }
- }
- Enum {
- name: "FillMode"
- values: {
- "Stretch": 0,
- "PreserveAspectFit": 1,
- "PreserveAspectCrop": 2
- }
- }
- Property { name: "source"; type: "QObject"; isPointer: true }
- Property { name: "fillMode"; type: "FillMode" }
- Property { name: "orientation"; type: "int" }
- Property { name: "autoOrientation"; revision: 2; type: "bool" }
- Property { name: "sourceRect"; type: "QRectF"; isReadonly: true }
- Property { name: "contentRect"; type: "QRectF"; isReadonly: true }
- Property { name: "filters"; type: "QAbstractVideoFilter"; isList: true; isReadonly: true }
- Property { name: "flushMode"; revision: 13; type: "FlushMode" }
- Property {
- name: "videoSurface"
- revision: 15
- type: "QAbstractVideoSurface"
- isReadonly: true
- isPointer: true
- }
- Signal {
- name: "fillModeChanged"
- Parameter { type: "QDeclarativeVideoOutput::FillMode" }
- }
- Method {
- name: "mapPointToItem"
- type: "QPointF"
- Parameter { name: "point"; type: "QPointF" }
- }
- Method {
- name: "mapRectToItem"
- type: "QRectF"
- Parameter { name: "rectangle"; type: "QRectF" }
- }
- Method {
- name: "mapNormalizedPointToItem"
- type: "QPointF"
- Parameter { name: "point"; type: "QPointF" }
- }
- Method {
- name: "mapNormalizedRectToItem"
- type: "QRectF"
- Parameter { name: "rectangle"; type: "QRectF" }
- }
- Method {
- name: "mapPointToSource"
- type: "QPointF"
- Parameter { name: "point"; type: "QPointF" }
- }
- Method {
- name: "mapRectToSource"
- type: "QRectF"
- Parameter { name: "rectangle"; type: "QRectF" }
- }
- Method {
- name: "mapPointToSourceNormalized"
- type: "QPointF"
- Parameter { name: "point"; type: "QPointF" }
- }
- Method {
- name: "mapRectToSourceNormalized"
- type: "QRectF"
- Parameter { name: "rectangle"; type: "QRectF" }
- }
- }
- Component {
- name: "QMediaObject"
- prototype: "QObject"
- Property { name: "notifyInterval"; type: "int" }
- Signal {
- name: "notifyIntervalChanged"
- Parameter { name: "milliSeconds"; type: "int" }
- }
- Signal {
- name: "metaDataAvailableChanged"
- Parameter { name: "available"; type: "bool" }
- }
- Signal { name: "metaDataChanged" }
- Signal {
- name: "metaDataChanged"
- Parameter { name: "key"; type: "string" }
- Parameter { name: "value"; type: "QVariant" }
- }
- Signal {
- name: "availabilityChanged"
- Parameter { name: "available"; type: "bool" }
- }
- Signal {
- name: "availabilityChanged"
- Parameter { name: "availability"; type: "QMultimedia::AvailabilityStatus" }
- }
- }
- Component { name: "QSGVideoItemSurface"; prototype: "QAbstractVideoSurface" }
- Component {
- name: "QSoundEffect"
- prototype: "QObject"
- exports: [
- "QtMultimedia/SoundEffect 5.0",
- "QtMultimedia/SoundEffect 5.3",
- "QtMultimedia/SoundEffect 5.8"
- ]
- exportMetaObjectRevisions: [0, 0, 0]
- Enum {
- name: "Loop"
- values: {
- "Infinite": -2
- }
- }
- Enum {
- name: "Status"
- values: {
- "Null": 0,
- "Loading": 1,
- "Ready": 2,
- "Error": 3
- }
- }
- Property { name: "source"; type: "QUrl" }
- Property { name: "loops"; type: "int" }
- Property { name: "loopsRemaining"; type: "int"; isReadonly: true }
- Property { name: "volume"; type: "double" }
- Property { name: "muted"; type: "bool" }
- Property { name: "playing"; type: "bool"; isReadonly: true }
- Property { name: "status"; type: "Status"; isReadonly: true }
- Property { name: "category"; type: "string" }
- Signal { name: "loopCountChanged" }
- Signal { name: "loadedChanged" }
- Method { name: "play" }
- Method { name: "stop" }
- }
-}
diff --git a/src/imports/multimedia/qdeclarativeaudio.cpp b/src/imports/multimedia/qdeclarativeaudio.cpp
deleted file mode 100644
index 75b39e19c..000000000
--- a/src/imports/multimedia/qdeclarativeaudio.cpp
+++ /dev/null
@@ -1,1736 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include <QtQml/qqmlinfo.h>
-
-#include "qdeclarativeaudio_p.h"
-
-#include <qmediaplayercontrol.h>
-#include <qmediaavailabilitycontrol.h>
-
-#include <qmediaservice.h>
-#include <private/qmediaserviceprovider_p.h>
-#include <private/qdeclarativevideooutput_p.h>
-#include <qmetadatareadercontrol.h>
-#include <qmediaavailabilitycontrol.h>
-
-#include "qdeclarativeplaylist_p.h"
-#include "qdeclarativemediametadata_p.h"
-
-#include <QAbstractVideoSurface>
-#include <QTimerEvent>
-#include <QtQml/qqmlengine.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype Audio
- \instantiates QDeclarativeAudio
- \brief Add audio playback to a scene.
-
- \inqmlmodule QtMultimedia
- \ingroup multimedia_qml
- \ingroup multimedia_audio_qml
-
- \qml
- Text {
- text: "Click Me!";
- font.pointSize: 24;
- width: 150; height: 50;
-
- Audio {
- id: playMusic
- source: "music.wav"
- }
- MouseArea {
- id: playArea
- anchors.fill: parent
- onPressed: { playMusic.play() }
- }
- }
- \endqml
-
- \sa Video
-*/
-
-void QDeclarativeAudio::_q_error(QMediaPlayer::Error errorCode)
-{
- m_error = errorCode;
- m_errorString = m_player->errorString();
-
- emit error(Error(errorCode), m_errorString);
- emit errorChanged();
-}
-
-void QDeclarativeAudio::_q_availabilityChanged(QMultimedia::AvailabilityStatus)
-{
- emit availabilityChanged(availability());
-}
-
-QDeclarativeAudio::QDeclarativeAudio(QObject *parent)
- : QObject(parent)
- , m_playlist(0)
- , m_autoPlay(false)
- , m_autoLoad(true)
- , m_loaded(false)
- , m_muted(false)
- , m_complete(false)
- , m_emitPlaylistChanged(false)
- , m_loopCount(1)
- , m_runningCount(0)
- , m_position(0)
- , m_vol(1.0)
- , m_playbackRate(1.0)
- , m_audioRole(UnknownRole)
- , m_playbackState(QMediaPlayer::StoppedState)
- , m_status(QMediaPlayer::NoMedia)
- , m_error(QMediaPlayer::ServiceMissingError)
- , m_player(0)
- , m_notifyInterval(1000)
-{
-}
-
-QDeclarativeAudio::~QDeclarativeAudio()
-{
- m_metaData.reset();
- delete m_player;
-}
-
-/*!
- \since 5.15
- \qmlproperty url QtMultimedia::MediaPlayer::videoOutput
-
- This property holds the target video output.
- Accepts one or an array of QAbstractVideoSurface or VideoOutput elements.
-
- \snippet multimedia-snippets/multiple-videooutputs.qml complete
-
- \sa QMediaPlayer::setVideoOutput()
-*/
-
-QVariant QDeclarativeAudio::videoOutput() const
-{
- return m_videoOutput;
-}
-
-void QDeclarativeAudio::setVideoOutput(const QVariant &v)
-{
- if (m_videoOutput == v)
- return;
-
- QAbstractVideoSurface *surface = nullptr;
- auto vo = v.value<QDeclarativeVideoOutput *>();
- if (vo)
- surface = vo->videoSurface();
- else
- surface = v.value<QAbstractVideoSurface *>();
-
- // If only one object has been passed.
- if (surface) {
- m_player->setVideoOutput(surface);
- } else {
- QList<QAbstractVideoSurface *> surfaces;
- // Check if it is an array.
- auto arr = v.value<QJSValue>();
- if (!arr.isNull()) {
- const int len = arr.property("length").toInt();
- for (int i = 0; i < len; ++i) {
- auto &&v = arr.property(i);
- if (v.isQObject()) {
- auto obj = v.toQObject();
- vo = qobject_cast<QDeclarativeVideoOutput *>(obj);
- surface = vo ? vo->videoSurface() : qobject_cast<QAbstractVideoSurface *>(obj);
- if (surface)
- surfaces.append(surface);
- }
- }
- }
-
- m_player->setVideoOutput(surfaces);
- }
-
- m_videoOutput = v;
- emit videoOutputChanged();
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::Audio::availability
-
- Returns the availability state of the media player.
-
- This is one of:
- \table
- \header \li Value \li Description
- \row \li Available
- \li The media player is available to use.
- \row \li Busy
- \li The media player is usually available, but some other
- process is utilizing the hardware necessary to play media.
- \row \li Unavailable
- \li There are no supported media playback facilities.
- \row \li ResourceMissing
- \li There is one or more resources missing, so the media player cannot
- be used. It may be possible to try again at a later time.
- \endtable
- */
-QDeclarativeAudio::Availability QDeclarativeAudio::availability() const
-{
- if (!m_player)
- return Unavailable;
- return Availability(m_player->availability());
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::Audio::audioRole
-
- This property holds the role of the audio stream. It can be set to specify the type of audio
- being played, allowing the system to make appropriate decisions when it comes to volume,
- routing or post-processing.
-
- The audio role must be set before setting the source property.
-
- Supported values can be retrieved with supportedAudioRoles().
-
- The value can be one of:
- \list
- \li UnknownRole - the role is unknown or undefined.
- \li MusicRole - music.
- \li VideoRole - soundtrack from a movie or a video.
- \li VoiceCommunicationRole - voice communications, such as telephony.
- \li AlarmRole - alarm.
- \li NotificationRole - notification, such as an incoming e-mail or a chat request.
- \li RingtoneRole - ringtone.
- \li AccessibilityRole - for accessibility, such as with a screen reader.
- \li SonificationRole - sonification, such as with user interface sounds.
- \li GameRole - game audio.
- \li CustomRole - The role is specified by customAudioRole.
- \endlist
-
- customAudioRole is cleared when this property is set to anything other than CustomRole.
-
- \since 5.6
-*/
-QDeclarativeAudio::AudioRole QDeclarativeAudio::audioRole() const
-{
- return !m_complete ? m_audioRole : AudioRole(m_player->audioRole());
-}
-
-void QDeclarativeAudio::setAudioRole(QDeclarativeAudio::AudioRole audioRole)
-{
- if (this->audioRole() == audioRole)
- return;
-
- if (m_complete) {
- m_player->setAudioRole(QAudio::Role(audioRole));
- } else {
- if (!m_customAudioRole.isEmpty()) {
- m_customAudioRole.clear();
- emit customAudioRoleChanged();
- }
- m_audioRole = audioRole;
- emit audioRoleChanged();
- }
-}
-
-/*!
- \qmlproperty string QtMultimedia::Audio::customAudioRole
-
- This property holds the role of the audio stream when the backend supports audio
- roles unknown to Qt. It can be set to specify the type of audio being played,
- allowing the system to make appropriate decisions when it comes to volume,
- routing or post-processing.
-
- The audio role must be set before setting the source property.
-
- audioRole is set to CustomRole when this property is set.
-
- \since 5.11
-*/
-QString QDeclarativeAudio::customAudioRole() const
-{
- return !m_complete ? m_customAudioRole : m_player->customAudioRole();
-}
-
-void QDeclarativeAudio::setCustomAudioRole(const QString &audioRole)
-{
- if (this->customAudioRole() == audioRole)
- return;
-
- if (m_complete) {
- m_player->setCustomAudioRole(audioRole);
- } else {
- setAudioRole(QDeclarativeAudio::CustomRole);
- m_customAudioRole = audioRole;
- emit customAudioRoleChanged();
- }
-}
-
-/*!
- \qmlproperty int QtMultimedia::Audio::notifyInterval
-
- The interval at which notifiable properties will update.
-
- The notifiable properties are \l position and \l bufferProgress.
-
- The interval is expressed in milliseconds, the default value is 1000.
-
- \since 5.9
-*/
-int QDeclarativeAudio::notifyInterval() const
-{
- return m_complete ? m_player->notifyInterval() : m_notifyInterval;
-}
-
-void QDeclarativeAudio::setNotifyInterval(int value)
-{
- if (notifyInterval() == value)
- return;
- if (m_complete) {
- m_player->setNotifyInterval(value);
- return;
- }
- m_notifyInterval = value;
- emit notifyIntervalChanged();
-}
-
-/*!
- \qmlmethod list<int> QtMultimedia::Audio::supportedAudioRoles()
-
- Returns a list of supported audio roles.
-
- If setting the audio role is not supported, an empty list is returned.
-
- \since 5.6
- \sa audioRole
-*/
-QJSValue QDeclarativeAudio::supportedAudioRoles() const
-{
- QJSEngine *engine = qmlEngine(this);
-
- if (!m_complete)
- return engine->newArray();
-
- QList<QAudio::Role> roles = m_player->supportedAudioRoles();
- int size = roles.size();
-
- QJSValue result = engine->newArray(size);
- for (int i = 0; i < size; ++i)
- result.setProperty(i, roles.at(i));
-
- return result;
-}
-
-QUrl QDeclarativeAudio::source() const
-{
- return m_source;
-}
-
-QDeclarativePlaylist *QDeclarativeAudio::playlist() const
-{
- return m_playlist;
-}
-
-void QDeclarativeAudio::setPlaylist(QDeclarativePlaylist *playlist)
-{
- if (playlist == m_playlist && m_source.isEmpty())
- return;
-
- if (!m_source.isEmpty()) {
- m_source.clear();
- emit sourceChanged();
- }
-
- m_playlist = playlist;
- m_content = m_playlist ?
- QMediaContent(m_playlist->mediaPlaylist(), QUrl(), false) : QMediaContent();
- m_loaded = false;
- if (m_complete && (m_autoLoad || m_content.isNull() || m_autoPlay)) {
- if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) {
- m_error = QMediaPlayer::NoError;
- m_errorString = QString();
-
- emit errorChanged();
- }
-
- if (!playlist)
- m_emitPlaylistChanged = true;
- m_player->setMedia(m_content, 0);
- m_loaded = true;
- }
- else
- emit playlistChanged();
-
- if (m_autoPlay)
- m_player->play();
-}
-
-bool QDeclarativeAudio::autoPlay() const
-{
- return m_autoPlay;
-}
-
-void QDeclarativeAudio::setAutoPlay(bool autoplay)
-{
- if (m_autoPlay == autoplay)
- return;
-
- m_autoPlay = autoplay;
- emit autoPlayChanged();
-}
-
-
-void QDeclarativeAudio::setSource(const QUrl &url)
-{
- if (url == m_source && m_playlist == NULL)
- return;
-
- if (m_playlist) {
- m_playlist = NULL;
- emit playlistChanged();
- }
-
- m_source = url;
- m_content = m_source.isEmpty() ? QMediaContent() : m_source;
- m_loaded = false;
- if (m_complete && (m_autoLoad || m_content.isNull() || m_autoPlay)) {
- if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) {
- m_error = QMediaPlayer::NoError;
- m_errorString = QString();
-
- emit errorChanged();
- }
-
- m_player->setMedia(m_content, 0);
- m_loaded = true;
- }
- else
- emit sourceChanged();
-
- if (m_autoPlay)
- m_player->play();
-}
-
-bool QDeclarativeAudio::isAutoLoad() const
-{
- return m_autoLoad;
-}
-
-void QDeclarativeAudio::setAutoLoad(bool autoLoad)
-{
- if (m_autoLoad == autoLoad)
- return;
-
- m_autoLoad = autoLoad;
- emit autoLoadChanged();
-}
-
-int QDeclarativeAudio::loopCount() const
-{
- return m_loopCount;
-}
-
-void QDeclarativeAudio::setLoopCount(int loopCount)
-{
- if (loopCount == 0)
- loopCount = 1;
- else if (loopCount < -1)
- loopCount = -1;
-
- if (m_loopCount == loopCount) {
- return;
- }
- m_loopCount = loopCount;
- m_runningCount = loopCount - 1;
- emit loopCountChanged();
-}
-
-void QDeclarativeAudio::setPlaybackState(QMediaPlayer::State playbackState)
-{
- if (m_playbackState == playbackState)
- return;
-
- if (m_complete) {
- switch (playbackState){
- case (QMediaPlayer::PlayingState):
- if (!m_loaded) {
- m_player->setMedia(m_content, 0);
- m_player->setPosition(m_position);
- m_loaded = true;
- }
- m_player->play();
- break;
-
- case (QMediaPlayer::PausedState):
- if (!m_loaded) {
- m_player->setMedia(m_content, 0);
- m_player->setPosition(m_position);
- m_loaded = true;
- }
- m_player->pause();
- break;
-
- case (QMediaPlayer::StoppedState):
- m_player->stop();
- }
- }
-}
-
-int QDeclarativeAudio::duration() const
-{
- return !m_complete ? 0 : m_player->duration();
-}
-
-int QDeclarativeAudio::position() const
-{
- return !m_complete ? m_position : m_player->position();
-}
-
-qreal QDeclarativeAudio::volume() const
-{
- return !m_complete ? m_vol : qreal(m_player->volume()) / 100;
-}
-
-void QDeclarativeAudio::setVolume(qreal volume)
-{
- if (volume < 0 || volume > 1) {
- qmlWarning(this) << tr("volume should be between 0.0 and 1.0");
- return;
- }
-
- if (this->volume() == volume)
- return;
-
- if (m_complete) {
- m_player->setVolume(qRound(volume * 100));
- } else {
- m_vol = volume;
- emit volumeChanged();
- }
-}
-
-bool QDeclarativeAudio::isMuted() const
-{
- return !m_complete ? m_muted : m_player->isMuted();
-}
-
-void QDeclarativeAudio::setMuted(bool muted)
-{
- if (isMuted() == muted)
- return;
-
- if (m_complete) {
- m_player->setMuted(muted);
- } else {
- m_muted = muted;
- emit mutedChanged();
- }
-}
-
-qreal QDeclarativeAudio::bufferProgress() const
-{
- return !m_complete ? 0 : qreal(m_player->bufferStatus()) / 100;
-}
-
-bool QDeclarativeAudio::isSeekable() const
-{
- return !m_complete ? false : m_player->isSeekable();
-}
-
-qreal QDeclarativeAudio::playbackRate() const
-{
- return m_complete ? m_player->playbackRate() : m_playbackRate;
-}
-
-void QDeclarativeAudio::setPlaybackRate(qreal rate)
-{
- if (playbackRate() == rate)
- return;
-
- if (m_complete) {
- m_player->setPlaybackRate(rate);
- } else {
- m_playbackRate = rate;
- emit playbackRateChanged();
- }
-}
-
-QString QDeclarativeAudio::errorString() const
-{
- return m_errorString;
-}
-
-QDeclarativeMediaMetaData *QDeclarativeAudio::metaData() const
-{
- return m_metaData.data();
-}
-
-
-/*!
- \qmlmethod QtMultimedia::Audio::play()
-
- Starts playback of the media.
-
- Sets the \l playbackState property to PlayingState.
-*/
-
-void QDeclarativeAudio::play()
-{
- if (!m_complete)
- return;
-
- setPlaybackState(QMediaPlayer::PlayingState);
-}
-
-/*!
- \qmlmethod QtMultimedia::Audio::pause()
-
- Pauses playback of the media.
-
- Sets the \l playbackState property to PausedState.
-*/
-
-void QDeclarativeAudio::pause()
-{
- if (!m_complete)
- return;
-
- setPlaybackState(QMediaPlayer::PausedState);
-}
-
-/*!
- \qmlmethod QtMultimedia::Audio::stop()
-
- Stops playback of the media.
-
- Sets the \l playbackState property to StoppedState.
-*/
-
-void QDeclarativeAudio::stop()
-{
- if (!m_complete)
- return;
-
- setPlaybackState(QMediaPlayer::StoppedState);
-}
-
-/*!
- \qmlmethod QtMultimedia::Audio::seek(offset)
-
- If the \l seekable property is true, seeks the current
- playback position to \a offset.
-
- Seeking may be asynchronous, so the \l position property
- may not be updated immediately.
-
- \sa seekable, position
-*/
-void QDeclarativeAudio::seek(int position)
-{
- // QMediaPlayer clamps this to positive numbers
- if (position < 0)
- position = 0;
-
- if (this->position() == position)
- return;
-
- if (m_complete) {
- m_player->setPosition(position);
- } else {
- m_position = position;
- emit positionChanged();
- }
-}
-
-/*!
- \qmlproperty url QtMultimedia::Audio::source
-
- This property holds the source URL of the media.
-
- Setting the \l source property clears the current \l playlist, if any.
-*/
-
-/*!
- \qmlproperty Playlist QtMultimedia::Audio::playlist
-
- This property holds the playlist used by the media player.
-
- Setting the \l playlist property resets the \l source to an empty string.
-
- \since 5.6
-*/
-
-/*!
- \qmlproperty int QtMultimedia::Audio::loops
-
- This property holds the number of times the media is played. A value of \c 0 or \c 1 means
- the media will be played only once; set to \c Audio.Infinite to enable infinite looping.
-
- The value can be changed while the media is playing, in which case it will update
- the remaining loops to the new value.
-
- The default is \c 1.
-*/
-
-/*!
- \qmlproperty bool QtMultimedia::Audio::autoLoad
-
- This property indicates if loading of media should begin immediately.
-
- Defaults to \c true. If \c false, the media will not be loaded until playback is started.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Audio::playbackStateChanged()
-
- This signal is emitted when the \l playbackState property is altered.
-
- The corresponding handler is \c onPlaybackStateChanged.
-*/
-
-
-/*!
- \qmlsignal QtMultimedia::Audio::paused()
-
- This signal is emitted when playback is paused.
-
- The corresponding handler is \c onPaused.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Audio::stopped()
-
- This signal is emitted when playback is stopped.
-
- The corresponding handler is \c onStopped.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Audio::playing()
-
- This signal is emitted when playback is started or resumed.
-
- The corresponding handler is \c onPlaying.
-*/
-
-/*!
- \qmlproperty enumeration QtMultimedia::Audio::status
-
- This property holds the status of media loading. It can be one of:
-
- \list
- \li NoMedia - no media has been set.
- \li Loading - the media is currently being loaded.
- \li Loaded - the media has been loaded.
- \li Buffering - the media is buffering data.
- \li Stalled - playback has been interrupted while the media is buffering data.
- \li Buffered - the media has buffered data.
- \li EndOfMedia - the media has played to the end.
- \li InvalidMedia - the media cannot be played.
- \li UnknownStatus - the status of the media is unknown.
- \endlist
-*/
-
-QDeclarativeAudio::Status QDeclarativeAudio::status() const
-{
- return Status(m_status);
-}
-
-
-/*!
- \qmlproperty enumeration QtMultimedia::Audio::playbackState
-
- This property holds the state of media playback. It can be one of:
-
- \list
- \li PlayingState - the media is currently playing.
- \li PausedState - playback of the media has been suspended.
- \li StoppedState - playback of the media is yet to begin.
- \endlist
-*/
-
-QDeclarativeAudio::PlaybackState QDeclarativeAudio::playbackState() const
-{
- return PlaybackState(m_playbackState);
-}
-
-/*!
- \qmlproperty bool QtMultimedia::Audio::autoPlay
-
- This property controls whether the media will begin to play on start up.
-
- Defaults to \c false. If set to \c true, the value of autoLoad will be overwritten to \c true.
-*/
-
-/*!
- \qmlproperty int QtMultimedia::Audio::duration
-
- This property holds the duration of the media in milliseconds.
-
- If the media doesn't have a fixed duration (a live stream for example) this will be 0.
-*/
-
-/*!
- \qmlproperty int QtMultimedia::Audio::position
-
- This property holds the current playback position in milliseconds.
-
- To change this position, use the \l seek() method.
-
- \sa seek()
-*/
-
-/*!
- \qmlproperty real QtMultimedia::Audio::volume
-
- This property holds the audio volume.
-
- The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this
- range will be clamped.
-
- The default volume is \c 1.0.
-
- UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale
- will produce linear changes in perceived loudness, which is what a user would normally expect
- from a volume control. See \l {QtMultimedia::QtMultimedia::convertVolume()}{QtMultimedia.convertVolume()}
- for more details.
-*/
-
-/*!
- \qmlproperty bool QtMultimedia::Audio::muted
-
- This property holds whether the audio output is muted.
-
- Defaults to false.
-*/
-
-/*!
- \qmlproperty bool QtMultimedia::Audio::hasAudio
-
- This property holds whether the media contains audio.
-*/
-
-bool QDeclarativeAudio::hasAudio() const
-{
- return !m_complete ? false : m_player->isAudioAvailable();
-}
-
-/*!
- \qmlproperty bool QtMultimedia::Audio::hasVideo
-
- This property holds whether the media contains video.
-*/
-
-bool QDeclarativeAudio::hasVideo() const
-{
- return !m_complete ? false : m_player->isVideoAvailable();
-}
-
-/*!
- \qmlproperty real QtMultimedia::Audio::bufferProgress
-
- This property holds how much of the data buffer is currently filled, from \c 0.0 (empty) to
- \c 1.0 (full).
-
- Playback can start or resume only when the buffer is entirely filled, in which case the
- status is \c Audio.Buffered or \c Audio.Buffering. A value lower than \c 1.0 implies that
- the status is \c Audio.Stalled.
-
- \sa status
-*/
-
-/*!
- \qmlproperty bool QtMultimedia::Audio::seekable
-
- This property holds whether position of the audio can be changed.
-
- If true, calling the \l seek() method will cause playback to seek to the new position.
-*/
-
-/*!
- \qmlproperty real QtMultimedia::Audio::playbackRate
-
- This property holds the rate at which audio is played at as a multiple of the normal rate.
-
- Defaults to 1.0.
-*/
-
-/*!
- \qmlproperty enumeration QtMultimedia::Audio::error
-
- This property holds the error state of the audio. It can be one of:
-
- \table
- \header \li Value \li Description
- \row \li NoError
- \li There is no current error.
- \row \li ResourceError
- \li The audio cannot be played due to a problem allocating resources.
- \row \li FormatError
- \li The audio format is not supported.
- \row \li NetworkError
- \li The audio cannot be played due to network issues.
- \row \li AccessDenied
- \li The audio cannot be played due to insufficient permissions.
- \row \li ServiceMissing
- \li The audio cannot be played because the media service could not be
- instantiated.
- \endtable
-*/
-
-QDeclarativeAudio::Error QDeclarativeAudio::error() const
-{
- return Error(m_error);
-}
-
-void QDeclarativeAudio::classBegin()
-{
- m_player = new QMediaPlayer(this);
-
- connect(m_player, SIGNAL(stateChanged(QMediaPlayer::State)),
- this, SLOT(_q_statusChanged()));
- connect(m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
- this, SLOT(_q_statusChanged()));
- connect(m_player, SIGNAL(mediaChanged(const QMediaContent&)),
- this, SLOT(_q_mediaChanged(const QMediaContent&)));
- connect(m_player, SIGNAL(durationChanged(qint64)),
- this, SIGNAL(durationChanged()));
- connect(m_player, SIGNAL(positionChanged(qint64)),
- this, SIGNAL(positionChanged()));
- connect(m_player, SIGNAL(volumeChanged(int)),
- this, SIGNAL(volumeChanged()));
- connect(m_player, SIGNAL(mutedChanged(bool)),
- this, SIGNAL(mutedChanged()));
- connect(m_player, SIGNAL(bufferStatusChanged(int)),
- this, SIGNAL(bufferProgressChanged()));
- connect(m_player, SIGNAL(seekableChanged(bool)),
- this, SIGNAL(seekableChanged()));
- connect(m_player, SIGNAL(playbackRateChanged(qreal)),
- this, SIGNAL(playbackRateChanged()));
- connect(m_player, SIGNAL(error(QMediaPlayer::Error)),
- this, SLOT(_q_error(QMediaPlayer::Error)));
- connect(m_player, SIGNAL(audioAvailableChanged(bool)),
- this, SIGNAL(hasAudioChanged()));
- connect(m_player, SIGNAL(videoAvailableChanged(bool)),
- this, SIGNAL(hasVideoChanged()));
- connect(m_player, SIGNAL(audioRoleChanged(QAudio::Role)),
- this, SIGNAL(audioRoleChanged()));
- connect(m_player, SIGNAL(customAudioRoleChanged(const QString &)),
- this, SIGNAL(customAudioRoleChanged()));
- connect(m_player, SIGNAL(notifyIntervalChanged(int)),
- this, SIGNAL(notifyIntervalChanged()));
-
- m_error = m_player->availability() == QMultimedia::ServiceMissing ? QMediaPlayer::ServiceMissingError : QMediaPlayer::NoError;
-
- connect(m_player, SIGNAL(availabilityChanged(QMultimedia::AvailabilityStatus)),
- this, SLOT(_q_availabilityChanged(QMultimedia::AvailabilityStatus)));
-
- m_metaData.reset(new QDeclarativeMediaMetaData(m_player));
-
- connect(m_player, SIGNAL(metaDataChanged()),
- m_metaData.data(), SIGNAL(metaDataChanged()));
-
- emit mediaObjectChanged();
-}
-
-void QDeclarativeAudio::componentComplete()
-{
- if (!qFuzzyCompare(m_vol, qreal(1.0)))
- m_player->setVolume(m_vol * 100);
- if (m_muted)
- m_player->setMuted(m_muted);
- if (!qFuzzyCompare(m_playbackRate, qreal(1.0)))
- m_player->setPlaybackRate(m_playbackRate);
- if (m_audioRole != UnknownRole)
- m_player->setAudioRole(QAudio::Role(m_audioRole));
- if (!m_customAudioRole.isEmpty())
- m_player->setCustomAudioRole(m_customAudioRole);
- if (m_notifyInterval != m_player->notifyInterval())
- m_player->setNotifyInterval(m_notifyInterval);
-
- if (!m_content.isNull() && (m_autoLoad || m_autoPlay)) {
- m_player->setMedia(m_content, 0);
- m_loaded = true;
- if (m_position > 0)
- m_player->setPosition(m_position);
- }
-
- m_complete = true;
-
- if (m_autoPlay) {
- if (m_content.isNull()) {
- m_player->stop();
- } else {
- m_player->play();
- }
- }
-}
-
-void QDeclarativeAudio::_q_statusChanged()
-{
- if (m_player->mediaStatus() == QMediaPlayer::EndOfMedia && m_runningCount != 0) {
- m_runningCount = std::max(m_runningCount - 1, -2);
- m_player->play();
- }
- const QMediaPlayer::MediaStatus oldStatus = m_status;
- const QMediaPlayer::State lastPlaybackState = m_playbackState;
-
- const QMediaPlayer::State state = m_player->state();
-
- m_playbackState = state;
-
- m_status = m_player->mediaStatus();
-
- if (m_status != oldStatus)
- emit statusChanged();
-
- if (lastPlaybackState != state) {
-
- if (lastPlaybackState == QMediaPlayer::StoppedState)
- m_runningCount = m_loopCount - 1;
-
- switch (state) {
- case QMediaPlayer::StoppedState:
- emit stopped();
- break;
- case QMediaPlayer::PausedState:
- emit paused();
- break;
- case QMediaPlayer::PlayingState:
- emit playing();
- break;
- }
-
- emit playbackStateChanged();
- }
-}
-
-void QDeclarativeAudio::_q_mediaChanged(const QMediaContent &media)
-{
- if (!media.playlist() && !m_emitPlaylistChanged) {
- emit sourceChanged();
- } else {
- m_emitPlaylistChanged = false;
- emit playlistChanged();
- }
-}
-
-/*!
- \qmlproperty string QtMultimedia::Audio::errorString
-
- This property holds a string describing the current error condition in more detail.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Audio::error(error, errorString)
-
- This signal is emitted when an \a error has
- occurred. The \a errorString parameter may contain more detailed
- information about the error.
-
- The corresponding handler is \c onError.
-
- \sa QMediaPlayer::Error
-*/
-
-/*!
- \qmlproperty variant QtMultimedia::Audio::mediaObject
-
- This property holds the native media object.
-
- It can be used to get a pointer to a QMediaPlayer object in order to integrate with C++ code.
-
- \code
- QObject *qmlAudio; // The QML Audio object
- QMediaPlayer *player = qvariant_cast<QMediaPlayer *>(qmlAudio->property("mediaObject"));
- \endcode
-
- \note This property is not accessible from QML.
-*/
-
-/*!
- \qmlpropertygroup QtMultimedia::Audio::metaData
- \qmlproperty variant QtMultimedia::Audio::metaData.title
- \qmlproperty variant QtMultimedia::Audio::metaData.subTitle
- \qmlproperty variant QtMultimedia::Audio::metaData.author
- \qmlproperty variant QtMultimedia::Audio::metaData.comment
- \qmlproperty variant QtMultimedia::Audio::metaData.description
- \qmlproperty variant QtMultimedia::Audio::metaData.category
- \qmlproperty variant QtMultimedia::Audio::metaData.genre
- \qmlproperty variant QtMultimedia::Audio::metaData.year
- \qmlproperty variant QtMultimedia::Audio::metaData.date
- \qmlproperty variant QtMultimedia::Audio::metaData.userRating
- \qmlproperty variant QtMultimedia::Audio::metaData.keywords
- \qmlproperty variant QtMultimedia::Audio::metaData.language
- \qmlproperty variant QtMultimedia::Audio::metaData.publisher
- \qmlproperty variant QtMultimedia::Audio::metaData.copyright
- \qmlproperty variant QtMultimedia::Audio::metaData.parentalRating
- \qmlproperty variant QtMultimedia::Audio::metaData.ratingOrganization
- \qmlproperty variant QtMultimedia::Audio::metaData.size
- \qmlproperty variant QtMultimedia::Audio::metaData.mediaType
- \qmlproperty variant QtMultimedia::Audio::metaData.audioBitRate
- \qmlproperty variant QtMultimedia::Audio::metaData.audioCodec
- \qmlproperty variant QtMultimedia::Audio::metaData.averageLevel
- \qmlproperty variant QtMultimedia::Audio::metaData.channelCount
- \qmlproperty variant QtMultimedia::Audio::metaData.peakValue
- \qmlproperty variant QtMultimedia::Audio::metaData.sampleRate
- \qmlproperty variant QtMultimedia::Audio::metaData.albumTitle
- \qmlproperty variant QtMultimedia::Audio::metaData.albumArtist
- \qmlproperty variant QtMultimedia::Audio::metaData.contributingArtist
- \qmlproperty variant QtMultimedia::Audio::metaData.composer
- \qmlproperty variant QtMultimedia::Audio::metaData.conductor
- \qmlproperty variant QtMultimedia::Audio::metaData.lyrics
- \qmlproperty variant QtMultimedia::Audio::metaData.mood
- \qmlproperty variant QtMultimedia::Audio::metaData.trackNumber
- \qmlproperty variant QtMultimedia::Audio::metaData.trackCount
- \qmlproperty variant QtMultimedia::Audio::metaData.coverArtUrlSmall
- \qmlproperty variant QtMultimedia::Audio::metaData.coverArtUrlLarge
- \qmlproperty variant QtMultimedia::Audio::metaData.resolution
- \qmlproperty variant QtMultimedia::Audio::metaData.pixelAspectRatio
- \qmlproperty variant QtMultimedia::Audio::metaData.videoFrameRate
- \qmlproperty variant QtMultimedia::Audio::metaData.videoBitRate
- \qmlproperty variant QtMultimedia::Audio::metaData.videoCodec
- \qmlproperty variant QtMultimedia::Audio::metaData.posterUrl
- \qmlproperty variant QtMultimedia::Audio::metaData.chapterNumber
- \qmlproperty variant QtMultimedia::Audio::metaData.director
- \qmlproperty variant QtMultimedia::Audio::metaData.leadPerformer
- \qmlproperty variant QtMultimedia::Audio::metaData.writer
-
- These properties hold the meta data for the current media.
-
- \list
- \li \c metaData.title - the title of the media.
- \li \c metaData.subTitle - the sub-title of the media.
- \li \c metaData.author - the author of the media.
- \li \c metaData.comment - a user comment about the media.
- \li \c metaData.description - a description of the media.
- \li \c metaData.category - the category of the media.
- \li \c metaData.genre - the genre of the media.
- \li \c metaData.year - the year of release of the media.
- \li \c metaData.date - the date of the media.
- \li \c metaData.userRating - a user rating of the media in the range of 0 to 100.
- \li \c metaData.keywords - a list of keywords describing the media.
- \li \c metaData.language - the language of the media, as an ISO 639-2 code.
- \li \c metaData.publisher - the publisher of the media.
- \li \c metaData.copyright - the media's copyright notice.
- \li \c metaData.parentalRating - the parental rating of the media.
- \li \c metaData.ratingOrganization - the name of the rating organization responsible for the
- parental rating of the media.
- \li \c metaData.size - the size of the media in bytes.
- \li \c metaData.mediaType - the type of the media.
- \li \c metaData.audioBitRate - the bit rate of the media's audio stream in bits per second.
- \li \c metaData.audioCodec - the encoding of the media audio stream.
- \li \c metaData.averageLevel - the average volume level of the media.
- \li \c metaData.channelCount - the number of channels in the media's audio stream.
- \li \c metaData.peakValue - the peak volume of media's audio stream.
- \li \c metaData.sampleRate - the sample rate of the media's audio stream in hertz.
- \li \c metaData.albumTitle - the title of the album the media belongs to.
- \li \c metaData.albumArtist - the name of the principal artist of the album the media
- belongs to.
- \li \c metaData.contributingArtist - the names of artists contributing to the media.
- \li \c metaData.composer - the composer of the media.
- \li \c metaData.conductor - the conductor of the media.
- \li \c metaData.lyrics - the lyrics to the media.
- \li \c metaData.mood - the mood of the media.
- \li \c metaData.trackNumber - the track number of the media.
- \li \c metaData.trackCount - the number of tracks on the album containing the media.
- \li \c metaData.coverArtUrlSmall - the URL of a small cover art image.
- \li \c metaData.coverArtUrlLarge - the URL of a large cover art image.
- \li \c metaData.resolution - the dimension of an image or video.
- \li \c metaData.pixelAspectRatio - the pixel aspect ratio of an image or video.
- \li \c metaData.videoFrameRate - the frame rate of the media's video stream.
- \li \c metaData.videoBitRate - the bit rate of the media's video stream in bits per second.
- \li \c metaData.videoCodec - the encoding of the media's video stream.
- \li \c metaData.posterUrl - the URL of a poster image.
- \li \c metaData.chapterNumber - the chapter number of the media.
- \li \c metaData.director - the director of the media.
- \li \c metaData.leadPerformer - the lead performer in the media.
- \li \c metaData.writer - the writer of the media.
- \endlist
-
- \sa {QMediaMetaData}
-*/
-
-
-///////////// MediaPlayer Docs /////////////
-
-/*!
- \qmltype MediaPlayer
- \instantiates QDeclarativeAudio
- \brief Add media playback to a scene.
-
- \inqmlmodule QtMultimedia
- \ingroup multimedia_qml
- \ingroup multimedia_audio_qml
- \ingroup multimedia_video_qml
-
- \qml
- Text {
- text: "Click Me!";
- font.pointSize: 24;
- width: 150; height: 50;
-
- MediaPlayer {
- id: playMusic
- source: "music.wav"
- }
- MouseArea {
- id: playArea
- anchors.fill: parent
- onPressed: { playMusic.play() }
- }
- }
- \endqml
-
- You can use MediaPlayer by itself to play audio content (like \l Audio),
- or you can use it in conjunction with a \l VideoOutput for rendering video.
-
- \qml
- Item {
- MediaPlayer {
- id: mediaplayer
- source: "groovy_video.mp4"
- }
-
- VideoOutput {
- anchors.fill: parent
- source: mediaplayer
- }
-
- MouseArea {
- id: playArea
- anchors.fill: parent
- onPressed: mediaplayer.play();
- }
- }
- \endqml
-
- \sa VideoOutput
-*/
-
-/*!
- \qmlproperty enumeration QtMultimedia::MediaPlayer::availability
-
- Returns the availability state of the media player.
-
- This is one of:
- \table
- \header \li Value \li Description
- \row \li Available
- \li The media player is available to use.
- \row \li Busy
- \li The media player is usually available, but some other
- process is utilizing the hardware necessary to play media.
- \row \li Unavailable
- \li There are no supported media playback facilities.
- \row \li ResourceMissing
- \li There is one or more resources missing, so the media player cannot
- be used. It may be possible to try again at a later time.
- \endtable
- */
-
-/*!
- \qmlproperty enumeration QtMultimedia::MediaPlayer::audioRole
-
- This property holds the role of the audio stream. It can be set to specify the type of audio
- being played, allowing the system to make appropriate decisions when it comes to volume,
- routing or post-processing.
-
- The audio role must be set before setting the source property.
-
- Supported values can be retrieved with supportedAudioRoles().
-
- The value can be one of:
- \list
- \li UnknownRole - the role is unknown or undefined.
- \li MusicRole - music.
- \li VideoRole - soundtrack from a movie or a video.
- \li VoiceCommunicationRole - voice communications, such as telephony.
- \li AlarmRole - alarm.
- \li NotificationRole - notification, such as an incoming e-mail or a chat request.
- \li RingtoneRole - ringtone.
- \li AccessibilityRole - for accessibility, such as with a screen reader.
- \li SonificationRole - sonification, such as with user interface sounds.
- \li GameRole - game audio.
- \li CustomRole - The role is specified by customAudioRole.
- \endlist
-
- customAudioRole is cleared when this property is set to anything other than CustomRole.
-
- \since 5.6
-*/
-
-/*!
- \qmlproperty string QtMultimedia::MediaPlayer::customAudioRole
-
- This property holds the role of the audio stream when the backend supports audio
- roles unknown to Qt. It can be set to specify the type of audio being played,
- allowing the system to make appropriate decisions when it comes to volume,
- routing or post-processing.
-
- The audio role must be set before setting the source property.
-
- audioRole is set to CustomRole when this property is set.
-
- \since 5.11
-*/
-
-/*!
- \qmlmethod list<int> QtMultimedia::MediaPlayer::supportedAudioRoles()
-
- Returns a list of supported audio roles.
-
- If setting the audio role is not supported, an empty list is returned.
-
- \since 5.6
- \sa audioRole
-*/
-
-/*!
- \qmlproperty int QtMultimedia::MediaPlayer::notifyInterval
-
- The interval at which notifiable properties will update.
-
- The notifiable properties are \l position and \l bufferProgress.
-
- The interval is expressed in milliseconds, the default value is 1000.
-
- \since 5.9
-*/
-
-/*!
- \qmlmethod QtMultimedia::MediaPlayer::play()
-
- Starts playback of the media.
-
- Sets the \l playbackState property to PlayingState.
-*/
-
-/*!
- \qmlmethod QtMultimedia::MediaPlayer::pause()
-
- Pauses playback of the media.
-
- Sets the \l playbackState property to PausedState.
-*/
-
-/*!
- \qmlmethod QtMultimedia::MediaPlayer::stop()
-
- Stops playback of the media.
-
- Sets the \l playbackState property to StoppedState.
-*/
-
-/*!
- \qmlproperty url QtMultimedia::MediaPlayer::source
-
- This property holds the source URL of the media.
-
- Setting the \l source property clears the current \l playlist, if any.
-
- Since Qt 5.12.2, the url scheme \c gst-pipeline provides custom pipelines
- for the GStreamer backend.
-
- If the pipeline contains a \c qtvideosink element,
- the current VideoOutput will be used for rendering video.
-
- \snippet multimedia-snippets/qtvideosink.qml complete
-
- \sa QMediaPlayer::setMedia()
-*/
-
-/*!
- \qmlproperty Playlist QtMultimedia::MediaPlayer::playlist
-
- This property holds the playlist used by the media player.
-
- Setting the \l playlist property resets the \l source to an empty string.
-
- \since 5.6
-*/
-
-/*!
- \qmlproperty int QtMultimedia::MediaPlayer::loops
-
- This property holds the number of times the media is played. A value of \c 0 or \c 1 means
- the media will be played only once; set to \c MediaPlayer.Infinite to enable infinite looping.
-
- The value can be changed while the media is playing, in which case it will update
- the remaining loops to the new value.
-
- The default is \c 1.
-*/
-
-/*!
- \qmlproperty bool QtMultimedia::MediaPlayer::autoLoad
-
- This property indicates if loading of media should begin immediately.
-
- Defaults to true, if false media will not be loaded until playback is started.
-*/
-
-/*!
- \qmlsignal QtMultimedia::MediaPlayer::playbackStateChanged()
-
- This signal is emitted when the \l playbackState property is altered.
-
- The corresponding handler is \c onPlaybackStateChanged.
-*/
-
-
-/*!
- \qmlsignal QtMultimedia::MediaPlayer::paused()
-
- This signal is emitted when playback is paused.
-
- The corresponding handler is \c onPaused.
-*/
-
-/*!
- \qmlsignal QtMultimedia::MediaPlayer::stopped()
-
- This signal is emitted when playback is stopped.
-
- The corresponding handler is \c onStopped.
-*/
-
-/*!
- \qmlsignal QtMultimedia::MediaPlayer::playing()
-
- This signal is emitted when playback is started or resumed.
-
- The corresponding handler is \c onPlaying.
-*/
-
-/*!
- \qmlproperty enumeration QtMultimedia::MediaPlayer::status
-
- This property holds the status of media loading. It can be one of:
-
- \list
- \li NoMedia - no media has been set.
- \li Loading - the media is currently being loaded.
- \li Loaded - the media has been loaded.
- \li Buffering - the media is buffering data.
- \li Stalled - playback has been interrupted while the media is buffering data.
- \li Buffered - the media has buffered data.
- \li EndOfMedia - the media has played to the end.
- \li InvalidMedia - the media cannot be played.
- \li UnknownStatus - the status of the media is unknown.
- \endlist
-*/
-
-/*!
- \qmlproperty enumeration QtMultimedia::MediaPlayer::playbackState
-
- This property holds the state of media playback. It can be one of:
-
- \list
- \li PlayingState - the media is currently playing.
- \li PausedState - playback of the media has been suspended.
- \li StoppedState - playback of the media is yet to begin.
- \endlist
-*/
-
-/*!
- \qmlproperty bool QtMultimedia::MediaPlayer::autoPlay
-
- This property controls whether the media will begin to play on start up.
-
- Defaults to \c false. If set to \c true, the value of autoLoad will be overwritten to \c true.
-*/
-
-/*!
- \qmlproperty int QtMultimedia::MediaPlayer::duration
-
- This property holds the duration of the media in milliseconds.
-
- If the media doesn't have a fixed duration (a live stream for example) this will be 0.
-*/
-
-/*!
- \qmlproperty int QtMultimedia::MediaPlayer::position
-
- This property holds the current playback position in milliseconds.
-
- To change this position, use the \l seek() method.
-
- \sa seek()
-*/
-
-/*!
- \qmlproperty real QtMultimedia::MediaPlayer::volume
-
- This property holds the audio volume of the media player.
-
- The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this
- range will be clamped.
-
- The default volume is \c 1.0.
-
- UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale
- will produce linear changes in perceived loudness, which is what a user would normally expect
- from a volume control. See \l {QtMultimedia::QtMultimedia::convertVolume()}{QtMultimedia.convertVolume()}
- for more details.
-*/
-
-/*!
- \qmlproperty bool QtMultimedia::MediaPlayer::muted
-
- This property holds whether the audio output is muted.
-
- Defaults to false.
-*/
-
-/*!
- \qmlproperty bool QtMultimedia::MediaPlayer::hasAudio
-
- This property holds whether the media contains audio.
-*/
-
-/*!
- \qmlproperty bool QtMultimedia::MediaPlayer::hasVideo
-
- This property holds whether the media contains video.
-*/
-
-/*!
- \qmlproperty real QtMultimedia::MediaPlayer::bufferProgress
-
- This property holds how much of the data buffer is currently filled, from \c 0.0 (empty) to
- \c 1.0 (full).
-
- Playback can start or resume only when the buffer is entirely filled, in which case the
- status is \c MediaPlayer.Buffered or \c MediaPlayer.Buffering. A value lower than \c 1.0
- implies that the status is \c MediaPlayer.Stalled.
-
- \sa status
-*/
-
-/*!
- \qmlproperty bool QtMultimedia::MediaPlayer::seekable
-
- This property holds whether position of the audio can be changed.
-
- If true, calling the \l seek() method will cause playback to seek to the new position.
-*/
-
-/*!
- \qmlmethod QtMultimedia::MediaPlayer::seek(offset)
-
- If the \l seekable property is true, seeks the current
- playback position to \a offset.
-
- Seeking may be asynchronous, so the \l position property
- may not be updated immediately.
-
- \sa seekable, position
-*/
-
-/*!
- \qmlproperty real QtMultimedia::MediaPlayer::playbackRate
-
- This property holds the rate at which audio is played at as a multiple of the normal rate.
-
- Defaults to 1.0.
-*/
-
-/*!
- \qmlproperty enumeration QtMultimedia::MediaPlayer::error
-
- This property holds the error state of the audio. It can be one of:
-
- \table
- \header \li Value \li Description
- \row \li NoError
- \li There is no current error.
- \row \li ResourceError
- \li The audio cannot be played due to a problem allocating resources.
- \row \li FormatError
- \li The audio format is not supported.
- \row \li NetworkError
- \li The audio cannot be played due to network issues.
- \row \li AccessDenied
- \li The audio cannot be played due to insufficient permissions.
- \row \li ServiceMissing
- \li The audio cannot be played because the media service could not be
- instantiated.
- \endtable
-*/
-
-/*!
- \qmlproperty string QtMultimedia::MediaPlayer::errorString
-
- This property holds a string describing the current error condition in more detail.
-*/
-
-/*!
- \qmlsignal QtMultimedia::MediaPlayer::error(error, errorString)
-
- This signal is emitted when an \a error has
- occurred. The \a errorString parameter may contain more detailed
- information about the error.
-
- The corresponding handler is \c onError.
-
- \sa QMediaPlayer::Error
-*/
-
-/*!
- \qmlproperty variant QtMultimedia::MediaPlayer::mediaObject
-
- This property holds the native media object.
-
- It can be used to get a pointer to a QMediaPlayer object in order to integrate with C++ code.
-
- \code
- QObject *qmlMediaPlayer; // The QML MediaPlayer object
- QMediaPlayer *player = qvariant_cast<QMediaPlayer *>(qmlMediaPlayer->property("mediaObject"));
- \endcode
-
- \note This property is not accessible from QML.
-*/
-
-/*!
- \qmlpropertygroup QtMultimedia::MediaPlayer::metaData
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.title
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.subTitle
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.author
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.comment
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.description
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.category
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.genre
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.year
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.date
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.userRating
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.keywords
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.language
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.publisher
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.copyright
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.parentalRating
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.ratingOrganization
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.size
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.mediaType
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.audioBitRate
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.audioCodec
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.averageLevel
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.channelCount
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.peakValue
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.sampleRate
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.albumTitle
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.albumArtist
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.contributingArtist
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.composer
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.conductor
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.lyrics
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.mood
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.trackNumber
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.trackCount
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.coverArtUrlSmall
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.coverArtUrlLarge
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.resolution
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.pixelAspectRatio
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.videoFrameRate
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.videoBitRate
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.videoCodec
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.posterUrl
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.chapterNumber
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.director
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.leadPerformer
- \qmlproperty variant QtMultimedia::MediaPlayer::metaData.writer
-
- These properties hold the meta data for the current media.
-
- \list
- \li \c metaData.title - the title of the media.
- \li \c metaData.subTitle - the sub-title of the media.
- \li \c metaData.author - the author of the media.
- \li \c metaData.comment - a user comment about the media.
- \li \c metaData.description - a description of the media.
- \li \c metaData.category - the category of the media.
- \li \c metaData.genre - the genre of the media.
- \li \c metaData.year - the year of release of the media.
- \li \c metaData.date - the date of the media.
- \li \c metaData.userRating - a user rating of the media in the range of 0 to 100.
- \li \c metaData.keywords - a list of keywords describing the media.
- \li \c metaData.language - the language of the media, as an ISO 639-2 code.
- \li \c metaData.publisher - the publisher of the media.
- \li \c metaData.copyright - the media's copyright notice.
- \li \c metaData.parentalRating - the parental rating of the media.
- \li \c metaData.ratingOrganization - the name of the rating organization responsible for the
- parental rating of the media.
- \li \c metaData.size - the size of the media in bytes.
- \li \c metaData.mediaType - the type of the media.
- \li \c metaData.audioBitRate - the bit rate of the media's audio stream in bits per second.
- \li \c metaData.audioCodec - the encoding of the media audio stream.
- \li \c metaData.averageLevel - the average volume level of the media.
- \li \c metaData.channelCount - the number of channels in the media's audio stream.
- \li \c metaData.peakValue - the peak volume of media's audio stream.
- \li \c metaData.sampleRate - the sample rate of the media's audio stream in hertz.
- \li \c metaData.albumTitle - the title of the album the media belongs to.
- \li \c metaData.albumArtist - the name of the principal artist of the album the media
- belongs to.
- \li \c metaData.contributingArtist - the names of artists contributing to the media.
- \li \c metaData.composer - the composer of the media.
- \li \c metaData.conductor - the conductor of the media.
- \li \c metaData.lyrics - the lyrics to the media.
- \li \c metaData.mood - the mood of the media.
- \li \c metaData.trackNumber - the track number of the media.
- \li \c metaData.trackCount - the number of tracks on the album containing the media.
- \li \c metaData.coverArtUrlSmall - the URL of a small cover art image.
- \li \c metaData.coverArtUrlLarge - the URL of a large cover art image.
- \li \c metaData.resolution - the dimension of an image or video.
- \li \c metaData.pixelAspectRatio - the pixel aspect ratio of an image or video.
- \li \c metaData.videoFrameRate - the frame rate of the media's video stream.
- \li \c metaData.videoBitRate - the bit rate of the media's video stream in bits per second.
- \li \c metaData.videoCodec - the encoding of the media's video stream.
- \li \c metaData.posterUrl - the URL of a poster image.
- \li \c metaData.chapterNumber - the chapter number of the media.
- \li \c metaData.director - the director of the media.
- \li \c metaData.leadPerformer - the lead performer in the media.
- \li \c metaData.writer - the writer of the media.
- \endlist
-
- \sa {QMediaMetaData}
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qdeclarativeaudio_p.cpp"
-
-
diff --git a/src/imports/multimedia/qdeclarativeaudio_p.h b/src/imports/multimedia/qdeclarativeaudio_p.h
deleted file mode 100644
index dc8800695..000000000
--- a/src/imports/multimedia/qdeclarativeaudio_p.h
+++ /dev/null
@@ -1,322 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEAUDIO_P_H
-#define QDECLARATIVEAUDIO_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qbasictimer.h>
-#include <QtQml/qqmlparserstatus.h>
-#include <QtQml/qqml.h>
-#include <QtQml/qjsvalue.h>
-
-#include <qmediaplayer.h>
-
-QT_BEGIN_NAMESPACE
-
-class QTimerEvent;
-class QMediaPlayerControl;
-class QMediaService;
-class QMediaServiceProvider;
-class QMetaDataReaderControl;
-class QDeclarativePlaylist;
-class QDeclarativeMediaBaseAnimation;
-class QDeclarativeMediaMetaData;
-class QMediaAvailabilityControl;
-
-class QDeclarativeAudio : public QObject, public QQmlParserStatus
-{
- Q_OBJECT
- Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
- Q_PROPERTY(QDeclarativePlaylist *playlist READ playlist WRITE setPlaylist NOTIFY playlistChanged REVISION 1)
- Q_PROPERTY(int loops READ loopCount WRITE setLoopCount NOTIFY loopCountChanged)
- Q_PROPERTY(PlaybackState playbackState READ playbackState NOTIFY playbackStateChanged)
- Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged)
- Q_PROPERTY(bool autoLoad READ isAutoLoad WRITE setAutoLoad NOTIFY autoLoadChanged)
- Q_PROPERTY(Status status READ status NOTIFY statusChanged)
- Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
- Q_PROPERTY(int position READ position NOTIFY positionChanged)
- Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged)
- Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
- Q_PROPERTY(bool hasAudio READ hasAudio NOTIFY hasAudioChanged)
- Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged)
- Q_PROPERTY(qreal bufferProgress READ bufferProgress NOTIFY bufferProgressChanged)
- Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged)
- Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged)
- Q_PROPERTY(Error error READ error NOTIFY errorChanged)
- Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
- Q_PROPERTY(QDeclarativeMediaMetaData *metaData READ metaData CONSTANT)
- Q_PROPERTY(QObject *mediaObject READ mediaObject NOTIFY mediaObjectChanged SCRIPTABLE false DESIGNABLE false)
- Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged)
- Q_PROPERTY(AudioRole audioRole READ audioRole WRITE setAudioRole NOTIFY audioRoleChanged REVISION 1)
- Q_PROPERTY(QString customAudioRole READ customAudioRole WRITE setCustomAudioRole NOTIFY customAudioRoleChanged REVISION 3)
- Q_PROPERTY(int notifyInterval READ notifyInterval WRITE setNotifyInterval NOTIFY notifyIntervalChanged REVISION 2)
- Q_PROPERTY(QVariant videoOutput READ videoOutput WRITE setVideoOutput NOTIFY videoOutputChanged REVISION 15)
- Q_ENUMS(Status)
- Q_ENUMS(Error)
- Q_ENUMS(Loop)
- Q_ENUMS(PlaybackState)
- Q_ENUMS(Availability)
- Q_ENUMS(AudioRole)
- Q_INTERFACES(QQmlParserStatus)
-public:
- enum Status
- {
- UnknownStatus = QMediaPlayer::UnknownMediaStatus,
- NoMedia = QMediaPlayer::NoMedia,
- Loading = QMediaPlayer::LoadingMedia,
- Loaded = QMediaPlayer::LoadedMedia,
- Stalled = QMediaPlayer::StalledMedia,
- Buffering = QMediaPlayer::BufferingMedia,
- Buffered = QMediaPlayer::BufferedMedia,
- EndOfMedia = QMediaPlayer::EndOfMedia,
- InvalidMedia = QMediaPlayer::InvalidMedia
- };
-
- enum Error
- {
- NoError = QMediaPlayer::NoError,
- ResourceError = QMediaPlayer::ResourceError,
- FormatError = QMediaPlayer::FormatError,
- NetworkError = QMediaPlayer::NetworkError,
- AccessDenied = QMediaPlayer::AccessDeniedError,
- ServiceMissing = QMediaPlayer::ServiceMissingError
- };
-
- enum Loop
- {
- Infinite = -1
- };
-
- enum PlaybackState
- {
- PlayingState = QMediaPlayer::PlayingState,
- PausedState = QMediaPlayer::PausedState,
- StoppedState = QMediaPlayer::StoppedState
- };
-
- enum Availability {
- Available = QMultimedia::Available,
- Busy = QMultimedia::Busy,
- Unavailable = QMultimedia::ServiceMissing,
- ResourceMissing = QMultimedia::ResourceError
- };
-
- enum AudioRole {
- UnknownRole = QAudio::UnknownRole,
- AccessibilityRole = QAudio::AccessibilityRole,
- AlarmRole = QAudio::AlarmRole,
- CustomRole = QAudio::CustomRole,
- GameRole = QAudio::GameRole,
- MusicRole = QAudio::MusicRole,
- NotificationRole = QAudio::NotificationRole,
- RingtoneRole = QAudio::RingtoneRole,
- SonificationRole = QAudio::SonificationRole,
- VideoRole = QAudio::VideoRole,
- VoiceCommunicationRole = QAudio::VoiceCommunicationRole
- };
-
- QDeclarativeAudio(QObject *parent = 0);
- ~QDeclarativeAudio();
-
- QVariant videoOutput() const;
- void setVideoOutput(const QVariant &);
-
- bool hasAudio() const;
- bool hasVideo() const;
-
- Status status() const;
- Error error() const;
- PlaybackState playbackState() const;
- void setPlaybackState(QMediaPlayer::State playbackState);
-
- void classBegin() override;
- void componentComplete() override;
-
- QObject *mediaObject() { return m_player; }
-
- Availability availability() const;
-
- AudioRole audioRole() const;
- void setAudioRole(AudioRole audioRole);
- QString customAudioRole() const;
- void setCustomAudioRole(const QString &audioRole);
-
- QUrl source() const;
- void setSource(const QUrl &url);
-
- QDeclarativePlaylist *playlist() const;
- void setPlaylist(QDeclarativePlaylist *playlist);
-
- int loopCount() const;
- void setLoopCount(int loopCount);
-
- int duration() const;
-
- int position() const;
-
- qreal volume() const;
- void setVolume(qreal volume);
-
- bool isMuted() const;
- void setMuted(bool muted);
-
- qreal bufferProgress() const;
-
- bool isSeekable() const;
-
- qreal playbackRate() const;
- void setPlaybackRate(qreal rate);
-
- QString errorString() const;
-
- QDeclarativeMediaMetaData *metaData() const;
-
- bool isAutoLoad() const;
- void setAutoLoad(bool autoLoad);
-
- bool autoPlay() const;
- void setAutoPlay(bool autoplay);
- int notifyInterval() const;
- void setNotifyInterval(int);
-
-public Q_SLOTS:
- void play();
- void pause();
- void stop();
- void seek(int position);
-
- Q_REVISION(1) QJSValue supportedAudioRoles() const;
-
-Q_SIGNALS:
- Q_REVISION(1) void playlistChanged();
-
- void sourceChanged();
- void autoLoadChanged();
- void loopCountChanged();
-
- void playbackStateChanged();
- void autoPlayChanged();
-
- void paused();
- void stopped();
- void playing();
-
- void statusChanged();
-
- void durationChanged();
- void positionChanged();
-
- void volumeChanged();
- void mutedChanged();
- void hasAudioChanged();
- void hasVideoChanged();
-
- void bufferProgressChanged();
-
- void seekableChanged();
- void playbackRateChanged();
-
- Q_REVISION(1) void audioRoleChanged();
- Q_REVISION(3) void customAudioRoleChanged();
-
- void availabilityChanged(Availability availability);
-
- void errorChanged();
- void error(QDeclarativeAudio::Error error, const QString &errorString);
-
- void mediaObjectChanged();
- Q_REVISION(2) void notifyIntervalChanged();
- Q_REVISION(15) void videoOutputChanged();
-
-private Q_SLOTS:
- void _q_error(QMediaPlayer::Error);
- void _q_availabilityChanged(QMultimedia::AvailabilityStatus);
- void _q_statusChanged();
- void _q_mediaChanged(const QMediaContent&);
-
-private:
- Q_DISABLE_COPY(QDeclarativeAudio)
-
- QDeclarativePlaylist *m_playlist;
- bool m_autoPlay;
- bool m_autoLoad;
- bool m_loaded;
- bool m_muted;
- bool m_complete;
- bool m_emitPlaylistChanged;
- int m_loopCount;
- int m_runningCount;
- int m_position;
- qreal m_vol;
- qreal m_playbackRate;
- AudioRole m_audioRole;
- QString m_customAudioRole;
-
- QMediaPlayer::State m_playbackState;
- QMediaPlayer::MediaStatus m_status;
- QMediaPlayer::Error m_error;
- QString m_errorString;
- QUrl m_source;
- QMediaContent m_content;
-
- QScopedPointer<QDeclarativeMediaMetaData> m_metaData;
-
- QMediaPlayer *m_player;
- int m_notifyInterval;
- QVariant m_videoOutput;
-
- friend class QDeclarativeMediaBaseAnimation;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeAudio))
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativecamera.cpp b/src/imports/multimedia/qdeclarativecamera.cpp
deleted file mode 100644
index c530fbe0b..000000000
--- a/src/imports/multimedia/qdeclarativecamera.cpp
+++ /dev/null
@@ -1,999 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativecamera_p.h"
-#include "qdeclarativecamerapreviewprovider_p.h"
-
-#include "qdeclarativecameraexposure_p.h"
-#include "qdeclarativecameraflash_p.h"
-#include "qdeclarativecamerafocus_p.h"
-#include "qdeclarativecameraimageprocessing_p.h"
-#include "qdeclarativecameraviewfinder_p.h"
-
-#include "qdeclarativemediametadata_p.h"
-
-#include <qmediaplayercontrol.h>
-#include <qmediaservice.h>
-#include <qvideorenderercontrol.h>
-#include <qvideodeviceselectorcontrol.h>
-#include <QtQml/qqmlinfo.h>
-
-#include <QtCore/QTimer>
-#include <QtGui/qevent.h>
-
-QT_BEGIN_NAMESPACE
-
-void QDeclarativeCamera::_q_errorOccurred(QCamera::Error errorCode)
-{
- emit errorOccurred(Error(errorCode), errorString());
- emit errorChanged();
-}
-
-void QDeclarativeCamera::_q_updateState(QCamera::State state)
-{
- emit cameraStateChanged(QDeclarativeCamera::State(state));
-}
-
-void QDeclarativeCamera::_q_availabilityChanged(QMultimedia::AvailabilityStatus availability)
-{
- emit availabilityChanged(Availability(availability));
-}
-
-/*!
- \qmltype Camera
- \instantiates QDeclarativeCamera
- \brief Access viewfinder frames, and take photos and movies.
- \ingroup multimedia_qml
- \ingroup camera_qml
- \inqmlmodule QtMultimedia
-
- \inherits QtObject
-
- You can use \c Camera to capture images and movies from a camera, and manipulate
- the capture and processing settings that get applied to the images. To display the
- viewfinder you can use \l VideoOutput with the Camera set as the source.
-
- \qml
- Item {
- width: 640
- height: 360
-
- Camera {
- id: camera
-
- imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash
-
- exposure {
- exposureCompensation: -1.0
- exposureMode: Camera.ExposurePortrait
- }
-
- flash.mode: Camera.FlashRedEyeReduction
-
- imageCapture {
- onImageCaptured: {
- photoPreview.source = preview // Show the preview in an Image
- }
- }
- }
-
- VideoOutput {
- source: camera
- anchors.fill: parent
- focus : visible // to receive focus and capture key events when visible
- }
-
- Image {
- id: photoPreview
- }
- }
- \endqml
-
- If multiple cameras are available, you can select which one to use by setting the \l deviceId
- property to a value from
- \l{QtMultimedia::QtMultimedia::availableCameras}{QtMultimedia.availableCameras}.
- On a mobile device, you can conveniently switch between front-facing and back-facing cameras
- by setting the \l position property.
-
- The various settings and functionality of the Camera stack is spread
- across a few different child properties of Camera.
-
- \table
- \header \li Property \li Description
- \row \li \l {CameraCapture} {imageCapture}
- \li Methods and properties for capturing still images.
- \row \li \l {CameraRecorder} {videoRecorder}
- \li Methods and properties for capturing movies.
- \row \li \l {CameraExposure} {exposure}
- \li Methods and properties for adjusting exposure (aperture, shutter speed etc).
- \row \li \l {CameraFocus} {focus}
- \li Methods and properties for adjusting focus and providing feedback on autofocus progress.
- \row \li \l {CameraFlash} {flash}
- \li Methods and properties for controlling the camera flash.
- \row \li \l {CameraImageProcessing} {imageProcessing}
- \li Methods and properties for adjusting camera image processing parameters.
- \endtable
-
- Basic camera state management, error reporting, and simple zoom properties are
- available in the Camera itself. For integration with C++ code, the
- \l mediaObject property allows you to
- access the standard Qt Multimedia camera controls.
-
- Many of the camera settings may take some time to apply, and might be limited
- to certain supported values depending on the hardware. Some camera settings may be
- set manually or automatically. These settings properties contain the current set value.
- For example, when autofocus is enabled the focus zones are exposed in the
- \l {CameraFocus}{focus} property.
-
- For additional information, read also the \l{Camera Overview}{camera overview}.
-*/
-
-/*!
- \class QDeclarativeCamera
- \internal
- \brief The QDeclarativeCamera class provides a camera item that you can add to a QQuickView.
-*/
-
-/*!
- Construct a declarative camera object using \a parent object.
- */
-QDeclarativeCamera::QDeclarativeCamera(QObject *parent) :
- QObject(parent),
- m_camera(0),
- m_metaData(0),
- m_pendingState(ActiveState),
- m_componentComplete(false)
-{
- m_currentCameraInfo = QCameraInfo::defaultCamera();
- m_camera = new QCamera(m_currentCameraInfo);
-
- m_imageCapture = new QDeclarativeCameraCapture(m_camera);
- m_videoRecorder = new QDeclarativeCameraRecorder(m_camera);
- m_exposure = new QDeclarativeCameraExposure(m_camera);
- m_flash = new QDeclarativeCameraFlash(m_camera);
- m_focus = new QDeclarativeCameraFocus(m_camera);
- m_imageProcessing = new QDeclarativeCameraImageProcessing(m_camera);
- m_viewfinder = new QDeclarativeCameraViewfinder(m_camera);
-
- connect(m_camera, SIGNAL(captureModeChanged(QCamera::CaptureModes)),
- this, SIGNAL(captureModeChanged()));
- connect(m_camera, SIGNAL(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason)),
- this, SIGNAL(lockStatusChanged()));
- connect(m_camera, &QCamera::stateChanged, this, &QDeclarativeCamera::_q_updateState);
- connect(m_camera, SIGNAL(statusChanged(QCamera::Status)), this, SIGNAL(cameraStatusChanged()));
- connect(m_camera, SIGNAL(errorOccurred(QCamera::Error)), this, SLOT(_q_errorOccurred(QCamera::Error)));
- connect(m_camera, SIGNAL(availabilityChanged(QMultimedia::AvailabilityStatus)),
- this, SLOT(_q_availabilityChanged(QMultimedia::AvailabilityStatus)));
-
- connect(m_camera->focus(), &QCameraFocus::opticalZoomChanged,
- this, &QDeclarativeCamera::opticalZoomChanged);
- connect(m_camera->focus(), &QCameraFocus::digitalZoomChanged,
- this, &QDeclarativeCamera::digitalZoomChanged);
- connect(m_camera->focus(), &QCameraFocus::maximumOpticalZoomChanged,
- this, &QDeclarativeCamera::maximumOpticalZoomChanged);
- connect(m_camera->focus(), &QCameraFocus::maximumDigitalZoomChanged,
- this, &QDeclarativeCamera::maximumDigitalZoomChanged);
-}
-
-/*! Destructor, clean up memory */
-QDeclarativeCamera::~QDeclarativeCamera()
-{
- m_camera->unload();
-
- // These must be deleted before QCamera
- delete m_imageCapture;
- delete m_videoRecorder;
- delete m_exposure;
- delete m_flash;
- delete m_focus;
- delete m_imageProcessing;
- delete m_metaData;
- delete m_viewfinder;
-
- delete m_camera;
-}
-
-void QDeclarativeCamera::classBegin()
-{
-}
-
-void QDeclarativeCamera::componentComplete()
-{
- m_componentComplete = true;
- setCameraState(m_pendingState);
-}
-
-/*!
- \qmlproperty string QtMultimedia::Camera::deviceId
-
- This property holds the unique identifier for the camera device being used. It may not be human-readable.
-
- You can get all available device IDs from \l{QtMultimedia::QtMultimedia::availableCameras}{QtMultimedia.availableCameras}.
- If no value is provided or if set to an empty string, the system's default camera will be used.
-
- If possible, \l cameraState, \l captureMode, \l digitalZoom and other camera parameters are
- preserved when changing the camera device.
-
- \sa displayName, position
- \since 5.4
-*/
-
-QString QDeclarativeCamera::deviceId() const
-{
- return m_currentCameraInfo.deviceName();
-}
-
-void QDeclarativeCamera::setDeviceId(const QString &name)
-{
- if (name == m_currentCameraInfo.deviceName())
- return;
-
- setupDevice(name);
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::Camera::position
-
- This property holds the physical position of the camera on the hardware system.
-
- On a mobile device, this property can be used to easily choose between
- front-facing and back-facing cameras. If this property is set to
- \c Camera.UnspecifiedPosition, the system's default camera is used.
-
- If possible, \l cameraState, \l captureMode, \l digitalZoom and other camera
- parameters are preserved when changing the camera device.
-
- \value Camera.UnspecifiedPosition
- The camera position is unspecified or unknown.
- \value Camera.BackFace
- The camera is on the back face of the system hardware. For example,
- on a mobile device, it is on side opposite from the screen.
- \value Camera.FrontFace
- The camera is on the front face of the system hardware. For example,
- on a mobile device, it means it is on the same side as the screen.
- Viewfinder frames of front-facing cameras are mirrored horizontally,
- so the users can see themselves as looking into a mirror. Captured
- images or videos are not mirrored.
-
- \sa deviceId
- \since 5.4
-*/
-
-QDeclarativeCamera::Position QDeclarativeCamera::position() const
-{
- return QDeclarativeCamera::Position(m_currentCameraInfo.position());
-}
-
-void QDeclarativeCamera::setPosition(Position position)
-{
- QCamera::Position pos = QCamera::Position(position);
- if (pos == m_currentCameraInfo.position())
- return;
-
- QString id;
-
- if (pos == QCamera::UnspecifiedPosition) {
- id = QCameraInfo::defaultCamera().deviceName();
- } else {
- QList<QCameraInfo> cameras = QCameraInfo::availableCameras(pos);
- if (!cameras.isEmpty())
- id = cameras.first().deviceName();
- }
-
- if (!id.isEmpty())
- setupDevice(id);
-}
-
-/*!
- \qmlproperty string QtMultimedia::Camera::displayName
-
- This property holds the human-readable name of the camera.
-
- You can use this property to display the name of the camera in a user interface.
-
- \readonly
- \sa deviceId
- \since 5.4
-*/
-
-QString QDeclarativeCamera::displayName() const
-{
- return m_currentCameraInfo.description();
-}
-
-/*!
- \qmlproperty int QtMultimedia::Camera::orientation
-
- This property holds the physical orientation of the camera sensor.
-
- The value is the orientation angle (clockwise, in steps of 90 degrees) of the camera sensor in
- relation to the display in its natural orientation.
-
- For example, suppose a mobile device which is naturally in portrait orientation. The back-facing
- camera is mounted in landscape. If the top side of the camera sensor is aligned with the right
- edge of the screen in natural orientation, \c orientation returns \c 270. If the top side of a
- front-facing camera sensor is aligned with the right edge of the screen, \c orientation
- returns \c 90.
-
- \readonly
- \sa VideoOutput::orientation
- \since 5.4
-*/
-
-int QDeclarativeCamera::orientation() const
-{
- return m_currentCameraInfo.orientation();
-}
-
-void QDeclarativeCamera::setupDevice(const QString &deviceName)
-{
- QMediaService *service = m_camera->service();
- if (!service)
- return;
-
- QVideoDeviceSelectorControl *deviceControl = qobject_cast<QVideoDeviceSelectorControl*>(service->requestControl(QVideoDeviceSelectorControl_iid));
- if (!deviceControl)
- return;
-
- int deviceIndex = -1;
-
- if (deviceName.isEmpty()) {
- deviceIndex = deviceControl->defaultDevice();
- } else {
- for (int i = 0; i < deviceControl->deviceCount(); ++i) {
- if (deviceControl->deviceName(i) == deviceName) {
- deviceIndex = i;
- break;
- }
- }
- }
-
- if (deviceIndex == -1)
- return;
-
- State previousState = cameraState();
- setCameraState(UnloadedState);
-
- deviceControl->setSelectedDevice(deviceIndex);
-
- QCameraInfo oldCameraInfo = m_currentCameraInfo;
- m_currentCameraInfo = QCameraInfo(*m_camera);
-
- emit deviceIdChanged();
- if (oldCameraInfo.description() != m_currentCameraInfo.description())
- emit displayNameChanged();
- if (oldCameraInfo.position() != m_currentCameraInfo.position())
- emit positionChanged();
- if (oldCameraInfo.orientation() != m_currentCameraInfo.orientation())
- emit orientationChanged();
-
- setCameraState(previousState);
-}
-
-/*!
- Returns any camera error.
- \sa QDeclarativeCameraError::Error
-*/
-QDeclarativeCamera::Error QDeclarativeCamera::errorCode() const
-{
- return QDeclarativeCamera::Error(m_camera->error());
-}
-
-/*!
- \qmlproperty string QtMultimedia::Camera::errorString
-
- This property holds the last error string, if any.
-
- \sa errorOccurred, errorCode
-*/
-QString QDeclarativeCamera::errorString() const
-{
- return m_camera->errorString();
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::Camera::availability
-
- This property holds the availability state of the camera.
-
- \value Camera.Available
- The camera is available for use.
- \value Camera.Busy
- The camera is busy at the moment as it is being used by another
- process.
- \value Camera.Unavailable
- The camera is not available for use (there may be no camera
- hardware).
- \value Camera.ResourceMissing
- The camera cannot be used because of missing resources.
- It may be possible to try again at a later time.
- */
-QDeclarativeCamera::Availability QDeclarativeCamera::availability() const
-{
- return Availability(m_camera->availability());
-}
-
-
-/*!
- \qmlproperty enumeration QtMultimedia::Camera::captureMode
-
- This property holds the camera capture mode. The default capture mode is
- \c CaptureStillImage.
-
- \value Camera.CaptureViewfinder
- Camera is only configured to display viewfinder.
- \value Camera.CaptureStillImage
- Prepares the Camera for capturing still images.
- \value Camera.CaptureVideo
- Prepares the Camera for capturing video.
-*/
-QDeclarativeCamera::CaptureMode QDeclarativeCamera::captureMode() const
-{
- return QDeclarativeCamera::CaptureMode(int(m_camera->captureMode()));
-}
-
-void QDeclarativeCamera::setCaptureMode(QDeclarativeCamera::CaptureMode mode)
-{
- m_camera->setCaptureMode(QCamera::CaptureModes(int(mode)));
-}
-
-
-/*!
- \qmlproperty enumeration QtMultimedia::Camera::cameraState
-
- This property holds the camera object's current state. The default camera
- state is \c ActiveState.
-
- \value Camera.UnloadedState
- The initial camera state, with the camera not loaded.
- The camera capabilities (with the exception of supported capture modes)
- are unknown. This state saves the most power, but takes the longest
- time to be ready for capture.
- While the supported settings are unknown in this state,
- you can still set the camera capture settings like codec,
- resolution, or frame rate.
- \value Camera.LoadedState
- The camera is loaded and ready to be configured.
- In this state you can query camera capabilities,
- set capture resolution, codecs, and so on.
- The viewfinder is not active in the loaded state.
- The camera consumes power in this state.
- \value Camera.ActiveState
- In the active state, the viewfinder frames are available
- and the camera is ready for capture.
-*/
-QDeclarativeCamera::State QDeclarativeCamera::cameraState() const
-{
- return m_componentComplete ? QDeclarativeCamera::State(m_camera->state()) : m_pendingState;
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::Camera::cameraStatus
-
- This property holds the camera object's current status.
-
- \value Camera.ActiveStatus
- The camera has been started and can produce data,
- viewfinder displays video frames.
- Depending on backend, changing camera settings such as
- capture mode, codecs, or resolution in \c {Camera.ActiveState} may
- lead to changing the status to \c LoadedStatus and \c StartingStatus
- while the settings are applied, and back to \c ActiveStatus when
- the camera is ready.
- \value Camera.StartingStatus
- The camera is transitioning to \c {Camera.ActiveState}. The camera
- service is not ready to capture yet.
- \value Camera.StoppingStatus
- The camera is transitioning from \c {Camera.ActiveState} to
- \c {Camera.LoadedState} or \c {Camera.UnloadedState}.
- \value Camera.StandbyStatus
- The camera is in the power saving standby mode.
- The camera may enter standby mode after some time of inactivity
- in the \c {Camera.LoadedState} state.
- \value Camera.LoadedStatus
- The camera is loaded and ready to be configured.
- This status indicates that the camera is opened and it's
- possible to query for supported image and video capture
- settings, such as resolution, frame rate, and codecs.
- \value Camera.LoadingStatus
- The camera is transitioning from \c {Camera.UnloadedState} to
- \c {Camera.LoadedState} or \c {Camera.ActiveState}.
- \value Camera.UnloadingStatus
- The camera is transitioning from \c {Camera.LoadedState} or
- \c {Camera.ActiveState} to \c {Camera.UnloadedState}.
- \value Camera.UnloadedStatus
- The initial camera status, with camera not loaded.
- The camera capabilities including supported capture
- settings may be unknown.
- \value Camera.UnavailableStatus
- The camera or camera backend is not available.
-*/
-QDeclarativeCamera::Status QDeclarativeCamera::cameraStatus() const
-{
- return QDeclarativeCamera::Status(m_camera->status());
-}
-
-void QDeclarativeCamera::setCameraState(QDeclarativeCamera::State state)
-{
- if (!m_componentComplete) {
- m_pendingState = state;
- return;
- }
-
- switch (state) {
- case QDeclarativeCamera::ActiveState:
- m_camera->start();
- break;
- case QDeclarativeCamera::UnloadedState:
- m_camera->unload();
- break;
- case QDeclarativeCamera::LoadedState:
- m_camera->load();
- break;
- }
-}
-
-/*!
- \qmlmethod QtMultimedia::Camera::start()
-
- Starts the camera. Viewfinder frames will
- be available and image or movie capture will
- be possible.
-*/
-void QDeclarativeCamera::start()
-{
- setCameraState(QDeclarativeCamera::ActiveState);
-}
-
-/*!
- \qmlmethod QtMultimedia::Camera::stop()
-
- Stops the camera, but leaves the camera
- stack loaded.
-
- In this state, the camera still consumes power.
-*/
-void QDeclarativeCamera::stop()
-{
- setCameraState(QDeclarativeCamera::LoadedState);
-}
-
-
-/*!
- \qmlproperty enumeration QtMultimedia::Camera::lockStatus
-
- This property holds the status of all the requested camera locks.
-
- \value Camera.Unlocked
- The application is not interested in camera settings value.
- The camera may keep this parameter without changes, which is common
- with camera focus, or adjust exposure and white balance constantly
- to keep the viewfinder image nice.
- \value Camera.Searching
- The application has requested the camera focus, exposure, or white
- balance lock with searchAndLock(). This state indicates the camera
- is focusing or calculating exposure and white balance.
- \value Camera.Locked
- The camera focus, exposure, or white balance is locked.
- The camera is ready to capture, and the application may check the
- exposure parameters.
- The locked state usually means the requested parameter stays the
- same, except in cases where the parameter is requested to be updated
- constantly. For example, in continuous focusing mode, the focus is
- considered locked as long as the object is in focus, even while the
- actual focusing distance may be constantly changing.
-*/
-/*!
- \property QDeclarativeCamera::lockStatus
-
- This property holds the status of all the requested camera locks.
-*/
-QDeclarativeCamera::LockStatus QDeclarativeCamera::lockStatus() const
-{
- return QDeclarativeCamera::LockStatus(m_camera->lockStatus());
-}
-
-/*!
- \qmlmethod QtMultimedia::Camera::searchAndLock()
-
- Start focusing, exposure and white balance calculation.
-
- This is appropriate to call when the camera focus button is pressed
- (or on a camera capture button half-press). If the camera supports
- autofocusing, information on the focus zones is available through
- the \l {CameraFocus}{focus} property.
-*/
-void QDeclarativeCamera::searchAndLock()
-{
- m_camera->searchAndLock();
-}
-
-/*!
- \qmlmethod QtMultimedia::Camera::unlock()
-
- Unlock focus, exposure and white balance locks.
- */
-void QDeclarativeCamera::unlock()
-{
- m_camera->unlock();
-}
-/*!
- \property QDeclarativeCamera::maximumOpticalZoom
-
- This property holds the maximum optical zoom factor supported, or 1.0 if optical zoom is not supported.
-*/
-/*!
- \qmlproperty real QtMultimedia::Camera::maximumOpticalZoom
-
- This property holds the maximum optical zoom factor supported, or 1.0 if optical zoom is not supported.
-*/
-qreal QDeclarativeCamera::maximumOpticalZoom() const
-{
- return m_camera->focus()->maximumOpticalZoom();
-}
-/*!
- \property QDeclarativeCamera::maximumDigitalZoom
-
- This property holds the maximum digital zoom factor supported, or 1.0 if digital zoom is not supported.
-*/
-/*!
- \qmlproperty real QtMultimedia::Camera::maximumDigitalZoom
-
- This property holds the maximum digital zoom factor supported, or 1.0 if digital zoom is not supported.
-*/
-qreal QDeclarativeCamera::maximumDigitalZoom() const
-{
- return m_camera->focus()->maximumDigitalZoom();
-}
-/*!
- \property QDeclarativeCamera::opticalZoom
-
- This property holds the current optical zoom factor.
-*/
-
-/*!
- \qmlproperty real QtMultimedia::Camera::opticalZoom
-
- This property holds the current optical zoom factor.
-*/
-qreal QDeclarativeCamera::opticalZoom() const
-{
- return m_camera->focus()->opticalZoom();
-}
-
-void QDeclarativeCamera::setOpticalZoom(qreal value)
-{
- m_camera->focus()->zoomTo(value, digitalZoom());
-}
-/*!
- \property QDeclarativeCamera::digitalZoom
-
- This property holds the current digital zoom factor.
-*/
-/*!
- \qmlproperty real QtMultimedia::Camera::digitalZoom
-
- This property holds the current digital zoom factor.
-*/
-qreal QDeclarativeCamera::digitalZoom() const
-{
- return m_camera->focus()->digitalZoom();
-}
-
-void QDeclarativeCamera::setDigitalZoom(qreal value)
-{
- m_camera->focus()->zoomTo(opticalZoom(), value);
-}
-
-/*!
- \qmlproperty variant QtMultimedia::Camera::mediaObject
-
- This property holds the native media object for the camera.
-
- It can be used to get a pointer to a QCamera object in order to integrate with C++ code.
-
- \code
- QObject *qmlCamera; // The QML Camera object
- QCamera *camera = qvariant_cast<QCamera *>(qmlCamera->property("mediaObject"));
- \endcode
-
- \note This property is not accessible from QML.
-*/
-
-/*!
- \qmlproperty enumeration QtMultimedia::Camera::errorCode
-
- This property holds the last error code.
-
- \value Camera.NoError
- No errors have occurred.
- \value Camera.CameraError
- An error has occurred.
- \value Camera.InvalidRequestError
- System resources do not support the requested functionality.
- \value Camera.ServiceMissingError
- No camera service available.
- \value Camera.NotSupportedFeatureError
- The feature is not supported.
-
- \sa errorOccurred, errorString
-*/
-
-/*!
- \qmlsignal QtMultimedia::Camera::error(errorCode, errorString)
- \obsolete
-
- Use errorOccurred() instead.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Camera::errorOccurred(errorCode, errorString)
- \since 5.15
-
- This signal is emitted when an error specified by \a errorCode occurs.
- A descriptive string value is available in \a errorString.
-
- The corresponding handler is \c onError.
-
- \sa errorCode, errorString
-*/
-
-/*!
- \qmlsignal Camera::lockStatusChanged()
-
- This signal is emitted when the lock status (focus, exposure etc) changes.
- This can happen when locking (e.g. autofocusing) is complete or has failed.
-
- The corresponding handler is \c onLockStatusChanged.
-*/
-
-/*!
- \qmlsignal Camera::cameraStateChanged(state)
-
- This signal is emitted when the camera state has changed to \a state. Since the
- state changes may take some time to occur this signal may arrive sometime
- after the state change has been requested.
-
- The corresponding handler is \c onCameraStateChanged.
-*/
-
-/*!
- \qmlsignal Camera::opticalZoomChanged(zoom)
-
- This signal is emitted when the optical zoom setting has changed to \a zoom.
-
- The corresponding handler is \c onOpticalZoomChanged.
-*/
-
-/*!
- \qmlsignal Camera::digitalZoomChanged(zoom)
-
- This signal is emitted when the digital zoom setting has changed to \a zoom.
-
- The corresponding handler is \c onDigitalZoomChanged.
-*/
-
-/*!
- \qmlsignal Camera::maximumOpticalZoomChanged(zoom)
-
- This signal is emitted when the maximum optical zoom setting has
- changed to \a zoom. This can occur when you change between video
- and still image capture modes, or the capture settings are changed.
-
- The corresponding handler is \c onMaximumOpticalZoomChanged.
-*/
-
-/*!
- \qmlsignal Camera::maximumDigitalZoomChanged(zoom)
-
- This signal is emitted when the maximum digital zoom setting has
- changed to \a zoom. This can occur when you change between video
- and still image capture modes, or the capture settings are changed.
-
- The corresponding handler is \c onMaximumDigitalZoomChanged.
-*/
-
-/*!
- \qmlpropertygroup QtMultimedia::Camera::metaData
- \qmlproperty variant QtMultimedia::Camera::metaData.cameraManufacturer
- \qmlproperty variant QtMultimedia::Camera::metaData.cameraModel
- \qmlproperty variant QtMultimedia::Camera::metaData.event
- \qmlproperty variant QtMultimedia::Camera::metaData.subject
- \qmlproperty variant QtMultimedia::Camera::metaData.orientation
- \qmlproperty variant QtMultimedia::Camera::metaData.dateTimeOriginal
- \qmlproperty variant QtMultimedia::Camera::metaData.gpsLatitude
- \qmlproperty variant QtMultimedia::Camera::metaData.gpsLongitude
- \qmlproperty variant QtMultimedia::Camera::metaData.gpsAltitude
- \qmlproperty variant QtMultimedia::Camera::metaData.gpsTimestamp
- \qmlproperty variant QtMultimedia::Camera::metaData.gpsTrack
- \qmlproperty variant QtMultimedia::Camera::metaData.gpsSpeed
- \qmlproperty variant QtMultimedia::Camera::metaData.gpsImgDirection
- \qmlproperty variant QtMultimedia::Camera::metaData.gpsProcessingMethod
-
- These properties hold the meta data for the camera captures.
-
- \list
- \li \c metaData.cameraManufacturer holds the name of the manufacturer of the camera.
- \li \c metaData.cameraModel holds the name of the model of the camera.
- \li \c metaData.event holds the event during which the photo or video is to be captured.
- \li \c metaData.subject holds the name of the subject of the capture or recording.
- \li \c metaData.orientation holds the clockwise rotation of the camera at time of capture.
- \li \c metaData.dateTimeOriginal holds the initial time at which the photo or video is captured.
- \li \c metaData.gpsLatitude holds the latitude of the camera in decimal degrees at time of capture.
- \li \c metaData.gpsLongitude holds the longitude of the camera in decimal degrees at time of capture.
- \li \c metaData.gpsAltitude holds the altitude of the camera in meters at time of capture.
- \li \c metaData.gpsTimestamp holds the timestamp of the GPS position data.
- \li \c metaData.gpsTrack holds direction of movement of the camera at the time of
- capture. It is measured in degrees clockwise from north.
- \li \c metaData.gpsSpeed holds the velocity in kilometers per hour of the camera at time of capture.
- \li \c metaData.gpsImgDirection holds direction the camera is facing at the time of capture.
- It is measured in degrees clockwise from north.
- \li \c metaData.gpsProcessingMethod holds the name of the method for determining the GPS position.
- \endlist
-
- \sa {QMediaMetaData}
- \since 5.4
-*/
-
-QDeclarativeMediaMetaData *QDeclarativeCamera::metaData()
-{
- if (!m_metaData)
- m_metaData = new QDeclarativeMediaMetaData(m_camera);
- return m_metaData;
-}
-
-/*!
- \qmlpropertygroup QtMultimedia::Camera::viewfinder
- \qmlproperty size QtMultimedia::Camera::viewfinder.resolution
- \qmlproperty real QtMultimedia::Camera::viewfinder.minimumFrameRate
- \qmlproperty real QtMultimedia::Camera::viewfinder.maximumFrameRate
-
- These properties hold the viewfinder settings.
-
- \c viewfinder.resolution holds the resolution of the camera viewfinder. If no
- resolution is given or if it is empty, the backend uses a default value.
-
- \c viewfinder.minimumFrameRate holds the minimum frame rate for the viewfinder in
- frames per second. If no value is given or if set to \c 0, the backend uses a default value.
-
- \c viewfinder.maximumFrameRate holds the maximum frame rate for the viewfinder in
- frames per second. If no value is given or if set to \c 0, the backend uses a default value.
-
- If \c viewfinder.minimumFrameRate is equal to \c viewfinder.maximumFrameRate, the frame rate is
- fixed. If not, the actual frame rate fluctuates between the two values.
-
- Changing the viewfinder settings while the camera is in the \c Camera.ActiveState state may
- cause the camera to be restarted.
-
- If the camera is used to capture videos or images, the viewfinder settings might be
- ignored if they conflict with the capture settings. You can check the actual viewfinder settings
- once the camera is in the \c Camera.ActiveStatus status.
-
- Supported values can be retrieved with supportedViewfinderResolutions() and
- supportedViewfinderFrameRateRanges().
-
- \since 5.4
- */
-
-QDeclarativeCameraViewfinder *QDeclarativeCamera::viewfinder()
-{
- return m_viewfinder;
-}
-
-/*!
- \qmlmethod list<size> QtMultimedia::Camera::supportedViewfinderResolutions(real minimumFrameRate, real maximumFrameRate)
-
- Returns a list of supported viewfinder resolutions.
-
- If both optional parameters \a minimumFrameRate and \a maximumFrameRate are specified, the
- returned list is reduced to resolutions supported for the given frame rate range.
-
- The camera must be loaded before calling this function, otherwise the returned list
- is empty.
-
- \sa {QtMultimedia::Camera::viewfinder}{viewfinder}
-
- \since 5.5
-*/
-QJSValue QDeclarativeCamera::supportedViewfinderResolutions(qreal minimumFrameRate, qreal maximumFrameRate)
-{
- QQmlEngine *engine = qmlEngine(this);
-
- QCameraViewfinderSettings settings;
- settings.setMinimumFrameRate(minimumFrameRate);
- settings.setMaximumFrameRate(maximumFrameRate);
- const QList<QSize> resolutions = m_camera->supportedViewfinderResolutions(settings);
-
- QJSValue supportedResolutions = engine->newArray(resolutions.count());
- int i = 0;
- for (const QSize &resolution : resolutions) {
- QJSValue size = engine->newObject();
- size.setProperty(QStringLiteral("width"), resolution.width());
- size.setProperty(QStringLiteral("height"), resolution.height());
- supportedResolutions.setProperty(i++, size);
- }
-
- return supportedResolutions;
-}
-
-/*!
- \qmlmethod list<object> QtMultimedia::Camera::supportedViewfinderFrameRateRanges(size resolution)
-
- Returns a list of supported viewfinder frame rate ranges.
-
- Each range object in the list has the \c minimumFrameRate and \c maximumFrameRate properties.
-
- If the optional parameter \a resolution is specified, the returned list is reduced to frame rate
- ranges supported for the given \a resolution.
-
- The camera must be loaded before calling this function, otherwise the returned list
- is empty.
-
- \sa {QtMultimedia::Camera::viewfinder}{viewfinder}
-
- \since 5.5
-*/
-QJSValue QDeclarativeCamera::supportedViewfinderFrameRateRanges(const QJSValue &resolution)
-{
- QQmlEngine *engine = qmlEngine(this);
-
- QCameraViewfinderSettings settings;
- if (!resolution.isUndefined()) {
- QJSValue width = resolution.property(QStringLiteral("width"));
- QJSValue height = resolution.property(QStringLiteral("height"));
- if (width.isNumber() && height.isNumber())
- settings.setResolution(width.toInt(), height.toInt());
- }
- const QList<QCamera::FrameRateRange> frameRateRanges = m_camera->supportedViewfinderFrameRateRanges(settings);
-
- QJSValue supportedFrameRateRanges = engine->newArray(frameRateRanges.count());
- int i = 0;
- for (const QCamera::FrameRateRange &frameRateRange : frameRateRanges) {
- QJSValue range = engine->newObject();
- range.setProperty(QStringLiteral("minimumFrameRate"), frameRateRange.minimumFrameRate);
- range.setProperty(QStringLiteral("maximumFrameRate"), frameRateRange.maximumFrameRate);
- supportedFrameRateRanges.setProperty(i++, range);
- }
-
- return supportedFrameRateRanges;
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qdeclarativecamera_p.cpp"
diff --git a/src/imports/multimedia/qdeclarativecamera_p.h b/src/imports/multimedia/qdeclarativecamera_p.h
deleted file mode 100644
index 51bd5ddf9..000000000
--- a/src/imports/multimedia/qdeclarativecamera_p.h
+++ /dev/null
@@ -1,366 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVECAMERA_H
-#define QDECLARATIVECAMERA_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qdeclarativecameracapture_p.h"
-#include "qdeclarativecamerarecorder_p.h"
-
-#include <qcamera.h>
-#include <qcamerainfo.h>
-#include <qcameraimageprocessing.h>
-#include <qcameraimagecapture.h>
-
-#include <QtCore/qbasictimer.h>
-#include <QtCore/qdatetime.h>
-#include <QtQml/qqmlparserstatus.h>
-#include <QtQml/qqml.h>
-#include <QtQml/qjsvalue.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeCameraExposure;
-class QDeclarativeCameraFocus;
-class QDeclarativeCameraFlash;
-class QDeclarativeCameraImageProcessing;
-class QDeclarativeMediaMetaData;
-class QDeclarativeCameraViewfinder;
-
-class QDeclarativeCamera : public QObject, public QQmlParserStatus
-{
- Q_OBJECT
- Q_INTERFACES(QQmlParserStatus)
-
- Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged REVISION 1)
- Q_PROPERTY(Position position READ position WRITE setPosition NOTIFY positionChanged REVISION 1)
- Q_PROPERTY(QString displayName READ displayName NOTIFY displayNameChanged REVISION 1)
- Q_PROPERTY(int orientation READ orientation NOTIFY orientationChanged REVISION 1)
-
- Q_PROPERTY(CaptureMode captureMode READ captureMode WRITE setCaptureMode NOTIFY captureModeChanged)
- Q_PROPERTY(State cameraState READ cameraState WRITE setCameraState NOTIFY cameraStateChanged)
- Q_PROPERTY(Status cameraStatus READ cameraStatus NOTIFY cameraStatusChanged)
- Q_PROPERTY(LockStatus lockStatus READ lockStatus NOTIFY lockStatusChanged)
- Q_PROPERTY(Error errorCode READ errorCode NOTIFY errorChanged)
- Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
-
- Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged)
-
- Q_PROPERTY(qreal opticalZoom READ opticalZoom WRITE setOpticalZoom NOTIFY opticalZoomChanged)
- Q_PROPERTY(qreal maximumOpticalZoom READ maximumOpticalZoom NOTIFY maximumOpticalZoomChanged)
- Q_PROPERTY(qreal digitalZoom READ digitalZoom WRITE setDigitalZoom NOTIFY digitalZoomChanged)
- Q_PROPERTY(qreal maximumDigitalZoom READ maximumDigitalZoom NOTIFY maximumDigitalZoomChanged)
-
- Q_PROPERTY(QObject *mediaObject READ mediaObject NOTIFY mediaObjectChanged SCRIPTABLE false DESIGNABLE false)
- Q_PROPERTY(QDeclarativeCameraCapture* imageCapture READ imageCapture CONSTANT)
- Q_PROPERTY(QDeclarativeCameraRecorder* videoRecorder READ videoRecorder CONSTANT)
- Q_PROPERTY(QDeclarativeCameraExposure* exposure READ exposure CONSTANT)
- Q_PROPERTY(QDeclarativeCameraFlash* flash READ flash CONSTANT)
- Q_PROPERTY(QDeclarativeCameraFocus* focus READ focus CONSTANT)
- Q_PROPERTY(QDeclarativeCameraImageProcessing* imageProcessing READ imageProcessing CONSTANT)
- Q_PROPERTY(QDeclarativeMediaMetaData *metaData READ metaData CONSTANT REVISION 1)
- Q_PROPERTY(QDeclarativeCameraViewfinder *viewfinder READ viewfinder CONSTANT REVISION 1)
-
- Q_ENUMS(Position)
- Q_ENUMS(CaptureMode)
- Q_ENUMS(State)
- Q_ENUMS(Status)
- Q_ENUMS(LockStatus)
- Q_ENUMS(Error)
-
- Q_ENUMS(FlashMode)
- Q_ENUMS(ExposureMode)
- Q_ENUMS(MeteringMode)
-
- Q_ENUMS(FocusMode)
- Q_ENUMS(FocusPointMode)
- Q_ENUMS(FocusAreaStatus)
- Q_ENUMS(Availability)
-
-public:
- enum Position {
- UnspecifiedPosition = QCamera::UnspecifiedPosition,
- BackFace = QCamera::BackFace,
- FrontFace = QCamera::FrontFace
- };
-
- enum CaptureMode {
- CaptureViewfinder = QCamera::CaptureViewfinder,
- CaptureStillImage = QCamera::CaptureStillImage,
- CaptureVideo = QCamera::CaptureVideo
- };
-
- enum State
- {
- ActiveState = QCamera::ActiveState,
- LoadedState = QCamera::LoadedState,
- UnloadedState = QCamera::UnloadedState
- };
-
- enum Status
- {
- UnavailableStatus = QCamera::UnavailableStatus,
- UnloadedStatus = QCamera::UnloadedStatus,
- LoadingStatus = QCamera::LoadingStatus,
- UnloadingStatus = QCamera::UnloadingStatus,
- LoadedStatus = QCamera::LoadedStatus,
- StandbyStatus = QCamera::StandbyStatus,
- StartingStatus = QCamera::StartingStatus,
- StoppingStatus = QCamera::StoppingStatus,
- ActiveStatus = QCamera::ActiveStatus
- };
-
- enum LockStatus
- {
- Unlocked = QCamera::Unlocked,
- Searching = QCamera::Searching,
- Locked = QCamera::Locked
- };
-
- enum Error
- {
- NoError = QCamera::NoError,
- CameraError = QCamera::CameraError,
- InvalidRequestError = QCamera::InvalidRequestError,
- ServiceMissingError = QCamera::ServiceMissingError,
- NotSupportedFeatureError = QCamera::NotSupportedFeatureError
- };
-
- enum FlashMode {
- FlashAuto = QCameraExposure::FlashAuto,
- FlashOff = QCameraExposure::FlashOff,
- FlashOn = QCameraExposure::FlashOn,
- FlashRedEyeReduction = QCameraExposure::FlashRedEyeReduction,
- FlashFill = QCameraExposure::FlashFill,
- FlashTorch = QCameraExposure::FlashTorch,
- FlashVideoLight = QCameraExposure::FlashVideoLight,
- FlashSlowSyncFrontCurtain = QCameraExposure::FlashSlowSyncFrontCurtain,
- FlashSlowSyncRearCurtain = QCameraExposure::FlashSlowSyncRearCurtain,
- FlashManual = QCameraExposure::FlashManual
- };
-
- enum ExposureMode {
- ExposureAuto = QCameraExposure::ExposureAuto,
- ExposureManual = QCameraExposure::ExposureManual,
- ExposurePortrait = QCameraExposure::ExposurePortrait,
- ExposureNight = QCameraExposure::ExposureNight,
- ExposureBacklight = QCameraExposure::ExposureBacklight,
- ExposureSpotlight = QCameraExposure::ExposureSpotlight,
- ExposureSports = QCameraExposure::ExposureSports,
- ExposureSnow = QCameraExposure::ExposureSnow,
- ExposureBeach = QCameraExposure::ExposureBeach,
- ExposureLargeAperture = QCameraExposure::ExposureLargeAperture,
- ExposureSmallAperture = QCameraExposure::ExposureSmallAperture,
- ExposureAction = QCameraExposure::ExposureAction,
- ExposureLandscape = QCameraExposure::ExposureLandscape,
- ExposureNightPortrait = QCameraExposure::ExposureNightPortrait,
- ExposureTheatre = QCameraExposure::ExposureTheatre,
- ExposureSunset = QCameraExposure::ExposureSunset,
- ExposureSteadyPhoto = QCameraExposure::ExposureSteadyPhoto,
- ExposureFireworks = QCameraExposure::ExposureFireworks,
- ExposureParty = QCameraExposure::ExposureParty,
- ExposureCandlelight = QCameraExposure::ExposureCandlelight,
- ExposureBarcode = QCameraExposure::ExposureBarcode,
- ExposureModeVendor = QCameraExposure::ExposureModeVendor
- };
-
- enum MeteringMode {
- MeteringMatrix = QCameraExposure::MeteringMatrix,
- MeteringAverage = QCameraExposure::MeteringAverage,
- MeteringSpot = QCameraExposure::MeteringSpot
- };
-
- enum FocusMode {
- FocusManual = QCameraFocus::ManualFocus,
- FocusHyperfocal = QCameraFocus::HyperfocalFocus,
- FocusInfinity = QCameraFocus::InfinityFocus,
- FocusAuto = QCameraFocus::AutoFocus,
- FocusContinuous = QCameraFocus::ContinuousFocus,
- FocusMacro = QCameraFocus::MacroFocus
- };
-
- enum FocusPointMode {
- FocusPointAuto = QCameraFocus::FocusPointAuto,
- FocusPointCenter = QCameraFocus::FocusPointCenter,
- FocusPointFaceDetection = QCameraFocus::FocusPointFaceDetection,
- FocusPointCustom = QCameraFocus::FocusPointCustom
- };
-
- enum FocusAreaStatus {
- FocusAreaUnused = QCameraFocusZone::Unused,
- FocusAreaSelected = QCameraFocusZone::Selected,
- FocusAreaFocused = QCameraFocusZone::Focused
- };
-
- enum Availability {
- Available = QMultimedia::Available,
- Busy = QMultimedia::Busy,
- Unavailable = QMultimedia::ServiceMissing,
- ResourceMissing = QMultimedia::ResourceError
- };
-
- QDeclarativeCamera(QObject *parent = 0);
- ~QDeclarativeCamera();
-
- QObject *mediaObject() { return m_camera; }
-
- QDeclarativeCameraCapture *imageCapture() { return m_imageCapture; }
- QDeclarativeCameraRecorder *videoRecorder() { return m_videoRecorder; }
- QDeclarativeCameraExposure *exposure() { return m_exposure; }
- QDeclarativeCameraFlash *flash() { return m_flash; }
- QDeclarativeCameraFocus *focus() { return m_focus; }
- QDeclarativeCameraImageProcessing *imageProcessing() { return m_imageProcessing; }
- QDeclarativeCameraViewfinder *viewfinder();
-
- QDeclarativeMediaMetaData *metaData();
-
- QString deviceId() const;
- void setDeviceId(const QString &name);
-
- Position position() const;
- void setPosition(Position position);
-
- QString displayName() const;
- int orientation() const;
-
- CaptureMode captureMode() const;
- State cameraState() const;
- Status cameraStatus() const;
-
- Error errorCode() const;
- QString errorString() const;
-
- LockStatus lockStatus() const;
-
- qreal maximumOpticalZoom() const;
- qreal maximumDigitalZoom() const;
-
- qreal opticalZoom() const;
- qreal digitalZoom() const;
-
- Availability availability() const;
-
-public Q_SLOTS:
- void setCaptureMode(CaptureMode mode);
-
- void start();
- void stop();
-
- void setCameraState(State state);
-
- void searchAndLock();
- void unlock();
-
- void setOpticalZoom(qreal);
- void setDigitalZoom(qreal);
-
- Q_REVISION(2) QJSValue supportedViewfinderResolutions(qreal minimumFrameRate = 0.0,
- qreal maximumFrameRate = 0.0);
-
- Q_REVISION(2) QJSValue supportedViewfinderFrameRateRanges(const QJSValue &resolution = QJSValue());
-
-Q_SIGNALS:
- void errorChanged();
- Q_REVISION(15) void errorOccurred(QDeclarativeCamera::Error errorCode, const QString &errorString);
-
- Q_REVISION(1) void deviceIdChanged();
- Q_REVISION(1) void positionChanged();
- Q_REVISION(1) void displayNameChanged();
- Q_REVISION(1) void orientationChanged();
-
- void captureModeChanged();
- void cameraStateChanged(QDeclarativeCamera::State);
- void cameraStatusChanged();
-
- void lockStatusChanged();
-
- void opticalZoomChanged(qreal);
- void digitalZoomChanged(qreal);
- void maximumOpticalZoomChanged(qreal);
- void maximumDigitalZoomChanged(qreal);
-
- void mediaObjectChanged();
-
- void availabilityChanged(Availability availability);
-
-private Q_SLOTS:
- void _q_updateState(QCamera::State);
- void _q_errorOccurred(QCamera::Error);
- void _q_availabilityChanged(QMultimedia::AvailabilityStatus);
-
-protected:
- void classBegin() override;
- void componentComplete() override;
-
-private:
- Q_DISABLE_COPY(QDeclarativeCamera)
- void setupDevice(const QString &deviceName);
-
- QCamera *m_camera;
- QCameraInfo m_currentCameraInfo;
-
- QDeclarativeCameraCapture *m_imageCapture;
- QDeclarativeCameraRecorder *m_videoRecorder;
- QDeclarativeCameraExposure *m_exposure;
- QDeclarativeCameraFlash *m_flash;
- QDeclarativeCameraFocus *m_focus;
- QDeclarativeCameraImageProcessing *m_imageProcessing;
- QDeclarativeMediaMetaData *m_metaData;
- QDeclarativeCameraViewfinder *m_viewfinder;
-
- State m_pendingState;
- bool m_componentComplete;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeCamera))
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativecameracapture.cpp b/src/imports/multimedia/qdeclarativecameracapture.cpp
deleted file mode 100644
index 96611f0ea..000000000
--- a/src/imports/multimedia/qdeclarativecameracapture.cpp
+++ /dev/null
@@ -1,384 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativecamera_p.h"
-#include "qdeclarativecameracapture_p.h"
-#include "qdeclarativecamerapreviewprovider_p.h"
-
-#include <qmetadatawritercontrol.h>
-
-#include <QtCore/qurl.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype CameraCapture
- \instantiates QDeclarativeCameraCapture
- \brief An interface for capturing camera images.
- \ingroup multimedia_qml
- \inqmlmodule QtMultimedia
- \ingroup camera_qml
-
- This type allows you to capture still images and be notified when they
- are available or saved to disk. You can adjust the resolution of the captured
- image and where the saved image should go.
-
- CameraCapture is a child of a \l Camera (as the \c imageCapture property)
- and cannot be created directly.
-
- \qml
- Item {
- width: 640
- height: 360
-
- Camera {
- id: camera
-
- imageCapture {
- onImageCaptured: {
- // Show the preview in an Image
- photoPreview.source = preview
- }
- }
- }
-
- VideoOutput {
- source: camera
- focus : visible // to receive focus and capture key events when visible
- anchors.fill: parent
-
- MouseArea {
- anchors.fill: parent;
- onClicked: camera.imageCapture.capture();
- }
- }
-
- Image {
- id: photoPreview
- }
- }
- \endqml
-
-*/
-
-QDeclarativeCameraCapture::QDeclarativeCameraCapture(QCamera *camera, QObject *parent) :
- QObject(parent),
- m_camera(camera)
-{
- m_capture = new QCameraImageCapture(camera, this);
-
- connect(m_capture, SIGNAL(readyForCaptureChanged(bool)), this, SIGNAL(readyForCaptureChanged(bool)));
- connect(m_capture, SIGNAL(imageExposed(int)), this, SIGNAL(imageExposed(int)));
- connect(m_capture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(_q_imageCaptured(int,QImage)));
- connect(m_capture, SIGNAL(imageMetadataAvailable(int,QString,QVariant)), this,
- SLOT(_q_imageMetadataAvailable(int,QString,QVariant)));
- connect(m_capture, SIGNAL(imageSaved(int,QString)), this, SLOT(_q_imageSaved(int,QString)));
- connect(m_capture, SIGNAL(error(int,QCameraImageCapture::Error,QString)),
- this, SLOT(_q_captureFailed(int,QCameraImageCapture::Error,QString)));
-
- connect(m_camera, SIGNAL(statusChanged(QCamera::Status)),
- this, SLOT(_q_cameraStatusChanged(QCamera::Status)));
-
- QMediaService *service = camera->service();
- m_metadataWriterControl = service ? service->requestControl<QMetaDataWriterControl*>() : 0;
-}
-
-QDeclarativeCameraCapture::~QDeclarativeCameraCapture()
-{
-}
-
-/*!
- \property QDeclarativeCameraCapture::ready
-
- This property holds a bool value indicating whether the camera
- is ready to capture photos or not.
-
- Calling capture() while \e ready is \c false is not permitted and
- results in an error.
-*/
-
-/*!
- \qmlproperty bool QtMultimedia::CameraCapture::ready
-
- This property holds a bool value indicating whether the camera
- is ready to capture photos or not.
-
- Calling capture() while \e ready is \c false is not permitted and
- results in an error.
-*/
-bool QDeclarativeCameraCapture::isReadyForCapture() const
-{
- return m_capture->isReadyForCapture();
-}
-
-/*!
- \qmlmethod QtMultimedia::CameraCapture::capture()
-
- Start image capture. The \l imageCaptured and \l imageSaved signals will
- be emitted when the capture is complete.
-
- The image will be captured to the default system location, typically
- QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) for
- still imaged or QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)
- for video.
-
- Camera saves all the capture parameters like exposure settings or
- image processing parameters, so changes to camera parameters after
- capture() is called do not affect previous capture requests.
-
- capture() returns the capture requestId parameter, used with
- imageExposed(), imageCaptured(), imageMetadataAvailable() and imageSaved() signals.
-
- \sa ready
-*/
-int QDeclarativeCameraCapture::capture()
-{
- return m_capture->capture();
-}
-
-/*!
- \qmlmethod QtMultimedia::CameraCapture::captureToLocation(location)
-
- Start image capture to specified \a location. The \l imageCaptured and \l imageSaved signals will
- be emitted when the capture is complete.
-
- CameraCapture::captureToLocation returns the capture requestId parameter, used with
- imageExposed(), imageCaptured(), imageMetadataAvailable() and imageSaved() signals.
-
- If the application is unable to write to the location specified by \c location
- the CameraCapture will emit an error. The most likely reasons for the application
- to be unable to write to a location is that the path is wrong and the location does not exists,
- or the application does not have write permission for that location.
-*/
-int QDeclarativeCameraCapture::captureToLocation(const QString &location)
-{
- return m_capture->capture(location);
-}
-
-/*!
- \qmlmethod QtMultimedia::CameraCapture::cancelCapture()
-
- Cancel pending image capture requests.
-*/
-
-void QDeclarativeCameraCapture::cancelCapture()
-{
- m_capture->cancelCapture();
-}
-/*!
- \property QDeclarativeCameraCapture::capturedImagePath
-
- This property holds the location of the last captured image.
-*/
-/*!
- \qmlproperty string QtMultimedia::CameraCapture::capturedImagePath
-
- This property holds the location of the last captured image.
-*/
-QString QDeclarativeCameraCapture::capturedImagePath() const
-{
- return m_capturedImagePath;
-}
-
-void QDeclarativeCameraCapture::_q_imageCaptured(int id, const QImage &preview)
-{
- QString previewId = QString("preview_%1").arg(id);
- QDeclarativeCameraPreviewProvider::registerPreview(previewId, preview);
-
- emit imageCaptured(id, QLatin1String("image://camera/")+previewId);
-}
-
-void QDeclarativeCameraCapture::_q_imageSaved(int id, const QString &fileName)
-{
- m_capturedImagePath = fileName;
- emit imageSaved(id, fileName);
-}
-
-void QDeclarativeCameraCapture::_q_imageMetadataAvailable(int id, const QString &key, const QVariant &value)
-{
- emit imageMetadataAvailable(id, key, value);
-}
-
-
-void QDeclarativeCameraCapture::_q_captureFailed(int id, QCameraImageCapture::Error error, const QString &message)
-{
- Q_UNUSED(error);
- qWarning() << "QCameraImageCapture error:" << message;
- emit captureFailed(id, message);
-}
-
-void QDeclarativeCameraCapture::_q_cameraStatusChanged(QCamera::Status status)
-{
- if (status != QCamera::UnloadedStatus && status != QCamera::LoadedStatus &&
- status != QCamera::ActiveStatus)
- return;
-
- emit supportedResolutionsChanged();
-}
-/*!
- \property QDeclarativeCameraCapture::resolution
-
- This property holds the resolution/size of the image to be captured.
- If empty, the system chooses the appropriate resolution.
-*/
-
-/*!
- \qmlproperty size QtMultimedia::CameraCapture::resolution
-
- This property holds the resolution/size of the image to be captured.
- If empty, the system chooses the appropriate resolution.
-
- \sa supportedResolutions
-*/
-
-QSize QDeclarativeCameraCapture::resolution()
-{
- return m_imageSettings.resolution();
-}
-
-void QDeclarativeCameraCapture::setResolution(const QSize &captureResolution)
-{
- m_imageSettings = m_capture->encodingSettings();
- if (captureResolution != resolution()) {
- m_imageSettings.setResolution(captureResolution);
- m_capture->setEncodingSettings(m_imageSettings);
- emit resolutionChanged(captureResolution);
- }
-}
-
-QCameraImageCapture::Error QDeclarativeCameraCapture::error() const
-{
- return m_capture->error();
-}
-/*!
- \property QDeclarativeCameraCapture::errorString
-
- This property holds the error message related to the last capture.
-*/
-
-/*!
- \qmlproperty string QtMultimedia::CameraCapture::errorString
-
- This property holds the error message related to the last capture.
-*/
-QString QDeclarativeCameraCapture::errorString() const
-{
- return m_capture->errorString();
-}
-
-/*!
- \qmlproperty list<size> QtMultimedia::CameraCapture::supportedResolutions
-
- This property holds a list of resolutions which are supported for capturing.
- The information can be used to set a valid \e resolution. If the camera isn't
- loaded, the list will be empty.
-
- \since 5.9
- \sa resolution
- */
-QVariantList QDeclarativeCameraCapture::supportedResolutions()
-{
- QVariantList supportedResolutions;
- for (const QSize &res : m_capture->supportedResolutions())
- supportedResolutions.append(QVariant(res));
- return supportedResolutions;
-}
-
-/*!
- \qmlmethod QtMultimedia::CameraCapture::setMetadata(key, value)
-
-
- Sets a particular metadata \a key to \a value for the subsequent image captures.
-
- \sa QMediaMetaData
-*/
-void QDeclarativeCameraCapture::setMetadata(const QString &key, const QVariant &value)
-{
- if (m_metadataWriterControl)
- m_metadataWriterControl->setMetaData(key, value);
-}
-
-/*!
- \qmlsignal QtMultimedia::CameraCapture::captureFailed(requestId, message)
-
- This signal is emitted when an error occurs during capture with \a requestId.
- A descriptive message is available in \a message.
-
- The corresponding handler is \c onCaptureFailed.
-*/
-
-/*!
- \qmlsignal QtMultimedia::CameraCapture::imageCaptured(requestId, preview)
-
- This signal is emitted when an image with \a requestId has been captured
- but not yet saved to the filesystem. The \a preview
- parameter can be used as the URL supplied to an \l Image.
-
- The corresponding handler is \c onImageCaptured.
-
- \sa imageSaved
-*/
-
-/*!
- \qmlsignal QtMultimedia::CameraCapture::imageSaved(requestId, path)
-
- This signal is emitted after the image with \a requestId has been written to the filesystem.
- The \a path is a local file path, not a URL.
-
- The corresponding handler is \c onImageSaved.
-
- \sa imageCaptured
-*/
-
-
-/*!
- \qmlsignal QtMultimedia::CameraCapture::imageMetadataAvailable(requestId, key, value)
-
- This signal is emitted when the image with \a requestId has new metadata
- available with the key \a key and value \a value.
-
- The corresponding handler is \c onImageMetadataAvailable.
-
- \sa imageCaptured
-*/
-
-
-QT_END_NAMESPACE
-
-#include "moc_qdeclarativecameracapture_p.cpp"
diff --git a/src/imports/multimedia/qdeclarativecameracapture_p.h b/src/imports/multimedia/qdeclarativecameracapture_p.h
deleted file mode 100644
index 1b8066a4e..000000000
--- a/src/imports/multimedia/qdeclarativecameracapture_p.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVECAMERACAPTURE_H
-#define QDECLARATIVECAMERACAPTURE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <qcamera.h>
-#include <qcameraimagecapture.h>
-#include <qmediaencodersettings.h>
-
-#include <QtQml/qqml.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeCamera;
-class QMetaDataWriterControl;
-
-class QDeclarativeCameraCapture : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(bool ready READ isReadyForCapture NOTIFY readyForCaptureChanged)
- Q_PROPERTY(QString capturedImagePath READ capturedImagePath NOTIFY imageSaved)
- Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged)
- Q_PROPERTY(QString errorString READ errorString NOTIFY captureFailed)
- Q_PROPERTY(QVariantList supportedResolutions READ supportedResolutions NOTIFY supportedResolutionsChanged REVISION 1)
-
-public:
- ~QDeclarativeCameraCapture();
-
- bool isReadyForCapture() const;
-
- QSize resolution();
-
- QString capturedImagePath() const;
- QCameraImageCapture::Error error() const;
- QString errorString() const;
- QVariantList supportedResolutions();
-
-public Q_SLOTS:
- int capture();
- int captureToLocation(const QString &location);
- void cancelCapture();
-
- void setResolution(const QSize &resolution);
- void setMetadata(const QString &key, const QVariant &value);
-
-Q_SIGNALS:
- void readyForCaptureChanged(bool);
-
- void imageExposed(int requestId);
- void imageCaptured(int requestId, const QString &preview);
- void imageMetadataAvailable(int requestId, const QString &key, const QVariant &value);
- void imageSaved(int requestId, const QString &path);
- void captureFailed(int requestId, const QString &message);
-
- void resolutionChanged(const QSize &);
- void supportedResolutionsChanged();
-
-private slots:
- void _q_imageCaptured(int, const QImage&);
- void _q_imageSaved(int, const QString&);
- void _q_imageMetadataAvailable(int, const QString &, const QVariant &);
- void _q_captureFailed(int, QCameraImageCapture::Error, const QString&);
- void _q_cameraStatusChanged(QCamera::Status status);
-
-private:
- friend class QDeclarativeCamera;
- QDeclarativeCameraCapture(QCamera *camera, QObject *parent = 0);
-
- QCamera *m_camera;
- QCameraImageCapture *m_capture;
- QImageEncoderSettings m_imageSettings;
- QString m_capturedImagePath;
- QMetaDataWriterControl *m_metadataWriterControl;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeCameraCapture))
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativecameraexposure.cpp b/src/imports/multimedia/qdeclarativecameraexposure.cpp
deleted file mode 100644
index af8c6acf6..000000000
--- a/src/imports/multimedia/qdeclarativecameraexposure.cpp
+++ /dev/null
@@ -1,464 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativecamera_p.h"
-#include "qdeclarativecameraexposure_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype CameraExposure
- \instantiates QDeclarativeCameraExposure
- \brief An interface for exposure related camera settings.
- \ingroup multimedia_qml
- \ingroup camera_qml
- \inqmlmodule QtMultimedia
-
- CameraExposure allows you to adjust exposure related settings
- like aperture and shutter speed, metering and ISO speed.
-
- It should not be constructed separately, instead the
- \c exposure property of the a \l Camera should be used.
-
- \qml
-
- Camera {
- id: camera
-
- exposure.exposureCompensation: -1.0
- exposure.exposureMode: Camera.ExposurePortrait
- }
-
- \endqml
-
- Several settings have both an automatic and a manual mode. In
- the automatic modes the camera software itself will decide what
- a reasonable setting is, but in most cases these settings can
- be overridden with a specific manual setting.
-
- For example, to select automatic shutter speed selection:
-
- \code
- camera.exposure.setAutoShutterSpeed()
- \endcode
-
- Or for a specific shutter speed:
-
- \code
- camera.exposure.manualShutterSpeed = 0.01 // 10ms
- \endcode
-
- You can only choose one or the other mode.
-*/
-
-/*!
- \internal
- \class QDeclarativeCameraExposure
- \brief The CameraExposure provides interface for exposure related camera settings.
-
-*/
-
-/*!
- Construct a declarative camera exposure object using \a parent object.
- */
-QDeclarativeCameraExposure::QDeclarativeCameraExposure(QCamera *camera, QObject *parent) :
- QObject(parent)
-{
- m_exposure = camera->exposure();
-
- connect(m_exposure, SIGNAL(isoSensitivityChanged(int)), this, SIGNAL(isoSensitivityChanged(int)));
- connect(m_exposure, SIGNAL(apertureChanged(qreal)), this, SIGNAL(apertureChanged(qreal)));
- connect(m_exposure, SIGNAL(shutterSpeedChanged(qreal)), this, SIGNAL(shutterSpeedChanged(qreal)));
-
- connect(m_exposure, SIGNAL(exposureCompensationChanged(qreal)), this, SIGNAL(exposureCompensationChanged(qreal)));
- connect(camera, &QCamera::statusChanged, [this](QCamera::Status status) {
- if (status != QCamera::UnloadedStatus && status != QCamera::LoadedStatus
- && status != QCamera::ActiveStatus) {
- return;
- }
-
- emit supportedExposureModesChanged();
- });
-}
-
-QDeclarativeCameraExposure::~QDeclarativeCameraExposure()
-{
-}
-/*!
- \property QDeclarativeCameraExposure::exposureCompensation
-
- This property holds the adjustment value for the automatically calculated exposure. The value is in EV units.
- */
-/*!
- \qmlproperty real QtMultimedia::CameraExposure::exposureCompensation
-
- This property holds the adjustment value for the automatically calculated exposure. The value is
- in EV units.
- */
-qreal QDeclarativeCameraExposure::exposureCompensation() const
-{
- return m_exposure->exposureCompensation();
-}
-
-void QDeclarativeCameraExposure::setExposureCompensation(qreal ev)
-{
- m_exposure->setExposureCompensation(ev);
-}
-/*!
- \property QDeclarativeCameraExposure::iso
-
- This property holds the sensor's ISO sensitivity value.
- */
-/*!
- \qmlproperty int QtMultimedia::CameraExposure::iso
-
- This property holds the sensor's ISO sensitivity value.
- */
-int QDeclarativeCameraExposure::isoSensitivity() const
-{
- return m_exposure->isoSensitivity();
-}
-/*!
- \property QDeclarativeCameraExposure::shutterSpeed
-
- This property holds the camera's shutter speed value in seconds.
- To affect the shutter speed you can use the \l manualShutterSpeed
- property and \l setAutoShutterSpeed().
-
-*/
-/*!
- \qmlproperty real QtMultimedia::CameraExposure::shutterSpeed
-
- This property holds the camera's current shutter speed value in seconds.
- To affect the shutter speed you can use the \l manualShutterSpeed
- property and \l setAutoShutterSpeed().
-
-*/
-qreal QDeclarativeCameraExposure::shutterSpeed() const
-{
- return m_exposure->shutterSpeed();
-}
-/*!
- \property QDeclarativeCameraExposure::aperture
-
- This property holds the current lens aperture as an F number (the ratio of the focal length to effective aperture diameter).
-
- \sa manualAperture, setAutoAperture()
-*/
-/*!
- \qmlproperty real QtMultimedia::CameraExposure::aperture
-
- This property holds the current lens aperture as an F number (the ratio of
- the focal length to effective aperture diameter).
-
- \sa manualAperture, setAutoAperture()
-*/
-qreal QDeclarativeCameraExposure::aperture() const
-{
- return m_exposure->aperture();
-}
-/*!
- \property QDeclarativeCameraExposure::manualIso
-
- This property holds the ISO settings for capturing photos.
-
- If the value is negative, the camera will
- automatically determine an appropriate value.
-
- \sa iso, setAutoIsoSensitivity()
-*/
-/*!
- \qmlproperty real QtMultimedia::CameraExposure::manualIso
-
- This property holds the ISO settings for capturing photos.
-
- If a negative value is specified, the camera will
- automatically determine an appropriate value.
-
- \sa iso, setAutoIsoSensitivity()
-*/
-
-int QDeclarativeCameraExposure::manualIsoSensitivity() const
-{
- return m_manualIso;
-}
-
-void QDeclarativeCameraExposure::setManualIsoSensitivity(int iso)
-{
- m_manualIso = iso;
- if (iso > 0)
- m_exposure->setManualIsoSensitivity(iso);
- else
- m_exposure->setAutoIsoSensitivity();
-
- emit manualIsoSensitivityChanged(iso);
-}
-/*!
- \property QDeclarativeCameraExposure::manualShutterSpeed
-
- This property holds the shutter speed value (in seconds).
- If the value is less than zero, the camera automatically
- determines an appropriate shutter speed.
-
- \l shutterSpeed, setAutoShutterSpeed()
-*/
-/*!
- \qmlproperty real QtMultimedia::CameraExposure::manualShutterSpeed
-
- This property holds the shutter speed value (in seconds).
- If the value is less than zero, the camera automatically
- determines an appropriate shutter speed.
-
- \l shutterSpeed, setAutoShutterSpeed()
-*/
-qreal QDeclarativeCameraExposure::manualShutterSpeed() const
-{
- return m_manualShutterSpeed;
-}
-
-void QDeclarativeCameraExposure::setManualShutterSpeed(qreal speed)
-{
- m_manualShutterSpeed = speed;
- if (speed > 0)
- m_exposure->setManualShutterSpeed(speed);
- else
- m_exposure->setAutoShutterSpeed();
-
- emit manualShutterSpeedChanged(speed);
-}
-/*!
- \property QDeclarativeCameraExposure::manualAperture
-
- This property holds aperture (F number) value
- for capturing photos.
-
- If the value is less than zero,
- the camera automatically determines an appropriate aperture value.
-
- \l aperture, setAutoAperture()
-*/
-/*!
- \qmlproperty real QtMultimedia::CameraExposure::manualAperture
-
- This property holds the aperture (F number) value
- for capturing photos.
-
- If the value is less than zero, the camera automatically
- determines an appropriate aperture value.
-
- \l aperture, setAutoAperture()
-*/
-qreal QDeclarativeCameraExposure::manualAperture() const
-{
- return m_manualAperture;
-}
-
-void QDeclarativeCameraExposure::setManualAperture(qreal aperture)
-{
- m_manualAperture = aperture;
- if (aperture > 0)
- m_exposure->setManualAperture(aperture);
- else
- m_exposure->setAutoAperture();
-
- emit manualApertureChanged(aperture);
-}
-
-/*!
- \qmlmethod QtMultimedia::CameraExposure::setAutoAperture()
- Turn on auto aperture selection. The manual aperture value is reset to -1.0
- */
-void QDeclarativeCameraExposure::setAutoAperture()
-{
- setManualAperture(-1.0);
-}
-
-/*!
- \qmlmethod QtMultimedia::CameraExposure::setAutoShutterSpeed()
- Turn on auto shutter speed selection. The manual shutter speed value is reset to -1.0
- */
-void QDeclarativeCameraExposure::setAutoShutterSpeed()
-{
- setManualShutterSpeed(-1.0);
-}
-
-/*!
- \qmlmethod QtMultimedia::CameraExposure::setAutoIsoSensitivity()
- Turn on auto ISO sensitivity selection. The manual ISO value is reset to -1.
- */
-void QDeclarativeCameraExposure::setAutoIsoSensitivity()
-{
- setManualIsoSensitivity(-1);
-}
-/*!
- \property QDeclarativeCameraExposure::exposureMode
-
- This property holds the camera exposure mode. The mode can one of the values in \l QCameraExposure::ExposureMode.
-*/
-/*!
- \qmlproperty enumeration QtMultimedia::CameraExposure::exposureMode
-
- This property holds the camera exposure mode.
-
- The mode can be one of the following:
-
- \table
- \header \li Value \li Description
- \row \li Camera.ExposureManual \li Manual mode.
- \row \li Camera.ExposureAuto \li Automatic mode.
- \row \li Camera.ExposureNight \li Night mode.
- \row \li Camera.ExposureBacklight \li Backlight exposure mode.
- \row \li Camera.ExposureSpotlight \li Spotlight exposure mode.
- \row \li Camera.ExposureSports \li Spots exposure mode.
- \row \li Camera.ExposureSnow \li Snow exposure mode.
- \row \li Camera.ExposureBeach \li Beach exposure mode.
- \row \li Camera.ExposureLargeAperture \li Use larger aperture with small depth of field.
- \row \li Camera.ExposureSmallAperture \li Use smaller aperture.
- \row \li Camera.ExposurePortrait \li Portrait exposure mode.
- \row \li Camera.ExposureAction \li Action exposure mode. Since 5.5
- \row \li Camera.ExposureLandscape \li Landscape exposure mode. Since 5.5
- \row \li Camera.ExposureNightPortrait \li Night portrait exposure mode. Since 5.5
- \row \li Camera.ExposureTheatre \li Theatre exposure mode. Since 5.5
- \row \li Camera.ExposureSunset \li Sunset exposure mode. Since 5.5
- \row \li Camera.ExposureSteadyPhoto \li Steady photo exposure mode. Since 5.5
- \row \li Camera.ExposureFireworks \li Fireworks exposure mode. Since 5.5
- \row \li Camera.ExposureParty \li Party exposure mode. Since 5.5
- \row \li Camera.ExposureCandlelight \li Candlelight exposure mode. Since 5.5
- \row \li Camera.ExposureBarcode \li Barcode exposure mode. Since 5.5
- \row \li Camera.ExposureModeVendor \li The base value for device specific exposure modes.
- \endtable
-*/
-
-QDeclarativeCameraExposure::ExposureMode QDeclarativeCameraExposure::exposureMode() const
-{
- return QDeclarativeCameraExposure::ExposureMode(m_exposure->exposureMode());
-}
-
-void QDeclarativeCameraExposure::setExposureMode(QDeclarativeCameraExposure::ExposureMode mode)
-{
- if (exposureMode() != mode) {
- m_exposure->setExposureMode(QCameraExposure::ExposureMode(mode));
- emit exposureModeChanged(exposureMode());
- }
-}
-
-/*!
- \qmlproperty list<ExposureMode> QtMultimedia::CameraExposure::supportedExposureModes
-
- This property holds the supported exposure modes of the camera.
-
- \since 5.11
- \sa exposureMode
- */
-QVariantList QDeclarativeCameraExposure::supportedExposureModes() const
-{
- QVariantList supportedModes;
-
- for (int i = int(ExposureAuto); i <= int(QCameraExposure::ExposureBarcode); ++i) {
- if (m_exposure->isExposureModeSupported((QCameraExposure::ExposureMode) i))
- supportedModes.append(QVariant(i));
- }
-
- return supportedModes;
-}
-
-/*!
- \property QDeclarativeCameraExposure::spotMeteringPoint
-
- This property holds the relative frame coordinates of the point to use
- for exposure metering. This point is only used in spot metering mode, and it
- typically defaults to the center \c (0.5, 0.5).
- */
-/*!
- \qmlproperty QPointF QtMultimedia::CameraExposure::spotMeteringPoint
-
- The property holds the frame coordinates of the point to use for exposure metering.
- This point is only used in spot metering mode, and it typically defaults
- to the center \c (0.5, 0.5).
- */
-
-QPointF QDeclarativeCameraExposure::spotMeteringPoint() const
-{
- return m_exposure->spotMeteringPoint();
-}
-
-void QDeclarativeCameraExposure::setSpotMeteringPoint(const QPointF &point)
-{
- QPointF oldPoint(spotMeteringPoint());
- m_exposure->setSpotMeteringPoint(point);
-
- if (oldPoint != spotMeteringPoint())
- emit spotMeteringPointChanged(spotMeteringPoint());
-}
-/*!
- \property QDeclarativeCameraExposure::meteringMode
-
- This property holds the camera metering mode (how exposure is balanced).
- The mode can be one of the constants in \l QCameraExposure::MeteringMode.
-*/
-/*!
- \qmlproperty enumeration QtMultimedia::CameraExposure::meteringMode
-
- This property holds the camera metering mode (how exposure is balanced).
-
- The mode can be one of the following:
-
- \table
- \header \li Value \li Description
- \row \li Camera.MeteringMatrix \li A matrix of sample points is used to measure exposure.
- \row \li Camera.MeteringAverage \li An average is used to measure exposure.
- \row \li Camera.MeteringSpot \li A specific location (\l spotMeteringPoint) is used to measure exposure.
- \endtable
-*/
-QDeclarativeCameraExposure::MeteringMode QDeclarativeCameraExposure::meteringMode() const
-{
- return QDeclarativeCameraExposure::MeteringMode(m_exposure->meteringMode());
-}
-
-void QDeclarativeCameraExposure::setMeteringMode(QDeclarativeCameraExposure::MeteringMode mode)
-{
- QDeclarativeCameraExposure::MeteringMode oldMode = meteringMode();
- m_exposure->setMeteringMode(QCameraExposure::MeteringMode(mode));
- if (oldMode != meteringMode())
- emit meteringModeChanged(meteringMode());
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qdeclarativecameraexposure_p.cpp"
diff --git a/src/imports/multimedia/qdeclarativecameraexposure_p.h b/src/imports/multimedia/qdeclarativecameraexposure_p.h
deleted file mode 100644
index ef99b1ce9..000000000
--- a/src/imports/multimedia/qdeclarativecameraexposure_p.h
+++ /dev/null
@@ -1,177 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVECAMERAEXPOSURE_H
-#define QDECLARATIVECAMERAEXPOSURE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qdeclarativecamera_p.h"
-#include <qcamera.h>
-#include <qcameraexposure.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeCamera;
-
-class QDeclarativeCameraExposure : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(qreal exposureCompensation READ exposureCompensation WRITE setExposureCompensation NOTIFY exposureCompensationChanged)
-
- Q_PROPERTY(int iso READ isoSensitivity NOTIFY isoSensitivityChanged)
- Q_PROPERTY(qreal shutterSpeed READ shutterSpeed NOTIFY shutterSpeedChanged)
- Q_PROPERTY(qreal aperture READ aperture NOTIFY apertureChanged)
-
- Q_PROPERTY(qreal manualShutterSpeed READ manualShutterSpeed WRITE setManualShutterSpeed NOTIFY manualShutterSpeedChanged)
- Q_PROPERTY(qreal manualAperture READ manualAperture WRITE setManualAperture NOTIFY manualApertureChanged)
- Q_PROPERTY(qreal manualIso READ manualIsoSensitivity WRITE setManualIsoSensitivity NOTIFY manualIsoSensitivityChanged)
-
- Q_PROPERTY(ExposureMode exposureMode READ exposureMode WRITE setExposureMode NOTIFY exposureModeChanged)
- Q_PROPERTY(QVariantList supportedExposureModes READ supportedExposureModes NOTIFY supportedExposureModesChanged REVISION 1)
-
- Q_PROPERTY(QPointF spotMeteringPoint READ spotMeteringPoint WRITE setSpotMeteringPoint NOTIFY spotMeteringPointChanged)
- Q_PROPERTY(MeteringMode meteringMode READ meteringMode WRITE setMeteringMode NOTIFY meteringModeChanged)
-
- Q_ENUMS(ExposureMode)
- Q_ENUMS(MeteringMode)
-public:
- enum ExposureMode {
- ExposureAuto = QCameraExposure::ExposureAuto,
- ExposureManual = QCameraExposure::ExposureManual,
- ExposurePortrait = QCameraExposure::ExposurePortrait,
- ExposureNight = QCameraExposure::ExposureNight,
- ExposureBacklight = QCameraExposure::ExposureBacklight,
- ExposureSpotlight = QCameraExposure::ExposureSpotlight,
- ExposureSports = QCameraExposure::ExposureSports,
- ExposureSnow = QCameraExposure::ExposureSnow,
- ExposureBeach = QCameraExposure::ExposureBeach,
- ExposureLargeAperture = QCameraExposure::ExposureLargeAperture,
- ExposureSmallAperture = QCameraExposure::ExposureSmallAperture,
- ExposureAction = QCameraExposure::ExposureAction,
- ExposureLandscape = QCameraExposure::ExposureLandscape,
- ExposureNightPortrait = QCameraExposure::ExposureNightPortrait,
- ExposureTheatre = QCameraExposure::ExposureTheatre,
- ExposureSunset = QCameraExposure::ExposureSunset,
- ExposureSteadyPhoto = QCameraExposure::ExposureSteadyPhoto,
- ExposureFireworks = QCameraExposure::ExposureFireworks,
- ExposureParty = QCameraExposure::ExposureParty,
- ExposureCandlelight = QCameraExposure::ExposureCandlelight,
- ExposureBarcode = QCameraExposure::ExposureBarcode,
- ExposureModeVendor = QCameraExposure::ExposureModeVendor
- };
-
- enum MeteringMode {
- MeteringMatrix = QCameraExposure::MeteringMatrix,
- MeteringAverage = QCameraExposure::MeteringAverage,
- MeteringSpot = QCameraExposure::MeteringSpot
- };
-
- ~QDeclarativeCameraExposure();
-
- ExposureMode exposureMode() const;
- QVariantList supportedExposureModes() const;
- qreal exposureCompensation() const;
-
- int isoSensitivity() const;
- qreal shutterSpeed() const;
- qreal aperture() const;
-
- int manualIsoSensitivity() const;
- qreal manualShutterSpeed() const;
- qreal manualAperture() const;
-
- QPointF spotMeteringPoint() const;
- void setSpotMeteringPoint(const QPointF &point);
-
- MeteringMode meteringMode() const;
- void setMeteringMode(MeteringMode mode);
-
-public Q_SLOTS:
- void setExposureMode(ExposureMode);
- void setExposureCompensation(qreal ev);
-
- void setManualAperture(qreal);
- void setManualShutterSpeed(qreal);
- void setManualIsoSensitivity(int iso);
-
- void setAutoAperture();
- void setAutoShutterSpeed();
- void setAutoIsoSensitivity();
-
-Q_SIGNALS:
- void isoSensitivityChanged(int);
- void apertureChanged(qreal);
- void shutterSpeedChanged(qreal);
-
- void manualIsoSensitivityChanged(int);
- void manualApertureChanged(qreal);
- void manualShutterSpeedChanged(qreal);
-
- void exposureCompensationChanged(qreal);
- void exposureModeChanged(ExposureMode);
- void supportedExposureModesChanged();
-
- void meteringModeChanged(MeteringMode);
- void spotMeteringPointChanged(QPointF);
-
-private:
- friend class QDeclarativeCamera;
- QDeclarativeCameraExposure(QCamera *camera, QObject *parent = 0);
-
- QCameraExposure *m_exposure;
- int m_manualIso;
- qreal m_manualAperture;
- qreal m_manualShutterSpeed;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeCameraExposure))
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativecameraflash.cpp b/src/imports/multimedia/qdeclarativecameraflash.cpp
deleted file mode 100644
index 5ce4a5d06..000000000
--- a/src/imports/multimedia/qdeclarativecameraflash.cpp
+++ /dev/null
@@ -1,198 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativecamera_p.h"
-#include "qdeclarativecameraflash_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype CameraFlash
- \instantiates QDeclarativeCameraFlash
- \inqmlmodule QtMultimedia
- \brief An interface for flash related camera settings.
- \ingroup multimedia_qml
- \ingroup camera_qml
-
- This type allows you to operate the camera flash
- hardware and control the flash mode used. Not all cameras have
- flash hardware (and in some cases it is shared with the
- \l {Torch}{torch} hardware).
-
- It should not be constructed separately, instead the
- \c flash property of a \l Camera should be used.
-
- \qml
-
- Camera {
- id: camera
-
- exposure.exposureCompensation: -1.0
- flash.mode: Camera.FlashRedEyeReduction
- }
-
- \endqml
-*/
-
-/*!
- Construct a declarative camera flash object using \a parent object.
- */
-QDeclarativeCameraFlash::QDeclarativeCameraFlash(QCamera *camera, QObject *parent)
- : QObject(parent)
-{
- m_exposure = camera->exposure();
- connect(m_exposure, SIGNAL(flashReady(bool)), this, SIGNAL(flashReady(bool)));
- connect(camera, SIGNAL(statusChanged(QCamera::Status)),
- this, SLOT(_q_cameraStatusChanged(QCamera::Status)));
-}
-
-QDeclarativeCameraFlash::~QDeclarativeCameraFlash()
-{
-}
-
-/*!
- \qmlproperty bool QtMultimedia::CameraFlash::ready
-
- This property indicates whether the flash is charged.
-*/
-bool QDeclarativeCameraFlash::isFlashReady() const
-{
- return m_exposure->isFlashReady();
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::CameraFlash::mode
-
- This property holds the camera flash mode.
-
- The mode can be one of the following:
- \table
- \header \li Value \li Description
- \row \li Camera.FlashOff \li Flash is Off.
- \row \li Camera.FlashOn \li Flash is On.
- \row \li Camera.FlashAuto \li Automatic flash.
- \row \li Camera.FlashRedEyeReduction \li Red eye reduction flash.
- \row \li Camera.FlashFill \li Use flash to fillin shadows.
- \row \li Camera.FlashTorch \li Constant light source. If supported, torch can be
- enabled without loading the camera.
- \row \li Camera.FlashVideoLight \li Constant light source, useful for video capture.
- The light is turned on only while the camera is active.
- \row \li Camera.FlashSlowSyncFrontCurtain
- \li Use the flash in conjunction with a slow shutter speed.
- This mode allows better exposure of distant objects and/or motion blur effect.
- \row \li Camera.FlashSlowSyncRearCurtain
- \li The similar mode to FlashSlowSyncFrontCurtain but flash is fired at the end of exposure.
- \row \li Camera.FlashManual \li Flash power is manually set.
- \endtable
-
-*/
-QDeclarativeCameraFlash::FlashMode QDeclarativeCameraFlash::flashMode() const
-{
- return QDeclarativeCameraFlash::FlashMode(int(m_exposure->flashMode()));
-}
-
-void QDeclarativeCameraFlash::setFlashMode(QDeclarativeCameraFlash::FlashMode mode)
-{
- if (flashMode() != mode) {
- m_exposure->setFlashMode(QCameraExposure::FlashModes(mode));
- emit flashModeChanged(mode);
- }
-}
-
-void QDeclarativeCameraFlash::_q_cameraStatusChanged(QCamera::Status status)
-{
- if (status != QCamera::UnloadedStatus && status != QCamera::LoadedStatus &&
- status != QCamera::ActiveStatus)
- return;
-
- emit supportedModesChanged();
-}
-
-/*!
- \qmlproperty list<FlashMode> QtMultimedia::CameraFlash::supportedModes
-
- This property holds the supported flash modes of the camera. If the list
- only contains Camera.FlashOff, no flash is supported.
-
- \code
- Camera {
- id: camera
- flash {
- onSupportedModesChanged {
- if (flash.supportedModes.length == 1) {
- // no flash supported
- } else {
- // some flash is supported
- }
- }
- }
- }
- \endcode
-
- \since 5.9
- \sa mode
- */
-QVariantList QDeclarativeCameraFlash::supportedModes() const
-{
- QVariantList supportedModes;
-
- for (int i=1; i <= (int) QCameraExposure::FlashManual; i = (i << 1)) {
- if (m_exposure->isFlashModeSupported((QCameraExposure::FlashMode) i))
- supportedModes.append(QVariant(i));
- }
-
- return supportedModes;
-}
-
-/*!
- \qmlsignal QtMultimedia::CameraFlash::flashModeChanged()
- This signal is emitted when the \c flashMode property is changed.
- The corresponding handler is \c onFlashModeChanged.
-*/
-
-/*!
- \qmlsignal QtMultimedia::CameraFlash::flashReady()
- This signal is emitted when QCameraExposure indicates that
- the flash is ready to use.
- The corresponding handler is \c onFlashReadyChanged.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qdeclarativecameraflash_p.cpp"
diff --git a/src/imports/multimedia/qdeclarativecameraflash_p.h b/src/imports/multimedia/qdeclarativecameraflash_p.h
deleted file mode 100644
index df037c4d6..000000000
--- a/src/imports/multimedia/qdeclarativecameraflash_p.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVECAMERAFLASH_H
-#define QDECLARATIVECAMERAFLASH_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <qcamera.h>
-#include <qcameraexposure.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeCamera;
-
-class QDeclarativeCameraFlash : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(bool ready READ isFlashReady NOTIFY flashReady)
- Q_PROPERTY(FlashMode mode READ flashMode WRITE setFlashMode NOTIFY flashModeChanged)
- Q_PROPERTY(QVariantList supportedModes READ supportedModes NOTIFY supportedModesChanged REVISION 1)
-
- Q_ENUMS(FlashMode)
-public:
- enum FlashMode {
- FlashAuto = QCameraExposure::FlashAuto,
- FlashOff = QCameraExposure::FlashOff,
- FlashOn = QCameraExposure::FlashOn,
- FlashRedEyeReduction = QCameraExposure::FlashRedEyeReduction,
- FlashFill = QCameraExposure::FlashFill,
- FlashTorch = QCameraExposure::FlashTorch,
- FlashVideoLight = QCameraExposure::FlashVideoLight,
- FlashSlowSyncFrontCurtain = QCameraExposure::FlashSlowSyncFrontCurtain,
- FlashSlowSyncRearCurtain = QCameraExposure::FlashSlowSyncRearCurtain,
- FlashManual = QCameraExposure::FlashManual
- };
-
- ~QDeclarativeCameraFlash();
-
- FlashMode flashMode() const;
- bool isFlashReady() const;
- QVariantList supportedModes() const;
-
-public Q_SLOTS:
- void setFlashMode(FlashMode);
-
-Q_SIGNALS:
- void flashReady(bool status);
- void flashModeChanged(FlashMode);
- void supportedModesChanged();
-
-private slots:
- void _q_cameraStatusChanged(QCamera::Status status);
-
-private:
- friend class QDeclarativeCamera;
- QDeclarativeCameraFlash(QCamera *camera, QObject *parent = 0);
-
- QCameraExposure *m_exposure;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeCameraFlash))
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativecamerafocus.cpp b/src/imports/multimedia/qdeclarativecamerafocus.cpp
deleted file mode 100644
index d8fb62d9a..000000000
--- a/src/imports/multimedia/qdeclarativecamerafocus.cpp
+++ /dev/null
@@ -1,413 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativecamera_p.h"
-#include "qdeclarativecamerafocus_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype CameraFocus
- \instantiates QDeclarativeCameraFocus
- \inqmlmodule QtMultimedia
- \brief An interface for focus related camera settings.
- \ingroup multimedia_qml
- \ingroup camera_qml
-
- This type allows control over manual and automatic
- focus settings, including information about any parts of the
- camera frame that are selected for autofocusing.
-
- It should not be constructed separately, instead the
- \c focus property of a \l Camera should be used.
-
- \qml
-
- Item {
- width: 640
- height: 360
-
- Camera {
- id: camera
-
- focus {
- focusMode: Camera.FocusMacro
- focusPointMode: Camera.FocusPointCustom
- customFocusPoint: Qt.point(0.2, 0.2) // Focus relative to top-left corner
- }
- }
-
- VideoOutput {
- source: camera
- anchors.fill: parent
- }
- }
-
- \endqml
-*/
-
-/*!
- \class QDeclarativeCameraFocus
- \internal
- \brief An interface for focus related camera settings.
-*/
-
-/*!
- Construct a declarative camera focus object using \a parent object.
- */
-
-QDeclarativeCameraFocus::QDeclarativeCameraFocus(QCamera *camera, QObject *parent) :
- QObject(parent)
-{
- m_focus = camera->focus();
- m_focusZones = new FocusZonesModel(this);
-
- updateFocusZones();
-
- connect(m_focus, SIGNAL(focusZonesChanged()), SLOT(updateFocusZones()));
- connect(camera, &QCamera::statusChanged, [this](QCamera::Status status) {
- if (status != QCamera::UnloadedStatus && status != QCamera::LoadedStatus
- && status != QCamera::ActiveStatus) {
- return;
- }
-
- emit supportedFocusModesChanged();
- emit supportedFocusPointModesChanged();
- });
-}
-
-QDeclarativeCameraFocus::~QDeclarativeCameraFocus()
-{
-}
-/*!
- \property QDeclarativeCameraFocus::focusMode
-
- This property holds the current camera focus mode.
-
- It's possible to combine multiple QCameraFocus::FocusMode enum values,
- for example QCameraFocus::MacroFocus + QCameraFocus::ContinuousFocus.
-
- In automatic focusing modes, the \l focusPointMode
- and \l focusZones properties provide information and control
- over how automatic focusing is performed.
-*/
-
-/*!
- \qmlproperty enumeration CameraFocus::focusMode
-
- This property holds the current camera focus mode, which can be one of the following values:
-
- \table
- \header
- \li Value
- \li Description
- \row
- \li FocusManual
- \li Manual or fixed focus mode.
- \row
- \li FocusHyperfocal
- \li Focus to hyperfocal distance, with the maximum depth of field achieved. All objects at distances from half of this distance out to infinity will be acceptably sharp.
- \row
- \li FocusInfinity
- \li Focus strictly to infinity.
- \row
- \li FocusAuto
- \li One-shot auto focus mode.
- \row
- \li FocusContinuous
- \li Continuous auto focus mode.
- \row
- \li FocusMacro
- \li One shot auto focus to objects close to camera.
- \endtable
-
- It's possible to combine multiple Camera::FocusMode values,
- for example Camera.FocusMacro + Camera.FocusContinuous.
-
- In automatic focusing modes, the \l focusPointMode property
- and \l focusZones property provide information and control
- over how automatic focusing is performed.
-*/
-QDeclarativeCameraFocus::FocusMode QDeclarativeCameraFocus::focusMode() const
-{
- return QDeclarativeCameraFocus::FocusMode(int(m_focus->focusMode()));
-}
-
-/*!
- \qmlproperty list<FocusMode> CameraFocus::supportedFocusModes
-
- This property holds the supported focus modes of the camera.
-
- \since 5.11
- \sa focusMode
-*/
-QVariantList QDeclarativeCameraFocus::supportedFocusModes() const
-{
- QVariantList supportedModes;
-
- for (int i = int(FocusManual); i <= int(FocusMacro); ++i) {
- if (m_focus->isFocusModeSupported((QCameraFocus::FocusMode) i))
- supportedModes.append(i);
- }
-
- return supportedModes;
-}
-
-void QDeclarativeCameraFocus::setFocusMode(QDeclarativeCameraFocus::FocusMode mode)
-{
- if (mode != focusMode()) {
- m_focus->setFocusMode(QCameraFocus::FocusModes(int(mode)));
- emit focusModeChanged(focusMode());
- }
-}
-/*!
- \property QDeclarativeCameraFocus::focusPointMode
-
- This property holds the current camera focus point mode. It is used in
- automatic focusing modes to determine what to focus on.
-
- If the current focus point mode is \l QCameraFocus::FocusPointCustom, the
- \l customFocusPoint property allows you to specify which part of
- the frame to focus on.
-*/
-/*!
- \qmlproperty enumeration CameraFocus::focusPointMode
-
- This property holds the current camera focus point mode. It is used in automatic
- focusing modes to determine what to focus on. If the current
- focus point mode is \c Camera.FocusPointCustom, the \l customFocusPoint
- property allows you to specify which part of the frame to focus on.
-
- The property can take one of the following values:
- \table
- \header
- \li Value
- \li Description
- \row
- \li FocusPointAuto
- \li Automatically select one or multiple focus points.
- \row
- \li FocusPointCenter
- \li Focus to the frame center.
- \row
- \li FocusPointFaceDetection
- \li Focus on faces in the frame.
- \row
- \li FocusPointCustom
- \li Focus to the custom point, defined by the customFocusPoint property.
- \endtable
-*/
-QDeclarativeCameraFocus::FocusPointMode QDeclarativeCameraFocus::focusPointMode() const
-{
- return QDeclarativeCameraFocus::FocusPointMode(m_focus->focusPointMode());
-}
-
-/*!
- \qmlproperty list<enumeration> CameraFocus::supportedFocusPointModes
-
- This property holds the supported focus point modes of the camera.
-
- \since 5.10
- \sa focusPointMode
-*/
-QVariantList QDeclarativeCameraFocus::supportedFocusPointModes() const
-{
- QVariantList supportedModes;
-
- for (int i = int(FocusPointAuto); i <= int(FocusPointCustom); i++) {
- if (m_focus->isFocusPointModeSupported(QCameraFocus::FocusPointMode(i)))
- supportedModes.append(i);
- }
-
- return supportedModes;
-}
-
-void QDeclarativeCameraFocus::setFocusPointMode(QDeclarativeCameraFocus::FocusPointMode mode)
-{
- if (mode != focusPointMode()) {
- m_focus->setFocusPointMode(QCameraFocus::FocusPointMode(mode));
- emit focusPointModeChanged(focusPointMode());
- }
-}
-
-/*!
- \property QDeclarativeCameraFocus::customFocusPoint
-
- This property holds the position of the custom focus point in relative
- frame coordinates. For example, QPointF(0,0) pointing to the left top corner of the frame, and QPointF(0.5,0.5)
- pointing to the center of the frame.
-
- Custom focus point is used only in QCameraFocus::FocusPointCustom focus mode.
-*/
-
-/*!
- \qmlproperty point QtMultimedia::CameraFocus::customFocusPoint
-
- This property holds the position of custom focus point, in relative frame coordinates:
- QPointF(0,0) points to the left top frame point, QPointF(0.5,0.5)
- points to the frame center.
-
- Custom focus point is used only in FocusPointCustom focus mode.
-*/
-
-QPointF QDeclarativeCameraFocus::customFocusPoint() const
-{
- return m_focus->customFocusPoint();
-}
-
-void QDeclarativeCameraFocus::setCustomFocusPoint(const QPointF &point)
-{
- if (point != customFocusPoint()) {
- m_focus->setCustomFocusPoint(point);
- emit customFocusPointChanged(customFocusPoint());
- }
-}
-/*!
- \property QDeclarativeCameraFocus::focusZones
-
- This property holds the list of current camera focus zones,
- each including \c area specified in the same coordinates as \l customFocusPoint, and zone \c status as one of the following values:
- \table
- \header \li Value \li Description
- \row \li QCameraFocusZone::Unused \li This focus point area is currently unused in autofocusing.
- \row \li QCameraFocusZone::Selected \li This focus point area is used in autofocusing, but is not in focus.
- \row \li QCameraFocusZone::Focused \li This focus point is used in autofocusing, and is in focus.
- \endtable
-*/
-/*!
- \qmlproperty list<focusZone> QtMultimedia::CameraFocus::focusZones
-
- This property holds the list of current camera focus zones,
- each including \c area specified in the same coordinates as \l customFocusPoint,
- and zone \c status as one of the following values:
-
- \table
- \header \li Value \li Description
- \row \li Camera.FocusAreaUnused \li This focus point area is currently unused in autofocusing.
- \row \li Camera.FocusAreaSelected \li This focus point area is used in autofocusing, but is not in focus.
- \row \li Camera.FocusAreaFocused \li This focus point is used in autofocusing, and is in focus.
- \endtable
-
- \qml
-
- VideoOutput {
- id: viewfinder
- source: camera
-
- //display focus areas on camera viewfinder:
- Repeater {
- model: camera.focus.focusZones
-
- Rectangle {
- border {
- width: 2
- color: status == Camera.FocusAreaFocused ? "green" : "white"
- }
- color: "transparent"
-
- // Map from the relative, normalized frame coordinates
- property variant mappedRect: viewfinder.mapNormalizedRectToItem(area);
-
- x: mappedRect.x
- y: mappedRect.y
- width: mappedRect.width
- height: mappedRect.height
- }
- }
- }
- \endqml
-*/
-
-QAbstractListModel *QDeclarativeCameraFocus::focusZones() const
-{
- return m_focusZones;
-}
-
-/*! \internal */
-void QDeclarativeCameraFocus::updateFocusZones()
-{
- m_focusZones->setFocusZones(m_focus->focusZones());
-}
-
-
-FocusZonesModel::FocusZonesModel(QObject *parent)
- :QAbstractListModel(parent)
-{
-}
-
-int FocusZonesModel::rowCount(const QModelIndex &parent) const
-{
- if (parent == QModelIndex())
- return m_focusZones.count();
-
- return 0;
-}
-
-QVariant FocusZonesModel::data(const QModelIndex &index, int role) const
-{
- if (index.row() < 0 || index.row() > m_focusZones.count())
- return QVariant();
-
- QCameraFocusZone zone = m_focusZones.value(index.row());
-
- if (role == StatusRole)
- return zone.status();
-
- if (role == AreaRole)
- return zone.area();
-
- return QVariant();
-}
-
-QHash<int,QByteArray> FocusZonesModel::roleNames() const
-{
- return {{StatusRole, QByteArrayLiteral("status")},
- {AreaRole, QByteArrayLiteral("area")}};
-}
-
-void FocusZonesModel::setFocusZones(const QCameraFocusZoneList &zones)
-{
- beginResetModel();
- m_focusZones = zones;
- endResetModel();
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qdeclarativecamerafocus_p.cpp"
diff --git a/src/imports/multimedia/qdeclarativecamerafocus_p.h b/src/imports/multimedia/qdeclarativecamerafocus_p.h
deleted file mode 100644
index df2514f13..000000000
--- a/src/imports/multimedia/qdeclarativecamerafocus_p.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVECAMERAFOCUS_H
-#define QDECLARATIVECAMERAFOCUS_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qabstractitemmodel.h>
-#include <qcamera.h>
-#include <qcamerafocus.h>
-#include "qdeclarativecamera_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class FocusZonesModel;
-class QDeclarativeCamera;
-
-class QDeclarativeCameraFocus : public QObject
-{
- Q_OBJECT
-
- Q_PROPERTY(FocusMode focusMode READ focusMode WRITE setFocusMode NOTIFY focusModeChanged)
- Q_PROPERTY(QVariantList supportedFocusModes READ supportedFocusModes NOTIFY supportedFocusModesChanged REVISION 1)
-
- Q_PROPERTY(FocusPointMode focusPointMode READ focusPointMode WRITE setFocusPointMode NOTIFY focusPointModeChanged)
- Q_PROPERTY(QVariantList supportedFocusPointModes READ supportedFocusPointModes NOTIFY supportedFocusPointModesChanged REVISION 1)
-
- Q_PROPERTY(QPointF customFocusPoint READ customFocusPoint WRITE setCustomFocusPoint NOTIFY customFocusPointChanged)
- Q_PROPERTY(QObject *focusZones READ focusZones CONSTANT)
-
- Q_ENUMS(FocusMode)
- Q_ENUMS(FocusPointMode)
-public:
- enum FocusMode {
- FocusManual = QCameraFocus::ManualFocus,
- FocusHyperfocal = QCameraFocus::HyperfocalFocus,
- FocusInfinity = QCameraFocus::InfinityFocus,
- FocusAuto = QCameraFocus::AutoFocus,
- FocusContinuous = QCameraFocus::ContinuousFocus,
- FocusMacro = QCameraFocus::MacroFocus
- };
-
- enum FocusPointMode {
- FocusPointAuto = QCameraFocus::FocusPointAuto,
- FocusPointCenter = QCameraFocus::FocusPointCenter,
- FocusPointFaceDetection = QCameraFocus::FocusPointFaceDetection,
- FocusPointCustom = QCameraFocus::FocusPointCustom
- };
-
- ~QDeclarativeCameraFocus();
-
- FocusMode focusMode() const;
- QVariantList supportedFocusModes() const;
-
- FocusPointMode focusPointMode() const;
- QVariantList supportedFocusPointModes() const;
-
- QPointF customFocusPoint() const;
- QAbstractListModel *focusZones() const;
-
-public Q_SLOTS:
- void setFocusMode(FocusMode);
- void setFocusPointMode(FocusPointMode mode);
- void setCustomFocusPoint(const QPointF &point);
-
-Q_SIGNALS:
- void focusModeChanged(FocusMode);
- void supportedFocusModesChanged();
- void focusPointModeChanged(FocusPointMode);
- void supportedFocusPointModesChanged();
- void customFocusPointChanged(const QPointF &);
-
-private Q_SLOTS:
- void updateFocusZones();
-
-private:
- friend class QDeclarativeCamera;
- QDeclarativeCameraFocus(QCamera *camera, QObject *parent = 0);
-
- QCameraFocus *m_focus;
- FocusZonesModel *m_focusZones;
-};
-
-class FocusZonesModel : public QAbstractListModel
-{
-Q_OBJECT
-public:
- enum FocusZoneRoles {
- StatusRole = Qt::UserRole + 1,
- AreaRole
- };
-
- FocusZonesModel(QObject *parent = 0);
-
- int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
- QHash<int,QByteArray> roleNames() const override;
-
-public slots:
- void setFocusZones(const QCameraFocusZoneList &zones);
-
-private:
- QCameraFocusZoneList m_focusZones;
-};
-
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeCameraFocus))
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativecameraimageprocessing.cpp b/src/imports/multimedia/qdeclarativecameraimageprocessing.cpp
deleted file mode 100644
index 908afea27..000000000
--- a/src/imports/multimedia/qdeclarativecameraimageprocessing.cpp
+++ /dev/null
@@ -1,361 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativecamera_p.h"
-#include "qdeclarativecameraimageprocessing_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype CameraImageProcessing
- \instantiates QDeclarativeCameraImageProcessing
- \inqmlmodule QtMultimedia
- \brief An interface for camera capture related settings.
- \ingroup multimedia_qml
- \ingroup camera_qml
-
- CameraImageProcessing provides control over post-processing
- done by the camera middleware, including white balance adjustments,
- contrast, saturation, sharpening, and denoising
-
- It should not be constructed separately, instead the
- \c imageProcessing property of a \l Camera should be used.
-
- \qml
-
- Camera {
- id: camera
-
- imageProcessing {
- whiteBalanceMode: Camera.WhiteBalanceTungsten
- contrast: 0.66
- saturation: -0.5
- }
- }
-
- \endqml
-
-
-*/
-/*!
- \class QDeclarativeCameraImageProcessing
- \internal
- \brief The CameraCapture provides an interface for camera capture related settings
-*/
-
-
-QDeclarativeCameraImageProcessing::QDeclarativeCameraImageProcessing(QCamera *camera, QObject *parent) :
- QObject(parent)
-{
- m_imageProcessing = camera->imageProcessing();
-
- connect(camera, QOverload<bool>::of(&QCamera::availabilityChanged),
- this, &QDeclarativeCameraImageProcessing::availableChanged);
- connect(camera, &QCamera::statusChanged, [this](QCamera::Status status) {
- if (status != QCamera::UnloadedStatus && status != QCamera::LoadedStatus
- && status != QCamera::ActiveStatus) {
- return;
- }
-
- emit supportedColorFiltersChanged();
- emit supportedWhiteBalanceModesChanged();
- });
-}
-
-QDeclarativeCameraImageProcessing::~QDeclarativeCameraImageProcessing()
-{
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::CameraImageProcessing::whiteBalanceMode
-
- \table
- \header \li Value \li Description
- \row \li WhiteBalanceManual \li Manual white balance. In this mode the manual white balance property value is used.
- \row \li WhiteBalanceAuto \li Auto white balance mode.
- \row \li WhiteBalanceSunlight \li Sunlight white balance mode.
- \row \li WhiteBalanceCloudy \li Cloudy white balance mode.
- \row \li WhiteBalanceShade \li Shade white balance mode.
- \row \li WhiteBalanceTungsten \li Tungsten white balance mode.
- \row \li WhiteBalanceFluorescent \li Fluorescent white balance mode.
- \row \li WhiteBalanceFlash \li Flash white balance mode.
- \row \li WhiteBalanceSunset \li Sunset white balance mode.
- \row \li WhiteBalanceVendor \li Vendor defined white balance mode.
- \endtable
-
- \sa manualWhiteBalance
-*/
-QDeclarativeCameraImageProcessing::WhiteBalanceMode QDeclarativeCameraImageProcessing::whiteBalanceMode() const
-{
- return WhiteBalanceMode(m_imageProcessing->whiteBalanceMode());
-}
-
-void QDeclarativeCameraImageProcessing::setWhiteBalanceMode(QDeclarativeCameraImageProcessing::WhiteBalanceMode mode) const
-{
- if (whiteBalanceMode() != mode) {
- m_imageProcessing->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode(mode));
- emit whiteBalanceModeChanged(whiteBalanceMode());
- }
-}
-
-/*!
- \qmlproperty qreal QtMultimedia::CameraImageProcessing::manualWhiteBalance
-
- The color temperature used when in manual white balance mode (WhiteBalanceManual).
- The units are Kelvin.
-
- \sa whiteBalanceMode
-*/
-qreal QDeclarativeCameraImageProcessing::manualWhiteBalance() const
-{
- return m_imageProcessing->manualWhiteBalance();
-}
-
-void QDeclarativeCameraImageProcessing::setManualWhiteBalance(qreal colorTemp) const
-{
- if (manualWhiteBalance() != colorTemp) {
- m_imageProcessing->setManualWhiteBalance(colorTemp);
- emit manualWhiteBalanceChanged(manualWhiteBalance());
- }
-}
-
-/*!
- \qmlproperty qreal QtMultimedia::CameraImageProcessing::brightness
-
- Image brightness adjustment.
- Valid brightness adjustment values range between -1.0 and 1.0, with a default of 0.
-
- \since 5.7
-*/
-qreal QDeclarativeCameraImageProcessing::brightness() const
-{
- return m_imageProcessing->brightness();
-}
-
-void QDeclarativeCameraImageProcessing::setBrightness(qreal value)
-{
- if (value != brightness()) {
- m_imageProcessing->setBrightness(value);
- emit brightnessChanged(brightness());
- }
-}
-
-/*!
- \qmlproperty qreal QtMultimedia::CameraImageProcessing::contrast
-
- Image contrast adjustment.
- Valid contrast adjustment values range between -1.0 and 1.0, with a default of 0.
-*/
-qreal QDeclarativeCameraImageProcessing::contrast() const
-{
- return m_imageProcessing->contrast();
-}
-
-void QDeclarativeCameraImageProcessing::setContrast(qreal value)
-{
- if (value != contrast()) {
- m_imageProcessing->setContrast(value);
- emit contrastChanged(contrast());
- }
-}
-
-/*!
- \qmlproperty qreal QtMultimedia::CameraImageProcessing::saturation
-
- Image saturation adjustment.
- Valid saturation adjustment values range between -1.0 and 1.0, the default is 0.
-*/
-qreal QDeclarativeCameraImageProcessing::saturation() const
-{
- return m_imageProcessing->saturation();
-}
-
-void QDeclarativeCameraImageProcessing::setSaturation(qreal value)
-{
- if (value != saturation()) {
- m_imageProcessing->setSaturation(value);
- emit saturationChanged(saturation());
- }
-}
-
-/*!
- \qmlproperty qreal QtMultimedia::CameraImageProcessing::sharpeningLevel
-
- Adjustment of sharpening level applied to image.
-
- Valid sharpening level values range between -1.0 for for sharpening disabled,
- 0 for default sharpening level and 1.0 for maximum sharpening applied.
-*/
-qreal QDeclarativeCameraImageProcessing::sharpeningLevel() const
-{
- return m_imageProcessing->sharpeningLevel();
-}
-
-void QDeclarativeCameraImageProcessing::setSharpeningLevel(qreal value)
-{
- if (value != sharpeningLevel()) {
- m_imageProcessing->setSharpeningLevel(value);
- emit sharpeningLevelChanged(sharpeningLevel());
- }
-}
-
-/*!
- \qmlproperty qreal QtMultimedia::CameraImageProcessing::denoisingLevel
-
- Adjustment of denoising applied to image.
-
- Valid denoising level values range between -1.0 for for denoising disabled,
- 0 for default denoising level and 1.0 for maximum denoising applied.
-*/
-qreal QDeclarativeCameraImageProcessing::denoisingLevel() const
-{
- return m_imageProcessing->denoisingLevel();
-}
-
-void QDeclarativeCameraImageProcessing::setDenoisingLevel(qreal value)
-{
- if (value != denoisingLevel()) {
- m_imageProcessing->setDenoisingLevel(value);
- emit denoisingLevelChanged(denoisingLevel());
- }
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::CameraImageProcessing::colorFilter
-
- This property holds which color filter if any will be applied to image data captured by the camera.
-
- It can be one of:
-
- \table
- \row \li CameraImageProcessing.ColorFilterNone \li No filter is applied to images.
- \row \li CameraImageProcessing.ColorFilterGrayscale \li A grayscale filter.
- \row \li CameraImageProcessing.ColorFilterNegative \li A negative filter.
- \row \li CameraImageProcessing.ColorFilterSolarize \li A solarize filter.
- \row \li CameraImageProcessing.ColorFilterSepia \li A sepia filter.
- \row \li CameraImageProcessing.ColorFilterPosterize \li A posterize filter.
- \row \li CameraImageProcessing.ColorFilterWhiteboard \li A whiteboard filter.
- \row \li CameraImageProcessing.ColorFilterBlackboard \li A blackboard filter.
- \row \li CameraImageProcessing.ColorFilterAqua \li An aqua filter.
- \row \li CameraImageProcessing.ColorFilterVendor \li The base value for vendor defined filters.
- \endtable
-
- \since 5.5
-*/
-
-QDeclarativeCameraImageProcessing::ColorFilter QDeclarativeCameraImageProcessing::colorFilter() const
-{
- return ColorFilter(m_imageProcessing->colorFilter());
-}
-
-/*!
- \qmlproperty bool QtMultimedia::CameraImageProcessing::isAvailable
-
- This property holds if image processing related settings are supported by this camera.
-
- \since 5.11
-*/
-bool QDeclarativeCameraImageProcessing::isAvailable() const
-{
- return m_imageProcessing->isAvailable();
-}
-
-/*!
- \qmlproperty list<ColorFilter> QtMultimedia::CameraImageProcessing::supportedColorFilters
-
- This property holds the supported color filters by this camera.
-
- \since 5.11
-*/
-QVariantList QDeclarativeCameraImageProcessing::supportedColorFilters() const
-{
- QVariantList supportedFilters;
-
- for (int i = int(ColorFilterNone); i <= int(ColorFilterVendor); ++i) {
- if (m_imageProcessing->isColorFilterSupported((QCameraImageProcessing::ColorFilter) i))
- supportedFilters.append(i);
- }
-
- return supportedFilters;
-}
-
-/*!
- \qmlproperty list<WhiteBalanceMode> QtMultimedia::CameraImageProcessing::supportedWhiteBalanceModes
-
- This property holds the supported white balance modes by this camera.
-
- \since 5.11
-*/
-QVariantList QDeclarativeCameraImageProcessing::supportedWhiteBalanceModes() const
-{
- QVariantList supportedModes;
-
- for (int i = int(WhiteBalanceAuto); i <= int(WhiteBalanceVendor); i++) {
- if (m_imageProcessing->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode(i)))
- supportedModes.append(i);
- }
-
- return supportedModes;
-}
-
-void QDeclarativeCameraImageProcessing::setColorFilter(ColorFilter filter)
-{
- if (this->colorFilter() != filter) {
- m_imageProcessing->setColorFilter(QCameraImageProcessing::ColorFilter(filter));
- emit colorFilterChanged();
- }
-}
-
-/*!
- \qmlsignal QtMultimedia::Camera::whiteBalanceModeChanged()
- This signal is emitted when the \c whiteBalanceMode property is changed.
-
- The corresponding handler is \c onWhiteBalanceModeChanged.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Camera::manualWhiteBalanceChanged()
- This signal is emitted when the \c manualWhiteBalance property is changed.
-
- The corresponding handler is \c onManualWhiteBalanceChanged.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qdeclarativecameraimageprocessing_p.cpp"
diff --git a/src/imports/multimedia/qdeclarativecameraimageprocessing_p.h b/src/imports/multimedia/qdeclarativecameraimageprocessing_p.h
deleted file mode 100644
index 390164250..000000000
--- a/src/imports/multimedia/qdeclarativecameraimageprocessing_p.h
+++ /dev/null
@@ -1,163 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVECAMERAIMAGEPROCESSING_H
-#define QDECLARATIVECAMERAIMAGEPROCESSING_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <qcamera.h>
-#include <qcameraimageprocessing.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeCamera;
-
-class QDeclarativeCameraImageProcessing : public QObject
-{
- Q_OBJECT
- Q_ENUMS(WhiteBalanceMode)
- Q_ENUMS(ColorFilter)
-
- Q_PROPERTY(WhiteBalanceMode whiteBalanceMode READ whiteBalanceMode WRITE setWhiteBalanceMode NOTIFY whiteBalanceModeChanged)
- Q_PROPERTY(qreal manualWhiteBalance READ manualWhiteBalance WRITE setManualWhiteBalance NOTIFY manualWhiteBalanceChanged)
- Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged REVISION 2)
- Q_PROPERTY(qreal contrast READ contrast WRITE setContrast NOTIFY contrastChanged)
- Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
- Q_PROPERTY(qreal sharpeningLevel READ sharpeningLevel WRITE setSharpeningLevel NOTIFY sharpeningLevelChanged)
- Q_PROPERTY(qreal denoisingLevel READ denoisingLevel WRITE setDenoisingLevel NOTIFY denoisingLevelChanged)
- Q_PROPERTY(ColorFilter colorFilter READ colorFilter WRITE setColorFilter NOTIFY colorFilterChanged REVISION 1)
- Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged REVISION 3)
- Q_PROPERTY(QVariantList supportedColorFilters READ supportedColorFilters
- NOTIFY supportedColorFiltersChanged REVISION 3)
- Q_PROPERTY(QVariantList supportedWhiteBalanceModes READ supportedWhiteBalanceModes
- NOTIFY supportedWhiteBalanceModesChanged REVISION 3)
-public:
- enum WhiteBalanceMode {
- WhiteBalanceAuto = QCameraImageProcessing::WhiteBalanceAuto,
- WhiteBalanceManual = QCameraImageProcessing::WhiteBalanceManual,
- WhiteBalanceSunlight = QCameraImageProcessing::WhiteBalanceSunlight,
- WhiteBalanceCloudy = QCameraImageProcessing::WhiteBalanceCloudy,
- WhiteBalanceShade = QCameraImageProcessing::WhiteBalanceShade,
- WhiteBalanceTungsten = QCameraImageProcessing::WhiteBalanceTungsten,
- WhiteBalanceFluorescent = QCameraImageProcessing::WhiteBalanceFluorescent,
- WhiteBalanceFlash = QCameraImageProcessing::WhiteBalanceFlash,
- WhiteBalanceSunset = QCameraImageProcessing::WhiteBalanceSunset,
- WhiteBalanceVendor = QCameraImageProcessing::WhiteBalanceVendor
- };
-
- enum ColorFilter {
- ColorFilterNone = QCameraImageProcessing::ColorFilterNone,
- ColorFilterGrayscale = QCameraImageProcessing::ColorFilterGrayscale,
- ColorFilterNegative = QCameraImageProcessing::ColorFilterNegative,
- ColorFilterSolarize = QCameraImageProcessing::ColorFilterSolarize,
- ColorFilterSepia = QCameraImageProcessing::ColorFilterSepia,
- ColorFilterPosterize = QCameraImageProcessing::ColorFilterPosterize,
- ColorFilterWhiteboard = QCameraImageProcessing::ColorFilterWhiteboard,
- ColorFilterBlackboard = QCameraImageProcessing::ColorFilterBlackboard,
- ColorFilterAqua = QCameraImageProcessing::ColorFilterAqua,
- ColorFilterVendor = QCameraImageProcessing::ColorFilterVendor
- };
-
- ~QDeclarativeCameraImageProcessing();
-
- WhiteBalanceMode whiteBalanceMode() const;
- qreal manualWhiteBalance() const;
-
- qreal brightness() const;
- qreal contrast() const;
- qreal saturation() const;
- qreal sharpeningLevel() const;
- qreal denoisingLevel() const;
-
- ColorFilter colorFilter() const;
-
- bool isAvailable() const;
- QVariantList supportedColorFilters() const;
- QVariantList supportedWhiteBalanceModes() const;
-
-public Q_SLOTS:
- void setWhiteBalanceMode(QDeclarativeCameraImageProcessing::WhiteBalanceMode mode) const;
- void setManualWhiteBalance(qreal colorTemp) const;
-
- Q_REVISION(2) void setBrightness(qreal value);
- void setContrast(qreal value);
- void setSaturation(qreal value);
- void setSharpeningLevel(qreal value);
- void setDenoisingLevel(qreal value);
-
- void setColorFilter(ColorFilter colorFilter);
-
-Q_SIGNALS:
- void whiteBalanceModeChanged(QDeclarativeCameraImageProcessing::WhiteBalanceMode) const;
- void manualWhiteBalanceChanged(qreal) const;
-
- Q_REVISION(2) void brightnessChanged(qreal);
- void contrastChanged(qreal);
- void saturationChanged(qreal);
- void sharpeningLevelChanged(qreal);
- void denoisingLevelChanged(qreal);
-
- void colorFilterChanged();
-
- void availableChanged();
- void supportedColorFiltersChanged();
- void supportedWhiteBalanceModesChanged();
-
-private:
- friend class QDeclarativeCamera;
- QDeclarativeCameraImageProcessing(QCamera *camera, QObject *parent = 0);
-
- QCameraImageProcessing *m_imageProcessing;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeCameraImageProcessing))
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativecamerapreviewprovider.cpp b/src/imports/multimedia/qdeclarativecamerapreviewprovider.cpp
deleted file mode 100644
index 0c1566992..000000000
--- a/src/imports/multimedia/qdeclarativecamerapreviewprovider.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativecamerapreviewprovider_p.h"
-#include <QtCore/qmutex.h>
-#include <QtCore/qdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-struct QDeclarativeCameraPreviewProviderPrivate
-{
- QString id;
- QImage image;
- QMutex mutex;
-};
-
-Q_GLOBAL_STATIC(QDeclarativeCameraPreviewProviderPrivate, qDeclarativeCameraPreviewProviderPrivate)
-
-QDeclarativeCameraPreviewProvider::QDeclarativeCameraPreviewProvider()
-: QQuickImageProvider(QQuickImageProvider::Image)
-{
-}
-
-QDeclarativeCameraPreviewProvider::~QDeclarativeCameraPreviewProvider()
-{
- QDeclarativeCameraPreviewProviderPrivate *d = qDeclarativeCameraPreviewProviderPrivate();
- QMutexLocker lock(&d->mutex);
- d->id.clear();
- d->image = QImage();
-}
-
-QImage QDeclarativeCameraPreviewProvider::requestImage(const QString &id, QSize *size, const QSize& requestedSize)
-{
- QDeclarativeCameraPreviewProviderPrivate *d = qDeclarativeCameraPreviewProviderPrivate();
- QMutexLocker lock(&d->mutex);
-
- if (d->id != id)
- return QImage();
-
- QImage res = d->image;
- if (!requestedSize.isEmpty())
- res = res.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
-
- if (size)
- *size = res.size();
-
- return res;
-}
-
-void QDeclarativeCameraPreviewProvider::registerPreview(const QString &id, const QImage &preview)
-{
- //only the last preview is kept
- QDeclarativeCameraPreviewProviderPrivate *d = qDeclarativeCameraPreviewProviderPrivate();
- QMutexLocker lock(&d->mutex);
- d->id = id;
- d->image = preview;
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/multimedia/qdeclarativecamerapreviewprovider_p.h b/src/imports/multimedia/qdeclarativecamerapreviewprovider_p.h
deleted file mode 100644
index cf5f0644c..000000000
--- a/src/imports/multimedia/qdeclarativecamerapreviewprovider_p.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVECAMERAPREVIEWPROVIDER_H
-#define QDECLARATIVECAMERAPREVIEWPROVIDER_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtQuick/qquickimageprovider.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeCameraPreviewProvider : public QQuickImageProvider
-{
-public:
- QDeclarativeCameraPreviewProvider();
- ~QDeclarativeCameraPreviewProvider();
-
- QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize) override;
- static void registerPreview(const QString &id, const QImage &preview);
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativecamerarecorder.cpp b/src/imports/multimedia/qdeclarativecamerarecorder.cpp
deleted file mode 100644
index 2739d19e0..000000000
--- a/src/imports/multimedia/qdeclarativecamerarecorder.cpp
+++ /dev/null
@@ -1,592 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativecamera_p.h"
-#include "qdeclarativecamerarecorder_p.h"
-
-#include <QtCore/qurl.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype CameraRecorder
- \instantiates QDeclarativeCameraRecorder
- \inqmlmodule QtMultimedia
- \brief Controls video recording with the Camera.
- \ingroup multimedia_qml
- \ingroup camera_qml
-
- CameraRecorder allows recording camera streams to files, and adjusting recording
- settings and metadata for videos.
-
- It should not be constructed separately, instead the
- \c videoRecorder property of a \l Camera should be used.
-
- \qml
- Camera {
- videoRecorder.audioEncodingMode: CameraRecorder.ConstantBitrateEncoding;
- videoRecorder.audioBitRate: 128000
- videoRecorder.mediaContainer: "mp4"
- // ...
- }
- \endqml
-
- There are many different settings for each part of the recording process (audio,
- video, and output formats), as well as control over muting and where to store
- the output file.
-
- \sa QAudioEncoderSettings, QVideoEncoderSettings
-*/
-
-QDeclarativeCameraRecorder::QDeclarativeCameraRecorder(QCamera *camera, QObject *parent) :
- QObject(parent)
-{
- m_recorder = new QMediaRecorder(camera, this);
- connect(m_recorder, SIGNAL(stateChanged(QMediaRecorder::State)),
- SLOT(updateRecorderState(QMediaRecorder::State)));
- connect(m_recorder, SIGNAL(statusChanged(QMediaRecorder::Status)),
- SIGNAL(recorderStatusChanged()));
- connect(m_recorder, SIGNAL(error(QMediaRecorder::Error)),
- SLOT(updateRecorderError(QMediaRecorder::Error)));
- connect(m_recorder, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool)));
- connect(m_recorder, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64)));
- connect(m_recorder, SIGNAL(actualLocationChanged(QUrl)),
- SLOT(updateActualLocation(QUrl)));
- connect(m_recorder, SIGNAL(metaDataChanged(QString,QVariant)),
- SIGNAL(metaDataChanged(QString,QVariant)));
-}
-
-QDeclarativeCameraRecorder::~QDeclarativeCameraRecorder()
-{
-}
-
-/*!
- \qmlproperty size QtMultimedia::CameraRecorder::resolution
-
- This property holds the video frame dimensions to be used for video capture.
-*/
-QSize QDeclarativeCameraRecorder::captureResolution()
-{
- return m_videoSettings.resolution();
-}
-
-/*!
- \qmlproperty string QtMultimedia::CameraRecorder::audioCodec
-
- This property holds the audio codec to be used for recording video.
- Typically this is \c aac or \c amr-wb.
-
- \sa {QtMultimedia::CameraImageProcessing::whiteBalanceMode}{whileBalanceMode}
-*/
-QString QDeclarativeCameraRecorder::audioCodec() const
-{
- return m_audioSettings.codec();
-}
-
-/*!
- \qmlproperty string QtMultimedia::CameraRecorder::videoCodec
-
- This property holds the video codec to be used for recording video.
- Typically this is \c h264.
-*/
-QString QDeclarativeCameraRecorder::videoCodec() const
-{
- return m_videoSettings.codec();
-}
-
-/*!
- \qmlproperty string QtMultimedia::CameraRecorder::mediaContainer
-
- This property holds the media container to be used for recording video.
- Typically this is \c mp4.
-*/
-QString QDeclarativeCameraRecorder::mediaContainer() const
-{
- return m_mediaContainer;
-}
-
-void QDeclarativeCameraRecorder::setCaptureResolution(const QSize &resolution)
-{
- m_videoSettings = m_recorder->videoSettings();
- if (resolution != captureResolution()) {
- m_videoSettings.setResolution(resolution);
- m_recorder->setVideoSettings(m_videoSettings);
- emit captureResolutionChanged(resolution);
- }
-}
-
-void QDeclarativeCameraRecorder::setAudioCodec(const QString &codec)
-{
- m_audioSettings = m_recorder->audioSettings();
- if (codec != audioCodec()) {
- m_audioSettings.setCodec(codec);
- m_recorder->setAudioSettings(m_audioSettings);
- emit audioCodecChanged(codec);
- }
-}
-
-void QDeclarativeCameraRecorder::setVideoCodec(const QString &codec)
-{
- m_videoSettings = m_recorder->videoSettings();
- if (codec != videoCodec()) {
- m_videoSettings.setCodec(codec);
- m_recorder->setVideoSettings(m_videoSettings);
- emit videoCodecChanged(codec);
- }
-}
-
-void QDeclarativeCameraRecorder::setMediaContainer(const QString &container)
-{
- if (container != m_mediaContainer) {
- m_mediaContainer = container;
- m_recorder->setContainerFormat(container);
- emit mediaContainerChanged(container);
- }
-}
-
-/*!
- \qmlproperty qreal QtMultimedia::CameraRecorder::frameRate
-
- This property holds the framerate (in frames per second) to be used for recording video.
-*/
-qreal QDeclarativeCameraRecorder::frameRate() const
-{
- return m_videoSettings.frameRate();
-}
-
-/*!
- \qmlproperty int QtMultimedia::CameraRecorder::videoBitRate
-
- This property holds the bit rate (in bits per second) to be used for recording video.
-*/
-int QDeclarativeCameraRecorder::videoBitRate() const
-{
- return m_videoSettings.bitRate();
-}
-
-/*!
- \qmlproperty int QtMultimedia::CameraRecorder::audioBitRate
-
- This property holds the audio bit rate (in bits per second) to be used for recording video.
-*/
-int QDeclarativeCameraRecorder::audioBitRate() const
-{
- return m_audioSettings.bitRate();
-}
-
-/*!
- \qmlproperty int QtMultimedia::CameraRecorder::audioChannels
-
- This property indicates the number of audio channels to be encoded while
- recording video (1 is mono, 2 is stereo).
-*/
-int QDeclarativeCameraRecorder::audioChannels() const
-{
- return m_audioSettings.channelCount();
-}
-
-/*!
- \qmlproperty int QtMultimedia::CameraRecorder::audioSampleRate
-
- This property holds the sample rate to be used to encode audio while recording video.
-*/
-int QDeclarativeCameraRecorder::audioSampleRate() const
-{
- return m_audioSettings.sampleRate();
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::CameraRecorder::videoEncodingMode
-
- This property holds the type of encoding method to be used for recording video.
-
- The following are the different encoding methods used:
-
- \table
- \header \li Value \li Description
- \row \li ConstantQualityEncoding
- \li Encoding will aim to have a constant quality, adjusting bitrate to fit.
- This is the default. The bitrate setting will be ignored.
- \row \li ConstantBitRateEncoding
- \li Encoding will use a constant bit rate, adjust quality to fit. This is
- appropriate if you are trying to optimize for space.
- \row \li AverageBitRateEncoding
- \li Encoding will try to keep an average bitrate setting, but will use
- more or less as needed.
- \endtable
-
-*/
-QDeclarativeCameraRecorder::EncodingMode QDeclarativeCameraRecorder::videoEncodingMode() const
-{
- return EncodingMode(m_videoSettings.encodingMode());
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::CameraRecorder::audioEncodingMode
-
- The type of encoding method to use when recording audio.
-
- \table
- \header \li Value \li Description
- \row \li ConstantQualityEncoding
- \li Encoding will aim to have a constant quality, adjusting bitrate to fit.
- This is the default. The bitrate setting will be ignored.
- \row \li ConstantBitRateEncoding
- \li Encoding will use a constant bit rate, adjust quality to fit. This is
- appropriate if you are trying to optimize for space.
- \row \li AverageBitRateEncoding
- \li Encoding will try to keep an average bitrate setting, but will use
- more or less as needed.
- \endtable
-*/
-QDeclarativeCameraRecorder::EncodingMode QDeclarativeCameraRecorder::audioEncodingMode() const
-{
- return EncodingMode(m_audioSettings.encodingMode());
-}
-
-void QDeclarativeCameraRecorder::setFrameRate(qreal frameRate)
-{
- m_videoSettings = m_recorder->videoSettings();
- if (!qFuzzyCompare(m_videoSettings.frameRate(),frameRate)) {
- m_videoSettings.setFrameRate(frameRate);
- m_recorder->setVideoSettings(m_videoSettings);
- emit frameRateChanged(frameRate);
- }
-}
-
-void QDeclarativeCameraRecorder::setVideoBitRate(int rate)
-{
- m_videoSettings = m_recorder->videoSettings();
- if (m_videoSettings.bitRate() != rate) {
- m_videoSettings.setBitRate(rate);
- m_recorder->setVideoSettings(m_videoSettings);
- emit videoBitRateChanged(rate);
- }
-}
-
-void QDeclarativeCameraRecorder::setAudioBitRate(int rate)
-{
- m_audioSettings = m_recorder->audioSettings();
- if (m_audioSettings.bitRate() != rate) {
- m_audioSettings.setBitRate(rate);
- m_recorder->setAudioSettings(m_audioSettings);
- emit audioBitRateChanged(rate);
- }
-}
-
-void QDeclarativeCameraRecorder::setAudioChannels(int channels)
-{
- m_audioSettings = m_recorder->audioSettings();
- if (m_audioSettings.channelCount() != channels) {
- m_audioSettings.setChannelCount(channels);
- m_recorder->setAudioSettings(m_audioSettings);
- emit audioChannelsChanged(channels);
- }
-}
-
-void QDeclarativeCameraRecorder::setAudioSampleRate(int rate)
-{
- m_audioSettings = m_recorder->audioSettings();
- if (m_audioSettings.sampleRate() != rate) {
- m_audioSettings.setSampleRate(rate);
- m_recorder->setAudioSettings(m_audioSettings);
- emit audioSampleRateChanged(rate);
- }
-}
-
-void QDeclarativeCameraRecorder::setAudioEncodingMode(QDeclarativeCameraRecorder::EncodingMode encodingMode)
-{
- m_audioSettings = m_recorder->audioSettings();
- if (m_audioSettings.encodingMode() != QMultimedia::EncodingMode(encodingMode)) {
- m_audioSettings.setEncodingMode(QMultimedia::EncodingMode(encodingMode));
- m_recorder->setAudioSettings(m_audioSettings);
- emit audioEncodingModeChanged(encodingMode);
- }
-}
-
-void QDeclarativeCameraRecorder::setVideoEncodingMode(QDeclarativeCameraRecorder::EncodingMode encodingMode)
-{
- m_videoSettings = m_recorder->videoSettings();
- if (m_videoSettings.encodingMode() != QMultimedia::EncodingMode(encodingMode)) {
- m_videoSettings.setEncodingMode(QMultimedia::EncodingMode(encodingMode));
- m_recorder->setVideoSettings(m_videoSettings);
- emit videoEncodingModeChanged(encodingMode);
- }
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::CameraRecorder::errorCode
-
- This property holds the last error code.
-
- \table
- \header \li Value \li Description
- \row \li NoError
- \li No Errors
-
- \row \li ResourceError
- \li Device is not ready or not available.
-
- \row \li FormatError
- \li Current format is not supported.
-
- \row \li OutOfSpaceError
- \li No space left on device.
-
- \endtable
-*/
-QDeclarativeCameraRecorder::Error QDeclarativeCameraRecorder::errorCode() const
-{
- return QDeclarativeCameraRecorder::Error(m_recorder->error());
-}
-
-/*!
- \qmlproperty string QtMultimedia::CameraRecorder::errorString
-
- This property holds the description of the last error.
-*/
-QString QDeclarativeCameraRecorder::errorString() const
-{
- return m_recorder->errorString();
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::CameraRecorder::recorderState
-
- This property holds the current state of the camera recorder object.
-
- The state can be one of these two:
-
- \table
- \header \li Value \li Description
- \row \li StoppedState
- \li The camera is not recording video.
-
- \row \li RecordingState
- \li The camera is recording video.
- \endtable
-*/
-QDeclarativeCameraRecorder::RecorderState QDeclarativeCameraRecorder::recorderState() const
-{
- //paused state is not supported for camera
- QMediaRecorder::State state = m_recorder->state();
-
- if (state == QMediaRecorder::PausedState)
- state = QMediaRecorder::StoppedState;
-
- return RecorderState(state);
-}
-
-
-/*!
- \qmlproperty enumeration QtMultimedia::CameraRecorder::recorderStatus
-
- This property holds the current status of media recording.
-
- \table
- \header \li Value \li Description
- \row \li UnavailableStatus
- \li Recording is not supported by the camera.
- \row \li UnloadedStatus
- \li The recorder is available but not loaded.
- \row \li LoadingStatus
- \li The recorder is initializing.
- \row \li LoadedStatus
- \li The recorder is initialized and ready to record media.
- \row \li StartingStatus
- \li Recording is requested but not active yet.
- \row \li RecordingStatus
- \li Recording is active.
- \row \li PausedStatus
- \li Recording is paused.
- \row \li FinalizingStatus
- \li Recording is stopped with media being finalized.
- \endtable
-*/
-
-QDeclarativeCameraRecorder::RecorderStatus QDeclarativeCameraRecorder::recorderStatus() const
-{
- return RecorderStatus(m_recorder->status());
-}
-
-/*!
- \qmlmethod QtMultimedia::CameraRecorder::record()
-
- Starts recording.
-*/
-void QDeclarativeCameraRecorder::record()
-{
- setRecorderState(RecordingState);
-}
-
-/*!
- \qmlmethod QtMultimedia::CameraRecorder::stop()
-
- Stops recording.
-*/
-void QDeclarativeCameraRecorder::stop()
-{
- setRecorderState(StoppedState);
-}
-
-void QDeclarativeCameraRecorder::setRecorderState(QDeclarativeCameraRecorder::RecorderState state)
-{
- if (!m_recorder)
- return;
-
- switch (state) {
- case QDeclarativeCameraRecorder::RecordingState:
- m_recorder->record();
- break;
- case QDeclarativeCameraRecorder::StoppedState:
- m_recorder->stop();
- break;
- }
-}
-/*!
- \property QDeclarativeCameraRecorder::outputLocation
-
- This property holds the destination location of the media content. If it is empty,
- the recorder uses the system-specific place and file naming scheme.
-*/
-/*!
- \qmlproperty string QtMultimedia::CameraRecorder::outputLocation
-
- This property holds the destination location of the media content. If the location is empty,
- the recorder uses the system-specific place and file naming scheme.
-*/
-
-QString QDeclarativeCameraRecorder::outputLocation() const
-{
- return m_recorder->outputLocation().toString();
-}
-/*!
- \property QDeclarativeCameraRecorder::actualLocation
-
- This property holds the absolute location to the last saved media content.
- The location is usually available after recording starts, and reset when
- new location is set or new recording starts.
-*/
-/*!
- \qmlproperty string QtMultimedia::CameraRecorder::actualLocation
-
- This property holds the actual location of the last saved media content. The actual location is
- usually available after the recording starts, and reset when new location is set or the new recording starts.
-*/
-
-QString QDeclarativeCameraRecorder::actualLocation() const
-{
- return m_recorder->actualLocation().toString();
-}
-
-void QDeclarativeCameraRecorder::setOutputLocation(const QString &location)
-{
- if (outputLocation() != location) {
- m_recorder->setOutputLocation(location);
- emit outputLocationChanged(outputLocation());
- }
-}
-/*!
- \property QDeclarativeCameraRecorder::duration
-
- This property holds the duration (in miliseconds) of the last recording.
-*/
-/*!
- \qmlproperty int QtMultimedia::CameraRecorder::duration
-
- This property holds the duration (in miliseconds) of the last recording.
-*/
-qint64 QDeclarativeCameraRecorder::duration() const
-{
- return m_recorder->duration();
-}
-/*!
- \property QDeclarativeCameraRecorder::muted
-
- This property indicates whether the audio input is muted during
- recording.
-*/
-/*!
- \qmlproperty bool QtMultimedia::CameraRecorder::muted
-
- This property indicates whether the audio input is muted during recording.
-*/
-bool QDeclarativeCameraRecorder::isMuted() const
-{
- return m_recorder->isMuted();
-}
-
-void QDeclarativeCameraRecorder::setMuted(bool muted)
-{
- m_recorder->setMuted(muted);
-}
-
-/*!
- \qmlmethod QtMultimedia::CameraRecorder::setMetadata(key, value)
-
- Sets metadata for the next video to be recorder, with
- the given \a key being associated with \a value.
-*/
-void QDeclarativeCameraRecorder::setMetadata(const QString &key, const QVariant &value)
-{
- m_recorder->setMetaData(key, value);
-}
-
-void QDeclarativeCameraRecorder::updateRecorderState(QMediaRecorder::State state)
-{
- if (state == QMediaRecorder::PausedState)
- state = QMediaRecorder::StoppedState;
-
- emit recorderStateChanged(RecorderState(state));
-}
-
-void QDeclarativeCameraRecorder::updateRecorderError(QMediaRecorder::Error errorCode)
-{
- qWarning() << "QMediaRecorder error:" << errorString();
- emit error(Error(errorCode), errorString());
-}
-
-void QDeclarativeCameraRecorder::updateActualLocation(const QUrl &url)
-{
- emit actualLocationChanged(url.toString());
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qdeclarativecamerarecorder_p.cpp"
diff --git a/src/imports/multimedia/qdeclarativecamerarecorder_p.h b/src/imports/multimedia/qdeclarativecamerarecorder_p.h
deleted file mode 100644
index be30f48f6..000000000
--- a/src/imports/multimedia/qdeclarativecamerarecorder_p.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVECAMERARECORDER_H
-#define QDECLARATIVECAMERARECORDER_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <qcamera.h>
-#include <qmediarecorder.h>
-#include <qmediaencodersettings.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeCamera;
-
-class QDeclarativeCameraRecorder : public QObject
-{
- Q_OBJECT
- Q_ENUMS(RecorderState)
- Q_ENUMS(RecorderStatus)
- Q_ENUMS(EncodingMode)
- Q_ENUMS(Error)
-
- Q_PROPERTY(RecorderState recorderState READ recorderState WRITE setRecorderState NOTIFY recorderStateChanged)
- Q_PROPERTY(RecorderStatus recorderStatus READ recorderStatus NOTIFY recorderStatusChanged)
-
- Q_PROPERTY(QString videoCodec READ videoCodec WRITE setVideoCodec NOTIFY videoCodecChanged)
- Q_PROPERTY(QSize resolution READ captureResolution WRITE setCaptureResolution NOTIFY captureResolutionChanged)
- Q_PROPERTY(qreal frameRate READ frameRate WRITE setFrameRate NOTIFY frameRateChanged)
- Q_PROPERTY(int videoBitRate READ videoBitRate WRITE setVideoBitRate NOTIFY videoBitRateChanged)
- Q_PROPERTY(EncodingMode videoEncodingMode READ videoEncodingMode WRITE setVideoEncodingMode NOTIFY videoEncodingModeChanged)
-
- Q_PROPERTY(QString audioCodec READ audioCodec WRITE setAudioCodec NOTIFY audioCodecChanged)
- Q_PROPERTY(int audioBitRate READ audioBitRate WRITE setAudioBitRate NOTIFY audioBitRateChanged)
- Q_PROPERTY(int audioChannels READ audioChannels WRITE setAudioChannels NOTIFY audioChannelsChanged)
- Q_PROPERTY(int audioSampleRate READ audioSampleRate WRITE setAudioSampleRate NOTIFY audioSampleRateChanged)
- Q_PROPERTY(EncodingMode audioEncodingMode READ audioEncodingMode WRITE setAudioEncodingMode NOTIFY audioEncodingModeChanged)
-
- Q_PROPERTY(QString mediaContainer READ mediaContainer WRITE setMediaContainer NOTIFY mediaContainerChanged)
-
- Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
- Q_PROPERTY(QString outputLocation READ outputLocation WRITE setOutputLocation NOTIFY outputLocationChanged)
- Q_PROPERTY(QString actualLocation READ actualLocation NOTIFY actualLocationChanged)
- Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
- Q_PROPERTY(QString errorString READ errorString NOTIFY error)
- Q_PROPERTY(Error errorCode READ errorCode NOTIFY error)
-
-public:
- enum RecorderState
- {
- StoppedState = QMediaRecorder::StoppedState,
- RecordingState = QMediaRecorder::RecordingState
- };
-
- enum RecorderStatus
- {
- UnavailableStatus = QMediaRecorder::UnavailableStatus,
- UnloadedStatus = QMediaRecorder::UnloadedStatus,
- LoadingStatus = QMediaRecorder::LoadingStatus,
- LoadedStatus = QMediaRecorder::LoadedStatus,
- StartingStatus = QMediaRecorder::StartingStatus,
- RecordingStatus = QMediaRecorder::RecordingStatus,
- PausedStatus = QMediaRecorder::PausedStatus,
- FinalizingStatus = QMediaRecorder::FinalizingStatus
- };
-
- enum EncodingMode
- {
- ConstantQualityEncoding = QMultimedia::ConstantQualityEncoding,
- ConstantBitRateEncoding = QMultimedia::ConstantBitRateEncoding,
- AverageBitRateEncoding = QMultimedia::AverageBitRateEncoding
- };
-
- enum Error {
- NoError = QMediaRecorder::NoError,
- ResourceError = QMediaRecorder::ResourceError,
- FormatError = QMediaRecorder::FormatError,
- OutOfSpaceError = QMediaRecorder::OutOfSpaceError
- };
-
- ~QDeclarativeCameraRecorder();
-
- RecorderState recorderState() const;
- RecorderStatus recorderStatus() const;
-
- QSize captureResolution();
-
- QString outputLocation() const;
- QString actualLocation() const;
-
- qint64 duration() const;
- bool isMuted() const;
-
- QString audioCodec() const;
- QString videoCodec() const;
- QString mediaContainer() const;
-
- Error errorCode() const;
- QString errorString() const;
-
- qreal frameRate() const;
- int videoBitRate() const;
- int audioBitRate() const;
- int audioChannels() const;
- int audioSampleRate() const;
-
- EncodingMode videoEncodingMode() const;
- EncodingMode audioEncodingMode() const;
-
-public Q_SLOTS:
- void setOutputLocation(const QString &location);
-
- void record();
- void stop();
- void setRecorderState(QDeclarativeCameraRecorder::RecorderState state);
-
- void setMuted(bool muted);
- void setMetadata(const QString &key, const QVariant &value);
-
- void setCaptureResolution(const QSize &resolution);
- void setAudioCodec(const QString &codec);
- void setVideoCodec(const QString &codec);
- void setMediaContainer(const QString &container);
-
- void setFrameRate(qreal frameRate);
- void setVideoBitRate(int rate);
- void setAudioBitRate(int rate);
- void setAudioChannels(int channels);
- void setAudioSampleRate(int rate);
-
- void setVideoEncodingMode(EncodingMode encodingMode);
- void setAudioEncodingMode(EncodingMode encodingMode);
-
-Q_SIGNALS:
- void recorderStateChanged(QDeclarativeCameraRecorder::RecorderState state);
- void recorderStatusChanged();
- void durationChanged(qint64 duration);
- void mutedChanged(bool muted);
- void outputLocationChanged(const QString &location);
- void actualLocationChanged(const QString &location);
-
- void error(QDeclarativeCameraRecorder::Error errorCode, const QString &errorString);
-
- void metaDataChanged(const QString &key, const QVariant &value);
-
- void captureResolutionChanged(const QSize &);
- void audioCodecChanged(const QString &codec);
- void videoCodecChanged(const QString &codec);
- void mediaContainerChanged(const QString &container);
-
- void frameRateChanged(qreal arg);
- void videoBitRateChanged(int arg);
- void audioBitRateChanged(int arg);
- void audioChannelsChanged(int arg);
- void audioSampleRateChanged(int arg);
-
- void audioEncodingModeChanged(EncodingMode encodingMode);
- void videoEncodingModeChanged(EncodingMode encodingMode);
-
-private slots:
- void updateRecorderState(QMediaRecorder::State);
- void updateRecorderError(QMediaRecorder::Error);
- void updateActualLocation(const QUrl&);
-
-private:
- friend class QDeclarativeCamera;
- QDeclarativeCameraRecorder(QCamera *camera, QObject *parent = 0);
-
- QMediaRecorder *m_recorder;
-
- QAudioEncoderSettings m_audioSettings;
- QVideoEncoderSettings m_videoSettings;
- QString m_mediaContainer;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeCameraRecorder))
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativecameraviewfinder.cpp b/src/imports/multimedia/qdeclarativecameraviewfinder.cpp
deleted file mode 100644
index 2b3c16429..000000000
--- a/src/imports/multimedia/qdeclarativecameraviewfinder.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativecamera_p.h"
-#include "qdeclarativecameraviewfinder_p.h"
-
-#include <QtMultimedia/qcameraviewfindersettingscontrol.h>
-
-
-QT_BEGIN_NAMESPACE
-
-QDeclarativeCameraViewfinder::QDeclarativeCameraViewfinder(QCamera *camera, QObject *parent)
- : QObject(parent)
- , m_camera(camera)
-{
- connect(m_camera, &QCamera::statusChanged,
- this, &QDeclarativeCameraViewfinder::_q_cameraStatusChanged);
-}
-
-QDeclarativeCameraViewfinder::~QDeclarativeCameraViewfinder()
-{
-}
-
-QSize QDeclarativeCameraViewfinder::resolution() const
-{
- return m_settings.resolution();
-}
-
-void QDeclarativeCameraViewfinder::setResolution(const QSize &res)
-{
- if (res != m_settings.resolution()) {
- m_settings = m_camera->viewfinderSettings();
- m_settings.setResolution(res);
- m_camera->setViewfinderSettings(m_settings);
- emit resolutionChanged();
- }
-}
-
-qreal QDeclarativeCameraViewfinder::minimumFrameRate() const
-{
- return m_settings.minimumFrameRate();
-}
-
-void QDeclarativeCameraViewfinder::setMinimumFrameRate(qreal frameRate)
-{
- if (frameRate != minimumFrameRate()) {
- m_settings = m_camera->viewfinderSettings();
- m_settings.setMinimumFrameRate(frameRate);
- m_camera->setViewfinderSettings(m_settings);
- emit minimumFrameRateChanged();
- }
-}
-
-qreal QDeclarativeCameraViewfinder::maximumFrameRate() const
-{
- return m_settings.maximumFrameRate();
-}
-
-void QDeclarativeCameraViewfinder::setMaximumFrameRate(qreal frameRate)
-{
- if (frameRate != maximumFrameRate()) {
- m_settings = m_camera->viewfinderSettings();
- m_settings.setMaximumFrameRate(frameRate);
- m_camera->setViewfinderSettings(m_settings);
- emit maximumFrameRateChanged();
- }
-}
-
-void QDeclarativeCameraViewfinder::_q_cameraStatusChanged(QCamera::Status status)
-{
- // Settings values might change when the camera starts, for example if the settings are
- // undefined, if unsupported values were set or if the settings conflict with capture settings.
- // They might also change on LoadedStatus, for example reverting to values that were set by the
- // user.
- if (status == QCamera::ActiveStatus || status == QCamera::LoadedStatus) {
- QCameraViewfinderSettings oldSettings = m_settings;
- m_settings = m_camera->viewfinderSettings();
- if (oldSettings.resolution() != m_settings.resolution())
- emit resolutionChanged();
- if (oldSettings.minimumFrameRate() != m_settings.minimumFrameRate())
- emit minimumFrameRateChanged();
- if (oldSettings.maximumFrameRate() != m_settings.maximumFrameRate())
- emit maximumFrameRateChanged();
- }
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qdeclarativecameraviewfinder_p.cpp"
diff --git a/src/imports/multimedia/qdeclarativecameraviewfinder_p.h b/src/imports/multimedia/qdeclarativecameraviewfinder_p.h
deleted file mode 100644
index 472f03ece..000000000
--- a/src/imports/multimedia/qdeclarativecameraviewfinder_p.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVECAMERAVIEWFINDER_P_H
-#define QDECLARATIVECAMERAVIEWFINDER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <qcamera.h>
-#include <qmediarecorder.h>
-#include <qmediaencodersettings.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeCamera;
-class QCameraViewfinderSettingsControl;
-
-class QDeclarativeCameraViewfinder : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged)
- Q_PROPERTY(qreal minimumFrameRate READ minimumFrameRate WRITE setMinimumFrameRate NOTIFY minimumFrameRateChanged)
- Q_PROPERTY(qreal maximumFrameRate READ maximumFrameRate WRITE setMaximumFrameRate NOTIFY maximumFrameRateChanged)
-public:
- QDeclarativeCameraViewfinder(QCamera *camera, QObject *parent = 0);
- ~QDeclarativeCameraViewfinder();
-
- QSize resolution() const;
- void setResolution(const QSize &resolution);
-
- qreal minimumFrameRate() const;
- void setMinimumFrameRate(qreal frameRate);
-
- qreal maximumFrameRate() const;
- void setMaximumFrameRate(qreal frameRate);
-
-Q_SIGNALS:
- void resolutionChanged();
- void minimumFrameRateChanged();
- void maximumFrameRateChanged();
-
-private Q_SLOTS:
- void _q_cameraStatusChanged(QCamera::Status status);
-
-private:
- QCamera *m_camera;
- QCameraViewfinderSettings m_settings;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativemediametadata_p.h b/src/imports/multimedia/qdeclarativemediametadata_p.h
deleted file mode 100644
index ede7f8723..000000000
--- a/src/imports/multimedia/qdeclarativemediametadata_p.h
+++ /dev/null
@@ -1,452 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEMEDIAMETADATA_P_H
-#define QDECLARATIVEMEDIAMETADATA_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtQml/qqml.h>
-#include <QtMultimedia/qmediametadata.h>
-#include <QtMultimedia/qmediaservice.h>
-#include <QtMultimedia/qmetadatawritercontrol.h>
-#include "qmediaobject.h"
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeMediaMetaData : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QVariant title READ title WRITE setTitle NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant subTitle READ subTitle WRITE setSubTitle NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant author READ author WRITE setAuthor NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant comment READ comment WRITE setComment NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant description READ description WRITE setDescription NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant category READ category WRITE setCategory NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant genre READ genre WRITE setGenre NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant year READ year WRITE setYear NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant date READ date WRITE setDate NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant userRating READ userRating WRITE setUserRating NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant keywords READ keywords WRITE setKeywords NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant language READ language WRITE setLanguage NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant publisher READ publisher WRITE setPublisher NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant copyright READ copyright WRITE setCopyright NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant parentalRating READ parentalRating WRITE setParentalRating NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant ratingOrganization READ ratingOrganization WRITE setRatingOrganization NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant size READ size WRITE setSize NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant mediaType READ mediaType WRITE setMediaType NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant duration READ duration WRITE setDuration NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant audioBitRate READ audioBitRate WRITE setAudioBitRate NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant audioCodec READ audioCodec WRITE setAudioCodec NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant averageLevel READ averageLevel WRITE setAverageLevel NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant channelCount READ channelCount WRITE setChannelCount NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant peakValue READ peakValue WRITE setPeakValue NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant sampleRate READ sampleRate WRITE setSampleRate NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant albumTitle READ albumTitle WRITE setAlbumTitle NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant albumArtist READ albumArtist WRITE setAlbumArtist NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant contributingArtist READ contributingArtist WRITE setContributingArtist NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant composer READ composer WRITE setComposer NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant conductor READ conductor WRITE setConductor NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant lyrics READ lyrics WRITE setLyrics NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant mood READ mood WRITE setMood NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant trackNumber READ trackNumber WRITE setTrackNumber NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant trackCount READ trackCount WRITE setTrackCount NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant coverArtUrlSmall READ coverArtUrlSmall WRITE setCoverArtUrlSmall NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant coverArtUrlLarge READ coverArtUrlLarge WRITE setCoverArtUrlLarge NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant resolution READ resolution WRITE setResolution NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant pixelAspectRatio READ pixelAspectRatio WRITE setPixelAspectRatio NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant videoFrameRate READ videoFrameRate WRITE setVideoFrameRate NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant videoBitRate READ videoBitRate WRITE setVideoBitRate NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant videoCodec READ videoCodec WRITE setVideoCodec NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant posterUrl READ posterUrl WRITE setPosterUrl NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant chapterNumber READ chapterNumber WRITE setChapterNumber NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant director READ director WRITE setDirector NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant leadPerformer READ leadPerformer WRITE setLeadPerformer NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant writer READ writer WRITE setWriter NOTIFY metaDataChanged)
-
- Q_PROPERTY(QVariant cameraManufacturer READ cameraManufacturer WRITE setCameraManufacturer NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant cameraModel READ cameraModel WRITE setCameraModel NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant event READ event WRITE setEvent NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant subject READ subject WRITE setSubject NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant orientation READ orientation WRITE setOrientation NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant exposureTime READ exposureTime WRITE setExposureTime NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant fNumber READ fNumber WRITE setFNumber NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant exposureProgram READ exposureProgram WRITE setExposureProgram NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant isoSpeedRatings READ isoSpeedRatings WRITE setISOSpeedRatings NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant exposureBiasValue READ exposureBiasValue WRITE setExposureBiasValue NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant dateTimeOriginal READ dateTimeOriginal WRITE setDateTimeOriginal NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant dateTimeDigitized READ dateTimeDigitized WRITE setDateTimeDigitized NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant subjectDistance READ subjectDistance WRITE setSubjectDistance NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant meteringMode READ meteringMode WRITE setMeteringMode NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant lightSource READ lightSource WRITE setLightSource NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant flash READ flash WRITE setFlash NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant focalLength READ focalLength WRITE setFocalLength NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant exposureMode READ exposureMode WRITE setExposureMode NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant whiteBalance READ whiteBalance WRITE setWhiteBalance NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant digitalZoomRatio READ digitalZoomRatio WRITE setDigitalZoomRatio NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant focalLengthIn35mmFilm READ focalLengthIn35mmFilm WRITE setFocalLengthIn35mmFilm NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant sceneCaptureType READ sceneCaptureType WRITE setSceneCaptureType NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gainControl READ gainControl WRITE setGainControl NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant contrast READ contrast WRITE setContrast NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant saturation READ saturation WRITE setSaturation NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant sharpness READ sharpness WRITE setSharpness NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant deviceSettingDescription READ deviceSettingDescription WRITE setDeviceSettingDescription NOTIFY metaDataChanged)
-
- Q_PROPERTY(QVariant gpsLatitude READ gpsLatitude WRITE setGPSLatitude NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsLongitude READ gpsLongitude WRITE setGPSLongitude NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsAltitude READ gpsAltitude WRITE setGPSAltitude NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsTimeStamp READ gpsTimeStamp WRITE setGPSTimeStamp NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsSatellites READ gpsSatellites WRITE setGPSSatellites NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsStatus READ gpsStatus WRITE setGPSStatus NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsDOP READ gpsDOP WRITE setGPSDOP NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsSpeed READ gpsSpeed WRITE setGPSSpeed NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsTrack READ gpsTrack WRITE setGPSTrack NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsTrackRef READ gpsTrackRef WRITE setGPSTrackRef NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsImgDirection READ gpsImgDirection WRITE setGPSImgDirection NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsImgDirectionRef READ gpsImgDirectionRef WRITE setGPSImgDirectionRef NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsMapDatum READ gpsMapDatum WRITE setGPSMapDatum NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsProcessingMethod READ gpsProcessingMethod WRITE setGPSProcessingMethod NOTIFY metaDataChanged)
- Q_PROPERTY(QVariant gpsAreaInformation READ gpsAreaInformation WRITE setGPSAreaInformation NOTIFY metaDataChanged)
-
-public:
- QDeclarativeMediaMetaData(QMediaObject *player, QObject *parent = 0)
- : QObject(parent)
- , m_mediaObject(player)
- , m_writerControl(0)
- , m_requestedWriterControl(false)
- {
- }
-
- ~QDeclarativeMediaMetaData()
- {
- if (m_writerControl) {
- if (QMediaService *service = m_mediaObject->service())
- service->releaseControl(m_writerControl);
- }
- }
-
- QVariant title() const { return m_mediaObject->metaData(QMediaMetaData::Title); }
- void setTitle(const QVariant &title) { setMetaData(QMediaMetaData::Title, title); }
- QVariant subTitle() const { return m_mediaObject->metaData(QMediaMetaData::SubTitle); }
- void setSubTitle(const QVariant &title) {
- setMetaData(QMediaMetaData::SubTitle, title); }
- QVariant author() const { return m_mediaObject->metaData(QMediaMetaData::Author); }
- void setAuthor(const QVariant &author) { setMetaData(QMediaMetaData::Author, author); }
- QVariant comment() const { return m_mediaObject->metaData(QMediaMetaData::Comment); }
- void setComment(const QVariant &comment) { setMetaData(QMediaMetaData::Comment, comment); }
- QVariant description() const { return m_mediaObject->metaData(QMediaMetaData::Description); }
- void setDescription(const QVariant &description) {
- setMetaData(QMediaMetaData::Description, description); }
- QVariant category() const { return m_mediaObject->metaData(QMediaMetaData::Category); }
- void setCategory(const QVariant &category) { setMetaData(QMediaMetaData::Category, category); }
- QVariant genre() const { return m_mediaObject->metaData(QMediaMetaData::Genre); }
- void setGenre(const QVariant &genre) { setMetaData(QMediaMetaData::Genre, genre); }
- QVariant year() const { return m_mediaObject->metaData(QMediaMetaData::Year); }
- void setYear(const QVariant &year) { setMetaData(QMediaMetaData::Year, year); }
- QVariant date() const { return m_mediaObject->metaData(QMediaMetaData::Date); }
- void setDate(const QVariant &date) { setMetaData(QMediaMetaData::Date, date); }
- QVariant userRating() const { return m_mediaObject->metaData(QMediaMetaData::UserRating); }
- void setUserRating(const QVariant &rating) { setMetaData(QMediaMetaData::UserRating, rating); }
- QVariant keywords() const { return m_mediaObject->metaData(QMediaMetaData::Keywords); }
- void setKeywords(const QVariant &keywords) { setMetaData(QMediaMetaData::Keywords, keywords); }
- QVariant language() const { return m_mediaObject->metaData(QMediaMetaData::Language); }
- void setLanguage(const QVariant &language) { setMetaData(QMediaMetaData::Language, language); }
- QVariant publisher() const { return m_mediaObject->metaData(QMediaMetaData::Publisher); }
- void setPublisher(const QVariant &publisher) {
- setMetaData(QMediaMetaData::Publisher, publisher); }
- QVariant copyright() const { return m_mediaObject->metaData(QMediaMetaData::Copyright); }
- void setCopyright(const QVariant &copyright) {
- setMetaData(QMediaMetaData::Copyright, copyright); }
- QVariant parentalRating() const { return m_mediaObject->metaData(QMediaMetaData::ParentalRating); }
- void setParentalRating(const QVariant &rating) {
- setMetaData(QMediaMetaData::ParentalRating, rating); }
- QVariant ratingOrganization() const {
- return m_mediaObject->metaData(QMediaMetaData::RatingOrganization); }
- void setRatingOrganization(const QVariant &organization) {
- setMetaData(QMediaMetaData::RatingOrganization, organization); }
- QVariant size() const { return m_mediaObject->metaData(QMediaMetaData::Size); }
- void setSize(const QVariant &size) { setMetaData(QMediaMetaData::Size, size); }
- QVariant mediaType() const { return m_mediaObject->metaData(QMediaMetaData::MediaType); }
- void setMediaType(const QVariant &type) { setMetaData(QMediaMetaData::MediaType, type); }
- QVariant duration() const { return m_mediaObject->metaData(QMediaMetaData::Duration); }
- void setDuration(const QVariant &duration) { setMetaData(QMediaMetaData::Duration, duration); }
- QVariant audioBitRate() const { return m_mediaObject->metaData(QMediaMetaData::AudioBitRate); }
- void setAudioBitRate(const QVariant &rate) { setMetaData(QMediaMetaData::AudioBitRate, rate); }
- QVariant audioCodec() const { return m_mediaObject->metaData(QMediaMetaData::AudioCodec); }
- void setAudioCodec(const QVariant &codec) { setMetaData(QMediaMetaData::AudioCodec, codec); }
- QVariant averageLevel() const { return m_mediaObject->metaData(QMediaMetaData::AverageLevel); }
- void setAverageLevel(const QVariant &level) {
- setMetaData(QMediaMetaData::AverageLevel, level); }
- QVariant channelCount() const { return m_mediaObject->metaData(QMediaMetaData::ChannelCount); }
- void setChannelCount(const QVariant &count) {
- setMetaData(QMediaMetaData::ChannelCount, count); }
- QVariant peakValue() const { return m_mediaObject->metaData(QMediaMetaData::PeakValue); }
- void setPeakValue(const QVariant &value) { setMetaData(QMediaMetaData::PeakValue, value); }
- QVariant sampleRate() const { return m_mediaObject->metaData(QMediaMetaData::SampleRate); }
- void setSampleRate(const QVariant &rate) { setMetaData(QMediaMetaData::SampleRate, rate); }
- QVariant albumTitle() const { return m_mediaObject->metaData(QMediaMetaData::AlbumTitle); }
- void setAlbumTitle(const QVariant &title) { setMetaData(QMediaMetaData::AlbumTitle, title); }
- QVariant albumArtist() const { return m_mediaObject->metaData(QMediaMetaData::AlbumArtist); }
- void setAlbumArtist(const QVariant &artist) {
- setMetaData(QMediaMetaData::AlbumArtist, artist); }
- QVariant contributingArtist() const {
- return m_mediaObject->metaData(QMediaMetaData::ContributingArtist); }
- void setContributingArtist(const QVariant &artist) {
- setMetaData(QMediaMetaData::ContributingArtist, artist); }
- QVariant composer() const { return m_mediaObject->metaData(QMediaMetaData::Composer); }
- void setComposer(const QVariant &composer) { setMetaData(QMediaMetaData::Composer, composer); }
- QVariant conductor() const { return m_mediaObject->metaData(QMediaMetaData::Conductor); }
- void setConductor(const QVariant &conductor) {
- setMetaData(QMediaMetaData::Conductor, conductor); }
- QVariant lyrics() const { return m_mediaObject->metaData(QMediaMetaData::Lyrics); }
- void setLyrics(const QVariant &lyrics) { setMetaData(QMediaMetaData::Lyrics, lyrics); }
- QVariant mood() const { return m_mediaObject->metaData(QMediaMetaData::Mood); }
- void setMood(const QVariant &mood) { setMetaData(QMediaMetaData::Mood, mood); }
- QVariant trackNumber() const { return m_mediaObject->metaData(QMediaMetaData::TrackNumber); }
- void setTrackNumber(const QVariant &track) { setMetaData(QMediaMetaData::TrackNumber, track); }
- QVariant trackCount() const { return m_mediaObject->metaData(QMediaMetaData::TrackCount); }
- void setTrackCount(const QVariant &count) { setMetaData(QMediaMetaData::TrackCount, count); }
- QVariant coverArtUrlSmall() const {
- return m_mediaObject->metaData(QMediaMetaData::CoverArtUrlSmall); }
- void setCoverArtUrlSmall(const QVariant &url) {
- setMetaData(QMediaMetaData::CoverArtUrlSmall, url); }
- QVariant coverArtUrlLarge() const {
- return m_mediaObject->metaData(QMediaMetaData::CoverArtUrlLarge); }
- void setCoverArtUrlLarge(const QVariant &url) {
- setMetaData(QMediaMetaData::CoverArtUrlLarge, url); }
- QVariant resolution() const { return m_mediaObject->metaData(QMediaMetaData::Resolution); }
- void setResolution(const QVariant &resolution) {
- setMetaData(QMediaMetaData::Resolution, resolution); }
- QVariant pixelAspectRatio() const {
- return m_mediaObject->metaData(QMediaMetaData::PixelAspectRatio); }
- void setPixelAspectRatio(const QVariant &ratio) {
- setMetaData(QMediaMetaData::PixelAspectRatio, ratio); }
- QVariant videoFrameRate() const { return m_mediaObject->metaData(QMediaMetaData::VideoFrameRate); }
- void setVideoFrameRate(const QVariant &rate) {
- setMetaData(QMediaMetaData::VideoFrameRate, rate); }
- QVariant videoBitRate() const { return m_mediaObject->metaData(QMediaMetaData::VideoBitRate); }
- void setVideoBitRate(const QVariant &rate) {
- setMetaData(QMediaMetaData::VideoBitRate, rate); }
- QVariant videoCodec() const { return m_mediaObject->metaData(QMediaMetaData::VideoCodec); }
- void setVideoCodec(const QVariant &codec) {
- setMetaData(QMediaMetaData::VideoCodec, codec); }
- QVariant posterUrl() const { return m_mediaObject->metaData(QMediaMetaData::PosterUrl); }
- void setPosterUrl(const QVariant &url) {
- setMetaData(QMediaMetaData::PosterUrl, url); }
- QVariant chapterNumber() const { return m_mediaObject->metaData(QMediaMetaData::ChapterNumber); }
- void setChapterNumber(const QVariant &chapter) {
- setMetaData(QMediaMetaData::ChapterNumber, chapter); }
- QVariant director() const { return m_mediaObject->metaData(QMediaMetaData::Director); }
- void setDirector(const QVariant &director) { setMetaData(QMediaMetaData::Director, director); }
- QVariant leadPerformer() const { return m_mediaObject->metaData(QMediaMetaData::LeadPerformer); }
- void setLeadPerformer(const QVariant &performer) {
- setMetaData(QMediaMetaData::LeadPerformer, performer); }
- QVariant writer() const { return m_mediaObject->metaData(QMediaMetaData::Writer); }
- void setWriter(const QVariant &writer) { setMetaData(QMediaMetaData::Writer, writer); }
-
- QVariant cameraManufacturer() const {
- return m_mediaObject->metaData(QMediaMetaData::CameraManufacturer); }
- void setCameraManufacturer(const QVariant &manufacturer) {
- setMetaData(QMediaMetaData::CameraManufacturer, manufacturer); }
- QVariant cameraModel() const { return m_mediaObject->metaData(QMediaMetaData::CameraModel); }
- void setCameraModel(const QVariant &model) { setMetaData(QMediaMetaData::CameraModel, model); }
-
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_GCC("-Woverloaded-virtual")
-QT_WARNING_DISABLE_CLANG("-Woverloaded-virtual")
- QVariant event() const { return m_mediaObject->metaData(QMediaMetaData::Event); }
-QT_WARNING_POP
-
- void setEvent(const QVariant &event) { setMetaData(QMediaMetaData::Event, event); }
- QVariant subject() const { return m_mediaObject->metaData(QMediaMetaData::Subject); }
- void setSubject(const QVariant &subject) { setMetaData(QMediaMetaData::Subject, subject); }
- QVariant orientation() const { return m_mediaObject->metaData(QMediaMetaData::Orientation); }
- void setOrientation(const QVariant &orientation) {
- setMetaData(QMediaMetaData::Orientation, orientation); }
- QVariant exposureTime() const { return m_mediaObject->metaData(QMediaMetaData::ExposureTime); }
- void setExposureTime(const QVariant &time) { setMetaData(QMediaMetaData::ExposureTime, time); }
- QVariant fNumber() const { return m_mediaObject->metaData(QMediaMetaData::FNumber); }
- void setFNumber(const QVariant &number) { setMetaData(QMediaMetaData::FNumber, number); }
- QVariant exposureProgram() const {
- return m_mediaObject->metaData(QMediaMetaData::ExposureProgram); }
- void setExposureProgram(const QVariant &program) {
- setMetaData(QMediaMetaData::ExposureProgram, program); }
- QVariant isoSpeedRatings() const {
- return m_mediaObject->metaData(QMediaMetaData::ISOSpeedRatings); }
- void setISOSpeedRatings(const QVariant &ratings) {
- setMetaData(QMediaMetaData::ISOSpeedRatings, ratings); }
- QVariant exposureBiasValue() const {
- return m_mediaObject->metaData(QMediaMetaData::ExposureBiasValue); }
- void setExposureBiasValue(const QVariant &bias) {
- setMetaData(QMediaMetaData::ExposureBiasValue, bias); }
- QVariant dateTimeOriginal() const {
- return m_mediaObject->metaData(QMediaMetaData::DateTimeOriginal); }
- void setDateTimeOriginal(const QVariant &dateTime) {
- setMetaData(QMediaMetaData::DateTimeOriginal, dateTime); }
- QVariant dateTimeDigitized() const {
- return m_mediaObject->metaData(QMediaMetaData::DateTimeDigitized); }
- void setDateTimeDigitized(const QVariant &dateTime) {
- setMetaData(QMediaMetaData::DateTimeDigitized, dateTime); }
- QVariant subjectDistance() const {
- return m_mediaObject->metaData(QMediaMetaData::SubjectDistance); }
- void setSubjectDistance(const QVariant &distance) {
- setMetaData(QMediaMetaData::SubjectDistance, distance); }
- QVariant meteringMode() const { return m_mediaObject->metaData(QMediaMetaData::MeteringMode); }
- void setMeteringMode(const QVariant &mode) { setMetaData(QMediaMetaData::MeteringMode, mode); }
- QVariant lightSource() const { return m_mediaObject->metaData(QMediaMetaData::LightSource); }
- void setLightSource(const QVariant &source) {
- setMetaData(QMediaMetaData::LightSource, source); }
- QVariant flash() const { return m_mediaObject->metaData(QMediaMetaData::Flash); }
- void setFlash(const QVariant &flash) { setMetaData(QMediaMetaData::Flash, flash); }
- QVariant focalLength() const { return m_mediaObject->metaData(QMediaMetaData::FocalLength); }
- void setFocalLength(const QVariant &length) {
- setMetaData(QMediaMetaData::FocalLength, length); }
- QVariant exposureMode() const { return m_mediaObject->metaData(QMediaMetaData::ExposureMode); }
- void setExposureMode(const QVariant &mode) {
- setMetaData(QMediaMetaData::ExposureMode, mode); }
- QVariant whiteBalance() const { return m_mediaObject->metaData(QMediaMetaData::WhiteBalance); }
- void setWhiteBalance(const QVariant &balance) {
- setMetaData(QMediaMetaData::WhiteBalance, balance); }
- QVariant digitalZoomRatio() const {
- return m_mediaObject->metaData(QMediaMetaData::DigitalZoomRatio); }
- void setDigitalZoomRatio(const QVariant &ratio) {
- setMetaData(QMediaMetaData::DigitalZoomRatio, ratio); }
- QVariant focalLengthIn35mmFilm() const {
- return m_mediaObject->metaData(QMediaMetaData::FocalLengthIn35mmFilm); }
- void setFocalLengthIn35mmFilm(const QVariant &length) {
- setMetaData(QMediaMetaData::FocalLengthIn35mmFilm, length); }
- QVariant sceneCaptureType() const {
- return m_mediaObject->metaData(QMediaMetaData::SceneCaptureType); }
- void setSceneCaptureType(const QVariant &type) {
- setMetaData(QMediaMetaData::SceneCaptureType, type); }
- QVariant gainControl() const { return m_mediaObject->metaData(QMediaMetaData::GainControl); }
- void setGainControl(const QVariant &gain) { setMetaData(QMediaMetaData::GainControl, gain); }
- QVariant contrast() const { return m_mediaObject->metaData(QMediaMetaData::Contrast); }
- void setContrast(const QVariant &contrast) { setMetaData(QMediaMetaData::Contrast, contrast); }
- QVariant saturation() const { return m_mediaObject->metaData(QMediaMetaData::Saturation); }
- void setSaturation(const QVariant &saturation) {
- setMetaData(QMediaMetaData::Saturation, saturation); }
- QVariant sharpness() const { return m_mediaObject->metaData(QMediaMetaData::Sharpness); }
- void setSharpness(const QVariant &sharpness) {
- setMetaData(QMediaMetaData::Sharpness, sharpness); }
- QVariant deviceSettingDescription() const {
- return m_mediaObject->metaData(QMediaMetaData::DeviceSettingDescription); }
- void setDeviceSettingDescription(const QVariant &description) {
- setMetaData(QMediaMetaData::DeviceSettingDescription, description); }
-
- QVariant gpsLatitude() const { return m_mediaObject->metaData(QMediaMetaData::GPSLatitude); }
- void setGPSLatitude(const QVariant &latitude) {
- setMetaData(QMediaMetaData::GPSLatitude, latitude); }
- QVariant gpsLongitude() const { return m_mediaObject->metaData(QMediaMetaData::GPSLongitude); }
- void setGPSLongitude(const QVariant &longitude) {
- setMetaData(QMediaMetaData::GPSLongitude, longitude); }
- QVariant gpsAltitude() const { return m_mediaObject->metaData(QMediaMetaData::GPSAltitude); }
- void setGPSAltitude(const QVariant &altitude) {
- setMetaData(QMediaMetaData::GPSAltitude, altitude); }
- QVariant gpsTimeStamp() const { return m_mediaObject->metaData(QMediaMetaData::GPSTimeStamp); }
- void setGPSTimeStamp(const QVariant &timestamp) {
- setMetaData(QMediaMetaData::GPSTimeStamp, timestamp); }
- QVariant gpsSatellites() const {
- return m_mediaObject->metaData(QMediaMetaData::GPSSatellites); }
- void setGPSSatellites(const QVariant &satellites) {
- setMetaData(QMediaMetaData::GPSSatellites, satellites); }
- QVariant gpsStatus() const { return m_mediaObject->metaData(QMediaMetaData::GPSStatus); }
- void setGPSStatus(const QVariant &status) { setMetaData(QMediaMetaData::GPSStatus, status); }
- QVariant gpsDOP() const { return m_mediaObject->metaData(QMediaMetaData::GPSDOP); }
- void setGPSDOP(const QVariant &dop) { setMetaData(QMediaMetaData::GPSDOP, dop); }
- QVariant gpsSpeed() const { return m_mediaObject->metaData(QMediaMetaData::GPSSpeed); }
- void setGPSSpeed(const QVariant &speed) { setMetaData(QMediaMetaData::GPSSpeed, speed); }
- QVariant gpsTrack() const { return m_mediaObject->metaData(QMediaMetaData::GPSTrack); }
- void setGPSTrack(const QVariant &track) { setMetaData(QMediaMetaData::GPSTrack, track); }
- QVariant gpsTrackRef() const { return m_mediaObject->metaData(QMediaMetaData::GPSTrackRef); }
- void setGPSTrackRef(const QVariant &ref) { setMetaData(QMediaMetaData::GPSTrackRef, ref); }
- QVariant gpsImgDirection() const {
- return m_mediaObject->metaData(QMediaMetaData::GPSImgDirection); }
- void setGPSImgDirection(const QVariant &direction) {
- setMetaData(QMediaMetaData::GPSImgDirection, direction); }
- QVariant gpsImgDirectionRef() const {
- return m_mediaObject->metaData(QMediaMetaData::GPSImgDirectionRef); }
- void setGPSImgDirectionRef(const QVariant &ref) {
- setMetaData(QMediaMetaData::GPSImgDirectionRef, ref); }
- QVariant gpsMapDatum() const { return m_mediaObject->metaData(QMediaMetaData::GPSMapDatum); }
- void setGPSMapDatum(const QVariant &datum) {
- setMetaData(QMediaMetaData::GPSMapDatum, datum); }
- QVariant gpsProcessingMethod() const {
- return m_mediaObject->metaData(QMediaMetaData::GPSProcessingMethod); }
- void setGPSProcessingMethod(const QVariant &method) {
- setMetaData(QMediaMetaData::GPSProcessingMethod, method); }
- QVariant gpsAreaInformation() const {
- return m_mediaObject->metaData(QMediaMetaData::GPSAreaInformation); }
- void setGPSAreaInformation(const QVariant &information) {
- setMetaData(QMediaMetaData::GPSAreaInformation, information); }
-
-Q_SIGNALS:
- void metaDataChanged();
-
-private:
- void setMetaData(const QString &key, const QVariant &value)
- {
- if (!m_requestedWriterControl) {
- m_requestedWriterControl = true;
- if (QMediaService *service = m_mediaObject->service())
- m_writerControl = service->requestControl<QMetaDataWriterControl *>();
- }
- if (m_writerControl)
- m_writerControl->setMetaData(key, value);
- }
-
- QMediaObject *m_mediaObject;
- QMetaDataWriterControl *m_writerControl;
- bool m_requestedWriterControl;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeMediaMetaData))
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativemultimediaglobal.cpp b/src/imports/multimedia/qdeclarativemultimediaglobal.cpp
deleted file mode 100644
index ac7a6496f..000000000
--- a/src/imports/multimedia/qdeclarativemultimediaglobal.cpp
+++ /dev/null
@@ -1,239 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativemultimediaglobal_p.h"
-
-#include <qcamerainfo.h>
-#include <qjsengine.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
-\qmltype QtMultimedia
-\inqmlmodule QtMultimedia
-\ingroup multimedia_qml
-\since 5.4
-\brief Provides a global object with useful functions from Qt Multimedia.
-
-The \c QtMultimedia object is a global object with utility functions and properties.
-
-It is not instantiable; to use it, call the members of the global \c QtMultimedia object directly.
-For example:
-
-\qml
-Camera {
- deviceId: QtMultimedia.defaultCamera.deviceId
-}
-\endqml
-
-*/
-
-/*!
- \qmlproperty object QtMultimedia::QtMultimedia::defaultCamera
- \readonly
-
- The \c defaultCamera object provides information about the default camera on the system.
-
- Its properties are \c deviceId, \c displayName, \c position and \c orientation. See
- \l{QtMultimedia::QtMultimedia::availableCameras}{availableCameras} for a description of each
- of them.
-
- If there is no default camera, \c defaultCamera.deviceId will contain an empty string.
-
- \note This property is static; it is not updated if the system's default camera changes after the
- application started.
-*/
-
-/*!
- \qmlproperty list<object> QtMultimedia::QtMultimedia::availableCameras
- \readonly
-
- This property provides information about the cameras available on the system.
-
- Each object in the list has the following properties:
-
- \table
- \row
- \li \c deviceId
- \li
- This read-only property holds the unique identifier of the camera.
-
- You can choose which device to use with a \l Camera object by setting its
- \l{Camera::deviceId}{deviceId} property to this value.
-
- \row
- \li \c displayName
- \li
- This read-only property holds the human-readable name of the camera.
- You can use this property to display the name of the camera in a user interface.
-
- \row
- \li \c position
- \li
- This read-only property holds the physical position of the camera on the hardware system.
- Please see \l{Camera::position}{Camera.position} for more information.
-
- \row
- \li \c orientation
- \li
- This read-only property holds the physical orientation of the camera sensor.
- Please see \l{Camera::orientation}{Camera.orientation} for more information.
-
- \endtable
-
- \note This property is static; it is not updated when cameras are added or removed from
- the system, like USB cameras on a desktop platform.
-
- The following example shows how to display a list of available cameras. The user can change
- the active camera by selecting one of the items in the list.
-
- \qml
- Item {
-
- Camera {
- id: camera
- }
-
- VideoOutput {
- anchors.fill: parent
- source: camera
- }
-
- ListView {
- anchors.fill: parent
-
- model: QtMultimedia.availableCameras
- delegate: Text {
- text: modelData.displayName
-
- MouseArea {
- anchors.fill: parent
- onClicked: camera.deviceId = modelData.deviceId
- }
- }
- }
- }
-
- \endqml
-*/
-
-static QJSValue cameraInfoToJSValue(QJSEngine *jsEngine, const QCameraInfo &camera)
-{
- QJSValue o = jsEngine->newObject();
- o.setProperty(QStringLiteral("deviceId"), camera.deviceName());
- o.setProperty(QStringLiteral("displayName"), camera.description());
- o.setProperty(QStringLiteral("position"), int(camera.position()));
- o.setProperty(QStringLiteral("orientation"), camera.orientation());
- return o;
-}
-
-QDeclarativeMultimediaGlobal::QDeclarativeMultimediaGlobal(QJSEngine *engine, QObject *parent)
- : QObject(parent)
- , m_engine(engine)
-{
-}
-
-QJSValue QDeclarativeMultimediaGlobal::defaultCamera() const
-{
- return cameraInfoToJSValue(m_engine, QCameraInfo::defaultCamera());
-}
-
-QJSValue QDeclarativeMultimediaGlobal::availableCameras() const
-{
- QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
- QJSValue availableCameras = m_engine->newArray(cameras.count());
- for (int i = 0; i < cameras.count(); ++i)
- availableCameras.setProperty(i, cameraInfoToJSValue(m_engine, cameras.at(i)));
- return availableCameras;
-}
-
-/*!
- \qmlmethod real QtMultimedia::QtMultimedia::convertVolume(real volume, VolumeScale from, VolumeScale to)
-
- Converts an audio \a volume \a from a volume scale \a to another, and returns the result.
-
- Depending on the context, different scales are used to represent audio volume. All Qt Multimedia
- classes that have an audio volume use a linear scale, the reason is that the loudness of a
- speaker is controlled by modulating its voltage on a linear scale. The human ear on the other
- hand, perceives loudness in a logarithmic way. Using a logarithmic scale for volume controls
- is therefore appropriate in most applications. The decibel scale is logarithmic by nature and
- is commonly used to define sound levels, it is usually used for UI volume controls in
- professional audio applications. The cubic scale is a computationally cheap approximation of a
- logarithmic scale, it provides more control over lower volume levels.
-
- Valid values for \a from and \a to are:
- \list
- \li QtMultimedia.LinearVolumeScale - Linear scale. \c 0.0 (0%) is silence and \c 1.0 (100%) is
- full volume. All Qt Multimedia types that have an audio volume use a linear scale.
- \li QtMultimedia.CubicVolumeScale - Cubic scale. \c 0.0 (0%) is silence and \c 1.0 (100%) is full
- volume.
- \li QtMultimedia.LogarithmicVolumeScale - Logarithmic scale. \c 0.0 (0%) is silence and \c 1.0
- (100%) is full volume. UI volume controls should usually use a logarithmic scale.
- \li QtMultimedia.DecibelVolumeScale - Decibel (dB, amplitude) logarithmic scale. \c -200 is
- silence and \c 0 is full volume.
- \endlist
-
- The following example shows how the volume value from a UI volume control can be converted so
- that the perceived increase in loudness is the same when increasing the volume control from 0.2
- to 0.3 as it is from 0.5 to 0.6:
-
- \code
- Slider {
- id: volumeSlider
-
- property real volume: QtMultimedia.convertVolume(volumeSlider.value,
- QtMultimedia.LogarithmicVolumeScale,
- QtMultimedia.LinearVolumeScale)
- }
-
- MediaPlayer {
- volume: volumeSlider.volume
- }
- \endcode
-
- \since 5.8
-*/
-qreal QDeclarativeMultimediaGlobal::convertVolume(qreal volume,
- QDeclarativeMultimediaGlobal::VolumeScale from,
- QDeclarativeMultimediaGlobal::VolumeScale to) const
-{
- return QAudio::convertVolume(volume, QAudio::VolumeScale(from), QAudio::VolumeScale(to));
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/multimedia/qdeclarativemultimediaglobal_p.h b/src/imports/multimedia/qdeclarativemultimediaglobal_p.h
deleted file mode 100644
index 101bd899a..000000000
--- a/src/imports/multimedia/qdeclarativemultimediaglobal_p.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEMULTIMEDIAGLOBAL_P_H
-#define QDECLARATIVEMULTIMEDIAGLOBAL_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtQml/qqml.h>
-#include <QtQml/qjsvalue.h>
-#include <QtMultimedia/qaudio.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeMultimediaGlobal : public QObject
-{
- Q_OBJECT
-
- Q_PROPERTY(QJSValue defaultCamera READ defaultCamera NOTIFY defaultCameraChanged)
- Q_PROPERTY(QJSValue availableCameras READ availableCameras NOTIFY availableCamerasChanged)
-
- Q_ENUMS(VolumeScale)
-
-public:
- enum VolumeScale {
- LinearVolumeScale = QAudio::LinearVolumeScale,
- CubicVolumeScale = QAudio::CubicVolumeScale,
- LogarithmicVolumeScale = QAudio::LogarithmicVolumeScale,
- DecibelVolumeScale = QAudio::DecibelVolumeScale
- };
-
- explicit QDeclarativeMultimediaGlobal(QJSEngine *engine, QObject *parent = 0);
-
- QJSValue defaultCamera() const;
- QJSValue availableCameras() const;
-
- Q_INVOKABLE qreal convertVolume(qreal volume, VolumeScale from, VolumeScale to) const;
-
-Q_SIGNALS:
- // Unused at the moment. QCameraInfo doesn't notify when cameras are added or removed,
- // but it might change in the future.
- void defaultCameraChanged();
- void availableCamerasChanged();
-
-private:
- QJSEngine *m_engine;
-};
-
-QT_END_NAMESPACE
-
-#endif // QDECLARATIVEMULTIMEDIAGLOBAL_P_H
diff --git a/src/imports/multimedia/qdeclarativeplaylist.cpp b/src/imports/multimedia/qdeclarativeplaylist.cpp
deleted file mode 100644
index 400e23467..000000000
--- a/src/imports/multimedia/qdeclarativeplaylist.cpp
+++ /dev/null
@@ -1,660 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativeplaylist_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype PlaylistItem
- \instantiates QDeclarativePlaylistItem
- \since 5.6
-
- \inqmlmodule QtMultimedia
- \ingroup multimedia_qml
- \ingroup multimedia_audio_qml
- \ingroup multimedia_video_qml
- \brief Defines an item in a Playlist.
-
- \sa Playlist
-*/
-
-/*!
- \qmlproperty url QtMultimedia::PlaylistItem::source
-
- This property holds the source URL of the item.
-
- \sa Playlist
-*/
-QDeclarativePlaylistItem::QDeclarativePlaylistItem(QObject *parent)
- : QObject(parent)
-{
-}
-
-QUrl QDeclarativePlaylistItem::source() const
-{
- return m_source;
-}
-
-void QDeclarativePlaylistItem::setSource(const QUrl &source)
-{
- m_source = source;
-}
-
-/*!
- \qmltype Playlist
- \instantiates QDeclarativePlaylist
- \since 5.6
- \brief For specifying a list of media to be played.
-
- \inqmlmodule QtMultimedia
- \ingroup multimedia_qml
- \ingroup multimedia_audio_qml
- \ingroup multimedia_video_qml
-
- The Playlist type provides a way to play a list of media with the MediaPlayer, Audio and Video
- types. It can be used as a data source for view elements (such as ListView) and other elements
- that interact with model data (such as Repeater). When used as a data model, each playlist
- item's source URL can be accessed using the \c source role.
-
- \qml
- Item {
- width: 400;
- height: 300;
-
- Audio {
- id: player;
- playlist: Playlist {
- id: playlist
- PlaylistItem { source: "song1.ogg"; }
- PlaylistItem { source: "song2.ogg"; }
- PlaylistItem { source: "song3.ogg"; }
- }
- }
-
- ListView {
- model: playlist;
- delegate: Text {
- font.pixelSize: 16;
- text: source;
- }
- }
-
- MouseArea {
- anchors.fill: parent;
- onPressed: {
- if (player.playbackState != Audio.PlayingState) {
- player.play();
- } else {
- player.pause();
- }
- }
- }
- }
- \endqml
-
- \sa MediaPlayer, Audio, Video
-*/
-
-void QDeclarativePlaylist::_q_mediaAboutToBeInserted(int start, int end)
-{
- emit itemAboutToBeInserted(start, end);
-
- beginInsertRows(QModelIndex(), start, end);
-}
-
-void QDeclarativePlaylist::_q_mediaInserted(int start, int end)
-{
- endInsertRows();
-
- emit itemCountChanged();
- emit itemInserted(start, end);
-}
-
-void QDeclarativePlaylist::_q_mediaAboutToBeRemoved(int start, int end)
-{
- emit itemAboutToBeRemoved(start, end);
-
- beginRemoveRows(QModelIndex(), start, end);
-}
-
-void QDeclarativePlaylist::_q_mediaRemoved(int start, int end)
-{
- endRemoveRows();
-
- emit itemCountChanged();
- emit itemRemoved(start, end);
-}
-
-void QDeclarativePlaylist::_q_mediaChanged(int start, int end)
-{
- emit dataChanged(createIndex(start, 0), createIndex(end, 0));
- emit itemChanged(start, end);
-}
-
-void QDeclarativePlaylist::_q_loadFailed()
-{
- m_error = m_playlist->error();
- m_errorString = m_playlist->errorString();
-
- emit error(Error(m_error), m_errorString);
- emit errorChanged();
- emit loadFailed();
-}
-
-QDeclarativePlaylist::QDeclarativePlaylist(QObject *parent)
- : QAbstractListModel(parent)
- , m_playlist(0)
- , m_error(QMediaPlaylist::NoError)
- , m_readOnly(false)
-{
-}
-
-QDeclarativePlaylist::~QDeclarativePlaylist()
-{
- delete m_playlist;
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::Playlist::playbackMode
-
- This property holds the order in which items in the playlist are played.
-
- \table
- \header \li Value \li Description
- \row \li CurrentItemOnce
- \li The current item is played only once.
- \row \li CurrentItemInLoop
- \li The current item is played repeatedly in a loop.
- \row \li Sequential
- \li Playback starts from the current and moves through each successive item until the last
- is reached and then stops. The next item is a null item when the last one is currently
- playing.
- \row \li Loop
- \li Playback restarts at the first item after the last has finished playing.
- \row \li Random
- \li Play items in random order.
- \endtable
- */
-QDeclarativePlaylist::PlaybackMode QDeclarativePlaylist::playbackMode() const
-{
- return PlaybackMode(m_playlist->playbackMode());
-}
-
-void QDeclarativePlaylist::setPlaybackMode(PlaybackMode mode)
-{
- if (playbackMode() == mode)
- return;
-
- m_playlist->setPlaybackMode(QMediaPlaylist::PlaybackMode(mode));
-}
-
-/*!
- \qmlproperty url QtMultimedia::Playlist::currentItemsource
-
- This property holds the source URL of the current item in the playlist.
- */
-QUrl QDeclarativePlaylist::currentItemSource() const
-{
- return m_playlist->currentMedia().request().url();
-}
-
-/*!
- \qmlproperty int QtMultimedia::Playlist::currentIndex
-
- This property holds the position of the current item in the playlist.
- */
-int QDeclarativePlaylist::currentIndex() const
-{
- return m_playlist->currentIndex();
-}
-
-void QDeclarativePlaylist::setCurrentIndex(int index)
-{
- if (currentIndex() == index)
- return;
-
- m_playlist->setCurrentIndex(index);
-}
-
-/*!
- \qmlproperty int QtMultimedia::Playlist::itemCount
-
- This property holds the number of items in the playlist.
- */
-int QDeclarativePlaylist::itemCount() const
-{
- return m_playlist->mediaCount();
-}
-
-/*!
- \qmlproperty bool QtMultimedia::Playlist::readOnly
-
- This property indicates if the playlist can be modified.
- */
-bool QDeclarativePlaylist::readOnly() const
-{
- // There's no signal to tell whether or not the read only state changed, so we consider it fixed
- // after its initial retrieval in componentComplete().
- return m_readOnly;
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::Playlist::error
-
- This property holds the error condition of the playlist.
-
- \table
- \header \li Value \li Description
- \row \li NoError
- \li No errors
- \row \li FormatError
- \li Format error.
- \row \li FormatNotSupportedError
- \li Format not supported.
- \row \li NetworkError
- \li Network error.
- \row \li AccessDeniedError
- \li Access denied error.
- \endtable
- */
-QDeclarativePlaylist::Error QDeclarativePlaylist::error() const
-{
- return Error(m_error);
-}
-
-/*!
- \qmlproperty string QtMultimedia::Playlist::errorString
-
- This property holds a string describing the current error condition of the playlist.
-*/
-QString QDeclarativePlaylist::errorString() const
-{
- return m_errorString;
-}
-
-/*!
- \qmlmethod url QtMultimedia::Playlist::itemSource(index)
-
- Returns the source URL of the item at the given \a index in the playlist.
-*/
-QUrl QDeclarativePlaylist::itemSource(int index)
-{
- return m_playlist->media(index).request().url();
-}
-
-/*!
- \qmlmethod int QtMultimedia::Playlist::nextIndex(steps)
-
- Returns the index of the item in the playlist which would be current after calling next()
- \a steps times.
-
- Returned value depends on the size of the playlist, the current position and the playback mode.
-
- \sa playbackMode, previousIndex()
-*/
-int QDeclarativePlaylist::nextIndex(int steps)
-{
- return m_playlist->nextIndex(steps);
-}
-
-/*!
- \qmlmethod int QtMultimedia::Playlist::previousIndex(steps)
-
- Returns the index of the item in the playlist which would be current after calling previous()
- \a steps times.
-
- Returned value depends on the size of the playlist, the current position and the playback mode.
-
- \sa playbackMode, nextIndex()
-*/
-int QDeclarativePlaylist::previousIndex(int steps)
-{
- return m_playlist->previousIndex(steps);
-}
-
-/*!
- \qmlmethod QtMultimedia::Playlist::next()
-
- Advances to the next item in the playlist.
-*/
-void QDeclarativePlaylist::next()
-{
- m_playlist->next();
-}
-
-/*!
- \qmlmethod QtMultimedia::Playlist::previous()
-
- Returns to the previous item in the playlist.
-*/
-void QDeclarativePlaylist::previous()
-{
- m_playlist->previous();
-}
-
-/*!
- \qmlmethod QtMultimedia::Playlist::shuffle()
-
- Shuffles items in the playlist.
-*/
-void QDeclarativePlaylist::shuffle()
-{
- m_playlist->shuffle();
-}
-
-/*!
- \qmlmethod QtMultimedia::Playlist::load(location, format)
-
- Loads a playlist from the given \a location. If \a format is specified, it is used, otherwise
- the format is guessed from the location name and the data.
-
- New items are appended to the playlist.
-
- \c onloaded() is emitted if the playlist loads successfully, otherwise \c onLoadFailed() is
- emitted with \l error and \l errorString defined accordingly.
-*/
-void QDeclarativePlaylist::load(const QUrl &location, const QString &format)
-{
- m_error = QMediaPlaylist::NoError;
- m_errorString = QString();
- emit errorChanged();
- m_playlist->load(location, format.toLatin1().constData());
-}
-
-/*!
- \qmlmethod bool QtMultimedia::Playlist::save(location, format)
-
- Saves the playlist to the given \a location. If \a format is specified, it is used, otherwise
- the format is guessed from the location name.
-
- Returns true if the playlist is saved successfully.
-*/
-bool QDeclarativePlaylist::save(const QUrl &location, const QString &format)
-{
- return m_playlist->save(location, format.toLatin1().constData());
-}
-
-/*!
- \qmlmethod bool QtMultimedia::Playlist::addItem(source)
-
- Appends the \a source URL to the playlist.
-
- Returns true if the \a source is added successfully.
-*/
-bool QDeclarativePlaylist::addItem(const QUrl &source)
-{
- return m_playlist->addMedia(QMediaContent(source));
-}
-
-/*!
- \qmlmethod bool QtMultimedia::Playlist::addItems(sources)
-
- Appends the list of URLs in \a sources to the playlist.
-
- Returns true if the \a sources are added successfully.
-
- \since 5.7
-*/
-bool QDeclarativePlaylist::addItems(const QList<QUrl> &sources)
-{
- if (sources.isEmpty())
- return false;
-
- QList<QMediaContent> contents;
- QList<QUrl>::const_iterator it = sources.constBegin();
- while (it != sources.constEnd()) {
- contents.push_back(QMediaContent(*it));
- ++it;
- }
- return m_playlist->addMedia(contents);
-}
-
-/*!
- \qmlmethod bool QtMultimedia::Playlist::insertItem(index, source)
-
- Inserts the \a source URL to the playlist at the given \a index.
-
- Returns true if the \a source is added successfully.
-*/
-bool QDeclarativePlaylist::insertItem(int index, const QUrl &source)
-{
- return m_playlist->insertMedia(index, QMediaContent(source));
-}
-
-/*!
- \qmlmethod bool QtMultimedia::Playlist::insertItems(index, sources)
-
- Inserts the list of URLs in \a sources to the playlist at the given \a index.
-
- Returns true if the \a sources are added successfully.
-
- \since 5.7
-*/
-bool QDeclarativePlaylist::insertItems(int index, const QList<QUrl> &sources)
-{
- if (sources.empty())
- return false;
-
- QList<QMediaContent> contents;
- QList<QUrl>::const_iterator it = sources.constBegin();
- while (it != sources.constEnd()) {
- contents.push_back(QMediaContent(*it));
- ++it;
- }
- return m_playlist->insertMedia(index, contents);
-}
-
-/*!
- \qmlmethod bool QtMultimedia::Playlist::moveItem(from, to)
-
- Moves the item at index position \a from to index position \a to.
-
- Returns \c true if the item is moved successfully.
-
- \since 5.7
-*/
-bool QDeclarativePlaylist::moveItem(int from, int to)
-{
- return m_playlist->moveMedia(from, to);
-}
-
-/*!
- \qmlmethod bool QtMultimedia::Playlist::removeItem(index)
-
- Removes the item at the given \a index from the playlist.
-
- Returns \c true if the item is removed successfully.
-*/
-bool QDeclarativePlaylist::removeItem(int index)
-{
- return m_playlist->removeMedia(index);
-}
-
-/*!
- \qmlmethod bool QtMultimedia::Playlist::removeItems(int start, int end)
-
- Removes items in the playlist from \a start to \a end inclusive.
-
- Returns \c true if the items are removed successfully.
-
- \since 5.7
-*/
-bool QDeclarativePlaylist::removeItems(int start, int end)
-{
- return m_playlist->removeMedia(start, end);
-}
-
-/*!
- \qmlmethod bool QtMultimedia::Playlist::clear()
-
- Removes all the items from the playlist.
-
- Returns \c true if the operation is successful.
-*/
-bool QDeclarativePlaylist::clear()
-{
- return m_playlist->clear();
-}
-
-int QDeclarativePlaylist::rowCount(const QModelIndex &parent) const
-{
- if (parent.isValid())
- return 0;
-
- return m_playlist->mediaCount();
-}
-
-QVariant QDeclarativePlaylist::data(const QModelIndex &index, int role) const
-{
- Q_UNUSED(role);
-
- if (!index.isValid())
- return QVariant();
-
- return m_playlist->media(index.row()).request().url();
-}
-
-QHash<int, QByteArray> QDeclarativePlaylist::roleNames() const
-{
- QHash<int, QByteArray> roleNames;
- roleNames[SourceRole] = "source";
- return roleNames;
-}
-
-void QDeclarativePlaylist::classBegin()
-{
- m_playlist = new QMediaPlaylist(this);
-
- connect(m_playlist, SIGNAL(currentIndexChanged(int)),
- this, SIGNAL(currentIndexChanged()));
- connect(m_playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)),
- this, SIGNAL(playbackModeChanged()));
- connect(m_playlist, SIGNAL(currentMediaChanged(QMediaContent)),
- this, SIGNAL(currentItemSourceChanged()));
- connect(m_playlist, SIGNAL(mediaAboutToBeInserted(int,int)),
- this, SLOT(_q_mediaAboutToBeInserted(int,int)));
- connect(m_playlist, SIGNAL(mediaInserted(int,int)),
- this, SLOT(_q_mediaInserted(int,int)));
- connect(m_playlist, SIGNAL(mediaAboutToBeRemoved(int,int)),
- this, SLOT(_q_mediaAboutToBeRemoved(int,int)));
- connect(m_playlist, SIGNAL(mediaRemoved(int,int)),
- this, SLOT(_q_mediaRemoved(int,int)));
- connect(m_playlist, SIGNAL(mediaChanged(int,int)),
- this, SLOT(_q_mediaChanged(int,int)));
- connect(m_playlist, SIGNAL(loaded()),
- this, SIGNAL(loaded()));
- connect(m_playlist, SIGNAL(loadFailed()),
- this, SLOT(_q_loadFailed()));
-
- if (m_playlist->isReadOnly()) {
- m_readOnly = true;
- emit readOnlyChanged();
- }
-}
-
-void QDeclarativePlaylist::componentComplete()
-{
-}
-
-/*!
- \qmlsignal QtMultimedia::Playlist::itemAboutToBeInserted(start, end)
-
- This signal is emitted when items are to be inserted into the playlist at \a start and ending at
- \a end.
-
- The corresponding handler is \c onItemAboutToBeInserted.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Playlist::itemInserted(start, end)
-
- This signal is emitted after items have been inserted into the playlist. The new items are those
- between \a start and \a end inclusive.
-
- The corresponding handler is \c onItemInserted.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Playlist::itemAboutToBeRemoved(start, end)
-
- This signal emitted when items are to be deleted from the playlist at \a start and ending at
- \a end.
-
- The corresponding handler is \c onItemAboutToBeRemoved.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Playlist::itemRemoved(start, end)
-
- This signal is emitted after items have been removed from the playlist. The removed items are
- those between \a start and \a end inclusive.
-
- The corresponding handler is \c onMediaRemoved.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Playlist::itemChanged(start, end)
-
- This signal is emitted after items have been changed in the playlist between \a start and
- \a end positions inclusive.
-
- The corresponding handler is \c onItemChanged.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Playlist::loaded()
-
- This signal is emitted when the playlist loading succeeded.
-
- The corresponding handler is \c onLoaded.
-*/
-
-/*!
- \qmlsignal QtMultimedia::Playlist::loadFailed()
-
- This signal is emitted when the playlist loading failed. \l error and \l errorString can be
- checked for more information on the failure.
-
- The corresponding handler is \c onLoadFailed.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qdeclarativeplaylist_p.cpp"
diff --git a/src/imports/multimedia/qdeclarativeplaylist_p.h b/src/imports/multimedia/qdeclarativeplaylist_p.h
deleted file mode 100644
index fa221a05b..000000000
--- a/src/imports/multimedia/qdeclarativeplaylist_p.h
+++ /dev/null
@@ -1,209 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEPLAYLIST_P_H
-#define QDECLARATIVEPLAYLIST_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/QAbstractListModel>
-#include <QtQml/qqmlparserstatus.h>
-#include <QtQml/qqml.h>
-
-#include <qmediaplaylist.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativePlaylistItem : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QUrl source READ source WRITE setSource)
-
-public:
- QDeclarativePlaylistItem(QObject *parent = 0);
-
- QUrl source() const;
- void setSource(const QUrl &source);
-
-private:
- QUrl m_source;
-};
-
-class QDeclarativePlaylist : public QAbstractListModel, public QQmlParserStatus
-{
- Q_OBJECT
- Q_PROPERTY(PlaybackMode playbackMode READ playbackMode WRITE setPlaybackMode NOTIFY playbackModeChanged)
- Q_PROPERTY(QUrl currentItemSource READ currentItemSource NOTIFY currentItemSourceChanged)
- Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
- Q_PROPERTY(int itemCount READ itemCount NOTIFY itemCountChanged)
- Q_PROPERTY(bool readOnly READ readOnly NOTIFY readOnlyChanged)
- Q_PROPERTY(Error error READ error NOTIFY errorChanged)
- Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
- Q_PROPERTY(QQmlListProperty<QDeclarativePlaylistItem> items READ items DESIGNABLE false)
- Q_ENUMS(PlaybackMode)
- Q_ENUMS(Error)
- Q_INTERFACES(QQmlParserStatus)
- Q_CLASSINFO("DefaultProperty", "items")
-
-public:
- enum PlaybackMode
- {
- CurrentItemOnce = QMediaPlaylist::CurrentItemOnce,
- CurrentItemInLoop = QMediaPlaylist::CurrentItemInLoop,
- Sequential = QMediaPlaylist::Sequential,
- Loop = QMediaPlaylist::Loop,
- Random = QMediaPlaylist::Random
- };
- enum Error
- {
- NoError = QMediaPlaylist::NoError,
- FormatError = QMediaPlaylist::FormatError,
- FormatNotSupportedError = QMediaPlaylist::FormatNotSupportedError,
- NetworkError = QMediaPlaylist::NetworkError,
- AccessDeniedError = QMediaPlaylist::AccessDeniedError
- };
- enum Roles
- {
- SourceRole = Qt::UserRole + 1
- };
-
- QDeclarativePlaylist(QObject *parent = 0);
- ~QDeclarativePlaylist();
-
- PlaybackMode playbackMode() const;
- void setPlaybackMode(PlaybackMode playbackMode);
- QUrl currentItemSource() const;
- int currentIndex() const;
- void setCurrentIndex(int currentIndex);
- int itemCount() const;
- bool readOnly() const;
- Error error() const;
- QString errorString() const;
- QMediaPlaylist *mediaPlaylist() const { return m_playlist; }
-
- int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
- QHash<int, QByteArray> roleNames() const override;
-
- void classBegin() override;
- void componentComplete() override;
-
- QQmlListProperty<QDeclarativePlaylistItem> items() {
- return QQmlListProperty<QDeclarativePlaylistItem>(
- this, 0, item_append, item_count, 0, item_clear);
- }
- static void item_append(QQmlListProperty<QDeclarativePlaylistItem> *list,
- QDeclarativePlaylistItem* item) {
- static_cast<QDeclarativePlaylist*>(list->object)->addItem(item->source());
- }
- static int item_count(QQmlListProperty<QDeclarativePlaylistItem> *list) {
- return static_cast<QDeclarativePlaylist*>(list->object)->itemCount();
- }
- static void item_clear(QQmlListProperty<QDeclarativePlaylistItem> *list) {
- static_cast<QDeclarativePlaylist*>(list->object)->clear();
- }
-
-public Q_SLOTS:
- QUrl itemSource(int index);
- int nextIndex(int steps = 1);
- int previousIndex(int steps = 1);
- void next();
- void previous();
- void shuffle();
- void load(const QUrl &location, const QString &format = QString());
- bool save(const QUrl &location, const QString &format = QString());
- bool addItem(const QUrl &source);
- Q_REVISION(1) bool addItems(const QList<QUrl> &sources);
- bool insertItem(int index, const QUrl &source);
- Q_REVISION(1) bool insertItems(int index, const QList<QUrl> &sources);
- Q_REVISION(1) bool moveItem(int from, int to);
- bool removeItem(int index);
- Q_REVISION(1) bool removeItems(int start, int end);
- bool clear();
-
-Q_SIGNALS:
- void playbackModeChanged();
- void currentItemSourceChanged();
- void currentIndexChanged();
- void itemCountChanged();
- void readOnlyChanged();
- void errorChanged();
-
- void itemAboutToBeInserted(int start, int end);
- void itemInserted(int start, int end);
- void itemAboutToBeRemoved(int start, int end);
- void itemRemoved(int start, int end);
- void itemChanged(int start, int end);
- void loaded();
- void loadFailed();
-
- void error(QDeclarativePlaylist::Error error, const QString &errorString);
-
-private Q_SLOTS:
- void _q_mediaAboutToBeInserted(int start, int end);
- void _q_mediaInserted(int start, int end);
- void _q_mediaAboutToBeRemoved(int start, int end);
- void _q_mediaRemoved(int start, int end);
- void _q_mediaChanged(int start, int end);
- void _q_loadFailed();
-
-private:
- Q_DISABLE_COPY(QDeclarativePlaylist)
-
- QMediaPlaylist *m_playlist;
- QString m_errorString;
- QMediaPlaylist::Error m_error;
- bool m_readOnly;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativePlaylistItem))
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativePlaylist))
-
-#endif
diff --git a/src/imports/multimedia/qdeclarativetorch.cpp b/src/imports/multimedia/qdeclarativetorch.cpp
deleted file mode 100644
index 954926b98..000000000
--- a/src/imports/multimedia/qdeclarativetorch.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QDebug>
-#include <QMediaService>
-
-#include "qdeclarativetorch_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype Torch
- \instantiates QDeclarativeTorch
- \inqmlmodule QtMultimedia
- \brief Simple control over torch functionality.
-
- \ingroup multimedia_qml
-
- In many cases the torch hardware is shared with camera flash functionality,
- and might be automatically controlled by the device. You have control over
- the power level (of course, higher power levels are brighter but reduce
- battery life significantly).
-
- \qml
-
- Torch {
- power: 75 // 75% of full power
- enabled: true // On
- }
-
- \endqml
-*/
-QDeclarativeTorch::QDeclarativeTorch(QObject *parent)
- : QObject(parent)
-{
- m_camera = new QCamera(this);
- QMediaService *service = m_camera->service();
-
- m_exposure = service ? service->requestControl<QCameraExposureControl*>() : 0;
- m_flash = service ? service->requestControl<QCameraFlashControl*>() : 0;
-
- if (m_exposure)
- connect(m_exposure, SIGNAL(actualValueChanged(int)), SLOT(parameterChanged(int)));
-
- // XXX There's no signal for flash mode changed
-}
-
-QDeclarativeTorch::~QDeclarativeTorch()
-{
-}
-
-/*!
- \qmlproperty bool QtMultimedia::Torch::enabled
-
- This property indicates whether the torch is enabled. If the torch functionality is shared
- with the camera flash hardware, the camera will take priority
- over torch settings and the torch is disabled.
-*/
-/*!
- \property QDeclarativeTorch::enabled
-
- This property indicates whether the torch is enabled. If the torch functionality
- is shared with the camera flash hardware, the camera will take
- priority and the torch is disabled.
- */
-bool QDeclarativeTorch::enabled() const
-{
- if (!m_flash)
- return false;
-
- return m_flash->flashMode() & QCameraExposure::FlashTorch;
-}
-
-
-/*!
- If \a on is true, attempt to turn on the torch.
- If the torch hardware is already in use by the camera, this will
- be ignored.
-*/
-void QDeclarativeTorch::setEnabled(bool on)
-{
- if (!m_flash)
- return;
-
- QCameraExposure::FlashModes mode = m_flash->flashMode();
-
- if (mode & QCameraExposure::FlashTorch) {
- if (!on) {
- m_flash->setFlashMode(mode & ~QCameraExposure::FlashTorch);
- emit enabledChanged();
- }
- } else {
- if (on) {
- m_flash->setFlashMode(mode | QCameraExposure::FlashTorch);
- emit enabledChanged();
- }
- }
-}
-
-/*!
- \qmlproperty int QtMultimedia::Torch::power
-
- This property holds the current torch power setting, as a percentage of full power.
-
- In some cases this setting may change automatically as a result
- of temperature or battery conditions.
-*/
-/*!
- \property QDeclarativeTorch::power
-
- This property holds the current torch power settings, as a percentage of full power.
-*/
-int QDeclarativeTorch::power() const
-{
- if (!m_exposure)
- return 0;
-
- return m_exposure->requestedValue(QCameraExposureControl::TorchPower).toInt();
-}
-
-/*!
- Sets the current torch power setting to \a power, as a percentage of
- full power.
-*/
-void QDeclarativeTorch::setPower(int power)
-{
- if (!m_exposure)
- return;
-
- power = qBound(0, power, 100);
- if (this->power() != power)
- m_exposure->setValue(QCameraExposureControl::TorchPower, power);
-}
-
-/* Check for changes in flash power */
-void QDeclarativeTorch::parameterChanged(int parameter)
-{
- if (parameter == QCameraExposureControl::FlashPower) {
- emit powerChanged();
- }
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/imports/multimedia/qdeclarativetorch_p.h b/src/imports/multimedia/qdeclarativetorch_p.h
deleted file mode 100644
index dffc20177..000000000
--- a/src/imports/multimedia/qdeclarativetorch_p.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QDECLARATIVETORCH_P_H
-#define QDECLARATIVETORCH_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/QObject>
-#include <QtQml/qqml.h>
-#include <qcamera.h>
-#include <qcameraexposurecontrol.h>
-#include <qcameraflashcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeTorch : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
- Q_PROPERTY(int power READ power WRITE setPower NOTIFY powerChanged)
-
- // Errors?
-
-public:
- explicit QDeclarativeTorch(QObject *parent = 0);
- ~QDeclarativeTorch();
-
- bool enabled() const;
- void setEnabled(bool enabled);
-
- int power() const;
- void setPower(int power);
-
-signals:
- void enabledChanged();
- void powerChanged();
-
-private slots:
- void parameterChanged(int parameter);
-
-private:
- QCamera *m_camera;
- QCameraExposureControl *m_exposure;
- QCameraFlashControl *m_flash;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeTorch))
-
-#endif // QDECLARATIVETORCH_P_H
diff --git a/src/imports/multimedia/qmldir b/src/imports/multimedia/qmldir
deleted file mode 100644
index 3d2d7c460..000000000
--- a/src/imports/multimedia/qmldir
+++ /dev/null
@@ -1,5 +0,0 @@
-module QtMultimedia
-plugin declarative_multimedia
-classname QMultimediaDeclarativeModule
-typeinfo plugins.qmltypes
-Video 5.0 Video.qml
diff --git a/src/multimedia/CMakeLists.txt b/src/multimedia/CMakeLists.txt
new file mode 100644
index 000000000..a17b1bfc7
--- /dev/null
+++ b/src/multimedia/CMakeLists.txt
@@ -0,0 +1,374 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Generated from multimedia.pro.
+
+#####################################################################
+## Multimedia Module:
+#####################################################################
+
+find_package(Qt6 COMPONENTS ShaderTools)
+
+qt_internal_find_apple_system_framework(FWCoreAudio CoreAudio) # special case
+qt_internal_find_apple_system_framework(FWCoreVideo CoreVideo) # special case
+qt_internal_find_apple_system_framework(FWAudioUnit AudioUnit) # special case
+qt_internal_find_apple_system_framework(FWCoreMedia CoreMedia) # special case
+qt_internal_find_apple_system_framework(FWAudioToolbox AudioToolbox) # special case
+
+qt_internal_add_module(Multimedia
+ PLUGIN_TYPES multimedia
+ SOURCES
+ audio/qtaudio.cpp audio/qtaudio.h audio/qaudio.h
+ audio/qaudiobuffer.cpp audio/qaudiobuffer.h
+ audio/qaudiodecoder.cpp audio/qaudiodecoder.h audio/qaudiodecoder_p.h
+ audio/qaudiodevice.cpp audio/qaudiodevice.h audio/qaudiodevice_p.h
+ audio/qaudioinput.cpp audio/qaudioinput.h
+ audio/qaudiobufferinput.cpp audio/qaudiobufferinput.h
+ audio/qaudiobufferoutput.cpp audio/qaudiobufferoutput.h audio/qaudiobufferoutput_p.h
+ audio/qaudiooutput.cpp audio/qaudiooutput.h
+ audio/qaudioformat.cpp audio/qaudioformat.h
+ audio/qaudiohelpers.cpp audio/qaudiohelpers_p.h
+ audio/qaudiosource.cpp audio/qaudiosource.h
+ audio/qaudiosink.cpp audio/qaudiosink.h
+ audio/qaudiosystem.cpp audio/qaudiosystem_p.h
+ audio/qaudiostatemachine.cpp audio/qaudiostatemachine_p.h
+ audio/qaudiostatemachineutils_p.h
+ audio/qsamplecache_p.cpp audio/qsamplecache_p.h
+ audio/qsoundeffect.cpp audio/qsoundeffect.h
+ audio/qwavedecoder.cpp audio/qwavedecoder.h
+ camera/qcamera.cpp camera/qcamera.h camera/qcamera_p.h
+ camera/qcameradevice.cpp camera/qcameradevice.h camera/qcameradevice_p.h
+ camera/qimagecapture.cpp camera/qimagecapture.h
+ compat/removed_api.cpp
+ platform/qgstreamer_platformspecificinterface.cpp platform/qgstreamer_platformspecificinterface_p.h
+ platform/qplatformaudiodecoder.cpp platform/qplatformaudiodecoder_p.h
+ platform/qplatformaudioinput_p.h
+ platform/qplatformaudiooutput_p.h
+ platform/qplatformaudioresampler_p.h
+ platform/qplatformcamera.cpp platform/qplatformcamera_p.h
+ platform/qplatformcapturablewindows_p.h
+ platform/qplatformimagecapture.cpp platform/qplatformimagecapture_p.h
+ platform/qplatformmediacapture.cpp platform/qplatformmediacapture_p.h
+ platform/qplatformmediadevices.cpp platform/qplatformmediadevices_p.h
+ platform/qplatformmediaformatinfo.cpp platform/qplatformmediaformatinfo_p.h
+ platform/qplatformmediaintegration.cpp platform/qplatformmediaintegration_p.h
+ platform/qplatformmediaplayer.cpp platform/qplatformmediaplayer_p.h
+ platform/qplatformmediaplugin.cpp platform/qplatformmediaplugin_p.h
+ platform/qplatformmediarecorder.cpp platform/qplatformmediarecorder_p.h
+ platform/qplatformsurfacecapture.cpp platform/qplatformsurfacecapture_p.h
+ platform/qplatformvideodevices.cpp platform/qplatformvideodevices_p.h
+ platform/qplatformvideosink.cpp platform/qplatformvideosink_p.h
+ platform/qplatformvideosource.cpp platform/qplatformvideosource_p.h
+ platform/qplatformvideoframeinput.cpp platform/qplatformvideoframeinput_p.h
+ platform/qplatformaudiobufferinput.cpp platform/qplatformaudiobufferinput_p.h
+ playback/qmediaplayer.cpp playback/qmediaplayer.h playback/qmediaplayer_p.h
+ qmediadevices.cpp qmediadevices.h
+ qmediaenumdebug.h
+ qmediaformat.cpp qmediaformat.h
+ qmediametadata.cpp qmediametadata.h
+ qmediastoragelocation.cpp qmediastoragelocation_p.h
+ qmediatimerange.cpp qmediatimerange.h
+ qmultimediautils.cpp qmultimediautils_p.h
+ qmediaframeinput.cpp qmediaframeinput_p.h
+ qmaybe_p.h
+ qtmultimediaglobal.h qtmultimediaglobal_p.h
+ qerrorinfo_p.h
+ qmediainputencoderinterface_p.h
+ recording/qmediacapturesession.cpp recording/qmediacapturesession.h recording/qmediacapturesession_p.h
+ recording/qmediarecorder.cpp recording/qmediarecorder.h recording/qmediarecorder_p.h
+ recording/qscreencapture.cpp recording/qscreencapture.h
+ recording/qwindowcapture.cpp recording/qwindowcapture.h
+ recording/qcapturablewindow.cpp recording/qcapturablewindow.h recording/qcapturablewindow_p.h
+ recording/qvideoframeinput.cpp recording/qvideoframeinput.h
+ video/qabstractvideobuffer.cpp video/qabstractvideobuffer.h
+ video/qhwvideobuffer.cpp video/qhwvideobuffer_p.h
+ video/qmemoryvideobuffer.cpp video/qmemoryvideobuffer_p.h
+ video/qimagevideobuffer.cpp video/qimagevideobuffer_p.h
+ video/qvideoframe.cpp video/qvideoframe.h video/qvideoframe_p.h
+ video/qvideosink.cpp video/qvideosink.h
+ video/qvideotexturehelper.cpp video/qvideotexturehelper_p.h
+ video/qvideoframeconversionhelper.cpp video/qvideoframeconversionhelper_p.h
+ video/qvideooutputorientationhandler.cpp video/qvideooutputorientationhandler_p.h
+ video/qvideoframeconverter.cpp video/qvideoframeconverter_p.h
+ video/qvideoframeformat.cpp video/qvideoframeformat.h
+ video/qvideowindow.cpp video/qvideowindow_p.h
+ video/qtvideo.cpp video/qtvideo.h
+ INCLUDE_DIRECTORIES
+ audio
+ camera
+ controls
+ platform
+ playback
+ recording
+ video
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::GuiPrivate
+ PUBLIC_LIBRARIES
+ Qt::Core
+ Qt::Gui
+ Qt::Network
+ PRIVATE_MODULE_INTERFACE
+ Qt::CorePrivate
+ Qt::GuiPrivate
+ NO_PCH_SOURCES
+ compat/removed_api.cpp
+ GENERATE_CPP_EXPORTS
+)
+
+qt_internal_extend_target(Multimedia
+ CONDITION LINUX OR ANDROID
+ SOURCES qsymbolsresolveutils.cpp qsymbolsresolveutils_p.h)
+
+qt_internal_add_simd_part(Multimedia SIMD sse2
+ SOURCES
+ video/qvideoframeconversionhelper_sse2.cpp
+)
+
+qt_internal_add_simd_part(Multimedia SIMD ssse3
+ SOURCES
+ video/qvideoframeconversionhelper_ssse3.cpp
+)
+
+qt_internal_add_simd_part(Multimedia SIMD arch_haswell
+ SOURCES
+ video/qvideoframeconversionhelper_avx2.cpp
+ EXCLUDE_OSX_ARCHITECTURES
+ arm64
+)
+
+qt_internal_add_docs(Multimedia
+ doc/qtmultimedia.qdocconf
+)
+
+qt_internal_extend_target(Multimedia CONDITION QT_FEATURE_alsa
+ SOURCES
+ alsa/qalsaaudiodevice.cpp alsa/qalsaaudiodevice_p.h
+ alsa/qalsaaudiosource.cpp alsa/qalsaaudiosource_p.h
+ alsa/qalsaaudiosink.cpp alsa/qalsaaudiosink_p.h
+ alsa/qalsamediadevices.cpp alsa/qalsamediadevices_p.h
+ INCLUDE_DIRECTORIES
+ alsa
+ LIBRARIES
+ ALSA::ALSA
+)
+
+qt_internal_extend_target(Multimedia CONDITION QT_FEATURE_pulseaudio
+ SOURCES
+ pulseaudio/qpulseaudiodevice.cpp pulseaudio/qpulseaudiodevice_p.h
+ pulseaudio/qaudioengine_pulse.cpp pulseaudio/qaudioengine_pulse_p.h
+ pulseaudio/qpulseaudiosource.cpp pulseaudio/qpulseaudiosource_p.h
+ pulseaudio/qpulseaudiosink.cpp pulseaudio/qpulseaudiosink_p.h
+ pulseaudio/qpulsehelpers.cpp pulseaudio/qpulsehelpers_p.h
+ pulseaudio/qpulseaudiomediadevices.cpp pulseaudio/qpulseaudiomediadevices_p.h
+ INCLUDE_DIRECTORIES
+ pulseaudio
+ LIBRARIES
+ WrapPulseAudio::WrapPulseAudio
+)
+
+qt_internal_extend_target(Multimedia CONDITION ANDROID
+ SOURCES
+ android/qandroidaudiosource.cpp android/qandroidaudiosource_p.h
+ android/qandroidaudiosink.cpp android/qandroidaudiosink_p.h
+ android/qandroidaudiodevice.cpp android/qandroidaudiodevice_p.h
+ android/qopenslesengine.cpp android/qopenslesengine_p.h
+ android/qandroidmediadevices.cpp android/qandroidmediadevices_p.h
+ INCLUDE_DIRECTORIES
+ android
+ LIBRARIES
+ OpenSLES
+)
+
+if(ANDROID)
+ set_property(TARGET Multimedia APPEND PROPERTY QT_ANDROID_BUNDLED_JAR_DEPENDENCIES
+ jar/Qt${QtMultimedia_VERSION_MAJOR}AndroidMultimedia.jar:org.qtproject.qt.android.multimedia.QtAudioDeviceManager
+ )
+endif()
+
+qt_internal_extend_target(Multimedia CONDITION APPLE
+ SOURCES
+ darwin/qdarwinaudiodevice.mm darwin/qdarwinaudiodevice_p.h
+ darwin/qdarwinaudiosource.mm darwin/qdarwinaudiosource_p.h
+ darwin/qdarwinaudiosink.mm darwin/qdarwinaudiosink_p.h
+ darwin/qcoreaudioutils.mm darwin/qcoreaudioutils_p.h
+ darwin/qdarwinmediadevices.mm darwin/qdarwinmediadevices_p.h
+ INCLUDE_DIRECTORIES
+ darwin
+ LIBRARIES
+ ${FWAudioToolbox}
+ ${FWCoreAudio}
+ ${FWCoreMedia}
+ ${FWCoreFoundation}
+)
+
+qt_internal_extend_target(Multimedia CONDITION MACOS
+ SOURCES
+ darwin/qmacosaudiodatautils_p.h
+)
+
+qt_internal_extend_target(Multimedia CONDITION IOS OR TVOS
+ SOURCES
+ darwin/qcoreaudiosessionmanager.mm darwin/qcoreaudiosessionmanager_p.h
+ LIBRARIES
+ ${FWAVFoundation}
+ ${FWFoundation}
+)
+
+qt_internal_extend_target(Multimedia CONDITION QNX
+ SOURCES
+ qnx/qqnxaudiodevice.cpp qnx/qqnxaudiodevice_p.h
+ qnx/qqnxaudiosink.cpp qnx/qqnxaudiosink_p.h
+ qnx/qqnxaudiosource.cpp qnx/qqnxaudiosource_p.h
+ qnx/qqnxaudioutils.cpp qnx/qqnxaudioutils_p.h
+ qnx/qqnxmediadevices.cpp qnx/qqnxmediadevices_p.h
+ INCLUDE_DIRECTORIES
+ qnx
+ LIBRARIES
+ asound
+)
+
+qt_internal_extend_target(Multimedia CONDITION QT_FEATURE_wmf
+ SOURCES
+ windows/qwindowsaudiodevice.cpp windows/qwindowsaudiodevice_p.h
+ windows/qwindowsaudiosource.cpp windows/qwindowsaudiosource_p.h
+ windows/qwindowsaudiosink.cpp windows/qwindowsaudiosink_p.h
+ windows/qwindowsaudioutils.cpp windows/qwindowsaudioutils_p.h
+ windows/qwindowsmediadevices.cpp windows/qwindowsmediadevices_p.h
+ windows/qwindowsmediafoundation.cpp windows/qwindowsmediafoundation_p.h
+ windows/qwindowsresampler.cpp windows/qwindowsresampler_p.h
+ windows/qwindowsmultimediautils.cpp windows/qwindowsmultimediautils_p.h
+ windows/qwindowsmfdefs.cpp windows/qwindowsmfdefs_p.h
+ windows/qcomptr_p.h
+ windows/qcomtaskresource_p.h
+ INCLUDE_DIRECTORIES
+ windows
+ LIBRARIES
+ winmm
+ ksuser
+)
+
+# Only on Windows' MinGW/LLVM build, symbols from `strmif.h` and `ddraw.h` conflicts
+# with symbols defined in `ksmedia.h`.
+qt_internal_extend_target(Multimedia CONDITION QT_FEATURE_wmf AND MINGW
+ NO_UNITY_BUILD_SOURCES
+ windows/qwindowsaudiodevice.cpp windows/qwindowsaudiodevice_p.h
+ windows/qwindowsaudiosource.cpp windows/qwindowsaudiosource_p.h
+ windows/qwindowsaudiosink.cpp windows/qwindowsaudiosink_p.h
+ windows/qwindowsaudioutils.cpp windows/qwindowsaudioutils_p.h
+ windows/qwindowsmediadevices.cpp windows/qwindowsmediadevices_p.h
+ windows/qwindowsmediafoundation.cpp windows/qwindowsmediafoundation_p.h
+ windows/qwindowsresampler.cpp windows/qwindowsresampler_p.h
+ windows/qwindowsmultimediautils.cpp windows/qwindowsmultimediautils_p.h
+ windows/qwindowsmfdefs.cpp windows/qwindowsmfdefs_p.h
+ windows/qcomptr_p.h
+ windows/qcomtaskresource_p.h
+)
+
+qt_internal_extend_target(Multimedia CONDITION WASM
+ SOURCES
+ wasm/qwasmmediadevices.cpp wasm/qwasmmediadevices_p.h
+ wasm/qwasmaudiosource.cpp wasm/qwasmaudiosource_p.h
+ wasm/qwasmaudiosink.cpp wasm/qwasmaudiosink_p.h
+ wasm/qwasmaudiodevice.cpp wasm/qwasmaudiodevice_p.h
+ INCLUDE_DIRECTORIES
+ wasm
+ PUBLIC_LIBRARIES
+ openal
+ NO_UNITY_BUILD_SOURCES
+ wasm/qwasmaudiosink.cpp
+ # To avoid collision between symbols defined in wasm/qwasmaudiosource.cpp.
+)
+
+set(VIDEO_VERTEX_SHADERS
+ "shaders/vertex.vert"
+ "shaders/externalsampler.vert"
+)
+
+set(VIDEO_SHADERS
+ "shaders/externalsampler.frag@glsl,100es,shaders/externalsampler_gles.frag"
+ "shaders/abgr.frag"
+ "shaders/argb.frag"
+ "shaders/rgba.frag"
+ "shaders/bgra.frag"
+ "shaders/y.frag"
+ "shaders/nv12.frag"
+ "shaders/nv21.frag"
+ "shaders/imc2.frag"
+ "shaders/imc4.frag"
+ "shaders/uyvy.frag"
+ "shaders/yuv_triplanar.frag"
+ "shaders/yuv_triplanar_p10.frag"
+ "shaders/yvu_triplanar.frag"
+ "shaders/yuyv.frag"
+ "shaders/ayuv.frag"
+ "shaders/nv12_bt2020_pq.frag"
+ "shaders/nv12_bt2020_hlg.frag"
+)
+
+qt_internal_add_shaders(Multimedia "qtmultimedia_shaders"
+ SILENT
+ BATCHABLE
+ PRECOMPILE
+ OPTIMIZED
+ PREFIX
+ "/qt-project.org/multimedia"
+ FILES
+ ${VIDEO_VERTEX_SHADERS}
+ ${VIDEO_SHADERS}
+)
+
+string(REPLACE ".frag" "_linear.frag.qsb" LINEAR_VIDEO_SHADERS "${VIDEO_SHADERS}")
+
+qt_internal_add_shaders(Multimedia "qtmultimedia_shaders_linear"
+ SILENT
+ BATCHABLE
+ PRECOMPILE
+ OPTIMIZED
+ PREFIX
+ "/qt-project.org/multimedia"
+ FILES
+ ${VIDEO_SHADERS}
+ OUTPUTS
+ ${LINEAR_VIDEO_SHADERS}
+ DEFINES
+ QMM_OUTPUTSURFACE_LINEAR
+)
+
+qt_internal_add_shaders(Multimedia "qtmultimedia_shaders_gl_macos"
+ SILENT
+ BATCHABLE
+ PRECOMPILE
+ OPTIMIZED
+ PREFIX
+ "/qt-project.org/multimedia"
+ GLSL
+ "120,150"
+ NOHLSL
+ NOMSL
+ FILES
+ "shaders/rectsampler.vert"
+ "shaders/rectsampler_bgra.frag"
+)
+
+qt_internal_add_shaders(Multimedia "qtmultimedia_shaders_gl_macos_linear"
+ SILENT
+ BATCHABLE
+ PRECOMPILE
+ OPTIMIZED
+ PREFIX
+ "/qt-project.org/multimedia"
+ GLSL
+ "120,150"
+ NOHLSL
+ NOMSL
+ FILES
+ "shaders/rectsampler_bgra.frag"
+ OUTPUTS
+ "shaders/rectsampler_bgra_linear.frag.qsb"
+)
+
+if(DEFINED QT_DEFAULT_MEDIA_BACKEND)
+ target_compile_definitions(Multimedia
+ PRIVATE QT_DEFAULT_MEDIA_BACKEND="${QT_DEFAULT_MEDIA_BACKEND}")
+endif()
diff --git a/src/multimedia/alsa/alsa.json b/src/multimedia/alsa/alsa.json
new file mode 100644
index 000000000..71abb213c
--- /dev/null
+++ b/src/multimedia/alsa/alsa.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "alsa" ]
+}
diff --git a/src/multimedia/alsa/qalsaaudiodevice.cpp b/src/multimedia/alsa/qalsaaudiodevice.cpp
new file mode 100644
index 000000000..893375270
--- /dev/null
+++ b/src/multimedia/alsa/qalsaaudiodevice.cpp
@@ -0,0 +1,71 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// INTERNAL USE ONLY: Do NOT use for any other purpose.
+//
+
+#include "qalsaaudiodevice_p.h"
+
+#include <alsa/version.h>
+
+QT_BEGIN_NAMESPACE
+
+QAlsaAudioDeviceInfo::QAlsaAudioDeviceInfo(const QByteArray &dev, const QString &desc, QAudioDevice::Mode mode)
+ : QAudioDevicePrivate(dev, mode)
+{
+ description = desc;
+
+ checkSurround();
+
+ minimumChannelCount = 1;
+ maximumChannelCount = 2;
+ if (surround71)
+ maximumChannelCount = 8;
+ else if (surround40)
+ maximumChannelCount = 4;
+ else if (surround51)
+ maximumChannelCount = 6;
+
+ minimumSampleRate = 8000;
+ maximumSampleRate = 48000;
+
+ supportedSampleFormats = {
+ QAudioFormat::UInt8,
+ QAudioFormat::Int16,
+ QAudioFormat::Int32,
+ QAudioFormat::Float,
+ };
+
+ preferredFormat.setChannelCount(mode == QAudioDevice::Input ? 1 : 2);
+ preferredFormat.setSampleFormat(QAudioFormat::Float);
+ preferredFormat.setSampleRate(48000);
+}
+
+QAlsaAudioDeviceInfo::~QAlsaAudioDeviceInfo() = default;
+
+void QAlsaAudioDeviceInfo::checkSurround()
+{
+ if (mode != QAudioDevice::Output)
+ return;
+
+ surround40 = false;
+ surround51 = false;
+ surround71 = false;
+
+ if (id.startsWith(QLatin1String("surround40")))
+ surround40 = true;
+ if (id.startsWith(QLatin1String("surround51")))
+ surround51 = true;
+ if (id.startsWith(QLatin1String("surround71")))
+ surround71 = true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/alsa/qalsaaudiodevice_p.h b/src/multimedia/alsa/qalsaaudiodevice_p.h
new file mode 100644
index 000000000..dcbc9e692
--- /dev/null
+++ b/src/multimedia/alsa/qalsaaudiodevice_p.h
@@ -0,0 +1,49 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+
+#ifndef QALSAAUDIODEVICEINFO_H
+#define QALSAAUDIODEVICEINFO_H
+
+#include <alsa/asoundlib.h>
+
+#include <QtCore/qbytearray.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qdebug.h>
+
+#include <QtMultimedia/qaudio.h>
+#include <private/qaudiodevice_p.h>
+#include <private/qaudiosystem_p.h>
+
+QT_BEGIN_NAMESPACE
+
+
+class QAlsaAudioDeviceInfo : public QAudioDevicePrivate
+{
+public:
+ QAlsaAudioDeviceInfo(const QByteArray &dev, const QString &description, QAudioDevice::Mode mode);
+ ~QAlsaAudioDeviceInfo();
+
+private:
+ void checkSurround();
+ bool surround40{};
+ bool surround51{};
+ bool surround71{};
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QALSAAUDIODEVICEINFO_H
diff --git a/src/multimedia/alsa/qalsaaudiosink.cpp b/src/multimedia/alsa/qalsaaudiosink.cpp
new file mode 100644
index 000000000..e515219a2
--- /dev/null
+++ b/src/multimedia/alsa/qalsaaudiosink.cpp
@@ -0,0 +1,698 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// INTERNAL USE ONLY: Do NOT use for any other purpose.
+//
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qvarlengtharray.h>
+#include <QtMultimedia/private/qaudiohelpers_p.h>
+#include "qalsaaudiosink_p.h"
+#include "qalsaaudiodevice_p.h"
+#include <QLoggingCategory>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(lcAlsaOutput, "qt.multimedia.alsa.output")
+//#define DEBUG_AUDIO 1
+
+QAlsaAudioSink::QAlsaAudioSink(const QByteArray &device, QObject *parent)
+ : QPlatformAudioSink(parent)
+{
+ m_device = device;
+
+ timer = new QTimer(this);
+ connect(timer, &QTimer::timeout, this, &QAlsaAudioSink::userFeed);
+}
+
+QAlsaAudioSink::~QAlsaAudioSink()
+{
+ close();
+ disconnect(timer, &QTimer::timeout, this, &QAlsaAudioSink::userFeed);
+ QCoreApplication::processEvents();
+ delete timer;
+}
+
+void QAlsaAudioSink::setVolume(qreal vol)
+{
+ m_volume = vol;
+}
+
+qreal QAlsaAudioSink::volume() const
+{
+ return m_volume;
+}
+
+QAudio::Error QAlsaAudioSink::error() const
+{
+ return errorState;
+}
+
+QAudio::State QAlsaAudioSink::state() const
+{
+ return deviceState;
+}
+
+int QAlsaAudioSink::xrun_recovery(int err)
+{
+ int count = 0;
+ bool reset = false;
+
+ // ESTRPIPE is not available in all OSes where ALSA is available
+ int estrpipe = EIO;
+#ifdef ESTRPIPE
+ estrpipe = ESTRPIPE;
+#endif
+
+ if(err == -EPIPE) {
+ errorState = QAudio::UnderrunError;
+ emit errorChanged(errorState);
+ err = snd_pcm_prepare(handle);
+ if(err < 0)
+ reset = true;
+
+ } else if ((err == -estrpipe)||(err == -EIO)) {
+ errorState = QAudio::IOError;
+ emit errorChanged(errorState);
+ while((err = snd_pcm_resume(handle)) == -EAGAIN){
+ usleep(100);
+ count++;
+ if(count > 5) {
+ reset = true;
+ break;
+ }
+ }
+ if(err < 0) {
+ err = snd_pcm_prepare(handle);
+ if(err < 0)
+ reset = true;
+ }
+ }
+ if(reset) {
+ close();
+ open();
+ snd_pcm_prepare(handle);
+ return 0;
+ }
+ return err;
+}
+
+int QAlsaAudioSink::setFormat()
+{
+ snd_pcm_format_t pcmformat = SND_PCM_FORMAT_UNKNOWN;
+
+ switch (settings.sampleFormat()) {
+ case QAudioFormat::UInt8:
+ pcmformat = SND_PCM_FORMAT_U8;
+ break;
+ case QAudioFormat::Int16:
+ if constexpr (QSysInfo::ByteOrder == QSysInfo::BigEndian)
+ pcmformat = SND_PCM_FORMAT_S16_BE;
+ else
+ pcmformat = SND_PCM_FORMAT_S16_LE;
+ break;
+ case QAudioFormat::Int32:
+ if constexpr (QSysInfo::ByteOrder == QSysInfo::BigEndian)
+ pcmformat = SND_PCM_FORMAT_S32_BE;
+ else
+ pcmformat = SND_PCM_FORMAT_S32_LE;
+ break;
+ case QAudioFormat::Float:
+ if constexpr (QSysInfo::ByteOrder == QSysInfo::BigEndian)
+ pcmformat = SND_PCM_FORMAT_FLOAT_BE;
+ else
+ pcmformat = SND_PCM_FORMAT_FLOAT_LE;
+ break;
+ default:
+ break;
+ }
+
+ return pcmformat != SND_PCM_FORMAT_UNKNOWN
+ ? snd_pcm_hw_params_set_format( handle, hwparams, pcmformat)
+ : -1;
+}
+
+void QAlsaAudioSink::start(QIODevice* device)
+{
+ if(deviceState != QAudio::StoppedState)
+ deviceState = QAudio::StoppedState;
+
+ errorState = QAudio::NoError;
+
+ // Handle change of mode
+ if(audioSource && !pullMode) {
+ delete audioSource;
+ audioSource = 0;
+ }
+
+ close();
+
+ pullMode = true;
+ audioSource = device;
+
+ connect(audioSource, &QIODevice::readyRead, timer, [this] {
+ if (!timer->isActive()) {
+ timer->start(period_time / 1000);
+ }
+ });
+ deviceState = QAudio::ActiveState;
+
+ open();
+
+ emit stateChanged(deviceState);
+}
+
+QIODevice* QAlsaAudioSink::start()
+{
+ if(deviceState != QAudio::StoppedState)
+ deviceState = QAudio::StoppedState;
+
+ errorState = QAudio::NoError;
+
+ // Handle change of mode
+ if(audioSource && !pullMode) {
+ delete audioSource;
+ audioSource = 0;
+ }
+
+ close();
+
+ audioSource = new AlsaOutputPrivate(this);
+ audioSource->open(QIODevice::WriteOnly|QIODevice::Unbuffered);
+ pullMode = false;
+
+ deviceState = QAudio::IdleState;
+
+ open();
+
+ emit stateChanged(deviceState);
+
+ return audioSource;
+}
+
+void QAlsaAudioSink::stop()
+{
+ if(deviceState == QAudio::StoppedState)
+ return;
+ errorState = QAudio::NoError;
+ deviceState = QAudio::StoppedState;
+ close();
+ emit stateChanged(deviceState);
+}
+
+bool QAlsaAudioSink::open()
+{
+ if(opened)
+ return true;
+
+#ifdef DEBUG_AUDIO
+ QTime now(QTime::currentTime());
+ qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
+#endif
+ elapsedTimeOffset = 0;
+
+ int dir;
+ int err = 0;
+ int count=0;
+ unsigned int sampleRate = settings.sampleRate();
+
+ if (!settings.isValid()) {
+ qWarning("QAudioSink: open error, invalid format.");
+ } else if (settings.sampleRate() <= 0) {
+ qWarning("QAudioSink: open error, invalid sample rate (%d).",
+ settings.sampleRate());
+ } else {
+ err = -1;
+ }
+
+ if (err == 0) {
+ errorState = QAudio::OpenError;
+ deviceState = QAudio::StoppedState;
+ emit errorChanged(errorState);
+ return false;
+ }
+
+ // Step 1: try and open the device
+ while((count < 5) && (err < 0)) {
+ err=snd_pcm_open(&handle, m_device.constData(),SND_PCM_STREAM_PLAYBACK,0);
+ if(err < 0)
+ count++;
+ }
+ if (( err < 0)||(handle == 0)) {
+ errorState = QAudio::OpenError;
+ emit errorChanged(errorState);
+ deviceState = QAudio::StoppedState;
+ return false;
+ }
+ snd_pcm_nonblock( handle, 0 );
+
+ // Step 2: Set the desired HW parameters.
+ snd_pcm_hw_params_alloca( &hwparams );
+
+ bool fatal = false;
+ QString errMessage;
+ unsigned int chunks = 8;
+
+ err = snd_pcm_hw_params_any( handle, hwparams );
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSink: snd_pcm_hw_params_any: err = %1").arg(err);
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 );
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSink: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_access( handle, hwparams, access );
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSink: snd_pcm_hw_params_set_access: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = setFormat();
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSink: snd_pcm_hw_params_set_format: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channelCount() );
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSink: snd_pcm_hw_params_set_channels: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &sampleRate, 0 );
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSink: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ unsigned int maxBufferTime = 0;
+ unsigned int minBufferTime = 0;
+ unsigned int maxPeriodTime = 0;
+ unsigned int minPeriodTime = 0;
+
+ err = snd_pcm_hw_params_get_buffer_time_max(hwparams, &maxBufferTime, &dir);
+ if ( err >= 0)
+ err = snd_pcm_hw_params_get_buffer_time_min(hwparams, &minBufferTime, &dir);
+ if ( err >= 0)
+ err = snd_pcm_hw_params_get_period_time_max(hwparams, &maxPeriodTime, &dir);
+ if ( err >= 0)
+ err = snd_pcm_hw_params_get_period_time_min(hwparams, &minPeriodTime, &dir);
+
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSink: buffer/period min and max: err = %1").arg(err);
+ } else {
+ static unsigned user_buffer_time = qEnvironmentVariableIntValue("QT_ALSA_OUTPUT_BUFFER_TIME");
+ static unsigned user_period_time = qEnvironmentVariableIntValue("QT_ALSA_OUTPUT_PERIOD_TIME");
+ const bool outOfRange = maxBufferTime < buffer_time || buffer_time < minBufferTime || maxPeriodTime < period_time || minPeriodTime > period_time;
+ if (outOfRange || user_period_time || user_buffer_time) {
+ period_time = user_period_time ? user_period_time : minPeriodTime;
+ if (!user_buffer_time) {
+ chunks = maxBufferTime / period_time;
+ buffer_time = period_time * chunks;
+ } else {
+ buffer_time = user_buffer_time;
+ chunks = buffer_time / period_time;
+ }
+ }
+ qCDebug(lcAlsaOutput) << "buffer time: [" << minBufferTime << "-" << maxBufferTime << "] =" << buffer_time;
+ qCDebug(lcAlsaOutput) << "period time: [" << minPeriodTime << "-" << maxPeriodTime << "] =" << period_time;
+ qCDebug(lcAlsaOutput) << "chunks =" << chunks;
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSink: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir);
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSink: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir);
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSink: snd_pcm_hw_params_set_periods_near: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params(handle, hwparams);
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSink: snd_pcm_hw_params: err = %1").arg(err);
+ }
+ }
+ if( err < 0) {
+ qWarning()<<errMessage;
+ errorState = QAudio::OpenError;
+ emit errorChanged(errorState);
+ deviceState = QAudio::StoppedState;
+ return false;
+ }
+ snd_pcm_hw_params_get_buffer_size(hwparams,&buffer_frames);
+ buffer_size = snd_pcm_frames_to_bytes(handle,buffer_frames);
+ snd_pcm_hw_params_get_period_size(hwparams,&period_frames, &dir);
+ period_size = snd_pcm_frames_to_bytes(handle,period_frames);
+ snd_pcm_hw_params_get_buffer_time(hwparams,&buffer_time, &dir);
+ snd_pcm_hw_params_get_period_time(hwparams,&period_time, &dir);
+
+ // Step 3: Set the desired SW parameters.
+ snd_pcm_sw_params_t *swparams;
+ snd_pcm_sw_params_alloca(&swparams);
+ snd_pcm_sw_params_current(handle, swparams);
+ snd_pcm_sw_params_set_start_threshold(handle,swparams,period_frames);
+ snd_pcm_sw_params_set_stop_threshold(handle,swparams,buffer_frames);
+ snd_pcm_sw_params_set_avail_min(handle, swparams,period_frames);
+ snd_pcm_sw_params(handle, swparams);
+
+ // Step 4: Prepare audio
+ if(audioBuffer == 0)
+ audioBuffer = new char[snd_pcm_frames_to_bytes(handle,buffer_frames)];
+ snd_pcm_prepare( handle );
+ snd_pcm_start(handle);
+
+ // Step 5: Setup timer
+ bytesAvailable = bytesFree();
+
+ // Step 6: Start audio processing
+ timer->start(period_time/1000);
+
+ elapsedTimeOffset = 0;
+ errorState = QAudio::NoError;
+ totalTimeValue = 0;
+ opened = true;
+
+ return true;
+}
+
+void QAlsaAudioSink::close()
+{
+ timer->stop();
+
+ if ( handle ) {
+ snd_pcm_drain( handle );
+ snd_pcm_close( handle );
+ handle = 0;
+ delete [] audioBuffer;
+ audioBuffer=0;
+ }
+ if(!pullMode && audioSource) {
+ delete audioSource;
+ audioSource = 0;
+ }
+ opened = false;
+}
+
+qsizetype QAlsaAudioSink::bytesFree() const
+{
+ if(resuming)
+ return period_size;
+
+ if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
+ return 0;
+
+ int frames = snd_pcm_avail_update(handle);
+ if (frames == -EPIPE) {
+ // Try and handle buffer underrun
+ int err = snd_pcm_recover(handle, frames, 0);
+ if (err < 0)
+ return 0;
+ else
+ frames = snd_pcm_avail_update(handle);
+ } else if (frames < 0) {
+ return 0;
+ }
+
+ if ((int)frames > (int)buffer_frames)
+ frames = buffer_frames;
+
+ return snd_pcm_frames_to_bytes(handle, frames);
+}
+
+qint64 QAlsaAudioSink::write( const char *data, qint64 len )
+{
+ // Write out some audio data
+ if ( !handle )
+ return 0;
+#ifdef DEBUG_AUDIO
+ qDebug()<<"frames to write out = "<<
+ snd_pcm_bytes_to_frames( handle, (int)len )<<" ("<<len<<") bytes";
+#endif
+ int frames, err;
+ int space = bytesFree();
+
+ if (!space)
+ return 0;
+
+ if (len < space)
+ space = len;
+
+ frames = snd_pcm_bytes_to_frames(handle, space);
+
+ if (m_volume < 1.0f) {
+ QVarLengthArray<char, 4096> out(space);
+ QAudioHelperInternal::qMultiplySamples(m_volume, settings, data, out.data(), space);
+ err = snd_pcm_writei(handle, out.constData(), frames);
+ } else {
+ err = snd_pcm_writei(handle, data, frames);
+ }
+
+ if(err > 0) {
+ totalTimeValue += err;
+ resuming = false;
+ errorState = QAudio::NoError;
+ if (deviceState != QAudio::ActiveState) {
+ deviceState = QAudio::ActiveState;
+ emit stateChanged(deviceState);
+ }
+ return snd_pcm_frames_to_bytes( handle, err );
+ } else
+ err = xrun_recovery(err);
+
+ if(err < 0) {
+ close();
+ errorState = QAudio::FatalError;
+ emit errorChanged(errorState);
+ deviceState = QAudio::StoppedState;
+ emit stateChanged(deviceState);
+ }
+ return 0;
+}
+
+void QAlsaAudioSink::setBufferSize(qsizetype value)
+{
+ if(deviceState == QAudio::StoppedState)
+ buffer_size = value;
+}
+
+qsizetype QAlsaAudioSink::bufferSize() const
+{
+ return buffer_size;
+}
+
+qint64 QAlsaAudioSink::processedUSecs() const
+{
+ return qint64(1000000) * totalTimeValue / settings.sampleRate();
+}
+
+void QAlsaAudioSink::resume()
+{
+ if(deviceState == QAudio::SuspendedState) {
+ int err = 0;
+
+ if(handle) {
+ err = snd_pcm_prepare( handle );
+ if(err < 0)
+ xrun_recovery(err);
+
+ err = snd_pcm_start(handle);
+ if(err < 0)
+ xrun_recovery(err);
+
+ bytesAvailable = (int)snd_pcm_frames_to_bytes(handle, buffer_frames);
+ }
+ resuming = true;
+
+ deviceState = suspendedInState;
+ errorState = QAudio::NoError;
+ timer->start(period_time/1000);
+ emit stateChanged(deviceState);
+ }
+}
+
+void QAlsaAudioSink::setFormat(const QAudioFormat& fmt)
+{
+ settings = fmt;
+}
+
+QAudioFormat QAlsaAudioSink::format() const
+{
+ return settings;
+}
+
+void QAlsaAudioSink::suspend()
+{
+ if(deviceState == QAudio::ActiveState || deviceState == QAudio::IdleState || resuming) {
+ suspendedInState = deviceState;
+ snd_pcm_drain(handle);
+ timer->stop();
+ deviceState = QAudio::SuspendedState;
+ errorState = QAudio::NoError;
+ emit stateChanged(deviceState);
+ }
+}
+
+void QAlsaAudioSink::userFeed()
+{
+ if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState)
+ return;
+#ifdef DEBUG_AUDIO
+ QTime now(QTime::currentTime());
+ qDebug()<<now.second()<<"s "<<now.msec()<<"ms :userFeed() OUT";
+#endif
+ if(deviceState == QAudio::IdleState)
+ bytesAvailable = bytesFree();
+
+ deviceReady();
+}
+
+bool QAlsaAudioSink::deviceReady()
+{
+ if(pullMode) {
+ int l = 0;
+ int chunks = bytesAvailable/period_size;
+ if(chunks==0) {
+ bytesAvailable = bytesFree();
+ return false;
+ }
+#ifdef DEBUG_AUDIO
+ qDebug()<<"deviceReady() avail="<<bytesAvailable<<" bytes, period size="<<period_size<<" bytes";
+ qDebug()<<"deviceReady() no. of chunks that can fit ="<<chunks<<", chunks in bytes ="<<period_size*chunks;
+#endif
+ int input = period_frames*chunks;
+ if(input > (int)buffer_frames)
+ input = buffer_frames;
+ l = audioSource->read(audioBuffer,snd_pcm_frames_to_bytes(handle, input));
+
+ // reading can take a while and stream may have been stopped
+ if (!handle)
+ return false;
+
+ if(l > 0) {
+ // Got some data to output
+ if (deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
+ return true;
+ qint64 bytesWritten = write(audioBuffer,l);
+ if (bytesWritten != l)
+ audioSource->seek(audioSource->pos()-(l-bytesWritten));
+ bytesAvailable = bytesFree();
+
+ } else if(l == 0) {
+ // Did not get any data to output
+ timer->stop();
+ snd_pcm_drain(handle);
+ bytesAvailable = bytesFree();
+ if(bytesAvailable > snd_pcm_frames_to_bytes(handle, buffer_frames-period_frames)) {
+ // Underrun
+ if (deviceState != QAudio::IdleState) {
+ errorState = audioSource->atEnd() ? QAudio::NoError : QAudio::UnderrunError;
+ emit errorChanged(errorState);
+ deviceState = QAudio::IdleState;
+ emit stateChanged(deviceState);
+ }
+ }
+
+ } else if(l < 0) {
+ close();
+ deviceState = QAudio::StoppedState;
+ errorState = QAudio::IOError;
+ emit errorChanged(errorState);
+ emit stateChanged(deviceState);
+ }
+ } else {
+ bytesAvailable = bytesFree();
+ if(bytesAvailable > snd_pcm_frames_to_bytes(handle, buffer_frames-period_frames)) {
+ // Underrun
+ if (deviceState != QAudio::IdleState) {
+ errorState = QAudio::UnderrunError;
+ emit errorChanged(errorState);
+ deviceState = QAudio::IdleState;
+ emit stateChanged(deviceState);
+ }
+ }
+ }
+
+ if(deviceState != QAudio::ActiveState)
+ return true;
+
+ return true;
+}
+
+void QAlsaAudioSink::reset()
+{
+ if(handle)
+ snd_pcm_reset(handle);
+
+ stop();
+}
+
+AlsaOutputPrivate::AlsaOutputPrivate(QAlsaAudioSink* audio)
+{
+ audioDevice = qobject_cast<QAlsaAudioSink*>(audio);
+}
+
+AlsaOutputPrivate::~AlsaOutputPrivate() {}
+
+qint64 AlsaOutputPrivate::readData( char* data, qint64 len)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(len);
+
+ return 0;
+}
+
+qint64 AlsaOutputPrivate::writeData(const char* data, qint64 len)
+{
+ int retry = 0;
+ qint64 written = 0;
+ if((audioDevice->deviceState == QAudio::ActiveState)
+ ||(audioDevice->deviceState == QAudio::IdleState)) {
+ while(written < len) {
+ int chunk = audioDevice->write(data+written,(len-written));
+ if(chunk <= 0)
+ retry++;
+ written+=chunk;
+ if(retry > 10)
+ return written;
+ }
+ }
+ return written;
+
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qalsaaudiosink_p.cpp"
diff --git a/src/multimedia/alsa/qalsaaudiosink_p.h b/src/multimedia/alsa/qalsaaudiosink_p.h
new file mode 100644
index 000000000..0f5a5aa5a
--- /dev/null
+++ b/src/multimedia/alsa/qalsaaudiosink_p.h
@@ -0,0 +1,121 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QAUDIOOUTPUTALSA_H
+#define QAUDIOOUTPUTALSA_H
+
+#include <alsa/asoundlib.h>
+
+#include <QtCore/qfile.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qtimer.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qelapsedtimer.h>
+#include <QtCore/qiodevice.h>
+
+#include <QtMultimedia/qaudio.h>
+#include <QtMultimedia/qaudiodevice.h>
+#include <private/qaudiosystem_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAlsaAudioSink : public QPlatformAudioSink
+{
+ friend class AlsaOutputPrivate;
+ Q_OBJECT
+public:
+ QAlsaAudioSink(const QByteArray &device, QObject *parent);
+ ~QAlsaAudioSink();
+
+ qint64 write( const char *data, qint64 len );
+
+ void start(QIODevice* device) override;
+ QIODevice* start() override;
+ void stop() override;
+ void reset() override;
+ void suspend() override;
+ void resume() override;
+ qsizetype bytesFree() const override;
+ void setBufferSize(qsizetype value) override;
+ qsizetype bufferSize() const override;
+ qint64 processedUSecs() const override;
+ QAudio::Error error() const override;
+ QAudio::State state() const override;
+ void setFormat(const QAudioFormat& fmt) override;
+ QAudioFormat format() const override;
+ void setVolume(qreal) override;
+ qreal volume() const override;
+
+
+ QIODevice* audioSource = nullptr;
+ QAudioFormat settings;
+ QAudio::Error errorState = QAudio::NoError;
+ QAudio::State deviceState = QAudio::StoppedState;
+ QAudio::State suspendedInState = QAudio::SuspendedState;
+
+private slots:
+ void userFeed();
+ bool deviceReady();
+
+signals:
+ void processMore();
+
+private:
+ bool opened = false;
+ bool pullMode = true;
+ bool resuming = false;
+ int buffer_size = 0;
+ int period_size = 0;
+ qint64 totalTimeValue = 0;
+ unsigned int buffer_time = 100000;
+ unsigned int period_time = 20000;
+ snd_pcm_uframes_t buffer_frames;
+ snd_pcm_uframes_t period_frames;
+ int xrun_recovery(int err);
+
+ int setFormat();
+ bool open();
+ void close();
+
+ QTimer* timer = nullptr;
+ QByteArray m_device;
+ int bytesAvailable = 0;
+ qint64 elapsedTimeOffset = 0;
+ char* audioBuffer = nullptr;
+ snd_pcm_t* handle = nullptr;
+ snd_pcm_access_t access = SND_PCM_ACCESS_RW_INTERLEAVED;
+ snd_pcm_hw_params_t *hwparams = nullptr;
+ qreal m_volume = 1.0f;
+};
+
+class AlsaOutputPrivate : public QIODevice
+{
+ friend class QAlsaAudioSink;
+ Q_OBJECT
+public:
+ AlsaOutputPrivate(QAlsaAudioSink* audio);
+ ~AlsaOutputPrivate();
+
+ qint64 readData( char* data, qint64 len) override;
+ qint64 writeData(const char* data, qint64 len) override;
+
+private:
+ QAlsaAudioSink *audioDevice;
+};
+
+QT_END_NAMESPACE
+
+
+#endif
diff --git a/src/multimedia/alsa/qalsaaudiosource.cpp b/src/multimedia/alsa/qalsaaudiosource.cpp
new file mode 100644
index 000000000..ebf6e24e2
--- /dev/null
+++ b/src/multimedia/alsa/qalsaaudiosource.cpp
@@ -0,0 +1,770 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// INTERNAL USE ONLY: Do NOT use for any other purpose.
+//
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qvarlengtharray.h>
+#include <QtMultimedia/private/qaudiohelpers_p.h>
+#include "qalsaaudiosource_p.h"
+
+QT_BEGIN_NAMESPACE
+
+//#define DEBUG_AUDIO 1
+
+QAlsaAudioSource::QAlsaAudioSource(const QByteArray &device, QObject *parent)
+ : QPlatformAudioSource(parent)
+{
+ bytesAvailable = 0;
+ handle = 0;
+ access = SND_PCM_ACCESS_RW_INTERLEAVED;
+ pcmformat = SND_PCM_FORMAT_S16;
+ buffer_size = 0;
+ period_size = 0;
+ buffer_time = 100000;
+ period_time = 20000;
+ totalTimeValue = 0;
+ errorState = QAudio::NoError;
+ deviceState = QAudio::StoppedState;
+ audioSource = 0;
+ pullMode = true;
+ resuming = false;
+
+ m_volume = 1.0f;
+
+ m_device = device;
+
+ timer = new QTimer(this);
+ connect(timer, &QTimer::timeout, this, &QAlsaAudioSource::userFeed);
+}
+
+QAlsaAudioSource::~QAlsaAudioSource()
+{
+ close();
+ disconnect(timer, &QTimer::timeout, this, &QAlsaAudioSource::userFeed);
+ QCoreApplication::processEvents();
+ delete timer;
+}
+
+void QAlsaAudioSource::setVolume(qreal vol)
+{
+ m_volume = vol;
+}
+
+qreal QAlsaAudioSource::volume() const
+{
+ return m_volume;
+}
+
+QAudio::Error QAlsaAudioSource::error() const
+{
+ return errorState;
+}
+
+QAudio::State QAlsaAudioSource::state() const
+{
+ return deviceState;
+}
+
+void QAlsaAudioSource::setFormat(const QAudioFormat& fmt)
+{
+ if (deviceState == QAudio::StoppedState)
+ settings = fmt;
+}
+
+QAudioFormat QAlsaAudioSource::format() const
+{
+ return settings;
+}
+
+int QAlsaAudioSource::xrun_recovery(int err)
+{
+ int count = 0;
+ bool reset = false;
+
+ // ESTRPIPE is not available in all OSes where ALSA is available
+ int estrpipe = EIO;
+#ifdef ESTRPIPE
+ estrpipe = ESTRPIPE;
+#endif
+
+ if(err == -EPIPE) {
+ errorState = QAudio::UnderrunError;
+ err = snd_pcm_prepare(handle);
+ if(err < 0)
+ reset = true;
+ else {
+ bytesAvailable = checkBytesReady();
+ if (bytesAvailable <= 0)
+ reset = true;
+ }
+ } else if ((err == -estrpipe)||(err == -EIO)) {
+ errorState = QAudio::IOError;
+ while((err = snd_pcm_resume(handle)) == -EAGAIN){
+ usleep(100);
+ count++;
+ if(count > 5) {
+ reset = true;
+ break;
+ }
+ }
+ if(err < 0) {
+ err = snd_pcm_prepare(handle);
+ if(err < 0)
+ reset = true;
+ }
+ }
+ if(reset) {
+ close();
+ open();
+ snd_pcm_prepare(handle);
+ return 0;
+ }
+ return err;
+}
+
+int QAlsaAudioSource::setFormat()
+{
+ snd_pcm_format_t pcmformat = SND_PCM_FORMAT_UNKNOWN;
+
+ switch (settings.sampleFormat()) {
+ case QAudioFormat::UInt8:
+ pcmformat = SND_PCM_FORMAT_U8;
+ break;
+ case QAudioFormat::Int16:
+ if constexpr (QSysInfo::ByteOrder == QSysInfo::BigEndian)
+ pcmformat = SND_PCM_FORMAT_S16_BE;
+ else
+ pcmformat = SND_PCM_FORMAT_S16_LE;
+ break;
+ case QAudioFormat::Int32:
+ if constexpr (QSysInfo::ByteOrder == QSysInfo::BigEndian)
+ pcmformat = SND_PCM_FORMAT_S32_BE;
+ else
+ pcmformat = SND_PCM_FORMAT_S32_LE;
+ break;
+ case QAudioFormat::Float:
+ if constexpr (QSysInfo::ByteOrder == QSysInfo::BigEndian)
+ pcmformat = SND_PCM_FORMAT_FLOAT_BE;
+ else
+ pcmformat = SND_PCM_FORMAT_FLOAT_LE;
+ break;
+ default:
+ break;
+ }
+
+ return pcmformat != SND_PCM_FORMAT_UNKNOWN
+ ? snd_pcm_hw_params_set_format( handle, hwparams, pcmformat)
+ : -1;
+}
+
+void QAlsaAudioSource::start(QIODevice* device)
+{
+ if(deviceState != QAudio::StoppedState)
+ close();
+
+ if(!pullMode && audioSource)
+ delete audioSource;
+
+ pullMode = true;
+ audioSource = device;
+
+ deviceState = QAudio::ActiveState;
+
+ if( !open() )
+ return;
+
+ emit stateChanged(deviceState);
+}
+
+QIODevice* QAlsaAudioSource::start()
+{
+ if(deviceState != QAudio::StoppedState)
+ close();
+
+ if(!pullMode && audioSource)
+ delete audioSource;
+
+ pullMode = false;
+ audioSource = new AlsaInputPrivate(this);
+ audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
+
+ deviceState = QAudio::IdleState;
+
+ if( !open() )
+ return 0;
+
+ emit stateChanged(deviceState);
+
+ return audioSource;
+}
+
+void QAlsaAudioSource::stop()
+{
+ if(deviceState == QAudio::StoppedState)
+ return;
+
+ deviceState = QAudio::StoppedState;
+
+ close();
+ emit stateChanged(deviceState);
+}
+
+bool QAlsaAudioSource::open()
+{
+#ifdef DEBUG_AUDIO
+ QTime now(QTime::currentTime());
+ qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
+#endif
+ elapsedTimeOffset = 0;
+
+ int dir;
+ int err = 0;
+ int count=0;
+ unsigned int sampleRate=settings.sampleRate();
+
+ if (!settings.isValid()) {
+ qWarning("QAudioSource: open error, invalid format.");
+ } else if (settings.sampleRate() <= 0) {
+ qWarning("QAudioSource: open error, invalid sample rate (%d).",
+ settings.sampleRate());
+ } else {
+ err = -1;
+ }
+
+ if (err == 0) {
+ errorState = QAudio::OpenError;
+ deviceState = QAudio::StoppedState;
+ emit errorChanged(errorState);
+ return false;
+ }
+
+
+ // Step 1: try and open the device
+ while((count < 5) && (err < 0)) {
+ err = snd_pcm_open(&handle, m_device.constData(), SND_PCM_STREAM_CAPTURE,0);
+ if(err < 0)
+ count++;
+ }
+ if (( err < 0)||(handle == 0)) {
+ errorState = QAudio::OpenError;
+ deviceState = QAudio::StoppedState;
+ emit stateChanged(deviceState);
+ return false;
+ }
+ snd_pcm_nonblock( handle, 0 );
+
+ // Step 2: Set the desired HW parameters.
+ snd_pcm_hw_params_alloca( &hwparams );
+
+ bool fatal = false;
+ QString errMessage;
+ unsigned int chunks = 8;
+
+ err = snd_pcm_hw_params_any( handle, hwparams );
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSource: snd_pcm_hw_params_any: err = %1").arg(err);
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 );
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSource: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_access( handle, hwparams, access );
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSource: snd_pcm_hw_params_set_access: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = setFormat();
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSource: snd_pcm_hw_params_set_format: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channelCount() );
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSource: snd_pcm_hw_params_set_channels: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &sampleRate, 0 );
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSource: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSource: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir);
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSource: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir);
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSource: snd_pcm_hw_params_set_periods_near: err = %1").arg(err);
+ }
+ }
+ if ( !fatal ) {
+ err = snd_pcm_hw_params(handle, hwparams);
+ if ( err < 0 ) {
+ fatal = true;
+ errMessage = QString::fromLatin1("QAudioSource: snd_pcm_hw_params: err = %1").arg(err);
+ }
+ }
+ if( err < 0) {
+ qWarning()<<errMessage;
+ errorState = QAudio::OpenError;
+ deviceState = QAudio::StoppedState;
+ emit stateChanged(deviceState);
+ return false;
+ }
+ snd_pcm_hw_params_get_buffer_size(hwparams,&buffer_frames);
+ buffer_size = snd_pcm_frames_to_bytes(handle,buffer_frames);
+ snd_pcm_hw_params_get_period_size(hwparams,&period_frames, &dir);
+ period_size = snd_pcm_frames_to_bytes(handle,period_frames);
+ snd_pcm_hw_params_get_buffer_time(hwparams,&buffer_time, &dir);
+ snd_pcm_hw_params_get_period_time(hwparams,&period_time, &dir);
+
+ // Step 3: Set the desired SW parameters.
+ snd_pcm_sw_params_t *swparams;
+ snd_pcm_sw_params_alloca(&swparams);
+ snd_pcm_sw_params_current(handle, swparams);
+ snd_pcm_sw_params_set_start_threshold(handle,swparams,period_frames);
+ snd_pcm_sw_params_set_stop_threshold(handle,swparams,buffer_frames);
+ snd_pcm_sw_params_set_avail_min(handle, swparams,period_frames);
+ snd_pcm_sw_params(handle, swparams);
+
+ // Step 4: Prepare audio
+ ringBuffer.resize(buffer_size);
+ snd_pcm_prepare( handle );
+ snd_pcm_start(handle);
+
+ // Step 5: Setup timer
+ bytesAvailable = checkBytesReady();
+
+ if(pullMode)
+ connect(audioSource, &QIODevice::readyRead, this, &QAlsaAudioSource::userFeed);
+
+ // Step 6: Start audio processing
+ chunks = buffer_size/period_size;
+ timer->start(period_time*chunks/2000);
+
+ errorState = QAudio::NoError;
+
+ totalTimeValue = 0;
+
+ return true;
+}
+
+void QAlsaAudioSource::close()
+{
+ timer->stop();
+
+ if ( handle ) {
+ snd_pcm_drop( handle );
+ snd_pcm_close( handle );
+ handle = 0;
+ }
+}
+
+int QAlsaAudioSource::checkBytesReady()
+{
+ if(resuming)
+ bytesAvailable = period_size;
+ else if(deviceState != QAudio::ActiveState
+ && deviceState != QAudio::IdleState)
+ bytesAvailable = 0;
+ else {
+ int frames = snd_pcm_avail_update(handle);
+ if (frames < 0) {
+ bytesAvailable = frames;
+ } else {
+ if((int)frames > (int)buffer_frames)
+ frames = buffer_frames;
+ bytesAvailable = snd_pcm_frames_to_bytes(handle, frames);
+ }
+ }
+ return bytesAvailable;
+}
+
+qsizetype QAlsaAudioSource::bytesReady() const
+{
+ return qMax(bytesAvailable, 0);
+}
+
+qint64 QAlsaAudioSource::read(char* data, qint64 len)
+{
+ // Read in some audio data and write it to QIODevice, pull mode
+ if ( !handle )
+ return 0;
+
+ int bytesRead = 0;
+ int bytesInRingbufferBeforeRead = ringBuffer.bytesOfDataInBuffer();
+
+ if (ringBuffer.bytesOfDataInBuffer() < len) {
+
+ // bytesAvaiable is saved as a side effect of checkBytesReady().
+ int bytesToRead = checkBytesReady();
+
+ if (bytesToRead < 0) {
+ // bytesAvailable as negative is error code, try to recover from it.
+ xrun_recovery(bytesToRead);
+ bytesToRead = checkBytesReady();
+ if (bytesToRead < 0) {
+ // recovery failed must stop and set error.
+ close();
+ errorState = QAudio::IOError;
+ deviceState = QAudio::StoppedState;
+ emit stateChanged(deviceState);
+ return 0;
+ }
+ }
+
+ bytesToRead = qMin<qint64>(len, bytesToRead);
+ bytesToRead = qMin<qint64>(ringBuffer.freeBytes(), bytesToRead);
+ bytesToRead -= bytesToRead % period_size;
+
+ int count=0;
+ int err = 0;
+ QVarLengthArray<char, 4096> buffer(bytesToRead);
+ while(count < 5 && bytesToRead > 0) {
+ int chunks = bytesToRead / period_size;
+ int frames = chunks * period_frames;
+ if (frames > (int)buffer_frames)
+ frames = buffer_frames;
+
+ int readFrames = snd_pcm_readi(handle, buffer.data(), frames);
+ bytesRead = snd_pcm_frames_to_bytes(handle, readFrames);
+ if (m_volume < 1.0f)
+ QAudioHelperInternal::qMultiplySamples(m_volume, settings,
+ buffer.constData(),
+ buffer.data(), bytesRead);
+
+ if (readFrames >= 0) {
+ ringBuffer.write(buffer.data(), bytesRead);
+#ifdef DEBUG_AUDIO
+ qDebug() << QString::fromLatin1("read in bytes = %1 (frames=%2)").arg(bytesRead).arg(readFrames).toLatin1().constData();
+#endif
+ break;
+ } else if((readFrames == -EAGAIN) || (readFrames == -EINTR)) {
+ errorState = QAudio::IOError;
+ err = 0;
+ break;
+ } else {
+ if(readFrames == -EPIPE) {
+ errorState = QAudio::UnderrunError;
+ err = snd_pcm_prepare(handle);
+#ifdef ESTRPIPE
+ } else if(readFrames == -ESTRPIPE) {
+ err = snd_pcm_prepare(handle);
+#endif
+ }
+ if(err != 0) break;
+ }
+ count++;
+ }
+
+ }
+
+ bytesRead += bytesInRingbufferBeforeRead;
+
+ if (bytesRead > 0) {
+ // got some send it onward
+#ifdef DEBUG_AUDIO
+ qDebug() << "frames to write to QIODevice = " <<
+ snd_pcm_bytes_to_frames( handle, (int)bytesRead ) << " (" << bytesRead << ") bytes";
+#endif
+ if (deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
+ return 0;
+
+ if (pullMode) {
+ qint64 l = 0;
+ qint64 bytesWritten = 0;
+ while (ringBuffer.bytesOfDataInBuffer() > 0) {
+ l = audioSource->write(ringBuffer.availableData(), ringBuffer.availableDataBlockSize());
+ if (l > 0) {
+ ringBuffer.readBytes(l);
+ bytesWritten += l;
+ } else {
+ break;
+ }
+ }
+
+ if (l < 0) {
+ close();
+ errorState = QAudio::IOError;
+ deviceState = QAudio::StoppedState;
+ emit stateChanged(deviceState);
+ } else if (l == 0 && bytesWritten == 0) {
+ if (deviceState != QAudio::IdleState) {
+ errorState = QAudio::NoError;
+ deviceState = QAudio::IdleState;
+ emit stateChanged(deviceState);
+ }
+ } else {
+ bytesAvailable -= bytesWritten;
+ totalTimeValue += bytesWritten;
+ resuming = false;
+ if (deviceState != QAudio::ActiveState) {
+ errorState = QAudio::NoError;
+ deviceState = QAudio::ActiveState;
+ emit stateChanged(deviceState);
+ }
+ }
+
+ return bytesWritten;
+ } else {
+ while (ringBuffer.bytesOfDataInBuffer() > 0) {
+ int size = ringBuffer.availableDataBlockSize();
+ memcpy(data, ringBuffer.availableData(), size);
+ data += size;
+ ringBuffer.readBytes(size);
+ }
+
+ bytesAvailable -= bytesRead;
+ totalTimeValue += bytesRead;
+ resuming = false;
+ if (deviceState != QAudio::ActiveState) {
+ errorState = QAudio::NoError;
+ deviceState = QAudio::ActiveState;
+ emit stateChanged(deviceState);
+ }
+
+ return bytesRead;
+ }
+ }
+
+ return 0;
+}
+
+void QAlsaAudioSource::resume()
+{
+ if(deviceState == QAudio::SuspendedState) {
+ int err = 0;
+
+ if(handle) {
+ err = snd_pcm_prepare( handle );
+ if(err < 0)
+ xrun_recovery(err);
+
+ err = snd_pcm_start(handle);
+ if(err < 0)
+ xrun_recovery(err);
+
+ bytesAvailable = buffer_size;
+ }
+ resuming = true;
+ deviceState = QAudio::ActiveState;
+ int chunks = buffer_size/period_size;
+ timer->start(period_time*chunks/2000);
+ emit stateChanged(deviceState);
+ }
+}
+
+void QAlsaAudioSource::setBufferSize(qsizetype value)
+{
+ buffer_size = value;
+}
+
+qsizetype QAlsaAudioSource::bufferSize() const
+{
+ return buffer_size;
+}
+
+qint64 QAlsaAudioSource::processedUSecs() const
+{
+ qint64 result = qint64(1000000) * totalTimeValue /
+ settings.bytesPerFrame() /
+ settings.sampleRate();
+
+ return result;
+}
+
+void QAlsaAudioSource::suspend()
+{
+ if(deviceState == QAudio::ActiveState||resuming) {
+ snd_pcm_drain(handle);
+ timer->stop();
+ deviceState = QAudio::SuspendedState;
+ emit stateChanged(deviceState);
+ }
+}
+
+void QAlsaAudioSource::userFeed()
+{
+ if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState)
+ return;
+#ifdef DEBUG_AUDIO
+ QTime now(QTime::currentTime());
+ qDebug()<<now.second()<<"s "<<now.msec()<<"ms :userFeed() IN";
+#endif
+ deviceReady();
+}
+
+bool QAlsaAudioSource::deviceReady()
+{
+ if(pullMode) {
+ // reads some audio data and writes it to QIODevice
+ read(0, buffer_size);
+ } else {
+ // emits readyRead() so user will call read() on QIODevice to get some audio data
+ AlsaInputPrivate* a = qobject_cast<AlsaInputPrivate*>(audioSource);
+ a->trigger();
+ }
+ bytesAvailable = checkBytesReady();
+
+ if(deviceState != QAudio::ActiveState)
+ return true;
+
+ if (bytesAvailable < 0) {
+ // bytesAvailable as negative is error code, try to recover from it.
+ xrun_recovery(bytesAvailable);
+ bytesAvailable = checkBytesReady();
+ if (bytesAvailable < 0) {
+ // recovery failed must stop and set error.
+ close();
+ errorState = QAudio::IOError;
+ deviceState = QAudio::StoppedState;
+ emit stateChanged(deviceState);
+ return 0;
+ }
+ }
+
+ return true;
+}
+
+void QAlsaAudioSource::reset()
+{
+ if(handle)
+ snd_pcm_reset(handle);
+ stop();
+ bytesAvailable = 0;
+}
+
+void QAlsaAudioSource::drain()
+{
+ if(handle)
+ snd_pcm_drain(handle);
+}
+
+AlsaInputPrivate::AlsaInputPrivate(QAlsaAudioSource* audio)
+{
+ audioDevice = qobject_cast<QAlsaAudioSource*>(audio);
+}
+
+AlsaInputPrivate::~AlsaInputPrivate()
+{
+}
+
+qint64 AlsaInputPrivate::readData( char* data, qint64 len)
+{
+ return audioDevice->read(data,len);
+}
+
+qint64 AlsaInputPrivate::writeData(const char* data, qint64 len)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(len);
+ return 0;
+}
+
+void AlsaInputPrivate::trigger()
+{
+ emit readyRead();
+}
+
+RingBuffer::RingBuffer() :
+ m_head(0),
+ m_tail(0)
+{
+}
+
+void RingBuffer::resize(int size)
+{
+ m_data.resize(size);
+}
+
+int RingBuffer::bytesOfDataInBuffer() const
+{
+ if (m_head < m_tail)
+ return m_tail - m_head;
+ else if (m_tail < m_head)
+ return m_data.size() + m_tail - m_head;
+ else
+ return 0;
+}
+
+int RingBuffer::freeBytes() const
+{
+ if (m_head > m_tail)
+ return m_head - m_tail - 1;
+ else if (m_tail > m_head)
+ return m_data.size() - m_tail + m_head - 1;
+ else
+ return m_data.size() - 1;
+}
+
+const char *RingBuffer::availableData() const
+{
+ return (m_data.constData() + m_head);
+}
+
+int RingBuffer::availableDataBlockSize() const
+{
+ if (m_head > m_tail)
+ return m_data.size() - m_head;
+ else if (m_tail > m_head)
+ return m_tail - m_head;
+ else
+ return 0;
+}
+
+void RingBuffer::readBytes(int bytes)
+{
+ m_head = (m_head + bytes) % m_data.size();
+}
+
+void RingBuffer::write(char *data, int len)
+{
+ if (m_tail + len < m_data.size()) {
+ memcpy(m_data.data() + m_tail, data, len);
+ m_tail += len;
+ } else {
+ int bytesUntilEnd = m_data.size() - m_tail;
+ memcpy(m_data.data() + m_tail, data, bytesUntilEnd);
+ if (len - bytesUntilEnd > 0)
+ memcpy(m_data.data(), data + bytesUntilEnd, len - bytesUntilEnd);
+ m_tail = len - bytesUntilEnd;
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qalsaaudiosource_p.cpp"
diff --git a/src/multimedia/alsa/qalsaaudiosource_p.h b/src/multimedia/alsa/qalsaaudiosource_p.h
new file mode 100644
index 000000000..87487a6ad
--- /dev/null
+++ b/src/multimedia/alsa/qalsaaudiosource_p.h
@@ -0,0 +1,142 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+
+#ifndef QAUDIOINPUTALSA_H
+#define QAUDIOINPUTALSA_H
+
+#include <alsa/asoundlib.h>
+
+#include <QtCore/qfile.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qtimer.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qelapsedtimer.h>
+#include <QtCore/qiodevice.h>
+
+#include <QtMultimedia/qaudio.h>
+#include <QtMultimedia/qaudiodevice.h>
+#include <private/qaudiosystem_p.h>
+
+QT_BEGIN_NAMESPACE
+
+
+class AlsaInputPrivate;
+
+class RingBuffer
+{
+public:
+ RingBuffer();
+
+ void resize(int size);
+
+ int bytesOfDataInBuffer() const;
+ int freeBytes() const;
+
+ const char *availableData() const;
+ int availableDataBlockSize() const;
+ void readBytes(int bytes);
+
+ void write(char *data, int len);
+
+private:
+ int m_head;
+ int m_tail;
+
+ QByteArray m_data;
+};
+
+class QAlsaAudioSource : public QPlatformAudioSource
+{
+ Q_OBJECT
+public:
+ QAlsaAudioSource(const QByteArray &device, QObject *parent);
+ ~QAlsaAudioSource();
+
+ qint64 read(char* data, qint64 len);
+
+ void start(QIODevice* device) override;
+ QIODevice* start() override;
+ void stop() override;
+ void reset() override;
+ void suspend() override;
+ void resume() override;
+ qsizetype bytesReady() const override;
+ void setBufferSize(qsizetype value) override;
+ qsizetype bufferSize() const override;
+ qint64 processedUSecs() const override;
+ QAudio::Error error() const override;
+ QAudio::State state() const override;
+ void setFormat(const QAudioFormat& fmt) override;
+ QAudioFormat format() const override;
+ void setVolume(qreal) override;
+ qreal volume() const override;
+ bool resuming;
+ snd_pcm_t* handle;
+ qint64 totalTimeValue;
+ QIODevice* audioSource;
+ QAudioFormat settings;
+ QAudio::Error errorState;
+ QAudio::State deviceState;
+
+private slots:
+ void userFeed();
+ bool deviceReady();
+
+private:
+ int checkBytesReady();
+ int xrun_recovery(int err);
+ int setFormat();
+ bool open();
+ void close();
+ void drain();
+
+ QTimer* timer;
+ qint64 elapsedTimeOffset;
+ RingBuffer ringBuffer;
+ qsizetype bytesAvailable;
+ QByteArray m_device;
+ bool pullMode;
+ qsizetype buffer_size;
+ int period_size;
+ unsigned int buffer_time;
+ unsigned int period_time;
+ snd_pcm_uframes_t buffer_frames;
+ snd_pcm_uframes_t period_frames;
+ snd_pcm_access_t access;
+ snd_pcm_format_t pcmformat;
+ snd_pcm_hw_params_t *hwparams;
+ qreal m_volume;
+};
+
+class AlsaInputPrivate : public QIODevice
+{
+ Q_OBJECT
+public:
+ AlsaInputPrivate(QAlsaAudioSource* audio);
+ ~AlsaInputPrivate();
+
+ qint64 readData( char* data, qint64 len) override;
+ qint64 writeData(const char* data, qint64 len) override;
+
+ void trigger();
+private:
+ QAlsaAudioSource *audioDevice;
+};
+
+QT_END_NAMESPACE
+
+
+#endif
diff --git a/src/multimedia/alsa/qalsamediadevices.cpp b/src/multimedia/alsa/qalsamediadevices.cpp
new file mode 100644
index 000000000..9466fa0cd
--- /dev/null
+++ b/src/multimedia/alsa/qalsamediadevices.cpp
@@ -0,0 +1,130 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qalsamediadevices_p.h"
+#include "qmediadevices.h"
+#include "qcameradevice_p.h"
+
+#include "private/qalsaaudiosource_p.h"
+#include "private/qalsaaudiosink_p.h"
+#include "private/qalsaaudiodevice_p.h"
+
+#include <alsa/asoundlib.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+
+struct free_char
+{
+ void operator()(char *c) const { ::free(c); }
+};
+
+using unique_str = std::unique_ptr<char, free_char>;
+
+bool operator==(const unique_str &str, std::string_view sv)
+{
+ return std::string_view{ str.get() } == sv;
+}
+bool operator!=(const unique_str &str, std::string_view sv)
+{
+ return !(str == sv);
+}
+
+} // namespace
+
+QAlsaMediaDevices::QAlsaMediaDevices()
+ : QPlatformMediaDevices()
+{
+}
+
+static QList<QAudioDevice> availableDevices(QAudioDevice::Mode mode)
+{
+ QList<QAudioDevice> devices;
+
+ // Create a list of all current audio devices that support mode
+ void **hints;
+ if (snd_device_name_hint(-1, "pcm", &hints) < 0) {
+ qWarning() << "no alsa devices available";
+ return devices;
+ }
+
+ std::string_view filter = (mode == QAudioDevice::Input) ? "Input" : "Output";
+
+ QAlsaAudioDeviceInfo *sysdefault = nullptr;
+
+ auto makeDeviceInfo = [&filter, mode](void *entry) -> QAlsaAudioDeviceInfo * {
+ unique_str name{ snd_device_name_get_hint(entry, "NAME") };
+ if (name && name != "null") {
+ unique_str descr{ snd_device_name_get_hint(entry, "DESC") };
+ unique_str io{ snd_device_name_get_hint(entry, "IOID") };
+
+ if (descr && (!io || (io == filter))) {
+ auto *infop = new QAlsaAudioDeviceInfo{
+ name.get(),
+ QString::fromUtf8(descr.get()),
+ mode,
+ };
+ return infop;
+ }
+ }
+ return nullptr;
+ };
+
+ bool hasDefault = false;
+ void **n = hints;
+ while (*n != NULL) {
+ QAlsaAudioDeviceInfo *infop = makeDeviceInfo(*n++);
+
+ if (infop) {
+ devices.append(infop->create());
+ if (!hasDefault && infop->id.startsWith("default")) {
+ infop->isDefault = true;
+ hasDefault = true;
+ }
+ if (!sysdefault && infop->id.startsWith("sysdefault"))
+ sysdefault = infop;
+ }
+ }
+
+ if (!hasDefault && sysdefault) {
+ // Make "sysdefault" the default device if there is no "default" device exists
+ sysdefault->isDefault = true;
+ hasDefault = true;
+ }
+ if (!hasDefault && devices.size() > 0) {
+ // forcefully declare the first device as "default"
+ QAlsaAudioDeviceInfo *infop = makeDeviceInfo(hints[0]);
+ if (infop) {
+ infop->isDefault = true;
+ devices.prepend(infop->create());
+ }
+ }
+
+ snd_device_name_free_hint(hints);
+ return devices;
+}
+
+QList<QAudioDevice> QAlsaMediaDevices::audioInputs() const
+{
+ return availableDevices(QAudioDevice::Input);
+}
+
+QList<QAudioDevice> QAlsaMediaDevices::audioOutputs() const
+{
+ return availableDevices(QAudioDevice::Output);
+}
+
+QPlatformAudioSource *QAlsaMediaDevices::createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ return new QAlsaAudioSource(deviceInfo.id(), parent);
+}
+
+QPlatformAudioSink *QAlsaMediaDevices::createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ return new QAlsaAudioSink(deviceInfo.id(), parent);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/alsa/qalsamediadevices_p.h b/src/multimedia/alsa/qalsamediadevices_p.h
new file mode 100644
index 000000000..d9fbb7c97
--- /dev/null
+++ b/src/multimedia/alsa/qalsamediadevices_p.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QALSAMEDIADEVICES_H
+#define QALSAMEDIADEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediadevices_p.h>
+#include <qset.h>
+#include <qaudio.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAlsaEngine;
+
+class QAlsaMediaDevices : public QPlatformMediaDevices
+{
+public:
+ QAlsaMediaDevices();
+
+ QList<QAudioDevice> audioInputs() const override;
+ QList<QAudioDevice> audioOutputs() const override;
+ QPlatformAudioSource *createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+ QPlatformAudioSink *createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/android/qandroidaudiodevice.cpp b/src/multimedia/android/qandroidaudiodevice.cpp
new file mode 100644
index 000000000..576774fd8
--- /dev/null
+++ b/src/multimedia/android/qandroidaudiodevice.cpp
@@ -0,0 +1,39 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidaudiodevice_p.h"
+
+#include "qopenslesengine_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QOpenSLESDeviceInfo::QOpenSLESDeviceInfo(const QByteArray &device, const QString &desc, QAudioDevice::Mode mode)
+ : QAudioDevicePrivate(device, mode),
+ m_engine(QOpenSLESEngine::instance())
+{
+ description = desc;
+
+ auto channels = m_engine->supportedChannelCounts(mode);
+ if (channels.size()) {
+ minimumChannelCount = channels.first();
+ maximumChannelCount = channels.last();
+ }
+
+ auto sampleRates = m_engine->supportedSampleRates(mode);
+ if (sampleRates.size()) {
+ minimumSampleRate = sampleRates.first();
+ maximumSampleRate = sampleRates.last();
+ }
+ if (mode == QAudioDevice::Input)
+ supportedSampleFormats.append(QAudioFormat::UInt8);
+ supportedSampleFormats.append(QAudioFormat::Int16);
+
+ preferredFormat.setChannelCount(2);
+ preferredFormat.setSampleRate(48000);
+ QAudioFormat::SampleFormat f = QAudioFormat::Int16;
+ if (!supportedSampleFormats.contains(f))
+ f = supportedSampleFormats.value(0, QAudioFormat::Unknown);
+ preferredFormat.setSampleFormat(f);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/android/qandroidaudiodevice_p.h b/src/multimedia/android/qandroidaudiodevice_p.h
new file mode 100644
index 000000000..d448306fe
--- /dev/null
+++ b/src/multimedia/android/qandroidaudiodevice_p.h
@@ -0,0 +1,37 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QOPENSLESDEVICEINFO_H
+#define QOPENSLESDEVICEINFO_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qaudiosystem_p.h>
+#include <private/qaudiodevice_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QOpenSLESEngine;
+
+class QOpenSLESDeviceInfo : public QAudioDevicePrivate
+{
+public:
+ QOpenSLESDeviceInfo(const QByteArray &device, const QString &desc, QAudioDevice::Mode mode);
+ ~QOpenSLESDeviceInfo() {}
+
+private:
+ QOpenSLESEngine *m_engine;
+};
+
+QT_END_NAMESPACE
+
+#endif // QOPENSLESDEVICEINFO_H
diff --git a/src/multimedia/android/qandroidaudiosink.cpp b/src/multimedia/android/qandroidaudiosink.cpp
new file mode 100644
index 000000000..4da4c5fdc
--- /dev/null
+++ b/src/multimedia/android/qandroidaudiosink.cpp
@@ -0,0 +1,614 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidaudiosink_p.h"
+#include "qopenslesengine_p.h"
+#include <QDebug>
+#include <qmath.h>
+#include <qmediadevices.h>
+
+#ifdef ANDROID
+#include <SLES/OpenSLES_Android.h>
+#include <SLES/OpenSLES_AndroidConfiguration.h>
+#endif // ANDROID
+
+QT_BEGIN_NAMESPACE
+
+static inline void openSlDebugInfo()
+{
+ const QAudioFormat &format = QMediaDevices::defaultAudioOutput().preferredFormat();
+ qDebug() << "======= OpenSL ES Device info ======="
+ << "\nSupports low-latency playback: " << (QOpenSLESEngine::supportsLowLatency() ? "YES" : "NO")
+ << "\nPreferred sample rate: " << QOpenSLESEngine::getOutputValue(QOpenSLESEngine::SampleRate, -1)
+ << "\nFrames per buffer: " << QOpenSLESEngine::getOutputValue(QOpenSLESEngine::FramesPerBuffer, -1)
+ << "\nPreferred Format: " << format
+ << "\nLow-latency buffer size: " << QOpenSLESEngine::getLowLatencyBufferSize(format)
+ << "\nDefault buffer size: " << QOpenSLESEngine::getDefaultBufferSize(format);
+}
+
+QAndroidAudioSink::QAndroidAudioSink(const QByteArray &device, QObject *parent)
+ : QPlatformAudioSink(parent),
+ m_deviceName(device)
+{
+#ifndef ANDROID
+ m_streamType = -1;
+#else
+ m_streamType = SL_ANDROID_STREAM_MEDIA;
+#endif // ANDROID
+}
+
+QAndroidAudioSink::~QAndroidAudioSink()
+{
+ destroyPlayer();
+}
+
+QAudio::Error QAndroidAudioSink::error() const
+{
+ return m_error;
+}
+
+QAudio::State QAndroidAudioSink::state() const
+{
+ return m_state;
+}
+
+void QAndroidAudioSink::start(QIODevice *device)
+{
+ Q_ASSERT(device);
+
+ if (m_state != QAudio::StoppedState)
+ stop();
+
+ if (!preparePlayer())
+ return;
+
+ m_endSound = false;
+ m_pullMode = true;
+ m_audioSource = device;
+ m_nextBuffer = 0;
+ m_processedBytes = 0;
+ m_availableBuffers = BufferCount;
+ setState(QAudio::ActiveState);
+ setError(QAudio::NoError);
+
+ // Attempt to fill buffers first.
+ for (int i = 0; i != BufferCount; ++i) {
+ const int index = i * m_bufferSize;
+ const qint64 readSize = m_audioSource->read(m_buffers + index, m_bufferSize);
+ if (readSize && SL_RESULT_SUCCESS != (*m_bufferQueueItf)->Enqueue(m_bufferQueueItf,
+ m_buffers + index,
+ readSize)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ return;
+ }
+ m_processedBytes += readSize;
+ }
+
+ if (m_processedBytes < 1)
+ onEOSEvent();
+
+ // Change the state to playing.
+ // We need to do this after filling the buffers or processedBytes might get corrupted.
+ startPlayer();
+ connect(m_audioSource, &QIODevice::readyRead, this, &QAndroidAudioSink::readyRead);
+}
+
+void QAndroidAudioSink::readyRead()
+{
+ if (m_pullMode && m_state == QAudio::IdleState) {
+ setState(QAudio::ActiveState);
+ setError(QAudio::NoError);
+ QMetaObject::invokeMethod(this, "bufferAvailable", Qt::QueuedConnection);
+ }
+}
+
+QIODevice *QAndroidAudioSink::start()
+{
+ if (m_state != QAudio::StoppedState)
+ stop();
+
+ if (!preparePlayer())
+ return nullptr;
+
+ m_pullMode = false;
+ m_processedBytes = 0;
+ m_availableBuffers = BufferCount;
+ m_audioSource = new SLIODevicePrivate(this);
+ m_audioSource->open(QIODevice::WriteOnly | QIODevice::Unbuffered);
+
+ // Change the state to playing
+ startPlayer();
+
+ setState(QAudio::IdleState);
+ return m_audioSource;
+}
+
+void QAndroidAudioSink::stop()
+{
+ if (m_state == QAudio::StoppedState)
+ return;
+
+ stopPlayer();
+ setError(QAudio::NoError);
+}
+
+qsizetype QAndroidAudioSink::bytesFree() const
+{
+ if (m_state != QAudio::ActiveState && m_state != QAudio::IdleState)
+ return 0;
+
+ return m_availableBuffers.loadAcquire() ? m_bufferSize : 0;
+}
+
+void QAndroidAudioSink::setBufferSize(qsizetype value)
+{
+ if (m_state != QAudio::StoppedState)
+ return;
+
+ m_startRequiresInit = true;
+ m_bufferSize = value;
+}
+
+qsizetype QAndroidAudioSink::bufferSize() const
+{
+ return m_bufferSize;
+}
+
+qint64 QAndroidAudioSink::processedUSecs() const
+{
+ if (m_state == QAudio::IdleState || m_state == QAudio::SuspendedState)
+ return m_format.durationForBytes(m_processedBytes);
+
+ SLmillisecond processMSec = 0;
+ if (m_playItf)
+ (*m_playItf)->GetPosition(m_playItf, &processMSec);
+
+ return processMSec * 1000;
+}
+
+void QAndroidAudioSink::resume()
+{
+ if (m_state != QAudio::SuspendedState)
+ return;
+
+ if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PLAYING)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ return;
+ }
+
+ setState(m_suspendedInState);
+ setError(QAudio::NoError);
+}
+
+void QAndroidAudioSink::setFormat(const QAudioFormat &format)
+{
+ m_startRequiresInit = true;
+ m_format = format;
+}
+
+QAudioFormat QAndroidAudioSink::format() const
+{
+ return m_format;
+}
+
+void QAndroidAudioSink::suspend()
+{
+ if (m_state != QAudio::ActiveState && m_state != QAudio::IdleState)
+ return;
+
+ if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PAUSED)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ return;
+ }
+
+ m_suspendedInState = m_state;
+ setState(QAudio::SuspendedState);
+ setError(QAudio::NoError);
+}
+
+void QAndroidAudioSink::reset()
+{
+ destroyPlayer();
+}
+
+void QAndroidAudioSink::setVolume(qreal vol)
+{
+ m_volume = qBound(qreal(0.0), vol, qreal(1.0));
+ const SLmillibel newVolume = adjustVolume(m_volume);
+ if (m_volumeItf && SL_RESULT_SUCCESS != (*m_volumeItf)->SetVolumeLevel(m_volumeItf, newVolume))
+ qWarning() << "Unable to change volume";
+}
+
+qreal QAndroidAudioSink::volume() const
+{
+ return m_volume;
+}
+
+void QAndroidAudioSink::onEOSEvent()
+{
+ if (m_state != QAudio::ActiveState)
+ return;
+
+ SLBufferQueueState state;
+ if (SL_RESULT_SUCCESS != (*m_bufferQueueItf)->GetState(m_bufferQueueItf, &state))
+ return;
+
+ if (state.count > 0)
+ return;
+
+ setState(QAudio::IdleState);
+ setError(QAudio::UnderrunError);
+}
+
+void QAndroidAudioSink::onBytesProcessed(qint64 bytes)
+{
+ m_processedBytes += bytes;
+}
+
+void QAndroidAudioSink::bufferAvailable()
+{
+ if (m_state == QAudio::StoppedState)
+ return;
+
+ if (!m_pullMode) { // We're in push mode.
+ // Signal that there is a new open slot in the buffer and return
+ const int val = m_availableBuffers.fetchAndAddRelease(1) + 1;
+ if (val == BufferCount)
+ QMetaObject::invokeMethod(this, "onEOSEvent", Qt::QueuedConnection);
+
+ return;
+ }
+
+ // We're in pull mode.
+ const int index = m_nextBuffer * m_bufferSize;
+ qint64 readSize = 0;
+ if (m_audioSource->atEnd()) {
+ // The whole sound was passed to player buffer, but setting SL_PLAYSTATE_STOPPED state
+ // too quickly will result in cutting of end of the sound. Therefore, we make it a little
+ // longer with empty data to make sure they will be played correctly
+ if (m_endSound) {
+ m_endSound = false;
+ setState(QAudio::IdleState);
+ return;
+ }
+ m_endSound = true;
+ readSize = m_bufferSize;
+ memset(m_buffers + index, 0, readSize);
+ } else {
+ readSize = m_audioSource->read(m_buffers + index, m_bufferSize);
+ }
+
+
+ if (readSize < 1) {
+ QMetaObject::invokeMethod(this, "onEOSEvent", Qt::QueuedConnection);
+ return;
+ }
+
+
+ if (SL_RESULT_SUCCESS != (*m_bufferQueueItf)->Enqueue(m_bufferQueueItf,
+ m_buffers + index,
+ readSize)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ return;
+ }
+
+ m_nextBuffer = (m_nextBuffer + 1) % BufferCount;
+ if (!m_endSound) {
+ QMetaObject::invokeMethod(this, "onBytesProcessed", Qt::QueuedConnection, Q_ARG(qint64, readSize));
+ }
+}
+
+void QAndroidAudioSink::playCallback(SLPlayItf player, void *ctx, SLuint32 event)
+{
+ Q_UNUSED(player);
+ QAndroidAudioSink *audioOutput = reinterpret_cast<QAndroidAudioSink *>(ctx);
+ if (event & SL_PLAYEVENT_HEADATEND)
+ QMetaObject::invokeMethod(audioOutput, "onEOSEvent", Qt::QueuedConnection);
+}
+
+void QAndroidAudioSink::bufferQueueCallback(SLBufferQueueItf bufferQueue, void *ctx)
+{
+ Q_UNUSED(bufferQueue);
+ QAndroidAudioSink *audioOutput = reinterpret_cast<QAndroidAudioSink *>(ctx);
+ QMetaObject::invokeMethod(audioOutput, "bufferAvailable", Qt::QueuedConnection);
+}
+
+bool QAndroidAudioSink::preparePlayer()
+{
+ if (m_startRequiresInit)
+ destroyPlayer();
+ else
+ return true;
+
+ if (!QOpenSLESEngine::setAudioOutput(m_deviceName))
+ qWarning() << "Unable to set up Audio Output Device";
+
+ SLEngineItf engine = QOpenSLESEngine::instance()->slEngine();
+ if (!engine) {
+ qWarning() << "No engine";
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ SLDataLocator_BufferQueue bufferQueueLocator = { SL_DATALOCATOR_BUFFERQUEUE, BufferCount };
+ SLAndroidDataFormat_PCM_EX pcmFormat = QOpenSLESEngine::audioFormatToSLFormatPCM(m_format);
+
+ SLDataSource audioSrc = { &bufferQueueLocator, &pcmFormat };
+
+ // OutputMix
+ if (SL_RESULT_SUCCESS != (*engine)->CreateOutputMix(engine,
+ &m_outputMixObject,
+ 0,
+ nullptr,
+ nullptr)) {
+ qWarning() << "Unable to create output mix";
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ if (SL_RESULT_SUCCESS != (*m_outputMixObject)->Realize(m_outputMixObject, SL_BOOLEAN_FALSE)) {
+ qWarning() << "Unable to initialize output mix";
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ SLDataLocator_OutputMix outputMixLocator = { SL_DATALOCATOR_OUTPUTMIX, m_outputMixObject };
+ SLDataSink audioSink = { &outputMixLocator, nullptr };
+
+#ifndef ANDROID
+ const int iids = 2;
+ const SLInterfaceID ids[iids] = { SL_IID_BUFFERQUEUE, SL_IID_VOLUME };
+ const SLboolean req[iids] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
+#else
+ const int iids = 3;
+ const SLInterfaceID ids[iids] = { SL_IID_BUFFERQUEUE,
+ SL_IID_VOLUME,
+ SL_IID_ANDROIDCONFIGURATION };
+ const SLboolean req[iids] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
+#endif // ANDROID
+
+ // AudioPlayer
+ if (SL_RESULT_SUCCESS != (*engine)->CreateAudioPlayer(engine,
+ &m_playerObject,
+ &audioSrc,
+ &audioSink,
+ iids,
+ ids,
+ req)) {
+ qWarning() << "Unable to create AudioPlayer";
+ setError(QAudio::OpenError);
+ return false;
+ }
+
+#ifdef ANDROID
+ // Set profile/category
+ SLAndroidConfigurationItf playerConfig;
+ if (SL_RESULT_SUCCESS == (*m_playerObject)->GetInterface(m_playerObject,
+ SL_IID_ANDROIDCONFIGURATION,
+ &playerConfig)) {
+ (*playerConfig)->SetConfiguration(playerConfig,
+ SL_ANDROID_KEY_STREAM_TYPE,
+ &m_streamType,
+ sizeof(SLint32));
+ }
+#endif // ANDROID
+
+ if (SL_RESULT_SUCCESS != (*m_playerObject)->Realize(m_playerObject, SL_BOOLEAN_FALSE)) {
+ qWarning() << "Unable to initialize AudioPlayer";
+ setError(QAudio::OpenError);
+ return false;
+ }
+
+ // Buffer interface
+ if (SL_RESULT_SUCCESS != (*m_playerObject)->GetInterface(m_playerObject,
+ SL_IID_BUFFERQUEUE,
+ &m_bufferQueueItf)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ if (SL_RESULT_SUCCESS != (*m_bufferQueueItf)->RegisterCallback(m_bufferQueueItf,
+ bufferQueueCallback,
+ this)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ // Play interface
+ if (SL_RESULT_SUCCESS != (*m_playerObject)->GetInterface(m_playerObject,
+ SL_IID_PLAY,
+ &m_playItf)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ if (SL_RESULT_SUCCESS != (*m_playItf)->RegisterCallback(m_playItf, playCallback, this)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ if (SL_RESULT_SUCCESS != (*m_playItf)->SetCallbackEventsMask(m_playItf, m_eventMask)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ // Volume interface
+ if (SL_RESULT_SUCCESS != (*m_playerObject)->GetInterface(m_playerObject,
+ SL_IID_VOLUME,
+ &m_volumeItf)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ setVolume(m_volume);
+
+ const int lowLatencyBufferSize = QOpenSLESEngine::getLowLatencyBufferSize(m_format);
+ const int defaultBufferSize = QOpenSLESEngine::getDefaultBufferSize(m_format);
+
+ if (defaultBufferSize <= 0) {
+ qWarning() << "Unable to get minimum buffer size, returned" << defaultBufferSize;
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ // Buffer size
+ if (m_bufferSize <= 0) {
+ m_bufferSize = defaultBufferSize;
+ } else if (QOpenSLESEngine::supportsLowLatency()) {
+ if (m_bufferSize < lowLatencyBufferSize)
+ m_bufferSize = lowLatencyBufferSize;
+ } else if (m_bufferSize < defaultBufferSize) {
+ m_bufferSize = defaultBufferSize;
+ }
+
+ if (!m_buffers)
+ m_buffers = new char[BufferCount * m_bufferSize];
+
+ setError(QAudio::NoError);
+ m_startRequiresInit = false;
+
+ return true;
+}
+
+void QAndroidAudioSink::destroyPlayer()
+{
+ if (m_state != QAudio::StoppedState)
+ stopPlayer();
+
+ if (m_playerObject) {
+ (*m_playerObject)->Destroy(m_playerObject);
+ m_playerObject = nullptr;
+ }
+
+ if (m_outputMixObject) {
+ (*m_outputMixObject)->Destroy(m_outputMixObject);
+ m_outputMixObject = nullptr;
+ }
+
+ if (!m_pullMode && m_audioSource) {
+ m_audioSource->close();
+ delete m_audioSource;
+ m_audioSource = nullptr;
+ }
+
+ delete [] m_buffers;
+ m_buffers = nullptr;
+ m_processedBytes = 0;
+ m_nextBuffer = 0;
+ m_availableBuffers.storeRelease(BufferCount);
+ m_playItf = nullptr;
+ m_volumeItf = nullptr;
+ m_bufferQueueItf = nullptr;
+ m_startRequiresInit = true;
+}
+
+void QAndroidAudioSink::stopPlayer()
+{
+ setState(QAudio::StoppedState);
+
+ if (m_audioSource) {
+ if (m_pullMode) {
+ disconnect(m_audioSource, &QIODevice::readyRead, this, &QAndroidAudioSink::readyRead);
+ } else {
+ m_audioSource->close();
+ delete m_audioSource;
+ m_audioSource = nullptr;
+ }
+ }
+
+ // We need to change the state manually...
+ if (m_playItf)
+ (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_STOPPED);
+
+ if (m_bufferQueueItf && SL_RESULT_SUCCESS != (*m_bufferQueueItf)->Clear(m_bufferQueueItf))
+ qWarning() << "Unable to clear buffer";
+}
+
+void QAndroidAudioSink::startPlayer()
+{
+ if (QOpenSLESEngine::printDebugInfo())
+ openSlDebugInfo();
+
+ if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PLAYING)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ }
+}
+
+qint64 QAndroidAudioSink::writeData(const char *data, qint64 len)
+{
+ if (!len)
+ return 0;
+
+ if (len > m_bufferSize)
+ len = m_bufferSize;
+
+ // Acquire one slot in the buffer
+ const int before = m_availableBuffers.fetchAndAddAcquire(-1);
+
+ // If there where no vacant slots, then we just overdrew the buffer account...
+ if (before < 1) {
+ m_availableBuffers.fetchAndAddRelease(1);
+ return 0;
+ }
+
+ const int index = m_nextBuffer * m_bufferSize;
+ ::memcpy(m_buffers + index, data, len);
+ const SLuint32 res = (*m_bufferQueueItf)->Enqueue(m_bufferQueueItf,
+ m_buffers + index,
+ len);
+
+ // If we where unable to enqueue a new buffer, give back the acquired slot.
+ if (res == SL_RESULT_BUFFER_INSUFFICIENT) {
+ m_availableBuffers.fetchAndAddRelease(1);
+ return 0;
+ }
+
+ if (res != SL_RESULT_SUCCESS) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ return -1;
+ }
+
+ m_processedBytes += len;
+ setState(QAudio::ActiveState);
+ setError(QAudio::NoError);
+ m_nextBuffer = (m_nextBuffer + 1) % BufferCount;
+
+ return len;
+}
+
+inline void QAndroidAudioSink::setState(QAudio::State state)
+{
+ if (m_state == state)
+ return;
+
+ m_state = state;
+ Q_EMIT stateChanged(m_state);
+}
+
+inline void QAndroidAudioSink::setError(QAudio::Error error)
+{
+ if (m_error == error)
+ return;
+
+ m_error = error;
+ Q_EMIT errorChanged(m_error);
+}
+
+inline SLmillibel QAndroidAudioSink::adjustVolume(qreal vol)
+{
+ if (qFuzzyIsNull(vol))
+ return SL_MILLIBEL_MIN;
+
+ if (qFuzzyCompare(vol, qreal(1.0)))
+ return 0;
+
+ return QAudio::convertVolume(vol, QAudio::LinearVolumeScale, QAudio::DecibelVolumeScale) * 100;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/android/qandroidaudiosink_p.h b/src/multimedia/android/qandroidaudiosink_p.h
new file mode 100644
index 000000000..4cb63b252
--- /dev/null
+++ b/src/multimedia/android/qandroidaudiosink_p.h
@@ -0,0 +1,127 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QOPENSLESAUDIOOUTPUT_H
+#define QOPENSLESAUDIOOUTPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qaudiosystem_p.h>
+#include <SLES/OpenSLES.h>
+#include <qbytearray.h>
+#include <qmap.h>
+#include <QElapsedTimer>
+#include <QIODevice>
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidAudioSink : public QPlatformAudioSink
+{
+ Q_OBJECT
+
+public:
+ QAndroidAudioSink(const QByteArray &device, QObject *parent);
+ ~QAndroidAudioSink();
+
+ void start(QIODevice *device) override;
+ QIODevice *start() override;
+ void stop() override;
+ void reset() override;
+ void suspend() override;
+ void resume() override;
+ qsizetype bytesFree() const override;
+ void setBufferSize(qsizetype value) override;
+ qsizetype bufferSize() const override;
+ qint64 processedUSecs() const override;
+ QAudio::Error error() const override;
+ QAudio::State state() const override;
+ void setFormat(const QAudioFormat &format) override;
+ QAudioFormat format() const override;
+
+ void setVolume(qreal volume) override;
+ qreal volume() const override;
+
+private:
+ friend class SLIODevicePrivate;
+
+ Q_INVOKABLE void onEOSEvent();
+ Q_INVOKABLE void onBytesProcessed(qint64 bytes);
+ Q_INVOKABLE void bufferAvailable();
+
+ static void playCallback(SLPlayItf playItf, void *ctx, SLuint32 event);
+ static void bufferQueueCallback(SLBufferQueueItf bufferQueue, void *ctx);
+
+ bool preparePlayer();
+ void destroyPlayer();
+ void stopPlayer();
+ void readyRead();
+ void startPlayer();
+ qint64 writeData(const char *data, qint64 len);
+
+ void setState(QAudio::State state);
+ void setError(QAudio::Error error);
+
+ SLmillibel adjustVolume(qreal vol);
+
+ static constexpr int BufferCount = 2;
+
+ QByteArray m_deviceName;
+ QAudio::State m_state = QAudio::StoppedState;
+ QAudio::State m_suspendedInState = QAudio::SuspendedState;
+ QAudio::Error m_error = QAudio::NoError;
+ SLObjectItf m_outputMixObject = nullptr;
+ SLObjectItf m_playerObject = nullptr;
+ SLPlayItf m_playItf = nullptr;
+ SLVolumeItf m_volumeItf = nullptr;
+ SLBufferQueueItf m_bufferQueueItf = nullptr;
+ QIODevice *m_audioSource = nullptr;
+ char *m_buffers = nullptr;
+ qreal m_volume = 1.0;
+ bool m_pullMode = false;
+ int m_nextBuffer = 0;
+ int m_bufferSize = 0;
+ qint64 m_elapsedTime = 0;
+ qint64 m_processedBytes = 0;
+ bool m_endSound = false;
+ QAtomicInt m_availableBuffers = BufferCount;
+ SLuint32 m_eventMask = SL_PLAYEVENT_HEADATEND;
+ bool m_startRequiresInit = true;
+
+ qint32 m_streamType;
+ QAudioFormat m_format;
+};
+
+class SLIODevicePrivate : public QIODevice
+{
+ Q_OBJECT
+
+public:
+ inline SLIODevicePrivate(QAndroidAudioSink *audio) : m_audioDevice(audio) {}
+ inline ~SLIODevicePrivate() override {}
+
+protected:
+ inline qint64 readData(char *, qint64) override { return 0; }
+ inline qint64 writeData(const char *data, qint64 len) override;
+
+private:
+ QAndroidAudioSink *m_audioDevice;
+};
+
+qint64 SLIODevicePrivate::writeData(const char *data, qint64 len)
+{
+ Q_ASSERT(m_audioDevice);
+ return m_audioDevice->writeData(data, len);
+}
+
+QT_END_NAMESPACE
+
+#endif // QOPENSLESAUDIOOUTPUT_H
diff --git a/src/multimedia/android/qandroidaudiosource.cpp b/src/multimedia/android/qandroidaudiosource.cpp
new file mode 100644
index 000000000..3a7332fd1
--- /dev/null
+++ b/src/multimedia/android/qandroidaudiosource.cpp
@@ -0,0 +1,470 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidaudiosource_p.h"
+
+#include "qopenslesengine_p.h"
+#include <private/qaudiohelpers_p.h>
+#include <qbuffer.h>
+#include <qdebug.h>
+#include <qloggingcategory.h>
+
+#ifdef ANDROID
+#include <SLES/OpenSLES_AndroidConfiguration.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qpermissions.h>
+#endif
+
+static Q_LOGGING_CATEGORY(qLcAndroidAudioSource, "qt.multimedia.android.audiosource")
+
+QT_BEGIN_NAMESPACE
+
+#define NUM_BUFFERS 2
+#define DEFAULT_PERIOD_TIME_MS 50
+#define MINIMUM_PERIOD_TIME_MS 5
+
+#ifdef ANDROID
+static bool hasRecordingPermission()
+{
+ QMicrophonePermission permission;
+
+ const bool permitted = qApp->checkPermission(permission) == Qt::PermissionStatus::Granted;
+ if (!permitted)
+ qCWarning(qLcAndroidAudioSource, "Missing microphone permission!");
+
+ return permitted;
+}
+
+static void bufferQueueCallback(SLAndroidSimpleBufferQueueItf, void *context)
+#else
+static void bufferQueueCallback(SLBufferQueueItf, void *context)
+#endif
+{
+ // Process buffer in main thread
+ QMetaObject::invokeMethod(reinterpret_cast<QAndroidAudioSource*>(context), "processBuffer");
+}
+
+QAndroidAudioSource::QAndroidAudioSource(const QByteArray &device, QObject *parent)
+ : QPlatformAudioSource(parent)
+ , m_device(device)
+ , m_engine(QOpenSLESEngine::instance())
+ , m_recorderObject(0)
+ , m_recorder(0)
+ , m_bufferQueue(0)
+ , m_pullMode(true)
+ , m_processedBytes(0)
+ , m_audioSource(0)
+ , m_bufferIODevice(0)
+ , m_errorState(QAudio::NoError)
+ , m_deviceState(QAudio::StoppedState)
+ , m_lastNotifyTime(0)
+ , m_volume(1.0)
+ , m_bufferSize(0)
+ , m_buffers(new QByteArray[NUM_BUFFERS])
+ , m_currentBuffer(0)
+{
+#ifdef ANDROID
+ if (qstrcmp(device, QT_ANDROID_PRESET_CAMCORDER) == 0)
+ m_recorderPreset = SL_ANDROID_RECORDING_PRESET_CAMCORDER;
+ else if (qstrcmp(device, QT_ANDROID_PRESET_VOICE_RECOGNITION) == 0)
+ m_recorderPreset = SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION;
+ else if (qstrcmp(device, QT_ANDROID_PRESET_VOICE_COMMUNICATION) == 0)
+ m_recorderPreset = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
+ else
+ m_recorderPreset = SL_ANDROID_RECORDING_PRESET_GENERIC;
+#endif
+}
+
+QAndroidAudioSource::~QAndroidAudioSource()
+{
+ if (m_recorderObject)
+ (*m_recorderObject)->Destroy(m_recorderObject);
+ delete[] m_buffers;
+}
+
+QAudio::Error QAndroidAudioSource::error() const
+{
+ return m_errorState;
+}
+
+QAudio::State QAndroidAudioSource::state() const
+{
+ return m_deviceState;
+}
+
+void QAndroidAudioSource::setFormat(const QAudioFormat &format)
+{
+ if (m_deviceState == QAudio::StoppedState)
+ m_format = format;
+}
+
+QAudioFormat QAndroidAudioSource::format() const
+{
+ return m_format;
+}
+
+void QAndroidAudioSource::start(QIODevice *device)
+{
+ if (m_deviceState != QAudio::StoppedState)
+ stopRecording();
+
+ if (!m_pullMode && m_bufferIODevice) {
+ m_bufferIODevice->close();
+ delete m_bufferIODevice;
+ m_bufferIODevice = 0;
+ }
+
+ m_pullMode = true;
+ m_audioSource = device;
+
+ if (startRecording()) {
+ m_deviceState = QAudio::ActiveState;
+ } else {
+ m_deviceState = QAudio::StoppedState;
+ Q_EMIT errorChanged(m_errorState);
+ }
+
+ Q_EMIT stateChanged(m_deviceState);
+}
+
+QIODevice *QAndroidAudioSource::start()
+{
+ if (m_deviceState != QAudio::StoppedState)
+ stopRecording();
+
+ m_audioSource = 0;
+
+ if (!m_pullMode && m_bufferIODevice) {
+ m_bufferIODevice->close();
+ delete m_bufferIODevice;
+ }
+
+ m_pullMode = false;
+ m_pushBuffer.clear();
+ m_bufferIODevice = new QBuffer(&m_pushBuffer, this);
+ m_bufferIODevice->open(QIODevice::ReadOnly);
+
+ if (startRecording()) {
+ m_deviceState = QAudio::IdleState;
+ } else {
+ m_deviceState = QAudio::StoppedState;
+ Q_EMIT errorChanged(m_errorState);
+ m_bufferIODevice->close();
+ delete m_bufferIODevice;
+ m_bufferIODevice = 0;
+ }
+
+ Q_EMIT stateChanged(m_deviceState);
+ return m_bufferIODevice;
+}
+
+bool QAndroidAudioSource::startRecording()
+{
+ if (!hasRecordingPermission())
+ return false;
+
+ m_processedBytes = 0;
+ m_lastNotifyTime = 0;
+
+ SLresult result;
+
+ // configure audio source
+ SLDataLocator_IODevice loc_dev = { SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT,
+ SL_DEFAULTDEVICEID_AUDIOINPUT, NULL };
+ SLDataSource audioSrc = { &loc_dev, NULL };
+
+ // configure audio sink
+#ifdef ANDROID
+ SLDataLocator_AndroidSimpleBufferQueue loc_bq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,
+ NUM_BUFFERS };
+#else
+ SLDataLocator_BufferQueue loc_bq = { SL_DATALOCATOR_BUFFERQUEUE, NUM_BUFFERS };
+#endif
+
+ SLAndroidDataFormat_PCM_EX format_pcm = QOpenSLESEngine::audioFormatToSLFormatPCM(m_format);
+ SLDataSink audioSnk = { &loc_bq, &format_pcm };
+
+ // create audio recorder
+ // (requires the RECORD_AUDIO permission)
+#ifdef ANDROID
+ const SLInterfaceID id[2] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_ANDROIDCONFIGURATION };
+ const SLboolean req[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
+#else
+ const SLInterfaceID id[1] = { SL_IID_BUFFERQUEUE };
+ const SLboolean req[1] = { SL_BOOLEAN_TRUE };
+#endif
+
+ result = (*m_engine->slEngine())->CreateAudioRecorder(m_engine->slEngine(), &m_recorderObject,
+ &audioSrc, &audioSnk,
+ sizeof(req) / sizeof(SLboolean), id, req);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::OpenError;
+ return false;
+ }
+
+#ifdef ANDROID
+ // configure recorder source
+ SLAndroidConfigurationItf configItf;
+ result = (*m_recorderObject)->GetInterface(m_recorderObject, SL_IID_ANDROIDCONFIGURATION,
+ &configItf);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::OpenError;
+ return false;
+ }
+
+ result = (*configItf)->SetConfiguration(configItf, SL_ANDROID_KEY_RECORDING_PRESET,
+ &m_recorderPreset, sizeof(SLuint32));
+
+ SLuint32 presetValue = SL_ANDROID_RECORDING_PRESET_NONE;
+ SLuint32 presetSize = 2*sizeof(SLuint32); // intentionally too big
+ result = (*configItf)->GetConfiguration(configItf, SL_ANDROID_KEY_RECORDING_PRESET,
+ &presetSize, (void*)&presetValue);
+
+ if (result != SL_RESULT_SUCCESS || presetValue == SL_ANDROID_RECORDING_PRESET_NONE) {
+ m_errorState = QAudio::OpenError;
+ return false;
+ }
+#endif
+
+ // realize the audio recorder
+ result = (*m_recorderObject)->Realize(m_recorderObject, SL_BOOLEAN_FALSE);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::OpenError;
+ return false;
+ }
+
+ // get the record interface
+ result = (*m_recorderObject)->GetInterface(m_recorderObject, SL_IID_RECORD, &m_recorder);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::FatalError;
+ return false;
+ }
+
+ // get the buffer queue interface
+#ifdef ANDROID
+ SLInterfaceID bufferqueueItfID = SL_IID_ANDROIDSIMPLEBUFFERQUEUE;
+#else
+ SLInterfaceID bufferqueueItfID = SL_IID_BUFFERQUEUE;
+#endif
+ result = (*m_recorderObject)->GetInterface(m_recorderObject, bufferqueueItfID, &m_bufferQueue);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::FatalError;
+ return false;
+ }
+
+ // register callback on the buffer queue
+ result = (*m_bufferQueue)->RegisterCallback(m_bufferQueue, bufferQueueCallback, this);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::FatalError;
+ return false;
+ }
+
+ if (m_bufferSize <= 0) {
+ m_bufferSize = m_format.bytesForDuration(DEFAULT_PERIOD_TIME_MS * 1000);
+ } else {
+ int minimumBufSize = m_format.bytesForDuration(MINIMUM_PERIOD_TIME_MS * 1000);
+ if (m_bufferSize < minimumBufSize)
+ m_bufferSize = minimumBufSize;
+ }
+
+ // enqueue empty buffers to be filled by the recorder
+ for (int i = 0; i < NUM_BUFFERS; ++i) {
+ m_buffers[i].resize(m_bufferSize);
+
+ result = (*m_bufferQueue)->Enqueue(m_bufferQueue, m_buffers[i].data(), m_bufferSize);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::FatalError;
+ return false;
+ }
+ }
+
+ // start recording
+ result = (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_RECORDING);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::FatalError;
+ return false;
+ }
+
+ m_errorState = QAudio::NoError;
+
+ return true;
+}
+
+void QAndroidAudioSource::stop()
+{
+ if (m_deviceState == QAudio::StoppedState)
+ return;
+
+ m_deviceState = QAudio::StoppedState;
+
+ stopRecording();
+
+ m_errorState = QAudio::NoError;
+ Q_EMIT stateChanged(m_deviceState);
+}
+
+void QAndroidAudioSource::stopRecording()
+{
+ flushBuffers();
+
+ (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_STOPPED);
+ (*m_bufferQueue)->Clear(m_bufferQueue);
+
+ (*m_recorderObject)->Destroy(m_recorderObject);
+ m_recorderObject = 0;
+
+ for (int i = 0; i < NUM_BUFFERS; ++i)
+ m_buffers[i].clear();
+ m_currentBuffer = 0;
+
+ if (!m_pullMode && m_bufferIODevice) {
+ m_bufferIODevice->close();
+ delete m_bufferIODevice;
+ m_bufferIODevice = 0;
+ m_pushBuffer.clear();
+ }
+}
+
+void QAndroidAudioSource::suspend()
+{
+ if (m_deviceState == QAudio::ActiveState) {
+ m_deviceState = QAudio::SuspendedState;
+ emit stateChanged(m_deviceState);
+
+ (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_PAUSED);
+ }
+}
+
+void QAndroidAudioSource::resume()
+{
+ if (m_deviceState == QAudio::SuspendedState || m_deviceState == QAudio::IdleState) {
+ (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_RECORDING);
+
+ m_deviceState = QAudio::ActiveState;
+ emit stateChanged(m_deviceState);
+ }
+}
+
+void QAndroidAudioSource::processBuffer()
+{
+ if (m_deviceState == QAudio::StoppedState || m_deviceState == QAudio::SuspendedState)
+ return;
+
+ if (m_deviceState != QAudio::ActiveState) {
+ m_errorState = QAudio::NoError;
+ m_deviceState = QAudio::ActiveState;
+ emit stateChanged(m_deviceState);
+ }
+
+ QByteArray *processedBuffer = &m_buffers[m_currentBuffer];
+ writeDataToDevice(processedBuffer->constData(), processedBuffer->size());
+
+ // Make sure that it was not stopped from writeDataToDevice
+ if (m_deviceState == QAudio::StoppedState || m_deviceState == QAudio::SuspendedState)
+ return;
+
+ // Re-enqueue the buffer
+ SLresult result = (*m_bufferQueue)->Enqueue(m_bufferQueue,
+ processedBuffer->data(),
+ processedBuffer->size());
+
+ m_currentBuffer = (m_currentBuffer + 1) % NUM_BUFFERS;
+
+ // If the buffer queue is empty (shouldn't happen), stop recording.
+#ifdef ANDROID
+ SLAndroidSimpleBufferQueueState state;
+#else
+ SLBufferQueueState state;
+#endif
+ result = (*m_bufferQueue)->GetState(m_bufferQueue, &state);
+ if (result != SL_RESULT_SUCCESS || state.count == 0) {
+ stop();
+ m_errorState = QAudio::FatalError;
+ Q_EMIT errorChanged(m_errorState);
+ }
+}
+
+void QAndroidAudioSource::writeDataToDevice(const char *data, int size)
+{
+ m_processedBytes += size;
+
+ QByteArray outData;
+
+ // Apply volume
+ if (m_volume < 1.0f) {
+ outData.resize(size);
+ QAudioHelperInternal::qMultiplySamples(m_volume, m_format, data, outData.data(), size);
+ } else {
+ outData.append(data, size);
+ }
+
+ if (m_pullMode) {
+ // write buffer to the QIODevice
+ if (m_audioSource->write(outData) < 0) {
+ stop();
+ m_errorState = QAudio::IOError;
+ Q_EMIT errorChanged(m_errorState);
+ }
+ } else {
+ // emits readyRead() so user will call read() on QIODevice to get some audio data
+ if (m_bufferIODevice != 0) {
+ m_pushBuffer.append(outData);
+ Q_EMIT m_bufferIODevice->readyRead();
+ }
+ }
+}
+
+void QAndroidAudioSource::flushBuffers()
+{
+ SLmillisecond recorderPos;
+ (*m_recorder)->GetPosition(m_recorder, &recorderPos);
+ qint64 devicePos = processedUSecs();
+
+ qint64 delta = recorderPos * 1000 - devicePos;
+
+ if (delta > 0) {
+ const int writeSize = qMin(m_buffers[m_currentBuffer].size(),
+ m_format.bytesForDuration(delta));
+ writeDataToDevice(m_buffers[m_currentBuffer].constData(), writeSize);
+ }
+}
+
+qsizetype QAndroidAudioSource::bytesReady() const
+{
+ if (m_deviceState == QAudio::ActiveState || m_deviceState == QAudio::SuspendedState)
+ return m_bufferIODevice ? m_bufferIODevice->bytesAvailable() : m_bufferSize;
+
+ return 0;
+}
+
+void QAndroidAudioSource::setBufferSize(qsizetype value)
+{
+ m_bufferSize = value;
+}
+
+qsizetype QAndroidAudioSource::bufferSize() const
+{
+ return m_bufferSize;
+}
+
+qint64 QAndroidAudioSource::processedUSecs() const
+{
+ return m_format.durationForBytes(m_processedBytes);
+}
+
+void QAndroidAudioSource::setVolume(qreal vol)
+{
+ m_volume = vol;
+}
+
+qreal QAndroidAudioSource::volume() const
+{
+ return m_volume;
+}
+
+void QAndroidAudioSource::reset()
+{
+ stop();
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/android/qandroidaudiosource_p.h b/src/multimedia/android/qandroidaudiosource_p.h
new file mode 100644
index 000000000..13578509c
--- /dev/null
+++ b/src/multimedia/android/qandroidaudiosource_p.h
@@ -0,0 +1,101 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QOPENSLESAUDIOINPUT_H
+#define QOPENSLESAUDIOINPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qaudiosystem_p.h>
+#include <QElapsedTimer>
+#include <SLES/OpenSLES.h>
+
+#ifdef ANDROID
+#include <SLES/OpenSLES_Android.h>
+
+#define QT_ANDROID_PRESET_MIC "mic"
+#define QT_ANDROID_PRESET_CAMCORDER "camcorder"
+#define QT_ANDROID_PRESET_VOICE_RECOGNITION "voicerecognition"
+#define QT_ANDROID_PRESET_VOICE_COMMUNICATION "voicecommunication"
+
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class QOpenSLESEngine;
+class QIODevice;
+class QBuffer;
+
+class QAndroidAudioSource : public QPlatformAudioSource
+{
+ Q_OBJECT
+
+public:
+ QAndroidAudioSource(const QByteArray &device, QObject *parent);
+ ~QAndroidAudioSource();
+
+ void start(QIODevice *device);
+ QIODevice *start();
+ void stop();
+ void reset();
+ void suspend();
+ void resume();
+ qsizetype bytesReady() const;
+ void setBufferSize(qsizetype value);
+ qsizetype bufferSize() const;
+ qint64 processedUSecs() const;
+ QAudio::Error error() const;
+ QAudio::State state() const;
+ void setFormat(const QAudioFormat &format);
+ QAudioFormat format() const;
+
+ void setVolume(qreal volume);
+ qreal volume() const;
+
+public Q_SLOTS:
+ void processBuffer();
+
+private:
+ bool startRecording();
+ void stopRecording();
+ void writeDataToDevice(const char *data, int size);
+ void flushBuffers();
+
+ QByteArray m_device;
+ QOpenSLESEngine *m_engine;
+ SLObjectItf m_recorderObject;
+ SLRecordItf m_recorder;
+#ifdef ANDROID
+ SLuint32 m_recorderPreset;
+ SLAndroidSimpleBufferQueueItf m_bufferQueue;
+#else
+ SLBufferQueueItf m_bufferQueue;
+#endif
+
+ bool m_pullMode;
+ qint64 m_processedBytes;
+ QIODevice *m_audioSource;
+ QBuffer *m_bufferIODevice;
+ QByteArray m_pushBuffer;
+ QAudioFormat m_format;
+ QAudio::Error m_errorState;
+ QAudio::State m_deviceState;
+ qint64 m_lastNotifyTime;
+ qreal m_volume;
+ int m_bufferSize;
+ QByteArray *m_buffers;
+ int m_currentBuffer;
+};
+
+QT_END_NAMESPACE
+
+#endif // QOPENSLESAUDIOINPUT_H
diff --git a/src/multimedia/android/qandroidmediadevices.cpp b/src/multimedia/android/qandroidmediadevices.cpp
new file mode 100644
index 000000000..7688da079
--- /dev/null
+++ b/src/multimedia/android/qandroidmediadevices.cpp
@@ -0,0 +1,113 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidmediadevices_p.h"
+#include "qmediadevices.h"
+#include "private/qcameradevice_p.h"
+
+#include "qandroidaudiosource_p.h"
+#include "qandroidaudiosink_p.h"
+#include "qandroidaudiodevice_p.h"
+#include "qopenslesengine_p.h"
+#include "private/qplatformmediaintegration_p.h"
+
+#include <qjnienvironment.h>
+#include <QJniObject>
+#include <QCoreApplication>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_JNI_CLASS(QtAudioDeviceManager,
+ "org/qtproject/qt/android/multimedia/QtAudioDeviceManager");
+
+
+QAndroidMediaDevices::QAndroidMediaDevices() : QPlatformMediaDevices()
+{
+ QtJniTypes::QtAudioDeviceManager::callStaticMethod<void>("registerAudioHeadsetStateReceiver");
+}
+
+QAndroidMediaDevices::~QAndroidMediaDevices()
+{
+ // Object of QAndroidMediaDevices type is static. Unregistering will happend only when closing
+ // the application. In such case it is probably not needed, but let's leave it for
+ // compatibility with Android documentation
+ QtJniTypes::QtAudioDeviceManager::callStaticMethod<void>("unregisterAudioHeadsetStateReceiver");
+}
+
+QList<QAudioDevice> QAndroidMediaDevices::audioInputs() const
+{
+ return QOpenSLESEngine::availableDevices(QAudioDevice::Input);
+}
+
+QList<QAudioDevice> QAndroidMediaDevices::audioOutputs() const
+{
+ return QOpenSLESEngine::availableDevices(QAudioDevice::Output);
+}
+
+QPlatformAudioSource *QAndroidMediaDevices::createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ return new QAndroidAudioSource(deviceInfo.id(), parent);
+}
+
+QPlatformAudioSink *QAndroidMediaDevices::createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ return new QAndroidAudioSink(deviceInfo.id(), parent);
+}
+
+void QAndroidMediaDevices::forwardAudioOutputsChanged()
+{
+ emit audioOutputsChanged();
+}
+
+void QAndroidMediaDevices::forwardAudioInputsChanged()
+{
+ emit audioInputsChanged();
+}
+
+static void onAudioInputDevicesUpdated(JNIEnv */*env*/, jobject /*thiz*/)
+{
+ static_cast<QAndroidMediaDevices*>(QPlatformMediaIntegration::instance()->mediaDevices())->forwardAudioInputsChanged();
+}
+
+static void onAudioOutputDevicesUpdated(JNIEnv */*env*/, jobject /*thiz*/)
+{
+ static_cast<QAndroidMediaDevices*>(QPlatformMediaIntegration::instance()->mediaDevices())->forwardAudioOutputsChanged();
+}
+
+Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
+{
+ static bool initialized = false;
+ if (initialized)
+ return JNI_VERSION_1_6;
+ initialized = true;
+
+ QT_USE_NAMESPACE
+ typedef union {
+ JNIEnv *nativeEnvironment;
+ void *venv;
+ } UnionJNIEnvToVoid;
+
+ UnionJNIEnvToVoid uenv;
+ uenv.venv = NULL;
+
+ if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_6) != JNI_OK)
+ return JNI_ERR;
+
+ const JNINativeMethod methods[] = {
+ { "onAudioInputDevicesUpdated", "()V", (void *)onAudioInputDevicesUpdated },
+ { "onAudioOutputDevicesUpdated", "()V", (void *)onAudioOutputDevicesUpdated }
+ };
+
+ bool registered = QJniEnvironment().registerNativeMethods(
+ "org/qtproject/qt/android/multimedia/QtAudioDeviceManager", methods,
+ std::size(methods));
+
+ if (!registered)
+ return JNI_ERR;
+
+ return JNI_VERSION_1_6;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/android/qandroidmediadevices_p.h b/src/multimedia/android/qandroidmediadevices_p.h
new file mode 100644
index 000000000..a77ed0451
--- /dev/null
+++ b/src/multimedia/android/qandroidmediadevices_p.h
@@ -0,0 +1,42 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDMEDIADEVICES_H
+#define QANDROIDMEDIADEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediadevices_p.h>
+#include <qaudio.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidMediaDevices : public QPlatformMediaDevices
+{
+public:
+ QAndroidMediaDevices();
+
+ ~QAndroidMediaDevices();
+ QList<QAudioDevice> audioInputs() const override;
+ QList<QAudioDevice> audioOutputs() const override;
+ QPlatformAudioSource *createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+ QPlatformAudioSink *createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+
+ void forwardAudioOutputsChanged();
+ void forwardAudioInputsChanged();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/android/qopenslesengine.cpp b/src/multimedia/android/qopenslesengine.cpp
new file mode 100644
index 000000000..738161ab7
--- /dev/null
+++ b/src/multimedia/android/qopenslesengine.cpp
@@ -0,0 +1,378 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qopenslesengine_p.h"
+
+#include "qandroidaudiosource_p.h"
+#include "qandroidaudiodevice_p.h"
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qjniobject.h>
+#include <QtCore/qpermissions.h>
+#include <QtCore/private/qandroidextras_p.h>
+#include <qdebug.h>
+
+#define MINIMUM_PERIOD_TIME_MS 5
+#define DEFAULT_PERIOD_TIME_MS 50
+
+#define CheckError(message) if (result != SL_RESULT_SUCCESS) { qWarning(message); return; }
+
+#define SL_ANDROID_PCM_REPRESENTATION_INVALID 0
+
+Q_GLOBAL_STATIC(QOpenSLESEngine, openslesEngine);
+
+QOpenSLESEngine::QOpenSLESEngine()
+ : m_engineObject(0)
+ , m_engine(0)
+ , m_checkedInputFormats(false)
+{
+ SLresult result;
+
+ result = slCreateEngine(&m_engineObject, 0, 0, 0, 0, 0);
+ CheckError("Failed to create engine");
+
+ result = (*m_engineObject)->Realize(m_engineObject, SL_BOOLEAN_FALSE);
+ CheckError("Failed to realize engine");
+
+ result = (*m_engineObject)->GetInterface(m_engineObject, SL_IID_ENGINE, &m_engine);
+ CheckError("Failed to get engine interface");
+}
+
+QOpenSLESEngine::~QOpenSLESEngine()
+{
+ if (m_engineObject)
+ (*m_engineObject)->Destroy(m_engineObject);
+}
+
+QOpenSLESEngine *QOpenSLESEngine::instance()
+{
+ return openslesEngine();
+}
+
+static SLuint32 getChannelMask(unsigned channelCount)
+{
+ switch (channelCount) {
+ case 1: return SL_SPEAKER_FRONT_CENTER;
+ case 2: return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
+ case 3: return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | SL_SPEAKER_FRONT_CENTER;
+ case 4: return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT
+ | SL_SPEAKER_BACK_LEFT | SL_SPEAKER_BACK_RIGHT;
+ case 5: return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | SL_SPEAKER_BACK_LEFT
+ | SL_SPEAKER_BACK_RIGHT | SL_SPEAKER_FRONT_CENTER;
+ case 6: return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | SL_SPEAKER_BACK_LEFT
+ | SL_SPEAKER_BACK_RIGHT | SL_SPEAKER_FRONT_CENTER | SL_SPEAKER_LOW_FREQUENCY;
+ default: return 0; // Default to 0 for an unsupported or unknown number of channels
+ }
+}
+
+SLAndroidDataFormat_PCM_EX QOpenSLESEngine::audioFormatToSLFormatPCM(const QAudioFormat &format)
+{
+ SLAndroidDataFormat_PCM_EX format_pcm;
+ format_pcm.formatType = SL_ANDROID_DATAFORMAT_PCM_EX;
+ format_pcm.numChannels = format.channelCount();
+ format_pcm.sampleRate = format.sampleRate() * 1000;
+ format_pcm.bitsPerSample = format.bytesPerSample() * 8;
+ format_pcm.containerSize = format.bytesPerSample() * 8;
+ format_pcm.channelMask = getChannelMask(format_pcm.numChannels);
+ format_pcm.endianness = (QSysInfo::ByteOrder == QSysInfo::LittleEndian ?
+ SL_BYTEORDER_LITTLEENDIAN :
+ SL_BYTEORDER_BIGENDIAN);
+
+ switch (format.sampleFormat()) {
+ case QAudioFormat::SampleFormat::UInt8:
+ format_pcm.representation = SL_ANDROID_PCM_REPRESENTATION_UNSIGNED_INT;
+ break;
+ case QAudioFormat::SampleFormat::Int16:
+ case QAudioFormat::SampleFormat::Int32:
+ format_pcm.representation = SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT;
+ break;
+ case QAudioFormat::SampleFormat::Float:
+ format_pcm.representation = SL_ANDROID_PCM_REPRESENTATION_FLOAT;
+ break;
+ case QAudioFormat::SampleFormat::NSampleFormats:
+ case QAudioFormat::SampleFormat::Unknown:
+ format_pcm.representation = SL_ANDROID_PCM_REPRESENTATION_INVALID;
+ break;
+ }
+
+ return format_pcm;
+}
+
+QList<QAudioDevice> QOpenSLESEngine::availableDevices(QAudioDevice::Mode mode)
+{
+ QList<QAudioDevice> devices;
+ QJniObject devs;
+ if (mode == QAudioDevice::Input) {
+ devs = QJniObject::callStaticObjectMethod(
+ "org/qtproject/qt/android/multimedia/QtAudioDeviceManager",
+ "getAudioInputDevices",
+ "()[Ljava/lang/String;");
+ } else if (mode == QAudioDevice::Output) {
+ devs = QJniObject::callStaticObjectMethod(
+ "org/qtproject/qt/android/multimedia/QtAudioDeviceManager",
+ "getAudioOutputDevices",
+ "()[Ljava/lang/String;");
+ }
+ if (devs.isValid()) {
+ QJniEnvironment env;
+ jobjectArray devsArray = static_cast<jobjectArray>(devs.object());
+ const jint size = env->GetArrayLength(devsArray);
+ for (int i = 0; i < size; ++i) {
+ QString val = QJniObject(env->GetObjectArrayElement(devsArray, i)).toString();
+ int pos = val.indexOf(QStringLiteral(":"));
+ devices << (new QOpenSLESDeviceInfo(
+ val.left(pos).toUtf8(), val.mid(pos+1), mode))->create();
+ }
+ }
+ return devices;
+}
+
+bool QOpenSLESEngine::setAudioOutput(const QByteArray &deviceId)
+{
+ return QJniObject::callStaticMethod<jboolean>(
+ "org/qtproject/qt/android/multimedia/QtAudioDeviceManager",
+ "setAudioOutput",
+ deviceId.toInt());
+}
+
+static bool hasRecordPermission()
+{
+ return qApp->checkPermission(QMicrophonePermission{}) == Qt::PermissionStatus::Granted;
+}
+
+QList<int> QOpenSLESEngine::supportedChannelCounts(QAudioDevice::Mode mode) const
+{
+ if (mode == QAudioDevice::Input) {
+ if (!m_checkedInputFormats)
+ const_cast<QOpenSLESEngine *>(this)->checkSupportedInputFormats();
+ return m_supportedInputChannelCounts;
+ } else {
+ return QList<int>() << 1 << 2;
+ }
+}
+
+QList<int> QOpenSLESEngine::supportedSampleRates(QAudioDevice::Mode mode) const
+{
+ if (mode == QAudioDevice::Input) {
+ if (!m_checkedInputFormats)
+ const_cast<QOpenSLESEngine *>(this)->checkSupportedInputFormats();
+ return m_supportedInputSampleRates;
+ } else {
+ return QList<int>() << 8000 << 11025 << 12000 << 16000 << 22050 << 24000
+ << 32000 << 44100 << 48000 << 64000 << 88200 << 96000 << 192000;
+ }
+}
+
+int QOpenSLESEngine::getOutputValue(QOpenSLESEngine::OutputValue type, int defaultValue)
+{
+ static int sampleRate = 0;
+ static int framesPerBuffer = 0;
+
+ if (type == FramesPerBuffer && framesPerBuffer != 0)
+ return framesPerBuffer;
+
+ if (type == SampleRate && sampleRate != 0)
+ return sampleRate;
+
+ QJniObject ctx(QNativeInterface::QAndroidApplication::context());
+ if (!ctx.isValid())
+ return defaultValue;
+
+
+ QJniObject audioServiceString = ctx.getStaticObjectField("android/content/Context",
+ "AUDIO_SERVICE",
+ "Ljava/lang/String;");
+ QJniObject am = ctx.callObjectMethod("getSystemService",
+ "(Ljava/lang/String;)Ljava/lang/Object;",
+ audioServiceString.object());
+ if (!am.isValid())
+ return defaultValue;
+
+ auto sampleRateField = QJniObject::getStaticObjectField("android/media/AudioManager",
+ "PROPERTY_OUTPUT_SAMPLE_RATE",
+ "Ljava/lang/String;");
+ auto framesPerBufferField = QJniObject::getStaticObjectField(
+ "android/media/AudioManager",
+ "PROPERTY_OUTPUT_FRAMES_PER_BUFFER",
+ "Ljava/lang/String;");
+
+ auto sampleRateString = am.callObjectMethod("getProperty",
+ "(Ljava/lang/String;)Ljava/lang/String;",
+ sampleRateField.object());
+ auto framesPerBufferString = am.callObjectMethod("getProperty",
+ "(Ljava/lang/String;)Ljava/lang/String;",
+ framesPerBufferField.object());
+
+ if (!sampleRateString.isValid() || !framesPerBufferString.isValid())
+ return defaultValue;
+
+ framesPerBuffer = framesPerBufferString.toString().toInt();
+ sampleRate = sampleRateString.toString().toInt();
+
+ if (type == FramesPerBuffer)
+ return framesPerBuffer;
+
+ if (type == SampleRate)
+ return sampleRate;
+
+ return defaultValue;
+}
+
+int QOpenSLESEngine::getDefaultBufferSize(const QAudioFormat &format)
+{
+ if (!format.isValid())
+ return 0;
+
+ const int channelConfig = [&format]() -> int
+ {
+ if (format.channelCount() == 1)
+ return 4; /* MONO */
+ else if (format.channelCount() == 2)
+ return 12; /* STEREO */
+ else if (format.channelCount() > 2)
+ return 1052; /* SURROUND */
+ else
+ return 1; /* DEFAULT */
+ }();
+
+ const int audioFormat = [&format]() -> int
+ {
+ const int sdkVersion = QNativeInterface::QAndroidApplication::sdkVersion();
+ if (format.sampleFormat() == QAudioFormat::Float && sdkVersion >= 21)
+ return 4; /* PCM_FLOAT */
+ else if (format.sampleFormat() == QAudioFormat::UInt8)
+ return 3; /* PCM_8BIT */
+ else if (format.sampleFormat() == QAudioFormat::Int16)
+ return 2; /* PCM_16BIT*/
+ else
+ return 1; /* DEFAULT */
+ }();
+
+ const int sampleRate = format.sampleRate();
+ const int minBufferSize = QJniObject::callStaticMethod<jint>("android/media/AudioTrack",
+ "getMinBufferSize",
+ "(III)I",
+ sampleRate,
+ channelConfig,
+ audioFormat);
+ return minBufferSize > 0 ? minBufferSize : format.bytesForDuration(DEFAULT_PERIOD_TIME_MS);
+}
+
+int QOpenSLESEngine::getLowLatencyBufferSize(const QAudioFormat &format)
+{
+ return format.bytesForFrames(QOpenSLESEngine::getOutputValue(QOpenSLESEngine::FramesPerBuffer,
+ format.framesForDuration(MINIMUM_PERIOD_TIME_MS)));
+}
+
+bool QOpenSLESEngine::supportsLowLatency()
+{
+ static int isSupported = -1;
+
+ if (isSupported != -1)
+ return (isSupported == 1);
+
+ QJniObject ctx(QNativeInterface::QAndroidApplication::context());
+ if (!ctx.isValid())
+ return false;
+
+ QJniObject pm = ctx.callObjectMethod("getPackageManager", "()Landroid/content/pm/PackageManager;");
+ if (!pm.isValid())
+ return false;
+
+ QJniObject audioFeatureField = QJniObject::getStaticObjectField(
+ "android/content/pm/PackageManager",
+ "FEATURE_AUDIO_LOW_LATENCY",
+ "Ljava/lang/String;");
+ if (!audioFeatureField.isValid())
+ return false;
+
+ isSupported = pm.callMethod<jboolean>("hasSystemFeature",
+ "(Ljava/lang/String;)Z",
+ audioFeatureField.object());
+ return (isSupported == 1);
+}
+
+bool QOpenSLESEngine::printDebugInfo()
+{
+ return qEnvironmentVariableIsSet("QT_OPENSL_INFO");
+}
+
+void QOpenSLESEngine::checkSupportedInputFormats()
+{
+ m_supportedInputChannelCounts = QList<int>() << 1;
+ m_supportedInputSampleRates.clear();
+
+ SLAndroidDataFormat_PCM_EX defaultFormat;
+ defaultFormat.formatType = SL_DATAFORMAT_PCM;
+ defaultFormat.numChannels = 1;
+ defaultFormat.sampleRate = SL_SAMPLINGRATE_44_1;
+ defaultFormat.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_32;
+ defaultFormat.containerSize = SL_PCMSAMPLEFORMAT_FIXED_32;
+ defaultFormat.channelMask = SL_ANDROID_MAKE_INDEXED_CHANNEL_MASK(SL_SPEAKER_FRONT_CENTER);
+ defaultFormat.endianness = SL_BYTEORDER_LITTLEENDIAN;
+ defaultFormat.representation = SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT;
+
+ const SLuint32 rates[13] = { SL_SAMPLINGRATE_8,
+ SL_SAMPLINGRATE_11_025,
+ SL_SAMPLINGRATE_12,
+ SL_SAMPLINGRATE_16,
+ SL_SAMPLINGRATE_22_05,
+ SL_SAMPLINGRATE_24,
+ SL_SAMPLINGRATE_32,
+ SL_SAMPLINGRATE_44_1,
+ SL_SAMPLINGRATE_48,
+ SL_SAMPLINGRATE_64,
+ SL_SAMPLINGRATE_88_2,
+ SL_SAMPLINGRATE_96,
+ SL_SAMPLINGRATE_192 };
+
+
+ // Test sampling rates
+ for (size_t i = 0 ; i < std::size(rates); ++i) {
+ SLAndroidDataFormat_PCM_EX format = defaultFormat;
+ format.sampleRate = rates[i];
+
+ if (inputFormatIsSupported(format))
+ m_supportedInputSampleRates.append(rates[i] / 1000);
+
+ }
+
+ // Test if stereo is supported
+ {
+ SLAndroidDataFormat_PCM_EX format = defaultFormat;
+ format.numChannels = 2;
+ format.channelMask = SL_ANDROID_MAKE_INDEXED_CHANNEL_MASK(SL_SPEAKER_FRONT_LEFT
+ | SL_SPEAKER_FRONT_RIGHT);
+ if (inputFormatIsSupported(format))
+ m_supportedInputChannelCounts.append(2);
+ }
+
+ m_checkedInputFormats = true;
+}
+
+bool QOpenSLESEngine::inputFormatIsSupported(SLAndroidDataFormat_PCM_EX format)
+{
+ SLresult result;
+ SLObjectItf recorder = 0;
+ SLDataLocator_IODevice loc_dev = { SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT,
+ SL_DEFAULTDEVICEID_AUDIOINPUT, NULL };
+ SLDataSource audioSrc = { &loc_dev, NULL };
+
+ SLDataLocator_AndroidSimpleBufferQueue loc_bq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 1 };
+ SLDataSink audioSnk = { &loc_bq, &format };
+
+ // only ask permission when it is about to create the audiorecorder
+ if (!hasRecordPermission())
+ return false;
+
+ result = (*m_engine)->CreateAudioRecorder(m_engine, &recorder, &audioSrc, &audioSnk, 0, 0, 0);
+ if (result == SL_RESULT_SUCCESS)
+ result = (*recorder)->Realize(recorder, false);
+
+ if (result == SL_RESULT_SUCCESS) {
+ (*recorder)->Destroy(recorder);
+ return true;
+ }
+
+ return false;
+}
diff --git a/src/multimedia/android/qopenslesengine_p.h b/src/multimedia/android/qopenslesengine_p.h
new file mode 100644
index 000000000..9918ac888
--- /dev/null
+++ b/src/multimedia/android/qopenslesengine_p.h
@@ -0,0 +1,65 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QOPENSLESENGINE_H
+#define QOPENSLESENGINE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qglobal.h>
+#include <qaudio.h>
+#include <qlist.h>
+#include <qaudioformat.h>
+#include <qaudiodevice.h>
+#include <SLES/OpenSLES_Android.h>
+
+QT_BEGIN_NAMESPACE
+
+class QOpenSLESEngine
+{
+public:
+ enum OutputValue { FramesPerBuffer, SampleRate };
+
+ QOpenSLESEngine();
+ ~QOpenSLESEngine();
+
+ static QOpenSLESEngine *instance();
+
+ SLEngineItf slEngine() const { return m_engine; }
+
+ static SLAndroidDataFormat_PCM_EX audioFormatToSLFormatPCM(const QAudioFormat &format);
+
+ static QList<QAudioDevice> availableDevices(QAudioDevice::Mode mode);
+ static bool setAudioOutput(const QByteArray &deviceId);
+ QList<int> supportedChannelCounts(QAudioDevice::Mode mode) const;
+ QList<int> supportedSampleRates(QAudioDevice::Mode mode) const;
+
+ static int getOutputValue(OutputValue type, int defaultValue = 0);
+ static int getDefaultBufferSize(const QAudioFormat &format);
+ static int getLowLatencyBufferSize(const QAudioFormat &format);
+ static bool supportsLowLatency();
+ static bool printDebugInfo();
+
+private:
+ void checkSupportedInputFormats();
+ bool inputFormatIsSupported(SLAndroidDataFormat_PCM_EX format);
+ SLObjectItf m_engineObject;
+ SLEngineItf m_engine;
+
+ QList<int> m_supportedInputChannelCounts;
+ QList<int> m_supportedInputSampleRates;
+ bool m_checkedInputFormats;
+};
+
+QT_END_NAMESPACE
+
+#endif // QOPENSLESENGINE_H
diff --git a/src/multimedia/audio/audio.pri b/src/multimedia/audio/audio.pri
deleted file mode 100644
index 388124205..000000000
--- a/src/multimedia/audio/audio.pri
+++ /dev/null
@@ -1,50 +0,0 @@
-INCLUDEPATH += audio
-
-PUBLIC_HEADERS += \
- audio/qaudio.h \
- audio/qaudiobuffer.h \
- audio/qaudioformat.h \
- audio/qaudioinput.h \
- audio/qaudiooutput.h \
- audio/qaudiodeviceinfo.h \
- audio/qaudiosystemplugin.h \
- audio/qaudiosystem.h \
- audio/qsoundeffect.h \
- audio/qsound.h \
- audio/qaudioprobe.h \
- audio/qaudiodecoder.h
-
-PRIVATE_HEADERS += \
- audio/qaudiobuffer_p.h \
- audio/qaudiodevicefactory_p.h \
- audio/qwavedecoder_p.h \
- audio/qsamplecache_p.h \
- audio/qaudiohelpers_p.h \
- audio/qaudiosystempluginext_p.h
-
-SOURCES += \
- audio/qaudio.cpp \
- audio/qaudioformat.cpp \
- audio/qaudiodeviceinfo.cpp \
- audio/qaudiooutput.cpp \
- audio/qaudioinput.cpp \
- audio/qaudiosystemplugin.cpp \
- audio/qaudiosystem.cpp \
- audio/qaudiodevicefactory.cpp \
- audio/qsoundeffect.cpp \
- audio/qwavedecoder_p.cpp \
- audio/qsamplecache_p.cpp \
- audio/qsound.cpp \
- audio/qaudiobuffer.cpp \
- audio/qaudioprobe.cpp \
- audio/qaudiodecoder.cpp \
- audio/qaudiohelpers.cpp
-
-qtConfig(pulseaudio) {
- QMAKE_USE_FOR_PRIVATE += pulseaudio
- PRIVATE_HEADERS += audio/qsoundeffect_pulse_p.h
- SOURCES += audio/qsoundeffect_pulse_p.cpp
-} else {
- PRIVATE_HEADERS += audio/qsoundeffect_qaudio_p.h
- SOURCES += audio/qsoundeffect_qaudio_p.cpp
-}
diff --git a/src/multimedia/audio/qaudio.cpp b/src/multimedia/audio/qaudio.cpp
deleted file mode 100644
index 82613270a..000000000
--- a/src/multimedia/audio/qaudio.cpp
+++ /dev/null
@@ -1,383 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include <qaudio.h>
-#include <qmath.h>
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-#define LOG100 4.60517018599
-
-static void qRegisterAudioMetaTypes()
-{
- qRegisterMetaType<QAudio::Error>();
- qRegisterMetaType<QAudio::State>();
- qRegisterMetaType<QAudio::Mode>();
- qRegisterMetaType<QAudio::Role>();
- qRegisterMetaType<QAudio::VolumeScale>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterAudioMetaTypes)
-
-/*!
- \namespace QAudio
- \ingroup multimedia-namespaces
- \brief The QAudio namespace contains enums used by the audio classes.
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_audio
-*/
-
-/*!
- \enum QAudio::Error
-
- \value NoError No errors have occurred
- \value OpenError An error occurred opening the audio device
- \value IOError An error occurred during read/write of audio device
- \value UnderrunError Audio data is not being fed to the audio device at a fast enough rate
- \value FatalError A non-recoverable error has occurred, the audio device is not usable at this time.
-*/
-
-/*!
- \enum QAudio::State
-
- \value ActiveState Audio data is being processed, this state is set after start() is called
- and while audio data is available to be processed.
- \value SuspendedState The audio stream is in a suspended state. Entered after suspend() is called
- or when another stream takes control of the audio device. In the later case,
- a call to resume will return control of the audio device to this stream. This
- should usually only be done upon user request.
- \value StoppedState The audio device is closed, and is not processing any audio data
- \value IdleState The QIODevice passed in has no data and audio system's buffer is empty, this state
- is set after start() is called and while no audio data is available to be processed.
- \value InterruptedState This stream is in a suspended state because another higher priority stream currently
- has control of the audio device. Playback cannot resume until the higher priority
- stream relinquishes control of the audio device.
-*/
-
-/*!
- \enum QAudio::Mode
-
- \value AudioOutput audio output device
- \value AudioInput audio input device
-*/
-
-/*!
- \enum QAudio::Role
-
- This enum describes the role of an audio stream.
-
- \value UnknownRole The role is unknown or undefined
- \value MusicRole Music
- \value VideoRole Soundtrack from a movie or a video
- \value VoiceCommunicationRole Voice communications, such as telephony
- \value AlarmRole Alarm
- \value NotificationRole Notification, such as an incoming e-mail or a chat request
- \value RingtoneRole Ringtone
- \value AccessibilityRole For accessibility, such as with a screen reader
- \value SonificationRole Sonification, such as with user interface sounds
- \value GameRole Game audio
- \value CustomRole The role is specified by QMediaPlayer::customAudioRole()
-
- \since 5.6
- \sa QMediaPlayer::setAudioRole()
-*/
-
-/*!
- \enum QAudio::VolumeScale
-
- This enum defines the different audio volume scales.
-
- \value LinearVolumeScale Linear scale. \c 0.0 (0%) is silence and \c 1.0 (100%) is full
- volume. All Qt Multimedia classes that have an audio volume use
- a linear scale.
- \value CubicVolumeScale Cubic scale. \c 0.0 (0%) is silence and \c 1.0 (100%) is full
- volume.
- \value LogarithmicVolumeScale Logarithmic Scale. \c 0.0 (0%) is silence and \c 1.0 (100%) is
- full volume. UI volume controls should usually use a logarithmic
- scale.
- \value DecibelVolumeScale Decibel (dB, amplitude) logarithmic scale. \c -200 is silence
- and \c 0 is full volume.
-
- \since 5.8
- \sa QAudio::convertVolume()
-*/
-
-namespace QAudio
-{
-
-/*!
- \fn qreal QAudio::convertVolume(qreal volume, VolumeScale from, VolumeScale to)
-
- Converts an audio \a volume \a from a volume scale \a to another, and returns the result.
-
- Depending on the context, different scales are used to represent audio volume. All Qt Multimedia
- classes that have an audio volume use a linear scale, the reason is that the loudness of a
- speaker is controlled by modulating its voltage on a linear scale. The human ear on the other
- hand, perceives loudness in a logarithmic way. Using a logarithmic scale for volume controls
- is therefore appropriate in most applications. The decibel scale is logarithmic by nature and
- is commonly used to define sound levels, it is usually used for UI volume controls in
- professional audio applications. The cubic scale is a computationally cheap approximation of a
- logarithmic scale, it provides more control over lower volume levels.
-
- The following example shows how to convert the volume value from a slider control before passing
- it to a QMediaPlayer. As a result, the perceived increase in volume is the same when increasing
- the volume slider from 20 to 30 as it is from 50 to 60:
-
- \snippet multimedia-snippets/audio.cpp Volume conversion
-
- \since 5.8
- \sa VolumeScale, QMediaPlayer::setVolume(), QAudioOutput::setVolume(),
- QAudioInput::setVolume(), QSoundEffect::setVolume(), QMediaRecorder::setVolume()
-*/
-qreal convertVolume(qreal volume, VolumeScale from, VolumeScale to)
-{
- switch (from) {
- case LinearVolumeScale:
- volume = qMax(qreal(0), volume);
- switch (to) {
- case LinearVolumeScale:
- return volume;
- case CubicVolumeScale:
- return qPow(volume, qreal(1 / 3.0));
- case LogarithmicVolumeScale:
- return 1 - std::exp(-volume * LOG100);
- case DecibelVolumeScale:
- if (volume < 0.001)
- return qreal(-200);
- else
- return qreal(20.0) * std::log10(volume);
- }
- break;
- case CubicVolumeScale:
- volume = qMax(qreal(0), volume);
- switch (to) {
- case LinearVolumeScale:
- return volume * volume * volume;
- case CubicVolumeScale:
- return volume;
- case LogarithmicVolumeScale:
- return 1 - std::exp(-volume * volume * volume * LOG100);
- case DecibelVolumeScale:
- if (volume < 0.001)
- return qreal(-200);
- else
- return qreal(3.0 * 20.0) * std::log10(volume);
- }
- break;
- case LogarithmicVolumeScale:
- volume = qMax(qreal(0), volume);
- switch (to) {
- case LinearVolumeScale:
- if (volume > 0.99)
- return 1;
- else
- return -std::log(1 - volume) / LOG100;
- case CubicVolumeScale:
- if (volume > 0.99)
- return 1;
- else
- return qPow(-std::log(1 - volume) / LOG100, qreal(1 / 3.0));
- case LogarithmicVolumeScale:
- return volume;
- case DecibelVolumeScale:
- if (volume < 0.001)
- return qreal(-200);
- else if (volume > 0.99)
- return 0;
- else
- return qreal(20.0) * std::log10(-std::log(1 - volume) / LOG100);
- }
- break;
- case DecibelVolumeScale:
- switch (to) {
- case LinearVolumeScale:
- return qPow(qreal(10.0), volume / qreal(20.0));
- case CubicVolumeScale:
- return qPow(qreal(10.0), volume / qreal(3.0 * 20.0));
- case LogarithmicVolumeScale:
- if (qFuzzyIsNull(volume))
- return 1;
- else
- return 1 - std::exp(-qPow(qreal(10.0), volume / qreal(20.0)) * LOG100);
- case DecibelVolumeScale:
- return volume;
- }
- break;
- }
-
- return volume;
-}
-
-}
-
-#ifndef QT_NO_DEBUG_STREAM
-QDebug operator<<(QDebug dbg, QAudio::Error error)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (error) {
- case QAudio::NoError:
- dbg << "NoError";
- break;
- case QAudio::OpenError:
- dbg << "OpenError";
- break;
- case QAudio::IOError:
- dbg << "IOError";
- break;
- case QAudio::UnderrunError:
- dbg << "UnderrunError";
- break;
- case QAudio::FatalError:
- dbg << "FatalError";
- break;
- }
- return dbg;
-}
-
-QDebug operator<<(QDebug dbg, QAudio::State state)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (state) {
- case QAudio::ActiveState:
- dbg << "ActiveState";
- break;
- case QAudio::SuspendedState:
- dbg << "SuspendedState";
- break;
- case QAudio::StoppedState:
- dbg << "StoppedState";
- break;
- case QAudio::IdleState:
- dbg << "IdleState";
- break;
- case QAudio::InterruptedState:
- dbg << "InterruptedState";
- break;
- }
- return dbg;
-}
-
-QDebug operator<<(QDebug dbg, QAudio::Mode mode)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (mode) {
- case QAudio::AudioInput:
- dbg << "AudioInput";
- break;
- case QAudio::AudioOutput:
- dbg << "AudioOutput";
- break;
- }
- return dbg;
-}
-
-QDebug operator<<(QDebug dbg, QAudio::Role role)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (role) {
- case QAudio::UnknownRole:
- dbg << "UnknownRole";
- break;
- case QAudio::AccessibilityRole:
- dbg << "AccessibilityRole";
- break;
- case QAudio::AlarmRole:
- dbg << "AlarmRole";
- break;
- case QAudio::GameRole:
- dbg << "GameRole";
- break;
- case QAudio::MusicRole:
- dbg << "MusicRole";
- break;
- case QAudio::NotificationRole:
- dbg << "NotificationRole";
- break;
- case QAudio::RingtoneRole:
- dbg << "RingtoneRole";
- break;
- case QAudio::SonificationRole:
- dbg << "SonificationRole";
- break;
- case QAudio::VideoRole:
- dbg << "VideoRole";
- break;
- case QAudio::VoiceCommunicationRole:
- dbg << "VoiceCommunicationRole";
- break;
- case QAudio::CustomRole:
- dbg << "CustomRole";
- break;
- }
- return dbg;
-}
-
-QDebug operator<<(QDebug dbg, QAudio::VolumeScale scale)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (scale) {
- case QAudio::LinearVolumeScale:
- dbg << "LinearVolumeScale";
- break;
- case QAudio::CubicVolumeScale:
- dbg << "CubicVolumeScale";
- break;
- case QAudio::LogarithmicVolumeScale:
- dbg << "LogarithmicVolumeScale";
- break;
- case QAudio::DecibelVolumeScale:
- dbg << "DecibelVolumeScale";
- break;
- }
- return dbg;
-}
-
-#endif
-
-
-QT_END_NAMESPACE
-
diff --git a/src/multimedia/audio/qaudio.h b/src/multimedia/audio/qaudio.h
index 90a8c236f..5ae994b9f 100644
--- a/src/multimedia/audio/qaudio.h
+++ b/src/multimedia/audio/qaudio.h
@@ -1,48 +1,14 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QAUDIO_H
#define QAUDIO_H
+#if 0
+#pragma qt_class(QAudio)
+#endif
+
#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
#include <QtCore/qmetatype.h>
@@ -52,25 +18,15 @@ QT_BEGIN_NAMESPACE
// Class forward declaration required for QDoc bug
class QString;
+
+#if defined(Q_QDOC)
+namespace QtAudio
+#else
namespace QAudio
+#endif
{
enum Error { NoError, OpenError, IOError, UnderrunError, FatalError };
- enum State { ActiveState, SuspendedState, StoppedState, IdleState, InterruptedState };
- enum Mode { AudioInput, AudioOutput };
-
- enum Role {
- UnknownRole,
- MusicRole,
- VideoRole,
- VoiceCommunicationRole,
- AlarmRole,
- NotificationRole,
- RingtoneRole,
- AccessibilityRole,
- SonificationRole,
- GameRole,
- CustomRole
- };
+ enum State { ActiveState, SuspendedState, StoppedState, IdleState };
enum VolumeScale {
LinearVolumeScale,
@@ -79,23 +35,19 @@ namespace QAudio
DecibelVolumeScale
};
- Q_MULTIMEDIA_EXPORT qreal convertVolume(qreal volume, VolumeScale from, VolumeScale to);
+ Q_MULTIMEDIA_EXPORT float convertVolume(float volume, VolumeScale from, VolumeScale to);
}
+#if !defined(Q_QDOC)
+namespace QtAudio = QAudio;
+#endif
+
#ifndef QT_NO_DEBUG_STREAM
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QAudio::Error error);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QAudio::State state);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QAudio::Mode mode);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QAudio::Role role);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QAudio::VolumeScale role);
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QtAudio::Error error);
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QtAudio::State state);
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QtAudio::VolumeScale role);
#endif
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QAudio::Error)
-Q_DECLARE_METATYPE(QAudio::State)
-Q_DECLARE_METATYPE(QAudio::Mode)
-Q_DECLARE_METATYPE(QAudio::Role)
-Q_DECLARE_METATYPE(QAudio::VolumeScale)
-
#endif // QAUDIO_H
diff --git a/src/multimedia/audio/qaudiobuffer.cpp b/src/multimedia/audio/qaudiobuffer.cpp
index 999f280b3..69adcc5b7 100644
--- a/src/multimedia/audio/qaudiobuffer.cpp
+++ b/src/multimedia/audio/qaudiobuffer.cpp
@@ -1,185 +1,27 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qaudiobuffer.h"
-#include "qaudiobuffer_p.h"
#include <QObject>
#include <QDebug>
QT_BEGIN_NAMESPACE
-
-static void qRegisterAudioBufferMetaTypes()
-{
- qRegisterMetaType<QAudioBuffer>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterAudioBufferMetaTypes)
-
-
class QAudioBufferPrivate : public QSharedData
{
public:
- QAudioBufferPrivate(QAbstractAudioBuffer *provider)
- : mProvider(provider)
- , mCount(1)
- {
- }
-
- ~QAudioBufferPrivate()
- {
- if (mProvider)
- mProvider->release();
- }
-
- void ref()
- {
- mCount.ref();
- }
-
- void deref()
- {
- if (!mCount.deref())
- delete this;
- }
-
- QAudioBufferPrivate *clone();
-
- static QAudioBufferPrivate *acquire(QAudioBufferPrivate *other)
- {
- if (!other)
- return nullptr;
-
- // Ref the other (if there are extant data() pointers, they will
- // also point here - it's a feature, not a bug, like QByteArray)
- other->ref();
- return other;
- }
-
- QAbstractAudioBuffer *mProvider;
- QAtomicInt mCount;
-};
-
-// Private class to go in .cpp file
-class QMemoryAudioBufferProvider : public QAbstractAudioBuffer {
-public:
- QMemoryAudioBufferProvider(const void *data, int frameCount, const QAudioFormat &format, qint64 startTime)
- : mStartTime(startTime)
- , mFrameCount(frameCount)
- , mFormat(format)
- {
- int numBytes = format.bytesForFrames(frameCount);
- if (numBytes > 0) {
- mBuffer = malloc(numBytes);
- if (!mBuffer) {
- // OOM, if that's likely
- mStartTime = -1;
- mFrameCount = 0;
- mFormat = QAudioFormat();
- } else {
- // Allocated, see if we have data to copy
- if (data) {
- memcpy(mBuffer, data, numBytes);
- } else {
- // We have to fill with the zero value..
- switch (format.sampleType()) {
- case QAudioFormat::SignedInt:
- // Signed int means 0x80, 0x8000 is zero
- // XXX this is not right for > 8 bits(0x8080 vs 0x8000)
- memset(mBuffer, 0x80, numBytes);
- break;
- default:
- memset(mBuffer, 0x0, numBytes);
- }
- }
- }
- } else
- mBuffer = nullptr;
- }
-
- ~QMemoryAudioBufferProvider()
+ QAudioBufferPrivate(const QAudioFormat &f, const QByteArray &d, qint64 start)
+ : format(f), data(d), startTime(start)
{
- if (mBuffer)
- free(mBuffer);
}
- void release() override {delete this;}
- QAudioFormat format() const override {return mFormat;}
- qint64 startTime() const override {return mStartTime;}
- int frameCount() const override {return mFrameCount;}
-
- void *constData() const override {return mBuffer;}
-
- void *writableData() override {return mBuffer;}
- QAbstractAudioBuffer *clone() const override
- {
- return new QMemoryAudioBufferProvider(mBuffer, mFrameCount, mFormat, mStartTime);
- }
-
- void *mBuffer;
- qint64 mStartTime;
- int mFrameCount;
- QAudioFormat mFormat;
+ QAudioFormat format;
+ QByteArray data;
+ qint64 startTime;
};
-QAudioBufferPrivate *QAudioBufferPrivate::clone()
-{
- // We want to create a single bufferprivate with a
- // single qaab
- // This should only be called when the count is > 1
- Q_ASSERT(mCount.loadRelaxed() > 1);
-
- if (mProvider) {
- QAbstractAudioBuffer *abuf = mProvider->clone();
-
- if (!abuf) {
- abuf = new QMemoryAudioBufferProvider(mProvider->constData(), mProvider->frameCount(), mProvider->format(), mProvider->startTime());
- }
-
- if (abuf) {
- return new QAudioBufferPrivate(abuf);
- }
- }
-
- return nullptr;
-}
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QAudioBufferPrivate);
/*!
\class QAbstractAudioBuffer
@@ -191,38 +33,29 @@ QAudioBufferPrivate *QAudioBufferPrivate::clone()
\inmodule QtMultimedia
\ingroup multimedia
\ingroup multimedia_audio
- \brief The QAudioBuffer class represents a collection of audio samples with a specific format and sample rate.
+ \brief The QAudioBuffer class represents a collection of audio samples with a specific format
+ and sample rate.
+
+ QAudioBuffer is used by the QAudioDecoder class to hand decoded audio data over to the
+ application. An audio buffer contains data in a certain QAudioFormat that can be queried using
+ format(). It is also tagged with timing and duration information.
+
+ To access the data stored inside the buffer, use the data() or constData() methods.
+
+ Audio buffers are explicitly shared, in most cases, you should call detach() before
+ modifying the data.
*/
-// ^ Mostly useful with probe or decoder
/*!
Create a new, empty, invalid buffer.
*/
-QAudioBuffer::QAudioBuffer()
- : d(nullptr)
-{
-}
+QAudioBuffer::QAudioBuffer() noexcept = default;
/*!
- \internal
- Create a new audio buffer from the supplied \a provider. This
- constructor is typically only used when handling certain hardware
- or media framework specific buffers, and generally isn't useful
- in application code.
+ Creates a new audio buffer from \a other. Audio buffers are explicitly shared,
+ you should call detach() on the buffer to make a copy that can then be modified.
*/
-QAudioBuffer::QAudioBuffer(QAbstractAudioBuffer *provider)
- : d(new QAudioBufferPrivate(provider))
-{
-}
-/*!
- Creates a new audio buffer from \a other. Generally
- this will have copy-on-write semantics - a copy will
- only be made when it has to be.
- */
-QAudioBuffer::QAudioBuffer(const QAudioBuffer &other)
-{
- d = QAudioBufferPrivate::acquire(other.d);
-}
+QAudioBuffer::QAudioBuffer(const QAudioBuffer &other) noexcept = default;
/*!
Creates a new audio buffer from the supplied \a data, in the
@@ -240,11 +73,9 @@ QAudioBuffer::QAudioBuffer(const QAudioBuffer &other)
*/
QAudioBuffer::QAudioBuffer(const QByteArray &data, const QAudioFormat &format, qint64 startTime)
{
- if (format.isValid()) {
- int frameCount = format.framesForBytes(data.size());
- d = new QAudioBufferPrivate(new QMemoryAudioBufferProvider(data.constData(), frameCount, format, startTime));
- } else
- d = nullptr;
+ if (!format.isValid() || !data.size())
+ return;
+ d = new QAudioBufferPrivate(format, data, startTime);
}
/*!
@@ -258,43 +89,55 @@ QAudioBuffer::QAudioBuffer(const QByteArray &data, const QAudioFormat &format, q
*/
QAudioBuffer::QAudioBuffer(int numFrames, const QAudioFormat &format, qint64 startTime)
{
- if (format.isValid())
- d = new QAudioBufferPrivate(new QMemoryAudioBufferProvider(nullptr, numFrames, format, startTime));
- else
- d = nullptr;
+ if (!format.isValid() || !numFrames)
+ return;
+
+ QByteArray data(format.bytesForFrames(numFrames), '\0');
+ d = new QAudioBufferPrivate(format, data, startTime);
}
/*!
+ \fn QAudioBuffer::QAudioBuffer(QAudioBuffer &&other)
+
+ Constructs a QAudioBuffer by moving from \a other.
+*/
+
+/*!
+ \fn void QAudioBuffer::swap(QAudioBuffer &other) noexcept
+
+ Swaps the audio buffer with \a other.
+*/
+
+/*!
+ \fn QAudioBuffer &QAudioBuffer::operator=(QAudioBuffer &&other)
+
+ Moves \a other into this QAudioBuffer.
+*/
+
+/*!
Assigns the \a other buffer to this.
*/
-QAudioBuffer &QAudioBuffer::operator =(const QAudioBuffer &other)
-{
- if (this->d != other.d) {
- if (d)
- d->deref();
- d = QAudioBufferPrivate::acquire(other.d);
- }
- return *this;
-}
+QAudioBuffer &QAudioBuffer::operator=(const QAudioBuffer &other) = default;
/*!
Destroys this audio buffer.
*/
-QAudioBuffer::~QAudioBuffer()
-{
- if (d)
- d->deref();
-}
+QAudioBuffer::~QAudioBuffer() = default;
+
+/*! \fn bool QAudioBuffer::isValid() const noexcept
-/*!
Returns true if this is a valid buffer. A valid buffer
has more than zero frames in it and a valid format.
*/
-bool QAudioBuffer::isValid() const
+
+/*!
+ Detaches this audio buffers from other copies that might share data with it.
+*/
+void QAudioBuffer::detach()
{
- if (!d || !d->mProvider)
- return false;
- return d->mProvider->format().isValid() && (d->mProvider->frameCount() > 0);
+ if (!d)
+ return;
+ d = new QAudioBufferPrivate(*d);
}
/*!
@@ -304,11 +147,11 @@ bool QAudioBuffer::isValid() const
the \l duration() or \l byteCount() are calculated
from the \l frameCount().
*/
-QAudioFormat QAudioBuffer::format() const
+QAudioFormat QAudioBuffer::format() const noexcept
{
- if (!isValid())
+ if (!d)
return QAudioFormat();
- return d->mProvider->format();
+ return d->format;
}
/*!
@@ -317,11 +160,11 @@ QAudioFormat QAudioBuffer::format() const
An audio frame is an interleaved set of one sample per channel
for the same instant in time.
*/
-int QAudioBuffer::frameCount() const
+qsizetype QAudioBuffer::frameCount() const noexcept
{
- if (!isValid())
+ if (!d)
return 0;
- return d->mProvider->frameCount();
+ return d->format.framesForBytes(d->data.size());
}
/*!
@@ -335,21 +178,17 @@ int QAudioBuffer::frameCount() const
\sa frameCount()
*/
-int QAudioBuffer::sampleCount() const
+qsizetype QAudioBuffer::sampleCount() const noexcept
{
- if (!isValid())
- return 0;
-
return frameCount() * format().channelCount();
}
/*!
Returns the size of this buffer, in bytes.
*/
-int QAudioBuffer::byteCount() const
+qsizetype QAudioBuffer::byteCount() const noexcept
{
- const QAudioFormat f(format());
- return format().bytesForFrames(frameCount());
+ return d ? d->data.size() : 0;
}
/*!
@@ -357,7 +196,7 @@ int QAudioBuffer::byteCount() const
This depends on the \l format(), and the \l frameCount().
*/
-qint64 QAudioBuffer::duration() const
+qint64 QAudioBuffer::duration() const noexcept
{
return format().durationForFrames(frameCount());
}
@@ -367,23 +206,23 @@ qint64 QAudioBuffer::duration() const
If this buffer is not part of a stream, this will return -1.
*/
-qint64 QAudioBuffer::startTime() const
+qint64 QAudioBuffer::startTime() const noexcept
{
- if (!isValid())
+ if (!d)
return -1;
- return d->mProvider->startTime();
+ return d->startTime;
}
/*!
+ \fn template <typename T> const T* QAudioBuffer::constData() const
+
Returns a pointer to this buffer's data. You can only read it.
This method is preferred over the const version of \l data() to
prevent unnecessary copying.
- There is also a templatized version of this constData() function that
- allows you to retrieve a specific type of read-only pointer to
- the data. Note that there is no checking done on the format of
- the audio buffer - this is simply a convenience function.
+ Note that there is no checking done on the format of the audio
+ buffer - this is simply a convenience function.
\code
// With a 16bit sample buffer:
@@ -391,22 +230,23 @@ qint64 QAudioBuffer::startTime() const
\endcode
*/
-const void* QAudioBuffer::constData() const
+
+const void *QAudioBuffer::constData() const noexcept
{
- if (!isValid())
+ if (!d)
return nullptr;
- return d->mProvider->constData();
+ return d->data.constData();
}
/*!
+ \fn template <typename T> const T* QAudioBuffer::data() const
+
Returns a pointer to this buffer's data. You can only read it.
You should use the \l constData() function rather than this
to prevent accidental deep copying.
- There is also a templatized version of this data() function that
- allows you to retrieve a specific type of read-only pointer to
- the data. Note that there is no checking done on the format of
+ Note that there is no checking done on the format of
the audio buffer - this is simply a convenience function.
\code
@@ -414,192 +254,73 @@ const void* QAudioBuffer::constData() const
const quint16 *data = buffer->data<quint16>();
\endcode
*/
-const void* QAudioBuffer::data() const
+
+const void *QAudioBuffer::data() const noexcept
{
- if (!isValid())
+ if (!d)
return nullptr;
- return d->mProvider->constData();
+ return d->data.constData();
}
-
-/*
- Template data/constData functions caused override problems with qdoc,
- so moved their docs into the non template versions.
-*/
-
/*!
+ \fn template <typename T> T* QAudioBuffer::data()
+
Returns a pointer to this buffer's data. You can modify the
data through the returned pointer.
- Since QAudioBuffers can share the actual sample data, calling
- this function will result in a deep copy being made if there
- are any other buffers using the sample. You should avoid calling
- this unless you really need to modify the data.
-
- This pointer will remain valid until the underlying storage is
- detached. In particular, if you obtain a pointer, and then
- copy this audio buffer, changing data through this pointer may
- change both buffer instances. Calling \l data() on either instance
- will again cause a deep copy to be made, which may invalidate
- the pointers returned from this function previously.
+ Since QAudioBuffer objects are explicitly shared, you should usually
+ call detach() before modifying the data through this function.
- There is also a templatized version of data() allows you to retrieve
- a specific type of pointer to the data. Note that there is no
- checking done on the format of the audio buffer - this is
- simply a convenience function.
+ Note that there is no checking done on the format of the audio
+ buffer - this is simply a convenience function.
\code
// With a 16bit sample buffer:
quint16 *data = buffer->data<quint16>(); // May cause deep copy
\endcode
*/
+
void *QAudioBuffer::data()
{
- if (!isValid())
+ if (!d)
return nullptr;
-
- if (d->mCount.loadRelaxed() != 1) {
- // Can't share a writable buffer
- // so we need to detach
- QAudioBufferPrivate *newd = d->clone();
-
- // This shouldn't happen
- if (!newd)
- return nullptr;
-
- d->deref();
- d = newd;
- }
-
- // We're (now) the only user of this qaab, so
- // see if it's writable directly
- void *buffer = d->mProvider->writableData();
- if (buffer) {
- return buffer;
- }
-
- // Wasn't writable, so turn it into a memory provider
- QAbstractAudioBuffer *memBuffer = new QMemoryAudioBufferProvider(constData(), frameCount(), format(), startTime());
-
- if (memBuffer) {
- d->mProvider->release();
- d->mCount.storeRelaxed(1);
- d->mProvider = memBuffer;
-
- return memBuffer->writableData();
- }
-
- return nullptr;
+ return d->data.data();
}
-// Template helper classes worth documenting
-
/*!
- \class QAudioBuffer::StereoFrameDefault
- \internal
-
- Just a trait class for the default value.
-*/
-
-/*!
- \class QAudioBuffer::StereoFrame
- \brief The StereoFrame class provides a simple wrapper for a stereo audio frame.
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_audio
-
- This templatized structure lets you treat a block of individual samples as an
- interleaved stereo stream frame. This is most useful when used with the templatized
- \l {QAudioBuffer::data()}{data()} functions of QAudioBuffer. Generally the data
- is accessed as a pointer, so no copying should occur.
-
- There are some predefined instantiations of this template for working with common
- stereo sample depths in a convenient way.
-
- This frame structure has \e left and \e right members for accessing individual channel data.
-
- For example:
- \code
- // Assuming 'buffer' is an unsigned 16 bit stereo buffer..
- QAudioBuffer::S16U *frames = buffer->data<QAudioBuffer::S16U>();
- for (int i=0; i < buffer->frameCount(); i++) {
- qSwap(frames[i].left, frames[i].right);
- }
- \endcode
+ \typedef QAudioBuffer::S16S
- \sa QAudioBuffer::S8U, QAudioBuffer::S8S, QAudioBuffer::S16S, QAudioBuffer::S16U, QAudioBuffer::S32F
+ This is a predefined specialization for a signed stereo 16 bit sample. Each
+ channel is a \e {signed short}.
*/
/*!
- \fn template <typename T> QAudioBuffer::StereoFrame<T>::StereoFrame()
+ \typedef QAudioBuffer::U8M
- Constructs a new frame with the "silent" value for this
- sample format (0 for signed formats and floats, 0x8* for unsigned formats).
+ This is a predefined specialization for an unsigned 8 bit mono sample.
*/
-
/*!
- \fn template <typename T> QAudioBuffer::StereoFrame<T>::StereoFrame(T leftSample, T rightSample)
-
- Constructs a new frame with the supplied \a leftSample and \a rightSample values.
-*/
-
+ \typedef QAudioBuffer::S16M
+ This is a predefined specialization for a signed 16 bit mono sample.
+i*/
/*!
- \fn template <typename T> QAudioBuffer::StereoFrame<T>::operator=(const StereoFrame &other)
-
- Assigns \a other to this frame.
- */
-
-
-/*!
- \fn template <typename T> QAudioBuffer::StereoFrame<T>::average() const
-
- Returns the arithmetic average of the left and right samples.
- */
-
-/*! \fn template <typename T> QAudioBuffer::StereoFrame<T>::clear()
-
- Sets the values of this frame to the "silent" value.
-*/
-
-/*!
- \variable QAudioBuffer::StereoFrame::left
- \brief the left sample
-*/
-
-/*!
- \variable QAudioBuffer::StereoFrame::right
- \brief the right sample
-*/
-
-/*!
- \typedef QAudioBuffer::S8U
-
- This is a predefined specialization for an unsigned stereo 8 bit sample. Each
- channel is an \e {unsigned char}.
+ \typedef QAudioBuffer::S32M
+ This is a predefined specialization for a signed 32 bit mono sample.
*/
/*!
- \typedef QAudioBuffer::S8S
-
- This is a predefined specialization for a signed stereo 8 bit sample. Each
- channel is a \e {signed char}.
+ \typedef QAudioBuffer::F32M
+ This is a predefined specialization for a 32 bit float mono sample.
*/
/*!
- \typedef QAudioBuffer::S16U
-
- This is a predefined specialization for an unsigned stereo 16 bit sample. Each
- channel is an \e {unsigned short}.
+ \typedef QAudioBuffer::U8S
+ This is a predifined specialization for an unsiged 8 bit stereo sample.
*/
/*!
- \typedef QAudioBuffer::S16S
-
- This is a predefined specialization for a signed stereo 16 bit sample. Each
- channel is a \e {signed short}.
+ \typedef QAudioBuffer::S32S
+ This is a predifined specialization for a siged 32 bit stereo sample.
*/
/*!
- \typedef QAudioBuffer::S32F
-
- This is a predefined specialization for an 32 bit float sample. Each
- channel is a \e float.
+ \typedef QAudioBuffer::F32S
+ This is a predifined specialization for a 32 bit float stereo sample.
*/
-
QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiobuffer.h b/src/multimedia/audio/qaudiobuffer.h
index bed387462..822619f31 100644
--- a/src/multimedia/audio/qaudiobuffer.h
+++ b/src/multimedia/audio/qaudiobuffer.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QAUDIOBUFFER_H
#define QAUDIOBUFFER_H
@@ -43,89 +7,149 @@
#include <QtCore/qshareddata.h>
#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
-#include <QtMultimedia/qaudio.h>
+#include <QtMultimedia/qtaudio.h>
#include <QtMultimedia/qaudioformat.h>
QT_BEGIN_NAMESPACE
-class QAbstractAudioBuffer;
-class QAudioBufferPrivate;
-class Q_MULTIMEDIA_EXPORT QAudioBuffer
+namespace QtPrivate {
+template <QAudioFormat::SampleFormat> struct AudioSampleFormatHelper
+{
+};
+
+template <> struct AudioSampleFormatHelper<QAudioFormat::UInt8>
+{
+ using value_type = unsigned char;
+ static constexpr value_type Default = 128;
+};
+
+template <> struct AudioSampleFormatHelper<QAudioFormat::Int16>
+{
+ using value_type = short;
+ static constexpr value_type Default = 0;
+};
+
+template <> struct AudioSampleFormatHelper<QAudioFormat::Int32>
{
+ using value_type = int;
+ static constexpr value_type Default = 0;
+};
+
+template <> struct AudioSampleFormatHelper<QAudioFormat::Float>
+{
+ using value_type = float;
+ static constexpr value_type Default = 0.;
+};
+
+}
+
+template <QAudioFormat::ChannelConfig config, QAudioFormat::SampleFormat format>
+struct QAudioFrame
+{
+private:
+ // popcount in qalgorithms.h is unfortunately not constexpr on MSVC.
+ // Use this here as a fallback
+ static constexpr int constexprPopcount(quint32 i)
+ {
+ i = i - ((i >> 1) & 0x55555555); // add pairs of bits
+ i = (i & 0x33333333) + ((i >> 2) & 0x33333333); // quads
+ i = (i + (i >> 4)) & 0x0F0F0F0F; // groups of 8
+ return (i * 0x01010101) >> 24; // horizontal sum of bytes
+ }
+ static constexpr int nChannels = constexprPopcount(config);
public:
- QAudioBuffer();
- QAudioBuffer(QAbstractAudioBuffer *provider);
- QAudioBuffer(const QAudioBuffer &other);
- QAudioBuffer(const QByteArray &data, const QAudioFormat &format, qint64 startTime = -1);
- QAudioBuffer(int numFrames, const QAudioFormat &format, qint64 startTime = -1); // Initialized to empty
+ using value_type = typename QtPrivate::AudioSampleFormatHelper<format>::value_type;
+ value_type channels[nChannels];
+ static constexpr int positionToIndex(QAudioFormat::AudioChannelPosition pos)
+ {
+ if (!(config & (1u << pos)))
+ return -1;
+
+ uint maskedChannels = config & ((1u << pos) - 1);
+ return qPopulationCount(maskedChannels);
+ }
- QAudioBuffer& operator=(const QAudioBuffer &other);
- ~QAudioBuffer();
+ value_type value(QAudioFormat::AudioChannelPosition pos) const {
+ int idx = positionToIndex(pos);
+ if (idx < 0)
+ return QtPrivate::AudioSampleFormatHelper<format>::Default;
+ return channels[idx];
+ }
+ void setValue(QAudioFormat::AudioChannelPosition pos, value_type val) {
+ int idx = positionToIndex(pos);
+ if (idx < 0)
+ return;
+ channels[idx] = val;
+ }
+ value_type operator[](QAudioFormat::AudioChannelPosition pos) const {
+ return value(pos);
+ }
+ constexpr void clear() {
+ for (int i = 0; i < nChannels; ++i)
+ channels[i] = QtPrivate::AudioSampleFormatHelper<format>::Default;
+ }
+};
+
+template <QAudioFormat::SampleFormat Format>
+using QAudioFrameMono = QAudioFrame<QAudioFormat::ChannelConfigMono, Format>;
+
+template <QAudioFormat::SampleFormat Format>
+using QAudioFrameStereo = QAudioFrame<QAudioFormat::ChannelConfigStereo, Format>;
+
+template <QAudioFormat::SampleFormat Format>
+using QAudioFrame2Dot1 = QAudioFrame<QAudioFormat::ChannelConfig2Dot1, Format>;
- bool isValid() const;
+template <QAudioFormat::SampleFormat Format>
+using QAudioFrameSurround5Dot1 = QAudioFrame<QAudioFormat::ChannelConfigSurround5Dot1, Format>;
- QAudioFormat format() const;
+template <QAudioFormat::SampleFormat Format>
+using QAudioFrameSurround7Dot1 = QAudioFrame<QAudioFormat::ChannelConfigSurround7Dot1, Format>;
- int frameCount() const;
- int sampleCount() const;
- int byteCount() const;
- qint64 duration() const;
- qint64 startTime() const;
+class QAudioBufferPrivate;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QAudioBufferPrivate, Q_MULTIMEDIA_EXPORT)
- // Data modification
- // void clear();
- // Other ideas
- // operator *=
- // operator += (need to be careful about different formats)
+class Q_MULTIMEDIA_EXPORT QAudioBuffer
+{
+public:
+ QAudioBuffer() noexcept;
+ QAudioBuffer(const QAudioBuffer &other) noexcept;
+ QAudioBuffer(const QByteArray &data, const QAudioFormat &format, qint64 startTime = -1);
+ QAudioBuffer(int numFrames, const QAudioFormat &format, qint64 startTime = -1); // Initialized to empty
+ ~QAudioBuffer();
- // Data access
- const void* constData() const; // Does not detach, preferred
- const void* data() const; // Does not detach
- void *data(); // detaches
+ QAudioBuffer& operator=(const QAudioBuffer &other);
- // Structures for easier access to stereo data
- template <typename T> struct StereoFrameDefault { enum { Default = 0 }; };
+ QAudioBuffer(QAudioBuffer &&other) noexcept = default;
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QAudioBuffer)
+ void swap(QAudioBuffer &other) noexcept
+ { d.swap(other.d); }
- template <typename T> struct StereoFrame {
+ bool isValid() const noexcept { return d != nullptr; };
- StereoFrame()
- : left(T(StereoFrameDefault<T>::Default))
- , right(T(StereoFrameDefault<T>::Default))
- {
- }
+ void detach();
- StereoFrame(T leftSample, T rightSample)
- : left(leftSample)
- , right(rightSample)
- {
- }
+ QAudioFormat format() const noexcept;
- StereoFrame& operator=(const StereoFrame &other)
- {
- // Two straight assigns is probably
- // cheaper than a conditional check on
- // self assignment
- left = other.left;
- right = other.right;
- return *this;
- }
+ qsizetype frameCount() const noexcept;
+ qsizetype sampleCount() const noexcept;
+ qsizetype byteCount() const noexcept;
- T left;
- T right;
+ qint64 duration() const noexcept;
+ qint64 startTime() const noexcept;
- T average() const {return (left + right) / 2;}
- void clear() {left = right = T(StereoFrameDefault<T>::Default);}
- };
+ // Structures for easier access to data
+ typedef QAudioFrameMono<QAudioFormat::UInt8> U8M;
+ typedef QAudioFrameMono<QAudioFormat::Int16> S16M;
+ typedef QAudioFrameMono<QAudioFormat::Int32> S32M;
+ typedef QAudioFrameMono<QAudioFormat::Float> F32M;
- typedef StereoFrame<unsigned char> S8U;
- typedef StereoFrame<signed char> S8S;
- typedef StereoFrame<unsigned short> S16U;
- typedef StereoFrame<signed short> S16S;
- typedef StereoFrame<float> S32F;
+ typedef QAudioFrameStereo<QAudioFormat::UInt8> U8S;
+ typedef QAudioFrameStereo<QAudioFormat::Int16> S16S;
+ typedef QAudioFrameStereo<QAudioFormat::Int32> S32S;
+ typedef QAudioFrameStereo<QAudioFormat::Float> F32S;
template <typename T> const T* constData() const {
return static_cast<const T*>(constData());
@@ -137,12 +161,12 @@ public:
return static_cast<T*>(data());
}
private:
- QAudioBufferPrivate *d;
-};
-
-template <> struct QAudioBuffer::StereoFrameDefault<unsigned char> { enum { Default = 128 }; };
-template <> struct QAudioBuffer::StereoFrameDefault<unsigned short> { enum { Default = 32768 }; };
+ const void* constData() const noexcept;
+ const void* data() const noexcept;
+ void *data();
+ QExplicitlySharedDataPointer<QAudioBufferPrivate> d;
+};
QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiobuffer_p.h b/src/multimedia/audio/qaudiobuffer_p.h
deleted file mode 100644
index e770989f2..000000000
--- a/src/multimedia/audio/qaudiobuffer_p.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIOBUFFER_P_H
-#define QAUDIOBUFFER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <qtmultimediaglobal.h>
-#include <qmultimedia.h>
-
-#include "qaudioformat.h"
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QAbstractAudioBuffer {
-public:
- virtual ~QAbstractAudioBuffer() {}
-
- // Lifetime management
- virtual void release() = 0;
-
- // Format related
- virtual QAudioFormat format() const = 0;
- virtual qint64 startTime() const = 0;
- virtual int frameCount() const = 0;
-
- // R/O Data
- virtual void *constData() const = 0;
-
- // For writable data we do this:
- // If we only have one reference to the provider,
- // call writableData(). If that does not return 0,
- // then we're finished. If it does return 0, then we call
- // writableClone() to get a new buffer and then release
- // the old clone if that succeeds. If it fails, we create
- // a memory clone from the constData and release the old buffer.
- // If writableClone() succeeds, we then call writableData() on it
- // and that should be good.
-
- virtual void *writableData() = 0;
- virtual QAbstractAudioBuffer *clone() const = 0;
-};
-
-
-QT_END_NAMESPACE
-
-#endif // QAUDIOBUFFER_P_H
diff --git a/src/multimedia/audio/qaudiobufferinput.cpp b/src/multimedia/audio/qaudiobufferinput.cpp
new file mode 100644
index 000000000..0ac72c764
--- /dev/null
+++ b/src/multimedia/audio/qaudiobufferinput.cpp
@@ -0,0 +1,162 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qaudiobufferinput.h"
+#include "qplatformaudiobufferinput_p.h"
+#include "qmediainputencoderinterface_p.h"
+#include "qmediaframeinput_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QAudioBufferInputPrivate : public QMediaFrameInputPrivate
+{
+public:
+ QAudioBufferInputPrivate(QAudioBufferInput *q) : q(q) { }
+
+ bool sendAudioBuffer(const QAudioBuffer &audioBuffer)
+ {
+ return sendMediaFrame(
+ [&]() { emit m_platfromAudioBufferInput->newAudioBuffer(audioBuffer); });
+ }
+
+ void initialize()
+ {
+ m_platfromAudioBufferInput = std::make_unique<QPlatformAudioBufferInput>();
+ addUpdateSignal(m_platfromAudioBufferInput.get(),
+ &QPlatformAudioBufferInput::encoderUpdated);
+ }
+
+ void uninitialize()
+ {
+ m_platfromAudioBufferInput.reset();
+
+ if (captureSession())
+ captureSession()->setAudioBufferInput(nullptr);
+ }
+
+ QMediaCaptureSession *session() const { return m_captureSession; }
+
+ QPlatformAudioBufferInput *platfromAudioBufferInput() const
+ {
+ return m_platfromAudioBufferInput.get();
+ }
+
+private:
+ void updateCaptureSessionConnections(QMediaCaptureSession *prevSession,
+ QMediaCaptureSession *newSession) override
+ {
+ if (prevSession)
+ removeUpdateSignal(prevSession, &QMediaCaptureSession::audioOutputChanged);
+
+ if (newSession)
+ addUpdateSignal(newSession, &QMediaCaptureSession::audioOutputChanged);
+ }
+
+ bool checkIfCanSendMediaFrame() const override
+ {
+ if (auto encoderInterface = m_platfromAudioBufferInput->encoderInterface())
+ return encoderInterface->canPushFrame();
+
+ // Not implemented yet
+ // return captureSession()->audioOutput() != nullptr;
+ return false;
+ }
+
+ void emitReadyToSendMediaFrame() override { emit q->readyToSendAudioBuffer(); }
+
+private:
+ QAudioBufferInput *q = nullptr;
+ QMediaCaptureSession *m_captureSession = nullptr;
+ std::unique_ptr<QPlatformAudioBufferInput> m_platfromAudioBufferInput;
+};
+
+/*!
+ \class QAudioBufferInput
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_audio
+ \since 6.8
+
+ \brief The QAudioBufferInput class is used for providing custom audio buffers
+ to \l QMediaRecorder through \l QMediaCaptureSession.
+
+ \sa QMediaRecorder, QMediaCaptureSession
+*/
+
+/*!
+ Constructs a new QAudioBufferInput object with \a parent.
+*/
+QAudioBufferInput::QAudioBufferInput(QObject *parent)
+ : QObject(*new QAudioBufferInputPrivate(this), parent)
+{
+ Q_D(QAudioBufferInput);
+ d->initialize();
+}
+
+/*!
+ Destroys the object.
+ */
+QAudioBufferInput::~QAudioBufferInput()
+{
+ Q_D(QAudioBufferInput);
+ d->uninitialize();
+}
+
+/*!
+ Sends \l QAudioBuffer to \l QMediaRecorder through \l QMediaCaptureSession.
+
+ Returns \c true if the specified \a audioBuffer has been sent successfully
+ to the destination. Returns \c false, if the buffer hasn't been sent,
+ which can happen if the instance is not assigned to
+ \l QMediaCaptureSession, the session doesn't have a media recorder,
+ the media recorder is not started or its queue is full.
+ The signal \l readyToSendAudiobuffer will be sent as soon as
+ the destination is able to handle a new audio buffer.
+
+ Sending of an empty audio buffer is treated by \l QMediaRecorder
+ as an end of the input stream. QMediaRecorder stops the recording
+ automatically if \l QMediaRecorder::autoStop is \c true and
+ all the inputs have reported the end of the stream.
+*/
+bool QAudioBufferInput::sendAudioBuffer(const QAudioBuffer &audioBuffer)
+{
+ Q_D(QAudioBufferInput);
+ return d->sendAudioBuffer(audioBuffer);
+}
+
+/*!
+ Returns the capture session this audio buffer input is connected to, or
+ a \c nullptr if the audio buffer input is not connected to a capture session.
+
+ Use QMediaCaptureSession::setAudioBufferInput() to connect
+ the audio buffer input to a session.
+*/
+QMediaCaptureSession *QAudioBufferInput::captureSession() const
+{
+ Q_D(const QAudioBufferInput);
+ return d->captureSession();
+}
+
+void QAudioBufferInput::setCaptureSession(QMediaCaptureSession *captureSession)
+{
+ Q_D(QAudioBufferInput);
+ d->setCaptureSession(captureSession);
+}
+
+QPlatformAudioBufferInput *QAudioBufferInput::platformAudioBufferInput() const
+{
+ Q_D(const QAudioBufferInput);
+ return d->platfromAudioBufferInput();
+}
+
+/*!
+ \fn void QAudioBufferInput::readyToSendAudioBuffer()
+
+ Signals that a new audio buffer can be sent to the audio buffer input.
+ After receiving the signal, if you have audio date to be sent, invoke \l sendAudioBuffer
+ once or in a loop until it returns \c false.
+
+ \sa sendAudioBuffer()
+*/
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiobufferinput.h b/src/multimedia/audio/qaudiobufferinput.h
new file mode 100644
index 000000000..92bb8b71a
--- /dev/null
+++ b/src/multimedia/audio/qaudiobufferinput.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAUDIOBUFFERINPUT_H
+#define QAUDIOBUFFERINPUT_H
+
+#include <QtMultimedia/qtmultimediaexports.h>
+#include <QtMultimedia/qaudiobuffer.h>
+#include <QtCore/qobject.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPlatformAudioBufferInput;
+class QAudioBufferInputPrivate;
+class QMediaCaptureSession;
+
+class Q_MULTIMEDIA_EXPORT QAudioBufferInput : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QAudioBufferInput(QObject *parent = nullptr);
+
+ ~QAudioBufferInput() override;
+
+ bool sendAudioBuffer(const QAudioBuffer &audioBuffer);
+
+ QMediaCaptureSession *captureSession() const;
+
+Q_SIGNALS:
+ void readyToSendAudioBuffer();
+
+private:
+ void setCaptureSession(QMediaCaptureSession *captureSession);
+
+ QPlatformAudioBufferInput *platformAudioBufferInput() const;
+
+ friend class QMediaCaptureSession;
+ Q_DISABLE_COPY(QAudioBufferInput)
+ Q_DECLARE_PRIVATE(QAudioBufferInput)
+};
+
+QT_END_NAMESPACE
+
+#endif // QAUDIOBUFFERINPUT_H
diff --git a/src/multimedia/audio/qaudiobufferoutput.cpp b/src/multimedia/audio/qaudiobufferoutput.cpp
new file mode 100644
index 000000000..50389c49a
--- /dev/null
+++ b/src/multimedia/audio/qaudiobufferoutput.cpp
@@ -0,0 +1,78 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qaudiobufferoutput_p.h"
+#include "qmediaplayer.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QAudioBufferOutput
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_audio
+ \since 6.8
+
+ \brief The QAudioBufferOutput class is used for capturing audio data provided by \l QMediaPlayer.
+
+ QAudioBufferOutput can be set to QMediaPlayer in order to receive audio buffers
+ decoded by the media player. The received audio data can be used for any
+ processing or visualization.
+
+ \sa QMediaPlayer, QMediaPlayer::setAudioBufferOutput, QAudioBuffer
+*/
+
+/*!
+ Constructs a new QAudioBufferOutput object with \a parent.
+
+ The audio format of output audio buffers will depend on
+ the source media file and the inner audio decoder in \l QMediaPlayer.
+*/
+QAudioBufferOutput::QAudioBufferOutput(QObject *parent)
+ : QObject(*new QAudioBufferOutputPrivate, parent)
+{
+}
+
+/*!
+ Constructs a new QAudioBufferOutput object with audio \a format and \a parent.
+
+ If the specified \a format is valid, it will be the format of output
+ audio buffers. Otherwise, the format of output audio buffers
+ will depend on the source media file and the inner audio decoder in \l QMediaPlayer.
+*/
+QAudioBufferOutput::QAudioBufferOutput(const QAudioFormat &format, QObject *parent)
+ : QObject(*new QAudioBufferOutputPrivate(format), parent)
+{
+}
+
+/*!
+ Destroys the audio buffer output object.
+*/
+QAudioBufferOutput::~QAudioBufferOutput()
+{
+ Q_D(QAudioBufferOutput);
+
+ if (d->mediaPlayer)
+ d->mediaPlayer->setAudioBufferOutput(nullptr);
+}
+
+/*!
+ Gets the audio format specified in the constructor.
+
+ If the format is valid, it specifies the format of output oudio buffers.
+*/
+QAudioFormat QAudioBufferOutput::format() const
+{
+ Q_D(const QAudioBufferOutput);
+ return d->format;
+}
+
+/*!
+ \fn void QAudioBufferOutput::audioBufferReceived(const QAudioBuffer &buffer)
+
+ Signals that a new audio \a buffer has been received from \l QMediaPlayer.
+*/
+
+QT_END_NAMESPACE
+
+#include "moc_qaudiobufferoutput.cpp"
diff --git a/src/multimedia/audio/qaudiobufferoutput.h b/src/multimedia/audio/qaudiobufferoutput.h
new file mode 100644
index 000000000..2e4fab1a4
--- /dev/null
+++ b/src/multimedia/audio/qaudiobufferoutput.h
@@ -0,0 +1,37 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAUDIOBUFFEROUTPUT_H
+#define QAUDIOBUFFEROUTPUT_H
+
+#include <QtMultimedia/qtmultimediaexports.h>
+#include <QtMultimedia/qaudiobuffer.h>
+#include <QtCore/qobject.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioBufferOutputPrivate;
+
+class Q_MULTIMEDIA_EXPORT QAudioBufferOutput : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QAudioBufferOutput(QObject *parent = nullptr);
+
+ explicit QAudioBufferOutput(const QAudioFormat &format, QObject *parent = nullptr);
+
+ ~QAudioBufferOutput() override;
+
+ QAudioFormat format() const;
+
+Q_SIGNALS:
+ void audioBufferReceived(const QAudioBuffer &buffer);
+
+private:
+ Q_DISABLE_COPY(QAudioBufferOutput)
+ Q_DECLARE_PRIVATE(QAudioBufferOutput)
+};
+
+QT_END_NAMESPACE
+
+#endif // QAUDIOBUFFEROUTPUT_H
diff --git a/src/multimedia/audio/qaudiobufferoutput_p.h b/src/multimedia/audio/qaudiobufferoutput_p.h
new file mode 100644
index 000000000..2f9c11bd1
--- /dev/null
+++ b/src/multimedia/audio/qaudiobufferoutput_p.h
@@ -0,0 +1,42 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAUDIOBUFFEROUTPUT_P_H
+#define QAUDIOBUFFEROUTPUT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/private/qobject_p.h>
+#include "qaudiobufferoutput.h"
+
+QT_BEGIN_NAMESPACE
+
+class QMediaPlayer;
+
+class QAudioBufferOutputPrivate : public QObjectPrivate
+{
+public:
+ QAudioBufferOutputPrivate(const QAudioFormat &format = {}) : format(std::move(format)) { }
+
+ static QMediaPlayer *exchangeMediaPlayer(QAudioBufferOutput &output, QMediaPlayer *player)
+ {
+ auto outputPrivate = static_cast<QAudioBufferOutputPrivate *>(output.d_func());
+ return std::exchange(outputPrivate->mediaPlayer, player);
+ }
+
+ QAudioFormat format;
+ QMediaPlayer *mediaPlayer = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QAUDIOBUFFEROUTPUT_P_H
diff --git a/src/multimedia/audio/qaudiodecoder.cpp b/src/multimedia/audio/qaudiodecoder.cpp
index 0286e9a85..f555f46ed 100644
--- a/src/multimedia/audio/qaudiodecoder.cpp
+++ b/src/multimedia/audio/qaudiodecoder.cpp
@@ -1,192 +1,104 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qaudiodecoder.h"
-#include "qmediaobject_p.h"
-#include <qmediaservice.h>
-#include "qaudiodecodercontrol.h"
-#include <private/qmediaserviceprovider_p.h>
+#include <private/qaudiodecoder_p.h>
+#include <private/qmultimediautils_p.h>
+#include <private/qplatformaudiodecoder_p.h>
+#include <private/qplatformmediaintegration_p.h>
#include <QtCore/qcoreevent.h>
-#include <QtCore/qmetaobject.h>
-#include <QtCore/qtimer.h>
#include <QtCore/qdebug.h>
+#include <QtCore/qmetaobject.h>
#include <QtCore/qpointer.h>
+#include <QtCore/qtimer.h>
+#include <QtCore/qurl.h>
QT_BEGIN_NAMESPACE
/*!
\class QAudioDecoder
- \brief The QAudioDecoder class allows decoding audio.
+ \brief The QAudioDecoder class implements decoding audio.
\inmodule QtMultimedia
\ingroup multimedia
\ingroup multimedia_audio
\preliminary
- The QAudioDecoder class is a high level class for decoding local
+ The QAudioDecoder class is a high level class for decoding
audio media files. It is similar to the QMediaPlayer class except
that audio is provided back through this API rather than routed
- directly to audio hardware, and playlists and network and streaming
- based media is not supported.
+ directly to audio hardware.
\sa QAudioBuffer
*/
-static void qRegisterAudioDecoderMetaTypes()
-{
- qRegisterMetaType<QAudioDecoder::State>("QAudioDecoder::State");
- qRegisterMetaType<QAudioDecoder::Error>("QAudioDecoder::Error");
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterAudioDecoderMetaTypes)
-
-class QAudioDecoderPrivate : public QMediaObjectPrivate
-{
- Q_DECLARE_NON_CONST_PUBLIC(QAudioDecoder)
-
-public:
- QAudioDecoderPrivate()
- : provider(nullptr)
- , control(nullptr)
- , state(QAudioDecoder::StoppedState)
- , error(QAudioDecoder::NoError)
- {}
-
- QMediaServiceProvider *provider;
- QAudioDecoderControl *control;
- QAudioDecoder::State state;
- QAudioDecoder::Error error;
- QString errorString;
-
- void _q_stateChanged(QAudioDecoder::State state);
- void _q_error(int error, const QString &errorString);
-};
-
-void QAudioDecoderPrivate::_q_stateChanged(QAudioDecoder::State ps)
+/*!
+ Construct an QAudioDecoder instance with \a parent.
+*/
+QAudioDecoder::QAudioDecoder(QObject *parent) : QObject{ *new QAudioDecoderPrivate, parent }
{
- Q_Q(QAudioDecoder);
+ QT6_ONLY(Q_UNUSED(unused))
- if (ps != state) {
- state = ps;
+ Q_D(QAudioDecoder);
- emit q->stateChanged(ps);
+ auto maybeDecoder = QPlatformMediaIntegration::instance()->createAudioDecoder(this);
+ if (maybeDecoder) {
+ d->decoder.reset(maybeDecoder.value());
+ } else {
+ qWarning() << "Failed to initialize QAudioDecoder" << maybeDecoder.error();
}
}
-void QAudioDecoderPrivate::_q_error(int error, const QString &errorString)
-{
- Q_Q(QAudioDecoder);
-
- this->error = QAudioDecoder::Error(error);
- this->errorString = errorString;
-
- emit q->error(this->error);
-}
+/*!
+ Destroys the audio decoder object.
+*/
+QAudioDecoder::~QAudioDecoder() = default;
/*!
- Construct an QAudioDecoder instance
- parented to \a parent.
+ Returns true is audio decoding is supported on this platform.
*/
-QAudioDecoder::QAudioDecoder(QObject *parent)
- : QMediaObject(*new QAudioDecoderPrivate,
- parent,
- QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_AUDIODECODER))
+bool QAudioDecoder::isSupported() const
{
- Q_D(QAudioDecoder);
+ Q_D(const QAudioDecoder);
- d->provider = QMediaServiceProvider::defaultServiceProvider();
- if (d->service) {
- d->control = qobject_cast<QAudioDecoderControl*>(d->service->requestControl(QAudioDecoderControl_iid));
- if (d->control != nullptr) {
- connect(d->control, SIGNAL(stateChanged(QAudioDecoder::State)), SLOT(_q_stateChanged(QAudioDecoder::State)));
- connect(d->control, SIGNAL(error(int,QString)), SLOT(_q_error(int,QString)));
-
- connect(d->control, SIGNAL(formatChanged(QAudioFormat)), SIGNAL(formatChanged(QAudioFormat)));
- connect(d->control, SIGNAL(sourceChanged()), SIGNAL(sourceChanged()));
- connect(d->control, SIGNAL(bufferReady()), this, SIGNAL(bufferReady()));
- connect(d->control ,SIGNAL(bufferAvailableChanged(bool)), this, SIGNAL(bufferAvailableChanged(bool)));
- connect(d->control ,SIGNAL(finished()), this, SIGNAL(finished()));
- connect(d->control ,SIGNAL(positionChanged(qint64)), this, SIGNAL(positionChanged(qint64)));
- connect(d->control ,SIGNAL(durationChanged(qint64)), this, SIGNAL(durationChanged(qint64)));
- }
- }
- if (!d->control) {
- d->error = ServiceMissingError;
- d->errorString = tr("The QAudioDecoder object does not have a valid service");
- }
+ return bool(d->decoder);
}
-
/*!
- Destroys the audio decoder object.
+ \property QAudioDecoder::isDecoding
+ \brief \c true if the decoder is currently running and decoding audio data.
*/
-QAudioDecoder::~QAudioDecoder()
+bool QAudioDecoder::isDecoding() const
{
- Q_D(QAudioDecoder);
-
- if (d->service) {
- if (d->control)
- d->service->releaseControl(d->control);
-
- d->provider->releaseService(d->service);
- }
-}
+ Q_D(const QAudioDecoder);
-QAudioDecoder::State QAudioDecoder::state() const
-{
- return d_func()->state;
+ return d->decoder && d->decoder->isDecoding();
}
/*!
- Returns the current error state.
-*/
+ Returns the current error state of the QAudioDecoder.
+*/
QAudioDecoder::Error QAudioDecoder::error() const
{
- return d_func()->error;
+ Q_D(const QAudioDecoder);
+ return d->decoder ? d->decoder->error() : NotSupportedError;
}
+/*!
+ \property QAudioDecoder::error
+
+ Returns a human readable description of the current error, or
+ an empty string is there is no error.
+*/
QString QAudioDecoder::errorString() const
{
- return d_func()->errorString;
+ Q_D(const QAudioDecoder);
+ if (!d->decoder)
+ return tr("QAudioDecoder not supported.");
+ return d->decoder->errorString();
}
/*!
@@ -205,18 +117,12 @@ void QAudioDecoder::start()
{
Q_D(QAudioDecoder);
- if (d->control == nullptr) {
- QMetaObject::invokeMethod(this, "_q_error", Qt::QueuedConnection,
- Q_ARG(int, QAudioDecoder::ServiceMissingError),
- Q_ARG(QString, tr("The QAudioDecoder object does not have a valid service")));
+ if (!d->decoder)
return;
- }
// Reset error conditions
- d->error = NoError;
- d->errorString.clear();
-
- d->control->start();
+ d->decoder->clearError();
+ d->decoder->start();
}
/*!
@@ -226,8 +132,8 @@ void QAudioDecoder::stop()
{
Q_D(QAudioDecoder);
- if (d->control != nullptr)
- d->control->stop();
+ if (d->decoder)
+ d->decoder->stop();
}
/*!
@@ -235,12 +141,10 @@ void QAudioDecoder::stop()
If \l setSourceDevice was called, this will
be empty.
*/
-QString QAudioDecoder::sourceFilename() const
+QUrl QAudioDecoder::source() const
{
Q_D(const QAudioDecoder);
- if (d->control)
- return d->control->sourceFilename();
- return QString();
+ return d->unresolvedUrl;
}
/*!
@@ -252,24 +156,28 @@ QString QAudioDecoder::sourceFilename() const
You can only specify either a source filename or
a source QIODevice. Setting one will unset the other.
*/
-void QAudioDecoder::setSourceFilename(const QString &fileName)
+void QAudioDecoder::setSource(const QUrl &fileName)
{
Q_D(QAudioDecoder);
- if (d->control != nullptr)
- d_func()->control->setSourceFilename(fileName);
+ if (!d->decoder)
+ return;
+
+ d->decoder->clearError();
+ d->unresolvedUrl = fileName;
+ d->decoder->setSourceDevice(nullptr);
+ QUrl url = qMediaFromUserInput(fileName);
+ d->decoder->setSource(url);
}
/*!
Returns the current source QIODevice, if one was set.
- If \l setSourceFilename() was called, this will be 0.
+ If \l setSource() was called, this will be a nullptr.
*/
QIODevice *QAudioDecoder::sourceDevice() const
{
Q_D(const QAudioDecoder);
- if (d->control)
- return d->control->sourceDevice();
- return nullptr;
+ return d->decoder ? d->decoder->sourceDevice() : nullptr;
}
/*!
@@ -284,24 +192,24 @@ QIODevice *QAudioDecoder::sourceDevice() const
void QAudioDecoder::setSourceDevice(QIODevice *device)
{
Q_D(QAudioDecoder);
-
- if (d->control != nullptr)
- d_func()->control->setSourceDevice(device);
+ if (d->decoder) {
+ d->unresolvedUrl = QUrl{};
+ d->decoder->setSourceDevice(device);
+ }
}
/*!
- Returns the current audio format of the decoded stream.
+ Returns the audio format the decoder is set to.
- Any buffers returned should have this format.
+ \note This may be different than the format of the decoded
+ samples, if the audio format was set to an invalid one.
\sa setAudioFormat(), formatChanged()
*/
QAudioFormat QAudioDecoder::audioFormat() const
{
Q_D(const QAudioDecoder);
- if (d->control)
- return d->control->audioFormat();
- return QAudioFormat();
+ return d->decoder ? d->decoder->audioFormat() : QAudioFormat{};
}
/*!
@@ -319,45 +227,20 @@ QAudioFormat QAudioDecoder::audioFormat() const
If you wish to reset the decoded format to that of the original
audio file, you can specify an invalid \a format.
+
+ \warning Setting a desired audio format is not yet supported
+ on the Android backend. It does work with the default FFMPEG
+ backend.
*/
void QAudioDecoder::setAudioFormat(const QAudioFormat &format)
{
- Q_D(QAudioDecoder);
-
- if (state() != QAudioDecoder::StoppedState)
+ if (isDecoding())
return;
- if (d->control != nullptr)
- d_func()->control->setAudioFormat(format);
-}
-
-/*!
- \internal
-*/
-
-bool QAudioDecoder::bind(QObject *obj)
-{
- return QMediaObject::bind(obj);
-}
-
-/*!
- \internal
-*/
-
-void QAudioDecoder::unbind(QObject *obj)
-{
- QMediaObject::unbind(obj);
-}
+ Q_D(QAudioDecoder);
-/*!
- Returns the level of support an audio decoder has for a \a mimeType and a set of \a codecs.
-*/
-QMultimedia::SupportEstimate QAudioDecoder::hasSupport(const QString &mimeType,
- const QStringList& codecs)
-{
- return QMediaServiceProvider::defaultServiceProvider()->hasSupport(QByteArray(Q_MEDIASERVICE_AUDIODECODER),
- mimeType,
- codecs);
+ if (d->decoder)
+ d->decoder->setAudioFormat(format);
}
/*!
@@ -368,9 +251,7 @@ QMultimedia::SupportEstimate QAudioDecoder::hasSupport(const QString &mimeType,
bool QAudioDecoder::bufferAvailable() const
{
Q_D(const QAudioDecoder);
- if (d->control)
- return d->control->bufferAvailable();
- return false;
+ return d->decoder && d->decoder->bufferAvailable();
}
/*!
@@ -381,9 +262,7 @@ bool QAudioDecoder::bufferAvailable() const
qint64 QAudioDecoder::position() const
{
Q_D(const QAudioDecoder);
- if (d->control)
- return d->control->position();
- return -1;
+ return d->decoder ? d->decoder->position() : -1;
}
/*!
@@ -394,9 +273,7 @@ qint64 QAudioDecoder::position() const
qint64 QAudioDecoder::duration() const
{
Q_D(const QAudioDecoder);
- if (d->control)
- return d->control->duration();
- return -1;
+ return d->decoder ? d->decoder->duration() : -1;
}
/*!
@@ -412,26 +289,11 @@ qint64 QAudioDecoder::duration() const
QAudioBuffer QAudioDecoder::read() const
{
Q_D(const QAudioDecoder);
-
- if (d->control) {
- return d->control->read();
- } else {
- return QAudioBuffer();
- }
+ return d->decoder ? d->decoder->read() : QAudioBuffer{};
}
// Enums
/*!
- \enum QAudioDecoder::State
-
- Defines the current state of a media player.
-
- \value StoppedState The decoder is not decoding. Decoding will
- start at the start of the media.
- \value DecodingState The audio player is currently decoding media.
-*/
-
-/*!
\enum QAudioDecoder::Error
Defines a media player error condition.
@@ -440,12 +302,12 @@ QAudioBuffer QAudioDecoder::read() const
\value ResourceError A media resource couldn't be resolved.
\value FormatError The format of a media resource isn't supported.
\value AccessDeniedError There are not the appropriate permissions to play a media resource.
- \value ServiceMissingError A valid playback service was not found, playback cannot proceed.
+ \value NotSupportedError QAudioDecoder is not supported on this platform
*/
// Signals
/*!
- \fn QAudioDecoder::error(QAudioDecoder::Error error)
+ \fn void QAudioDecoder::error(QAudioDecoder::Error error)
Signals that an \a error condition has occurred.
@@ -453,17 +315,11 @@ QAudioBuffer QAudioDecoder::read() const
*/
/*!
- \fn void QAudioDecoder::stateChanged(State state)
-
- Signal the \a state of the decoder object has changed.
-*/
-
-/*!
\fn void QAudioDecoder::sourceChanged()
Signals that the current source of the decoder has changed.
- \sa sourceFilename(), sourceDevice()
+ \sa source(), sourceDevice()
*/
/*!
@@ -517,26 +373,9 @@ QAudioBuffer QAudioDecoder::read() const
\sa positionChanged()
*/
-
// Properties
/*!
- \property QAudioDecoder::state
- \brief the audio decoder's playback state.
-
- By default this property is QAudioDecoder::Stopped
-
- \sa start(), stop()
-*/
-
-/*!
- \property QAudioDecoder::error
- \brief a string describing the last error condition.
-
- \sa error()
-*/
-
-/*!
- \property QAudioDecoder::sourceFilename
+ \property QAudioDecoder::source
\brief the active filename being decoded by the decoder object.
*/
diff --git a/src/multimedia/audio/qaudiodecoder.h b/src/multimedia/audio/qaudiodecoder.h
index 4ba107946..9044b6617 100644
--- a/src/multimedia/audio/qaudiodecoder.h
+++ b/src/multimedia/audio/qaudiodecoder.h
@@ -1,89 +1,43 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QAUDIODECODER_H
#define QAUDIODECODER_H
-#include <QtMultimedia/qmediaobject.h>
+#include <QtCore/qobject.h>
#include <QtMultimedia/qmediaenumdebug.h>
-
#include <QtMultimedia/qaudiobuffer.h>
QT_BEGIN_NAMESPACE
class QAudioDecoderPrivate;
-class Q_MULTIMEDIA_EXPORT QAudioDecoder : public QMediaObject
+class Q_MULTIMEDIA_EXPORT QAudioDecoder : public QObject
{
Q_OBJECT
- Q_PROPERTY(QString sourceFilename READ sourceFilename WRITE setSourceFilename NOTIFY sourceChanged)
- Q_PROPERTY(State state READ state NOTIFY stateChanged)
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(bool isDecoding READ isDecoding NOTIFY isDecodingChanged)
Q_PROPERTY(QString error READ errorString)
Q_PROPERTY(bool bufferAvailable READ bufferAvailable NOTIFY bufferAvailableChanged)
- Q_ENUMS(State)
- Q_ENUMS(Error)
-
public:
- enum State
- {
- StoppedState,
- DecodingState
- };
-
enum Error
{
NoError,
ResourceError,
FormatError,
AccessDeniedError,
- ServiceMissingError
+ NotSupportedError
};
+ Q_ENUM(Error)
explicit QAudioDecoder(QObject *parent = nullptr);
~QAudioDecoder();
- static QMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs = QStringList());
+ bool isSupported() const;
+ bool isDecoding() const;
- State state() const;
-
- QString sourceFilename() const;
- void setSourceFilename(const QString &fileName);
+ QUrl source() const;
+ void setSource(const QUrl &fileName);
QIODevice* sourceDevice() const;
void setSourceDevice(QIODevice *device);
@@ -108,8 +62,8 @@ Q_SIGNALS:
void bufferAvailableChanged(bool);
void bufferReady();
void finished();
+ void isDecodingChanged(bool);
- void stateChanged(QAudioDecoder::State newState);
void formatChanged(const QAudioFormat &format);
void error(QAudioDecoder::Error error);
@@ -119,23 +73,16 @@ Q_SIGNALS:
void positionChanged(qint64 position);
void durationChanged(qint64 duration);
-public:
- bool bind(QObject *) override;
- void unbind(QObject *) override;
-
private:
Q_DISABLE_COPY(QAudioDecoder)
Q_DECLARE_PRIVATE(QAudioDecoder)
- Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAudioDecoder::State))
- Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &))
+
+ // ### Qt7: remove unused member
+ QT6_ONLY(void *unused = nullptr;) // for ABI compatibility
};
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QAudioDecoder::State)
-Q_DECLARE_METATYPE(QAudioDecoder::Error)
-
-Q_MEDIA_ENUM_DEBUG(QAudioDecoder, State)
Q_MEDIA_ENUM_DEBUG(QAudioDecoder, Error)
#endif // QAUDIODECODER_H
diff --git a/src/multimedia/audio/qaudiodecoder_p.h b/src/multimedia/audio/qaudiodecoder_p.h
new file mode 100644
index 000000000..fa7311457
--- /dev/null
+++ b/src/multimedia/audio/qaudiodecoder_p.h
@@ -0,0 +1,40 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAUDIODECODER_P_H
+#define QAUDIODECODER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/private/qobject_p.h>
+#include <QtMultimedia/private/qplatformaudiodecoder_p.h>
+
+#include <memory.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioDecoder;
+
+class QAudioDecoderPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QAudioDecoder)
+
+public:
+ QAudioDecoderPrivate() = default;
+
+ QUrl unresolvedUrl;
+ std::unique_ptr<QPlatformAudioDecoder> decoder;
+};
+
+QT_END_NAMESPACE
+
+#endif // QAUDIODECODER_P_H
diff --git a/src/multimedia/audio/qaudiodevice.cpp b/src/multimedia/audio/qaudiodevice.cpp
new file mode 100644
index 000000000..4b1e182cb
--- /dev/null
+++ b/src/multimedia/audio/qaudiodevice.cpp
@@ -0,0 +1,373 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qaudiosystem_p.h"
+#include "qaudiodevice_p.h"
+#include <private/qplatformmediadevices_p.h>
+#include <private/qplatformmediaintegration_p.h>
+
+#include <QtCore/qmap.h>
+
+QT_BEGIN_NAMESPACE
+
+QAudioDevicePrivate::~QAudioDevicePrivate() = default;
+
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QAudioDevicePrivate);
+
+/*!
+ \class QAudioDevice
+ \brief The QAudioDevice class provides an information about audio devices and their
+ functionality.
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_audio
+
+ QAudioDevice describes an audio device available in the system, either for input or for
+ playback.
+
+ A QAudioDevice is used by Qt to construct
+ classes that communicate with the device -- such as
+ QAudioSource, and QAudioSink. It is also used to determine the
+ input or output device to use in a capture session or during media playback.
+
+ You can also query each device for the formats it supports. A
+ format in this context is a set consisting of a channel count, sample rate, and sample type. A
+ format is represented by the QAudioFormat class.
+
+ The values supported by the device for each of these parameters can be
+ fetched with minimumChannelCount(), maximumChannelCount(),
+ minimumSampleRate(), maximumSampleRate() and supportedSampleFormats(). The
+ combinations supported are dependent on the audio device capabilities. If
+ you need a specific format, you can check if the device supports it with
+ isFormatSupported(). For instance:
+
+ \snippet multimedia-snippets/audio.cpp Audio output setup
+
+ The set of available devices can be retrieved from the QMediaDevices class.
+
+ For instance:
+
+ \snippet multimedia-snippets/audio.cpp Dumping audio formats
+
+ In this code sample, we loop through all devices that are able to output
+ sound, i.e., play an audio stream in a supported format. For each device we
+ find, we simply print the deviceName().
+
+ \sa QAudioSink, QAudioSource, QAudioFormat
+*/
+
+/*!
+ \qmlvaluetype audioDevice
+ \inqmlmodule QtMultimedia
+ \since 6.2
+ //! \instantiates QAudioDevice
+ \brief Describes an audio device.
+ \ingroup multimedia_qml
+ \ingroup multimedia_audio_qml
+ \ingroup qmlvaluetypes
+
+ The audioDevice value type describes the properties of an audio device that
+ is connected to the system.
+
+ The list of audio input or output devices can be queried from the \l{MediaDevices}
+ type. To select a certain audio device for input or output set it as the device
+ on \l{AudioInput} or \l{AudioOutput}.
+
+ \qml
+ MediaPlayer {
+ audioOutput: AudioOutput {
+ device: mediaDevices.defaultAudioOutput
+ }
+ }
+ MediaDevices {
+ id: mediaDevices
+ }
+ \endqml
+*/
+
+/*!
+ Constructs a null QAudioDevice object.
+*/
+QAudioDevice::QAudioDevice() = default;
+
+/*!
+ Constructs a copy of \a other.
+*/
+QAudioDevice::QAudioDevice(const QAudioDevice &other) = default;
+
+/*!
+ \fn QAudioDevice::QAudioDevice(QAudioDevice &&other)
+
+ Move constructs from \a other.
+*/
+/*!
+ \fn void QAudioDevice::swap(QAudioDevice &other) noexcept
+
+ Swaps the audio device with the \a other.
+*/
+/*!
+ Destroy this audio device info.
+*/
+QAudioDevice::~QAudioDevice() = default;
+
+/*!
+ Sets the QAudioDevice object to be equal to \a other.
+*/
+QAudioDevice &QAudioDevice::operator=(const QAudioDevice &other) = default;
+
+/*!
+ \fn QAudioDevice& QAudioDevice::operator=(QAudioDevice &&other)
+
+ Moves \a other into this QAudioDevice object.
+*/
+
+/*!
+ Returns true if this QAudioDevice class represents the
+ same audio device as \a other.
+*/
+bool QAudioDevice::operator==(const QAudioDevice &other) const
+{
+ if (d == other.d)
+ return true;
+ if (!d || !other.d)
+ return false;
+ if (d->mode == other.d->mode && d->id == other.d->id && d->isDefault == other.d->isDefault)
+ return true;
+ return false;
+}
+
+/*!
+ Returns true if this QAudioDevice class represents a
+ different audio device than \a other
+*/
+bool QAudioDevice::operator!=(const QAudioDevice &other) const
+{
+ return !operator==(other);
+}
+
+/*!
+ Returns whether this QAudioDevice object holds a valid device definition.
+*/
+bool QAudioDevice::isNull() const
+{
+ return d == nullptr;
+}
+
+/*!
+ \qmlproperty string QtMultimedia::audioDevice::id
+
+ Holds an identifier for the audio device.
+
+ Device names vary depending on the platform/audio plugin being used.
+
+ They are a unique identifier for the audio device.
+*/
+
+/*!
+ \property QAudioDevice::id
+
+ Returns an identifier for the audio device.
+
+ Device names vary depending on the platform/audio plugin being used.
+
+ They are a unique identifier for the audio device.
+*/
+QByteArray QAudioDevice::id() const
+{
+ return isNull() ? QByteArray() : d->id;
+}
+
+/*!
+ \qmlproperty string QtMultimedia::audioDevice::description
+
+ Holds a human readable name of the audio device.
+
+ Use this string to present the device to the user.
+*/
+
+/*!
+ \property QAudioDevice::description
+
+ Returns a human readable name of the audio device.
+
+ Use this string to present the device to the user.
+*/
+QString QAudioDevice::description() const
+{
+ return isNull() ? QString() : d->description;
+}
+
+/*!
+ \qmlproperty bool QtMultimedia::audioDevice::isDefault
+
+ Is true if this is the default audio device.
+*/
+
+/*!
+ \property QAudioDevice::isDefault
+
+ Returns true if this is the default audio device.
+*/
+bool QAudioDevice::isDefault() const
+{
+ return d ? d->isDefault : false;
+}
+
+/*!
+ Returns true if the supplied \a settings are supported by the audio
+ device described by this QAudioDevice.
+*/
+bool QAudioDevice::isFormatSupported(const QAudioFormat &settings) const
+{
+ if (isNull())
+ return false;
+ if (settings.sampleRate() < d->minimumSampleRate
+ || settings.sampleRate() > d->maximumSampleRate)
+ return false;
+ if (settings.channelCount() < d->minimumChannelCount
+ || settings.channelCount() > d->maximumChannelCount)
+ return false;
+ if (!d->supportedSampleFormats.contains(settings.sampleFormat()))
+ return false;
+ return true;
+}
+
+/*!
+ Returns the default audio format settings for this device.
+
+ These settings are provided by the platform/audio plugin being used.
+
+ They are also dependent on the \l {QtAudio}::Mode being used.
+
+ A typical audio system would provide something like:
+ \list
+ \li Input settings: 48000Hz mono 16 bit.
+ \li Output settings: 48000Hz stereo 16 bit.
+ \endlist
+*/
+QAudioFormat QAudioDevice::preferredFormat() const
+{
+ return isNull() ? QAudioFormat() : d->preferredFormat;
+}
+
+/*!
+ Returns the minimum supported sample rate (in Hertz).
+*/
+int QAudioDevice::minimumSampleRate() const
+{
+ return isNull() ? 0 : d->minimumSampleRate;
+}
+
+/*!
+ Returns the maximum supported sample rate (in Hertz).
+*/
+int QAudioDevice::maximumSampleRate() const
+{
+ return isNull() ? 0 : d->maximumSampleRate;
+}
+
+/*!
+ Returns the minimum number of supported channel counts.
+
+ This is typically 1 for mono sound, or 2 for stereo sound.
+*/
+int QAudioDevice::minimumChannelCount() const
+{
+ return isNull() ? 0 : d->minimumChannelCount;
+}
+
+/*!
+ Returns the maximum number of supported channel counts.
+
+ This is typically 1 for mono sound, or 2 for stereo sound.
+*/
+int QAudioDevice::maximumChannelCount() const
+{
+ return isNull() ? 0 : d->maximumChannelCount;
+}
+
+/*!
+ Returns a list of supported sample types.
+*/
+QList<QAudioFormat::SampleFormat> QAudioDevice::supportedSampleFormats() const
+{
+ return isNull() ? QList<QAudioFormat::SampleFormat>() : d->supportedSampleFormats;
+}
+
+/*!
+ Returns the channel configuration of the device.
+*/
+QAudioFormat::ChannelConfig QAudioDevice::channelConfiguration() const
+{
+ return isNull() ? QAudioFormat::ChannelConfigUnknown : d->channelConfiguration;
+}
+
+/*!
+ \fn QAudioDevicePrivate QAudioDevice::handle() const
+ \internal
+*/
+/*!
+ \internal
+*/
+QAudioDevice::QAudioDevice(QAudioDevicePrivate *p) : d(p) { }
+
+/*!
+ \enum QAudioDevice::Mode
+
+ Describes the mode of this device.
+
+ \value Null
+ A null device.
+ \value Input
+ An input device.
+ \value Output
+ An output device.
+*/
+
+/*!
+ \qmlproperty enumeration QtMultimedia::audioDevice::mode
+
+ Holds whether this device is an input or output device.
+
+ The returned value can be one of the following:
+
+
+ \value audioDevice.Null A null device.
+ \value audioDevice.Input input device.
+ \value audioDevice.Output An output device.
+
+*/
+
+/*!
+ \property QAudioDevice::mode
+
+ Returns whether this device is an input or output device.
+*/
+QAudioDevice::Mode QAudioDevice::mode() const
+{
+ return d ? d->mode : Null;
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug dbg, QAudioDevice::Mode mode)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ switch (mode) {
+ case QAudioDevice::Input:
+ dbg << "QAudioDevice::Input";
+ break;
+ case QAudioDevice::Output:
+ dbg << "QAudioDevice::Output";
+ break;
+ case QAudioDevice::Null:
+ dbg << "QAudioDevice::Null";
+ break;
+ }
+ return dbg;
+}
+#endif
+
+QT_END_NAMESPACE
+
+#include "moc_qaudiodevice.cpp"
diff --git a/src/multimedia/audio/qaudiodevice.h b/src/multimedia/audio/qaudiodevice.h
new file mode 100644
index 000000000..abd1b654c
--- /dev/null
+++ b/src/multimedia/audio/qaudiodevice.h
@@ -0,0 +1,84 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#ifndef QAUDIODEVICEINFO_H
+#define QAUDIODEVICEINFO_H
+
+#include <QtCore/qobject.h>
+#include <QtCore/qbytearray.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qlist.h>
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+
+#include <QtMultimedia/qtaudio.h>
+#include <QtMultimedia/qaudioformat.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioDevicePrivate;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QAudioDevicePrivate, Q_MULTIMEDIA_EXPORT)
+
+class Q_MULTIMEDIA_EXPORT QAudioDevice
+{
+ Q_GADGET
+ Q_PROPERTY(QByteArray id READ id CONSTANT)
+ Q_PROPERTY(QString description READ description CONSTANT)
+ Q_PROPERTY(bool isDefault READ isDefault CONSTANT)
+ Q_PROPERTY(Mode mode READ mode CONSTANT)
+public:
+ enum Mode {
+ Null,
+ Input,
+ Output
+ };
+ Q_ENUM(Mode)
+
+ QAudioDevice();
+ QAudioDevice(const QAudioDevice& other);
+ ~QAudioDevice();
+
+ QAudioDevice(QAudioDevice &&other) noexcept = default;
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QAudioDevice)
+ void swap(QAudioDevice &other) noexcept
+ { d.swap(other.d); }
+
+ QAudioDevice& operator=(const QAudioDevice& other);
+
+ bool operator==(const QAudioDevice &other) const;
+ bool operator!=(const QAudioDevice &other) const;
+
+ bool isNull() const;
+
+ QByteArray id() const;
+ QString description() const;
+
+ bool isDefault() const;
+ QAudioDevice::Mode mode() const;
+
+ bool isFormatSupported(const QAudioFormat &format) const;
+ QAudioFormat preferredFormat() const;
+
+ int minimumSampleRate() const;
+ int maximumSampleRate() const;
+ int minimumChannelCount() const;
+ int maximumChannelCount() const;
+ QList<QAudioFormat::SampleFormat> supportedSampleFormats() const;
+ QAudioFormat::ChannelConfig channelConfiguration() const;
+
+ const QAudioDevicePrivate *handle() const { return d.get(); }
+private:
+ friend class QAudioDevicePrivate;
+ QAudioDevice(QAudioDevicePrivate *p);
+ QExplicitlySharedDataPointer<QAudioDevicePrivate> d;
+};
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, QAudioDevice::Mode mode);
+#endif
+
+QT_END_NAMESPACE
+
+#endif // QAUDIODEVICEINFO_H
diff --git a/src/multimedia/audio/qaudiodevice_p.h b/src/multimedia/audio/qaudiodevice_p.h
new file mode 100644
index 000000000..c59856d72
--- /dev/null
+++ b/src/multimedia/audio/qaudiodevice_p.h
@@ -0,0 +1,62 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#ifndef QAUDIODEVICEINFO_P_H
+#define QAUDIODEVICEINFO_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qaudiodevice.h>
+#include <QtCore/private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIA_EXPORT QAudioDevicePrivate : public QSharedData
+{
+public:
+ QAudioDevicePrivate(const QByteArray &i, QAudioDevice::Mode m)
+ : id(i),
+ mode(m)
+ {}
+ virtual ~QAudioDevicePrivate();
+ QByteArray id;
+ QAudioDevice::Mode mode = QAudioDevice::Output;
+ bool isDefault = false;
+
+ QAudioFormat preferredFormat;
+ QString description;
+ int minimumSampleRate = 0;
+ int maximumSampleRate = 0;
+ int minimumChannelCount = 0;
+ int maximumChannelCount = 0;
+ QList<QAudioFormat::SampleFormat> supportedSampleFormats;
+ QAudioFormat::ChannelConfig channelConfiguration = QAudioFormat::ChannelConfigUnknown;
+
+ bool operator == (const QAudioDevicePrivate &other) const
+ {
+ return id == other.id && mode == other.mode && isDefault == other.isDefault
+ && preferredFormat == other.preferredFormat && description == other.description
+ && minimumSampleRate == other.minimumSampleRate
+ && maximumSampleRate == other.maximumSampleRate
+ && minimumChannelCount == other.minimumChannelCount
+ && maximumChannelCount == other.maximumChannelCount
+ && supportedSampleFormats == other.supportedSampleFormats
+ && channelConfiguration == other.channelConfiguration;
+ }
+
+ QAudioDevice create() { return QAudioDevice(this); }
+};
+
+QT_END_NAMESPACE
+
+#endif // QAUDIODEVICEINFO_H
diff --git a/src/multimedia/audio/qaudiodevicefactory.cpp b/src/multimedia/audio/qaudiodevicefactory.cpp
deleted file mode 100644
index cf770c468..000000000
--- a/src/multimedia/audio/qaudiodevicefactory.cpp
+++ /dev/null
@@ -1,259 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qdebug.h>
-
-#include "qaudiosystem.h"
-#include "qaudiosystemplugin.h"
-#include "qaudiosystempluginext_p.h"
-
-#include "qmediapluginloader_p.h"
-#include "qaudiodevicefactory_p.h"
-
-QT_BEGIN_NAMESPACE
-
-static QString defaultKey()
-{
- return QStringLiteral("default");
-}
-
-#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
-Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, audioLoader,
- (QAudioSystemFactoryInterface_iid, QLatin1String("audio"), Qt::CaseInsensitive))
-#endif
-
-class QNullDeviceInfo : public QAbstractAudioDeviceInfo
-{
-public:
- QAudioFormat preferredFormat() const override { qWarning()<<"using null deviceinfo, none available"; return QAudioFormat(); }
- bool isFormatSupported(const QAudioFormat& ) const override { return false; }
- QAudioFormat nearestFormat(const QAudioFormat& ) const { return QAudioFormat(); }
- QString deviceName() const override { return QString(); }
- QStringList supportedCodecs() override { return QStringList(); }
- QList<int> supportedSampleRates() override { return QList<int>(); }
- QList<int> supportedChannelCounts() override { return QList<int>(); }
- QList<int> supportedSampleSizes() override { return QList<int>(); }
- QList<QAudioFormat::Endian> supportedByteOrders() override { return QList<QAudioFormat::Endian>(); }
- QList<QAudioFormat::SampleType> supportedSampleTypes() override { return QList<QAudioFormat::SampleType>(); }
-};
-
-class QNullInputDevice : public QAbstractAudioInput
-{
-public:
- void start(QIODevice*) override { qWarning()<<"using null input device, none available";}
- QIODevice *start() override { qWarning()<<"using null input device, none available"; return nullptr; }
- void stop() override {}
- void reset() override {}
- void suspend() override {}
- void resume() override {}
- int bytesReady() const override { return 0; }
- int periodSize() const override { return 0; }
- void setBufferSize(int ) override {}
- int bufferSize() const override { return 0; }
- void setNotifyInterval(int ) override {}
- int notifyInterval() const override { return 0; }
- qint64 processedUSecs() const override { return 0; }
- qint64 elapsedUSecs() const override { return 0; }
- QAudio::Error error() const override { return QAudio::OpenError; }
- QAudio::State state() const override { return QAudio::StoppedState; }
- void setFormat(const QAudioFormat&) override {}
- QAudioFormat format() const override { return QAudioFormat(); }
- void setVolume(qreal) override {}
- qreal volume() const override {return 1.0f;}
-};
-
-class QNullOutputDevice : public QAbstractAudioOutput
-{
-public:
- void start(QIODevice*) override {qWarning()<<"using null output device, none available";}
- QIODevice *start() override { qWarning()<<"using null output device, none available"; return nullptr; }
- void stop() override {}
- void reset() override {}
- void suspend() override {}
- void resume() override {}
- int bytesFree() const override { return 0; }
- int periodSize() const override { return 0; }
- void setBufferSize(int ) override {}
- int bufferSize() const override { return 0; }
- void setNotifyInterval(int ) override {}
- int notifyInterval() const override { return 0; }
- qint64 processedUSecs() const override { return 0; }
- qint64 elapsedUSecs() const override { return 0; }
- QAudio::Error error() const override { return QAudio::OpenError; }
- QAudio::State state() const override { return QAudio::StoppedState; }
- void setFormat(const QAudioFormat&) override {}
- QAudioFormat format() const override { return QAudioFormat(); }
-};
-
-QList<QAudioDeviceInfo> QAudioDeviceFactory::availableDevices(QAudio::Mode mode)
-{
- QList<QAudioDeviceInfo> devices;
-#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
- QMediaPluginLoader* l = audioLoader();
- const auto keys = l->keys();
- for (const QString& key : keys) {
- QAudioSystemFactoryInterface* plugin = qobject_cast<QAudioSystemFactoryInterface*>(l->instance(key));
- if (plugin) {
- const auto availableDevices = plugin->availableDevices(mode);
- for (const QByteArray& handle : availableDevices)
- devices << QAudioDeviceInfo(key, handle, mode);
- }
- }
-#endif
-
- return devices;
-}
-
-QAudioDeviceInfo QAudioDeviceFactory::defaultDevice(QAudio::Mode mode)
-{
-#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
- QMediaPluginLoader* l = audioLoader();
-
- // Check if there is a default plugin.
- QAudioSystemFactoryInterface *plugin = qobject_cast<QAudioSystemFactoryInterface *>(l->instance(defaultKey()));
- if (plugin) {
- // Check if the plugin has the extension interface.
- QAudioSystemPluginExtension *pluginExt = qobject_cast<QAudioSystemPluginExtension *>(l->instance(defaultKey()));
- // Ask for the default device.
- if (pluginExt) {
- const QByteArray &device = pluginExt->defaultDevice(mode);
- if (!device.isEmpty())
- return QAudioDeviceInfo(defaultKey(), device, mode);
- }
-
- // If there were no default devices, e.g., if the plugin did not implement the extent-ion interface,
- // then just pick the first device that's available.
- const auto &devices = plugin->availableDevices(mode);
- if (!devices.isEmpty())
- return QAudioDeviceInfo(defaultKey(), devices.first(), mode);
- }
-
- // If no plugin is marked as default, check the other plugins.
- // Note: We're going to prioritize plugins that report a default device.
- const auto &keys = l->keys();
- QAudioDeviceInfo fallbackDevice;
- for (const auto &key : keys) {
- if (key == defaultKey())
- continue;
- QAudioSystemFactoryInterface* plugin = qobject_cast<QAudioSystemFactoryInterface*>(l->instance(key));
- if (plugin) {
- // Check if the plugin has the extent-ion interface.
- QAudioSystemPluginExtension *pluginExt = qobject_cast<QAudioSystemPluginExtension *>(l->instance(key));
- if (pluginExt) {
- const QByteArray &device = pluginExt->defaultDevice(mode);
- if (!device.isEmpty())
- return QAudioDeviceInfo(key, device, mode);
- } else if (fallbackDevice.isNull()) {
- const auto &devices = plugin->availableDevices(mode);
- if (!devices.isEmpty())
- fallbackDevice = QAudioDeviceInfo(key, devices.first(), mode);
- }
- }
- }
-
-#endif
-
- return QAudioDeviceInfo();
-}
-
-QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode)
-{
- QAbstractAudioDeviceInfo *rc = nullptr;
-
-#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
- QAudioSystemFactoryInterface* plugin =
- qobject_cast<QAudioSystemFactoryInterface*>(audioLoader()->instance(realm));
-
- if (plugin)
- rc = plugin->createDeviceInfo(handle, mode);
-#endif
-
- return rc == nullptr ? new QNullDeviceInfo() : rc;
-}
-
-QAbstractAudioInput* QAudioDeviceFactory::createDefaultInputDevice(QAudioFormat const &format)
-{
- return createInputDevice(defaultDevice(QAudio::AudioInput), format);
-}
-
-QAbstractAudioOutput* QAudioDeviceFactory::createDefaultOutputDevice(QAudioFormat const &format)
-{
- return createOutputDevice(defaultDevice(QAudio::AudioOutput), format);
-}
-
-QAbstractAudioInput* QAudioDeviceFactory::createInputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format)
-{
- if (deviceInfo.isNull())
- return new QNullInputDevice();
-
-#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
- QAudioSystemFactoryInterface* plugin =
- qobject_cast<QAudioSystemFactoryInterface*>(audioLoader()->instance(deviceInfo.realm()));
-
- if (plugin) {
- QAbstractAudioInput* p = plugin->createInput(deviceInfo.handle());
- if (p) p->setFormat(format);
- return p;
- }
-#endif
-
- return new QNullInputDevice();
-}
-
-QAbstractAudioOutput* QAudioDeviceFactory::createOutputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format)
-{
- if (deviceInfo.isNull())
- return new QNullOutputDevice();
-
-#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
- QAudioSystemFactoryInterface* plugin =
- qobject_cast<QAudioSystemFactoryInterface*>(audioLoader()->instance(deviceInfo.realm()));
-
- if (plugin) {
- QAbstractAudioOutput* p = plugin->createOutput(deviceInfo.handle());
- if (p) p->setFormat(format);
- return p;
- }
-#endif
-
- return new QNullOutputDevice();
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/multimedia/audio/qaudiodevicefactory_p.h b/src/multimedia/audio/qaudiodevicefactory_p.h
deleted file mode 100644
index 238be46a7..000000000
--- a/src/multimedia/audio/qaudiodevicefactory_p.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifndef QAUDIODEVICEFACTORY_P_H
-#define QAUDIODEVICEFACTORY_P_H
-
-#include <QtCore/qbytearray.h>
-#include <QtCore/qlist.h>
-
-#include <qtmultimediaglobal.h>
-#include <qmultimedia.h>
-
-#include "qaudiodeviceinfo.h"
-
-QT_BEGIN_NAMESPACE
-
-
-class QAbstractAudioInput;
-class QAbstractAudioOutput;
-class QAbstractAudioDeviceInfo;
-
-class QAudioDeviceFactory
-{
-public:
- static QList<QAudioDeviceInfo> availableDevices(QAudio::Mode mode);
-
- static QAudioDeviceInfo defaultDevice(QAudio::Mode mode);
-
- static QAbstractAudioDeviceInfo* audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode);
-
- static QAbstractAudioInput* createDefaultInputDevice(QAudioFormat const &format);
- static QAbstractAudioOutput* createDefaultOutputDevice(QAudioFormat const &format);
-
- static QAbstractAudioInput* createInputDevice(QAudioDeviceInfo const &device, QAudioFormat const &format);
- static QAbstractAudioOutput* createOutputDevice(QAudioDeviceInfo const &device, QAudioFormat const &format);
-
- static QAbstractAudioInput* createNullInput();
- static QAbstractAudioOutput* createNullOutput();
-};
-
-QT_END_NAMESPACE
-
-#endif // QAUDIODEVICEFACTORY_P_H
-
diff --git a/src/multimedia/audio/qaudiodeviceinfo.cpp b/src/multimedia/audio/qaudiodeviceinfo.cpp
deleted file mode 100644
index 051ef8b3f..000000000
--- a/src/multimedia/audio/qaudiodeviceinfo.cpp
+++ /dev/null
@@ -1,476 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qaudiodevicefactory_p.h"
-#include "qaudiosystem.h"
-#include "qaudiodeviceinfo.h"
-
-#include <QtCore/qmap.h>
-
-QT_BEGIN_NAMESPACE
-
-static void qRegisterAudioDeviceInfoMetaTypes()
-{
- qRegisterMetaType<QAudioDeviceInfo>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterAudioDeviceInfoMetaTypes)
-
-class QAudioDeviceInfoPrivate : public QSharedData
-{
-public:
- QAudioDeviceInfoPrivate()
- : mode(QAudio::AudioOutput)
- , info(nullptr)
- {
- }
-
- QAudioDeviceInfoPrivate(const QString &r, const QByteArray &h, QAudio::Mode m):
- realm(r), handle(h), mode(m)
- {
- if (!handle.isEmpty())
- info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode);
- else
- info = nullptr;
- }
-
- QAudioDeviceInfoPrivate(const QAudioDeviceInfoPrivate &other):
- QSharedData(other),
- realm(other.realm), handle(other.handle), mode(other.mode)
- {
- info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode);
- }
-
- QAudioDeviceInfoPrivate& operator=(const QAudioDeviceInfoPrivate &other)
- {
- delete info;
-
- realm = other.realm;
- handle = other.handle;
- mode = other.mode;
- info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode);
- return *this;
- }
-
- ~QAudioDeviceInfoPrivate()
- {
- delete info;
- }
-
- QString realm;
- QByteArray handle;
- QAudio::Mode mode;
- QAbstractAudioDeviceInfo* info;
-};
-
-
-/*!
- \class QAudioDeviceInfo
- \brief The QAudioDeviceInfo class provides an interface to query audio devices and their functionality.
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_audio
-
- QAudioDeviceInfo lets you query for audio devices--such as sound
- cards and USB headsets--that are currently available on the system.
- The audio devices available are dependent on the platform or audio plugins installed.
-
- A QAudioDeviceInfo is used by Qt to construct
- classes that communicate with the device--such as
- QAudioInput, and QAudioOutput.
-
- You can also query each device for the formats it supports. A
- format in this context is a set consisting of a specific byte
- order, channel, codec, frequency, sample rate, and sample type. A
- format is represented by the QAudioFormat class.
-
- The values supported by the device for each of these
- parameters can be fetched with
- supportedByteOrders(), supportedChannelCounts(), supportedCodecs(),
- supportedSampleRates(), supportedSampleSizes(), and
- supportedSampleTypes(). The combinations supported are dependent on the platform,
- audio plugins installed and the audio device capabilities. If you need a
- specific format, you can check if
- the device supports it with isFormatSupported(), or fetch a
- supported format that is as close as possible to the format with
- nearestFormat(). For instance:
-
- \snippet multimedia-snippets/audio.cpp Setting audio format
-
- The static
- functions defaultInputDevice(), defaultOutputDevice(), and
- availableDevices() let you get a list of all available
- devices. Devices are fetched according to the value of mode
- this is specified by the \l {QAudio}::Mode enum.
- The QAudioDeviceInfo returned are only valid for the \l {QAudio}::Mode.
-
- For instance:
-
- \snippet multimedia-snippets/audio.cpp Dumping audio formats
-
- In this code sample, we loop through all devices that are able to output
- sound, i.e., play an audio stream in a supported format. For each device we
- find, we simply print the deviceName().
-
- \sa QAudioOutput, QAudioInput
-*/
-
-/*!
- Constructs an empty QAudioDeviceInfo object.
-*/
-QAudioDeviceInfo::QAudioDeviceInfo():
- d(new QAudioDeviceInfoPrivate)
-{
-}
-
-/*!
- Constructs a copy of \a other.
-*/
-QAudioDeviceInfo::QAudioDeviceInfo(const QAudioDeviceInfo& other):
- d(other.d)
-{
-}
-
-/*!
- Destroy this audio device info.
-*/
-QAudioDeviceInfo::~QAudioDeviceInfo()
-{
-}
-
-/*!
- Sets the QAudioDeviceInfo object to be equal to \a other.
-*/
-QAudioDeviceInfo& QAudioDeviceInfo::operator=(const QAudioDeviceInfo &other)
-{
- d = other.d;
- return *this;
-}
-
-/*!
- Returns true if this QAudioDeviceInfo class represents the
- same audio device as \a other.
-*/
-bool QAudioDeviceInfo::operator ==(const QAudioDeviceInfo &other) const
-{
- if (d == other.d)
- return true;
- if (d->realm == other.d->realm
- && d->mode == other.d->mode
- && d->handle == other.d->handle
- && deviceName() == other.deviceName())
- return true;
- return false;
-}
-
-/*!
- Returns true if this QAudioDeviceInfo class represents a
- different audio device than \a other
-*/
-bool QAudioDeviceInfo::operator !=(const QAudioDeviceInfo &other) const
-{
- return !operator==(other);
-}
-
-/*!
- Returns whether this QAudioDeviceInfo object holds a valid device definition.
-*/
-bool QAudioDeviceInfo::isNull() const
-{
- return d->info == nullptr;
-}
-
-/*!
- Returns the human readable name of the audio device.
-
- Device names vary depending on the platform/audio plugin being used.
-
- They are a unique string identifier for the audio device.
-
- eg. default, Intel, U0x46d0x9a4
-*/
-QString QAudioDeviceInfo::deviceName() const
-{
- return isNull() ? QString() : d->info->deviceName();
-}
-
-/*!
- Returns true if the supplied \a settings are supported by the audio
- device described by this QAudioDeviceInfo.
-*/
-bool QAudioDeviceInfo::isFormatSupported(const QAudioFormat &settings) const
-{
- return isNull() ? false : d->info->isFormatSupported(settings);
-}
-
-/*!
- Returns the default audio format settings for this device.
-
- These settings are provided by the platform/audio plugin being used.
-
- They are also dependent on the \l {QAudio}::Mode being used.
-
- A typical audio system would provide something like:
- \list
- \li Input settings: 8000Hz mono 8 bit.
- \li Output settings: 44100Hz stereo 16 bit little endian.
- \endlist
-*/
-QAudioFormat QAudioDeviceInfo::preferredFormat() const
-{
- return isNull() ? QAudioFormat() : d->info->preferredFormat();
-}
-
-/*!
- Returns the closest QAudioFormat to the supplied \a settings that the system supports.
-
- These settings are provided by the platform/audio plugin being used.
-
- They are also dependent on the \l {QAudio}::Mode being used.
-*/
-QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
-{
- if (isFormatSupported(settings))
- return settings;
-
- QAudioFormat nearest = settings;
-
- QList<QString> testCodecs = supportedCodecs();
- QList<int> testChannels = supportedChannelCounts();
- QList<QAudioFormat::Endian> testByteOrders = supportedByteOrders();
- QList<QAudioFormat::SampleType> testSampleTypes;
- QList<QAudioFormat::SampleType> sampleTypesAvailable = supportedSampleTypes();
- QMap<int,int> testSampleRates;
- QList<int> sampleRatesAvailable = supportedSampleRates();
- QMap<int,int> testSampleSizes;
- QList<int> sampleSizesAvailable = supportedSampleSizes();
-
- // Get sorted lists for checking
- if (testCodecs.contains(settings.codec())) {
- testCodecs.removeAll(settings.codec());
- testCodecs.insert(0, settings.codec());
- }
- testChannels.removeAll(settings.channelCount());
- testChannels.insert(0, settings.channelCount());
- testByteOrders.removeAll(settings.byteOrder());
- testByteOrders.insert(0, settings.byteOrder());
-
- if (sampleTypesAvailable.contains(settings.sampleType()))
- testSampleTypes.append(settings.sampleType());
- if (sampleTypesAvailable.contains(QAudioFormat::SignedInt))
- testSampleTypes.append(QAudioFormat::SignedInt);
- if (sampleTypesAvailable.contains(QAudioFormat::UnSignedInt))
- testSampleTypes.append(QAudioFormat::UnSignedInt);
- if (sampleTypesAvailable.contains(QAudioFormat::Float))
- testSampleTypes.append(QAudioFormat::Float);
-
- if (sampleSizesAvailable.contains(settings.sampleSize()))
- testSampleSizes.insert(0,settings.sampleSize());
- sampleSizesAvailable.removeAll(settings.sampleSize());
- for (int size : qAsConst(sampleSizesAvailable)) {
- int larger = (size > settings.sampleSize()) ? size : settings.sampleSize();
- int smaller = (size > settings.sampleSize()) ? settings.sampleSize() : size;
- bool isMultiple = ( 0 == (larger % smaller));
- int diff = larger - smaller;
- testSampleSizes.insert((isMultiple ? diff : diff+100000), size);
- }
- if (sampleRatesAvailable.contains(settings.sampleRate()))
- testSampleRates.insert(0,settings.sampleRate());
- sampleRatesAvailable.removeAll(settings.sampleRate());
- for (int sampleRate : qAsConst(sampleRatesAvailable)) {
- int larger = (sampleRate > settings.sampleRate()) ? sampleRate : settings.sampleRate();
- int smaller = (sampleRate > settings.sampleRate()) ? settings.sampleRate() : sampleRate;
- bool isMultiple = ( 0 == (larger % smaller));
- int diff = larger - smaller;
- testSampleRates.insert((isMultiple ? diff : diff+100000), sampleRate);
- }
-
- // Try to find nearest
- for (const QString &codec : qAsConst(testCodecs)) {
- nearest.setCodec(codec);
- for (QAudioFormat::Endian order : qAsConst(testByteOrders)) {
- nearest.setByteOrder(order);
- for (QAudioFormat::SampleType sample : qAsConst(testSampleTypes)) {
- nearest.setSampleType(sample);
- for (int sampleSize : qAsConst(testSampleSizes)) {
- nearest.setSampleSize(sampleSize);
- for (int channel : qAsConst(testChannels)) {
- nearest.setChannelCount(channel);
- for (int sampleRate : qAsConst(testSampleRates)) {
- nearest.setSampleRate(sampleRate);
- if (isFormatSupported(nearest))
- return nearest;
- }
- }
- }
- }
- }
- }
- //Fallback
- return preferredFormat();
-}
-
-/*!
- Returns a list of supported codecs.
-
- All platform and plugin implementations should provide support for:
-
- "audio/pcm" - Linear PCM
-
- For writing plugins to support additional codecs refer to:
-
- http://www.iana.org/assignments/media-types/audio/
-*/
-QStringList QAudioDeviceInfo::supportedCodecs() const
-{
- return isNull() ? QStringList() : d->info->supportedCodecs();
-}
-
-/*!
- Returns a list of supported sample rates (in Hertz).
-
-*/
-QList<int> QAudioDeviceInfo::supportedSampleRates() const
-{
- return isNull() ? QList<int>() : d->info->supportedSampleRates();
-}
-
-/*!
- Returns a list of supported channel counts.
-
- This is typically 1 for mono sound, or 2 for stereo sound.
-
-*/
-QList<int> QAudioDeviceInfo::supportedChannelCounts() const
-{
- return isNull() ? QList<int>() : d->info->supportedChannelCounts();
-}
-
-/*!
- Returns a list of supported sample sizes (in bits).
-
- Typically this will include 8 and 16 bit sample sizes.
-
-*/
-QList<int> QAudioDeviceInfo::supportedSampleSizes() const
-{
- return isNull() ? QList<int>() : d->info->supportedSampleSizes();
-}
-
-/*!
- Returns a list of supported byte orders.
-*/
-QList<QAudioFormat::Endian> QAudioDeviceInfo::supportedByteOrders() const
-{
- return isNull() ? QList<QAudioFormat::Endian>() : d->info->supportedByteOrders();
-}
-
-/*!
- Returns a list of supported sample types.
-*/
-QList<QAudioFormat::SampleType> QAudioDeviceInfo::supportedSampleTypes() const
-{
- return isNull() ? QList<QAudioFormat::SampleType>() : d->info->supportedSampleTypes();
-}
-
-/*!
- Returns the information for the default input audio device.
- All platform and audio plugin implementations provide a default audio device to use.
-*/
-QAudioDeviceInfo QAudioDeviceInfo::defaultInputDevice()
-{
- return QAudioDeviceFactory::defaultDevice(QAudio::AudioInput);
-}
-
-/*!
- Returns the information for the default output audio device.
- All platform and audio plugin implementations provide a default audio device to use.
-*/
-QAudioDeviceInfo QAudioDeviceInfo::defaultOutputDevice()
-{
- return QAudioDeviceFactory::defaultDevice(QAudio::AudioOutput);
-}
-
-/*!
- Returns a list of audio devices that support \a mode.
-*/
-QList<QAudioDeviceInfo> QAudioDeviceInfo::availableDevices(QAudio::Mode mode)
-{
- return QAudioDeviceFactory::availableDevices(mode);
-}
-
-
-/*!
- \internal
-*/
-QAudioDeviceInfo::QAudioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode):
- d(new QAudioDeviceInfoPrivate(realm, handle, mode))
-{
-}
-
-/*!
- Returns the key that represents the audio plugin.
-
- \since 5.14
- \sa QAudioSystemPlugin
-*/
-QString QAudioDeviceInfo::realm() const
-{
- return d->realm;
-}
-
-/*!
- \internal
-*/
-QByteArray QAudioDeviceInfo::handle() const
-{
- return d->handle;
-}
-
-
-/*!
- \internal
-*/
-QAudio::Mode QAudioDeviceInfo::mode() const
-{
- return d->mode;
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/multimedia/audio/qaudiodeviceinfo.h b/src/multimedia/audio/qaudiodeviceinfo.h
deleted file mode 100644
index 015c8bad7..000000000
--- a/src/multimedia/audio/qaudiodeviceinfo.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QAUDIODEVICEINFO_H
-#define QAUDIODEVICEINFO_H
-
-#include <QtCore/qobject.h>
-#include <QtCore/qbytearray.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qlist.h>
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
-
-#include <QtMultimedia/qaudio.h>
-#include <QtMultimedia/qaudioformat.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QAudioDeviceFactory;
-
-class QAudioDeviceInfoPrivate;
-class Q_MULTIMEDIA_EXPORT QAudioDeviceInfo
-{
- friend class QAudioDeviceFactory;
-
-public:
- QAudioDeviceInfo();
- QAudioDeviceInfo(const QAudioDeviceInfo& other);
- ~QAudioDeviceInfo();
-
- QAudioDeviceInfo& operator=(const QAudioDeviceInfo& other);
-
- bool operator==(const QAudioDeviceInfo &other) const;
- bool operator!=(const QAudioDeviceInfo &other) const;
-
- bool isNull() const;
-
- QString deviceName() const;
-
- bool isFormatSupported(const QAudioFormat &format) const;
- QAudioFormat preferredFormat() const;
- QAudioFormat nearestFormat(const QAudioFormat &format) const;
-
- QStringList supportedCodecs() const;
- QList<int> supportedSampleRates() const;
- QList<int> supportedChannelCounts() const;
- QList<int> supportedSampleSizes() const;
- QList<QAudioFormat::Endian> supportedByteOrders() const;
- QList<QAudioFormat::SampleType> supportedSampleTypes() const;
- QString realm() const;
-
- static QAudioDeviceInfo defaultInputDevice();
- static QAudioDeviceInfo defaultOutputDevice();
-
- static QList<QAudioDeviceInfo> availableDevices(QAudio::Mode mode);
-
-private:
- QAudioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode);
- QByteArray handle() const;
- QAudio::Mode mode() const;
-
- QSharedDataPointer<QAudioDeviceInfoPrivate> d;
-};
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QAudioDeviceInfo)
-
-#endif // QAUDIODEVICEINFO_H
diff --git a/src/multimedia/audio/qaudioformat.cpp b/src/multimedia/audio/qaudioformat.cpp
index be3561084..9f51759b5 100644
--- a/src/multimedia/audio/qaudioformat.cpp
+++ b/src/multimedia/audio/qaudioformat.cpp
@@ -1,99 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QDebug>
#include <qaudioformat.h>
-
+#include <qalgorithms.h>
QT_BEGIN_NAMESPACE
-static void qRegisterAudioFormatMetaTypes()
-{
- qRegisterMetaType<QAudioFormat>();
- qRegisterMetaType<QAudioFormat::SampleType>();
- qRegisterMetaType<QAudioFormat::Endian>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterAudioFormatMetaTypes)
-
-class QAudioFormatPrivate : public QSharedData
-{
-public:
- QAudioFormatPrivate()
- {
- sampleRate = -1;
- channels = -1;
- sampleSize = -1;
- byteOrder = QAudioFormat::Endian(QSysInfo::ByteOrder);
- sampleType = QAudioFormat::Unknown;
- }
-
- QAudioFormatPrivate(const QAudioFormatPrivate &other):
- QSharedData(other),
- codec(other.codec),
- byteOrder(other.byteOrder),
- sampleType(other.sampleType),
- sampleRate(other.sampleRate),
- channels(other.channels),
- sampleSize(other.sampleSize)
- {
- }
-
- QAudioFormatPrivate& operator=(const QAudioFormatPrivate &other)
- {
- codec = other.codec;
- byteOrder = other.byteOrder;
- sampleType = other.sampleType;
- sampleRate = other.sampleRate;
- channels = other.channels;
- sampleSize = other.sampleSize;
-
- return *this;
- }
-
- QString codec;
- QAudioFormat::Endian byteOrder;
- QAudioFormat::SampleType sampleType;
- int sampleRate;
- int channels;
- int sampleSize;
-};
-
/*!
\class QAudioFormat
\brief The QAudioFormat class stores audio stream parameter information.
@@ -102,15 +14,12 @@ public:
\ingroup multimedia
\ingroup multimedia_audio
- An audio format specifies how data in an audio stream is arranged,
- i.e, how the stream is to be interpreted. The encoding itself is
- specified by the codec() used for the stream.
+ An audio format specifies how data in a raw audio stream is arranged. For
+ example, how the stream is to be interpreted.
- In addition to the encoding, QAudioFormat contains other
- parameters that further specify how the audio sample data is arranged.
- These are the frequency, the number of channels, the sample size,
- the sample type, and the byte order. The following table describes
- these in more detail.
+ QAudioFormat contains parameters that specify how the audio sample data
+ is arranged. These are the frequency, the number of channels, and the
+ sample format. The following table describes these in more detail.
\table
\header
@@ -122,241 +31,231 @@ public:
\row
\li Number of channels
\li The number of audio channels (typically one for mono
- or two for stereo)
- \row
- \li Sample size
- \li How much data is stored in each sample (typically 8
- or 16 bits)
+ or two for stereo). These are the amount of consecutive
+ samples that together form one frame in the stream
\row
- \li Sample type
- \li Numerical representation of sample (typically signed integer,
- unsigned integer or float)
- \row
- \li Byte order
- \li Byte ordering of sample (typically little endian, big endian)
+ \li Sample format
+ \li The format of the audio samples in the stream
\endtable
- This class is typically used in conjunction with QAudioInput or
- QAudioOutput to allow you to specify the parameters of the audio
+ This class is used in conjunction with QAudioSource or
+ QAudioSink to allow you to specify the parameters of the audio
stream being read or written, or with QAudioBuffer when dealing with
samples in memory.
You can obtain audio formats compatible with the audio device used
- through functions in QAudioDeviceInfo. This class also lets you
+ through functions in QAudioDevice. This class also lets you
query available parameter values for a device, so that you can set
- the parameters yourself. See the \l QAudioDeviceInfo class
+ the parameters yourself. See the \l QAudioDevice class
description for details. You need to know the format of the audio
streams you wish to play or record.
- In the common case of interleaved linear PCM data, the codec will
- be "audio/pcm", and the samples for all channels will be interleaved.
+ Samples for all channels will be interleaved.
One sample for each channel for the same instant in time is referred
to as a frame in Qt Multimedia (and other places).
*/
/*!
- Construct a new audio format.
+ \fn QAudioFormat::QAudioFormat()
+
+ Constructs a new audio format.
Values are initialized as follows:
\list
- \li sampleRate() = -1
- \li channelCount() = -1
- \li sampleSize() = -1
- \li byteOrder() = QAudioFormat::Endian(QSysInfo::ByteOrder)
- \li sampleType() = QAudioFormat::Unknown
- \c codec() = ""
+ \li sampleRate() = 0
+ \li channelCount() = 0
+ \li sampleFormat() = QAudioFormat::Unknown
\endlist
*/
-QAudioFormat::QAudioFormat():
- d(new QAudioFormatPrivate)
-{
-}
/*!
+ \fn QAudioFormat::QAudioFormat(const QAudioFormat &other)
+
Construct a new audio format using \a other.
*/
-QAudioFormat::QAudioFormat(const QAudioFormat &other):
- d(other.d)
-{
-}
/*!
+ \fn QAudioFormat::~QAudioFormat()
+
Destroy this audio format.
*/
-QAudioFormat::~QAudioFormat()
-{
-}
/*!
- Assigns \a other to this QAudioFormat implementation.
+ \fn bool QAudioFormat::operator==(const QAudioFormat &a, const QAudioFormat &b)
+
+ Returns \c true if audio format \a a is equal to \a b, otherwise returns \c false.
*/
-QAudioFormat& QAudioFormat::operator=(const QAudioFormat &other)
-{
- d = other.d;
- return *this;
-}
/*!
- Returns true if this QAudioFormat is equal to the \a other
- QAudioFormat; otherwise returns false.
+ \fn bool QAudioFormat::operator!=(const QAudioFormat &a, const QAudioFormat &b)
- All elements of QAudioFormat are used for the comparison.
+ Returns \c true if audio format \a a is not equal to \a b, otherwise returns \c false.
*/
-bool QAudioFormat::operator==(const QAudioFormat &other) const
-{
- return d->sampleRate == other.d->sampleRate &&
- d->channels == other.d->channels &&
- d->sampleSize == other.d->sampleSize &&
- d->byteOrder == other.d->byteOrder &&
- d->codec == other.d->codec &&
- d->sampleType == other.d->sampleType;
-}
/*!
- Returns true if this QAudioFormat is not equal to the \a other
- QAudioFormat; otherwise returns false.
+ \fn bool QAudioFormat::isValid() const
- All elements of QAudioFormat are used for the comparison.
+ Returns \c true if all of the parameters are valid.
*/
-bool QAudioFormat::operator!=(const QAudioFormat& other) const
-{
- return !(*this == other);
-}
/*!
- Returns true if all of the parameters are valid.
+ \fn void QAudioFormat::setSampleRate(int samplerate)
+
+ Sets the sample rate to \a samplerate in Hertz.
*/
-bool QAudioFormat::isValid() const
-{
- return d->sampleRate != -1 && d->channels != -1 && d->sampleSize != -1 &&
- d->sampleType != QAudioFormat::Unknown && !d->codec.isEmpty();
-}
/*!
- Sets the sample rate to \a samplerate Hertz.
+ \fn int QAudioFormat::sampleRate() const
+ Returns the current sample rate in Hertz.
*/
-void QAudioFormat::setSampleRate(int samplerate)
-{
- d->sampleRate = samplerate;
-}
/*!
- Returns the current sample rate in Hertz.
-
+ \enum QAudioFormat::AudioChannelPosition
+
+ Describes the possible audio channel positions. These follow the standard
+ definition used in the 22.2 surround sound configuration.
+
+ \value UnknownPosition Unknown position
+ \value FrontLeft
+ \value FrontRight
+ \value FrontCenter
+ \value LFE Low Frequency Effect channel (Subwoofer)
+ \value BackLeft
+ \value BackRight
+ \value FrontLeftOfCenter
+ \value FrontRightOfCenter
+ \value BackCenter
+ \value LFE2
+ \value SideLeft
+ \value SideRight
+ \value TopFrontLeft
+ \value TopFrontRight
+ \value TopFrontCenter
+ \value TopCenter
+ \value TopBackLeft
+ \value TopBackRight
+ \value TopSideLeft
+ \value TopSideRight
+ \value TopBackCenter
+ \value BottomFrontCenter
+ \value BottomFrontLeft
+ \value BottomFrontRight
*/
-int QAudioFormat::sampleRate() const
-{
- return d->sampleRate;
-}
-
/*!
- Sets the channel count to \a channels.
-
+ \variable QAudioFormat::NChannelPositions
+ \internal
*/
-void QAudioFormat::setChannelCount(int channels)
-{
- d->channels = channels;
-}
/*!
- Returns the current channel count value.
-
+ \enum QAudioFormat::ChannelConfig
+
+ This enum describes a standardized audio channel layout. The most common
+ configurations are Mono, Stereo, 2.1 (stereo plus low frequency), 5.1 surround,
+ and 7.1 surround configurations.
+
+ \value ChannelConfigUnknown The channel configuration is not known.
+ \value ChannelConfigMono The audio has one Center channel.
+ \value ChannelConfigStereo The audio has two channels, Left and Right.
+ \value ChannelConfig2Dot1 The audio has three channels, Left, Right and
+ LFE (low frequency effect).
+ \value ChannelConfig3Dot0 The audio has three channels, Left, Right, and
+ Center.
+ \value ChannelConfig3Dot1 The audio has four channels, Left, Right, Center,
+ and LFE (low frequency effect).
+ \value ChannelConfigSurround5Dot0 The audio has five channels, Left, Right,
+ Center, BackLeft, and BackRight.
+ \value ChannelConfigSurround5Dot1 The audio has 6 channels, Left, Right,
+ Center, LFE, BackLeft, and BackRight.
+ \value ChannelConfigSurround7Dot0 The audio has 7 channels, Left, Right,
+ Center, BackLeft, BackRight, SideLeft, and SideRight.
+ \value ChannelConfigSurround7Dot1 The audio has 8 channels, Left, Right,
+ Center, LFE, BackLeft, BackRight, SideLeft, and SideRight.
*/
-int QAudioFormat::channelCount() const
-{
- return d->channels;
-}
/*!
- Sets the sample size to the \a sampleSize specified, in bits.
+ Sets the channel configuration to \a config.
+
+ Sets the channel configuration of the audio format to one of the standard
+ audio channel configurations.
- This is typically 8 or 16, but some systems may support higher sample sizes.
+ \note that this will also modify the channel count.
*/
-void QAudioFormat::setSampleSize(int sampleSize)
+void QAudioFormat::setChannelConfig(ChannelConfig config) noexcept
{
- d->sampleSize = sampleSize;
+ m_channelConfig = config;
+ if (config != ChannelConfigUnknown)
+ m_channelCount = qPopulationCount(config);
}
/*!
- Returns the current sample size value, in bits.
-
- \sa bytesPerFrame()
+ Returns the position of a certain audio \a channel inside an audio frame
+ for the given format.
+ Returns -1 if the channel does not exist for this format or the channel
+ configuration is unknown.
*/
-int QAudioFormat::sampleSize() const
+int QAudioFormat::channelOffset(AudioChannelPosition channel) const noexcept
{
- return d->sampleSize;
+ if (!(m_channelConfig & (1u << channel)))
+ return -1;
+
+ uint maskedChannels = m_channelConfig & ((1u << channel) - 1);
+ return qPopulationCount(maskedChannels);
}
/*!
- Sets the codec to \a codec.
-
- The parameter to this function should be one of the types
- reported by the QAudioDeviceInfo::supportedCodecs() function
- for the audio device you are working with.
+ \fn void QAudioFormat::setChannelCount(int channels)
- \sa QAudioDeviceInfo::supportedCodecs()
+ Sets the channel count to \a channels. Setting this also sets the channel
+ config to ChannelConfigUnknown.
*/
-void QAudioFormat::setCodec(const QString &codec)
-{
- d->codec = codec;
-}
/*!
- Returns the current codec identifier.
+ \fn template <typename... Args> QAudioFormat::ChannelConfig QAudioFormat::channelConfig(Args... channels)
- \sa QAudioDeviceInfo::supportedCodecs()
+ Returns the current channel configuration for the given \a channels.
*/
-QString QAudioFormat::codec() const
-{
- return d->codec;
-}
-
/*!
- Sets the byteOrder to \a byteOrder.
+ \fn QAudioFormat::ChannelConfig QAudioFormat::channelConfig() const noexcept
+
+ Returns the current channel configuration.
*/
-void QAudioFormat::setByteOrder(QAudioFormat::Endian byteOrder)
-{
- d->byteOrder = byteOrder;
-}
/*!
- Returns the current byteOrder value.
+ \fn int QAudioFormat::channelCount() const
+
+ Returns the current channel count value.
+
*/
-QAudioFormat::Endian QAudioFormat::byteOrder() const
-{
- return d->byteOrder;
-}
/*!
- Sets the sampleType to \a sampleType.
+ \fn void QAudioFormat::setSampleFormat(SampleFormat format)
+
+ Sets the sample format to \a format.
+
+ \sa QAudioFormat::SampleFormat
*/
-void QAudioFormat::setSampleType(QAudioFormat::SampleType sampleType)
-{
- d->sampleType = sampleType;
-}
/*!
- Returns the current SampleType value.
+ \fn QAudioFormat::SampleFormat QAudioFormat::sampleFormat() const
+ Returns the current sample format.
+
+ \sa setSampleFormat()
*/
-QAudioFormat::SampleType QAudioFormat::sampleType() const
-{
- return d->sampleType;
-}
/*!
- Returns the number of bytes required for this audio format for \a duration microseconds.
+ Returns the number of bytes required for this audio format for \a microseconds.
Returns 0 if this format is not valid.
- Note that some rounding may occur if \a duration is not an exact fraction of the
+ Note that some rounding may occur if \a microseconds is not an exact fraction of the
sampleRate().
\sa durationForBytes()
*/
-qint32 QAudioFormat::bytesForDuration(qint64 duration) const
+qint32 QAudioFormat::bytesForDuration(qint64 microseconds) const
{
- return bytesPerFrame() * framesForDuration(duration);
+ return bytesPerFrame() * framesForDuration(microseconds);
}
/*!
@@ -371,6 +270,10 @@ qint32 QAudioFormat::bytesForDuration(qint64 duration) const
*/
qint64 QAudioFormat::durationForBytes(qint32 bytes) const
{
+ // avoid compiler warnings about unused variables. [[maybe_unused]] in the header
+ // gives compiler errors on older gcc versions
+ Q_UNUSED(reserved);
+
if (!isValid() || bytes <= 0)
return 0;
@@ -409,17 +312,17 @@ qint32 QAudioFormat::framesForBytes(qint32 byteCount) const
}
/*!
- Returns the number of frames required to represent \a duration microseconds in this format.
+ Returns the number of frames required to represent \a microseconds in this format.
- Note that some rounding may occur if \a duration is not an exact fraction of the
+ Note that some rounding may occur if \a microseconds is not an exact fraction of the
\l sampleRate().
*/
-qint32 QAudioFormat::framesForDuration(qint64 duration) const
+qint32 QAudioFormat::framesForDuration(qint64 microseconds) const
{
if (!isValid())
return 0;
- return qint32((duration * sampleRate()) / 1000000LL);
+ return qint32((microseconds * sampleRate()) / 1000000LL);
}
/*!
@@ -434,85 +337,142 @@ qint64 QAudioFormat::durationForFrames(qint32 frameCount) const
}
/*!
- Returns the number of bytes required to represent one frame (a sample in each channel) in this format.
+ \fn int QAudioFormat::bytesPerFrame() const
+
+ Returns the number of bytes required to represent one frame
+ (a sample in each channel) in this format.
Returns 0 if this format is invalid.
*/
-int QAudioFormat::bytesPerFrame() const
-{
- if (!isValid())
- return 0;
-
- return (sampleSize() * channelCount()) / 8;
-}
/*!
- \enum QAudioFormat::SampleType
+ \fn int QAudioFormat::bytesPerSample() const
+ Returns the number of bytes required to represent one sample in this format.
- \value Unknown Not Set
- \value SignedInt Samples are signed integers
- \value UnSignedInt Samples are unsigned intergers
- \value Float Samples are floats
+ Returns 0 if this format is invalid.
*/
/*!
- \enum QAudioFormat::Endian
-
- \value BigEndian Samples are big endian byte order
- \value LittleEndian Samples are little endian byte order
+ Normalizes the \a sample value to a number between -1 and 1.
+ The method depends on the QaudioFormat.
*/
+float QAudioFormat::normalizedSampleValue(const void *sample) const
+{
+ switch (m_sampleFormat) {
+ case UInt8:
+ return ((float)*reinterpret_cast<const quint8 *>(sample))
+ / (float)std::numeric_limits<qint8>::max()
+ - 1.;
+ case Int16:
+ return ((float)*reinterpret_cast<const qint16 *>(sample))
+ / (float)std::numeric_limits<qint16>::max();
+ case Int32:
+ return ((float)*reinterpret_cast<const qint32 *>(sample))
+ / (float)std::numeric_limits<qint32>::max();
+ case Float:
+ return *reinterpret_cast<const float *>(sample);
+ case Unknown:
+ case NSampleFormats:
+ break;
+ }
-#ifndef QT_NO_DEBUG_STREAM
-QDebug operator<<(QDebug dbg, QAudioFormat::Endian endian)
+ return 0.;
+}
+
+/*!
+ Returns a default channel configuration for \a channelCount.
+
+ Default configurations are defined for up to 8 channels, and correspond to
+ standard Mono, Stereo and Surround configurations. For higher channel counts,
+ this simply uses the first \a channelCount audio channels defined in
+ \l QAudioFormat::AudioChannelPosition.
+*/
+QAudioFormat::ChannelConfig QAudioFormat::defaultChannelConfigForChannelCount(int channelCount)
{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (endian) {
- case QAudioFormat::BigEndian:
- dbg << "BigEndian";
- break;
- case QAudioFormat::LittleEndian:
- dbg << "LittleEndian";
- break;
+ QAudioFormat::ChannelConfig config;
+ switch (channelCount) {
+ case 0:
+ config = QAudioFormat::ChannelConfigUnknown;
+ break;
+ case 1:
+ config = QAudioFormat::ChannelConfigMono;
+ break;
+ case 2:
+ config = QAudioFormat::ChannelConfigStereo;
+ break;
+ case 3:
+ config = QAudioFormat::ChannelConfig2Dot1;
+ break;
+ case 4:
+ config = QAudioFormat::channelConfig(QAudioFormat::FrontLeft, QAudioFormat::FrontRight,
+ QAudioFormat::BackLeft, QAudioFormat::BackRight);
+ break;
+ case 5:
+ config = QAudioFormat::ChannelConfigSurround5Dot0;
+ break;
+ case 6:
+ config = QAudioFormat::ChannelConfigSurround5Dot1;
+ break;
+ case 7:
+ config = QAudioFormat::ChannelConfigSurround7Dot0;
+ break;
+ case 8:
+ config = QAudioFormat::ChannelConfigSurround7Dot1;
+ break;
+ default:
+ // give up, simply use the first n channels
+ config = QAudioFormat::ChannelConfig((1 << (channelCount + 1)) - 1);
}
- return dbg;
+ return config;
}
-QDebug operator<<(QDebug dbg, QAudioFormat::SampleType type)
+/*!
+ \enum QAudioFormat::SampleFormat
+
+ Qt will always expect and use samples in the endianness of the host platform.
+ When processing audio data from external sources yourself, ensure you convert
+ them to the correct endianness before writing them to a QAudioSink or
+ QAudioBuffer.
+
+ \value Unknown Not Set
+ \value UInt8 Samples are 8 bit unsigned integers
+ \value Int16 Samples are 16 bit signed integers
+ \value Int32 Samples are 32 bit signed integers
+ \value Float Samples are floats
+ \omitvalue NSampleFormats
+*/
+
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug dbg, QAudioFormat::SampleFormat type)
{
QDebugStateSaver saver(dbg);
dbg.nospace();
switch (type) {
- case QAudioFormat::SignedInt:
- dbg << "SignedInt";
- break;
- case QAudioFormat::UnSignedInt:
- dbg << "UnSignedInt";
- break;
- case QAudioFormat::Float:
- dbg << "Float";
- break;
- default:
- dbg << "Unknown";
- break;
+ case QAudioFormat::UInt8:
+ dbg << "UInt8";
+ break;
+ case QAudioFormat::Int16:
+ dbg << "Int16";
+ break;
+ case QAudioFormat::Int32:
+ dbg << "Int32";
+ break;
+ case QAudioFormat::Float:
+ dbg << "Float";
+ break;
+ default:
+ dbg << "Unknown";
+ break;
}
return dbg;
}
QDebug operator<<(QDebug dbg, const QAudioFormat &f)
{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- dbg << "QAudioFormat(" << f.sampleRate() << "Hz, "
- << f.sampleSize() << "bit, channelCount=" << f.channelCount()
- << ", sampleType=" << f.sampleType() << ", byteOrder=" << f.byteOrder()
- << ", codec=" << f.codec() << ')';
-
+ dbg << "QAudioFormat(" << f.sampleRate() << "Hz, " << f.channelCount() << "Channels, "
+ << f.sampleFormat() << "Format )";
return dbg;
}
#endif
-
-
QT_END_NAMESPACE
-
diff --git a/src/multimedia/audio/qaudioformat.h b/src/multimedia/audio/qaudioformat.h
index 97779ea2c..a04ab6e1a 100644
--- a/src/multimedia/audio/qaudioformat.h
+++ b/src/multimedia/audio/qaudioformat.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QAUDIOFORMAT_H
@@ -45,72 +9,152 @@
#include <QtCore/qshareddata.h>
#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
QT_BEGIN_NAMESPACE
class QAudioFormatPrivate;
-class Q_MULTIMEDIA_EXPORT QAudioFormat
+namespace QtPrivate {
+template <typename... Args>
+constexpr int channelConfig(Args... values) {
+ return (0 | ... | (1u << values));
+}
+}
+
+class QAudioFormat
{
public:
- enum SampleType { Unknown, SignedInt, UnSignedInt, Float };
- enum Endian { BigEndian = QSysInfo::BigEndian, LittleEndian = QSysInfo::LittleEndian };
-
- QAudioFormat();
- QAudioFormat(const QAudioFormat &other);
- ~QAudioFormat();
-
- QAudioFormat& operator=(const QAudioFormat &other);
- bool operator==(const QAudioFormat &other) const;
- bool operator!=(const QAudioFormat &other) const;
-
- bool isValid() const;
-
- void setSampleRate(int sampleRate);
- int sampleRate() const;
-
- void setChannelCount(int channelCount);
- int channelCount() const;
-
- void setSampleSize(int sampleSize);
- int sampleSize() const;
-
- void setCodec(const QString &codec);
- QString codec() const;
-
- void setByteOrder(QAudioFormat::Endian byteOrder);
- QAudioFormat::Endian byteOrder() const;
-
- void setSampleType(QAudioFormat::SampleType sampleType);
- QAudioFormat::SampleType sampleType() const;
+ enum SampleFormat : quint16 {
+ Unknown,
+ UInt8,
+ Int16,
+ Int32,
+ Float,
+ NSampleFormats
+ };
+
+ // This matches the speaker positions of a 22.2 audio layout. Stereo, Surround 5.1 and Surround 7.1 are subsets of these
+ enum AudioChannelPosition {
+ UnknownPosition,
+ FrontLeft,
+ FrontRight,
+ FrontCenter,
+ LFE,
+ BackLeft,
+ BackRight,
+ FrontLeftOfCenter,
+ FrontRightOfCenter,
+ BackCenter,
+ SideLeft,
+ SideRight,
+ TopCenter,
+ TopFrontLeft,
+ TopFrontCenter,
+ TopFrontRight,
+ TopBackLeft,
+ TopBackCenter,
+ TopBackRight,
+ LFE2,
+ TopSideLeft,
+ TopSideRight,
+ BottomFrontCenter,
+ BottomFrontLeft,
+ BottomFrontRight
+ };
+ static constexpr int NChannelPositions = BottomFrontRight + 1;
+
+ enum ChannelConfig : quint32 {
+ ChannelConfigUnknown = 0,
+ ChannelConfigMono = QtPrivate::channelConfig(FrontCenter),
+ ChannelConfigStereo = QtPrivate::channelConfig(FrontLeft, FrontRight),
+ ChannelConfig2Dot1 = QtPrivate::channelConfig(FrontLeft, FrontRight, LFE),
+ ChannelConfig3Dot0 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter),
+ ChannelConfig3Dot1 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE),
+ ChannelConfigSurround5Dot0 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, BackLeft, BackRight),
+ ChannelConfigSurround5Dot1 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE, BackLeft, BackRight),
+ ChannelConfigSurround7Dot0 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, BackLeft, BackRight, SideLeft, SideRight),
+ ChannelConfigSurround7Dot1 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE, BackLeft, BackRight, SideLeft, SideRight),
+ };
+
+ template <typename... Args>
+ static constexpr ChannelConfig channelConfig(Args... channels)
+ {
+ return ChannelConfig(QtPrivate::channelConfig(channels...));
+ }
+
+ constexpr bool isValid() const noexcept
+ {
+ return m_sampleRate > 0 && m_channelCount > 0 && m_sampleFormat != Unknown;
+ }
+
+ constexpr void setSampleRate(int sampleRate) noexcept { m_sampleRate = sampleRate; }
+ constexpr int sampleRate() const noexcept { return m_sampleRate; }
+
+ Q_MULTIMEDIA_EXPORT void setChannelConfig(ChannelConfig config) noexcept;
+ constexpr ChannelConfig channelConfig() const noexcept { return m_channelConfig; }
+
+ constexpr void setChannelCount(int channelCount) noexcept { m_channelConfig = ChannelConfigUnknown; m_channelCount = channelCount; }
+ constexpr int channelCount() const noexcept { return m_channelCount; }
+
+ Q_MULTIMEDIA_EXPORT int channelOffset(AudioChannelPosition channel) const noexcept;
+
+ constexpr void setSampleFormat(SampleFormat f) noexcept { m_sampleFormat = f; }
+ constexpr SampleFormat sampleFormat() const noexcept { return m_sampleFormat; }
// Helper functions
- qint32 bytesForDuration(qint64 duration) const;
- qint64 durationForBytes(qint32 byteCount) const;
-
- qint32 bytesForFrames(qint32 frameCount) const;
- qint32 framesForBytes(qint32 byteCount) const;
-
- qint32 framesForDuration(qint64 duration) const;
- qint64 durationForFrames(qint32 frameCount) const;
-
- int bytesPerFrame() const;
+ Q_MULTIMEDIA_EXPORT qint32 bytesForDuration(qint64 microseconds) const;
+ Q_MULTIMEDIA_EXPORT qint64 durationForBytes(qint32 byteCount) const;
+
+ Q_MULTIMEDIA_EXPORT qint32 bytesForFrames(qint32 frameCount) const;
+ Q_MULTIMEDIA_EXPORT qint32 framesForBytes(qint32 byteCount) const;
+
+ Q_MULTIMEDIA_EXPORT qint32 framesForDuration(qint64 microseconds) const;
+ Q_MULTIMEDIA_EXPORT qint64 durationForFrames(qint32 frameCount) const;
+
+ constexpr int bytesPerFrame() const { return bytesPerSample()*channelCount(); }
+ constexpr int bytesPerSample() const noexcept
+ {
+ switch (m_sampleFormat) {
+ case Unknown:
+ case NSampleFormats: return 0;
+ case UInt8: return 1;
+ case Int16: return 2;
+ case Int32:
+ case Float: return 4;
+ }
+ return 0;
+ }
+
+ Q_MULTIMEDIA_EXPORT float normalizedSampleValue(const void *sample) const;
+
+ friend bool operator==(const QAudioFormat &a, const QAudioFormat &b)
+ {
+ return a.m_sampleRate == b.m_sampleRate &&
+ a.m_channelCount == b.m_channelCount &&
+ a.m_sampleFormat == b.m_sampleFormat;
+ }
+ friend bool operator!=(const QAudioFormat &a, const QAudioFormat &b)
+ {
+ return !(a == b);
+ }
+
+ static Q_MULTIMEDIA_EXPORT ChannelConfig defaultChannelConfigForChannelCount(int channelCount);
private:
- QSharedDataPointer<QAudioFormatPrivate> d;
+ SampleFormat m_sampleFormat = SampleFormat::Unknown;
+ short m_channelCount = 0;
+ ChannelConfig m_channelConfig = ChannelConfigUnknown;
+ int m_sampleRate = 0;
+ quint64 reserved = 0;
};
#ifndef QT_NO_DEBUG_STREAM
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QAudioFormat &);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QAudioFormat::SampleType);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QAudioFormat::Endian);
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QAudioFormat::SampleFormat);
#endif
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QAudioFormat)
-Q_DECLARE_METATYPE(QAudioFormat::SampleType)
-Q_DECLARE_METATYPE(QAudioFormat::Endian)
#endif // QAUDIOFORMAT_H
diff --git a/src/multimedia/audio/qaudiohelpers.cpp b/src/multimedia/audio/qaudiohelpers.cpp
index fae591477..c2d8681c6 100644
--- a/src/multimedia/audio/qaudiohelpers.cpp
+++ b/src/multimedia/audio/qaudiohelpers.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qaudiohelpers_p.h"
@@ -43,49 +7,6 @@
QT_BEGIN_NAMESPACE
-// Base implementation of 24 bits number.
-// Used to adjust 3 bytes values by a factor.
-// TODO: Uses little-endian only.
-class Int24
-{
-public:
- quint8 data[3];
- Int24(qint32 v) {
- data[0] = v & 0xFF;
- data[1] = (v & 0xFF00) >> 8;
- data[2] = (v & 0xFF0000) >> 16;
- }
- template<class T>
- T multiply(qreal factor, T v = 0) const {
- v |= data[0];
- v |= data[1] << 8;
- v |= data[2] << 16;
- v *= factor;
- return v;
- }
-};
-
-class qint24: public Int24
-{
-public:
- qint24(qint32 v): Int24(v) {}
- qint24 operator*(qreal factor) const {
- // Checks if it is a signed value.
- qint32 v = (data[2] & 0x80) ? 0xFF000000 : 0;
- return multiply(factor, v);
- }
-};
-
-class quint24: public Int24
-{
-public:
- quint24(quint32 v): Int24(v) {}
- quint24 operator*(qreal factor) const {
- return multiply<quint32>(factor);
- }
-};
-
-
namespace QAudioHelperInternal
{
@@ -102,20 +23,8 @@ template<class T> void adjustSamples(qreal factor, const void *src, void *dst, i
template<class T> struct signedVersion {};
template<> struct signedVersion<quint8>
{
- typedef qint8 TS;
- enum {offset = 0x80};
-};
-
-template<> struct signedVersion<quint16>
-{
- typedef qint16 TS;
- enum {offset = 0x8000};
-};
-
-template<> struct signedVersion<quint32>
-{
- typedef qint32 TS;
- enum {offset = 0x80000000};
+ using TS = qint8;
+ static constexpr int offset = 0x80;
};
template<class T> void adjustUnsignedSamples(qreal factor, const void *src, void *dst, int samples)
@@ -129,34 +38,24 @@ template<class T> void adjustUnsignedSamples(qreal factor, const void *src, void
void qMultiplySamples(qreal factor, const QAudioFormat &format, const void* src, void* dest, int len)
{
- int samplesCount = len / (format.sampleSize()/8);
+ const int samplesCount = len / qMax(1, format.bytesPerSample());
- switch ( format.sampleSize() ) {
- case 8:
- if (format.sampleType() == QAudioFormat::SignedInt)
- QAudioHelperInternal::adjustSamples<qint8>(factor,src,dest,samplesCount);
- else if (format.sampleType() == QAudioFormat::UnSignedInt)
- QAudioHelperInternal::adjustUnsignedSamples<quint8>(factor,src,dest,samplesCount);
+ switch (format.sampleFormat()) {
+ case QAudioFormat::Unknown:
+ case QAudioFormat::NSampleFormats:
+ return;
+ case QAudioFormat::UInt8:
+ QAudioHelperInternal::adjustUnsignedSamples<quint8>(factor,src,dest,samplesCount);
+ break;
+ case QAudioFormat::Int16:
+ QAudioHelperInternal::adjustSamples<qint16>(factor,src,dest,samplesCount);
break;
- case 16:
- if (format.sampleType() == QAudioFormat::SignedInt)
- QAudioHelperInternal::adjustSamples<qint16>(factor,src,dest,samplesCount);
- else if (format.sampleType() == QAudioFormat::UnSignedInt)
- QAudioHelperInternal::adjustUnsignedSamples<quint16>(factor,src,dest,samplesCount);
+ case QAudioFormat::Int32:
+ QAudioHelperInternal::adjustSamples<qint32>(factor,src,dest,samplesCount);
break;
- case 24:
- if (format.sampleType() == QAudioFormat::SignedInt)
- QAudioHelperInternal::adjustSamples<qint24>(factor,src,dest,samplesCount);
- else if (format.sampleType() == QAudioFormat::UnSignedInt)
- QAudioHelperInternal::adjustSamples<quint24>(factor,src,dest,samplesCount);
+ case QAudioFormat::Float:
+ QAudioHelperInternal::adjustSamples<float>(factor,src,dest,samplesCount);
break;
- default:
- if (format.sampleType() == QAudioFormat::SignedInt)
- QAudioHelperInternal::adjustSamples<qint32>(factor,src,dest,samplesCount);
- else if (format.sampleType() == QAudioFormat::UnSignedInt)
- QAudioHelperInternal::adjustUnsignedSamples<quint32>(factor,src,dest,samplesCount);
- else if (format.sampleType() == QAudioFormat::Float)
- QAudioHelperInternal::adjustSamples<float>(factor,src,dest,samplesCount);
}
}
}
diff --git a/src/multimedia/audio/qaudiohelpers_p.h b/src/multimedia/audio/qaudiohelpers_p.h
index c59e01cad..81e6c6382 100644
--- a/src/multimedia/audio/qaudiohelpers_p.h
+++ b/src/multimedia/audio/qaudiohelpers_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QAUDIOHELPERS_H
#define QAUDIOHELPERS_H
@@ -52,6 +16,7 @@
//
#include <qaudioformat.h>
+#include <private/qglobal_p.h>
QT_BEGIN_NAMESPACE
diff --git a/src/multimedia/audio/qaudioinput.cpp b/src/multimedia/audio/qaudioinput.cpp
index 872dce819..dc7d7335f 100644
--- a/src/multimedia/audio/qaudioinput.cpp
+++ b/src/multimedia/audio/qaudioinput.cpp
@@ -1,413 +1,192 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include "qaudio.h"
-#include "qaudiodeviceinfo.h"
-#include "qaudiosystem.h"
-#include "qaudioinput.h"
-
-#include "qaudiodevicefactory_p.h"
-
-QT_BEGIN_NAMESPACE
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-/*!
- \class QAudioInput
- \brief The QAudioInput class provides an interface for receiving audio data from an audio input device.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_audio
-
- You can construct an audio input with the system's
- \l{QAudioDeviceInfo::defaultInputDevice()}{default audio input
- device}. It is also possible to create QAudioInput with a
- specific QAudioDeviceInfo. When you create the audio input, you
- should also send in the QAudioFormat to be used for the recording
- (see the QAudioFormat class description for details).
-
- To record to a file:
-
- QAudioInput lets you record audio with an audio input device. The
- default constructor of this class will use the systems default
- audio device, but you can also specify a QAudioDeviceInfo for a
- specific device. You also need to pass in the QAudioFormat in
- which you wish to record.
-
- Starting up the QAudioInput is simply a matter of calling start()
- with a QIODevice opened for writing. For instance, to record to a
- file, you can:
-
- \snippet multimedia-snippets/audio.cpp Audio input class members
-
- \snippet multimedia-snippets/audio.cpp Audio input setup
-
- This will start recording if the format specified is supported by
- the input device (you can check this with
- QAudioDeviceInfo::isFormatSupported(). In case there are any
- snags, use the error() function to check what went wrong. We stop
- recording in the \c stopRecording() slot.
-
- \snippet multimedia-snippets/audio.cpp Audio input stop recording
-
- At any point in time, QAudioInput will be in one of four states:
- active, suspended, stopped, or idle. These states are specified by
- the QAudio::State enum. You can request a state change directly through
- suspend(), resume(), stop(), reset(), and start(). The current
- state is reported by state(). QAudioOutput will also signal you
- when the state changes (stateChanged()).
+#include <qaudioinput.h>
+#include <qaudiodevice.h>
+#include <qmediadevices.h>
+#include <private/qplatformaudioinput_p.h>
+#include <private/qplatformmediaintegration_p.h>
- QAudioInput provides several ways of measuring the time that has
- passed since the start() of the recording. The \c processedUSecs()
- function returns the length of the stream in microseconds written,
- i.e., it leaves out the times the audio input was suspended or idle.
- The elapsedUSecs() function returns the time elapsed since start() was called regardless of
- which states the QAudioInput has been in.
-
- If an error should occur, you can fetch its reason with error().
- The possible error reasons are described by the QAudio::Error
- enum. The QAudioInput will enter the \l{QAudio::}{StoppedState} when
- an error is encountered. Connect to the stateChanged() signal to
- handle the error:
-
- \snippet multimedia-snippets/audio.cpp Audio input state changed
-
- \sa QAudioOutput, QAudioDeviceInfo
-*/
+#include <utility>
/*!
- Construct a new audio input and attach it to \a parent.
- The default audio input device is used with the output
- \a format parameters.
-*/
+ \qmltype AudioInput
+ \instantiates QAudioInput
+ \brief An audio input to be used for capturing audio in a capture session.
-QAudioInput::QAudioInput(const QAudioFormat &format, QObject *parent):
- QObject(parent)
-{
- d = QAudioDeviceFactory::createDefaultInputDevice(format);
- connect(d, SIGNAL(notify()), SIGNAL(notify()));
- connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State)));
-}
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+ \ingroup multimedia_audio_qml
-/*!
- Construct a new audio input and attach it to \a parent.
- The device referenced by \a audioDevice is used with the input
- \a format parameters.
-*/
+ \qml
+ CaptureSession {
+ id: playMusic
+ audioInput: AudioInput {
+ volume: slider.value
+ }
+ recorder: MediaRecorder { ... }
+ }
+ Slider {
+ id: slider
+ from: 0.
+ to: 1.
+ }
+ \endqml
-QAudioInput::QAudioInput(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format, QObject *parent):
- QObject(parent)
-{
- d = QAudioDeviceFactory::createInputDevice(audioDevice, format);
- connect(d, SIGNAL(notify()), SIGNAL(notify()));
- connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State)));
-}
+ You can use AudioInput together with a QtMultiMedia::CaptureSession to capture audio from an
+ audio input device.
-/*!
- Destroy this audio input.
+ \sa Camera, AudioOutput
*/
-QAudioInput::~QAudioInput()
-{
- delete d;
-}
-
/*!
- Starts transferring audio data from the system's audio input to the \a device.
- The \a device must have been opened in the \l{QIODevice::WriteOnly}{WriteOnly},
- \l{QIODevice::Append}{Append} or \l{QIODevice::ReadWrite}{ReadWrite} modes.
-
- If the QAudioInput is able to successfully get audio data, state() returns
- either QAudio::ActiveState or QAudio::IdleState, error() returns QAudio::NoError
- and the stateChanged() signal is emitted.
-
- If a problem occurs during this process, error() returns QAudio::OpenError,
- state() returns QAudio::StoppedState and the stateChanged() signal is emitted.
-
- \sa QIODevice
-*/
-
-void QAudioInput::start(QIODevice* device)
-{
- d->start(device);
-}
-
-/*!
- Returns a pointer to the internal QIODevice being used to transfer data from
- the system's audio input. The device will already be open and
- \l{QIODevice::read()}{read()} can read data directly from it.
-
- \note The pointer will become invalid after the stream is stopped or
- if you start another stream.
-
- If the QAudioInput is able to access the system's audio device, state() returns
- QAudio::IdleState, error() returns QAudio::NoError
- and the stateChanged() signal is emitted.
-
- If a problem occurs during this process, error() returns QAudio::OpenError,
- state() returns QAudio::StoppedState and the stateChanged() signal is emitted.
+ \class QAudioInput
+ \brief Represents an input channel for audio.
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_audio
- \sa QIODevice
+ This class represents an input channel that can be used together with
+ QMediaCaptureSession. It enables the selection of the physical input device
+ to be used, muting the channel, and changing the channel's volume.
*/
-QIODevice* QAudioInput::start()
+QAudioInput::QAudioInput(QObject *parent) : QAudioInput(QMediaDevices::defaultAudioInput(), parent)
{
- return d->start();
}
-/*!
- Returns the QAudioFormat being used.
-*/
-
-QAudioFormat QAudioInput::format() const
+QAudioInput::QAudioInput(const QAudioDevice &device, QObject *parent)
+ : QObject(parent)
{
- return d->format();
+ auto maybeAudioInput = QPlatformMediaIntegration::instance()->createAudioInput(this);
+ if (maybeAudioInput) {
+ d = maybeAudioInput.value();
+ d->device = device.mode() == QAudioDevice::Input ? device : QMediaDevices::defaultAudioInput();
+ d->setAudioDevice(d->device);
+ } else {
+ d = new QPlatformAudioInput(nullptr);
+ qWarning() << "Failed to initialize QAudioInput" << maybeAudioInput.error();
+ }
}
-/*!
- Stops the audio input, detaching from the system resource.
-
- Sets error() to QAudio::NoError, state() to QAudio::StoppedState and
- emit stateChanged() signal.
-*/
-
-void QAudioInput::stop()
+QAudioInput::~QAudioInput()
{
- d->stop();
+ setDisconnectFunction({});
+ delete d;
}
/*!
- Drops all audio data in the buffers, resets buffers to zero.
-*/
+ \qmlproperty real QtMultimedia::AudioInput::volume
-void QAudioInput::reset()
-{
- d->reset();
-}
+ The volume is scaled linearly, ranging from \c 0 (silence) to \c 1 (full volume).
+ \note values outside this range will be clamped.
-/*!
- Stops processing audio data, preserving buffered audio data.
+ By default the volume is \c 1.
- Sets error() to QAudio::NoError, state() to QAudio::SuspendedState and
- emit stateChanged() signal.
+ UI volume controls should usually be scaled non-linearly. For example,
+ using a logarithmic scale will produce linear changes in perceived loudness,
+ which is what a user would normally expect from a volume control.
+ \sa QtAudio::convertVolume()
*/
-
-void QAudioInput::suspend()
-{
- d->suspend();
-}
-
/*!
- Resumes processing audio data after a suspend().
+ \property QAudioInput::volume
- Sets error() to QAudio::NoError.
- Sets state() to QAudio::ActiveState if you previously called start(QIODevice*).
- Sets state() to QAudio::IdleState if you previously called start().
- emits stateChanged() signal.
+ The property returns the volume of the audio input.
*/
-
-void QAudioInput::resume()
+float QAudioInput::volume() const
{
- d->resume();
+ return d->volume;
}
-/*!
- Sets the audio buffer size to \a value bytes.
-
- Note: This function can be called anytime before start(), calls to this
- are ignored after start(). It should not be assumed that the buffer size
- set is the actual buffer size used, calling bufferSize() anytime after start()
- will return the actual buffer size being used.
-
-*/
-
-void QAudioInput::setBufferSize(int value)
+void QAudioInput::setVolume(float volume)
{
- d->setBufferSize(value);
+ volume = qBound(0., volume, 1.);
+ if (d->volume == volume)
+ return;
+ d->volume = volume;
+ d->setVolume(volume);
+ emit volumeChanged(volume);
}
/*!
- Returns the audio buffer size in bytes.
+ \qmlproperty bool QtMultimedia::AudioInput::muted
- If called before start(), returns platform default value.
- If called before start() but setBufferSize() was called prior, returns value set by setBufferSize().
- If called after start(), returns the actual buffer size being used. This may not be what was set previously
- by setBufferSize().
+ This property holds whether the audio input is muted.
+ Defaults to \c{false}.
*/
-int QAudioInput::bufferSize() const
-{
- return d->bufferSize();
-}
-
/*!
- Returns the amount of audio data available to read in bytes.
+ \property QAudioInput::muted
+ \brief The muted state of the current media.
- Note: returned value is only valid while in QAudio::ActiveState or QAudio::IdleState
- state, otherwise returns zero.
+ The value will be \c true if the input is muted; otherwise \c false.
*/
-
-int QAudioInput::bytesReady() const
+bool QAudioInput::isMuted() const
{
- /*
- -If not ActiveState|IdleState, return 0
- -return amount of audio data available to read
- */
- return d->bytesReady();
+ return d->muted;
}
-/*!
- Returns the period size in bytes.
-
- Note: This is the recommended read size in bytes.
-*/
-
-int QAudioInput::periodSize() const
+void QAudioInput::setMuted(bool muted)
{
- return d->periodSize();
+ if (d->muted == muted)
+ return;
+ d->muted = muted;
+ d->setMuted(muted);
+ emit mutedChanged(muted);
}
/*!
- Sets the interval for notify() signal to be emitted.
- This is based on the \a ms of audio data processed
- not on actual real-time.
- The minimum resolution of the timer is platform specific and values
- should be checked with notifyInterval() to confirm actual value
- being used.
-*/
+ \qmlproperty AudioDevice QtMultimedia::AudioInput::device
-void QAudioInput::setNotifyInterval(int ms)
-{
- d->setNotifyInterval(ms);
-}
+ This property describes the audio device connected to this input.
-/*!
- Returns the notify interval in milliseconds.
+ The device property represents the audio device this input is connected to.
+ This property can be used to select an output device from the
+ QtMultimedia::MediaDevices::audioInputs() list.
*/
-int QAudioInput::notifyInterval() const
-{
- return d->notifyInterval();
-}
-
/*!
- Sets the input volume to \a volume.
+ \property QAudioInput::device
+ \brief The audio device connected to this input.
- The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this
- range will be clamped.
+ The device property represents the audio device connected to this input.
+ This property can be used to select an input device from the
+ QMediaDevices::audioInputs() list.
- If the device does not support adjusting the input
- volume then \a volume will be ignored and the input
- volume will remain at 1.0.
-
- The default volume is \c 1.0.
-
- Note: Adjustments to the volume will change the volume of this audio stream, not the global volume.
+ You can select the system default audio input by setting this property to
+ a default constructed QAudioDevice object.
*/
-void QAudioInput::setVolume(qreal volume)
+QAudioDevice QAudioInput::device() const
{
- qreal v = qBound(qreal(0.0), volume, qreal(1.0));
- d->setVolume(v);
+ return d->device;
}
-/*!
- Returns the input volume.
-
- If the device does not support adjusting the input volume
- the returned value will be 1.0.
-*/
-qreal QAudioInput::volume() const
-{
- return d->volume();
-}
-
-/*!
- Returns the amount of audio data processed since start()
- was called in microseconds.
-*/
-
-qint64 QAudioInput::processedUSecs() const
+void QAudioInput::setDevice(const QAudioDevice &device)
{
- return d->processedUSecs();
+ auto dev = device;
+ if (dev.isNull())
+ dev = QMediaDevices::defaultAudioInput();
+ if (dev.mode() != QAudioDevice::Input)
+ return;
+ if (d->device == dev)
+ return;
+ d->device = dev;
+ d->setAudioDevice(dev);
+ emit deviceChanged();
}
/*!
- Returns the microseconds since start() was called, including time in Idle and
- Suspend states.
+ \internal
*/
-
-qint64 QAudioInput::elapsedUSecs() const
-{
- return d->elapsedUSecs();
-}
-
-/*!
- Returns the error state.
-*/
-
-QAudio::Error QAudioInput::error() const
+void QAudioInput::setDisconnectFunction(std::function<void()> disconnectFunction)
{
- return d->error();
+ if (d->disconnectFunction) {
+ auto df = d->disconnectFunction;
+ d->disconnectFunction = {};
+ df();
+ }
+ d->disconnectFunction = std::move(disconnectFunction);
}
-/*!
- Returns the state of audio processing.
-*/
-
-QAudio::State QAudioInput::state() const
-{
- return d->state();
-}
-
-/*!
- \fn QAudioInput::stateChanged(QAudio::State state)
- This signal is emitted when the device \a state has changed.
-*/
-
-/*!
- \fn QAudioInput::notify()
- This signal is emitted when x ms of audio data has been processed
- the interval set by setNotifyInterval(x).
-*/
-
-QT_END_NAMESPACE
-
#include "moc_qaudioinput.cpp"
-
diff --git a/src/multimedia/audio/qaudioinput.h b/src/multimedia/audio/qaudioinput.h
index b17fd4d79..6f4f6b099 100644
--- a/src/multimedia/audio/qaudioinput.h
+++ b/src/multimedia/audio/qaudioinput.h
@@ -1,109 +1,54 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QAUDIOINPUTDEVICE_H
+#define QAUDIOINPUTDEVICE_H
-#ifndef QAUDIOINPUT_H
-#define QAUDIOINPUT_H
-
-#include <QtCore/qiodevice.h>
-
+#include <QtCore/qobject.h>
#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
-
-#include <QtMultimedia/qaudio.h>
-#include <QtMultimedia/qaudioformat.h>
-#include <QtMultimedia/qaudiodeviceinfo.h>
+#include <QtMultimedia/qtaudio.h>
+#include <functional>
QT_BEGIN_NAMESPACE
-
-
-class QAbstractAudioInput;
+class QAudioDevice;
+class QPlatformAudioInput;
class Q_MULTIMEDIA_EXPORT QAudioInput : public QObject
{
Q_OBJECT
+ Q_PROPERTY(QAudioDevice device READ device WRITE setDevice NOTIFY deviceChanged)
+ Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
+ Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
public:
- explicit QAudioInput(const QAudioFormat &format = QAudioFormat(), QObject *parent = nullptr);
- explicit QAudioInput(const QAudioDeviceInfo &audioDeviceInfo, const QAudioFormat &format = QAudioFormat(), QObject *parent = nullptr);
+ explicit QAudioInput(QObject *parent = nullptr);
+ explicit QAudioInput(const QAudioDevice &deviceInfo, QObject *parent = nullptr);
~QAudioInput();
- QAudioFormat format() const;
-
- void start(QIODevice *device);
- QIODevice* start();
-
- void stop();
- void reset();
- void suspend();
- void resume();
+ QAudioDevice device() const;
+ float volume() const;
+ bool isMuted() const;
- void setBufferSize(int bytes);
- int bufferSize() const;
-
- int bytesReady() const;
- int periodSize() const;
-
- void setNotifyInterval(int milliSeconds);
- int notifyInterval() const;
-
- void setVolume(qreal volume);
- qreal volume() const;
-
- qint64 processedUSecs() const;
- qint64 elapsedUSecs() const;
-
- QAudio::Error error() const;
- QAudio::State state() const;
+public Q_SLOTS:
+ void setDevice(const QAudioDevice &device);
+ void setVolume(float volume);
+ void setMuted(bool muted);
Q_SIGNALS:
- void stateChanged(QAudio::State state);
- void notify();
+ void deviceChanged();
+ void volumeChanged(float volume);
+ void mutedChanged(bool muted);
private:
+ QPlatformAudioInput *handle() const { return d; }
+ void setDisconnectFunction(std::function<void()> disconnectFunction);
+ friend class QMediaCaptureSession;
Q_DISABLE_COPY(QAudioInput)
-
- QAbstractAudioInput* d;
+ QPlatformAudioInput *d = nullptr;
};
QT_END_NAMESPACE
-#endif // QAUDIOINPUT_H
+#endif // QAUDIOINPUTDEVICE_H
diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp
index e37da9bdf..3bb52a4d2 100644
--- a/src/multimedia/audio/qaudiooutput.cpp
+++ b/src/multimedia/audio/qaudiooutput.cpp
@@ -1,429 +1,209 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include "qaudio.h"
-#include "qaudiodeviceinfo.h"
-#include "qaudiosystem.h"
-#include "qaudiooutput.h"
-
-#include "qaudiodevicefactory_p.h"
-
-
-QT_BEGIN_NAMESPACE
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-/*!
- \class QAudioOutput
- \brief The QAudioOutput class provides an interface for sending audio data to an audio output device.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_audio
-
- You can construct an audio output with the system's
- \l{QAudioDeviceInfo::defaultOutputDevice()}{default audio output
- device}. It is also possible to create QAudioOutput with a
- specific QAudioDeviceInfo. When you create the audio output, you
- should also send in the QAudioFormat to be used for the playback
- (see the QAudioFormat class description for details).
-
- To play a file:
-
- Starting to play an audio stream is simply a matter of calling
- start() with a QIODevice. QAudioOutput will then fetch the data it
- needs from the io device. So playing back an audio file is as
- simple as:
-
- \snippet multimedia-snippets/audio.cpp Audio output class members
-
- \snippet multimedia-snippets/audio.cpp Audio output setup
-
- The file will start playing assuming that the audio system and
- output device support it. If you run out of luck, check what's
- up with the error() function.
-
- After the file has finished playing, we need to stop the device:
-
- \snippet multimedia-snippets/audio.cpp Audio output state changed
-
- At any given time, the QAudioOutput will be in one of four states:
- active, suspended, stopped, or idle. These states are described
- by the QAudio::State enum.
- State changes are reported through the stateChanged() signal. You
- can use this signal to, for instance, update the GUI of the
- application; the mundane example here being changing the state of
- a \c { play/pause } button. You request a state change directly
- with suspend(), stop(), reset(), resume(), and start().
-
- While the stream is playing, you can set a notify interval in
- milliseconds with setNotifyInterval(). This interval specifies the
- time between two emissions of the notify() signal. This is
- relative to the position in the stream, i.e., if the QAudioOutput
- is in the SuspendedState or the IdleState, the notify() signal is
- not emitted. A typical use-case would be to update a
- \l{QSlider}{slider} that allows seeking in the stream.
- If you want the time since playback started regardless of which
- states the audio output has been in, elapsedUSecs() is the function for you.
-
- If an error occurs, you can fetch the \l{QAudio::Error}{error
- type} with the error() function. Please see the QAudio::Error enum
- for a description of the possible errors that are reported. When
- an error is encountered, the state changes to QAudio::StoppedState.
- You can check for errors by connecting to the stateChanged()
- signal:
-
- \snippet multimedia-snippets/audio.cpp Audio output state changed
-
- \sa QAudioInput, QAudioDeviceInfo
-*/
+#include <qaudiooutput.h>
+#include <qaudiodevice.h>
+#include <qmediadevices.h>
+#include <private/qplatformaudiooutput_p.h>
+#include <private/qplatformmediaintegration_p.h>
/*!
- Construct a new audio output and attach it to \a parent.
- The default audio output device is used with the output
- \a format parameters.
-*/
-QAudioOutput::QAudioOutput(const QAudioFormat &format, QObject *parent):
- QObject(parent)
-{
- d = QAudioDeviceFactory::createDefaultOutputDevice(format);
- connect(d, SIGNAL(notify()), SIGNAL(notify()));
- connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State)));
-}
+ \qmltype AudioOutput
+ \instantiates QAudioOutput
+ \brief An audio output to be used for playback or monitoring of a capture session.
-/*!
- Construct a new audio output and attach it to \a parent.
- The device referenced by \a audioDevice is used with the output
- \a format parameters.
-*/
-QAudioOutput::QAudioOutput(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format, QObject *parent):
- QObject(parent)
-{
- d = QAudioDeviceFactory::createOutputDevice(audioDevice, format);
- connect(d, SIGNAL(notify()), SIGNAL(notify()));
- connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State)));
-}
-
-/*!
- Destroys this audio output.
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+ \ingroup multimedia_audio_qml
- This will release any system resources used and free any buffers.
-*/
-QAudioOutput::~QAudioOutput()
-{
- delete d;
-}
+ \qml
+ MediaPlayer {
+ id: playMusic
+ source: "music.wav"
+ audioOutput: AudioOutput {
+ volume: slider.value
+ }
+ }
+ Slider {
+ id: slider
+ from: 0.
+ to: 1.
+ }
+ \endqml
-/*!
- Returns the QAudioFormat being used.
+ You can use AudioOutput together with a QtMultiMedia::MediaPlayer to play audio content, or you
+ can use it in conjunction with a MultiMedia::CaptureSession to monitor the audio processed by the
+ capture session.
+ \sa VideoOutput, AudioInput
*/
-QAudioFormat QAudioOutput::format() const
-{
- return d->format();
-}
/*!
- Starts transferring audio data from the \a device to the system's audio output.
- The \a device must have been opened in the \l{QIODevice::ReadOnly}{ReadOnly} or
- \l{QIODevice::ReadWrite}{ReadWrite} modes.
-
- If the QAudioOutput is able to successfully output audio data, state() returns
- QAudio::ActiveState, error() returns QAudio::NoError
- and the stateChanged() signal is emitted.
-
- If a problem occurs during this process, error() returns QAudio::OpenError,
- state() returns QAudio::StoppedState and the stateChanged() signal is emitted.
+ \class QAudioOutput
+ \brief Represents an output channel for audio.
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_audio
+ \since 6.0
- \sa QIODevice
+ This class represents an output channel that can be used together with
+ QMediaPlayer or QMediaCaptureSession. It enables the selection of the
+ physical output device to be used, muting the channel, and changing the
+ channel's volume.
*/
-void QAudioOutput::start(QIODevice* device)
+QAudioOutput::QAudioOutput(QObject *parent)
+ : QAudioOutput(QMediaDevices::defaultAudioOutput(), parent)
{
- d->start(device);
}
-/*!
- Returns a pointer to the internal QIODevice being used to transfer data to
- the system's audio output. The device will already be open and
- \l{QIODevice::write()}{write()} can write data directly to it.
-
- \note The pointer will become invalid after the stream is stopped or
- if you start another stream.
-
- If the QAudioOutput is able to access the system's audio device, state() returns
- QAudio::IdleState, error() returns QAudio::NoError
- and the stateChanged() signal is emitted.
-
- If a problem occurs during this process, error() returns QAudio::OpenError,
- state() returns QAudio::StoppedState and the stateChanged() signal is emitted.
-
- \sa QIODevice
-*/
-QIODevice* QAudioOutput::start()
+QAudioOutput::QAudioOutput(const QAudioDevice &device, QObject *parent)
+ : QObject(parent)
{
- return d->start();
+ auto maybeAudioOutput = QPlatformMediaIntegration::instance()->createAudioOutput(this);
+ if (maybeAudioOutput) {
+ d = maybeAudioOutput.value();
+ d->device = device.mode() == QAudioDevice::Output ? device : QMediaDevices::defaultAudioOutput();
+ d->setAudioDevice(d->device);
+ } else {
+ d = new QPlatformAudioOutput(nullptr);
+ qWarning() << "Failed to initialize QAudioOutput" << maybeAudioOutput.error();
+ }
}
-/*!
- Stops the audio output, detaching from the system resource.
-
- Sets error() to QAudio::NoError, state() to QAudio::StoppedState and
- emit stateChanged() signal.
-*/
-void QAudioOutput::stop()
+QAudioOutput::~QAudioOutput()
{
- d->stop();
+ setDisconnectFunction({});
+ delete d;
}
/*!
- Drops all audio data in the buffers, resets buffers to zero.
+ \qmlproperty real QtMultimedia::AudioOutput::volume
-*/
-void QAudioOutput::reset()
-{
- d->reset();
-}
+ This property holds the volume of the audio output.
-/*!
- Stops processing audio data, preserving buffered audio data.
+ The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume).
+ Values outside this range will be clamped: a value lower than 0.0 is set to
+ 0.0, a value higher than 1.0 will set to 1.0.
- Sets error() to QAudio::NoError, state() to QAudio::SuspendedState and
- emits stateChanged() signal.
-*/
-void QAudioOutput::suspend()
-{
- d->suspend();
-}
+ The default volume is \c{1.0}.
-/*!
- Resumes processing audio data after a suspend().
+ UI \l{volume controls} should usually be scaled non-linearly. For example,
+ using a logarithmic scale will produce linear changes in perceived \l{loudness},
+ which is what a user would normally expect from a volume control.
- Sets error() to QAudio::NoError.
- Sets state() to QAudio::ActiveState if you previously called start(QIODevice*).
- Sets state() to QAudio::IdleState if you previously called start().
- emits stateChanged() signal.
+ See \l {QtAudio::convertVolume()}{QtMultimedia.convertVolume()}
+ for more details.
*/
-void QAudioOutput::resume()
-{
- d->resume();
-}
/*!
- Returns the number of free bytes available in the audio buffer.
+ \property QAudioOutput::volume
+ \brief The current volume.
- \note The returned value is only valid while in QAudio::ActiveState or QAudio::IdleState
- state, otherwise returns zero.
-*/
-int QAudioOutput::bytesFree() const
-{
- return d->bytesFree();
-}
+ The volume is scaled linearly, ranging from \c 0 (silence) to \c 1
+ (full volume).
+ \note values outside this range will be clamped.
-/*!
- Returns the period size in bytes. This is the amount of data required each period
- to prevent buffer underrun, and to ensure uninterrupted playback.
+ By default the volume is \c 1.
- \note It is recommended to provide at least enough data for a full period with each
- write operation.
-*/
-int QAudioOutput::periodSize() const
-{
- return d->periodSize();
-}
-
-/*!
- Sets the audio buffer size to \a value in bytes.
+ UI volume controls should usually be scaled non-linearly. For example,
+ using a logarithmic scale will produce linear changes in perceived loudness,
+ which is what a user would normally expect from a volume control.
- \note This function can be called anytime before start(). Calls to this
- are ignored after start(). It should not be assumed that the buffer size
- set is the actual buffer size used - call bufferSize() anytime after start()
- to return the actual buffer size being used.
+ \sa QtAudio::convertVolume()
*/
-void QAudioOutput::setBufferSize(int value)
+float QAudioOutput::volume() const
{
- d->setBufferSize(value);
+ return d->volume;
}
-/*!
- Returns the audio buffer size in bytes.
-
- If called before start(), returns platform default value.
- If called before start() but setBufferSize() was called prior, returns value set by setBufferSize().
- If called after start(), returns the actual buffer size being used. This may not be what was set previously
- by setBufferSize().
-
-*/
-int QAudioOutput::bufferSize() const
+void QAudioOutput::setVolume(float volume)
{
- return d->bufferSize();
+ volume = qBound(0., volume, 1.);
+ if (d->volume == volume)
+ return;
+ d->volume = volume;
+ d->setVolume(volume);
+ emit volumeChanged(volume);
}
/*!
- Sets the interval for notify() signal to be emitted.
- This is based on the \a ms of audio data processed,
- not on wall clock time.
- The minimum resolution of the timer is platform specific and values
- should be checked with notifyInterval() to confirm the actual value
- being used.
-*/
-void QAudioOutput::setNotifyInterval(int ms)
-{
- d->setNotifyInterval(ms);
-}
+ \qmlproperty bool QtMultimedia::AudioOutput::muted
-/*!
- Returns the notify interval in milliseconds.
-*/
-int QAudioOutput::notifyInterval() const
-{
- return d->notifyInterval();
-}
+ This property holds whether the audio output is muted.
-/*!
- Returns the amount of audio data processed since start()
- was called (in microseconds).
+ Defaults to \c{false}.
*/
-qint64 QAudioOutput::processedUSecs() const
-{
- return d->processedUSecs();
-}
/*!
- Returns the microseconds since start() was called, including time in Idle and
- Suspend states.
-*/
-qint64 QAudioOutput::elapsedUSecs() const
-{
- return d->elapsedUSecs();
-}
+ \property QAudioOutput::muted
+ \brief The muted state of the current media.
-/*!
- Returns the error state.
+ The value will be \c true if the output is muted; otherwise \c{false}.
*/
-QAudio::Error QAudioOutput::error() const
+bool QAudioOutput::isMuted() const
{
- return d->error();
+ return d->muted;
}
-/*!
- Returns the state of audio processing.
-*/
-QAudio::State QAudioOutput::state() const
+void QAudioOutput::setMuted(bool muted)
{
- return d->state();
+ if (d->muted == muted)
+ return;
+ d->muted = muted;
+ d->setMuted(muted);
+ emit mutedChanged(muted);
}
/*!
- Sets the output volume to \a volume.
-
- The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this
- range will be clamped.
+ \qmlproperty AudioDevice QtMultimedia::AudioOutput::device
- The default volume is \c 1.0.
+ This property describes the audio device connected to this output.
- Note: Adjustments to the volume will change the volume of this audio stream, not the global volume.
-
- UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale
- will produce linear changes in perceived loudness, which is what a user would normally expect
- from a volume control. See QAudio::convertVolume() for more details.
+ The device property represents the audio device this output is connected to.
+ This property can be used to select an output device from the
+ QtMultimedia::MediaDevices::audioOutputs() list.
*/
-void QAudioOutput::setVolume(qreal volume)
-{
- qreal v = qBound(qreal(0.0), volume, qreal(1.0));
- d->setVolume(v);
-}
/*!
- Returns the volume between 0.0 and 1.0 inclusive.
+ \property QAudioOutput::device
+ \brief The audio device connected to this output.
+
+ The device property represents the audio device this output is connected to.
+ This property can be used to select an output device from the
+ QMediaDevices::audioOutputs() list.
+ You can select the system default audio output by setting this property to
+ a default constructed QAudioDevice object.
*/
-qreal QAudioOutput::volume() const
+QAudioDevice QAudioOutput::device() const
{
- return d->volume();
+ return d->device;
}
-/*!
- Returns the audio category of this audio stream.
-
- Some platforms can group audio streams into categories
- and manage their volumes independently, or display them
- in a system mixer control. You can set this property to
- allow the platform to distinguish the purpose of your streams.
-
- \sa setCategory()
-*/
-QString QAudioOutput::category() const
+void QAudioOutput::setDevice(const QAudioDevice &device)
{
- return d->category();
+ auto dev = device;
+ if (dev.isNull())
+ dev = QMediaDevices::defaultAudioOutput();
+ if (dev.mode() != QAudioDevice::Output)
+ return;
+ if (d->device == dev)
+ return;
+ d->device = dev;
+ d->setAudioDevice(dev);
+ emit deviceChanged();
}
/*!
- Sets the audio category of this audio stream to \a category.
-
- Some platforms can group audio streams into categories
- and manage their volumes independently, or display them
- in a system mixer control. You can set this property to
- allow the platform to distinguish the purpose of your streams.
-
- Not all platforms support audio stream categorization. In this
- case, the function call will be ignored.
-
- Changing an audio output stream's category while it is opened
- will not take effect until it is reopened.
- \sa category()
+ \internal
*/
-void QAudioOutput::setCategory(const QString &category)
+void QAudioOutput::setDisconnectFunction(std::function<void()> disconnectFunction)
{
- d->setCategory(category);
+ if (d->disconnectFunction) {
+ auto df = d->disconnectFunction;
+ d->disconnectFunction = {};
+ df();
+ }
+ d->disconnectFunction = std::move(disconnectFunction);
}
-/*!
- \fn QAudioOutput::stateChanged(QAudio::State state)
- This signal is emitted when the device \a state has changed.
- This is the current state of the audio output.
-*/
-
-/*!
- \fn QAudioOutput::notify()
- This signal is emitted when a certain interval of milliseconds
- of audio data has been processed. The interval is set by
- setNotifyInterval().
-*/
-
-QT_END_NAMESPACE
-
#include "moc_qaudiooutput.cpp"
diff --git a/src/multimedia/audio/qaudiooutput.h b/src/multimedia/audio/qaudiooutput.h
index 5f466d8e1..643d19f94 100644
--- a/src/multimedia/audio/qaudiooutput.h
+++ b/src/multimedia/audio/qaudiooutput.h
@@ -1,112 +1,55 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QAUDIOOUTPUTDEVICE_H
+#define QAUDIOOUTPUTDEVICE_H
-#ifndef QAUDIOOUTPUT_H
-#define QAUDIOOUTPUT_H
-
-#include <QtCore/qiodevice.h>
-
+#include <QtCore/qobject.h>
#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
-
-#include <QtMultimedia/qaudio.h>
-#include <QtMultimedia/qaudioformat.h>
-#include <QtMultimedia/qaudiodeviceinfo.h>
+#include <QtMultimedia/qtaudio.h>
+#include <functional>
QT_BEGIN_NAMESPACE
-
-
-class QAbstractAudioOutput;
+class QAudioDevice;
+class QPlatformAudioOutput;
class Q_MULTIMEDIA_EXPORT QAudioOutput : public QObject
{
Q_OBJECT
+ Q_PROPERTY(QAudioDevice device READ device WRITE setDevice NOTIFY deviceChanged)
+ Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
+ Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
public:
- explicit QAudioOutput(const QAudioFormat &format = QAudioFormat(), QObject *parent = nullptr);
- explicit QAudioOutput(const QAudioDeviceInfo &audioDeviceInfo, const QAudioFormat &format = QAudioFormat(), QObject *parent = nullptr);
+ explicit QAudioOutput(QObject *parent = nullptr);
+ explicit QAudioOutput(const QAudioDevice &device, QObject *parent = nullptr);
~QAudioOutput();
- QAudioFormat format() const;
-
- void start(QIODevice *device);
- QIODevice* start();
-
- void stop();
- void reset();
- void suspend();
- void resume();
+ QAudioDevice device() const;
+ float volume() const;
+ bool isMuted() const;
- void setBufferSize(int bytes);
- int bufferSize() const;
-
- int bytesFree() const;
- int periodSize() const;
-
- void setNotifyInterval(int milliSeconds);
- int notifyInterval() const;
-
- qint64 processedUSecs() const;
- qint64 elapsedUSecs() const;
-
- QAudio::Error error() const;
- QAudio::State state() const;
-
- void setVolume(qreal);
- qreal volume() const;
-
- QString category() const;
- void setCategory(const QString &category);
+public Q_SLOTS:
+ void setDevice(const QAudioDevice &device);
+ void setVolume(float volume);
+ void setMuted(bool muted);
Q_SIGNALS:
- void stateChanged(QAudio::State state);
- void notify();
+ void deviceChanged();
+ void volumeChanged(float volume);
+ void mutedChanged(bool muted);
private:
+ QPlatformAudioOutput *handle() const { return d; }
+ void setDisconnectFunction(std::function<void()> disconnectFunction);
+ friend class QMediaCaptureSession;
+ friend class QMediaPlayer;
Q_DISABLE_COPY(QAudioOutput)
-
- QAbstractAudioOutput* d;
+ QPlatformAudioOutput *d = nullptr;
};
QT_END_NAMESPACE
-#endif // QAUDIOOUTPUT_H
+#endif // QAUDIOOUTPUTDEVICE_H
diff --git a/src/multimedia/audio/qaudioprobe.cpp b/src/multimedia/audio/qaudioprobe.cpp
deleted file mode 100644
index 7fb57242f..000000000
--- a/src/multimedia/audio/qaudioprobe.cpp
+++ /dev/null
@@ -1,205 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \class QAudioProbe
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_audio
-
- \brief The QAudioProbe class allows you to monitor audio being played or recorded.
-
- \snippet multimedia-snippets/qaudioprobe.cpp desc
-
- \sa QVideoProbe, QMediaPlayer, QCamera
-*/
-
-#include "qaudioprobe.h"
-#include "qmediaaudioprobecontrol.h"
-#include "qmediaservice.h"
-#include "qmediarecorder.h"
-#include "qsharedpointer.h"
-#include "qpointer.h"
-
-QT_BEGIN_NAMESPACE
-
-class QAudioProbePrivate {
-public:
- QPointer<QMediaObject> source;
- QPointer<QMediaAudioProbeControl> probee;
-};
-
-/*!
- Creates a new QAudioProbe class with a \a parent. After setting the
- source to monitor with \l setSource(), the \l audioBufferProbed()
- signal will be emitted when audio buffers are flowing in the
- source media object.
- */
-QAudioProbe::QAudioProbe(QObject *parent)
- : QObject(parent)
- , d(new QAudioProbePrivate)
-{
-}
-
-/*!
- Destroys this probe and disconnects from any
- media object.
- */
-QAudioProbe::~QAudioProbe()
-{
- if (d->source) {
- // Disconnect
- if (d->probee) {
- disconnect(d->probee.data(), SIGNAL(audioBufferProbed(QAudioBuffer)), this, SIGNAL(audioBufferProbed(QAudioBuffer)));
- disconnect(d->probee.data(), SIGNAL(flush()), this, SIGNAL(flush()));
- }
- d->source.data()->service()->releaseControl(d->probee.data());
- }
-}
-
-/*!
- Sets the media object to monitor to \a source.
-
- If \a source is zero, this probe will be deactivated
- and this function wil return true.
-
- If the media object does not support monitoring
- audio, this function will return false.
-
- The previous object will no longer be monitored.
- Passing in the same object will be ignored, but
- monitoring will continue.
- */
-bool QAudioProbe::setSource(QMediaObject *source)
-{
- // Need to:
- // 1) disconnect from current source if necessary
- // 2) see if new one has the probe control
- // 3) connect if so
-
- // in case source was destroyed but probe control is still valid
- if (!d->source && d->probee) {
- disconnect(d->probee.data(), SIGNAL(audioBufferProbed(QAudioBuffer)), this, SIGNAL(audioBufferProbed(QAudioBuffer)));
- disconnect(d->probee.data(), SIGNAL(flush()), this, SIGNAL(flush()));
- d->probee.clear();
- }
-
- if (source != d->source.data()) {
- if (d->source) {
- Q_ASSERT(d->probee);
- disconnect(d->probee.data(), SIGNAL(audioBufferProbed(QAudioBuffer)), this, SIGNAL(audioBufferProbed(QAudioBuffer)));
- disconnect(d->probee.data(), SIGNAL(flush()), this, SIGNAL(flush()));
- d->source.data()->service()->releaseControl(d->probee.data());
- d->source.clear();
- d->probee.clear();
- }
-
- if (source) {
- QMediaService *service = source->service();
- if (service) {
- d->probee = service->requestControl<QMediaAudioProbeControl*>();
- }
-
- if (d->probee) {
- connect(d->probee.data(), SIGNAL(audioBufferProbed(QAudioBuffer)), this, SIGNAL(audioBufferProbed(QAudioBuffer)));
- connect(d->probee.data(), SIGNAL(flush()), this, SIGNAL(flush()));
- d->source = source;
- }
- }
- }
-
- return (!source || d->probee != nullptr);
-}
-
-/*!
- Starts monitoring the given \a mediaRecorder.
-
- Returns true on success.
-
- If there is no mediaObject associated with \a mediaRecorder, or if it is
- zero, this probe will be deactivated and this function wil return true.
-
- If the media recorder instance does not support monitoring
- audio, this function will return false.
-
- Any previously monitored objects will no longer be monitored.
- Passing in the same (valid) object will be ignored, but
- monitoring will continue.
- */
-bool QAudioProbe::setSource(QMediaRecorder *mediaRecorder)
-{
- QMediaObject *source = mediaRecorder ? mediaRecorder->mediaObject() : nullptr;
- bool result = setSource(source);
-
- if (!mediaRecorder)
- return true;
-
- if (mediaRecorder && !source)
- return false;
-
- return result;
-}
-
-/*!
- Returns true if this probe is monitoring something, or false otherwise.
-
- The source being monitored does not need to be active.
- */
-bool QAudioProbe::isActive() const
-{
- return d->probee != nullptr;
-}
-
-/*!
- \fn QAudioProbe::audioBufferProbed(const QAudioBuffer &buffer)
-
- This signal should be emitted when an audio \a buffer is processed in the
- media service.
-*/
-
-
-/*!
- \fn QAudioProbe::flush()
-
- This signal should be emitted when it is required to release all buffers.
- Application must release all outstanding references to audio buffers.
-*/
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudioprobe.h b/src/multimedia/audio/qaudioprobe.h
deleted file mode 100644
index e0d5619d2..000000000
--- a/src/multimedia/audio/qaudioprobe.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIOPROBE_H
-#define QAUDIOPROBE_H
-
-#include <QtCore/qobject.h>
-#include <QtMultimedia/qaudiobuffer.h>
-
-QT_BEGIN_NAMESPACE
-
-class QMediaObject;
-class QMediaRecorder;
-
-class QAudioProbePrivate;
-class Q_MULTIMEDIA_EXPORT QAudioProbe : public QObject
-{
- Q_OBJECT
-public:
- explicit QAudioProbe(QObject *parent = nullptr);
- ~QAudioProbe();
-
- bool setSource(QMediaObject *source);
- bool setSource(QMediaRecorder *source);
-
- bool isActive() const;
-
-Q_SIGNALS:
- void audioBufferProbed(const QAudioBuffer &buffer);
- void flush();
-
-private:
- QAudioProbePrivate *d;
-};
-
-QT_END_NAMESPACE
-
-#endif // QAUDIOPROBE_H
diff --git a/src/multimedia/audio/qaudiosink.cpp b/src/multimedia/audio/qaudiosink.cpp
new file mode 100644
index 000000000..12263d32a
--- /dev/null
+++ b/src/multimedia/audio/qaudiosink.cpp
@@ -0,0 +1,339 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#include "qaudio.h"
+#include "qaudiodevice.h"
+#include "qaudiosystem_p.h"
+#include "qaudiosink.h"
+
+#include <private/qplatformmediadevices_p.h>
+#include <private/qplatformmediaintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QAudioSink
+ \brief The QAudioSink class provides an interface for sending audio data to
+ an audio output device.
+
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_audio
+
+ You can construct an audio output with the system's
+ default audio output device. It is also possible to
+ create QAudioSink with a specific QAudioDevice. When
+ you create the audio output, you should also send in
+ the QAudioFormat to be used for the playback (see
+ the QAudioFormat class description for details).
+
+ To play a file:
+
+ Starting to play an audio stream is simply a matter of calling
+ start() with a QIODevice. QAudioSink will then fetch the data it
+ needs from the io device. So playing back an audio file is as
+ simple as:
+
+ \snippet multimedia-snippets/audio.cpp Audio output class members
+
+ \snippet multimedia-snippets/audio.cpp Audio output setup
+
+ The file will start playing assuming that the audio system and
+ output device support it. If you run out of luck, check what's
+ up with the error() function.
+
+ After the file has finished playing, we need to stop the device:
+
+ \snippet multimedia-snippets/audio.cpp Audio output stop
+
+ At any given time, the QAudioSink will be in one of four states:
+ active, suspended, stopped, or idle. These states are described
+ by the QtAudio::State enum.
+ State changes are reported through the stateChanged() signal. You
+ can use this signal to, for instance, update the GUI of the
+ application; the mundane example here being changing the state of
+ a \c { play/pause } button. You request a state change directly
+ with suspend(), stop(), reset(), resume(), and start().
+
+ If an error occurs, you can fetch the \l{QtAudio::Error}{error
+ type} with the error() function. Please see the QtAudio::Error enum
+ for a description of the possible errors that are reported. When
+ QtAudio::UnderrunError is encountered, the state changes to QtAudio::IdleState,
+ when another error is encountered, the state changes to QtAudio::StoppedState.
+ You can check for errors by connecting to the stateChanged()
+ signal:
+
+ \snippet multimedia-snippets/audio.cpp Audio output state changed
+
+ \sa QAudioSource, QAudioDevice
+*/
+
+/*!
+ Construct a new audio output and attach it to \a parent.
+ The default audio output device is used with the output
+ \a format parameters.
+*/
+QAudioSink::QAudioSink(const QAudioFormat &format, QObject *parent)
+ : QAudioSink({}, format, parent)
+{
+}
+
+/*!
+ Construct a new audio output and attach it to \a parent.
+ The device referenced by \a audioDevice is used with the output
+ \a format parameters.
+*/
+QAudioSink::QAudioSink(const QAudioDevice &audioDevice, const QAudioFormat &format, QObject *parent):
+ QObject(parent)
+{
+ d = QPlatformMediaIntegration::instance()->mediaDevices()->audioOutputDevice(format, audioDevice, parent);
+ if (d)
+ connect(d, &QPlatformAudioSink::stateChanged, this, [this](QAudio::State state) {
+ // if the signal has been emitted from another thread,
+ // the state may be already changed by main one
+ if (state == d->state())
+ emit stateChanged(state);
+ });
+ else
+ qWarning() << ("No audio device detected");
+}
+
+/*!
+ \fn bool QAudioSink::isNull() const
+
+ Returns \c true is the QAudioSink instance is \c null, otherwise returns
+ \c false.
+*/
+
+/*!
+ Destroys this audio output.
+
+ This will release any system resources used and free any buffers.
+*/
+QAudioSink::~QAudioSink()
+{
+ delete d;
+}
+
+/*!
+ Returns the QAudioFormat being used.
+
+*/
+QAudioFormat QAudioSink::format() const
+{
+ return d ? d->format() : QAudioFormat();
+}
+
+/*!
+ Starts transferring audio data from the \a device to the system's audio output.
+ The \a device must have been opened in the \l{QIODevice::ReadOnly}{ReadOnly} or
+ \l{QIODevice::ReadWrite}{ReadWrite} modes.
+
+ If the QAudioSink is able to successfully output audio data, state() returns
+ QtAudio::ActiveState, error() returns QtAudio::NoError
+ and the stateChanged() signal is emitted.
+
+ If a problem occurs during this process, error() returns QtAudio::OpenError,
+ state() returns QtAudio::StoppedState and the stateChanged() signal is emitted.
+
+ \sa QIODevice
+*/
+void QAudioSink::start(QIODevice* device)
+{
+ if (!d)
+ return;
+ d->elapsedTime.restart();
+ d->start(device);
+}
+
+/*!
+ Returns a pointer to the internal QIODevice being used to transfer data to
+ the system's audio output. The device will already be open and
+ \l{QIODevice::write()}{write()} can write data directly to it.
+
+ \note The pointer will become invalid after the stream is stopped or
+ if you start another stream.
+
+ If the QAudioSink is able to access the system's audio device, state() returns
+ QtAudio::IdleState, error() returns QtAudio::NoError
+ and the stateChanged() signal is emitted.
+
+ If a problem occurs during this process, error() returns QtAudio::OpenError,
+ state() returns QtAudio::StoppedState and the stateChanged() signal is emitted.
+
+ \sa QIODevice
+*/
+QIODevice* QAudioSink::start()
+{
+ if (!d)
+ return nullptr;
+ d->elapsedTime.restart();
+ return d->start();
+}
+
+/*!
+ Stops the audio output, detaching from the system resource.
+
+ Sets error() to QtAudio::NoError, state() to QtAudio::StoppedState and
+ emit stateChanged() signal.
+*/
+void QAudioSink::stop()
+{
+ if (d)
+ d->stop();
+}
+
+/*!
+ Drops all audio data in the buffers, resets buffers to zero.
+
+*/
+void QAudioSink::reset()
+{
+ if (d)
+ d->reset();
+}
+
+/*!
+ Stops processing audio data, preserving buffered audio data.
+
+ Sets error() to QtAudio::NoError, state() to QtAudio::SuspendedState and
+ emits stateChanged() signal.
+*/
+void QAudioSink::suspend()
+{
+ if (d)
+ d->suspend();
+}
+
+/*!
+ Resumes processing audio data after a suspend().
+
+ Sets state() to the state the sink had when suspend() was called, and sets
+ error() to QAudioError::NoError. This function does nothing if the audio sink's
+ state is not QtAudio::SuspendedState.
+*/
+void QAudioSink::resume()
+{
+ if (d)
+ d->resume();
+}
+
+/*!
+ Returns the number of free bytes available in the audio buffer.
+
+ \note The returned value is only valid while in QtAudio::ActiveState or QtAudio::IdleState
+ state, otherwise returns zero.
+*/
+qsizetype QAudioSink::bytesFree() const
+{
+ return d ? d->bytesFree() : 0;
+}
+
+/*!
+ Sets the audio buffer size to \a value in bytes.
+
+ \note This function can be called anytime before start(). Calls to this
+ are ignored after start(). It should not be assumed that the buffer size
+ set is the actual buffer size used - call bufferSize() anytime after start()
+ to return the actual buffer size being used.
+*/
+void QAudioSink::setBufferSize(qsizetype value)
+{
+ if (d)
+ d->setBufferSize(value);
+}
+
+/*!
+ Returns the audio buffer size in bytes.
+
+ If called before start(), returns platform default value.
+ If called before start() but setBufferSize() was called prior, returns value set by setBufferSize().
+ If called after start(), returns the actual buffer size being used. This may not be what was set previously
+ by setBufferSize().
+
+*/
+qsizetype QAudioSink::bufferSize() const
+{
+ return d ? d->bufferSize() : 0;
+}
+
+/*!
+ Returns the amount of audio data processed since start()
+ was called (in microseconds).
+*/
+qint64 QAudioSink::processedUSecs() const
+{
+ return d ? d->processedUSecs() : 0;
+}
+
+/*!
+ Returns the microseconds since start() was called, including time in Idle and
+ Suspend states.
+*/
+qint64 QAudioSink::elapsedUSecs() const
+{
+ return state() == QAudio::StoppedState ? 0 : d->elapsedTime.nsecsElapsed()/1000;
+}
+
+/*!
+ Returns the error state.
+*/
+QtAudio::Error QAudioSink::error() const
+{
+ return d ? d->error() : QAudio::OpenError;
+}
+
+/*!
+ Returns the state of audio processing.
+*/
+QtAudio::State QAudioSink::state() const
+{
+ return d ? d->state() : QAudio::StoppedState;
+}
+
+/*!
+ Sets the output volume to \a volume.
+
+ The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume).
+ Values outside this range will be clamped.
+
+ The default volume is \c 1.0.
+
+ \note Adjustments to the volume will change the volume of this audio stream,
+ not the global volume.
+
+ UI volume controls should usually be scaled non-linearly. For example, using
+ a logarithmic scale will produce linear changes in perceived loudness, which
+ is what a user would normally expect from a volume control. See
+ QtAudio::convertVolume() for more details.
+*/
+void QAudioSink::setVolume(qreal volume)
+{
+ if (!d)
+ return;
+ qreal v = qBound(qreal(0.0), volume, qreal(1.0));
+ d->setVolume(v);
+}
+
+/*!
+ Returns the volume between 0.0 and 1.0 inclusive.
+*/
+qreal QAudioSink::volume() const
+{
+ return d ? d->volume() : 1.0;
+}
+
+/*!
+ \fn QAudioSink::stateChanged(QtAudio::State state)
+ This signal is emitted when the device \a state has changed.
+ This is the current state of the audio output.
+
+ \note The QtAudio namespace was named QAudio up to and including Qt 6.6.
+ String-based connections to this signal have to use \c{QAudio::State} as
+ the parameter type: \c{connect(source, SIGNAL(stateChanged(QAudio::State)), ...);}
+*/
+
+QT_END_NAMESPACE
+
+#include "moc_qaudiosink.cpp"
diff --git a/src/multimedia/audio/qaudiosink.h b/src/multimedia/audio/qaudiosink.h
new file mode 100644
index 000000000..e071e6fbc
--- /dev/null
+++ b/src/multimedia/audio/qaudiosink.h
@@ -0,0 +1,74 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#ifndef QAUDIOOUTPUT_H
+#define QAUDIOOUTPUT_H
+
+#include <QtCore/qiodevice.h>
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+
+#include <QtMultimedia/qtaudio.h>
+#include <QtMultimedia/qaudioformat.h>
+#include <QtMultimedia/qaudiodevice.h>
+
+
+QT_BEGIN_NAMESPACE
+
+
+
+class QPlatformAudioSink;
+
+class Q_MULTIMEDIA_EXPORT QAudioSink : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit QAudioSink(const QAudioFormat &format = QAudioFormat(), QObject *parent = nullptr);
+ explicit QAudioSink(const QAudioDevice &audioDeviceInfo, const QAudioFormat &format = QAudioFormat(), QObject *parent = nullptr);
+ ~QAudioSink();
+
+ bool isNull() const { return !d; }
+
+ QAudioFormat format() const;
+
+ void start(QIODevice *device);
+ QIODevice* start();
+
+ void stop();
+ void reset();
+ void suspend();
+ void resume();
+
+ void setBufferSize(qsizetype bytes);
+ qsizetype bufferSize() const;
+
+ qsizetype bytesFree() const;
+
+ qint64 processedUSecs() const;
+ qint64 elapsedUSecs() const;
+
+ QtAudio::Error error() const;
+ QtAudio::State state() const;
+
+ void setVolume(qreal);
+ qreal volume() const;
+
+Q_SIGNALS:
+#if defined(Q_QDOC)
+ void stateChanged(QtAudio::State state);
+#else
+ // use QAudio here to keep string-based connections working
+ void stateChanged(QAudio::State state);
+#endif
+
+private:
+ Q_DISABLE_COPY(QAudioSink)
+
+ QPlatformAudioSink* d;
+};
+
+QT_END_NAMESPACE
+
+#endif // QAUDIOOUTPUT_H
diff --git a/src/multimedia/audio/qaudiosource.cpp b/src/multimedia/audio/qaudiosource.cpp
new file mode 100644
index 000000000..1ed5e82bc
--- /dev/null
+++ b/src/multimedia/audio/qaudiosource.cpp
@@ -0,0 +1,369 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#include "qaudio.h"
+#include "qaudiodevice.h"
+#include "qaudiosystem_p.h"
+#include "qaudiosource.h"
+
+#include <private/qplatformmediadevices_p.h>
+#include <private/qplatformmediaintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QAudioSource
+ \brief The QAudioSource class provides an interface for receiving audio data from an audio input device.
+
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_audio
+
+ You can construct an audio input with the system's
+ default audio input device. It is also possible to
+ create QAudioSource with a specific QAudioDevice. When
+ you create the audio input, you should also send in the
+ QAudioFormat to be used for the recording (see the QAudioFormat
+ class description for details).
+
+ To record to a file:
+
+ QAudioSource lets you record audio with an audio input device. The
+ default constructor of this class will use the systems default
+ audio device, but you can also specify a QAudioDevice for a
+ specific device. You also need to pass in the QAudioFormat in
+ which you wish to record.
+
+ Starting up the QAudioSource is simply a matter of calling start()
+ with a QIODevice opened for writing. For instance, to record to a
+ file, you can:
+
+ \snippet multimedia-snippets/audio.cpp Audio input class members
+
+ \snippet multimedia-snippets/audio.cpp Audio input setup
+
+ This will start recording if the format specified is supported by
+ the input device (you can check this with
+ QAudioDevice::isFormatSupported(). In case there are any
+ snags, use the error() function to check what went wrong. We stop
+ recording in the \c stopRecording() slot.
+
+ \snippet multimedia-snippets/audio.cpp Audio input stop recording
+
+ At any point in time, QAudioSource will be in one of four states:
+ active, suspended, stopped, or idle. These states are specified by
+ the QtAudio::State enum. You can request a state change directly through
+ suspend(), resume(), stop(), reset(), and start(). The current
+ state is reported by state(). QAudioSink will also signal you
+ when the state changes (stateChanged()).
+
+ QAudioSource provides several ways of measuring the time that has
+ passed since the start() of the recording. The \c processedUSecs()
+ function returns the length of the stream in microseconds written,
+ i.e., it leaves out the times the audio input was suspended or idle.
+ The elapsedUSecs() function returns the time elapsed since start() was called regardless of
+ which states the QAudioSource has been in.
+
+ If an error should occur, you can fetch its reason with error().
+ The possible error reasons are described by the QtAudio::Error
+ enum. The QAudioSource will enter the \l{QtAudio::}{StoppedState} when
+ an error is encountered. Connect to the stateChanged() signal to
+ handle the error:
+
+ \snippet multimedia-snippets/audio.cpp Audio input state changed
+
+ \sa QAudioSink, QAudioDevice
+*/
+
+/*!
+ Construct a new audio input and attach it to \a parent.
+ The default audio input device is used with the output
+ \a format parameters.
+*/
+
+QAudioSource::QAudioSource(const QAudioFormat &format, QObject *parent)
+ : QAudioSource({}, format, parent)
+{
+}
+
+/*!
+ Construct a new audio input and attach it to \a parent.
+ The device referenced by \a audioDevice is used with the input
+ \a format parameters.
+*/
+
+QAudioSource::QAudioSource(const QAudioDevice &audioDevice, const QAudioFormat &format, QObject *parent):
+ QObject(parent)
+{
+ d = QPlatformMediaIntegration::instance()->mediaDevices()->audioInputDevice(format, audioDevice, parent);
+ if (d) {
+ connect(d, &QPlatformAudioSource::stateChanged, this, [this](QAudio::State state) {
+ // if the signal has been emitted from another thread,
+ // the state may be already changed by main one
+ if (state == d->state())
+ emit stateChanged(state);
+ });
+ }
+ else
+ qWarning() << ("No audio device detected");
+
+}
+
+/*!
+ \fn bool QAudioSource::isNull() const
+
+ Returns \c true if the audio source is \c null, otherwise returns \c false.
+*/
+
+/*!
+ Destroy this audio input.
+*/
+
+QAudioSource::~QAudioSource()
+{
+ delete d;
+}
+
+/*!
+ Starts transferring audio data from the system's audio input to the \a device.
+ The \a device must have been opened in the \l{QIODevice::WriteOnly}{WriteOnly},
+ \l{QIODevice::Append}{Append} or \l{QIODevice::ReadWrite}{ReadWrite} modes.
+
+ If the QAudioSource is able to successfully get audio data, state() returns
+ either QtAudio::ActiveState or QtAudio::IdleState, error() returns QtAudio::NoError
+ and the stateChanged() signal is emitted.
+
+ If a problem occurs during this process, error() returns QtAudio::OpenError,
+ state() returns QtAudio::StoppedState and the stateChanged() signal is emitted.
+
+ \sa QIODevice
+*/
+
+void QAudioSource::start(QIODevice* device)
+{
+ if (!d)
+ return;
+ d->elapsedTime.start();
+ d->start(device);
+}
+
+/*!
+ Returns a pointer to the internal QIODevice being used to transfer data from
+ the system's audio input. The device will already be open and
+ \l{QIODevice::read()}{read()} can read data directly from it.
+
+ \note The pointer will become invalid after the stream is stopped or
+ if you start another stream.
+
+ If the QAudioSource is able to access the system's audio device, state() returns
+ QtAudio::IdleState, error() returns QtAudio::NoError
+ and the stateChanged() signal is emitted.
+
+ If a problem occurs during this process, error() returns QtAudio::OpenError,
+ state() returns QtAudio::StoppedState and the stateChanged() signal is emitted.
+
+ \sa QIODevice
+*/
+
+QIODevice* QAudioSource::start()
+{
+ if (!d)
+ return nullptr;
+ d->elapsedTime.start();
+ return d->start();
+}
+
+/*!
+ Returns the QAudioFormat being used.
+*/
+
+QAudioFormat QAudioSource::format() const
+{
+ return d ? d->format() : QAudioFormat();
+}
+
+/*!
+ Stops the audio input, detaching from the system resource.
+
+ Sets error() to QtAudio::NoError, state() to QtAudio::StoppedState and
+ emit stateChanged() signal.
+*/
+
+void QAudioSource::stop()
+{
+ if (d)
+ d->stop();
+}
+
+/*!
+ Drops all audio data in the buffers, resets buffers to zero.
+*/
+
+void QAudioSource::reset()
+{
+ if (d)
+ d->reset();
+}
+
+/*!
+ Stops processing audio data, preserving buffered audio data.
+
+ Sets error() to QtAudio::NoError, state() to QtAudio::SuspendedState and
+ emit stateChanged() signal.
+*/
+
+void QAudioSource::suspend()
+{
+ if (d)
+ d->suspend();
+}
+
+/*!
+ Resumes processing audio data after a suspend().
+
+ Sets error() to QtAudio::NoError.
+ Sets state() to QtAudio::ActiveState if you previously called start(QIODevice*).
+ Sets state() to QtAudio::IdleState if you previously called start().
+ emits stateChanged() signal.
+*/
+
+void QAudioSource::resume()
+{
+ if (d)
+ d->resume();
+}
+
+/*!
+ Sets the audio buffer size to \a value bytes.
+
+ Note: This function can be called anytime before start(), calls to this
+ are ignored after start(). It should not be assumed that the buffer size
+ set is the actual buffer size used, calling bufferSize() anytime after start()
+ will return the actual buffer size being used.
+
+*/
+
+void QAudioSource::setBufferSize(qsizetype value)
+{
+ if (d)
+ d->setBufferSize(value);
+}
+
+/*!
+ Returns the audio buffer size in bytes.
+
+ If called before start(), returns platform default value.
+ If called before start() but setBufferSize() was called prior, returns value set by setBufferSize().
+ If called after start(), returns the actual buffer size being used. This may not be what was set previously
+ by setBufferSize().
+
+*/
+
+qsizetype QAudioSource::bufferSize() const
+{
+ return d ? d->bufferSize() : 0;
+}
+
+/*!
+ Returns the amount of audio data available to read in bytes.
+
+ Note: returned value is only valid while in QtAudio::ActiveState or QtAudio::IdleState
+ state, otherwise returns zero.
+*/
+
+qsizetype QAudioSource::bytesAvailable() const
+{
+ /*
+ -If not ActiveState|IdleState, return 0
+ -return amount of audio data available to read
+ */
+ return d ? d->bytesReady() : 0;
+}
+
+/*!
+ Sets the input volume to \a volume.
+
+ The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this
+ range will be clamped.
+
+ If the device does not support adjusting the input
+ volume then \a volume will be ignored and the input
+ volume will remain at 1.0.
+
+ The default volume is \c 1.0.
+
+ Note: Adjustments to the volume will change the volume of this audio stream, not the global volume.
+*/
+void QAudioSource::setVolume(qreal volume)
+{
+ if (!d)
+ return;
+ qreal v = qBound(qreal(0.0), volume, qreal(1.0));
+ d->setVolume(v);
+}
+
+/*!
+ Returns the input volume.
+
+ If the device does not support adjusting the input volume
+ the returned value will be 1.0.
+*/
+qreal QAudioSource::volume() const
+{
+ return d ? d->volume() : 1.0;
+}
+
+/*!
+ Returns the amount of audio data processed since start()
+ was called in microseconds.
+*/
+
+qint64 QAudioSource::processedUSecs() const
+{
+ return d ? d->processedUSecs() : 0;
+}
+
+/*!
+ Returns the microseconds since start() was called, including time in Idle and
+ Suspend states.
+*/
+
+#include <qdebug.h>
+
+qint64 QAudioSource::elapsedUSecs() const
+{
+ return state() == QAudio::StoppedState ? 0 : d->elapsedTime.nsecsElapsed()/1000;
+}
+
+/*!
+ Returns the error state.
+*/
+
+QtAudio::Error QAudioSource::error() const
+{
+ return d ? d->error() : QAudio::OpenError;
+}
+
+/*!
+ Returns the state of audio processing.
+*/
+
+QtAudio::State QAudioSource::state() const
+{
+ return d ? d->state() : QAudio::StoppedState;
+}
+
+/*!
+ \fn QAudioSource::stateChanged(QtAudio::State state)
+ This signal is emitted when the device \a state has changed.
+
+ \note The QtAudio namespace was named QAudio up to and including Qt 6.6.
+ String-based connections to this signal have to use \c{QAudio::State} as
+ the parameter type: \c{connect(source, SIGNAL(stateChanged(QAudio::State)), ...);}
+*/
+
+QT_END_NAMESPACE
+
+#include "moc_qaudiosource.cpp"
+
diff --git a/src/multimedia/audio/qaudiosource.h b/src/multimedia/audio/qaudiosource.h
new file mode 100644
index 000000000..f0ad0ceb5
--- /dev/null
+++ b/src/multimedia/audio/qaudiosource.h
@@ -0,0 +1,72 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#ifndef QAUDIOINPUT_H
+#define QAUDIOINPUT_H
+
+#include <QtCore/qiodevice.h>
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+
+#include <QtMultimedia/qtaudio.h>
+#include <QtMultimedia/qaudioformat.h>
+#include <QtMultimedia/qaudiodevice.h>
+
+
+QT_BEGIN_NAMESPACE
+
+class QPlatformAudioSource;
+
+class Q_MULTIMEDIA_EXPORT QAudioSource : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit QAudioSource(const QAudioFormat &format = QAudioFormat(), QObject *parent = nullptr);
+ explicit QAudioSource(const QAudioDevice &audioDeviceInfo, const QAudioFormat &format = QAudioFormat(), QObject *parent = nullptr);
+ ~QAudioSource();
+
+ bool isNull() const { return !d; }
+
+ QAudioFormat format() const;
+
+ void start(QIODevice *device);
+ QIODevice* start();
+
+ void stop();
+ void reset();
+ void suspend();
+ void resume();
+
+ void setBufferSize(qsizetype bytes);
+ qsizetype bufferSize() const;
+
+ qsizetype bytesAvailable() const;
+
+ void setVolume(qreal volume);
+ qreal volume() const;
+
+ qint64 processedUSecs() const;
+ qint64 elapsedUSecs() const;
+
+ QtAudio::Error error() const;
+ QtAudio::State state() const;
+
+Q_SIGNALS:
+#if defined(Q_QDOC)
+ void stateChanged(QtAudio::State state);
+#else
+ // use QAudio here to keep string-based connections working
+ void stateChanged(QAudio::State state);
+#endif
+
+private:
+ Q_DISABLE_COPY(QAudioSource)
+
+ QPlatformAudioSource *d;
+};
+
+QT_END_NAMESPACE
+
+#endif // QAUDIOINPUT_H
diff --git a/src/multimedia/audio/qaudiostatemachine.cpp b/src/multimedia/audio/qaudiostatemachine.cpp
new file mode 100644
index 000000000..2d42200e6
--- /dev/null
+++ b/src/multimedia/audio/qaudiostatemachine.cpp
@@ -0,0 +1,150 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qaudiostatemachine_p.h"
+#include "qaudiosystem_p.h"
+#include <qpointer.h>
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+using Notifier = QAudioStateMachine::Notifier;
+using namespace AudioStateMachineUtils;
+
+QAudioStateMachine::QAudioStateMachine(QAudioStateChangeNotifier &notifier) : m_notifier(&notifier)
+{
+}
+
+QAudioStateMachine::~QAudioStateMachine() = default;
+
+QAudio::State QAudioStateMachine::state() const
+{
+ return toAudioState(m_state.load(std::memory_order_acquire));
+}
+
+QAudio::Error QAudioStateMachine::error() const
+{
+ return toAudioError(m_state.load(std::memory_order_acquire));
+}
+
+template <typename StatesChecker, typename NewState>
+Notifier QAudioStateMachine::changeState(const StatesChecker &checker, const NewState &newState)
+{
+ if constexpr (std::is_same_v<RawState, NewState>)
+ return changeState(checker, [newState](RawState) { return newState; });
+ else {
+ RawState prevState = m_state.load(std::memory_order_relaxed);
+ const auto exchanged = multipleCompareExchange(m_state, prevState, checker, newState);
+
+ if (Q_LIKELY(exchanged))
+ return { this, newState(prevState), prevState };
+
+ return {};
+ }
+}
+
+Notifier QAudioStateMachine::stop(QAudio::Error error, bool shouldDrain, bool forceUpdateError)
+{
+ auto statesChecker =
+ makeStatesChecker(QAudio::ActiveState, QAudio::IdleState, QAudio::SuspendedState,
+ forceUpdateError ? QAudio::StoppedState : QAudio::ActiveState);
+
+ const auto state = toRawState(QAudio::StoppedState, error);
+ auto getNewState = [&](RawState prevState) {
+ const bool shouldAddFlag = shouldDrain && toAudioState(prevState) == QAudio::ActiveState;
+ return shouldAddFlag ? addDrainingFlag(state) : state;
+ };
+
+ return changeState(statesChecker, getNewState);
+}
+
+Notifier QAudioStateMachine::start(bool active)
+{
+ return changeState(makeStatesChecker(QAudio::StoppedState),
+ toRawState(active ? QAudio::ActiveState : QAudio::IdleState));
+}
+
+bool QAudioStateMachine::isActiveOrIdle() const
+{
+ const auto state = this->state();
+ return state == QAudio::ActiveState || state == QAudio::IdleState;
+}
+
+bool QAudioStateMachine::onDrained()
+{
+ return changeState(isDrainingState, removeDrainingFlag);
+}
+
+bool QAudioStateMachine::isDraining() const
+{
+ return isDrainingState(m_state.load(std::memory_order_acquire));
+}
+
+std::pair<bool, bool> QAudioStateMachine::getDrainedAndStopped() const
+{
+ const auto state = m_state.load(std::memory_order_acquire);
+ return { !isDrainingState(state), toAudioState(state) == QAudio::StoppedState };
+}
+
+Notifier QAudioStateMachine::suspend()
+{
+ // Due to the current documentation, we set QAudio::NoError.
+ // TBD: leave the previous error should be more reasonable (IgnoreError)
+ const auto error = QAudio::NoError;
+ auto result = changeState(makeStatesChecker(QAudio::ActiveState, QAudio::IdleState),
+ toRawState(QAudio::SuspendedState, error));
+
+ if (result)
+ m_suspendedInState = result.prevAudioState();
+
+ return result;
+}
+
+Notifier QAudioStateMachine::resume()
+{
+ // Due to the current documentation, we set QAudio::NoError.
+ // TBD: leave the previous error should be more reasonable (IgnoreError)
+ const auto error = QAudio::NoError;
+ return changeState(makeStatesChecker(QAudio::SuspendedState),
+ toRawState(m_suspendedInState, error));
+}
+
+Notifier QAudioStateMachine::activateFromIdle()
+{
+ return changeState(makeStatesChecker(QAudio::IdleState), toRawState(QAudio::ActiveState));
+}
+
+Notifier QAudioStateMachine::updateActiveOrIdle(bool isActive, QAudio::Error error)
+{
+ const auto state = isActive ? QAudio::ActiveState : QAudio::IdleState;
+ return changeState(makeStatesChecker(QAudio::ActiveState, QAudio::IdleState),
+ toRawState(state, error));
+}
+
+Notifier QAudioStateMachine::setError(QAudio::Error error)
+{
+ auto fixState = [error](RawState prevState) { return setStateError(prevState, error); };
+ return changeState([](RawState) { return true; }, fixState);
+}
+
+Notifier QAudioStateMachine::forceSetState(QAudio::State state, QAudio::Error error)
+{
+ return changeState([](RawState) { return true; }, toRawState(state, error));
+}
+
+void QAudioStateMachine::reset(RawState state, RawState prevState)
+{
+ auto notifier = m_notifier;
+
+ const auto audioState = toAudioState(state);
+ const auto audioError = toAudioError(state);
+
+ if (toAudioState(prevState) != audioState && notifier)
+ emit notifier->stateChanged(audioState);
+
+ // check the notifier in case the object was deleted in
+ if (toAudioError(prevState) != audioError && notifier)
+ emit notifier->errorChanged(audioError);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiostatemachine_p.h b/src/multimedia/audio/qaudiostatemachine_p.h
new file mode 100644
index 000000000..385453020
--- /dev/null
+++ b/src/multimedia/audio/qaudiostatemachine_p.h
@@ -0,0 +1,149 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAUDIOSTATEMACHINE_P_H
+#define QAUDIOSTATEMACHINE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qaudiostatemachineutils_p.h"
+
+#include <qpointer.h>
+#include <atomic>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioStateChangeNotifier;
+
+/* QAudioStateMachine provides an opportunity to
+ * toggle QAudio::State with QAudio::Error in
+ * a thread-safe manner.
+ * The toggling functions return a notifier,
+ * which notifies about the change via
+ * QAudioStateChangeNotifier::stateChanged and errorChanged.
+ *
+ * The state machine is supposed to be used mostly in
+ * QAudioSink and QAudioSource implementations.
+ */
+class Q_MULTIMEDIA_EXPORT QAudioStateMachine
+{
+public:
+ using RawState = AudioStateMachineUtils::RawState;
+ class Notifier
+ {
+ public:
+ void reset()
+ {
+ if (auto stateMachine = std::exchange(m_stateMachine, nullptr))
+ stateMachine->reset(m_state, m_prevState);
+ }
+
+ ~Notifier() { reset(); }
+
+ Notifier(const Notifier &) = delete;
+ Notifier(Notifier &&other) noexcept
+ : m_stateMachine(std::exchange(other.m_stateMachine, nullptr)),
+ m_state(other.m_state),
+ m_prevState(other.m_prevState)
+ {
+ }
+
+ operator bool() const { return m_stateMachine != nullptr; }
+
+ QAudio::State prevAudioState() const { return AudioStateMachineUtils::toAudioState(m_prevState); }
+
+ QAudio::State audioState() const { return AudioStateMachineUtils::toAudioState(m_state); }
+
+ bool isDraining() const { return AudioStateMachineUtils::isDrainingState(m_state); }
+
+ bool isStateChanged() const { return prevAudioState() != audioState(); }
+
+ private:
+ Notifier(QAudioStateMachine *stateMachine = nullptr, RawState state = QAudio::StoppedState,
+ RawState prevState = QAudio::StoppedState)
+ : m_stateMachine(stateMachine), m_state(state), m_prevState(prevState)
+ {
+ }
+
+ private:
+ QAudioStateMachine *m_stateMachine;
+ RawState m_state;
+ const RawState m_prevState;
+
+ friend class QAudioStateMachine;
+ };
+
+ QAudioStateMachine(QAudioStateChangeNotifier &notifier);
+
+ ~QAudioStateMachine();
+
+ QAudio::State state() const;
+
+ QAudio::Error error() const;
+
+ bool isActiveOrIdle() const;
+
+ bool isDraining() const;
+
+ // atomicaly checks if the state is stopped and marked as drained
+ std::pair<bool, bool> getDrainedAndStopped() const;
+
+ // Stopped[draining] -> Stopped
+ bool onDrained();
+
+ // Active/Idle/Suspended -> Stopped
+ // or Active -> Stopped[draining] for shouldDrain = true
+ Notifier stop(QAudio::Error error = QAudio::NoError, bool shouldDrain = false,
+ bool forceUpdateError = false);
+
+ // Active/Idle/Suspended -> Stopped
+ Notifier stopOrUpdateError(QAudio::Error error = QAudio::NoError)
+ {
+ return stop(error, false, true);
+ }
+
+ // Stopped -> Active/Idle
+ Notifier start(bool isActive = true);
+
+ // Active/Idle -> Suspended + saves the exchanged state
+ Notifier suspend();
+
+ // Suspended -> saved state (Active/Idle)
+ Notifier resume();
+
+ // Idle -> Active
+ Notifier activateFromIdle();
+
+ // Active/Idle -> Active/Idle + updateError
+ Notifier updateActiveOrIdle(bool isActive, QAudio::Error error = QAudio::NoError);
+
+ // Any -> Any; better use more strict methods
+ Notifier forceSetState(QAudio::State state, QAudio::Error error = QAudio::NoError);
+
+ // force set the error
+ Notifier setError(QAudio::Error error);
+
+private:
+ template <typename StatesChecker, typename NewState>
+ Notifier changeState(const StatesChecker &statesChecker, const NewState &newState);
+
+ void reset(RawState state, RawState prevState);
+
+private:
+ QPointer<QAudioStateChangeNotifier> m_notifier;
+ std::atomic<RawState> m_state = QAudio::StoppedState;
+ QAudio::State m_suspendedInState = QAudio::SuspendedState;
+};
+
+QT_END_NAMESPACE
+
+#endif // QAUDIOSTATEMACHINE_P_H
diff --git a/src/multimedia/audio/qaudiostatemachineutils_p.h b/src/multimedia/audio/qaudiostatemachineutils_p.h
new file mode 100644
index 000000000..f80517f77
--- /dev/null
+++ b/src/multimedia/audio/qaudiostatemachineutils_p.h
@@ -0,0 +1,96 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAUDIOSTATEMACHINEUTILS_P_H
+#define QAUDIOSTATEMACHINEUTILS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qaudio.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace AudioStateMachineUtils {
+
+using RawState = int;
+
+constexpr uint32_t AudioStateBitsCount = 8;
+constexpr RawState AudioStateMask = 0xFF;
+constexpr RawState AudioErrorMask = 0xFF00;
+constexpr RawState DrainingFlag = 0x10000;
+
+static_assert(!(AudioStateMask & DrainingFlag) && !(AudioStateMask & AudioErrorMask)
+ && !(AudioErrorMask & DrainingFlag),
+ "Invalid masks");
+
+constexpr bool isDrainingState(RawState state)
+{
+ return (state & DrainingFlag) != 0;
+}
+
+constexpr RawState addDrainingFlag(RawState state)
+{
+ return state | DrainingFlag;
+}
+
+constexpr RawState removeDrainingFlag(RawState state)
+{
+ return state & ~DrainingFlag;
+}
+
+constexpr QAudio::State toAudioState(RawState state)
+{
+ return QAudio::State(state & AudioStateMask);
+}
+
+constexpr QAudio::Error toAudioError(RawState state)
+{
+ return QAudio::Error((state & AudioErrorMask) >> AudioStateBitsCount);
+}
+
+constexpr RawState toRawState(QAudio::State state, QAudio::Error error = QAudio::NoError)
+{
+ return state | (error << AudioStateBitsCount);
+}
+
+constexpr RawState setStateError(RawState state, QAudio::Error error)
+{
+ return (error << AudioStateBitsCount) | (state & ~AudioErrorMask);
+}
+
+template <typename... States>
+constexpr auto makeStatesChecker(States... states)
+{
+ return [=](RawState state) {
+ state &= (AudioStateMask | DrainingFlag);
+ return (... || (state == states));
+ };
+}
+
+// ensures compareExchange (testAndSet) operation with opportunity
+// to check several states, can be considered as atomic
+template <typename T, typename Predicate, typename NewValueGetter>
+bool multipleCompareExchange(std::atomic<T> &target, T &prevValue, Predicate predicate,
+ NewValueGetter newValueGetter)
+{
+ while (predicate(prevValue))
+ if (target.compare_exchange_strong(prevValue, newValueGetter(prevValue),
+ std::memory_order_acq_rel))
+ return true;
+
+ return false;
+}
+} // namespace AudioStateMachineUtils
+
+QT_END_NAMESPACE
+
+#endif // QAUDIOSTATEMACHINEUTILS_P_H
diff --git a/src/multimedia/audio/qaudiosystem.cpp b/src/multimedia/audio/qaudiosystem.cpp
index b11993e55..355771f6b 100644
--- a/src/multimedia/audio/qaudiosystem.cpp
+++ b/src/multimedia/audio/qaudiosystem.cpp
@@ -1,376 +1,23 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-#include "qaudiosystem.h"
+#include "qaudiosystem_p.h"
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QAbstractAudioDeviceInfo
- \brief The QAbstractAudioDeviceInfo class is a base class for audio backends.
-
- \ingroup multimedia
- \ingroup multimedia_audio
- \inmodule QtMultimedia
-
- This class implements the audio functionality for
- QAudioDeviceInfo, i.e., QAudioDeviceInfo keeps a
- QAbstractAudioDeviceInfo and routes function calls to it. For a
- description of the functionality that QAbstractAudioDeviceInfo
- implements, you can read the class and functions documentation of
- QAudioDeviceInfo.
-
- \sa QAudioDeviceInfo
- \sa QAbstractAudioOutput, QAbstractAudioInput
-*/
-
-/*!
- \fn virtual QAudioFormat QAbstractAudioDeviceInfo::preferredFormat() const
- Returns the recommended settings to use.
-*/
-
-/*!
- \fn virtual bool QAbstractAudioDeviceInfo::isFormatSupported(const QAudioFormat& format) const
- Returns true if \a format is available from audio device.
-*/
-
-/*!
- \fn virtual QString QAbstractAudioDeviceInfo::deviceName() const
- Returns the audio device name.
-*/
-
-/*!
- \fn virtual QStringList QAbstractAudioDeviceInfo::supportedCodecs()
- Returns the list of currently available codecs.
-*/
-
-/*!
- \fn virtual QList<int> QAbstractAudioDeviceInfo::supportedSampleRates()
- Returns the list of currently available sample rates.
-*/
-
-/*!
- \fn virtual QList<int> QAbstractAudioDeviceInfo::supportedChannelCounts()
- Returns the list of currently available channels.
-*/
-
-/*!
- \fn virtual QList<int> QAbstractAudioDeviceInfo::supportedSampleSizes()
- Returns the list of currently available sample sizes.
-*/
-
-/*!
- \fn virtual QList<QAudioFormat::Endian> QAbstractAudioDeviceInfo::supportedByteOrders()
- Returns the list of currently available byte orders.
-*/
-
-/*!
- \fn virtual QList<QAudioFormat::SampleType> QAbstractAudioDeviceInfo::supportedSampleTypes()
- Returns the list of currently available sample types.
-*/
-
-/*!
- \class QAbstractAudioOutput
- \brief The QAbstractAudioOutput class is a base class for audio backends.
-
- \ingroup multimedia
- \inmodule QtMultimedia
-
- QAbstractAudioOutput implements audio functionality for
- QAudioOutput, i.e., QAudioOutput routes function calls to
- QAbstractAudioOutput. For a description of the functionality that
- is implemented, see the QAudioOutput class and function
- descriptions.
-
- \sa QAudioOutput
-*/
-
-/*!
- \fn virtual void QAbstractAudioOutput::start(QIODevice* device)
- Uses the \a device as the QIODevice to transfer data.
-*/
-
-/*!
- \fn virtual QIODevice* QAbstractAudioOutput::start()
- Returns a pointer to the QIODevice being used to handle
- the data transfer. This QIODevice can be used to write() audio data directly.
-*/
-
-/*!
- \fn virtual void QAbstractAudioOutput::stop()
- Stops the audio output.
-*/
-
-/*!
- \fn virtual void QAbstractAudioOutput::reset()
- Drops all audio data in the buffers, resets buffers to zero.
-*/
-
-/*!
- \fn virtual void QAbstractAudioOutput::suspend()
- Stops processing audio data, preserving buffered audio data.
-*/
-
-/*!
- \fn virtual void QAbstractAudioOutput::resume()
- Resumes processing audio data after a suspend()
-*/
-
-/*!
- \fn virtual int QAbstractAudioOutput::bytesFree() const
- Returns the free space available in bytes in the audio buffer.
-*/
-
-/*!
- \fn virtual int QAbstractAudioOutput::periodSize() const
- Returns the period size in bytes.
-*/
-
-/*!
- \fn virtual void QAbstractAudioOutput::setBufferSize(int value)
- Sets the audio buffer size to \a value in bytes.
-*/
-
-/*!
- \fn virtual int QAbstractAudioOutput::bufferSize() const
- Returns the audio buffer size in bytes.
-*/
-
-/*!
- \fn virtual void QAbstractAudioOutput::setNotifyInterval(int ms)
- Sets the interval for notify() signal to be emitted. This is based on the \a ms
- of audio data processed not on actual real-time. The resolution of the timer
- is platform specific.
-*/
-
-/*!
- \fn virtual int QAbstractAudioOutput::notifyInterval() const
- Returns the notify interval in milliseconds.
-*/
-
-/*!
- \fn virtual qint64 QAbstractAudioOutput::processedUSecs() const
- Returns the amount of audio data processed since start() was called in milliseconds.
-*/
-
-/*!
- \fn virtual qint64 QAbstractAudioOutput::elapsedUSecs() const
- Returns the milliseconds since start() was called, including time in Idle and suspend states.
-*/
+#include <private/qplatformmediadevices_p.h>
-/*!
- \fn virtual QAudio::Error QAbstractAudioOutput::error() const
- Returns the error state.
-*/
-
-/*!
- \fn virtual QAudio::State QAbstractAudioOutput::state() const
- Returns the state of audio processing.
-*/
-
-/*!
- \fn virtual void QAbstractAudioOutput::setFormat(const QAudioFormat& fmt)
- Set the QAudioFormat to use to \a fmt.
- Setting the format is only allowable while in QAudio::StoppedState.
-*/
-
-/*!
- \fn virtual QAudioFormat QAbstractAudioOutput::format() const
- Returns the QAudioFormat being used.
-*/
-
-/*!
- \fn virtual void QAbstractAudioOutput::setVolume(qreal volume)
- Sets the volume.
- Where \a volume is between 0.0 and 1.0.
-*/
-
-/*!
- \fn virtual qreal QAbstractAudioOutput::volume() const
- Returns the volume in the range 0.0 and 1.0.
-*/
-
-/*!
- \fn QAbstractAudioOutput::errorChanged(QAudio::Error error)
- This signal is emitted when the \a error state has changed.
-*/
-
-/*!
- \fn QAbstractAudioOutput::stateChanged(QAudio::State state)
- This signal is emitted when the device \a state has changed.
-*/
-
-/*!
- \fn QAbstractAudioOutput::notify()
- This signal is emitted when x ms of audio data has been processed
- the interval set by setNotifyInterval(x).
-*/
-
-
-/*!
- \class QAbstractAudioInput
- \brief The QAbstractAudioInput class provides access for QAudioInput to access the audio
- device provided by the plugin.
-
- \ingroup multimedia
- \inmodule QtMultimedia
-
- QAudioDeviceInput keeps an instance of QAbstractAudioInput and
- routes calls to functions of the same name to QAbstractAudioInput.
- This means that it is QAbstractAudioInput that implements the
- audio functionality. For a description of the functionality, see
- the QAudioInput class description.
-
- \sa QAudioInput
-*/
-
-/*!
- \fn virtual void QAbstractAudioInput::start(QIODevice* device)
- Uses the \a device as the QIODevice to transfer data.
-*/
-
-/*!
- \fn virtual QIODevice* QAbstractAudioInput::start()
- Returns a pointer to the QIODevice being used to handle
- the data transfer. This QIODevice can be used to read() audio data directly.
-*/
-
-/*!
- \fn virtual void QAbstractAudioInput::stop()
- Stops the audio input.
-*/
-
-/*!
- \fn virtual void QAbstractAudioInput::reset()
- Drops all audio data in the buffers, resets buffers to zero.
-*/
-
-/*!
- \fn virtual void QAbstractAudioInput::suspend()
- Stops processing audio data, preserving buffered audio data.
-*/
-
-/*!
- \fn virtual void QAbstractAudioInput::resume()
- Resumes processing audio data after a suspend().
-*/
-
-/*!
- \fn virtual int QAbstractAudioInput::bytesReady() const
- Returns the amount of audio data available to read in bytes.
-*/
-
-/*!
- \fn virtual int QAbstractAudioInput::periodSize() const
- Returns the period size in bytes.
-*/
-
-/*!
- \fn virtual void QAbstractAudioInput::setBufferSize(int value)
- Sets the audio buffer size to \a value in milliseconds.
-*/
-
-/*!
- \fn virtual int QAbstractAudioInput::bufferSize() const
- Returns the audio buffer size in milliseconds.
-*/
-
-/*!
- \fn virtual void QAbstractAudioInput::setNotifyInterval(int ms)
- Sets the interval for notify() signal to be emitted. This is based
- on the \a ms of audio data processed not on actual real-time.
- The resolution of the timer is platform specific.
-*/
-
-/*!
- \fn virtual int QAbstractAudioInput::notifyInterval() const
- Returns the notify interval in milliseconds.
-*/
-
-/*!
- \fn virtual qint64 QAbstractAudioInput::processedUSecs() const
- Returns the amount of audio data processed since start() was called in milliseconds.
-*/
-
-/*!
- \fn virtual qint64 QAbstractAudioInput::elapsedUSecs() const
- Returns the milliseconds since start() was called, including time in Idle and suspend states.
-*/
-
-/*!
- \fn virtual QAudio::Error QAbstractAudioInput::error() const
- Returns the error state.
-*/
-
-/*!
- \fn virtual QAudio::State QAbstractAudioInput::state() const
- Returns the state of audio processing.
-*/
-
-/*!
- \fn virtual void QAbstractAudioInput::setFormat(const QAudioFormat& fmt)
- Set the QAudioFormat to use to \a fmt.
- Setting the format is only allowable while in QAudio::StoppedState.
-*/
-
-/*!
- \fn virtual QAudioFormat QAbstractAudioInput::format() const
- Returns the QAudioFormat being used
-*/
+QT_BEGIN_NAMESPACE
-/*!
- \fn QAbstractAudioInput::errorChanged(QAudio::Error error)
- This signal is emitted when the \a error state has changed.
-*/
+QAudioStateChangeNotifier::QAudioStateChangeNotifier(QObject *parent) : QObject(parent) { }
-/*!
- \fn QAbstractAudioInput::stateChanged(QAudio::State state)
- This signal is emitted when the device \a state has changed.
-*/
+QPlatformAudioSink::QPlatformAudioSink(QObject *parent) : QAudioStateChangeNotifier(parent) { }
-/*!
- \fn QAbstractAudioInput::notify()
- This signal is emitted when x ms of audio data has been processed
- the interval set by setNotifyInterval(x).
-*/
+qreal QPlatformAudioSink::volume() const
+{
+ return 1.0;
+}
+QPlatformAudioSource::QPlatformAudioSource(QObject *parent) : QAudioStateChangeNotifier(parent) { }
QT_END_NAMESPACE
-#include "moc_qaudiosystem.cpp"
+#include "moc_qaudiosystem_p.cpp"
diff --git a/src/multimedia/audio/qaudiosystem.h b/src/multimedia/audio/qaudiosystem.h
deleted file mode 100644
index c326460fe..000000000
--- a/src/multimedia/audio/qaudiosystem.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIOSYSTEM_H
-#define QAUDIOSYSTEM_H
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
-
-#include <QtMultimedia/qaudio.h>
-#include <QtMultimedia/qaudioformat.h>
-#include <QtMultimedia/qaudiodeviceinfo.h>
-
-QT_BEGIN_NAMESPACE
-
-class QIODevice;
-
-class Q_MULTIMEDIA_EXPORT QAbstractAudioDeviceInfo : public QObject
-{
- Q_OBJECT
-
-public:
- virtual QAudioFormat preferredFormat() const = 0;
- virtual bool isFormatSupported(const QAudioFormat &format) const = 0;
- virtual QString deviceName() const = 0;
- virtual QStringList supportedCodecs() = 0;
- virtual QList<int> supportedSampleRates() = 0;
- virtual QList<int> supportedChannelCounts() = 0;
- virtual QList<int> supportedSampleSizes() = 0;
- virtual QList<QAudioFormat::Endian> supportedByteOrders() = 0;
- virtual QList<QAudioFormat::SampleType> supportedSampleTypes() = 0;
-};
-
-class Q_MULTIMEDIA_EXPORT QAbstractAudioOutput : public QObject
-{
- Q_OBJECT
-
-public:
- virtual void start(QIODevice *device) = 0;
- virtual QIODevice* start() = 0;
- virtual void stop() = 0;
- virtual void reset() = 0;
- virtual void suspend() = 0;
- virtual void resume() = 0;
- virtual int bytesFree() const = 0;
- virtual int periodSize() const = 0;
- virtual void setBufferSize(int value) = 0;
- virtual int bufferSize() const = 0;
- virtual void setNotifyInterval(int milliSeconds) = 0;
- virtual int notifyInterval() const = 0;
- virtual qint64 processedUSecs() const = 0;
- virtual qint64 elapsedUSecs() const = 0;
- virtual QAudio::Error error() const = 0;
- virtual QAudio::State state() const = 0;
- virtual void setFormat(const QAudioFormat& fmt) = 0;
- virtual QAudioFormat format() const = 0;
- virtual void setVolume(qreal) {}
- virtual qreal volume() const { return 1.0; }
- virtual QString category() const { return QString(); }
- virtual void setCategory(const QString &) { }
-
-Q_SIGNALS:
- void errorChanged(QAudio::Error error);
- void stateChanged(QAudio::State state);
- void notify();
-};
-
-class Q_MULTIMEDIA_EXPORT QAbstractAudioInput : public QObject
-{
- Q_OBJECT
-
-public:
- virtual void start(QIODevice *device) = 0;
- virtual QIODevice* start() = 0;
- virtual void stop() = 0;
- virtual void reset() = 0;
- virtual void suspend() = 0;
- virtual void resume() = 0;
- virtual int bytesReady() const = 0;
- virtual int periodSize() const = 0;
- virtual void setBufferSize(int value) = 0;
- virtual int bufferSize() const = 0;
- virtual void setNotifyInterval(int milliSeconds) = 0;
- virtual int notifyInterval() const = 0;
- virtual qint64 processedUSecs() const = 0;
- virtual qint64 elapsedUSecs() const = 0;
- virtual QAudio::Error error() const = 0;
- virtual QAudio::State state() const = 0;
- virtual void setFormat(const QAudioFormat& fmt) = 0;
- virtual QAudioFormat format() const = 0;
- virtual void setVolume(qreal) = 0;
- virtual qreal volume() const = 0;
-
-Q_SIGNALS:
- void errorChanged(QAudio::Error error);
- void stateChanged(QAudio::State state);
- void notify();
-};
-
-QT_END_NAMESPACE
-
-#endif // QAUDIOSYSTEM_H
diff --git a/src/multimedia/audio/qaudiosystem_p.h b/src/multimedia/audio/qaudiosystem_p.h
new file mode 100644
index 000000000..4a0650e80
--- /dev/null
+++ b/src/multimedia/audio/qaudiosystem_p.h
@@ -0,0 +1,96 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAUDIOSYSTEM_H
+#define QAUDIOSYSTEM_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+
+#include <QtMultimedia/qaudio.h>
+#include <QtMultimedia/qaudioformat.h>
+#include <QtMultimedia/qaudiodevice.h>
+
+#include <QtCore/qelapsedtimer.h>
+#include <QtCore/private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QIODevice;
+
+class Q_MULTIMEDIA_EXPORT QAudioStateChangeNotifier : public QObject
+{
+ Q_OBJECT
+public:
+ QAudioStateChangeNotifier(QObject *parent = nullptr);
+
+signals:
+ void errorChanged(QAudio::Error error);
+ void stateChanged(QAudio::State state);
+};
+
+class Q_MULTIMEDIA_EXPORT QPlatformAudioSink : public QAudioStateChangeNotifier
+{
+ Q_OBJECT
+
+public:
+ QPlatformAudioSink(QObject *parent);
+ virtual void start(QIODevice *device) = 0;
+ virtual QIODevice* start() = 0;
+ virtual void stop() = 0;
+ virtual void reset() = 0;
+ virtual void suspend() = 0;
+ virtual void resume() = 0;
+ virtual qsizetype bytesFree() const = 0;
+ virtual void setBufferSize(qsizetype value) = 0;
+ virtual qsizetype bufferSize() const = 0;
+ virtual qint64 processedUSecs() const = 0;
+ virtual QAudio::Error error() const = 0;
+ virtual QAudio::State state() const = 0;
+ virtual void setFormat(const QAudioFormat& fmt) = 0;
+ virtual QAudioFormat format() const = 0;
+ virtual void setVolume(qreal) {}
+ virtual qreal volume() const;
+
+ QElapsedTimer elapsedTime;
+};
+
+class Q_MULTIMEDIA_EXPORT QPlatformAudioSource : public QAudioStateChangeNotifier
+{
+ Q_OBJECT
+
+public:
+ QPlatformAudioSource(QObject *parent);
+ virtual void start(QIODevice *device) = 0;
+ virtual QIODevice* start() = 0;
+ virtual void stop() = 0;
+ virtual void reset() = 0;
+ virtual void suspend() = 0;
+ virtual void resume() = 0;
+ virtual qsizetype bytesReady() const = 0;
+ virtual void setBufferSize(qsizetype value) = 0;
+ virtual qsizetype bufferSize() const = 0;
+ virtual qint64 processedUSecs() const = 0;
+ virtual QAudio::Error error() const = 0;
+ virtual QAudio::State state() const = 0;
+ virtual void setFormat(const QAudioFormat& fmt) = 0;
+ virtual QAudioFormat format() const = 0;
+ virtual void setVolume(qreal) = 0;
+ virtual qreal volume() const = 0;
+
+ QElapsedTimer elapsedTime;
+};
+
+QT_END_NAMESPACE
+
+#endif // QAUDIOSYSTEM_H
diff --git a/src/multimedia/audio/qaudiosystemplugin.cpp b/src/multimedia/audio/qaudiosystemplugin.cpp
deleted file mode 100644
index cb5628477..000000000
--- a/src/multimedia/audio/qaudiosystemplugin.cpp
+++ /dev/null
@@ -1,138 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include "qaudiosystemplugin.h"
-#include "qaudiosystempluginext_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QAudioSystemFactoryInterface::~QAudioSystemFactoryInterface()
-{
-}
-
-QAudioSystemPluginExtension::~QAudioSystemPluginExtension()
-{
-}
-
-/*!
- \class QAudioSystemPlugin
- \brief The QAudioSystemPlugin class provides an abstract base for audio plugins.
-
- \ingroup multimedia
- \ingroup multimedia_audio
- \inmodule QtMultimedia
-
- Writing a audio plugin is achieved by subclassing this base class,
- reimplementing the pure virtual functions availableDevices(),
- createInput(), createOutput() and createDeviceInfo() then exporting
- the class with the Q_PLUGIN_METADATA() macro.
-
- The json file containing the meta data should contain a list of keys
- matching the plugin. Add "default" to your list of keys available
- to override the default audio device to be provided by your plugin.
-
- \code
- { "Keys": [ "default" ] }
- \endcode
-
- Unit tests are available to help in debugging new plugins.
-
- \sa QAbstractAudioDeviceInfo, QAbstractAudioOutput, QAbstractAudioInput
-
- Qt comes with plugins for Windows (WinMM and WASAPI), Linux (ALSA and PulseAudio), \macos / iOS
- (CoreAudio), Android (OpenSL ES) and QNX.
-
- If no audio plugins are available, a fallback dummy backend will be used.
- This should print out warnings if this is the case when you try and use QAudioInput
- or QAudioOutput. To fix this problem, make sure the dependencies for the Qt plugins are
- installed on the system and reconfigure Qt (e.g. alsa-devel package on Linux), or create your
- own plugin with a default key to always override the dummy fallback. The easiest way to
- determine if you have only a dummy backend is to get a list of available audio devices.
-
- QAudioDeviceInfo::availableDevices(QAudio::AudioOutput).size() = 0 (dummy backend)
-*/
-
-/*!
- \fn QAudioSystemPlugin::QAudioSystemPlugin(QObject* parent)
-
- Constructs a new audio plugin with \a parent.
- This is invoked automatically by the Q_PLUGIN_METADATA() macro.
-*/
-
-QAudioSystemPlugin::QAudioSystemPlugin(QObject* parent) :
- QObject(parent)
-{}
-
-/*!
- \fn QAudioSystemPlugin::~QAudioSystemPlugin()
-
- Destroys the audio plugin.
- You never have to call this explicitly. Qt destroys a plugin automatically when it is no longer used.
-*/
-
-QAudioSystemPlugin::~QAudioSystemPlugin()
-{}
-
-/*!
- \fn QList<QByteArray> QAudioSystemPlugin::availableDevices(QAudio::Mode mode) const
- Returns a list of available audio devices for \a mode
-*/
-
-/*!
- \fn QAbstractAudioInput* QAudioSystemPlugin::createInput(const QByteArray& device)
- Returns a pointer to a QAbstractAudioInput created using \a device identifier
-*/
-
-/*!
- \fn QAbstractAudioOutput* QAudioSystemPlugin::createOutput(const QByteArray& device)
- Returns a pointer to a QAbstractAudioOutput created using \a device identifier
-
-*/
-
-/*!
- \fn QAbstractAudioDeviceInfo* QAudioSystemPlugin::createDeviceInfo(const QByteArray& device, QAudio::Mode mode)
- Returns a pointer to a QAbstractAudioDeviceInfo created using \a device and \a mode
-
-*/
-
-
-QT_END_NAMESPACE
-
-#include "moc_qaudiosystemplugin.cpp"
diff --git a/src/multimedia/audio/qaudiosystemplugin.h b/src/multimedia/audio/qaudiosystemplugin.h
deleted file mode 100644
index 18079e9d9..000000000
--- a/src/multimedia/audio/qaudiosystemplugin.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QAUDIOSYSTEMPLUGIN_H
-#define QAUDIOSYSTEMPLUGIN_H
-
-#include <QtCore/qstring.h>
-#include <QtCore/qplugin.h>
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
-
-#include <QtMultimedia/qaudioformat.h>
-#include <QtMultimedia/qaudiodeviceinfo.h>
-#include <QtMultimedia/qaudiosystem.h>
-
-QT_BEGIN_NAMESPACE
-
-struct Q_MULTIMEDIA_EXPORT QAudioSystemFactoryInterface
-{
- virtual QList<QByteArray> availableDevices(QAudio::Mode) const = 0;
- virtual QAbstractAudioInput* createInput(const QByteArray& device) = 0;
- virtual QAbstractAudioOutput* createOutput(const QByteArray& device) = 0;
- virtual QAbstractAudioDeviceInfo* createDeviceInfo(const QByteArray& device, QAudio::Mode mode) = 0;
- virtual ~QAudioSystemFactoryInterface();
-};
-
-#define QAudioSystemFactoryInterface_iid \
- "org.qt-project.qt.audiosystemfactory/5.0"
-Q_DECLARE_INTERFACE(QAudioSystemFactoryInterface, QAudioSystemFactoryInterface_iid)
-
-class Q_MULTIMEDIA_EXPORT QAudioSystemPlugin : public QObject, public QAudioSystemFactoryInterface
-{
- Q_OBJECT
- Q_INTERFACES(QAudioSystemFactoryInterface)
-
-public:
- explicit QAudioSystemPlugin(QObject *parent = nullptr);
- ~QAudioSystemPlugin();
-
- QList<QByteArray> availableDevices(QAudio::Mode) const override = 0;
- QAbstractAudioInput* createInput(const QByteArray& device) override = 0;
- QAbstractAudioOutput* createOutput(const QByteArray& device) override = 0;
- QAbstractAudioDeviceInfo* createDeviceInfo(const QByteArray& device, QAudio::Mode mode) override = 0;
-};
-
-QT_END_NAMESPACE
-
-#endif // QAUDIOSYSTEMPLUGIN_H
diff --git a/src/multimedia/audio/qaudiosystempluginext_p.h b/src/multimedia/audio/qaudiosystempluginext_p.h
deleted file mode 100644
index 6493b7f77..000000000
--- a/src/multimedia/audio/qaudiosystempluginext_p.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIOSYSTEMPLUGINEXT_P_H
-#define QAUDIOSYSTEMPLUGINEXT_P_H
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qaudio.h>
-#include <QtCore/qplugin.h>
-
-QT_BEGIN_NAMESPACE
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-struct Q_MULTIMEDIA_EXPORT QAudioSystemPluginExtension
-{
- virtual QByteArray defaultDevice(QAudio::Mode) const = 0;
- virtual ~QAudioSystemPluginExtension();
-};
-
-#define QAudioSystemPluginExtension_iid "org.qt-project.qt.audiosystempluginextension"
-Q_DECLARE_INTERFACE(QAudioSystemPluginExtension, QAudioSystemPluginExtension_iid)
-
-QT_END_NAMESPACE
-
-#endif // QAUDIOSYSTEMPLUGINEXT_P_H
diff --git a/src/multimedia/audio/qsamplecache_p.cpp b/src/multimedia/audio/qsamplecache_p.cpp
index b293946cc..b4be09f72 100644
--- a/src/multimedia/audio/qsamplecache_p.cpp
+++ b/src/multimedia/audio/qsamplecache_p.cpp
@@ -1,51 +1,17 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsamplecache_p.h"
-#include "qwavedecoder_p.h"
+#include "qwavedecoder.h"
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QtCore/QDebug>
-//#define QT_SAMPLECACHE_DEBUG
+#include <QtCore/qloggingcategory.h>
+
+static Q_LOGGING_CATEGORY(qLcSampleCache, "qt.multimedia.samplecache")
#include <mutex>
@@ -105,8 +71,6 @@ QSampleCache::QSampleCache(QObject *parent)
, m_loadingRefCount(0)
{
m_loadingThread.setObjectName(QLatin1String("QSampleCache::LoadingThread"));
- connect(&m_loadingThread, SIGNAL(finished()), this, SIGNAL(isLoadingChanged()));
- connect(&m_loadingThread, SIGNAL(started()), this, SIGNAL(isLoadingChanged()));
}
QNetworkAccessManager& QSampleCache::networkAccessManager()
@@ -166,22 +130,25 @@ QSample* QSampleCache::requestSample(const QUrl& url)
{
//lock and add first to make sure live loadingThread will not be killed during this function call
m_loadingMutex.lock();
+ const bool needsThreadStart = m_loadingRefCount == 0;
m_loadingRefCount++;
m_loadingMutex.unlock();
- if (!m_loadingThread.isRunning())
- m_loadingThread.start();
-
-#ifdef QT_SAMPLECACHE_DEBUG
- qDebug() << "QSampleCache: request sample [" << url << "]";
-#endif
+ qCDebug(qLcSampleCache) << "QSampleCache: request sample [" << url << "]";
std::unique_lock<QRecursiveMutex> locker(m_mutex);
QMap<QUrl, QSample*>::iterator it = m_samples.find(url);
QSample* sample;
if (it == m_samples.end()) {
+ if (needsThreadStart) {
+ // Previous thread might be finishing, need to wait for it. If not, this is a no-op.
+ m_loadingThread.wait();
+ m_loadingThread.start();
+ }
sample = new QSample(url, this);
m_samples.insert(url, sample);
+#if QT_CONFIG(thread)
sample->moveToThread(&m_loadingThread);
+#endif
} else {
sample = *it;
}
@@ -198,9 +165,7 @@ void QSampleCache::setCapacity(qint64 capacity)
const std::lock_guard<QRecursiveMutex> locker(m_mutex);
if (m_capacity == capacity)
return;
-#ifdef QT_SAMPLECACHE_DEBUG
- qDebug() << "QSampleCache: capacity changes from " << m_capacity << "to " << capacity;
-#endif
+ qCDebug(qLcSampleCache) << "QSampleCache: capacity changes from " << m_capacity << "to " << capacity;
if (m_capacity > 0 && capacity <= 0) { //memory management strategy changed
for (QMap<QUrl, QSample*>::iterator it = m_samples.begin(); it != m_samples.end();) {
QSample* sample = *it;
@@ -233,9 +198,7 @@ void QSampleCache::refresh(qint64 usageChange)
if (m_capacity <= 0 || m_usage <= m_capacity)
return;
-#ifdef QT_SAMPLECACHE_DEBUG
qint64 recoveredSize = 0;
-#endif
//free unused samples to keep usage under capacity limit.
for (QMap<QUrl, QSample*>::iterator it = m_samples.begin(); it != m_samples.end();) {
@@ -244,20 +207,16 @@ void QSampleCache::refresh(qint64 usageChange)
++it;
continue;
}
-#ifdef QT_SAMPLECACHE_DEBUG
recoveredSize += sample->m_soundData.size();
-#endif
unloadSample(sample);
it = m_samples.erase(it);
if (m_usage <= m_capacity)
return;
}
-#ifdef QT_SAMPLECACHE_DEBUG
- qDebug() << "QSampleCache: refresh(" << usageChange
+ qCDebug(qLcSampleCache) << "QSampleCache: refresh(" << usageChange
<< ") recovered size =" << recoveredSize
<< "new usage =" << m_usage;
-#endif
if (m_usage > m_capacity)
qWarning() << "QSampleCache: usage[" << m_usage << " out of limit[" << m_capacity << "]";
@@ -278,9 +237,7 @@ QSample::~QSample()
m_parent->removeUnreferencedSample(this);
QMutexLocker locker(&m_mutex);
-#ifdef QT_SAMPLECACHE_DEBUG
- qDebug() << "~QSample" << this << ": deleted [" << m_url << "]" << QThread::currentThread();
-#endif
+ qCDebug(qLcSampleCache) << "~QSample" << this << ": deleted [" << m_url << "]" << QThread::currentThread();
cleanup();
}
@@ -315,9 +272,7 @@ bool QSampleCache::notifyUnreferencedSample(QSample* sample)
void QSample::release()
{
QMutexLocker locker(&m_mutex);
-#ifdef QT_SAMPLECACHE_DEBUG
- qDebug() << "Sample:: release" << this << QThread::currentThread() << m_ref;
-#endif
+ qCDebug(qLcSampleCache) << "Sample:: release" << this << QThread::currentThread() << m_ref;
if (--m_ref == 0) {
locker.unlock();
m_parent->notifyUnreferencedSample(this);
@@ -328,10 +283,15 @@ void QSample::release()
// must be called locked.
void QSample::cleanup()
{
- if (m_waveDecoder)
+ qCDebug(qLcSampleCache) << "QSample: cleanup";
+ if (m_waveDecoder) {
+ m_waveDecoder->disconnect(this);
m_waveDecoder->deleteLater();
- if (m_stream)
+ }
+ if (m_stream) {
+ m_stream->disconnect(this);
m_stream->deleteLater();
+ }
m_waveDecoder = nullptr;
m_stream = nullptr;
@@ -346,14 +306,14 @@ void QSample::addRef()
// Called in loading thread
void QSample::readSample()
{
+#if QT_CONFIG(thread)
Q_ASSERT(QThread::currentThread()->objectName() == QLatin1String("QSampleCache::LoadingThread"));
- QMutexLocker m(&m_mutex);
-#ifdef QT_SAMPLECACHE_DEBUG
- qDebug() << "QSample: readSample";
#endif
+ QMutexLocker m(&m_mutex);
qint64 read = m_waveDecoder->read(m_soundData.data() + m_sampleReadLength,
qMin(m_waveDecoder->bytesAvailable(),
qint64(m_waveDecoder->size() - m_sampleReadLength)));
+ qCDebug(qLcSampleCache) << "QSample: readSample" << read;
if (read > 0)
m_sampleReadLength += read;
if (m_sampleReadLength < m_waveDecoder->size())
@@ -365,16 +325,17 @@ void QSample::readSample()
// Called in loading thread
void QSample::decoderReady()
{
+#if QT_CONFIG(thread)
Q_ASSERT(QThread::currentThread()->objectName() == QLatin1String("QSampleCache::LoadingThread"));
- QMutexLocker m(&m_mutex);
-#ifdef QT_SAMPLECACHE_DEBUG
- qDebug() << "QSample: decoder ready";
#endif
+ QMutexLocker m(&m_mutex);
+ qCDebug(qLcSampleCache) << "QSample: decoder ready";
m_parent->refresh(m_waveDecoder->size());
m_soundData.resize(m_waveDecoder->size());
m_sampleReadLength = 0;
qint64 read = m_waveDecoder->read(m_soundData.data(), m_waveDecoder->size());
+ qCDebug(qLcSampleCache) << " bytes read" << read;
if (read > 0)
m_sampleReadLength += read;
if (m_sampleReadLength >= m_waveDecoder->size())
@@ -392,26 +353,42 @@ QSample::State QSample::state() const
// Essentially a second ctor, doesn't need locks (?)
void QSample::load()
{
+#if QT_CONFIG(thread)
Q_ASSERT(QThread::currentThread()->objectName() == QLatin1String("QSampleCache::LoadingThread"));
-#ifdef QT_SAMPLECACHE_DEBUG
- qDebug() << "QSample: load [" << m_url << "]";
#endif
- m_stream = m_parent->networkAccessManager().get(QNetworkRequest(m_url));
- connect(m_stream, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), SLOT(decoderError()));
+ qCDebug(qLcSampleCache) << "QSample: load [" << m_url << "]";
+ QNetworkReply *reply = m_parent->networkAccessManager().get(QNetworkRequest(m_url));
+ m_stream = reply;
+ connect(reply, &QNetworkReply::errorOccurred, this, &QSample::loadingError);
m_waveDecoder = new QWaveDecoder(m_stream);
- connect(m_waveDecoder, SIGNAL(formatKnown()), SLOT(decoderReady()));
- connect(m_waveDecoder, SIGNAL(parsingError()), SLOT(decoderError()));
- connect(m_waveDecoder, SIGNAL(readyRead()), SLOT(readSample()));
+ connect(m_waveDecoder, &QWaveDecoder::formatKnown, this, &QSample::decoderReady);
+ connect(m_waveDecoder, &QWaveDecoder::parsingError, this, &QSample::decoderError);
+ connect(m_waveDecoder, &QIODevice::readyRead, this, &QSample::readSample);
+
+ m_waveDecoder->open(QIODevice::ReadOnly);
+}
+
+void QSample::loadingError(QNetworkReply::NetworkError errorCode)
+{
+#if QT_CONFIG(thread)
+ Q_ASSERT(QThread::currentThread()->objectName() == QLatin1String("QSampleCache::LoadingThread"));
+#endif
+ QMutexLocker m(&m_mutex);
+ qCDebug(qLcSampleCache) << "QSample: loading error" << errorCode;
+ cleanup();
+ m_state = QSample::Error;
+ qobject_cast<QSampleCache*>(m_parent)->loadingRelease();
+ emit error();
}
// Called in loading thread
void QSample::decoderError()
{
+#if QT_CONFIG(thread)
Q_ASSERT(QThread::currentThread()->objectName() == QLatin1String("QSampleCache::LoadingThread"));
- QMutexLocker m(&m_mutex);
-#ifdef QT_SAMPLECACHE_DEBUG
- qDebug() << "QSample: decoder error";
#endif
+ QMutexLocker m(&m_mutex);
+ qCDebug(qLcSampleCache) << "QSample: decoder error";
cleanup();
m_state = QSample::Error;
qobject_cast<QSampleCache*>(m_parent)->loadingRelease();
@@ -421,11 +398,11 @@ void QSample::decoderError()
// Called in loading thread from decoder when sample is done. Locked already.
void QSample::onReady()
{
+#if QT_CONFIG(thread)
Q_ASSERT(QThread::currentThread()->objectName() == QLatin1String("QSampleCache::LoadingThread"));
-#ifdef QT_SAMPLECACHE_DEBUG
- qDebug() << "QSample: load ready";
#endif
m_audioFormat = m_waveDecoder->audioFormat();
+ qCDebug(qLcSampleCache) << "QSample: load ready format:" << m_audioFormat;
cleanup();
m_state = QSample::Ready;
qobject_cast<QSampleCache*>(m_parent)->loadingRelease();
diff --git a/src/multimedia/audio/qsamplecache_p.h b/src/multimedia/audio/qsamplecache_p.h
index 4c2384743..3ba0c420c 100644
--- a/src/multimedia/audio/qsamplecache_p.h
+++ b/src/multimedia/audio/qsamplecache_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSAMPLECACHE_P_H
#define QSAMPLECACHE_P_H
@@ -58,7 +22,8 @@
#include <QtCore/qmap.h>
#include <QtCore/qset.h>
#include <qaudioformat.h>
-
+#include <qnetworkreply.h>
+#include <private/qglobal_p.h>
QT_BEGIN_NAMESPACE
@@ -97,6 +62,7 @@ protected:
private Q_SLOTS:
void load();
+ void loadingError(QNetworkReply::NetworkError);
void decoderError();
void readSample();
void decoderReady();
@@ -136,9 +102,6 @@ public:
bool isLoading() const;
bool isCached(const QUrl& url) const;
-Q_SIGNALS:
- void isLoadingChanged();
-
private:
QMap<QUrl, QSample*> m_samples;
QSet<QSample*> m_staleSamples;
diff --git a/src/multimedia/audio/qsound.cpp b/src/multimedia/audio/qsound.cpp
deleted file mode 100644
index cbd336457..000000000
--- a/src/multimedia/audio/qsound.cpp
+++ /dev/null
@@ -1,244 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qsound.h"
-#include "qsoundeffect.h"
-#include "qcoreapplication.h"
-
-
-/*!
- \class QSound
- \brief The QSound class provides a method to play .wav sound files.
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_audio
-
- Qt provides the most commonly required audio operation in GUI
- applications: asynchronously playing a sound file. This is most
- easily accomplished using the static play() function:
-
- \snippet multimedia-snippets/qsound.cpp 0
-
- Alternatively, create a QSound object from the sound file first
- and then call the play() slot:
-
- \snippet multimedia-snippets/qsound.cpp 1
-
- In both cases, the file may either be a local file or in a
- \l{The Qt Resource System}{resource}.
-
- Once created a QSound object can be queried for its fileName() and
- total number of loops() (i.e. the number of times the sound will
- play). The number of repetitions can be altered using the
- setLoops() function. While playing the sound, the loopsRemaining()
- function returns the remaining number of repetitions. Use the
- isFinished() function to determine whether the sound has finished
- playing.
-
- Sounds played using a QSound object may use more memory than the
- static play() function, but it may also play more immediately
- (depending on the underlying platform audio facilities).
-
- If you require finer control over playing sounds, consider the
- \l QSoundEffect or \l QAudioOutput classes.
-
- \sa QSoundEffect
-*/
-
-/*!
- \enum QSound::Loop
-
- \value Infinite Can be used as a parameter to \l setLoops() to loop infinitely.
-*/
-
-
-/*!
- Plays the sound stored in the file specified by the given \a filename.
-
- The file can either be a local file or in a \l{The Qt Resource System}{resource}.
-
- \sa stop(), loopsRemaining(), isFinished()
-*/
-void QSound::play(const QString &filename)
-{
- // Object destruction is generally handled via deleteOnComplete
- // Unexpected cases will be handled via parenting of QSound objects to qApp
- QSound *sound = new QSound(filename, qApp);
- sound->connect(sound->m_soundEffect, &QSoundEffect::playingChanged,
- sound, &QSound::deleteOnComplete);
- sound->play();
-}
-
-/*!
- Constructs a QSound object from the file specified by the given \a
- filename and with the given \a parent.
-
- The file can either be a local file or in a \l{The Qt Resource System}{resource}.
-
- \sa play()
-*/
-QSound::QSound(const QString &filename, QObject *parent)
- : QObject(parent)
-{
- m_soundEffect = new QSoundEffect(this);
- const bool isQrc = filename.startsWith(QLatin1String("qrc:"), Qt::CaseInsensitive);
- const QUrl url = isQrc ? QUrl(filename) : QUrl::fromLocalFile(filename);
- m_soundEffect->setSource(url);
-}
-
-/*!
- Destroys this sound object. If the sound is not finished playing,
- the stop() function is called before the sound object is
- destroyed.
-
- \sa stop(), isFinished()
-*/
-QSound::~QSound()
-{
- if (!isFinished())
- stop();
-}
-
-/*!
- Returns true if the sound has finished playing; otherwise returns false.
-*/
-bool QSound::isFinished() const
-{
- return !m_soundEffect->isPlaying();
-}
-
-/*!
- \overload
-
- Starts playing the sound specified by this QSound object.
-
- The function returns immediately. Depending on the platform audio
- facilities, other sounds may stop or be mixed with the new
- sound. The sound can be played again at any time, possibly mixing
- or replacing previous plays of the sound.
-
- \sa fileName()
-*/
-void QSound::play()
-{
- m_soundEffect->play();
-}
-
-/*!
- Returns the number of times the sound will play.
- Return value of \c QSound::Infinite indicates infinite number of loops
-
- \sa loopsRemaining(), setLoops()
-*/
-int QSound::loops() const
-{
- // retain old API value for infinite loops
- int loopCount = m_soundEffect->loopCount();
- if (loopCount == QSoundEffect::Infinite)
- loopCount = Infinite;
-
- return loopCount;
-}
-
-/*!
- Returns the remaining number of times the sound will loop (for all
- positive values this value decreases each time the sound is played).
- Return value of \c QSound::Infinite indicates infinite number of loops
-
- \sa loops(), isFinished()
-*/
-int QSound::loopsRemaining() const
-{
- // retain old API value for infinite loops
- int loopsRemaining = m_soundEffect->loopsRemaining();
- if (loopsRemaining == QSoundEffect::Infinite)
- loopsRemaining = Infinite;
-
- return loopsRemaining;
-}
-
-/*!
- \fn void QSound::setLoops(int number)
-
- Sets the sound to repeat the given \a number of times when it is
- played.
-
- Note that passing the value \c QSound::Infinite will cause the sound to loop
- indefinitely.
-
- \sa loops()
-*/
-void QSound::setLoops(int n)
-{
- if (n == Infinite)
- n = QSoundEffect::Infinite;
-
- m_soundEffect->setLoopCount(n);
-}
-
-/*!
- Returns the filename associated with this QSound object.
-
- \sa QSound()
-*/
-QString QSound::fileName() const
-{
- return m_soundEffect->source().toLocalFile();
-}
-
-/*!
- Stops the sound playing.
-
- \sa play()
-*/
-void QSound::stop()
-{
- m_soundEffect->stop();
-}
-
-/*!
- \internal
-*/
-void QSound::deleteOnComplete()
-{
- if (!m_soundEffect->isPlaying())
- deleteLater();
-}
-
-#include "moc_qsound.cpp"
diff --git a/src/multimedia/audio/qsound.h b/src/multimedia/audio/qsound.h
deleted file mode 100644
index 972847c37..000000000
--- a/src/multimedia/audio/qsound.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSOUND_H
-#define QSOUND_H
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtCore/qobject.h>
-
-QT_BEGIN_NAMESPACE
-
-class QSoundEffect;
-
-class Q_MULTIMEDIA_EXPORT QSound : public QObject
-{
- Q_OBJECT
-public:
- enum Loop
- {
- Infinite = -1
- };
-
- static void play(const QString &filename);
-
- explicit QSound(const QString &filename, QObject *parent = nullptr);
- ~QSound();
-
- int loops() const;
- int loopsRemaining() const;
- void setLoops(int);
- QString fileName() const;
-
- bool isFinished() const;
-
-public Q_SLOTS:
- void play();
- void stop();
-
-private Q_SLOTS:
- void deleteOnComplete();
-
-private:
- QSoundEffect *m_soundEffect = nullptr;
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QSOUND_H
diff --git a/src/multimedia/audio/qsoundeffect.cpp b/src/multimedia/audio/qsoundeffect.cpp
index 09085dca9..c12114672 100644
--- a/src/multimedia/audio/qsoundeffect.cpp
+++ b/src/multimedia/audio/qsoundeffect.cpp
@@ -1,53 +1,265 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtMultimedia/private/qtmultimediaglobal_p.h>
#include "qsoundeffect.h"
-
-#if QT_CONFIG(pulseaudio)
-#include "qsoundeffect_pulse_p.h"
-#else
-#include "qsoundeffect_qaudio_p.h"
-#endif
+#include "qsamplecache_p.h"
+#include "qaudiodevice.h"
+#include "qaudiosink.h"
+#include "qmediadevices.h"
+#include "qaudiobuffer.h"
+#include <QtCore/qloggingcategory.h>
+#include <private/qplatformmediadevices_p.h>
+#include <private/qplatformmediaintegration_p.h>
+#include <private/qplatformaudioresampler_p.h>
+
+static Q_LOGGING_CATEGORY(qLcSoundEffect, "qt.multimedia.soundeffect")
QT_BEGIN_NAMESPACE
+Q_GLOBAL_STATIC(QSampleCache, sampleCache)
+
+namespace
+{
+struct AudioSinkDeleter
+{
+ void operator ()(QAudioSink* sink) const
+ {
+ sink->stop();
+ // Investigate:should we just delete?
+ sink->deleteLater();
+ }
+};
+
+struct SampleDeleter
+{
+ void operator ()(QSample* sample) const
+ {
+ sample->release();
+ }
+};
+}
+
+class QSoundEffectPrivate : public QIODevice
+{
+public:
+ QSoundEffectPrivate(QSoundEffect *q, const QAudioDevice &audioDevice = QAudioDevice());
+ ~QSoundEffectPrivate() override = default;
+
+ qint64 readData(char *data, qint64 len) override;
+ qint64 writeData(const char *data, qint64 len) override;
+ qint64 size() const override {
+ if (m_sample->state() != QSample::Ready)
+ return 0;
+ return m_loopCount == QSoundEffect::Infinite ? 0 : m_loopCount * m_audioBuffer.byteCount();
+ }
+ qint64 bytesAvailable() const override {
+ if (m_sample->state() != QSample::Ready)
+ return 0;
+ if (m_loopCount == QSoundEffect::Infinite)
+ return std::numeric_limits<qint64>::max();
+ return m_runningCount * m_audioBuffer.byteCount() - m_offset;
+ }
+ bool isSequential() const override {
+ return m_loopCount == QSoundEffect::Infinite;
+ }
+ bool atEnd() const override {
+ return m_runningCount == 0;
+ }
+
+ void setLoopsRemaining(int loopsRemaining);
+ void setStatus(QSoundEffect::Status status);
+ void setPlaying(bool playing);
+
+public Q_SLOTS:
+ void sampleReady();
+ void decoderError();
+ void stateChanged(QAudio::State);
+
+public:
+ QSoundEffect *q_ptr;
+ QUrl m_url;
+ int m_loopCount = 1;
+ int m_runningCount = 0;
+ bool m_playing = false;
+ QSoundEffect::Status m_status = QSoundEffect::Null;
+ std::unique_ptr<QAudioSink, AudioSinkDeleter> m_audioSink;
+ std::unique_ptr<QSample, SampleDeleter> m_sample;
+ QAudioBuffer m_audioBuffer;
+ bool m_muted = false;
+ float m_volume = 1.0;
+ bool m_sampleReady = false;
+ qint64 m_offset = 0;
+ QAudioDevice m_audioDevice;
+};
+
+QSoundEffectPrivate::QSoundEffectPrivate(QSoundEffect *q, const QAudioDevice &audioDevice)
+ : QIODevice(q)
+ , q_ptr(q)
+ , m_audioDevice(audioDevice)
+{
+ open(QIODevice::ReadOnly);
+
+ QPlatformMediaIntegration::instance()->mediaDevices()->prepareAudio();
+}
+
+void QSoundEffectPrivate::sampleReady()
+{
+ if (m_status == QSoundEffect::Error)
+ return;
+
+ qCDebug(qLcSoundEffect) << this << "sampleReady: sample size:" << m_sample->data().size();
+ disconnect(m_sample.get(), &QSample::error, this, &QSoundEffectPrivate::decoderError);
+ disconnect(m_sample.get(), &QSample::ready, this, &QSoundEffectPrivate::sampleReady);
+ if (!m_audioSink) {
+ const auto audioDevice =
+ m_audioDevice.isNull() ? QMediaDevices::defaultAudioOutput() : m_audioDevice;
+
+ if (audioDevice.isNull()) {
+ // We are likely on a virtual machine, for example in CI
+ qCCritical(qLcSoundEffect) << "Failed to play sound. No audio devices present.";
+ setStatus(QSoundEffect::Error);
+ return;
+ }
+
+ const auto &sampleFormat = m_sample->format();
+ const auto sampleChannelConfig =
+ sampleFormat.channelConfig() == QAudioFormat::ChannelConfigUnknown
+ ? QAudioFormat::defaultChannelConfigForChannelCount(sampleFormat.channelCount())
+ : sampleFormat.channelConfig();
+
+ if (sampleChannelConfig != audioDevice.channelConfiguration()
+ && audioDevice.channelConfiguration() != QAudioFormat::ChannelConfigUnknown) {
+ qCDebug(qLcSoundEffect) << "Create resampler for channels mapping: config"
+ << sampleFormat.channelConfig() << "=> config"
+ << audioDevice.channelConfiguration();
+ auto outputFormat = sampleFormat;
+ outputFormat.setChannelConfig(audioDevice.channelConfiguration());
+
+ const auto resampler = QPlatformMediaIntegration::instance()->createAudioResampler(
+ m_sample->format(), outputFormat);
+ if (resampler)
+ m_audioBuffer = resampler.value()->resample(m_sample->data().constData(),
+ m_sample->data().size());
+ else
+ qCDebug(qLcSoundEffect) << "Cannot create resampler for channels mapping";
+ }
+
+ if (!m_audioBuffer.isValid())
+ m_audioBuffer = QAudioBuffer(m_sample->data(), m_sample->format());
+
+ m_audioSink.reset(new QAudioSink(audioDevice, m_audioBuffer.format()));
+
+ connect(m_audioSink.get(), &QAudioSink::stateChanged, this, &QSoundEffectPrivate::stateChanged);
+ if (!m_muted)
+ m_audioSink->setVolume(m_volume);
+ else
+ m_audioSink->setVolume(0);
+ }
+ m_sampleReady = true;
+ setStatus(QSoundEffect::Ready);
+
+ if (m_playing && m_audioSink->state() == QAudio::StoppedState) {
+ qCDebug(qLcSoundEffect) << this << "starting playback on audiooutput";
+ m_audioSink->start(this);
+ }
+}
+
+void QSoundEffectPrivate::decoderError()
+{
+ qWarning("QSoundEffect(qaudio): Error decoding source %ls", qUtf16Printable(m_url.toString()));
+ disconnect(m_sample.get(), &QSample::ready, this, &QSoundEffectPrivate::sampleReady);
+ disconnect(m_sample.get(), &QSample::error, this, &QSoundEffectPrivate::decoderError);
+ m_playing = false;
+ setStatus(QSoundEffect::Error);
+}
+
+void QSoundEffectPrivate::stateChanged(QAudio::State state)
+{
+ qCDebug(qLcSoundEffect) << this << "stateChanged " << state;
+ if ((state == QAudio::IdleState && m_runningCount == 0) || state == QAudio::StoppedState)
+ q_ptr->stop();
+}
+
+qint64 QSoundEffectPrivate::readData(char *data, qint64 len)
+{
+ qCDebug(qLcSoundEffect) << this << "readData" << len << m_runningCount;
+ if (!len)
+ return 0;
+ if (m_sample->state() != QSample::Ready)
+ return 0;
+ if (m_runningCount == 0 || !m_playing)
+ return 0;
+
+ qint64 bytesWritten = 0;
+
+ const int sampleSize = m_audioBuffer.byteCount();
+ const char *sampleData = m_audioBuffer.constData<char>();
+
+ while (len && m_runningCount) {
+ int toWrite = qMin(sampleSize - m_offset, len);
+ memcpy(data, sampleData + m_offset, toWrite);
+ bytesWritten += toWrite;
+ data += toWrite;
+ len -= toWrite;
+ m_offset += toWrite;
+ if (m_offset >= sampleSize) {
+ if (m_runningCount > 0 && m_runningCount != QSoundEffect::Infinite)
+ setLoopsRemaining(m_runningCount - 1);
+ m_offset = 0;
+ }
+ }
+
+ return bytesWritten;
+}
+
+qint64 QSoundEffectPrivate::writeData(const char *data, qint64 len)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(len);
+ return 0;
+}
+
+void QSoundEffectPrivate::setLoopsRemaining(int loopsRemaining)
+{
+ if (m_runningCount == loopsRemaining)
+ return;
+ qCDebug(qLcSoundEffect) << this << "setLoopsRemaining " << loopsRemaining;
+ m_runningCount = loopsRemaining;
+ emit q_ptr->loopsRemainingChanged();
+}
+
+void QSoundEffectPrivate::setStatus(QSoundEffect::Status status)
+{
+ qCDebug(qLcSoundEffect) << this << "setStatus" << status;
+ if (m_status == status)
+ return;
+ bool oldLoaded = q_ptr->isLoaded();
+ m_status = status;
+ emit q_ptr->statusChanged();
+ if (oldLoaded != q_ptr->isLoaded())
+ emit q_ptr->loadedChanged();
+}
+
+void QSoundEffectPrivate::setPlaying(bool playing)
+{
+ qCDebug(qLcSoundEffect) << this << "setPlaying(" << playing << ")" << m_playing;
+ if (m_audioSink) {
+ m_audioSink->stop();
+ if (playing && !m_sampleReady)
+ return;
+ }
+
+ if (m_playing == playing)
+ return;
+ m_playing = playing;
+
+ if (m_audioSink && playing)
+ m_audioSink->start(this);
+
+ emit q_ptr->playingChanged();
+}
+
/*!
\class QSoundEffect
\brief The QSoundEffect class provides a way to play low latency sound effects.
@@ -94,8 +306,8 @@ QT_BEGIN_NAMESPACE
a generally lower latency way, and is suitable for "feedback" type sounds in
response to user actions (e.g. virtual keyboard sounds, positive or negative
feedback for popup dialogs, or game sounds). If low latency is not important,
- consider using the MediaPlayer or Audio types instead, since they support a wider
- variety of media formats and are less resource intensive.
+ consider using the MediaPlayer type instead, since it support a wider
+ variety of media formats and is less resource intensive.
Typically the sound effect should be reused, which allows all the
parsing and preparation to be done ahead of time, and only triggered
@@ -111,33 +323,20 @@ QT_BEGIN_NAMESPACE
sound effects.
*/
-static QSoundEffectPrivate *initPrivate(QSoundEffect *self, QSoundEffectPrivate *d)
-{
- QObject::connect(d, &QSoundEffectPrivate::loopsRemainingChanged, self, &QSoundEffect::loopsRemainingChanged);
- QObject::connect(d, &QSoundEffectPrivate::volumeChanged, self, &QSoundEffect::volumeChanged);
- QObject::connect(d, &QSoundEffectPrivate::mutedChanged, self, &QSoundEffect::mutedChanged);
- QObject::connect(d, &QSoundEffectPrivate::loadedChanged, self, &QSoundEffect::loadedChanged);
- QObject::connect(d, &QSoundEffectPrivate::playingChanged, self, &QSoundEffect::playingChanged);
- QObject::connect(d, &QSoundEffectPrivate::statusChanged, self, &QSoundEffect::statusChanged);
- QObject::connect(d, &QSoundEffectPrivate::categoryChanged, self, &QSoundEffect::categoryChanged);
-
- return d;
-}
/*!
Creates a QSoundEffect with the given \a parent.
*/
QSoundEffect::QSoundEffect(QObject *parent)
- : QObject(parent)
- , d(initPrivate(this, new QSoundEffectPrivate(this)))
+ : QSoundEffect(QAudioDevice(), parent)
{
}
/*!
Creates a QSoundEffect with the given \a audioDevice and \a parent.
*/
-QSoundEffect::QSoundEffect(const QAudioDeviceInfo &audioDevice, QObject *parent)
+QSoundEffect::QSoundEffect(const QAudioDevice &audioDevice, QObject *parent)
: QObject(parent)
- , d(initPrivate(this, new QSoundEffectPrivate(audioDevice, this)))
+ , d(new QSoundEffectPrivate(this, audioDevice))
{
}
@@ -146,7 +345,10 @@ QSoundEffect::QSoundEffect(const QAudioDeviceInfo &audioDevice, QObject *parent)
*/
QSoundEffect::~QSoundEffect()
{
- d->release();
+ stop();
+ d->m_audioSink.reset();
+ d->m_sample.reset();
+ delete d;
}
/*!
@@ -156,7 +358,15 @@ QSoundEffect::~QSoundEffect()
*/
QStringList QSoundEffect::supportedMimeTypes()
{
- return QSoundEffectPrivate::supportedMimeTypes();
+ // Only return supported mime types if we have a audio device available
+ const QList<QAudioDevice> devices = QMediaDevices::audioOutputs();
+ if (devices.isEmpty())
+ return QStringList();
+
+ return QStringList() << QLatin1String("audio/x-wav")
+ << QLatin1String("audio/wav")
+ << QLatin1String("audio/wave")
+ << QLatin1String("audio/x-pn-wav");
}
/*!
@@ -178,16 +388,63 @@ QStringList QSoundEffect::supportedMimeTypes()
/*! Returns the URL of the current source to play */
QUrl QSoundEffect::source() const
{
- return d->source();
+ return d->m_url;
}
/*! Set the current URL to play to \a url. */
void QSoundEffect::setSource(const QUrl &url)
{
- if (d->source() == url)
+ qCDebug(qLcSoundEffect) << this << "setSource current=" << d->m_url << ", to=" << url;
+ if (d->m_url == url)
return;
- d->setSource(url);
+ Q_ASSERT(d->m_url != url);
+
+ stop();
+
+ d->m_url = url;
+
+ d->m_sampleReady = false;
+
+ if (url.isEmpty()) {
+ d->setStatus(QSoundEffect::Null);
+ return;
+ }
+
+ if (!url.isValid()) {
+ d->setStatus(QSoundEffect::Error);
+ return;
+ }
+
+ if (d->m_sample) {
+ if (!d->m_sampleReady) {
+ disconnect(d->m_sample.get(), &QSample::error, d, &QSoundEffectPrivate::decoderError);
+ disconnect(d->m_sample.get(), &QSample::ready, d, &QSoundEffectPrivate::sampleReady);
+ }
+ d->m_sample->release();
+ d->m_sample = nullptr;
+ }
+
+ if (d->m_audioSink) {
+ disconnect(d->m_audioSink.get(), &QAudioSink::stateChanged, d, &QSoundEffectPrivate::stateChanged);
+ d->m_audioSink.reset();
+ }
+
+ d->setStatus(QSoundEffect::Loading);
+ d->m_sample.reset(sampleCache()->requestSample(url));
+ connect(d->m_sample.get(), &QSample::error, d, &QSoundEffectPrivate::decoderError);
+ connect(d->m_sample.get(), &QSample::ready, d, &QSoundEffectPrivate::sampleReady);
+
+ switch (d->m_sample->state()) {
+ case QSample::Ready:
+ d->sampleReady();
+ break;
+ case QSample::Error:
+ d->decoderError();
+ break;
+ default:
+ break;
+ }
emit sourceChanged();
}
@@ -218,7 +475,7 @@ void QSoundEffect::setSource(const QUrl &url)
*/
int QSoundEffect::loopCount() const
{
- return d->loopCount();
+ return d->m_loopCount;
}
/*!
@@ -245,14 +502,35 @@ void QSoundEffect::setLoopCount(int loopCount)
}
if (loopCount == 0)
loopCount = 1;
- if (d->loopCount() == loopCount)
+ if (d->m_loopCount == loopCount)
return;
- d->setLoopCount(loopCount);
+ d->m_loopCount = loopCount;
+ if (d->m_playing)
+ d->setLoopsRemaining(loopCount);
emit loopCountChanged();
}
/*!
+ \property QSoundEffect::audioDevice
+
+ Returns the QAudioDevice instance.
+*/
+QAudioDevice QSoundEffect::audioDevice()
+{
+ return d->m_audioDevice;
+}
+
+void QSoundEffect::setAudioDevice(const QAudioDevice &device)
+{
+ if (d->m_audioDevice == device)
+ return;
+ // ### recreate the QAudioSink if needed
+ d->m_audioDevice = device;
+ emit audioDeviceChanged();
+}
+
+/*!
\qmlproperty int QtMultimedia::SoundEffect::loopsRemaining
This property contains the number of loops remaining before the sound effect
@@ -266,7 +544,7 @@ void QSoundEffect::setLoopCount(int loopCount)
*/
int QSoundEffect::loopsRemaining() const
{
- return d->loopsRemaining();
+ return d->m_runningCount;
}
@@ -280,9 +558,9 @@ int QSoundEffect::loopsRemaining() const
The default volume is \c 1.0.
- UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale
+ UI volume controls should usually be scaled non-linearly. For example, using a logarithmic scale
will produce linear changes in perceived loudness, which is what a user would normally expect
- from a volume control. See \l {QtMultimedia::QtMultimedia::convertVolume()}{QtMultimedia.convertVolume()}
+ from a volume control. See \l {QtAudio::convertVolume()}{convertVolume()}
for more details.
*/
/*!
@@ -294,9 +572,12 @@ int QSoundEffect::loopsRemaining() const
/*!
Returns the current volume of this sound effect, from 0.0 (silent) to 1.0 (maximum volume).
*/
-qreal QSoundEffect::volume() const
+float QSoundEffect::volume() const
{
- return d->volume();
+ if (d->m_audioSink && !d->m_muted)
+ return d->m_audioSink->volume();
+
+ return d->m_volume;
}
/*!
@@ -307,17 +588,22 @@ qreal QSoundEffect::volume() const
The default volume is \c 1.0.
- UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale
+ UI volume controls should usually be scaled non-linearly. For example, using a logarithmic scale
will produce linear changes in perceived loudness, which is what a user would normally expect
- from a volume control. See QAudio::convertVolume() for more details.
+ from a volume control. See QtAudio::convertVolume() for more details.
*/
-void QSoundEffect::setVolume(qreal volume)
+void QSoundEffect::setVolume(float volume)
{
- volume = qBound(qreal(0.0), volume, qreal(1.0));
- if (qFuzzyCompare(d->volume(), volume))
+ volume = qBound(0.0f, volume, 1.0f);
+ if (d->m_volume == volume)
return;
- d->setVolume(volume);
+ d->m_volume = volume;
+
+ if (d->m_audioSink && !d->m_muted)
+ d->m_audioSink->setVolume(volume);
+
+ emit volumeChanged();
}
/*!
@@ -335,7 +621,7 @@ void QSoundEffect::setVolume(qreal volume)
/*! Returns whether this sound effect is muted */
bool QSoundEffect::isMuted() const
{
- return d->isMuted();
+ return d->m_muted;
}
/*!
@@ -347,10 +633,16 @@ bool QSoundEffect::isMuted() const
*/
void QSoundEffect::setMuted(bool muted)
{
- if (d->isMuted() == muted)
+ if (d->m_muted == muted)
return;
- d->setMuted(muted);
+ if (muted && d->m_audioSink)
+ d->m_audioSink->setVolume(0);
+ else if (!muted && d->m_audioSink && d->m_muted)
+ d->m_audioSink->setVolume(d->m_volume);
+
+ d->m_muted = muted;
+ emit mutedChanged();
}
/*!
@@ -365,7 +657,7 @@ void QSoundEffect::setMuted(bool muted)
*/
bool QSoundEffect::isLoaded() const
{
- return d->isLoaded();
+ return d->m_status == QSoundEffect::Ready;
}
/*!
@@ -386,7 +678,14 @@ bool QSoundEffect::isLoaded() const
*/
void QSoundEffect::play()
{
- d->play();
+ d->m_offset = 0;
+ d->setLoopsRemaining(d->m_loopCount);
+ qCDebug(qLcSoundEffect) << this << "play" << d->m_loopCount << d->m_runningCount;
+ if (d->m_status == QSoundEffect::Null || d->m_status == QSoundEffect::Error) {
+ d->setStatus(QSoundEffect::Null);
+ return;
+ }
+ d->setPlaying(true);
}
/*!
@@ -403,7 +702,7 @@ void QSoundEffect::play()
/*! Returns true if the sound effect is currently playing, or false otherwise */
bool QSoundEffect::isPlaying() const
{
- return d->isPlaying();
+ return d->m_playing;
}
/*!
@@ -443,72 +742,9 @@ bool QSoundEffect::isPlaying() const
*/
QSoundEffect::Status QSoundEffect::status() const
{
- return d->status();
-}
-
-/*!
- \qmlproperty string QtMultimedia::SoundEffect::category
-
- This property contains the \e category of this sound effect.
-
- Some platforms can perform different audio routing
- for different categories, or may allow the user to
- set different volume levels for different categories.
-
- This setting will be ignored on platforms that do not
- support audio categories.
-*/
-/*!
- \property QSoundEffect::category
-
- This property contains the \e category of this sound effect.
-
- Some platforms can perform different audio routing
- for different categories, or may allow the user to
- set different volume levels for different categories.
-
- This setting will be ignored on platforms that do not
- support audio categories.
-*/
-/*!
- Returns the current \e category for this sound effect.
-
- Some platforms can perform different audio routing
- for different categories, or may allow the user to
- set different volume levels for different categories.
-
- This setting will be ignored on platforms that do not
- support audio categories.
-
- \sa setCategory()
-*/
-QString QSoundEffect::category() const
-{
- return d->category();
-}
-
-/*!
- Sets the \e category of this sound effect to \a category.
-
- Some platforms can perform different audio routing
- for different categories, or may allow the user to
- set different volume levels for different categories.
-
- This setting will be ignored on platforms that do not
- support audio categories.
-
- If this setting is changed while a sound effect is playing
- it will only take effect when the sound effect has stopped
- playing.
-
- \sa category()
- */
-void QSoundEffect::setCategory(const QString &category)
-{
- d->setCategory(category);
+ return d->m_status;
}
-
/*!
\qmlmethod QtMultimedia::SoundEffect::stop()
@@ -523,7 +759,12 @@ void QSoundEffect::setCategory(const QString &category)
*/
void QSoundEffect::stop()
{
- d->stop();
+ if (!d->m_playing)
+ return;
+ qCDebug(qLcSoundEffect) << "stop()";
+ d->m_offset = 0;
+
+ d->setPlaying(false);
}
/* Signals */
@@ -537,8 +778,6 @@ void QSoundEffect::stop()
\qmlsignal QtMultimedia::SoundEffect::sourceChanged()
The \c sourceChanged signal is emitted when the source has been changed.
-
- The corresponding handler is \c onSourceChanged.
*/
/*!
\fn void QSoundEffect::loadedChanged()
@@ -549,8 +788,6 @@ void QSoundEffect::stop()
\qmlsignal QtMultimedia::SoundEffect::loadedChanged()
The \c loadedChanged signal is emitted when the loading state has changed.
-
- The corresponding handler is \c onLoadedChanged.
*/
/*!
@@ -562,8 +799,6 @@ void QSoundEffect::stop()
\qmlsignal QtMultimedia::SoundEffect::loopCountChanged()
The \c loopCountChanged signal is emitted when the initial number of loops has changed.
-
- The corresponding handler is \c onLoopCountChanged.
*/
/*!
@@ -575,8 +810,6 @@ void QSoundEffect::stop()
\qmlsignal QtMultimedia::SoundEffect::loopsRemainingChanged()
The \c loopsRemainingChanged signal is emitted when the remaining number of loops has changed.
-
- The corresponding handler is \c onLoopsRemainingChanged.
*/
/*!
@@ -588,8 +821,6 @@ void QSoundEffect::stop()
\qmlsignal QtMultimedia::SoundEffect::volumeChanged()
The \c volumeChanged signal is emitted when the volume has changed.
-
- The corresponding handler is \c onVolumeChanged.
*/
/*!
@@ -601,8 +832,6 @@ void QSoundEffect::stop()
\qmlsignal QtMultimedia::SoundEffect::mutedChanged()
The \c mutedChanged signal is emitted when the mute state has changed.
-
- The corresponding handler is \c onMutedChanged.
*/
/*!
@@ -614,8 +843,6 @@ void QSoundEffect::stop()
\qmlsignal QtMultimedia::SoundEffect::playingChanged()
The \c playingChanged signal is emitted when the playing property has changed.
-
- The corresponding handler is \c onPlayingChanged.
*/
/*!
@@ -627,24 +854,8 @@ void QSoundEffect::stop()
\qmlsignal QtMultimedia::SoundEffect::statusChanged()
The \c statusChanged signal is emitted when the status property has changed.
-
- The corresponding handler is \c onStatusChanged.
*/
-/*!
- \fn void QSoundEffect::categoryChanged()
-
- The \c categoryChanged signal is emitted when the category property has changed.
-*/
-/*!
- \qmlsignal QtMultimedia::SoundEffect::categoryChanged()
-
- The \c categoryChanged signal is emitted when the category property has changed.
-
- The corresponding handler is \c onCategoryChanged.
-*/
-
-
QT_END_NAMESPACE
#include "moc_qsoundeffect.cpp"
diff --git a/src/multimedia/audio/qsoundeffect.h b/src/multimedia/audio/qsoundeffect.h
index 1185afe07..eeafc4c9f 100644
--- a/src/multimedia/audio/qsoundeffect.h
+++ b/src/multimedia/audio/qsoundeffect.h
@@ -1,46 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSOUNDEFFECT_H
#define QSOUNDEFFECT_H
#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtMultimedia/qaudio.h>
#include <QtCore/qobject.h>
#include <QtCore/qurl.h>
#include <QtCore/qstringlist.h>
@@ -50,7 +15,7 @@ QT_BEGIN_NAMESPACE
class QSoundEffectPrivate;
-class QAudioDeviceInfo;
+class QAudioDevice;
class Q_MULTIMEDIA_EXPORT QSoundEffect : public QObject
{
@@ -59,19 +24,18 @@ class Q_MULTIMEDIA_EXPORT QSoundEffect : public QObject
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(int loops READ loopCount WRITE setLoopCount NOTIFY loopCountChanged)
Q_PROPERTY(int loopsRemaining READ loopsRemaining NOTIFY loopsRemainingChanged)
- Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged)
+ Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
Q_PROPERTY(bool playing READ isPlaying NOTIFY playingChanged)
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
- Q_PROPERTY(QString category READ category WRITE setCategory NOTIFY categoryChanged)
- Q_ENUMS(Loop)
- Q_ENUMS(Status)
+ Q_PROPERTY(QAudioDevice audioDevice READ audioDevice WRITE setAudioDevice NOTIFY audioDeviceChanged)
public:
enum Loop
{
Infinite = -2
};
+ Q_ENUM(Loop)
enum Status
{
@@ -80,9 +44,10 @@ public:
Ready,
Error
};
+ Q_ENUM(Status)
explicit QSoundEffect(QObject *parent = nullptr);
- explicit QSoundEffect(const QAudioDeviceInfo &audioDevice, QObject *parent = nullptr);
+ explicit QSoundEffect(const QAudioDevice &audioDevice, QObject *parent = nullptr);
~QSoundEffect();
static QStringList supportedMimeTypes();
@@ -94,8 +59,11 @@ public:
int loopsRemaining() const;
void setLoopCount(int loopCount);
- qreal volume() const;
- void setVolume(qreal volume);
+ QAudioDevice audioDevice();
+ void setAudioDevice(const QAudioDevice &device);
+
+ float volume() const;
+ void setVolume(float volume);
bool isMuted() const;
void setMuted(bool muted);
@@ -105,9 +73,6 @@ public:
bool isPlaying() const;
Status status() const;
- QString category() const;
- void setCategory(const QString &category);
-
Q_SIGNALS:
void sourceChanged();
void loopCountChanged();
@@ -117,7 +82,7 @@ Q_SIGNALS:
void loadedChanged();
void playingChanged();
void statusChanged();
- void categoryChanged();
+ void audioDeviceChanged();
public Q_SLOTS:
void play();
diff --git a/src/multimedia/audio/qsoundeffect_pulse_p.cpp b/src/multimedia/audio/qsoundeffect_pulse_p.cpp
deleted file mode 100644
index 51cdde026..000000000
--- a/src/multimedia/audio/qsoundeffect_pulse_p.cpp
+++ /dev/null
@@ -1,1214 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// INTERNAL USE ONLY: Do NOT use for any other purpose.
-//
-
-#include <QtCore/qcoreapplication.h>
-#include <qaudioformat.h>
-#include <QTime>
-#include <QTimer>
-
-#include "qsoundeffect_pulse_p.h"
-
-#include <private/qaudiohelpers_p.h>
-#include <private/qmediaresourcepolicy_p.h>
-#include <private/qmediaresourceset_p.h>
-#include <QAudioDeviceInfo>
-#include <unistd.h>
-
-//#define QT_PA_DEBUG
-
-QT_BEGIN_NAMESPACE
-
-namespace
-{
-inline pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format)
-{
- pa_sample_spec spec;
-
- spec.rate = format.sampleRate();
- spec.channels = format.channelCount();
- spec.format = PA_SAMPLE_INVALID;
- const bool isBigEndian = (format.byteOrder() == QAudioFormat::BigEndian);
-
- if (format.sampleType() == QAudioFormat::UnSignedInt) {
- if (format.sampleSize() == 8)
- spec.format = PA_SAMPLE_U8;
- } else if (format.sampleType() == QAudioFormat::SignedInt) {
- if (format.sampleSize() == 16) {
- spec.format = isBigEndian ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE;
- } else if (format.sampleSize() == 24) {
- spec.format = isBigEndian ? PA_SAMPLE_S24BE : PA_SAMPLE_S24LE;
- } else if (format.sampleSize() == 32) {
- spec.format = isBigEndian ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE;
- }
- } else if (format.sampleType() == QAudioFormat::Float) {
- if (format.sampleSize() == 32)
- spec.format = isBigEndian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE;
- }
-
- return spec;
-}
-
-class PulseDaemon : public QObject
-{
- Q_OBJECT
-public:
- PulseDaemon()
- {
- prepare();
- }
-
- ~PulseDaemon()
- {
- release();
- }
-
- inline void ref()
- {
- m_ref.ref();
- prepare();
- }
-
- inline void deref()
- {
- if (!m_ref.deref())
- release();
- }
-
- inline void lock()
- {
- if (m_mainLoop) {
- if (++m_lockCount == 1)
- pa_threaded_mainloop_lock(m_mainLoop);
- }
- }
-
- inline void unlock()
- {
- if (m_mainLoop) {
- if (--m_lockCount == 0)
- pa_threaded_mainloop_unlock(m_mainLoop);
- }
- }
-
- inline pa_context *context() const
- {
- return m_context;
- }
-
-Q_SIGNALS:
- void contextReady();
- void contextFailed();
-
-private Q_SLOTS:
- void onContextFailed()
- {
- release();
-
- // Try to reconnect later
- QTimer::singleShot(30000, this, &PulseDaemon::prepare);
-
- emit contextFailed();
- }
-
- void prepare()
- {
- if (m_prepared)
- return;
-
- m_context = nullptr;
- m_mainLoop = pa_threaded_mainloop_new();
- if (m_mainLoop == nullptr) {
- qWarning("PulseAudioService: unable to create pulseaudio mainloop");
- return;
- }
-
- if (pa_threaded_mainloop_start(m_mainLoop) != 0) {
- qWarning("PulseAudioService: unable to start pulseaudio mainloop");
- pa_threaded_mainloop_free(m_mainLoop);
- return;
- }
-
- m_mainLoopApi = pa_threaded_mainloop_get_api(m_mainLoop);
-
- lock();
- m_context = pa_context_new(m_mainLoopApi, QString(QLatin1String("QtPulseAudio:%1")).arg(::getpid()).toLatin1().constData());
-
- if (m_context == nullptr) {
- qWarning("PulseAudioService: Unable to create new pulseaudio context");
- unlock();
- pa_threaded_mainloop_free(m_mainLoop);
- m_mainLoop = nullptr;
- onContextFailed();
- return;
- }
-
- pa_context_set_state_callback(m_context, context_state_callback, this);
-
- const QByteArray srvStrEnv = qgetenv("QT_PULSE_SERVER_STRING");
- const char *srvStr = srvStrEnv.isNull() ? nullptr : srvStrEnv.constData();
- pa_context_flags_t flags = qEnvironmentVariableIsSet("QT_PULSE_NOAUTOSPAWN") ? PA_CONTEXT_NOAUTOSPAWN : (pa_context_flags_t)0;
-
- if (pa_context_connect(m_context, srvStr, flags, nullptr) < 0) {
- qWarning("PulseAudioService: pa_context_connect() failed");
- pa_context_unref(m_context);
- unlock();
- pa_threaded_mainloop_free(m_mainLoop);
- m_mainLoop = nullptr;
- m_context = nullptr;
- return;
- }
- unlock();
-
- m_prepared = true;
- }
-
-private:
- void release()
- {
- if (!m_prepared)
- return;
-
- if (m_context) {
- lock();
- pa_context_disconnect(m_context);
- unlock();
- }
-
- if (m_mainLoop) {
- pa_threaded_mainloop_stop(m_mainLoop);
- pa_threaded_mainloop_free(m_mainLoop);
- m_mainLoop = nullptr;
- }
-
- if (m_context) {
- pa_context_unref(m_context);
- m_context = nullptr;
- }
-
- m_prepared = false;
- }
-
- static void context_state_callback(pa_context *c, void *userdata)
- {
- PulseDaemon *self = reinterpret_cast<PulseDaemon*>(userdata);
- switch (pa_context_get_state(c)) {
- case PA_CONTEXT_CONNECTING:
- case PA_CONTEXT_AUTHORIZING:
- case PA_CONTEXT_SETTING_NAME:
- break;
- case PA_CONTEXT_READY:
- QMetaObject::invokeMethod(self, "contextReady", Qt::QueuedConnection);
- break;
- case PA_CONTEXT_FAILED:
- QMetaObject::invokeMethod(self, "onContextFailed", Qt::QueuedConnection);
- break;
- default:
- break;
- }
- }
-
- bool m_prepared = false;
- pa_context *m_context = nullptr;
- pa_threaded_mainloop *m_mainLoop = nullptr;
- pa_mainloop_api *m_mainLoopApi = nullptr;
- uint m_lockCount = 0;
- QAtomicInt m_ref;
-};
-
-}
-
-Q_GLOBAL_STATIC(PulseDaemon, pulseDaemon)
-Q_GLOBAL_STATIC(QSampleCache, sampleCache)
-
-namespace
-{
-class PulseDaemonLocker
-{
-public:
- PulseDaemonLocker()
- {
- pulseDaemon()->lock();
- }
-
- ~PulseDaemonLocker()
- {
- pulseDaemon()->unlock();
- }
-};
-}
-
-class QSoundEffectRef
-{
-public:
- QSoundEffectRef(QSoundEffectPrivate *target)
- : m_target(target)
- {
-#ifdef QT_PA_DEBUG
- qDebug() << "QSoundEffectRef(" << this << ") ctor";
-#endif
- }
-
- QSoundEffectRef *getRef()
- {
-#ifdef QT_PA_DEBUG
- qDebug() << "QSoundEffectRef(" << this << ") getRef";
-#endif
- QMutexLocker locker(&m_mutex);
- m_ref++;
- return this;
- }
-
- void release()
- {
-#ifdef QT_PA_DEBUG
- qDebug() << "QSoundEffectRef(" << this << ") Release";
-#endif
- m_mutex.lock();
- --m_ref;
- if (m_ref == 0) {
- m_mutex.unlock();
-#ifdef QT_PA_DEBUG
- qDebug() << "QSoundEffectRef(" << this << ") deleted";
-#endif
- delete this;
- return;
- }
- m_mutex.unlock();
- }
-
- QSoundEffectPrivate* soundEffect() const
- {
- QMutexLocker locker(&m_mutex);
- return m_target;
- }
-
- void notifyDeleted()
- {
-#ifdef QT_PA_DEBUG
- qDebug() << "QSoundEffectRef(" << this << ") notifyDeleted";
-#endif
- QMutexLocker locker(&m_mutex);
- m_target = nullptr;
- }
-
-private:
- int m_ref = 1;
- mutable QMutex m_mutex;
- QSoundEffectPrivate *m_target = nullptr;
-};
-
-QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent):
- QObject(parent)
-{
- pulseDaemon()->ref();
-
- m_ref = new QSoundEffectRef(this);
- if (pulseDaemon()->context())
- pa_sample_spec_init(&m_pulseSpec);
-
- m_resources = QMediaResourcePolicy::createResourceSet<QMediaPlayerResourceSetInterface>();
- Q_ASSERT(m_resources);
- m_resourcesAvailable = m_resources->isAvailable();
- connect(m_resources, &QMediaPlayerResourceSetInterface::availabilityChanged,
- this, &QSoundEffectPrivate::handleAvailabilityChanged);
-}
-
-QSoundEffectPrivate::QSoundEffectPrivate(const QAudioDeviceInfo &audioDevice, QObject *parent)
- : QSoundEffectPrivate(parent)
-{
- m_sinkName = audioDevice.deviceName();
-}
-
-void QSoundEffectPrivate::handleAvailabilityChanged(bool available)
-{
- m_resourcesAvailable = available;
-#ifdef DEBUG_RESOURCE
- qDebug() << Q_FUNC_INFO << "Resource availability changed " << m_resourcesAvailable;
-#endif
- if (!m_resourcesAvailable)
- stop();
-}
-
-void QSoundEffectPrivate::release()
-{
-#ifdef QT_PA_DEBUG
- qDebug() << this << "release";
-#endif
- m_ref->notifyDeleted();
- unloadPulseStream();
- if (m_sample) {
- m_sample->release();
- m_sample = nullptr;
- }
-
- this->deleteLater();
-}
-
-QString QSoundEffectPrivate::category() const
-{
- return m_category;
-}
-
-void QSoundEffectPrivate::setCategory(const QString &category)
-{
- if (m_category != category) {
- m_category = category;
-
- PulseDaemonLocker locker;
-
- if (m_playing || m_playQueued) {
- // Currently playing, we need to disconnect when
- // playback stops
- m_reloadCategory = true;
- } else if (m_pulseStream) {
- // We have to disconnect and reconnect
- unloadPulseStream();
- createPulseStream();
- } else {
- // Well, next time we create the pulse stream
- // it should be set
- }
-
- emit categoryChanged();
- }
-}
-
-QSoundEffectPrivate::~QSoundEffectPrivate()
-{
- QMediaResourcePolicy::destroyResourceSet(m_resources);
- m_resources = nullptr;
- m_ref->release();
-
- pulseDaemon()->deref();
-}
-
-QStringList QSoundEffectPrivate::supportedMimeTypes()
-{
- QStringList supportedTypes;
- supportedTypes << QLatin1String("audio/x-wav") << QLatin1String("audio/vnd.wave") ;
- return supportedTypes;
-}
-
-QUrl QSoundEffectPrivate::source() const
-{
- return m_source;
-}
-
-void QSoundEffectPrivate::setSource(const QUrl &url)
-{
- Q_ASSERT(m_source != url);
-#ifdef QT_PA_DEBUG
- qDebug() << this << "setSource =" << url;
-#endif
-
- PulseDaemonLocker locker;
-
- // Make sure the stream is empty before loading a new source (otherwise whatever is there will
- // be played before the new source)
- emptyStream();
-
- stop();
-
- if (m_sample) {
- if (!m_sampleReady) {
- disconnect(m_sample, &QSample::error, this, &QSoundEffectPrivate::decoderError);
- disconnect(m_sample, &QSample::ready, this, &QSoundEffectPrivate::sampleReady);
- }
- m_sample->release();
- m_sample = nullptr;
- }
-
- m_source = url;
- m_sampleReady = false;
-
- setLoopsRemaining(0);
- if (m_pulseStream && !pa_stream_is_corked(m_pulseStream)) {
- pa_stream_set_write_callback(m_pulseStream, nullptr, nullptr);
- pa_stream_set_underflow_callback(m_pulseStream, nullptr, nullptr);
- pa_operation *op = pa_stream_cork(m_pulseStream, 1, nullptr, nullptr);
- if (op)
- pa_operation_unref(op);
- else
- qWarning("QSoundEffect(pulseaudio): failed to cork stream");
- }
- setPlaying(false);
-
- if (url.isEmpty()) {
- setStatus(QSoundEffect::Null);
- return;
- }
-
- setStatus(QSoundEffect::Loading);
- m_sample = sampleCache()->requestSample(url);
- connect(m_sample, &QSample::error, this, &QSoundEffectPrivate::decoderError);
- connect(m_sample, &QSample::ready, this, &QSoundEffectPrivate::sampleReady);
- switch(m_sample->state()) {
- case QSample::Ready:
- sampleReady();
- break;
- case QSample::Error:
- decoderError();
- break;
- default:
- break;
- }
-}
-
-int QSoundEffectPrivate::loopCount() const
-{
- return m_loopCount;
-}
-
-int QSoundEffectPrivate::loopsRemaining() const
-{
- return m_runningCount;
-}
-
-void QSoundEffectPrivate::setLoopCount(int loopCount)
-{
- if (loopCount == 0)
- loopCount = 1;
- m_loopCount = loopCount;
- if (m_playing) {
- PulseDaemonLocker locker;
- setLoopsRemaining(loopCount);
- }
-}
-
-qreal QSoundEffectPrivate::volume() const
-{
- QMutexLocker locker(&m_volumeLock);
- return m_volume;
-}
-
-static void volume_stream_flush_callback(pa_stream *s, int success, void *userdata)
-{
- Q_UNUSED(s);
- QSoundEffectRef *ref = reinterpret_cast<QSoundEffectRef *>(userdata);
- QSoundEffectPrivate *self = ref->soundEffect();
- ref->release();
- if (!self)
- return;
-
- if (!success)
- qWarning("QSoundEffect(pulseaudio): failed to drain");
-
- QMetaObject::invokeMethod(self, "prepare", Qt::QueuedConnection);
-}
-
-void QSoundEffectPrivate::setVolume(qreal volume)
-{
- QMutexLocker locker(&m_volumeLock);
-
- if (qFuzzyCompare(m_volume, volume))
- return;
-
- m_volume = qBound(qreal(0), volume, qreal(1));
- locker.unlock();
- if (!m_playing && m_pulseStream)
- pa_stream_flush(m_pulseStream, volume_stream_flush_callback, m_ref->getRef());
- emit volumeChanged();
-}
-
-bool QSoundEffectPrivate::isMuted() const
-{
- QMutexLocker locker(&m_volumeLock);
- return m_muted;
-}
-
-void QSoundEffectPrivate::setMuted(bool muted)
-{
- m_volumeLock.lock();
- m_muted = muted;
- m_volumeLock.unlock();
-
- emit mutedChanged();
-}
-
-bool QSoundEffectPrivate::isLoaded() const
-{
- return m_status == QSoundEffect::Ready;
-}
-
-bool QSoundEffectPrivate::isPlaying() const
-{
- return m_playing;
-}
-
-QSoundEffect::Status QSoundEffectPrivate::status() const
-{
- return m_status;
-}
-
-void QSoundEffectPrivate::setPlaying(bool playing)
-{
-#ifdef QT_PA_DEBUG
- qDebug() << this << "setPlaying(" << playing << ")";
-#endif
- if (m_playing == playing)
- return;
- if (!playing)
- m_playQueued = false;
- m_playing = playing;
- emit playingChanged();
-}
-
-void QSoundEffectPrivate::setStatus(QSoundEffect::Status status)
-{
-#ifdef QT_PA_DEBUG
- qDebug() << this << "setStatus" << status;
-#endif
- if (m_status == status)
- return;
- bool oldLoaded = isLoaded();
- m_status = status;
- emit statusChanged();
- if (oldLoaded != isLoaded())
- emit loadedChanged();
-}
-
-void QSoundEffectPrivate::setLoopsRemaining(int loopsRemaining)
-{
-#ifdef QT_PA_DEBUG
- qDebug() << this << "setLoopsRemaining " << loopsRemaining;
-#endif
- if (m_runningCount == loopsRemaining)
- return;
- m_runningCount = loopsRemaining;
- emit loopsRemainingChanged();
-}
-
-void QSoundEffectPrivate::play()
-{
- if (!m_resourcesAvailable)
- return;
-
- playAvailable();
-}
-
-void QSoundEffectPrivate::playAvailable()
-{
-#ifdef QT_PA_DEBUG
- qDebug() << this << "play";
-#endif
- if (m_status == QSoundEffect::Null || m_status == QSoundEffect::Error || m_playQueued)
- return;
-
- PulseDaemonLocker locker;
-
- if (!m_pulseStream || m_status != QSoundEffect::Ready || m_stopping || m_emptying) {
-#ifdef QT_PA_DEBUG
- qDebug() << this << "play deferred";
-#endif
- m_playQueued = true;
- } else {
- if (m_playing) { //restart playing from the beginning
-#ifdef QT_PA_DEBUG
- qDebug() << this << "restart playing";
-#endif
- setLoopsRemaining(0);
- m_playQueued = true;
- Q_ASSERT(m_pulseStream);
- emptyStream(ReloadSampleWhenDone);
- return;
- }
- setLoopsRemaining(m_loopCount);
- playSample();
- }
-
- setPlaying(true);
-}
-
-void QSoundEffectPrivate::emptyStream(EmptyStreamOptions options)
-{
-#ifdef QT_PA_DEBUG
- qDebug() << this << "emptyStream";
-#endif
- if (!m_pulseStream || m_emptying)
- return;
-
- const bool reloadSample = options.testFlag(ReloadSampleWhenDone);
- pa_stream_success_cb_t flushCompleteCb = reloadSample ? stream_flush_reload_callback
- : stream_flush_callback;
-
- PulseDaemonLocker locker;
-
- m_emptying = true;
- pa_stream_set_write_callback(m_pulseStream, nullptr, nullptr);
- pa_stream_set_underflow_callback(m_pulseStream, nullptr, nullptr);
- pa_operation *op = pa_stream_flush(m_pulseStream, flushCompleteCb, m_ref->getRef());
- if (op)
- pa_operation_unref(op);
- else
- qWarning("QSoundEffect(pulseaudio): failed to flush stream");
-}
-
-void QSoundEffectPrivate::emptyComplete(void *stream, bool reload)
-{
-#ifdef QT_PA_DEBUG
- qDebug() << this << "emptyComplete";
-#endif
-
- PulseDaemonLocker locker;
-
- m_emptying = false;
-
- if ((pa_stream *)stream == m_pulseStream) {
- pa_operation *op = pa_stream_cork(m_pulseStream, 1,
- reload ? stream_cork_callback : nullptr, m_ref->getRef());
- if (op)
- pa_operation_unref(op);
- else
- qWarning("QSoundEffect(pulseaudio): failed to cork stream");
- }
-}
-
-void QSoundEffectPrivate::sampleReady()
-{
- PulseDaemonLocker locker;
-
- // The slot might be called right after a new call to setSource().
- // In this case, the sample has been reset and the slot is being called for the previous sample.
- // Just ignore it.
- if (Q_UNLIKELY(!m_sample || m_sample->state() != QSample::Ready))
- return;
-
-#ifdef QT_PA_DEBUG
- qDebug() << this << "sampleReady";
-#endif
- disconnect(m_sample, &QSample::error, this, &QSoundEffectPrivate::decoderError);
- disconnect(m_sample, &QSample::ready, this, &QSoundEffectPrivate::sampleReady);
- pa_sample_spec newFormatSpec = audioFormatToSampleSpec(m_sample->format());
-
- if (m_pulseStream && !pa_sample_spec_equal(&m_pulseSpec, &newFormatSpec)) {
- unloadPulseStream();
- }
- m_pulseSpec = newFormatSpec;
-
- m_sampleReady = true;
- m_position = 0;
-
- if (m_name.isNull())
- m_name = QString(QLatin1String("QtPulseSample-%1-%2")).arg(::getpid()).arg(quintptr(this)).toUtf8();
-
- if (m_pulseStream && pa_stream_get_state(m_pulseStream) == PA_STREAM_READY) {
-#ifdef QT_PA_DEBUG
- qDebug() << this << "reuse existing pulsestream";
-#endif
- const pa_buffer_attr *bufferAttr = pa_stream_get_buffer_attr(m_pulseStream);
- if (bufferAttr->prebuf > uint32_t(m_sample->data().size())) {
- pa_buffer_attr newBufferAttr;
- newBufferAttr = *bufferAttr;
- newBufferAttr.prebuf = m_sample->data().size();
- pa_operation *op = pa_stream_set_buffer_attr(m_pulseStream, &newBufferAttr, stream_adjust_prebuffer_callback, m_ref->getRef());
- if (op)
- pa_operation_unref(op);
- else
- qWarning("QSoundEffect(pulseaudio): failed to adjust pre-buffer attribute");
- } else {
- streamReady();
- }
- } else if (!m_pulseStream) {
- if (!pulseDaemon()->context() || pa_context_get_state(pulseDaemon()->context()) != PA_CONTEXT_READY) {
- connect(pulseDaemon(), &PulseDaemon::contextReady,
- this, &QSoundEffectPrivate::contextReady);
- return;
- }
- createPulseStream();
- }
-}
-
-void QSoundEffectPrivate::decoderError()
-{
- qWarning("QSoundEffect(pulseaudio): Error decoding source %ls", qUtf16Printable(m_source.toString()));
- disconnect(m_sample, &QSample::error, this, &QSoundEffectPrivate::decoderError);
- bool playingDirty = false;
- if (m_playing) {
- m_playing = false;
- playingDirty = true;
- }
- setStatus(QSoundEffect::Error);
- if (playingDirty)
- emit playingChanged();
-}
-
-void QSoundEffectPrivate::unloadPulseStream()
-{
-#ifdef QT_PA_DEBUG
- qDebug() << this << "unloadPulseStream";
-#endif
- m_sinkInputId = -1;
- PulseDaemonLocker locker;
- if (m_pulseStream) {
- pa_stream_set_state_callback(m_pulseStream, nullptr, nullptr);
- pa_stream_set_write_callback(m_pulseStream, nullptr, nullptr);
- pa_stream_set_underflow_callback(m_pulseStream, nullptr, nullptr);
- pa_stream_disconnect(m_pulseStream);
- pa_stream_unref(m_pulseStream);
- disconnect(pulseDaemon(), &PulseDaemon::contextFailed,
- this, &QSoundEffectPrivate::contextFailed);
- m_pulseStream = nullptr;
- m_reloadCategory = false; // category will be reloaded when we connect anyway
- }
-}
-
-void QSoundEffectPrivate::prepare()
-{
- if (!m_pulseStream || !m_sampleReady)
- return;
- PulseDaemonLocker locker;
-
- if (pa_stream_get_state(m_pulseStream) != PA_STREAM_READY)
- return;
-
- pa_stream_set_write_callback(m_pulseStream, stream_write_callback, this);
- pa_stream_set_underflow_callback(m_pulseStream, stream_underrun_callback, this);
- m_stopping = false;
- size_t writeBytes = size_t(qMin(m_pulseBufferSize, m_sample->data().size()));
-#ifdef QT_PA_DEBUG
- qDebug() << this << "prepare(): writable size =" << pa_stream_writable_size(m_pulseStream)
- << "actual writeBytes =" << writeBytes
- << "m_playQueued =" << m_playQueued;
-#endif
- m_position = writeToStream(m_sample->data().data(), writeBytes);
-
- if (m_playQueued) {
- m_playQueued = false;
- setLoopsRemaining(m_loopCount);
- playSample();
- }
-}
-
-void QSoundEffectPrivate::uploadSample()
-{
- // Always called on PulseAudio thread
-
- if (m_runningCount == 0) {
-#ifdef QT_PA_DEBUG
- qDebug() << this << "uploadSample: return due to 0 m_runningCount";
-#endif
- return;
- }
-
- if (Q_UNLIKELY(!m_pulseStream
- || pa_stream_get_state(m_pulseStream) != PA_STREAM_READY
- || !m_sampleReady)) {
- return;
- }
-
-#ifdef QT_PA_DEBUG
- qDebug() << this << "uploadSample: m_runningCount =" << m_runningCount;
-#endif
- if (m_position == m_sample->data().size()) {
- m_position = 0;
- if (m_runningCount > 0)
- setLoopsRemaining(m_runningCount - 1);
- if (m_runningCount == 0) {
- return;
- }
- }
-
- int writableSize = int(pa_stream_writable_size(m_pulseStream));
- int firstPartLength = qMin(m_sample->data().size() - m_position, writableSize);
-
- int writtenBytes = writeToStream(m_sample->data().data() + m_position,
- firstPartLength);
-
- m_position += writtenBytes;
- if (m_position == m_sample->data().size()) {
- m_position = 0;
- if (m_runningCount > 0)
- setLoopsRemaining(m_runningCount - 1);
- if (m_runningCount != 0 && firstPartLength < writableSize)
- {
- while (writtenBytes < writableSize) {
- int writeSize = qMin(writableSize - writtenBytes, m_sample->data().size());
- writtenBytes += writeToStream(m_sample->data().data(), writeSize);
-
- if (writeSize < m_sample->data().size()) {
- m_position = writeSize;
- break;
- }
- if (m_runningCount > 0)
- setLoopsRemaining(m_runningCount - 1);
- if (m_runningCount == 0)
- break;
- }
- }
- }
-#ifdef QT_PA_DEBUG
- qDebug() << this << "uploadSample: use direct write, writeable size =" << writableSize
- << "actual writtenBytes =" << writtenBytes;
-#endif
-}
-
-int QSoundEffectPrivate::writeToStream(const void *data, int size)
-{
- // Always called on PulseAudio thread
-
- if (size < 1)
- return 0;
-
- m_volumeLock.lock();
- qreal volume = m_muted ? 0 : m_volume;
- m_volumeLock.unlock();
- pa_free_cb_t writeDoneCb = stream_write_done_callback;
-
- if (volume < 1.0f) {
- // Don't use PulseAudio volume, as it might affect all other streams of the same category
- // or even affect the system volume if flat volumes are enabled
- void *dest = nullptr;
- size_t nbytes = size;
- if (pa_stream_begin_write(m_pulseStream, &dest, &nbytes) < 0) {
- qWarning("QSoundEffect(pulseaudio): pa_stream_begin_write, error = %s",
- pa_strerror(pa_context_errno(pulseDaemon()->context())));
- return 0;
- }
-
- size = int(nbytes);
- QAudioHelperInternal::qMultiplySamples(volume, m_sample->format(), data, dest, size);
- data = dest;
- writeDoneCb = nullptr;
- }
-
- if (pa_stream_write(m_pulseStream, data, size, writeDoneCb, 0, PA_SEEK_RELATIVE) < 0) {
- qWarning("QSoundEffect(pulseaudio): pa_stream_write, error = %s",
- pa_strerror(pa_context_errno(pulseDaemon()->context())));
- return 0;
- }
-
- return size;
-}
-
-void QSoundEffectPrivate::playSample()
-{
- PulseDaemonLocker locker;
-
-#ifdef QT_PA_DEBUG
- qDebug() << this << "playSample";
-#endif
- Q_ASSERT(m_pulseStream);
- Q_ASSERT(pa_stream_get_state(m_pulseStream) == PA_STREAM_READY);
- pa_operation *o = pa_stream_cork(m_pulseStream, 0, nullptr, nullptr);
- if (o)
- pa_operation_unref(o);
-}
-
-void QSoundEffectPrivate::stop()
-{
-#ifdef QT_PA_DEBUG
- qDebug() << this << "stop";
-#endif
- if (!m_playing)
- return;
-
- PulseDaemonLocker locker;
-
- setPlaying(false);
-
- m_stopping = true;
- if (m_pulseStream) {
- emptyStream(ReloadSampleWhenDone);
- if (m_reloadCategory) {
- unloadPulseStream(); // upon play we reconnect anyway
- }
- }
- setLoopsRemaining(0);
- m_position = 0;
- m_playQueued = false;
- m_reloadCategory = false;
-}
-
-void QSoundEffectPrivate::underRun()
-{
- stop();
-}
-
-void QSoundEffectPrivate::streamReady()
-{
- PulseDaemonLocker locker;
-
- if (Q_UNLIKELY(!m_sample || m_sample->state() != QSample::Ready
- || !m_pulseStream || pa_stream_get_state(m_pulseStream) != PA_STREAM_READY)) {
- return;
- }
-
-#ifdef QT_PA_DEBUG
- qDebug() << this << "streamReady";
-#endif
-
- m_sinkInputId = pa_stream_get_index(m_pulseStream);
-#ifdef QT_PA_DEBUG
- const pa_buffer_attr *realBufAttr = pa_stream_get_buffer_attr(m_pulseStream);
- qDebug() << this << "m_sinkInputId =" << m_sinkInputId
- << "tlength =" << realBufAttr->tlength << "maxlength =" << realBufAttr->maxlength
- << "minreq = " << realBufAttr->minreq << "prebuf =" << realBufAttr->prebuf;
-#endif
- prepare();
- setStatus(QSoundEffect::Ready);
-}
-
-void QSoundEffectPrivate::createPulseStream()
-{
-#ifdef QT_PA_DEBUG
- qDebug() << this << "createPulseStream";
-#endif
-
- if (!pulseDaemon()->context())
- return;
-
- pa_proplist *propList = pa_proplist_new();
- if (!m_category.isNull())
- pa_proplist_sets(propList, PA_PROP_MEDIA_ROLE, m_category.toLatin1().constData());
- pa_stream *stream = pa_stream_new_with_proplist(pulseDaemon()->context(), m_name.constData(),
- &m_pulseSpec, nullptr, propList);
- pa_proplist_free(propList);
-
- connect(pulseDaemon(), &PulseDaemon::contextFailed,
- this, &QSoundEffectPrivate::contextFailed);
-
- if (stream == nullptr) {
- qWarning("QSoundEffect(pulseaudio): Failed to create stream");
- m_pulseStream = nullptr;
- setStatus(QSoundEffect::Error);
- setPlaying(false);
- return;
- }
- else {
- pa_stream_set_state_callback(stream, stream_state_callback, this);
- pa_stream_set_write_callback(stream, stream_write_callback, this);
- pa_stream_set_underflow_callback(stream, stream_underrun_callback, this);
- }
- m_pulseStream = stream;
-
- if (pa_stream_connect_playback(m_pulseStream,
- m_sinkName.isEmpty() ? nullptr : m_sinkName.toLatin1().constData(),
- nullptr, PA_STREAM_START_CORKED, nullptr, nullptr) < 0) {
- qWarning("QSoundEffect(pulseaudio): Failed to connect stream, error = %s",
- pa_strerror(pa_context_errno(pulseDaemon()->context())));
- }
-}
-
-void QSoundEffectPrivate::contextReady()
-{
- disconnect(pulseDaemon(), &PulseDaemon::contextReady,
- this, &QSoundEffectPrivate::contextReady);
- PulseDaemonLocker locker;
- createPulseStream();
-}
-
-void QSoundEffectPrivate::contextFailed()
-{
- unloadPulseStream();
- connect(pulseDaemon(), &PulseDaemon::contextReady,
- this, &QSoundEffectPrivate::contextReady);
-}
-
-void QSoundEffectPrivate::stream_write_callback(pa_stream *s, size_t length, void *userdata)
-{
- Q_UNUSED(length);
- Q_UNUSED(s);
-
- QSoundEffectPrivate *self = reinterpret_cast<QSoundEffectPrivate*>(userdata);
-#ifdef QT_PA_DEBUG
- qDebug() << self << "stream_write_callback";
-#endif
- self->uploadSample();
-}
-
-void QSoundEffectPrivate::stream_state_callback(pa_stream *s, void *userdata)
-{
- QSoundEffectPrivate *self = reinterpret_cast<QSoundEffectPrivate*>(userdata);
- switch (pa_stream_get_state(s)) {
- case PA_STREAM_READY:
- {
-#ifdef QT_PA_DEBUG
- qDebug() << self << "pulse stream ready";
-#endif
- if (Q_UNLIKELY(!self->m_sample || self->m_sample->state() != QSample::Ready))
- return;
-
- const pa_buffer_attr *bufferAttr = pa_stream_get_buffer_attr(self->m_pulseStream);
- self->m_pulseBufferSize = bufferAttr->tlength;
- if (bufferAttr->prebuf > uint32_t(self->m_sample->data().size())) {
- pa_buffer_attr newBufferAttr;
- newBufferAttr = *bufferAttr;
- newBufferAttr.prebuf = self->m_sample->data().size();
- pa_operation *op = pa_stream_set_buffer_attr(self->m_pulseStream, &newBufferAttr, stream_adjust_prebuffer_callback, self->m_ref->getRef());
- if (op)
- pa_operation_unref(op);
- else
- qWarning("QSoundEffect(pulseaudio): failed to adjust pre-buffer attribute");
- } else {
- QMetaObject::invokeMethod(self, "streamReady", Qt::QueuedConnection);
- }
- break;
- }
- case PA_STREAM_CREATING:
-#ifdef QT_PA_DEBUG
- qDebug() << self << "pulse stream creating";
-#endif
- break;
- case PA_STREAM_TERMINATED:
-#ifdef QT_PA_DEBUG
- qDebug() << self << "pulse stream terminated";
-#endif
- break;
-
- case PA_STREAM_FAILED:
- default:
- qWarning("QSoundEffect(pulseaudio): Error in pulse audio stream");
- break;
- }
-}
-
-void QSoundEffectPrivate::stream_adjust_prebuffer_callback(pa_stream *s, int success, void *userdata)
-{
-#ifdef QT_PA_DEBUG
- qDebug() << "stream_adjust_prebuffer_callback";
-#endif
- Q_UNUSED(s);
- QSoundEffectRef *ref = reinterpret_cast<QSoundEffectRef*>(userdata);
- QSoundEffectPrivate *self = ref->soundEffect();
- ref->release();
- if (!self)
- return;
-
- if (!success)
- qWarning("QSoundEffect(pulseaudio): failed to adjust pre-buffer attribute");
-#ifdef QT_PA_DEBUG
- qDebug() << self << "stream_adjust_prebuffer_callback";
-#endif
- QMetaObject::invokeMethod(self, "streamReady", Qt::QueuedConnection);
-}
-
-void QSoundEffectPrivate::stream_underrun_callback(pa_stream *s, void *userdata)
-{
- Q_UNUSED(s);
- QSoundEffectPrivate *self = reinterpret_cast<QSoundEffectPrivate*>(userdata);
-#ifdef QT_PA_DEBUG
- qDebug() << self << "stream_underrun_callback";
-#endif
- if (self->m_runningCount == 0 && !self->m_playQueued)
- QMetaObject::invokeMethod(self, "underRun", Qt::QueuedConnection);
-#ifdef QT_PA_DEBUG
- else
- qDebug() << "underun corked =" << pa_stream_is_corked(s);
-#endif
-}
-
-void QSoundEffectPrivate::stream_cork_callback(pa_stream *s, int success, void *userdata)
-{
-#ifdef QT_PA_DEBUG
- qDebug() << "stream_cork_callback";
-#endif
- Q_UNUSED(s);
- QSoundEffectRef *ref = reinterpret_cast<QSoundEffectRef*>(userdata);
- QSoundEffectPrivate *self = ref->soundEffect();
- ref->release();
- if (!self)
- return;
-
- if (!success)
- qWarning("QSoundEffect(pulseaudio): failed to stop");
-#ifdef QT_PA_DEBUG
- qDebug() << self << "stream_cork_callback";
-#endif
- QMetaObject::invokeMethod(self, "prepare", Qt::QueuedConnection);
-}
-
-void QSoundEffectPrivate::stream_flush_callback(pa_stream *s, int success, void *userdata)
-{
-#ifdef QT_PA_DEBUG
- qDebug() << "stream_flush_callback";
-#endif
- Q_UNUSED(s);
- QSoundEffectRef *ref = reinterpret_cast<QSoundEffectRef*>(userdata);
- QSoundEffectPrivate *self = ref->soundEffect();
- ref->release();
- if (!self)
- return;
-
- if (!success)
- qWarning("QSoundEffect(pulseaudio): failed to drain");
-
- QMetaObject::invokeMethod(self, "emptyComplete", Qt::QueuedConnection, Q_ARG(void*, s), Q_ARG(bool, false));
-}
-
-void QSoundEffectPrivate::stream_flush_reload_callback(pa_stream *s, int success, void *userdata)
-{
-#ifdef QT_PA_DEBUG
- qDebug() << "stream_flush_reload_callback";
-#endif
- Q_UNUSED(s);
- QSoundEffectRef *ref = reinterpret_cast<QSoundEffectRef*>(userdata);
- QSoundEffectPrivate *self = ref->soundEffect();
- ref->release();
- if (!self)
- return;
-
- if (!success)
- qWarning("QSoundEffect(pulseaudio): failed to drain");
-
- QMetaObject::invokeMethod(self, "emptyComplete", Qt::QueuedConnection, Q_ARG(void*, s), Q_ARG(bool, true));
-}
-
-void QSoundEffectPrivate::stream_write_done_callback(void *p)
-{
- Q_UNUSED(p);
-#ifdef QT_PA_DEBUG
- qDebug() << "stream_write_done_callback";
-#endif
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qsoundeffect_pulse_p.cpp"
-#include "qsoundeffect_pulse_p.moc"
diff --git a/src/multimedia/audio/qsoundeffect_pulse_p.h b/src/multimedia/audio/qsoundeffect_pulse_p.h
deleted file mode 100644
index e0073f0d5..000000000
--- a/src/multimedia/audio/qsoundeffect_pulse_p.h
+++ /dev/null
@@ -1,188 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSOUNDEFFECT_PULSE_H
-#define QSOUNDEFFECT_PULSE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-
-#include "qsoundeffect.h"
-
-#include <QtCore/qobject.h>
-#include <QtCore/qdatetime.h>
-#include <QtCore/qmutex.h>
-#include <qmediaplayer.h>
-#include <pulse/pulseaudio.h>
-#include "qsamplecache_p.h"
-
-#include <private/qmediaresourcepolicy_p.h>
-#include <private/qmediaresourceset_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QSoundEffectRef;
-
-class QSoundEffectPrivate : public QObject
-{
- Q_OBJECT
-public:
- explicit QSoundEffectPrivate(QObject* parent);
- explicit QSoundEffectPrivate(const QAudioDeviceInfo &audioDevice, QObject *parent);
- ~QSoundEffectPrivate();
-
- static QStringList supportedMimeTypes();
-
- QUrl source() const;
- void setSource(const QUrl &url);
- int loopCount() const;
- int loopsRemaining() const;
- void setLoopCount(int loopCount);
- qreal volume() const;
- void setVolume(qreal volume);
- bool isMuted() const;
- void setMuted(bool muted);
- bool isLoaded() const;
- bool isPlaying() const;
- QSoundEffect::Status status() const;
-
- void release();
-
- QString category() const;
- void setCategory(const QString &category);
-
-public Q_SLOTS:
- void play();
- void stop();
-
-Q_SIGNALS:
- void loopsRemainingChanged();
- void volumeChanged();
- void mutedChanged();
- void loadedChanged();
- void playingChanged();
- void statusChanged();
- void categoryChanged();
-
-private Q_SLOTS:
- void decoderError();
- void sampleReady();
- void uploadSample();
- void contextReady();
- void contextFailed();
- void underRun();
- void prepare();
- void streamReady();
- void emptyComplete(void *stream, bool reload);
-
- void handleAvailabilityChanged(bool available);
-
-private:
- void playAvailable();
- void playSample();
-
- enum EmptyStreamOption {
- ReloadSampleWhenDone = 0x1
- };
- Q_DECLARE_FLAGS(EmptyStreamOptions, EmptyStreamOption)
- void emptyStream(EmptyStreamOptions options = EmptyStreamOptions());
-
- void createPulseStream();
- void unloadPulseStream();
-
- int writeToStream(const void *data, int size);
-
- void setPlaying(bool playing);
- void setStatus(QSoundEffect::Status status);
- void setLoopsRemaining(int loopsRemaining);
-
- static void stream_write_callback(pa_stream *s, size_t length, void *userdata);
- static void stream_state_callback(pa_stream *s, void *userdata);
- static void stream_underrun_callback(pa_stream *s, void *userdata);
- static void stream_cork_callback(pa_stream *s, int success, void *userdata);
- static void stream_flush_callback(pa_stream *s, int success, void *userdata);
- static void stream_flush_reload_callback(pa_stream *s, int success, void *userdata);
- static void stream_write_done_callback(void *p);
- static void stream_adjust_prebuffer_callback(pa_stream *s, int success, void *userdata);
-
- pa_stream *m_pulseStream = nullptr;
- QString m_sinkName;
- int m_sinkInputId = -1;
- pa_sample_spec m_pulseSpec;
- int m_pulseBufferSize = 0;
-
- bool m_emptying = false;
- bool m_sampleReady = false;
- bool m_playing = false;
- QSoundEffect::Status m_status = QSoundEffect::Null;
- bool m_muted = false;
- bool m_playQueued = false;
- bool m_stopping = false;
- qreal m_volume = 1.0;
- int m_loopCount = 1;
- int m_runningCount = 0;
- QUrl m_source;
- QByteArray m_name;
- QString m_category;
- bool m_reloadCategory = false;
-
- QSample *m_sample = nullptr;
- int m_position = 0;
- QSoundEffectRef *m_ref = nullptr;
-
- bool m_resourcesAvailable = false;
-
- // Protects volume while PuseAudio is accessing it
- mutable QMutex m_volumeLock;
-
- QMediaPlayerResourceSetInterface *m_resources = nullptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QSOUNDEFFECT_PULSE_H
diff --git a/src/multimedia/audio/qsoundeffect_qaudio_p.cpp b/src/multimedia/audio/qsoundeffect_qaudio_p.cpp
deleted file mode 100644
index 90d195d3f..000000000
--- a/src/multimedia/audio/qsoundeffect_qaudio_p.cpp
+++ /dev/null
@@ -1,457 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// INTERNAL USE ONLY: Do NOT use for any other purpose.
-//
-
-#include "qsoundeffect_qaudio_p.h"
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qiodevice.h>
-
-//#include <QDebug>
-//#define QT_QAUDIO_DEBUG 1
-
-QT_BEGIN_NAMESPACE
-
-Q_GLOBAL_STATIC(QSampleCache, sampleCache)
-
-QSoundEffectPrivate::QSoundEffectPrivate(QObject *parent):
- QObject(parent),
- d(new PrivateSoundSource(this))
-{
-}
-
-QSoundEffectPrivate::QSoundEffectPrivate(const QAudioDeviceInfo &audioDevice, QObject *parent)
- : QObject(parent)
- , d(new PrivateSoundSource(this, audioDevice))
-{
-}
-
-QSoundEffectPrivate::~QSoundEffectPrivate()
-{
-}
-
-void QSoundEffectPrivate::release()
-{
- stop();
- if (d->m_audioOutput) {
- d->m_audioOutput->stop();
- d->m_audioOutput->deleteLater();
- d->m_sample->release();
- }
- delete d;
- this->deleteLater();
-}
-
-QStringList QSoundEffectPrivate::supportedMimeTypes()
-{
- // Only return supported mime types if we have a audio device available
- const QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
- if (devices.size() <= 0)
- return QStringList();
-
- return QStringList() << QLatin1String("audio/x-wav")
- << QLatin1String("audio/wav")
- << QLatin1String("audio/wave")
- << QLatin1String("audio/x-pn-wav");
-}
-
-QUrl QSoundEffectPrivate::source() const
-{
- return d->m_url;
-}
-
-void QSoundEffectPrivate::setSource(const QUrl &url)
-{
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << this << "setSource current=" << d->m_url << ", to=" << url;
-#endif
- Q_ASSERT(d->m_url != url);
-
- stop();
-
- d->m_url = url;
-
- d->m_sampleReady = false;
-
- if (url.isEmpty()) {
- setStatus(QSoundEffect::Null);
- return;
- }
-
- if (!url.isValid()) {
- setStatus(QSoundEffect::Error);
- return;
- }
-
- if (d->m_sample) {
- if (!d->m_sampleReady) {
- disconnect(d->m_sample, &QSample::error, d, &PrivateSoundSource::decoderError);
- disconnect(d->m_sample, &QSample::ready, d, &PrivateSoundSource::sampleReady);
- }
- d->m_sample->release();
- d->m_sample = nullptr;
- }
-
- if (d->m_audioOutput) {
- disconnect(d->m_audioOutput, &QAudioOutput::stateChanged, d, &PrivateSoundSource::stateChanged);
- d->m_audioOutput->stop();
- d->m_audioOutput->deleteLater();
- d->m_audioOutput = nullptr;
- }
-
- setStatus(QSoundEffect::Loading);
- d->m_sample = sampleCache()->requestSample(url);
- connect(d->m_sample, &QSample::error, d, &PrivateSoundSource::decoderError);
- connect(d->m_sample, &QSample::ready, d, &PrivateSoundSource::sampleReady);
-
- switch (d->m_sample->state()) {
- case QSample::Ready:
- d->sampleReady();
- break;
- case QSample::Error:
- d->decoderError();
- break;
- default:
- break;
- }
-}
-
-int QSoundEffectPrivate::loopCount() const
-{
- return d->m_loopCount;
-}
-
-int QSoundEffectPrivate::loopsRemaining() const
-{
- return d->m_runningCount;
-}
-
-void QSoundEffectPrivate::setLoopCount(int loopCount)
-{
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << "setLoopCount " << loopCount;
-#endif
- if (loopCount == 0)
- loopCount = 1;
- d->m_loopCount = loopCount;
- if (d->m_playing)
- setLoopsRemaining(loopCount);
-}
-
-qreal QSoundEffectPrivate::volume() const
-{
- if (d->m_audioOutput && !d->m_muted)
- return d->m_audioOutput->volume();
-
- return d->m_volume;
-}
-
-void QSoundEffectPrivate::setVolume(qreal volume)
-{
- d->m_volume = volume;
-
- if (d->m_audioOutput && !d->m_muted)
- d->m_audioOutput->setVolume(volume);
-
- emit volumeChanged();
-}
-
-bool QSoundEffectPrivate::isMuted() const
-{
- return d->m_muted;
-}
-
-void QSoundEffectPrivate::setMuted(bool muted)
-{
- if (muted && d->m_audioOutput)
- d->m_audioOutput->setVolume(0);
- else if (!muted && d->m_audioOutput && d->m_muted)
- d->m_audioOutput->setVolume(d->m_volume);
-
- d->m_muted = muted;
- emit mutedChanged();
-}
-
-bool QSoundEffectPrivate::isLoaded() const
-{
- return d->m_status == QSoundEffect::Ready;
-}
-
-
-bool QSoundEffectPrivate::isPlaying() const
-{
- return d->m_playing;
-}
-
-QSoundEffect::Status QSoundEffectPrivate::status() const
-{
- return d->m_status;
-}
-
-void QSoundEffectPrivate::play()
-{
- d->m_offset = 0;
- setLoopsRemaining(d->m_loopCount);
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << this << "play";
-#endif
- if (d->m_status == QSoundEffect::Null || d->m_status == QSoundEffect::Error) {
- setStatus(QSoundEffect::Null);
- return;
- }
- setPlaying(true);
- if (d->m_audioOutput && d->m_audioOutput->state() == QAudio::StoppedState && d->m_sampleReady)
- d->m_audioOutput->start(d);
-}
-
-void QSoundEffectPrivate::stop()
-{
- if (!d->m_playing)
- return;
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << "stop()";
-#endif
- d->m_offset = 0;
-
- setPlaying(false);
-
- if (d->m_audioOutput)
- d->m_audioOutput->stop();
-}
-
-void QSoundEffectPrivate::setStatus(QSoundEffect::Status status)
-{
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << this << "setStatus" << status;
-#endif
- if (d->m_status == status)
- return;
- bool oldLoaded = isLoaded();
- d->m_status = status;
- emit statusChanged();
- if (oldLoaded != isLoaded())
- emit loadedChanged();
-}
-
-void QSoundEffectPrivate::setPlaying(bool playing)
-{
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << this << "setPlaying(" << playing << ")";
-#endif
- if (d->m_playing == playing)
- return;
- d->m_playing = playing;
- emit playingChanged();
-}
-
-void QSoundEffectPrivate::setLoopsRemaining(int loopsRemaining)
-{
- if (d->m_runningCount == loopsRemaining)
- return;
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << this << "setLoopsRemaining " << loopsRemaining;
-#endif
- d->m_runningCount = loopsRemaining;
- emit loopsRemainingChanged();
-}
-
-/* Categories are ignored */
-QString QSoundEffectPrivate::category() const
-{
- return d->m_category;
-}
-
-void QSoundEffectPrivate::setCategory(const QString &category)
-{
- if (d->m_category != category && !d->m_playing) {
- d->m_category = category;
- emit categoryChanged();
- }
-}
-
-PrivateSoundSource::PrivateSoundSource(QSoundEffectPrivate *s, const QAudioDeviceInfo &audioDevice)
- : QIODevice(s)
- , m_audioDevice(audioDevice)
-{
- soundeffect = s;
- m_category = QLatin1String("game");
- open(QIODevice::ReadOnly);
-}
-
-void PrivateSoundSource::sampleReady()
-{
- if (m_status == QSoundEffect::Error)
- return;
-
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << this << "sampleReady "<<m_playing;
-#endif
- disconnect(m_sample, &QSample::error, this, &PrivateSoundSource::decoderError);
- disconnect(m_sample, &QSample::ready, this, &PrivateSoundSource::sampleReady);
- if (!m_audioOutput) {
- if (m_audioDevice.isNull())
- m_audioOutput = new QAudioOutput(m_sample->format());
- else
- m_audioOutput = new QAudioOutput(m_audioDevice, m_sample->format());
- connect(m_audioOutput, &QAudioOutput::stateChanged, this, &PrivateSoundSource::stateChanged);
- if (!m_muted)
- m_audioOutput->setVolume(m_volume);
- else
- m_audioOutput->setVolume(0);
- }
- m_sampleReady = true;
- soundeffect->setStatus(QSoundEffect::Ready);
-
- if (m_playing && m_audioOutput->state() == QAudio::StoppedState)
- m_audioOutput->start(this);
-}
-
-void PrivateSoundSource::decoderError()
-{
- qWarning("QSoundEffect(qaudio): Error decoding source %ls", qUtf16Printable(m_url.toString()));
- disconnect(m_sample, &QSample::ready, this, &PrivateSoundSource::sampleReady);
- disconnect(m_sample, &QSample::error, this, &PrivateSoundSource::decoderError);
- m_playing = false;
- soundeffect->setStatus(QSoundEffect::Error);
-}
-
-void PrivateSoundSource::stateChanged(QAudio::State state)
-{
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << this << "stateChanged " << state;
-#endif
- if ((state == QAudio::IdleState && m_runningCount == 0)
- || (state == QAudio::StoppedState && m_audioOutput->error() != QAudio::NoError))
- emit soundeffect->stop();
-}
-
-qint64 PrivateSoundSource::readData(char *data, qint64 len)
-{
- if ((m_runningCount > 0 || m_runningCount == QSoundEffect::Infinite) && m_playing) {
-
- if (m_sample->state() != QSample::Ready)
- return 0;
-
- qint64 bytesWritten = 0;
-
- const int periodSize = m_audioOutput->periodSize();
- const int sampleSize = m_sample->data().size();
- const char* sampleData = m_sample->data().constData();
-
- // Some systems can have large buffers we only need a max of three
- int periodsFree = qMin(3, (int)(m_audioOutput->bytesFree()/periodSize));
- int dataOffset = 0;
-
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << "bytesFree=" << m_audioOutput->bytesFree() << ", can fit " << periodsFree << " periodSize() chunks";
-#endif
-
- while ((periodsFree > 0) && (bytesWritten + periodSize <= len)) {
-
- if (sampleSize - m_offset >= periodSize) {
- // We can fit a whole period of data
- memcpy(data + dataOffset, sampleData + m_offset, periodSize);
- m_offset += periodSize;
- dataOffset += periodSize;
- bytesWritten += periodSize;
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << "WHOLE PERIOD: bytesWritten=" << bytesWritten << ", offset=" << m_offset
- << ", filesize=" << sampleSize;
-#endif
- } else {
- // We are at end of sound, first write what is left of current sound
- memcpy(data + dataOffset, sampleData + m_offset, sampleSize - m_offset);
- bytesWritten += sampleSize - m_offset;
- int wrapLen = periodSize - (sampleSize - m_offset);
- if (wrapLen > sampleSize)
- wrapLen = sampleSize;
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << "END OF SOUND: bytesWritten=" << bytesWritten << ", offset=" << m_offset
- << ", part1=" << (sampleSize-m_offset);
-#endif
- dataOffset += (sampleSize - m_offset);
- m_offset = 0;
-
- if (m_runningCount > 0 && m_runningCount != QSoundEffect::Infinite)
- soundeffect->setLoopsRemaining(m_runningCount-1);
-
- if (m_runningCount > 0 || m_runningCount == QSoundEffect::Infinite) {
- // There are still more loops of this sound to play, append the start of sound to make up full period
- memcpy(data + dataOffset, sampleData + m_offset, wrapLen);
- m_offset += wrapLen;
- dataOffset += wrapLen;
- bytesWritten += wrapLen;
-#ifdef QT_QAUDIO_DEBUG
- qDebug() << "APPEND START FOR FULL PERIOD: bytesWritten=" << bytesWritten << ", offset=" << m_offset
- << ", part2=" << wrapLen;
- qDebug() << "part1 + part2 should be a period " << periodSize;
-#endif
- }
- }
- if (m_runningCount == 0)
- break;
-
- periodsFree--;
- }
- return bytesWritten;
- }
-
- return 0;
-}
-
-qint64 PrivateSoundSource::writeData(const char *data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
- return 0;
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qsoundeffect_qaudio_p.cpp"
diff --git a/src/multimedia/audio/qsoundeffect_qaudio_p.h b/src/multimedia/audio/qsoundeffect_qaudio_p.h
deleted file mode 100644
index a3a48f60d..000000000
--- a/src/multimedia/audio/qsoundeffect_qaudio_p.h
+++ /dev/null
@@ -1,151 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSOUNDEFFECT_QAUDIO_H
-#define QSOUNDEFFECT_QAUDIO_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qobject.h>
-#include <QtCore/qurl.h>
-#include "qaudiooutput.h"
-#include "qsamplecache_p.h"
-#include "qsoundeffect.h"
-
-QT_BEGIN_NAMESPACE
-
-class QSoundEffectPrivate;
-
-class PrivateSoundSource : public QIODevice
-{
- friend class QSoundEffectPrivate;
- Q_OBJECT
-public:
- PrivateSoundSource(QSoundEffectPrivate *s, const QAudioDeviceInfo &audioDevice = QAudioDeviceInfo());
- ~PrivateSoundSource() {}
-
- qint64 readData(char *data, qint64 len) override;
- qint64 writeData(const char *data, qint64 len) override;
-
-private Q_SLOTS:
- void sampleReady();
- void decoderError();
- void stateChanged(QAudio::State);
-
-private:
- QUrl m_url;
- int m_loopCount = 1;
- int m_runningCount = 0;
- bool m_playing = false;
- QSoundEffect::Status m_status = QSoundEffect::Null;
- QAudioOutput *m_audioOutput = nullptr;
- QSample *m_sample = nullptr;
- bool m_muted = false;
- qreal m_volume = 1.0;
- bool m_sampleReady = false;
- qint64 m_offset = 0;
- QString m_category;
- QAudioDeviceInfo m_audioDevice;
- QSoundEffectPrivate *soundeffect = nullptr;
-};
-
-
-class QSoundEffectPrivate : public QObject
-{
- friend class PrivateSoundSource;
- Q_OBJECT
-public:
-
- explicit QSoundEffectPrivate(QObject *parent);
- explicit QSoundEffectPrivate(const QAudioDeviceInfo &audioDevice, QObject *parent);
- ~QSoundEffectPrivate();
-
- static QStringList supportedMimeTypes();
-
- QUrl source() const;
- void setSource(const QUrl &url);
- int loopCount() const;
- int loopsRemaining() const;
- void setLoopCount(int loopCount);
- qreal volume() const;
- void setVolume(qreal volume);
- bool isMuted() const;
- void setMuted(bool muted);
- bool isLoaded() const;
- bool isPlaying() const;
- QSoundEffect::Status status() const;
-
- void release();
-
- QString category() const;
- void setCategory(const QString &);
-
-public Q_SLOTS:
- void play();
- void stop();
-
-Q_SIGNALS:
- void loopsRemainingChanged();
- void volumeChanged();
- void mutedChanged();
- void loadedChanged();
- void playingChanged();
- void statusChanged();
- void categoryChanged();
-
-private:
- void setStatus(QSoundEffect::Status status);
- void setPlaying(bool playing);
- void setLoopsRemaining(int loopsRemaining);
-
- PrivateSoundSource *d = nullptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QSOUNDEFFECT_QAUDIO_H
diff --git a/src/multimedia/audio/qtaudio.cpp b/src/multimedia/audio/qtaudio.cpp
new file mode 100644
index 000000000..fb14e5093
--- /dev/null
+++ b/src/multimedia/audio/qtaudio.cpp
@@ -0,0 +1,245 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#include <qtaudio.h>
+#include <qmath.h>
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+#define LOG100 4.60517018599
+
+/*!
+ \namespace QtAudio
+ \ingroup multimedia-namespaces
+ \brief The QtAudio namespace contains enums used by the audio classes.
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_audio
+*/
+
+/*!
+ \enum QtAudio::Error
+
+ \value NoError No errors have occurred
+ \value OpenError An error occurred opening the audio device
+ \value IOError An error occurred during read/write of audio device
+ \value UnderrunError Audio data is not being fed to the audio device at a fast enough rate
+ \value FatalError A non-recoverable error has occurred, the audio device is not usable at this time.
+*/
+
+/*!
+ \enum QtAudio::State
+
+ \value ActiveState Audio data is being processed, this state is set after start() is called
+ and while audio data is available to be processed.
+ \value SuspendedState The audio stream is in a suspended state. Entered after suspend() is called
+ or when another stream takes control of the audio device. In the later case,
+ a call to resume will return control of the audio device to this stream. This
+ should usually only be done upon user request.
+ \value StoppedState The audio device is closed, and is not processing any audio data
+ \value IdleState The QIODevice passed in has no data and audio system's buffer is empty, this state
+ is set after start() is called and while no audio data is available to be processed.
+*/
+
+/*!
+ \enum QtAudio::VolumeScale
+
+ This enum defines the different audio volume scales.
+
+ \value LinearVolumeScale Linear scale. \c 0.0 (0%) is silence and \c 1.0 (100%) is full
+ volume. All Qt Multimedia classes that have an audio volume use
+ a linear scale.
+ \value CubicVolumeScale Cubic scale. \c 0.0 (0%) is silence and \c 1.0 (100%) is full
+ volume.
+ \value LogarithmicVolumeScale Logarithmic Scale. \c 0.0 (0%) is silence and \c 1.0 (100%) is
+ full volume. UI volume controls should usually use a logarithmic
+ scale.
+ \value DecibelVolumeScale Decibel (dB, amplitude) logarithmic scale. \c -200 is silence
+ and \c 0 is full volume.
+
+ \sa QtAudio::convertVolume()
+*/
+
+#if defined(Q_QDOC)
+namespace QtAudio
+#else
+namespace QAudio
+#endif
+{
+
+/*!
+ Converts an audio \a volume \a from a volume scale \a to another, and returns the result.
+
+ Depending on the context, different scales are used to represent audio volume. All Qt Multimedia
+ classes that have an audio volume use a linear scale, the reason is that the loudness of a
+ speaker is controlled by modulating its voltage on a linear scale. The human ear on the other
+ hand, perceives loudness in a logarithmic way. Using a logarithmic scale for volume controls
+ is therefore appropriate in most applications. The decibel scale is logarithmic by nature and
+ is commonly used to define sound levels, it is usually used for UI volume controls in
+ professional audio applications. The cubic scale is a computationally cheap approximation of a
+ logarithmic scale, it provides more control over lower volume levels.
+
+ The following example shows how to convert the volume value from a slider control before passing
+ it to a QMediaPlayer. As a result, the perceived increase in volume is the same when increasing
+ the volume slider from 20 to 30 as it is from 50 to 60:
+
+ \snippet multimedia-snippets/audio.cpp Volume conversion
+
+ \sa VolumeScale, QAudioSink::setVolume(), QAudioSource::setVolume(),
+ QSoundEffect::setVolume()
+*/
+float convertVolume(float volume, VolumeScale from, VolumeScale to)
+{
+ switch (from) {
+ case LinearVolumeScale:
+ volume = qMax(float(0), volume);
+ switch (to) {
+ case LinearVolumeScale:
+ return volume;
+ case CubicVolumeScale:
+ return qPow(volume, float(1 / 3.0));
+ case LogarithmicVolumeScale:
+ return 1 - std::exp(-volume * LOG100);
+ case DecibelVolumeScale:
+ if (volume < 0.001)
+ return float(-200);
+ else
+ return float(20.0) * std::log10(volume);
+ }
+ break;
+ case CubicVolumeScale:
+ volume = qMax(float(0), volume);
+ switch (to) {
+ case LinearVolumeScale:
+ return volume * volume * volume;
+ case CubicVolumeScale:
+ return volume;
+ case LogarithmicVolumeScale:
+ return 1 - std::exp(-volume * volume * volume * LOG100);
+ case DecibelVolumeScale:
+ if (volume < 0.001)
+ return float(-200);
+ else
+ return float(3.0 * 20.0) * std::log10(volume);
+ }
+ break;
+ case LogarithmicVolumeScale:
+ volume = qMax(float(0), volume);
+ switch (to) {
+ case LinearVolumeScale:
+ if (volume > 0.99)
+ return 1;
+ else
+ return -std::log(1 - volume) / LOG100;
+ case CubicVolumeScale:
+ if (volume > 0.99)
+ return 1;
+ else
+ return qPow(-std::log(1 - volume) / LOG100, float(1 / 3.0));
+ case LogarithmicVolumeScale:
+ return volume;
+ case DecibelVolumeScale:
+ if (volume < 0.001)
+ return float(-200);
+ else if (volume > 0.99)
+ return 0;
+ else
+ return float(20.0) * std::log10(-std::log(1 - volume) / LOG100);
+ }
+ break;
+ case DecibelVolumeScale:
+ switch (to) {
+ case LinearVolumeScale:
+ return qPow(float(10.0), volume / float(20.0));
+ case CubicVolumeScale:
+ return qPow(float(10.0), volume / float(3.0 * 20.0));
+ case LogarithmicVolumeScale:
+ if (qFuzzyIsNull(volume))
+ return 1;
+ else
+ return 1 - std::exp(-qPow(float(10.0), volume / float(20.0)) * LOG100);
+ case DecibelVolumeScale:
+ return volume;
+ }
+ break;
+ }
+
+ return volume;
+}
+
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug dbg, QAudio::Error error)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ switch (error) {
+ case QAudio::NoError:
+ dbg << "NoError";
+ break;
+ case QAudio::OpenError:
+ dbg << "OpenError";
+ break;
+ case QAudio::IOError:
+ dbg << "IOError";
+ break;
+ case QAudio::UnderrunError:
+ dbg << "UnderrunError";
+ break;
+ case QAudio::FatalError:
+ dbg << "FatalError";
+ break;
+ }
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, QAudio::State state)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ switch (state) {
+ case QAudio::ActiveState:
+ dbg << "ActiveState";
+ break;
+ case QAudio::SuspendedState:
+ dbg << "SuspendedState";
+ break;
+ case QAudio::StoppedState:
+ dbg << "StoppedState";
+ break;
+ case QAudio::IdleState:
+ dbg << "IdleState";
+ break;
+ }
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, QAudio::VolumeScale scale)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ switch (scale) {
+ case QAudio::LinearVolumeScale:
+ dbg << "LinearVolumeScale";
+ break;
+ case QAudio::CubicVolumeScale:
+ dbg << "CubicVolumeScale";
+ break;
+ case QAudio::LogarithmicVolumeScale:
+ dbg << "LogarithmicVolumeScale";
+ break;
+ case QAudio::DecibelVolumeScale:
+ dbg << "DecibelVolumeScale";
+ break;
+ }
+ return dbg;
+}
+
+#endif
+
+
+QT_END_NAMESPACE
+
diff --git a/src/multimedia/audio/qtaudio.h b/src/multimedia/audio/qtaudio.h
new file mode 100644
index 000000000..6f6e0e668
--- /dev/null
+++ b/src/multimedia/audio/qtaudio.h
@@ -0,0 +1,18 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#ifndef QTAUDIO_H
+#define QTAUDIO_H
+
+#if 0
+#pragma qt_class(QtAudio)
+#endif
+
+#include <QtMultimedia/qaudio.h>
+
+QT_BEGIN_NAMESPACE
+
+QT_END_NAMESPACE
+
+#endif // QTAUDIO_H
diff --git a/src/multimedia/audio/qwavedecoder.cpp b/src/multimedia/audio/qwavedecoder.cpp
new file mode 100644
index 000000000..452363ddc
--- /dev/null
+++ b/src/multimedia/audio/qwavedecoder.cpp
@@ -0,0 +1,507 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwavedecoder.h"
+
+#include <QtCore/qtimer.h>
+#include <QtCore/qendian.h>
+#include <limits.h>
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+
+void bswap2(char *data, qsizetype count) noexcept
+{
+ for (qsizetype i = 0; i < count; ++i) {
+ qSwap(data[0], data[1]);
+ ++count;
+ data += 2;
+ }
+}
+
+void bswap4(char *data, qsizetype count) noexcept
+{
+ for (qsizetype i = 0; i < count; ++i) {
+ qSwap(data[0], data[3]);
+ qSwap(data[1], data[2]);
+ ++count;
+ data += 4;
+ }
+}
+
+}
+
+QWaveDecoder::QWaveDecoder(QIODevice *device, QObject *parent)
+ : QIODevice(parent),
+ device(device)
+{
+}
+
+QWaveDecoder::QWaveDecoder(QIODevice *device, const QAudioFormat &format, QObject *parent)
+ : QIODevice(parent),
+ device(device),
+ format(format)
+{
+}
+
+QWaveDecoder::~QWaveDecoder() = default;
+
+bool QWaveDecoder::open(QIODevice::OpenMode mode)
+{
+ bool canOpen = false;
+ if (mode & QIODevice::ReadOnly && mode & ~QIODevice::WriteOnly) {
+ canOpen = QIODevice::open(mode | QIODevice::Unbuffered);
+ if (canOpen && enoughDataAvailable())
+ handleData();
+ else
+ connect(device, &QIODevice::readyRead, this, &QWaveDecoder::handleData);
+ return canOpen;
+ }
+
+ if (mode & QIODevice::WriteOnly) {
+ if (format.sampleFormat() != QAudioFormat::Int16)
+ return false; // data format is not supported
+ canOpen = QIODevice::open(mode);
+ if (canOpen && writeHeader())
+ haveHeader = true;
+ return canOpen;
+ }
+ return QIODevice::open(mode);
+}
+
+void QWaveDecoder::close()
+{
+ if (isOpen() && (openMode() & QIODevice::WriteOnly)) {
+ Q_ASSERT(dataSize < INT_MAX);
+ if (!device->isOpen() || !writeDataLength())
+ qWarning() << "Failed to finalize wav file";
+ }
+ QIODevice::close();
+}
+
+bool QWaveDecoder::seek(qint64 pos)
+{
+ return device->seek(pos);
+}
+
+qint64 QWaveDecoder::pos() const
+{
+ return device->pos();
+}
+
+void QWaveDecoder::setIODevice(QIODevice * /* device */)
+{
+}
+
+QAudioFormat QWaveDecoder::audioFormat() const
+{
+ return format;
+}
+
+QIODevice* QWaveDecoder::getDevice()
+{
+ return device;
+}
+
+int QWaveDecoder::duration() const
+{
+ if (openMode() & QIODevice::WriteOnly)
+ return 0;
+ int bytesPerSec = format.bytesPerFrame() * format.sampleRate();
+ return bytesPerSec ? size() * 1000 / bytesPerSec : 0;
+}
+
+qint64 QWaveDecoder::size() const
+{
+ if (openMode() & QIODevice::ReadOnly) {
+ if (!haveFormat)
+ return 0;
+ if (bps == 24)
+ return dataSize*2/3;
+ return dataSize;
+ } else {
+ return device->size();
+ }
+}
+
+bool QWaveDecoder::isSequential() const
+{
+ return device->isSequential();
+}
+
+qint64 QWaveDecoder::bytesAvailable() const
+{
+ return haveFormat ? device->bytesAvailable() : 0;
+}
+
+qint64 QWaveDecoder::headerLength()
+{
+ return HeaderLength;
+}
+
+qint64 QWaveDecoder::readData(char *data, qint64 maxlen)
+{
+ const int bytesPerSample = format.bytesPerSample();
+ if (!haveFormat || bytesPerSample == 0)
+ return 0;
+
+ if (bps == 24) {
+ // 24 bit WAV, read in as 16 bit
+ qint64 l = 0;
+ while (l < maxlen - 1) {
+ char tmp[3];
+ device->read(tmp, 3);
+ if (byteSwap)
+ qSwap(tmp[0], tmp[2]);
+#if Q_BYTE_ORDER == Q_BIG_ENDIAN
+ data[0] = tmp[0];
+ data[1] = tmp[1];
+#else
+ data[0] = tmp[1];
+ data[1] = tmp[2];
+#endif
+ data += 2;
+ l += 2;
+ }
+ return l;
+ }
+
+ qint64 nSamples = maxlen / bytesPerSample;
+ maxlen = nSamples * bytesPerSample;
+ int read = device->read(data, maxlen);
+
+ if (!byteSwap || format.bytesPerFrame() == 1)
+ return read;
+
+ nSamples = read / bytesPerSample;
+ switch (bytesPerSample) {
+ case 2:
+ bswap2(data, nSamples);
+ break;
+ case 4:
+ bswap4(data, nSamples);
+ break;
+ default:
+ Q_UNREACHABLE();
+ }
+ return read;
+
+}
+
+qint64 QWaveDecoder::writeData(const char *data, qint64 len)
+{
+ if (!haveHeader)
+ return 0;
+ qint64 written = device->write(data, len);
+ dataSize += written;
+ return written;
+}
+
+bool QWaveDecoder::writeHeader()
+{
+ if (device->size() != 0)
+ return false;
+
+#ifndef Q_LITTLE_ENDIAN
+ // only implemented for LITTLE ENDIAN
+ return false;
+#endif
+
+ CombinedHeader header;
+
+ memset(&header, 0, HeaderLength);
+
+ // RIFF header
+ memcpy(header.riff.descriptor.id,"RIFF",4);
+ qToLittleEndian<quint32>(quint32(dataSize + HeaderLength - 8),
+ reinterpret_cast<unsigned char*>(&header.riff.descriptor.size));
+ memcpy(header.riff.type, "WAVE",4);
+
+ // WAVE header
+ memcpy(header.wave.descriptor.id,"fmt ",4);
+ qToLittleEndian<quint32>(quint32(16),
+ reinterpret_cast<unsigned char*>(&header.wave.descriptor.size));
+ qToLittleEndian<quint16>(quint16(1),
+ reinterpret_cast<unsigned char*>(&header.wave.audioFormat));
+ qToLittleEndian<quint16>(quint16(format.channelCount()),
+ reinterpret_cast<unsigned char*>(&header.wave.numChannels));
+ qToLittleEndian<quint32>(quint32(format.sampleRate()),
+ reinterpret_cast<unsigned char*>(&header.wave.sampleRate));
+ qToLittleEndian<quint32>(quint32(format.sampleRate() * format.bytesPerFrame()),
+ reinterpret_cast<unsigned char*>(&header.wave.byteRate));
+ qToLittleEndian<quint16>(quint16(format.channelCount() * format.bytesPerSample()),
+ reinterpret_cast<unsigned char*>(&header.wave.blockAlign));
+ qToLittleEndian<quint16>(quint16(format.bytesPerSample() * 8),
+ reinterpret_cast<unsigned char*>(&header.wave.bitsPerSample));
+
+ // DATA header
+ memcpy(header.data.descriptor.id,"data",4);
+ qToLittleEndian<quint32>(quint32(dataSize),
+ reinterpret_cast<unsigned char*>(&header.data.descriptor.size));
+
+ return device->write(reinterpret_cast<const char *>(&header), HeaderLength);
+}
+
+bool QWaveDecoder::writeDataLength()
+{
+#ifndef Q_LITTLE_ENDIAN
+ // only implemented for LITTLE ENDIAN
+ return false;
+#endif
+
+ if (isSequential())
+ return false;
+
+ // seek to RIFF header size, see header.riff.descriptor.size above
+ if (!device->seek(4)) {
+ qDebug() << "can't seek";
+ return false;
+ }
+
+ quint32 length = dataSize + HeaderLength - 8;
+ if (device->write(reinterpret_cast<const char *>(&length), 4) != 4)
+ return false;
+
+ // seek to DATA header size, see header.data.descriptor.size above
+ if (!device->seek(40))
+ return false;
+
+ return device->write(reinterpret_cast<const char *>(&dataSize), 4);
+}
+
+void QWaveDecoder::parsingFailed()
+{
+ Q_ASSERT(device);
+ disconnect(device, &QIODevice::readyRead, this, &QWaveDecoder::handleData);
+ emit parsingError();
+}
+
+void QWaveDecoder::handleData()
+{
+ if (openMode() == QIODevice::WriteOnly)
+ return;
+
+ // As a special "state", if we have junk to skip, we do
+ if (junkToSkip > 0) {
+ discardBytes(junkToSkip); // this also updates junkToSkip
+
+ // If we couldn't skip all the junk, return
+ if (junkToSkip > 0) {
+ // We might have run out
+ if (device->atEnd())
+ parsingFailed();
+ return;
+ }
+ }
+
+ if (state == QWaveDecoder::InitialState) {
+ if (device->bytesAvailable() < qint64(sizeof(RIFFHeader)))
+ return;
+
+ RIFFHeader riff;
+ device->read(reinterpret_cast<char *>(&riff), sizeof(RIFFHeader));
+
+ // RIFF = little endian RIFF, RIFX = big endian RIFF
+ if (((qstrncmp(riff.descriptor.id, "RIFF", 4) != 0) && (qstrncmp(riff.descriptor.id, "RIFX", 4) != 0))
+ || qstrncmp(riff.type, "WAVE", 4) != 0) {
+ parsingFailed();
+ return;
+ }
+
+ state = QWaveDecoder::WaitingForFormatState;
+ bigEndian = (qstrncmp(riff.descriptor.id, "RIFX", 4) == 0);
+ byteSwap = (bigEndian != (QSysInfo::ByteOrder == QSysInfo::BigEndian));
+ }
+
+ if (state == QWaveDecoder::WaitingForFormatState) {
+ if (findChunk("fmt ")) {
+ chunk descriptor;
+ peekChunk(&descriptor);
+
+ quint32 rawChunkSize = descriptor.size + sizeof(chunk);
+ if (device->bytesAvailable() < qint64(rawChunkSize))
+ return;
+
+ WAVEHeader wave;
+ device->read(reinterpret_cast<char *>(&wave), sizeof(WAVEHeader));
+
+ if (rawChunkSize > sizeof(WAVEHeader))
+ discardBytes(rawChunkSize - sizeof(WAVEHeader));
+
+ // Swizzle this
+ if (bigEndian) {
+ wave.audioFormat = qFromBigEndian<quint16>(wave.audioFormat);
+ } else {
+ wave.audioFormat = qFromLittleEndian<quint16>(wave.audioFormat);
+ }
+
+ if (wave.audioFormat != 0 && wave.audioFormat != 1) {
+ // 32bit wave files have format == 0xFFFE (WAVE_FORMAT_EXTENSIBLE).
+ // but don't support them at the moment.
+ parsingFailed();
+ return;
+ }
+
+ int rate;
+ int channels;
+ if (bigEndian) {
+ bps = qFromBigEndian<quint16>(wave.bitsPerSample);
+ rate = qFromBigEndian<quint32>(wave.sampleRate);
+ channels = qFromBigEndian<quint16>(wave.numChannels);
+ } else {
+ bps = qFromLittleEndian<quint16>(wave.bitsPerSample);
+ rate = qFromLittleEndian<quint32>(wave.sampleRate);
+ channels = qFromLittleEndian<quint16>(wave.numChannels);
+ }
+
+ QAudioFormat::SampleFormat fmt = QAudioFormat::Unknown;
+ switch(bps) {
+ case 8:
+ fmt = QAudioFormat::UInt8;
+ break;
+ case 16:
+ fmt = QAudioFormat::Int16;
+ break;
+ case 24:
+ fmt = QAudioFormat::Int16;
+ break;
+ case 32:
+ fmt = QAudioFormat::Int32;
+ break;
+ }
+ if (fmt == QAudioFormat::Unknown || rate == 0 || channels == 0) {
+ parsingFailed();
+ return;
+ }
+
+ format.setSampleFormat(fmt);
+ format.setSampleRate(rate);
+ format.setChannelCount(channels);
+
+ state = QWaveDecoder::WaitingForDataState;
+ }
+ }
+
+ if (state == QWaveDecoder::WaitingForDataState) {
+ if (findChunk("data")) {
+ disconnect(device, &QIODevice::readyRead, this, &QWaveDecoder::handleData);
+
+ chunk descriptor;
+ device->read(reinterpret_cast<char *>(&descriptor), sizeof(chunk));
+ if (bigEndian)
+ descriptor.size = qFromBigEndian<quint32>(descriptor.size);
+ else
+ descriptor.size = qFromLittleEndian<quint32>(descriptor.size);
+
+ dataSize = descriptor.size; //means the data size from the data header, not the actual file size
+ if (!dataSize)
+ dataSize = device->size() - headerLength();
+
+ haveFormat = true;
+ connect(device, &QIODevice::readyRead, this, &QIODevice::readyRead);
+ emit formatKnown();
+
+ return;
+ }
+ }
+
+ // If we hit the end without finding data, it's a parsing error
+ if (device->atEnd()) {
+ parsingFailed();
+ }
+}
+
+bool QWaveDecoder::enoughDataAvailable()
+{
+ chunk descriptor;
+ if (!peekChunk(&descriptor, false))
+ return false;
+
+ // This is only called for the RIFF/RIFX header, before bigEndian is set,
+ // so we have to manually swizzle
+ if (qstrncmp(descriptor.id, "RIFX", 4) == 0)
+ descriptor.size = qFromBigEndian<quint32>(descriptor.size);
+ if (qstrncmp(descriptor.id, "RIFF", 4) == 0)
+ descriptor.size = qFromLittleEndian<quint32>(descriptor.size);
+
+ if (device->bytesAvailable() < qint64(sizeof(chunk) + descriptor.size))
+ return false;
+
+ return true;
+}
+
+bool QWaveDecoder::findChunk(const char *chunkId)
+{
+ chunk descriptor;
+
+ do {
+ if (!peekChunk(&descriptor))
+ return false;
+
+ if (qstrncmp(descriptor.id, chunkId, 4) == 0)
+ return true;
+
+ // A program reading a RIFF file can skip over any chunk whose chunk
+ // ID it doesn't recognize; it simply skips the number of bytes specified
+ // by ckSize plus the pad byte, if present. See Multimedia Programming
+ // Interface and Data Specifications 1.0. IBM / Microsoft. August 1991. pp. 10-11.
+ const quint32 sizeWithPad = descriptor.size + (descriptor.size & 1);
+
+ // It's possible that bytes->available() is less than the chunk size
+ // if it's corrupt.
+ junkToSkip = qint64(sizeof(chunk) + sizeWithPad);
+
+ // Skip the current amount
+ if (junkToSkip > 0)
+ discardBytes(junkToSkip);
+
+ // If we still have stuff left, just exit and try again later
+ // since we can't call peekChunk
+ if (junkToSkip > 0)
+ return false;
+
+ } while (device->bytesAvailable() > 0);
+
+ return false;
+}
+
+bool QWaveDecoder::peekChunk(chunk *pChunk, bool handleEndianness)
+{
+ if (device->bytesAvailable() < qint64(sizeof(chunk)))
+ return false;
+
+ if (!device->peek(reinterpret_cast<char *>(pChunk), sizeof(chunk)))
+ return false;
+
+ if (handleEndianness) {
+ if (bigEndian)
+ pChunk->size = qFromBigEndian<quint32>(pChunk->size);
+ else
+ pChunk->size = qFromLittleEndian<quint32>(pChunk->size);
+ }
+ return true;
+}
+
+void QWaveDecoder::discardBytes(qint64 numBytes)
+{
+ // Discards a number of bytes
+ // If the iodevice doesn't have this many bytes in it,
+ // remember how much more junk we have to skip.
+ if (device->isSequential()) {
+ QByteArray r = device->read(qMin(numBytes, qint64(16384))); // uggh, wasted memory, limit to a max of 16k
+ if (r.size() < numBytes)
+ junkToSkip = numBytes - r.size();
+ else
+ junkToSkip = 0;
+ } else {
+ quint64 origPos = device->pos();
+ device->seek(device->pos() + numBytes);
+ junkToSkip = origPos + numBytes - device->pos();
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwavedecoder.cpp"
diff --git a/src/multimedia/audio/qwavedecoder.h b/src/multimedia/audio/qwavedecoder.h
new file mode 100644
index 000000000..a96e731db
--- /dev/null
+++ b/src/multimedia/audio/qwavedecoder.h
@@ -0,0 +1,115 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef WAVEDECODER_H
+#define WAVEDECODER_H
+
+#include <QtCore/qiodevice.h>
+#include <QtMultimedia/qaudioformat.h>
+
+
+QT_BEGIN_NAMESPACE
+
+
+
+class Q_MULTIMEDIA_EXPORT QWaveDecoder : public QIODevice
+{
+ Q_OBJECT
+
+public:
+ explicit QWaveDecoder(QIODevice *device, QObject *parent = nullptr);
+ explicit QWaveDecoder(QIODevice *device, const QAudioFormat &format,
+ QObject *parent = nullptr);
+ ~QWaveDecoder();
+
+ QAudioFormat audioFormat() const;
+ QIODevice* getDevice();
+ int duration() const;
+ static qint64 headerLength();
+
+ bool open(QIODevice::OpenMode mode) override;
+ void close() override;
+ bool seek(qint64 pos) override;
+ qint64 pos() const override;
+ void setIODevice(QIODevice *device);
+ qint64 size() const override;
+ bool isSequential() const override;
+ qint64 bytesAvailable() const override;
+
+Q_SIGNALS:
+ void formatKnown();
+ void parsingError();
+
+private Q_SLOTS:
+ void handleData();
+
+private:
+ qint64 readData(char *data, qint64 maxlen) override;
+ qint64 writeData(const char *data, qint64 len) override;
+
+ bool writeHeader();
+ bool writeDataLength();
+ bool enoughDataAvailable();
+ bool findChunk(const char *chunkId);
+ void discardBytes(qint64 numBytes);
+ void parsingFailed();
+
+ enum State {
+ InitialState,
+ WaitingForFormatState,
+ WaitingForDataState
+ };
+
+ struct chunk
+ {
+ char id[4]; // A four-character code that identifies the representation of the chunk data
+ // padded on the right with blank characters (ASCII 32)
+ quint32 size; // Does not include the size of the id or size fields or the pad byte at the end of payload
+ };
+
+ bool peekChunk(chunk* pChunk, bool handleEndianness = true);
+
+ struct RIFFHeader
+ {
+ chunk descriptor;
+ char type[4];
+ };
+ struct WAVEHeader
+ {
+ chunk descriptor;
+ quint16 audioFormat;
+ quint16 numChannels;
+ quint32 sampleRate;
+ quint32 byteRate;
+ quint16 blockAlign;
+ quint16 bitsPerSample;
+ };
+
+ struct DATAHeader
+ {
+ chunk descriptor;
+ };
+
+ struct CombinedHeader
+ {
+ RIFFHeader riff;
+ WAVEHeader wave;
+ DATAHeader data;
+ };
+ static const int HeaderLength = sizeof(CombinedHeader);
+
+ bool haveFormat = false;
+ bool haveHeader = false;
+ qint64 dataSize = 0;
+ QIODevice *device = nullptr;
+ QAudioFormat format;
+ State state = InitialState;
+ quint32 junkToSkip = 0;
+ bool bigEndian = false;
+ bool byteSwap = false;
+ int bps = 0;
+};
+
+QT_END_NAMESPACE
+
+#endif // WAVEDECODER_H
diff --git a/src/multimedia/audio/qwavedecoder_p.cpp b/src/multimedia/audio/qwavedecoder_p.cpp
deleted file mode 100644
index 7e10a0f10..000000000
--- a/src/multimedia/audio/qwavedecoder_p.cpp
+++ /dev/null
@@ -1,312 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qwavedecoder_p.h"
-
-#include <QtCore/qtimer.h>
-#include <QtCore/qendian.h>
-
-QT_BEGIN_NAMESPACE
-
-QWaveDecoder::QWaveDecoder(QIODevice *s, QObject *parent):
- QIODevice(parent),
- haveFormat(false),
- dataSize(0),
- source(s),
- state(QWaveDecoder::InitialState),
- junkToSkip(0),
- bigEndian(false)
-{
- open(QIODevice::ReadOnly | QIODevice::Unbuffered);
-
- if (enoughDataAvailable())
- QTimer::singleShot(0, this, SLOT(handleData()));
- else
- connect(source, SIGNAL(readyRead()), SLOT(handleData()));
-}
-
-QWaveDecoder::~QWaveDecoder()
-{
-}
-
-QAudioFormat QWaveDecoder::audioFormat() const
-{
- return format;
-}
-
-int QWaveDecoder::duration() const
-{
- return size() * 1000 / (format.sampleSize() / 8) / format.channelCount() / format.sampleRate();
-}
-
-qint64 QWaveDecoder::size() const
-{
- return haveFormat ? dataSize : 0;
-}
-
-bool QWaveDecoder::isSequential() const
-{
- return source->isSequential();
-}
-
-qint64 QWaveDecoder::bytesAvailable() const
-{
- return haveFormat ? source->bytesAvailable() : 0;
-}
-
-qint64 QWaveDecoder::readData(char *data, qint64 maxlen)
-{
- return haveFormat ? source->read(data, maxlen) : 0;
-}
-
-qint64 QWaveDecoder::writeData(const char *data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
-
- return -1;
-}
-
-void QWaveDecoder::parsingFailed()
-{
- Q_ASSERT(source);
- source->disconnect(SIGNAL(readyRead()), this, SLOT(handleData()));
- emit parsingError();
-}
-
-void QWaveDecoder::handleData()
-{
- // As a special "state", if we have junk to skip, we do
- if (junkToSkip > 0) {
- discardBytes(junkToSkip); // this also updates junkToSkip
-
- // If we couldn't skip all the junk, return
- if (junkToSkip > 0) {
- // We might have run out
- if (source->atEnd())
- parsingFailed();
- return;
- }
- }
-
- if (state == QWaveDecoder::InitialState) {
- if (source->bytesAvailable() < qint64(sizeof(RIFFHeader)))
- return;
-
- RIFFHeader riff;
- source->read(reinterpret_cast<char *>(&riff), sizeof(RIFFHeader));
-
- // RIFF = little endian RIFF, RIFX = big endian RIFF
- if (((qstrncmp(riff.descriptor.id, "RIFF", 4) != 0) && (qstrncmp(riff.descriptor.id, "RIFX", 4) != 0))
- || qstrncmp(riff.type, "WAVE", 4) != 0) {
- parsingFailed();
- return;
- } else {
- state = QWaveDecoder::WaitingForFormatState;
- if (qstrncmp(riff.descriptor.id, "RIFX", 4) == 0)
- bigEndian = true;
- else
- bigEndian = false;
- }
- }
-
- if (state == QWaveDecoder::WaitingForFormatState) {
- if (findChunk("fmt ")) {
- chunk descriptor;
- peekChunk(&descriptor);
-
- quint32 rawChunkSize = descriptor.size + sizeof(chunk);
- if (source->bytesAvailable() < qint64(rawChunkSize))
- return;
-
- WAVEHeader wave;
- source->read(reinterpret_cast<char *>(&wave), sizeof(WAVEHeader));
-
- if (rawChunkSize > sizeof(WAVEHeader))
- discardBytes(rawChunkSize - sizeof(WAVEHeader));
-
- // Swizzle this
- if (bigEndian) {
- wave.audioFormat = qFromBigEndian<quint16>(wave.audioFormat);
- } else {
- wave.audioFormat = qFromLittleEndian<quint16>(wave.audioFormat);
- }
-
- if (wave.audioFormat != 0 && wave.audioFormat != 1) {
- // 32bit wave files have format == 0xFFFE (WAVE_FORMAT_EXTENSIBLE).
- // but don't support them at the moment.
- parsingFailed();
- return;
- } else {
- format.setCodec(QLatin1String("audio/pcm"));
-
- if (bigEndian) {
- int bps = qFromBigEndian<quint16>(wave.bitsPerSample);
-
- format.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt);
- format.setByteOrder(QAudioFormat::BigEndian);
- format.setSampleRate(qFromBigEndian<quint32>(wave.sampleRate));
- format.setSampleSize(bps);
- format.setChannelCount(qFromBigEndian<quint16>(wave.numChannels));
- } else {
- int bps = qFromLittleEndian<quint16>(wave.bitsPerSample);
-
- format.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt);
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleRate(qFromLittleEndian<quint32>(wave.sampleRate));
- format.setSampleSize(bps);
- format.setChannelCount(qFromLittleEndian<quint16>(wave.numChannels));
- }
-
- state = QWaveDecoder::WaitingForDataState;
- }
- }
- }
-
- if (state == QWaveDecoder::WaitingForDataState) {
- if (findChunk("data")) {
- source->disconnect(SIGNAL(readyRead()), this, SLOT(handleData()));
-
- chunk descriptor;
- source->read(reinterpret_cast<char *>(&descriptor), sizeof(chunk));
- if (bigEndian)
- descriptor.size = qFromBigEndian<quint32>(descriptor.size);
- else
- descriptor.size = qFromLittleEndian<quint32>(descriptor.size);
-
- dataSize = descriptor.size;
-
- haveFormat = true;
- connect(source, SIGNAL(readyRead()), SIGNAL(readyRead()));
- emit formatKnown();
-
- return;
- }
- }
-
- // If we hit the end without finding data, it's a parsing error
- if (source->atEnd()) {
- parsingFailed();
- }
-}
-
-bool QWaveDecoder::enoughDataAvailable()
-{
- chunk descriptor;
- if (!peekChunk(&descriptor, false))
- return false;
-
- // This is only called for the RIFF/RIFX header, before bigEndian is set,
- // so we have to manually swizzle
- if (qstrncmp(descriptor.id, "RIFX", 4) == 0)
- descriptor.size = qFromBigEndian<quint32>(descriptor.size);
- if (qstrncmp(descriptor.id, "RIFF", 4) == 0)
- descriptor.size = qFromLittleEndian<quint32>(descriptor.size);
-
- if (source->bytesAvailable() < qint64(sizeof(chunk) + descriptor.size))
- return false;
-
- return true;
-}
-
-bool QWaveDecoder::findChunk(const char *chunkId)
-{
- chunk descriptor;
-
- do {
- if (!peekChunk(&descriptor))
- return false;
-
- if (qstrncmp(descriptor.id, chunkId, 4) == 0)
- return true;
-
- // It's possible that bytes->available() is less than the chunk size
- // if it's corrupt.
- junkToSkip = qint64(sizeof(chunk) + descriptor.size);
-
- // Skip the current amount
- if (junkToSkip > 0)
- discardBytes(junkToSkip);
-
- // If we still have stuff left, just exit and try again later
- // since we can't call peekChunk
- if (junkToSkip > 0)
- return false;
-
- } while (source->bytesAvailable() > 0);
-
- return false;
-}
-
-bool QWaveDecoder::peekChunk(chunk *pChunk, bool handleEndianness)
-{
- if (source->bytesAvailable() < qint64(sizeof(chunk)))
- return false;
-
- source->peek(reinterpret_cast<char *>(pChunk), sizeof(chunk));
- if (handleEndianness) {
- if (bigEndian)
- pChunk->size = qFromBigEndian<quint32>(pChunk->size);
- else
- pChunk->size = qFromLittleEndian<quint32>(pChunk->size);
- }
- return true;
-}
-
-void QWaveDecoder::discardBytes(qint64 numBytes)
-{
- // Discards a number of bytes
- // If the iodevice doesn't have this many bytes in it,
- // remember how much more junk we have to skip.
- if (source->isSequential()) {
- QByteArray r = source->read(qMin(numBytes, qint64(16384))); // uggh, wasted memory, limit to a max of 16k
- if (r.size() < numBytes)
- junkToSkip = numBytes - r.size();
- else
- junkToSkip = 0;
- } else {
- quint64 origPos = source->pos();
- source->seek(source->pos() + numBytes);
- junkToSkip = origPos + numBytes - source->pos();
- }
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qwavedecoder_p.cpp"
diff --git a/src/multimedia/audio/qwavedecoder_p.h b/src/multimedia/audio/qwavedecoder_p.h
deleted file mode 100644
index 3be0dbaa6..000000000
--- a/src/multimedia/audio/qwavedecoder_p.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef WAVEDECODER_H
-#define WAVEDECODER_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qiodevice.h>
-#include <qaudioformat.h>
-
-
-QT_BEGIN_NAMESPACE
-
-
-
-class QWaveDecoder : public QIODevice
-{
- Q_OBJECT
-
-public:
- explicit QWaveDecoder(QIODevice *source, QObject *parent = nullptr);
- ~QWaveDecoder();
-
- QAudioFormat audioFormat() const;
- int duration() const;
-
- qint64 size() const override;
- bool isSequential() const override;
- qint64 bytesAvailable() const override;
-
-Q_SIGNALS:
- void formatKnown();
- void parsingError();
-
-private Q_SLOTS:
- void handleData();
-
-private:
- qint64 readData(char *data, qint64 maxlen) override;
- qint64 writeData(const char *data, qint64 len) override;
-
- bool enoughDataAvailable();
- bool findChunk(const char *chunkId);
- void discardBytes(qint64 numBytes);
- void parsingFailed();
-
- enum State {
- InitialState,
- WaitingForFormatState,
- WaitingForDataState
- };
-
- struct chunk
- {
- char id[4];
- quint32 size;
- };
- bool peekChunk(chunk* pChunk, bool handleEndianness = true);
-
- struct RIFFHeader
- {
- chunk descriptor;
- char type[4];
- };
- struct WAVEHeader
- {
- chunk descriptor;
- quint16 audioFormat;
- quint16 numChannels;
- quint32 sampleRate;
- quint32 byteRate;
- quint16 blockAlign;
- quint16 bitsPerSample;
- };
-
- bool haveFormat;
- qint64 dataSize;
- QAudioFormat format;
- QIODevice *source;
- State state;
- quint32 junkToSkip;
- bool bigEndian;
-};
-
-QT_END_NAMESPACE
-
-#endif // WAVEDECODER_H
diff --git a/src/multimedia/camera/camera.pri b/src/multimedia/camera/camera.pri
deleted file mode 100644
index 29ed96668..000000000
--- a/src/multimedia/camera/camera.pri
+++ /dev/null
@@ -1,22 +0,0 @@
-INCLUDEPATH += camera
-
-PRIVATE_HEADERS += \
- camera/qcamera_p.h
-
-PUBLIC_HEADERS += \
- camera/qcamera.h \
- camera/qcameraimagecapture.h \
- camera/qcameraexposure.h \
- camera/qcamerafocus.h \
- camera/qcameraimageprocessing.h \
- camera/qcamerainfo.h \
- camera/qcameraviewfindersettings.h
-
-SOURCES += \
- camera/qcamera.cpp \
- camera/qcameraexposure.cpp \
- camera/qcamerafocus.cpp \
- camera/qcameraimageprocessing.cpp \
- camera/qcameraimagecapture.cpp \
- camera/qcamerainfo.cpp \
- camera/qcameraviewfindersettings.cpp
diff --git a/src/multimedia/camera/qcamera.cpp b/src/multimedia/camera/qcamera.cpp
index b4515cfad..9cfbcc01d 100644
--- a/src/multimedia/camera/qcamera.cpp
+++ b/src/multimedia/camera/qcamera.cpp
@@ -1,87 +1,21 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qcamera_p.h"
-#include "qmediaserviceprovider_p.h"
-
-#include <qcamerainfo.h>
-#include <qcameracontrol.h>
-#include <qcameralockscontrol.h>
-#include <qcameraexposurecontrol.h>
-#include <qcamerafocuscontrol.h>
-#include <qmediarecordercontrol.h>
-#include <qcameraimageprocessingcontrol.h>
-#include <qcameraimagecapturecontrol.h>
-#include <qvideodeviceselectorcontrol.h>
-#include <qcamerainfocontrol.h>
-#include <qcameraviewfindersettingscontrol.h>
+
+#include <qcameradevice.h>
+#include <private/qplatformcamera_p.h>
+#include <private/qplatformimagecapture_p.h>
+#include <private/qplatformmediaintegration_p.h>
+#include <private/qplatformmediacapture_p.h>
+#include <qmediadevices.h>
+#include <qmediacapturesession.h>
#include <QDebug>
QT_BEGIN_NAMESPACE
-static void qRegisterCameraMetaTypes()
-{
- qRegisterMetaType<QCamera::Error>("QCamera::Error");
- qRegisterMetaType<QCamera::State>("QCamera::State");
- qRegisterMetaType<QCamera::Status>("QCamera::Status");
- qRegisterMetaType<QCamera::CaptureModes>("QCamera::CaptureModes");
- qRegisterMetaType<QCamera::LockType>("QCamera::LockType");
- qRegisterMetaType<QCamera::LockStatus>("QCamera::LockStatus");
- qRegisterMetaType<QCamera::LockChangeReason>("QCamera::LockChangeReason");
- qRegisterMetaType<QCamera::Position>("QCamera::Position");
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterCameraMetaTypes)
-
-Q_DECL_CONSTEXPR static bool qt_sizeLessThan(const QSize &s1, const QSize &s2) Q_DECL_NOTHROW
-{
- return (s1.width() * s1.height()) < (s2.width() * s2.height());
-}
-
-Q_DECL_CONSTEXPR static bool qt_frameRateRangeLessThan(const QCamera::FrameRateRange &s1, const QCamera::FrameRateRange &s2) Q_DECL_NOTHROW
-{
- return qFuzzyCompare(s1.maximumFrameRate, s2.maximumFrameRate) ? (s1.minimumFrameRate < s2.minimumFrameRate)
- : (s1.maximumFrameRate < s2.maximumFrameRate);
-}
-
/*!
\class QCamera
@@ -92,301 +26,173 @@ Q_DECL_CONSTEXPR static bool qt_frameRateRangeLessThan(const QCamera::FrameRateR
\ingroup multimedia
\ingroup multimedia_camera
- QCamera can be used with QCameraViewfinder for viewfinder display,
- QMediaRecorder for video recording and QCameraImageCapture for image taking.
+ QCamera can be used within a QMediaCaptureSession for video recording and image taking.
- You can use QCameraInfo to list available cameras and choose which one to use.
+ You can use QCameraDevice to list available cameras and choose which one to use.
\snippet multimedia-snippets/camera.cpp Camera selection
- See the \l{Camera Overview}{camera overview} for more information.
-*/
-
-void QCameraPrivate::_q_error(int error, const QString &errorString)
-{
- Q_Q(QCamera);
+ On hardware that supports it, QCamera lets you adjust the focus
+ and zoom. This also includes functionality such as a
+ "Macro" mode for close up work (e.g. reading barcodes, or
+ recognizing letters), or "touch to focus" - indicating an
+ interesting area of the image for the hardware to attempt
+ to focus on.
- this->error = QCamera::Error(error);
- this->errorString = errorString;
+ \snippet multimedia-snippets/camera.cpp Camera custom focus
- emit q->errorOccurred(this->error);
-}
+ The \l minimumZoomFactor() and \l maximumZoomFactor() methods provide the
+ range of supported zoom factors. The \l zoomTo() method allows changing
+ the zoom factor.
-void QCameraPrivate::setState(QCamera::State newState)
-{
- unsetError();
-
- if (!control) {
- _q_error(QCamera::ServiceMissingError, QCamera::tr("The camera service is missing"));
- return;
- }
+ \snippet multimedia-snippets/camera.cpp Camera zoom
- restartPending = false;
- control->setState(newState);
-}
-void QCameraPrivate::_q_updateState(QCamera::State newState)
-{
- Q_Q(QCamera);
+ After capturing the raw data for a camera frame, the camera hardware and
+ software performs various image processing tasks to produce the final
+ image. This includes compensating for ambient light color, reducing
+ noise, as well as making some other adjustments to the image.
- //omit changins state to Loaded when the camera is temporarily
- //stopped to apply shanges
- if (restartPending)
- return;
+ You can control many of these processing steps through the Camera properties.
+ For example, you can set the white balance (or color temperature) used
+ for processing images:
- if (newState != state) {
- state = newState;
- emit q->stateChanged(state);
- }
-}
+ \snippet multimedia-snippets/camera.cpp Camera image whitebalance
-void QCameraPrivate::_q_preparePropertyChange(int changeType)
-{
- if (!control)
- return;
+ For more information on image processing of camera frames, see
+ \l {camera_image_processing}{Camera Image Processing}.
- QCamera::Status status = control->status();
+ See the \l{Camera Overview}{camera overview} for more information.
+*/
- //all the changes are allowed until the camera is starting
- if (control->state() != QCamera::ActiveState)
- return;
+/*!
+ \qmltype Camera
+ \instantiates QCamera
+ \inqmlmodule QtMultimedia
+ \brief An interface for camera settings related to focus and zoom.
+ \ingroup multimedia_qml
+ \ingroup camera_qml
- if (control->canChangeProperty(QCameraControl::PropertyChangeType(changeType), status))
- return;
+ The Camera element can be used within a \l CaptureSession for video recording
+ and image taking.
- restartPending = true;
- control->setState(QCamera::LoadedState);
- QMetaObject::invokeMethod(q_ptr, "_q_restartCamera", Qt::QueuedConnection);
-}
+ You can use \l MediaDevices to list available cameras and choose which one to use.
-void QCameraPrivate::_q_restartCamera()
-{
- if (restartPending) {
- restartPending = false;
- control->setState(QCamera::ActiveState);
+ \qml
+ MediaDevices {
+ id: mediaDevices
}
-}
-
-void QCameraPrivate::init()
-{
- Q_Q(QCamera);
- provider = QMediaServiceProvider::defaultServiceProvider();
- initControls();
- cameraExposure = new QCameraExposure(q);
- cameraFocus = new QCameraFocus(q);
- imageProcessing = new QCameraImageProcessing(q);
-}
-
-void QCameraPrivate::initControls()
-{
- Q_Q(QCamera);
-
- if (service) {
- control = qobject_cast<QCameraControl *>(service->requestControl(QCameraControl_iid));
- locksControl = qobject_cast<QCameraLocksControl *>(service->requestControl(QCameraLocksControl_iid));
- deviceControl = qobject_cast<QVideoDeviceSelectorControl*>(service->requestControl(QVideoDeviceSelectorControl_iid));
- infoControl = qobject_cast<QCameraInfoControl*>(service->requestControl(QCameraInfoControl_iid));
- viewfinderSettingsControl2 = qobject_cast<QCameraViewfinderSettingsControl2*>(service->requestControl(QCameraViewfinderSettingsControl2_iid));
- if (!viewfinderSettingsControl2)
- viewfinderSettingsControl = qobject_cast<QCameraViewfinderSettingsControl*>(service->requestControl(QCameraViewfinderSettingsControl_iid));
-
- if (control) {
- q->connect(control, SIGNAL(stateChanged(QCamera::State)), q, SLOT(_q_updateState(QCamera::State)));
- q->connect(control, SIGNAL(statusChanged(QCamera::Status)), q, SIGNAL(statusChanged(QCamera::Status)));
- q->connect(control, SIGNAL(captureModeChanged(QCamera::CaptureModes)),
- q, SIGNAL(captureModeChanged(QCamera::CaptureModes)));
- q->connect(control, SIGNAL(error(int,QString)), q, SLOT(_q_error(int,QString)));
-
+ CaptureSession {
+ camera: Camera {
+ cameraDevice: mediaDevices.defaultVideoInput
}
-
- if (locksControl) {
- q->connect(locksControl, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus,QCamera::LockChangeReason)),
- q, SLOT(_q_updateLockStatus(QCamera::LockType,QCamera::LockStatus,QCamera::LockChangeReason)));
- }
-
- error = QCamera::NoError;
- } else {
- control = nullptr;
- locksControl = nullptr;
- deviceControl = nullptr;
- infoControl = nullptr;
- viewfinderSettingsControl = nullptr;
- viewfinderSettingsControl2 = nullptr;
-
- error = QCamera::ServiceMissingError;
- errorString = QCamera::tr("The camera service is missing");
}
-}
+ \endqml
-void QCameraPrivate::clear()
-{
- delete cameraExposure;
- delete cameraFocus;
- delete imageProcessing;
-
- if (service) {
- if (control)
- service->releaseControl(control);
- if (locksControl)
- service->releaseControl(locksControl);
- if (deviceControl)
- service->releaseControl(deviceControl);
- if (infoControl)
- service->releaseControl(infoControl);
- if (viewfinderSettingsControl)
- service->releaseControl(viewfinderSettingsControl);
- if (viewfinderSettingsControl2)
- service->releaseControl(viewfinderSettingsControl2);
-
- provider->releaseService(service);
- }
+ On hardware that supports it, QCamera lets you adjust the focus
+ and zoom. This also includes functionality such as a
+ "Macro" mode for close up work (e.g. reading barcodes, or
+ recognizing letters), or "touch to focus" - indicating an
+ interesting area of the image for the hardware to attempt
+ to focus on.
- cameraExposure = nullptr;
- cameraFocus = nullptr;
- imageProcessing = nullptr;
- control = nullptr;
- locksControl = nullptr;
- deviceControl = nullptr;
- infoControl = nullptr;
- viewfinderSettingsControl = nullptr;
- viewfinderSettingsControl2 = nullptr;
- service = nullptr;
-}
+ \qml
-void QCameraPrivate::updateLockStatus()
-{
- Q_Q(QCamera);
+ Item {
+ width: 640
+ height: 360
- QCamera::LockStatus oldStatus = lockStatus;
+ CaptureSession {
+ camera: Camera {
+ id: camera
- QMap<QCamera::LockStatus, int> lockStatusPriority;
- lockStatusPriority.insert(QCamera::Locked, 1);
- lockStatusPriority.insert(QCamera::Unlocked, 2);
- lockStatusPriority.insert(QCamera::Searching, 3);
+ focusMode: Camera.FocusModeAutoNear
+ customFocusPoint: Qt.point(0.2, 0.2) // Focus relative to top-left corner
+ }
+ videoOutput: videoOutput
+ }
- lockStatus = requestedLocks ? QCamera::Locked : QCamera::Unlocked;
- int priority = 0;
+ VideoOutput {
+ id: videoOutput
+ anchors.fill: parent
+ }
+ }
- QList<QCamera::LockStatus> lockStatuses;
+ \endqml
- if (requestedLocks & QCamera::LockFocus)
- lockStatuses << q->lockStatus(QCamera::LockFocus);
+ The \l minimumZoomFactor and \l maximumZoomFactor properties provide the
+ range of supported zoom factors. The \l zoomFactor property allows changing
+ the zoom factor.
- if (requestedLocks & QCamera::LockExposure)
- lockStatuses << q->lockStatus(QCamera::LockExposure);
+ \qml
+ Camera {
+ zoomFactor: maximumZoomFactor // zoom in as much as possible
+ }
+ \endqml
- if (requestedLocks & QCamera::LockWhiteBalance)
- lockStatuses << q->lockStatus(QCamera::LockWhiteBalance);
+ After capturing the raw data for a camera frame, the camera hardware and
+ software performs various image processing tasks to produce the final
+ image. This includes compensating for ambient light color, reducing
+ noise, as well as making some other adjustments to the image.
+ You can control many of these processing steps through the Camera properties.
+ For example, you can set the white balance (or color temperature) used
+ for processing images:
- for (QCamera::LockStatus currentStatus : qAsConst(lockStatuses)) {
- int currentPriority = lockStatusPriority.value(currentStatus, -1);
- if (currentPriority > priority) {
- priority = currentPriority;
- lockStatus = currentStatus;
- }
+ \qml
+ Camera {
+ whiteBalanceMode: Camera.WhiteBalanceManual
+ colorTemperature: 5600
}
+ \endqml
- if (!supressLockChangedSignal && oldStatus != lockStatus) {
- emit q->lockStatusChanged(lockStatus, lockChangeReason);
+ For more information on image processing of camera frames, see
+ \l {camera_image_processing}{Camera Image Processing}.
- if (lockStatus == QCamera::Locked)
- emit q->locked();
- else if (lockStatus == QCamera::Unlocked && lockChangeReason == QCamera::LockFailed)
- emit q->lockFailed();
- }
-/*
- qDebug() << "Requested locks:" << (requestedLocks & QCamera::LockExposure ? 'e' : ' ')
- << (requestedLocks & QCamera::LockFocus ? 'f' : ' ')
- << (requestedLocks & QCamera::LockWhiteBalance ? 'w' : ' ');
- qDebug() << "Lock status: f:" << q->lockStatus(QCamera::LockFocus)
- << " e:" << q->lockStatus(QCamera::LockExposure)
- << " w:" << q->lockStatus(QCamera::LockWhiteBalance)
- << " composite:" << lockStatus;
+ See the \l{Camera Overview}{camera overview} for more information.
*/
-}
-void QCameraPrivate::_q_updateLockStatus(QCamera::LockType type, QCamera::LockStatus status, QCamera::LockChangeReason reason)
+void QCameraPrivate::init(const QCameraDevice &device)
{
Q_Q(QCamera);
- lockChangeReason = reason;
- updateLockStatus();
- emit q->lockStatusChanged(type, status, reason);
-}
-
-
-/*!
- Construct a QCamera with a \a parent.
-*/
-
-QCamera::QCamera(QObject *parent):
- QMediaObject(*new QCameraPrivate,
- parent,
- QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA))
-{
- Q_D(QCamera);
- d->init();
- // Select the default camera
- if (d->service != nullptr && d->deviceControl)
- d->deviceControl->setSelectedDevice(d->deviceControl->defaultDevice());
+ auto maybeControl = QPlatformMediaIntegration::instance()->createCamera(q);
+ if (!maybeControl) {
+ qWarning() << "Failed to initialize QCamera" << maybeControl.error();
+ return;
+ }
+ control = maybeControl.value();
+ cameraDevice = !device.isNull() ? device : QMediaDevices::defaultVideoInput();
+ if (cameraDevice.isNull())
+ control->updateError(QCamera::CameraError, QStringLiteral("No camera detected"));
+ control->setCamera(cameraDevice);
+ q->connect(control, &QPlatformVideoSource::activeChanged, q, &QCamera::activeChanged);
+ q->connect(control, &QPlatformCamera::errorChanged, q, &QCamera::errorChanged);
+ q->connect(control, &QPlatformCamera::errorOccurred, q, &QCamera::errorOccurred);
}
/*!
- Construct a QCamera from \a deviceName and \a parent.
+ Construct a QCamera with a \a parent.
- If no camera with that \a deviceName exists, the camera object will
- be invalid.
+ Selects the default camera on the system if more than one camera is available.
*/
-QCamera::QCamera(const QByteArray& deviceName, QObject *parent):
- QMediaObject(*new QCameraPrivate, parent,
- QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA,
- QMediaServiceProviderHint(deviceName)))
+QCamera::QCamera(QObject *parent)
+ : QCamera(QMediaDevices::defaultVideoInput(), parent)
{
- Q_D(QCamera);
- d->init();
-
- bool found = false;
- // Pass device name to service.
- if (d->deviceControl) {
- const QString name = QString::fromLatin1(deviceName);
- for (int i = 0; i < d->deviceControl->deviceCount(); i++) {
- if (d->deviceControl->deviceName(i) == name) {
- d->deviceControl->setSelectedDevice(i);
- found = true;
- break;
- }
- }
- }
-
- // The camera should not be used if device with requested name does not exist.
- if (!found) {
- if (d->service) {
- if (d->control)
- d->service->releaseControl(d->control);
- if (d->deviceControl)
- d->service->releaseControl(d->deviceControl);
- if (d->infoControl)
- d->service->releaseControl(d->infoControl);
- }
- d->control = nullptr;
- d->deviceControl = nullptr;
- d->infoControl = nullptr;
- d->error = QCamera::ServiceMissingError;
- d->errorString = QCamera::tr("The camera service is missing");
- }
}
/*!
\since 5.3
- Construct a QCamera from a camera description \a cameraInfo and \a parent.
+ Construct a QCamera from a camera description \a cameraDevice and \a parent.
*/
-QCamera::QCamera(const QCameraInfo &cameraInfo, QObject *parent)
- : QCamera(cameraInfo.deviceName().toLatin1(), parent)
+QCamera::QCamera(const QCameraDevice &cameraDevice, QObject *parent)
+ : QObject(*new QCameraPrivate, parent)
{
+ Q_D(QCamera);
+ d->init(cameraDevice);
}
/*!
@@ -398,33 +204,23 @@ QCamera::QCamera(const QCameraInfo &cameraInfo, QObject *parent)
back-facing cameras.
If no camera is available at the specified \a position or if \a position is
- QCamera::UnspecifiedPosition, the default camera is used.
+ QCameraDevice::UnspecifiedPosition, the default camera is used.
*/
-QCamera::QCamera(QCamera::Position position, QObject *parent)
- : QMediaObject(*new QCameraPrivate,
- parent,
- QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA, QMediaServiceProviderHint(position)))
+QCamera::QCamera(QCameraDevice::Position position, QObject *parent)
+ : QObject(*new QCameraPrivate, parent)
{
Q_D(QCamera);
- d->init();
-
- if (d->service != nullptr && d->deviceControl) {
- bool selectDefault = true;
-
- if (d->infoControl && position != UnspecifiedPosition) {
- for (int i = 0; i < d->deviceControl->deviceCount(); i++) {
- if (d->infoControl->cameraPosition(d->deviceControl->deviceName(i)) == position) {
- d->deviceControl->setSelectedDevice(i);
- selectDefault = false;
- break;
- }
- }
- }
- if (selectDefault)
- d->deviceControl->setSelectedDevice(d->deviceControl->defaultDevice());
+ QCameraDevice device;
+ auto cameras = QMediaDevices::videoInputs();
+ for (const auto &c : cameras) {
+ if (c.position() == position) {
+ device = c;
+ break;
+ }
}
+ d->init(device);
}
/*!
@@ -434,873 +230,1128 @@ QCamera::QCamera(QCamera::Position position, QObject *parent)
QCamera::~QCamera()
{
Q_D(QCamera);
- d->clear();
+ if (d->captureSession)
+ d->captureSession->setCamera(nullptr);
}
/*!
- Returns the availability state of the camera service.
+ Returns true if the camera can be used.
*/
-QMultimedia::AvailabilityStatus QCamera::availability() const
+bool QCamera::isAvailable() const
{
Q_D(const QCamera);
- if (d->control == nullptr)
- return QMultimedia::ServiceMissing;
+ return d->control && !d->cameraDevice.isNull();
+}
- if (d->deviceControl && d->deviceControl->deviceCount() == 0)
- return QMultimedia::ResourceError;
+/*! \qmlproperty bool QtMultimedia::Camera::active
- if (d->error != QCamera::NoError)
- return QMultimedia::ResourceError;
+ Describes whether the camera is currently active.
+*/
- return QMediaObject::availability();
-}
+/*! \property QCamera::active
+ Describes whether the camera is currently active.
+*/
/*!
- Returns the camera exposure control object.
+ Returns true if the camera is currently active.
*/
-QCameraExposure *QCamera::exposure() const
+bool QCamera::isActive() const
{
- return d_func()->cameraExposure;
+ Q_D(const QCamera);
+ return d->control && d->control->isActive();
}
/*!
- Returns the camera focus control object.
+ Turns the camera on if \a active is \c{true}, or off if it's \c{false}.
*/
-QCameraFocus *QCamera::focus() const
+void QCamera::setActive(bool active)
{
- return d_func()->cameraFocus;
+ Q_D(const QCamera);
+ if (d->control)
+ d->control->setActive(active);
}
/*!
- Returns the camera image processing control object.
+ \qmlproperty enumeration QtMultimedia::Camera::error
+
+ Returns the error state of the camera.
+
+ \sa QCamera::Error
*/
-QCameraImageProcessing *QCamera::imageProcessing() const
+
+/*!
+ \property QCamera::error
+
+ Returns the error state of the camera.
+*/
+
+QCamera::Error QCamera::error() const
{
- return d_func()->imageProcessing;
+ Q_D(const QCamera);
+
+ return d->control ? d->control->error() : QCamera::CameraError;
}
/*!
- Sets the QVideoWidget based camera \a viewfinder.
- The previously set viewfinder is detached.
+ \qmlproperty string QtMultimedia::Camera::errorString
- //! QVideoWidget is forward declared.
+ Returns a human readable string describing a camera's error state.
*/
-void QCamera::setViewfinder(QVideoWidget *viewfinder)
-{
- Q_D(QCamera);
- d->_q_preparePropertyChange(QCameraControl::Viewfinder);
- if (d->viewfinder)
- unbind(d->viewfinder);
+/*!
+ \property QCamera::errorString
- // We don't know (in this library) that QVideoWidget inherits QObject
- QObject *viewFinderObject = reinterpret_cast<QObject*>(viewfinder);
+ Returns a human readable string describing a camera's error state.
+*/
+QString QCamera::errorString() const
+{
+ Q_D(const QCamera);
- d->viewfinder = viewFinderObject && bind(viewFinderObject) ? viewFinderObject : nullptr;
+ return d->control ? d->control->errorString()
+ : QStringLiteral("Camera is not supported on the platform");
}
+/*! \enum QCamera::Feature
+
+ Describes a set of features supported by the camera. The returned value can be a
+ combination of:
+
+ \value ColorTemperature
+ The Camera supports setting a custom \l{colorTemperature}.
+ \value ExposureCompensation
+ The Camera supports setting a custom \l{exposureCompensation}.
+ \value IsoSensitivity
+ The Camera supports setting a custom \l{isoSensitivity}.
+ \value ManualExposureTime
+ The Camera supports setting a \l{QCamera::manualExposureTime}{manual exposure Time}.
+ \value CustomFocusPoint
+ The Camera supports setting a \l{QCamera::customFocusPoint}{custom focus point}.
+ \value FocusDistance
+ The Camera supports setting the \l{focusDistance} property.
+*/
+
/*!
- Sets the QGraphicsVideoItem based camera \a viewfinder.
- The previously set viewfinder is detached.
+ \qmlproperty Features QtMultimedia::Camera::supportedFeatures
+ Returns the features supported by this camera.
- //! QGraphicsVideoItem is forward declared.
+ \sa QCamera::Feature
*/
-void QCamera::setViewfinder(QGraphicsVideoItem *viewfinder)
-{
- Q_D(QCamera);
- d->_q_preparePropertyChange(QCameraControl::Viewfinder);
- if (d->viewfinder)
- unbind(d->viewfinder);
+/*!
+ \property QCamera::supportedFeatures
- // We don't know (in this library) that QGraphicsVideoItem (multiply) inherits QObject
- // but QObject inheritance depends on QObject coming first, so try this out.
- QObject *viewFinderObject = reinterpret_cast<QObject*>(viewfinder);
+ Returns the features supported by this camera.
- d->viewfinder = viewFinderObject && bind(viewFinderObject) ? viewFinderObject : nullptr;
+ \sa QCamera::Feature
+*/
+QCamera::Features QCamera::supportedFeatures() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->supportedFeatures() : QCamera::Features{};
}
-/*!
- Sets a video \a surface as the viewfinder of a camera.
+/*! \qmlmethod void Camera::start()
+
+ Starts the camera.
- If a viewfinder has already been set on the camera the new surface
- will replace it.
+ Same as setting the active property to true.
+
+ If the camera can't be started for some reason, the errorOccurred() signal is emitted.
*/
-void QCamera::setViewfinder(QAbstractVideoSurface *surface)
-{
- Q_D(QCamera);
+/*! \fn void QCamera::start()
- d->surfaceViewfinder.setVideoSurface(surface);
+ Starts the camera.
- if (d->viewfinder != &d->surfaceViewfinder) {
- if (d->viewfinder)
- unbind(d->viewfinder);
+ Same as setActive(true).
- d->viewfinder = nullptr;
+ If the camera can't be started for some reason, the errorOccurred() signal is emitted.
+*/
- if (surface && bind(&d->surfaceViewfinder))
- d->viewfinder = &d->surfaceViewfinder;
- } else if (!surface) {
- //unbind the surfaceViewfinder if null surface is set
- unbind(&d->surfaceViewfinder);
- d->viewfinder = nullptr;
- }
-}
+/*! \qmlmethod void Camera::stop()
-/*!
- Returns the viewfinder settings being used by the camera.
+ Stops the camera.
+ Same as setting the active property to false.
+*/
- Settings may change when the camera is started, for example if the viewfinder settings
- are undefined or if unsupported values are set.
+/*! \fn void QCamera::stop()
- If viewfinder settings are not supported by the camera, it always returns a null
- QCameraViewfinderSettings object.
+ Stops the camera.
+ Same as setActive(false).
+*/
- \sa setViewfinderSettings()
+/*!
+ Returns the capture session this camera is connected to, or
+ a nullptr if the camera is not connected to a capture session.
- \since 5.5
+ use QMediaCaptureSession::setCamera() to connect the camera to
+ a session.
*/
-QCameraViewfinderSettings QCamera::viewfinderSettings() const
+QMediaCaptureSession *QCamera::captureSession() const
{
Q_D(const QCamera);
+ return d->captureSession;
+}
- if (d->viewfinderSettingsControl2)
- return d->viewfinderSettingsControl2->viewfinderSettings();
+/*!
+ \internal
+*/
+void QCamera::setCaptureSession(QMediaCaptureSession *session)
+{
+ Q_D(QCamera);
+ d->captureSession = session;
+}
- QCameraViewfinderSettings settings;
- if (d->viewfinderSettingsControl) {
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::Resolution))
- settings.setResolution(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::Resolution).toSize());
+/*!
+ \internal
+*/
+QPlatformCamera *QCamera::platformCamera()
+{
+ Q_D(const QCamera);
+ return d->control;
+}
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MinimumFrameRate))
- settings.setMinimumFrameRate(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::MinimumFrameRate).toReal());
+/*! \qmlproperty cameraDevice QtMultimedia::Camera::cameraDevice
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MaximumFrameRate))
- settings.setMaximumFrameRate(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::MaximumFrameRate).toReal());
+ Gets or sets the currently active camera device.
+*/
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelAspectRatio))
- settings.setPixelAspectRatio(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::PixelAspectRatio).toSize());
+/*!
+ \property QCamera::cameraDevice
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelFormat))
- settings.setPixelFormat(qvariant_cast<QVideoFrame::PixelFormat>(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::PixelFormat)));
- }
- return settings;
+ Returns the QCameraDevice object associated with this camera.
+ */
+QCameraDevice QCamera::cameraDevice() const
+{
+ Q_D(const QCamera);
+ return d->cameraDevice;
}
/*!
- Sets the viewfinder \a settings.
+ Connects the camera object to the physical camera device described by
+ \a cameraDevice. Using a default constructed QCameraDevice object as
+ \a cameraDevice will connect the camera to the system default camera device.
+*/
+void QCamera::setCameraDevice(const QCameraDevice &cameraDevice)
+{
+ Q_D(QCamera);
+ auto dev = cameraDevice;
+ if (dev.isNull())
+ dev = QMediaDevices::defaultVideoInput();
+ if (d->cameraDevice == dev)
+ return;
+ d->cameraDevice = dev;
+ if (d->control)
+ d->control->setCamera(d->cameraDevice);
+ emit cameraDeviceChanged();
+ setCameraFormat({});
+}
+
+/*! \qmlproperty cameraFormat QtMultimedia::Camera::cameraFormat
+
+ Gets or sets the currently active camera format.
+
+ \note When using the FFMPEG backend on an Android target device if you request
+ \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
+ semi-planar NV12/NV21. This depends on the codec implemented by the device
+ OEM.
- If some parameters are not specified, or null settings are passed, the camera will choose
- default values.
+ \sa cameraDevice::videoFormats
+*/
- If the camera is used to capture videos or images, the viewfinder settings might be
- ignored if they conflict with the capture settings. You can check the actual viewfinder settings
- once the camera is in the \c QCamera::ActiveStatus status.
+/*!
+ \property QCamera::cameraFormat
- Changing the viewfinder settings while the camera is in the QCamera::ActiveState state may
- cause the camera to be restarted.
+ Returns the camera format currently used by the camera.
- \sa viewfinderSettings(), supportedViewfinderResolutions(), supportedViewfinderFrameRateRanges(),
- supportedViewfinderPixelFormats()
+ \note When using the FFMPEG backend on an Android target device if you request
+ \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
+ semi-planar NV12/NV21. This depends on the codec implemented by the device
+ OEM.
- \since 5.5
+ \sa QCameraDevice::videoFormats
*/
-void QCamera::setViewfinderSettings(const QCameraViewfinderSettings &settings)
+QCameraFormat QCamera::cameraFormat() const
+{
+ Q_D(const QCamera);
+ return d->cameraFormat;
+}
+
+/*!
+ Tells the camera to use the format described by \a format. This can be used to define
+ a specific resolution and frame rate to be used for recording and image capture.
+
+ \note When using the FFMPEG backend on an Android target device if you request
+ \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
+ semi-planar NV12/NV21. This depends on the codec implemented by the device
+ OEM.
+*/
+void QCamera::setCameraFormat(const QCameraFormat &format)
{
Q_D(QCamera);
+ if (!d->control || !d->control->setCameraFormat(format))
+ return;
- if (d->viewfinderSettingsControl || d->viewfinderSettingsControl2)
- d->_q_preparePropertyChange(QCameraControl::ViewfinderSettings);
+ d->cameraFormat = format;
+ emit cameraFormatChanged();
+}
- if (d->viewfinderSettingsControl2) {
- d->viewfinderSettingsControl2->setViewfinderSettings(settings);
+/*!
+ \enum QCamera::Error
- } else if (d->viewfinderSettingsControl) {
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::Resolution))
- d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::Resolution, settings.resolution());
+ This enum holds the last error code.
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MinimumFrameRate))
- d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::MinimumFrameRate, settings.minimumFrameRate());
+ \value NoError No errors have occurred.
+ \value CameraError An error has occurred.
+*/
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MaximumFrameRate))
- d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::MaximumFrameRate, settings.maximumFrameRate());
+/*!
+ \qmlsignal void Camera::errorOccurred(Camera::Error error, string errorString)
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelAspectRatio))
- d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::PixelAspectRatio, settings.pixelAspectRatio());
+ This signal is emitted when error state changes to \a error. A description
+ of the error is provided as \a errorString.
+*/
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelFormat))
- d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::PixelFormat, settings.pixelFormat());
- }
-}
+/*!
+ \fn void QCamera::errorOccurred(QCamera::Error error, const QString &errorString)
+
+ This signal is emitted when error state changes to \a error. A description
+ of the error is provided as \a errorString.
+*/
/*!
- Returns a list of supported viewfinder settings.
+ \qmlproperty enumeration Camera::focusMode
+
+ This property holds the current camera focus mode.
- The list is ordered by preference; preferred settings come first.
+ \note In automatic focusing modes and where supported, the \l focusPoint property provides
+ information and control over the area of the image that is being focused.
- The optional \a settings argument can be used to conveniently filter the results.
- If \a settings is non null, the returned list is reduced to settings matching the given partial
- \a settings.
+ \value Camera.FocusModeAuto Continuous auto focus mode.
+ \value Camera.FocusModeAutoNear Continuous auto focus, preferring objects near to
+ the camera.
+ \value Camera.FocusModeAutoFar Continuous auto focus, preferring objects far away
+ from the camera.
+ \value Camera.FocusModeHyperfocal Focus to hyperfocal distance, with the maximum
+ depth of field achieved. All objects at distances from half of this
+ distance out to infinity will be acceptably sharp.
+ \value Camera.FocusModeInfinity Focus strictly to infinity.
+ \value Camera.FocusModeManual Manual or fixed focus mode.
+
+ If a certain focus mode is not supported, setting it will have no effect.
+
+ \sa isFocusModeSupported
+*/
- The status of the camera must be LoadedStatus before calling this function, otherwise the returned list
- is empty.
+/*!
+ \property QCamera::focusMode
+ \brief the current camera focus mode.
- \sa setViewfinderSettings(), supportedViewfinderResolutions(), supportedViewfinderFrameRateRanges(),
- supportedViewfinderPixelFormats()
+ Sets up different focus modes for the camera. All auto focus modes will focus continuously.
+ Locking the focus is possible by setting the focus mode to \l FocusModeManual. This will keep
+ the current focus and stop any automatic focusing.
- \since 5.5
+ \sa isFocusModeSupported
*/
-QList<QCameraViewfinderSettings> QCamera::supportedViewfinderSettings(const QCameraViewfinderSettings &settings) const
+QCamera::FocusMode QCamera::focusMode() const
{
Q_D(const QCamera);
+ return d->control ? d->control->focusMode() : QCamera::FocusModeAuto;
+}
- if (!d->viewfinderSettingsControl2)
- return QList<QCameraViewfinderSettings>();
-
- if (settings.isNull())
- return d->viewfinderSettingsControl2->supportedViewfinderSettings();
-
- QList<QCameraViewfinderSettings> results;
- const QList<QCameraViewfinderSettings> supported = d->viewfinderSettingsControl2->supportedViewfinderSettings();
- for (const QCameraViewfinderSettings &s : supported) {
- if ((settings.resolution().isEmpty() || settings.resolution() == s.resolution())
- && (qFuzzyIsNull(settings.minimumFrameRate()) || qFuzzyCompare((float)settings.minimumFrameRate(), (float)s.minimumFrameRate()))
- && (qFuzzyIsNull(settings.maximumFrameRate()) || qFuzzyCompare((float)settings.maximumFrameRate(), (float)s.maximumFrameRate()))
- && (settings.pixelFormat() == QVideoFrame::Format_Invalid || settings.pixelFormat() == s.pixelFormat())
- && (settings.pixelAspectRatio().isEmpty() || settings.pixelAspectRatio() == s.pixelAspectRatio())) {
- results.append(s);
- }
- }
+/*!
+ \fn void QCamera::focusModeChanged()
- return results;
+ Signals when the focusMode changes.
+*/
+void QCamera::setFocusMode(QCamera::FocusMode mode)
+{
+ Q_D(QCamera);
+ if (!d->control || d->control->focusMode() == mode)
+ return;
+ d->control->setFocusMode(mode);
+ emit focusModeChanged();
}
/*!
- Returns a list of supported viewfinder resolutions.
+ \qmlmethod bool Camera::isFocusModeSupported(FocusMode mode)
- This is a convenience function which retrieves unique resolutions from the supported settings.
+ Returns true if the focus \a mode is supported by the camera.
+*/
- If non null viewfinder \a settings are passed, the returned list is reduced to resolutions
- supported with partial \a settings applied.
+/*!
+ Returns true if the focus \a mode is supported by the camera.
+*/
+bool QCamera::isFocusModeSupported(FocusMode mode) const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->isFocusModeSupported(mode) : false;
+}
- The camera must be loaded before calling this function, otherwise the returned list
- is empty.
+/*!
+ \qmlproperty point QtMultimedia::Camera::focusPoint
+ Returns the point currently used by the auto focus system to focus onto.
+*/
- \sa QCameraViewfinderSettings::resolution(), setViewfinderSettings()
+/*!
+ \property QCamera::focusPoint
- \since 5.5
-*/
-QList<QSize> QCamera::supportedViewfinderResolutions(const QCameraViewfinderSettings &settings) const
+ Returns the point currently used by the auto focus system to focus onto.
+ */
+QPointF QCamera::focusPoint() const
{
- QList<QSize> resolutions;
- const QList<QCameraViewfinderSettings> capabilities = supportedViewfinderSettings(settings);
- for (const QCameraViewfinderSettings &s : capabilities) {
- if (!resolutions.contains(s.resolution()))
- resolutions.append(s.resolution());
- }
- std::sort(resolutions.begin(), resolutions.end(), qt_sizeLessThan);
+ Q_D(const QCamera);
+ return d->control ? d->control->focusPoint() : QPointF(-1., -1.);
- return resolutions;
}
/*!
- Returns a list of supported viewfinder frame rate ranges.
+ \qmlproperty point QtMultimedia::Camera::customFocusPoint
+
+ This property holds the position of custom focus point, in relative frame
+ coordinates. This means that QPointF(0,0) points to the top-left corner
+ of the frame, and QPointF(0.5,0.5) points to the center of the frame.
- This is a convenience function which retrieves unique frame rate ranges from the supported settings.
+ Custom focus point is used only in \c FocusPointCustom focus mode.
- If non null viewfinder \a settings are passed, the returned list is reduced to frame rate ranges
- supported with partial \a settings applied.
+ You can check whether custom focus points are supported by querying
+ supportedFeatures() with the Feature.CustomFocusPoint flag.
+*/
- The camera must be loaded before calling this function, otherwise the returned list
- is empty.
+/*!
+ \property QCamera::customFocusPoint
- \sa QCameraViewfinderSettings::minimumFrameRate(), QCameraViewfinderSettings::maximumFrameRate(),
- setViewfinderSettings()
+ This property represents the position of the custom focus point, in relative frame coordinates:
+ QPointF(0,0) points to the left top frame point, QPointF(0.5,0.5) points to the frame center.
- \since 5.5
+ The custom focus point property is used only in \c FocusPointCustom focus mode.
+
+ You can check whether custom focus points are supported by querying
+ supportedFeatures() with the Feature.CustomFocusPoint flag.
*/
-QList<QCamera::FrameRateRange> QCamera::supportedViewfinderFrameRateRanges(const QCameraViewfinderSettings &settings) const
+QPointF QCamera::customFocusPoint() const
{
- QList<QCamera::FrameRateRange> frameRateRanges;
- const QList<QCameraViewfinderSettings> capabilities = supportedViewfinderSettings(settings);
- for (const QCameraViewfinderSettings &s : capabilities) {
- QCamera::FrameRateRange range(s.minimumFrameRate(), s.maximumFrameRate());
- if (!frameRateRanges.contains(range))
- frameRateRanges.append(range);
- }
- std::sort(frameRateRanges.begin(), frameRateRanges.end(), qt_frameRateRangeLessThan);
+ Q_D(const QCamera);
+ return d->control ? d->control->customFocusPoint() : QPointF{-1., -1.};
+}
- return frameRateRanges;
+void QCamera::setCustomFocusPoint(const QPointF &point)
+{
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setCustomFocusPoint(point);
}
/*!
- Returns a list of supported viewfinder pixel formats.
+ \qmlproperty float QtMultimedia::Camera::focusDistance
- This is a convenience function which retrieves unique pixel formats from the supported settings.
+ This property return an approximate focus distance of the camera. The value reported
+ is between 0 and 1, 0 being the closest possible focus distance, 1 being as far away
+ as possible. Note that 1 is often, but not always infinity.
- If non null viewfinder \a settings are passed, the returned list is reduced to pixel formats
- supported with partial \a settings applied.
+ Setting the focus distance will be ignored unless the focus mode is set to
+ \l {focusMode}{FocusModeManual}.
+*/
- The camera must be loaded before calling this function, otherwise the returned list
- is empty.
+/*!
+ \property QCamera::focusDistance
- \sa QCameraViewfinderSettings::pixelFormat(), setViewfinderSettings()
+ This property return an approximate focus distance of the camera. The value reported
+ is between 0 and 1, 0 being the closest possible focus distance, 1 being as far away
+ as possible. Note that 1 is often, but not always infinity.
- \since 5.5
+ Setting the focus distance will be ignored unless the focus mode is set to
+ \l FocusModeManual.
*/
-QList<QVideoFrame::PixelFormat> QCamera::supportedViewfinderPixelFormats(const QCameraViewfinderSettings &settings) const
+void QCamera::setFocusDistance(float d)
{
- QList<QVideoFrame::PixelFormat> pixelFormats;
- const QList<QCameraViewfinderSettings> capabilities = supportedViewfinderSettings(settings);
- for (const QCameraViewfinderSettings &s : capabilities) {
- if (!pixelFormats.contains(s.pixelFormat()))
- pixelFormats.append(s.pixelFormat());
- }
+ if (!d_func()->control || focusMode() != FocusModeManual)
+ return;
+ d_func()->control->setFocusDistance(d);
+}
- return pixelFormats;
+float QCamera::focusDistance() const
+{
+ if (d_func()->control && focusMode() == FocusModeManual)
+ return d_func()->control->focusDistance();
+ return 0.;
}
/*!
- Returns the error state of the object.
+ \qmlproperty real QtMultimedia::Camera::maximumZoomFactor
+
+ This property holds the maximum zoom factor supported.
+
+ This will be \c 1.0 on cameras that do not support zooming.
*/
-QCamera::Error QCamera::error() const
-{
- return d_func()->error;
-}
/*!
- Returns a string describing a camera's error state.
+ \property QCamera::maximumZoomFactor
+
+ Returns the maximum zoom factor.
+
+ This will be \c 1.0 on cameras that do not support zooming.
*/
-QString QCamera::errorString() const
+
+float QCamera::maximumZoomFactor() const
{
- return d_func()->errorString;
+ Q_D(const QCamera);
+ return d->control ? d->control->maxZoomFactor() : 1.f;
}
+/*!
+ \qmlproperty real QtMultimedia::Camera::minimumZoomFactor
+
+ This property holds the minimum zoom factor supported.
+
+ This will be \c 1.0 on cameras that do not support zooming.
+*/
/*!
- Returns true if the capture \a mode is suported.
+ \property QCamera::minimumZoomFactor
+
+ Returns the minimum zoom factor.
+
+ This will be \c 1.0 on cameras that do not support zooming.
*/
-bool QCamera::isCaptureModeSupported(QCamera::CaptureModes mode) const
+
+float QCamera::minimumZoomFactor() const
{
- return d_func()->control ? d_func()->control->isCaptureModeSupported(mode) : false;
+ Q_D(const QCamera);
+ return d->control ? d->control->minZoomFactor() : 1.f;
}
/*!
- \property QCamera::captureMode
+ \qmlproperty real QtMultimedia::Camera::zoomFactor
- The type of media (video or still images),
- the camera is configured to capture.
-
- It's allowed to change capture mode in any camera state,
- but if the camera is currently active,
- chaging capture mode is likely to lead to camera status
- chaged to QCamera::LoadedStatus, QCamera::LoadingStatus,
- and when the camera is ready to QCamera::ActiveStatus.
+ Gets or sets the current zoom factor. Values will be clamped between
+ \l minimumZoomFactor and \l maximumZoomFactor.
*/
-QCamera::CaptureModes QCamera::captureMode() const
+/*!
+ \property QCamera::zoomFactor
+ \brief The current zoom factor.
+
+ Gets or sets the current zoom factor. Values will be clamped between
+ \l minimumZoomFactor and \l maximumZoomFactor.
+*/
+float QCamera::zoomFactor() const
{
- return d_func()->control ? d_func()->control->captureMode() : QCamera::CaptureStillImage;
+ Q_D(const QCamera);
+ return d->control ? d->control->zoomFactor() : 1.f;
}
-
-void QCamera::setCaptureMode(QCamera::CaptureModes mode)
+/*!
+ Zooms to a zoom factor \a factor at a rate of 1 factor per second.
+ */
+void QCamera::setZoomFactor(float factor)
{
- Q_D(QCamera);
-
- if (mode != captureMode()) {
- if (d->control) {
- d->_q_preparePropertyChange(QCameraControl::CaptureMode);
- d->control->setCaptureMode(mode);
- }
- }
+ zoomTo(factor, 0.f);
}
-
/*!
- Starts the camera.
+ \qmlmethod void QtMultimedia::Camera::zoomTo(factor, rate)
- State is changed to QCamera::ActiveState if camera is started
- successfully, otherwise errorOccurred() signal is emitted.
+ Zooms to a zoom factor \a factor using \a rate.
- While the camera state is changed to QCamera::ActiveState,
- starting the camera service can be asynchronous with the actual
- status reported with QCamera::status property.
+ The \a rate is specified in powers of two per second. At a rate of 1
+ it would take 2 seconds to go from a zoom factor of 1 to 4.
+
+ \note Using a specific rate is not supported on all cameras. If not supported,
+ zooming will happen as fast as possible.
*/
-void QCamera::start()
-{
- Q_D(QCamera);
- d->setState(QCamera::ActiveState);
-}
/*!
- Stops the camera.
- The camera state is changed from QCamera::ActiveState to QCamera::LoadedState.
+ Zooms to a zoom factor \a factor using \a rate.
- In this state, the camera still consumes power.
+ The \a rate is specified in powers of two per second. At a rate of 1
+ it would take 2 seconds to go from a zoom factor of 1 to 4.
- \sa unload(), QCamera::UnloadedState
+ \note Using a specific rate is not supported on all cameras. If not supported,
+ zooming will happen as fast as possible.
*/
-void QCamera::stop()
+void QCamera::zoomTo(float factor, float rate)
{
+ Q_ASSERT(rate >= 0.f);
+ if (rate < 0.f)
+ rate = 0.f;
+
Q_D(QCamera);
- d->setState(QCamera::LoadedState);
+ if (!d->control)
+ return;
+ factor = qBound(d->control->minZoomFactor(), factor, d->control->maxZoomFactor());
+ d->control->zoomTo(factor, rate);
}
/*!
- Opens the camera device.
- The camera state is changed to QCamera::LoadedState.
+ \enum QCamera::FocusMode
+
+ \value FocusModeAuto Continuous auto focus mode.
+ \value FocusModeAutoNear Continuous auto focus mode on near objects.
+ \value FocusModeAutoFar Continuous auto focus mode on objects far away.
+ \value FocusModeHyperfocal Focus to hyperfocal distance, with the maximum depth of field achieved.
+ All objects at distances from half of this
+ distance out to infinity will be acceptably sharp.
+ \value FocusModeInfinity Focus strictly to infinity.
+ \value FocusModeManual Manual or fixed focus mode.
+*/
+
+/*!
+ \qmlproperty enumeration QtMultimedia::Camera::flashMode
- It's not necessary to explicitly load the camera, unless the application
- needs to read the supported camera settings and change the default values
- according to the camera capabilities.
+ Gets or sets a certain flash mode if the camera has a flash.
- In all the other cases, it's possible to start the camera directly
- from the unloaded state.
+ \value Camera.FlashOff Flash is Off.
+ \value Camera.FlashOn Flash is On.
+ \value Camera.FlashAuto Automatic flash.
- /sa QCamera::UnloadedState
+ \sa isFlashModeSupported, isFlashReady
*/
-void QCamera::load()
-{
- Q_D(QCamera);
- d->setState(QCamera::LoadedState);
-}
/*!
- Closes the camera device and deallocates the related resources.
- The camera state is changed to QCamera::UnloadedState.
+ \property QCamera::flashMode
+ \brief The flash mode being used.
+
+ Enables a certain flash mode if the camera has a flash.
+
+ \sa QCamera::FlashMode, QCamera::isFlashModeSupported, QCamera::isFlashReady
*/
-void QCamera::unload()
+QCamera::FlashMode QCamera::flashMode() const
{
- Q_D(QCamera);
- d->setState(QCamera::UnloadedState);
+ Q_D(const QCamera);
+ return d->control ? d->control->flashMode() : QCamera::FlashOff;
}
-QCamera::State QCamera::state() const
+void QCamera::setFlashMode(QCamera::FlashMode mode)
{
- return d_func()->state;
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setFlashMode(mode);
}
-QCamera::Status QCamera::status() const
-{
- if(d_func()->control)
- return (QCamera::Status)d_func()->control->status();
-
- return QCamera::UnavailableStatus;
-}
+/*!
+ \qmlmethod bool QtMultimedia::Camera::isFlashModeSupported(FlashMode mode)
+ Returns true if the flash \a mode is supported.
+*/
/*!
- Returns the lock types that the camera supports.
+ Returns true if the flash \a mode is supported.
*/
-QCamera::LockTypes QCamera::supportedLocks() const
+bool QCamera::isFlashModeSupported(QCamera::FlashMode mode) const
{
Q_D(const QCamera);
-
- return d->locksControl
- ? d->locksControl->supportedLocks()
- : QCamera::LockTypes();
+ return d->control ? d->control->isFlashModeSupported(mode) : (mode == FlashOff);
}
/*!
- Returns the requested lock types.
+ \qmlmethod bool QtMultimedia::Camera::isFlashReady()
+
+ Returns true if flash is charged.
*/
-QCamera::LockTypes QCamera::requestedLocks() const
-{
- return d_func()->requestedLocks;
-}
/*!
- Returns the status of requested camera settings locks.
+ Returns true if flash is charged.
*/
-QCamera::LockStatus QCamera::lockStatus() const
+bool QCamera::isFlashReady() const
{
- return d_func()->lockStatus;
+ Q_D(const QCamera);
+ return d->control ? d->control->isFlashReady() : false;
}
/*!
- Returns the lock status for a given \a lockType.
+ \qmlproperty Camera::TorchMode Camera::torchMode
+
+ Gets or sets the torch mode being used.
+
+ A torch is a continuous source of light. It can be used during video recording in
+ low light conditions. Enabling torch mode will usually override any currently set
+ flash mode.
+
+ \sa QCamera::TorchMode, Camera::isTorchModeSupported(), Camera::flashMode
*/
-QCamera::LockStatus QCamera::lockStatus(QCamera::LockType lockType) const
-{
- const QCameraPrivate *d = d_func();
- if (!(lockType & d->requestedLocks))
- return QCamera::Unlocked;
+/*!
+ \property QCamera::torchMode
+ \brief The torch mode being used.
+
+ A torch is a continuous source of light. It can be used during video recording in
+ low light conditions. Enabling torch mode will usually override any currently set
+ flash mode.
- if (d->locksControl)
- return d->locksControl->lockStatus(lockType);
+ \sa QCamera::TorchMode, QCamera::isTorchModeSupported, QCamera::flashMode
+*/
+QCamera::TorchMode QCamera::torchMode() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->torchMode() : TorchOff;
+}
- return QCamera::Locked;
+void QCamera::setTorchMode(QCamera::TorchMode mode)
+{
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setTorchMode(mode);
}
/*!
- \fn void QCamera::searchAndLock(QCamera::LockTypes locks)
+ \qmlmethod bool QtMultimedia::Camera::isTorchModeSupported(TorchMode mode)
- Locks the camera settings with the requested \a locks, including focusing in the single autofocus mode,
- exposure and white balance if the exposure and white balance modes are not manual.
+ Returns true if the torch \a mode is supported.
+*/
- The camera settings are usually locked before taking one or multiple still images,
- in responce to the shutter button being half pressed.
+/*!
+ Returns true if the torch \a mode is supported.
+*/
+bool QCamera::isTorchModeSupported(QCamera::TorchMode mode) const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->isTorchModeSupported(mode) : (mode == TorchOff);
+}
- The QCamera::locked() signal is emitted when camera settings are successfully locked,
- otherwise QCamera::lockFailed() is emitted.
+/*!
+ \qmlproperty ExposureMode QtMultimedia::Camera::exposureMode
+ \brief The exposure mode being used.
- QCamera also emits lockStatusChanged(QCamera::LockType, QCamera::LockStatus)
- on individual lock status changes and lockStatusChanged(QCamera::LockStatus) signal on composite status changes.
+ \sa QCamera::ExposureMode, Camera::isExposureModeSupported()
+*/
- Locking serves two roles: it initializes calculation of automatic parameter
- (focusing, calculating the correct exposure and white balance) and allows
- to keep some or all of those parameters during number of shots.
+/*!
+ \property QCamera::exposureMode
+ \brief The exposure mode being used.
- If the camera doesn't support keeping one of parameters between shots, the related
- lock state changes to QCamera::Unlocked.
+ \sa QCamera::isExposureModeSupported
+*/
+QCamera::ExposureMode QCamera::exposureMode() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->exposureMode() : QCamera::ExposureAuto;
+}
- It's also acceptable to relock already locked settings,
- depending on the lock parameter this initiates new focusing, exposure or white balance calculation.
- */
-void QCamera::searchAndLock(QCamera::LockTypes locks)
+void QCamera::setExposureMode(QCamera::ExposureMode mode)
{
Q_D(QCamera);
+ if (d->control)
+ d->control->setExposureMode(mode);
+}
- QCamera::LockStatus oldStatus = d->lockStatus;
- d->supressLockChangedSignal = true;
-
- if (d->locksControl) {
- locks &= d->locksControl->supportedLocks();
- d->requestedLocks |= locks;
- d->locksControl->searchAndLock(locks);
- }
+/*!
+ \qmlmethod bool QtMultimedia::Camera::isExposureModeSupported(ExposureMode mode)
- d->supressLockChangedSignal = false;
+ Returns true if the exposure \a mode is supported.
+*/
- d->lockStatus = oldStatus;
- d->updateLockStatus();
+/*!
+ Returns true if the exposure \a mode is supported.
+*/
+bool QCamera::isExposureModeSupported(QCamera::ExposureMode mode) const
+{
+ Q_D(const QCamera);
+ return d->control && d->control->isExposureModeSupported(mode);
}
/*!
- Lock all the supported camera settings.
- */
-void QCamera::searchAndLock()
+ \qmlproperty real QtMultimedia::Camera::exposureCompensation
+
+ Gets or sets the exposure compensation in EV units.
+
+ Exposure compensation property allows to adjust the automatically calculated
+ exposure.
+*/
+
+/*!
+ \property QCamera::exposureCompensation
+ \brief Exposure compensation in EV units.
+
+ Exposure compensation property allows to adjust the automatically calculated
+ exposure.
+*/
+float QCamera::exposureCompensation() const
{
- searchAndLock(LockExposure | LockWhiteBalance | LockFocus);
+ Q_D(const QCamera);
+ return d->control ? d->control->exposureCompensation() : 0.f;
}
-/*!
- Unlocks the camera settings specified with \a locks or cancel the current locking if one is active.
- */
-void QCamera::unlock(QCamera::LockTypes locks)
+void QCamera::setExposureCompensation(float ev)
{
Q_D(QCamera);
+ if (d->control)
+ d->control->setExposureCompensation(ev);
+}
- QCamera::LockStatus oldStatus = d->lockStatus;
- d->supressLockChangedSignal = true;
+/*!
+ \qmlproperty int QtMultimedia::Camera::isoSensitivity
- d->requestedLocks &= ~locks;
+ Describes the ISO sensitivity currently used by the camera.
- if (d->locksControl) {
- locks &= d->locksControl->supportedLocks();
- d->locksControl->unlock(locks);
- }
+*/
- d->supressLockChangedSignal = false;
+/*!
+ \property QCamera::isoSensitivity
+ \brief The sensor ISO sensitivity.
- d->lockStatus = oldStatus;
- d->updateLockStatus();
-}
+ Describes the ISO sensitivity currently used by the camera.
-/*!
- Unlock all the requested camera locks.
- */
-void QCamera::unlock()
+ \sa setAutoIsoSensitivity(), setManualIsoSensitivity()
+*/
+int QCamera::isoSensitivity() const
{
- unlock(d_func()->requestedLocks);
+ Q_D(const QCamera);
+ return d->control ? d->control->isoSensitivity() : -1;
}
-
/*!
- \class QCamera::FrameRateRange
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_camera
- \since 5.5
-
- \brief A FrameRateRange represents a range of frame rates as minimum and maximum rate.
+ \qmlproperty int QtMultimedia::Camera::manualIsoSensitivity
- If the minimum frame rate is equal to the maximum frame rate, the frame rate is fixed.
- If not, the actual frame rate fluctuates between the minimum and the maximum.
+ Describes a manually set ISO sensitivity
- \sa QCamera::supportedViewfinderFrameRateRanges(), QCameraViewfinderSettings
+ Setting this property to -1 (the default), implies that the camera
+ automatically adjusts the ISO sensitivity.
*/
/*!
- \fn QCamera::FrameRateRange::FrameRateRange()
+ \property QCamera::manualIsoSensitivity
+ \brief Describes a manually set ISO sensitivity
- Constructs a null frame rate range, with both minimumFrameRate and maximumFrameRate
- equal to \c 0.0.
+ Setting this property to -1 (the default), implies that the camera
+ automatically adjusts the ISO sensitivity.
*/
+void QCamera::setManualIsoSensitivity(int iso)
+{
+ Q_D(QCamera);
+ if (iso <= 0)
+ iso = -1;
+ if (d->control)
+ d->control->setManualIsoSensitivity(iso);
+}
+
+int QCamera::manualIsoSensitivity() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->manualIsoSensitivity() : 100;
+}
/*!
- \fn QCamera::FrameRateRange::FrameRateRange(qreal minimum, qreal maximum)
+ \fn QCamera::setAutoIsoSensitivity()
+ Turn on auto sensitivity
+*/
- Constructs a frame rate range with the given \a minimum and \a maximum frame rates.
+void QCamera::setAutoIsoSensitivity()
+{
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setManualIsoSensitivity(-1);
+}
+
+/*!
+ Returns the minimum ISO sensitivity supported by the camera.
*/
+int QCamera::minimumIsoSensitivity() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->minIso() : -1;
+}
/*!
- \variable QCamera::FrameRateRange::minimumFrameRate
- The minimum frame rate supported by the range, in frames per second.
+ Returns the maximum ISO sensitivity supported by the camera.
*/
+int QCamera::maximumIsoSensitivity() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->maxIso() : -1;
+}
/*!
- \variable QCamera::FrameRateRange::maximumFrameRate
- The maximum frame rate supported by the range, in frames per second.
+ The minimal exposure time in seconds.
*/
+float QCamera::minimumExposureTime() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->minExposureTime() : -1.f;
+}
/*!
- \enum QCamera::State
+ The maximal exposure time in seconds.
+*/
+float QCamera::maximumExposureTime() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->maxExposureTime() : -1.f;
+}
- This enum holds the current state of the camera.
+/*!
+ \qmlproperty float QtMultimedia::Camera::exposureTime
+ Returns the Camera's exposure time in seconds.
- \value UnloadedState
- The initial camera state, with camera not loaded.
- The camera capabilities, except supported capture modes,
- are unknown.
- While the supported settings are unknown in this state,
- it's allowed to set the camera capture settings like codec,
- resolution, or frame rate.
- \value LoadedState
- The camera is loaded and ready to be configured.
- In this state it's allowed to query camera capabilities,
- set capture resolution, codecs, etc.
- The viewfinder is not active in the loaded state.
- The camera consumes power in the loaded state.
- \value ActiveState
- In the active state as soon as camera is started
- the viewfinder displays video frames and the
- camera is ready for capture.
+ \sa manualExposureTime
*/
-
/*!
- \property QCamera::state
- \brief The current state of the camera object.
+ \property QCamera::exposureTime
+ \brief Camera's exposure time in seconds.
+
+ \sa minimumExposureTime(), maximumExposureTime(), setManualExposureTime()
*/
/*!
- \enum QCamera::Status
+ \fn QCamera::exposureTimeChanged(float speed)
- This enum holds the current status of the camera.
-
- \value ActiveStatus
- The camera has been started and can produce data.
- The viewfinder displays video frames in active state.
- Depending on backend, changing some camera settings like
- capture mode, codecs or resolution in ActiveState may lead
- to changing the camera status to LoadedStatus and StartingStatus while
- the settings are applied and back to ActiveStatus when the camera is ready.
- \value StartingStatus
- The camera is starting in result of state transition to QCamera::ActiveState.
- The camera service is not ready to capture yet.
- \value StoppingStatus
- The camera is stopping in result of state transition from QCamera::ActiveState
- to QCamera::LoadedState or QCamera::UnloadedState.
- \value StandbyStatus
- The camera is in the power saving standby mode.
- The camera may come to the standby mode after some time of inactivity
- in the QCamera::LoadedState state.
- \value LoadedStatus
- The camera is loaded and ready to be configured.
- This status indicates the camera device is opened and
- it's possible to query for supported image and video capture settings,
- like resolution, framerate and codecs.
- \value LoadingStatus
- The camera device loading in result of state transition from
- QCamera::UnloadedState to QCamera::LoadedState or QCamera::ActiveState.
- \value UnloadingStatus
- The camera device is unloading in result of state transition from
- QCamera::LoadedState or QCamera::ActiveState to QCamera::UnloadedState.
- \value UnloadedStatus
- The initial camera status, with camera not loaded.
- The camera capabilities including supported capture settings may be unknown.
- \value UnavailableStatus
- The camera or camera backend is not available.
+ Signals that a camera's exposure \a speed has changed.
*/
-
/*!
- \property QCamera::status
- \brief The current status of the camera object.
+ Returns the current exposure time in seconds.
*/
+float QCamera::exposureTime() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->exposureTime() : -1;
+}
/*!
- \enum QCamera::CaptureMode
+ \qmlproperty real QtMultimedia::Camera::manualExposureTime
- This enum holds the capture mode of the camera.
+ Gets or sets a manual exposure time.
- \value CaptureViewfinder Camera is only configured to display viewfinder.
- \value CaptureStillImage Camera is configured for still frames capture.
- \value CaptureVideo Camera is configured for video capture.
+ Setting this property to -1 (the default) means that the camera
+ automatically determines the exposure time.
*/
/*!
- \enum QCamera::LockType
-
- This enum holds the camera lock type.
+ \property QCamera::manualExposureTime
- \value NoLock
- \value LockExposure
- Lock camera exposure.
- \value LockWhiteBalance
- Lock the white balance.
- \value LockFocus
- Lock camera focus.
+ Set the manual exposure time to \a seconds
*/
+void QCamera::setManualExposureTime(float seconds)
+{
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setManualExposureTime(seconds);
+}
/*!
- \property QCamera::lockStatus
- \brief The overall status for all the requested camera locks.
+ Returns the manual exposure time in seconds, or -1
+ if the camera is using automatic exposure times.
*/
+float QCamera::manualExposureTime() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->manualExposureTime() : -1;
+}
/*!
- \fn void QCamera::locked()
-
- Signals all the requested camera settings are locked.
+ Use automatically calculated exposure time
*/
+void QCamera::setAutoExposureTime()
+{
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setManualExposureTime(-1);
+}
+
/*!
- \fn void QCamera::lockFailed()
+ \enum QCamera::FlashMode
- Signals locking of at least one requested camera settings failed.
+ \value FlashOff Flash is Off.
+ \value FlashOn Flash is On.
+ \value FlashAuto Automatic flash.
*/
/*!
- \fn QCamera::lockStatusChanged(QCamera::LockStatus status, QCamera::LockChangeReason reason)
+ \enum QCamera::TorchMode
- Signals the overall \a status for all the requested camera locks was changed with specified \a reason.
+ \value TorchOff Torch is Off.
+ \value TorchOn Torch is On.
+ \value TorchAuto Automatic torch.
*/
/*!
- \fn QCamera::lockStatusChanged(QCamera::LockType lock, QCamera::LockStatus status, QCamera::LockChangeReason reason)
- Signals the \a lock \a status was changed with specified \a reason.
+ \enum QCamera::ExposureMode
+
+ \value ExposureAuto Automatic mode.
+ \value ExposureManual Manual mode.
+ \value ExposurePortrait Portrait exposure mode.
+ \value ExposureNight Night mode.
+ \value ExposureSports Spots exposure mode.
+ \value ExposureSnow Snow exposure mode.
+ \value ExposureBeach Beach exposure mode.
+ \value ExposureAction Action mode. Since 5.5
+ \value ExposureLandscape Landscape mode. Since 5.5
+ \value ExposureNightPortrait Night portrait mode. Since 5.5
+ \value ExposureTheatre Theatre mode. Since 5.5
+ \value ExposureSunset Sunset mode. Since 5.5
+ \value ExposureSteadyPhoto Steady photo mode. Since 5.5
+ \value ExposureFireworks Fireworks mode. Since 5.5
+ \value ExposureParty Party mode. Since 5.5
+ \value ExposureCandlelight Candlelight mode. Since 5.5
+ \value ExposureBarcode Barcode mode. Since 5.5
*/
/*!
- \enum QCamera::LockStatus
+ \qmlproperty bool QtMultimedia::Camera::flashReady
- This enum holds the overall status for all the requested camera locks.
-
- \value Unlocked
- The application is not interested in camera settings value.
- The camera may keep this parameter without changes, this is common with camera focus,
- or adjust exposure and white balance constantly to keep the viewfinder image nice.
- \value Searching
- The application has requested the camera focus, exposure or white balance lock with
- QCamera::searchAndLock(). This state indicates the camera is focusing or
- calculating exposure and white balance.
- \value Locked
- The camera focus, exposure or white balance is locked.
- The camera is ready to capture, application may check the exposure
- stays the same, parameters. The \c Locked status usually means the
- requested parameter except in the cases when the parameter is requested
- to be constantly updated. For example, in continuous focusing mode,
- the focus is considered locked as long as the object is in focus, even
- while the actual focusing distance may be constantly changing.
+ Indicates if the flash is charged and ready to use.
*/
/*!
- \enum QCamera::LockChangeReason
+ \property QCamera::flashReady
+ \brief Indicates if the flash is charged and ready to use.
+*/
- This enum holds the reason why the camera lock status changed.
+/*!
+ \fn void QCamera::flashReady(bool ready)
- \value UserRequest
- The lock status changed in result of user request, usually to unlock camera settings.
- \value LockAcquired
- The lock status successfuly changed to QCamera::Locked.
- \value LockFailed
- The camera failed to acquire the requested lock in result of
- autofocus failure, exposure out of supported range, etc.
- \value LockLost
- The camera is not able to maintain the requested lock any more.
- Lock status is changed to QCamera::Unlocked.
- \value LockTemporaryLost
- The lock is lost, but the camera is working hard to reacquire it.
- This value may be used in continuous focusing mode,
- when the camera loses the focus, the focus lock state is changed to Qcamera::Searching
- with LockTemporaryLost reason.
+ Signal the flash \a ready status has changed.
*/
/*!
- \enum QCamera::Error
-
- This enum holds the last error code.
+ \fn void QCamera::isoSensitivityChanged(int value)
- \value NoError No errors have occurred.
- \value CameraError An error has occurred.
- \value InvalidRequestError System resource doesn't support requested functionality.
- \value ServiceMissingError No camera service available.
- \value NotSupportedFeatureError The feature is not supported.
+ Signal emitted when sensitivity changes to \a value.
*/
/*!
- \fn void QCamera::error(QCamera::Error value)
- \obsolete
+ \fn void QCamera::exposureCompensationChanged(float value)
- Use errorOccurred() instead.
+ Signal emitted when the exposure compensation changes to \a value.
*/
+
/*!
- \fn void QCamera::errorOccurred(QCamera::Error value)
- \since 5.15
+ \qmlproperty WhiteBalanceMode QtMultimedia::Camera::whiteBalanceMode
+
+ Gets or sets the white balance mode being used.
- Signal emitted when error state changes to \a value.
+ \sa QCamera::WhiteBalanceMode
*/
/*!
- \enum QCamera::Position
- \since 5.3
+ \property QCamera::whiteBalanceMode
- This enum specifies the physical position of the camera on the system hardware.
+ Returns the white balance mode being used.
+*/
+QCamera::WhiteBalanceMode QCamera::whiteBalanceMode() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->whiteBalanceMode() : QCamera::WhiteBalanceAuto;
+}
- \value UnspecifiedPosition The camera position is unspecified or unknown.
+/*!
+ Sets the white balance to \a mode.
+*/
+void QCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)
+{
+ Q_D(QCamera);
+ if (!d->control)
+ return;
+ if (!d->control->isWhiteBalanceModeSupported(mode))
+ return;
+ d->control->setWhiteBalanceMode(mode);
+ if (mode == QCamera::WhiteBalanceManual)
+ d->control->setColorTemperature(5600);
+}
- \value BackFace The camera is on the back face of the system hardware. For example on a
- mobile device, it means it is on the opposite side to that of the screen.
+/*!
+ \qmlmethod bool QtMultimedia::Camera::isWhiteBalanceModeSupported(WhiteBalanceMode mode)
- \value FrontFace The camera is on the front face of the system hardware. For example on a
- mobile device, it means it is on the same side as that of the screen. Viewfinder frames of
- front-facing cameras are mirrored horizontally, so the users can see themselves as looking
- into a mirror. Captured images or videos are not mirrored.
+ Returns true if the white balance \a mode is supported.
+*/
- \sa QCameraInfo::position()
+/*!
+ Returns true if the white balance \a mode is supported.
*/
+bool QCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const
+{
+ Q_D(const QCamera);
+ return d->control && d->control->isWhiteBalanceModeSupported(mode);
+}
/*!
- \fn void QCamera::captureModeChanged(QCamera::CaptureModes mode)
+ \qmlmethod QtMultimedia::Camera::colorTemperature
- Signals the capture \a mode has changed.
+ Gets or sets the current color temperature.
+
+ Setting a color temperature will only have an effect if WhiteBalanceManual is
+ supported. In this case, setting a temperature greater 0 will automatically set the
+ white balance mode to WhiteBalanceManual. Setting the temperature to 0 will reset
+ the white balance mode to WhiteBalanceAuto.
*/
/*!
- \fn QCamera::stateChanged(QCamera::State state)
-
- Signals the camera \a state has changed.
+ \property QCamera::colorTemperature
- Usually the state changes is caused by calling
- load(), unload(), start() and stop(),
- but the state can also be changed change as a result of camera error.
+ Returns the current color temperature if the
+ current white balance mode is \c WhiteBalanceManual. For other modes the
+ return value is undefined.
*/
+int QCamera::colorTemperature() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->colorTemperature() : 0;
+}
/*!
- \fn QCamera::statusChanged(QCamera::Status status)
+ Sets manual white balance to \a colorTemperature. This is used
+ when whiteBalanceMode() is set to \c WhiteBalanceManual. The units are Kelvin.
- Signals the camera \a status has changed.
+ Setting a color temperature will only have an effect if WhiteBalanceManual is
+ supported. In this case, setting a temperature greater 0 will automatically set the
+ white balance mode to WhiteBalanceManual. Setting the temperature to 0 will reset
+ the white balance mode to WhiteBalanceAuto.
+*/
+void QCamera::setColorTemperature(int colorTemperature)
+{
+ Q_D(QCamera);
+ if (!d->control)
+ return;
+ if (colorTemperature < 0)
+ colorTemperature = 0;
+ if (colorTemperature == 0) {
+ d->control->setWhiteBalanceMode(WhiteBalanceAuto);
+ } else if (!isWhiteBalanceModeSupported(WhiteBalanceManual)) {
+ return;
+ } else {
+ d->control->setWhiteBalanceMode(WhiteBalanceManual);
+ }
+ d->control->setColorTemperature(colorTemperature);
+}
+
+/*!
+ \enum QCamera::WhiteBalanceMode
+
+ \value WhiteBalanceAuto Auto white balance mode.
+ \value WhiteBalanceManual Manual white balance. In this mode the white
+ balance should be set with setColorTemperature()
+ \value WhiteBalanceSunlight Sunlight white balance mode.
+ \value WhiteBalanceCloudy Cloudy white balance mode.
+ \value WhiteBalanceShade Shade white balance mode.
+ \value WhiteBalanceTungsten Tungsten (incandescent) white balance mode.
+ \value WhiteBalanceFluorescent Fluorescent white balance mode.
+ \value WhiteBalanceFlash Flash white balance mode.
+ \value WhiteBalanceSunset Sunset white balance mode.
*/
+/*!
+ \fn void QCamera::brightnessChanged()
+ \internal
+*/
+/*!
+ \fn void QCamera::contrastChanged()
+ \internal
+*/
+/*!
+ \fn void QCamera::hueChanged()
+ \internal
+*/
+/*!
+ \fn void QCamera::saturationChanged()
+ \internal
+*/
QT_END_NAMESPACE
#include "moc_qcamera.cpp"
diff --git a/src/multimedia/camera/qcamera.h b/src/multimedia/camera/qcamera.h
index d088e9beb..82d89f5a9 100644
--- a/src/multimedia/camera/qcamera.h
+++ b/src/multimedia/camera/qcamera.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QCAMERA_H
#define QCAMERA_H
@@ -46,248 +10,264 @@
#include <QtCore/qpoint.h>
#include <QtCore/qrect.h>
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmediaservice.h>
+#include <QtCore/qobject.h>
-#include <QtMultimedia/qcameraexposure.h>
-#include <QtMultimedia/qcamerafocus.h>
-#include <QtMultimedia/qcameraimageprocessing.h>
-#include <QtMultimedia/qcameraviewfindersettings.h>
+#include <QtMultimedia/qcameradevice.h>
#include <QtMultimedia/qmediaenumdebug.h>
QT_BEGIN_NAMESPACE
-class QAbstractVideoSurface;
-class QVideoWidget;
-class QGraphicsVideoItem;
-class QCameraInfo;
+class QCameraDevice;
+class QPlatformMediaCaptureSession;
+class QMediaCaptureSession;
class QCameraPrivate;
-class Q_MULTIMEDIA_EXPORT QCamera : public QMediaObject
+class Q_MULTIMEDIA_EXPORT QCamera : public QObject
{
Q_OBJECT
- Q_PROPERTY(QCamera::State state READ state NOTIFY stateChanged)
- Q_PROPERTY(QCamera::Status status READ status NOTIFY statusChanged)
- Q_PROPERTY(QCamera::CaptureModes captureMode READ captureMode WRITE setCaptureMode NOTIFY captureModeChanged)
- Q_PROPERTY(QCamera::LockStatus lockStatus READ lockStatus NOTIFY lockStatusChanged)
-
- Q_ENUMS(Status)
- Q_ENUMS(State)
- Q_ENUMS(CaptureMode)
- Q_ENUMS(Error)
- Q_ENUMS(LockStatus)
- Q_ENUMS(LockChangeReason)
- Q_ENUMS(LockType)
- Q_ENUMS(Position)
-public:
- struct FrameRateRange
- {
- Q_DECL_CONSTEXPR FrameRateRange() Q_DECL_NOTHROW
- : minimumFrameRate(0)
- , maximumFrameRate(0)
- { }
-
- Q_DECL_CONSTEXPR FrameRateRange(qreal minimum, qreal maximum) Q_DECL_NOTHROW
- : minimumFrameRate(minimum)
- , maximumFrameRate(maximum)
- { }
-
- qreal minimumFrameRate;
- qreal maximumFrameRate;
- };
-
- enum Status {
- UnavailableStatus,
- UnloadedStatus,
- LoadingStatus,
- UnloadingStatus,
- LoadedStatus,
- StandbyStatus,
- StartingStatus,
- StoppingStatus,
- ActiveStatus
- };
-
- enum State {
- UnloadedState,
- LoadedState,
- ActiveState
- };
-
- enum CaptureMode
- {
- CaptureViewfinder = 0,
- CaptureStillImage = 0x01,
- CaptureVideo = 0x02
- };
- Q_DECLARE_FLAGS(CaptureModes, CaptureMode)
+ Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
+ // Qt 7: rename to device
+ Q_PROPERTY(QCameraDevice cameraDevice READ cameraDevice WRITE setCameraDevice NOTIFY cameraDeviceChanged)
+ Q_PROPERTY(Error error READ error NOTIFY errorChanged)
+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
+ Q_PROPERTY(QCameraFormat cameraFormat READ cameraFormat WRITE setCameraFormat NOTIFY cameraFormatChanged)
+
+ Q_PROPERTY(FocusMode focusMode READ focusMode WRITE setFocusMode NOTIFY focusModeChanged)
+ Q_PROPERTY(QPointF focusPoint READ focusPoint NOTIFY focusPointChanged)
+ Q_PROPERTY(QPointF customFocusPoint READ customFocusPoint WRITE setCustomFocusPoint NOTIFY customFocusPointChanged)
+ Q_PROPERTY(float focusDistance READ focusDistance WRITE setFocusDistance NOTIFY focusDistanceChanged)
+
+ Q_PROPERTY(float minimumZoomFactor READ minimumZoomFactor NOTIFY minimumZoomFactorChanged)
+ Q_PROPERTY(float maximumZoomFactor READ maximumZoomFactor NOTIFY maximumZoomFactorChanged)
+ Q_PROPERTY(float zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged)
+ Q_PROPERTY(float exposureTime READ exposureTime NOTIFY exposureTimeChanged)
+ Q_PROPERTY(int manualExposureTime READ manualExposureTime WRITE setManualExposureTime NOTIFY manualExposureTimeChanged)
+ Q_PROPERTY(int isoSensitivity READ isoSensitivity NOTIFY isoSensitivityChanged)
+ Q_PROPERTY(int manualIsoSensitivity READ manualIsoSensitivity WRITE setManualIsoSensitivity NOTIFY manualIsoSensitivityChanged)
+ Q_PROPERTY(float exposureCompensation READ exposureCompensation WRITE setExposureCompensation NOTIFY exposureCompensationChanged)
+ Q_PROPERTY(QCamera::ExposureMode exposureMode READ exposureMode WRITE setExposureMode NOTIFY exposureModeChanged)
+ Q_PROPERTY(bool flashReady READ isFlashReady NOTIFY flashReady)
+ Q_PROPERTY(QCamera::FlashMode flashMode READ flashMode WRITE setFlashMode NOTIFY flashModeChanged)
+ Q_PROPERTY(QCamera::TorchMode torchMode READ torchMode WRITE setTorchMode NOTIFY torchModeChanged)
+
+ Q_PROPERTY(WhiteBalanceMode whiteBalanceMode READ whiteBalanceMode WRITE setWhiteBalanceMode NOTIFY whiteBalanceModeChanged)
+ Q_PROPERTY(int colorTemperature READ colorTemperature WRITE setColorTemperature NOTIFY colorTemperatureChanged)
+ Q_PROPERTY(Features supportedFeatures READ supportedFeatures NOTIFY supportedFeaturesChanged)
+public:
enum Error
{
NoError,
- CameraError,
- InvalidRequestError,
- ServiceMissingError,
- NotSupportedFeatureError
+ CameraError
};
-
- enum LockStatus
- {
- Unlocked,
- Searching,
- Locked
+ Q_ENUM(Error)
+
+ enum FocusMode {
+ FocusModeAuto,
+ FocusModeAutoNear,
+ FocusModeAutoFar,
+ FocusModeHyperfocal,
+ FocusModeInfinity,
+ FocusModeManual
};
+ Q_ENUM(FocusMode)
- enum LockChangeReason {
- UserRequest,
- LockAcquired,
- LockFailed,
- LockLost,
- LockTemporaryLost
+ enum FlashMode {
+ FlashOff,
+ FlashOn,
+ FlashAuto
};
+ Q_ENUM(FlashMode)
- enum LockType
- {
- NoLock = 0,
- LockExposure = 0x01,
- LockWhiteBalance = 0x02,
- LockFocus = 0x04
+ enum TorchMode {
+ TorchOff,
+ TorchOn,
+ TorchAuto
};
- Q_DECLARE_FLAGS(LockTypes, LockType)
-
- enum Position
- {
- UnspecifiedPosition,
- BackFace,
- FrontFace
+ Q_ENUM(TorchMode)
+
+ enum ExposureMode {
+ ExposureAuto,
+ ExposureManual,
+ ExposurePortrait,
+ ExposureNight,
+ ExposureSports,
+ ExposureSnow,
+ ExposureBeach,
+ ExposureAction,
+ ExposureLandscape,
+ ExposureNightPortrait,
+ ExposureTheatre,
+ ExposureSunset,
+ ExposureSteadyPhoto,
+ ExposureFireworks,
+ ExposureParty,
+ ExposureCandlelight,
+ ExposureBarcode
+ };
+ Q_ENUM(ExposureMode)
+
+ enum WhiteBalanceMode {
+ WhiteBalanceAuto = 0,
+ WhiteBalanceManual = 1,
+ WhiteBalanceSunlight = 2,
+ WhiteBalanceCloudy = 3,
+ WhiteBalanceShade = 4,
+ WhiteBalanceTungsten = 5,
+ WhiteBalanceFluorescent = 6,
+ WhiteBalanceFlash = 7,
+ WhiteBalanceSunset = 8
};
+ Q_ENUM(WhiteBalanceMode)
+
+ enum class Feature {
+ ColorTemperature = 0x1,
+ ExposureCompensation = 0x2,
+ IsoSensitivity = 0x4,
+ ManualExposureTime = 0x8,
+ CustomFocusPoint = 0x10,
+ FocusDistance = 0x20
+ };
+ Q_DECLARE_FLAGS(Features, Feature)
explicit QCamera(QObject *parent = nullptr);
- explicit QCamera(const QByteArray& deviceName, QObject *parent = nullptr);
- explicit QCamera(const QCameraInfo& cameraInfo, QObject *parent = nullptr);
- explicit QCamera(QCamera::Position position, QObject *parent = nullptr);
+ explicit QCamera(const QCameraDevice& cameraDevice, QObject *parent = nullptr);
+ explicit QCamera(QCameraDevice::Position position, QObject *parent = nullptr);
~QCamera();
- QMultimedia::AvailabilityStatus availability() const override;
+ bool isAvailable() const;
+ bool isActive() const;
- State state() const;
- Status status() const;
+ QMediaCaptureSession *captureSession() const;
- CaptureModes captureMode() const;
- bool isCaptureModeSupported(CaptureModes mode) const;
+ QCameraDevice cameraDevice() const;
+ void setCameraDevice(const QCameraDevice &cameraDevice);
- QCameraExposure *exposure() const;
- QCameraFocus *focus() const;
- QCameraImageProcessing *imageProcessing() const;
+ QCameraFormat cameraFormat() const;
+ void setCameraFormat(const QCameraFormat &format);
- void setViewfinder(QVideoWidget *viewfinder);
- void setViewfinder(QGraphicsVideoItem *viewfinder);
- void setViewfinder(QAbstractVideoSurface *surface);
+ Error error() const;
+ QString errorString() const;
- QCameraViewfinderSettings viewfinderSettings() const;
- void setViewfinderSettings(const QCameraViewfinderSettings &settings);
+ Features supportedFeatures() const;
- QList<QCameraViewfinderSettings> supportedViewfinderSettings(
- const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const;
+ FocusMode focusMode() const;
+ void setFocusMode(FocusMode mode);
+ Q_INVOKABLE bool isFocusModeSupported(FocusMode mode) const;
- QList<QSize> supportedViewfinderResolutions(
- const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const;
+ QPointF focusPoint() const;
- QList<FrameRateRange> supportedViewfinderFrameRateRanges(
- const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const;
+ QPointF customFocusPoint() const;
+ void setCustomFocusPoint(const QPointF &point);
- QList<QVideoFrame::PixelFormat> supportedViewfinderPixelFormats(
- const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const;
+ void setFocusDistance(float d);
+ float focusDistance() const;
- Error error() const;
- QString errorString() const;
+ float minimumZoomFactor() const;
+ float maximumZoomFactor() const;
+ float zoomFactor() const;
+ void setZoomFactor(float factor);
- QCamera::LockTypes supportedLocks() const;
- QCamera::LockTypes requestedLocks() const;
+ FlashMode flashMode() const;
+ Q_INVOKABLE bool isFlashModeSupported(FlashMode mode) const;
+ Q_INVOKABLE bool isFlashReady() const;
- QCamera::LockStatus lockStatus() const;
- QCamera::LockStatus lockStatus(QCamera::LockType lock) const;
+ TorchMode torchMode() const;
+ Q_INVOKABLE bool isTorchModeSupported(TorchMode mode) const;
-public Q_SLOTS:
- void setCaptureMode(QCamera::CaptureModes mode);
+ ExposureMode exposureMode() const;
+ Q_INVOKABLE bool isExposureModeSupported(ExposureMode mode) const;
- void load();
- void unload();
+ float exposureCompensation() const;
- void start();
- void stop();
+ int isoSensitivity() const;
+ int manualIsoSensitivity() const;
- void searchAndLock();
- void unlock();
+ float exposureTime() const;
+ float manualExposureTime() const;
- void searchAndLock(QCamera::LockTypes locks);
- void unlock(QCamera::LockTypes locks);
+ int minimumIsoSensitivity() const;
+ int maximumIsoSensitivity() const;
-Q_SIGNALS:
- void stateChanged(QCamera::State state);
- void captureModeChanged(QCamera::CaptureModes);
- void statusChanged(QCamera::Status status);
+ float minimumExposureTime() const;
+ float maximumExposureTime() const;
- void locked();
- void lockFailed();
+ WhiteBalanceMode whiteBalanceMode() const;
+ Q_INVOKABLE bool isWhiteBalanceModeSupported(WhiteBalanceMode mode) const;
- void lockStatusChanged(QCamera::LockStatus status, QCamera::LockChangeReason reason);
- void lockStatusChanged(QCamera::LockType lock, QCamera::LockStatus status, QCamera::LockChangeReason reason);
+ int colorTemperature() const;
- void errorOccurred(QCamera::Error);
+public Q_SLOTS:
+ void setActive(bool active);
+ void start() { setActive(true); }
+ void stop() { setActive(false); }
-private:
- Q_DISABLE_COPY(QCamera)
- Q_DECLARE_PRIVATE(QCamera)
- Q_PRIVATE_SLOT(d_func(), void _q_preparePropertyChange(int))
- Q_PRIVATE_SLOT(d_func(), void _q_restartCamera())
- Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &))
- Q_PRIVATE_SLOT(d_func(), void _q_updateLockStatus(QCamera::LockType, QCamera::LockStatus, QCamera::LockChangeReason))
- Q_PRIVATE_SLOT(d_func(), void _q_updateState(QCamera::State))
- friend class QCameraInfo;
-};
+ void zoomTo(float zoom, float rate);
-Q_DECLARE_OPERATORS_FOR_FLAGS(QCamera::LockTypes)
+ void setFlashMode(FlashMode mode);
+ void setTorchMode(TorchMode mode);
+ void setExposureMode(ExposureMode mode);
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
-QT_WARNING_DISABLE_GCC("-Wfloat-equal")
+ void setExposureCompensation(float ev);
-Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator==(const QCamera::FrameRateRange &r1, const QCamera::FrameRateRange &r2) Q_DECL_NOTHROW
-{
- return qFuzzyCompare(r1.minimumFrameRate, r2.minimumFrameRate)
- && qFuzzyCompare(r1.maximumFrameRate, r2.maximumFrameRate);
-}
+ void setManualIsoSensitivity(int iso);
+ void setAutoIsoSensitivity();
+
+ void setManualExposureTime(float seconds);
+ void setAutoExposureTime();
-QT_WARNING_POP
+ void setWhiteBalanceMode(WhiteBalanceMode mode);
+ void setColorTemperature(int colorTemperature);
+
+Q_SIGNALS:
+ void activeChanged(bool);
+ void errorChanged();
+ void errorOccurred(QCamera::Error error, const QString &errorString);
+ void cameraDeviceChanged();
+ void cameraFormatChanged();
+ void supportedFeaturesChanged();
+
+ void focusModeChanged();
+ void zoomFactorChanged(float);
+ void minimumZoomFactorChanged(float);
+ void maximumZoomFactorChanged(float);
+ void focusDistanceChanged(float);
+ void focusPointChanged();
+ void customFocusPointChanged();
+
+ void flashReady(bool);
+ void flashModeChanged();
+ void torchModeChanged();
+
+ void exposureTimeChanged(float speed);
+ void manualExposureTimeChanged(float speed);
+ void isoSensitivityChanged(int);
+ void manualIsoSensitivityChanged(int);
+ void exposureCompensationChanged(float);
+ void exposureModeChanged();
+
+ void whiteBalanceModeChanged() QT6_ONLY(const);
+ void colorTemperatureChanged() QT6_ONLY(const);
+ void brightnessChanged();
+ void contrastChanged();
+ void saturationChanged();
+ void hueChanged();
-Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator!=(const QCamera::FrameRateRange &r1, const QCamera::FrameRateRange &r2) Q_DECL_NOTHROW
-{ return !(r1 == r2); }
+private:
+ class QPlatformCamera *platformCamera();
+ void setCaptureSession(QMediaCaptureSession *session);
+ friend class QMediaCaptureSession;
+ Q_DISABLE_COPY(QCamera)
+ Q_DECLARE_PRIVATE(QCamera)
+ friend class QCameraDevice;
+};
-Q_DECLARE_TYPEINFO(QCamera::FrameRateRange, Q_PRIMITIVE_TYPE);
+Q_DECLARE_OPERATORS_FOR_FLAGS(QCamera::Features)
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QCamera::State)
-Q_DECLARE_METATYPE(QCamera::Status)
-Q_DECLARE_METATYPE(QCamera::Error)
-Q_DECLARE_METATYPE(QCamera::CaptureMode)
-Q_DECLARE_METATYPE(QCamera::CaptureModes)
-Q_DECLARE_METATYPE(QCamera::LockType)
-Q_DECLARE_METATYPE(QCamera::LockStatus)
-Q_DECLARE_METATYPE(QCamera::LockChangeReason)
-Q_DECLARE_METATYPE(QCamera::Position)
-
-Q_MEDIA_ENUM_DEBUG(QCamera, State)
-Q_MEDIA_ENUM_DEBUG(QCamera, Status)
Q_MEDIA_ENUM_DEBUG(QCamera, Error)
-Q_MEDIA_ENUM_DEBUG(QCamera, CaptureMode)
-Q_MEDIA_ENUM_DEBUG(QCamera, LockType)
-Q_MEDIA_ENUM_DEBUG(QCamera, LockStatus)
-Q_MEDIA_ENUM_DEBUG(QCamera, LockChangeReason)
-Q_MEDIA_ENUM_DEBUG(QCamera, Position)
#endif // QCAMERA_H
diff --git a/src/multimedia/camera/qcamera_p.h b/src/multimedia/camera/qcamera_p.h
index 99759dbd3..ae1299435 100644
--- a/src/multimedia/camera/qcamera_p.h
+++ b/src/multimedia/camera/qcamera_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QCAMERA_P_H
#define QCAMERA_P_H
@@ -51,94 +15,26 @@
// We mean it.
//
-#include "qmediaobject_p.h"
-#include "qvideosurfaceoutput_p.h"
+#include "private/qobject_p.h"
#include "qcamera.h"
+#include "qcameradevice.h"
QT_BEGIN_NAMESPACE
-class QMediaServiceProvider;
-class QCameraControl;
-class QVideoDeviceSelectorControl;
-class QCameraLocksControl;
-class QCameraInfoControl;
-class QCameraViewfinderSettingsControl;
-class QCameraViewfinderSettingsControl2;
+class QPlatformCamera;
+class QPlatformMediaCaptureSession;
-class QCameraPrivate : public QMediaObjectPrivate
+class QCameraPrivate : public QObjectPrivate
{
- Q_DECLARE_NON_CONST_PUBLIC(QCamera)
+ Q_DECLARE_PUBLIC(QCamera)
public:
- QCameraPrivate():
- QMediaObjectPrivate(),
- provider(nullptr),
- control(nullptr),
- deviceControl(nullptr),
- locksControl(nullptr),
- infoControl(nullptr),
- viewfinderSettingsControl(nullptr),
- viewfinderSettingsControl2(nullptr),
- cameraExposure(nullptr),
- cameraFocus(nullptr),
- imageProcessing(nullptr),
- viewfinder(nullptr),
- capture(nullptr),
- state(QCamera::UnloadedState),
- error(QCamera::NoError),
- requestedLocks(QCamera::NoLock),
- lockStatus(QCamera::Unlocked),
- lockChangeReason(QCamera::UserRequest),
- supressLockChangedSignal(false),
- restartPending(false)
- {
- }
+ void init(const QCameraDevice &device);
- void init();
- void initControls();
+ QMediaCaptureSession *captureSession = nullptr;
+ QPlatformCamera *control = nullptr;
- void clear();
-
- QMediaServiceProvider *provider;
-
- QCameraControl *control;
- QVideoDeviceSelectorControl *deviceControl;
- QCameraLocksControl *locksControl;
- QCameraInfoControl *infoControl;
- QCameraViewfinderSettingsControl *viewfinderSettingsControl;
- QCameraViewfinderSettingsControl2 *viewfinderSettingsControl2;
-
- QCameraExposure *cameraExposure;
- QCameraFocus *cameraFocus;
- QCameraImageProcessing *imageProcessing;
-
- QObject *viewfinder;
- QObject *capture;
-
- QCamera::State state;
-
- QCamera::Error error;
- QString errorString;
-
- QCamera::LockTypes requestedLocks;
-
- QCamera::LockStatus lockStatus;
- QCamera::LockChangeReason lockChangeReason;
- bool supressLockChangedSignal;
-
- bool restartPending;
-
- QVideoSurfaceOutput surfaceViewfinder;
-
- void _q_error(int error, const QString &errorString);
- void unsetError() { error = QCamera::NoError; errorString.clear(); }
-
- void setState(QCamera::State);
-
- void _q_updateLockStatus(QCamera::LockType, QCamera::LockStatus, QCamera::LockChangeReason);
- void _q_updateState(QCamera::State newState);
- void _q_preparePropertyChange(int changeType);
- void _q_restartCamera();
- void updateLockStatus();
+ QCameraDevice cameraDevice;
+ QCameraFormat cameraFormat;
};
QT_END_NAMESPACE
diff --git a/src/multimedia/camera/qcameradevice.cpp b/src/multimedia/camera/qcameradevice.cpp
new file mode 100644
index 000000000..63e7fb4c0
--- /dev/null
+++ b/src/multimedia/camera/qcameradevice.cpp
@@ -0,0 +1,470 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qcameradevice_p.h"
+
+#include "qcamera_p.h"
+
+QT_BEGIN_NAMESPACE
+
+
+/*!
+ \class QCameraFormat
+ \since 6.2
+ \brief The QCameraFormat class describes a video format supported by a camera device.
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_camera
+
+ QCameraFormat represents a certain video format supported by a camera device.
+
+ The format is a combination of a
+ \l{QVideoFrameFormat::PixelFormat}{pixel format}, resolution and a range of frame
+ rates.
+
+ QCameraFormat objects can be queried from QCameraDevice to inspect the set of
+ supported video formats.
+
+ \sa QCameraDevice, QCamera
+*/
+
+/*!
+ \qmlvaluetype cameraFormat
+ \ingroup qmlvaluetypes
+ \inqmlmodule QtMultimedia
+ \since 6.2
+ //! \instantiates QCameraFormat
+ \brief Describes a video format supported by a camera device.
+ \ingroup multimedia_qml
+ \ingroup multimedia_video_qml
+
+ cameraFormat represents a certain video format supported by a camera device.
+
+ The format is a combination of a
+ \l{pixel format}{QVideoFrameFormat::PixelFormat}, resolution and a range of frame
+ rates.
+
+ cameraFormat objects can be queried from \l cameraDevice to inspect the set of
+ supported video formats.
+
+ \sa cameraDevice, Camera
+*/
+
+/*!
+ Constructs a null camera format.
+
+ \sa isNull()
+*/
+QCameraFormat::QCameraFormat() noexcept = default;
+
+/*!
+ Copy constructs a camera format from the \a other format.
+*/
+QCameraFormat::QCameraFormat(const QCameraFormat &other) noexcept = default;
+
+/*!
+ Assign \a other to this.
+*/
+QCameraFormat &QCameraFormat::operator=(const QCameraFormat &other) noexcept = default;
+
+/*!
+ Destructs the camera format object.
+*/
+QCameraFormat::~QCameraFormat() = default;
+
+/*! \fn bool QCameraFormat::isNull() const noexcept
+
+ Returns true if this is a default constructed QCameraFormat.
+*/
+
+/*!
+ \qmlproperty enumeration QtMultimedia::cameraFormat::pixelFormat
+
+ Holds the pixel format.
+
+ Most commonly this is either QVideoFrameFormat::Format_Jpeg or QVideoFrameFormat::Format_YUVY
+ but other formats could also be supported by the camera.
+
+ \sa QVideoFrameFormat::PixelFormat
+*/
+
+/*!
+ \property QCameraFormat::pixelFormat
+
+ Returns the pixel format.
+
+ Most commonly this is either QVideoFrameFormat::Format_Jpeg or QVideoFrameFormat::Format_YUVY
+ but other formats could also be supported by the camera.
+
+ \sa QVideoFrameFormat::PixelFormat
+*/
+QVideoFrameFormat::PixelFormat QCameraFormat::pixelFormat() const noexcept
+{
+ return d ? d->pixelFormat : QVideoFrameFormat::Format_Invalid;
+}
+
+/*!
+ \qmlproperty size QtMultimedia::cameraFormat::resolution
+
+ Returns the resolution.
+*/
+
+/*!
+ \property QCameraFormat::resolution
+
+ Returns the resolution.
+*/
+QSize QCameraFormat::resolution() const noexcept
+{
+ return d ? d->resolution : QSize();
+}
+
+/*!
+ \qmlproperty real QtMultimedia::cameraFormat::minFrameRate
+
+ Returns the lowest frame rate defined by this format.
+*/
+
+/*!
+ \property QCameraFormat::minFrameRate
+
+ Returns the lowest frame rate defined by this format.
+*/
+float QCameraFormat::minFrameRate() const noexcept
+{
+ return d ? d->minFrameRate : 0;
+}
+
+/*!
+ \qmlproperty real QtMultimedia::cameraFormat::maxFrameRate
+
+ Returns the highest frame rate defined by this format.
+
+ The camera will always try to use the maximum frame rate supported by a
+ certain video format.
+*/
+
+/*!
+ \property QCameraFormat::maxFrameRate
+
+ Returns the highest frame rate defined by this format.
+
+ The camera will always try to use the highest frame rate supported by a
+ certain video format.
+*/
+float QCameraFormat::maxFrameRate() const noexcept
+{
+ return d ? d->maxFrameRate : 0;
+}
+
+/*!
+ \internal
+*/
+QCameraFormat::QCameraFormat(QCameraFormatPrivate *p)
+ : d(p)
+{
+}
+
+/*!
+ Returns \c true if the \a other format is equal to this camera format, otherwise \c false.
+*/
+bool QCameraFormat::operator==(const QCameraFormat &other) const
+{
+ if (d == other.d)
+ return true;
+ if (!d || !other.d)
+ return false;
+ return d->pixelFormat == other.d->pixelFormat &&
+ d->minFrameRate == other.d->minFrameRate &&
+ d->maxFrameRate == other.d->maxFrameRate &&
+ d->resolution == other.d->resolution;
+}
+
+/*!
+ \fn bool QCameraFormat::operator!=(const QCameraFormat &other) const
+
+ Returns \c false if the \a other format is equal to this camera format, otherwise \c true.
+*/
+
+/*!
+ \class QCameraDevice
+ \brief The QCameraDevice class provides general information about camera devices.
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_camera
+
+ QCameraDevice represents a physical camera device and its properties.
+
+ You can discover what cameras are available on a system using the
+ availableCameras() and defaultCamera() functions. These are contained within
+ QtMultimedia::MediaDevices.
+
+ This example prints the name of all available cameras:
+
+ \snippet multimedia-snippets/camera.cpp Camera listing
+
+ A QCameraDevice can be used to construct a QCamera. The following example
+ instantiates a QCamera whose camera device is named \c {mycamera}:
+
+ \snippet multimedia-snippets/camera.cpp Camera selection
+
+ You can also use QCameraDevice to get general information about a camera
+ device such as description and physical position on the system.
+
+ \snippet multimedia-snippets/camera.cpp Camera info
+
+ \sa QCamera
+*/
+
+/*!
+ \qmlvaluetype cameraDevice
+ \ingroup qmlvaluetypes
+ \inqmlmodule QtMultimedia
+ \since 6.2
+ //! \instantiates QCameraDevice
+ \brief Describes a camera device.
+ \ingroup multimedia_qml
+ \ingroup multimedia_video_qml
+
+ The cameraDevice value type describes the properties of a camera device that
+ is connected to the system.
+
+ The list of camera devices can be queried from the \l{MediaDevices}
+ type. To select a certain camera device set it as the device
+ on \l{Camera}.
+
+ \qml
+ CaptureSession {
+ camera: Camera {
+ cameraDevice: mediaDevices.defaultVideoInput
+ }
+ }
+ MediaDevices {
+ id: mediaDevices
+ }
+ \endqml
+*/
+
+/*!
+ Constructs a null camera device
+*/
+QCameraDevice::QCameraDevice() = default;
+
+/*!
+ Constructs a copy of \a other.
+*/
+QCameraDevice::QCameraDevice(const QCameraDevice &other) = default;
+
+/*!
+ Destroys the QCameraDevice.
+*/
+QCameraDevice::~QCameraDevice() = default;
+
+/*!
+ Returns true if this QCameraDevice is equal to \a other.
+*/
+bool QCameraDevice::operator==(const QCameraDevice &other) const
+{
+ if (d == other.d)
+ return true;
+
+ if (!d || ! other.d)
+ return false;
+
+ return (d->id == other.d->id
+ && d->description == other.d->description
+ && d->position == other.d->position);
+}
+
+/*!
+ Returns true if this QCameraDevice is null or invalid.
+*/
+bool QCameraDevice::isNull() const
+{
+ return !d;
+}
+
+/*!
+ \qmlproperty string QtMultimedia::cameraDevice::id
+
+ Holds he device id of the camera
+
+ This is a unique ID to identify the camera and may not be human-readable.
+*/
+
+/*!
+ \property QCameraDevice::id
+
+ Returns the device id of the camera
+
+ This is a unique ID to identify the camera and may not be human-readable.
+*/
+QByteArray QCameraDevice::id() const
+{
+ return d ? d->id : QByteArray();
+}
+
+/*!
+ \qmlproperty bool QtMultimedia::cameraDevice::isDefault
+
+ Is true if this is the default camera device.
+*/
+
+/*!
+ \property QCameraDevice::isDefault
+
+ Returns true if this is the default camera device.
+*/
+bool QCameraDevice::isDefault() const
+{
+ return d ? d->isDefault : false;
+}
+
+/*!
+ \since 6.7
+ \qmlproperty QtVideo::Rotation QtMultimedia::cameraDevice::correctionAngle
+
+ Returns the rotation angle needed to compensate for the physical camera rotation of the camera
+ compared to its native orientation. In other words, the property represents the clockwise angle
+ through which the output image needs to be rotated to be upright on the device screen in its
+ native orientation. Since \a correctionAngle is relative to the native orientation, this value
+ does not change with altering the device orientation (portrait/landscape). The correction angle
+ may be non-zero mostly on Android, where native and camera orientations are defined by the manufacturer.
+
+ \image camera_correctionAngle_90.png Example with 90 degrees \a correctionAngle
+*/
+
+/*!
+ \since 6.7
+ \property QCameraDevice::correctionAngle
+
+ Returns the rotation angle needed to compensate for the physical camera rotation of the camera
+ compared to its native orientation. In other words, the property represents the clockwise angle
+ through which the output image needs to be rotated to be upright on the device screen in its
+ native orientation. Since \a correctionAngle is relative to the native orientation, this value
+ does not change with altering the device orientation (portrait/landscape). The correction angle
+ may be non-zero mostly on Android, where native and camera orientations are defined by the manufacturer.
+
+ \image camera_correctionAngle_90.png Example with 90 degrees \a correctionAngle
+*/
+QtVideo::Rotation QCameraDevice::correctionAngle() const
+{
+ return d ? QtVideo::Rotation(d->orientation) : QtVideo::Rotation::None;
+}
+
+/*!
+ \qmlproperty string QtMultimedia::cameraDevice::description
+
+ Holds a human readable name of the camera.
+
+ Use this string to present the device to the user.
+*/
+
+/*!
+ \property QCameraDevice::description
+
+ Returns the human-readable description of the camera.
+
+ Use this string to present the device to the user.
+*/
+QString QCameraDevice::description() const
+{
+ return d ? d->description : QString();
+}
+
+/*!
+ \enum QCameraDevice::Position
+
+ This enum specifies the physical position of the camera on the system hardware.
+
+ \value UnspecifiedPosition The camera position is unspecified or unknown.
+ \value BackFace The camera is on the back face of the system hardware. For example on a
+ mobile device, it means it is on the opposite side to that of the screen.
+ \value FrontFace The camera is on the front face of the system hardware. For example on a
+ mobile device, it means it is on the same side as that of the screen.
+
+ \sa position()
+*/
+
+/*!
+ \qmlproperty enumeration QtMultimedia::cameraDevice::position
+
+ Returns the physical position of the camera on the hardware system.
+
+ The returned value can be one of the following:
+
+ \value cameraDevice.UnspecifiedPosition The camera position is unspecified or unknown.
+ \value cameraDevice.BackFace The camera is on the back face of the system hardware. For example on a
+ mobile device, it means it is on the opposite side to that of the screen.
+ \value cameraDevice.FrontFace The camera is on the front face of the system hardware. For example on a
+ mobile device, it means it is on the same side as that of the screen.
+*/
+
+/*!
+ \property QCameraDevice::position
+
+ Returns the physical position of the camera on the hardware system.
+*/
+QCameraDevice::Position QCameraDevice::position() const
+{
+ return d ? d->position : QCameraDevice::UnspecifiedPosition;
+}
+
+/*!
+ Returns a list of resolutions that the camera can use to
+ capture still images.
+
+ \sa QImageCapture
+ */
+QList<QSize> QCameraDevice::photoResolutions() const
+{
+ return d ? d->photoResolutions : QList<QSize>{};
+}
+
+/*!
+ \qmlproperty CameraFormat QtMultimedia::cameraDevice::videoFormats
+
+ Holds the video formats supported by the camera.
+*/
+
+/*!
+ \property QCameraDevice::videoFormats
+
+ Returns the video formats supported by the camera.
+*/
+QList<QCameraFormat> QCameraDevice::videoFormats() const
+{
+ return d ? d->videoFormats : QList<QCameraFormat>{};
+}
+
+QCameraDevice::QCameraDevice(QCameraDevicePrivate *p)
+ : d(p)
+{}
+
+/*!
+ Sets the QCameraDevice object to be equal to \a other.
+*/
+QCameraDevice& QCameraDevice::operator=(const QCameraDevice& other) = default;
+
+/*!
+ \fn QCameraDevice::operator!=(const QCameraDevice &other) const
+
+ Returns true if this QCameraDevice is different from \a other.
+*/
+
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug d, const QCameraDevice &camera)
+{
+ d.maybeSpace() << QStringLiteral("QCameraDevice(name=%1, id=%2, position=%3)")
+ .arg(camera.description())
+ .arg(QLatin1StringView(camera.id()))
+ .arg(QLatin1StringView(
+ QMetaEnum::fromType<QCameraDevice::Position>().valueToKey(
+ camera.position())));
+ return d.space();
+}
+#endif
+
+QT_END_NAMESPACE
+
+#include "moc_qcameradevice.cpp"
diff --git a/src/multimedia/camera/qcameradevice.h b/src/multimedia/camera/qcameradevice.h
new file mode 100644
index 000000000..2a9fac659
--- /dev/null
+++ b/src/multimedia/camera/qcameradevice.h
@@ -0,0 +1,104 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCAMERAINFO_H
+#define QCAMERAINFO_H
+
+#include <QtMultimedia/qtvideo.h>
+#include <QtMultimedia/qvideoframe.h>
+#include <QtCore/qsharedpointer.h>
+
+QT_BEGIN_NAMESPACE
+
+class QCameraFormatPrivate;
+class Q_MULTIMEDIA_EXPORT QCameraFormat
+{
+ Q_GADGET
+ Q_PROPERTY(QSize resolution READ resolution CONSTANT)
+ Q_PROPERTY(QVideoFrameFormat::PixelFormat pixelFormat READ pixelFormat CONSTANT)
+ Q_PROPERTY(float minFrameRate READ minFrameRate CONSTANT)
+ Q_PROPERTY(float maxFrameRate READ maxFrameRate CONSTANT)
+public:
+ QCameraFormat() noexcept;
+ QCameraFormat(const QCameraFormat &other) noexcept;
+ QCameraFormat &operator=(const QCameraFormat &other) noexcept;
+ ~QCameraFormat();
+
+ QVideoFrameFormat::PixelFormat pixelFormat() const noexcept;
+ QSize resolution() const noexcept;
+ float minFrameRate() const noexcept;
+ float maxFrameRate() const noexcept;
+
+ bool isNull() const noexcept { return !d; }
+
+ bool operator==(const QCameraFormat &other) const;
+ inline bool operator!=(const QCameraFormat &other) const
+ { return !operator==(other); }
+
+private:
+ friend class QCameraFormatPrivate;
+ QCameraFormat(QCameraFormatPrivate *p);
+ QExplicitlySharedDataPointer<QCameraFormatPrivate> d;
+};
+
+class QCameraDevicePrivate;
+class Q_MULTIMEDIA_EXPORT QCameraDevice
+{
+ Q_GADGET
+ Q_PROPERTY(QByteArray id READ id CONSTANT)
+ Q_PROPERTY(QString description READ description CONSTANT)
+ Q_PROPERTY(bool isDefault READ isDefault CONSTANT)
+ Q_PROPERTY(Position position READ position CONSTANT)
+ Q_PROPERTY(QList<QCameraFormat> videoFormats READ videoFormats CONSTANT)
+ Q_PROPERTY(QtVideo::Rotation correctionAngle READ correctionAngle CONSTANT)
+public:
+ QCameraDevice();
+ QCameraDevice(const QCameraDevice& other);
+ QCameraDevice& operator=(const QCameraDevice& other);
+ ~QCameraDevice();
+
+ bool operator==(const QCameraDevice &other) const;
+ inline bool operator!=(const QCameraDevice &other) const;
+
+ bool isNull() const;
+
+ QByteArray id() const;
+ QString description() const;
+
+ // ### Add here and to QAudioDevice
+// QByteArray groupId() const;
+// QString groupDescription() const;
+
+ bool isDefault() const;
+
+ enum Position
+ {
+ UnspecifiedPosition,
+ BackFace,
+ FrontFace
+ };
+ Q_ENUM(Position)
+
+ Position position() const;
+
+ QList<QSize> photoResolutions() const;
+ QList<QCameraFormat> videoFormats() const;
+
+ QtVideo::Rotation correctionAngle() const;
+ // ### Add zoom and other camera information
+
+private:
+ friend class QCameraDevicePrivate;
+ QCameraDevice(QCameraDevicePrivate *p);
+ QExplicitlySharedDataPointer<QCameraDevicePrivate> d;
+};
+
+bool QCameraDevice::operator!=(const QCameraDevice &other) const { return !operator==(other); }
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QCameraDevice&);
+#endif
+
+QT_END_NAMESPACE
+
+#endif // QCAMERAINFO_H
diff --git a/src/multimedia/camera/qcameradevice_p.h b/src/multimedia/camera/qcameradevice_p.h
new file mode 100644
index 000000000..638cc0cae
--- /dev/null
+++ b/src/multimedia/camera/qcameradevice_p.h
@@ -0,0 +1,75 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCAMERAINFO_P_H
+#define QCAMERAINFO_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qcameradevice.h>
+#include <QtCore/qsharedpointer.h>
+#include <QtCore/private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QCameraFormatPrivate : public QSharedData
+{
+public:
+ QVideoFrameFormat::PixelFormat pixelFormat = QVideoFrameFormat::Format_Invalid;
+ QSize resolution;
+ float minFrameRate = 0;
+ float maxFrameRate = 0;
+ QVideoFrameFormat::ColorRange colorRange = QVideoFrameFormat::ColorRange_Unknown;
+
+ static QVideoFrameFormat::ColorRange getColorRange(const QCameraFormat &format)
+ {
+ auto d = handle(format);
+ return d ? d->colorRange : QVideoFrameFormat::ColorRange_Unknown;
+ }
+
+ static const QCameraFormatPrivate *handle(const QCameraFormat &format)
+ {
+ return format.d.get();
+ }
+
+ QCameraFormat create() { return QCameraFormat(this); }
+};
+
+class QCameraDevicePrivate : public QSharedData
+{
+public:
+ QByteArray id;
+ QString description;
+ bool isDefault = false;
+ QCameraDevice::Position position = QCameraDevice::UnspecifiedPosition;
+ int orientation = 0;
+ QList<QSize> photoResolutions;
+ QList<QCameraFormat> videoFormats;
+
+ static const QCameraDevicePrivate *handle(const QCameraDevice &device)
+ {
+ return device.d.data();
+ }
+
+ bool operator==(const QCameraDevicePrivate &other) const
+ {
+ return id == other.id && description == other.description && isDefault == other.isDefault
+ && position == other.position && orientation == other.orientation
+ && photoResolutions == other.photoResolutions && videoFormats == other.videoFormats;
+ }
+
+ QCameraDevice create() { return QCameraDevice(this); }
+};
+
+QT_END_NAMESPACE
+
+#endif // QCAMERAINFO_P_H
diff --git a/src/multimedia/camera/qcameraexposure.cpp b/src/multimedia/camera/qcameraexposure.cpp
deleted file mode 100644
index 022dea28c..000000000
--- a/src/multimedia/camera/qcameraexposure.cpp
+++ /dev/null
@@ -1,707 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qcameraexposure.h"
-#include "qmediaobject_p.h"
-
-#include <qcamera.h>
-#include <qcameraexposurecontrol.h>
-#include <qcameraflashcontrol.h>
-
-#include <QtCore/QMetaObject>
-#include <QtCore/QDebug>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraExposure
-
-
- \brief The QCameraExposure class provides interface for exposure related camera settings.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_camera
-
-*/
-
-//#define DEBUG_EXPOSURE_CHANGES 1
-
-static void qRegisterCameraExposureMetaTypes()
-{
- qRegisterMetaType<QCameraExposure::ExposureMode>("QCameraExposure::ExposureMode");
- qRegisterMetaType<QCameraExposure::FlashModes>("QCameraExposure::FlashModes");
- qRegisterMetaType<QCameraExposure::MeteringMode>("QCameraExposure::MeteringMode");
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterCameraExposureMetaTypes)
-
-
-class QCameraExposurePrivate
-{
- Q_DECLARE_NON_CONST_PUBLIC(QCameraExposure)
-public:
- void initControls();
- QCameraExposure *q_ptr;
-
- template<typename T> T actualExposureParameter(QCameraExposureControl::ExposureParameter parameter, const T &defaultValue) const;
- template<typename T> T requestedExposureParameter(QCameraExposureControl::ExposureParameter parameter, const T &defaultValue) const;
- template<typename T> void setExposureParameter(QCameraExposureControl::ExposureParameter parameter, const T &value);
- void resetExposureParameter(QCameraExposureControl::ExposureParameter parameter);
-
- QCamera *camera;
- QCameraExposureControl *exposureControl;
- QCameraFlashControl *flashControl;
-
- void _q_exposureParameterChanged(int parameter);
- void _q_exposureParameterRangeChanged(int parameter);
-};
-
-void QCameraExposurePrivate::initControls()
-{
- Q_Q(QCameraExposure);
-
- QMediaService *service = camera->service();
- exposureControl = nullptr;
- flashControl = nullptr;
- if (service) {
- exposureControl = qobject_cast<QCameraExposureControl *>(service->requestControl(QCameraExposureControl_iid));
- flashControl = qobject_cast<QCameraFlashControl *>(service->requestControl(QCameraFlashControl_iid));
- }
- if (exposureControl) {
- q->connect(exposureControl, SIGNAL(actualValueChanged(int)),
- q, SLOT(_q_exposureParameterChanged(int)));
- q->connect(exposureControl, SIGNAL(parameterRangeChanged(int)),
- q, SLOT(_q_exposureParameterRangeChanged(int)));
- }
-
- if (flashControl)
- q->connect(flashControl, SIGNAL(flashReady(bool)), q, SIGNAL(flashReady(bool)));
-}
-
-template<typename T>
-T QCameraExposurePrivate::actualExposureParameter(QCameraExposureControl::ExposureParameter parameter, const T &defaultValue) const
-{
- QVariant value = exposureControl ? exposureControl->actualValue(parameter) : QVariant();
-
- return value.isValid() ? value.value<T>() : defaultValue;
-}
-
-template<typename T>
-T QCameraExposurePrivate::requestedExposureParameter(QCameraExposureControl::ExposureParameter parameter, const T &defaultValue) const
-{
- QVariant value = exposureControl ? exposureControl->requestedValue(parameter) : QVariant();
-
- return value.isValid() ? value.value<T>() : defaultValue;
-}
-
-template<typename T>
-void QCameraExposurePrivate::setExposureParameter(QCameraExposureControl::ExposureParameter parameter, const T &value)
-{
- if (exposureControl)
- exposureControl->setValue(parameter, QVariant::fromValue<T>(value));
-}
-
-void QCameraExposurePrivate::resetExposureParameter(QCameraExposureControl::ExposureParameter parameter)
-{
- if (exposureControl)
- exposureControl->setValue(parameter, QVariant());
-}
-
-
-void QCameraExposurePrivate::_q_exposureParameterChanged(int parameter)
-{
- Q_Q(QCameraExposure);
-
-#if DEBUG_EXPOSURE_CHANGES
- qDebug() << "Exposure parameter changed:"
- << QCameraExposureControl::ExposureParameter(parameter)
- << exposureControl->actualValue(QCameraExposureControl::ExposureParameter(parameter));
-#endif
-
- switch (parameter) {
- case QCameraExposureControl::ISO:
- emit q->isoSensitivityChanged(q->isoSensitivity());
- break;
- case QCameraExposureControl::Aperture:
- emit q->apertureChanged(q->aperture());
- break;
- case QCameraExposureControl::ShutterSpeed:
- emit q->shutterSpeedChanged(q->shutterSpeed());
- break;
- case QCameraExposureControl::ExposureCompensation:
- emit q->exposureCompensationChanged(q->exposureCompensation());
- break;
- }
-}
-
-void QCameraExposurePrivate::_q_exposureParameterRangeChanged(int parameter)
-{
- Q_Q(QCameraExposure);
-
- switch (parameter) {
- case QCameraExposureControl::Aperture:
- emit q->apertureRangeChanged();
- break;
- case QCameraExposureControl::ShutterSpeed:
- emit q->shutterSpeedRangeChanged();
- break;
- }
-}
-
-/*!
- Construct a QCameraExposure from service \a provider and \a parent.
-*/
-
-QCameraExposure::QCameraExposure(QCamera *parent):
- QObject(parent), d_ptr(new QCameraExposurePrivate)
-{
- Q_D(QCameraExposure);
- d->camera = parent;
- d->q_ptr = this;
- d->initControls();
-}
-
-
-/*!
- Destroys the camera exposure object.
-*/
-
-QCameraExposure::~QCameraExposure()
-{
- Q_D(QCameraExposure);
- if (d->exposureControl)
- d->camera->service()->releaseControl(d->exposureControl);
-
- delete d;
-}
-
-/*!
- Returns true if exposure settings are supported by this camera.
-*/
-bool QCameraExposure::isAvailable() const
-{
- return d_func()->exposureControl != nullptr;
-}
-
-
-/*!
- \property QCameraExposure::flashMode
- \brief The flash mode being used.
-
- Usually the single QCameraExposure::FlashMode flag is used,
- but some non conflicting flags combination are also allowed,
- like QCameraExposure::FlashManual | QCameraExposure::FlashSlowSyncRearCurtain.
-
- \sa QCameraExposure::isFlashModeSupported(), QCameraExposure::isFlashReady()
-*/
-
-QCameraExposure::FlashModes QCameraExposure::flashMode() const
-{
- return d_func()->flashControl ? d_func()->flashControl->flashMode() : QCameraExposure::FlashOff;
-}
-
-void QCameraExposure::setFlashMode(QCameraExposure::FlashModes mode)
-{
- if (d_func()->flashControl)
- d_func()->flashControl->setFlashMode(mode);
-}
-
-/*!
- Returns true if the flash \a mode is supported.
-*/
-
-bool QCameraExposure::isFlashModeSupported(QCameraExposure::FlashModes mode) const
-{
- return d_func()->flashControl ? d_func()->flashControl->isFlashModeSupported(mode) : false;
-}
-
-/*!
- Returns true if flash is charged.
-*/
-
-bool QCameraExposure::isFlashReady() const
-{
- return d_func()->flashControl ? d_func()->flashControl->isFlashReady() : false;
-}
-
-/*!
- \property QCameraExposure::exposureMode
- \brief The exposure mode being used.
-
- \sa QCameraExposure::isExposureModeSupported()
-*/
-
-QCameraExposure::ExposureMode QCameraExposure::exposureMode() const
-{
- return d_func()->actualExposureParameter<QCameraExposure::ExposureMode>(QCameraExposureControl::ExposureMode, QCameraExposure::ExposureAuto);
-}
-
-void QCameraExposure::setExposureMode(QCameraExposure::ExposureMode mode)
-{
- d_func()->setExposureParameter<QCameraExposure::ExposureMode>(QCameraExposureControl::ExposureMode, mode);
-}
-
-/*!
- Returns true if the exposure \a mode is supported.
-*/
-
-bool QCameraExposure::isExposureModeSupported(QCameraExposure::ExposureMode mode) const
-{
- if (!d_func()->exposureControl)
- return false;
-
- bool continuous = false;
- return d_func()->exposureControl->supportedParameterRange(QCameraExposureControl::ExposureMode, &continuous)
- .contains(QVariant::fromValue<QCameraExposure::ExposureMode>(mode));
-}
-
-/*!
- \property QCameraExposure::exposureCompensation
- \brief Exposure compensation in EV units.
-
- Exposure compensation property allows to adjust the automatically calculated exposure.
-*/
-
-qreal QCameraExposure::exposureCompensation() const
-{
- return d_func()->actualExposureParameter<qreal>(QCameraExposureControl::ExposureCompensation, 0.0);
-}
-
-void QCameraExposure::setExposureCompensation(qreal ev)
-{
- d_func()->setExposureParameter<qreal>(QCameraExposureControl::ExposureCompensation, ev);
-}
-
-/*!
- \property QCameraExposure::meteringMode
- \brief The metering mode being used.
-
- \sa QCameraExposure::isMeteringModeSupported()
-*/
-
-QCameraExposure::MeteringMode QCameraExposure::meteringMode() const
-{
- return d_func()->actualExposureParameter<QCameraExposure::MeteringMode>(QCameraExposureControl::MeteringMode, QCameraExposure::MeteringMatrix);
-}
-
-void QCameraExposure::setMeteringMode(QCameraExposure::MeteringMode mode)
-{
- d_func()->setExposureParameter<QCameraExposure::MeteringMode>(QCameraExposureControl::MeteringMode, mode);
-}
-
-/*!
- \fn QCameraExposure::spotMeteringPoint() const
-
- When supported, the spot metering point is the (normalized) position of the point of the image
- where exposure metering will be performed. This is typically used to indicate an
- "interesting" area of the image that should be exposed properly.
-
- The coordinates are relative frame coordinates:
- QPointF(0,0) points to the left top frame point, QPointF(0.5,0.5) points to the frame center,
- which is typically the default spot metering point.
-
- The spot metering point is only used with spot metering mode.
-
- \sa setSpotMeteringPoint()
-*/
-
-QPointF QCameraExposure::spotMeteringPoint() const
-{
- return d_func()->exposureControl ? d_func()->exposureControl->actualValue(QCameraExposureControl::SpotMeteringPoint).toPointF() : QPointF();
-}
-
-/*!
- \fn QCameraExposure::setSpotMeteringPoint(const QPointF &point)
-
- Allows setting the spot metering point to \a point.
-
- \sa spotMeteringPoint()
-*/
-
-void QCameraExposure::setSpotMeteringPoint(const QPointF &point)
-{
- if (d_func()->exposureControl)
- d_func()->exposureControl->setValue(QCameraExposureControl::SpotMeteringPoint, point);
-}
-
-
-/*!
- Returns true if the metering \a mode is supported.
-*/
-bool QCameraExposure::isMeteringModeSupported(QCameraExposure::MeteringMode mode) const
-{
- if (!d_func()->exposureControl)
- return false;
-
- bool continuous = false;
- return d_func()->exposureControl->supportedParameterRange(QCameraExposureControl::MeteringMode, &continuous)
- .contains(QVariant::fromValue<QCameraExposure::MeteringMode>(mode));
-}
-
-int QCameraExposure::isoSensitivity() const
-{
- return d_func()->actualExposureParameter<int>(QCameraExposureControl::ISO, -1);
-}
-
-/*!
- Returns the requested ISO sensitivity
- or -1 if automatic ISO is turned on.
-*/
-int QCameraExposure::requestedIsoSensitivity() const
-{
- return d_func()->requestedExposureParameter<int>(QCameraExposureControl::ISO, -1);
-}
-
-/*!
- Returns the list of ISO senitivities camera supports.
-
- If the camera supports arbitrary ISO sensitivities within the supported range,
- *\a continuous is set to true, otherwise *\a continuous is set to false.
-*/
-QList<int> QCameraExposure::supportedIsoSensitivities(bool *continuous) const
-{
- QList<int> res;
- QCameraExposureControl *control = d_func()->exposureControl;
-
- bool tmp = false;
- if (!continuous)
- continuous = &tmp;
-
- if (!control)
- return res;
-
- const auto range = control->supportedParameterRange(QCameraExposureControl::ISO, continuous);
- for (const QVariant &value : range) {
- bool ok = false;
- int intValue = value.toInt(&ok);
- if (ok)
- res.append(intValue);
- else
- qWarning() << "Incompatible ISO value type, int is expected";
- }
-
- return res;
-}
-
-/*!
- \fn QCameraExposure::setManualIsoSensitivity(int iso)
- Sets the manual sensitivity to \a iso
-*/
-
-void QCameraExposure::setManualIsoSensitivity(int iso)
-{
- d_func()->setExposureParameter<int>(QCameraExposureControl::ISO, iso);
-}
-
-/*!
- \fn QCameraExposure::setAutoIsoSensitivity()
- Turn on auto sensitivity
-*/
-
-void QCameraExposure::setAutoIsoSensitivity()
-{
- d_func()->resetExposureParameter(QCameraExposureControl::ISO);
-}
-
-/*!
- \property QCameraExposure::shutterSpeed
- \brief Camera's shutter speed in seconds.
-
- \sa supportedShutterSpeeds(), setAutoShutterSpeed(), setManualShutterSpeed()
-*/
-
-/*!
- \fn QCameraExposure::shutterSpeedChanged(qreal speed)
-
- Signals that a camera's shutter \a speed has changed.
-*/
-
-/*!
- \property QCameraExposure::isoSensitivity
- \brief The sensor ISO sensitivity.
-
- \sa supportedIsoSensitivities(), setAutoIsoSensitivity(), setManualIsoSensitivity()
-*/
-
-/*!
- \property QCameraExposure::aperture
- \brief Lens aperture is specified as an F number, the ratio of the focal length to effective aperture diameter.
-
- \sa supportedApertures(), setAutoAperture(), setManualAperture(), requestedAperture()
-*/
-
-
-qreal QCameraExposure::aperture() const
-{
- return d_func()->actualExposureParameter<qreal>(QCameraExposureControl::Aperture, -1.0);
-}
-
-/*!
- Returns the requested manual aperture
- or -1.0 if automatic aperture is turned on.
-*/
-qreal QCameraExposure::requestedAperture() const
-{
- return d_func()->requestedExposureParameter<qreal>(QCameraExposureControl::Aperture, -1.0);
-}
-
-
-/*!
- Returns the list of aperture values camera supports.
- The apertures list can change depending on the focal length,
- in such a case the apertureRangeChanged() signal is emitted.
-
- If the camera supports arbitrary aperture values within the supported range,
- *\a continuous is set to true, otherwise *\a continuous is set to false.
-*/
-QList<qreal> QCameraExposure::supportedApertures(bool * continuous) const
-{
- QList<qreal> res;
- QCameraExposureControl *control = d_func()->exposureControl;
-
- bool tmp = false;
- if (!continuous)
- continuous = &tmp;
-
- if (!control)
- return res;
-
- const auto range = control->supportedParameterRange(QCameraExposureControl::Aperture, continuous);
- for (const QVariant &value : range) {
- bool ok = false;
- qreal realValue = value.toReal(&ok);
- if (ok)
- res.append(realValue);
- else
- qWarning() << "Incompatible aperture value type, qreal is expected";
- }
-
- return res;
-}
-
-/*!
- \fn QCameraExposure::setManualAperture(qreal aperture)
- Sets the manual camera \a aperture value.
-*/
-
-void QCameraExposure::setManualAperture(qreal aperture)
-{
- d_func()->setExposureParameter<qreal>(QCameraExposureControl::Aperture, aperture);
-}
-
-/*!
- \fn QCameraExposure::setAutoAperture()
- Turn on auto aperture
-*/
-
-void QCameraExposure::setAutoAperture()
-{
- d_func()->resetExposureParameter(QCameraExposureControl::Aperture);
-}
-
-/*!
- Returns the current shutter speed in seconds.
-*/
-
-qreal QCameraExposure::shutterSpeed() const
-{
- return d_func()->actualExposureParameter<qreal>(QCameraExposureControl::ShutterSpeed, -1.0);
-}
-
-/*!
- Returns the requested manual shutter speed in seconds
- or -1.0 if automatic shutter speed is turned on.
-*/
-qreal QCameraExposure::requestedShutterSpeed() const
-{
- return d_func()->requestedExposureParameter<qreal>(QCameraExposureControl::ShutterSpeed, -1.0);
-}
-
-/*!
- Returns the list of shutter speed values in seconds camera supports.
-
- If the camera supports arbitrary shutter speed values within the supported range,
- *\a continuous is set to true, otherwise *\a continuous is set to false.
-*/
-QList<qreal> QCameraExposure::supportedShutterSpeeds(bool *continuous) const
-{
- QList<qreal> res;
- QCameraExposureControl *control = d_func()->exposureControl;
-
- bool tmp = false;
- if (!continuous)
- continuous = &tmp;
-
- if (!control)
- return res;
-
- const auto range = control->supportedParameterRange(QCameraExposureControl::ShutterSpeed, continuous);
- for (const QVariant &value : range) {
- bool ok = false;
- qreal realValue = value.toReal(&ok);
- if (ok)
- res.append(realValue);
- else
- qWarning() << "Incompatible shutter speed value type, qreal is expected";
- }
-
- return res;
-}
-
-/*!
- Set the manual shutter speed to \a seconds
-*/
-
-void QCameraExposure::setManualShutterSpeed(qreal seconds)
-{
- d_func()->setExposureParameter<qreal>(QCameraExposureControl::ShutterSpeed, seconds);
-}
-
-/*!
- Turn on auto shutter speed
-*/
-
-void QCameraExposure::setAutoShutterSpeed()
-{
- d_func()->resetExposureParameter(QCameraExposureControl::ShutterSpeed);
-}
-
-
-/*!
- \enum QCameraExposure::FlashMode
-
- \value FlashAuto Automatic flash.
- \value FlashOff Flash is Off.
- \value FlashOn Flash is On.
- \value FlashRedEyeReduction Red eye reduction flash.
- \value FlashFill Use flash to fillin shadows.
- \value FlashTorch Constant light source. If supported,
- torch can be enabled without loading the camera.
- \value FlashVideoLight Constant light source, useful for video capture.
- The light is turned on only while camera is active.
- \value FlashSlowSyncFrontCurtain
- Use the flash in conjunction with a slow shutter speed.
- This mode allows better exposure of distant objects and/or motion blur effect.
- \value FlashSlowSyncRearCurtain
- The similar mode to FlashSlowSyncFrontCurtain but flash is fired at the end of exposure.
- \value FlashManual Flash power is manualy set.
-*/
-
-/*!
- \enum QCameraExposure::ExposureMode
-
- \value ExposureAuto Automatic mode.
- \value ExposureManual Manual mode.
- \value ExposurePortrait Portrait exposure mode.
- \value ExposureNight Night mode.
- \value ExposureBacklight Backlight exposure mode.
- \value ExposureSpotlight Spotlight exposure mode.
- \value ExposureSports Spots exposure mode.
- \value ExposureSnow Snow exposure mode.
- \value ExposureBeach Beach exposure mode.
- \value ExposureLargeAperture Use larger aperture with small depth of field.
- \value ExposureSmallAperture Use smaller aperture.
- \value ExposureAction Action mode. Since 5.5
- \value ExposureLandscape Landscape mode. Since 5.5
- \value ExposureNightPortrait Night portrait mode. Since 5.5
- \value ExposureTheatre Theatre mode. Since 5.5
- \value ExposureSunset Sunset mode. Since 5.5
- \value ExposureSteadyPhoto Steady photo mode. Since 5.5
- \value ExposureFireworks Fireworks mode. Since 5.5
- \value ExposureParty Party mode. Since 5.5
- \value ExposureCandlelight Candlelight mode. Since 5.5
- \value ExposureBarcode Barcode mode. Since 5.5
- \value ExposureModeVendor The base value for device specific exposure modes.
-*/
-
-/*!
- \enum QCameraExposure::MeteringMode
-
- \value MeteringMatrix Matrix metering mode.
- \value MeteringAverage Center weighted average metering mode.
- \value MeteringSpot Spot metering mode.
-*/
-
-/*!
- \property QCameraExposure::flashReady
- \brief Indicates if the flash is charged and ready to use.
-*/
-
-/*!
- \fn void QCameraExposure::flashReady(bool ready)
-
- Signal the flash \a ready status has changed.
-*/
-
-/*!
- \fn void QCameraExposure::apertureChanged(qreal value)
-
- Signal emitted when aperature changes to \a value.
-*/
-
-/*!
- \fn void QCameraExposure::apertureRangeChanged()
-
- Signal emitted when aperature range has changed.
-*/
-
-
-/*!
- \fn void QCameraExposure::shutterSpeedRangeChanged()
-
- Signal emitted when the shutter speed range has changed.
-*/
-
-
-/*!
- \fn void QCameraExposure::isoSensitivityChanged(int value)
-
- Signal emitted when sensitivity changes to \a value.
-*/
-
-/*!
- \fn void QCameraExposure::exposureCompensationChanged(qreal value)
-
- Signal emitted when the exposure compensation changes to \a value.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcameraexposure.cpp"
diff --git a/src/multimedia/camera/qcameraexposure.h b/src/multimedia/camera/qcameraexposure.h
deleted file mode 100644
index a1dc96701..000000000
--- a/src/multimedia/camera/qcameraexposure.h
+++ /dev/null
@@ -1,195 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAEXPOSURE_H
-#define QCAMERAEXPOSURE_H
-
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmediaenumdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QCamera;
-class QCameraExposurePrivate;
-
-class Q_MULTIMEDIA_EXPORT QCameraExposure : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(qreal aperture READ aperture NOTIFY apertureChanged)
- Q_PROPERTY(qreal shutterSpeed READ shutterSpeed NOTIFY shutterSpeedChanged)
- Q_PROPERTY(int isoSensitivity READ isoSensitivity NOTIFY isoSensitivityChanged)
- Q_PROPERTY(qreal exposureCompensation READ exposureCompensation WRITE setExposureCompensation NOTIFY exposureCompensationChanged)
- Q_PROPERTY(bool flashReady READ isFlashReady NOTIFY flashReady)
- Q_PROPERTY(QCameraExposure::FlashModes flashMode READ flashMode WRITE setFlashMode)
- Q_PROPERTY(QCameraExposure::ExposureMode exposureMode READ exposureMode WRITE setExposureMode)
- Q_PROPERTY(QCameraExposure::MeteringMode meteringMode READ meteringMode WRITE setMeteringMode)
-
- Q_ENUMS(FlashMode)
- Q_ENUMS(ExposureMode)
- Q_ENUMS(MeteringMode)
-public:
- enum FlashMode {
- FlashAuto = 0x1,
- FlashOff = 0x2,
- FlashOn = 0x4,
- FlashRedEyeReduction = 0x8,
- FlashFill = 0x10,
- FlashTorch = 0x20,
- FlashVideoLight = 0x40,
- FlashSlowSyncFrontCurtain = 0x80,
- FlashSlowSyncRearCurtain = 0x100,
- FlashManual = 0x200
- };
- Q_DECLARE_FLAGS(FlashModes, FlashMode)
-
- enum ExposureMode {
- ExposureAuto = 0,
- ExposureManual = 1,
- ExposurePortrait = 2,
- ExposureNight = 3,
- ExposureBacklight = 4,
- ExposureSpotlight = 5,
- ExposureSports = 6,
- ExposureSnow = 7,
- ExposureBeach = 8,
- ExposureLargeAperture = 9,
- ExposureSmallAperture = 10,
- ExposureAction = 11,
- ExposureLandscape = 12,
- ExposureNightPortrait = 13,
- ExposureTheatre = 14,
- ExposureSunset = 15,
- ExposureSteadyPhoto = 16,
- ExposureFireworks = 17,
- ExposureParty = 18,
- ExposureCandlelight = 19,
- ExposureBarcode = 20,
- ExposureModeVendor = 1000
- };
-
- enum MeteringMode {
- MeteringMatrix = 1,
- MeteringAverage = 2,
- MeteringSpot = 3
- };
-
- bool isAvailable() const;
-
- FlashModes flashMode() const;
- bool isFlashModeSupported(FlashModes mode) const;
- bool isFlashReady() const;
-
- ExposureMode exposureMode() const;
- bool isExposureModeSupported(ExposureMode mode) const;
-
- qreal exposureCompensation() const;
-
- MeteringMode meteringMode() const;
- bool isMeteringModeSupported(MeteringMode mode) const;
-
- QPointF spotMeteringPoint() const;
- void setSpotMeteringPoint(const QPointF &point);
-
- int isoSensitivity() const;
- qreal aperture() const;
- qreal shutterSpeed() const;
-
- int requestedIsoSensitivity() const;
- qreal requestedAperture() const;
- qreal requestedShutterSpeed() const;
-
- QList<int> supportedIsoSensitivities(bool *continuous = nullptr) const;
- QList<qreal> supportedApertures(bool *continuous = nullptr) const;
- QList<qreal> supportedShutterSpeeds(bool *continuous = nullptr) const;
-
-public Q_SLOTS:
- void setFlashMode(FlashModes mode);
- void setExposureMode(ExposureMode mode);
- void setMeteringMode(MeteringMode mode);
-
- void setExposureCompensation(qreal ev);
-
- void setManualIsoSensitivity(int iso);
- void setAutoIsoSensitivity();
-
- void setManualAperture(qreal aperture);
- void setAutoAperture();
-
- void setManualShutterSpeed(qreal seconds);
- void setAutoShutterSpeed();
-
-Q_SIGNALS:
- void flashReady(bool);
-
- void apertureChanged(qreal);
- void apertureRangeChanged();
- void shutterSpeedChanged(qreal speed);
- void shutterSpeedRangeChanged();
- void isoSensitivityChanged(int);
- void exposureCompensationChanged(qreal);
-
-protected:
- virtual ~QCameraExposure();
-
-private:
- friend class QCamera;
- friend class QCameraPrivate;
- explicit QCameraExposure(QCamera *parent = nullptr);
-
- Q_DISABLE_COPY(QCameraExposure)
- Q_DECLARE_PRIVATE(QCameraExposure)
- Q_PRIVATE_SLOT(d_func(), void _q_exposureParameterChanged(int))
- Q_PRIVATE_SLOT(d_func(), void _q_exposureParameterRangeChanged(int))
- QCameraExposurePrivate *d_ptr;
-};
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(QCameraExposure::FlashModes)
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QCameraExposure::ExposureMode)
-Q_DECLARE_METATYPE(QCameraExposure::FlashModes)
-Q_DECLARE_METATYPE(QCameraExposure::MeteringMode)
-
-Q_MEDIA_ENUM_DEBUG(QCameraExposure, ExposureMode)
-Q_MEDIA_ENUM_DEBUG(QCameraExposure, FlashMode)
-Q_MEDIA_ENUM_DEBUG(QCameraExposure, MeteringMode)
-
-#endif // QCAMERAEXPOSURE_H
diff --git a/src/multimedia/camera/qcamerafocus.cpp b/src/multimedia/camera/qcamerafocus.cpp
deleted file mode 100644
index 980b9dc93..000000000
--- a/src/multimedia/camera/qcamerafocus.cpp
+++ /dev/null
@@ -1,614 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qcamerafocus.h"
-#include "qmediaobject_p.h"
-
-#include <qcamera.h>
-#include <qcameracontrol.h>
-#include <qcameraexposurecontrol.h>
-#include <qcamerafocuscontrol.h>
-#include <qcamerazoomcontrol.h>
-#include <qmediarecordercontrol.h>
-#include <qcameraimagecapturecontrol.h>
-#include <qvideodeviceselectorcontrol.h>
-
-#include <QtCore/QDebug>
-
-QT_BEGIN_NAMESPACE
-
-static void qRegisterCameraFocusMetaTypes()
-{
- qRegisterMetaType<QCameraFocus::FocusModes>("QCameraFocus::FocusModes");
- qRegisterMetaType<QCameraFocus::FocusPointMode>("QCameraFocus::FocusPointMode");
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterCameraFocusMetaTypes)
-
-
-class QCameraFocusFakeZoomControl : public QCameraZoomControl
-{
-public:
- QCameraFocusFakeZoomControl(QObject *parent) :
- QCameraZoomControl(parent) {}
-
- qreal maximumOpticalZoom() const override { return 1.0; }
- qreal maximumDigitalZoom() const override { return 1.0; }
-
- qreal requestedOpticalZoom() const override { return 1.0; }
- qreal requestedDigitalZoom() const override { return 1.0; }
- qreal currentOpticalZoom() const override { return 1.0; }
- qreal currentDigitalZoom() const override { return 1.0; }
-
- void zoomTo(qreal, qreal) override { qWarning("The camera doesn't support zooming."); }
-};
-
-class QCameraFocusFakeFocusControl : public QCameraFocusControl
-{
-public:
- QCameraFocusFakeFocusControl(QObject *parent) :
- QCameraFocusControl(parent) {}
-
- QCameraFocus::FocusModes focusMode() const override { return QCameraFocus::AutoFocus; }
- void setFocusMode(QCameraFocus::FocusModes) override { qWarning("Focus mode selection is not supported"); }
- bool isFocusModeSupported(QCameraFocus::FocusModes) const override { return false; }
-
- QCameraFocus::FocusPointMode focusPointMode() const override { return QCameraFocus::FocusPointAuto; }
- void setFocusPointMode(QCameraFocus::FocusPointMode) override { qWarning("Focus points mode selection is not supported"); }
- bool isFocusPointModeSupported(QCameraFocus::FocusPointMode) const override { return false; }
- QPointF customFocusPoint() const override { return QPointF(0.5,0.5); }
- void setCustomFocusPoint(const QPointF &) override { qWarning("Focus points selection is not supported"); }
-
- QCameraFocusZoneList focusZones() const override { return QCameraFocusZoneList(); }
-};
-
-
-
-class QCameraFocusZoneData : public QSharedData
-{
-public:
- QCameraFocusZoneData():
- status(QCameraFocusZone::Invalid)
- {
-
- }
-
- QCameraFocusZoneData(const QRectF &_area, QCameraFocusZone::FocusZoneStatus _status):
- area(_area),
- status(_status)
- {
-
- }
-
-
- QCameraFocusZoneData(const QCameraFocusZoneData &other):
- QSharedData(other),
- area(other.area),
- status(other.status)
- {
- }
-
- QCameraFocusZoneData& operator=(const QCameraFocusZoneData &other)
- {
- area = other.area;
- status = other.status;
- return *this;
- }
-
- QRectF area;
- QCameraFocusZone::FocusZoneStatus status;
-};
-
-
-/*!
- \class QCameraFocusZone
-
- \brief The QCameraFocusZone class provides information on zones used for autofocusing a camera.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_camera
-
- For cameras that support autofocusing, in order for a camera to autofocus on
- part of a sensor frame, it considers different zones within the frame. Which
- zones to use, and where the zones are located vary between different cameras.
-
- This class exposes what zones are used by a particular camera, and a list of the
- zones can be retrieved by a \l QCameraFocus instance.
-
- You can use this information to present visual feedback - for example, drawing
- rectangles around areas of the camera frame that are in focus, or changing the
- color of a zone as it comes into focus.
-
- \snippet multimedia-snippets/camera.cpp Camera focus zones
-
- \sa QCameraFocus
-*/
-
-/*!
- \enum QCameraFocusZone::FocusZoneStatus
-
- \value Invalid This zone is not valid
- \value Unused This zone may be used for autofocusing, but is not currently.
- \value Selected This zone is currently being used for autofocusing, but is not in focus.
- \value Focused This zone is being used for autofocusing and is currently in focus.
-*/
-
-/*!
- * \internal
- * Creates a new, empty QCameraFocusZone.
- */
-QCameraFocusZone::QCameraFocusZone()
- :d(new QCameraFocusZoneData)
-{
-
-}
-
-/*!
- * \internal
- * Creates a new QCameraFocusZone with the supplied \a area and \a status.
- */
-QCameraFocusZone::QCameraFocusZone(const QRectF &area, QCameraFocusZone::FocusZoneStatus status)
- :d(new QCameraFocusZoneData(area, status))
-{
-}
-
-/*!
- * Creates a new QCameraFocusZone as a copy of \a other.
- */
-QCameraFocusZone::QCameraFocusZone(const QCameraFocusZone &other)
- :d(other.d)
-{
-
-}
-
-/*!
- * Destroys this QCameraFocusZone.
- */
-QCameraFocusZone::~QCameraFocusZone()
-{
-
-}
-
-/*!
- * Assigns \a other to this QCameraFocusZone.
- */
-QCameraFocusZone& QCameraFocusZone::operator=(const QCameraFocusZone &other)
-{
- d = other.d;
- return *this;
-}
-
-/*!
- * Returns true if this focus zone is the same as \a other.
- */
-bool QCameraFocusZone::operator==(const QCameraFocusZone &other) const
-{
- return d == other.d ||
- (d->area == other.d->area && d->status == other.d->status);
-}
-
-/*!
- * Returns true if this focus zone is not the same as \a other.
- */
-bool QCameraFocusZone::operator!=(const QCameraFocusZone &other) const
-{
- return !(*this == other);
-}
-
-/*!
- * Returns true if this focus zone has a valid area and status.
- */
-bool QCameraFocusZone::isValid() const
-{
- return d->status != Invalid && !d->area.isValid();
-}
-
-/*!
- * Returns the area of the camera frame that this focus zone encompasses.
- *
- * Coordinates are in frame relative coordinates - \c QPointF(0,0) is the top
- * left of the frame, and \c QPointF(1,1) is the bottom right.
- */
-QRectF QCameraFocusZone::area() const
-{
- return d->area;
-}
-
-/*!
- * Returns the current status of this focus zone.
- */
-QCameraFocusZone::FocusZoneStatus QCameraFocusZone::status() const
-{
- return d->status;
-}
-
-/*!
- * \internal
- * Sets the current status of this focus zone to \a status.
- */
-void QCameraFocusZone::setStatus(QCameraFocusZone::FocusZoneStatus status)
-{
- d->status = status;
-}
-
-
-/*!
- \class QCameraFocus
-
- \brief The QCameraFocus class provides an interface for focus and zoom related camera settings.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_camera
-
- On hardware that supports it, this class lets you adjust the focus
- or zoom (both optical and digital). This also includes things
- like "Macro" mode for close up work (e.g. reading barcodes, or
- recognising letters), or "touch to focus" - indicating an
- interesting area of the viewfinder for the hardware to attempt
- to focus on.
-
- \snippet multimedia-snippets/camera.cpp Camera custom zoom
-
- Zooming can be accomplished in a number of ways - usually the more
- expensive but higher quality approach is an optical zoom, which allows
- using the full extent of the camera sensor to gather image pixels. In
- addition it is possible to digitally zoom, which will generally just
- enlarge part of the sensor frame and throw away other parts. If the
- camera hardware supports optical zoom this should generally always
- be used first. The \l maximumOpticalZoom() method allows this to be
- checked. The \l zoomTo() method allows changing both optical and
- digital zoom at once.
-
- \snippet multimedia-snippets/camera.cpp Camera combined zoom
-
- \section2 Some notes on autofocus
- Some hardware supports a movable focus lens assembly, and typically
- this hardware also supports automatically focusing via some heuristic.
- You can influence this via the \l FocusPointMode setting - typically
- the center of the frame is brought into focus, but some hardware
- also supports focusing on any faces detected in the frame, or on
- a specific point (usually provided by a user in a "touch to focus"
- scenario).
-
- This class (in combination with \l QCameraFocusZone)
- can expose information on what parts of the camera sensor image
- are in focus or are being used for autofocusing via the \l focusZones()
- property:
-
- \snippet multimedia-snippets/camera.cpp Camera focus zones
-
- \sa QCameraFocusZone
-*/
-
-
-class QCameraFocusPrivate : public QMediaObjectPrivate
-{
- Q_DECLARE_NON_CONST_PUBLIC(QCameraFocus)
-public:
- void initControls();
-
- QCamera *camera;
-
- QCameraFocusControl *focusControl;
- QCameraZoomControl *zoomControl;
- bool available;
-};
-
-
-void QCameraFocusPrivate::initControls()
-{
- Q_Q(QCameraFocus);
-
- focusControl = nullptr;
- zoomControl = nullptr;
-
- QMediaService *service = camera->service();
- if (service) {
- focusControl = qobject_cast<QCameraFocusControl *>(service->requestControl(QCameraFocusControl_iid));
- zoomControl = qobject_cast<QCameraZoomControl *>(service->requestControl(QCameraZoomControl_iid));
- }
-
- available = focusControl != nullptr;
-
- if (!focusControl)
- focusControl = new QCameraFocusFakeFocusControl(q);
-
- if (!zoomControl)
- zoomControl = new QCameraFocusFakeZoomControl(q);
-
- q->connect(focusControl, SIGNAL(focusZonesChanged()), q, SIGNAL(focusZonesChanged()));
-
- q->connect(zoomControl, SIGNAL(currentOpticalZoomChanged(qreal)),
- q, SIGNAL(opticalZoomChanged(qreal)));
- q->connect(zoomControl, SIGNAL(currentDigitalZoomChanged(qreal)),
- q, SIGNAL(digitalZoomChanged(qreal)));
- q->connect(zoomControl, SIGNAL(maximumOpticalZoomChanged(qreal)),
- q, SIGNAL(maximumOpticalZoomChanged(qreal)));
- q->connect(zoomControl, SIGNAL(maximumDigitalZoomChanged(qreal)),
- q, SIGNAL(maximumDigitalZoomChanged(qreal)));
-}
-
-/*!
- \internal
- Construct a QCameraFocus for \a camera.
-*/
-
-QCameraFocus::QCameraFocus(QCamera *camera)
- : QObject(*new QCameraFocusPrivate, camera)
-{
- Q_D(QCameraFocus);
- d->camera = camera;
- d->initControls();
-}
-
-
-/*!
- Destroys the camera focus object.
-*/
-
-QCameraFocus::~QCameraFocus()
-{
-}
-
-/*!
- Returns true if focus related settings are supported by this camera.
-
- You may need to also check if any specific features are supported.
-*/
-bool QCameraFocus::isAvailable() const
-{
- return d_func()->available;
-}
-
-/*!
- \property QCameraFocus::focusMode
- \brief the current camera focus mode.
-
-
- This controls the way the camera lens assembly is configured.
-
- \sa QCameraFocus::isFocusModeSupported()
-*/
-
-QCameraFocus::FocusModes QCameraFocus::focusMode() const
-{
- return d_func()->focusControl->focusMode();
-}
-
-void QCameraFocus::setFocusMode(QCameraFocus::FocusModes mode)
-{
- d_func()->focusControl->setFocusMode(mode);
-}
-
-/*!
- Returns true if the focus \a mode is supported by camera.
-*/
-
-bool QCameraFocus::isFocusModeSupported(FocusModes mode) const
-{
- return d_func()->focusControl->isFocusModeSupported(mode);
-}
-
-/*!
- \property QCameraFocus::focusPointMode
- \brief the current camera focus point selection mode.
-
- If the camera focus mode is set to use an autofocusing mode,
- this property controls the way the camera will select areas
- of the frame to use for autofocusing.
-
- \sa QCameraFocus::isFocusPointModeSupported()
-*/
-
-QCameraFocus::FocusPointMode QCameraFocus::focusPointMode() const
-{
- return d_func()->focusControl->focusPointMode();
-}
-
-void QCameraFocus::setFocusPointMode(QCameraFocus::FocusPointMode mode)
-{
- d_func()->focusControl->setFocusPointMode(mode);
-}
-
-/*!
- Returns true if focus point \a mode is supported.
- */
-bool QCameraFocus::isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const
-{
- return d_func()->focusControl->isFocusPointModeSupported(mode);
-}
-
-/*!
- \property QCameraFocus::customFocusPoint
-
- This property represents the position of the custom focus point, in relative frame coordinates:
- QPointF(0,0) points to the left top frame point, QPointF(0.5,0.5) points to the frame center.
-
- The custom focus point property is used only in \c FocusPointCustom focus mode.
- */
-
-QPointF QCameraFocus::customFocusPoint() const
-{
- return d_func()->focusControl->customFocusPoint();
-}
-
-void QCameraFocus::setCustomFocusPoint(const QPointF &point)
-{
- d_func()->focusControl->setCustomFocusPoint(point);
-}
-
-/*!
- \property QCameraFocus::focusZones
-
- Returns the list of active focus zones.
-
- If QCamera::FocusPointAuto or QCamera::FocusPointFaceDetection focus mode is selected
- this method returns the list of zones the camera is actually focused on.
-
- The coordinates system is the same as for custom focus points:
- QPointF(0,0) points to the left top frame point, QPointF(0.5,0.5) points to the frame center.
- */
-QCameraFocusZoneList QCameraFocus::focusZones() const
-{
- return d_func()->focusControl->focusZones();
-}
-
-/*!
- Returns the maximum optical zoom.
-
- This will be \c 1.0 on cameras that do not support optical zoom.
-*/
-
-qreal QCameraFocus::maximumOpticalZoom() const
-{
- return d_func()->zoomControl->maximumOpticalZoom();
-}
-
-/*!
- Returns the maximum digital zoom
-
- This will be \c 1.0 on cameras that do not support digital zoom.
-*/
-
-qreal QCameraFocus::maximumDigitalZoom() const
-{
- return d_func()->zoomControl->maximumDigitalZoom();
-}
-
-/*!
- \property QCameraFocus::opticalZoom
- \brief the current optical zoom value.
-
- \sa QCameraFocus::digitalZoom
-*/
-
-qreal QCameraFocus::opticalZoom() const
-{
- return d_func()->zoomControl->currentOpticalZoom();
-}
-
-/*!
- \property QCameraFocus::digitalZoom
- \brief the current digital zoom value.
-
- \sa QCameraFocus::opticalZoom
-*/
-qreal QCameraFocus::digitalZoom() const
-{
- return d_func()->zoomControl->currentDigitalZoom();
-}
-
-
-/*!
- Set the camera \a optical and \a digital zoom values.
-
- Since there may be a physical component to move, the change in
- zoom value may not be instantaneous.
-
-*/
-void QCameraFocus::zoomTo(qreal optical, qreal digital)
-{
- d_func()->zoomControl->zoomTo(optical, digital);
-}
-
-/*!
- \enum QCameraFocus::FocusMode
-
- \value ManualFocus Manual or fixed focus mode.
- \value HyperfocalFocus Focus to hyperfocal distance, with the maximum depth of field achieved.
- All objects at distances from half of this
- distance out to infinity will be acceptably sharp.
- \value InfinityFocus Focus strictly to infinity.
- \value AutoFocus One-shot auto focus mode.
- \value ContinuousFocus Continuous auto focus mode.
- \value MacroFocus One shot auto focus to objects close to camera.
-*/
-
-/*!
- \enum QCameraFocus::FocusPointMode
-
- \value FocusPointAuto Automatically select one or multiple focus points.
- \value FocusPointCenter Focus to the frame center.
- \value FocusPointFaceDetection Focus on faces in the frame.
- \value FocusPointCustom Focus to the custom point, defined by QCameraFocus::customFocusPoint property.
-*/
-
-/*!
- \fn void QCameraFocus::opticalZoomChanged(qreal value)
-
- Signal emitted when optical zoom value changes to new \a value.
-*/
-
-/*!
- \fn void QCameraFocus::digitalZoomChanged(qreal value)
-
- Signal emitted when digital zoom value changes to new \a value.
-*/
-
-/*!
- \fn void QCameraFocus::maximumOpticalZoomChanged(qreal zoom)
-
- Signal emitted when the maximum supported optical \a zoom value changed.
-*/
-
-/*!
- \fn void QCameraFocus::maximumDigitalZoomChanged(qreal zoom)
-
- Signal emitted when the maximum supported digital \a zoom value changed.
-
- The maximum supported zoom value can depend on other camera settings,
- like capture mode or resolution.
-*/
-
-
-
-/*!
- \fn QCameraFocus::focusZonesChanged()
-
- This signal is emitted when the set of zones used in autofocusing is changed.
-
- This can change when a zone is focused or loses focus, or new focus zones
- have been detected.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcamerafocus.cpp"
diff --git a/src/multimedia/camera/qcamerafocus.h b/src/multimedia/camera/qcamerafocus.h
deleted file mode 100644
index 11639c3da..000000000
--- a/src/multimedia/camera/qcamerafocus.h
+++ /dev/null
@@ -1,177 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAFOCUS_H
-#define QCAMERAFOCUS_H
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qpair.h>
-#include <QtCore/qsize.h>
-#include <QtCore/qpoint.h>
-#include <QtCore/qrect.h>
-#include <QtCore/qshareddata.h>
-
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmediaenumdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QCamera;
-
-class QCameraFocusZoneData;
-
-class Q_MULTIMEDIA_EXPORT QCameraFocusZone {
-public:
- enum FocusZoneStatus {
- Invalid,
- Unused,
- Selected,
- Focused
- };
-
- QCameraFocusZone();
- QCameraFocusZone(const QRectF &area, FocusZoneStatus status = Selected);
- QCameraFocusZone(const QCameraFocusZone &other);
-
- QCameraFocusZone& operator=(const QCameraFocusZone &other);
- bool operator==(const QCameraFocusZone &other) const;
- bool operator!=(const QCameraFocusZone &other) const;
-
- ~QCameraFocusZone();
-
- bool isValid() const;
-
- QRectF area() const;
-
- FocusZoneStatus status() const;
- void setStatus(FocusZoneStatus status);
-
-private:
- QSharedDataPointer<QCameraFocusZoneData> d;
-};
-
-typedef QList<QCameraFocusZone> QCameraFocusZoneList;
-
-
-class QCameraFocusPrivate;
-class Q_MULTIMEDIA_EXPORT QCameraFocus : public QObject
-{
- Q_OBJECT
-
- Q_PROPERTY(FocusModes focusMode READ focusMode WRITE setFocusMode)
- Q_PROPERTY(FocusPointMode focusPointMode READ focusPointMode WRITE setFocusPointMode)
- Q_PROPERTY(QPointF customFocusPoint READ customFocusPoint WRITE setCustomFocusPoint)
- Q_PROPERTY(QCameraFocusZoneList focusZones READ focusZones NOTIFY focusZonesChanged)
- Q_PROPERTY(qreal opticalZoom READ opticalZoom NOTIFY opticalZoomChanged)
- Q_PROPERTY(qreal digitalZoom READ digitalZoom NOTIFY digitalZoomChanged)
-
- Q_ENUMS(FocusMode)
- Q_ENUMS(FocusPointMode)
-public:
- enum FocusMode {
- ManualFocus = 0x1,
- HyperfocalFocus = 0x02,
- InfinityFocus = 0x04,
- AutoFocus = 0x8,
- ContinuousFocus = 0x10,
- MacroFocus = 0x20
- };
- Q_DECLARE_FLAGS(FocusModes, FocusMode)
-
- enum FocusPointMode {
- FocusPointAuto,
- FocusPointCenter,
- FocusPointFaceDetection,
- FocusPointCustom
- };
-
- bool isAvailable() const;
-
- FocusModes focusMode() const;
- void setFocusMode(FocusModes mode);
- bool isFocusModeSupported(FocusModes mode) const;
-
- FocusPointMode focusPointMode() const;
- void setFocusPointMode(FocusPointMode mode);
- bool isFocusPointModeSupported(FocusPointMode) const;
- QPointF customFocusPoint() const;
- void setCustomFocusPoint(const QPointF &point);
-
- QCameraFocusZoneList focusZones() const;
-
- qreal maximumOpticalZoom() const;
- qreal maximumDigitalZoom() const;
- qreal opticalZoom() const;
- qreal digitalZoom() const;
-
- void zoomTo(qreal opticalZoom, qreal digitalZoom);
-
-Q_SIGNALS:
- void opticalZoomChanged(qreal);
- void digitalZoomChanged(qreal);
-
- void focusZonesChanged();
-
- void maximumOpticalZoomChanged(qreal);
- void maximumDigitalZoomChanged(qreal);
-
-protected:
- ~QCameraFocus();
-
-private:
- friend class QCamera;
- friend class QCameraPrivate;
- QCameraFocus(QCamera *camera);
-
- Q_DISABLE_COPY(QCameraFocus)
- Q_DECLARE_PRIVATE(QCameraFocus)
-};
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(QCameraFocus::FocusModes)
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QCameraFocus::FocusModes)
-Q_DECLARE_METATYPE(QCameraFocus::FocusPointMode)
-
-Q_MEDIA_ENUM_DEBUG(QCameraFocus, FocusMode)
-Q_MEDIA_ENUM_DEBUG(QCameraFocus, FocusPointMode)
-
-#endif // QCAMERAFOCUS_H
diff --git a/src/multimedia/camera/qcameraimagecapture.cpp b/src/multimedia/camera/qcameraimagecapture.cpp
deleted file mode 100644
index 7eb67daed..000000000
--- a/src/multimedia/camera/qcameraimagecapture.cpp
+++ /dev/null
@@ -1,651 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include <qcameraimagecapture.h>
-#include <qcameraimagecapturecontrol.h>
-#include <qmediaencodersettings.h>
-#include <qcameracapturedestinationcontrol.h>
-#include <qcameracapturebufferformatcontrol.h>
-
-#include <qimageencodercontrol.h>
-#include "qmediaobject_p.h"
-#include <qmediaservice.h>
-#include <qcamera.h>
-#include <qcameracontrol.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmetaobject.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraImageCapture
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_camera
-
-
- \brief The QCameraImageCapture class is used for the recording of media content.
-
- The QCameraImageCapture class is a high level images recording class.
- It's not intended to be used alone but for accessing the media
- recording functions of other media objects, like QCamera.
-
- \snippet multimedia-snippets/camera.cpp Camera
-
- \snippet multimedia-snippets/camera.cpp Camera keys
-
- \sa QCamera
-*/
-
-/*!
- \enum QCameraImageCapture::CaptureDestination
-
- \value CaptureToFile Capture the image to a file.
- \value CaptureToBuffer Capture the image to a buffer for further processing.
-*/
-
-static void qRegisterCameraImageCaptureMetaTypes()
-{
- qRegisterMetaType<QCameraImageCapture::Error>("QCameraImageCapture::Error");
- qRegisterMetaType<QCameraImageCapture::CaptureDestination>("QCameraImageCapture::CaptureDestination");
- qRegisterMetaType<QCameraImageCapture::CaptureDestinations>("QCameraImageCapture::CaptureDestinations");
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterCameraImageCaptureMetaTypes)
-
-
-class QCameraImageCapturePrivate
-{
- Q_DECLARE_NON_CONST_PUBLIC(QCameraImageCapture)
-public:
- QCameraImageCapturePrivate();
-
- QMediaObject *mediaObject;
-
- QCameraImageCaptureControl *control;
- QImageEncoderControl *encoderControl;
- QCameraCaptureDestinationControl *captureDestinationControl;
- QCameraCaptureBufferFormatControl *bufferFormatControl;
-
- QCameraImageCapture::Error error;
- QString errorString;
-
- void _q_error(int id, int error, const QString &errorString);
- void _q_readyChanged(bool);
- void _q_serviceDestroyed();
-
- void unsetError() { error = QCameraImageCapture::NoError; errorString.clear(); }
-
- QCameraImageCapture *q_ptr;
-};
-
-QCameraImageCapturePrivate::QCameraImageCapturePrivate():
- mediaObject(nullptr),
- control(nullptr),
- encoderControl(nullptr),
- captureDestinationControl(nullptr),
- bufferFormatControl(nullptr),
- error(QCameraImageCapture::NoError)
-{
-}
-
-void QCameraImageCapturePrivate::_q_error(int id, int error, const QString &errorString)
-{
- Q_Q(QCameraImageCapture);
-
- this->error = QCameraImageCapture::Error(error);
- this->errorString = errorString;
-
- emit q->error(id, this->error, errorString);
-}
-
-void QCameraImageCapturePrivate::_q_readyChanged(bool ready)
-{
- Q_Q(QCameraImageCapture);
- emit q->readyForCaptureChanged(ready);
-}
-
-void QCameraImageCapturePrivate::_q_serviceDestroyed()
-{
- mediaObject = nullptr;
- control = nullptr;
- encoderControl = nullptr;
- captureDestinationControl = nullptr;
- bufferFormatControl = nullptr;
-}
-
-/*!
- Constructs a media recorder which records the media produced by \a mediaObject.
-
- The \a parent is passed to QMediaObject.
-*/
-
-QCameraImageCapture::QCameraImageCapture(QMediaObject *mediaObject, QObject *parent):
- QObject(parent), d_ptr(new QCameraImageCapturePrivate)
-{
- Q_D(QCameraImageCapture);
-
- d->q_ptr = this;
-
- if (mediaObject)
- mediaObject->bind(this);
-}
-
-/*!
- Destroys images capture object.
-*/
-
-QCameraImageCapture::~QCameraImageCapture()
-{
- Q_D(QCameraImageCapture);
-
- if (d->mediaObject)
- d->mediaObject->unbind(this);
-
- delete d_ptr;
-}
-
-/*!
- \reimp
-*/
-QMediaObject *QCameraImageCapture::mediaObject() const
-{
- return d_func()->mediaObject;
-}
-
-/*!
- \reimp
-*/
-bool QCameraImageCapture::setMediaObject(QMediaObject *mediaObject)
-{
- Q_D(QCameraImageCapture);
-
- if (d->mediaObject) {
- if (d->control) {
- disconnect(d->control, SIGNAL(imageExposed(int)),
- this, SIGNAL(imageExposed(int)));
- disconnect(d->control, SIGNAL(imageCaptured(int,QImage)),
- this, SIGNAL(imageCaptured(int,QImage)));
- disconnect(d->control, SIGNAL(imageAvailable(int,QVideoFrame)),
- this, SIGNAL(imageAvailable(int,QVideoFrame)));
- disconnect(d->control, SIGNAL(imageMetadataAvailable(int,QString,QVariant)),
- this, SIGNAL(imageMetadataAvailable(int,QString,QVariant)));
- disconnect(d->control, SIGNAL(imageSaved(int,QString)),
- this, SIGNAL(imageSaved(int,QString)));
- disconnect(d->control, SIGNAL(readyForCaptureChanged(bool)),
- this, SLOT(_q_readyChanged(bool)));
- disconnect(d->control, SIGNAL(error(int,int,QString)),
- this, SLOT(_q_error(int,int,QString)));
-
- if (d->captureDestinationControl) {
- disconnect(d->captureDestinationControl, SIGNAL(captureDestinationChanged(QCameraImageCapture::CaptureDestinations)),
- this, SIGNAL(captureDestinationChanged(QCameraImageCapture::CaptureDestinations)));
- }
-
- if (d->bufferFormatControl) {
- disconnect(d->bufferFormatControl, SIGNAL(bufferFormatChanged(QVideoFrame::PixelFormat)),
- this, SIGNAL(bufferFormatChanged(QVideoFrame::PixelFormat)));
- }
-
- QMediaService *service = d->mediaObject->service();
- service->releaseControl(d->control);
- if (d->encoderControl)
- service->releaseControl(d->encoderControl);
- if (d->captureDestinationControl)
- service->releaseControl(d->captureDestinationControl);
- if (d->bufferFormatControl)
- service->releaseControl(d->bufferFormatControl);
-
- disconnect(service, SIGNAL(destroyed()), this, SLOT(_q_serviceDestroyed()));
- }
- }
-
- d->mediaObject = mediaObject;
-
- if (d->mediaObject) {
- QMediaService *service = mediaObject->service();
- if (service) {
- d->control = qobject_cast<QCameraImageCaptureControl*>(service->requestControl(QCameraImageCaptureControl_iid));
-
- if (d->control) {
- d->encoderControl = qobject_cast<QImageEncoderControl *>(service->requestControl(QImageEncoderControl_iid));
- d->captureDestinationControl = qobject_cast<QCameraCaptureDestinationControl *>(
- service->requestControl(QCameraCaptureDestinationControl_iid));
- d->bufferFormatControl = qobject_cast<QCameraCaptureBufferFormatControl *>(
- service->requestControl(QCameraCaptureBufferFormatControl_iid));
-
- connect(d->control, SIGNAL(imageExposed(int)),
- this, SIGNAL(imageExposed(int)));
- connect(d->control, SIGNAL(imageCaptured(int,QImage)),
- this, SIGNAL(imageCaptured(int,QImage)));
- connect(d->control, SIGNAL(imageMetadataAvailable(int,QString,QVariant)),
- this, SIGNAL(imageMetadataAvailable(int,QString,QVariant)));
- connect(d->control, SIGNAL(imageAvailable(int,QVideoFrame)),
- this, SIGNAL(imageAvailable(int,QVideoFrame)));
- connect(d->control, SIGNAL(imageSaved(int,QString)),
- this, SIGNAL(imageSaved(int,QString)));
- connect(d->control, SIGNAL(readyForCaptureChanged(bool)),
- this, SLOT(_q_readyChanged(bool)));
- connect(d->control, SIGNAL(error(int,int,QString)),
- this, SLOT(_q_error(int,int,QString)));
-
- if (d->captureDestinationControl) {
- connect(d->captureDestinationControl, SIGNAL(captureDestinationChanged(QCameraImageCapture::CaptureDestinations)),
- this, SIGNAL(captureDestinationChanged(QCameraImageCapture::CaptureDestinations)));
- }
-
- if (d->bufferFormatControl) {
- connect(d->bufferFormatControl, SIGNAL(bufferFormatChanged(QVideoFrame::PixelFormat)),
- this, SIGNAL(bufferFormatChanged(QVideoFrame::PixelFormat)));
- }
-
- connect(service, SIGNAL(destroyed()), this, SLOT(_q_serviceDestroyed()));
-
- return true;
- }
- }
- }
-
- // without QCameraImageCaptureControl discard the media object
- d->mediaObject = nullptr;
- d->control = nullptr;
- d->encoderControl = nullptr;
- d->captureDestinationControl = nullptr;
- d->bufferFormatControl = nullptr;
-
- return false;
-}
-
-/*!
- Returns true if the images capture service ready to use.
-*/
-bool QCameraImageCapture::isAvailable() const
-{
- if (d_func()->control != nullptr)
- return true;
- else
- return false;
-}
-
-/*!
- Returns the availability of this functionality.
-*/
-QMultimedia::AvailabilityStatus QCameraImageCapture::availability() const
-{
- if (d_func()->control != nullptr)
- return QMultimedia::Available;
- else
- return QMultimedia::ServiceMissing;
-}
-
-/*!
- Returns the current error state.
-
- \sa errorString()
-*/
-
-QCameraImageCapture::Error QCameraImageCapture::error() const
-{
- return d_func()->error;
-}
-
-/*!
- Returns a string describing the current error state.
-
- \sa error()
-*/
-
-QString QCameraImageCapture::errorString() const
-{
- return d_func()->errorString;
-}
-
-
-/*!
- Returns a list of supported image codecs.
-*/
-QStringList QCameraImageCapture::supportedImageCodecs() const
-{
- return d_func()->encoderControl ?
- d_func()->encoderControl->supportedImageCodecs() : QStringList();
-}
-
-/*!
- Returns a description of an image \a codec.
-*/
-QString QCameraImageCapture::imageCodecDescription(const QString &codec) const
-{
- return d_func()->encoderControl ?
- d_func()->encoderControl->imageCodecDescription(codec) : QString();
-}
-
-/*!
- Returns a list of resolutions images can be encoded at.
-
- If non null image \a settings parameter is passed,
- the returned list is reduced to resolution supported with partial settings like image codec or quality applied.
-
- If the encoder supports arbitrary resolutions within the supported range,
- *\a continuous is set to true, otherwise *\a continuous is set to false.
-
- \sa QImageEncoderSettings::resolution()
-*/
-QList<QSize> QCameraImageCapture::supportedResolutions(const QImageEncoderSettings &settings, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- return d_func()->encoderControl ?
- d_func()->encoderControl->supportedResolutions(settings, continuous) : QList<QSize>();
-}
-
-/*!
- Returns the image encoder settings being used.
-
- \sa setEncodingSettings()
-*/
-
-QImageEncoderSettings QCameraImageCapture::encodingSettings() const
-{
- return d_func()->encoderControl ?
- d_func()->encoderControl->imageSettings() : QImageEncoderSettings();
-}
-
-/*!
- Sets the image encoding \a settings.
-
- If some parameters are not specified, or null settings are passed,
- the encoder choose the default encoding parameters.
-
- \sa encodingSettings()
-*/
-
-void QCameraImageCapture::setEncodingSettings(const QImageEncoderSettings &settings)
-{
- Q_D(QCameraImageCapture);
-
- if (d->encoderControl) {
- QCamera *camera = qobject_cast<QCamera*>(d->mediaObject);
- if (camera && camera->captureMode() == QCamera::CaptureStillImage) {
- QMetaObject::invokeMethod(camera,
- "_q_preparePropertyChange",
- Qt::DirectConnection,
- Q_ARG(int, QCameraControl::ImageEncodingSettings));
- }
-
- d->encoderControl->setImageSettings(settings);
- }
-}
-
-/*!
- Returns the list of supported buffer image capture formats.
-
- \sa bufferFormat(), setBufferFormat()
-*/
-QList<QVideoFrame::PixelFormat> QCameraImageCapture::supportedBufferFormats() const
-{
- if (d_func()->bufferFormatControl)
- return d_func()->bufferFormatControl->supportedBufferFormats();
- else
- return QList<QVideoFrame::PixelFormat>();
-}
-
-/*!
- Returns the buffer image capture format being used.
-
- \sa supportedBufferFormats(), setBufferFormat()
-*/
-QVideoFrame::PixelFormat QCameraImageCapture::bufferFormat() const
-{
- if (d_func()->bufferFormatControl)
- return d_func()->bufferFormatControl->bufferFormat();
- else
- return QVideoFrame::Format_Invalid;
-}
-
-/*!
- Sets the buffer image capture \a format to be used.
-
- \sa bufferFormat(), supportedBufferFormats(), captureDestination()
-*/
-void QCameraImageCapture::setBufferFormat(const QVideoFrame::PixelFormat format)
-{
- if (d_func()->bufferFormatControl)
- d_func()->bufferFormatControl->setBufferFormat(format);
-}
-
-/*!
- Returns true if the image capture \a destination is supported; otherwise returns false.
-
- \sa captureDestination(), setCaptureDestination()
-*/
-bool QCameraImageCapture::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const
-{
- if (d_func()->captureDestinationControl)
- return d_func()->captureDestinationControl->isCaptureDestinationSupported(destination);
- else
- return destination == CaptureToFile;
-}
-
-/*!
- Returns the image capture destination being used.
-
- \sa isCaptureDestinationSupported(), setCaptureDestination()
-*/
-QCameraImageCapture::CaptureDestinations QCameraImageCapture::captureDestination() const
-{
- if (d_func()->captureDestinationControl)
- return d_func()->captureDestinationControl->captureDestination();
- else
- return CaptureToFile;
-}
-
-/*!
- Sets the capture \a destination to be used.
-
- \sa isCaptureDestinationSupported(), captureDestination()
-*/
-void QCameraImageCapture::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination)
-{
- Q_D(QCameraImageCapture);
-
- if (d->captureDestinationControl)
- d->captureDestinationControl->setCaptureDestination(destination);
-}
-
-/*!
- \property QCameraImageCapture::readyForCapture
- \brief whether the service is ready to capture a an image immediately.
-
- Calling capture() while \e readyForCapture is \c false is not permitted and
- results in an error.
-*/
-
-bool QCameraImageCapture::isReadyForCapture() const
-{
- if (d_func()->control)
- return d_func()->control->isReadyForCapture();
- else
- return false;
-}
-
-/*!
- \fn QCameraImageCapture::readyForCaptureChanged(bool ready)
-
- Signals that a camera's \a ready for capture state has changed.
-*/
-
-
-/*!
- Capture the image and save it to \a file.
- This operation is asynchronous in majority of cases,
- followed by signals QCameraImageCapture::imageExposed(),
- QCameraImageCapture::imageCaptured(), QCameraImageCapture::imageSaved()
- or QCameraImageCapture::error().
-
- If an empty \a file is passed, the camera backend choses
- the default location and naming scheme for photos on the system,
- if only file name without full path is specified, the image will be saved to
- the default directory, with a full path reported with imageCaptured() and imageSaved() signals.
-
- QCamera saves all the capture parameters like exposure settings or
- image processing parameters, so changes to camera parameters after
- capture() is called do not affect previous capture requests.
-
- QCameraImageCapture::capture returns the capture Id parameter, used with
- imageExposed(), imageCaptured() and imageSaved() signals.
-
- \sa isReadyForCapture()
-*/
-int QCameraImageCapture::capture(const QString &file)
-{
- Q_D(QCameraImageCapture);
-
- d->unsetError();
-
- if (d->control) {
- return d->control->capture(file);
- } else {
- d->error = NotSupportedFeatureError;
- d->errorString = tr("Device does not support images capture.");
-
- emit error(-1, d->error, d->errorString);
- }
-
- return -1;
-}
-
-/*!
- Cancel incomplete capture requests.
- Already captured and queused for proicessing images may be discarded.
-*/
-void QCameraImageCapture::cancelCapture()
-{
- Q_D(QCameraImageCapture);
-
- d->unsetError();
-
- if (d->control) {
- d->control->cancelCapture();
- } else {
- d->error = NotSupportedFeatureError;
- d->errorString = tr("Device does not support images capture.");
-
- emit error(-1, d->error, d->errorString);
- }
-}
-
-
-/*!
- \enum QCameraImageCapture::Error
-
- \value NoError No Errors.
- \value NotReadyError The service is not ready for capture yet.
- \value ResourceError Device is not ready or not available.
- \value OutOfSpaceError No space left on device.
- \value NotSupportedFeatureError Device does not support stillimages capture.
- \value FormatError Current format is not supported.
-*/
-
-/*!
- \enum QCameraImageCapture::DriveMode
-
- \value SingleImageCapture Drive mode is capturing a single picture.
-*/
-
-/*!
- \fn QCameraImageCapture::error(int id, QCameraImageCapture::Error error, const QString &errorString)
-
- Signals that the capture request \a id has failed with an \a error
- and \a errorString description.
-*/
-
-/*!
- \fn QCameraImageCapture::bufferFormatChanged(QVideoFrame::PixelFormat format)
-
- Signal emitted when the buffer \a format for the buffer image capture has changed.
-*/
-
-/*!
- \fn QCameraImageCapture::captureDestinationChanged(CaptureDestinations destination)
-
- Signal emitted when the capture \a destination has changed.
-*/
-
-/*!
- \fn QCameraImageCapture::imageExposed(int id)
-
- Signal emitted when the frame with request \a id was exposed.
-*/
-
-/*!
- \fn QCameraImageCapture::imageCaptured(int id, const QImage &preview);
-
- Signal emitted when QAbstractVideoSurface is used as a viewfinder and
- the frame with request \a id was captured, but not processed and saved yet.
- Frame \a preview can be displayed to user.
-*/
-
-/*!
- \fn QCameraImageCapture::imageMetadataAvailable(int id, const QString &key, const QVariant &value)
-
- Signals that a metadata for an image with request \a id is available. Also
- includes the \a key and \a value of the metadata.
-
- This signal is emitted between imageExposed and imageSaved signals.
-*/
-
-/*!
- \fn QCameraImageCapture::imageAvailable(int id, const QVideoFrame &frame)
-
- Signal emitted when QCameraImageCapture::CaptureToBuffer is set and
- the \a frame with request \a id is available.
-*/
-
-/*!
- \fn QCameraImageCapture::imageSaved(int id, const QString &fileName)
-
- Signal emitted when QCameraImageCapture::CaptureToFile is set and
- the frame with request \a id was saved to \a fileName.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcameraimagecapture.cpp"
diff --git a/src/multimedia/camera/qcameraimagecapture.h b/src/multimedia/camera/qcameraimagecapture.h
deleted file mode 100644
index 931fe3902..000000000
--- a/src/multimedia/camera/qcameraimagecapture.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAIMAGECAPTURE_H
-#define QCAMERAIMAGECAPTURE_H
-
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmediaencodersettings.h>
-#include <QtMultimedia/qmediabindableinterface.h>
-#include <QtMultimedia/qvideoframe.h>
-
-#include <QtMultimedia/qmediaenumdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-class QSize;
-QT_END_NAMESPACE
-
-QT_BEGIN_NAMESPACE
-
-class QImageEncoderSettings;
-
-class QCameraImageCapturePrivate;
-class Q_MULTIMEDIA_EXPORT QCameraImageCapture : public QObject, public QMediaBindableInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaBindableInterface)
- Q_ENUMS(Error)
- Q_ENUMS(CaptureDestination)
- Q_PROPERTY(bool readyForCapture READ isReadyForCapture NOTIFY readyForCaptureChanged)
-public:
- enum Error
- {
- NoError,
- NotReadyError,
- ResourceError,
- OutOfSpaceError,
- NotSupportedFeatureError,
- FormatError
- };
-
- enum DriveMode
- {
- SingleImageCapture
- };
-
- enum CaptureDestination
- {
- CaptureToFile = 0x01,
- CaptureToBuffer = 0x02
- };
- Q_DECLARE_FLAGS(CaptureDestinations, CaptureDestination)
-
- explicit QCameraImageCapture(QMediaObject *mediaObject, QObject *parent = nullptr);
- ~QCameraImageCapture();
-
- bool isAvailable() const;
- QMultimedia::AvailabilityStatus availability() const;
-
- QMediaObject *mediaObject() const override;
-
- Error error() const;
- QString errorString() const;
-
- bool isReadyForCapture() const;
-
- QStringList supportedImageCodecs() const;
- QString imageCodecDescription(const QString &codecName) const;
-
- QList<QSize> supportedResolutions(const QImageEncoderSettings &settings = QImageEncoderSettings(),
- bool *continuous = nullptr) const;
-
- QImageEncoderSettings encodingSettings() const;
- void setEncodingSettings(const QImageEncoderSettings& settings);
-
- QList<QVideoFrame::PixelFormat> supportedBufferFormats() const;
- QVideoFrame::PixelFormat bufferFormat() const;
- void setBufferFormat(const QVideoFrame::PixelFormat format);
-
- bool isCaptureDestinationSupported(CaptureDestinations destination) const;
- CaptureDestinations captureDestination() const;
- void setCaptureDestination(CaptureDestinations destination);
-
-public Q_SLOTS:
- int capture(const QString &location = QString());
- void cancelCapture();
-
-Q_SIGNALS:
- void error(int id, QCameraImageCapture::Error error, const QString &errorString);
-
- void readyForCaptureChanged(bool ready);
- void bufferFormatChanged(QVideoFrame::PixelFormat format);
- void captureDestinationChanged(QCameraImageCapture::CaptureDestinations destination);
-
- void imageExposed(int id);
- void imageCaptured(int id, const QImage &preview);
- void imageMetadataAvailable(int id, const QString &key, const QVariant &value);
- void imageAvailable(int id, const QVideoFrame &frame);
- void imageSaved(int id, const QString &fileName);
-
-protected:
- bool setMediaObject(QMediaObject *) override;
-
- QCameraImageCapturePrivate *d_ptr;
-private:
- Q_DISABLE_COPY(QCameraImageCapture)
- Q_DECLARE_PRIVATE(QCameraImageCapture)
- Q_PRIVATE_SLOT(d_func(), void _q_error(int, int, const QString &))
- Q_PRIVATE_SLOT(d_func(), void _q_readyChanged(bool))
- Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed())
-};
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(QCameraImageCapture::CaptureDestinations)
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QCameraImageCapture::Error)
-Q_DECLARE_METATYPE(QCameraImageCapture::CaptureDestination)
-Q_DECLARE_METATYPE(QCameraImageCapture::CaptureDestinations)
-
-Q_MEDIA_ENUM_DEBUG(QCameraImageCapture, Error)
-Q_MEDIA_ENUM_DEBUG(QCameraImageCapture, CaptureDestination)
-
-#endif
-
diff --git a/src/multimedia/camera/qcameraimageprocessing.cpp b/src/multimedia/camera/qcameraimageprocessing.cpp
deleted file mode 100644
index af6c22391..000000000
--- a/src/multimedia/camera/qcameraimageprocessing.cpp
+++ /dev/null
@@ -1,401 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qcameraimageprocessing.h"
-#include "qmediaobject_p.h"
-
-#include <qcameracontrol.h>
-#include <qcameraexposurecontrol.h>
-#include <qcamerafocuscontrol.h>
-#include <qmediarecordercontrol.h>
-#include <qcameraimageprocessingcontrol.h>
-#include <qcameraimagecapturecontrol.h>
-#include <qvideodeviceselectorcontrol.h>
-
-#include <QtCore/QDebug>
-
-QT_BEGIN_NAMESPACE
-
-static void qRegisterCameraImageProcessingMetaTypes()
- {
- qRegisterMetaType<QCameraImageProcessing::WhiteBalanceMode>();
- qRegisterMetaType<QCameraImageProcessing::ColorFilter>();
- }
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterCameraImageProcessingMetaTypes)
-
-
-/*!
- \class QCameraImageProcessing
-
- \brief The QCameraImageProcessing class provides an interface for
- image processing related camera settings.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_camera
-
- After capturing the data for a camera frame, the camera hardware and
- software performs various image processing tasks to produce a final
- image. This includes compensating for ambient light color, reducing
- noise, as well as making some other adjustments to the image.
-
- You can retrieve this class from an instance of a \l QCamera object.
-
- For example, you can set the white balance (or color temperature) used
- for processing images:
-
- \snippet multimedia-snippets/camera.cpp Camera image whitebalance
-
- Or adjust the amount of denoising performed:
-
- \snippet multimedia-snippets/camera.cpp Camera image denoising
-
- In some cases changing these settings may result in a longer delay
- before an image is ready.
-
- For more information on image processing of camera frames, see \l {camera_image_processing}{Camera Image Processing}.
-
- \sa QCameraImageProcessingControl
-*/
-
-class QCameraImageProcessingFakeControl : public QCameraImageProcessingControl {
-public:
- QCameraImageProcessingFakeControl(QObject *parent) :
- QCameraImageProcessingControl(parent)
- {}
-
- bool isParameterSupported(ProcessingParameter) const override { return false; }
- bool isParameterValueSupported(ProcessingParameter, const QVariant &) const override { return false; }
- QVariant parameter(ProcessingParameter) const override { return QVariant(); }
- void setParameter(ProcessingParameter, const QVariant &) override {}
-};
-
-
-class QCameraImageProcessingPrivate : public QMediaObjectPrivate
-{
- Q_DECLARE_NON_CONST_PUBLIC(QCameraImageProcessing)
-public:
- void initControls();
-
- QCamera *camera;
- QCameraImageProcessingControl *imageControl;
- bool available;
-};
-
-
-void QCameraImageProcessingPrivate::initControls()
-{
- imageControl = 0;
-
- QMediaService *service = camera->service();
- if (service)
- imageControl = qobject_cast<QCameraImageProcessingControl *>(service->requestControl(QCameraImageProcessingControl_iid));
-
- available = (imageControl != nullptr);
-
- if (!imageControl)
- imageControl = new QCameraImageProcessingFakeControl(q_ptr);
-}
-
-/*!
- Construct a QCameraImageProcessing for \a camera.
-*/
-
-QCameraImageProcessing::QCameraImageProcessing(QCamera *camera)
- : QObject(*new QCameraImageProcessingPrivate, camera)
-{
- Q_D(QCameraImageProcessing);
- d->camera = camera;
- d->initControls();
-}
-
-
-/*!
- Destroys the camera focus object.
-*/
-
-QCameraImageProcessing::~QCameraImageProcessing()
-{
-}
-
-
-/*!
- Returns true if image processing related settings are supported by this camera.
-*/
-bool QCameraImageProcessing::isAvailable() const
-{
- return d_func()->available;
-}
-
-
-/*!
- Returns the white balance mode being used.
-*/
-
-QCameraImageProcessing::WhiteBalanceMode QCameraImageProcessing::whiteBalanceMode() const
-{
- return d_func()->imageControl->parameter(QCameraImageProcessingControl::WhiteBalancePreset)
- .value<QCameraImageProcessing::WhiteBalanceMode>();
-}
-
-/*!
- Sets the white balance to \a mode.
-*/
-
-void QCameraImageProcessing::setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode)
-{
- d_func()->imageControl->setParameter(
- QCameraImageProcessingControl::WhiteBalancePreset,
- QVariant::fromValue<QCameraImageProcessing::WhiteBalanceMode>(mode));
-}
-
-/*!
- Returns true if the white balance \a mode is supported.
-*/
-
-bool QCameraImageProcessing::isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode mode) const
-{
- return d_func()->imageControl->isParameterValueSupported(
- QCameraImageProcessingControl::WhiteBalancePreset,
- QVariant::fromValue<QCameraImageProcessing::WhiteBalanceMode>(mode));
-
-}
-
-/*!
- Returns the current color temperature if the
- current white balance mode is \c WhiteBalanceManual. For other modes the
- return value is undefined.
-*/
-
-qreal QCameraImageProcessing::manualWhiteBalance() const
-{
- return d_func()->imageControl->parameter(QCameraImageProcessingControl::ColorTemperature).toReal();
-}
-
-/*!
- Sets manual white balance to \a colorTemperature. This is used
- when whiteBalanceMode() is set to \c WhiteBalanceManual. The units are Kelvin.
-*/
-
-void QCameraImageProcessing::setManualWhiteBalance(qreal colorTemperature)
-{
- d_func()->imageControl->setParameter(
- QCameraImageProcessingControl::ColorTemperature,
- QVariant(colorTemperature));
-}
-
-/*!
- Returns the brightness adjustment setting.
- */
-qreal QCameraImageProcessing::brightness() const
-{
- return d_func()->imageControl->parameter(QCameraImageProcessingControl::BrightnessAdjustment).toReal();
-}
-
-/*!
- Set the brightness adjustment to \a value.
-
- Valid brightness adjustment values range between -1.0 and 1.0, with a default of 0.
- */
-void QCameraImageProcessing::setBrightness(qreal value)
-{
- d_func()->imageControl->setParameter(QCameraImageProcessingControl::BrightnessAdjustment,
- QVariant(value));
-}
-
-/*!
- Returns the contrast adjustment setting.
-*/
-qreal QCameraImageProcessing::contrast() const
-{
- return d_func()->imageControl->parameter(QCameraImageProcessingControl::ContrastAdjustment).toReal();
-}
-
-/*!
- Set the contrast adjustment to \a value.
-
- Valid contrast adjustment values range between -1.0 and 1.0, with a default of 0.
-*/
-void QCameraImageProcessing::setContrast(qreal value)
-{
- d_func()->imageControl->setParameter(QCameraImageProcessingControl::ContrastAdjustment,
- QVariant(value));
-}
-
-/*!
- Returns the saturation adjustment value.
-*/
-qreal QCameraImageProcessing::saturation() const
-{
- return d_func()->imageControl->parameter(QCameraImageProcessingControl::SaturationAdjustment).toReal();
-}
-
-/*!
- Sets the saturation adjustment value to \a value.
-
- Valid saturation values range between -1.0 and 1.0, with a default of 0.
-*/
-
-void QCameraImageProcessing::setSaturation(qreal value)
-{
- d_func()->imageControl->setParameter(QCameraImageProcessingControl::SaturationAdjustment,
- QVariant(value));
-}
-
-/*!
- Returns the sharpening adjustment level.
-*/
-qreal QCameraImageProcessing::sharpeningLevel() const
-{
- return d_func()->imageControl->parameter(QCameraImageProcessingControl::SharpeningAdjustment).toReal();
-}
-
-/*!
- Sets the sharpening adjustment \a level.
-
- Valid sharpening values range between -1.0 and 1.0, with a default of 0.
-*/
-
-void QCameraImageProcessing::setSharpeningLevel(qreal level)
-{
- d_func()->imageControl->setParameter(QCameraImageProcessingControl::SharpeningAdjustment,
- QVariant(level));
-}
-
-/*!
- Returns the denoising adjustment level.
-*/
-qreal QCameraImageProcessing::denoisingLevel() const
-{
- return d_func()->imageControl->parameter(QCameraImageProcessingControl::DenoisingAdjustment).toReal();
-}
-
-/*!
- Sets the denoising adjustment \a level.
-
- Valid denoising values range between -1.0 and 1.0, with a default of 0.
-
- If the parameter value is set to 0, the amount of denoising applied
- is selected by camera and depends on camera capabilities and settings.
- Changing value in -1.0..1.0 range adjusts the amount of denoising applied
- within the supported range.
-*/
-void QCameraImageProcessing::setDenoisingLevel(qreal level)
-{
- d_func()->imageControl->setParameter(QCameraImageProcessingControl::DenoisingAdjustment,
- QVariant(level));
-}
-
-/*!
- \enum QCameraImageProcessing::WhiteBalanceMode
-
- \value WhiteBalanceAuto Auto white balance mode.
- \value WhiteBalanceManual Manual white balance. In this mode the white balance should be set with
- setManualWhiteBalance()
- \value WhiteBalanceSunlight Sunlight white balance mode.
- \value WhiteBalanceCloudy Cloudy white balance mode.
- \value WhiteBalanceShade Shade white balance mode.
- \value WhiteBalanceTungsten Tungsten (incandescent) white balance mode.
- \value WhiteBalanceFluorescent Fluorescent white balance mode.
- \value WhiteBalanceFlash Flash white balance mode.
- \value WhiteBalanceSunset Sunset white balance mode.
- \value WhiteBalanceVendor Base value for vendor defined white balance modes.
-*/
-
-/*!
- \enum QCameraImageProcessing::ColorFilter
-
- \value ColorFilterNone No filter is applied to images.
- \value ColorFilterGrayscale A grayscale filter.
- \value ColorFilterNegative A negative filter.
- \value ColorFilterSolarize A solarize filter.
- \value ColorFilterSepia A sepia filter.
- \value ColorFilterPosterize A posterize filter.
- \value ColorFilterWhiteboard A whiteboard filter.
- \value ColorFilterBlackboard A blackboard filter.
- \value ColorFilterAqua An aqua filter.
- \value ColorFilterVendor The base value for vendor defined filters.
-
- \since 5.5
-*/
-
-/*!
- Returns the color filter which will be applied to image data captured by the camera.
-
- \since 5.5
-*/
-
-QCameraImageProcessing::ColorFilter QCameraImageProcessing::colorFilter() const
-{
- return d_func()->imageControl->parameter(QCameraImageProcessingControl::ColorFilter)
- .value<QCameraImageProcessing::ColorFilter>();
-}
-
-
-/*!
- Sets the color \a filter which will be applied to image data captured by the camera.
-
- \since 5.5
-*/
-
-void QCameraImageProcessing::setColorFilter(QCameraImageProcessing::ColorFilter filter)
-{
- d_func()->imageControl->setParameter(
- QCameraImageProcessingControl::ColorFilter,
- QVariant::fromValue<QCameraImageProcessing::ColorFilter>(filter));
-}
-
-/*!
- Returns true if a color \a filter is supported.
-
- \since 5.5
-*/
-
-bool QCameraImageProcessing::isColorFilterSupported(QCameraImageProcessing::ColorFilter filter) const
-{
- return d_func()->imageControl->isParameterValueSupported(
- QCameraImageProcessingControl::ColorFilter,
- QVariant::fromValue<QCameraImageProcessing::ColorFilter>(filter));
-
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qcameraimageprocessing.cpp"
diff --git a/src/multimedia/camera/qcameraimageprocessing.h b/src/multimedia/camera/qcameraimageprocessing.h
deleted file mode 100644
index ddb94f70a..000000000
--- a/src/multimedia/camera/qcameraimageprocessing.h
+++ /dev/null
@@ -1,139 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAIMAGEPROCESSING_H
-#define QCAMERAIMAGEPROCESSING_H
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qpair.h>
-#include <QtCore/qsize.h>
-#include <QtCore/qpoint.h>
-#include <QtCore/qrect.h>
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmediaservice.h>
-#include <QtMultimedia/qmediaenumdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QCamera;
-
-class QCameraImageProcessingPrivate;
-class Q_MULTIMEDIA_EXPORT QCameraImageProcessing : public QObject
-{
- Q_OBJECT
- Q_ENUMS(WhiteBalanceMode ColorFilter)
-public:
- enum WhiteBalanceMode {
- WhiteBalanceAuto = 0,
- WhiteBalanceManual = 1,
- WhiteBalanceSunlight = 2,
- WhiteBalanceCloudy = 3,
- WhiteBalanceShade = 4,
- WhiteBalanceTungsten = 5,
- WhiteBalanceFluorescent = 6,
- WhiteBalanceFlash = 7,
- WhiteBalanceSunset = 8,
- WhiteBalanceVendor = 1000
- };
-
- enum ColorFilter {
- ColorFilterNone,
- ColorFilterGrayscale,
- ColorFilterNegative,
- ColorFilterSolarize,
- ColorFilterSepia,
- ColorFilterPosterize,
- ColorFilterWhiteboard,
- ColorFilterBlackboard,
- ColorFilterAqua,
- ColorFilterVendor = 1000
- };
-
- bool isAvailable() const;
-
- WhiteBalanceMode whiteBalanceMode() const;
- void setWhiteBalanceMode(WhiteBalanceMode mode);
- bool isWhiteBalanceModeSupported(WhiteBalanceMode mode) const;
-
- qreal manualWhiteBalance() const;
- void setManualWhiteBalance(qreal colorTemperature);
-
- qreal brightness() const;
- void setBrightness(qreal value);
-
- qreal contrast() const;
- void setContrast(qreal value);
-
- qreal saturation() const;
- void setSaturation(qreal value);
-
- qreal sharpeningLevel() const;
- void setSharpeningLevel(qreal value);
-
- qreal denoisingLevel() const;
- void setDenoisingLevel(qreal value);
-
- ColorFilter colorFilter() const;
- void setColorFilter(ColorFilter filter);
- bool isColorFilterSupported(ColorFilter filter) const;
-
-protected:
- ~QCameraImageProcessing();
-
-private:
- friend class QCamera;
- friend class QCameraPrivate;
- QCameraImageProcessing(QCamera *camera);
-
- Q_DISABLE_COPY(QCameraImageProcessing)
- Q_DECLARE_PRIVATE(QCameraImageProcessing)
-};
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QCameraImageProcessing::WhiteBalanceMode)
-Q_DECLARE_METATYPE(QCameraImageProcessing::ColorFilter)
-
-Q_MEDIA_ENUM_DEBUG(QCameraImageProcessing, WhiteBalanceMode)
-Q_MEDIA_ENUM_DEBUG(QCameraImageProcessing, ColorFilter)
-
-#endif // QCAMERAIMAGEPROCESSING_H
diff --git a/src/multimedia/camera/qcamerainfo.cpp b/src/multimedia/camera/qcamerainfo.cpp
deleted file mode 100644
index 1e7511851..000000000
--- a/src/multimedia/camera/qcamerainfo.cpp
+++ /dev/null
@@ -1,287 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qcamerainfo.h"
-
-#include "qcamera_p.h"
-#include "qmediaserviceprovider_p.h"
-
-#include <qvideodeviceselectorcontrol.h>
-#include <qcamerainfocontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraInfo
- \brief The QCameraInfo class provides general information about camera devices.
- \since 5.3
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_camera
-
- QCameraInfo lets you query for camera devices that are currently available on the system.
-
- The static functions defaultCamera() and availableCameras() provide you a list of all
- available cameras.
-
- This example prints the name of all available cameras:
-
- \snippet multimedia-snippets/camera.cpp Camera listing
-
- A QCameraInfo can be used to construct a QCamera. The following example instantiates a QCamera
- whose camera device is named 'mycamera':
-
- \snippet multimedia-snippets/camera.cpp Camera selection
-
- You can also use QCameraInfo to get general information about a camera device such as
- description, physical position on the system, or camera sensor orientation.
-
- \snippet multimedia-snippets/camera.cpp Camera info
-
- \sa QCamera
-*/
-
-class QCameraInfoPrivate
-{
-public:
- QCameraInfoPrivate() : isNull(true), position(QCamera::UnspecifiedPosition), orientation(0)
- { }
-
- bool isNull;
- QString deviceName;
- QString description;
- QCamera::Position position;
- int orientation;
-};
-
-/*!
- Constructs a camera info object for \a camera.
-
- You can use it to query information about the \a camera object passed as argument.
-
- If the \a camera is invalid, for example when no camera device is available on the system,
- the QCameraInfo object will be invalid and isNull() will return true.
-*/
-QCameraInfo::QCameraInfo(const QCamera &camera)
- : d(new QCameraInfoPrivate)
-{
- const QVideoDeviceSelectorControl *deviceControl = camera.d_func()->deviceControl;
- if (deviceControl && deviceControl->deviceCount() > 0) {
- const int selectedDevice = deviceControl->selectedDevice();
- d->deviceName = deviceControl->deviceName(selectedDevice);
- d->description = deviceControl->deviceDescription(selectedDevice);
- d->isNull = false;
- }
-
- const QCameraInfoControl *infoControl = camera.d_func()->infoControl;
- if (infoControl) {
- d->position = infoControl->cameraPosition(d->deviceName);
- d->orientation = infoControl->cameraOrientation(d->deviceName);
- d->isNull = false;
- }
-}
-
-/*!
- Constructs a camera info object from a camera device \a name.
-
- If no such device exists, the QCameraInfo object will be invalid and isNull() will return true.
-*/
-QCameraInfo::QCameraInfo(const QByteArray &name)
- : d(new QCameraInfoPrivate)
-{
- if (!name.isNull()) {
- QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
- const QByteArray service(Q_MEDIASERVICE_CAMERA);
- if (provider->devices(service).contains(name)) {
- d->deviceName = QString::fromLatin1(name);
- d->description = provider->deviceDescription(service, name);
- d->position = provider->cameraPosition(name);
- d->orientation = provider->cameraOrientation(name);
- d->isNull = false;
- }
- }
-}
-
-/*!
- Constructs a copy of \a other.
-*/
-QCameraInfo::QCameraInfo(const QCameraInfo &other)
- : d(other.d)
-{
-}
-
-/*!
- Destroys the QCameraInfo.
-*/
-QCameraInfo::~QCameraInfo()
-{
-}
-
-/*!
- Returns true if this QCameraInfo is equal to \a other.
-*/
-bool QCameraInfo::operator==(const QCameraInfo &other) const
-{
- if (d == other.d)
- return true;
-
- return (d->deviceName == other.d->deviceName
- && d->description == other.d->description
- && d->position == other.d->position
- && d->orientation == other.d->orientation);
-}
-
-/*!
- Returns true if this QCameraInfo is null or invalid.
-*/
-bool QCameraInfo::isNull() const
-{
- return d->isNull;
-}
-
-/*!
- Returns the device name of the camera
-
- This is a unique ID to identify the camera and may not be human-readable.
-*/
-QString QCameraInfo::deviceName() const
-{
- return d->deviceName;
-}
-
-/*!
- Returns the human-readable description of the camera.
-*/
-QString QCameraInfo::description() const
-{
- return d->description;
-}
-
-/*!
- Returns the physical position of the camera on the hardware system.
-*/
-QCamera::Position QCameraInfo::position() const
-{
- return d->position;
-}
-
-/*!
- Returns the physical orientation of the camera sensor.
-
- The value is the orientation angle (clockwise, in steps of 90 degrees) of the camera sensor
- in relation to the display in its natural orientation.
-
- You can show the camera image in the correct orientation by rotating it by this value in the
- anti-clockwise direction.
-
- For example, suppose a mobile device which is naturally in portrait orientation. The back-facing
- camera is mounted in landscape. If the top side of the camera sensor is aligned with the
- right edge of the screen in natural orientation, the value should be 270. If the top side of a
- front-facing camera sensor is aligned with the right of the screen, the value should be 90.
-*/
-int QCameraInfo::orientation() const
-{
- return d->orientation;
-}
-
-/*!
- Returns the default camera on the system.
-
- The returned object should be checked using isNull() before being used, in case there is no
- default camera or no cameras at all.
-
- \sa availableCameras()
-*/
-QCameraInfo QCameraInfo::defaultCamera()
-{
- return QCameraInfo(QMediaServiceProvider::defaultServiceProvider()->defaultDevice(Q_MEDIASERVICE_CAMERA));
-}
-
-/*!
- Returns a list of available cameras on the system which are located at \a position.
-
- If \a position is not specified or if the value is QCamera::UnspecifiedPosition, a list of
- all available cameras will be returned.
-*/
-QList<QCameraInfo> QCameraInfo::availableCameras(QCamera::Position position)
-{
- QList<QCameraInfo> cameras;
-
- const QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
- const QByteArray service(Q_MEDIASERVICE_CAMERA);
- const QList<QByteArray> devices = provider->devices(service);
- for (int i = 0; i < devices.count(); ++i) {
- const QByteArray &name = devices.at(i);
- if (position == QCamera::UnspecifiedPosition
- || position == provider->cameraPosition(name)) {
- cameras.append(QCameraInfo(name));
- }
- }
-
- return cameras;
-}
-
-/*!
- Sets the QCameraInfo object to be equal to \a other.
-*/
-QCameraInfo& QCameraInfo::operator=(const QCameraInfo& other)
-{
- d = other.d;
- return *this;
-}
-
-/*!
- \fn QCameraInfo::operator!=(const QCameraInfo &other) const
-
- Returns true if this QCameraInfo is different from \a other.
-*/
-
-#ifndef QT_NO_DEBUG_STREAM
-QDebug operator<<(QDebug d, const QCameraInfo &camera)
-{
- d.maybeSpace() << QStringLiteral("QCameraInfo(deviceName=%1, position=%2, orientation=%3)")
- .arg(camera.deviceName())
- .arg(QString::fromLatin1(QCamera::staticMetaObject.enumerator(QCamera::staticMetaObject.indexOfEnumerator("Position"))
- .valueToKey(camera.position())))
- .arg(camera.orientation());
- return d.space();
-}
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/camera/qcamerainfo.h b/src/multimedia/camera/qcamerainfo.h
deleted file mode 100644
index 821ebb4a5..000000000
--- a/src/multimedia/camera/qcamerainfo.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAINFO_H
-#define QCAMERAINFO_H
-
-#include <QtMultimedia/qcamera.h>
-#include <QtCore/qsharedpointer.h>
-
-QT_BEGIN_NAMESPACE
-
-class QCameraInfoPrivate;
-
-class Q_MULTIMEDIA_EXPORT QCameraInfo
-{
-public:
- explicit QCameraInfo(const QByteArray &name = QByteArray());
- explicit QCameraInfo(const QCamera &camera);
- QCameraInfo(const QCameraInfo& other);
- ~QCameraInfo();
-
- QCameraInfo& operator=(const QCameraInfo& other);
- bool operator==(const QCameraInfo &other) const;
- inline bool operator!=(const QCameraInfo &other) const;
-
- bool isNull() const;
-
- QString deviceName() const;
- QString description() const;
- QCamera::Position position() const;
- int orientation() const;
-
- static QCameraInfo defaultCamera();
- static QList<QCameraInfo> availableCameras(QCamera::Position position = QCamera::UnspecifiedPosition);
-
-private:
- QSharedPointer<QCameraInfoPrivate> d;
-};
-
-bool QCameraInfo::operator!=(const QCameraInfo &other) const { return !operator==(other); }
-
-#ifndef QT_NO_DEBUG_STREAM
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QCameraInfo&);
-#endif
-
-QT_END_NAMESPACE
-
-#endif // QCAMERAINFO_H
diff --git a/src/multimedia/camera/qcameraviewfindersettings.cpp b/src/multimedia/camera/qcameraviewfindersettings.cpp
deleted file mode 100644
index 90b61bcf7..000000000
--- a/src/multimedia/camera/qcameraviewfindersettings.cpp
+++ /dev/null
@@ -1,331 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qcameraviewfindersettings.h"
-
-QT_BEGIN_NAMESPACE
-
-static void qRegisterViewfinderSettingsMetaType()
-{
- qRegisterMetaType<QCameraViewfinderSettings>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterViewfinderSettingsMetaType)
-
-
-class QCameraViewfinderSettingsPrivate : public QSharedData
-{
-public:
- QCameraViewfinderSettingsPrivate() :
- isNull(true),
- minimumFrameRate(0.0),
- maximumFrameRate(0.0),
- pixelFormat(QVideoFrame::Format_Invalid)
- {
- }
-
- QCameraViewfinderSettingsPrivate(const QCameraViewfinderSettingsPrivate &other):
- QSharedData(other),
- isNull(other.isNull),
- resolution(other.resolution),
- minimumFrameRate(other.minimumFrameRate),
- maximumFrameRate(other.maximumFrameRate),
- pixelFormat(other.pixelFormat),
- pixelAspectRatio(other.pixelAspectRatio)
- {
- }
-
- bool isNull;
- QSize resolution;
- qreal minimumFrameRate;
- qreal maximumFrameRate;
- QVideoFrame::PixelFormat pixelFormat;
- QSize pixelAspectRatio;
-
-private:
- QCameraViewfinderSettingsPrivate& operator=(const QCameraViewfinderSettingsPrivate &other);
-};
-
-
-/*!
- \class QCameraViewfinderSettings
- \since 5.5
- \brief The QCameraViewfinderSettings class provides a set of viewfinder settings.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_camera
-
- A viewfinder settings object is used to specify the viewfinder settings used by QCamera.
- Viewfinder settings are selected by constructing a QCameraViewfinderSettings object,
- setting the desired properties and then passing it to a QCamera instance using the
- QCamera::setViewfinderSettings() function.
-
- \snippet multimedia-snippets/camera.cpp Camera viewfinder settings
-
- Different cameras may have different capabilities. The application should query the camera
- capabilities before setting parameters. For example, the application should call
- QCamera::supportedViewfinderResolutions() before calling setResolution().
-
- \sa QCamera
-*/
-
-/*!
- Constructs a null viewfinder settings object.
-*/
-QCameraViewfinderSettings::QCameraViewfinderSettings()
- : d(new QCameraViewfinderSettingsPrivate)
-{
-}
-
-/*!
- Constructs a copy of the viewfinder settings object \a other.
-*/
-QCameraViewfinderSettings::QCameraViewfinderSettings(const QCameraViewfinderSettings &other)
- : d(other.d)
-{
-
-}
-
-/*!
- Destroys a viewfinder settings object.
-*/
-QCameraViewfinderSettings::~QCameraViewfinderSettings()
-{
-
-}
-
-/*!
- Assigns the value of \a other to a viewfinder settings object.
-*/
-QCameraViewfinderSettings &QCameraViewfinderSettings::operator=(const QCameraViewfinderSettings &other)
-{
- d = other.d;
- return *this;
-}
-
-/*! \fn QCameraViewfinderSettings &QCameraViewfinderSettings::operator=(QCameraViewfinderSettings &&other)
-
- Moves \a other to this viewfinder settings object and returns a reference to this object.
-*/
-
-/*!
- \fn void QCameraViewfinderSettings::swap(QCameraViewfinderSettings &other)
-
- Swaps this viewfinder settings object with \a other. This
- function is very fast and never fails.
-*/
-
-/*!
- \relates QCameraViewfinderSettings
- \since 5.5
-
- Determines if \a lhs is of equal value to \a rhs.
-
- Returns true if the settings objects are of equal value, and false if they
- are not of equal value.
-*/
-bool operator==(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs) Q_DECL_NOTHROW
-{
- return (lhs.d == rhs.d) ||
- (lhs.d->isNull == rhs.d->isNull &&
- lhs.d->resolution == rhs.d->resolution &&
- lhs.d->minimumFrameRate == rhs.d->minimumFrameRate &&
- lhs.d->maximumFrameRate == rhs.d->maximumFrameRate &&
- lhs.d->pixelFormat == rhs.d->pixelFormat &&
- lhs.d->pixelAspectRatio == rhs.d->pixelAspectRatio);
-}
-
-/*!
- \fn bool operator!=(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs)
- \relates QCameraViewfinderSettings
- \since 5.5
-
- Determines if \a lhs is of equal value to \a rhs.
-
- Returns true if the settings objects are not of equal value, and false if
- they are of equal value.
-*/
-
-/*!
- Identifies if a viewfinder settings object is uninitalized.
-
- Returns true if the settings are null, and false if they are not.
-*/
-bool QCameraViewfinderSettings::isNull() const
-{
- return d->isNull;
-}
-
-/*!
- Returns the viewfinder resolution.
-*/
-QSize QCameraViewfinderSettings::resolution() const
-{
- return d->resolution;
-}
-
-/*!
- Sets the viewfinder \a resolution.
-
- If the given \a resolution is empty, the backend makes an optimal choice based on the
- supported resolutions and the other viewfinder settings.
-
- If the camera is used to capture videos or images, the viewfinder resolution might be
- ignored if it conflicts with the capture resolution.
-
- \sa QVideoEncoderSettings::setResolution(), QImageEncoderSettings::setResolution(),
- QCamera::supportedViewfinderResolutions()
-*/
-void QCameraViewfinderSettings::setResolution(const QSize &resolution)
-{
- d->isNull = false;
- d->resolution = resolution;
-}
-
-/*!
- \fn QCameraViewfinderSettings::setResolution(int width, int height)
-
- This is an overloaded function.
-
- Sets the \a width and \a height of the viewfinder resolution.
-*/
-
-/*!
- Returns the viewfinder minimum frame rate in frames per second.
-
- \sa maximumFrameRate()
-*/
-qreal QCameraViewfinderSettings::minimumFrameRate() const
-{
- return d->minimumFrameRate;
-}
-
-/*!
- Sets the viewfinder minimum frame \a rate in frames per second.
-
- If the minimum frame \a rate is equal to the maximum frame rate, the frame rate is fixed.
- If not, the actual frame rate fluctuates between the minimum and the maximum.
-
- If the given \a rate equals to \c 0, the backend makes an optimal choice based on the
- supported frame rates and the other viewfinder settings.
-
- \sa setMaximumFrameRate(), QCamera::supportedViewfinderFrameRateRanges()
-*/
-void QCameraViewfinderSettings::setMinimumFrameRate(qreal rate)
-{
- d->isNull = false;
- d->minimumFrameRate = rate;
-}
-
-/*!
- Returns the viewfinder maximum frame rate in frames per second.
-
- \sa minimumFrameRate()
-*/
-qreal QCameraViewfinderSettings::maximumFrameRate() const
-{
- return d->maximumFrameRate;
-}
-
-/*!
- Sets the viewfinder maximum frame \a rate in frames per second.
-
- If the maximum frame \a rate is equal to the minimum frame rate, the frame rate is fixed.
- If not, the actual frame rate fluctuates between the minimum and the maximum.
-
- If the given \a rate equals to \c 0, the backend makes an optimal choice based on the
- supported frame rates and the other viewfinder settings.
-
- \sa setMinimumFrameRate(), QCamera::supportedViewfinderFrameRateRanges()
-*/
-void QCameraViewfinderSettings::setMaximumFrameRate(qreal rate)
-{
- d->isNull = false;
- d->maximumFrameRate = rate;
-}
-
-/*!
- Returns the viewfinder pixel format.
-*/
-QVideoFrame::PixelFormat QCameraViewfinderSettings::pixelFormat() const
-{
- return d->pixelFormat;
-}
-
-/*!
- Sets the viewfinder pixel \a format.
-
- If the given \a format is equal to QVideoFrame::Format_Invalid, the backend uses the
- default format.
-
- \sa QCamera::supportedViewfinderPixelFormats()
-*/
-void QCameraViewfinderSettings::setPixelFormat(QVideoFrame::PixelFormat format)
-{
- d->isNull = false;
- d->pixelFormat = format;
-}
-
-/*!
- Returns the viewfinder pixel aspect ratio.
-*/
-QSize QCameraViewfinderSettings::pixelAspectRatio() const
-{
- return d->pixelAspectRatio;
-}
-
-/*!
- Sets the viewfinder pixel aspect \a ratio.
-*/
-void QCameraViewfinderSettings::setPixelAspectRatio(const QSize &ratio)
-{
- d->isNull = false;
- d->pixelAspectRatio = ratio;
-}
-
-/*!
- \fn QCameraViewfinderSettings::setPixelAspectRatio(int horizontal, int vertical)
-
- This is an overloaded function.
-
- Sets the \a horizontal and \a vertical elements of the viewfinder's pixel aspect ratio.
-*/
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/camera/qcameraviewfindersettings.h b/src/multimedia/camera/qcameraviewfindersettings.h
deleted file mode 100644
index 432bdcf1f..000000000
--- a/src/multimedia/camera/qcameraviewfindersettings.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAVIEWFINDERSETTINGS_H
-#define QCAMERAVIEWFINDERSETTINGS_H
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qvideoframe.h>
-
-#include <QtCore/qshareddata.h>
-#include <QtCore/qsize.h>
-
-QT_BEGIN_NAMESPACE
-
-class QCameraViewfinderSettingsPrivate;
-
-class Q_MULTIMEDIA_EXPORT QCameraViewfinderSettings
-{
-public:
- QCameraViewfinderSettings();
- QCameraViewfinderSettings(const QCameraViewfinderSettings& other);
-
- ~QCameraViewfinderSettings();
-
- QCameraViewfinderSettings& operator=(const QCameraViewfinderSettings &other);
-#ifdef Q_COMPILER_RVALUE_REFS
- QCameraViewfinderSettings &operator=(QCameraViewfinderSettings &&other) Q_DECL_NOTHROW
- { swap(other); return *this; }
-#endif
-
- void swap(QCameraViewfinderSettings &other) Q_DECL_NOTHROW { d.swap(other.d); }
-
- friend Q_MULTIMEDIA_EXPORT bool operator==(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs) Q_DECL_NOTHROW;
- bool isNull() const;
-
- QSize resolution() const;
- void setResolution(const QSize &);
- inline void setResolution(int width, int height)
- { setResolution(QSize(width, height)); }
-
- qreal minimumFrameRate() const;
- void setMinimumFrameRate(qreal rate);
-
- qreal maximumFrameRate() const;
- void setMaximumFrameRate(qreal rate);
-
- QVideoFrame::PixelFormat pixelFormat() const;
- void setPixelFormat(QVideoFrame::PixelFormat format);
-
- QSize pixelAspectRatio() const;
- void setPixelAspectRatio(const QSize &ratio);
- inline void setPixelAspectRatio(int horizontal, int vertical)
- { setPixelAspectRatio(QSize(horizontal, vertical)); }
-
-private:
- QSharedDataPointer<QCameraViewfinderSettingsPrivate> d;
-};
-Q_DECLARE_SHARED(QCameraViewfinderSettings)
-
-inline bool operator!=(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs) Q_DECL_NOTHROW
-{ return !operator==(lhs, rhs); }
-
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QCameraViewfinderSettings)
-
-#endif // QCAMERAVIEWFINDERSETTINGS_H
diff --git a/src/multimedia/camera/qimagecapture.cpp b/src/multimedia/camera/qimagecapture.cpp
new file mode 100644
index 000000000..df3ddae3f
--- /dev/null
+++ b/src/multimedia/camera/qimagecapture.cpp
@@ -0,0 +1,548 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include <qimagecapture.h>
+#include <private/qplatformimagecapture_p.h>
+#include <qmediametadata.h>
+#include <private/qplatformmediacapture_p.h>
+#include <private/qplatformmediaintegration_p.h>
+#include <private/qplatformmediaformatinfo_p.h>
+#include <qmediacapturesession.h>
+
+#include "private/qobject_p.h"
+#include <qcamera.h>
+#include <private/qplatformcamera_p.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qurl.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qmetaobject.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QImageCapture
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_camera
+
+
+ \brief The QImageCapture class is used for the recording of media content.
+
+ The QImageCapture class is a high level images recording class.
+ It's not intended to be used alone but for accessing the media
+ recording functions of other media objects, like QCamera.
+
+ \snippet multimedia-snippets/camera.cpp Camera
+
+ \snippet multimedia-snippets/camera.cpp Camera keys
+
+ \sa QCamera
+*/
+
+class QImageCapturePrivate
+{
+ Q_DECLARE_PUBLIC(QImageCapture)
+public:
+ QCamera *camera = nullptr;
+
+ QMediaCaptureSession *captureSession = nullptr;
+ QPlatformImageCapture *control = nullptr;
+
+ QImageCapture::Error error = QImageCapture::NoError;
+ QString errorString;
+ QMediaMetaData metaData;
+
+ void _q_error(int id, int error, const QString &errorString);
+
+ void unsetError() { error = QImageCapture::NoError; errorString.clear(); }
+
+ QImageCapture *q_ptr;
+};
+
+void QImageCapturePrivate::_q_error(int id, int error, const QString &errorString)
+{
+ Q_Q(QImageCapture);
+
+ this->error = QImageCapture::Error(error);
+ this->errorString = errorString;
+
+ emit q->errorChanged();
+ emit q->errorOccurred(id, this->error, errorString);
+}
+
+/*!
+ Constructs a image capture object, from a \a parent, that can capture
+ individual still images produced by a camera.
+
+ You must connect both an image capture object and a QCamera to a capture
+ session to capture images.
+*/
+
+QImageCapture::QImageCapture(QObject *parent)
+ : QObject(parent), d_ptr(new QImageCapturePrivate)
+{
+ Q_D(QImageCapture);
+ d->q_ptr = this;
+
+ auto maybeControl = QPlatformMediaIntegration::instance()->createImageCapture(this);
+ if (!maybeControl) {
+ qWarning() << "Failed to initialize QImageCapture" << maybeControl.error();
+ d->errorString = maybeControl.error();
+ d->error = NotReadyError;
+ return;
+ }
+
+ d->control = maybeControl.value();
+ connect(d->control, &QPlatformImageCapture::imageExposed, this, &QImageCapture::imageExposed);
+ connect(d->control, &QPlatformImageCapture::imageCaptured, this, &QImageCapture::imageCaptured);
+ connect(d->control, &QPlatformImageCapture::imageMetadataAvailable, this,
+ &QImageCapture::imageMetadataAvailable);
+ connect(d->control, &QPlatformImageCapture::imageAvailable, this,
+ &QImageCapture::imageAvailable);
+ connect(d->control, &QPlatformImageCapture::imageSaved, this, &QImageCapture::imageSaved);
+ connect(d->control, &QPlatformImageCapture::readyForCaptureChanged, this,
+ &QImageCapture::readyForCaptureChanged);
+ connect(d->control, SIGNAL(error(int,int,QString)),
+ this, SLOT(_q_error(int,int,QString)));
+}
+
+/*!
+ \fn void QImageCapture::imageMetadataAvailable(int id, const QMediaMetaData &metaData)
+
+ Signals that an image identified by \a id has \a metaData.
+*/
+
+/*!
+ \internal
+*/
+void QImageCapture::setCaptureSession(QMediaCaptureSession *session)
+{
+ Q_D(QImageCapture);
+ d->captureSession = session;
+}
+
+/*!
+ Destroys images capture object.
+*/
+
+QImageCapture::~QImageCapture()
+{
+ if (d_ptr->captureSession)
+ d_ptr->captureSession->setImageCapture(nullptr);
+ delete d_ptr;
+}
+
+/*!
+ Returns true if the images capture service ready to use.
+*/
+bool QImageCapture::isAvailable() const
+{
+ return d_func()->control && d_func()->captureSession && d_func()->captureSession->camera();
+}
+
+/*!
+ Returns the capture session this camera is connected to, or
+ a nullptr if the camera is not connected to a capture session.
+
+ Use QMediaCaptureSession::setImageCapture() to connect the image capture to
+ a session.
+*/
+QMediaCaptureSession *QImageCapture::captureSession() const
+{
+ return d_ptr->captureSession;
+}
+
+/*!
+ \property QImageCapture::error
+
+ Returns the current error state.
+
+ \sa errorString()
+*/
+
+QImageCapture::Error QImageCapture::error() const
+{
+ return d_func()->error;
+}
+
+/*!
+ \property QImageCapture::errorString
+
+ Returns a string describing the current error state.
+
+ \sa error()
+*/
+
+QString QImageCapture::errorString() const
+{
+ return d_func()->errorString;
+}
+
+/*!
+ \property QImageCapture::metaData
+ \brief The meta data that will get embedded into the image.
+
+ \note Additional fields such as a time stamp or location may get added by
+ the camera back end.
+*/
+QMediaMetaData QImageCapture::metaData() const
+{
+ Q_D(const QImageCapture);
+ return d->metaData;
+}
+
+/*!
+ Replaces any existing meta data, to be embedded into the captured image,
+ with a set of \a metaData.
+*/
+void QImageCapture::setMetaData(const QMediaMetaData &metaData)
+{
+ Q_D(QImageCapture);
+ d->metaData = metaData;
+ if (d->control)
+ d->control->setMetaData(d->metaData);
+ emit metaDataChanged();
+}
+
+/*!
+ Adds additional \a metaData to any existing meta data, that is embedded
+ into the captured image.
+*/
+void QImageCapture::addMetaData(const QMediaMetaData &metaData)
+{
+ Q_D(QImageCapture);
+ auto data = d->metaData;
+ for (auto k : metaData.keys())
+ data.insert(k, metaData.value(k));
+ setMetaData(data);
+}
+
+/*!
+ \property QImageCapture::readyForCapture
+
+ Holds \c true if the camera is ready to capture an image immediately.
+ Calling capture() while \c readyForCapture is \c false is not
+ permitted and results in an error.
+*/
+bool QImageCapture::isReadyForCapture() const
+{
+ Q_D(const QImageCapture);
+ if (!d->control || !d->captureSession || !d->control->isReadyForCapture())
+ return false;
+ auto *camera = d->captureSession->camera();
+ if (!camera || !camera->isActive())
+ return false;
+ return true;
+}
+
+/*!
+ \fn QImageCapture::readyForCaptureChanged(bool ready)
+
+ Signals that a camera's \a ready for capture state has changed.
+*/
+
+
+/*!
+ Capture the image and save it to \a file.
+ This operation is asynchronous in majority of cases,
+ followed by signals QImageCapture::imageExposed(),
+ QImageCapture::imageCaptured(), QImageCapture::imageSaved()
+ or QImageCapture::error().
+
+ If an empty \a file is passed, the camera back end chooses
+ the default location and naming scheme for photos on the system,
+ if only file name without full path is specified, the image will be saved to
+ the default directory, with a full path reported with imageCaptured() and imageSaved() signals.
+
+ QCamera saves all the capture parameters like exposure settings or
+ image processing parameters, so changes to camera parameters after
+ capture() is called do not affect previous capture requests.
+
+ QImageCapture::capture returns the capture Id parameter, used with
+ imageExposed(), imageCaptured() and imageSaved() signals.
+
+ \sa isReadyForCapture()
+*/
+int QImageCapture::captureToFile(const QString &file)
+{
+ Q_D(QImageCapture);
+ if (!d->control) {
+ d->_q_error(-1, d->error, d->errorString);
+ return -1;
+ }
+
+ d->unsetError();
+
+ if (!isReadyForCapture()) {
+ d->_q_error(-1, NotReadyError, tr("Could not capture in stopped state"));
+ return -1;
+ }
+
+ return d->control->capture(file);
+}
+
+/*!
+ Capture the image and make it available as a QImage.
+ This operation is asynchronous in majority of cases,
+ followed by signals QImageCapture::imageExposed(),
+ QImageCapture::imageCaptured()
+ or QImageCapture::error().
+
+ QImageCapture::capture returns the capture Id parameter, used with
+ imageExposed(), imageCaptured() and imageSaved() signals.
+
+ \sa isReadyForCapture()
+*/
+int QImageCapture::capture()
+{
+ Q_D(QImageCapture);
+ if (!d->control) {
+ d->_q_error(-1, d->error, d->errorString);
+ return -1;
+ } else {
+ d->unsetError();
+ return d->control->captureToBuffer();
+ }
+}
+
+/*!
+ \enum QImageCapture::Error
+
+ \value NoError No Errors.
+ \value NotReadyError The service is not ready for capture yet.
+ \value ResourceError Device is not ready or not available.
+ \value OutOfSpaceError No space left on device.
+ \value NotSupportedFeatureError Device does not support stillimages capture.
+ \value FormatError Current format is not supported.
+*/
+
+/*!
+ \fn QImageCapture::errorOccurred(int id, QImageCapture::Error error, const QString &errorString);
+
+ Signals that the capture request \a id has failed with an \a error
+ and \a errorString description.
+*/
+
+/*!
+ \fn QImageCapture::imageExposed(int id)
+
+ Signal emitted when the frame with request \a id was exposed.
+*/
+
+/*!
+ \fn QImageCapture::imageCaptured(int id, const QImage &preview);
+
+ Signal emitted when the frame with request \a id was captured, but not
+ processed and saved yet. Frame \a preview can be displayed to user.
+*/
+
+/*!
+ \fn QImageCapture::imageAvailable(int id, const QVideoFrame &frame)
+
+ Signal emitted when the \a frame with request \a id is available.
+*/
+
+/*!
+ \fn QImageCapture::imageSaved(int id, const QString &fileName)
+
+ Signal emitted when QImageCapture::CaptureToFile is set and
+ the frame with request \a id was saved to \a fileName.
+*/
+
+/*!
+ \enum QImageCapture::FileFormat
+
+ Choose one of the following image formats:
+
+ \value UnspecifiedFormat No format specified
+ \value JPEG \c .jpg or \c .jpeg format
+ \value PNG \c .png format
+ \value WebP \c .webp format
+ \value Tiff \c .tiff format
+ \omitvalue LastFileFormat
+*/
+
+
+/*!
+ \property QImageCapture::fileFormat
+ \brief The image format.
+*/
+
+QImageCapture::FileFormat QImageCapture::fileFormat() const
+{
+ Q_D(const QImageCapture);
+ return d->control ? d->control->imageSettings().format() : UnspecifiedFormat;
+}
+
+/*!
+ Sets the image \a format.
+*/
+void QImageCapture::setFileFormat(QImageCapture::FileFormat format)
+{
+ Q_D(QImageCapture);
+ if (!d->control)
+ return;
+ auto fmt = d->control->imageSettings();
+ if (fmt.format() == format)
+ return;
+ fmt.setFormat(format);
+ d->control->setImageSettings(fmt);
+ emit fileFormatChanged();
+}
+
+/*!
+ Returns a list of supported file formats.
+
+ \sa {QImageCapture::}{FileFormat}
+*/
+QList<QImageCapture::FileFormat> QImageCapture::supportedFormats()
+{
+ return QPlatformMediaIntegration::instance()->formatInfo()->imageFormats;
+}
+
+/*!
+ Returns the name of the given format, \a f.
+*/
+QString QImageCapture::fileFormatName(QImageCapture::FileFormat f)
+{
+ const char *name = nullptr;
+ switch (f) {
+ case UnspecifiedFormat:
+ name = "Unspecified image format";
+ break;
+ case JPEG:
+ name = "JPEG";
+ break;
+ case PNG:
+ name = "PNG";
+ break;
+ case WebP:
+ name = "WebP";
+ break;
+ case Tiff:
+ name = "Tiff";
+ break;
+ }
+ return QString::fromUtf8(name);
+}
+
+/*!
+ Returns the description of the given file format, \a f.
+*/
+QString QImageCapture::fileFormatDescription(QImageCapture::FileFormat f)
+{
+ const char *name = nullptr;
+ switch (f) {
+ case UnspecifiedFormat:
+ name = "Unspecified image format";
+ break;
+ case JPEG:
+ name = "JPEG";
+ break;
+ case PNG:
+ name = "PNG";
+ break;
+ case WebP:
+ name = "WebP";
+ break;
+ case Tiff:
+ name = "Tiff";
+ break;
+ }
+ return QString::fromUtf8(name);
+}
+
+/*!
+ Returns the resolution of the encoded image.
+*/
+
+QSize QImageCapture::resolution() const
+{
+ Q_D(const QImageCapture);
+ return d->control ? d->control->imageSettings().resolution() : QSize{};
+}
+
+/*!
+ \fn void QImageCapture::resolutionChanged()
+
+ Signals when the image resolution changes.
+*/
+
+/*!
+ Sets the \a resolution of the encoded image.
+
+ An empty QSize indicates the encoder should make an optimal choice based on
+ what is available from the image source and the limitations of the codec.
+*/
+void QImageCapture::setResolution(const QSize &resolution)
+{
+ Q_D(QImageCapture);
+ if (!d->control)
+ return;
+ auto fmt = d->control->imageSettings();
+ if (fmt.resolution() == resolution)
+ return;
+ fmt.setResolution(resolution);
+ d->control->setImageSettings(fmt);
+ emit resolutionChanged();
+}
+
+/*!
+ Sets the \a width and \a height of the resolution of the encoded image.
+
+ \overload
+*/
+void QImageCapture::setResolution(int width, int height)
+{
+ setResolution(QSize(width, height));
+}
+
+/*!
+ \enum QImageCapture::Quality
+
+ Enumerates quality encoding levels.
+
+ \value VeryLowQuality
+ \value LowQuality
+ \value NormalQuality
+ \value HighQuality
+ \value VeryHighQuality
+*/
+
+/*!
+ \property QImageCapture::quality
+ \brief The image encoding quality.
+*/
+QImageCapture::Quality QImageCapture::quality() const
+{
+ Q_D(const QImageCapture);
+ return d->control ? d->control->imageSettings().quality() : NormalQuality;
+}
+
+/*!
+ Sets the image encoding \a quality.
+*/
+void QImageCapture::setQuality(Quality quality)
+{
+ Q_D(QImageCapture);
+ if (!d->control)
+ return;
+ auto fmt = d->control->imageSettings();
+ if (fmt.quality() == quality)
+ return;
+ fmt.setQuality(quality);
+ d->control->setImageSettings(fmt);
+ emit resolutionChanged();
+}
+
+/*!
+ \internal
+*/
+QPlatformImageCapture *QImageCapture::platformImageCapture()
+{
+ Q_D(QImageCapture);
+ return d->control;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qimagecapture.cpp"
diff --git a/src/multimedia/camera/qimagecapture.h b/src/multimedia/camera/qimagecapture.h
new file mode 100644
index 000000000..48608792a
--- /dev/null
+++ b/src/multimedia/camera/qimagecapture.h
@@ -0,0 +1,135 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCAMERAIMAGECAPTURE_H
+#define QCAMERAIMAGECAPTURE_H
+
+#include <QtCore/qobject.h>
+#include <QtMultimedia/qvideoframe.h>
+
+#include <QtMultimedia/qmediaenumdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSize;
+class QMediaMetaData;
+QT_END_NAMESPACE
+
+QT_BEGIN_NAMESPACE
+
+class QImageEncoderSettings;
+class QCamera;
+class QMediaCaptureSession;
+
+class QImageCapturePrivate;
+class Q_MULTIMEDIA_EXPORT QImageCapture : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool readyForCapture READ isReadyForCapture NOTIFY readyForCaptureChanged)
+ Q_PROPERTY(QMediaMetaData metaData READ metaData WRITE setMetaData NOTIFY metaDataChanged)
+ Q_PROPERTY(Error error READ error NOTIFY errorChanged)
+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
+ Q_PROPERTY(FileFormat fileFormat READ fileFormat NOTIFY setFileFormat NOTIFY fileFormatChanged)
+ Q_PROPERTY(Quality quality READ quality NOTIFY setQuality NOTIFY qualityChanged)
+public:
+ enum Error
+ {
+ NoError,
+ NotReadyError,
+ ResourceError,
+ OutOfSpaceError,
+ NotSupportedFeatureError,
+ FormatError
+ };
+ Q_ENUM(Error)
+
+ enum Quality
+ {
+ VeryLowQuality,
+ LowQuality,
+ NormalQuality,
+ HighQuality,
+ VeryHighQuality
+ };
+ Q_ENUM(Quality)
+
+ enum FileFormat {
+ UnspecifiedFormat,
+ JPEG,
+ PNG,
+ WebP,
+ Tiff,
+ LastFileFormat = Tiff
+ };
+ Q_ENUM(FileFormat)
+
+ explicit QImageCapture(QObject *parent = nullptr);
+ ~QImageCapture();
+
+ bool isAvailable() const;
+
+ QMediaCaptureSession *captureSession() const;
+
+ Error error() const;
+ QString errorString() const;
+
+ bool isReadyForCapture() const;
+
+ FileFormat fileFormat() const;
+ void setFileFormat(FileFormat format);
+
+ static QList<FileFormat> supportedFormats();
+ static QString fileFormatName(FileFormat c);
+ static QString fileFormatDescription(FileFormat c);
+
+ QSize resolution() const;
+ void setResolution(const QSize &);
+ void setResolution(int width, int height);
+
+ Quality quality() const;
+ void setQuality(Quality quality);
+
+ QMediaMetaData metaData() const;
+ void setMetaData(const QMediaMetaData &metaData);
+ void addMetaData(const QMediaMetaData &metaData);
+
+public Q_SLOTS:
+ int captureToFile(const QString &location = QString());
+ int capture();
+
+Q_SIGNALS:
+ void errorChanged();
+ void errorOccurred(int id, QImageCapture::Error error, const QString &errorString);
+
+ void readyForCaptureChanged(bool ready);
+ void metaDataChanged();
+
+ void fileFormatChanged();
+ void qualityChanged();
+ void resolutionChanged();
+
+ void imageExposed(int id);
+ void imageCaptured(int id, const QImage &preview);
+ void imageMetadataAvailable(int id, const QMediaMetaData &metaData);
+ void imageAvailable(int id, const QVideoFrame &frame);
+ void imageSaved(int id, const QString &fileName);
+
+private:
+ // This is here to flag an incompatibilities with Qt 5
+ QImageCapture(QCamera *) = delete;
+
+ friend class QMediaCaptureSession;
+ class QPlatformImageCapture *platformImageCapture();
+ void setCaptureSession(QMediaCaptureSession *session);
+ QImageCapturePrivate *d_ptr;
+ Q_DISABLE_COPY(QImageCapture)
+ Q_DECLARE_PRIVATE(QImageCapture)
+ Q_PRIVATE_SLOT(d_func(), void _q_error(int, int, const QString &))
+};
+
+QT_END_NAMESPACE
+
+Q_MEDIA_ENUM_DEBUG(QImageCapture, Error)
+
+#endif
+
diff --git a/src/multimedia/compat/removed_api.cpp b/src/multimedia/compat/removed_api.cpp
new file mode 100644
index 000000000..567024c8e
--- /dev/null
+++ b/src/multimedia/compat/removed_api.cpp
@@ -0,0 +1,16 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#define QT_MULTIMEDIA_BUILD_REMOVED_API
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+
+QT_USE_NAMESPACE
+
+#if QT_MULTIMEDIA_REMOVED_SINCE(6, 7)
+
+// #include "qotherheader.h"
+// // implement removed functions from qotherheader.h
+// order sections alphabetically
+
+#endif // QT_MULTIMEDIA_REMOVED_SINCE(6, 7)
diff --git a/src/multimedia/configure.cmake b/src/multimedia/configure.cmake
new file mode 100644
index 000000000..5fe25f172
--- /dev/null
+++ b/src/multimedia/configure.cmake
@@ -0,0 +1,212 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+
+
+#### Inputs
+
+
+
+#### Libraries
+
+qt_find_package(ALSA PROVIDED_TARGETS ALSA::ALSA MODULE_NAME multimedia QMAKE_LIB alsa)
+qt_find_package(AVFoundation PROVIDED_TARGETS AVFoundation::AVFoundation MODULE_NAME multimedia QMAKE_LIB avfoundation)
+qt_find_package(GStreamer PROVIDED_TARGETS GStreamer::GStreamer MODULE_NAME multimedia QMAKE_LIB gstreamer_1_0)
+qt_find_package(GStreamer COMPONENTS App PROVIDED_TARGETS GStreamer::App MODULE_NAME multimedia QMAKE_LIB gstreamer_app_1_0)
+qt_add_qmake_lib_dependency(gstreamer_app_1_0 gstreamer_1_0)
+qt_find_package(GStreamer OPTIONAL_COMPONENTS Photography PROVIDED_TARGETS GStreamer::Photography MODULE_NAME multimedia QMAKE_LIB gstreamer_photography_1_0) # special case
+qt_add_qmake_lib_dependency(gstreamer_photography_1_0 gstreamer_1_0)
+qt_find_package(GStreamer OPTIONAL_COMPONENTS Gl PROVIDED_TARGETS GStreamer::Gl MODULE_NAME multimedia QMAKE_LIB gstreamer_gl_1_0) # special case
+qt_add_qmake_lib_dependency(gstreamer_gl_1_0 gstreamer_1_0)
+qt_find_package(MMRendererCore PROVIDED_TARGETS MMRendererCore::MMRendererCore MODULE_NAME multimedia QMAKE_LIB mmrndcore)
+qt_find_package(MMRenderer PROVIDED_TARGETS MMRenderer::MMRenderer MODULE_NAME multimedia QMAKE_LIB mmrndclient)
+qt_find_package(WrapPulseAudio PROVIDED_TARGETS WrapPulseAudio::WrapPulseAudio MODULE_NAME multimedia QMAKE_LIB pulseaudio)
+qt_find_package(WMF PROVIDED_TARGETS WMF::WMF MODULE_NAME multimedia QMAKE_LIB wmf)
+if(TARGET EGL::EGL)
+ qt_internal_disable_find_package_global_promotion(EGL::EGL)
+endif()
+qt_find_package(EGL PROVIDED_TARGETS EGL::EGL)
+
+
+qt_find_package(FFmpeg OPTIONAL_COMPONENTS AVCODEC AVFORMAT AVUTIL SWRESAMPLE SWSCALE PROVIDED_TARGETS FFmpeg::avcodec FFmpeg::avformat FFmpeg::avutil FFmpeg::swresample FFmpeg::swscale MODULE_NAME multimedia QMAKE_LIB ffmpeg)
+qt_find_package(VAAPI COMPONENTS VA DRM PROVIDED_TARGETS VAAPI::VAAPI MODULE_NAME multimedia QMAKE_LIB vaapi)
+
+#### Tests
+
+
+qt_config_compile_test("evr"
+ LABEL "evr.h"
+ PROJECT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../config.tests/evr"
+)
+
+qt_config_compile_test("gpu_vivante"
+ LABEL "Vivante GPU"
+ PROJECT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../config.tests/gpu_vivante"
+)
+
+qt_config_compile_test("linux_v4l"
+ LABEL "Video for Linux"
+ PROJECT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../config.tests/linux_v4l"
+)
+
+qt_config_compile_test("wmsdk"
+ LABEL "wmsdk.h"
+ PROJECT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../config.tests/wmsdk"
+)
+qt_config_compile_test(linux_dmabuf
+ LABEL "Linux DMA buffer support"
+ LIBRARIES
+ EGL::EGL
+ CODE
+"#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+int main(int, char **)
+{
+ /* BEGIN TEST: */
+ eglCreateImage(nullptr,
+ EGL_NO_CONTEXT,
+ EGL_LINUX_DMA_BUF_EXT,
+ nullptr,
+ nullptr);
+ /* END TEST: */
+ return 0;
+}
+")
+
+#### Features
+
+qt_feature("ffmpeg" PRIVATE
+ LABEL "FFmpeg"
+ ENABLE INPUT_ffmpeg STREQUAL 'yes'
+ DISABLE INPUT_ffmpeg STREQUAL 'no'
+ CONDITION FFmpeg_FOUND AND (APPLE OR WIN32 OR ANDROID OR QNX OR QT_FEATURE_pulseaudio)
+)
+qt_feature("alsa" PUBLIC PRIVATE
+ LABEL "ALSA (experimental)"
+ AUTODETECT false
+ CONDITION UNIX AND NOT QNX AND ALSA_FOUND AND NOT QT_FEATURE_pulseaudio
+)
+qt_feature("avfoundation" PUBLIC PRIVATE
+ LABEL "AVFoundation"
+ CONDITION AVFoundation_FOUND
+)
+qt_feature("coreaudio" PUBLIC PRIVATE
+ LABEL "CoreAudio"
+ CONDITION AVFoundation_FOUND
+)
+qt_feature("videotoolbox" PUBLIC PRIVATE
+ LABEL "VideoToolbox"
+ CONDITION AVFoundation_FOUND
+)
+qt_feature("evr" PUBLIC PRIVATE
+ LABEL "evr.h"
+ CONDITION WIN32 AND TEST_evr
+)
+qt_feature("gstreamer_1_0" PRIVATE
+ LABEL "GStreamer 1.0"
+ CONDITION GStreamer_FOUND
+)
+qt_feature("gstreamer_app" PRIVATE
+ LABEL "GStreamer App"
+ CONDITION ( QT_FEATURE_gstreamer_1_0 AND GStreamer_App_FOUND )
+)
+qt_feature("gstreamer_photography" PRIVATE
+ LABEL "GStreamer Photography"
+ CONDITION ( QT_FEATURE_gstreamer_1_0 AND GStreamer_Photography_FOUND )
+)
+qt_feature("gstreamer_gl" PRIVATE
+ LABEL "GStreamer OpenGL"
+ CONDITION QT_FEATURE_opengl AND QT_FEATURE_gstreamer_1_0 AND GStreamer_Gl_FOUND AND EGL_FOUND
+)
+qt_feature("gstreamer" PRIVATE
+ LABEL "QtMM GStreamer plugin"
+ CONDITION (QT_FEATURE_gstreamer_1_0 AND QT_FEATURE_gstreamer_app)
+ ENABLE INPUT_gstreamer STREQUAL 'yes'
+ DISABLE INPUT_gstreamer STREQUAL 'no'
+)
+
+qt_feature("gpu_vivante" PRIVATE
+ LABEL "Vivante GPU"
+ CONDITION QT_FEATURE_gui AND QT_FEATURE_opengles2 AND TEST_gpu_vivante
+)
+qt_feature("linux_v4l" PRIVATE
+ LABEL "Video for Linux"
+ CONDITION UNIX AND TEST_linux_v4l
+)
+qt_feature("linux_dmabuf" PRIVATE
+ LABEL "Linux DMA buffer support"
+ CONDITION UNIX AND TEST_linux_dmabuf
+)
+qt_feature("vaapi" PRIVATE
+ LABEL "VAAPI support"
+ CONDITION UNIX AND VAAPI_FOUND AND QT_FEATURE_linux_dmabuf
+)
+qt_feature("mmrenderer" PUBLIC PRIVATE
+ LABEL "MMRenderer"
+ CONDITION MMRenderer_FOUND AND MMRendererCore_FOUND
+ EMIT_IF QNX
+)
+qt_feature("pulseaudio" PUBLIC PRIVATE
+ LABEL "PulseAudio"
+ DISABLE INPUT_pulseaudio STREQUAL 'no'
+ CONDITION WrapPulseAudio_FOUND
+)
+qt_feature("wmsdk" PRIVATE
+ LABEL "Windows Media SDK"
+ CONDITION WIN32 AND TEST_wmsdk
+)
+qt_feature("opensles" PRIVATE
+ LABEL "Open SLES (Android)"
+ CONDITION ANDROID
+)
+qt_feature("wasm" PRIVATE
+ LABEL "Web Assembly"
+ CONDITION WASM
+)
+
+qt_feature("wmf" PRIVATE
+ LABEL "Windows Media Foundation"
+ CONDITION WIN32 AND WMF_FOUND AND QT_FEATURE_wmsdk
+)
+
+qt_feature("spatialaudio" PRIVATE
+ LABEL "Spatial Audio"
+)
+qt_feature("spatialaudio_quick3d" PRIVATE
+ LABEL "Spatial Audio (Quick3D)"
+ CONDITION TARGET Qt::Quick3D AND QT_FEATURE_spatialaudio
+)
+
+qt_configure_add_summary_section(NAME "Qt Multimedia")
+qt_configure_add_summary_entry(ARGS "spatialaudio")
+qt_configure_add_summary_entry(ARGS "spatialaudio_quick3d")
+qt_configure_add_summary_section(NAME "Low level Audio Backend")
+qt_configure_add_summary_entry(ARGS "alsa")
+qt_configure_add_summary_entry(ARGS "pulseaudio")
+qt_configure_add_summary_entry(ARGS "mmrenderer")
+qt_configure_add_summary_entry(ARGS "coreaudio")
+qt_configure_add_summary_entry(ARGS "wmsdk")
+qt_configure_add_summary_entry(ARGS "opensles")
+qt_configure_add_summary_entry(ARGS "wasm")
+qt_configure_end_summary_section()
+qt_configure_add_summary_section(NAME "Plugin")
+qt_configure_add_summary_entry(ARGS "gstreamer_1_0")
+qt_configure_add_summary_entry(ARGS "ffmpeg")
+qt_configure_add_summary_entry(ARGS "mmrenderer")
+qt_configure_add_summary_entry(ARGS "avfoundation")
+qt_configure_add_summary_entry(ARGS "wmf")
+qt_configure_end_summary_section()
+qt_configure_add_summary_section(NAME "Hardware acceleration and features")
+qt_configure_add_summary_entry(ARGS "linux_v4l")
+qt_configure_add_summary_entry(ARGS "vaapi")
+qt_configure_add_summary_entry(ARGS "linux_dmabuf")
+qt_configure_add_summary_entry(ARGS "videotoolbox")
+qt_configure_end_summary_section()
+qt_configure_end_summary_section() # end of "Qt Multimedia" section
+
+qt_configure_add_report_entry(
+ TYPE WARNING
+ MESSAGE "No backend for low level audio found."
+ CONDITION NOT QT_FEATURE_alsa AND NOT QT_FEATURE_pulseaudio AND NOT QT_FEATURE_mmrenderer AND NOT QT_FEATURE_coreaudio AND NOT QT_FEATURE_wmsdk AND NOT ANDROID AND NOT WASM
+)
diff --git a/src/multimedia/configure.json b/src/multimedia/configure.json
deleted file mode 100644
index d50f8c015..000000000
--- a/src/multimedia/configure.json
+++ /dev/null
@@ -1,300 +0,0 @@
-{
- "module": "multimedia",
- "depends": [
- "gui"
- ],
- "condition": "module.gui",
- "testDir": "../../config.tests",
-
- "commandline": {
- "options": {
- "alsa": "boolean",
- "evr": { "type": "boolean" },
- "directshow": { "type": "boolean" },
- "wmf": { "type": "boolean" },
- "gstreamer": { "type": "optionalString", "values": [ "no", "yes", "0.10", "1.0" ] },
- "pulseaudio": "boolean"
- }
- },
-
- "libraries": {
- "alsa": {
- "label": "ALSA",
- "test": "alsa",
- "sources": [
- "-lasound"
- ]
- },
- "avfoundation": {
- "label": "AVFoundation",
- "test": "avfoundation",
- "sources": [
- { "libs": "-framework AVFoundation -framework Foundation" }
- ]
- },
- "directshow": {
- "label": "DirectShow",
- "test": "directshow",
- "sources": [
- { "libs": "-lstrmiids -ldmoguids -luuid -lmsdmo -lole32 -loleaut32" }
- ]
- },
- "gstreamer_0_10": {
- "label": "GStreamer 0.10",
- "export": "gstreamer",
- "test": "gstreamer",
- "sources": [
- { "type": "pkgConfig",
- "args": "gstreamer-0.10 gstreamer-base-0.10 gstreamer-audio-0.10 gstreamer-video-0.10 gstreamer-pbutils-0.10 gstreamer-interfaces-0.10" }
- ]
- },
- "gstreamer_1_0": {
- "label": "GStreamer 1.0",
- "export": "gstreamer",
- "test": "gstreamer",
- "sources": [
- { "type": "pkgConfig",
- "args": "gstreamer-1.0 gstreamer-base-1.0 gstreamer-audio-1.0 gstreamer-video-1.0 gstreamer-pbutils-1.0 gstreamer-allocators-1.0" },
- { "libs": "-lgstreamer-1.0 -lgstbase-1.0 -lgstaudio-1.0 -lgstvideo-1.0 -lgstpbutils-1.0 -lglib-2.0 -lgobject-2.0",
- "condition": "config.win32 || config.macos" },
- { "libs": "", "condition": "config.android && input.gstreamer != ''" }
- ]
- },
- "gstreamer_app_0_10": {
- "label": "GStreamer App 0.10",
- "export": "gstreamer_app",
- "test": "gstreamer_appsrc",
- "use": "gstreamer_0_10",
- "sources": [
- { "type": "pkgConfig", "args": "gstreamer-app-0.10" }
- ]
- },
- "gstreamer_app_1_0": {
- "label": "GStreamer App 1.0",
- "export": "gstreamer_app",
- "test": "gstreamer_appsrc",
- "use": "gstreamer_1_0",
- "sources": [
- { "type": "pkgConfig", "args": "gstreamer-app-1.0" },
- { "libs": "-lgstapp-1.0", "condition": "config.win32 || config.macos" },
- { "libs": "", "condition": "config.android && input.gstreamer != ''" }
- ]
- },
- "gstreamer_photography_0_10": {
- "label": "GStreamer Photography 0.10",
- "export": "gstreamer_photography",
- "test": "gstreamer_photography",
- "use": "gstreamer_0_10",
- "sources": [
- { "libs": "-lgstphotography-0.10" }
- ]
- },
- "gstreamer_photography_1_0": {
- "label": "GStreamer Photography 1.0",
- "export": "gstreamer_photography",
- "test": "gstreamer_photography",
- "use": "gstreamer_1_0",
- "sources": [
- { "libs": "-lgstphotography-1.0" }
- ]
- },
- "gstreamer_gl_1_0": {
- "label": "GStreamer OpenGL 1.0",
- "export": "gstreamer_gl",
- "test": {
- "include": "gst/gl/gl.h"
- },
- "use": "gstreamer_1_0",
- "sources": [
- { "type": "pkgConfig", "args": "gstreamer-gl-1.0" }
- ]
- },
- "libresourceqt5": {
- "label": "libresourceqt5",
- "test": "resourcepolicy",
- "sources": [
- { "type": "pkgConfig", "args": "libresourceqt5" }
- ]
- },
- "mmrenderer": {
- "label": "MMRenderer",
- "test": "mmrenderer",
- "sources": [
- { "libs": "-lmmrndclient -lstrm" }
- ]
- },
- "pulseaudio": {
- "label": "PulseAudio >= 0.9.10",
- "test": "pulseaudio",
- "sources": [
- { "type": "pkgConfig", "args": "libpulse >= 0.9.10 libpulse-mainloop-glib" }
- ]
- },
- "wmf": {
- "label": "WMF",
- "test": "wmf",
- "sources": [
- { "libs": "-lstrmiids -ldmoguids -luuid -lmsdmo -lole32 -loleaut32 -lMf -lMfuuid -lMfplat -lPropsys" }
- ]
- }
- },
-
- "tests": {
- "evr": {
- "label": "evr.h",
- "type": "compile",
- "test": "evr"
- },
- "gstreamer_encodingprofiles": {
- "label": "GStreamer encoding-profile.h",
- "type": "compile",
- "use": "gstreamer",
- "test": "gstreamer_encodingprofiles"
- },
- "gpu_vivante": {
- "label": "Vivante GPU",
- "type": "compile",
- "test": "gpu_vivante"
- },
- "linux_v4l": {
- "label": "Video for Linux",
- "type": "compile",
- "test": "linux_v4l"
- },
- "wmsdk": {
- "label": "wmsdk.h",
- "type": "compile",
- "test": "wmsdk"
- },
- "wshellitem": {
- "label": "WShellItem",
- "type": "compile",
- "test": "wshellitem"
- }
- },
-
- "features": {
- "alsa": {
- "label": "ALSA",
- "condition": "config.unix && !config.qnx && libs.alsa",
- "output": [ "feature", "privateFeature" ]
- },
- "avfoundation": {
- "label": "AVFoundation",
- "emitIf": "config.darwin",
- "condition": "libs.avfoundation",
- "output": [ "feature", "privateFeature" ]
- },
- "directshow": {
- "label": "DirectShow",
- "condition": "config.win32 && libs.directshow",
- "output": [ "feature", "privateFeature" ]
- },
- "evr": {
- "label": "evr.h",
- "condition": "config.win32 && tests.evr",
- "output": [ "feature", "privateFeature" ]
- },
- "gstreamer_0_10": {
- "label": "GStreamer 0.10",
- "disable": "input.gstreamer == '1.0' || input.gstreamer == 'no'",
- "enable": "input.gstreamer == '0.10'",
- "condition": "!features.gstreamer_1_0 && libs.gstreamer_0_10",
- "output": [ "privateFeature" ]
- },
- "gstreamer_1_0": {
- "label": "GStreamer 1.0",
- "disable": "input.gstreamer == '0.10' || input.gstreamer == 'no'",
- "enable": "input.gstreamer == '1.0'",
- "condition": "libs.gstreamer_1_0",
- "output": [ "privateFeature" ]
- },
- "gstreamer": {
- "condition": "features.gstreamer_1_0 || features.gstreamer_0_10",
- "output": [ "privateFeature" ]
- },
- "gstreamer_app": {
- "label": "GStreamer App",
- "condition": "(features.gstreamer_1_0 && libs.gstreamer_app_1_0) || (features.gstreamer_0_10 && libs.gstreamer_app_0_10)",
- "output": [ "privateFeature" ]
- },
- "gstreamer_encodingprofiles": {
- "label": "GStreamer encoding-profile.h",
- "condition": "features.gstreamer && tests.gstreamer_encodingprofiles",
- "output": [ "privateFeature" ]
- },
- "gstreamer_photography": {
- "label": "GStreamer Photography",
- "condition": "(features.gstreamer_1_0 && libs.gstreamer_photography_1_0) || (features.gstreamer_0_10 && libs.gstreamer_photography_0_10)",
- "output": [ "privateFeature" ]
- },
- "gstreamer_gl": {
- "label": "GStreamer OpenGL",
- "condition": "features.opengl && features.gstreamer_1_0 && libs.gstreamer_gl_1_0",
- "output": [ "privateFeature" ]
- },
- "gpu_vivante": {
- "label": "Vivante GPU",
- "condition": "features.gui && features.opengles2 && tests.gpu_vivante",
- "output": [ "privateFeature" ]
- },
- "resourcepolicy": {
- "label": "Resource Policy (libresourceqt5)",
- "condition": "libs.libresourceqt5",
- "output": [ "privateFeature" ]
- },
- "linux_v4l": {
- "label": "Video for Linux",
- "condition": "config.unix && tests.linux_v4l",
- "output": [ "privateFeature" ]
- },
- "mmrenderer": {
- "label": "MMRenderer",
- "emitIf": "config.qnx",
- "condition": "libs.mmrenderer",
- "output": [ "feature", "privateFeature" ]
- },
- "pulseaudio": {
- "label": "PulseAudio",
- "autoDetect": "config.unix",
- "condition": "libs.pulseaudio",
- "output": [ "feature", "privateFeature" ]
- },
- "wmsdk": {
- "label": "wmsdk.h",
- "condition": "config.win32 && tests.wmsdk",
- "output": [ "privateFeature" ]
- },
- "wshellitem": {
- "label": "WShellItem",
- "condition": "config.win32 && features.directshow && tests.wshellitem",
- "output": [ "feature", "privateFeature" ]
- },
- "wmf": {
- "label": "Windows Media Foundation",
- "condition": "config.win32 && libs.wmf",
- "output": [ "privateFeature" ]
- }
- },
-
- "report": [
- ],
-
- "summary": [
- {
- "section": "Qt Multimedia",
- "entries": [
- "alsa",
- "gstreamer_1_0",
- "gstreamer_0_10",
- "linux_v4l",
- "pulseaudio",
- "resourcepolicy",
- "mmrenderer",
- "avfoundation",
- "directshow",
- "wmf"
- ]
- }
- ]
-}
diff --git a/src/multimedia/controls/controls.pri b/src/multimedia/controls/controls.pri
deleted file mode 100644
index c0eb28936..000000000
--- a/src/multimedia/controls/controls.pri
+++ /dev/null
@@ -1,80 +0,0 @@
-
-INCLUDEPATH += controls
-
-PUBLIC_HEADERS += \
- controls/qaudiodecodercontrol.h \
- controls/qaudioencodersettingscontrol.h \
- controls/qaudioinputselectorcontrol.h \
- controls/qaudiooutputselectorcontrol.h \
- controls/qcameracapturebufferformatcontrol.h \
- controls/qcameracapturedestinationcontrol.h \
- controls/qcameracontrol.h \
- controls/qcamerainfocontrol.h \
- controls/qcameraexposurecontrol.h \
- controls/qcamerafeedbackcontrol.h \
- controls/qcameraflashcontrol.h \
- controls/qcamerafocuscontrol.h \
- controls/qcamerazoomcontrol.h \
- controls/qcameraimagecapturecontrol.h \
- controls/qcameraimageprocessingcontrol.h \
- controls/qcameralockscontrol.h \
- controls/qcameraviewfindersettingscontrol.h \
- controls/qimageencodercontrol.h \
- controls/qmediacontainercontrol.h \
- controls/qmediagaplessplaybackcontrol.h \
- controls/qmediaplayercontrol.h \
- controls/qmediarecordercontrol.h \
- controls/qmediastreamscontrol.h \
- controls/qmetadatareadercontrol.h \
- controls/qmetadatawritercontrol.h \
- controls/qvideodeviceselectorcontrol.h \
- controls/qvideoencodersettingscontrol.h \
- controls/qvideorenderercontrol.h \
- controls/qvideowindowcontrol.h \
- controls/qmediaaudioprobecontrol.h \
- controls/qmediavideoprobecontrol.h \
- controls/qmediaavailabilitycontrol.h \
- controls/qaudiorolecontrol.h \
- controls/qcustomaudiorolecontrol.h
-
-PRIVATE_HEADERS += \
- controls/qmediaplaylistcontrol_p.h \
- controls/qmediaplaylistsourcecontrol_p.h
-
-SOURCES += \
- controls/qcameracapturebufferformatcontrol.cpp \
- controls/qcameracapturedestinationcontrol.cpp \
- controls/qcameracontrol.cpp \
- controls/qcamerainfocontrol.cpp \
- controls/qcameraexposurecontrol.cpp \
- controls/qcamerafeedbackcontrol.cpp \
- controls/qcameraflashcontrol.cpp \
- controls/qcamerafocuscontrol.cpp \
- controls/qcamerazoomcontrol.cpp \
- controls/qcameraimagecapturecontrol.cpp \
- controls/qcameraimageprocessingcontrol.cpp \
- controls/qcameralockscontrol.cpp \
- controls/qcameraviewfindersettingscontrol.cpp \
- controls/qimageencodercontrol.cpp \
- controls/qmediacontainercontrol.cpp \
- controls/qmediagaplessplaybackcontrol.cpp \
- controls/qmediaplayercontrol.cpp \
- controls/qmediaplaylistcontrol.cpp \
- controls/qmediaplaylistsourcecontrol.cpp \
- controls/qmediarecordercontrol.cpp \
- controls/qmediastreamscontrol.cpp \
- controls/qmetadatareadercontrol.cpp \
- controls/qmetadatawritercontrol.cpp \
- controls/qvideorenderercontrol.cpp \
- controls/qvideowindowcontrol.cpp \
- controls/qmediaaudioprobecontrol.cpp \
- controls/qmediavideoprobecontrol.cpp \
- controls/qmediaavailabilitycontrol.cpp \
- controls/qaudiodecodercontrol.cpp \
- controls/qvideoencodersettingscontrol.cpp \
- controls/qaudioencodersettingscontrol.cpp \
- controls/qaudioinputselectorcontrol.cpp \
- controls/qaudiooutputselectorcontrol.cpp \
- controls/qvideodeviceselectorcontrol.cpp \
- controls/qaudiorolecontrol.cpp \
- controls/qcustomaudiorolecontrol.cpp
diff --git a/src/multimedia/controls/qaudiodecodercontrol.cpp b/src/multimedia/controls/qaudiodecodercontrol.cpp
deleted file mode 100644
index 711303174..000000000
--- a/src/multimedia/controls/qaudiodecodercontrol.cpp
+++ /dev/null
@@ -1,267 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediacontrol_p.h"
-#include "qaudiodecodercontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-
-/*!
- \class QAudioDecoderControl
- \obsolete
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- \brief The QAudioDecoderControl class provides access to the audio decoding
- functionality of a QMediaService.
-
- \preliminary
-
- The functionality provided by this control is exposed to application
- code through the QAudioDecoder class.
-
- The interface name of QAudioDecoderControl is \c org.qt-project.qt.audiodecodercontrol/5.0 as
- defined in QAudioDecoderControl_iid.
-
- \sa QMediaService::requestControl(), QAudioDecoder
-*/
-
-/*!
- \macro QAudioDecoderControl_iid
-
- \c org.qt-project.qt.audiodecodercontrol/5.0
-
- Defines the interface name of the QAudioDecoderControl class.
-
- \relates QAudioDecoderControl
-*/
-
-/*!
- Destroys an audio decoder control.
-*/
-QAudioDecoderControl::~QAudioDecoderControl()
-{
-}
-
-/*!
- Constructs a new audio decoder control with the given \a parent.
-*/
-QAudioDecoderControl::QAudioDecoderControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- \fn QAudioDecoderControl::state() const
-
- Returns the state of a player control.
-*/
-
-/*!
- \fn QAudioDecoderControl::stateChanged(QAudioDecoder::State newState)
-
- Signals that the state of a player control has changed to \a newState.
-
- \sa state()
-*/
-
-/*!
- \fn QAudioDecoderControl::sourceFilename() const
-
- Returns the current media source filename, or a null QString if none (or a device)
-*/
-
-/*!
- \fn QAudioDecoderControl::setSourceFilename(const QString &fileName)
-
- Sets the current source to \a fileName. Changing the source will
- stop any current decoding and discard any buffers.
-
- Sources are exclusive, so only one can be set.
-*/
-
-/*!
- \fn QAudioDecoderControl::sourceDevice() const
-
- Returns the current media source QIODevice, or 0 if none (or a file).
-*/
-
-/*!
- \fn QAudioDecoderControl::setSourceDevice(QIODevice *device)
-
- Sets the current source to \a device. Changing the source will
- stop any current decoding and discard any buffers.
-
- Sources are exclusive, so only one can be set.
-*/
-
-/*!
- \fn QAudioDecoderControl::start()
-
- Starts decoding the current media.
-
- If successful the player control will immediately enter the \l {QAudioDecoder::DecodingState}
- {decoding} state.
-
- \sa state(), read()
-*/
-
-/*!
- \fn QAudioDecoderControl::stop()
-
- Stops playback of the current media and discards any buffers.
-
- If successful the player control will immediately enter the \l {QAudioDecoder::StoppedState}
- {stopped} state.
-*/
-
-/*!
- \fn QAudioDecoderControl::error(int error, const QString &errorString)
-
- Signals that an \a error has occurred. The \a errorString provides a more detailed explanation.
-*/
-
-/*!
- \fn QAudioDecoderControl::bufferAvailableChanged(bool available)
-
- Signals that the bufferAvailable property has changed to \a available.
-*/
-
-/*!
- \fn QAudioDecoderControl::bufferReady()
-
- Signals that a new buffer is ready for reading.
-*/
-
-/*!
- \fn QAudioDecoderControl::bufferAvailable() const
-
- Returns true if a buffer is available to be read,
- and false otherwise.
-*/
-
-/*!
- \fn QAudioDecoderControl::sourceChanged()
-
- Signals that the current source of the decoder has changed.
-
- \sa sourceFilename(), sourceDevice()
-*/
-
-/*!
- \fn QAudioDecoderControl::formatChanged(const QAudioFormat &format)
-
- Signals that the current audio format of the decoder has changed to \a format.
-
- \sa audioFormat(), setAudioFormat()
-*/
-
-/*!
- \fn void QAudioDecoderControl::finished()
-
- Signals that the decoding has finished successfully.
- If decoding fails, error signal is emitted instead.
-
- \sa start(), stop(), error()
-*/
-
-/*!
- \fn void QAudioDecoderControl::positionChanged(qint64 position)
-
- Signals that the current \a position of the decoder has changed.
-
- \sa durationChanged()
-*/
-
-/*!
- \fn void QAudioDecoderControl::durationChanged(qint64 duration)
-
- Signals that the estimated \a duration of the decoded data has changed.
-
- \sa positionChanged()
-*/
-
-/*!
- \fn QAudioDecoderControl::audioFormat() const
- Returns the current audio format of the decoded stream.
-
- Any buffers returned should have this format.
-
- \sa setAudioFormat(), formatChanged()
-*/
-
-/*!
- \fn QAudioDecoderControl::setAudioFormat(const QAudioFormat &format)
- Set the desired audio format for decoded samples to \a format.
-
- If the decoder does not support this format, \l error() will
- be set to \c FormatError.
-
- If you do not specify a format, the format of the decoded
- audio itself will be used. Otherwise, some format conversion
- will be applied.
-
- If you wish to reset the decoded format to that of the original
- audio file, you can specify an invalid \a format.
-*/
-
-/*!
- \fn QAudioDecoderControl::read()
- Attempts to read a buffer from the decoder, without blocking. Returns invalid buffer if there are
- no decoded buffers available, or on error.
-*/
-
-/*!
- \fn QAudioDecoderControl::position() const
- Returns position (in milliseconds) of the last buffer read from
- the decoder or -1 if no buffers have been read.
-*/
-
-/*!
- \fn QAudioDecoderControl::duration() const
- Returns total duration (in milliseconds) of the audio stream
- or -1 if not available.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qaudiodecodercontrol.cpp"
diff --git a/src/multimedia/controls/qaudiodecodercontrol.h b/src/multimedia/controls/qaudiodecodercontrol.h
deleted file mode 100644
index 6ab27ba62..000000000
--- a/src/multimedia/controls/qaudiodecodercontrol.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIODECODERCONTROL_H
-#define QAUDIODECODERCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qaudiodecoder.h>
-
-#include <QtCore/qpair.h>
-
-#include <QtMultimedia/qaudiobuffer.h>
-
-QT_BEGIN_NAMESPACE
-
-class QIODevice;
-class Q_MULTIMEDIA_EXPORT QAudioDecoderControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- ~QAudioDecoderControl();
-
- virtual QAudioDecoder::State state() const = 0;
-
- virtual QString sourceFilename() const = 0;
- virtual void setSourceFilename(const QString &fileName) = 0;
-
- virtual QIODevice* sourceDevice() const = 0;
- virtual void setSourceDevice(QIODevice *device) = 0;
-
- virtual void start() = 0;
- virtual void stop() = 0;
-
- virtual QAudioFormat audioFormat() const = 0;
- virtual void setAudioFormat(const QAudioFormat &format) = 0;
-
- virtual QAudioBuffer read() = 0;
- virtual bool bufferAvailable() const = 0;
-
- virtual qint64 position() const = 0;
- virtual qint64 duration() const = 0;
-
-Q_SIGNALS:
- void stateChanged(QAudioDecoder::State newState);
- void formatChanged(const QAudioFormat &format);
- void sourceChanged();
-
- void error(int error, const QString &errorString);
-
- void bufferReady();
- void bufferAvailableChanged(bool available);
- void finished();
-
- void positionChanged(qint64 position);
- void durationChanged(qint64 duration);
-
-protected:
- explicit QAudioDecoderControl(QObject *parent = nullptr);
-};
-
-#define QAudioDecoderControl_iid "org.qt-project.qt.audiodecodercontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QAudioDecoderControl, QAudioDecoderControl_iid)
-
-QT_END_NAMESPACE
-
-#endif // QAUDIODECODERCONTROL_H
diff --git a/src/multimedia/controls/qaudioencodersettingscontrol.cpp b/src/multimedia/controls/qaudioencodersettingscontrol.cpp
deleted file mode 100644
index 5ae473178..000000000
--- a/src/multimedia/controls/qaudioencodersettingscontrol.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qaudioencodersettingscontrol.h"
-#include <QtCore/qstringlist.h>
-
-QT_BEGIN_NAMESPACE
-
-
-/*!
- \class QAudioEncoderSettingsControl
- \obsolete
- \inmodule QtMultimedia
-
- \ingroup multimedia_control
-
- \brief The QAudioEncoderSettingsControl class provides access to the settings of a
- media service that performs audio encoding.
-
- If a QMediaService supports encoding audio data it will implement
- QAudioEncoderSettingsControl. This control provides information about the limits
- of restricted audio encoder options and allows the selection of a set of
- audio encoder settings as specified in a QAudioEncoderSettings object.
-
- The functionality provided by this control is exposed to application code through the
- QMediaRecorder class.
-
- The interface name of QAudioEncoderSettingsControl is \c org.qt-project.qt.audioencodersettingscontrol/5.0 as
- defined in QAudioEncoderSettingsControl_iid.
-
- \sa QMediaService::requestControl(), QMediaRecorder
-*/
-
-/*!
- \macro QAudioEncoderSettingsControl_iid
-
- \c org.qt-project.qt.audioencodersettingscontrol/5.0
-
- Defines the interface name of the QAudioEncoderSettingsControl class.
-
- \relates QAudioEncoderSettingsControl
-*/
-
-/*!
- Create a new audio encoder settings control object with the given \a parent.
-*/
-QAudioEncoderSettingsControl::QAudioEncoderSettingsControl(QObject *parent)
- :QMediaControl(parent)
-{
-}
-
-/*!
- Destroys the audio encoder settings control.
-*/
-QAudioEncoderSettingsControl::~QAudioEncoderSettingsControl()
-{
-}
-
-/*!
- \fn QAudioEncoderSettingsControl::supportedAudioCodecs() const
-
- Returns the list of supported audio codec names.
-*/
-
-/*!
- \fn QAudioEncoderSettingsControl::codecDescription(const QString &codecName) const
-
- Returns the description of audio codec \a codecName.
-*/
-
-/*!
- \fn QAudioEncoderSettingsControl::supportedSampleRates(const QAudioEncoderSettings &settings = QAudioEncoderSettings(),
- bool *continuous) const
-
- Returns the list of supported audio sample rates, if known.
-
- If non null audio \a settings parameter is passed,
- the returned list is reduced to sample rates supported with partial settings applied.
-
- It can be used for example to query the list of sample rates, supported by specific audio codec.
-
- If the encoder supports arbitrary sample rates within the supported rates range,
- *\a continuous is set to true, otherwise *\a continuous is set to false.
-*/
-
-/*!
- \fn QAudioEncoderSettingsControl::audioSettings() const
-
- Returns the audio encoder settings.
-
- The returned value may be different tha passed to QAudioEncoderSettingsControl::setAudioSettings()
- if the settings contains the default or undefined parameters.
- In this case if the undefined parameters are already resolved, they should be returned.
-*/
-
-/*!
- \fn QAudioEncoderSettingsControl::setAudioSettings(const QAudioEncoderSettings &settings)
-
- Sets the selected audio \a settings.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qaudioencodersettingscontrol.cpp"
diff --git a/src/multimedia/controls/qaudioencodersettingscontrol.h b/src/multimedia/controls/qaudioencodersettingscontrol.h
deleted file mode 100644
index b4c3abafd..000000000
--- a/src/multimedia/controls/qaudioencodersettingscontrol.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIOENCODERSETTINGSCONTROL_H
-#define QAUDIOENCODERSETTINGSCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediarecorder.h>
-#include <QtCore/qlist.h>
-#include <QtCore/qpair.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAudioFormat;
-QT_END_NAMESPACE
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QAudioEncoderSettingsControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QAudioEncoderSettingsControl();
-
- virtual QStringList supportedAudioCodecs() const = 0;
- virtual QString codecDescription(const QString &codecName) const = 0;
-
- virtual QList<int> supportedSampleRates(const QAudioEncoderSettings &settings,
- bool *continuous = nullptr) const = 0;
-
- virtual QAudioEncoderSettings audioSettings() const = 0;
- virtual void setAudioSettings(const QAudioEncoderSettings &settings) = 0;
-
-protected:
- explicit QAudioEncoderSettingsControl(QObject *parent = nullptr);
-};
-
-#define QAudioEncoderSettingsControl_iid "org.qt-project.qt.audioencodersettingscontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QAudioEncoderSettingsControl, QAudioEncoderSettingsControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QAUDIOENCODERSETTINGSCONTROL_H
diff --git a/src/multimedia/controls/qaudioinputselectorcontrol.cpp b/src/multimedia/controls/qaudioinputselectorcontrol.cpp
deleted file mode 100644
index 649891225..000000000
--- a/src/multimedia/controls/qaudioinputselectorcontrol.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qaudioinputselectorcontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QAudioInputSelectorControl
- \obsolete
-
- \brief The QAudioInputSelectorControl class provides an audio input selector media control.
- \inmodule QtMultimedia
- \ingroup multimedia_control
-
- The QAudioInputSelectorControl class provides descriptions of the audio
- inputs available on a system and allows one to be selected as the audio
- input of a media service.
-
- The interface name of QAudioInputSelectorControl is \c org.qt-project.qt.audioinputselectorcontrol/5.0 as
- defined in QAudioInputSelectorControl_iid.
-
- \sa QMediaService::requestControl()
-*/
-
-/*!
- \macro QAudioInputSelectorControl_iid
-
- \c org.qt-project.qt.audioinputselectorcontrol/5.0
-
- Defines the interface name of the QAudioInputSelectorControl class.
-
- \relates QAudioInputSelectorControl
-*/
-
-/*!
- Constructs a new audio input selector control with the given \a parent.
-*/
-QAudioInputSelectorControl::QAudioInputSelectorControl(QObject *parent)
- :QMediaControl(parent)
-{
-}
-
-/*!
- Destroys an audio input selector control.
-*/
-QAudioInputSelectorControl::~QAudioInputSelectorControl()
-{
-}
-
-/*!
- \fn QList<QString> QAudioInputSelectorControl::availableInputs() const
-
- Returns a list of the names of the available audio inputs.
-*/
-
-/*!
- \fn QString QAudioInputSelectorControl::inputDescription(const QString& name) const
-
- Returns the description of the input \a name.
-*/
-
-/*!
- \fn QString QAudioInputSelectorControl::defaultInput() const
-
- Returns the name of the default audio input.
-*/
-
-/*!
- \fn QString QAudioInputSelectorControl::activeInput() const
-
- Returns the name of the currently selected audio input.
-*/
-
-/*!
- \fn QAudioInputSelectorControl::setActiveInput(const QString& name)
-
- Set the active audio input to \a name.
-*/
-
-/*!
- \fn QAudioInputSelectorControl::activeInputChanged(const QString& name)
-
- Signals that the audio input has changed to \a name.
-*/
-
-/*!
- \fn QAudioInputSelectorControl::availableInputsChanged()
-
- Signals that list of available inputs has changed.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qaudioinputselectorcontrol.cpp"
diff --git a/src/multimedia/controls/qaudioinputselectorcontrol.h b/src/multimedia/controls/qaudioinputselectorcontrol.h
deleted file mode 100644
index 9665b55de..000000000
--- a/src/multimedia/controls/qaudioinputselectorcontrol.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIOINPUTSELECTORCONTROL_H
-#define QAUDIOINPUTSELECTORCONTROL_H
-
-#include <QtMultimedia/qaudio.h>
-#include <QtMultimedia/qmediacontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-
-// Class forward declaration required for QDoc bug
-class QString;
-class Q_MULTIMEDIA_EXPORT QAudioInputSelectorControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QAudioInputSelectorControl();
-
- virtual QList<QString> availableInputs() const = 0;
- virtual QString inputDescription(const QString& name) const = 0;
- virtual QString defaultInput() const = 0;
- virtual QString activeInput() const = 0;
-
-public Q_SLOTS:
- virtual void setActiveInput(const QString& name) = 0;
-
-Q_SIGNALS:
- void activeInputChanged(const QString& name);
- void availableInputsChanged();
-
-protected:
- explicit QAudioInputSelectorControl(QObject *parent = nullptr);
-};
-
-#define QAudioInputSelectorControl_iid "org.qt-project.qt.audioinputselectorcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QAudioInputSelectorControl, QAudioInputSelectorControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QAUDIOINPUTSELECTORCONTROL_H
diff --git a/src/multimedia/controls/qaudiooutputselectorcontrol.cpp b/src/multimedia/controls/qaudiooutputselectorcontrol.cpp
deleted file mode 100644
index 64886e4c9..000000000
--- a/src/multimedia/controls/qaudiooutputselectorcontrol.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qaudiooutputselectorcontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QAudioOutputSelectorControl
- \obsolete
-
- \brief The QAudioOutputSelectorControl class provides an audio output selector media control.
- \inmodule QtMultimedia
- \ingroup multimedia_control
-
- The QAudioOutputSelectorControl class provides descriptions of the audio
- outputs available on a system and allows one to be selected as the audio
- output of a media service.
-
- The interface name of QAudioOutputSelectorControl is \c org.qt-project.qt.audiooutputselectorcontrol/5.0 as
- defined in QAudioOutputSelectorControl_iid.
-
- \sa QMediaService::requestControl()
-*/
-
-/*!
- \macro QAudioOutputSelectorControl_iid
-
- \c org.qt-project.qt.audiooutputselectorcontrol/5.0
-
- Defines the interface name of the QAudioOutputSelectorControl class.
-
- \relates QAudioOutputSelectorControl
-*/
-
-/*!
- Constructs a new audio output selector control with the given \a parent.
-*/
-QAudioOutputSelectorControl::QAudioOutputSelectorControl(QObject *parent)
- :QMediaControl(parent)
-{
-}
-
-/*!
- Destroys an audio output selector control.
-*/
-QAudioOutputSelectorControl::~QAudioOutputSelectorControl()
-{
-}
-
-/*!
- \fn QList<QString> QAudioOutputSelectorControl::availableOutputs() const
-
- Returns a list of the names of the available audio outputs.
-*/
-
-/*!
- \fn QString QAudioOutputSelectorControl::outputDescription(const QString& name) const
-
- Returns the description of the output \a name.
-*/
-
-/*!
- \fn QString QAudioOutputSelectorControl::defaultOutput() const
-
- Returns the name of the default audio output.
-*/
-
-/*!
- \fn QString QAudioOutputSelectorControl::activeOutput() const
-
- Returns the name of the currently selected audio output.
-*/
-
-/*!
- \fn QAudioOutputSelectorControl::setActiveOutput(const QString& name)
-
- Set the active audio output to \a name.
-*/
-
-/*!
- \fn QAudioOutputSelectorControl::activeOutputChanged(const QString& name)
-
- Signals that the audio output has changed to \a name.
-*/
-
-/*!
- \fn QAudioOutputSelectorControl::availableOutputsChanged()
-
- Signals that list of available outputs has changed.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qaudiooutputselectorcontrol.cpp"
diff --git a/src/multimedia/controls/qaudiooutputselectorcontrol.h b/src/multimedia/controls/qaudiooutputselectorcontrol.h
deleted file mode 100644
index de44d0ebb..000000000
--- a/src/multimedia/controls/qaudiooutputselectorcontrol.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIOOUTPUTSELECTORCONTROL_H
-#define QAUDIOOUTPUTSELECTORCONTROL_H
-
-#include <QtMultimedia/qaudio.h>
-#include <QtMultimedia/qmediacontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-
-// Class forward declaration required for QDoc bug
-class QString;
-class Q_MULTIMEDIA_EXPORT QAudioOutputSelectorControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QAudioOutputSelectorControl();
-
- virtual QList<QString> availableOutputs() const = 0;
- virtual QString outputDescription(const QString& name) const = 0;
- virtual QString defaultOutput() const = 0;
- virtual QString activeOutput() const = 0;
-
-public Q_SLOTS:
- virtual void setActiveOutput(const QString& name) = 0;
-
-Q_SIGNALS:
- void activeOutputChanged(const QString& name);
- void availableOutputsChanged();
-
-protected:
- explicit QAudioOutputSelectorControl(QObject *parent = nullptr);
-};
-
-#define QAudioOutputSelectorControl_iid "org.qt-project.qt.audiooutputselectorcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QAudioOutputSelectorControl, QAudioOutputSelectorControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QAUDIOOUTPUTSELECTORCONTROL_H
diff --git a/src/multimedia/controls/qaudiorolecontrol.cpp b/src/multimedia/controls/qaudiorolecontrol.cpp
deleted file mode 100644
index 01e60a914..000000000
--- a/src/multimedia/controls/qaudiorolecontrol.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediacontrol_p.h"
-#include "qaudiorolecontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QAudioRoleControl
- \obsolete
- \inmodule QtMultimedia
- \ingroup multimedia_control
- \since 5.6
-
- \brief The QAudioRoleControl class provides control over the audio role of a media object.
-
- If a QMediaService supports audio roles it will implement QAudioRoleControl.
-
- The functionality provided by this control is exposed to application code through the
- QMediaPlayer class.
-
- The interface name of QAudioRoleControl is \c org.qt-project.qt.audiorolecontrol/5.6 as
- defined in QAudioRoleControl_iid.
-
- \sa QMediaService::requestControl(), QMediaPlayer
-*/
-
-/*!
- \macro QAudioRoleControl_iid
-
- \c org.qt-project.qt.audiorolecontrol/5.6
-
- Defines the interface name of the QAudioRoleControl class.
-
- \relates QAudioRoleControl
-*/
-
-/*!
- Construct a QAudioRoleControl with the given \a parent.
-*/
-QAudioRoleControl::QAudioRoleControl(QObject *parent)
- : QMediaControl(*new QMediaControlPrivate, parent)
-{
-
-}
-
-/*!
- Destroys the audio role control.
-*/
-QAudioRoleControl::~QAudioRoleControl()
-{
-
-}
-
-/*!
- \fn QAudio::Role QAudioRoleControl::audioRole() const
-
- Returns the audio role of the media played by the media service.
-*/
-
-/*!
- \fn void QAudioRoleControl::setAudioRole(QAudio::Role role)
-
- Sets the audio \a role of the media played by the media service.
-*/
-
-/*!
- \fn QList<QAudio::Role> QAudioRoleControl::supportedAudioRoles() const
-
- Returns a list of audio roles that the media service supports.
-*/
-
-/*!
- \fn void QAudioRoleControl::audioRoleChanged(QAudio::Role role)
-
- Signal emitted when the audio \a role has changed.
- */
-
-QT_END_NAMESPACE
-
-#include "moc_qaudiorolecontrol.cpp"
diff --git a/src/multimedia/controls/qaudiorolecontrol.h b/src/multimedia/controls/qaudiorolecontrol.h
deleted file mode 100644
index c59874fdf..000000000
--- a/src/multimedia/controls/qaudiorolecontrol.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIOROLECONTROL_H
-#define QAUDIOROLECONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qaudio.h>
-
-QT_BEGIN_NAMESPACE
-
-// Class forward declaration required for QDoc bug
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QAudioRoleControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QAudioRoleControl();
-
- virtual QAudio::Role audioRole() const = 0;
- virtual void setAudioRole(QAudio::Role role) = 0;
-
- virtual QList<QAudio::Role> supportedAudioRoles() const = 0;
-
-Q_SIGNALS:
- void audioRoleChanged(QAudio::Role role);
-
-protected:
- explicit QAudioRoleControl(QObject *parent = nullptr);
-};
-
-#define QAudioRoleControl_iid "org.qt-project.qt.audiorolecontrol/5.6"
-Q_MEDIA_DECLARE_CONTROL(QAudioRoleControl, QAudioRoleControl_iid)
-
-QT_END_NAMESPACE
-
-#endif // QAUDIOROLECONTROL_H
diff --git a/src/multimedia/controls/qcameracapturebufferformatcontrol.cpp b/src/multimedia/controls/qcameracapturebufferformatcontrol.cpp
deleted file mode 100644
index 8f0c3e6e9..000000000
--- a/src/multimedia/controls/qcameracapturebufferformatcontrol.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qcameracapturebufferformatcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraCaptureBufferFormatControl
- \obsolete
-
- \brief The QCameraCaptureBufferFormatControl class provides a control for setting the capture buffer format.
-
- The format is of type QVideoFrame::PixelFormat.
-
- \inmodule QtMultimedia
-
- \ingroup multimedia_control
-
- The interface name of QCameraCaptureBufferFormatControl is \c org.qt-project.qt.cameracapturebufferformatcontrol/5.0 as
- defined in QCameraCaptureBufferFormatControl_iid.
-
- \sa QMediaService::requestControl()
-*/
-
-/*!
- \macro QCameraCaptureBufferFormatControl_iid
-
- \c org.qt-project.qt.cameracapturebufferformatcontrol/5.0
-
- Defines the interface name of the QCameraCaptureBufferFormatControl class.
-
- \relates QCameraCaptureBufferFormatControl
-*/
-
-/*!
- Constructs a new image buffer capture format control object with the given \a parent
-*/
-QCameraCaptureBufferFormatControl::QCameraCaptureBufferFormatControl(QObject *parent)
- :QMediaControl(parent)
-{
-}
-
-/*!
- Destroys an image buffer capture format control.
-*/
-QCameraCaptureBufferFormatControl::~QCameraCaptureBufferFormatControl()
-{
-}
-
-/*!
- \fn QCameraCaptureBufferFormatControl::supportedBufferFormats() const
-
- Returns the list of the supported buffer capture formats.
-*/
-
-/*!
- \fn QCameraCaptureBufferFormatControl::bufferFormat() const
-
- Returns the current buffer capture format.
-*/
-
-/*!
- \fn QCameraCaptureBufferFormatControl::setBufferFormat(QVideoFrame::PixelFormat format)
-
- Sets the buffer capture \a format.
-*/
-
-/*!
- \fn QCameraCaptureBufferFormatControl::bufferFormatChanged(QVideoFrame::PixelFormat format)
-
- Signals the buffer image capture format changed to \a format.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcameracapturebufferformatcontrol.cpp"
diff --git a/src/multimedia/controls/qcameracapturebufferformatcontrol.h b/src/multimedia/controls/qcameracapturebufferformatcontrol.h
deleted file mode 100644
index 1c8f44243..000000000
--- a/src/multimedia/controls/qcameracapturebufferformatcontrol.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERACAPTUREBUFFERFORMATCONTROL_H
-#define QCAMERACAPTUREBUFFERFORMATCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qcameraimagecapture.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraCaptureBufferFormatControl : public QMediaControl
-{
- Q_OBJECT
-public:
- ~QCameraCaptureBufferFormatControl();
-
- virtual QList<QVideoFrame::PixelFormat> supportedBufferFormats() const = 0;
- virtual QVideoFrame::PixelFormat bufferFormat() const = 0;
- virtual void setBufferFormat(QVideoFrame::PixelFormat format) = 0;
-
-Q_SIGNALS:
- void bufferFormatChanged(QVideoFrame::PixelFormat format);
-
-protected:
- explicit QCameraCaptureBufferFormatControl(QObject *parent = nullptr);
-};
-
-#define QCameraCaptureBufferFormatControl_iid "org.qt-project.qt.cameracapturebufferformatcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraCaptureBufferFormatControl, QCameraCaptureBufferFormatControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif
-
diff --git a/src/multimedia/controls/qcameracapturedestinationcontrol.cpp b/src/multimedia/controls/qcameracapturedestinationcontrol.cpp
deleted file mode 100644
index a9a54a3b8..000000000
--- a/src/multimedia/controls/qcameracapturedestinationcontrol.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qcameracapturedestinationcontrol.h>
-#include <QtCore/qstringlist.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraCaptureDestinationControl
- \obsolete
-
- \brief The QCameraCaptureDestinationControl class provides a control for setting capture destination.
-
- Depending on backend capabilities capture to file, buffer or both can be supported.
-
- \inmodule QtMultimedia
-
- \ingroup multimedia_control
-
- The interface name of QCameraCaptureDestinationControl is \c org.qt-project.qt.cameracapturedestinationcontrol/5.0 as
- defined in QCameraCaptureDestinationControl_iid.
-
-
- \sa QMediaService::requestControl()
-*/
-
-/*!
- \macro QCameraCaptureDestinationControl_iid
-
- \c org.qt-project.qt.cameracapturedestinationcontrol/5.0
-
- Defines the interface name of the QCameraCaptureDestinationControl class.
-
- \relates QCameraCaptureDestinationControl
-*/
-
-/*!
- Constructs a new image capture destination control object with the given \a parent
-*/
-QCameraCaptureDestinationControl::QCameraCaptureDestinationControl(QObject *parent)
- :QMediaControl(parent)
-{
-}
-
-/*!
- Destroys an image capture destination control.
-*/
-QCameraCaptureDestinationControl::~QCameraCaptureDestinationControl()
-{
-}
-
-/*!
- \fn QCameraCaptureDestinationControl::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const
-
- Returns true if the capture \a destination is supported; and false if it is not.
-*/
-
-/*!
- \fn QCameraCaptureDestinationControl::captureDestination() const
-
- Returns the current capture destination. The default destination is QCameraImageCapture::CaptureToFile.
-*/
-
-/*!
- \fn QCameraCaptureDestinationControl::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination)
-
- Sets the capture \a destination.
-*/
-
-/*!
- \fn QCameraCaptureDestinationControl::captureDestinationChanged(QCameraImageCapture::CaptureDestinations destination)
-
- Signals the image capture \a destination changed.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcameracapturedestinationcontrol.cpp"
diff --git a/src/multimedia/controls/qcameracapturedestinationcontrol.h b/src/multimedia/controls/qcameracapturedestinationcontrol.h
deleted file mode 100644
index 395f8c511..000000000
--- a/src/multimedia/controls/qcameracapturedestinationcontrol.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERACAPTUREDESTINATIONCONTROL_H
-#define QCAMERACAPTUREDESTINATIONCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qcameraimagecapture.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraCaptureDestinationControl : public QMediaControl
-{
- Q_OBJECT
-public:
- ~QCameraCaptureDestinationControl();
-
- virtual bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const = 0;
- virtual QCameraImageCapture::CaptureDestinations captureDestination() const = 0;
- virtual void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) = 0;
-
-Q_SIGNALS:
- void captureDestinationChanged(QCameraImageCapture::CaptureDestinations destination);
-
-protected:
- explicit QCameraCaptureDestinationControl(QObject *parent = nullptr);
-};
-
-#define QCameraCaptureDestinationControl_iid "org.qt-project.qt.cameracapturedestinationcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraCaptureDestinationControl, QCameraCaptureDestinationControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif
-
diff --git a/src/multimedia/controls/qcameracontrol.cpp b/src/multimedia/controls/qcameracontrol.cpp
deleted file mode 100644
index d33fa94c9..000000000
--- a/src/multimedia/controls/qcameracontrol.cpp
+++ /dev/null
@@ -1,205 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qcameracontrol.h>
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraControl
- \obsolete
-
-
-
- \brief The QCameraControl class is an abstract base class for
- classes that control still cameras or video cameras.
-
- \inmodule QtMultimedia
-
- \ingroup multimedia_control
-
- This service is provided by a QMediaService object via
- QMediaService::control(). It is used by QCamera.
-
- The interface name of QCameraControl is \c org.qt-project.qt.cameracontrol/5.0 as
- defined in QCameraControl_iid.
-
-
-
- \sa QMediaService::requestControl(), QCamera
-*/
-
-/*!
- \macro QCameraControl_iid
-
- \c org.qt-project.qt.cameracontrol/5.0
-
- Defines the interface name of the QCameraControl class.
-
- \relates QCameraControl
-*/
-
-/*!
- Constructs a camera control object with \a parent.
-*/
-
-QCameraControl::QCameraControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destruct the camera control object.
-*/
-
-QCameraControl::~QCameraControl()
-{
-}
-
-/*!
- \fn QCameraControl::state() const
-
- Returns the state of the camera service.
-
- \sa QCamera::state
-*/
-
-/*!
- \fn QCameraControl::setState(QCamera::State state)
-
- Sets the camera \a state.
-
- State changes are synchronous and indicate user intention,
- while camera status is used as a feedback mechanism to inform application about backend status.
- Status changes are reported asynchronously with QCameraControl::statusChanged() signal.
-
- \sa QCamera::State
-*/
-
-/*!
- \fn void QCameraControl::stateChanged(QCamera::State state)
-
- Signal emitted when the camera \a state changes.
-
- In most cases the state chage is caused by QCameraControl::setState(),
- but if critical error has occurred the state changes to QCamera::UnloadedState.
-*/
-
-/*!
- \fn QCameraControl::status() const
-
- Returns the status of the camera service.
-
- \sa QCamera::state
-*/
-
-/*!
- \fn void QCameraControl::statusChanged(QCamera::Status status)
-
- Signal emitted when the camera \a status changes.
-*/
-
-
-/*!
- \fn void QCameraControl::error(int error, const QString &errorString)
-
- Signal emitted when an error occurs with error code \a error and
- a description of the error \a errorString.
-*/
-
-/*!
- \fn Camera::CaptureModes QCameraControl::captureMode() const = 0
-
- Returns the current capture mode.
-*/
-
-/*!
- \fn void QCameraControl::setCaptureMode(QCamera::CaptureModes mode) = 0;
-
- Sets the current capture \a mode.
-
- The capture mode changes are synchronous and allowed in any camera state.
-
- If the capture mode is changed while camera is active,
- it's recommended to change status to QCamera::LoadedStatus
- and start activating the camera in the next event loop
- with the status changed to QCamera::StartingStatus.
- This allows the capture settings to be applied before camera is started.
- Than change the status to QCamera::StartedStatus when the capture mode change is done.
-*/
-
-/*!
- \fn bool QCameraControl::isCaptureModeSupported(QCamera::CaptureModes mode) const = 0;
-
- Returns true if the capture \a mode is suported.
-*/
-
-/*!
- \fn QCameraControl::captureModeChanged(QCamera::CaptureModes mode)
-
- Signal emitted when the camera capture \a mode changes.
- */
-
-/*!
- \fn bool QCameraControl::canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const
-
- Returns true if backend can effectively apply changing camera properties of \a changeType type
- while the camera state is QCamera::Active and camera status matches \a status parameter.
-
- If backend doesn't support applying this change in the active state, it will be stopped
- before the settings are changed and restarted after.
- Otherwise the backend should apply the change in the current state,
- with the camera status indicating the progress, if necessary.
-*/
-
-/*!
- \enum QCameraControl::PropertyChangeType
-
- \value CaptureMode Indicates the capture mode is changed.
- \value ImageEncodingSettings Image encoder settings are changed, including resolution.
- \value VideoEncodingSettings
- Video encoder settings are changed, including audio, video and container settings.
- \value Viewfinder Viewfinder is changed.
- \value ViewfinderSettings Viewfinder settings are changed.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcameracontrol.cpp"
diff --git a/src/multimedia/controls/qcameracontrol.h b/src/multimedia/controls/qcameracontrol.h
deleted file mode 100644
index 6c5163118..000000000
--- a/src/multimedia/controls/qcameracontrol.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERACONTROL_H
-#define QCAMERACONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-
-#include <QtMultimedia/qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- enum PropertyChangeType {
- CaptureMode = 1,
- ImageEncodingSettings = 2,
- VideoEncodingSettings = 3,
- Viewfinder = 4,
- ViewfinderSettings = 5
- };
-
- ~QCameraControl();
-
- virtual QCamera::State state() const = 0;
- virtual void setState(QCamera::State state) = 0;
-
- virtual QCamera::Status status() const = 0;
-
- virtual QCamera::CaptureModes captureMode() const = 0;
- virtual void setCaptureMode(QCamera::CaptureModes) = 0;
- virtual bool isCaptureModeSupported(QCamera::CaptureModes mode) const = 0;
-
- virtual bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const = 0;
-
-Q_SIGNALS:
- void stateChanged(QCamera::State);
- void statusChanged(QCamera::Status);
- void error(int error, const QString &errorString);
- void captureModeChanged(QCamera::CaptureModes mode);
-
-protected:
- explicit QCameraControl(QObject *parent = nullptr);
-};
-
-#define QCameraControl_iid "org.qt-project.qt.cameracontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraControl, QCameraControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QCAMERACONTROL_H
-
diff --git a/src/multimedia/controls/qcameraexposurecontrol.cpp b/src/multimedia/controls/qcameraexposurecontrol.cpp
deleted file mode 100644
index 2095c9cfa..000000000
--- a/src/multimedia/controls/qcameraexposurecontrol.cpp
+++ /dev/null
@@ -1,207 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qcameraexposurecontrol.h>
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraExposureControl
- \obsolete
-
- \brief The QCameraExposureControl class allows controlling camera exposure parameters.
-
- \inmodule QtMultimedia
-
- \ingroup multimedia_control
-
- The QCameraExposure class is the usual method of adjusting exposure related parameters
- when using camera functionality. This class provides a more complete but less easy
- to use interface, and also forms the interface to implement when writing a new
- implementation of QCamera functionality.
-
- You can adjust a number of parameters that will affect images and video taken with
- the corresponding QCamera object - see the \l {QCameraExposureControl::ExposureParameter}{ExposureParameter} enumeration.
-
- The interface name of QCameraExposureControl is \c org.qt-project.qt.cameraexposurecontrol/5.0 as
- defined in QCameraExposureControl_iid.
-
- \sa QCameraExposure, QCamera
-*/
-
-/*!
- \macro QCameraExposureControl_iid
-
- \c org.qt-project.qt.cameraexposurecontrol/5.0
-
- Defines the interface name of the QCameraExposureControl class.
-
- \relates QCameraExposureControl
-*/
-
-/*!
- Constructs a camera exposure control object with \a parent.
-*/
-QCameraExposureControl::QCameraExposureControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destroys the camera exposure control object.
-*/
-QCameraExposureControl::~QCameraExposureControl()
-{
-}
-
-/*!
- \enum QCameraExposureControl::ExposureParameter
- \value ISO
- Camera ISO sensitivity, specified as integer value.
- \value Aperture
- Lens aperture is specified as an qreal F number.
- The supported apertures list can change depending on the focal length,
- in such a case the exposureParameterRangeChanged() signal is emitted.
- \value ShutterSpeed
- Shutter speed in seconds, specified as qreal.
- \value ExposureCompensation
- Exposure compensation, specified as qreal EV value.
- \value FlashPower
- Manual flash power, specified as qreal value.
- Accepted power range is [0..1.0],
- with 0 value means no flash and 1.0 corresponds to full flash power.
-
- This value is only used in the \l{QCameraExposure::FlashManual}{manual flash mode}.
- \value TorchPower
- Manual torch power, specified as qreal value.
- Accepted power range is [0..1.0],
- with 0 value means no light and 1.0 corresponds to full torch power.
-
- This value is only used in the \l{QCameraExposure::FlashTorch}{torch flash mode}.
- \value FlashCompensation
- Flash compensation, specified as qreal EV value.
- \value SpotMeteringPoint
- The relative frame coordinate of the point to use for exposure metering
- in spot metering mode, specified as a QPointF.
- \value ExposureMode
- Camera exposure mode.
- \value MeteringMode
- Camera metering mode.
- \value ExtendedExposureParameter
- The base value for platform specific extended parameters.
- For such parameters the sequential values starting from ExtendedExposureParameter should be used.
-*/
-
-/*!
- \fn QCameraExposureControl::isParameterSupported(ExposureParameter parameter) const
-
- Returns true is exposure \a parameter is supported by backend.
- \since 5.0
-*/
-
-/*!
- \fn QCameraExposureControl::requestedValue(ExposureParameter parameter) const
-
- Returns the requested exposure \a parameter value.
-
- \since 5.0
-*/
-
-/*!
- \fn QCameraExposureControl::actualValue(ExposureParameter parameter) const
-
- Returns the actual exposure \a parameter value, or invalid QVariant() if the value is unknown or not supported.
-
- The actual parameter value may differ for the requested one if automatic mode is selected or
- camera supports only limited set of values within the supported range.
- \since 5.0
-*/
-
-
-/*!
- \fn QCameraExposureControl::supportedParameterRange(ExposureParameter parameter, bool *continuous = 0) const
-
- Returns the list of supported \a parameter values;
-
- If the camera supports arbitrary exposure parameter value within the supported range,
- *\a continuous is set to true, otherwise *\a continuous is set to false.
-
- \since 5.0
-*/
-
-/*!
- \fn bool QCameraExposureControl::setValue(ExposureParameter parameter, const QVariant& value)
-
- Set the exposure \a parameter to \a value.
- If a null or invalid QVariant is passed, backend should choose the value automatically,
- and if possible report the actual value to user with QCameraExposureControl::actualValue().
-
- Returns true if parameter is supported and value is correct.
- \since 5.0
-*/
-
-/*!
- \fn void QCameraExposureControl::requestedValueChanged(int parameter)
-
- Signal emitted when the requested exposure \a parameter value has changed,
- usually in result of setValue() call.
- \since 5.0
-*/
-
-/*!
- \fn void QCameraExposureControl::actualValueChanged(int parameter)
-
- Signal emitted when the actual exposure \a parameter value has changed,
- usually in result of auto exposure algorithms or manual exposure parameter applied.
-
- \since 5.0
-*/
-
-/*!
- \fn void QCameraExposureControl::parameterRangeChanged(int parameter)
-
- Signal emitted when the supported range of exposure \a parameter values has changed.
-
- \since 5.0
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcameraexposurecontrol.cpp"
diff --git a/src/multimedia/controls/qcameraexposurecontrol.h b/src/multimedia/controls/qcameraexposurecontrol.h
deleted file mode 100644
index 7694380e5..000000000
--- a/src/multimedia/controls/qcameraexposurecontrol.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAEXPOSURECONTROL_H
-#define QCAMERAEXPOSURECONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-
-#include <QtMultimedia/qcameraexposure.h>
-#include <QtMultimedia/qcamera.h>
-#include <QtMultimedia/qmediaenumdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraExposureControl : public QMediaControl
-{
- Q_OBJECT
- Q_ENUMS(ExposureParameter)
-
-public:
- ~QCameraExposureControl();
-
- enum ExposureParameter {
- ISO,
- Aperture,
- ShutterSpeed,
- ExposureCompensation,
- FlashPower,
- FlashCompensation,
- TorchPower,
- SpotMeteringPoint,
- ExposureMode,
- MeteringMode,
- ExtendedExposureParameter = 1000
- };
-
- virtual bool isParameterSupported(ExposureParameter parameter) const = 0;
- virtual QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const = 0;
-
- virtual QVariant requestedValue(ExposureParameter parameter) const = 0;
- virtual QVariant actualValue(ExposureParameter parameter) const = 0;
- virtual bool setValue(ExposureParameter parameter, const QVariant& value) = 0;
-
-Q_SIGNALS:
- void requestedValueChanged(int parameter);
- void actualValueChanged(int parameter);
- void parameterRangeChanged(int parameter);
-
-protected:
- explicit QCameraExposureControl(QObject *parent = nullptr);
-};
-
-#define QCameraExposureControl_iid "org.qt-project.qt.cameraexposurecontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraExposureControl, QCameraExposureControl_iid)
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QCameraExposureControl::ExposureParameter)
-
-Q_MEDIA_ENUM_DEBUG(QCameraExposureControl, ExposureParameter)
-
-
-#endif // QCAMERAEXPOSURECONTROL_H
-
diff --git a/src/multimedia/controls/qcamerafeedbackcontrol.cpp b/src/multimedia/controls/qcamerafeedbackcontrol.cpp
deleted file mode 100644
index 42cd7d661..000000000
--- a/src/multimedia/controls/qcamerafeedbackcontrol.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-
-#include "qcamerafeedbackcontrol.h"
-#include <private/qmediacontrol_p.h>
-
-/*!
- \class QCameraFeedbackControl
- \obsolete
-
- \brief The QCameraFeedbackControl class allows controlling feedback (sounds etc) during camera operation.
-
- \inmodule QtMultimedia
-
- \ingroup multimedia_control
- \since 5.0
-
- When using a camera, there are several times when some form of feedback to
- the user is given - for example, when an image is taken, or when recording is started.
- You can enable or disable some of this feedback, or adjust what sound might be played
- for these actions.
-
- In some cases it may be undesirable to play a sound effect - for example, when initiating
- video recording the sound itself may be recorded.
-
- \note In some countries or regions, feedback sounds or other indications (e.g. a red light) are
- mandatory during camera operation. In these cases, you can check \c isEventFeedbackLocked to check
- if that type of feedback can be modified. Any attempts to change a locked feedback type will be
- ignored.
-
- The interface name of QCameraFeedbackControl is \c org.qt-project.qt.camerafeedbackcontrol/5.0 as
- defined in QCameraFeedbackControl_iid.
-
- \sa QCamera
-*/
-
-/*!
- \enum QCameraFeedbackControl::EventType
-
- This enumeration describes certain events that occur during camera usage. You
- can associate some form of feedback to be given when the event occurs, or check
- whether feedback for this event is enabled or locked so that changes cannot be made.
-
-
-
- \value ViewfinderStarted The viewfinder stream was started (even if not visible)
- \value ViewfinderStopped The viewfinder stream was stopped
- \value ImageCaptured An image was captured but not yet fully processed
- \value ImageSaved An image is fully available and saved somewhere.
- \value ImageError An error occurred while capturing an image
- \value RecordingStarted Video recording has started
- \value RecordingInProgress Video recording is in progress
- \value RecordingStopped Video recording has stopped
- \value AutoFocusInProgress The camera is trying to automatically focus
- \value AutoFocusLocked The camera has automatically focused successfully
- \value AutoFocusFailed The camera was unable to focus automatically
-*/
-
-/*!
- \macro QCameraFeedbackControl_iid
-
- \c org.qt-project.qt.camerafeedbackcontrol/5.0
-
- Defines the interface name of the QCameraFeedbackControl class.
-
- \relates QCameraFeedbackControl
-*/
-
-/*!
- Constructs a camera feedback control object with \a parent.
-*/
-QCameraFeedbackControl::QCameraFeedbackControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destroys the camera feedback control object.
-*/
-QCameraFeedbackControl::~QCameraFeedbackControl()
-{
-}
-
-/*!
- \fn bool QCameraFeedbackControl::isEventFeedbackLocked(EventType event) const
-
- Returns true if the feedback setting for \a event is locked. This may be true
- because of legal compliance issues, or because configurability of this event's
- feedback is not supported.
-
- \since 5.0
-*/
-
-/*!
- \fn bool QCameraFeedbackControl::isEventFeedbackEnabled(EventType event) const
-
- Returns true if the feedback for \a event is enabled.
-
- \since 5.0
-*/
-
-/*!
- \fn bool QCameraFeedbackControl::setEventFeedbackEnabled(EventType event, bool enabled)
-
- Turns on feedback for the specific \a event if \a enabled is true, otherwise disables the
- feedback. Returns true if the feedback could be modified, or false otherwise (e.g. this feedback
- type is locked).
-
- \since 5.0
-*/
-
-
-/*!
- \fn void QCameraFeedbackControl::resetEventFeedback(EventType event)
-
- Restores the feedback setting for this \a event to its default setting.
-
- \since 5.0
-*/
-
-/*!
- \fn bool QCameraFeedbackControl::setEventFeedbackSound(EventType event, const QString &filePath)
-
- When the given \a event occurs, the sound effect referenced by \a filePath
- will be played instead of the default sound.
-
- If this feedback type is locked, or if the supplied path is inaccessible,
- this function will return false. In addition, some forms of feedback may
- be non-auditory (e.g. a red light, or a vibration), and false may be
- returned in this case.
-
- The file referenced should be linear PCM (WAV format).
-
- \note In the case that a valid file path to an unsupported file is given, this
- function will return true but the feedback will use the original setting.
-
- \since 5.0
-*/
-
-
-
-
-
-
diff --git a/src/multimedia/controls/qcamerafeedbackcontrol.h b/src/multimedia/controls/qcamerafeedbackcontrol.h
deleted file mode 100644
index 195ad3915..000000000
--- a/src/multimedia/controls/qcamerafeedbackcontrol.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-
-#ifndef QCAMERAFEEDBACKCONTROL_H
-#define QCAMERAFEEDBACKCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-
-#include <QtMultimedia/qcamera.h>
-#include <QtMultimedia/qmediaenumdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraFeedbackControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- enum EventType {
- ViewfinderStarted = 1,
- ViewfinderStopped,
- ImageCaptured,
- ImageSaved,
- ImageError,
- RecordingStarted,
- RecordingInProgress,
- RecordingStopped,
- AutoFocusInProgress,
- AutoFocusLocked,
- AutoFocusFailed
- };
-
- ~QCameraFeedbackControl();
-
- virtual bool isEventFeedbackLocked(EventType) const = 0;
-
- virtual bool isEventFeedbackEnabled(EventType) const = 0;
-
- virtual bool setEventFeedbackEnabled(EventType, bool) = 0;
- virtual void resetEventFeedback(EventType) = 0;
-
- virtual bool setEventFeedbackSound(EventType, const QString &filePath) = 0;
-
-protected:
- explicit QCameraFeedbackControl(QObject *parent = nullptr);
-};
-
-#define QCameraFeedbackControl_iid "org.qt-project.qt.camerafeedbackcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraFeedbackControl, QCameraFeedbackControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QCAMERAFEEDBACKCONTROL_H
diff --git a/src/multimedia/controls/qcameraflashcontrol.cpp b/src/multimedia/controls/qcameraflashcontrol.cpp
deleted file mode 100644
index 658e2d56c..000000000
--- a/src/multimedia/controls/qcameraflashcontrol.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qcameraflashcontrol.h>
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraFlashControl
- \obsolete
-
- \brief The QCameraFlashControl class allows controlling a camera's flash.
-
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- You can set the type of flash effect used when an image is captured, and test to see
- if the flash hardware is ready to fire.
-
- You can retrieve this control from the camera object in the usual way:
-
- Some camera devices may not have flash hardware, or may not be configurable. In that
- case, there will be no QCameraFlashControl available.
-
- The interface name of QCameraFlashControl is \c org.qt-project.qt.cameraflashcontrol/5.0 as
- defined in QCameraFlashControl_iid.
-
- \sa QCamera
-*/
-
-/*!
- \macro QCameraFlashControl_iid
-
- \c org.qt-project.qt.cameraflashcontrol/5.0
-
- Defines the interface name of the QCameraFlashControl class.
-
- \relates QCameraFlashControl
-*/
-
-/*!
- Constructs a camera flash control object with \a parent.
-*/
-QCameraFlashControl::QCameraFlashControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destroys the camera control object.
-*/
-QCameraFlashControl::~QCameraFlashControl()
-{
-}
-
-/*!
- \fn QCamera::FlashModes QCameraFlashControl::flashMode() const
-
- Returns the current flash mode.
-*/
-
-/*!
- \fn void QCameraFlashControl::setFlashMode(QCameraExposure::FlashModes mode)
-
- Set the current flash \a mode.
-
- Usually a single QCameraExposure::FlashMode flag is used,
- but some non conflicting flags combination are also allowed,
- like QCameraExposure::FlashManual | QCameraExposure::FlashSlowSyncRearCurtain.
-*/
-
-
-/*!
- \fn QCameraFlashControl::isFlashModeSupported(QCameraExposure::FlashModes mode) const
-
- Return true if the reqested flash \a mode is supported.
- Some QCameraExposure::FlashMode values can be combined,
- for example QCameraExposure::FlashManual | QCameraExposure::FlashSlowSyncRearCurtain
-*/
-
-/*!
- \fn bool QCameraFlashControl::isFlashReady() const
-
- Returns true if flash is charged.
-*/
-
-/*!
- \fn void QCameraFlashControl::flashReady(bool ready)
-
- Signal emitted when flash state changes to \a ready.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcameraflashcontrol.cpp"
diff --git a/src/multimedia/controls/qcameraflashcontrol.h b/src/multimedia/controls/qcameraflashcontrol.h
deleted file mode 100644
index d4b7d1f4c..000000000
--- a/src/multimedia/controls/qcameraflashcontrol.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAFLASHCONTROL_H
-#define QCAMERAFLASHCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-
-#include <QtMultimedia/qcameraexposure.h>
-#include <QtMultimedia/qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraFlashControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- ~QCameraFlashControl();
-
- virtual QCameraExposure::FlashModes flashMode() const = 0;
- virtual void setFlashMode(QCameraExposure::FlashModes mode) = 0;
- virtual bool isFlashModeSupported(QCameraExposure::FlashModes mode) const = 0;
-
- virtual bool isFlashReady() const = 0;
-
-Q_SIGNALS:
- void flashReady(bool);
-
-protected:
- explicit QCameraFlashControl(QObject *parent = nullptr);
-};
-
-#define QCameraFlashControl_iid "org.qt-project.qt.cameraflashcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraFlashControl, QCameraFlashControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QCAMERAFLASHCONTROL_H
-
diff --git a/src/multimedia/controls/qcamerafocuscontrol.cpp b/src/multimedia/controls/qcamerafocuscontrol.cpp
deleted file mode 100644
index b216882b4..000000000
--- a/src/multimedia/controls/qcamerafocuscontrol.cpp
+++ /dev/null
@@ -1,198 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qcamerafocuscontrol.h>
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraFocusControl
- \obsolete
-
-
- \brief The QCameraFocusControl class supplies control for
- focusing related camera parameters.
-
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- The interface name of QCameraFocusControl is \c org.qt-project.qt.camerafocuscontrol/5.0 as
- defined in QCameraFocusControl_iid.
-
-
- \sa QMediaService::requestControl(), QCamera
-*/
-
-/*!
- \macro QCameraFocusControl_iid
-
- \c org.qt-project.qt.camerafocuscontrol/5.0
-
- Defines the interface name of the QCameraFocusControl class.
-
- \relates QCameraFocusControl
-*/
-
-/*!
- Constructs a camera control object with \a parent.
-*/
-
-QCameraFocusControl::QCameraFocusControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destruct the camera control object.
-*/
-
-QCameraFocusControl::~QCameraFocusControl()
-{
-}
-
-
-/*!
- \fn QCameraFocus::FocusModes QCameraFocusControl::focusMode() const
-
- Returns the focus mode being used.
-*/
-
-
-/*!
- \fn void QCameraFocusControl::setFocusMode(QCameraFocus::FocusModes mode)
-
- Set the focus mode to \a mode.
-*/
-
-
-/*!
- \fn bool QCameraFocusControl::isFocusModeSupported(QCameraFocus::FocusModes mode) const
-
- Returns true if focus \a mode is supported.
-*/
-
-/*!
- \fn QCameraFocusControl::focusPointMode() const
-
- Returns the camera focus point selection mode.
-*/
-
-/*!
- \fn QCameraFocusControl::setFocusPointMode(QCameraFocus::FocusPointMode mode)
-
- Sets the camera focus point selection \a mode.
-*/
-
-/*!
- \fn QCameraFocusControl::isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const
-
- Returns true if the camera focus point \a mode is supported.
-*/
-
-/*!
- \fn QCameraFocusControl::customFocusPoint() const
-
- Return the position of custom focus point, in relative frame coordinates:
- QPointF(0,0) points to the left top frame point, QPointF(0.5,0.5) points to the frame center.
-
- Custom focus point is used only in FocusPointCustom focus mode.
-*/
-
-/*!
- \fn QCameraFocusControl::setCustomFocusPoint(const QPointF &point)
-
- Sets the custom focus \a point.
-
- If camera supports fixed set of focus points,
- it should use the nearest supported focus point,
- and return the actual focus point with QCameraFocusControl::focusZones().
-
- \sa QCameraFocusControl::customFocusPoint(), QCameraFocusControl::focusZones()
-*/
-
-/*!
- \fn QCameraFocusControl::focusZones() const
-
- Returns the list of zones, the camera is using for focusing or focused on.
-*/
-
-/*!
- \fn QCameraFocusControl::focusZonesChanged()
-
- Signal is emitted when the set of zones, camera focused on is changed.
-
- Usually the zones list is changed when the camera is focused.
-
- \sa QCameraFocusControl::focusZones()
-*/
-
-/*!
- \fn void QCameraFocusControl::focusModeChanged(QCameraFocus::FocusModes mode)
-
- Signal is emitted when the focus \a mode is changed,
- usually in result of QCameraFocusControl::setFocusMode call or capture mode changes.
-
- \sa QCameraFocusControl::focusMode(), QCameraFocusControl::setFocusMode()
-*/
-
-/*!
- \fn void QCameraFocusControl::focusPointModeChanged(QCameraFocus::FocusPointMode mode)
-
- Signal is emitted when the focus point \a mode is changed,
- usually in result of QCameraFocusControl::setFocusPointMode call or capture mode changes.
-
- \sa QCameraFocusControl::focusPointMode(), QCameraFocusControl::setFocusPointMode()
-*/
-
-/*!
- \fn void QCameraFocusControl::customFocusPointChanged(const QPointF &point)
-
- Signal is emitted when the custom focus \a point is changed.
-
- \sa QCameraFocusControl::customFocusPoint(), QCameraFocusControl::setCustomFocusPoint()
-*/
-
-
-
-QT_END_NAMESPACE
-
-#include "moc_qcamerafocuscontrol.cpp"
diff --git a/src/multimedia/controls/qcamerafocuscontrol.h b/src/multimedia/controls/qcamerafocuscontrol.h
deleted file mode 100644
index a93d2fd1e..000000000
--- a/src/multimedia/controls/qcamerafocuscontrol.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAFOCUSCONTROL_H
-#define QCAMERAFOCUSCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-
-#include <QtMultimedia/qcamerafocus.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraFocusControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- ~QCameraFocusControl();
-
- virtual QCameraFocus::FocusModes focusMode() const = 0;
- virtual void setFocusMode(QCameraFocus::FocusModes mode) = 0;
- virtual bool isFocusModeSupported(QCameraFocus::FocusModes mode) const = 0;
-
- virtual QCameraFocus::FocusPointMode focusPointMode() const = 0;
- virtual void setFocusPointMode(QCameraFocus::FocusPointMode mode) = 0;
- virtual bool isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const = 0;
- virtual QPointF customFocusPoint() const = 0;
- virtual void setCustomFocusPoint(const QPointF &point) = 0;
-
- virtual QCameraFocusZoneList focusZones() const = 0;
-
-Q_SIGNALS:
- void focusModeChanged(QCameraFocus::FocusModes mode);
- void focusPointModeChanged(QCameraFocus::FocusPointMode mode);
- void customFocusPointChanged(const QPointF &point);
-
- void focusZonesChanged();
-
-protected:
- explicit QCameraFocusControl(QObject *parent = nullptr);
-};
-
-#define QCameraFocusControl_iid "org.qt-project.qt.camerafocuscontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraFocusControl, QCameraFocusControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QCAMERAFOCUSCONTROL_H
-
diff --git a/src/multimedia/controls/qcameraimagecapturecontrol.cpp b/src/multimedia/controls/qcameraimagecapturecontrol.cpp
deleted file mode 100644
index 0e089d01b..000000000
--- a/src/multimedia/controls/qcameraimagecapturecontrol.cpp
+++ /dev/null
@@ -1,195 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qcameraimagecapturecontrol.h>
-#include <QtCore/qstringlist.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraImageCaptureControl
- \obsolete
-
- \brief The QCameraImageCaptureControl class provides a control interface
- for image capture services.
-
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- The interface name of QCameraImageCaptureControl is \c org.qt-project.qt.cameraimagecapturecontrol/5.0 as
- defined in QCameraImageCaptureControl_iid.
-
-
- \sa QMediaService::requestControl()
-*/
-
-/*!
- \macro QCameraImageCaptureControl_iid
-
- \c org.qt-project.qt.cameraimagecapturecontrol/5.0
-
- Defines the interface name of the QCameraImageCaptureControl class.
-
- \relates QCameraImageCaptureControl
-*/
-
-/*!
- Constructs a new image capture control object with the given \a parent
-*/
-QCameraImageCaptureControl::QCameraImageCaptureControl(QObject *parent)
- :QMediaControl(parent)
-{
-}
-
-/*!
- Destroys an image capture control.
-*/
-QCameraImageCaptureControl::~QCameraImageCaptureControl()
-{
-}
-
-/*!
- \fn QCameraImageCaptureControl::isReadyForCapture() const
-
- Identifies if a capture control is ready to perform a capture
- immediately (all the resources necessary for image capture are allocated,
- hardware initialized, flash is charged, etc).
-
- Returns true if the camera is ready for capture; and false if it is not.
-
- It's permissible to call capture() while the camera status is QCamera::ActiveStatus
- regardless of isReadyForCapture property value.
- If camera is not ready to capture image immediately,
- the capture request is queued with all the related camera settings
- to be executed as soon as possible.
-*/
-
-/*!
- \fn QCameraImageCaptureControl::readyForCaptureChanged(bool ready)
-
- Signals that a capture control's \a ready state has changed.
-*/
-
-/*!
- \fn QCameraImageCaptureControl::capture(const QString &fileName)
-
- Initiates the capture of an image to \a fileName.
- The \a fileName can be relative or empty,
- in this case the service should use the system specific place
- and file naming scheme.
-
- The Camera service should save all the capture parameters
- like exposure settings or image processing parameters,
- so changes to camera parameters after capture() is called
- do not affect previous capture requests.
-
- Returns the capture request id number, which is used later
- with imageExposed(), imageCaptured() and imageSaved() signals.
-*/
-
-/*!
- \fn QCameraImageCaptureControl::cancelCapture()
-
- Cancel pending capture requests.
-*/
-
-/*!
- \fn QCameraImageCaptureControl::imageExposed(int requestId)
-
- Signals that an image with it \a requestId
- has just been exposed.
- This signal can be used for the shutter sound or other indicaton.
-*/
-
-/*!
- \fn QCameraImageCaptureControl::imageCaptured(int requestId, const QImage &preview)
-
- Signals that an image with it \a requestId
- has been captured and a \a preview is available.
-*/
-
-/*!
- \fn QCameraImageCaptureControl::imageMetadataAvailable(int id, const QString &key, const QVariant &value)
-
- Signals that a metadata for an image with request \a id is available. Signal
- also contains the \a key and \a value of the metadata.
-
- This signal should be emitted between imageExposed and imageSaved signals.
-*/
-
-/*!
- \fn QCameraImageCaptureControl::imageAvailable(int requestId, const QVideoFrame &buffer)
-
- Signals that a captured \a buffer with a \a requestId is available.
-*/
-
-/*!
- \fn QCameraImageCaptureControl::imageSaved(int requestId, const QString &fileName)
-
- Signals that a captured image with a \a requestId has been saved
- to \a fileName.
-*/
-
-/*!
- \fn QCameraImageCaptureControl::driveMode() const
-
- Returns the current camera drive mode.
-*/
-
-/*!
- \fn QCameraImageCaptureControl::setDriveMode(QCameraImageCapture::DriveMode mode)
-
- Sets the current camera drive \a mode.
-*/
-
-
-/*!
- \fn QCameraImageCaptureControl::error(int id, int error, const QString &errorString)
-
- Signals the capture request \a id failed with \a error code and message \a errorString.
-
- \sa QCameraImageCapture::Error
-*/
-
-
-QT_END_NAMESPACE
-
-#include "moc_qcameraimagecapturecontrol.cpp"
diff --git a/src/multimedia/controls/qcameraimagecapturecontrol.h b/src/multimedia/controls/qcameraimagecapturecontrol.h
deleted file mode 100644
index 72b0abda3..000000000
--- a/src/multimedia/controls/qcameraimagecapturecontrol.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAIMAGECAPTURECONTROL_H
-#define QCAMERAIMAGECAPTURECONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qcameraimagecapture.h>
-
-QT_BEGIN_NAMESPACE
-
-class QImage;
-QT_END_NAMESPACE
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraImageCaptureControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- ~QCameraImageCaptureControl();
-
- virtual bool isReadyForCapture() const = 0;
-
- virtual QCameraImageCapture::DriveMode driveMode() const = 0;
- virtual void setDriveMode(QCameraImageCapture::DriveMode mode) = 0;
-
- virtual int capture(const QString &fileName) = 0;
- virtual void cancelCapture() = 0;
-
-Q_SIGNALS:
- void readyForCaptureChanged(bool ready);
-
- void imageExposed(int requestId);
- void imageCaptured(int requestId, const QImage &preview);
- void imageMetadataAvailable(int id, const QString &key, const QVariant &value);
- void imageAvailable(int requestId, const QVideoFrame &buffer);
- void imageSaved(int requestId, const QString &fileName);
-
- void error(int id, int error, const QString &errorString);
-
-protected:
- explicit QCameraImageCaptureControl(QObject *parent = nullptr);
-};
-
-#define QCameraImageCaptureControl_iid "org.qt-project.qt.cameraimagecapturecontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraImageCaptureControl, QCameraImageCaptureControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QCAMERAIMAGECAPTURECONTROL_H
-
diff --git a/src/multimedia/controls/qcameraimageprocessingcontrol.cpp b/src/multimedia/controls/qcameraimageprocessingcontrol.cpp
deleted file mode 100644
index fba4bf400..000000000
--- a/src/multimedia/controls/qcameraimageprocessingcontrol.cpp
+++ /dev/null
@@ -1,189 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qcameraimageprocessingcontrol.h>
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-static void qRegisterCameraImageProcessingControlMetaTypes()
-{
- qRegisterMetaType<QCameraImageProcessingControl::ProcessingParameter>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterCameraImageProcessingControlMetaTypes)
-
-/*!
- \class QCameraImageProcessingControl
- \obsolete
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
-
- \brief The QCameraImageProcessingControl class provides an abstract class
- for controlling image processing parameters, like white balance,
- contrast, saturation, sharpening and denoising.
-
- The interface name of QCameraImageProcessingControl is \c org.qt-project.qt.cameraimageprocessingcontrol/5.0 as
- defined in QCameraImageProcessingControl_iid.
-
- Camera service may choose the parameters of image processing pipeline depending
- on sensor properties camera settings and capture parameters.
-
- This control allows to modify some parameters of image processing pipeline
- to achieve desired results.
-
- Parameters with the "Adjustment" suffix, like ContrastAdjustment, SaturationAdjustment etc
- allows to adjust the parameter values, selected by camera engine,
- while parameters like Contrast and Saturation overwrites them.
-
- For example setting the SharpeningAdjustment parameter to -0.1
- slightly reduces the amount of sharpening applied,
- while settings the Sharpening parameter to 0 disables sharpening at all.
-
- \sa QMediaService::requestControl(), QCamera
-*/
-
-/*!
- \macro QCameraImageProcessingControl_iid
-
- \c org.qt-project.qt.cameraimageprocessingcontrol/5.0
-
- Defines the interface name of the QCameraImageProcessingControl class.
-
- \relates QCameraImageProcessingControl
-*/
-
-/*!
- Constructs an image processing control object with \a parent.
-*/
-
-QCameraImageProcessingControl::QCameraImageProcessingControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destruct the image processing control object.
-*/
-
-QCameraImageProcessingControl::~QCameraImageProcessingControl()
-{
-}
-
-/*!
- \fn bool QCameraImageProcessingControl::isParameterSupported(ProcessingParameter parameter) const
-
- Returns true if the camera supports adjusting image processing \a parameter.
-
- Usually the supported setting is static,
- but some parameters may not be available depending on other
- camera settings, like presets.
- In such case the currently supported parameters should be returned.
-*/
-
-/*!
- \fn bool QCameraImageProcessingControl::isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const
-
- Returns true if the camera supports setting the image processing \a parameter \a value.
-
- It's used only for parameters with a limited set of values, like WhiteBalancePreset.
-*/
-
-
-/*!
- \fn QCameraImageProcessingControl::parameter(ProcessingParameter parameter) const
-
- Returns the image processing \a parameter value.
-*/
-
-/*!
- \fn QCameraImageProcessingControl::setParameter(ProcessingParameter parameter, const QVariant &value)
-
- Sets the image processing \a parameter \a value.
- Passing the null or invalid QVariant value allows
- backend to choose the suitable parameter value.
-
- The valid values range depends on the parameter type.
- For WhiteBalancePreset the value should be one of QCameraImageProcessing::WhiteBalanceMode values;
- for Contrast, Saturation, Brightness, Sharpening and Denoising the value should be
- in [0..1.0] range with invalid QVariant value indicating the default parameter value;
- for ContrastAdjustment, SaturationAdjustment, BrightnessAdjustment,
- SharpeningAdjustment and DenoisingAdjustment the value should be
- in [-1.0..1.0] range with default 0.
-*/
-
-/*!
- \enum QCameraImageProcessingControl::ProcessingParameter
-
- \value WhiteBalancePreset
- The white balance preset.
- \value ColorTemperature
- Color temperature in K. This value is used when the manual white balance mode is selected.
- \value Contrast
- Image contrast.
- \value Saturation
- Image saturation.
- \value Brightness
- Image brightness.
- \value Sharpening
- Amount of sharpening applied.
- \value Denoising
- Amount of denoising applied.
- \value ContrastAdjustment
- Image contrast adjustment.
- \value SaturationAdjustment
- Image saturation adjustment.
- \value BrightnessAdjustment
- Image brightness adjustment.
- \value SharpeningAdjustment
- Adjustment of sharpening applied.
- \value DenoisingAdjustment
- Adjustment of denoising applied.
- \value ColorFilter
- Image filter applied. Since 5.5
- \value ExtendedParameter
- The base value for platform specific extended parameters.
- */
-
-QT_END_NAMESPACE
-
-#include "moc_qcameraimageprocessingcontrol.cpp"
diff --git a/src/multimedia/controls/qcameraimageprocessingcontrol.h b/src/multimedia/controls/qcameraimageprocessingcontrol.h
deleted file mode 100644
index 8be435f8f..000000000
--- a/src/multimedia/controls/qcameraimageprocessingcontrol.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAIMAGEPROCESSINGCONTROL_H
-#define QCAMERAIMAGEPROCESSINGCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-
-#include <QtMultimedia/qcamera.h>
-#include <QtMultimedia/qmediaenumdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraImageProcessingControl : public QMediaControl
-{
- Q_OBJECT
- Q_ENUMS(ProcessingParameter)
-
-public:
- ~QCameraImageProcessingControl();
-
- enum ProcessingParameter {
- WhiteBalancePreset,
- ColorTemperature,
- Contrast,
- Saturation,
- Brightness,
- Sharpening,
- Denoising,
- ContrastAdjustment,
- SaturationAdjustment,
- BrightnessAdjustment,
- SharpeningAdjustment,
- DenoisingAdjustment,
- ColorFilter,
- ExtendedParameter = 1000
- };
-
- virtual bool isParameterSupported(ProcessingParameter) const = 0;
- virtual bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const = 0;
- virtual QVariant parameter(ProcessingParameter parameter) const = 0;
- virtual void setParameter(ProcessingParameter parameter, const QVariant &value) = 0;
-
-protected:
- explicit QCameraImageProcessingControl(QObject *parent = nullptr);
-};
-
-#define QCameraImageProcessingControl_iid "org.qt-project.qt.cameraimageprocessingcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraImageProcessingControl, QCameraImageProcessingControl_iid)
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QCameraImageProcessingControl::ProcessingParameter)
-
-Q_MEDIA_ENUM_DEBUG(QCameraImageProcessingControl, ProcessingParameter)
-
-#endif
-
diff --git a/src/multimedia/controls/qcamerainfocontrol.cpp b/src/multimedia/controls/qcamerainfocontrol.cpp
deleted file mode 100644
index 8a4ef3b44..000000000
--- a/src/multimedia/controls/qcamerainfocontrol.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qcamerainfocontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraInfoControl
- \obsolete
- \since 5.3
-
- \brief The QCameraInfoControl class provides a camera info media control.
- \inmodule QtMultimedia
-
- \ingroup multimedia_control
-
- The QCameraInfoControl class provides information about the camera devices
- available on the system.
-
- The interface name of QCameraInfoControl is \c org.qt-project.qt.camerainfocontrol/5.3 as
- defined in QCameraInfoControl_iid.
-*/
-
-/*!
- \macro QCameraInfoControl_iid
-
- \c org.qt-project.qt.camerainfocontrol/5.3
-
- Defines the interface name of the QCameraInfoControl class.
-
- \relates QVideoDeviceSelectorControl
-*/
-
-/*!
- Constructs a camera info control with the given \a parent.
-*/
-QCameraInfoControl::QCameraInfoControl(QObject *parent)
- : QMediaControl(parent)
-{
-}
-
-/*!
- Destroys a camera info control.
-*/
-QCameraInfoControl::~QCameraInfoControl()
-{
-}
-
-/*!
- \fn QCameraInfoControl::cameraPosition(const QString &deviceName) const
-
- Returns the physical position of the camera named \a deviceName on the hardware system.
-*/
-
-/*!
- \fn QCameraInfoControl::cameraOrientation(const QString &deviceName) const
-
- Returns the physical orientation of the sensor for the camera named \a deviceName.
-
- The value is the orientation angle (clockwise, in steps of 90 degrees) of the camera sensor
- in relation to the display in its natural orientation.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcamerainfocontrol.cpp"
diff --git a/src/multimedia/controls/qcamerainfocontrol.h b/src/multimedia/controls/qcamerainfocontrol.h
deleted file mode 100644
index 9ee0a3abf..000000000
--- a/src/multimedia/controls/qcamerainfocontrol.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAINFOCONTROL_H
-#define QCAMERAINFOCONTROL_H
-
-#include <QtMultimedia/qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraInfoControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QCameraInfoControl();
-
- virtual QCamera::Position cameraPosition(const QString &deviceName) const = 0;
- virtual int cameraOrientation(const QString &deviceName) const = 0;
-
-protected:
- explicit QCameraInfoControl(QObject *parent = nullptr);
-};
-
-#define QCameraInfoControl_iid "org.qt-project.qt.camerainfocontrol/5.3"
-Q_MEDIA_DECLARE_CONTROL(QCameraInfoControl, QCameraInfoControl_iid)
-
-QT_END_NAMESPACE
-
-#endif // QCAMERAINFOCONTROL_H
diff --git a/src/multimedia/controls/qcameralockscontrol.cpp b/src/multimedia/controls/qcameralockscontrol.cpp
deleted file mode 100644
index 27b68cf2c..000000000
--- a/src/multimedia/controls/qcameralockscontrol.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qcameralockscontrol.h>
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraLocksControl
- \obsolete
-
-
-
- \brief The QCameraLocksControl class is an abstract base class for
- classes that control still cameras or video cameras.
-
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- This service is provided by a QMediaService object via
- QMediaService::control(). It is used by QCamera.
-
- The interface name of QCameraLocksControl is \c org.qt-project.qt.cameralockscontrol/5.0 as
- defined in QCameraLocksControl_iid.
-
-
- \sa QMediaService::requestControl(), QCamera
-*/
-
-/*!
- \macro QCameraLocksControl_iid
-
- \c org.qt-project.qt.cameralockscontrol/5.0
-
- Defines the interface name of the QCameraLocksControl class.
-
- \relates QCameraLocksControl
-*/
-
-/*!
- Constructs a camera locks control object with \a parent.
-*/
-
-QCameraLocksControl::QCameraLocksControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destruct the camera locks control object.
-*/
-
-QCameraLocksControl::~QCameraLocksControl()
-{
-}
-
-/*!
- \fn QCameraLocksControl::supportedLocks() const
-
- Returns the lock types, the camera supports.
-*/
-
-/*!
- \fn QCameraLocksControl::lockStatus(QCamera::LockType lock) const
-
- Returns the camera \a lock status.
-*/
-
-/*!
- \fn QCameraLocksControl::searchAndLock(QCamera::LockTypes locks)
-
- Request camera \a locks.
-*/
-
-/*!
- \fn QCameraLocksControl::unlock(QCamera::LockTypes locks)
-
- Unlock camera \a locks.
-*/
-
-/*!
- \fn QCameraLocksControl::lockStatusChanged(QCamera::LockType lock, QCamera::LockStatus status, QCamera::LockChangeReason reason)
-
- Signals the lock \a type \a status was changed with the specified \a reason.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcameralockscontrol.cpp"
diff --git a/src/multimedia/controls/qcameralockscontrol.h b/src/multimedia/controls/qcameralockscontrol.h
deleted file mode 100644
index d545d971e..000000000
--- a/src/multimedia/controls/qcameralockscontrol.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERALOCKSCONTROL_H
-#define QCAMERALOCKSCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-
-#include <QtMultimedia/qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraLocksControl : public QMediaControl
-{
- Q_OBJECT
-public:
- ~QCameraLocksControl();
-
- virtual QCamera::LockTypes supportedLocks() const = 0;
-
- virtual QCamera::LockStatus lockStatus(QCamera::LockType lock) const = 0;
-
- virtual void searchAndLock(QCamera::LockTypes locks) = 0;
- virtual void unlock(QCamera::LockTypes locks) = 0;
-
-Q_SIGNALS:
- void lockStatusChanged(QCamera::LockType type, QCamera::LockStatus status, QCamera::LockChangeReason reason);
-
-protected:
- explicit QCameraLocksControl(QObject *parent = nullptr);
-};
-
-#define QCameraLocksControl_iid "org.qt-project.qt.cameralockscontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraLocksControl, QCameraLocksControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QCAMERALOCKSCONTROL_H
-
diff --git a/src/multimedia/controls/qcameraviewfindersettingscontrol.cpp b/src/multimedia/controls/qcameraviewfindersettingscontrol.cpp
deleted file mode 100644
index bd5c7a73b..000000000
--- a/src/multimedia/controls/qcameraviewfindersettingscontrol.cpp
+++ /dev/null
@@ -1,206 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qcameraviewfindersettingscontrol.h"
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraViewfinderSettingsControl
- \obsolete
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
-
- \brief The QCameraViewfinderSettingsControl class provides an abstract class
- for controlling camera viewfinder parameters.
-
- The interface name of QCameraViewfinderSettingsControl is \c org.qt-project.qt.cameraviewfindersettingscontrol/5.0 as
- defined in QCameraViewfinderSettingsControl_iid.
-
- \warning New backends should implement QCameraViewfinderSettingsControl2 instead.
- Application developers should request this control only if QCameraViewfinderSettingsControl2
- is not available.
-
- \sa QMediaService::requestControl(), QCameraViewfinderSettingsControl2, QCamera
-*/
-
-/*!
- \macro QCameraViewfinderSettingsControl_iid
-
- \c org.qt-project.qt.cameraviewfindersettingscontrol/5.0
-
- Defines the interface name of the QCameraViewfinderSettingsControl class.
-
- \relates QCameraViewfinderSettingsControl
-*/
-
-/*!
- Constructs a camera viewfinder control object with \a parent.
-*/
-QCameraViewfinderSettingsControl::QCameraViewfinderSettingsControl(QObject *parent)
- : QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destroys the camera viewfinder control object.
-*/
-QCameraViewfinderSettingsControl::~QCameraViewfinderSettingsControl()
-{
-}
-
-/*!
- \enum QCameraViewfinderSettingsControl::ViewfinderParameter
- \value Resolution
- Viewfinder resolution, QSize.
- \value PixelAspectRatio
- Pixel aspect ratio, QSize as in QVideoSurfaceFormat::pixelAspectRatio
- \value MinimumFrameRate
- Minimum viewfinder frame rate, qreal
- \value MaximumFrameRate
- Maximum viewfinder frame rate, qreal
- \value PixelFormat
- Viewfinder pixel format, QVideoFrame::PixelFormat
- \value UserParameter
- The base value for platform specific extended parameters.
- For such parameters the sequential values starting from UserParameter should be used.
-*/
-
-/*!
- \fn bool QCameraViewfinderSettingsControl::isViewfinderParameterSupported(ViewfinderParameter parameter) const
-
- Returns true if configuration of viewfinder \a parameter is supported by camera backend.
-*/
-
-/*!
- \fn QCameraViewfinderSettingsControl::viewfinderParameter(ViewfinderParameter parameter) const
-
- Returns the value of viewfinder \a parameter.
-*/
-
-/*!
- \fn QCameraViewfinderSettingsControl::setViewfinderParameter(ViewfinderParameter parameter, const QVariant &value)
-
- Set the prefferred \a value of viewfinder \a parameter.
-
- Calling this while the camera is active may result in the camera being
- stopped and reloaded. If video recording is in progress, this call may be ignored.
-
- If an unsupported parameter is specified the camera may fail to load,
- or the setting may be ignored.
-
- Viewfinder parameters may also depend on other camera settings,
- especially in video capture mode. If camera configuration conflicts
- with viewfinder settings, the camara configuration is usually preferred.
-*/
-
-
-/*!
- \class QCameraViewfinderSettingsControl2
- \inmodule QtMultimedia
- \ingroup multimedia_control
- \since 5.5
-
- \brief The QCameraViewfinderSettingsControl2 class provides access to the viewfinder settings
- of a camera media service.
-
- The functionality provided by this control is exposed to application code through the QCamera class.
-
- The interface name of QCameraViewfinderSettingsControl2 is \c org.qt-project.qt.cameraviewfindersettingscontrol2/5.5 as
- defined in QCameraViewfinderSettingsControl2_iid.
-
- \sa QMediaService::requestControl(), QCameraViewfinderSettings, QCamera
-*/
-
-/*!
- \macro QCameraViewfinderSettingsControl2_iid
-
- \c org.qt-project.qt.cameraviewfindersettingscontrol2/5.5
-
- Defines the interface name of the QCameraViewfinderSettingsControl2 class.
-
- \relates QCameraViewfinderSettingsControl2
-*/
-
-/*!
- Constructs a camera viewfinder settings control object with \a parent.
-*/
-QCameraViewfinderSettingsControl2::QCameraViewfinderSettingsControl2(QObject *parent)
- : QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destroys the camera viewfinder settings control object.
-*/
-QCameraViewfinderSettingsControl2::~QCameraViewfinderSettingsControl2()
-{
-}
-
-/*!
- \fn QCameraViewfinderSettingsControl2::supportedViewfinderSettings() const
-
- Returns a list of supported camera viewfinder settings.
-
- The list is ordered by preference; preferred settings come first.
-*/
-
-/*!
- \fn QCameraViewfinderSettingsControl2::viewfinderSettings() const
-
- Returns the viewfinder settings.
-
- If undefined or unsupported values are passed to QCameraViewfinderSettingsControl2::setViewfinderSettings(),
- this function returns the actual settings used by the camera viewfinder. These may be available
- only once the camera is active.
-*/
-
-/*!
- \fn QCameraViewfinderSettingsControl2::setViewfinderSettings(const QCameraViewfinderSettings &settings)
-
- Sets the camera viewfinder \a settings.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcameraviewfindersettingscontrol.cpp"
diff --git a/src/multimedia/controls/qcameraviewfindersettingscontrol.h b/src/multimedia/controls/qcameraviewfindersettingscontrol.h
deleted file mode 100644
index 7877bd1db..000000000
--- a/src/multimedia/controls/qcameraviewfindersettingscontrol.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-
-#ifndef QCAMERAVIEWFINDERSETTINGSCONTROL_H
-#define QCAMERAVIEWFINDERSETTINGSCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraViewfinderSettingsControl : public QMediaControl
-{
- Q_OBJECT
-public:
- enum ViewfinderParameter {
- Resolution,
- PixelAspectRatio,
- MinimumFrameRate,
- MaximumFrameRate,
- PixelFormat,
- UserParameter = 1000
- };
-
- ~QCameraViewfinderSettingsControl();
-
- virtual bool isViewfinderParameterSupported(ViewfinderParameter parameter) const = 0;
- virtual QVariant viewfinderParameter(ViewfinderParameter parameter) const = 0;
- virtual void setViewfinderParameter(ViewfinderParameter parameter, const QVariant &value) = 0;
-
-protected:
- explicit QCameraViewfinderSettingsControl(QObject *parent = nullptr);
-};
-
-#define QCameraViewfinderSettingsControl_iid "org.qt-project.qt.cameraviewfindersettingscontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraViewfinderSettingsControl, QCameraViewfinderSettingsControl_iid)
-
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraViewfinderSettingsControl2 : public QMediaControl
-{
- Q_OBJECT
-public:
- virtual ~QCameraViewfinderSettingsControl2();
-
- virtual QList<QCameraViewfinderSettings> supportedViewfinderSettings() const = 0;
-
- virtual QCameraViewfinderSettings viewfinderSettings() const = 0;
- virtual void setViewfinderSettings(const QCameraViewfinderSettings &settings) = 0;
-
-protected:
- explicit QCameraViewfinderSettingsControl2(QObject *parent = nullptr);
-};
-
-#define QCameraViewfinderSettingsControl2_iid "org.qt-project.qt.cameraviewfindersettingscontrol2/5.5"
-Q_MEDIA_DECLARE_CONTROL(QCameraViewfinderSettingsControl2, QCameraViewfinderSettingsControl2_iid)
-
-QT_END_NAMESPACE
-
-#endif // QCAMERAVIEWFINDERSETTINGSCONTROL_H
diff --git a/src/multimedia/controls/qcamerazoomcontrol.cpp b/src/multimedia/controls/qcamerazoomcontrol.cpp
deleted file mode 100644
index 1f0835224..000000000
--- a/src/multimedia/controls/qcamerazoomcontrol.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qcamerazoomcontrol.h>
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraZoomControl
- \obsolete
-
-
- \brief The QCameraZoomControl class supplies control for
- optical and digital camera zoom.
-
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- The interface name of QCameraZoomControl is \c org.qt-project.qt.camerazoomcontrol/5.0 as
- defined in QCameraZoomControl_iid.
-
-
- \sa QMediaService::requestControl(), QCamera
-*/
-
-/*!
- \macro QCameraZoomControl_iid
-
- \c org.qt-project.qt.camerazoomcontrol/5.0
-
- Defines the interface name of the QCameraZoomControl class.
-
- \relates QCameraZoomControl
-*/
-
-/*!
- Constructs a camera zoom control object with \a parent.
-*/
-
-QCameraZoomControl::QCameraZoomControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destruct the camera zoom control object.
-*/
-
-QCameraZoomControl::~QCameraZoomControl()
-{
-}
-
-/*!
- \fn qreal QCameraZoomControl::maximumOpticalZoom() const
-
- Returns the maximum optical zoom value, or 1.0 if optical zoom is not supported.
-*/
-
-
-/*!
- \fn qreal QCameraZoomControl::maximumDigitalZoom() const
-
- Returns the maximum digital zoom value, or 1.0 if digital zoom is not supported.
-*/
-
-
-/*!
- \fn qreal QCameraZoomControl::requestedOpticalZoom() const
-
- Return the requested optical zoom value.
-*/
-
-/*!
- \fn qreal QCameraZoomControl::requestedDigitalZoom() const
-
- Return the requested digital zoom value.
-*/
-
-/*!
- \fn qreal QCameraZoomControl::currentOpticalZoom() const
-
- Return the current optical zoom value.
-*/
-
-/*!
- \fn qreal QCameraZoomControl::currentDigitalZoom() const
-
- Return the current digital zoom value.
-*/
-
-/*!
- \fn void QCameraZoomControl::zoomTo(qreal optical, qreal digital)
-
- Sets \a optical and \a digital zoom values.
-
- Zooming can be asynchronous with value changes reported with
- currentDigitalZoomChanged() and currentOpticalZoomChanged() signals.
-
- The backend should expect and correctly handle frequent zoomTo() calls
- during zoom animations or slider movements.
-*/
-
-
-/*!
- \fn void QCameraZoomControl::currentOpticalZoomChanged(qreal zoom)
-
- Signal emitted when the current optical \a zoom value changed.
-*/
-
-/*!
- \fn void QCameraZoomControl::currentDigitalZoomChanged(qreal zoom)
-
- Signal emitted when the current digital \a zoom value changed.
-*/
-
-/*!
- \fn void QCameraZoomControl::requestedOpticalZoomChanged(qreal zoom)
-
- Signal emitted when the requested optical \a zoom value changed.
-*/
-
-/*!
- \fn void QCameraZoomControl::requestedDigitalZoomChanged(qreal zoom)
-
- Signal emitted when the requested digital \a zoom value changed.
-*/
-
-
-/*!
- \fn void QCameraZoomControl::maximumOpticalZoomChanged(qreal zoom)
-
- Signal emitted when the maximum supported optical \a zoom value changed.
-
- The maximum supported zoom value can depend on other camera settings,
- like focusing mode.
-*/
-
-/*!
- \fn void QCameraZoomControl::maximumDigitalZoomChanged(qreal zoom)
-
- Signal emitted when the maximum supported digital \a zoom value changed.
-
- The maximum supported zoom value can depend on other camera settings,
- like capture mode or resolution.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qcamerazoomcontrol.cpp"
diff --git a/src/multimedia/controls/qcamerazoomcontrol.h b/src/multimedia/controls/qcamerazoomcontrol.h
deleted file mode 100644
index feca6a362..000000000
--- a/src/multimedia/controls/qcamerazoomcontrol.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAZOOMCONTROL_H
-#define QCAMERAZOOMCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCameraZoomControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- ~QCameraZoomControl();
-
- virtual qreal maximumOpticalZoom() const = 0;
- virtual qreal maximumDigitalZoom() const = 0;
-
- virtual qreal requestedOpticalZoom() const = 0;
- virtual qreal requestedDigitalZoom() const = 0;
- virtual qreal currentOpticalZoom() const = 0;
- virtual qreal currentDigitalZoom() const = 0;
-
- virtual void zoomTo(qreal optical, qreal digital) = 0;
-
-Q_SIGNALS:
- void maximumOpticalZoomChanged(qreal);
- void maximumDigitalZoomChanged(qreal);
-
- void requestedOpticalZoomChanged(qreal opticalZoom);
- void requestedDigitalZoomChanged(qreal digitalZoom);
- void currentOpticalZoomChanged(qreal opticalZoom);
- void currentDigitalZoomChanged(qreal digitalZoom);
-
-protected:
- explicit QCameraZoomControl(QObject *parent = nullptr);
-};
-
-#define QCameraZoomControl_iid "org.qt-project.qt.camerazoomcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QCameraZoomControl, QCameraZoomControl_iid)
-
-QT_END_NAMESPACE
-
-#endif // QCAMERAZOOMCONTROL_H
diff --git a/src/multimedia/controls/qcustomaudiorolecontrol.cpp b/src/multimedia/controls/qcustomaudiorolecontrol.cpp
deleted file mode 100644
index f1b89eda5..000000000
--- a/src/multimedia/controls/qcustomaudiorolecontrol.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 QNX Software Systems. All rights reserved.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediacontrol_p.h"
-#include "qcustomaudiorolecontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCustomAudioRoleControl
- \obsolete
- \inmodule QtMultimedia
- \ingroup multimedia_control
- \since 5.11
-
- \brief The QCustomAudioRoleControl class provides control over the audio role of a media object.
-
- If a QMediaService supports audio roles it may implement QCustomAudioRoleControl in order to
- provide access to roles unknown to Qt.
-
- The functionality provided by this control is exposed to application code through the
- QMediaPlayer class.
-
- The interface name of QCustomAudioRoleControl is \c org.qt-project.qt.customaudiorolecontrol/5.11 as
- defined in QCustomAudioRoleControl_iid.
-
- \sa QMediaService::requestControl(), QMediaPlayer
-*/
-
-/*!
- \macro QCustomAudioRoleControl_iid
-
- \c org.qt-project.qt.customaudiorolecontrol/5.11
-
- Defines the interface name of the QCustomAudioRoleControl class.
-
- \relates QCustomAudioRoleControl
-*/
-
-/*!
- Construct a QCustomAudioRoleControl with the given \a parent.
-*/
-QCustomAudioRoleControl::QCustomAudioRoleControl(QObject *parent)
- : QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destroys the audio role control.
-*/
-QCustomAudioRoleControl::~QCustomAudioRoleControl()
-{
-}
-
-/*!
- \fn QAudio::Role QCustomAudioRoleControl::customAudioRole() const
-
- Returns the audio role of the media played by the media service.
-*/
-
-/*!
- \fn void QCustomAudioRoleControl::setCustomAudioRole(const QString &role)
-
- Sets the audio \a role of the media played by the media service.
-*/
-
-/*!
- \fn QStringList QCustomAudioRoleControl::supportedCustomAudioRoles() const
-
- Returns a list of custom audio roles that the media service supports. An
- empty list may indicate that the supported custom audio roles aren't known.
- The list may not be complete.
-*/
-
-/*!
- \fn void QCustomAudioRoleControl::customAudioRoleChanged(const QString &role)
-
- Signal emitted when the audio \a role has changed.
- */
-
-QT_END_NAMESPACE
-
-#include "moc_qcustomaudiorolecontrol.cpp"
diff --git a/src/multimedia/controls/qcustomaudiorolecontrol.h b/src/multimedia/controls/qcustomaudiorolecontrol.h
deleted file mode 100644
index 5a587c034..000000000
--- a/src/multimedia/controls/qcustomaudiorolecontrol.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 QNX Software Systems. All rights reserved.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCUSTOMAUDIOROLECONTROL_H
-#define QCUSTOMAUDIOROLECONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qaudio.h>
-
-QT_BEGIN_NAMESPACE
-
-// Class forward declaration required for QDoc bug
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QCustomAudioRoleControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QCustomAudioRoleControl();
-
- virtual QString customAudioRole() const = 0;
- virtual void setCustomAudioRole(const QString &role) = 0;
-
- virtual QStringList supportedCustomAudioRoles() const = 0;
-
-Q_SIGNALS:
- void customAudioRoleChanged(const QString &role);
-
-protected:
- explicit QCustomAudioRoleControl(QObject *parent = nullptr);
-};
-
-#define QCustomAudioRoleControl_iid "org.qt-project.qt.customaudiorolecontrol/5.11"
-Q_MEDIA_DECLARE_CONTROL(QCustomAudioRoleControl, QCustomAudioRoleControl_iid)
-
-QT_END_NAMESPACE
-
-#endif // QCUSTOMAUDIOROLECONTROL_H
diff --git a/src/multimedia/controls/qimageencodercontrol.cpp b/src/multimedia/controls/qimageencodercontrol.cpp
deleted file mode 100644
index 6223c33c7..000000000
--- a/src/multimedia/controls/qimageencodercontrol.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qimageencodercontrol.h"
-#include <QtCore/qstringlist.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QImageEncoderControl
- \obsolete
-
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- \brief The QImageEncoderControl class provides access to the settings of a media service that
- performs image encoding.
-
- If a QMediaService supports encoding image data it will implement QImageEncoderControl.
- This control allows to \l {setImageSettings()}{set image encoding settings} and
- provides functions for quering supported image \l {supportedImageCodecs()}{codecs} and
- \l {supportedResolutions()}{resolutions}.
-
- The interface name of QImageEncoderControl is \c org.qt-project.qt.imageencodercontrol/5.0 as
- defined in QImageEncoderControl_iid.
-
- \sa QImageEncoderSettings, QMediaService::requestControl()
-*/
-
-/*!
- \macro QImageEncoderControl_iid
-
- \c org.qt-project.qt.imageencodercontrol/5.0
-
- Defines the interface name of the QImageEncoderControl class.
-
- \relates QImageEncoderControl
-*/
-
-/*!
- Constructs a new image encoder control object with the given \a parent
-*/
-QImageEncoderControl::QImageEncoderControl(QObject *parent)
- :QMediaControl(parent)
-{
-}
-
-/*!
- Destroys the image encoder control.
-*/
-QImageEncoderControl::~QImageEncoderControl()
-{
-}
-
-/*!
- \fn QImageEncoderControl::supportedResolutions(const QImageEncoderSettings &settings = QImageEncoderSettings(),
- bool *continuous = 0) const
-
- Returns a list of supported resolutions.
-
- If non null image \a settings parameter is passed,
- the returned list is reduced to resolutions supported with partial settings applied.
- It can be used to query the list of resolutions, supported by specific image codec.
-
- If the encoder supports arbitrary resolutions within the supported resolutions range,
- *\a continuous is set to true, otherwise *\a continuous is set to false.
-*/
-
-/*!
- \fn QImageEncoderControl::supportedImageCodecs() const
-
- Returns a list of supported image codecs.
-*/
-
-/*!
- \fn QImageEncoderControl::imageCodecDescription(const QString &codec) const
-
- Returns a description of an image \a codec.
-*/
-
-/*!
- \fn QImageEncoderControl::imageSettings() const
-
- Returns the currently used image encoder settings.
-
- The returned value may be different tha passed to QImageEncoderControl::setImageSettings()
- if the settings contains the default or undefined parameters.
- In this case if the undefined parameters are already resolved, they should be returned.
-*/
-
-/*!
- \fn QImageEncoderControl::setImageSettings(const QImageEncoderSettings &settings)
-
- Sets the selected image encoder \a settings.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qimageencodercontrol.cpp"
diff --git a/src/multimedia/controls/qimageencodercontrol.h b/src/multimedia/controls/qimageencodercontrol.h
deleted file mode 100644
index c33266d9a..000000000
--- a/src/multimedia/controls/qimageencodercontrol.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QIMAGEENCODERCONTROL_H
-#define QIMAGEENCODERCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediarecorder.h>
-#include <QtMultimedia/qmediaencodersettings.h>
-
-#include <QtCore/qsize.h>
-
-QT_BEGIN_NAMESPACE
-
-class QByteArray;
-QT_END_NAMESPACE
-
-QT_BEGIN_NAMESPACE
-
-class Q_MULTIMEDIA_EXPORT QImageEncoderControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QImageEncoderControl();
-
- virtual QStringList supportedImageCodecs() const = 0;
- virtual QString imageCodecDescription(const QString &codec) const = 0;
-
- virtual QList<QSize> supportedResolutions(const QImageEncoderSettings &settings,
- bool *continuous = nullptr) const = 0;
-
- virtual QImageEncoderSettings imageSettings() const = 0;
- virtual void setImageSettings(const QImageEncoderSettings &settings) = 0;
-
-protected:
- explicit QImageEncoderControl(QObject *parent = nullptr);
-};
-
-#define QImageEncoderControl_iid "org.qt-project.qt.imageencodercontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QImageEncoderControl, QImageEncoderControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/multimedia/controls/qmediaaudioprobecontrol.cpp b/src/multimedia/controls/qmediaaudioprobecontrol.cpp
deleted file mode 100644
index e22135903..000000000
--- a/src/multimedia/controls/qmediaaudioprobecontrol.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaaudioprobecontrol.h"
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QMediaAudioProbeControl
- \obsolete
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- \brief The QMediaAudioProbeControl class allows control over probing audio data in media objects.
-
- \l QAudioProbe is the client facing class for probing audio - this class is implemented by
- media backends to provide this functionality.
-
- The interface name of QMediaAudioProbeControl is \c org.qt-project.qt.mediaaudioprobecontrol/5.0 as
- defined in QMediaAudioProbeControl_iid.
-
- \sa QAudioProbe, QMediaService::requestControl(), QMediaPlayer, QCamera
-*/
-
-/*!
- \macro QMediaAudioProbeControl_iid
-
- \c org.qt-project.qt.mediaaudioprobecontrol/5.0
-
- Defines the interface name of the QMediaAudioProbeControl class.
-
- \relates QMediaAudioProbeControl
-*/
-
-/*!
- Create a new media audio probe control object with the given \a parent.
-*/
-QMediaAudioProbeControl::QMediaAudioProbeControl(QObject *parent)
- : QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*! Destroys this audio probe control */
-QMediaAudioProbeControl::~QMediaAudioProbeControl()
-{
-}
-
-/*!
- \fn QMediaAudioProbeControl::audioBufferProbed(const QAudioBuffer &buffer)
-
- This signal should be emitted when an audio \a buffer is processed in the
- media service.
-*/
-
-
-/*!
- \fn QMediaAudioProbeControl::flush()
-
- This signal should be emitted when it is required to release all frames.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaaudioprobecontrol.cpp"
diff --git a/src/multimedia/controls/qmediaaudioprobecontrol.h b/src/multimedia/controls/qmediaaudioprobecontrol.h
deleted file mode 100644
index 74cb1bc5a..000000000
--- a/src/multimedia/controls/qmediaaudioprobecontrol.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIAAUDIOPROBECONTROL_H
-#define QMEDIAAUDIOPROBECONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAudioBuffer;
-class Q_MULTIMEDIA_EXPORT QMediaAudioProbeControl : public QMediaControl
-{
- Q_OBJECT
-public:
- virtual ~QMediaAudioProbeControl();
-
-Q_SIGNALS:
- void audioBufferProbed(const QAudioBuffer &buffer);
- void flush();
-
-protected:
- explicit QMediaAudioProbeControl(QObject *parent = nullptr);
-};
-
-#define QMediaAudioProbeControl_iid "org.qt-project.qt.mediaaudioprobecontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMediaAudioProbeControl, QMediaAudioProbeControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIAAUDIOPROBECONTROL_H
diff --git a/src/multimedia/controls/qmediaavailabilitycontrol.cpp b/src/multimedia/controls/qmediaavailabilitycontrol.cpp
deleted file mode 100644
index 68b404369..000000000
--- a/src/multimedia/controls/qmediaavailabilitycontrol.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaavailabilitycontrol.h"
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QMediaAvailabilityControl
- \obsolete
-
- \brief The QMediaAvailabilityControl class supplies a control for reporting availability of a service.
-
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- An instance of QMediaObject (or its derived classes) can report any changes
- in availability via this control.
-
- The interface name of QMediaAvailabilityControl is \c org.qt-project.qt.mediaavailabilitycontrol/5.0 as
- defined in QMediaAvailabilityControl_iid.
-
- \sa QMediaService::requestControl(), QMediaObject
-*/
-
-/*!
- \macro QMediaAvailabilityControl_iid
-
- \c org.qt-project.qt.mediaavailabilitycontrol/5.0
-
- Defines the interface name of the QMediaAvailabilityControl class.
-
- \relates QMediaAvailabilityControl
-*/
-
-/*!
- Constructs an availability control object with \a parent.
-*/
-QMediaAvailabilityControl::QMediaAvailabilityControl(QObject *parent)
- : QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destruct the availability control object.
-*/
-QMediaAvailabilityControl::~QMediaAvailabilityControl()
-{
-}
-
-
-/*!
- \fn QMultimedia::AvailabilityStatus QMediaAvailabilityControl::availability() const
-
- Returns the current availability of this instance of the media service.
- If the availability changes at run time (for example, some other media
- client takes all media resources) the availabilityChanges() signal
- should be emitted.
-*/
-
-
-/*!
- \fn void QMediaAvailabilityControl::availabilityChanged(QMultimedia::AvailabilityStatus availability)
-
- Signal emitted when the current \a availability value changed.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaavailabilitycontrol.cpp"
diff --git a/src/multimedia/controls/qmediaavailabilitycontrol.h b/src/multimedia/controls/qmediaavailabilitycontrol.h
deleted file mode 100644
index a61617b1f..000000000
--- a/src/multimedia/controls/qmediaavailabilitycontrol.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIAAVAILABILITYCONTROL_H
-#define QMEDIAAVAILABILITYCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmultimedia.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QMediaAvailabilityControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- ~QMediaAvailabilityControl();
-
- virtual QMultimedia::AvailabilityStatus availability() const = 0;
-
-Q_SIGNALS:
- void availabilityChanged(QMultimedia::AvailabilityStatus availability);
-
-protected:
- explicit QMediaAvailabilityControl(QObject *parent = nullptr);
-};
-
-#define QMediaAvailabilityControl_iid "org.qt-project.qt.mediaavailabilitycontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMediaAvailabilityControl, QMediaAvailabilityControl_iid)
-
-QT_END_NAMESPACE
-
-#endif // QMEDIAAVAILABILITYCONTROL_H
diff --git a/src/multimedia/controls/qmediacontainercontrol.cpp b/src/multimedia/controls/qmediacontainercontrol.cpp
deleted file mode 100644
index 2b2c8b78b..000000000
--- a/src/multimedia/controls/qmediacontainercontrol.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include "qmediacontainercontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QMediaContainerControl
- \obsolete
-
- \brief The QMediaContainerControl class provides access to the output container format of a QMediaService.
-
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- If a QMediaService supports writing encoded data it will implement
- QMediaContainerControl. This control provides information about the output
- containers supported by a media service and allows one to be selected as
- the current output containers.
-
- The functionality provided by this control is exposed to application code
- through the QMediaRecorder class.
-
- The interface name of QMediaContainerControl is \c org.qt-project.qt.mediacontainercontrol/5.0 as
- defined in QMediaContainerControl_iid.
-
- \sa QMediaService::requestControl(), QMediaRecorder
-*/
-
-/*!
- \macro QMediaContainerControl_iid
-
- \c org.qt-project.qt.mediacontainercontrol/5.0
-
- Defines the interface name of the QMediaContainerControl class.
-
- \relates QMediaContainerControl
-*/
-
-/*!
- Constructs a new media container control with the given \a parent.
-*/
-QMediaContainerControl::QMediaContainerControl(QObject *parent)
- :QMediaControl(parent)
-{
-}
-
-/*!
- Destroys a media container control.
-*/
-QMediaContainerControl::~QMediaContainerControl()
-{
-}
-
-
-/*!
- \fn QMediaContainerControl::supportedContainers() const
-
- Returns a list of MIME types of supported container formats.
-*/
-
-/*!
- \fn QMediaContainerControl::containerFormat() const
-
- Returns the selected container format.
-*/
-
-/*!
- \fn QMediaContainerControl::setContainerFormat(const QString &format)
-
- Sets the current container \a format.
-*/
-
-/*!
- \fn QMediaContainerControl::containerDescription(const QString &formatMimeType) const
-
- Returns a description of the container \a formatMimeType.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediacontainercontrol.cpp"
diff --git a/src/multimedia/controls/qmediacontainercontrol.h b/src/multimedia/controls/qmediacontainercontrol.h
deleted file mode 100644
index 23c2918b9..000000000
--- a/src/multimedia/controls/qmediacontainercontrol.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QMEDIACONTAINERCONTROL_H
-#define QMEDIACONTAINERCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QMediaContainerControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QMediaContainerControl();
-
- virtual QStringList supportedContainers() const = 0;
- virtual QString containerFormat() const = 0;
- virtual void setContainerFormat(const QString &format) = 0;
-
- virtual QString containerDescription(const QString &formatMimeType) const = 0;
-
-protected:
- explicit QMediaContainerControl(QObject *parent = nullptr);
-};
-
-#define QMediaContainerControl_iid "org.qt-project.qt.mediacontainercontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMediaContainerControl, QMediaContainerControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIACONTAINERCONTROL_H
diff --git a/src/multimedia/controls/qmediagaplessplaybackcontrol.cpp b/src/multimedia/controls/qmediagaplessplaybackcontrol.cpp
deleted file mode 100644
index c9f531454..000000000
--- a/src/multimedia/controls/qmediagaplessplaybackcontrol.cpp
+++ /dev/null
@@ -1,157 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediagaplessplaybackcontrol.h"
-#include "qmediacontrol_p.h"
-
-/*!
- \class QMediaGaplessPlaybackControl
- \obsolete
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- \brief The QMediaGaplessPlaybackControl class provides access to the gapless playback
- related control of a QMediaService.
-
- If a QMediaService supports gapless playback it will implement QMediaGaplessPlaybackControl.
- This control provides a means to set the \l {setNextMedia()}{next media} or
- \l {setCrossfadeTime()}{crossfade time} for smooth transitions between tracks.
-
- The functionality provided by this control is exposed to application
- code through the QMediaPlayer class.
-
- The interface name of QMediaGaplessPlaybackControl is
- \c org.qt-project.qt.mediagaplessplaybackcontrol/5.0 as defined in QMediaGaplessPlaybackControl_iid.
-
- \sa QMediaService::requestControl(), QMediaPlayer
-*/
-
-/*!
- \macro QMediaGaplessPlaybackControl_iid
-
- \c org.qt-project.qt.mediagaplessplaybackcontrol/5.0
-
- Defines the interface name of the QMediaGaplessPlaybackControl class.
-
- \relates QMediaGaplessPlaybackControl
-*/
-
-/*!
- Destroys a gapless playback control.
-*/
-QMediaGaplessPlaybackControl::~QMediaGaplessPlaybackControl()
-{
-}
-
-/*!
- Constructs a new gapless playback control with the given \a parent.
-*/
-QMediaGaplessPlaybackControl::QMediaGaplessPlaybackControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- \fn QMediaGaplessPlaybackControl::nextMedia() const
-
- Returns the content of the next media
-*/
-
-/*!
- \fn QMediaGaplessPlaybackControl::setNextMedia(const QMediaContent& media)
-
- Sets the next \a media for smooth transition.
-*/
-
-/*!
- \fn QMediaGaplessPlaybackControl::nextMediaChanged(const QMediaContent& media)
-
- Signals that the next \a media has changed (either explicitly via \l setNextMedia() or when the
- player clears the next media while advancing to it).
-
- \sa nextMedia()
-*/
-
-/*!
- \fn QMediaGaplessPlaybackControl::advancedToNextMedia()
-
- Signals when the player advances to the next media (the content of next media will be cleared).
-
- \sa nextMedia()
-*/
-
-/*!
- \fn QMediaGaplessPlaybackControl::isCrossfadeSupported() const
-
- Indicates whether crossfading is supported or not.
- If crossfading is not supported, \l setCrossfadeTime() will be ignored and \l crossfadeTime() will
- always return 0.
-
-*/
-
-/*!
- \fn QMediaGaplessPlaybackControl::setCrossfadeTime(qreal crossfadeTime)
-
- Sets the \a crossfadeTime in seconds for smooth transition.
-
- Positive value means how much time it will take for the next media to transit from silent to
- full volume and vice versa for current one. So both current and the next one will be playing
- during this period of time.
-
- A crossfade time of zero or negative will result in gapless playback (suitable for some
- continuous media).
-
-*/
-
-/*!
- \fn QMediaGaplessPlaybackControl::crossfadeTime() const
-
- Returns current crossfade time in seconds.
-*/
-
-/*!
- \fn QMediaGaplessPlaybackControl::crossfadeTimeChanged(qreal crossfadeTime)
-
- Signals that the \a crossfadeTime has changed.
-
- \sa crossfadeTime()
-*/
-
diff --git a/src/multimedia/controls/qmediagaplessplaybackcontrol.h b/src/multimedia/controls/qmediagaplessplaybackcontrol.h
deleted file mode 100644
index 23e2b4fc2..000000000
--- a/src/multimedia/controls/qmediagaplessplaybackcontrol.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef QMEDIAGAPLESSPLAYBACKCONTROL_H
-#define QMEDIAGAPLESSPLAYBACKCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediacontent.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QMediaGaplessPlaybackControl : public QMediaControl
-{
- Q_OBJECT
-public:
- virtual ~QMediaGaplessPlaybackControl();
-
- virtual QMediaContent nextMedia() const = 0;
- virtual void setNextMedia(const QMediaContent &media) = 0;
-
- virtual bool isCrossfadeSupported() const = 0;
- virtual qreal crossfadeTime() const = 0;
- virtual void setCrossfadeTime(qreal crossfadeTime) = 0;
-
-Q_SIGNALS:
- void crossfadeTimeChanged(qreal crossfadeTime);
- void nextMediaChanged(const QMediaContent& media);
- void advancedToNextMedia();
-
-protected:
- explicit QMediaGaplessPlaybackControl(QObject *parent = nullptr);
-};
-
-#define QMediaGaplessPlaybackControl_iid "org.qt-project.qt.mediagaplessplaybackcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMediaGaplessPlaybackControl, QMediaGaplessPlaybackControl_iid)
-
-QT_END_NAMESPACE
-
-#endif // QMEDIAGAPLESSPLAYBACKCONTROL_H
diff --git a/src/multimedia/controls/qmediaplayercontrol.cpp b/src/multimedia/controls/qmediaplayercontrol.cpp
deleted file mode 100644
index a180413b9..000000000
--- a/src/multimedia/controls/qmediaplayercontrol.cpp
+++ /dev/null
@@ -1,386 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaplayercontrol.h"
-#include "qmediacontrol_p.h"
-#include "qmediaplayer.h"
-
-QT_BEGIN_NAMESPACE
-
-
-/*!
- \class QMediaPlayerControl
- \obsolete
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
-
- \brief The QMediaPlayerControl class provides access to the media playing
- functionality of a QMediaService.
-
- If a QMediaService can play media is will implement QMediaPlayerControl.
- This control provides a means to set the \l {setMedia()}{media} to play,
- \l {play()}{start}, \l {pause()} {pause} and \l {stop()}{stop} playback,
- \l {setPosition()}{seek}, and control the \l {setVolume()}{volume}.
- It also provides feedback on the \l {duration()}{duration} of the media,
- the current \l {position()}{position}, and \l {bufferStatus()}{buffering}
- progress.
-
- The functionality provided by this control is exposed to application
- code through the QMediaPlayer class.
-
- The interface name of QMediaPlayerControl is \c org.qt-project.qt.mediaplayercontrol/5.0 as
- defined in QMediaPlayerControl_iid.
-
- \sa QMediaService::requestControl(), QMediaPlayer
-*/
-
-/*!
- \macro QMediaPlayerControl_iid
-
- \c org.qt-project.qt.mediaplayercontrol/5.0
-
- Defines the interface name of the QMediaPlayerControl class.
-
- \relates QMediaPlayerControl
-*/
-
-/*!
- Destroys a media player control.
-*/
-QMediaPlayerControl::~QMediaPlayerControl()
-{
-}
-
-/*!
- Constructs a new media player control with the given \a parent.
-*/
-QMediaPlayerControl::QMediaPlayerControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- \fn QMediaPlayerControl::state() const
-
- Returns the state of a player control.
-*/
-
-/*!
- \fn QMediaPlayerControl::stateChanged(QMediaPlayer::State newState)
-
- Signals that the state of a player control has changed to \a newState.
-
- \sa state()
-*/
-
-/*!
- \fn QMediaPlayerControl::mediaStatus() const
-
- Returns the status of the current media.
-*/
-
-
-/*!
- \fn QMediaPlayerControl::mediaStatusChanged(QMediaPlayer::MediaStatus status)
-
- Signals that the \a status of the current media has changed.
-
- \sa mediaStatus()
-*/
-
-
-/*!
- \fn QMediaPlayerControl::duration() const
-
- Returns the duration of the current media in milliseconds.
-*/
-
-/*!
- \fn QMediaPlayerControl::durationChanged(qint64 duration)
-
- Signals that the \a duration of the current media has changed.
-
- \sa duration()
-*/
-
-/*!
- \fn QMediaPlayerControl::position() const
-
- Returns the current playback position in milliseconds.
-*/
-
-/*!
- \fn QMediaPlayerControl::setPosition(qint64 position)
-
- Sets the playback \a position of the current media. This will initiate a seek and it may take
- some time for playback to reach the position set.
-*/
-
-/*!
- \fn QMediaPlayerControl::positionChanged(qint64 position)
-
- Signals the playback \a position has changed.
-
- This is only emitted in when there has been a discontinous change in the playback postion, such
- as a seek or the position being reset.
-
- \sa position()
-*/
-
-/*!
- \fn QMediaPlayerControl::volume() const
-
- Returns the audio volume of a player control.
-*/
-
-/*!
- \fn QMediaPlayerControl::setVolume(int volume)
-
- Sets the audio \a volume of a player control.
-
- The volume is scaled linearly, ranging from \c 0 (silence) to \c 100 (full volume).
-*/
-
-/*!
- \fn QMediaPlayerControl::volumeChanged(int volume)
-
- Signals the audio \a volume of a player control has changed.
-
- \sa volume()
-*/
-
-/*!
- \fn QMediaPlayerControl::isMuted() const
-
- Returns the mute state of a player control.
-*/
-
-/*!
- \fn QMediaPlayerControl::setMuted(bool mute)
-
- Sets the \a mute state of a player control.
-*/
-
-/*!
- \fn QMediaPlayerControl::mutedChanged(bool mute)
-
- Signals a change in the \a mute status of a player control.
-
- \sa isMuted()
-*/
-
-/*!
- \fn QMediaPlayerControl::bufferStatus() const
-
- Returns the buffering progress of the current media. Progress is measured in the percentage
- of the buffer filled.
-*/
-
-/*!
- \fn QMediaPlayerControl::bufferStatusChanged(int percentFilled)
-
- Signal the amount of the local buffer filled as a percentage by \a percentFilled.
-
- \sa bufferStatus()
-*/
-
-/*!
- \fn QMediaPlayerControl::isAudioAvailable() const
-
- Identifies if there is audio output available for the current media.
-
- Returns true if audio output is available and false otherwise.
-*/
-
-/*!
- \fn QMediaPlayerControl::audioAvailableChanged(bool audioAvailable)
-
- Signals that there has been a change in the availability of audio output \a audioAvailable.
-
- \sa isAudioAvailable()
-*/
-
-/*!
- \fn QMediaPlayerControl::isVideoAvailable() const
-
- Identifies if there is video output available for the current media.
-
- Returns true if video output is available and false otherwise.
-*/
-
-/*!
- \fn QMediaPlayerControl::videoAvailableChanged(bool videoAvailable)
-
- Signal that the availability of visual content has changed to \a videoAvailable.
-
- \sa isVideoAvailable()
-*/
-
-/*!
- \fn QMediaPlayerControl::isSeekable() const
-
- Identifies if the current media is seekable.
-
- Returns true if it possible to seek within the current media, and false otherwise.
-*/
-
-/*!
- \fn QMediaPlayerControl::seekableChanged(bool seekable)
-
- Signals that the \a seekable state of a player control has changed.
-
- \sa isSeekable()
-*/
-
-/*!
- \fn QMediaPlayerControl::availablePlaybackRanges() const
-
- Returns a range of times in milliseconds that can be played back.
-
- Usually for local files this is a continuous interval equal to [0..duration()]
- or an empty time range if seeking is not supported, but for network sources
- it refers to the buffered parts of the media.
-*/
-
-/*!
- \fn QMediaPlayerControl::availablePlaybackRangesChanged(const QMediaTimeRange &ranges)
-
- Signals that the available media playback \a ranges have changed.
-
- \sa QMediaPlayerControl::availablePlaybackRanges()
-*/
-
-/*!
- \fn qreal QMediaPlayerControl::playbackRate() const
-
- Returns the rate of playback.
-*/
-
-/*!
- \fn QMediaPlayerControl::setPlaybackRate(qreal rate)
-
- Sets the \a rate of playback.
-*/
-
-/*!
- \fn QMediaPlayerControl::media() const
-
- Returns the current media source.
-*/
-
-/*!
- \fn QMediaPlayerControl::mediaStream() const
-
- Returns the current media stream. This is only a valid if a stream was passed to setMedia().
-
- \sa setMedia()
-*/
-
-/*!
- \fn QMediaPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream)
-
- Sets the current \a media source. If a \a stream is supplied; data will be read from that
- instead of attempting to resolve the media source. The media source may still be used to
- supply media information such as mime type.
-
- Setting the media to a null QMediaContent will cause the control to discard all
- information relating to the current media source and to cease all I/O operations related
- to that media.
-
- Qt resource files are never passed as is. If the service supports
- QMediaServiceProviderHint::StreamPlayback, a \a stream is supplied, pointing to an opened
- QFile. Otherwise, the resource is copied into a temporary file and \a media contains the
- url to that file.
-*/
-
-/*!
- \fn QMediaPlayerControl::mediaChanged(const QMediaContent& content)
-
- Signals that the current media \a content has changed.
-*/
-
-/*!
- \fn QMediaPlayerControl::play()
-
- Starts playback of the current media.
-
- If successful the player control will immediately enter the \l {QMediaPlayer::PlayingState}
- {playing} state.
-
- \sa state()
-*/
-
-/*!
- \fn QMediaPlayerControl::pause()
-
- Pauses playback of the current media.
-
- If successful the player control will immediately enter the \l {QMediaPlayer::PausedState}
- {paused} state.
-
- \sa state(), play(), stop()
-*/
-
-/*!
- \fn QMediaPlayerControl::stop()
-
- Stops playback of the current media.
-
- If successful the player control will immediately enter the \l {QMediaPlayer::StoppedState}
- {stopped} state.
-*/
-
-/*!
- \fn QMediaPlayerControl::error(int error, const QString &errorString)
-
- Signals that an \a error has occurred. The \a errorString provides a more detailed explanation.
-*/
-
-/*!
- \fn QMediaPlayerControl::playbackRateChanged(qreal rate)
-
- Signal emitted when playback rate changes to \a rate.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaplayercontrol.cpp"
diff --git a/src/multimedia/controls/qmediaplayercontrol.h b/src/multimedia/controls/qmediaplayercontrol.h
deleted file mode 100644
index 8b5072572..000000000
--- a/src/multimedia/controls/qmediaplayercontrol.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIAPLAYERCONTROL_H
-#define QMEDIAPLAYERCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaplayer.h>
-#include <QtMultimedia/qmediatimerange.h>
-
-#include <QtCore/qpair.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaPlaylist;
-
-class Q_MULTIMEDIA_EXPORT QMediaPlayerControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- ~QMediaPlayerControl();
-
- virtual QMediaPlayer::State state() const = 0;
-
- virtual QMediaPlayer::MediaStatus mediaStatus() const = 0;
-
- virtual qint64 duration() const = 0;
-
- virtual qint64 position() const = 0;
- virtual void setPosition(qint64 position) = 0;
-
- virtual int volume() const = 0;
- virtual void setVolume(int volume) = 0;
-
- virtual bool isMuted() const = 0;
- virtual void setMuted(bool mute) = 0;
-
- virtual int bufferStatus() const = 0;
-
- virtual bool isAudioAvailable() const = 0;
- virtual bool isVideoAvailable() const = 0;
-
- virtual bool isSeekable() const = 0;
-
- virtual QMediaTimeRange availablePlaybackRanges() const = 0;
-
- virtual qreal playbackRate() const = 0;
- virtual void setPlaybackRate(qreal rate) = 0;
-
- virtual QMediaContent media() const = 0;
- virtual const QIODevice *mediaStream() const = 0;
- virtual void setMedia(const QMediaContent &media, QIODevice *stream) = 0;
-
- virtual void play() = 0;
- virtual void pause() = 0;
- virtual void stop() = 0;
-
-Q_SIGNALS:
- void mediaChanged(const QMediaContent& content);
- void durationChanged(qint64 duration);
- void positionChanged(qint64 position);
- void stateChanged(QMediaPlayer::State newState);
- void mediaStatusChanged(QMediaPlayer::MediaStatus status);
- void volumeChanged(int volume);
- void mutedChanged(bool mute);
- void audioAvailableChanged(bool audioAvailable);
- void videoAvailableChanged(bool videoAvailable);
- void bufferStatusChanged(int percentFilled);
- void seekableChanged(bool seekable);
- void availablePlaybackRangesChanged(const QMediaTimeRange &ranges);
- void playbackRateChanged(qreal rate);
- void error(int error, const QString &errorString);
-
-protected:
- explicit QMediaPlayerControl(QObject *parent = nullptr);
-};
-
-#define QMediaPlayerControl_iid "org.qt-project.qt.mediaplayercontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMediaPlayerControl, QMediaPlayerControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIAPLAYERCONTROL_H
-
diff --git a/src/multimedia/controls/qmediaplaylistcontrol.cpp b/src/multimedia/controls/qmediaplaylistcontrol.cpp
deleted file mode 100644
index 61e20e170..000000000
--- a/src/multimedia/controls/qmediaplaylistcontrol.cpp
+++ /dev/null
@@ -1,206 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include "qmediaplaylistcontrol_p.h"
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QMediaPlaylistControl
- \internal
-
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
-
- \brief The QMediaPlaylistControl class provides access to the playlist
- functionality of a QMediaService.
-
- If a QMediaService contains an internal playlist it will implement
- QMediaPlaylistControl. This control provides access to the contents of the
- \l {playlistProvider()}{playlist}, as well as the \l
- {currentIndex()}{position} of the current media, and a means of navigating
- to the \l {next()}{next} and \l {previous()}{previous} media.
-
- The functionality provided by the control is exposed to application code
- through the QMediaPlaylist class.
-
- The interface name of QMediaPlaylistControl is \c org.qt-project.qt.mediaplaylistcontrol/5.0 as
- defined in QMediaPlaylistControl_iid.
-
- \sa QMediaService::requestControl(), QMediaPlayer
-*/
-
-/*!
- \macro QMediaPlaylistControl_iid
-
- \c org.qt-project.qt.mediaplaylistcontrol/5.0
-
- Defines the interface name of the QMediaPlaylistControl class.
-
- \relates QMediaPlaylistControl
-*/
-
-/*!
- Create a new playlist control object with the given \a parent.
-*/
-QMediaPlaylistControl::QMediaPlaylistControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destroys the playlist control.
-*/
-QMediaPlaylistControl::~QMediaPlaylistControl()
-{
-}
-
-
-/*!
- \fn QMediaPlaylistControl::playlistProvider() const
-
- Returns the playlist used by this media player.
-*/
-
-/*!
- \fn QMediaPlaylistControl::setPlaylistProvider(QMediaPlaylistProvider *playlist)
-
- Set the playlist of this media player to \a playlist.
-
- In many cases it is possible just to use the playlist
- constructed by player, but sometimes replacing the whole
- playlist allows to avoid copyting of all the items bettween playlists.
-
- Returns true if player can use this passed playlist; otherwise returns false.
-
-*/
-
-/*!
- \fn QMediaPlaylistControl::currentIndex() const
-
- Returns position of the current media source in the playlist.
-*/
-
-/*!
- \fn QMediaPlaylistControl::setCurrentIndex(int position)
-
- Jump to the item at the given \a position.
-*/
-
-/*!
- \fn QMediaPlaylistControl::nextIndex(int step) const
-
- Returns the index of item, which were current after calling next()
- \a step times.
-
- Returned value depends on the size of playlist, current position
- and playback mode.
-
- \sa QMediaPlaylist::playbackMode
-*/
-
-/*!
- \fn QMediaPlaylistControl::previousIndex(int step) const
-
- Returns the index of item, which were current after calling previous()
- \a step times.
-
- \sa QMediaPlaylist::playbackMode
-*/
-
-/*!
- \fn QMediaPlaylistControl::next()
-
- Moves to the next item in playlist.
-*/
-
-/*!
- \fn QMediaPlaylistControl::previous()
-
- Returns to the previous item in playlist.
-*/
-
-/*!
- \fn QMediaPlaylistControl::playbackMode() const
-
- Returns the playlist navigation mode.
-
- \sa QMediaPlaylist::PlaybackMode
-*/
-
-/*!
- \fn QMediaPlaylistControl::setPlaybackMode(QMediaPlaylist::PlaybackMode mode)
-
- Sets the playback \a mode.
-
- \sa QMediaPlaylist::PlaybackMode
-*/
-
-/*!
- \fn QMediaPlaylistControl::playlistProviderChanged()
-
- Signal emitted when the playlist provider has changed.
-*/
-
-/*!
- \fn QMediaPlaylistControl::currentIndexChanged(int position)
-
- Signal emitted when the playlist \a position is changed.
-*/
-
-/*!
- \fn QMediaPlaylistControl::playbackModeChanged(QMediaPlaylist::PlaybackMode mode)
-
- Signal emitted when the playback \a mode is changed.
-*/
-
-/*!
- \fn QMediaPlaylistControl::currentMediaChanged(const QMediaContent& content)
-
- Signal emitted when current media changes to \a content.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaplaylistcontrol_p.cpp"
diff --git a/src/multimedia/controls/qmediaplaylistcontrol_p.h b/src/multimedia/controls/qmediaplaylistcontrol_p.h
deleted file mode 100644
index 93c5a3e25..000000000
--- a/src/multimedia/controls/qmediaplaylistcontrol_p.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QMEDIAPLAYLISTCONTROL_P_H
-#define QMEDIAPLAYLISTCONTROL_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qobject.h>
-#include "qmediacontrol.h"
-#include <private/qmediaplaylistnavigator_p.h>
-
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaPlaylistProvider;
-
-class Q_MULTIMEDIA_EXPORT QMediaPlaylistControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QMediaPlaylistControl();
-
- virtual QMediaPlaylistProvider* playlistProvider() const = 0;
- virtual bool setPlaylistProvider(QMediaPlaylistProvider *playlist) = 0;
-
- virtual int currentIndex() const = 0;
- virtual void setCurrentIndex(int position) = 0;
- virtual int nextIndex(int steps) const = 0;
- virtual int previousIndex(int steps) const = 0;
-
- virtual void next() = 0;
- virtual void previous() = 0;
-
- virtual QMediaPlaylist::PlaybackMode playbackMode() const = 0;
- virtual void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) = 0;
-
-Q_SIGNALS:
- void playlistProviderChanged();
- void currentIndexChanged(int position);
- void currentMediaChanged(const QMediaContent&);
- void playbackModeChanged(QMediaPlaylist::PlaybackMode mode);
-
-protected:
- QMediaPlaylistControl(QObject *parent = nullptr);
-};
-
-#define QMediaPlaylistControl_iid "org.qt-project.qt.mediaplaylistcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMediaPlaylistControl, QMediaPlaylistControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIAPLAYLISTCONTROL_P_H
diff --git a/src/multimedia/controls/qmediaplaylistsourcecontrol.cpp b/src/multimedia/controls/qmediaplaylistsourcecontrol.cpp
deleted file mode 100644
index f95c4b508..000000000
--- a/src/multimedia/controls/qmediaplaylistsourcecontrol.cpp
+++ /dev/null
@@ -1,126 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include "qmediaplaylistsourcecontrol_p.h"
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QMediaPlaylistSourceControl
- \internal
-
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
-
- \brief The QMediaPlaylistSourceControl class provides access to the playlist playback
- functionality of a QMediaService.
-
- This control allows QMediaPlaylist to be passed directly to the service
- instead of playing media sources one by one. This control should be
- implemented if backend benefits from knowing the next media source to be
- played, for example for preloading, cross fading or gap-less playback.
-
- If QMediaPlaylistSourceControl is provided, the backend must listen for
- current playlist item changes to load corresponding media source and
- advance the playlist with QMediaPlaylist::next() when playback of the
- current media is finished.
-
- The interface name of QMediaPlaylistSourceControl is \c org.qt-project.qt.mediaplaylistsourcecontrol/5.0 as
- defined in QMediaPlaylistSourceControl_iid.
-
- \sa QMediaService::requestControl(), QMediaPlayer
-*/
-
-/*!
- \macro QMediaPlaylistSourceControl_iid
-
- \c org.qt-project.qt.mediaplaylistsourcecontrol/5.0
-
- Defines the interface name of the QMediaPlaylistSourceControl class.
-
- \relates QMediaPlaylistSourceControl
-*/
-
-/*!
- Create a new playlist source control object with the given \a parent.
-*/
-QMediaPlaylistSourceControl::QMediaPlaylistSourceControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destroys the playlist control.
-*/
-QMediaPlaylistSourceControl::~QMediaPlaylistSourceControl()
-{
-}
-
-
-/*!
- \fn QMediaPlaylistSourceControl::playlist() const
-
- Returns the current playlist.
- Should return a null pointer if no playlist is assigned.
-*/
-
-/*!
- \fn QMediaPlaylistSourceControl::setPlaylist(QMediaPlaylist *playlist)
-
- Set the playlist of this media player to \a playlist.
- If a null pointer is passed, the playlist source should be disabled.
-
- The current media should be replaced with the current item of the media playlist.
-*/
-
-
-/*!
- \fn QMediaPlaylistSourceControl::playlistChanged(QMediaPlaylist* playlist)
-
- Signal emitted when the playlist has changed to \a playlist.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaplaylistsourcecontrol_p.cpp"
diff --git a/src/multimedia/controls/qmediaplaylistsourcecontrol_p.h b/src/multimedia/controls/qmediaplaylistsourcecontrol_p.h
deleted file mode 100644
index a98ee8738..000000000
--- a/src/multimedia/controls/qmediaplaylistsourcecontrol_p.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QMEDIAPLAYLISTSOURCECONTROL_P_H
-#define QMEDIAPLAYLISTSOURCECONTROL_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <qmediacontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaPlaylist;
-
-class Q_MULTIMEDIA_EXPORT QMediaPlaylistSourceControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QMediaPlaylistSourceControl();
-
- virtual QMediaPlaylist *playlist() const = 0;
- virtual void setPlaylist(QMediaPlaylist *) = 0;
-
-Q_SIGNALS:
- void playlistChanged(QMediaPlaylist* playlist);
-
-protected:
- QMediaPlaylistSourceControl(QObject *parent = nullptr);
-};
-
-#define QMediaPlaylistSourceControl_iid "org.qt-project.qt.mediaplaylistsourcecontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMediaPlaylistSourceControl, QMediaPlaylistSourceControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIAPLAYLISTCONTROL_P_H
diff --git a/src/multimedia/controls/qmediarecordercontrol.cpp b/src/multimedia/controls/qmediarecordercontrol.cpp
deleted file mode 100644
index 87ace7017..000000000
--- a/src/multimedia/controls/qmediarecordercontrol.cpp
+++ /dev/null
@@ -1,223 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediarecordercontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-
-/*!
- \class QMediaRecorderControl
- \obsolete
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- \brief The QMediaRecorderControl class provides access to the recording
- functionality of a QMediaService.
-
- Generally you will use the QMediaRecorder class in application code - this
- class is mostly used when implementing a new QMediaService or if there is
- access to specific low level functionality not otherwise present in QMediaRecorder.
-
- If a QMediaService can record media it will implement QMediaRecorderControl.
- This control provides a means to set the \l {outputLocation()}{output location},
- and record, pause and stop recording via the \l setState() method. It also
- provides feedback on the \l {duration()}{duration} of the recording.
-
- The interface name of QMediaRecorderControl is \c org.qt-project.qt.mediarecordercontrol/5.0 as
- defined in QMediaRecorderControl_iid.
-
- \sa QMediaService::requestControl(), QMediaRecorder
-
-*/
-
-/*!
- \macro QMediaRecorderControl_iid
-
- \c org.qt-project.qt.mediarecordercontrol/5.0
-
- Defines the interface name of the QMediaRecorderControl class.
-
- \relates QMediaRecorderControl
-*/
-
-/*!
- Constructs a media recorder control with the given \a parent.
-*/
-
-QMediaRecorderControl::QMediaRecorderControl(QObject* parent)
- : QMediaControl(parent)
-{
-}
-
-/*!
- Destroys a media recorder control.
-*/
-
-QMediaRecorderControl::~QMediaRecorderControl()
-{
-}
-
-/*!
- \fn QUrl QMediaRecorderControl::outputLocation() const
-
- Returns the current output location being used.
-*/
-
-/*!
- \fn bool QMediaRecorderControl::setOutputLocation(const QUrl &location)
-
- Sets the output \a location and returns if this operation is successful.
- If file at the output location already exists, it should be overwritten.
-
- The \a location can be relative or empty;
- in this case the service should use the system specific place and file naming scheme.
-
- After recording has started, the backend should report the actual file location
- with actualLocationChanged() signal.
-*/
-
-/*!
- \fn QMediaRecorder::State QMediaRecorderControl::state() const
-
- Return the current recording state.
-*/
-
-/*!
- \fn QMediaRecorder::Status QMediaRecorderControl::status() const
-
- Return the current recording status.
-*/
-
-/*!
- \fn qint64 QMediaRecorderControl::duration() const
-
- Return the current duration in milliseconds.
-*/
-
-/*!
- \fn void QMediaRecorderControl::setState(QMediaRecorder::State state)
-
- Set the media recorder \a state.
-*/
-
-/*!
- \fn void QMediaRecorderControl::applySettings()
-
- Commits the encoder settings and performs pre-initialization to reduce delays when recording
- is started.
-*/
-
-/*!
- \fn bool QMediaRecorderControl::isMuted() const
-
- Returns true if the recorder is muted, and false if it is not.
-*/
-
-/*!
- \fn void QMediaRecorderControl::setMuted(bool muted)
-
- Sets the \a muted state of a media recorder.
-*/
-
-/*!
- \fn qreal QMediaRecorderControl::volume() const
-
- Returns the audio volume of a media recorder control.
-*/
-
-/*!
- \fn void QMediaRecorderControl::setVolume(qreal volume)
-
- Sets the audio \a volume of a media recorder control.
-
- The volume is scaled linearly, ranging from \c 0 (silence) to \c 100 (full volume).
-*/
-
-/*!
- \fn void QMediaRecorderControl::stateChanged(QMediaRecorder::State state)
-
- Signals that the \a state of a media recorder has changed.
-*/
-
-/*!
- \fn void QMediaRecorderControl::statusChanged(QMediaRecorder::Status status)
-
- Signals that the \a status of a media recorder has changed.
-*/
-
-
-/*!
- \fn void QMediaRecorderControl::durationChanged(qint64 duration)
-
- Signals that the \a duration of the recorded media has changed.
-
- This only emitted when there is a discontinuous change in the duration such as being reset to 0.
-*/
-
-/*!
- \fn void QMediaRecorderControl::mutedChanged(bool muted)
-
- Signals that the \a muted state of a media recorder has changed.
-*/
-
-/*!
- \fn void QMediaRecorderControl::volumeChanged(qreal gain)
-
- Signals that the audio \a gain value has changed.
-*/
-
-/*!
- \fn void QMediaRecorderControl::actualLocationChanged(const QUrl &location)
-
- Signals that the actual media \a location has changed.
- This signal should be emitted at start of recording.
-*/
-
-/*!
- \fn void QMediaRecorderControl::error(int error, const QString &errorString)
-
- Signals that an \a error has occurred. The \a errorString describes the error.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediarecordercontrol.cpp"
diff --git a/src/multimedia/controls/qmediarecordercontrol.h b/src/multimedia/controls/qmediarecordercontrol.h
deleted file mode 100644
index a0529ce59..000000000
--- a/src/multimedia/controls/qmediarecordercontrol.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIARECORDERCONTROL_H
-#define QMEDIARECORDERCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediarecorder.h>
-
-QT_BEGIN_NAMESPACE
-
-class QUrl;
-QT_END_NAMESPACE
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QMediaRecorderControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QMediaRecorderControl();
-
- virtual QUrl outputLocation() const = 0;
- virtual bool setOutputLocation(const QUrl &location) = 0;
-
- virtual QMediaRecorder::State state() const = 0;
- virtual QMediaRecorder::Status status() const = 0;
-
- virtual qint64 duration() const = 0;
-
- virtual bool isMuted() const = 0;
- virtual qreal volume() const = 0;
-
- virtual void applySettings() = 0;
-
-Q_SIGNALS:
- void stateChanged(QMediaRecorder::State state);
- void statusChanged(QMediaRecorder::Status status);
- void durationChanged(qint64 position);
- void mutedChanged(bool muted);
- void volumeChanged(qreal volume);
- void actualLocationChanged(const QUrl &location);
- void error(int error, const QString &errorString);
-
-public Q_SLOTS:
- virtual void setState(QMediaRecorder::State state) = 0;
- virtual void setMuted(bool muted) = 0;
- virtual void setVolume(qreal volume) = 0;
-
-protected:
- explicit QMediaRecorderControl(QObject *parent = nullptr);
-};
-
-#define QMediaRecorderControl_iid "org.qt-project.qt.mediarecordercontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMediaRecorderControl, QMediaRecorderControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/multimedia/controls/qmediastreamscontrol.cpp b/src/multimedia/controls/qmediastreamscontrol.cpp
deleted file mode 100644
index 2db9eb6fc..000000000
--- a/src/multimedia/controls/qmediastreamscontrol.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediastreamscontrol.h"
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-static void qRegisterMediaStreamControlMetaTypes()
-{
- qRegisterMetaType<QMediaStreamsControl::StreamType>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterMediaStreamControlMetaTypes)
-
-
-/*!
- \class QMediaStreamsControl
- \obsolete
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- \brief The QMediaStreamsControl class provides a media stream selection control.
-
-
- The QMediaStreamsControl class provides descriptions of the available media streams
- and allows individual streams to be activated and deactivated.
-
- The interface name of QMediaStreamsControl is \c org.qt-project.qt.mediastreamscontrol/5.0 as
- defined in QMediaStreamsControl_iid.
-
- \sa QMediaService::requestControl()
-*/
-
-/*!
- \macro QMediaStreamsControl_iid
-
- \c org.qt-project.qt.mediastreamscontrol/5.0
-
- Defines the interface name of the QMediaStreamsControl class.
-
- \relates QMediaStreamsControl
-*/
-
-/*!
- Constructs a new media streams control with the given \a parent.
-*/
-QMediaStreamsControl::QMediaStreamsControl(QObject *parent)
- :QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destroys a media streams control.
-*/
-QMediaStreamsControl::~QMediaStreamsControl()
-{
-}
-
-/*!
- \enum QMediaStreamsControl::StreamType
-
- Media stream type.
-
- \value AudioStream Audio stream.
- \value VideoStream Video stream.
- \value SubPictureStream Subpicture or teletext stream.
- \value UnknownStream The stream type is unknown.
- \value DataStream
-*/
-
-/*!
- \fn QMediaStreamsControl::streamCount()
-
- Returns the number of media streams.
-*/
-
-/*!
- \fn QMediaStreamsControl::streamType(int streamNumber)
-
- Return the type of media stream \a streamNumber.
-*/
-
-/*!
- \fn QMediaStreamsControl::metaData(int streamNumber, const QString &key)
-
- Returns the meta-data value of \a key for the given \a streamNumber.
-
- Useful metadata keys are QMediaMetaData::Title,
- QMediaMetaData::Description and QMediaMetaData::Language.
-*/
-
-/*!
- \fn QMediaStreamsControl::isActive(int streamNumber)
-
- Returns true if the media stream \a streamNumber is active.
-*/
-
-/*!
- \fn QMediaStreamsControl::setActive(int streamNumber, bool state)
-
- Sets the active \a state of media stream \a streamNumber.
-
- Setting the active state of a media stream to true will activate it. If any other stream
- of the same type was previously active it will be deactivated. Setting the active state fo a
- media stream to false will deactivate it.
-*/
-
-/*!
- \fn QMediaStreamsControl::streamsChanged()
-
- The signal is emitted when the available streams list is changed.
-*/
-
-/*!
- \fn QMediaStreamsControl::activeStreamsChanged()
-
- The signal is emitted when the active streams list is changed.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediastreamscontrol.cpp"
diff --git a/src/multimedia/controls/qmediastreamscontrol.h b/src/multimedia/controls/qmediastreamscontrol.h
deleted file mode 100644
index e2506882d..000000000
--- a/src/multimedia/controls/qmediastreamscontrol.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QMEDIASTREAMSCONTROL_H
-#define QMEDIASTREAMSCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmultimedia.h>
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmediaenumdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QMediaStreamsControl : public QMediaControl
-{
- Q_OBJECT
- Q_ENUMS(SteamType)
-public:
- enum StreamType { UnknownStream, VideoStream, AudioStream, SubPictureStream, DataStream };
-
- virtual ~QMediaStreamsControl();
-
- virtual int streamCount() = 0;
- virtual StreamType streamType(int streamNumber) = 0;
-
- virtual QVariant metaData(int streamNumber, const QString &key) = 0;
-
- virtual bool isActive(int streamNumber) = 0;
- virtual void setActive(int streamNumber, bool state) = 0;
-
-Q_SIGNALS:
- void streamsChanged();
- void activeStreamsChanged();
-
-protected:
- explicit QMediaStreamsControl(QObject *parent = nullptr);
-};
-
-#define QMediaStreamsControl_iid "org.qt-project.qt.mediastreamscontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMediaStreamsControl, QMediaStreamsControl_iid)
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QMediaStreamsControl::StreamType)
-
-Q_MEDIA_ENUM_DEBUG(QMediaStreamsControl, StreamType)
-
-#endif // QMEDIASTREAMSCONTROL_H
-
diff --git a/src/multimedia/controls/qmediavideoprobecontrol.cpp b/src/multimedia/controls/qmediavideoprobecontrol.cpp
deleted file mode 100644
index 4a85d56d0..000000000
--- a/src/multimedia/controls/qmediavideoprobecontrol.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediavideoprobecontrol.h"
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QMediaVideoProbeControl
- \obsolete
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- \brief The QMediaVideoProbeControl class allows control over probing video frames in media objects.
-
- \l QVideoProbe is the client facing class for probing video - this class is implemented by
- media backends to provide this functionality.
-
- The interface name of QMediaVideoProbeControl is \c org.qt-project.qt.mediavideoprobecontrol/5.0 as
- defined in QMediaVideoProbeControl_iid.
-
- \sa QVideoProbe, QMediaService::requestControl(), QMediaPlayer, QCamera
-*/
-
-/*!
- \macro QMediaVideoProbeControl_iid
-
- \c org.qt-project.qt.mediavideoprobecontrol/5.0
-
- Defines the interface name of the QMediaVideoProbeControl class.
-
- \relates QMediaVideoProbeControl
-*/
-
-/*!
- Create a new media video probe control object with the given \a parent.
-*/
-QMediaVideoProbeControl::QMediaVideoProbeControl(QObject *parent)
- : QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*! Destroys this video probe control */
-QMediaVideoProbeControl::~QMediaVideoProbeControl()
-{
-}
-
-/*!
- \fn QMediaVideoProbeControl::videoFrameProbed(const QVideoFrame &frame)
-
- This signal should be emitted when a video \a frame is processed in the
- media service.
-*/
-
-/*!
- \fn QMediaVideoProbeControl::flush()
-
- This signal should be emitted when it is required to release all frames.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediavideoprobecontrol.cpp"
diff --git a/src/multimedia/controls/qmediavideoprobecontrol.h b/src/multimedia/controls/qmediavideoprobecontrol.h
deleted file mode 100644
index 363975055..000000000
--- a/src/multimedia/controls/qmediavideoprobecontrol.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-
-#ifndef QMEDIAVIDEOPROBECONTROL_H
-#define QMEDIAVIDEOPROBECONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QVideoFrame;
-class Q_MULTIMEDIA_EXPORT QMediaVideoProbeControl : public QMediaControl
-{
- Q_OBJECT
-public:
- virtual ~QMediaVideoProbeControl();
-
-Q_SIGNALS:
- void videoFrameProbed(const QVideoFrame &frame);
- void flush();
-
-protected:
- explicit QMediaVideoProbeControl(QObject *parent = nullptr);
-};
-
-#define QMediaVideoProbeControl_iid "org.qt-project.qt.mediavideoprobecontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMediaVideoProbeControl, QMediaVideoProbeControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIAVIDEOPROBECONTROL_H
diff --git a/src/multimedia/controls/qmetadatareadercontrol.cpp b/src/multimedia/controls/qmetadatareadercontrol.cpp
deleted file mode 100644
index f01ffec38..000000000
--- a/src/multimedia/controls/qmetadatareadercontrol.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediacontrol_p.h"
-#include <qmetadatareadercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-
-/*!
- \class QMetaDataReaderControl
- \obsolete
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
-
- \brief The QMetaDataReaderControl class provides read access to the
- meta-data of a QMediaService's media.
-
- If a QMediaService can provide read or write access to the meta-data of
- its current media it will implement QMetaDataReaderControl. This control
- provides functions for both retrieving and setting meta-data values.
- Meta-data may be addressed by the keys defined in the
- QMediaMetaData namespace.
-
- The functionality provided by this control is exposed to application
- code by the meta-data members of QMediaObject, and so meta-data access
- is potentially available in any of the media object classes. Any media
- service may implement QMetaDataReaderControl.
-
- The interface name of QMetaDataReaderControl is
- \c org.qt-project.qt.metadatareadercontrol/5.0 as defined in
- QMetaDataReaderControl_iid.
-
- \sa QMediaService::requestControl(), QMediaObject
-*/
-
-/*!
- \macro QMetaDataReaderControl_iid
-
- \c org.qt-project.qt.metadatareadercontrol/5.0
-
- Defines the interface name of the QMetaDataReaderControl class.
-
- \relates QMetaDataReaderControl
-*/
-
-/*!
- Construct a QMetaDataReaderControl with \a parent. This class is meant as a base class
- for service specific meta data providers so this constructor is protected.
-*/
-
-QMetaDataReaderControl::QMetaDataReaderControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destroy the meta-data object.
-*/
-
-QMetaDataReaderControl::~QMetaDataReaderControl()
-{
-}
-
-/*!
- \fn bool QMetaDataReaderControl::isMetaDataAvailable() const
-
- Identifies if meta-data is available from a media service.
-
- Returns true if the meta-data is available and false otherwise.
-*/
-
-/*!
- \fn QVariant QMetaDataReaderControl::metaData(const QString &key) const
-
- Returns the meta-data for the given \a key.
-*/
-
-/*!
- \fn QMetaDataReaderControl::availableMetaData() const
-
- Returns a list of keys there is meta-data available for.
-*/
-
-/*!
- \fn void QMetaDataReaderControl::metaDataChanged()
-
- Signal the changes of meta-data.
-
- If multiple meta-data elements are changed,
- metaDataChanged(const QString &key, const QVariant &value) signal is emitted
- for each of them with metaDataChanged() changed emitted once.
-*/
-
-/*!
- \fn void QMetaDataReaderControl::metaDataChanged(const QString &key, const QVariant &value)
-
- Signal the changes of one meta-data element \a value with the given \a key.
-*/
-
-/*!
- \fn void QMetaDataReaderControl::metaDataAvailableChanged(bool available)
-
- Signal the availability of meta-data has changed, \a available will
- be true if the multimedia object has meta-data.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmetadatareadercontrol.cpp"
diff --git a/src/multimedia/controls/qmetadatareadercontrol.h b/src/multimedia/controls/qmetadatareadercontrol.h
deleted file mode 100644
index b13c7ea00..000000000
--- a/src/multimedia/controls/qmetadatareadercontrol.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMETADATAREADERCONTROL_H
-#define QMETADATAREADERCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QMetaDataReaderControl : public QMediaControl
-{
- Q_OBJECT
-public:
- ~QMetaDataReaderControl();
-
- virtual bool isMetaDataAvailable() const = 0;
-
- virtual QVariant metaData(const QString &key) const = 0;
- virtual QStringList availableMetaData() const = 0;
-
-Q_SIGNALS:
- void metaDataChanged();
- void metaDataChanged(const QString &key, const QVariant &value);
-
- void metaDataAvailableChanged(bool available);
-
-protected:
- explicit QMetaDataReaderControl(QObject *parent = nullptr);
-};
-
-#define QMetaDataReaderControl_iid "org.qt-project.qt.metadatareadercontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMetaDataReaderControl, QMetaDataReaderControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QMETADATAPROVIDER_H
diff --git a/src/multimedia/controls/qmetadatawritercontrol.cpp b/src/multimedia/controls/qmetadatawritercontrol.cpp
deleted file mode 100644
index 6221edaa1..000000000
--- a/src/multimedia/controls/qmetadatawritercontrol.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediacontrol_p.h"
-#include <qmetadatawritercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-
-/*!
- \class QMetaDataWriterControl
- \obsolete
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
-
- \brief The QMetaDataWriterControl class provides write access to the
- meta-data of a QMediaService's media.
-
- If a QMediaService can provide write access to the meta-data of its
- current media it will implement QMetaDataWriterControl. This control
- provides functions for both retrieving and setting meta-data values.
- Meta-data may be addressed by the keys defined in the
- QMediaMetaData namespace.
-
- The functionality provided by this control is exposed to application code
- by the meta-data members of QMediaObject, and so meta-data access is
- potentially available in any of the media object classes. Any media
- service may implement QMetaDataControl.
-
- The interface name of QMetaDataWriterControl is \c org.qt-project.qt.metadatawritercontrol/5.0 as
- defined in QMetaDataWriterControl_iid.
-
- \sa QMediaService::requestControl(), QMediaObject
-*/
-
-/*!
- \macro QMetaDataWriterControl_iid
-
- \c org.qt-project.qt.metadatawritercontrol/5.0
-
- Defines the interface name of the QMetaDataWriterControl class.
-
- \relates QMetaDataWriterControl
-*/
-
-/*!
- Construct a QMetaDataWriterControl with \a parent. This class is meant as a base class
- for service specific meta data providers so this constructor is protected.
-*/
-
-QMetaDataWriterControl::QMetaDataWriterControl(QObject *parent):
- QMediaControl(*new QMediaControlPrivate, parent)
-{
-}
-
-/*!
- Destroy the meta-data writer control.
-*/
-
-QMetaDataWriterControl::~QMetaDataWriterControl()
-{
-}
-
-/*!
- \fn bool QMetaDataWriterControl::isMetaDataAvailable() const
-
- Identifies if meta-data is available from a media service.
-
- Returns true if the meta-data is available and false otherwise.
-*/
-
-/*!
- \fn bool QMetaDataWriterControl::isWritable() const
-
- Identifies if a media service's meta-data can be edited.
-
- Returns true if the meta-data is writable and false otherwise.
-*/
-
-/*!
- \fn QVariant QMetaDataWriterControl::metaData(const QString &key) const
-
- Returns the meta-data for the given \a key.
-*/
-
-/*!
- \fn void QMetaDataWriterControl::setMetaData(const QString &key, const QVariant &value)
-
- Sets the \a value of the meta-data element with the given \a key.
-*/
-
-/*!
- \fn QMetaDataWriterControl::availableMetaData() const
-
- Returns a list of keys there is meta-data available for.
-*/
-
-/*!
- \fn void QMetaDataWriterControl::metaDataChanged()
-
- Signal the changes of meta-data.
-
- If multiple meta-data elements are changed,
- metaDataChanged(const QString &key, const QVariant &value) signal is emitted
- for each of them with metaDataChanged() changed emitted once.
-*/
-
-/*!
- \fn void QMetaDataWriterControl::metaDataChanged(const QString &key, const QVariant &value)
-
- Signal the changes of one meta-data element \a value with the given \a key.
-*/
-
-/*!
- \fn void QMetaDataWriterControl::metaDataAvailableChanged(bool available)
-
- Signal the availability of meta-data has changed, \a available will
- be true if the multimedia object has meta-data.
-*/
-
-/*!
- \fn void QMetaDataWriterControl::writableChanged(bool writable)
-
- Signal a change in the writable status of meta-data, \a writable will be
- true if meta-data elements can be added or adjusted.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmetadatawritercontrol.cpp"
diff --git a/src/multimedia/controls/qmetadatawritercontrol.h b/src/multimedia/controls/qmetadatawritercontrol.h
deleted file mode 100644
index a1d4449c3..000000000
--- a/src/multimedia/controls/qmetadatawritercontrol.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMETADATAWRITERCONTROL_H
-#define QMETADATAWRITERCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QMetaDataWriterControl : public QMediaControl
-{
- Q_OBJECT
-public:
- ~QMetaDataWriterControl();
-
- virtual bool isWritable() const = 0;
- virtual bool isMetaDataAvailable() const = 0;
-
- virtual QVariant metaData(const QString &key) const = 0;
- virtual void setMetaData(const QString &key, const QVariant &value) = 0;
- virtual QStringList availableMetaData() const = 0;
-
-Q_SIGNALS:
- void metaDataChanged();
- void metaDataChanged(const QString &key, const QVariant &value);
-
- void writableChanged(bool writable);
- void metaDataAvailableChanged(bool available);
-
-protected:
- explicit QMetaDataWriterControl(QObject *parent = nullptr);
-};
-
-#define QMetaDataWriterControl_iid "org.qt-project.qt.metadatawritercontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QMetaDataWriterControl, QMetaDataWriterControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/multimedia/controls/qvideodeviceselectorcontrol.cpp b/src/multimedia/controls/qvideodeviceselectorcontrol.cpp
deleted file mode 100644
index 420ba9150..000000000
--- a/src/multimedia/controls/qvideodeviceselectorcontrol.cpp
+++ /dev/null
@@ -1,143 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qvideodeviceselectorcontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QVideoDeviceSelectorControl
- \obsolete
-
- \brief The QVideoDeviceSelectorControl class provides an video device selector media control.
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- The QVideoDeviceSelectorControl class provides descriptions of the video devices
- available on a system and allows one to be selected as the endpoint of a
- media service.
-
- The interface name of QVideoDeviceSelectorControl is \c org.qt-project.qt.videodeviceselectorcontrol/5.0 as
- defined in QVideoDeviceSelectorControl_iid.
-*/
-
-/*!
- \macro QVideoDeviceSelectorControl_iid
-
- \c org.qt-project.qt.videodeviceselectorcontrol/5.0
-
- Defines the interface name of the QVideoDeviceSelectorControl class.
-
- \relates QVideoDeviceSelectorControl
-*/
-
-/*!
- Constructs a video device selector control with the given \a parent.
-*/
-QVideoDeviceSelectorControl::QVideoDeviceSelectorControl(QObject *parent)
- :QMediaControl(parent)
-{
-}
-
-/*!
- Destroys a video device selector control.
-*/
-QVideoDeviceSelectorControl::~QVideoDeviceSelectorControl()
-{
-}
-
-/*!
- \fn QVideoDeviceSelectorControl::deviceCount() const
-
- Returns the number of available video devices;
-*/
-
-/*!
- \fn QVideoDeviceSelectorControl::deviceName(int index) const
-
- Returns the name of the video device at \a index.
-*/
-
-/*!
- \fn QVideoDeviceSelectorControl::deviceDescription(int index) const
-
- Returns a description of the video device at \a index.
-*/
-
-/*!
- \fn QVideoDeviceSelectorControl::defaultDevice() const
-
- Returns the index of the default video device.
-*/
-
-/*!
- \fn QVideoDeviceSelectorControl::selectedDevice() const
-
- Returns the index of the selected video device.
-*/
-
-/*!
- \fn QVideoDeviceSelectorControl::setSelectedDevice(int index)
-
- Sets the selected video device \a index.
-*/
-
-/*!
- \fn QVideoDeviceSelectorControl::devicesChanged()
-
- Signals that the list of available video devices has changed.
-*/
-
-/*!
- \fn QVideoDeviceSelectorControl::selectedDeviceChanged(int index)
-
- Signals that the selected video device \a index has changed.
-*/
-
-/*!
- \fn QVideoDeviceSelectorControl::selectedDeviceChanged(const QString &name)
-
- Signals that the selected video device \a name has changed.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qvideodeviceselectorcontrol.cpp"
diff --git a/src/multimedia/controls/qvideodeviceselectorcontrol.h b/src/multimedia/controls/qvideodeviceselectorcontrol.h
deleted file mode 100644
index 4697196ce..000000000
--- a/src/multimedia/controls/qvideodeviceselectorcontrol.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QVIDEODEVICESELECTORCONTROL_H
-#define QVIDEODEVICESELECTORCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QVideoDeviceSelectorControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QVideoDeviceSelectorControl();
-
- virtual int deviceCount() const = 0;
-
- virtual QString deviceName(int index) const = 0;
- virtual QString deviceDescription(int index) const = 0;
-
- virtual int defaultDevice() const = 0;
- virtual int selectedDevice() const = 0;
-
-public Q_SLOTS:
- virtual void setSelectedDevice(int index) = 0;
-
-Q_SIGNALS:
- void selectedDeviceChanged(int index);
- void selectedDeviceChanged(const QString &name);
- void devicesChanged();
-
-protected:
- explicit QVideoDeviceSelectorControl(QObject *parent = nullptr);
-};
-
-#define QVideoDeviceSelectorControl_iid "org.qt-project.qt.videodeviceselectorcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QVideoDeviceSelectorControl, QVideoDeviceSelectorControl_iid)
-
-QT_END_NAMESPACE
-
-#endif // QVIDEODEVICESELECTORCONTROL_H
diff --git a/src/multimedia/controls/qvideoencodersettingscontrol.cpp b/src/multimedia/controls/qvideoencodersettingscontrol.cpp
deleted file mode 100644
index 64643f6db..000000000
--- a/src/multimedia/controls/qvideoencodersettingscontrol.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qvideoencodersettingscontrol.h"
-#include <QtCore/qstringlist.h>
-#include <QtCore/qvariant.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QVideoEncoderSettingsControl
- \obsolete
-
- \inmodule QtMultimedia
-
-
- \ingroup multimedia_control
-
- \brief The QVideoEncoderSettingsControl class provides access to the settings
- of a media service that performs video encoding.
-
- If a QMediaService supports encoding video data it will implement
- QVideoEncoderSettingsControl. This control provides information about the limits
- of restricted video encoder options and allows the selection of a set of
- video encoder settings as specified in a QVideoEncoderSettings object.
-
- The functionality provided by this control is exposed to application code
- through the QMediaRecorder class.
-
- The interface name of QVideoEncoderSettingsControl is \c org.qt-project.qt.videoencodersettingscontrol/5.0 as
- defined in QVideoEncoderSettingsControl_iid.
-
- \sa QMediaRecorder, QVideoEncoderSettings, QMediaService::requestControl()
-*/
-
-/*!
- \macro QVideoEncoderSettingsControl_iid
-
- \c org.qt-project.qt.videoencodersettingscontrol/5.0
-
- Defines the interface name of the QVideoEncoderSettingsControl class.
-
- \relates QVideoEncoderSettingsControl
-*/
-
-/*!
- Create a new video encoder settings control object with the given \a parent.
-*/
-QVideoEncoderSettingsControl::QVideoEncoderSettingsControl(QObject *parent)
- :QMediaControl(parent)
-{
-}
-
-/*!
- Destroys a video encoder settings control.
-*/
-QVideoEncoderSettingsControl::~QVideoEncoderSettingsControl()
-{
-}
-
-/*!
- \fn QVideoEncoderSettingsControl::supportedVideoCodecs() const
-
- Returns the list of supported video codecs.
-*/
-
-/*!
- \fn QVideoEncoderSettingsControl::videoCodecDescription(const QString &codec) const
-
- Returns a description of a video \a codec.
-*/
-
-/*!
- \fn QVideoEncoderSettingsControl::supportedResolutions(const QVideoEncoderSettings &settings = QVideoEncoderSettings(),
- bool *continuous = 0) const
-
- Returns a list of supported resolutions.
-
- If non null video \a settings parameter is passed,
- the returned list is reduced to resolution supported with partial settings like
- \l {QVideoEncoderSettings::setCodec()}{video codec} or
- \l {QVideoEncoderSettings::setFrameRate()}{frame rate} applied.
-
- If the encoder supports arbitrary resolutions within the supported resolutions range,
- *\a continuous is set to true, otherwise *\a continuous is set to false.
-
- \sa QVideoEncoderSettings::resolution()
-*/
-
-/*!
- \fn QVideoEncoderSettingsControl::supportedFrameRates(const QVideoEncoderSettings &settings = QVideoEncoderSettings(),
- bool *continuous = 0) const
-
- Returns a list of supported frame rates.
-
- If non null video \a settings parameter is passed,
- the returned list is reduced to frame rates supported with partial settings like
- \l {QVideoEncoderSettings::setCodec()}{video codec} or
- \l {QVideoEncoderSettings::setResolution()}{video resolution} applied.
-
- If the encoder supports arbitrary frame rates within the supported range,
- *\a continuous is set to true, otherwise *\a continuous is set to false.
-
- \sa QVideoEncoderSettings::frameRate()
-*/
-
-/*!
- \fn QVideoEncoderSettingsControl::videoSettings() const
-
- Returns the video encoder settings.
-
- The returned value may be different tha passed to QVideoEncoderSettingsControl::setVideoSettings()
- if the settings contains the default or undefined parameters.
- In this case if the undefined parameters are already resolved, they should be returned.
-*/
-
-/*!
- \fn QVideoEncoderSettingsControl::setVideoSettings(const QVideoEncoderSettings &settings)
-
- Sets the selected video encoder \a settings.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qvideoencodersettingscontrol.cpp"
diff --git a/src/multimedia/controls/qvideoencodersettingscontrol.h b/src/multimedia/controls/qvideoencodersettingscontrol.h
deleted file mode 100644
index ac13833d1..000000000
--- a/src/multimedia/controls/qvideoencodersettingscontrol.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QVIDEOENCODERSETTINGSCONTROL_H
-#define QVIDEOENCODERSETTINGSCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediarecorder.h>
-
-#include <QtCore/qpair.h>
-#include <QtCore/qsize.h>
-
-QT_BEGIN_NAMESPACE
-
-class QByteArray;
-QT_END_NAMESPACE
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QVideoEncoderSettingsControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QVideoEncoderSettingsControl();
-
- virtual QList<QSize> supportedResolutions(const QVideoEncoderSettings &settings,
- bool *continuous = nullptr) const = 0;
-
- virtual QList<qreal> supportedFrameRates(const QVideoEncoderSettings &settings,
- bool *continuous = nullptr) const = 0;
-
- virtual QStringList supportedVideoCodecs() const = 0;
- virtual QString videoCodecDescription(const QString &codec) const = 0;
-
- virtual QVideoEncoderSettings videoSettings() const = 0;
- virtual void setVideoSettings(const QVideoEncoderSettings &settings) = 0;
-
-protected:
- explicit QVideoEncoderSettingsControl(QObject *parent = nullptr);
-};
-
-#define QVideoEncoderSettingsControl_iid "org.qt-project.qt.videoencodersettingscontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QVideoEncoderSettingsControl, QVideoEncoderSettingsControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/multimedia/controls/qvideorenderercontrol.cpp b/src/multimedia/controls/qvideorenderercontrol.cpp
deleted file mode 100644
index eee20d59e..000000000
--- a/src/multimedia/controls/qvideorenderercontrol.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qvideorenderercontrol.h"
-
-#include "qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QVideoRendererControl
- \obsolete
-
- \inmodule QtMultimedia
- \brief The QVideoRendererControl class provides a media control for rendering video to a QAbstractVideoSurface.
-
-
- \ingroup multimedia_control
-
- Using the surface() property of QVideoRendererControl a
- QAbstractVideoSurface may be set as the video render target of a
- QMediaService.
-
- \snippet multimedia-snippets/video.cpp Video renderer control
-
- QVideoRendererControl is one of a number of possible video output controls.
-
- The interface name of QVideoRendererControl is \c org.qt-project.qt.videorenderercontrol/5.0 as
- defined in QVideoRendererControl_iid.
-
- \sa QMediaService::requestControl(), QVideoWidget
-*/
-
-/*!
- \macro QVideoRendererControl_iid
-
- \c org.qt-project.qt.videorenderercontrol/5.0
-
- Defines the interface name of the QVideoRendererControl class.
-
- \relates QVideoRendererControl
-*/
-
-/*!
- Constructs a new video renderer media end point with the given \a parent.
-*/
-QVideoRendererControl::QVideoRendererControl(QObject *parent)
- : QMediaControl(parent)
-{
-}
-
-/*!
- Destroys a video renderer media end point.
-*/
-QVideoRendererControl::~QVideoRendererControl()
-{
-}
-
-/*!
- \fn QVideoRendererControl::surface() const
-
- Returns the surface a video producer renders to.
-*/
-
-/*!
- \fn QVideoRendererControl::setSurface(QAbstractVideoSurface *surface)
-
- Sets the \a surface a video producer renders to.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qvideorenderercontrol.cpp"
diff --git a/src/multimedia/controls/qvideorenderercontrol.h b/src/multimedia/controls/qvideorenderercontrol.h
deleted file mode 100644
index 87552271a..000000000
--- a/src/multimedia/controls/qvideorenderercontrol.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QVIDEORENDERERCONTROL_H
-#define QVIDEORENDERERCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAbstractVideoSurface;
-class Q_MULTIMEDIA_EXPORT QVideoRendererControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- ~QVideoRendererControl();
-
- virtual QAbstractVideoSurface *surface() const = 0;
- virtual void setSurface(QAbstractVideoSurface *surface) = 0;
-
-protected:
- explicit QVideoRendererControl(QObject *parent = nullptr);
-};
-
-#define QVideoRendererControl_iid "org.qt-project.qt.videorenderercontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QVideoRendererControl, QVideoRendererControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QVIDEORENDERERCONTROL_H
diff --git a/src/multimedia/controls/qvideowindowcontrol.cpp b/src/multimedia/controls/qvideowindowcontrol.cpp
deleted file mode 100644
index a6b2bf407..000000000
--- a/src/multimedia/controls/qvideowindowcontrol.cpp
+++ /dev/null
@@ -1,259 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qvideowindowcontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QVideoWindowControl
- \obsolete
-
- \inmodule QtMultimedia
-
- \ingroup multimedia_control
- \brief The QVideoWindowControl class provides a media control for rendering video to a window.
-
-
- The winId() property QVideoWindowControl allows a platform specific window
- ID to be set as the video render target of a QMediaService. The
- displayRect() property is used to set the region of the window the video
- should be rendered to, and the aspectRatioMode() property indicates how the
- video should be scaled to fit the displayRect().
-
- \snippet multimedia-snippets/video.cpp Video window control
-
- QVideoWindowControl is one of a number of possible video output controls.
-
- The interface name of QVideoWindowControl is \c org.qt-project.qt.videowindowcontrol/5.0 as
- defined in QVideoWindowControl_iid.
-
- \sa QMediaService::requestControl(), QVideoWidget
-*/
-
-/*!
- \macro QVideoWindowControl_iid
-
- \c org.qt-project.qt.videowindowcontrol/5.0
-
- Defines the interface name of the QVideoWindowControl class.
-
- \relates QVideoWindowControl
-*/
-
-/*!
- Constructs a new video window control with the given \a parent.
-*/
-QVideoWindowControl::QVideoWindowControl(QObject *parent)
- : QMediaControl(parent)
-{
-}
-
-/*!
- Destroys a video window control.
-*/
-QVideoWindowControl::~QVideoWindowControl()
-{
-}
-
-/*!
- \fn QVideoWindowControl::winId() const
-
- Returns the ID of the window a video overlay end point renders to.
-*/
-
-/*!
- \fn QVideoWindowControl::setWinId(WId id)
-
- Sets the \a id of the window a video overlay end point renders to.
-*/
-
-/*!
- \fn QVideoWindowControl::displayRect() const
- Returns the sub-rect of a window where video is displayed.
-*/
-
-/*!
- \fn QVideoWindowControl::setDisplayRect(const QRect &rect)
- Sets the sub-\a rect of a window where video is displayed.
-*/
-
-/*!
- \fn QVideoWindowControl::isFullScreen() const
-
- Identifies if a video overlay is a fullScreen overlay.
-
- Returns true if the video overlay is fullScreen, and false otherwise.
-*/
-
-/*!
- \fn QVideoWindowControl::setFullScreen(bool fullScreen)
-
- Sets whether a video overlay is a \a fullScreen overlay.
-*/
-
-/*!
- \fn QVideoWindowControl::fullScreenChanged(bool fullScreen)
-
- Signals that the \a fullScreen state of a video overlay has changed.
-*/
-
-/*!
- \fn QVideoWindowControl::repaint()
-
- Repaints the last frame.
-*/
-
-/*!
- \fn QVideoWindowControl::nativeSize() const
-
- Returns a suggested size for the video display based on the resolution and aspect ratio of the
- video.
-*/
-
-/*!
- \fn QVideoWindowControl::nativeSizeChanged()
-
- Signals that the native dimensions of the video have changed.
-*/
-
-
-/*!
- \fn QVideoWindowControl::aspectRatioMode() const
-
- Returns how video is scaled to fit the display region with respect to its aspect ratio.
-*/
-
-/*!
- \fn QVideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
-
- Sets the aspect ratio \a mode which determines how video is scaled to the fit the display region
- with respect to its aspect ratio.
-*/
-
-/*!
- \fn QVideoWindowControl::brightness() const
-
- Returns the brightness adjustment applied to a video overlay.
-
- Valid brightness values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWindowControl::setBrightness(int brightness)
-
- Sets a \a brightness adjustment for a video overlay.
-
- Valid brightness values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWindowControl::brightnessChanged(int brightness)
-
- Signals that a video overlay's \a brightness adjustment has changed.
-*/
-
-/*!
- \fn QVideoWindowControl::contrast() const
-
- Returns the contrast adjustment applied to a video overlay.
-
- Valid contrast values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWindowControl::setContrast(int contrast)
-
- Sets the \a contrast adjustment for a video overlay.
-
- Valid contrast values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWindowControl::contrastChanged(int contrast)
-
- Signals that a video overlay's \a contrast adjustment has changed.
-*/
-
-/*!
- \fn QVideoWindowControl::hue() const
-
- Returns the hue adjustment applied to a video overlay.
-
- Value hue values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWindowControl::setHue(int hue)
-
- Sets a \a hue adjustment for a video overlay.
-
- Valid hue values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWindowControl::hueChanged(int hue)
-
- Signals that a video overlay's \a hue adjustment has changed.
-*/
-
-/*!
- \fn QVideoWindowControl::saturation() const
-
- Returns the saturation adjustment applied to a video overlay.
-
- Value saturation values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWindowControl::setSaturation(int saturation)
- Sets a \a saturation adjustment for a video overlay.
-
- Valid saturation values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWindowControl::saturationChanged(int saturation)
-
- Signals that a video overlay's \a saturation adjustment has changed.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qvideowindowcontrol.cpp"
diff --git a/src/multimedia/controls/qvideowindowcontrol.h b/src/multimedia/controls/qvideowindowcontrol.h
deleted file mode 100644
index 510a29989..000000000
--- a/src/multimedia/controls/qvideowindowcontrol.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QVIDEOWINDOWCONTROL_H
-#define QVIDEOWINDOWCONTROL_H
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtCore/qrect.h>
-#include <QtCore/qsize.h>
-#include <QtGui/qwindowdefs.h>
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QVideoWindowControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- ~QVideoWindowControl();
-
- virtual WId winId() const = 0;
- virtual void setWinId(WId id) = 0;
-
- virtual QRect displayRect() const = 0;
- virtual void setDisplayRect(const QRect &rect) = 0;
-
- virtual bool isFullScreen() const = 0;
- virtual void setFullScreen(bool fullScreen) = 0;
-
- virtual void repaint() = 0;
-
- virtual QSize nativeSize() const = 0;
-
- virtual Qt::AspectRatioMode aspectRatioMode() const = 0;
- virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0;
-
- virtual int brightness() const = 0;
- virtual void setBrightness(int brightness) = 0;
-
- virtual int contrast() const = 0;
- virtual void setContrast(int contrast) = 0;
-
- virtual int hue() const = 0;
- virtual void setHue(int hue) = 0;
-
- virtual int saturation() const = 0;
- virtual void setSaturation(int saturation) = 0;
-
-Q_SIGNALS:
- void fullScreenChanged(bool fullScreen);
- void brightnessChanged(int brightness);
- void contrastChanged(int contrast);
- void hueChanged(int hue);
- void saturationChanged(int saturation);
- void nativeSizeChanged();
-
-protected:
- explicit QVideoWindowControl(QObject *parent = nullptr);
-};
-
-#define QVideoWindowControl_iid "org.qt-project.qt.videowindowcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QVideoWindowControl, QVideoWindowControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/multimedia/darwin/qcoreaudiosessionmanager.mm b/src/multimedia/darwin/qcoreaudiosessionmanager.mm
new file mode 100644
index 000000000..cee955905
--- /dev/null
+++ b/src/multimedia/darwin/qcoreaudiosessionmanager.mm
@@ -0,0 +1,437 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qcoreaudiosessionmanager_p.h"
+#import <AVFoundation/AVAudioSession.h>
+#import <Foundation/Foundation.h>
+
+QT_BEGIN_NAMESPACE
+
+@interface CoreAudioSessionObserver : NSObject
+{
+ CoreAudioSessionManager *m_sessionManager;
+ AVAudioSession *m_audioSession;
+}
+
+@property (readonly, getter=sessionManager) CoreAudioSessionManager *m_sessionManager;
+@property (readonly, getter=audioSession) AVAudioSession *m_audioSession;
+
+-(CoreAudioSessionObserver *)initWithAudioSessionManager:(CoreAudioSessionManager *)sessionManager;
+
+-(BOOL)activateAudio;
+-(BOOL)deactivateAudio;
+
+//Notification handlers
+-(void)audioSessionInterruption:(NSNotification *)notification;
+-(void)audioSessionRouteChange:(NSNotification *)notification;
+-(void)audioSessionMediaServicesWereReset:(NSNotification *)notification;
+
+@end //interface CoreAudioSessionObserver
+
+@implementation CoreAudioSessionObserver
+
+@synthesize m_sessionManager, m_audioSession;
+
+-(CoreAudioSessionObserver *)initWithAudioSessionManager:(CoreAudioSessionManager *)sessionManager
+{
+ if (!(self = [super init]))
+ return nil;
+
+ self->m_sessionManager = sessionManager;
+ self->m_audioSession = [AVAudioSession sharedInstance];
+
+ //Set up observers
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(audioSessionInterruption:)
+ name:AVAudioSessionInterruptionNotification
+ object:self->m_audioSession];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(audioSessionMediaServicesWereReset:)
+ name:AVAudioSessionMediaServicesWereResetNotification
+ object:self->m_audioSession];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(audioSessionRouteChange:)
+ name:AVAudioSessionRouteChangeNotification
+ object:self->m_audioSession];
+
+ return self;
+}
+
+-(void)dealloc
+{
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug() << Q_FUNC_INFO;
+#endif
+
+ [[NSNotificationCenter defaultCenter] removeObserver:self
+ name:AVAudioSessionInterruptionNotification
+ object:self->m_audioSession];
+ [[NSNotificationCenter defaultCenter] removeObserver:self
+ name:AVAudioSessionMediaServicesWereResetNotification
+ object:self->m_audioSession];
+ [[NSNotificationCenter defaultCenter] removeObserver:self
+ name:AVAudioSessionRouteChangeNotification
+ object:self->m_audioSession];
+
+ [super dealloc];
+}
+
+-(BOOL)activateAudio
+{
+ NSError *error = nil;
+ BOOL success = [self->m_audioSession setActive:YES error:&error];
+ if (![self->m_audioSession setActive:YES error:&error]) {
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audio session activation failed: %s", [[error localizedDescription] UTF8String]);
+ } else {
+ qDebug("audio session activated");
+#endif
+ }
+
+ return success;
+}
+
+-(BOOL)deactivateAudio
+{
+ NSError *error = nil;
+ BOOL success = [m_audioSession setActive:NO error:&error];
+#ifdef QT_DEBUG_COREAUDIO
+ if (!success) {
+ qDebug("%s", [[error localizedDescription] UTF8String]);
+ }
+#endif
+ return success;
+}
+
+-(void)audioSessionInterruption:(NSNotification *)notification
+{
+ NSNumber *type = [[notification userInfo] valueForKey:AVAudioSessionInterruptionTypeKey];
+ if ([type intValue] == AVAudioSessionInterruptionTypeBegan) {
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audioSession Interuption begain");
+#endif
+ } else if ([type intValue] == AVAudioSessionInterruptionTypeEnded) {
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audioSession Interuption ended");
+#endif
+ NSNumber *option = [[notification userInfo] valueForKey:AVAudioSessionInterruptionOptionKey];
+ if ([option intValue] == AVAudioSessionInterruptionOptionShouldResume) {
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audioSession is active and immediately ready to be used.");
+#endif
+ } else {
+ [self activateAudio];
+ }
+ }
+}
+
+-(void)audioSessionMediaServicesWereReset:(NSNotification *)notification
+{
+ Q_UNUSED(notification);
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audioSession Media Services were reset");
+#endif
+ //Reactivate audio when this occurs
+ [self activateAudio];
+}
+
+-(void)audioSessionRouteChange:(NSNotification *)notification
+{
+ NSNumber *reason = [[notification userInfo] valueForKey:AVAudioSessionRouteChangeReasonKey];
+ NSUInteger reasonEnum = [reason intValue];
+
+ if (reasonEnum == AVAudioSessionRouteChangeReasonUnknown) {
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audioSession route changed. reason: unknown");
+#endif
+ } else if (reasonEnum == AVAudioSessionRouteChangeReasonNewDeviceAvailable) {
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audioSession route changed. reason: new device available");
+#endif
+ } else if (reasonEnum == AVAudioSessionRouteChangeReasonOldDeviceUnavailable) {
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audioSession route changed. reason: old device unavailable");
+#endif
+ } else if (reasonEnum == AVAudioSessionRouteChangeReasonCategoryChange) {
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audioSession route changed. reason: category changed");
+#endif
+ } else if (reasonEnum == AVAudioSessionRouteChangeReasonOverride) {
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audioSession route changed. reason: override");
+#endif
+ } else if (reasonEnum == AVAudioSessionRouteChangeReasonWakeFromSleep) {
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audioSession route changed. reason: woken from sleep");
+#endif
+ } else if (reasonEnum == AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory) {
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("audioSession route changed. reason: no suitable route for category");
+#endif
+ }
+
+ m_sessionManager->devicesAvailableChanged();
+}
+
+@end //implementation CoreAudioSessionObserver
+
+CoreAudioSessionManager::CoreAudioSessionManager() :
+ QObject(0)
+{
+ m_sessionObserver = [[CoreAudioSessionObserver alloc] initWithAudioSessionManager:this];
+}
+
+CoreAudioSessionManager::~CoreAudioSessionManager()
+{
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug() << Q_FUNC_INFO;
+#endif
+ [m_sessionObserver release];
+}
+
+
+CoreAudioSessionManager &CoreAudioSessionManager::instance()
+{
+ static CoreAudioSessionManager instance;
+ return instance;
+}
+
+bool CoreAudioSessionManager::setActive(bool active)
+{
+ if (active) {
+ return [m_sessionObserver activateAudio];
+ } else {
+ return [m_sessionObserver deactivateAudio];
+ }
+}
+
+bool CoreAudioSessionManager::setCategory(CoreAudioSessionManager::AudioSessionCategorys category, CoreAudioSessionManager::AudioSessionCategoryOptions options)
+{
+ NSString *targetCategory = nil;
+
+ switch (category) {
+ case CoreAudioSessionManager::Ambient:
+ targetCategory = AVAudioSessionCategoryAmbient;
+ break;
+ case CoreAudioSessionManager::SoloAmbient:
+ targetCategory = AVAudioSessionCategorySoloAmbient;
+ break;
+ case CoreAudioSessionManager::Playback:
+ targetCategory = AVAudioSessionCategoryPlayback;
+ break;
+ case CoreAudioSessionManager::Record:
+ targetCategory = AVAudioSessionCategoryRecord;
+ break;
+ case CoreAudioSessionManager::PlayAndRecord:
+ targetCategory = AVAudioSessionCategoryPlayAndRecord;
+ break;
+ case CoreAudioSessionManager::AudioProcessing:
+#ifndef Q_OS_TVOS
+ targetCategory = AVAudioSessionCategoryAudioProcessing;
+#endif
+ break;
+ case CoreAudioSessionManager::MultiRoute:
+ targetCategory = AVAudioSessionCategoryMultiRoute;
+ break;
+ }
+
+ if (targetCategory == nil)
+ return false;
+
+ return [[m_sessionObserver audioSession] setCategory:targetCategory
+ withOptions:(AVAudioSessionCategoryOptions)options
+ error:nil];
+}
+
+bool CoreAudioSessionManager::setMode(CoreAudioSessionManager::AudioSessionModes mode)
+{
+ NSString *targetMode = nil;
+ switch (mode) {
+ case CoreAudioSessionManager::Default:
+ targetMode = AVAudioSessionModeDefault;
+ break;
+ case CoreAudioSessionManager::VoiceChat:
+ targetMode = AVAudioSessionModeVoiceChat;
+ break;
+ case CoreAudioSessionManager::GameChat:
+ targetMode = AVAudioSessionModeGameChat;
+ break;
+ case CoreAudioSessionManager::VideoRecording:
+ targetMode = AVAudioSessionModeVideoRecording;
+ break;
+ case CoreAudioSessionManager::Measurement:
+ targetMode = AVAudioSessionModeMeasurement;
+ break;
+ case CoreAudioSessionManager::MoviePlayback:
+ targetMode = AVAudioSessionModeMoviePlayback;
+ break;
+ }
+
+ if (targetMode == nil)
+ return false;
+
+ return [[m_sessionObserver audioSession] setMode:targetMode error:nil];
+
+}
+
+CoreAudioSessionManager::AudioSessionCategorys CoreAudioSessionManager::category()
+{
+ NSString *category = [[m_sessionObserver audioSession] category];
+ AudioSessionCategorys localCategory = Ambient;
+
+ if (category == AVAudioSessionCategoryAmbient) {
+ localCategory = Ambient;
+ } else if (category == AVAudioSessionCategorySoloAmbient) {
+ localCategory = SoloAmbient;
+ } else if (category == AVAudioSessionCategoryPlayback) {
+ localCategory = Playback;
+ } else if (category == AVAudioSessionCategoryRecord) {
+ localCategory = Record;
+ } else if (category == AVAudioSessionCategoryPlayAndRecord) {
+ localCategory = PlayAndRecord;
+#ifndef Q_OS_TVOS
+ } else if (category == AVAudioSessionCategoryAudioProcessing) {
+ localCategory = AudioProcessing;
+#endif
+ } else if (category == AVAudioSessionCategoryMultiRoute) {
+ localCategory = MultiRoute;
+ }
+
+ return localCategory;
+}
+
+CoreAudioSessionManager::AudioSessionModes CoreAudioSessionManager::mode()
+{
+ NSString *mode = [[m_sessionObserver audioSession] mode];
+ AudioSessionModes localMode = Default;
+
+ if (mode == AVAudioSessionModeDefault) {
+ localMode = Default;
+ } else if (mode == AVAudioSessionModeVoiceChat) {
+ localMode = VoiceChat;
+ } else if (mode == AVAudioSessionModeGameChat) {
+ localMode = GameChat;
+ } else if (mode == AVAudioSessionModeVideoRecording) {
+ localMode = VideoRecording;
+ } else if (mode == AVAudioSessionModeMeasurement) {
+ localMode = Measurement;
+ } else if (mode == AVAudioSessionModeMoviePlayback) {
+ localMode = MoviePlayback;
+ }
+
+ return localMode;
+}
+
+QList<QByteArray> CoreAudioSessionManager::inputDevices()
+{
+ //TODO: Add support for USB input devices
+ //Right now the default behavior on iOS is to have only one input route
+ //at a time.
+ QList<QByteArray> inputDevices;
+ inputDevices << "default";
+ return inputDevices;
+}
+
+QList<QByteArray> CoreAudioSessionManager::outputDevices()
+{
+ //TODO: Add support for USB output devices
+ //Right now the default behavior on iOS is to have only one output route
+ //at a time.
+ QList<QByteArray> outputDevices;
+ outputDevices << "default";
+ return outputDevices;
+}
+
+float CoreAudioSessionManager::currentIOBufferDuration()
+{
+ return [[m_sessionObserver audioSession] IOBufferDuration];
+}
+
+float CoreAudioSessionManager::preferredSampleRate()
+{
+ return [[m_sessionObserver audioSession] preferredSampleRate];
+}
+
+#ifdef QT_DEBUG_COREAUDIO
+QDebug operator<<(QDebug dbg, CoreAudioSessionManager::AudioSessionCategorys category)
+{
+ QDebug output = dbg.nospace();
+ switch (category) {
+ case CoreAudioSessionManager::Ambient:
+ output << "AudioSessionCategoryAmbient";
+ break;
+ case CoreAudioSessionManager::SoloAmbient:
+ output << "AudioSessionCategorySoloAmbient";
+ break;
+ case CoreAudioSessionManager::Playback:
+ output << "AudioSessionCategoryPlayback";
+ break;
+ case CoreAudioSessionManager::Record:
+ output << "AudioSessionCategoryRecord";
+ break;
+ case CoreAudioSessionManager::PlayAndRecord:
+ output << "AudioSessionCategoryPlayAndRecord";
+ break;
+ case CoreAudioSessionManager::AudioProcessing:
+ output << "AudioSessionCategoryAudioProcessing";
+ break;
+ case CoreAudioSessionManager::MultiRoute:
+ output << "AudioSessionCategoryMultiRoute";
+ break;
+ }
+ return output;
+}
+
+QDebug operator<<(QDebug dbg, CoreAudioSessionManager::AudioSessionCategoryOptions option)
+{
+ QDebug output = dbg.nospace();
+ switch (option) {
+ case CoreAudioSessionManager::None:
+ output << "AudioSessionCategoryOptionNone";
+ break;
+ case CoreAudioSessionManager::MixWithOthers:
+ output << "AudioSessionCategoryOptionMixWithOthers";
+ break;
+ case CoreAudioSessionManager::DuckOthers:
+ output << "AudioSessionCategoryOptionDuckOthers";
+ break;
+ case CoreAudioSessionManager::AllowBluetooth:
+ output << "AudioSessionCategoryOptionAllowBluetooth";
+ break;
+ case CoreAudioSessionManager::DefaultToSpeaker:
+ output << "AudioSessionCategoryOptionDefaultToSpeaker";
+ break;
+ }
+ return output;
+}
+
+QDebug operator<<(QDebug dbg, CoreAudioSessionManager::AudioSessionModes mode)
+{
+ QDebug output = dbg.nospace();
+ switch (mode) {
+ case CoreAudioSessionManager::Default:
+ output << "AudioSessionModeDefault";
+ break;
+ case CoreAudioSessionManager::VoiceChat:
+ output << "AudioSessionModeVoiceChat";
+ break;
+ case CoreAudioSessionManager::GameChat:
+ output << "AudioSessionModeGameChat";
+ break;
+ case CoreAudioSessionManager::VideoRecording:
+ output << "AudioSessionModeVideoRecording";
+ break;
+ case CoreAudioSessionManager::Measurement:
+ output << "AudioSessionModeMeasurement";
+ break;
+ case CoreAudioSessionManager::MoviePlayback:
+ output << "AudioSessionModeMoviePlayback";
+ break;
+ }
+ return output;
+}
+#endif
+
+QT_END_NAMESPACE
+
+#include "moc_qcoreaudiosessionmanager_p.cpp"
diff --git a/src/multimedia/darwin/qcoreaudiosessionmanager_p.h b/src/multimedia/darwin/qcoreaudiosessionmanager_p.h
new file mode 100644
index 000000000..a6dfe88f4
--- /dev/null
+++ b/src/multimedia/darwin/qcoreaudiosessionmanager_p.h
@@ -0,0 +1,95 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef IOSAUDIOSESSIONMANAGER_H
+#define IOSAUDIOSESSIONMANAGER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QObject>
+#ifdef QT_DEBUG_COREAUDIO
+# include <QtCore/QDebug>
+#endif
+
+@class CoreAudioSessionObserver;
+
+QT_BEGIN_NAMESPACE
+
+class CoreAudioSessionManager : public QObject
+{
+ Q_OBJECT
+public:
+ enum AudioSessionCategorys {
+ Ambient,
+ SoloAmbient,
+ Playback,
+ Record,
+ PlayAndRecord,
+ AudioProcessing,
+ MultiRoute
+ };
+ enum AudioSessionCategoryOptions {
+ None = 0,
+ MixWithOthers = 1,
+ DuckOthers = 2,
+ AllowBluetooth = 4,
+ DefaultToSpeaker = 8
+ };
+ enum AudioSessionModes {
+ Default,
+ VoiceChat,
+ GameChat,
+ VideoRecording,
+ Measurement,
+ MoviePlayback
+ };
+
+ static CoreAudioSessionManager& instance();
+
+ bool setActive(bool active);
+ bool setCategory(AudioSessionCategorys category, AudioSessionCategoryOptions options = None);
+ bool setMode(AudioSessionModes mode);
+
+ AudioSessionCategorys category();
+ AudioSessionModes mode();
+
+ QList<QByteArray> inputDevices();
+ QList<QByteArray> outputDevices();
+
+ float currentIOBufferDuration();
+ float preferredSampleRate();
+
+signals:
+ void activeChanged();
+ void categoryChanged();
+ void modeChanged();
+ void routeChanged();
+ void devicesAvailableChanged();
+
+private:
+ CoreAudioSessionManager();
+ ~CoreAudioSessionManager();
+ CoreAudioSessionManager(CoreAudioSessionManager const &copy);
+ CoreAudioSessionManager& operator =(CoreAudioSessionManager const &copy);
+
+ CoreAudioSessionObserver *m_sessionObserver;
+};
+
+#ifdef QT_DEBUG_COREAUDIO
+QDebug operator <<(QDebug dbg, CoreAudioSessionManager::AudioSessionCategorys category);
+QDebug operator <<(QDebug dbg, CoreAudioSessionManager::AudioSessionCategoryOptions option);
+QDebug operator <<(QDebug dbg, CoreAudioSessionManager::AudioSessionModes mode);
+#endif
+
+QT_END_NAMESPACE
+
+#endif // IOSAUDIOSESSIONMANAGER_H
diff --git a/src/multimedia/darwin/qcoreaudioutils.mm b/src/multimedia/darwin/qcoreaudioutils.mm
new file mode 100644
index 000000000..46f98dcc9
--- /dev/null
+++ b/src/multimedia/darwin/qcoreaudioutils.mm
@@ -0,0 +1,344 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qcoreaudioutils_p.h"
+#include <qdebug.h>
+#include <mach/mach_time.h>
+
+QT_BEGIN_NAMESPACE
+
+double CoreAudioUtils::sFrequency = 0.0;
+bool CoreAudioUtils::sIsInitialized = false;
+
+void CoreAudioUtils::initialize()
+{
+ struct mach_timebase_info timeBaseInfo;
+ mach_timebase_info(&timeBaseInfo);
+ sFrequency = static_cast<double>(timeBaseInfo.denom) / static_cast<double>(timeBaseInfo.numer);
+ sFrequency *= 1000000000.0;
+
+ sIsInitialized = true;
+}
+
+
+quint64 CoreAudioUtils::currentTime()
+{
+ return mach_absolute_time();
+}
+
+double CoreAudioUtils::frequency()
+{
+ if (!sIsInitialized)
+ initialize();
+ return sFrequency;
+}
+
+QAudioFormat CoreAudioUtils::toQAudioFormat(AudioStreamBasicDescription const& sf)
+{
+ QAudioFormat audioFormat;
+ // all Darwin HW is little endian, we ignore those formats
+ if ((sf.mFormatFlags & kAudioFormatFlagIsBigEndian) != 0 && QSysInfo::ByteOrder != QSysInfo::LittleEndian)
+ return audioFormat;
+
+ // filter out the formats we're interested in
+ QAudioFormat::SampleFormat format = QAudioFormat::Unknown;
+ switch (sf.mBitsPerChannel) {
+ case 8:
+ if ((sf.mFormatFlags & kAudioFormatFlagIsSignedInteger) == 0)
+ format = QAudioFormat::UInt8;
+ break;
+ case 16:
+ if ((sf.mFormatFlags & kAudioFormatFlagIsSignedInteger) != 0)
+ format = QAudioFormat::Int16;
+ break;
+ case 32:
+ if ((sf.mFormatFlags & kAudioFormatFlagIsSignedInteger) != 0)
+ format = QAudioFormat::Int32;
+ else if ((sf.mFormatFlags & kAudioFormatFlagIsFloat) != 0)
+ format = QAudioFormat::Float;
+ break;
+ default:
+ break;
+ }
+
+ audioFormat.setSampleFormat(format);
+ audioFormat.setSampleRate(sf.mSampleRate);
+ audioFormat.setChannelCount(sf.mChannelsPerFrame);
+
+ return audioFormat;
+}
+
+AudioStreamBasicDescription CoreAudioUtils::toAudioStreamBasicDescription(QAudioFormat const& audioFormat)
+{
+ AudioStreamBasicDescription sf;
+
+ sf.mFormatFlags = kAudioFormatFlagIsPacked;
+ sf.mSampleRate = audioFormat.sampleRate();
+ sf.mFramesPerPacket = 1;
+ sf.mChannelsPerFrame = audioFormat.channelCount();
+ sf.mBitsPerChannel = audioFormat.bytesPerSample() * 8;
+ sf.mBytesPerFrame = audioFormat.bytesPerFrame();
+ sf.mBytesPerPacket = sf.mFramesPerPacket * sf.mBytesPerFrame;
+ sf.mFormatID = kAudioFormatLinearPCM;
+
+ switch (audioFormat.sampleFormat()) {
+ case QAudioFormat::Int16:
+ case QAudioFormat::Int32:
+ sf.mFormatFlags |= kAudioFormatFlagIsSignedInteger;
+ break;
+ case QAudioFormat::Float:
+ sf.mFormatFlags |= kAudioFormatFlagIsFloat;
+ break;
+ case QAudioFormat::UInt8:
+ /* default */
+ case QAudioFormat::Unknown:
+ case QAudioFormat::NSampleFormats:
+ break;
+ }
+
+ return sf;
+}
+
+
+static constexpr struct {
+ QAudioFormat::AudioChannelPosition pos;
+ AudioChannelLabel label;
+} channelMap[] = {
+ { QAudioFormat::FrontLeft, kAudioChannelLabel_Left },
+ { QAudioFormat::FrontRight, kAudioChannelLabel_Right },
+ { QAudioFormat::FrontCenter, kAudioChannelLabel_Center },
+ { QAudioFormat::LFE, kAudioChannelLabel_LFEScreen },
+ { QAudioFormat::BackLeft, kAudioChannelLabel_LeftSurround },
+ { QAudioFormat::BackRight, kAudioChannelLabel_RightSurround },
+ { QAudioFormat::FrontLeftOfCenter, kAudioChannelLabel_LeftCenter },
+ { QAudioFormat::FrontRightOfCenter, kAudioChannelLabel_RightCenter },
+ { QAudioFormat::BackCenter, kAudioChannelLabel_CenterSurround },
+ { QAudioFormat::LFE2, kAudioChannelLabel_LFE2 },
+ { QAudioFormat::SideLeft, kAudioChannelLabel_LeftSurroundDirect }, // ???
+ { QAudioFormat::SideRight, kAudioChannelLabel_RightSurroundDirect }, // ???
+ { QAudioFormat::TopFrontLeft, kAudioChannelLabel_VerticalHeightLeft },
+ { QAudioFormat::TopFrontRight, kAudioChannelLabel_VerticalHeightRight },
+ { QAudioFormat::TopFrontCenter, kAudioChannelLabel_VerticalHeightCenter },
+ { QAudioFormat::TopCenter, kAudioChannelLabel_CenterTopMiddle },
+ { QAudioFormat::TopBackLeft, kAudioChannelLabel_TopBackLeft },
+ { QAudioFormat::TopBackRight, kAudioChannelLabel_TopBackRight },
+ { QAudioFormat::TopSideLeft, kAudioChannelLabel_LeftTopMiddle },
+ { QAudioFormat::TopSideRight, kAudioChannelLabel_RightTopMiddle },
+ { QAudioFormat::TopBackCenter, kAudioChannelLabel_TopBackCenter },
+};
+
+std::unique_ptr<AudioChannelLayout> CoreAudioUtils::toAudioChannelLayout(const QAudioFormat &format, UInt32 *size)
+{
+ auto channelConfig = format.channelConfig();
+ if (channelConfig == QAudioFormat::ChannelConfigUnknown)
+ channelConfig = QAudioFormat::defaultChannelConfigForChannelCount(format.channelCount());
+
+ *size = sizeof(AudioChannelLayout) + int(QAudioFormat::NChannelPositions)*sizeof(AudioChannelDescription);
+ auto *layout = static_cast<AudioChannelLayout *>(malloc(*size));
+ memset(layout, 0, *size);
+ layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
+
+ for (const auto &m : channelMap) {
+ if (channelConfig & QAudioFormat::channelConfig(m.pos))
+ layout->mChannelDescriptions[layout->mNumberChannelDescriptions++].mChannelLabel = m.label;
+ }
+
+ if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::BottomFrontCenter)) {
+ auto &desc = layout->mChannelDescriptions[layout->mNumberChannelDescriptions++];
+ desc.mChannelLabel = kAudioChannelLabel_UseCoordinates;
+ desc.mChannelFlags = kAudioChannelFlags_SphericalCoordinates;
+ desc.mCoordinates[kAudioChannelCoordinates_Azimuth] = 0.f;
+ desc.mCoordinates[kAudioChannelCoordinates_Elevation] = -20.;
+ desc.mCoordinates[kAudioChannelCoordinates_Distance] = 1.f;
+ }
+ if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::BottomFrontLeft)) {
+ auto &desc = layout->mChannelDescriptions[layout->mNumberChannelDescriptions++];
+ desc.mChannelLabel = kAudioChannelLabel_UseCoordinates;
+ desc.mChannelFlags = kAudioChannelFlags_SphericalCoordinates;
+ desc.mCoordinates[kAudioChannelCoordinates_Azimuth] = -45.f;
+ desc.mCoordinates[kAudioChannelCoordinates_Elevation] = -20.;
+ desc.mCoordinates[kAudioChannelCoordinates_Distance] = 1.f;
+ }
+ if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::BottomFrontRight)) {
+ auto &desc = layout->mChannelDescriptions[layout->mNumberChannelDescriptions++];
+ desc.mChannelLabel = kAudioChannelLabel_UseCoordinates;
+ desc.mChannelFlags = kAudioChannelFlags_SphericalCoordinates;
+ desc.mCoordinates[kAudioChannelCoordinates_Azimuth] = 45.f;
+ desc.mCoordinates[kAudioChannelCoordinates_Elevation] = -20.;
+ desc.mCoordinates[kAudioChannelCoordinates_Distance] = 1.f;
+ }
+
+ return std::unique_ptr<AudioChannelLayout>(layout);
+}
+
+static constexpr struct {
+ AudioChannelLayoutTag tag;
+ QAudioFormat::ChannelConfig channelConfig;
+} layoutTagMap[] = {
+ { kAudioChannelLayoutTag_Mono, QAudioFormat::ChannelConfigMono },
+ { kAudioChannelLayoutTag_Stereo, QAudioFormat::ChannelConfigStereo },
+ { kAudioChannelLayoutTag_StereoHeadphones, QAudioFormat::ChannelConfigStereo },
+ { kAudioChannelLayoutTag_MPEG_1_0, QAudioFormat::ChannelConfigMono },
+ { kAudioChannelLayoutTag_MPEG_2_0, QAudioFormat::ChannelConfigStereo },
+ { kAudioChannelLayoutTag_MPEG_3_0_A, QAudioFormat::channelConfig(QAudioFormat::FrontLeft,
+ QAudioFormat::FrontRight,
+ QAudioFormat::FrontCenter) },
+ { kAudioChannelLayoutTag_MPEG_4_0_A, QAudioFormat::channelConfig(QAudioFormat::FrontLeft,
+ QAudioFormat::FrontRight,
+ QAudioFormat::FrontCenter,
+ QAudioFormat::BackCenter) },
+ { kAudioChannelLayoutTag_MPEG_5_0_A, QAudioFormat::ChannelConfigSurround5Dot0 },
+ { kAudioChannelLayoutTag_MPEG_5_1_A, QAudioFormat::ChannelConfigSurround5Dot1 },
+ { kAudioChannelLayoutTag_MPEG_6_1_A, QAudioFormat::channelConfig(QAudioFormat::FrontLeft,
+ QAudioFormat::FrontRight,
+ QAudioFormat::FrontCenter,
+ QAudioFormat::LFE,
+ QAudioFormat::BackLeft,
+ QAudioFormat::BackRight,
+ QAudioFormat::BackCenter) },
+ { kAudioChannelLayoutTag_MPEG_7_1_A, QAudioFormat::ChannelConfigSurround7Dot1 },
+ { kAudioChannelLayoutTag_SMPTE_DTV, QAudioFormat::channelConfig(QAudioFormat::FrontLeft,
+ QAudioFormat::FrontRight,
+ QAudioFormat::FrontCenter,
+ QAudioFormat::LFE,
+ QAudioFormat::BackLeft,
+ QAudioFormat::BackRight,
+ QAudioFormat::TopFrontLeft,
+ QAudioFormat::TopFrontRight) },
+
+ { kAudioChannelLayoutTag_ITU_2_1, QAudioFormat::ChannelConfig2Dot1 },
+ { kAudioChannelLayoutTag_ITU_2_2, QAudioFormat::channelConfig(QAudioFormat::FrontLeft,
+ QAudioFormat::FrontRight,
+ QAudioFormat::BackLeft,
+ QAudioFormat::BackRight) }
+};
+
+
+QAudioFormat::ChannelConfig CoreAudioUtils::fromAudioChannelLayout(const AudioChannelLayout *layout)
+{
+ for (const auto &m : layoutTagMap) {
+ if (m.tag == layout->mChannelLayoutTag)
+ return m.channelConfig;
+ }
+
+ quint32 channels = 0;
+ if (layout->mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelDescriptions) {
+ // special case 1 and 2 channel configs, as they are often reported without proper descriptions
+ if (layout->mNumberChannelDescriptions == 1
+ && (layout->mChannelDescriptions[0].mChannelLabel == kAudioChannelLabel_Unknown
+ || layout->mChannelDescriptions[0].mChannelLabel == kAudioChannelLabel_Mono))
+ return QAudioFormat::ChannelConfigMono;
+ if (layout->mNumberChannelDescriptions == 2 &&
+ layout->mChannelDescriptions[0].mChannelLabel == kAudioChannelLabel_Unknown &&
+ layout->mChannelDescriptions[1].mChannelLabel == kAudioChannelLabel_Unknown)
+ return QAudioFormat::ChannelConfigStereo;
+
+ for (uint i = 0; i < layout->mNumberChannelDescriptions; ++i) {
+ const auto channelLabel = layout->mChannelDescriptions[i].mChannelLabel;
+ if (channelLabel == kAudioChannelLabel_Unknown) {
+ // Any number of unknown channel labels occurs for loopback audio devices.
+ // E.g. the case is reproduced with installed software Soundflower.
+ continue;
+ }
+
+ const auto found = std::find_if(channelMap, std::end(channelMap),
+ [channelLabel](const auto &labelWithPos) {
+ return labelWithPos.label == channelLabel;
+ });
+
+ if (found == std::end(channelMap))
+ qWarning() << "audio device has unrecognized channel, index:" << i
+ << "label:" << channelLabel;
+ else
+ channels |= QAudioFormat::channelConfig(found->pos);
+ }
+ } else {
+ qWarning() << "Channel layout uses unimplemented format, channelLayoutTag:"
+ << layout->mChannelLayoutTag;
+ }
+ return QAudioFormat::ChannelConfig(channels);
+}
+
+// QAudioRingBuffer
+CoreAudioRingBuffer::CoreAudioRingBuffer(int bufferSize):
+ m_bufferSize(bufferSize)
+{
+ m_buffer = new char[m_bufferSize];
+ reset();
+}
+
+CoreAudioRingBuffer::~CoreAudioRingBuffer()
+{
+ delete[] m_buffer;
+}
+
+CoreAudioRingBuffer::Region CoreAudioRingBuffer::acquireReadRegion(int size)
+{
+ const int used = m_bufferUsed.fetchAndAddAcquire(0);
+
+ if (used > 0) {
+ const int readSize = qMin(size, qMin(m_bufferSize - m_readPos, used));
+
+ return readSize > 0 ? Region(m_buffer + m_readPos, readSize) : Region(0, 0);
+ }
+
+ return Region(0, 0);
+}
+
+void CoreAudioRingBuffer::releaseReadRegion(const CoreAudioRingBuffer::Region &region)
+{
+ m_readPos = (m_readPos + region.second) % m_bufferSize;
+
+ m_bufferUsed.fetchAndAddRelease(-region.second);
+}
+
+CoreAudioRingBuffer::Region CoreAudioRingBuffer::acquireWriteRegion(int size)
+{
+ const int free = m_bufferSize - m_bufferUsed.fetchAndAddAcquire(0);
+
+ Region output;
+
+ if (free > 0) {
+ const int writeSize = qMin(size, qMin(m_bufferSize - m_writePos, free));
+ output = writeSize > 0 ? Region(m_buffer + m_writePos, writeSize) : Region(0, 0);
+ } else {
+ output = Region(0, 0);
+ }
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("acquireWriteRegion(%d) free: %d returning Region(%p, %d)", size, free, output.first, output.second);
+#endif
+ return output;
+}
+void CoreAudioRingBuffer::releaseWriteRegion(const CoreAudioRingBuffer::Region &region)
+{
+ m_writePos = (m_writePos + region.second) % m_bufferSize;
+
+ m_bufferUsed.fetchAndAddRelease(region.second);
+#ifdef QT_DEBUG_COREAUDIO
+ qDebug("releaseWriteRegion(%p,%d): m_writePos:%d", region.first, region.second, m_writePos);
+#endif
+}
+
+int CoreAudioRingBuffer::used() const
+{
+ return m_bufferUsed.loadRelaxed();
+}
+
+int CoreAudioRingBuffer::free() const
+{
+ return m_bufferSize - m_bufferUsed.loadRelaxed();
+}
+
+int CoreAudioRingBuffer::size() const
+{
+ return m_bufferSize;
+}
+
+void CoreAudioRingBuffer::reset()
+{
+ m_readPos = 0;
+ m_writePos = 0;
+ m_bufferUsed.storeRelaxed(0);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/darwin/qcoreaudioutils_p.h b/src/multimedia/darwin/qcoreaudioutils_p.h
new file mode 100644
index 000000000..94b6298f3
--- /dev/null
+++ b/src/multimedia/darwin/qcoreaudioutils_p.h
@@ -0,0 +1,72 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef IOSAUDIOUTILS_H
+#define IOSAUDIOUTILS_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <CoreAudio/CoreAudioTypes.h>
+
+#include <QtMultimedia/QAudioFormat>
+#include <QtCore/qglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+class CoreAudioUtils
+{
+public:
+ static quint64 currentTime();
+ static double frequency();
+ static Q_MULTIMEDIA_EXPORT QAudioFormat toQAudioFormat(const AudioStreamBasicDescription& streamFormat);
+ static AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& audioFormat);
+
+ // ownership is transferred to caller, free with ::free()
+ static Q_MULTIMEDIA_EXPORT std::unique_ptr<AudioChannelLayout> toAudioChannelLayout(const QAudioFormat &format, UInt32 *size);
+ static QAudioFormat::ChannelConfig fromAudioChannelLayout(const AudioChannelLayout *layout);
+
+private:
+ static void initialize();
+ static double sFrequency;
+ static bool sIsInitialized;
+};
+
+class CoreAudioRingBuffer
+{
+public:
+ typedef QPair<char*, int> Region;
+
+ CoreAudioRingBuffer(int bufferSize);
+ ~CoreAudioRingBuffer();
+
+ Region acquireReadRegion(int size);
+ void releaseReadRegion(Region const& region);
+ Region acquireWriteRegion(int size);
+ void releaseWriteRegion(Region const& region);
+
+ int used() const;
+ int free() const;
+ int size() const;
+
+ void reset();
+
+private:
+ int m_bufferSize;
+ int m_readPos;
+ int m_writePos;
+ char* m_buffer;
+ QAtomicInt m_bufferUsed;
+};
+
+QT_END_NAMESPACE
+
+#endif // IOSAUDIOUTILS_H
diff --git a/src/multimedia/darwin/qdarwinaudiodevice.mm b/src/multimedia/darwin/qdarwinaudiodevice.mm
new file mode 100644
index 000000000..8374f4cea
--- /dev/null
+++ b/src/multimedia/darwin/qdarwinaudiodevice.mm
@@ -0,0 +1,108 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qdarwinaudiodevice_p.h"
+#include "qcoreaudioutils_p.h"
+#include <private/qcore_mac_p.h>
+
+#if defined(Q_OS_IOS)
+#include "qcoreaudiosessionmanager_p.h"
+#else
+#include "qmacosaudiodatautils_p.h"
+#endif
+
+#include <QtCore/QDataStream>
+#include <QtCore/QDebug>
+#include <QtCore/QSet>
+#include <QIODevice>
+
+QT_BEGIN_NAMESPACE
+
+#if defined(Q_OS_MACOS)
+QCoreAudioDeviceInfo::QCoreAudioDeviceInfo(AudioDeviceID id, const QByteArray &device, QAudioDevice::Mode mode)
+ : QAudioDevicePrivate(device, mode),
+ m_deviceId(id)
+#else
+QCoreAudioDeviceInfo::QCoreAudioDeviceInfo(const QByteArray &device, QAudioDevice::Mode mode)
+ : QAudioDevicePrivate(device, mode)
+#endif
+{
+ description = getDescription();
+ getChannelLayout();
+ preferredFormat = determinePreferredFormat();
+ minimumSampleRate = 1;
+ maximumSampleRate = 96000;
+ minimumChannelCount = 1;
+ maximumChannelCount = 16;
+ supportedSampleFormats << QAudioFormat::UInt8 << QAudioFormat::Int16 << QAudioFormat::Int32 << QAudioFormat::Float;
+
+}
+
+QAudioFormat QCoreAudioDeviceInfo::determinePreferredFormat() const
+{
+ QAudioFormat format;
+
+#if defined(Q_OS_MACOS)
+ const auto audioDevicePropertyStreamsAddress =
+ makePropertyAddress(kAudioDevicePropertyStreams, mode);
+
+ if (auto streamIDs = getAudioData<AudioStreamID>(m_deviceId, audioDevicePropertyStreamsAddress,
+ "propertyStreams")) {
+ const auto audioDevicePhysicalFormatPropertyAddress =
+ makePropertyAddress(kAudioStreamPropertyPhysicalFormat, mode);
+
+ for (auto streamID : *streamIDs) {
+ if (auto streamDescription = getAudioObject<AudioStreamBasicDescription>(
+ streamID, audioDevicePhysicalFormatPropertyAddress,
+ "prefferedPhysicalFormat")) {
+ format = CoreAudioUtils::toQAudioFormat(*streamDescription);
+ break;
+ }
+ }
+ }
+
+ if (!format.isValid())
+#endif
+ {
+ format.setSampleRate(44100);
+ format.setSampleFormat(QAudioFormat::Int16);
+ format.setChannelCount(mode == QAudioDevice::Input ? 1 : 2);
+ }
+ format.setChannelConfig(channelConfiguration);
+
+ return format;
+}
+
+
+QString QCoreAudioDeviceInfo::getDescription() const
+{
+#ifdef Q_OS_MACOS
+ const auto propertyAddress = makePropertyAddress(kAudioObjectPropertyName, mode);
+ if (auto name =
+ getAudioObject<CFStringRef>(m_deviceId, propertyAddress, "Device Description")) {
+ auto deleter = qScopeGuard([&name]() { CFRelease(*name); });
+ return QString::fromCFString(*name);
+ }
+
+ return {};
+#else
+ return QString::fromUtf8(id);
+#endif
+}
+
+void QCoreAudioDeviceInfo::getChannelLayout()
+{
+#ifdef Q_OS_MACOS
+ const auto propertyAddress =
+ makePropertyAddress(kAudioDevicePropertyPreferredChannelLayout, mode);
+ if (auto data = getAudioData<char>(m_deviceId, propertyAddress, "prefferedChannelLayout",
+ sizeof(AudioChannelLayout))) {
+ const auto *layout = reinterpret_cast<const AudioChannelLayout *>(data->data());
+ channelConfiguration = CoreAudioUtils::fromAudioChannelLayout(layout);
+ }
+#else
+ channelConfiguration = (mode == QAudioDevice::Input) ? QAudioFormat::ChannelConfigMono : QAudioFormat::ChannelConfigStereo;
+#endif
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/darwin/qdarwinaudiodevice_p.h b/src/multimedia/darwin/qdarwinaudiodevice_p.h
new file mode 100644
index 000000000..637c5d197
--- /dev/null
+++ b/src/multimedia/darwin/qdarwinaudiodevice_p.h
@@ -0,0 +1,52 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef IOSAUDIODEVICEINFO_H
+#define IOSAUDIODEVICEINFO_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qaudiosystem_p.h>
+#include <private/qaudiodevice_p.h>
+
+#if defined(Q_OS_MACOS)
+# include <CoreAudio/CoreAudio.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class QCoreAudioDeviceInfo : public QAudioDevicePrivate
+{
+public:
+#if defined(Q_OS_MACOS)
+ QCoreAudioDeviceInfo(AudioDeviceID id, const QByteArray &device, QAudioDevice::Mode mode);
+#else
+ QCoreAudioDeviceInfo(const QByteArray &device, QAudioDevice::Mode mode);
+#endif
+ ~QCoreAudioDeviceInfo() {}
+
+ bool isFormatSupported(const QAudioFormat &format) const;
+
+#if defined(Q_OS_MACOS)
+ AudioDeviceID deviceID() const { return m_deviceId; }
+#endif
+private:
+ QAudioFormat determinePreferredFormat() const;
+ QString getDescription() const;
+ void getChannelLayout();
+#if defined(Q_OS_MACOS)
+ AudioDeviceID m_deviceId;
+#endif
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/darwin/qdarwinaudiosink.mm b/src/multimedia/darwin/qdarwinaudiosink.mm
new file mode 100644
index 000000000..9242bb2f0
--- /dev/null
+++ b/src/multimedia/darwin/qdarwinaudiosink.mm
@@ -0,0 +1,609 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qdarwinaudiosink_p.h"
+#include "qcoreaudiosessionmanager_p.h"
+#include "qdarwinaudiodevice_p.h"
+#include "qcoreaudioutils_p.h"
+#include "qdarwinmediadevices_p.h"
+#include <qmediadevices.h>
+
+#include <QtCore/QDataStream>
+#include <QtCore/QTimer>
+#include <QtCore/QDebug>
+
+#include <AudioUnit/AudioUnit.h>
+#include <AudioToolbox/AudioToolbox.h>
+#if defined(Q_OS_MACOS)
+# include <AudioUnit/AudioComponent.h>
+#endif
+
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+# include <QtMultimedia/private/qaudiohelpers_p.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+static int audioRingBufferSize(int bufferSize, int maxPeriodSize)
+{
+ // TODO: review this code
+ return bufferSize
+ + (bufferSize % maxPeriodSize == 0 ? 0 : maxPeriodSize - (bufferSize % maxPeriodSize));
+}
+
+QDarwinAudioSinkBuffer::QDarwinAudioSinkBuffer(int bufferSize, int maxPeriodSize,
+ const QAudioFormat &audioFormat)
+ : m_maxPeriodSize(maxPeriodSize),
+ m_bytesPerFrame(audioFormat.bytesPerFrame()),
+ m_periodTime(maxPeriodSize / m_bytesPerFrame * 1000 / audioFormat.sampleRate()),
+ m_buffer(
+ std::make_unique<CoreAudioRingBuffer>(audioRingBufferSize(bufferSize, maxPeriodSize)))
+{
+ m_fillTimer = new QTimer(this);
+ m_fillTimer->setTimerType(Qt::PreciseTimer);
+ m_fillTimer->setInterval(m_buffer->size() / 2 / m_maxPeriodSize * m_periodTime);
+ connect(m_fillTimer, &QTimer::timeout, this, &QDarwinAudioSinkBuffer::fillBuffer);
+}
+
+QDarwinAudioSinkBuffer::~QDarwinAudioSinkBuffer() = default;
+
+qint64 QDarwinAudioSinkBuffer::readFrames(char *data, qint64 maxFrames)
+{
+ bool wecan = true;
+ qint64 framesRead = 0;
+
+ while (wecan && framesRead < maxFrames) {
+ CoreAudioRingBuffer::Region region = m_buffer->acquireReadRegion((maxFrames - framesRead) * m_bytesPerFrame);
+
+ if (region.second > 0) {
+ // Ensure that we only read whole frames.
+ region.second -= region.second % m_bytesPerFrame;
+
+ if (region.second > 0) {
+ memcpy(data + (framesRead * m_bytesPerFrame), region.first, region.second);
+ framesRead += region.second / m_bytesPerFrame;
+ } else
+ wecan = false; // If there is only a partial frame left we should exit.
+ }
+ else
+ wecan = false;
+
+ m_buffer->releaseReadRegion(region);
+ }
+
+ if (framesRead == 0 && m_deviceError)
+ framesRead = -1;
+
+ return framesRead;
+}
+
+qint64 QDarwinAudioSinkBuffer::writeBytes(const char *data, qint64 maxSize)
+{
+ bool wecan = true;
+ qint64 bytesWritten = 0;
+
+ maxSize -= maxSize % m_bytesPerFrame;
+ while (wecan && bytesWritten < maxSize) {
+ CoreAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(maxSize - bytesWritten);
+
+ if (region.second > 0) {
+ memcpy(region.first, data + bytesWritten, region.second);
+ bytesWritten += region.second;
+ }
+ else
+ wecan = false;
+
+ m_buffer->releaseWriteRegion(region);
+ }
+
+ if (bytesWritten > 0)
+ emit readyRead();
+
+ return bytesWritten;
+}
+
+int QDarwinAudioSinkBuffer::available() const
+{
+ return m_buffer->free();
+}
+
+bool QDarwinAudioSinkBuffer::deviceAtEnd() const
+{
+ return m_deviceAtEnd;
+}
+
+void QDarwinAudioSinkBuffer::reset()
+{
+ m_buffer->reset();
+ setFillingEnabled(false);
+ setPrefetchDevice(nullptr);
+}
+
+void QDarwinAudioSinkBuffer::setPrefetchDevice(QIODevice *device)
+{
+ if (std::exchange(m_device, device) == device)
+ return;
+
+ m_deviceError = false;
+ m_deviceAtEnd = device && device->atEnd();
+ const auto wasFillingEnabled = m_fillingEnabled;
+ setFillingEnabled(false);
+ setFillingEnabled(wasFillingEnabled);
+}
+
+QIODevice *QDarwinAudioSinkBuffer::prefetchDevice() const
+{
+ return m_device;
+}
+
+void QDarwinAudioSinkBuffer::setFillingEnabled(bool enabled)
+{
+ if (std::exchange(m_fillingEnabled, enabled) == enabled)
+ return;
+
+ if (!enabled)
+ m_fillTimer->stop();
+ else if (m_device) {
+ fillBuffer();
+ m_fillTimer->start();
+ }
+}
+
+void QDarwinAudioSinkBuffer::fillBuffer()
+{
+ const int free = m_buffer->free();
+ const int writeSize = free - (free % m_maxPeriodSize);
+
+ if (writeSize > 0) {
+ bool wecan = true;
+ int filled = 0;
+
+ while (!m_deviceError && wecan && filled < writeSize) {
+ CoreAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(writeSize - filled);
+
+ if (region.second > 0) {
+ region.second = m_device->read(region.first, region.second);
+ m_deviceAtEnd = m_device->atEnd();
+ if (region.second > 0)
+ filled += region.second;
+ else if (region.second == 0)
+ wecan = false;
+ else if (region.second < 0) {
+ setFillingEnabled(false);
+ region.second = 0;
+ m_deviceError = true;
+ }
+ }
+ else
+ wecan = false;
+
+ m_buffer->releaseWriteRegion(region);
+ }
+
+ if (filled > 0)
+ emit readyRead();
+ }
+}
+
+QDarwinAudioSinkDevice::QDarwinAudioSinkDevice(QDarwinAudioSinkBuffer *audioBuffer, QObject *parent)
+ : QIODevice(parent)
+ , m_audioBuffer(audioBuffer)
+{
+ open(QIODevice::WriteOnly | QIODevice::Unbuffered);
+}
+
+qint64 QDarwinAudioSinkDevice::readData(char *data, qint64 len)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(len);
+
+ return 0;
+}
+
+qint64 QDarwinAudioSinkDevice::writeData(const char *data, qint64 len)
+{
+ return m_audioBuffer->writeBytes(data, len);
+}
+
+QDarwinAudioSink::QDarwinAudioSink(const QAudioDevice &device, QObject *parent)
+ : QPlatformAudioSink(parent), m_audioDeviceInfo(device), m_stateMachine(*this)
+{
+ QAudioDevice di = device;
+ if (di.isNull())
+ di = QMediaDevices::defaultAudioOutput();
+#if defined(Q_OS_MACOS)
+ const QCoreAudioDeviceInfo *info = static_cast<const QCoreAudioDeviceInfo *>(di.handle());
+ Q_ASSERT(info);
+ m_audioDeviceId = info->deviceID();
+#endif
+ m_device = di.id();
+
+ m_clockFrequency = CoreAudioUtils::frequency() / 1000;
+
+ connect(this, &QDarwinAudioSink::stateChanged, this, &QDarwinAudioSink::updateAudioDevice);
+}
+
+QDarwinAudioSink::~QDarwinAudioSink()
+{
+ close();
+}
+
+void QDarwinAudioSink::start(QIODevice *device)
+{
+ reset();
+
+ if (!m_audioDeviceInfo.isFormatSupported(m_audioFormat) || !open()) {
+ m_stateMachine.setError(QAudio::OpenError);
+ return;
+ }
+
+ if (!device) {
+ m_stateMachine.setError(QAudio::IOError);
+ return;
+ }
+
+ m_audioBuffer->setPrefetchDevice(device);
+
+ m_pullMode = true;
+ m_totalFrames = 0;
+
+ m_stateMachine.start();
+}
+
+QIODevice *QDarwinAudioSink::start()
+{
+ reset();
+
+ if (!m_audioDeviceInfo.isFormatSupported(m_audioFormat) || !open()) {
+ m_stateMachine.setError(QAudio::OpenError);
+ return m_audioIO;
+ }
+
+ m_pullMode = false;
+ m_totalFrames = 0;
+
+ m_stateMachine.start(false);
+
+ return m_audioIO;
+}
+
+void QDarwinAudioSink::stop()
+{
+ if (m_audioBuffer)
+ m_audioBuffer->setFillingEnabled(false);
+
+ if (auto notifier = m_stateMachine.stop(QAudio::NoError, true)) {
+ Q_ASSERT((notifier.prevAudioState() == QAudio::ActiveState) == notifier.isDraining());
+ if (notifier.isDraining() && !m_drainSemaphore.tryAcquire(1, 500)) {
+ const bool wasDraining = m_stateMachine.onDrained();
+
+ qWarning() << "Failed wait for getting sink drained; was draining:" << wasDraining;
+
+ // handle a rare corner case when the audio thread managed to release the semaphore in
+ // the time window between tryAcquire and onDrained
+ if (!wasDraining)
+ m_drainSemaphore.acquire();
+ }
+ }
+}
+
+void QDarwinAudioSink::reset()
+{
+ onAudioDeviceDrained();
+ m_stateMachine.stopOrUpdateError();
+}
+
+void QDarwinAudioSink::suspend()
+{
+ m_stateMachine.suspend();
+}
+
+void QDarwinAudioSink::resume()
+{
+ m_stateMachine.resume();
+}
+
+qsizetype QDarwinAudioSink::bytesFree() const
+{
+ return m_audioBuffer->available();
+}
+
+void QDarwinAudioSink::setBufferSize(qsizetype value)
+{
+ if (state() == QAudio::StoppedState)
+ m_internalBufferSize = value;
+}
+
+qsizetype QDarwinAudioSink::bufferSize() const
+{
+ return m_internalBufferSize;
+}
+
+qint64 QDarwinAudioSink::processedUSecs() const
+{
+ return m_totalFrames * 1000000 / m_audioFormat.sampleRate();
+}
+
+QAudio::Error QDarwinAudioSink::error() const
+{
+ return m_stateMachine.error();
+}
+
+QAudio::State QDarwinAudioSink::state() const
+{
+ return m_stateMachine.state();
+}
+
+void QDarwinAudioSink::setFormat(const QAudioFormat &format)
+{
+ if (state() == QAudio::StoppedState)
+ m_audioFormat = format;
+}
+
+QAudioFormat QDarwinAudioSink::format() const
+{
+ return m_audioFormat;
+}
+
+void QDarwinAudioSink::setVolume(qreal volume)
+{
+ m_cachedVolume = qBound(qreal(0.0), volume, qreal(1.0));
+ if (!m_isOpen)
+ return;
+
+#if defined(Q_OS_MACOS)
+ //on OS X the volume can be set directly on the AudioUnit
+ if (AudioUnitSetParameter(m_audioUnit,
+ kHALOutputParam_Volume,
+ kAudioUnitScope_Global,
+ 0 /* bus */,
+ m_cachedVolume,
+ 0) == noErr)
+ m_volume = m_cachedVolume;
+#endif
+}
+
+qreal QDarwinAudioSink::volume() const
+{
+ return m_cachedVolume;
+}
+
+void QDarwinAudioSink::inputReady()
+{
+ m_stateMachine.activateFromIdle();
+}
+
+OSStatus QDarwinAudioSink::renderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
+{
+ Q_UNUSED(ioActionFlags);
+ Q_UNUSED(inTimeStamp);
+ Q_UNUSED(inBusNumber);
+ Q_UNUSED(inNumberFrames);
+
+ QDarwinAudioSink* d = static_cast<QDarwinAudioSink*>(inRefCon);
+
+ const auto [drained, stopped] = d->m_stateMachine.getDrainedAndStopped();
+
+ if (drained && stopped) {
+ ioData->mBuffers[0].mDataByteSize = 0;
+ } else {
+ const UInt32 bytesPerFrame = d->m_streamFormat.mBytesPerFrame;
+ qint64 framesRead;
+
+ Q_ASSERT(ioData->mBuffers[0].mDataByteSize / bytesPerFrame == inNumberFrames);
+ framesRead = d->m_audioBuffer->readFrames((char*)ioData->mBuffers[0].mData,
+ ioData->mBuffers[0].mDataByteSize / bytesPerFrame);
+
+ if (framesRead > 0) {
+ ioData->mBuffers[0].mDataByteSize = framesRead * bytesPerFrame;
+ d->m_totalFrames += framesRead;
+
+#if defined(Q_OS_MACOS)
+ if (stopped) {
+ qreal oldVolume = d->m_cachedVolume;
+ // Decrease volume smoothly.
+ d->setVolume(d->m_volume / 2);
+ d->m_cachedVolume = oldVolume;
+ }
+#elif defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+ // on iOS we have to adjust the sound volume ourselves
+ if (!qFuzzyCompare(d->m_cachedVolume, qreal(1.0f))) {
+ QAudioHelperInternal::qMultiplySamples(d->m_cachedVolume,
+ d->m_audioFormat,
+ ioData->mBuffers[0].mData, /* input */
+ ioData->mBuffers[0].mData, /* output */
+ ioData->mBuffers[0].mDataByteSize);
+ }
+#endif
+
+ }
+ else {
+ ioData->mBuffers[0].mDataByteSize = 0;
+ if (framesRead == 0)
+ d->onAudioDeviceIdle();
+ else
+ d->onAudioDeviceError();
+ }
+ }
+
+ return noErr;
+}
+
+bool QDarwinAudioSink::open()
+{
+#if defined(Q_OS_IOS)
+ // Set default category to Ambient (implies MixWithOthers). This makes sure audio stops playing
+ // if the screen is locked or if the Silent switch is toggled.
+ CoreAudioSessionManager::instance().setCategory(CoreAudioSessionManager::Ambient, CoreAudioSessionManager::None);
+ CoreAudioSessionManager::instance().setActive(true);
+#endif
+
+ if (error() != QAudio::NoError)
+ return false;
+
+ if (m_isOpen) {
+ setVolume(m_cachedVolume);
+ return true;
+ }
+
+ AudioComponentDescription componentDescription;
+ componentDescription.componentType = kAudioUnitType_Output;
+#if defined(Q_OS_MACOS)
+ componentDescription.componentSubType = kAudioUnitSubType_HALOutput;
+#else
+ componentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
+#endif
+ componentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
+ componentDescription.componentFlags = 0;
+ componentDescription.componentFlagsMask = 0;
+
+ AudioComponent component = AudioComponentFindNext(0, &componentDescription);
+ if (component == 0) {
+ qWarning() << "QAudioOutput: Failed to find Output component";
+ return false;
+ }
+
+ if (AudioComponentInstanceNew(component, &m_audioUnit) != noErr) {
+ qWarning() << "QAudioOutput: Unable to Open Output Component";
+ return false;
+ }
+
+ // register callback
+ AURenderCallbackStruct callback;
+ callback.inputProc = renderCallback;
+ callback.inputProcRefCon = this;
+
+ if (AudioUnitSetProperty(m_audioUnit,
+ kAudioUnitProperty_SetRenderCallback,
+ kAudioUnitScope_Global,
+ 0,
+ &callback,
+ sizeof(callback)) != noErr) {
+ qWarning() << "QAudioOutput: Failed to set AudioUnit callback";
+ return false;
+ }
+
+#if defined(Q_OS_MACOS)
+ //Set Audio Device
+ if (AudioUnitSetProperty(m_audioUnit,
+ kAudioOutputUnitProperty_CurrentDevice,
+ kAudioUnitScope_Global,
+ 0,
+ &m_audioDeviceId,
+ sizeof(m_audioDeviceId)) != noErr) {
+ qWarning() << "QAudioOutput: Unable to use configured device";
+ return false;
+ }
+#endif
+ UInt32 size;
+
+
+ // Set stream format
+ m_streamFormat = CoreAudioUtils::toAudioStreamBasicDescription(m_audioFormat);
+ size = sizeof(m_streamFormat);
+
+ if (AudioUnitSetProperty(m_audioUnit,
+ kAudioUnitProperty_StreamFormat,
+ kAudioUnitScope_Input,
+ 0,
+ &m_streamFormat,
+ size) != noErr) {
+ qWarning() << "QAudioOutput: Unable to Set Stream information";
+ return false;
+ }
+
+ // Allocate buffer
+ UInt32 numberOfFrames = 0;
+#if defined(Q_OS_MACOS)
+ size = sizeof(UInt32);
+ if (AudioUnitGetProperty(m_audioUnit,
+ kAudioDevicePropertyBufferFrameSize,
+ kAudioUnitScope_Global,
+ 0,
+ &numberOfFrames,
+ &size) != noErr) {
+ qWarning() << "QAudioSource: Failed to get audio period size";
+ return false;
+ }
+#else //iOS
+ Float32 bufferSize = CoreAudioSessionManager::instance().currentIOBufferDuration();
+ bufferSize *= m_streamFormat.mSampleRate;
+ numberOfFrames = bufferSize;
+#endif
+
+ m_periodSizeBytes = numberOfFrames * m_streamFormat.mBytesPerFrame;
+ if (m_internalBufferSize < m_periodSizeBytes * 2)
+ m_internalBufferSize = m_periodSizeBytes * 2;
+ else
+ m_internalBufferSize -= m_internalBufferSize % m_streamFormat.mBytesPerFrame;
+
+ m_audioBuffer = std::make_unique<QDarwinAudioSinkBuffer>(m_internalBufferSize,
+ m_periodSizeBytes, m_audioFormat);
+ connect(m_audioBuffer.get(), &QDarwinAudioSinkBuffer::readyRead, this,
+ &QDarwinAudioSink::inputReady); // Pull
+
+ m_audioIO = new QDarwinAudioSinkDevice(m_audioBuffer.get(), this);
+
+ //Init
+ if (AudioUnitInitialize(m_audioUnit)) {
+ qWarning() << "QAudioOutput: Failed to initialize AudioUnit";
+ return false;
+ }
+
+ m_isOpen = true;
+
+ setVolume(m_cachedVolume);
+
+ return true;
+}
+
+void QDarwinAudioSink::close()
+{
+ if (m_audioUnit != 0) {
+ m_stateMachine.stop();
+
+ AudioUnitUninitialize(m_audioUnit);
+ AudioComponentInstanceDispose(m_audioUnit);
+ m_audioUnit = 0;
+ }
+
+ m_audioBuffer.reset();
+}
+
+void QDarwinAudioSink::onAudioDeviceIdle()
+{
+ const bool atEnd = m_audioBuffer->deviceAtEnd();
+ if (!m_stateMachine.updateActiveOrIdle(false, atEnd ? QAudio::NoError : QAudio::UnderrunError))
+ onAudioDeviceDrained();
+}
+
+void QDarwinAudioSink::onAudioDeviceDrained()
+{
+ if (m_stateMachine.onDrained())
+ m_drainSemaphore.release();
+}
+
+void QDarwinAudioSink::onAudioDeviceError()
+{
+ m_stateMachine.stop(QAudio::IOError);
+}
+
+void QDarwinAudioSink::updateAudioDevice()
+{
+ const auto state = m_stateMachine.state();
+
+ Q_ASSERT(m_audioBuffer);
+ Q_ASSERT(m_audioUnit);
+
+ if (state == QAudio::StoppedState)
+ m_audioBuffer->reset();
+ else
+ m_audioBuffer->setFillingEnabled(state != QAudio::SuspendedState);
+
+ const bool unitStarted = state == QAudio::ActiveState;
+ if (std::exchange(m_audioUnitStarted, unitStarted) != unitStarted)
+ (unitStarted ? AudioOutputUnitStart : AudioOutputUnitStop)(m_audioUnit);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qdarwinaudiosink_p.cpp"
diff --git a/src/multimedia/darwin/qdarwinaudiosink_p.h b/src/multimedia/darwin/qdarwinaudiosink_p.h
new file mode 100644
index 000000000..1fddcb205
--- /dev/null
+++ b/src/multimedia/darwin/qdarwinaudiosink_p.h
@@ -0,0 +1,170 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef IOSAUDIOOUTPUT_H
+#define IOSAUDIOOUTPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qaudiosystem_p.h>
+#include <private/qaudiostatemachine_p.h>
+
+#if defined(Q_OS_MACOS)
+# include <CoreAudio/CoreAudio.h>
+#endif
+#include <AudioUnit/AudioUnit.h>
+#include <CoreAudio/CoreAudioTypes.h>
+
+#include <QtCore/QIODevice>
+#include <qdarwinaudiodevice_p.h>
+#include <qsemaphore.h>
+
+QT_BEGIN_NAMESPACE
+
+class QDarwinAudioSinkBuffer;
+class QTimer;
+class QCoreAudioDeviceInfo;
+class CoreAudioRingBuffer;
+
+class QDarwinAudioSinkBuffer : public QObject
+{
+ Q_OBJECT
+
+public:
+ QDarwinAudioSinkBuffer(int bufferSize, int maxPeriodSize, QAudioFormat const& audioFormat);
+ ~QDarwinAudioSinkBuffer();
+
+ qint64 readFrames(char *data, qint64 maxFrames);
+ qint64 writeBytes(const char *data, qint64 maxSize);
+
+ int available() const;
+
+ bool deviceAtEnd() const;
+
+ void reset();
+
+ void setPrefetchDevice(QIODevice *device);
+
+ QIODevice *prefetchDevice() const;
+
+ void setFillingEnabled(bool enabled);
+
+signals:
+ void readyRead();
+
+private slots:
+ void fillBuffer();
+
+private:
+ bool m_deviceError = false;
+ bool m_fillingEnabled = false;
+ bool m_deviceAtEnd = false;
+ const int m_maxPeriodSize = 0;
+ const int m_bytesPerFrame = 0;
+ const int m_periodTime = 0;
+ QIODevice *m_device = nullptr;
+ QTimer *m_fillTimer = nullptr;
+ std::unique_ptr<CoreAudioRingBuffer> m_buffer;
+};
+
+class QDarwinAudioSinkDevice : public QIODevice
+{
+public:
+ QDarwinAudioSinkDevice(QDarwinAudioSinkBuffer *audioBuffer, QObject *parent);
+
+ qint64 readData(char *data, qint64 len);
+ qint64 writeData(const char *data, qint64 len);
+
+ bool isSequential() const { return true; }
+
+private:
+ QDarwinAudioSinkBuffer *m_audioBuffer;
+};
+
+
+class QDarwinAudioSink : public QPlatformAudioSink
+{
+ Q_OBJECT
+
+public:
+ QDarwinAudioSink(const QAudioDevice &device, QObject *parent);
+ ~QDarwinAudioSink();
+
+ void start(QIODevice *device);
+ QIODevice *start();
+ void stop();
+ void reset();
+ void suspend();
+ void resume();
+ qsizetype bytesFree() const;
+ void setBufferSize(qsizetype value);
+ qsizetype bufferSize() const;
+ qint64 processedUSecs() const;
+ QAudio::Error error() const;
+ QAudio::State state() const;
+ void setFormat(const QAudioFormat &format);
+ QAudioFormat format() const;
+
+ void setVolume(qreal volume);
+ qreal volume() const;
+
+private slots:
+ void inputReady();
+ void updateAudioDevice();
+
+private:
+ enum ThreadState { Running, Draining, Stopped };
+
+ static OSStatus renderCallback(void *inRefCon,
+ AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp,
+ UInt32 inBusNumber,
+ UInt32 inNumberFrames,
+ AudioBufferList *ioData);
+
+ bool open();
+ void close();
+ void onAudioDeviceIdle();
+ void onAudioDeviceError();
+ void onAudioDeviceDrained();
+
+ QAudioDevice m_audioDeviceInfo;
+ QByteArray m_device;
+
+ static constexpr int DEFAULT_BUFFER_SIZE = 8 * 1024;
+
+ bool m_isOpen = false;
+ int m_internalBufferSize = DEFAULT_BUFFER_SIZE;
+ int m_periodSizeBytes = 0;
+ qint64 m_totalFrames = 0;
+ QAudioFormat m_audioFormat;
+ QIODevice *m_audioIO = nullptr;
+#if defined(Q_OS_MACOS)
+ AudioDeviceID m_audioDeviceId;
+#endif
+ AudioUnit m_audioUnit = 0;
+ bool m_audioUnitStarted = false;
+ Float64 m_clockFrequency = 0;
+ AudioStreamBasicDescription m_streamFormat;
+ std::unique_ptr<QDarwinAudioSinkBuffer> m_audioBuffer;
+ qreal m_cachedVolume = 1.;
+#if defined(Q_OS_MACOS)
+ qreal m_volume = 1.;
+#endif
+ bool m_pullMode = false;
+
+ QAudioStateMachine m_stateMachine;
+ QSemaphore m_drainSemaphore;
+};
+
+QT_END_NAMESPACE
+
+#endif // IOSAUDIOOUTPUT_H
diff --git a/src/multimedia/darwin/qdarwinaudiosource.mm b/src/multimedia/darwin/qdarwinaudiosource.mm
new file mode 100644
index 000000000..4c1345fb8
--- /dev/null
+++ b/src/multimedia/darwin/qdarwinaudiosource.mm
@@ -0,0 +1,942 @@
+// Copyright (C) 2022 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qdarwinaudiosource_p.h"
+#include "qcoreaudiosessionmanager_p.h"
+#include "qdarwinaudiodevice_p.h"
+#include "qcoreaudioutils_p.h"
+#include "qdarwinmediadevices_p.h"
+#include <qmediadevices.h>
+
+#if defined(Q_OS_MACOS)
+# include <AudioUnit/AudioComponent.h>
+#endif
+
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+# include "qcoreaudiosessionmanager_p.h"
+#endif
+
+#include <QtMultimedia/private/qaudiohelpers_p.h>
+#include <QtCore/QDataStream>
+#include <QtCore/QDebug>
+
+QT_BEGIN_NAMESPACE
+
+static const int DEFAULT_BUFFER_SIZE = 4 * 1024;
+
+QCoreAudioBufferList::QCoreAudioBufferList(const AudioStreamBasicDescription &streamFormat)
+ : m_owner(false)
+ , m_streamDescription(streamFormat)
+{
+ const bool isInterleaved = (m_streamDescription.mFormatFlags & kAudioFormatFlagIsNonInterleaved) == 0;
+ const int numberOfBuffers = isInterleaved ? 1 : m_streamDescription.mChannelsPerFrame;
+
+ m_dataSize = 0;
+
+ m_bufferList = reinterpret_cast<AudioBufferList*>(malloc(sizeof(AudioBufferList) +
+ (sizeof(AudioBuffer) * numberOfBuffers)));
+
+ m_bufferList->mNumberBuffers = numberOfBuffers;
+ for (int i = 0; i < numberOfBuffers; ++i) {
+ m_bufferList->mBuffers[i].mNumberChannels = isInterleaved ? numberOfBuffers : 1;
+ m_bufferList->mBuffers[i].mDataByteSize = 0;
+ m_bufferList->mBuffers[i].mData = 0;
+ }
+}
+
+QCoreAudioBufferList::QCoreAudioBufferList(const AudioStreamBasicDescription &streamFormat, char *buffer, int bufferSize)
+ : m_owner(false)
+ , m_streamDescription(streamFormat)
+ , m_bufferList(0)
+{
+ m_dataSize = bufferSize;
+
+ m_bufferList = reinterpret_cast<AudioBufferList*>(malloc(sizeof(AudioBufferList) + sizeof(AudioBuffer)));
+
+ m_bufferList->mNumberBuffers = 1;
+ m_bufferList->mBuffers[0].mNumberChannels = 1;
+ m_bufferList->mBuffers[0].mDataByteSize = m_dataSize;
+ m_bufferList->mBuffers[0].mData = buffer;
+}
+
+QCoreAudioBufferList::QCoreAudioBufferList(const AudioStreamBasicDescription &streamFormat, int framesToBuffer)
+ : m_owner(true)
+ , m_streamDescription(streamFormat)
+ , m_bufferList(0)
+{
+ const bool isInterleaved = (m_streamDescription.mFormatFlags & kAudioFormatFlagIsNonInterleaved) == 0;
+ const int numberOfBuffers = isInterleaved ? 1 : m_streamDescription.mChannelsPerFrame;
+
+ m_dataSize = framesToBuffer * m_streamDescription.mBytesPerFrame;
+
+ m_bufferList = reinterpret_cast<AudioBufferList*>(malloc(sizeof(AudioBufferList) +
+ (sizeof(AudioBuffer) * numberOfBuffers)));
+ m_bufferList->mNumberBuffers = numberOfBuffers;
+ for (int i = 0; i < numberOfBuffers; ++i) {
+ m_bufferList->mBuffers[i].mNumberChannels = isInterleaved ? numberOfBuffers : 1;
+ m_bufferList->mBuffers[i].mDataByteSize = m_dataSize;
+ m_bufferList->mBuffers[i].mData = malloc(m_dataSize);
+ }
+}
+
+QCoreAudioBufferList::~QCoreAudioBufferList()
+{
+ if (m_owner) {
+ for (UInt32 i = 0; i < m_bufferList->mNumberBuffers; ++i)
+ free(m_bufferList->mBuffers[i].mData);
+ }
+
+ free(m_bufferList);
+}
+
+char *QCoreAudioBufferList::data(int buffer) const
+{
+ return static_cast<char*>(m_bufferList->mBuffers[buffer].mData);
+}
+
+qint64 QCoreAudioBufferList::bufferSize(int buffer) const
+{
+ return m_bufferList->mBuffers[buffer].mDataByteSize;
+}
+
+int QCoreAudioBufferList::frameCount(int buffer) const
+{
+ return m_bufferList->mBuffers[buffer].mDataByteSize / m_streamDescription.mBytesPerFrame;
+}
+
+int QCoreAudioBufferList::packetCount(int buffer) const
+{
+ return m_bufferList->mBuffers[buffer].mDataByteSize / m_streamDescription.mBytesPerPacket;
+}
+
+int QCoreAudioBufferList::packetSize() const
+{
+ return m_streamDescription.mBytesPerPacket;
+}
+
+void QCoreAudioBufferList::reset()
+{
+ for (UInt32 i = 0; i < m_bufferList->mNumberBuffers; ++i) {
+ m_bufferList->mBuffers[i].mDataByteSize = m_dataSize;
+ m_bufferList->mBuffers[i].mData = 0;
+ }
+}
+
+QCoreAudioPacketFeeder::QCoreAudioPacketFeeder(QCoreAudioBufferList *abl)
+ : m_audioBufferList(abl)
+{
+ m_totalPackets = m_audioBufferList->packetCount();
+ m_position = 0;
+}
+
+bool QCoreAudioPacketFeeder::feed(AudioBufferList &dst, UInt32 &packetCount)
+{
+ if (m_position == m_totalPackets) {
+ dst.mBuffers[0].mDataByteSize = 0;
+ packetCount = 0;
+ return false;
+ }
+
+ if (m_totalPackets - m_position < packetCount)
+ packetCount = m_totalPackets - m_position;
+
+ dst.mBuffers[0].mDataByteSize = packetCount * m_audioBufferList->packetSize();
+ dst.mBuffers[0].mData = m_audioBufferList->data() + (m_position * m_audioBufferList->packetSize());
+
+ m_position += packetCount;
+
+ return true;
+}
+
+bool QCoreAudioPacketFeeder::empty() const
+{
+ return m_position == m_totalPackets;
+}
+
+QDarwinAudioSourceBuffer::QDarwinAudioSourceBuffer(int bufferSize, int maxPeriodSize, const AudioStreamBasicDescription &inputFormat, const AudioStreamBasicDescription &outputFormat, QObject *parent)
+ : QObject(parent)
+ , m_deviceError(false)
+ , m_device(0)
+ , m_audioConverter(0)
+ , m_inputFormat(inputFormat)
+ , m_outputFormat(outputFormat)
+ , m_volume(qreal(1.0f))
+{
+ m_maxPeriodSize = maxPeriodSize;
+ m_periodTime = m_maxPeriodSize / m_outputFormat.mBytesPerFrame * 1000 / m_outputFormat.mSampleRate;
+
+ m_buffer = new CoreAudioRingBuffer(bufferSize);
+
+ m_inputBufferList = new QCoreAudioBufferList(m_inputFormat);
+
+ m_flushTimer = new QTimer(this);
+ connect(m_flushTimer, SIGNAL(timeout()), this, SLOT(flushBuffer()));
+
+ if (CoreAudioUtils::toQAudioFormat(inputFormat) != CoreAudioUtils::toQAudioFormat(outputFormat)) {
+ if (AudioConverterNew(&m_inputFormat, &m_outputFormat, &m_audioConverter) != noErr) {
+ qWarning() << "QAudioSource: Unable to create an Audio Converter";
+ m_audioConverter = 0;
+ }
+ }
+
+ m_qFormat = CoreAudioUtils::toQAudioFormat(inputFormat); // we adjust volume before conversion
+}
+
+QDarwinAudioSourceBuffer::~QDarwinAudioSourceBuffer()
+{
+ delete m_buffer;
+}
+
+qreal QDarwinAudioSourceBuffer::volume() const
+{
+ return m_volume;
+}
+
+void QDarwinAudioSourceBuffer::setVolume(qreal v)
+{
+ m_volume = v;
+}
+
+qint64 QDarwinAudioSourceBuffer::renderFromDevice(AudioUnit audioUnit, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames)
+{
+ const bool pullMode = m_device == 0;
+
+ OSStatus err;
+ qint64 framesRendered = 0;
+
+ m_inputBufferList->reset();
+ err = AudioUnitRender(audioUnit,
+ ioActionFlags,
+ inTimeStamp,
+ inBusNumber,
+ inNumberFrames,
+ m_inputBufferList->audioBufferList());
+
+ // adjust volume, if necessary
+ if (!qFuzzyCompare(m_volume, qreal(1.0f))) {
+ QAudioHelperInternal::qMultiplySamples(m_volume,
+ m_qFormat,
+ m_inputBufferList->data(), /* input */
+ m_inputBufferList->data(), /* output */
+ m_inputBufferList->bufferSize());
+ }
+
+ if (m_audioConverter != 0) {
+ QCoreAudioPacketFeeder feeder(m_inputBufferList);
+
+ int copied = 0;
+ const int available = m_buffer->free();
+
+ while (err == noErr && !feeder.empty()) {
+ CoreAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available - copied);
+
+ if (region.second == 0)
+ break;
+
+ AudioBufferList output;
+ output.mNumberBuffers = 1;
+ output.mBuffers[0].mNumberChannels = 1;
+ output.mBuffers[0].mDataByteSize = region.second;
+ output.mBuffers[0].mData = region.first;
+
+ UInt32 packetSize = region.second / m_outputFormat.mBytesPerPacket;
+ err = AudioConverterFillComplexBuffer(m_audioConverter,
+ converterCallback,
+ &feeder,
+ &packetSize,
+ &output,
+ 0);
+ region.second = output.mBuffers[0].mDataByteSize;
+ copied += region.second;
+
+ m_buffer->releaseWriteRegion(region);
+ }
+
+ framesRendered += copied / m_outputFormat.mBytesPerFrame;
+ }
+ else {
+ const int available = m_inputBufferList->bufferSize();
+ bool wecan = true;
+ int copied = 0;
+
+ while (wecan && copied < available) {
+ CoreAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available - copied);
+
+ if (region.second > 0) {
+ memcpy(region.first, m_inputBufferList->data() + copied, region.second);
+ copied += region.second;
+ }
+ else
+ wecan = false;
+
+ m_buffer->releaseWriteRegion(region);
+ }
+
+ framesRendered = copied / m_outputFormat.mBytesPerFrame;
+ }
+
+ if (pullMode && framesRendered > 0)
+ emit readyRead();
+
+ return framesRendered;
+}
+
+qint64 QDarwinAudioSourceBuffer::readBytes(char *data, qint64 len)
+{
+ bool wecan = true;
+ qint64 bytesCopied = 0;
+
+ len -= len % m_maxPeriodSize;
+ while (wecan && bytesCopied < len) {
+ CoreAudioRingBuffer::Region region = m_buffer->acquireReadRegion(len - bytesCopied);
+
+ if (region.second > 0) {
+ memcpy(data + bytesCopied, region.first, region.second);
+ bytesCopied += region.second;
+ }
+ else
+ wecan = false;
+
+ m_buffer->releaseReadRegion(region);
+ }
+
+ return bytesCopied;
+}
+
+void QDarwinAudioSourceBuffer::setFlushDevice(QIODevice *device)
+{
+ if (m_device != device)
+ m_device = device;
+}
+
+void QDarwinAudioSourceBuffer::startFlushTimer()
+{
+ if (m_device != 0) {
+ // We use the period time for the timer, since that's
+ // around the buffer size (pre conversion >.>)
+ m_flushTimer->start(qMax(1, m_periodTime));
+ }
+}
+
+void QDarwinAudioSourceBuffer::stopFlushTimer()
+{
+ m_flushTimer->stop();
+}
+
+void QDarwinAudioSourceBuffer::flush(bool all)
+{
+ if (m_device == 0)
+ return;
+
+ const int used = m_buffer->used();
+ const int readSize = all ? used : used - (used % m_maxPeriodSize);
+
+ if (readSize > 0) {
+ bool wecan = true;
+ int flushed = 0;
+
+ while (!m_deviceError && wecan && flushed < readSize) {
+ CoreAudioRingBuffer::Region region = m_buffer->acquireReadRegion(readSize - flushed);
+
+ if (region.second > 0) {
+ int bytesWritten = m_device->write(region.first, region.second);
+ if (bytesWritten < 0) {
+ stopFlushTimer();
+ m_deviceError = true;
+ }
+ else {
+ region.second = bytesWritten;
+ flushed += bytesWritten;
+ wecan = bytesWritten != 0;
+ }
+ }
+ else
+ wecan = false;
+
+ m_buffer->releaseReadRegion(region);
+ }
+ }
+}
+
+void QDarwinAudioSourceBuffer::reset()
+{
+ m_buffer->reset();
+ m_deviceError = false;
+}
+
+int QDarwinAudioSourceBuffer::available() const
+{
+ return m_buffer->free();
+}
+
+int QDarwinAudioSourceBuffer::used() const
+{
+ return m_buffer->used();
+}
+
+void QDarwinAudioSourceBuffer::flushBuffer()
+{
+ flush();
+}
+
+OSStatus QDarwinAudioSourceBuffer::converterCallback(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets, AudioBufferList *ioData, AudioStreamPacketDescription **outDataPacketDescription, void *inUserData)
+{
+ Q_UNUSED(inAudioConverter);
+ Q_UNUSED(outDataPacketDescription);
+
+ QCoreAudioPacketFeeder* feeder = static_cast<QCoreAudioPacketFeeder*>(inUserData);
+
+ if (!feeder->feed(*ioData, *ioNumberDataPackets))
+ return as_empty;
+
+ return noErr;
+}
+
+QDarwinAudioSourceDevice::QDarwinAudioSourceDevice(QDarwinAudioSourceBuffer *audioBuffer, QObject *parent)
+ : QIODevice(parent)
+ , m_audioBuffer(audioBuffer)
+{
+ open(QIODevice::ReadOnly | QIODevice::Unbuffered);
+ connect(m_audioBuffer, SIGNAL(readyRead()), this, SIGNAL(readyRead()));
+}
+
+qint64 QDarwinAudioSourceDevice::readData(char *data, qint64 len)
+{
+ return m_audioBuffer->readBytes(data, len);
+}
+
+qint64 QDarwinAudioSourceDevice::writeData(const char *data, qint64 len)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(len);
+
+ return 0;
+}
+
+QDarwinAudioSource::QDarwinAudioSource(const QAudioDevice &device, QObject *parent)
+ : QPlatformAudioSource(parent)
+ , m_audioDeviceInfo(device)
+ , m_isOpen(false)
+ , m_internalBufferSize(DEFAULT_BUFFER_SIZE)
+ , m_totalFrames(0)
+ , m_audioUnit(0)
+ , m_clockFrequency(CoreAudioUtils::frequency() / 1000)
+ , m_errorCode(QAudio::NoError)
+ , m_stateCode(QAudio::StoppedState)
+ , m_audioBuffer(nullptr)
+ , m_volume(1.0)
+{
+ QAudioDevice di = device;
+ if (di.isNull())
+ di = QMediaDevices::defaultAudioInput();
+#if defined(Q_OS_MACOS)
+ const QCoreAudioDeviceInfo *info = static_cast<const QCoreAudioDeviceInfo *>(di.handle());
+ Q_ASSERT(info);
+ m_audioDeviceId = info->deviceID();
+#endif
+ m_device = di.id();
+}
+
+
+QDarwinAudioSource::~QDarwinAudioSource()
+{
+ close();
+}
+
+bool QDarwinAudioSource::open()
+{
+#if defined(Q_OS_IOS)
+ CoreAudioSessionManager::instance().setCategory(CoreAudioSessionManager::PlayAndRecord, CoreAudioSessionManager::MixWithOthers);
+ CoreAudioSessionManager::instance().setActive(true);
+#endif
+
+ if (m_isOpen)
+ return true;
+
+ AudioComponentDescription componentDescription;
+ componentDescription.componentType = kAudioUnitType_Output;
+#if defined(Q_OS_MACOS)
+ componentDescription.componentSubType = kAudioUnitSubType_HALOutput;
+#else
+ componentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
+#endif
+ componentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
+ componentDescription.componentFlags = 0;
+ componentDescription.componentFlagsMask = 0;
+
+ AudioComponent component = AudioComponentFindNext(0, &componentDescription);
+ if (component == 0) {
+ qWarning() << "QAudioSource: Failed to find Output component";
+ return false;
+ }
+
+ if (AudioComponentInstanceNew(component, &m_audioUnit) != noErr) {
+ qWarning() << "QAudioSource: Unable to Open Output Component";
+ return false;
+ }
+
+ // Set mode
+ // switch to input mode
+ UInt32 enable = 1;
+ if (AudioUnitSetProperty(m_audioUnit,
+ kAudioOutputUnitProperty_EnableIO,
+ kAudioUnitScope_Input,
+ 1,
+ &enable,
+ sizeof(enable)) != noErr) {
+ qWarning() << "QAudioSource: Unable to switch to input mode (Enable Input)";
+ return false;
+ }
+
+ enable = 0;
+ if (AudioUnitSetProperty(m_audioUnit,
+ kAudioOutputUnitProperty_EnableIO,
+ kAudioUnitScope_Output,
+ 0,
+ &enable,
+ sizeof(enable)) != noErr) {
+ qWarning() << "QAudioSource: Unable to switch to input mode (Disable output)";
+ return false;
+ }
+
+ // register callback
+ AURenderCallbackStruct callback;
+ callback.inputProc = inputCallback;
+ callback.inputProcRefCon = this;
+
+ if (AudioUnitSetProperty(m_audioUnit,
+ kAudioOutputUnitProperty_SetInputCallback,
+ kAudioUnitScope_Global,
+ 0,
+ &callback,
+ sizeof(callback)) != noErr) {
+ qWarning() << "QAudioSource: Failed to set AudioUnit callback";
+ return false;
+ }
+
+#if defined(Q_OS_MACOS)
+ //Set Audio Device
+ if (AudioUnitSetProperty(m_audioUnit,
+ kAudioOutputUnitProperty_CurrentDevice,
+ kAudioUnitScope_Global,
+ 0,
+ &m_audioDeviceId,
+ sizeof(m_audioDeviceId)) != noErr) {
+ qWarning() << "QAudioSource: Unable to use configured device";
+ return false;
+ }
+#endif
+
+ //set format
+ m_streamFormat = CoreAudioUtils::toAudioStreamBasicDescription(m_audioFormat);
+
+#if defined(Q_OS_MACOS)
+ UInt32 size = 0;
+
+ if (m_audioFormat == m_audioDeviceInfo.preferredFormat()) {
+#endif
+
+ m_deviceFormat = m_streamFormat;
+ AudioUnitSetProperty(m_audioUnit,
+ kAudioUnitProperty_StreamFormat,
+ kAudioUnitScope_Output,
+ 1,
+ &m_deviceFormat,
+ sizeof(m_deviceFormat));
+#if defined(Q_OS_MACOS)
+ } else {
+ size = sizeof(m_deviceFormat);
+ if (AudioUnitGetProperty(m_audioUnit,
+ kAudioUnitProperty_StreamFormat,
+ kAudioUnitScope_Input,
+ 1,
+ &m_deviceFormat,
+ &size) != noErr) {
+ qWarning() << "QAudioSource: Unable to retrieve device format";
+ return false;
+ }
+
+ if (AudioUnitSetProperty(m_audioUnit,
+ kAudioUnitProperty_StreamFormat,
+ kAudioUnitScope_Output,
+ 1,
+ &m_deviceFormat,
+ sizeof(m_deviceFormat)) != noErr) {
+ qWarning() << "QAudioSource: Unable to set device format";
+ return false;
+ }
+ }
+#endif
+
+ //setup buffers
+ UInt32 numberOfFrames;
+#if defined(Q_OS_MACOS)
+ size = sizeof(UInt32);
+ if (AudioUnitGetProperty(m_audioUnit,
+ kAudioDevicePropertyBufferFrameSize,
+ kAudioUnitScope_Global,
+ 0,
+ &numberOfFrames,
+ &size) != noErr) {
+ qWarning() << "QAudioSource: Failed to get audio period size";
+ return false;
+ }
+ //BUG: numberOfFrames gets ignored after this point
+
+ AudioValueRange bufferRange;
+ size = sizeof(AudioValueRange);
+
+ if (AudioUnitGetProperty(m_audioUnit,
+ kAudioDevicePropertyBufferFrameSizeRange,
+ kAudioUnitScope_Global,
+ 0,
+ &bufferRange,
+ &size) != noErr) {
+ qWarning() << "QAudioSource: Failed to get audio period size range";
+ return false;
+ }
+
+ // See if the requested buffer size is permissible
+ numberOfFrames = qBound((UInt32)bufferRange.mMinimum, m_internalBufferSize / m_streamFormat.mBytesPerFrame, (UInt32)bufferRange.mMaximum);
+
+ // Set it back
+ if (AudioUnitSetProperty(m_audioUnit,
+ kAudioDevicePropertyBufferFrameSize,
+ kAudioUnitScope_Global,
+ 0,
+ &numberOfFrames,
+ sizeof(UInt32)) != noErr) {
+ qWarning() << "QAudioSource: Failed to set audio buffer size";
+ return false;
+ }
+#else //iOS
+ Float32 bufferSize = CoreAudioSessionManager::instance().currentIOBufferDuration();
+ bufferSize *= m_streamFormat.mSampleRate;
+ numberOfFrames = bufferSize;
+#endif
+
+ // Now allocate a few buffers to be safe.
+ m_periodSizeBytes = m_internalBufferSize = numberOfFrames * m_streamFormat.mBytesPerFrame;
+
+ {
+ QMutexLocker lock(m_audioBuffer);
+ m_audioBuffer = new QDarwinAudioSourceBuffer(m_internalBufferSize * 4,
+ m_periodSizeBytes,
+ m_deviceFormat,
+ m_streamFormat,
+ this);
+
+ m_audioBuffer->setVolume(m_volume);
+ }
+ m_audioIO = new QDarwinAudioSourceDevice(m_audioBuffer, this);
+
+ // Init
+ if (AudioUnitInitialize(m_audioUnit) != noErr) {
+ qWarning() << "QAudioSource: Failed to initialize AudioUnit";
+ return false;
+ }
+
+ m_isOpen = true;
+
+ return m_isOpen;
+
+}
+
+void QDarwinAudioSource::close()
+{
+ stop();
+ if (m_audioUnit != 0) {
+ AudioOutputUnitStop(m_audioUnit);
+ AudioUnitUninitialize(m_audioUnit);
+ AudioComponentInstanceDispose(m_audioUnit);
+ }
+
+ delete m_audioBuffer;
+ m_audioBuffer = nullptr;
+ m_isOpen = false;
+}
+
+void QDarwinAudioSource::start(QIODevice *device)
+{
+ QIODevice* op = device;
+
+ if (!m_audioDeviceInfo.isFormatSupported(m_audioFormat) || !open()) {
+ m_stateCode = QAudio::StoppedState;
+ m_errorCode = QAudio::OpenError;
+ return;
+ }
+
+ reset();
+ {
+ QMutexLocker lock(m_audioBuffer);
+ m_audioBuffer->reset();
+ m_audioBuffer->setFlushDevice(op);
+ }
+
+ if (op == 0)
+ op = m_audioIO;
+
+ // Start
+ m_totalFrames = 0;
+
+ m_stateCode = QAudio::IdleState;
+ m_errorCode = QAudio::NoError;
+ emit stateChanged(m_stateCode);
+
+ audioThreadStart();
+}
+
+
+QIODevice *QDarwinAudioSource::start()
+{
+ QIODevice* op = 0;
+
+ if (!m_audioDeviceInfo.isFormatSupported(m_audioFormat) || !open()) {
+ m_stateCode = QAudio::StoppedState;
+ m_errorCode = QAudio::OpenError;
+ return m_audioIO;
+ }
+
+ reset();
+ {
+ QMutexLocker lock(m_audioBuffer);
+ m_audioBuffer->reset();
+ m_audioBuffer->setFlushDevice(op);
+ }
+
+ if (op == 0)
+ op = m_audioIO;
+
+ // Start
+ m_totalFrames = 0;
+
+ m_stateCode = QAudio::IdleState;
+ m_errorCode = QAudio::NoError;
+ emit stateChanged(m_stateCode);
+
+ audioThreadStart();
+
+ return op;
+}
+
+
+void QDarwinAudioSource::stop()
+{
+ QMutexLocker lock(m_audioBuffer);
+ if (m_stateCode != QAudio::StoppedState) {
+ audioThreadStop();
+ m_audioBuffer->flush(true);
+
+ m_errorCode = QAudio::NoError;
+ m_stateCode = QAudio::StoppedState;
+ QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, m_stateCode));
+ }
+}
+
+
+void QDarwinAudioSource::reset()
+{
+ QMutexLocker lock(m_audioBuffer);
+ if (m_stateCode != QAudio::StoppedState) {
+ audioThreadStop();
+
+ m_errorCode = QAudio::NoError;
+ m_stateCode = QAudio::StoppedState;
+ m_audioBuffer->reset();
+ QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, m_stateCode));
+ }
+}
+
+
+void QDarwinAudioSource::suspend()
+{
+ QMutexLocker lock(m_audioBuffer);
+ if (m_stateCode == QAudio::ActiveState || m_stateCode == QAudio::IdleState) {
+ audioThreadStop();
+
+ m_errorCode = QAudio::NoError;
+ m_stateCode = QAudio::SuspendedState;
+ QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, m_stateCode));
+ }
+}
+
+
+void QDarwinAudioSource::resume()
+{
+ QMutexLocker lock(m_audioBuffer);
+ if (m_stateCode == QAudio::SuspendedState) {
+ audioThreadStart();
+
+ m_errorCode = QAudio::NoError;
+ m_stateCode = QAudio::ActiveState;
+ QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, m_stateCode));
+ }
+}
+
+
+qsizetype QDarwinAudioSource::bytesReady() const
+{
+ QMutexLocker lock(m_audioBuffer);
+ if (!m_audioBuffer)
+ return 0;
+ return m_audioBuffer->used();
+}
+
+void QDarwinAudioSource::setBufferSize(qsizetype value)
+{
+ m_internalBufferSize = value;
+}
+
+
+qsizetype QDarwinAudioSource::bufferSize() const
+{
+ return m_internalBufferSize;
+}
+
+qint64 QDarwinAudioSource::processedUSecs() const
+{
+ return m_totalFrames * 1000000 / m_audioFormat.sampleRate();
+}
+
+QAudio::Error QDarwinAudioSource::error() const
+{
+ return m_errorCode;
+}
+
+
+QAudio::State QDarwinAudioSource::state() const
+{
+ return m_stateCode;
+}
+
+
+void QDarwinAudioSource::setFormat(const QAudioFormat &format)
+{
+ if (m_stateCode == QAudio::StoppedState)
+ m_audioFormat = format;
+}
+
+
+QAudioFormat QDarwinAudioSource::format() const
+{
+ return m_audioFormat;
+}
+
+
+void QDarwinAudioSource::setVolume(qreal volume)
+{
+ QMutexLocker lock(m_audioBuffer);
+ m_volume = volume;
+ if (m_audioBuffer)
+ m_audioBuffer->setVolume(m_volume);
+}
+
+
+qreal QDarwinAudioSource::volume() const
+{
+ return m_volume;
+}
+
+void QDarwinAudioSource::deviceStoppped()
+{
+ stopTimers();
+ emit stateChanged(m_stateCode);
+}
+
+void QDarwinAudioSource::audioThreadStart()
+{
+ startTimers();
+ m_audioThreadState.storeRelaxed(Running);
+ AudioOutputUnitStart(m_audioUnit);
+}
+
+void QDarwinAudioSource::audioThreadStop()
+{
+ stopTimers();
+ if (m_audioThreadState.testAndSetAcquire(Running, Stopped))
+ m_audioBuffer->wait();
+}
+
+void QDarwinAudioSource::audioDeviceStop()
+{
+ AudioOutputUnitStop(m_audioUnit);
+ m_audioThreadState.storeRelaxed(Stopped);
+ m_audioBuffer->wake();
+}
+
+void QDarwinAudioSource::audioDeviceActive()
+{
+ if (m_stateCode == QAudio::IdleState) {
+ QMutexLocker lock(m_audioBuffer);
+ m_stateCode = QAudio::ActiveState;
+ emit stateChanged(m_stateCode);
+ }
+}
+
+void QDarwinAudioSource::audioDeviceFull()
+{
+ if (m_stateCode == QAudio::ActiveState) {
+ QMutexLocker lock(m_audioBuffer);
+ m_errorCode = QAudio::UnderrunError;
+ m_stateCode = QAudio::IdleState;
+ emit stateChanged(m_stateCode);
+ }
+}
+
+void QDarwinAudioSource::audioDeviceError()
+{
+ if (m_stateCode == QAudio::ActiveState) {
+ QMutexLocker lock(m_audioBuffer);
+ audioDeviceStop();
+
+ m_errorCode = QAudio::IOError;
+ m_stateCode = QAudio::StoppedState;
+ QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection);
+ }
+}
+
+void QDarwinAudioSource::startTimers()
+{
+ m_audioBuffer->startFlushTimer();
+}
+
+void QDarwinAudioSource::stopTimers()
+{
+ m_audioBuffer->stopFlushTimer();
+}
+
+OSStatus QDarwinAudioSource::inputCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
+{
+ Q_UNUSED(ioData);
+
+ QDarwinAudioSource* d = static_cast<QDarwinAudioSource*>(inRefCon);
+
+ const int threadState = d->m_audioThreadState.loadAcquire();
+ if (threadState == Stopped)
+ d->audioDeviceStop();
+ else {
+ qint64 framesWritten;
+
+ {
+ QMutexLocker locker(d->m_audioBuffer);
+ framesWritten = d->m_audioBuffer->renderFromDevice(d->m_audioUnit,
+ ioActionFlags,
+ inTimeStamp,
+ inBusNumber,
+ inNumberFrames);
+ }
+
+ if (framesWritten > 0) {
+ d->m_totalFrames += framesWritten;
+ d->audioDeviceActive();
+ } else if (framesWritten == 0)
+ d->audioDeviceFull();
+ else if (framesWritten < 0)
+ d->audioDeviceError();
+ }
+
+ return noErr;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qdarwinaudiosource_p.cpp"
diff --git a/src/multimedia/darwin/qdarwinaudiosource_p.h b/src/multimedia/darwin/qdarwinaudiosource_p.h
new file mode 100644
index 000000000..87c3c1070
--- /dev/null
+++ b/src/multimedia/darwin/qdarwinaudiosource_p.h
@@ -0,0 +1,244 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef IOSAUDIOINPUT_H
+#define IOSAUDIOINPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qaudiosystem_p.h>
+#include <qdarwinaudiodevice_p.h>
+
+#include <AudioUnit/AudioUnit.h>
+#include <CoreAudio/CoreAudioTypes.h>
+#include <AudioToolbox/AudioToolbox.h>
+
+#include <QtCore/QIODevice>
+#include <QtCore/QWaitCondition>
+#include <QtCore/QMutex>
+#include <QtCore/QTimer>
+
+QT_BEGIN_NAMESPACE
+
+class CoreAudioRingBuffer;
+class QCoreAudioPacketFeeder;
+class QDarwinAudioSourceBuffer;
+class QDarwinAudioSourceDevice;
+
+class QCoreAudioBufferList
+{
+public:
+ QCoreAudioBufferList(AudioStreamBasicDescription const& streamFormat);
+ QCoreAudioBufferList(AudioStreamBasicDescription const& streamFormat, char *buffer, int bufferSize);
+ QCoreAudioBufferList(AudioStreamBasicDescription const& streamFormat, int framesToBuffer);
+
+ ~QCoreAudioBufferList();
+
+ AudioBufferList* audioBufferList() const { return m_bufferList; }
+ char *data(int buffer = 0) const;
+ qint64 bufferSize(int buffer = 0) const;
+ int frameCount(int buffer = 0) const;
+ int packetCount(int buffer = 0) const;
+ int packetSize() const;
+ void reset();
+
+private:
+ bool m_owner;
+ int m_dataSize;
+ AudioStreamBasicDescription m_streamDescription;
+ AudioBufferList *m_bufferList;
+};
+
+class QCoreAudioPacketFeeder
+{
+public:
+ QCoreAudioPacketFeeder(QCoreAudioBufferList *abl);
+
+ bool feed(AudioBufferList& dst, UInt32& packetCount);
+ bool empty() const;
+
+private:
+ UInt32 m_totalPackets;
+ UInt32 m_position;
+ QCoreAudioBufferList *m_audioBufferList;
+};
+
+class QDarwinAudioSourceBuffer : public QObject
+{
+ Q_OBJECT
+
+public:
+ QDarwinAudioSourceBuffer(int bufferSize,
+ int maxPeriodSize,
+ AudioStreamBasicDescription const& inputFormat,
+ AudioStreamBasicDescription const& outputFormat,
+ QObject *parent);
+
+ ~QDarwinAudioSourceBuffer();
+
+ qreal volume() const;
+ void setVolume(qreal v);
+
+ qint64 renderFromDevice(AudioUnit audioUnit,
+ AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp,
+ UInt32 inBusNumber,
+ UInt32 inNumberFrames);
+
+ qint64 readBytes(char *data, qint64 len);
+
+ void setFlushDevice(QIODevice *device);
+
+ void startFlushTimer();
+ void stopFlushTimer();
+
+ void flush(bool all = false);
+ void reset();
+ int available() const;
+ int used() const;
+
+ void lock() { m_mutex.lock(); }
+ void unlock() { m_mutex.unlock(); }
+
+ void wait() { m_threadFinished.wait(&m_mutex); }
+ void wake() { m_threadFinished.wakeOne(); }
+
+signals:
+ void readyRead();
+
+private slots:
+ void flushBuffer();
+
+private:
+ QMutex m_mutex;
+ QWaitCondition m_threadFinished;
+
+ bool m_deviceError;
+ int m_maxPeriodSize;
+ int m_periodTime;
+ QIODevice *m_device;
+ QTimer *m_flushTimer;
+ CoreAudioRingBuffer *m_buffer;
+ QCoreAudioBufferList *m_inputBufferList;
+ AudioConverterRef m_audioConverter;
+ AudioStreamBasicDescription m_inputFormat;
+ AudioStreamBasicDescription m_outputFormat;
+ QAudioFormat m_qFormat;
+ qreal m_volume;
+
+ const static OSStatus as_empty = 'qtem';
+
+ // Converter callback
+ static OSStatus converterCallback(AudioConverterRef inAudioConverter,
+ UInt32 *ioNumberDataPackets,
+ AudioBufferList *ioData,
+ AudioStreamPacketDescription **outDataPacketDescription,
+ void *inUserData);
+};
+
+class QDarwinAudioSourceDevice : public QIODevice
+{
+ Q_OBJECT
+
+public:
+ QDarwinAudioSourceDevice(QDarwinAudioSourceBuffer *audioBuffer, QObject *parent);
+
+ qint64 readData(char *data, qint64 len);
+ qint64 writeData(const char *data, qint64 len);
+
+ bool isSequential() const { return true; }
+
+private:
+ QDarwinAudioSourceBuffer *m_audioBuffer;
+};
+
+class QDarwinAudioSource : public QPlatformAudioSource
+{
+ Q_OBJECT
+
+public:
+ QDarwinAudioSource(const QAudioDevice &device, QObject *parent);
+ ~QDarwinAudioSource();
+
+ void start(QIODevice *device);
+ QIODevice *start();
+ void stop();
+ void reset();
+ void suspend();
+ void resume();
+ qsizetype bytesReady() const;
+ void setBufferSize(qsizetype value);
+ qsizetype bufferSize() const;
+ qint64 processedUSecs() const;
+ QAudio::Error error() const;
+ QAudio::State state() const;
+ void setFormat(const QAudioFormat &format);
+ QAudioFormat format() const;
+
+ void setVolume(qreal volume);
+ qreal volume() const;
+
+private slots:
+ void deviceStoppped();
+
+private:
+ enum {
+ Running,
+ Stopped
+ };
+
+ bool open();
+ void close();
+
+ void audioThreadStart();
+ void audioThreadStop();
+
+ void audioDeviceStop();
+ void audioDeviceActive();
+ void audioDeviceFull();
+ void audioDeviceError();
+
+ void startTimers();
+ void stopTimers();
+
+ // Input callback
+ static OSStatus inputCallback(void *inRefCon,
+ AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp,
+ UInt32 inBusNumber,
+ UInt32 inNumberFrames,
+ AudioBufferList *ioData);
+
+ QAudioDevice m_audioDeviceInfo;
+ QByteArray m_device;
+ bool m_isOpen;
+ int m_periodSizeBytes;
+ int m_internalBufferSize;
+ qint64 m_totalFrames;
+ QAudioFormat m_audioFormat;
+ QIODevice *m_audioIO;
+ AudioUnit m_audioUnit;
+#if defined(Q_OS_MACOS)
+ AudioDeviceID m_audioDeviceId;
+#endif
+ Float64 m_clockFrequency;
+ QAudio::Error m_errorCode;
+ QAudio::State m_stateCode;
+ QDarwinAudioSourceBuffer *m_audioBuffer;
+ QAtomicInt m_audioThreadState;
+ AudioStreamBasicDescription m_streamFormat;
+ AudioStreamBasicDescription m_deviceFormat;
+ qreal m_volume;
+};
+
+QT_END_NAMESPACE
+
+#endif // IOSAUDIOINPUT_H
diff --git a/src/multimedia/darwin/qdarwinmediadevices.mm b/src/multimedia/darwin/qdarwinmediadevices.mm
new file mode 100644
index 000000000..b0a108935
--- /dev/null
+++ b/src/multimedia/darwin/qdarwinmediadevices.mm
@@ -0,0 +1,269 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qdarwinmediadevices_p.h"
+#include "qmediadevices.h"
+#include "private/qaudiodevice_p.h"
+#include "qdarwinaudiodevice_p.h"
+#include "qdarwinaudiosource_p.h"
+#include "qdarwinaudiosink_p.h"
+
+#include <qloggingcategory.h>
+
+#include <qdebug.h>
+
+#if defined(Q_OS_IOS)
+#include "qcoreaudiosessionmanager_p.h"
+#import <AVFoundation/AVFoundation.h>
+#else
+#include "qmacosaudiodatautils_p.h"
+#endif
+
+#if defined(Q_OS_MACOS)
+static Q_LOGGING_CATEGORY(qLcDarwinMediaDevices, "qt.multimedia.darwin.mediaDevices")
+#endif
+
+QT_BEGIN_NAMESPACE
+
+template<typename... Args>
+QAudioDevice createAudioDevice(bool isDefault, Args &&...args)
+{
+ auto *dev = new QCoreAudioDeviceInfo(std::forward<Args>(args)...);
+ dev->isDefault = isDefault;
+ return dev->create();
+}
+
+#if defined(Q_OS_MACOS)
+
+static AudioDeviceID defaultAudioDevice(QAudioDevice::Mode mode)
+{
+ const AudioObjectPropertySelector selector = (mode == QAudioDevice::Output) ? kAudioHardwarePropertyDefaultOutputDevice
+ : kAudioHardwarePropertyDefaultInputDevice;
+ const AudioObjectPropertyAddress propertyAddress = {
+ selector,
+ kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMain,
+ };
+
+ if (auto audioDevice = getAudioObject<AudioDeviceID>(kAudioObjectSystemObject, propertyAddress,
+ "Default Device")) {
+ return *audioDevice;
+ }
+
+ return 0;
+}
+
+static QByteArray uniqueId(AudioDeviceID device, QAudioDevice::Mode mode)
+{
+ const AudioObjectPropertyAddress propertyAddress =
+ makePropertyAddress(kAudioDevicePropertyDeviceUID, mode);
+
+ if (auto name = getAudioObject<CFStringRef>(device, propertyAddress, "Device UID")) {
+ QString s = QString::fromCFString(*name);
+ CFRelease(*name);
+ return s.toUtf8();
+ }
+
+ return QByteArray();
+}
+
+static QList<QAudioDevice> availableAudioDevices(QAudioDevice::Mode mode)
+{
+ QList<QAudioDevice> devices;
+
+ AudioDeviceID defaultDevice = defaultAudioDevice(mode);
+ if (defaultDevice != 0)
+ devices << createAudioDevice(true, defaultDevice, uniqueId(defaultDevice, mode), mode);
+
+ const AudioObjectPropertyAddress audioDevicesPropertyAddress = {
+ kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMain
+ };
+
+ if (auto audioDevices = getAudioData<AudioDeviceID>(
+ kAudioObjectSystemObject, audioDevicesPropertyAddress, "Audio Devices")) {
+ const AudioObjectPropertyAddress audioDeviceStreamFormatPropertyAddress =
+ makePropertyAddress(kAudioDevicePropertyStreamFormat, mode);
+
+ for (const auto &device : *audioDevices) {
+ if (device == defaultDevice)
+ continue;
+
+ if (getAudioObject<AudioStreamBasicDescription>(device,
+ audioDeviceStreamFormatPropertyAddress,
+ nullptr /*don't print logs*/)) {
+ devices << createAudioDevice(false, device, uniqueId(device, mode), mode);
+ }
+ }
+ }
+
+ return devices;
+}
+
+static OSStatus audioDeviceChangeListener(AudioObjectID id, UInt32,
+ const AudioObjectPropertyAddress *address, void *ptr)
+{
+ Q_ASSERT(address);
+ Q_ASSERT(ptr);
+
+ QDarwinMediaDevices *instance = static_cast<QDarwinMediaDevices *>(ptr);
+
+ qCDebug(qLcDarwinMediaDevices)
+ << "audioDeviceChangeListener: id:" << id << "address: " << address->mSelector
+ << address->mScope << address->mElement;
+
+ switch (address->mSelector) {
+ case kAudioHardwarePropertyDefaultInputDevice:
+ instance->onInputsUpdated();
+ break;
+ case kAudioHardwarePropertyDefaultOutputDevice:
+ instance->onOutputsUpdated();
+ break;
+ default:
+ instance->onInputsUpdated();
+ instance->onOutputsUpdated();
+ break;
+ }
+
+ return 0;
+}
+
+static constexpr AudioObjectPropertyAddress listenerAddresses[] = {
+ { kAudioHardwarePropertyDefaultInputDevice, kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMain },
+ { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMain },
+ { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMain }
+};
+
+static void setAudioListeners(QDarwinMediaDevices &instance)
+{
+ for (const auto &address : listenerAddresses) {
+ const auto err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &address,
+ audioDeviceChangeListener, &instance);
+
+ if (err)
+ qWarning() << "Fail to add listener. mSelector:" << address.mSelector
+ << "mScope:" << address.mScope << "mElement:" << address.mElement
+ << "err:" << err;
+ }
+}
+
+static void removeAudioListeners(QDarwinMediaDevices &instance)
+{
+ for (const auto &address : listenerAddresses) {
+ const auto err = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &address,
+ audioDeviceChangeListener, &instance);
+
+ if (err)
+ qWarning() << "Fail to remove listener. mSelector:" << address.mSelector
+ << "mScope:" << address.mScope << "mElement:" << address.mElement
+ << "err:" << err;
+ }
+}
+
+#elif defined(Q_OS_IOS)
+
+static QList<QAudioDevice> availableAudioDevices(QAudioDevice::Mode mode)
+{
+ QList<QAudioDevice> devices;
+
+ if (mode == QAudioDevice::Output) {
+ devices.append(createAudioDevice(true, "default", QAudioDevice::Output));
+ } else {
+ AVCaptureDevice *defaultDevice =
+ [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
+
+ // TODO: Support Bluetooth and USB devices
+ AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
+ [AVCaptureDeviceDiscoverySession
+ discoverySessionWithDeviceTypes:@[ AVCaptureDeviceTypeBuiltInMicrophone ]
+ mediaType:AVMediaTypeAudio
+ position:AVCaptureDevicePositionUnspecified];
+
+ NSArray *captureDevices = [captureDeviceDiscoverySession devices];
+ for (AVCaptureDevice *device in captureDevices) {
+ const bool isDefault =
+ defaultDevice && [defaultDevice.uniqueID isEqualToString:device.uniqueID];
+ devices.append(createAudioDevice(isDefault,
+ QString::fromNSString(device.uniqueID).toUtf8(),
+ QAudioDevice::Input));
+ }
+ }
+
+ return devices;
+}
+
+static void setAudioListeners(QDarwinMediaDevices &)
+{
+ // ### This should use the audio session manager
+}
+
+static void removeAudioListeners(QDarwinMediaDevices &)
+{
+ // ### This should use the audio session manager
+}
+
+#endif
+
+
+QDarwinMediaDevices::QDarwinMediaDevices()
+ : QPlatformMediaDevices()
+{
+#ifdef Q_OS_MACOS // TODO: implement setAudioListeners, removeAudioListeners for Q_OS_IOS, after
+ // that - remove or modify the define
+ m_cachedAudioInputs = availableAudioDevices(QAudioDevice::Input);
+ m_cachedAudioOutputs = availableAudioDevices(QAudioDevice::Output);
+#endif
+
+ setAudioListeners(*this);
+}
+
+
+QDarwinMediaDevices::~QDarwinMediaDevices()
+{
+ removeAudioListeners(*this);
+}
+
+QList<QAudioDevice> QDarwinMediaDevices::audioInputs() const
+{
+ return availableAudioDevices(QAudioDevice::Input);
+}
+
+QList<QAudioDevice> QDarwinMediaDevices::audioOutputs() const
+{
+ return availableAudioDevices(QAudioDevice::Output);
+}
+
+void QDarwinMediaDevices::onInputsUpdated()
+{
+ auto inputs = availableAudioDevices(QAudioDevice::Input);
+ if (m_cachedAudioInputs != inputs) {
+ m_cachedAudioInputs = inputs;
+ emit audioInputsChanged();
+ }
+}
+
+void QDarwinMediaDevices::onOutputsUpdated()
+{
+ auto outputs = availableAudioDevices(QAudioDevice::Output);
+ if (m_cachedAudioOutputs != outputs) {
+ m_cachedAudioOutputs = outputs;
+ emit audioOutputsChanged();
+ }
+}
+
+QPlatformAudioSource *QDarwinMediaDevices::createAudioSource(const QAudioDevice &info,
+ QObject *parent)
+{
+ return new QDarwinAudioSource(info, parent);
+}
+
+QPlatformAudioSink *QDarwinMediaDevices::createAudioSink(const QAudioDevice &info,
+ QObject *parent)
+{
+ return new QDarwinAudioSink(info, parent);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/darwin/qdarwinmediadevices_p.h b/src/multimedia/darwin/qdarwinmediadevices_p.h
new file mode 100644
index 000000000..0c7a45433
--- /dev/null
+++ b/src/multimedia/darwin/qdarwinmediadevices_p.h
@@ -0,0 +1,49 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QDARWINMEDIADEVICES_H
+#define QDARWINMEDIADEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediadevices_p.h>
+#include <qelapsedtimer.h>
+#include <qcameradevice.h>
+
+QT_BEGIN_NAMESPACE
+
+class QCameraDevice;
+
+class QDarwinMediaDevices : public QPlatformMediaDevices
+{
+public:
+ QDarwinMediaDevices();
+ ~QDarwinMediaDevices() override;
+
+ QList<QAudioDevice> audioInputs() const override;
+ QList<QAudioDevice> audioOutputs() const override;
+ QPlatformAudioSource *createAudioSource(const QAudioDevice &info,
+ QObject *parent) override;
+ QPlatformAudioSink *createAudioSink(const QAudioDevice &info,
+ QObject *parent) override;
+
+ void onInputsUpdated();
+ void onOutputsUpdated();
+
+private:
+ QList<QAudioDevice> m_cachedAudioInputs;
+ QList<QAudioDevice> m_cachedAudioOutputs;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/darwin/qmacosaudiodatautils_p.h b/src/multimedia/darwin/qmacosaudiodatautils_p.h
new file mode 100644
index 000000000..8cc2f8440
--- /dev/null
+++ b/src/multimedia/darwin/qmacosaudiodatautils_p.h
@@ -0,0 +1,112 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QMACOSAUDIODATAUTILS_P_H
+#define QMACOSAUDIODATAUTILS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <CoreAudio/AudioHardware.h>
+
+#include "qaudiodevice.h"
+#include "qdebug.h"
+
+#include <optional>
+#include <vector>
+#include <algorithm>
+
+QT_BEGIN_NAMESPACE
+
+template<typename... Args>
+void printUnableToReadWarning(const char *logName, AudioObjectID objectID, const AudioObjectPropertyAddress &address, Args &&...args)
+{
+ if (!logName)
+ return;
+
+ char scope[5] = {0};
+ memcpy(&scope, &address.mScope, 4);
+ std::reverse(scope, scope + 4);
+
+ auto warn = qWarning();
+ warn << "Unable to read property" << logName << "for object" << objectID << ", scope" << scope << ";";
+ (warn << ... << args);
+ warn << "\n If the warning is unexpected use test_audio_config to get comprehensive audio info and report a bug";
+}
+
+inline static AudioObjectPropertyAddress
+makePropertyAddress(AudioObjectPropertySelector selector, QAudioDevice::Mode mode,
+ AudioObjectPropertyElement element = kAudioObjectPropertyElementMain)
+{
+ return { selector,
+ mode == QAudioDevice::Input ? kAudioDevicePropertyScopeInput
+ : kAudioDevicePropertyScopeOutput,
+ element };
+}
+
+inline static bool getAudioData(AudioObjectID objectID, const AudioObjectPropertyAddress &address,
+ void *dst, UInt32 dstSize, const char *logName)
+{
+ UInt32 readBytes = dstSize;
+ const auto res = AudioObjectGetPropertyData(objectID, &address, 0, nullptr, &readBytes, dst);
+
+ if (res != noErr)
+ printUnableToReadWarning(logName, objectID, address, "Err:", res);
+ else if (readBytes != dstSize)
+ printUnableToReadWarning(logName, objectID, address, "Data size", readBytes, "VS", dstSize,
+ "expected");
+ else
+ return true;
+
+ return false;
+}
+
+template<typename T>
+std::optional<std::vector<T>> getAudioData(AudioObjectID objectID,
+ const AudioObjectPropertyAddress &address,
+ const char *logName, size_t minDataSize = 0)
+{
+ static_assert(std::is_trivial_v<T>, "A trivial type is expected");
+
+ UInt32 size = 0;
+ const auto res = AudioObjectGetPropertyDataSize(objectID, &address, 0, nullptr, &size);
+
+ if (res != noErr) {
+ printUnableToReadWarning(logName, objectID, address,
+ "AudioObjectGetPropertyDataSize failed, Err:", res);
+ } else if (size / sizeof(T) < minDataSize) {
+ printUnableToReadWarning(logName, objectID, address, "Data size is too small:", size, "VS",
+ minDataSize * sizeof(T), "bytes");
+ } else {
+ std::vector<T> data(size / sizeof(T));
+ if (getAudioData(objectID, address, data.data(), data.size() * sizeof(T), logName))
+ return { std::move(data) };
+ }
+
+ return {};
+}
+
+template<typename T>
+std::optional<T> getAudioObject(AudioObjectID objectID, const AudioObjectPropertyAddress &address,
+ const char *logName)
+{
+ static_assert(std::is_trivial_v<T>, "A trivial type is expected");
+
+ T object{};
+ if (getAudioData(objectID, address, &object, sizeof(T), logName))
+ return { object };
+
+ return {};
+}
+
+QT_END_NAMESPACE
+
+#endif // QMACOSAUDIODATAUTILS_P_H
diff --git a/src/multimedia/doc/qtmultimedia.qdocconf b/src/multimedia/doc/qtmultimedia.qdocconf
index dfafd8715..97e6dc696 100644
--- a/src/multimedia/doc/qtmultimedia.qdocconf
+++ b/src/multimedia/doc/qtmultimedia.qdocconf
@@ -6,7 +6,9 @@ description = Qt Multimedia Documentation
version = $QT_VERSION
moduleheader = QtMultimediaDoc
-includepaths = -I .
+includepaths += .
+
+examplesinstallpath = multimedia
# The following parameters are for creating a qhp file, the qhelpgenerator
# program can convert the qhp file into a qch file which can be opened in
@@ -36,7 +38,7 @@ qhp.QtMultimedia.subprojects.widgetclasses.sortPages = true
qhp.QtMultimedia.subprojects.qmltypes.title = QML Types
qhp.QtMultimedia.subprojects.qmltypes.indexTitle = Qt Multimedia QML Types
-qhp.QtMultimedia.subprojects.qmltypes.selectors = qmlclass
+qhp.QtMultimedia.subprojects.qmltypes.selectors = qmltype
qhp.QtMultimedia.subprojects.qmltypes.sortPages = true
qhp.QtMultimedia.subprojects.examples.title = Examples
@@ -44,23 +46,37 @@ qhp.QtMultimedia.subprojects.examples.indexTitle = Qt Multimedia Examples
qhp.QtMultimedia.subprojects.examples.selectors = doc:example
qhp.QtMultimedia.subprojects.examples.sortPages = true
-exampledirs += ../../../examples \
+exampledirs += ../../../examples/multimedia \
+ ../../../examples/multimediawidgets \
snippets \
../../multimediawidgets/doc/snippets
-manifestmeta.highlighted.names = "QtMultimedia/QML Video Shader Effects Example" \
- "QtMultimedia/Media Player Example"
-
-headerdirs += ../..
+headerdirs += .. \
+ ../../multimediawidgets \
+ ../../multimediaquick
imagedirs += src/images \
-sourcedirs += ../..
+sourcedirs += .. \
+ ../../multimediawidgets \
+ ../../multimediaquick
-excludedirs += ../../gsttools
+depends += qtcore qtdoc qtgui qtquick qtqml qtwidgets qtnetwork qmake qtcmake qtquickcontrols qtspatialaudio
-depends += qtcore qtdoc qtgui qtquick qtqml qtwidgets qtnetwork
+# Ignore \since commands for versions earlier than 6.3
+ignoresince = 6.3
navigation.landingpage = "Qt Multimedia"
navigation.cppclassespage = "Qt Multimedia C++ Classes"
navigation.qmltypespage = "Qt Multimedia QML Types"
+
+# Highlighted examples in Graphics & Multimedia category
+manifestmeta.highlighted.names = \
+ "QtMultimedia/Screen Capture Example" \
+ "QtMultimedia/QML Video Recorder"
+
+# Highlighted examples in Mobile category
+manifestmeta.highlighted.names += "QtMultimedia/QML Camera Application"
+
+# Fail the documentation build if there are more warnings than the limit
+warninglimit = 0
diff --git a/src/multimedia/doc/snippets/CMakeLists.txt b/src/multimedia/doc/snippets/CMakeLists.txt
new file mode 100644
index 000000000..c3937477b
--- /dev/null
+++ b/src/multimedia/doc/snippets/CMakeLists.txt
@@ -0,0 +1,15 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+project(multimedia_cppsnippets)
+
+add_executable(mytarget
+ multimedia-snippets/media.cpp
+)
+
+# ![0]
+find_package(Qt6 REQUIRED COMPONENTS Multimedia)
+target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
+# ![0]
diff --git a/src/multimedia/doc/snippets/doc_src_qtmultimedia.cpp b/src/multimedia/doc/snippets/doc_src_qtmultimedia.cpp
deleted file mode 100644
index a56283474..000000000
--- a/src/multimedia/doc/snippets/doc_src_qtmultimedia.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [0]
-#include <QtMultimedia>
-//! [0]
diff --git a/src/multimedia/doc/snippets/doc_src_qtmultimedia.pro b/src/multimedia/doc/snippets/doc_src_qtmultimedia.pro
deleted file mode 100644
index 13da13011..000000000
--- a/src/multimedia/doc/snippets/doc_src_qtmultimedia.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-#! [0]
-QT += multimedia
-#! [0]
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp b/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp
index 57d3adfb4..565f7b29b 100644
--- a/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp
+++ b/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp
@@ -1,53 +1,19 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/* Audio related snippets */
#include <QFile>
#include <QTimer>
#include <QDebug>
+#include <qobject.h>
+#include <qfile.h>
-#include "qaudiodeviceinfo.h"
-#include "qaudioinput.h"
+#include "qaudiodevice.h"
+#include "qaudiosource.h"
#include "qaudiooutput.h"
-#include "qaudioprobe.h"
#include "qaudiodecoder.h"
#include "qmediaplayer.h"
+#include "qmediadevices.h"
class AudioInputExample : public QObject {
Q_OBJECT
@@ -62,7 +28,7 @@ public Q_SLOTS:
private:
//! [Audio input class members]
QFile destinationFile; // Class member
- QAudioInput* audio; // Class member
+ QAudioSource* audio; // Class member
//! [Audio input class members]
};
@@ -77,21 +43,17 @@ void AudioInputExample::setup()
// Set up the desired format, for example:
format.setSampleRate(8000);
format.setChannelCount(1);
- format.setSampleSize(8);
- format.setCodec("audio/pcm");
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::UnSignedInt);
+ format.setSampleFormat(QAudioFormat::UInt8);
- QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
+ QAudioDevice info = QMediaDevices::defaultAudioInput();
if (!info.isFormatSupported(format)) {
qWarning() << "Default format not supported, trying to use the nearest.";
- format = info.nearestFormat(format);
}
- audio = new QAudioInput(format, this);
- connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));
+ audio = new QAudioSource(format, this);
+ connect(audio, &QAudioSource::stateChanged, this, &AudioInputExample::handleStateChanged);
- QTimer::singleShot(3000, this, SLOT(stopRecording()));
+ QTimer::singleShot(3000, this, &AudioInputExample::stopRecording);
audio->start(&destinationFile);
// Records audio for 3000ms
}
@@ -137,11 +99,12 @@ public:
public Q_SLOTS:
void handleStateChanged(QAudio::State newState);
+ void stopAudioOutput();
private:
//! [Audio output class members]
QFile sourceFile; // class member.
- QAudioOutput* audio; // class member.
+ QAudioSink* audio; // class member.
//! [Audio output class members]
};
@@ -156,32 +119,36 @@ void AudioOutputExample::setup()
// Set up the format, eg.
format.setSampleRate(8000);
format.setChannelCount(1);
- format.setSampleSize(8);
- format.setCodec("audio/pcm");
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::UnSignedInt);
+ format.setSampleFormat(QAudioFormat::UInt8);
- QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
+ QAudioDevice info(QMediaDevices::defaultAudioOutput());
if (!info.isFormatSupported(format)) {
qWarning() << "Raw audio format not supported by backend, cannot play audio.";
return;
}
- audio = new QAudioOutput(format, this);
- connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));
+ audio = new QAudioSink(format, this);
+ connect(audio, QAudioSink::stateChanged, this, &AudioInputExample::handleStateChanged);
audio->start(&sourceFile);
}
//! [Audio output setup]
+//! [Audio output stop]
+void AudioOutputExample::stopAudioOutput()
+{
+ audio->stop();
+ sourceFile.close();
+ delete audio;
+}
+//! [Audio output stop]
+
//! [Audio output state changed]
void AudioOutputExample::handleStateChanged(QAudio::State newState)
{
switch (newState) {
case QAudio::IdleState:
// Finished playing (no more data)
- audio->stop();
- sourceFile.close();
- delete audio;
+ AudioOutputExample::stopAudioOutput();
break;
case QAudio::StoppedState:
@@ -204,18 +171,13 @@ void AudioDeviceInfo()
QAudioFormat format;
format.setSampleRate(44100);
// ... other format parameters
- format.setSampleType(QAudioFormat::SignedInt);
-
- QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
-
- if (!info.isFormatSupported(format))
- format = info.nearestFormat(format);
+ format.setSampleFormat(QAudioFormat::Int16);
//! [Setting audio format]
//! [Dumping audio formats]
- const auto deviceInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
- for (const QAudioDeviceInfo &deviceInfo : deviceInfos)
- qDebug() << "Device name: " << deviceInfo.deviceName();
+ const auto devices = QMediaDevices::audioOutputs();
+ for (const QAudioDevice &device : devices)
+ qDebug() << "Device: " << device.description();
//! [Dumping audio formats]
}
@@ -234,16 +196,14 @@ void AudioDecodingExample::decode()
//! [Local audio decoding]
QAudioFormat desiredFormat;
desiredFormat.setChannelCount(2);
- desiredFormat.setCodec("audio/x-raw");
- desiredFormat.setSampleType(QAudioFormat::UnSignedInt);
+ desiredFormat.setSampleFormat(QAudioFormat::Int16);
desiredFormat.setSampleRate(48000);
- desiredFormat.setSampleSize(16);
QAudioDecoder *decoder = new QAudioDecoder(this);
decoder->setAudioFormat(desiredFormat);
- decoder->setSourceFilename("level1.mp3");
+ decoder->setSource("level1.mp3");
- connect(decoder, SIGNAL(bufferReady()), this, SLOT(readBuffer()));
+ connect(decoder, &QAudioDecoder::bufferReady, this, &AudioDecodingExample::readBuffer);
decoder->start();
// Now wait for bufferReady() signal and call decoder->read()
@@ -257,9 +217,9 @@ void applyVolume(int volumeSliderValue)
{
// volumeSliderValue is in the range [0..100]
- qreal linearVolume = QAudio::convertVolume(volumeSliderValue / qreal(100.0),
- QAudio::LogarithmicVolumeScale,
- QAudio::LinearVolumeScale);
+ qreal linearVolume = QtAudio::convertVolume(volumeSliderValue / qreal(100.0),
+ QtAudio::LogarithmicVolumeScale,
+ QtAudio::LinearVolumeScale);
player.setVolume(qRound(linearVolume * 100));
}
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/audiorecorder.cpp b/src/multimedia/doc/snippets/multimedia-snippets/audiorecorder.cpp
deleted file mode 100644
index bb9193b03..000000000
--- a/src/multimedia/doc/snippets/multimedia-snippets/audiorecorder.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtWidgets>
-
-#include <qaudiorecorder.h>
-#include <qmediaservice.h>
-
-#include <QtMultimedia/qaudioformat.h>
-
-#include "audiorecorder.h"
-
-AudioRecorder::AudioRecorder()
-{
-//! [create-objs-1]
- capture = new QAudioRecorder();
-//! [create-objs-1]
-
- // set a default file
- capture->setOutputLocation(QUrl("test.raw"));
-
- QWidget *window = new QWidget;
- QGridLayout* layout = new QGridLayout;
-
- QLabel* deviceLabel = new QLabel;
- deviceLabel->setText("Devices");
- deviceBox = new QComboBox(this);
- deviceBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
-
- QLabel* codecLabel = new QLabel;
- codecLabel->setText("Codecs");
- codecsBox = new QComboBox(this);
- codecsBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
-
- QLabel* qualityLabel = new QLabel;
- qualityLabel->setText("Quality");
- qualityBox = new QComboBox(this);
- qualityBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
-
-//! [device-list]
- for(int i = 0; i < audiosource->deviceCount(); i++)
- deviceBox->addItem(audiosource->name(i));
-//! [device-list]
-
-//! [codec-list]
- QStringList codecs = capture->supportedAudioCodecs();
- for(int i = 0; i < codecs.count(); i++)
- codecsBox->addItem(codecs.at(i));
-//! [codec-list]
-
- qualityBox->addItem("Low");
- qualityBox->addItem("Medium");
- qualityBox->addItem("High");
-
- connect(capture, SIGNAL(durationChanged(qint64)), this, SLOT(updateProgress(qint64)));
- connect(capture, SIGNAL(stateChanged(QMediaRecorder::State)), this, SLOT(stateChanged(QMediaRecorder::State)));
-
- layout->addWidget(deviceLabel,0,0,Qt::AlignHCenter);
- connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int)));
- layout->addWidget(deviceBox,0,1,1,3,Qt::AlignLeft);
-
- layout->addWidget(codecLabel,1,0,Qt::AlignHCenter);
- connect(codecsBox,SIGNAL(activated(int)),SLOT(codecChanged(int)));
- layout->addWidget(codecsBox,1,1,Qt::AlignLeft);
-
- layout->addWidget(qualityLabel,1,2,Qt::AlignHCenter);
- connect(qualityBox,SIGNAL(activated(int)),SLOT(qualityChanged(int)));
- layout->addWidget(qualityBox,1,3,Qt::AlignLeft);
-
- fileButton = new QPushButton(this);
- fileButton->setText(tr("Output File"));
- connect(fileButton,SIGNAL(clicked()),SLOT(selectOutputFile()));
- layout->addWidget(fileButton,3,0,Qt::AlignHCenter);
-
- button = new QPushButton(this);
- button->setText(tr("Record"));
- connect(button,SIGNAL(clicked()),SLOT(toggleRecord()));
- layout->addWidget(button,3,3,Qt::AlignHCenter);
-
- recTime = new QLabel;
- recTime->setText("0 sec");
- layout->addWidget(recTime,4,0,Qt::AlignHCenter);
-
- window->setLayout(layout);
- setCentralWidget(window);
- window->show();
-
- active = false;
-}
-
-AudioRecorder::~AudioRecorder()
-{
- delete capture;
- delete audiosource;
-}
-
-void AudioRecorder::updateProgress(qint64 pos)
-{
- currentTime = pos;
- if(currentTime == 0) currentTime = 1;
- QString text = QString("%1 secs").arg(currentTime/1000);
- recTime->setText(text);
-}
-
-void AudioRecorder::stateChanged(QMediaRecorder::State state)
-{
- qWarning()<<"stateChanged() "<<state;
-}
-
-void AudioRecorder::deviceChanged(int idx)
-{
-//! [get-device]
- for(int i = 0; i < audiosource->deviceCount(); i++) {
- if(deviceBox->itemText(idx).compare(audiosource->name(i)) == 0)
- audiosource->setSelectedDevice(i);
- }
-//! [get-device]
-}
-
-void AudioRecorder::codecChanged(int idx)
-{
- Q_UNUSED(idx);
- //capture->setAudioCodec(codecsBox->itemText(idx));
-}
-
-void AudioRecorder::qualityChanged(int idx)
-{
- Q_UNUSED(idx);
- /*
- if(capture->audioCodec().compare("audio/pcm") == 0) {
- if(qualityBox->itemText(idx).compare("Low") == 0) {
- // 8000Hz mono is 8kbps
- capture->setAudioBitrate(8);
- } else if(qualityBox->itemText(idx).compare("Medium") == 0) {
- // 22050Hz mono is 44.1kbps
- capture->setAudioBitrate(44);
- } else if(qualityBox->itemText(idx).compare("High") == 0) {
- // 44100Hz mono is 88.2kbps
- capture->setAudioBitrate(88);
- }
- }
- */
-}
-
-//! [toggle-record]
-void AudioRecorder::toggleRecord()
-{
- if(!active) {
- recTime->setText("0 sec");
- currentTime = 0;
- capture->record();
-
- button->setText(tr("Stop"));
- active = true;
- } else {
- capture->stop();
- button->setText(tr("Record"));
- active = false;
- }
-}
-//! [toggle-record]
-
-void AudioRecorder::selectOutputFile()
-{
- QStringList fileNames;
-
- QFileDialog dialog(this);
-
- dialog.setFileMode(QFileDialog::AnyFile);
- if (dialog.exec())
- fileNames = dialog.selectedFiles();
-
- if(fileNames.size() > 0)
- capture->setOutputLocation(QUrl(fileNames.first()));
-}
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp b/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp
index f851caadd..053af088f 100644
--- a/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp
+++ b/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp
@@ -1,66 +1,30 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/* Camera snippets */
#include "qcamera.h"
-#include "qcamerainfo.h"
-#include "qcameraviewfinder.h"
-#include "qcameraviewfindersettings.h"
+#include "qcameradevice.h"
#include "qmediarecorder.h"
-#include "qcameraimagecapture.h"
-#include "qcameraimageprocessing.h"
-#include "qabstractvideosurface.h"
+#include "qmediadevices.h"
+#include "qmediacapturesession.h"
+#include "qimagecapture.h"
+#include "qvideosink.h"
+#include <QtMultimediaWidgets/qvideowidget.h>
#include <QtGui/qscreen.h>
#include <QtGui/qguiapplication.h>
#include <QtGui/qimage.h>
/* Globals so that everything is consistent. */
QCamera *camera = 0;
-QCameraViewfinder *viewfinder = 0;
QMediaRecorder *recorder = 0;
-QCameraImageCapture *imageCapture = 0;
+QImageCapture *imageCapture = 0;
+QVideoWidget *viewfinder = 0;
//! [Camera overview check]
bool checkCameraAvailability()
{
- if (QCameraInfo::availableCameras().count() > 0)
+ if (QMediaDevices::videoInputs().count() > 0)
return true;
else
return false;
@@ -70,47 +34,37 @@ bool checkCameraAvailability()
void overview_viewfinder()
{
//! [Camera overview viewfinder]
+ QMediaCaptureSession captureSession;
camera = new QCamera;
- viewfinder = new QCameraViewfinder;
- camera->setViewfinder(viewfinder);
+ captureSession.setCamera(camera);
+ viewfinder = new QVideoWidget;
+ captureSession.setVideoOutput(viewfinder);
viewfinder->show();
- camera->start(); // to start the viewfinder
+ camera->start(); // to start the camera
//! [Camera overview viewfinder]
}
void overview_camera_by_position()
{
//! [Camera overview position]
- camera = new QCamera(QCamera::FrontFace);
+ camera = new QCamera(QCameraDevice::FrontFace);
//! [Camera overview position]
}
// -.-
-class MyVideoSurface : public QAbstractVideoSurface
-{
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
- {
- Q_UNUSED(handleType);
- return QList<QVideoFrame::PixelFormat>();
- }
- bool present(const QVideoFrame &frame)
- {
- Q_UNUSED(frame);
- return true;
- }
-};
-
void overview_surface()
{
- MyVideoSurface *mySurface;
+ QVideoSink *mySink;
//! [Camera overview surface]
+ QMediaCaptureSession captureSession;
camera = new QCamera;
- mySurface = new MyVideoSurface;
- camera->setViewfinder(mySurface);
+ captureSession.setCamera(camera);
+ mySink = new QVideoSink;
+ captureSession.setVideoOutput(mySink);
camera->start();
- // MyVideoSurface::present(..) will be called with viewfinder frames
+ // MyVideoSink::setVideoFrame(..) will be called with video frames
//! [Camera overview surface]
}
@@ -121,18 +75,18 @@ void overview_viewfinder_orientation()
//! [Camera overview viewfinder orientation]
// Assuming a QImage has been created from the QVideoFrame that needs to be presented
QImage videoFrame;
- QCameraInfo cameraInfo(camera); // needed to get the camera sensor position and orientation
+ QCameraDevice cameraDevice(camera); // needed to get the camera sensor position and orientation
// Get the current display orientation
const QScreen *screen = QGuiApplication::primaryScreen();
const int screenAngle = screen->angleBetween(screen->nativeOrientation(), screen->orientation());
int rotation;
- if (cameraInfo.position() == QCamera::BackFace) {
- rotation = (cameraInfo.orientation() - screenAngle) % 360;
+ if (cameraDevice.position() == QCameraDevice::BackFace) {
+ rotation = (cameraDevice.orientation() - screenAngle) % 360;
} else {
// Front position, compensate the mirror
- rotation = (360 - cameraInfo.orientation() + screenAngle) % 360;
+ rotation = (360 - cameraDevice.orientation() + screenAngle) % 360;
}
// Rotate the frame so it always shows in the correct orientation
@@ -143,31 +97,36 @@ void overview_viewfinder_orientation()
void overview_still()
{
//! [Camera overview capture]
- imageCapture = new QCameraImageCapture(camera);
+ QMediaCaptureSession captureSession;
+ camera = new QCamera;
+ captureSession.setCamera(camera);
+ imageCapture = new QImageCapture;
+ captureSession.setImageCapture(imageCapture);
- camera->setCaptureMode(QCamera::CaptureStillImage);
camera->start(); // Viewfinder frames start flowing
- //on half pressed shutter button
- camera->searchAndLock();
-
//on shutter button pressed
imageCapture->capture();
-
- //on shutter button released
- camera->unlock();
//! [Camera overview capture]
}
void overview_movie()
{
//! [Camera overview movie]
+ QMediaCaptureSession captureSession;
camera = new QCamera;
+ captureSession.setCamera(camera);
recorder = new QMediaRecorder(camera);
+ captureSession.setRecorder(recorder);
- camera->setCaptureMode(QCamera::CaptureVideo);
camera->start();
+ // setup output format for the recorder
+ QMediaFormat format(QMediaFormat::MPEG4);
+ format.setVideoCodec(QMediaRecorder::VideoCodec::H264);
+ format.setAudioCodec(QMediaRecorder::AudioCodec::MP3);
+ recorder->setMediaFormat(settings);
+
//on shutter button pressed
recorder->record();
@@ -179,19 +138,19 @@ void overview_movie()
void camera_listing()
{
//! [Camera listing]
- const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
- for (const QCameraInfo &cameraInfo : cameras)
- qDebug() << cameraInfo.deviceName();
+ const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
+ for (const QCameraDevice &cameraDevice : cameras)
+ qDebug() << cameraDevice.description();
//! [Camera listing]
}
void camera_selection()
{
//! [Camera selection]
- const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
- for (const QCameraInfo &cameraInfo : cameras) {
- if (cameraInfo.deviceName() == "mycamera")
- camera = new QCamera(cameraInfo);
+ const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
+ for (const QCameraDevice &cameraDevice : cameras) {
+ if (cameraDevice.description() == "mycamera")
+ camera = new QCamera(cameraDevice);
}
//! [Camera selection]
}
@@ -200,95 +159,54 @@ void camera_info()
{
//! [Camera info]
QCamera myCamera;
- QCameraInfo cameraInfo(myCamera);
+ QCameraDevice cameraDevice = camera->cameraDevice();
- if (cameraInfo.position() == QCamera::FrontFace)
+ if (cameraDevice.position() == QCameraDevice::FrontFace)
qDebug() << "The camera is on the front face of the hardware system.";
- else if (cameraInfo.position() == QCamera::BackFace)
+ else if (cameraDevice.position() == QCameraDevice::BackFace)
qDebug() << "The camera is on the back face of the hardware system.";
-
- qDebug() << "The camera sensor orientation is " << cameraInfo.orientation() << " degrees.";
//! [Camera info]
}
void camera_blah()
{
//! [Camera]
+ QMediaCaptureSession captureSession;
camera = new QCamera;
+ captureSession.setCamera(camera);
- viewfinder = new QCameraViewfinder();
+ viewfinder = new QVideoWidget();
viewfinder->show();
+ captureSession.setVideoOutput(viewfinder);
- camera->setViewfinder(viewfinder);
-
- imageCapture = new QCameraImageCapture(camera);
+ imageCapture = new QImageCapture(camera);
+ captureSession.setImageCapture(imageCapture);
- camera->setCaptureMode(QCamera::CaptureStillImage);
camera->start();
//! [Camera]
//! [Camera keys]
- //on half pressed shutter button
- camera->searchAndLock();
-
//on shutter button pressed
imageCapture->capture();
-
- //on shutter button released
- camera->unlock();
//! [Camera keys]
}
void cameraimageprocessing()
{
- //! [Camera image whitebalance]
camera = new QCamera;
- QCameraImageProcessing *imageProcessing = camera->imageProcessing();
-
- if (imageProcessing->isAvailable()) {
- imageProcessing->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceFluorescent);
- }
//! [Camera image whitebalance]
-
- //! [Camera image denoising]
- imageProcessing->setDenoisingLevel(-0.3); //reduce the amount of denoising applied
- //! [Camera image denoising]
+ camera->setWhiteBalanceMode(QCamera::WhiteBalanceFluorescent);
+ //! [Camera image whitebalance]
}
void camerafocus()
{
- //! [Camera custom zoom]
- QCameraFocus *focus = camera->focus();
- focus->setFocusPointMode(QCameraFocus::FocusPointCustom);
- focus->setCustomFocusPoint(QPointF(0.25f, 0.75f)); // A point near the bottom left, 25% away from the corner, near that shiny vase
- //! [Camera custom zoom]
-
- //! [Camera combined zoom]
- focus->zoomTo(3.0, 4.0); // Super zoom!
- //! [Camera combined zoom]
-
- //! [Camera focus zones]
- focus->setFocusPointMode(QCameraFocus::FocusPointAuto);
- const QList<QCameraFocusZone> zones = focus->focusZones();
- for (const QCameraFocusZone &zone : zones) {
- if (zone.status() == QCameraFocusZone::Focused) {
- // Draw a green box at zone.area()
- } else if (zone.status() == QCameraFocusZone::Selected) {
- // This area is selected for autofocusing, but is not in focus
- // Draw a yellow box at zone.area()
- }
- }
- //! [Camera focus zones]
-}
-
-void camera_viewfindersettings()
-{
- //! [Camera viewfinder settings]
- QCameraViewfinderSettings viewfinderSettings;
- viewfinderSettings.setResolution(640, 480);
- viewfinderSettings.setMinimumFrameRate(15.0);
- viewfinderSettings.setMaximumFrameRate(30.0);
-
- camera->setViewfinderSettings(viewfinderSettings);
- //! [Camera viewfinder settings]
+ //! [Camera custom focus]
+ camera->setFocusPointMode(QCamera::FocusModeManual);
+ camera->setCustomFocusPoint(QPointF(0.25f, 0.75f)); // A point near the bottom left, 25% away from the corner, near that shiny vase
+ //! [Camera custom focus]
+
+ //! [Camera zoom]
+ camera->setZoomFactor(3.0);
+ //! [Camera zoom]
}
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/devices.cpp b/src/multimedia/doc/snippets/multimedia-snippets/devices.cpp
new file mode 100644
index 000000000..652400364
--- /dev/null
+++ b/src/multimedia/doc/snippets/multimedia-snippets/devices.cpp
@@ -0,0 +1,38 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include <QAudioDevice>
+#include <QCameraDevice>
+#include <QMediaDevices>
+#include <QString>
+#include <QTextStream>
+
+int main(int argc, char *argv[])
+{
+ Q_UNUSED(argc);
+ Q_UNUSED(argv);
+
+ QTextStream out(stdout);
+
+ //! [Media Audio Input Device Enumeration]
+ const QList<QAudioDevice> audioDevices = QMediaDevices::audioInputs();
+ for (const QAudioDevice &device : audioDevices)
+ {
+ out << "ID: " << device.id() << Qt::endl;
+ out << "Description: " << device.description() << Qt::endl;
+ out << "Is default: " << (device.isDefault() ? "Yes" : "No") << Qt::endl;
+ }
+ //! [Media Audio Input Device Enumeration]
+
+ //! [Media Video Input Device Enumeration]
+ const QList<QCameraDevice> videoDevices = QMediaDevices::videoInputs();
+ for (const QCameraDevice &device : videoDevices)
+ {
+ out << "ID: " << device.id() << Qt::endl;
+ out << "Description: " << device.description() << Qt::endl;
+ out << "Is default: " << (device.isDefault() ? "Yes" : "No") << Qt::endl;
+ }
+ //! [Media Video Input Device Enumeration]
+
+ return 0;
+}
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/media.cpp b/src/multimedia/doc/snippets/multimedia-snippets/media.cpp
index 5ba7fcc25..a4b9a9fb5 100644
--- a/src/multimedia/doc/snippets/multimedia-snippets/media.cpp
+++ b/src/multimedia/doc/snippets/multimedia-snippets/media.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/* Media related snippets */
#include <QFile>
@@ -44,17 +8,15 @@
#include "qmediaplaylist.h"
#include "qmediarecorder.h"
-#include "qmediaservice.h"
-#include "qmediaplayercontrol.h"
+#include "qplatformmediaplayer_p.h"
#include "qmediaplayer.h"
#include "qvideowidget.h"
-#include "qcameraimagecapture.h"
+#include "qimagecapture.h"
#include "qcamera.h"
#include "qcameraviewfinder.h"
-#include "qaudioprobe.h"
#include "qaudiorecorder.h"
-#include "qvideoprobe.h"
-#include <QAbstractVideoSurface>
+#include "qurl.h"
+#include <QVideoSink>
class MediaExample : public QObject {
Q_OBJECT
@@ -62,28 +24,22 @@ class MediaExample : public QObject {
void MediaControl();
void MediaPlayer();
void MediaRecorder();
- void AudioRecorder();
- void EncoderSettings();
- void ImageEncoderSettings();
- void AudioProbe();
- void VideoProbe();
+ void recorderSettings();
+ void imageSettings();
private:
// Common naming
- QMediaService *mediaService;
QVideoWidget *videoWidget;
QWidget *widget;
QMediaPlayer *player;
+ QAudioOutput *audioOutput;
QMediaPlaylist *playlist;
QMediaContent video;
QMediaRecorder *recorder;
QCamera *camera;
QCameraViewfinder *viewfinder;
- QCameraImageCapture *imageCapture;
+ QImageCapture *imageCapture;
QString fileName;
- QAudioRecorder *audioRecorder;
- QAudioProbe *audioProbe;
- QVideoProbe *videoProbe;
QMediaContent image1;
QMediaContent image2;
@@ -92,258 +48,62 @@ private:
void MediaExample::MediaControl()
{
- {
- //! [Request control]
- QMediaPlayerControl *control = qobject_cast<QMediaPlayerControl *>(
- mediaService->requestControl("org.qt-project.qt.mediaplayercontrol/5.0"));
- //! [Request control]
- Q_UNUSED(control);
- }
-
- {
- //! [Request control templated]
- QMediaPlayerControl *control = mediaService->requestControl<QMediaPlayerControl *>();
- //! [Request control templated]
- Q_UNUSED(control);
- }
}
-void MediaExample::EncoderSettings()
+void MediaExample::recorderSettings()
{
- //! [Audio encoder settings]
- QAudioEncoderSettings audioSettings;
- audioSettings.setCodec("audio/mpeg");
- audioSettings.setChannelCount(2);
-
- recorder->setAudioSettings(audioSettings);
- //! [Audio encoder settings]
+ //! [Media recorder settings]
+ QMediaFormat format(QMediaFormat::MPEG4);
+ format.setVideoCodec(QMediaRecorder::VideoCodec::H264);
+ format.setAudioCodec(QMediaRecorder::AudioCodec::MP3);
- //! [Video encoder settings]
- QVideoEncoderSettings videoSettings;
- videoSettings.setCodec("video/mpeg2");
- videoSettings.setResolution(640, 480);
-
- recorder->setVideoSettings(videoSettings);
- //! [Video encoder settings]
+ recorder->setMediaFormat(settings);
+ //! [Media recorder settings]
}
-void MediaExample::ImageEncoderSettings()
+void MediaExample::imageSettings()
{
- //! [Image encoder settings]
- QImageEncoderSettings imageSettings;
- imageSettings.setCodec("image/jpeg");
- imageSettings.setResolution(1600, 1200);
-
- imageCapture->setEncodingSettings(imageSettings);
- //! [Image encoder settings]
+ //! [Image recorder settings]
+ imageCapture->setFileFormat(QImageCapture::JPEG);
+ imageCapture->setResolution(1600, 1200);
+ //! [Image recorder settings]
}
void MediaExample::MediaPlayer()
{
//! [Player]
player = new QMediaPlayer;
- connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
- player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3"));
- player->setVolume(50);
+ audioOutput = new QAudioOutput;
+ player->setAudioOutput(audioOutput);
+ connect(player, &QMediaPlayer::positionChanged, this, &MediaExample::positionChanged);
+ player->setSource(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3"));
+ audioOutput->setVolume(50);
player->play();
//! [Player]
//! [Local playback]
player = new QMediaPlayer;
+ audioOutput = new QAudioOutput;
+ player->setAudioOutput(audioOutput);
// ...
- player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3"));
- player->setVolume(50);
+ player->setSource(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3"));
+ audioOutput->setVolume(50);
player->play();
//! [Local playback]
-
- //! [Audio playlist]
- player = new QMediaPlayer;
-
- playlist = new QMediaPlaylist(player);
- playlist->addMedia(QUrl("http://example.com/myfile1.mp3"));
- playlist->addMedia(QUrl("http://example.com/myfile2.mp3"));
- // ...
- playlist->setCurrentIndex(1);
- player->play();
- //! [Audio playlist]
-
- //! [Movie playlist]
- playlist = new QMediaPlaylist;
- playlist->addMedia(QUrl("http://example.com/movie1.mp4"));
- playlist->addMedia(QUrl("http://example.com/movie2.mp4"));
- playlist->addMedia(QUrl("http://example.com/movie3.mp4"));
- playlist->setCurrentIndex(1);
-
- player = new QMediaPlayer;
- player->setPlaylist(playlist);
-
- videoWidget = new QVideoWidget;
- player->setVideoOutput(videoWidget);
- videoWidget->show();
-
- player->play();
- //! [Movie playlist]
-
- //! [Pipeline]
- player = new QMediaPlayer;
- player->setMedia(QUrl("gst-pipeline: videotestsrc ! autovideosink"));
- player->play();
- //! [Pipeline]
-
- //! [Pipeline Surface]
- class Surface : public QAbstractVideoSurface
- {
- public:
- Surface(QObject *p) : QAbstractVideoSurface(p) { }
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType) const override
- {
- // Make sure that the driver supports this pixel format.
- return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_YUYV;
- }
-
- // Video frames are handled here.
- bool present(const QVideoFrame &) override { return true; }
- };
-
- player = new QMediaPlayer;
- player->setVideoOutput(new Surface(player));
- player->setMedia(QUrl("gst-pipeline: videotestsrc ! qtvideosink"));
- player->play();
- //! [Pipeline Surface]
-
- //! [Pipeline Widget]
- player = new QMediaPlayer;
- videoWidget = new QVideoWidget;
- videoWidget->show();
- player->setVideoOutput(videoWidget);
- player->setMedia(QUrl("gst-pipeline: videotestsrc ! xvimagesink name=\"qtvideosink\""));
- player->play();
- //! [Pipeline Widget]
-
- //! [Pipeline appsrc]
- QImage img("images/qt-logo.png");
- img = img.convertToFormat(QImage::Format_ARGB32);
- QByteArray ba(reinterpret_cast<const char *>(img.bits()), img.sizeInBytes());
- QBuffer buffer(&ba);
- buffer.open(QIODevice::ReadOnly);
- player = new QMediaPlayer;
- player->setMedia(QUrl("gst-pipeline: appsrc blocksize=4294967295 ! \
- video/x-raw,format=BGRx,framerate=30/1,width=200,height=147 ! \
- coloreffects preset=heat ! videoconvert ! video/x-raw,format=I420 ! jpegenc ! rtpjpegpay ! \
- udpsink host=127.0.0.1 port=5000"), &buffer);
- player->play();
-
- QMediaPlayer *receiver = new QMediaPlayer;
- videoWidget = new QVideoWidget;
- receiver->setVideoOutput(videoWidget);
- receiver->setMedia(QUrl("gst-pipeline: udpsrc port=5000 ! \
- application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! \
- xvimagesink name=qtvideosink"));
- receiver->play();
- // Content will be shown in this widget.
- videoWidget->show();
- //! [Pipeline appsrc]
}
void MediaExample::MediaRecorder()
{
//! [Media recorder]
- recorder = new QMediaRecorder(camera);
-
- QAudioEncoderSettings audioSettings;
- audioSettings.setCodec("audio/amr");
- audioSettings.setQuality(QMultimedia::HighQuality);
-
- recorder->setAudioSettings(audioSettings);
-
- recorder->setOutputLocation(QUrl::fromLocalFile(fileName));
- recorder->record();
+ QMediaCaptureSession session;
+ QAudioInput audioInput;
+ session.setAudioInput(&input);
+ QMediaRecorder recorder;
+ session.setRecorder(&recorder);
+ recorder.setQuality(QMediaRecorder::HighQuality);
+ recorder.setOutputLocation(QUrl::fromLocalFile("test.mp3"));
+ recorder.record();
//! [Media recorder]
}
-void MediaExample::AudioRecorder()
-{
- //! [Audio recorder]
- audioRecorder = new QAudioRecorder;
-
- QAudioEncoderSettings audioSettings;
- audioSettings.setCodec("audio/amr");
- audioSettings.setQuality(QMultimedia::HighQuality);
-
- audioRecorder->setEncodingSettings(audioSettings);
-
- audioRecorder->setOutputLocation(QUrl::fromLocalFile("test.amr"));
- audioRecorder->record();
- //! [Audio recorder]
-
- //! [Audio recorder inputs]
- const QStringList inputs = audioRecorder->audioInputs();
- QString selectedInput = audioRecorder->defaultAudioInput();
-
- for (const QString &input : inputs) {
- QString description = audioRecorder->audioInputDescription(input);
- // show descriptions to user and allow selection
- selectedInput = input;
- }
-
- audioRecorder->setAudioInput(selectedInput);
- //! [Audio recorder inputs]
-}
-
-void MediaExample::AudioProbe()
-{
- //! [Audio probe]
- audioRecorder = new QAudioRecorder;
-
- QAudioEncoderSettings audioSettings;
- audioSettings.setCodec("audio/amr");
- audioSettings.setQuality(QMultimedia::HighQuality);
-
- audioRecorder->setEncodingSettings(audioSettings);
-
- audioRecorder->setOutputLocation(QUrl::fromLocalFile("test.amr"));
-
- audioProbe = new QAudioProbe(this);
- if (audioProbe->setSource(audioRecorder)) {
- // Probing succeeded, audioProbe->isValid() should be true.
- connect(audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)),
- this, SLOT(calculateLevel(QAudioBuffer)));
- }
-
- audioRecorder->record();
- // Now audio buffers being recorded should be signaled
- // by the probe, so we can do things like calculating the
- // audio power level, or performing a frequency transform
- //! [Audio probe]
-}
-
-void MediaExample::VideoProbe()
-{
- //! [Video probe]
- camera = new QCamera;
- viewfinder = new QCameraViewfinder();
- camera->setViewfinder(viewfinder);
-
- camera->setCaptureMode(QCamera::CaptureVideo);
-
- videoProbe = new QVideoProbe(this);
-
- if (videoProbe->setSource(camera)) {
- // Probing succeeded, videoProbe->isValid() should be true.
- connect(videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)),
- this, SLOT(detectBarcodes(QVideoFrame)));
- }
-
- camera->start();
- // Viewfinder frames should now also be emitted by
- // the video probe, even in still image capture mode.
- // Another alternative is to install the probe on a
- // QMediaRecorder connected to the camera to get the
- // recorded frames, if they are different from the
- // viewfinder frames.
-
- //! [Video probe]
-}
-
-
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/multimedia-snippets.pro b/src/multimedia/doc/snippets/multimedia-snippets/multimedia-snippets.pro
deleted file mode 100644
index a46b20bd0..000000000
--- a/src/multimedia/doc/snippets/multimedia-snippets/multimedia-snippets.pro
+++ /dev/null
@@ -1,26 +0,0 @@
-# Doc snippets - compiled for truthiness
-
-TEMPLATE = lib
-TARGET = qtmmksnippets
-
-INCLUDEPATH += ../../../../src/global \
- ../../../../src/multimedia \
- ../../../../src/multimedia/audio \
- ../../../../src/multimedia/video \
- ../../../../src/multimedia/camera
-
-CONFIG += console
-
-QT += multimedia multimediawidgets widgets multimedia-private
-
-SOURCES += \
- audio.cpp \
- video.cpp \
- camera.cpp \
- media.cpp \
- qsound.cpp
-
-OTHER_FILES += \
- soundeffect.qml \
- qtvideosink.qml \
- multiple-videooutputs.qml
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/multiple-videooutputs.qml b/src/multimedia/doc/snippets/multimedia-snippets/multiple-videooutputs.qml
index e3c1587f6..0c673cc42 100644
--- a/src/multimedia/doc/snippets/multimedia-snippets/multiple-videooutputs.qml
+++ b/src/multimedia/doc/snippets/multimedia-snippets/multiple-videooutputs.qml
@@ -1,53 +1,19 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-import QtQuick 2.0
-import QtQuick.Window 2.2
-import QtMultimedia 5.15
+import QtQuick
+import QtQuick.Window
+import QtMultimedia
//! [complete]
Item {
MediaPlayer {
id: mediaplayer
- autoPlay: true
source: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
videoOutput: [v1, v2]
+ audioOutput: AudioOutput {
+
+ }
}
VideoOutput {
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/qaudioprobe.cpp b/src/multimedia/doc/snippets/multimedia-snippets/qaudioprobe.cpp
deleted file mode 100644
index 8543395f3..000000000
--- a/src/multimedia/doc/snippets/multimedia-snippets/qaudioprobe.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [desc]
-QAudioRecorder *recorder = new QAudioRecorder();
-QAudioProbe *probe = new QAudioProbe;
-
-// ... configure the audio recorder (skipped)
-
-connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(processBuffer(QAudioBuffer)));
-
-probe->setSource(recorder); // Returns true, hopefully.
-
-recorder->record(); // Now we can do things like calculating levels or performing an FFT
-//! [desc]
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp b/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp
index fbc849c2e..644dcb228 100644
--- a/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp
+++ b/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp
@@ -1,69 +1,9 @@
- /****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "qpushbutton.h"
-#include "qsound.h"
#include "qsoundeffect.h"
-void qsoundsnippet() {
- //! [0]
- QSound::play("mysounds/bells.wav");
- //! [0]
-
-
- //! [1]
- QSound bells("mysounds/bells.wav");
- bells.play();
- //! [1]
-}
-
void qsoundeffectsnippet() {
//! [2]
QSoundEffect effect;
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/qtvideosink.qml b/src/multimedia/doc/snippets/multimedia-snippets/qtvideosink.qml
index a4ae07f30..eeac9c28e 100644
--- a/src/multimedia/doc/snippets/multimedia-snippets/qtvideosink.qml
+++ b/src/multimedia/doc/snippets/multimedia-snippets/qtvideosink.qml
@@ -1,55 +1,23 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-import QtQuick 2.0
-import QtMultimedia 5.12
+import QtQuick
+import QtMultimedia
//! [complete]
Item {
MediaPlayer {
id: mediaplayer
- source: "gst-pipeline: videotestsrc ! qtvideosink"
+ source: "file:///test.mp4"
+ videoOutput: videoOutput
+ audioOutput: AudioOutput {
+
+ }
}
VideoOutput {
+ id: videoOutput
anchors.fill: parent
- source: mediaplayer
}
MouseArea {
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/soundeffect.qml b/src/multimedia/doc/snippets/multimedia-snippets/soundeffect.qml
index c414aca56..e91e54e3c 100644
--- a/src/multimedia/doc/snippets/multimedia-snippets/soundeffect.qml
+++ b/src/multimedia/doc/snippets/multimedia-snippets/soundeffect.qml
@@ -1,44 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-import QtQuick 2.0
-import QtMultimedia 5.5
+import QtQuick
+import QtMultimedia
//! [complete snippet]
Text {
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/video.cpp b/src/multimedia/doc/snippets/multimedia-snippets/video.cpp
index 46327e3d6..8cc3b41b3 100644
--- a/src/multimedia/doc/snippets/multimedia-snippets/video.cpp
+++ b/src/multimedia/doc/snippets/multimedia-snippets/video.cpp
@@ -1,95 +1,29 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/* Video related snippets */
#include "qvideorenderercontrol.h"
-#include "qmediaservice.h"
#include "qmediaplayer.h"
-#include "qabstractvideosurface.h"
-#include "qvideowidgetcontrol.h"
+#include "qvideosink.h"
#include "qvideowindowcontrol.h"
#include "qgraphicsvideoitem.h"
-#include "qmediaplaylist.h"
-#include "qvideosurfaceformat.h"
+#include "qvideoframeformat.h"
#include <QFormLayout>
#include <QGraphicsView>
-//! [Derived Surface]
-class MyVideoSurface : public QAbstractVideoSurface
-{
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const
- {
- Q_UNUSED(handleType);
-
- // Return the formats you will support
- return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB565;
- }
-
- bool present(const QVideoFrame &frame)
- {
- Q_UNUSED(frame);
- // Handle the frame and do your processing
-
- return true;
- }
-};
-//! [Derived Surface]
-
//! [Video producer]
class MyVideoProducer : public QObject
{
Q_OBJECT
- Q_PROPERTY(QAbstractVideoSurface *videoSurface READ videoSurface WRITE setVideoSurface)
+ Q_PROPERTY(QVideoSink *videoSink READ videoSink WRITE setVideoSink)
public:
- QAbstractVideoSurface* videoSurface() const { return m_surface; }
+ QVideoSink* videoSink() const { return m_sink; }
- void setVideoSurface(QAbstractVideoSurface *surface)
+ void setVideoSink(QVideoSink *sink)
{
- if (m_surface != surface && m_surface && m_surface->isActive()) {
- m_surface->stop();
- }
- m_surface = surface;
- if (m_surface)
- m_surface->start(m_format);
+ m_sink = sink;
}
// ...
@@ -97,13 +31,12 @@ public:
public slots:
void onNewVideoContentReceived(const QVideoFrame &frame)
{
- if (m_surface)
- m_surface->present(frame);
+ if (m_sink)
+ m_sink->setVideoFrame(frame);
}
private:
- QAbstractVideoSurface *m_surface;
- QVideoSurfaceFormat m_format;
+ QVideoSink *m_sink;
};
//! [Video producer]
@@ -113,7 +46,6 @@ class VideoExample : public QObject {
Q_OBJECT
public:
void VideoGraphicsItem();
- void VideoRendererControl();
void VideoWidget();
void VideoWindowControl();
void VideoWidgetControl();
@@ -121,46 +53,32 @@ public:
private:
// Common naming
- QMediaService *mediaService;
- QMediaPlaylist *playlist;
QVideoWidget *videoWidget;
QWidget *widget;
QFormLayout *layout;
- QAbstractVideoSurface *myVideoSurface;
+ QVideoSink *myVideoSink;
QMediaPlayer *player;
QMediaContent video;
QGraphicsView *graphicsView;
};
-void VideoExample::VideoRendererControl()
-{
- //! [Video renderer control]
- QVideoRendererControl *rendererControl = mediaService->requestControl<QVideoRendererControl *>();
- rendererControl->setSurface(myVideoSurface);
- //! [Video renderer control]
-}
-
void VideoExample::VideoWidget()
{
//! [Video widget]
player = new QMediaPlayer;
-
- playlist = new QMediaPlaylist(player);
- playlist->addMedia(QUrl("http://example.com/myclip1.mp4"));
- playlist->addMedia(QUrl("http://example.com/myclip2.mp4"));
+ player->setSource(QUrl("http://example.com/myclip1.mp4"));
videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->show();
- playlist->setCurrentIndex(1);
player->play();
//! [Video widget]
player->stop();
//! [Setting surface in player]
- player->setVideoOutput(myVideoSurface);
+ player->setVideoOutput(myVideoSink);
//! [Setting surface in player]
}
@@ -168,7 +86,7 @@ void VideoExample::VideoSurface()
{
//! [Widget Surface]
QImage img = QImage("images/qt-logo.png").convertToFormat(QImage::Format_ARGB32);
- QVideoSurfaceFormat format(img.size(), QVideoFrame::Format_ARGB32);
+ QVideoFrameFormat format(img.size(), QVideoFrameFormat::Format_ARGB8888);
videoWidget = new QVideoWidget;
videoWidget->videoSurface()->start(format);
videoWidget->videoSurface()->present(img);
@@ -180,30 +98,10 @@ void VideoExample::VideoSurface()
graphicsView->scene()->addItem(item);
graphicsView->show();
QImage img = QImage("images/qt-logo.png").convertToFormat(QImage::Format_ARGB32);
- QVideoSurfaceFormat format(img.size(), QVideoFrame::Format_ARGB32);
- item->videoSurface()->start(format);
- item->videoSurface()->present(img);
+ item->videoSink()->setVideoFrame(QVideoFrame(img));
//! [GraphicsVideoItem Surface]
}
-void VideoExample::VideoWidgetControl()
-{
- //! [Video widget control]
- QVideoWidgetControl *widgetControl = mediaService->requestControl<QVideoWidgetControl *>();
- layout->addWidget(widgetControl->videoWidget());
- //! [Video widget control]
-}
-
-void VideoExample::VideoWindowControl()
-{
- //! [Video window control]
- QVideoWindowControl *windowControl = mediaService->requestControl<QVideoWindowControl *>();
- windowControl->setWinId(widget->winId());
- windowControl->setDisplayRect(widget->rect());
- windowControl->setAspectRatioMode(Qt::KeepAspectRatio);
- //! [Video window control]
-}
-
void VideoExample::VideoGraphicsItem()
{
//! [Video graphics item]
@@ -214,7 +112,7 @@ void VideoExample::VideoGraphicsItem()
graphicsView->scene()->addItem(item);
graphicsView->show();
- player->setMedia(QUrl("http://example.com/myclip4.ogv"));
+ player->setSource(QUrl("http://example.com/myclip4.ogv"));
player->play();
//! [Video graphics item]
}
diff --git a/src/multimedia/doc/snippets/snippets.pro b/src/multimedia/doc/snippets/snippets.pro
deleted file mode 100644
index 31a3a0992..000000000
--- a/src/multimedia/doc/snippets/snippets.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS += multimedia-snippets
diff --git a/src/multimedia/doc/src/audiooverview.qdoc b/src/multimedia/doc/src/audiooverview.qdoc
index d39738da4..40a6318a6 100644
--- a/src/multimedia/doc/src/audiooverview.qdoc
+++ b/src/multimedia/doc/src/audiooverview.qdoc
@@ -1,136 +1,130 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page audiooverview.html
\title Audio Overview
-\brief Audio playback, recording and processing
+\inlineimage sound-wave-small.jpg
+\brief Playback, recording and processing of Audio.
+\ingroup explanations-graphicsandmultimedia
\section1 Audio Features
-Qt Multimedia offers a range of audio classes, covering both low and
-high level approaches to audio input, output and processing. In
-addition to traditional audio usage, the \l{Qt Audio Engine QML Types}{Qt Audio Engine}
-QML types offer high level 3D positional audio for QML applications.
-See that documentation for more information.
+Qt Multimedia offers a range of audio classes that cover both low and
+high level approaches to: audio input, output and processing.
\section1 Audio Implementation Details
\section2 Playing Compressed Audio
-For playing media or audio files that are not simple, uncompressed audio, you can
-use the \l QMediaPlayer C++ class, or the \l {Audio} and \l {MediaPlayer} QML types.
+
+For playing media or audio files that are not simple, uncompressed audio, you
+can use the QMediaPlayer C++ class, or the \l{MediaPlayer} QML type.
The QMediaPlayer class and associated QML types are also capable of playing
-\l{multimedia-playing-video}{video}, if required. The compressed audio formats supported does depend
-on the operating system environment, and also what media plugins the user
-may have installed.
+\l{multimedia-playing-video}{video}, if required.
+
+See \l{Supported Media Formats} for more detail.
+
+The media player needs to be connected to a QAudioOutput object (or the QML AudioOutput
+element) to play back audio.
Here is how you play a local file using C++:
\snippet multimedia-snippets/media.cpp Local playback
-You can also put files (even remote URLs) into a playlist:
- \snippet multimedia-snippets/media.cpp Audio playlist
+The same functionality in QML:
+
+\qml
+MediaPlayer {
+ audioOutput: AudioOutput {}
+ source: "file:///path/to/my/music.mp3"
+ Component.onCompleted: { play() }
+}
+\endqml
\section2 Recording Audio to a File
-For recording audio to a file, the \l {QAudioRecorder} class allows you
-to compress audio data from an input device and record it.
- \snippet multimedia-snippets/media.cpp Audio recorder
+To record audio to a file, you need to create a capture session and connect to it an audio
+input and a recorder. These elements are implemented with the QMediaCaptureSession,
+QAudioInput, and QMediaRecorder classes. The default constructed QAudioInput selects the
+system default audio input. The recorder controls the recording process with a simple record()
+and stop() functions. Additionally, you can use it to select the output location, audio
+encoder, or file container format.
-\section2 Low Latency Sound Effects
+A session recording audio from the default microphone would look as follows in C++:
+
+ \snippet multimedia-snippets/media.cpp Media recorder
-In addition to the raw access to sound devices described above, the QSoundEffect class (and
-\l {SoundEffect} QML type) offers a slightly higher level way to play
-sounds. These classes allow you to specify a WAV format file which can
-then be played with low latency when necessary. Both QSoundEffect and
-SoundEffect have essentially the same API.
+In QML, the same can be achieved by:
-You can adjust the number of \l {QSoundEffect::loopCount()}{loops} a sound effect is played, as well as
-the \l {QSoundEffect::setVolume()}{volume} (or \l {QSoundEffect::setMuted()}{muting}) of the effect.
+\qml
+CaptureSession {
+ audioInput: AudioInput {}
+ mediaRecorder: MediaRecorder {
+ id: recorder
+ outputLocation: "file:///path/to/test.mp3"
+ }
+ Component.onCompleted: { recorder.record() }
+}
+\endqml
-For older, Qt 4.x based applications \l QSound is also available. Applications
-are recommended to use QSoundEffect where possible.
+QMediaCaptureSession also provides support for more complex use cases such as image
+capturing or video recording.
-\section2 Monitoring Audio Data During Playback or Recording
+\section2 Low Latency Sound Effects
-The \l QAudioProbe class allows you to monitor audio data being played or
-recorded in the higher level classes like \l QMediaPlayer, \l QCamera and
-\l QAudioRecorder. After creating your high level class, you can simply
-set the source of the probe to your class, and receive audio buffers as they
-are processed. This is useful for several audio processing tasks, particularly
-for visualization or adjusting gain. You cannot modify the buffers, and
-they may arrive at a slightly different time than the media pipeline
-processes them.
+In addition to \l{raw access} to sound devices, the QSoundEffect
+class (and \l{SoundEffect} QML type) offers a more abstract way to play
+sounds. This class allows you to specify a \b{WAV format} file, which can
+then be played with low latency when necessary.
-Here's an example of installing a probe during recording:
- \snippet multimedia-snippets/media.cpp Audio probe
+You can adjust the:
+\list
+ \li \l{QSoundEffect::loopCount()}{Number of loops} in which a sound effect
+ is played.
+ \li \l{QSoundEffect::setVolume()}{Volume} of the sound effect.
+ \li \l{QSoundEffect::setMuted()}{Muting} of the sound effect.
+\endlist
+\target raw access
\section2 Low Level Audio Playback and Recording
-Qt Multimedia offers classes for raw access to audio input and output
+
+The C++ API of Qt Multimedia offers classes for raw access to audio input and output
facilities, allowing applications to receive raw data from devices like
-microphones, and to write raw data to speakers or other devices. Generally
+microphones, and to write raw data to speakers or other devices. Generally
these classes do not do any audio decoding, or other processing, but they
can support different types of raw audio data.
-The QAudioOutput class offers raw audio data output, while QAudioInput
-offers raw audio data input. Both classes have adjustable buffers and
-latency, so they are suitable for both low latency use cases (like games
-or VOIP) and high latency (like music playback). The available hardware
+The QAudioSink class offers raw audio data output, while QAudioSource
+offers raw audio data input. The available hardware
determines what audio outputs and inputs are available.
\section3 Push and Pull
The low level audio classes can operate in two modes - \c push and \c pull.
In \c pull mode, the audio device is started by giving it a QIODevice. For
-an output device, the QAudioOutput class will pull data from the QIODevice
+an output device, the QAudioSink class will pull data from the QIODevice
(using \l QIODevice::read()) when more audio data is required. Conversely,
-for \c pull mode with QAudioInput, when audio data is available then the
+for \c pull mode with QAudioSource, when audio data is available then the
data will be written directly to the QIODevice.
In \c push mode, the audio device provides a QIODevice instance that
-can be written or read to as needed. Typically this results in simpler
+can be written or read to as needed. Typically, this results in simpler
code but more buffering, which may affect latency.
\section2 Decoding Compressed Audio to Memory
+
In some cases you may want to decode a compressed audio file and do further
-processing yourself (for example, mixing multiple samples or using custom
-digital signal processing algorithms). QAudioDecoder supports decoding local
+processing yourself. For example, mixing multiple samples or using custom
+digital signal processing algorithms. QAudioDecoder supports decoding local
files or data streams from QIODevice instances.
Here's an example of decoding a local file:
\snippet multimedia-snippets/audio.cpp Local audio decoding
-\section1 Examples
-
-There are both C++ and QML examples available.
+\section2 Spatial Audio
-\section2 C++ Examples
-
-\annotatedlist audio_examples
+The \l {Qt Spatial Audio} module provides an API for implementation sound
+fields in 3D space.
\section1 Reference Documentation
@@ -142,4 +136,8 @@ There are both C++ and QML examples available.
\annotatedlist multimedia_audio_qml
+\section2 Examples
+
+\annotatedlist audio_examples
*/
+
diff --git a/src/multimedia/doc/src/cameraoverview.qdoc b/src/multimedia/doc/src/cameraoverview.qdoc
index 69631fdab..b93954d6d 100644
--- a/src/multimedia/doc/src/cameraoverview.qdoc
+++ b/src/multimedia/doc/src/cameraoverview.qdoc
@@ -1,82 +1,82 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page cameraoverview.html
\title Camera Overview
\brief Camera viewfinder, still image capture, and video recording.
+\ingroup explanations-graphicsandmultimedia
The Qt Multimedia API provides a number of camera related classes, so you
-can access images and videos from mobile device cameras or webcameras.
+can access images and videos from mobile device cameras or web cameras.
There are both C++ and QML APIs for common tasks.
\section1 Camera Features
-In order to use the camera classes a quick overview of the way a camera
-works is needed. If you're already familiar with this, you can skip ahead to
+In order to use the camera classes, a quick overview of the way a camera
+works is needed. If you're already familiar with this, you can skip ahead to
\l {camera-tldr}{Camera implementation details}.
+For a more detailed explanations of how a camera works, see the following YouTube
+clip.
+
+\youtube qS1FmgPVLqw
\section2 The Lens Assembly
+
At one end of the camera assembly is the lens assembly (one or
-more lenses, arranged to focus light onto the sensor). The lenses
-themselves can sometimes be moved to adjust things like focus and zoom,
-or they might be fixed in an arrangement to give a good balance between
-objects in focus, and cost.
+more lenses, arranged to focus light onto the sensor). The lenses
+themselves can sometimes be moved to adjust things like focus and zoom. They
+might also be fixed in an arrangement for a good balance between maintaining
+focus and cost.
+
+\image how-focus-works.gif "An animation of how focus works"
+
+\image Zoom.gif "An animation of how zoom works."
Some lens assemblies can automatically be adjusted so that
an object at different distances from the camera can be kept in focus.
This is usually done by measuring how sharp a particular area of the
-frame is, and by adjusting the lens assembly until it is maximally
-sharp. In some cases the camera will always use the center of the
-frame for this. Other cameras may also allow the region to focus
-to be specified (for "touch to zoom", or "face zoom" features).
+frame is, and then adjusting the lens assembly to find the peak sharpness. In
+some cases, the camera will always use the center of the frame for this.
+In other cases, a camera may also allow this target focus region to be specified.
+Some examples of this feature include:
+\list
+\li Face zoom: Using computer vision to detect and use one or more faces as the
+target.
+\li Touch to zoom: Enabling the user to manually select an area via the preview
+screen.
+\endlist
\section2 The Sensor
Once light arrives at the sensor, it gets converted into digital pixels.
This process can depend on a number of things but ultimately comes down
-to two things - how long the conversion is allowed to take, and how
-bright the light is. The longer a conversion can take, the better the
-quality. Using a flash can assist with letting more light hit the sensor,
+to two things:
+\list
+\li The length of time conversion is allowed to take. Also known as exposure
+time.
+\li How bright the light is.
+\endlist
+
+The longer a conversion is allowed to take, the better the resulting image
+quality. Using a flash can assist with letting more light hit the sensor,
allowing it to convert pixels faster, giving better quality for the same
-amount of time. Conversely, allowing a longer conversion time can let you
-take photos in darker environments, as long as the camera is steady.
+amount of time. Conversely, allowing a longer conversion time can let you
+take photos in darker environments, \b{as long as the camera is steady}. If the
+camera moves while the sensor is recording, the resulting image is blurred.
\section2 Image Processing
After the image has been captured by the sensor, the camera firmware performs
various image processing tasks on it to compensate for various sensor
-characteristics, current lighting, and desired image properties. Faster sensor
-pixel conversion times tend to introduce digital noise, so some amount of image
-processing can be done to remove this based on the camera sensor settings.
+characteristics, current lighting, and desired image properties. Faster sensor
+pixel conversion times may introduce digital noise, so some amount of image
+processing can be done to remove this, based on the camera sensor settings.
The color of the image can also be adjusted at this stage to compensate for
different light sources - fluorescent lights and sunlight give very different
appearances to the same object, so the image can be adjusted based on the
white balance of the picture (due to the different color temperatures of the
light sources).
+\image image_processing.png "5 examples of various image processing techniques."
Some forms of "special effects" can also be performed at this stage. Black
and white, sepia, or "negative" style images can be produced.
@@ -84,31 +84,24 @@ and white, sepia, or "negative" style images can be produced.
\section2 Recording for Posterity
Finally, once a perfectly focused, exposed and processed image has been
created, it can be put to good use. Camera images can be further processed
-by application code (for example, to detect barcodes, or to stitch together a
+by application code (for example, to detect bar-codes, or to stitch together a
panoramic image), or saved to a common format like JPEG, or used to create a movie.
Many of these tasks have classes to assist them.
\target camera-tldr
\section1 Camera Implementation Details
-\section2 Detecting and Selecting Camera
+\section2 Detecting and Selecting a Camera
-Before using the camera APIs, you should check that a camera is available at runtime. If there
-is none, you could for example disable camera related features in your application. To perform this
-check in C++, use the \l QCameraInfo::availableCameras() function, as shown in the example below:
+Before using the camera APIs, you should check that a camera is available at
+runtime. If there is none available, you could disable camera related features
+in your application. To perform this check in C++, use the
+\l QMediaDevices::videoInputs() function, as shown in the example below:
- \snippet multimedia-snippets/camera.cpp Camera overview check
-
-In QML, use the \l{QtMultimedia::QtMultimedia::availableCameras}{QtMultimedia.availableCameras}
-property:
-\qml
-Item {
- property bool isCameraAvailable: QtMultimedia.availableCameras.length > 0
-}
-\endqml
+ \snippet multimedia-snippets/camera.cpp Camera overview check
-After determining whether a camera is available, access it using the \l QCamera class in C++ or
-the \l Camera type in QML.
+Access a camera using the \l QCamera class in C++ or the \l Camera
+type in QML.
When multiple cameras are available, you can specify which one to use.
@@ -116,22 +109,19 @@ In C++:
\snippet multimedia-snippets/camera.cpp Camera selection
-In QML, you can set the \c Camera \l{Camera::deviceId}{deviceId} property. All available IDs can
-be retrieved from \l{QtMultimedia::QtMultimedia::availableCameras}{QtMultimedia.availableCameras}:
-
-\qml
-Camera {
- deviceId: QtMultimedia.availableCameras[0].deviceId
-}
-\endqml
-
-You can also select the camera by its physical position on the system rather than its device ID.
-This is useful on mobile devices, which often have a front-facing and a back-facing camera.
+In QML, you can select the camera by setting the \l{Camera::cameraDevice} property.
+You can also select a camera by its physical position on the system rather than
+by camera info. This is useful on mobile devices, which often have a
+front-facing and a back-facing camera.
In C++:
\snippet multimedia-snippets/camera.cpp Camera overview position
+
+In QML, you can set the \c Camera \l{Camera::cameraDevice}{cameraDevice} property.
+Available cameras can be retrieved with MediaDevices.videoInputs
+
In QML:
\qml
@@ -140,66 +130,65 @@ Camera {
}
\endqml
-If neither device ID nor position is specified, the default camera will be used. On desktop
-platforms, the default camera is set by the user in the system settings. On a mobile device, the
-back-facing camera is usually the default camera. You can get information about the default camera
-using \l QCameraInfo::defaultCamera() in C++ or
-\l{QtMultimedia::QtMultimedia::defaultCamera}{QtMultimedia.defaultCamera} in QML.
-\section2 Viewfinder
+If both QCameraDevice and position aren't specified, the default camera
+will be used. On desktop platforms, the default camera is set by the
+user in the system settings. On a mobile device, the back-facing camera
+is usually the default camera. You can get the default camera with
+QMediaDevices::defaultVideoInput() or MediaDevices.defaultVideoInput
+in QML.
+
+\section2 Preview
While not strictly necessary, it's often useful to be able to see
-what the camera is pointing at. Most digital cameras allow an image
-feed from the camera sensor at a lower resolution (usually up to
-the size of the display of the camera) so you can compose
-a photo or video, and then switch to a slower but higher resolution
-mode for capturing the image.
+what the camera is pointing at. This is known as a preview.
Depending on whether you're using QML or C++, you can do this in multiple ways.
-In QML, you can use \l Camera and \l VideoOutput together to show a
-simple viewfinder:
+In QML, you can use \l Camera and videoOutput together to monitor a
+captureSession.
\qml
-VideoOutput {
- source: camera
+Item {
+ VideoOutput {
+ id: output
+ anchors.fill: parent
+ }
+ CaptureSession {
+ videoOutput: output
- Camera {
- id: camera
- // You can adjust various settings in here
+ Camera {
+ // You can adjust various settings in here
+ }
}
}
\endqml
In C++, your choice depends on whether you are using widgets, or QGraphicsView.
-The \l QCameraViewfinder class is used in the widgets case, and \l QGraphicsVideoItem
+The \l QVideoWidget class is used in the widgets case, and \l QGraphicsVideoItem
is useful for QGraphicsView.
\snippet multimedia-snippets/camera.cpp Camera overview viewfinder
-For advanced usage (like processing viewfinder frames as they come, to detect
-objects or patterns), you can also derive from \l QAbstractVideoSurface and
-set that as the viewfinder for the QCamera object. In this case you will
-need to render the viewfinder image yourself.
+For advanced usage (like processing preview frames as they come, which enables
+detection of objects or patterns), you can also use your own QVideoSink and set
+that as the videoOutput for the QMediaCaptureSession. In this case, you will need to
+render the preview image yourself by processing the data received from the
+videoFrameChanged() signal.
\snippet multimedia-snippets/camera.cpp Camera overview surface
-On mobile devices, the viewfinder image might not always be in the orientation you would expect.
-The camera sensors on these devices are often mounted in landscape while the natural
-orientation of the screen is portrait. This results in the image appearing sideways or inverted
-depending on the device orientation. In order to reflect on screen what the user actually sees, you
-should make sure the viewfinder frames are always rotated to the correct orientation, taking into
-account the camera sensor orientation and the current display orientation.
-
- \snippet multimedia-snippets/camera.cpp Camera overview viewfinder orientation
+On mobile devices, the preview image is by default oriented in the same way as the device.
+Thus, as the user rotates the device, the preview image will switch between portrait and
+landscape mode. Once you start recording, the orientation will be locked. To avoid a poor
+user experience, you should also lock the orientation of the applications user interface
+while recording. This can be achieved using the
+\l{QWindow::contentOrientation}{contentOrientation} property of QWindow.
\section2 Still Images
-After setting up a viewfinder and finding something photogenic,
-to capture an image we need to initialize a new QCameraImageCapture
-object. All that is then needed is to start the camera, lock it so
-that things are in focus and the settings are not different from the
-viewfinder while the image capture occurs, capture the image, and
-finally unlock the camera ready for the next photo.
+After setting up a viewfinder and finding something photogenic, to capture an
+image we need to initialize a new QImageCapture object. All that is then
+needed is to start the camera and capture the image.
\snippet multimedia-snippets/camera.cpp Camera overview capture
@@ -213,90 +202,68 @@ well as creating a viewfinder, we will also initialize a media recorder object.
\snippet multimedia-snippets/camera.cpp Camera overview movie
-Signals from the \e mediaRecorder can be connected to slots to react to
-changes in the state of the recorder or error events. Recording itself
-starts with the \l {QMediaRecorder::record()}{record()} function of
-mediaRecorder being called, this causes the signal \l
-{QMediaRecorder::stateChanged()}{stateChanged()} to be emitted. The
-recording process can be changed with the \l {QMediaRecorder::record()}{record()},
-\l {QMediaRecorder::stop()}{stop()} and \l {QMediaRecorder::setMuted()}{setMuted()}
-slots in \l QMediaRecorder.
+Signals from the \e QMediaRecorder can be connected to slots to react to
+changes in the state of the encoding process or error events. Recording
+starts when \l QMediaRecorder::record() is called. This causes the signal
+\l{QMediaRecorder::}{recorderStateChanged()} to be emitted. Recording is
+controlled by the record(), stop(), and pause() slots of QMediaRecorder.
\section2 Controlling the Imaging Pipeline
-Now that the basics of capturing images or movies are covered, there are a number
+Now that the basics of capturing images and movies are covered, there are a number
of ways to control the imaging pipeline to implement some interesting techniques.
As explained earlier, several physical and electronic elements combine to determine
the final images, and you can control them with different classes.
\section3 Focus and Zoom
-Focusing (and zoom) is managed primarily by the \l QCameraFocus class.
-QCameraFocus allows the developer to set the general policy by means of the
-enums for the \l {QCameraFocus::FocusMode}{FocusMode} and the
-\l {QCameraFocus::FocusPointMode}{FocusPointMode}. \l {QCameraFocus::FocusMode}{FocusMode}
-deals with settings such as \l {QCameraFocus::FocusMode}{AutoFocus},
-\l {QCameraFocus::FocusMode}{ContinuousFocus} and \l {QCameraFocus::FocusMode}{InfinityFocus},
-whereas \l {QCameraFocus::FocusMode}{FocusPointMode} deals with the
-various focus zones within the view that are used for autofocus modes. \l {QCameraFocus::FocusMode}{FocusPointMode}
-has support for face recognition (where the camera supports it), center focus and a custom
-focus where the focus point can be specified.
+QCamera allows you to set the general focus policy by means of the
+enums for the \l {QCamera::FocusMode}{FocusMode}. \l {QCamera::FocusMode}{FocusMode}
+deals with settings such as \l {QCamera::FocusModeAuto},
+and \l {QCamera::FocusModeInfinity}.
-For camera hardware that supports it, \l {QCameraFocus::FocusMode}{Macro focus} allows
-imaging of things that are close to the sensor. This is useful in applications like
-barcode recognition, or business card scanning.
+For camera hardware that supports it, \l QCamera::FocusModeAutoNear allows
+imaging of things that are close to the sensor. This is useful in applications
+like bar-code recognition, or business card scanning.
-In addition to focus, QCameraFocus allows you to control any available optical or
-digital zoom. In general, optical zoom is higher quality, but more expensive to
-manufacture, so the available zoom range might be limited (or fixed to unity).
+In addition to focus, QCamera allows you to control any available zoom
+functionality using \l{QCamera::setZoomFactor}{setZoomFactor()} or
+\l{QCamera::zoomTo}{zoomTo()}. The
+available zoom range might be limited or entirely fixed to unity (1:1). The
+allowed range can be checked with \l{QCamera::minimumZoomFactor}{minimumZoomFactor()}
+and \l{QCamera::maximumZoomFactor}{maximumZoomFactor()}.
-\section3 Exposure, Aperture, Shutter Speed and Flash
+\section3 Exposure, Shutter Speed and Flash
There are a number of settings that affect the amount of light that hits the
-camera sensor, and hence the quality of the resulting image. The \l QCameraExposure
-class allows you to adjust these settings. You can use this class to implement
-some techniques like High Dynamic Range (HDR) photos by locking the exposure
-parameters (with \l {QCamera::searchAndLock()}), or motion blur by setting slow shutter speeds
-with small apertures.
-
-The main settings for automatic image taking are the \l {QCameraExposure::ExposureMode}{exposure mode}
-and \l {QCameraExposure::FlashMode}{flash mode}. Several other settings (aperture, ISO setting,
- shutter speed) are usually managed automatically but can also be overridden if desired.
-
-You can also adjust the \l {QCameraExposure::meteringMode()} to control which parts
-of the camera frame to measure exposure at. Some camera implementations also allow
-you to specify a specific point that should be used for exposure metering - this is
-useful if you can let the user touch or click on an interesting part of the viewfinder,
-and then use this point so that the image exposure is best at that point.
-
-Finally, you can control the flash hardware (if present) using this class. In some cases
-the hardware may also double as a torch (typically when the flash is LED based, rather than
-a xenon or other bulb). See also \l {Torch} for an easy to use API for
-torch functionality.
+camera sensor, and hence the quality of the resulting image.
+
+The main settings for automatic image taking are the
+\l {QCamera::ExposureMode}{exposure mode} and \l {QCamera::FlashMode}{flash mode}.
+Several other settings (such as: ISO setting and exposure time) are usually
+managed automatically, but can also be overridden if desired.
+
+Finally, you can control the flash hardware (if present) using this class. In
+some cases the hardware may also double as a torch.
\target camera_image_processing
\section3 Image Processing
-The QCameraImageProcessing class lets you adjust the image processing
-part of the pipeline. This includes the \l {QCameraImageProcessing::WhiteBalanceMode}{white balance}
-(or color temperature), \l {QCameraImageProcessing::contrast()}{contrast},
-\l {QCameraImageProcessing::saturation()}{saturation}, \l {QCameraImageProcessing::setSharpeningLevel()}{sharpening}
-and \l {QCameraImageProcessing::setDenoisingLevel()}{denoising}. Most cameras support automatic settings
-for all of these, so you shouldn't need to adjust them unless the user wants a specific setting.
+The QCamera class lets you adjust the image processing part of the pipeline.
+These settings include:
+\list
+ \li \l {QCamera::WhiteBalanceMode}{white balance}
+ (also known as color temperature)
+\endlist
-If you're taking a series of images (for example, to stitch them together for
-a panoramic image), you should lock the image processing settings so that all the
-images taken appear similar with \e {QCamera::searchAndLock(QCamera::LockWhiteBalance)}/
+Most cameras support automatic settings for all of these, so you shouldn't need
+to adjust them unless the user wants a specific setting.
\section3 Canceling Asynchronous Operations
-Various operations such as image capture and auto focusing occur
-asynchrously. These operations can often be canceled by the start of a new
-operation as long as this is supported by the camera. For image capture,
-the operation can be canceled by calling
-\l {QCameraImageCapture::cancelCapture()}{cancelCapture()}. For AutoFocus,
-autoexposure or white balance cancellation can be done by calling
-\e {QCamera::unlock(QCamera::LockFocus)}.
+Various operations, such as image capture and auto focusing, occur asynchronously.
+These operations can often be canceled by the start of a new operation, as long
+as this is supported by the camera.
\section1 Examples
diff --git a/src/multimedia/doc/src/changes.qdoc b/src/multimedia/doc/src/changes.qdoc
deleted file mode 100644
index fd7188fa3..000000000
--- a/src/multimedia/doc/src/changes.qdoc
+++ /dev/null
@@ -1,140 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
-
-\page changes.html
-\title Changes in Qt Multimedia
-\brief A description of changes in this version of Qt Multimedia
-
-
-The Qt Multimedia module in Qt 5 combines (and replaces) two older modules, namely the
-Qt Multimedia module from Qt 4.x, and Qt Multimedia Kit module from Qt Mobility.
-Existing code that uses Qt Multimedia from Qt 4 can be ported with minimal effort, but
-porting code that uses Qt Multimedia Kit may be a more involved process. The
-\l {changed features} section highlights changes relevant to porting.
-
-Also, note that widget-based classes, such as \l QVideoWidget, are now in a separate
-module called Qt Multimedia Widgets.
-
-\section1 New features in Qt 5.0
-
-There are a number of new features in Qt Multimedia:
-\list
-\li Expanded QML API
-\li In addition to the \l Video QML type, there is now the option of using \l MediaPlayer and \l VideoOutput together
-\li QML \l Torch class
-\li New \l QAudioRecorder class
-\li Volume support for QAudioOutput and QAudioInput
-\li More examples and documentation
-\li QSound moved from Qt GUI to Qt Multimedia
-\li QSoundEffect available to C++ now, as well as QML
-\li Various other API improvements and bugfixes
-\endlist
-
-
-\section1 Removed features
-
-A number of classes or features previously offered in Qt Multimedia or Qt Multimedia Kit have
-been removed.
-
-\table 70%
- \header
- \li Removed feature
- \li Notes
- \row
- \li QMediaImageViewer
- \li This class (and related controls and services) were removed since
- their functionality was not suitable for many applications
-\endtable
-
-\section1 Changed features
-
-A number of classes previously offered in Qt Multimedia or Qt Multimedia Kit have
-changed in ways that may affect previously written code. This table highlights such changes.
-
-\table 70%
- \header
- \li Changed feature
- \li Notes
- \row
- \li \c qmake project file changes
- \li Previously, to use Qt Multimedia Kit, the \c qmake project file must contain
- \code
- CONFIG += mobility
- MOBILITY += multimedia
- \endcode
- Now, you only need to write
- \code
- QT += multimedia
- \endcode
- Or, if you want to use the widget classes,
- \code
- QT += multimedia multimediawidgets
- \endcode
- \row
- \li Namespaces
- \li The \c QtMultimediaKit namespace has been renamed to QMultimedia. This
- affects a few enumerations, namely \c SupportEstimate, \c EncodingQuality,
- \c EncodingMode and \c AvailabilityStatus. Searching and replacing
- \c QtMultimediaKit with \c QMultimedia will greatly aid porting efforts. Metadata
- have been split off into their own namespace, QMediaMetaData.
- \row
- \li Metadata types
- \li In Qt Multimedia Kit, pre-defined metadata keys were enumerations in the
- \c QtMultimediaKit namespace. These pre-defined keys have been changed to
- string literals in the \c QMediaMetaData namespace, for consistency with
- extended keys.
- \row
- \li Metadata accessor methods
- \li In Qt Multimedia Kit, there were two different families of methods to access
- metadata. Functions such as \c QMediaObject::metaData() operated on pre-defined
- metadata using enumerated keys, while functions such as
- \c QMediaObject::extendedMetaData() operated on extended metadata using
- string keys. Qt 5 combines both families into one (e.g. QMediaObject::metaData()),
- which can operate on both pre-defined and extended metadata, using string keys.
- \row
- \li Qt Metatype registration
- \li Qt 5 registers many more classes and types with the meta-object system than before.
- If you have previously applied Q_DECLARE_METATYPE macros to any Qt Multimedia class,
- you will probably need to remove them.
- \row
- \li QSoundEffect availability
- \li The SoundEffect QML type was publicly accessible in Qt Multimeda Kit,
- and now the C++ version is officially public too. If your code contains the
- previously undocumented QSoundEffect, you may need to update it.
- \row
- \li Camera controls
- \li A large number of the camera controls (QCameraImageProcessingControl,
- QCameraFocusControl, etc.) have been updated to address a number of
- design flaws. In particular, a number of discrete
- accessor methods have been collapsed into parametrized methods, and
- the ranges or data types of some parameters have been adjusted.
-
-\endtable
-
-*/
diff --git a/src/multimedia/doc/src/examples/video-qml-paint-rate.qdocinc b/src/multimedia/doc/src/examples/video-qml-paint-rate.qdocinc
index 860f14270..34f7df319 100644
--- a/src/multimedia/doc/src/examples/video-qml-paint-rate.qdocinc
+++ b/src/multimedia/doc/src/examples/video-qml-paint-rate.qdocinc
@@ -2,7 +2,7 @@ The QML painting rate is calculated by the FrequencyMonitor class, which
turns a stream of events (received via the notify() slot), into an
instantaneous and an averaged frequency:
-\quotefromfile multimedia/video/snippets/frequencymonitor/frequencymonitor.h
+\quotefromfile video/qmlvideo/frequencymonitor.h
\skipto class FrequencyMonitor : public QObject
\printuntil Q_OBJECT
\skipto Q_PROPERTY(qreal instantaneousFrequency
@@ -19,13 +19,13 @@ instantaneous and an averaged frequency:
The FrequencyMonitor class is exposed to QML like this
-\quotefromfile multimedia/video/snippets/frequencymonitor/frequencymonitordeclarative.cpp
+\quotefromfile video/qmlvideo/frequencymonitordeclarative.cpp
\skipto FrequencyMonitor::qmlRegisterType
\printuntil }
and its data is displayed by defining a QML item called FrequencyItem, like this:
-\quotefromfile multimedia/video/snippets/frequencymonitor/qml/frequencymonitor/FrequencyItem.qml
+\quotefromfile video/qmlvideo/frequencymonitor/FrequencyItem.qml
\skipto import FrequencyMonitor
\printuntil id: root
\dots
@@ -39,5 +39,3 @@ and its data is displayed by defining a QML item called FrequencyItem, like this
The result looks like this:
\image video-qml-paint-rate.png
-
-
diff --git a/src/multimedia/doc/src/images/Zoom.gif b/src/multimedia/doc/src/images/Zoom.gif
new file mode 100644
index 000000000..dfba0faf1
--- /dev/null
+++ b/src/multimedia/doc/src/images/Zoom.gif
Binary files differ
diff --git a/src/multimedia/doc/src/images/camera_correctionAngle_90.png b/src/multimedia/doc/src/images/camera_correctionAngle_90.png
new file mode 100644
index 000000000..7a3c169a5
--- /dev/null
+++ b/src/multimedia/doc/src/images/camera_correctionAngle_90.png
Binary files differ
diff --git a/src/multimedia/doc/src/images/how-focus-works.gif b/src/multimedia/doc/src/images/how-focus-works.gif
new file mode 100644
index 000000000..a691b49ac
--- /dev/null
+++ b/src/multimedia/doc/src/images/how-focus-works.gif
Binary files differ
diff --git a/src/multimedia/doc/src/images/image_processing.png b/src/multimedia/doc/src/images/image_processing.png
new file mode 100644
index 000000000..2a52fbce3
--- /dev/null
+++ b/src/multimedia/doc/src/images/image_processing.png
Binary files differ
diff --git a/src/multimedia/doc/src/images/noun_Media_166644.svg b/src/multimedia/doc/src/images/noun_Media_166644.svg
new file mode 100644
index 000000000..cc2fa8d83
--- /dev/null
+++ b/src/multimedia/doc/src/images/noun_Media_166644.svg
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ version="1.1"
+ x="0px"
+ y="0px"
+ viewBox="0 0 97.908676 59.1375"
+ enable-background="new 0 0 100 100"
+ xml:space="preserve"
+ id="svg26"
+ sodipodi:docname="noun_Media_166644.svg"
+ width="97.908676"
+ height="59.137501"
+ inkscape:version="1.0.2 (e86c870879, 2021-01-15, custom)"><metadata
+ id="metadata32"><rdf:RDF><cc:Work
+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
+ id="defs30" /><sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="2560"
+ inkscape:window-height="1377"
+ id="namedview28"
+ showgrid="false"
+ inkscape:zoom="8.064"
+ inkscape:cx="32.007416"
+ inkscape:cy="20.413416"
+ inkscape:window-x="1912"
+ inkscape:window-y="-8"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="svg26"
+ inkscape:document-rotation="0" /><g
+ transform="matrix(0.13985577,0,0,-0.1432582,-21.001292,1300.868)"
+ id="g20"><path
+ d="m 467.5,9080.3 c -2.1,-0.6 -3.7,-1.9 -4.6,-3.7 -0.7,-1.4 -0.8,-6.7 -0.8,-48.2 v -46.6 h 7.1 7.1 v 23.6 23.6 h 105.1 105.1 v -47.8 c 0,-26.2 0.1,-47.8 0.4,-47.8 0.2,0 3.2,0.6 6.7,1.4 l 6.4,1.3 0.1,69.7 c 0.1,68.3 0.1,69.7 -0.8,71.2 -0.5,0.9 -1.7,2 -2.6,2.5 -1.5,0.8 -6.9,0.9 -114.9,1 -62.1,0.2 -113.6,0 -114.3,-0.2 z m 32.5,-25.6 v -11.8 h -11.8 -11.8 v 11.8 11.8 h 11.8 11.8 z m 37.4,0 v -11.8 h -11.6 -11.6 v 11.8 11.8 h 11.6 11.6 z m 37.5,0 v -11.8 h -11.6 -11.6 v 11.8 11.8 h 11.6 11.6 z m 37.4,0 v -11.8 h -11.6 -11.6 v 11.8 11.8 h 11.6 11.6 z m 37.4,0 v -11.8 h -11.6 -11.6 v 11.8 11.8 h 11.6 11.6 z m 36.9,0 v -11.8 H 675.3 664 v 11.8 11.8 h 11.3 11.3 z"
+ id="path2" /><path
+ d="m 546,9008.9 c -1.2,-0.5 -2.5,-1.7 -3.1,-2.6 -1,-1.6 -1,-2.4 -1,-53.2 0,-46.4 0.1,-51.8 0.8,-53.3 1.1,-2.2 3.4,-3.6 6.2,-3.6 2,0 5.2,1.9 43.5,25.4 22.7,14 41.8,25.9 42.4,26.4 2.7,2.4 2.5,7.2 -0.2,9.8 -2.5,2.3 -83.1,51.5 -84.8,51.8 -1.2,0.2 -2.4,0 -3.8,-0.7 z m 41.8,-38.4 c 21.8,-13.4 28.3,-17.6 27.8,-18 -0.7,-0.7 -58.2,-36.1 -59.2,-36.5 -0.6,-0.2 -0.7,5.8 -0.7,37 v 37.3 l 1.9,-1.1 c 1,-0.7 14.6,-9.1 30.2,-18.7 z"
+ id="path4" /><path
+ d="m 179,8967.7 c -2.5,-0.4 -7.7,-2.3 -10.3,-3.6 -8.4,-4.4 -14.3,-11.9 -17.3,-21.7 l -1.1,-3.6 -0.1,-80.3 c -0.1,-54.6 0,-81.7 0.4,-84.8 1.8,-16.1 13.6,-28.6 29.5,-31.1 2.2,-0.4 49.5,-0.5 149.2,-0.5 120.1,0 146.6,0.1 149.7,0.7 10.8,2 20,8.9 24.9,18.7 3.9,7.9 3.6,2.1 3.6,93.6 0,90.9 0.2,85.5 -3.4,93 -4.6,9.6 -12.9,16.3 -23.3,19 -3.8,1 -5.4,1 -152.1,0.9 -81.8,-0.1 -149,-0.2 -149.7,-0.3 z m 297.5,-14 c 7.9,-1.7 14.6,-8.5 16.1,-16.7 0.7,-3.7 0.7,-159.8 0,-163.7 -1.4,-7.8 -7.3,-14.2 -14.8,-16.2 -2.9,-0.8 -13.8,-0.8 -150.6,-0.7 l -147.5,0.1 -3.3,1.6 c -4.4,2.1 -8.3,6 -10.3,10.3 l -1.6,3.3 -0.1,82.2 c -0.1,81.1 -0.1,82.3 0.9,85.5 2.2,7.1 9,13.2 16.2,14.4 0.7,0.1 66.8,0.2 146.8,0.3 104.9,0.1 146.3,0 148.2,-0.4 z"
+ id="path6" /><path
+ d="m 194,8929.6 c -0.8,-0.5 -1.9,-1.7 -2.3,-2.6 -0.8,-1.5 -0.9,-5.9 -0.9,-72.1 v -70.5 l 1.1,-1.7 c 0.7,-1 2,-2 3.4,-2.6 2.3,-1 2.3,-1 4.6,0 1.4,0.6 2.8,1.6 3.4,2.6 l 1.1,1.7 v 70.4 c 0,78 0.2,72.6 -3.2,74.7 -1.9,1.4 -5.2,1.4 -7.2,0.1 z"
+ id="path8" /><path
+ d="m 412.5,8929.8 c -3,-1 -7.1,-5 -8.5,-8.1 -1.1,-2.5 -1.2,-3.1 -1.2,-13.2 0,-12.4 0.3,-13.9 4.3,-18.1 4.3,-4.5 4.4,-4.6 27.4,-4.6 23,0 23.1,0 27.4,4.6 4,4.2 4.3,5.7 4.3,18.1 0,10.1 0,10.7 -1.2,13.2 -1.5,3.2 -5.6,7.1 -8.7,8.2 -3.3,1 -40.6,1 -43.8,-0.1 z m 39.5,-21.6 v -8.4 H 434.5 417 l -0.1,7.9 c 0,4.3 0,8.1 0.1,8.5 0.2,0.5 3.7,0.6 17.6,0.5 l 17.4,-0.1 z"
+ id="path10" /><path
+ d="m 318.8,8917.6 c -9.3,-1.5 -19.2,-5.4 -26.7,-10.4 -4.8,-3.2 -12.8,-11 -16.2,-15.8 -8.2,-11.4 -12.4,-24.3 -12.4,-38.3 0,-17 6.2,-32.4 17.8,-44.7 16.4,-17.2 40.3,-24.2 63.3,-18.4 25.8,6.5 44.8,28 48.6,54.9 0.7,5.1 0.3,16.2 -0.7,21.2 -2.9,13 -8.7,23.8 -18,33 -9.3,9.3 -19.3,14.8 -32.5,17.8 -5.7,1.2 -17.5,1.6 -23.2,0.7 z m 16.7,-13.8 c 6.7,-0.6 15.6,-4.1 22.5,-8.8 4.5,-3 10.1,-8.9 13.5,-14.1 10,-15.5 11,-34.7 2.5,-51.2 -6.7,-13 -18.1,-22.2 -32.9,-26.2 -3.2,-0.9 -5.2,-1.1 -12.4,-1.1 -10,0 -13.8,0.7 -21.5,4.3 -10.8,5.1 -18.7,12.7 -24,22.9 -4.3,8.3 -6.1,16.5 -5.6,26 0.4,7.1 1.7,12.7 4.5,18.6 3,6.2 5.2,9.5 9.9,14.3 8.3,8.7 19.6,14.2 31.7,15.4 3.7,0.5 5.6,0.5 11.8,-0.1 z"
+ id="path12" /><path
+ d="m 326,8893.5 c -0.8,-0.3 -2,-1.3 -2.7,-2 -1,-1.1 -1.2,-1.8 -1.2,-4.5 0,-3.1 0.1,-3.2 1.8,-4.8 1.3,-1.2 2.4,-1.7 4.2,-1.9 9.7,-1.1 13.8,-2.8 19,-7.6 4.8,-4.4 8.2,-11.6 8.3,-17 0,-4.7 2.1,-8.2 5.4,-9.1 3.7,-1 8,1.6 8.7,5.3 0.5,2.6 -0.5,10 -1.9,14.1 -2.3,6.8 -5.4,11.6 -10.5,16.5 -6.3,6.1 -13.1,9.6 -21.6,11 -5.4,0.8 -7.6,0.8 -9.5,0 z"
+ id="path14" /><path
+ d="m 752.2,8933.3 c -49.4,-10.4 -90.3,-19.3 -90.9,-19.7 -0.6,-0.4 -1.6,-1.3 -2,-2.1 -0.8,-1.3 -0.9,-6 -1.1,-81.5 l -0.2,-80.2 -3.3,2.7 c -4.3,3.4 -10.8,6.8 -16.3,8.5 -4.1,1.3 -5,1.4 -13,1.4 -7.9,0 -9,-0.1 -12.9,-1.3 -16.9,-5.2 -28.9,-17.6 -33.7,-35 -0.6,-2.4 -0.8,-5 -0.8,-11.4 0,-7.7 0.1,-8.8 1.4,-12.8 5.4,-17.7 19.6,-30.6 37.5,-33.7 4.6,-0.8 15.7,-0.4 19.9,0.7 17.2,4.7 29.5,17.1 34.6,35.1 l 1.1,3.8 0.1,65 0.1,65 81.2,17.7 c 44.7,9.7 81.4,17.5 81.6,17.3 0.2,-0.2 0.4,-21.2 0.5,-46.7 0.1,-45.5 0.1,-46.3 -0.8,-45.6 -0.5,0.4 -2.5,1.9 -4.3,3.2 -11,8.4 -26.3,11.5 -39.9,8 -4.5,-1.1 -12.1,-4.6 -15.7,-7.3 -13.4,-9.7 -20.8,-25.1 -19.8,-41.4 0.7,-12 5,-21.9 13.3,-30.5 9.3,-9.6 20.8,-14.5 34,-14.5 13,0 24.7,4.9 34,14.3 5.7,5.8 9.7,12.8 12.2,21.7 l 1.1,3.8 0.1,104.4 c 0.1,98.8 0,104.5 -0.7,106.1 -1.2,2.2 -3,3.5 -5.4,3.8 -1.5,0.1 -32.1,-6.2 -91.9,-18.8 z m 84.1,-21.2 v -24.4 l -1.1,-0.2 c -3,-0.7 -159.4,-34.7 -161,-35 l -1.8,-0.3 0.1,25 0.1,25 81,17.1 c 44.6,9.4 81.4,17.1 81.9,17.1 0.7,0.1 0.8,-1.4 0.8,-24.3 z m -27.8,-133.7 c 10,-1.8 19.4,-8.9 23.8,-17.9 2.6,-5.2 3.5,-9.4 3.6,-14.8 0,-5.9 -0.8,-9.4 -3.4,-15 -3.8,-8 -11.2,-14.4 -19.8,-17.2 -6.8,-2.3 -16.7,-1.7 -23.5,1.2 -9.2,4.1 -16.7,13 -19.2,22.8 -1.1,4.4 -0.7,13.9 0.7,18.3 1.6,4.8 4.4,9.2 8.5,13.3 7.7,7.8 18.7,11.3 29.3,9.3 z m -176.8,-30.7 c 9.8,-2.1 18.5,-9 23,-18.2 5.5,-11.5 4.2,-24.4 -3.7,-35.1 -5.7,-7.7 -16.2,-12.9 -26.1,-12.9 -10.2,0 -20.8,5.1 -26.7,12.9 -7.8,10.3 -9.2,23.6 -3.6,35.1 3.5,7.2 8.7,12.3 16.1,15.9 6.2,2.9 13.9,3.8 21,2.3 z"
+ id="path16" /><path
+ d="m 521.7,8874 v -6.9 h 7.9 7.9 v -11.6 -11.5 h -7.9 -7.9 v -7.1 -7.1 h 61.5 61.5 v 7.1 7.1 h -9.1 -9.1 v 11.6 11.6 h 9.1 9.1 v 6.9 6.9 h -61.5 -61.5 z m 53.2,-18.5 V 8844 h -11.6 -11.6 v 11.6 11.6 h 11.6 11.6 z m 37.4,0 V 8844 h -11.6 -11.6 v 11.6 11.6 h 11.6 11.6 z"
+ id="path18" /></g></svg>
diff --git a/src/multimedia/doc/src/images/qS1FmgPVL.jpg b/src/multimedia/doc/src/images/qS1FmgPVL.jpg
new file mode 100644
index 000000000..4dc2bb7c2
--- /dev/null
+++ b/src/multimedia/doc/src/images/qS1FmgPVL.jpg
Binary files differ
diff --git a/src/multimedia/doc/src/images/sound-wave-small.jpg b/src/multimedia/doc/src/images/sound-wave-small.jpg
new file mode 100644
index 000000000..1a873d94d
--- /dev/null
+++ b/src/multimedia/doc/src/images/sound-wave-small.jpg
Binary files differ
diff --git a/src/multimedia/doc/src/multimedia-overview.qdoc b/src/multimedia/doc/src/multimedia-overview.qdoc
new file mode 100644
index 000000000..6da54a7e2
--- /dev/null
+++ b/src/multimedia/doc/src/multimedia-overview.qdoc
@@ -0,0 +1,142 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+
+
+/*!
+\page multimediaoverview.html
+\title Multimedia Overview
+\brief A set of APIs for working with audio, video and camera devices.
+\ingroup explanations-graphicsandmultimedia
+
+Multimedia support in Qt is provided by the \l{Qt Multimedia} module. The Qt
+Multimedia module provides a rich feature set that enables you to easily take
+advantage of a platform's multimedia capabilities, such as media playback and
+the use of camera devices.
+
+\section1 Features
+
+Here are some things you can do with the Qt Multimedia APIs:
+
+\list
+\li Access raw audio devices for input and output.
+\li Play low latency sound effects.
+\li Play 3D spatial audio.
+\li Play media files in playlists (such as compressed audio or video files).
+\li Record audio and compress it.
+\li Use a camera, including viewfinder, image capture, and movie recording
+\li Decode audio media files into memory for processing.
+\endlist
+
+\section1 Multimedia Components
+
+The Qt Multimedia APIs are categorized into three main components. More
+information specific to each component is available in the overview pages. You
+can also take a look at some \l{Multimedia Recipes}{recipes}.
+
+\list
+\li \l {Audio Overview}
+\li \l {Video Overview}
+\li \l {Camera Overview}
+\li \l {Spatial Audio Overview} (Technology Preview)
+\endlist
+
+\section1 Multimedia Recipes
+
+For some quick recipes, see this table:
+
+\table 70%
+ \header
+ \li Use case
+ \li Examples
+ \li QML Types
+ \li C++ Classes
+ \row
+ \li Playing a sound effect
+ \li
+ \li \l{SoundEffect}
+ \li QSoundEffect
+ \row
+ \li Playing 3D sound
+ \li \l{Spatial Audio Panning Example}{audiopanning}
+ \li SpatialSound, AudioEngine
+ \li QSpatialSound, QAudioEngine
+ \row
+ \li Playing encoded audio (MP3, AAC etc)
+ \li \l{Media Player Example}{player}
+ \li \l{MediaPlayer}
+ \li QMediaPlayer
+ \row
+ \li Playing raw audio data with low latency
+ \li \l{Audio Output Example}{audiooutput}
+ \li
+ \li QAudioSink
+ \row
+ \li Accessing raw audio input data
+ \li \l{Spectrum Example}{spectrum},
+ \l{Audio Source Example}{audiosource}
+ \li
+ \li QAudioSource
+ \row
+ \li Recording encoded audio data
+ \li \l{Audio Recorder Example}{audiorecorder}
+ \li \l{CaptureSession}, \l{AudioInput}, \l{MediaRecorder}
+ \li QMediaCaptureSession, QAudioInput, QMediaRecorder
+ \row
+ \li Discovering audio and video devices
+ \li \l{Audio Devices Example}{audiodevices}
+ \li \l{MediaDevices}, \l{audioDevice}, \l{cameraDevice}
+ \li QMediaDevices, QAudioDevice, QCameraDevice
+ \row
+ \li Video Playback
+ \li \l{Media Player Example}{player},
+ \l{QML Media Player Example}{mediaplayer}
+ \li \l MediaPlayer, \l VideoOutput, \l Video
+ \li QMediaPlayer, QVideoWidget, QGraphicsVideoItem
+ \row
+ \li Capturing audio and video
+ \li \l {Camera Example}{camera},
+ \l {QML Video Recorder}{recorder}
+ \li \l CaptureSession, \l Camera, \l AudioInput \l VideoOutput
+ \li QMediaCaptureSession, QCamera, QAudioInput, QVideoWidget
+ \row
+ \li Capturing photos
+ \li \l {Camera Example}{camera},
+ \l {QML Video Recorder}{recorder}
+ \li \l CaptureSession, \l Camera, \l ImageCapture
+ \li QMediaCaptureSession, QCamera, QImageCapture
+ \row
+ \li Capturing movies
+ \li \l {Camera Example}{camera},
+ \l {QML Video Recorder}{recorder}
+ \li \l CaptureSession, \l Camera, \l MediaRecorder
+ \li QMediaCaptureSession, QCamera, QMediaRecorder
+\endtable
+
+\section1 Limitations
+
+The Qt Multimedia APIs build upon the multimedia framework of the underlying
+platform. This can mean that support for various codecs, or containers will vary
+between machines. This support depends on what the end user has installed.
+See \l{Supported Media Formats} for more detail.
+
+\note Qt Multimedia APIs depend on functionality provided by QCoreApplication,
+and multimedia objects created using the Qt Multimedia APIs can only be used
+during the lifetime of this application object. It is therefore important to
+create a QCoreApplication, QGuiApplication, or QApplication before accessing
+any of the Qt Multimedia APIs. If the application object is recreated, make
+sure that any Qt Multimedia objects are also recreated.
+
+\section1 Changes from Previous Versions
+
+If you previously used Qt Multimedia in Qt 5, see
+\l{Changes to Qt Multimedia} for more information on what has changed, and what
+you might need to change when porting code to Qt 6.
+
+\section1 Reference Documentation
+
+\list
+ \li \l{Qt Multimedia C++ Classes}{C++ Classes}
+ \li \l{Qt Multimedia QML Types}{QML Types}
+\endlist
+*/
diff --git a/src/multimedia/doc/src/multimedia.qdoc b/src/multimedia/doc/src/multimedia.qdoc
deleted file mode 100644
index dcf394c87..000000000
--- a/src/multimedia/doc/src/multimedia.qdoc
+++ /dev/null
@@ -1,186 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
-\page multimediaoverview.html
-\title Multimedia
-\brief A set of APIs for working with audio, video and camera devices.
-
-Multimedia support in Qt is provided by the \l{Qt Multimedia} module. The Qt
-Multimedia module provides a rich feature set that enables you to easily take
-advantage of a platform's multimedia capabilities such as media playback and
-the use of camera devices.
-
-\section1 Features
-
-Here are some examples of what can be done with Qt Multimedia APIs:
-
-\list
-\li Access raw audio devices for input and output
-\li Play low latency sound effects
-\li Play media files in playlists (such as compressed audio or video files)
-\li Record audio and compress it
-\li Use a camera, including viewfinder, image capture, and movie recording
-\li Play 3D positional audio with \l{Qt Audio Engine QML Types}{Qt Audio Engine}
-\li Decode audio media files into memory for processing
-\li Accessing video frames or audio buffers as they are played or recorded
-\endlist
-
-\section1 Multimedia Components
-
-Qt's multimedia APIs are categorized into four main components. More
-information (including background information and class references) is
-available here:
-
-\list
-\li \l {Audio Overview}
-\li \l {Video Overview}
-\li \l {Camera Overview}
-\endlist
-
-\section1 Multimedia Recipes
-
-For some quick recipes, look at the overviews above and consult this table:
-
-\table 70%
- \header
- \li Use case
- \li Examples
- \li QML Types
- \li C++ Classes
- \row
- \li Playing a sound effect
- \li
- \li
- \li QSoundEffect
- \row
- \li Playing low latency audio
- \li \l{Audio Input Example}{audioinput},
- \l{Spectrum Example}{spectrum}
- \li
- \li QAudioOutput
- \row
- \li Playing encoded audio (MP3, AAC etc)
- \li \l{Media Player Example}{player}
- \li \l Audio, \l {MediaPlayer}
- \li QMediaPlayer
- \row
- \li Accessing raw audio input data
- \li \l{Spectrum Example}{spectrum},
- \l{Audio Input Example}{audioinput}
- \li
- \li QAudioInput
- \row
- \li Recording encoded audio data
- \li \l{Audio Recorder Example}{audiorecorder}
- \li
- \li QAudioRecorder
- \row
- \li Discovering raw audio devices
- \li \l{Audio Devices Example}{audiodevices}
- \li
- \li QAudioDeviceInfo
- \row
- \li Video Playback
- \li \l{Media Player Example}{player},
- \l{QML Video Example}{qmlvideo},
- \l{QML Video Shader Effects Example}{qmlvideofx}
- \li \l MediaPlayer, \l VideoOutput, \l Video
- \li QMediaPlayer, QVideoWidget, QGraphicsVideoItem
- \row
- \li Video Processing
- \li \l {QML Video Example}{qmlvideofx}
- \li \l {MediaPlayer}, \l VideoOutput
- \li QMediaPlayer, QAbstractVideoSurface, QVideoFrame
- \row
- \li Accessing camera viewfinder
- \li \l {Camera Example}{camera},
- \l {QML Camera Example}{declarative-camera}
- \li \l Camera, \l VideoOutput
- \li QCamera, QVideoWidget, QGraphicsVideoItem
- \row
- \li Viewfinder processing
- \li
- \li \l Camera, \l VideoOutput
- \li QCamera, QAbstractVideoSurface, QVideoFrame
- \row
- \li Capturing photos
- \li \l {Camera Example}{camera},
- \l {QML Camera Example}{declarative-camera}
- \li \l Camera
- \li QCamera, QCameraImageCapture
- \row
- \li Capturing movies
- \li \l {Camera Example}{camera},
- \l {QML Camera Example}{declarative-camera}
- \li \l Camera
- \li QCamera, QMediaRecorder
- \row
- \li 3D sound sources
- \li
- \li \l {AudioEngine Example}{Audio Engine}
- \li \l {AudioEngine}, \l Sound
- \li
-\endtable
-
-\section1 Limitations
-
-The Qt Multimedia APIs build upon the multimedia framework of the underlying
-platform. This can mean that support for various codecs or containers can vary
-between machines, depending on what the end user has installed.
-
-\section1 Advanced Usage
-
-For developers wishing to access some platform specific settings, or to port the
-Qt Multimedia APIs to a new platform or technology, see \l{Multimedia Backend
-Development}.
-
-\section1 Changes from Previous Versions
-
-If you previously used Qt Multimedia in Qt 4, or used Qt Multimedia Kit in
-Qt Mobility, please see \l {Changes in Qt Multimedia} for more information on
-what changed, and what you might need to change when porting code.
-
-\section1 Reference Documentation
-
-\section2 QML Types
-The QML types are accessed by using:
-\code
-import QtMultimedia 5.8
-\endcode
-\annotatedlist multimedia_qml
-The following types are accessed by using \l{Qt Audio Engine QML Types}{Qt Audio Engine}:
-\qml \QtMinorVersion
-import QtAudioEngine 1.\1
-\endqml
-\annotatedlist multimedia_audioengine
-
-\section2 Multimedia Classes
-
-\annotatedlist multimedia
-
-*/
diff --git a/src/multimedia/doc/src/multimediabackend.qdoc b/src/multimedia/doc/src/multimediabackend.qdoc
deleted file mode 100644
index 48d598999..000000000
--- a/src/multimedia/doc/src/multimediabackend.qdoc
+++ /dev/null
@@ -1,139 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-/*!
-
-\title Multimedia Backend Development
-\page multimediabackend.html
-\brief Information for implementing a new multimedia backend.
-\ingroup mobility
-
-\tableofcontents
-
-\section1 Overview
-
-A multimedia backend provides the glue between platform-specific libraries, and
-Qt Multimedia. In some cases the available cross-platform Multimedia APIs or
-implementations are not sufficient, or not immediately available on a certain
-platform. Alternatively, the multimedia implementation on a platform might expose
-certain extra properties or functionality that other platforms do not, or a finer
-degree of control might be possible. For these cases, it is possible to use
-extended controls directly.
-\omit
-In addition, if you plan to port the Qt Multimedia APIs to a new platform, you do
-this by implementing certain control and service classes, as detailed below.
-
-\section1 Extending the API
-
-For the developer who wishes to extend the functionality of the Qt Multimedia
-classes there are several classes of particular importance. The classes
-providing default functionality are QMediaService, QMediaServiceProvider and
-QMediaControl. Some of these classes are not in the public API since they
-are very seldom useful to application developers.
-
-To extend the Multimedia API you would use the following three classes or
-classes derived from them.
-
- \list
- \li QMediaServiceProvider is used by the top level client class to
- request a service. The top level class knowing what kind of service it needs.
-
- \li \l QMediaService provides a service and when asked by the top level
- object, say a component, will return a QMediaControl object.
-
- \li \l QMediaControl allows the control of the service using a known interface.
- \endlist
-
-Consider a developer creating, for example, a media player class called MyPlayer.
-It may have special requirements beyond ordinary media players and so may
-need a custom service and a custom control. We can subclass QMediaServiceProvider
-to create our MyServiceProvider class. Also we will create a
-MyMediaService, and the MyMediaControl to manipulate the media service.
-
-The MyPlayer object calls MyServiceProvider::requestService() to get an
-instance of MyMediaService. Then the MyPlayer object calls this service
-object it has just received and calling \l {QMediaService::requestControl()}{requestControl()}
-it will receive the control object derived from QMediaControl.
-
-Now we have all the parts necessary for our media application. We have the service
-provider, the service it provides and the control used to manipulate the
-service. Since our MyPlayer object has instances of the service and its
-control then it would be possible for these to be used by associated classes
-that could do additional actions, perhaps with their own control since the
-parameter to requestControl() is a zero-terminated string, \e {const char *},
-for the interface.
-
-\section2 Adding a Media Service Provider
-
-In general, adding a new media service provider is outside the scope of this documentation.
-For best results, consult the existing provider source code, and seek assistance on the relevant
-mailing lists and IRC channels.
-
-The base class for creating new service providers is \l{QMediaServiceProvider}.
-The user must implement the \l{QMediaServiceProvider::requestService()}{requestService()}
-function
-
-\code
- QMediaService* requestService(const QByteArray &type, const QMediaServiceProviderHint &hint);
-\endcode
-
-The details of implementation will depend on the provider. Looking at the
-class \l QMediaServiceProvider for the default implementation. Notice that
-\l {QMediaServiceProvider::requestService()}{requestService()} uses the
-\l QMediaServiceProviderHint to look for the appropriate plugin and then to
-insert it into the plugin map. However, for a specific service provider there
-is probably no need for this approach, it will simply depend on what the
-developer wants to implement.
-
-Other methods that may be overloaded
-\code
- void releaseService(QMediaService *service);
-
- QtMediaServices::SupportEstimate hasSupport(const QByteArray &serviceType,
- const QString &mimeType,
- const QStringList& codecs,
- int flags) const;
-
- QStringList supportedMimeTypes(const QByteArray &serviceType, int flags) const;
-
- QList<QByteArray> devices(const QByteArray &serviceType) const;
-
- QString deviceDescription(const QByteArray &serviceType, const QByteArray &device);
-\endcode
-
-The choice of what needs to be done depends on what the developer wishes to do with the service.
-
-\endomit
-
-\section2 Classes for service implementers.
-
-\annotatedlist multimedia_control
-
-*/
-
-
diff --git a/src/multimedia/doc/src/platform-notes-apple.qdoc b/src/multimedia/doc/src/platform-notes-apple.qdoc
new file mode 100644
index 000000000..a9bca07c2
--- /dev/null
+++ b/src/multimedia/doc/src/platform-notes-apple.qdoc
@@ -0,0 +1,19 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\page qtmultimedia-apple.html
+\title Qt Multimedia on macOS and iOS
+\brief Platform notes for iOS
+
+This page covers the availability of Qt Multimedia features on iOS and macOS.
+
+\section1 Limitations
+
+Since Qt Multimedia for iOS uses the camera and microphone, the \c Info.plist
+assigned to QMAKE_INFO_PLIST in the project file must contain the keys
+\c NSCameraUsageDescription and \c NSMicrophoneUsageDescription. Otherwise, the
+application will abort on startup. See \l{Info.plist} documentation from Apple
+for more information regarding this key.
+
+*/
diff --git a/src/multimedia/doc/src/platform-notes-gstreamer-on-android.qdoc b/src/multimedia/doc/src/platform-notes-gstreamer-on-android.qdoc
deleted file mode 100644
index 51836d99a..000000000
--- a/src/multimedia/doc/src/platform-notes-gstreamer-on-android.qdoc
+++ /dev/null
@@ -1,59 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
-\page platform-notes-gstreamer-on-android.html
-\title Qt Multimedia GStreamer on Android
-\brief Platform notes for GStreamer on Android
-\since 5.14
-
-This page covers the availability of GStreamer on Android.
-
-\section1 Limitations
-
-Since GStreamer is licensed under LGPL and distributed in archives (and should be statically linked),
-Qt Multimedia does not provide support of GStreamer on Android by default.
-
-Therefore GStreamer support must be explicitly enabled by configuring Qt with the \c -gstreamer option.
-
-\section1 Setup
-
-The GStreamer project provides prebuilt binaries which you can download and unzip into any location of your choice.
-
-The environment variable \c GSTREAMER_ROOT_ANDROID should be set to the location where you unzipped the downloaded package.
-
-\section1 Application
-
-Qt Multimedia does not contain any plugins and all needed plugins must be included
-and registered in applications manually by \c GST_PLUGIN_STATIC_DECLARE and \c GST_PLUGIN_STATIC_REGISTER
-after \c gst_init().
-
-Please refer to the official manual on how to statically link plugins to an application.
-
-https://gstreamer.freedesktop.org/documentation/gstreamer/gstplugin.html?gi-language=c#GST_PLUGIN_STATIC_REGISTER
-
-*/
diff --git a/src/multimedia/doc/src/platform-notes-ios.qdoc b/src/multimedia/doc/src/platform-notes-ios.qdoc
deleted file mode 100644
index db5cd6d5a..000000000
--- a/src/multimedia/doc/src/platform-notes-ios.qdoc
+++ /dev/null
@@ -1,43 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
-\page qtmultimedia-ios.html
-\title Qt Multimedia on iOS
-\brief Platform notes for iOS
-
-This page covers the availability of Qt Multimedia features on iOS.
-
-\section1 Limitations
-
-Since Qt Multimedia for iOS uses the camera, the \c Info.plist assigned to
-QMAKE_INFO_PLIST in the project file must contain the key
-\c NSCameraUsageDescription. Otherwise the application will
-abort on startup. See Info.plist documentation from Apple for more information
-regarding this key.
-
-*/
diff --git a/src/multimedia/doc/src/platform-notes-wasm.qdoc b/src/multimedia/doc/src/platform-notes-wasm.qdoc
new file mode 100644
index 000000000..d1a942c9f
--- /dev/null
+++ b/src/multimedia/doc/src/platform-notes-wasm.qdoc
@@ -0,0 +1,35 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\page qtmultimedia-wasm.html
+\title Qt Multimedia on WebAssembly
+\brief Platform notes for WebAssembly
+
+This page covers the availability of Qt Multimedia features on WebAssembly.
+
+\section1 Limitations
+
+Due to the asynchronous nature of javascript, some features such as getting the list of
+QMediaDevices, will not be readily available and may take some time to request permissions and
+gather the list of devices. The audioInputsChanged, audioOutputsChanged and
+videoInputChanged signals from QMediaDevices class will be emitted when they are available.
+
+Playing video currently works by using a html 2d context, so all operations are on the CPU.
+
+Performance is acceptable, although there is a copy on every frame, so it may be
+less performant than desktop platforms when playing hi-def video.
+
+Using and selecting different Codecs/video formats have not yet been tested, but whatever
+video formats the browser supports will most likely work.
+
+Playing data from a stream (using \c {setSourceDevice(QIODevice*)}), instead
+of fetching a URL, isn't supported.
+
+Some advanced features may or may not work at this time.
+
+Files can be served from the/any web server, respective
+of \l{https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS}{CORS}. Because of
+the limited size of local file storage, playing local files is discouraged.
+
+ */
diff --git a/src/multimedia/doc/src/platform-notes-windows.qdoc b/src/multimedia/doc/src/platform-notes-windows.qdoc
deleted file mode 100644
index a69e96d99..000000000
--- a/src/multimedia/doc/src/platform-notes-windows.qdoc
+++ /dev/null
@@ -1,62 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
-\page qtmultimedia-windows.html
-\title Qt Multimedia on Windows
-\brief Platform notes for Windows
-
-This page covers the availability of Qt Multimedia features on Windows.
-
-\section1 Implementation
-
-Qt Multimedia features for Windows are implemented in two plugins; one
-using the Microsoft DirectShow API, and another using WMF (Windows Media
-Foundation) framework. DirectShow API was introduced in Windows 98, and
-gradually deprecated from Windows XP onwards. Media Foundation framework
-was introduced in Windows Vista as a replacement for DirectShow and other
-multimedia APIs. Consequently, WMF plugin in Qt is supported only for
-Windows Vista and later versions of the operating system.
-
-The environment variable \c QT_MULTIMEDIA_PREFERRED_PLUGINS can be used to
-control the priority of the plugins. For example, setting it to
-"windowsmediafoundation" or "directshow" will cause the corresponding plugin
-to be the preferred one.
-
-\section1 Limitations
-
-The WMF plugin in Qt does not currently provide a camera backend. Instead,
-limited support for camera features is provided by the DirectShow
-plugin. Basic features such as displaying a viewfinder and capturing a
-still image are supported, however, majority of camera controls are not
-implemented.
-
-Video recording is currently not supported. Additionally, the DirectShow
-plugin does not support any low-level video functionality such as
-monitoring video frames being played or recorded using \l QVideoProbe or
-related classes.
-*/
diff --git a/src/multimedia/doc/src/plugins/qml-multimedia.qdoc b/src/multimedia/doc/src/plugins/qml-multimedia.qdoc
deleted file mode 100644
index b6df70973..000000000
--- a/src/multimedia/doc/src/plugins/qml-multimedia.qdoc
+++ /dev/null
@@ -1,216 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \page qml-multimedia.html
-
- \title Qt Multimedia QML API
-
- \brief A QML API for the Qt Multimedia module.
-
-
- \section1 Overview
-
- The Qt Multimedia module gives developers a simplified way to use audio and video playback, and access camera functionality. The Multimedia QML API provides a QML friendly interface to these features.
-
- \section1 Types
-
- \section2 Audio
-
- \l Audio is an easy way to add audio playback to a Qt Quick
- scene. Qt Multimedia provides properties for control, methods (functions) and signals.
-
- The code extract below shows the creation and use of an Audio instance.
-
- \qml
-
- Item {
- width: 640
- height: 360
-
- Audio {
- id: playMusic
- source: "music.wav"
- }
-
- MouseArea {
- id: playArea
- anchors.fill: parent
- onPressed: { playMusic.play() }
- }
- }
-
- \endqml
-
- The snippet above shows how the inclusion of \e playMusic enables audio features on the type that contains it. So that when the parent's MouseArea is clicked the \l {Audio::play()}{play()} method of Audio is run. Other typical audio control methods are available such as \l {Audio::pause}{pause()} and \l {Audio::stop()}{stop()}.
-
- Much of the getting / setting of \l Audio parameters is done through properties. These include
- \table 70%
- \header
- \li Property
- \li Description
- \row
- \li \l {Audio::source}{source}
- \li The source URL of the media.
- \row
- \li \l {Audio::autoLoad}{autoLoad}
- \li Indicates if loading of media should begin immediately.
- \row
- \li \l{Audio::playing}{playing}
- \li Indicates that the media is playing.
- \row
- \li \l {Audio::paused}{paused}
- \li The media is paused.
- \row
- \li \l{Audio::status}{status}
- \li The status of media loading.
- \row
- \li \l{Audio::duration}{duration}
- \li Amount of time in milliseconds the media will play.
- \row
- \li \l{Audio::position}{position}
- \li Current position in the media in milliseconds of play.
- \row
- \li \l{Audio::volume}{volume}
- \li Audio output volume: from 0.0 (silent) to 1.0 (maximum)
- \row
- \li \l{Audio::muted}{muted}
- \li Indicates audio is muted.
- \row
- \li \l{Audio::bufferProgress}{bufferProgress}
- \li Indicates how full the data buffer is: 0.0 (empty) to 1.0 (full).
- \row
- \li \l{Audio::seekable}{seekable}
- \li Indicates whether the audio position can be changed.
- \row
- \li \l{Audio::playbackRate}{playbackRate}
- \li The rate at which audio is played at as a multiple of the normal rate.
- \row
- \li \l{Audio::error}{error}
- \li An error code for the error state including NoError
- \row
- \li \l{Audio::errorString}{errorString}
- \li A description of the current error condition.
- \endtable
-
- The set of signals available allow the developer to create custom behavior when the following events occur,
-
- \table 70%
- \header
- \li Signal
- \li Description
- \row
- \li \l{Audio::playing}{playing}
- \li Called when playback is started, or when resumed from paused state.
- \row
- \li \l{Audio::paused}{paused}
- \li Called when playback is paused.
- \row
- \li \l{Audio::stopped}{stopped}
- \li Called when playback is stopped.
- \row
- \li \l{Audio::error}{error}
- \li Called when the specified error occurs.
- \endtable
-
- \section2 Camera
-
- \l Camera enables still image and video capture using
- QML. It has a number of properties that help setting it up.
-
- The details of using a \l Camera are described in further depth
- in the \l {Camera Overview} and in the corresponding reference documentation.
-
- \section2 Video
-
- Adding video playback, with sound, to a Qt Quick scene is also easy. The process is very similar to that of Audio above, in fact \l {Video} shares many of the property names, methods and signals. Here is the equivalent sample code to implement video playback in a scene
-
- \qml
-
- Video {
- id: video
- width : 800
- height : 600
- source: "video.avi"
-
- MouseArea {
- anchors.fill: parent
- onClicked: {
- video.play()
- }
- }
-
- focus: true
- Keys.onSpacePressed: video.paused = !video.paused
- Keys.onLeftPressed: video.position -= 5000
- Keys.onRightPressed: video.position += 5000
- }
-
- \endqml
-
- There are similar features like \l {Video::play()}{play()} with new
- features specific to video.
-
- In the above sample when the parent of MouseArea is clicked, an area of 800x600 pixels with an id of 'video', the source "video.avi" will play in that area. Notice also that signals for the \l Keys have been defined so that a spacebar will toggle the pause button; the left arrow will move the current position in the video to 5 seconds previously; and the right arrow will advance the current position in the video by 5 seconds.
-
- Most of the differences will obviously be about video control and information. There are many properties associated with \l {Video}, most of them deal with meta-data, control of the video media and aspects of presentation.
-
- \section2 SoundEffect
-
- \l SoundEffect provides a way to play short sound effects, like in video games. Multiple sound effect instances can be played simultaneously.
- You should use \l Audio for music playback.
-
- \qml
-
- Item {
- width: 640
- height: 360
-
- SoundEffect {
- id: effect
- source: "test.wav"
- }
- MouseArea {
- id: playArea
- anchors.fill: parent
- onPressed: { effect.play() }
- }
- }
-
- \endqml
-
-
- In the above sample the sound effect will be played when the MouseArea is clicked.
-
- For a complete description of this type, see \l SoundEffect
-
- \section1 Multimedia QML Types
-
- \annotatedlist multimedia_qml
-*/
-
-
diff --git a/src/multimedia/doc/src/qm-external-pages.qdoc b/src/multimedia/doc/src/qm-external-pages.qdoc
new file mode 100644
index 000000000..8a28780c0
--- /dev/null
+++ b/src/multimedia/doc/src/qm-external-pages.qdoc
@@ -0,0 +1,232 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \externalpage https://gstreamer.freedesktop.org
+ \title gstreamer
+*/
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Pixel_Format
+ \title pixel format
+*/
+
+/*!
+ \externalpage https://developer.apple.com/documentation/bundleresources/information_property_list
+ \title Info.plist
+*/
+
+/*!
+ \externalpage https://www.wix.com/blog/photography/2018/10/04/photography-terms/
+ \title photo glossary
+*/
+
+/*!
+ \externalpage https://doc.qt.io/qt-6/qtqml-syntax-imports.html
+ \title qtqml import syntax
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Sonification
+ \title Sonification
+*/
+
+/*!
+ \externalpage http://www.sengpielaudio.com/calculator-loudness.htm
+ \title loudness
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
+ \title ISO 639-2 code
+*/
+
+/*!
+ \externalpage https://www.dr-lex.be/info-stuff/volumecontrols.html
+ \title volume controls
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Hyperfocal_distance
+ \title hyperfocal
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Depth_of_field
+ \title DOF
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Media_type#Mime.types
+ \title MIME type
+*/
+
+/*!
+ \externalpage https://doc.qt.io/qt-5/qml-qtmultimedia-audio.html
+ \title Audio QML Type
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Windows_Media_Audio
+ \title Windows Media Audio
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Advanced_Audio_Coding
+ \title Advanced Audio Coding
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/ALAC
+ \title Apple Lossless Audio Codec
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Matroska
+ \title Matroska (MKV)
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Windows_Media_Video
+ \title Windows Media Video
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/MP3
+ \title MPEG-1 Audio Layer III or MPEG-2 Audio Layer III
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/WAV
+ \title Waveform Audio File Format
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Ogg
+ \title Ogg
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/MPEG-4
+ \title MPEG-4
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Audio_Video_Interleave
+ \title Audio Video Interleave
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/QuickTime
+ \title QuickTime
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/WebM
+ \title WebM
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/MPEG-4_Part_3
+ \title MPEG-4 Part 3 or MPEG-4 Audio (formally ISO/IEC 14496-3)
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/FLAC
+ \title Free Lossless Audio Codec
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Dolby_Digital
+ \title Dolby Digital
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Dolby_Digital_Plus
+ \title Dolby Digital Plus (EAC3)
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Opus_(audio_format)
+ \title Opus Audio Format
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Dolby_TrueHD
+ \title Dolby TrueHD
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Vorbis
+ \title Ogg Vorbis
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/VP8
+ \title VP8
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/MPEG-2
+ \title MPEG-2
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/MPEG-1
+ \title MPEG-1
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding
+ \title High Efficiency Video Coding (HEVC)
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Advanced_Video_Coding
+ \title Advanced Video Coding
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/AV1
+ \title AOMedia Video 1
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Motion_JPEG
+ \title MotionJPEG
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/VP9
+ \title VP9
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Theora
+ \title Theora
+*/
+
+/*!
+ \externalpage https://en.wikipedia.org/wiki/Windows_Media_Player
+ \title Windows Media Player
+*/
+
+
+/*!
+ \externalpage https://support.microsoft.com/en-us/topic/file-types-supported-by-windows-media-player-32d9998e-dc8f-af54-7ba1-e996f74375d9
+ \title Windows Media Player documentation
+*/
+
+/*!
+ \externalpage https://www.codecguide.com/guides.htm
+ \title codec guide
+*/
+
+/*!
+ \externalpage https://developer.android.com/guide/topics/media/media-formats
+ \title Android supported media formats
+*/
+
+/*!
+ \externalpage https://gstreamer.freedesktop.org/
+ \title GStreamer
+*/
diff --git a/src/multimedia/doc/src/qt6-changes.qdoc b/src/multimedia/doc/src/qt6-changes.qdoc
new file mode 100644
index 000000000..ad5ebab74
--- /dev/null
+++ b/src/multimedia/doc/src/qt6-changes.qdoc
@@ -0,0 +1,145 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page qtmultimedia-changes-qt6.html
+ \title Changes to Qt Multimedia
+ \ingroup changes-qt-5-to-6
+ \brief Migrate Qt Multimedia to Qt 6.
+
+ Qt 6 is a result of the conscious effort to make the framework more
+ efficient and easy to use.
+
+ We try to maintain binary and source compatibility for all the public
+ APIs in each release. But some changes were inevitable in an effort to
+ make Qt a better framework.
+
+The module has been refactored significantly and has changed classification,
+from essential to add-on. The Qt Multimedia module in Qt 6 replaces the
+Qt Multimedia module from Qt 5.x. Existing code that uses Qt Multimedia from
+Qt 5 can be ported with limited effort.
+
+
+\section1 New features in Qt 6
+
+There are a number of new features in Qt Multimedia:
+\list
+ \li QMediaCaptureSession class is the central object for media capture.
+ \li QMediaRecorder class is now a class limited to recording audio and video.
+ It handles encoding of data produced in a capture session.
+ \li Using QMediaFormat and QMediaRecorder, setting up the desired encoding
+ when recording has changed significantly.
+ \li You can now also monitor the audio recorded by a capture session.
+ \li Support for selection of audio, video and subtitle tracks when playing
+ back media files has been added.
+ \li QAudioDecoder is now supported on all platforms.
+\endlist
+
+
+\section1 Removed features
+
+\table 70%
+ \header
+ \li Removed feature
+ \li Notes or suggested alternative
+ \row
+ \li Playlist in QMediaPlayer
+ \li QMediaPlayer does not do any playlist handling anymore in Qt 6.
+ \row
+ \li QMediaPlayList
+ \li This class has been removed from the API. It does however still exist
+ as part of the \l{Media Player Example}.
+ \row
+ \li QAudioProbe and QVideoProbe
+ \li The audio and video probing API has been removed.
+ \row
+ \li QAudioRecorder
+ \li Use the QMediaCaptureSession or CaptureSession QML type.
+ \row
+ \li \l{Audio QML type}
+ \li Use MediaPlayer QML type.
+ \row
+ \li QMediaObject and QMediaBindableInterface
+ \li These classes have been removed in favor of a more direct API for
+ setting up connections between objects using, for example, setVideoOutput
+ and QMediaCaptureSession.
+ \row
+ \li QCameraViewFinderSettings
+ \li This class has been removed. Use QCameraFormat to define the
+ resolution and frame rate the camera should be using.
+ \row
+ \li QMediaContent
+ \li The class has been removed. Use QUrl for individual media files instead.
+ \row
+ \li QSound
+ \li Use QSoundEffect instead.
+ \row
+ \li QVideoFilterRunnable
+ \li Use \l{shader effects} in QML instead or access the QVideoFrame's
+ content in C++.
+ \row
+ \li Public back-end API
+ \li The back-end API of Qt Multimedia is private in Qt 6. This improves
+ response time for supporting new multimedia use cases. Any classes that
+ contain the words "Control" or "Abstract" in the class name in Qt 5 are
+ now private in Qt 6.
+ \row
+ \li Back-end plugins
+ \li Qt Multimedia in Qt 6 does not use a plugin infrastructure for its
+ back ends anymore.
+ This means that users no longer need to ship those back ends with their
+ application. Instead, the back end being used is determined at compile
+ time based on the underlying operating system. Qt uses \l gstreamer on
+ Linux, WMF on Windows, AVFoundation on macOS and iOS and the Android
+ multimedia APIs on Android.
+\endtable
+
+\section1 Changed features
+
+A number of classes previously offered in Qt Multimedia have
+changed in ways that may affect previously written code. The following table
+highlights these changes.
+
+\table 70%
+ \header
+ \li Changed feature
+ \li Notes
+ \row
+ \li Handling of Camera resolutions and frame rates
+ \li Handling of these has been simplified and a new QCameraFormat class
+ helps with selecting the correct resolution and frame rate for the camera.
+ \row
+ \li Video output handling on the C++ side has changed significantly.
+ \li QAbstractVideoSurface has been replaced by the QVideoSink class, and
+ generic rendering support has been enhanced to cover all \l{pixel format}s
+ supported by Qt Multimedia.
+ \row
+ \li Metadata types
+ \li QMediaMetaData has changed significantly: mainly moving from string
+ based to enum based keys, and reducing the set of supported keys to the
+ ones that can be supported on most platforms.
+ \row
+ \li QMediaFormat
+ \li Handling of formats for encoded media and the settings for the media
+ recorder have changed significantly. Qt 5 provides a string-based
+ API, a separated file format, and audio and video codecs into three classes.
+ However, Qt 6 unifies the formats in the QMediaFormat class. Additional
+ settings are directly specified in QMediaRecorder. Setting up file formats
+ and codecs is now implemented with enums and no longer uses strings. This
+ puts some limitations on the set of codecs that can be used, but helps
+ provide a consistent cross-platform API.
+ \row
+ \li QCameraImageCapture renamed QImageCapture
+ \li None
+ \row
+ \li Audio inputs and outputs
+ \li QMediaPlayer and QMediaCaptureSession (and the corresponding QML types MediaPlayer and
+ CaptureSession) are not connected to any audio devices by default. Explicitly connect them
+ to a QAudioInput/AudioInput or QAudioOutput/AudioOutput to capture or play back audio.
+ \row
+ \li Capturing video
+ \li A capture session is by default not connected to a Camera. Connect it to a QCamera object
+ (Camera item) to be able to capture video or still images.
+\endtable
+
+*/
diff --git a/src/multimedia/doc/src/qtaudioengine.qdoc b/src/multimedia/doc/src/qtaudioengine.qdoc
deleted file mode 100644
index c45d4e8af..000000000
--- a/src/multimedia/doc/src/qtaudioengine.qdoc
+++ /dev/null
@@ -1,59 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
-\qmlmodule QtAudioEngine 1.\QtMinorVersion
-\title Qt Audio Engine QML Types
-\ingroup qmlmodules
-\brief Provides QML types for 3D positional audio playback and content management.
-
-Qt Audio Engine is part of the \l{Qt Multimedia} module. Qt Audio
-Engine provides types for 3D positional audio playback and content management.
-
-The QML types can be imported into your application using the following import
-statement in your .qml file:
-\qml \QtMinorVersion
-import QtAudioEngine 1.\1
-\endqml
-
-\section1 Qt Audio Engine Features
-
-Qt Audio Engine enables developers to organize wave files into discrete \l Sound
-with different \l {PlayVariation}{play variations}, group sound controls by \l
-{AudioCategory} categories and define \l {AttenuationModelLinear}{attenuation
-models} and various 3D audio settings all in one place. Playback of \l
-{SoundInstance}{sound instances} can be conveniently activated by in-app events
-and managed by QtAudioEngine or controlled by explicitly defining \l
-SoundInstance for easier QML bindings.
-
-\section1 Examples
-\list
- \li \l {AudioEngine Example}{Audio Engine}
-\endlist
-
-\section1 QML Types
-*/
diff --git a/src/multimedia/doc/src/qtmultimedia-building-from-source.qdoc b/src/multimedia/doc/src/qtmultimedia-building-from-source.qdoc
new file mode 100644
index 000000000..df434c699
--- /dev/null
+++ b/src/multimedia/doc/src/qtmultimedia-building-from-source.qdoc
@@ -0,0 +1,94 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\page qtmultimedia-building-from-source.html
+\title Building Qt Multimedia from sources
+\brief This document describes how to build Qt Multimedia with full
+feature support from source code.
+
+This page describes the process of configuring and building \l{Qt
+Multimedia}. This description assumes familiarity with \l{Building Qt
+Sources} which specifies build requirements for your platform, as well
+as an overview of \l{Qt Configure Options}. For platform-specific
+considerations related to the Qt Multimedia module, see \l{Platform
+Notes} below.
+
+\section1 Building from source
+
+Building Qt Multimedia with full feature support depends on \l
+{https://ffmpeg.org/}{FFmpeg} headers and libraries on most platforms.
+It is possible to build Qt Multimedia without the Qt Multimedia FFmpeg
+media backend, but this is only recommended when building for platforms
+where the FFmpeg backend is not supported.
+
+FFmpeg developer libraries required to build Qt Multimedia can be built
+from sources or downloaded as binary packages. Qt Multimedia can use
+either static linking or dynamic linking to FFmpeg libraries. We
+recommend using the same major version of FFmpeg that is listed in
+\l{FFmpeg as the default backend}.
+
+To build Qt Multimedia with FFmpeg support, specify the \c{-DFFMPEG_DIR}
+CMake variable on the configure command line when building Qt. Note the
+\c{--} separator which separates ordinary configure arguments from CMake
+parameters.
+
+\badcode
+qt-source/configure -- -DFFMPEG_DIR=<FFMPEG_DIR>
+\endcode
+
+Here, \c{<FFMPEG_DIR>} is the directory containing the FFmpeg include,
+lib, and bin directories. To build Qt Multimedia without FFmpeg, omit
+the \c{<FFMPEG_DIR>} variable or specify the \c{-no-feature-ffmpeg}
+configure option.
+
+If you prefer not to build all Qt's submodules, you can reduce configure
+and build times using the \c{-submodules} configure option. This will
+configure a build that only builds Qt Multimedia and its dependencies.
+
+\badcode
+qt-source/configure -submodules qtmultimedia -- -DFFMPEG_DIR=<FFMPEG_DIR>
+\endcode
+
+If you configure Qt Multimedia against FFmpeg built with shared
+libraries (dynamic linking), the FFmpeg shared libraries must be in the
+module loader's search path to run tests or use examples.
+
+\note Qt Multimedia requires the FFmpeg avformat, avcodec, swresample,
+swscale, and avutil libraries during runtime to be able to use the
+FFmpeg media backend. If one or more of these dynamic libraries are not
+found during application startup, the FFmpeg media backend will fail to
+load, and the system will attempt to load the native backend. Qt
+Multimedia doesn't support as many features on native backends.
+
+If you don't already have these libraries in the \c{path}, specify the
+\c{-DQT_DEPLOY_FFMPEG=ON} configure option. With this option enabled,
+the necessary FFmpeg binaries will be copied to Qt's install directory
+during the build and install steps:
+
+\badcode
+qt-source/configure -submodules qtmultimedia -- -DFFMPEG_DIR=<FFMPEG_DIR> -DQT_DEPLOY_FFMPEG=ON
+\endcode
+
+After configuring Qt Multimedia, carefully review the configure summary
+(found in the config.summary file). You can verify that FFmpeg is found
+under the "Plugin" section. Then follow the regular build and install
+steps described in \l{Building Qt Sources}.
+
+\section1 Platform Notes
+
+\section2 Linux
+
+\list
+ \li When configuring Qt Multimedia with FFmpeg enabled, the
+ pulseaudio development package is required. Without this
+ package, FFmpeg will not be recognized.
+ \li When using a version of FFmpeg that is built with VAAPI support,
+ we recommend building Qt Multimedia with VAAPI support as well
+ to make hardware texture conversion possible. To configure Qt
+ Multimedia with VAAPI support, VAAPI developer libraries must be
+ installed on your system. Review the config.summary file to
+ verify that VAAPI support is enabled under the "Hardware
+ acceleration and features" section.
+\endlist
+*/
diff --git a/src/multimedia/doc/src/qtmultimedia-cpp.qdoc b/src/multimedia/doc/src/qtmultimedia-cpp.qdoc
index f75ecbfe2..b0c4ea732 100644
--- a/src/multimedia/doc/src/qtmultimedia-cpp.qdoc
+++ b/src/multimedia/doc/src/qtmultimedia-cpp.qdoc
@@ -1,48 +1,21 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2015 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\module QtMultimedia
\title Qt Multimedia Module C++ Classes
\ingroup modules
\qtvariable multimedia
+ \qtcmakepackage Multimedia
\brief The \l {Qt Multimedia} module provides audio, video and camera
functionality.
- To enable Qt Multimedia in a project, add this directive into the
- C++ files:
-
- \snippet doc_src_qtmultimedia.cpp 0
-
- To link against the C++ libraries, add the following to your \c qmake project
- file:
-
- \snippet doc_src_qtmultimedia.pro 0
+ \include module-use.qdocinc using qt module
+ \code
+ find_package(Qt6 REQUIRED COMPONENTS Multimedia)
+ target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
+ \endcode
*/
/*!
@@ -54,7 +27,7 @@
QML alternatives. If your application is serving complex use cases such as
decoding media files, accessing video or audio buffers, use the C++
alternative. For more details about the complex audio, video, and camera use
- cases supported by the C++ classes, refer to \l {Multimedia}{Multimedia Overview}.
+ cases supported by the C++ classes, refer to \l {Qt Multimedia}{Multimedia Overview}.
\section1 Namespaces
\annotatedlist multimedia-namespaces
@@ -66,4 +39,7 @@
\section2 Qt Multimedia Widgets Module
\generatelist {classesbymodule QtMultimediaWidgets}
+
+ \section2 Qt Spatial Audio Module
+ \generatelist {classesbymodule QtSpatialAudio}
*/
diff --git a/src/multimedia/doc/src/qtmultimedia-examples.qdoc b/src/multimedia/doc/src/qtmultimedia-examples.qdoc
index d8da05c32..e53eed32f 100644
--- a/src/multimedia/doc/src/qtmultimedia-examples.qdoc
+++ b/src/multimedia/doc/src/qtmultimedia-examples.qdoc
@@ -1,37 +1,15 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2015 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\group multimedia_examples
- \ingroup all-examples
\title Qt Multimedia Examples
\brief Demonstrates the multimedia functionality provided by Qt.
- The \l{Qt Multimedia} module provides low-level audio support on Linux,
- Windows and \macos. It also provides audio plugin API to allow developers
- implement their own audio support for custom devices and platforms.
+ The \l{Qt Multimedia} module provides cross-platform multimedia capabilities
+ for Qt based applications.
+
+ The examples listed below show some typical use cases in various areas, featuring
+ both low-level audio examples, high level audio and video playback
+ as well as capturing and recording of audiovisual content using both C++ and QML.
*/
diff --git a/src/multimedia/doc/src/qtmultimedia-index.qdoc b/src/multimedia/doc/src/qtmultimedia-index.qdoc
index 13c686978..74646b84c 100644
--- a/src/multimedia/doc/src/qtmultimedia-index.qdoc
+++ b/src/multimedia/doc/src/qtmultimedia-index.qdoc
@@ -1,186 +1,288 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page qtmultimedia-index.html
\title Qt Multimedia
- \brief The Qt Multimedia module provides APIs for audio, video and
- camera-related functionality.
+ \image noun_Media_166644.svg "image of multimedia icons, courtesy of misirlou from the Noun Project"
+ \brief The Qt Multimedia module provides APIs for playing back and recording
+ audiovisual content
- Qt Multimedia is an essential module that provides a rich set of QML types
- and C++ classes to handle multimedia content. It also provides necessary
- APIs to access the camera functionality. The included
- \l{Qt Audio Engine QML Types}{Qt Audio Engine} provides types for
- 3D positional audio playback and content management.
+ Qt Multimedia is an add-on module that provides a rich set of QML types
+ and C++ classes to handle multimedia content. It contains an easy to use
+ API for playing back audio and video files and rendering those on screen, as
+ well as a comprehensive API for recording audio and video from the system's
+ cameras and microphones.
The functionality of this module is divided into the following submodules:
\table
\row
- \li \l{QtMultimedia}{Qt Multimedia}
- \li Provides API for multimedia-specific use cases.
+ \li \l{Multimedia Overview}{Qt Multimedia}
+ \li Provides an API for multimedia-specific use cases.
\row
- \li \l{QtMultimediaWidgets}{Qt Multimedia Widgets}
- \li Provides the widget-based multimedia API.
+ \li \l{Qt Multimedia Widgets}
+ \li Provides a widget-based multimedia API.
+ \row
+ \li \l{Qt Spatial Audio}
+ \li Provides an API for implementing sound fields in 3D space.
\endtable
- \section1 Getting Started
+ \section1 Getting started
+ If you are porting from Qt 5 to Qt 6 see \l{Changes to Qt Multimedia}.
- The QML types can be imported into your applciation using the following
- import statement in your \c {.qml} file.
+ If you are new to Qt Multimedia, the QML types can be
+ \l{qtqml import syntax}{imported} into an application using the following
+ statement in your \c {.qml} file.
- \qml \QtMinorVersion
- import QtMultimedia 5.\1
+ \qml
+ import QtMultimedia
\endqml
- If you intend to use the C++ classes in your application, include the C++
- definitions using the following directive:
+ To link against the C++ libraries, add the following to your project's
+ \c CMakeLists.txt file. Substitute \c my_project with the name of your
+ project.
- \code
- #include <QtMultimedia>
- #include <QtMultimediaWidgets>
- \endcode
+ \code
+ find_package(Qt6 REQUIRED COMPONENTS Multimedia)
+ target_link_libraries(my_project PRIVATE Qt6::Multimedia)
+ \endcode
- \note If you are using a few classes from this module, we recommend
- including those specific classes only instead of the module.
+ See \l {Building Qt Multimedia from sources} for guidance on building
+ Qt Multimedia from sources.
- To link against the corresponding C++ libraries, add the following to your
- \c {qmake} project file:
+ \section1 Overviews and important topics
- \code
- QT += multimedia multimediawidgets
- \endcode
+ \list
+ \li \l{Changes to Qt Multimedia}{Changes in Qt 6}
+ \li \l{Multimedia Overview}
+ \li \l{Audio Overview}
+ \li \l{Spatial Audio Overview}
+ \li \l{Video Overview}
+ \li \l{Camera Overview}
+ \li \l{Supported Media Formats}
+ \endlist
- \section1 QML Types and C++ Classes
+ \section1 QML types
- The following is a list of important QML types and C++ classes provided by
- this module:
+ The following table outlines some important QML types.
\table
\header
\li Type
\li Description
\row
- \li \l {QtMultimedia::Audio}{Audio}
- \li Add audio playback functionality to a scene
+ \li \l{MediaPlayer}
+ \li Add audio/video playback functionality to a scene.
\row
- \li \l {QtMultimedia::Playlist}{Playlist}
- \li For specifying a list of media to be played.
+ \li \l {QtMultimedia::CaptureSession}{CaptureSession}
+ \li Create a session for capturing audio/video.
\row
\li \l {QtMultimedia::Camera}{Camera}
- \li Access camera viewfinder frames
+ \li Access a camera connected to the system.
+ \row
+ \li \l {QtMultimedia::AudioInput}{AudioInput}
+ \li Access an audio input (microphone) connected to the system.
\row
- \li MediaPlayer
- \li Add media playback functionality to a scene. It is same as Audio type,
- but can be used for video playback with the VideoOutput type.
+ \li \l {QtMultimedia::AudioOutput}{AudioOutput}
+ \li Access an audio output (speaker, headphone) connected to the system.
+ \row
+ \li \l {QtMultimedia::VideoOutput}{VideoOutput}
+ \li Display video content.
+ \row
+ \li \l {QtMultimedia::MediaRecorder}{MediaRecorder}
+ \li Record audio/video from the CaptureSession.
+ \row
+ \li \l {QtMultimedia::ImageCapture}{ImageCapture}
+ \li Capture still images from the Camera.
\row
\li \l {QtMultimedia::Video}{Video}
- \li Add Video playback functionality to a scene. It uses MediaPlayer and
+ \li Add Video playback functionality to a scene. Uses MediaPlayer and
VideoOutput types to provide video playback functionality.
+ \row
+ \li \l {QtMultimedia::ScreenCapture}{ScreenCapture}
+ \li Captures a screen.
+ \row
+ \li \l {QtMultimedia::WindowCapture}{WindowCapture}
+ \li Captures a top-level window.
\endtable
+ \section1 C++ classes
+
+ The following table outlines some important C++ classes
+
\table
\header
\li Class
\li Description
\row
- \li QAudioOutput
- \li Sends audio data to an audio output device
+ \li QMediaPlayer
+ \li Playback media from a source.
+ \row
+ \li QVideoWidget
+ \li Display video from a media player or a capture session.
\row
- \li QAudioRecorder
- \li Record media content from an audio source.
+ \li QMediaCaptureSession
+ \li Capture audio and video.
\row
\li QCamera
- \li Access camera viewfinder.
+ \li Access a camera connected to the system
\row
- \li QCameraImageCapture
+ \li QAudioInput
+ \li Access an audio input (microphone) connected to the system.
+ \row
+ \li QAudioOutput
+ \li Access an audio output (speaker, headphone) connected to the system.
+ \row
+ \li QImageCapture
\li Capture still images with a camera.
\row
\li QMediaRecorder
- \li Record media content from a camera source.
+ \li Record media content from a capture session.
\row
- \li QMediaPlayer
- \li Playback media from a source.
+ \li QVideoSink
+ \li Access and render individual video frames.
+ \row
+ \li QAudioSink
+ \li Sends raw audio data to an audio output device.
\row
- \li QMediaPlaylist
- \li List of media to be played.
+ \li QScreenCapture
+ \li Captures a screen.
\row
- \li QAbstractVideoSurface
- \li Base class for video presentation.
+ \li QWindowCapture
+ \li Captures a top-level window.
\endtable
- \section1 Licenses and Attributions
+ For playback QMediaPlayer, QAudioOutput and QVideoOutput contain all the required functionality.
+ The other classes are used for capturing audio and video content, where the QMediaCaptureSession is the central
+ class managing the whole capture/recording process.
- The Qt Quick Multimedia module is available under commercial licenses from \l{The Qt Company}.
- In addition, it is available under free software licenses. Since Qt 5.4,
+ \section1 Licenses and attributions
+
+ The Qt Multimedia module is available under commercial licenses from
+ \l{The Qt Company}.
+ In addition, it is available under free software licenses. Since Qt 5.6,
these free software licenses are
\l{GNU Lesser General Public License, version 3}, or
the \l{GNU General Public License, version 2}.
See \l{Qt Licensing} for further details.
- \section1 Related Information
+ Furthermore, Qt Multimedia in Qt \QtVersion may contain third-party modules
+ under following permissive licenses:
- \section2 Guides
- \list
- \li \l Multimedia - overview of multimedia support in Qt
- \li \l{Audio Overview}
- \li \l{Video Overview}
- \li \l{Camera Overview}
- \endlist
+ \generatelist{groupsbymodule attributions-qtmultimedia}
- \section2 Platform Notes
+ Note that video compression standards, such as the H.264 media compression
+ standard, may be covered by patents and can incur royalty fees. This can
+ apply to any implementation, also if the implementation is provided as an
+ operating system service, through a third party library, or through any of
+ Qt Multimedia's backends. Such fees are not covered by the Qt licenses.
- The \l{Qt Multimedia Backends} wiki provides a summary of features
- supported by each platform plugin made available by this module. The
- following topics provide more platform-specific information.
+ \section1 Target platform and backend notes
+ We aim to align the behavior on all the platforms but there are some issues
+ to consider.
- \list
- \li \l{Qt Multimedia on Windows}{Windows}
- \li \l{Qt Multimedia on iOS}{iOS}
- \endlist
+ \section2 Backends
+ On most platforms, there are two different backends that can be used for
+ Qt Multimedia.
- \section2 Reference
- \list
- \li Qt Multimedia
+ \section3 FFmpeg as the default backend
+ In this release the \l {http://ffmpeg.org}{FFmpeg framework} is set as the
+ default backend on Windows, macOS, Android, and Linux except Yocto distribution.
+
+ The version shipped with Qt binary packages is \b{FFmpeg 6.1.1} and is tested
+ by the maintainers.
+
+ \note On the Windows and macOS platforms, Qt's FFmpeg media backend
+ uses dynamic linking to the FFmpeg libraries. Windows and macOS
+ applications must therefore bundle FFmpeg binaries in their
+ installer, and make them visible to the application at runtime. On
+ Windows, we recommend to store the FFmpeg dlls in the same directory
+ as the application's executable file, because this guarantees that
+ the correct build of FFmpeg is being used if multiple versions are
+ available on the system. All necessary FFmpeg libraries are shipped
+ with the Qt Online Installer and are automatically deployed if the
+ windeployqt or macdeployqt tools are used to create the deployment.
+ Applications can also deploy their own build of FFmpeg, as long as
+ the FFmpeg major version matches the version used by Qt.
+
+ \note See \l{Licenses and Attributions} regarding what components are removed
+ in the package shipped by Qt.
+
+ \section3 Native backends
+ These are:
\list
- \li \l{Qt Multimedia QML Types}{QML Types}
- \li \l{Qt Multimedia C++ Classes}{C++ Classes}
- \endlist
+ \li gstreamer on Linux
+ \li AVFoundation on macOS and iOS
+ \li WMF Windows
+ \li MediaCodec framework on Android
\endlist
+ \note These are still available but with \b limited support. The gstreamer
+ backend is only available on Linux.
+ \note MediaCodec on Android is deprecated as of Qt 6.8 and will be removed
+ in Qt 7.0.
+
+ \section2 Backend support
+ Maintainers will strive to fix critical issues with the native backends but
+ don't guarantee fixing minor issues and won't implement new features for the
+ native backends. Furthermore, even some major issues with the gstreamer
+ backend (on Linux) won't be fixed since gstreamer is difficult to debug and
+ is further complicated as it is dependent on Linux distributions.
+
+ We aim to align the behavior on all the platforms, especially, with the
+ FFmpeg backend. Despite this fact we still have platform-dependent issues
+ with formats, codecs, advanced camera features, and screen capturing due to
+ the Qt Multimedia API relying on target platform APIs. For example, with FFmpeg,
+ there are specific problems with hardware acceleration on Linux targets with
+ ARM architectures.
+
+ Backend-dependent limitations will be documented and their status maintained
+ in the respective classes.
+
+ \section2 Changing backends
+
+ In the case of issues with the default FFmpeg backend, we suggest testing with a native backend.
+ You can switch to native backends by setting the \c{QT_MEDIA_BACKEND} environment variable
+ to \c windows, \c gstreamer (on Linux), \c darwin (on macOS and iOS), or \c android:
+
+ \code
+ export QT_MEDIA_BACKEND=darwin
+ \endcode
+
+ In order to force assign FFmpeg as the used backend, set the variable to \c ffmpeg:
+
+ \code
+ export QT_MEDIA_BACKEND=ffmpeg
+ \endcode
+
+ On the Qt Multimedia compilation stage the default media backend can be configured
+ via cmake variable \c{QT_DEFAULT_MEDIA_BACKEND}.
+
+ \section2 Target platform notes
+ The following pages list issues for specific target platforms that are not
+ related to the multimedia backed.
+
\list
- \li Qt Audio Engine
- \list
- \li \l{Qt Audio Engine QML Types}{QML Types}
- \endlist
+ \li \l{Qt Multimedia on macOS and iOS}{macOS and iOS}
+ \li \l{Qt Multimedia on WebAssembly}{WebAssembly}
\endlist
- \section2 Examples
- \list
- \li \l{Qt Multimedia Examples}
- \endlist
+ \section1 Permissions
+
+ Starting from Qt 6.6, the Qt Multimedia module uses new \l QPermission API
+ to handle \l {QCameraPermission}{camera} and
+ \l {QMicrophonePermission}{microphone} permissions. This means that Qt
+ itself no longer queries for these permissions, so this needs to be done
+ directly from the client application.
+
+ Please refer to the \l {Application Permissions} page for an example of how
+ to integrate the new \l QPermission API into the application.
+
+ \section1 Reference and examples
+ \list
+ \li \l{Qt Multimedia QML Types}{QML Types}
+ \li \l{Qt Multimedia C++ Classes}{C++ Classes}
+ \li \l{Qt Multimedia Examples}{Examples}
+ \endlist
*/
diff --git a/src/multimedia/doc/src/qtmultimedia-qml-types.qdoc b/src/multimedia/doc/src/qtmultimedia-qml-types.qdoc
new file mode 100644
index 000000000..0d61a8917
--- /dev/null
+++ b/src/multimedia/doc/src/qtmultimedia-qml-types.qdoc
@@ -0,0 +1,45 @@
+// Copyright (C) 2015 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\qmlmodule QtMultimedia
+\noautolist
+\title Qt Multimedia QML Types
+\ingroup qmlmodules
+\brief Provides QML types for multimedia support.
+
+The QML types for \l{Qt Multimedia} support the basic use cases such as:
+\list
+ \li audio and video playback,
+ \li access camera functionality,
+ \li record video,
+ \li and access camera settings.
+\endlist
+
+\section1 QML Types
+
+Qt Multimedia QML types can be imported into your application using the
+following import statement in your .qml file:
+
+\qml
+import QtMultimedia
+\endqml
+
+\generatelist qmltypesbymodule QtMultimedia
+
+The \QtMultimedia import provides also the following
+\l [QtQml]{QML Value Types}{value types}:
+
+\generatelist qmlvaluetypesbymodule QtMultimedia
+
+\section2 Qt Spatial Audio Module
+
+Qt Spatial Audio QML types can be imported into your application using the
+following import statement in your .qml file:
+
+\qml
+import QtQuick3D.SpatialAudio
+\endqml
+
+\generatelist qmltypesbymodule QtQuick3D.SpatialAudio
+*/
diff --git a/src/multimedia/doc/src/qtmultimedia5.qdoc b/src/multimedia/doc/src/qtmultimedia5.qdoc
deleted file mode 100644
index 461cc716f..000000000
--- a/src/multimedia/doc/src/qtmultimedia5.qdoc
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
-\qmlmodule QtMultimedia 5.\QtMinorVersion
-\title Qt Multimedia QML Types
-\ingroup qmlmodules
-\brief Provides QML types for multimedia support.
-
-The QML types for \l{Qt Multimedia} support the basic use cases such as:
-\list
- \li audio and video playback,
- \li access camera functionality,
- \li record video,
- \li and access camera settings.
-\endlist
-
-\section1 QML Types
-
-Qt Multimedia QML types can be imported into your application using the
-following import statement in your .qml file:
-
-\qml \QtMinorVersion
-import QtMultimedia 5.\1
-\endqml
-
-\generatelist qmltypesbymodule QtMultimedia
-
-\section2 Qt Audio Engine
-
-\l {QtAudioEngine}{Qt Audio Engine} provides types for 3D positional audio
-playback and content management. These types can be imported into your
-application using the following import statement in your .qml file:
-
-\qml \QtMinorVersion
-import QtAudioEngine 1.\1
-\endqml
-
-\generatelist qmltypesbymodule QtAudioEngine
-
-\noautolist
-*/
diff --git a/src/multimedia/doc/src/videooverview.qdoc b/src/multimedia/doc/src/videooverview.qdoc
index c3fa50f04..3185c9a02 100644
--- a/src/multimedia/doc/src/videooverview.qdoc
+++ b/src/multimedia/doc/src/videooverview.qdoc
@@ -1,42 +1,19 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page videooverview.html
\title Video Overview
\brief Video playback
+\ingroup explanations-graphicsandmultimedia
\section1 Video Features
Qt Multimedia offers both high and low level C++ classes for playing and
-manipulating video data, and QML types for playback and control. Some
-of these classes also overlap with both \l {Camera Overview}{camera} and
-\l {Audio Overview}{audio} classes, which can be useful.
+manipulating video data, and QML types for playback and recording. Some
+of the classes presented here overlap with what is presented in the \l {Camera Overview} and
+\l {Audio Overview}.
\section1 Video Implementation Details
@@ -54,69 +31,73 @@ And an example with QGraphicsVideoItem:
\section2 Playing Video in QML
-You can use \l VideoOutput to render content that is
-provided by either a \l MediaPlayer or a \l Camera.
-The VideoOutput is a visual component that can be transformed
-or acted upon by shaders (as the \l {QML Video Shader Effects Example} shows), while
-all media decoding and playback control is handled by the \l MediaPlayer.
-
-Alternatively there is also a higher level \l Video type that
-acts as a single, visual element to play video and control playback.
+You can use \l VideoOutput to render content that is provided by
+either a \l MediaPlayer or a \l Camera. The VideoOutput is a visual
+component that can be embedded into a QQuickScene or \l Window, while
+all media decoding and playback control is handled by the \l MediaPlayer
+or \l CaptureSession. A \l Video element has been provided for convenience.
+It combines MediaPlayer, VideoOutput and AudioOutput elements in one item.
\section2 Working with Low Level Video Frames
Qt Multimedia offers a number of low level classes to make handling
-video frames a bit easier. These classes are primarily used when
+video frames a bit easier. These classes are primarily used when
writing code that processes video or camera frames (for example,
detecting barcodes, or applying a fancy vignette effect), or needs
to display video in a special way that is otherwise unsupported.
The \l QVideoFrame class encapsulates a video frame and allows the
contents to be mapped into system memory for manipulation or
-processing, while deriving a class from \l QAbstractVideoSurface
+processing. Using your own QVideoSink
allows you to receive these frames from \l QMediaPlayer and
\l QCamera.
-\snippet multimedia-snippets/video.cpp Derived Surface
+\section2 Recording Video
+The central class for any type of capturing or recording of audio and video is QMediaCaptureSession
+(or the CaptureSession QML type). You can connect a QCamera (Camera in QML) and a QMediaRecorder
+(MediaRecorder)to the session and then ask the media recorder to start recording.
+
+\section1 Supported Media Formats
-and with an instance of this surface, \c myVideoSurface, you can set
-the surface as the \l {QMediaPlayer::setVideoOutput()}{video output} for QMediaPlayer.
+What media formats are supported ultimately depends on the configuration of the
+target system.
-\snippet multimedia-snippets/video.cpp Setting surface in player
+\section2 Windows
+By default what is available on a MS Windows target depends on the version of
+\l{Windows Media Player} that was packaged with the OS. See the
+\l{Windows Media Player documentation} for official information.
-Several of the built-in Qt classes offer this functionality
-as well, so if you decode video in your application, you can present
-it to classes that offer a \l QVideoRendererControl class, and in QML
-you can set a custom object for the source of a \l VideoOutput
-with either a writable \c videoSurface property (that the instance will
-set it's internal video surface to) or a readable \c mediaObject property
-with a QMediaObject derived class that implements the \l QVideoRendererControl
-interface.
+Independent of Windows Media Player, there are of course numerous codec packs
+that could be installed. See the \l{codec guide} site for some examples.
-The following snippet shows a class that has a writable \c videoSurface property
-and receives frames through a public slot \c onNewVideoContentReceived(). These
-frames are then presented on the surface set in \c setVideoSurface().
+\section2 Android
+See \l{Android supported media formats} for this information.
-\snippet multimedia-snippets/video.cpp Video producer
+\section2 Linux
+On Linux this is about installing the correct \l{GStreamer} plugins.
-\section2 Recording Video
-You can use the \l QMediaRecorder class in conjunction with other
-classes to record video to disk. Primarily this is used with
-the camera, so consult the \l {Camera Overview} for more information.
-
-\section2 Monitoring Video Frames
-You can use the \l QVideoProbe class to access video frames as they
-flow through different parts of a media pipeline when using other
-classes like \l QMediaPlayer, \l QMediaRecorder or \l QCamera. After
-creating the high level media class, you can set the source of the
-video probe to that instance. This can be useful for performing
-some video processing tasks (like barcode recognition, or object
-detection) while the video is rendered normally. You can not affect
-the video frames using this class, and they may arrive at a slightly
-different time than they are being rendered.
-
-Here's an example of installing a video probe while recording the camera:
- \snippet multimedia-snippets/media.cpp Video probe
+\section3 Minimum Required GStreamer Plugins
+\list
+\li gstreamer1.0-plugins-base
+\li gstreamer1.0-plugins-good
+\li gstreamer1.0-plugins-pulseaudio
+\endlist
+
+For a Linux desktop target, it is strongly recommended to have \c gstreamer1.0-libav
+for good codec coverage and \c gstreamer1.0-vaapi to get hardware acceleration.
+
+On embedded Linux, the required set of plugins could be somewhat different.
+
+\section2 Determining Supported Media Formats at Runtime
+You can determine what formats are available on a target system at runtime using
+the static QMediaFormat API.
+
+\list
+\li Use \l QMediaFormat::isSupported() on a QMediaFormat::ConversionMode to query a
+ specific format.
+\li Use \l QMediaFormat::supportedFileFormats() on a default constructed QMediaFormat
+ to get all the supported file formats.
+\endlist
\section1 Examples
diff --git a/src/multimedia/multimedia.pro b/src/multimedia/multimedia.pro
deleted file mode 100644
index 10d49ef59..000000000
--- a/src/multimedia/multimedia.pro
+++ /dev/null
@@ -1,98 +0,0 @@
-TARGET = QtMultimedia
-QT = core-private network gui-private
-
-MODULE_PLUGIN_TYPES = \
- mediaservice \
- audio \
- video/bufferpool \
- video/gstvideorenderer \
- video/videonode \
- playlistformats \
- resourcepolicy
-
-QMAKE_DOCS = $$PWD/doc/qtmultimedia.qdocconf
-
-INCLUDEPATH *= .
-
-PRIVATE_HEADERS += \
- qtmultimediaglobal_p.h \
- qmediacontrol_p.h \
- qmediaobject_p.h \
- qmediapluginloader_p.h \
- qmediaservice_p.h \
- qmediaserviceprovider_p.h \
- qmediaresourcepolicyplugin_p.h \
- qmediaresourcepolicy_p.h \
- qmediaresourceset_p.h \
- qmediastoragelocation_p.h \
- qmultimediautils_p.h
-
-PUBLIC_HEADERS += \
- qtmultimediaglobal.h \
- qmediabindableinterface.h \
- qmediacontrol.h \
- qmediaenumdebug.h \
- qmediametadata.h \
- qmediaobject.h \
- qmediaservice.h \
- qmediaserviceproviderplugin.h \
- qmediatimerange.h \
- qmultimedia.h
-
-SOURCES += \
- qmediabindableinterface.cpp \
- qmediacontrol.cpp \
- qmediametadata.cpp \
- qmediaobject.cpp \
- qmediapluginloader.cpp \
- qmediaservice.cpp \
- qmediaserviceprovider.cpp \
- qmediatimerange.cpp \
- qmediaresourcepolicyplugin_p.cpp \
- qmediaresourcepolicy_p.cpp \
- qmediaresourceset_p.cpp \
- qmediastoragelocation.cpp \
- qmultimedia.cpp \
- qmultimediautils.cpp
-
-CONFIG += simd optimize_full
-
-include(audio/audio.pri)
-include(camera/camera.pri)
-include(controls/controls.pri)
-include(playback/playback.pri)
-include(recording/recording.pri)
-include(video/video.pri)
-
-ANDROID_BUNDLED_JAR_DEPENDENCIES = \
- jar/Qt$${QT_MAJOR_VERSION}AndroidMultimedia.jar:org.qtproject.qt.android.multimedia.QtMultimediaUtils
-ANDROID_LIB_DEPENDENCIES = \
- plugins/mediaservice/libplugins_mediaservice_qtmedia_android.so \
- lib/libQt5MultimediaQuick.so:Qt5Quick
-ANDROID_BUNDLED_FILES += \
- lib/libQt5MultimediaQuick.so
-ANDROID_PERMISSIONS += \
- android.permission.CAMERA \
- android.permission.RECORD_AUDIO
-ANDROID_FEATURES += \
- android.hardware.camera \
- android.hardware.camera.autofocus \
- android.hardware.microphone
-
-MODULE_WINRT_CAPABILITIES_DEVICE += \
- microphone \
- webcam
-
-qtConfig(gstreamer) {
- ANDROID_LIB_DEPENDENCIES += \
- plugins/mediaservice/libgstcamerabin.so \
- plugins/mediaservice/libgstmediacapture.so \
- plugins/mediaservice/libgstmediaplayer.so \
- plugins/mediaservice/libgstaudiodecoder.so
-}
-
-win32: LIBS_PRIVATE += -luuid
-
-HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
-
-load(qt_module)
diff --git a/src/multimedia/platform/qgstreamer_platformspecificinterface.cpp b/src/multimedia/platform/qgstreamer_platformspecificinterface.cpp
new file mode 100644
index 000000000..06ce46e3c
--- /dev/null
+++ b/src/multimedia/platform/qgstreamer_platformspecificinterface.cpp
@@ -0,0 +1,27 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/private/qgstreamer_platformspecificinterface_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QGStreamerPlatformSpecificInterface::~QGStreamerPlatformSpecificInterface() = default;
+
+QGStreamerPlatformSpecificInterface *QGStreamerPlatformSpecificInterface::instance()
+{
+ return dynamic_cast<QGStreamerPlatformSpecificInterface *>(
+ QPlatformMediaIntegration::instance()->platformSpecificInterface());
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/platform/qgstreamer_platformspecificinterface_p.h b/src/multimedia/platform/qgstreamer_platformspecificinterface_p.h
new file mode 100644
index 000000000..1a086f5a4
--- /dev/null
+++ b/src/multimedia/platform/qgstreamer_platformspecificinterface_p.h
@@ -0,0 +1,46 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef GSTREAMER_PLATFORMSPECIFICINTERFACE_P_H
+#define GSTREAMER_PLATFORMSPECIFICINTERFACE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/private/qplatformmediaintegration_p.h>
+
+typedef struct _GstPipeline GstPipeline; // NOLINT (bugprone-reserved-identifier)
+typedef struct _GstElement GstElement; // NOLINT (bugprone-reserved-identifier)
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIA_EXPORT QGStreamerPlatformSpecificInterface
+ : public QAbstractPlatformSpecificInterface
+{
+public:
+ ~QGStreamerPlatformSpecificInterface() override;
+
+ static QGStreamerPlatformSpecificInterface *instance();
+
+ virtual QAudioDevice makeCustomGStreamerAudioInput(const QByteArray &gstreamerPipeline) = 0;
+ virtual QAudioDevice makeCustomGStreamerAudioOutput(const QByteArray &gstreamerPipeline) = 0;
+ virtual QCamera *makeCustomGStreamerCamera(const QByteArray &gstreamerPipeline,
+ QObject *parent) = 0;
+
+ // Note: ownership of GstElement is not transferred
+ virtual QCamera *makeCustomGStreamerCamera(GstElement *, QObject *parent) = 0;
+
+ virtual GstPipeline *gstPipeline(QMediaPlayer *) = 0;
+ virtual GstPipeline *gstPipeline(QMediaCaptureSession *) = 0;
+};
+
+QT_END_NAMESPACE
+
+#endif // GSTREAMER_PLATFORMSPECIFICINTERFACE_P_H
diff --git a/src/multimedia/platform/qplatformaudiobufferinput.cpp b/src/multimedia/platform/qplatformaudiobufferinput.cpp
new file mode 100644
index 000000000..883b11fc0
--- /dev/null
+++ b/src/multimedia/platform/qplatformaudiobufferinput.cpp
@@ -0,0 +1,10 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformaudiobufferinput_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformaudiobufferinput_p.cpp"
diff --git a/src/multimedia/platform/qplatformaudiobufferinput_p.h b/src/multimedia/platform/qplatformaudiobufferinput_p.h
new file mode 100644
index 000000000..a05a98100
--- /dev/null
+++ b/src/multimedia/platform/qplatformaudiobufferinput_p.h
@@ -0,0 +1,56 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMAUDIOBUFFERINPUT_P_H
+#define QPLATFORMAUDIOBUFFERINPUT_P_H
+
+#include "qaudioformat.h"
+#include "qaudiobuffer.h"
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QMediaInputEncoderInterface;
+
+class Q_MULTIMEDIA_EXPORT QPlatformAudioBufferInputBase : public QObject
+{
+ Q_OBJECT
+Q_SIGNALS:
+ void newAudioBuffer(const QAudioBuffer &buffer);
+};
+
+class Q_MULTIMEDIA_EXPORT QPlatformAudioBufferInput : public QPlatformAudioBufferInputBase
+{
+ Q_OBJECT
+public:
+ QPlatformAudioBufferInput(QAudioFormat format = {}) : m_format(std::move(format)) { }
+
+ const QAudioFormat &audioFormat() const { return m_format; }
+
+ QMediaInputEncoderInterface *encoderInterface() const { return m_encoderInterface; }
+ void setEncoderInterface(QMediaInputEncoderInterface *interface)
+ {
+ m_encoderInterface = interface;
+ }
+
+Q_SIGNALS:
+ void encoderUpdated();
+
+private:
+ QMediaInputEncoderInterface *m_encoderInterface = nullptr;
+ QAudioFormat m_format;
+};
+
+QT_END_NAMESPACE
+
+#endif // QPLATFORMAUDIOBUFFERINPUT_P_H
diff --git a/src/multimedia/platform/qplatformaudiodecoder.cpp b/src/multimedia/platform/qplatformaudiodecoder.cpp
new file mode 100644
index 000000000..0bf472410
--- /dev/null
+++ b/src/multimedia/platform/qplatformaudiodecoder.cpp
@@ -0,0 +1,81 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformaudiodecoder_p.h"
+#include "qthread.h"
+
+QT_BEGIN_NAMESPACE
+
+QPlatformAudioDecoder::QPlatformAudioDecoder(QAudioDecoder *parent) : q(parent) { }
+
+QPlatformAudioDecoder::~QPlatformAudioDecoder() = default;
+
+void QPlatformAudioDecoder::error(int error, const QString &errorString)
+{
+ if (error == m_error && errorString == m_errorString)
+ return;
+ m_error = QAudioDecoder::Error(error);
+ m_errorString = errorString;
+
+ if (m_error != QAudioDecoder::NoError) {
+ setIsDecoding(false);
+ emit q->error(m_error);
+ }
+}
+
+void QPlatformAudioDecoder::bufferAvailableChanged(bool available)
+{
+ if (m_bufferAvailable == available)
+ return;
+ m_bufferAvailable = available;
+
+ if (QThread::currentThread() != q->thread())
+ QMetaObject::invokeMethod(q, "bufferAvailableChanged", Qt::QueuedConnection, Q_ARG(bool, available));
+ else
+ emit q->bufferAvailableChanged(available);
+}
+
+void QPlatformAudioDecoder::bufferReady()
+{
+ if (QThread::currentThread() != q->thread())
+ QMetaObject::invokeMethod(q, "bufferReady", Qt::QueuedConnection);
+ else
+ emit q->bufferReady();
+}
+
+void QPlatformAudioDecoder::sourceChanged()
+{
+ emit q->sourceChanged();
+}
+
+void QPlatformAudioDecoder::formatChanged(const QAudioFormat &format)
+{
+ emit q->formatChanged(format);
+}
+
+void QPlatformAudioDecoder::finished()
+{
+ durationChanged(-1);
+ setIsDecoding(false);
+ emit q->finished();
+}
+
+void QPlatformAudioDecoder::positionChanged(qint64 position)
+{
+ if (m_position == position)
+ return;
+ m_position = position;
+ emit q->positionChanged(position);
+}
+
+void QPlatformAudioDecoder::durationChanged(qint64 duration)
+{
+ if (m_duration == duration)
+ return;
+ m_duration = duration;
+ emit q->durationChanged(duration);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformaudiodecoder_p.cpp"
diff --git a/src/multimedia/platform/qplatformaudiodecoder_p.h b/src/multimedia/platform/qplatformaudiodecoder_p.h
new file mode 100644
index 000000000..1159a37ca
--- /dev/null
+++ b/src/multimedia/platform/qplatformaudiodecoder_p.h
@@ -0,0 +1,92 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAUDIODECODERCONTROL_H
+#define QAUDIODECODERCONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qaudiobuffer.h>
+#include <QtMultimedia/qaudiodecoder.h>
+#include <QtCore/qpair.h>
+#include <QtCore/qurl.h>
+#include <QtCore/private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QIODevice;
+class Q_MULTIMEDIA_EXPORT QPlatformAudioDecoder : public QObject
+{
+ Q_OBJECT
+
+public:
+ virtual QUrl source() const = 0;
+ virtual void setSource(const QUrl &fileName) = 0;
+
+ virtual QIODevice* sourceDevice() const = 0;
+ virtual void setSourceDevice(QIODevice *device) = 0;
+
+ virtual void start() = 0;
+ virtual void stop() = 0;
+
+ virtual QAudioFormat audioFormat() const = 0;
+ virtual void setAudioFormat(const QAudioFormat &format) = 0;
+
+ virtual QAudioBuffer read() = 0;
+ virtual bool bufferAvailable() const { return m_bufferAvailable; }
+
+ virtual qint64 position() const { return m_position; }
+ virtual qint64 duration() const { return m_duration; }
+
+ void formatChanged(const QAudioFormat &format);
+
+ void sourceChanged();
+
+ void error(int error, const QString &errorString);
+ void clearError() { error(QAudioDecoder::NoError, QString()); }
+
+ void bufferReady();
+ void bufferAvailableChanged(bool available);
+ void setIsDecoding(bool running = true) {
+ if (m_isDecoding == running)
+ return;
+ m_isDecoding = running;
+ emit q->isDecodingChanged(m_isDecoding);
+ }
+ void finished();
+ bool isDecoding() const { return m_isDecoding; }
+
+ void positionChanged(qint64 position);
+ void durationChanged(qint64 duration);
+
+ QAudioDecoder::Error error() const { return m_error; }
+ QString errorString() const { return m_errorString; }
+
+ virtual ~QPlatformAudioDecoder();
+
+protected:
+ explicit QPlatformAudioDecoder(QAudioDecoder *parent);
+
+private:
+ QAudioDecoder *q = nullptr;
+
+ qint64 m_duration = -1;
+ qint64 m_position = -1;
+ QAudioDecoder::Error m_error = QAudioDecoder::NoError;
+ QString m_errorString;
+ bool m_isDecoding = false;
+ bool m_bufferAvailable = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QAUDIODECODERCONTROL_H
diff --git a/src/multimedia/platform/qplatformaudioinput_p.h b/src/multimedia/platform/qplatformaudioinput_p.h
new file mode 100644
index 000000000..d6497c06e
--- /dev/null
+++ b/src/multimedia/platform/qplatformaudioinput_p.h
@@ -0,0 +1,46 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QPLATFORMAUDIOINPUT_H
+#define QPLATFORMAUDIOINPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <qaudiodevice.h>
+
+#include <functional>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioInput;
+
+class Q_MULTIMEDIA_EXPORT QPlatformAudioInput
+{
+public:
+ explicit QPlatformAudioInput(QAudioInput *qq) : q(qq) { }
+ virtual ~QPlatformAudioInput() = default;
+
+ virtual void setAudioDevice(const QAudioDevice & /*device*/) { }
+ virtual void setMuted(bool /*muted*/) {}
+ virtual void setVolume(float /*volume*/) {}
+
+ QAudioInput *q = nullptr;
+ QAudioDevice device;
+ float volume = 1.;
+ bool muted = false;
+ std::function<void()> disconnectFunction;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QPLATFORMAUDIOINPUT_H
diff --git a/src/multimedia/platform/qplatformaudiooutput_p.h b/src/multimedia/platform/qplatformaudiooutput_p.h
new file mode 100644
index 000000000..b8f5af6f3
--- /dev/null
+++ b/src/multimedia/platform/qplatformaudiooutput_p.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QPLATFORMAUDIOOUTPUT_H
+#define QPLATFORMAUDIOOUTPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <qaudiodevice.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioOutput;
+
+class Q_MULTIMEDIA_EXPORT QPlatformAudioOutput
+{
+public:
+ explicit QPlatformAudioOutput(QAudioOutput *qq) : q(qq) { }
+ virtual ~QPlatformAudioOutput() = default;
+
+ virtual void setAudioDevice(const QAudioDevice &/*device*/) {}
+ virtual void setMuted(bool /*muted*/) {}
+ virtual void setVolume(float /*volume*/) {}
+
+ QAudioOutput *q = nullptr;
+ QAudioDevice device;
+ float volume = 1.;
+ bool muted = false;
+ std::function<void()> disconnectFunction;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QPLATFORMAUDIOOUTPUT_H
diff --git a/src/multimedia/platform/qplatformaudioresampler_p.h b/src/multimedia/platform/qplatformaudioresampler_p.h
new file mode 100644
index 000000000..fd8edc2be
--- /dev/null
+++ b/src/multimedia/platform/qplatformaudioresampler_p.h
@@ -0,0 +1,33 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMAUDIORESAMPLER_P_H
+#define QPLATFORMAUDIORESAMPLER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <qaudiobuffer.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPlatformAudioResampler
+{
+public:
+ virtual ~QPlatformAudioResampler() = default;
+
+ virtual QAudioBuffer resample(const char *data, size_t size) = 0;
+};
+
+QT_END_NAMESPACE
+
+#endif // QPLATFORMAUDIORESAMPLER_P_H
diff --git a/src/multimedia/platform/qplatformcamera.cpp b/src/multimedia/platform/qplatformcamera.cpp
new file mode 100644
index 000000000..d03c19d67
--- /dev/null
+++ b/src/multimedia/platform/qplatformcamera.cpp
@@ -0,0 +1,233 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformcamera_p.h"
+#include "private/qcameradevice_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QPlatformCamera::QPlatformCamera(QCamera *parent) : QPlatformVideoSource(parent), m_camera(parent)
+{
+ qRegisterMetaType<QVideoFrame>();
+}
+
+QCameraFormat QPlatformCamera::findBestCameraFormat(const QCameraDevice &camera) const
+{
+ // check if fmt is better. We try to find the highest resolution that offers
+ // at least 30 FPS
+ // we use 29 FPS to compare against as some cameras report 29.97 FPS...
+
+ auto makeCriteria = [this](const QCameraFormat &fmt) {
+ constexpr float MinSufficientFrameRate = 29.f;
+
+ const auto isValid = fmt.pixelFormat() != QVideoFrameFormat::Format_Invalid;
+ const auto resolution = fmt.resolution();
+ const auto sufficientFrameRate = std::min(fmt.maxFrameRate(), MinSufficientFrameRate);
+ const auto pixelFormatScore =
+ cameraPixelFormatScore(fmt.pixelFormat(), QCameraFormatPrivate::getColorRange(fmt));
+
+ return std::make_tuple(
+ isValid, // 1st: ensure valid formats
+ sufficientFrameRate, // 2nd: ensure the highest frame rate in the range [0; 29]*/
+ resolution.width() * resolution.height(), // 3rd: ensure the highest resolution
+ pixelFormatScore, // 4th: eshure the best pixel format
+ fmt.maxFrameRate()); // 5th: ensure the highest framerate in the whole range
+ };
+
+ const auto formats = camera.videoFormats();
+ const auto found =
+ std::max_element(formats.begin(), formats.end(),
+ [makeCriteria](const QCameraFormat &fmtA, const QCameraFormat &fmtB) {
+ return makeCriteria(fmtA) < makeCriteria(fmtB);
+ });
+
+ return found == formats.end() ? QCameraFormat{} : *found;
+}
+
+QVideoFrameFormat QPlatformCamera::frameFormat() const
+{
+ QVideoFrameFormat result(m_cameraFormat.resolution(),
+ m_framePixelFormat == QVideoFrameFormat::Format_Invalid
+ ? m_cameraFormat.pixelFormat()
+ : m_framePixelFormat);
+ result.setStreamFrameRate(m_cameraFormat.maxFrameRate());
+ return result;
+}
+
+void QPlatformCamera::supportedFeaturesChanged(QCamera::Features f)
+{
+ if (m_supportedFeatures == f)
+ return;
+ m_supportedFeatures = f;
+ emit m_camera->supportedFeaturesChanged();
+}
+
+void QPlatformCamera::minimumZoomFactorChanged(float factor)
+{
+ if (m_minZoom == factor)
+ return;
+ m_minZoom = factor;
+ emit m_camera->minimumZoomFactorChanged(factor);
+}
+
+void QPlatformCamera::maximumZoomFactorChanged(float factor)
+{
+ if (m_maxZoom == factor)
+ return;
+ m_maxZoom = factor;
+ emit m_camera->maximumZoomFactorChanged(factor);
+}
+
+void QPlatformCamera::focusModeChanged(QCamera::FocusMode mode)
+{
+ if (m_focusMode == mode)
+ return;
+ m_focusMode = mode;
+ emit m_camera->focusModeChanged();
+}
+
+void QPlatformCamera::customFocusPointChanged(const QPointF &point)
+{
+ if (m_customFocusPoint == point)
+ return;
+ m_customFocusPoint = point;
+ emit m_camera->customFocusPointChanged();
+}
+
+
+void QPlatformCamera::zoomFactorChanged(float zoom)
+{
+ if (m_zoomFactor == zoom)
+ return;
+ m_zoomFactor = zoom;
+ emit m_camera->zoomFactorChanged(zoom);
+}
+
+
+void QPlatformCamera::focusDistanceChanged(float d)
+{
+ if (m_focusDistance == d)
+ return;
+ m_focusDistance = d;
+ emit m_camera->focusDistanceChanged(m_focusDistance);
+}
+
+
+void QPlatformCamera::flashReadyChanged(bool ready)
+{
+ if (m_flashReady == ready)
+ return;
+ m_flashReady = ready;
+ emit m_camera->flashReady(m_flashReady);
+}
+
+void QPlatformCamera::flashModeChanged(QCamera::FlashMode mode)
+{
+ if (m_flashMode == mode)
+ return;
+ m_flashMode = mode;
+ emit m_camera->flashModeChanged();
+}
+
+void QPlatformCamera::torchModeChanged(QCamera::TorchMode mode)
+{
+ if (m_torchMode == mode)
+ return;
+ m_torchMode = mode;
+ emit m_camera->torchModeChanged();
+}
+
+void QPlatformCamera::exposureModeChanged(QCamera::ExposureMode mode)
+{
+ if (m_exposureMode == mode)
+ return;
+ m_exposureMode = mode;
+ emit m_camera->exposureModeChanged();
+}
+
+void QPlatformCamera::exposureCompensationChanged(float compensation)
+{
+ if (m_exposureCompensation == compensation)
+ return;
+ m_exposureCompensation = compensation;
+ emit m_camera->exposureCompensationChanged(compensation);
+}
+
+void QPlatformCamera::exposureCompensationRangeChanged(float min, float max)
+{
+ if (m_minExposureCompensation == min && m_maxExposureCompensation == max)
+ return;
+ m_minExposureCompensation = min;
+ m_maxExposureCompensation = max;
+ // tell frontend
+}
+
+void QPlatformCamera::isoSensitivityChanged(int iso)
+{
+ if (m_iso == iso)
+ return;
+ m_iso = iso;
+ emit m_camera->isoSensitivityChanged(iso);
+}
+
+void QPlatformCamera::exposureTimeChanged(float speed)
+{
+ if (m_exposureTime == speed)
+ return;
+ m_exposureTime = speed;
+ emit m_camera->exposureTimeChanged(speed);
+}
+
+void QPlatformCamera::whiteBalanceModeChanged(QCamera::WhiteBalanceMode mode)
+{
+ if (m_whiteBalance == mode)
+ return;
+ m_whiteBalance = mode;
+ emit m_camera->whiteBalanceModeChanged();
+}
+
+void QPlatformCamera::colorTemperatureChanged(int temperature)
+{
+ Q_ASSERT(temperature >= 0);
+ Q_ASSERT((temperature > 0 && whiteBalanceMode() == QCamera::WhiteBalanceManual) ||
+ (temperature == 0 && whiteBalanceMode() == QCamera::WhiteBalanceAuto));
+ if (m_colorTemperature == temperature)
+ return;
+ m_colorTemperature = temperature;
+ emit m_camera->colorTemperatureChanged();
+}
+
+int QPlatformCamera::colorTemperatureForWhiteBalance(QCamera::WhiteBalanceMode mode)
+{
+ switch (mode) {
+ case QCamera::WhiteBalanceAuto:
+ break;
+ case QCamera::WhiteBalanceManual:
+ case QCamera::WhiteBalanceSunlight:
+ return 5600;
+ case QCamera::WhiteBalanceCloudy:
+ return 6000;
+ case QCamera::WhiteBalanceShade:
+ return 7000;
+ case QCamera::WhiteBalanceTungsten:
+ return 3200;
+ case QCamera::WhiteBalanceFluorescent:
+ return 4000;
+ case QCamera::WhiteBalanceFlash:
+ return 5500;
+ case QCamera::WhiteBalanceSunset:
+ return 3000;
+ }
+ return 0;
+}
+
+void QPlatformCamera::updateError(QCamera::Error error, const QString &errorString)
+{
+ QMetaObject::invokeMethod(this, [this, error, errorString]() {
+ m_error.setAndNotify(error, errorString, *this);
+ });
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformcamera_p.cpp"
diff --git a/src/multimedia/platform/qplatformcamera_p.h b/src/multimedia/platform/qplatformcamera_p.h
new file mode 100644
index 000000000..341bf9121
--- /dev/null
+++ b/src/multimedia/platform/qplatformcamera_p.h
@@ -0,0 +1,165 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMCAMERA_H
+#define QPLATFORMCAMERA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qplatformvideosource_p.h"
+#include "private/qerrorinfo_p.h"
+#include <QtMultimedia/qcamera.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIA_EXPORT QPlatformCamera : public QPlatformVideoSource
+{
+ Q_OBJECT
+
+public:
+ virtual void setCamera(const QCameraDevice &camera) = 0;
+ virtual bool setCameraFormat(const QCameraFormat &/*format*/) { return false; }
+ QCameraFormat cameraFormat() const { return m_cameraFormat; }
+
+ virtual bool isFocusModeSupported(QCamera::FocusMode mode) const { return mode == QCamera::FocusModeAuto; }
+ virtual void setFocusMode(QCamera::FocusMode /*mode*/) {}
+
+ virtual void setCustomFocusPoint(const QPointF &/*point*/) {}
+
+ virtual void setFocusDistance(float) {}
+
+ // smaller 0: zoom instantly, rate in power-of-two/sec
+ virtual void zoomTo(float /*newZoomFactor*/, float /*rate*/ = -1.) {}
+
+ virtual void setFlashMode(QCamera::FlashMode /*mode*/) {}
+ virtual bool isFlashModeSupported(QCamera::FlashMode mode) const { return mode == QCamera::FlashOff; }
+ virtual bool isFlashReady() const { return false; }
+
+ virtual void setTorchMode(QCamera::TorchMode /*mode*/) {}
+ virtual bool isTorchModeSupported(QCamera::TorchMode mode) const { return mode == QCamera::TorchOff; }
+
+ virtual void setExposureMode(QCamera::ExposureMode) {}
+ virtual bool isExposureModeSupported(QCamera::ExposureMode mode) const { return mode == QCamera::ExposureAuto; }
+ virtual void setExposureCompensation(float) {}
+ virtual int isoSensitivity() const { return 100; }
+ virtual void setManualIsoSensitivity(int) {}
+ virtual void setManualExposureTime(float) {}
+ virtual float exposureTime() const { return -1.; }
+
+ virtual bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const { return mode == QCamera::WhiteBalanceAuto; }
+ virtual void setWhiteBalanceMode(QCamera::WhiteBalanceMode /*mode*/) {}
+ virtual void setColorTemperature(int /*temperature*/) {}
+
+ QVideoFrameFormat frameFormat() const override;
+
+ QCamera::Features supportedFeatures() const { return m_supportedFeatures; }
+
+ QCamera::FocusMode focusMode() const { return m_focusMode; }
+ QPointF focusPoint() const { return m_customFocusPoint; }
+
+ float minZoomFactor() const { return m_minZoom; }
+ float maxZoomFactor() const { return m_maxZoom; }
+ float zoomFactor() const { return m_zoomFactor; }
+ QPointF customFocusPoint() const { return m_customFocusPoint; }
+ float focusDistance() const { return m_focusDistance; }
+
+ QCamera::FlashMode flashMode() const { return m_flashMode; }
+ QCamera::TorchMode torchMode() const { return m_torchMode; }
+
+ QCamera::ExposureMode exposureMode() const { return m_exposureMode; }
+ float exposureCompensation() const { return m_exposureCompensation; }
+ int manualIsoSensitivity() const { return m_iso; }
+ int minIso() const { return m_minIso; }
+ int maxIso() const { return m_maxIso; }
+ float manualExposureTime() const { return m_exposureTime; }
+ float minExposureTime() const { return m_minExposureTime; }
+ float maxExposureTime() const { return m_maxExposureTime; }
+ QCamera::WhiteBalanceMode whiteBalanceMode() const { return m_whiteBalance; }
+ int colorTemperature() const { return m_colorTemperature; }
+
+ void supportedFeaturesChanged(QCamera::Features);
+ void minimumZoomFactorChanged(float factor);
+ void maximumZoomFactorChanged(float);
+ void focusModeChanged(QCamera::FocusMode mode);
+ void customFocusPointChanged(const QPointF &point);
+ void focusDistanceChanged(float d);
+ void zoomFactorChanged(float zoom);
+ void flashReadyChanged(bool);
+ void flashModeChanged(QCamera::FlashMode mode);
+ void torchModeChanged(QCamera::TorchMode mode);
+ void exposureModeChanged(QCamera::ExposureMode mode);
+ void exposureCompensationChanged(float compensation);
+ void exposureCompensationRangeChanged(float min, float max);
+ void isoSensitivityChanged(int iso);
+ void minIsoChanged(int iso) { m_minIso = iso; }
+ void maxIsoChanged(int iso) { m_maxIso = iso; }
+ void exposureTimeChanged(float speed);
+ void minExposureTimeChanged(float secs) { m_minExposureTime = secs; }
+ void maxExposureTimeChanged(float secs) { m_maxExposureTime = secs; }
+ void whiteBalanceModeChanged(QCamera::WhiteBalanceMode mode);
+ void colorTemperatureChanged(int temperature);
+
+ static int colorTemperatureForWhiteBalance(QCamera::WhiteBalanceMode mode);
+
+ QCamera::Error error() const { return m_error.code(); }
+ QString errorString() const final { return m_error.description(); }
+
+ void updateError(QCamera::Error error, const QString &errorString);
+
+Q_SIGNALS:
+ void errorOccurred(QCamera::Error error, const QString &errorString);
+
+protected:
+ explicit QPlatformCamera(QCamera *parent);
+
+ virtual int cameraPixelFormatScore(QVideoFrameFormat::PixelFormat /*format*/,
+ QVideoFrameFormat::ColorRange /*colorRange*/) const
+ {
+ return 0;
+ }
+
+ QCameraFormat findBestCameraFormat(const QCameraDevice &camera) const;
+ QCameraFormat m_cameraFormat;
+ QVideoFrameFormat::PixelFormat m_framePixelFormat = QVideoFrameFormat::Format_Invalid;
+
+private:
+ QCamera *m_camera = nullptr;
+ QCamera::Features m_supportedFeatures = {};
+ QCamera::FocusMode m_focusMode = QCamera::FocusModeAuto;
+ float m_minZoom = 1.;
+ float m_maxZoom = 1.;
+ float m_zoomFactor = 1.;
+ float m_focusDistance = 1.;
+ QPointF m_customFocusPoint{-1, -1};
+ bool m_flashReady = false;
+ QCamera::FlashMode m_flashMode = QCamera::FlashOff;
+ QCamera::TorchMode m_torchMode = QCamera::TorchOff;
+ QCamera::ExposureMode m_exposureMode = QCamera::ExposureAuto;
+ float m_exposureCompensation = 0.;
+ float m_minExposureCompensation = 0.;
+ float m_maxExposureCompensation = 0.;
+ int m_iso = -1;
+ int m_minIso = -1;
+ int m_maxIso = -1;
+ float m_exposureTime = -1.;
+ float m_minExposureTime = -1.;
+ float m_maxExposureTime = -1.;
+ QCamera::WhiteBalanceMode m_whiteBalance = QCamera::WhiteBalanceAuto;
+ int m_colorTemperature = 0;
+ QErrorInfo<QCamera::Error> m_error;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QPLATFORMCAMERA_H
+
diff --git a/src/multimedia/platform/qplatformcapturablewindows_p.h b/src/multimedia/platform/qplatformcapturablewindows_p.h
new file mode 100644
index 000000000..41949aaac
--- /dev/null
+++ b/src/multimedia/platform/qplatformcapturablewindows_p.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMCAPTURABLEWINDOWS_P_H
+#define QPLATFORMCAPTURABLEWINDOWS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qtmultimediaglobal_p.h"
+#include "qcapturablewindow.h"
+
+#include <qlist.h>
+
+QT_BEGIN_NAMESPACE
+
+class QCapturableWindow;
+class QCapturableWindowPrivate;
+
+class QPlatformCapturableWindows
+{
+public:
+ QPlatformCapturableWindows() = default;
+
+ virtual ~QPlatformCapturableWindows() = default;
+
+ virtual QList<QCapturableWindow> windows() const { return {}; }
+
+ virtual bool isWindowValid(const QCapturableWindowPrivate &) const { return false; }
+
+ Q_DISABLE_COPY(QPlatformCapturableWindows);
+};
+
+QT_END_NAMESPACE
+
+#endif // QPLATFORMCAPTURABLEWINDOWS_P_H
diff --git a/src/multimedia/platform/qplatformimagecapture.cpp b/src/multimedia/platform/qplatformimagecapture.cpp
new file mode 100644
index 000000000..5d8349256
--- /dev/null
+++ b/src/multimedia/platform/qplatformimagecapture.cpp
@@ -0,0 +1,27 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformimagecapture_p.h"
+#include <QtCore/qstringlist.h>
+
+QT_BEGIN_NAMESPACE
+
+QPlatformImageCapture::QPlatformImageCapture(QImageCapture *parent)
+ : QObject(parent),
+ m_imageCapture(parent)
+{
+}
+
+QString QPlatformImageCapture::msgCameraNotReady()
+{
+ return QImageCapture::tr("Camera is not ready.");
+}
+
+QString QPlatformImageCapture::msgImageCaptureNotSet()
+{
+ return QImageCapture::tr("No instance of QImageCapture set on QMediaCaptureSession.");
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformimagecapture_p.cpp"
diff --git a/src/multimedia/platform/qplatformimagecapture_p.h b/src/multimedia/platform/qplatformimagecapture_p.h
new file mode 100644
index 000000000..5bfb15ced
--- /dev/null
+++ b/src/multimedia/platform/qplatformimagecapture_p.h
@@ -0,0 +1,97 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCAMERAIMAGECAPTURECONTROL_H
+#define QCAMERAIMAGECAPTURECONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qimagecapture.h>
+#include <QtMultimedia/qmediametadata.h>
+#include <QtMultimedia/qimagecapture.h>
+#include <QtCore/private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QImage;
+class QPlatformMediaCaptureSession;
+
+class QImageEncoderSettingsPrivate;
+class Q_MULTIMEDIA_EXPORT QImageEncoderSettings
+{
+ QImageCapture::FileFormat m_format = QImageCapture::UnspecifiedFormat;
+ QSize m_resolution;
+ QImageCapture::Quality m_quality = QImageCapture::NormalQuality;
+
+public:
+ bool operator==(const QImageEncoderSettings &other) {
+ return m_format == other.m_format &&
+ m_resolution == other.m_resolution &&
+ m_quality == other.m_quality;
+ }
+ bool operator!=(const QImageEncoderSettings &other) { return !operator==(other); }
+
+ QImageCapture::FileFormat format() const { return m_format; }
+ void setFormat(QImageCapture::FileFormat f) { m_format = f; }
+
+ QSize resolution() const { return m_resolution; }
+ void setResolution(const QSize &s) { m_resolution = s; }
+ void setResolution(int width, int height) { m_resolution = QSize(width, height); }
+
+ QImageCapture::Quality quality() const { return m_quality; }
+ void setQuality(QImageCapture::Quality quality) { m_quality = quality; }
+};
+
+class Q_MULTIMEDIA_EXPORT QPlatformImageCapture : public QObject
+{
+ Q_OBJECT
+
+public:
+ virtual bool isReadyForCapture() const = 0;
+
+ virtual int capture(const QString &fileName) = 0;
+ virtual int captureToBuffer() = 0;
+
+ virtual QImageEncoderSettings imageSettings() const = 0;
+ virtual void setImageSettings(const QImageEncoderSettings &settings) = 0;
+
+ virtual void setMetaData(const QMediaMetaData &m) { m_metaData = m; }
+ QMediaMetaData metaData() const { return m_metaData; }
+
+ QImageCapture *imageCapture() { return m_imageCapture; }
+
+ static QString msgCameraNotReady();
+ static QString msgImageCaptureNotSet();
+
+Q_SIGNALS:
+ void readyForCaptureChanged(bool ready);
+
+ void imageExposed(int requestId);
+ void imageCaptured(int requestId, const QImage &preview);
+ void imageMetadataAvailable(int id, const QMediaMetaData &);
+ void imageAvailable(int requestId, const QVideoFrame &buffer);
+ void imageSaved(int requestId, const QString &fileName);
+
+ void error(int id, int error, const QString &errorString);
+
+protected:
+ explicit QPlatformImageCapture(QImageCapture *parent = nullptr);
+private:
+ QImageCapture *m_imageCapture = nullptr;
+ QMediaMetaData m_metaData;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QCAMERAIMAGECAPTURECONTROL_H
+
diff --git a/src/multimedia/platform/qplatformmediacapture.cpp b/src/multimedia/platform/qplatformmediacapture.cpp
new file mode 100644
index 000000000..13bcbd63b
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediacapture.cpp
@@ -0,0 +1,37 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtMultimedia/qaudiodevice.h>
+#include <QtMultimedia/qaudioinput.h>
+#include <QtMultimedia/qmediacapturesession.h>
+#include <QtMultimedia/private/qplatformcamera_p.h>
+#include <QtMultimedia/private/qplatformmediacapture_p.h>
+#include <QtMultimedia/private/qmediacapturesession_p.h>
+#include <QtMultimedia/private/qplatformsurfacecapture_p.h>
+#include <QtMultimedia/private/qplatformvideoframeinput_p.h>
+#include <QtMultimedia/private/qtmultimediaglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QPlatformMediaCaptureSession::~QPlatformMediaCaptureSession() = default;
+
+std::vector<QPlatformVideoSource *> QPlatformMediaCaptureSession::activeVideoSources()
+{
+ std::vector<QPlatformVideoSource *> result;
+
+ auto checkSource = [&result](QPlatformVideoSource *source) {
+ if (source && source->isActive())
+ result.push_back(source);
+ };
+
+ checkSource(videoFrameInput());
+ checkSource(camera());
+ checkSource(screenCapture());
+ checkSource(windowCapture());
+
+ return result;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformmediacapture_p.cpp"
diff --git a/src/multimedia/platform/qplatformmediacapture_p.h b/src/multimedia/platform/qplatformmediacapture_p.h
new file mode 100644
index 000000000..8d6afc90e
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediacapture_p.h
@@ -0,0 +1,89 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QPLATFORMMEDIACAPTURE_H
+#define QPLATFORMMEDIACAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <QtCore/qobject.h>
+
+QT_BEGIN_NAMESPACE
+class QPlatformCamera;
+class QPlatformImageCapture;
+class QPlatformMediaRecorder;
+class QAudioDevice;
+class QCameraDevice;
+class QVideoSink;
+class QPlatformAudioInput;
+class QPlatformAudioOutput;
+class QMediaCaptureSession;
+class QPlatformSurfaceCapture;
+class QPlatformVideoSource;
+class QPlatformAudioBufferInput;
+class QPlatformVideoFrameInput;
+
+class Q_MULTIMEDIA_EXPORT QPlatformMediaCaptureSession : public QObject
+{
+ Q_OBJECT
+public:
+ QPlatformMediaCaptureSession() = default;
+ ~QPlatformMediaCaptureSession() override;
+
+ void setCaptureSession(QMediaCaptureSession *session) { m_session = session; }
+ QMediaCaptureSession *captureSession() const { return m_session; }
+
+ virtual QPlatformCamera *camera() = 0;
+ virtual void setCamera(QPlatformCamera *) {}
+
+ virtual QPlatformSurfaceCapture *screenCapture() { return nullptr; }
+ virtual void setScreenCapture(QPlatformSurfaceCapture *) {}
+
+ virtual QPlatformSurfaceCapture *windowCapture() { return nullptr; }
+ virtual void setWindowCapture(QPlatformSurfaceCapture *) { }
+
+ virtual QPlatformVideoFrameInput *videoFrameInput() { return nullptr; }
+ virtual void setVideoFrameInput(QPlatformVideoFrameInput *) { }
+
+ virtual QPlatformImageCapture *imageCapture() = 0;
+ virtual void setImageCapture(QPlatformImageCapture *) {}
+
+ virtual QPlatformMediaRecorder *mediaRecorder() = 0;
+ virtual void setMediaRecorder(QPlatformMediaRecorder *) {}
+
+ virtual void setAudioInput(QPlatformAudioInput *input) = 0;
+
+ virtual void setAudioBufferInput(QPlatformAudioBufferInput *) { }
+
+ virtual void setVideoPreview(QVideoSink * /*sink*/) {}
+
+ virtual void setAudioOutput(QPlatformAudioOutput *) {}
+
+ // TBD: implement ordering of the sources basing on the order of adding
+ std::vector<QPlatformVideoSource *> activeVideoSources();
+
+Q_SIGNALS:
+ void cameraChanged();
+ void screenCaptureChanged();
+ void windowCaptureChanged();
+ void videoFrameInputChanged();
+ void imageCaptureChanged();
+ void encoderChanged();
+
+private:
+ QMediaCaptureSession *m_session = nullptr;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QPLATFORMMEDIAINTERFACE_H
diff --git a/src/multimedia/platform/qplatformmediadevices.cpp b/src/multimedia/platform/qplatformmediadevices.cpp
new file mode 100644
index 000000000..a6029228d
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediadevices.cpp
@@ -0,0 +1,114 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformmediadevices_p.h"
+#include "qplatformmediaintegration_p.h"
+#include "qcameradevice.h"
+#include "qaudiosystem_p.h"
+#include "qaudiodevice.h"
+#include "qplatformvideodevices_p.h"
+
+#if defined(Q_OS_ANDROID)
+#include <qandroidmediadevices_p.h>
+#elif defined(Q_OS_DARWIN)
+#include <qdarwinmediadevices_p.h>
+#elif defined(Q_OS_WINDOWS) && QT_CONFIG(wmf)
+#include <qwindowsmediadevices_p.h>
+#elif QT_CONFIG(alsa)
+#include <qalsamediadevices_p.h>
+#elif QT_CONFIG(pulseaudio)
+#include <qpulseaudiomediadevices_p.h>
+#elif defined(Q_OS_QNX)
+#include <qqnxmediadevices_p.h>
+#elif defined(Q_OS_WASM)
+#include <private/qwasmmediadevices_p.h>
+#endif
+
+
+QT_BEGIN_NAMESPACE
+
+std::unique_ptr<QPlatformMediaDevices> QPlatformMediaDevices::create()
+{
+#ifdef Q_OS_DARWIN
+ return std::make_unique<QDarwinMediaDevices>();
+#elif defined(Q_OS_WINDOWS) && QT_CONFIG(wmf)
+ return std::make_unique<QWindowsMediaDevices>();
+#elif defined(Q_OS_ANDROID)
+ return std::make_unique<QAndroidMediaDevices>();
+#elif QT_CONFIG(alsa)
+ return std::make_unique<QAlsaMediaDevices>();
+#elif QT_CONFIG(pulseaudio)
+ return std::make_unique<QPulseAudioMediaDevices>();
+#elif defined(Q_OS_QNX)
+ return std::make_unique<QQnxMediaDevices>();
+#elif defined(Q_OS_WASM)
+ return std::make_unique<QWasmMediaDevices>();
+#else
+ return std::make_unique<QPlatformMediaDevices>();
+#endif
+}
+
+QPlatformMediaDevices::QPlatformMediaDevices() = default;
+
+void QPlatformMediaDevices::initVideoDevicesConnection()
+{
+ // Make sure we are notified if video inputs changed
+ if (const auto videoDevices = QPlatformMediaIntegration::instance()->videoDevices())
+ connect(videoDevices, &QPlatformVideoDevices::videoInputsChanged, this,
+ &QPlatformMediaDevices::videoInputsChanged, Qt::UniqueConnection);
+}
+
+QPlatformMediaDevices::~QPlatformMediaDevices() = default;
+
+QList<QAudioDevice> QPlatformMediaDevices::audioInputs() const
+{
+ return {};
+}
+
+QList<QAudioDevice> QPlatformMediaDevices::audioOutputs() const
+{
+ return {};
+}
+
+QPlatformAudioSource *QPlatformMediaDevices::createAudioSource(const QAudioDevice &, QObject *)
+{
+ return nullptr;
+}
+QPlatformAudioSink *QPlatformMediaDevices::createAudioSink(const QAudioDevice &, QObject *)
+{
+ return nullptr;
+}
+
+QPlatformAudioSource *QPlatformMediaDevices::audioInputDevice(const QAudioFormat &format,
+ const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ QAudioDevice info = deviceInfo;
+ if (info.isNull())
+ info = audioInputs().value(0);
+
+ QPlatformAudioSource* p = !info.isNull() ? createAudioSource(info, parent) : nullptr;
+ if (p)
+ p->setFormat(format);
+ return p;
+}
+
+QPlatformAudioSink *QPlatformMediaDevices::audioOutputDevice(const QAudioFormat &format,
+ const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ QAudioDevice info = deviceInfo;
+ if (info.isNull())
+ info = audioOutputs().value(0);
+
+ QPlatformAudioSink* p = !info.isNull() ? createAudioSink(info, parent) : nullptr;
+ if (p)
+ p->setFormat(format);
+ return p;
+}
+
+void QPlatformMediaDevices::prepareAudio() { }
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformmediadevices_p.cpp"
diff --git a/src/multimedia/platform/qplatformmediadevices_p.h b/src/multimedia/platform/qplatformmediadevices_p.h
new file mode 100644
index 000000000..0de41a973
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediadevices_p.h
@@ -0,0 +1,63 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMMEDIADEVICES_H
+#define QPLATFORMMEDIADEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <qlist.h>
+#include <qobject.h>
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioDevice;
+class QPlatformAudioSource;
+class QPlatformAudioSink;
+class QAudioFormat;
+
+class Q_MULTIMEDIA_EXPORT QPlatformMediaDevices : public QObject
+{
+ Q_OBJECT
+public:
+ QPlatformMediaDevices();
+ ~QPlatformMediaDevices() override;
+
+ static std::unique_ptr<QPlatformMediaDevices> create();
+
+ virtual QList<QAudioDevice> audioInputs() const;
+ virtual QList<QAudioDevice> audioOutputs() const;
+
+ virtual QPlatformAudioSource *createAudioSource(const QAudioDevice &, QObject *parent);
+ virtual QPlatformAudioSink *createAudioSink(const QAudioDevice &, QObject *parent);
+
+ QPlatformAudioSource *audioInputDevice(const QAudioFormat &format,
+ const QAudioDevice &deviceInfo, QObject *parent);
+ QPlatformAudioSink *audioOutputDevice(const QAudioFormat &format,
+ const QAudioDevice &deviceInfo, QObject *parent);
+
+ virtual void prepareAudio();
+
+ void initVideoDevicesConnection();
+
+Q_SIGNALS:
+ void audioInputsChanged();
+ void audioOutputsChanged();
+ void videoInputsChanged();
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QPLATFORMMEDIADEVICES_H
diff --git a/src/multimedia/platform/qplatformmediaformatinfo.cpp b/src/multimedia/platform/qplatformmediaformatinfo.cpp
new file mode 100644
index 000000000..e69b32ed3
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediaformatinfo.cpp
@@ -0,0 +1,76 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformmediaformatinfo_p.h"
+#include <qset.h>
+
+QT_BEGIN_NAMESPACE
+
+QPlatformMediaFormatInfo::QPlatformMediaFormatInfo() = default;
+
+QPlatformMediaFormatInfo::~QPlatformMediaFormatInfo() = default;
+
+QList<QMediaFormat::FileFormat> QPlatformMediaFormatInfo::supportedFileFormats(const QMediaFormat &constraints, QMediaFormat::ConversionMode m) const
+{
+ QSet<QMediaFormat::FileFormat> formats;
+
+ const auto &codecMap = (m == QMediaFormat::Encode) ? encoders : decoders;
+ for (const auto &m : codecMap) {
+ if (constraints.audioCodec() != QMediaFormat::AudioCodec::Unspecified && !m.audio.contains(constraints.audioCodec()))
+ continue;
+ if (constraints.videoCodec() != QMediaFormat::VideoCodec::Unspecified && !m.video.contains(constraints.videoCodec()))
+ continue;
+ formats.insert(m.format);
+ }
+ return formats.values();
+}
+
+QList<QMediaFormat::AudioCodec> QPlatformMediaFormatInfo::supportedAudioCodecs(const QMediaFormat &constraints, QMediaFormat::ConversionMode m) const
+{
+ QSet<QMediaFormat::AudioCodec> codecs;
+
+ const auto &codecMap = (m == QMediaFormat::Encode) ? encoders : decoders;
+ for (const auto &m : codecMap) {
+ if (constraints.fileFormat() != QMediaFormat::UnspecifiedFormat && m.format != constraints.fileFormat())
+ continue;
+ if (constraints.videoCodec() != QMediaFormat::VideoCodec::Unspecified && !m.video.contains(constraints.videoCodec()))
+ continue;
+ for (const auto &c : m.audio)
+ codecs.insert(c);
+ }
+ return codecs.values();
+}
+
+QList<QMediaFormat::VideoCodec> QPlatformMediaFormatInfo::supportedVideoCodecs(const QMediaFormat &constraints, QMediaFormat::ConversionMode m) const
+{
+ QSet<QMediaFormat::VideoCodec> codecs;
+
+ const auto &codecMap = (m == QMediaFormat::Encode) ? encoders : decoders;
+ for (const auto &m : codecMap) {
+ if (constraints.fileFormat() != QMediaFormat::UnspecifiedFormat && m.format != constraints.fileFormat())
+ continue;
+ if (constraints.audioCodec() != QMediaFormat::AudioCodec::Unspecified && !m.audio.contains(constraints.audioCodec()))
+ continue;
+ for (const auto &c : m.video)
+ codecs.insert(c);
+ }
+ return codecs.values();
+}
+
+bool QPlatformMediaFormatInfo::isSupported(const QMediaFormat &format, QMediaFormat::ConversionMode m) const
+{
+ const auto &codecMap = (m == QMediaFormat::Encode) ? encoders : decoders;
+
+ for (const auto &m : codecMap) {
+ if (m.format != format.fileFormat())
+ continue;
+ if (!m.audio.contains(format.audioCodec()))
+ continue;
+ if (format.videoCodec() != QMediaFormat::VideoCodec::Unspecified && !m.video.contains(format.videoCodec()))
+ continue;
+ return true;
+ }
+ return false;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/platform/qplatformmediaformatinfo_p.h b/src/multimedia/platform/qplatformmediaformatinfo_p.h
new file mode 100644
index 000000000..4229a3c4c
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediaformatinfo_p.h
@@ -0,0 +1,50 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMMEDIAFORMATINFO_H
+#define QPLATFORMMEDIAFORMATINFO_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <qimagecapture.h>
+#include <qmediaformat.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIA_EXPORT QPlatformMediaFormatInfo
+{
+public:
+ QPlatformMediaFormatInfo();
+ virtual ~QPlatformMediaFormatInfo();
+
+ QList<QMediaFormat::FileFormat> supportedFileFormats(const QMediaFormat &constraints, QMediaFormat::ConversionMode m) const;
+ QList<QMediaFormat::AudioCodec> supportedAudioCodecs(const QMediaFormat &constraints, QMediaFormat::ConversionMode m) const;
+ QList<QMediaFormat::VideoCodec> supportedVideoCodecs(const QMediaFormat &constraints, QMediaFormat::ConversionMode m) const;
+
+ bool isSupported(const QMediaFormat &format, QMediaFormat::ConversionMode m) const;
+
+ struct CodecMap {
+ QMediaFormat::FileFormat format;
+ QList<QMediaFormat::AudioCodec> audio;
+ QList<QMediaFormat::VideoCodec> video;
+ };
+ QList<CodecMap> encoders;
+ QList<CodecMap> decoders;
+
+ QList<QImageCapture::FileFormat> imageFormats;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QPLATFORMMEDIAFORMATINFO_H
diff --git a/src/multimedia/platform/qplatformmediaintegration.cpp b/src/multimedia/platform/qplatformmediaintegration.cpp
new file mode 100644
index 000000000..4bacc488f
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediaintegration.cpp
@@ -0,0 +1,222 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <qtmultimediaglobal_p.h>
+#include "qplatformmediaintegration_p.h"
+#include <qatomic.h>
+#include <qmutex.h>
+#include <qplatformaudioinput_p.h>
+#include <qplatformaudiooutput_p.h>
+#include <qplatformaudioresampler_p.h>
+#include <qplatformvideodevices_p.h>
+#include <qmediadevices.h>
+#include <qcameradevice.h>
+#include <qloggingcategory.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qapplicationstatic.h>
+
+#include "qplatformcapturablewindows_p.h"
+#include "qplatformmediadevices_p.h"
+#include <QtCore/private/qfactoryloader_p.h>
+#include <QtCore/private/qcoreapplication_p.h>
+#include <private/qplatformmediaformatinfo_p.h>
+#include "qplatformmediaplugin_p.h"
+
+namespace {
+
+class QFallbackIntegration : public QPlatformMediaIntegration
+{
+public:
+ QFallbackIntegration() : QPlatformMediaIntegration(QLatin1String("fallback"))
+ {
+ qWarning("No QtMultimedia backends found. Only QMediaDevices, QAudioDevice, QSoundEffect, QAudioSink, and QAudioSource are available.");
+ }
+};
+
+static Q_LOGGING_CATEGORY(qLcMediaPlugin, "qt.multimedia.plugin")
+
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
+ (QPlatformMediaPlugin_iid,
+ QLatin1String("/multimedia")))
+
+static const auto FFmpegBackend = QStringLiteral("ffmpeg");
+
+static QString defaultBackend(const QStringList &backends)
+{
+#ifdef QT_DEFAULT_MEDIA_BACKEND
+ auto backend = QString::fromUtf8(QT_DEFAULT_MEDIA_BACKEND);
+ if (backends.contains(backend))
+ return backend;
+#endif
+
+#if defined(Q_OS_DARWIN) || defined(Q_OS_LINUX) || defined(Q_OS_WINDOWS) || defined(Q_OS_ANDROID)
+ // Return ffmpeg backend by default.
+ // Platform backends for the OS list are optionally available but have limited support.
+ if (backends.contains(FFmpegBackend))
+ return FFmpegBackend;
+#else
+ // Return platform backend (non-ffmpeg) by default.
+ if (backends.size() > 1 && backends[0] == FFmpegBackend)
+ return backends[1];
+#endif
+
+ return backends[0];
+}
+
+struct InstanceHolder
+{
+ InstanceHolder()
+ {
+ if (!QCoreApplication::instance())
+ qCCritical(qLcMediaPlugin()) << "Qt Multimedia requires a QCoreApplication instance";
+
+ const QStringList backends = QPlatformMediaIntegration::availableBackends();
+ QString backend = QString::fromUtf8(qgetenv("QT_MEDIA_BACKEND"));
+ if (backend.isEmpty() && !backends.isEmpty())
+ backend = defaultBackend(backends);
+
+ qCDebug(qLcMediaPlugin) << "Loading media backend" << backend;
+ instance.reset(
+ qLoadPlugin<QPlatformMediaIntegration, QPlatformMediaPlugin>(loader(), backend));
+
+ if (!instance) {
+ // No backends found. Use fallback to support basic functionality
+ instance = std::make_unique<QFallbackIntegration>();
+ }
+ }
+
+ ~InstanceHolder()
+ {
+ instance.reset();
+ qCDebug(qLcMediaPlugin) << "Released media backend";
+ }
+
+ std::unique_ptr<QPlatformMediaIntegration> instance;
+};
+
+Q_APPLICATION_STATIC(InstanceHolder, s_instanceHolder);
+
+} // namespace
+
+QT_BEGIN_NAMESPACE
+
+QPlatformMediaIntegration *QPlatformMediaIntegration::instance()
+{
+ return s_instanceHolder->instance.get();
+}
+
+QList<QCameraDevice> QPlatformMediaIntegration::videoInputs()
+{
+ auto devices = videoDevices();
+ return devices ? devices->videoDevices() : QList<QCameraDevice>{};
+}
+
+QMaybe<std::unique_ptr<QPlatformAudioResampler>>
+QPlatformMediaIntegration::createAudioResampler(const QAudioFormat &, const QAudioFormat &)
+{
+ return notAvailable;
+}
+
+QMaybe<QPlatformAudioInput *> QPlatformMediaIntegration::createAudioInput(QAudioInput *q)
+{
+ return new QPlatformAudioInput(q);
+}
+
+QMaybe<QPlatformAudioOutput *> QPlatformMediaIntegration::createAudioOutput(QAudioOutput *q)
+{
+ return new QPlatformAudioOutput(q);
+}
+
+QList<QCapturableWindow> QPlatformMediaIntegration::capturableWindowsList()
+{
+ const auto capturableWindows = this->capturableWindows();
+ return capturableWindows ? capturableWindows->windows() : QList<QCapturableWindow>{};
+}
+
+bool QPlatformMediaIntegration::isCapturableWindowValid(const QCapturableWindowPrivate &window)
+{
+ const auto capturableWindows = this->capturableWindows();
+ return capturableWindows && capturableWindows->isWindowValid(window);
+}
+
+const QPlatformMediaFormatInfo *QPlatformMediaIntegration::formatInfo()
+{
+ std::call_once(m_formatInfoOnceFlg, [this]() {
+ m_formatInfo.reset(createFormatInfo());
+ Q_ASSERT(m_formatInfo);
+ });
+ return m_formatInfo.get();
+}
+
+QPlatformMediaFormatInfo *QPlatformMediaIntegration::createFormatInfo()
+{
+ return new QPlatformMediaFormatInfo;
+}
+
+std::unique_ptr<QPlatformMediaDevices> QPlatformMediaIntegration::createMediaDevices()
+{
+ return QPlatformMediaDevices::create();
+}
+
+// clang-format off
+QPlatformVideoDevices *QPlatformMediaIntegration::videoDevices()
+{
+ std::call_once(m_videoDevicesOnceFlag,
+ [this]() {
+ m_videoDevices.reset(createVideoDevices());
+ });
+ return m_videoDevices.get();
+}
+
+QPlatformCapturableWindows *QPlatformMediaIntegration::capturableWindows()
+{
+ std::call_once(m_capturableWindowsOnceFlag,
+ [this]() {
+ m_capturableWindows.reset(createCapturableWindows());
+ });
+ return m_capturableWindows.get();
+}
+
+QPlatformMediaDevices *QPlatformMediaIntegration::mediaDevices()
+{
+ std::call_once(m_mediaDevicesOnceFlag, [this] {
+ m_mediaDevices = createMediaDevices();
+ });
+ return m_mediaDevices.get();
+}
+
+// clang-format on
+
+QStringList QPlatformMediaIntegration::availableBackends()
+{
+ QStringList list;
+
+ if (QFactoryLoader *fl = loader()) {
+ const auto keyMap = fl->keyMap();
+ for (auto it = keyMap.constBegin(); it != keyMap.constEnd(); ++it)
+ if (!list.contains(it.value()))
+ list << it.value();
+ }
+
+ qCDebug(qLcMediaPlugin) << "Available backends" << list;
+ return list;
+}
+
+QLatin1String QPlatformMediaIntegration::name()
+{
+ return m_backendName;
+}
+
+QVideoFrame QPlatformMediaIntegration::convertVideoFrame(QVideoFrame &,
+ const QVideoFrameFormat &)
+{
+ return {};
+}
+
+QPlatformMediaIntegration::QPlatformMediaIntegration(QLatin1String name) : m_backendName(name) { }
+
+QPlatformMediaIntegration::~QPlatformMediaIntegration() = default;
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformmediaintegration_p.cpp"
diff --git a/src/multimedia/platform/qplatformmediaintegration_p.h b/src/multimedia/platform/qplatformmediaintegration_p.h
new file mode 100644
index 000000000..d03d0c794
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediaintegration_p.h
@@ -0,0 +1,139 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QPLATFORMMEDIAINTEGRATION_H
+#define QPLATFORMMEDIAINTEGRATION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <private/qmultimediautils_p.h>
+#include <qcapturablewindow.h>
+#include <qmediarecorder.h>
+#include <qstring.h>
+
+#include <memory>
+#include <mutex>
+
+QT_BEGIN_NAMESPACE
+
+class QMediaPlayer;
+class QAudioDecoder;
+class QCamera;
+class QScreenCapture;
+class QWindowCapture;
+class QMediaRecorder;
+class QImageCapture;
+class QMediaDevices;
+class QPlatformMediaDevices;
+class QPlatformMediaCaptureSession;
+class QPlatformMediaPlayer;
+class QPlatformAudioDecoder;
+class QPlatformAudioResampler;
+class QPlatformCamera;
+class QPlatformSurfaceCapture;
+class QPlatformMediaRecorder;
+class QPlatformImageCapture;
+class QPlatformMediaFormatInfo;
+class QObject;
+class QPlatformVideoSink;
+class QVideoSink;
+class QAudioInput;
+class QAudioOutput;
+class QPlatformAudioInput;
+class QPlatformAudioOutput;
+class QPlatformVideoDevices;
+class QCapturableWindow;
+class QPlatformCapturableWindows;
+class QVideoFrame;
+
+class Q_MULTIMEDIA_EXPORT QAbstractPlatformSpecificInterface
+{
+public:
+ virtual ~QAbstractPlatformSpecificInterface() = default;
+};
+
+class Q_MULTIMEDIA_EXPORT QPlatformMediaIntegration : public QObject
+{
+ Q_OBJECT
+ inline static const QString notAvailable = QStringLiteral("Not available");
+public:
+ static QPlatformMediaIntegration *instance();
+
+ explicit QPlatformMediaIntegration(QLatin1String);
+ virtual ~QPlatformMediaIntegration();
+ const QPlatformMediaFormatInfo *formatInfo();
+
+ virtual QList<QCameraDevice> videoInputs();
+ virtual QMaybe<QPlatformCamera *> createCamera(QCamera *) { return notAvailable; }
+ virtual QPlatformSurfaceCapture *createScreenCapture(QScreenCapture *) { return nullptr; }
+ virtual QPlatformSurfaceCapture *createWindowCapture(QWindowCapture *) { return nullptr; }
+
+ virtual QMaybe<QPlatformAudioDecoder *> createAudioDecoder(QAudioDecoder *) { return notAvailable; }
+ virtual QMaybe<std::unique_ptr<QPlatformAudioResampler>>
+ createAudioResampler(const QAudioFormat & /*inputFormat*/,
+ const QAudioFormat & /*outputFormat*/);
+ virtual QMaybe<QPlatformMediaCaptureSession *> createCaptureSession() { return notAvailable; }
+ virtual QMaybe<QPlatformMediaPlayer *> createPlayer(QMediaPlayer *) { return notAvailable; }
+ virtual QMaybe<QPlatformMediaRecorder *> createRecorder(QMediaRecorder *) { return notAvailable; }
+ virtual QMaybe<QPlatformImageCapture *> createImageCapture(QImageCapture *) { return notAvailable; }
+
+ virtual QMaybe<QPlatformAudioInput *> createAudioInput(QAudioInput *);
+ virtual QMaybe<QPlatformAudioOutput *> createAudioOutput(QAudioOutput *);
+
+ virtual QMaybe<QPlatformVideoSink *> createVideoSink(QVideoSink *) { return notAvailable; }
+
+ QList<QCapturableWindow> capturableWindowsList();
+ bool isCapturableWindowValid(const QCapturableWindowPrivate &);
+
+ QPlatformVideoDevices *videoDevices();
+
+ QPlatformCapturableWindows *capturableWindows();
+
+ QPlatformMediaDevices *mediaDevices();
+
+ static QStringList availableBackends();
+ QLatin1String name(); // for unit tests
+
+ // Convert a QVideoFrame to the destination format
+ virtual QVideoFrame convertVideoFrame(QVideoFrame &, const QVideoFrameFormat &);
+
+ virtual QAbstractPlatformSpecificInterface *platformSpecificInterface() { return nullptr; }
+
+protected:
+ virtual QPlatformMediaFormatInfo *createFormatInfo();
+
+ virtual QPlatformVideoDevices *createVideoDevices() { return nullptr; }
+
+ virtual QPlatformCapturableWindows *createCapturableWindows() { return nullptr; }
+
+ virtual std::unique_ptr<QPlatformMediaDevices> createMediaDevices();
+
+private:
+ std::unique_ptr<QPlatformVideoDevices> m_videoDevices;
+ std::once_flag m_videoDevicesOnceFlag;
+
+ std::unique_ptr<QPlatformCapturableWindows> m_capturableWindows;
+ std::once_flag m_capturableWindowsOnceFlag;
+
+ mutable std::unique_ptr<QPlatformMediaFormatInfo> m_formatInfo;
+ mutable std::once_flag m_formatInfoOnceFlg;
+
+ std::unique_ptr<QPlatformMediaDevices> m_mediaDevices;
+ std::once_flag m_mediaDevicesOnceFlag;
+
+ const QLatin1String m_backendName;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QPLATFORMMEDIAINTERFACE_H
diff --git a/src/multimedia/platform/qplatformmediaplayer.cpp b/src/multimedia/platform/qplatformmediaplayer.cpp
new file mode 100644
index 000000000..00840f074
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediaplayer.cpp
@@ -0,0 +1,40 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformmediaplayer_p.h"
+#include <private/qmediaplayer_p.h>
+#include "qmediaplayer.h"
+#include "qplatformmediadevices_p.h"
+#include "qplatformmediaintegration_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QPlatformMediaPlayer::QPlatformMediaPlayer(QMediaPlayer *parent) : player(parent)
+{
+ QPlatformMediaIntegration::instance()->mediaDevices()->prepareAudio();
+}
+
+QPlatformMediaPlayer::~QPlatformMediaPlayer() = default;
+
+void QPlatformMediaPlayer::stateChanged(QMediaPlayer::PlaybackState newState)
+{
+ if (newState == m_state)
+ return;
+ m_state = newState;
+ player->d_func()->setState(newState);
+}
+
+void QPlatformMediaPlayer::mediaStatusChanged(QMediaPlayer::MediaStatus status)
+{
+ if (m_status == status)
+ return;
+ m_status = status;
+ player->d_func()->setStatus(status);
+}
+
+void QPlatformMediaPlayer::error(int error, const QString &errorString)
+{
+ player->d_func()->setError(QMediaPlayer::Error(error), errorString);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/platform/qplatformmediaplayer_p.h b/src/multimedia/platform/qplatformmediaplayer_p.h
new file mode 100644
index 000000000..3b839fdd5
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediaplayer_p.h
@@ -0,0 +1,170 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QMEDIAPLAYERCONTROL_H
+#define QMEDIAPLAYERCONTROL_H
+
+#include <QtMultimedia/qmediaplayer.h>
+#include <QtMultimedia/qmediatimerange.h>
+#include <QtMultimedia/qaudiodevice.h>
+#include <QtMultimedia/qmediametadata.h>
+
+#include <QtCore/qpair.h>
+#include <QtCore/private/qglobal_p.h>
+#include <QtCore/qobject.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMediaStreamsControl;
+class QPlatformAudioOutput;
+
+class Q_MULTIMEDIA_EXPORT QPlatformMediaPlayer
+{
+public:
+ virtual ~QPlatformMediaPlayer();
+ virtual QMediaPlayer::PlaybackState state() const { return m_state; }
+ virtual QMediaPlayer::MediaStatus mediaStatus() const { return m_status; };
+
+ virtual qint64 duration() const = 0;
+
+ virtual qint64 position() const { return m_position; }
+ virtual void setPosition(qint64 position) = 0;
+
+ virtual float bufferProgress() const = 0;
+
+ virtual bool isAudioAvailable() const { return m_audioAvailable; }
+ virtual bool isVideoAvailable() const { return m_videoAvailable; }
+
+ virtual bool isSeekable() const { return m_seekable; }
+
+ virtual QMediaTimeRange availablePlaybackRanges() const = 0;
+
+ virtual qreal playbackRate() const = 0;
+ virtual void setPlaybackRate(qreal rate) = 0;
+
+ virtual QUrl media() const = 0;
+ virtual const QIODevice *mediaStream() const = 0;
+ virtual void setMedia(const QUrl &media, QIODevice *stream) = 0;
+
+ virtual void play() = 0;
+ virtual void pause() = 0;
+ virtual void stop() = 0;
+
+ virtual bool streamPlaybackSupported() const { return false; }
+
+ virtual void setAudioOutput(QPlatformAudioOutput *) {}
+
+ virtual void setAudioBufferOutput(QAudioBufferOutput *) { }
+
+ virtual QMediaMetaData metaData() const { return {}; }
+
+ virtual void setVideoSink(QVideoSink * /*sink*/) = 0;
+
+ // media streams
+ enum TrackType { VideoStream, AudioStream, SubtitleStream, NTrackTypes };
+
+ virtual int trackCount(TrackType) { return 0; };
+ virtual QMediaMetaData trackMetaData(TrackType /*type*/, int /*streamNumber*/) { return QMediaMetaData(); }
+ virtual int activeTrack(TrackType) { return -1; }
+ virtual void setActiveTrack(TrackType, int /*streamNumber*/) {}
+
+ void durationChanged(std::chrono::milliseconds ms) { durationChanged(ms.count()); }
+ void durationChanged(qint64 duration) { emit player->durationChanged(duration); }
+ void positionChanged(std::chrono::milliseconds ms) { positionChanged(ms.count()); }
+ void positionChanged(qint64 position) {
+ if (m_position == position)
+ return;
+ m_position = position;
+ emit player->positionChanged(position);
+ }
+ void audioAvailableChanged(bool audioAvailable) {
+ if (m_audioAvailable == audioAvailable)
+ return;
+ m_audioAvailable = audioAvailable;
+ emit player->hasAudioChanged(audioAvailable);
+ }
+ void videoAvailableChanged(bool videoAvailable) {
+ if (m_videoAvailable == videoAvailable)
+ return;
+ m_videoAvailable = videoAvailable;
+ emit player->hasVideoChanged(videoAvailable);
+ }
+ void seekableChanged(bool seekable) {
+ if (m_seekable == seekable)
+ return;
+ m_seekable = seekable;
+ emit player->seekableChanged(seekable);
+ }
+ void playbackRateChanged(qreal rate) { emit player->playbackRateChanged(rate); }
+ void bufferProgressChanged(float progress) { emit player->bufferProgressChanged(progress); }
+ void metaDataChanged() { emit player->metaDataChanged(); }
+ void tracksChanged() { emit player->tracksChanged(); }
+ void activeTracksChanged() { emit player->activeTracksChanged(); }
+
+ void stateChanged(QMediaPlayer::PlaybackState newState);
+ void mediaStatusChanged(QMediaPlayer::MediaStatus status);
+ void error(int error, const QString &errorString);
+
+ void resetCurrentLoop() { m_currentLoop = 0; }
+ bool doLoop() {
+ return isSeekable() && (m_loops < 0 || ++m_currentLoop < m_loops);
+ }
+ int loops() { return m_loops; }
+ virtual void setLoops(int loops)
+ {
+ if (m_loops == loops)
+ return;
+ m_loops = loops;
+ Q_EMIT player->loopsChanged();
+ }
+
+protected:
+ explicit QPlatformMediaPlayer(QMediaPlayer *parent = nullptr);
+
+private:
+ QMediaPlayer *player = nullptr;
+ QMediaPlayer::MediaStatus m_status = QMediaPlayer::NoMedia;
+ QMediaPlayer::PlaybackState m_state = QMediaPlayer::StoppedState;
+ bool m_seekable = false;
+ bool m_videoAvailable = false;
+ bool m_audioAvailable = false;
+ int m_loops = 1;
+ int m_currentLoop = 0;
+ qint64 m_position = 0;
+};
+
+#ifndef QT_NO_DEBUG_STREAM
+inline QDebug operator<<(QDebug dbg, QPlatformMediaPlayer::TrackType type)
+{
+ QDebugStateSaver save(dbg);
+ dbg.nospace();
+
+ switch (type) {
+ case QPlatformMediaPlayer::TrackType::AudioStream:
+ return dbg << "AudioStream";
+ case QPlatformMediaPlayer::TrackType::VideoStream:
+ return dbg << "VideoStream";
+ case QPlatformMediaPlayer::TrackType::SubtitleStream:
+ return dbg << "SubtitleStream";
+ default:
+ Q_UNREACHABLE_RETURN(dbg);
+ }
+}
+#endif
+
+QT_END_NAMESPACE
+
+
+#endif // QMEDIAPLAYERCONTROL_H
+
diff --git a/src/multimedia/platform/qplatformmediaplugin.cpp b/src/multimedia/platform/qplatformmediaplugin.cpp
new file mode 100644
index 000000000..7828fa08e
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediaplugin.cpp
@@ -0,0 +1,14 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformmediaplugin_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QPlatformMediaPlugin::QPlatformMediaPlugin(QObject *parent) : QObject(parent) { }
+
+QPlatformMediaPlugin::~QPlatformMediaPlugin() = default;
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformmediaplugin_p.cpp"
diff --git a/src/multimedia/platform/qplatformmediaplugin_p.h b/src/multimedia/platform/qplatformmediaplugin_p.h
new file mode 100644
index 000000000..4c8b9e458
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediaplugin_p.h
@@ -0,0 +1,42 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QPLATFORMMEDIAPLUGIN_P_H
+#define QPLATFORMMEDIAPLUGIN_P_H
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtCore/qplugin.h>
+#include <QtCore/qfactoryinterface.h>
+#include <QtCore/private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPlatformMediaIntegration;
+
+#define QPlatformMediaPlugin_iid "org.qt-project.Qt.QPlatformMediaPlugin"
+
+class Q_MULTIMEDIA_EXPORT QPlatformMediaPlugin : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QPlatformMediaPlugin(QObject *parent = nullptr);
+ ~QPlatformMediaPlugin() override;
+
+ virtual QPlatformMediaIntegration *create(const QString &key) = 0;
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QPLATFORMMEDIAPLUGIN_P_H
diff --git a/src/multimedia/platform/qplatformmediarecorder.cpp b/src/multimedia/platform/qplatformmediarecorder.cpp
new file mode 100644
index 000000000..30dba0a45
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediarecorder.cpp
@@ -0,0 +1,75 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformmediarecorder_p.h"
+#include "qstandardpaths.h"
+#include "qmediastoragelocation_p.h"
+#include <QObject>
+
+QT_BEGIN_NAMESPACE
+
+QPlatformMediaRecorder::QPlatformMediaRecorder(QMediaRecorder *parent)
+ : q(parent)
+{
+}
+
+void QPlatformMediaRecorder::pause()
+{
+ updateError(QMediaRecorder::FormatError, QMediaRecorder::tr("Pause not supported"));
+}
+
+void QPlatformMediaRecorder::resume()
+{
+ updateError(QMediaRecorder::FormatError, QMediaRecorder::tr("Resume not supported"));
+}
+
+void QPlatformMediaRecorder::stateChanged(QMediaRecorder::RecorderState state)
+{
+ if (m_state == state)
+ return;
+ m_state = state;
+ emit q->recorderStateChanged(state);
+}
+
+void QPlatformMediaRecorder::durationChanged(qint64 duration)
+{
+ if (m_duration == duration)
+ return;
+ m_duration = duration;
+ emit q->durationChanged(duration);
+}
+
+void QPlatformMediaRecorder::actualLocationChanged(const QUrl &location)
+{
+ if (m_actualLocation == location)
+ return;
+ m_actualLocation = location;
+ emit q->actualLocationChanged(location);
+}
+
+void QPlatformMediaRecorder::updateError(QMediaRecorder::Error error, const QString &errorString)
+{
+ m_error.setAndNotify(error, errorString, *q);
+}
+
+void QPlatformMediaRecorder::metaDataChanged()
+{
+ emit q->metaDataChanged();
+}
+
+QString QPlatformMediaRecorder::findActualLocation(const QMediaEncoderSettings &settings) const
+{
+ const auto audioOnly = settings.videoCodec() == QMediaFormat::VideoCodec::Unspecified;
+
+ const auto primaryLocation =
+ audioOnly ? QStandardPaths::MusicLocation : QStandardPaths::MoviesLocation;
+ const QString suffix = settings.mimeType().preferredSuffix();
+ const QString location = QMediaStorageLocation::generateFileName(
+ outputLocation().toString(QUrl::PreferLocalFile), primaryLocation, suffix);
+
+ Q_ASSERT(!location.isEmpty());
+
+ return location;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/platform/qplatformmediarecorder_p.h b/src/multimedia/platform/qplatformmediarecorder_p.h
new file mode 100644
index 000000000..dea45ac70
--- /dev/null
+++ b/src/multimedia/platform/qplatformmediarecorder_p.h
@@ -0,0 +1,159 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QPLATFORMMEDIARECORDER_H
+#define QPLATFORMMEDIARECORDER_H
+
+#include <QtCore/qurl.h>
+#include <QtCore/qsize.h>
+#include <QtCore/qmimetype.h>
+#include <QtCore/qpointer.h>
+#include <QtCore/qiodevice.h>
+
+#include <QtMultimedia/qmediarecorder.h>
+#include <QtMultimedia/qmediametadata.h>
+#include <QtMultimedia/qmediaformat.h>
+#include <QtMultimedia/private/qerrorinfo_p.h>
+#include <QtCore/private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QUrl;
+QT_END_NAMESPACE
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIA_EXPORT QMediaEncoderSettings
+{
+ QMediaRecorder::EncodingMode m_encodingMode = QMediaRecorder::ConstantQualityEncoding;
+ QMediaRecorder::Quality m_quality = QMediaRecorder::NormalQuality;
+
+ QMediaFormat m_format;
+ int m_audioBitrate = -1;
+ int m_audioSampleRate = -1;
+ int m_audioChannels = -1;
+
+ QSize m_videoResolution = QSize(-1, -1);
+ int m_videoFrameRate = -1;
+ int m_videoBitRate = -1;
+public:
+
+ QMediaFormat mediaFormat() const { return m_format; }
+ void setMediaFormat(const QMediaFormat &format) { m_format = format; }
+ void resolveFormat(QMediaFormat::ResolveFlags flags = QMediaFormat::NoFlags)
+ { m_format.resolveForEncoding(flags); }
+
+ QMediaFormat::FileFormat fileFormat() const { return mediaFormat().fileFormat(); }
+ QMediaFormat::VideoCodec videoCodec() const { return mediaFormat().videoCodec(); }
+ QMediaFormat::AudioCodec audioCodec() const { return mediaFormat().audioCodec(); }
+ QMimeType mimeType() const { return mediaFormat().mimeType(); }
+
+ QMediaRecorder::EncodingMode encodingMode() const { return m_encodingMode; }
+ void setEncodingMode(QMediaRecorder::EncodingMode mode) { m_encodingMode = mode; }
+
+ QMediaRecorder::Quality quality() const { return m_quality; }
+ void setQuality(QMediaRecorder::Quality quality) { m_quality = quality; }
+
+ QSize videoResolution() const { return m_videoResolution; }
+ void setVideoResolution(const QSize &size) { m_videoResolution = size; }
+
+ qreal videoFrameRate() const { return m_videoFrameRate; }
+ void setVideoFrameRate(qreal rate) { m_videoFrameRate = rate; }
+
+ int videoBitRate() const { return m_videoBitRate; }
+ void setVideoBitRate(int bitrate) { m_videoBitRate = bitrate; }
+
+ int audioBitRate() const { return m_audioBitrate; }
+ void setAudioBitRate(int bitrate) { m_audioBitrate = bitrate; }
+
+ int audioChannelCount() const { return m_audioChannels; }
+ void setAudioChannelCount(int channels) { m_audioChannels = channels; }
+
+ int audioSampleRate() const { return m_audioSampleRate; }
+ void setAudioSampleRate(int rate) { m_audioSampleRate = rate; }
+
+ bool operator==(const QMediaEncoderSettings &other) const
+ {
+ return m_format == other.m_format &&
+ m_encodingMode == other.m_encodingMode &&
+ m_quality == other.m_quality &&
+ m_audioBitrate == other.m_audioBitrate &&
+ m_audioSampleRate == other.m_audioSampleRate &&
+ m_audioChannels == other.m_audioChannels &&
+ m_videoResolution == other.m_videoResolution &&
+ m_videoFrameRate == other.m_videoFrameRate &&
+ m_videoBitRate == other.m_videoBitRate;
+ }
+
+ bool operator!=(const QMediaEncoderSettings &other) const
+ { return !operator==(other); }
+};
+
+class Q_MULTIMEDIA_EXPORT QPlatformMediaRecorder
+{
+public:
+ virtual ~QPlatformMediaRecorder() {}
+
+ virtual bool isLocationWritable(const QUrl &location) const = 0;
+
+ virtual QMediaRecorder::RecorderState state() const { return m_state; }
+ virtual void record(QMediaEncoderSettings &settings) = 0;
+ virtual void pause();
+ virtual void resume();
+ virtual void stop() = 0;
+
+ virtual qint64 duration() const { return m_duration; }
+
+ virtual void setMetaData(const QMediaMetaData &) {}
+ virtual QMediaMetaData metaData() const { return {}; }
+
+ QMediaRecorder::Error error() const { return m_error.code(); }
+ QString errorString() const { return m_error.description(); }
+
+ QUrl outputLocation() const { return m_outputLocation; }
+ virtual void setOutputLocation(const QUrl &location) { m_outputLocation = location; }
+ QUrl actualLocation() const { return m_actualLocation; }
+ void clearActualLocation() { m_actualLocation.clear(); }
+ void clearError() { updateError(QMediaRecorder::NoError, QString()); }
+
+ QIODevice *outputDevice() const { return m_outputDevice; }
+ void setOutputDevice(QIODevice *device) { m_outputDevice = device; }
+
+protected:
+ explicit QPlatformMediaRecorder(QMediaRecorder *parent);
+
+ void stateChanged(QMediaRecorder::RecorderState state);
+ void durationChanged(qint64 position);
+ void actualLocationChanged(const QUrl &location);
+ void updateError(QMediaRecorder::Error error, const QString &errorString);
+ void metaDataChanged();
+
+ QMediaRecorder *mediaRecorder() { return q; }
+
+ QString findActualLocation(const QMediaEncoderSettings &settings) const;
+
+private:
+ QMediaRecorder *q = nullptr;
+ QErrorInfo<QMediaRecorder::Error> m_error;
+ QUrl m_actualLocation;
+ QUrl m_outputLocation;
+ QPointer<QIODevice> m_outputDevice;
+ qint64 m_duration = 0;
+
+ QMediaRecorder::RecorderState m_state = QMediaRecorder::StoppedState;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/platform/qplatformsurfacecapture.cpp b/src/multimedia/platform/qplatformsurfacecapture.cpp
new file mode 100644
index 000000000..a56f48b62
--- /dev/null
+++ b/src/multimedia/platform/qplatformsurfacecapture.cpp
@@ -0,0 +1,83 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "platform/qplatformsurfacecapture_p.h"
+#include "qvideoframe.h"
+#include "qguiapplication.h"
+#include "qdebug.h"
+
+QT_BEGIN_NAMESPACE
+
+QPlatformSurfaceCapture::QPlatformSurfaceCapture(Source initialSource) : m_source(initialSource)
+{
+ Q_ASSERT(std::visit([](auto source) { return source == decltype(source){}; }, initialSource));
+ qRegisterMetaType<QVideoFrame>();
+}
+
+void QPlatformSurfaceCapture::setActive(bool active)
+{
+ if (m_active == active)
+ return;
+
+ if (!setActiveInternal(active))
+ return;
+
+ m_active = active;
+ emit activeChanged(active);
+}
+
+bool QPlatformSurfaceCapture::isActive() const
+{
+ return m_active;
+}
+
+void QPlatformSurfaceCapture::setSource(Source source)
+{
+ Q_ASSERT(source.index() == m_source.index());
+
+ if (m_source == source)
+ return;
+
+ if (m_active)
+ setActiveInternal(false);
+
+ m_source = source;
+
+ if (m_active && !setActiveInternal(true)) {
+ m_active = false;
+ emit activeChanged(false);
+ }
+
+ std::visit([this](auto source) { emit sourceChanged(source); }, m_source);
+}
+
+QPlatformSurfaceCapture::Error QPlatformSurfaceCapture::error() const
+{
+ return m_error.code();
+}
+
+QString QPlatformSurfaceCapture::errorString() const
+{
+ return m_error.description();
+}
+
+void QPlatformSurfaceCapture::updateError(Error error, const QString &errorString)
+{
+ m_error.setAndNotify(error, errorString, *this);
+}
+
+bool QPlatformSurfaceCapture::checkScreenWithError(ScreenSource &screen)
+{
+ if (!screen)
+ screen = QGuiApplication::primaryScreen();
+
+ if (screen)
+ return true;
+
+ updateError(NotFound, QLatin1String("No screens found"));
+ return false;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformsurfacecapture_p.cpp"
diff --git a/src/multimedia/platform/qplatformsurfacecapture_p.h b/src/multimedia/platform/qplatformsurfacecapture_p.h
new file mode 100644
index 000000000..e4c59c6f4
--- /dev/null
+++ b/src/multimedia/platform/qplatformsurfacecapture_p.h
@@ -0,0 +1,87 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMSURFACECAPTURE_H
+#define QPLATFORMSURFACECAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qplatformvideosource_p.h"
+#include "qscreen.h"
+#include "qcapturablewindow.h"
+#include "qpointer.h"
+#include "private/qerrorinfo_p.h"
+
+#include <optional>
+#include <variant>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoFrame;
+
+class Q_MULTIMEDIA_EXPORT QPlatformSurfaceCapture : public QPlatformVideoSource
+{
+ Q_OBJECT
+
+public:
+ enum Error {
+ NoError = 0,
+ InternalError = 1,
+ CapturingNotSupported = 2,
+ CaptureFailed = 4,
+ NotFound = 5,
+ };
+
+ using ScreenSource = QPointer<QScreen>;
+ using WindowSource = QCapturableWindow;
+
+ using Source = std::variant<ScreenSource, WindowSource>;
+
+ explicit QPlatformSurfaceCapture(Source initialSource);
+
+ void setActive(bool active) override;
+ bool isActive() const override;
+
+ void setSource(Source source);
+
+ template<typename Type>
+ Type source() const {
+ return *q_check_ptr(std::get_if<Type>(&m_source));
+ }
+
+ Source source() const { return m_source; }
+
+ Error error() const;
+ QString errorString() const final;
+
+protected:
+ virtual bool setActiveInternal(bool) = 0;
+
+ bool checkScreenWithError(ScreenSource &screen);
+
+public Q_SLOTS:
+ void updateError(Error error, const QString &errorString);
+
+Q_SIGNALS:
+ void sourceChanged(WindowSource);
+ void sourceChanged(ScreenSource);
+ void errorOccurred(Error error, QString errorString);
+
+private:
+ QErrorInfo<Error> m_error;
+ Source m_source;
+ bool m_active = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QPLATFORMSURFACECAPTURE_H
diff --git a/src/multimedia/platform/qplatformvideodevices.cpp b/src/multimedia/platform/qplatformvideodevices.cpp
new file mode 100644
index 000000000..bcf664cd2
--- /dev/null
+++ b/src/multimedia/platform/qplatformvideodevices.cpp
@@ -0,0 +1,12 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformvideodevices_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QPlatformVideoDevices::~QPlatformVideoDevices() = default;
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformvideodevices_p.cpp"
diff --git a/src/multimedia/platform/qplatformvideodevices_p.h b/src/multimedia/platform/qplatformvideodevices_p.h
new file mode 100644
index 000000000..008322be2
--- /dev/null
+++ b/src/multimedia/platform/qplatformvideodevices_p.h
@@ -0,0 +1,46 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QPLATFORMVIDEODEVICES_H
+#define QPLATFORMVIDEODEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <qmediarecorder.h>
+#include <qobject.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPlatformMediaIntegration;
+
+class Q_MULTIMEDIA_EXPORT QPlatformVideoDevices : public QObject
+{
+ Q_OBJECT
+public:
+ QPlatformVideoDevices(QPlatformMediaIntegration *integration)
+ : m_integration(integration)
+ {}
+
+ ~QPlatformVideoDevices() override;
+
+ virtual QList<QCameraDevice> videoDevices() const = 0;
+
+Q_SIGNALS:
+ void videoInputsChanged();
+
+protected:
+ QPlatformMediaIntegration *m_integration = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/platform/qplatformvideoframeinput.cpp b/src/multimedia/platform/qplatformvideoframeinput.cpp
new file mode 100644
index 000000000..d90306345
--- /dev/null
+++ b/src/multimedia/platform/qplatformvideoframeinput.cpp
@@ -0,0 +1,10 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformvideoframeinput_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformvideoframeinput_p.cpp"
diff --git a/src/multimedia/platform/qplatformvideoframeinput_p.h b/src/multimedia/platform/qplatformvideoframeinput_p.h
new file mode 100644
index 000000000..45714492c
--- /dev/null
+++ b/src/multimedia/platform/qplatformvideoframeinput_p.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMVIDEOFRAMEINPUT_P_H
+#define QPLATFORMVIDEOFRAMEINPUT_P_H
+
+#include "qplatformvideosource_p.h"
+#include "qmetaobject.h"
+#include "qpointer.h"
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QMediaInputEncoderInterface;
+
+class Q_MULTIMEDIA_EXPORT QPlatformVideoFrameInput : public QPlatformVideoSource
+{
+ Q_OBJECT
+public:
+ QPlatformVideoFrameInput(QVideoFrameFormat format = {}) : m_format(std::move(format)) { }
+
+ void setActive(bool) final { }
+ bool isActive() const final { return true; }
+
+ QVideoFrameFormat frameFormat() const final { return m_format; }
+
+ QString errorString() const final { return {}; }
+
+ QMediaInputEncoderInterface *encoderInterface() const { return m_encoderInterface; }
+ void setEncoderInterface(QMediaInputEncoderInterface *interface)
+ {
+ m_encoderInterface = interface;
+ }
+
+Q_SIGNALS:
+ void encoderUpdated();
+
+private:
+ QMediaInputEncoderInterface *m_encoderInterface = nullptr;
+ QVideoFrameFormat m_format;
+};
+
+QT_END_NAMESPACE
+
+#endif // QPLATFORMVIDEOFRAMEINPUT_P_H
diff --git a/src/multimedia/platform/qplatformvideosink.cpp b/src/multimedia/platform/qplatformvideosink.cpp
new file mode 100644
index 000000000..abf82af0f
--- /dev/null
+++ b/src/multimedia/platform/qplatformvideosink.cpp
@@ -0,0 +1,78 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformvideosink_p.h"
+#include "qmultimediautils_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QPlatformVideoSink::QPlatformVideoSink(QVideoSink *parent) : QObject(parent), m_sink(parent) { }
+
+QPlatformVideoSink::~QPlatformVideoSink() = default;
+
+QSize QPlatformVideoSink::nativeSize() const
+{
+ QMutexLocker locker(&m_mutex);
+ return m_nativeSize;
+}
+
+void QPlatformVideoSink::setNativeSize(QSize s)
+{
+ {
+ QMutexLocker locker(&m_mutex);
+ if (m_nativeSize == s)
+ return;
+ m_nativeSize = s;
+ }
+ emit m_sink->videoSizeChanged();
+}
+
+void QPlatformVideoSink::setVideoFrame(const QVideoFrame &frame)
+{
+ bool sizeChanged = false;
+
+ {
+ QMutexLocker locker(&m_mutex);
+ if (frame == m_currentVideoFrame)
+ return;
+ m_currentVideoFrame = frame;
+ m_currentVideoFrame.setSubtitleText(m_subtitleText);
+ const auto size = qRotatedFrameSize(frame);
+ if (size != m_nativeSize) {
+ m_nativeSize = size;
+ sizeChanged = true;
+ }
+ }
+
+ // emit signals outside the mutex to avoid deadlocks on the user side
+ if (sizeChanged)
+ emit m_sink->videoSizeChanged();
+ emit m_sink->videoFrameChanged(frame);
+}
+
+QVideoFrame QPlatformVideoSink::currentVideoFrame() const
+{
+ QMutexLocker locker(&m_mutex);
+ return m_currentVideoFrame;
+}
+
+void QPlatformVideoSink::setSubtitleText(const QString &subtitleText)
+{
+ {
+ QMutexLocker locker(&m_mutex);
+ if (m_subtitleText == subtitleText)
+ return;
+ m_subtitleText = subtitleText;
+ }
+ emit m_sink->subtitleTextChanged(subtitleText);
+}
+
+QString QPlatformVideoSink::subtitleText() const
+{
+ QMutexLocker locker(&m_mutex);
+ return m_subtitleText;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qplatformvideosink_p.cpp"
diff --git a/src/multimedia/platform/qplatformvideosink_p.h b/src/multimedia/platform/qplatformvideosink_p.h
new file mode 100644
index 000000000..53eca374f
--- /dev/null
+++ b/src/multimedia/platform/qplatformvideosink_p.h
@@ -0,0 +1,84 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMVIDEOSINK_H
+#define QPLATFORMVIDEOSINK_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtCore/qobject.h>
+#include <QtCore/qrect.h>
+#include <QtCore/qsize.h>
+#include <QtCore/qmutex.h>
+#include <QtGui/qwindowdefs.h>
+#include <qvideosink.h>
+#include <qvideoframe.h>
+#include <qdebug.h>
+#include <private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+// Required for QDoc workaround
+class QString;
+
+class Q_MULTIMEDIA_EXPORT QPlatformVideoSink : public QObject
+{
+ Q_OBJECT
+
+public:
+ ~QPlatformVideoSink() override;
+
+ virtual void setRhi(QRhi * /*rhi*/) {}
+
+ virtual void setWinId(WId) {}
+ virtual void setDisplayRect(const QRect &) {};
+ virtual void setFullScreen(bool) {}
+ virtual void setAspectRatioMode(Qt::AspectRatioMode) {}
+
+ QSize nativeSize() const;
+
+ virtual void setBrightness(float /*brightness*/) {}
+ virtual void setContrast(float /*contrast*/) {}
+ virtual void setHue(float /*hue*/) {}
+ virtual void setSaturation(float /*saturation*/) {}
+
+ QVideoSink *videoSink() { return m_sink; }
+
+ void setNativeSize(QSize s);
+
+ virtual void setVideoFrame(const QVideoFrame &frame);
+
+ QVideoFrame currentVideoFrame() const;
+
+ void setSubtitleText(const QString &subtitleText);
+
+ QString subtitleText() const;
+
+protected:
+ explicit QPlatformVideoSink(QVideoSink *parent);
+
+Q_SIGNALS:
+ void rhiChanged(QRhi *rhi);
+
+private:
+ QVideoSink *m_sink = nullptr;
+ mutable QMutex m_mutex;
+ QSize m_nativeSize;
+ QString m_subtitleText;
+ QVideoFrame m_currentVideoFrame;
+};
+
+QT_END_NAMESPACE
+
+
+#endif
diff --git a/src/multimedia/platform/qplatformvideosource.cpp b/src/multimedia/platform/qplatformvideosource.cpp
new file mode 100644
index 000000000..a23ed91ae
--- /dev/null
+++ b/src/multimedia/platform/qplatformvideosource.cpp
@@ -0,0 +1,15 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformvideosource_p.h"
+
+QT_BEGIN_NAMESPACE
+
+std::optional<int> QPlatformVideoSource::ffmpegHWPixelFormat() const
+{
+ return {};
+};
+
+QT_END_NAMESPACE
+
+//#include "moc_qplatformvideosource_p.cpp
diff --git a/src/multimedia/platform/qplatformvideosource_p.h b/src/multimedia/platform/qplatformvideosource_p.h
new file mode 100644
index 000000000..b11524226
--- /dev/null
+++ b/src/multimedia/platform/qplatformvideosource_p.h
@@ -0,0 +1,58 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMVIDEOSOURCE_P_H
+#define QPLATFORMVIDEOSOURCE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qvideoframeformat.h"
+
+#include <QtCore/qobject.h>
+#include <QtCore/qnativeinterface.h>
+#include <QtCore/private/qglobal_p.h>
+
+#include <optional>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoFrame;
+class QPlatformMediaCaptureSession;
+
+class Q_MULTIMEDIA_EXPORT QPlatformVideoSource : public QObject
+{
+ Q_OBJECT
+public:
+ using QObject::QObject;
+
+ virtual void setActive(bool active) = 0;
+ virtual bool isActive() const = 0;
+
+ virtual QVideoFrameFormat frameFormat() const = 0;
+
+ virtual std::optional<int> ffmpegHWPixelFormat() const;
+
+ virtual void setCaptureSession(QPlatformMediaCaptureSession *) { }
+
+ virtual QString errorString() const = 0;
+
+ bool hasError() const { return !errorString().isEmpty(); }
+
+Q_SIGNALS:
+ void newVideoFrame(const QVideoFrame &);
+ void activeChanged(bool);
+ void errorChanged();
+};
+
+QT_END_NAMESPACE
+
+#endif // QPLATFORMVIDEOSOURCE_P_H
diff --git a/src/multimedia/playback/playback.pri b/src/multimedia/playback/playback.pri
deleted file mode 100644
index 81a3b298f..000000000
--- a/src/multimedia/playback/playback.pri
+++ /dev/null
@@ -1,24 +0,0 @@
-INCLUDEPATH += playback
-
-PUBLIC_HEADERS += \
- playback/qmediacontent.h \
- playback/qmediaplayer.h \
- playback/qmediaplaylist.h
-
-PRIVATE_HEADERS += \
- playback/qmediaplaylist_p.h \
- playback/qmediaplaylistprovider_p.h \
- playback/qmediaplaylistioplugin_p.h \
- playback/qmediaplaylistnavigator_p.h \
- playback/qmedianetworkplaylistprovider_p.h \
- playback/qplaylistfileparser_p.h
-
-SOURCES += \
- playback/qmedianetworkplaylistprovider.cpp \
- playback/qmediacontent.cpp \
- playback/qmediaplayer.cpp \
- playback/qmediaplaylist.cpp \
- playback/qmediaplaylistioplugin.cpp \
- playback/qmediaplaylistnavigator.cpp \
- playback/qmediaplaylistprovider.cpp \
- playback/qplaylistfileparser.cpp
diff --git a/src/multimedia/playback/qmediacontent.cpp b/src/multimedia/playback/qmediacontent.cpp
deleted file mode 100644
index 08ce49587..000000000
--- a/src/multimedia/playback/qmediacontent.cpp
+++ /dev/null
@@ -1,249 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qurl.h>
-#include <QtCore/qvariant.h>
-#include <QtCore/QPointer>
-
-#include <qmediaplaylist.h>
-#include "qmediacontent.h"
-
-QT_BEGIN_NAMESPACE
-
-static void qRegisterMediaContentMetaTypes()
-{
- qRegisterMetaType<QMediaContent>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterMediaContentMetaTypes)
-
-
-class QMediaContentPrivate : public QSharedData
-{
-public:
- QMediaContentPrivate():
- isPlaylistOwned(false)
- {}
-
- QMediaContentPrivate(const QNetworkRequest &r):
- isPlaylistOwned(false)
- {
- requests << r;
- }
-
- QMediaContentPrivate(const QMediaContentPrivate &other):
- QSharedData(other),
- requests(other.requests),
- playlist(other.playlist),
- isPlaylistOwned(false)
- {}
-
- QMediaContentPrivate(QMediaPlaylist *pls, const QUrl &url, bool isOwn):
- playlist(pls),
- isPlaylistOwned(isOwn)
- {
- requests << QNetworkRequest(url);
- }
-
- ~QMediaContentPrivate()
- {
- if (isPlaylistOwned && !playlist.isNull())
- playlist.data()->deleteLater();
- }
-
- bool operator ==(const QMediaContentPrivate &other) const
- {
- return requests == other.requests && playlist == other.playlist;
- }
-
- QList<QNetworkRequest> requests;
- QPointer<QMediaPlaylist> playlist;
- bool isPlaylistOwned;
-private:
- QMediaContentPrivate& operator=(const QMediaContentPrivate &other);
-};
-
-
-/*!
- \class QMediaContent
-
- \brief The QMediaContent class provides access to the resource relating to a media content.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_playback
-
- QMediaContent is used within the multimedia framework as the logical handle
- to media content. A QMediaContent object contains a \l {QNetworkRequest}
- which provides the URL of the content.
-
- A non-null QMediaContent will always have a reference to
- the content available through the request() method.
-
- Alternatively QMediaContent can represent a playlist and contain a pointer to a
- valid QMediaPlaylist object. In this case URL is optional and can either be empty
- or point to the playlist URL.
-*/
-
-
-/*!
- Constructs a null QMediaContent.
-*/
-
-QMediaContent::QMediaContent()
-{
-}
-
-/*!
- Constructs a media content with \a url providing a reference to the content.
-*/
-
-QMediaContent::QMediaContent(const QUrl &url):
- d(new QMediaContentPrivate)
-{
- d->requests << QNetworkRequest(url);
-}
-
-/*!
- Constructs a media content with \a request providing a reference to the content.
-
- This constructor can be used to reference media content via network protocols such as HTTP.
- This may include additional information required to obtain the resource, such as Cookies or HTTP headers.
-*/
-
-QMediaContent::QMediaContent(const QNetworkRequest &request):
- d(new QMediaContentPrivate)
-{
- d->requests << request;
-}
-
-/*!
- Constructs a copy of the media content \a other.
-*/
-
-QMediaContent::QMediaContent(const QMediaContent &other):
- d(other.d)
-{
-}
-
-/*!
- Constructs a media content with \a playlist.
-
- \a contentUrl of a playlist is an optional parameter and can be empty.
-
- Set \a takeOwnership to true if you want QMediaContent to take ownership of the playlist.
- \a takeOwnership is set to false by default.
-*/
-
-QMediaContent::QMediaContent(QMediaPlaylist *playlist, const QUrl &contentUrl, bool takeOwnership):
- d(new QMediaContentPrivate(playlist, contentUrl, takeOwnership))
-{
-}
-
-/*!
- Destroys the media content object.
-*/
-
-QMediaContent::~QMediaContent()
-{
-}
-
-/*!
- Assigns the value of \a other to this media content.
-*/
-
-QMediaContent& QMediaContent::operator=(const QMediaContent &other)
-{
- d = other.d;
- return *this;
-}
-
-/*!
- Returns true if \a other is equivalent to this media content; false otherwise.
-*/
-
-bool QMediaContent::operator==(const QMediaContent &other) const
-{
- return (d.constData() == 0 && other.d.constData() == nullptr) ||
- (d.constData() != 0 && other.d.constData() != nullptr &&
- *d.constData() == *other.d.constData());
-}
-
-/*!
- Returns true if \a other is not equivalent to this media content; false otherwise.
-*/
-
-bool QMediaContent::operator!=(const QMediaContent &other) const
-{
- return !(*this == other);
-}
-
-/*!
- Returns true if this media content is null (uninitialized); false otherwise.
-*/
-
-bool QMediaContent::isNull() const
-{
- return d.constData() == nullptr;
-}
-
-/*!
- \since 5.14
-
- Returns a QNetworkRequest that represents the resource for this media content.
-*/
-
-QNetworkRequest QMediaContent::request() const
-{
- return (d && !d->requests.isEmpty()) ? d->requests.first() : QNetworkRequest();
-}
-
-/*!
- Returns a playlist for this media content or 0 if this QMediaContent is not a playlist.
-*/
-
-QMediaPlaylist *QMediaContent::playlist() const
-{
- return d.constData() != nullptr
- ? d->playlist.data()
- : nullptr;
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/multimedia/playback/qmediacontent.h b/src/multimedia/playback/qmediacontent.h
deleted file mode 100644
index 983df47ef..000000000
--- a/src/multimedia/playback/qmediacontent.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIACONTENT_H
-#define QMEDIACONTENT_H
-
-#include <QtCore/qmetatype.h>
-#include <QtCore/qshareddata.h>
-
-#include <QNetworkRequest>
-#include <QtMultimedia/qtmultimediaglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-class QMediaPlaylist;
-
-class QMediaContentPrivate;
-class Q_MULTIMEDIA_EXPORT QMediaContent
-{
-public:
- QMediaContent();
- QMediaContent(const QUrl &contentUrl);
- QMediaContent(const QNetworkRequest &contentRequest);
- QMediaContent(const QMediaContent &other);
- QMediaContent(QMediaPlaylist *playlist, const QUrl &contentUrl = QUrl(), bool takeOwnership = false);
- ~QMediaContent();
-
- QMediaContent& operator=(const QMediaContent &other);
-
- bool operator==(const QMediaContent &other) const;
- bool operator!=(const QMediaContent &other) const;
-
- bool isNull() const;
- QNetworkRequest request() const;
-
- QMediaPlaylist *playlist() const;
-private:
- QSharedDataPointer<QMediaContentPrivate> d;
-};
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QMediaContent)
-
-#endif // QMEDIACONTENT_H
diff --git a/src/multimedia/playback/qmedianetworkplaylistprovider.cpp b/src/multimedia/playback/qmedianetworkplaylistprovider.cpp
deleted file mode 100644
index 8282d636a..000000000
--- a/src/multimedia/playback/qmedianetworkplaylistprovider.cpp
+++ /dev/null
@@ -1,281 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmedianetworkplaylistprovider_p.h"
-#include "qmediaplaylistprovider_p.h"
-#include "qmediacontent.h"
-#include "qmediaobject_p.h"
-#include "qplaylistfileparser_p.h"
-#include "qrandom.h"
-
-QT_BEGIN_NAMESPACE
-
-class QMediaNetworkPlaylistProviderPrivate: public QMediaPlaylistProviderPrivate
-{
- Q_DECLARE_NON_CONST_PUBLIC(QMediaNetworkPlaylistProvider)
-public:
- bool load(const QNetworkRequest &request);
-
- QPlaylistFileParser parser;
- QList<QMediaContent> resources;
-
- void _q_handleParserError(QPlaylistFileParser::ParserError err, const QString &);
- void _q_handleNewItem(const QVariant& content);
-
- QMediaNetworkPlaylistProvider *q_ptr;
-};
-
-bool QMediaNetworkPlaylistProviderPrivate::load(const QNetworkRequest &request)
-{
- parser.abort();
- parser.start(request);
-
- return true;
-}
-
-void QMediaNetworkPlaylistProviderPrivate::_q_handleParserError(QPlaylistFileParser::ParserError err, const QString &errorMessage)
-{
- Q_Q(QMediaNetworkPlaylistProvider);
-
- QMediaPlaylist::Error playlistError = QMediaPlaylist::NoError;
-
- switch (err) {
- case QPlaylistFileParser::NoError:
- return;
- case QPlaylistFileParser::FormatError:
- playlistError = QMediaPlaylist::FormatError;
- break;
- case QPlaylistFileParser::FormatNotSupportedError:
- playlistError = QMediaPlaylist::FormatNotSupportedError;
- break;
- case QPlaylistFileParser::ResourceError:
- // fall through
- case QPlaylistFileParser::NetworkError:
- playlistError = QMediaPlaylist::NetworkError;
- break;
- }
-
- parser.abort();
-
- emit q->loadFailed(playlistError, errorMessage);
-}
-
-void QMediaNetworkPlaylistProviderPrivate::_q_handleNewItem(const QVariant& content)
-{
- Q_Q(QMediaNetworkPlaylistProvider);
-
- QUrl url;
- if (content.type() == QVariant::Url) {
- url = content.toUrl();
- } else if (content.type() == QVariant::Map) {
- url = content.toMap()[QLatin1String("url")].toUrl();
- } else {
- return;
- }
-
- q->addMedia(QMediaContent(url));
-}
-
-QMediaNetworkPlaylistProvider::QMediaNetworkPlaylistProvider(QObject *parent)
- :QMediaPlaylistProvider(*new QMediaNetworkPlaylistProviderPrivate, parent)
-{
- d_func()->q_ptr = this;
- connect(&d_func()->parser, SIGNAL(newItem(QVariant)),
- this, SLOT(_q_handleNewItem(QVariant)));
- connect(&d_func()->parser, SIGNAL(finished()), this, SIGNAL(loaded()));
- connect(&d_func()->parser, SIGNAL(error(QPlaylistFileParser::ParserError,QString)),
- this, SLOT(_q_handleParserError(QPlaylistFileParser::ParserError,QString)));
-}
-
-QMediaNetworkPlaylistProvider::~QMediaNetworkPlaylistProvider()
-{
-}
-
-bool QMediaNetworkPlaylistProvider::isReadOnly() const
-{
- return false;
-}
-
-bool QMediaNetworkPlaylistProvider::load(const QNetworkRequest &request, const char *format)
-{
- Q_UNUSED(format);
- return d_func()->load(request);
-}
-
-int QMediaNetworkPlaylistProvider::mediaCount() const
-{
- return d_func()->resources.size();
-}
-
-QMediaContent QMediaNetworkPlaylistProvider::media(int pos) const
-{
- return d_func()->resources.value(pos);
-}
-
-bool QMediaNetworkPlaylistProvider::addMedia(const QMediaContent &content)
-{
- Q_D(QMediaNetworkPlaylistProvider);
-
- int pos = d->resources.count();
-
- emit mediaAboutToBeInserted(pos, pos);
- d->resources.append(content);
- emit mediaInserted(pos, pos);
-
- return true;
-}
-
-bool QMediaNetworkPlaylistProvider::addMedia(const QList<QMediaContent> &items)
-{
- Q_D(QMediaNetworkPlaylistProvider);
-
- if (items.isEmpty())
- return true;
-
- int pos = d->resources.count();
- int end = pos+items.count()-1;
-
- emit mediaAboutToBeInserted(pos, end);
- d->resources.append(items);
- emit mediaInserted(pos, end);
-
- return true;
-}
-
-
-bool QMediaNetworkPlaylistProvider::insertMedia(int pos, const QMediaContent &content)
-{
- Q_D(QMediaNetworkPlaylistProvider);
-
- emit mediaAboutToBeInserted(pos, pos);
- d->resources.insert(pos, content);
- emit mediaInserted(pos,pos);
-
- return true;
-}
-
-bool QMediaNetworkPlaylistProvider::insertMedia(int pos, const QList<QMediaContent> &items)
-{
- Q_D(QMediaNetworkPlaylistProvider);
-
- if (items.isEmpty())
- return true;
-
- const int last = pos+items.count()-1;
-
- emit mediaAboutToBeInserted(pos, last);
- for (int i=0; i<items.count(); i++)
- d->resources.insert(pos+i, items.at(i));
- emit mediaInserted(pos, last);
-
- return true;
-}
-
-bool QMediaNetworkPlaylistProvider::moveMedia(int from, int to)
-{
- Q_D(QMediaNetworkPlaylistProvider);
-
- Q_ASSERT(from >= 0 && from < mediaCount());
- Q_ASSERT(to >= 0 && to < mediaCount());
-
- if (from == to)
- return false;
-
- const QMediaContent media = d->resources.at(from);
- return removeMedia(from, from) && insertMedia(to, media);
-}
-
-bool QMediaNetworkPlaylistProvider::removeMedia(int fromPos, int toPos)
-{
- Q_D(QMediaNetworkPlaylistProvider);
-
- Q_ASSERT(fromPos >= 0);
- Q_ASSERT(fromPos <= toPos);
- Q_ASSERT(toPos < mediaCount());
-
- emit mediaAboutToBeRemoved(fromPos, toPos);
- d->resources.erase(d->resources.begin()+fromPos, d->resources.begin()+toPos+1);
- emit mediaRemoved(fromPos, toPos);
-
- return true;
-}
-
-bool QMediaNetworkPlaylistProvider::removeMedia(int pos)
-{
- Q_D(QMediaNetworkPlaylistProvider);
-
- emit mediaAboutToBeRemoved(pos, pos);
- d->resources.removeAt(pos);
- emit mediaRemoved(pos, pos);
-
- return true;
-}
-
-bool QMediaNetworkPlaylistProvider::clear()
-{
- Q_D(QMediaNetworkPlaylistProvider);
- if (!d->resources.isEmpty()) {
- int lastPos = mediaCount()-1;
- emit mediaAboutToBeRemoved(0, lastPos);
- d->resources.clear();
- emit mediaRemoved(0, lastPos);
- }
-
- return true;
-}
-
-void QMediaNetworkPlaylistProvider::shuffle()
-{
- Q_D(QMediaNetworkPlaylistProvider);
- if (!d->resources.isEmpty()) {
- QList<QMediaContent> resources;
-
- while (!d->resources.isEmpty()) {
- resources.append(d->resources.takeAt(QRandomGenerator::global()->bounded(int(d->resources.size()))));
- }
-
- d->resources = resources;
- emit mediaChanged(0, mediaCount()-1);
- }
-
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qmedianetworkplaylistprovider_p.cpp"
diff --git a/src/multimedia/playback/qmedianetworkplaylistprovider_p.h b/src/multimedia/playback/qmedianetworkplaylistprovider_p.h
deleted file mode 100644
index 6b5220935..000000000
--- a/src/multimedia/playback/qmedianetworkplaylistprovider_p.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIANETWORKPAYLISTPROVIDER_P_H
-#define QMEDIANETWORKPAYLISTPROVIDER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qmediaplaylistprovider_p.h"
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaNetworkPlaylistProviderPrivate;
-class Q_MULTIMEDIA_EXPORT QMediaNetworkPlaylistProvider : public QMediaPlaylistProvider
-{
- Q_OBJECT
-public:
- QMediaNetworkPlaylistProvider(QObject *parent = nullptr);
- ~QMediaNetworkPlaylistProvider();
-
- bool load(const QNetworkRequest &request, const char *format = nullptr) override;
-
- int mediaCount() const override;
- QMediaContent media(int pos) const override;
-
- bool isReadOnly() const override;
-
- bool addMedia(const QMediaContent &content) override;
- bool addMedia(const QList<QMediaContent> &items) override;
- bool insertMedia(int pos, const QMediaContent &content) override;
- bool insertMedia(int pos, const QList<QMediaContent> &items) override;
- bool moveMedia(int from, int to) override;
- bool removeMedia(int pos) override;
- bool removeMedia(int start, int end) override;
- bool clear() override;
-
-public Q_SLOTS:
- void shuffle() override;
-
-private:
- Q_DISABLE_COPY(QMediaNetworkPlaylistProvider)
- Q_DECLARE_PRIVATE(QMediaNetworkPlaylistProvider)
- Q_PRIVATE_SLOT(d_func(), void _q_handleParserError(QPlaylistFileParser::ParserError err, const QString &))
- Q_PRIVATE_SLOT(d_func(), void _q_handleNewItem(const QVariant& content))
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIANETWORKPAYLISTSOURCE_P_H
diff --git a/src/multimedia/playback/qmediaplayer.cpp b/src/multimedia/playback/qmediaplayer.cpp
index 977c02e69..644c2d094 100644
--- a/src/multimedia/playback/qmediaplayer.cpp
+++ b/src/multimedia/playback/qmediaplayer.cpp
@@ -1,372 +1,156 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaplayer.h"
-#include "qvideosurfaces_p.h"
-#include "qvideosurfaceoutput_p.h"
-
-#include "qmediaobject_p.h"
-#include <qmediaservice.h>
-#include <qmediaplayercontrol.h>
-#include <qmediaserviceprovider_p.h>
-#include <qmediaplaylist.h>
-#include <qmediaplaylistcontrol_p.h>
-#include <qmediaplaylistsourcecontrol_p.h>
-#include <qaudiorolecontrol.h>
-#include <qcustomaudiorolecontrol.h>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qmediaplayer_p.h"
+
+#include <private/qmultimediautils_p.h>
+#include <private/qplatformmediaintegration_p.h>
+#include <private/qaudiobufferoutput_p.h>
+#include <qvideosink.h>
+#include <qaudiooutput.h>
#include <QtCore/qcoreevent.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qtimer.h>
#include <QtCore/qdebug.h>
+#include <QtCore/qdir.h>
#include <QtCore/qpointer.h>
#include <QtCore/qfileinfo.h>
#include <QtCore/qtemporaryfile.h>
-#include <QDir>
+#include <QtCore/qcoreapplication.h>
+
+#if defined(Q_OS_ANDROID)
+# include <QtCore/qjniobject.h>
+#endif
QT_BEGIN_NAMESPACE
/*!
\class QMediaPlayer
- \brief The QMediaPlayer class allows the playing of a media source.
+ \brief The QMediaPlayer class allows the playing of a media files.
\inmodule QtMultimedia
\ingroup multimedia
\ingroup multimedia_playback
+ \ingroup multimedia_video
The QMediaPlayer class is a high level media playback class. It can be used
- to playback such content as songs, movies and internet radio. The content
- to playback is specified as a QMediaContent object, which can be thought of as a
- main or canonical URL with additional information attached. When provided
- with a QMediaContent playback may be able to commence.
+ to playback audio of video media files. The content
+ to playback is specified as a QUrl object.
\snippet multimedia-snippets/media.cpp Player
- QVideoWidget can be used with QMediaPlayer for video rendering and QMediaPlaylist
- for accessing playlist functionality.
+ QVideoWidget can be used with QMediaPlayer for video rendering.
- \snippet multimedia-snippets/media.cpp Movie playlist
-
- Since QMediaPlayer is a QMediaObject, you can use several of the QMediaObject
- functions for things like:
-
- \list
- \li Accessing the currently playing media's metadata (\l {QMediaObject::metaData()} and \l {QMediaMetaData}{predefined meta-data keys})
- \li Checking to see if the media playback service is currently available (\l {QMediaObject::availability()})
- \endlist
-
- \sa QMediaObject, QMediaService, QVideoWidget, QMediaPlaylist
+ \sa QVideoWidget
*/
-static void qRegisterMediaPlayerMetaTypes()
-{
- qRegisterMetaType<QMediaPlayer::State>("QMediaPlayer::State");
- qRegisterMetaType<QMediaPlayer::MediaStatus>("QMediaPlayer::MediaStatus");
- qRegisterMetaType<QMediaPlayer::Error>("QMediaPlayer::Error");
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterMediaPlayerMetaTypes)
-
-#define MAX_NESTED_PLAYLISTS 16
-
-class QMediaPlayerPrivate : public QMediaObjectPrivate
-{
- Q_DECLARE_NON_CONST_PUBLIC(QMediaPlayer)
-
-public:
- QMediaPlayerPrivate()
- : provider(nullptr)
- , control(nullptr)
- , audioRoleControl(nullptr)
- , customAudioRoleControl(nullptr)
- , playlist(nullptr)
- , state(QMediaPlayer::StoppedState)
- , status(QMediaPlayer::UnknownMediaStatus)
- , error(QMediaPlayer::NoError)
- , ignoreNextStatusChange(-1)
- , nestedPlaylists(0)
- , hasStreamPlaybackFeature(false)
- {}
-
- QMediaServiceProvider *provider;
- QMediaPlayerControl* control;
- QAudioRoleControl *audioRoleControl;
- QCustomAudioRoleControl *customAudioRoleControl;
- QString errorString;
-
- QPointer<QObject> videoOutput;
- QMediaPlaylist *playlist;
- QVideoSurfaceOutput surfaceOutput;
- QMediaContent qrcMedia;
- QScopedPointer<QFile> qrcFile;
-
- QMediaContent rootMedia;
- QMediaContent pendingPlaylist;
- QMediaPlayer::State state;
- QMediaPlayer::MediaStatus status;
- QMediaPlayer::Error error;
- int ignoreNextStatusChange;
- int nestedPlaylists;
- bool hasStreamPlaybackFeature;
-
- QMediaPlaylist *parentPlaylist(QMediaPlaylist *pls);
- bool isInChain(const QUrl &url);
-
- void setMedia(const QMediaContent &media, QIODevice *stream = nullptr);
-
- void setPlaylist(QMediaPlaylist *playlist);
- void setPlaylistMedia();
- void loadPlaylist();
- void disconnectPlaylist();
- void connectPlaylist();
-
- void _q_stateChanged(QMediaPlayer::State state);
- void _q_mediaStatusChanged(QMediaPlayer::MediaStatus status);
- void _q_error(int error, const QString &errorString);
- void _q_updateMedia(const QMediaContent&);
- void _q_playlistDestroyed();
- void _q_handleMediaChanged(const QMediaContent&);
- void _q_handlePlaylistLoaded();
- void _q_handlePlaylistLoadFailed();
-};
-
-QMediaPlaylist *QMediaPlayerPrivate::parentPlaylist(QMediaPlaylist *pls)
-{
- // This function finds a parent playlist for an item in the active chain of playlists.
- // Every item in the chain comes from currentMedia() of its parent.
- // We don't need to travers the whole tree of playlists,
- // but only the subtree of active ones.
- for (QMediaPlaylist *current = rootMedia.playlist(); current && current != pls; current = current->currentMedia().playlist())
- if (current->currentMedia().playlist() == pls)
- return current;
- return nullptr;
-}
-
-bool QMediaPlayerPrivate::isInChain(const QUrl &url)
-{
- // Check whether a URL is already in the chain of playlists.
- // Also see a comment in parentPlaylist().
- for (QMediaPlaylist *current = rootMedia.playlist(); current && current != playlist; current = current->currentMedia().playlist())
- if (current->currentMedia().request().url() == url) {
- return true;
+/*!
+ \qmltype MediaPlayer
+ \instantiates QMediaPlayer
+ \brief Adds media playback to a scene.
+
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+ \ingroup multimedia_audio_qml
+ \ingroup multimedia_video_qml
+
+ \qml
+ Text {
+ text: "Click Me!";
+ font.pointSize: 24;
+ width: 150; height: 50;
+
+ MediaPlayer {
+ id: playMusic
+ source: "music.wav"
+ audioOutput: AudioOutput {}
}
- return false;
-}
-
-void QMediaPlayerPrivate::_q_stateChanged(QMediaPlayer::State ps)
-{
- Q_Q(QMediaPlayer);
-
- // Backend switches into stopped state every time new media is about to be loaded.
- // If media player has a playlist loaded make sure player doesn' stop.
- if (playlist && playlist->currentIndex() != -1 && ps != state && ps == QMediaPlayer::StoppedState) {
- if (control->mediaStatus() == QMediaPlayer::EndOfMedia ||
- control->mediaStatus() == QMediaPlayer::InvalidMedia) {
- // if media player is not stopped, and
- // we have finished playback for the current media,
- // advance to the next item in the playlist
- Q_ASSERT(state != QMediaPlayer::StoppedState);
- playlist->next();
- return;
- } else if (control->mediaStatus() == QMediaPlayer::LoadingMedia) {
- return;
+ MouseArea {
+ anchors.fill: parent
+ onPressed: { playMusic.play() }
}
}
+ \endqml
+
+ You can use MediaPlayer together with a MultiMedia::AudioOutput to play audio content, or you can use it
+ in conjunction with a Multimedia::VideoOutput for rendering video.
+
+ \qml
+ Item {
+ MediaPlayer {
+ id: mediaplayer
+ source: "groovy_video.mp4"
+ audioOutput: AudioOutput {}
+ videoOutput: videoOutput
+ }
- if (ps != state) {
- state = ps;
-
- if (ps == QMediaPlayer::PlayingState)
- q->addPropertyWatch("position");
- else
- q->removePropertyWatch("position");
+ VideoOutput {
+ id: videoOutput
+ anchors.fill: parent
+ }
- emit q->stateChanged(ps);
+ MouseArea {
+ anchors.fill: parent
+ onPressed: mediaplayer.play();
+ }
}
-}
+ \endqml
-void QMediaPlayerPrivate::_q_mediaStatusChanged(QMediaPlayer::MediaStatus s)
+ \sa AudioOutput, VideoOutput
+*/
+
+void QMediaPlayerPrivate::setState(QMediaPlayer::PlaybackState toState)
{
Q_Q(QMediaPlayer);
- if (int(s) == ignoreNextStatusChange) {
- ignoreNextStatusChange = -1;
- return;
- }
-
- if (s != status) {
- status = s;
-
- switch (s) {
- case QMediaPlayer::StalledMedia:
- case QMediaPlayer::BufferingMedia:
- q->addPropertyWatch("bufferStatus");
- break;
- default:
- q->removePropertyWatch("bufferStatus");
- break;
- }
-
- emit q->mediaStatusChanged(s);
+ if (toState != state) {
+ const auto fromState = std::exchange(state, toState);
+ if (toState == QMediaPlayer::PlayingState || fromState == QMediaPlayer::PlayingState)
+ emit q->playingChanged(toState == QMediaPlayer::PlayingState);
+ emit q->playbackStateChanged(toState);
}
}
-void QMediaPlayerPrivate::_q_error(int error, const QString &errorString)
+void QMediaPlayerPrivate::setStatus(QMediaPlayer::MediaStatus s)
{
Q_Q(QMediaPlayer);
- if (error == int(QMediaPlayer::MediaIsPlaylist)) {
- loadPlaylist();
- } else {
- this->error = QMediaPlayer::Error(error);
- this->errorString = errorString;
- emit q->error(this->error);
-
- if (playlist)
- playlist->next();
- }
+ emit q->mediaStatusChanged(s);
}
-void QMediaPlayerPrivate::_q_updateMedia(const QMediaContent &media)
+void QMediaPlayerPrivate::setError(QMediaPlayer::Error error, const QString &errorString)
{
Q_Q(QMediaPlayer);
- if (!control)
- return;
-
- // check if the current playlist is a top-level playlist
- Q_ASSERT(playlist);
- if (media.isNull() && playlist != rootMedia.playlist()) {
- // switch back to parent playlist
- QMediaPlaylist *pls = parentPlaylist(playlist);
- Q_ASSERT(pls);
- disconnectPlaylist();
- playlist = pls;
- connectPlaylist();
-
- Q_ASSERT(!pendingPlaylist.playlist());
- nestedPlaylists--;
- Q_ASSERT(nestedPlaylists >= 0);
-
- playlist->next();
- return;
- }
-
- if (media.playlist()) {
- if (nestedPlaylists < MAX_NESTED_PLAYLISTS) {
- nestedPlaylists++;
- Q_ASSERT(!pendingPlaylist.playlist());
-
- // disconnect current playlist
- disconnectPlaylist();
- // new playlist signals are connected
- // in the call to setPlaylist() in _q_handlePlaylistLoaded()
- playlist = media.playlist();
- emit q->currentMediaChanged(media);
- _q_handlePlaylistLoaded();
- return;
- } else if (playlist) {
- playlist->next();
- }
- return;
- }
-
- const QMediaPlayer::State currentState = state;
-
- setMedia(media, nullptr);
-
- if (!media.isNull()) {
- switch (currentState) {
- case QMediaPlayer::PlayingState:
- control->play();
- break;
- case QMediaPlayer::PausedState:
- control->pause();
- break;
- default:
- break;
- }
- }
-
- _q_stateChanged(control->state());
-}
-
-void QMediaPlayerPrivate::_q_playlistDestroyed()
-{
- playlist = nullptr;
- setMedia(QMediaContent(), nullptr);
+ this->error.setAndNotify(error, errorString, *q);
}
-void QMediaPlayerPrivate::setMedia(const QMediaContent &media, QIODevice *stream)
+void QMediaPlayerPrivate::setMedia(const QUrl &media, QIODevice *stream)
{
- Q_Q(QMediaPlayer);
-
if (!control)
return;
- QScopedPointer<QFile> file;
+ std::unique_ptr<QFile> file;
- // Backends can't play qrc files directly.
- // If the backend supports StreamPlayback, we pass a QFile for that resource.
+ // Back ends can't play qrc files directly.
+ // If the back end supports StreamPlayback, we pass a QFile for that resource.
// If it doesn't, we copy the data to a temporary file and pass its path.
- if (!media.isNull() && !stream && media.request().url().scheme() == QLatin1String("qrc")) {
+ if (!media.isEmpty() && !stream && media.scheme() == QLatin1String("qrc")) {
qrcMedia = media;
- file.reset(new QFile(QLatin1Char(':') + media.request().url().path()));
+ file.reset(new QFile(QLatin1Char(':') + media.path()));
if (!file->open(QFile::ReadOnly)) {
- QMetaObject::invokeMethod(q, "_q_error", Qt::QueuedConnection,
- Q_ARG(int, QMediaPlayer::ResourceError),
- Q_ARG(QString, QMediaPlayer::tr("Attempting to play invalid Qt resource")));
- QMetaObject::invokeMethod(q, "_q_mediaStatusChanged", Qt::QueuedConnection,
- Q_ARG(QMediaPlayer::MediaStatus, QMediaPlayer::InvalidMedia));
file.reset();
- // Ignore the next NoMedia status change, we just want to clear the current media
- // on the backend side since we can't load the new one and we want to be in the
- // InvalidMedia status.
- ignoreNextStatusChange = QMediaPlayer::NoMedia;
- control->setMedia(QMediaContent(), nullptr);
-
- } else if (hasStreamPlaybackFeature) {
- control->setMedia(media, file.data());
+ control->setMedia(QUrl(), nullptr);
+ control->mediaStatusChanged(QMediaPlayer::InvalidMedia);
+ control->error(QMediaPlayer::ResourceError, QMediaPlayer::tr("Attempting to play invalid Qt resource"));
+
+ } else if (control->streamPlaybackSupported()) {
+ control->setMedia(media, file.get());
} else {
#if QT_CONFIG(temporaryfile)
#if defined(Q_OS_ANDROID)
- QString tempFileName = QDir::tempPath() + media.request().url().path();
+ QString tempFileName = QDir::tempPath() + media.path();
QDir().mkpath(QFileInfo(tempFileName).path());
QTemporaryFile *tempFile = QTemporaryFile::createNativeFile(*file);
if (!tempFile->rename(tempFileName))
@@ -374,14 +158,21 @@ void QMediaPlayerPrivate::setMedia(const QMediaContent &media, QIODevice *stream
#else
QTemporaryFile *tempFile = new QTemporaryFile;
- // Preserve original file extension, some backends might not load the file if it doesn't
+ // Preserve original file extension, some back ends might not load the file if it doesn't
// have an extension.
const QString suffix = QFileInfo(*file).suffix();
if (!suffix.isEmpty())
tempFile->setFileTemplate(tempFile->fileTemplate() + QLatin1Char('.') + suffix);
// Copy the qrc data into the temporary file
- tempFile->open();
+ if (!tempFile->open()) {
+ control->setMedia(QUrl(), nullptr);
+ control->mediaStatusChanged(QMediaPlayer::InvalidMedia);
+ control->error(QMediaPlayer::ResourceError, tempFile->errorString());
+ delete tempFile;
+ qrcFile.reset();
+ return;
+ }
char buffer[4096];
while (true) {
qint64 len = file->read(buffer, sizeof(buffer));
@@ -392,253 +183,53 @@ void QMediaPlayerPrivate::setMedia(const QMediaContent &media, QIODevice *stream
tempFile->close();
#endif
file.reset(tempFile);
- control->setMedia(QMediaContent(QUrl::fromLocalFile(file->fileName())), nullptr);
+ control->setMedia(QUrl(QUrl::fromLocalFile(file->fileName())), nullptr);
#else
qWarning("Qt was built with -no-feature-temporaryfile: playback from resource file is not supported!");
#endif
}
} else {
- qrcMedia = QMediaContent();
- control->setMedia(media, stream);
- }
-
- qrcFile.swap(file); // Cleans up any previous file
-}
-
-void QMediaPlayerPrivate::_q_handleMediaChanged(const QMediaContent &media)
-{
- Q_Q(QMediaPlayer);
-
- emit q->currentMediaChanged(qrcMedia.isNull() ? media : qrcMedia);
-}
-
-void QMediaPlayerPrivate::setPlaylist(QMediaPlaylist *pls)
-{
- disconnectPlaylist();
- playlist = pls;
-
- setPlaylistMedia();
-}
-
-void QMediaPlayerPrivate::setPlaylistMedia()
-{
- // This function loads current playlist media into backend.
- // If current media is a playlist, the function recursively
- // loads media from the playlist.
- // It also makes sure the correct playlist signals are connected.
- Q_Q(QMediaPlayer);
-
- if (playlist) {
- connectPlaylist();
- if (playlist->currentMedia().playlist()) {
- if (nestedPlaylists < MAX_NESTED_PLAYLISTS) {
- emit q->currentMediaChanged(playlist->currentMedia());
- // rewind nested playlist to start
- playlist->currentMedia().playlist()->setCurrentIndex(0);
- nestedPlaylists++;
- setPlaylist(playlist->currentMedia().playlist());
- } else {
- playlist->next();
- }
- return;
- } else {
- // If we've just switched to a new playlist,
- // then last emitted currentMediaChanged was a playlist.
- // Make sure we emit currentMediaChanged if new playlist has
- // the same media as the previous one:
- // sample.m3u
- // test.wav -- processed by backend
- // nested.m3u -- processed by frontend
- // test.wav -- processed by backend,
- // media is not changed,
- // frontend needs to emit currentMediaChanged
- bool isSameMedia = (q->currentMedia() == playlist->currentMedia());
- setMedia(playlist->currentMedia(), nullptr);
- if (isSameMedia) {
- emit q->currentMediaChanged(q->currentMedia());
- }
+ qrcMedia = QUrl();
+ QUrl url = qMediaFromUserInput(media);
+ if (url.scheme() == QLatin1String("content") && !stream) {
+ file.reset(new QFile(media.url()));
+ stream = file.get();
}
- } else {
- setMedia(QMediaContent(), nullptr);
- }
-}
-
-void QMediaPlayerPrivate::loadPlaylist()
-{
- Q_Q(QMediaPlayer);
- Q_ASSERT(pendingPlaylist.isNull());
-
- // Do not load a playlist if there are more than MAX_NESTED_PLAYLISTS in the chain already,
- // or if the playlist URL is already in the chain, i.e. do not allow recursive playlists and loops.
- if (nestedPlaylists < MAX_NESTED_PLAYLISTS
- && !q->currentMedia().request().url().isEmpty()
- && !isInChain(q->currentMedia().request().url()))
- {
- pendingPlaylist = QMediaContent(new QMediaPlaylist, q->currentMedia().request().url(), true);
- QObject::connect(pendingPlaylist.playlist(), SIGNAL(loaded()), q, SLOT(_q_handlePlaylistLoaded()));
- QObject::connect(pendingPlaylist.playlist(), SIGNAL(loadFailed()), q, SLOT(_q_handlePlaylistLoadFailed()));
- pendingPlaylist.playlist()->load(pendingPlaylist.request());
- } else if (playlist) {
- playlist->next();
- }
-}
-void QMediaPlayerPrivate::disconnectPlaylist()
-{
- Q_Q(QMediaPlayer);
- if (playlist) {
- QObject::disconnect(playlist, SIGNAL(currentMediaChanged(QMediaContent)),
- q, SLOT(_q_updateMedia(QMediaContent)));
- QObject::disconnect(playlist, SIGNAL(destroyed()), q, SLOT(_q_playlistDestroyed()));
- q->unbind(playlist);
+ control->setMedia(url, stream);
}
-}
-void QMediaPlayerPrivate::connectPlaylist()
-{
- Q_Q(QMediaPlayer);
- if (playlist) {
- q->bind(playlist);
- QObject::connect(playlist, SIGNAL(currentMediaChanged(QMediaContent)),
- q, SLOT(_q_updateMedia(QMediaContent)));
- QObject::connect(playlist, SIGNAL(destroyed()), q, SLOT(_q_playlistDestroyed()));
- }
+ qrcFile.swap(file); // Cleans up any previous file
}
-void QMediaPlayerPrivate::_q_handlePlaylistLoaded()
+QList<QMediaMetaData> QMediaPlayerPrivate::trackMetaData(QPlatformMediaPlayer::TrackType s) const
{
- Q_Q(QMediaPlayer);
-
- if (pendingPlaylist.playlist()) {
- Q_ASSERT(!q->currentMedia().playlist());
- // if there is an active playlist
- if (playlist) {
- Q_ASSERT(playlist->currentIndex() >= 0);
- disconnectPlaylist();
- playlist->insertMedia(playlist->currentIndex() + 1, pendingPlaylist);
- playlist->removeMedia(playlist->currentIndex());
- nestedPlaylists++;
- } else {
- Q_ASSERT(!rootMedia.playlist());
- rootMedia = pendingPlaylist;
- emit q->mediaChanged(rootMedia);
+ QList<QMediaMetaData> tracks;
+ if (control) {
+ int count = control->trackCount(s);
+ for (int i = 0; i < count; ++i) {
+ tracks.append(control->trackMetaData(s, i));
}
-
- playlist = pendingPlaylist.playlist();
- emit q->currentMediaChanged(pendingPlaylist);
- }
- pendingPlaylist = QMediaContent();
-
- playlist->next();
- setPlaylistMedia();
-
- switch (state) {
- case QMediaPlayer::PausedState:
- control->pause();
- break;
- case QMediaPlayer::PlayingState:
- control->play();
- break;
- case QMediaPlayer::StoppedState:
- break;
- }
-}
-
-void QMediaPlayerPrivate::_q_handlePlaylistLoadFailed()
-{
- pendingPlaylist = QMediaContent();
-
- if (!control)
- return;
-
- if (playlist)
- playlist->next();
- else
- setMedia(QMediaContent(), nullptr);
-}
-
-static QMediaService *playerService(QMediaPlayer::Flags flags)
-{
- QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
- if (flags) {
- QMediaServiceProviderHint::Features features;
- if (flags & QMediaPlayer::LowLatency)
- features |= QMediaServiceProviderHint::LowLatencyPlayback;
-
- if (flags & QMediaPlayer::StreamPlayback)
- features |= QMediaServiceProviderHint::StreamPlayback;
-
- if (flags & QMediaPlayer::VideoSurface)
- features |= QMediaServiceProviderHint::VideoSurface;
-
- return provider->requestService(Q_MEDIASERVICE_MEDIAPLAYER,
- QMediaServiceProviderHint(features));
}
-
- return provider->requestService(Q_MEDIASERVICE_MEDIAPLAYER);
+ return tracks;
}
-
/*!
- Construct a QMediaPlayer instance
- parented to \a parent and with \a flags.
+ Constructs a QMediaPlayer instance as a child of \a{parent}.
*/
-QMediaPlayer::QMediaPlayer(QObject *parent, QMediaPlayer::Flags flags):
- QMediaObject(*new QMediaPlayerPrivate,
- parent,
- playerService(flags))
+QMediaPlayer::QMediaPlayer(QObject *parent)
+ : QObject(*new QMediaPlayerPrivate, parent)
{
Q_D(QMediaPlayer);
- d->provider = QMediaServiceProvider::defaultServiceProvider();
- if (d->service == nullptr) {
- d->error = ServiceMissingError;
+ auto maybeControl = QPlatformMediaIntegration::instance()->createPlayer(this);
+ if (maybeControl) {
+ d->control = maybeControl.value();
+ d->state = d->control->state();
} else {
- d->control = qobject_cast<QMediaPlayerControl*>(d->service->requestControl(QMediaPlayerControl_iid));
- if (d->control != nullptr) {
- connect(d->control, SIGNAL(mediaChanged(QMediaContent)), SLOT(_q_handleMediaChanged(QMediaContent)));
- connect(d->control, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(_q_stateChanged(QMediaPlayer::State)));
- connect(d->control, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
- SLOT(_q_mediaStatusChanged(QMediaPlayer::MediaStatus)));
- connect(d->control, SIGNAL(error(int,QString)), SLOT(_q_error(int,QString)));
-
- connect(d->control, &QMediaPlayerControl::durationChanged, this, &QMediaPlayer::durationChanged);
- connect(d->control, &QMediaPlayerControl::positionChanged, this, &QMediaPlayer::positionChanged);
- connect(d->control, &QMediaPlayerControl::audioAvailableChanged, this, &QMediaPlayer::audioAvailableChanged);
- connect(d->control, &QMediaPlayerControl::videoAvailableChanged, this, &QMediaPlayer::videoAvailableChanged);
- connect(d->control, &QMediaPlayerControl::volumeChanged, this, &QMediaPlayer::volumeChanged);
- connect(d->control, &QMediaPlayerControl::mutedChanged, this, &QMediaPlayer::mutedChanged);
- connect(d->control, &QMediaPlayerControl::seekableChanged, this, &QMediaPlayer::seekableChanged);
- connect(d->control, &QMediaPlayerControl::playbackRateChanged, this, &QMediaPlayer::playbackRateChanged);
- connect(d->control, &QMediaPlayerControl::bufferStatusChanged, this, &QMediaPlayer::bufferStatusChanged);
-
- d->state = d->control->state();
- d->status = d->control->mediaStatus();
-
- if (d->state == PlayingState)
- addPropertyWatch("position");
-
- if (d->status == StalledMedia || d->status == BufferingMedia)
- addPropertyWatch("bufferStatus");
-
- d->hasStreamPlaybackFeature = d->provider->supportedFeatures(d->service).testFlag(QMediaServiceProviderHint::StreamPlayback);
-
- d->audioRoleControl = qobject_cast<QAudioRoleControl*>(d->service->requestControl(QAudioRoleControl_iid));
- if (d->audioRoleControl) {
- connect(d->audioRoleControl, &QAudioRoleControl::audioRoleChanged,
- this, &QMediaPlayer::audioRoleChanged);
-
- d->customAudioRoleControl = qobject_cast<QCustomAudioRoleControl *>(
- d->service->requestControl(QCustomAudioRoleControl_iid));
- if (d->customAudioRoleControl) {
- connect(d->customAudioRoleControl,
- &QCustomAudioRoleControl::customAudioRoleChanged,
- this,
- &QMediaPlayer::customAudioRoleChanged);
- }
- }
- }
+ qWarning() << "Failed to initialize QMediaPlayer" << maybeControl.error();
+ d->setError(QMediaPlayer::ResourceError, maybeControl.error());
}
}
@@ -651,86 +242,56 @@ QMediaPlayer::~QMediaPlayer()
{
Q_D(QMediaPlayer);
- d->disconnectPlaylist();
- // Disconnect everything to prevent notifying
- // when a receiver is already destroyed.
- disconnect();
+ // prevents emitting audioOutputChanged and videoOutputChanged.
+ QSignalBlocker blocker(this);
- if (d->service) {
- if (d->control)
- d->service->releaseControl(d->control);
- if (d->audioRoleControl)
- d->service->releaseControl(d->audioRoleControl);
- if (d->customAudioRoleControl)
- d->service->releaseControl(d->customAudioRoleControl);
+ // Reset audio output and video sink to ensure proper unregistering of the source
+ // To be investigated: registering of the source might be removed after switching on the ffmpeg
+ // backend;
- d->provider->releaseService(d->service);
- }
+ setAudioOutput(nullptr);
+
+ d->setVideoSink(nullptr);
+ delete d->control;
}
-QMediaContent QMediaPlayer::media() const
+QUrl QMediaPlayer::source() const
{
Q_D(const QMediaPlayer);
- return d->rootMedia;
+ return d->source;
}
/*!
Returns the stream source of media data.
- This is only valid if a stream was passed to setMedia().
+ This is only valid if a stream was passed to setSource().
- \sa setMedia()
+ \sa setSource()
*/
-const QIODevice *QMediaPlayer::mediaStream() const
-{
- Q_D(const QMediaPlayer);
-
- // When playing a resource file, we might have passed a QFile to the backend. Hide it from
- // the user.
- if (d->control && d->qrcMedia.isNull())
- return d->control->mediaStream();
-
- return nullptr;
-}
-
-QMediaPlaylist *QMediaPlayer::playlist() const
+const QIODevice *QMediaPlayer::sourceDevice() const
{
Q_D(const QMediaPlayer);
- return d->rootMedia.playlist();
+ return d->stream;
}
-QMediaContent QMediaPlayer::currentMedia() const
-{
- Q_D(const QMediaPlayer);
-
- // When playing a resource file, don't return the backend's current media, which
- // can be a temporary file.
- if (!d->qrcMedia.isNull())
- return d->qrcMedia;
-
- if (d->control)
- return d->control->media();
-
- return QMediaContent();
-}
+/*!
+ \property QMediaPlayer::playbackState
-void QMediaPlayer::setPlaylist(QMediaPlaylist *playlist)
-{
- QMediaContent m(playlist, QUrl(), false);
- setMedia(m);
-}
+ Returns the \l{QMediaPlayer::}{PlaybackState}.
-QMediaPlayer::State QMediaPlayer::state() const
+ \sa playing
+*/
+QMediaPlayer::PlaybackState QMediaPlayer::playbackState() const
{
Q_D(const QMediaPlayer);
// In case if EndOfMedia status is already received
// but state is not.
- if (d->control != nullptr
- && d->status == QMediaPlayer::EndOfMedia
+ if (d->control
+ && d->control->mediaStatus() == QMediaPlayer::EndOfMedia
&& d->state != d->control->state()) {
return d->control->state();
}
@@ -740,545 +301,789 @@ QMediaPlayer::State QMediaPlayer::state() const
QMediaPlayer::MediaStatus QMediaPlayer::mediaStatus() const
{
- return d_func()->status;
+ Q_D(const QMediaPlayer);
+ return d->control ? d->control->mediaStatus() : NoMedia;
}
+/*!
+ Returns the duration of the current media in ms.
+
+ Returns 0 if the media player doesn't have a valid media file or stream.
+ For live streams, the duration usually changes during playback as more
+ data becomes available.
+*/
qint64 QMediaPlayer::duration() const
{
Q_D(const QMediaPlayer);
-
- if (d->control != nullptr)
- return d->control->duration();
-
- return -1;
+ return d->control ? d->control->duration() : 0;
}
+/*!
+ Returns the current position inside the media being played back in ms.
+
+ Returns 0 if the media player doesn't have a valid media file or stream.
+ For live streams, the duration usually changes during playback as more
+ data becomes available.
+*/
qint64 QMediaPlayer::position() const
{
Q_D(const QMediaPlayer);
+ return d->control ? d->control->position() : 0;
+}
- if (d->control != nullptr)
- return d->control->position();
+/*!
+ Returns a number between 0 and 1 when buffering data.
- return 0;
-}
+ 0 means that there is no buffered data available, playback is usually
+ stalled in this case. Playback will resume once the buffer reaches 1,
+ meaning enough data has been buffered to be able to resume playback.
-int QMediaPlayer::volume() const
+ bufferProgress() will always return 1 for local files.
+*/
+float QMediaPlayer::bufferProgress() const
{
Q_D(const QMediaPlayer);
+ return d->control ? d->control->bufferProgress() : 0;
+}
- if (d->control != nullptr)
- return d->control->volume();
+/*!
+ Returns a QMediaTimeRange describing the currently buffered data.
- return 0;
-}
+ When streaming media from a remote source, different parts of the media
+ file can be available locally. The returned QMediaTimeRange object describes
+ the time ranges that are buffered and available for immediate playback.
-bool QMediaPlayer::isMuted() const
+ \sa QMediaTimeRange
+*/
+QMediaTimeRange QMediaPlayer::bufferedTimeRange() const
{
Q_D(const QMediaPlayer);
+ return d->control ? d->control->availablePlaybackRanges() : QMediaTimeRange{};
+}
- if (d->control != nullptr)
- return d->control->isMuted();
+/*!
+ \qmlproperty bool QtMultimedia::MediaPlayer::hasAudio
- return false;
-}
+ This property holds whether the media contains audio.
+*/
-int QMediaPlayer::bufferStatus() const
+/*!
+ \property QMediaPlayer::hasAudio
+ \brief This property holds whether the media contains audio.
+*/
+bool QMediaPlayer::hasAudio() const
{
Q_D(const QMediaPlayer);
+ return d->control && d->control->isAudioAvailable();
+}
- if (d->control != nullptr)
- return d->control->bufferStatus();
+/*!
+ \qmlproperty bool QtMultimedia::MediaPlayer::hasVideo
- return 0;
-}
+ This property holds whether the media contains video.
+*/
-bool QMediaPlayer::isAudioAvailable() const
+/*!
+ \property QMediaPlayer::hasVideo
+ \brief This property holds whether the media contains video.
+*/
+bool QMediaPlayer::hasVideo() const
{
Q_D(const QMediaPlayer);
+ return d->control && d->control->isVideoAvailable();
+}
- if (d->control != nullptr)
- return d->control->isAudioAvailable();
+/*!
+ Returns true if the media is seekable. Most file based media files are seekable,
+ but live streams usually are not.
- return false;
+ \sa position
+*/
+bool QMediaPlayer::isSeekable() const
+{
+ Q_D(const QMediaPlayer);
+ return d->control && d->control->isSeekable();
}
-bool QMediaPlayer::isVideoAvailable() const
+bool QMediaPlayer::isPlaying() const
{
Q_D(const QMediaPlayer);
-
- if (d->control != nullptr)
- return d->control->isVideoAvailable();
-
- return false;
+ return d->state == QMediaPlayer::PlayingState;
}
-bool QMediaPlayer::isSeekable() const
+/*!
+ Returns the current playback rate.
+*/
+qreal QMediaPlayer::playbackRate() const
{
Q_D(const QMediaPlayer);
+ return d->control ? d->control->playbackRate() : 0.;
+}
+
+/*!
+ \enum QMediaPlayer::Loops
- if (d->control != nullptr)
- return d->control->isSeekable();
+ Some predefined constants for the \l loops property.
- return false;
-}
+ \value Infinite Loop forever.
+ \value Once Play the media once (the default).
+*/
-qreal QMediaPlayer::playbackRate() const
+/*!
+ \property QMediaPlayer::loops
+
+ Determines how often the media is played before the player stops.
+ Set to QMediaPlayer::Infinite to loop the current media file forever.
+
+ The default value is \c 1. Setting this property to \c 0 has no effect.
+*/
+
+/*!
+ \qmlproperty int QtMultimedia::MediaPlayer::loops
+
+ Determines how often the media is played before the player stops.
+ Set to MediaPlayer::Infinite to loop the current media file forever.
+
+ The default value is \c 1. Setting this property to \c 0 has no effect.
+*/
+int QMediaPlayer::loops() const
{
Q_D(const QMediaPlayer);
+ return d->control ? d->control->loops() : 1;
+}
- if (d->control != nullptr)
- return d->control->playbackRate();
-
- return 0.0;
+void QMediaPlayer::setLoops(int loops)
+{
+ Q_D(QMediaPlayer);
+ if (loops == 0)
+ return;
+ if (d->control)
+ d->control->setLoops(loops);
}
/*!
Returns the current error state.
*/
-
QMediaPlayer::Error QMediaPlayer::error() const
{
- return d_func()->error;
+ return d_func()->error.code();
}
+/*!
+ \qmlproperty string QtMultimedia::MediaPlayer::errorString
+
+ This property holds a string describing the current error condition in more
+ detail.
+*/
+
+/*!
+ \property QMediaPlayer::errorString
+ \brief This property holds a string describing the current error condition in
+ more detail.
+*/
QString QMediaPlayer::errorString() const
{
- return d_func()->errorString;
+ return d_func()->error.description();
}
-//public Q_SLOTS:
/*!
- Start or resume playing the current source.
+ \qmlmethod QtMultimedia::MediaPlayer::play()
+
+ Starts or resumes playback of the media.
+
+ Sets the \l playbackState property to PlayingState, and changes
+ \l playing to \c true.
*/
+/*!
+ Start or resume playing the current source.
+
+ \sa pause(), stop()
+*/
void QMediaPlayer::play()
{
Q_D(QMediaPlayer);
- if (d->control == nullptr) {
- QMetaObject::invokeMethod(this, "_q_error", Qt::QueuedConnection,
- Q_ARG(int, QMediaPlayer::ServiceMissingError),
- Q_ARG(QString, tr("The QMediaPlayer object does not have a valid service")));
+ if (!d->control)
return;
- }
-
- //if playlist control is available, the service should advance itself
- if (d->rootMedia.playlist() && !d->rootMedia.playlist()->isEmpty()) {
- // switch to playing state
- if (d->state != QMediaPlayer::PlayingState)
- d->_q_stateChanged(QMediaPlayer::PlayingState);
-
- if (d->rootMedia.playlist()->currentIndex() == -1) {
- if (d->playlist != d->rootMedia.playlist())
- d->setPlaylist(d->rootMedia.playlist());
- Q_ASSERT(d->playlist == d->rootMedia.playlist());
-
- emit currentMediaChanged(d->rootMedia);
- d->playlist->setCurrentIndex(0);
- }
- }
// Reset error conditions
- d->error = NoError;
- d->errorString = QString();
+ d->setError(NoError, QString());
d->control->play();
}
/*!
- Pause playing the current source.
+ \qmlmethod QtMultimedia::MediaPlayer::pause()
+
+ Pauses playback of the media.
+
+ Sets the \l playbackState property to PausedState,
+ and changes \l playing to \c false.
*/
+/*!
+ Pause playing the current source.
+
+ \sa play(), stop()
+*/
void QMediaPlayer::pause()
{
Q_D(QMediaPlayer);
- if (d->control != nullptr)
+ if (d->control)
d->control->pause();
}
/*!
- Stop playing, and reset the play position to the beginning.
+ \qmlmethod QtMultimedia::MediaPlayer::stop()
+
+ Stops playback of the media.
+
+ Sets the \l playbackState property to StoppedState,
+ and changes \l playing to \c false.
*/
+/*!
+ Stop playing, and reset the play position to the beginning.
+
+ \sa play(), pause()
+*/
void QMediaPlayer::stop()
{
Q_D(QMediaPlayer);
- if (d->control != nullptr)
+ if (d->control)
d->control->stop();
-
- // If media player didn't stop in response to control.
- // This happens if we have an active playlist and control
- // media status is
- // QMediaPlayer::LoadingMedia, QMediaPlayer::InvalidMedia, or QMediaPlayer::EndOfMedia
- // see QMediaPlayerPrivate::_q_stateChanged()
- if (d->playlist && d->state != QMediaPlayer::StoppedState) {
- d->state = QMediaPlayer::StoppedState;
- removePropertyWatch("position");
- emit stateChanged(QMediaPlayer::StoppedState);
- }
}
void QMediaPlayer::setPosition(qint64 position)
{
Q_D(QMediaPlayer);
- if (d->control == nullptr)
+ if (!d->control)
+ return;
+ if (!d->control->isSeekable())
return;
-
d->control->setPosition(qMax(position, 0ll));
}
-void QMediaPlayer::setVolume(int v)
+void QMediaPlayer::setPlaybackRate(qreal rate)
{
Q_D(QMediaPlayer);
- if (d->control == nullptr)
- return;
-
- int clamped = qBound(0, v, 100);
- if (clamped == volume())
- return;
-
- d->control->setVolume(clamped);
+ if (d->control)
+ d->control->setPlaybackRate(rate);
}
-void QMediaPlayer::setMuted(bool muted)
-{
- Q_D(QMediaPlayer);
-
- if (d->control == nullptr || muted == isMuted())
- return;
+/*!
+ \qmlproperty url QtMultimedia::MediaPlayer::source
- d->control->setMuted(muted);
-}
+ This property holds the source URL of the media.
-void QMediaPlayer::setPlaybackRate(qreal rate)
-{
- Q_D(QMediaPlayer);
+ \snippet multimedia-snippets/qtvideosink.qml complete
- if (d->control != nullptr)
- d->control->setPlaybackRate(rate);
-}
+ \sa QMediaPlayer::setSource()
+*/
/*!
- Sets the current \a media source.
-
- If a \a stream is supplied; media data will be read from it instead of resolving the media
- source. In this case the url should be provided to resolve additional information
- about the media such as mime type. The \a stream must be open and readable.
- For macOS the \a stream should be also seekable.
+ Sets the current \a source.
- Setting the media to a null QMediaContent will cause the player to discard all
+ Setting the media to a null QUrl will cause the player to discard all
information relating to the current media source and to cease all I/O operations related
- to that media.
+ to that media. Setting the media will stop the playback.
\note This function returns immediately after recording the specified source of the media.
It does not wait for the media to finish loading and does not check for errors. Listen for
the mediaStatusChanged() and error() signals to be notified when the media is loaded and
when an error occurs during loading.
- Since Qt 5.12.2, the url scheme \c gst-pipeline provides custom pipelines
- for the GStreamer backend.
+ \note FFmpeg, used by the FFmpeg media backend, restricts use of nested protocols for
+ security reasons. In controlled environments where all inputs are trusted, the list of
+ approved protocols can be overridden using the QT_FFMPEG_PROTOCOL_WHITELIST environment
+ variable. This environment variable is Qt's private API and can change between patch
+ releases without notice.
+*/
- \snippet multimedia-snippets/media.cpp Pipeline
+void QMediaPlayer::setSource(const QUrl &source)
+{
+ Q_D(QMediaPlayer);
+ stop();
+
+ if (d->source == source && d->stream == nullptr)
+ return;
- If QAbstractVideoSurface is used as the video output,
- \c qtvideosink can be used as a video sink element directly in the pipeline.
- After that the surface will receive the video frames in QAbstractVideoSurface::present().
+ d->source = source;
+ d->stream = nullptr;
- \snippet multimedia-snippets/media.cpp Pipeline Surface
+ d->setMedia(source, nullptr);
+ emit sourceChanged(d->source);
+}
- If QVideoWidget is used as the video output
- and the pipeline contains a video sink element named \c qtvideosink,
- current QVideoWidget will be used to render the video.
+/*!
+ Sets the current source \a device.
- \snippet multimedia-snippets/media.cpp Pipeline Widget
+ The media data will be read from \a device. The \a sourceUrl can be provided
+ to resolve additional information about the media, mime type etc. The
+ \a device must be open and readable.
- If the pipeline contains appsrc element, it will be used to push data from \a stream.
+ For macOS the \a device should also be seek-able.
- \snippet multimedia-snippets/media.cpp Pipeline appsrc
+ \note This function returns immediately after recording the specified source
+ of the media. It does not wait for the media to finish loading and does not
+ check for errors. Listen for the mediaStatusChanged() and error() signals to
+ be notified when the media is loaded, and if an error occurs during loading.
*/
-
-void QMediaPlayer::setMedia(const QMediaContent &media, QIODevice *stream)
+void QMediaPlayer::setSourceDevice(QIODevice *device, const QUrl &sourceUrl)
{
Q_D(QMediaPlayer);
stop();
- QMediaContent oldMedia = d->rootMedia;
- d->disconnectPlaylist();
- d->playlist = nullptr;
- d->rootMedia = media;
- d->nestedPlaylists = 0;
+ if (d->source == sourceUrl && d->stream == device)
+ return;
- if (oldMedia != media)
- emit mediaChanged(d->rootMedia);
+ d->source = sourceUrl;
+ d->stream = device;
- if (media.playlist()) {
- // reset playlist to the 1st item
- media.playlist()->setCurrentIndex(0);
- d->setPlaylist(media.playlist());
- } else {
- d->setMedia(media, stream);
- }
+ d->setMedia(d->source, device);
+ emit sourceChanged(d->source);
}
/*!
- \internal
+ Sets an audio buffer \a output to the media player.
+
+ If \l QAudioBufferOutput is specified and the media source
+ contains an audio stream, the media player, it will emit
+ the signal \l{QAudioBufferOutput::audioBufferReceived} with
+ audio buffers containing decoded audio data. At the end of
+ the audio stream, \c QMediaPlayer emits an empty \l QAudioBuffer.
+
+ \c QMediaPlayer emits outputs frames at the same time as it
+ pushes the matching data to the audio output if it's specified.
+ However, the sound can be played with a small delay due to
+ audio bufferization.
*/
-
-bool QMediaPlayer::bind(QObject *obj)
+void QMediaPlayer::setAudioBufferOutput(QAudioBufferOutput *output)
{
- return QMediaObject::bind(obj);
+ Q_D(QMediaPlayer);
+
+ QAudioBufferOutput *oldOutput = d->audioBufferOutput;
+ if (oldOutput == output)
+ return;
+
+ d->audioBufferOutput = output;
+
+ if (output) {
+ auto oldPlayer = QAudioBufferOutputPrivate::exchangeMediaPlayer(*oldOutput, this);
+ if (oldPlayer)
+ oldPlayer->setAudioBufferOutput(nullptr);
+ }
+
+ if (d->control)
+ d->control->setAudioBufferOutput(output);
+
+ emit audioBufferOutputChanged();
}
/*!
- \internal
+ Get \l QAudioBufferOutput that has been set to the media player.
*/
-
-void QMediaPlayer::unbind(QObject *obj)
+QAudioBufferOutput *QMediaPlayer::audioBufferOutput() const
{
- QMediaObject::unbind(obj);
+ Q_D(const QMediaPlayer);
+ return d->audioBufferOutput;
}
/*!
- Returns the level of support a media player has for a \a mimeType and a set of \a codecs.
+ \qmlproperty AudioOutput QtMultimedia::MediaPlayer::audioOutput
+
+ This property holds the target audio output.
+ Accepts one AudioOutput elements.
- The \a flags argument allows additional requirements such as performance indicators to be
- specified.
+ \sa QMediaPlayer::setAudioOutput()
*/
-QMultimedia::SupportEstimate QMediaPlayer::hasSupport(const QString &mimeType,
- const QStringList& codecs,
- Flags flags)
-{
- return QMediaServiceProvider::defaultServiceProvider()->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER),
- mimeType,
- codecs,
- flags);
-}
+
/*!
- \deprecated
- Returns a list of MIME types supported by the media player.
+ \property QMediaPlayer::audioOutput
+ \brief The audio output device used by the media player.
- The \a flags argument causes the resultant list to be restricted to MIME types which can be supported
- given additional requirements, such as performance indicators.
+ The current audio output to be used when playing back media. Setting
+ a new audio output will replace the currently used output.
- This function may not return useful results on some platforms, and support for a specific file of a
- given mime type is not guaranteed even if the mime type is in general supported. In addition, in some
- cases this function will need to load all available media plugins and query them for their support, which
- may take some time.
+ Setting this property to \c nullptr will disable any audio output.
*/
-QStringList QMediaPlayer::supportedMimeTypes(Flags flags)
+void QMediaPlayer::setAudioOutput(QAudioOutput *output)
+{
+ Q_D(QMediaPlayer);
+ auto oldOutput = d->audioOutput;
+ if (oldOutput == output)
+ return;
+ d->audioOutput = output;
+ if (d->control)
+ d->control->setAudioOutput(nullptr);
+ if (oldOutput)
+ oldOutput->setDisconnectFunction({});
+ if (output) {
+ output->setDisconnectFunction([this](){ setAudioOutput(nullptr); });
+ if (d->control)
+ d->control->setAudioOutput(output->handle());
+ }
+ emit audioOutputChanged();
+}
+
+QAudioOutput *QMediaPlayer::audioOutput() const
{
- return QMediaServiceProvider::defaultServiceProvider()->supportedMimeTypes(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER),
- flags);
+ Q_D(const QMediaPlayer);
+ return d->audioOutput;
}
/*!
- \fn void QMediaPlayer::setVideoOutput(QVideoWidget* output)
+ \qmlproperty list<mediaMetaData> QtMultimedia::MediaPlayer::audioTracks
- Attach a QVideoWidget video \a output to the media player.
+ This property holds a list of metadata.
+ Each index refers to an audio track.
- If the media player has already video output attached,
- it will be replaced with a new one.
+ The metadata holds properties describing the individual tracks. For
+ audio tracks the \l{QMediaMetaData}{Language} is usually the most
+ important property.
+
+ \sa mediaMetaData
*/
-void QMediaPlayer::setVideoOutput(QVideoWidget *output)
-{
- Q_D(QMediaPlayer);
- if (d->videoOutput)
- unbind(d->videoOutput);
+/*!
+ \property QMediaPlayer::audioTracks
+
+ Lists the set of available audio tracks inside the media.
- // We don't know (in this library) that QVideoWidget inherits QObject
- QObject *outputObject = reinterpret_cast<QObject*>(output);
+ The QMediaMetaData returned describes the properties of individual
+ tracks.
- d->videoOutput = outputObject && bind(outputObject) ? outputObject : nullptr;
+ Different audio tracks can for example contain audio in different languages.
+*/
+QList<QMediaMetaData> QMediaPlayer::audioTracks() const
+{
+ Q_D(const QMediaPlayer);
+ return d->trackMetaData(QPlatformMediaPlayer::AudioStream);
}
/*!
- \fn void QMediaPlayer::setVideoOutput(QGraphicsVideoItem* output)
+ \qmlproperty list<mediaMetaData> QtMultimedia::MediaPlayer::videoTracks
- Attach a QGraphicsVideoItem video \a output to the media player.
+ This property holds a list of metadata.
+ Each index refers to a video track.
- If the media player has already video output attached,
- it will be replaced with a new one.
+ The metadata holds properties describing the individual tracks.
+
+ \sa mediaMetaData
*/
-void QMediaPlayer::setVideoOutput(QGraphicsVideoItem *output)
-{
- Q_D(QMediaPlayer);
- if (d->videoOutput)
- unbind(d->videoOutput);
+/*!
+ \property QMediaPlayer::videoTracks
- // We don't know (in this library) that QGraphicsVideoItem (multiply) inherits QObject
- // but QObject inheritance depends on QObject coming first, so try this out.
- QObject *outputObject = reinterpret_cast<QObject*>(output);
+ Lists the set of available video tracks inside the media.
- d->videoOutput = outputObject && bind(outputObject) ? outputObject : nullptr;
+ The QMediaMetaData returned describes the properties of individual
+ tracks.
+*/
+QList<QMediaMetaData> QMediaPlayer::videoTracks() const
+{
+ Q_D(const QMediaPlayer);
+ return d->trackMetaData(QPlatformMediaPlayer::VideoStream);
}
/*!
- Sets a video \a surface as the video output of a media player.
+ \qmlproperty list<mediaMetaData> QtMultimedia::MediaPlayer::subtitleTracks
- If a video output has already been set on the media player the new surface
- will replace it.
+ This property holds a list of metadata.
+ Each index refers to a subtitle track.
+
+ The metadata holds properties describing the individual tracks. For
+ subtitle tracks the \l{QMediaMetaData}{Language} is usually the most
+ important property.
+
+ \sa mediaMetaData
*/
-void QMediaPlayer::setVideoOutput(QAbstractVideoSurface *surface)
+/*!
+ \property QMediaPlayer::subtitleTracks
+
+ Lists the set of available subtitle tracks inside the media.
+
+ The QMediaMetaData returned describes the properties of individual
+ tracks.
+*/
+QList<QMediaMetaData> QMediaPlayer::subtitleTracks() const
{
- Q_D(QMediaPlayer);
+ Q_D(const QMediaPlayer);
+ return d->trackMetaData(QPlatformMediaPlayer::SubtitleStream);
+}
+
+/*!
+ \qmlproperty int QtMultimedia::MediaPlayer::activeAudioTrack
- d->surfaceOutput.setVideoSurface(surface);
+ This property holds the track number of the currently active audio track.
+ Set to \c{-1} to disable audio track.
- if (d->videoOutput != &d->surfaceOutput) {
- if (d->videoOutput)
- unbind(d->videoOutput);
+ The default property value is \c{0}: the first audio track.
+*/
- d->videoOutput = nullptr;
+/*!
+ \property QMediaPlayer::activeAudioTrack
+ \brief Returns the currently active audio track.
- if (surface && bind(&d->surfaceOutput))
- d->videoOutput = &d->surfaceOutput;
- } else if (!surface) {
- //unbind the surfaceOutput if null surface is set
- unbind(&d->surfaceOutput);
- d->videoOutput = nullptr;
- }
+ By default, the first available audio track will be chosen.
+
+ Set \a index to \c -1 to disable all audio tracks.
+*/
+int QMediaPlayer::activeAudioTrack() const
+{
+ Q_D(const QMediaPlayer);
+ return d->control ? d->control->activeTrack(QPlatformMediaPlayer::AudioStream) : 0;
}
/*!
- \since 5.15
- Sets multiple video surfaces as the video output of a media player.
- This allows the media player to render video frames on different surfaces.
-
- All video surfaces must support at least one shared \c QVideoFrame::PixelFormat.
+ \since 6.2
+ \qmlproperty int QtMultimedia::MediaPlayer::activeVideoTrack
- If a video output has already been set on the media player the new surfaces
- will replace it.
+ This property holds the track number of the currently active video audio track.
+ Set to \c{-1} to disable video track.
- \sa QAbstractVideoSurface::supportedPixelFormats
+ The default property value is \c{0}: the first video track.
*/
-void QMediaPlayer::setVideoOutput(const QList<QAbstractVideoSurface *> &surfaces)
+/*!
+ \property QMediaPlayer::activeVideoTrack
+ \brief Returns the currently active video track.
+
+ By default, the first available audio track will be chosen.
+
+ Set \a index to \c -1 to disable all video tracks.
+*/
+int QMediaPlayer::activeVideoTrack() const
{
- setVideoOutput(!surfaces.empty() ? new QVideoSurfaces(surfaces, this) : nullptr);
+ Q_D(const QMediaPlayer);
+ return d->control ? d->control->activeTrack(QPlatformMediaPlayer::VideoStream) : -1;
}
-/*! \reimp */
-QMultimedia::AvailabilityStatus QMediaPlayer::availability() const
+/*!
+ \since 6.2
+ \qmlproperty int QtMultimedia::MediaPlayer::activeSubtitleTrack
+
+ This property holds the track number of the currently active subtitle track.
+ Set to \c{-1} to disable subtitle track.
+
+ The default property value is \c{-1}: no subtitles active.
+*/
+
+/*!
+ \property QMediaPlayer::activeSubtitleTrack
+ \brief Returns the currently active subtitle track.
+
+ Set \a index to \c -1 to disable subtitles.
+
+ Subtitles are disabled by default.
+*/
+int QMediaPlayer::activeSubtitleTrack() const
{
Q_D(const QMediaPlayer);
+ return d->control ? d->control->activeTrack(QPlatformMediaPlayer::SubtitleStream) : -1;
+}
+void QMediaPlayer::setActiveAudioTrack(int index)
+{
+ Q_D(QMediaPlayer);
if (!d->control)
- return QMultimedia::ServiceMissing;
+ return;
- return QMediaObject::availability();
+ if (activeAudioTrack() == index)
+ return;
+ d->control->setActiveTrack(QPlatformMediaPlayer::AudioStream, index);
}
-QAudio::Role QMediaPlayer::audioRole() const
+void QMediaPlayer::setActiveVideoTrack(int index)
{
- Q_D(const QMediaPlayer);
-
- if (d->audioRoleControl != nullptr)
- return d->audioRoleControl->audioRole();
+ Q_D(QMediaPlayer);
+ if (!d->control)
+ return;
- return QAudio::UnknownRole;
+ if (activeVideoTrack() == index)
+ return;
+ d->control->setActiveTrack(QPlatformMediaPlayer::VideoStream, index);
}
-void QMediaPlayer::setAudioRole(QAudio::Role audioRole)
+void QMediaPlayer::setActiveSubtitleTrack(int index)
{
Q_D(QMediaPlayer);
+ if (!d->control)
+ return;
- if (d->audioRoleControl) {
- if (d->customAudioRoleControl != nullptr && d->audioRoleControl->audioRole() != audioRole) {
- d->customAudioRoleControl->setCustomAudioRole(QString());
- }
-
- d->audioRoleControl->setAudioRole(audioRole);
- }
+ if (activeSubtitleTrack() == index)
+ return;
+ d->control->setActiveTrack(QPlatformMediaPlayer::SubtitleStream, index);
}
/*!
- Returns a list of supported audio roles.
+ \qmlproperty VideoOutput QtMultimedia::MediaPlayer::videoOutput
+
+ This property holds the target video output.
+ Accepts one VideoOutput elements.
+
+ \sa QMediaPlayer::setVideoOutput()
+*/
+
+/*!
+ \property QMediaPlayer::videoOutput
+ \brief The video output to be used by the media player.
- If setting the audio role is not supported, an empty list is returned.
+ A media player can only have one video output attached, so
+ setting this property will replace the previously connected
+ video output.
- \since 5.6
- \sa audioRole
+ Setting this property to \c nullptr will disable video output.
*/
-QList<QAudio::Role> QMediaPlayer::supportedAudioRoles() const
+QObject *QMediaPlayer::videoOutput() const
{
Q_D(const QMediaPlayer);
+ return d->videoOutput;
+}
+
+void QMediaPlayer::setVideoOutput(QObject *output)
+{
+ Q_D(QMediaPlayer);
+ if (d->videoOutput == output)
+ return;
- if (d->audioRoleControl)
- return d->audioRoleControl->supportedAudioRoles();
+ auto *sink = qobject_cast<QVideoSink *>(output);
+ if (!sink && output) {
+ auto *mo = output->metaObject();
+ mo->invokeMethod(output, "videoSink", Q_RETURN_ARG(QVideoSink *, sink));
+ }
+ d->videoOutput = output;
+ d->setVideoSink(sink);
+}
- return QList<QAudio::Role>();
+/*!
+ Sets \a sink to be the QVideoSink instance to
+ retrieve video data.
+*/
+void QMediaPlayer::setVideoSink(QVideoSink *sink)
+{
+ Q_D(QMediaPlayer);
+ d->videoOutput = nullptr;
+ d->setVideoSink(sink);
}
-QString QMediaPlayer::customAudioRole() const
+/*!
+ Returns the QVideoSink instance.
+*/
+QVideoSink *QMediaPlayer::videoSink() const
{
Q_D(const QMediaPlayer);
+ return d->videoSink;
+}
- if (audioRole() != QAudio::CustomRole)
- return QString();
- if (d->customAudioRoleControl != nullptr)
- return d->customAudioRoleControl->customAudioRole();
+#if 0
+/*
+ \since 5.15
+ Sets multiple video sinks as the video output of a media player.
+ This allows the media player to render video frames on several outputs.
- return QString();
+ If a video output has already been set on the media player the new surfaces
+ will replace it.
+*/
+void QMediaPlayer::setVideoOutput(const QList<QVideoSink *> &sinks)
+{
+ // ### IMPLEMENT ME
+ Q_UNUSED(sinks);
+// setVideoOutput(!surfaces.empty() ? new QVideoSurfaces(surfaces, this) : nullptr);
}
+#endif
-void QMediaPlayer::setCustomAudioRole(const QString &audioRole)
+/*!
+ Returns true if the media player is supported on this platform.
+*/
+bool QMediaPlayer::isAvailable() const
{
- Q_D(QMediaPlayer);
-
- if (d->customAudioRoleControl) {
- Q_ASSERT(d->audioRoleControl);
- setAudioRole(QAudio::CustomRole);
- d->customAudioRoleControl->setCustomAudioRole(audioRole);
- }
+ Q_D(const QMediaPlayer);
+ return bool(d->control);
}
/*!
- Returns a list of supported custom audio roles. An empty list may
- indicate that the supported custom audio roles aren't known. The
- list may not be complete.
+ \qmlproperty mediaMetaData QtMultimedia::MediaPlayer::metaData
+
+ Returns meta data for the current media used by the media player.
- \since 5.11
- \sa customAudioRole
+ Meta data can contain information such as the title of the video or its creation date.
+
+ \note The Windows implementation provides metadata only for media located on the local file
+ system.
*/
-QStringList QMediaPlayer::supportedCustomAudioRoles() const
-{
- Q_D(const QMediaPlayer);
- if (d->customAudioRoleControl)
- return d->customAudioRoleControl->supportedCustomAudioRoles();
+/*!
+ \property QMediaPlayer::metaData
+
+ Returns meta data for the current media used by the media player.
+
+ Meta data can contain information such as the title of the video or its creation date.
- return QStringList();
+ \note The Windows implementation provides metadata only for media located on the local file
+ system.
+*/
+QMediaMetaData QMediaPlayer::metaData() const
+{
+ Q_D(const QMediaPlayer);
+ return d->control ? d->control->metaData() : QMediaMetaData{};
}
// Enums
/*!
- \enum QMediaPlayer::State
+ \enum QMediaPlayer::PlaybackState
Defines the current state of a media player.
\value StoppedState The media player is not playing content, playback will begin from the start
of the current track.
- \value PlayingState The media player is currently playing content.
+ \value PlayingState The media player is currently playing content. This indicates the same as the \l playing property.
\value PausedState The media player has paused playback, playback of the current track will
resume from the position the player was paused at.
*/
/*!
+ \qmlproperty enumeration QtMultimedia::MediaPlayer::playbackState
+
+ This property holds the state of media playback. It can be one of the following:
+
+ \table
+ \header \li Property value
+ \li Description
+ \row \li PlayingState
+ \li The media is currently playing. This indicates the same as the \l playing property.
+ \row \li PausedState
+ \li Playback of the media has been suspended.
+ \row \li StoppedState
+ \li Playback of the media is yet to begin.
+ \endtable
+*/
+
+/*!
+ \qmlsignal QtMultimedia::MediaPlayer::playbackStateChanged()
+
+ This signal is emitted when the \l playbackState property is altered.
+*/
+
+/*!
+ \qmlsignal QtMultimedia::MediaPlayer::playingChanged()
+
+ This signal is emitted when the \l playing property changes.
+*/
+
+/*!
\enum QMediaPlayer::MediaStatus
Defines the status of a media player's current media.
- \value UnknownMediaStatus The status of the media cannot be determined.
\value NoMedia The is no current media. The player is in the StoppedState.
\value LoadingMedia The current media is being loaded. The player may be in any state.
\value LoadedMedia The current media has been loaded. The player is in the StoppedState.
@@ -1294,6 +1099,54 @@ QStringList QMediaPlayer::supportedCustomAudioRoles() const
*/
/*!
+ \qmlproperty enumeration QtMultimedia::MediaPlayer::mediaStatus
+
+ This property holds the status of media loading. It can be one of the following:
+
+ \table
+ \header
+ \li Property value
+ \li Description
+ \row \li NoMedia
+ \li No media has been set.
+ \row \li LoadingMedia
+ \li The media is currently being loaded.
+ \row \li LoadedMedia
+ \li The media has been loaded.
+ \row \li BufferingMedia
+ \li The media is buffering data.
+ \row \li StalledMedia
+ \li Playback has been interrupted while the media is buffering data.
+ \row \li BufferedMedia
+ \li The media has buffered data.
+ \row \li EndOfMedia
+ \li The media has played to the end.
+ \row \li InvalidMedia
+ \li The media cannot be played.
+ \endtable
+*/
+
+/*!
+ \qmlproperty enumeration QtMultimedia::MediaPlayer::error
+
+ This property holds the error state of the audio. It can be one of the following.
+
+ \table
+ \header \li Value \li Description
+ \row \li NoError
+ \li There is no current error.
+ \row \li ResourceError
+ \li The audio cannot be played due to a problem allocating resources.
+ \row \li FormatError
+ \li The audio format is not supported.
+ \row \li NetworkError
+ \li The audio cannot be played due to network issues.
+ \row \li AccessDeniedError
+ \li The audio cannot be played due to insufficient permissions.
+ \endtable
+*/
+
+/*!
\enum QMediaPlayer::Error
Defines a media player error condition.
@@ -1304,23 +1157,24 @@ QStringList QMediaPlayer::supportedCustomAudioRoles() const
be possible, but without an audio or video component.
\value NetworkError A network error occurred.
\value AccessDeniedError There are not the appropriate permissions to play a media resource.
- \value ServiceMissingError A valid playback service was not found, playback cannot proceed.
- \omitvalue MediaIsPlaylist
*/
-// Signals
/*!
- \fn QMediaPlayer::error(QMediaPlayer::Error error)
+ \qmlsignal QtMultimedia::MediaPlayer::errorOccurred(error, errorString)
- Signals that an \a error condition has occurred.
+ This signal is emitted when an \a error has occurred. The \a errorString
+ parameter may contain more detailed information about the error.
- \sa errorString()
+ \sa QMediaPlayer::Error
*/
/*!
- \fn void QMediaPlayer::stateChanged(State state)
+ \fn QMediaPlayer::errorOccurred(QMediaPlayer::Error error, const QString &errorString)
+
+ Signals that an \a error condition has occurred, with \a errorString
+ containing a description of the error.
- Signal the \a state of the Player object has changed.
+ \sa errorString()
*/
/*!
@@ -1332,19 +1186,9 @@ QStringList QMediaPlayer::supportedCustomAudioRoles() const
*/
/*!
- \fn void QMediaPlayer::mediaChanged(const QMediaContent &media);
+ \fn void QMediaPlayer::sourceChanged(const QUrl &media);
Signals that the media source has been changed to \a media.
-
- \sa media(), currentMediaChanged()
-*/
-
-/*!
- \fn void QMediaPlayer::currentMediaChanged(const QMediaContent &media);
-
- Signals that the current playing content has been changed to \a media.
-
- \sa currentMedia(), mediaChanged()
*/
/*!
@@ -1359,33 +1203,8 @@ QStringList QMediaPlayer::supportedCustomAudioRoles() const
Signals the \a seekable status of the player object has changed.
*/
-/*!
- \fn void QMediaPlayer::audioRoleChanged(QAudio::Role role)
-
- Signals that the audio \a role of the media player has changed.
-
- \since 5.6
-*/
-
-/*!
- \fn void QMediaPlayer::customAudioRoleChanged(const QString &role)
-
- Signals that the audio \a role of the media player has changed.
-
- \since 5.11
-*/
-
// Properties
/*!
- \property QMediaPlayer::state
- \brief the media player's playback state.
-
- By default this property is QMediaPlayer::Stopped
-
- \sa mediaStatus(), play(), pause(), stop()
-*/
-
-/*!
\property QMediaPlayer::error
\brief a string describing the last error condition.
@@ -1393,50 +1212,22 @@ QStringList QMediaPlayer::supportedCustomAudioRoles() const
*/
/*!
- \property QMediaPlayer::media
+ \property QMediaPlayer::source
\brief the active media source being used by the player object.
- The player object will use the QMediaContent for selection of the content to
+ The player object will use the QUrl for selection of the content to
be played.
- By default this property has a null QMediaContent.
+ By default this property has a null QUrl.
- Setting this property to a null QMediaContent will cause the player to discard all
+ Setting this property to a null QUrl will cause the player to discard all
information relating to the current media source and to cease all I/O operations related
to that media.
- \sa QMediaContent, currentMedia()
+ \sa QUrl
*/
/*!
- \property QMediaPlayer::currentMedia
- \brief the current active media content being played by the player object.
- This value could be different from QMediaPlayer::media property if a playlist is used.
- In this case currentMedia indicates the current media content being processed
- by the player, while QMediaPlayer::media property contains the original playlist.
-
- \sa QMediaContent, media()
-*/
-
-/*!
- \property QMediaPlayer::playlist
- \brief the media playlist being used by the player object.
-
- The player object will use the current playlist item for selection of the content to
- be played.
-
- By default this property is set to null.
-
- If the media playlist is used as a source, QMediaPlayer::currentMedia is updated with
- a current playlist item. The current source should be selected with
- QMediaPlaylist::setCurrentIndex(int) instead of QMediaPlayer::setMedia(),
- otherwise the current playlist will be discarded.
-
- \sa QMediaContent
-*/
-
-
-/*!
\property QMediaPlayer::mediaStatus
\brief the status of the current media stream.
@@ -1445,7 +1236,15 @@ QStringList QMediaPlayer::supportedCustomAudioRoles() const
By default this property is QMediaPlayer::NoMedia
- \sa state
+*/
+
+/*!
+ \qmlproperty int QtMultimedia::MediaPlayer::duration
+
+ This property holds the duration of the media in milliseconds.
+
+ If the media doesn't have a fixed duration (a live stream for example) this
+ will be set to \c{0}.
*/
/*!
@@ -1459,40 +1258,47 @@ QStringList QMediaPlayer::supportedCustomAudioRoles() const
*/
/*!
- \property QMediaPlayer::position
- \brief the playback position of the current media.
+ \qmlproperty int QtMultimedia::MediaPlayer::position
The value is the current playback position, expressed in milliseconds since
the beginning of the media. Periodically changes in the position will be
- indicated with the signal positionChanged(), the interval between updates
- can be set with QMediaObject's method setNotifyInterval().
+ indicated with the positionChanged() signal.
+
+ If the \l seekable property is true, this property can be set to milliseconds.
*/
/*!
- \property QMediaPlayer::volume
- \brief the current playback volume.
-
- The playback volume is scaled linearly, ranging from \c 0 (silence) to \c 100 (full volume).
- Values outside this range will be clamped.
+ \property QMediaPlayer::position
+ \brief the playback position of the current media.
- By default the volume is \c 100.
+ The value is the current playback position, expressed in milliseconds since
+ the beginning of the media. Periodically changes in the position will be
+ indicated with the positionChanged() signal.
- UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale
- will produce linear changes in perceived loudness, which is what a user would normally expect
- from a volume control. See QAudio::convertVolume() for more details.
+ If the \l seekable property is true, this property can be set to milliseconds.
*/
/*!
- \property QMediaPlayer::muted
- \brief the muted state of the current media.
+ \qmlproperty real QtMultimedia::MediaPlayer::bufferProgress
- The value will be true if the playback volume is muted; otherwise false.
-*/
+ This property holds how much of the data buffer is currently filled,
+ from \c 0.0 (empty) to \c 1.0 (full).
+
+ Playback can start or resume only when the buffer is entirely filled.
+ When the buffer is filled, \c MediaPlayer.Buffered is true.
+ When buffer progress is between \c 0.0 and \c 1.0, \c MediaPlayer.Buffering
+ is set to \c{true}.
+
+ A value lower than \c 1.0 implies that the property \c MediaPlayer.StalledMedia
+ is \c{true}.
+
+ \sa mediaStatus
+ */
/*!
- \property QMediaPlayer::bufferStatus
+ \property QMediaPlayer::bufferProgress
\brief the percentage of the temporary buffer filled before playback begins or resumes, from
- \c 0 (empty) to \c 100 (full).
+ \c 0. (empty) to \c 1. (full).
When the player object is buffering; this property holds the percentage of
the temporary buffer that is filled. The buffer will need to reach 100%
@@ -1504,24 +1310,9 @@ QStringList QMediaPlayer::supportedCustomAudioRoles() const
*/
/*!
- \property QMediaPlayer::audioAvailable
- \brief the audio availabilty status for the current media.
-
- As the life time of QMediaPlayer can be longer than the playback of one
- QMediaContent, this property may change over time, the
- audioAvailableChanged signal can be used to monitor it's status.
-*/
-
-/*!
- \property QMediaPlayer::videoAvailable
- \brief the video availability status for the current media.
+ \qmlproperty bool QtMultimedia::MediaPlayer::seekable
- If available, the QVideoWidget class can be used to view the video. As the
- life time of QMediaPlayer can be longer than the playback of one
- QMediaContent, this property may change over time, the
- videoAvailableChanged signal can be used to monitor it's status.
-
- \sa QVideoWidget, QMediaContent
+ This property holds whether the \l position of the media can be changed.
*/
/*!
@@ -1534,108 +1325,77 @@ QStringList QMediaPlayer::supportedCustomAudioRoles() const
*/
/*!
- \property QMediaPlayer::playbackRate
- \brief the playback rate of the current media.
+ \qmlproperty bool QtMultimedia::MediaPlayer::playing
+ \since 6.5
- This value is a multiplier applied to the media's standard play rate. By
- default this value is 1.0, indicating that the media is playing at the
- standard pace. Values higher than 1.0 will increase the rate of play.
- Values less than zero can be set and indicate the media should rewind at the
- multiplier of the standard pace.
+ Indicates whether the media is currently playing.
- Not all playback services support change of the playback rate. It is
- framework defined as to the status and quality of audio and video
- while fast forwarding or rewinding.
+ \sa playbackState
*/
/*!
- \property QMediaPlayer::audioRole
- \brief the role of the audio stream played by the media player.
+ \property QMediaPlayer::playing
+ \brief Whether the media is playing.
+ \since 6.5
- It can be set to specify the type of audio being played, allowing the system to make
- appropriate decisions when it comes to volume, routing or post-processing.
-
- The audio role must be set before calling setMedia().
-
- customAudioRole is cleared when this property is set to anything other than
- QAudio::CustomRole.
-
- \since 5.6
- \sa supportedAudioRoles()
+ \sa playbackState, PlayingState
*/
/*!
- \property QMediaPlayer::customAudioRole
- \brief the role of the audio stream played by the media player.
-
- It can be set to specify the type of audio being played when the backend supports
- audio roles unknown to Qt. Specifying a role allows the system to make appropriate
- decisions when it comes to volume, routing or post-processing.
+ \qmlproperty real QtMultimedia::MediaPlayer::playbackRate
- The audio role must be set before calling setMedia().
+ This property holds the rate at which media is played at as a multiple of
+ the normal rate.
- audioRole is set to QAudio::CustomRole when this property is set.
+ For more information, see \l{QMediaPlayer::playbackRate}.
- \since 5.11
- \sa supportedCustomAudioRoles()
+ Defaults to \c{1.0}.
*/
/*!
- \fn void QMediaPlayer::durationChanged(qint64 duration)
-
- Signal the duration of the content has changed to \a duration, expressed in milliseconds.
-*/
+ \property QMediaPlayer::playbackRate
+ \brief the playback rate of the current media.
-/*!
- \fn void QMediaPlayer::positionChanged(qint64 position)
+ This value is a multiplier applied to the media's standard playback
+ rate. By default this value is 1.0, indicating that the media is
+ playing at the standard speed. Values higher than 1.0 will increase
+ the playback speed, while values between 0.0 and 1.0 results in
+ slower playback. Negative playback rates are not supported.
- Signal the position of the content has changed to \a position, expressed in
- milliseconds.
+ Not all playback services support change of the playback rate. It is
+ framework defined as to the status and quality of audio and video
+ while fast forwarding or rewinding.
*/
/*!
- \fn void QMediaPlayer::volumeChanged(int volume)
+ \fn void QMediaPlayer::durationChanged(qint64 duration)
- Signal the playback volume has changed to \a volume.
+ Signals the duration of the content has changed to \a duration, expressed in milliseconds.
*/
/*!
- \fn void QMediaPlayer::mutedChanged(bool muted)
+ \fn void QMediaPlayer::positionChanged(qint64 position)
- Signal the mute state has changed to \a muted.
+ Signals the position of the content has changed to \a position, expressed in
+ milliseconds.
*/
/*!
- \fn void QMediaPlayer::videoAvailableChanged(bool videoAvailable)
+ \fn void QMediaPlayer::hasVideoChanged(bool videoAvailable)
- Signal the availability of visual content has changed to \a videoAvailable.
+ Signals the availability of visual content has changed to \a videoAvailable.
*/
/*!
- \fn void QMediaPlayer::audioAvailableChanged(bool available)
+ \fn void QMediaPlayer::hasAudioChanged(bool available)
Signals the availability of audio content has changed to \a available.
*/
/*!
- \fn void QMediaPlayer::bufferStatusChanged(int percentFilled)
-
- Signal the amount of the local buffer filled as a percentage by \a percentFilled.
-*/
-
-/*!
- \enum QMediaPlayer::Flag
-
- \value LowLatency The player is expected to be used with simple audio formats,
- but playback should start without significant delay.
- Such playback service can be used for beeps, ringtones, etc.
-
- \value StreamPlayback The player is expected to play QIODevice based streams.
- If passed to QMediaPlayer constructor, the service supporting
- streams playback will be chosen.
+ \fn void QMediaPlayer::bufferProgressChanged(float filled)
- \value VideoSurface The player is expected to be able to render to a
- QAbstractVideoSurface \l {setVideoOutput()}{output}.
+ Signals the amount of the local buffer \a filled as a number between 0 and 1.
*/
QT_END_NAMESPACE
diff --git a/src/multimedia/playback/qmediaplayer.h b/src/multimedia/playback/qmediaplayer.h
index 66a60b508..e0d1fec75 100644
--- a/src/multimedia/playback/qmediaplayer.h
+++ b/src/multimedia/playback/qmediaplayer.h
@@ -1,95 +1,69 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMEDIAPLAYER_H
#define QMEDIAPLAYER_H
+#include <QtCore/qobject.h>
+#include <QtCore/qurl.h>
#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmediacontent.h>
#include <QtMultimedia/qmediaenumdebug.h>
-#include <QtMultimedia/qaudio.h>
+#include <QtMultimedia/qtaudio.h>
QT_BEGIN_NAMESPACE
-
-class QAbstractVideoSurface;
-class QMediaPlaylist;
-class QVideoWidget;
-class QGraphicsVideoItem;
+class QVideoSink;
+class QAudioOutput;
+class QAudioDevice;
+class QMediaMetaData;
+class QMediaTimeRange;
+class QAudioBufferOutput;
class QMediaPlayerPrivate;
-class Q_MULTIMEDIA_EXPORT QMediaPlayer : public QMediaObject
+class Q_MULTIMEDIA_EXPORT QMediaPlayer : public QObject
{
Q_OBJECT
- Q_PROPERTY(QMediaContent media READ media WRITE setMedia NOTIFY mediaChanged)
- Q_PROPERTY(QMediaContent currentMedia READ currentMedia NOTIFY currentMediaChanged)
- Q_PROPERTY(QMediaPlaylist* playlist READ playlist WRITE setPlaylist)
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged)
- Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged)
- Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
- Q_PROPERTY(int bufferStatus READ bufferStatus NOTIFY bufferStatusChanged)
- Q_PROPERTY(bool audioAvailable READ isAudioAvailable NOTIFY audioAvailableChanged)
- Q_PROPERTY(bool videoAvailable READ isVideoAvailable NOTIFY videoAvailableChanged)
+ Q_PROPERTY(float bufferProgress READ bufferProgress NOTIFY bufferProgressChanged)
+ Q_PROPERTY(bool hasAudio READ hasAudio NOTIFY hasAudioChanged)
+ Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged)
Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged)
+ Q_PROPERTY(bool playing READ isPlaying NOTIFY playingChanged)
Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged)
- Q_PROPERTY(State state READ state NOTIFY stateChanged)
+ Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged)
+ Q_PROPERTY(PlaybackState playbackState READ playbackState NOTIFY playbackStateChanged)
Q_PROPERTY(MediaStatus mediaStatus READ mediaStatus NOTIFY mediaStatusChanged)
- Q_PROPERTY(QAudio::Role audioRole READ audioRole WRITE setAudioRole NOTIFY audioRoleChanged)
- Q_PROPERTY(QString customAudioRole READ customAudioRole WRITE setCustomAudioRole NOTIFY customAudioRoleChanged)
- Q_PROPERTY(QString error READ errorString)
- Q_ENUMS(State)
- Q_ENUMS(MediaStatus)
- Q_ENUMS(Error)
+ Q_PROPERTY(QMediaMetaData metaData READ metaData NOTIFY metaDataChanged)
+ Q_PROPERTY(Error error READ error NOTIFY errorChanged)
+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
+ Q_PROPERTY(QObject *videoOutput READ videoOutput WRITE setVideoOutput NOTIFY videoOutputChanged)
+ Q_PROPERTY(QAudioOutput *audioOutput READ audioOutput WRITE setAudioOutput NOTIFY
+ audioOutputChanged)
+
+ Q_PROPERTY(QList<QMediaMetaData> audioTracks READ audioTracks NOTIFY tracksChanged)
+ Q_PROPERTY(QList<QMediaMetaData> videoTracks READ videoTracks NOTIFY tracksChanged)
+ Q_PROPERTY(QList<QMediaMetaData> subtitleTracks READ subtitleTracks NOTIFY tracksChanged)
+
+ Q_PROPERTY(int activeAudioTrack READ activeAudioTrack WRITE setActiveAudioTrack NOTIFY
+ activeTracksChanged)
+ Q_PROPERTY(int activeVideoTrack READ activeVideoTrack WRITE setActiveVideoTrack NOTIFY
+ activeTracksChanged)
+ Q_PROPERTY(int activeSubtitleTrack READ activeSubtitleTrack WRITE setActiveSubtitleTrack NOTIFY
+ activeTracksChanged)
public:
- enum State
+ enum PlaybackState
{
StoppedState,
PlayingState,
PausedState
};
+ Q_ENUM(PlaybackState)
enum MediaStatus
{
- UnknownMediaStatus,
NoMedia,
LoadingMedia,
LoadedMedia,
@@ -99,14 +73,7 @@ public:
EndOfMedia,
InvalidMedia
};
-
- enum Flag
- {
- LowLatency = 0x01,
- StreamPlayback = 0x02,
- VideoSurface = 0x04
- };
- Q_DECLARE_FLAGS(Flags, Flag)
+ Q_ENUM(MediaStatus)
enum Error
{
@@ -114,56 +81,72 @@ public:
ResourceError,
FormatError,
NetworkError,
- AccessDeniedError,
- ServiceMissingError,
- MediaIsPlaylist
+ AccessDeniedError
};
+ Q_ENUM(Error)
- explicit QMediaPlayer(QObject *parent = nullptr, Flags flags = Flags());
+ enum Loops
+ {
+ Infinite = -1,
+ Once = 1
+ };
+ Q_ENUM(Loops)
+
+ explicit QMediaPlayer(QObject *parent = nullptr);
~QMediaPlayer();
- static QMultimedia::SupportEstimate hasSupport(const QString &mimeType,
- const QStringList& codecs = QStringList(),
- Flags flags = Flags());
- static QStringList supportedMimeTypes(Flags flags = Flags());
+ QList<QMediaMetaData> audioTracks() const;
+ QList<QMediaMetaData> videoTracks() const;
+ QList<QMediaMetaData> subtitleTracks() const;
+
+ int activeAudioTrack() const;
+ int activeVideoTrack() const;
+ int activeSubtitleTrack() const;
+
+ void setActiveAudioTrack(int index);
+ void setActiveVideoTrack(int index);
+ void setActiveSubtitleTrack(int index);
- void setVideoOutput(QVideoWidget *);
- void setVideoOutput(QGraphicsVideoItem *);
- void setVideoOutput(QAbstractVideoSurface *surface);
- void setVideoOutput(const QList<QAbstractVideoSurface *> &surfaces);
+ void setAudioBufferOutput(QAudioBufferOutput *output);
+ QAudioBufferOutput *audioBufferOutput() const;
- QMediaContent media() const;
- const QIODevice *mediaStream() const;
- QMediaPlaylist *playlist() const;
- QMediaContent currentMedia() const;
+ void setAudioOutput(QAudioOutput *output);
+ QAudioOutput *audioOutput() const;
- State state() const;
+ void setVideoOutput(QObject *);
+ QObject *videoOutput() const;
+
+ void setVideoSink(QVideoSink *sink);
+ QVideoSink *videoSink() const;
+
+ QUrl source() const;
+ const QIODevice *sourceDevice() const;
+
+ PlaybackState playbackState() const;
MediaStatus mediaStatus() const;
qint64 duration() const;
qint64 position() const;
- int volume() const;
- bool isMuted() const;
- bool isAudioAvailable() const;
- bool isVideoAvailable() const;
+ bool hasAudio() const;
+ bool hasVideo() const;
- int bufferStatus() const;
+ float bufferProgress() const;
+ QMediaTimeRange bufferedTimeRange() const;
bool isSeekable() const;
qreal playbackRate() const;
+ bool isPlaying() const;
+
+ int loops() const;
+ void setLoops(int loops);
+
Error error() const;
QString errorString() const;
- QMultimedia::AvailabilityStatus availability() const override;
-
- QAudio::Role audioRole() const;
- void setAudioRole(QAudio::Role audioRole);
- QList<QAudio::Role> supportedAudioRoles() const;
- QString customAudioRole() const;
- void setCustomAudioRole(const QString &audioRole);
- QStringList supportedCustomAudioRoles() const;
+ bool isAvailable() const;
+ QMediaMetaData metaData() const;
public Q_SLOTS:
void play();
@@ -171,63 +154,50 @@ public Q_SLOTS:
void stop();
void setPosition(qint64 position);
- void setVolume(int volume);
- void setMuted(bool muted);
void setPlaybackRate(qreal rate);
- void setMedia(const QMediaContent &media, QIODevice *stream = nullptr);
- void setPlaylist(QMediaPlaylist *playlist);
+ void setSource(const QUrl &source);
+ void setSourceDevice(QIODevice *device, const QUrl &sourceUrl = QUrl());
Q_SIGNALS:
- void mediaChanged(const QMediaContent &media);
- void currentMediaChanged(const QMediaContent &media);
-
- void stateChanged(QMediaPlayer::State newState);
+ void sourceChanged(const QUrl &media);
+ void playbackStateChanged(QMediaPlayer::PlaybackState newState);
void mediaStatusChanged(QMediaPlayer::MediaStatus status);
void durationChanged(qint64 duration);
void positionChanged(qint64 position);
- void volumeChanged(int volume);
- void mutedChanged(bool muted);
- void audioAvailableChanged(bool available);
- void videoAvailableChanged(bool videoAvailable);
+ void hasAudioChanged(bool available);
+ void hasVideoChanged(bool videoAvailable);
- void bufferStatusChanged(int percentFilled);
+ void bufferProgressChanged(float progress);
void seekableChanged(bool seekable);
+ void playingChanged(bool playing);
void playbackRateChanged(qreal rate);
+ void loopsChanged();
- void audioRoleChanged(QAudio::Role role);
- void customAudioRoleChanged(const QString &role);
+ void metaDataChanged();
+ void videoOutputChanged();
+ void audioOutputChanged();
+ void audioBufferOutputChanged();
- void error(QMediaPlayer::Error error);
+ void tracksChanged();
+ void activeTracksChanged();
-public:
- bool bind(QObject *) override;
- void unbind(QObject *) override;
+ void errorChanged();
+ void errorOccurred(QMediaPlayer::Error error, const QString &errorString);
private:
Q_DISABLE_COPY(QMediaPlayer)
Q_DECLARE_PRIVATE(QMediaPlayer)
- Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QMediaPlayer::State))
- Q_PRIVATE_SLOT(d_func(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus))
- Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &))
- Q_PRIVATE_SLOT(d_func(), void _q_updateMedia(const QMediaContent&))
- Q_PRIVATE_SLOT(d_func(), void _q_playlistDestroyed())
- Q_PRIVATE_SLOT(d_func(), void _q_handleMediaChanged(const QMediaContent&))
- Q_PRIVATE_SLOT(d_func(), void _q_handlePlaylistLoaded())
- Q_PRIVATE_SLOT(d_func(), void _q_handlePlaylistLoadFailed())
+ friend class QPlatformMediaPlayer;
};
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QMediaPlayer::State)
-Q_DECLARE_METATYPE(QMediaPlayer::MediaStatus)
-Q_DECLARE_METATYPE(QMediaPlayer::Error)
-
-Q_MEDIA_ENUM_DEBUG(QMediaPlayer, State)
+Q_MEDIA_ENUM_DEBUG(QMediaPlayer, PlaybackState)
Q_MEDIA_ENUM_DEBUG(QMediaPlayer, MediaStatus)
Q_MEDIA_ENUM_DEBUG(QMediaPlayer, Error)
diff --git a/src/multimedia/playback/qmediaplayer_p.h b/src/multimedia/playback/qmediaplayer_p.h
new file mode 100644
index 000000000..3d32d4e68
--- /dev/null
+++ b/src/multimedia/playback/qmediaplayer_p.h
@@ -0,0 +1,90 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QMEDIAPLAYER_P_H
+#define QMEDIAPLAYER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qmediaplayer.h"
+#include "qmediametadata.h"
+#include "qvideosink.h"
+#include "qaudiooutput.h"
+#include "qaudiobufferoutput.h"
+#include <private/qplatformmediaplayer_p.h>
+#include <private/qerrorinfo_p.h>
+
+#include "private/qobject_p.h"
+#include <QtCore/qobject.h>
+#include <QtCore/qpointer.h>
+#include <QtCore/qurl.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qtimer.h>
+
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+class QPlatformMediaPlayer;
+
+class QMediaPlayerPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QMediaPlayer)
+
+public:
+ static QMediaPlayerPrivate *get(QMediaPlayer *session)
+ {
+ return reinterpret_cast<QMediaPlayerPrivate *>(QObjectPrivate::get(session));
+ }
+
+ QMediaPlayerPrivate() = default;
+ QPlatformMediaPlayer *control = nullptr;
+
+ QPointer<QAudioBufferOutput> audioBufferOutput;
+ QPointer<QAudioOutput> audioOutput;
+ QPointer<QVideoSink> videoSink;
+ QPointer<QObject> videoOutput;
+ QUrl qrcMedia;
+ std::unique_ptr<QFile> qrcFile;
+ QUrl source;
+ QIODevice *stream = nullptr;
+
+ QMediaPlayer::PlaybackState state = QMediaPlayer::StoppedState;
+ QErrorInfo<QMediaPlayer::Error> error;
+
+ void setMedia(const QUrl &media, QIODevice *stream = nullptr);
+
+ QList<QMediaMetaData> trackMetaData(QPlatformMediaPlayer::TrackType s) const;
+
+ void setState(QMediaPlayer::PlaybackState state);
+ void setStatus(QMediaPlayer::MediaStatus status);
+ void setError(QMediaPlayer::Error error, const QString &errorString);
+
+ void setVideoSink(QVideoSink *sink)
+ {
+ Q_Q(QMediaPlayer);
+ if (sink == videoSink)
+ return;
+ if (videoSink)
+ videoSink->setSource(nullptr);
+ videoSink = sink;
+ if (sink)
+ sink->setSource(q);
+ if (control)
+ control->setVideoSink(sink);
+ emit q->videoOutputChanged();
+ }
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/playback/qmediaplaylist.cpp b/src/multimedia/playback/qmediaplaylist.cpp
deleted file mode 100644
index 9539a1809..000000000
--- a/src/multimedia/playback/qmediaplaylist.cpp
+++ /dev/null
@@ -1,824 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaplaylist.h"
-#include "qmediaplaylist_p.h"
-#include "qmediaplaylistprovider_p.h"
-#include "qmediaplaylistioplugin_p.h"
-#include "qmedianetworkplaylistprovider_p.h"
-#include "qmediaservice.h"
-#include "qmediaplaylistcontrol_p.h"
-#include "qmediaplayercontrol.h"
-
-#include <QtCore/qlist.h>
-#include <QtCore/qfile.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qcoreevent.h>
-#include <QtCore/qcoreapplication.h>
-
-#include "qmediapluginloader_p.h"
-
-QT_BEGIN_NAMESPACE
-
-Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, playlistIOLoader,
- (QMediaPlaylistIOInterface_iid, QLatin1String("playlistformats"), Qt::CaseInsensitive))
-
-static void qRegisterMediaPlaylistMetaTypes()
-{
- qRegisterMetaType<QMediaPlaylist::Error>();
- qRegisterMetaType<QMediaPlaylist::PlaybackMode>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterMediaPlaylistMetaTypes)
-
-
-/*!
- \class QMediaPlaylist
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_playback
-
-
- \brief The QMediaPlaylist class provides a list of media content to play.
-
- QMediaPlaylist is intended to be used with other media objects,
- like QMediaPlayer.
-
- QMediaPlaylist allows to access the service intrinsic playlist functionality
- if available, otherwise it provides the local memory playlist implementation.
-
- \snippet multimedia-snippets/media.cpp Movie playlist
-
- Depending on playlist source implementation, most of the playlist mutating
- operations can be asynchronous.
-
- \sa QMediaContent
-*/
-
-
-/*!
- \enum QMediaPlaylist::PlaybackMode
-
- The QMediaPlaylist::PlaybackMode describes the order items in playlist are played.
-
- \value CurrentItemOnce The current item is played only once.
-
- \value CurrentItemInLoop The current item is played repeatedly in a loop.
-
- \value Sequential Playback starts from the current and moves through each successive item until the last is reached and then stops.
- The next item is a null item when the last one is currently playing.
-
- \value Loop Playback restarts at the first item after the last has finished playing.
-
- \value Random Play items in random order.
-*/
-
-
-
-/*!
- Create a new playlist object with the given \a parent.
-*/
-
-QMediaPlaylist::QMediaPlaylist(QObject *parent)
- : QObject(parent)
- , d_ptr(new QMediaPlaylistPrivate)
-{
- Q_D(QMediaPlaylist);
-
- d->q_ptr = this;
- d->networkPlaylistControl = new QMediaNetworkPlaylistControl(this);
-
- setMediaObject(nullptr);
-}
-
-/*!
- Destroys the playlist.
- */
-
-QMediaPlaylist::~QMediaPlaylist()
-{
- Q_D(QMediaPlaylist);
-
- if (d->mediaObject)
- d->mediaObject->unbind(this);
-
- delete d_ptr;
-}
-
-/*!
- Returns the QMediaObject instance that this QMediaPlaylist is bound too,
- or 0 otherwise.
-*/
-QMediaObject *QMediaPlaylist::mediaObject() const
-{
- return d_func()->mediaObject;
-}
-
-/*!
- \internal
- If \a mediaObject is null or doesn't have an intrinsic playlist,
- internal local memory playlist source will be created.
-*/
-bool QMediaPlaylist::setMediaObject(QMediaObject *mediaObject)
-{
- Q_D(QMediaPlaylist);
-
- if (mediaObject && mediaObject == d->mediaObject)
- return true;
-
- QMediaService *service = mediaObject
- ? mediaObject->service() : nullptr;
-
- QMediaPlaylistControl *newControl = nullptr;
-
- if (service)
- newControl = qobject_cast<QMediaPlaylistControl*>(service->requestControl(QMediaPlaylistControl_iid));
-
- if (!newControl)
- newControl = d->networkPlaylistControl;
-
- if (d->control != newControl) {
- int removedStart = -1;
- int removedEnd = -1;
- int insertedStart = -1;
- int insertedEnd = -1;
-
- if (d->control) {
- QMediaPlaylistProvider *playlist = d->control->playlistProvider();
- disconnect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)),
- this, SLOT(_q_loadFailed(QMediaPlaylist::Error,QString)));
-
- disconnect(playlist, &QMediaPlaylistProvider::mediaChanged, this, &QMediaPlaylist::mediaChanged);
- disconnect(playlist, &QMediaPlaylistProvider::mediaAboutToBeInserted, this, &QMediaPlaylist::mediaAboutToBeInserted);
- disconnect(playlist, &QMediaPlaylistProvider::mediaInserted, this, &QMediaPlaylist::mediaInserted);
- disconnect(playlist, &QMediaPlaylistProvider::mediaAboutToBeRemoved, this, &QMediaPlaylist::mediaAboutToBeRemoved);
- disconnect(playlist, &QMediaPlaylistProvider::mediaRemoved, this, &QMediaPlaylist::mediaRemoved);
-
- disconnect(playlist, &QMediaPlaylistProvider::loaded, this, &QMediaPlaylist::loaded);
-
- disconnect(d->control, &QMediaPlaylistControl::playbackModeChanged,
- this, &QMediaPlaylist::playbackModeChanged);
- disconnect(d->control, &QMediaPlaylistControl::currentIndexChanged,
- this, &QMediaPlaylist::currentIndexChanged);
- disconnect(d->control, &QMediaPlaylistControl::currentMediaChanged,
- this, &QMediaPlaylist::currentMediaChanged);
-
- // Copy playlist items, sync playback mode and sync current index between
- // old control and new control
- d->syncControls(d->control, newControl,
- &removedStart, &removedEnd,
- &insertedStart, &insertedEnd);
-
- if (d->mediaObject)
- d->mediaObject->service()->releaseControl(d->control);
- }
-
- d->control = newControl;
- QMediaPlaylistProvider *playlist = d->control->playlistProvider();
- connect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)),
- this, SLOT(_q_loadFailed(QMediaPlaylist::Error,QString)));
-
- connect(playlist, &QMediaPlaylistProvider::mediaChanged, this, &QMediaPlaylist::mediaChanged);
- connect(playlist, &QMediaPlaylistProvider::mediaAboutToBeInserted, this, &QMediaPlaylist::mediaAboutToBeInserted);
- connect(playlist, &QMediaPlaylistProvider::mediaInserted, this, &QMediaPlaylist::mediaInserted);
- connect(playlist, &QMediaPlaylistProvider::mediaAboutToBeRemoved, this, &QMediaPlaylist::mediaAboutToBeRemoved);
- connect(playlist, &QMediaPlaylistProvider::mediaRemoved, this, &QMediaPlaylist::mediaRemoved);
-
- connect(playlist, &QMediaPlaylistProvider::loaded, this, &QMediaPlaylist::loaded);
-
- connect(d->control, &QMediaPlaylistControl::playbackModeChanged,
- this, &QMediaPlaylist::playbackModeChanged);
- connect(d->control, &QMediaPlaylistControl::currentIndexChanged,
- this, &QMediaPlaylist::currentIndexChanged);
- connect(d->control, &QMediaPlaylistControl::currentMediaChanged,
- this, &QMediaPlaylist::currentMediaChanged);
-
- if (removedStart != -1 && removedEnd != -1) {
- emit mediaAboutToBeRemoved(removedStart, removedEnd);
- emit mediaRemoved(removedStart, removedEnd);
- }
-
- if (insertedStart != -1 && insertedEnd != -1) {
- emit mediaAboutToBeInserted(insertedStart, insertedEnd);
- emit mediaInserted(insertedStart, insertedEnd);
- }
- }
-
- d->mediaObject = mediaObject;
-
- return true;
-}
-
-/*!
- \property QMediaPlaylist::playbackMode
-
- This property defines the order that items in the playlist are played.
-
- \sa QMediaPlaylist::PlaybackMode
-*/
-
-QMediaPlaylist::PlaybackMode QMediaPlaylist::playbackMode() const
-{
- return d_func()->control->playbackMode();
-}
-
-void QMediaPlaylist::setPlaybackMode(QMediaPlaylist::PlaybackMode mode)
-{
- Q_D(QMediaPlaylist);
- d->control->setPlaybackMode(mode);
-}
-
-/*!
- Returns position of the current media content in the playlist.
-*/
-int QMediaPlaylist::currentIndex() const
-{
- return d_func()->control->currentIndex();
-}
-
-/*!
- Returns the current media content.
-*/
-
-QMediaContent QMediaPlaylist::currentMedia() const
-{
- return d_func()->playlist()->media(currentIndex());
-}
-
-/*!
- Returns the index of the item, which would be current after calling next()
- \a steps times.
-
- Returned value depends on the size of playlist, current position
- and playback mode.
-
- \sa QMediaPlaylist::playbackMode(), previousIndex()
-*/
-int QMediaPlaylist::nextIndex(int steps) const
-{
- return d_func()->control->nextIndex(steps);
-}
-
-/*!
- Returns the index of the item, which would be current after calling previous()
- \a steps times.
-
- \sa QMediaPlaylist::playbackMode(), nextIndex()
-*/
-
-int QMediaPlaylist::previousIndex(int steps) const
-{
- return d_func()->control->previousIndex(steps);
-}
-
-
-/*!
- Returns the number of items in the playlist.
-
- \sa isEmpty()
- */
-int QMediaPlaylist::mediaCount() const
-{
- return d_func()->playlist()->mediaCount();
-}
-
-/*!
- Returns true if the playlist contains no items, otherwise returns false.
-
- \sa mediaCount()
- */
-bool QMediaPlaylist::isEmpty() const
-{
- return mediaCount() == 0;
-}
-
-/*!
- Returns true if the playlist can be modified, otherwise returns false.
-
- \sa mediaCount()
- */
-bool QMediaPlaylist::isReadOnly() const
-{
- return d_func()->playlist()->isReadOnly();
-}
-
-/*!
- Returns the media content at \a index in the playlist.
-*/
-
-QMediaContent QMediaPlaylist::media(int index) const
-{
- return d_func()->playlist()->media(index);
-}
-
-/*!
- Append the media \a content to the playlist.
-
- Returns true if the operation is successful, otherwise returns false.
- */
-bool QMediaPlaylist::addMedia(const QMediaContent &content)
-{
- return d_func()->control->playlistProvider()->addMedia(content);
-}
-
-/*!
- Append multiple media content \a items to the playlist.
-
- Returns true if the operation is successful, otherwise returns false.
- */
-bool QMediaPlaylist::addMedia(const QList<QMediaContent> &items)
-{
- return d_func()->control->playlistProvider()->addMedia(items);
-}
-
-/*!
- Insert the media \a content to the playlist at position \a pos.
-
- Returns true if the operation is successful, otherwise returns false.
-*/
-
-bool QMediaPlaylist::insertMedia(int pos, const QMediaContent &content)
-{
- QMediaPlaylistProvider *playlist = d_func()->playlist();
- return playlist->insertMedia(qBound(0, pos, playlist->mediaCount()), content);
-}
-
-/*!
- Insert multiple media content \a items to the playlist at position \a pos.
-
- Returns true if the operation is successful, otherwise returns false.
-*/
-
-bool QMediaPlaylist::insertMedia(int pos, const QList<QMediaContent> &items)
-{
- QMediaPlaylistProvider *playlist = d_func()->playlist();
- return playlist->insertMedia(qBound(0, pos, playlist->mediaCount()), items);
-}
-
-/*!
- Move the item from position \a from to position \a to.
-
- Returns true if the operation is successful, otherwise false.
-
- \since 5.7
-*/
-bool QMediaPlaylist::moveMedia(int from, int to)
-{
- QMediaPlaylistProvider *playlist = d_func()->playlist();
- return playlist->moveMedia(qBound(0, from, playlist->mediaCount()),
- qBound(0, to, playlist->mediaCount()));
-}
-
-/*!
- Remove the item from the playlist at position \a pos.
-
- Returns true if the operation is successful, otherwise return false.
- */
-bool QMediaPlaylist::removeMedia(int pos)
-{
- QMediaPlaylistProvider *playlist = d_func()->playlist();
- if (pos >= 0 && pos < playlist->mediaCount())
- return playlist->removeMedia(pos);
- else
- return false;
-}
-
-/*!
- Remove items in the playlist from \a start to \a end inclusive.
-
- Returns true if the operation is successful, otherwise return false.
- */
-bool QMediaPlaylist::removeMedia(int start, int end)
-{
- QMediaPlaylistProvider *playlist = d_func()->playlist();
- start = qMax(0, start);
- end = qMin(end, playlist->mediaCount() - 1);
- if (start <= end)
- return playlist->removeMedia(start, end);
- else
- return false;
-}
-
-/*!
- Remove all the items from the playlist.
-
- Returns true if the operation is successful, otherwise return false.
- */
-bool QMediaPlaylist::clear()
-{
- Q_D(QMediaPlaylist);
- return d->playlist()->clear();
-}
-
-bool QMediaPlaylistPrivate::readItems(QMediaPlaylistReader *reader)
-{
- QList<QMediaContent> items;
-
- while (!reader->atEnd())
- items.append(reader->readItem());
-
- return playlist()->addMedia(items);
-}
-
-bool QMediaPlaylistPrivate::writeItems(QMediaPlaylistWriter *writer)
-{
- for (int i=0; i<playlist()->mediaCount(); i++) {
- if (!writer->writeItem(playlist()->media(i)))
- return false;
- }
- writer->close();
- return true;
-}
-
-/*!
- * \internal
- * Copy playlist items, sync playback mode and sync current index between old control and new control
-*/
-void QMediaPlaylistPrivate::syncControls(QMediaPlaylistControl *oldControl, QMediaPlaylistControl *newControl,
- int *removedStart, int *removedEnd,
- int *insertedStart, int *insertedEnd)
-{
- Q_ASSERT(oldControl != NULL && newControl != NULL);
- Q_ASSERT(removedStart != NULL && removedEnd != NULL
- && insertedStart != NULL && insertedEnd != NULL);
-
- QMediaPlaylistProvider *oldPlaylist = oldControl->playlistProvider();
- QMediaPlaylistProvider *newPlaylist = newControl->playlistProvider();
-
- Q_ASSERT(oldPlaylist != NULL && newPlaylist != NULL);
-
- *removedStart = -1;
- *removedEnd = -1;
- *insertedStart = -1;
- *insertedEnd = -1;
-
- if (newPlaylist->isReadOnly()) {
- // we can't transfer the items from the old control.
- // Report these items as removed.
- if (oldPlaylist->mediaCount() > 0) {
- *removedStart = 0;
- *removedEnd = oldPlaylist->mediaCount() - 1;
- }
- // The new control might have some items that can't be cleared.
- // Report these as inserted.
- if (newPlaylist->mediaCount() > 0) {
- *insertedStart = 0;
- *insertedEnd = newPlaylist->mediaCount() - 1;
- }
- } else {
- const int oldPlaylistSize = oldPlaylist->mediaCount();
-
- newPlaylist->clear();
- for (int i = 0; i < oldPlaylistSize; ++i)
- newPlaylist->addMedia(oldPlaylist->media(i));
- }
-
- newControl->setPlaybackMode(oldControl->playbackMode());
- newControl->setCurrentIndex(oldControl->currentIndex());
-}
-
-/*!
- Load playlist using network \a request. If \a format is specified, it is used,
- otherwise format is guessed from playlist name and data.
-
- New items are appended to playlist.
-
- QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully,
- otherwise the playlist emits loadFailed().
-*/
-void QMediaPlaylist::load(const QNetworkRequest &request, const char *format)
-{
- Q_D(QMediaPlaylist);
-
- d->error = NoError;
- d->errorString.clear();
-
- if (d->playlist()->load(request,format))
- return;
-
- if (isReadOnly()) {
- d->error = AccessDeniedError;
- d->errorString = tr("Could not add items to read only playlist.");
- emit loadFailed();
- return;
- }
-
- const auto keys = playlistIOLoader()->keys();
- for (QString const& key : keys) {
- QMediaPlaylistIOInterface* plugin = qobject_cast<QMediaPlaylistIOInterface*>(playlistIOLoader()->instance(key));
- if (plugin && plugin->canRead(request.url(), format)) {
- QMediaPlaylistReader *reader = plugin->createReader(request.url(), QByteArray(format));
- if (reader && d->readItems(reader)) {
- delete reader;
- emit loaded();
- return;
- }
- delete reader;
- }
- }
-
- d->error = FormatNotSupportedError;
- d->errorString = tr("Playlist format is not supported");
- emit loadFailed();
-
- return;
-}
-
-/*!
- Load playlist from \a location. If \a format is specified, it is used,
- otherwise format is guessed from location name and data.
-
- New items are appended to playlist.
-
- QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully,
- otherwise the playlist emits loadFailed().
-*/
-
-void QMediaPlaylist::load(const QUrl &location, const char *format)
-{
- load(QNetworkRequest(location), format);
-}
-
-/*!
- Load playlist from QIODevice \a device. If \a format is specified, it is used,
- otherwise format is guessed from device data.
-
- New items are appended to playlist.
-
- QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully,
- otherwise the playlist emits loadFailed().
-*/
-void QMediaPlaylist::load(QIODevice * device, const char *format)
-{
- Q_D(QMediaPlaylist);
-
- d->error = NoError;
- d->errorString.clear();
-
- if (d->playlist()->load(device,format))
- return;
-
- if (isReadOnly()) {
- d->error = AccessDeniedError;
- d->errorString = tr("Could not add items to read only playlist.");
- emit loadFailed();
- return;
- }
-
- const auto keys = playlistIOLoader()->keys();
- for (QString const& key : keys) {
- QMediaPlaylistIOInterface* plugin = qobject_cast<QMediaPlaylistIOInterface*>(playlistIOLoader()->instance(key));
- if (plugin && plugin->canRead(device,format)) {
- QMediaPlaylistReader *reader = plugin->createReader(device,QByteArray(format));
- if (reader && d->readItems(reader)) {
- delete reader;
- emit loaded();
- return;
- }
- delete reader;
- }
- }
-
- d->error = FormatNotSupportedError;
- d->errorString = tr("Playlist format is not supported");
- emit loadFailed();
-
- return;
-}
-
-/*!
- Save playlist to \a location. If \a format is specified, it is used,
- otherwise format is guessed from location name.
-
- Returns true if playlist was saved successfully, otherwise returns false.
- */
-bool QMediaPlaylist::save(const QUrl &location, const char *format)
-{
- Q_D(QMediaPlaylist);
-
- d->error = NoError;
- d->errorString.clear();
-
- if (d->playlist()->save(location,format))
- return true;
-
- QFile file(location.toLocalFile());
-
- if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
- d->error = AccessDeniedError;
- d->errorString = tr("The file could not be accessed.");
- return false;
- }
-
- return save(&file, format);
-}
-
-/*!
- Save playlist to QIODevice \a device using format \a format.
-
- Returns true if playlist was saved successfully, otherwise returns false.
-*/
-bool QMediaPlaylist::save(QIODevice * device, const char *format)
-{
- Q_D(QMediaPlaylist);
-
- d->error = NoError;
- d->errorString.clear();
-
- if (d->playlist()->save(device,format))
- return true;
-
- const auto keys = playlistIOLoader()->keys();
- for (QString const& key : keys) {
- QMediaPlaylistIOInterface* plugin = qobject_cast<QMediaPlaylistIOInterface*>(playlistIOLoader()->instance(key));
- if (plugin && plugin->canWrite(device,format)) {
- QMediaPlaylistWriter *writer = plugin->createWriter(device,QByteArray(format));
- if (writer && d->writeItems(writer)) {
- delete writer;
- return true;
- }
- delete writer;
- }
- }
-
- d->error = FormatNotSupportedError;
- d->errorString = tr("Playlist format is not supported.");
-
- return false;
-}
-
-/*!
- Returns the last error condition.
-*/
-QMediaPlaylist::Error QMediaPlaylist::error() const
-{
- return d_func()->error;
-}
-
-/*!
- Returns the string describing the last error condition.
-*/
-QString QMediaPlaylist::errorString() const
-{
- return d_func()->errorString;
-}
-
-/*!
- Shuffle items in the playlist.
-*/
-void QMediaPlaylist::shuffle()
-{
- d_func()->playlist()->shuffle();
-}
-
-
-/*!
- Advance to the next media content in playlist.
-*/
-void QMediaPlaylist::next()
-{
- d_func()->control->next();
-}
-
-/*!
- Return to the previous media content in playlist.
-*/
-void QMediaPlaylist::previous()
-{
- d_func()->control->previous();
-}
-
-/*!
- Activate media content from playlist at position \a playlistPosition.
-*/
-
-void QMediaPlaylist::setCurrentIndex(int playlistPosition)
-{
- d_func()->control->setCurrentIndex(playlistPosition);
-}
-
-/*!
- \fn void QMediaPlaylist::mediaInserted(int start, int end)
-
- This signal is emitted after media has been inserted into the playlist.
- The new items are those between \a start and \a end inclusive.
- */
-
-/*!
- \fn void QMediaPlaylist::mediaRemoved(int start, int end)
-
- This signal is emitted after media has been removed from the playlist.
- The removed items are those between \a start and \a end inclusive.
- */
-
-/*!
- \fn void QMediaPlaylist::mediaChanged(int start, int end)
-
- This signal is emitted after media has been changed in the playlist
- between \a start and \a end positions inclusive.
- */
-
-/*!
- \fn void QMediaPlaylist::currentIndexChanged(int position)
-
- Signal emitted when playlist position changed to \a position.
-*/
-
-/*!
- \fn void QMediaPlaylist::playbackModeChanged(QMediaPlaylist::PlaybackMode mode)
-
- Signal emitted when playback mode changed to \a mode.
-*/
-
-/*!
- \fn void QMediaPlaylist::mediaAboutToBeInserted(int start, int end)
-
- Signal emitted when items are to be inserted at \a start and ending at \a end.
-*/
-
-/*!
- \fn void QMediaPlaylist::mediaAboutToBeRemoved(int start, int end)
-
- Signal emitted when item are to be deleted at \a start and ending at \a end.
-*/
-
-/*!
- \fn void QMediaPlaylist::currentMediaChanged(const QMediaContent &content)
-
- Signal emitted when current media changes to \a content.
-*/
-
-/*!
- \property QMediaPlaylist::currentIndex
- \brief Current position.
-*/
-
-/*!
- \property QMediaPlaylist::currentMedia
- \brief Current media content.
-*/
-
-/*!
- \fn QMediaPlaylist::loaded()
-
- Signal emitted when playlist finished loading.
-*/
-
-/*!
- \fn QMediaPlaylist::loadFailed()
-
- Signal emitted if failed to load playlist.
-*/
-
-/*!
- \enum QMediaPlaylist::Error
-
- This enum describes the QMediaPlaylist error codes.
-
- \value NoError No errors.
- \value FormatError Format error.
- \value FormatNotSupportedError Format not supported.
- \value NetworkError Network error.
- \value AccessDeniedError Access denied error.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaplaylist.cpp"
-#include "moc_qmediaplaylist_p.cpp"
diff --git a/src/multimedia/playback/qmediaplaylist.h b/src/multimedia/playback/qmediaplaylist.h
deleted file mode 100644
index 4eb93bd02..000000000
--- a/src/multimedia/playback/qmediaplaylist.h
+++ /dev/null
@@ -1,148 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIAPLAYLIST_H
-#define QMEDIAPLAYLIST_H
-
-#include <QtCore/qobject.h>
-
-#include <QtMultimedia/qmediacontent.h>
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmediabindableinterface.h>
-#include <QtMultimedia/qmediaenumdebug.h>
-
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaPlaylistProvider;
-
-class QMediaPlaylistPrivate;
-class Q_MULTIMEDIA_EXPORT QMediaPlaylist : public QObject, public QMediaBindableInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaBindableInterface)
- Q_PROPERTY(QMediaPlaylist::PlaybackMode playbackMode READ playbackMode WRITE setPlaybackMode NOTIFY playbackModeChanged)
- Q_PROPERTY(QMediaContent currentMedia READ currentMedia NOTIFY currentMediaChanged)
- Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
- Q_ENUMS(PlaybackMode Error)
-
-public:
- enum PlaybackMode { CurrentItemOnce, CurrentItemInLoop, Sequential, Loop, Random };
- enum Error { NoError, FormatError, FormatNotSupportedError, NetworkError, AccessDeniedError };
-
- explicit QMediaPlaylist(QObject *parent = nullptr);
- virtual ~QMediaPlaylist();
-
- QMediaObject *mediaObject() const override;
-
- PlaybackMode playbackMode() const;
- void setPlaybackMode(PlaybackMode mode);
-
- int currentIndex() const;
- QMediaContent currentMedia() const;
-
- int nextIndex(int steps = 1) const;
- int previousIndex(int steps = 1) const;
-
- QMediaContent media(int index) const;
-
- int mediaCount() const;
- bool isEmpty() const;
- bool isReadOnly() const;
-
- bool addMedia(const QMediaContent &content);
- bool addMedia(const QList<QMediaContent> &items);
- bool insertMedia(int index, const QMediaContent &content);
- bool insertMedia(int index, const QList<QMediaContent> &items);
- bool moveMedia(int from, int to);
- bool removeMedia(int pos);
- bool removeMedia(int start, int end);
- bool clear();
-
- void load(const QNetworkRequest &request, const char *format = nullptr);
- void load(const QUrl &location, const char *format = nullptr);
- void load(QIODevice *device, const char *format = nullptr);
-
- bool save(const QUrl &location, const char *format = nullptr);
- bool save(QIODevice * device, const char *format);
-
- Error error() const;
- QString errorString() const;
-
-public Q_SLOTS:
- void shuffle();
-
- void next();
- void previous();
-
- void setCurrentIndex(int index);
-
-Q_SIGNALS:
- void currentIndexChanged(int index);
- void playbackModeChanged(QMediaPlaylist::PlaybackMode mode);
- void currentMediaChanged(const QMediaContent&);
-
- void mediaAboutToBeInserted(int start, int end);
- void mediaInserted(int start, int end);
- void mediaAboutToBeRemoved(int start, int end);
- void mediaRemoved(int start, int end);
- void mediaChanged(int start, int end);
-
- void loaded();
- void loadFailed();
-
-protected:
- bool setMediaObject(QMediaObject *object) override;
- QMediaPlaylistPrivate *d_ptr;
-
-private:
- Q_DECLARE_PRIVATE(QMediaPlaylist)
- Q_PRIVATE_SLOT(d_func(), void _q_loadFailed(QMediaPlaylist::Error, const QString &))
-};
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QMediaPlaylist::PlaybackMode)
-Q_DECLARE_METATYPE(QMediaPlaylist::Error)
-
-Q_MEDIA_ENUM_DEBUG(QMediaPlaylist, PlaybackMode)
-Q_MEDIA_ENUM_DEBUG(QMediaPlaylist, Error)
-
-#endif // QMEDIAPLAYLIST_H
diff --git a/src/multimedia/playback/qmediaplaylist_p.h b/src/multimedia/playback/qmediaplaylist_p.h
deleted file mode 100644
index 16fce00a9..000000000
--- a/src/multimedia/playback/qmediaplaylist_p.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIAPLAYLIST_P_H
-#define QMEDIAPLAYLIST_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qmediaplaylist.h"
-#include "qmediaplaylistcontrol_p.h"
-#include "qmediaplayer.h"
-#include "qmediaplayercontrol.h"
-#include "qmedianetworkplaylistprovider_p.h"
-#include "qmediaobject_p.h"
-
-#include <QtCore/qdebug.h>
-
-#ifdef Q_MOC_RUN
-# pragma Q_MOC_EXPAND_MACROS
-#endif
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaPlaylistControl;
-class QMediaPlaylistProvider;
-class QMediaPlaylistReader;
-class QMediaPlaylistWriter;
-class QMediaPlayerControl;
-
-class QMediaPlaylistPrivate
-{
- Q_DECLARE_PUBLIC(QMediaPlaylist)
-public:
- QMediaPlaylistPrivate()
- :mediaObject(nullptr),
- control(nullptr),
- networkPlaylistControl(nullptr),
- error(QMediaPlaylist::NoError)
- {
- }
-
- virtual ~QMediaPlaylistPrivate() {}
-
- void _q_loadFailed(QMediaPlaylist::Error error, const QString &errorString)
- {
- this->error = error;
- this->errorString = errorString;
-
- emit q_ptr->loadFailed();
- }
-
- void _q_mediaObjectDeleted()
- {
- Q_Q(QMediaPlaylist);
- mediaObject = nullptr;
- if (control != networkPlaylistControl)
- control = nullptr;
- q->setMediaObject(nullptr);
- }
-
- QMediaObject *mediaObject;
-
- QMediaPlaylistControl *control;
- QMediaPlaylistProvider *playlist() const { return control->playlistProvider(); }
-
- QMediaPlaylistControl *networkPlaylistControl;
-
- bool readItems(QMediaPlaylistReader *reader);
- bool writeItems(QMediaPlaylistWriter *writer);
-
- void syncControls(QMediaPlaylistControl *oldControl, QMediaPlaylistControl *newControl,
- int *removedStart, int *removedEnd,
- int *insertedStart, int *insertedEnd);
-
- QMediaPlaylist::Error error;
- QString errorString;
-
- QMediaPlaylist *q_ptr;
-};
-
-
-class QMediaNetworkPlaylistControl : public QMediaPlaylistControl
-{
- Q_OBJECT
-public:
- QMediaNetworkPlaylistControl(QObject *parent)
- :QMediaPlaylistControl(parent)
- {
- QMediaPlaylistProvider *playlist = new QMediaNetworkPlaylistProvider(this);
- m_navigator = new QMediaPlaylistNavigator(playlist,this);
- m_navigator->setPlaybackMode(QMediaPlaylist::Sequential);
-
- connect(m_navigator, SIGNAL(currentIndexChanged(int)), SIGNAL(currentIndexChanged(int)));
- connect(m_navigator, SIGNAL(activated(QMediaContent)), SIGNAL(currentMediaChanged(QMediaContent)));
- connect(m_navigator, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)), SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)));
- }
-
- ~QMediaNetworkPlaylistControl() {}
-
- QMediaPlaylistProvider* playlistProvider() const override { return m_navigator->playlist(); }
- bool setPlaylistProvider(QMediaPlaylistProvider *mediaPlaylist) override
- {
- m_navigator->setPlaylist(mediaPlaylist);
- emit playlistProviderChanged();
- return true;
- }
-
- int currentIndex() const override { return m_navigator->currentIndex(); }
- void setCurrentIndex(int position) override { m_navigator->jump(position); }
- int nextIndex(int steps) const override { return m_navigator->nextIndex(steps); }
- int previousIndex(int steps) const override { return m_navigator->previousIndex(steps); }
-
- void next() override { m_navigator->next(); }
- void previous() override { m_navigator->previous(); }
-
- QMediaPlaylist::PlaybackMode playbackMode() const override { return m_navigator->playbackMode(); }
- void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) override { m_navigator->setPlaybackMode(mode); }
-
-private:
- QMediaPlaylistNavigator *m_navigator;
-};
-
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIAPLAYLIST_P_H
diff --git a/src/multimedia/playback/qmediaplaylistioplugin.cpp b/src/multimedia/playback/qmediaplaylistioplugin.cpp
deleted file mode 100644
index 957c7c79d..000000000
--- a/src/multimedia/playback/qmediaplaylistioplugin.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaplaylistioplugin_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QMediaPlaylistReader
- \internal
-
- \brief The QMediaPlaylistReader class provides an interface for reading a playlist file.
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_playback
-
- \sa QMediaPlaylistIOPlugin
-*/
-
-/*!
- Destroys a media playlist reader.
-*/
-QMediaPlaylistReader::~QMediaPlaylistReader()
-{
-}
-
-/*!
- \fn QMediaPlaylistReader::atEnd() const
-
- Identifies if a playlist reader has reached the end of its input.
-
- Returns true if the reader has reached the end; and false otherwise.
-*/
-
-/*!
- \fn QMediaPlaylistReader::readItem()
-
- Reads an item of media from a playlist file.
-
- Returns the read media, or a null QMediaContent if no more media is available.
-*/
-
-/*!
- \fn QMediaPlaylistReader::close()
-
- Closes a playlist reader's input device.
-*/
-
-/*!
- \class QMediaPlaylistWriter
- \internal
-
- \brief The QMediaPlaylistWriter class provides an interface for writing a playlist file.
-
- \sa QMediaPlaylistIOPlugin
-*/
-
-/*!
- Destroys a media playlist writer.
-*/
-QMediaPlaylistWriter::~QMediaPlaylistWriter()
-{
-}
-
-/*!
- \fn QMediaPlaylistWriter::writeItem(const QMediaContent &media)
-
- Writes an item of \a media to a playlist file.
-
- Returns true if the media was written successfully; and false otherwise.
-*/
-
-/*!
- \fn QMediaPlaylistWriter::close()
-
- Finalizes the writing of a playlist and closes the output device.
-*/
-
-/*!
- \class QMediaPlaylistIOPlugin
- \internal
-
- \brief The QMediaPlaylistIOPlugin class provides an interface for media playlist I/O plug-ins.
-*/
-
-/*!
- Constructs a media playlist I/O plug-in with the given \a parent.
-*/
-QMediaPlaylistIOPlugin::QMediaPlaylistIOPlugin(QObject *parent)
- :QObject(parent)
-{
-}
-
-/*!
- Destroys a media playlist I/O plug-in.
-*/
-QMediaPlaylistIOPlugin::~QMediaPlaylistIOPlugin()
-{
-}
-
-/*!
- \fn QMediaPlaylistIOPlugin::canRead(QIODevice *device, const QByteArray &format) const
-
- Identifies if plug-in can read \a format data from an I/O \a device.
-
- Returns true if the data can be read; and false otherwise.
-*/
-
-/*!
- \fn QMediaPlaylistIOPlugin::canRead(const QUrl& location, const QByteArray &format) const
-
- Identifies if a plug-in can read \a format data from a URL \a location.
-
- Returns true if the data can be read; and false otherwise.
-*/
-
-/*!
- \fn QMediaPlaylistIOPlugin::canWrite(QIODevice *device, const QByteArray &format) const
-
- Identifies if a plug-in can write \a format data to an I/O \a device.
-
- Returns true if the data can be written; and false otherwise.
-*/
-
-/*!
- \fn QMediaPlaylistIOPlugin::createReader(QIODevice *device, const QByteArray &format)
-
- Returns a new QMediaPlaylistReader which reads \a format data from an I/O \a device.
-
- If the device is invalid or the format is unsupported this will return a null pointer.
-*/
-
-/*!
- \fn QMediaPlaylistIOPlugin::createReader(const QUrl& location, const QByteArray &format)
-
- Returns a new QMediaPlaylistReader which reads \a format data from a URL \a location.
-
- If the location or the format is unsupported this will return a null pointer.
-*/
-
-/*!
- \fn QMediaPlaylistIOPlugin::createWriter(QIODevice *device, const QByteArray &format)
-
- Returns a new QMediaPlaylistWriter which writes \a format data to an I/O \a device.
-
- If the device is invalid or the format is unsupported this will return a null pointer.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaplaylistioplugin_p.cpp"
diff --git a/src/multimedia/playback/qmediaplaylistioplugin_p.h b/src/multimedia/playback/qmediaplaylistioplugin_p.h
deleted file mode 100644
index 153679958..000000000
--- a/src/multimedia/playback/qmediaplaylistioplugin_p.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIAPLAYLISTIOPLUGIN_P_H
-#define QMEDIAPLAYLISTIOPLUGIN_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qobject.h>
-#include <QtCore/qplugin.h>
-
-#include <qtmultimediaglobal.h>
-
-#include "qmediacontent.h"
-
-QT_BEGIN_NAMESPACE
-
-class QString;
-class QUrl;
-class QByteArray;
-class QIODevice;
-
-class Q_MULTIMEDIA_EXPORT QMediaPlaylistReader
-{
-public:
- virtual ~QMediaPlaylistReader();
-
- virtual bool atEnd() const = 0;
- virtual QMediaContent readItem() = 0;
- virtual void close() = 0;
-};
-
-class Q_MULTIMEDIA_EXPORT QMediaPlaylistWriter
-{
-public:
- virtual ~QMediaPlaylistWriter();
-
- virtual bool writeItem(const QMediaContent &content) = 0;
- virtual void close() = 0;
-};
-
-struct Q_MULTIMEDIA_EXPORT QMediaPlaylistIOInterface
-{
- virtual bool canRead(QIODevice *device, const QByteArray &format = QByteArray() ) const = 0;
- virtual bool canRead(const QUrl& location, const QByteArray &format = QByteArray()) const = 0;
-
- virtual bool canWrite(QIODevice *device, const QByteArray &format) const = 0;
-
- virtual QMediaPlaylistReader *createReader(QIODevice *device, const QByteArray &format = QByteArray()) = 0;
- virtual QMediaPlaylistReader *createReader(const QUrl& location, const QByteArray &format = QByteArray()) = 0;
-
- virtual QMediaPlaylistWriter *createWriter(QIODevice *device, const QByteArray &format) = 0;
-};
-
-#define QMediaPlaylistIOInterface_iid "org.qt-project.qt.mediaplaylistio/5.0"
-Q_DECLARE_INTERFACE(QMediaPlaylistIOInterface, QMediaPlaylistIOInterface_iid);
-
-class Q_MULTIMEDIA_EXPORT QMediaPlaylistIOPlugin : public QObject, public QMediaPlaylistIOInterface
-{
-Q_OBJECT
-Q_INTERFACES(QMediaPlaylistIOInterface)
-public:
- explicit QMediaPlaylistIOPlugin(QObject *parent = nullptr);
- ~QMediaPlaylistIOPlugin();
-
- bool canRead(QIODevice *device, const QByteArray &format = QByteArray() ) const override = 0;
- bool canRead(const QUrl& location, const QByteArray &format = QByteArray()) const override = 0;
-
- bool canWrite(QIODevice *device, const QByteArray &format) const override = 0;
-
- QMediaPlaylistReader *createReader(QIODevice *device, const QByteArray &format = QByteArray()) override = 0;
- QMediaPlaylistReader *createReader(const QUrl& location, const QByteArray &format = QByteArray()) override = 0;
-
- QMediaPlaylistWriter *createWriter(QIODevice *device, const QByteArray &format) override = 0;
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIAPLAYLISTIOPLUGIN_P_H
diff --git a/src/multimedia/playback/qmediaplaylistnavigator.cpp b/src/multimedia/playback/qmediaplaylistnavigator.cpp
deleted file mode 100644
index 9b25f968a..000000000
--- a/src/multimedia/playback/qmediaplaylistnavigator.cpp
+++ /dev/null
@@ -1,544 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaplaylistnavigator_p.h"
-#include "qmediaplaylistprovider_p.h"
-#include "qmediaplaylist.h"
-#include "qmediaobject_p.h"
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qrandom.h>
-
-QT_BEGIN_NAMESPACE
-
-class QMediaPlaylistNullProvider : public QMediaPlaylistProvider
-{
-public:
- QMediaPlaylistNullProvider() :QMediaPlaylistProvider() {}
- ~QMediaPlaylistNullProvider() {}
- int mediaCount() const override {return 0;}
- QMediaContent media(int) const override { return QMediaContent(); }
-};
-
-Q_GLOBAL_STATIC(QMediaPlaylistNullProvider, _q_nullMediaPlaylist)
-
-class QMediaPlaylistNavigatorPrivate
-{
- Q_DECLARE_NON_CONST_PUBLIC(QMediaPlaylistNavigator)
-public:
- QMediaPlaylistNavigatorPrivate()
- :playlist(nullptr),
- currentPos(-1),
- lastValidPos(-1),
- playbackMode(QMediaPlaylist::Sequential),
- randomPositionsOffset(-1)
- {
- }
-
- QMediaPlaylistProvider *playlist;
- int currentPos;
- int lastValidPos; //to be used with CurrentItemOnce playback mode
- QMediaPlaylist::PlaybackMode playbackMode;
- QMediaContent currentItem;
-
- mutable QList<int> randomModePositions;
- mutable int randomPositionsOffset;
-
- int nextItemPos(int steps = 1) const;
- int previousItemPos(int steps = 1) const;
-
- void _q_mediaInserted(int start, int end);
- void _q_mediaRemoved(int start, int end);
- void _q_mediaChanged(int start, int end);
-
- QMediaPlaylistNavigator *q_ptr;
-};
-
-
-int QMediaPlaylistNavigatorPrivate::nextItemPos(int steps) const
-{
- if (playlist->mediaCount() == 0)
- return -1;
-
- if (steps == 0)
- return currentPos;
-
- switch (playbackMode) {
- case QMediaPlaylist::CurrentItemOnce:
- return /*currentPos == -1 ? lastValidPos :*/ -1;
- case QMediaPlaylist::CurrentItemInLoop:
- return currentPos;
- case QMediaPlaylist::Sequential:
- {
- int nextPos = currentPos+steps;
- return nextPos < playlist->mediaCount() ? nextPos : -1;
- }
- case QMediaPlaylist::Loop:
- return (currentPos+steps) % playlist->mediaCount();
- case QMediaPlaylist::Random:
- {
- //TODO: limit the history size
-
- if (randomPositionsOffset == -1) {
- randomModePositions.clear();
- randomModePositions.append(currentPos);
- randomPositionsOffset = 0;
- }
-
- while (randomModePositions.size() < randomPositionsOffset+steps+1)
- randomModePositions.append(-1);
- int res = randomModePositions[randomPositionsOffset+steps];
- if (res<0 || res >= playlist->mediaCount()) {
- res = QRandomGenerator::global()->bounded(playlist->mediaCount());
- randomModePositions[randomPositionsOffset+steps] = res;
- }
-
- return res;
- }
- }
-
- return -1;
-}
-
-int QMediaPlaylistNavigatorPrivate::previousItemPos(int steps) const
-{
- if (playlist->mediaCount() == 0)
- return -1;
-
- if (steps == 0)
- return currentPos;
-
- switch (playbackMode) {
- case QMediaPlaylist::CurrentItemOnce:
- return /*currentPos == -1 ? lastValidPos :*/ -1;
- case QMediaPlaylist::CurrentItemInLoop:
- return currentPos;
- case QMediaPlaylist::Sequential:
- {
- int prevPos = currentPos == -1 ? playlist->mediaCount() - steps : currentPos - steps;
- return prevPos>=0 ? prevPos : -1;
- }
- case QMediaPlaylist::Loop:
- {
- int prevPos = currentPos - steps;
- while (prevPos<0)
- prevPos += playlist->mediaCount();
- return prevPos;
- }
- case QMediaPlaylist::Random:
- {
- //TODO: limit the history size
-
- if (randomPositionsOffset == -1) {
- randomModePositions.clear();
- randomModePositions.append(currentPos);
- randomPositionsOffset = 0;
- }
-
- while (randomPositionsOffset-steps < 0) {
- randomModePositions.prepend(-1);
- randomPositionsOffset++;
- }
-
- int res = randomModePositions[randomPositionsOffset-steps];
- if (res<0 || res >= playlist->mediaCount()) {
- res = QRandomGenerator::global()->bounded(playlist->mediaCount());
- randomModePositions[randomPositionsOffset-steps] = res;
- }
-
- return res;
- }
- }
-
- return -1;
-}
-
-/*!
- \class QMediaPlaylistNavigator
- \internal
-
- \brief The QMediaPlaylistNavigator class provides navigation for a media playlist.
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_playback
-
- \sa QMediaPlaylist, QMediaPlaylistProvider
-*/
-
-
-/*!
- Constructs a media playlist navigator for a \a playlist.
-
- The \a parent is passed to QObject.
- */
-QMediaPlaylistNavigator::QMediaPlaylistNavigator(QMediaPlaylistProvider *playlist, QObject *parent)
- : QObject(parent)
- , d_ptr(new QMediaPlaylistNavigatorPrivate)
-{
- d_ptr->q_ptr = this;
-
- setPlaylist(playlist ? playlist : _q_nullMediaPlaylist());
-}
-
-/*!
- Destroys a media playlist navigator.
- */
-
-QMediaPlaylistNavigator::~QMediaPlaylistNavigator()
-{
- delete d_ptr;
-}
-
-
-/*! \property QMediaPlaylistNavigator::playbackMode
- Contains the playback mode.
- */
-QMediaPlaylist::PlaybackMode QMediaPlaylistNavigator::playbackMode() const
-{
- return d_func()->playbackMode;
-}
-
-/*!
- Sets the playback \a mode.
- */
-void QMediaPlaylistNavigator::setPlaybackMode(QMediaPlaylist::PlaybackMode mode)
-{
- Q_D(QMediaPlaylistNavigator);
- if (d->playbackMode == mode)
- return;
-
- if (mode == QMediaPlaylist::Random) {
- d->randomPositionsOffset = 0;
- d->randomModePositions.append(d->currentPos);
- } else if (d->playbackMode == QMediaPlaylist::Random) {
- d->randomPositionsOffset = -1;
- d->randomModePositions.clear();
- }
-
- d->playbackMode = mode;
-
- emit playbackModeChanged(mode);
- emit surroundingItemsChanged();
-}
-
-/*!
- Returns the playlist being navigated.
-*/
-
-QMediaPlaylistProvider *QMediaPlaylistNavigator::playlist() const
-{
- return d_func()->playlist;
-}
-
-/*!
- Sets the \a playlist to navigate.
-*/
-void QMediaPlaylistNavigator::setPlaylist(QMediaPlaylistProvider *playlist)
-{
- Q_D(QMediaPlaylistNavigator);
-
- if (d->playlist == playlist)
- return;
-
- if (d->playlist) {
- d->playlist->disconnect(this);
- }
-
- if (playlist) {
- d->playlist = playlist;
- } else {
- //assign to shared readonly null playlist
- d->playlist = _q_nullMediaPlaylist();
- }
-
- connect(d->playlist, SIGNAL(mediaInserted(int,int)), SLOT(_q_mediaInserted(int,int)));
- connect(d->playlist, SIGNAL(mediaRemoved(int,int)), SLOT(_q_mediaRemoved(int,int)));
- connect(d->playlist, SIGNAL(mediaChanged(int,int)), SLOT(_q_mediaChanged(int,int)));
-
- d->randomPositionsOffset = -1;
- d->randomModePositions.clear();
-
- if (d->currentPos != -1) {
- d->currentPos = -1;
- emit currentIndexChanged(-1);
- }
-
- if (!d->currentItem.isNull()) {
- d->currentItem = QMediaContent();
- emit activated(d->currentItem); //stop playback
- }
-}
-
-/*! \property QMediaPlaylistNavigator::currentItem
-
- Contains the media at the current position in the playlist.
-
- \sa currentIndex()
-*/
-
-QMediaContent QMediaPlaylistNavigator::currentItem() const
-{
- return itemAt(d_func()->currentPos);
-}
-
-/*! \fn QMediaContent QMediaPlaylistNavigator::nextItem(int steps) const
-
- Returns the media that is \a steps positions ahead of the current
- position in the playlist.
-
- \sa nextIndex()
-*/
-QMediaContent QMediaPlaylistNavigator::nextItem(int steps) const
-{
- return itemAt(nextIndex(steps));
-}
-
-/*!
- Returns the media that is \a steps positions behind the current
- position in the playlist.
-
- \sa previousIndex()
- */
-QMediaContent QMediaPlaylistNavigator::previousItem(int steps) const
-{
- return itemAt(previousIndex(steps));
-}
-
-/*!
- Returns the media at a \a position in the playlist.
- */
-QMediaContent QMediaPlaylistNavigator::itemAt(int position) const
-{
- return d_func()->playlist->media(position);
-}
-
-/*! \property QMediaPlaylistNavigator::currentIndex
-
- Contains the position of the current media.
-
- If no media is current, the property contains -1.
-
- \sa nextIndex(), previousIndex()
-*/
-
-int QMediaPlaylistNavigator::currentIndex() const
-{
- return d_func()->currentPos;
-}
-
-/*!
- Returns a position \a steps ahead of the current position
- accounting for the playbackMode().
-
- If the position is beyond the end of the playlist, this value
- returned is -1.
-
- \sa currentIndex(), previousIndex(), playbackMode()
-*/
-
-int QMediaPlaylistNavigator::nextIndex(int steps) const
-{
- return d_func()->nextItemPos(steps);
-}
-
-/*!
-
- Returns a position \a steps behind the current position accounting
- for the playbackMode().
-
- If the position is prior to the beginning of the playlist this will
- return -1.
-
- \sa currentIndex(), nextIndex(), playbackMode()
-*/
-int QMediaPlaylistNavigator::previousIndex(int steps) const
-{
- return d_func()->previousItemPos(steps);
-}
-
-/*!
- Advances to the next item in the playlist.
-
- \sa previous(), jump(), playbackMode()
- */
-void QMediaPlaylistNavigator::next()
-{
- Q_D(QMediaPlaylistNavigator);
-
- int nextPos = d->nextItemPos();
-
- if ( playbackMode() == QMediaPlaylist::Random )
- d->randomPositionsOffset++;
-
- jump(nextPos);
-}
-
-/*!
- Returns to the previous item in the playlist,
-
- \sa next(), jump(), playbackMode()
- */
-void QMediaPlaylistNavigator::previous()
-{
- Q_D(QMediaPlaylistNavigator);
-
- int prevPos = d->previousItemPos();
- if ( playbackMode() == QMediaPlaylist::Random )
- d->randomPositionsOffset--;
-
- jump(prevPos);
-}
-
-/*!
- Jumps to a new \a position in the playlist.
- */
-void QMediaPlaylistNavigator::jump(int position)
-{
- Q_D(QMediaPlaylistNavigator);
-
- if (position < -1 || position >= d->playlist->mediaCount())
- position = -1;
-
- if (position != -1)
- d->lastValidPos = position;
-
- if (playbackMode() == QMediaPlaylist::Random) {
- if (d->randomModePositions[d->randomPositionsOffset] != position) {
- d->randomModePositions.clear();
- d->randomModePositions.append(position);
- d->randomPositionsOffset = 0;
- }
- }
-
- if (position != -1)
- d->currentItem = d->playlist->media(position);
- else
- d->currentItem = QMediaContent();
-
- if (position != d->currentPos) {
- d->currentPos = position;
- emit currentIndexChanged(d->currentPos);
- emit surroundingItemsChanged();
- }
-
- emit activated(d->currentItem);
-}
-
-/*!
- \internal
-*/
-void QMediaPlaylistNavigatorPrivate::_q_mediaInserted(int start, int end)
-{
- Q_Q(QMediaPlaylistNavigator);
-
- if (currentPos >= start) {
- currentPos = end-start+1;
- q->jump(currentPos);
- }
-
- //TODO: check if they really changed
- emit q->surroundingItemsChanged();
-}
-
-/*!
- \internal
-*/
-void QMediaPlaylistNavigatorPrivate::_q_mediaRemoved(int start, int end)
-{
- Q_Q(QMediaPlaylistNavigator);
-
- if (currentPos > end) {
- currentPos = currentPos - end-start+1;
- q->jump(currentPos);
- } else if (currentPos >= start) {
- //current item was removed
- currentPos = qMin(start, playlist->mediaCount()-1);
- q->jump(currentPos);
- }
-
- //TODO: check if they really changed
- emit q->surroundingItemsChanged();
-}
-
-/*!
- \internal
-*/
-void QMediaPlaylistNavigatorPrivate::_q_mediaChanged(int start, int end)
-{
- Q_Q(QMediaPlaylistNavigator);
-
- if (currentPos >= start && currentPos<=end) {
- QMediaContent src = playlist->media(currentPos);
- if (src != currentItem) {
- currentItem = src;
- emit q->activated(src);
- }
- }
-
- //TODO: check if they really changed
- emit q->surroundingItemsChanged();
-}
-
-/*!
- \fn QMediaPlaylistNavigator::activated(const QMediaContent &media)
-
- Signals that the current \a media has changed.
-*/
-
-/*!
- \fn QMediaPlaylistNavigator::currentIndexChanged(int position)
-
- Signals the \a position of the current media has changed.
-*/
-
-/*!
- \fn QMediaPlaylistNavigator::playbackModeChanged(QMediaPlaylist::PlaybackMode mode)
-
- Signals that the playback \a mode has changed.
-*/
-
-/*!
- \fn QMediaPlaylistNavigator::surroundingItemsChanged()
-
- Signals that media immediately surrounding the current position has changed.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaplaylistnavigator_p.cpp"
diff --git a/src/multimedia/playback/qmediaplaylistnavigator_p.h b/src/multimedia/playback/qmediaplaylistnavigator_p.h
deleted file mode 100644
index 2ac03a62c..000000000
--- a/src/multimedia/playback/qmediaplaylistnavigator_p.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIAPLAYLISTNAVIGATOR_P_H
-#define QMEDIAPLAYLISTNAVIGATOR_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qmediaplaylistprovider_p.h"
-#include "qmediaplaylist.h"
-#include <QtCore/qobject.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaPlaylistNavigatorPrivate;
-class Q_MULTIMEDIA_EXPORT QMediaPlaylistNavigator : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QMediaPlaylist::PlaybackMode playbackMode READ playbackMode WRITE setPlaybackMode NOTIFY playbackModeChanged)
- Q_PROPERTY(int currentIndex READ currentIndex WRITE jump NOTIFY currentIndexChanged)
- Q_PROPERTY(QMediaContent currentItem READ currentItem)
-
-public:
- QMediaPlaylistNavigator(QMediaPlaylistProvider *playlist, QObject *parent = nullptr);
- virtual ~QMediaPlaylistNavigator();
-
- QMediaPlaylistProvider *playlist() const;
- void setPlaylist(QMediaPlaylistProvider *playlist);
-
- QMediaPlaylist::PlaybackMode playbackMode() const;
-
- QMediaContent currentItem() const;
- QMediaContent nextItem(int steps = 1) const;
- QMediaContent previousItem(int steps = 1) const;
-
- QMediaContent itemAt(int position) const;
-
- int currentIndex() const;
- int nextIndex(int steps = 1) const;
- int previousIndex(int steps = 1) const;
-
-public Q_SLOTS:
- void next();
- void previous();
-
- void jump(int);
-
- void setPlaybackMode(QMediaPlaylist::PlaybackMode mode);
-
-Q_SIGNALS:
- void activated(const QMediaContent &content);
- void currentIndexChanged(int);
- void playbackModeChanged(QMediaPlaylist::PlaybackMode mode);
-
- void surroundingItemsChanged();
-
-protected:
- QMediaPlaylistNavigatorPrivate *d_ptr;
-
-private:
- Q_DISABLE_COPY(QMediaPlaylistNavigator)
- Q_DECLARE_PRIVATE(QMediaPlaylistNavigator)
-
- Q_PRIVATE_SLOT(d_func(), void _q_mediaInserted(int start, int end))
- Q_PRIVATE_SLOT(d_func(), void _q_mediaRemoved(int start, int end))
- Q_PRIVATE_SLOT(d_func(), void _q_mediaChanged(int start, int end))
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIAPLAYLISTNAVIGATOR_P_H
diff --git a/src/multimedia/playback/qmediaplaylistprovider.cpp b/src/multimedia/playback/qmediaplaylistprovider.cpp
deleted file mode 100644
index 8089a9320..000000000
--- a/src/multimedia/playback/qmediaplaylistprovider.cpp
+++ /dev/null
@@ -1,321 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaplaylistprovider_p.h"
-
-#include <QtCore/qurl.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QMediaPlaylistProvider
- \internal
-
- \brief The QMediaPlaylistProvider class provides an abstract list of media.
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_playback
-
- \sa QMediaPlaylist
-*/
-
-/*!
- Constructs a playlist provider with the given \a parent.
-*/
-QMediaPlaylistProvider::QMediaPlaylistProvider(QObject *parent)
- :QObject(parent), d_ptr(new QMediaPlaylistProviderPrivate)
-{
-}
-
-/*!
- \internal
-*/
-QMediaPlaylistProvider::QMediaPlaylistProvider(QMediaPlaylistProviderPrivate &dd, QObject *parent)
- :QObject(parent), d_ptr(&dd)
-{
-}
-
-/*!
- Destroys a playlist provider.
-*/
-QMediaPlaylistProvider::~QMediaPlaylistProvider()
-{
- delete d_ptr;
-}
-
-/*!
- \fn QMediaPlaylistProvider::mediaCount() const;
-
- Returns the size of playlist.
-*/
-
-/*!
- \fn QMediaPlaylistProvider::media(int index) const;
-
- Returns the media at \a index in the playlist.
-
- If the index is invalid this will return a null media content.
-*/
-
-
-/*!
- Loads a playlist using network \a request. If no playlist \a format is specified the loader
- will inspect the URL or probe the headers to guess the format.
-
- New items are appended to playlist.
-
- Returns true if the provider supports the format and loading from the locations URL protocol,
- otherwise this will return false.
-*/
-bool QMediaPlaylistProvider::load(const QNetworkRequest &request, const char *format)
-{
- Q_UNUSED(request);
- Q_UNUSED(format);
- return false;
-}
-
-/*!
- Loads a playlist from from an I/O \a device. If no playlist \a format is specified the loader
- will probe the headers to guess the format.
-
- New items are appended to playlist.
-
- Returns true if the provider supports the format and loading from an I/O device, otherwise this
- will return false.
-*/
-bool QMediaPlaylistProvider::load(QIODevice * device, const char *format)
-{
- Q_UNUSED(device);
- Q_UNUSED(format);
- return false;
-}
-
-/*!
- Saves the contents of a playlist to a URL \a location. If no playlist \a format is specified
- the writer will inspect the URL to guess the format.
-
- Returns true if the playlist was saved successfully; and false otherwise.
- */
-bool QMediaPlaylistProvider::save(const QUrl &location, const char *format)
-{
- Q_UNUSED(location);
- Q_UNUSED(format);
- return false;
-}
-
-/*!
- Saves the contents of a playlist to an I/O \a device in the specified \a format.
-
- Returns true if the playlist was saved successfully; and false otherwise.
-*/
-bool QMediaPlaylistProvider::save(QIODevice * device, const char *format)
-{
- Q_UNUSED(device);
- Q_UNUSED(format);
- return false;
-}
-
-/*!
- Returns true if a playlist is read-only; otherwise returns false.
-*/
-bool QMediaPlaylistProvider::isReadOnly() const
-{
- return true;
-}
-
-/*!
- Append \a media to a playlist.
-
- Returns true if the media was appended; and false otherwise.
-*/
-bool QMediaPlaylistProvider::addMedia(const QMediaContent &media)
-{
- Q_UNUSED(media);
- return false;
-}
-
-/*!
- Append multiple media \a items to a playlist.
-
- Returns true if the media items were appended; and false otherwise.
-*/
-bool QMediaPlaylistProvider::addMedia(const QList<QMediaContent> &items)
-{
- for (const QMediaContent &item : items) {
- if (!addMedia(item))
- return false;
- }
-
- return true;
-}
-
-/*!
- Inserts \a media into a playlist at \a position.
-
- Returns true if the media was inserted; and false otherwise.
-*/
-bool QMediaPlaylistProvider::insertMedia(int position, const QMediaContent &media)
-{
- Q_UNUSED(position);
- Q_UNUSED(media);
- return false;
-}
-
-/*!
- Inserts multiple media \a items into a playlist at \a position.
-
- Returns true if the media \a items were inserted; and false otherwise.
-*/
-bool QMediaPlaylistProvider::insertMedia(int position, const QList<QMediaContent> &items)
-{
- for (int i=0; i<items.count(); i++) {
- if (!insertMedia(position+i,items.at(i)))
- return false;
- }
-
- return true;
-}
-
-/*!
- Move the media from position \a from to position \a to.
-
- Returns true if the operation is successful, otherwise false.
-
- \since 5.7
-*/
-bool QMediaPlaylistProvider::moveMedia(int from, int to)
-{
- Q_UNUSED(from);
- Q_UNUSED(to);
-
- return false;
-}
-
-/*!
- Removes the media at \a position from a playlist.
-
- Returns true if the media was removed; and false otherwise.
-*/
-bool QMediaPlaylistProvider::removeMedia(int position)
-{
- Q_UNUSED(position);
- return false;
-}
-
-/*!
- Removes the media between the given \a start and \a end positions from a playlist.
-
- Returns true if the media was removed; and false otherwise.
- */
-bool QMediaPlaylistProvider::removeMedia(int start, int end)
-{
- for (int pos=end; pos>=start; pos--) {
- if (!removeMedia(pos))
- return false;
- }
-
- return true;
-}
-
-/*!
- Removes all media from a playlist.
-
- Returns true if the media was removed; and false otherwise.
-*/
-bool QMediaPlaylistProvider::clear()
-{
- return removeMedia(0, mediaCount()-1);
-}
-
-/*!
- Shuffles the contents of a playlist.
-*/
-void QMediaPlaylistProvider::shuffle()
-{
-}
-
-/*!
- \fn void QMediaPlaylistProvider::mediaAboutToBeInserted(int start, int end);
-
- Signals that new media is about to be inserted into a playlist between the \a start and \a end
- positions.
-*/
-
-/*!
- \fn void QMediaPlaylistProvider::mediaInserted(int start, int end);
-
- Signals that new media has been inserted into a playlist between the \a start and \a end
- positions.
-*/
-
-/*!
- \fn void QMediaPlaylistProvider::mediaAboutToBeRemoved(int start, int end);
-
- Signals that media is about to be removed from a playlist between the \a start and \a end
- positions.
-*/
-
-/*!
- \fn void QMediaPlaylistProvider::mediaRemoved(int start, int end);
-
- Signals that media has been removed from a playlist between the \a start and \a end positions.
-*/
-
-/*!
- \fn void QMediaPlaylistProvider::mediaChanged(int start, int end);
-
- Signals that media in playlist between the \a start and \a end positions inclusive has changed.
-*/
-
-/*!
- \fn void QMediaPlaylistProvider::loaded()
-
- Signals that a load() finished successfully.
-*/
-
-/*!
- \fn void QMediaPlaylistProvider::loadFailed(QMediaPlaylist::Error error, const QString& errorMessage)
-
- Signals that a load failed() due to an \a error. The \a errorMessage provides more information.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaplaylistprovider_p.cpp"
diff --git a/src/multimedia/playback/qmediaplaylistprovider_p.h b/src/multimedia/playback/qmediaplaylistprovider_p.h
deleted file mode 100644
index ed27612b9..000000000
--- a/src/multimedia/playback/qmediaplaylistprovider_p.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIAPLAYLISTPROVIDER_P_H
-#define QMEDIAPLAYLISTPROVIDER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qmediacontent.h"
-#include "qmediaplaylist.h"
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaPlaylistProviderPrivate
-{
-public:
- QMediaPlaylistProviderPrivate()
- {}
- virtual ~QMediaPlaylistProviderPrivate()
- {}
-};
-
-class Q_MULTIMEDIA_EXPORT QMediaPlaylistProvider : public QObject
-{
-Q_OBJECT
-public:
- QMediaPlaylistProvider(QObject *parent = nullptr);
- virtual ~QMediaPlaylistProvider();
-
- virtual bool load(const QNetworkRequest &request, const char *format = nullptr);
- virtual bool load(QIODevice *device, const char *format = nullptr);
- virtual bool save(const QUrl &location, const char *format = nullptr);
- virtual bool save(QIODevice * device, const char *format);
-
- virtual int mediaCount() const = 0;
- virtual QMediaContent media(int index) const = 0;
-
- virtual bool isReadOnly() const;
-
- virtual bool addMedia(const QMediaContent &content);
- virtual bool addMedia(const QList<QMediaContent> &contentList);
- virtual bool insertMedia(int index, const QMediaContent &content);
- virtual bool insertMedia(int index, const QList<QMediaContent> &content);
- virtual bool moveMedia(int from, int to);
- virtual bool removeMedia(int pos);
- virtual bool removeMedia(int start, int end);
- virtual bool clear();
-
-public Q_SLOTS:
- virtual void shuffle();
-
-Q_SIGNALS:
- void mediaAboutToBeInserted(int start, int end);
- void mediaInserted(int start, int end);
-
- void mediaAboutToBeRemoved(int start, int end);
- void mediaRemoved(int start, int end);
-
- void mediaChanged(int start, int end);
-
- void loaded();
- void loadFailed(QMediaPlaylist::Error, const QString& errorMessage);
-
-protected:
- QMediaPlaylistProviderPrivate *d_ptr;
- QMediaPlaylistProvider(QMediaPlaylistProviderPrivate &dd, QObject *parent);
-
-private:
- Q_DECLARE_PRIVATE(QMediaPlaylistProvider)
-};
-
-QT_END_NAMESPACE
-
-
-
-#endif // QMEDIAPLAYLISTSOURCE_P_H
diff --git a/src/multimedia/playback/qplaylistfileparser.cpp b/src/multimedia/playback/qplaylistfileparser.cpp
deleted file mode 100644
index b60e9778c..000000000
--- a/src/multimedia/playback/qplaylistfileparser.cpp
+++ /dev/null
@@ -1,632 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qplaylistfileparser_p.h"
-#include <qfileinfo.h>
-#include <QtCore/QDebug>
-#include <QtCore/qiodevice.h>
-#include <QtNetwork/QNetworkReply>
-#include <QtNetwork/QNetworkRequest>
-#include "qmediaplayer.h"
-#include "qmediaobject_p.h"
-#include "qmediametadata.h"
-#include "qmediacontent.h"
-
-QT_BEGIN_NAMESPACE
-
-namespace {
-
-class ParserBase
-{
-public:
- explicit ParserBase(QPlaylistFileParser *parent)
- : m_parent(parent)
- , m_aborted(false)
- {
- Q_ASSERT(m_parent);
- }
-
- bool parseLine(int lineIndex, const QString& line, const QUrl& root)
- {
- if (m_aborted)
- return false;
-
- const bool ok = parseLineImpl(lineIndex, line, root);
- return ok && !m_aborted;
- }
-
- virtual void abort() { m_aborted = true; }
- virtual ~ParserBase() { }
-
-protected:
- virtual bool parseLineImpl(int lineIndex, const QString& line, const QUrl& root) = 0;
-
- static QUrl expandToFullPath(const QUrl &root, const QString &line)
- {
- // On Linux, backslashes are not converted to forward slashes :/
- if (line.startsWith(QLatin1String("//")) || line.startsWith(QLatin1String("\\\\"))) {
- // Network share paths are not resolved
- return QUrl::fromLocalFile(line);
- }
-
- QUrl url(line);
- if (url.scheme().isEmpty()) {
- // Resolve it relative to root
- if (root.isLocalFile())
- return QUrl::fromUserInput(line, root.adjusted(QUrl::RemoveFilename).toLocalFile(), QUrl::AssumeLocalFile);
- else
- return root.resolved(url);
- } else if (url.scheme().length() == 1) {
- // Assume it's a drive letter for a Windows path
- url = QUrl::fromLocalFile(line);
- }
-
- return url;
- }
-
- void newItemFound(const QVariant& content) { Q_EMIT m_parent->newItem(content); }
-
-private:
- QPlaylistFileParser *m_parent;
- bool m_aborted;
-};
-
-class M3UParser : public ParserBase
-{
-public:
- explicit M3UParser(QPlaylistFileParser *q)
- : ParserBase(q)
- , m_extendedFormat(false)
- {
- }
-
- /*
- *
- Extended M3U directives
-
- #EXTM3U - header - must be first line of file
- #EXTINF - extra info - length (seconds), title
- #EXTINF - extra info - length (seconds), artist '-' title
-
- Example
-
- #EXTM3U
- #EXTINF:123, Sample artist - Sample title
- C:\Documents and Settings\I\My Music\Sample.mp3
- #EXTINF:321,Example Artist - Example title
- C:\Documents and Settings\I\My Music\Greatest Hits\Example.ogg
-
- */
- bool parseLineImpl(int lineIndex, const QString& line, const QUrl& root) override
- {
- if (line[0] == '#' ) {
- if (m_extendedFormat) {
- if (line.startsWith(QLatin1String("#EXTINF:"))) {
- m_extraInfo.clear();
- int artistStart = line.indexOf(QLatin1String(","), 8);
- bool ok = false;
- QStringView lineView { line };
- int length = lineView.mid(8, artistStart < 8 ? -1 : artistStart - 8).trimmed().toInt(&ok);
- if (ok && length > 0) {
- //convert from second to milisecond
- m_extraInfo[QMediaMetaData::Duration] = QVariant(length * 1000);
- }
- if (artistStart > 0) {
- int titleStart = getSplitIndex(line, artistStart);
- if (titleStart > artistStart) {
- m_extraInfo[QMediaMetaData::Author] = lineView.mid(artistStart + 1,
- titleStart - artistStart - 1).trimmed().toString().
- replace(QLatin1String("--"), QLatin1String("-"));
- m_extraInfo[QMediaMetaData::Title] = lineView.mid(titleStart + 1).trimmed().toString().
- replace(QLatin1String("--"), QLatin1String("-"));
- } else {
- m_extraInfo[QMediaMetaData::Title] = lineView.mid(artistStart + 1).trimmed().toString().
- replace(QLatin1String("--"), QLatin1String("-"));
- }
- }
- }
- } else if (lineIndex == 0 && line.startsWith(QLatin1String("#EXTM3U"))) {
- m_extendedFormat = true;
- }
- } else {
- m_extraInfo[QLatin1String("url")] = expandToFullPath(root, line);
- newItemFound(QVariant(m_extraInfo));
- m_extraInfo.clear();
- }
-
- return true;
- }
-
- int getSplitIndex(const QString& line, int startPos)
- {
- if (startPos < 0)
- startPos = 0;
- const QChar* buf = line.data();
- for (int i = startPos; i < line.length(); ++i) {
- if (buf[i] == '-') {
- if (i == line.length() - 1)
- return i;
- ++i;
- if (buf[i] != '-')
- return i - 1;
- }
- }
- return -1;
- }
-
-private:
- QVariantMap m_extraInfo;
- bool m_extendedFormat;
-};
-
-class PLSParser : public ParserBase
-{
-public:
- explicit PLSParser(QPlaylistFileParser *q)
- : ParserBase(q)
- {
- }
-
-/*
- *
-The format is essentially that of an INI file structured as follows:
-
-Header
-
- * [playlist] : This tag indicates that it is a Playlist File
-
-Track Entry
-Assuming track entry #X
-
- * FileX : Variable defining location of stream.
- * TitleX : Defines track title.
- * LengthX : Length in seconds of track. Value of -1 indicates indefinite.
-
-Footer
-
- * NumberOfEntries : This variable indicates the number of tracks.
- * Version : Playlist version. Currently only a value of 2 is valid.
-
-[playlist]
-
-File1=Alternative\everclear - SMFTA.mp3
-
-Title1=Everclear - So Much For The Afterglow
-
-Length1=233
-
-File2=http://www.site.com:8000/listen.pls
-
-Title2=My Cool Stream
-
-Length5=-1
-
-NumberOfEntries=2
-
-Version=2
-*/
- bool parseLineImpl(int, const QString &line, const QUrl &root) override
- {
- // We ignore everything but 'File' entries, since that's the only thing we care about.
- if (!line.startsWith(QLatin1String("File")))
- return true;
-
- QString value = getValue(line);
- if (value.isEmpty())
- return true;
-
- newItemFound(expandToFullPath(root, value));
-
- return true;
- }
-
- QString getValue(QStringView line) {
- int start = line.indexOf('=');
- if (start < 0)
- return QString();
- return line.mid(start + 1).trimmed().toString();
- }
-};
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////////////
-
-class QPlaylistFileParserPrivate
-{
- Q_DECLARE_PUBLIC(QPlaylistFileParser)
-public:
- QPlaylistFileParserPrivate(QPlaylistFileParser *q)
- : q_ptr(q)
- , m_stream(nullptr)
- , m_type(QPlaylistFileParser::UNKNOWN)
- , m_scanIndex(0)
- , m_lineIndex(-1)
- , m_utf8(false)
- , m_aborted(false)
- {
- }
-
- void handleData();
- void handleParserFinished();
- void abort();
- void reset();
-
- QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> m_source;
- QScopedPointer<ParserBase> m_currentParser;
- QByteArray m_buffer;
- QUrl m_root;
- QNetworkAccessManager m_mgr;
- QString m_mimeType;
- QPlaylistFileParser *q_ptr;
- QIODevice *m_stream;
- QPlaylistFileParser::FileType m_type;
- struct ParserJob
- {
- QIODevice *m_stream;
- QMediaContent m_media;
- QString m_mimeType;
- bool isValid() const { return m_stream || !m_media.isNull(); }
- void reset() { m_stream = nullptr; m_media = QMediaContent(); m_mimeType = QString(); }
- } m_pendingJob;
- int m_scanIndex;
- int m_lineIndex;
- bool m_utf8;
- bool m_aborted;
-
-private:
- bool processLine(int startIndex, int length);
-};
-
-#define LINE_LIMIT 4096
-#define READ_LIMIT 64
-
-bool QPlaylistFileParserPrivate::processLine(int startIndex, int length)
-{
- Q_Q(QPlaylistFileParser);
- m_lineIndex++;
-
- if (!m_currentParser) {
- const QString urlString = m_root.toString();
- const QString &suffix = !urlString.isEmpty() ? QFileInfo(urlString).suffix() : urlString;
- const QString &mimeType = m_source->header(QNetworkRequest::ContentTypeHeader).toString();
- m_type = QPlaylistFileParser::findPlaylistType(suffix, !mimeType.isEmpty() ? mimeType : m_mimeType, m_buffer.constData(), quint32(m_buffer.size()));
-
- switch (m_type) {
- case QPlaylistFileParser::UNKNOWN:
- emit q->error(QPlaylistFileParser::FormatError,
- QPlaylistFileParser::tr("%1 playlist type is unknown").arg(m_root.toString()));
- q->abort();
- return false;
- case QPlaylistFileParser::M3U:
- m_currentParser.reset(new M3UParser(q));
- break;
- case QPlaylistFileParser::M3U8:
- m_currentParser.reset(new M3UParser(q));
- m_utf8 = true;
- break;
- case QPlaylistFileParser::PLS:
- m_currentParser.reset(new PLSParser(q));
- break;
- }
-
- Q_ASSERT(!m_currentParser.isNull());
- }
-
- QString line;
-
- if (m_utf8) {
- line = QString::fromUtf8(m_buffer.constData() + startIndex, length).trimmed();
- } else {
- line = QString::fromLatin1(m_buffer.constData() + startIndex, length).trimmed();
- }
- if (line.isEmpty())
- return true;
-
- Q_ASSERT(m_currentParser);
- return m_currentParser->parseLine(m_lineIndex, line, m_root);
-}
-
-void QPlaylistFileParserPrivate::handleData()
-{
- Q_Q(QPlaylistFileParser);
- while (m_source->bytesAvailable() && !m_aborted) {
- int expectedBytes = qMin(READ_LIMIT, int(qMin(m_source->bytesAvailable(),
- qint64(LINE_LIMIT - m_buffer.size()))));
- m_buffer.push_back(m_source->read(expectedBytes));
- int processedBytes = 0;
- while (m_scanIndex < m_buffer.length() && !m_aborted) {
- char s = m_buffer[m_scanIndex];
- if (s == '\r' || s == '\n') {
- int l = m_scanIndex - processedBytes;
- if (l > 0) {
- if (!processLine(processedBytes, l))
- break;
- }
- processedBytes = m_scanIndex + 1;
- if (!m_source) {
- //some error happened, so exit parsing
- return;
- }
- }
- m_scanIndex++;
- }
-
- if (m_aborted)
- break;
-
- if (m_buffer.length() - processedBytes >= LINE_LIMIT) {
- emit q->error(QPlaylistFileParser::FormatError, QPlaylistFileParser::tr("invalid line in playlist file"));
- q->abort();
- break;
- }
-
- if (m_source->isFinished() && !m_source->bytesAvailable()) {
- //last line
- processLine(processedBytes, -1);
- break;
- }
-
- Q_ASSERT(m_buffer.length() == m_scanIndex);
- if (processedBytes == 0)
- continue;
-
- int copyLength = m_buffer.length() - processedBytes;
- if (copyLength > 0) {
- Q_ASSERT(copyLength <= READ_LIMIT);
- m_buffer = m_buffer.right(copyLength);
- } else {
- m_buffer.clear();
- }
- m_scanIndex = 0;
- }
-
- handleParserFinished();
-}
-
-QPlaylistFileParser::QPlaylistFileParser(QObject *parent)
- : QObject(parent)
- , d_ptr(new QPlaylistFileParserPrivate(this))
-{
-
-}
-
-QPlaylistFileParser::~QPlaylistFileParser()
-{
-
-}
-
-QPlaylistFileParser::FileType QPlaylistFileParser::findByMimeType(const QString &mime)
-{
- if (mime == QLatin1String("text/uri-list") || mime == QLatin1String("audio/x-mpegurl") || mime == QLatin1String("audio/mpegurl"))
- return QPlaylistFileParser::M3U;
-
- if (mime == QLatin1String("application/x-mpegURL") || mime == QLatin1String("application/vnd.apple.mpegurl"))
- return QPlaylistFileParser::M3U8;
-
- if (mime == QLatin1String("audio/x-scpls"))
- return QPlaylistFileParser::PLS;
-
- return QPlaylistFileParser::UNKNOWN;
-}
-
-QPlaylistFileParser::FileType QPlaylistFileParser::findBySuffixType(const QString &suffix)
-{
- const QString &s = suffix.toLower();
-
- if (s == QLatin1String("m3u"))
- return QPlaylistFileParser::M3U;
-
- if (s == QLatin1String("m3u8"))
- return QPlaylistFileParser::M3U8;
-
- if (s == QLatin1String("pls"))
- return QPlaylistFileParser::PLS;
-
- return QPlaylistFileParser::UNKNOWN;
-}
-
-QPlaylistFileParser::FileType QPlaylistFileParser::findByDataHeader(const char *data, quint32 size)
-{
- if (!data || size == 0)
- return QPlaylistFileParser::UNKNOWN;
-
- if (size >= 7 && strncmp(data, "#EXTM3U", 7) == 0)
- return QPlaylistFileParser::M3U;
-
- if (size >= 10 && strncmp(data, "[playlist]", 10) == 0)
- return QPlaylistFileParser::PLS;
-
- return QPlaylistFileParser::UNKNOWN;
-}
-
-QPlaylistFileParser::FileType QPlaylistFileParser::findPlaylistType(const QString& suffix,
- const QString& mime,
- const char *data,
- quint32 size)
-{
-
- FileType dataHeaderType = findByDataHeader(data, size);
- if (dataHeaderType != UNKNOWN)
- return dataHeaderType;
-
- FileType mimeType = findByMimeType(mime);
- if (mimeType != UNKNOWN)
- return mimeType;
-
- FileType suffixType = findBySuffixType(suffix);
- if (suffixType != UNKNOWN)
- return suffixType;
-
- return UNKNOWN;
-}
-
-/*
- * Delegating
- */
-void QPlaylistFileParser::start(const QMediaContent &media, QIODevice *stream, const QString &mimeType)
-{
- if (stream)
- start(stream, mimeType);
- else
- start(media.request(), mimeType);
-}
-
-void QPlaylistFileParser::start(QIODevice *stream, const QString &mimeType)
-{
- Q_D(QPlaylistFileParser);
- const bool validStream = stream ? (stream->isOpen() && stream->isReadable()) : false;
-
- if (!validStream) {
- Q_EMIT error(ResourceError, tr("Invalid stream"));
- return;
- }
-
- if (!d->m_currentParser.isNull()) {
- abort();
- d->m_pendingJob = { stream, QUrl(), mimeType };
- return;
- }
-
- d->reset();
- d->m_mimeType = mimeType;
- d->m_stream = stream;
- connect(d->m_stream, SIGNAL(readyRead()), this, SLOT(_q_handleData()));
- d->handleData();
-}
-
-void QPlaylistFileParser::start(const QNetworkRequest& request, const QString &mimeType)
-{
- Q_D(QPlaylistFileParser);
- const QUrl &url = request.url();
-
- if (url.isLocalFile() && !QFile::exists(url.toLocalFile())) {
- emit error(ResourceError, QString(tr("%1 does not exist")).arg(url.toString()));
- return;
- }
-
- if (!d->m_currentParser.isNull()) {
- abort();
- d->m_pendingJob = { nullptr, request, mimeType };
- return;
- }
-
- d->reset();
- d->m_root = url;
- d->m_mimeType = mimeType;
- d->m_source.reset(d->m_mgr.get(request));
- connect(d->m_source.data(), SIGNAL(readyRead()), this, SLOT(handleData()));
- connect(d->m_source.data(), SIGNAL(finished()), this, SLOT(handleData()));
- connect(d->m_source.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError)), this, SLOT(handleError()));
-
- if (url.isLocalFile())
- d->handleData();
-}
-
-void QPlaylistFileParser::abort()
-{
- Q_D(QPlaylistFileParser);
- d->abort();
-
- if (d->m_source)
- d->m_source->disconnect();
-
- if (d->m_stream)
- disconnect(d->m_stream, SIGNAL(readyRead()), this, SLOT(handleData()));
-}
-
-void QPlaylistFileParser::handleData()
-{
- Q_D(QPlaylistFileParser);
- d->handleData();
-}
-
-void QPlaylistFileParserPrivate::handleParserFinished()
-{
- Q_Q(QPlaylistFileParser);
- const bool isParserValid = !m_currentParser.isNull();
- if (!isParserValid && !m_aborted)
- emit q->error(QPlaylistFileParser::FormatNotSupportedError, QPlaylistFileParser::tr("Empty file provided"));
-
- if (isParserValid && !m_aborted) {
- m_currentParser.reset();
- emit q->finished();
- }
-
- if (!m_aborted)
- q->abort();
-
- if (!m_source.isNull())
- m_source.reset();
-
- if (m_pendingJob.isValid())
- q->start(m_pendingJob.m_media, m_pendingJob.m_stream, m_pendingJob.m_mimeType);
-}
-
-void QPlaylistFileParserPrivate::abort()
-{
- m_aborted = true;
- if (!m_currentParser.isNull())
- m_currentParser->abort();
-}
-
-void QPlaylistFileParserPrivate::reset()
-{
- Q_ASSERT(m_currentParser.isNull());
- Q_ASSERT(m_source.isNull());
- m_buffer.clear();
- m_root.clear();
- m_mimeType.clear();
- m_stream = 0;
- m_type = QPlaylistFileParser::UNKNOWN;
- m_scanIndex = 0;
- m_lineIndex = -1;
- m_utf8 = false;
- m_aborted = false;
- m_pendingJob.reset();
-}
-
-void QPlaylistFileParser::handleError()
-{
- Q_D(QPlaylistFileParser);
- const QString &errorString = d->m_source->errorString();
- Q_EMIT error(QPlaylistFileParser::NetworkError, errorString);
- abort();
-}
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/playback/qplaylistfileparser_p.h b/src/multimedia/playback/qplaylistfileparser_p.h
deleted file mode 100644
index cf96ccdbf..000000000
--- a/src/multimedia/playback/qplaylistfileparser_p.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef PLAYLISTFILEPARSER_P_H
-#define PLAYLISTFILEPARSER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qtmultimediaglobal.h"
-#include <QtCore/qobject.h>
-
-QT_BEGIN_NAMESPACE
-
-class QIODevice;
-class QMediaContent;
-class QNetworkRequest;
-
-class QPlaylistFileParserPrivate;
-
-class Q_MULTIMEDIA_EXPORT QPlaylistFileParser : public QObject
-{
- Q_OBJECT
-public:
- QPlaylistFileParser(QObject *parent = nullptr);
- ~QPlaylistFileParser();
-
- enum FileType
- {
- UNKNOWN,
- M3U,
- M3U8, // UTF-8 version of M3U
- PLS
- };
-
- enum ParserError
- {
- NoError,
- FormatError,
- FormatNotSupportedError,
- ResourceError,
- NetworkError
- };
-
- void start(const QMediaContent &media, QIODevice *stream = nullptr, const QString &mimeType = QString());
- void start(const QNetworkRequest &request, const QString &mimeType = QString());
- void abort();
-
-Q_SIGNALS:
- void newItem(const QVariant& content);
- void finished();
- void error(QPlaylistFileParser::ParserError err, const QString& errorMsg);
-
-private Q_SLOTS:
- void handleData();
- void handleError();
-
-private:
- void start(QIODevice *stream, const QString &mimeType = QString());
-
- static FileType findByMimeType(const QString &mime);
- static FileType findBySuffixType(const QString &suffix);
- static FileType findByDataHeader(const char *data, quint32 size);
- static FileType findPlaylistType(QIODevice *device,
- const QString& mime);
- static FileType findPlaylistType(const QString &suffix,
- const QString& mime,
- const char *data = nullptr,
- quint32 size = 0);
-
- Q_DISABLE_COPY(QPlaylistFileParser)
- Q_DECLARE_PRIVATE(QPlaylistFileParser)
- QScopedPointer<QPlaylistFileParserPrivate> d_ptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // PLAYLISTFILEPARSER_P_H
diff --git a/src/multimedia/pulseaudio/pulseaudio.json b/src/multimedia/pulseaudio/pulseaudio.json
new file mode 100644
index 000000000..5e0336ee8
--- /dev/null
+++ b/src/multimedia/pulseaudio/pulseaudio.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "pulseaudio" ]
+}
diff --git a/src/multimedia/pulseaudio/qaudioengine_pulse.cpp b/src/multimedia/pulseaudio/qaudioengine_pulse.cpp
new file mode 100644
index 000000000..5fac7234a
--- /dev/null
+++ b/src/multimedia/pulseaudio/qaudioengine_pulse.cpp
@@ -0,0 +1,508 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtCore/qdebug.h>
+
+#include <qaudiodevice.h>
+#include <QGuiApplication>
+#include <QIcon>
+#include <QTimer>
+#include "qaudioengine_pulse_p.h"
+#include "qpulseaudiodevice_p.h"
+#include "qpulsehelpers_p.h"
+#include <sys/types.h>
+#include <unistd.h>
+#include <mutex> // for lock_guard
+
+QT_BEGIN_NAMESPACE
+
+template<typename Info>
+static bool updateDevicesMap(QReadWriteLock &lock, QByteArray defaultDeviceId,
+ QMap<int, QAudioDevice> &devices, QAudioDevice::Mode mode,
+ const Info &info)
+{
+ QWriteLocker locker(&lock);
+
+ bool isDefault = defaultDeviceId == info.name;
+ auto newDeviceInfo = std::make_unique<QPulseAudioDeviceInfo>(info.name, info.description, isDefault, mode);
+ newDeviceInfo->channelConfiguration = QPulseAudioInternal::channelConfigFromMap(info.channel_map);
+ newDeviceInfo->preferredFormat = QPulseAudioInternal::sampleSpecToAudioFormat(info.sample_spec);
+ newDeviceInfo->preferredFormat.setChannelConfig(newDeviceInfo->channelConfiguration);
+
+ auto &device = devices[info.index];
+ if (device.handle() && *newDeviceInfo == *device.handle())
+ return false;
+
+ device = newDeviceInfo.release()->create();
+ return true;
+}
+
+static bool updateDevicesMap(QReadWriteLock &lock, QByteArray defaultDeviceId,
+ QMap<int, QAudioDevice> &devices)
+{
+ QWriteLocker locker(&lock);
+
+ bool result = false;
+
+ for (QAudioDevice &device : devices) {
+ auto deviceInfo = device.handle();
+ const auto isDefault = deviceInfo->id == defaultDeviceId;
+ if (deviceInfo->isDefault != isDefault) {
+ Q_ASSERT(dynamic_cast<const QPulseAudioDeviceInfo *>(deviceInfo));
+ auto newDeviceInfo = std::make_unique<QPulseAudioDeviceInfo>(
+ *static_cast<const QPulseAudioDeviceInfo *>(deviceInfo));
+ newDeviceInfo->isDefault = isDefault;
+ device = newDeviceInfo.release()->create();
+ result = true;
+ }
+ }
+
+ return result;
+};
+
+static void serverInfoCallback(pa_context *context, const pa_server_info *info, void *userdata)
+{
+ using namespace Qt::Literals;
+ using namespace QPulseAudioInternal;
+
+ if (!info) {
+ qWarning() << "Failed to get server information:" << currentError(context);
+ return;
+ }
+
+ if (Q_UNLIKELY(qLcPulseAudioEngine().isEnabled(QtDebugMsg))) {
+ char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
+
+ pa_sample_spec_snprint(ss, sizeof(ss), &info->sample_spec);
+ pa_channel_map_snprint(cm, sizeof(cm), &info->channel_map);
+
+ qCDebug(qLcPulseAudioEngine)
+ << QStringLiteral("User name: %1\n"
+ "Host Name: %2\n"
+ "Server Name: %3\n"
+ "Server Version: %4\n"
+ "Default Sample Specification: %5\n"
+ "Default Channel Map: %6\n"
+ "Default Sink: %7\n"
+ "Default Source: %8\n")
+ .arg(QString::fromUtf8(info->user_name),
+ QString::fromUtf8(info->host_name),
+ QString::fromUtf8(info->server_name),
+ QLatin1StringView(info->server_version), QLatin1StringView(ss),
+ QLatin1StringView(cm), QString::fromUtf8(info->default_sink_name),
+ QString::fromUtf8(info->default_source_name));
+ }
+
+ QPulseAudioEngine *pulseEngine = static_cast<QPulseAudioEngine*>(userdata);
+
+ bool defaultSinkChanged = false;
+ bool defaultSourceChanged = false;
+
+ {
+ QWriteLocker locker(&pulseEngine->m_serverLock);
+
+ if (pulseEngine->m_defaultSink != info->default_sink_name) {
+ pulseEngine->m_defaultSink = info->default_sink_name;
+ defaultSinkChanged = true;
+ }
+
+ if (pulseEngine->m_defaultSource != info->default_source_name) {
+ pulseEngine->m_defaultSource = info->default_source_name;
+ defaultSourceChanged = true;
+ }
+ }
+
+ if (defaultSinkChanged
+ && updateDevicesMap(pulseEngine->m_sinkLock, pulseEngine->m_defaultSink,
+ pulseEngine->m_sinks))
+ emit pulseEngine->audioOutputsChanged();
+
+ if (defaultSourceChanged
+ && updateDevicesMap(pulseEngine->m_sourceLock, pulseEngine->m_defaultSource,
+ pulseEngine->m_sources))
+ emit pulseEngine->audioInputsChanged();
+
+ pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
+}
+
+static void sinkInfoCallback(pa_context *context, const pa_sink_info *info, int isLast, void *userdata)
+{
+ using namespace Qt::Literals;
+ using namespace QPulseAudioInternal;
+
+ QPulseAudioEngine *pulseEngine = static_cast<QPulseAudioEngine *>(userdata);
+
+ if (isLast < 0) {
+ qWarning() << "Failed to get sink information:" << currentError(context);
+ return;
+ }
+
+ if (isLast) {
+ pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
+ return;
+ }
+
+ Q_ASSERT(info);
+
+ if (Q_UNLIKELY(qLcPulseAudioEngine().isEnabled(QtDebugMsg))) {
+ static const QMap<pa_sink_state, QString> stateMap{
+ { PA_SINK_INVALID_STATE, u"n/a"_s }, { PA_SINK_RUNNING, u"RUNNING"_s },
+ { PA_SINK_IDLE, u"IDLE"_s }, { PA_SINK_SUSPENDED, u"SUSPENDED"_s },
+ { PA_SINK_UNLINKED, u"UNLINKED"_s },
+ };
+
+ qCDebug(qLcPulseAudioEngine)
+ << QStringLiteral("Sink #%1\n"
+ "\tState: %2\n"
+ "\tName: %3\n"
+ "\tDescription: %4\n")
+ .arg(QString::number(info->index), stateMap.value(info->state),
+ QString::fromUtf8(info->name),
+ QString::fromUtf8(info->description));
+ }
+
+ if (updateDevicesMap(pulseEngine->m_sinkLock, pulseEngine->m_defaultSink, pulseEngine->m_sinks,
+ QAudioDevice::Output, *info))
+ emit pulseEngine->audioOutputsChanged();
+}
+
+static void sourceInfoCallback(pa_context *context, const pa_source_info *info, int isLast, void *userdata)
+{
+ using namespace Qt::Literals;
+
+ Q_UNUSED(context);
+ QPulseAudioEngine *pulseEngine = static_cast<QPulseAudioEngine*>(userdata);
+
+ if (isLast) {
+ pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
+ return;
+ }
+
+ Q_ASSERT(info);
+
+ if (Q_UNLIKELY(qLcPulseAudioEngine().isEnabled(QtDebugMsg))) {
+ static const QMap<pa_source_state, QString> stateMap{
+ { PA_SOURCE_INVALID_STATE, u"n/a"_s }, { PA_SOURCE_RUNNING, u"RUNNING"_s },
+ { PA_SOURCE_IDLE, u"IDLE"_s }, { PA_SOURCE_SUSPENDED, u"SUSPENDED"_s },
+ { PA_SOURCE_UNLINKED, u"UNLINKED"_s },
+ };
+
+ qCDebug(qLcPulseAudioEngine)
+ << QStringLiteral("Source #%1\n"
+ "\tState: %2\n"
+ "\tName: %3\n"
+ "\tDescription: %4\n")
+ .arg(QString::number(info->index), stateMap.value(info->state),
+ QString::fromUtf8(info->name),
+ QString::fromUtf8(info->description));
+ }
+
+ // skip monitor channels
+ if (info->monitor_of_sink != PA_INVALID_INDEX)
+ return;
+
+ if (updateDevicesMap(pulseEngine->m_sourceLock, pulseEngine->m_defaultSource,
+ pulseEngine->m_sources, QAudioDevice::Input, *info))
+ emit pulseEngine->audioInputsChanged();
+}
+
+static void event_cb(pa_context* context, pa_subscription_event_type_t t, uint32_t index, void* userdata)
+{
+ QPulseAudioEngine *pulseEngine = static_cast<QPulseAudioEngine*>(userdata);
+
+ int type = t & PA_SUBSCRIPTION_EVENT_TYPE_MASK;
+ int facility = t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK;
+
+ switch (type) {
+ case PA_SUBSCRIPTION_EVENT_NEW:
+ case PA_SUBSCRIPTION_EVENT_CHANGE:
+ switch (facility) {
+ case PA_SUBSCRIPTION_EVENT_SERVER: {
+ PAOperationUPtr op(pa_context_get_server_info(context, serverInfoCallback, userdata));
+ if (!op)
+ qWarning() << "PulseAudioService: failed to get server info";
+ break;
+ }
+ case PA_SUBSCRIPTION_EVENT_SINK: {
+ PAOperationUPtr op(
+ pa_context_get_sink_info_by_index(context, index, sinkInfoCallback, userdata));
+ if (!op)
+ qWarning() << "PulseAudioService: failed to get sink info";
+ break;
+ }
+ case PA_SUBSCRIPTION_EVENT_SOURCE: {
+ PAOperationUPtr op(pa_context_get_source_info_by_index(context, index,
+ sourceInfoCallback, userdata));
+ if (!op)
+ qWarning() << "PulseAudioService: failed to get source info";
+ break;
+ }
+ default:
+ break;
+ }
+ break;
+ case PA_SUBSCRIPTION_EVENT_REMOVE:
+ switch (facility) {
+ case PA_SUBSCRIPTION_EVENT_SINK: {
+ QWriteLocker locker(&pulseEngine->m_sinkLock);
+ pulseEngine->m_sinks.remove(index);
+ break;
+ }
+ case PA_SUBSCRIPTION_EVENT_SOURCE: {
+ QWriteLocker locker(&pulseEngine->m_sourceLock);
+ pulseEngine->m_sources.remove(index);
+ break;
+ }
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+static void contextStateCallbackInit(pa_context *context, void *userdata)
+{
+ Q_UNUSED(context);
+
+ if (Q_UNLIKELY(qLcPulseAudioEngine().isEnabled(QtDebugMsg)))
+ qCDebug(qLcPulseAudioEngine) << pa_context_get_state(context);
+
+ QPulseAudioEngine *pulseEngine = reinterpret_cast<QPulseAudioEngine*>(userdata);
+ pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
+}
+
+static void contextStateCallback(pa_context *c, void *userdata)
+{
+ QPulseAudioEngine *self = reinterpret_cast<QPulseAudioEngine*>(userdata);
+ pa_context_state_t state = pa_context_get_state(c);
+
+ if (Q_UNLIKELY(qLcPulseAudioEngine().isEnabled(QtDebugMsg)))
+ qCDebug(qLcPulseAudioEngine) << state;
+
+ if (state == PA_CONTEXT_FAILED)
+ QMetaObject::invokeMethod(self, "onContextFailed", Qt::QueuedConnection);
+}
+
+Q_GLOBAL_STATIC(QPulseAudioEngine, pulseEngine);
+
+QPulseAudioEngine::QPulseAudioEngine(QObject *parent)
+ : QObject(parent)
+ , m_mainLoopApi(nullptr)
+ , m_context(nullptr)
+ , m_prepared(false)
+{
+ prepare();
+}
+
+QPulseAudioEngine::~QPulseAudioEngine()
+{
+ if (m_prepared)
+ release();
+}
+
+void QPulseAudioEngine::prepare()
+{
+ using namespace QPulseAudioInternal;
+ bool keepGoing = true;
+ bool ok = true;
+
+ m_mainLoop = pa_threaded_mainloop_new();
+ if (m_mainLoop == nullptr) {
+ qWarning() << "PulseAudioService: unable to create pulseaudio mainloop";
+ return;
+ }
+
+ if (pa_threaded_mainloop_start(m_mainLoop) != 0) {
+ qWarning() << "PulseAudioService: unable to start pulseaudio mainloop";
+ pa_threaded_mainloop_free(m_mainLoop);
+ m_mainLoop = nullptr;
+ return;
+ }
+
+ m_mainLoopApi = pa_threaded_mainloop_get_api(m_mainLoop);
+
+ lock();
+
+ pa_proplist *proplist = pa_proplist_new();
+ if (!QGuiApplication::applicationDisplayName().isEmpty())
+ pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, qUtf8Printable(QGuiApplication::applicationDisplayName()));
+ if (!QGuiApplication::desktopFileName().isEmpty())
+ pa_proplist_sets(proplist, PA_PROP_APPLICATION_ID, qUtf8Printable(QGuiApplication::desktopFileName()));
+ if (const QString windowIconName = QGuiApplication::windowIcon().name(); !windowIconName.isEmpty())
+ pa_proplist_sets(proplist, PA_PROP_WINDOW_ICON_NAME, qUtf8Printable(windowIconName));
+
+ m_context = pa_context_new_with_proplist(m_mainLoopApi, nullptr, proplist);
+ pa_proplist_free(proplist);
+
+ if (m_context == nullptr) {
+ qWarning() << "PulseAudioService: Unable to create new pulseaudio context";
+ pa_threaded_mainloop_unlock(m_mainLoop);
+ pa_threaded_mainloop_free(m_mainLoop);
+ m_mainLoop = nullptr;
+ onContextFailed();
+ return;
+ }
+
+ pa_context_set_state_callback(m_context, contextStateCallbackInit, this);
+
+ if (pa_context_connect(m_context, nullptr, static_cast<pa_context_flags_t>(0), nullptr) < 0) {
+ qWarning() << "PulseAudioService: pa_context_connect() failed";
+ pa_context_unref(m_context);
+ pa_threaded_mainloop_unlock(m_mainLoop);
+ pa_threaded_mainloop_free(m_mainLoop);
+ m_mainLoop = nullptr;
+ m_context = nullptr;
+ return;
+ }
+
+ pa_threaded_mainloop_wait(m_mainLoop);
+
+ while (keepGoing) {
+ switch (pa_context_get_state(m_context)) {
+ case PA_CONTEXT_CONNECTING:
+ case PA_CONTEXT_AUTHORIZING:
+ case PA_CONTEXT_SETTING_NAME:
+ break;
+
+ case PA_CONTEXT_READY:
+ qCDebug(qLcPulseAudioEngine) << "Connection established.";
+ keepGoing = false;
+ break;
+
+ case PA_CONTEXT_TERMINATED:
+ qCritical("PulseAudioService: Context terminated.");
+ keepGoing = false;
+ ok = false;
+ break;
+
+ case PA_CONTEXT_FAILED:
+ default:
+ qCritical() << "PulseAudioService: Connection failure:"
+ << currentError(m_context);
+ keepGoing = false;
+ ok = false;
+ }
+
+ if (keepGoing)
+ pa_threaded_mainloop_wait(m_mainLoop);
+ }
+
+ if (ok) {
+ pa_context_set_state_callback(m_context, contextStateCallback, this);
+
+ pa_context_set_subscribe_callback(m_context, event_cb, this);
+ PAOperationUPtr op(pa_context_subscribe(
+ m_context,
+ pa_subscription_mask_t(PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SOURCE
+ | PA_SUBSCRIPTION_MASK_SERVER),
+ nullptr, nullptr));
+ if (!op)
+ qWarning() << "PulseAudioService: failed to subscribe to context notifications";
+ } else {
+ pa_context_unref(m_context);
+ m_context = nullptr;
+ }
+
+ unlock();
+
+ if (ok) {
+ updateDevices();
+ m_prepared = true;
+ } else {
+ pa_threaded_mainloop_free(m_mainLoop);
+ m_mainLoop = nullptr;
+ onContextFailed();
+ }
+}
+
+void QPulseAudioEngine::release()
+{
+ if (!m_prepared)
+ return;
+
+ if (m_context) {
+ pa_context_disconnect(m_context);
+ pa_context_unref(m_context);
+ m_context = nullptr;
+ }
+
+ if (m_mainLoop) {
+ pa_threaded_mainloop_stop(m_mainLoop);
+ pa_threaded_mainloop_free(m_mainLoop);
+ m_mainLoop = nullptr;
+ }
+
+ m_prepared = false;
+}
+
+void QPulseAudioEngine::updateDevices()
+{
+ std::lock_guard lock(*this);
+
+ // Get default input and output devices
+ PAOperationUPtr operation(pa_context_get_server_info(m_context, serverInfoCallback, this));
+ if (operation) {
+ while (pa_operation_get_state(operation.get()) == PA_OPERATION_RUNNING)
+ pa_threaded_mainloop_wait(m_mainLoop);
+ } else {
+ qWarning() << "PulseAudioService: failed to get server info";
+ }
+
+ // Get output devices
+ operation.reset(pa_context_get_sink_info_list(m_context, sinkInfoCallback, this));
+ if (operation) {
+ while (pa_operation_get_state(operation.get()) == PA_OPERATION_RUNNING)
+ pa_threaded_mainloop_wait(m_mainLoop);
+ } else {
+ qWarning() << "PulseAudioService: failed to get sink info";
+ }
+
+ // Get input devices
+ operation.reset(pa_context_get_source_info_list(m_context, sourceInfoCallback, this));
+ if (operation) {
+ while (pa_operation_get_state(operation.get()) == PA_OPERATION_RUNNING)
+ pa_threaded_mainloop_wait(m_mainLoop);
+ } else {
+ qWarning() << "PulseAudioService: failed to get source info";
+ }
+}
+
+void QPulseAudioEngine::onContextFailed()
+{
+ // Give a chance to the connected slots to still use the Pulse main loop before releasing it.
+ emit contextFailed();
+
+ release();
+
+ // Try to reconnect later
+ QTimer::singleShot(3000, this, &QPulseAudioEngine::prepare);
+}
+
+QPulseAudioEngine *QPulseAudioEngine::instance()
+{
+ return pulseEngine();
+}
+
+QList<QAudioDevice> QPulseAudioEngine::availableDevices(QAudioDevice::Mode mode) const
+{
+ if (mode == QAudioDevice::Output) {
+ QReadLocker locker(&m_sinkLock);
+ return m_sinks.values();
+ }
+
+ if (mode == QAudioDevice::Input) {
+ QReadLocker locker(&m_sourceLock);
+ return m_sources.values();
+ }
+
+ return {};
+}
+
+QByteArray QPulseAudioEngine::defaultDevice(QAudioDevice::Mode mode) const
+{
+ return (mode == QAudioDevice::Output) ? m_defaultSink : m_defaultSource;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/pulseaudio/qaudioengine_pulse_p.h b/src/multimedia/pulseaudio/qaudioengine_pulse_p.h
new file mode 100644
index 000000000..2ed1fa0b1
--- /dev/null
+++ b/src/multimedia/pulseaudio/qaudioengine_pulse_p.h
@@ -0,0 +1,93 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPULSEAUDIOENGINE_H
+#define QPULSEAUDIOENGINE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qmap.h>
+#include <QtCore/qbytearray.h>
+#include <QtCore/qreadwritelock.h>
+#include <pulse/pulseaudio.h>
+#include "qpulsehelpers_p.h"
+#include <qaudioformat.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPulseAudioEngine : public QObject
+{
+ Q_OBJECT
+
+public:
+ QPulseAudioEngine(QObject *parent = 0);
+ ~QPulseAudioEngine();
+
+ static QPulseAudioEngine *instance();
+ pa_threaded_mainloop *mainloop() { return m_mainLoop; }
+ pa_context *context() { return m_context; }
+
+ inline void lock()
+ {
+ if (m_mainLoop)
+ pa_threaded_mainloop_lock(m_mainLoop);
+ }
+
+ inline void unlock()
+ {
+ if (m_mainLoop)
+ pa_threaded_mainloop_unlock(m_mainLoop);
+ }
+
+ inline void wait(pa_operation *op)
+ {
+ while (m_mainLoop && pa_operation_get_state(op) == PA_OPERATION_RUNNING)
+ pa_threaded_mainloop_wait(m_mainLoop);
+ }
+
+ QList<QAudioDevice> availableDevices(QAudioDevice::Mode mode) const;
+ QByteArray defaultDevice(QAudioDevice::Mode mode) const;
+
+Q_SIGNALS:
+ void contextFailed();
+ void audioInputsChanged();
+ void audioOutputsChanged();
+
+private Q_SLOTS:
+ void prepare();
+ void onContextFailed();
+
+private:
+ void updateDevices();
+ void release();
+
+public:
+ QMap<int, QAudioDevice> m_sinks;
+ QMap<int, QAudioDevice> m_sources;
+
+ QByteArray m_defaultSink;
+ QByteArray m_defaultSource;
+
+ mutable QReadWriteLock m_sinkLock;
+ mutable QReadWriteLock m_sourceLock;
+ mutable QReadWriteLock m_serverLock;
+
+private:
+ pa_mainloop_api *m_mainLoopApi;
+ pa_threaded_mainloop *m_mainLoop;
+ pa_context *m_context;
+ bool m_prepared;
+ };
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/pulseaudio/qpulseaudiodevice.cpp b/src/multimedia/pulseaudio/qpulseaudiodevice.cpp
new file mode 100644
index 000000000..487b88f6d
--- /dev/null
+++ b/src/multimedia/pulseaudio/qpulseaudiodevice.cpp
@@ -0,0 +1,46 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qpulseaudiodevice_p.h"
+#include "qaudioengine_pulse_p.h"
+#include "qpulsehelpers_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QPulseAudioDeviceInfo::QPulseAudioDeviceInfo(const char *device, const char *desc, bool isDef, QAudioDevice::Mode mode)
+ : QAudioDevicePrivate(device, mode)
+{
+ description = QString::fromUtf8(desc);
+ isDefault = isDef;
+
+ minimumChannelCount = 1;
+ maximumChannelCount = PA_CHANNELS_MAX;
+ minimumSampleRate = 1;
+ maximumSampleRate = PA_RATE_MAX;
+
+ constexpr bool isBigEndian = QSysInfo::ByteOrder == QSysInfo::BigEndian;
+
+ const struct {
+ pa_sample_format pa_fmt;
+ QAudioFormat::SampleFormat qt_fmt;
+ } formatMap[] = {
+ { PA_SAMPLE_U8, QAudioFormat::UInt8 },
+ { isBigEndian ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE, QAudioFormat::Int16 },
+ { isBigEndian ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE, QAudioFormat::Int32 },
+ { isBigEndian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE, QAudioFormat::Float },
+ };
+
+ for (const auto &f : formatMap) {
+ if (pa_sample_format_valid(f.pa_fmt) != 0)
+ supportedSampleFormats.append(f.qt_fmt);
+ }
+
+ preferredFormat.setChannelCount(2);
+ preferredFormat.setSampleRate(48000);
+ QAudioFormat::SampleFormat f = QAudioFormat::Int16;
+ if (!supportedSampleFormats.contains(f))
+ f = supportedSampleFormats.value(0, QAudioFormat::Unknown);
+ preferredFormat.setSampleFormat(f);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/pulseaudio/qpulseaudiodevice_p.h b/src/multimedia/pulseaudio/qpulseaudiodevice_p.h
new file mode 100644
index 000000000..b44c71e0d
--- /dev/null
+++ b/src/multimedia/pulseaudio/qpulseaudiodevice_p.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAUDIODEVICEINFOPULSE_H
+#define QAUDIODEVICEINFOPULSE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qbytearray.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qlist.h>
+
+#include "qaudio.h"
+#include "qaudiodevice.h"
+#include <private/qaudiosystem_p.h>
+#include <private/qaudiodevice_p.h>
+
+#include <pulse/pulseaudio.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPulseAudioDeviceInfo : public QAudioDevicePrivate
+{
+public:
+ QPulseAudioDeviceInfo(const char *device, const char *description, bool isDefault, QAudioDevice::Mode mode);
+ ~QPulseAudioDeviceInfo() {}
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/multimedia/pulseaudio/qpulseaudiomediadevices.cpp b/src/multimedia/pulseaudio/qpulseaudiomediadevices.cpp
new file mode 100644
index 000000000..4deee6033
--- /dev/null
+++ b/src/multimedia/pulseaudio/qpulseaudiomediadevices.cpp
@@ -0,0 +1,55 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qpulseaudiomediadevices_p.h"
+#include "qmediadevices.h"
+#include "private/qcameradevice_p.h"
+
+#include "qpulseaudiosource_p.h"
+#include "qpulseaudiosink_p.h"
+#include "qpulseaudiodevice_p.h"
+#include "qaudioengine_pulse_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QPulseAudioMediaDevices::QPulseAudioMediaDevices()
+ : QPlatformMediaDevices()
+{
+ pulseEngine = new QPulseAudioEngine();
+
+ // TODO: it might make sense to connect device changing signals
+ // to each added QMediaDevices
+ QObject::connect(pulseEngine, &QPulseAudioEngine::audioInputsChanged,
+ this, &QPulseAudioMediaDevices::audioInputsChanged, Qt::DirectConnection);
+ QObject::connect(pulseEngine, &QPulseAudioEngine::audioOutputsChanged,
+ this, &QPulseAudioMediaDevices::audioOutputsChanged, Qt::DirectConnection);
+}
+
+QPulseAudioMediaDevices::~QPulseAudioMediaDevices()
+{
+ delete pulseEngine;
+}
+
+QList<QAudioDevice> QPulseAudioMediaDevices::audioInputs() const
+{
+ return pulseEngine->availableDevices(QAudioDevice::Input);
+}
+
+QList<QAudioDevice> QPulseAudioMediaDevices::audioOutputs() const
+{
+ return pulseEngine->availableDevices(QAudioDevice::Output);
+}
+
+QPlatformAudioSource *QPulseAudioMediaDevices::createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ return new QPulseAudioSource(deviceInfo.id(), parent);
+}
+
+QPlatformAudioSink *QPulseAudioMediaDevices::createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ return new QPulseAudioSink(deviceInfo.id(), parent);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/pulseaudio/qpulseaudiomediadevices_p.h b/src/multimedia/pulseaudio/qpulseaudiomediadevices_p.h
new file mode 100644
index 000000000..094dc3907
--- /dev/null
+++ b/src/multimedia/pulseaudio/qpulseaudiomediadevices_p.h
@@ -0,0 +1,45 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPULSEAUDIOMEDIADEVICES_H
+#define QPULSEAUDIOMEDIADEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediadevices_p.h>
+#include <qset.h>
+#include <qaudio.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPulseAudioEngine;
+
+class QPulseAudioMediaDevices : public QPlatformMediaDevices
+{
+public:
+ QPulseAudioMediaDevices();
+ ~QPulseAudioMediaDevices();
+
+ QList<QAudioDevice> audioInputs() const override;
+ QList<QAudioDevice> audioOutputs() const override;
+ QPlatformAudioSource *createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+ QPlatformAudioSink *createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+
+private:
+ QPulseAudioEngine *pulseEngine;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/pulseaudio/qpulseaudiosink.cpp b/src/multimedia/pulseaudio/qpulseaudiosink.cpp
new file mode 100644
index 000000000..610677eeb
--- /dev/null
+++ b/src/multimedia/pulseaudio/qpulseaudiosink.cpp
@@ -0,0 +1,749 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qmath.h>
+#include <private/qaudiohelpers_p.h>
+
+#include "qpulseaudiosink_p.h"
+#include "qaudioengine_pulse_p.h"
+#include "qpulsehelpers_p.h"
+#include <sys/types.h>
+#include <unistd.h>
+#include <mutex> // for std::lock_guard
+
+QT_BEGIN_NAMESPACE
+
+static constexpr uint SinkPeriodTimeMs = 20;
+static constexpr uint DefaultBufferLengthMs = 100;
+
+#define LOW_LATENCY_CATEGORY_NAME "game"
+
+static void outputStreamWriteCallback(pa_stream *stream, size_t length, void *userdata)
+{
+ Q_UNUSED(stream);
+ Q_UNUSED(userdata);
+ qCDebug(qLcPulseAudioOut) << "Write callback:" << length;
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+ pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
+}
+
+static void outputStreamStateCallback(pa_stream *stream, void *userdata)
+{
+ Q_UNUSED(userdata);
+ pa_stream_state_t state = pa_stream_get_state(stream);
+ qCDebug(qLcPulseAudioOut) << "Stream state callback:" << state;
+ switch (state) {
+ case PA_STREAM_CREATING:
+ case PA_STREAM_READY:
+ case PA_STREAM_TERMINATED:
+ break;
+
+ case PA_STREAM_FAILED:
+ default:
+ qWarning() << QStringLiteral("Stream error: %1")
+ .arg(QString::fromUtf8(pa_strerror(
+ pa_context_errno(pa_stream_get_context(stream)))));
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+ pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
+ break;
+ }
+}
+
+static void outputStreamUnderflowCallback(pa_stream *stream, void *userdata)
+{
+ Q_UNUSED(stream);
+ qCDebug(qLcPulseAudioOut) << "Buffer underflow";
+ if (userdata)
+ static_cast<QPulseAudioSink *>(userdata)->streamUnderflowCallback();
+}
+
+static void outputStreamOverflowCallback(pa_stream *stream, void *userdata)
+{
+ Q_UNUSED(stream);
+ Q_UNUSED(userdata);
+ qCDebug(qLcPulseAudioOut) << "Buffer overflow";
+}
+
+static void outputStreamLatencyCallback(pa_stream *stream, void *userdata)
+{
+ Q_UNUSED(stream);
+ Q_UNUSED(userdata);
+
+ if (Q_UNLIKELY(qLcPulseAudioOut().isEnabled(QtDebugMsg))) {
+ const pa_timing_info *info = pa_stream_get_timing_info(stream);
+
+ qCDebug(qLcPulseAudioOut) << "Latency callback:";
+ qCDebug(qLcPulseAudioOut) << "\tWrite index corrupt: " << info->write_index_corrupt;
+ qCDebug(qLcPulseAudioOut) << "\tWrite index: " << info->write_index;
+ qCDebug(qLcPulseAudioOut) << "\tRead index corrupt: " << info->read_index_corrupt;
+ qCDebug(qLcPulseAudioOut) << "\tRead index: " << info->read_index;
+ qCDebug(qLcPulseAudioOut) << "\tSink usec: " << info->sink_usec;
+ qCDebug(qLcPulseAudioOut) << "\tConfigured sink usec: " << info->configured_sink_usec;
+ }
+}
+
+static void outputStreamSuccessCallback(pa_stream *stream, int success, void *userdata)
+{
+ Q_UNUSED(stream);
+ Q_UNUSED(userdata);
+
+ qCDebug(qLcPulseAudioOut) << "Stream successful:" << success;
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+ pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
+}
+
+static void outputStreamDrainComplete(pa_stream *stream, int success, void *userdata)
+{
+ Q_UNUSED(stream);
+
+ qCDebug(qLcPulseAudioOut) << "Stream drained:" << static_cast<bool>(success) << userdata;
+
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+ pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
+
+ if (userdata && success)
+ static_cast<QPulseAudioSink *>(userdata)->streamDrainedCallback();
+}
+
+static void outputStreamFlushComplete(pa_stream *stream, int success, void *userdata)
+{
+ Q_UNUSED(stream);
+
+ qCDebug(qLcPulseAudioOut) << "Stream flushed:" << static_cast<bool>(success) << userdata;
+}
+
+static void streamAdjustPrebufferCallback(pa_stream *stream, int success, void *userdata)
+{
+ Q_UNUSED(stream);
+ Q_UNUSED(success);
+ Q_UNUSED(userdata);
+
+ qCDebug(qLcPulseAudioOut) << "Prebuffer adjusted:" << static_cast<bool>(success);
+}
+
+QPulseAudioSink::QPulseAudioSink(const QByteArray &device, QObject *parent)
+ : QPlatformAudioSink(parent), m_device(device), m_stateMachine(*this)
+{
+}
+
+QPulseAudioSink::~QPulseAudioSink()
+{
+ if (auto notifier = m_stateMachine.stop())
+ close();
+}
+
+QAudio::Error QPulseAudioSink::error() const
+{
+ return m_stateMachine.error();
+}
+
+QAudio::State QPulseAudioSink::state() const
+{
+ return m_stateMachine.state();
+}
+
+void QPulseAudioSink::streamUnderflowCallback()
+{
+ bool atEnd = m_audioSource && m_audioSource->atEnd();
+ if (atEnd && m_stateMachine.state() != QAudio::StoppedState) {
+ qCDebug(qLcPulseAudioOut) << "Draining stream at end of buffer";
+ exchangeDrainOperation(pa_stream_drain(m_stream, outputStreamDrainComplete, this));
+ }
+
+ m_stateMachine.updateActiveOrIdle(
+ false, (m_pullMode && atEnd) ? QAudio::NoError : QAudio::UnderrunError);
+}
+
+void QPulseAudioSink::streamDrainedCallback()
+{
+ if (!exchangeDrainOperation(nullptr))
+ return;
+}
+
+void QPulseAudioSink::start(QIODevice *device)
+{
+ reset();
+
+ m_pullMode = true;
+ m_audioSource = device;
+
+ if (!open()) {
+ m_audioSource = nullptr;
+ return;
+ }
+
+ // ensure we only process timing infos that are up to date
+ gettimeofday(&lastTimingInfo, nullptr);
+ lastProcessedUSecs = 0;
+
+ connect(m_audioSource, &QIODevice::readyRead, this, &QPulseAudioSink::startPulling);
+
+ m_stateMachine.start();
+}
+
+void QPulseAudioSink::startPulling()
+{
+ Q_ASSERT(m_pullMode);
+ if (m_tickTimer.isActive())
+ return;
+
+ m_tickTimer.start(m_pullingPeriodTime, this);
+}
+
+void QPulseAudioSink::stopTimer()
+{
+ if (m_tickTimer.isActive())
+ m_tickTimer.stop();
+}
+
+QIODevice *QPulseAudioSink::start()
+{
+ reset();
+
+ m_pullMode = false;
+
+ if (!open())
+ return nullptr;
+
+ m_audioSource = new PulseOutputPrivate(this);
+ m_audioSource->open(QIODevice::WriteOnly | QIODevice::Unbuffered);
+
+ // ensure we only process timing infos that are up to date
+ gettimeofday(&lastTimingInfo, nullptr);
+ lastProcessedUSecs = 0;
+
+ m_stateMachine.start(false);
+
+ return m_audioSource;
+}
+
+bool QPulseAudioSink::open()
+{
+ if (m_opened)
+ return true;
+
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+
+ if (!pulseEngine->context()
+ || pa_context_get_state(pulseEngine->context()) != PA_CONTEXT_READY) {
+ m_stateMachine.stopOrUpdateError(QAudio::FatalError);
+ return false;
+ }
+
+ pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(m_format);
+ pa_channel_map channel_map = QPulseAudioInternal::channelMapForAudioFormat(m_format);
+ Q_ASSERT(spec.channels == channel_map.channels);
+
+ if (!pa_sample_spec_valid(&spec)) {
+ m_stateMachine.stopOrUpdateError(QAudio::OpenError);
+ return false;
+ }
+
+ m_spec = spec;
+ m_totalTimeValue = 0;
+
+ if (m_streamName.isNull())
+ m_streamName =
+ QStringLiteral("QtmPulseStream-%1-%2").arg(::getpid()).arg(quintptr(this)).toUtf8();
+
+ if (Q_UNLIKELY(qLcPulseAudioOut().isEnabled(QtDebugMsg))) {
+ qCDebug(qLcPulseAudioOut) << "Opening stream with.";
+ qCDebug(qLcPulseAudioOut) << "\tFormat: " << spec.format;
+ qCDebug(qLcPulseAudioOut) << "\tRate: " << spec.rate;
+ qCDebug(qLcPulseAudioOut) << "\tChannels: " << spec.channels;
+ qCDebug(qLcPulseAudioOut) << "\tFrame size: " << pa_frame_size(&spec);
+ }
+
+ pulseEngine->lock();
+
+ pa_proplist *propList = pa_proplist_new();
+#if 0
+ qint64 bytesPerSecond = m_format.sampleRate() * m_format.bytesPerFrame();
+ static const char *mediaRoleFromAudioRole[] = {
+ nullptr, // UnknownRole
+ "music", // MusicRole
+ "video", // VideoRole
+ "phone", // VoiceCommunicationRole
+ "event", // AlarmRole
+ "event", // NotificationRole
+ "phone", // RingtoneRole
+ "a11y", // AccessibilityRole
+ nullptr, // SonificationRole
+ "game" // GameRole
+ };
+
+ const char *r = mediaRoleFromAudioRole[m_role];
+ if (r)
+ pa_proplist_sets(propList, PA_PROP_MEDIA_ROLE, r);
+#endif
+
+ m_stream = pa_stream_new_with_proplist(pulseEngine->context(), m_streamName.constData(),
+ &m_spec, &channel_map, propList);
+ pa_proplist_free(propList);
+
+ if (!m_stream) {
+ qCWarning(qLcPulseAudioOut) << "QAudioSink: pa_stream_new_with_proplist() failed!";
+ pulseEngine->unlock();
+
+ m_stateMachine.stopOrUpdateError(QAudio::OpenError);
+ return false;
+ }
+
+ pa_stream_set_state_callback(m_stream, outputStreamStateCallback, this);
+ pa_stream_set_write_callback(m_stream, outputStreamWriteCallback, this);
+
+ pa_stream_set_underflow_callback(m_stream, outputStreamUnderflowCallback, this);
+ pa_stream_set_overflow_callback(m_stream, outputStreamOverflowCallback, this);
+ pa_stream_set_latency_update_callback(m_stream, outputStreamLatencyCallback, this);
+
+ pa_buffer_attr requestedBuffer;
+ // Request a target buffer size
+ auto targetBufferSize = m_userBufferSize ? *m_userBufferSize : defaultBufferSize();
+ requestedBuffer.tlength =
+ targetBufferSize ? static_cast<uint32_t>(targetBufferSize) : static_cast<uint32_t>(-1);
+ // Rest should be determined by PulseAudio
+ requestedBuffer.fragsize = static_cast<uint32_t>(-1);
+ requestedBuffer.maxlength = static_cast<uint32_t>(-1);
+ requestedBuffer.minreq = static_cast<uint32_t>(-1);
+ requestedBuffer.prebuf = static_cast<uint32_t>(-1);
+
+ pa_stream_flags flags =
+ pa_stream_flags(PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_ADJUST_LATENCY);
+ if (pa_stream_connect_playback(m_stream, m_device.data(), &requestedBuffer, flags, nullptr,
+ nullptr)
+ < 0) {
+ qCWarning(qLcPulseAudioOut) << "pa_stream_connect_playback() failed!";
+ pa_stream_unref(m_stream);
+ m_stream = nullptr;
+ pulseEngine->unlock();
+ m_stateMachine.stopOrUpdateError(QAudio::OpenError);
+ return false;
+ }
+
+ while (pa_stream_get_state(m_stream) != PA_STREAM_READY)
+ pa_threaded_mainloop_wait(pulseEngine->mainloop());
+
+ const pa_buffer_attr *buffer = pa_stream_get_buffer_attr(m_stream);
+ m_bufferSize = buffer->tlength;
+
+ if (m_pullMode) {
+ // Adjust period time to reduce chance of it being higher than amount of bytes requested by
+ // PulseAudio server
+ m_pullingPeriodTime =
+ qMin(SinkPeriodTimeMs, pa_bytes_to_usec(m_bufferSize, &m_spec) / 1000 / 2);
+ m_pullingPeriodSize = pa_usec_to_bytes(m_pullingPeriodTime * 1000, &m_spec);
+ }
+
+ m_audioBuffer.resize(buffer->maxlength);
+
+ const qint64 streamSize = m_audioSource ? m_audioSource->size() : 0;
+ if (m_pullMode && streamSize > 0 && static_cast<qint64>(buffer->prebuf) > streamSize) {
+ pa_buffer_attr newBufferAttr;
+ newBufferAttr = *buffer;
+ newBufferAttr.prebuf = streamSize;
+ PAOperationUPtr(pa_stream_set_buffer_attr(m_stream, &newBufferAttr,
+ streamAdjustPrebufferCallback, nullptr));
+ }
+
+ if (Q_UNLIKELY(qLcPulseAudioOut().isEnabled(QtDebugMsg))) {
+ qCDebug(qLcPulseAudioOut) << "Buffering info:";
+ qCDebug(qLcPulseAudioOut) << "\tMax length: " << buffer->maxlength;
+ qCDebug(qLcPulseAudioOut) << "\tTarget length: " << buffer->tlength;
+ qCDebug(qLcPulseAudioOut) << "\tPre-buffering: " << buffer->prebuf;
+ qCDebug(qLcPulseAudioOut) << "\tMinimum request: " << buffer->minreq;
+ qCDebug(qLcPulseAudioOut) << "\tFragment size: " << buffer->fragsize;
+ }
+
+ pulseEngine->unlock();
+
+ connect(pulseEngine, &QPulseAudioEngine::contextFailed, this,
+ &QPulseAudioSink::onPulseContextFailed);
+
+ m_opened = true;
+
+ if (m_pullMode)
+ startPulling();
+
+ m_elapsedTimeOffset = 0;
+
+ return true;
+}
+
+void QPulseAudioSink::close()
+{
+ if (!m_opened)
+ return;
+
+ stopTimer();
+
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+
+ if (m_stream) {
+ std::lock_guard lock(*pulseEngine);
+
+ pa_stream_set_state_callback(m_stream, nullptr, nullptr);
+ pa_stream_set_write_callback(m_stream, nullptr, nullptr);
+ pa_stream_set_underflow_callback(m_stream, nullptr, nullptr);
+ pa_stream_set_overflow_callback(m_stream, nullptr, nullptr);
+ pa_stream_set_latency_update_callback(m_stream, nullptr, nullptr);
+
+ if (auto prevOp = exchangeDrainOperation(nullptr))
+ // cancel draining operation to prevent calling draining callback after closing.
+ pa_operation_cancel(prevOp.get());
+
+ PAOperationUPtr operation(pa_stream_flush(m_stream, outputStreamFlushComplete, nullptr));
+
+ pa_stream_disconnect(m_stream);
+ pa_stream_unref(m_stream);
+ m_stream = nullptr;
+ }
+
+ disconnect(pulseEngine, &QPulseAudioEngine::contextFailed, this,
+ &QPulseAudioSink::onPulseContextFailed);
+
+ if (m_audioSource) {
+ if (m_pullMode) {
+ disconnect(m_audioSource, &QIODevice::readyRead, this, nullptr);
+ m_audioSource->reset();
+ } else {
+ delete m_audioSource;
+ m_audioSource = nullptr;
+ }
+ }
+
+ m_opened = false;
+ m_audioBuffer.clear();
+}
+
+void QPulseAudioSink::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == m_tickTimer.timerId() && m_pullMode)
+ userFeed();
+
+ QPlatformAudioSink::timerEvent(event);
+}
+
+void QPulseAudioSink::userFeed()
+{
+ int writableSize = bytesFree();
+
+ if (writableSize == 0) {
+ // PulseAudio server doesn't want any more data
+ m_stateMachine.activateFromIdle();
+ return;
+ }
+
+ // Write up to writableSize
+ const int inputSize =
+ std::min({ m_pullingPeriodSize, static_cast<int>(m_audioBuffer.size()), writableSize });
+
+ Q_ASSERT(!m_audioBuffer.empty());
+ int audioBytesPulled = m_audioSource->read(m_audioBuffer.data(), inputSize);
+ Q_ASSERT(audioBytesPulled <= inputSize);
+
+ if (audioBytesPulled > 0) {
+ if (audioBytesPulled > inputSize) {
+ qCWarning(qLcPulseAudioOut)
+ << "Invalid audio data size provided by pull source:" << audioBytesPulled
+ << "should be less than" << inputSize;
+ audioBytesPulled = inputSize;
+ }
+ auto bytesWritten = write(m_audioBuffer.data(), audioBytesPulled);
+ if (bytesWritten != audioBytesPulled)
+ qWarning() << "Unfinished write:" << bytesWritten << "vs" << audioBytesPulled;
+
+ m_stateMachine.activateFromIdle();
+
+ if (inputSize < writableSize) // PulseAudio needs more data.
+ QMetaObject::invokeMethod(this, &QPulseAudioSink::userFeed, Qt::QueuedConnection);
+ } else if (audioBytesPulled == 0) {
+ stopTimer();
+ const auto atEnd = m_audioSource->atEnd();
+ qCDebug(qLcPulseAudioOut) << "No more data available, source is done:" << atEnd;
+ }
+}
+
+qint64 QPulseAudioSink::write(const char *data, qint64 len)
+{
+ using namespace QPulseAudioInternal;
+
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+
+ pulseEngine->lock();
+
+ size_t nbytes = len;
+ void *dest = nullptr;
+
+ if (pa_stream_begin_write(m_stream, &dest, &nbytes) < 0) {
+ pulseEngine->unlock();
+ qCWarning(qLcPulseAudioOut)
+ << "pa_stream_begin_write error:" << currentError(pulseEngine->context());
+ m_stateMachine.updateActiveOrIdle(false, QAudio::IOError);
+ return 0;
+ }
+
+ len = qMin(len, qint64(nbytes));
+
+ if (m_volume < 1.0f) {
+ // Don't use PulseAudio volume, as it might affect all other streams of the same category
+ // or even affect the system volume if flat volumes are enabled
+ QAudioHelperInternal::qMultiplySamples(m_volume, m_format, data, dest, len);
+ } else {
+ memcpy(dest, data, len);
+ }
+
+ data = reinterpret_cast<char *>(dest);
+
+ if ((pa_stream_write(m_stream, data, len, nullptr, 0, PA_SEEK_RELATIVE)) < 0) {
+ pulseEngine->unlock();
+ qCWarning(qLcPulseAudioOut)
+ << "pa_stream_write error:" << currentError(pulseEngine->context());
+ m_stateMachine.updateActiveOrIdle(false, QAudio::IOError);
+ return 0;
+ }
+
+ pulseEngine->unlock();
+ m_totalTimeValue += len;
+
+ m_stateMachine.updateActiveOrIdle(true);
+ return len;
+}
+
+void QPulseAudioSink::stop()
+{
+ if (auto notifier = m_stateMachine.stop()) {
+ {
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+ std::lock_guard lock(*pulseEngine);
+
+ if (auto prevOp = exchangeDrainOperation(nullptr))
+ // cancel the draining callback that is not relevant already
+ pa_operation_cancel(prevOp.get());
+
+ PAOperationUPtr drainOp(pa_stream_drain(m_stream, outputStreamDrainComplete, nullptr));
+ pulseEngine->wait(drainOp.get());
+ }
+
+ close();
+ }
+}
+
+qsizetype QPulseAudioSink::bytesFree() const
+{
+ if (!m_stateMachine.isActiveOrIdle())
+ return 0;
+
+ std::lock_guard lock(*QPulseAudioEngine::instance());
+ return pa_stream_writable_size(m_stream);
+}
+
+void QPulseAudioSink::setBufferSize(qsizetype value)
+{
+ m_userBufferSize = value;
+}
+
+qsizetype QPulseAudioSink::bufferSize() const
+{
+ if (m_bufferSize)
+ return m_bufferSize;
+
+ if (m_userBufferSize)
+ return *m_userBufferSize;
+
+ return defaultBufferSize();
+}
+
+static qint64 operator-(timeval t1, timeval t2)
+{
+ constexpr qint64 secsToUSecs = 1000000;
+ return (t1.tv_sec - t2.tv_sec) * secsToUSecs + (t1.tv_usec - t2.tv_usec);
+}
+
+qint64 QPulseAudioSink::processedUSecs() const
+{
+ const auto state = this->state();
+ if (!m_stream || state == QAudio::StoppedState)
+ return 0;
+ if (state == QAudio::SuspendedState)
+ return lastProcessedUSecs;
+
+ auto info = pa_stream_get_timing_info(m_stream);
+ if (!info)
+ return lastProcessedUSecs;
+
+ // if the info changed, update our cached data, and recalculate the average latency
+ if (info->timestamp - lastTimingInfo > 0) {
+ lastTimingInfo.tv_sec = info->timestamp.tv_sec;
+ lastTimingInfo.tv_usec = info->timestamp.tv_usec;
+ averageLatency =
+ 0; // also use that as long as we don't have valid data from the timing info
+
+ // Only use timing values when playing, otherwise the latency numbers can be way off
+ if (info->since_underrun >= 0
+ && pa_bytes_to_usec(info->since_underrun, &m_spec) > info->sink_usec) {
+ latencyList.append(info->sink_usec);
+ // Average over the last X timing infos to keep numbers more stable.
+ // 10 seems to be a decent number that keeps values relatively stable but doesn't make
+ // the list too big
+ const int latencyListMaxSize = 10;
+ if (latencyList.size() > latencyListMaxSize)
+ latencyList.pop_front();
+ for (const auto l : latencyList)
+ averageLatency += l;
+ averageLatency /= latencyList.size();
+ if (averageLatency < 0)
+ averageLatency = 0;
+ }
+ }
+
+ const qint64 usecsRead = info->read_index < 0 ? 0 : pa_bytes_to_usec(info->read_index, &m_spec);
+ const qint64 usecsWritten =
+ info->write_index < 0 ? 0 : pa_bytes_to_usec(info->write_index, &m_spec);
+
+ // processed data is the amount read by the server minus its latency
+ qint64 usecs = usecsRead - averageLatency;
+
+ timeval tv;
+ gettimeofday(&tv, nullptr);
+
+ // and now adjust for the time since the last update
+ qint64 timeSinceUpdate = tv - info->timestamp;
+ if (timeSinceUpdate > 0)
+ usecs += timeSinceUpdate;
+
+ // We can never have processed more than we've written to the sink
+ if (usecs > usecsWritten)
+ usecs = usecsWritten;
+
+ // make sure timing is monotonic
+ if (usecs < lastProcessedUSecs)
+ usecs = lastProcessedUSecs;
+ else
+ lastProcessedUSecs = usecs;
+
+ return usecs;
+}
+
+void QPulseAudioSink::resume()
+{
+ if (auto notifier = m_stateMachine.resume()) {
+ {
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+
+ std::lock_guard lock(*pulseEngine);
+
+ PAOperationUPtr operation(
+ pa_stream_cork(m_stream, 0, outputStreamSuccessCallback, nullptr));
+ pulseEngine->wait(operation.get());
+
+ operation.reset(pa_stream_trigger(m_stream, outputStreamSuccessCallback, nullptr));
+ pulseEngine->wait(operation.get());
+ }
+
+ if (m_pullMode)
+ startPulling();
+ }
+}
+
+void QPulseAudioSink::setFormat(const QAudioFormat &format)
+{
+ m_format = format;
+}
+
+QAudioFormat QPulseAudioSink::format() const
+{
+ return m_format;
+}
+
+void QPulseAudioSink::suspend()
+{
+ if (auto notifier = m_stateMachine.suspend()) {
+ stopTimer();
+
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+
+ std::lock_guard lock(*pulseEngine);
+
+ PAOperationUPtr operation(
+ pa_stream_cork(m_stream, 1, outputStreamSuccessCallback, nullptr));
+ pulseEngine->wait(operation.get());
+ }
+}
+
+void QPulseAudioSink::reset()
+{
+ if (auto notifier = m_stateMachine.stopOrUpdateError())
+ close();
+}
+
+PulseOutputPrivate::PulseOutputPrivate(QPulseAudioSink *audio)
+{
+ m_audioDevice = qobject_cast<QPulseAudioSink *>(audio);
+}
+
+qint64 PulseOutputPrivate::readData(char *data, qint64 len)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(len);
+
+ return 0;
+}
+
+qint64 PulseOutputPrivate::writeData(const char *data, qint64 len)
+{
+ qint64 written = 0;
+
+ const auto state = m_audioDevice->state();
+ if (state == QAudio::ActiveState || state == QAudio::IdleState) {
+ while (written < len) {
+ int chunk = m_audioDevice->write(data + written, (len - written));
+ if (chunk <= 0)
+ return written;
+ written += chunk;
+ }
+ }
+
+ return written;
+}
+
+void QPulseAudioSink::setVolume(qreal vol)
+{
+ if (qFuzzyCompare(m_volume, vol))
+ return;
+
+ m_volume = qBound(qreal(0), vol, qreal(1));
+}
+
+qreal QPulseAudioSink::volume() const
+{
+ return m_volume;
+}
+
+void QPulseAudioSink::onPulseContextFailed()
+{
+ if (auto notifier = m_stateMachine.stop(QAudio::FatalError))
+ close();
+}
+
+PAOperationUPtr QPulseAudioSink::exchangeDrainOperation(pa_operation *newOperation)
+{
+ return PAOperationUPtr(m_drainOperation.exchange(newOperation));
+}
+
+qsizetype QPulseAudioSink::defaultBufferSize() const
+{
+ if (m_spec.rate > 0)
+ return pa_usec_to_bytes(DefaultBufferLengthMs * 1000, &m_spec);
+
+ auto spec = QPulseAudioInternal::audioFormatToSampleSpec(m_format);
+ if (pa_sample_spec_valid(&spec))
+ return pa_usec_to_bytes(DefaultBufferLengthMs * 1000, &spec);
+
+ return 0;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qpulseaudiosink_p.cpp"
diff --git a/src/multimedia/pulseaudio/qpulseaudiosink_p.h b/src/multimedia/pulseaudio/qpulseaudiosink_p.h
new file mode 100644
index 000000000..cf0b181ec
--- /dev/null
+++ b/src/multimedia/pulseaudio/qpulseaudiosink_p.h
@@ -0,0 +1,136 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAUDIOOUTPUTPULSE_H
+#define QAUDIOOUTPUTPULSE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qfile.h>
+#include <QtCore/qtimer.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qelapsedtimer.h>
+#include <QtCore/qiodevice.h>
+
+#include "qaudio.h"
+#include "qaudiodevice.h"
+#include "pulseaudio/qpulsehelpers_p.h"
+
+#include <private/qaudiosystem_p.h>
+#include <private/qaudiostatemachine_p.h>
+#include <pulse/pulseaudio.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPulseAudioSink : public QPlatformAudioSink
+{
+ friend class PulseOutputPrivate;
+ Q_OBJECT
+
+public:
+ QPulseAudioSink(const QByteArray &device, QObject *parent);
+ ~QPulseAudioSink();
+
+ void start(QIODevice *device) override;
+ QIODevice *start() override;
+ void stop() override;
+ void reset() override;
+ void suspend() override;
+ void resume() override;
+ qsizetype bytesFree() const override;
+ void setBufferSize(qsizetype value) override;
+ qsizetype bufferSize() const override;
+ qint64 processedUSecs() const override;
+ QAudio::Error error() const override;
+ QAudio::State state() const override;
+ void setFormat(const QAudioFormat &format) override;
+ QAudioFormat format() const override;
+
+ void setVolume(qreal volume) override;
+ qreal volume() const override;
+
+ void streamUnderflowCallback();
+ void streamDrainedCallback();
+
+protected:
+ void timerEvent(QTimerEvent *event) override;
+
+private:
+ void startPulling();
+ void stopTimer();
+
+ bool open();
+ void close();
+ qint64 write(const char *data, qint64 len);
+
+private Q_SLOTS:
+ void userFeed();
+ void onPulseContextFailed();
+
+ PAOperationUPtr exchangeDrainOperation(pa_operation *newOperation);
+
+private:
+ qsizetype defaultBufferSize() const;
+
+ pa_sample_spec m_spec = {};
+ // calculate timing manually, as pulseaudio doesn't give us good enough data
+ mutable timeval lastTimingInfo = {};
+
+ mutable QList<qint64> latencyList; // last latency values
+
+ QByteArray m_device;
+ QByteArray m_streamName;
+ QAudioFormat m_format;
+ QBasicTimer m_tickTimer;
+
+ QIODevice *m_audioSource = nullptr;
+ pa_stream *m_stream = nullptr;
+ std::vector<char> m_audioBuffer;
+
+ qint64 m_totalTimeValue = 0;
+ qint64 m_elapsedTimeOffset = 0;
+ mutable qint64 averageLatency = 0; // average latency
+ mutable qint64 lastProcessedUSecs = 0;
+ qreal m_volume = 1.0;
+
+ std::atomic<pa_operation *> m_drainOperation = nullptr;
+ qsizetype m_bufferSize = 0;
+ std::optional<qsizetype> m_userBufferSize = std::nullopt;
+ int m_pullingPeriodSize = 0;
+ int m_pullingPeriodTime = 0;
+ bool m_pullMode = true;
+ bool m_opened = false;
+
+ QAudioStateMachine m_stateMachine;
+};
+
+class PulseOutputPrivate : public QIODevice
+{
+ friend class QPulseAudioSink;
+ Q_OBJECT
+
+public:
+ PulseOutputPrivate(QPulseAudioSink *audio);
+ virtual ~PulseOutputPrivate() {}
+
+protected:
+ qint64 readData(char *data, qint64 len) override;
+ qint64 writeData(const char *data, qint64 len) override;
+
+private:
+ QPulseAudioSink *m_audioDevice;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/pulseaudio/qpulseaudiosource.cpp b/src/multimedia/pulseaudio/qpulseaudiosource.cpp
new file mode 100644
index 000000000..488daa48b
--- /dev/null
+++ b/src/multimedia/pulseaudio/qpulseaudiosource.cpp
@@ -0,0 +1,566 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qmath.h>
+#include <private/qaudiohelpers_p.h>
+
+#include "qpulseaudiosource_p.h"
+#include "qaudioengine_pulse_p.h"
+#include "qpulseaudiodevice_p.h"
+#include "qpulsehelpers_p.h"
+#include <sys/types.h>
+#include <unistd.h>
+#include <mutex> // for lock_guard
+
+QT_BEGIN_NAMESPACE
+
+const int SourcePeriodTimeMs = 50;
+
+static void inputStreamReadCallback(pa_stream *stream, size_t length, void *userdata)
+{
+ Q_UNUSED(userdata);
+ Q_UNUSED(length);
+ Q_UNUSED(stream);
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+ pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
+}
+
+static void inputStreamStateCallback(pa_stream *stream, void *userdata)
+{
+ using namespace QPulseAudioInternal;
+
+ Q_UNUSED(userdata);
+ pa_stream_state_t state = pa_stream_get_state(stream);
+ qCDebug(qLcPulseAudioIn) << "Stream state: " << state;
+ switch (state) {
+ case PA_STREAM_CREATING:
+ break;
+ case PA_STREAM_READY:
+ if (Q_UNLIKELY(qLcPulseAudioIn().isEnabled(QtDebugMsg))) {
+ QPulseAudioSource *audioInput = static_cast<QPulseAudioSource *>(userdata);
+ const pa_buffer_attr *buffer_attr = pa_stream_get_buffer_attr(stream);
+ qCDebug(qLcPulseAudioIn) << "*** maxlength: " << buffer_attr->maxlength;
+ qCDebug(qLcPulseAudioIn) << "*** prebuf: " << buffer_attr->prebuf;
+ qCDebug(qLcPulseAudioIn) << "*** fragsize: " << buffer_attr->fragsize;
+ qCDebug(qLcPulseAudioIn) << "*** minreq: " << buffer_attr->minreq;
+ qCDebug(qLcPulseAudioIn) << "*** tlength: " << buffer_attr->tlength;
+
+ pa_sample_spec spec =
+ QPulseAudioInternal::audioFormatToSampleSpec(audioInput->format());
+ qCDebug(qLcPulseAudioIn)
+ << "*** bytes_to_usec: " << pa_bytes_to_usec(buffer_attr->fragsize, &spec);
+ }
+ break;
+ case PA_STREAM_TERMINATED:
+ break;
+ case PA_STREAM_FAILED:
+ default:
+ qWarning() << "Stream error: " << currentError(stream);
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+ pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
+ break;
+ }
+}
+
+static void inputStreamUnderflowCallback(pa_stream *stream, void *userdata)
+{
+ Q_UNUSED(userdata);
+ Q_UNUSED(stream);
+ qWarning() << "Got a buffer underflow!";
+}
+
+static void inputStreamOverflowCallback(pa_stream *stream, void *userdata)
+{
+ Q_UNUSED(stream);
+ Q_UNUSED(userdata);
+ qWarning() << "Got a buffer overflow!";
+}
+
+static void inputStreamSuccessCallback(pa_stream *stream, int success, void *userdata)
+{
+ Q_UNUSED(stream);
+ Q_UNUSED(userdata);
+ Q_UNUSED(success);
+
+ // if (!success)
+ // TODO: Is cork success? i->operation_success = success;
+
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+ pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
+}
+
+QPulseAudioSource::QPulseAudioSource(const QByteArray &device, QObject *parent)
+ : QPlatformAudioSource(parent),
+ m_totalTimeValue(0),
+ m_audioSource(nullptr),
+ m_volume(qreal(1.0f)),
+ m_pullMode(true),
+ m_opened(false),
+ m_bufferSize(0),
+ m_periodSize(0),
+ m_periodTime(SourcePeriodTimeMs),
+ m_stream(nullptr),
+ m_device(device),
+ m_stateMachine(*this)
+{
+}
+
+QPulseAudioSource::~QPulseAudioSource()
+{
+ // TODO: Investigate draining the stream
+ if (auto notifier = m_stateMachine.stop())
+ close();
+}
+
+QAudio::Error QPulseAudioSource::error() const
+{
+ return m_stateMachine.error();
+}
+
+QAudio::State QPulseAudioSource::state() const
+{
+ return m_stateMachine.state();
+}
+
+void QPulseAudioSource::setFormat(const QAudioFormat &format)
+{
+ if (!m_stateMachine.isActiveOrIdle())
+ m_format = format;
+}
+
+QAudioFormat QPulseAudioSource::format() const
+{
+ return m_format;
+}
+
+void QPulseAudioSource::start(QIODevice *device)
+{
+ reset();
+
+ if (!open())
+ return;
+
+ m_pullMode = true;
+ m_audioSource = device;
+
+ m_stateMachine.start();
+}
+
+QIODevice *QPulseAudioSource::start()
+{
+ reset();
+
+ if (!open())
+ return nullptr;
+
+ m_pullMode = false;
+ m_audioSource = new PulseInputPrivate(this);
+ m_audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
+
+ m_stateMachine.start(false);
+
+ return m_audioSource;
+}
+
+void QPulseAudioSource::stop()
+{
+ if (auto notifier = m_stateMachine.stop())
+ close();
+}
+
+bool QPulseAudioSource::open()
+{
+ if (m_opened)
+ return true;
+
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+
+ if (!pulseEngine->context()
+ || pa_context_get_state(pulseEngine->context()) != PA_CONTEXT_READY) {
+ m_stateMachine.stopOrUpdateError(QAudio::FatalError);
+ return false;
+ }
+
+ pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(m_format);
+ pa_channel_map channel_map = QPulseAudioInternal::channelMapForAudioFormat(m_format);
+ Q_ASSERT(spec.channels == channel_map.channels);
+
+ if (!pa_sample_spec_valid(&spec)) {
+ m_stateMachine.stopOrUpdateError(QAudio::OpenError);
+ return false;
+ }
+
+ m_spec = spec;
+
+ //if (Q_UNLIKELY(qLcPulseAudioIn().isEnabled(QtDebugMsg)) {
+ // QTime now(QTime::currentTime());
+ // qCDebug(qLcPulseAudioIn) << now.second() << "s " << now.msec() << "ms :open()";
+ //}
+
+ if (m_streamName.isNull())
+ m_streamName =
+ QStringLiteral("QtmPulseStream-%1-%2").arg(::getpid()).arg(quintptr(this)).toUtf8();
+
+ if (Q_UNLIKELY(qLcPulseAudioIn().isEnabled(QtDebugMsg))) {
+ qCDebug(qLcPulseAudioIn) << "Format: " << spec.format;
+ qCDebug(qLcPulseAudioIn) << "Rate: " << spec.rate;
+ qCDebug(qLcPulseAudioIn) << "Channels: " << spec.channels;
+ qCDebug(qLcPulseAudioIn) << "Frame size: " << pa_frame_size(&spec);
+ }
+
+ pulseEngine->lock();
+
+ m_stream = pa_stream_new(pulseEngine->context(), m_streamName.constData(), &spec, &channel_map);
+
+ pa_stream_set_state_callback(m_stream, inputStreamStateCallback, this);
+ pa_stream_set_read_callback(m_stream, inputStreamReadCallback, this);
+
+ pa_stream_set_underflow_callback(m_stream, inputStreamUnderflowCallback, this);
+ pa_stream_set_overflow_callback(m_stream, inputStreamOverflowCallback, this);
+
+ m_periodSize = pa_usec_to_bytes(SourcePeriodTimeMs * 1000, &spec);
+
+ int flags = 0;
+ pa_buffer_attr buffer_attr;
+ buffer_attr.maxlength = static_cast<uint32_t>(-1);
+ buffer_attr.prebuf = static_cast<uint32_t>(-1);
+ buffer_attr.tlength = static_cast<uint32_t>(-1);
+ buffer_attr.minreq = static_cast<uint32_t>(-1);
+ flags |= PA_STREAM_ADJUST_LATENCY;
+
+ if (m_bufferSize > 0)
+ buffer_attr.fragsize = static_cast<uint32_t>(m_bufferSize);
+ else
+ buffer_attr.fragsize = static_cast<uint32_t>(m_periodSize);
+
+ flags |= PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_INTERPOLATE_TIMING;
+
+ int connectionResult = pa_stream_connect_record(m_stream, m_device.data(), &buffer_attr,
+ static_cast<pa_stream_flags_t>(flags));
+ if (connectionResult < 0) {
+ qWarning() << "pa_stream_connect_record() failed!";
+ pa_stream_unref(m_stream);
+ m_stream = nullptr;
+ pulseEngine->unlock();
+ m_stateMachine.stopOrUpdateError(QAudio::OpenError);
+ return false;
+ }
+
+ //if (Q_UNLIKELY(qLcPulseAudioIn().isEnabled(QtDebugMsg))) {
+ // auto *ss = pa_stream_get_sample_spec(m_stream);
+ // qCDebug(qLcPulseAudioIn) << "connected stream:";
+ // qCDebug(qLcPulseAudioIn) << " channels" << ss->channels << spec.channels;
+ // qCDebug(qLcPulseAudioIn) << " format" << ss->format << spec.format;
+ // qCDebug(qLcPulseAudioIn) << " rate" << ss->rate << spec.rate;
+ //}
+
+ while (pa_stream_get_state(m_stream) != PA_STREAM_READY)
+ pa_threaded_mainloop_wait(pulseEngine->mainloop());
+
+ const pa_buffer_attr *actualBufferAttr = pa_stream_get_buffer_attr(m_stream);
+ m_periodSize = actualBufferAttr->fragsize;
+ m_periodTime = pa_bytes_to_usec(m_periodSize, &spec) / 1000;
+ if (actualBufferAttr->tlength != static_cast<uint32_t>(-1))
+ m_bufferSize = actualBufferAttr->tlength;
+
+ pulseEngine->unlock();
+
+ connect(pulseEngine, &QPulseAudioEngine::contextFailed, this,
+ &QPulseAudioSource::onPulseContextFailed);
+
+ m_opened = true;
+ m_timer.start(m_periodTime, this);
+
+ m_elapsedTimeOffset = 0;
+ m_totalTimeValue = 0;
+
+ return true;
+}
+
+void QPulseAudioSource::close()
+{
+ if (!m_opened)
+ return;
+
+ m_timer.stop();
+
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+
+ if (m_stream) {
+ std::lock_guard lock(*pulseEngine);
+
+ pa_stream_set_state_callback(m_stream, nullptr, nullptr);
+ pa_stream_set_read_callback(m_stream, nullptr, nullptr);
+ pa_stream_set_underflow_callback(m_stream, nullptr, nullptr);
+ pa_stream_set_overflow_callback(m_stream, nullptr, nullptr);
+
+ pa_stream_disconnect(m_stream);
+ pa_stream_unref(m_stream);
+ m_stream = nullptr;
+ }
+
+ disconnect(pulseEngine, &QPulseAudioEngine::contextFailed, this,
+ &QPulseAudioSource::onPulseContextFailed);
+
+ if (!m_pullMode && m_audioSource) {
+ delete m_audioSource;
+ m_audioSource = nullptr;
+ }
+ m_opened = false;
+}
+
+qsizetype QPulseAudioSource::bytesReady() const
+{
+ using namespace QPulseAudioInternal;
+
+ if (!m_stateMachine.isActiveOrIdle())
+ return 0;
+
+ std::lock_guard lock(*QPulseAudioEngine::instance());
+
+ int bytes = pa_stream_readable_size(m_stream);
+ if (bytes < 0) {
+ qWarning() << "pa_stream_readable_size() failed:" << currentError(m_stream);
+ return 0;
+ }
+
+ return static_cast<qsizetype>(bytes);
+}
+
+qint64 QPulseAudioSource::read(char *data, qint64 len)
+{
+ using namespace QPulseAudioInternal;
+
+ Q_ASSERT(data != nullptr || len == 0);
+
+ m_stateMachine.updateActiveOrIdle(true, QAudio::NoError);
+ int readBytes = 0;
+
+ if (!m_pullMode && !m_tempBuffer.isEmpty()) {
+ readBytes = qMin(static_cast<int>(len), m_tempBuffer.size());
+ if (readBytes)
+ memcpy(data, m_tempBuffer.constData(), readBytes);
+ m_totalTimeValue += readBytes;
+
+ if (readBytes < m_tempBuffer.size()) {
+ m_tempBuffer.remove(0, readBytes);
+ return readBytes;
+ }
+
+ m_tempBuffer.clear();
+ }
+
+ while (pa_stream_readable_size(m_stream) > 0) {
+ size_t readLength = 0;
+
+ if (Q_UNLIKELY(qLcPulseAudioIn().isEnabled(QtDebugMsg))) {
+ auto readableSize = pa_stream_readable_size(m_stream);
+ qCDebug(qLcPulseAudioIn) << "QPulseAudioSource::read -- " << readableSize
+ << " bytes available from pulse audio";
+ }
+
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+ pulseEngine->lock();
+
+ const void *audioBuffer;
+
+ // Second and third parameters (audioBuffer and length) to pa_stream_peek are output
+ // parameters, the audioBuffer pointer is set to point to the actual pulse audio data, and
+ // the length is set to the length of this data.
+ if (pa_stream_peek(m_stream, &audioBuffer, &readLength) < 0) {
+ qWarning() << "pa_stream_peek() failed:" << currentError(m_stream);
+ pulseEngine->unlock();
+ return 0;
+ }
+
+ qint64 actualLength = 0;
+ if (m_pullMode) {
+ QByteArray adjusted(readLength, Qt::Uninitialized);
+ applyVolume(audioBuffer, adjusted.data(), readLength);
+ actualLength = m_audioSource->write(adjusted);
+
+ if (actualLength < qint64(readLength)) {
+ pulseEngine->unlock();
+ m_stateMachine.updateActiveOrIdle(false, QAudio::UnderrunError);
+ return actualLength;
+ }
+ } else {
+ actualLength = qMin(static_cast<int>(len - readBytes), static_cast<int>(readLength));
+ applyVolume(audioBuffer, data + readBytes, actualLength);
+ }
+
+ qCDebug(qLcPulseAudioIn) << "QPulseAudioSource::read -- wrote " << actualLength
+ << " to client";
+
+ if (actualLength < qint64(readLength)) {
+ int diff = readLength - actualLength;
+ int oldSize = m_tempBuffer.size();
+
+ qCDebug(qLcPulseAudioIn) << "QPulseAudioSource::read -- appending " << diff
+ << " bytes of data to temp buffer";
+
+ m_tempBuffer.resize(m_tempBuffer.size() + diff);
+ applyVolume(static_cast<const char *>(audioBuffer) + actualLength,
+ m_tempBuffer.data() + oldSize, diff);
+ QMetaObject::invokeMethod(this, "userFeed", Qt::QueuedConnection);
+ }
+
+ m_totalTimeValue += actualLength;
+ readBytes += actualLength;
+
+ pa_stream_drop(m_stream);
+ pulseEngine->unlock();
+
+ if (!m_pullMode && readBytes >= len)
+ break;
+ }
+
+ qCDebug(qLcPulseAudioIn) << "QPulseAudioSource::read -- returning after reading " << readBytes
+ << " bytes";
+
+ return readBytes;
+}
+
+void QPulseAudioSource::applyVolume(const void *src, void *dest, int len)
+{
+ Q_ASSERT((src && dest) || len == 0);
+ if (m_volume < 1.f)
+ QAudioHelperInternal::qMultiplySamples(m_volume, m_format, src, dest, len);
+ else if (len)
+ memcpy(dest, src, len);
+}
+
+void QPulseAudioSource::resume()
+{
+ if (auto notifier = m_stateMachine.resume()) {
+ {
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+
+ std::lock_guard lock(*pulseEngine);
+
+ PAOperationUPtr operation(
+ pa_stream_cork(m_stream, 0, inputStreamSuccessCallback, nullptr));
+ pulseEngine->wait(operation.get());
+ }
+
+ m_timer.start(m_periodTime, this);
+ }
+}
+
+void QPulseAudioSource::setVolume(qreal vol)
+{
+ if (qFuzzyCompare(m_volume, vol))
+ return;
+
+ m_volume = qBound(qreal(0), vol, qreal(1));
+}
+
+qreal QPulseAudioSource::volume() const
+{
+ return m_volume;
+}
+
+void QPulseAudioSource::setBufferSize(qsizetype value)
+{
+ m_bufferSize = value;
+}
+
+qsizetype QPulseAudioSource::bufferSize() const
+{
+ return m_bufferSize;
+}
+
+qint64 QPulseAudioSource::processedUSecs() const
+{
+ if (!m_stream)
+ return 0;
+ pa_usec_t usecs = 0;
+ int result = pa_stream_get_time(m_stream, &usecs);
+ Q_UNUSED(result);
+ //if (result != 0)
+ // qWarning() << "no timing info from pulse";
+
+ return usecs;
+}
+
+void QPulseAudioSource::suspend()
+{
+ if (auto notifier = m_stateMachine.suspend()) {
+ m_timer.stop();
+
+ QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
+
+ std::lock_guard lock(*pulseEngine);
+
+ PAOperationUPtr operation(pa_stream_cork(m_stream, 1, inputStreamSuccessCallback, nullptr));
+ pulseEngine->wait(operation.get());
+ }
+}
+
+void QPulseAudioSource::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == m_timer.timerId())
+ userFeed();
+
+ QPlatformAudioSource::timerEvent(event);
+}
+
+void QPulseAudioSource::userFeed()
+{
+ if (!m_stateMachine.isActiveOrIdle())
+ return;
+
+ //if (Q_UNLIKELY(qLcPulseAudioIn().isEnabled(QtDebugMsg)) {
+ // QTime now(QTime::currentTime());
+ // qCDebug(qLcPulseAudioIn) << now.second() << "s " << now.msec() << "ms :userFeed() IN";
+ //}
+
+ if (m_pullMode) {
+ // reads some audio data and writes it to QIODevice
+ read(nullptr,0);
+ } else if (m_audioSource != nullptr) {
+ // emits readyRead() so user will call read() on QIODevice to get some audio data
+ PulseInputPrivate *a = qobject_cast<PulseInputPrivate*>(m_audioSource);
+ a->trigger();
+ }
+}
+
+void QPulseAudioSource::reset()
+{
+ if (auto notifier = m_stateMachine.stopOrUpdateError())
+ close();
+}
+
+void QPulseAudioSource::onPulseContextFailed()
+{
+ if (auto notifier = m_stateMachine.stopOrUpdateError(QAudio::FatalError))
+ close();
+}
+
+PulseInputPrivate::PulseInputPrivate(QPulseAudioSource *audio)
+{
+ m_audioDevice = qobject_cast<QPulseAudioSource *>(audio);
+}
+
+qint64 PulseInputPrivate::readData(char *data, qint64 len)
+{
+ return m_audioDevice->read(data, len);
+}
+
+qint64 PulseInputPrivate::writeData(const char *data, qint64 len)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(len);
+ return 0;
+}
+
+void PulseInputPrivate::trigger()
+{
+ emit readyRead();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qpulseaudiosource_p.cpp"
diff --git a/src/multimedia/pulseaudio/qpulseaudiosource_p.h b/src/multimedia/pulseaudio/qpulseaudiosource_p.h
new file mode 100644
index 000000000..d652f81a0
--- /dev/null
+++ b/src/multimedia/pulseaudio/qpulseaudiosource_p.h
@@ -0,0 +1,116 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QAUDIOINPUTPULSE_H
+#define QAUDIOINPUTPULSE_H
+
+#include <QtCore/qfile.h>
+#include <QtCore/qtimer.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qelapsedtimer.h>
+#include <QtCore/qiodevice.h>
+
+#include "qaudio.h"
+#include "qaudiodevice.h"
+#include <private/qaudiosystem_p.h>
+#include <private/qaudiostatemachine_p.h>
+
+#include <pulse/pulseaudio.h>
+
+QT_BEGIN_NAMESPACE
+
+class PulseInputPrivate;
+
+class QPulseAudioSource : public QPlatformAudioSource
+{
+ Q_OBJECT
+
+public:
+ QPulseAudioSource(const QByteArray &device, QObject *parent);
+ ~QPulseAudioSource();
+
+ qint64 read(char *data, qint64 len);
+
+ void start(QIODevice *device) override;
+ QIODevice *start() override;
+ void stop() override;
+ void reset() override;
+ void suspend() override;
+ void resume() override;
+ qsizetype bytesReady() const override;
+ void setBufferSize(qsizetype value) override;
+ qsizetype bufferSize() const override;
+ qint64 processedUSecs() const override;
+ QAudio::Error error() const override;
+ QAudio::State state() const override;
+ void setFormat(const QAudioFormat &format) override;
+ QAudioFormat format() const override;
+
+ void setVolume(qreal volume) override;
+ qreal volume() const override;
+
+ qint64 m_totalTimeValue;
+ QIODevice *m_audioSource;
+ QAudioFormat m_format;
+ qreal m_volume;
+
+protected:
+ void timerEvent(QTimerEvent *event) override;
+
+private slots:
+ void userFeed();
+ void onPulseContextFailed();
+
+private:
+ void applyVolume(const void *src, void *dest, int len);
+
+ bool open();
+ void close();
+
+ bool m_pullMode;
+ bool m_opened;
+ int m_bufferSize;
+ int m_periodSize;
+ unsigned int m_periodTime;
+ QBasicTimer m_timer;
+ qint64 m_elapsedTimeOffset;
+ pa_stream *m_stream;
+ QByteArray m_streamName;
+ QByteArray m_device;
+ QByteArray m_tempBuffer;
+ pa_sample_spec m_spec;
+
+ QAudioStateMachine m_stateMachine;
+};
+
+class PulseInputPrivate : public QIODevice
+{
+ Q_OBJECT
+public:
+ PulseInputPrivate(QPulseAudioSource *audio);
+ ~PulseInputPrivate() override = default;
+
+ qint64 readData(char *data, qint64 len) override;
+ qint64 writeData(const char *data, qint64 len) override;
+
+ void trigger();
+
+private:
+ QPulseAudioSource *m_audioDevice;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/pulseaudio/qpulsehelpers.cpp b/src/multimedia/pulseaudio/qpulsehelpers.cpp
new file mode 100644
index 000000000..bc03e133f
--- /dev/null
+++ b/src/multimedia/pulseaudio/qpulsehelpers.cpp
@@ -0,0 +1,284 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qpulsehelpers_p.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(qLcPulseAudioOut, "qt.multimedia.pulseaudio.output")
+Q_LOGGING_CATEGORY(qLcPulseAudioIn, "qt.multimedia.pulseaudio.input")
+Q_LOGGING_CATEGORY(qLcPulseAudioEngine, "qt.multimedia.pulseaudio.engine")
+
+namespace QPulseAudioInternal
+{
+pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format)
+{
+ pa_sample_spec spec;
+
+ spec.rate = format.sampleRate();
+ spec.channels = format.channelCount();
+ spec.format = PA_SAMPLE_INVALID;
+ const bool isBigEndian = QSysInfo::ByteOrder == QSysInfo::BigEndian;
+
+ if (format.sampleFormat() == QAudioFormat::UInt8) {
+ spec.format = PA_SAMPLE_U8;
+ } else if (format.sampleFormat() == QAudioFormat::Int16) {
+ spec.format = isBigEndian ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE;
+ } else if (format.sampleFormat() == QAudioFormat::Int32) {
+ spec.format = isBigEndian ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE;
+ } else if (format.sampleFormat() == QAudioFormat::Float) {
+ spec.format = isBigEndian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE;
+ }
+
+ return spec;
+}
+
+pa_channel_map channelMapForAudioFormat(const QAudioFormat &format)
+{
+ pa_channel_map map;
+ map.channels = 0;
+
+ auto config = format.channelConfig();
+ if (config == QAudioFormat::ChannelConfigUnknown)
+ config = QAudioFormat::defaultChannelConfigForChannelCount(format.channelCount());
+
+ if (config == QAudioFormat::ChannelConfigMono) {
+ map.channels = 1;
+ map.map[0] = PA_CHANNEL_POSITION_MONO;
+ } else {
+ if (config & QAudioFormat::channelConfig(QAudioFormat::FrontLeft))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_FRONT_LEFT;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::FrontRight))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_FRONT_RIGHT;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::FrontCenter))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_FRONT_CENTER;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::LFE))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_LFE;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::BackLeft))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_REAR_LEFT;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::BackRight))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_REAR_RIGHT;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::FrontLeftOfCenter))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::FrontRightOfCenter))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::BackCenter))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_REAR_CENTER;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::LFE2))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_LFE;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::SideLeft))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_SIDE_LEFT;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::SideRight))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_SIDE_RIGHT;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::TopFrontLeft))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_TOP_FRONT_LEFT;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::TopFrontRight))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_TOP_FRONT_RIGHT;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::TopFrontCenter))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_TOP_FRONT_CENTER;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::TopCenter))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_TOP_CENTER;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::TopBackLeft))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_TOP_REAR_LEFT;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::TopBackRight))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_TOP_REAR_RIGHT;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::TopSideLeft))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_AUX0;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::TopSideRight))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_AUX1;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::TopBackCenter))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_TOP_REAR_CENTER;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::BottomFrontCenter))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_AUX2;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::BottomFrontLeft))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_AUX3;
+ if (config & QAudioFormat::channelConfig(QAudioFormat::BottomFrontRight))
+ map.map[map.channels++] = PA_CHANNEL_POSITION_AUX4;
+ }
+
+ Q_ASSERT(qPopulationCount(config) == map.channels);
+ return map;
+}
+
+QAudioFormat::ChannelConfig channelConfigFromMap(const pa_channel_map &map)
+{
+ quint32 config = 0;
+ for (int i = 0; i < map.channels; ++i) {
+ switch (map.map[i]) {
+ case PA_CHANNEL_POSITION_MONO:
+ case PA_CHANNEL_POSITION_FRONT_CENTER:
+ config |= QAudioFormat::channelConfig(QAudioFormat::FrontCenter);
+ break;
+ case PA_CHANNEL_POSITION_FRONT_LEFT:
+ config |= QAudioFormat::channelConfig(QAudioFormat::FrontLeft);
+ break;
+ case PA_CHANNEL_POSITION_FRONT_RIGHT:
+ config |= QAudioFormat::channelConfig(QAudioFormat::FrontRight);
+ break;
+ case PA_CHANNEL_POSITION_REAR_CENTER:
+ config |= QAudioFormat::channelConfig(QAudioFormat::BackCenter);
+ break;
+ case PA_CHANNEL_POSITION_REAR_LEFT:
+ config |= QAudioFormat::channelConfig(QAudioFormat::BackLeft);
+ break;
+ case PA_CHANNEL_POSITION_REAR_RIGHT:
+ config |= QAudioFormat::channelConfig(QAudioFormat::BackRight);
+ break;
+ case PA_CHANNEL_POSITION_LFE:
+ config |= QAudioFormat::channelConfig(QAudioFormat::LFE);
+ break;
+ case PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER:
+ config |= QAudioFormat::channelConfig(QAudioFormat::FrontLeftOfCenter);
+ break;
+ case PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER:
+ config |= QAudioFormat::channelConfig(QAudioFormat::FrontRightOfCenter);
+ break;
+ case PA_CHANNEL_POSITION_SIDE_LEFT:
+ config |= QAudioFormat::channelConfig(QAudioFormat::SideLeft);
+ break;
+ case PA_CHANNEL_POSITION_SIDE_RIGHT:
+ config |= QAudioFormat::channelConfig(QAudioFormat::SideRight);
+ break;
+
+ case PA_CHANNEL_POSITION_TOP_CENTER:
+ config |= QAudioFormat::channelConfig(QAudioFormat::TopCenter);
+ break;
+ case PA_CHANNEL_POSITION_TOP_FRONT_LEFT:
+ config |= QAudioFormat::channelConfig(QAudioFormat::TopFrontLeft);
+ break;
+ case PA_CHANNEL_POSITION_TOP_FRONT_RIGHT:
+ config |= QAudioFormat::channelConfig(QAudioFormat::TopFrontRight);
+ break;
+ case PA_CHANNEL_POSITION_TOP_FRONT_CENTER:
+ config |= QAudioFormat::channelConfig(QAudioFormat::TopFrontCenter);
+ break;
+ case PA_CHANNEL_POSITION_TOP_REAR_LEFT:
+ config |= QAudioFormat::channelConfig(QAudioFormat::TopBackLeft);
+ break;
+ case PA_CHANNEL_POSITION_TOP_REAR_RIGHT:
+ config |= QAudioFormat::channelConfig(QAudioFormat::TopBackRight);
+ break;
+ case PA_CHANNEL_POSITION_TOP_REAR_CENTER:
+ config |= QAudioFormat::channelConfig(QAudioFormat::TopBackCenter);
+ break;
+ default:
+ break;
+ }
+ }
+ return QAudioFormat::ChannelConfig(config);
+}
+
+QAudioFormat sampleSpecToAudioFormat(const pa_sample_spec &spec)
+{
+ QAudioFormat format;
+
+ format.setSampleRate(spec.rate);
+ format.setChannelCount(spec.channels);
+ QAudioFormat::SampleFormat sampleFormat;
+ switch (spec.format) {
+ case PA_SAMPLE_U8:
+ sampleFormat = QAudioFormat::UInt8;
+ break;
+ case PA_SAMPLE_S16LE:
+ case PA_SAMPLE_S16BE:
+ sampleFormat = QAudioFormat::Int16;
+ break;
+ case PA_SAMPLE_FLOAT32LE:
+ case PA_SAMPLE_FLOAT32BE:
+ sampleFormat = QAudioFormat::Float;
+ break;
+ case PA_SAMPLE_S32LE:
+ case PA_SAMPLE_S32BE:
+ sampleFormat = QAudioFormat::Int32;
+ break;
+ default:
+ return {};
+ }
+
+ format.setSampleFormat(sampleFormat);
+ return format;
+}
+
+QUtf8StringView currentError(const pa_context *context)
+{
+ return pa_strerror(pa_context_errno(context));
+}
+
+QUtf8StringView currentError(const pa_stream *stream)
+{
+ return currentError(pa_stream_get_context(stream));
+}
+
+} // namespace QPulseAudioInternal
+
+static QLatin1StringView stateToQStringView(pa_stream_state_t state)
+{
+ using namespace Qt::StringLiterals;
+ switch (state)
+ {
+ case PA_STREAM_UNCONNECTED: return "Unconnected"_L1;
+ case PA_STREAM_CREATING: return "Creating"_L1;
+ case PA_STREAM_READY: return "Ready"_L1;
+ case PA_STREAM_FAILED: return "Failed"_L1;
+ case PA_STREAM_TERMINATED: return "Terminated"_L1;
+ default: Q_UNREACHABLE_RETURN("Unknown stream state"_L1);
+ }
+}
+
+static QLatin1StringView sampleFormatToQStringView(pa_sample_format format)
+{
+ using namespace Qt::StringLiterals;
+ switch (format)
+ {
+ case PA_SAMPLE_U8: return "Unsigned 8 Bit PCM."_L1;
+ case PA_SAMPLE_ALAW: return "8 Bit a-Law "_L1;
+ case PA_SAMPLE_ULAW: return "8 Bit mu-Law"_L1;
+ case PA_SAMPLE_S16LE: return "Signed 16 Bit PCM, little endian (PC)."_L1;
+ case PA_SAMPLE_S16BE: return "Signed 16 Bit PCM, big endian."_L1;
+ case PA_SAMPLE_FLOAT32LE: return "32 Bit IEEE floating point, little endian (PC), range -1.0 to 1.0"_L1;
+ case PA_SAMPLE_FLOAT32BE: return "32 Bit IEEE floating point, big endian, range -1.0 to 1.0"_L1;
+ case PA_SAMPLE_S32LE: return "Signed 32 Bit PCM, little endian (PC)."_L1;
+ case PA_SAMPLE_S32BE: return "Signed 32 Bit PCM, big endian."_L1;
+ case PA_SAMPLE_S24LE: return "Signed 24 Bit PCM packed, little endian (PC)."_L1;
+ case PA_SAMPLE_S24BE: return "Signed 24 Bit PCM packed, big endian."_L1;
+ case PA_SAMPLE_S24_32LE: return "Signed 24 Bit PCM in LSB of 32 Bit words, little endian (PC)."_L1;
+ case PA_SAMPLE_S24_32BE: return "Signed 24 Bit PCM in LSB of 32 Bit words, big endian."_L1;
+ case PA_SAMPLE_MAX: return "Upper limit of valid sample types."_L1;
+ case PA_SAMPLE_INVALID: return "Invalid sample format"_L1;
+ default: Q_UNREACHABLE_RETURN("Unknown sample format"_L1);
+ }
+}
+
+static QLatin1StringView stateToQStringView(pa_context_state_t state)
+{
+ using namespace Qt::StringLiterals;
+ switch (state)
+ {
+ case PA_CONTEXT_UNCONNECTED: return "Unconnected"_L1;
+ case PA_CONTEXT_CONNECTING: return "Connecting"_L1;
+ case PA_CONTEXT_AUTHORIZING: return "Authorizing"_L1;
+ case PA_CONTEXT_SETTING_NAME: return "Setting Name"_L1;
+ case PA_CONTEXT_READY: return "Ready"_L1;
+ case PA_CONTEXT_FAILED: return "Failed"_L1;
+ case PA_CONTEXT_TERMINATED: return "Terminated"_L1;
+ default: Q_UNREACHABLE_RETURN("Unknown context state"_L1);
+ }
+}
+
+
+QDebug operator<<(QDebug dbg, pa_stream_state_t state)
+{
+ return dbg << stateToQStringView(state);
+}
+
+QDebug operator<<(QDebug dbg, pa_sample_format format)
+{
+ return dbg << sampleFormatToQStringView(format);
+}
+
+QDebug operator<<(QDebug dbg, pa_context_state_t state)
+{
+ return dbg << stateToQStringView(state);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/pulseaudio/qpulsehelpers_p.h b/src/multimedia/pulseaudio/qpulsehelpers_p.h
new file mode 100644
index 000000000..d271fde48
--- /dev/null
+++ b/src/multimedia/pulseaudio/qpulsehelpers_p.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPULSEHELPER_H
+#define QPULSEHELPER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qaudiodevice.h"
+#include <qaudioformat.h>
+#include <pulse/pulseaudio.h>
+#include <QtCore/QLoggingCategory>
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qLcPulseAudioOut)
+Q_DECLARE_LOGGING_CATEGORY(qLcPulseAudioIn)
+Q_DECLARE_LOGGING_CATEGORY(qLcPulseAudioEngine)
+
+struct PAOperationDeleter
+{
+ void operator()(pa_operation *op) const { pa_operation_unref(op); }
+};
+
+using PAOperationUPtr = std::unique_ptr<pa_operation, PAOperationDeleter>;
+
+namespace QPulseAudioInternal
+{
+pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format);
+QAudioFormat sampleSpecToAudioFormat(const pa_sample_spec &spec);
+pa_channel_map channelMapForAudioFormat(const QAudioFormat &format);
+QAudioFormat::ChannelConfig channelConfigFromMap(const pa_channel_map &map);
+
+QUtf8StringView currentError(const pa_context *);
+QUtf8StringView currentError(const pa_stream *);
+
+} // namespace QPulseAudioInternal
+
+QDebug operator<<(QDebug, pa_stream_state_t);
+QDebug operator<<(QDebug, pa_sample_format);
+QDebug operator<<(QDebug, pa_context_state_t);
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/qerrorinfo_p.h b/src/multimedia/qerrorinfo_p.h
new file mode 100644
index 000000000..6428cb00f
--- /dev/null
+++ b/src/multimedia/qerrorinfo_p.h
@@ -0,0 +1,57 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QERRORINFO_P_H
+#define QERRORINFO_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QString>
+
+QT_BEGIN_NAMESPACE
+
+template <typename ErrorCode, ErrorCode NoError = ErrorCode::NoError>
+class QErrorInfo
+{
+public:
+ QErrorInfo(ErrorCode error = NoError, QString description = {})
+ : m_code(error), m_description(std::move(description))
+ {
+ }
+
+ template <typename Notifier>
+ void setAndNotify(ErrorCode code, QString description, Notifier &notifier)
+ {
+ const bool changed = code != m_code || description != m_description;
+
+ m_code = code;
+ m_description = std::move(description);
+
+ if (code != NoError)
+ emit notifier.errorOccurred(m_code, m_description);
+
+ if (changed)
+ emit notifier.errorChanged();
+ }
+
+ ErrorCode code() const { return m_code; }
+ QString description() const { return m_description; };
+
+private:
+ ErrorCode m_code;
+ QString m_description;
+};
+
+QT_END_NAMESPACE
+
+#endif // QERRORINFO_P_H
diff --git a/src/multimedia/qmaybe_p.h b/src/multimedia/qmaybe_p.h
new file mode 100644
index 000000000..5fe2d4d6c
--- /dev/null
+++ b/src/multimedia/qmaybe_p.h
@@ -0,0 +1,96 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QMAYBE_P_H
+#define QMAYBE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/private/qglobal_p.h>
+#include <qstring.h>
+#include <optional>
+#include <utility>
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+struct QUnexpect
+{
+};
+
+static constexpr QUnexpect unexpect{};
+
+template <typename Value, typename Error = QString>
+class QMaybe
+{
+public:
+ QMaybe(const Value &v)
+ {
+ if constexpr (std::is_pointer_v<Value>) {
+ if (!v)
+ return; // nullptr is treated as nullopt (for raw pointer types only)
+ }
+ m_value = v;
+ }
+
+ QMaybe(Value &&v)
+ {
+ if constexpr (std::is_pointer_v<Value>) {
+ if (!v)
+ return; // nullptr is treated as nullopt (for raw pointer types only)
+ }
+ m_value = std::move(v);
+ }
+
+ QMaybe(const QMaybe &other) = default;
+
+ QMaybe &operator=(const QMaybe &other) = default;
+
+ QMaybe(const Error &error) : m_error(error) { }
+
+ template <class... Args>
+ QMaybe(QUnexpect, Args &&...args) : m_error{ std::forward<Args>(args)... }
+ {
+ static_assert(std::is_constructible_v<Error, Args &&...>,
+ "Invalid arguments for creating an error type");
+ }
+
+ constexpr explicit operator bool() const noexcept { return m_value.has_value(); }
+
+ constexpr Value &value()
+ {
+ Q_ASSERT(m_value.has_value());
+ return *m_value;
+ }
+
+ constexpr const Value &value() const
+ {
+ Q_ASSERT(m_value.has_value());
+ return *m_value;
+ }
+
+ constexpr Value *operator->() noexcept { return std::addressof(value()); }
+ constexpr const Value *operator->() const noexcept { return std::addressof(value()); }
+
+ constexpr Value &operator*() &noexcept { return value(); }
+ constexpr const Value &operator*() const &noexcept { return value(); }
+
+ constexpr const Error &error() const { return m_error; }
+
+private:
+ std::optional<Value> m_value;
+ Error m_error;
+};
+
+QT_END_NAMESPACE
+
+#endif // QMAYBE_P_H
diff --git a/src/multimedia/qmediabindableinterface.cpp b/src/multimedia/qmediabindableinterface.cpp
deleted file mode 100644
index 8a6b9fadd..000000000
--- a/src/multimedia/qmediabindableinterface.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qmediabindableinterface.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QMediaBindableInterface
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_core
-
-
- \brief The QMediaBindableInterface class is the base class for objects extending media objects functionality.
-
- \sa
-*/
-
-/*!
- Destroys a media helper object.
-*/
-
-QMediaBindableInterface::~QMediaBindableInterface()
-{
-}
-
-/*!
- \fn QMediaBindableInterface::mediaObject() const;
-
- Return the currently attached media object.
-*/
-
-
-/*!
- \fn QMediaBindableInterface::setMediaObject(QMediaObject *object);
-
- Attaches to the media \a object.
- Returns true if attached successfully, otherwise returns false.
-*/
-
-
-
-QT_END_NAMESPACE
-
diff --git a/src/multimedia/qmediabindableinterface.h b/src/multimedia/qmediabindableinterface.h
deleted file mode 100644
index ce0d0822e..000000000
--- a/src/multimedia/qmediabindableinterface.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIABINDABLEINTERFACE_H
-#define QMEDIABINDABLEINTERFACE_H
-
-#include <QtMultimedia/qmediaobject.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaObject;
-
-class Q_MULTIMEDIA_EXPORT QMediaBindableInterface
-{
-public:
- virtual ~QMediaBindableInterface();
-
- virtual QMediaObject *mediaObject() const = 0;
-
-protected:
- friend class QMediaObject;
- virtual bool setMediaObject(QMediaObject *object) = 0;
-};
-
-#define QMediaBindableInterface_iid \
- "org.qt-project.qt.mediabindable/5.0"
-Q_DECLARE_INTERFACE(QMediaBindableInterface, QMediaBindableInterface_iid)
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIABINDABLEINTERFACE_H
diff --git a/src/multimedia/qmediacontrol.cpp b/src/multimedia/qmediacontrol.cpp
deleted file mode 100644
index 6f0a980a2..000000000
--- a/src/multimedia/qmediacontrol.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qmetaobject.h>
-#include <QtCore/qtimer.h>
-
-#include "qmediacontrol.h"
-#include "qmediacontrol_p.h"
-
-
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QMediaControl
- \obsolete
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_control
- \ingroup multimedia_core
-
- \brief The QMediaControl class provides a base interface for media service controls.
-
- Media controls provide an interface to individual features provided by a
- media service. Most services implement a principal control which exposes
- the core functionality of the service and a number of optional controls which
- expose any additional functionality.
-
- A pointer to a control implemented by a media service can be obtained using
- the \l {QMediaService::requestControl()} member of QMediaService. If the
- service doesn't implement a control it will instead return a null pointer.
-
- \snippet multimedia-snippets/media.cpp Request control
-
- Alternatively if the IId of the control has been declared using
- Q_MEDIA_DECLARE_CONTROL the template version of
- QMediaService::requestControl() can be used to request the service without
- explicitly passing the IId or using qobject_cast().
-
- \snippet multimedia-snippets/media.cpp Request control templated
-
- Most application code will not interface directly with a media service's
- controls, instead the QMediaObject which owns the service acts as an
- intermediary between one or more controls and the application.
-
- \sa QMediaService, QMediaObject
-*/
-
-/*!
- \macro Q_MEDIA_DECLARE_CONTROL(Class, IId)
- \relates QMediaControl
-
- The Q_MEDIA_DECLARE_CONTROL macro declares an \a IId for a \a Class that
- inherits from QMediaControl.
-
- Declaring an IId for a QMediaControl allows an instance of that control to
- be requested from QMediaService::requestControl() without explicitly
- passing the IId.
-
- \snippet multimedia-snippets/media.cpp Request control templated
-
- \sa QMediaService::requestControl()
-*/
-
-/*!
- Destroys a media control.
-*/
-
-QMediaControl::~QMediaControl()
-{
- delete d_ptr;
-}
-
-/*!
- Constructs a media control with the given \a parent.
-*/
-
-QMediaControl::QMediaControl(QObject *parent)
- : QObject(parent)
- , d_ptr(new QMediaControlPrivate)
-{
- d_ptr->q_ptr = this;
-}
-
-/*!
- \internal
-*/
-
-QMediaControl::QMediaControl(QMediaControlPrivate &dd, QObject *parent)
- : QObject(parent)
- , d_ptr(&dd)
-
-{
- d_ptr->q_ptr = this;
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qmediacontrol.cpp"
diff --git a/src/multimedia/qmediacontrol.h b/src/multimedia/qmediacontrol.h
deleted file mode 100644
index 48ae44f8a..000000000
--- a/src/multimedia/qmediacontrol.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QABSTRACTMEDIACONTROL_H
-#define QABSTRACTMEDIACONTROL_H
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-
-#include <QtCore/qobject.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qvariant.h>
-
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaControlPrivate;
-class Q_MULTIMEDIA_EXPORT QMediaControl : public QObject
-{
- Q_OBJECT
-
-public:
- ~QMediaControl();
-
-protected:
- explicit QMediaControl(QObject *parent = nullptr);
- explicit QMediaControl(QMediaControlPrivate &dd, QObject *parent = nullptr);
-
- QMediaControlPrivate *d_ptr;
-
-private:
- Q_DECLARE_PRIVATE(QMediaControl)
-};
-
-template <typename T> const char *qmediacontrol_iid() { return nullptr; }
-
-#define Q_MEDIA_DECLARE_CONTROL(Class, IId) \
- template <> inline const char *qmediacontrol_iid<Class *>() { return IId; }
-
-QT_END_NAMESPACE
-
-
-#endif // QABSTRACTMEDIACONTROL_H
diff --git a/src/multimedia/qmediacontrol_p.h b/src/multimedia/qmediacontrol_p.h
deleted file mode 100644
index e9827fd1e..000000000
--- a/src/multimedia/qmediacontrol_p.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QABSTRACTMEDIACONTROL_P_H
-#define QABSTRACTMEDIACONTROL_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <qtmultimediaglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaControl;
-
-class QMediaControlPrivate
-{
-public:
- virtual ~QMediaControlPrivate() {}
-
- QMediaControl *q_ptr;
-};
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/multimedia/qmediadevices.cpp b/src/multimedia/qmediadevices.cpp
new file mode 100644
index 000000000..1d77f4de8
--- /dev/null
+++ b/src/multimedia/qmediadevices.cpp
@@ -0,0 +1,288 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qmediadevices.h"
+#include "private/qplatformmediaintegration_p.h"
+#include "private/qplatformmediadevices_p.h"
+
+#include <qaudiodevice.h>
+#include <qcameradevice.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QMediaDevices
+ \brief The QMediaDevices class provides information about available
+ multimedia input and output devices.
+ \ingroup multimedia
+ \inmodule QtMultimedia
+
+ The QMediaDevices class provides information about the available multimedia
+ devices and the system defaults. It monitors the following three groups:
+ \list
+ \li Audio input devices (Microphones)
+ \li Audio output devices (Speakers, Headsets)
+ \li Video input devices (Cameras)
+ \endlist
+
+ QMediaDevices provides a separate list for each device group. If it detects that a
+ new device has been connected to the system or an attached device has been disconnected
+ from the system, it will update the corresponding device list and emit a signal
+ notifying about the change.
+
+ The QMediaDevices::audioInputs and QMediaDevices::audioOutputs functions can be used
+ to enumerate all microphones and speakers/headsets on the system. This example first
+ gets a list of all connected microphones, and then prints their identifier, description,
+ and if it is the default device or not.
+
+ \snippet multimedia-snippets/devices.cpp Media Audio Input Device Enumeration
+
+ Similarly, the QMediaDevices::videoInputs will return a list of all connected cameras.
+ In this example we list all connected cameras and their identifier, description, and
+ if it is the default camera or not.
+
+ \snippet multimedia-snippets/devices.cpp Media Video Input Device Enumeration
+
+ QMediaDevices monitors the system defaults for each device group. It will notify about
+ any changes done through the system settings. For example, if the user selects a new
+ default audio output in the system settings, QMediaDevices will update the default audio
+ output accordingly and emit a signal. If the system does not provide a default for a
+ camera or an audio input, QMediaDevices will select the first device from the list as
+ the default device.
+
+ While using the default input and output devices is often sufficient for
+ playing back or recording multimedia, there is often a need to explicitly
+ select the device to be used.
+
+ QMediaDevices is a singleton object and all getters are thread-safe.
+*/
+
+/*!
+ \qmltype MediaDevices
+ \since 6.2
+ \instantiates QMediaDevices
+ \brief MediaDevices provides information about available
+ multimedia input and output devices.
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+
+ The MediaDevices type provides information about the available multimedia
+ devices and the system defaults. It monitors the following three groups:
+ \list
+ \li Audio input devices (Microphones)
+ \li Audio output devices (Speakers, Headsets)
+ \li Video input devices (Cameras)
+ \endlist
+
+ MediaDevices provides a separate list for each device group. If it detects that a
+ new device has been connected to the system or an attached device has been disconnected
+ from the system, it will update the corresponding device list and emit a signal
+ notifying about the change.
+
+ MediaDevices monitors the system defaults for each device group. It will notify about
+ any changes done through the system settings. For example, if the user selects a new
+ default audio output in the system settings, MediaDevices will update the default audio
+ output accordingly and emit a signal. If the system does not provide a default for a
+ camera or an audio input, MediaDevices will select the first device from the list as
+ the default device.
+
+ While using the default input and output devices is often sufficient for
+ playing back or recording multimedia, there is often a need to explicitly
+ select the device to be used.
+
+ For example, the snippet below will ensure that the media player always uses
+ the systems default audio output device for playback:
+
+ \qml
+ MediaDevices {
+ id: devices
+ }
+ MediaPlayer {
+ ...
+ audioOutput: AudioOutput {
+ device: devices.defaultAudioOutput
+ }
+ }
+ \endqml
+
+ \sa Camera, AudioInput, VideoOutput
+*/
+
+/*!
+ \qmlproperty list<audioDevice> QtMultimedia::MediaDevices::audioInputs
+ Contains a list of available audio input devices on the system.
+
+ Those devices are usually microphones. Devices can be either built-in, or
+ connected through for example USB or Bluetooth.
+*/
+
+/*!
+ \property QMediaDevices::audioInputs
+
+ Returns a list of available audio input devices on the system.
+
+ Those devices are usually microphones. Devices can be either built-in, or
+ connected through for example USB or Bluetooth.
+*/
+QList<QAudioDevice> QMediaDevices::audioInputs()
+{
+ return QPlatformMediaIntegration::instance()->mediaDevices()->audioInputs();
+}
+
+/*!
+ \qmlproperty list<audioDevice> QtMultimedia::MediaDevices::audioOutputs
+ Contains a list of available audio output devices on the system.
+
+ Those devices are usually loudspeakers or head sets. Devices can be either
+ built-in, or connected through for example USB or Bluetooth.
+*/
+
+/*!
+ \property QMediaDevices::audioOutputs
+
+ Returns a list of available audio output devices on the system.
+
+ Those devices are usually loudspeakers or head sets. Devices can be either
+ built-in, or connected through for example USB or Bluetooth.
+*/
+QList<QAudioDevice> QMediaDevices::audioOutputs()
+{
+ return QPlatformMediaIntegration::instance()->mediaDevices()->audioOutputs();
+}
+
+/*!
+ \qmlproperty list<cameraDevice> QtMultimedia::MediaDevices::videoInputs
+ Contains a list of cameras on the system.
+*/
+
+/*!
+ \property QMediaDevices::videoInputs
+
+ Returns a list of available cameras on the system.
+*/
+QList<QCameraDevice> QMediaDevices::videoInputs()
+{
+ QPlatformMediaIntegration::instance()->mediaDevices()->initVideoDevicesConnection();
+ return QPlatformMediaIntegration::instance()->videoInputs();
+}
+
+/*!
+ \qmlproperty audioDevice QtMultimedia::MediaDevices::defaultAudioInput
+ Returns the default audio input device.
+
+ The default device can change during the runtime of the application. The value
+ of this property will automatically adjust itself to such changes.
+*/
+
+/*!
+ \property QMediaDevices::defaultAudioInput
+
+ Returns the default audio input device.
+
+ The default device can change during the runtime of the application.
+ The audioInputsChanged() signal is emitted in this case.
+*/
+QAudioDevice QMediaDevices::defaultAudioInput()
+{
+ const auto inputs = audioInputs();
+ if (inputs.isEmpty())
+ return {};
+ for (const auto &info : inputs)
+ if (info.isDefault())
+ return info;
+ return inputs.value(0);
+}
+
+/*!
+ \qmlproperty audioDevice QtMultimedia::MediaDevices::defaultAudioOutput
+ Returns the default audio output device.
+
+ The default device can change during the runtime of the application. The value
+ of this property will automatically adjust itself to such changes.
+*/
+
+/*!
+ \property QMediaDevices::defaultAudioOutput
+
+ Returns the default audio output device.
+
+ The default device can change during the runtime of the application. The
+ audioOutputsChanged() signal is emitted in this case.
+*/
+QAudioDevice QMediaDevices::defaultAudioOutput()
+{
+ const auto outputs = audioOutputs();
+ if (outputs.isEmpty())
+ return {};
+ for (const auto &info : outputs)
+ if (info.isDefault())
+ return info;
+ return outputs.value(0);
+}
+
+/*!
+ \qmlproperty cameraDevice QtMultimedia::MediaDevices::defaultVideoInput
+ Returns the default camera on the system.
+
+ \note The returned object should be checked using isNull() before being used,
+ in case there is no camera available.
+
+ The default device can change during the runtime of the application. The value
+ of this property will automatically adjust itself to such changes.
+*/
+
+/*!
+ \property QMediaDevices::defaultVideoInput
+
+ Returns the default camera on the system.
+
+ \note The returned object should be checked using isNull() before being used,
+ in case there is no default camera or no cameras at all.
+
+ The default device can change during the runtime of the application. The
+ videoInputsChanged() signal is emitted in that case.
+
+ \sa videoInputs()
+*/
+QCameraDevice QMediaDevices::defaultVideoInput()
+{
+ const auto inputs = videoInputs();
+ if (inputs.isEmpty())
+ return {};
+ for (const auto &info : inputs)
+ if (info.isDefault())
+ return info;
+ return inputs.value(0);
+}
+
+/*!
+ \internal
+*/
+QMediaDevices::QMediaDevices(QObject *parent)
+ : QObject(parent)
+{
+ auto platformDevices = QPlatformMediaIntegration::instance()->mediaDevices();
+ connect(platformDevices, &QPlatformMediaDevices::videoInputsChanged, this,
+ &QMediaDevices::videoInputsChanged);
+ connect(platformDevices, &QPlatformMediaDevices::audioInputsChanged, this,
+ &QMediaDevices::audioInputsChanged);
+ connect(platformDevices, &QPlatformMediaDevices::audioOutputsChanged, this,
+ &QMediaDevices::audioOutputsChanged);
+}
+
+/*!
+ \internal
+*/
+QMediaDevices::~QMediaDevices() = default;
+
+void QMediaDevices::connectNotify(const QMetaMethod &signal)
+{
+ if (signal == QMetaMethod::fromSignal(&QMediaDevices::videoInputsChanged))
+ QPlatformMediaIntegration::instance()->mediaDevices()->initVideoDevicesConnection();
+
+ QObject::connectNotify(signal);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qmediadevices.cpp"
diff --git a/src/multimedia/qmediadevices.h b/src/multimedia/qmediadevices.h
new file mode 100644
index 000000000..832799095
--- /dev/null
+++ b/src/multimedia/qmediadevices.h
@@ -0,0 +1,56 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QMEDIADEVICES_H
+#define QMEDIADEVICES_H
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtCore/qobject.h>
+#include <QtCore/qstringlist.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioDevice;
+class QCameraDevice;
+
+class QMediaDevicesPrivate;
+
+class Q_MULTIMEDIA_EXPORT QMediaDevices : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QList<QAudioDevice> audioInputs READ audioInputs NOTIFY audioInputsChanged)
+ Q_PROPERTY(QList<QAudioDevice> audioOutputs READ audioOutputs NOTIFY audioOutputsChanged)
+ Q_PROPERTY(QList<QCameraDevice> videoInputs READ videoInputs NOTIFY videoInputsChanged)
+ Q_PROPERTY(QAudioDevice defaultAudioInput READ defaultAudioInput NOTIFY audioInputsChanged)
+ Q_PROPERTY(QAudioDevice defaultAudioOutput READ defaultAudioOutput NOTIFY audioOutputsChanged)
+ Q_PROPERTY(QCameraDevice defaultVideoInput READ defaultVideoInput NOTIFY videoInputsChanged)
+
+public:
+ QMediaDevices(QObject *parent = nullptr);
+ ~QMediaDevices();
+
+ static QList<QAudioDevice> audioInputs();
+ static QList<QAudioDevice> audioOutputs();
+ static QList<QCameraDevice> videoInputs();
+
+ static QAudioDevice defaultAudioInput();
+ static QAudioDevice defaultAudioOutput();
+ static QCameraDevice defaultVideoInput();
+
+Q_SIGNALS:
+ void audioInputsChanged();
+ void audioOutputsChanged();
+ void videoInputsChanged();
+
+protected:
+ void connectNotify(const QMetaMethod &signal) override;
+
+private:
+ friend class QMediaDevicesPrivate;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QABSTRACTMEDIASERVICE_H
+
diff --git a/src/multimedia/qmediaenumdebug.h b/src/multimedia/qmediaenumdebug.h
index 6fc151bbf..e9efb0983 100644
--- a/src/multimedia/qmediaenumdebug.h
+++ b/src/multimedia/qmediaenumdebug.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMEDIAENUMDEBUG_H
#define QMEDIAENUMDEBUG_H
diff --git a/src/multimedia/qmediaformat.cpp b/src/multimedia/qmediaformat.cpp
new file mode 100644
index 000000000..a05648636
--- /dev/null
+++ b/src/multimedia/qmediaformat.cpp
@@ -0,0 +1,883 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qmediaformat.h"
+#include "private/qplatformmediaintegration_p.h"
+#include "private/qplatformmediaformatinfo_p.h"
+#include <QtCore/qmimedatabase.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QMediaFormat
+ \ingroup multimedia
+ \inmodule QtMultimedia
+ \brief Describes an encoding format for a multimedia file or stream.
+ \since 6.2
+
+ QMediaFormat describes an encoding format for a multimedia file or stream.
+
+ You can check whether a certain media format can be used for encoding
+ or decoding using QMediaFormat.
+*/
+
+/*!
+ \qmlvaluetype mediaFormat
+ \ingroup qmlvaluetypes
+ \since 6.2
+ //! \instantiates QMediaFormat
+ \brief MediaFormat describes the format of a media file.
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+
+ The MediaFormat type describes the format of a media file. It contains
+ three properties that describe the file type and the audio and video codecs
+ that are being used.
+
+ MediaFormat can be used to specify the type of file that should be created
+ by a MediaRecorder. The snippet below shows an example that sets up the
+ recorder to create an mpeg4 video with AAC encoded audio and H265 video:
+
+ \qml
+ CaptureSession {
+ ... // setup inputs
+ MediaRecorder {
+ mediaFormat {
+ fileFormat: MediaFormat.MPEG4
+ audioCodec: MediaFormat.AudioCodec.AAC
+ videoCodec: MediaFormat.VideoCodec.H265
+ }
+ }
+ }
+ \endqml
+
+ If the specified mediaFormat is not supported, the MediaRecorder will automatically try
+ to find the best possible replacement format and use that instead.
+
+ \sa MediaRecorder, CaptureSession
+*/
+
+namespace {
+
+const char *mimeTypeForFormat[QMediaFormat::LastFileFormat + 2] =
+{
+ "",
+ "video/x-ms-wmv",
+ "video/x-msvideo",
+ "video/x-matroska",
+ "video/mp4",
+ "video/ogg",
+ "video/quicktime",
+ "video/webm",
+ // Audio Formats
+ "audio/mp4",
+ "audio/aac",
+ "audio/x-ms-wma",
+ "audio/mpeg",
+ "audio/flac",
+ "audio/wav"
+};
+
+constexpr QMediaFormat::FileFormat videoFormatPriorityList[] =
+{
+ QMediaFormat::MPEG4,
+ QMediaFormat::QuickTime,
+ QMediaFormat::AVI,
+ QMediaFormat::WebM,
+ QMediaFormat::WMV,
+ QMediaFormat::Matroska,
+ QMediaFormat::Ogg,
+ QMediaFormat::UnspecifiedFormat
+};
+
+constexpr QMediaFormat::FileFormat audioFormatPriorityList[] =
+{
+ QMediaFormat::Mpeg4Audio,
+ QMediaFormat::MP3,
+ QMediaFormat::WMA,
+ QMediaFormat::FLAC,
+ QMediaFormat::Wave,
+ QMediaFormat::UnspecifiedFormat
+};
+
+constexpr QMediaFormat::AudioCodec audioPriorityList[] =
+{
+ QMediaFormat::AudioCodec::AAC,
+ QMediaFormat::AudioCodec::MP3,
+ QMediaFormat::AudioCodec::AC3,
+ QMediaFormat::AudioCodec::Opus,
+ QMediaFormat::AudioCodec::EAC3,
+ QMediaFormat::AudioCodec::DolbyTrueHD,
+ QMediaFormat::AudioCodec::WMA,
+ QMediaFormat::AudioCodec::FLAC,
+ QMediaFormat::AudioCodec::Vorbis,
+ QMediaFormat::AudioCodec::Wave,
+ QMediaFormat::AudioCodec::Unspecified
+};
+
+constexpr QMediaFormat::VideoCodec videoPriorityList[] =
+{
+ QMediaFormat::VideoCodec::H265,
+ QMediaFormat::VideoCodec::VP9,
+ QMediaFormat::VideoCodec::H264,
+ QMediaFormat::VideoCodec::AV1,
+ QMediaFormat::VideoCodec::VP8,
+ QMediaFormat::VideoCodec::WMV,
+ QMediaFormat::VideoCodec::Theora,
+ QMediaFormat::VideoCodec::MPEG4,
+ QMediaFormat::VideoCodec::MPEG2,
+ QMediaFormat::VideoCodec::MPEG1,
+ QMediaFormat::VideoCodec::MotionJPEG,
+};
+
+}
+
+class QMediaFormatPrivate : public QSharedData
+{};
+
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QMediaFormatPrivate);
+
+/*! \enum QMediaFormat::FileFormat
+
+ Describes the container format used in a multimedia file or stream.
+
+ \value WMA
+ \l {Windows Media Audio}
+ \value AAC
+ \l{Advanced Audio Coding}
+ \value Matroska
+ \l{Matroska (MKV)}
+ \value WMV
+ \l{Windows Media Video}
+ \value MP3
+ \l{MPEG-1 Audio Layer III or MPEG-2 Audio Layer III}
+ \value Wave
+ \l{Waveform Audio File Format}
+ \value Ogg
+ \l{Ogg}
+ \value MPEG4
+ \l{MPEG-4}
+ \value AVI
+ \l{Audio Video Interleave}
+ \value QuickTime
+ \l{QuickTime}
+ \value WebM
+ \l{WebM}
+ \value Mpeg4Audio
+ \l{MPEG-4 Part 3 or MPEG-4 Audio (formally ISO/IEC 14496-3)}
+ \value FLAC
+ \l{Free Lossless Audio Codec}
+ \value UnspecifiedFormat
+ The format is unspecified.
+
+ \omitvalue LastFileFormat
+*/
+
+/*! \qmlproperty enumeration QtMultimedia::mediaFormat::fileFormat
+
+ Describes the container format used in a multimedia file or stream.
+ It can take one of the following values:
+
+ \table
+ \header \li Property value
+ \li Description
+ \row \li MediaFormat.WMA
+ \li \l{Windows Media Audio}
+ \row \li MediaFormat.AAC
+ \li \l{Advanced Audio Coding}
+ \row \li MediaFormat.Matroska
+ \li \l{Matroska (MKV)}
+ \row \li MediaFormat.WMV
+ \li \l{Windows Media Video}
+ \row \li MediaFormat.MP3
+ \li \l{MPEG-1 Audio Layer III or MPEG-2 Audio Layer III}
+ \row \li MediaFormat.Wave
+ \li \l{Waveform Audio File Format}
+ \row \li MediaFormat.Ogg
+ \li \l{Ogg}
+ \row \li MediaFormat.MPEG4
+ \li \l{MPEG-4}
+ \row \li MediaFormat.AVI
+ \li \l{Audio Video Interleave}
+ \row \li MediaFormat.QuickTime
+ \li \l{QuickTime}
+ \row \li MediaFormat.WebM
+ \li \l{WebM}
+ \row \li MediaFormat.Mpeg4Audio
+ \li \l{MPEG-4 Part 3 or MPEG-4 Audio (formally ISO/IEC 14496-3)}
+ \row \li MediaFormat.FLAC
+ \li \l{Free Lossless Audio Codec}
+ \row \li MediaFormat.UnspecifiedFormat
+ \li The format is unspecified.
+ \endtable
+*/
+
+/*! \enum QMediaFormat::AudioCodec
+
+ Describes the audio codec used in multimedia file or stream.
+
+ \value WMA
+ \l {Windows Media Audio}
+ \value AC3
+ \l {Dolby Digital}
+ \value AAC
+ \l{Advanced Audio Coding}
+ \value ALAC
+ \l{Apple Lossless Audio Codec}
+ \value DolbyTrueHD
+ \l{Dolby TrueHD}
+ \value EAC3
+ \l {Dolby Digital Plus (EAC3)}
+ \value MP3
+ \l{MPEG-1 Audio Layer III or MPEG-2 Audio Layer III}
+ \value Wave
+ \l{Waveform Audio File Format}
+ \value Vorbis
+ \l{Ogg Vorbis}
+ \value FLAC
+ \l{Free Lossless Audio Codec}
+ \value Opus
+ \l{Opus Audio Format}
+ \value Unspecified
+ Unspecified codec
+
+ \omitvalue LastAudioCodec
+*/
+
+/*! \qmlproperty enumeration QtMultimedia::mediaFormat::audioCodec
+
+ Describes the audio codec used in multimedia file or stream.
+ It can take one of the following values:
+
+ \table
+ \header \li Property value
+ \li Description
+ \row \li MediaFormat.WMA
+ \li \l {Windows Media Audio}
+ \row \li MediaFormat.AC3
+ \li \l {Dolby Digital}
+ \row \li MediaFormat.AAC
+ \li \l{Advanced Audio Coding}
+ \row \li MediaFormat.ALAC
+ \li \l{Apple Lossless Audio Codec}
+ \row \li MediaFormat.DolbyTrueHD
+ \li \l{Dolby TrueHD}
+ \row \li MediaFormat.EAC3
+ \li \l {Dolby Digital Plus (EAC3)}
+ \row \li MediaFormat.MP3
+ \li \l{MPEG-1 Audio Layer III or MPEG-2 Audio Layer III}
+ \row \li MediaFormat.Wave
+ \li \l{Waveform Audio File Format}
+ \row \li MediaFormat.Vorbis
+ \li \l{Ogg Vorbis}
+ \row \li MediaFormat.FLAC
+ \li \l{Free Lossless Audio Codec}
+ \row \li MediaFormat.Opus
+ \li \l{Opus Audio Format}
+ \row \li MediaFormat.Unspecified
+ \li Unspecified codec
+ \endtable
+*/
+
+/*! \enum QMediaFormat::VideoCodec
+
+ Describes the video coded used in multimedia file or stream.
+
+ \value VP8
+ \l{VP8}
+ \value MPEG2
+ \l{MPEG-2}
+ \value MPEG1
+ \l{MPEG-1}
+ \value WMV
+ \l{Windows Media Video}
+ \value H265
+ \l{High Efficiency Video Coding (HEVC)}
+ \value H264
+ \l{Advanced Video Coding}
+ \value MPEG4
+ \l{MPEG-4}
+ \value AV1
+ \l{AOMedia Video 1}
+ \value MotionJPEG
+ \l{MotionJPEG}
+ \value VP9
+ \l{VP9}
+ \value Theora
+ \l{Theora}
+ \value Unspecified
+ Video codec not specified
+
+ \omitvalue LastVideoCodec
+*/
+
+/*! \qmlproperty enumeration QtMultimedia::mediaFormat::videoCodec
+
+ Describes the video codec used in multimedia file or stream.
+ It can take one of the following values:
+
+ \table
+ \header \li Property value
+ \li Description
+ \row \li MediaFormat.VP8
+ \li \l{VP8}
+ \row \li MediaFormat.MPEG2
+ \li \l{MPEG-2}
+ \row \li MediaFormat.MPEG1
+ \li \l{MPEG-1}
+ \row \li MediaFormat.WMV
+ \li \l{Windows Media Video}
+ \row \li MediaFormat.H265
+ \li \l{High Efficiency Video Coding (HEVC)}
+ \row \li MediaFormat.H264
+ \li \l{Advanced Video Coding}
+ \row \li MediaFormat.MPEG4
+ \li \l{MPEG-4}
+ \row \li MediaFormat.AV1
+ \li \l{AOMedia Video 1}
+ \row \li MediaFormat.MotionJPEG
+ \li \l{MotionJPEG}
+ \row \li MediaFormat.VP9
+ \li \l{VP9}
+ \row \li MediaFormat.Theora
+ \li \l{Theora}
+ \row \li MediaFormat.Unspecified
+ \li Video codec not specified
+ \endtable
+*/
+
+// these are non inline to make a possible future addition of a d pointer binary compatible
+
+/*!
+ Constructs a QMediaFormat object for \a format.
+*/
+QMediaFormat::QMediaFormat(FileFormat format)
+ : fmt(format)
+{
+}
+
+/*!
+ Destroys the QMediaFormat object.
+*/
+QMediaFormat::~QMediaFormat() = default;
+
+/*!
+ Constructs a QMediaFormat object by copying from \a other.
+*/
+QMediaFormat::QMediaFormat(const QMediaFormat &other) noexcept = default;
+
+/*!
+ \fn void QMediaFormat::swap(QMediaFormat &other) noexcept
+
+ Swaps the media format with \a other.
+*/
+/*!
+ Copies \a other into this QMediaFormat object.
+*/
+QMediaFormat &QMediaFormat::operator=(const QMediaFormat &other) noexcept = default;
+
+/*! \fn QMediaFormat::QMediaFormat(QMediaFormat &&other)
+
+ Constructs a QMediaFormat objects by moving from \a other.
+*/
+
+/*! \fn QMediaFormat &QMediaFormat::operator=(QMediaFormat &&other)
+
+ Moves \a other into this QMediaFormat objects.
+*/
+
+// Properties
+/*! \property QMediaFormat::fileFormat
+
+ \brief The file (container) format of the media.
+
+ \sa QMediaFormat::FileFormat
+*/
+
+/*! \property QMediaFormat::audioCodec
+
+ \brief The audio codec of the media.
+
+ \sa QMediaFormat::AudioCodec
+*/
+
+/*! \property QMediaFormat::videoCodec
+
+ \brief The video codec of the media.
+
+ \sa QMediaFormat::VideoCodec
+*/
+
+/*! \fn void QMediaFormat::setVideoCodec(VideoCodec codec)
+
+ Sets the video codec to \a codec.
+
+ \sa videoCodec(), QMediaFormat::VideoCodec
+*/
+
+/*! \fn QMediaFormat::VideoCodec QMediaFormat::videoCodec() const
+
+ Returns the video codec used in this format.
+
+ \sa setVideoCodec(), QMediaFormat::VideoCodec
+*/
+
+/*! \fn void QMediaFormat::setAudioCodec(AudioCodec codec)
+
+ Sets the audio codec to \a codec.
+
+ \sa audioCodec(), QMediaFormat::AudioCodec
+*/
+
+/*! \fn QMediaFormat::AudioCodec QMediaFormat::audioCodec() const
+
+ Returns the audio codec used in this format.
+
+ \sa setAudioCodec(), QMediaFormat::AudioCodec
+*/
+
+/*!
+ Returns \c true if Qt Multimedia can encode or decode this format,
+ depending on \a mode.
+*/
+
+bool QMediaFormat::isSupported(ConversionMode mode) const
+{
+ return QPlatformMediaIntegration::instance()->formatInfo()->isSupported(*this, mode);
+}
+
+/*!
+ Returns the \l{MIME type} for the file format used in this media format.
+*/
+
+QMimeType QMediaFormat::mimeType() const
+{
+ return QMimeDatabase().mimeTypeForName(QString::fromLatin1(mimeTypeForFormat[fmt + 1]));
+}
+
+/*!
+ \enum QMediaFormat::ConversionMode
+
+ In many cases, systems have asymmetric capabilities and can often decode more formats
+ or codecs than can be encoded. This enum describes the requested conversion mode to
+ be used when checking whether a certain file format or codec is supported.
+
+ \value Encode
+ Used to check whether a certain file format or codec can be encoded.
+ \value Decode
+ Used to check whether a certain file format or codec can be decoded.
+
+ \sa supportedFileFormats, supportedAudioCodecs, supportedVideoCodecs
+*/
+
+/*!
+ \qmlmethod list<FileFormat> QtMultimedia::mediaFormat::supportedFileFormats(conversionMode)
+ Returns a list of file formats for the audio and video
+ codec indicated by \a{conversionMode}.
+
+ To get all supported file formats, run this query on a default constructed MediaFormat. To
+ get a list of file formats supporting a specific combination of an audio and video codec,
+ you can set the audioCodec and videoCodec properties before running this query.
+
+ \sa QMediaFormat::ConversionMode
+*/
+
+/*!
+ Returns a list of file formats for the audio and video
+ codec indicated by \a{m}.
+
+ To get all supported file formats, run this query on a default constructed
+ QMediaFormat.
+
+ \sa QMediaFormat::ConversionMode
+*/
+QList<QMediaFormat::FileFormat> QMediaFormat::supportedFileFormats(QMediaFormat::ConversionMode m)
+{
+ return QPlatformMediaIntegration::instance()->formatInfo()->supportedFileFormats(*this, m);
+}
+
+/*!
+ \qmlmethod list<VideoCodec> QtMultimedia::mediaFormat::supportedVideoCodecs(conversionMode)
+ Returns a list of video codecs for the chosen file format and
+ audio codec (\a conversionMode).
+
+ To get all supported video codecs, run this query on a default constructed MediaFormat. To
+ get a list of supported video codecs for a specific combination of a file format and an audio
+ codec, you can set the fileFormat and audioCodec properties before running this query.
+
+ \sa QMediaFormat::ConversionMode
+*/
+
+/*!
+ Returns a list of video codecs for the chosen file format and
+ audio codec (\a m).
+
+ To get all supported video codecs, run this query on a default constructed
+ MediaFormat.
+
+ \sa QMediaFormat::ConversionMode
+*/
+QList<QMediaFormat::VideoCodec> QMediaFormat::supportedVideoCodecs(QMediaFormat::ConversionMode m)
+{
+ return QPlatformMediaIntegration::instance()->formatInfo()->supportedVideoCodecs(*this, m);
+}
+
+/*!
+ \qmlmethod list<AudioCodec> QtMultimedia::mediaFormat::supportedAudioFormats(conversionMode)
+ Returns a list of audio codecs for the chosen file format and
+ video codec (\a conversionMode).
+
+ To get all supported audio codecs, run this query on a default constructed MediaFormat. To get
+ a list of supported audio codecs for a specific combination of a file format and a video codec,
+ you can set the fileFormat and videoCodec properties before running this query.
+
+ \sa QMediaFormat::ConversionMode
+*/
+
+/*!
+ Returns a list of audio codecs for the chosen file format and
+ video codec (\a m).
+
+ To get all supported audio codecs, run this query on a default constructed
+ QMediaFormat.
+
+ \sa QMediaFormat::ConversionMode
+*/
+QList<QMediaFormat::AudioCodec> QMediaFormat::supportedAudioCodecs(QMediaFormat::ConversionMode m)
+{
+ return QPlatformMediaIntegration::instance()->formatInfo()->supportedAudioCodecs(*this, m);
+}
+
+/*!
+ \qmlmethod string QtMultimedia::mediaFormat::fileFormatName(fileFormat)
+ Returns a string based name for \a fileFormat.
+*/
+
+/*!
+ Returns a string based name for \a fileFormat.
+*/
+QString QMediaFormat::fileFormatName(QMediaFormat::FileFormat fileFormat)
+{
+ constexpr const char *descriptions[QMediaFormat::LastFileFormat + 2] = {
+ "Unspecified",
+ "WMV",
+ "AVI",
+ "Matroska",
+ "MPEG-4",
+ "Ogg",
+ "QuickTime",
+ "WebM",
+ // Audio Formats
+ "MPEG-4 Audio",
+ "AAC",
+ "WMA",
+ "MP3",
+ "FLAC",
+ "Wave"
+ };
+ return QString::fromUtf8(descriptions[int(fileFormat) + 1]);
+}
+
+/*!
+ \qmlmethod string QtMultimedia::mediaFormat::audioCodecName(codec)
+ Returns a string based name for \a codec.
+*/
+
+/*!
+ Returns a string based name for \a codec.
+*/
+QString QMediaFormat::audioCodecName(QMediaFormat::AudioCodec codec)
+{
+ constexpr const char *descriptions[] = {
+ "Invalid",
+ "MP3",
+ "AAC",
+ "AC3",
+ "EAC3",
+ "FLAC",
+ "DolbyTrueHD",
+ "Opus",
+ "Vorbis",
+ "Wave",
+ "WMA",
+ "ALAC",
+ };
+ return QString::fromUtf8(descriptions[int(codec) + 1]);
+}
+
+/*!
+ \qmlmethod string QtMultimedia::mediaFormat::videoCodecName(codec)
+ Returns a string based name for \a codec.
+*/
+
+/*!
+ Returns a string based name for \a codec.
+*/
+QString QMediaFormat::videoCodecName(QMediaFormat::VideoCodec codec)
+{
+ constexpr const char *descriptions[] = {
+ "Invalid",
+ "MPEG1",
+ "MPEG2",
+ "MPEG4",
+ "H264",
+ "H265",
+ "VP8",
+ "VP9",
+ "AV1",
+ "Theora",
+ "WMV",
+ "MotionJPEG"
+ };
+ return QString::fromUtf8(descriptions[int(codec) + 1]);
+}
+
+/*!
+ \qmlmethod string QtMultimedia::mediaFormat::fileFormatDescription(fileFormat)
+ Returns a description for \a fileFormat.
+*/
+
+/*!
+ Returns a description for \a fileFormat.
+*/
+QString QMediaFormat::fileFormatDescription(QMediaFormat::FileFormat fileFormat)
+{
+ constexpr const char *descriptions[QMediaFormat::LastFileFormat + 2] = {
+ "Unspecified File Format",
+ "Windows Media Video",
+ "Audio Video Interleave",
+ "Matroska Multimedia Container",
+ "MPEG-4 Video Container",
+ "Ogg",
+ "QuickTime Container",
+ "WebM",
+ // Audio Formats
+ "MPEG-4 Audio",
+ "AAC",
+ "Windows Media Audio",
+ "MP3",
+ "Free Lossless Audio Codec (FLAC)",
+ "Wave File"
+ };
+ return QString::fromUtf8(descriptions[int(fileFormat) + 1]);
+}
+
+/*!
+ \qmlmethod string QtMultimedia::mediaFormat::audioCodecDescription(codec)
+ Returns a description for \a codec.
+*/
+
+/*!
+ Returns a description for \a codec.
+*/
+QString QMediaFormat::audioCodecDescription(QMediaFormat::AudioCodec codec)
+{
+ constexpr const char *descriptions[] = {
+ "Unspecified Audio Codec",
+ "MP3",
+ "Advanced Audio Codec (AAC)",
+ "Dolby Digital (AC3)",
+ "Dolby Digital Plus (E-AC3)",
+ "Free Lossless Audio Codec (FLAC)",
+ "Dolby True HD",
+ "Opus",
+ "Vorbis",
+ "Wave",
+ "Windows Media Audio",
+ "Apple Lossless Audio Codec (ALAC)",
+ };
+ return QString::fromUtf8(descriptions[int(codec) + 1]);
+}
+
+/*!
+ \qmlmethod string QtMultimedia::mediaFormat::videoCodecDescription(codec)
+ Returns a description for \a codec.
+*/
+
+/*!
+ Returns a description for \a codec.
+*/
+QString QMediaFormat::videoCodecDescription(QMediaFormat::VideoCodec codec)
+{
+ constexpr const char *descriptions[] = {
+ "Unspecified Video Codec",
+ "MPEG-1 Video",
+ "MPEG-2 Video",
+ "MPEG-4 Video",
+ "H.264",
+ "H.265",
+ "VP8",
+ "VP9",
+ "AV1",
+ "Theora",
+ "Windows Media Video",
+ "MotionJPEG"
+ };
+ return QString::fromUtf8(descriptions[int(codec) + 1]);
+}
+
+/*!
+ \fn bool QMediaFormat::operator!=(const QMediaFormat &other) const
+
+ Returns \c true if \a other is not equal to the current media format,
+ otherwise returns \c false.
+*/
+
+/*!
+ Returns \c true if \a other is equal to the current media format, otherwise
+ returns \c false.
+*/
+bool QMediaFormat::operator==(const QMediaFormat &other) const
+{
+ Q_ASSERT(!d);
+ return fmt == other.fmt &&
+ audio == other.audio &&
+ video == other.video;
+}
+
+/*!
+ \enum QMediaFormat::ResolveFlags
+
+ Describes the requirements for resolving a suitable format for
+ QMediaRecorder.
+
+ \value NoFlags
+ No requirements
+ \value RequiresVideo
+ A video codec is required
+
+ \sa resolveForEncoding()
+*/
+
+/*!
+ Resolves the format, based on \a flags, to a format that is supported by
+ QMediaRecorder.
+
+ This method tries to find the best possible match for unspecified settings.
+ Settings that are not supported by the recorder will be modified to the closest
+ match that is supported.
+
+ When resolving, priority is given in the following order:
+ \list 1
+ \li File format
+ \li Video codec
+ \li Audio codec
+ \endlist
+*/
+void QMediaFormat::resolveForEncoding(ResolveFlags flags)
+{
+ const bool requiresVideo = (flags & ResolveFlags::RequiresVideo) != 0;
+
+ if (!requiresVideo)
+ video = VideoCodec::Unspecified;
+
+ // need to adjust the format. Priority is given first to file format, then video codec, then audio codec
+
+ QMediaFormat nullFormat;
+ auto supportedFormats = nullFormat.supportedFileFormats(QMediaFormat::Encode);
+ auto supportedAudioCodecs = nullFormat.supportedAudioCodecs(QMediaFormat::Encode);
+ auto supportedVideoCodecs = nullFormat.supportedVideoCodecs(QMediaFormat::Encode);
+
+ auto bestSupportedFileFormat = [&](QMediaFormat::AudioCodec audio = QMediaFormat::AudioCodec::Unspecified,
+ QMediaFormat::VideoCodec video = QMediaFormat::VideoCodec::Unspecified)
+ {
+ QMediaFormat f;
+ f.setAudioCodec(audio);
+ f.setVideoCodec(video);
+ auto supportedFormats = f.supportedFileFormats(QMediaFormat::Encode);
+ auto *list = (flags == NoFlags) ? audioFormatPriorityList : videoFormatPriorityList;
+ while (*list != QMediaFormat::UnspecifiedFormat) {
+ if (supportedFormats.contains(*list))
+ break;
+ ++list;
+ }
+ return *list;
+ };
+
+ // reset format if it does not support video when video is required
+ if (requiresVideo && this->supportedVideoCodecs(QMediaFormat::Encode).isEmpty())
+ fmt = QMediaFormat::UnspecifiedFormat;
+
+ // reset non supported formats and codecs
+ if (!supportedFormats.contains(fmt))
+ fmt = QMediaFormat::UnspecifiedFormat;
+ if (!supportedAudioCodecs.contains(audio))
+ audio = QMediaFormat::AudioCodec::Unspecified;
+ if (!requiresVideo || !supportedVideoCodecs.contains(video))
+ video = QMediaFormat::VideoCodec::Unspecified;
+
+ if (requiresVideo) {
+ // try finding a file format that is supported
+ if (fmt == QMediaFormat::UnspecifiedFormat)
+ fmt = bestSupportedFileFormat(audio, video);
+ // try without the audio codec
+ if (fmt == QMediaFormat::UnspecifiedFormat)
+ fmt = bestSupportedFileFormat(QMediaFormat::AudioCodec::Unspecified, video);
+ }
+ // try without the video codec
+ if (fmt == QMediaFormat::UnspecifiedFormat)
+ fmt = bestSupportedFileFormat(audio);
+ // give me a format that's supported
+ if (fmt == QMediaFormat::UnspecifiedFormat)
+ fmt = bestSupportedFileFormat();
+ // still nothing? Give up
+ if (fmt == QMediaFormat::UnspecifiedFormat) {
+ *this = {};
+ return;
+ }
+
+ // find a working video codec
+ if (requiresVideo) {
+ // reset the audio codec, so that we won't throw away the video codec
+ // if it is supported (choosing the specified video codec has higher
+ // priority than the specified audio codec)
+ auto a = audio;
+ audio = QMediaFormat::AudioCodec::Unspecified;
+ auto videoCodecs = this->supportedVideoCodecs(QMediaFormat::Encode);
+ if (!videoCodecs.contains(video)) {
+ // not supported, try to find a replacement
+ auto *list = videoPriorityList;
+ while (*list != QMediaFormat::VideoCodec::Unspecified) {
+ if (videoCodecs.contains(*list))
+ break;
+ ++list;
+ }
+ video = *list;
+ }
+ audio = a;
+ } else {
+ video = QMediaFormat::VideoCodec::Unspecified;
+ }
+
+ // and a working audio codec
+ auto audioCodecs = this->supportedAudioCodecs(QMediaFormat::Encode);
+ if (!audioCodecs.contains(audio)) {
+ auto *list = audioPriorityList;
+ while (*list != QMediaFormat::AudioCodec::Unspecified) {
+ if (audioCodecs.contains(*list))
+ break;
+ ++list;
+ }
+ audio = *list;
+ }
+}
+
+/*!
+ \variable QMediaFormat::audio
+ \internal
+*/
+/*!
+ \variable QMediaFormat::d
+ \internal
+*/
+/*!
+ \variable QMediaFormat::video
+ \internal
+*/
+/*!
+ \variable QMediaFormat::fmt
+ \internal
+*/
+QT_END_NAMESPACE
+
+#include "moc_qmediaformat.cpp"
diff --git a/src/multimedia/qmediaformat.h b/src/multimedia/qmediaformat.h
new file mode 100644
index 000000000..225d21896
--- /dev/null
+++ b/src/multimedia/qmediaformat.h
@@ -0,0 +1,149 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QMEDIAFORMAT_H
+#define QMEDIAFORMAT_H
+
+#include <QtCore/qsharedpointer.h>
+#include <QtMultimedia/qtmultimediaglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMimeType;
+class QMediaFormat;
+class QMediaFormatPrivate;
+
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QMediaFormatPrivate, Q_MULTIMEDIA_EXPORT)
+
+class Q_MULTIMEDIA_EXPORT QMediaFormat
+{
+ Q_GADGET
+ Q_PROPERTY(FileFormat fileFormat READ fileFormat WRITE setFileFormat)
+ Q_PROPERTY(AudioCodec audioCodec READ audioCodec WRITE setAudioCodec)
+ Q_PROPERTY(VideoCodec videoCodec READ videoCodec WRITE setVideoCodec)
+ Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
+public:
+ enum FileFormat {
+ UnspecifiedFormat = -1,
+ // Video Formats
+ WMV,
+ AVI,
+ Matroska,
+ MPEG4,
+ Ogg,
+ QuickTime,
+ WebM,
+ // Audio Only Formats
+ Mpeg4Audio,
+ AAC,
+ WMA,
+ MP3,
+ FLAC,
+ Wave,
+ LastFileFormat = Wave
+ };
+ Q_ENUM(FileFormat)
+
+ enum class AudioCodec {
+ Unspecified = -1,
+ MP3,
+ AAC,
+ AC3,
+ EAC3,
+ FLAC,
+ DolbyTrueHD,
+ Opus,
+ Vorbis,
+ Wave,
+ WMA,
+ ALAC,
+ LastAudioCodec = ALAC
+ };
+ Q_ENUM(AudioCodec)
+
+ enum class VideoCodec {
+ Unspecified = -1,
+ MPEG1,
+ MPEG2,
+ MPEG4,
+ H264,
+ H265,
+ VP8,
+ VP9,
+ AV1,
+ Theora,
+ WMV,
+ MotionJPEG,
+ LastVideoCodec = MotionJPEG
+ };
+ Q_ENUM(VideoCodec)
+
+ enum ConversionMode {
+ Encode,
+ Decode
+ };
+ Q_ENUM(ConversionMode)
+
+ enum ResolveFlags
+ {
+ NoFlags,
+ RequiresVideo
+ };
+
+ QMediaFormat(FileFormat format = UnspecifiedFormat);
+ ~QMediaFormat();
+ QMediaFormat(const QMediaFormat &other) noexcept;
+ QMediaFormat &operator=(const QMediaFormat &other) noexcept;
+
+ QMediaFormat(QMediaFormat &&other) noexcept = default;
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QMediaFormat)
+ void swap(QMediaFormat &other) noexcept
+ {
+ std::swap(fmt, other.fmt);
+ std::swap(audio, other.audio);
+ std::swap(video, other.video);
+ d.swap(other.d);
+ }
+
+ FileFormat fileFormat() const { return fmt; }
+ void setFileFormat(FileFormat f) { fmt = f; }
+
+ void setVideoCodec(VideoCodec codec) { video = codec; }
+ VideoCodec videoCodec() const { return video; }
+
+ void setAudioCodec(AudioCodec codec) { audio = codec; }
+ AudioCodec audioCodec() const { return audio; }
+
+ Q_INVOKABLE bool isSupported(ConversionMode mode) const;
+
+ QMimeType mimeType() const;
+
+ Q_INVOKABLE QList<FileFormat> supportedFileFormats(ConversionMode m);
+ Q_INVOKABLE QList<VideoCodec> supportedVideoCodecs(ConversionMode m);
+ Q_INVOKABLE QList<AudioCodec> supportedAudioCodecs(ConversionMode m);
+
+ Q_INVOKABLE static QString fileFormatName(FileFormat fileFormat);
+ Q_INVOKABLE static QString audioCodecName(AudioCodec codec);
+ Q_INVOKABLE static QString videoCodecName(VideoCodec codec);
+
+ Q_INVOKABLE static QString fileFormatDescription(QMediaFormat::FileFormat fileFormat);
+ Q_INVOKABLE static QString audioCodecDescription(QMediaFormat::AudioCodec codec);
+ Q_INVOKABLE static QString videoCodecDescription(QMediaFormat::VideoCodec codec);
+
+ bool operator==(const QMediaFormat &other) const;
+ bool operator!=(const QMediaFormat &other) const
+ { return !operator==(other); }
+
+ void resolveForEncoding(ResolveFlags flags);
+
+protected:
+ friend class QMediaFormatPrivate;
+ FileFormat fmt;
+ AudioCodec audio = AudioCodec::Unspecified;
+ VideoCodec video = VideoCodec::Unspecified;
+ QExplicitlySharedDataPointer<QMediaFormatPrivate> d;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/qmediaframeinput.cpp b/src/multimedia/qmediaframeinput.cpp
new file mode 100644
index 000000000..4bb90d3ee
--- /dev/null
+++ b/src/multimedia/qmediaframeinput.cpp
@@ -0,0 +1,43 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qmediaframeinput_p.h"
+
+QT_BEGIN_NAMESPACE
+
+void QMediaFrameInputPrivate::setCaptureSession(QMediaCaptureSession *session)
+{
+ if (session == m_captureSession)
+ return;
+
+ auto prevSession = std::exchange(m_captureSession, session);
+ updateCaptureSessionConnections(prevSession, session);
+ updateCanSendMediaFrame();
+}
+
+void QMediaFrameInputPrivate::updateCanSendMediaFrame()
+{
+ const bool canSendMediaFrame = m_captureSession && checkIfCanSendMediaFrame();
+ if (m_canSendMediaFrame != canSendMediaFrame) {
+ m_canSendMediaFrame = canSendMediaFrame;
+ if (m_canSendMediaFrame)
+ emitReadyToSendMediaFrame();
+ }
+}
+
+void QMediaFrameInputPrivate::postponeCheckReadyToSend()
+{
+ if (m_canSendMediaFrame && !m_postponeReadyToSendCheckRun) {
+ m_postponeReadyToSendCheckRun = true;
+ QMetaObject::invokeMethod(
+ q_ptr,
+ [this]() {
+ m_postponeReadyToSendCheckRun = false;
+ if (m_canSendMediaFrame)
+ emitReadyToSendMediaFrame();
+ },
+ Qt::QueuedConnection);
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/qmediaframeinput_p.h b/src/multimedia/qmediaframeinput_p.h
new file mode 100644
index 000000000..22277865d
--- /dev/null
+++ b/src/multimedia/qmediaframeinput_p.h
@@ -0,0 +1,74 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QMEDIAFRAMEINPUT_P_H
+#define QMEDIAFRAMEINPUT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qmediacapturesession.h"
+#include <QtCore/private/qobject_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMediaFrameInputPrivate : public QObjectPrivate
+{
+public:
+ void setCaptureSession(QMediaCaptureSession *session);
+
+ QMediaCaptureSession *captureSession() const { return m_captureSession; }
+
+protected:
+ template <typename Sender>
+ bool sendMediaFrame(Sender &&sender)
+ {
+ if (!m_canSendMediaFrame)
+ return false;
+
+ sender();
+ postponeCheckReadyToSend();
+ return true;
+ }
+
+ template <typename Sender, typename Signal>
+ void addUpdateSignal(Sender sender, Signal signal)
+ {
+ connect(sender, signal, this, &QMediaFrameInputPrivate::updateCanSendMediaFrame);
+ }
+
+ template <typename Sender, typename Signal>
+ void removeUpdateSignal(Sender sender, Signal signal)
+ {
+ disconnect(sender, signal, this, &QMediaFrameInputPrivate::updateCanSendMediaFrame);
+ }
+
+ void updateCanSendMediaFrame();
+
+private:
+ void postponeCheckReadyToSend();
+
+ virtual bool checkIfCanSendMediaFrame() const = 0;
+
+ virtual void emitReadyToSendMediaFrame() = 0;
+
+ virtual void updateCaptureSessionConnections(QMediaCaptureSession *prevSession,
+ QMediaCaptureSession *currentSession) = 0;
+
+private:
+ QMediaCaptureSession *m_captureSession = nullptr;
+ bool m_canSendMediaFrame = false;
+ bool m_postponeReadyToSendCheckRun = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QMEDIAFRAMEINPUT_P_H
diff --git a/src/multimedia/qmediainputencoderinterface_p.h b/src/multimedia/qmediainputencoderinterface_p.h
new file mode 100644
index 000000000..c199e59b4
--- /dev/null
+++ b/src/multimedia/qmediainputencoderinterface_p.h
@@ -0,0 +1,31 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QMEDIAINPUTENCODERINTERFACE_P_H
+#define QMEDIAINPUTENCODERINTERFACE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMediaInputEncoderInterface
+{
+public:
+ virtual ~QMediaInputEncoderInterface() = default;
+ virtual bool canPushFrame() const = 0;
+};
+
+QT_END_NAMESPACE
+
+#endif // QMEDIAINPUTENCODERINTERFACE_P_H
diff --git a/src/multimedia/qmediametadata.cpp b/src/multimedia/qmediametadata.cpp
index 0b2343443..afbaea5b7 100644
--- a/src/multimedia/qmediametadata.cpp
+++ b/src/multimedia/qmediametadata.cpp
@@ -1,261 +1,163 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qmediametadata.h"
-QT_BEGIN_NAMESPACE
-
-/*
- When these conditions are satisfied, QStringLiteral is implemented by
- gcc's statement-expression extension. However, in this file it will
- not work, because "statement-expressions are not allowed outside functions
- nor in template-argument lists".
- MSVC 2012 produces an internal compiler error on encountering
- QStringLiteral in this context.
-
- Fall back to the less-performant QLatin1String in this case.
-*/
-#if defined(Q_CC_GNU) && defined(Q_COMPILER_LAMBDA)
-# define Q_DEFINE_METADATA(key) const QString QMediaMetaData::key(QStringLiteral(#key))
-#else
-# define Q_DEFINE_METADATA(key) const QString QMediaMetaData::key(QLatin1String(#key))
-#endif
-
-// Common
-Q_DEFINE_METADATA(Title);
-Q_DEFINE_METADATA(SubTitle);
-Q_DEFINE_METADATA(Author);
-Q_DEFINE_METADATA(Comment);
-Q_DEFINE_METADATA(Description);
-Q_DEFINE_METADATA(Category);
-Q_DEFINE_METADATA(Genre);
-Q_DEFINE_METADATA(Year);
-Q_DEFINE_METADATA(Date);
-Q_DEFINE_METADATA(UserRating);
-Q_DEFINE_METADATA(Keywords);
-Q_DEFINE_METADATA(Language);
-Q_DEFINE_METADATA(Publisher);
-Q_DEFINE_METADATA(Copyright);
-Q_DEFINE_METADATA(ParentalRating);
-Q_DEFINE_METADATA(RatingOrganization);
-
-// Media
-Q_DEFINE_METADATA(Size);
-Q_DEFINE_METADATA(MediaType);
-Q_DEFINE_METADATA(Duration);
-
-// Audio
-Q_DEFINE_METADATA(AudioBitRate);
-Q_DEFINE_METADATA(AudioCodec);
-Q_DEFINE_METADATA(AverageLevel);
-Q_DEFINE_METADATA(ChannelCount);
-Q_DEFINE_METADATA(PeakValue);
-Q_DEFINE_METADATA(SampleRate);
-
-// Music
-Q_DEFINE_METADATA(AlbumTitle);
-Q_DEFINE_METADATA(AlbumArtist);
-Q_DEFINE_METADATA(ContributingArtist);
-Q_DEFINE_METADATA(Composer);
-Q_DEFINE_METADATA(Conductor);
-Q_DEFINE_METADATA(Lyrics);
-Q_DEFINE_METADATA(Mood);
-Q_DEFINE_METADATA(TrackNumber);
-Q_DEFINE_METADATA(TrackCount);
-
-Q_DEFINE_METADATA(CoverArtUrlSmall);
-Q_DEFINE_METADATA(CoverArtUrlLarge);
-
-// Image/Video
-Q_DEFINE_METADATA(Resolution);
-Q_DEFINE_METADATA(PixelAspectRatio);
-Q_DEFINE_METADATA(Orientation);
-
-// Video
-Q_DEFINE_METADATA(VideoFrameRate);
-Q_DEFINE_METADATA(VideoBitRate);
-Q_DEFINE_METADATA(VideoCodec);
-
-Q_DEFINE_METADATA(PosterUrl);
-
-// Movie
-Q_DEFINE_METADATA(ChapterNumber);
-Q_DEFINE_METADATA(Director);
-Q_DEFINE_METADATA(LeadPerformer);
-Q_DEFINE_METADATA(Writer);
-
-// Photos
-Q_DEFINE_METADATA(CameraManufacturer);
-Q_DEFINE_METADATA(CameraModel);
-Q_DEFINE_METADATA(Event);
-Q_DEFINE_METADATA(Subject);
-Q_DEFINE_METADATA(ExposureTime);
-Q_DEFINE_METADATA(FNumber);
-Q_DEFINE_METADATA(ExposureProgram);
-Q_DEFINE_METADATA(ISOSpeedRatings);
-Q_DEFINE_METADATA(ExposureBiasValue);
-Q_DEFINE_METADATA(DateTimeOriginal);
-Q_DEFINE_METADATA(DateTimeDigitized);
-Q_DEFINE_METADATA(SubjectDistance);
-Q_DEFINE_METADATA(MeteringMode);
-Q_DEFINE_METADATA(LightSource);
-Q_DEFINE_METADATA(Flash);
-Q_DEFINE_METADATA(FocalLength);
-Q_DEFINE_METADATA(ExposureMode);
-Q_DEFINE_METADATA(WhiteBalance);
-Q_DEFINE_METADATA(DigitalZoomRatio);
-Q_DEFINE_METADATA(FocalLengthIn35mmFilm);
-Q_DEFINE_METADATA(SceneCaptureType);
-Q_DEFINE_METADATA(GainControl);
-Q_DEFINE_METADATA(Contrast);
-Q_DEFINE_METADATA(Saturation);
-Q_DEFINE_METADATA(Sharpness);
-Q_DEFINE_METADATA(DeviceSettingDescription);
-
-// Location
-Q_DEFINE_METADATA(GPSLatitude);
-Q_DEFINE_METADATA(GPSLongitude);
-Q_DEFINE_METADATA(GPSAltitude);
-Q_DEFINE_METADATA(GPSTimeStamp);
-Q_DEFINE_METADATA(GPSSatellites);
-Q_DEFINE_METADATA(GPSStatus);
-Q_DEFINE_METADATA(GPSDOP);
-Q_DEFINE_METADATA(GPSSpeed);
-Q_DEFINE_METADATA(GPSTrack);
-Q_DEFINE_METADATA(GPSTrackRef);
-Q_DEFINE_METADATA(GPSImgDirection);
-Q_DEFINE_METADATA(GPSImgDirectionRef);
-Q_DEFINE_METADATA(GPSMapDatum);
-Q_DEFINE_METADATA(GPSProcessingMethod);
-Q_DEFINE_METADATA(GPSAreaInformation);
-
-Q_DEFINE_METADATA(PosterImage);
-Q_DEFINE_METADATA(CoverArtImage);
-Q_DEFINE_METADATA(ThumbnailImage);
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qdatetime.h>
+#include <QtCore/qobject.h>
+#include <QtCore/qsize.h>
+#include <QtCore/qurl.h>
+#include <QtCore/qvariant.h>
+#include <QtGui/qimage.h>
+#include <QtMultimedia/qmediaformat.h>
+QT_BEGIN_NAMESPACE
/*!
- \namespace QMediaMetaData
- \ingroup multimedia-namespaces
- \ingroup multimedia
+ \class QMediaMetaData
\inmodule QtMultimedia
- \brief Provides identifiers for meta-data attributes.
+ \brief Provides meta-data for media files.
- \note Not all identifiers are supported on all platforms. Please consult vendor documentation for specific support
- on different platforms.
+ \note Not all identifiers are supported on all platforms.
\table 60%
\header \li {3,1}
Common attributes
\header \li Value \li Description \li Type
\row \li Title \li The title of the media. \li QString
- \row \li SubTitle \li The sub-title of the media. \li QString
\row \li Author \li The authors of the media. \li QStringList
\row \li Comment \li A user comment about the media. \li QString
\row \li Description \li A description of the media. \li QString
- \row \li Category \li The category of the media. \li QStringList
\row \li Genre \li The genre of the media. \li QStringList
- \row \li Year \li The year of release of the media. \li int
- \row \li Date \li The date of the media. \li QDate.
- \row \li UserRating \li A user rating of the media. \li int [0..100]
- \row \li Keywords \li A list of keywords describing the media. \li QStringList
- \row \li Language \li The language of media, as an ISO 639-2 code. \li QString
+ \row \li Date \li The date of the media. \li QDateTime.
+ \row \li Language \li The language of media. \li QLocale::Language
\row \li Publisher \li The publisher of the media. \li QString
\row \li Copyright \li The media's copyright notice. \li QString
- \row \li ParentalRating \li The parental rating of the media. \li QString
- \row \li RatingOrganization \li The organization responsible for the parental rating of the media.
- \li QString
+ \row \li Url \li A Url pointing to the origin of the media. \li QUrl
\header \li {3,1}
Media attributes
- \row \li Size \li The size in bytes of the media. \li qint64
\row \li MediaType \li The type of the media (audio, video, etc). \li QString
- \row \li Duration \li The duration in millseconds of the media. \li qint64
+ \row \li FileFormat \li The file format of the media. \li QMediaFormat::FileFormat
+ \row \li Duration \li The duration in milliseconds of the media. \li qint64
\header \li {3,1}
Audio attributes
\row \li AudioBitRate \li The bit rate of the media's audio stream in bits per second. \li int
- \row \li AudioCodec \li The codec of the media's audio stream. \li QString
- \row \li AverageLevel \li The average volume level of the media. \li int
- \row \li ChannelCount \li The number of channels in the media's audio stream. \li int
- \row \li PeakValue \li The peak volume of the media's audio stream. \li int
- \row \li SampleRate \li The sample rate of the media's audio stream in hertz. \li int
+ \row \li AudioCodec \li The codec of the media's audio stream. \li QMediaFormat::AudioCodec
+
+ \header \li {3,1}
+ Video attributes
+ \row \li VideoFrameRate \li The frame rate of the media's video stream. \li qreal
+ \row \li VideoBitRate \li The bit rate of the media's video stream in bits per second. \li int
+ \row \li VideoCodec \li The codec of the media's video stream. \li QMediaFormat::VideoCodec
+ \row \li HasHdrContent \li True if video is intended for HDR display (FFmpeg media backend only). \li bool
\header \li {3,1}
Music attributes
\row \li AlbumTitle \li The title of the album the media belongs to. \li QString
\row \li AlbumArtist \li The principal artist of the album the media belongs to. \li QString
\row \li ContributingArtist \li The artists contributing to the media. \li QStringList
- \row \li Composer \li The composer of the media. \li QStringList
- \row \li Conductor \li The conductor of the media. \li QString
- \row \li Lyrics \li The lyrics to the media. \li QString
- \row \li Mood \li The mood of the media. \li QString
\row \li TrackNumber \li The track number of the media. \li int
- \row \li TrackCount \li The number of tracks on the album containing the media. \li int
+ \row \li Composer \li The composer of the media. \li QStringList
+ \row \li LeadPerformer \li The lead performer in the media. \li QStringList
- \row \li CoverArtUrlSmall \li The URL of a small cover art image. \li QUrl
- \row \li CoverArtUrlLarge \li The URL of a large cover art image. \li QUrl
+ \row \li ThumbnailImage \li An embedded thumbnail image if present in metadata. \li QImage
\row \li CoverArtImage \li An embedded cover art image. \li QImage
\header \li {3,1}
Image and video attributes
+ \row \li Orientation \li The rotation angle of an image or video. \li int
\row \li Resolution \li The dimensions of an image or video. \li QSize
- \row \li PixelAspectRatio \li The pixel aspect ratio of an image or video. \li QSize
- \row \li Orientation \li Orientation of an image or video. \li int (degrees)
- \header \li {3,1}
- Video attributes
- \row \li VideoFrameRate \li The frame rate of the media's video stream. \li qreal
- \row \li VideoBitRate \li The bit rate of the media's video stream in bits per second. \li int
- \row \li VideoCodec \li The codec of the media's video stream. \li QString
+ \endtable
+*/
- \row \li PosterUrl \li The URL of a poster image. \li QUrl
- \row \li PosterImage \li An embedded poster image. \li QImage
- \header \li {3,1}
- Movie attributes
- \row \li ChapterNumber \li The chapter number of the media. \li int
- \row \li Director \li The director of the media. \li QString
- \row \li LeadPerformer \li The lead performer in the media. \li QStringList
- \row \li Writer \li The writer of the media. \li QStringList
+/*!
+ Returns the meta type used to store data for Key \a key.
+*/
+QMetaType QMediaMetaData::keyType(Key key)
+{
+ switch (key) {
+ case Title:
+ case Comment:
+ case Description:
+ case Publisher:
+ case Copyright:
+ case MediaType:
+ case AlbumTitle:
+ case AlbumArtist:
+ return QMetaType::fromType<QString>();
+ case Genre:
+ case Author:
+ case ContributingArtist:
+ case Composer:
+ case LeadPerformer:
+ return QMetaType::fromType<QStringList>();
+
+ case Date:
+ return QMetaType::fromType<QDateTime>();
+
+ case Language:
+ return QMetaType::fromType<QLocale::Language>();
+ case Url:
+ return QMetaType::fromType<QUrl>();
+
+ case Duration:
+ return QMetaType::fromType<qint64>();
+ case FileFormat:
+ return QMetaType::fromType<QMediaFormat::FileFormat>();
+
+ case AudioBitRate:
+ case VideoBitRate:
+ case TrackNumber:
+ case Orientation:
+ return QMetaType::fromType<int>();
+ case AudioCodec:
+ return QMetaType::fromType<QMediaFormat::AudioCodec>();
+ case VideoCodec:
+ return QMetaType::fromType<QMediaFormat::VideoCodec>();
+ case VideoFrameRate:
+ return QMetaType::fromType<qreal>();
+
+
+ case ThumbnailImage:
+ case CoverArtImage:
+ return QMetaType::fromType<QImage>();
+
+ case Resolution:
+ return QMetaType::fromType<QSize>();
+
+ case HasHdrContent:
+ return QMetaType::fromType<bool>();
+
+ default:
+ return QMetaType::fromType<void>();
+ }
+}
+
+/*!
+ \qmlvaluetype mediaMetaData
+ \ingroup qmlvaluetypes
+ \inqmlmodule QtMultimedia
+ \since 6.2
+ //! \instantiates QMediaMetaData
+ \brief Provides meta-data for media files.
+ \ingroup multimedia_qml
+ \ingroup multimedia_audio_qml
+ \ingroup multimedia_video_qml
+
+ Meta-data is supplementary data describing media.
+ See QMediaMetaData for available meta data attributes.
+*/
+
+/*
+ Some potential attributes to add if we can properly support them.
+ Might require that we add EXIF support to Qt Multimedia
\header \li {3,1}
Photo attributes.
@@ -275,17 +177,16 @@ Q_DEFINE_METADATA(ThumbnailImage);
\row \li DateTimeOriginal \li The date and time when the original image data was generated. \li QDateTime
\row \li DateTimeDigitized \li The date and time when the image was stored as digital data. \li QDateTime
\row \li SubjectDistance \li The distance to the subject, given in meters. \li qreal
- \row \li MeteringMode \li The metering mode. \li QCameraExposure::MeteringMode
\row \li LightSource
\li The kind of light source. \li QString
\row \li Flash
- \li Status of flash when the image was shot. \li QCameraExposure::FlashMode
+ \li Status of flash when the image was shot. \li QCamera::FlashMode
\row \li FocalLength
\li The actual focal length of the lens, in mm. \li qreal
\row \li ExposureMode
- \li Indicates the exposure mode set when the image was shot. \li QCameraExposure::ExposureMode
+ \li Indicates the exposure mode set when the image was shot. \li QCamera::ExposureMode
\row \li WhiteBalance
- \li Indicates the white balance mode set when the image was shot. \li QCameraImageProcessing::WhiteBalanceMode
+ \li Indicates the white balance mode set when the image was shot. \li QCamera::WhiteBalanceMode
\row \li DigitalZoomRatio
\li Indicates the digital zoom ratio when the image was shot. \li qreal
\row \li FocalLengthIn35mmFilm
@@ -345,8 +246,281 @@ Q_DEFINE_METADATA(ThumbnailImage);
\row \li GPSAreaInformation
\li The name of the GPS area. \li QString
- \row \li ThumbnailImage \li An embedded thumbnail image. \li QImage
\endtable
*/
+/*!
+ \enum QMediaMetaData::Key
+
+ The following meta data keys can be used:
+
+ \value Title Media title
+ \value Author Media author
+ \value Comment Comment
+ \value Description Brief desripttion
+ \value Genre Genre the media belongs to
+ \value Date Creation date
+ \value Language Media language
+ \value Publisher Media publisher info.
+ \value Copyright Media copyright info.
+ \value Url Publisher's website URL
+ \value Duration Media playback duration
+ \value MediaType Type of the media
+ \value FileFormat File format
+ \value AudioBitRate
+ \value AudioCodec
+ \value VideoBitRate
+ \value VideoCodec
+ \value VideoFrameRate
+ \value AlbumTitle Album's title
+ \value AlbumArtist Artist's info.
+ \value ContributingArtist
+ \value TrackNumber
+ \value Composer Media composer's info.
+ \value LeadPerformer
+ \value ThumbnailImage Media thumbnail image (if embedded in metadata)
+ \value CoverArtImage Media cover art
+ \value Orientation
+ \value Resolution
+ \value [since 6.8] HasHdrContent Video may have HDR content (read only, FFmpeg media backend only)
+*/
+
+/*!
+ \variable QMediaMetaData::NumMetaData
+ \internal
+*/
+
+/*!
+ \qmlmethod variant QtMultimedia::mediaMetaData::value(Key key)
+
+ Returns the meta data value for Key \a key, or a null QVariant if no
+ meta-data for the key is available.
+*/
+
+/*!
+ \fn QVariant QMediaMetaData::value(QMediaMetaData::Key key) const
+
+ Returns the meta data value for Key \a key, or a null QVariant if no
+ meta data for the key is available.
+*/
+
+/*!
+ \qmlmethod bool QtMultimedia::mediaMetaData::isEmpty()
+ Returns \c true if the meta data contains no items: otherwise returns \c{false}.
+*/
+
+/*!
+ \fn bool QMediaMetaData::isEmpty() const
+ Returns \c true if the meta data contains no items: otherwise returns \c{false}.
+*/
+
+/*!
+ \qmlmethod void QtMultimedia::mediaMetaData::clear()
+ Removes all data from the MediaMetaData object.
+*/
+
+/*!
+ \fn void QMediaMetaData::clear()
+ Removes all data from the meta data object.
+*/
+
+/*!
+ \qmlmethod void QtMultimedia::mediaMetaData::insert(Key k, variant value)
+ Inserts a \a value into a Key: \a{k}.
+*/
+
+/*!
+ \fn void QMediaMetaData::insert(QMediaMetaData::Key k, const QVariant &value)
+ Inserts a \a value into a Key: \a{k}.
+*/
+/*!
+ \qmlmethod void QtMultimedia::mediaMetaData::remove(Key k)
+ Removes meta data from a Key: \a{k}.
+*/
+
+/*!
+ \fn void QMediaMetaData::remove(QMediaMetaData::Key k)
+ Removes meta data from a Key: \a{k}.
+*/
+
+/*!
+ \qmlmethod list<Key> QtMultimedia::mediaMetaData::keys()
+ Returns a list of MediaMetaData.Keys.
+*/
+
+/*!
+ \fn QMediaMetaData::keys() const
+ Returns a QList of QMediaMetaData::Keys.
+*/
+
+/*!
+ \qmlmethod string QtMultimedia::mediaMetaData::stringValue(Key key)
+ Returns the meta data for key \a key as a QString.
+
+ This is mainly meant to simplify presenting the meta data to a user.
+*/
+/*!
+ Returns the meta data for key \a key as a QString.
+
+ This is mainly meant to simplify presenting the meta data to a user.
+*/
+QString QMediaMetaData::stringValue(QMediaMetaData::Key key) const
+{
+ QVariant value = data.value(key);
+ if (value.isNull())
+ return QString();
+
+ switch (key) {
+ // string based or convertible to string
+ case Title:
+ case Author:
+ case Comment:
+ case Description:
+ case Genre:
+ case Publisher:
+ case Copyright:
+ case Date:
+ case Url:
+ case MediaType:
+ case AudioBitRate:
+ case VideoBitRate:
+ case VideoFrameRate:
+ case AlbumTitle:
+ case AlbumArtist:
+ case ContributingArtist:
+ case TrackNumber:
+ case Composer:
+ case Orientation:
+ case LeadPerformer:
+ case HasHdrContent:
+ return value.toString();
+ case Language: {
+ auto l = value.value<QLocale::Language>();
+ return QLocale::languageToString(l);
+ }
+ case Duration: {
+ QTime time = QTime::fromMSecsSinceStartOfDay(value.toInt());
+ return time.toString();
+ }
+ case FileFormat:
+ return QMediaFormat::fileFormatName(value.value<QMediaFormat::FileFormat>());
+ case AudioCodec:
+ return QMediaFormat::audioCodecName(value.value<QMediaFormat::AudioCodec>());
+ case VideoCodec:
+ return QMediaFormat::videoCodecName(value.value<QMediaFormat::VideoCodec>());
+ case Resolution: {
+ QSize size = value.toSize();
+ return QStringLiteral("%1 x %2").arg(size.width()).arg(size.height());
+ }
+ case ThumbnailImage:
+ case CoverArtImage:
+ break;
+ }
+ return QString();
+}
+/*!
+ \qmlmethod string QtMultimedia::mediaMetaData::metaDataKeyToString(Key key)
+ returns a string representation of \a key that can be used when presenting
+ meta data to users.
+*/
+
+/*!
+ returns a string representation of \a key that can be used when presenting
+ meta data to users.
+*/
+QString QMediaMetaData::metaDataKeyToString(QMediaMetaData::Key key)
+{
+ switch (key) {
+ case QMediaMetaData::Title:
+ return (QCoreApplication::translate("QMediaMetaData", "Title"));
+ case QMediaMetaData::Author:
+ return (QCoreApplication::translate("QMediaMetaData", "Author"));
+ case QMediaMetaData::Comment:
+ return (QCoreApplication::translate("QMediaMetaData", "Comment"));
+ case QMediaMetaData::Description:
+ return (QCoreApplication::translate("QMediaMetaData", "Description"));
+ case QMediaMetaData::Genre:
+ return (QCoreApplication::translate("QMediaMetaData", "Genre"));
+ case QMediaMetaData::Date:
+ return (QCoreApplication::translate("QMediaMetaData", "Date"));
+ case QMediaMetaData::Language:
+ return (QCoreApplication::translate("QMediaMetaData", "Language"));
+ case QMediaMetaData::Publisher:
+ return (QCoreApplication::translate("QMediaMetaData", "Publisher"));
+ case QMediaMetaData::Copyright:
+ return (QCoreApplication::translate("QMediaMetaData", "Copyright"));
+ case QMediaMetaData::Url:
+ return (QCoreApplication::translate("QMediaMetaData", "Url"));
+ case QMediaMetaData::Duration:
+ return (QCoreApplication::translate("QMediaMetaData", "Duration"));
+ case QMediaMetaData::MediaType:
+ return (QCoreApplication::translate("QMediaMetaData", "Media type"));
+ case QMediaMetaData::FileFormat:
+ return (QCoreApplication::translate("QMediaMetaData", "Container Format"));
+ case QMediaMetaData::AudioBitRate:
+ return (QCoreApplication::translate("QMediaMetaData", "Audio bit rate"));
+ case QMediaMetaData::AudioCodec:
+ return (QCoreApplication::translate("QMediaMetaData", "Audio codec"));
+ case QMediaMetaData::VideoBitRate:
+ return (QCoreApplication::translate("QMediaMetaData", "Video bit rate"));
+ case QMediaMetaData::VideoCodec:
+ return (QCoreApplication::translate("QMediaMetaData", "Video codec"));
+ case QMediaMetaData::VideoFrameRate:
+ return (QCoreApplication::translate("QMediaMetaData", "Video frame rate"));
+ case QMediaMetaData::AlbumTitle:
+ return (QCoreApplication::translate("QMediaMetaData", "Album title"));
+ case QMediaMetaData::AlbumArtist:
+ return (QCoreApplication::translate("QMediaMetaData", "Album artist"));
+ case QMediaMetaData::ContributingArtist:
+ return (QCoreApplication::translate("QMediaMetaData", "Contributing artist"));
+ case QMediaMetaData::TrackNumber:
+ return (QCoreApplication::translate("QMediaMetaData", "Track number"));
+ case QMediaMetaData::Composer:
+ return (QCoreApplication::translate("QMediaMetaData", "Composer"));
+ case QMediaMetaData::ThumbnailImage:
+ return (QCoreApplication::translate("QMediaMetaData", "Thumbnail image"));
+ case QMediaMetaData::CoverArtImage:
+ return (QCoreApplication::translate("QMediaMetaData", "Cover art image"));
+ case QMediaMetaData::Orientation:
+ return (QCoreApplication::translate("QMediaMetaData", "Orientation"));
+ case QMediaMetaData::Resolution:
+ return (QCoreApplication::translate("QMediaMetaData", "Resolution"));
+ case QMediaMetaData::LeadPerformer:
+ return (QCoreApplication::translate("QMediaMetaData", "Lead performer"));
+ case QMediaMetaData::HasHdrContent:
+ return (QCoreApplication::translate("QMediaMetaData", "Has HDR content"));
+ }
+ return QString();
+}
+
+// operator documentation
+/*!
+\fn QVariant &QMediaMetaData ::operator[](QMediaMetaData::Key k)
+ Returns data stored at the Key \a{k}.
+ \code
+ QMediaMetaData rockBallad1;
+ rockBalad[QMediaMetaData::Genre]="Rock"
+ \endcode
+*/
+
+/*!
+\fn bool QMediaMetaData::operator==(const QMediaMetaData &a, const QMediaMetaData &b)
+ Compares two meta data objects \a a and \a b, and returns
+ \c true if they are identical or \c false if they differ.
+*/
+
+/*!
+\fn bool QMediaMetaData::operator!=(const QMediaMetaData &a, const QMediaMetaData &b)
+ Compares two meta data objects \a a and \a b, and returns
+ \c false if they are identical or \c true if they differ.
+*/
+
+/*!
+ \variable QMediaMetaData::data
+ \brief the meta data.
+ \note this is a \c protected member of its class.
+*/
+
QT_END_NAMESPACE
+
+#include "moc_qmediametadata.cpp"
diff --git a/src/multimedia/qmediametadata.h b/src/multimedia/qmediametadata.h
index 8d8744490..0ff03dda2 100644
--- a/src/multimedia/qmediametadata.h
+++ b/src/multimedia/qmediametadata.h
@@ -1,49 +1,17 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMEDIAMETADATA_H
#define QMEDIAMETADATA_H
+#if 0
+#pragma qt_class(QMediaMetaData)
+#endif
+
#include <QtCore/qpair.h>
-#include <QtCore/qmetatype.h>
+#include <QtCore/qvariant.h>
#include <QtCore/qstring.h>
-
+#include <QtCore/qhash.h>
#include <QtMultimedia/qtmultimediaglobal.h>
QT_BEGIN_NAMESPACE
@@ -51,238 +19,79 @@ QT_BEGIN_NAMESPACE
// Class forward declaration required for QDoc bug
class QString;
-#define Q_DECLARE_METADATA(key) Q_MULTIMEDIA_EXPORT extern const QString key
-
-namespace QMediaMetaData {
-#ifdef Q_QDOC
- // QDoc does not like macros, so try to keep this in sync :)
- QString Title;
- QString SubTitle;
- QString Author;
- QString Comment;
- QString Description;
- QString Category;
- QString Genre;
- QString Year;
- QString Date;
- QString UserRating;
- QString Keywords;
- QString Language;
- QString Publisher;
- QString Copyright;
- QString ParentalRating;
- QString RatingOrganization;
-
- // Media
- QString Size;
- QString MediaType;
- QString Duration;
-
- // Audio
- QString AudioBitRate;
- QString AudioCodec;
- QString AverageLevel;
- QString ChannelCount;
- QString PeakValue;
- QString SampleRate;
-
- // Music
- QString AlbumTitle;
- QString AlbumArtist;
- QString ContributingArtist;
- QString Composer;
- QString Conductor;
- QString Lyrics;
- QString Mood;
- QString TrackNumber;
- QString TrackCount;
-
- QString CoverArtUrlSmall;
- QString CoverArtUrlLarge;
-
- // Image/Video
- QString Resolution;
- QString PixelAspectRatio;
-
- // Video
- QString VideoFrameRate;
- QString VideoBitRate;
- QString VideoCodec;
-
- QString PosterUrl;
-
- // Movie
- QString ChapterNumber;
- QString Director;
- QString LeadPerformer;
- QString Writer;
-
- // Photos
- QString CameraManufacturer;
- QString CameraModel;
- QString Event;
- QString Subject;
- QString Orientation;
- QString ExposureTime;
- QString FNumber;
- QString ExposureProgram;
- QString ISOSpeedRatings;
- QString ExposureBiasValue;
- QString DateTimeOriginal;
- QString DateTimeDigitized;
- QString SubjectDistance;
- QString MeteringMode;
- QString LightSource;
- QString Flash;
- QString FocalLength;
- QString ExposureMode;
- QString WhiteBalance;
- QString DigitalZoomRatio;
- QString FocalLengthIn35mmFilm;
- QString SceneCaptureType;
- QString GainControl;
- QString Contrast;
- QString Saturation;
- QString Sharpness;
- QString DeviceSettingDescription;
-
- // Location
- QString GPSLatitude;
- QString GPSLongitude;
- QString GPSAltitude;
- QString GPSTimeStamp;
- QString GPSSatellites;
- QString GPSStatus;
- QString GPSDOP;
- QString GPSSpeed;
- QString GPSTrack;
- QString GPSTrackRef;
- QString GPSImgDirection;
- QString GPSImgDirectionRef;
- QString GPSMapDatum;
- QString GPSProcessingMethod;
- QString GPSAreaInformation;
-
- QString PosterImage;
- QString CoverArtImage;
- QString ThumbnailImage;
-#else
- // Common
- Q_DECLARE_METADATA(Title);
- Q_DECLARE_METADATA(SubTitle);
- Q_DECLARE_METADATA(Author);
- Q_DECLARE_METADATA(Comment);
- Q_DECLARE_METADATA(Description);
- Q_DECLARE_METADATA(Category);
- Q_DECLARE_METADATA(Genre);
- Q_DECLARE_METADATA(Year);
- Q_DECLARE_METADATA(Date);
- Q_DECLARE_METADATA(UserRating);
- Q_DECLARE_METADATA(Keywords);
- Q_DECLARE_METADATA(Language);
- Q_DECLARE_METADATA(Publisher);
- Q_DECLARE_METADATA(Copyright);
- Q_DECLARE_METADATA(ParentalRating);
- Q_DECLARE_METADATA(RatingOrganization);
-
- // Media
- Q_DECLARE_METADATA(Size);
- Q_DECLARE_METADATA(MediaType);
- Q_DECLARE_METADATA(Duration);
-
- // Audio
- Q_DECLARE_METADATA(AudioBitRate);
- Q_DECLARE_METADATA(AudioCodec);
- Q_DECLARE_METADATA(AverageLevel);
- Q_DECLARE_METADATA(ChannelCount);
- Q_DECLARE_METADATA(PeakValue);
- Q_DECLARE_METADATA(SampleRate);
-
- // Music
- Q_DECLARE_METADATA(AlbumTitle);
- Q_DECLARE_METADATA(AlbumArtist);
- Q_DECLARE_METADATA(ContributingArtist);
- Q_DECLARE_METADATA(Composer);
- Q_DECLARE_METADATA(Conductor);
- Q_DECLARE_METADATA(Lyrics);
- Q_DECLARE_METADATA(Mood);
- Q_DECLARE_METADATA(TrackNumber);
- Q_DECLARE_METADATA(TrackCount);
-
- Q_DECLARE_METADATA(CoverArtUrlSmall);
- Q_DECLARE_METADATA(CoverArtUrlLarge);
-
- // Image/Video
- Q_DECLARE_METADATA(Resolution);
- Q_DECLARE_METADATA(PixelAspectRatio);
-
- // Video
- Q_DECLARE_METADATA(VideoFrameRate);
- Q_DECLARE_METADATA(VideoBitRate);
- Q_DECLARE_METADATA(VideoCodec);
-
- Q_DECLARE_METADATA(PosterUrl);
-
- // Movie
- Q_DECLARE_METADATA(ChapterNumber);
- Q_DECLARE_METADATA(Director);
- Q_DECLARE_METADATA(LeadPerformer);
- Q_DECLARE_METADATA(Writer);
-
- // Photos
- Q_DECLARE_METADATA(CameraManufacturer);
- Q_DECLARE_METADATA(CameraModel);
- Q_DECLARE_METADATA(Event);
- Q_DECLARE_METADATA(Subject);
- Q_DECLARE_METADATA(Orientation);
- Q_DECLARE_METADATA(ExposureTime);
- Q_DECLARE_METADATA(FNumber);
- Q_DECLARE_METADATA(ExposureProgram);
- Q_DECLARE_METADATA(ISOSpeedRatings);
- Q_DECLARE_METADATA(ExposureBiasValue);
- Q_DECLARE_METADATA(DateTimeOriginal);
- Q_DECLARE_METADATA(DateTimeDigitized);
- Q_DECLARE_METADATA(SubjectDistance);
- Q_DECLARE_METADATA(MeteringMode);
- Q_DECLARE_METADATA(LightSource);
- Q_DECLARE_METADATA(Flash);
- Q_DECLARE_METADATA(FocalLength);
- Q_DECLARE_METADATA(ExposureMode);
- Q_DECLARE_METADATA(WhiteBalance);
- Q_DECLARE_METADATA(DigitalZoomRatio);
- Q_DECLARE_METADATA(FocalLengthIn35mmFilm);
- Q_DECLARE_METADATA(SceneCaptureType);
- Q_DECLARE_METADATA(GainControl);
- Q_DECLARE_METADATA(Contrast);
- Q_DECLARE_METADATA(Saturation);
- Q_DECLARE_METADATA(Sharpness);
- Q_DECLARE_METADATA(DeviceSettingDescription);
-
- // Location
- Q_DECLARE_METADATA(GPSLatitude);
- Q_DECLARE_METADATA(GPSLongitude);
- Q_DECLARE_METADATA(GPSAltitude);
- Q_DECLARE_METADATA(GPSTimeStamp);
- Q_DECLARE_METADATA(GPSSatellites);
- Q_DECLARE_METADATA(GPSStatus);
- Q_DECLARE_METADATA(GPSDOP);
- Q_DECLARE_METADATA(GPSSpeed);
- Q_DECLARE_METADATA(GPSTrack);
- Q_DECLARE_METADATA(GPSTrackRef);
- Q_DECLARE_METADATA(GPSImgDirection);
- Q_DECLARE_METADATA(GPSImgDirectionRef);
- Q_DECLARE_METADATA(GPSMapDatum);
- Q_DECLARE_METADATA(GPSProcessingMethod);
- Q_DECLARE_METADATA(GPSAreaInformation);
-
- Q_DECLARE_METADATA(PosterImage);
- Q_DECLARE_METADATA(CoverArtImage);
- Q_DECLARE_METADATA(ThumbnailImage);
-#endif
-}
-
-#undef Q_DECLARE_METADATA
+class Q_MULTIMEDIA_EXPORT QMediaMetaData
+{
+ Q_GADGET
+public:
+ enum Key {
+ Title,
+ Author,
+ Comment,
+ Description,
+ Genre,
+ Date,
+
+ Language,
+ Publisher,
+ Copyright,
+ Url,
+
+ Duration,
+ MediaType,
+ FileFormat,
+
+ AudioBitRate,
+ AudioCodec,
+ VideoBitRate,
+ VideoCodec,
+ VideoFrameRate,
+
+ AlbumTitle,
+ AlbumArtist,
+ ContributingArtist,
+ TrackNumber,
+ Composer,
+ LeadPerformer,
+
+ ThumbnailImage,
+ CoverArtImage,
+
+ Orientation,
+ Resolution,
+
+ HasHdrContent
+ };
+ Q_ENUM(Key)
+
+ static constexpr int NumMetaData = HasHdrContent + 1;
+
+// QMetaType typeForKey(Key k);
+ Q_INVOKABLE QVariant value(Key k) const { return data.value(k); }
+ Q_INVOKABLE void insert(Key k, const QVariant &value) { data.insert(k, value); }
+ Q_INVOKABLE void remove(Key k) { data.remove(k); }
+ Q_INVOKABLE QList<Key> keys() const { return data.keys(); }
+
+ QVariant &operator[](Key k) { return data[k]; }
+ Q_INVOKABLE void clear() { data.clear(); }
+
+ Q_INVOKABLE bool isEmpty() const { return data.isEmpty(); }
+ Q_INVOKABLE QString stringValue(Key k) const;
+
+ Q_INVOKABLE static QString metaDataKeyToString(Key k);
+
+protected:
+ friend bool operator==(const QMediaMetaData &a, const QMediaMetaData &b)
+ { return a.data == b.data; }
+ friend bool operator!=(const QMediaMetaData &a, const QMediaMetaData &b)
+ { return a.data != b.data; }
+
+ static QMetaType keyType(Key key);
+
+ QHash<Key, QVariant> data;
+};
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QMediaMetaData)
+
#endif // QMEDIAMETADATA_H
diff --git a/src/multimedia/qmediaobject.cpp b/src/multimedia/qmediaobject.cpp
deleted file mode 100644
index a26433c8e..000000000
--- a/src/multimedia/qmediaobject.cpp
+++ /dev/null
@@ -1,427 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qmetaobject.h>
-#include <QtCore/qdebug.h>
-
-#include "qmediaobject_p.h"
-
-#include <qmediaservice.h>
-#include <qmetadatareadercontrol.h>
-#include <qmediabindableinterface.h>
-#include <qmediaavailabilitycontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-void QMediaObjectPrivate::_q_notify()
-{
- Q_Q(QMediaObject);
-
- const QMetaObject* m = q->metaObject();
-
- // QTBUG-57045
- // we create a copy of notifyProperties container to ensure that if a property is removed
- // from the original container as a result of invoking propertyChanged signal, the iterator
- // won't become invalidated
- QSet<int> properties = notifyProperties;
-
- for (int pi : qAsConst(properties)) {
- QMetaProperty p = m->property(pi);
- p.notifySignal().invoke(
- q, QGenericArgument(QMetaType::typeName(p.userType()), p.read(q).data()));
- }
-}
-
-void QMediaObjectPrivate::_q_availabilityChanged()
-{
- Q_Q(QMediaObject);
-
- // Really this should not always emit, but
- // we can't really tell from here (isAvailable
- // may not have changed, or the mediaobject's overridden
- // availability() may not have changed).
- q->availabilityChanged(q->availability());
- q->availabilityChanged(q->isAvailable());
-}
-
-/*!
- \class QMediaObject
-
- \brief The QMediaObject class provides a common base for multimedia objects.
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_core
-
- It provides some basic functionality that is common to other high level classes
- like \l QMediaPlayer, \l QAudioDecoder and \l QCamera, including availability
- and meta-data functionality, as well as functionality to connect media objects
- with support classes like QMediaPlaylist.
-
- The higher level QMediaObject derived classes provide the actual multimedia
- functionality, by internally using a QMediaService. Each media object
- hosts a QMediaService and uses the QMediaControl interfaces implemented by the service to implement its
- API. These controls can be accessed from the media object if necessary, but in general
- the useful functionality can be accessed from the higher level classes.
-
- Most media objects when constructed will request a new
- QMediaService instance, but some like
- QMediaRecorder and QAudioRecorder will share a service with another object.
-
- \sa QMediaService, QMediaControl
-*/
-
-/*!
- Destroys this media object.
-*/
-
-QMediaObject::~QMediaObject()
-{
-}
-
-/*!
- Returns the availability of the functionality offered by this object.
-
- In some cases the functionality may not be available (for example, if
- the current operating system or platform does not provide the required
- functionality), or it may be temporarily unavailable (for example,
- audio playback during a phone call or similar).
-*/
-
-QMultimedia::AvailabilityStatus QMediaObject::availability() const
-{
- if (d_func()->service == nullptr)
- return QMultimedia::ServiceMissing;
-
- if (d_func()->availabilityControl)
- return d_func()->availabilityControl->availability();
-
- return QMultimedia::Available;
-}
-
-/*!
- Returns true if the service is available for use.
-*/
-
-bool QMediaObject::isAvailable() const
-{
- return availability() == QMultimedia::Available;
-}
-
-/*!
- Returns the media service that provides the functionality of this multimedia object.
-*/
-
-QMediaService* QMediaObject::service() const
-{
- return d_func()->service;
-}
-
-int QMediaObject::notifyInterval() const
-{
- return d_func()->notifyTimer->interval();
-}
-
-void QMediaObject::setNotifyInterval(int milliSeconds)
-{
- Q_D(QMediaObject);
-
- if (d->notifyTimer->interval() != milliSeconds) {
- d->notifyTimer->setInterval(milliSeconds);
-
- emit notifyIntervalChanged(milliSeconds);
- }
-}
-
-/*!
- Bind \a object to this QMediaObject instance.
-
- This method establishes a relationship between this media object and a
- helper object. The nature of the relationship depends on both parties. This
- methods returns true if the helper was successfully bound, false otherwise.
-
- Most subclasses of QMediaObject provide more convenient functions
- that wrap this functionality, so this function rarely needs to be
- called directly.
-
- The object passed must implement the QMediaBindableInterface interface.
-
- \sa QMediaBindableInterface
-*/
-bool QMediaObject::bind(QObject *object)
-{
- QMediaBindableInterface *helper = qobject_cast<QMediaBindableInterface*>(object);
- if (!helper)
- return false;
-
- QMediaObject *currentObject = helper->mediaObject();
-
- if (currentObject == this)
- return true;
-
- if (currentObject)
- currentObject->unbind(object);
-
- return helper->setMediaObject(this);
-}
-
-/*!
- Detach \a object from the QMediaObject instance.
-
- Unbind the helper object from this media object. A warning
- will be generated if the object was not previously bound to this
- object.
-
- \sa QMediaBindableInterface
-*/
-void QMediaObject::unbind(QObject *object)
-{
- QMediaBindableInterface *helper = qobject_cast<QMediaBindableInterface*>(object);
-
- if (helper && helper->mediaObject() == this)
- helper->setMediaObject(nullptr);
- else
- qWarning() << "QMediaObject: Trying to unbind not connected helper object";
-}
-
-/*!
- Constructs a media object which uses the functionality provided by a media \a service.
-
- The \a parent is passed to QObject.
-
- This class is meant as a base class for multimedia objects so this
- constructor is protected.
-*/
-
-QMediaObject::QMediaObject(QObject *parent, QMediaService *service)
- : QObject(*new QMediaObjectPrivate, parent)
-{
- Q_D(QMediaObject);
-
- d->notifyTimer = new QTimer(this);
- d->notifyTimer->setInterval(1000);
- connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify()));
-
- d->service = service;
-
- setupControls();
-}
-
-/*!
- \internal
-*/
-
-QMediaObject::QMediaObject(QMediaObjectPrivate &dd, QObject *parent, QMediaService *service)
- : QObject(dd, parent)
-{
- Q_D(QMediaObject);
-
- d->notifyTimer = new QTimer(this);
- d->notifyTimer->setInterval(1000);
- connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify()));
-
- d->service = service;
-
- setupControls();
-}
-
-/*!
- Watch the property \a name. The property's notify signal will be emitted
- once every \c notifyInterval milliseconds.
-
- \sa notifyInterval
-*/
-
-void QMediaObject::addPropertyWatch(QByteArray const &name)
-{
- Q_D(QMediaObject);
-
- const QMetaObject* m = metaObject();
-
- int index = m->indexOfProperty(name.constData());
-
- if (index != -1 && m->property(index).hasNotifySignal()) {
- d->notifyProperties.insert(index);
-
- if (!d->notifyTimer->isActive())
- d->notifyTimer->start();
- }
-}
-
-/*!
- Remove property \a name from the list of properties whose changes are
- regularly signaled.
-
- \sa notifyInterval
-*/
-
-void QMediaObject::removePropertyWatch(QByteArray const &name)
-{
- Q_D(QMediaObject);
-
- int index = metaObject()->indexOfProperty(name.constData());
-
- if (index != -1) {
- d->notifyProperties.remove(index);
-
- if (d->notifyProperties.isEmpty())
- d->notifyTimer->stop();
- }
-}
-
-/*!
- \property QMediaObject::notifyInterval
-
- The interval at which notifiable properties will update.
-
- The interval is expressed in milliseconds, the default value is 1000.
-
- \sa addPropertyWatch(), removePropertyWatch()
-*/
-
-/*!
- \fn void QMediaObject::notifyIntervalChanged(int milliseconds)
-
- Signal a change in the notify interval period to \a milliseconds.
-*/
-
-/*!
- Returns true if there is meta-data associated with this media object, else false.
-*/
-
-bool QMediaObject::isMetaDataAvailable() const
-{
- Q_D(const QMediaObject);
-
- return d->metaDataControl
- ? d->metaDataControl->isMetaDataAvailable()
- : false;
-}
-
-/*!
- \fn QMediaObject::metaDataAvailableChanged(bool available)
-
- Signals that the \a available state of a media object's meta-data has changed.
-*/
-
-/*!
- Returns the value associated with a meta-data \a key.
-
- See the list of predefined \l {QMediaMetaData}{meta-data keys}.
-*/
-QVariant QMediaObject::metaData(const QString &key) const
-{
- Q_D(const QMediaObject);
-
- return d->metaDataControl
- ? d->metaDataControl->metaData(key)
- : QVariant();
-}
-
-/*!
- Returns a list of keys there is meta-data available for.
-*/
-QStringList QMediaObject::availableMetaData() const
-{
- Q_D(const QMediaObject);
-
- return d->metaDataControl
- ? d->metaDataControl->availableMetaData()
- : QStringList();
-}
-
-/*!
- \fn QMediaObject::metaDataChanged()
-
- Signals that this media object's meta-data has changed.
-
- If multiple meta-data elements are changed,
- metaDataChanged(const QString &key, const QVariant &value) signal is emitted
- for each of them with metaDataChanged() changed emitted once.
-*/
-
-/*!
- \fn QMediaObject::metaDataChanged(const QString &key, const QVariant &value)
-
- Signal the changes of one meta-data element \a value with the given \a key.
-*/
-
-
-void QMediaObject::setupControls()
-{
- Q_D(QMediaObject);
-
- if (d->service != nullptr) {
- d->metaDataControl = qobject_cast<QMetaDataReaderControl*>(
- d->service->requestControl(QMetaDataReaderControl_iid));
-
- if (d->metaDataControl) {
- connect(d->metaDataControl, SIGNAL(metaDataChanged()), SIGNAL(metaDataChanged()));
- connect(d->metaDataControl,
- SIGNAL(metaDataChanged(QString,QVariant)),
- SIGNAL(metaDataChanged(QString,QVariant)));
- connect(d->metaDataControl,
- SIGNAL(metaDataAvailableChanged(bool)),
- SIGNAL(metaDataAvailableChanged(bool)));
- }
-
- d->availabilityControl = d->service->requestControl<QMediaAvailabilityControl*>();
- if (d->availabilityControl) {
- connect(d->availabilityControl,
- SIGNAL(availabilityChanged(QMultimedia::AvailabilityStatus)),
- SLOT(_q_availabilityChanged()));
- }
- }
-}
-
-/*!
- \fn QMediaObject::availabilityChanged(bool available)
-
- Signal emitted when the availability state has changed to \a available.
-*/
-
-/*!
- \fn QMediaObject::availabilityChanged(QMultimedia::AvailabilityStatus availability)
-
- Signal emitted when the availability of the service has changed to \a availability.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaobject.cpp"
diff --git a/src/multimedia/qmediaobject.h b/src/multimedia/qmediaobject.h
deleted file mode 100644
index 7c8da9555..000000000
--- a/src/multimedia/qmediaobject.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QABSTRACTMEDIAOBJECT_H
-#define QABSTRACTMEDIAOBJECT_H
-
-#include <QtCore/qobject.h>
-#include <QtCore/qstringlist.h>
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaService;
-class QMediaBindableInterface;
-
-class QMediaObjectPrivate;
-class Q_MULTIMEDIA_EXPORT QMediaObject : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(int notifyInterval READ notifyInterval WRITE setNotifyInterval NOTIFY notifyIntervalChanged)
-public:
- ~QMediaObject();
-
- virtual bool isAvailable() const;
- virtual QMultimedia::AvailabilityStatus availability() const;
-
- virtual QMediaService* service() const;
-
- int notifyInterval() const;
- void setNotifyInterval(int milliSeconds);
-
- virtual bool bind(QObject *);
- virtual void unbind(QObject *);
-
- bool isMetaDataAvailable() const;
-
- QVariant metaData(const QString &key) const;
- QStringList availableMetaData() const;
-
-Q_SIGNALS:
- void notifyIntervalChanged(int milliSeconds);
-
- void metaDataAvailableChanged(bool available);
- void metaDataChanged();
- void metaDataChanged(const QString &key, const QVariant &value);
-
- void availabilityChanged(bool available);
- void availabilityChanged(QMultimedia::AvailabilityStatus availability);
-
-protected:
- QMediaObject(QObject *parent, QMediaService *service);
- QMediaObject(QMediaObjectPrivate &dd, QObject *parent, QMediaService *service);
-
- void addPropertyWatch(QByteArray const &name);
- void removePropertyWatch(QByteArray const &name);
-
-private:
- void setupControls();
-
- Q_DECLARE_PRIVATE(QMediaObject)
- Q_PRIVATE_SLOT(d_func(), void _q_notify())
- Q_PRIVATE_SLOT(d_func(), void _q_availabilityChanged())
-};
-
-
-QT_END_NAMESPACE
-
-
-#endif // QABSTRACTMEDIAOBJECT_H
diff --git a/src/multimedia/qmediaobject_p.h b/src/multimedia/qmediaobject_p.h
deleted file mode 100644
index 5067fa6d1..000000000
--- a/src/multimedia/qmediaobject_p.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QABSTRACTMEDIAOBJECT_P_H
-#define QABSTRACTMEDIAOBJECT_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qbytearray.h>
-#include <QtCore/qset.h>
-#include <QtCore/qtimer.h>
-
-#include "qmediaobject.h"
-#include "private/qobject_p.h"
-
-QT_BEGIN_NAMESPACE
-
-
-class QMetaDataReaderControl;
-class QMediaAvailabilityControl;
-
-#define Q_DECLARE_NON_CONST_PUBLIC(Class) \
- inline Class* q_func() { return static_cast<Class *>(q_ptr); } \
- friend class Class;
-
-
-class QMediaObjectPrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QMediaObject)
-
-public:
- QMediaObjectPrivate() : service(nullptr), metaDataControl(nullptr), availabilityControl(nullptr), notifyTimer(nullptr) {}
- virtual ~QMediaObjectPrivate() {}
-
- void _q_notify();
- void _q_availabilityChanged();
-
- QMediaService *service;
- QMetaDataReaderControl *metaDataControl;
- QMediaAvailabilityControl *availabilityControl;
-
- QTimer* notifyTimer;
- QSet<int> notifyProperties;
-};
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/multimedia/qmediapluginloader.cpp b/src/multimedia/qmediapluginloader.cpp
deleted file mode 100644
index 3e9e6cc21..000000000
--- a/src/multimedia/qmediapluginloader.cpp
+++ /dev/null
@@ -1,186 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediapluginloader_p.h"
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qjsonarray.h>
-#include <private/qfactoryloader_p.h>
-
-#include "qmediaserviceproviderplugin.h"
-
-QT_BEGIN_NAMESPACE
-
-QMediaPluginLoader::QMediaPluginLoader(const char *iid, const QString &location, Qt::CaseSensitivity caseSensitivity):
- m_iid(iid)
-{
-#if defined(Q_OS_ANDROID)
- m_location = QString(location).replace(QLatin1Char('/'), QLatin1Char('_'));
-#else
- m_location = QString::fromLatin1("/%1").arg(location);
-#endif
- m_factoryLoader = new QFactoryLoader(m_iid, m_location, caseSensitivity);
- loadMetadata();
-}
-
-QMediaPluginLoader::~QMediaPluginLoader()
-{
- delete m_factoryLoader;
-}
-
-QStringList QMediaPluginLoader::keys() const
-{
- return m_metadata.keys();
-}
-
-QObject* QMediaPluginLoader::instance(QString const &key)
-{
- if (!m_metadata.contains(key))
- return nullptr;
-
- int idx = m_metadata.value(key).first().value(QStringLiteral("index")).toDouble();
- if (idx < 0)
- return nullptr;
-
- return m_factoryLoader->instance(idx);
-}
-
-QList<QObject*> QMediaPluginLoader::instances(QString const &key)
-{
- if (!m_metadata.contains(key))
- return QList<QObject*>();
-
- QList<QString> keys;
- QList<QObject *> objects;
- const auto list = m_metadata.value(key);
- for (const QJsonObject &jsonobj : list) {
- int idx = jsonobj.value(QStringLiteral("index")).toDouble();
- if (idx < 0)
- continue;
-
- QObject *object = m_factoryLoader->instance(idx);
- if (!objects.contains(object)) {
- QJsonArray arr = jsonobj.value(QStringLiteral("Keys")).toArray();
- keys.append(!arr.isEmpty() ? arr.at(0).toString() : QStringLiteral(""));
- objects.append(object);
- }
- }
-
- static const bool showDebug = qEnvironmentVariableIntValue("QT_DEBUG_PLUGINS");
- static const QStringList preferredPlugins =
- qEnvironmentVariable("QT_MULTIMEDIA_PREFERRED_PLUGINS").split(QLatin1Char(','), Qt::SkipEmptyParts);
- for (int i = preferredPlugins.size() - 1; i >= 0; --i) {
- auto name = preferredPlugins[i];
- bool found = false;
- for (int j = 0; j < keys.size(); ++j) {
- if (!keys[j].startsWith(name))
- continue;
-
- auto obj = objects[j];
- objects.removeAt(j);
- objects.prepend(obj);
- auto k = keys[j];
- keys.removeAt(j);
- keys.prepend(k);
- found = true;
- break;
- }
-
- if (showDebug && !found)
- qWarning() << "QMediaPluginLoader: pattern" << name << "did not match any loaded plugin";
- }
-
- if (showDebug)
- qDebug() << "QMediaPluginLoader: loaded plugins for key" << key << ":" << keys;
-
- return objects;
-}
-
-void QMediaPluginLoader::loadMetadata()
-{
-#if !defined QT_NO_DEBUG
- const bool showDebug = qgetenv("QT_DEBUG_PLUGINS").toInt() > 0;
-#endif
-
-#if !defined QT_NO_DEBUG
- if (showDebug)
- qDebug() << "QMediaPluginLoader: loading metadata for iid " << m_iid << " at location " << m_location;
-#endif
-
- if (!m_metadata.isEmpty()) {
-#if !defined QT_NO_DEBUG
- if (showDebug)
- qDebug() << "QMediaPluginLoader: already loaded metadata, returning";
-#endif
- return;
- }
-
- QList<QJsonObject> meta = m_factoryLoader->metaData();
- for (int i = 0; i < meta.size(); i++) {
- QJsonObject jsonobj = meta.at(i).value(QStringLiteral("MetaData")).toObject();
- jsonobj.insert(QStringLiteral("index"), i);
-#if !defined QT_NO_DEBUG
- if (showDebug)
- qDebug() << "QMediaPluginLoader: Inserted index " << i << " into metadata: " << jsonobj;
-#endif
-
- QJsonArray arr = jsonobj.value(QStringLiteral("Services")).toArray();
- // Preserve compatibility with older plugins (made before 5.1) in which
- // services were declared in the 'Keys' property
- if (arr.isEmpty())
- arr = jsonobj.value(QStringLiteral("Keys")).toArray();
-
- for (const QJsonValue &value : qAsConst(arr)) {
- QString key = value.toString();
-
- if (!m_metadata.contains(key)) {
-#if !defined QT_NO_DEBUG
- if (showDebug)
- qDebug() << "QMediaPluginLoader: Inserting new list for key: " << key;
-#endif
- m_metadata.insert(key, QList<QJsonObject>());
- }
-
- m_metadata[key].append(jsonobj);
- }
- }
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/multimedia/qmediapluginloader_p.h b/src/multimedia/qmediapluginloader_p.h
deleted file mode 100644
index a4e726544..000000000
--- a/src/multimedia/qmediapluginloader_p.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIAPLUGINLOADER_H
-#define QMEDIAPLUGINLOADER_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <qtmultimediaglobal.h>
-#include <QtCore/qobject.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmap.h>
-#include <QtCore/qjsonobject.h>
-
-
-QT_BEGIN_NAMESPACE
-
-class QFactoryLoader;
-class QMediaServiceProviderPlugin;
-
-class Q_MULTIMEDIA_EXPORT QMediaPluginLoader
-{
-public:
- QMediaPluginLoader(const char *iid,
- const QString &suffix = QString(),
- Qt::CaseSensitivity = Qt::CaseSensitive);
- ~QMediaPluginLoader();
-
- QStringList keys() const;
- QObject* instance(QString const &key);
- QList<QObject*> instances(QString const &key);
-
-private:
- void loadMetadata();
-
- QByteArray m_iid;
- QString m_location;
- QMap<QString, QList<QJsonObject> > m_metadata;
-
- QFactoryLoader *m_factoryLoader;
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIAPLUGINLOADER_H
diff --git a/src/multimedia/qmediaresourcepolicy_p.cpp b/src/multimedia/qmediaresourcepolicy_p.cpp
deleted file mode 100644
index 14dc15968..000000000
--- a/src/multimedia/qmediaresourcepolicy_p.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaresourcepolicy_p.h"
-#include "qmediapluginloader_p.h"
-#include "qmediaresourcepolicyplugin_p.h"
-#include "qmediaresourceset_p.h"
-
-namespace {
- class QDummyMediaPlayerResourceSet : public QMediaPlayerResourceSetInterface
- {
- public:
- QDummyMediaPlayerResourceSet(QObject *parent)
- : QMediaPlayerResourceSetInterface(parent)
- {
- }
-
- bool isVideoEnabled() const override
- {
- return true;
- }
-
- bool isGranted() const override
- {
- return true;
- }
-
- bool isAvailable() const override
- {
- return true;
- }
-
- void acquire() override {}
- void release() override {}
- void setVideoEnabled(bool) override {}
- };
-}
-
-QT_BEGIN_NAMESPACE
-
-Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, resourcePolicyLoader,
- (QMediaResourceSetFactoryInterface_iid, QLatin1String("resourcepolicy"), Qt::CaseInsensitive))
-
-Q_GLOBAL_STATIC(QObject, dummyRoot)
-
-QObject* QMediaResourcePolicy::createResourceSet(const QString& interfaceId)
-{
- QMediaResourceSetFactoryInterface *factory =
- qobject_cast<QMediaResourceSetFactoryInterface*>(resourcePolicyLoader()
- ->instance(QLatin1String("default")));
- QObject *obj = nullptr;
- if (factory)
- obj = factory->create(interfaceId);
-
- if (!obj) {
- if (interfaceId == QLatin1String(QMediaPlayerResourceSetInterface_iid)) {
- obj = new QDummyMediaPlayerResourceSet(dummyRoot());
- }
- }
- Q_ASSERT(obj);
- return obj;
-}
-
-void QMediaResourcePolicy::destroyResourceSet(QObject* resourceSet)
-{
- if (resourceSet->parent() == dummyRoot()) {
- delete resourceSet;
- return;
- }
- QMediaResourceSetFactoryInterface *factory =
- qobject_cast<QMediaResourceSetFactoryInterface*>(resourcePolicyLoader()
- ->instance(QLatin1String("default")));
- Q_ASSERT(factory);
- if (!factory)
- return;
- return factory->destroy(resourceSet);
-}
-QT_END_NAMESPACE
diff --git a/src/multimedia/qmediaresourcepolicy_p.h b/src/multimedia/qmediaresourcepolicy_p.h
deleted file mode 100644
index 13e3f4913..000000000
--- a/src/multimedia/qmediaresourcepolicy_p.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIARESOURCEPOLICY_H
-#define QMEDIARESOURCEPOLICY_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QObject>
-#include "qtmultimediaglobal.h"
-
-QT_BEGIN_NAMESPACE
-
-class Q_MULTIMEDIA_EXPORT QMediaResourcePolicy
-{
-public:
- //a dummy object will always be provided if the interfaceId is not supported
- template<typename T>
- static T* createResourceSet();
- static void destroyResourceSet(QObject* resourceSet);
-private:
- static QObject* createResourceSet(const QString& interfaceId);
-};
-
-template<typename T>
-T* QMediaResourcePolicy::createResourceSet()
-{
- return qobject_cast<T*>(QMediaResourcePolicy::createResourceSet(T::iid()));
-}
-
-QT_END_NAMESPACE
-
-#endif // QMEDIARESOURCEPOLICY_H
diff --git a/src/multimedia/qmediaresourcepolicyplugin_p.cpp b/src/multimedia/qmediaresourcepolicyplugin_p.cpp
deleted file mode 100644
index 051eeb9db..000000000
--- a/src/multimedia/qmediaresourcepolicyplugin_p.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaresourcepolicyplugin_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QMediaResourcePolicyPlugin::QMediaResourcePolicyPlugin(QObject *parent)
- : QObject(parent)
-{
-}
-
-QMediaResourcePolicyPlugin::~QMediaResourcePolicyPlugin()
-{
-}
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/qmediaresourcepolicyplugin_p.h b/src/multimedia/qmediaresourcepolicyplugin_p.h
deleted file mode 100644
index e37551390..000000000
--- a/src/multimedia/qmediaresourcepolicyplugin_p.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QRESOURCEPOLICYPLUGIN_P_H
-#define QRESOURCEPOLICYPLUGIN_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QObject>
-#include <qtmultimediaglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-struct Q_MULTIMEDIA_EXPORT QMediaResourceSetFactoryInterface
-{
- virtual QObject* create(const QString& interfaceId) = 0;
- virtual void destroy(QObject *resourceSet) = 0;
-};
-
-#define QMediaResourceSetFactoryInterface_iid \
- "org.qt-project.qt.mediaresourcesetfactory/5.0"
-Q_DECLARE_INTERFACE(QMediaResourceSetFactoryInterface, QMediaResourceSetFactoryInterface_iid)
-
-class Q_MULTIMEDIA_EXPORT QMediaResourcePolicyPlugin : public QObject, public QMediaResourceSetFactoryInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaResourceSetFactoryInterface)
-
-public:
- QMediaResourcePolicyPlugin(QObject *parent = nullptr);
- ~QMediaResourcePolicyPlugin();
-};
-
-QT_END_NAMESPACE
-
-#endif // QRESOURCEPOLICYPLUGIN_P_H
diff --git a/src/multimedia/qmediaresourceset_p.cpp b/src/multimedia/qmediaresourceset_p.cpp
deleted file mode 100644
index 6f6d89d73..000000000
--- a/src/multimedia/qmediaresourceset_p.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaresourceset_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QMediaPlayerResourceSetInterface::QMediaPlayerResourceSetInterface(QObject *parent)
- : QObject(parent)
-{
-}
-
-QString QMediaPlayerResourceSetInterface::iid()
-{
- return QLatin1String(QMediaPlayerResourceSetInterface_iid);
-}
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/qmediaresourceset_p.h b/src/multimedia/qmediaresourceset_p.h
deleted file mode 100644
index 5ad4ca7aa..000000000
--- a/src/multimedia/qmediaresourceset_p.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIARESOURCESET_P_H
-#define QMEDIARESOURCESET_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-#include <QObject>
-#include <qtmultimediaglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-#define QMediaPlayerResourceSetInterface_iid \
- "org.qt-project.qt.mediaplayerresourceset/5.0"
-
-class Q_MULTIMEDIA_EXPORT QMediaPlayerResourceSetInterface : public QObject
-{
- Q_OBJECT
-public:
- virtual bool isVideoEnabled() const = 0;
- virtual bool isGranted() const = 0;
- virtual bool isAvailable() const = 0;
-
- virtual void acquire() = 0;
- virtual void release() = 0;
- virtual void setVideoEnabled(bool enabled) = 0;
-
- static QString iid();
-
-Q_SIGNALS:
- void resourcesGranted();
- void resourcesLost();
- void resourcesDenied();
- void resourcesReleased();
- void availabilityChanged(bool available);
-
-protected:
- QMediaPlayerResourceSetInterface(QObject *parent = nullptr);
-};
-
-QT_END_NAMESPACE
-
-#endif // QMEDIARESOURCESET_P_H
diff --git a/src/multimedia/qmediaservice.cpp b/src/multimedia/qmediaservice.cpp
deleted file mode 100644
index ad543acae..000000000
--- a/src/multimedia/qmediaservice.cpp
+++ /dev/null
@@ -1,143 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaservice.h"
-#include "qmediaservice_p.h"
-
-#include <QtCore/qtimer.h>
-
-
-
-QT_BEGIN_NAMESPACE
-
-
-/*!
- \class QMediaService
- \obsolete
- \brief The QMediaService class provides a common base class for media
- service implementations.
- \ingroup multimedia
- \ingroup multimedia_control
- \ingroup multimedia_core
- \inmodule QtMultimedia
-
- Media services provide implementations of the functionality promised
- by media objects, and allow multiple providers to implement a QMediaObject.
-
- To provide the functionality of a QMediaObject media services implement
- QMediaControl interfaces. Services typically implement one core media
- control which provides the core feature of a media object, and some
- number of additional controls which provide either optional features of
- the media object, or features of a secondary media object or peripheral
- object.
-
- A pointer to media service's QMediaControl implementation can be obtained
- by passing the control's interface name to the requestControl() function.
-
- \snippet multimedia-snippets/media.cpp Request control
-
- Media objects can use services loaded dynamically from plug-ins or
- implemented statically within an applications. Plug-in based services
- should also implement the QMediaServiceProviderPlugin interface. Static
- services should implement the QMediaServiceProvider interface. In general,
- implementing a QMediaService is outside of the scope of this documentation
- and support on the relevant mailing lists or IRC channels should be sought.
-
- \sa QMediaObject, QMediaControl
-*/
-
-/*!
- Construct a media service with the given \a parent. This class is meant as a
- base class for Multimedia services so this constructor is protected.
-*/
-
-QMediaService::QMediaService(QObject *parent)
- : QObject(*new QMediaServicePrivate, parent)
-{
-}
-
-/*!
- \internal
-*/
-QMediaService::QMediaService(QMediaServicePrivate &dd, QObject *parent)
- : QObject(dd, parent)
-{
-}
-
-/*!
- Destroys a media service.
-*/
-
-QMediaService::~QMediaService()
-{
-}
-
-/*!
- \fn QMediaControl* QMediaService::requestControl(const char *interface)
-
- Returns a pointer to the media control implementing \a interface.
-
- If the service does not implement the control, or if it is unavailable a
- null pointer is returned instead.
-
- Controls must be returned to the service when no longer needed using the
- releaseControl() function.
-*/
-
-/*!
- \fn T QMediaService::requestControl()
-
- Returns a pointer to the media control of type T implemented by a media service.
-
- If the service does not implement the control, or if it is unavailable a
- null pointer is returned instead.
-
- Controls must be returned to the service when no longer needed using the
- releaseControl() function.
-*/
-
-/*!
- \fn void QMediaService::releaseControl(QMediaControl *control);
-
- Releases a \a control back to the service.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaservice.cpp"
diff --git a/src/multimedia/qmediaservice.h b/src/multimedia/qmediaservice.h
deleted file mode 100644
index f3e38630c..000000000
--- a/src/multimedia/qmediaservice.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QABSTRACTMEDIASERVICE_H
-#define QABSTRACTMEDIASERVICE_H
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtCore/qobject.h>
-#include <QtCore/qstringlist.h>
-
-#include <QtMultimedia/qmediacontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaServicePrivate;
-class Q_MULTIMEDIA_EXPORT QMediaService : public QObject
-{
- Q_OBJECT
-
-public:
- ~QMediaService();
-
- virtual QMediaControl* requestControl(const char *name) = 0;
-
- template <typename T> inline T requestControl() {
- if (QMediaControl *control = requestControl(qmediacontrol_iid<T>())) {
- if (T typedControl = qobject_cast<T>(control))
- return typedControl;
- releaseControl(control);
- }
- return 0;
- }
-
- virtual void releaseControl(QMediaControl *control) = 0;
-
-protected:
- QMediaService(QObject* parent);
- QMediaService(QMediaServicePrivate &dd, QObject *parent);
-
-private:
- Q_DECLARE_PRIVATE(QMediaService)
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QABSTRACTMEDIASERVICE_H
-
diff --git a/src/multimedia/qmediaservice_p.h b/src/multimedia/qmediaservice_p.h
deleted file mode 100644
index a9dbd5d29..000000000
--- a/src/multimedia/qmediaservice_p.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QABSTRACTMEDIASERVICE_P_H
-#define QABSTRACTMEDIASERVICE_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "private/qobject_p.h"
-
-QT_BEGIN_NAMESPACE
-
-
-class QAudioDeviceControl;
-
-class QMediaServicePrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QMediaService)
-public:
- QMediaServicePrivate() {}
- virtual ~QMediaServicePrivate() {}
-};
-
-QT_END_NAMESPACE
-
-
-
-#endif
diff --git a/src/multimedia/qmediaserviceprovider.cpp b/src/multimedia/qmediaserviceprovider.cpp
deleted file mode 100644
index 93b560d8c..000000000
--- a/src/multimedia/qmediaserviceprovider.cpp
+++ /dev/null
@@ -1,1004 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qmap.h>
-
-#include "qmediaservice.h"
-#include "qmediaserviceprovider_p.h"
-#include "qmediaserviceproviderplugin.h"
-#include "qmediapluginloader_p.h"
-#include "qmediaplayer.h"
-
-QT_BEGIN_NAMESPACE
-
-QMediaServiceProviderFactoryInterface::~QMediaServiceProviderFactoryInterface()
-{
-}
-
-class QMediaServiceProviderHintPrivate : public QSharedData
-{
-public:
- QMediaServiceProviderHintPrivate(QMediaServiceProviderHint::Type type)
- : type(type)
- {
- }
-
- QMediaServiceProviderHintPrivate(const QMediaServiceProviderHintPrivate &other)
- :QSharedData(other),
- type(other.type),
- device(other.device),
- cameraPosition(other.cameraPosition),
- mimeType(other.mimeType),
- codecs(other.codecs),
- features(other.features)
- {
- }
-
- ~QMediaServiceProviderHintPrivate()
- {
- }
-
- QMediaServiceProviderHint::Type type;
- QByteArray device;
- QCamera::Position cameraPosition = QCamera::UnspecifiedPosition;
- QString mimeType;
- QStringList codecs;
- QMediaServiceProviderHint::Features features;
-};
-
-/*!
- \class QMediaServiceProviderHint
- \obsolete
-
- \brief The QMediaServiceProviderHint class describes what is required of a QMediaService.
-
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_control
- \ingroup multimedia_core
-
- \internal
-
- The QMediaServiceProvider class uses hints to select an appropriate media service.
-*/
-
-/*!
- \enum QMediaServiceProviderHint::Feature
-
- Enumerates features a media service may provide.
-
- \value LowLatencyPlayback
- The service is expected to play simple audio formats,
- but playback should start without significant delay.
- Such playback service can be used for beeps, ringtones, etc.
-
- \value RecordingSupport
- The service provides audio or video recording functions.
-
- \value StreamPlayback
- The service is capable of playing QIODevice based streams.
-
- \value VideoSurface
- The service is capable of renderering to a QAbstractVideoSurface
- output.
-*/
-
-/*!
- \enum QMediaServiceProviderHint::Type
-
- Enumerates the possible types of media service provider hint.
-
- \value Null En empty hint, use the default service.
- \value ContentType Select media service most suitable for certain content type.
- \value Device Select media service which supports certain device.
- \value SupportedFeatures Select media service supporting the set of optional features.
- \value CameraPosition Select media service having a camera at a specified position.
-*/
-
-
-/*!
- Constructs an empty media service provider hint.
-*/
-QMediaServiceProviderHint::QMediaServiceProviderHint()
- :d(new QMediaServiceProviderHintPrivate(Null))
-{
-}
-
-/*!
- Constructs a ContentType media service provider hint.
-
- This type of hint describes a service that is able to play content of a specific MIME \a type
- encoded with one or more of the listed \a codecs.
-*/
-QMediaServiceProviderHint::QMediaServiceProviderHint(const QString &type, const QStringList& codecs)
- :d(new QMediaServiceProviderHintPrivate(ContentType))
-{
- d->mimeType = type;
- d->codecs = codecs;
-}
-
-/*!
- Constructs a Device media service provider hint.
-
- This type of hint describes a media service that utilizes a specific \a device.
-*/
-QMediaServiceProviderHint::QMediaServiceProviderHint(const QByteArray &device)
- :d(new QMediaServiceProviderHintPrivate(Device))
-{
- d->device = device;
-}
-
-/*!
- \since 5.3
-
- Constructs a CameraPosition media service provider hint.
-
- This type of hint describes a media service that has a camera in the specific \a position.
-*/
-QMediaServiceProviderHint::QMediaServiceProviderHint(QCamera::Position position)
- :d(new QMediaServiceProviderHintPrivate(CameraPosition))
-{
- d->cameraPosition = position;
-}
-
-/*!
- Constructs a SupportedFeatures media service provider hint.
-
- This type of hint describes a service which supports a specific set of \a features.
-*/
-QMediaServiceProviderHint::QMediaServiceProviderHint(QMediaServiceProviderHint::Features features)
- :d(new QMediaServiceProviderHintPrivate(SupportedFeatures))
-{
- d->features = features;
-}
-
-/*!
- Constructs a copy of the media service provider hint \a other.
-*/
-QMediaServiceProviderHint::QMediaServiceProviderHint(const QMediaServiceProviderHint &other)
- :d(other.d)
-{
-}
-
-/*!
- Destroys a media service provider hint.
-*/
-QMediaServiceProviderHint::~QMediaServiceProviderHint()
-{
-}
-
-/*!
- Assigns the value \a other to a media service provider hint.
-*/
-QMediaServiceProviderHint& QMediaServiceProviderHint::operator=(const QMediaServiceProviderHint &other)
-{
- d = other.d;
- return *this;
-}
-
-/*!
- Identifies if \a other is of equal value to a media service provider hint.
-
- Returns true if the hints are equal, and false if they are not.
-*/
-bool QMediaServiceProviderHint::operator == (const QMediaServiceProviderHint &other) const
-{
- return (d == other.d) ||
- (d->type == other.d->type &&
- d->device == other.d->device &&
- d->cameraPosition == other.d->cameraPosition &&
- d->mimeType == other.d->mimeType &&
- d->codecs == other.d->codecs &&
- d->features == other.d->features);
-}
-
-/*!
- Identifies if \a other is not of equal value to a media service provider hint.
-
- Returns true if the hints are not equal, and false if they are.
-*/
-bool QMediaServiceProviderHint::operator != (const QMediaServiceProviderHint &other) const
-{
- return !(*this == other);
-}
-
-/*!
- Returns true if a media service provider is null.
-*/
-bool QMediaServiceProviderHint::isNull() const
-{
- return d->type == Null;
-}
-
-/*!
- Returns the type of a media service provider hint.
-*/
-QMediaServiceProviderHint::Type QMediaServiceProviderHint::type() const
-{
- return d->type;
-}
-
-/*!
- Returns the mime type of the media a service is expected to be able play.
-*/
-QString QMediaServiceProviderHint::mimeType() const
-{
- return d->mimeType;
-}
-
-/*!
- Returns a list of codes a media service is expected to be able to decode.
-*/
-QStringList QMediaServiceProviderHint::codecs() const
-{
- return d->codecs;
-}
-
-/*!
- Returns the name of a device a media service is expected to utilize.
-*/
-QByteArray QMediaServiceProviderHint::device() const
-{
- return d->device;
-}
-
-/*!
- \since 5.3
-
- Returns the camera's position a media service is expected to utilize.
-*/
-QCamera::Position QMediaServiceProviderHint::cameraPosition() const
-{
- return d->cameraPosition;
-}
-
-
-/*!
- Returns a set of features a media service is expected to provide.
-*/
-QMediaServiceProviderHint::Features QMediaServiceProviderHint::features() const
-{
- return d->features;
-}
-
-
-Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, loader,
- (QMediaServiceProviderFactoryInterface_iid, QLatin1String("mediaservice"), Qt::CaseInsensitive))
-
-
-class QPluginServiceProvider : public QMediaServiceProvider
-{
- struct MediaServiceData {
- QByteArray type;
- QMediaServiceProviderPlugin *plugin;
-
- MediaServiceData() : plugin(nullptr) { }
- };
-
- QMap<const QMediaService*, MediaServiceData> mediaServiceData;
-
-public:
- QMediaService* requestService(const QByteArray &type, const QMediaServiceProviderHint &hint) override
- {
- QString key(QLatin1String(type.constData()));
-
- QList<QMediaServiceProviderPlugin *>plugins;
- const auto instances = loader()->instances(key);
- for (QObject *obj : instances) {
- QMediaServiceProviderPlugin *plugin =
- qobject_cast<QMediaServiceProviderPlugin*>(obj);
- if (plugin)
- plugins << plugin;
- }
-
- if (!plugins.isEmpty()) {
- QMediaServiceProviderPlugin *plugin = nullptr;
-
- switch (hint.type()) {
- case QMediaServiceProviderHint::Null:
- plugin = plugins[0];
- //special case for media player, if low latency was not asked,
- //prefer services not offering it, since they are likely to support
- //more formats
- if (type == QByteArray(Q_MEDIASERVICE_MEDIAPLAYER)) {
- for (QMediaServiceProviderPlugin *currentPlugin : qAsConst(plugins)) {
- QMediaServiceFeaturesInterface *iface =
- qobject_cast<QMediaServiceFeaturesInterface*>(currentPlugin);
-
- if (!iface || !(iface->supportedFeatures(type) &
- QMediaServiceProviderHint::LowLatencyPlayback)) {
- plugin = currentPlugin;
- break;
- }
-
- }
- }
- break;
- case QMediaServiceProviderHint::SupportedFeatures:
- plugin = plugins[0];
- for (QMediaServiceProviderPlugin *currentPlugin : qAsConst(plugins)) {
- QMediaServiceFeaturesInterface *iface =
- qobject_cast<QMediaServiceFeaturesInterface*>(currentPlugin);
-
- if (iface) {
- if ((iface->supportedFeatures(type) & hint.features()) == hint.features()) {
- plugin = currentPlugin;
- break;
- }
- }
- }
- break;
- case QMediaServiceProviderHint::Device: {
- plugin = plugins[0];
- for (QMediaServiceProviderPlugin *currentPlugin : qAsConst(plugins)) {
- QMediaServiceSupportedDevicesInterface *iface =
- qobject_cast<QMediaServiceSupportedDevicesInterface*>(currentPlugin);
-
- if (iface && iface->devices(type).contains(hint.device())) {
- plugin = currentPlugin;
- break;
- }
- }
- }
- break;
- case QMediaServiceProviderHint::CameraPosition: {
- plugin = plugins[0];
- if (type == QByteArray(Q_MEDIASERVICE_CAMERA)
- && hint.cameraPosition() != QCamera::UnspecifiedPosition) {
- for (QMediaServiceProviderPlugin *currentPlugin : qAsConst(plugins)) {
- const QMediaServiceSupportedDevicesInterface *deviceIface =
- qobject_cast<QMediaServiceSupportedDevicesInterface*>(currentPlugin);
- const QMediaServiceCameraInfoInterface *cameraIface =
- qobject_cast<QMediaServiceCameraInfoInterface*>(currentPlugin);
-
- if (deviceIface && cameraIface) {
- const QList<QByteArray> cameras = deviceIface->devices(type);
- for (const QByteArray &camera : cameras) {
- if (cameraIface->cameraPosition(camera) == hint.cameraPosition()) {
- plugin = currentPlugin;
- break;
- }
- }
- }
- }
- }
- }
- break;
- case QMediaServiceProviderHint::ContentType: {
- QMultimedia::SupportEstimate estimate = QMultimedia::NotSupported;
- for (QMediaServiceProviderPlugin *currentPlugin : qAsConst(plugins)) {
- QMultimedia::SupportEstimate currentEstimate = QMultimedia::MaybeSupported;
- QMediaServiceSupportedFormatsInterface *iface =
- qobject_cast<QMediaServiceSupportedFormatsInterface*>(currentPlugin);
-
- if (iface)
- currentEstimate = iface->hasSupport(hint.mimeType(), hint.codecs());
-
- if (currentEstimate > estimate) {
- estimate = currentEstimate;
- plugin = currentPlugin;
-
- if (currentEstimate == QMultimedia::PreferredService)
- break;
- }
- }
- }
- break;
- }
-
- if (plugin != nullptr) {
- QMediaService *service = plugin->create(key);
- if (service != nullptr) {
- MediaServiceData d;
- d.type = type;
- d.plugin = plugin;
- mediaServiceData.insert(service, d);
- }
-
- return service;
- }
- }
-
- qWarning() << "defaultServiceProvider::requestService(): no service found for -" << key;
- return nullptr;
- }
-
- void releaseService(QMediaService *service) override
- {
- if (service != nullptr) {
- MediaServiceData d = mediaServiceData.take(service);
-
- if (d.plugin != nullptr)
- d.plugin->release(service);
- }
- }
-
- QMediaServiceProviderHint::Features supportedFeatures(const QMediaService *service) const override
- {
- if (service) {
- MediaServiceData d = mediaServiceData.value(service);
-
- if (d.plugin) {
- QMediaServiceFeaturesInterface *iface =
- qobject_cast<QMediaServiceFeaturesInterface*>(d.plugin);
-
- if (iface)
- return iface->supportedFeatures(d.type);
- }
- }
-
- return QMediaServiceProviderHint::Features();
- }
-
- QMultimedia::SupportEstimate hasSupport(const QByteArray &serviceType,
- const QString &mimeType,
- const QStringList& codecs,
- int flags) const override
- {
- const QList<QObject*> instances = loader()->instances(QLatin1String(serviceType));
-
- if (instances.isEmpty())
- return QMultimedia::NotSupported;
-
- bool allServicesProvideInterface = true;
- QMultimedia::SupportEstimate supportEstimate = QMultimedia::NotSupported;
-
- for (QObject *obj : instances) {
- QMediaServiceSupportedFormatsInterface *iface =
- qobject_cast<QMediaServiceSupportedFormatsInterface*>(obj);
-
-
- if (flags) {
- QMediaServiceFeaturesInterface *iface =
- qobject_cast<QMediaServiceFeaturesInterface*>(obj);
-
- if (iface) {
- QMediaServiceProviderHint::Features features = iface->supportedFeatures(serviceType);
-
- //if low latency playback was asked, skip services known
- //not to provide low latency playback
- if ((flags & QMediaPlayer::LowLatency) &&
- !(features & QMediaServiceProviderHint::LowLatencyPlayback))
- continue;
-
- //the same for QIODevice based streams support
- if ((flags & QMediaPlayer::StreamPlayback) &&
- !(features & QMediaServiceProviderHint::StreamPlayback))
- continue;
- }
- }
-
- if (iface)
- supportEstimate = qMax(supportEstimate, iface->hasSupport(mimeType, codecs));
- else
- allServicesProvideInterface = false;
- }
-
- //don't return PreferredService
- supportEstimate = qMin(supportEstimate, QMultimedia::ProbablySupported);
-
- //Return NotSupported only if no services are available of serviceType
- //or all the services returned NotSupported, otherwise return at least MaybeSupported
- if (!allServicesProvideInterface)
- supportEstimate = qMax(QMultimedia::MaybeSupported, supportEstimate);
-
- return supportEstimate;
- }
-
- QStringList supportedMimeTypes(const QByteArray &serviceType, int flags) const override
- {
- const QList<QObject*> instances = loader()->instances(QLatin1String(serviceType));
-
- QStringList supportedTypes;
-
- for (QObject *obj : instances) {
- QMediaServiceSupportedFormatsInterface *iface =
- qobject_cast<QMediaServiceSupportedFormatsInterface*>(obj);
-
-
- if (flags) {
- QMediaServiceFeaturesInterface *iface =
- qobject_cast<QMediaServiceFeaturesInterface*>(obj);
-
- if (iface) {
- QMediaServiceProviderHint::Features features = iface->supportedFeatures(serviceType);
-
- // If low latency playback was asked for, skip MIME types from services known
- // not to provide low latency playback
- if ((flags & QMediaPlayer::LowLatency) &&
- !(features & QMediaServiceProviderHint::LowLatencyPlayback))
- continue;
-
- //the same for QIODevice based streams support
- if ((flags & QMediaPlayer::StreamPlayback) &&
- !(features & QMediaServiceProviderHint::StreamPlayback))
- continue;
-
- //the same for QAbstractVideoSurface support
- if ((flags & QMediaPlayer::VideoSurface) &&
- !(features & QMediaServiceProviderHint::VideoSurface))
- continue;
- }
- }
-
- if (iface) {
- supportedTypes << iface->supportedMimeTypes();
- }
- }
-
- // Multiple services may support the same MIME type
- supportedTypes.removeDuplicates();
-
- return supportedTypes;
- }
-
- QByteArray defaultDevice(const QByteArray &serviceType) const override
- {
- const auto instances = loader()->instances(QLatin1String(serviceType));
- for (QObject *obj : instances) {
- const QMediaServiceDefaultDeviceInterface *iface =
- qobject_cast<QMediaServiceDefaultDeviceInterface*>(obj);
-
- if (iface) {
- QByteArray name = iface->defaultDevice(serviceType);
- if (!name.isEmpty())
- return name;
- }
- }
-
- // if QMediaServiceDefaultDeviceInterface is not implemented, return the
- // first available device.
- QList<QByteArray> devs = devices(serviceType);
- if (!devs.isEmpty())
- return devs.first();
-
- return QByteArray();
- }
-
- QList<QByteArray> devices(const QByteArray &serviceType) const override
- {
- QList<QByteArray> res;
-
- const auto instances = loader()->instances(QLatin1String(serviceType));
- for (QObject *obj : instances) {
- QMediaServiceSupportedDevicesInterface *iface =
- qobject_cast<QMediaServiceSupportedDevicesInterface*>(obj);
-
- if (iface) {
- res.append(iface->devices(serviceType));
- }
- }
-
- return res;
- }
-
- QString deviceDescription(const QByteArray &serviceType, const QByteArray &device) override
- {
- const auto instances = loader()->instances(QLatin1String(serviceType));
- for (QObject *obj : instances) {
- QMediaServiceSupportedDevicesInterface *iface =
- qobject_cast<QMediaServiceSupportedDevicesInterface*>(obj);
-
- if (iface) {
- if (iface->devices(serviceType).contains(device))
- return iface->deviceDescription(serviceType, device);
- }
- }
-
- return QString();
- }
-
- QCamera::Position cameraPosition(const QByteArray &device) const override
- {
- const QByteArray serviceType(Q_MEDIASERVICE_CAMERA);
- const auto instances = loader()->instances(QString::fromLatin1(serviceType));
- for (QObject *obj : instances) {
- const QMediaServiceSupportedDevicesInterface *deviceIface =
- qobject_cast<QMediaServiceSupportedDevicesInterface*>(obj);
- const QMediaServiceCameraInfoInterface *cameraIface =
- qobject_cast<QMediaServiceCameraInfoInterface*>(obj);
-
- if (cameraIface) {
- if (deviceIface && !deviceIface->devices(serviceType).contains(device))
- continue;
- return cameraIface->cameraPosition(device);
- }
- }
-
- return QCamera::UnspecifiedPosition;
- }
-
- int cameraOrientation(const QByteArray &device) const override
- {
- const QByteArray serviceType(Q_MEDIASERVICE_CAMERA);
- const auto instances = loader()->instances(QString::fromLatin1(serviceType));
- for (QObject *obj : instances) {
- const QMediaServiceSupportedDevicesInterface *deviceIface =
- qobject_cast<QMediaServiceSupportedDevicesInterface*>(obj);
- const QMediaServiceCameraInfoInterface *cameraIface =
- qobject_cast<QMediaServiceCameraInfoInterface*>(obj);
-
- if (cameraIface) {
- if (deviceIface && !deviceIface->devices(serviceType).contains(device))
- continue;
- return cameraIface->cameraOrientation(device);
- }
- }
-
- return 0;
- }
-};
-
-Q_GLOBAL_STATIC(QPluginServiceProvider, pluginProvider);
-
-/*!
- \class QMediaServiceProvider
- \obsolete
- \ingroup multimedia
- \ingroup multimedia_control
- \ingroup multimedia_core
-
- \internal
-
- \brief The QMediaServiceProvider class provides an abstract allocator for media services.
-*/
-
-/*!
- \internal
- \fn QMediaServiceProvider::requestService(const QByteArray &type, const QMediaServiceProviderHint &hint)
-
- Requests an instance of a \a type service which best matches the given \a
- hint.
-
- Returns a pointer to the requested service, or a null pointer if there is
- no suitable service.
-
- The returned service must be released with releaseService when it is
- finished with.
-*/
-
-/*!
- \internal
- \fn QMediaServiceProvider::releaseService(QMediaService *service)
-
- Releases a media \a service requested with requestService().
-*/
-
-/*!
- \internal
- \fn QMediaServiceProvider::supportedFeatures(const QMediaService *service) const
-
- Returns the features supported by a given \a service.
-*/
-QMediaServiceProviderHint::Features QMediaServiceProvider::supportedFeatures(const QMediaService *service) const
-{
- Q_UNUSED(service);
-
- return {};
-}
-
-/*!
- \internal
- Returns how confident a media service provider is that is can provide a \a
- serviceType service that is able to play media of a specific \a mimeType
- that is encoded using the listed \a codecs while adhering to constraints
- identified in \a flags.
-*/
-QMultimedia::SupportEstimate QMediaServiceProvider::hasSupport(const QByteArray &serviceType,
- const QString &mimeType,
- const QStringList& codecs,
- int flags) const
-{
- Q_UNUSED(serviceType);
- Q_UNUSED(mimeType);
- Q_UNUSED(codecs);
- Q_UNUSED(flags);
-
- return QMultimedia::MaybeSupported;
-}
-
-/*!
- \internal
- \fn QStringList QMediaServiceProvider::supportedMimeTypes(const QByteArray &serviceType, int flags) const
-
- Returns a list of MIME types supported by the service provider for the
- specified \a serviceType.
-
- The resultant list is restricted to MIME types which can be supported given
- the constraints in \a flags.
-*/
-QStringList QMediaServiceProvider::supportedMimeTypes(const QByteArray &serviceType, int flags) const
-{
- Q_UNUSED(serviceType);
- Q_UNUSED(flags);
-
- return QStringList();
-}
-
-/*!
- \internal
- \since 5.3
-
- Returns the default device for a \a service type.
-*/
-QByteArray QMediaServiceProvider::defaultDevice(const QByteArray &serviceType) const
-{
- Q_UNUSED(serviceType);
- return QByteArray();
-}
-
-/*!
- \internal
- Returns the list of devices related to \a service type.
-*/
-QList<QByteArray> QMediaServiceProvider::devices(const QByteArray &service) const
-{
- Q_UNUSED(service);
- return QList<QByteArray>();
-}
-
-/*!
- \internal
- Returns the description of \a device related to \a serviceType, suitable for use by
- an application for display.
-*/
-QString QMediaServiceProvider::deviceDescription(const QByteArray &serviceType, const QByteArray &device)
-{
- Q_UNUSED(serviceType);
- Q_UNUSED(device);
- return QString();
-}
-
-/*!
- \internal
- \since 5.3
-
- Returns the physical position of a camera \a device on the system hardware.
-*/
-QCamera::Position QMediaServiceProvider::cameraPosition(const QByteArray &device) const
-{
- Q_UNUSED(device);
- return QCamera::UnspecifiedPosition;
-}
-
-/*!
- \internal
- \since 5.3
-
- Returns the physical orientation of the camera \a device. The value is the angle by which the
- camera image should be rotated anti-clockwise (in steps of 90 degrees) so it shows correctly on
- the display in its natural orientation.
-*/
-int QMediaServiceProvider::cameraOrientation(const QByteArray &device) const
-{
- Q_UNUSED(device);
- return 0;
-}
-
-static QMediaServiceProvider *qt_defaultMediaServiceProvider = nullptr;
-
-/*!
- Sets a media service \a provider as the default.
- It's useful for unit tests to provide mock service.
-
- \internal
-*/
-void QMediaServiceProvider::setDefaultServiceProvider(QMediaServiceProvider *provider)
-{
- qt_defaultMediaServiceProvider = provider;
-}
-
-
-/*!
- \internal
- Returns a default provider of media services.
-*/
-QMediaServiceProvider *QMediaServiceProvider::defaultServiceProvider()
-{
- return qt_defaultMediaServiceProvider != nullptr
- ? qt_defaultMediaServiceProvider
- : static_cast<QMediaServiceProvider *>(pluginProvider());
-}
-
-/*!
- \class QMediaServiceProviderPlugin
- \obsolete
- \inmodule QtMultimedia
- \brief The QMediaServiceProviderPlugin class interface provides an interface for QMediaService
- plug-ins.
-
- A media service provider plug-in may implement one or more of
- QMediaServiceSupportedFormatsInterface,
- QMediaServiceSupportedDevicesInterface, and QMediaServiceFeaturesInterface
- to identify the features it supports.
-*/
-
-/*!
- \fn QMediaServiceProviderPlugin::create(const QString &key)
-
- Constructs a new instance of the QMediaService identified by \a key.
-
- The QMediaService returned must be destroyed with release().
-*/
-
-/*!
- \fn QMediaServiceProviderPlugin::release(QMediaService *service)
-
- Destroys a media \a service constructed with create().
-*/
-
-
-/*!
- \class QMediaServiceSupportedFormatsInterface
- \obsolete
- \inmodule QtMultimedia
- \brief The QMediaServiceSupportedFormatsInterface class interface
- identifies if a media service plug-in supports a media format.
-
- A QMediaServiceProviderPlugin may implement this interface.
-*/
-
-/*!
- \fn QMediaServiceSupportedFormatsInterface::~QMediaServiceSupportedFormatsInterface()
-
- Destroys a media service supported formats interface.
-*/
-
-/*!
- \fn QMediaServiceSupportedFormatsInterface::hasSupport(const QString &mimeType, const QStringList& codecs) const
-
- Returns the level of support a media service plug-in has for a \a mimeType
- and set of \a codecs.
-*/
-
-/*!
- \fn QMediaServiceSupportedFormatsInterface::supportedMimeTypes() const
-
- Returns a list of MIME types supported by the media service plug-in.
-*/
-
-/*!
- \class QMediaServiceSupportedDevicesInterface
- \obsolete
- \inmodule QtMultimedia
- \brief The QMediaServiceSupportedDevicesInterface class interface
- identifies the devices supported by a media service plug-in.
-
- A QMediaServiceProviderPlugin may implement this interface.
-*/
-
-/*!
- \fn QMediaServiceSupportedDevicesInterface::~QMediaServiceSupportedDevicesInterface()
-
- Destroys a media service supported devices interface.
-*/
-
-/*!
- \fn QList<QByteArray> QMediaServiceSupportedDevicesInterface::devices(const QByteArray &service) const
-
- Returns a list of devices available for a \a service type.
-*/
-
-/*!
- \fn QString QMediaServiceSupportedDevicesInterface::deviceDescription(const QByteArray &service, const QByteArray &device)
-
- Returns the description of a \a device available for a \a service type.
-*/
-
-/*!
- \class QMediaServiceDefaultDeviceInterface
- \obsolete
- \inmodule QtMultimedia
- \brief The QMediaServiceDefaultDeviceInterface class interface
- identifies the default device used by a media service plug-in.
-
- A QMediaServiceProviderPlugin may implement this interface.
-
- \since 5.3
-*/
-
-/*!
- \fn QMediaServiceDefaultDeviceInterface::~QMediaServiceDefaultDeviceInterface()
-
- Destroys a media service default device interface.
-*/
-
-/*!
- \fn QByteArray QMediaServiceDefaultDeviceInterface::defaultDevice(const QByteArray &service) const
-
- Returns the default device for a \a service type.
-*/
-
-/*!
- \class QMediaServiceCameraInfoInterface
- \obsolete
- \inmodule QtMultimedia
- \since 5.3
- \brief The QMediaServiceCameraInfoInterface class interface
- provides camera-specific information about devices supported by a camera service plug-in.
-
- A QMediaServiceProviderPlugin may implement this interface, in that case it also needs to
- implement the QMediaServiceSupportedDevicesInterface.
-*/
-
-/*!
- \fn QMediaServiceCameraInfoInterface::~QMediaServiceCameraInfoInterface()
-
- Destroys a media service camera info interface.
-*/
-
-/*!
- \fn QMediaServiceCameraInfoInterface::cameraPosition(const QByteArray &device) const
-
- Returns the physical position of a camera \a device supported by a camera service plug-in.
-*/
-
-/*!
- \fn QMediaServiceCameraInfoInterface::cameraOrientation(const QByteArray &device) const
-
- Returns the physical orientation of a camera \a device supported by a camera service plug-in.
-*/
-
-/*!
- \class QMediaServiceFeaturesInterface
- \obsolete
- \inmodule QtMultimedia
- \brief The QMediaServiceFeaturesInterface class interface identifies
- features supported by a media service plug-in.
-
- A QMediaServiceProviderPlugin may implement this interface.
-*/
-
-/*!
- \fn QMediaServiceFeaturesInterface::~QMediaServiceFeaturesInterface()
-
- Destroys a media service features interface.
-*/
-/*!
- \fn QMediaServiceFeaturesInterface::supportedFeatures(const QByteArray &service) const
-
- Returns a set of features supported by a plug-in \a service.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qmediaserviceprovider_p.cpp"
-#include "moc_qmediaserviceproviderplugin.cpp"
diff --git a/src/multimedia/qmediaserviceprovider_p.h b/src/multimedia/qmediaserviceprovider_p.h
deleted file mode 100644
index 4ca9c9e8f..000000000
--- a/src/multimedia/qmediaserviceprovider_p.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIASERVICEPROVIDER_H
-#define QMEDIASERVICEPROVIDER_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qobject.h>
-#include <QtCore/qshareddata.h>
-#include <qtmultimediaglobal.h>
-#include "qmultimedia.h"
-#include "qmediaserviceproviderplugin.h"
-
-QT_BEGIN_NAMESPACE
-
-
-class QMediaService;
-
-class Q_MULTIMEDIA_EXPORT QMediaServiceProvider : public QObject
-{
- Q_OBJECT
-
-public:
- virtual QMediaService* requestService(const QByteArray &type, const QMediaServiceProviderHint &hint = QMediaServiceProviderHint()) = 0;
- virtual void releaseService(QMediaService *service) = 0;
-
- virtual QMediaServiceProviderHint::Features supportedFeatures(const QMediaService *service) const;
-
- virtual QMultimedia::SupportEstimate hasSupport(const QByteArray &serviceType,
- const QString &mimeType,
- const QStringList& codecs,
- int flags = 0) const;
- virtual QStringList supportedMimeTypes(const QByteArray &serviceType, int flags = 0) const;
-
- virtual QByteArray defaultDevice(const QByteArray &serviceType) const;
- virtual QList<QByteArray> devices(const QByteArray &serviceType) const;
- virtual QString deviceDescription(const QByteArray &serviceType, const QByteArray &device);
-
- virtual QCamera::Position cameraPosition(const QByteArray &device) const;
- virtual int cameraOrientation(const QByteArray &device) const;
-
- static QMediaServiceProvider* defaultServiceProvider();
- static void setDefaultServiceProvider(QMediaServiceProvider *provider);
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QMEDIASERVICEPROVIDER_H
diff --git a/src/multimedia/qmediaserviceproviderplugin.h b/src/multimedia/qmediaserviceproviderplugin.h
deleted file mode 100644
index 3337b2e72..000000000
--- a/src/multimedia/qmediaserviceproviderplugin.h
+++ /dev/null
@@ -1,245 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIASERVICEPROVIDERPLUGIN_H
-#define QMEDIASERVICEPROVIDERPLUGIN_H
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qplugin.h>
-#include <QtMultimedia/qmultimedia.h>
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qcamera.h>
-
-#ifdef Q_MOC_RUN
-# pragma Q_MOC_EXPAND_MACROS
-#endif
-
-QT_BEGIN_NAMESPACE
-
-// Required for QDoc workaround
-class QString;
-
-class QMediaService;
-
-class QMediaServiceProviderHintPrivate;
-class Q_MULTIMEDIA_EXPORT QMediaServiceProviderHint
-{
-public:
- enum Type { Null, ContentType, Device, SupportedFeatures, CameraPosition };
-
- enum Feature {
- LowLatencyPlayback = 0x01,
- RecordingSupport = 0x02,
- StreamPlayback = 0x04,
- VideoSurface = 0x08
- };
- Q_DECLARE_FLAGS(Features, Feature)
-
- QMediaServiceProviderHint();
- QMediaServiceProviderHint(const QString &mimeType, const QStringList& codecs);
- QMediaServiceProviderHint(const QByteArray &device);
- QMediaServiceProviderHint(QCamera::Position position);
- QMediaServiceProviderHint(Features features);
- QMediaServiceProviderHint(const QMediaServiceProviderHint &other);
- ~QMediaServiceProviderHint();
-
- QMediaServiceProviderHint& operator=(const QMediaServiceProviderHint &other);
-
- bool operator == (const QMediaServiceProviderHint &other) const;
- bool operator != (const QMediaServiceProviderHint &other) const;
-
- bool isNull() const;
-
- Type type() const;
-
- QString mimeType() const;
- QStringList codecs() const;
-
- QByteArray device() const;
- QCamera::Position cameraPosition() const;
-
- Features features() const;
-
- //to be extended, if necessary
-
-private:
- QSharedDataPointer<QMediaServiceProviderHintPrivate> d;
-};
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(QMediaServiceProviderHint::Features)
-
-// Required for QDoc workaround
-class QString;
-
-struct Q_MULTIMEDIA_EXPORT QMediaServiceProviderFactoryInterface
-{
- virtual QMediaService* create(QString const& key) = 0;
- virtual void release(QMediaService *service) = 0;
- virtual ~QMediaServiceProviderFactoryInterface();
-};
-
-#define QMediaServiceProviderFactoryInterface_iid \
- "org.qt-project.qt.mediaserviceproviderfactory/5.0"
-Q_DECLARE_INTERFACE(QMediaServiceProviderFactoryInterface, QMediaServiceProviderFactoryInterface_iid)
-
-// Required for QDoc workaround
-class QString;
-
-struct Q_MULTIMEDIA_EXPORT QMediaServiceSupportedFormatsInterface
-{
- virtual ~QMediaServiceSupportedFormatsInterface() {}
- virtual QMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const = 0;
- virtual QStringList supportedMimeTypes() const = 0;
-};
-
-#define QMediaServiceSupportedFormatsInterface_iid \
- "org.qt-project.qt.mediaservicesupportedformats/5.0"
-Q_DECLARE_INTERFACE(QMediaServiceSupportedFormatsInterface, QMediaServiceSupportedFormatsInterface_iid)
-
-// Required for QDoc workaround
-class QString;
-
-struct Q_MULTIMEDIA_EXPORT QMediaServiceSupportedDevicesInterface
-{
- virtual ~QMediaServiceSupportedDevicesInterface() {}
- virtual QList<QByteArray> devices(const QByteArray &service) const = 0;
- virtual QString deviceDescription(const QByteArray &service, const QByteArray &device) = 0;
-};
-
-#define QMediaServiceSupportedDevicesInterface_iid \
- "org.qt-project.qt.mediaservicesupporteddevices/5.0"
-Q_DECLARE_INTERFACE(QMediaServiceSupportedDevicesInterface, QMediaServiceSupportedDevicesInterface_iid)
-
-// This should be part of QMediaServiceSupportedDevicesInterface but it can't in order
-// to preserve binary compatibility with 5.2 and earlier.
-// The whole media service plugin API shouldn't even be public in the first place. It should
-// be made private in Qt 6.0 and QMediaServiceDefaultDeviceInterface should be merged with
-// QMediaServiceSupportedDevicesInterface
-struct Q_MULTIMEDIA_EXPORT QMediaServiceDefaultDeviceInterface
-{
- virtual ~QMediaServiceDefaultDeviceInterface() {}
- virtual QByteArray defaultDevice(const QByteArray &service) const = 0;
-};
-
-#define QMediaServiceDefaultDeviceInterface_iid \
- "org.qt-project.qt.mediaservicedefaultdevice/5.3"
-Q_DECLARE_INTERFACE(QMediaServiceDefaultDeviceInterface, QMediaServiceDefaultDeviceInterface_iid)
-
-struct Q_MULTIMEDIA_EXPORT QMediaServiceCameraInfoInterface
-{
- virtual ~QMediaServiceCameraInfoInterface() {}
- virtual QCamera::Position cameraPosition(const QByteArray &device) const = 0;
- virtual int cameraOrientation(const QByteArray &device) const = 0;
-};
-
-#define QMediaServiceCameraInfoInterface_iid \
- "org.qt-project.qt.mediaservicecamerainfo/5.3"
-Q_DECLARE_INTERFACE(QMediaServiceCameraInfoInterface, QMediaServiceCameraInfoInterface_iid)
-
-// Required for QDoc workaround
-class QString;
-
-struct Q_MULTIMEDIA_EXPORT QMediaServiceFeaturesInterface
-{
- virtual ~QMediaServiceFeaturesInterface() {}
- virtual QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const = 0;
-};
-
-
-#define QMediaServiceFeaturesInterface_iid \
- "org.qt-project.qt.mediaservicefeatures/5.0"
-Q_DECLARE_INTERFACE(QMediaServiceFeaturesInterface, QMediaServiceFeaturesInterface_iid)
-
-// Required for QDoc workaround
-class QString;
-
-class Q_MULTIMEDIA_EXPORT QMediaServiceProviderPlugin : public QObject, public QMediaServiceProviderFactoryInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaServiceProviderFactoryInterface)
-
-public:
- QMediaService* create(const QString& key) override = 0;
- void release(QMediaService *service) override = 0;
-};
-
-/*!
- Service with support for media playback
- Required Controls: QMediaPlayerControl
- Optional Controls: QMediaPlaylistControl, QAudioDeviceControl
- Video Output Controls (used by QWideoWidget and QGraphicsVideoItem):
- Required: QVideoOutputControl
- Optional: QVideoWindowControl, QVideoRendererControl, QVideoWidgetControl
-*/
-#define Q_MEDIASERVICE_MEDIAPLAYER "org.qt-project.qt.mediaplayer"
-
-/*!
- Service with support for recording from audio sources
- Required Controls: QAudioDeviceControl
- Recording Controls (QMediaRecorder):
- Required: QMediaRecorderControl
- Recommended: QAudioEncoderSettingsControl
- Optional: QMediaContainerControl
-*/
-#define Q_MEDIASERVICE_AUDIOSOURCE "org.qt-project.qt.audiosource"
-
-/*!
- Service with support for camera use.
- Required Controls: QCameraControl
- Optional Controls: QCameraExposureControl, QCameraFocusControl, QCameraImageProcessingControl
- Still Capture Controls: QCameraImageCaptureControl
- Video Capture Controls (QMediaRecorder):
- Required: QMediaRecorderControl
- Recommended: QAudioEncoderSettingsControl, QVideoEncoderSettingsControl, QMediaContainerControl
- Viewfinder Video Output Controls (used by QCameraViewfinder and QGraphicsVideoItem):
- Required: QVideoOutputControl
- Optional: QVideoWindowControl, QVideoRendererControl, QVideoWidgetControl
-*/
-#define Q_MEDIASERVICE_CAMERA "org.qt-project.qt.camera"
-
-/*!
- Service with support for decoding audio.
- Required Controls: QAudioDecoderControl
- Optional: that streams control
-*/
-#define Q_MEDIASERVICE_AUDIODECODER "org.qt-project.qt.audiodecode"
-
-QT_END_NAMESPACE
-
-#endif // QMEDIASERVICEPROVIDERPLUGIN_H
diff --git a/src/multimedia/qmediastoragelocation.cpp b/src/multimedia/qmediastoragelocation.cpp
index c77ad5dba..61c4061f4 100644
--- a/src/multimedia/qmediastoragelocation.cpp
+++ b/src/multimedia/qmediastoragelocation.cpp
@@ -1,145 +1,86 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qmediastoragelocation_p.h"
#include <QStandardPaths>
+#include <QUrl>
QT_BEGIN_NAMESPACE
-QMediaStorageLocation::QMediaStorageLocation()
-{
-}
-
-void QMediaStorageLocation::addStorageLocation(MediaType type, const QString &location)
-{
- m_customLocations[type].append(location);
-}
-
-QDir QMediaStorageLocation::defaultLocation(MediaType type) const
+QDir QMediaStorageLocation::defaultDirectory(QStandardPaths::StandardLocation type)
{
QStringList dirCandidates;
- dirCandidates << m_customLocations.value(type);
-
- switch (type) {
- case Movies:
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
- break;
- case Music:
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
- break;
- case Pictures:
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
- default:
- break;
- }
+#if QT_CONFIG(mmrenderer)
+ dirCandidates << QLatin1String("shared/camera");
+#endif
+ dirCandidates << QStandardPaths::writableLocation(type);
+ dirCandidates << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
dirCandidates << QDir::homePath();
dirCandidates << QDir::currentPath();
dirCandidates << QDir::tempPath();
- for (const QString &path : qAsConst(dirCandidates)) {
- if (QFileInfo(path).isWritable())
- return QDir(path);
+ for (const QString &path : std::as_const(dirCandidates)) {
+ QDir dir(path);
+ if (dir.exists() && QFileInfo(path).isWritable())
+ return dir;
}
return QDir();
}
-QString QMediaStorageLocation::generateFileName(const QString &requestedName,
- MediaType type,
- const QString &prefix,
- const QString &extension) const
+static QString generateFileName(const QDir &dir, const QString &prefix, const QString &extension)
{
- if (requestedName.isEmpty())
- return generateFileName(prefix, defaultLocation(type), extension);
+ auto lastMediaIndex = 0;
+ const auto list = dir.entryList({ QStringLiteral("%1*.%2").arg(prefix, extension) });
+ for (const QString &fileName : list) {
+ auto mediaIndex = QStringView{fileName}.mid(prefix.size(), fileName.size() - prefix.size() - extension.size() - 1).toInt();
+ lastMediaIndex = qMax(lastMediaIndex, mediaIndex);
+ }
- QString path = requestedName;
+ const QString name = QStringLiteral("%1%2.%3")
+ .arg(prefix)
+ .arg(lastMediaIndex + 1, 4, 10, QLatin1Char('0'))
+ .arg(extension);
- if (QFileInfo(path).isRelative())
- path = defaultLocation(type).absoluteFilePath(path);
+ return dir.absoluteFilePath(name);
+}
- if (QFileInfo(path).isDir())
- return generateFileName(prefix, QDir(path), extension);
- if (!path.endsWith(extension))
- path.append(QString(QLatin1String(".%1")).arg(extension));
+QString QMediaStorageLocation::generateFileName(const QString &requestedName,
+ QStandardPaths::StandardLocation type,
+ const QString &extension)
+{
+ using namespace Qt::StringLiterals;
- return path;
-}
+ if (QUrl(requestedName).scheme() == "content"_L1)
+ return requestedName;
-QString QMediaStorageLocation::generateFileName(const QString &prefix,
- const QDir &dir,
- const QString &extension) const
-{
- QMutexLocker lock(&m_mutex);
-
- const QString lastMediaKey = dir.absolutePath() + QLatin1Char(' ') + prefix + QLatin1Char(' ') + extension;
- qint64 lastMediaIndex = m_lastUsedIndex.value(lastMediaKey, 0);
-
- if (lastMediaIndex == 0) {
- // first run, find the maximum media number during the fist capture
- const auto list = dir.entryList(QStringList() << QString(QLatin1String("%1*.%2")).arg(prefix).arg(extension));
- for (const QString &fileName : list) {
- const qint64 mediaIndex = QStringView{fileName}.mid(prefix.length(), fileName.size() - prefix.length() - extension.length() - 1).toInt();
- lastMediaIndex = qMax(lastMediaIndex, mediaIndex);
- }
+ auto prefix = "clip_"_L1;
+ switch (type) {
+ case QStandardPaths::PicturesLocation: prefix = "image_"_L1; break;
+ case QStandardPaths::MoviesLocation: prefix = "video_"_L1; break;
+ case QStandardPaths::MusicLocation: prefix = "record_"_L1; break;
+ default: break;
}
- // don't just rely on cached lastMediaIndex value,
- // someone else may create a file after camera started
- while (true) {
- const QString name = QString(QLatin1String("%1%2.%3")).arg(prefix)
- .arg(lastMediaIndex + 1, 8, 10, QLatin1Char('0'))
- .arg(extension);
+ if (requestedName.isEmpty())
+ return generateFileName(defaultDirectory(type), prefix, extension);
- const QString path = dir.absoluteFilePath(name);
- if (!QFileInfo::exists(path)) {
- m_lastUsedIndex[lastMediaKey] = lastMediaIndex + 1;
- return path;
- }
+ QString path = requestedName;
- lastMediaIndex++;
- }
+ if (QFileInfo(path).isRelative() && QUrl(path).isRelative())
+ path = defaultDirectory(type).absoluteFilePath(path);
+
+ if (QFileInfo(path).isDir())
+ return generateFileName(QDir(path), prefix, extension);
- return QString();
+ if (!path.endsWith(extension))
+ path.append(QStringLiteral(".%1").arg(extension));
+
+ return path;
}
QT_END_NAMESPACE
diff --git a/src/multimedia/qmediastoragelocation_p.h b/src/multimedia/qmediastoragelocation_p.h
index 13399b54d..39c4b7162 100644
--- a/src/multimedia/qmediastoragelocation_p.h
+++ b/src/multimedia/qmediastoragelocation_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMEDIASTORAGELOCATION_H
#define QMEDIASTORAGELOCATION_H
@@ -52,36 +16,16 @@
//
#include <qtmultimediaglobal.h>
+#include <QStandardPaths>
#include <QDir>
-#include <QMap>
-#include <QHash>
-#include <QMutex>
+#include <private/qglobal_p.h>
QT_BEGIN_NAMESPACE
-class Q_MULTIMEDIA_EXPORT QMediaStorageLocation
+namespace QMediaStorageLocation
{
-public:
- enum MediaType {
- Movies,
- Music,
- Pictures,
- Sounds
- };
-
- QMediaStorageLocation();
-
- void addStorageLocation(MediaType type, const QString &location);
-
- QDir defaultLocation(MediaType type) const;
-
- QString generateFileName(const QString &requestedName, MediaType type, const QString &prefix, const QString &extension) const;
- QString generateFileName(const QString &prefix, const QDir &dir, const QString &extension) const;
-
-private:
- mutable QMutex m_mutex;
- mutable QHash<QString, qint64> m_lastUsedIndex;
- QMap<MediaType, QStringList> m_customLocations;
+ Q_MULTIMEDIA_EXPORT QDir defaultDirectory(QStandardPaths::StandardLocation type);
+ Q_MULTIMEDIA_EXPORT QString generateFileName(const QString &requestedName, QStandardPaths::StandardLocation type, const QString &extension);
};
QT_END_NAMESPACE
diff --git a/src/multimedia/qmediatimerange.cpp b/src/multimedia/qmediatimerange.cpp
index 913790a0e..2af9cefc6 100644
--- a/src/multimedia/qmediatimerange.cpp
+++ b/src/multimedia/qmediatimerange.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtCore/qdebug.h>
@@ -44,8 +8,9 @@
QT_BEGIN_NAMESPACE
/*!
- \class QMediaTimeInterval
- \brief The QMediaTimeInterval class represents a time interval with integer precision.
+ \class QMediaTimeRange::Interval
+ \brief The QMediaTimeRange::Interval class represents a time interval with
+ integer precision.
\inmodule QtMultimedia
\ingroup multimedia
@@ -71,169 +36,101 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QMediaTimeInterval::QMediaTimeInterval()
-
- Constructs an empty interval.
-*/
-QMediaTimeInterval::QMediaTimeInterval()
- : s(0)
- , e(0)
-{
-
-}
-
-/*!
- \fn QMediaTimeInterval::QMediaTimeInterval(qint64 start, qint64 end)
+ \fn QMediaTimeRange::Interval::Interval(qint64 start, qint64 end)
Constructs an interval with the specified \a start and \a end times.
*/
-QMediaTimeInterval::QMediaTimeInterval(qint64 start, qint64 end)
- : s(start)
- , e(end)
-{
-
-}
/*!
- \fn QMediaTimeInterval::start() const
+ \fn QMediaTimeRange::Interval::start() const
Returns the start time of the interval.
\sa end()
*/
-qint64 QMediaTimeInterval::start() const
-{
- return s;
-}
/*!
- \fn QMediaTimeInterval::end() const
+ \fn QMediaTimeRange::Interval::end() const
Returns the end time of the interval.
\sa start()
*/
-qint64 QMediaTimeInterval::end() const
-{
- return e;
-}
/*!
- \fn QMediaTimeInterval::contains(qint64 time) const
+ \fn QMediaTimeRange::Interval::contains(qint64 time) const
Returns true if the time interval contains the specified \a time.
That is, start() <= time <= end().
*/
-bool QMediaTimeInterval::contains(qint64 time) const
-{
- return isNormal() ? (s <= time && time <= e)
- : (e <= time && time <= s);
-}
/*!
- \fn QMediaTimeInterval::isNormal() const
+ \fn QMediaTimeRange::Interval::isNormal() const
Returns true if this time interval is normal.
A normal time interval has start() <= end().
\sa normalized()
*/
-bool QMediaTimeInterval::isNormal() const
-{
- return s <= e;
-}
/*!
- \fn QMediaTimeInterval::normalized() const
+ \fn QMediaTimeRange::Interval::normalized() const
Returns a normalized version of this interval.
If the start() time of the interval is greater than the end() time,
then the returned interval has the start and end times swapped.
*/
-QMediaTimeInterval QMediaTimeInterval::normalized() const
-{
- if(s > e)
- return QMediaTimeInterval(e, s);
-
- return *this;
-}
/*!
- \fn QMediaTimeInterval::translated(qint64 offset) const
+ \fn QMediaTimeRange::Interval::translated(qint64 offset) const
Returns a copy of this time interval, translated by a value of \a offset.
An interval can be moved forward through time with a positive offset, or backward
through time with a negative offset.
*/
-QMediaTimeInterval QMediaTimeInterval::translated(qint64 offset) const
-{
- return QMediaTimeInterval(s + offset, e + offset);
-}
/*!
- \relates QMediaTimeRange
+ \fn bool QMediaTimeRange::Interval::operator==(QMediaTimeRange::Interval lhs, QMediaTimeRange::Interval rhs)
- Returns true if \a a is exactly equal to \a b.
+ Returns true if \a lhs is exactly equal to \a rhs.
*/
-bool operator==(const QMediaTimeInterval &a, const QMediaTimeInterval &b)
-{
- return a.start() == b.start() && a.end() == b.end();
-}
/*!
- \relates QMediaTimeRange
+ \fn bool QMediaTimeRange::Interval::operator!=(QMediaTimeRange::Interval lhs, QMediaTimeRange::Interval rhs)
- Returns true if \a a is not exactly equal to \a b.
+ Returns true if \a lhs is not exactly equal to \a rhs.
*/
-bool operator!=(const QMediaTimeInterval &a, const QMediaTimeInterval &b)
-{
- return a.start() != b.start() || a.end() != b.end();
-}
class QMediaTimeRangePrivate : public QSharedData
{
public:
+ QMediaTimeRangePrivate() = default;
+ QMediaTimeRangePrivate(const QMediaTimeRange::Interval &interval);
- QMediaTimeRangePrivate();
- QMediaTimeRangePrivate(const QMediaTimeRangePrivate &other);
- QMediaTimeRangePrivate(const QMediaTimeInterval &interval);
-
- QList<QMediaTimeInterval> intervals;
+ QList<QMediaTimeRange::Interval> intervals;
- void addInterval(const QMediaTimeInterval &interval);
- void removeInterval(const QMediaTimeInterval &interval);
+ void addInterval(const QMediaTimeRange::Interval &interval);
+ void removeInterval(const QMediaTimeRange::Interval &interval);
};
-QMediaTimeRangePrivate::QMediaTimeRangePrivate()
- : QSharedData()
-{
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QMediaTimeRangePrivate);
-}
-
-QMediaTimeRangePrivate::QMediaTimeRangePrivate(const QMediaTimeRangePrivate &other)
- : QSharedData()
- , intervals(other.intervals)
-{
-
-}
-
-QMediaTimeRangePrivate::QMediaTimeRangePrivate(const QMediaTimeInterval &interval)
- : QSharedData()
+QMediaTimeRangePrivate::QMediaTimeRangePrivate(const QMediaTimeRange::Interval &interval)
{
- if(interval.isNormal())
+ if (interval.isNormal())
intervals << interval;
}
-void QMediaTimeRangePrivate::addInterval(const QMediaTimeInterval &interval)
+void QMediaTimeRangePrivate::addInterval(const QMediaTimeRange::Interval &interval)
{
// Handle normalized intervals only
- if(!interval.isNormal())
+ if (!interval.isNormal())
return;
// Find a place to insert the interval
int i;
- for (i = 0; i < intervals.count(); i++) {
+ for (i = 0; i < intervals.size(); i++) {
// Insert before this element
if(interval.s < intervals[i].s) {
intervals.insert(i, interval);
@@ -242,29 +139,29 @@ void QMediaTimeRangePrivate::addInterval(const QMediaTimeInterval &interval)
}
// Interval needs to be added to the end of the list
- if (i == intervals.count())
+ if (i == intervals.size())
intervals.append(interval);
// Do we need to correct the element before us?
- if(i > 0 && intervals[i - 1].e >= interval.s - 1)
+ if (i > 0 && intervals[i - 1].e >= interval.s - 1)
i--;
// Merge trailing ranges
- while (i < intervals.count() - 1
+ while (i < intervals.size() - 1
&& intervals[i].e >= intervals[i + 1].s - 1) {
intervals[i].e = qMax(intervals[i].e, intervals[i + 1].e);
intervals.removeAt(i + 1);
}
}
-void QMediaTimeRangePrivate::removeInterval(const QMediaTimeInterval &interval)
+void QMediaTimeRangePrivate::removeInterval(const QMediaTimeRange::Interval &interval)
{
// Handle normalized intervals only
- if(!interval.isNormal())
+ if (!interval.isNormal())
return;
- for (int i = 0; i < intervals.count(); i++) {
- QMediaTimeInterval r = intervals[i];
+ for (int i = 0; i < intervals.size(); i++) {
+ const QMediaTimeRange::Interval r = intervals.at(i);
if (r.e < interval.s) {
// Before the removal interval
@@ -275,7 +172,7 @@ void QMediaTimeRangePrivate::removeInterval(const QMediaTimeInterval &interval)
} else if (r.s < interval.s && interval.e < r.e) {
// Split case - a single range has a chunk removed
intervals[i].e = interval.s -1;
- addInterval(QMediaTimeInterval(interval.e + 1, r.e));
+ addInterval(QMediaTimeRange::Interval(interval.e + 1, r.e));
break;
} else if (r.s < interval.s) {
// Trimming Tail Case
@@ -311,14 +208,12 @@ void QMediaTimeRangePrivate::removeInterval(const QMediaTimeInterval &interval)
within the range may be expanded, trimmed, deleted, merged or split to ensure
that all intervals within the time range remain distinct and disjoint. As a
consequence, all intervals added or removed from a time range must be
- \l{QMediaTimeInterval::isNormal()}{normal}.
+ \l{QMediaTimeRange::Interval::isNormal()}{normal}.
- \sa QMediaTimeInterval
+ \sa QMediaTimeRange::Interval
*/
/*!
- \fn QMediaTimeRange::QMediaTimeRange()
-
Constructs an empty time range.
*/
QMediaTimeRange::QMediaTimeRange()
@@ -328,80 +223,76 @@ QMediaTimeRange::QMediaTimeRange()
}
/*!
- \fn QMediaTimeRange::QMediaTimeRange(qint64 start, qint64 end)
-
Constructs a time range that contains an initial interval from
\a start to \a end inclusive.
- If the interval is not \l{QMediaTimeInterval::isNormal()}{normal},
+ If the interval is not \l{QMediaTimeRange::Interval::isNormal()}{normal},
the resulting time range will be empty.
\sa addInterval()
*/
QMediaTimeRange::QMediaTimeRange(qint64 start, qint64 end)
- : d(new QMediaTimeRangePrivate(QMediaTimeInterval(start, end)))
+ : QMediaTimeRange(Interval(start, end))
{
-
}
/*!
- \fn QMediaTimeRange::QMediaTimeRange(const QMediaTimeInterval &interval)
-
Constructs a time range that contains an initial interval, \a interval.
- If \a interval is not \l{QMediaTimeInterval::isNormal()}{normal},
+ If \a interval is not \l{QMediaTimeRange::Interval::isNormal()}{normal},
the resulting time range will be empty.
\sa addInterval()
*/
-QMediaTimeRange::QMediaTimeRange(const QMediaTimeInterval &interval)
+QMediaTimeRange::QMediaTimeRange(const QMediaTimeRange::Interval &interval)
: d(new QMediaTimeRangePrivate(interval))
{
-
}
/*!
- \fn QMediaTimeRange::QMediaTimeRange(const QMediaTimeRange &range)
-
Constructs a time range by copying another time \a range.
*/
-QMediaTimeRange::QMediaTimeRange(const QMediaTimeRange &range)
- : d(range.d)
-{
+QMediaTimeRange::QMediaTimeRange(const QMediaTimeRange &range) noexcept = default;
-}
+/*! \fn QMediaTimeRange::QMediaTimeRange(QMediaTimeRange &&other)
+
+ Constructs a time range by moving from \a other.
+*/
+
+/*!
+ \fn void QMediaTimeRange::swap(QMediaTimeRange &other) noexcept
+
+ Swaps the current instance with the \a other.
+*/
/*!
\fn QMediaTimeRange::~QMediaTimeRange()
Destructor.
*/
-QMediaTimeRange::~QMediaTimeRange()
-{
-
-}
+QMediaTimeRange::~QMediaTimeRange() = default;
/*!
Takes a copy of the \a other time range and returns itself.
*/
-QMediaTimeRange &QMediaTimeRange::operator=(const QMediaTimeRange &other)
-{
- d = other.d;
- return *this;
-}
+QMediaTimeRange &QMediaTimeRange::operator=(const QMediaTimeRange &other) noexcept = default;
+
+/*!
+ \fn QMediaTimeRange &QMediaTimeRange::operator=(QMediaTimeRange &&other)
+
+ Moves \a other into this time range.
+*/
/*!
Sets the time range to a single continuous interval, \a interval.
*/
-QMediaTimeRange &QMediaTimeRange::operator=(const QMediaTimeInterval &interval)
+QMediaTimeRange &QMediaTimeRange::operator=(const QMediaTimeRange::Interval &interval)
{
d = new QMediaTimeRangePrivate(interval);
return *this;
}
/*!
- \fn QMediaTimeRange::earliestTime() const
-
Returns the earliest time within the time range.
For empty time ranges, this value is equal to zero.
@@ -411,14 +302,12 @@ QMediaTimeRange &QMediaTimeRange::operator=(const QMediaTimeInterval &interval)
qint64 QMediaTimeRange::earliestTime() const
{
if (!d->intervals.isEmpty())
- return d->intervals[0].s;
+ return d->intervals[0].start();
return 0;
}
/*!
- \fn QMediaTimeRange::latestTime() const
-
Returns the latest time within the time range.
For empty time ranges, this value is equal to zero.
@@ -428,13 +317,12 @@ qint64 QMediaTimeRange::earliestTime() const
qint64 QMediaTimeRange::latestTime() const
{
if (!d->intervals.isEmpty())
- return d->intervals[d->intervals.count() - 1].e;
+ return d->intervals[d->intervals.size() - 1].end();
return 0;
}
/*!
- \fn QMediaTimeRange::addInterval(qint64 start, qint64 end)
\overload
Adds the interval specified by \a start and \a end
@@ -444,15 +332,14 @@ qint64 QMediaTimeRange::latestTime() const
*/
void QMediaTimeRange::addInterval(qint64 start, qint64 end)
{
- d->addInterval(QMediaTimeInterval(start, end));
+ detach();
+ d->addInterval(Interval(start, end));
}
/*!
- \fn QMediaTimeRange::addInterval(const QMediaTimeInterval &interval)
-
Adds the specified \a interval to the time range.
- Adding intervals which are not \l{QMediaTimeInterval::isNormal()}{normal}
+ Adding intervals which are not \l{QMediaTimeRange::Interval::isNormal()}{normal}
is invalid, and will be ignored.
If the specified interval is adjacent to, or overlaps existing
@@ -462,8 +349,9 @@ void QMediaTimeRange::addInterval(qint64 start, qint64 end)
\sa removeInterval()
*/
-void QMediaTimeRange::addInterval(const QMediaTimeInterval &interval)
+void QMediaTimeRange::addInterval(const QMediaTimeRange::Interval &interval)
{
+ detach();
d->addInterval(interval);
}
@@ -474,14 +362,14 @@ void QMediaTimeRange::addInterval(const QMediaTimeInterval &interval)
*/
void QMediaTimeRange::addTimeRange(const QMediaTimeRange &range)
{
+ detach();
const auto intervals = range.intervals();
- for (const QMediaTimeInterval &i : intervals) {
+ for (const Interval &i : intervals) {
d->addInterval(i);
}
}
/*!
- \fn QMediaTimeRange::removeInterval(qint64 start, qint64 end)
\overload
Removes the interval specified by \a start and \a end
@@ -491,15 +379,16 @@ void QMediaTimeRange::addTimeRange(const QMediaTimeRange &range)
*/
void QMediaTimeRange::removeInterval(qint64 start, qint64 end)
{
- d->removeInterval(QMediaTimeInterval(start, end));
+ detach();
+ d->removeInterval(Interval(start, end));
}
/*!
- \fn QMediaTimeRange::removeInterval(const QMediaTimeInterval &interval)
+ \fn QMediaTimeRange::removeInterval(const QMediaTimeRange::Interval &interval)
Removes the specified \a interval from the time range.
- Removing intervals which are not \l{QMediaTimeInterval::isNormal()}{normal}
+ Removing intervals which are not \l{QMediaTimeRange::Interval::isNormal()}{normal}
is invalid, and will be ignored.
Intervals within the time range will be trimmed, split or deleted
@@ -510,8 +399,9 @@ void QMediaTimeRange::removeInterval(qint64 start, qint64 end)
\sa addInterval()
*/
-void QMediaTimeRange::removeInterval(const QMediaTimeInterval &interval)
+void QMediaTimeRange::removeInterval(const QMediaTimeRange::Interval &interval)
{
+ detach();
d->removeInterval(interval);
}
@@ -522,8 +412,9 @@ void QMediaTimeRange::removeInterval(const QMediaTimeInterval &interval)
*/
void QMediaTimeRange::removeTimeRange(const QMediaTimeRange &range)
{
+ detach();
const auto intervals = range.intervals();
- for (const QMediaTimeInterval &i : intervals) {
+ for (const Interval &i : intervals) {
d->removeInterval(i);
}
}
@@ -540,7 +431,7 @@ QMediaTimeRange& QMediaTimeRange::operator+=(const QMediaTimeRange &other)
/*!
Adds the specified \a interval to the time range and returns the result.
*/
-QMediaTimeRange& QMediaTimeRange::operator+=(const QMediaTimeInterval &interval)
+QMediaTimeRange& QMediaTimeRange::operator+=(const QMediaTimeRange::Interval &interval)
{
addInterval(interval);
return *this;
@@ -558,7 +449,7 @@ QMediaTimeRange& QMediaTimeRange::operator-=(const QMediaTimeRange &other)
/*!
Removes the specified \a interval from the time range and returns the result.
*/
-QMediaTimeRange& QMediaTimeRange::operator-=(const QMediaTimeInterval &interval)
+QMediaTimeRange& QMediaTimeRange::operator-=(const QMediaTimeRange::Interval &interval)
{
removeInterval(interval);
return *this;
@@ -573,15 +464,24 @@ QMediaTimeRange& QMediaTimeRange::operator-=(const QMediaTimeInterval &interval)
*/
void QMediaTimeRange::clear()
{
+ detach();
d->intervals.clear();
}
/*!
+ \internal
+*/
+void QMediaTimeRange::detach()
+{
+ d.detach();
+}
+
+/*!
\fn QMediaTimeRange::intervals() const
Returns the list of intervals covered by this time range.
*/
-QList<QMediaTimeInterval> QMediaTimeRange::intervals() const
+QList<QMediaTimeRange::Interval> QMediaTimeRange::intervals() const
{
return d->intervals;
}
@@ -606,7 +506,7 @@ bool QMediaTimeRange::isEmpty() const
*/
bool QMediaTimeRange::isContinuous() const
{
- return (d->intervals.count() <= 1);
+ return (d->intervals.size() <= 1);
}
/*!
@@ -616,11 +516,11 @@ bool QMediaTimeRange::isContinuous() const
*/
bool QMediaTimeRange::contains(qint64 time) const
{
- for (int i = 0; i < d->intervals.count(); i++) {
+ for (int i = 0; i < d->intervals.size(); i++) {
if (d->intervals[i].contains(time))
return true;
- if (time < d->intervals[i].s)
+ if (time < d->intervals[i].start())
break;
}
@@ -628,53 +528,47 @@ bool QMediaTimeRange::contains(qint64 time) const
}
/*!
- \relates QMediaTimeRange
+ \fn bool QMediaTimeRange::operator==(const QMediaTimeRange &lhs, const QMediaTimeRange &rhs)
- Returns true if all intervals in \a a are present in \a b.
+ Returns true if all intervals in \a lhs are present in \a rhs.
*/
-bool operator==(const QMediaTimeRange &a, const QMediaTimeRange &b)
-{
- return a.intervals() == b.intervals();
-}
/*!
- \relates QMediaTimeRange
+ \fn bool QMediaTimeRange::operator!=(const QMediaTimeRange &lhs, const QMediaTimeRange &rhs)
- Returns true if one or more intervals in \a a are not present in \a b.
+ Returns true if one or more intervals in \a lhs are not present in \a rhs.
*/
-bool operator!=(const QMediaTimeRange &a, const QMediaTimeRange &b)
-{
- return !(a == b);
-}
/*!
+ \fn QMediaTimeRange operator+(const QMediaTimeRange &r1, const QMediaTimeRange &r2)
\relates QMediaTimeRange
Returns a time range containing the union between \a r1 and \a r2.
*/
-QMediaTimeRange operator+(const QMediaTimeRange &r1, const QMediaTimeRange &r2)
-{
- return (QMediaTimeRange(r1) += r2);
-}
/*!
+ \fn QMediaTimeRange operator-(const QMediaTimeRange &r1, const QMediaTimeRange &r2)
\relates QMediaTimeRange
Returns a time range containing \a r2 subtracted from \a r1.
*/
-QMediaTimeRange operator-(const QMediaTimeRange &r1, const QMediaTimeRange &r2)
+
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug dbg, const QMediaTimeRange::Interval &interval)
{
- return (QMediaTimeRange(r1) -= r2);
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ dbg << "QMediaTimeRange::Interval( " << interval.start() << ", " << interval.end() << " )";
+ return dbg;
}
-#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QMediaTimeRange &range)
{
QDebugStateSaver saver(dbg);
dbg.nospace();
dbg << "QMediaTimeRange( ";
const auto intervals = range.intervals();
- for (const QMediaTimeInterval &interval : intervals)
+ for (const auto &interval : intervals)
dbg << '(' << interval.start() << ", " << interval.end() << ") ";
dbg.space();
dbg << ')';
@@ -683,4 +577,3 @@ QDebug operator<<(QDebug dbg, const QMediaTimeRange &range)
#endif
QT_END_NAMESPACE
-
diff --git a/src/multimedia/qmediatimerange.h b/src/multimedia/qmediatimerange.h
index 97524f24a..7245a845a 100644
--- a/src/multimedia/qmediatimerange.h
+++ b/src/multimedia/qmediatimerange.h
@@ -1,131 +1,129 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMEDIATIMERANGE_H
#define QMEDIATIMERANGE_H
#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
#include <QtCore/qshareddata.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qmetatype.h>
QT_BEGIN_NAMESPACE
class QMediaTimeRangePrivate;
-class Q_MULTIMEDIA_EXPORT QMediaTimeInterval
-{
-public:
- QMediaTimeInterval();
- QMediaTimeInterval(qint64 start, qint64 end);
-
- qint64 start() const;
- qint64 end() const;
-
- bool contains(qint64 time) const;
-
- bool isNormal() const;
- QMediaTimeInterval normalized() const;
- QMediaTimeInterval translated(qint64 offset) const;
-
-private:
- friend class QMediaTimeRangePrivate;
- friend class QMediaTimeRange;
-
- qint64 s;
- qint64 e;
-};
-
-Q_MULTIMEDIA_EXPORT bool operator==(const QMediaTimeInterval&, const QMediaTimeInterval&);
-Q_MULTIMEDIA_EXPORT bool operator!=(const QMediaTimeInterval&, const QMediaTimeInterval&);
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QMediaTimeRangePrivate, Q_MULTIMEDIA_EXPORT)
class Q_MULTIMEDIA_EXPORT QMediaTimeRange
{
public:
+ struct Interval
+ {
+ constexpr Interval() noexcept = default;
+ explicit constexpr Interval(qint64 start, qint64 end) noexcept
+ : s(start), e(end)
+ {}
+
+ constexpr qint64 start() const noexcept { return s; }
+ constexpr qint64 end() const noexcept { return e; }
+
+ constexpr bool contains(qint64 time) const noexcept
+ {
+ return isNormal() ? (s <= time && time <= e)
+ : (e <= time && time <= s);
+ }
+
+ constexpr bool isNormal() const noexcept { return s <= e; }
+ constexpr Interval normalized() const
+ {
+ return s > e ? Interval(e, s) : *this;
+ }
+ constexpr Interval translated(qint64 offset) const
+ {
+ return Interval(s + offset, e + offset);
+ }
+
+ friend constexpr bool operator==(Interval lhs, Interval rhs) noexcept
+ {
+ return lhs.start() == rhs.start() && lhs.end() == rhs.end();
+ }
+ friend constexpr bool operator!=(Interval lhs, Interval rhs) noexcept
+ {
+ return lhs.start() != rhs.start() || lhs.end() != rhs.end();
+ }
+
+ private:
+ friend class QMediaTimeRangePrivate;
+ qint64 s = 0;
+ qint64 e = 0;
+ };
QMediaTimeRange();
- QMediaTimeRange(qint64 start, qint64 end);
- QMediaTimeRange(const QMediaTimeInterval&);
- QMediaTimeRange(const QMediaTimeRange &range);
+ explicit QMediaTimeRange(qint64 start, qint64 end);
+ QMediaTimeRange(const Interval&);
+ QMediaTimeRange(const QMediaTimeRange &range) noexcept;
~QMediaTimeRange();
- QMediaTimeRange &operator=(const QMediaTimeRange&);
- QMediaTimeRange &operator=(const QMediaTimeInterval&);
+ QMediaTimeRange &operator=(const QMediaTimeRange&) noexcept;
+
+ QMediaTimeRange(QMediaTimeRange &&other) noexcept = default;
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QMediaTimeRange)
+ void swap(QMediaTimeRange &other) noexcept
+ { d.swap(other.d); }
+ void detach();
+
+ QMediaTimeRange &operator=(const Interval&);
qint64 earliestTime() const;
qint64 latestTime() const;
- QList<QMediaTimeInterval> intervals() const;
+ QList<QMediaTimeRange::Interval> intervals() const;
bool isEmpty() const;
bool isContinuous() const;
bool contains(qint64 time) const;
void addInterval(qint64 start, qint64 end);
- void addInterval(const QMediaTimeInterval &interval);
+ void addInterval(const Interval &interval);
void addTimeRange(const QMediaTimeRange&);
void removeInterval(qint64 start, qint64 end);
- void removeInterval(const QMediaTimeInterval &interval);
+ void removeInterval(const Interval &interval);
void removeTimeRange(const QMediaTimeRange&);
QMediaTimeRange& operator+=(const QMediaTimeRange&);
- QMediaTimeRange& operator+=(const QMediaTimeInterval&);
+ QMediaTimeRange& operator+=(const Interval&);
QMediaTimeRange& operator-=(const QMediaTimeRange&);
- QMediaTimeRange& operator-=(const QMediaTimeInterval&);
+ QMediaTimeRange& operator-=(const Interval&);
void clear();
+ friend inline bool operator==(const QMediaTimeRange &lhs, const QMediaTimeRange &rhs)
+ { return lhs.intervals() == rhs.intervals(); }
+ friend inline bool operator!=(const QMediaTimeRange &lhs, const QMediaTimeRange &rhs)
+ { return lhs.intervals() != rhs.intervals(); }
+
private:
- QSharedDataPointer<QMediaTimeRangePrivate> d;
+ QExplicitlySharedDataPointer<QMediaTimeRangePrivate> d;
};
-Q_MULTIMEDIA_EXPORT bool operator==(const QMediaTimeRange&, const QMediaTimeRange&);
-Q_MULTIMEDIA_EXPORT bool operator!=(const QMediaTimeRange&, const QMediaTimeRange&);
-Q_MULTIMEDIA_EXPORT QMediaTimeRange operator+(const QMediaTimeRange&, const QMediaTimeRange&);
-Q_MULTIMEDIA_EXPORT QMediaTimeRange operator-(const QMediaTimeRange&, const QMediaTimeRange&);
-
#ifndef QT_NO_DEBUG_STREAM
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QMediaTimeRange::Interval &);
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QMediaTimeRange &);
#endif
+inline QMediaTimeRange operator+(const QMediaTimeRange &r1, const QMediaTimeRange &r2)
+{ return (QMediaTimeRange(r1) += r2); }
+inline QMediaTimeRange operator-(const QMediaTimeRange &r1, const QMediaTimeRange &r2)
+{ return (QMediaTimeRange(r1) -= r2); }
+
+Q_DECLARE_SHARED(QMediaTimeRange)
+
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QMediaTimeRange)
+Q_DECLARE_METATYPE(QMediaTimeRange::Interval)
#endif // QMEDIATIMERANGE_H
diff --git a/src/multimedia/qmultimedia.cpp b/src/multimedia/qmultimedia.cpp
deleted file mode 100644
index 34d7cbe5a..000000000
--- a/src/multimedia/qmultimedia.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmultimedia.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \namespace QMultimedia
- \ingroup multimedia-namespaces
- \ingroup multimedia
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_core
-
- \brief The QMultimedia namespace contains miscellaneous identifiers used throughout the Qt Multimedia library.
-
-*/
-
-static void qRegisterMultimediaMetaTypes()
-{
- qRegisterMetaType<QMultimedia::AvailabilityStatus>();
- qRegisterMetaType<QMultimedia::SupportEstimate>();
- qRegisterMetaType<QMultimedia::EncodingMode>();
- qRegisterMetaType<QMultimedia::EncodingQuality>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterMultimediaMetaTypes)
-
-
-/*!
- \enum QMultimedia::SupportEstimate
-
- Enumerates the levels of support a media service provider may have for a feature.
-
- \value NotSupported The feature is not supported.
- \value MaybeSupported The feature may be supported.
- \value ProbablySupported The feature is probably supported.
- \value PreferredService The service is the preferred provider of a service.
-*/
-
-/*!
- \enum QMultimedia::EncodingQuality
-
- Enumerates quality encoding levels.
-
- \value VeryLowQuality
- \value LowQuality
- \value NormalQuality
- \value HighQuality
- \value VeryHighQuality
-*/
-
-/*!
- \enum QMultimedia::EncodingMode
-
- Enumerates encoding modes.
-
- \value ConstantQualityEncoding Encoding will aim to have a constant quality, adjusting bitrate to fit.
- \value ConstantBitRateEncoding Encoding will use a constant bit rate, adjust quality to fit.
- \value AverageBitRateEncoding Encoding will try to keep an average bitrate setting, but will use
- more or less as needed.
- \value TwoPassEncoding The media will first be processed to determine the characteristics,
- and then processed a second time allocating more bits to the areas
- that need it.
-*/
-
-/*!
- \enum QMultimedia::AvailabilityStatus
-
- Enumerates Service status errors.
-
- \value Available The service is operating correctly.
- \value ServiceMissing There is no service available to provide the requested functionality.
- \value ResourceError The service could not allocate resources required to function correctly.
- \value Busy The service must wait for access to necessary resources.
-*/
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/qmultimedia.h b/src/multimedia/qmultimedia.h
deleted file mode 100644
index a3dbc5e3e..000000000
--- a/src/multimedia/qmultimedia.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMULTIMEDIA_H
-#define QMULTIMEDIA_H
-
-#include <QtCore/qpair.h>
-#include <QtCore/qmetatype.h>
-#include <QtCore/qstring.h>
-
-#include <QtMultimedia/qtmultimediaglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace QMultimedia
-{
- enum SupportEstimate
- {
- NotSupported,
- MaybeSupported,
- ProbablySupported,
- PreferredService
- };
-
- enum EncodingQuality
- {
- VeryLowQuality,
- LowQuality,
- NormalQuality,
- HighQuality,
- VeryHighQuality
- };
-
- enum EncodingMode
- {
- ConstantQualityEncoding,
- ConstantBitRateEncoding,
- AverageBitRateEncoding,
- TwoPassEncoding
- };
-
- enum AvailabilityStatus
- {
- Available,
- ServiceMissing,
- Busy,
- ResourceError
- };
-
-}
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QMultimedia::AvailabilityStatus)
-Q_DECLARE_METATYPE(QMultimedia::SupportEstimate)
-Q_DECLARE_METATYPE(QMultimedia::EncodingMode)
-Q_DECLARE_METATYPE(QMultimedia::EncodingQuality)
-
-
-#endif
diff --git a/src/multimedia/qmultimediautils.cpp b/src/multimedia/qmultimediautils.cpp
index 54653751b..9740b6d60 100644
--- a/src/multimedia/qmultimediautils.cpp
+++ b/src/multimedia/qmultimediautils.cpp
@@ -1,50 +1,20 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qmultimediautils_p.h"
+#include "qvideoframe.h"
+#include "qvideoframeformat.h"
+
+#include <QtCore/qdir.h>
QT_BEGIN_NAMESPACE
-void qt_real_to_fraction(qreal value, int *numerator, int *denominator)
+Fraction qRealToFraction(qreal value)
{
- if (!numerator || !denominator)
- return;
+ int integral = int(floor(value));
+ value -= qreal(integral);
+ if (value == 0.)
+ return {integral, 1};
const int dMax = 1000;
int n1 = 0, d1 = 1, n2 = 1, d2 = 1;
@@ -53,19 +23,7 @@ void qt_real_to_fraction(qreal value, int *numerator, int *denominator)
mid = qreal(n1 + n2) / (d1 + d2);
if (qAbs(value - mid) < 0.000001) {
- if (d1 + d2 <= dMax) {
- *numerator = n1 + n2;
- *denominator = d1 + d2;
- return;
- } else if (d2 > d1) {
- *numerator = n2;
- *denominator = d2;
- return;
- } else {
- *numerator = n1;
- *denominator = d1;
- return;
- }
+ break;
} else if (value > mid) {
n1 = n1 + n2;
d1 = d1 + d2;
@@ -75,13 +33,68 @@ void qt_real_to_fraction(qreal value, int *numerator, int *denominator)
}
}
- if (d1 > dMax) {
- *numerator = n2;
- *denominator = d2;
- } else {
- *numerator = n1;
- *denominator = d1;
- }
+ if (d1 + d2 <= dMax)
+ return {n1 + n2 + integral * (d1 + d2), d1 + d2};
+ else if (d2 < d1)
+ return { n2 + integral * d2, d2 };
+ else
+ return { n1 + integral * d1, d1 };
+}
+
+QSize qCalculateFrameSize(QSize resolution, Fraction par)
+{
+ if (par.numerator == par.denominator || par.numerator < 1 || par.denominator < 1)
+ return resolution;
+
+ if (par.numerator > par.denominator)
+ return { resolution.width() * par.numerator / par.denominator, resolution.height() };
+
+ return { resolution.width(), resolution.height() * par.denominator / par.numerator };
+}
+
+QSize qRotatedFrameSize(QSize size, int rotation)
+{
+ Q_ASSERT(rotation % 90 == 0);
+ return rotation % 180 ? size.transposed() : size;
+}
+
+QSize qRotatedFrameSize(const QVideoFrame &frame)
+{
+ return qRotatedFrameSize(frame.size(), frame.rotation());
+}
+
+QUrl qMediaFromUserInput(QUrl url)
+{
+ using namespace Qt::Literals;
+ if (url.scheme().isEmpty() || url.scheme() == "file"_L1)
+ url = QUrl::fromUserInput(url.toString(), QDir::currentPath(), QUrl::AssumeLocalFile);
+ return url;
+}
+
+bool qIsAutoHdrEnabled()
+{
+ static const bool autoHdrEnabled = qEnvironmentVariableIntValue("QT_MEDIA_AUTO_HDR");
+
+ return autoHdrEnabled;
+}
+
+QRhiSwapChain::Format qGetRequiredSwapChainFormat(const QVideoFrameFormat &format)
+{
+ constexpr auto sdrMaxLuminance = 100.0f;
+ const auto formatMaxLuminance = format.maxLuminance();
+
+ return formatMaxLuminance > sdrMaxLuminance ? QRhiSwapChain::HDRExtendedSrgbLinear
+ : QRhiSwapChain::SDR;
+}
+
+bool qShouldUpdateSwapChainFormat(QRhiSwapChain *swapChain,
+ QRhiSwapChain::Format requiredSwapChainFormat)
+{
+ if (!swapChain)
+ return false;
+
+ return qIsAutoHdrEnabled() && swapChain->format() != requiredSwapChainFormat
+ && swapChain->isFormatSupported(requiredSwapChainFormat);
}
QT_END_NAMESPACE
diff --git a/src/multimedia/qmultimediautils_p.h b/src/multimedia/qmultimediautils_p.h
index 771502bdd..a5d60e066 100644
--- a/src/multimedia/qmultimediautils_p.h
+++ b/src/multimedia/qmultimediautils_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMULTIMEDIAUTILS_P_H
#define QMULTIMEDIAUTILS_P_H
@@ -51,11 +15,49 @@
// We mean it.
//
-#include <QtMultimedia/qmultimedia.h>
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtMultimedia/qtvideo.h>
+#include <QtMultimedia/private/qmaybe_p.h>
+#include <QtCore/qsize.h>
+#include <QtCore/qurl.h>
+#include <QtGui/rhi/qrhi.h>
QT_BEGIN_NAMESPACE
-Q_MULTIMEDIA_EXPORT void qt_real_to_fraction(qreal value, int *numerator, int *denominator);
+class QRhiSwapChain;
+class QVideoFrame;
+class QVideoFrameFormat;
+
+struct Fraction {
+ int numerator;
+ int denominator;
+};
+
+Q_MULTIMEDIA_EXPORT Fraction qRealToFraction(qreal value);
+
+Q_MULTIMEDIA_EXPORT QSize qCalculateFrameSize(QSize resolution, Fraction pixelAspectRatio);
+
+// TODO: after adding pixel aspect ratio to QVideoFrameFormat, the function should
+// consider PAR as well as rotation
+Q_MULTIMEDIA_EXPORT QSize qRotatedFrameSize(QSize size, int rotation);
+
+inline QSize qRotatedFrameSize(QSize size, QtVideo::Rotation rotation)
+{
+ return qRotatedFrameSize(size, qToUnderlying(rotation));
+}
+
+Q_MULTIMEDIA_EXPORT QSize qRotatedFrameSize(const QVideoFrame &frame);
+
+Q_MULTIMEDIA_EXPORT QUrl qMediaFromUserInput(QUrl fileName);
+
+Q_MULTIMEDIA_EXPORT bool qIsAutoHdrEnabled();
+
+Q_MULTIMEDIA_EXPORT QRhiSwapChain::Format
+qGetRequiredSwapChainFormat(const QVideoFrameFormat &format);
+
+Q_MULTIMEDIA_EXPORT bool
+qShouldUpdateSwapChainFormat(QRhiSwapChain *swapChain,
+ QRhiSwapChain::Format requiredSwapChainFormat);
QT_END_NAMESPACE
diff --git a/src/multimedia/qnx/qqnxaudiodevice.cpp b/src/multimedia/qnx/qqnxaudiodevice.cpp
new file mode 100644
index 000000000..4e1390e8b
--- /dev/null
+++ b/src/multimedia/qnx/qqnxaudiodevice.cpp
@@ -0,0 +1,85 @@
+// Copyright (C) 2016 Research In Motion
+// Copyright (C) 2021 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxaudiodevice_p.h"
+
+#include "qqnxaudioutils_p.h"
+
+#include <array>
+
+#include <sys/asoundlib.h>
+
+using namespace QnxAudioUtils;
+
+QT_BEGIN_NAMESPACE
+
+QnxAudioDeviceInfo::QnxAudioDeviceInfo(const QByteArray &deviceName, QAudioDevice::Mode mode)
+ : QAudioDevicePrivate(deviceName, mode)
+{
+ isDefault = id.contains("Preferred");
+
+ preferredFormat.setChannelCount(mode == QAudioDevice::Input ? 1 : 2);
+
+ description = QString::fromUtf8(id);
+
+ minimumChannelCount = 1;
+ maximumChannelCount = 2;
+
+ const std::optional<snd_pcm_channel_info_t> info = pcmChannelInfo(id, mode);
+
+ if (!info)
+ return;
+
+ minimumSampleRate = info->min_rate;
+ maximumSampleRate = info->max_rate;
+
+ constexpr std::array sampleRates { 48000, 44100, 22050, 16000, 11025, 8000 };
+
+ for (int rate : sampleRates) {
+ if (rate <= maximumSampleRate && rate >= minimumSampleRate) {
+ preferredFormat.setSampleRate(rate);
+ break;
+ }
+ }
+
+ if (info->formats & SND_PCM_FMT_U8) {
+ supportedSampleFormats << QAudioFormat::UInt8;
+ preferredFormat.setSampleFormat(QAudioFormat::UInt8);
+ }
+
+ if (info->formats & SND_PCM_FMT_S16) {
+ supportedSampleFormats << QAudioFormat::Int16;
+ preferredFormat.setSampleFormat(QAudioFormat::Int16);
+ }
+
+ if (info->formats & SND_PCM_FMT_S32)
+ supportedSampleFormats << QAudioFormat::Int32;
+
+ if (info->formats & SND_PCM_FMT_FLOAT)
+ supportedSampleFormats << QAudioFormat::Float;
+}
+
+QnxAudioDeviceInfo::~QnxAudioDeviceInfo()
+{
+}
+
+bool QnxAudioDeviceInfo::isFormatSupported(const QAudioFormat &format) const
+{
+ const HandleUniquePtr handle = openPcmDevice(id, mode);
+
+ if (!handle)
+ return false;
+
+ const std::optional<snd_pcm_channel_info_t> info = pcmChannelInfo(handle.get(), mode);
+
+ if (!info)
+ return false;
+
+ snd_pcm_channel_params_t params = formatToChannelParams(format, mode, info->max_fragment_size);
+ const int errorCode = snd_pcm_plugin_params(handle.get(), &params);
+
+ return errorCode == 0;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/qnx/qqnxaudiodevice_p.h b/src/multimedia/qnx/qqnxaudiodevice_p.h
new file mode 100644
index 000000000..52c89c14f
--- /dev/null
+++ b/src/multimedia/qnx/qqnxaudiodevice_p.h
@@ -0,0 +1,35 @@
+// Copyright (C) 2016 Research In Motion
+// Copyright (C) 2021 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QNXAUDIODEVICE_P_H
+#define QNXAUDIODEVICE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qaudiosystem_p.h"
+#include <private/qaudiodevice_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QnxAudioDeviceInfo : public QAudioDevicePrivate
+{
+public:
+ QnxAudioDeviceInfo(const QByteArray &deviceName, QAudioDevice::Mode mode);
+ ~QnxAudioDeviceInfo();
+
+ bool isFormatSupported(const QAudioFormat &format) const;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/qnx/qqnxaudiosink.cpp b/src/multimedia/qnx/qqnxaudiosink.cpp
new file mode 100644
index 000000000..fa4b97ab6
--- /dev/null
+++ b/src/multimedia/qnx/qqnxaudiosink.cpp
@@ -0,0 +1,516 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxaudiosink_p.h"
+
+#include <private/qaudiohelpers_p.h>
+#include <sys/asoundlib.h>
+#include <sys/asound_common.h>
+
+#include <algorithm>
+#include <limits>
+
+#pragma GCC diagnostic ignored "-Wvla"
+
+QT_BEGIN_NAMESPACE
+
+QQnxAudioSink::QQnxAudioSink(const QAudioDevice &deviceInfo, QObject *parent)
+ : QPlatformAudioSink(parent)
+ , m_source(0)
+ , m_pushSource(false)
+ , m_timer(new QTimer(this))
+ , m_error(QAudio::NoError)
+ , m_state(QAudio::StoppedState)
+ , m_suspendedInState(QAudio::SuspendedState)
+ , m_volume(1.0)
+ , m_periodSize(0)
+ , m_bytesWritten(0)
+ , m_requestedBufferSize(0)
+ , m_deviceInfo(deviceInfo)
+ , m_pcmNotifier(0)
+{
+ m_timer->setSingleShot(false);
+ m_timer->setInterval(20);
+ connect(m_timer, &QTimer::timeout, this, &QQnxAudioSink::pullData);
+
+ const std::optional<snd_pcm_channel_info_t> info = QnxAudioUtils::pcmChannelInfo(
+ m_deviceInfo.id(), QAudioDevice::Output);
+
+ if (info)
+ m_requestedBufferSize = info->max_fragment_size;
+}
+
+QQnxAudioSink::~QQnxAudioSink()
+{
+ stop();
+}
+
+void QQnxAudioSink::start(QIODevice *source)
+{
+ if (m_state != QAudio::StoppedState)
+ stop();
+
+ m_source = source;
+ m_pushSource = false;
+
+ if (open()) {
+ changeState(QAudio::ActiveState, QAudio::NoError);
+ m_timer->start();
+ } else {
+ changeState(QAudio::StoppedState, QAudio::OpenError);
+ }
+}
+
+QIODevice *QQnxAudioSink::start()
+{
+ if (m_state != QAudio::StoppedState)
+ stop();
+
+ m_source = new QnxPushIODevice(this);
+ m_source->open(QIODevice::WriteOnly|QIODevice::Unbuffered);
+ m_pushSource = true;
+
+ if (open()) {
+ changeState(QAudio::IdleState, QAudio::NoError);
+ } else {
+ changeState(QAudio::StoppedState, QAudio::OpenError);
+ }
+
+ return m_source;
+}
+
+void QQnxAudioSink::stop()
+{
+ if (m_state == QAudio::StoppedState)
+ return;
+
+ changeState(QAudio::StoppedState, QAudio::NoError);
+
+ close();
+}
+
+void QQnxAudioSink::reset()
+{
+ if (m_pcmHandle)
+#if SND_PCM_VERSION < SND_PROTOCOL_VERSION('P',3,0,2)
+ snd_pcm_playback_drain(m_pcmHandle.get());
+#else
+ snd_pcm_channel_drain(m_pcmHandle.get(), SND_PCM_CHANNEL_PLAYBACK);
+#endif
+ stop();
+}
+
+void QQnxAudioSink::suspend()
+{
+ if (!m_pcmHandle)
+ return;
+
+ snd_pcm_playback_pause(m_pcmHandle.get());
+ suspendInternal(QAudio::SuspendedState);
+}
+
+void QQnxAudioSink::resume()
+{
+ if (!m_pcmHandle)
+ return;
+
+ snd_pcm_playback_resume(m_pcmHandle.get());
+ resumeInternal();
+}
+
+void QQnxAudioSink::setBufferSize(qsizetype bufferSize)
+{
+ m_requestedBufferSize = std::clamp<qsizetype>(bufferSize, 0, std::numeric_limits<int>::max());
+}
+
+qsizetype QQnxAudioSink::bufferSize() const
+{
+ const std::optional<snd_pcm_channel_setup_t> setup = m_pcmHandle
+ ? QnxAudioUtils::pcmChannelSetup(m_pcmHandle.get(), QAudioDevice::Output)
+ : std::nullopt;
+
+ return setup ? setup->buf.block.frag_size : m_requestedBufferSize;
+}
+
+qsizetype QQnxAudioSink::bytesFree() const
+{
+ if (m_state != QAudio::ActiveState && m_state != QAudio::IdleState)
+ return 0;
+
+ const std::optional<snd_pcm_channel_status_t> status = QnxAudioUtils::pcmChannelStatus(
+ m_pcmHandle.get(), QAudioDevice::Output);
+
+ return status ? status->free : 0;
+}
+
+qint64 QQnxAudioSink::processedUSecs() const
+{
+ return qint64(1000000) * m_format.framesForBytes(m_bytesWritten) / m_format.sampleRate();
+}
+
+QAudio::Error QQnxAudioSink::error() const
+{
+ return m_error;
+}
+
+QAudio::State QQnxAudioSink::state() const
+{
+ return m_state;
+}
+
+void QQnxAudioSink::setFormat(const QAudioFormat &format)
+{
+ if (m_state == QAudio::StoppedState)
+ m_format = format;
+}
+
+QAudioFormat QQnxAudioSink::format() const
+{
+ return m_format;
+}
+
+void QQnxAudioSink::setVolume(qreal volume)
+{
+ m_volume = qBound(qreal(0.0), volume, qreal(1.0));
+}
+
+qreal QQnxAudioSink::volume() const
+{
+ return m_volume;
+}
+
+void QQnxAudioSink::updateState()
+{
+ const std::optional<snd_pcm_channel_status_t> status = QnxAudioUtils::pcmChannelStatus(
+ m_pcmHandle.get(), QAudioDevice::Output);
+
+ if (!status)
+ return;
+
+ if (state() == QAudio::ActiveState && status->underrun > 0)
+ changeState(QAudio::IdleState, QAudio::UnderrunError);
+ else if (state() == QAudio::IdleState && status->underrun == 0)
+ changeState(QAudio::ActiveState, QAudio::NoError);
+}
+
+void QQnxAudioSink::pullData()
+{
+ if (m_state == QAudio::StoppedState
+ || m_state == QAudio::SuspendedState)
+ return;
+
+ const int bytesAvailable = bytesFree();
+
+ // skip if we have less than 4ms of data
+ if (m_format.durationForBytes(bytesAvailable) < 4000)
+ return;
+
+ const int frames = m_format.framesForBytes(bytesAvailable);
+ // The buffer is placed on the stack so no more than 64K or 1 frame
+ // whichever is larger.
+ const int maxFrames = qMax(m_format.framesForBytes(64 * 1024), 1);
+ const int bytesRequested = m_format.bytesForFrames(qMin(frames, maxFrames));
+
+ char buffer[bytesRequested];
+ const int bytesRead = m_source->read(buffer, bytesRequested);
+
+ // reading can take a while and stream may have been stopped
+ if (!m_pcmHandle)
+ return;
+
+ if (bytesRead > 0) {
+ const qint64 bytesWritten = write(buffer, bytesRead);
+
+ if (bytesWritten <= 0) {
+ close();
+ changeState(QAudio::StoppedState, QAudio::FatalError);
+ } else if (bytesWritten != bytesRead) {
+ m_source->seek(m_source->pos()-(bytesRead-bytesWritten));
+ }
+ } else {
+ // We're done
+ if (bytesRead == 0)
+ changeState(QAudio::IdleState, QAudio::NoError);
+ else
+ changeState(QAudio::IdleState, QAudio::IOError);
+ }
+}
+
+bool QQnxAudioSink::open()
+{
+ if (!m_format.isValid() || m_format.sampleRate() <= 0) {
+ if (!m_format.isValid())
+ qWarning("QQnxAudioSink: open error, invalid format.");
+ else
+ qWarning("QQnxAudioSink: open error, invalid sample rate (%d).", m_format.sampleRate());
+
+ return false;
+ }
+
+
+ m_pcmHandle = QnxAudioUtils::openPcmDevice(m_deviceInfo.id(), QAudioDevice::Output);
+
+ if (!m_pcmHandle)
+ return false;
+
+ int errorCode = 0;
+
+ if ((errorCode = snd_pcm_nonblock_mode(m_pcmHandle.get(), 0)) < 0) {
+ qWarning("QQnxAudioSink: open error, couldn't set non block mode (0x%x)", -errorCode);
+ close();
+ return false;
+ }
+
+ addPcmEventFilter();
+
+ // Necessary so that bytesFree() which uses the "free" member of the status struct works
+ snd_pcm_plugin_set_disable(m_pcmHandle.get(), PLUGIN_MMAP);
+
+ const std::optional<snd_pcm_channel_info_t> info = QnxAudioUtils::pcmChannelInfo(
+ m_pcmHandle.get(), QAudioDevice::Output);
+
+ if (!info) {
+ close();
+ return false;
+ }
+
+ const int fragmentSize = std::clamp(m_requestedBufferSize,
+ info->min_fragment_size, info->max_fragment_size);
+
+ snd_pcm_channel_params_t params = QnxAudioUtils::formatToChannelParams(m_format,
+ QAudioDevice::Output, fragmentSize);
+
+ if ((errorCode = snd_pcm_plugin_params(m_pcmHandle.get(), &params)) < 0) {
+ qWarning("QQnxAudioSink: open error, couldn't set channel params (0x%x)", -errorCode);
+ close();
+ return false;
+ }
+
+ if ((errorCode = snd_pcm_plugin_prepare(m_pcmHandle.get(), SND_PCM_CHANNEL_PLAYBACK)) < 0) {
+ qWarning("QQnxAudioSink: open error, couldn't prepare channel (0x%x)", -errorCode);
+ close();
+ return false;
+ }
+
+ const std::optional<snd_pcm_channel_setup_t> setup = QnxAudioUtils::pcmChannelSetup(
+ m_pcmHandle.get(), QAudioDevice::Output);
+
+ if (!setup) {
+ close();
+ return false;
+ }
+
+ m_periodSize = qMin(2048, setup->buf.block.frag_size);
+ m_bytesWritten = 0;
+
+ createPcmNotifiers();
+
+ return true;
+}
+
+void QQnxAudioSink::close()
+{
+ if (!m_pushSource)
+ m_timer->stop();
+
+ destroyPcmNotifiers();
+
+ if (m_pcmHandle) {
+#if SND_PCM_VERSION < SND_PROTOCOL_VERSION('P',3,0,2)
+ snd_pcm_plugin_flush(m_pcmHandle.get(), SND_PCM_CHANNEL_PLAYBACK);
+#else
+ snd_pcm_plugin_drop(m_pcmHandle.get(), SND_PCM_CHANNEL_PLAYBACK);
+#endif
+ m_pcmHandle = nullptr;
+ }
+
+ if (m_pushSource) {
+ delete m_source;
+ m_source = 0;
+ }
+}
+
+void QQnxAudioSink::changeState(QAudio::State state, QAudio::Error error)
+{
+ if (m_state != state) {
+ m_state = state;
+ emit stateChanged(state);
+ }
+
+ if (m_error != error) {
+ m_error = error;
+ emit errorChanged(error);
+ }
+}
+
+qint64 QQnxAudioSink::pushData(const char *data, qint64 len)
+{
+ const QAudio::State s = state();
+
+ if (s == QAudio::StoppedState || s == QAudio::SuspendedState)
+ return 0;
+
+ if (s == QAudio::IdleState)
+ changeState(QAudio::ActiveState, QAudio::NoError);
+
+ qint64 totalWritten = 0;
+
+ int retry = 0;
+
+ constexpr int maxRetries = 10;
+
+ while (totalWritten < len) {
+ const int bytesWritten = write(data + totalWritten, len - totalWritten);
+
+ if (bytesWritten <= 0) {
+ ++retry;
+
+ if (retry >= maxRetries) {
+ close();
+ changeState(QAudio::StoppedState, QAudio::FatalError);
+
+ return totalWritten;
+ } else {
+ continue;
+ }
+ }
+
+ retry = 0;
+
+ totalWritten += bytesWritten;
+ }
+
+ return totalWritten;
+}
+
+qint64 QQnxAudioSink::write(const char *data, qint64 len)
+{
+ if (!m_pcmHandle)
+ return 0;
+
+ // Make sure we're writing (N * frame) worth of bytes
+ const int size = m_format.bytesForFrames(qBound(qint64(0), qint64(bytesFree()), len) / m_format.bytesPerFrame());
+
+ if (size == 0)
+ return 0;
+
+ int written = 0;
+
+ if (m_volume < 1.0f) {
+ char out[size];
+ QAudioHelperInternal::qMultiplySamples(m_volume, m_format, data, out, size);
+ written = snd_pcm_plugin_write(m_pcmHandle.get(), out, size);
+ } else {
+ written = snd_pcm_plugin_write(m_pcmHandle.get(), data, size);
+ }
+
+ if (written > 0) {
+ m_bytesWritten += written;
+ return written;
+ }
+
+ return 0;
+}
+
+void QQnxAudioSink::suspendInternal(QAudio::State suspendState)
+{
+ if (!m_pushSource)
+ m_timer->stop();
+
+ m_suspendedInState = m_state;
+ changeState(suspendState, QAudio::NoError);
+}
+
+void QQnxAudioSink::resumeInternal()
+{
+ changeState(m_suspendedInState, QAudio::NoError);
+
+ m_timer->start();
+}
+
+QAudio::State suspendState(const snd_pcm_event_t &event)
+{
+ Q_ASSERT(event.type == SND_PCM_EVENT_AUDIOMGMT_STATUS);
+ Q_ASSERT(event.data.audiomgmt_status.new_status == SND_PCM_STATUS_SUSPENDED);
+ return QAudio::SuspendedState;
+}
+
+void QQnxAudioSink::addPcmEventFilter()
+{
+ /* Enable PCM events */
+ snd_pcm_filter_t filter;
+ memset(&filter, 0, sizeof(filter));
+ filter.enable = (1<<SND_PCM_EVENT_AUDIOMGMT_STATUS) |
+ (1<<SND_PCM_EVENT_AUDIOMGMT_MUTE) |
+ (1<<SND_PCM_EVENT_OUTPUTCLASS) |
+ (1<<SND_PCM_EVENT_UNDERRUN);
+ snd_pcm_set_filter(m_pcmHandle.get(), SND_PCM_CHANNEL_PLAYBACK, &filter);
+}
+
+void QQnxAudioSink::createPcmNotifiers()
+{
+ // QSocketNotifier::Read for poll based event dispatcher. Exception for
+ // select based event dispatcher.
+ m_pcmNotifier = new QSocketNotifier(snd_pcm_file_descriptor(m_pcmHandle.get(),
+ SND_PCM_CHANNEL_PLAYBACK),
+ QSocketNotifier::Read, this);
+ connect(m_pcmNotifier, &QSocketNotifier::activated,
+ this, &QQnxAudioSink::pcmNotifierActivated);
+}
+
+void QQnxAudioSink::destroyPcmNotifiers()
+{
+ if (m_pcmNotifier) {
+ delete m_pcmNotifier;
+ m_pcmNotifier = 0;
+ }
+}
+
+void QQnxAudioSink::pcmNotifierActivated(int socket)
+{
+ Q_UNUSED(socket);
+
+ snd_pcm_event_t pcm_event;
+ memset(&pcm_event, 0, sizeof(pcm_event));
+ while (snd_pcm_channel_read_event(m_pcmHandle.get(), SND_PCM_CHANNEL_PLAYBACK, &pcm_event) == 0) {
+ if (pcm_event.type == SND_PCM_EVENT_AUDIOMGMT_STATUS) {
+ if (pcm_event.data.audiomgmt_status.new_status == SND_PCM_STATUS_SUSPENDED)
+ suspendInternal(suspendState(pcm_event));
+ else if (pcm_event.data.audiomgmt_status.new_status == SND_PCM_STATUS_RUNNING)
+ resumeInternal();
+ else if (pcm_event.data.audiomgmt_status.new_status == SND_PCM_STATUS_PAUSED)
+ suspendInternal(QAudio::SuspendedState);
+ } else if (pcm_event.type == SND_PCM_EVENT_UNDERRUN) {
+ updateState();
+ }
+ }
+}
+
+QnxPushIODevice::QnxPushIODevice(QQnxAudioSink *output)
+ : QIODevice(output),
+ m_output(output)
+{
+}
+
+QnxPushIODevice::~QnxPushIODevice()
+{
+}
+
+qint64 QnxPushIODevice::readData(char *data, qint64 len)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(len);
+ return 0;
+}
+
+qint64 QnxPushIODevice::writeData(const char *data, qint64 len)
+{
+ return m_output->pushData(data, len);
+}
+
+bool QnxPushIODevice::isSequential() const
+{
+ return true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/qnx/qqnxaudiosink_p.h b/src/multimedia/qnx/qqnxaudiosink_p.h
new file mode 100644
index 000000000..1275121b3
--- /dev/null
+++ b/src/multimedia/qnx/qqnxaudiosink_p.h
@@ -0,0 +1,119 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QNXAUDIOOUTPUT_H
+#define QNXAUDIOOUTPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qaudiosystem_p.h"
+
+#include "qqnxaudioutils_p.h"
+
+#include <QElapsedTimer>
+#include <QTimer>
+#include <QIODevice>
+#include <QSocketNotifier>
+
+#include <sys/asoundlib.h>
+#include <sys/neutrino.h>
+
+QT_BEGIN_NAMESPACE
+
+class QnxPushIODevice;
+
+class QQnxAudioSink : public QPlatformAudioSink
+{
+ Q_OBJECT
+
+public:
+ explicit QQnxAudioSink(const QAudioDevice &deviceInfo, QObject *parent);
+ ~QQnxAudioSink();
+
+ void start(QIODevice *source) override;
+ QIODevice *start() override;
+ void stop() override;
+ void reset() override;
+ void suspend() override;
+ void resume() override;
+ qsizetype bytesFree() const override;
+ void setBufferSize(qsizetype) override;
+ qsizetype bufferSize() const override;
+ qint64 processedUSecs() const override;
+ QAudio::Error error() const override;
+ QAudio::State state() const override;
+ void setFormat(const QAudioFormat &format) override;
+ QAudioFormat format() const override;
+ void setVolume(qreal volume) override;
+ qreal volume() const override;
+ qint64 pushData(const char *data, qint64 len);
+
+private slots:
+ void pullData();
+ void pcmNotifierActivated(int socket);
+
+private:
+ bool open();
+ void close();
+ void changeState(QAudio::State state, QAudio::Error error);
+
+ void addPcmEventFilter();
+ void createPcmNotifiers();
+ void destroyPcmNotifiers();
+
+ void suspendInternal(QAudio::State suspendState);
+ void resumeInternal();
+
+ void updateState();
+
+ qint64 write(const char *data, qint64 len);
+
+ QIODevice *m_source;
+ bool m_pushSource;
+ QTimer *m_timer;
+
+ QAudio::Error m_error;
+ QAudio::State m_state;
+ QAudio::State m_suspendedInState;
+ QAudioFormat m_format;
+ qreal m_volume;
+ int m_periodSize;
+
+ QnxAudioUtils::HandleUniquePtr m_pcmHandle;
+ qint64 m_bytesWritten;
+
+ int m_requestedBufferSize;
+
+ QAudioDevice m_deviceInfo;
+
+ QSocketNotifier *m_pcmNotifier;
+};
+
+class QnxPushIODevice : public QIODevice
+{
+ Q_OBJECT
+public:
+ explicit QnxPushIODevice(QQnxAudioSink *output);
+ ~QnxPushIODevice();
+
+ qint64 readData(char *data, qint64 len);
+ qint64 writeData(const char *data, qint64 len);
+
+ bool isSequential() const override;
+
+private:
+ QQnxAudioSink *m_output;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/qnx/qqnxaudiosource.cpp b/src/multimedia/qnx/qqnxaudiosource.cpp
new file mode 100644
index 000000000..becbaa0c0
--- /dev/null
+++ b/src/multimedia/qnx/qqnxaudiosource.cpp
@@ -0,0 +1,376 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxaudiosource_p.h"
+
+#include <private/qaudiohelpers_p.h>
+
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+QQnxAudioSource::QQnxAudioSource(const QAudioDevice &deviceInfo, QObject *parent)
+ : QPlatformAudioSource(parent)
+ , m_audioSource(0)
+ , m_pcmNotifier(0)
+ , m_error(QAudio::NoError)
+ , m_state(QAudio::StoppedState)
+ , m_bytesRead(0)
+ , m_elapsedTimeOffset(0)
+ , m_totalTimeValue(0)
+ , m_volume(qreal(1.0f))
+ , m_bytesAvailable(0)
+ , m_bufferSize(0)
+ , m_periodSize(0)
+ , m_deviceInfo(deviceInfo)
+ , m_pullMode(true)
+{
+}
+
+QQnxAudioSource::~QQnxAudioSource()
+{
+ close();
+}
+
+void QQnxAudioSource::start(QIODevice *device)
+{
+ if (m_state != QAudio::StoppedState)
+ close();
+
+ if (!m_pullMode && m_audioSource)
+ delete m_audioSource;
+
+ m_pullMode = true;
+ m_audioSource = device;
+
+ if (open())
+ changeState(QAudio::ActiveState, QAudio::NoError);
+ else
+ changeState(QAudio::StoppedState, QAudio::OpenError);
+}
+
+QIODevice *QQnxAudioSource::start()
+{
+ if (m_state != QAudio::StoppedState)
+ close();
+
+ if (!m_pullMode && m_audioSource)
+ delete m_audioSource;
+
+ m_pullMode = false;
+ m_audioSource = new InputPrivate(this);
+ m_audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
+
+ if (open()) {
+ changeState(QAudio::IdleState, QAudio::NoError);
+ } else {
+ delete m_audioSource;
+ m_audioSource = 0;
+
+ changeState(QAudio::StoppedState, QAudio::OpenError);
+ }
+
+ return m_audioSource;
+}
+
+void QQnxAudioSource::stop()
+{
+ if (m_state == QAudio::StoppedState)
+ return;
+
+ changeState(QAudio::StoppedState, QAudio::NoError);
+ close();
+}
+
+void QQnxAudioSource::reset()
+{
+ stop();
+ m_bytesAvailable = 0;
+}
+
+void QQnxAudioSource::suspend()
+{
+ if (m_state == QAudio::StoppedState)
+ return;
+
+ snd_pcm_capture_pause(m_pcmHandle.get());
+
+ if (m_pcmNotifier)
+ m_pcmNotifier->setEnabled(false);
+
+ changeState(QAudio::SuspendedState, QAudio::NoError);
+}
+
+void QQnxAudioSource::resume()
+{
+ if (m_state == QAudio::StoppedState)
+ return;
+
+ snd_pcm_capture_resume(m_pcmHandle.get());
+
+ if (m_pcmNotifier)
+ m_pcmNotifier->setEnabled(true);
+
+ if (m_pullMode)
+ changeState(QAudio::ActiveState, QAudio::NoError);
+ else
+ changeState(QAudio::IdleState, QAudio::NoError);
+}
+
+qsizetype QQnxAudioSource::bytesReady() const
+{
+ return qMax(m_bytesAvailable, 0);
+}
+
+void QQnxAudioSource::setBufferSize(qsizetype bufferSize)
+{
+ m_bufferSize = bufferSize;
+}
+
+qsizetype QQnxAudioSource::bufferSize() const
+{
+ return m_bufferSize;
+}
+
+qint64 QQnxAudioSource::processedUSecs() const
+{
+ return qint64(1000000) * m_format.framesForBytes(m_bytesRead) / m_format.sampleRate();
+}
+
+QAudio::Error QQnxAudioSource::error() const
+{
+ return m_error;
+}
+
+QAudio::State QQnxAudioSource::state() const
+{
+ return m_state;
+}
+
+void QQnxAudioSource::setFormat(const QAudioFormat &format)
+{
+ if (m_state == QAudio::StoppedState)
+ m_format = format;
+}
+
+QAudioFormat QQnxAudioSource::format() const
+{
+ return m_format;
+}
+
+void QQnxAudioSource::setVolume(qreal volume)
+{
+ m_volume = qBound(qreal(0.0), volume, qreal(1.0));
+}
+
+qreal QQnxAudioSource::volume() const
+{
+ return m_volume;
+}
+
+void QQnxAudioSource::userFeed()
+{
+ if (m_state == QAudio::StoppedState || m_state == QAudio::SuspendedState)
+ return;
+
+ deviceReady();
+}
+
+bool QQnxAudioSource::deviceReady()
+{
+ if (m_pullMode) {
+ // reads some audio data and writes it to QIODevice
+ read(0, 0);
+ } else {
+ m_bytesAvailable = m_periodSize;
+
+ // emits readyRead() so user will call read() on QIODevice to get some audio data
+ if (m_audioSource != 0) {
+ InputPrivate *input = qobject_cast<InputPrivate*>(m_audioSource);
+ input->trigger();
+ }
+ }
+
+ if (m_state != QAudio::ActiveState)
+ return true;
+
+ return true;
+}
+
+bool QQnxAudioSource::open()
+{
+ if (!m_format.isValid() || m_format.sampleRate() <= 0) {
+ if (!m_format.isValid())
+ qWarning("QQnxAudioSource: open error, invalid format.");
+ else
+ qWarning("QQnxAudioSource: open error, invalid sample rate (%d).", m_format.sampleRate());
+
+ return false;
+ }
+
+ m_pcmHandle = QnxAudioUtils::openPcmDevice(m_deviceInfo.id(), QAudioDevice::Input);
+
+ if (!m_pcmHandle)
+ return false;
+
+ int errorCode = 0;
+
+ // Necessary so that bytesFree() which uses the "free" member of the status struct works
+ snd_pcm_plugin_set_disable(m_pcmHandle.get(), PLUGIN_MMAP);
+
+ const std::optional<snd_pcm_channel_info_t> info = QnxAudioUtils::pcmChannelInfo(
+ m_pcmHandle.get(), QAudioDevice::Input);
+
+ if (!info) {
+ close();
+ return false;
+ }
+
+ snd_pcm_channel_params_t params = QnxAudioUtils::formatToChannelParams(m_format,
+ QAudioDevice::Input, info->max_fragment_size);
+
+ if ((errorCode = snd_pcm_plugin_params(m_pcmHandle.get(), &params)) < 0) {
+ qWarning("QQnxAudioSource: open error, couldn't set channel params (0x%x)", -errorCode);
+ close();
+ return false;
+ }
+
+ if ((errorCode = snd_pcm_plugin_prepare(m_pcmHandle.get(), SND_PCM_CHANNEL_CAPTURE)) < 0) {
+ qWarning("QQnxAudioSource: open error, couldn't prepare channel (0x%x)", -errorCode);
+ close();
+ return false;
+ }
+
+ const std::optional<snd_pcm_channel_setup_t> setup = QnxAudioUtils::pcmChannelSetup(
+ m_pcmHandle.get(), QAudioDevice::Input);
+
+ m_periodSize = qMin(2048, setup->buf.block.frag_size);
+
+ m_elapsedTimeOffset = 0;
+ m_totalTimeValue = 0;
+ m_bytesRead = 0;
+
+ m_pcmNotifier = new QSocketNotifier(snd_pcm_file_descriptor(m_pcmHandle.get(), SND_PCM_CHANNEL_CAPTURE),
+ QSocketNotifier::Read, this);
+ connect(m_pcmNotifier, SIGNAL(activated(QSocketDescriptor)), this, SLOT(userFeed()));
+
+ return true;
+}
+
+void QQnxAudioSource::close()
+{
+ if (m_pcmHandle) {
+#if SND_PCM_VERSION < SND_PROTOCOL_VERSION('P',3,0,2)
+ snd_pcm_plugin_flush(m_pcmHandle.get(), SND_PCM_CHANNEL_CAPTURE);
+#else
+ snd_pcm_plugin_drop(m_pcmHandle.get(), SND_PCM_CHANNEL_CAPTURE);
+#endif
+ m_pcmHandle = nullptr;
+ }
+
+ if (m_pcmNotifier) {
+ delete m_pcmNotifier;
+ m_pcmNotifier = 0;
+ }
+
+ if (!m_pullMode && m_audioSource) {
+ delete m_audioSource;
+ m_audioSource = 0;
+ }
+}
+
+qint64 QQnxAudioSource::read(char *data, qint64 len)
+{
+ if (!m_pullMode && m_bytesAvailable == 0)
+ return 0;
+
+ int errorCode = 0;
+ QByteArray tempBuffer(m_periodSize, 0);
+
+ const int actualRead = snd_pcm_plugin_read(m_pcmHandle.get(), tempBuffer.data(), m_periodSize);
+ if (actualRead < 1) {
+ snd_pcm_channel_status_t status;
+ memset(&status, 0, sizeof(status));
+ status.channel = SND_PCM_CHANNEL_CAPTURE;
+ if ((errorCode = snd_pcm_plugin_status(m_pcmHandle.get(), &status)) < 0) {
+ qWarning("QQnxAudioSource: read error, couldn't get plugin status (0x%x)", -errorCode);
+ close();
+ changeState(QAudio::StoppedState, QAudio::FatalError);
+ return -1;
+ }
+
+ if (status.status == SND_PCM_STATUS_READY
+ || status.status == SND_PCM_STATUS_OVERRUN) {
+ if ((errorCode = snd_pcm_plugin_prepare(m_pcmHandle.get(), SND_PCM_CHANNEL_CAPTURE)) < 0) {
+ qWarning("QQnxAudioSource: read error, couldn't prepare plugin (0x%x)", -errorCode);
+ close();
+ changeState(QAudio::StoppedState, QAudio::FatalError);
+ return -1;
+ }
+ }
+ } else {
+ changeState(QAudio::ActiveState, QAudio::NoError);
+ }
+
+ if (m_volume < 1.0f)
+ QAudioHelperInternal::qMultiplySamples(m_volume, m_format, tempBuffer.data(), tempBuffer.data(), actualRead);
+
+ m_bytesRead += actualRead;
+
+ if (m_pullMode) {
+ m_audioSource->write(tempBuffer.data(), actualRead);
+ } else {
+ memcpy(data, tempBuffer.data(), qMin(static_cast<qint64>(actualRead), len));
+ }
+
+ m_bytesAvailable = 0;
+
+ return actualRead;
+}
+
+void QQnxAudioSource::changeState(QAudio::State state, QAudio::Error error)
+{
+ if (m_state != state) {
+ m_state = state;
+ emit stateChanged(state);
+ }
+
+ if (m_error != error) {
+ m_error = error;
+ emit errorChanged(error);
+ }
+}
+
+InputPrivate::InputPrivate(QQnxAudioSource *audio)
+ : m_audioDevice(audio)
+{
+}
+
+qint64 InputPrivate::readData(char *data, qint64 len)
+{
+ return m_audioDevice->read(data, len);
+}
+
+qint64 InputPrivate::writeData(const char *data, qint64 len)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(len);
+ return 0;
+}
+
+qint64 InputPrivate::bytesAvailable() const
+{
+ return m_audioDevice->m_bytesAvailable + QIODevice::bytesAvailable();
+}
+
+bool InputPrivate::isSequential() const
+{
+ return true;
+}
+
+void InputPrivate::trigger()
+{
+ emit readyRead();
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/qnx/qqnxaudiosource_p.h b/src/multimedia/qnx/qqnxaudiosource_p.h
new file mode 100644
index 000000000..6b9cf61ac
--- /dev/null
+++ b/src/multimedia/qnx/qqnxaudiosource_p.h
@@ -0,0 +1,113 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QNXAUDIOINPUT_H
+#define QNXAUDIOINPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qaudiosystem_p.h"
+
+#include "qqnxaudioutils_p.h"
+
+#include <QSocketNotifier>
+#include <QIODevice>
+#include <QElapsedTimer>
+#include <QTimer>
+
+#include <sys/asoundlib.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxAudioSource : public QPlatformAudioSource
+{
+ Q_OBJECT
+
+public:
+ explicit QQnxAudioSource(const QAudioDevice &deviceInfo, QObject *parent);
+ ~QQnxAudioSource();
+
+ void start(QIODevice*) override;
+ QIODevice* start() override;
+ void stop() override;
+ void reset() override;
+ void suspend() override;
+ void resume() override;
+ qsizetype bytesReady() const override;
+ void setBufferSize(qsizetype ) override;
+ qsizetype bufferSize() const override;
+ qint64 processedUSecs() const override;
+ QAudio::Error error() const override;
+ QAudio::State state() const override;
+ void setFormat(const QAudioFormat&) override;
+ QAudioFormat format() const override;
+ void setVolume(qreal) override;
+ qreal volume() const override;
+
+private slots:
+ void userFeed();
+ bool deviceReady();
+
+private:
+ friend class InputPrivate;
+
+ bool open();
+ void close();
+ qint64 read(char *data, qint64 len);
+ void changeState(QAudio::State state, QAudio::Error error);
+
+ QAudioFormat m_format;
+
+ QIODevice *m_audioSource;
+ QnxAudioUtils::HandleUniquePtr m_pcmHandle;
+ QSocketNotifier *m_pcmNotifier;
+
+ QAudio::Error m_error;
+ QAudio::State m_state;
+
+ qint64 m_bytesRead;
+ qint64 m_elapsedTimeOffset;
+ qint64 m_totalTimeValue;
+
+ qreal m_volume;
+
+ int m_bytesAvailable;
+ int m_bufferSize;
+ int m_periodSize;
+
+ QAudioDevice m_deviceInfo;
+
+ bool m_pullMode;
+};
+
+class InputPrivate : public QIODevice
+{
+ Q_OBJECT
+public:
+ InputPrivate(QQnxAudioSource *audio);
+
+ qint64 readData(char *data, qint64 len) override;
+ qint64 writeData(const char *data, qint64 len) override;
+
+ qint64 bytesAvailable() const override;
+
+ bool isSequential() const override;
+
+ void trigger();
+
+private:
+ QQnxAudioSource *m_audioDevice;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/qnx/qqnxaudioutils.cpp b/src/multimedia/qnx/qqnxaudioutils.cpp
new file mode 100644
index 000000000..ddcb4f0de
--- /dev/null
+++ b/src/multimedia/qnx/qqnxaudioutils.cpp
@@ -0,0 +1,148 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxaudioutils_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QnxAudioUtils
+{
+
+snd_pcm_channel_params_t formatToChannelParams(const QAudioFormat &format, QAudioDevice::Mode mode, int fragmentSize)
+{
+ snd_pcm_channel_params_t params;
+ memset(&params, 0, sizeof(params));
+ params.channel = (mode == QAudioDevice::Output) ? SND_PCM_CHANNEL_PLAYBACK : SND_PCM_CHANNEL_CAPTURE;
+ params.mode = SND_PCM_MODE_BLOCK;
+ params.start_mode = SND_PCM_START_DATA;
+ params.stop_mode = SND_PCM_STOP_ROLLOVER;
+ params.buf.block.frag_size = fragmentSize;
+ params.buf.block.frags_min = 1;
+ params.buf.block.frags_max = 1;
+ strcpy(params.sw_mixer_subchn_name, "QAudio Channel");
+
+ params.format.interleave = 1;
+ params.format.rate = format.sampleRate();
+ params.format.voices = format.channelCount();
+
+ switch (format.sampleFormat()) {
+ case QAudioFormat::UInt8:
+ params.format.format = SND_PCM_SFMT_U8;
+ break;
+ default:
+ // fall through
+ case QAudioFormat::Int16:
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ params.format.format = SND_PCM_SFMT_S16_LE;
+#else
+ params.format.format = SND_PCM_SFMT_S16_BE;
+#endif
+ break;
+ case QAudioFormat::Int32:
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ params.format.format = SND_PCM_SFMT_S32_LE;
+#else
+ params.format.format = SND_PCM_SFMT_S32_BE;
+#endif
+ break;
+ case QAudioFormat::Float:
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ params.format.format = SND_PCM_SFMT_FLOAT_LE;
+#else
+ params.format.format = SND_PCM_SFMT_FLOAT_BE;
+#endif
+ break;
+ }
+
+ return params;
+}
+
+
+HandleUniquePtr openPcmDevice(const QByteArray &id, QAudioDevice::Mode mode)
+{
+ const int pcmMode = mode == QAudioDevice::Output
+ ? SND_PCM_OPEN_PLAYBACK
+ : SND_PCM_OPEN_CAPTURE;
+
+ snd_pcm_t *handle;
+
+ const int errorCode = snd_pcm_open_name(&handle, id.constData(), pcmMode);
+
+ if (errorCode != 0) {
+ qWarning("Unable to open PCM device %s (0x%x)", id.constData(), -errorCode);
+ return {};
+ }
+
+ return HandleUniquePtr { handle };
+}
+
+template <typename T, typename Func>
+std::optional<T> pcmChannelGetStruct(snd_pcm_t *handle, QAudioDevice::Mode mode, Func &&func)
+{
+ // initialize in-place to prevent an extra copy when returning
+ std::optional<T> t = { T{} };
+
+ t->channel = mode == QAudioDevice::Output
+ ? SND_PCM_CHANNEL_PLAYBACK
+ : SND_PCM_CHANNEL_CAPTURE;
+
+ const int errorCode = func(handle, &(*t));
+
+ if (errorCode != 0) {
+ qWarning("QAudioDevice: couldn't get channel info (0x%x)", -errorCode);
+ return {};
+ }
+
+ return t;
+}
+
+template <typename T, typename Func>
+std::optional<T> pcmChannelGetStruct(const QByteArray &device,
+ QAudioDevice::Mode mode, Func &&func)
+{
+ const HandleUniquePtr handle = openPcmDevice(device, mode);
+
+ if (!handle)
+ return {};
+
+ return pcmChannelGetStruct<T>(handle.get(), mode, std::forward<Func>(func));
+}
+
+
+std::optional<snd_pcm_channel_info_t> pcmChannelInfo(snd_pcm_t *handle, QAudioDevice::Mode mode)
+{
+ return pcmChannelGetStruct<snd_pcm_channel_info_t>(handle, mode, snd_pcm_plugin_info);
+}
+
+std::optional<snd_pcm_channel_info_t> pcmChannelInfo(const QByteArray &device,
+ QAudioDevice::Mode mode)
+{
+ return pcmChannelGetStruct<snd_pcm_channel_info_t>(device, mode, snd_pcm_plugin_info);
+}
+
+std::optional<snd_pcm_channel_setup_t> pcmChannelSetup(snd_pcm_t *handle, QAudioDevice::Mode mode)
+{
+ return pcmChannelGetStruct<snd_pcm_channel_setup_t>(handle, mode, snd_pcm_plugin_setup);
+}
+
+std::optional<snd_pcm_channel_setup_t> pcmChannelSetup(const QByteArray &device,
+ QAudioDevice::Mode mode)
+{
+ return pcmChannelGetStruct<snd_pcm_channel_setup_t>(device, mode, snd_pcm_plugin_setup);
+}
+
+std::optional<snd_pcm_channel_status_t> pcmChannelStatus(snd_pcm_t *handle, QAudioDevice::Mode mode)
+{
+ return pcmChannelGetStruct<snd_pcm_channel_status_t>(handle, mode, snd_pcm_plugin_status);
+}
+
+std::optional<snd_pcm_channel_status_t> pcmChannelStatus(const QByteArray &device,
+ QAudioDevice::Mode mode)
+{
+ return pcmChannelGetStruct<snd_pcm_channel_status_t>(device, mode, snd_pcm_plugin_status);
+}
+
+
+} // namespace QnxAudioUtils
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/qnx/qqnxaudioutils_p.h b/src/multimedia/qnx/qqnxaudioutils_p.h
new file mode 100644
index 000000000..c0d2e5b1c
--- /dev/null
+++ b/src/multimedia/qnx/qqnxaudioutils_p.h
@@ -0,0 +1,51 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QNXAUDIOUTILS_H
+#define QNXAUDIOUTILS_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qaudiosystem_p.h"
+
+#include <memory>
+#include <optional>
+
+#include <sys/asoundlib.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QnxAudioUtils
+{
+ snd_pcm_channel_params_t formatToChannelParams(const QAudioFormat &format, QAudioDevice::Mode mode, int fragmentSize);
+
+ struct HandleDeleter
+ {
+ void operator()(snd_pcm_t *h) { if (h) snd_pcm_close(h); }
+ };
+
+ using HandleUniquePtr = std::unique_ptr<snd_pcm_t, HandleDeleter>;
+ HandleUniquePtr openPcmDevice(const QByteArray &id, QAudioDevice::Mode mode);
+
+ std::optional<snd_pcm_channel_info_t> pcmChannelInfo(snd_pcm_t *handle, QAudioDevice::Mode mode);
+ std::optional<snd_pcm_channel_info_t> pcmChannelInfo(const QByteArray &device, QAudioDevice::Mode mode);
+
+ std::optional<snd_pcm_channel_setup_t> pcmChannelSetup(snd_pcm_t *handle, QAudioDevice::Mode mode);
+ std::optional<snd_pcm_channel_setup_t> pcmChannelSetup(const QByteArray &device, QAudioDevice::Mode mode);
+
+ std::optional<snd_pcm_channel_status_t> pcmChannelStatus(snd_pcm_t *handle, QAudioDevice::Mode mode);
+ std::optional<snd_pcm_channel_status_t> pcmChannelStatus(const QByteArray &device, QAudioDevice::Mode mode);
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/qnx/qqnxmediadevices.cpp b/src/multimedia/qnx/qqnxmediadevices.cpp
new file mode 100644
index 000000000..d9e33fcdc
--- /dev/null
+++ b/src/multimedia/qnx/qqnxmediadevices.cpp
@@ -0,0 +1,70 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxmediadevices_p.h"
+#include "qmediadevices.h"
+#include "private/qcameradevice_p.h"
+#include "qcameradevice.h"
+
+#include "qqnxaudiosource_p.h"
+#include "qqnxaudiosink_p.h"
+#include "qqnxaudiodevice_p.h"
+
+#include <qdir.h>
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+static QList<QAudioDevice> enumeratePcmDevices(QAudioDevice::Mode mode)
+{
+ if (mode == QAudioDevice::Null)
+ return {};
+
+ QDir dir(QStringLiteral("/dev/snd"));
+
+ dir.setFilter(QDir::Files);
+ dir.setSorting(QDir::Name);
+
+ // QNX PCM devices names start with the pcm prefix and end either with the
+ // 'p' (playback) or 'c' (capture) suffix
+
+ const char modeSuffix = mode == QAudioDevice::Input ? 'c' : 'p';
+
+ QList<QAudioDevice> devices;
+
+ for (const QString &entry : dir.entryList()) {
+ if (entry.startsWith(QStringLiteral("pcm")) && entry.back() == modeSuffix)
+ devices << (new QnxAudioDeviceInfo(entry.toUtf8(), mode))->create();
+ }
+
+ return devices;
+}
+
+QQnxMediaDevices::QQnxMediaDevices()
+ : QPlatformMediaDevices()
+{
+}
+
+QList<QAudioDevice> QQnxMediaDevices::audioInputs() const
+{
+ return ::enumeratePcmDevices(QAudioDevice::Input);
+}
+
+QList<QAudioDevice> QQnxMediaDevices::audioOutputs() const
+{
+ return ::enumeratePcmDevices(QAudioDevice::Output);
+}
+
+QPlatformAudioSource *QQnxMediaDevices::createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ return new QQnxAudioSource(deviceInfo, parent);
+}
+
+QPlatformAudioSink *QQnxMediaDevices::createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ return new QQnxAudioSink(deviceInfo, parent);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/qnx/qqnxmediadevices_p.h b/src/multimedia/qnx/qqnxmediadevices_p.h
new file mode 100644
index 000000000..b8ccf5807
--- /dev/null
+++ b/src/multimedia/qnx/qqnxmediadevices_p.h
@@ -0,0 +1,39 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQNXMEDIADEVICES_H
+#define QQNXMEDIADEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediadevices_p.h>
+#include <qaudio.h>
+#include <qcameradevice.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxMediaDevices : public QPlatformMediaDevices
+{
+public:
+ QQnxMediaDevices();
+
+ QList<QAudioDevice> audioInputs() const override;
+ QList<QAudioDevice> audioOutputs() const override;
+ QPlatformAudioSource *createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+ QPlatformAudioSink *createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/qsymbolsresolveutils.cpp b/src/multimedia/qsymbolsresolveutils.cpp
new file mode 100644
index 000000000..8441ac243
--- /dev/null
+++ b/src/multimedia/qsymbolsresolveutils.cpp
@@ -0,0 +1,79 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qsymbolsresolveutils_p.h"
+
+#include <qdebug.h>
+#include <algorithm>
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcSymbolsResolver, "qt.multimedia.symbolsresolver");
+
+bool SymbolsResolver::isLazyLoadEnabled()
+{
+ static const bool lazyLoad =
+ !static_cast<bool>(qEnvironmentVariableIntValue("QT_INSTANT_LOAD_FFMPEG_STUBS"));
+ return lazyLoad;
+}
+
+SymbolsResolver::SymbolsResolver(const char *libLoggingName, LibraryLoader loader)
+ : m_libLoggingName(libLoggingName)
+{
+ Q_ASSERT(libLoggingName);
+ Q_ASSERT(loader);
+
+ auto library = loader();
+ if (library && library->isLoaded())
+ m_library = std::move(library);
+ else
+ qCWarning(qLcSymbolsResolver) << "Couldn't load" << m_libLoggingName << "library";
+}
+
+SymbolsResolver::SymbolsResolver(const char *libName, const char *version,
+ const char *libLoggingName)
+ : m_libLoggingName(libLoggingName ? libLoggingName : libName)
+{
+ Q_ASSERT(libName);
+ Q_ASSERT(version);
+
+ auto library = std::make_unique<QLibrary>(QString::fromLocal8Bit(libName),
+ QString::fromLocal8Bit(version));
+ if (library->load())
+ m_library = std::move(library);
+ else
+ qCWarning(qLcSymbolsResolver) << "Couldn't load" << m_libLoggingName << "library";
+}
+
+SymbolsResolver::~SymbolsResolver()
+{
+ if (m_library)
+ m_library->unload();
+}
+
+QFunctionPointer SymbolsResolver::initFunction(const char *funcName)
+{
+ if (!m_library)
+ return nullptr;
+ if (auto func = m_library->resolve(funcName))
+ return func;
+
+ qCWarning(qLcSymbolsResolver) << "Couldn't resolve" << m_libLoggingName << "symbol" << funcName;
+ m_library->unload();
+ m_library.reset();
+ return nullptr;
+}
+
+void SymbolsResolver::checkLibrariesLoaded(SymbolsMarker *begin, SymbolsMarker *end)
+{
+ if (m_library) {
+ qCDebug(qLcSymbolsResolver) << m_libLoggingName << "symbols resolved";
+ } else {
+ const auto size = reinterpret_cast<char *>(end) - reinterpret_cast<char *>(begin);
+ memset(begin, 0, size);
+ qCWarning(qLcSymbolsResolver) << "Couldn't resolve" << m_libLoggingName << "symbols";
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/qsymbolsresolveutils_p.h b/src/multimedia/qsymbolsresolveutils_p.h
new file mode 100644
index 000000000..98a552170
--- /dev/null
+++ b/src/multimedia/qsymbolsresolveutils_p.h
@@ -0,0 +1,178 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef Q_SYMBOLSRESOLVEUTILS
+#define Q_SYMBOLSRESOLVEUTILS
+
+#include <QtCore/qlibrary.h>
+#include <QtMultimedia/qtmultimediaexports.h>
+#include <tuple>
+#include <memory>
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+constexpr bool areVersionsEqual(const char lhs[], const char rhs[])
+{
+ int i = 0;
+ for (; lhs[i] && rhs[i]; ++i)
+ if (lhs[i] != rhs[i])
+ return false;
+ return lhs[i] == rhs[i];
+}
+
+constexpr bool areVersionsEqual(const char lhs[], int rhsInt)
+{
+ int lhsInt = 0;
+ for (int i = 0; lhs[i]; ++i) {
+ if (lhs[i] < '0' || lhs[i] > '9')
+ return false;
+
+ lhsInt *= 10;
+ lhsInt += lhs[i] - '0';
+ }
+
+ return lhsInt == rhsInt;
+}
+
+
+template <typename T>
+struct DefaultReturn
+{
+ template <typename... Arg>
+ T operator()(Arg &&...) { return val; }
+ T val;
+};
+
+template <>
+struct DefaultReturn<void>
+{
+ template <typename... Arg>
+ void operator()(Arg &&...) { }
+};
+
+template <typename...>
+struct FuncInfo;
+
+template <typename R, typename... A>
+struct FuncInfo<R(A...)>
+{
+ using Return = R;
+ using Args = std::tuple<A...>;
+};
+
+class Q_MULTIMEDIA_EXPORT SymbolsResolver
+{
+public:
+ using LibraryLoader = std::unique_ptr<QLibrary> (*)();
+ static bool isLazyLoadEnabled();
+
+ ~SymbolsResolver();
+protected:
+ SymbolsResolver(const char *libLoggingName, LibraryLoader loader);
+
+ SymbolsResolver(const char *libName, const char *version = "",
+ const char *libLoggingName = nullptr);
+
+ QFunctionPointer initFunction(const char *name);
+
+ struct SymbolsMarker {};
+ void checkLibrariesLoaded(SymbolsMarker *begin, SymbolsMarker *end);
+
+private:
+ const char *m_libLoggingName;
+ std::unique_ptr<QLibrary> m_library;
+};
+
+
+QT_END_NAMESPACE
+
+// clang-format off
+
+#define CHECK_VERSIONS(Name, NeededSoversion, DetectedVersion) \
+ static_assert(areVersionsEqual(NeededSoversion, DetectedVersion), \
+ "Configuartion error: misleading " Name " versions!")
+
+#define BEGIN_INIT_FUNCS(...) \
+ QT_USE_NAMESPACE \
+ namespace { \
+ class SymbolsResolverImpl : SymbolsResolver { \
+ public: \
+ SymbolsResolverImpl() : SymbolsResolver(__VA_ARGS__) \
+ { checkLibrariesLoaded(&symbolsBegin, &symbolsEnd); } \
+ static const SymbolsResolverImpl& instance() \
+ { static const SymbolsResolverImpl instance; return instance; } \
+ SymbolsMarker symbolsBegin;
+
+#define INIT_FUNC(F) QFunctionPointer F = initFunction(#F);
+
+#define END_INIT_FUNCS() \
+ SymbolsMarker symbolsEnd; \
+ }; \
+ [[maybe_unused]] static const auto *instantResolver = \
+ SymbolsResolver::isLazyLoadEnabled() ? &SymbolsResolverImpl::instance() : nullptr; \
+ }
+
+
+#ifdef Q_EXPORT_STUB_SYMBOLS
+#define EXPORT_FUNC Q_MULTIMEDIA_EXPORT
+#else
+#define EXPORT_FUNC
+#endif
+
+#define DEFINE_FUNC_IMPL(F, Vars, TypesWithVars, ReturnFunc) \
+ using F##_ReturnType = FuncInfo<decltype(F)>::Return; \
+ extern "C" EXPORT_FUNC [[maybe_unused]] F##_ReturnType F(TypesWithVars(F)) { \
+ using F##_Type = F##_ReturnType (*)(TypesWithVars(F)); \
+ const auto f = SymbolsResolverImpl::instance().F; \
+ return f ? (reinterpret_cast<F##_Type>(f))(Vars()) : ReturnFunc(); \
+ }
+
+
+#define VAR(I) a##I
+#define VARS0()
+#define VARS1() VAR(0)
+#define VARS2() VARS1(), VAR(1)
+#define VARS3() VARS2(), VAR(2)
+#define VARS4() VARS3(), VAR(3)
+#define VARS5() VARS4(), VAR(4)
+#define VARS6() VARS5(), VAR(5)
+#define VARS7() VARS6(), VAR(6)
+#define VARS8() VARS7(), VAR(7)
+#define VARS9() VARS8(), VAR(8)
+#define VARS10() VARS9(), VAR(9)
+#define VARS11() VARS10(), VAR(10)
+
+#define TYPE_WITH_VAR(F, I) std::tuple_element_t<I, FuncInfo<decltype(F)>::Args> VAR(I)
+#define TYPES_WITH_VARS0(F)
+#define TYPES_WITH_VARS1(F) TYPE_WITH_VAR(F, 0)
+#define TYPES_WITH_VARS2(F) TYPES_WITH_VARS1(F), TYPE_WITH_VAR(F, 1)
+#define TYPES_WITH_VARS3(F) TYPES_WITH_VARS2(F), TYPE_WITH_VAR(F, 2)
+#define TYPES_WITH_VARS4(F) TYPES_WITH_VARS3(F), TYPE_WITH_VAR(F, 3)
+#define TYPES_WITH_VARS5(F) TYPES_WITH_VARS4(F), TYPE_WITH_VAR(F, 4)
+#define TYPES_WITH_VARS6(F) TYPES_WITH_VARS5(F), TYPE_WITH_VAR(F, 5)
+#define TYPES_WITH_VARS7(F) TYPES_WITH_VARS6(F), TYPE_WITH_VAR(F, 6)
+#define TYPES_WITH_VARS8(F) TYPES_WITH_VARS7(F), TYPE_WITH_VAR(F, 7)
+#define TYPES_WITH_VARS9(F) TYPES_WITH_VARS8(F), TYPE_WITH_VAR(F, 8)
+#define TYPES_WITH_VARS10(F) TYPES_WITH_VARS9(F), TYPE_WITH_VAR(F, 9)
+#define TYPES_WITH_VARS11(F) TYPES_WITH_VARS10(F), TYPE_WITH_VAR(F, 10)
+
+
+#define RET(F, ...) DefaultReturn<FuncInfo<decltype(F)>::Return>{__VA_ARGS__}
+
+#define DEFINE_FUNC(F, ArgsCount, /*Return value*/...) \
+ DEFINE_FUNC_IMPL(F, VARS##ArgsCount, TYPES_WITH_VARS##ArgsCount, RET(F, __VA_ARGS__));
+
+// clang-format on
+
+#endif // Q_SYMBOLSRESOLVEUTILS
diff --git a/src/multimedia/qt_cmdline.cmake b/src/multimedia/qt_cmdline.cmake
new file mode 100644
index 000000000..5aabbbcb7
--- /dev/null
+++ b/src/multimedia/qt_cmdline.cmake
@@ -0,0 +1,8 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_commandline_option(alsa TYPE boolean)
+qt_commandline_option(evr TYPE boolean)
+qt_commandline_option(wmf TYPE boolean)
+qt_commandline_option(gstreamer TYPE optionalString VALUES no yes)
+qt_commandline_option(pulseaudio TYPE boolean)
diff --git a/src/multimedia/qtmultimediaglobal.h b/src/multimedia/qtmultimediaglobal.h
index ae11ed271..6b6200add 100644
--- a/src/multimedia/qtmultimediaglobal.h
+++ b/src/multimedia/qtmultimediaglobal.h
@@ -1,59 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTMULTIMEDIAGLOBAL_H
#define QTMULTIMEDIAGLOBAL_H
#include <QtGui/qtguiglobal.h>
#include <QtMultimedia/qtmultimedia-config.h>
+#include <QtMultimedia/qtmultimediaexports.h>
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_STATIC
-# if defined(QT_BUILD_MULTIMEDIA_LIB)
-# define Q_MULTIMEDIA_EXPORT Q_DECL_EXPORT
-# else
-# define Q_MULTIMEDIA_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define Q_MULTIMEDIA_EXPORT
-#endif
-
-QT_END_NAMESPACE
-#endif // QTQMLGLOBAL_H
+#endif // QTMULTIMEDIAGLOBAL_H
diff --git a/src/multimedia/qtmultimediaglobal_p.h b/src/multimedia/qtmultimediaglobal_p.h
index 797142029..e8ff737a7 100644
--- a/src/multimedia/qtmultimediaglobal_p.h
+++ b/src/multimedia/qtmultimediaglobal_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTMULTIMEDIAGLOBAL_P_H
#define QTMULTIMEDIAGLOBAL_P_H
diff --git a/src/multimedia/recording/qaudiorecorder.cpp b/src/multimedia/recording/qaudiorecorder.cpp
deleted file mode 100644
index 1db5c54a2..000000000
--- a/src/multimedia/recording/qaudiorecorder.cpp
+++ /dev/null
@@ -1,248 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qaudiorecorder.h"
-#include "qaudioinputselectorcontrol.h"
-#include "qmediaobject_p.h"
-#include "qmediarecorder_p.h"
-#include <qmediaservice.h>
-#include <qmediaserviceprovider_p.h>
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmetaobject.h>
-
-#include <qaudioformat.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QAudioRecorder
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_recording
-
- \brief The QAudioRecorder class is used for the recording of audio.
-
- The QAudioRecorder class is a high level media recording class and contains
- the same functionality as \l QMediaRecorder.
-
- \snippet multimedia-snippets/media.cpp Audio recorder
-
- In addition QAudioRecorder provides functionality for selecting the audio input.
-
- \snippet multimedia-snippets/media.cpp Audio recorder inputs
-
- The \l {Audio Recorder Example} shows how to use this class in more detail.
-
- \sa QMediaRecorder, QAudioInputSelectorControl
-*/
-
-class QAudioRecorderObject : public QMediaObject
-{
-public:
- QAudioRecorderObject(QObject *parent, QMediaService *service)
- :QMediaObject(parent, service)
- {
- }
-
- ~QAudioRecorderObject()
- {
- }
-};
-
-class QAudioRecorderPrivate : public QMediaRecorderPrivate
-{
- Q_DECLARE_NON_CONST_PUBLIC(QAudioRecorder)
-
-public:
- void initControls()
- {
- Q_Q(QAudioRecorder);
- audioInputSelector = nullptr;
-
- QMediaService *service = mediaObject ? mediaObject->service() : nullptr;
-
- if (service != nullptr)
- audioInputSelector = qobject_cast<QAudioInputSelectorControl*>(service->requestControl(QAudioInputSelectorControl_iid));
-
- if (audioInputSelector) {
- q->connect(audioInputSelector, SIGNAL(activeInputChanged(QString)),
- SIGNAL(audioInputChanged(QString)));
- q->connect(audioInputSelector, SIGNAL(availableInputsChanged()),
- SIGNAL(availableAudioInputsChanged()));
- }
- }
-
- QAudioRecorderPrivate():
- QMediaRecorderPrivate(),
- provider(nullptr),
- audioInputSelector(nullptr) {}
-
- QMediaServiceProvider *provider;
- QAudioInputSelectorControl *audioInputSelector;
-};
-
-
-
-/*!
- Constructs an audio recorder.
- The \a parent is passed to QMediaObject.
-*/
-
-QAudioRecorder::QAudioRecorder(QObject *parent):
- QMediaRecorder(*new QAudioRecorderPrivate, nullptr, parent)
-{
- Q_D(QAudioRecorder);
- d->provider = QMediaServiceProvider::defaultServiceProvider();
-
- QMediaService *service = d->provider->requestService(Q_MEDIASERVICE_AUDIOSOURCE);
- setMediaObject(new QAudioRecorderObject(this, service));
- d->initControls();
-}
-
-/*!
- Destroys an audio recorder object.
-*/
-
-QAudioRecorder::~QAudioRecorder()
-{
- Q_D(QAudioRecorder);
- QMediaService *service = d->mediaObject ? d->mediaObject->service() : nullptr;
- QMediaObject *mediaObject = d->mediaObject;
- setMediaObject(nullptr);
-
- if (service && d->audioInputSelector)
- service->releaseControl(d->audioInputSelector);
-
- if (d->provider && service)
- d->provider->releaseService(service);
-
- delete mediaObject;
-}
-
-/*!
- Returns a list of available audio inputs
-*/
-
-QStringList QAudioRecorder::audioInputs() const
-{
- Q_D(const QAudioRecorder);
- if (d->audioInputSelector)
- return d->audioInputSelector->availableInputs();
- else
- return QStringList();
-}
-
-/*!
- Returns the readable translated description of the audio input device with \a name.
-*/
-
-QString QAudioRecorder::audioInputDescription(const QString& name) const
-{
- Q_D(const QAudioRecorder);
-
- if (d->audioInputSelector)
- return d->audioInputSelector->inputDescription(name);
- else
- return QString();
-}
-
-/*!
- Returns the default audio input name.
-*/
-
-QString QAudioRecorder::defaultAudioInput() const
-{
- Q_D(const QAudioRecorder);
-
- if (d->audioInputSelector)
- return d->audioInputSelector->defaultInput();
- else
- return QString();
-}
-
-/*!
- \property QAudioRecorder::audioInput
- \brief the active audio input name.
-
-*/
-
-/*!
- Returns the active audio input name.
-*/
-
-QString QAudioRecorder::audioInput() const
-{
- Q_D(const QAudioRecorder);
-
- if (d->audioInputSelector)
- return d->audioInputSelector->activeInput();
- else
- return QString();
-}
-
-/*!
- Set the active audio input to \a name.
-*/
-
-void QAudioRecorder::setAudioInput(const QString& name)
-{
- Q_D(const QAudioRecorder);
-
- if (d->audioInputSelector)
- return d->audioInputSelector->setActiveInput(name);
-}
-
-/*!
- \fn QAudioRecorder::audioInputChanged(const QString& name)
-
- Signal emitted when active audio input changes to \a name.
-*/
-
-/*!
- \fn QAudioRecorder::availableAudioInputsChanged()
-
- Signal is emitted when the available audio inputs change.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qaudiorecorder.cpp"
diff --git a/src/multimedia/recording/qaudiorecorder.h b/src/multimedia/recording/qaudiorecorder.h
deleted file mode 100644
index e57794b40..000000000
--- a/src/multimedia/recording/qaudiorecorder.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIORECORDER_H
-#define QAUDIORECORDER_H
-
-#include <QtMultimedia/qmediarecorder.h>
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmediaencodersettings.h>
-#include <QtMultimedia/qmediaenumdebug.h>
-
-#include <QtCore/qpair.h>
-
-QT_BEGIN_NAMESPACE
-
-class QString;
-class QSize;
-class QAudioFormat;
-QT_END_NAMESPACE
-
-QT_BEGIN_NAMESPACE
-
-class QAudioRecorderPrivate;
-class Q_MULTIMEDIA_EXPORT QAudioRecorder : public QMediaRecorder
-{
- Q_OBJECT
- Q_PROPERTY(QString audioInput READ audioInput WRITE setAudioInput NOTIFY audioInputChanged)
-public:
- explicit QAudioRecorder(QObject *parent = nullptr);
- ~QAudioRecorder();
-
- QStringList audioInputs() const;
- QString defaultAudioInput() const;
- QString audioInputDescription(const QString& name) const;
-
- QString audioInput() const;
-
-public Q_SLOTS:
- void setAudioInput(const QString& name);
-
-Q_SIGNALS:
- void audioInputChanged(const QString& name);
- void availableAudioInputsChanged();
-
-private:
- Q_DISABLE_COPY(QAudioRecorder)
- Q_DECLARE_PRIVATE(QAudioRecorder)
-};
-
-QT_END_NAMESPACE
-
-#endif // QAUDIORECORDER_H
diff --git a/src/multimedia/recording/qcapturablewindow.cpp b/src/multimedia/recording/qcapturablewindow.cpp
new file mode 100644
index 000000000..34b6a1f5d
--- /dev/null
+++ b/src/multimedia/recording/qcapturablewindow.cpp
@@ -0,0 +1,156 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qcapturablewindow.h"
+#include "qcapturablewindow_p.h"
+#include "qplatformmediaintegration_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QCapturableWindowPrivate)
+
+/*!
+ \class QCapturableWindow
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_video
+ \since 6.6
+
+ \brief Used for getting the basic information of a capturable window.
+
+ The class contains a set of window information, except the method
+ QCapturableWindow::isValid which pulls the current state
+ whenever it's called.
+
+ \sa QWindowCapture
+*/
+/*!
+ \qmlvaluetype CapturableWindow
+ \instantiates QCapturableWindow
+ \brief The CapturableWindow type is used getting basic
+ of a window that is available for capturing via WindowCapture.
+
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+ \ingroup multimedia_video_qml
+ \since 6.6
+
+ The class contains a dump of window information, except the property
+ 'isValid' which pulls the actual window state every time.
+
+ \sa WindowCapture
+*/
+
+/*!
+ \fn QCapturableWindow::QCapturableWindow(QCapturableWindow &&other)
+
+ Constructs a QCapturableWindow by moving from \a other.
+*/
+
+/*!
+ \fn void QCapturableWindow::swap(QCapturableWindow &other) noexcept
+
+ Swaps the current window information with \a other.
+*/
+
+/*!
+ \fn QCapturableWindow &QCapturableWindow::operator=(QCapturableWindow &&other)
+
+ Moves \a other into this QCapturableWindow.
+*/
+
+/*!
+ Constructs a null capturable window information that doesn't refer to any window.
+*/
+QCapturableWindow::QCapturableWindow() = default;
+
+/*!
+ Destroys the window information.
+ */
+QCapturableWindow::~QCapturableWindow() = default;
+
+/*!
+ Construct a new window information using \a other QCapturableWindow.
+*/
+QCapturableWindow::QCapturableWindow(const QCapturableWindow &other) = default;
+
+/*!
+ Assigns the \a other window information to this QCapturableWindow.
+*/
+QCapturableWindow& QCapturableWindow::operator=(const QCapturableWindow &other) = default;
+
+/*!
+ \fn bool QCapturableWindow::operator==(const QCapturableWindow &lhs, const QCapturableWindow &rhs)
+
+ Returns \c true if window information \a lhs and \a rhs refer to the same window,
+ otherwise returns \c false.
+*/
+
+/*!
+ \fn bool QCapturableWindow::operator!=(const QCapturableWindow &lhs, const QCapturableWindow &rhs)
+
+ Returns \c true if window information \a lhs and \a rhs refer to different windows,
+ otherwise returns \c false.
+*/
+bool operator==(const QCapturableWindow &lhs, const QCapturableWindow &rhs) noexcept
+{
+ return lhs.d == rhs.d || (lhs.d && rhs.d && lhs.d->id == rhs.d->id);
+}
+
+/*!
+ \qmlproperty string QtMultimedia::CapturableWindow::isValid
+
+ This property identifies whether a window information is valid.
+
+ An invalid window information refers to non-existing window or doesn't refer to any one.
+*/
+
+/*!
+ Identifies whether a window information is valid.
+
+ An invalid window information refers to non-existing window or doesn't refer to any one.
+
+ Returns true if the window is valid, and false if it is not.
+*/
+bool QCapturableWindow::isValid() const
+{
+ return d && QPlatformMediaIntegration::instance()->isCapturableWindowValid(*d);
+}
+
+/*!
+ \qmlproperty string QtMultimedia::CapturableWindow::description
+
+ This property holds the description of the reffered window.
+*/
+
+/*!
+ Returns a description of the window. In most cases it represents the window title.
+*/
+QString QCapturableWindow::description() const
+{
+ if (!d)
+ return {};
+
+ if (d->description.isEmpty() && d->id)
+ return QLatin1String("Window 0x") + QString::number(d->id, 16);
+
+ return d->description;
+}
+
+QCapturableWindow::QCapturableWindow(QCapturableWindowPrivate *capturablePrivate)
+ : d(capturablePrivate)
+{
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug dbg, const QCapturableWindow &window)
+{
+ dbg << QStringLiteral("Capturable window '%1'").arg(window.description());
+ return dbg;
+}
+#endif
+
+
+QT_END_NAMESPACE
+
+#include "moc_qcapturablewindow.cpp"
diff --git a/src/multimedia/recording/qcapturablewindow.h b/src/multimedia/recording/qcapturablewindow.h
new file mode 100644
index 000000000..f18dbf72d
--- /dev/null
+++ b/src/multimedia/recording/qcapturablewindow.h
@@ -0,0 +1,66 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCAPTURABLEWINDOW_H
+#define QCAPTURABLEWINDOW_H
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtCore/qmetatype.h>
+#include <QtCore/qshareddata.h>
+
+QT_BEGIN_NAMESPACE
+
+class QCapturableWindowPrivate;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QCapturableWindowPrivate, Q_MULTIMEDIA_EXPORT)
+
+class QMediaCaptureSession;
+class QWindowCapturePrivate;
+
+class QCapturableWindow
+{
+ Q_GADGET_EXPORT(Q_MULTIMEDIA_EXPORT)
+ Q_PROPERTY(QString description READ description CONSTANT)
+ Q_PROPERTY(bool isValid READ isValid CONSTANT)
+public:
+ Q_MULTIMEDIA_EXPORT QCapturableWindow();
+
+ Q_MULTIMEDIA_EXPORT ~QCapturableWindow();
+
+ Q_MULTIMEDIA_EXPORT QCapturableWindow(const QCapturableWindow &other);
+
+ QCapturableWindow(QCapturableWindow &&other) noexcept = default;
+
+ Q_MULTIMEDIA_EXPORT QCapturableWindow& operator=(const QCapturableWindow &other);
+
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QCapturableWindow);
+
+ void swap(QCapturableWindow &other) noexcept
+ { d.swap(other.d); }
+
+ Q_MULTIMEDIA_EXPORT friend bool operator==(const QCapturableWindow &lhs, const QCapturableWindow &rhs) noexcept;
+
+ friend bool operator!=(const QCapturableWindow &lhs, const QCapturableWindow &rhs) noexcept
+ { return !(lhs == rhs); }
+
+ Q_MULTIMEDIA_EXPORT bool isValid() const;
+
+ Q_MULTIMEDIA_EXPORT QString description() const;
+
+#ifndef QT_NO_DEBUG_STREAM
+ Q_MULTIMEDIA_EXPORT friend QDebug operator<<(QDebug, const QCapturableWindow &);
+#endif
+
+private:
+ Q_MULTIMEDIA_EXPORT QCapturableWindow(QCapturableWindowPrivate *capturablePrivate);
+ friend class QCapturableWindowPrivate;
+
+ QExplicitlySharedDataPointer<QCapturableWindowPrivate> d;
+};
+
+Q_DECLARE_SHARED(QCapturableWindow)
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QCapturableWindow)
+
+#endif // QCAPTURABLEWINDOW_H
diff --git a/src/multimedia/recording/qcapturablewindow_p.h b/src/multimedia/recording/qcapturablewindow_p.h
new file mode 100644
index 000000000..9cb186a77
--- /dev/null
+++ b/src/multimedia/recording/qcapturablewindow_p.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCAPTURABLEWINDOW_P_H
+#define QCAPTURABLEWINDOW_P_H
+
+#include <QtGui/qwindowdefs.h>
+#include <QtCore/QSharedData>
+#include <QtMultimedia/qcapturablewindow.h>
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QCapturableWindowPrivate : public QSharedData {
+public:
+ using Id = size_t;
+
+ QString description;
+ Id id = 0;
+
+ static const QCapturableWindowPrivate *handle(const QCapturableWindow &window)
+ {
+ return window.d.get();
+ }
+
+ QCapturableWindow create() { return QCapturableWindow(this); }
+};
+
+QT_END_NAMESPACE
+
+#endif // QCAPTURABLEWINDOW_P_H
diff --git a/src/multimedia/recording/qmediacapturesession.cpp b/src/multimedia/recording/qmediacapturesession.cpp
new file mode 100644
index 000000000..9df09acef
--- /dev/null
+++ b/src/multimedia/recording/qmediacapturesession.cpp
@@ -0,0 +1,688 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qmediacapturesession.h"
+#include "qmediacapturesession_p.h"
+#include "qaudiodevice.h"
+#include "qcamera.h"
+#include "qmediarecorder.h"
+#include "qimagecapture.h"
+#include "qvideosink.h"
+#include "qscreencapture.h"
+#include "qwindowcapture.h"
+#include "qvideoframeinput.h"
+
+#include "qplatformmediaintegration_p.h"
+#include "qplatformmediacapture_p.h"
+#include "qaudioinput.h"
+#include "qaudiobufferinput.h"
+#include "qaudiooutput.h"
+
+QT_BEGIN_NAMESPACE
+
+void QMediaCaptureSessionPrivate::setVideoSink(QVideoSink *sink)
+{
+ Q_Q(QMediaCaptureSession);
+
+ if (sink == videoSink)
+ return;
+ if (videoSink)
+ videoSink->setSource(nullptr);
+ videoSink = sink;
+ if (sink)
+ sink->setSource(q);
+ if (captureSession)
+ captureSession->setVideoPreview(sink);
+ emit q->videoOutputChanged();
+}
+
+/*!
+ \class QMediaCaptureSession
+
+ \brief The QMediaCaptureSession class allows capturing of audio and video content.
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_video
+ \ingroup multimedia_audio
+
+ The QMediaCaptureSession is the central class that manages capturing of media on the local
+ device.
+
+ You can connect a video input to QMediaCaptureSession using setCamera(),
+ setScreenCapture(), setWindowCapture() or setVideoFrameInput().
+ A preview of the captured media can be seen by setting a QVideoWidget or QGraphicsVideoItem
+ using setVideoOutput().
+
+ You can connect a microphone to QMediaCaptureSession using setAudioInput(), or set your
+ custom audio input using setAudioBufferInput().
+ The captured sound can be heard by routing the audio to an output device using setAudioOutput().
+
+ You can capture still images from a camera by setting a QImageCapture object on the capture
+ session, and record audio/video using a QMediaRecorder.
+
+ \sa QCamera, QAudioDevice, QMediaRecorder, QImageCapture, QScreenCapture, QWindowCapture,
+ QVideoFrameInput, QMediaRecorder, QGraphicsVideoItem
+*/
+
+/*!
+ \qmltype CaptureSession
+ \since 6.2
+ \instantiates QMediaCaptureSession
+ \brief Allows capturing of audio and video content.
+
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+ \ingroup multimedia_audio_qml
+ \ingroup multimedia_video_qml
+
+ This is the central type that manages capturing of media on the local device.
+
+ Connect a camera and a microphone to a CaptureSession by assigning Camera
+ and AudioInput objects to the relevant properties.
+
+ Capture a screen by connecting a ScreenCapture object to
+ the screenCapture property.
+
+ Capture a window by connecting a WindowCapture object to
+ the windowCapture property.
+
+ Enable a preview of the captured media by assigning a VideoOutput element to
+ the videoOutput property.
+
+ Route audio to an output device by assigning an AudioOutput object
+ to the audioOutput property.
+
+ Capture still images from a camera by assigning an ImageCapture to the
+ imageCapture property.
+
+ Record audio/video by assigning a MediaRecorder to the recorder property.
+
+\qml
+ CaptureSession {
+ id: captureSession
+ camera: Camera {
+ id: camera
+ }
+ imageCapture: ImageCapture {
+ id: imageCapture
+ }
+
+ recorder: MediaRecorder {
+ id: recorder
+ }
+ videoOutput: preview
+ }
+\endqml
+
+ \sa Camera, MediaDevices, MediaRecorder, ImageCapture, ScreenCapture, WindowCapture, AudioInput, VideoOutput
+*/
+
+/*!
+ Creates a session for media capture from the \a parent object.
+ */
+QMediaCaptureSession::QMediaCaptureSession(QObject *parent)
+ : QObject{ *new QMediaCaptureSessionPrivate, parent }
+{
+ QT6_ONLY(Q_UNUSED(unused))
+
+ Q_D(QMediaCaptureSession);
+
+ auto maybeCaptureSession = QPlatformMediaIntegration::instance()->createCaptureSession();
+ if (maybeCaptureSession) {
+ d->captureSession.reset(maybeCaptureSession.value());
+ d->captureSession->setCaptureSession(this);
+ } else {
+ qWarning() << "Failed to initialize QMediaCaptureSession" << maybeCaptureSession.error();
+ }
+}
+
+/*!
+ Destroys the session.
+ */
+QMediaCaptureSession::~QMediaCaptureSession()
+{
+ Q_D(QMediaCaptureSession);
+
+ setCamera(nullptr);
+ setRecorder(nullptr);
+ setImageCapture(nullptr);
+ setScreenCapture(nullptr);
+ setWindowCapture(nullptr);
+ setVideoFrameInput(nullptr);
+ setAudioBufferInput(nullptr);
+ setAudioInput(nullptr);
+ setAudioOutput(nullptr);
+ d->setVideoSink(nullptr);
+ d->captureSession.reset();
+}
+/*!
+ \qmlproperty AudioInput QtMultimedia::CaptureSession::audioInput
+
+ This property holds the audio input that is being used to capture audio.
+*/
+
+/*!
+ \property QMediaCaptureSession::audioInput
+
+ Returns the device that is being used to capture audio.
+*/
+QAudioInput *QMediaCaptureSession::audioInput() const
+{
+ Q_D(const QMediaCaptureSession);
+ return d->audioInput;
+}
+
+/*!
+ Sets the audio input device to \a input. If setting it to an empty
+ QAudioDevice the capture session will use the default input as
+ defined by the operating system.
+*/
+void QMediaCaptureSession::setAudioInput(QAudioInput *input)
+{
+ Q_D(QMediaCaptureSession);
+
+ QAudioInput *oldInput = d->audioInput;
+ if (oldInput == input)
+ return;
+
+ // To avoid double emit of audioInputChanged
+ // from recursive setAudioInput(nullptr) call.
+ d->audioInput = nullptr;
+
+ if (d->captureSession)
+ d->captureSession->setAudioInput(nullptr);
+ if (oldInput)
+ oldInput->setDisconnectFunction({});
+ if (input) {
+ input->setDisconnectFunction([this](){ setAudioInput(nullptr); });
+ if (d->captureSession)
+ d->captureSession->setAudioInput(input->handle());
+ }
+ d->audioInput = input;
+ emit audioInputChanged();
+}
+
+/*!
+ \property QMediaCaptureSession::audioBufferInput
+ \since 6.8
+
+ \brief The object used to send custom audio buffers to \l QMediaRecorder.
+*/
+QAudioBufferInput *QMediaCaptureSession::audioBufferInput() const
+{
+ Q_D(const QMediaCaptureSession);
+
+ return d->audioBufferInput;
+}
+
+void QMediaCaptureSession::setAudioBufferInput(QAudioBufferInput *input)
+{
+ Q_D(QMediaCaptureSession);
+
+ // TODO: come up with an unification of the captures setup
+ QAudioBufferInput *oldInput = d->audioBufferInput;
+ if (oldInput == input)
+ return;
+ d->audioBufferInput = input;
+ if (d->captureSession)
+ d->captureSession->setAudioBufferInput(nullptr);
+ if (oldInput) {
+ if (oldInput->captureSession() && oldInput->captureSession() != this)
+ oldInput->captureSession()->setAudioBufferInput(nullptr);
+ oldInput->setCaptureSession(nullptr);
+ }
+ if (input) {
+ if (input->captureSession())
+ input->captureSession()->setAudioBufferInput(nullptr);
+ if (d->captureSession)
+ d->captureSession->setAudioBufferInput(input->platformAudioBufferInput());
+ input->setCaptureSession(this);
+ }
+ emit audioBufferInputChanged();
+}
+
+/*!
+ \qmlproperty Camera QtMultimedia::CaptureSession::camera
+
+ \brief The camera used to capture video.
+
+ Record video or take images by adding a camera to the capture session using
+ this property.
+*/
+
+/*!
+ \property QMediaCaptureSession::camera
+
+ \brief The camera used to capture video.
+
+ Record video or take images by adding a camera to the capture session
+ using this property.
+*/
+QCamera *QMediaCaptureSession::camera() const
+{
+ Q_D(const QMediaCaptureSession);
+
+ return d->camera;
+}
+
+void QMediaCaptureSession::setCamera(QCamera *camera)
+{
+ Q_D(QMediaCaptureSession);
+
+ // TODO: come up with an unification of the captures setup
+ QCamera *oldCamera = d->camera;
+ if (oldCamera == camera)
+ return;
+ d->camera = camera;
+ if (d->captureSession)
+ d->captureSession->setCamera(nullptr);
+ if (oldCamera) {
+ if (oldCamera->captureSession() && oldCamera->captureSession() != this)
+ oldCamera->captureSession()->setCamera(nullptr);
+ oldCamera->setCaptureSession(nullptr);
+ }
+ if (camera) {
+ if (camera->captureSession())
+ camera->captureSession()->setCamera(nullptr);
+ if (d->captureSession)
+ d->captureSession->setCamera(camera->platformCamera());
+ camera->setCaptureSession(this);
+ }
+ emit cameraChanged();
+}
+
+/*!
+ \qmlproperty ScreenCapture QtMultimedia::CaptureSession::screenCapture
+ \since 6.5
+
+ \brief The object used to capture a screen.
+
+ Record a screen by adding a screen capture objet
+ to the capture session using this property.
+*/
+
+/*!
+ \property QMediaCaptureSession::screenCapture
+ \since 6.5
+
+ \brief The object used to capture a screen.
+
+ Record a screen by adding a screen capture object
+ to the capture session using this property.
+*/
+QScreenCapture *QMediaCaptureSession::screenCapture()
+{
+ Q_D(QMediaCaptureSession);
+
+ return d->screenCapture;
+}
+
+void QMediaCaptureSession::setScreenCapture(QScreenCapture *screenCapture)
+{
+ Q_D(QMediaCaptureSession);
+
+ // TODO: come up with an unification of the captures setup
+ QScreenCapture *oldScreenCapture = d->screenCapture;
+ if (oldScreenCapture == screenCapture)
+ return;
+ d->screenCapture = screenCapture;
+ if (d->captureSession)
+ d->captureSession->setScreenCapture(nullptr);
+ if (oldScreenCapture) {
+ if (oldScreenCapture->captureSession() && oldScreenCapture->captureSession() != this)
+ oldScreenCapture->captureSession()->setScreenCapture(nullptr);
+ oldScreenCapture->setCaptureSession(nullptr);
+ }
+ if (screenCapture) {
+ if (screenCapture->captureSession())
+ screenCapture->captureSession()->setScreenCapture(nullptr);
+ if (d->captureSession)
+ d->captureSession->setScreenCapture(screenCapture->platformScreenCapture());
+ screenCapture->setCaptureSession(this);
+ }
+ emit screenCaptureChanged();
+}
+
+/*!
+ \qmlproperty WindowCapture QtMultimedia::CaptureSession::windowCapture
+ \since 6.6
+
+ \brief The object used to capture a window.
+
+ Record a window by adding a window capture object
+ to the capture session using this property.
+*/
+
+/*!
+ \property QMediaCaptureSession::windowCapture
+ \since 6.6
+
+ \brief The object used to capture a window.
+
+ Record a window by adding a window capture objet
+ to the capture session using this property.
+*/
+QWindowCapture *QMediaCaptureSession::windowCapture()
+{
+ Q_D(QMediaCaptureSession);
+ return d->windowCapture;
+}
+
+void QMediaCaptureSession::setWindowCapture(QWindowCapture *windowCapture)
+{
+ Q_D(QMediaCaptureSession);
+
+ // TODO: come up with an unification of the captures setup
+ QWindowCapture *oldCapture = d->windowCapture;
+ if (oldCapture == windowCapture)
+ return;
+ d->windowCapture = windowCapture;
+ if (d->captureSession)
+ d->captureSession->setWindowCapture(nullptr);
+ if (oldCapture) {
+ if (oldCapture->captureSession() && oldCapture->captureSession() != this)
+ oldCapture->captureSession()->setWindowCapture(nullptr);
+ oldCapture->setCaptureSession(nullptr);
+ }
+ if (windowCapture) {
+ if (windowCapture->captureSession())
+ windowCapture->captureSession()->setWindowCapture(nullptr);
+ if (d->captureSession)
+ d->captureSession->setWindowCapture(windowCapture->platformWindowCapture());
+ windowCapture->setCaptureSession(this);
+ }
+ emit windowCaptureChanged();
+}
+
+/*!
+ \property QMediaCaptureSession::videoFrameInput
+ \since 6.8
+
+ \brief The object used to send custom video frames to
+ \l QMediaRecorder or a video output.
+*/
+QVideoFrameInput *QMediaCaptureSession::videoFrameInput() const
+{
+ Q_D(const QMediaCaptureSession);
+ return d->videoFrameInput;
+}
+
+void QMediaCaptureSession::setVideoFrameInput(QVideoFrameInput *input)
+{
+ Q_D(QMediaCaptureSession);
+ // TODO: come up with an unification of the captures setup
+ QVideoFrameInput *oldInput = d->videoFrameInput;
+ if (oldInput == input)
+ return;
+ d->videoFrameInput = input;
+ if (d->captureSession)
+ d->captureSession->setVideoFrameInput(nullptr);
+ if (oldInput) {
+ if (oldInput->captureSession() && oldInput->captureSession() != this)
+ oldInput->captureSession()->setVideoFrameInput(nullptr);
+ oldInput->setCaptureSession(nullptr);
+ }
+ if (input) {
+ if (input->captureSession())
+ input->captureSession()->setVideoFrameInput(nullptr);
+ if (d->captureSession)
+ d->captureSession->setVideoFrameInput(input->platformVideoFrameInput());
+ input->setCaptureSession(this);
+ }
+ emit videoFrameInputChanged();
+}
+
+/*!
+ \qmlproperty ImageCapture QtMultimedia::CaptureSession::imageCapture
+
+ \brief The object used to capture still images.
+
+ Add an ImageCapture interface to the capture session to enable
+ capturing of still images from the camera.
+*/
+/*!
+ \property QMediaCaptureSession::imageCapture
+
+ \brief the object used to capture still images.
+
+ Add a QImageCapture object to the capture session to enable
+ capturing of still images from the camera.
+*/
+QImageCapture *QMediaCaptureSession::imageCapture()
+{
+ Q_D(QMediaCaptureSession);
+
+ return d->imageCapture;
+}
+
+void QMediaCaptureSession::setImageCapture(QImageCapture *imageCapture)
+{
+ Q_D(QMediaCaptureSession);
+
+ // TODO: come up with an unification of the captures setup
+ QImageCapture *oldImageCapture = d->imageCapture;
+ if (oldImageCapture == imageCapture)
+ return;
+ d->imageCapture = imageCapture;
+ if (d->captureSession)
+ d->captureSession->setImageCapture(nullptr);
+ if (oldImageCapture) {
+ if (oldImageCapture->captureSession() && oldImageCapture->captureSession() != this)
+ oldImageCapture->captureSession()->setImageCapture(nullptr);
+ oldImageCapture->setCaptureSession(nullptr);
+ }
+ if (imageCapture) {
+ if (imageCapture->captureSession())
+ imageCapture->captureSession()->setImageCapture(nullptr);
+ if (d->captureSession)
+ d->captureSession->setImageCapture(imageCapture->platformImageCapture());
+ imageCapture->setCaptureSession(this);
+ }
+ emit imageCaptureChanged();
+}
+/*!
+ \qmlproperty MediaRecorder QtMultimedia::CaptureSession::recorder
+
+ \brief The recorder object used to capture audio/video.
+
+ Add a MediaRcorder object to the capture session to enable
+ recording of audio and/or video from the capture session.
+*/
+/*!
+ \property QMediaCaptureSession::recorder
+
+ \brief The recorder object used to capture audio/video.
+
+ Add a QMediaRecorder object to the capture session to enable
+ recording of audio and/or video from the capture session.
+*/
+
+QMediaRecorder *QMediaCaptureSession::recorder()
+{
+ Q_D(QMediaCaptureSession);
+ return d->recorder;
+}
+
+void QMediaCaptureSession::setRecorder(QMediaRecorder *recorder)
+{
+ Q_D(QMediaCaptureSession);
+ QMediaRecorder *oldRecorder = d->recorder;
+ if (oldRecorder == recorder)
+ return;
+ d->recorder = recorder;
+ if (d->captureSession)
+ d->captureSession->setMediaRecorder(nullptr);
+ if (oldRecorder) {
+ if (oldRecorder->captureSession() && oldRecorder->captureSession() != this)
+ oldRecorder->captureSession()->setRecorder(nullptr);
+ oldRecorder->setCaptureSession(nullptr);
+ }
+ if (recorder) {
+ if (recorder->captureSession())
+ recorder->captureSession()->setRecorder(nullptr);
+ if (d->captureSession)
+ d->captureSession->setMediaRecorder(recorder->platformRecoder());
+ recorder->setCaptureSession(this);
+ }
+ emit recorderChanged();
+}
+/*!
+ \qmlproperty VideoOutput QtMultimedia::CaptureSession::videoOutput
+
+ \brief The VideoOutput that is the video preview for the capture session.
+
+ A VideoOutput based preview is expected to have an invokable videoSink()
+ method that returns a QVideoSink.
+
+ The previously set preview is detached.
+
+*/
+/*!
+ \property QMediaCaptureSession::videoOutput
+
+ Returns the video output for the session.
+*/
+QObject *QMediaCaptureSession::videoOutput() const
+{
+ Q_D(const QMediaCaptureSession);
+ return d->videoOutput;
+}
+/*!
+ Sets a QObject, (\a output), to a video preview for the capture session.
+
+ A QObject based preview is expected to have an invokable videoSink()
+ method that returns a QVideoSink.
+
+ The previously set preview is detached.
+*/
+void QMediaCaptureSession::setVideoOutput(QObject *output)
+{
+ Q_D(QMediaCaptureSession);
+ if (d->videoOutput == output)
+ return;
+ QVideoSink *sink = qobject_cast<QVideoSink *>(output);
+ if (!sink && output) {
+ auto *mo = output->metaObject();
+ mo->invokeMethod(output, "videoSink", Q_RETURN_ARG(QVideoSink *, sink));
+ }
+ d->videoOutput = output;
+ d->setVideoSink(sink);
+}
+
+/*!
+ Sets a QVideoSink, (\a sink), to a video preview for the capture session.
+
+ A QObject based preview is expected to have an invokable videoSink()
+ method that returns a QVideoSink.
+
+ The previously set preview is detached.
+*/
+void QMediaCaptureSession::setVideoSink(QVideoSink *sink)
+{
+ Q_D(QMediaCaptureSession);
+ d->videoOutput = nullptr;
+ d->setVideoSink(sink);
+}
+
+/*!
+ Returns the QVideoSink for the session.
+*/
+QVideoSink *QMediaCaptureSession::videoSink() const
+{
+ Q_D(const QMediaCaptureSession);
+ return d->videoSink;
+}
+/*!
+ Sets the audio output device to \a{output}.
+
+ Setting an audio output device enables audio routing from an audio input device.
+*/
+void QMediaCaptureSession::setAudioOutput(QAudioOutput *output)
+{
+ Q_D(QMediaCaptureSession);
+
+ QAudioOutput *oldOutput = d->audioOutput;
+ if (oldOutput == output)
+ return;
+
+ // We don't want to end up with signal emitted
+ // twice (from recursive call setAudioInput(nullptr)
+ // from oldOutput->setDisconnectFunction():
+ d->audioOutput = nullptr;
+
+ if (d->captureSession)
+ d->captureSession->setAudioOutput(nullptr);
+ if (oldOutput)
+ oldOutput->setDisconnectFunction({});
+ if (output) {
+ output->setDisconnectFunction([this](){ setAudioOutput(nullptr); });
+ if (d->captureSession)
+ d->captureSession->setAudioOutput(output->handle());
+ }
+ d->audioOutput = output;
+ emit audioOutputChanged();
+}
+/*!
+ \qmlproperty AudioOutput QtMultimedia::CaptureSession::audioOutput
+ \brief The audio output device for the capture session.
+
+ Add an AudioOutput device to the capture session to enable
+ audio routing from an AudioInput device.
+*/
+/*!
+ \property QMediaCaptureSession::audioOutput
+
+ Returns the audio output for the session.
+*/
+QAudioOutput *QMediaCaptureSession::audioOutput() const
+{
+ Q_D(const QMediaCaptureSession);
+ return d->audioOutput;
+}
+
+/*!
+ \internal
+*/
+QPlatformMediaCaptureSession *QMediaCaptureSession::platformSession() const
+{
+ Q_D(const QMediaCaptureSession);
+ return d->captureSession.get();
+}
+/*!
+ \qmlsignal QtMultimedia::CaptureSession::audioInputChanged()
+ This signal is emitted when an audio input has changed.
+ \sa CaptureSession::audioInput
+*/
+
+/*!
+ \qmlsignal QtMultimedia::CaptureSession::cameraChanged()
+ This signal is emitted when the selected camera has changed.
+ \sa CaptureSession::camera
+*/
+
+/*!
+ \qmlsignal QtMultimedia::CaptureSession::imageCaptureChanged()
+ This signal is emitted when the selected interface has changed.
+ \sa CaptureSession::camera
+*/
+
+/*!
+ \qmlsignal QtMultimedia::CaptureSession::recorderChanged()
+ This signal is emitted when the selected recorder has changed.
+ \sa CaptureSession::recorder
+*/
+
+/*!
+ \qmlsignal QtMultimedia::CaptureSession::videoOutputChanged()
+ This signal is emitted when the selected video output has changed.
+ \sa CaptureSession::videoOutput
+*/
+
+/*!
+ \qmlsignal QtMultimedia::CaptureSession::audioOutputChanged()
+ This signal is emitted when the selected audio output has changed.
+ \sa CaptureSession::audioOutput
+*/
+QT_END_NAMESPACE
+
+#include "moc_qmediacapturesession.cpp"
diff --git a/src/multimedia/recording/qmediacapturesession.h b/src/multimedia/recording/qmediacapturesession.h
new file mode 100644
index 000000000..219c382d1
--- /dev/null
+++ b/src/multimedia/recording/qmediacapturesession.h
@@ -0,0 +1,106 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QMEDIACAPTURESESSION_H
+#define QMEDIACAPTURESESSION_H
+
+#include <QtCore/qobject.h>
+#include <QtMultimedia/qtmultimediaglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+class QCamera;
+class QAudioInput;
+class QAudioBufferInput;
+class QAudioOutput;
+class QCameraDevice;
+class QImageCapture;
+class QMediaRecorder;
+class QPlatformMediaCaptureSession;
+class QVideoSink;
+class QScreenCapture;
+class QWindowCapture;
+class QVideoFrameInput;
+
+class QMediaCaptureSessionPrivate;
+class Q_MULTIMEDIA_EXPORT QMediaCaptureSession : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QAudioInput *audioInput READ audioInput WRITE setAudioInput NOTIFY audioInputChanged)
+ Q_PROPERTY(QAudioBufferInput *audioBufferInput READ audioBufferInput WRITE setAudioBufferInput
+ NOTIFY audioBufferInputChanged)
+ Q_PROPERTY(QAudioOutput *audioOutput READ audioOutput WRITE setAudioOutput NOTIFY audioOutputChanged)
+ Q_PROPERTY(QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged)
+ Q_PROPERTY(
+ QScreenCapture *screenCapture READ screenCapture WRITE setScreenCapture NOTIFY screenCaptureChanged)
+ Q_PROPERTY(
+ QWindowCapture *windowCapture READ windowCapture WRITE setWindowCapture NOTIFY windowCaptureChanged)
+ Q_PROPERTY(QVideoFrameInput *videoFrameInput READ videoFrameInput WRITE setVideoFrameInput
+ NOTIFY videoFrameInputChanged)
+ Q_PROPERTY(QImageCapture *imageCapture READ imageCapture WRITE setImageCapture NOTIFY imageCaptureChanged)
+ Q_PROPERTY(QMediaRecorder *recorder READ recorder WRITE setRecorder NOTIFY recorderChanged)
+ Q_PROPERTY(QObject *videoOutput READ videoOutput WRITE setVideoOutput NOTIFY videoOutputChanged)
+public:
+ explicit QMediaCaptureSession(QObject *parent = nullptr);
+ ~QMediaCaptureSession();
+
+ QAudioInput *audioInput() const;
+ void setAudioInput(QAudioInput *input);
+
+ QAudioBufferInput *audioBufferInput() const;
+ void setAudioBufferInput(QAudioBufferInput *input);
+
+ QCamera *camera() const;
+ void setCamera(QCamera *camera);
+
+ QImageCapture *imageCapture();
+ void setImageCapture(QImageCapture *imageCapture);
+
+ QScreenCapture *screenCapture();
+ void setScreenCapture(QScreenCapture *screenCapture);
+
+ QWindowCapture *windowCapture();
+ void setWindowCapture(QWindowCapture *windowCapture);
+
+ QVideoFrameInput *videoFrameInput() const;
+ void setVideoFrameInput(QVideoFrameInput *input);
+
+ QMediaRecorder *recorder();
+ void setRecorder(QMediaRecorder *recorder);
+
+ void setVideoOutput(QObject *output);
+ QObject *videoOutput() const;
+
+ void setVideoSink(QVideoSink *sink);
+ QVideoSink *videoSink() const;
+
+ void setAudioOutput(QAudioOutput *output);
+ QAudioOutput *audioOutput() const;
+
+ QPlatformMediaCaptureSession *platformSession() const;
+
+Q_SIGNALS:
+ void audioInputChanged();
+ void audioBufferInputChanged();
+ void cameraChanged();
+ void screenCaptureChanged();
+ void windowCaptureChanged();
+ void videoFrameInputChanged();
+ void imageCaptureChanged();
+ void recorderChanged();
+ void videoOutputChanged();
+ void audioOutputChanged();
+
+private:
+ friend class QPlatformMediaCaptureSession;
+
+ // ### Qt7: remove unused member
+ QT6_ONLY(void *unused = nullptr;) // for ABI compatibility
+
+ Q_DISABLE_COPY(QMediaCaptureSession)
+ Q_DECLARE_PRIVATE(QMediaCaptureSession)
+};
+
+QT_END_NAMESPACE
+
+#endif // QMEDIACAPTURESESSION_H
diff --git a/src/multimedia/recording/qmediacapturesession_p.h b/src/multimedia/recording/qmediacapturesession_p.h
new file mode 100644
index 000000000..cba222993
--- /dev/null
+++ b/src/multimedia/recording/qmediacapturesession_p.h
@@ -0,0 +1,53 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QMEDIACAPTURESESSION_P_H
+#define QMEDIACAPTURESESSION_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qmediacapturesession.h>
+
+#include <QtCore/qpointer.h>
+#include <QtCore/private/qobject_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMediaCaptureSessionPrivate : public QObjectPrivate
+{
+public:
+ static QMediaCaptureSessionPrivate *get(QMediaCaptureSession *session)
+ {
+ return reinterpret_cast<QMediaCaptureSessionPrivate *>(QObjectPrivate::get(session));
+ }
+
+ Q_DECLARE_PUBLIC(QMediaCaptureSession)
+
+ std::unique_ptr<QPlatformMediaCaptureSession> captureSession;
+ QAudioInput *audioInput = nullptr;
+ QPointer<QAudioBufferInput> audioBufferInput;
+ QAudioOutput *audioOutput = nullptr;
+ QPointer<QCamera> camera;
+ QPointer<QScreenCapture> screenCapture;
+ QPointer<QWindowCapture> windowCapture;
+ QPointer<QVideoFrameInput> videoFrameInput;
+ QPointer<QImageCapture> imageCapture;
+ QPointer<QMediaRecorder> recorder;
+ QPointer<QVideoSink> videoSink;
+ QPointer<QObject> videoOutput;
+
+ void setVideoSink(QVideoSink *sink);
+};
+
+QT_END_NAMESPACE
+
+#endif // QMEDIACAPTURESESSION_P_H
diff --git a/src/multimedia/recording/qmediaencodersettings.cpp b/src/multimedia/recording/qmediaencodersettings.cpp
deleted file mode 100644
index 0e169c2b0..000000000
--- a/src/multimedia/recording/qmediaencodersettings.cpp
+++ /dev/null
@@ -1,952 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediaencodersettings.h"
-
-QT_BEGIN_NAMESPACE
-
-static void qRegisterEncoderSettingsMetaTypes()
-{
- qRegisterMetaType<QAudioEncoderSettings>();
- qRegisterMetaType<QVideoEncoderSettings>();
- qRegisterMetaType<QImageEncoderSettings>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterEncoderSettingsMetaTypes)
-
-
-class QAudioEncoderSettingsPrivate : public QSharedData
-{
-public:
- QAudioEncoderSettingsPrivate() :
- isNull(true),
- encodingMode(QMultimedia::ConstantQualityEncoding),
- bitrate(-1),
- sampleRate(-1),
- channels(-1),
- quality(QMultimedia::NormalQuality)
- {
- }
-
- QAudioEncoderSettingsPrivate(const QAudioEncoderSettingsPrivate &other):
- QSharedData(other),
- isNull(other.isNull),
- encodingMode(other.encodingMode),
- codec(other.codec),
- bitrate(other.bitrate),
- sampleRate(other.sampleRate),
- channels(other.channels),
- quality(other.quality),
- encodingOptions(other.encodingOptions)
- {
- }
-
- bool isNull;
- QMultimedia::EncodingMode encodingMode;
- QString codec;
- int bitrate;
- int sampleRate;
- int channels;
- QMultimedia::EncodingQuality quality;
- QVariantMap encodingOptions;
-
-private:
- QAudioEncoderSettingsPrivate& operator=(const QAudioEncoderSettingsPrivate &other);
-};
-
-/*!
- \class QAudioEncoderSettings
-
- \brief The QAudioEncoderSettings class provides a set of audio encoder settings.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_recording
-
- A audio encoder settings object is used to specify the audio encoder
- settings used by QMediaRecorder. Audio encoder settings are selected by
- constructing a QAudioEncoderSettings object, setting the desired properties
- and then passing it to a QMediaRecorder instance using the
- QMediaRecorder::setEncodingSettings() function.
-
- \snippet multimedia-snippets/media.cpp Audio encoder settings
-
- \sa QMediaRecorder, QAudioEncoderSettingsControl
-*/
-
-/*!
- Construct a null audio encoder settings object.
-*/
-QAudioEncoderSettings::QAudioEncoderSettings()
- :d(new QAudioEncoderSettingsPrivate)
-{
-}
-
-/*!
- Constructs a copy of the audio encoder settings object \a other.
-*/
-
-QAudioEncoderSettings::QAudioEncoderSettings(const QAudioEncoderSettings& other)
- :d(other.d)
-{
-}
-
-/*!
- Destroys an audio encoder settings object.
-*/
-
-QAudioEncoderSettings::~QAudioEncoderSettings()
-{
-}
-
-/*!
- Assigns the value of \a other to an audio encoder settings object.
-*/
-
-QAudioEncoderSettings& QAudioEncoderSettings::operator=(const QAudioEncoderSettings &other)
-{
- d = other.d;
- return *this;
-}
-
-/*!
- Determines if \a other is of equal value to an audio encoder settings
- object.
-
- Returns true if the settings objects are of equal value, and false if they
- are not of equal value.
-*/
-
-bool QAudioEncoderSettings::operator==(const QAudioEncoderSettings &other) const
-{
- return (d == other.d) ||
- (d->isNull == other.d->isNull &&
- d->encodingMode == other.d->encodingMode &&
- d->bitrate == other.d->bitrate &&
- d->sampleRate == other.d->sampleRate &&
- d->channels == other.d->channels &&
- d->quality == other.d->quality &&
- d->codec == other.d->codec &&
- d->encodingOptions == other.d->encodingOptions);
-}
-
-/*!
- Determines if \a other is of equal value to an audio encoder settings
- object.
-
- Returns true if the settings objects are not of equal value, and true if
- they are of equal value.
-*/
-
-bool QAudioEncoderSettings::operator!=(const QAudioEncoderSettings &other) const
-{
- return !(*this == other);
-}
-
-/*!
- Identifies if an audio settings object is initialized.
-
- Returns true if the settings object is null, and false if it is not.
-*/
-
-bool QAudioEncoderSettings::isNull() const
-{
- return d->isNull;
-}
-
-/*!
- Returns the audio encoding mode.
-
- \sa QMultimedia::EncodingMode
-*/
-QMultimedia::EncodingMode QAudioEncoderSettings::encodingMode() const
-{
- return d->encodingMode;
-}
-
-/*!
- Sets the audio encoding \a mode setting.
-
- If QMultimedia::ConstantQualityEncoding is set, the quality
- encoding parameter is used and bit rate is ignored,
- otherwise the bitrate is used.
-
- The audio codec, channels count and sample rate settings are used in all
- the encoding modes.
-
- \sa encodingMode(), QMultimedia::EncodingMode
-*/
-void QAudioEncoderSettings::setEncodingMode(QMultimedia::EncodingMode mode)
-{
- d->encodingMode = mode;
-}
-
-/*!
- Returns the audio codec.
-*/
-QString QAudioEncoderSettings::codec() const
-{
- return d->codec;
-}
-
-/*!
- Sets the audio \a codec.
-*/
-void QAudioEncoderSettings::setCodec(const QString& codec)
-{
- d->isNull = false;
- d->codec = codec;
-}
-
-/*!
- Returns the bit rate of the compressed audio stream in bits per second.
-*/
-int QAudioEncoderSettings::bitRate() const
-{
- return d->bitrate;
-}
-
-/*!
- Returns the number of audio channels.
-*/
-int QAudioEncoderSettings::channelCount() const
-{
- return d->channels;
-}
-
-/*!
- Sets the number of audio \a channels.
-
- A value of -1 indicates the encoder should make an optimal choice based on
- what is available from the audio source and the limitations of the codec.
-*/
-void QAudioEncoderSettings::setChannelCount(int channels)
-{
- d->isNull = false;
- d->channels = channels;
-}
-
-/*!
- Sets the audio bit \a rate in bits per second.
-*/
-void QAudioEncoderSettings::setBitRate(int rate)
-{
- d->isNull = false;
- d->bitrate = rate;
-}
-
-/*!
- Returns the audio sample rate in Hz.
-*/
-int QAudioEncoderSettings::sampleRate() const
-{
- return d->sampleRate;
-}
-
-/*!
- Sets the audio sample \a rate in Hz.
-
- A value of -1 indicates the encoder should make an optimal choice based on what is avaialbe
- from the audio source and the limitations of the codec.
- */
-void QAudioEncoderSettings::setSampleRate(int rate)
-{
- d->isNull = false;
- d->sampleRate = rate;
-}
-
-/*!
- Returns the audio encoding quality.
-*/
-
-QMultimedia::EncodingQuality QAudioEncoderSettings::quality() const
-{
- return d->quality;
-}
-
-/*!
- Set the audio encoding \a quality.
-
- Setting the audio quality parameter allows backend to choose the balanced
- set of encoding parameters to achieve the desired quality level.
-
- The \a quality settings parameter is only used in the
- \l {QMultimedia::ConstantQualityEncoding}{constant quality} \l{encodingMode()}{encoding mode}.
-*/
-void QAudioEncoderSettings::setQuality(QMultimedia::EncodingQuality quality)
-{
- d->isNull = false;
- d->quality = quality;
-}
-
-/*!
- Returns the value of encoding \a option.
-
- \sa setEncodingOption(), encodingOptions()
-*/
-QVariant QAudioEncoderSettings::encodingOption(const QString &option) const
-{
- return d->encodingOptions.value(option);
-}
-
-/*!
- Returns the all the encoding options as QVariantMap.
-
- \sa encodingOption(), setEncodingOptions()
-*/
-QVariantMap QAudioEncoderSettings::encodingOptions() const
-{
- return d->encodingOptions;
-}
-
-/*!
- Set the encoding \a option to \a value.
-
- The supported set and meaning of encoding options are
- system and selected codec specific.
-
- \sa encodingOption(), setEncodingOptions()
-*/
-void QAudioEncoderSettings::setEncodingOption(const QString &option, const QVariant &value)
-{
- d->isNull = false;
- if (value.isNull())
- d->encodingOptions.remove(option);
- else
- d->encodingOptions.insert(option, value);
-}
-
-/*!
- Replace all the encoding options with \a options.
-
- The supported set and meaning of encoding options are
- system and selected codec specific.
-
- \sa encodingOption(), setEncodingOption()
-*/
-void QAudioEncoderSettings::setEncodingOptions(const QVariantMap &options)
-{
- d->isNull = false;
- d->encodingOptions = options;
-}
-
-class QVideoEncoderSettingsPrivate : public QSharedData
-{
-public:
- QVideoEncoderSettingsPrivate() :
- isNull(true),
- encodingMode(QMultimedia::ConstantQualityEncoding),
- bitrate(-1),
- frameRate(0),
- quality(QMultimedia::NormalQuality)
- {
- }
-
- QVideoEncoderSettingsPrivate(const QVideoEncoderSettingsPrivate &other):
- QSharedData(other),
- isNull(other.isNull),
- encodingMode(other.encodingMode),
- codec(other.codec),
- bitrate(other.bitrate),
- resolution(other.resolution),
- frameRate(other.frameRate),
- quality(other.quality),
- encodingOptions(other.encodingOptions)
- {
- }
-
- bool isNull;
- QMultimedia::EncodingMode encodingMode;
- QString codec;
- int bitrate;
- QSize resolution;
- qreal frameRate;
- QMultimedia::EncodingQuality quality;
- QVariantMap encodingOptions;
-
-private:
- QVideoEncoderSettingsPrivate& operator=(const QVideoEncoderSettingsPrivate &other);
-};
-
-/*!
- \class QVideoEncoderSettings
-
- \brief The QVideoEncoderSettings class provides a set of video encoder settings.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_recording
-
- A video encoder settings object is used to specify the video encoder
- settings used by QMediaRecorder. Video encoder settings are selected by
- constructing a QVideoEncoderSettings object, setting the desired properties
- and then passing it to a QMediaRecorder instance using the
- QMediaRecorder::setEncodingSettings() function.
-
- \snippet multimedia-snippets/media.cpp Video encoder settings
-
- \sa QMediaRecorder, QVideoEncoderSettingsControl
-*/
-
-/*!
- Constructs a null video encoder settings object.
-*/
-
-QVideoEncoderSettings::QVideoEncoderSettings()
- :d(new QVideoEncoderSettingsPrivate)
-{
-}
-
-/*!
- Constructs a copy of the video encoder settings object \a other.
-*/
-
-QVideoEncoderSettings::QVideoEncoderSettings(const QVideoEncoderSettings& other)
- :d(other.d)
-{
-}
-
-/*!
- Destroys a video encoder settings object.
-*/
-
-QVideoEncoderSettings::~QVideoEncoderSettings()
-{
-}
-
-/*!
- Assigns the value of \a other to a video encoder settings object.
-*/
-QVideoEncoderSettings &QVideoEncoderSettings::operator=(const QVideoEncoderSettings &other)
-{
- d = other.d;
- return *this;
-}
-
-/*!
- Determines if \a other is of equal value to a video encoder settings object.
-
- Returns true if the settings objects are of equal value, and false if they
- are not of equal value.
-*/
-bool QVideoEncoderSettings::operator==(const QVideoEncoderSettings &other) const
-{
- return (d == other.d) ||
- (d->isNull == other.d->isNull &&
- d->encodingMode == other.d->encodingMode &&
- d->bitrate == other.d->bitrate &&
- d->quality == other.d->quality &&
- d->codec == other.d->codec &&
- d->resolution == other.d->resolution &&
- qFuzzyCompare(d->frameRate, other.d->frameRate) &&
- d->encodingOptions == other.d->encodingOptions);
-}
-
-/*!
- Determines if \a other is of equal value to a video encoder settings object.
-
- Returns true if the settings objects are not of equal value, and false if
- they are of equal value.
-*/
-bool QVideoEncoderSettings::operator!=(const QVideoEncoderSettings &other) const
-{
- return !(*this == other);
-}
-
-/*!
- Identifies if a video encoder settings object is uninitalized.
-
- Returns true if the settings are null, and false if they are not.
-*/
-bool QVideoEncoderSettings::isNull() const
-{
- return d->isNull;
-}
-
-/*!
- Returns the video encoding mode.
-
- \sa QMultimedia::EncodingMode
-*/
-QMultimedia::EncodingMode QVideoEncoderSettings::encodingMode() const
-{
- return d->encodingMode;
-}
-
-/*!
- Sets the video encoding \a mode.
-
- If QMultimedia::ConstantQualityEncoding is set,
- the quality encoding parameter is used and bit rate is ignored,
- otherwise the bitrate is used.
-
- The rest of encoding settings are respected regardless of encoding mode.
-
- \sa QMultimedia::EncodingMode
-*/
-void QVideoEncoderSettings::setEncodingMode(QMultimedia::EncodingMode mode)
-{
- d->isNull = false;
- d->encodingMode = mode;
-}
-
-/*!
- Returns the video codec.
-*/
-
-QString QVideoEncoderSettings::codec() const
-{
- return d->codec;
-}
-
-/*!
- Sets the video \a codec.
-*/
-void QVideoEncoderSettings::setCodec(const QString& codec)
-{
- d->isNull = false;
- d->codec = codec;
-}
-
-/*!
- Returns bit rate of the encoded video stream in bits per second.
-*/
-int QVideoEncoderSettings::bitRate() const
-{
- return d->bitrate;
-}
-
-/*!
- Sets the bit rate of the encoded video stream to \a value.
-*/
-
-void QVideoEncoderSettings::setBitRate(int value)
-{
- d->isNull = false;
- d->bitrate = value;
-}
-
-/*!
- Returns the video frame rate.
-*/
-qreal QVideoEncoderSettings::frameRate() const
-{
- return d->frameRate;
-}
-
-/*!
- \fn QVideoEncoderSettings::setFrameRate(qreal rate)
-
- Sets the video frame \a rate.
-
- A value of 0 indicates the encoder should make an optimal choice based on what is available
- from the video source and the limitations of the codec.
-*/
-
-void QVideoEncoderSettings::setFrameRate(qreal rate)
-{
- d->isNull = false;
- d->frameRate = rate;
-}
-
-/*!
- Returns the resolution of the encoded video.
-*/
-
-QSize QVideoEncoderSettings::resolution() const
-{
- return d->resolution;
-}
-
-/*!
- Sets the \a resolution of the encoded video.
-
- An empty QSize indicates the encoder should make an optimal choice based on
- what is available from the video source and the limitations of the codec.
-*/
-
-void QVideoEncoderSettings::setResolution(const QSize &resolution)
-{
- d->isNull = false;
- d->resolution = resolution;
-}
-
-/*!
- Sets the \a width and \a height of the resolution of the encoded video.
-
- \overload
-*/
-
-void QVideoEncoderSettings::setResolution(int width, int height)
-{
- d->isNull = false;
- d->resolution = QSize(width, height);
-}
-
-/*!
- Returns the video encoding quality.
-*/
-
-QMultimedia::EncodingQuality QVideoEncoderSettings::quality() const
-{
- return d->quality;
-}
-
-/*!
- Sets the video encoding \a quality.
-
- Setting the video quality parameter allows backend to choose the balanced
- set of encoding parameters to achieve the desired quality level.
-
- The \a quality settings parameter is only used in the
- \l {QMultimedia::ConstantQualityEncoding}{constant quality} \l{encodingMode()}{encoding mode}.
- The \a quality settings parameter is only used in the \l
- {QMultimedia::ConstantQualityEncoding}{constant quality}
- \l{encodingMode()}{encoding mode}.
-*/
-
-void QVideoEncoderSettings::setQuality(QMultimedia::EncodingQuality quality)
-{
- d->isNull = false;
- d->quality = quality;
-}
-
-/*!
- Returns the value of encoding \a option.
-
- \sa setEncodingOption(), encodingOptions()
-*/
-QVariant QVideoEncoderSettings::encodingOption(const QString &option) const
-{
- return d->encodingOptions.value(option);
-}
-
-/*!
- Returns the all the encoding options as QVariantMap.
-
- \sa encodingOption(), setEncodingOptions()
-*/
-QVariantMap QVideoEncoderSettings::encodingOptions() const
-{
- return d->encodingOptions;
-}
-
-/*!
- Set the encoding \a option \a value.
-
- The supported set and meaning of encoding options are
- system and selected codec specific.
-
- \sa encodingOption(), setEncodingOptions()
-*/
-void QVideoEncoderSettings::setEncodingOption(const QString &option, const QVariant &value)
-{
- d->isNull = false;
- if (value.isNull())
- d->encodingOptions.remove(option);
- else
- d->encodingOptions.insert(option, value);
-}
-
-/*!
- Replace all the encoding options with \a options.
-
- The supported set and meaning of encoding options are
- system and selected codec specific.
-
- \sa encodingOption(), setEncodingOption()
-*/
-void QVideoEncoderSettings::setEncodingOptions(const QVariantMap &options)
-{
- d->isNull = false;
- d->encodingOptions = options;
-}
-
-
-class QImageEncoderSettingsPrivate : public QSharedData
-{
-public:
- QImageEncoderSettingsPrivate() :
- isNull(true),
- quality(QMultimedia::NormalQuality)
- {
- }
-
- QImageEncoderSettingsPrivate(const QImageEncoderSettingsPrivate &other):
- QSharedData(other),
- isNull(other.isNull),
- codec(other.codec),
- resolution(other.resolution),
- quality(other.quality),
- encodingOptions(other.encodingOptions)
- {
- }
-
- bool isNull;
- QString codec;
- QSize resolution;
- QMultimedia::EncodingQuality quality;
- QVariantMap encodingOptions;
-
-private:
- QImageEncoderSettingsPrivate& operator=(const QImageEncoderSettingsPrivate &other);
-};
-
-/*!
- \class QImageEncoderSettings
-
-
- \brief The QImageEncoderSettings class provides a set of image encoder
- settings.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_camera
-
- A image encoder settings object is used to specify the image encoder
- settings used by QCameraImageCapture. Image encoder settings are selected
- by constructing a QImageEncoderSettings object, setting the desired
- properties and then passing it to a QCameraImageCapture instance using the
- QCameraImageCapture::setImageSettings() function.
-
- \snippet multimedia-snippets/media.cpp Image encoder settings
-
- \sa QImageEncoderControl
-*/
-
-/*!
- Constructs a null image encoder settings object.
-*/
-
-QImageEncoderSettings::QImageEncoderSettings()
- :d(new QImageEncoderSettingsPrivate)
-{
-}
-
-/*!
- Constructs a copy of the image encoder settings object \a other.
-*/
-
-QImageEncoderSettings::QImageEncoderSettings(const QImageEncoderSettings& other)
- :d(other.d)
-{
-}
-
-/*!
- Destroys a image encoder settings object.
-*/
-
-QImageEncoderSettings::~QImageEncoderSettings()
-{
-}
-
-/*!
- Assigns the value of \a other to a image encoder settings object.
-*/
-QImageEncoderSettings &QImageEncoderSettings::operator=(const QImageEncoderSettings &other)
-{
- d = other.d;
- return *this;
-}
-
-/*!
- Determines if \a other is of equal value to a image encoder settings
- object.
-
- Returns true if the settings objects are of equal value, and false if they
- are not of equal value.
-*/
-bool QImageEncoderSettings::operator==(const QImageEncoderSettings &other) const
-{
- return (d == other.d) ||
- (d->isNull == other.d->isNull &&
- d->quality == other.d->quality &&
- d->codec == other.d->codec &&
- d->resolution == other.d->resolution &&
- d->encodingOptions == other.d->encodingOptions);
-
-}
-
-/*!
- Determines if \a other is of equal value to a image encoder settings
- object.
-
- Returns true if the settings objects are not of equal value, and false if
- they are of equal value.
-*/
-bool QImageEncoderSettings::operator!=(const QImageEncoderSettings &other) const
-{
- return !(*this == other);
-}
-
-/*!
- Identifies if a image encoder settings object is uninitalized.
-
- Returns true if the settings are null, and false if they are not.
-*/
-bool QImageEncoderSettings::isNull() const
-{
- return d->isNull;
-}
-
-/*!
- Returns the image codec.
-*/
-
-QString QImageEncoderSettings::codec() const
-{
- return d->codec;
-}
-
-/*!
- Sets the image \a codec.
-*/
-void QImageEncoderSettings::setCodec(const QString& codec)
-{
- d->isNull = false;
- d->codec = codec;
-}
-
-/*!
- Returns the resolution of the encoded image.
-*/
-
-QSize QImageEncoderSettings::resolution() const
-{
- return d->resolution;
-}
-
-/*!
- Sets the \a resolution of the encoded image.
-
- An empty QSize indicates the encoder should make an optimal choice based on
- what is available from the image source and the limitations of the codec.
-*/
-
-void QImageEncoderSettings::setResolution(const QSize &resolution)
-{
- d->isNull = false;
- d->resolution = resolution;
-}
-
-/*!
- Sets the \a width and \a height of the resolution of the encoded image.
-
- \overload
-*/
-
-void QImageEncoderSettings::setResolution(int width, int height)
-{
- d->isNull = false;
- d->resolution = QSize(width, height);
-}
-
-/*!
- Returns the image encoding quality.
-*/
-
-QMultimedia::EncodingQuality QImageEncoderSettings::quality() const
-{
- return d->quality;
-}
-
-/*!
- Sets the image encoding \a quality.
-*/
-
-void QImageEncoderSettings::setQuality(QMultimedia::EncodingQuality quality)
-{
- d->isNull = false;
- d->quality = quality;
-}
-
-/*!
- Returns the value of encoding \a option.
-
- \sa setEncodingOption(), encodingOptions()
-*/
-QVariant QImageEncoderSettings::encodingOption(const QString &option) const
-{
- return d->encodingOptions.value(option);
-}
-
-/*!
- Returns the all the encoding options as QVariantMap.
-
- \sa encodingOption(), setEncodingOptions()
-*/
-QVariantMap QImageEncoderSettings::encodingOptions() const
-{
- return d->encodingOptions;
-}
-
-/*!
- Set the encoding \a option \a value.
-
- The supported set and meaning of encoding options are
- system and selected codec specific.
-
- \sa encodingOption(), setEncodingOptions()
-*/
-void QImageEncoderSettings::setEncodingOption(const QString &option, const QVariant &value)
-{
- d->isNull = false;
- if (value.isNull())
- d->encodingOptions.remove(option);
- else
- d->encodingOptions.insert(option, value);
-}
-
-/*!
- Replace all the encoding options with \a options.
-
- The supported set and meaning of encoding options are
- system and selected codec specific.
-
- \sa encodingOption(), setEncodingOption()
-*/
-void QImageEncoderSettings::setEncodingOptions(const QVariantMap &options)
-{
- d->isNull = false;
- d->encodingOptions = options;
-}
-
-
-QT_END_NAMESPACE
-
diff --git a/src/multimedia/recording/qmediaencodersettings.h b/src/multimedia/recording/qmediaencodersettings.h
deleted file mode 100644
index 0d6a9eddf..000000000
--- a/src/multimedia/recording/qmediaencodersettings.h
+++ /dev/null
@@ -1,180 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIAENCODERSETTINGS_H
-#define QMEDIAENCODERSETTINGS_H
-
-#include <QtCore/qsharedpointer.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qsize.h>
-#include <QtCore/qvariant.h>
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
-
-QT_BEGIN_NAMESPACE
-
-
-
-class QAudioEncoderSettingsPrivate;
-class Q_MULTIMEDIA_EXPORT QAudioEncoderSettings
-{
-public:
- QAudioEncoderSettings();
- QAudioEncoderSettings(const QAudioEncoderSettings& other);
-
- ~QAudioEncoderSettings();
-
- QAudioEncoderSettings& operator=(const QAudioEncoderSettings &other);
- bool operator==(const QAudioEncoderSettings &other) const;
- bool operator!=(const QAudioEncoderSettings &other) const;
-
- bool isNull() const;
-
- QMultimedia::EncodingMode encodingMode() const;
- void setEncodingMode(QMultimedia::EncodingMode);
-
- QString codec() const;
- void setCodec(const QString& codec);
-
- int bitRate() const;
- void setBitRate(int bitrate);
-
- int channelCount() const;
- void setChannelCount(int channels);
-
- int sampleRate() const;
- void setSampleRate(int rate);
-
- QMultimedia::EncodingQuality quality() const;
- void setQuality(QMultimedia::EncodingQuality quality);
-
- QVariant encodingOption(const QString &option) const;
- QVariantMap encodingOptions() const;
- void setEncodingOption(const QString &option, const QVariant &value);
- void setEncodingOptions(const QVariantMap &options);
-
-private:
- QSharedDataPointer<QAudioEncoderSettingsPrivate> d;
-};
-
-class QVideoEncoderSettingsPrivate;
-class Q_MULTIMEDIA_EXPORT QVideoEncoderSettings
-{
-public:
- QVideoEncoderSettings();
- QVideoEncoderSettings(const QVideoEncoderSettings& other);
-
- ~QVideoEncoderSettings();
-
- QVideoEncoderSettings& operator=(const QVideoEncoderSettings &other);
- bool operator==(const QVideoEncoderSettings &other) const;
- bool operator!=(const QVideoEncoderSettings &other) const;
-
- bool isNull() const;
-
- QMultimedia::EncodingMode encodingMode() const;
- void setEncodingMode(QMultimedia::EncodingMode);
-
- QString codec() const;
- void setCodec(const QString &);
-
- QSize resolution() const;
- void setResolution(const QSize &);
- void setResolution(int width, int height);
-
- qreal frameRate() const;
- void setFrameRate(qreal rate);
-
- int bitRate() const;
- void setBitRate(int bitrate);
-
- QMultimedia::EncodingQuality quality() const;
- void setQuality(QMultimedia::EncodingQuality quality);
-
- QVariant encodingOption(const QString &option) const;
- QVariantMap encodingOptions() const;
- void setEncodingOption(const QString &option, const QVariant &value);
- void setEncodingOptions(const QVariantMap &options);
-
-private:
- QSharedDataPointer<QVideoEncoderSettingsPrivate> d;
-};
-
-class QImageEncoderSettingsPrivate;
-class Q_MULTIMEDIA_EXPORT QImageEncoderSettings
-{
-public:
- QImageEncoderSettings();
- QImageEncoderSettings(const QImageEncoderSettings& other);
-
- ~QImageEncoderSettings();
-
- QImageEncoderSettings& operator=(const QImageEncoderSettings &other);
- bool operator==(const QImageEncoderSettings &other) const;
- bool operator!=(const QImageEncoderSettings &other) const;
-
- bool isNull() const;
-
- QString codec() const;
- void setCodec(const QString &);
-
- QSize resolution() const;
- void setResolution(const QSize &);
- void setResolution(int width, int height);
-
- QMultimedia::EncodingQuality quality() const;
- void setQuality(QMultimedia::EncodingQuality quality);
-
- QVariant encodingOption(const QString &option) const;
- QVariantMap encodingOptions() const;
- void setEncodingOption(const QString &option, const QVariant &value);
- void setEncodingOptions(const QVariantMap &options);
-
-private:
- QSharedDataPointer<QImageEncoderSettingsPrivate> d;
-};
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QAudioEncoderSettings)
-Q_DECLARE_METATYPE(QVideoEncoderSettings)
-Q_DECLARE_METATYPE(QImageEncoderSettings)
-
-
-#endif
diff --git a/src/multimedia/recording/qmediarecorder.cpp b/src/multimedia/recording/qmediarecorder.cpp
index 617627985..9fe1e4501 100644
--- a/src/multimedia/recording/qmediarecorder.cpp
+++ b/src/multimedia/recording/qmediarecorder.cpp
@@ -1,61 +1,24 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediarecorder.h"
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
#include "qmediarecorder_p.h"
-#include <qmediarecordercontrol.h>
-#include "qmediaobject_p.h"
-#include <qmediaservice.h>
-#include <qmediaserviceprovider_p.h>
-#include <qmetadatawritercontrol.h>
-#include <qaudioencodersettingscontrol.h>
-#include <qvideoencodersettingscontrol.h>
-#include <qmediacontainercontrol.h>
-#include <qmediaavailabilitycontrol.h>
+#include <private/qplatformmediarecorder_p.h>
+#include <qaudiodevice.h>
#include <qcamera.h>
-#include <qcameracontrol.h>
+#include <qscreencapture.h>
+#include <qwindowcapture.h>
+#include <qmediacapturesession.h>
+#include <private/qplatformcamera_p.h>
+#include <private/qplatformsurfacecapture_p.h>
+#include <private/qplatformmediaintegration_p.h>
+#include <private/qplatformmediacapture_p.h>
#include <QtCore/qdebug.h>
#include <QtCore/qurl.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qmetaobject.h>
+#include <QtCore/qtimer.h>
#include <qaudioformat.h>
@@ -66,179 +29,103 @@ QT_BEGIN_NAMESPACE
\inmodule QtMultimedia
\ingroup multimedia
\ingroup multimedia_recording
+ \ingroup multimedia_video
+ \ingroup multimedia_audio
- \brief The QMediaRecorder class is used for the recording of media content.
+ \brief The QMediaRecorder class is used for encoding and recording a capture session.
- The QMediaRecorder class is a high level media recording class. It's not
- intended to be used alone but for accessing the media recording functions
- of other media objects, like QCamera.
+ The QMediaRecorder class is a class for encoding and recording media generated in a
+ QMediaCaptureSession.
\snippet multimedia-snippets/media.cpp Media recorder
-
- \sa QAudioRecorder
*/
+/*!
+ \qmltype MediaRecorder
+ \instantiates QMediaRecorder
+ \brief For encoding and recording media generated in a CaptureSession.
-static void qRegisterMediaRecorderMetaTypes()
-{
- qRegisterMetaType<QMediaRecorder::State>("QMediaRecorder::State");
- qRegisterMetaType<QMediaRecorder::Status>("QMediaRecorder::Status");
- qRegisterMetaType<QMediaRecorder::Error>("QMediaRecorder::Error");
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterMediaRecorderMetaTypes)
-
-
-QMediaRecorderPrivate::QMediaRecorderPrivate():
- mediaObject(nullptr),
- control(nullptr),
- formatControl(nullptr),
- audioControl(nullptr),
- videoControl(nullptr),
- metaDataControl(nullptr),
- availabilityControl(nullptr),
- settingsChanged(false),
- notifyTimer(nullptr),
- state(QMediaRecorder::StoppedState),
- error(QMediaRecorder::NoError)
-{
-}
-
-#define ENUM_NAME(c,e,v) (c::staticMetaObject.enumerator(c::staticMetaObject.indexOfEnumerator(e)).valueToKey((v)))
-
-void QMediaRecorderPrivate::_q_stateChanged(QMediaRecorder::State ps)
-{
- Q_Q(QMediaRecorder);
-
- if (ps == QMediaRecorder::RecordingState)
- notifyTimer->start();
- else
- notifyTimer->stop();
-
-// qDebug() << "Recorder state changed:" << ENUM_NAME(QMediaRecorder,"State",ps);
- if (state != ps) {
- emit q->stateChanged(ps);
- }
-
- state = ps;
-}
-
-
-void QMediaRecorderPrivate::_q_error(int error, const QString &errorString)
-{
- Q_Q(QMediaRecorder);
-
- this->error = QMediaRecorder::Error(error);
- this->errorString = errorString;
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+ \ingroup multimedia_audio_qml
+ \ingroup multimedia_video_qml
- emit q->error(this->error);
-}
+ The MediaRecorder element can be used within a CaptureSession to record and encode audio and
+ video captured from a microphone and camera
-void QMediaRecorderPrivate::_q_serviceDestroyed()
-{
- mediaObject = nullptr;
- control = nullptr;
- formatControl = nullptr;
- audioControl = nullptr;
- videoControl = nullptr;
- metaDataControl = nullptr;
- availabilityControl = nullptr;
- settingsChanged = true;
-}
+ \since 6.2
+ The code below shows a simple capture session containing a MediaRecorder using the default
+ camera and default audio input.
-void QMediaRecorderPrivate::_q_updateActualLocation(const QUrl &location)
-{
- if (actualLocation != location) {
- actualLocation = location;
- emit q_func()->actualLocationChanged(actualLocation);
+\qml
+ CaptureSession {
+ id: captureSession
+ camera: Camera {
+ id: camera
+ active: true
+ }
+ audioInput: AudioInput {}
+ recorder: MediaRecorder {
+ id: recorder
+ }
}
-}
-
-void QMediaRecorderPrivate::_q_notify()
-{
- emit q_func()->durationChanged(q_func()->duration());
-}
-
-void QMediaRecorderPrivate::_q_updateNotifyInterval(int ms)
-{
- notifyTimer->setInterval(ms);
-}
-
-void QMediaRecorderPrivate::applySettingsLater()
-{
- if (control && !settingsChanged) {
- settingsChanged = true;
- QMetaObject::invokeMethod(q_func(), "_q_applySettings", Qt::QueuedConnection);
+\endqml
+
+ The code below shows how the recording can be started and stopped.
+\qml
+ CameraButton {
+ text: "Record"
+ visible: recorder.recorderState !== MediaRecorder.RecordingState
+ onClicked: recorder.record()
}
-}
-void QMediaRecorderPrivate::_q_applySettings()
-{
- if (control && settingsChanged) {
- settingsChanged = false;
- control->applySettings();
+ CameraButton {
+ id: stopButton
+ text: "Stop"
+ visible: recorder.recorderState === MediaRecorder.RecordingState
+ onClicked: recorder.stop()
}
-}
+\endqml
-void QMediaRecorderPrivate::_q_availabilityChanged(QMultimedia::AvailabilityStatus availability)
+ \sa CaptureSession, Camera, AudioInput, ImageCapture
+*/
+QMediaRecorderPrivate::QMediaRecorderPrivate()
{
- Q_Q(QMediaRecorder);
- Q_UNUSED(error);
- Q_UNUSED(availability);
-
- // Really this should not always emit, but
- // we can't really tell from here (isAvailable
- // may not have changed, or the mediaobject's overridden
- // availability() may not have changed).
- q->availabilityChanged(q->availability());
- q->availabilityChanged(q->isAvailable());
+ // Force an early initialization of the mime database
+ // to avoid a delay when recording for the first time.
+ encoderSettings.mimeType();
}
-void QMediaRecorderPrivate::restartCamera()
+QString QMediaRecorderPrivate::msgFailedStartRecording()
{
- //restart camera if it can't apply new settings in the Active state
- QCamera *camera = qobject_cast<QCamera*>(mediaObject);
- if (camera && camera->captureMode() == QCamera::CaptureVideo) {
- QMetaObject::invokeMethod(camera,
- "_q_preparePropertyChange",
- Qt::DirectConnection,
- Q_ARG(int, QCameraControl::VideoEncodingSettings));
- }
+ return QMediaRecorder::tr("Failed to start recording");
}
-
/*!
- Constructs a media recorder which records the media produced by \a mediaObject.
-
- The \a parent is passed to QMediaObject.
+ Constructs a media recorder which records the media produced by a microphone and camera.
+ The media recorder is a child of \a{parent}.
*/
-QMediaRecorder::QMediaRecorder(QMediaObject *mediaObject, QObject *parent):
- QObject(parent),
- d_ptr(new QMediaRecorderPrivate)
+QMediaRecorder::QMediaRecorder(QObject *parent)
+ : QObject(parent),
+ d_ptr(new QMediaRecorderPrivate)
{
Q_D(QMediaRecorder);
- d->q_ptr = this;
- d->notifyTimer = new QTimer(this);
- connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify()));
+ auto &mediaIntegration = *QPlatformMediaIntegration::instance();
- setMediaObject(mediaObject);
-}
-
-/*!
- \internal
-*/
-QMediaRecorder::QMediaRecorder(QMediaRecorderPrivate &dd, QMediaObject *mediaObject, QObject *parent):
- QObject(parent),
- d_ptr(&dd)
-{
- Q_D(QMediaRecorder);
d->q_ptr = this;
-
- d->notifyTimer = new QTimer(this);
- connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify()));
-
- setMediaObject(mediaObject);
+ auto maybeControl = mediaIntegration.createRecorder(this);
+ if (maybeControl) {
+ // The first format info initialization may take some time,
+ // for users it seems to be more suitable to have a delay on the object construction
+ // rather than on QMediaRecorder::record
+ mediaIntegration.formatInfo();
+
+ d->control = maybeControl.value();
+ } else {
+ d->initErrorMessage = maybeControl.error();
+ qWarning() << "Failed to initialize QMediaRecorder" << maybeControl.error();
+ }
}
/*!
@@ -247,219 +134,76 @@ QMediaRecorder::QMediaRecorder(QMediaRecorderPrivate &dd, QMediaObject *mediaObj
QMediaRecorder::~QMediaRecorder()
{
+ if (d_ptr->captureSession)
+ d_ptr->captureSession->setRecorder(nullptr);
+ delete d_ptr->control;
delete d_ptr;
}
/*!
- Returns the QMediaObject instance that this QMediaRecorder is bound too,
- or 0 otherwise.
+ \internal
*/
-QMediaObject *QMediaRecorder::mediaObject() const
+QPlatformMediaRecorder *QMediaRecorder::platformRecoder() const
{
- return d_func()->mediaObject;
+ return d_ptr->control;
}
/*!
\internal
*/
-bool QMediaRecorder::setMediaObject(QMediaObject *object)
+void QMediaRecorder::setCaptureSession(QMediaCaptureSession *session)
{
Q_D(QMediaRecorder);
+ d->captureSession = session;
+}
+/*!
+ \qmlproperty QUrl QtMultimedia::MediaRecorder::outputLocation
+ \brief The destination location of media content.
- if (object == d->mediaObject)
- return true;
-
- if (d->mediaObject) {
- if (d->control) {
- disconnect(d->control, SIGNAL(stateChanged(QMediaRecorder::State)),
- this, SLOT(_q_stateChanged(QMediaRecorder::State)));
-
- disconnect(d->control, SIGNAL(statusChanged(QMediaRecorder::Status)),
- this, SIGNAL(statusChanged(QMediaRecorder::Status)));
-
- disconnect(d->control, SIGNAL(mutedChanged(bool)),
- this, SIGNAL(mutedChanged(bool)));
-
- disconnect(d->control, SIGNAL(volumeChanged(qreal)),
- this, SIGNAL(volumeChanged(qreal)));
-
- disconnect(d->control, SIGNAL(durationChanged(qint64)),
- this, SIGNAL(durationChanged(qint64)));
-
- disconnect(d->control, SIGNAL(actualLocationChanged(QUrl)),
- this, SLOT(_q_updateActualLocation(QUrl)));
-
- disconnect(d->control, SIGNAL(error(int,QString)),
- this, SLOT(_q_error(int,QString)));
- }
-
- disconnect(d->mediaObject, SIGNAL(notifyIntervalChanged(int)), this, SLOT(_q_updateNotifyInterval(int)));
-
- QMediaService *service = d->mediaObject->service();
-
- if (service) {
- disconnect(service, SIGNAL(destroyed()), this, SLOT(_q_serviceDestroyed()));
-
- if (d->control)
- service->releaseControl(d->control);
- if (d->formatControl)
- service->releaseControl(d->formatControl);
- if (d->audioControl)
- service->releaseControl(d->audioControl);
- if (d->videoControl)
- service->releaseControl(d->videoControl);
- if (d->metaDataControl) {
- disconnect(d->metaDataControl, SIGNAL(metaDataChanged()),
- this, SIGNAL(metaDataChanged()));
- disconnect(d->metaDataControl, SIGNAL(metaDataChanged(QString,QVariant)),
- this, SIGNAL(metaDataChanged(QString,QVariant)));
- disconnect(d->metaDataControl, SIGNAL(metaDataAvailableChanged(bool)),
- this, SIGNAL(metaDataAvailableChanged(bool)));
- disconnect(d->metaDataControl, SIGNAL(writableChanged(bool)),
- this, SIGNAL(metaDataWritableChanged(bool)));
-
- service->releaseControl(d->metaDataControl);
- }
- if (d->availabilityControl) {
- disconnect(d->availabilityControl, SIGNAL(availabilityChanged(QMultimedia::AvailabilityStatus)),
- this, SLOT(_q_availabilityChanged(QMultimedia::AvailabilityStatus)));
- service->releaseControl(d->availabilityControl);
- }
- }
- }
-
- d->control = nullptr;
- d->formatControl = nullptr;
- d->audioControl = nullptr;
- d->videoControl = nullptr;
- d->metaDataControl = nullptr;
- d->availabilityControl = nullptr;
-
- d->mediaObject = object;
-
- if (d->mediaObject) {
- QMediaService *service = d->mediaObject->service();
-
- d->notifyTimer->setInterval(d->mediaObject->notifyInterval());
- connect(d->mediaObject, SIGNAL(notifyIntervalChanged(int)), SLOT(_q_updateNotifyInterval(int)));
-
- if (service) {
- d->control = qobject_cast<QMediaRecorderControl*>(service->requestControl(QMediaRecorderControl_iid));
-
- if (d->control) {
- d->formatControl = qobject_cast<QMediaContainerControl *>(service->requestControl(QMediaContainerControl_iid));
- d->audioControl = qobject_cast<QAudioEncoderSettingsControl *>(service->requestControl(QAudioEncoderSettingsControl_iid));
- d->videoControl = qobject_cast<QVideoEncoderSettingsControl *>(service->requestControl(QVideoEncoderSettingsControl_iid));
-
- QMediaControl *control = service->requestControl(QMetaDataWriterControl_iid);
- if (control) {
- d->metaDataControl = qobject_cast<QMetaDataWriterControl *>(control);
- if (!d->metaDataControl) {
- service->releaseControl(control);
- } else {
- connect(d->metaDataControl,
- SIGNAL(metaDataChanged()),
- SIGNAL(metaDataChanged()));
- connect(d->metaDataControl, SIGNAL(metaDataChanged(QString,QVariant)),
- this, SIGNAL(metaDataChanged(QString,QVariant)));
- connect(d->metaDataControl,
- SIGNAL(metaDataAvailableChanged(bool)),
- SIGNAL(metaDataAvailableChanged(bool)));
- connect(d->metaDataControl,
- SIGNAL(writableChanged(bool)),
- SIGNAL(metaDataWritableChanged(bool)));
- }
- }
-
- d->availabilityControl = service->requestControl<QMediaAvailabilityControl*>();
- if (d->availabilityControl) {
- connect(d->availabilityControl, SIGNAL(availabilityChanged(QMultimedia::AvailabilityStatus)),
- this, SLOT(_q_availabilityChanged(QMultimedia::AvailabilityStatus)));
- }
-
- connect(d->control, SIGNAL(stateChanged(QMediaRecorder::State)),
- this, SLOT(_q_stateChanged(QMediaRecorder::State)));
-
- connect(d->control, SIGNAL(statusChanged(QMediaRecorder::Status)),
- this, SIGNAL(statusChanged(QMediaRecorder::Status)));
-
- connect(d->control, SIGNAL(mutedChanged(bool)),
- this, SIGNAL(mutedChanged(bool)));
-
- connect(d->control, SIGNAL(volumeChanged(qreal)),
- this, SIGNAL(volumeChanged(qreal)));
-
- connect(d->control, SIGNAL(durationChanged(qint64)),
- this, SIGNAL(durationChanged(qint64)));
-
- connect(d->control, SIGNAL(actualLocationChanged(QUrl)),
- this, SLOT(_q_updateActualLocation(QUrl)));
-
- connect(d->control, SIGNAL(error(int,QString)),
- this, SLOT(_q_error(int,QString)));
-
- connect(service, SIGNAL(destroyed()), this, SLOT(_q_serviceDestroyed()));
-
-
- d->applySettingsLater();
-
- return true;
- }
- }
+ Setting the location can fail, for example when the service supports only
+ local file system locations but a network URL was passed. If the operation
+ fails an errorOccured() signal is emitted.
- d->mediaObject = nullptr;
- return false;
- }
+ The location can be relative or empty. If empty the recorder uses the
+ system specific place and file naming scheme.
- return true;
-}
+ \sa errorOccurred()
+*/
/*!
\property QMediaRecorder::outputLocation
\brief the destination location of media content.
Setting the location can fail, for example when the service supports only
- local file system locations but a network URL was passed. If the service
- does not support media recording this setting the output location will
- always fail.
+ local file system locations but a network URL was passed. If the operation
+ fails an errorOccured() signal is emitted.
- The \a location can be relative or empty;
- in this case the recorder uses the system specific place and file naming scheme.
- After recording has stated, QMediaRecorder::outputLocation() returns the actual output location.
+ The output location can be relative or empty; in the latter case the recorder
+ uses the system specific place and file naming scheme.
*/
/*!
- \property QMediaRecorder::actualLocation
- \brief the actual location of the last media content.
+ \qmlproperty QUrl QtMultimedia::MediaRecorder::actualLocation
+ \brief The actual location of the last media content.
The actual location is usually available after recording starts,
and reset when new location is set or new recording starts.
*/
/*!
- Returns true if media recorder service ready to use.
+ \property QMediaRecorder::actualLocation
+ \brief The actual location of the last media content.
- \sa availabilityChanged()
+ The actual location is usually available after recording starts,
+ and reset when new location is set or new recording starts.
*/
-bool QMediaRecorder::isAvailable() const
-{
- return availability() == QMultimedia::Available;
-}
/*!
- Returns the availability of this functionality.
-
- \sa availabilityChanged()
+ Returns \c true if media recorder service ready to use.
*/
-QMultimedia::AvailabilityStatus QMediaRecorder::availability() const
+bool QMediaRecorder::isAvailable() const
{
- if (d_func()->control == nullptr)
- return QMultimedia::ServiceMissing;
-
- if (d_func()->availabilityControl)
- return d_func()->availabilityControl->availability();
-
- return QMultimedia::Available;
+ return d_func()->control && d_func()->captureSession;
}
QUrl QMediaRecorder::outputLocation() const
@@ -467,41 +211,68 @@ QUrl QMediaRecorder::outputLocation() const
return d_func()->control ? d_func()->control->outputLocation() : QUrl();
}
-bool QMediaRecorder::setOutputLocation(const QUrl &location)
+void QMediaRecorder::setOutputLocation(const QUrl &location)
{
Q_D(QMediaRecorder);
- d->actualLocation.clear();
- return d->control ? d->control->setOutputLocation(location) : false;
+ if (!d->control) {
+ emit errorOccurred(QMediaRecorder::ResourceError, d->initErrorMessage);
+ return;
+ }
+ d->control->setOutputLocation(location);
+ d->control->clearActualLocation();
+ if (!location.isEmpty() && !d->control->isLocationWritable(location))
+ emit errorOccurred(QMediaRecorder::LocationNotWritable, tr("Output location not writable"));
}
-QUrl QMediaRecorder::actualLocation() const
+/*!
+ Set the output IO device for media content.
+
+ The \a device must have been opened in the \l{QIODevice::WriteOnly}{WriteOnly} or
+ \l{QIODevice::ReadWrite}{ReadWrite} modes before the recording starts.
+
+ The media recorder doesn't take ownership of the specified \a device.
+ If the recording has been started, the device must be kept alive and open until
+ the signal \c recorderStateChanged(StoppedState) is emitted.
+
+ \sa outputDevice()
+*/
+void QMediaRecorder::setOutputDevice(QIODevice *device)
{
- return d_func()->actualLocation;
+ Q_D(QMediaRecorder);
+ d->control->setOutputDevice(device);
}
/*!
- Returns the current media recorder state.
+ Returns the output IO device for media content.
- \sa QMediaRecorder::State
+ \sa setOutputDevice()
*/
+QIODevice *QMediaRecorder::outputDevice() const
+{
+ Q_D(const QMediaRecorder);
+ return d->control->outputDevice();
+}
-QMediaRecorder::State QMediaRecorder::state() const
+QUrl QMediaRecorder::actualLocation() const
{
- return d_func()->control ? QMediaRecorder::State(d_func()->control->state()) : StoppedState;
+ Q_D(const QMediaRecorder);
+ return d->control ? d->control->actualLocation() : QUrl();
}
/*!
- Returns the current media recorder status.
+ Returns the current media recorder state.
- \sa QMediaRecorder::Status
+ \sa QMediaRecorder::RecorderState
*/
-QMediaRecorder::Status QMediaRecorder::status() const
+QMediaRecorder::RecorderState QMediaRecorder::recorderState() const
{
- return d_func()->control ? QMediaRecorder::Status(d_func()->control->status()) : UnavailableStatus;
+ return d_func()->control ? QMediaRecorder::RecorderState(d_func()->control->state()) : StoppedState;
}
/*!
+ \property QMediaRecorder::error
+
Returns the current error state.
\sa errorString()
@@ -509,10 +280,19 @@ QMediaRecorder::Status QMediaRecorder::status() const
QMediaRecorder::Error QMediaRecorder::error() const
{
- return d_func()->error;
+ Q_D(const QMediaRecorder);
+
+ return d->control ? d->control->error() : QMediaRecorder::ResourceError;
}
+/*!
+ \qmlproperty string QtMultimedia::MediaRecorder::errorString
+ \brief This property holds a string describing the current error state.
+ \sa error
+*/
/*!
+ \property QMediaRecorder::errorString
+
Returns a string describing the current error state.
\sa error()
@@ -520,8 +300,15 @@ QMediaRecorder::Error QMediaRecorder::error() const
QString QMediaRecorder::errorString() const
{
- return d_func()->errorString;
+ Q_D(const QMediaRecorder);
+
+ return d->control ? d->control->errorString() : d->initErrorMessage;
}
+/*!
+ \qmlproperty qint64 QtMultimedia::MediaRecorder::duration
+
+ \brief This property holds the recorded media duration in milliseconds.
+*/
/*!
\property QMediaRecorder::duration
@@ -533,577 +320,670 @@ qint64 QMediaRecorder::duration() const
{
return d_func()->control ? d_func()->control->duration() : 0;
}
-
/*!
- \property QMediaRecorder::muted
+ \fn void QMediaRecorder::encoderSettingsChanged()
- \brief whether a recording audio stream is muted.
+ Signals when the encoder settings change.
*/
+/*!
+ \qmlmethod QtMultimedia::MediaRecorder::record()
+ \brief Starts recording.
-bool QMediaRecorder::isMuted() const
-{
- return d_func()->control ? d_func()->control->isMuted() : 0;
-}
+ While the recorder state is changed immediately to
+ \c MediaRecorder.RecordingState, recording may start asynchronously.
-void QMediaRecorder::setMuted(bool muted)
-{
- Q_D(QMediaRecorder);
-
- if (d->control)
- d->control->setMuted(muted);
-}
+ If recording fails, the error() signal is emitted with recorder state being
+ reset back to \c{QMediaRecorder.StoppedState}.
+ \note On mobile devices, recording will happen in the orientation the
+ device had when calling record and is locked for the duration of the recording.
+ To avoid artifacts on the user interface, we recommend to keep the user interface
+ locked to the same orientation as long as the recording is ongoing using
+ the contentOrientation property of the Window and unlock it again once the recording
+ is finished.
+*/
/*!
- \property QMediaRecorder::volume
-
- \brief the current recording audio volume.
+ Start recording.
- The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this
- range will be clamped.
+ While the recorder state is changed immediately to
+ c\{QMediaRecorder::RecordingState}, recording may start asynchronously.
- The default volume is \c 1.0.
+ If recording fails error() signal is emitted with recorder state being
+ reset back to \c{QMediaRecorder::StoppedState}.
- UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale
- will produce linear changes in perceived loudness, which is what a user would normally expect
- from a volume control. See QAudio::convertVolume() for more details.
+ \note On mobile devices, recording will happen in the orientation the
+ device had when calling record and is locked for the duration of the recording.
+ To avoid artifacts on the user interface, we recommend to keep the user interface
+ locked to the same orientation as long as the recording is ongoing using
+ the contentOrientation property of QWindow and unlock it again once the recording
+ is finished.
*/
-qreal QMediaRecorder::volume() const
+void QMediaRecorder::record()
{
- return d_func()->control ? d_func()->control->volume() : 1.0;
-}
+ Q_D(QMediaRecorder);
+ if (!d->control || !d->captureSession)
+ return;
-void QMediaRecorder::setVolume(qreal volume)
-{
- Q_D(QMediaRecorder);
+ if (d->control->state() == QMediaRecorder::PausedState) {
+ d->control->resume();
+ } else {
+ auto oldMediaFormat = d->encoderSettings.mediaFormat();
- if (d->control) {
- volume = qMax(qreal(0.0), volume);
- d->control->setVolume(volume);
+ auto platformSession = d->captureSession->platformSession();
+ const bool hasVideo = platformSession && !platformSession->activeVideoSources().empty();
+
+ d->encoderSettings.resolveFormat(hasVideo ? QMediaFormat::RequiresVideo : QMediaFormat::NoFlags);
+ d->control->clearActualLocation();
+ d->control->clearError();
+
+ auto settings = d->encoderSettings;
+ d->control->record(d->encoderSettings);
+
+ if (settings != d->encoderSettings)
+ emit encoderSettingsChanged();
+
+ if (oldMediaFormat != d->encoderSettings.mediaFormat())
+ emit mediaFormatChanged();
}
}
-
/*!
- Returns a list of supported container formats.
-*/
-QStringList QMediaRecorder::supportedContainers() const
-{
- return d_func()->formatControl ?
- d_func()->formatControl->supportedContainers() : QStringList();
-}
+ \qmlmethod QtMultimedia::MediaRecorder::pause()
+ \brief Pauses recording.
-/*!
- Returns a description of a container \a format.
-*/
-QString QMediaRecorder::containerDescription(const QString &format) const
-{
- return d_func()->formatControl ?
- d_func()->formatControl->containerDescription(format) : QString();
-}
+ The recorder state is changed to QMediaRecorder.PausedState.
+ Depending on the platform, pausing recording may be not supported.
+ In this case the recorder state is unchanged.
+*/
/*!
- Returns the selected container format.
+ Pauses recording.
+
+ The recorder state is changed to QMediaRecorder::PausedState.
+
+ Depending on the platform, pausing recording may be not supported.
+ In this case the recorder state is unchanged.
*/
-QString QMediaRecorder::containerFormat() const
+void QMediaRecorder::pause()
{
- return d_func()->formatControl ?
- d_func()->formatControl->containerFormat() : QString();
+ Q_D(QMediaRecorder);
+ if (d->control && d->captureSession)
+ d->control->pause();
}
-
/*!
- Returns a list of supported audio codecs.
+ \qmlmethod QtMultimedia::MediaRecorder::stop()
+ \brief Stops the recording.
+
+ The recorder will stop the recording. Processing pending video and audio data might
+ however still take some time. The recording is finished, once the state of the media
+ recorder changes to QMediaRecorder::StoppedState.
*/
-QStringList QMediaRecorder::supportedAudioCodecs() const
-{
- return d_func()->audioControl ?
- d_func()->audioControl->supportedAudioCodecs() : QStringList();
-}
/*!
- Returns a description of an audio \a codec.
+ The recorder will stop the recording. Processing pending video and audio data might
+ however still take some time. The recording is finished, once the state of the media
+ recorder changes to QMediaRecorder::StoppedState.
*/
-QString QMediaRecorder::audioCodecDescription(const QString &codec) const
+void QMediaRecorder::stop()
{
- return d_func()->audioControl ?
- d_func()->audioControl->codecDescription(codec) : QString();
+ Q_D(QMediaRecorder);
+ if (d->control && d->captureSession)
+ d->control->stop();
}
+/*!
+ \qmlproperty enumeration QtMultimedia::MediaRecorder::recorderState
+ \brief This property holds the current media recorder state.
+
+ The state property represents the user request and is changed synchronously
+ during record(), pause() or stop() calls.
+ RecorderSstate may also change asynchronously when recording fails.
+ \value MediaRecorder.StoppedState The recorder is not active.
+ \value MediaRecorder.RecordingState The recording is requested.
+ \value MediaRecorder.PausedState The recorder is pause.
+*/
/*!
- Returns a list of supported audio sample rates.
+ \enum QMediaRecorder::RecorderState
- If non null audio \a settings parameter is passed, the returned list is
- reduced to sample rates supported with partial settings applied.
+ \value StoppedState The recorder is not active.
+ \value RecordingState The recording is requested.
+ \value PausedState The recorder is paused.
+*/
+/*!
+ \qmlproperty enumeration QtMultimedia::MediaRecorder::error
+ \brief This property holds the current media recorder error state.
- This can be used to query the list of sample rates, supported by specific
- audio codec.
+ \value MediaRecorder.NoError Not in an error state.
+ \value MediaRecorder.ResourceError Not enough system resources
+ \value MediaRecorder.FormatError the current format is not supported.
+ \value MediaRecorder.OutOfSpaceError No space left on device.
+ \value MediaRecorder.LocationNotWriteable The output location is not writable.
+*/
+/*!
+ \enum QMediaRecorder::Error
- If the encoder supports arbitrary sample rates within the supported rates
- range, *\a continuous is set to true, otherwise *\a continuous is set to
- false.
+ \value NoError No Errors.
+ \value ResourceError Device is not ready or not available.
+ \value FormatError Current format is not supported.
+ \value OutOfSpaceError No space left on device.
+ \value LocationNotWritable The output location is not writable.
*/
-QList<int> QMediaRecorder::supportedAudioSampleRates(const QAudioEncoderSettings &settings, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
+/*!
+ \property QMediaRecorder::recorderState
+ \brief The current state of the media recorder.
- return d_func()->audioControl ?
- d_func()->audioControl->supportedSampleRates(settings, continuous) : QList<int>();
-}
+ The state property represents the user request and is changed synchronously
+ during record(), pause() or stop() calls.
+ Recorder state may also change asynchronously when recording fails.
+*/
/*!
- Returns a list of resolutions video can be encoded at.
+ \qmlsignal QtMultimedia::MediaRecorder::recorderStateChanged(RecorderState state)
+ \brief Signals that a media recorder's \a state has changed.
+*/
- If non null video \a settings parameter is passed, the returned list is
- reduced to resolution supported with partial settings like video codec or
- framerate applied.
+/*!
+ \fn QMediaRecorder::recorderStateChanged(QMediaRecorder::RecorderState state)
- If the encoder supports arbitrary resolutions within the supported range,
- *\a continuous is set to true, otherwise *\a continuous is set to false.
+ Signals that a media recorder's \a state has changed.
+*/
- \sa QVideoEncoderSettings::resolution()
+/*!
+ \qmlsignal QtMultimedia::MediaRecorder::durationChanged(qint64 duration)
+ \brief Signals that the \a duration of the recorded media has changed.
*/
-QList<QSize> QMediaRecorder::supportedResolutions(const QVideoEncoderSettings &settings, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
- return d_func()->videoControl ?
- d_func()->videoControl->supportedResolutions(settings, continuous) : QList<QSize>();
-}
+/*!
+ \fn QMediaRecorder::durationChanged(qint64 duration)
+ Signals that the \a duration of the recorded media has changed.
+*/
/*!
- Returns a list of frame rates video can be encoded at.
+ \qmlsignal QtMultimedia::MediaRecorder::actualLocationChanged(const QUrl &location)
+ \brief Signals that the actual \a location of the recorded media has changed.
- If non null video \a settings parameter is passed, the returned list is
- reduced to frame rates supported with partial settings like video codec or
- resolution applied.
+ This signal is usually emitted when recording starts.
+*/
+/*!
+ \fn QMediaRecorder::actualLocationChanged(const QUrl &location)
- If the encoder supports arbitrary frame rates within the supported range,
- *\a continuous is set to true, otherwise *\a continuous is set to false.
+ Signals that the actual \a location of the recorded media has changed.
+ This signal is usually emitted when recording starts.
+*/
+/*!
+ \qmlsignal QtMultimedia::MediaRecorder::errorOccurred(Error error, const QString &errorString)
+ \brief Signals that an \a error has occurred.
- \sa QVideoEncoderSettings::frameRate()
+ The \a errorString contains a description of the error.
*/
-QList<qreal> QMediaRecorder::supportedFrameRates(const QVideoEncoderSettings &settings, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
+/*!
+ \fn QMediaRecorder::errorOccurred(QMediaRecorder::Error error, const QString &errorString)
- return d_func()->videoControl ?
- d_func()->videoControl->supportedFrameRates(settings, continuous) : QList<qreal>();
-}
+ Signals that an \a error has occurred, with \a errorString containing
+ a description of the error.
+*/
/*!
- Returns a list of supported video codecs.
+ \qmlproperty mediaMetaData QtMultimedia::MediaRecorder::metaData
+
+ \brief This property holds meta data associated with the recording.
+
+ When a recording is started, any meta-data assigned will be attached to that
+ recording.
+
+ \note Ensure that meta-data is assigned correctly by assigning it before
+ starting the recording.
+
+ \sa mediaMetaData
*/
-QStringList QMediaRecorder::supportedVideoCodecs() const
-{
- return d_func()->videoControl ?
- d_func()->videoControl->supportedVideoCodecs() : QStringList();
-}
/*!
- Returns a description of a video \a codec.
+ \property QMediaRecorder::metaData
- \sa setEncodingSettings()
+ Returns the metaData associated with the recording.
*/
-QString QMediaRecorder::videoCodecDescription(const QString &codec) const
+QMediaMetaData QMediaRecorder::metaData() const
{
- return d_func()->videoControl ?
- d_func()->videoControl->videoCodecDescription(codec) : QString();
+ Q_D(const QMediaRecorder);
+
+ return d->control ? d->control->metaData() : QMediaMetaData{};
}
/*!
- Returns the audio encoder settings being used.
+ Sets the meta data to \a metaData.
- \sa setEncodingSettings()
+ \note To ensure that meta-data is set correctly, it should be set before starting the recording.
+ Once the recording is started, any meta-data set will be attached to the next recording.
*/
-
-QAudioEncoderSettings QMediaRecorder::audioSettings() const
+void QMediaRecorder::setMetaData(const QMediaMetaData &metaData)
{
- return d_func()->audioControl ?
- d_func()->audioControl->audioSettings() : QAudioEncoderSettings();
+ Q_D(QMediaRecorder);
+
+ if (d->control && d->captureSession)
+ d->control->setMetaData(metaData);
}
/*!
- Returns the video encoder settings being used.
-
- \sa setEncodingSettings()
+ Adds \a metaData to the recorded media.
*/
-
-QVideoEncoderSettings QMediaRecorder::videoSettings() const
+void QMediaRecorder::addMetaData(const QMediaMetaData &metaData)
{
- return d_func()->videoControl ?
- d_func()->videoControl->videoSettings() : QVideoEncoderSettings();
+ auto data = this->metaData();
+ // merge data
+ for (const auto &k : metaData.keys())
+ data.insert(k, metaData.value(k));
+ setMetaData(data);
}
/*!
- Sets the audio encoder \a settings.
+ \property QMediaRecorder::autoStop
- If some parameters are not specified, or null settings are passed, the
- encoder will choose default encoding parameters, depending on media
- source properties.
+ This property controls whether the media recorder stops automatically when
+ all media inputs have reported the end of the stream or have been deactivated.
- It's only possible to change settings when the encoder is in the
- QMediaEncoder::StoppedState state.
+ The end of the stream is reported by sending an empty media frame,
+ which you can send explicitly via \l QVideoFrameInput or \l QAudioBufferInput.
- \sa audioSettings(), videoSettings(), containerFormat()
+ Video inputs, specificly, \l QCamera, \l QScreenCapture and \l QWindowCapture,
+ can be deactivated via the function \c setActive.
+
+ Defaults to \c false.
+
+ \sa QCamera, QScreenCapture, QWindowCapture
*/
-void QMediaRecorder::setAudioSettings(const QAudioEncoderSettings &settings)
+bool QMediaRecorder::autoStop() const
+{
+ Q_D(const QMediaRecorder);
+
+ return d->autoStop;
+}
+
+void QMediaRecorder::setAutoStop(bool autoStop)
{
Q_D(QMediaRecorder);
- //restart camera if it can't apply new settings in the Active state
- d->restartCamera();
+ if (d->autoStop == autoStop)
+ return;
- if (d->audioControl) {
- d->audioControl->setAudioSettings(settings);
- d->applySettingsLater();
- }
+ d->autoStop = autoStop;
+ emit autoStopChanged();
}
/*!
- Sets the video encoder \a settings.
-
- If some parameters are not specified, or null settings are passed, the
- encoder will choose default encoding parameters, depending on media
- source properties.
+ \qmlsignal QtMultimedia::MediaRecorder::metaDataChanged()
- It's only possible to change settings when the encoder is in the
- QMediaEncoder::StoppedState state.
+ \brief Signals that a media object's meta-data has changed.
- \sa audioSettings(), videoSettings(), containerFormat()
+ If multiple meta-data elements are changed metaDataChanged() is emitted
+ once.
*/
+/*!
+ \fn QMediaRecorder::metaDataChanged()
-void QMediaRecorder::setVideoSettings(const QVideoEncoderSettings &settings)
-{
- Q_D(QMediaRecorder);
+ Signals that a media object's meta-data has changed.
- d->restartCamera();
+ If multiple meta-data elements are changed metaDataChanged() is emitted
+ once.
+*/
- if (d->videoControl) {
- d->videoControl->setVideoSettings(settings);
- d->applySettingsLater();
- }
+/*!
+ Returns the media capture session.
+*/
+QMediaCaptureSession *QMediaRecorder::captureSession() const
+{
+ Q_D(const QMediaRecorder);
+ return d->captureSession;
}
-
/*!
- Sets the media \a container format.
+ \qmlproperty enumeration QtMultimedia::MediaRecorder::quality
- If the container format is not specified, the
- encoder will choose format, depending on media source properties
- and encoding settings selected.
+ Enumerates quality encoding levels.
- It's only possible to change settings when the encoder is in the
- QMediaEncoder::StoppedState state.
+ \value MediaRecorder.VeryLowQuality
+ \value MediaRecorder.LowQuality
+ \value MediaRecorder.NormalQuality
+ \value MediaRecorder.HighQuality
+ \value MediaRecorder.VeryHighQuality
+*/
+/*!
+ \enum QMediaRecorder::Quality
- \sa audioSettings(), videoSettings(), containerFormat()
+ Enumerates quality encoding levels.
+
+ \value VeryLowQuality
+ \value LowQuality
+ \value NormalQuality
+ \value HighQuality
+ \value VeryHighQuality
*/
-void QMediaRecorder::setContainerFormat(const QString &container)
-{
- Q_D(QMediaRecorder);
+/*!
+ \enum QMediaRecorder::EncodingMode
- d->restartCamera();
+ Enumerates encoding modes.
- if (d->formatControl) {
- d->formatControl->setContainerFormat(container);
- d->applySettingsLater();
- }
-}
+ \value ConstantQualityEncoding Encoding will aim to have a constant quality, adjusting bitrate to fit.
+ \value ConstantBitRateEncoding Encoding will use a constant bit rate, adjust quality to fit.
+ \value AverageBitRateEncoding Encoding will try to keep an average bitrate setting, but will use
+ more or less as needed.
+ \value TwoPassEncoding The media will first be processed to determine the characteristics,
+ and then processed a second time allocating more bits to the areas
+ that need it.
+*/
/*!
- Sets the \a audio and \a video encoder settings and \a container format.
- If some parameters are not specified, or null settings are passed, the
- encoder will choose default encoding parameters, depending on media
- source properties.
+ \qmlproperty MediaFormat QtMultimedia::MediaRecorder::mediaFormat
- It's only possible to change settings when the encoder is in the
- QMediaEncoder::StoppedState state.
+ \brief This property holds the current MediaFormat of the recorder.
+*/
+/*!
+ \property QMediaRecorder::mediaFormat
- \sa audioSettings(), videoSettings(), containerFormat()
+ Returns the recording media format.
*/
+QMediaFormat QMediaRecorder::mediaFormat() const
+{
+ Q_D(const QMediaRecorder);
+ return d->encoderSettings.mediaFormat();
+}
-void QMediaRecorder::setEncodingSettings(const QAudioEncoderSettings &audio,
- const QVideoEncoderSettings &video,
- const QString &container)
+void QMediaRecorder::setMediaFormat(const QMediaFormat &format)
{
Q_D(QMediaRecorder);
+ if (d->encoderSettings.mediaFormat() == format)
+ return;
+ d->encoderSettings.setMediaFormat(format);
+ emit mediaFormatChanged();
+}
- d->restartCamera();
-
- if (d->audioControl)
- d->audioControl->setAudioSettings(audio);
+/*!
- if (d->videoControl)
- d->videoControl->setVideoSettings(video);
+ \qmlproperty enumeration QtMultimedia::MediaRecorder::encodingMode
+ \since 6.6
+ \brief This property holds the encoding mode.
+ \sa QMediaRecorder::EncodingMode
+*/
- if (d->formatControl)
- d->formatControl->setContainerFormat(container);
+/*!
+ Returns the encoding mode.
- d->applySettingsLater();
+ \sa EncodingMode
+*/
+QMediaRecorder::EncodingMode QMediaRecorder::encodingMode() const
+{
+ Q_D(const QMediaRecorder);
+ return d->encoderSettings.encodingMode();
}
/*!
- Start recording.
-
- While the recorder state is changed immediately to QMediaRecorder::RecordingState,
- recording may start asynchronously, with statusChanged(QMediaRecorder::RecordingStatus)
- signal emitted when recording starts.
+ \fn void QMediaRecorder::encodingModeChanged()
- If recording fails error() signal is emitted
- with recorder state being reset back to QMediaRecorder::StoppedState.
+ Signals when the encoding mode changes.
*/
+/*!
+ Sets the encoding \a mode setting.
-void QMediaRecorder::record()
+ If ConstantQualityEncoding is set, the quality
+ encoding parameter is used and bit rates are ignored,
+ otherwise the bitrates are used.
+
+ \sa encodingMode(), EncodingMode
+*/
+void QMediaRecorder::setEncodingMode(EncodingMode mode)
{
Q_D(QMediaRecorder);
-
- d->actualLocation.clear();
-
- if (d->settingsChanged)
- d->_q_applySettings();
-
- // reset error
- d->error = NoError;
- d->errorString = QString();
-
- if (d->control)
- d->control->setState(RecordingState);
+ if (d->encoderSettings.encodingMode() == mode)
+ return;
+ d->encoderSettings.setEncodingMode(mode);
+ emit encodingModeChanged();
}
/*!
- Pause recording.
-
- The recorder state is changed to QMediaRecorder::PausedState.
+ \property QMediaRecorder::quality
- Depending on platform recording pause may be not supported,
- in this case the recorder state stays unchanged.
+ Returns the recording quality.
*/
-
-void QMediaRecorder::pause()
+QMediaRecorder::Quality QMediaRecorder::quality() const
{
- Q_D(QMediaRecorder);
- if (d->control)
- d->control->setState(PausedState);
+ Q_D(const QMediaRecorder);
+ return d->encoderSettings.quality();
}
/*!
- Stop recording.
+ \fn void QMediaRecorder::qualityChanged()
- The recorder state is changed to QMediaRecorder::StoppedState.
+ Signals when the recording quality changes.
*/
-
-void QMediaRecorder::stop()
+void QMediaRecorder::setQuality(Quality quality)
{
Q_D(QMediaRecorder);
- if (d->control)
- d->control->setState(StoppedState);
+ if (d->encoderSettings.quality() == quality)
+ return;
+ d->encoderSettings.setQuality(quality);
+ emit qualityChanged();
}
/*!
- \enum QMediaRecorder::State
+ \qmlproperty Size QtMultimedia::MediaRecorder::videoResolution
+ \since 6.6
+ \brief This property holds the resolution of the encoded video.
- \value StoppedState The recorder is not active.
- If this is the state after recording then the actual created recording has
- finished being written to the final location and is ready on all platforms
- except on Android. On Android, due to platform limitations, there is no way
- to be certain that the recording has finished writing to the final location.
- \value RecordingState The recording is requested.
- \value PausedState The recorder is paused.
+ Set an empty Size to make the recorder choose an optimal resolution based
+ on what is available from the video source and the limitations of the codec.
*/
-/*!
- \enum QMediaRecorder::Status
- \value UnavailableStatus
- The recorder is not available or not supported by connected media object.
- \value UnloadedStatus
- The recorder is avilable but not loaded.
- \value LoadingStatus
- The recorder is initializing.
- \value LoadedStatus
- The recorder is initialized and ready to record media.
- \value StartingStatus
- Recording is requested but not active yet.
- \value RecordingStatus
- Recording is active.
- \value PausedStatus
- Recording is paused.
- \value FinalizingStatus
- Recording is stopped with media being finalized.
+/*!
+ Returns the resolution of the encoded video.
*/
+QSize QMediaRecorder::videoResolution() const
+{
+ Q_D(const QMediaRecorder);
+ return d->encoderSettings.videoResolution();
+}
/*!
- \enum QMediaRecorder::Error
+ \fn void QMediaRecorder::videoResolutionChanged()
- \value NoError No Errors.
- \value ResourceError Device is not ready or not available.
- \value FormatError Current format is not supported.
- \value OutOfSpaceError No space left on device.
+ Signals when the video recording resolution changes.
*/
-
/*!
- \property QMediaRecorder::state
- \brief The current state of the media recorder.
+ Sets the resolution of the encoded video to \a{size}.
- The state property represents the user request and is changed synchronously
- during record(), pause() or stop() calls.
- Recorder state may also change asynchronously when recording fails.
+ Pass an empty QSize to make the recorder choose an optimal resolution based
+ on what is available from the video source and the limitations of the codec.
*/
+void QMediaRecorder::setVideoResolution(const QSize &size)
+{
+ Q_D(QMediaRecorder);
+ if (d->encoderSettings.videoResolution() == size)
+ return;
+ d->encoderSettings.setVideoResolution(size);
+ emit videoResolutionChanged();
+}
-/*!
- \property QMediaRecorder::status
- \brief The current status of the media recorder.
+/*! \fn void QMediaRecorder::setVideoResolution(int width, int height)
- The status is changed asynchronously and represents the actual status
- of media recorder.
+ Sets the \a width and \a height of the resolution of the encoded video.
+
+ \overload
*/
/*!
- \fn QMediaRecorder::stateChanged(State state)
+ \qmlproperty real QtMultimedia::MediaRecorder::videoFrameRate
+ \since 6.6
+ \brief This property holds the video frame rate.
- Signals that a media recorder's \a state has changed.
+ A value of 0 indicates the recorder should make an optimal choice based on what is available
+ from the video source and the limitations of the codec.
*/
/*!
- \fn QMediaRecorder::durationChanged(qint64 duration)
-
- Signals that the \a duration of the recorded media has changed.
+ Returns the video frame rate.
*/
+qreal QMediaRecorder::videoFrameRate() const
+{
+ Q_D(const QMediaRecorder);
+ return d->encoderSettings.videoFrameRate();
+}
/*!
- \fn QMediaRecorder::actualLocationChanged(const QUrl &location)
+ \fn void QMediaRecorder::videoFrameRateChanged()
- Signals that the actual \a location of the recorded media has changed.
- This signal is usually emitted when recording starts.
+ Signals when the recording video frame rate changes.
*/
-
/*!
- \fn QMediaRecorder::error(QMediaRecorder::Error error)
+ Sets the video \a frameRate.
- Signals that an \a error has occurred.
+ A value of 0 indicates the recorder should make an optimal choice based on what is available
+ from the video source and the limitations of the codec.
*/
+void QMediaRecorder::setVideoFrameRate(qreal frameRate)
+{
+ Q_D(QMediaRecorder);
+ if (d->encoderSettings.videoFrameRate() == frameRate)
+ return;
+ d->encoderSettings.setVideoFrameRate(frameRate);
+ emit videoFrameRateChanged();
+}
/*!
- \fn QMediaRecorder::availabilityChanged(bool available)
-
- Signals that the media recorder is now available (if \a available is true), or not.
+ \qmlproperty int QtMultimedia::MediaRecorder::videoBitRate
+ \since 6.6
+ \brief This property holds the bit rate of the compressed video stream in bits per second.
*/
/*!
- \fn QMediaRecorder::availabilityChanged(QMultimedia::AvailabilityStatus availability)
-
- Signals that the service availability has changed to \a availability.
+ Returns the bit rate of the compressed video stream in bits per second.
*/
+int QMediaRecorder::videoBitRate() const
+{
+ Q_D(const QMediaRecorder);
+ return d->encoderSettings.videoBitRate();
+}
/*!
- \fn QMediaRecorder::mutedChanged(bool muted)
+ \fn void QMediaRecorder::videoBitRateChanged()
- Signals that the \a muted state has changed. If true the recording is being muted.
+ Signals when the recording video bit rate changes.
*/
-
/*!
- \property QMediaRecorder::metaDataAvailable
- \brief whether access to a media object's meta-data is available.
+ Sets the video \a bitRate in bits per second.
+*/
+void QMediaRecorder::setVideoBitRate(int bitRate)
+{
+ Q_D(QMediaRecorder);
+ if (d->encoderSettings.videoBitRate() == bitRate)
+ return;
+ d->encoderSettings.setVideoBitRate(bitRate);
+ emit videoBitRateChanged();
+}
- If this is true there is meta-data available, otherwise there is no meta-data available.
+/*!
+ \qmlproperty int QtMultimedia::MediaRecorder::audioBitRate
+ \since 6.6
+ \brief This property holds the bit rate of the compressed audio stream in bits per second.
*/
-bool QMediaRecorder::isMetaDataAvailable() const
+/*!
+ Returns the bit rate of the compressed audio stream in bits per second.
+*/
+int QMediaRecorder::audioBitRate() const
{
Q_D(const QMediaRecorder);
-
- return d->metaDataControl
- ? d->metaDataControl->isMetaDataAvailable()
- : false;
+ return d->encoderSettings.audioBitRate();
}
/*!
- \fn QMediaRecorder::metaDataAvailableChanged(bool available)
+ \fn void QMediaRecorder::audioBitRateChanged()
- Signals that the \a available state of a media object's meta-data has changed.
+ Signals when the recording audio bit rate changes.
*/
-
/*!
- \property QMediaRecorder::metaDataWritable
- \brief whether a media object's meta-data is writable.
-
- If this is true the meta-data is writable, otherwise the meta-data is read-only.
+ Sets the audio \a bitRate in bits per second.
*/
-
-bool QMediaRecorder::isMetaDataWritable() const
+void QMediaRecorder::setAudioBitRate(int bitRate)
{
- Q_D(const QMediaRecorder);
-
- return d->metaDataControl
- ? d->metaDataControl->isWritable()
- : false;
+ Q_D(QMediaRecorder);
+ if (d->encoderSettings.audioBitRate() == bitRate)
+ return;
+ d->encoderSettings.setAudioBitRate(bitRate);
+ emit audioBitRateChanged();
}
/*!
- \fn QMediaRecorder::metaDataWritableChanged(bool writable)
-
- Signals that the \a writable state of a media object's meta-data has changed.
+ \qmlproperty int QtMultimedia::MediaRecorder::audioChannelCount
+ \since 6.6
+ \brief This property holds the number of audio channels.
*/
/*!
- Returns the value associated with a meta-data \a key.
+ Returns the number of audio channels.
*/
-QVariant QMediaRecorder::metaData(const QString &key) const
+int QMediaRecorder::audioChannelCount() const
{
Q_D(const QMediaRecorder);
-
- return d->metaDataControl
- ? d->metaDataControl->metaData(key)
- : QVariant();
+ return d->encoderSettings.audioChannelCount();
}
/*!
- Sets a \a value for a meta-data \a key.
+ \fn void QMediaRecorder::audioChannelCountChanged()
- \note To ensure that meta data is set corretly, it should be set before starting the recording.
- Once the recording is stopped, any meta data set will be attached to the next recording.
+ Signals when the recording audio channel count changes.
*/
-void QMediaRecorder::setMetaData(const QString &key, const QVariant &value)
+/*!
+ Sets the number of audio \a channels.
+
+ A value of -1 indicates the recorder should make an optimal choice based on
+ what is available from the audio source and the limitations of the codec.
+*/
+void QMediaRecorder::setAudioChannelCount(int channels)
{
Q_D(QMediaRecorder);
-
- if (d->metaDataControl)
- d->metaDataControl->setMetaData(key, value);
+ if (d->encoderSettings.audioChannelCount() == channels)
+ return;
+ d->encoderSettings.setAudioChannelCount(channels);
+ emit audioChannelCountChanged();
}
/*!
- Returns a list of keys there is meta-data available for.
+ \qmlproperty int QtMultimedia::MediaRecorder::audioSampleRate
+ \since 6.6
+ \brief This property holds the audio sample rate in Hz.
+*/
+
+/*!
+ Returns the audio sample rate in Hz.
*/
-QStringList QMediaRecorder::availableMetaData() const
+int QMediaRecorder::audioSampleRate() const
{
Q_D(const QMediaRecorder);
-
- return d->metaDataControl
- ? d->metaDataControl->availableMetaData()
- : QStringList();
+ return d->encoderSettings.audioSampleRate();
}
-
/*!
- \fn QMediaRecorder::metaDataChanged()
+ \fn void QMediaRecorder::audioSampleRateChanged()
- Signals that a media object's meta-data has changed.
-
- If multiple meta-data elements are changed,
- metaDataChanged(const QString &key, const QVariant &value) signal is emitted
- for each of them with metaDataChanged() changed emitted once.
+ Signals when the recording audio sample rate changes.
*/
-
/*!
- \fn QMediaRecorder::metaDataChanged(const QString &key, const QVariant &value)
+ Sets the audio \a sampleRate in Hz.
- Signal the changes of one meta-data element \a value with the given \a key.
+ A value of \c -1 indicates the recorder should make an optimal choice based
+ on what is available from the audio source, and the limitations of the codec.
*/
+void QMediaRecorder::setAudioSampleRate(int sampleRate)
+{
+ Q_D(QMediaRecorder);
+ if (d->encoderSettings.audioSampleRate() == sampleRate)
+ return;
+ d->encoderSettings.setAudioSampleRate(sampleRate);
+ emit audioSampleRateChanged();
+}
QT_END_NAMESPACE
diff --git a/src/multimedia/recording/qmediarecorder.h b/src/multimedia/recording/qmediarecorder.h
index 0fdcf80e4..a73d9f8af 100644
--- a/src/multimedia/recording/qmediarecorder.h
+++ b/src/multimedia/recording/qmediarecorder.h
@@ -1,50 +1,14 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIARECORDER_H
-#define QMEDIARECORDER_H
-
-#include <QtMultimedia/qmultimedia.h>
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmediaencodersettings.h>
-#include <QtMultimedia/qmediabindableinterface.h>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QMediaRecorder_H
+#define QMediaRecorder_H
+
+#include <QtCore/qobject.h>
+#include <QtCore/qsize.h>
+#include <QtMultimedia/qtmultimediaglobal.h>
#include <QtMultimedia/qmediaenumdebug.h>
+#include <QtMultimedia/qmediametadata.h>
#include <QtCore/qpair.h>
@@ -53,171 +17,168 @@ QT_BEGIN_NAMESPACE
class QUrl;
class QSize;
class QAudioFormat;
-QT_END_NAMESPACE
-
-QT_BEGIN_NAMESPACE
-
-class QMediaRecorderService;
-class QAudioEncoderSettings;
-class QVideoEncoderSettings;
+class QCamera;
+class QCameraDevice;
+class QMediaFormat;
+class QAudioDevice;
+class QMediaCaptureSession;
+class QPlatformMediaRecorder;
class QMediaRecorderPrivate;
-class Q_MULTIMEDIA_EXPORT QMediaRecorder : public QObject, public QMediaBindableInterface
+class Q_MULTIMEDIA_EXPORT QMediaRecorder : public QObject
{
Q_OBJECT
- Q_INTERFACES(QMediaBindableInterface)
- Q_ENUMS(State)
- Q_ENUMS(Status)
- Q_ENUMS(Error)
- Q_PROPERTY(QMediaRecorder::State state READ state NOTIFY stateChanged)
- Q_PROPERTY(QMediaRecorder::Status status READ status NOTIFY statusChanged)
+ Q_PROPERTY(QMediaRecorder::RecorderState recorderState READ recorderState NOTIFY recorderStateChanged)
Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
Q_PROPERTY(QUrl outputLocation READ outputLocation WRITE setOutputLocation)
Q_PROPERTY(QUrl actualLocation READ actualLocation NOTIFY actualLocationChanged)
- Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
- Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged)
- Q_PROPERTY(bool metaDataAvailable READ isMetaDataAvailable NOTIFY metaDataAvailableChanged)
- Q_PROPERTY(bool metaDataWritable READ isMetaDataWritable NOTIFY metaDataWritableChanged)
+ Q_PROPERTY(QMediaMetaData metaData READ metaData WRITE setMetaData NOTIFY metaDataChanged)
+ Q_PROPERTY(QMediaRecorder::Error error READ error NOTIFY errorChanged)
+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
+ Q_PROPERTY(QMediaFormat mediaFormat READ mediaFormat WRITE setMediaFormat NOTIFY mediaFormatChanged)
+ Q_PROPERTY(Quality quality READ quality WRITE setQuality NOTIFY qualityChanged)
+ Q_PROPERTY(QMediaRecorder::EncodingMode encodingMode READ encodingMode WRITE setEncodingMode NOTIFY encodingModeChanged)
+ Q_PROPERTY(QSize videoResolution READ videoResolution WRITE setVideoResolution NOTIFY videoResolutionChanged)
+ Q_PROPERTY(qreal videoFrameRate READ videoFrameRate WRITE setVideoFrameRate NOTIFY videoFrameRateChanged)
+ Q_PROPERTY(int videoBitRate READ videoBitRate WRITE setVideoBitRate NOTIFY videoBitRateChanged)
+ Q_PROPERTY(int audioBitRate READ audioBitRate WRITE setAudioBitRate NOTIFY audioBitRateChanged)
+ Q_PROPERTY(int audioChannelCount READ audioChannelCount WRITE setAudioChannelCount NOTIFY audioChannelCountChanged)
+ Q_PROPERTY(int audioSampleRate READ audioSampleRate WRITE setAudioSampleRate NOTIFY audioSampleRateChanged)
+ Q_PROPERTY(bool autoStop READ autoStop WRITE setAutoStop NOTIFY autoStopChanged)
public:
+ enum Quality
+ {
+ VeryLowQuality,
+ LowQuality,
+ NormalQuality,
+ HighQuality,
+ VeryHighQuality
+ };
+ Q_ENUM(Quality)
- enum State
+ enum EncodingMode
+ {
+ ConstantQualityEncoding,
+ ConstantBitRateEncoding,
+ AverageBitRateEncoding,
+ TwoPassEncoding
+ };
+ Q_ENUM(EncodingMode)
+
+ enum RecorderState
{
StoppedState,
RecordingState,
PausedState
};
-
- enum Status {
- UnavailableStatus,
- UnloadedStatus,
- LoadingStatus,
- LoadedStatus,
- StartingStatus,
- RecordingStatus,
- PausedStatus,
- FinalizingStatus
- };
+ Q_ENUM(RecorderState)
enum Error
{
NoError,
ResourceError,
FormatError,
- OutOfSpaceError
+ OutOfSpaceError,
+ LocationNotWritable
};
+ Q_ENUM(Error)
- explicit QMediaRecorder(QMediaObject *mediaObject, QObject *parent = nullptr);
+ QMediaRecorder(QObject *parent = nullptr);
~QMediaRecorder();
- QMediaObject *mediaObject() const override;
-
bool isAvailable() const;
- QMultimedia::AvailabilityStatus availability() const;
QUrl outputLocation() const;
- bool setOutputLocation(const QUrl &location);
+ void setOutputLocation(const QUrl &location);
+
+ void setOutputDevice(QIODevice *device);
+ QIODevice *outputDevice() const;
QUrl actualLocation() const;
- State state() const;
- Status status() const;
+ RecorderState recorderState() const;
Error error() const;
QString errorString() const;
qint64 duration() const;
- bool isMuted() const;
- qreal volume() const;
+ QMediaFormat mediaFormat() const;
+ void setMediaFormat(const QMediaFormat &format);
- QStringList supportedContainers() const;
- QString containerDescription(const QString &format) const;
+ EncodingMode encodingMode() const;
+ void setEncodingMode(EncodingMode);
- QStringList supportedAudioCodecs() const;
- QString audioCodecDescription(const QString &codecName) const;
+ Quality quality() const;
+ void setQuality(Quality quality);
- QList<int> supportedAudioSampleRates(const QAudioEncoderSettings &settings = QAudioEncoderSettings(),
- bool *continuous = nullptr) const;
+ QSize videoResolution() const;
+ void setVideoResolution(const QSize &);
+ void setVideoResolution(int width, int height) { setVideoResolution(QSize(width, height)); }
- QStringList supportedVideoCodecs() const;
- QString videoCodecDescription(const QString &codecName) const;
+ qreal videoFrameRate() const;
+ void setVideoFrameRate(qreal frameRate);
- QList<QSize> supportedResolutions(const QVideoEncoderSettings &settings = QVideoEncoderSettings(),
- bool *continuous = nullptr) const;
+ int videoBitRate() const;
+ void setVideoBitRate(int bitRate);
- QList<qreal> supportedFrameRates(const QVideoEncoderSettings &settings = QVideoEncoderSettings(),
- bool *continuous = nullptr) const;
+ int audioBitRate() const;
+ void setAudioBitRate(int bitRate);
- QAudioEncoderSettings audioSettings() const;
- QVideoEncoderSettings videoSettings() const;
- QString containerFormat() const;
+ int audioChannelCount() const;
+ void setAudioChannelCount(int channels);
- void setAudioSettings(const QAudioEncoderSettings &audioSettings);
- void setVideoSettings(const QVideoEncoderSettings &videoSettings);
- void setContainerFormat(const QString &container);
+ int audioSampleRate() const;
+ void setAudioSampleRate(int sampleRate);
- void setEncodingSettings(const QAudioEncoderSettings &audioSettings,
- const QVideoEncoderSettings &videoSettings = QVideoEncoderSettings(),
- const QString &containerMimeType = QString());
+ QMediaMetaData metaData() const;
+ void setMetaData(const QMediaMetaData &metaData);
+ void addMetaData(const QMediaMetaData &metaData);
- bool isMetaDataAvailable() const;
- bool isMetaDataWritable() const;
+ bool autoStop() const;
+ void setAutoStop(bool autoStop);
- QVariant metaData(const QString &key) const;
- void setMetaData(const QString &key, const QVariant &value);
- QStringList availableMetaData() const;
+ QMediaCaptureSession *captureSession() const;
+ QPlatformMediaRecorder *platformRecoder() const;
public Q_SLOTS:
void record();
void pause();
void stop();
- void setMuted(bool muted);
- void setVolume(qreal volume);
Q_SIGNALS:
- void stateChanged(QMediaRecorder::State state);
- void statusChanged(QMediaRecorder::Status status);
+ void recorderStateChanged(RecorderState state);
void durationChanged(qint64 duration);
- void mutedChanged(bool muted);
- void volumeChanged(qreal volume);
void actualLocationChanged(const QUrl &location);
+ void encoderSettingsChanged();
- void error(QMediaRecorder::Error error);
+ void errorOccurred(Error error, const QString &errorString);
+ void errorChanged();
- void metaDataAvailableChanged(bool available);
- void metaDataWritableChanged(bool writable);
void metaDataChanged();
- void metaDataChanged(const QString &key, const QVariant &value);
- void availabilityChanged(bool available);
- void availabilityChanged(QMultimedia::AvailabilityStatus availability);
+ void mediaFormatChanged();
+ void encodingModeChanged();
+ void qualityChanged();
+ void videoResolutionChanged();
+ void videoFrameRateChanged();
+ void videoBitRateChanged();
+ void audioBitRateChanged();
+ void audioChannelCountChanged();
+ void audioSampleRateChanged();
+ void autoStopChanged();
-protected:
- QMediaRecorder(QMediaRecorderPrivate &dd, QMediaObject *mediaObject, QObject *parent = nullptr);
- bool setMediaObject(QMediaObject *object) override;
-
- QMediaRecorderPrivate *d_ptr;
private:
+ QMediaRecorderPrivate *d_ptr;
+ friend class QMediaCaptureSession;
+ void setCaptureSession(QMediaCaptureSession *session);
Q_DISABLE_COPY(QMediaRecorder)
Q_DECLARE_PRIVATE(QMediaRecorder)
- Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QMediaRecorder::State))
- Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &))
- Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed())
- Q_PRIVATE_SLOT(d_func(), void _q_notify())
- Q_PRIVATE_SLOT(d_func(), void _q_updateActualLocation(const QUrl &))
- Q_PRIVATE_SLOT(d_func(), void _q_updateNotifyInterval(int))
- Q_PRIVATE_SLOT(d_func(), void _q_applySettings())
- Q_PRIVATE_SLOT(d_func(), void _q_availabilityChanged(QMultimedia::AvailabilityStatus))
};
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QMediaRecorder::State)
-Q_DECLARE_METATYPE(QMediaRecorder::Status)
-Q_DECLARE_METATYPE(QMediaRecorder::Error)
-
-Q_MEDIA_ENUM_DEBUG(QMediaRecorder, State)
-Q_MEDIA_ENUM_DEBUG(QMediaRecorder, Status)
+Q_MEDIA_ENUM_DEBUG(QMediaRecorder, RecorderState)
Q_MEDIA_ENUM_DEBUG(QMediaRecorder, Error)
-#endif // QMEDIARECORDER_H
+#endif // QMediaRecorder_H
diff --git a/src/multimedia/recording/qmediarecorder_p.h b/src/multimedia/recording/qmediarecorder_p.h
index f634d016e..896f6c368 100644
--- a/src/multimedia/recording/qmediarecorder_p.h
+++ b/src/multimedia/recording/qmediarecorder_p.h
@@ -1,44 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMEDIARECORDER_P_H
-#define QMEDIARECORDER_P_H
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QMediaRecorder_P_H
+#define QMediaRecorder_P_H
//
// W A R N I N G
@@ -52,60 +16,39 @@
//
#include "qmediarecorder.h"
-#include "qmediaobject_p.h"
+#include "qcamera.h"
#include <QtCore/qurl.h>
+#include <QtCore/qpointer.h>
+#include "private/qplatformmediarecorder_p.h"
QT_BEGIN_NAMESPACE
-class QMediaRecorderControl;
-class QMediaContainerControl;
-class QAudioEncoderSettingsControl;
-class QVideoEncoderSettingsControl;
-class QMetaDataWriterControl;
-class QMediaAvailabilityControl;
+class QPlatformMediaRecorder;
class QTimer;
-class QMediaRecorderPrivate
+class Q_MULTIMEDIA_EXPORT QMediaRecorderPrivate
{
- Q_DECLARE_NON_CONST_PUBLIC(QMediaRecorder)
+ Q_DECLARE_PUBLIC(QMediaRecorder)
public:
QMediaRecorderPrivate();
- virtual ~QMediaRecorderPrivate() {}
-
- void applySettingsLater();
- void restartCamera();
-
- QMediaObject *mediaObject;
- QMediaRecorderControl *control;
- QMediaContainerControl *formatControl;
- QAudioEncoderSettingsControl *audioControl;
- QVideoEncoderSettingsControl *videoControl;
- QMetaDataWriterControl *metaDataControl;
- QMediaAvailabilityControl *availabilityControl;
+ static QString msgFailedStartRecording();
- bool settingsChanged;
+ QMediaCaptureSession *captureSession = nullptr;
+ QPlatformMediaRecorder *control = nullptr;
+ QString initErrorMessage;
+ bool autoStop = false;
- QTimer* notifyTimer;
+ bool settingsChanged = false;
- QMediaRecorder::State state;
- QMediaRecorder::Error error;
- QString errorString;
- QUrl actualLocation;
+ QMediaEncoderSettings encoderSettings;
- void _q_stateChanged(QMediaRecorder::State state);
- void _q_error(int error, const QString &errorString);
- void _q_serviceDestroyed();
- void _q_updateActualLocation(const QUrl &);
- void _q_notify();
- void _q_updateNotifyInterval(int ms);
- void _q_applySettings();
- void _q_availabilityChanged(QMultimedia::AvailabilityStatus availability);
-
- QMediaRecorder *q_ptr;
+ QMediaRecorder *q_ptr = nullptr;
};
+#undef Q_DECLARE_NON_CONST_PUBLIC
+
QT_END_NAMESPACE
#endif
diff --git a/src/multimedia/recording/qscreencapture-limitations.qdocinc b/src/multimedia/recording/qscreencapture-limitations.qdocinc
new file mode 100644
index 000000000..240a1a389
--- /dev/null
+++ b/src/multimedia/recording/qscreencapture-limitations.qdocinc
@@ -0,0 +1,25 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ //! [content]
+ \section1 Screen Capture Limitations
+ On Qt 6.5.2 and above, the following limitations apply to using \1ScreenCapture:
+ \list
+ \li It is only supported with the FFmpeg backend.
+ \li It is unsupported on Linux with Wayland compositor, due to Wayland
+ protocol restrictions and limitations.
+ \li It is not supported on mobile operating systems, except on Android.
+ There, you might run into performance issues as the class is currently
+ implemented via QScreen::grabWindow, which is not optimal for the use case.
+ \li On embedded with EGLFS, it has limited functionality. For Qt Quick
+ applications, the class is currently implemented via
+ QQuickWindow::grabWindow, which can cause performance issues.
+ \li In most cases, we set a screen capture frame rate that equals the screen
+ refresh rate, except on Windows, where the rate might be flexible.
+ Such a frame rate (75/120 FPS) might cause performance issues on weak
+ CPUs if the captured screen is of 4K resolution. On EGLFS, the capture
+ frame rate is currently locked to 30 FPS.
+ \endlist
+ //! [content]
+*/
diff --git a/src/multimedia/recording/qscreencapture.cpp b/src/multimedia/recording/qscreencapture.cpp
new file mode 100644
index 000000000..c178af1c1
--- /dev/null
+++ b/src/multimedia/recording/qscreencapture.cpp
@@ -0,0 +1,261 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qscreencapture.h"
+#include "qmediacapturesession.h"
+#include <private/qplatformmediaintegration_p.h>
+#include <private/qplatformsurfacecapture_p.h>
+#include <private/qobject_p.h>
+
+QT_BEGIN_NAMESPACE
+
+static QScreenCapture::Error toScreenCaptureError(QPlatformSurfaceCapture::Error error)
+{
+ return static_cast<QScreenCapture::Error>(error);
+}
+
+class QScreenCapturePrivate : public QObjectPrivate
+{
+public:
+ QMediaCaptureSession *captureSession = nullptr;
+ std::unique_ptr<QPlatformSurfaceCapture> platformScreenCapture;
+};
+
+/*!
+ \class QScreenCapture
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_video
+ \since 6.5
+
+ \brief This class is used for capturing a screen.
+
+ The class captures a screen. It is managed by
+ the QMediaCaptureSession class where the captured screen can be displayed
+ in a video preview object or recorded to a file.
+
+ \snippet multimedia-snippets/media.cpp Media recorder
+
+ \include qscreencapture-limitations.qdocinc {content} {Q}
+
+ \sa QWindowCapture, QMediaCaptureSession
+*/
+/*!
+ \qmltype ScreenCapture
+ \instantiates QScreenCapture
+ \brief This type is used for capturing a screen.
+
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+ \ingroup multimedia_video_qml
+
+ ScreenCapture captures a screen. It is managed by
+ MediaCaptureSession where the captured screen can be displayed
+ in a video preview object or recorded to a file.
+
+ \since 6.5
+ The code below shows a simple capture session with ScreenCapture playing
+ back the captured primary screen view in VideoOutput.
+
+\qml
+ CaptureSession {
+ id: captureSession
+ screenCapture: ScreenCapture {
+ id: screenCapture
+ active: true
+ }
+ videoOutput: VideoOutput {
+ id: videoOutput
+ }
+ }
+\endqml
+
+ \include qscreencapture-limitations.qdocinc {content} {}
+
+ \sa WindowCapture, CaptureSession
+*/
+
+QScreenCapture::QScreenCapture(QObject *parent)
+ : QObject(*new QScreenCapturePrivate, parent)
+{
+ Q_D(QScreenCapture);
+
+ auto platformCapture = QPlatformMediaIntegration::instance()->createScreenCapture(this);
+ if (platformCapture) {
+ connect(platformCapture, &QPlatformSurfaceCapture::activeChanged, this,
+ &QScreenCapture::activeChanged);
+ connect(platformCapture, &QPlatformSurfaceCapture::errorChanged, this,
+ &QScreenCapture::errorChanged);
+ connect(platformCapture, &QPlatformSurfaceCapture::errorOccurred, this,
+ [this](QPlatformSurfaceCapture::Error error, QString errorString) {
+ emit errorOccurred(toScreenCaptureError(error), errorString);
+ });
+
+ connect(platformCapture,
+ qOverload<QPlatformSurfaceCapture::ScreenSource>(
+ &QPlatformSurfaceCapture::sourceChanged),
+ this, &QScreenCapture::screenChanged);
+
+ d->platformScreenCapture.reset(platformCapture);
+ }
+}
+
+QScreenCapture::~QScreenCapture()
+{
+ Q_D(QScreenCapture);
+
+ // Reset platformScreenCapture in the destructor to avoid having broken ref in the object.
+ d->platformScreenCapture.reset();
+
+ if (d->captureSession)
+ d->captureSession->setScreenCapture(nullptr);
+}
+
+/*!
+ \enum QScreenCapture::Error
+
+ Enumerates error codes that can be signaled by the QScreenCapture class.
+ errorString() provides detailed information about the error cause.
+
+ \value NoError No error
+ \value InternalError Internal screen capturing driver error
+ \value CapturingNotSupported Capturing is not supported
+ \value CaptureFailed Capturing screen failed
+ \value NotFound Selected screen not found
+*/
+
+/*!
+ Returns the capture session this QScreenCapture is connected to.
+
+ Use QMediaCaptureSession::setScreenCapture() to connect the camera to
+ a session.
+*/
+QMediaCaptureSession *QScreenCapture::captureSession() const
+{
+ Q_D(const QScreenCapture);
+
+ return d->captureSession;
+}
+
+/*!
+ \qmlproperty bool QtMultimedia::ScreenCapture::active
+ Describes whether the capturing is currently active.
+*/
+
+/*!
+ \property QScreenCapture::active
+ \brief whether the capturing is currently active.
+*/
+void QScreenCapture::setActive(bool active)
+{
+ Q_D(QScreenCapture);
+
+ if (d->platformScreenCapture)
+ d->platformScreenCapture->setActive(active);
+}
+
+bool QScreenCapture::isActive() const
+{
+ Q_D(const QScreenCapture);
+
+ return d->platformScreenCapture && d->platformScreenCapture->isActive();
+}
+
+/*!
+ \qmlproperty Screen QtMultimedia::ScreenCapture::screen
+ Describes the screen for capturing.
+*/
+
+/*!
+ \property QScreenCapture::screen
+ \brief the screen for capturing.
+*/
+
+void QScreenCapture::setScreen(QScreen *screen)
+{
+ Q_D(QScreenCapture);
+
+ if (d->platformScreenCapture)
+ d->platformScreenCapture->setSource(QPlatformSurfaceCapture::ScreenSource(screen));
+}
+
+QScreen *QScreenCapture::screen() const
+{
+ Q_D(const QScreenCapture);
+
+ return d->platformScreenCapture
+ ? d->platformScreenCapture->source<QPlatformSurfaceCapture::ScreenSource>()
+ : nullptr;
+}
+
+/*!
+ \qmlproperty enumeration QtMultimedia::ScreenCapture::error
+ Returns a code of the last error.
+*/
+
+/*!
+ \property QScreenCapture::error
+ \brief the code of the last error.
+*/
+QScreenCapture::Error QScreenCapture::error() const
+{
+ Q_D(const QScreenCapture);
+
+ return d->platformScreenCapture ? toScreenCaptureError(d->platformScreenCapture->error())
+ : CapturingNotSupported;
+}
+
+/*!
+ \fn void QScreenCapture::errorOccurred(QScreenCapture::Error error, const QString &errorString)
+
+ Signals when an \a error occurs, along with the \a errorString.
+*/
+/*!
+ \qmlproperty string QtMultimedia::ScreenCapture::errorString
+ Returns a human readable string describing the cause of error.
+*/
+
+/*!
+ \property QScreenCapture::errorString
+ \brief a human readable string describing the cause of error.
+*/
+QString QScreenCapture::errorString() const
+{
+ Q_D(const QScreenCapture);
+
+ return d->platformScreenCapture ? d->platformScreenCapture->errorString()
+ : QLatin1StringView("Capturing is not support on this platform");
+}
+/*!
+ \fn void QScreenCapture::start()
+
+ Starts screen capture.
+*/
+/*!
+ \fn void QScreenCapture::stop()
+
+ Stops screen capture.
+*/
+/*!
+ \internal
+*/
+void QScreenCapture::setCaptureSession(QMediaCaptureSession *captureSession)
+{
+ Q_D(QScreenCapture);
+
+ d->captureSession = captureSession;
+}
+
+/*!
+ \internal
+*/
+class QPlatformSurfaceCapture *QScreenCapture::platformScreenCapture() const
+{
+ Q_D(const QScreenCapture);
+
+ return d->platformScreenCapture.get();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qscreencapture.cpp"
diff --git a/src/multimedia/recording/qscreencapture.h b/src/multimedia/recording/qscreencapture.h
new file mode 100644
index 000000000..b46925bc0
--- /dev/null
+++ b/src/multimedia/recording/qscreencapture.h
@@ -0,0 +1,72 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QSCREENCAPTURE_H
+#define QSCREENCAPTURE_H
+
+#include <QtCore/qobject.h>
+#include <QtCore/qnamespace.h>
+#include <QtGui/qscreen.h>
+#include <QtGui/qwindow.h>
+#include <QtGui/qwindowdefs.h>
+#include <QtMultimedia/qtmultimediaglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMediaCaptureSession;
+class QPlatformSurfaceCapture;
+class QScreenCapturePrivate;
+
+class Q_MULTIMEDIA_EXPORT QScreenCapture : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
+ Q_PROPERTY(QScreen *screen READ screen WRITE setScreen NOTIFY screenChanged)
+ Q_PROPERTY(Error error READ error NOTIFY errorChanged)
+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
+
+public:
+ enum Error {
+ NoError = 0,
+ InternalError = 1,
+ CapturingNotSupported = 2,
+ CaptureFailed = 4,
+ NotFound = 5,
+ };
+ Q_ENUM(Error)
+
+ explicit QScreenCapture(QObject *parent = nullptr);
+ ~QScreenCapture() override;
+
+ QMediaCaptureSession *captureSession() const;
+
+ void setScreen(QScreen *screen);
+ QScreen *screen() const;
+
+ bool isActive() const;
+
+ Error error() const;
+ QString errorString() const;
+
+public Q_SLOTS:
+ void setActive(bool active);
+ void start() { setActive(true); }
+ void stop() { setActive(false); }
+
+Q_SIGNALS:
+ void activeChanged(bool);
+ void errorChanged();
+ void screenChanged(QScreen *);
+ void errorOccurred(QScreenCapture::Error error, const QString &errorString);
+
+private:
+ void setCaptureSession(QMediaCaptureSession *captureSession);
+ QPlatformSurfaceCapture *platformScreenCapture() const;
+ friend class QMediaCaptureSession;
+ Q_DISABLE_COPY(QScreenCapture)
+ Q_DECLARE_PRIVATE(QScreenCapture)
+};
+
+QT_END_NAMESPACE
+
+#endif // QSCREENCAPTURE_H
diff --git a/src/multimedia/recording/qvideoframeinput.cpp b/src/multimedia/recording/qvideoframeinput.cpp
new file mode 100644
index 000000000..cfeb911cc
--- /dev/null
+++ b/src/multimedia/recording/qvideoframeinput.cpp
@@ -0,0 +1,156 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qvideoframeinput.h"
+#include "qmediaframeinput_p.h"
+#include "qmediainputencoderinterface_p.h"
+#include "qplatformvideoframeinput_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QVideoFrameInputPrivate : public QMediaFrameInputPrivate
+{
+public:
+ QVideoFrameInputPrivate(QVideoFrameInput *q) : q(q) { }
+
+ bool sendVideoFrame(const QVideoFrame &frame)
+ {
+ return sendMediaFrame([&]() { emit m_platfromVideoFrameInput->newVideoFrame(frame); });
+ }
+
+ void initialize()
+ {
+ m_platfromVideoFrameInput = std::make_unique<QPlatformVideoFrameInput>();
+ addUpdateSignal(m_platfromVideoFrameInput.get(), &QPlatformVideoFrameInput::encoderUpdated);
+ }
+
+ void uninitialize()
+ {
+ m_platfromVideoFrameInput.reset();
+
+ if (captureSession())
+ captureSession()->setVideoFrameInput(nullptr);
+ }
+
+ QPlatformVideoFrameInput *platfromVideoFrameInput() const
+ {
+ return m_platfromVideoFrameInput.get();
+ }
+
+protected:
+ void updateCaptureSessionConnections(QMediaCaptureSession *prevSession,
+ QMediaCaptureSession *newSession) override
+ {
+ if (prevSession)
+ removeUpdateSignal(prevSession, &QMediaCaptureSession::videoOutputChanged);
+
+ if (newSession)
+ addUpdateSignal(newSession, &QMediaCaptureSession::videoOutputChanged);
+ }
+
+ bool checkIfCanSendMediaFrame() const override
+ {
+ if (auto encoderInterface = m_platfromVideoFrameInput->encoderInterface())
+ return encoderInterface->canPushFrame();
+
+ return captureSession()->videoOutput() || captureSession()->videoSink();
+ }
+
+ void emitReadyToSendMediaFrame() override { emit q->readyToSendVideoFrame(); }
+
+private:
+ QVideoFrameInput *q = nullptr;
+ std::unique_ptr<QPlatformVideoFrameInput> m_platfromVideoFrameInput;
+};
+
+/*!
+ \class QVideoFrameInput
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_video
+ \since 6.8
+
+ \brief The QVideoFrameInput class is used for providing custom video frames
+ to \l QMediaRecorder or a video output through \l QMediaCaptureSession.
+
+ \sa QMediaRecorder, QMediaCaptureSession, QVideoSink, QVideoOutput
+*/
+
+/*!
+ Constructs a new QVideoFrameInput object with \a parent.
+*/
+QVideoFrameInput::QVideoFrameInput(QObject *parent)
+ : QObject(*new QVideoFrameInputPrivate(this), parent)
+{
+ Q_D(QVideoFrameInput);
+ d->initialize();
+}
+
+/*!
+ Destroys the object.
+ */
+QVideoFrameInput::~QVideoFrameInput()
+{
+ Q_D(QVideoFrameInput);
+ d->uninitialize();
+}
+
+/*!
+ Sends \l QVideoFrame to \l QMediaRecorder or a video output
+ through \l QMediaCaptureSession.
+
+ Returns \c true if the specified \a frame has been sent successfully
+ to the destination. Returns \c false, if the frame hasn't been sent,
+ which can happen if the instance is not assigned to
+ \l QMediaCaptureSession, the session doesn't have video outputs or
+ a media recorder, the media recorder is not started or its queue is full.
+ The signal \l readyToSendVideoFrame will be sent as soon as
+ the destination is able to handle a new frame.
+
+ Sending of an empty video frame is treated by \l QMediaRecorder
+ as an end of the input stream. QMediaRecorder stops the recording
+ automatically if \l QMediaRecorder::autoStop is \c true and
+ all the inputs have reported the end of the stream.
+*/
+bool QVideoFrameInput::sendVideoFrame(const QVideoFrame &frame)
+{
+ Q_D(QVideoFrameInput);
+ return d->sendVideoFrame(frame);
+}
+
+/*!
+ Returns the capture session this video frame input is connected to, or
+ a \c nullptr if the video frame input is not connected to a capture session.
+
+ Use QMediaCaptureSession::setVideoFrameInput() to connect
+ the video frame input to a session.
+*/
+QMediaCaptureSession *QVideoFrameInput::captureSession() const
+{
+ Q_D(const QVideoFrameInput);
+ return d->captureSession();
+}
+
+void QVideoFrameInput::setCaptureSession(QMediaCaptureSession *captureSession)
+{
+ Q_D(QVideoFrameInput);
+ d->setCaptureSession(captureSession);
+}
+
+QPlatformVideoFrameInput *QVideoFrameInput::platformVideoFrameInput() const
+{
+ Q_D(const QVideoFrameInput);
+ return d->platfromVideoFrameInput();
+}
+
+/*!
+ \fn void QVideoFrameInput::readyToSendVideoFrame()
+
+ Signals that a new frame can be sent to the video frame input.
+ After receiving the signal, if you have frames to be sent, invoke \l sendVideoFrame
+ once or in a loop until it returns \c false.
+
+ \sa sendVideoFrame()
+*/
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/recording/qvideoframeinput.h b/src/multimedia/recording/qvideoframeinput.h
new file mode 100644
index 000000000..6617b051f
--- /dev/null
+++ b/src/multimedia/recording/qvideoframeinput.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QVIDEOFRAMEINPUT_H
+#define QVIDEOFRAMEINPUT_H
+
+#include <QtMultimedia/qtmultimediaexports.h>
+#include <QtMultimedia/qvideoframe.h>
+#include <QtCore/qobject.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPlatformVideoFrameInput;
+class QVideoFrameInputPrivate;
+class QMediaCaptureSession;
+
+class Q_MULTIMEDIA_EXPORT QVideoFrameInput : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QVideoFrameInput(QObject *parent = nullptr);
+
+ ~QVideoFrameInput() override;
+
+ bool sendVideoFrame(const QVideoFrame &frame);
+
+ QMediaCaptureSession *captureSession() const;
+
+Q_SIGNALS:
+ void readyToSendVideoFrame();
+
+private:
+ void setCaptureSession(QMediaCaptureSession *captureSession);
+
+ QPlatformVideoFrameInput *platformVideoFrameInput() const;
+
+ friend class QMediaCaptureSession;
+ Q_DISABLE_COPY(QVideoFrameInput)
+ Q_DECLARE_PRIVATE(QVideoFrameInput)
+};
+
+QT_END_NAMESPACE
+
+#endif // QVIDEOFRAMEINPUT_H
diff --git a/src/multimedia/recording/qwindowcapture.cpp b/src/multimedia/recording/qwindowcapture.cpp
new file mode 100644
index 000000000..69ad60100
--- /dev/null
+++ b/src/multimedia/recording/qwindowcapture.cpp
@@ -0,0 +1,268 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowcapture.h"
+#include "qplatformmediaintegration_p.h"
+#include "qmediacapturesession.h"
+#include "private/qobject_p.h"
+#include "private/qplatformsurfacecapture_p.h"
+
+QT_BEGIN_NAMESPACE
+
+static QWindowCapture::Error toWindowCaptureError(QPlatformSurfaceCapture::Error error)
+{
+ return static_cast<QWindowCapture::Error>(error);
+}
+
+class QWindowCapturePrivate : public QObjectPrivate
+{
+public:
+ QMediaCaptureSession *captureSession = nullptr;
+ std::unique_ptr<QPlatformSurfaceCapture> platformWindowCapture;
+};
+
+/*!
+ \class QWindowCapture
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_video
+ \since 6.6
+
+ \brief This class is used for capturing a window.
+
+ The class captures a window. It is managed by
+ the QMediaCaptureSession class where the captured window can be displayed
+ in a video preview object or recorded to a file.
+
+ \sa QMediaCaptureSession, QCapturableWindow
+*/
+/*!
+ \qmltype WindowCapture
+ \instantiates QWindowCapture
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+ \ingroup multimedia_video_qml
+ \since 6.6
+
+ \brief This type is used for capturing a window.
+
+ WindowCapture captures a window. It is managed by
+ MediaCaptureSession where the captured window can be displayed
+ in a video preview object or recorded to a file.
+
+ \sa CaptureSession, CapturableWindow
+*/
+
+/*!
+ \enum QWindowCapture::Error
+
+ Enumerates error codes that can be signaled by the QWindowCapture class.
+ errorString() provides detailed information about the error cause.
+
+ \value NoError No error
+ \value InternalError Internal window capturing driver error
+ \value CapturingNotSupported Window capturing is not supported
+ \value CaptureFailed Capturing window failed
+ \value NotFound Selected window not found
+*/
+
+/*!
+ Constructs a new QWindowCapture object with \a parent.
+*/
+QWindowCapture::QWindowCapture(QObject *parent) : QObject(*new QWindowCapturePrivate, parent)
+{
+ Q_D(QWindowCapture);
+
+ qRegisterMetaType<QCapturableWindow>();
+
+ auto platformCapture = QPlatformMediaIntegration::instance()->createWindowCapture(this);
+
+ if (platformCapture) {
+ connect(platformCapture, &QPlatformSurfaceCapture::activeChanged, this,
+ &QWindowCapture::activeChanged);
+ connect(platformCapture, &QPlatformSurfaceCapture::errorChanged, this,
+ &QWindowCapture::errorChanged);
+ connect(platformCapture, &QPlatformSurfaceCapture::errorOccurred, this,
+ [this](QPlatformSurfaceCapture::Error error, QString errorString) {
+ emit errorOccurred(toWindowCaptureError(error), errorString);
+ });
+ connect(platformCapture,
+ qOverload<QCapturableWindow>(&QPlatformSurfaceCapture::sourceChanged), this,
+ &QWindowCapture::windowChanged);
+
+ d->platformWindowCapture.reset(platformCapture);
+ }
+}
+
+/*!
+ Destroys the object.
+ */
+QWindowCapture::~QWindowCapture()
+{
+ Q_D(QWindowCapture);
+
+ d->platformWindowCapture.reset();
+
+ if (d->captureSession)
+ d->captureSession->setWindowCapture(nullptr);
+}
+
+/*!
+ \qmlmethod list<CapturableWindow> QtMultimedia::WindowCapture::capturableWindows()
+
+ Returns a list of CapturableWindow objects that is available for capturing.
+*/
+/*!
+ \fn QList<QCapturableWindow> QWindowCapture::capturableWindows()
+
+ Returns a list of QCapturableWindow objects that is available for capturing.
+ */
+QList<QCapturableWindow> QWindowCapture::capturableWindows()
+{
+ return QPlatformMediaIntegration::instance()->capturableWindowsList();
+}
+
+QMediaCaptureSession *QWindowCapture::captureSession() const
+{
+ Q_D(const QWindowCapture);
+
+ return d->captureSession;
+}
+
+/*!
+ \qmlproperty Window QtMultimedia::WindowCapture::window
+ Describes the window for capturing.
+
+ \sa QtMultimedia::WindowCapture::capturableWindows
+*/
+
+/*!
+ \property QWindowCapture::window
+ \brief the window for capturing.
+
+ \sa QWindowCapture::capturableWindows
+*/
+QCapturableWindow QWindowCapture::window() const
+{
+ Q_D(const QWindowCapture);
+
+ return d->platformWindowCapture ? d->platformWindowCapture->source<QCapturableWindow>()
+ : QCapturableWindow();
+}
+
+void QWindowCapture::setWindow(QCapturableWindow window)
+{
+ Q_D(QWindowCapture);
+
+ if (d->platformWindowCapture)
+ d->platformWindowCapture->setSource(window);
+}
+
+/*!
+ \qmlproperty bool QtMultimedia::WindowCapture::active
+ Describes whether the capturing is currently active.
+*/
+
+/*!
+ \property QWindowCapture::active
+ \brief whether the capturing is currently active.
+
+ \sa start(), stop()
+*/
+bool QWindowCapture::isActive() const
+{
+ Q_D(const QWindowCapture);
+
+ return d->platformWindowCapture && d->platformWindowCapture->isActive();
+}
+
+void QWindowCapture::setActive(bool active)
+{
+ Q_D(QWindowCapture);
+
+ if (d->platformWindowCapture)
+ d->platformWindowCapture->setActive(active);
+}
+
+/*!
+ \qmlmethod QtMultimedia::WindowCapture::start
+*/
+
+/*!
+ \fn void QWindowCapture::start()
+
+ Starts capturing the \l window.
+
+ This is equivalent to setting the \l active property to true.
+*/
+
+/*!
+ \qmlmethod QtMultimedia::WindowCapture::stop
+*/
+
+/*!
+ \fn void QWindowCapture::stop()
+
+ Stops capturing.
+
+ This is equivalent to setting the \l active property to false.
+*/
+
+
+/*!
+ \qmlproperty enumeration QtMultimedia::WindowCapture::error
+ Returns a code of the last error.
+*/
+
+/*!
+ \property QWindowCapture::error
+ \brief the code of the last error.
+*/
+QWindowCapture::Error QWindowCapture::error() const
+{
+ Q_D(const QWindowCapture);
+
+ return d->platformWindowCapture ? toWindowCaptureError(d->platformWindowCapture->error())
+ : CapturingNotSupported;
+}
+
+/*!
+ \fn void QWindowCapture::errorOccurred(QWindowCapture::Error error, const QString &errorString)
+
+ Signals when an \a error occurs, along with the \a errorString.
+*/
+/*!
+ \qmlproperty string QtMultimedia::WindowCapture::errorString
+ Returns a human readable string describing the cause of error.
+*/
+
+/*!
+ \property QWindowCapture::errorString
+ \brief a human readable string describing the cause of error.
+*/
+QString QWindowCapture::errorString() const
+{
+ Q_D(const QWindowCapture);
+
+ return d->platformWindowCapture
+ ? d->platformWindowCapture->errorString()
+ : QLatin1StringView("Capturing is not support on this platform");
+}
+
+void QWindowCapture::setCaptureSession(QMediaCaptureSession *captureSession)
+{
+ Q_D(QWindowCapture);
+
+ d->captureSession = captureSession;
+}
+
+QPlatformSurfaceCapture *QWindowCapture::platformWindowCapture() const
+{
+ Q_D(const QWindowCapture);
+
+ return d->platformWindowCapture.get();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwindowcapture.cpp"
diff --git a/src/multimedia/recording/qwindowcapture.h b/src/multimedia/recording/qwindowcapture.h
new file mode 100644
index 000000000..4c8b2eac3
--- /dev/null
+++ b/src/multimedia/recording/qwindowcapture.h
@@ -0,0 +1,71 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWCAPTURE_H
+#define QWINDOWCAPTURE_H
+
+#include <QtMultimedia/qtmultimediaexports.h>
+#include <QtMultimedia/qcapturablewindow.h>
+#include <QtCore/qobject.h>
+#include <QtCore/qlist.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPlatformSurfaceCapture;
+
+class Q_MULTIMEDIA_EXPORT QWindowCapture : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
+ Q_PROPERTY(QCapturableWindow window READ window WRITE setWindow NOTIFY windowChanged)
+ Q_PROPERTY(Error error READ error NOTIFY errorChanged)
+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
+public:
+ enum Error {
+ NoError = 0,
+ InternalError = 1,
+ CapturingNotSupported = 2,
+ CaptureFailed = 4,
+ NotFound = 5,
+ };
+ Q_ENUM(Error)
+
+ explicit QWindowCapture(QObject *parent = nullptr);
+ ~QWindowCapture() override;
+
+ Q_INVOKABLE static QList<QCapturableWindow> capturableWindows();
+
+ QMediaCaptureSession *captureSession() const;
+
+ void setWindow(QCapturableWindow window);
+
+ QCapturableWindow window() const;
+
+ bool isActive() const;
+
+ Error error() const;
+ QString errorString() const;
+
+public Q_SLOTS:
+ void setActive(bool active);
+ void start() { setActive(true); }
+ void stop() { setActive(false); }
+
+Q_SIGNALS:
+ void activeChanged(bool);
+ void windowChanged(QCapturableWindow window);
+ void errorChanged();
+ void errorOccurred(QWindowCapture::Error error, const QString &errorString);
+
+private:
+ void setCaptureSession(QMediaCaptureSession *captureSession);
+ QPlatformSurfaceCapture *platformWindowCapture() const;
+
+ friend class QMediaCaptureSession;
+ Q_DISABLE_COPY(QWindowCapture)
+ Q_DECLARE_PRIVATE(QWindowCapture)
+};
+
+QT_END_NAMESPACE
+
+#endif // QWINDOWCAPTURE_H
diff --git a/src/multimedia/recording/recording.pri b/src/multimedia/recording/recording.pri
deleted file mode 100644
index 20ed99e04..000000000
--- a/src/multimedia/recording/recording.pri
+++ /dev/null
@@ -1,14 +0,0 @@
-INCLUDEPATH += recording
-
-PUBLIC_HEADERS += \
- recording/qaudiorecorder.h \
- recording/qmediaencodersettings.h \
- recording/qmediarecorder.h \
-
-PRIVATE_HEADERS += \
- recording/qmediarecorder_p.h \
-
-SOURCES += \
- recording/qaudiorecorder.cpp \
- recording/qmediaencodersettings.cpp \
- recording/qmediarecorder.cpp
diff --git a/src/multimedia/shaders/abgr.frag b/src/multimedia/shaders/abgr.frag
new file mode 100644
index 000000000..7eadb092d
--- /dev/null
+++ b/src/multimedia/shaders/abgr.frag
@@ -0,0 +1,19 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D rgbTexture;
+
+void main()
+{
+ fragColor = ubuf.colorMatrix * texture(rgbTexture, texCoord).abgr * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+}
diff --git a/src/multimedia/shaders/argb.frag b/src/multimedia/shaders/argb.frag
new file mode 100644
index 000000000..1adbc8dba
--- /dev/null
+++ b/src/multimedia/shaders/argb.frag
@@ -0,0 +1,19 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D rgbTexture;
+
+void main()
+{
+ fragColor = ubuf.colorMatrix * texture(rgbTexture, texCoord).gbar * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+}
diff --git a/src/multimedia/shaders/ayuv.frag b/src/multimedia/shaders/ayuv.frag
new file mode 100644
index 000000000..92c3f71fe
--- /dev/null
+++ b/src/multimedia/shaders/ayuv.frag
@@ -0,0 +1,25 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+
+void main()
+{
+ vec3 YUV = texture(plane1Texture, texCoord).gba;
+ float A = texture(plane1Texture, texCoord).r;
+ fragColor = ubuf.colorMatrix * vec4(YUV, 1.0) * A * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+
+ // Clamp output to valid range to account for out-of-range
+ // input values and numerical inaccuracies in YUV->RGB conversion
+ fragColor = clamp(fragColor, 0.0, 1.0);
+}
diff --git a/src/multimedia/shaders/bgra.frag b/src/multimedia/shaders/bgra.frag
new file mode 100644
index 000000000..0ba0e4c9e
--- /dev/null
+++ b/src/multimedia/shaders/bgra.frag
@@ -0,0 +1,19 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D rgbTexture;
+
+void main()
+{
+ fragColor = ubuf.colorMatrix * texture(rgbTexture, texCoord).bgra * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+}
diff --git a/src/multimedia/shaders/colorconvert.glsl b/src/multimedia/shaders/colorconvert.glsl
new file mode 100644
index 000000000..f28a0902e
--- /dev/null
+++ b/src/multimedia/shaders/colorconvert.glsl
@@ -0,0 +1,19 @@
+#ifndef COLORCONVERT
+#define COLORCONVERT
+
+// Convert the Rec2020 RGB colorspace to sRGB using:
+// https://www.itu.int/dms_pub/itu-r/opb/rep/R-REP-BT.2407-2017-PDF-E.pdf
+// We can use the simple matrix defined there for a conversion between BT2020
+// and sRGB. Conversion has to be done in linear color space.
+vec4 convertRec2020ToSRGB(vec4 rgba)
+{
+ const mat4 mat =
+ mat4(1.6605f, -0.5876f, -0.0728f, 0.0000f,
+ -0.1246f, 1.1329f, -0.0083f, 0.0000f,
+ -0.0182f, -0.1006f, 1.1187f, 0.0000f,
+ 0.0000f, 0.0000f, 0.0000f, 1.0000f);
+
+ return rgba * mat;
+}
+
+#endif
diff --git a/src/multimedia/shaders/colortransfer.glsl b/src/multimedia/shaders/colortransfer.glsl
new file mode 100644
index 000000000..1d70ae9eb
--- /dev/null
+++ b/src/multimedia/shaders/colortransfer.glsl
@@ -0,0 +1,118 @@
+#ifndef PERCEPTUAL_QUANTIZER
+#define PERCEPTUAL_QUANTIZER
+
+// Convert Rec.709 to linear
+vec4 convertRec709ToLinear(vec4 rgba)
+{
+ const vec4 alphaMinusOne = vec4(0.099, 0.099, 0.099, 0);
+ const vec4 alpha = alphaMinusOne + 1.;
+ bvec4 cutoff = lessThan(rgba, vec4(0.081));
+ vec4 high = pow((rgba + alphaMinusOne)/alpha, vec4(1./0.45));
+ vec4 low = rgba/4.5;
+ return mix(high, low, cutoff);
+}
+
+vec4 convertSRGBToLinear(vec4 sRGB)
+{
+ // https://en.wikipedia.org/wiki/SRGB
+ const bvec3 cutoff = lessThanEqual(sRGB.rgb, vec3(0.04045));
+ const vec3 low = sRGB.rgb / 12.92;
+ const vec3 high = pow((sRGB.rgb + 0.055) / 1.055, vec3(2.4));
+ vec3 linear = mix(high, low, cutoff);
+ return vec4(linear, sRGB.a);
+}
+
+vec4 convertSRGBFromLinear(vec4 linear)
+{
+ // https://en.wikipedia.org/wiki/SRGB
+ const bvec3 cutoff = lessThanEqual(linear.rgb, vec3(0.0031308));
+ const vec3 low = linear.rgb * 12.92;
+ const vec3 high = 1.055 * pow(linear.rgb, vec3(1.0 / 2.4f)) - 0.055;
+ vec3 sRGB = mix(high, low, cutoff);
+ return vec4(sRGB, linear.a);
+}
+
+// This uses the PQ transfer function, see also https://en.wikipedia.org/wiki/Perceptual_quantizer
+// or https://ieeexplore.ieee.org/document/7291452
+const float SDR_LEVEL = 100.;
+
+vec4 convertPQToLinear(vec4 rgba)
+{
+ const vec4 one_over_m1 = vec4(8192./1305.);
+ const vec4 one_over_m2 = vec4(32./2523.);
+ const float c1 = 107./128.;
+ const float c2 = 2413./128;
+ const float c3 = 2392./128.;
+
+ vec4 e = pow(rgba, one_over_m2);
+ vec4 num = max(e - c1, 0);
+ vec4 den = c2 - c3*e;
+ return pow(num/den, one_over_m1)*10000./SDR_LEVEL;
+}
+
+vec4 convertPQFromLinear(vec4 rgba)
+{
+ const float m1 = float(1305./8192.);
+ const float m2 = float(2523./32.);
+ const float c1 = 107./128.;
+ const float c2 = 2413./128;
+ const float c3 = 2392./128.;
+
+ rgba *= SDR_LEVEL/10000.;
+ vec4 p = pow(rgba, vec4(m1));
+ vec4 num = c1 + c2*p;
+ vec4 den = 1. + c3*p;
+ return pow(num/den, vec4(m2));
+}
+
+float convertPQToLinear(float sig)
+{
+ const float one_over_m1 = float(8192./1305.);
+ const float one_over_m2 = float(32./2523.);
+ const float c1 = 107./128.;
+ const float c2 = 2413./128;
+ const float c3 = 2392./128.;
+
+ float e = pow(sig, one_over_m2);
+ float num = max(e - c1, 0);
+ float den = c2 - c3*e;
+ return pow(num/den, one_over_m1)*10000./SDR_LEVEL;
+}
+
+float convertPQFromLinear(float sig)
+{
+ const float m1 = float(1305./8192.);
+ const float m2 = float(2523./32.);
+ const float c1 = 107./128.;
+ const float c2 = 2413./128;
+ const float c3 = 2392./128.;
+
+ sig *= SDR_LEVEL/10000.;
+ float p = pow(sig, m1);
+ float num = c1 + c2*p;
+ float den = 1. + c3*p;
+ return pow(num/den, m2);
+}
+
+// This implements support for HLG transfer functions, see also https://en.wikipedia.org/wiki/Hybrid_log–gamma
+
+
+vec4 convertHLGToLinear(vec4 rgba, float maxLum)
+{
+ const float a = 0.17883277;
+ const float b = 0.28466892; // = 1 - 4a
+ const float c = 0.55991073; // = 0.5 - a ln(4a)
+
+ bvec4 cutoff = lessThan(rgba, vec4(0.5));
+ vec4 low = rgba*rgba/3;
+ vec4 high = (exp((rgba - c)/a) + b)/12.;
+ rgba = mix(high, low, cutoff);
+
+ float lum = dot(rgba, vec4(0.2627, 0.6780, 0.0593, 0.));
+ float y = pow(lum, 0.2); // gamma-1 with gamma = 1.2
+
+ rgba *= y*maxLum;
+ return rgba;
+}
+
+#endif
diff --git a/src/multimedia/shaders/compile.bat b/src/multimedia/shaders/compile.bat
new file mode 100755
index 000000000..8a012d265
--- /dev/null
+++ b/src/multimedia/shaders/compile.bat
@@ -0,0 +1,16 @@
+:: Copyright (C) 2019 The Qt Company Ltd.
+:: SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o rgba.vert.qsb rgba.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o rgba.frag.qsb rgba.frag
+
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o yuv.vert.qsb yuv.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o yuv_yv.frag.qsb yuv_yv.frag
+
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o nv12.frag.qsb nv12.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o nv21.frag.qsb nv21.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o uyvy.frag.qsb uyvy.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o yuyv.frag.qsb yuyv.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o ayuv.frag.qsb ayuv.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o p010be.frag.qsb p010be.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o p010be.frag.qsb p010be.frag
diff --git a/src/multimedia/shaders/externalsampler.frag b/src/multimedia/shaders/externalsampler.frag
new file mode 100644
index 000000000..f786bc4e1
--- /dev/null
+++ b/src/multimedia/shaders/externalsampler.frag
@@ -0,0 +1,14 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+
+void main()
+{
+ fragColor = vec4(1., 0., 0., 0.);
+}
diff --git a/src/multimedia/shaders/externalsampler.vert b/src/multimedia/shaders/externalsampler.vert
new file mode 100644
index 000000000..e693370dc
--- /dev/null
+++ b/src/multimedia/shaders/externalsampler.vert
@@ -0,0 +1,16 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+
+layout(location = 0) in vec4 vertexPosition;
+layout(location = 1) in vec2 vertexTexCoord;
+
+layout(location = 0) out vec2 texCoord;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main() {
+ texCoord = (ubuf.colorMatrix * vec4(vertexTexCoord, 0.0, 1.0)).xy;
+ gl_Position = ubuf.matrix * vertexPosition;
+}
diff --git a/src/multimedia/shaders/externalsampler_gles.frag b/src/multimedia/shaders/externalsampler_gles.frag
new file mode 100644
index 000000000..1292acebc
--- /dev/null
+++ b/src/multimedia/shaders/externalsampler_gles.frag
@@ -0,0 +1,28 @@
+#extension GL_OES_EGL_image_external : require
+precision highp float;
+precision highp int;
+
+struct buf
+{
+ mat4 matrix;
+ mat4 colorMatrix;
+ float opacity;
+ float width;
+ float masteringWhite;
+ float maxLum;
+};
+
+uniform buf ubuf;
+
+uniform samplerExternalOES plane1Texture;
+
+varying vec2 texCoord;
+
+void main()
+{
+ gl_FragColor = texture2D(plane1Texture, texCoord).rgba * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = pow(fragColor, 2.2);
+#endif
+}
diff --git a/src/multimedia/shaders/hdrtonemapper.glsl b/src/multimedia/shaders/hdrtonemapper.glsl
new file mode 100644
index 000000000..e10b6eca3
--- /dev/null
+++ b/src/multimedia/shaders/hdrtonemapper.glsl
@@ -0,0 +1,38 @@
+#ifndef HDR_TONEMAPPER
+#define HDR_TONEMAPPER
+
+#include "colortransfer.glsl"
+
+// See https://www.itu.int/dms_pub/itu-r/opb/rep/R-REP-BT.2390-6-2019-PDF-E.pdf, section 5.4
+//
+// masteringWhite in PQ values, not in linear. maxOutLum as defined in the doc above
+// we assume that masteringBlack == 0, and minLum == 0 to simplify the calculations
+//
+// The HDR tonemapping operates in non linear space (PQ or HLG), taking the
+// non linear luminosity as input and returning a factor by which to scale
+// the RGB signal so it fits within the outbut devices range.
+//
+// We're using the same algorithm for HLG, and do the equivalent mapping in
+// HLG space.
+float tonemapScaleForLuminosity(float y, float masteringWhite, float maxLum)
+{
+ float p = y/masteringWhite;
+
+ float ks = 1.5*maxLum - 0.5;
+
+ if (p < ks)
+ return 1.;
+
+ float t = (p - ks)/(1 - ks);
+ float t2 = t*t;
+ float t3 = t*t2;
+
+ p = (2*t3 - 3*t2 + 1)*ks + (t3 - 2*t2 + t)*(1. - ks) + (-2*t3 + 3*t2)*maxLum;
+
+ // get the linear new luminosity
+ float newY = p*masteringWhite;
+
+ return newY/y;
+}
+
+#endif
diff --git a/src/multimedia/shaders/imc2.frag b/src/multimedia/shaders/imc2.frag
new file mode 100644
index 000000000..18401d420
--- /dev/null
+++ b/src/multimedia/shaders/imc2.frag
@@ -0,0 +1,29 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+layout(binding = 2) uniform sampler2D plane2Texture;
+
+void main()
+{
+ float Y = texture(plane1Texture, texCoord).r;
+ float x = texCoord.x/2.;
+ float U = texture(plane2Texture, vec2(x + .5, texCoord.y)).r;
+ float V = texture(plane2Texture, vec2(x, texCoord.y)).r;
+ vec4 color = vec4(Y, U, V, 1.);
+ fragColor = ubuf.colorMatrix * color * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+
+ // Clamp output to valid range to account for out-of-range
+ // input values and numerical inaccuracies in YUV->RGB conversion
+ fragColor = clamp(fragColor, 0.0, 1.0);
+}
diff --git a/src/multimedia/shaders/imc4.frag b/src/multimedia/shaders/imc4.frag
new file mode 100644
index 000000000..574a5f49b
--- /dev/null
+++ b/src/multimedia/shaders/imc4.frag
@@ -0,0 +1,29 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+layout(binding = 2) uniform sampler2D plane2Texture;
+
+void main()
+{
+ float Y = texture(plane1Texture, texCoord).r;
+ float x = texCoord.x/2.;
+ float U = texture(plane2Texture, vec2(x, texCoord.y)).r;
+ float V = texture(plane2Texture, vec2(x + .5, texCoord.y)).r;
+ vec4 color = vec4(Y, U, V, 1.);
+ fragColor = ubuf.colorMatrix * color * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+
+ // Clamp output to valid range to account for out-of-range
+ // input values and numerical inaccuracies in YUV->RGB conversion
+ fragColor = clamp(fragColor, 0.0, 1.0);
+}
diff --git a/src/multimedia/shaders/nv12.frag b/src/multimedia/shaders/nv12.frag
new file mode 100644
index 000000000..20399d9f0
--- /dev/null
+++ b/src/multimedia/shaders/nv12.frag
@@ -0,0 +1,27 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+layout(binding = 2) uniform sampler2D plane2Texture;
+
+void main()
+{
+ float Y = texture(plane1Texture, texCoord).r;
+ vec2 UV = texture(plane2Texture, texCoord).rg;
+ vec4 color = vec4(Y, UV.x, UV.y, 1.);
+ fragColor = ubuf.colorMatrix * color * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+
+ // Clamp output to valid range to account for out-of-range
+ // input values and numerical inaccuracies in YUV->RGB conversion
+ fragColor = clamp(fragColor, 0.0, 1.0);
+}
diff --git a/src/multimedia/shaders/nv12_bt2020_hlg.frag b/src/multimedia/shaders/nv12_bt2020_hlg.frag
new file mode 100644
index 000000000..25560c9b7
--- /dev/null
+++ b/src/multimedia/shaders/nv12_bt2020_hlg.frag
@@ -0,0 +1,42 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+#include "colorconvert.glsl"
+#include "hdrtonemapper.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+layout(binding = 2) uniform sampler2D plane2Texture;
+
+// This implements support HDR video using the HLG transfer functions, see also
+// https://en.wikipedia.org/wiki/Hybrid_log–gamma
+// https://www.itu.int/dms_pub/itu-r/opb/rep/R-REP-BT.2390-6-2019-PDF-E.pdf
+// https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-E.pdf
+//
+// Tonemapping is done using the same algorithm as for the PQ transfer function, but we
+// operate in HLG space here.
+void main()
+{
+ float Y = texture(plane1Texture, texCoord).r;
+ vec2 UV = texture(plane2Texture, texCoord).rg;
+ // map to Rec.2020 color space
+ fragColor = vec4(Y, UV.x, UV.y, 1.);
+ fragColor = ubuf.colorMatrix * fragColor;
+
+ // tonemap
+ float y = (Y - 16./256.)*256./219.; // Video range (16...235)
+ float scale = tonemapScaleForLuminosity(y, ubuf.masteringWhite, ubuf.maxLum);
+ fragColor *= scale;
+
+ fragColor = convertHLGToLinear(fragColor, ubuf.maxLum);
+ fragColor = convertRec2020ToSRGB(fragColor);
+ fragColor *= ubuf.opacity;
+
+#ifndef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBFromLinear(fragColor);
+#endif
+}
diff --git a/src/multimedia/shaders/nv12_bt2020_pq.frag b/src/multimedia/shaders/nv12_bt2020_pq.frag
new file mode 100644
index 000000000..96aef068e
--- /dev/null
+++ b/src/multimedia/shaders/nv12_bt2020_pq.frag
@@ -0,0 +1,48 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+#include "colorconvert.glsl"
+#include "hdrtonemapper.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+layout(binding = 2) uniform sampler2D plane2Texture;
+
+// This uses the PQ transfer function, see also https://en.wikipedia.org/wiki/Perceptual_quantizer
+// or https://ieeexplore.ieee.org/document/7291452
+//
+// Tonemapping into the RGB range supported by the output is done using
+// https://www.itu.int/dms_pub/itu-r/opb/rep/R-REP-BT.2390-6-2019-PDF-E.pdf, section 5.4
+//
+// masteringWhite in PQ values, not in linear. maxOutLum as defined in the doc above
+// we assume that masteringBlack == 0, and minLum == 0 to simplify the calculations
+//
+// The calculation calculates a new luminosity in non linear space and scales the UV
+// components before linearizing. This corresponds to option (2) at the end of section 5.4.
+// This option was chosen as it keeps the colors correct while as well as being computationally
+// cheapest.
+void main()
+{
+ float Y = texture(plane1Texture, texCoord).r;
+ vec2 UV = texture(plane2Texture, texCoord).rg;
+ // map to Rec.2020 color space
+ fragColor = vec4(Y, UV.x, UV.y, 1.);
+ fragColor = ubuf.colorMatrix * fragColor;
+
+ // tonemap
+ float y = (Y - 16./256.)*256./219.; // Video range (16...235)
+ float scale = tonemapScaleForLuminosity(y, ubuf.masteringWhite, ubuf.maxLum);
+ fragColor *= scale;
+
+ fragColor = convertPQToLinear(fragColor);
+ fragColor = convertRec2020ToSRGB(fragColor);
+ fragColor *= ubuf.opacity;
+
+#ifndef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBFromLinear(fragColor);
+#endif
+}
diff --git a/src/multimedia/shaders/nv21.frag b/src/multimedia/shaders/nv21.frag
new file mode 100644
index 000000000..c3f641be5
--- /dev/null
+++ b/src/multimedia/shaders/nv21.frag
@@ -0,0 +1,27 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+layout(binding = 2) uniform sampler2D plane2Texture;
+
+void main()
+{
+ float Y = texture(plane1Texture, texCoord).r;
+ vec2 UV = texture(plane2Texture, texCoord).gr;
+ vec4 color = vec4(Y, UV.x, UV.y, 1.);
+ fragColor = ubuf.colorMatrix * color * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+
+ // Clamp output to valid range to account for out-of-range
+ // input values and numerical inaccuracies in YUV->RGB conversion
+ fragColor = clamp(fragColor, 0.0, 1.0);
+}
diff --git a/src/multimedia/shaders/rectsampler.vert b/src/multimedia/shaders/rectsampler.vert
new file mode 100644
index 000000000..e693370dc
--- /dev/null
+++ b/src/multimedia/shaders/rectsampler.vert
@@ -0,0 +1,16 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+
+layout(location = 0) in vec4 vertexPosition;
+layout(location = 1) in vec2 vertexTexCoord;
+
+layout(location = 0) out vec2 texCoord;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main() {
+ texCoord = (ubuf.colorMatrix * vec4(vertexTexCoord, 0.0, 1.0)).xy;
+ gl_Position = ubuf.matrix * vertexPosition;
+}
diff --git a/src/multimedia/shaders/rectsampler_bgra.frag b/src/multimedia/shaders/rectsampler_bgra.frag
new file mode 100644
index 000000000..8b1b9a4ad
--- /dev/null
+++ b/src/multimedia/shaders/rectsampler_bgra.frag
@@ -0,0 +1,19 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2DRect rgbTexture;
+
+void main()
+{
+ fragColor = texture(rgbTexture, texCoord).rgba * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+}
diff --git a/src/multimedia/shaders/rgba.frag b/src/multimedia/shaders/rgba.frag
new file mode 100644
index 000000000..b53e0dc71
--- /dev/null
+++ b/src/multimedia/shaders/rgba.frag
@@ -0,0 +1,19 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D rgbTexture;
+
+void main()
+{
+ fragColor = ubuf.colorMatrix * texture(rgbTexture, texCoord).rgba * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+}
diff --git a/src/multimedia/shaders/uniformbuffer.glsl b/src/multimedia/shaders/uniformbuffer.glsl
new file mode 100644
index 000000000..c74859c5d
--- /dev/null
+++ b/src/multimedia/shaders/uniformbuffer.glsl
@@ -0,0 +1,11 @@
+// Make sure to also modify externalsampler_gles.frag when modifying this
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ mat4 colorMatrix;
+ float opacity;
+ float width;
+ // HDR metadata required for tonemapping
+ float masteringWhite; // in PQ or HLG values
+ float maxLum; // in PQ or HLG values
+} ubuf;
diff --git a/src/multimedia/shaders/uyvy.frag b/src/multimedia/shaders/uyvy.frag
new file mode 100644
index 000000000..26a83da3f
--- /dev/null
+++ b/src/multimedia/shaders/uyvy.frag
@@ -0,0 +1,27 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+
+void main()
+{
+ int x = int(floor(texCoord.x * ubuf.width));
+ bool rightSubPixel = (x/2*2 != x);
+ float Y = rightSubPixel ? texture(plane1Texture, texCoord).a : texture(plane1Texture, texCoord).g;
+ vec2 UV = texture(plane1Texture, texCoord).rb;
+ fragColor = ubuf.colorMatrix * vec4(Y, UV, 1.0) * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+
+ // Clamp output to valid range to account for out-of-range
+ // input values and numerical inaccuracies in YUV->RGB conversion
+ fragColor = clamp(fragColor, 0.0, 1.0);
+}
diff --git a/src/multimedia/shaders/vertex.vert b/src/multimedia/shaders/vertex.vert
new file mode 100644
index 000000000..ce170824e
--- /dev/null
+++ b/src/multimedia/shaders/vertex.vert
@@ -0,0 +1,16 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+
+layout(location = 0) in vec4 vertexPosition;
+layout(location = 1) in vec2 vertexTexCoord;
+
+layout(location = 0) out vec2 texCoord;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main() {
+ texCoord = vertexTexCoord;
+ gl_Position = ubuf.matrix * vertexPosition;
+}
diff --git a/src/multimedia/shaders/y.frag b/src/multimedia/shaders/y.frag
new file mode 100644
index 000000000..8c25fc762
--- /dev/null
+++ b/src/multimedia/shaders/y.frag
@@ -0,0 +1,25 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+
+void main()
+{
+ float Y = texture(plane1Texture, texCoord).r;
+ vec4 color = vec4(Y, Y, Y, 1.);
+ fragColor = ubuf.colorMatrix * color * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+
+ // Clamp output to valid range to account for out-of-range
+ // input values and numerical inaccuracies in YUV->RGB conversion
+ fragColor = clamp(fragColor, 0.0, 1.0);
+}
diff --git a/src/multimedia/shaders/yuv_triplanar.frag b/src/multimedia/shaders/yuv_triplanar.frag
new file mode 100644
index 000000000..228147943
--- /dev/null
+++ b/src/multimedia/shaders/yuv_triplanar.frag
@@ -0,0 +1,29 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+layout(binding = 2) uniform sampler2D plane2Texture;
+layout(binding = 3) uniform sampler2D plane3Texture;
+
+void main()
+{
+ float Y = texture(plane1Texture, texCoord).r;
+ float U = texture(plane2Texture, texCoord).r;
+ float V = texture(plane3Texture, texCoord).r;
+ vec4 color = vec4(Y, U, V, 1.);
+ fragColor = ubuf.colorMatrix * color * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+
+ // Clamp output to valid range to account for out-of-range
+ // input values and numerical inaccuracies in YUV->RGB conversion
+ fragColor = clamp(fragColor, 0.0, 1.0);
+}
diff --git a/src/multimedia/shaders/yuv_triplanar_p10.frag b/src/multimedia/shaders/yuv_triplanar_p10.frag
new file mode 100644
index 000000000..5da0ed339
--- /dev/null
+++ b/src/multimedia/shaders/yuv_triplanar_p10.frag
@@ -0,0 +1,29 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+layout(binding = 2) uniform sampler2D plane2Texture;
+layout(binding = 3) uniform sampler2D plane3Texture;
+
+void main()
+{
+ float Y = texture(plane1Texture, texCoord).r * 64;
+ float U = texture(plane2Texture, texCoord).r * 64;
+ float V = texture(plane3Texture, texCoord).r * 64;
+ vec4 color = vec4(Y, U, V, 1.);
+ fragColor = ubuf.colorMatrix * color * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+
+ // Clamp output to valid range to account for out-of-range
+ // input values and numerical inaccuracies in YUV->RGB conversion
+ fragColor = clamp(fragColor, 0.0, 1.0);
+}
diff --git a/src/multimedia/shaders/yuyv.frag b/src/multimedia/shaders/yuyv.frag
new file mode 100644
index 000000000..0f6e65b6d
--- /dev/null
+++ b/src/multimedia/shaders/yuyv.frag
@@ -0,0 +1,27 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+
+void main()
+{
+ int x = int(floor(texCoord.x * ubuf.width));
+ bool rightSubPixel = (x/2*2 != x);
+ float Y = rightSubPixel ? texture(plane1Texture, texCoord).b : texture(plane1Texture, texCoord).r;
+ vec2 UV = texture(plane1Texture, texCoord).ga;
+ fragColor = ubuf.colorMatrix * vec4(Y, UV, 1.0) * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+
+ // Clamp output to valid range to account for out-of-range
+ // input values and numerical inaccuracies in YUV->RGB conversion
+ fragColor = clamp(fragColor, 0.0, 1.0);
+}
diff --git a/src/multimedia/shaders/yvu_triplanar.frag b/src/multimedia/shaders/yvu_triplanar.frag
new file mode 100644
index 000000000..ac2cbdf63
--- /dev/null
+++ b/src/multimedia/shaders/yvu_triplanar.frag
@@ -0,0 +1,29 @@
+#version 440
+#extension GL_GOOGLE_include_directive : enable
+
+#include "uniformbuffer.glsl"
+#include "colortransfer.glsl"
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D plane1Texture;
+layout(binding = 2) uniform sampler2D plane2Texture;
+layout(binding = 3) uniform sampler2D plane3Texture;
+
+void main()
+{
+ float Y = texture(plane1Texture, texCoord).r;
+ float V = texture(plane2Texture, texCoord).r;
+ float U = texture(plane3Texture, texCoord).r;
+ vec4 color = vec4(Y, U, V, 1.);
+ fragColor = ubuf.colorMatrix * color * ubuf.opacity;
+
+#ifdef QMM_OUTPUTSURFACE_LINEAR
+ fragColor = convertSRGBToLinear(fragColor);
+#endif
+
+ // Clamp output to valid range to account for out-of-range
+ // input values and numerical inaccuracies in YUV->RGB conversion
+ fragColor = clamp(fragColor, 0.0, 1.0);
+}
diff --git a/src/multimedia/video/qabstractvideobuffer.cpp b/src/multimedia/video/qabstractvideobuffer.cpp
index 793241be9..7368082b1 100644
--- a/src/multimedia/video/qabstractvideobuffer.cpp
+++ b/src/multimedia/video/qabstractvideobuffer.cpp
@@ -1,397 +1,139 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qabstractvideobuffer_p.h"
-
-#include <qvariant.h>
-
-#include <QDebug>
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qabstractvideobuffer.h"
QT_BEGIN_NAMESPACE
-static void qRegisterAbstractVideoBufferMetaTypes()
-{
- qRegisterMetaType<QAbstractVideoBuffer::HandleType>();
- qRegisterMetaType<QAbstractVideoBuffer::MapMode>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterAbstractVideoBufferMetaTypes)
-
-int QAbstractVideoBufferPrivate::map(
- QAbstractVideoBuffer::MapMode mode,
- int *numBytes,
- int bytesPerLine[4],
- uchar *data[4])
-{
- data[0] = q_ptr->map(mode, numBytes, bytesPerLine);
- return data[0] ? 1 : 0;
-}
-
/*!
\class QAbstractVideoBuffer
+ \since 6.8
\brief The QAbstractVideoBuffer class is an abstraction for video data.
\inmodule QtMultimedia
\ingroup multimedia
\ingroup multimedia_video
- The QVideoFrame class makes use of a QAbstractVideoBuffer internally to reference a buffer of
- video data. Quite often video data buffers may reside in video memory rather than system
- memory, and this class provides an abstraction of the location.
-
- In addition, creating a subclass of QAbstractVideoBuffer will allow you to construct video
- frames from preallocated or static buffers, in cases where the QVideoFrame constructors
- taking a QByteArray or a QImage do not suffice. This may be necessary when implementing
- a new hardware accelerated video system, for example.
+ The \l QVideoFrame class makes use of a QAbstractVideoBuffer internally to reference a buffer of
+ video data. Creating a subclass of QAbstractVideoBuffer allows you to construct video
+ frames from preallocated or static buffers. The subclass can contain a hardware buffer,
+ and implement access to the data by mapping the buffer to CPU memory.
The contents of a buffer can be accessed by mapping the buffer to memory using the map()
- function, which returns a pointer to memory containing the contents of the video buffer.
- The memory returned by map() is released by calling the unmap() function.
-
- The handle() of a buffer may also be used to manipulate its contents using type specific APIs.
- The type of a buffer's handle is given by the handleType() function.
+ function, which returns a structure containing information about plane layout of the current
+ video data.
- \sa QVideoFrame
+ \sa QVideoFrame, QVideoFrameFormat, QtVideo::MapMode
*/
/*!
- \enum QAbstractVideoBuffer::HandleType
-
- Identifies the type of a video buffers handle.
-
- \value NoHandle The buffer has no handle, its data can only be accessed by mapping the buffer.
- \value GLTextureHandle The handle of the buffer is an OpenGL texture ID.
- \value MTLTextureHandle The handle of the buffer is an Metal texture ID.
- \value XvShmImageHandle The handle contains pointer to shared memory XVideo image.
- \value CoreImageHandle The handle contains pointer to \macos CIImage.
- \value QPixmapHandle The handle of the buffer is a QPixmap.
- \value EGLImageHandle The handle of the buffer is an EGLImageKHR.
- \value UserHandle Start value for user defined handle types.
-
- \sa handleType()
-*/
+ \class QAbstractVideoBuffer::MapData
+ \brief The QAbstractVideoBuffer::MapData structure describes the mapped plane layout.
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_video
-/*!
- \enum QAbstractVideoBuffer::MapMode
+ The structure contains a number of mapped planes, and plane data for each plane,
+ specificly, a number of bytes per line, a data pointer, and a data size.
+ The structure doesn't hold any ownership of the data it refers to.
- Enumerates how a video buffer's data is mapped to system memory.
+ A defaultly created structure means that no data has been mapped.
- \value NotMapped The video buffer is not mapped to memory.
- \value ReadOnly The mapped memory is populated with data from the video buffer when mapped, but
- the content of the mapped memory may be discarded when unmapped.
- \value WriteOnly The mapped memory is uninitialized when mapped, but the possibly modified content
- will be used to populate the video buffer when unmapped.
- \value ReadWrite The mapped memory is populated with data from the video buffer, and the
- video buffer is repopulated with the content of the mapped memory when it is unmapped.
+ All the values in the structure default to zeros.
- \sa mapMode(), map()
+ \sa QAbstractVideoBuffer::map
*/
/*!
- Constructs an abstract video buffer of the given \a type.
-*/
-QAbstractVideoBuffer::QAbstractVideoBuffer(HandleType type)
- : d_ptr(nullptr)
- , m_type(type)
-{
-}
+ \variable QAbstractVideoBuffer::MapData::planeCount
-/*!
- \internal
-*/
-QAbstractVideoBuffer::QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type)
- : d_ptr(&dd)
- , m_type(type)
-{
- d_ptr->q_ptr = this;
-}
+ The number of planes of the mapped video data. If the format of the data
+ is multiplanar, and the value is \c 1, the actual plane layout will
+ be calculated upon invoking of \l QVideoFrame::map from the frame height,
+ \c{bytesPerLine[0]}, and \c{dataSize[0]}.
-/*!
- Destroys an abstract video buffer.
+ Defaults to \c 0.
*/
-QAbstractVideoBuffer::~QAbstractVideoBuffer()
-{
- delete d_ptr;
-}
/*!
- Releases the video buffer.
+ \variable QAbstractVideoBuffer::MapData::bytesPerLine
- QVideoFrame calls QAbstractVideoBuffer::release when the buffer is not used
- any more and can be destroyed or returned to the buffer pool.
+ The array of numbrers of bytes per line for each
+ plane from \c 0 to \c{planeCount - 1}.
- The default implementation deletes the buffer instance.
+ The values of the array default to \c 0.
*/
-void QAbstractVideoBuffer::release()
-{
- delete this;
-}
/*!
- Returns the type of a video buffer's handle.
+ \variable QAbstractVideoBuffer::MapData::data
- \sa handle()
-*/
-QAbstractVideoBuffer::HandleType QAbstractVideoBuffer::handleType() const
-{
- return m_type;
-}
-
-/*!
- \fn QAbstractVideoBuffer::mapMode() const
-
- Returns the mode a video buffer is mapped in.
+ The array of pointers to the mapped video pixel data
+ for each plane from \c 0 to \c{planeCount - 1}.
+ The implementation of QAbstractVideoBuffer must hold ownership of the data
+ at least until \l QAbstractVideoBuffer::unmap is called.
- \sa map()
+ The values of the array default to \c nullptr.
*/
/*!
- \fn QAbstractVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
-
- Maps the contents of a video buffer to memory.
-
- In some cases the video buffer might be stored in video memory or otherwise inaccessible
- memory, so it is necessary to map the buffer before accessing the pixel data. This may involve
- copying the contents around, so avoid mapping and unmapping unless required.
-
- The map \a mode indicates whether the contents of the mapped memory should be read from and/or
- written to the buffer. If the map mode includes the \c QAbstractVideoBuffer::ReadOnly flag the
- mapped memory will be populated with the content of the buffer when initially mapped. If the map
- mode includes the \c QAbstractVideoBuffer::WriteOnly flag the content of the possibly modified
- mapped memory will be written back to the buffer when unmapped.
-
- When access to the data is no longer needed be sure to call the unmap() function to release the
- mapped memory and possibly update the buffer contents.
+ \variable QAbstractVideoBuffer::MapData::dataSize
- Returns a pointer to the mapped memory region, or a null pointer if the mapping failed. The
- size in bytes of the mapped memory region is returned in \a numBytes, and the line stride in \a
- bytesPerLine.
+ The array of sizes in bytes of the mapped video pixel data
+ for each plane from \c 0 to \c{planeCount - 1}.
- \note Writing to memory that is mapped as read-only is undefined, and may result in changes
- to shared data or crashes.
-
- \sa unmap(), mapMode()
+ The values of the array default to \c 0.
*/
-
+// must be out-of-line to ensure correct working of dynamic_cast when QHwVideoBuffer is created in tests
/*!
- Independently maps the planes of a video buffer to memory.
+ Destroys a video buffer.
+*/
+QAbstractVideoBuffer::~QAbstractVideoBuffer() = default;
- The map \a mode indicates whether the contents of the mapped memory should be read from and/or
- written to the buffer. If the map mode includes the \c QAbstractVideoBuffer::ReadOnly flag the
- mapped memory will be populated with the content of the buffer when initially mapped. If the map
- mode includes the \c QAbstractVideoBuffer::WriteOnly flag the content of the possibly modified
- mapped memory will be written back to the buffer when unmapped.
+/*! \fn QAbstractVideoBuffer::MapData QAbstractVideoBuffer::map(QtVideo::MapMode mode)
- When access to the data is no longer needed be sure to call the unmap() function to release the
- mapped memory and possibly update the buffer contents.
+ Maps the planes of a video buffer to memory.
- Returns the number of planes in the mapped video data. For each plane the line stride of that
- plane will be returned in \a bytesPerLine, and a pointer to the plane data will be returned in
- \a data. The accumulative size of the mapped data is returned in \a numBytes.
+ Returns a \l MapData structure that contains information about the plane layout of
+ the mapped current video data. If the mapping fails, the method returns the default structure.
+ For CPU memory buffers, the data is considered as already mapped, so the function
+ just returns the plane layout of the preallocated underlying data.
- Not all buffer implementations will map more than the first plane, if this returns a single
- plane for a planar format the additional planes will have to be calculated from the line stride
- of the first plane and the frame height. Mapping a buffer with QVideoFrame will do this for
- you.
+ The map \a mode indicates whether the contents of the mapped memory should be read from and/or
+ written to the buffer. If the map mode includes the \c QtVideo::MapMode::WriteOnly flag,
+ the content of the possibly modified mapped memory is expected to be written back
+ to the buffer when unmapped.
- To implement this function create a derivative of QAbstractPlanarVideoBuffer and implement
- its map function instance instead.
+ When access to the data is no longer needed, the \l unmap function is called
+ to release the mapped memory and possibly update the buffer contents.
- \since 5.4
+ If the format of the video data is multiplanar, the method may map the whole pixel data
+ as a single plane. In this case, mapping a buffer with \l QVideoFrame
+ will calculate additional planes from the specified line stride of the first plane,
+ the frame height, and the data size.
*/
-int QAbstractVideoBuffer::mapPlanes(MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4])
-{
- if (d_ptr) {
- return d_ptr->map(mode, numBytes, bytesPerLine, data);
- } else {
- data[0] = map(mode, numBytes, bytesPerLine);
-
- return data[0] ? 1 : 0;
- }
-}
/*!
\fn QAbstractVideoBuffer::unmap()
Releases the memory mapped by the map() function.
- If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the \c QAbstractVideoBuffer::WriteOnly
+ If the \l {QtVideo::MapMode}{MapMode} included the \c QtVideo::MapMode::WriteOnly
flag this will write the current content of the mapped memory back to the video frame.
- \sa map()
-*/
-
-/*!
- Returns a type specific handle to the data buffer.
-
- The type of the handle is given by handleType() function.
-
- \sa handleType()
-*/
-QVariant QAbstractVideoBuffer::handle() const
-{
- return QVariant();
-}
-
-
-int QAbstractPlanarVideoBufferPrivate::map(
- QAbstractVideoBuffer::MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4])
-{
- return q_func()->map(mode, numBytes, bytesPerLine, data);
-}
-
-/*!
- \class QAbstractPlanarVideoBuffer
- \brief The QAbstractPlanarVideoBuffer class is an abstraction for planar video data.
- \inmodule QtMultimedia
- \ingroup QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_video
-
- QAbstractPlanarVideoBuffer extends QAbstractVideoBuffer to support mapping
- non-continuous planar video data. Implement this instead of QAbstractVideoBuffer when the
- abstracted video data stores planes in separate buffers or includes padding between planes
- which would interfere with calculating offsets from the bytes per line and frame height.
-
- \sa QAbstractVideoBuffer::mapPlanes()
- \since 5.4
-*/
-
-/*!
- Constructs an abstract planar video buffer of the given \a type.
-*/
-QAbstractPlanarVideoBuffer::QAbstractPlanarVideoBuffer(HandleType type)
- : QAbstractVideoBuffer(*new QAbstractPlanarVideoBufferPrivate, type)
-{
-}
-
-/*!
- \internal
-*/
-QAbstractPlanarVideoBuffer::QAbstractPlanarVideoBuffer(
- QAbstractPlanarVideoBufferPrivate &dd, HandleType type)
- : QAbstractVideoBuffer(dd, type)
-{
-}
-/*!
- Destroys an abstract planar video buffer.
-*/
-QAbstractPlanarVideoBuffer::~QAbstractPlanarVideoBuffer()
-{
-}
+ For CPU video buffers, the function may be not overridden.
+ The default implementation of \c unmap does nothing.
-/*!
- \internal
+ \sa map()
*/
-uchar *QAbstractPlanarVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
-{
- uchar *data[4];
- int strides[4];
- if (map(mode, numBytes, strides, data) > 0) {
- if (bytesPerLine)
- *bytesPerLine = strides[0];
- return data[0];
- } else {
- return nullptr;
- }
-}
/*!
- \fn int QAbstractPlanarVideoBuffer::map(MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4])
-
- Maps the contents of a video buffer to memory.
+ \fn QAbstractVideoBuffer::format() const
- The map \a mode indicates whether the contents of the mapped memory should be read from and/or
- written to the buffer. If the map mode includes the \c QAbstractVideoBuffer::ReadOnly flag the
- mapped memory will be populated with the content of the buffer when initially mapped. If the map
- mode includes the \c QAbstractVideoBuffer::WriteOnly flag the content of the possibly modified
- mapped memory will be written back to the buffer when unmapped.
-
- When access to the data is no longer needed be sure to call the unmap() function to release the
- mapped memory and possibly update the buffer contents.
+ Gets \l QVideoFrameFormat of the underlying video buffer.
- Returns the number of planes in the mapped video data. For each plane the line stride of that
- plane will be returned in \a bytesPerLine, and a pointer to the plane data will be returned in
- \a data. The accumulative size of the mapped data is returned in \a numBytes.
-
- \sa QAbstractVideoBuffer::map(), QAbstractVideoBuffer::unmap(), QAbstractVideoBuffer::mapMode()
+ The format must be available upon construction of \l QVideoFrame.
+ QVideoFrame will contain won instance of the given format, that
+ can be detached and modified.
*/
-#ifndef QT_NO_DEBUG_STREAM
-QDebug operator<<(QDebug dbg, QAbstractVideoBuffer::HandleType type)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (type) {
- case QAbstractVideoBuffer::NoHandle:
- return dbg << "NoHandle";
- case QAbstractVideoBuffer::GLTextureHandle:
- return dbg << "GLTextureHandle";
- case QAbstractVideoBuffer::MTLTextureHandle:
- return dbg << "MTLTextureHandle";
- case QAbstractVideoBuffer::XvShmImageHandle:
- return dbg << "XvShmImageHandle";
- case QAbstractVideoBuffer::CoreImageHandle:
- return dbg << "CoreImageHandle";
- case QAbstractVideoBuffer::QPixmapHandle:
- return dbg << "QPixmapHandle";
- default:
- return dbg << "UserHandle(" << int(type) << ')';
- }
-}
-
-QDebug operator<<(QDebug dbg, QAbstractVideoBuffer::MapMode mode)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (mode) {
- case QAbstractVideoBuffer::ReadOnly:
- return dbg << "ReadOnly";
- case QAbstractVideoBuffer::ReadWrite:
- return dbg << "ReadWrite";
- case QAbstractVideoBuffer::WriteOnly:
- return dbg << "WriteOnly";
- default:
- return dbg << "NotMapped";
- }
-}
-#endif
-
QT_END_NAMESPACE
diff --git a/src/multimedia/video/qabstractvideobuffer.h b/src/multimedia/video/qabstractvideobuffer.h
index b3f31b377..3e046f3b4 100644
--- a/src/multimedia/video/qabstractvideobuffer.h
+++ b/src/multimedia/video/qabstractvideobuffer.h
@@ -1,131 +1,32 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QABSTRACTVIDEOBUFFER_H
#define QABSTRACTVIDEOBUFFER_H
-#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
-
-
-#include <QtCore/qmetatype.h>
+#include <QtMultimedia/qtmultimediaexports.h>
+#include <QtMultimedia/qvideoframeformat.h>
+#include <QtMultimedia/qtvideo.h>
QT_BEGIN_NAMESPACE
-
-class QVariant;
-
-class QAbstractVideoBufferPrivate;
-
class Q_MULTIMEDIA_EXPORT QAbstractVideoBuffer
{
public:
- enum HandleType
+ struct MapData
{
- NoHandle,
- GLTextureHandle,
- MTLTextureHandle,
- XvShmImageHandle,
- CoreImageHandle,
- QPixmapHandle,
- EGLImageHandle,
- UserHandle = 1000
+ int planeCount = 0;
+ int bytesPerLine[4] = {};
+ uchar *data[4] = {};
+ int dataSize[4] = {};
};
- enum MapMode
- {
- NotMapped = 0x00,
- ReadOnly = 0x01,
- WriteOnly = 0x02,
- ReadWrite = ReadOnly | WriteOnly
- };
-
- QAbstractVideoBuffer(HandleType type);
virtual ~QAbstractVideoBuffer();
- virtual void release();
-
- HandleType handleType() const;
-
- virtual MapMode mapMode() const = 0;
-
- virtual uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) = 0;
- int mapPlanes(MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4]);
- virtual void unmap() = 0;
-
- virtual QVariant handle() const;
-
-protected:
- QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type);
-
- QAbstractVideoBufferPrivate *d_ptr; // For expansion, not used currently
- HandleType m_type;
-
-private:
- Q_DECLARE_PRIVATE(QAbstractVideoBuffer)
- Q_DISABLE_COPY(QAbstractVideoBuffer)
-};
-
-class QAbstractPlanarVideoBufferPrivate;
-class Q_MULTIMEDIA_EXPORT QAbstractPlanarVideoBuffer : public QAbstractVideoBuffer
-{
-public:
- QAbstractPlanarVideoBuffer(HandleType type);
- virtual ~QAbstractPlanarVideoBuffer();
-
- uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) override;
- virtual int map(MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4]) = 0;
-
-protected:
- QAbstractPlanarVideoBuffer(QAbstractPlanarVideoBufferPrivate &dd, HandleType type);
-
-private:
- Q_DISABLE_COPY(QAbstractPlanarVideoBuffer)
+ virtual MapData map(QtVideo::MapMode mode) = 0;
+ virtual void unmap() { }
+ virtual QVideoFrameFormat format() const = 0;
};
-#ifndef QT_NO_DEBUG_STREAM
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QAbstractVideoBuffer::HandleType);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QAbstractVideoBuffer::MapMode);
-#endif
-
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QAbstractVideoBuffer::HandleType)
-Q_DECLARE_METATYPE(QAbstractVideoBuffer::MapMode)
-
#endif
diff --git a/src/multimedia/video/qabstractvideobuffer_p.h b/src/multimedia/video/qabstractvideobuffer_p.h
deleted file mode 100644
index 4877d3120..000000000
--- a/src/multimedia/video/qabstractvideobuffer_p.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QABSTRACTVIDEOBUFFER_P_H
-#define QABSTRACTVIDEOBUFFER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qshareddata.h>
-#include "qabstractvideobuffer.h"
-
-#include <qtmultimediaglobal.h>
-#include <qmultimedia.h>
-
-
-QT_BEGIN_NAMESPACE
-
-class QAbstractVideoBufferPrivate
-{
-public:
- QAbstractVideoBufferPrivate()
- : q_ptr(nullptr)
- {}
-
- virtual ~QAbstractVideoBufferPrivate()
- {}
-
- virtual int map(
- QAbstractVideoBuffer::MapMode mode,
- int *numBytes,
- int bytesPerLine[4],
- uchar *data[4]);
-
- QAbstractVideoBuffer *q_ptr;
-};
-
-class QAbstractPlanarVideoBufferPrivate : QAbstractVideoBufferPrivate
-{
-public:
- QAbstractPlanarVideoBufferPrivate()
- {}
-
- int map(QAbstractVideoBuffer::MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4]) override;
-
-private:
- Q_DECLARE_PUBLIC(QAbstractPlanarVideoBuffer)
-};
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/multimedia/video/qabstractvideofilter.cpp b/src/multimedia/video/qabstractvideofilter.cpp
deleted file mode 100644
index 84dd8e0f2..000000000
--- a/src/multimedia/video/qabstractvideofilter.cpp
+++ /dev/null
@@ -1,325 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qabstractvideofilter.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QAbstractVideoFilter
- \since 5.5
- \brief The QAbstractVideoFilter class represents a filter that is applied to the video frames
- received by a VideoOutput type.
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_video
-
- QAbstractVideoFilter provides a convenient way for applications to run image
- processing, computer vision algorithms or any generic transformation or
- calculation on the output of a VideoOutput type, regardless of the source
- (video or camera). By providing a simple interface it allows applications and
- third parties to easily develop QML types that provide image processing
- algorithms using popular frameworks like \l{http://opencv.org}{OpenCV}. Due to
- the close integration with the final stages of the Qt Multimedia video
- pipeline, accelerated and possibly zero-copy solutions are feasible too: for
- instance, a plugin providing OpenCL-based algorithms can use OpenCL's OpenGL
- interop to use the OpenGL textures created by a hardware accelerated video
- decoder, without additional readbacks and copies.
-
- \note QAbstractVideoFilter is not always the best choice. To apply effects or
- transformations using OpenGL shaders to the image shown on screen, the
- standard Qt Quick approach of using ShaderEffect items in combination with
- VideoOutput should be used. VideoFilter is not a replacement for this. It is
- rather targeted for performing computations (that do not necessarily change
- the image shown on screen) and computer vision algorithms provided by
- external frameworks.
-
- QAbstractVideoFilter is meant to be subclassed. The subclasses are then registered to
- the QML engine, so they can be used as a QML type. The list of filters are
- assigned to a VideoOutput type via its \l{QtMultimedia::VideoOutput::filters}{filters}
- property.
-
- A single filter represents one transformation or processing step on
- a video frame. The output is a modified video frame, some arbitrary data or
- both. For example, image transformations will result in a different image,
- whereas an algorithm for detecting objects on an image will likely provide
- a list of rectangles.
-
- Arbitrary data can be represented as properties on the QAbstractVideoFilter subclass
- and on the QObject or QJSValue instances passed to its signals. What exactly
- these properties and signals are, is up to the individual video
- filters. Completion of the operations can be indicated by
- signals. Computations that do not result in a modified image will pass the
- input image through so that subsequent filters can be placed after them.
-
- Properties set on QAbstractVideoFilter serve as input to the computation, similarly
- to how uniform values are specified in ShaderEffect types. The changed
- property values are taken into use when the next video frame is processed.
-
- The typical usage is to subclass QAbstractVideoFilter and QVideoFilterRunnable:
-
- \badcode
- class MyFilterRunnable : public QVideoFilterRunnable {
- public:
- QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags) { ... }
- };
-
- class MyFilter : public QAbstractVideoFilter {
- public:
- QVideoFilterRunnable *createFilterRunnable() { return new MyFilterRunnable; }
- signals:
- void finished(QObject *result);
- };
-
- int main(int argc, char **argv) {
- ...
- qmlRegisterType<MyFilter>("my.uri", 1, 0, "MyFilter");
- ...
- }
- \endcode
-
- MyFilter is thus accessible from QML:
-
- \badcode
- import my.uri 1.0
-
- Camera {
- id: camera
- }
- MyFilter {
- id: filter
- // set properties, they can also be animated
- onFinished: console.log("results of the computation: " + result)
- }
- VideoOutput {
- source: camera
- filters: [ filter ]
- anchors.fill: parent
- }
- \endcode
-
- This also allows providing filters in QML plugins, separately from the application.
-
- \sa VideoOutput, Camera, MediaPlayer, QVideoFilterRunnable
-*/
-
-/*!
- \class QVideoFilterRunnable
- \since 5.5
- \brief The QVideoFilterRunnable class represents the implementation of a filter
- that owns all graphics and computational resources, and performs the actual filtering
- or calculations.
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_video
-
- Video filters are split into QAbstractVideoFilter and corresponding QVideoFilterRunnable
- instances, similar to QQuickItem and QSGNode. This is necessary to support
- threaded rendering scenarios. When using the threaded render loop of the Qt
- Quick scene graph, all rendering happens on a dedicated thread.
- QVideoFilterRunnable instances always live on this thread and all its functions,
- run(), the constructor, and the destructor, are guaranteed to be invoked on
- that thread with the OpenGL context bound. QAbstractVideoFilter instances live on
- the main (GUI) thread, like any other QObject and QQuickItem instances
- created from QML.
-
- Once created, QVideoFilterRunnable instances are managed by Qt Multimedia and
- will be automatically destroyed and recreated when necessary, for example
- when the scene graph is invalidated or the QQuickWindow changes or is closed.
- Creation happens via the QAbstractVideoFilter::createFilterRunnable() factory function.
-
- \sa QAbstractVideoFilter
- */
-
-/*!
- \fn QVideoFrame QVideoFilterRunnable::run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags)
-
- Reimplement this function to perform filtering or computation on the \a
- input video frame. Like the constructor and destructor, this function is
- always called on the render thread with the OpenGL context bound.
-
- Implementations that do not modify the video frame can simply return \a input.
-
- It is safe to access properties of the associated QAbstractVideoFilter instance from
- this function.
-
- \a input will not be mapped, it is up to this function to call QVideoFrame::map()
- and QVideoFrame::unmap() as necessary.
-
- \a surfaceFormat provides additional information, for example it can be used
- to determine which way is up in the input image as that is important for
- filters to operate on multiple platforms with multiple cameras.
-
- \a flags contains additional information about the filter's invocation. For
- example the LastInChain flag indicates that the filter is the last in a
- VideoOutput's associated filter list. This can be very useful in cases where
- multiple filters are chained together and the work is performed on image data
- in some custom format (for example a format specific to some computer vision
- framework). To avoid conversion on every filter in the chain, all
- intermediate filters can return a QVideoFrame hosting data in the custom
- format. Only the last, where the flag is set, returns a QVideoFrame in a
- format compatible with Qt.
-
- Filters that want to expose the results of their computation to Javascript
- code in QML can declare their own custom signals in the QAbstractVideoFilter
- subclass to indicate the completion of the operation. For filters that only
- calculate some results and do not modify the video frame, it is also possible
- to operate asynchronously. They can queue the necessary operations using the
- compute API and return from this function without emitting any signals. The
- signal indicating the completion is then emitted only when the compute API
- indicates that the operations were done and the results are available. Note
- that it is strongly recommended to represent the filter's output data as a
- separate instance of QJSValue or a QObject-derived class which is passed as a
- parameter to the signal and becomes exposed to the Javascript engine. In case
- of QObject the ownership of this object is controlled by the standard QML
- rules: if it has no parent, ownership is transferred to the Javascript engine,
- otherwise it stays with the emitter. Note that the signal connection may be
- queued,for example when using the threaded render loop of Qt Quick, and so the
- object must stay valid for a longer time, destroying it right after calling
- this function is not safe. Using a dedicated results object is guaranteed to
- be safe even when using threaded rendering. The same is not necessarily true
- for properties on the QAbstractVideoFilter instance itself: properties can
- safely be read in run() since the gui thread is blocked during that time but
- writing may become problematic.
-
- \note Avoid time consuming operations in this function as they block the
- entire rendering of the application.
-
- \note The handleType() and pixelFormat() of \a input is completely up to the
- video decoding backend on the platform in use. On some platforms different
- forms of input are used depending on the graphics stack. For example, when
- playing back videos on Windows with the WMF backend, QVideoFrame contains
- OpenGL-wrapped Direct3D textures in case of using ANGLE, but regular pixel
- data when using desktop OpenGL (opengl32.dll). Similarly, the video file
- format will often decide if the data is RGB or YUV, but this may also depend
- on the decoder and the configuration in use. The returned video frame does
- not have to be in the same format as the input, for example a filter with an
- input of a QVideoFrame backed by system memory can output a QVideoFrame with
- an OpenGL texture handle.
-
- \sa QVideoFrame, QVideoSurfaceFormat
- */
-
-/*!
- \enum QVideoFilterRunnable::RunFlag
-
- \value LastInChain Indicates that the filter runnable's associated QAbstractVideoFilter
- is the last in the corresponding VideoOutput type's filters list, meaning
- that the returned frame is the one that is going to be presented to the scene
- graph without invoking any further filters.
- */
-
-class QAbstractVideoFilterPrivate
-{
-public:
- QAbstractVideoFilterPrivate() :
- active(true)
- { }
-
- bool active;
-};
-
-/*!
- \internal
- */
-QVideoFilterRunnable::~QVideoFilterRunnable()
-{
-}
-
-/*!
- Constructs a new QAbstractVideoFilter instance with parent object \a parent.
- */
-QAbstractVideoFilter::QAbstractVideoFilter(QObject *parent) :
- QObject(parent),
- d_ptr(new QAbstractVideoFilterPrivate)
-{
-}
-
-/*!
- \internal
- */
-QAbstractVideoFilter::~QAbstractVideoFilter()
-{
- delete d_ptr;
-}
-
-/*!
- \property QAbstractVideoFilter::active
- \brief the active status of the filter.
-
- This is true if the filter is active, false otherwise.
-
- By default filters are active. When set to \c false, the filter will be
- ignored by the VideoOutput type.
- */
-bool QAbstractVideoFilter::isActive() const
-{
- Q_D(const QAbstractVideoFilter);
- return d->active;
-}
-
-void QAbstractVideoFilter::setActive(bool v)
-{
- Q_D(QAbstractVideoFilter);
- if (d->active != v) {
- d->active = v;
- emit activeChanged();
- }
-}
-
-/*!
- \fn QVideoFilterRunnable *QAbstractVideoFilter::createFilterRunnable()
-
- Factory function to create a new instance of a QVideoFilterRunnable subclass
- corresponding to this filter.
-
- This function is called on the thread on which the Qt Quick scene graph
- performs rendering, with the OpenGL context bound. Ownership of the returned
- instance is transferred: the returned instance will live on the render thread
- and will be destroyed automatically when necessary.
-
- Typically, implementations of the function will simply construct a new
- QVideoFilterRunnable instance, passing \c this to the constructor as the
- filter runnables must know their associated QAbstractVideoFilter instance to
- access dynamic properties and optionally emit signals.
- */
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/video/qabstractvideofilter.h b/src/multimedia/video/qabstractvideofilter.h
deleted file mode 100644
index 6263f4730..000000000
--- a/src/multimedia/video/qabstractvideofilter.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QABSTRACTVIDEOFILTER_H
-#define QABSTRACTVIDEOFILTER_H
-
-#include <QtCore/qobject.h>
-#include <QtMultimedia/qvideoframe.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAbstractVideoFilterPrivate;
-
-class Q_MULTIMEDIA_EXPORT QVideoFilterRunnable
-{
-public:
- enum RunFlag {
- LastInChain = 0x01
- };
- Q_DECLARE_FLAGS(RunFlags, RunFlag)
-
- virtual ~QVideoFilterRunnable();
- virtual QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags) = 0;
-};
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(QVideoFilterRunnable::RunFlags)
-
-class Q_MULTIMEDIA_EXPORT QAbstractVideoFilter : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
-
-public:
- explicit QAbstractVideoFilter(QObject *parent = nullptr);
- ~QAbstractVideoFilter();
-
- bool isActive() const;
- void setActive(bool v);
-
- virtual QVideoFilterRunnable *createFilterRunnable() = 0;
-
-Q_SIGNALS:
- void activeChanged();
-
-private:
- Q_DECLARE_PRIVATE(QAbstractVideoFilter)
- Q_DISABLE_COPY(QAbstractVideoFilter)
-
- QAbstractVideoFilterPrivate *d_ptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QABSTRACTVIDEOFILTER_H
diff --git a/src/multimedia/video/qabstractvideosurface.cpp b/src/multimedia/video/qabstractvideosurface.cpp
deleted file mode 100644
index 68a190e40..000000000
--- a/src/multimedia/video/qabstractvideosurface.cpp
+++ /dev/null
@@ -1,389 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//TESTED_COMPONENT=src/multimedia
-
-#include "qabstractvideosurface.h"
-
-#include "qvideosurfaceformat.h"
-
-#include <QtCore/qvariant.h>
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-static void qRegisterAbstractVideoSurfaceMetaTypes()
-{
- qRegisterMetaType<QAbstractVideoSurface::Error>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterAbstractVideoSurfaceMetaTypes)
-
-
-class QAbstractVideoSurfacePrivate {
-public:
- QAbstractVideoSurfacePrivate()
- : error(QAbstractVideoSurface::NoError),
- active(false)
- {
- }
-
-public:
- QVideoSurfaceFormat surfaceFormat;
- QAbstractVideoSurface::Error error;
- QSize nativeResolution;
- bool active;
-};
-
-/*!
- \class QAbstractVideoSurface
- \brief The QAbstractVideoSurface class is a base class for video presentation surfaces.
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_video
-
- The QAbstractVideoSurface class defines the standard interface that video producers use to
- inter-operate with video presentation surfaces. You can subclass this interface to receive
- video frames from sources like \l {QMediaPlayer}{decoded media} or \l {QCamera}{cameras} to
- perform your own processing.
-
- A video surface presents a continuous stream of identically formatted QVideoFrame instances, where the format
- of each frame is compatible with a stream format supplied when starting a presentation. Each frame
- may have timestamp information that can be used by the surface to decide when to display that
- frame.
-
- A list of pixel formats a surface can present is given by the supportedPixelFormats() function,
- and the isFormatSupported() function will test if a video surface format is supported. If a
- format is not supported the nearestFormat() function may be able to suggest a similar format.
- For example, if a surface supports fixed set of resolutions it may suggest the smallest
- supported resolution that contains the proposed resolution.
-
- The start() function takes a supported format and enables a video surface. Once started a
- surface will begin displaying the frames it receives in the present() function. Surfaces may
- hold a reference to the buffer of a presented video frame until a new frame is presented or
- streaming is stopped. In addition, a video surface may hold a reference to a video frame
- until the \l {QVideoFrame::endTime()}{end timestamp} has passed. The stop() function will
- disable a surface and release any video buffers it holds references to.
-
- \section2 Implementing a subclass of QAbstractVideoSurface
-
- When implementing a subclass of this interface, there are only a handful of functions to
- implement, broken down into two classes:
-
- \list
- \li Format related
- \li Presentation related
- \endlist
-
- For format related functionality, you just have to describe the pixel formats that you
- support (and the nearestFormat() function). For presentation related functionality, you
- have to implement the present() function, and the start() and stop() functions.
-
- \note You must call the base class implementation of start() and stop() in your implementation.
-*/
-
-/*!
- \enum QAbstractVideoSurface::Error
- This enum describes the errors that may be returned by the error() function.
-
- \value NoError No error occurred.
- \value UnsupportedFormatError A video format was not supported.
- \value IncorrectFormatError A video frame was not compatible with the format of the surface.
- \value StoppedError The surface has not been started.
- \value ResourceError The surface could not allocate some resource.
-*/
-
-/*!
- Constructs a video surface with the given \a parent.
-*/
-QAbstractVideoSurface::QAbstractVideoSurface(QObject *parent)
- : QObject(parent),
- d_ptr(new QAbstractVideoSurfacePrivate)
-{
-}
-
-/*!
- Destroys a video surface.
-*/
-QAbstractVideoSurface::~QAbstractVideoSurface()
-{
-}
-
-/*!
- \fn QAbstractVideoSurface::supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const
-
- Returns a list of pixel formats a video surface can present for a given handle \a type.
-
- The pixel formats returned for the QAbstractVideoBuffer::NoHandle type are valid for any buffer
- that can be mapped in read-only mode.
-
- Types that are first in the list can be assumed to be faster to render.
-*/
-
-/*!
- Tests a video surface \a format to determine if a surface can accept it.
-
- Returns true if the format is supported by the surface, and false otherwise.
-*/
-bool QAbstractVideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const
-{
- return supportedPixelFormats(format.handleType()).contains(format.pixelFormat());
-}
-
-/*!
- Returns a supported video surface format that is similar to \a format.
-
- A similar surface format is one that has the same \l {QVideoSurfaceFormat::pixelFormat()}{pixel
- format} and \l {QVideoSurfaceFormat::handleType()}{handle type} but may differ in some of the other
- properties. For example, if there are restrictions on the \l {QVideoSurfaceFormat::frameSize()}
- {frame sizes} a video surface can accept it may suggest a format with a larger frame size and
- a \l {QVideoSurfaceFormat::viewport()}{viewport} the size of the original frame size.
-
- If the format is already supported it will be returned unchanged, or if there is no similar
- supported format an invalid format will be returned.
-*/
-QVideoSurfaceFormat QAbstractVideoSurface::nearestFormat(const QVideoSurfaceFormat &format) const
-{
- return isFormatSupported(format)
- ? format
- : QVideoSurfaceFormat();
-}
-
-/*!
- \fn QAbstractVideoSurface::supportedFormatsChanged()
-
- Signals that the set of formats supported by a video surface has changed.
-
- \sa supportedPixelFormats(), isFormatSupported()
-*/
-
-/*!
- Returns the format of a video surface.
-*/
-QVideoSurfaceFormat QAbstractVideoSurface::surfaceFormat() const
-{
- Q_D(const QAbstractVideoSurface);
- return d->surfaceFormat;
-}
-
-/*!
- \fn QAbstractVideoSurface::surfaceFormatChanged(const QVideoSurfaceFormat &format)
-
- Signals that the configured \a format of a video surface has changed.
-
- \sa surfaceFormat(), start()
-*/
-
-/*!
- Starts a video surface presenting \a format frames.
-
- Returns true if the surface was started, and false if an error occurred.
-
- \note You must call the base class implementation of start() at the end of your implementation.
- \sa isActive(), stop()
-*/
-bool QAbstractVideoSurface::start(const QVideoSurfaceFormat &format)
-{
- Q_D(QAbstractVideoSurface);
- bool wasActive = d->active;
-
- d->active = true;
- d->surfaceFormat = format;
- d->error = NoError;
-
- emit surfaceFormatChanged(format);
-
- if (!wasActive)
- emit activeChanged(true);
-
- return true;
-}
-
-/*!
- Stops a video surface presenting frames and releases any resources acquired in start().
-
- \note You must call the base class implementation of stop() at the start of your implementation.
- \sa isActive(), start()
-*/
-void QAbstractVideoSurface::stop()
-{
- Q_D(QAbstractVideoSurface);
- if (d->active) {
- d->surfaceFormat = QVideoSurfaceFormat();
- d->active = false;
-
- emit activeChanged(false);
- emit surfaceFormatChanged(surfaceFormat());
- }
-}
-
-/*!
- Indicates whether a video surface has been started.
-
- Returns true if the surface has been started, and false otherwise.
-*/
-bool QAbstractVideoSurface::isActive() const
-{
- Q_D(const QAbstractVideoSurface);
- return d->active;
-}
-
-/*!
- \fn QAbstractVideoSurface::activeChanged(bool active)
-
- Signals that the \a active state of a video surface has changed.
-
- \sa isActive(), start(), stop()
-*/
-
-/*!
- \fn QAbstractVideoSurface::present(const QVideoFrame &frame)
-
- Presents a video \a frame.
-
- Returns true if the frame was presented, and false if an error occurred.
-
- Not all surfaces will block until the presentation of a frame has completed. Calling present()
- on a non-blocking surface may fail if called before the presentation of a previous frame has
- completed. In such cases the surface may not return to a ready state until it has had an
- opportunity to process events.
-
- If present() fails for any other reason the surface should immediately enter the stopped state
- and an error() value will be set.
-
- A video surface must be in the started state for present() to succeed, and the format of the
- video frame must be compatible with the current video surface format.
-
- \sa error()
-*/
-
-/*!
- Returns the last error that occurred.
-
- If a surface fails to start(), or stops unexpectedly this function can be called to discover
- what error occurred.
-*/
-
-QAbstractVideoSurface::Error QAbstractVideoSurface::error() const
-{
- Q_D(const QAbstractVideoSurface);
- return d->error;
-}
-
-/*!
- Sets the value of error() to \a error.
-
- This can be called by implementors of this interface to communicate
- what the most recent error was.
-*/
-void QAbstractVideoSurface::setError(Error error)
-{
- Q_D(QAbstractVideoSurface);
- d->error = error;
-}
-
-/*!
- \property QAbstractVideoSurface::nativeResolution
-
- The native resolution of video surface.
- This is the resolution of video frames the surface
- can render with optimal quality and/or performance.
-
- The native resolution is not always known and can be changed during playback.
- */
-QSize QAbstractVideoSurface::nativeResolution() const
-{
- Q_D(const QAbstractVideoSurface);
- return d->nativeResolution;
-}
-
-/*!
- Set the video surface native \a resolution.
-
- This function can be called by implementors of this interface to specify
- to frame producers what the native resolution of this surface is.
- */
-void QAbstractVideoSurface::setNativeResolution(const QSize &resolution)
-{
- Q_D(QAbstractVideoSurface);
-
- if (d->nativeResolution != resolution) {
- d->nativeResolution = resolution;
-
- emit nativeResolutionChanged(resolution);
- }
-}
-/*!
- \fn QAbstractVideoSurface::nativeResolutionChanged(const QSize &resolution);
-
- Signals the native \a resolution of video surface has changed.
-*/
-
-#ifndef QT_NO_DEBUG_STREAM
-QDebug operator<<(QDebug dbg, const QAbstractVideoSurface::Error& error)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (error) {
- case QAbstractVideoSurface::UnsupportedFormatError:
- dbg << "UnsupportedFormatError";
- break;
- case QAbstractVideoSurface::IncorrectFormatError:
- dbg << "IncorrectFormatError";
- break;
- case QAbstractVideoSurface::StoppedError:
- dbg << "StoppedError";
- break;
- case QAbstractVideoSurface::ResourceError:
- dbg << "ResourceError";
- break;
- default:
- dbg << "NoError";
- break;
- }
- return dbg;
-}
-#endif
-
-
-QT_END_NAMESPACE
-
-#include "moc_qabstractvideosurface.cpp"
-
diff --git a/src/multimedia/video/qabstractvideosurface.h b/src/multimedia/video/qabstractvideosurface.h
deleted file mode 100644
index c136ba6c1..000000000
--- a/src/multimedia/video/qabstractvideosurface.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QABSTRACTVIDEOSURFACE_H
-#define QABSTRACTVIDEOSURFACE_H
-
-#include <QtCore/qobject.h>
-#include <QtMultimedia/qvideoframe.h>
-
-QT_BEGIN_NAMESPACE
-
-class QRectF;
-class QVideoSurfaceFormat;
-
-class QAbstractVideoSurfacePrivate;
-
-class Q_MULTIMEDIA_EXPORT QAbstractVideoSurface : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QSize nativeResolution READ nativeResolution NOTIFY nativeResolutionChanged)
-public:
- enum Error
- {
- NoError,
- UnsupportedFormatError,
- IncorrectFormatError,
- StoppedError,
- ResourceError
- };
-
- explicit QAbstractVideoSurface(QObject *parent = nullptr);
- ~QAbstractVideoSurface();
-
- virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(
- QAbstractVideoBuffer::HandleType type = QAbstractVideoBuffer::NoHandle) const = 0;
- virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const;
- virtual QVideoSurfaceFormat nearestFormat(const QVideoSurfaceFormat &format) const;
-
- QVideoSurfaceFormat surfaceFormat() const;
-
- QSize nativeResolution() const;
-
- virtual bool start(const QVideoSurfaceFormat &format);
- virtual void stop();
-
- bool isActive() const;
-
- virtual bool present(const QVideoFrame &frame) = 0;
-
- Error error() const;
-
-Q_SIGNALS:
- void activeChanged(bool active);
- void surfaceFormatChanged(const QVideoSurfaceFormat &format);
- void supportedFormatsChanged();
- void nativeResolutionChanged(const QSize &resolution);
-
-protected:
- void setError(Error error);
- void setNativeResolution(const QSize &resolution);
-
-private:
- Q_DECLARE_PRIVATE(QAbstractVideoSurface)
- QScopedPointer<QAbstractVideoSurfacePrivate> d_ptr;
-};
-
-#ifndef QT_NO_DEBUG_STREAM
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QAbstractVideoSurface::Error &);
-#endif
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QAbstractVideoSurface*)
-Q_DECLARE_METATYPE(QAbstractVideoSurface::Error)
-
-#endif
diff --git a/src/multimedia/video/qhwvideobuffer.cpp b/src/multimedia/video/qhwvideobuffer.cpp
new file mode 100644
index 000000000..ecd3435d0
--- /dev/null
+++ b/src/multimedia/video/qhwvideobuffer.cpp
@@ -0,0 +1,17 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qhwvideobuffer_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QVideoFrameTextures::~QVideoFrameTextures() = default;
+
+QHwVideoBuffer::QHwVideoBuffer(QVideoFrame::HandleType type, QRhi *rhi) : m_type(type), m_rhi(rhi)
+{
+}
+
+// must be out-of-line to ensure correct working of dynamic_cast when QHwVideoBuffer is created in tests
+QHwVideoBuffer::~QHwVideoBuffer() = default;
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/video/qhwvideobuffer_p.h b/src/multimedia/video/qhwvideobuffer_p.h
new file mode 100644
index 000000000..fabf82dce
--- /dev/null
+++ b/src/multimedia/video/qhwvideobuffer_p.h
@@ -0,0 +1,58 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QHWVIDEOBUFFER_P_H
+#define QHWVIDEOBUFFER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qabstractvideobuffer.h"
+#include "qvideoframe.h"
+
+#include <QtGui/qmatrix4x4.h>
+
+QT_BEGIN_NAMESPACE
+
+class QRhi;
+class QRhiTexture;
+
+class Q_MULTIMEDIA_EXPORT QVideoFrameTextures
+{
+public:
+ virtual ~QVideoFrameTextures();
+ virtual QRhiTexture *texture(uint plane) const = 0;
+};
+
+class Q_MULTIMEDIA_EXPORT QHwVideoBuffer : public QAbstractVideoBuffer
+{
+public:
+ QHwVideoBuffer(QVideoFrame::HandleType type, QRhi *rhi = nullptr);
+
+ ~QHwVideoBuffer() override;
+
+ QVideoFrame::HandleType handleType() const { return m_type; }
+ QRhi *rhi() const { return m_rhi; }
+
+ QVideoFrameFormat format() const override { return {}; }
+
+ virtual std::unique_ptr<QVideoFrameTextures> mapTextures(QRhi *) { return {}; }
+ virtual quint64 textureHandle(QRhi *, int /*plane*/) const { return 0; }
+ virtual QMatrix4x4 externalTextureMatrix() const { return {}; }
+
+protected:
+ QVideoFrame::HandleType m_type;
+ QRhi *m_rhi = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QHWVIDEOBUFFER_P_H
diff --git a/src/multimedia/video/qimagevideobuffer.cpp b/src/multimedia/video/qimagevideobuffer.cpp
index 28dacefc6..6f35f0e53 100644
--- a/src/multimedia/video/qimagevideobuffer.cpp
+++ b/src/multimedia/video/qimagevideobuffer.cpp
@@ -1,110 +1,85 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qimagevideobuffer_p.h"
-
-#include "qabstractvideobuffer_p.h"
-
-#include <qimage.h>
-#include <qvariant.h>
+#include "qvideoframeformat.h"
QT_BEGIN_NAMESPACE
-/*!
- * \class QImageVideoBuffer
- * \internal
- *
- * A video buffer class for a QImage.
- */
-class QImageVideoBufferPrivate : public QAbstractVideoBufferPrivate
-{
-public:
- QImageVideoBufferPrivate()
- : mapMode(QAbstractVideoBuffer::NotMapped)
- {
- }
-
- QAbstractVideoBuffer::MapMode mapMode;
- QImage image;
-};
-
-QImageVideoBuffer::QImageVideoBuffer(const QImage &image)
- : QAbstractVideoBuffer(*new QImageVideoBufferPrivate, NoHandle)
-{
- Q_D(QImageVideoBuffer);
-
- d->image = image;
-}
+namespace {
-QImageVideoBuffer::~QImageVideoBuffer()
+QImage::Format fixImageFormat(QImage::Format format)
{
+ switch (format) {
+ case QImage::Format_ARGB32_Premultiplied:
+ case QImage::Format_ARGB8565_Premultiplied:
+ case QImage::Format_ARGB6666_Premultiplied:
+ case QImage::Format_ARGB8555_Premultiplied:
+ case QImage::Format_ARGB4444_Premultiplied:
+ case QImage::Format_RGBA8888_Premultiplied:
+ case QImage::Format_A2BGR30_Premultiplied:
+ case QImage::Format_A2RGB30_Premultiplied:
+ case QImage::Format_RGBA64_Premultiplied:
+ case QImage::Format_RGBA16FPx4_Premultiplied:
+ case QImage::Format_RGBA32FPx4_Premultiplied:
+ return QImage::Format_ARGB32_Premultiplied;
+ case QImage::Format_ARGB32:
+ case QImage::Format_RGBA8888:
+ case QImage::Format_Alpha8:
+ case QImage::Format_RGBA64:
+ case QImage::Format_RGBA16FPx4:
+ case QImage::Format_RGBA32FPx4:
+ return QImage::Format_ARGB32;
+ case QImage::Format_Invalid:
+ return QImage::Format_Invalid;
+ default:
+ return QImage::Format_RGB32;
+ }
}
-QAbstractVideoBuffer::MapMode QImageVideoBuffer::mapMode() const
+QImage fixImage(QImage image)
{
- return d_func()->mapMode;
-}
+ if (image.format() == QImage::Format_Invalid)
+ return image;
-uchar *QImageVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
-{
- Q_D(QImageVideoBuffer);
+ const auto frameFormat = QVideoFrameFormat::pixelFormatFromImageFormat(image.format());
+ if (frameFormat != QVideoFrameFormat::Format_Invalid)
+ return image;
- if (d->mapMode == NotMapped && d->image.bits() && mode != NotMapped) {
- d->mapMode = mode;
+ return image.convertToFormat(fixImageFormat(image.format()));
+}
- if (numBytes)
- *numBytes = int(d->image.sizeInBytes());
+} // namespace
- if (bytesPerLine)
- *bytesPerLine = d->image.bytesPerLine();
+QImageVideoBuffer::QImageVideoBuffer(QImage image) : m_image(fixImage(std::move(image))) { }
- return d->image.bits();
- } else {
- return nullptr;
+QAbstractVideoBuffer::MapData QImageVideoBuffer::map(QtVideo::MapMode mode)
+{
+ MapData mapData;
+ if (m_mapMode == QtVideo::MapMode::NotMapped && !m_image.isNull()
+ && mode != QtVideo::MapMode::NotMapped) {
+ m_mapMode = mode;
+
+ mapData.planeCount = 1;
+ mapData.bytesPerLine[0] = m_image.bytesPerLine();
+ if (mode == QtVideo::MapMode::ReadOnly)
+ mapData.data[0] = const_cast<uint8_t *>(m_image.constBits());
+ else
+ mapData.data[0] = m_image.bits();
+ mapData.dataSize[0] = m_image.sizeInBytes();
}
+
+ return mapData;
}
void QImageVideoBuffer::unmap()
{
- Q_D(QImageVideoBuffer);
+ m_mapMode = QtVideo::MapMode::NotMapped;
+}
- d->mapMode = NotMapped;
+QImage QImageVideoBuffer::underlyingImage() const
+{
+ return m_image;
}
QT_END_NAMESPACE
diff --git a/src/multimedia/video/qimagevideobuffer_p.h b/src/multimedia/video/qimagevideobuffer_p.h
index f2b88dd9b..be2bcd800 100644
--- a/src/multimedia/video/qimagevideobuffer_p.h
+++ b/src/multimedia/video/qimagevideobuffer_p.h
@@ -1,45 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QIMAGEVIDEOBUFFER_P_H
#define QIMAGEVIDEOBUFFER_P_H
+#include <qabstractvideobuffer.h>
+#include <qimage.h>
+
//
// W A R N I N G
// -------------
@@ -51,29 +18,26 @@
// We mean it.
//
-#include <qabstractvideobuffer.h>
-
QT_BEGIN_NAMESPACE
-
-class QImage;
-
-class QImageVideoBufferPrivate;
-
class Q_MULTIMEDIA_EXPORT QImageVideoBuffer : public QAbstractVideoBuffer
{
- Q_DECLARE_PRIVATE(QImageVideoBuffer)
public:
- QImageVideoBuffer(const QImage &image);
- ~QImageVideoBuffer();
+ QImageVideoBuffer(QImage image);
- MapMode mapMode() const override;
+ MapData map(QtVideo::MapMode mode) override;
- uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) override;
void unmap() override;
+
+ QVideoFrameFormat format() const override { return {}; }
+
+ QImage underlyingImage() const;
+
+private:
+ QtVideo::MapMode m_mapMode = QtVideo::MapMode::NotMapped;
+ QImage m_image;
};
QT_END_NAMESPACE
-
-#endif
+#endif // QIMAGEVIDEOBUFFER_P_H
diff --git a/src/multimedia/video/qmemoryvideobuffer.cpp b/src/multimedia/video/qmemoryvideobuffer.cpp
index febcd66c8..dc3aada56 100644
--- a/src/multimedia/video/qmemoryvideobuffer.cpp
+++ b/src/multimedia/video/qmemoryvideobuffer.cpp
@@ -1,63 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qmemoryvideobuffer_p.h"
-#include "qabstractvideobuffer_p.h"
-#include <qbytearray.h>
-
QT_BEGIN_NAMESPACE
-class QMemoryVideoBufferPrivate : public QAbstractVideoBufferPrivate
-{
-public:
- QMemoryVideoBufferPrivate()
- : bytesPerLine(0)
- , mapMode(QAbstractVideoBuffer::NotMapped)
- {
- }
-
- int bytesPerLine;
- QAbstractVideoBuffer::MapMode mapMode;
- QByteArray data;
-};
-
/*!
\class QMemoryVideoBuffer
\brief The QMemoryVideoBuffer class provides a system memory allocated video data buffer.
@@ -70,50 +17,37 @@ public:
/*!
Constructs a video buffer with an image stride of \a bytesPerLine from a byte \a array.
*/
-QMemoryVideoBuffer::QMemoryVideoBuffer(const QByteArray &array, int bytesPerLine)
- : QAbstractVideoBuffer(*new QMemoryVideoBufferPrivate, NoHandle)
+QMemoryVideoBuffer::QMemoryVideoBuffer(QByteArray data, int bytesPerLine)
+ : m_bytesPerLine(bytesPerLine), m_data(std::move(data))
{
- Q_D(QMemoryVideoBuffer);
-
- d->data = array;
- d->bytesPerLine = bytesPerLine;
}
/*!
Destroys a system memory allocated video buffer.
*/
-QMemoryVideoBuffer::~QMemoryVideoBuffer()
-{
-}
+QMemoryVideoBuffer::~QMemoryVideoBuffer() = default;
/*!
\reimp
*/
-QAbstractVideoBuffer::MapMode QMemoryVideoBuffer::mapMode() const
+QAbstractVideoBuffer::MapData QMemoryVideoBuffer::map(QtVideo::MapMode mode)
{
- return d_func()->mapMode;
-}
-
-/*!
- \reimp
-*/
-uchar *QMemoryVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
-{
- Q_D(QMemoryVideoBuffer);
-
- if (d->mapMode == NotMapped && d->data.size() && mode != NotMapped) {
- d->mapMode = mode;
-
- if (numBytes)
- *numBytes = d->data.size();
-
- if (bytesPerLine)
- *bytesPerLine = d->bytesPerLine;
-
- return reinterpret_cast<uchar *>(d->data.data());
- } else {
- return nullptr;
+ MapData mapData;
+ if (m_mapMode == QtVideo::MapMode::NotMapped && m_data.size() && mode != QtVideo::MapMode::NotMapped) {
+ m_mapMode = mode;
+
+ mapData.planeCount = 1;
+ mapData.bytesPerLine[0] = m_bytesPerLine;
+ // avoid detaching and extra copying in case the underlyingByteArray is
+ // being held by textures or anything else.
+ if (mode == QtVideo::MapMode::ReadOnly)
+ mapData.data[0] = reinterpret_cast<uchar *>(const_cast<char*>(m_data.constData()));
+ else
+ mapData.data[0] = reinterpret_cast<uchar *>(m_data.data());
+ mapData.dataSize[0] = m_data.size();
}
+
+ return mapData;
}
/*!
@@ -121,7 +55,7 @@ uchar *QMemoryVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
*/
void QMemoryVideoBuffer::unmap()
{
- d_func()->mapMode = NotMapped;
+ m_mapMode = QtVideo::MapMode::NotMapped;
}
QT_END_NAMESPACE
diff --git a/src/multimedia/video/qmemoryvideobuffer_p.h b/src/multimedia/video/qmemoryvideobuffer_p.h
index e1b1f83a9..b861ad479 100644
--- a/src/multimedia/video/qmemoryvideobuffer_p.h
+++ b/src/multimedia/video/qmemoryvideobuffer_p.h
@@ -1,46 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMEMORYVIDEOBUFFER_P_H
#define QMEMORYVIDEOBUFFER_P_H
-#include <qabstractvideobuffer.h>
+#include "qabstractvideobuffer.h"
//
// W A R N I N G
@@ -55,20 +19,21 @@
QT_BEGIN_NAMESPACE
-
-class QMemoryVideoBufferPrivate;
-
class Q_MULTIMEDIA_EXPORT QMemoryVideoBuffer : public QAbstractVideoBuffer
{
- Q_DECLARE_PRIVATE(QMemoryVideoBuffer)
public:
- QMemoryVideoBuffer(const QByteArray &data, int bytesPerLine);
- ~QMemoryVideoBuffer();
-
- MapMode mapMode() const override;
+ QMemoryVideoBuffer(QByteArray data, int bytesPerLine);
+ ~QMemoryVideoBuffer() override;
- uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) override;
+ MapData map(QtVideo::MapMode mode) override;
void unmap() override;
+
+ QVideoFrameFormat format() const override { return {}; }
+
+private:
+ int m_bytesPerLine = 0;
+ QtVideo::MapMode m_mapMode = QtVideo::MapMode::NotMapped;
+ QByteArray m_data;
};
QT_END_NAMESPACE
diff --git a/src/multimedia/video/qtvideo.cpp b/src/multimedia/video/qtvideo.cpp
new file mode 100644
index 000000000..46f1e3101
--- /dev/null
+++ b/src/multimedia/video/qtvideo.cpp
@@ -0,0 +1,71 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qtvideo.h"
+
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \namespace QtVideo
+ \since 6.7
+ \inmodule QtMultimedia
+ \brief Enumerations for camera and video functionality.
+*/
+
+/*!
+ \enum QtVideo::Rotation
+ \since 6.7
+
+ The angle of the clockwise rotation that should be applied to a video
+ frame before displaying.
+
+ \value None No rotation required, the frame has correct orientation
+ \value Clockwise90 The frame should be rotated clockwise by 90 degrees
+ \value Clockwise180 The frame should be rotated clockwise by 180 degrees
+ \value Clockwise270 The frame should be rotated clockwise by 270 degrees
+*/
+
+/*!
+ \enum QtVideo::MapMode
+
+ Enumerates how a video buffer's data is mapped to system memory.
+
+ \value NotMapped
+ The video buffer is not mapped to memory.
+ \value ReadOnly
+ The mapped memory is populated with data from the video buffer when mapped,
+ but the content of the mapped memory may be discarded when unmapped.
+ \value WriteOnly
+ The mapped memory is uninitialized when mapped, but the possibly modified
+ content will be used to populate the video buffer when unmapped.
+ \value ReadWrite
+ The mapped memory is populated with data from the video
+ buffer, and the video buffer is repopulated with the content of the mapped
+ memory when it is unmapped.
+
+ \sa mapMode(), map()
+*/
+
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug dbg, QtVideo::MapMode mode)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ switch (mode) {
+ case QtVideo::MapMode::ReadOnly:
+ return dbg << "ReadOnly";
+ case QtVideo::MapMode::ReadWrite:
+ return dbg << "ReadWrite";
+ case QtVideo::MapMode::WriteOnly:
+ return dbg << "WriteOnly";
+ default:
+ return dbg << "NotMapped";
+ }
+}
+#endif
+
+QT_END_NAMESPACE
+
+#include "moc_qtvideo.cpp"
diff --git a/src/multimedia/video/qtvideo.h b/src/multimedia/video/qtvideo.h
new file mode 100644
index 000000000..fdcb26419
--- /dev/null
+++ b/src/multimedia/video/qtvideo.h
@@ -0,0 +1,57 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QTVIDEO_H
+#define QTVIDEO_H
+
+#include <QtMultimedia/qtmultimediaexports.h>
+#include <QtCore/qobjectdefs.h>
+#include <QtCore/qtconfigmacros.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QtVideo
+{
+Q_NAMESPACE_EXPORT(Q_MULTIMEDIA_EXPORT)
+
+enum class Rotation { None = 0, Clockwise90 = 90, Clockwise180 = 180, Clockwise270 = 270 };
+Q_ENUM_NS(Rotation)
+
+enum class MapMode
+{
+ NotMapped = 0x00,
+ ReadOnly = 0x01,
+ WriteOnly = 0x02,
+ ReadWrite = ReadOnly | WriteOnly
+};
+Q_ENUM_NS(MapMode)
+
+inline constexpr MapMode operator & (MapMode lhs, MapMode rhs)
+{
+ return MapMode(qToUnderlying(lhs) & qToUnderlying(rhs));
+}
+
+inline constexpr MapMode operator | (MapMode lhs, MapMode rhs)
+{
+ return MapMode(qToUnderlying(lhs) | qToUnderlying(rhs));
+}
+
+inline constexpr MapMode &operator &= (MapMode &lhs, MapMode rhs)
+{
+ return (lhs = lhs & rhs);
+}
+
+inline constexpr MapMode &operator |= (MapMode &lhs, MapMode rhs)
+{
+ return (lhs = lhs | rhs);
+}
+
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QtVideo::MapMode);
+#endif
+
+QT_END_NAMESPACE
+
+#endif // QTVIDEO_H
diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp
index 2df52f360..9da4ea3b8 100644
--- a/src/multimedia/video/qvideoframe.cpp
+++ b/src/multimedia/video/qvideoframe.cpp
@@ -1,123 +1,28 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qvideoframe.h"
-#include "qimagevideobuffer_p.h"
+#include "qvideoframe_p.h"
+#include "qvideotexturehelper_p.h"
+#include "qmultimediautils_p.h"
#include "qmemoryvideobuffer_p.h"
-#include "qvideoframeconversionhelper_p.h"
+#include "qvideoframeconverter_p.h"
+#include "qimagevideobuffer_p.h"
+#include "qpainter.h"
+#include <qtextlayout.h>
#include <qimage.h>
-#include <qmutex.h>
#include <qpair.h>
#include <qsize.h>
#include <qvariant.h>
+#include <rhi/qrhi.h>
#include <QDebug>
QT_BEGIN_NAMESPACE
-static void qRegisterVideoFrameMetaTypes()
-{
- qRegisterMetaType<QVideoFrame>();
- qRegisterMetaType<QVideoFrame::FieldType>();
- qRegisterMetaType<QVideoFrame::PixelFormat>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterVideoFrameMetaTypes)
-
-
-class QVideoFramePrivate : public QSharedData
-{
-public:
- QVideoFramePrivate()
- : startTime(-1)
- , endTime(-1)
- , mappedBytes(0)
- , planeCount(0)
- , pixelFormat(QVideoFrame::Format_Invalid)
- , fieldType(QVideoFrame::ProgressiveFrame)
- , buffer(nullptr)
- , mappedCount(0)
- {
- memset(data, 0, sizeof(data));
- memset(bytesPerLine, 0, sizeof(bytesPerLine));
- }
-
- QVideoFramePrivate(const QSize &size, QVideoFrame::PixelFormat format)
- : size(size)
- , startTime(-1)
- , endTime(-1)
- , mappedBytes(0)
- , planeCount(0)
- , pixelFormat(format)
- , fieldType(QVideoFrame::ProgressiveFrame)
- , buffer(nullptr)
- , mappedCount(0)
- {
- memset(data, 0, sizeof(data));
- memset(bytesPerLine, 0, sizeof(bytesPerLine));
- }
-
- ~QVideoFramePrivate()
- {
- if (buffer)
- buffer->release();
- }
-
- QSize size;
- qint64 startTime;
- qint64 endTime;
- uchar *data[4];
- int bytesPerLine[4];
- int mappedBytes;
- int planeCount;
- QVideoFrame::PixelFormat pixelFormat;
- QVideoFrame::FieldType fieldType;
- QAbstractVideoBuffer *buffer;
- int mappedCount;
- QMutex mapMutex;
- QVariantMap metadata;
-
-private:
- Q_DISABLE_COPY(QVideoFramePrivate)
-};
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QVideoFramePrivate);
/*!
\class QVideoFrame
@@ -134,253 +39,212 @@ private:
frames can vary greatly, and some pixel formats offer greater compression opportunities at
the expense of ease of use.
- The pixel contents of a video frame can be mapped to memory using the map() function. While
- mapped, the video data can accessed using the bits() function, which returns a pointer to a
- buffer. The total size of this buffer is given by the mappedBytes() function, and the size of
- each line is given by bytesPerLine(). The return value of the handle() function may also be
- used to access frame data using the internal buffer's native APIs (for example - an OpenGL
- texture handle).
+ The pixel contents of a video frame can be mapped to memory using the map() function. After
+ a successful call to map(), the video data can be accessed through various functions. Some of
+ the YUV pixel formats provide the data in several planes. The planeCount() method will return
+ the amount of planes that being used.
+
+ While mapped, the video data of each plane can accessed using the bits() function, which
+ returns a pointer to a buffer. The size of this buffer is given by the mappedBytes() function,
+ and the size of each line is given by bytesPerLine(). The return value of the handle()
+ function may also be used to access frame data using the internal buffer's native APIs
+ (for example - an OpenGL texture handle).
A video frame can also have timestamp information associated with it. These timestamps can be
- used by an implementation of \l QAbstractVideoSurface to determine when to start and stop
- displaying the frame, but not all surfaces might respect this setting.
+ used to determine when to start and stop displaying the frame.
- The video pixel data in a QVideoFrame is encapsulated in a QAbstractVideoBuffer. A QVideoFrame
- may be constructed from any buffer type by subclassing the QAbstractVideoBuffer class.
+ QVideoFrame objects can consume a significant amount of memory or system resources and
+ should not be held for longer than required by the application.
\note Since video frames can be expensive to copy, QVideoFrame is explicitly shared, so any
change made to a video frame will also apply to any copies.
+
+ \sa QAbstractVideoBuffer, QVideoFrameFormat, QtVideo::MapMode
*/
/*!
- \enum QVideoFrame::PixelFormat
-
- Enumerates video data types.
-
- \value Format_Invalid
- The frame is invalid.
-
- \value Format_ARGB32
- The frame is stored using a 32-bit ARGB format (0xAARRGGBB). This is equivalent to
- QImage::Format_ARGB32.
-
- \value Format_ARGB32_Premultiplied
- The frame stored using a premultiplied 32-bit ARGB format (0xAARRGGBB). This is equivalent
- to QImage::Format_ARGB32_Premultiplied.
+ \enum QVideoFrame::HandleType
- \value Format_RGB32
- The frame stored using a 32-bit RGB format (0xffRRGGBB). This is equivalent to
- QImage::Format_RGB32
+ Identifies the type of a video buffers handle.
- \value Format_RGB24
- The frame is stored using a 24-bit RGB format (8-8-8). This is equivalent to
- QImage::Format_RGB888
+ \value NoHandle
+ The buffer has no handle, its data can only be accessed by mapping the buffer.
+ \value RhiTextureHandle
+ The handle of the buffer is defined by The Qt Rendering Hardware Interface
+ (RHI). RHI is Qt's internal graphics abstraction for 3D APIs, such as
+ OpenGL, Vulkan, Metal, and Direct 3D.
- \value Format_RGB565
- The frame is stored using a 16-bit RGB format (5-6-5). This is equivalent to
- QImage::Format_RGB16.
-
- \value Format_RGB555
- The frame is stored using a 16-bit RGB format (5-5-5). This is equivalent to
- QImage::Format_RGB555.
-
- \value Format_ARGB8565_Premultiplied
- The frame is stored using a 24-bit premultiplied ARGB format (8-5-6-5).
-
- \value Format_BGRA32
- The frame is stored using a 32-bit BGRA format (0xBBGGRRAA).
-
- \value Format_BGRA32_Premultiplied
- The frame is stored using a premultiplied 32bit BGRA format.
-
- \value Format_ABGR32
- The frame is stored using a 32-bit ABGR format (0xAABBGGRR).
-
- \value Format_BGR32
- The frame is stored using a 32-bit BGR format (0xBBGGRRff).
+ \sa handleType()
+*/
- \value Format_BGR24
- The frame is stored using a 24-bit BGR format (0xBBGGRR).
- \value Format_BGR565
- The frame is stored using a 16-bit BGR format (5-6-5).
+/*!
+ Constructs a null video frame.
+*/
+QVideoFrame::QVideoFrame()
+{
+}
- \value Format_BGR555
- The frame is stored using a 16-bit BGR format (5-5-5).
+#if QT_DEPRECATED_SINCE(6, 8)
- \value Format_BGRA5658_Premultiplied
- The frame is stored using a 24-bit premultiplied BGRA format (5-6-5-8).
+/*!
+ \internal
+ Constructs a video frame from a \a buffer with the given pixel \a format and \a size in pixels.
- \value Format_AYUV444
- The frame is stored using a packed 32-bit AYUV format (0xAAYYUUVV).
+ \note This doesn't increment the reference count of the video buffer.
+*/
+QVideoFrame::QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoFrameFormat &format)
+ : d(new QVideoFramePrivate(format, std::unique_ptr<QAbstractVideoBuffer>(buffer)))
+{
+}
- \value Format_AYUV444_Premultiplied
- The frame is stored using a packed premultiplied 32-bit AYUV format (0xAAYYUUVV).
+/*!
+ \internal
+*/
+QAbstractVideoBuffer *QVideoFrame::videoBuffer() const
+{
+ return d ? d->videoBuffer.get() : nullptr;
+}
- \value Format_YUV444
- The frame is stored using a 24-bit packed YUV format (8-8-8).
+#endif
- \value Format_YUV420P
- The frame is stored using an 8-bit per component planar YUV format with the U and V planes
- horizontally and vertically sub-sampled, i.e. the height and width of the U and V planes are
- half that of the Y plane.
+/*!
+ Constructs a video frame of the given pixel \a format.
- \value Format_YUV422P
- The frame is stored using an 8-bit per component planar YUV format with the U and V planes
- horizontally sub-sampled, i.e. the width of the U and V planes are
- half that of the Y plane, and height of U and V planes is the same as Y.
+*/
+QVideoFrame::QVideoFrame(const QVideoFrameFormat &format)
+ : d(new QVideoFramePrivate(format))
+{
+ auto *textureDescription = QVideoTextureHelper::textureDescription(format.pixelFormat());
+ qsizetype bytes = textureDescription->bytesForSize(format.frameSize());
+ if (bytes > 0) {
+ QByteArray data;
+ data.resize(bytes);
- \value Format_YV12
- The frame is stored using an 8-bit per component planar YVU format with the V and U planes
- horizontally and vertically sub-sampled, i.e. the height and width of the V and U planes are
- half that of the Y plane.
+ // Check the memory was successfully allocated.
+ if (!data.isEmpty())
+ d->videoBuffer = std::make_unique<QMemoryVideoBuffer>(
+ data, textureDescription->strideForWidth(format.frameWidth()));
+ }
+}
- \value Format_UYVY
- The frame is stored using an 8-bit per component packed YUV format with the U and V planes
- horizontally sub-sampled (U-Y-V-Y), i.e. two horizontally adjacent pixels are stored as a 32-bit
- macropixel which has a Y value for each pixel and common U and V values.
+/*!
+ Constructs a QVideoFrame from a QImage.
+ \since 6.8
+
+ If the QImage::Format matches one of the formats in
+ QVideoFrameFormat::PixelFormat, the QVideoFrame will hold an instance of
+ the \a image and use that format without any pixel format conversion.
+ In this case, pixel data will be copied only if you call \l{QVideoFrame::map}
+ with \c WriteOnly flag while keeping the original image.
+
+ Otherwise, if the QImage::Format matches none of video formats,
+ the image is first converted to a supported (A)RGB format using
+ QImage::convertedTo() with the Qt::AutoColor flag.
+ This may incur a performance penalty.
+
+ If QImage::isNull() evaluates to true for the input QImage, the
+ QVideoFrame will be invalid and QVideoFrameFormat::isValid() will
+ return false.
+
+ \sa QVideoFrameFormat::pixelFormatFromImageFormat()
+ \sa QImage::convertedTo()
+ \sa QImage::isNull()
+*/
+QVideoFrame::QVideoFrame(const QImage &image)
+{
+ auto buffer = std::make_unique<QImageVideoBuffer>(image);
- \value Format_YUYV
- The frame is stored using an 8-bit per component packed YUV format with the U and V planes
- horizontally sub-sampled (Y-U-Y-V), i.e. two horizontally adjacent pixels are stored as a 32-bit
- macropixel which has a Y value for each pixel and common U and V values.
+ // If the QImage::Format is not convertible to QVideoFrameFormat,
+ // QImageVideoBuffer automatically converts image to a compatible
+ // (A)RGB format.
+ const QImage &bufferImage = buffer->underlyingImage();
- \value Format_NV12
- The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y)
- followed by a horizontally and vertically sub-sampled, packed UV plane (U-V).
+ if (bufferImage.isNull())
+ return;
- \value Format_NV21
- The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y)
- followed by a horizontally and vertically sub-sampled, packed VU plane (V-U).
+ // `bufferImage` is now supported by QVideoFrameFormat::pixelFormatFromImageFormat()
+ QVideoFrameFormat format = {
+ bufferImage.size(), QVideoFrameFormat::pixelFormatFromImageFormat(bufferImage.format())
+ };
- \value Format_IMC1
- The frame is stored using an 8-bit per component planar YUV format with the U and V planes
- horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except
- that the bytes per line of the U and V planes are padded out to the same stride as the Y plane.
+ Q_ASSERT(format.isValid());
- \value Format_IMC2
- The frame is stored using an 8-bit per component planar YUV format with the U and V planes
- horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except
- that the lines of the U and V planes are interleaved, i.e. each line of U data is followed by a
- line of V data creating a single line of the same stride as the Y data.
+ d = new QVideoFramePrivate{ std::move(format), std::move(buffer) };
+}
- \value Format_IMC3
- The frame is stored using an 8-bit per component planar YVU format with the V and U planes
- horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that
- the bytes per line of the V and U planes are padded out to the same stride as the Y plane.
+/*!
+ Constructs a QVideoFrame from a \l QAbstractVideoBuffer.
- \value Format_IMC4
- The frame is stored using an 8-bit per component planar YVU format with the V and U planes
- horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that
- the lines of the V and U planes are interleaved, i.e. each line of V data is followed by a line
- of U data creating a single line of the same stride as the Y data.
+ \since 6.8
- \value Format_Y8
- The frame is stored using an 8-bit greyscale format.
+ The specified \a videoBuffer refers to an instance a reimplemented
+ \l QAbstractVideoBuffer. The instance is expected to contain a preallocated custom
+ video buffer and must implement \l QAbstractVideoBuffer::format,
+ \l QAbstractVideoBuffer::map, and \l QAbstractVideoBuffer::unmap for GPU content.
- \value Format_Y16
- The frame is stored using a 16-bit linear greyscale format. Little endian.
+ If \a videoBuffer is null or gets an invalid \l QVideoFrameFormat,
+ the constructors creates an invalid video frame.
- \value Format_Jpeg
- The frame is stored in compressed Jpeg format.
+ The created frame will hold ownership of the specified video buffer for its lifetime.
+ Considering that QVideoFrame is implemented via a shared private object,
+ the specified video buffer will be destroyed upon destruction of the last copy
+ of the created video frame.
- \value Format_CameraRaw
- The frame is stored using a device specific camera raw format.
+ Note, if a video frame has been passed to \l QMediaRecorder or a rendering pipeline,
+ the lifetime of the frame is undefined, and the media recorder can destroy it
+ in a different thread.
- \value Format_AdobeDng
- The frame is stored using raw Adobe Digital Negative (DNG) format.
+ QVideoFrame will contain own instance of QVideoFrameFormat.
+ Upon invoking \l setStreamFrameRate, \l setMirrored, or \l setRotation,
+ the inner format can be modified, and \l surfaceFormat will return
+ a detached instance.
- \value Format_User
- Start value for user defined pixel formats.
+ \sa QAbstractVideoBuffer, QVideoFrameFormat
*/
+QVideoFrame::QVideoFrame(std::unique_ptr<QAbstractVideoBuffer> videoBuffer)
+{
+ if (!videoBuffer)
+ return;
-/*!
- \enum QVideoFrame::FieldType
-
- Specifies the field an interlaced video frame belongs to.
-
- \value ProgressiveFrame The frame is not interlaced.
- \value TopField The frame contains a top field.
- \value BottomField The frame contains a bottom field.
- \value InterlacedFrame The frame contains a merged top and bottom field.
-*/
+ QVideoFrameFormat format = videoBuffer->format();
+ if (!format.isValid())
+ return;
-/*!
- Constructs a null video frame.
-*/
-QVideoFrame::QVideoFrame()
- : d(new QVideoFramePrivate)
-{
+ d = new QVideoFramePrivate{ std::move(format), std::move(videoBuffer) };
}
/*!
- Constructs a video frame from a \a buffer with the given pixel \a format and \a size in pixels.
+ Constructs a shallow copy of \a other. Since QVideoFrame is
+ explicitly shared, these two instances will reflect the same frame.
- \note This doesn't increment the reference count of the video buffer.
*/
-QVideoFrame::QVideoFrame(
- QAbstractVideoBuffer *buffer, const QSize &size, PixelFormat format)
- : d(new QVideoFramePrivate(size, format))
-{
- d->buffer = buffer;
-}
+QVideoFrame::QVideoFrame(const QVideoFrame &other) = default;
/*!
- Constructs a video frame of the given pixel \a format and \a size in pixels.
+ \fn QVideoFrame::QVideoFrame(QVideoFrame &&other)
- The \a bytesPerLine (stride) is the length of each scan line in bytes, and \a bytes is the total
- number of bytes that must be allocated for the frame.
+ Constructs a QVideoFrame by moving from \a other.
*/
-QVideoFrame::QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format)
- : d(new QVideoFramePrivate(size, format))
-{
- if (bytes > 0) {
- QByteArray data;
- data.resize(bytes);
-
- // Check the memory was successfully allocated.
- if (!data.isEmpty())
- d->buffer = new QMemoryVideoBuffer(data, bytesPerLine);
- }
-}
/*!
- Constructs a video frame from an \a image.
-
- \note This will construct an invalid video frame if there is no frame type equivalent to the
- image format.
+ \fn void QVideoFrame::swap(QVideoFrame &other) noexcept
- \sa pixelFormatFromImageFormat()
+ Swaps the current video frame with \a other.
*/
-QVideoFrame::QVideoFrame(const QImage &image)
- : d(new QVideoFramePrivate(
- image.size(), pixelFormatFromImageFormat(image.format())))
-{
- if (d->pixelFormat != Format_Invalid)
- d->buffer = new QImageVideoBuffer(image);
-}
/*!
- Constructs a shallow copy of \a other. Since QVideoFrame is
- explicitly shared, these two instances will reflect the same frame.
+ \fn QVideoFrame &QVideoFrame::operator=(QVideoFrame &&other)
+ Moves \a other into this QVideoFrame.
*/
-QVideoFrame::QVideoFrame(const QVideoFrame &other)
- : d(other.d)
-{
-}
/*!
Assigns the contents of \a other to this video frame. Since QVideoFrame is
explicitly shared, these two instances will reflect the same frame.
*/
-QVideoFrame &QVideoFrame::operator =(const QVideoFrame &other)
-{
- d = other.d;
-
- return *this;
-}
+QVideoFrame &QVideoFrame::operator =(const QVideoFrame &other) = default;
/*!
\return \c true if this QVideoFrame and \a other reflect the same frame.
@@ -402,18 +266,7 @@ bool QVideoFrame::operator!=(const QVideoFrame &other) const
/*!
Destroys a video frame.
*/
-QVideoFrame::~QVideoFrame()
-{
-}
-
-/*!
- \return underlying video buffer or \c null if there is none.
- \since 5.13
-*/
-QAbstractVideoBuffer *QVideoFrame::buffer() const
-{
- return d->buffer;
-}
+QVideoFrame::~QVideoFrame() = default;
/*!
Identifies whether a video frame is valid.
@@ -424,24 +277,34 @@ QAbstractVideoBuffer *QVideoFrame::buffer() const
*/
bool QVideoFrame::isValid() const
{
- return d->buffer != nullptr;
+ return d && d->videoBuffer && d->format.pixelFormat() != QVideoFrameFormat::Format_Invalid;
+}
+
+/*!
+ Returns the pixel format of this video frame.
+*/
+QVideoFrameFormat::PixelFormat QVideoFrame::pixelFormat() const
+{
+ return d ? d->format.pixelFormat() : QVideoFrameFormat::Format_Invalid;
}
/*!
- Returns the color format of a video frame.
+ Returns the surface format of this video frame.
*/
-QVideoFrame::PixelFormat QVideoFrame::pixelFormat() const
+QVideoFrameFormat QVideoFrame::surfaceFormat() const
{
- return d->pixelFormat;
+ return d ? d->format : QVideoFrameFormat{};
}
/*!
Returns the type of a video frame's handle.
+ The handle type could either be NoHandle, meaning that the frame is memory
+ based, or a RHI texture.
*/
-QAbstractVideoBuffer::HandleType QVideoFrame::handleType() const
+QVideoFrame::HandleType QVideoFrame::handleType() const
{
- return d->buffer ? d->buffer->handleType() : QAbstractVideoBuffer::NoHandle;
+ return (d && d->hwVideoBuffer) ? d->hwVideoBuffer->handleType() : QVideoFrame::NoHandle;
}
/*!
@@ -449,7 +312,7 @@ QAbstractVideoBuffer::HandleType QVideoFrame::handleType() const
*/
QSize QVideoFrame::size() const
{
- return d->size;
+ return d ? d->format.frameSize() : QSize();
}
/*!
@@ -457,7 +320,7 @@ QSize QVideoFrame::size() const
*/
int QVideoFrame::width() const
{
- return d->size.width();
+ return size().width();
}
/*!
@@ -465,49 +328,31 @@ int QVideoFrame::width() const
*/
int QVideoFrame::height() const
{
- return d->size.height();
-}
-
-/*!
- Returns the field an interlaced video frame belongs to.
-
- If the video is not interlaced this will return WholeFrame.
-*/
-QVideoFrame::FieldType QVideoFrame::fieldType() const
-{
- return d->fieldType;
-}
-
-/*!
- Sets the \a field an interlaced video frame belongs to.
-*/
-void QVideoFrame::setFieldType(QVideoFrame::FieldType field)
-{
- d->fieldType = field;
+ return size().height();
}
/*!
Identifies if a video frame's contents are currently mapped to system memory.
- This is a convenience function which checks that the \l {QAbstractVideoBuffer::MapMode}{MapMode}
- of the frame is not equal to QAbstractVideoBuffer::NotMapped.
+ This is a convenience function which checks that the \l {QtVideo::MapMode}{MapMode}
+ of the frame is not equal to QtVideo::MapMode::NotMapped.
Returns true if the contents of the video frame are mapped to system memory, and false
otherwise.
- \sa mapMode(), QAbstractVideoBuffer::MapMode
+ \sa mapMode(), QtVideo::MapMode
*/
bool QVideoFrame::isMapped() const
{
- return d->buffer != nullptr && d->buffer->mapMode() != QAbstractVideoBuffer::NotMapped;
+ return d && d->mapMode != QtVideo::MapMode::NotMapped;
}
/*!
Identifies if the mapped contents of a video frame will be persisted when the frame is unmapped.
- This is a convenience function which checks if the \l {QAbstractVideoBuffer::MapMode}{MapMode}
- contains the QAbstractVideoBuffer::WriteOnly flag.
+ This is a convenience function which checks if the \l {QtVideo::MapMode}{MapMode}
+ contains the QtVideo::MapMode::WriteOnly flag.
Returns true if the video frame will be updated when unmapped, and false otherwise.
@@ -515,37 +360,37 @@ bool QVideoFrame::isMapped() const
Depending on the buffer implementation the changes may be persisted, or worse alter a shared
buffer.
- \sa mapMode(), QAbstractVideoBuffer::MapMode
+ \sa mapMode(), QtVideo::MapMode
*/
bool QVideoFrame::isWritable() const
{
- return d->buffer != nullptr && (d->buffer->mapMode() & QAbstractVideoBuffer::WriteOnly);
+ return d && (d->mapMode & QtVideo::MapMode::WriteOnly) != QtVideo::MapMode::NotMapped;
}
/*!
Identifies if the mapped contents of a video frame were read from the frame when it was mapped.
- This is a convenience function which checks if the \l {QAbstractVideoBuffer::MapMode}{MapMode}
- contains the QAbstractVideoBuffer::WriteOnly flag.
+ This is a convenience function which checks if the \l {QtVideo::MapMode}{MapMode}
+ contains the QtVideo::MapMode::WriteOnly flag.
Returns true if the contents of the mapped memory were read from the video frame, and false
otherwise.
- \sa mapMode(), QAbstractVideoBuffer::MapMode
+ \sa mapMode(), QtVideo::MapMode
*/
bool QVideoFrame::isReadable() const
{
- return d->buffer != nullptr && (d->buffer->mapMode() & QAbstractVideoBuffer::ReadOnly);
+ return d && (d->mapMode & QtVideo::MapMode::ReadOnly) != QtVideo::MapMode::NotMapped;
}
/*!
Returns the mode a video frame was mapped to system memory in.
- \sa map(), QAbstractVideoBuffer::MapMode
+ \sa map(), QtVideo::MapMode
*/
-QAbstractVideoBuffer::MapMode QVideoFrame::mapMode() const
+QVideoFrame::MapMode QVideoFrame::mapMode() const
{
- return d->buffer != nullptr ? d->buffer->mapMode() : QAbstractVideoBuffer::NotMapped;
+ return static_cast<QVideoFrame::MapMode>(d ? d->mapMode : QtVideo::MapMode::NotMapped);
}
/*!
@@ -556,9 +401,9 @@ QAbstractVideoBuffer::MapMode QVideoFrame::mapMode() const
copying the contents around, so avoid mapping and unmapping unless required.
The map \a mode indicates whether the contents of the mapped memory should be read from and/or
- written to the frame. If the map mode includes the \c QAbstractVideoBuffer::ReadOnly flag the
+ written to the frame. If the map mode includes the \c QtVideo::MapMode::ReadOnly flag the
mapped memory will be populated with the content of the video frame when initially mapped. If the map
- mode includes the \c QAbstractVideoBuffer::WriteOnly flag the content of the possibly modified
+ mode includes the \c QtVideo::MapMode::WriteOnly flag the content of the possibly modified
mapped memory will be written back to the frame when unmapped.
While mapped the contents of a video frame can be accessed directly through the pointer returned
@@ -578,120 +423,197 @@ QAbstractVideoBuffer::MapMode QVideoFrame::mapMode() const
\sa unmap(), mapMode(), bits()
*/
-bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode)
+bool QVideoFrame::map(QtVideo::MapMode mode)
{
- QMutexLocker lock(&d->mapMutex);
-
- if (!d->buffer)
+ if (!d || !d->videoBuffer)
return false;
- if (mode == QAbstractVideoBuffer::NotMapped)
+ QMutexLocker lock(&d->mapMutex);
+ if (mode == QtVideo::MapMode::NotMapped)
return false;
if (d->mappedCount > 0) {
//it's allowed to map the video frame multiple times in read only mode
- if (d->buffer->mapMode() == QAbstractVideoBuffer::ReadOnly
- && mode == QAbstractVideoBuffer::ReadOnly) {
+ if (d->mapMode == QtVideo::MapMode::ReadOnly && mode == QtVideo::MapMode::ReadOnly) {
d->mappedCount++;
return true;
- } else {
- return false;
}
+
+ return false;
}
- Q_ASSERT(d->data[0] == nullptr);
- Q_ASSERT(d->bytesPerLine[0] == 0);
- Q_ASSERT(d->planeCount == 0);
- Q_ASSERT(d->mappedBytes == 0);
+ Q_ASSERT(d->mapData.data[0] == nullptr);
+ Q_ASSERT(d->mapData.bytesPerLine[0] == 0);
+ Q_ASSERT(d->mapData.planeCount == 0);
+ Q_ASSERT(d->mapData.dataSize[0] == 0);
- d->planeCount = d->buffer->mapPlanes(mode, &d->mappedBytes, d->bytesPerLine, d->data);
- if (d->planeCount == 0)
+ d->mapData = d->videoBuffer->map(mode);
+ if (d->mapData.planeCount == 0)
return false;
- if (d->planeCount > 1) {
- // If the plane count is derive the additional planes for planar formats.
- } else switch (d->pixelFormat) {
- case Format_Invalid:
- case Format_ARGB32:
- case Format_ARGB32_Premultiplied:
- case Format_RGB32:
- case Format_RGB24:
- case Format_RGB565:
- case Format_RGB555:
- case Format_ARGB8565_Premultiplied:
- case Format_BGRA32:
- case Format_BGRA32_Premultiplied:
- case Format_ABGR32:
- case Format_BGR32:
- case Format_BGR24:
- case Format_BGR565:
- case Format_BGR555:
- case Format_BGRA5658_Premultiplied:
- case Format_AYUV444:
- case Format_AYUV444_Premultiplied:
- case Format_YUV444:
- case Format_UYVY:
- case Format_YUYV:
- case Format_Y8:
- case Format_Y16:
- case Format_Jpeg:
- case Format_CameraRaw:
- case Format_AdobeDng:
- case Format_User:
- // Single plane or opaque format.
- break;
- case Format_YUV420P:
- case Format_YUV422P:
- case Format_YV12: {
- // The UV stride is usually half the Y stride and is 32-bit aligned.
- // However it's not always the case, at least on Windows where the
- // UV planes are sometimes not aligned.
- // We calculate the stride using the UV byte count to always
- // have a correct stride.
- const int height = d->size.height();
- const int yStride = d->bytesPerLine[0];
- const int uvHeight = d->pixelFormat == Format_YUV422P ? height : height / 2;
- const int uvStride = (d->mappedBytes - (yStride * height)) / uvHeight / 2;
-
- // Three planes, the second and third vertically (and horizontally for other than Format_YUV422P formats) subsampled.
- d->planeCount = 3;
- d->bytesPerLine[2] = d->bytesPerLine[1] = uvStride;
- d->data[1] = d->data[0] + (yStride * height);
- d->data[2] = d->data[1] + (uvStride * uvHeight);
- break;
- }
- case Format_NV12:
- case Format_NV21:
- case Format_IMC2:
- case Format_IMC4: {
- // Semi planar, Full resolution Y plane with interleaved subsampled U and V planes.
- d->planeCount = 2;
- d->bytesPerLine[1] = d->bytesPerLine[0];
- d->data[1] = d->data[0] + (d->bytesPerLine[0] * d->size.height());
- break;
- }
- case Format_IMC1:
- case Format_IMC3: {
- // Three planes, the second and third vertically and horizontally subsumpled,
- // but with lines padded to the width of the first plane.
- d->planeCount = 3;
- d->bytesPerLine[2] = d->bytesPerLine[1] = d->bytesPerLine[0];
- d->data[1] = d->data[0] + (d->bytesPerLine[0] * d->size.height());
- d->data[2] = d->data[1] + (d->bytesPerLine[1] * d->size.height() / 2);
- break;
- }
- default:
- break;
+ d->mapMode = mode;
+
+ if (d->mapData.planeCount == 1) {
+ auto pixelFmt = d->format.pixelFormat();
+ // If the plane count is 1 derive the additional planes for planar formats.
+ switch (pixelFmt) {
+ case QVideoFrameFormat::Format_Invalid:
+ case QVideoFrameFormat::Format_ARGB8888:
+ case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
+ case QVideoFrameFormat::Format_XRGB8888:
+ case QVideoFrameFormat::Format_BGRA8888:
+ case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
+ case QVideoFrameFormat::Format_BGRX8888:
+ case QVideoFrameFormat::Format_ABGR8888:
+ case QVideoFrameFormat::Format_XBGR8888:
+ case QVideoFrameFormat::Format_RGBA8888:
+ case QVideoFrameFormat::Format_RGBX8888:
+ case QVideoFrameFormat::Format_AYUV:
+ case QVideoFrameFormat::Format_AYUV_Premultiplied:
+ case QVideoFrameFormat::Format_UYVY:
+ case QVideoFrameFormat::Format_YUYV:
+ case QVideoFrameFormat::Format_Y8:
+ case QVideoFrameFormat::Format_Y16:
+ case QVideoFrameFormat::Format_Jpeg:
+ case QVideoFrameFormat::Format_SamplerExternalOES:
+ case QVideoFrameFormat::Format_SamplerRect:
+ // Single plane or opaque format.
+ break;
+ case QVideoFrameFormat::Format_YUV420P:
+ case QVideoFrameFormat::Format_YUV420P10:
+ case QVideoFrameFormat::Format_YUV422P:
+ case QVideoFrameFormat::Format_YV12: {
+ // The UV stride is usually half the Y stride and is 32-bit aligned.
+ // However it's not always the case, at least on Windows where the
+ // UV planes are sometimes not aligned.
+ // We calculate the stride using the UV byte count to always
+ // have a correct stride.
+ const int height = this->height();
+ const int yStride = d->mapData.bytesPerLine[0];
+ const int uvHeight = pixelFmt == QVideoFrameFormat::Format_YUV422P ? height : height / 2;
+ const int uvStride = (d->mapData.dataSize[0] - (yStride * height)) / uvHeight / 2;
+
+ // Three planes, the second and third vertically (and horizontally for other than Format_YUV422P formats) subsampled.
+ d->mapData.planeCount = 3;
+ d->mapData.bytesPerLine[2] = d->mapData.bytesPerLine[1] = uvStride;
+ d->mapData.dataSize[0] = yStride * height;
+ d->mapData.dataSize[1] = uvStride * uvHeight;
+ d->mapData.dataSize[2] = uvStride * uvHeight;
+ d->mapData.data[1] = d->mapData.data[0] + d->mapData.dataSize[0];
+ d->mapData.data[2] = d->mapData.data[1] + d->mapData.dataSize[1];
+ break;
+ }
+ case QVideoFrameFormat::Format_NV12:
+ case QVideoFrameFormat::Format_NV21:
+ case QVideoFrameFormat::Format_IMC2:
+ case QVideoFrameFormat::Format_IMC4:
+ case QVideoFrameFormat::Format_P010:
+ case QVideoFrameFormat::Format_P016: {
+ // Semi planar, Full resolution Y plane with interleaved subsampled U and V planes.
+ d->mapData.planeCount = 2;
+ d->mapData.bytesPerLine[1] = d->mapData.bytesPerLine[0];
+ int size = d->mapData.dataSize[0];
+ d->mapData.dataSize[0] = (d->mapData.bytesPerLine[0] * height());
+ d->mapData.dataSize[1] = size - d->mapData.dataSize[0];
+ d->mapData.data[1] = d->mapData.data[0] + d->mapData.dataSize[0];
+ break;
+ }
+ case QVideoFrameFormat::Format_IMC1:
+ case QVideoFrameFormat::Format_IMC3: {
+ // Three planes, the second and third vertically and horizontally subsumpled,
+ // but with lines padded to the width of the first plane.
+ d->mapData.planeCount = 3;
+ d->mapData.bytesPerLine[2] = d->mapData.bytesPerLine[1] = d->mapData.bytesPerLine[0];
+ d->mapData.dataSize[0] = (d->mapData.bytesPerLine[0] * height());
+ d->mapData.dataSize[1] = (d->mapData.bytesPerLine[0] * height() / 2);
+ d->mapData.dataSize[2] = (d->mapData.bytesPerLine[0] * height() / 2);
+ d->mapData.data[1] = d->mapData.data[0] + d->mapData.dataSize[0];
+ d->mapData.data[2] = d->mapData.data[1] + d->mapData.dataSize[1];
+ break;
+ }
+ }
}
d->mappedCount++;
+
+ // unlock mapMutex to avoid potential deadlock imageMutex <--> mapMutex
+ lock.unlock();
+
+ if ((mode & QtVideo::MapMode::WriteOnly) != QtVideo::MapMode::NotMapped) {
+ QMutexLocker lock(&d->imageMutex);
+ d->image = {};
+ }
+
return true;
}
+#if QT_DEPRECATED_SINCE(6, 8)
+
+/*!
+ \deprecated [6.8] Use \c QtVideo::MapMode instead. The values of this enum
+ are consistent with values of \c QtVideo::MapMode.
+ \enum QVideoFrame::MapMode
+
+ Enumerates how a video buffer's data is mapped to system memory.
+
+ \value NotMapped
+ The video buffer is not mapped to memory.
+ \value ReadOnly
+ The mapped memory is populated with data from the video buffer when mapped,
+ but the content of the mapped memory may be discarded when unmapped.
+ \value WriteOnly
+ The mapped memory is uninitialized when mapped, but the possibly modified
+ content will be used to populate the video buffer when unmapped.
+ \value ReadWrite
+ The mapped memory is populated with data from the video
+ buffer, and the video buffer is repopulated with the content of the mapped
+ memory when it is unmapped.
+
+ \sa mapMode(), map()
+*/
+
+/*!
+ \deprecated [6.8] Use \c QVideoFrame::map(Qt::Video::MapMode) instead.
+ Maps the contents of a video frame to system (CPU addressable) memory.
+
+ In some cases the video frame data might be stored in video memory or otherwise inaccessible
+ memory, so it is necessary to map a frame before accessing the pixel data. This may involve
+ copying the contents around, so avoid mapping and unmapping unless required.
+
+ The map \a mode indicates whether the contents of the mapped memory should be read from and/or
+ written to the frame. If the map mode includes the \c QVideoFrame::ReadOnly flag the
+ mapped memory will be populated with the content of the video frame when initially mapped. If the map
+ mode includes the \c QVideoFrame::WriteOnly flag the content of the possibly modified
+ mapped memory will be written back to the frame when unmapped.
+
+ While mapped the contents of a video frame can be accessed directly through the pointer returned
+ by the bits() function.
+
+ When access to the data is no longer needed, be sure to call the unmap() function to release the
+ mapped memory and possibly update the video frame contents.
+
+ If the video frame has been mapped in read only mode, it is permissible to map it
+ multiple times in read only mode (and unmap it a corresponding number of times). In all
+ other cases it is necessary to unmap the frame first before mapping a second time.
+
+ \note Writing to memory that is mapped as read-only is undefined, and may result in changes
+ to shared data or crashes.
+
+ Returns true if the frame was mapped to memory in the given \a mode and false otherwise.
+
+ \sa unmap(), mapMode(), bits()
+*/
+bool QVideoFrame::map(QVideoFrame::MapMode mode)
+{
+ return map(static_cast<QtVideo::MapMode>(mode));
+}
+
+#endif
+
/*!
Releases the memory mapped by the map() function.
- If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly
+ If the \l {QtVideo::MapMode}{MapMode} included the QtVideo::MapMode::WriteOnly
flag this will persist the current content of the mapped memory to the video frame.
unmap() should not be called if map() function failed.
@@ -700,11 +622,11 @@ bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode)
*/
void QVideoFrame::unmap()
{
- QMutexLocker lock(&d->mapMutex);
-
- if (!d->buffer)
+ if (!d || !d->videoBuffer)
return;
+ QMutexLocker lock(&d->mapMutex);
+
if (d->mappedCount == 0) {
qWarning() << "QVideoFrame::unmap() was called more times then QVideoFrame::map()";
return;
@@ -713,31 +635,13 @@ void QVideoFrame::unmap()
d->mappedCount--;
if (d->mappedCount == 0) {
- d->mappedBytes = 0;
- d->planeCount = 0;
- memset(d->bytesPerLine, 0, sizeof(d->bytesPerLine));
- memset(d->data, 0, sizeof(d->data));
-
- d->buffer->unmap();
+ d->mapData = {};
+ d->mapMode = QtVideo::MapMode::NotMapped;
+ d->videoBuffer->unmap();
}
}
/*!
- Returns the number of bytes in a scan line.
-
- \note For planar formats this is the bytes per line of the first plane only. The bytes per line of subsequent
- planes should be calculated as per the frame \l{QVideoFrame::PixelFormat}{pixel format}.
-
- This value is only valid while the frame data is \l {map()}{mapped}.
-
- \sa bits(), map(), mappedBytes()
-*/
-int QVideoFrame::bytesPerLine() const
-{
- return d->bytesPerLine[0];
-}
-
-/*!
Returns the number of bytes in a scan line of a \a plane.
This value is only valid while the frame data is \l {map()}{mapped}.
@@ -748,23 +652,9 @@ int QVideoFrame::bytesPerLine() const
int QVideoFrame::bytesPerLine(int plane) const
{
- return plane >= 0 && plane < d->planeCount ? d->bytesPerLine[plane] : 0;
-}
-
-/*!
- Returns a pointer to the start of the frame data buffer.
-
- This value is only valid while the frame data is \l {map()}{mapped}.
-
- Changes made to data accessed via this pointer (when mapped with write access)
- are only guaranteed to have been persisted when unmap() is called and when the
- buffer has been mapped for writing.
-
- \sa map(), mappedBytes(), bytesPerLine()
-*/
-uchar *QVideoFrame::bits()
-{
- return d->data[0];
+ if (!d)
+ return 0;
+ return plane >= 0 && plane < d->mapData.planeCount ? d->mapData.bytesPerLine[plane] : 0;
}
/*!
@@ -781,22 +671,9 @@ uchar *QVideoFrame::bits()
*/
uchar *QVideoFrame::bits(int plane)
{
- return plane >= 0 && plane < d->planeCount ? d->data[plane] : nullptr;
-}
-
-/*!
- Returns a pointer to the start of the frame data buffer.
-
- This value is only valid while the frame data is \l {map()}{mapped}.
-
- If the buffer was not mapped with read access, the contents of this
- buffer will initially be uninitialized.
-
- \sa map(), mappedBytes(), bytesPerLine()
-*/
-const uchar *QVideoFrame::bits() const
-{
- return d->data[0];
+ if (!d)
+ return nullptr;
+ return plane >= 0 && plane < d->mapData.planeCount ? d->mapData.data[plane] : nullptr;
}
/*!
@@ -812,45 +689,37 @@ const uchar *QVideoFrame::bits() const
*/
const uchar *QVideoFrame::bits(int plane) const
{
- return plane >= 0 && plane < d->planeCount ? d->data[plane] : nullptr;
+ if (!d)
+ return nullptr;
+ return plane >= 0 && plane < d->mapData.planeCount ? d->mapData.data[plane] : nullptr;
}
/*!
- Returns the number of bytes occupied by the mapped frame data.
+ Returns the number of bytes occupied by plane \a plane of the mapped frame data.
This value is only valid while the frame data is \l {map()}{mapped}.
\sa map()
*/
-int QVideoFrame::mappedBytes() const
+int QVideoFrame::mappedBytes(int plane) const
{
- return d->mappedBytes;
+ if (!d)
+ return 0;
+ return plane >= 0 && plane < d->mapData.planeCount ? d->mapData.dataSize[plane] : 0;
}
/*!
Returns the number of planes in the video frame.
- This value is only valid while the frame data is \l {map()}{mapped}.
-
\sa map()
\since 5.4
*/
int QVideoFrame::planeCount() const
{
- return d->planeCount;
-}
-
-/*!
- Returns a type specific handle to a video frame's buffer.
-
- For an OpenGL texture this would be the texture ID.
-
- \sa QAbstractVideoBuffer::handle()
-*/
-QVariant QVideoFrame::handle() const
-{
- return d->buffer != nullptr ? d->buffer->handle() : QVariant();
+ if (!d)
+ return 0;
+ return d->format.planeCount();
}
/*!
@@ -861,6 +730,8 @@ QVariant QVideoFrame::handle() const
*/
qint64 QVideoFrame::startTime() const
{
+ if (!d)
+ return -1;
return d->startTime;
}
@@ -872,6 +743,8 @@ qint64 QVideoFrame::startTime() const
*/
void QVideoFrame::setStartTime(qint64 time)
{
+ if (!d)
+ return;
d->startTime = time;
}
@@ -883,6 +756,8 @@ void QVideoFrame::setStartTime(qint64 time)
*/
qint64 QVideoFrame::endTime() const
{
+ if (!d)
+ return -1;
return d->endTime;
}
@@ -894,366 +769,205 @@ qint64 QVideoFrame::endTime() const
*/
void QVideoFrame::setEndTime(qint64 time)
{
+ if (!d)
+ return;
d->endTime = time;
}
+#if QT_DEPRECATED_SINCE(6, 7)
/*!
- Returns any extra metadata associated with this frame.
- */
-QVariantMap QVideoFrame::availableMetaData() const
-{
- return d->metadata;
-}
+ \enum QVideoFrame::RotationAngle
+ \deprecated [6.7] Use QtVideo::Rotation instead.
+
+ The angle of the clockwise rotation that should be applied to a video
+ frame before displaying.
+
+ \value Rotation0 No rotation required, the frame has correct orientation
+ \value Rotation90 The frame should be rotated by 90 degrees
+ \value Rotation180 The frame should be rotated by 180 degrees
+ \value Rotation270 The frame should be rotated by 270 degrees
+*/
/*!
- Returns any metadata for this frame for the given \a key.
+ \fn void QVideoFrame::setRotationAngle(RotationAngle)
+ \deprecated [6.7] Use \c QVideoFrame::setRotation instead.
- This might include frame specific information from
- a camera, or subtitles from a decoded video stream.
+ Sets the \a angle the frame should be rotated clockwise before displaying.
+*/
- See the documentation for the relevant video frame
- producer for further information about available metadata.
- */
-QVariant QVideoFrame::metaData(const QString &key) const
+/*!
+ \fn QVideoFrame::RotationAngle QVideoFrame::rotationAngle() const
+ \deprecated [6.7] Use \c QVideoFrame::rotation instead.
+
+ Returns the angle the frame should be rotated clockwise before displaying.
+*/
+
+#endif
+
+
+/*!
+ Sets the \a angle the frame should be rotated clockwise before displaying.
+*/
+void QVideoFrame::setRotation(QtVideo::Rotation angle)
{
- return d->metadata.value(key);
+ if (d)
+ d->format.setRotation(angle);
}
/*!
- Sets the metadata for the given \a key to \a value.
-
- If \a value is a null variant, any metadata for this key will be removed.
-
- The producer of the video frame might use this to associate
- certain data with this frame, or for an intermediate processor
- to add information for a consumer of this frame.
+ Returns the angle the frame should be rotated clockwise before displaying.
*/
-void QVideoFrame::setMetaData(const QString &key, const QVariant &value)
+QtVideo::Rotation QVideoFrame::rotation() const
{
- if (!value.isNull())
- d->metadata.insert(key, value);
- else
- d->metadata.remove(key);
+ return d ? d->format.rotation() : QtVideo::Rotation::None;
}
/*!
- Returns a video pixel format equivalent to an image \a format. If there is no equivalent
- format QVideoFrame::InvalidType is returned instead.
-
- \note In general \l QImage does not handle YUV formats.
-
+ Sets the \a mirrored flag for the frame and
+ sets the flag to the underlying \l surfaceFormat.
*/
-QVideoFrame::PixelFormat QVideoFrame::pixelFormatFromImageFormat(QImage::Format format)
+void QVideoFrame::setMirrored(bool mirrored)
{
- switch (format) {
- case QImage::Format_RGB32:
- case QImage::Format_RGBX8888:
- return Format_RGB32;
- case QImage::Format_ARGB32:
- case QImage::Format_RGBA8888:
- return Format_ARGB32;
- case QImage::Format_ARGB32_Premultiplied:
- case QImage::Format_RGBA8888_Premultiplied:
- return Format_ARGB32_Premultiplied;
- case QImage::Format_RGB16:
- return Format_RGB565;
- case QImage::Format_ARGB8565_Premultiplied:
- return Format_ARGB8565_Premultiplied;
- case QImage::Format_RGB555:
- return Format_RGB555;
- case QImage::Format_RGB888:
- return Format_RGB24;
- case QImage::Format_Grayscale8:
- return Format_Y8;
- default:
- return Format_Invalid;
- }
+ if (d)
+ d->format.setMirrored(mirrored);
}
/*!
- Returns an image format equivalent to a video frame pixel \a format. If there is no equivalent
- format QImage::Format_Invalid is returned instead.
-
- \note In general \l QImage does not handle YUV formats.
-
+ Returns whether the frame should be mirrored before displaying.
*/
-QImage::Format QVideoFrame::imageFormatFromPixelFormat(PixelFormat format)
+bool QVideoFrame::mirrored() const
{
- switch (format) {
- case Format_Invalid:
- return QImage::Format_Invalid;
- case Format_ARGB32:
- return QImage::Format_ARGB32;
- case Format_ARGB32_Premultiplied:
- return QImage::Format_ARGB32_Premultiplied;
- case Format_RGB32:
- return QImage::Format_RGB32;
- case Format_RGB24:
- return QImage::Format_RGB888;
- case Format_RGB565:
- return QImage::Format_RGB16;
- case Format_RGB555:
- return QImage::Format_RGB555;
- case Format_ARGB8565_Premultiplied:
- return QImage::Format_ARGB8565_Premultiplied;
- case Format_BGRA32:
- case Format_BGRA32_Premultiplied:
- case Format_BGR32:
- case Format_BGR24:
- return QImage::Format_Invalid;
- case Format_BGR565:
- case Format_BGR555:
- case Format_BGRA5658_Premultiplied:
- case Format_AYUV444:
- case Format_AYUV444_Premultiplied:
- case Format_YUV444:
- case Format_YUV420P:
- case Format_YUV422P:
- case Format_YV12:
- case Format_UYVY:
- case Format_YUYV:
- case Format_NV12:
- case Format_NV21:
- case Format_IMC1:
- case Format_IMC2:
- case Format_IMC3:
- case Format_IMC4:
- case Format_Y16:
- case Format_Jpeg:
- case Format_CameraRaw:
- case Format_AdobeDng:
- return QImage::Format_Invalid;
- case Format_Y8:
- return QImage::Format_Grayscale8;
- case Format_User:
- default:
- return QImage::Format_Invalid;
- }
- return QImage::Format_Invalid;
+ return d && d->format.isMirrored();
}
+/*!
+ Sets the frame \a rate of a video stream in frames per second.
+*/
+void QVideoFrame::setStreamFrameRate(qreal rate)
+{
+ if (d)
+ d->format.setStreamFrameRate(rate);
+}
-extern void QT_FASTCALL qt_convert_BGRA32_to_ARGB32(const QVideoFrame&, uchar*);
-extern void QT_FASTCALL qt_convert_BGR24_to_ARGB32(const QVideoFrame&, uchar*);
-extern void QT_FASTCALL qt_convert_BGR565_to_ARGB32(const QVideoFrame&, uchar*);
-extern void QT_FASTCALL qt_convert_BGR555_to_ARGB32(const QVideoFrame&, uchar*);
-extern void QT_FASTCALL qt_convert_AYUV444_to_ARGB32(const QVideoFrame&, uchar*);
-extern void QT_FASTCALL qt_convert_YUV444_to_ARGB32(const QVideoFrame&, uchar*);
-extern void QT_FASTCALL qt_convert_YUV420P_to_ARGB32(const QVideoFrame&, uchar*);
-extern void QT_FASTCALL qt_convert_YV12_to_ARGB32(const QVideoFrame&, uchar*);
-extern void QT_FASTCALL qt_convert_UYVY_to_ARGB32(const QVideoFrame&, uchar*);
-extern void QT_FASTCALL qt_convert_YUYV_to_ARGB32(const QVideoFrame&, uchar*);
-extern void QT_FASTCALL qt_convert_NV12_to_ARGB32(const QVideoFrame&, uchar*);
-extern void QT_FASTCALL qt_convert_NV21_to_ARGB32(const QVideoFrame&, uchar*);
-
-static VideoFrameConvertFunc qConvertFuncs[QVideoFrame::NPixelFormats] = {
- /* Format_Invalid */ nullptr, // Not needed
- /* Format_ARGB32 */ nullptr, // Not needed
- /* Format_ARGB32_Premultiplied */ nullptr, // Not needed
- /* Format_RGB32 */ nullptr, // Not needed
- /* Format_RGB24 */ nullptr, // Not needed
- /* Format_RGB565 */ nullptr, // Not needed
- /* Format_RGB555 */ nullptr, // Not needed
- /* Format_ARGB8565_Premultiplied */ nullptr, // Not needed
- /* Format_BGRA32 */ qt_convert_BGRA32_to_ARGB32,
- /* Format_BGRA32_Premultiplied */ qt_convert_BGRA32_to_ARGB32,
- /* Format_ABGR32 */ nullptr,
- /* Format_BGR32 */ qt_convert_BGRA32_to_ARGB32,
- /* Format_BGR24 */ qt_convert_BGR24_to_ARGB32,
- /* Format_BGR565 */ qt_convert_BGR565_to_ARGB32,
- /* Format_BGR555 */ qt_convert_BGR555_to_ARGB32,
- /* Format_BGRA5658_Premultiplied */ nullptr,
- /* Format_AYUV444 */ qt_convert_AYUV444_to_ARGB32,
- /* Format_AYUV444_Premultiplied */ nullptr,
- /* Format_YUV444 */ qt_convert_YUV444_to_ARGB32,
- /* Format_YUV420P */ qt_convert_YUV420P_to_ARGB32,
- /* Format_YUV422P */ nullptr,
- /* Format_YV12 */ qt_convert_YV12_to_ARGB32,
- /* Format_UYVY */ qt_convert_UYVY_to_ARGB32,
- /* Format_YUYV */ qt_convert_YUYV_to_ARGB32,
- /* Format_NV12 */ qt_convert_NV12_to_ARGB32,
- /* Format_NV21 */ qt_convert_NV21_to_ARGB32,
- /* Format_IMC1 */ nullptr,
- /* Format_IMC2 */ nullptr,
- /* Format_IMC3 */ nullptr,
- /* Format_IMC4 */ nullptr,
- /* Format_Y8 */ nullptr,
- /* Format_Y16 */ nullptr,
- /* Format_Jpeg */ nullptr, // Not needed
- /* Format_CameraRaw */ nullptr,
- /* Format_AdobeDng */ nullptr,
-};
-
-static void qInitConvertFuncsAsm()
+/*!
+ Returns the frame rate of a video stream in frames per second.
+*/
+qreal QVideoFrame::streamFrameRate() const
{
-#ifdef QT_COMPILER_SUPPORTS_SSE2
- extern void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_sse2(const QVideoFrame&, uchar*);
- if (qCpuHasFeature(SSE2)){
- qConvertFuncs[QVideoFrame::Format_BGRA32] = qt_convert_BGRA32_to_ARGB32_sse2;
- qConvertFuncs[QVideoFrame::Format_BGRA32_Premultiplied] = qt_convert_BGRA32_to_ARGB32_sse2;
- qConvertFuncs[QVideoFrame::Format_BGR32] = qt_convert_BGRA32_to_ARGB32_sse2;
- }
-#endif
-#ifdef QT_COMPILER_SUPPORTS_SSSE3
- extern void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_ssse3(const QVideoFrame&, uchar*);
- if (qCpuHasFeature(SSSE3)){
- qConvertFuncs[QVideoFrame::Format_BGRA32] = qt_convert_BGRA32_to_ARGB32_ssse3;
- qConvertFuncs[QVideoFrame::Format_BGRA32_Premultiplied] = qt_convert_BGRA32_to_ARGB32_ssse3;
- qConvertFuncs[QVideoFrame::Format_BGR32] = qt_convert_BGRA32_to_ARGB32_ssse3;
- }
-#endif
-#ifdef QT_COMPILER_SUPPORTS_AVX2
- extern void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_avx2(const QVideoFrame&, uchar*);
- if (qCpuHasFeature(AVX2)){
- qConvertFuncs[QVideoFrame::Format_BGRA32] = qt_convert_BGRA32_to_ARGB32_avx2;
- qConvertFuncs[QVideoFrame::Format_BGRA32_Premultiplied] = qt_convert_BGRA32_to_ARGB32_avx2;
- qConvertFuncs[QVideoFrame::Format_BGR32] = qt_convert_BGRA32_to_ARGB32_avx2;
- }
-#endif
+ return d ? d->format.streamFrameRate() : 0.;
}
/*!
Based on the pixel format converts current video frame to image.
\since 5.15
*/
-QImage QVideoFrame::image() const
+QImage QVideoFrame::toImage() const
{
- QVideoFrame frame = *this;
- QImage result;
-
- if (!frame.isValid() || !frame.map(QAbstractVideoBuffer::ReadOnly))
- return result;
-
- // Formats supported by QImage don't need conversion
- QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat());
- if (imageFormat != QImage::Format_Invalid) {
- result = QImage(frame.bits(), frame.width(), frame.height(), frame.bytesPerLine(), imageFormat).copy();
- }
+ if (!isValid())
+ return {};
- // Load from JPG
- else if (frame.pixelFormat() == QVideoFrame::Format_Jpeg) {
- result.loadFromData(frame.bits(), frame.mappedBytes(), "JPG");
- }
+ QMutexLocker lock(&d->imageMutex);
- // Need conversion
- else {
- static bool initAsmFuncsDone = false;
- if (!initAsmFuncsDone) {
- qInitConvertFuncsAsm();
- initAsmFuncsDone = true;
- }
- VideoFrameConvertFunc convert = qConvertFuncs[frame.pixelFormat()];
- if (!convert) {
- qWarning() << Q_FUNC_INFO << ": unsupported pixel format" << frame.pixelFormat();
- } else {
- result = QImage(frame.width(), frame.height(), QImage::Format_ARGB32);
- convert(frame, result.bits());
- }
+ if (d->image.isNull()) {
+ const bool mirrorY = surfaceFormat().scanLineDirection() != QVideoFrameFormat::TopToBottom;
+ d->image = qImageFromVideoFrame(*this, rotation(), mirrored(), mirrorY);
}
- frame.unmap();
+ return d->image;
+}
- return result;
+/*!
+ Returns the subtitle text that should be rendered together with this video frame.
+*/
+QString QVideoFrame::subtitleText() const
+{
+ return d ? d->subtitleText : QString();
}
-#ifndef QT_NO_DEBUG_STREAM
-QDebug operator<<(QDebug dbg, QVideoFrame::PixelFormat pf)
+/*!
+ Sets the subtitle text that should be rendered together with this video frame to \a text.
+*/
+void QVideoFrame::setSubtitleText(const QString &text)
{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (pf) {
- case QVideoFrame::Format_Invalid:
- return dbg << "Format_Invalid";
- case QVideoFrame::Format_ARGB32:
- return dbg << "Format_ARGB32";
- case QVideoFrame::Format_ARGB32_Premultiplied:
- return dbg << "Format_ARGB32_Premultiplied";
- case QVideoFrame::Format_RGB32:
- return dbg << "Format_RGB32";
- case QVideoFrame::Format_RGB24:
- return dbg << "Format_RGB24";
- case QVideoFrame::Format_RGB565:
- return dbg << "Format_RGB565";
- case QVideoFrame::Format_RGB555:
- return dbg << "Format_RGB555";
- case QVideoFrame::Format_ARGB8565_Premultiplied:
- return dbg << "Format_ARGB8565_Premultiplied";
- case QVideoFrame::Format_BGRA32:
- return dbg << "Format_BGRA32";
- case QVideoFrame::Format_BGRA32_Premultiplied:
- return dbg << "Format_BGRA32_Premultiplied";
- case QVideoFrame::Format_ABGR32:
- return dbg << "Format_ABGR32";
- case QVideoFrame::Format_BGR32:
- return dbg << "Format_BGR32";
- case QVideoFrame::Format_BGR24:
- return dbg << "Format_BGR24";
- case QVideoFrame::Format_BGR565:
- return dbg << "Format_BGR565";
- case QVideoFrame::Format_BGR555:
- return dbg << "Format_BGR555";
- case QVideoFrame::Format_BGRA5658_Premultiplied:
- return dbg << "Format_BGRA5658_Premultiplied";
- case QVideoFrame::Format_AYUV444:
- return dbg << "Format_AYUV444";
- case QVideoFrame::Format_AYUV444_Premultiplied:
- return dbg << "Format_AYUV444_Premultiplied";
- case QVideoFrame::Format_YUV444:
- return dbg << "Format_YUV444";
- case QVideoFrame::Format_YUV420P:
- return dbg << "Format_YUV420P";
- case QVideoFrame::Format_YUV422P:
- return dbg << "Format_YUV422P";
- case QVideoFrame::Format_YV12:
- return dbg << "Format_YV12";
- case QVideoFrame::Format_UYVY:
- return dbg << "Format_UYVY";
- case QVideoFrame::Format_YUYV:
- return dbg << "Format_YUYV";
- case QVideoFrame::Format_NV12:
- return dbg << "Format_NV12";
- case QVideoFrame::Format_NV21:
- return dbg << "Format_NV21";
- case QVideoFrame::Format_IMC1:
- return dbg << "Format_IMC1";
- case QVideoFrame::Format_IMC2:
- return dbg << "Format_IMC2";
- case QVideoFrame::Format_IMC3:
- return dbg << "Format_IMC3";
- case QVideoFrame::Format_IMC4:
- return dbg << "Format_IMC4";
- case QVideoFrame::Format_Y8:
- return dbg << "Format_Y8";
- case QVideoFrame::Format_Y16:
- return dbg << "Format_Y16";
- case QVideoFrame::Format_Jpeg:
- return dbg << "Format_Jpeg";
- case QVideoFrame::Format_AdobeDng:
- return dbg << "Format_AdobeDng";
- case QVideoFrame::Format_CameraRaw:
- return dbg << "Format_CameraRaw";
-
- default:
- return dbg << QString(QLatin1String("UserType(%1)" )).arg(int(pf)).toLatin1().constData();
- }
+ if (!d)
+ return;
+ d->subtitleText = text;
}
-QDebug operator<<(QDebug dbg, QVideoFrame::FieldType f)
+/*!
+ Uses a QPainter, \a{painter}, to render this QVideoFrame to \a rect.
+ The PaintOptions \a options can be used to specify a background color and
+ how \a rect should be filled with the video.
+
+ \note that rendering will usually happen without hardware acceleration when
+ using this method.
+*/
+void QVideoFrame::paint(QPainter *painter, const QRectF &rect, const PaintOptions &options)
{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (f) {
- case QVideoFrame::TopField:
- return dbg << "TopField";
- case QVideoFrame::BottomField:
- return dbg << "BottomField";
- case QVideoFrame::InterlacedFrame:
- return dbg << "InterlacedFrame";
- default:
- return dbg << "ProgressiveFrame";
+ if (!isValid()) {
+ painter->fillRect(rect, options.backgroundColor);
+ return;
+ }
+
+ QRectF targetRect = rect;
+ QSizeF size = qRotatedFrameSize(*this);
+
+ size.scale(targetRect.size(), options.aspectRatioMode);
+
+ if (options.aspectRatioMode == Qt::KeepAspectRatio) {
+ targetRect = QRect(0, 0, size.width(), size.height());
+ targetRect.moveCenter(rect.center());
+ // we might not be drawing every pixel, fill the leftovers black
+ if (options.backgroundColor != Qt::transparent && rect != targetRect) {
+ if (targetRect.top() > rect.top()) {
+ QRectF top(rect.left(), rect.top(), rect.width(), targetRect.top() - rect.top());
+ painter->fillRect(top, Qt::black);
+ }
+ if (targetRect.left() > rect.left()) {
+ QRectF top(rect.left(), targetRect.top(), targetRect.left() - rect.left(), targetRect.height());
+ painter->fillRect(top, Qt::black);
+ }
+ if (targetRect.right() < rect.right()) {
+ QRectF top(targetRect.right(), targetRect.top(), rect.right() - targetRect.right(), targetRect.height());
+ painter->fillRect(top, Qt::black);
+ }
+ if (targetRect.bottom() < rect.bottom()) {
+ QRectF top(rect.left(), targetRect.bottom(), rect.width(), rect.bottom() - targetRect.bottom());
+ painter->fillRect(top, Qt::black);
+ }
+ }
+ }
+
+ if (map(QtVideo::MapMode::ReadOnly)) {
+ const QTransform oldTransform = painter->transform();
+ QTransform transform = oldTransform;
+ transform.translate(targetRect.center().x() - size.width()/2,
+ targetRect.center().y() - size.height()/2);
+ painter->setTransform(transform);
+ QImage image = toImage();
+ painter->drawImage({{}, size}, image, {{},image.size()});
+ painter->setTransform(oldTransform);
+
+ unmap();
+ } else if (isValid()) {
+ // #### error handling
+ } else {
+ painter->fillRect(rect, Qt::black);
}
+
+ if ((options.paintFlags & PaintOptions::DontDrawSubtitles) || d->subtitleText.isEmpty())
+ return;
+
+ // draw subtitles
+ auto text = d->subtitleText;
+ text.replace(QLatin1Char('\n'), QChar::LineSeparator);
+
+ QVideoTextureHelper::SubtitleLayout layout;
+ layout.update(targetRect.size().toSize(), this->subtitleText());
+ layout.draw(painter, targetRect.topLeft());
}
+#ifndef QT_NO_DEBUG_STREAM
static QString qFormatTimeStamps(qint64 start, qint64 end)
{
// Early out for invalid.
@@ -1272,56 +986,68 @@ static QString qFormatTimeStamps(qint64 start, qint64 end)
if (onlyOne) {
if (start > 0)
- return QString::fromLatin1("@%1:%2:%3.%4")
+ return QStringLiteral("@%1:%2:%3.%4")
.arg(start, 1, 10, QLatin1Char('0'))
.arg(s_minutes, 2, 10, QLatin1Char('0'))
.arg(s_seconds, 2, 10, QLatin1Char('0'))
.arg(s_millis, 2, 10, QLatin1Char('0'));
- else
- return QString::fromLatin1("@%1:%2.%3")
- .arg(s_minutes, 2, 10, QLatin1Char('0'))
- .arg(s_seconds, 2, 10, QLatin1Char('0'))
- .arg(s_millis, 2, 10, QLatin1Char('0'));
- } else if (end == -1) {
+ return QStringLiteral("@%1:%2.%3")
+ .arg(s_minutes, 2, 10, QLatin1Char('0'))
+ .arg(s_seconds, 2, 10, QLatin1Char('0'))
+ .arg(s_millis, 2, 10, QLatin1Char('0'));
+ }
+
+ if (end == -1) {
// Similar to start-start, except it means keep displaying it?
if (start > 0)
- return QString::fromLatin1("%1:%2:%3.%4 - forever")
+ return QStringLiteral("%1:%2:%3.%4 - forever")
.arg(start, 1, 10, QLatin1Char('0'))
.arg(s_minutes, 2, 10, QLatin1Char('0'))
.arg(s_seconds, 2, 10, QLatin1Char('0'))
.arg(s_millis, 2, 10, QLatin1Char('0'));
- else
- return QString::fromLatin1("%1:%2.%3 - forever")
- .arg(s_minutes, 2, 10, QLatin1Char('0'))
- .arg(s_seconds, 2, 10, QLatin1Char('0'))
- .arg(s_millis, 2, 10, QLatin1Char('0'));
- } else {
- const int e_millis = end % 1000000;
- end /= 1000000;
- const int e_seconds = end % 60;
- end /= 60;
- const int e_minutes = end % 60;
- end /= 60;
-
- if (start > 0 || end > 0)
- return QString::fromLatin1("%1:%2:%3.%4 - %5:%6:%7.%8")
- .arg(start, 1, 10, QLatin1Char('0'))
- .arg(s_minutes, 2, 10, QLatin1Char('0'))
- .arg(s_seconds, 2, 10, QLatin1Char('0'))
- .arg(s_millis, 2, 10, QLatin1Char('0'))
- .arg(end, 1, 10, QLatin1Char('0'))
- .arg(e_minutes, 2, 10, QLatin1Char('0'))
- .arg(e_seconds, 2, 10, QLatin1Char('0'))
- .arg(e_millis, 2, 10, QLatin1Char('0'));
- else
- return QString::fromLatin1("%1:%2.%3 - %4:%5.%6")
- .arg(s_minutes, 2, 10, QLatin1Char('0'))
- .arg(s_seconds, 2, 10, QLatin1Char('0'))
- .arg(s_millis, 2, 10, QLatin1Char('0'))
- .arg(e_minutes, 2, 10, QLatin1Char('0'))
- .arg(e_seconds, 2, 10, QLatin1Char('0'))
- .arg(e_millis, 2, 10, QLatin1Char('0'));
+ return QStringLiteral("%1:%2.%3 - forever")
+ .arg(s_minutes, 2, 10, QLatin1Char('0'))
+ .arg(s_seconds, 2, 10, QLatin1Char('0'))
+ .arg(s_millis, 2, 10, QLatin1Char('0'));
}
+
+ const int e_millis = end % 1000000;
+ end /= 1000000;
+ const int e_seconds = end % 60;
+ end /= 60;
+ const int e_minutes = end % 60;
+ end /= 60;
+
+ if (start > 0 || end > 0)
+ return QStringLiteral("%1:%2:%3.%4 - %5:%6:%7.%8")
+ .arg(start, 1, 10, QLatin1Char('0'))
+ .arg(s_minutes, 2, 10, QLatin1Char('0'))
+ .arg(s_seconds, 2, 10, QLatin1Char('0'))
+ .arg(s_millis, 2, 10, QLatin1Char('0'))
+ .arg(end, 1, 10, QLatin1Char('0'))
+ .arg(e_minutes, 2, 10, QLatin1Char('0'))
+ .arg(e_seconds, 2, 10, QLatin1Char('0'))
+ .arg(e_millis, 2, 10, QLatin1Char('0'));
+ return QStringLiteral("%1:%2.%3 - %4:%5.%6")
+ .arg(s_minutes, 2, 10, QLatin1Char('0'))
+ .arg(s_seconds, 2, 10, QLatin1Char('0'))
+ .arg(s_millis, 2, 10, QLatin1Char('0'))
+ .arg(e_minutes, 2, 10, QLatin1Char('0'))
+ .arg(e_seconds, 2, 10, QLatin1Char('0'))
+ .arg(e_millis, 2, 10, QLatin1Char('0'));
+}
+
+QDebug operator<<(QDebug dbg, QVideoFrame::HandleType type)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ switch (type) {
+ case QVideoFrame::NoHandle:
+ return dbg << "NoHandle";
+ case QVideoFrame::RhiTextureHandle:
+ return dbg << "RhiTextureHandle";
+ }
+ return dbg;
}
QDebug operator<<(QDebug dbg, const QVideoFrame& f)
@@ -1333,8 +1059,6 @@ QDebug operator<<(QDebug dbg, const QVideoFrame& f)
<< f.handleType() << ", "
<< f.mapMode() << ", "
<< qFormatTimeStamps(f.startTime(), f.endTime()).toLatin1().constData();
- if (f.availableMetaData().count())
- dbg << ", metaData: " << f.availableMetaData();
dbg << ')';
return dbg;
}
diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h
index 268e82d70..c026972f8 100644
--- a/src/multimedia/video/qvideoframe.h
+++ b/src/multimedia/video/qvideoframe.h
@@ -1,191 +1,170 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QVIDEOFRAME_H
#define QVIDEOFRAME_H
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtMultimedia/qtvideo.h>
+#include <QtMultimedia/qvideoframeformat.h>
+
#include <QtCore/qmetatype.h>
#include <QtCore/qshareddata.h>
#include <QtGui/qimage.h>
-#include <QtMultimedia/qabstractvideobuffer.h>
-#include <QtCore/qvariant.h>
QT_BEGIN_NAMESPACE
class QSize;
-
class QVideoFramePrivate;
+class QAbstractVideoBuffer;
+class QRhi;
+class QRhiResourceUpdateBatch;
+class QRhiTexture;
+
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QVideoFramePrivate, Q_MULTIMEDIA_EXPORT)
class Q_MULTIMEDIA_EXPORT QVideoFrame
{
public:
- enum FieldType
+
+ enum HandleType
{
- ProgressiveFrame,
- TopField,
- BottomField,
- InterlacedFrame
+ NoHandle,
+ RhiTextureHandle
};
- enum PixelFormat
+ enum MapMode
{
- Format_Invalid,
- Format_ARGB32,
- Format_ARGB32_Premultiplied,
- Format_RGB32,
- Format_RGB24,
- Format_RGB565,
- Format_RGB555,
- Format_ARGB8565_Premultiplied,
- Format_BGRA32,
- Format_BGRA32_Premultiplied,
- Format_ABGR32,
- Format_BGR32,
- Format_BGR24,
- Format_BGR565,
- Format_BGR555,
- Format_BGRA5658_Premultiplied,
-
- Format_AYUV444,
- Format_AYUV444_Premultiplied,
- Format_YUV444,
- Format_YUV420P,
- Format_YUV422P,
- Format_YV12,
- Format_UYVY,
- Format_YUYV,
- Format_NV12,
- Format_NV21,
- Format_IMC1,
- Format_IMC2,
- Format_IMC3,
- Format_IMC4,
- Format_Y8,
- Format_Y16,
-
- Format_Jpeg,
-
- Format_CameraRaw,
- Format_AdobeDng,
-
-#ifndef Q_QDOC
- NPixelFormats,
-#endif
- Format_User = 1000
+ NotMapped Q_DECL_ENUMERATOR_DEPRECATED_X("Use QtVideo::MapMode::NotMapped instead")
+ = static_cast<int>(QtVideo::MapMode::NotMapped),
+ ReadOnly Q_DECL_ENUMERATOR_DEPRECATED_X("Use QtVideo::MapMode::ReadOnly instead")
+ = static_cast<int>(QtVideo::MapMode::ReadOnly),
+ WriteOnly Q_DECL_ENUMERATOR_DEPRECATED_X("Use QtVideo::MapMode::WriteOnly instead")
+ = static_cast<int>(QtVideo::MapMode::WriteOnly),
+ ReadWrite Q_DECL_ENUMERATOR_DEPRECATED_X("Use QtVideo::MapMode::ReadWrite instead")
+ = static_cast<int>(QtVideo::MapMode::ReadWrite)
};
+#if QT_DEPRECATED_SINCE(6, 7)
+ enum RotationAngle
+ {
+ Rotation0 Q_DECL_ENUMERATOR_DEPRECATED_X("Use QtVideo::Rotation::None instead") = 0,
+ Rotation90 Q_DECL_ENUMERATOR_DEPRECATED_X("Use QtVideo::Rotation::Clockwise90 instead") = 90,
+ Rotation180 Q_DECL_ENUMERATOR_DEPRECATED_X("Use QtVideo::Rotation::Clockwise180 instead") = 180,
+ Rotation270 Q_DECL_ENUMERATOR_DEPRECATED_X("Use QtVideo::Rotation::Clockwise270 instead") = 270
+ };
+#endif
+
QVideoFrame();
- QVideoFrame(QAbstractVideoBuffer *buffer, const QSize &size, PixelFormat format);
- QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format);
- QVideoFrame(const QImage &image);
+ QVideoFrame(const QVideoFrameFormat &format);
+ explicit QVideoFrame(const QImage &image);
+ explicit QVideoFrame(std::unique_ptr<QAbstractVideoBuffer> videoBuffer);
QVideoFrame(const QVideoFrame &other);
~QVideoFrame();
+ QVideoFrame(QVideoFrame &&other) noexcept = default;
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QVideoFrame)
+ void swap(QVideoFrame &other) noexcept
+ { d.swap(other.d); }
+
+
QVideoFrame &operator =(const QVideoFrame &other);
bool operator==(const QVideoFrame &other) const;
bool operator!=(const QVideoFrame &other) const;
- QAbstractVideoBuffer *buffer() const;
bool isValid() const;
- PixelFormat pixelFormat() const;
+ QVideoFrameFormat::PixelFormat pixelFormat() const;
- QAbstractVideoBuffer::HandleType handleType() const;
+ QVideoFrameFormat surfaceFormat() const;
+ QVideoFrame::HandleType handleType() const;
QSize size() const;
int width() const;
int height() const;
- FieldType fieldType() const;
- void setFieldType(FieldType);
-
bool isMapped() const;
bool isReadable() const;
bool isWritable() const;
- QAbstractVideoBuffer::MapMode mapMode() const;
+ QVideoFrame::MapMode mapMode() const;
- bool map(QAbstractVideoBuffer::MapMode mode);
+ bool map(QtVideo::MapMode mode);
+#if QT_DEPRECATED_SINCE(6, 8)
+ QT_DEPRECATED_VERSION_X_6_7("Use QVideoFrame::map(QtVideo::MapMode) instead")
+ bool map(QVideoFrame::MapMode mode);
+#endif
void unmap();
- int bytesPerLine() const;
int bytesPerLine(int plane) const;
- uchar *bits();
uchar *bits(int plane);
- const uchar *bits() const;
const uchar *bits(int plane) const;
- int mappedBytes() const;
+ int mappedBytes(int plane) const;
int planeCount() const;
- QVariant handle() const;
-
qint64 startTime() const;
void setStartTime(qint64 time);
qint64 endTime() const;
void setEndTime(qint64 time);
- QVariantMap availableMetaData() const;
- QVariant metaData(const QString &key) const;
- void setMetaData(const QString &key, const QVariant &value);
+#if QT_DEPRECATED_SINCE(6, 7)
+ QT_DEPRECATED_VERSION_X_6_7("Use QVideoFrame::setRotation(QtVideo::Rotation) instead")
+ void setRotationAngle(RotationAngle angle) { setRotation(QtVideo::Rotation(angle)); }
+
+ QT_DEPRECATED_VERSION_X_6_7("Use QVideoFrame::rotation() instead")
+ RotationAngle rotationAngle() const { return RotationAngle(rotation()); }
+#endif
+
+ void setRotation(QtVideo::Rotation angle);
+ QtVideo::Rotation rotation() const;
+
+ void setMirrored(bool);
+ bool mirrored() const;
+
+ void setStreamFrameRate(qreal rate);
+ qreal streamFrameRate() const;
- QImage image() const;
+ QImage toImage() const;
- static PixelFormat pixelFormatFromImageFormat(QImage::Format format);
- static QImage::Format imageFormatFromPixelFormat(PixelFormat format);
+ struct PaintOptions {
+ QColor backgroundColor = Qt::transparent;
+ Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio;
+ enum PaintFlag {
+ DontDrawSubtitles = 0x1
+ };
+ Q_DECLARE_FLAGS(PaintFlags, PaintFlag)
+ PaintFlags paintFlags = {};
+ };
+
+ QString subtitleText() const;
+ void setSubtitleText(const QString &text);
+
+ void paint(QPainter *painter, const QRectF &rect, const PaintOptions &options);
+#if QT_DEPRECATED_SINCE(6, 8)
+ QT_DEPRECATED_VERSION_X_6_8("The constructor is internal and deprecated")
+ QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoFrameFormat &format);
+
+ QT_DEPRECATED_VERSION_X_6_8("The method is internal and deprecated")
+ QAbstractVideoBuffer *videoBuffer() const;
+#endif
private:
+ friend class QVideoFramePrivate;
QExplicitlySharedDataPointer<QVideoFramePrivate> d;
};
+Q_DECLARE_SHARED(QVideoFrame)
+
#ifndef QT_NO_DEBUG_STREAM
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoFrame&);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoFrame::FieldType);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoFrame::PixelFormat);
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoFrame::HandleType);
#endif
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QVideoFrame)
-Q_DECLARE_METATYPE(QVideoFrame::FieldType)
-Q_DECLARE_METATYPE(QVideoFrame::PixelFormat)
#endif
diff --git a/src/multimedia/video/qvideoframe_p.h b/src/multimedia/video/qvideoframe_p.h
new file mode 100644
index 000000000..865e26463
--- /dev/null
+++ b/src/multimedia/video/qvideoframe_p.h
@@ -0,0 +1,87 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QVIDEOFRAME_P_H
+#define QVIDEOFRAME_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qvideoframe.h"
+#include "qhwvideobuffer_p.h"
+
+#include <qmutex.h>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoFramePrivate : public QSharedData
+{
+public:
+ QVideoFramePrivate() = default;
+
+ template <typename Buffer>
+ static QVideoFrame createFrame(std::unique_ptr<Buffer> buffer, QVideoFrameFormat format)
+ {
+ QVideoFrame result;
+ result.d.reset(new QVideoFramePrivate(std::move(format), std::move(buffer)));
+ return result;
+ }
+
+ template <typename Buffer = QAbstractVideoBuffer>
+ QVideoFramePrivate(QVideoFrameFormat format, std::unique_ptr<Buffer> buffer = nullptr)
+ : format{ std::move(format) }, videoBuffer{ std::move(buffer) }
+ {
+ if constexpr (std::is_base_of_v<QHwVideoBuffer, Buffer>)
+ hwVideoBuffer = static_cast<QHwVideoBuffer *>(videoBuffer.get());
+ else if constexpr (std::is_same_v<QAbstractVideoBuffer, Buffer>)
+ hwVideoBuffer = dynamic_cast<QHwVideoBuffer *>(videoBuffer.get());
+ // else hwVideoBuffer == nullptr
+ }
+
+ static QVideoFramePrivate *handle(QVideoFrame &frame) { return frame.d.get(); };
+
+ static QHwVideoBuffer *hwBuffer(const QVideoFrame &frame)
+ {
+ return frame.d ? frame.d->hwVideoBuffer : nullptr;
+ };
+
+ static QAbstractVideoBuffer *buffer(const QVideoFrame &frame)
+ {
+ return frame.d ? frame.d->videoBuffer.get() : nullptr;
+ };
+
+ QVideoFrame adoptThisByVideoFrame()
+ {
+ QVideoFrame frame;
+ frame.d = QExplicitlySharedDataPointer(this, QAdoptSharedDataTag{});
+ return frame;
+ }
+
+ qint64 startTime = -1;
+ qint64 endTime = -1;
+ QAbstractVideoBuffer::MapData mapData;
+ QtVideo::MapMode mapMode = QtVideo::MapMode::NotMapped;
+ QVideoFrameFormat format;
+ std::unique_ptr<QAbstractVideoBuffer> videoBuffer;
+ QHwVideoBuffer *hwVideoBuffer = nullptr;
+ int mappedCount = 0;
+ QMutex mapMutex;
+ QString subtitleText;
+ QImage image;
+ QMutex imageMutex;
+
+private:
+ Q_DISABLE_COPY(QVideoFramePrivate)
+};
+
+QT_END_NAMESPACE
+
+#endif // QVIDEOFRAMEPRIVATE_P_H
diff --git a/src/multimedia/video/qvideoframeconversionhelper.cpp b/src/multimedia/video/qvideoframeconversionhelper.cpp
index 3a461592f..d3f2b0403 100644
--- a/src/multimedia/video/qvideoframeconversionhelper.cpp
+++ b/src/multimedia/video/qvideoframeconversionhelper.cpp
@@ -1,43 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qvideoframeconversionhelper_p.h"
+#include "qrgb.h"
+
+#include <mutex>
QT_BEGIN_NAMESPACE
@@ -66,37 +33,63 @@ static inline void planarYUV420_to_ARGB32(const uchar *y, int yStride,
quint32 *rgb,
int width, int height)
{
- quint32 *rgb0 = rgb;
- quint32 *rgb1 = rgb + width;
+ height &= ~1;
- for (int j = 0; j < height; j += 2) {
+ for (int j = 0; j + 1 < height; j += 2) {
const uchar *lineY0 = y;
const uchar *lineY1 = y + yStride;
const uchar *lineU = u;
const uchar *lineV = v;
- for (int i = 0; i < width; i += 2) {
+ quint32 *rgb0 = rgb;
+ quint32 *rgb1 = rgb + width;
+ for (int i = 0; i + 1 < width; i += 2) {
EXPAND_UV(*lineU, *lineV);
lineU += uvPixelStride;
lineV += uvPixelStride;
- *rgb0++ = qYUVToARGB32(*lineY0++, rv, guv, bu);
- *rgb0++ = qYUVToARGB32(*lineY0++, rv, guv, bu);
- *rgb1++ = qYUVToARGB32(*lineY1++, rv, guv, bu);
- *rgb1++ = qYUVToARGB32(*lineY1++, rv, guv, bu);
+ rgb0[i] = qYUVToARGB32(*lineY0++, rv, guv, bu);
+ rgb0[i + 1] = qYUVToARGB32(*lineY0++, rv, guv, bu);
+ rgb1[i] = qYUVToARGB32(*lineY1++, rv, guv, bu);
+ rgb1[i + 1] = qYUVToARGB32(*lineY1++, rv, guv, bu);
}
y += yStride << 1; // stride * 2
u += uStride;
v += vStride;
- rgb0 += width;
- rgb1 += width;
+ rgb += width << 1; // width * 2
}
}
+static inline void planarYUV422_to_ARGB32(const uchar *y, int yStride,
+ const uchar *u, int uStride,
+ const uchar *v, int vStride,
+ int uvPixelStride,
+ quint32 *rgb,
+ int width, int height)
+{
+ for (int j = 0; j < height; ++j) {
+ const uchar *lineY0 = y;
+ const uchar *lineU = u;
+ const uchar *lineV = v;
+
+ for (int i = 0; i + 1 < width; i += 2) {
+ EXPAND_UV(*lineU, *lineV);
+ lineU += uvPixelStride;
+ lineV += uvPixelStride;
+ rgb[i] = qYUVToARGB32(*lineY0++, rv, guv, bu);
+ rgb[i+1] = qYUVToARGB32(*lineY0++, rv, guv, bu);
+ }
-void QT_FASTCALL qt_convert_YUV420P_to_ARGB32(const QVideoFrame &frame, uchar *output)
+ y += yStride; // stride * 2
+ u += uStride;
+ v += vStride;
+ rgb += width;
+ }
+}
+
+static void QT_FASTCALL qt_convert_YUV420P_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_TRIPLANAR(frame)
planarYUV420_to_ARGB32(plane1, plane1Stride,
@@ -107,7 +100,19 @@ void QT_FASTCALL qt_convert_YUV420P_to_ARGB32(const QVideoFrame &frame, uchar *o
width, height);
}
-void QT_FASTCALL qt_convert_YV12_to_ARGB32(const QVideoFrame &frame, uchar *output)
+static void QT_FASTCALL qt_convert_YUV422P_to_ARGB32(const QVideoFrame &frame, uchar *output)
+{
+ FETCH_INFO_TRIPLANAR(frame)
+ planarYUV422_to_ARGB32(plane1, plane1Stride,
+ plane2, plane2Stride,
+ plane3, plane3Stride,
+ 1,
+ reinterpret_cast<quint32*>(output),
+ width, height);
+}
+
+
+static void QT_FASTCALL qt_convert_YV12_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_TRIPLANAR(frame)
planarYUV420_to_ARGB32(plane1, plane1Stride,
@@ -118,7 +123,7 @@ void QT_FASTCALL qt_convert_YV12_to_ARGB32(const QVideoFrame &frame, uchar *outp
width, height);
}
-void QT_FASTCALL qt_convert_AYUV444_to_ARGB32(const QVideoFrame &frame, uchar *output)
+static void QT_FASTCALL qt_convert_AYUV_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_PACKED(frame)
MERGE_LOOPS(width, height, stride, 4)
@@ -136,17 +141,17 @@ void QT_FASTCALL qt_convert_AYUV444_to_ARGB32(const QVideoFrame &frame, uchar *o
EXPAND_UV(u, v);
- *rgb++ = qYUVToARGB32(y, rv, guv, bu, a);
+ *rgb++ = qPremultiply(qYUVToARGB32(y, rv, guv, bu, a));
}
src += stride;
}
}
-void QT_FASTCALL qt_convert_YUV444_to_ARGB32(const QVideoFrame &frame, uchar *output)
+static void QT_FASTCALL qt_convert_AYUV_Premultiplied_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_PACKED(frame)
- MERGE_LOOPS(width, height, stride, 3)
+ MERGE_LOOPS(width, height, stride, 4)
quint32 *rgb = reinterpret_cast<quint32*>(output);
@@ -154,20 +159,21 @@ void QT_FASTCALL qt_convert_YUV444_to_ARGB32(const QVideoFrame &frame, uchar *ou
const uchar *lineSrc = src;
for (int j = 0; j < width; ++j) {
+ int a = *lineSrc++;
int y = *lineSrc++;
int u = *lineSrc++;
int v = *lineSrc++;
EXPAND_UV(u, v);
- *rgb++ = qYUVToARGB32(y, rv, guv, bu);
+ *rgb++ = qYUVToARGB32(y, rv, guv, bu, a);
}
src += stride;
}
}
-void QT_FASTCALL qt_convert_UYVY_to_ARGB32(const QVideoFrame &frame, uchar *output)
+static void QT_FASTCALL qt_convert_UYVY_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_PACKED(frame)
MERGE_LOOPS(width, height, stride, 2)
@@ -176,8 +182,7 @@ void QT_FASTCALL qt_convert_UYVY_to_ARGB32(const QVideoFrame &frame, uchar *outp
for (int i = 0; i < height; ++i) {
const uchar *lineSrc = src;
-
- for (int j = 0; j < width; j += 2) {
+ for (int j = 0; j + 1 < width; j += 2) {
int u = *lineSrc++;
int y0 = *lineSrc++;
int v = *lineSrc++;
@@ -185,15 +190,16 @@ void QT_FASTCALL qt_convert_UYVY_to_ARGB32(const QVideoFrame &frame, uchar *outp
EXPAND_UV(u, v);
- *rgb++ = qYUVToARGB32(y0, rv, guv, bu);
- *rgb++ = qYUVToARGB32(y1, rv, guv, bu);
+ rgb[j] = qYUVToARGB32(y0, rv, guv, bu);
+ rgb[j+1] = qYUVToARGB32(y1, rv, guv, bu);
}
src += stride;
+ rgb += width;
}
}
-void QT_FASTCALL qt_convert_YUYV_to_ARGB32(const QVideoFrame &frame, uchar *output)
+static void QT_FASTCALL qt_convert_YUYV_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_PACKED(frame)
MERGE_LOOPS(width, height, stride, 2)
@@ -202,8 +208,7 @@ void QT_FASTCALL qt_convert_YUYV_to_ARGB32(const QVideoFrame &frame, uchar *outp
for (int i = 0; i < height; ++i) {
const uchar *lineSrc = src;
-
- for (int j = 0; j < width; j += 2) {
+ for (int j = 0; j + 1 < width; j += 2) {
int y0 = *lineSrc++;
int u = *lineSrc++;
int y1 = *lineSrc++;
@@ -211,15 +216,16 @@ void QT_FASTCALL qt_convert_YUYV_to_ARGB32(const QVideoFrame &frame, uchar *outp
EXPAND_UV(u, v);
- *rgb++ = qYUVToARGB32(y0, rv, guv, bu);
- *rgb++ = qYUVToARGB32(y1, rv, guv, bu);
+ rgb[j] = qYUVToARGB32(y0, rv, guv, bu);
+ rgb[j+1] = qYUVToARGB32(y1, rv, guv, bu);
}
src += stride;
+ rgb += width;
}
}
-void QT_FASTCALL qt_convert_NV12_to_ARGB32(const QVideoFrame &frame, uchar *output)
+static void QT_FASTCALL qt_convert_NV12_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_BIPLANAR(frame)
planarYUV420_to_ARGB32(plane1, plane1Stride,
@@ -230,7 +236,7 @@ void QT_FASTCALL qt_convert_NV12_to_ARGB32(const QVideoFrame &frame, uchar *outp
width, height);
}
-void QT_FASTCALL qt_convert_NV21_to_ARGB32(const QVideoFrame &frame, uchar *output)
+static void QT_FASTCALL qt_convert_NV21_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_BIPLANAR(frame)
planarYUV420_to_ARGB32(plane1, plane1Stride,
@@ -241,7 +247,63 @@ void QT_FASTCALL qt_convert_NV21_to_ARGB32(const QVideoFrame &frame, uchar *outp
width, height);
}
-void QT_FASTCALL qt_convert_BGRA32_to_ARGB32(const QVideoFrame &frame, uchar *output)
+static void QT_FASTCALL qt_convert_IMC1_to_ARGB32(const QVideoFrame &frame, uchar *output)
+{
+ FETCH_INFO_TRIPLANAR(frame)
+ Q_ASSERT(plane1Stride == plane2Stride);
+ Q_ASSERT(plane1Stride == plane3Stride);
+
+ planarYUV420_to_ARGB32(plane1, plane1Stride,
+ plane3, plane3Stride,
+ plane2, plane2Stride,
+ 1,
+ reinterpret_cast<quint32*>(output),
+ width, height);
+}
+
+static void QT_FASTCALL qt_convert_IMC2_to_ARGB32(const QVideoFrame &frame, uchar *output)
+{
+ FETCH_INFO_BIPLANAR(frame)
+ Q_ASSERT(plane1Stride == plane2Stride);
+
+ planarYUV420_to_ARGB32(plane1, plane1Stride,
+ plane2 + (plane1Stride >> 1), plane1Stride,
+ plane2, plane1Stride,
+ 1,
+ reinterpret_cast<quint32*>(output),
+ width, height);
+}
+
+static void QT_FASTCALL qt_convert_IMC3_to_ARGB32(const QVideoFrame &frame, uchar *output)
+{
+ FETCH_INFO_TRIPLANAR(frame)
+ Q_ASSERT(plane1Stride == plane2Stride);
+ Q_ASSERT(plane1Stride == plane3Stride);
+
+ planarYUV420_to_ARGB32(plane1, plane1Stride,
+ plane2, plane2Stride,
+ plane3, plane3Stride,
+ 1,
+ reinterpret_cast<quint32*>(output),
+ width, height);
+}
+
+static void QT_FASTCALL qt_convert_IMC4_to_ARGB32(const QVideoFrame &frame, uchar *output)
+{
+ FETCH_INFO_BIPLANAR(frame)
+ Q_ASSERT(plane1Stride == plane2Stride);
+
+ planarYUV420_to_ARGB32(plane1, plane1Stride,
+ plane2, plane1Stride,
+ plane2 + (plane1Stride >> 1), plane1Stride,
+ 1,
+ reinterpret_cast<quint32*>(output),
+ width, height);
+}
+
+
+template<typename Pixel>
+static void QT_FASTCALL qt_convert_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_PACKED(frame)
MERGE_LOOPS(width, height, stride, 4)
@@ -249,106 +311,320 @@ void QT_FASTCALL qt_convert_BGRA32_to_ARGB32(const QVideoFrame &frame, uchar *ou
quint32 *argb = reinterpret_cast<quint32*>(output);
for (int y = 0; y < height; ++y) {
- const quint32 *bgra = reinterpret_cast<const quint32*>(src);
+ const Pixel *data = reinterpret_cast<const Pixel *>(src);
int x = 0;
for (; x < width - 3; x += 4) {
- *argb++ = qConvertBGRA32ToARGB32(*bgra++);
- *argb++ = qConvertBGRA32ToARGB32(*bgra++);
- *argb++ = qConvertBGRA32ToARGB32(*bgra++);
- *argb++ = qConvertBGRA32ToARGB32(*bgra++);
+ // Copy 4 pixels onto the stack in one go. This significantly increases performance
+ // in the case where the mapped memory is uncached (because it's a framebuffer)
+ Pixel p[4];
+ memcpy(p, data, 4*sizeof(Pixel));
+ *argb++ = qPremultiply(p[0].convert());
+ *argb++ = qPremultiply(p[1].convert());
+ *argb++ = qPremultiply(p[2].convert());
+ *argb++ = qPremultiply(p[3].convert());
+ data += 4;
}
// leftovers
- for (; x < width; ++x)
- *argb++ = qConvertBGRA32ToARGB32(*bgra++);
+ for (; x < width; ++x) {
+ *argb++ = qPremultiply(data->convert());
+ ++data;
+ }
src += stride;
}
}
-void QT_FASTCALL qt_convert_BGR24_to_ARGB32(const QVideoFrame &frame, uchar *output)
+template<typename Pixel>
+static void QT_FASTCALL qt_convert_premultiplied_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_PACKED(frame)
- MERGE_LOOPS(width, height, stride, 3)
+ MERGE_LOOPS(width, height, stride, 4)
quint32 *argb = reinterpret_cast<quint32*>(output);
for (int y = 0; y < height; ++y) {
- const uchar *bgr = src;
+ const Pixel *data = reinterpret_cast<const Pixel *>(src);
int x = 0;
for (; x < width - 3; x += 4) {
- *argb++ = qConvertBGR24ToARGB32(bgr);
- bgr += 3;
- *argb++ = qConvertBGR24ToARGB32(bgr);
- bgr += 3;
- *argb++ = qConvertBGR24ToARGB32(bgr);
- bgr += 3;
- *argb++ = qConvertBGR24ToARGB32(bgr);
- bgr += 3;
+ // Copy 4 pixels onto the stack in one go. This significantly increases performance
+ // in the case where the mapped memory is uncached (because it's a framebuffer)
+ Pixel p[4];
+ memcpy(p, data, 4*sizeof(Pixel));
+ *argb++ = p[0].convert();
+ *argb++ = p[1].convert();
+ *argb++ = p[2].convert();
+ *argb++ = p[3].convert();
+ data += 4;
}
// leftovers
for (; x < width; ++x) {
- *argb++ = qConvertBGR24ToARGB32(bgr);
- bgr += 3;
+ *argb++ = data->convert();
+ ++data;
}
src += stride;
}
}
-void QT_FASTCALL qt_convert_BGR565_to_ARGB32(const QVideoFrame &frame, uchar *output)
+static inline void planarYUV420_16bit_to_ARGB32(const uchar *y, int yStride,
+ const uchar *u, int uStride,
+ const uchar *v, int vStride,
+ int uvPixelStride,
+ quint32 *rgb,
+ int width, int height)
{
- FETCH_INFO_PACKED(frame)
- MERGE_LOOPS(width, height, stride, 2)
+ height &= ~1;
- quint32 *argb = reinterpret_cast<quint32*>(output);
+ for (int j = 0; j + 1 < height; j += 2) {
+ const uchar *lineY0 = y;
+ const uchar *lineY1 = y + yStride;
+ const uchar *lineU = u;
+ const uchar *lineV = v;
- for (int y = 0; y < height; ++y) {
- const quint16 *bgr = reinterpret_cast<const quint16*>(src);
+ quint32 *rgb0 = rgb;
+ quint32 *rgb1 = rgb + width;
- int x = 0;
- for (; x < width - 3; x += 4) {
- *argb++ = qConvertBGR565ToARGB32(*bgr++);
- *argb++ = qConvertBGR565ToARGB32(*bgr++);
- *argb++ = qConvertBGR565ToARGB32(*bgr++);
- *argb++ = qConvertBGR565ToARGB32(*bgr++);
- }
+ for (int i = 0; i + 1 < width; i += 2) {
+ EXPAND_UV(*lineU, *lineV);
+ lineU += uvPixelStride;
+ lineV += uvPixelStride;
- // leftovers
- for (; x < width; ++x)
- *argb++ = qConvertBGR565ToARGB32(*bgr++);
+ *rgb0++ = qYUVToARGB32(*lineY0, rv, guv, bu);
+ lineY0 += 2;
+ *rgb0++ = qYUVToARGB32(*lineY0, rv, guv, bu);
+ lineY0 += 2;
+ *rgb1++ = qYUVToARGB32(*lineY1, rv, guv, bu);
+ lineY1 += 2;
+ *rgb1++ = qYUVToARGB32(*lineY1, rv, guv, bu);
+ lineY1 += 2;
+ }
- src += stride;
+ y += yStride << 1; // stride * 2
+ u += uStride;
+ v += vStride;
+ rgb += width * 2;
}
}
-void QT_FASTCALL qt_convert_BGR555_to_ARGB32(const QVideoFrame &frame, uchar *output)
+
+static void QT_FASTCALL qt_convert_P016_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
- FETCH_INFO_PACKED(frame)
- MERGE_LOOPS(width, height, stride, 2)
+ FETCH_INFO_BIPLANAR(frame)
+ planarYUV420_16bit_to_ARGB32(plane1 + 1, plane1Stride,
+ plane2 + 1, plane2Stride,
+ plane2 + 3, plane2Stride,
+ 4,
+ reinterpret_cast<quint32*>(output),
+ width, height);
+}
+
+template <typename Y>
+static void QT_FASTCALL qt_convert_Y_to_ARGB32(const QVideoFrame &frame, uchar *output)
+{
+ FETCH_INFO_PACKED(frame)
+ MERGE_LOOPS(width, height, stride, (int)sizeof(Y))
quint32 *argb = reinterpret_cast<quint32*>(output);
+ using Pixel = YPixel<Y>;
+
for (int y = 0; y < height; ++y) {
- const quint16 *bgr = reinterpret_cast<const quint16*>(src);
+ const Pixel *pixel = reinterpret_cast<const Pixel *>(src);
int x = 0;
for (; x < width - 3; x += 4) {
- *argb++ = qConvertBGR555ToARGB32(*bgr++);
- *argb++ = qConvertBGR555ToARGB32(*bgr++);
- *argb++ = qConvertBGR555ToARGB32(*bgr++);
- *argb++ = qConvertBGR555ToARGB32(*bgr++);
+ *argb++ = pixel->convert();
+ ++pixel;
+ *argb++ = pixel->convert();
+ ++pixel;
+ *argb++ = pixel->convert();
+ ++pixel;
+ *argb++ = pixel->convert();
+ ++pixel;
}
// leftovers
- for (; x < width; ++x)
- *argb++ = qConvertBGR555ToARGB32(*bgr++);
+ for (; x < width; ++x) {
+ *argb++ = pixel->convert();
+ ++pixel;
+ }
src += stride;
}
+ MERGE_LOOPS(width, height, stride, 1)
+}
+
+template<typename Pixel>
+static void QT_FASTCALL qt_copy_pixels_with_mask(Pixel *dst, const Pixel *src, size_t size,
+ Pixel mask)
+{
+ for (size_t x = 0; x < size; ++x)
+ dst[x] = src[x] | mask;
+}
+
+static VideoFrameConvertFunc qConvertFuncs[QVideoFrameFormat::NPixelFormats] = {
+ /* Format_Invalid */ nullptr, // Not needed
+ /* Format_ARGB8888 */ qt_convert_to_ARGB32<ARGB8888>,
+ /* Format_ARGB8888_Premultiplied */ qt_convert_premultiplied_to_ARGB32<ARGB8888>,
+ /* Format_XRGB8888 */ qt_convert_premultiplied_to_ARGB32<XRGB8888>,
+ /* Format_BGRA8888 */ qt_convert_to_ARGB32<BGRA8888>,
+ /* Format_BGRA8888_Premultiplied */ qt_convert_premultiplied_to_ARGB32<BGRA8888>,
+ /* Format_BGRX8888 */ qt_convert_premultiplied_to_ARGB32<BGRX8888>,
+ /* Format_ABGR8888 */ qt_convert_to_ARGB32<ABGR8888>,
+ /* Format_XBGR8888 */ qt_convert_premultiplied_to_ARGB32<XBGR8888>,
+ /* Format_RGBA8888 */ qt_convert_to_ARGB32<RGBA8888>,
+ /* Format_RGBX8888 */ qt_convert_premultiplied_to_ARGB32<RGBX8888>,
+ /* Format_AYUV */ qt_convert_AYUV_to_ARGB32,
+ /* Format_AYUV_Premultiplied */ qt_convert_AYUV_Premultiplied_to_ARGB32,
+ /* Format_YUV420P */ qt_convert_YUV420P_to_ARGB32,
+ /* Format_YUV422P */ qt_convert_YUV422P_to_ARGB32,
+ /* Format_YV12 */ qt_convert_YV12_to_ARGB32,
+ /* Format_UYVY */ qt_convert_UYVY_to_ARGB32,
+ /* Format_YUYV */ qt_convert_YUYV_to_ARGB32,
+ /* Format_NV12 */ qt_convert_NV12_to_ARGB32,
+ /* Format_NV21 */ qt_convert_NV21_to_ARGB32,
+ /* Format_IMC1 */ qt_convert_IMC1_to_ARGB32,
+ /* Format_IMC2 */ qt_convert_IMC2_to_ARGB32,
+ /* Format_IMC3 */ qt_convert_IMC3_to_ARGB32,
+ /* Format_IMC4 */ qt_convert_IMC4_to_ARGB32,
+ /* Format_Y8 */ qt_convert_Y_to_ARGB32<uchar>,
+ /* Format_Y16 */ qt_convert_Y_to_ARGB32<ushort>,
+ /* Format_P010 */ qt_convert_P016_to_ARGB32,
+ /* Format_P016 */ qt_convert_P016_to_ARGB32,
+ /* Format_Jpeg */ nullptr, // Not needed
+};
+
+static PixelsCopyFunc qPixelsCopyFunc = qt_copy_pixels_with_mask<uint32_t>;
+
+static std::once_flag InitFuncsAsmFlag;
+
+static void qInitFuncsAsm()
+{
+#ifdef QT_COMPILER_SUPPORTS_SSE2
+ extern void QT_FASTCALL qt_convert_ARGB8888_to_ARGB32_sse2(const QVideoFrame &frame, uchar *output);
+ extern void QT_FASTCALL qt_convert_ABGR8888_to_ARGB32_sse2(const QVideoFrame &frame, uchar *output);
+ extern void QT_FASTCALL qt_convert_RGBA8888_to_ARGB32_sse2(const QVideoFrame &frame, uchar *output);
+ extern void QT_FASTCALL qt_convert_BGRA8888_to_ARGB32_sse2(const QVideoFrame &frame, uchar *output);
+ extern void QT_FASTCALL qt_copy_pixels_with_mask_sse2(uint32_t * dst, const uint32_t *src, size_t size, uint32_t mask);
+
+ if (qCpuHasFeature(SSE2)){
+ qConvertFuncs[QVideoFrameFormat::Format_ARGB8888] = qt_convert_ARGB8888_to_ARGB32_sse2;
+ qConvertFuncs[QVideoFrameFormat::Format_ARGB8888_Premultiplied] = qt_convert_ARGB8888_to_ARGB32_sse2;
+ qConvertFuncs[QVideoFrameFormat::Format_XRGB8888] = qt_convert_ARGB8888_to_ARGB32_sse2;
+ qConvertFuncs[QVideoFrameFormat::Format_BGRA8888] = qt_convert_BGRA8888_to_ARGB32_sse2;
+ qConvertFuncs[QVideoFrameFormat::Format_BGRA8888_Premultiplied] = qt_convert_BGRA8888_to_ARGB32_sse2;
+ qConvertFuncs[QVideoFrameFormat::Format_BGRX8888] = qt_convert_BGRA8888_to_ARGB32_sse2;
+ qConvertFuncs[QVideoFrameFormat::Format_ABGR8888] = qt_convert_ABGR8888_to_ARGB32_sse2;
+ qConvertFuncs[QVideoFrameFormat::Format_XBGR8888] = qt_convert_ABGR8888_to_ARGB32_sse2;
+ qConvertFuncs[QVideoFrameFormat::Format_RGBA8888] = qt_convert_RGBA8888_to_ARGB32_sse2;
+ qConvertFuncs[QVideoFrameFormat::Format_RGBX8888] = qt_convert_RGBA8888_to_ARGB32_sse2;
+
+ qPixelsCopyFunc = qt_copy_pixels_with_mask_sse2;
+ }
+#endif
+#ifdef QT_COMPILER_SUPPORTS_SSSE3
+ extern void QT_FASTCALL qt_convert_ARGB8888_to_ARGB32_ssse3(const QVideoFrame &frame, uchar *output);
+ extern void QT_FASTCALL qt_convert_ABGR8888_to_ARGB32_ssse3(const QVideoFrame &frame, uchar *output);
+ extern void QT_FASTCALL qt_convert_RGBA8888_to_ARGB32_ssse3(const QVideoFrame &frame, uchar *output);
+ extern void QT_FASTCALL qt_convert_BGRA8888_to_ARGB32_ssse3(const QVideoFrame &frame, uchar *output);
+ if (qCpuHasFeature(SSSE3)){
+ qConvertFuncs[QVideoFrameFormat::Format_ARGB8888] = qt_convert_ARGB8888_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoFrameFormat::Format_ARGB8888_Premultiplied] = qt_convert_ARGB8888_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoFrameFormat::Format_XRGB8888] = qt_convert_ARGB8888_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoFrameFormat::Format_BGRA8888] = qt_convert_BGRA8888_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoFrameFormat::Format_BGRA8888_Premultiplied] = qt_convert_BGRA8888_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoFrameFormat::Format_BGRX8888] = qt_convert_BGRA8888_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoFrameFormat::Format_ABGR8888] = qt_convert_ABGR8888_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoFrameFormat::Format_XBGR8888] = qt_convert_ABGR8888_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoFrameFormat::Format_RGBA8888] = qt_convert_RGBA8888_to_ARGB32_ssse3;
+ qConvertFuncs[QVideoFrameFormat::Format_RGBX8888] = qt_convert_RGBA8888_to_ARGB32_ssse3;
+ }
+#endif
+#ifdef QT_COMPILER_SUPPORTS_AVX2
+ extern void QT_FASTCALL qt_convert_ARGB8888_to_ARGB32_avx2(const QVideoFrame &frame, uchar *output);
+ extern void QT_FASTCALL qt_convert_ABGR8888_to_ARGB32_avx2(const QVideoFrame &frame, uchar *output);
+ extern void QT_FASTCALL qt_convert_RGBA8888_to_ARGB32_avx2(const QVideoFrame &frame, uchar *output);
+ extern void QT_FASTCALL qt_convert_BGRA8888_to_ARGB32_avx2(const QVideoFrame &frame, uchar *output);
+ extern void QT_FASTCALL qt_copy_pixels_with_mask_avx2(uint32_t * dst, const uint32_t *src, size_t size, uint32_t mask);
+ if (qCpuHasFeature(AVX2)){
+ qConvertFuncs[QVideoFrameFormat::Format_ARGB8888] = qt_convert_ARGB8888_to_ARGB32_avx2;
+ qConvertFuncs[QVideoFrameFormat::Format_ARGB8888_Premultiplied] = qt_convert_ARGB8888_to_ARGB32_avx2;
+ qConvertFuncs[QVideoFrameFormat::Format_XRGB8888] = qt_convert_ARGB8888_to_ARGB32_avx2;
+ qConvertFuncs[QVideoFrameFormat::Format_BGRA8888] = qt_convert_BGRA8888_to_ARGB32_avx2;
+ qConvertFuncs[QVideoFrameFormat::Format_BGRA8888_Premultiplied] = qt_convert_BGRA8888_to_ARGB32_avx2;
+ qConvertFuncs[QVideoFrameFormat::Format_BGRX8888] = qt_convert_BGRA8888_to_ARGB32_avx2;
+ qConvertFuncs[QVideoFrameFormat::Format_ABGR8888] = qt_convert_ABGR8888_to_ARGB32_avx2;
+ qConvertFuncs[QVideoFrameFormat::Format_XBGR8888] = qt_convert_ABGR8888_to_ARGB32_avx2;
+ qConvertFuncs[QVideoFrameFormat::Format_RGBA8888] = qt_convert_RGBA8888_to_ARGB32_avx2;
+ qConvertFuncs[QVideoFrameFormat::Format_RGBX8888] = qt_convert_RGBA8888_to_ARGB32_avx2;
+
+ qPixelsCopyFunc = qt_copy_pixels_with_mask_avx2;
+ }
+#endif
+}
+
+VideoFrameConvertFunc qConverterForFormat(QVideoFrameFormat::PixelFormat format)
+{
+ std::call_once(InitFuncsAsmFlag, &qInitFuncsAsm);
+
+ VideoFrameConvertFunc convert = qConvertFuncs[format];
+ return convert;
+}
+
+void Q_MULTIMEDIA_EXPORT qCopyPixelsWithAlphaMask(uint32_t *dst,
+ const uint32_t *src,
+ size_t pixCount,
+ QVideoFrameFormat::PixelFormat format,
+ bool srcAlphaVaries)
+{
+ if (pixCount == 0)
+ return;
+
+ const auto mask = qAlphaMask(format);
+
+ if (srcAlphaVaries || (src[0] & mask) != mask)
+ qCopyPixelsWithMask(dst, src, pixCount, mask);
+ else
+ memcpy(dst, src, pixCount * 4);
+}
+
+void qCopyPixelsWithMask(uint32_t *dst, const uint32_t *src, size_t size, uint32_t mask)
+{
+ std::call_once(InitFuncsAsmFlag, &qInitFuncsAsm);
+
+ qPixelsCopyFunc(dst, src, size, mask);
+}
+
+uint32_t qAlphaMask(QVideoFrameFormat::PixelFormat format)
+{
+ switch (format) {
+ case QVideoFrameFormat::Format_ARGB8888:
+ case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
+ case QVideoFrameFormat::Format_XRGB8888:
+ case QVideoFrameFormat::Format_ABGR8888:
+ case QVideoFrameFormat::Format_XBGR8888:
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ return 0xff;
+#else
+ return 0xff000000;
+#endif
+ case QVideoFrameFormat::Format_BGRA8888:
+ case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
+ case QVideoFrameFormat::Format_BGRX8888:
+ case QVideoFrameFormat::Format_RGBA8888:
+ case QVideoFrameFormat::Format_RGBX8888:
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ return 0xff000000;
+#else
+ return 0xff;
+#endif
+ default:
+ return 0;
+ }
}
QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideoframeconversionhelper_avx2.cpp b/src/multimedia/video/qvideoframeconversionhelper_avx2.cpp
index 4df08f162..6802cca74 100644
--- a/src/multimedia/video/qvideoframeconversionhelper_avx2.cpp
+++ b/src/multimedia/video/qvideoframeconversionhelper_avx2.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qvideoframeconversionhelper_p.h"
@@ -43,29 +7,51 @@
QT_BEGIN_NAMESPACE
-void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_avx2(const QVideoFrame &frame, uchar *output)
+namespace {
+
+template<int a, int r, int g, int b>
+void convert_to_ARGB32_avx2(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_PACKED(frame)
MERGE_LOOPS(width, height, stride, 4)
quint32 *argb = reinterpret_cast<quint32*>(output);
- const __m256i shuffleMask = _mm256_set_epi8(12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3,
- 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3);
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ __m256i shuffleMask = _mm256_set_epi8(12 + a, 12 + r, 12 + g, 12 + b,
+ 8 + a, 8 + r, 8 + g, 8 + b,
+ 4 + a, 4 + r, 4 + g, 4 + b,
+ 0 + a, 0 + r, 0 + g, 0 + b,
+ 12 + a, 12 + r, 12 + g, 12 + b,
+ 8 + a, 8 + r, 8 + g, 8 + b,
+ 4 + a, 4 + r, 4 + g, 4 + b,
+ 0 + a, 0 + r, 0 + g, 0 + b);
+#else
+ __m256i shuffleMask = _mm256_set_epi8(15 - a, 15 - r, 15 - g, 15 - b,
+ 11 - a, 11 - r, 11 - g, 11 - b,
+ 7 - a, 7 - r, 7 - g, 7 - b,
+ 3 - a, 3 - r, 3 - g, 3 - b,
+ 15 - a, 15 - r, 15 - g, 15 - b,
+ 11 - a, 11 - r, 11 - g, 11 - b,
+ 7 - a, 7 - r, 7 - g, 7 - b,
+ 3 - a, 3 - r, 3 - g, 3 - b);
+#endif
+
+ using Pixel = const ArgbPixel<a, r, g, b>;
for (int y = 0; y < height; ++y) {
- const quint32 *bgra = reinterpret_cast<const quint32*>(src);
+ auto *pixel = reinterpret_cast<const Pixel *>(src);
int x = 0;
- ALIGN(32, argb, x, width) {
- *argb = qConvertBGRA32ToARGB32(*bgra);
- ++bgra;
+ QT_MEDIA_ALIGN(32, argb, x, width) {
+ *argb = pixel->convert();
+ ++pixel;
++argb;
}
for (; x < width - 15; x += 16) {
- __m256i pixelData = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(bgra));
- __m256i pixelData2 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(bgra + 8));
- bgra += 16;
+ __m256i pixelData = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(pixel));
+ __m256i pixelData2 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(pixel + 8));
+ pixel += 16;
pixelData = _mm256_shuffle_epi8(pixelData, shuffleMask);
pixelData2 = _mm256_shuffle_epi8(pixelData2, shuffleMask);
_mm256_store_si256(reinterpret_cast<__m256i*>(argb), pixelData);
@@ -75,8 +61,8 @@ void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_avx2(const QVideoFrame &frame, ucha
// leftovers
for (; x < width; ++x) {
- *argb = qConvertBGRA32ToARGB32(*bgra);
- ++bgra;
+ *argb = pixel->convert();
+ ++pixel;
++argb;
}
@@ -84,6 +70,66 @@ void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_avx2(const QVideoFrame &frame, ucha
}
}
+}
+
+
+void QT_FASTCALL qt_convert_ARGB8888_to_ARGB32_avx2(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_avx2<0, 1, 2, 3>(frame, output);
+}
+
+void QT_FASTCALL qt_convert_ABGR8888_to_ARGB32_avx2(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_avx2<0, 3, 2, 1>(frame, output);
+}
+
+void QT_FASTCALL qt_convert_RGBA8888_to_ARGB32_avx2(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_avx2<3, 0, 1, 2>(frame, output);
+}
+
+void QT_FASTCALL qt_convert_BGRA8888_to_ARGB32_avx2(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_avx2<3, 2, 1, 0>(frame, output);
+}
+
+void QT_FASTCALL qt_copy_pixels_with_mask_avx2(uint32_t *dst, const uint32_t *src, size_t size, uint32_t mask)
+{
+ const auto mask256 = _mm256_set_epi32(mask, mask, mask, mask, mask, mask, mask, mask);
+
+ size_t x = 0;
+
+ QT_MEDIA_ALIGN(32, dst, x, size)
+ *(dst++) = *(src++) | mask;
+
+ for (; x < size - (8 * 4 + 1); x += 8 * 4) {
+ const auto srcData1 = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src));
+ const auto srcData2 = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src += 8));
+ const auto srcData3 = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src += 8));
+ const auto srcData4 = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src += 8));
+
+ _mm256_store_si256(reinterpret_cast<__m256i *>(dst), _mm256_or_si256(srcData1, mask256));
+ _mm256_store_si256(reinterpret_cast<__m256i *>(dst += 8), _mm256_or_si256(srcData2, mask256));
+ _mm256_store_si256(reinterpret_cast<__m256i *>(dst += 8), _mm256_or_si256(srcData3, mask256));
+ _mm256_store_si256(reinterpret_cast<__m256i *>(dst += 8), _mm256_or_si256(srcData4, mask256));
+
+ src += 8;
+ dst += 8;
+ }
+
+ // leftovers
+ for (; x < size - 7; x += 8) {
+ const auto srcData = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src));
+ _mm256_store_si256(reinterpret_cast<__m256i *>(dst), _mm256_or_si256(srcData, mask256));
+
+ src += 8;
+ dst += 8;
+ }
+
+ for (; x < size; ++x)
+ *(dst++) = *(src++) | mask;
+}
+
QT_END_NAMESPACE
#endif
diff --git a/src/multimedia/video/qvideoframeconversionhelper_p.h b/src/multimedia/video/qvideoframeconversionhelper_p.h
index b7837db2a..17490a817 100644
--- a/src/multimedia/video/qvideoframeconversionhelper_p.h
+++ b/src/multimedia/video/qvideoframeconversionhelper_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QVIDEOFRAMECONVERSIONHELPER_P_H
#define QVIDEOFRAMECONVERSIONHELPER_P_H
@@ -54,40 +18,93 @@
#include <qvideoframe.h>
#include <private/qsimd_p.h>
+QT_BEGIN_NAMESPACE
+
+// Converts to RGB32 or ARGB32_Premultiplied
typedef void (QT_FASTCALL *VideoFrameConvertFunc)(const QVideoFrame &frame, uchar *output);
+typedef void(QT_FASTCALL *PixelsCopyFunc)(uint32_t *dst, const uint32_t *src, size_t size, uint32_t mask);
-inline quint32 qConvertBGRA32ToARGB32(quint32 bgra)
-{
- return (((bgra & 0xFF000000) >> 24)
- | ((bgra & 0x00FF0000) >> 8)
- | ((bgra & 0x0000FF00) << 8)
- | ((bgra & 0x000000FF) << 24));
-}
+VideoFrameConvertFunc qConverterForFormat(QVideoFrameFormat::PixelFormat format);
+
+void Q_MULTIMEDIA_EXPORT qCopyPixelsWithAlphaMask(uint32_t *dst,
+ const uint32_t *src,
+ size_t size,
+ QVideoFrameFormat::PixelFormat format,
+ bool srcAlphaVaries);
-inline quint32 qConvertBGR24ToARGB32(const uchar *bgr)
+void Q_MULTIMEDIA_EXPORT qCopyPixelsWithMask(uint32_t *dst, const uint32_t *src, size_t size, uint32_t mask);
+
+uint32_t Q_MULTIMEDIA_EXPORT qAlphaMask(QVideoFrameFormat::PixelFormat format);
+
+template<int a, int r, int g, int b>
+struct ArgbPixel
{
- return 0xFF000000 | bgr[0] | bgr[1] << 8 | bgr[2] << 16;
-}
+ quint32 data;
+ inline quint32 convert() const
+ {
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ return (((data >> (8*a)) & 0xff) << 24)
+ | (((data >> (8*r)) & 0xff) << 16)
+ | (((data >> (8*g)) & 0xff) << 8)
+ | ((data >> (8*b)) & 0xff);
+#else
+ return (((data >> (32-8*a)) & 0xff) << 24)
+ | (((data >> (32-8*r)) & 0xff) << 16)
+ | (((data >> (32-8*g)) & 0xff) << 8)
+ | ((data >> (32-8*b)) & 0xff);
+#endif
+ }
+};
-inline quint32 qConvertBGR565ToARGB32(quint16 bgr)
+template<int r, int g, int b>
+struct RgbPixel
{
- return 0xff000000
- | ((((bgr) >> 8) & 0xf8) | (((bgr) >> 13) & 0x7))
- | ((((bgr) << 5) & 0xfc00) | (((bgr) >> 1) & 0x300))
- | ((((bgr) << 19) & 0xf80000) | (((bgr) << 14) & 0x70000));
-}
+ quint32 data;
+ inline quint32 convert() const
+ {
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ return 0xff000000
+ | (((data >> (8*r)) & 0xff) << 16)
+ | (((data >> (8*g)) & 0xff) << 8)
+ | ((data >> (8*b)) & 0xff);
+#else
+ return 0xff000000
+ | (((data >> (32-8*r)) & 0xff) << 16)
+ | (((data >> (32-8*g)) & 0xff) << 8)
+ | ((data >> (32-8*b)) & 0xff);
+#endif
+ }
+};
-inline quint32 qConvertBGR555ToARGB32(quint16 bgr)
+template<typename Y>
+struct YPixel
{
- return 0xff000000
- | ((((bgr) >> 7) & 0xf8) | (((bgr) >> 12) & 0x7))
- | ((((bgr) << 6) & 0xf800) | (((bgr) << 1) & 0x700))
- | ((((bgr) << 19) & 0xf80000) | (((bgr) << 11) & 0x70000));
-}
+ Y data;
+ static constexpr uint shift = (sizeof(Y) - 1)*8;
+ inline quint32 convert() const
+ {
+ uint y = (data >> shift) & 0xff;
+ return (0xff000000)
+ | (y << 16)
+ | (y << 8)
+ | (y);
+ }
+
+};
+
+
+using ARGB8888 = ArgbPixel<0, 1, 2, 3>;
+using ABGR8888 = ArgbPixel<0, 3, 2, 1>;
+using RGBA8888 = ArgbPixel<3, 0, 1, 2>;
+using BGRA8888 = ArgbPixel<3, 2, 1, 0>;
+using XRGB8888 = RgbPixel<1, 2, 3>;
+using XBGR8888 = RgbPixel<3, 2, 1>;
+using RGBX8888 = RgbPixel<0, 1, 2>;
+using BGRX8888 = RgbPixel<2, 1, 0>;
#define FETCH_INFO_PACKED(frame) \
- const uchar *src = frame.bits(); \
- int stride = frame.bytesPerLine(); \
+ const uchar *src = frame.bits(0); \
+ int stride = frame.bytesPerLine(0); \
int width = frame.width(); \
int height = frame.height();
@@ -116,8 +133,10 @@ inline quint32 qConvertBGR555ToARGB32(quint16 bgr)
stride = 0; \
}
-#define ALIGN(boundary, ptr, x, length) \
+#define QT_MEDIA_ALIGN(boundary, ptr, x, length) \
for (; ((reinterpret_cast<qintptr>(ptr) & (boundary - 1)) != 0) && x < length; ++x)
+QT_END_NAMESPACE
+
#endif // QVIDEOFRAMECONVERSIONHELPER_P_H
diff --git a/src/multimedia/video/qvideoframeconversionhelper_sse2.cpp b/src/multimedia/video/qvideoframeconversionhelper_sse2.cpp
index 50e12c07b..b7049d806 100644
--- a/src/multimedia/video/qvideoframeconversionhelper_sse2.cpp
+++ b/src/multimedia/video/qvideoframeconversionhelper_sse2.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qvideoframeconversionhelper_p.h"
@@ -43,40 +7,50 @@
QT_BEGIN_NAMESPACE
-void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_sse2(const QVideoFrame &frame, uchar *output)
+namespace {
+
+template<int a, int r, int b, int g>
+void convert_to_ARGB32_sse2(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_PACKED(frame)
MERGE_LOOPS(width, height, stride, 4)
quint32 *argb = reinterpret_cast<quint32*>(output);
const __m128i zero = _mm_setzero_si128();
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ const uchar shuffle = _MM_SHUFFLE(a, r, b, g);
+#else
+ const uchar shuffle = _MM_SHUFFLE(3-a, 3-r, 3-b, 3-g);
+#endif
+
+ using Pixel = const ArgbPixel<a, r, g, b>;
for (int y = 0; y < height; ++y) {
- const quint32 *bgra = reinterpret_cast<const quint32*>(src);
+ auto *pixel = reinterpret_cast<const Pixel *>(src);
int x = 0;
- ALIGN(16, argb, x, width) {
- *argb = qConvertBGRA32ToARGB32(*bgra);
- ++bgra;
+ QT_MEDIA_ALIGN(16, argb, x, width) {
+ *argb = pixel->convert();
+ ++pixel;
++argb;
}
for (; x < width - 3; x += 4) {
- __m128i pixelData = _mm_loadu_si128(reinterpret_cast<const __m128i*>(bgra));
- bgra += 4;
- __m128i gaComponents = _mm_unpacklo_epi8(pixelData, zero);
- __m128i brComponents = _mm_unpackhi_epi8(pixelData, zero);
- gaComponents = _mm_shufflelo_epi16(_mm_shufflehi_epi16(gaComponents, _MM_SHUFFLE(0, 1, 2, 3)), _MM_SHUFFLE(0, 1, 2, 3)); // swap GA
- brComponents = _mm_shufflelo_epi16(_mm_shufflehi_epi16(brComponents, _MM_SHUFFLE(0, 1, 2, 3)), _MM_SHUFFLE(0, 1, 2, 3)); // swap BR
- pixelData = _mm_packus_epi16(gaComponents, brComponents);
+ __m128i pixelData = _mm_loadu_si128(reinterpret_cast<const __m128i*>(pixel));
+ pixel += 4;
+ __m128i lowPixels = _mm_unpacklo_epi8(pixelData, zero);
+ __m128i highPixels = _mm_unpackhi_epi8(pixelData, zero);
+ lowPixels = _mm_shufflelo_epi16(_mm_shufflehi_epi16(lowPixels, shuffle), shuffle);
+ highPixels = _mm_shufflelo_epi16(_mm_shufflehi_epi16(highPixels, shuffle), shuffle);
+ pixelData = _mm_packus_epi16(lowPixels, highPixels);
_mm_store_si128(reinterpret_cast<__m128i*>(argb), pixelData);
argb += 4;
}
// leftovers
for (; x < width; ++x) {
- *argb = qConvertBGRA32ToARGB32(*bgra);
- ++bgra;
+ *argb = pixel->convert();
+ ++pixel;
++argb;
}
@@ -84,6 +58,66 @@ void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_sse2(const QVideoFrame &frame, ucha
}
}
+}
+
+void QT_FASTCALL qt_convert_ARGB8888_to_ARGB32_sse2(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_sse2<0, 1, 2, 3>(frame, output);
+}
+
+void QT_FASTCALL qt_convert_ABGR8888_to_ARGB32_sse2(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_sse2<0, 3, 2, 1>(frame, output);
+}
+
+void QT_FASTCALL qt_convert_RGBA8888_to_ARGB32_sse2(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_sse2<3, 0, 1, 2>(frame, output);
+}
+
+void QT_FASTCALL qt_convert_BGRA8888_to_ARGB32_sse2(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_sse2<3, 2, 1, 0>(frame, output);
+}
+
+void QT_FASTCALL qt_copy_pixels_with_mask_sse2(uint32_t *dst, const uint32_t *src, size_t size, uint32_t mask)
+{
+ const auto mask128 = _mm_set_epi32(mask, mask, mask, mask);
+
+ size_t x = 0;
+
+ QT_MEDIA_ALIGN(16, dst, x, size)
+ *(dst++) = *(src++) | mask;
+
+ for (; x < size - (4 * 4 - 1); x += 4 * 4) {
+ const auto srcData0 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(src));
+ const auto srcData1 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(src += 4));
+ const auto srcData2 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(src += 4));
+ const auto srcData3 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(src += 4));
+
+ _mm_store_si128(reinterpret_cast<__m128i *>(dst), _mm_or_si128(srcData0, mask128));
+ _mm_store_si128(reinterpret_cast<__m128i *>(dst += 4), _mm_or_si128(srcData1, mask128));
+ _mm_store_si128(reinterpret_cast<__m128i *>(dst += 4), _mm_or_si128(srcData2, mask128));
+ _mm_store_si128(reinterpret_cast<__m128i *>(dst += 4), _mm_or_si128(srcData3, mask128));
+
+ src += 4;
+ dst += 4;
+ }
+
+ for (; x < size - 3; x += 4) {
+ const auto srcData = _mm_loadu_si128(reinterpret_cast<const __m128i *>(src));
+
+ _mm_store_si128(reinterpret_cast<__m128i *>(dst), _mm_or_si128(srcData, mask128));
+
+ src += 4;
+ dst += 4;
+ }
+
+ // leftovers
+ for (; x < size; ++x)
+ *(dst++) = *(src++) | mask;
+}
+
QT_END_NAMESPACE
#endif
diff --git a/src/multimedia/video/qvideoframeconversionhelper_ssse3.cpp b/src/multimedia/video/qvideoframeconversionhelper_ssse3.cpp
index 1e87c8e5c..10a244fb0 100644
--- a/src/multimedia/video/qvideoframeconversionhelper_ssse3.cpp
+++ b/src/multimedia/video/qvideoframeconversionhelper_ssse3.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qvideoframeconversionhelper_p.h"
@@ -43,28 +7,43 @@
QT_BEGIN_NAMESPACE
-void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_ssse3(const QVideoFrame &frame, uchar *output)
+namespace {
+
+template<int a, int r, int g, int b>
+void convert_to_ARGB32_ssse3(const QVideoFrame &frame, uchar *output)
{
FETCH_INFO_PACKED(frame)
MERGE_LOOPS(width, height, stride, 4)
quint32 *argb = reinterpret_cast<quint32*>(output);
- __m128i shuffleMask = _mm_set_epi8(12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3);
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ __m128i shuffleMask = _mm_set_epi8(12 + a, 12 + r, 12 + g, 12 + b,
+ 8 + a, 8 + r, 8 + g, 8 + b,
+ 4 + a, 4 + r, 4 + g, 4 + b,
+ 0 + a, 0 + r, 0 + g, 0 + b);
+#else
+ __m128i shuffleMask = _mm_set_epi8(15 - a, 15 - r, 15 - g, 15 - b,
+ 11 - a, 11 - r, 11 - g, 11 - b,
+ 7 - a, 7 - r, 7 - g, 7 - b,
+ 3 - a, 3 - r, 3 - g, 3 - b);
+#endif
+
+ using Pixel = const ArgbPixel<a, r, g, b>;
for (int y = 0; y < height; ++y) {
- const quint32 *bgra = reinterpret_cast<const quint32*>(src);
+ const auto *pixel = reinterpret_cast<const Pixel *>(src);
int x = 0;
- ALIGN(16, argb, x, width) {
- *argb = qConvertBGRA32ToARGB32(*bgra);
- ++bgra;
+ QT_MEDIA_ALIGN(16, argb, x, width) {
+ *argb = pixel->convert();
+ ++pixel;
++argb;
}
for (; x < width - 7; x += 8) {
- __m128i pixelData = _mm_loadu_si128(reinterpret_cast<const __m128i*>(bgra));
- __m128i pixelData2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(bgra + 4));
- bgra += 8;
+ __m128i pixelData = _mm_loadu_si128(reinterpret_cast<const __m128i*>(pixel));
+ __m128i pixelData2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(pixel + 4));
+ pixel += 8;
pixelData = _mm_shuffle_epi8(pixelData, shuffleMask);
pixelData2 = _mm_shuffle_epi8(pixelData2, shuffleMask);
_mm_store_si128(reinterpret_cast<__m128i*>(argb), pixelData);
@@ -74,8 +53,8 @@ void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_ssse3(const QVideoFrame &frame, uch
// leftovers
for (; x < width; ++x) {
- *argb = qConvertBGRA32ToARGB32(*bgra);
- ++bgra;
+ *argb = pixel->convert();
+ ++pixel;
++argb;
}
@@ -83,6 +62,28 @@ void QT_FASTCALL qt_convert_BGRA32_to_ARGB32_ssse3(const QVideoFrame &frame, uch
}
}
+}
+
+void QT_FASTCALL qt_convert_ARGB8888_to_ARGB32_ssse3(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_ssse3<0, 1, 2, 3>(frame, output);
+}
+
+void QT_FASTCALL qt_convert_ABGR8888_to_ARGB32_ssse3(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_ssse3<0, 3, 2, 1>(frame, output);
+}
+
+void QT_FASTCALL qt_convert_RGBA8888_to_ARGB32_ssse3(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_ssse3<3, 0, 1, 2>(frame, output);
+}
+
+void QT_FASTCALL qt_convert_BGRA8888_to_ARGB32_ssse3(const QVideoFrame &frame, uchar *output)
+{
+ convert_to_ARGB32_ssse3<3, 2, 1, 0>(frame, output);
+}
+
QT_END_NAMESPACE
#endif
diff --git a/src/multimedia/video/qvideoframeconverter.cpp b/src/multimedia/video/qvideoframeconverter.cpp
new file mode 100644
index 000000000..d406aa342
--- /dev/null
+++ b/src/multimedia/video/qvideoframeconverter.cpp
@@ -0,0 +1,462 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qvideoframeconverter_p.h"
+#include "qvideoframeconversionhelper_p.h"
+#include "qvideoframeformat.h"
+#include "qvideoframe_p.h"
+#include "qmultimediautils_p.h"
+#include "qabstractvideobuffer.h"
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qsize.h>
+#include <QtCore/qhash.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qthreadstorage.h>
+#include <QtGui/qimage.h>
+#include <QtGui/qoffscreensurface.h>
+#include <qpa/qplatformintegration.h>
+#include <private/qvideotexturehelper_p.h>
+#include <private/qguiapplication_p.h>
+#include <rhi/qrhi.h>
+
+#ifdef Q_OS_DARWIN
+#include <QtCore/private/qcore_mac_p.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcVideoFrameConverter, "qt.multimedia.video.frameconverter")
+
+namespace {
+
+struct State
+{
+ QRhi *rhi = nullptr;
+#if QT_CONFIG(opengl)
+ QOffscreenSurface *fallbackSurface = nullptr;
+#endif
+ bool cpuOnly = false;
+#if defined(Q_OS_ANDROID)
+ QMetaObject::Connection appStateChangedConnection;
+#endif
+ ~State() {
+ resetRhi();
+ }
+
+ void resetRhi() {
+ delete rhi;
+ rhi = nullptr;
+#if QT_CONFIG(opengl)
+ delete fallbackSurface;
+ fallbackSurface = nullptr;
+#endif
+ cpuOnly = false;
+ }
+};
+
+}
+
+static QThreadStorage<State> g_state;
+static QHash<QString, QShader> g_shaderCache;
+
+static const float g_quad[] = {
+ // Rotation 0 CW
+ 1.f, -1.f, 1.f, 1.f,
+ 1.f, 1.f, 1.f, 0.f,
+ -1.f, -1.f, 0.f, 1.f,
+ -1.f, 1.f, 0.f, 0.f,
+ // Rotation 90 CW
+ 1.f, -1.f, 1.f, 0.f,
+ 1.f, 1.f, 0.f, 0.f,
+ -1.f, -1.f, 1.f, 1.f,
+ -1.f, 1.f, 0.f, 1.f,
+ // Rotation 180 CW
+ 1.f, -1.f, 0.f, 0.f,
+ 1.f, 1.f, 0.f, 1.f,
+ -1.f, -1.f, 1.f, 0.f,
+ -1.f, 1.f, 1.f, 1.f,
+ // Rotation 270 CW
+ 1.f, -1.f, 0.f, 1.f,
+ 1.f, 1.f, 1.f, 1.f,
+ -1.f, -1.f, 0.f, 0.f,
+ -1.f, 1.f, 1.f, 0.f,
+};
+
+static bool pixelFormatHasAlpha(QVideoFrameFormat::PixelFormat format)
+{
+ switch (format) {
+ case QVideoFrameFormat::Format_ARGB8888:
+ case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
+ case QVideoFrameFormat::Format_BGRA8888:
+ case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
+ case QVideoFrameFormat::Format_ABGR8888:
+ case QVideoFrameFormat::Format_RGBA8888:
+ case QVideoFrameFormat::Format_AYUV:
+ case QVideoFrameFormat::Format_AYUV_Premultiplied:
+ return true;
+ default:
+ return false;
+ }
+};
+
+static QShader vfcGetShader(const QString &name)
+{
+ QShader shader = g_shaderCache.value(name);
+ if (shader.isValid())
+ return shader;
+
+ QFile f(name);
+ if (f.open(QIODevice::ReadOnly))
+ shader = QShader::fromSerialized(f.readAll());
+
+ if (shader.isValid())
+ g_shaderCache[name] = shader;
+
+ return shader;
+}
+
+static void rasterTransform(QImage &image, QtVideo::Rotation rotation,
+ bool mirrorX, bool mirrorY)
+{
+ QTransform t;
+ if (mirrorX)
+ t.scale(-1.f, 1.f);
+ if (rotation != QtVideo::Rotation::None)
+ t.rotate(float(rotation));
+ if (mirrorY)
+ t.scale(1.f, -1.f);
+ if (!t.isIdentity())
+ image = image.transformed(t);
+}
+
+static void imageCleanupHandler(void *info)
+{
+ QByteArray *imageData = reinterpret_cast<QByteArray *>(info);
+ delete imageData;
+}
+
+static QRhi *initializeRHI(QRhi *videoFrameRhi)
+{
+ if (g_state.localData().rhi || g_state.localData().cpuOnly)
+ return g_state.localData().rhi;
+
+ QRhi::Implementation backend = videoFrameRhi ? videoFrameRhi->backend() : QRhi::Null;
+
+ if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RhiBasedRendering)) {
+
+#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
+ if (backend == QRhi::Metal || backend == QRhi::Null) {
+ QRhiMetalInitParams params;
+ g_state.localData().rhi = QRhi::create(QRhi::Metal, &params);
+ }
+#endif
+
+#if defined(Q_OS_WIN)
+ if (backend == QRhi::D3D11 || backend == QRhi::Null) {
+ QRhiD3D11InitParams params;
+ g_state.localData().rhi = QRhi::create(QRhi::D3D11, &params);
+ }
+#endif
+
+#if QT_CONFIG(opengl)
+ if (!g_state.localData().rhi && (backend == QRhi::OpenGLES2 || backend == QRhi::Null)) {
+ if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)
+ && QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RasterGLSurface)
+ && !QCoreApplication::testAttribute(Qt::AA_ForceRasterWidgets)) {
+
+ g_state.localData().fallbackSurface = QRhiGles2InitParams::newFallbackSurface();
+ QRhiGles2InitParams params;
+ params.fallbackSurface = g_state.localData().fallbackSurface;
+ if (backend == QRhi::OpenGLES2)
+ params.shareContext = static_cast<const QRhiGles2NativeHandles*>(videoFrameRhi->nativeHandles())->context;
+ g_state.localData().rhi = QRhi::create(QRhi::OpenGLES2, &params);
+
+#if defined(Q_OS_ANDROID)
+ // reset RHI state on application suspension, as this will be invalid after resuming
+ if (!g_state.localData().appStateChangedConnection) {
+ g_state.localData().appStateChangedConnection = QObject::connect(qApp, &QGuiApplication::applicationStateChanged, qApp, [](auto state) {
+ if (state == Qt::ApplicationSuspended)
+ g_state.localData().resetRhi();
+ });
+ }
+#endif
+ }
+ }
+#endif
+ }
+
+ if (!g_state.localData().rhi) {
+ g_state.localData().cpuOnly = true;
+ qWarning() << Q_FUNC_INFO << ": No RHI backend. Using CPU conversion.";
+ }
+
+ return g_state.localData().rhi;
+}
+
+static bool updateTextures(QRhi *rhi,
+ std::unique_ptr<QRhiBuffer> &uniformBuffer,
+ std::unique_ptr<QRhiSampler> &textureSampler,
+ std::unique_ptr<QRhiShaderResourceBindings> &shaderResourceBindings,
+ std::unique_ptr<QRhiGraphicsPipeline> &graphicsPipeline,
+ std::unique_ptr<QRhiRenderPassDescriptor> &renderPass,
+ QVideoFrame &frame,
+ const std::unique_ptr<QVideoFrameTextures> &videoFrameTextures)
+{
+ auto format = frame.surfaceFormat();
+ auto pixelFormat = format.pixelFormat();
+
+ auto textureDesc = QVideoTextureHelper::textureDescription(pixelFormat);
+
+ QRhiShaderResourceBinding bindings[4];
+ auto *b = bindings;
+ *b++ = QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage,
+ uniformBuffer.get());
+ for (int i = 0; i < textureDesc->nplanes; ++i)
+ *b++ = QRhiShaderResourceBinding::sampledTexture(i + 1, QRhiShaderResourceBinding::FragmentStage,
+ videoFrameTextures->texture(i), textureSampler.get());
+ shaderResourceBindings->setBindings(bindings, b);
+ shaderResourceBindings->create();
+
+ graphicsPipeline.reset(rhi->newGraphicsPipeline());
+ graphicsPipeline->setTopology(QRhiGraphicsPipeline::TriangleStrip);
+
+ QShader vs = vfcGetShader(QVideoTextureHelper::vertexShaderFileName(format));
+ if (!vs.isValid())
+ return false;
+
+ QShader fs = vfcGetShader(QVideoTextureHelper::fragmentShaderFileName(format));
+ if (!fs.isValid())
+ return false;
+
+ graphicsPipeline->setShaderStages({
+ { QRhiShaderStage::Vertex, vs },
+ { QRhiShaderStage::Fragment, fs }
+ });
+
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({
+ { 4 * sizeof(float) }
+ });
+ inputLayout.setAttributes({
+ { 0, 0, QRhiVertexInputAttribute::Float2, 0 },
+ { 0, 1, QRhiVertexInputAttribute::Float2, 2 * sizeof(float) }
+ });
+
+ graphicsPipeline->setVertexInputLayout(inputLayout);
+ graphicsPipeline->setShaderResourceBindings(shaderResourceBindings.get());
+ graphicsPipeline->setRenderPassDescriptor(renderPass.get());
+ graphicsPipeline->create();
+
+ return true;
+}
+
+static QImage convertJPEG(const QVideoFrame &frame, QtVideo::Rotation rotation, bool mirrorX, bool mirrorY)
+{
+ QVideoFrame varFrame = frame;
+ if (!varFrame.map(QtVideo::MapMode::ReadOnly)) {
+ qCDebug(qLcVideoFrameConverter) << Q_FUNC_INFO << ": frame mapping failed";
+ return {};
+ }
+ QImage image;
+ image.loadFromData(varFrame.bits(0), varFrame.mappedBytes(0), "JPG");
+ varFrame.unmap();
+ rasterTransform(image, rotation, mirrorX, mirrorY);
+ return image;
+}
+
+static QImage convertCPU(const QVideoFrame &frame, QtVideo::Rotation rotation, bool mirrorX, bool mirrorY)
+{
+ VideoFrameConvertFunc convert = qConverterForFormat(frame.pixelFormat());
+ if (!convert) {
+ qCDebug(qLcVideoFrameConverter) << Q_FUNC_INFO << ": unsupported pixel format" << frame.pixelFormat();
+ return {};
+ } else {
+ QVideoFrame varFrame = frame;
+ if (!varFrame.map(QtVideo::MapMode::ReadOnly)) {
+ qCDebug(qLcVideoFrameConverter) << Q_FUNC_INFO << ": frame mapping failed";
+ return {};
+ }
+ auto format = pixelFormatHasAlpha(varFrame.pixelFormat()) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
+ QImage image = QImage(varFrame.width(), varFrame.height(), format);
+ convert(varFrame, image.bits());
+ varFrame.unmap();
+ rasterTransform(image, rotation, mirrorX, mirrorY);
+ return image;
+ }
+}
+
+QImage qImageFromVideoFrame(const QVideoFrame &frame, QtVideo::Rotation rotation, bool mirrorX,
+ bool mirrorY, bool forceCpu)
+{
+#ifdef Q_OS_DARWIN
+ QMacAutoReleasePool releasePool;
+#endif
+
+ if (!g_state.hasLocalData())
+ g_state.setLocalData({});
+
+ std::unique_ptr<QRhiRenderPassDescriptor> renderPass;
+ std::unique_ptr<QRhiBuffer> vertexBuffer;
+ std::unique_ptr<QRhiBuffer> uniformBuffer;
+ std::unique_ptr<QRhiTexture> targetTexture;
+ std::unique_ptr<QRhiTextureRenderTarget> renderTarget;
+ std::unique_ptr<QRhiSampler> textureSampler;
+ std::unique_ptr<QRhiShaderResourceBindings> shaderResourceBindings;
+ std::unique_ptr<QRhiGraphicsPipeline> graphicsPipeline;
+
+ if (frame.size().isEmpty() || frame.pixelFormat() == QVideoFrameFormat::Format_Invalid)
+ return {};
+
+ if (frame.pixelFormat() == QVideoFrameFormat::Format_Jpeg)
+ return convertJPEG(frame, rotation, mirrorX, mirrorY);
+
+ if (forceCpu) // For test purposes
+ return convertCPU(frame, rotation, mirrorX, mirrorY);
+
+ QRhi *rhi = nullptr;
+
+ if (QHwVideoBuffer *buffer = QVideoFramePrivate::hwBuffer(frame))
+ rhi = buffer->rhi();
+
+ if (!rhi || rhi->thread() != QThread::currentThread())
+ rhi = initializeRHI(rhi);
+
+ if (!rhi || rhi->isRecordingFrame())
+ return convertCPU(frame, rotation, mirrorX, mirrorY);
+
+ // Do conversion using shaders
+
+ const QSize frameSize = qRotatedFrameSize(frame.size(), rotation);
+
+ vertexBuffer.reset(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(g_quad)));
+ vertexBuffer->create();
+
+ uniformBuffer.reset(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64 + 64 + 4 + 4 + 4 + 4));
+ uniformBuffer->create();
+
+ textureSampler.reset(rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
+ QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge));
+ textureSampler->create();
+
+ shaderResourceBindings.reset(rhi->newShaderResourceBindings());
+
+ targetTexture.reset(rhi->newTexture(QRhiTexture::RGBA8, frameSize, 1, QRhiTexture::RenderTarget));
+ if (!targetTexture->create()) {
+ qCDebug(qLcVideoFrameConverter) << "Failed to create target texture. Using CPU conversion.";
+ return convertCPU(frame, rotation, mirrorX, mirrorY);
+ }
+
+ renderTarget.reset(rhi->newTextureRenderTarget({ { targetTexture.get() } }));
+ renderPass.reset(renderTarget->newCompatibleRenderPassDescriptor());
+ renderTarget->setRenderPassDescriptor(renderPass.get());
+ renderTarget->create();
+
+ QRhiCommandBuffer *cb = nullptr;
+ QRhi::FrameOpResult r = rhi->beginOffscreenFrame(&cb);
+ if (r != QRhi::FrameOpSuccess) {
+ qCDebug(qLcVideoFrameConverter) << "Failed to set up offscreen frame. Using CPU conversion.";
+ return convertCPU(frame, rotation, mirrorX, mirrorY);
+ }
+
+ QRhiResourceUpdateBatch *rub = rhi->nextResourceUpdateBatch();
+
+ rub->uploadStaticBuffer(vertexBuffer.get(), g_quad);
+
+ QVideoFrame frameTmp = frame;
+ auto videoFrameTextures = QVideoTextureHelper::createTextures(frameTmp, rhi, rub, {});
+ if (!videoFrameTextures) {
+ qCDebug(qLcVideoFrameConverter) << "Failed obtain textures. Using CPU conversion.";
+ return convertCPU(frame, rotation, mirrorX, mirrorY);
+ }
+
+ if (!updateTextures(rhi, uniformBuffer, textureSampler, shaderResourceBindings,
+ graphicsPipeline, renderPass, frameTmp, videoFrameTextures)) {
+ qCDebug(qLcVideoFrameConverter) << "Failed to update textures. Using CPU conversion.";
+ return convertCPU(frame, rotation, mirrorX, mirrorY);
+ }
+
+ float xScale = mirrorX ? -1.0 : 1.0;
+ float yScale = mirrorY ? -1.0 : 1.0;
+
+ if (rhi->isYUpInFramebuffer())
+ yScale = -yScale;
+
+ QMatrix4x4 transform;
+ transform.scale(xScale, yScale);
+
+ QByteArray uniformData(64 + 64 + 4 + 4, Qt::Uninitialized);
+ QVideoTextureHelper::updateUniformData(&uniformData, frame.surfaceFormat(), frame, transform, 1.f);
+ rub->updateDynamicBuffer(uniformBuffer.get(), 0, uniformData.size(), uniformData.constData());
+
+ cb->beginPass(renderTarget.get(), Qt::black, { 1.0f, 0 }, rub);
+ cb->setGraphicsPipeline(graphicsPipeline.get());
+
+ cb->setViewport({ 0, 0, float(frameSize.width()), float(frameSize.height()) });
+ cb->setShaderResources(shaderResourceBindings.get());
+
+ const int rotationIndex = (qToUnderlying(rotation) / 90) % 4;
+ const quint32 vertexOffset = quint32(sizeof(float)) * 16 * rotationIndex;
+ const QRhiCommandBuffer::VertexInput vbufBinding(vertexBuffer.get(), vertexOffset);
+ cb->setVertexInput(0, 1, &vbufBinding);
+ cb->draw(4);
+
+ QRhiReadbackDescription readDesc(targetTexture.get());
+ QRhiReadbackResult readResult;
+ bool readCompleted = false;
+
+ readResult.completed = [&readCompleted] { readCompleted = true; };
+
+ rub = rhi->nextResourceUpdateBatch();
+ rub->readBackTexture(readDesc, &readResult);
+
+ cb->endPass(rub);
+
+ rhi->endOffscreenFrame();
+
+ if (!readCompleted) {
+ qCDebug(qLcVideoFrameConverter) << "Failed to read back texture. Using CPU conversion.";
+ return convertCPU(frame, rotation, mirrorX, mirrorY);
+ }
+
+ QByteArray *imageData = new QByteArray(readResult.data);
+
+ return QImage(reinterpret_cast<const uchar *>(imageData->constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888_Premultiplied, imageCleanupHandler, imageData);
+}
+
+QImage videoFramePlaneAsImage(QVideoFrame &frame, int plane, QImage::Format targetFormat,
+ QSize targetSize)
+{
+ if (plane >= frame.planeCount())
+ return {};
+
+ if (!frame.map(QtVideo::MapMode::ReadOnly)) {
+ qWarning() << "Cannot map a video frame in ReadOnly mode!";
+ return {};
+ }
+
+ auto frameHandle = QVideoFramePrivate::handle(frame);
+
+ // With incrementing the reference counter, we share the mapped QVideoFrame
+ // with the target QImage. The function imageCleanupFunction is going to adopt
+ // the frameHandle by QVideoFrame and dereference it upon the destruction.
+ frameHandle->ref.ref();
+
+ auto imageCleanupFunction = [](void *data) {
+ QVideoFrame frame = reinterpret_cast<QVideoFramePrivate *>(data)->adoptThisByVideoFrame();
+ Q_ASSERT(frame.isMapped());
+ frame.unmap();
+ };
+
+ const auto bytesPerLine = frame.bytesPerLine(plane);
+ const auto height =
+ bytesPerLine ? qMin(targetSize.height(), frame.mappedBytes(plane) / bytesPerLine) : 0;
+
+ return QImage(reinterpret_cast<const uchar *>(frame.bits(plane)), targetSize.width(), height,
+ bytesPerLine, targetFormat, imageCleanupFunction, frameHandle);
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/multimedia/video/qvideoframeconverter_p.h b/src/multimedia/video/qvideoframeconverter_p.h
new file mode 100644
index 000000000..ad6cea9e4
--- /dev/null
+++ b/src/multimedia/video/qvideoframeconverter_p.h
@@ -0,0 +1,36 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QVIDEOFRAMECONVERTER_H
+#define QVIDEOFRAMECONVERTER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qvideoframe.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_MULTIMEDIA_EXPORT QImage
+qImageFromVideoFrame(const QVideoFrame &frame, QtVideo::Rotation rotation = QtVideo::Rotation::None,
+ bool mirrorX = false, bool mirrorY = false, bool forceCpu = false);
+
+/**
+ * @brief Maps the video frame and returns an image having a shared ownership for the video frame
+ * and referencing to its mapped data.
+ */
+Q_MULTIMEDIA_EXPORT QImage videoFramePlaneAsImage(QVideoFrame &frame, int plane,
+ QImage::Format targetFromat, QSize targetSize);
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/multimedia/video/qvideoframeformat.cpp b/src/multimedia/video/qvideoframeformat.cpp
new file mode 100644
index 000000000..b3177234f
--- /dev/null
+++ b/src/multimedia/video/qvideoframeformat.cpp
@@ -0,0 +1,1044 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qvideoframeformat.h"
+#include "qvideotexturehelper_p.h"
+
+#include <qdebug.h>
+#include <qlist.h>
+#include <qmetatype.h>
+#include <qpair.h>
+#include <qvariant.h>
+#include <qmatrix4x4.h>
+
+static void initResource() {
+ Q_INIT_RESOURCE(qtmultimedia_shaders);
+}
+
+QT_BEGIN_NAMESPACE
+
+class QVideoFrameFormatPrivate : public QSharedData
+{
+public:
+ QVideoFrameFormatPrivate() = default;
+
+ QVideoFrameFormatPrivate(
+ const QSize &size,
+ QVideoFrameFormat::PixelFormat format)
+ : pixelFormat(format)
+ , frameSize(size)
+ , viewport(QPoint(0, 0), size)
+ {
+ }
+
+ bool operator ==(const QVideoFrameFormatPrivate &other) const
+ {
+ if (pixelFormat == other.pixelFormat
+ && scanLineDirection == other.scanLineDirection
+ && frameSize == other.frameSize
+ && viewport == other.viewport
+ && frameRatesEqual(frameRate, other.frameRate)
+ && colorSpace == other.colorSpace
+ && mirrored == other.mirrored
+ && rotation == other.rotation)
+ return true;
+
+ return false;
+ }
+
+ inline static bool frameRatesEqual(qreal r1, qreal r2)
+ {
+ return qAbs(r1 - r2) <= 0.00001 * qMin(qAbs(r1), qAbs(r2));
+ }
+
+ QVideoFrameFormat::PixelFormat pixelFormat = QVideoFrameFormat::Format_Invalid;
+ QVideoFrameFormat::Direction scanLineDirection = QVideoFrameFormat::TopToBottom;
+ QSize frameSize;
+ QVideoFrameFormat::ColorSpace colorSpace = QVideoFrameFormat::ColorSpace_Undefined;
+ QVideoFrameFormat::ColorTransfer colorTransfer = QVideoFrameFormat::ColorTransfer_Unknown;
+ QVideoFrameFormat::ColorRange colorRange = QVideoFrameFormat::ColorRange_Unknown;
+ QRect viewport;
+ float frameRate = 0.0;
+ float maxLuminance = -1.;
+ bool mirrored = false;
+ QtVideo::Rotation rotation = QtVideo::Rotation::None;
+};
+
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QVideoFrameFormatPrivate);
+
+/*!
+ \class QVideoFrameFormat
+ \brief The QVideoFrameFormat class specifies the stream format of a video presentation
+ surface.
+ \inmodule QtMultimedia
+
+ \ingroup multimedia
+ \ingroup multimedia_video
+
+ A video sink presents a stream of video frames. QVideoFrameFormat describes the type of
+ the frames and determines how they should be presented.
+
+ The core properties of a video stream required to set up a video sink are the pixel format
+ given by pixelFormat(), and the frame dimensions given by frameSize().
+
+ The region of a frame that is actually displayed on a video surface is given by the viewport().
+ A stream may have a viewport less than the entire region of a frame to allow for videos smaller
+ than the nearest optimal size of a video frame. For example the width of a frame may be
+ extended so that the start of each scan line is eight byte aligned.
+
+ Other common properties are the scanLineDirection(), frameRate() and the yCrCbColorSpace().
+*/
+
+/*!
+ \enum QVideoFrameFormat::PixelFormat
+
+ Enumerates video data types.
+
+ \value Format_Invalid
+ The frame is invalid.
+
+ \value Format_ARGB8888
+ The frame is stored using a ARGB format with 8 bits per component.
+
+ \value Format_ARGB8888_Premultiplied
+ The frame stored using a premultiplied ARGB format with 8 bits per component.
+
+ \value Format_XRGB8888
+ The frame stored using a 32 bits per pixel RGB format (0xff, R, G, B).
+
+ \value Format_BGRA8888
+ The frame is stored using a 32-bit BGRA format (0xBBGGRRAA).
+
+ \value Format_BGRA8888_Premultiplied
+ The frame is stored using a premultiplied 32bit BGRA format.
+
+ \value Format_ABGR8888
+ The frame is stored using a 32-bit ABGR format (0xAABBGGRR).
+
+ \value Format_XBGR8888
+ The frame is stored using a 32-bit BGR format (0xffBBGGRR).
+
+ \value Format_RGBA8888
+ The frame is stored in memory as the bytes R, G, B, A/X, with R at the lowest address and A/X at the highest address.
+
+ \value Format_BGRX8888
+ The frame is stored in format 32-bit BGRx format, [31:0] B:G:R:x 8:8:8:8 little endian
+
+ \value Format_RGBX8888
+ The frame is stored in memory as the bytes R, G, B, A/X, with R at the lowest address and A/X at the highest address.
+
+ \value Format_AYUV
+ The frame is stored using a packed 32-bit AYUV format (0xAAYYUUVV).
+
+ \value Format_AYUV_Premultiplied
+ The frame is stored using a packed premultiplied 32-bit AYUV format (0xAAYYUUVV).
+
+ \value Format_YUV420P
+ The frame is stored using an 8-bit per component planar YUV format with the U and V planes
+ horizontally and vertically sub-sampled, i.e. the height and width of the U and V planes are
+ half that of the Y plane.
+
+ \value Format_YUV422P
+ The frame is stored using an 8-bit per component planar YUV format with the U and V planes
+ horizontally sub-sampled, i.e. the width of the U and V planes are
+ half that of the Y plane, and height of U and V planes is the same as Y.
+
+ \value Format_YV12
+ The frame is stored using an 8-bit per component planar YVU format with the V and U planes
+ horizontally and vertically sub-sampled, i.e. the height and width of the V and U planes are
+ half that of the Y plane.
+
+ \value Format_UYVY
+ The frame is stored using an 8-bit per component packed YUV format with the U and V planes
+ horizontally sub-sampled (U-Y-V-Y), i.e. two horizontally adjacent pixels are stored as a 32-bit
+ macropixel which has a Y value for each pixel and common U and V values.
+
+ \value Format_YUYV
+ The frame is stored using an 8-bit per component packed YUV format with the U and V planes
+ horizontally sub-sampled (Y-U-Y-V), i.e. two horizontally adjacent pixels are stored as a 32-bit
+ macropixel which has a Y value for each pixel and common U and V values.
+
+ \value Format_NV12
+ The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y)
+ followed by a horizontally and vertically sub-sampled, packed UV plane (U-V).
+
+ \value Format_NV21
+ The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y)
+ followed by a horizontally and vertically sub-sampled, packed VU plane (V-U).
+
+ \value Format_IMC1
+ The frame is stored using an 8-bit per component planar YUV format with the U and V planes
+ horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except
+ that the bytes per line of the U and V planes are padded out to the same stride as the Y plane.
+
+ \value Format_IMC2
+ The frame is stored using an 8-bit per component planar YUV format with the U and V planes
+ horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except
+ that the lines of the U and V planes are interleaved, i.e. each line of U data is followed by a
+ line of V data creating a single line of the same stride as the Y data.
+
+ \value Format_IMC3
+ The frame is stored using an 8-bit per component planar YVU format with the V and U planes
+ horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that
+ the bytes per line of the V and U planes are padded out to the same stride as the Y plane.
+
+ \value Format_IMC4
+ The frame is stored using an 8-bit per component planar YVU format with the V and U planes
+ horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that
+ the lines of the V and U planes are interleaved, i.e. each line of V data is followed by a line
+ of U data creating a single line of the same stride as the Y data.
+
+ \value Format_P010
+ The frame is stored using a 16bit per component semi-planar YUV format with a Y plane (Y)
+ followed by a horizontally and vertically sub-sampled, packed UV plane (U-V). Only the 10 most
+ significant bits of each component are being used.
+
+ \value Format_P016
+ The frame is stored using a 16bit per component semi-planar YUV format with a Y plane (Y)
+ followed by a horizontally and vertically sub-sampled, packed UV plane (U-V).
+
+ \value Format_Y8
+ The frame is stored using an 8-bit greyscale format.
+
+ \value Format_Y16
+ The frame is stored using a 16-bit linear greyscale format. Little endian.
+
+ \value Format_Jpeg
+ The frame is stored in compressed Jpeg format.
+
+ \value Format_SamplerExternalOES
+ The frame is stored in external OES texture format. This is currently only being used on Android.
+
+ \value Format_SamplerRect
+ The frame is stored in rectangle texture format (GL_TEXTURE_RECTANGLE). This is only being used on
+ macOS with an OpenGL based Rendering Hardware interface. The underlying pixel format stored in the
+ texture is Format_BRGA8888.
+
+ \value Format_YUV420P10
+ Similar to YUV420, but uses 16bits per component, 10 of those significant.
+*/
+
+/*!
+ \enum QVideoFrameFormat::Direction
+
+ Enumerates the layout direction of video scan lines.
+
+ \value TopToBottom Scan lines are arranged from the top of the frame to the bottom.
+ \value BottomToTop Scan lines are arranged from the bottom of the frame to the top.
+*/
+
+/*!
+ \enum QVideoFrameFormat::YCbCrColorSpace
+
+ \deprecated Use QVideoFrameFormat::ColorSpace instead.
+
+ Enumerates the Y'CbCr color space of video frames.
+
+ \value YCbCr_Undefined
+ No color space is specified.
+
+ \value YCbCr_BT601
+ A Y'CbCr color space defined by ITU-R recommendation BT.601
+ with Y value range from 16 to 235, and Cb/Cr range from 16 to 240.
+ Used mostly by older videos that were targeting CRT displays.
+
+ \value YCbCr_BT709
+ A Y'CbCr color space defined by ITU-R BT.709 with the same values range as YCbCr_BT601.
+ The most commonly used color space today.
+
+ \value YCbCr_xvYCC601
+ This value is deprecated. Please check the \l ColorRange instead.
+ The BT.601 color space with the value range extended to 0 to 255.
+ It is backward compatible with BT.601 and uses values outside BT.601 range to represent a
+ wider range of colors.
+
+ \value YCbCr_xvYCC709
+ This value is deprecated. Please check the \l ColorRange instead.
+ The BT.709 color space with the value range extended to 0 to 255.
+
+ \value YCbCr_JPEG
+ The full range Y'CbCr color space used in most JPEG files.
+
+ \value YCbCr_BT2020
+ The color space defined by ITU-R BT.2020. Used mainly for HDR videos.
+*/
+
+
+/*!
+ \enum QVideoFrameFormat::ColorSpace
+
+ Enumerates the color space of video frames.
+
+ \value ColorSpace_Undefined
+ No color space is specified.
+
+ \value ColorSpace_BT601
+ A color space defined by ITU-R recommendation BT.601
+ with Y value range from 16 to 235, and Cb/Cr range from 16 to 240.
+ Used mostly by older videos that were targeting CRT displays.
+
+ \value ColorSpace_BT709
+ A color space defined by ITU-R BT.709 with the same values range as ColorSpace_BT601.
+ The most commonly used color space today.
+
+ \value ColorSpace_AdobeRgb
+ The full range YUV color space used in most JPEG files.
+
+ \value ColorSpace_BT2020
+ The color space defined by ITU-R BT.2020. Used mainly for HDR videos.
+*/
+
+/*!
+ \enum QVideoFrameFormat::ColorTransfer
+
+ \value ColorTransfer_Unknown
+ The color transfer function is unknown.
+
+ \value ColorTransfer_BT709
+ Color values are encoded according to BT709. See also https://www.itu.int/rec/R-REC-BT.709/en.
+ This is close to, but not identical to a gamma curve of 2.2, and the same transfer curve as is
+ used in sRGB.
+
+ \value ColorTransfer_BT601
+ Color values are encoded according to BT601. See also https://www.itu.int/rec/R-REC-BT.601/en.
+
+ \value ColorTransfer_Linear
+ Color values are linear
+
+ \value ColorTransfer_Gamma22
+ Color values are encoded with a gamma of 2.2
+
+ \value ColorTransfer_Gamma28
+ Color values are encoded with a gamma of 2.8
+
+ \value ColorTransfer_ST2084
+ Color values are encoded using STME ST 2084. This transfer function is the most common HDR
+ transfer function and often called the 'perceptual quantizer'. See also https://www.itu.int/rec/R-REC-BT.2100
+ and https://en.wikipedia.org/wiki/Perceptual_quantizer.
+
+
+ \value ColorTransfer_STD_B67
+ Color values are encoded using ARIB STD B67. This transfer function is also often referred to as 'hybrid log gamma'.
+ See also https://www.itu.int/rec/R-REC-BT.2100 and https://en.wikipedia.org/wiki/Hybrid_log–gamma.
+*/
+
+/*!
+ \enum QVideoFrameFormat::ColorRange
+
+ Describes the color range used by the video data. Video data usually comes in either full
+ color range, where all values are being used, or a more limited range traditionally used in
+ YUV video formats, where a subset of all values is being used.
+
+ \value ColorRange_Unknown
+ The color range of the video is unknown.
+
+ \value ColorRange_Video
+
+ The color range traditionally used by most YUV video formats. For 8 bit formats, the Y component is
+ limited to values between 16 and 235. The U and V components are limited to values between 16 and 240
+
+ For higher bit depths multiply these values with 2^(depth-8).
+
+ \value ColorRange_Full
+
+ Full color range. All values from 0 to 2^depth - 1 are valid.
+*/
+
+/*!
+ Constructs a null video stream format.
+*/
+QVideoFrameFormat::QVideoFrameFormat()
+ : d(new QVideoFrameFormatPrivate)
+{
+ initResource();
+}
+
+/*!
+ Constructs a video stream with the given frame \a size and pixel \a format.
+*/
+QVideoFrameFormat::QVideoFrameFormat(
+ const QSize& size, QVideoFrameFormat::PixelFormat format)
+ : d(new QVideoFrameFormatPrivate(size, format))
+{
+}
+
+/*!
+ Constructs a copy of \a other.
+*/
+QVideoFrameFormat::QVideoFrameFormat(const QVideoFrameFormat &other) = default;
+
+/*!
+ \fn QVideoFrameFormat::QVideoFrameFormat(QVideoFrameFormat &&other)
+
+ Constructs a QVideoFrameFormat by moving from \a other.
+*/
+
+/*!
+ \fn void QVideoFrameFormat::swap(QVideoFrameFormat &other) noexcept
+
+ Swaps the current video frame format with the \a other.
+*/
+
+/*!
+ Assigns the values of \a other to this object.
+*/
+QVideoFrameFormat &QVideoFrameFormat::operator =(const QVideoFrameFormat &other) = default;
+
+/*!
+ \fn QVideoFrameFormat &QVideoFrameFormat::operator =(QVideoFrameFormat &&other)
+
+ Moves \a other into this QVideoFrameFormat.
+*/
+
+/*!
+ Destroys a video stream description.
+*/
+QVideoFrameFormat::~QVideoFrameFormat() = default;
+
+/*!
+ Identifies if a video surface format has a valid pixel format and frame size.
+
+ Returns true if the format is valid, and false otherwise.
+*/
+bool QVideoFrameFormat::isValid() const
+{
+ return d->pixelFormat != Format_Invalid && d->frameSize.isValid();
+}
+
+/*!
+ Returns true if \a other is the same as this video format, and false if they are different.
+*/
+bool QVideoFrameFormat::operator ==(const QVideoFrameFormat &other) const
+{
+ return d == other.d || *d == *other.d;
+}
+
+/*!
+ Returns true if \a other is different to this video format, and false if they are the same.
+*/
+bool QVideoFrameFormat::operator !=(const QVideoFrameFormat &other) const
+{
+ return d != other.d && !(*d == *other.d);
+}
+
+/*!
+ \internal
+*/
+void QVideoFrameFormat::detach()
+{
+ d.detach();
+}
+
+/*!
+ Returns the pixel format of frames in a video stream.
+*/
+QVideoFrameFormat::PixelFormat QVideoFrameFormat::pixelFormat() const
+{
+ return d->pixelFormat;
+}
+
+/*!
+ Returns the dimensions of frames in a video stream.
+
+ \sa frameWidth(), frameHeight()
+*/
+QSize QVideoFrameFormat::frameSize() const
+{
+ return d->frameSize;
+}
+
+/*!
+ Returns the width of frames in a video stream.
+
+ \sa frameSize(), frameHeight()
+*/
+int QVideoFrameFormat::frameWidth() const
+{
+ return d->frameSize.width();
+}
+
+/*!
+ Returns the height of frame in a video stream.
+*/
+int QVideoFrameFormat::frameHeight() const
+{
+ return d->frameSize.height();
+}
+
+/*!
+ Returns the number of planes used.
+ This number is depending on the pixel format and is
+ 1 for RGB based formats, and a number between 1 and 3 for
+ YUV based formats.
+*/
+int QVideoFrameFormat::planeCount() const
+{
+ return QVideoTextureHelper::textureDescription(d->pixelFormat)->nplanes;
+}
+
+/*!
+ Sets the size of frames in a video stream to \a size.
+
+ This will reset the viewport() to fill the entire frame.
+*/
+void QVideoFrameFormat::setFrameSize(const QSize &size)
+{
+ detach();
+ d->frameSize = size;
+ d->viewport = QRect(QPoint(0, 0), size);
+}
+
+/*!
+ \overload
+
+ Sets the \a width and \a height of frames in a video stream.
+
+ This will reset the viewport() to fill the entire frame.
+*/
+void QVideoFrameFormat::setFrameSize(int width, int height)
+{
+ detach();
+ d->frameSize = QSize(width, height);
+ d->viewport = QRect(0, 0, width, height);
+}
+
+/*!
+ Returns the viewport of a video stream.
+
+ The viewport is the region of a video frame that is actually displayed.
+
+ By default the viewport covers an entire frame.
+*/
+QRect QVideoFrameFormat::viewport() const
+{
+ return d->viewport;
+}
+
+/*!
+ Sets the viewport of a video stream to \a viewport.
+*/
+void QVideoFrameFormat::setViewport(const QRect &viewport)
+{
+ detach();
+ d->viewport = viewport;
+}
+
+/*!
+ Returns the direction of scan lines.
+*/
+QVideoFrameFormat::Direction QVideoFrameFormat::scanLineDirection() const
+{
+ return d->scanLineDirection;
+}
+
+/*!
+ Sets the \a direction of scan lines.
+*/
+void QVideoFrameFormat::setScanLineDirection(Direction direction)
+{
+ detach();
+ d->scanLineDirection = direction;
+}
+
+#if QT_DEPRECATED_SINCE(6, 8)
+/*!
+ Returns the frame rate of a video stream in frames per second.
+*/
+qreal QVideoFrameFormat::frameRate() const
+{
+ return streamFrameRate();
+}
+
+/*!
+ Sets the frame \a rate of a video stream in frames per second.
+*/
+void QVideoFrameFormat::setFrameRate(qreal rate)
+{
+ setStreamFrameRate(rate);
+}
+#endif
+
+/*!
+ Returns the frame rate of a video stream in frames per second.
+*/
+qreal QVideoFrameFormat::streamFrameRate() const
+{
+ return d->frameRate;
+}
+
+/*!
+ Sets the frame \a rate of a video stream in frames per second.
+*/
+void QVideoFrameFormat::setStreamFrameRate(qreal rate)
+{
+ detach();
+ d->frameRate = rate;
+}
+
+#if QT_DEPRECATED_SINCE(6, 4)
+/*!
+ \deprecated Use colorSpace() instead
+
+ Returns the Y'CbCr color space of a video stream.
+*/
+QVideoFrameFormat::YCbCrColorSpace QVideoFrameFormat::yCbCrColorSpace() const
+{
+ return YCbCrColorSpace(d->colorSpace);
+}
+
+/*!
+ \deprecated Use setColorSpace() instead
+
+ Sets the Y'CbCr color \a space of a video stream.
+ It is only used with raw YUV frame types.
+*/
+void QVideoFrameFormat::setYCbCrColorSpace(QVideoFrameFormat::YCbCrColorSpace space)
+{
+ detach();
+ d->colorSpace = ColorSpace(space);
+}
+#endif // QT_DEPRECATED_SINCE(6, 4)
+
+/*!
+ Returns the color space of a video stream.
+*/
+QVideoFrameFormat::ColorSpace QVideoFrameFormat::colorSpace() const
+{
+ return d->colorSpace;
+}
+
+/*!
+ Sets the \a colorSpace of a video stream.
+*/
+void QVideoFrameFormat::setColorSpace(ColorSpace colorSpace)
+{
+ detach();
+ d->colorSpace = colorSpace;
+}
+
+/*!
+ Returns the color transfer function that should be used to render the
+ video stream.
+*/
+QVideoFrameFormat::ColorTransfer QVideoFrameFormat::colorTransfer() const
+{
+ return d->colorTransfer;
+}
+
+/*!
+ Sets the color transfer function that should be used to render the
+ video stream to \a colorTransfer.
+*/
+void QVideoFrameFormat::setColorTransfer(ColorTransfer colorTransfer)
+{
+ detach();
+ d->colorTransfer = colorTransfer;
+}
+
+/*!
+ Returns the color range that should be used to render the
+ video stream.
+*/
+QVideoFrameFormat::ColorRange QVideoFrameFormat::colorRange() const
+{
+ return d->colorRange;
+}
+
+/*!
+ Sets the color transfer range that should be used to render the
+ video stream to \a range.
+*/
+void QVideoFrameFormat::setColorRange(ColorRange range)
+{
+ detach();
+ d->colorRange = range;
+}
+
+/*!
+ Returns \c true if the surface is mirrored around its vertical axis.
+ This is typically needed for video frames coming from a front camera of a mobile device.
+
+ \note The mirroring here differs from QImage::mirrored, as a vertically mirrored QImage
+ will be mirrored around its x-axis.
+
+ \since 5.11
+ */
+bool QVideoFrameFormat::isMirrored() const
+{
+ return d->mirrored;
+}
+
+/*!
+ Sets if the surface is \a mirrored around its vertical axis.
+ This is typically needed for video frames coming from a front camera of a mobile device.
+ Default value is false.
+
+ \note The mirroring here differs from QImage::mirrored, as a vertically mirrored QImage
+ will be mirrored around its x-axis.
+
+ \since 5.11
+ */
+void QVideoFrameFormat::setMirrored(bool mirrored)
+{
+ detach();
+ d->mirrored = mirrored;
+}
+
+/*!
+ Returns the rotation angle the matching video frame should be rotated clockwise before displaying.
+ */
+QtVideo::Rotation QVideoFrameFormat::rotation() const
+{
+ return d->rotation;
+}
+
+/*!
+ Sets the \a rotation angle the matching video frame should be rotated clockwise before displaying.
+ */
+void QVideoFrameFormat::setRotation(QtVideo::Rotation rotation)
+{
+ detach();
+ d->rotation = rotation;
+}
+
+/*!
+ \internal
+*/
+QString QVideoFrameFormat::vertexShaderFileName() const
+{
+ return QVideoTextureHelper::vertexShaderFileName(*this);
+}
+
+/*!
+ \internal
+*/
+QString QVideoFrameFormat::fragmentShaderFileName() const
+{
+ return QVideoTextureHelper::fragmentShaderFileName(*this);
+}
+
+/*!
+ \internal
+*/
+void QVideoFrameFormat::updateUniformData(QByteArray *dst, const QVideoFrame &frame, const QMatrix4x4 &transform, float opacity) const
+{
+ QVideoTextureHelper::updateUniformData(dst, *this, frame, transform, opacity);
+}
+
+/*!
+ \internal
+
+ The maximum luminence in nits as set by the HDR metadata. If the video doesn't have meta data, the returned value depends on the
+ maximum that can be encoded by the transfer function.
+*/
+float QVideoFrameFormat::maxLuminance() const
+{
+ if (d->maxLuminance <= 0) {
+ if (d->colorTransfer == ColorTransfer_ST2084)
+ return 10000.; // ST2084 can encode up to 10000 nits
+ if (d->colorTransfer == ColorTransfer_STD_B67)
+ return 1500.; // SRD_B67 can encode up to 1200 nits, use a bit more for some headroom
+ return 100; // SDR
+ }
+ return d->maxLuminance;
+}
+/*!
+ Sets the maximum luminance to the given value, \a lum.
+*/
+void QVideoFrameFormat::setMaxLuminance(float lum)
+{
+ detach();
+ d->maxLuminance = lum;
+}
+
+
+/*!
+ Returns a video pixel format equivalent to an image \a format. If there is no equivalent
+ format QVideoFrameFormat::Format_Invalid is returned instead.
+
+ \note In general \l QImage does not handle YUV formats.
+
+*/
+QVideoFrameFormat::PixelFormat QVideoFrameFormat::pixelFormatFromImageFormat(QImage::Format format)
+{
+ switch (format) {
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ case QImage::Format_RGB32:
+ return QVideoFrameFormat::Format_BGRX8888;
+ case QImage::Format_ARGB32:
+ return QVideoFrameFormat::Format_BGRA8888;
+ case QImage::Format_ARGB32_Premultiplied:
+ return QVideoFrameFormat::Format_BGRA8888_Premultiplied;
+#else
+ case QImage::Format_RGB32:
+ return QVideoFrameFormat::Format_XRGB8888;
+ case QImage::Format_ARGB32:
+ return QVideoFrameFormat::Format_ARGB8888;
+ case QImage::Format_ARGB32_Premultiplied:
+ return QVideoFrameFormat::Format_ARGB8888_Premultiplied;
+#endif
+ case QImage::Format_RGBA8888:
+ return QVideoFrameFormat::Format_RGBA8888;
+ case QImage::Format_RGBA8888_Premultiplied:
+ // QVideoFrameFormat::Format_RGBA8888_Premultiplied is to be added in 6.8
+ // Format_RGBX8888 suits the best as a workaround
+ return QVideoFrameFormat::Format_RGBX8888;
+ case QImage::Format_RGBX8888:
+ return QVideoFrameFormat::Format_RGBX8888;
+ case QImage::Format_Grayscale8:
+ return QVideoFrameFormat::Format_Y8;
+ case QImage::Format_Grayscale16:
+ return QVideoFrameFormat::Format_Y16;
+ default:
+ return QVideoFrameFormat::Format_Invalid;
+ }
+}
+
+/*!
+ Returns an image format equivalent to a video frame pixel \a format. If there is no equivalent
+ format QImage::Format_Invalid is returned instead.
+
+ \note In general \l QImage does not handle YUV formats.
+
+*/
+QImage::Format QVideoFrameFormat::imageFormatFromPixelFormat(QVideoFrameFormat::PixelFormat format)
+{
+ switch (format) {
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ case QVideoFrameFormat::Format_BGRA8888:
+ return QImage::Format_ARGB32;
+ case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
+ return QImage::Format_ARGB32_Premultiplied;
+ case QVideoFrameFormat::Format_BGRX8888:
+ return QImage::Format_RGB32;
+ case QVideoFrameFormat::Format_ARGB8888:
+ case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
+ case QVideoFrameFormat::Format_XRGB8888:
+ return QImage::Format_Invalid;
+#else
+ case QVideoFrameFormat::Format_ARGB8888:
+ return QImage::Format_ARGB32;
+ case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
+ return QImage::Format_ARGB32_Premultiplied;
+ case QVideoFrameFormat::Format_XRGB8888:
+ return QImage::Format_RGB32;
+ case QVideoFrameFormat::Format_BGRA8888:
+ case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
+ case QVideoFrameFormat::Format_BGRX8888:
+ return QImage::Format_Invalid;
+#endif
+ case QVideoFrameFormat::Format_RGBA8888:
+ return QImage::Format_RGBA8888;
+ case QVideoFrameFormat::Format_RGBX8888:
+ return QImage::Format_RGBX8888;
+ case QVideoFrameFormat::Format_Y8:
+ return QImage::Format_Grayscale8;
+ case QVideoFrameFormat::Format_Y16:
+ return QImage::Format_Grayscale16;
+ case QVideoFrameFormat::Format_ABGR8888:
+ case QVideoFrameFormat::Format_XBGR8888:
+ case QVideoFrameFormat::Format_AYUV:
+ case QVideoFrameFormat::Format_AYUV_Premultiplied:
+ case QVideoFrameFormat::Format_YUV420P:
+ case QVideoFrameFormat::Format_YUV420P10:
+ case QVideoFrameFormat::Format_YUV422P:
+ case QVideoFrameFormat::Format_YV12:
+ case QVideoFrameFormat::Format_UYVY:
+ case QVideoFrameFormat::Format_YUYV:
+ case QVideoFrameFormat::Format_NV12:
+ case QVideoFrameFormat::Format_NV21:
+ case QVideoFrameFormat::Format_IMC1:
+ case QVideoFrameFormat::Format_IMC2:
+ case QVideoFrameFormat::Format_IMC3:
+ case QVideoFrameFormat::Format_IMC4:
+ case QVideoFrameFormat::Format_P010:
+ case QVideoFrameFormat::Format_P016:
+ case QVideoFrameFormat::Format_Jpeg:
+ case QVideoFrameFormat::Format_Invalid:
+ case QVideoFrameFormat::Format_SamplerExternalOES:
+ case QVideoFrameFormat::Format_SamplerRect:
+ return QImage::Format_Invalid;
+ }
+ return QImage::Format_Invalid;
+}
+
+/*!
+ Returns a string representation of the given \a pixelFormat.
+*/
+QString QVideoFrameFormat::pixelFormatToString(QVideoFrameFormat::PixelFormat pixelFormat)
+{
+ switch (pixelFormat) {
+ case QVideoFrameFormat::Format_Invalid:
+ return QStringLiteral("Invalid");
+ case QVideoFrameFormat::Format_ARGB8888:
+ return QStringLiteral("ARGB8888");
+ case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
+ return QStringLiteral("ARGB8888 Premultiplied");
+ case QVideoFrameFormat::Format_XRGB8888:
+ return QStringLiteral("XRGB8888");
+ case QVideoFrameFormat::Format_BGRA8888:
+ return QStringLiteral("BGRA8888");
+ case QVideoFrameFormat::Format_BGRX8888:
+ return QStringLiteral("BGRX8888");
+ case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
+ return QStringLiteral("BGRA8888 Premultiplied");
+ case QVideoFrameFormat::Format_RGBA8888:
+ return QStringLiteral("RGBA8888");
+ case QVideoFrameFormat::Format_RGBX8888:
+ return QStringLiteral("RGBX8888");
+ case QVideoFrameFormat::Format_ABGR8888:
+ return QStringLiteral("ABGR8888");
+ case QVideoFrameFormat::Format_XBGR8888:
+ return QStringLiteral("XBGR8888");
+ case QVideoFrameFormat::Format_AYUV:
+ return QStringLiteral("AYUV");
+ case QVideoFrameFormat::Format_AYUV_Premultiplied:
+ return QStringLiteral("AYUV Premultiplied");
+ case QVideoFrameFormat::Format_YUV420P:
+ return QStringLiteral("YUV420P");
+ case QVideoFrameFormat::Format_YUV420P10:
+ return QStringLiteral("YUV420P10");
+ case QVideoFrameFormat::Format_YUV422P:
+ return QStringLiteral("YUV422P");
+ case QVideoFrameFormat::Format_YV12:
+ return QStringLiteral("YV12");
+ case QVideoFrameFormat::Format_UYVY:
+ return QStringLiteral("UYVY");
+ case QVideoFrameFormat::Format_YUYV:
+ return QStringLiteral("YUYV");
+ case QVideoFrameFormat::Format_NV12:
+ return QStringLiteral("NV12");
+ case QVideoFrameFormat::Format_NV21:
+ return QStringLiteral("NV21");
+ case QVideoFrameFormat::Format_IMC1:
+ return QStringLiteral("IMC1");
+ case QVideoFrameFormat::Format_IMC2:
+ return QStringLiteral("IMC2");
+ case QVideoFrameFormat::Format_IMC3:
+ return QStringLiteral("IMC3");
+ case QVideoFrameFormat::Format_IMC4:
+ return QStringLiteral("IMC4");
+ case QVideoFrameFormat::Format_Y8:
+ return QStringLiteral("Y8");
+ case QVideoFrameFormat::Format_Y16:
+ return QStringLiteral("Y16");
+ case QVideoFrameFormat::Format_P010:
+ return QStringLiteral("P010");
+ case QVideoFrameFormat::Format_P016:
+ return QStringLiteral("P016");
+ case QVideoFrameFormat::Format_SamplerExternalOES:
+ return QStringLiteral("SamplerExternalOES");
+ case QVideoFrameFormat::Format_Jpeg:
+ return QStringLiteral("Jpeg");
+ case QVideoFrameFormat::Format_SamplerRect:
+ return QStringLiteral("SamplerRect");
+ }
+
+ return QStringLiteral("");
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+# if QT_DEPRECATED_SINCE(6, 4)
+QDebug operator<<(QDebug dbg, QVideoFrameFormat::YCbCrColorSpace cs)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ switch (cs) {
+ case QVideoFrameFormat::YCbCr_BT601:
+ dbg << "YCbCr_BT601";
+ break;
+ case QVideoFrameFormat::YCbCr_BT709:
+ dbg << "YCbCr_BT709";
+ break;
+ case QVideoFrameFormat::YCbCr_JPEG:
+ dbg << "YCbCr_JPEG";
+ break;
+ case QVideoFrameFormat::YCbCr_xvYCC601:
+ dbg << "YCbCr_xvYCC601";
+ break;
+ case QVideoFrameFormat::YCbCr_xvYCC709:
+ dbg << "YCbCr_xvYCC709";
+ break;
+ case QVideoFrameFormat::YCbCr_BT2020:
+ dbg << "YCbCr_BT2020";
+ break;
+ default:
+ dbg << "YCbCr_Undefined";
+ break;
+ }
+ return dbg;
+}
+# endif // QT_DEPRECATED_SINCE(6, 4)
+
+QDebug operator<<(QDebug dbg, QVideoFrameFormat::ColorSpace cs)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ switch (cs) {
+ case QVideoFrameFormat::ColorSpace_BT601:
+ dbg << "ColorSpace_BT601";
+ break;
+ case QVideoFrameFormat::ColorSpace_BT709:
+ dbg << "ColorSpace_BT709";
+ break;
+ case QVideoFrameFormat::ColorSpace_AdobeRgb:
+ dbg << "ColorSpace_AdobeRgb";
+ break;
+ case QVideoFrameFormat::ColorSpace_BT2020:
+ dbg << "ColorSpace_BT2020";
+ break;
+ default:
+ dbg << "ColorSpace_Undefined";
+ break;
+ }
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, QVideoFrameFormat::Direction dir)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ switch (dir) {
+ case QVideoFrameFormat::BottomToTop:
+ dbg << "BottomToTop";
+ break;
+ case QVideoFrameFormat::TopToBottom:
+ dbg << "TopToBottom";
+ break;
+ }
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, const QVideoFrameFormat &f)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+ dbg << "QVideoFrameFormat(" << f.pixelFormat() << ", " << f.frameSize()
+ << ", viewport=" << f.viewport()
+ << ", colorSpace=" << f.colorSpace()
+ << ')'
+ << "\n pixel format=" << f.pixelFormat()
+ << "\n frame size=" << f.frameSize()
+ << "\n viewport=" << f.viewport()
+ << "\n colorSpace=" << f.colorSpace()
+ << "\n frameRate=" << f.streamFrameRate()
+ << "\n mirrored=" << f.isMirrored();
+
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, QVideoFrameFormat::PixelFormat pf)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+
+ auto format = QVideoFrameFormat::pixelFormatToString(pf);
+ if (format.isEmpty())
+ return dbg;
+
+ dbg.noquote() << QStringLiteral("Format_") << format;
+ return dbg;
+}
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideoframeformat.h b/src/multimedia/video/qvideoframeformat.h
new file mode 100644
index 000000000..18dc9952d
--- /dev/null
+++ b/src/multimedia/video/qvideoframeformat.h
@@ -0,0 +1,223 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QVIDEOSURFACEFORMAT_H
+#define QVIDEOSURFACEFORMAT_H
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtMultimedia/qtvideo.h>
+
+#include <QtCore/qlist.h>
+#include <QtCore/qmetatype.h>
+#include <QtCore/qshareddata.h>
+#include <QtCore/qsize.h>
+#include <QtGui/qimage.h>
+
+QT_BEGIN_NAMESPACE
+
+
+class QDebug;
+
+class QVideoFrameFormatPrivate;
+class QVideoFrame;
+class QMatrix4x4;
+
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QVideoFrameFormatPrivate, Q_MULTIMEDIA_EXPORT)
+
+class Q_MULTIMEDIA_EXPORT QVideoFrameFormat
+{
+public:
+ enum PixelFormat
+ {
+ Format_Invalid,
+ Format_ARGB8888,
+ Format_ARGB8888_Premultiplied,
+ Format_XRGB8888,
+ Format_BGRA8888,
+ Format_BGRA8888_Premultiplied,
+ Format_BGRX8888,
+ Format_ABGR8888,
+ Format_XBGR8888,
+ Format_RGBA8888,
+ Format_RGBX8888,
+
+ Format_AYUV,
+ Format_AYUV_Premultiplied,
+ Format_YUV420P,
+ Format_YUV422P,
+ Format_YV12,
+ Format_UYVY,
+ Format_YUYV,
+ Format_NV12,
+ Format_NV21,
+ Format_IMC1,
+ Format_IMC2,
+ Format_IMC3,
+ Format_IMC4,
+ Format_Y8,
+ Format_Y16,
+
+ Format_P010,
+ Format_P016,
+
+ Format_SamplerExternalOES,
+ Format_Jpeg,
+ Format_SamplerRect,
+
+ Format_YUV420P10
+ };
+#ifndef Q_QDOC
+ static constexpr int NPixelFormats = Format_YUV420P10 + 1;
+#endif
+
+ enum Direction
+ {
+ TopToBottom,
+ BottomToTop
+ };
+
+#if QT_DEPRECATED_SINCE(6, 4)
+ enum YCbCrColorSpace
+ {
+ YCbCr_Undefined = 0,
+ YCbCr_BT601 = 1,
+ YCbCr_BT709 = 2,
+ YCbCr_xvYCC601 = 3,
+ YCbCr_xvYCC709 = 4,
+ YCbCr_JPEG = 5,
+ YCbCr_BT2020 = 6
+ };
+#endif
+
+ // Keep values compatible with YCbCrColorSpace
+ enum ColorSpace
+ {
+ ColorSpace_Undefined = 0,
+ ColorSpace_BT601 = 1,
+ ColorSpace_BT709 = 2,
+ ColorSpace_AdobeRgb = 5,
+ ColorSpace_BT2020 = 6
+ };
+
+ enum ColorTransfer
+ {
+ ColorTransfer_Unknown,
+ ColorTransfer_BT709,
+ ColorTransfer_BT601,
+ ColorTransfer_Linear,
+ ColorTransfer_Gamma22,
+ ColorTransfer_Gamma28,
+ ColorTransfer_ST2084,
+ ColorTransfer_STD_B67,
+ };
+
+ enum ColorRange
+ {
+ ColorRange_Unknown,
+ ColorRange_Video,
+ ColorRange_Full
+ };
+
+ QVideoFrameFormat();
+ QVideoFrameFormat(const QSize &size, PixelFormat pixelFormat);
+ QVideoFrameFormat(const QVideoFrameFormat &format);
+ ~QVideoFrameFormat();
+
+ QVideoFrameFormat(QVideoFrameFormat &&other) noexcept = default;
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QVideoFrameFormat);
+ void swap(QVideoFrameFormat &other) noexcept
+ { d.swap(other.d); }
+
+ void detach();
+
+ QVideoFrameFormat &operator=(const QVideoFrameFormat &format);
+
+ bool operator==(const QVideoFrameFormat &format) const;
+ bool operator!=(const QVideoFrameFormat &format) const;
+
+ bool isValid() const;
+
+ QVideoFrameFormat::PixelFormat pixelFormat() const;
+
+ QSize frameSize() const;
+ void setFrameSize(const QSize &size);
+ void setFrameSize(int width, int height);
+
+ int frameWidth() const;
+ int frameHeight() const;
+
+ int planeCount() const;
+
+ QRect viewport() const;
+ void setViewport(const QRect &viewport);
+
+ Direction scanLineDirection() const;
+ void setScanLineDirection(Direction direction);
+
+#if QT_DEPRECATED_SINCE(6, 8)
+ QT_DEPRECATED_VERSION_X_6_8("Use streamFrameRate()")
+ qreal frameRate() const;
+ QT_DEPRECATED_VERSION_X_6_8("Use setStreamFrameRate()")
+ void setFrameRate(qreal rate);
+#endif
+
+ qreal streamFrameRate() const;
+ void setStreamFrameRate(qreal rate);
+
+#if QT_DEPRECATED_SINCE(6, 4)
+ QT_DEPRECATED_VERSION_X_6_4("Use colorSpace()")
+ YCbCrColorSpace yCbCrColorSpace() const;
+ QT_DEPRECATED_VERSION_X_6_4("Use setColorSpace()")
+ void setYCbCrColorSpace(YCbCrColorSpace colorSpace);
+#endif
+
+ ColorSpace colorSpace() const;
+ void setColorSpace(ColorSpace colorSpace);
+
+ ColorTransfer colorTransfer() const;
+ void setColorTransfer(ColorTransfer colorTransfer);
+
+ ColorRange colorRange() const;
+ void setColorRange(ColorRange range);
+
+ bool isMirrored() const;
+ void setMirrored(bool mirrored);
+
+ QtVideo::Rotation rotation() const;
+ void setRotation(QtVideo::Rotation rotation);
+
+ QString vertexShaderFileName() const;
+ QString fragmentShaderFileName() const;
+ void updateUniformData(QByteArray *dst, const QVideoFrame &frame, const QMatrix4x4 &transform, float opacity) const;
+
+ float maxLuminance() const;
+ void setMaxLuminance(float lum);
+
+ static PixelFormat pixelFormatFromImageFormat(QImage::Format format);
+ static QImage::Format imageFormatFromPixelFormat(PixelFormat format);
+
+ static QString pixelFormatToString(QVideoFrameFormat::PixelFormat pixelFormat);
+
+private:
+ QExplicitlySharedDataPointer<QVideoFrameFormatPrivate> d;
+};
+
+Q_DECLARE_SHARED(QVideoFrameFormat)
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoFrameFormat &);
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoFrameFormat::Direction);
+#if QT_DEPRECATED_SINCE(6, 4)
+QT_DEPRECATED_VERSION_X_6_4("Use QVideoFrameFormat::ColorSpace")
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoFrameFormat::YCbCrColorSpace);
+#endif
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoFrameFormat::ColorSpace);
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoFrameFormat::PixelFormat);
+#endif
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QVideoFrameFormat)
+
+#endif
+
diff --git a/src/multimedia/video/qvideooutputorientationhandler.cpp b/src/multimedia/video/qvideooutputorientationhandler.cpp
index e21efb37d..ff91bd7fb 100644
--- a/src/multimedia/video/qvideooutputorientationhandler.cpp
+++ b/src/multimedia/video/qvideooutputorientationhandler.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qvideooutputorientationhandler_p.h"
@@ -44,14 +8,18 @@
QT_BEGIN_NAMESPACE
+bool QVideoOutputOrientationHandler::m_isRecording = false;
+
QVideoOutputOrientationHandler::QVideoOutputOrientationHandler(QObject *parent)
: QObject(parent)
, m_currentOrientation(0)
{
QScreen *screen = QGuiApplication::primaryScreen();
+ if (!screen)
+ return;
- connect(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)),
- this, SLOT(screenOrientationChanged(Qt::ScreenOrientation)));
+ connect(screen, &QScreen::orientationChanged, this,
+ &QVideoOutputOrientationHandler::screenOrientationChanged);
screenOrientationChanged(screen->orientation());
}
@@ -63,7 +31,12 @@ int QVideoOutputOrientationHandler::currentOrientation() const
void QVideoOutputOrientationHandler::screenOrientationChanged(Qt::ScreenOrientation orientation)
{
+ if (m_isRecording)
+ return;
+
const QScreen *screen = QGuiApplication::primaryScreen();
+ if (!screen)
+ return;
const int angle = (360 - screen->angleBetween(screen->nativeOrientation(), orientation)) % 360;
@@ -75,3 +48,5 @@ void QVideoOutputOrientationHandler::screenOrientationChanged(Qt::ScreenOrientat
}
QT_END_NAMESPACE
+
+#include "moc_qvideooutputorientationhandler_p.cpp"
diff --git a/src/multimedia/video/qvideooutputorientationhandler_p.h b/src/multimedia/video/qvideooutputorientationhandler_p.h
index d04a781ab..ae31f333b 100644
--- a/src/multimedia/video/qvideooutputorientationhandler_p.h
+++ b/src/multimedia/video/qvideooutputorientationhandler_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QVIDEOOUTPUTORIENTATIONHANDLER_P_H
#define QVIDEOOUTPUTORIENTATIONHANDLER_P_H
@@ -54,6 +18,7 @@
#include <qtmultimediaglobal.h>
#include <QObject>
+#include <private/qglobal_p.h>
QT_BEGIN_NAMESPACE
@@ -65,6 +30,9 @@ public:
int currentOrientation() const;
+ static void setIsRecording(bool isRecording) { m_isRecording = isRecording; }
+ static bool isRecording() { return m_isRecording; }
+
Q_SIGNALS:
void orientationChanged(int angle);
@@ -73,6 +41,7 @@ private Q_SLOTS:
private:
int m_currentOrientation;
+ static bool m_isRecording;
};
QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideoprobe.cpp b/src/multimedia/video/qvideoprobe.cpp
deleted file mode 100644
index f7995b297..000000000
--- a/src/multimedia/video/qvideoprobe.cpp
+++ /dev/null
@@ -1,218 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-/*!
- \class QVideoProbe
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_video
-
- \brief The QVideoProbe class allows you to monitor video frames being played or recorded.
-
- \code
- QMediaPlayer *player = new QMediaPlayer();
- QVideoProbe *probe = new QVideoProbe;
-
- connect(probe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(processFrame(QVideoFrame)));
-
- probe->setSource(player); // Returns true, hopefully.
-
- player->setVideoOutput(myVideoSurface);
- player->setMedia(QUrl::fromLocalFile("observation.mp4"));
- player->play(); // Start receiving frames as they get presented to myVideoSurface
- \endcode
-
- This same approach works with the QCamera object as well, to receive viewfinder or video
- frames as they are captured.
-
- \sa QAudioProbe, QMediaPlayer, QCamera
-*/
-
-#include "qvideoprobe.h"
-#include "qmediavideoprobecontrol.h"
-#include "qmediaservice.h"
-#include "qmediarecorder.h"
-#include "qsharedpointer.h"
-#include "qpointer.h"
-
-QT_BEGIN_NAMESPACE
-
-class QVideoProbePrivate {
-public:
- QPointer<QMediaObject> source;
- QPointer<QMediaVideoProbeControl> probee;
-};
-
-/*!
- Creates a new QVideoProbe class with \a parent. After setting the
- source to monitor with \l setSource(), the \l videoFrameProbed()
- signal will be emitted when video frames are flowing in the
- source media object.
- */
-QVideoProbe::QVideoProbe(QObject *parent)
- : QObject(parent)
- , d(new QVideoProbePrivate)
-{
-
-}
-
-/*!
- Destroys this probe and disconnects from any
- media object.
- */
-QVideoProbe::~QVideoProbe()
-{
- if (d->source) {
- // Disconnect
- if (d->probee) {
- disconnect(d->probee.data(), SIGNAL(videoFrameProbed(QVideoFrame)), this, SIGNAL(videoFrameProbed(QVideoFrame)));
- disconnect(d->probee.data(), SIGNAL(flush()), this, SIGNAL(flush()));
- }
- d->source.data()->service()->releaseControl(d->probee.data());
- }
-}
-
-/*!
- Sets the media object to monitor to \a source.
-
- If \a source is zero, this probe will be deactivated
- and this function wil return true.
-
- If the media object does not support monitoring
- video, this function will return false.
-
- Any previously monitored objects will no longer be monitored.
- Passing in the same object will be ignored, but
- monitoring will continue.
- */
-bool QVideoProbe::setSource(QMediaObject *source)
-{
- // Need to:
- // 1) disconnect from current source if necessary
- // 2) see if new one has the probe control
- // 3) connect if so
-
- // in case source was destroyed but probe control is still valid
- if (!d->source && d->probee) {
- disconnect(d->probee.data(), SIGNAL(videoFrameProbed(QVideoFrame)), this, SIGNAL(videoFrameProbed(QVideoFrame)));
- disconnect(d->probee.data(), SIGNAL(flush()), this, SIGNAL(flush()));
- d->probee.clear();
- }
-
- if (source != d->source.data()) {
- if (d->source) {
- Q_ASSERT(d->probee);
- disconnect(d->probee.data(), SIGNAL(videoFrameProbed(QVideoFrame)), this, SIGNAL(videoFrameProbed(QVideoFrame)));
- disconnect(d->probee.data(), SIGNAL(flush()), this, SIGNAL(flush()));
- d->source.data()->service()->releaseControl(d->probee.data());
- d->source.clear();
- d->probee.clear();
- }
-
- if (source) {
- QMediaService *service = source->service();
- if (service) {
- d->probee = service->requestControl<QMediaVideoProbeControl*>();
- }
-
- if (d->probee) {
- connect(d->probee.data(), SIGNAL(videoFrameProbed(QVideoFrame)), this, SIGNAL(videoFrameProbed(QVideoFrame)));
- connect(d->probee.data(), SIGNAL(flush()), this, SIGNAL(flush()));
- d->source = source;
- }
- }
- }
-
- return (!source || d->probee != nullptr);
-}
-
-/*!
- Starts monitoring the given \a mediaRecorder.
-
- If there is no mediaObject associated with \a mediaRecorder, or if it is
- zero, this probe will be deactivated and this function wil return true.
-
- If the media recorder instance does not support monitoring
- video, this function will return false.
-
- Any previously monitored objects will no longer be monitored.
- Passing in the same object will be ignored, but
- monitoring will continue.
- */
-bool QVideoProbe::setSource(QMediaRecorder *mediaRecorder)
-{
- QMediaObject *source = mediaRecorder ? mediaRecorder->mediaObject() : nullptr;
- bool result = setSource(source);
-
- if (!mediaRecorder)
- return true;
-
- if (mediaRecorder && !source)
- return false;
-
- return result;
-}
-
-/*!
- Returns true if this probe is monitoring something, or false otherwise.
-
- The source being monitored does not need to be active.
- */
-bool QVideoProbe::isActive() const
-{
- return d->probee != nullptr;
-}
-
-/*!
- \fn QVideoProbe::videoFrameProbed(const QVideoFrame &frame)
-
- This signal should be emitted when a video \a frame is processed in the
- media service.
-*/
-
-/*!
- \fn QVideoProbe::flush()
-
- This signal should be emitted when it is required to release all frames.
- Application must release all outstanding references to video frames.
-*/
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideoprobe.h b/src/multimedia/video/qvideoprobe.h
deleted file mode 100644
index 38f5ca05a..000000000
--- a/src/multimedia/video/qvideoprobe.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QVIDEOPROBE_H
-#define QVIDEOPROBE_H
-
-#include <QtCore/QObject>
-#include <QtMultimedia/qvideoframe.h>
-
-QT_BEGIN_NAMESPACE
-
-class QMediaObject;
-class QMediaRecorder;
-
-class QVideoProbePrivate;
-class Q_MULTIMEDIA_EXPORT QVideoProbe : public QObject
-{
- Q_OBJECT
-public:
- explicit QVideoProbe(QObject *parent = nullptr);
- ~QVideoProbe();
-
- bool setSource(QMediaObject *source);
- bool setSource(QMediaRecorder *source);
-
- bool isActive() const;
-
-Q_SIGNALS:
- void videoFrameProbed(const QVideoFrame &frame);
- void flush();
-
-private:
- QVideoProbePrivate *d;
-};
-
-QT_END_NAMESPACE
-
-#endif // QVIDEOPROBE_H
diff --git a/src/multimedia/video/qvideosink.cpp b/src/multimedia/video/qvideosink.cpp
new file mode 100644
index 000000000..4551a8960
--- /dev/null
+++ b/src/multimedia/video/qvideosink.cpp
@@ -0,0 +1,194 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qvideosink.h"
+
+#include "qvideoframeformat.h"
+#include "qvideoframe.h"
+#include "qmediaplayer.h"
+#include "qmediacapturesession.h"
+
+#include <qvariant.h>
+#include <qpainter.h>
+#include <qmatrix4x4.h>
+#include <QDebug>
+#include <private/qplatformmediaintegration_p.h>
+#include <private/qplatformvideosink_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoSinkPrivate {
+public:
+ QVideoSinkPrivate(QVideoSink *q)
+ : q_ptr(q)
+ {
+ auto maybeVideoSink = QPlatformMediaIntegration::instance()->createVideoSink(q);
+ if (maybeVideoSink) {
+ videoSink = maybeVideoSink.value();
+ } else {
+ qWarning() << "Failed to create QVideoSink" << maybeVideoSink.error();
+ }
+ }
+ ~QVideoSinkPrivate()
+ {
+ delete videoSink;
+ }
+ void unregisterSource()
+ {
+ if (!source)
+ return;
+ auto *old = source;
+ source = nullptr;
+ if (auto *player = qobject_cast<QMediaPlayer *>(old))
+ player->setVideoSink(nullptr);
+ else if (auto *capture = qobject_cast<QMediaCaptureSession *>(old))
+ capture->setVideoSink(nullptr);
+ }
+
+ QVideoSink *q_ptr = nullptr;
+ QPlatformVideoSink *videoSink = nullptr;
+ QObject *source = nullptr;
+ QRhi *rhi = nullptr;
+};
+
+/*!
+ \class QVideoSink
+
+ \brief The QVideoSink class represents a generic sink for video data.
+ \inmodule QtMultimedia
+ \ingroup multimedia
+ \ingroup multimedia_video
+
+ The QVideoSink class can be used to retrieve video data on a frame by frame
+ basis from Qt Multimedia.
+
+ QVideoSink will provide individual video frames to the application developer
+ through the videoFrameChanged() signal.
+
+ The video frame can then be used to read out the data of those frames and handle them
+ further. When using QPainter, the QVideoFrame can be drawing using the paint() method
+ in QVideoSink.
+
+ QVideoFrame objects can consume a significant amount of memory or system resources and
+ should thus not be held for longer than required by the application.
+
+ \sa QMediaPlayer, QMediaCaptureSession
+
+*/
+
+/*!
+ Constructs a new QVideoSink object with \a parent.
+ */
+QVideoSink::QVideoSink(QObject *parent)
+ : QObject(parent),
+ d(new QVideoSinkPrivate(this))
+{
+ qRegisterMetaType<QVideoFrame>();
+}
+
+/*!
+ Destroys the object.
+ */
+QVideoSink::~QVideoSink()
+{
+ disconnect(this);
+ d->unregisterSource();
+ delete d;
+}
+
+/*!
+ Returns the QRhi instance being used to create texture data in the video frames.
+ */
+QRhi *QVideoSink::rhi() const
+{
+ return d->rhi;
+}
+
+/*!
+ \internal
+ Sets the QRhi instance being used to create texture data in the video frames
+ to \a rhi.
+ */
+void QVideoSink::setRhi(QRhi *rhi)
+{
+ if (d->rhi == rhi)
+ return;
+ d->rhi = rhi;
+ if (d->videoSink)
+ d->videoSink->setRhi(rhi);
+}
+
+/*!
+ \internal
+*/
+QPlatformVideoSink *QVideoSink::platformVideoSink() const
+{
+ return d->videoSink;
+}
+
+/*!
+ Returns the current video frame.
+ */
+QVideoFrame QVideoSink::videoFrame() const
+{
+ return d->videoSink ? d->videoSink->currentVideoFrame() : QVideoFrame{};
+}
+
+/*!
+ \fn void QVideoSink::videoFrameChanged(const QVideoFrame &frame) const
+
+ Signals when the video \a frame changes.
+*/
+/*!
+ Sets the current video \a frame.
+*/
+void QVideoSink::setVideoFrame(const QVideoFrame &frame)
+{
+ if (d->videoSink)
+ d->videoSink->setVideoFrame(frame);
+}
+
+/*!
+ \property QVideoSink::subtitleText
+
+ Returns the current subtitle text.
+*/
+QString QVideoSink::subtitleText() const
+{
+ return d->videoSink ? d->videoSink->subtitleText() : QString{};
+}
+
+/*!
+ Sets the current \a subtitle text.
+*/
+void QVideoSink::setSubtitleText(const QString &subtitle)
+{
+ if (d->videoSink)
+ d->videoSink->setSubtitleText(subtitle);
+}
+
+/*!
+ \property QVideoSink::videoSize
+
+ Returns the size of the video currently being played back. If no video is
+ being played, this method returns an invalid size.
+ */
+QSize QVideoSink::videoSize() const
+{
+ return d->videoSink ? d->videoSink->nativeSize() : QSize{};
+}
+
+void QVideoSink::setSource(QObject *source)
+{
+ if (d->source == source)
+ return;
+ if (source)
+ d->unregisterSource();
+ d->source = source;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qvideosink.cpp"
+
+
diff --git a/src/multimedia/video/qvideosink.h b/src/multimedia/video/qvideosink.h
new file mode 100644
index 000000000..1a2e77834
--- /dev/null
+++ b/src/multimedia/video/qvideosink.h
@@ -0,0 +1,57 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QABSTRACTVIDEOSINK_H
+#define QABSTRACTVIDEOSINK_H
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtCore/qobject.h>
+#include <QtGui/qwindowdefs.h>
+
+QT_BEGIN_NAMESPACE
+
+class QRectF;
+class QVideoFrameFormat;
+class QVideoFrame;
+
+class QVideoSinkPrivate;
+class QPlatformVideoSink;
+class QRhi;
+
+class Q_MULTIMEDIA_EXPORT QVideoSink : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString subtitleText READ subtitleText WRITE setSubtitleText NOTIFY subtitleTextChanged)
+ Q_PROPERTY(QSize videoSize READ videoSize NOTIFY videoSizeChanged)
+public:
+ QVideoSink(QObject *parent = nullptr);
+ ~QVideoSink();
+
+ QRhi *rhi() const;
+ void setRhi(QRhi *rhi);
+
+ QSize videoSize() const;
+
+ QString subtitleText() const;
+ void setSubtitleText(const QString &subtitle);
+
+ void setVideoFrame(const QVideoFrame &frame);
+ QVideoFrame videoFrame() const;
+
+ QPlatformVideoSink *platformVideoSink() const;
+Q_SIGNALS:
+ void videoFrameChanged(const QVideoFrame &frame) QT6_ONLY(const);
+ void subtitleTextChanged(const QString &subtitleText) QT6_ONLY(const);
+ void videoSizeChanged();
+
+private:
+ friend class QMediaPlayerPrivate;
+ friend class QMediaCaptureSessionPrivate;
+ void setSource(QObject *source);
+
+ QVideoSinkPrivate *d = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/video/qvideosurfaceformat.cpp b/src/multimedia/video/qvideosurfaceformat.cpp
deleted file mode 100644
index 400352b50..000000000
--- a/src/multimedia/video/qvideosurfaceformat.cpp
+++ /dev/null
@@ -1,678 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qvideosurfaceformat.h"
-
-#include <qdebug.h>
-#include <qlist.h>
-#include <qmetatype.h>
-#include <qpair.h>
-#include <qvariant.h>
-
-QT_BEGIN_NAMESPACE
-
-static void qRegisterVideoSurfaceFormatMetaTypes()
-{
- qRegisterMetaType<QVideoSurfaceFormat>();
- qRegisterMetaType<QVideoSurfaceFormat::Direction>();
- qRegisterMetaType<QVideoSurfaceFormat::YCbCrColorSpace>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterVideoSurfaceFormatMetaTypes)
-
-
-class QVideoSurfaceFormatPrivate : public QSharedData
-{
-public:
- QVideoSurfaceFormatPrivate()
- : pixelFormat(QVideoFrame::Format_Invalid)
- , handleType(QAbstractVideoBuffer::NoHandle)
- , scanLineDirection(QVideoSurfaceFormat::TopToBottom)
- , pixelAspectRatio(1, 1)
- , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined)
- , frameRate(0.0)
- , mirrored(false)
- {
- }
-
- QVideoSurfaceFormatPrivate(
- const QSize &size,
- QVideoFrame::PixelFormat format,
- QAbstractVideoBuffer::HandleType type)
- : pixelFormat(format)
- , handleType(type)
- , scanLineDirection(QVideoSurfaceFormat::TopToBottom)
- , frameSize(size)
- , pixelAspectRatio(1, 1)
- , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined)
- , viewport(QPoint(0, 0), size)
- , frameRate(0.0)
- , mirrored(false)
- {
- }
-
- QVideoSurfaceFormatPrivate(const QVideoSurfaceFormatPrivate &other)
- : QSharedData(other)
- , pixelFormat(other.pixelFormat)
- , handleType(other.handleType)
- , scanLineDirection(other.scanLineDirection)
- , frameSize(other.frameSize)
- , pixelAspectRatio(other.pixelAspectRatio)
- , ycbcrColorSpace(other.ycbcrColorSpace)
- , viewport(other.viewport)
- , frameRate(other.frameRate)
- , mirrored(other.mirrored)
- , propertyNames(other.propertyNames)
- , propertyValues(other.propertyValues)
- {
- }
-
- bool operator ==(const QVideoSurfaceFormatPrivate &other) const
- {
- if (pixelFormat == other.pixelFormat
- && handleType == other.handleType
- && scanLineDirection == other.scanLineDirection
- && frameSize == other.frameSize
- && pixelAspectRatio == other.pixelAspectRatio
- && viewport == other.viewport
- && frameRatesEqual(frameRate, other.frameRate)
- && ycbcrColorSpace == other.ycbcrColorSpace
- && mirrored == other.mirrored
- && propertyNames.count() == other.propertyNames.count()) {
- for (int i = 0; i < propertyNames.count(); ++i) {
- int j = other.propertyNames.indexOf(propertyNames.at(i));
-
- if (j == -1 || propertyValues.at(i) != other.propertyValues.at(j))
- return false;
- }
- return true;
- } else {
- return false;
- }
- }
-
- inline static bool frameRatesEqual(qreal r1, qreal r2)
- {
- return qAbs(r1 - r2) <= 0.00001 * qMin(qAbs(r1), qAbs(r2));
- }
-
- QVideoFrame::PixelFormat pixelFormat;
- QAbstractVideoBuffer::HandleType handleType;
- QVideoSurfaceFormat::Direction scanLineDirection;
- QSize frameSize;
- QSize pixelAspectRatio;
- QVideoSurfaceFormat::YCbCrColorSpace ycbcrColorSpace;
- QRect viewport;
- qreal frameRate;
- bool mirrored;
- QList<QByteArray> propertyNames;
- QList<QVariant> propertyValues;
-};
-
-/*!
- \class QVideoSurfaceFormat
- \brief The QVideoSurfaceFormat class specifies the stream format of a video presentation
- surface.
- \inmodule QtMultimedia
-
- \ingroup multimedia
- \ingroup multimedia_video
-
- A video surface presents a stream of video frames. The surface's format describes the type of
- the frames and determines how they should be presented.
-
- The core properties of a video stream required to setup a video surface are the pixel format
- given by pixelFormat(), and the frame dimensions given by frameSize().
-
- If the surface is to present frames using a frame's handle a surface format will also include
- a handle type which is given by the handleType() function.
-
- The region of a frame that is actually displayed on a video surface is given by the viewport().
- A stream may have a viewport less than the entire region of a frame to allow for videos smaller
- than the nearest optimal size of a video frame. For example the width of a frame may be
- extended so that the start of each scan line is eight byte aligned.
-
- Other common properties are the pixelAspectRatio(), scanLineDirection(), and frameRate().
- Additionally a stream may have some additional type specific properties which are listed by the
- dynamicPropertyNames() function and can be accessed using the property(), and setProperty()
- functions.
-*/
-
-/*!
- \enum QVideoSurfaceFormat::Direction
-
- Enumerates the layout direction of video scan lines.
-
- \value TopToBottom Scan lines are arranged from the top of the frame to the bottom.
- \value BottomToTop Scan lines are arranged from the bottom of the frame to the top.
-*/
-
-/*!
- \enum QVideoSurfaceFormat::YCbCrColorSpace
-
- Enumerates the Y'CbCr color space of video frames.
-
- \value YCbCr_Undefined
- No color space is specified.
-
- \value YCbCr_BT601
- A Y'CbCr color space defined by ITU-R recommendation BT.601
- with Y value range from 16 to 235, and Cb/Cr range from 16 to 240.
- Used in standard definition video.
-
- \value YCbCr_BT709
- A Y'CbCr color space defined by ITU-R BT.709 with the same values range as YCbCr_BT601. Used
- for HDTV.
-
- \value YCbCr_xvYCC601
- The BT.601 color space with the value range extended to 0 to 255.
- It is backward compatibile with BT.601 and uses values outside BT.601 range to represent a
- wider range of colors.
-
- \value YCbCr_xvYCC709
- The BT.709 color space with the value range extended to 0 to 255.
-
- \value YCbCr_JPEG
- The full range Y'CbCr color space used in JPEG files.
-*/
-
-/*!
- Constructs a null video stream format.
-*/
-QVideoSurfaceFormat::QVideoSurfaceFormat()
- : d(new QVideoSurfaceFormatPrivate)
-{
-}
-
-/*!
- Contructs a description of stream which receives stream of \a type buffers with given frame
- \a size and pixel \a format.
-*/
-QVideoSurfaceFormat::QVideoSurfaceFormat(
- const QSize& size, QVideoFrame::PixelFormat format, QAbstractVideoBuffer::HandleType type)
- : d(new QVideoSurfaceFormatPrivate(size, format, type))
-{
-}
-
-/*!
- Constructs a copy of \a other.
-*/
-QVideoSurfaceFormat::QVideoSurfaceFormat(const QVideoSurfaceFormat &other)
- : d(other.d)
-{
-}
-
-/*!
- Assigns the values of \a other to this object.
-*/
-QVideoSurfaceFormat &QVideoSurfaceFormat::operator =(const QVideoSurfaceFormat &other)
-{
- d = other.d;
-
- return *this;
-}
-
-/*!
- Destroys a video stream description.
-*/
-QVideoSurfaceFormat::~QVideoSurfaceFormat()
-{
-}
-
-/*!
- Identifies if a video surface format has a valid pixel format and frame size.
-
- Returns true if the format is valid, and false otherwise.
-*/
-bool QVideoSurfaceFormat::isValid() const
-{
- return d->pixelFormat != QVideoFrame::Format_Invalid && d->frameSize.isValid();
-}
-
-/*!
- Returns true if \a other is the same as this video format, and false if they are different.
-*/
-bool QVideoSurfaceFormat::operator ==(const QVideoSurfaceFormat &other) const
-{
- return d == other.d || *d == *other.d;
-}
-
-/*!
- Returns true if \a other is different to this video format, and false if they are the same.
-*/
-bool QVideoSurfaceFormat::operator !=(const QVideoSurfaceFormat &other) const
-{
- return d != other.d && !(*d == *other.d);
-}
-
-/*!
- Returns the pixel format of frames in a video stream.
-*/
-QVideoFrame::PixelFormat QVideoSurfaceFormat::pixelFormat() const
-{
- return d->pixelFormat;
-}
-
-/*!
- Returns the type of handle the surface uses to present the frame data.
-
- If the handle type is \c QAbstractVideoBuffer::NoHandle, buffers with any handle type are valid
- provided they can be \l {QAbstractVideoBuffer::map()}{mapped} with the
- QAbstractVideoBuffer::ReadOnly flag. If the handleType() is not QAbstractVideoBuffer::NoHandle
- then the handle type of the buffer must be the same as that of the surface format.
-*/
-QAbstractVideoBuffer::HandleType QVideoSurfaceFormat::handleType() const
-{
- return d->handleType;
-}
-
-/*!
- Returns the dimensions of frames in a video stream.
-
- \sa frameWidth(), frameHeight()
-*/
-QSize QVideoSurfaceFormat::frameSize() const
-{
- return d->frameSize;
-}
-
-/*!
- Returns the width of frames in a video stream.
-
- \sa frameSize(), frameHeight()
-*/
-int QVideoSurfaceFormat::frameWidth() const
-{
- return d->frameSize.width();
-}
-
-/*!
- Returns the height of frame in a video stream.
-*/
-int QVideoSurfaceFormat::frameHeight() const
-{
- return d->frameSize.height();
-}
-
-/*!
- Sets the size of frames in a video stream to \a size.
-
- This will reset the viewport() to fill the entire frame.
-*/
-void QVideoSurfaceFormat::setFrameSize(const QSize &size)
-{
- d->frameSize = size;
- d->viewport = QRect(QPoint(0, 0), size);
-}
-
-/*!
- \overload
-
- Sets the \a width and \a height of frames in a video stream.
-
- This will reset the viewport() to fill the entire frame.
-*/
-void QVideoSurfaceFormat::setFrameSize(int width, int height)
-{
- d->frameSize = QSize(width, height);
- d->viewport = QRect(0, 0, width, height);
-}
-
-/*!
- Returns the viewport of a video stream.
-
- The viewport is the region of a video frame that is actually displayed.
-
- By default the viewport covers an entire frame.
-*/
-QRect QVideoSurfaceFormat::viewport() const
-{
- return d->viewport;
-}
-
-/*!
- Sets the viewport of a video stream to \a viewport.
-*/
-void QVideoSurfaceFormat::setViewport(const QRect &viewport)
-{
- d->viewport = viewport;
-}
-
-/*!
- Returns the direction of scan lines.
-*/
-QVideoSurfaceFormat::Direction QVideoSurfaceFormat::scanLineDirection() const
-{
- return d->scanLineDirection;
-}
-
-/*!
- Sets the \a direction of scan lines.
-*/
-void QVideoSurfaceFormat::setScanLineDirection(Direction direction)
-{
- d->scanLineDirection = direction;
-}
-
-/*!
- Returns the frame rate of a video stream in frames per second.
-*/
-qreal QVideoSurfaceFormat::frameRate() const
-{
- return d->frameRate;
-}
-
-/*!
- Sets the frame \a rate of a video stream in frames per second.
-*/
-void QVideoSurfaceFormat::setFrameRate(qreal rate)
-{
- d->frameRate = rate;
-}
-
-/*!
- Returns a video stream's pixel aspect ratio.
-*/
-QSize QVideoSurfaceFormat::pixelAspectRatio() const
-{
- return d->pixelAspectRatio;
-}
-
-/*!
- Sets a video stream's pixel aspect \a ratio.
-*/
-void QVideoSurfaceFormat::setPixelAspectRatio(const QSize &ratio)
-{
- d->pixelAspectRatio = ratio;
-}
-
-/*!
- \overload
-
- Sets the \a horizontal and \a vertical elements of a video stream's pixel aspect ratio.
-*/
-void QVideoSurfaceFormat::setPixelAspectRatio(int horizontal, int vertical)
-{
- d->pixelAspectRatio = QSize(horizontal, vertical);
-}
-
-/*!
- Returns the Y'CbCr color space of a video stream.
-*/
-QVideoSurfaceFormat::YCbCrColorSpace QVideoSurfaceFormat::yCbCrColorSpace() const
-{
- return d->ycbcrColorSpace;
-}
-
-/*!
- Sets the Y'CbCr color \a space of a video stream.
- It is only used with raw YUV frame types.
-*/
-void QVideoSurfaceFormat::setYCbCrColorSpace(QVideoSurfaceFormat::YCbCrColorSpace space)
-{
- d->ycbcrColorSpace = space;
-}
-
-/*!
- Returns \c true if the surface is mirrored around its vertical axis.
- This is typically needed for video frames coming from a front camera of a mobile device.
-
- \note The mirroring here differs from QImage::mirrored, as a vertically mirrored QImage
- will be mirrored around its x-axis.
-
- \since 5.11
- */
-bool QVideoSurfaceFormat::isMirrored() const
-{
- return d->mirrored;
-}
-
-/*!
- Sets if the surface is \a mirrored around its vertical axis.
- This is typically needed for video frames coming from a front camera of a mobile device.
- Default value is false.
-
- \note The mirroring here differs from QImage::mirrored, as a vertically mirrored QImage
- will be mirrored around its x-axis.
-
- \since 5.11
- */
-void QVideoSurfaceFormat::setMirrored(bool mirrored)
-{
- d->mirrored = mirrored;
-}
-
-/*!
- Returns a suggested size in pixels for the video stream.
-
- This is the size of the viewport scaled according to the pixel aspect ratio.
-*/
-QSize QVideoSurfaceFormat::sizeHint() const
-{
- QSize size = d->viewport.size();
-
- if (d->pixelAspectRatio.height() != 0)
- size.setWidth(size.width() * d->pixelAspectRatio.width() / d->pixelAspectRatio.height());
-
- return size;
-}
-
-/*!
- Returns a list of video format dynamic property names.
-*/
-QList<QByteArray> QVideoSurfaceFormat::propertyNames() const
-{
- return (QList<QByteArray>()
- << "handleType"
- << "pixelFormat"
- << "frameSize"
- << "frameWidth"
- << "viewport"
- << "scanLineDirection"
- << "frameRate"
- << "pixelAspectRatio"
- << "sizeHint"
- << "yCbCrColorSpace"
- << "mirrored")
- + d->propertyNames;
-}
-
-/*!
- Returns the value of the video format's \a name property.
-*/
-QVariant QVideoSurfaceFormat::property(const char *name) const
-{
- if (qstrcmp(name, "handleType") == 0) {
- return QVariant::fromValue(d->handleType);
- } else if (qstrcmp(name, "pixelFormat") == 0) {
- return QVariant::fromValue(d->pixelFormat);
- } else if (qstrcmp(name, "frameSize") == 0) {
- return d->frameSize;
- } else if (qstrcmp(name, "frameWidth") == 0) {
- return d->frameSize.width();
- } else if (qstrcmp(name, "frameHeight") == 0) {
- return d->frameSize.height();
- } else if (qstrcmp(name, "viewport") == 0) {
- return d->viewport;
- } else if (qstrcmp(name, "scanLineDirection") == 0) {
- return QVariant::fromValue(d->scanLineDirection);
- } else if (qstrcmp(name, "frameRate") == 0) {
- return QVariant::fromValue(d->frameRate);
- } else if (qstrcmp(name, "pixelAspectRatio") == 0) {
- return QVariant::fromValue(d->pixelAspectRatio);
- } else if (qstrcmp(name, "sizeHint") == 0) {
- return sizeHint();
- } else if (qstrcmp(name, "yCbCrColorSpace") == 0) {
- return QVariant::fromValue(d->ycbcrColorSpace);
- } else if (qstrcmp(name, "mirrored") == 0) {
- return d->mirrored;
- } else {
- int id = 0;
- for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {}
-
- return id < d->propertyValues.count()
- ? d->propertyValues.at(id)
- : QVariant();
- }
-}
-
-/*!
- Sets the video format's \a name property to \a value.
-
- Trying to set a read only property will be ignored.
-
-*/
-void QVideoSurfaceFormat::setProperty(const char *name, const QVariant &value)
-{
- if (qstrcmp(name, "handleType") == 0) {
- // read only.
- } else if (qstrcmp(name, "pixelFormat") == 0) {
- // read only.
- } else if (qstrcmp(name, "frameSize") == 0) {
- if (value.canConvert<QSize>()) {
- d->frameSize = qvariant_cast<QSize>(value);
- d->viewport = QRect(QPoint(0, 0), d->frameSize);
- }
- } else if (qstrcmp(name, "frameWidth") == 0) {
- // read only.
- } else if (qstrcmp(name, "frameHeight") == 0) {
- // read only.
- } else if (qstrcmp(name, "viewport") == 0) {
- if (value.canConvert<QRect>())
- d->viewport = qvariant_cast<QRect>(value);
- } else if (qstrcmp(name, "scanLineDirection") == 0) {
- if (value.canConvert<Direction>())
- d->scanLineDirection = qvariant_cast<Direction>(value);
- } else if (qstrcmp(name, "frameRate") == 0) {
- if (value.canConvert<qreal>())
- d->frameRate = qvariant_cast<qreal>(value);
- } else if (qstrcmp(name, "pixelAspectRatio") == 0) {
- if (value.canConvert<QSize>())
- d->pixelAspectRatio = qvariant_cast<QSize>(value);
- } else if (qstrcmp(name, "sizeHint") == 0) {
- // read only.
- } else if (qstrcmp(name, "yCbCrColorSpace") == 0) {
- if (value.canConvert<YCbCrColorSpace>())
- d->ycbcrColorSpace = qvariant_cast<YCbCrColorSpace>(value);
- } else if (qstrcmp(name, "mirrored") == 0) {
- if (value.canConvert<bool>())
- d->mirrored = qvariant_cast<bool>(value);
- } else {
- int id = 0;
- for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {}
-
- if (id < d->propertyValues.count()) {
- if (value.isNull()) {
- d->propertyNames.removeAt(id);
- d->propertyValues.removeAt(id);
- } else {
- d->propertyValues[id] = value;
- }
- } else if (!value.isNull()) {
- d->propertyNames.append(QByteArray(name));
- d->propertyValues.append(value);
- }
- }
-}
-
-
-#ifndef QT_NO_DEBUG_STREAM
-QDebug operator<<(QDebug dbg, QVideoSurfaceFormat::YCbCrColorSpace cs)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (cs) {
- case QVideoSurfaceFormat::YCbCr_BT601:
- dbg << "YCbCr_BT601";
- break;
- case QVideoSurfaceFormat::YCbCr_BT709:
- dbg << "YCbCr_BT709";
- break;
- case QVideoSurfaceFormat::YCbCr_JPEG:
- dbg << "YCbCr_JPEG";
- break;
- case QVideoSurfaceFormat::YCbCr_xvYCC601:
- dbg << "YCbCr_xvYCC601";
- break;
- case QVideoSurfaceFormat::YCbCr_xvYCC709:
- dbg << "YCbCr_xvYCC709";
- break;
- case QVideoSurfaceFormat::YCbCr_CustomMatrix:
- dbg << "YCbCr_CustomMatrix";
- break;
- default:
- dbg << "YCbCr_Undefined";
- break;
- }
- return dbg;
-}
-
-QDebug operator<<(QDebug dbg, QVideoSurfaceFormat::Direction dir)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- switch (dir) {
- case QVideoSurfaceFormat::BottomToTop:
- dbg << "BottomToTop";
- break;
- case QVideoSurfaceFormat::TopToBottom:
- dbg << "TopToBottom";
- break;
- }
- return dbg;
-}
-
-QDebug operator<<(QDebug dbg, const QVideoSurfaceFormat &f)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- dbg << "QVideoSurfaceFormat(" << f.pixelFormat() << ", " << f.frameSize()
- << ", viewport=" << f.viewport() << ", pixelAspectRatio=" << f.pixelAspectRatio()
- << ", handleType=" << f.handleType() << ", yCbCrColorSpace=" << f.yCbCrColorSpace()
- << ')';
-
- const auto propertyNames = f.propertyNames();
- for (const QByteArray& propertyName : propertyNames)
- dbg << "\n " << propertyName.data() << " = " << f.property(propertyName.data());
-
- return dbg;
-}
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideosurfaceformat.h b/src/multimedia/video/qvideosurfaceformat.h
deleted file mode 100644
index 1d1990c77..000000000
--- a/src/multimedia/video/qvideosurfaceformat.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QVIDEOSURFACEFORMAT_H
-#define QVIDEOSURFACEFORMAT_H
-
-#include <QtCore/qlist.h>
-#include <QtCore/qpair.h>
-#include <QtCore/qshareddata.h>
-#include <QtCore/qsize.h>
-#include <QtGui/qimage.h>
-#include <QtMultimedia/qvideoframe.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QDebug;
-
-class QVideoSurfaceFormatPrivate;
-
-class Q_MULTIMEDIA_EXPORT QVideoSurfaceFormat
-{
-public:
- enum Direction
- {
- TopToBottom,
- BottomToTop
- };
-
- enum YCbCrColorSpace
- {
- YCbCr_Undefined,
- YCbCr_BT601,
- YCbCr_BT709,
- YCbCr_xvYCC601,
- YCbCr_xvYCC709,
- YCbCr_JPEG,
-#ifndef Q_QDOC
- YCbCr_CustomMatrix
-#endif
- };
-
- QVideoSurfaceFormat();
- QVideoSurfaceFormat(
- const QSize &size,
- QVideoFrame::PixelFormat pixelFormat,
- QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle);
- QVideoSurfaceFormat(const QVideoSurfaceFormat &format);
- ~QVideoSurfaceFormat();
-
- QVideoSurfaceFormat &operator =(const QVideoSurfaceFormat &format);
-
- bool operator ==(const QVideoSurfaceFormat &format) const;
- bool operator !=(const QVideoSurfaceFormat &format) const;
-
- bool isValid() const;
-
- QVideoFrame::PixelFormat pixelFormat() const;
- QAbstractVideoBuffer::HandleType handleType() const;
-
- QSize frameSize() const;
- void setFrameSize(const QSize &size);
- void setFrameSize(int width, int height);
-
- int frameWidth() const;
- int frameHeight() const;
-
- QRect viewport() const;
- void setViewport(const QRect &viewport);
-
- Direction scanLineDirection() const;
- void setScanLineDirection(Direction direction);
-
- qreal frameRate() const;
- void setFrameRate(qreal rate);
-
- QSize pixelAspectRatio() const;
- void setPixelAspectRatio(const QSize &ratio);
- void setPixelAspectRatio(int width, int height);
-
- YCbCrColorSpace yCbCrColorSpace() const;
- void setYCbCrColorSpace(YCbCrColorSpace colorSpace);
-
- bool isMirrored() const;
- void setMirrored(bool mirrored);
-
- QSize sizeHint() const;
-
- QList<QByteArray> propertyNames() const;
- QVariant property(const char *name) const;
- void setProperty(const char *name, const QVariant &value);
-
-private:
- QSharedDataPointer<QVideoSurfaceFormatPrivate> d;
-};
-
-#ifndef QT_NO_DEBUG_STREAM
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoSurfaceFormat &);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoSurfaceFormat::Direction);
-Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoSurfaceFormat::YCbCrColorSpace);
-#endif
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QVideoSurfaceFormat)
-Q_DECLARE_METATYPE(QVideoSurfaceFormat::Direction)
-Q_DECLARE_METATYPE(QVideoSurfaceFormat::YCbCrColorSpace)
-
-#endif
-
diff --git a/src/multimedia/video/qvideosurfaceoutput.cpp b/src/multimedia/video/qvideosurfaceoutput.cpp
deleted file mode 100644
index ebc9e1cb6..000000000
--- a/src/multimedia/video/qvideosurfaceoutput.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qvideosurfaceoutput_p.h"
-
-#include <qabstractvideosurface.h>
-#include <qmediaservice.h>
-#include <qvideorenderercontrol.h>
-
-/*!
- * \class QVideoSurfaceOutput
- * \internal
- */
-QVideoSurfaceOutput::QVideoSurfaceOutput(QObject*parent)
- : QObject(parent)
-{
-}
-
-QVideoSurfaceOutput::~QVideoSurfaceOutput()
-{
- if (m_control) {
- m_control.data()->setSurface(nullptr);
- m_service.data()->releaseControl(m_control.data());
- }
-}
-
-QMediaObject *QVideoSurfaceOutput::mediaObject() const
-{
- return m_object.data();
-}
-
-void QVideoSurfaceOutput::setVideoSurface(QAbstractVideoSurface *surface)
-{
- m_surface = surface;
-
- if (m_control)
- m_control.data()->setSurface(surface);
-}
-
-bool QVideoSurfaceOutput::setMediaObject(QMediaObject *object)
-{
- if (m_control) {
- m_control.data()->setSurface(nullptr);
- m_service.data()->releaseControl(m_control.data());
- }
- m_control.clear();
- m_service.clear();
- m_object.clear();
-
- if (object) {
- if (QMediaService *service = object->service()) {
- if (QMediaControl *control = service->requestControl(QVideoRendererControl_iid)) {
- if ((m_control = qobject_cast<QVideoRendererControl *>(control))) {
- m_service = service;
- m_object = object;
- m_control.data()->setSurface(m_surface.data());
-
- return true;
- }
- service->releaseControl(control);
- }
- }
- }
- return false;
-}
diff --git a/src/multimedia/video/qvideosurfaceoutput_p.h b/src/multimedia/video/qvideosurfaceoutput_p.h
deleted file mode 100644
index 5d050bcb0..000000000
--- a/src/multimedia/video/qvideosurfaceoutput_p.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QVIDEOSURFACEOUTPUT_P_H
-#define QVIDEOSURFACEOUTPUT_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <qmediabindableinterface.h>
-
-#include <QtCore/qsharedpointer.h>
-#include <QtCore/qpointer.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QAbstractVideoSurface;
-class QVideoRendererControl;
-
-class QVideoSurfaceOutput : public QObject, public QMediaBindableInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaBindableInterface)
-public:
- QVideoSurfaceOutput(QObject *parent = nullptr);
- ~QVideoSurfaceOutput();
-
- QMediaObject *mediaObject() const override;
-
- void setVideoSurface(QAbstractVideoSurface *surface);
-
-protected:
- bool setMediaObject(QMediaObject *object) override;
-
-private:
- QPointer<QAbstractVideoSurface> m_surface;
- QPointer<QVideoRendererControl> m_control;
- QPointer<QMediaService> m_service;
- QPointer<QMediaObject> m_object;
-};
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/multimedia/video/qvideosurfaces.cpp b/src/multimedia/video/qvideosurfaces.cpp
deleted file mode 100644
index 7ce1bd932..000000000
--- a/src/multimedia/video/qvideosurfaces.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qvideosurfaces_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QVideoSurfaces::QVideoSurfaces(const QList<QAbstractVideoSurface *> &s, QObject *parent)
- : QAbstractVideoSurface(parent), m_surfaces(s)
-{
- for (auto a : s) {
- connect(a, &QAbstractVideoSurface::supportedFormatsChanged, this, [this, a] {
- auto context = property("GLContext").value<QObject *>();
- if (!context)
- setProperty("GLContext", a->property("GLContext"));
-
- emit supportedFormatsChanged();
- });
- }
-}
-
-QVideoSurfaces::~QVideoSurfaces()
-{
-}
-
-QList<QVideoFrame::PixelFormat> QVideoSurfaces::supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const
-{
- QList<QVideoFrame::PixelFormat> result;
- QMap<QVideoFrame::PixelFormat, int> formats;
- for (auto &s : m_surfaces) {
- for (auto &p : s->supportedPixelFormats(type)) {
- if (++formats[p] == m_surfaces.size())
- result << p;
- }
- }
-
- return result;
-}
-
-bool QVideoSurfaces::start(const QVideoSurfaceFormat &format)
-{
- bool result = true;
- for (auto &s : m_surfaces)
- result &= s->start(format);
-
- return result && QAbstractVideoSurface::start(format);
-}
-
-void QVideoSurfaces::stop()
-{
- for (auto &s : m_surfaces)
- s->stop();
-
- QAbstractVideoSurface::stop();
-}
-
-bool QVideoSurfaces::present(const QVideoFrame &frame)
-{
- bool result = true;
- for (auto &s : m_surfaces)
- result &= s->present(frame);
-
- return result;
-}
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideosurfaces_p.h b/src/multimedia/video/qvideosurfaces_p.h
deleted file mode 100644
index 9074ba458..000000000
--- a/src/multimedia/video/qvideosurfaces_p.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QVIDEOSURFACES_P_H
-#define QVIDEOSURFACES_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QAbstractVideoSurface>
-#include <QList>
-
-QT_BEGIN_NAMESPACE
-
-class QVideoSurfaces : public QAbstractVideoSurface
-{
-public:
- QVideoSurfaces(const QList<QAbstractVideoSurface *> &surfaces, QObject *parent = nullptr);
- ~QVideoSurfaces();
-
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const override;
- bool start(const QVideoSurfaceFormat &format) override;
- void stop() override;
- bool present(const QVideoFrame &frame) override;
-
-private:
- QList<QAbstractVideoSurface *> m_surfaces;
- Q_DISABLE_COPY(QVideoSurfaces)
-};
-
-QT_END_NAMESPACE
-
-#endif // QVIDEOSURFACES_P_H
diff --git a/src/multimedia/video/qvideotexturehelper.cpp b/src/multimedia/video/qvideotexturehelper.cpp
new file mode 100644
index 000000000..093989654
--- /dev/null
+++ b/src/multimedia/video/qvideotexturehelper.cpp
@@ -0,0 +1,855 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qabstractvideobuffer.h"
+
+#include "qvideotexturehelper_p.h"
+#include "qvideoframeconverter_p.h"
+#include "qvideoframe_p.h"
+
+#include <qpainter.h>
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QVideoTextureHelper
+{
+
+static const TextureDescription descriptions[QVideoFrameFormat::NPixelFormats] = {
+ // Format_Invalid
+ { 0, 0,
+ [](int, int) { return 0; },
+ { QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat},
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_ARGB8888
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_ARGB8888_Premultiplied
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_XRGB8888
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_BGRA8888
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_BGRA8888_Premultiplied
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_BGRX8888
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_ABGR8888
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_XBGR8888
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_RGBA8888
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_RGBX8888
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_AYUV
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_AYUV_Premultiplied
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_YUV420P
+ { 3, 1,
+ [](int stride, int height) { return stride * ((height * 3 / 2 + 1) & ~1); },
+ { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 },
+ { { 1, 1 }, { 2, 2 }, { 2, 2 } }
+ },
+ // Format_YUV422P
+ { 3, 1,
+ [](int stride, int height) { return stride * height * 2; },
+ { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 },
+ { { 1, 1 }, { 2, 1 }, { 2, 1 } }
+ },
+ // Format_YV12
+ { 3, 1,
+ [](int stride, int height) { return stride * ((height * 3 / 2 + 1) & ~1); },
+ { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 },
+ { { 1, 1 }, { 2, 2 }, { 2, 2 } }
+ },
+ // Format_UYVY
+ { 1, 2,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 2, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_YUYV
+ { 1, 2,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 2, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_NV12
+ { 2, 1,
+ [](int stride, int height) { return stride * ((height * 3 / 2 + 1) & ~1); },
+ { QRhiTexture::R8, QRhiTexture::RG8, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 2, 2 }, { 1, 1 } }
+ },
+ // Format_NV21
+ { 2, 1,
+ [](int stride, int height) { return stride * ((height * 3 / 2 + 1) & ~1); },
+ { QRhiTexture::R8, QRhiTexture::RG8, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 2, 2 }, { 1, 1 } }
+ },
+ // Format_IMC1
+ { 3, 1,
+ [](int stride, int height) {
+ // IMC1 requires that U and V components are aligned on a multiple of 16 lines
+ int h = (height + 15) & ~15;
+ h += 2*(((h/2) + 15) & ~15);
+ return stride * h;
+ },
+ { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 },
+ { { 1, 1 }, { 2, 2 }, { 2, 2 } }
+ },
+ // Format_IMC2
+ { 2, 1,
+ [](int stride, int height) { return 2*stride*height; },
+ { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 2 }, { 1, 1 } }
+ },
+ // Format_IMC3
+ { 3, 1,
+ [](int stride, int height) {
+ // IMC3 requires that U and V components are aligned on a multiple of 16 lines
+ int h = (height + 15) & ~15;
+ h += 2*(((h/2) + 15) & ~15);
+ return stride * h;
+ },
+ { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 },
+ { { 1, 1 }, { 2, 2 }, { 2, 2 } }
+ },
+ // Format_IMC4
+ { 2, 1,
+ [](int stride, int height) { return 2*stride*height; },
+ { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 2 }, { 1, 1 } }
+ },
+ // Format_Y8
+ { 1, 1,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::R8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_Y16
+ { 1, 2,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::R16, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_P010
+ { 2, 2,
+ [](int stride, int height) { return stride * ((height * 3 / 2 + 1) & ~1); },
+ { QRhiTexture::R16, QRhiTexture::RG16, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 2, 2 }, { 1, 1 } }
+ },
+ // Format_P016
+ { 2, 2,
+ [](int stride, int height) { return stride * ((height * 3 / 2 + 1) & ~1); },
+ { QRhiTexture::R16, QRhiTexture::RG16, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 2, 2 }, { 1, 1 } }
+ },
+ // Format_SamplerExternalOES
+ {
+ 1, 0,
+ [](int, int) { return 0; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_Jpeg
+ { 1, 4,
+ [](int stride, int height) { return stride*height; },
+ { QRhiTexture::RGBA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_SamplerRect
+ {
+ 1, 0,
+ [](int, int) { return 0; },
+ { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat },
+ { { 1, 1 }, { 1, 1 }, { 1, 1 } }
+ },
+ // Format_YUV420P10
+ { 3, 2,
+ [](int stride, int height) { return stride * ((height * 3 / 2 + 1) & ~1); },
+ { QRhiTexture::R16, QRhiTexture::R16, QRhiTexture::R16 },
+ { { 1, 1 }, { 2, 2 }, { 2, 2 } }
+ },
+};
+
+const TextureDescription *textureDescription(QVideoFrameFormat::PixelFormat format)
+{
+ return descriptions + format;
+}
+
+QString vertexShaderFileName(const QVideoFrameFormat &format)
+{
+ auto fmt = format.pixelFormat();
+ Q_UNUSED(fmt);
+
+#if 1//def Q_OS_ANDROID
+ if (fmt == QVideoFrameFormat::Format_SamplerExternalOES)
+ return QStringLiteral(":/qt-project.org/multimedia/shaders/externalsampler.vert.qsb");
+#endif
+#if 1//def Q_OS_MACOS
+ if (fmt == QVideoFrameFormat::Format_SamplerRect)
+ return QStringLiteral(":/qt-project.org/multimedia/shaders/rectsampler.vert.qsb");
+#endif
+
+ return QStringLiteral(":/qt-project.org/multimedia/shaders/vertex.vert.qsb");
+}
+
+QString fragmentShaderFileName(const QVideoFrameFormat &format, QRhiSwapChain::Format surfaceFormat)
+{
+ const char *shader = nullptr;
+ switch (format.pixelFormat()) {
+ case QVideoFrameFormat::Format_Y8:
+ case QVideoFrameFormat::Format_Y16:
+ shader = "y";
+ break;
+ case QVideoFrameFormat::Format_AYUV:
+ case QVideoFrameFormat::Format_AYUV_Premultiplied:
+ shader = "ayuv";
+ break;
+ case QVideoFrameFormat::Format_ARGB8888:
+ case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
+ case QVideoFrameFormat::Format_XRGB8888:
+ shader = "argb";
+ break;
+ case QVideoFrameFormat::Format_ABGR8888:
+ case QVideoFrameFormat::Format_XBGR8888:
+ shader = "abgr";
+ break;
+ case QVideoFrameFormat::Format_Jpeg: // Jpeg is decoded transparently into an ARGB texture
+ shader = "bgra";
+ break;
+ case QVideoFrameFormat::Format_RGBA8888:
+ case QVideoFrameFormat::Format_RGBX8888:
+ case QVideoFrameFormat::Format_BGRA8888:
+ case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
+ case QVideoFrameFormat::Format_BGRX8888:
+ shader = "rgba";
+ break;
+ case QVideoFrameFormat::Format_YUV420P:
+ case QVideoFrameFormat::Format_YUV422P:
+ case QVideoFrameFormat::Format_IMC3:
+ shader = "yuv_triplanar";
+ break;
+ case QVideoFrameFormat::Format_YUV420P10:
+ shader = "yuv_triplanar_p10";
+ break;
+ case QVideoFrameFormat::Format_YV12:
+ case QVideoFrameFormat::Format_IMC1:
+ shader = "yvu_triplanar";
+ break;
+ case QVideoFrameFormat::Format_IMC2:
+ shader = "imc2";
+ break;
+ case QVideoFrameFormat::Format_IMC4:
+ shader = "imc4";
+ break;
+ case QVideoFrameFormat::Format_UYVY:
+ shader = "uyvy";
+ break;
+ case QVideoFrameFormat::Format_YUYV:
+ shader = "yuyv";
+ break;
+ case QVideoFrameFormat::Format_P010:
+ case QVideoFrameFormat::Format_P016:
+ // P010/P016 have the same layout as NV12, just 16 instead of 8 bits per pixel
+ if (format.colorTransfer() == QVideoFrameFormat::ColorTransfer_ST2084) {
+ shader = "nv12_bt2020_pq";
+ break;
+ }
+ if (format.colorTransfer() == QVideoFrameFormat::ColorTransfer_STD_B67) {
+ shader = "nv12_bt2020_hlg";
+ break;
+ }
+ // Fall through, should be bt709
+ Q_FALLTHROUGH();
+ case QVideoFrameFormat::Format_NV12:
+ shader = "nv12";
+ break;
+ case QVideoFrameFormat::Format_NV21:
+ shader = "nv21";
+ break;
+ case QVideoFrameFormat::Format_SamplerExternalOES:
+#if 1//def Q_OS_ANDROID
+ shader = "externalsampler";
+ break;
+#endif
+ case QVideoFrameFormat::Format_SamplerRect:
+#if 1//def Q_OS_MACOS
+ shader = "rectsampler_bgra";
+ break;
+#endif
+ // fallthrough
+ case QVideoFrameFormat::Format_Invalid:
+ default:
+ break;
+ }
+ if (!shader)
+ return QString();
+ QString shaderFile = QStringLiteral(":/qt-project.org/multimedia/shaders/") + QString::fromLatin1(shader);
+ if (surfaceFormat == QRhiSwapChain::HDRExtendedSrgbLinear)
+ shaderFile += QLatin1String("_linear");
+ shaderFile += QStringLiteral(".frag.qsb");
+ return shaderFile;
+}
+
+// Matrices are calculated from
+// https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.601-7-201103-I!!PDF-E.pdf
+// https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.709-6-201506-I!!PDF-E.pdf
+// https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2020-2-201510-I!!PDF-E.pdf
+//
+// For BT2020, we also need to convert the Rec2020 RGB colorspace to sRGB see
+// shaders/colorconvert.glsl for details.
+//
+// Doing the math gives the following (Y, U & V normalized to [0..1] range):
+//
+// Y = a*R + b*G + c*B
+// R = Y + e*V
+// G = Y - c*d/b*U - a*e/b*V
+// B = Y + d*U
+
+// BT2020:
+// a = .2627, b = 0.6780, c = 0.0593
+// d = 1.8814
+// e = 1.4746
+//
+// BT709:
+// a = 0.2126, b = 0.7152, c = 0.0722
+// d = 1.8556
+// e = 1.5748
+//
+// BT601:
+// a = 0.299, b = 0.578, c = 0.114
+// d = 1.42
+// e = 1.772
+//
+
+// clang-format off
+static QMatrix4x4 colorMatrix(const QVideoFrameFormat &format)
+{
+ auto colorSpace = format.colorSpace();
+ if (colorSpace == QVideoFrameFormat::ColorSpace_Undefined) {
+ if (format.frameHeight() > 576)
+ // HD video, assume BT709
+ colorSpace = QVideoFrameFormat::ColorSpace_BT709;
+ else
+ // SD video, assume BT601
+ colorSpace = QVideoFrameFormat::ColorSpace_BT601;
+ }
+ switch (colorSpace) {
+ case QVideoFrameFormat::ColorSpace_AdobeRgb:
+ return {
+ 1.0f, 0.000f, 1.402f, -0.701f,
+ 1.0f, -0.344f, -0.714f, 0.529f,
+ 1.0f, 1.772f, 0.000f, -0.886f,
+ 0.0f, 0.000f, 0.000f, 1.000f
+ };
+ default:
+ case QVideoFrameFormat::ColorSpace_BT709:
+ if (format.colorRange() == QVideoFrameFormat::ColorRange_Full)
+ return {
+ 1.0f, 0.0f, 1.5748f, -0.790488f,
+ 1.0f, -0.187324f, -0.468124f, 0.329010f,
+ 1.0f, 1.855600f, 0.0f, -0.931439f,
+ 0.0f, 0.0f, 0.0f, 1.0f
+ };
+ return {
+ 1.1644f, 0.0000f, 1.7927f, -0.9729f,
+ 1.1644f, -0.2132f, -0.5329f, 0.3015f,
+ 1.1644f, 2.1124f, 0.0000f, -1.1334f,
+ 0.0000f, 0.0000f, 0.0000f, 1.0000f
+ };
+ case QVideoFrameFormat::ColorSpace_BT2020:
+ if (format.colorRange() == QVideoFrameFormat::ColorRange_Full)
+ return {
+ 1.f, 0.0000f, 1.4746f, -0.7402f,
+ 1.f, -0.1646f, -0.5714f, 0.3694f,
+ 1.f, 1.8814f, 0.000f, -0.9445f,
+ 0.0f, 0.0000f, 0.000f, 1.0000f
+ };
+ return {
+ 1.1644f, 0.000f, 1.6787f, -0.9157f,
+ 1.1644f, -0.1874f, -0.6504f, 0.3475f,
+ 1.1644f, 2.1418f, 0.0000f, -1.1483f,
+ 0.0000f, 0.0000f, 0.0000f, 1.0000f
+ };
+ case QVideoFrameFormat::ColorSpace_BT601:
+ // Corresponds to the primaries used by NTSC BT601. For PAL BT601, we use the BT709 conversion
+ // as those are very close.
+ if (format.colorRange() == QVideoFrameFormat::ColorRange_Full)
+ return {
+ 1.f, 0.000f, 1.772f, -0.886f,
+ 1.f, -0.1646f, -0.57135f, 0.36795f,
+ 1.f, 1.42f, 0.000f, -0.71f,
+ 0.0f, 0.000f, 0.000f, 1.0000f
+ };
+ return {
+ 1.164f, 0.000f, 1.596f, -0.8708f,
+ 1.164f, -0.392f, -0.813f, 0.5296f,
+ 1.164f, 2.017f, 0.000f, -1.0810f,
+ 0.000f, 0.000f, 0.000f, 1.0000f
+ };
+ }
+}
+// clang-format on
+
+// PQ transfer function, see also https://en.wikipedia.org/wiki/Perceptual_quantizer
+// or https://ieeexplore.ieee.org/document/7291452
+static float convertPQFromLinear(float sig)
+{
+ const float m1 = 1305.f/8192.f;
+ const float m2 = 2523.f/32.f;
+ const float c1 = 107.f/128.f;
+ const float c2 = 2413.f/128.f;
+ const float c3 = 2392.f/128.f;
+
+ const float SDR_LEVEL = 100.f;
+ sig *= SDR_LEVEL/10000.f;
+ float psig = powf(sig, m1);
+ float num = c1 + c2*psig;
+ float den = 1 + c3*psig;
+ return powf(num/den, m2);
+}
+
+float convertHLGFromLinear(float sig)
+{
+ const float a = 0.17883277f;
+ const float b = 0.28466892f; // = 1 - 4a
+ const float c = 0.55991073f; // = 0.5 - a ln(4a)
+
+ if (sig < 1.f/12.f)
+ return sqrtf(3.f*sig);
+ return a*logf(12.f*sig - b) + c;
+}
+
+static float convertSDRFromLinear(float sig)
+{
+ return sig;
+}
+
+void updateUniformData(QByteArray *dst, const QVideoFrameFormat &format, const QVideoFrame &frame, const QMatrix4x4 &transform, float opacity, float maxNits)
+{
+#ifndef Q_OS_ANDROID
+ Q_UNUSED(frame);
+#endif
+
+ QMatrix4x4 cmat;
+ switch (format.pixelFormat()) {
+ case QVideoFrameFormat::Format_Invalid:
+ return;
+
+ case QVideoFrameFormat::Format_Jpeg:
+ case QVideoFrameFormat::Format_ARGB8888:
+ case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
+ case QVideoFrameFormat::Format_XRGB8888:
+ case QVideoFrameFormat::Format_BGRA8888:
+ case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
+ case QVideoFrameFormat::Format_BGRX8888:
+ case QVideoFrameFormat::Format_ABGR8888:
+ case QVideoFrameFormat::Format_XBGR8888:
+ case QVideoFrameFormat::Format_RGBA8888:
+ case QVideoFrameFormat::Format_RGBX8888:
+
+ case QVideoFrameFormat::Format_Y8:
+ case QVideoFrameFormat::Format_Y16:
+ break;
+ case QVideoFrameFormat::Format_IMC1:
+ case QVideoFrameFormat::Format_IMC2:
+ case QVideoFrameFormat::Format_IMC3:
+ case QVideoFrameFormat::Format_IMC4:
+ case QVideoFrameFormat::Format_AYUV:
+ case QVideoFrameFormat::Format_AYUV_Premultiplied:
+ case QVideoFrameFormat::Format_YUV420P:
+ case QVideoFrameFormat::Format_YUV420P10:
+ case QVideoFrameFormat::Format_YUV422P:
+ case QVideoFrameFormat::Format_YV12:
+ case QVideoFrameFormat::Format_UYVY:
+ case QVideoFrameFormat::Format_YUYV:
+ case QVideoFrameFormat::Format_NV12:
+ case QVideoFrameFormat::Format_NV21:
+ case QVideoFrameFormat::Format_P010:
+ case QVideoFrameFormat::Format_P016:
+ cmat = colorMatrix(format);
+ break;
+ case QVideoFrameFormat::Format_SamplerExternalOES:
+ // get Android specific transform for the externalsampler texture
+ if (auto hwBuffer = QVideoFramePrivate::hwBuffer(frame))
+ cmat = hwBuffer->externalTextureMatrix();
+ break;
+ case QVideoFrameFormat::Format_SamplerRect:
+ {
+ // Similarly to SamplerExternalOES, the "color matrix" is used here to
+ // transform the texture coordinates. OpenGL texture rectangles expect
+ // non-normalized UVs, so apply a scale to have the fragment shader see
+ // UVs in range [width,height] instead of [0,1].
+ const QSize videoSize = frame.size();
+ cmat.scale(videoSize.width(), videoSize.height());
+ }
+ break;
+ }
+
+ // HDR with a PQ or HLG transfer function uses a BT2390 based tone mapping to cut off the HDR peaks
+ // This requires that we pass the max luminance the tonemapper should clip to over to the fragment
+ // shader. To reduce computations there, it's precomputed in PQ values here.
+ auto fromLinear = convertSDRFromLinear;
+ switch (format.colorTransfer()) {
+ case QVideoFrameFormat::ColorTransfer_ST2084:
+ fromLinear = convertPQFromLinear;
+ break;
+ case QVideoFrameFormat::ColorTransfer_STD_B67:
+ fromLinear = convertHLGFromLinear;
+ break;
+ default:
+ break;
+ }
+
+ if (dst->size() < qsizetype(sizeof(UniformData)))
+ dst->resize(sizeof(UniformData));
+
+ auto ud = reinterpret_cast<UniformData*>(dst->data());
+ memcpy(ud->transformMatrix, transform.constData(), sizeof(ud->transformMatrix));
+ memcpy(ud->colorMatrix, cmat.constData(), sizeof(ud->transformMatrix));
+ ud->opacity = opacity;
+ ud->width = float(format.frameWidth());
+ ud->masteringWhite = fromLinear(float(format.maxLuminance())/100.f);
+ ud->maxLum = fromLinear(float(maxNits)/100.f);
+}
+
+enum class UpdateTextureWithMapResult : uint8_t {
+ Failed,
+ UpdatedWithDataCopy,
+ UpdatedWithDataReference
+};
+
+static UpdateTextureWithMapResult updateTextureWithMap(const QVideoFrame &frame, QRhi *rhi,
+ QRhiResourceUpdateBatch *rub, int plane,
+ std::unique_ptr<QRhiTexture> &tex)
+{
+ Q_ASSERT(frame.isMapped());
+
+ QVideoFrameFormat fmt = frame.surfaceFormat();
+ QVideoFrameFormat::PixelFormat pixelFormat = fmt.pixelFormat();
+ QSize size = fmt.frameSize();
+
+ const TextureDescription &texDesc = descriptions[pixelFormat];
+ QSize planeSize(size.width()/texDesc.sizeScale[plane].x, size.height()/texDesc.sizeScale[plane].y);
+
+ bool needsRebuild = !tex || tex->pixelSize() != planeSize || tex->format() != texDesc.textureFormat[plane];
+ if (!tex) {
+ tex.reset(rhi->newTexture(texDesc.textureFormat[plane], planeSize, 1, {}));
+ if (!tex) {
+ qWarning("Failed to create new texture (size %dx%d)", planeSize.width(), planeSize.height());
+ return UpdateTextureWithMapResult::Failed;
+ }
+ }
+
+ if (needsRebuild) {
+ tex->setFormat(texDesc.textureFormat[plane]);
+ tex->setPixelSize(planeSize);
+ if (!tex->create()) {
+ qWarning("Failed to create texture (size %dx%d)", planeSize.width(), planeSize.height());
+ return UpdateTextureWithMapResult::Failed;
+ }
+ }
+
+ auto result = UpdateTextureWithMapResult::UpdatedWithDataCopy;
+
+ QRhiTextureSubresourceUploadDescription subresDesc;
+
+ if (pixelFormat == QVideoFrameFormat::Format_Jpeg) {
+ Q_ASSERT(plane == 0);
+
+ QImage image;
+
+ // calling QVideoFrame::toImage is not accurate. To be fixed.
+ image = frame.toImage();
+ image.convertTo(QImage::Format_ARGB32);
+ subresDesc.setImage(image);
+
+ } else {
+ // Note, QByteArray::fromRawData creare QByteArray as a view without data copying
+ subresDesc.setData(QByteArray::fromRawData(
+ reinterpret_cast<const char *>(frame.bits(plane)), frame.mappedBytes(plane)));
+ subresDesc.setDataStride(frame.bytesPerLine(plane));
+ result = UpdateTextureWithMapResult::UpdatedWithDataReference;
+ }
+
+ QRhiTextureUploadEntry entry(0, 0, subresDesc);
+ QRhiTextureUploadDescription desc({ entry });
+ rub->uploadTexture(tex.get(), desc);
+
+ return result;
+}
+
+static std::unique_ptr<QRhiTexture> createTextureFromHandle(const QVideoFrame &frame, QRhi *rhi, int plane)
+{
+ QHwVideoBuffer *hwBuffer = QVideoFramePrivate::hwBuffer(frame);
+ Q_ASSERT(hwBuffer);
+
+ QVideoFrameFormat fmt = frame.surfaceFormat();
+ QVideoFrameFormat::PixelFormat pixelFormat = fmt.pixelFormat();
+ QSize size = fmt.frameSize();
+
+ const TextureDescription &texDesc = descriptions[pixelFormat];
+ QSize planeSize(size.width()/texDesc.sizeScale[plane].x, size.height()/texDesc.sizeScale[plane].y);
+
+ QRhiTexture::Flags textureFlags = {};
+ if (pixelFormat == QVideoFrameFormat::Format_SamplerExternalOES) {
+#ifdef Q_OS_ANDROID
+ if (rhi->backend() == QRhi::OpenGLES2)
+ textureFlags |= QRhiTexture::ExternalOES;
+#endif
+ }
+ if (pixelFormat == QVideoFrameFormat::Format_SamplerRect) {
+#ifdef Q_OS_MACOS
+ if (rhi->backend() == QRhi::OpenGLES2)
+ textureFlags |= QRhiTexture::TextureRectangleGL;
+#endif
+ }
+
+ if (quint64 handle = hwBuffer->textureHandle(rhi, plane); handle) {
+ std::unique_ptr<QRhiTexture> tex(rhi->newTexture(texDesc.textureFormat[plane], planeSize, 1, textureFlags));
+ if (tex->createFrom({handle, 0}))
+ return tex;
+
+ qWarning("Failed to initialize QRhiTexture wrapper for native texture object %llu",handle);
+ }
+ return {};
+}
+
+class QVideoFrameTexturesArray : public QVideoFrameTextures
+{
+public:
+ using TextureArray = std::array<std::unique_ptr<QRhiTexture>, TextureDescription::maxPlanes>;
+ QVideoFrameTexturesArray(TextureArray &&textures, QVideoFrame mappedFrame = {})
+ : m_textures(std::move(textures)), m_mappedFrame(std::move(mappedFrame))
+ {
+ Q_ASSERT(!m_mappedFrame.isValid() || m_mappedFrame.isReadable());
+ }
+
+ // We keep the source frame mapped during the target texture lifetime.
+ // Alternatively, we may use setting a custom image to QRhiTextureSubresourceUploadDescription,
+ // unsig videoFramePlaneAsImage, however, the OpenGL rendering pipeline in QRhi
+ // may keep QImage, and consequently the mapped QVideoFrame,
+ // even after the target texture is deleted: QTBUG-123174.
+ ~QVideoFrameTexturesArray() { m_mappedFrame.unmap(); }
+
+ QRhiTexture *texture(uint plane) const override
+ {
+ return plane < std::size(m_textures) ? m_textures[plane].get() : nullptr;
+ }
+
+ TextureArray takeTextures() { return std::move(m_textures); }
+
+private:
+ TextureArray m_textures;
+ QVideoFrame m_mappedFrame;
+};
+
+static std::unique_ptr<QVideoFrameTextures> createTexturesFromHandles(const QVideoFrame &frame, QRhi *rhi)
+{
+ const TextureDescription &texDesc = descriptions[frame.surfaceFormat().pixelFormat()];
+ bool ok = true;
+ QVideoFrameTexturesArray::TextureArray textures;
+ for (quint8 plane = 0; plane < texDesc.nplanes; ++plane) {
+ textures[plane] = QVideoTextureHelper::createTextureFromHandle(frame, rhi, plane);
+ ok &= bool(textures[plane]);
+ }
+ if (ok)
+ return std::make_unique<QVideoFrameTexturesArray>(std::move(textures));
+ else
+ return {};
+}
+
+static std::unique_ptr<QVideoFrameTextures> createTexturesFromMemory(QVideoFrame frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, QVideoFrameTextures *old)
+{
+ const TextureDescription &texDesc = descriptions[frame.surfaceFormat().pixelFormat()];
+ QVideoFrameTexturesArray::TextureArray textures;
+ auto oldArray = dynamic_cast<QVideoFrameTexturesArray *>(old);
+ if (oldArray)
+ textures = oldArray->takeTextures();
+
+ if (!frame.map(QtVideo::MapMode::ReadOnly)) {
+ qWarning() << "Cannot map a video frame in ReadOnly mode!";
+ return {};
+ }
+
+ auto unmapFrameGuard = qScopeGuard([&frame] { frame.unmap(); });
+
+ bool shouldKeepMapping = false;
+ for (quint8 plane = 0; plane < texDesc.nplanes; ++plane) {
+ const auto result = updateTextureWithMap(frame, rhi, rub, plane, textures[plane]);
+ if (result == UpdateTextureWithMapResult::Failed)
+ return {};
+
+ if (result == UpdateTextureWithMapResult::UpdatedWithDataReference)
+ shouldKeepMapping = true;
+ }
+
+ // as QVideoFrame::unmap does nothing with null frames, we just move the frame to the result
+ return std::make_unique<QVideoFrameTexturesArray>(
+ std::move(textures), shouldKeepMapping ? std::move(frame) : QVideoFrame());
+}
+
+std::unique_ptr<QVideoFrameTextures> createTextures(QVideoFrame &frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, std::unique_ptr<QVideoFrameTextures> &&oldTextures)
+{
+ if (!frame.isValid())
+ return {};
+
+ if (QHwVideoBuffer *hwBuffer = QVideoFramePrivate::hwBuffer(frame)) {
+ if (auto textures = hwBuffer->mapTextures(rhi))
+ return textures;
+
+ if (auto textures = createTexturesFromHandles(frame, rhi))
+ return textures;
+ }
+
+ return createTexturesFromMemory(frame, rhi, rub, oldTextures.get());
+}
+
+bool SubtitleLayout::update(const QSize &frameSize, QString text)
+{
+ text.replace(QLatin1Char('\n'), QChar::LineSeparator);
+ if (layout.text() == text && videoSize == frameSize)
+ return false;
+
+ videoSize = frameSize;
+ QFont font;
+ // 0.045 - based on this https://www.md-subs.com/saa-subtitle-font-size
+ qreal fontSize = frameSize.height() * 0.045;
+ font.setPointSize(fontSize);
+
+ layout.setText(text);
+ if (text.isEmpty()) {
+ bounds = {};
+ return true;
+ }
+ layout.setFont(font);
+ QTextOption option;
+ option.setUseDesignMetrics(true);
+ option.setAlignment(Qt::AlignCenter);
+ layout.setTextOption(option);
+
+ QFontMetrics metrics(font);
+ int leading = metrics.leading();
+
+ qreal lineWidth = videoSize.width()*.9;
+ qreal margin = videoSize.width()*.05;
+ qreal height = 0;
+ qreal textWidth = 0;
+ layout.beginLayout();
+ while (1) {
+ QTextLine line = layout.createLine();
+ if (!line.isValid())
+ break;
+
+ line.setLineWidth(lineWidth);
+ height += leading;
+ line.setPosition(QPointF(margin, height));
+ height += line.height();
+ textWidth = qMax(textWidth, line.naturalTextWidth());
+ }
+ layout.endLayout();
+
+ // put subtitles vertically in lower part of the video but not stuck to the bottom
+ int bottomMargin = videoSize.height() / 20;
+ qreal y = videoSize.height() - bottomMargin - height;
+ layout.setPosition(QPointF(0, y));
+ textWidth += fontSize/4.;
+
+ bounds = QRectF((videoSize.width() - textWidth)/2., y, textWidth, height);
+ return true;
+}
+
+void SubtitleLayout::draw(QPainter *painter, const QPointF &translate) const
+{
+ painter->save();
+ painter->translate(translate);
+ painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
+
+ QColor bgColor = Qt::black;
+ bgColor.setAlpha(128);
+ painter->setBrush(bgColor);
+ painter->setPen(Qt::NoPen);
+ painter->drawRect(bounds);
+
+ QTextLayout::FormatRange range;
+ range.start = 0;
+ range.length = layout.text().size();
+ range.format.setForeground(Qt::white);
+ layout.draw(painter, {}, { range });
+ painter->restore();
+}
+
+QImage SubtitleLayout::toImage() const
+{
+ auto size = bounds.size().toSize();
+ if (size.isEmpty())
+ return QImage();
+ QImage img(size, QImage::Format_RGBA8888_Premultiplied);
+ QColor bgColor = Qt::black;
+ bgColor.setAlpha(128);
+ img.fill(bgColor);
+
+ QPainter painter(&img);
+ painter.translate(-bounds.topLeft());
+ QTextLayout::FormatRange range;
+ range.start = 0;
+ range.length = layout.text().size();
+ range.format.setForeground(Qt::white);
+ layout.draw(&painter, {}, { range });
+ return img;
+}
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideotexturehelper_p.h b/src/multimedia/video/qvideotexturehelper_p.h
new file mode 100644
index 000000000..982c1b48a
--- /dev/null
+++ b/src/multimedia/video/qvideotexturehelper_p.h
@@ -0,0 +1,93 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QVIDEOTEXTUREHELPER_H
+#define QVIDEOTEXTUREHELPER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qvideoframeformat.h>
+#include <rhi/qrhi.h>
+
+#include <QtGui/qtextlayout.h>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoFrame;
+class QTextLayout;
+class QVideoFrameTextures;
+
+namespace QVideoTextureHelper
+{
+
+struct TextureDescription
+{
+ static constexpr int maxPlanes = 3;
+ struct SizeScale {
+ int x;
+ int y;
+ };
+ using BytesRequired = int(*)(int stride, int height);
+
+ inline int strideForWidth(int width) const { return (width*strideFactor + 15) & ~15; }
+ inline int bytesForSize(QSize s) const { return bytesRequired(strideForWidth(s.width()), s.height()); }
+ int widthForPlane(int width, int plane) const
+ {
+ if (plane > nplanes) return 0;
+ return (width + sizeScale[plane].x - 1)/sizeScale[plane].x;
+ }
+ int heightForPlane(int height, int plane) const
+ {
+ if (plane > nplanes) return 0;
+ return (height + sizeScale[plane].y - 1)/sizeScale[plane].y;
+ }
+
+ int nplanes;
+ int strideFactor;
+ BytesRequired bytesRequired;
+ QRhiTexture::Format textureFormat[maxPlanes];
+ SizeScale sizeScale[maxPlanes];
+};
+
+Q_MULTIMEDIA_EXPORT const TextureDescription *textureDescription(QVideoFrameFormat::PixelFormat format);
+
+Q_MULTIMEDIA_EXPORT QString vertexShaderFileName(const QVideoFrameFormat &format);
+Q_MULTIMEDIA_EXPORT QString fragmentShaderFileName(const QVideoFrameFormat &format, QRhiSwapChain::Format surfaceFormat = QRhiSwapChain::SDR);
+Q_MULTIMEDIA_EXPORT void updateUniformData(QByteArray *dst, const QVideoFrameFormat &format, const QVideoFrame &frame,
+ const QMatrix4x4 &transform, float opacity, float maxNits = 100);
+Q_MULTIMEDIA_EXPORT std::unique_ptr<QVideoFrameTextures> createTextures(QVideoFrame &frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, std::unique_ptr<QVideoFrameTextures> &&oldTextures);
+
+struct UniformData {
+ float transformMatrix[4][4];
+ float colorMatrix[4][4];
+ float opacity;
+ float width;
+ float masteringWhite;
+ float maxLum;
+};
+
+struct Q_MULTIMEDIA_EXPORT SubtitleLayout
+{
+ QSize videoSize;
+ QRectF bounds;
+ QTextLayout layout;
+
+ bool update(const QSize &frameSize, QString text);
+ void draw(QPainter *painter, const QPointF &translate) const;
+ QImage toImage() const;
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/video/qvideowindow.cpp b/src/multimedia/video/qvideowindow.cpp
new file mode 100644
index 000000000..9b88a86df
--- /dev/null
+++ b/src/multimedia/video/qvideowindow.cpp
@@ -0,0 +1,531 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qvideowindow_p.h"
+#include <QPlatformSurfaceEvent>
+#include <qfile.h>
+#include <qpainter.h>
+#include <private/qguiapplication_p.h>
+#include <private/qmemoryvideobuffer_p.h>
+#include <private/qhwvideobuffer_p.h>
+#include <private/qmultimediautils_p.h>
+#include <private/qvideoframe_p.h>
+#include <qpa/qplatformintegration.h>
+
+QT_BEGIN_NAMESPACE
+
+static QSurface::SurfaceType platformSurfaceType()
+{
+#if defined(Q_OS_DARWIN)
+ return QSurface::MetalSurface;
+#elif defined (Q_OS_WIN)
+ return QSurface::Direct3DSurface;
+#endif
+
+ auto *integration = QGuiApplicationPrivate::platformIntegration();
+
+ if (!integration->hasCapability(QPlatformIntegration::OpenGL))
+ return QSurface::RasterSurface;
+
+ if (QCoreApplication::testAttribute(Qt::AA_ForceRasterWidgets))
+ return QSurface::RasterSurface;
+
+ if (integration->hasCapability(QPlatformIntegration::RasterGLSurface))
+ return QSurface::RasterGLSurface;
+
+ return QSurface::OpenGLSurface;
+}
+
+QVideoWindowPrivate::QVideoWindowPrivate(QVideoWindow *q)
+ : q(q),
+ m_sink(new QVideoSink)
+{
+ Q_ASSERT(q);
+
+ if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RhiBasedRendering)) {
+ auto surfaceType = ::platformSurfaceType();
+ q->setSurfaceType(surfaceType);
+ switch (surfaceType) {
+ case QSurface::RasterSurface:
+ case QSurface::OpenVGSurface:
+ // can't use those surfaces, need to render in SW
+ m_graphicsApi = QRhi::Null;
+ break;
+ case QSurface::OpenGLSurface:
+ case QSurface::RasterGLSurface:
+ m_graphicsApi = QRhi::OpenGLES2;
+ break;
+ case QSurface::VulkanSurface:
+ m_graphicsApi = QRhi::Vulkan;
+ break;
+ case QSurface::MetalSurface:
+ m_graphicsApi = QRhi::Metal;
+ break;
+ case QSurface::Direct3DSurface:
+ m_graphicsApi = QRhi::D3D11;
+ break;
+ }
+ }
+
+ QObject::connect(m_sink.get(), &QVideoSink::videoFrameChanged, q, &QVideoWindow::setVideoFrame);
+}
+
+QVideoWindowPrivate::~QVideoWindowPrivate()
+{
+ QObject::disconnect(m_sink.get(), &QVideoSink::videoFrameChanged,
+ q, &QVideoWindow::setVideoFrame);
+}
+
+static const float g_vw_quad[] = {
+ // 4 clockwise rotation of texture vertexes (the second pair)
+ // Rotation 0
+ -1.f, -1.f, 0.f, 0.f,
+ -1.f, 1.f, 0.f, 1.f,
+ 1.f, -1.f, 1.f, 0.f,
+ 1.f, 1.f, 1.f, 1.f,
+ // Rotation 90
+ -1.f, -1.f, 0.f, 1.f,
+ -1.f, 1.f, 1.f, 1.f,
+ 1.f, -1.f, 0.f, 0.f,
+ 1.f, 1.f, 1.f, 0.f,
+
+ // Rotation 180
+ -1.f, -1.f, 1.f, 1.f,
+ -1.f, 1.f, 1.f, 0.f,
+ 1.f, -1.f, 0.f, 1.f,
+ 1.f, 1.f, 0.f, 0.f,
+ // Rotation 270
+ -1.f, -1.f, 1.f, 0.f,
+ -1.f, 1.f, 0.f, 0.f,
+ 1.f, -1.f, 1.f, 1.f,
+ 1.f, 1.f, 0.f, 1.f
+};
+
+static QShader vwGetShader(const QString &name)
+{
+ QFile f(name);
+ if (f.open(QIODevice::ReadOnly))
+ return QShader::fromSerialized(f.readAll());
+
+ return QShader();
+}
+
+void QVideoWindowPrivate::initRhi()
+{
+ if (m_graphicsApi == QRhi::Null)
+ return;
+
+ QRhi::Flags rhiFlags = {};//QRhi::EnableDebugMarkers | QRhi::EnableProfiling;
+
+#if QT_CONFIG(opengl)
+ if (m_graphicsApi == QRhi::OpenGLES2) {
+ m_fallbackSurface.reset(QRhiGles2InitParams::newFallbackSurface(q->format()));
+ QRhiGles2InitParams params;
+ params.fallbackSurface = m_fallbackSurface.get();
+ params.window = q;
+ params.format = q->format();
+ m_rhi.reset(QRhi::create(QRhi::OpenGLES2, &params, rhiFlags));
+ }
+#endif
+
+#if QT_CONFIG(vulkan)
+ if (m_graphicsApi == QRhi::Vulkan) {
+ QRhiVulkanInitParams params;
+ params.inst = q->vulkanInstance();
+ params.window = q;
+ m_rhi.reset(QRhi::create(QRhi::Vulkan, &params, rhiFlags));
+ }
+#endif
+
+#ifdef Q_OS_WIN
+ if (m_graphicsApi == QRhi::D3D11) {
+ QRhiD3D11InitParams params;
+ params.enableDebugLayer = true;
+ m_rhi.reset(QRhi::create(QRhi::D3D11, &params, rhiFlags));
+ }
+#endif
+
+#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
+ if (m_graphicsApi == QRhi::Metal) {
+ QRhiMetalInitParams params;
+ m_rhi.reset(QRhi::create(QRhi::Metal, &params, rhiFlags));
+ }
+#endif
+ if (!m_rhi)
+ return;
+
+ m_swapChain.reset(m_rhi->newSwapChain());
+ m_swapChain->setWindow(q);
+ m_renderPass.reset(m_swapChain->newCompatibleRenderPassDescriptor());
+ m_swapChain->setRenderPassDescriptor(m_renderPass.get());
+
+ m_vertexBuf.reset(m_rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(g_vw_quad)));
+ m_vertexBuf->create();
+ m_vertexBufReady = false;
+
+ m_uniformBuf.reset(m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, sizeof(QVideoTextureHelper::UniformData)));
+ m_uniformBuf->create();
+
+ m_textureSampler.reset(m_rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
+ QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge));
+ m_textureSampler->create();
+
+ m_shaderResourceBindings.reset(m_rhi->newShaderResourceBindings());
+ m_subtitleResourceBindings.reset(m_rhi->newShaderResourceBindings());
+
+ m_subtitleUniformBuf.reset(m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, sizeof(QVideoTextureHelper::UniformData)));
+ m_subtitleUniformBuf->create();
+
+ Q_ASSERT(NVideoFrameSlots >= m_rhi->resourceLimit(QRhi::FramesInFlight));
+}
+
+void QVideoWindowPrivate::setupGraphicsPipeline(QRhiGraphicsPipeline *pipeline, QRhiShaderResourceBindings *bindings, const QVideoFrameFormat &fmt)
+{
+
+ pipeline->setTopology(QRhiGraphicsPipeline::TriangleStrip);
+ QShader vs = vwGetShader(QVideoTextureHelper::vertexShaderFileName(fmt));
+ Q_ASSERT(vs.isValid());
+ QShader fs = vwGetShader(QVideoTextureHelper::fragmentShaderFileName(fmt, m_swapChain->format()));
+ Q_ASSERT(fs.isValid());
+ pipeline->setShaderStages({
+ { QRhiShaderStage::Vertex, vs },
+ { QRhiShaderStage::Fragment, fs }
+ });
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({
+ { 4 * sizeof(float) }
+ });
+ inputLayout.setAttributes({
+ { 0, 0, QRhiVertexInputAttribute::Float2, 0 },
+ { 0, 1, QRhiVertexInputAttribute::Float2, 2 * sizeof(float) }
+ });
+ pipeline->setVertexInputLayout(inputLayout);
+ pipeline->setShaderResourceBindings(bindings);
+ pipeline->setRenderPassDescriptor(m_renderPass.get());
+ pipeline->create();
+}
+
+void QVideoWindowPrivate::updateTextures(QRhiResourceUpdateBatch *rub)
+{
+ m_texturesDirty = false;
+
+ // We render a 1x1 black pixel when we don't have a video
+ if (!m_currentFrame.isValid())
+ m_currentFrame = QVideoFramePrivate::createFrame(
+ std::make_unique<QMemoryVideoBuffer>(QByteArray{ 4, 0 }, 4),
+ QVideoFrameFormat(QSize(1, 1), QVideoFrameFormat::Format_RGBA8888));
+
+ m_frameTextures = QVideoTextureHelper::createTextures(m_currentFrame, m_rhi.get(), rub, std::move(m_frameTextures));
+ if (!m_frameTextures)
+ return;
+
+ QRhiShaderResourceBinding bindings[4];
+ auto *b = bindings;
+ *(b++) = QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage,
+ m_uniformBuf.get());
+
+ auto fmt = m_currentFrame.surfaceFormat();
+ auto textureDesc = QVideoTextureHelper::textureDescription(fmt.pixelFormat());
+
+ for (int i = 0; i < textureDesc->nplanes; ++i)
+ (*b++) = QRhiShaderResourceBinding::sampledTexture(i + 1, QRhiShaderResourceBinding::FragmentStage,
+ m_frameTextures->texture(i), m_textureSampler.get());
+ m_shaderResourceBindings->setBindings(bindings, b);
+ m_shaderResourceBindings->create();
+
+ if (fmt != format) {
+ format = fmt;
+ if (!m_graphicsPipeline)
+ m_graphicsPipeline.reset(m_rhi->newGraphicsPipeline());
+
+ setupGraphicsPipeline(m_graphicsPipeline.get(), m_shaderResourceBindings.get(), format);
+ }
+}
+
+void QVideoWindowPrivate::updateSubtitle(QRhiResourceUpdateBatch *rub, const QSize &frameSize)
+{
+ m_subtitleDirty = false;
+ m_hasSubtitle = !m_currentFrame.subtitleText().isEmpty();
+ if (!m_hasSubtitle)
+ return;
+
+ m_subtitleLayout.update(frameSize, m_currentFrame.subtitleText());
+ QSize size = m_subtitleLayout.bounds.size().toSize();
+
+ QImage img = m_subtitleLayout.toImage();
+
+ m_subtitleTexture.reset(m_rhi->newTexture(QRhiTexture::RGBA8, size));
+ m_subtitleTexture->create();
+ rub->uploadTexture(m_subtitleTexture.get(), img);
+
+ QRhiShaderResourceBinding bindings[2];
+
+ bindings[0] = QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage,
+ m_subtitleUniformBuf.get());
+
+ bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage,
+ m_subtitleTexture.get(), m_textureSampler.get());
+ m_subtitleResourceBindings->setBindings(bindings, bindings + 2);
+ m_subtitleResourceBindings->create();
+
+ if (!m_subtitlePipeline) {
+ m_subtitlePipeline.reset(m_rhi->newGraphicsPipeline());
+
+ QRhiGraphicsPipeline::TargetBlend blend;
+ blend.enable = true;
+ m_subtitlePipeline->setTargetBlends({ blend });
+ setupGraphicsPipeline(m_subtitlePipeline.get(), m_subtitleResourceBindings.get(), QVideoFrameFormat(QSize(1, 1), QVideoFrameFormat::Format_RGBA8888));
+ }
+}
+
+void QVideoWindowPrivate::init()
+{
+ if (initialized)
+ return;
+ initialized = true;
+
+ initRhi();
+
+ if (!m_rhi)
+ backingStore = new QBackingStore(q);
+ else
+ m_sink->setRhi(m_rhi.get());
+}
+
+void QVideoWindowPrivate::resizeSwapChain()
+{
+ m_hasSwapChain = m_swapChain->createOrResize();
+}
+
+void QVideoWindowPrivate::releaseSwapChain()
+{
+ if (m_hasSwapChain) {
+ m_hasSwapChain = false;
+ m_swapChain->destroy();
+ }
+}
+
+void QVideoWindowPrivate::render()
+{
+ if (!initialized)
+ init();
+
+ if (!q->isExposed() || !isExposed)
+ return;
+
+ QRect rect(0, 0, q->width(), q->height());
+
+ if (backingStore) {
+ if (backingStore->size() != q->size())
+ backingStore->resize(q->size());
+
+ backingStore->beginPaint(rect);
+
+ QPaintDevice *device = backingStore->paintDevice();
+ if (!device)
+ return;
+ QPainter painter(device);
+
+ m_currentFrame.paint(&painter, rect, { Qt::black, aspectRatioMode });
+ painter.end();
+
+ backingStore->endPaint();
+ backingStore->flush(rect);
+ return;
+ }
+
+ const int frameRotationIndex = (static_cast<int>(m_currentFrame.rotation()) / 90) % 4;
+ QSize frameSize = m_currentFrame.size();
+ if (frameRotationIndex % 2)
+ frameSize.transpose();
+ QSize scaled = frameSize.scaled(rect.size(), aspectRatioMode);
+ QRect videoRect = QRect(QPoint(0, 0), scaled);
+ videoRect.moveCenter(rect.center());
+ QRect subtitleRect = videoRect.intersected(rect);
+
+ if (!m_hasSwapChain || (m_swapChain->currentPixelSize() != m_swapChain->surfacePixelSize()))
+ resizeSwapChain();
+
+ const auto requiredSwapChainFormat =
+ qGetRequiredSwapChainFormat(m_currentFrame.surfaceFormat());
+ if (qShouldUpdateSwapChainFormat(m_swapChain.get(), requiredSwapChainFormat)) {
+ releaseSwapChain();
+ m_swapChain->setFormat(requiredSwapChainFormat);
+ resizeSwapChain();
+ }
+
+ if (!m_hasSwapChain)
+ return;
+
+ QRhi::FrameOpResult r = m_rhi->beginFrame(m_swapChain.get());
+
+ // keep the video frames alive until we know that they are not needed anymore
+ m_videoFrameSlots[m_rhi->currentFrameSlot()] = m_currentFrame;
+
+ if (r == QRhi::FrameOpSwapChainOutOfDate) {
+ resizeSwapChain();
+ if (!m_hasSwapChain)
+ return;
+ r = m_rhi->beginFrame(m_swapChain.get());
+ }
+ if (r != QRhi::FrameOpSuccess) {
+ qWarning("beginFrame failed with %d, retry", r);
+ q->requestUpdate();
+ return;
+ }
+
+ QRhiResourceUpdateBatch *rub = m_rhi->nextResourceUpdateBatch();
+
+ if (!m_vertexBufReady) {
+ m_vertexBufReady = true;
+ rub->uploadStaticBuffer(m_vertexBuf.get(), g_vw_quad);
+ }
+
+ if (m_texturesDirty)
+ updateTextures(rub);
+
+ if (m_subtitleDirty || m_subtitleLayout.videoSize != subtitleRect.size())
+ updateSubtitle(rub, subtitleRect.size());
+
+ float mirrorFrame = m_currentFrame.mirrored() ? -1.f : 1.f;
+ float xscale = mirrorFrame * float(videoRect.width())/float(rect.width());
+ float yscale = -1.f * float(videoRect.height())/float(rect.height());
+
+ QMatrix4x4 transform;
+ transform.scale(xscale, yscale);
+
+ float maxNits = 100;
+ if (m_swapChain->format() == QRhiSwapChain::HDRExtendedSrgbLinear) {
+ auto info = m_swapChain->hdrInfo();
+ if (info.limitsType == QRhiSwapChainHdrInfo::ColorComponentValue)
+ maxNits = 100 * info.limits.colorComponentValue.maxColorComponentValue;
+ else
+ maxNits = info.limits.luminanceInNits.maxLuminance;
+ }
+
+ QByteArray uniformData;
+ QVideoTextureHelper::updateUniformData(&uniformData, m_currentFrame.surfaceFormat(), m_currentFrame, transform, 1.f, maxNits);
+ rub->updateDynamicBuffer(m_uniformBuf.get(), 0, uniformData.size(), uniformData.constData());
+
+ if (m_hasSubtitle) {
+ QMatrix4x4 st;
+ st.translate(0, -2.f * (float(m_subtitleLayout.bounds.center().y()) + float(subtitleRect.top()))/ float(rect.height()) + 1.f);
+ st.scale(float(m_subtitleLayout.bounds.width())/float(rect.width()),
+ -1.f * float(m_subtitleLayout.bounds.height())/float(rect.height()));
+
+ QByteArray uniformData;
+ QVideoFrameFormat fmt(m_subtitleLayout.bounds.size().toSize(), QVideoFrameFormat::Format_ARGB8888);
+ QVideoTextureHelper::updateUniformData(&uniformData, fmt, QVideoFrame(), st, 1.f);
+ rub->updateDynamicBuffer(m_subtitleUniformBuf.get(), 0, uniformData.size(), uniformData.constData());
+ }
+
+ QRhiCommandBuffer *cb = m_swapChain->currentFrameCommandBuffer();
+ cb->beginPass(m_swapChain->currentFrameRenderTarget(), Qt::black, { 1.0f, 0 }, rub);
+ cb->setGraphicsPipeline(m_graphicsPipeline.get());
+ auto size = m_swapChain->currentPixelSize();
+ cb->setViewport({ 0, 0, float(size.width()), float(size.height()) });
+ cb->setShaderResources(m_shaderResourceBindings.get());
+
+ quint32 vertexOffset = quint32(sizeof(float)) * 16 * frameRotationIndex;
+ const QRhiCommandBuffer::VertexInput vbufBinding(m_vertexBuf.get(), vertexOffset);
+ cb->setVertexInput(0, 1, &vbufBinding);
+ cb->draw(4);
+
+ if (m_hasSubtitle) {
+ cb->setGraphicsPipeline(m_subtitlePipeline.get());
+ cb->setShaderResources(m_subtitleResourceBindings.get());
+ const QRhiCommandBuffer::VertexInput vbufBinding(m_vertexBuf.get(), 0);
+ cb->setVertexInput(0, 1, &vbufBinding);
+ cb->draw(4);
+ }
+
+ cb->endPass();
+
+ m_rhi->endFrame(m_swapChain.get());
+}
+
+/*!
+ \class QVideoWindow
+ \internal
+*/
+QVideoWindow::QVideoWindow(QScreen *screen)
+ : QWindow(screen)
+ , d(new QVideoWindowPrivate(this))
+{
+}
+
+QVideoWindow::QVideoWindow(QWindow *parent)
+ : QWindow(parent)
+ , d(new QVideoWindowPrivate(this))
+{
+}
+
+QVideoWindow::~QVideoWindow() = default;
+
+QVideoSink *QVideoWindow::videoSink() const
+{
+ return d->m_sink.get();
+}
+
+Qt::AspectRatioMode QVideoWindow::aspectRatioMode() const
+{
+ return d->aspectRatioMode;
+}
+
+void QVideoWindow::setAspectRatioMode(Qt::AspectRatioMode mode)
+{
+ if (d->aspectRatioMode == mode)
+ return;
+ d->aspectRatioMode = mode;
+ emit aspectRatioModeChanged(mode);
+}
+
+bool QVideoWindow::event(QEvent *e)
+{
+ switch (e->type()) {
+ case QEvent::UpdateRequest:
+ d->render();
+ return true;
+
+ case QEvent::PlatformSurface:
+ // this is the proper time to tear down the swapchain (while the native window and surface are still around)
+ if (static_cast<QPlatformSurfaceEvent *>(e)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
+ d->releaseSwapChain();
+ d->isExposed = false;
+ }
+ break;
+ case QEvent::Expose:
+ d->isExposed = isExposed();
+ if (d->isExposed)
+ d->render();
+ return true;
+
+ default:
+ break;
+ }
+
+ return QWindow::event(e);
+}
+
+void QVideoWindow::resizeEvent(QResizeEvent *resizeEvent)
+{
+ if (!d->backingStore)
+ return;
+ if (!d->initialized)
+ d->init();
+ d->backingStore->resize(resizeEvent->size());
+}
+
+void QVideoWindow::setVideoFrame(const QVideoFrame &frame)
+{
+ if (d->m_currentFrame.subtitleText() != frame.subtitleText())
+ d->m_subtitleDirty = true;
+ d->m_currentFrame = frame;
+ d->m_texturesDirty = true;
+ if (d->isExposed)
+ requestUpdate();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qvideowindow_p.cpp"
diff --git a/src/multimedia/video/qvideowindow_p.h b/src/multimedia/video/qvideowindow_p.h
new file mode 100644
index 000000000..3305d3b40
--- /dev/null
+++ b/src/multimedia/video/qvideowindow_p.h
@@ -0,0 +1,127 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QVIDEOWINDOW_P_H
+#define QVIDEOWINDOW_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QWindow>
+#include <QOffscreenSurface>
+#include <qtextlayout.h>
+#include <rhi/qrhi.h>
+#include <qvideoframe.h>
+#include <private/qplatformvideosink_p.h>
+#include <private/qvideotexturehelper_p.h>
+#include <qbackingstore.h>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoWindow;
+
+class QVideoWindowPrivate {
+public:
+ QVideoWindowPrivate(QVideoWindow *q);
+ ~QVideoWindowPrivate();
+ bool canRender() const { return m_useRhi; }
+
+ QRhi *rhi() const { return m_rhi.get(); }
+
+ void init();
+ void render();
+
+ void initRhi();
+
+ void resizeSwapChain();
+ void releaseSwapChain();
+
+ void updateTextures(QRhiResourceUpdateBatch *rub);
+ void updateSubtitle(QRhiResourceUpdateBatch *rub, const QSize &frameSize);
+
+ void setupGraphicsPipeline(QRhiGraphicsPipeline *pipeline, QRhiShaderResourceBindings *bindings, const QVideoFrameFormat &fmt);
+
+ QVideoWindow *q = nullptr;
+ Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio;
+
+ QBackingStore *backingStore = nullptr;
+
+#if QT_CONFIG(opengl)
+ std::unique_ptr<QOffscreenSurface> m_fallbackSurface;
+#endif
+ std::unique_ptr<QRhi> m_rhi;
+ std::unique_ptr<QRhiSwapChain> m_swapChain;
+ std::unique_ptr<QRhiRenderPassDescriptor> m_renderPass;
+
+ std::unique_ptr<QRhiBuffer> m_vertexBuf;
+ bool m_vertexBufReady = false;
+ std::unique_ptr<QRhiBuffer> m_uniformBuf;
+ std::unique_ptr<QVideoFrameTextures> m_frameTextures;
+ std::unique_ptr<QRhiSampler> m_textureSampler;
+ std::unique_ptr<QRhiShaderResourceBindings> m_shaderResourceBindings;
+ std::unique_ptr<QRhiGraphicsPipeline> m_graphicsPipeline;
+
+ std::unique_ptr<QRhiTexture> m_subtitleTexture;
+ std::unique_ptr<QRhiShaderResourceBindings> m_subtitleResourceBindings;
+ std::unique_ptr<QRhiGraphicsPipeline> m_subtitlePipeline;
+ std::unique_ptr<QRhiBuffer> m_subtitleUniformBuf;
+
+ std::unique_ptr<QVideoSink> m_sink;
+ QRhi::Implementation m_graphicsApi = QRhi::Null;
+ QVideoFrame m_currentFrame;
+ QVideoTextureHelper::SubtitleLayout m_subtitleLayout;
+
+ enum { NVideoFrameSlots = 4 };
+ QVideoFrame m_videoFrameSlots[NVideoFrameSlots];
+
+ bool initialized = false;
+ bool isExposed = false;
+ bool m_useRhi = true;
+ bool m_hasSwapChain = false;
+ bool m_texturesDirty = true;
+ bool m_subtitleDirty = false;
+ bool m_hasSubtitle = false;
+ QVideoFrameFormat format;
+};
+
+class Q_MULTIMEDIA_EXPORT QVideoWindow : public QWindow
+{
+ Q_OBJECT
+public:
+ explicit QVideoWindow(QScreen *screen = nullptr);
+ explicit QVideoWindow(QWindow *parent);
+ ~QVideoWindow();
+
+ Q_INVOKABLE QVideoSink *videoSink() const;
+
+ Qt::AspectRatioMode aspectRatioMode() const;
+
+public Q_SLOTS:
+ void setAspectRatioMode(Qt::AspectRatioMode mode);
+
+Q_SIGNALS:
+ void aspectRatioModeChanged(Qt::AspectRatioMode mode);
+
+protected:
+ bool event(QEvent *e) override;
+ void resizeEvent(QResizeEvent *) override;
+
+private Q_SLOTS:
+ void setVideoFrame(const QVideoFrame &frame);
+
+private:
+ friend class QVideoWindowPrivate;
+ std::unique_ptr<QVideoWindowPrivate> d;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/video/video.pri b/src/multimedia/video/video.pri
deleted file mode 100644
index a3668ba4a..000000000
--- a/src/multimedia/video/video.pri
+++ /dev/null
@@ -1,37 +0,0 @@
-
-INCLUDEPATH += video
-
-PUBLIC_HEADERS += \
- video/qabstractvideobuffer.h \
- video/qabstractvideosurface.h \
- video/qvideoframe.h \
- video/qvideosurfaceformat.h \
- video/qvideoprobe.h \
- video/qabstractvideofilter.h
-
-PRIVATE_HEADERS += \
- video/qabstractvideobuffer_p.h \
- video/qimagevideobuffer_p.h \
- video/qmemoryvideobuffer_p.h \
- video/qvideooutputorientationhandler_p.h \
- video/qvideosurfaceoutput_p.h \
- video/qvideoframeconversionhelper_p.h \
- video/qvideosurfaces_p.h
-
-SOURCES += \
- video/qabstractvideobuffer.cpp \
- video/qabstractvideosurface.cpp \
- video/qimagevideobuffer.cpp \
- video/qmemoryvideobuffer.cpp \
- video/qvideoframe.cpp \
- video/qvideooutputorientationhandler.cpp \
- video/qvideosurfaceformat.cpp \
- video/qvideosurfaceoutput.cpp \
- video/qvideoprobe.cpp \
- video/qabstractvideofilter.cpp \
- video/qvideoframeconversionhelper.cpp \
- video/qvideosurfaces.cpp
-
-SSE2_SOURCES += video/qvideoframeconversionhelper_sse2.cpp
-SSSE3_SOURCES += video/qvideoframeconversionhelper_ssse3.cpp
-AVX2_SOURCES += video/qvideoframeconversionhelper_avx2.cpp
diff --git a/src/multimedia/wasm/qwasmaudiodevice.cpp b/src/multimedia/wasm/qwasmaudiodevice.cpp
new file mode 100644
index 000000000..c87a0ad54
--- /dev/null
+++ b/src/multimedia/wasm/qwasmaudiodevice.cpp
@@ -0,0 +1,56 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmaudiodevice_p.h"
+#include <emscripten.h>
+#include <emscripten/val.h>
+#include <emscripten/bind.h>
+
+#include <AL/al.h>
+#include <AL/alc.h>
+
+QT_BEGIN_NAMESPACE
+
+QWasmAudioDevice::QWasmAudioDevice(const char *device, const char *desc, bool isDef, QAudioDevice::Mode mode)
+ : QAudioDevicePrivate(device, mode)
+{
+ description = QString::fromUtf8(desc);
+
+ isDefault = isDef;
+ minimumChannelCount = 1;
+ maximumChannelCount = 2;
+ minimumSampleRate = 8000;
+ maximumSampleRate = 96000; // js AudioContext max according to docs
+
+ // native openAL formats
+ supportedSampleFormats.append(QAudioFormat::UInt8);
+ supportedSampleFormats.append(QAudioFormat::Int16);
+
+ // Browsers use 32bit floats as native, but emscripten reccomends checking for the exension.
+ if (alIsExtensionPresent("AL_EXT_float32"))
+ supportedSampleFormats.append(QAudioFormat::Float);
+
+ preferredFormat.setChannelCount(2);
+
+ // FIXME: firefox
+ // An AudioContext was prevented from starting automatically.
+ // It must be created or resumed after a user gesture on the page.
+ emscripten::val audioContext = emscripten::val::global("window")["AudioContext"].new_();
+ if (audioContext == emscripten::val::undefined())
+ audioContext = emscripten::val::global("window")["webkitAudioContext"].new_();
+
+ if (audioContext != emscripten::val::undefined()) {
+ audioContext.call<void>("resume");
+ int sRate = audioContext["sampleRate"].as<int>();
+ audioContext.call<void>("close");
+ preferredFormat.setSampleRate(sRate);
+ }
+
+ auto f = QAudioFormat::Float;
+
+ if (!supportedSampleFormats.contains(f))
+ f = QAudioFormat::Int16;
+ preferredFormat.setSampleFormat(f);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/wasm/qwasmaudiodevice_p.h b/src/multimedia/wasm/qwasmaudiodevice_p.h
new file mode 100644
index 000000000..cc86c1575
--- /dev/null
+++ b/src/multimedia/wasm/qwasmaudiodevice_p.h
@@ -0,0 +1,31 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMAUDIODEVICEINFO_H
+#define QWASMAUDIODEVICEINFO_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qaudiodevice_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QWasmAudioDevice : public QAudioDevicePrivate
+{
+public:
+ QWasmAudioDevice(const char *device, const char *description, bool isDefault, QAudioDevice::Mode mode);
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMAUDIODEVICEINFO_H
diff --git a/src/multimedia/wasm/qwasmaudiosink.cpp b/src/multimedia/wasm/qwasmaudiosink.cpp
new file mode 100644
index 000000000..d1068e744
--- /dev/null
+++ b/src/multimedia/wasm/qwasmaudiosink.cpp
@@ -0,0 +1,464 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmaudiosink_p.h"
+
+
+#include <emscripten.h>
+#include <AL/al.h>
+#include <AL/alc.h>
+#include <QDebug>
+#include <QtMath>
+#include <QIODevice>
+
+// non native al formats (AL_EXT_float32)
+#define AL_FORMAT_MONO_FLOAT32 0x10010
+#define AL_FORMAT_STEREO_FLOAT32 0x10011
+
+constexpr unsigned int DEFAULT_BUFFER_DURATION = 50'000;
+
+class ALData {
+public:
+ ALCcontext *context = nullptr;
+ ALCdevice *device = nullptr;
+ ALuint source;
+ ALuint *buffers = nullptr;
+ ALuint *buffer = nullptr;
+ ALenum format;
+};
+
+QT_BEGIN_NAMESPACE
+
+class QWasmAudioSinkDevice : public QIODevice {
+
+ QWasmAudioSink *m_out;
+
+public:
+ QWasmAudioSinkDevice(QWasmAudioSink *parent);
+
+protected:
+ qint64 readData(char *data, qint64 maxlen) override;
+ qint64 writeData(const char *data, qint64 len) override;
+};
+
+QWasmAudioSink::QWasmAudioSink(const QByteArray &device, QObject *parent)
+ : QPlatformAudioSink(parent),
+ m_name(device),
+ m_timer(new QTimer(this))
+{
+ m_timer->setSingleShot(false);
+ aldata = new ALData();
+ connect(m_timer, &QTimer::timeout, this, [this](){
+ if (m_pullMode)
+ nextALBuffers();
+ else {
+ unloadALBuffers();
+ m_device->write(nullptr, 0);
+ updateState();
+ }
+ });
+}
+
+QWasmAudioSink::~QWasmAudioSink()
+{
+ delete aldata;
+ if (m_tmpData)
+ delete[] m_tmpData;
+}
+
+void QWasmAudioSink::start(QIODevice *device)
+{
+ Q_ASSERT(device);
+ Q_ASSERT(device->openMode().testFlag(QIODevice::ReadOnly));
+ m_device = device;
+ start(true);
+}
+
+QIODevice *QWasmAudioSink::start()
+{
+ m_device = new QWasmAudioSinkDevice(this);
+ m_device->open(QIODevice::WriteOnly);
+ start(false);
+ return m_device;
+}
+
+void QWasmAudioSink::start(bool mode)
+{
+ auto formatError = [this](){
+ qWarning() << "Unsupported audio format " << m_format;
+ setError(QAudio::OpenError);
+ };
+ switch (m_format.sampleFormat()) {
+ case QAudioFormat::UInt8:
+ switch (m_format.channelCount()) {
+ case 1:
+ aldata->format = AL_FORMAT_MONO8;
+ break;
+ case 2:
+ aldata->format = AL_FORMAT_STEREO8;
+ break;
+ default:
+ return formatError();
+ }
+ break;
+ case QAudioFormat::Int16:
+ switch (m_format.channelCount()) {
+ case 1:
+ aldata->format = AL_FORMAT_MONO16;
+ break;
+ case 2:
+ aldata->format = AL_FORMAT_STEREO16;
+ break;
+ default:
+ return formatError();
+ }
+ break;
+ case QAudioFormat::Float:
+ switch (m_format.channelCount()) {
+ case 1:
+ aldata->format = AL_FORMAT_MONO_FLOAT32;
+ break;
+ case 2:
+ aldata->format = AL_FORMAT_STEREO_FLOAT32;
+ break;
+ default:
+ return formatError();
+ }
+ break;
+ default:
+ return formatError();
+ }
+
+ alGetError();
+ aldata->device = alcOpenDevice(m_name.data());
+ if (!aldata->device) {
+ qWarning() << "Failed to open audio device" << alGetString(alGetError());
+ return setError(QAudio::OpenError);
+ }
+ ALint attrlist[] = {ALC_FREQUENCY, m_format.sampleRate(), 0};
+ aldata->context = alcCreateContext(aldata->device, attrlist);
+
+ if (!aldata->context) {
+ qWarning() << "Failed to create audio context" << alGetString(alGetError());
+ return setError(QAudio::OpenError);
+ }
+ alcMakeContextCurrent(aldata->context);
+
+ alGenSources(1, &aldata->source);
+
+ if (m_bufferSize > 0)
+ m_bufferFragmentsCount = qMax(2,qCeil((qreal)m_bufferSize/(m_bufferFragmentSize)));
+ m_bufferSize = m_bufferFragmentsCount * m_bufferFragmentSize;
+ aldata->buffers = new ALuint[m_bufferFragmentsCount];
+ aldata->buffer = aldata->buffers;
+ alGenBuffers(m_bufferFragmentsCount, aldata->buffers);
+ m_processed = 0;
+ m_tmpDataOffset = 0;
+ m_pullMode = mode;
+ alSourcef(aldata->source, AL_GAIN, m_volume);
+ if (m_pullMode)
+ loadALBuffers();
+ m_timer->setInterval(DEFAULT_BUFFER_DURATION / 3000);
+ m_timer->start();
+ if (m_pullMode)
+ alSourcePlay(aldata->source);
+ m_running = true;
+ m_elapsedTimer.start();
+ updateState();
+}
+
+void QWasmAudioSink::stop()
+{
+ if (!m_running)
+ return;
+ m_elapsedTimer.invalidate();
+ alSourceStop(aldata->source);
+ alSourceRewind(aldata->source);
+ m_timer->stop();
+ m_bufferFragmentsBusyCount = 0;
+ alDeleteSources(1, &aldata->source);
+ alDeleteBuffers(m_bufferFragmentsCount, aldata->buffers);
+ delete[] aldata->buffers;
+ alcMakeContextCurrent(nullptr);
+ alcDestroyContext(aldata->context);
+ alcCloseDevice(aldata->device);
+ m_running = false;
+ m_processed = 0;
+ if (!m_pullMode)
+ m_device->deleteLater();
+ updateState();
+}
+
+void QWasmAudioSink::reset()
+{
+ stop();
+ m_error = QAudio::NoError;
+}
+
+void QWasmAudioSink::suspend()
+{
+ if (!m_running)
+ return;
+
+ m_suspendedInState = m_state;
+ alSourcePause(aldata->source);
+}
+
+void QWasmAudioSink::resume()
+{
+ if (!m_running)
+ return;
+
+ alSourcePlay(aldata->source);
+}
+
+qsizetype QWasmAudioSink::bytesFree() const
+{
+ int processed;
+ alGetSourcei(aldata->source, AL_BUFFERS_PROCESSED, &processed);
+ return m_running ? m_bufferFragmentSize * (m_bufferFragmentsCount - m_bufferFragmentsBusyCount
+ + (qsizetype)processed) : 0;
+}
+
+void QWasmAudioSink::setBufferSize(qsizetype value)
+{
+ if (m_running)
+ return;
+
+ m_bufferSize = value;
+}
+
+qsizetype QWasmAudioSink::bufferSize() const
+{
+ return m_bufferSize;
+}
+
+qint64 QWasmAudioSink::processedUSecs() const
+{
+ int processed;
+ alGetSourcei(aldata->source, AL_BUFFERS_PROCESSED, &processed);
+ return m_format.durationForBytes(m_processed + m_format.bytesForDuration(
+ DEFAULT_BUFFER_DURATION * processed));
+}
+
+QAudio::Error QWasmAudioSink::error() const
+{
+ return m_error;
+}
+
+QAudio::State QWasmAudioSink::state() const
+{
+ if (!m_running)
+ return QAudio::StoppedState;
+ ALint state;
+ alGetSourcei(aldata->source, AL_SOURCE_STATE, &state);
+ switch (state) {
+ case AL_INITIAL:
+ return QAudio::IdleState;
+ case AL_PLAYING:
+ return QAudio::ActiveState;
+ case AL_PAUSED:
+ return QAudio::SuspendedState;
+ case AL_STOPPED:
+ return m_running ? QAudio::IdleState : QAudio::StoppedState;
+ }
+ return QAudio::StoppedState;
+}
+
+void QWasmAudioSink::setFormat(const QAudioFormat &fmt)
+{
+ if (m_running)
+ return;
+ m_format = fmt;
+ if (m_tmpData)
+ delete[] m_tmpData;
+ m_bufferFragmentSize = m_format.bytesForDuration(DEFAULT_BUFFER_DURATION);
+ m_bufferSize = m_bufferFragmentSize * m_bufferFragmentsCount;
+ m_tmpData = new char[m_bufferFragmentSize];
+}
+
+QAudioFormat QWasmAudioSink::format() const
+{
+ return m_format;
+}
+
+void QWasmAudioSink::setVolume(qreal volume)
+{
+ if (m_volume == volume)
+ return;
+ m_volume = volume;
+ if (m_running)
+ alSourcef(aldata->source, AL_GAIN, volume);
+}
+
+qreal QWasmAudioSink::volume() const
+{
+ return m_volume;
+}
+
+void QWasmAudioSink::loadALBuffers()
+{
+ if (m_bufferFragmentsBusyCount == m_bufferFragmentsCount)
+ return;
+
+ if (m_device->bytesAvailable() == 0) {
+ return;
+ }
+
+ auto size = m_device->read(m_tmpData + m_tmpDataOffset, m_bufferFragmentSize -
+ m_tmpDataOffset);
+ m_tmpDataOffset += size;
+ if (!m_tmpDataOffset || (m_tmpDataOffset != m_bufferFragmentSize &&
+ m_bufferFragmentsBusyCount >= m_bufferFragmentsCount * 2 / 3))
+ return;
+
+ alBufferData(*aldata->buffer, aldata->format, m_tmpData, m_tmpDataOffset,
+ m_format.sampleRate());
+ m_tmpDataOffset = 0;
+ alGetError();
+ alSourceQueueBuffers(aldata->source, 1, aldata->buffer);
+ if (alGetError())
+ return;
+
+ m_bufferFragmentsBusyCount++;
+ m_processed += size;
+ if (++aldata->buffer == aldata->buffers + m_bufferFragmentsCount)
+ aldata->buffer = aldata->buffers;
+}
+
+void QWasmAudioSink::unloadALBuffers()
+{
+ int processed;
+ alGetSourcei(aldata->source, AL_BUFFERS_PROCESSED, &processed);
+
+ if (processed) {
+ auto head = aldata->buffer - m_bufferFragmentsBusyCount;
+ if (head < aldata->buffers) {
+ if (head + processed > aldata->buffers) {
+ auto batch = m_bufferFragmentsBusyCount - (aldata->buffer - aldata->buffers);
+ alGetError();
+ alSourceUnqueueBuffers(aldata->source, batch, head + m_bufferFragmentsCount);
+ if (!alGetError()) {
+ m_bufferFragmentsBusyCount -= batch;
+ m_processed += m_bufferFragmentSize*batch;
+ }
+ processed -= batch;
+ if (!processed)
+ return;
+ head = aldata->buffers;
+ } else {
+ head += m_bufferFragmentsCount;
+ }
+ }
+ alGetError();
+ alSourceUnqueueBuffers(aldata->source, processed, head);
+ if (!alGetError())
+ m_bufferFragmentsBusyCount -= processed;
+ }
+}
+
+void QWasmAudioSink::nextALBuffers()
+{
+ updateState();
+ unloadALBuffers();
+ loadALBuffers();
+ ALint state;
+ alGetSourcei(aldata->source, AL_SOURCE_STATE, &state);
+ if (state != AL_PLAYING && m_error == QAudio::NoError)
+ alSourcePlay(aldata->source);
+ updateState();
+}
+
+void QWasmAudioSink::updateState()
+{
+ auto current = state();
+ if (m_state == current)
+ return;
+ m_state = current;
+
+ if (m_state == QAudio::IdleState && m_running && m_device->bytesAvailable() == 0)
+ setError(QAudio::UnderrunError);
+
+ emit stateChanged(m_state);
+
+}
+
+void QWasmAudioSink::setError(QAudio::Error error)
+{
+ if (error == m_error)
+ return;
+ m_error = error;
+ if (error != QAudio::NoError) {
+ m_timer->stop();
+ alSourceRewind(aldata->source);
+ }
+
+ emit errorChanged(error);
+}
+
+QWasmAudioSinkDevice::QWasmAudioSinkDevice(QWasmAudioSink *parent)
+ : QIODevice(parent),
+ m_out(parent)
+{
+}
+
+qint64 QWasmAudioSinkDevice::readData(char *data, qint64 maxlen)
+{
+ Q_UNUSED(data)
+ Q_UNUSED(maxlen)
+ return 0;
+}
+
+
+qint64 QWasmAudioSinkDevice::writeData(const char *data, qint64 len)
+{
+ ALint state;
+ alGetSourcei(m_out->aldata->source, AL_SOURCE_STATE, &state);
+ if (state != AL_INITIAL)
+ m_out->unloadALBuffers();
+ if (m_out->m_bufferFragmentsBusyCount < m_out->m_bufferFragmentsCount) {
+ bool exceeds = m_out->m_tmpDataOffset + len > m_out->m_bufferFragmentSize;
+ bool flush = m_out->m_bufferFragmentsBusyCount < m_out->m_bufferFragmentsCount * 2 / 3 ||
+ m_out->m_tmpDataOffset + len >= m_out->m_bufferFragmentSize;
+ const char *read;
+ char *tmp = m_out->m_tmpData;
+ int size = 0;
+ if (m_out->m_tmpDataOffset && exceeds) {
+ size = m_out->m_tmpDataOffset + len;
+ tmp = new char[m_out->m_tmpDataOffset + len];
+ std::memcpy(tmp, m_out->m_tmpData, m_out->m_tmpDataOffset);
+ }
+ if (flush && !m_out->m_tmpDataOffset) {
+ read = data;
+ size = len;
+ } else {
+ std::memcpy(tmp + m_out->m_tmpDataOffset, data, len);
+ read = tmp;
+ if (!exceeds) {
+ m_out->m_tmpDataOffset += len;
+ size = m_out->m_tmpDataOffset;
+ }
+ }
+ m_out->m_processed += size;
+ if (size && flush) {
+ alBufferData(*m_out->aldata->buffer, m_out->aldata->format, read, size,
+ m_out->m_format.sampleRate());
+ if (tmp && tmp != m_out->m_tmpData)
+ delete[] tmp;
+ m_out->m_tmpDataOffset = 0;
+ alGetError();
+ alSourceQueueBuffers(m_out->aldata->source, 1, m_out->aldata->buffer);
+ if (alGetError())
+ return 0;
+ m_out->m_bufferFragmentsBusyCount++;
+ if (++m_out->aldata->buffer == m_out->aldata->buffers + m_out->m_bufferFragmentsCount)
+ m_out->aldata->buffer = m_out->aldata->buffers;
+ if (state != AL_PLAYING)
+ alSourcePlay(m_out->aldata->source);
+ }
+ return len;
+ }
+ return 0;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/wasm/qwasmaudiosink_p.h b/src/multimedia/wasm/qwasmaudiosink_p.h
new file mode 100644
index 000000000..975b7f6cc
--- /dev/null
+++ b/src/multimedia/wasm/qwasmaudiosink_p.h
@@ -0,0 +1,89 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMAUDIOSINK_H
+#define QWASMAUDIOSINK_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qaudiosystem_p.h>
+#include <QTimer>
+#include <QElapsedTimer>
+
+class ALData;
+class QIODevice;
+
+QT_BEGIN_NAMESPACE
+
+class QWasmAudioSink : public QPlatformAudioSink
+{
+ Q_OBJECT
+
+ QByteArray m_name;
+ ALData *aldata = nullptr;
+ QTimer *m_timer = nullptr;
+ QIODevice *m_device = nullptr;
+ QAudioFormat m_format;
+ QAudio::Error m_error = QAudio::NoError;
+ bool m_running = false;
+ QAudio::State m_state = QAudio::StoppedState;
+ QAudio::State m_suspendedInState = QAudio::SuspendedState;
+ int m_bufferSize = 0;
+ quint64 m_processed = 0;
+ QElapsedTimer m_elapsedTimer;
+ int m_bufferFragmentsCount = 10;
+ int m_notifyInterval = 0;
+ char *m_tmpData = nullptr;
+ int m_bufferFragmentSize = 0;
+ int m_lastNotified = 0;
+ int m_tmpDataOffset = 0;
+ int m_bufferFragmentsBusyCount = 0;
+ bool m_pullMode;
+ qreal m_volume = 1;
+
+ void loadALBuffers();
+ void unloadALBuffers();
+ void nextALBuffers();
+
+private slots:
+ void updateState();
+ void setError(QAudio::Error);
+
+public:
+ QWasmAudioSink(const QByteArray &device, QObject *parent);
+ ~QWasmAudioSink();
+
+public:
+ void start(QIODevice *device) override;
+ QIODevice *start() override;
+ void start(bool mode);
+ void stop() override;
+ void reset() override;
+ void suspend() override;
+ void resume() override;
+ qsizetype bytesFree() const override;
+ void setBufferSize(qsizetype value) override;
+ qsizetype bufferSize() const override;
+ qint64 processedUSecs() const override;
+ QAudio::Error error() const override;
+ QAudio::State state() const override;
+ void setFormat(const QAudioFormat &fmt) override;
+ QAudioFormat format() const override;
+ void setVolume(qreal volume) override;
+ qreal volume() const override;
+
+ friend class QWasmAudioSinkDevice;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMAUDIOSINK_H
diff --git a/src/multimedia/wasm/qwasmaudiosource.cpp b/src/multimedia/wasm/qwasmaudiosource.cpp
new file mode 100644
index 000000000..81f222c4b
--- /dev/null
+++ b/src/multimedia/wasm/qwasmaudiosource.cpp
@@ -0,0 +1,315 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmaudiosource_p.h"
+
+#include <emscripten.h>
+#include <AL/al.h>
+#include <AL/alc.h>
+#include <QDataStream>
+#include <QDebug>
+#include <QtMath>
+#include <private/qaudiohelpers_p.h>
+#include <QIODevice>
+
+QT_BEGIN_NAMESPACE
+
+#define AL_FORMAT_MONO_FLOAT32 0x10010
+#define AL_FORMAT_STEREO_FLOAT32 0x10011
+
+constexpr unsigned int DEFAULT_BUFFER_DURATION = 50'000;
+
+class QWasmAudioSourceDevice : public QIODevice
+{
+ QWasmAudioSource *m_in;
+
+public:
+ explicit QWasmAudioSourceDevice(QWasmAudioSource *in);
+
+protected:
+ qint64 readData(char *data, qint64 maxlen) override;
+ qint64 writeData(const char *data, qint64 len) override;
+};
+
+class ALData {
+public:
+ ALCdevice *device = nullptr;
+ ALCcontext *context = nullptr;
+};
+
+void QWasmAudioSource::setError(const QAudio::Error &error)
+{
+ if (m_error == error)
+ return;
+ m_error = error;
+ emit errorChanged(error);
+}
+
+void QWasmAudioSource::writeBuffer()
+{
+ int samples = 0;
+ alcGetIntegerv(aldata->device, ALC_CAPTURE_SAMPLES, 1, &samples);
+ samples = qMin(samples, m_format.framesForBytes(m_bufferSize));
+ auto bytes = m_format.bytesForFrames(samples);
+ auto err = alcGetError(aldata->device);
+ alcCaptureSamples(aldata->device, m_tmpData, samples);
+ err = alcGetError(aldata->device);
+ if (err) {
+ qWarning() << alcGetString(aldata->device, err);
+ return setError(QAudio::FatalError);
+ }
+ if (m_volume < 1)
+ QAudioHelperInternal::qMultiplySamples(m_volume, m_format, m_tmpData, m_tmpData, bytes);
+ m_processed += bytes;
+ m_device->write(m_tmpData,bytes);
+}
+
+QWasmAudioSource::QWasmAudioSource(const QByteArray &device , QObject *parent)
+ : QPlatformAudioSource(parent),
+ m_name(device),
+ m_timer(new QTimer(this))
+{
+ if (device.contains("Emscripten")) {
+ aldata = new ALData();
+ connect(m_timer, &QTimer::timeout, this, [this](){
+ Q_ASSERT(m_running);
+ if (m_pullMode)
+ writeBuffer();
+ else if (bytesReady() > 0)
+ emit m_device->readyRead();
+ });
+ }
+}
+
+void QWasmAudioSource::start(QIODevice *device)
+{
+ m_device = device;
+ start(true);
+}
+
+QIODevice *QWasmAudioSource::start()
+{
+ m_device = new QWasmAudioSourceDevice(this);
+ m_device->open(QIODevice::ReadOnly);
+ start(false);
+ return m_device;
+}
+
+void QWasmAudioSource::start(bool mode)
+{
+ m_pullMode = mode;
+ auto formatError = [this](){
+ qWarning() << "Unsupported audio format " << m_format;
+ setError(QAudio::OpenError);
+ };
+ ALCenum format;
+ switch (m_format.sampleFormat()) {
+ case QAudioFormat::UInt8:
+ switch (m_format.channelCount()) {
+ case 1:
+ format = AL_FORMAT_MONO8;
+ break;
+ case 2:
+ format = AL_FORMAT_STEREO8;
+ break;
+ default:
+ return formatError();
+ }
+ break;
+ case QAudioFormat::Int16:
+ switch (m_format.channelCount()) {
+ case 1:
+ format = AL_FORMAT_MONO16;
+ break;
+ case 2:
+ format = AL_FORMAT_STEREO16;
+ break;
+ default:
+ return formatError();
+ }
+ break;
+ case QAudioFormat::Float:
+ switch (m_format.channelCount()) {
+ case 1:
+ format = AL_FORMAT_MONO_FLOAT32;
+ break;
+ case 2:
+ format = AL_FORMAT_STEREO_FLOAT32;
+ break;
+ default:
+ return formatError();
+ }
+ break;
+ default:
+ return formatError();
+ }
+ if (m_tmpData)
+ delete[] m_tmpData;
+ if (m_pullMode)
+ m_tmpData = new char[m_bufferSize];
+ else
+ m_tmpData = nullptr;
+ m_timer->setInterval(m_format.durationForBytes(m_bufferSize) / 3000);
+ m_timer->start();
+
+ alcGetError(aldata->device); // clear error state
+ aldata->device = alcCaptureOpenDevice(m_name.data(), m_format.sampleRate(), format,
+ m_format.framesForBytes(m_bufferSize));
+
+ auto err = alcGetError(aldata->device);
+ if (err) {
+ qWarning() << "alcCaptureOpenDevice" << alcGetString(aldata->device, err);
+ return setError(QAudio::OpenError);
+ }
+ alcCaptureStart(aldata->device);
+ m_elapsedTimer.start();
+ auto cerr = alcGetError(aldata->device);
+ if (cerr) {
+ qWarning() << "alcCaptureStart" << alcGetString(aldata->device, cerr);
+ return setError(QAudio::OpenError);
+ }
+ m_processed = 0;
+ m_running = true;
+}
+
+void QWasmAudioSource::stop()
+{
+ if (m_pullMode)
+ writeBuffer();
+ alcCaptureStop(aldata->device);
+ alcCaptureCloseDevice(aldata->device);
+ m_elapsedTimer.invalidate();
+ if (m_tmpData) {
+ delete[] m_tmpData;
+ m_tmpData = nullptr;
+ }
+ if (!m_pullMode)
+ m_device->deleteLater();
+ m_timer->stop();
+ m_running = false;
+}
+
+void QWasmAudioSource::reset()
+{
+ stop();
+ if (m_tmpData) {
+ delete[] m_tmpData;
+ m_tmpData = nullptr;
+ }
+ m_running = false;
+ m_processed = 0;
+ m_error = QAudio::NoError;
+}
+
+void QWasmAudioSource::suspend()
+{
+ if (!m_running)
+ return;
+
+ m_suspended = true;
+ alcCaptureStop(aldata->device);
+}
+
+void QWasmAudioSource::resume()
+{
+ if (!m_running)
+ return;
+
+ m_suspended = false;
+ alcCaptureStart(aldata->device);
+}
+
+qsizetype QWasmAudioSource::bytesReady() const
+{
+ if (!m_running)
+ return 0;
+ int samples;
+ alcGetIntegerv(aldata->device, ALC_CAPTURE_SAMPLES, 1, &samples);
+ return m_format.bytesForFrames(samples);
+}
+
+void QWasmAudioSource::setBufferSize(qsizetype value)
+{
+ if (!m_running)
+ return;
+ m_bufferSize = value;
+}
+
+qsizetype QWasmAudioSource::bufferSize() const
+{
+ return m_bufferSize;
+}
+
+qint64 QWasmAudioSource::processedUSecs() const
+{
+ return m_format.durationForBytes(m_processed);
+}
+
+QAudio::Error QWasmAudioSource::error() const
+{
+ return m_error;
+}
+
+QAudio::State QWasmAudioSource::state() const
+{
+ if (m_running)
+ return QAudio::ActiveState;
+ else
+ return QAudio::StoppedState;
+}
+
+void QWasmAudioSource::setFormat(const QAudioFormat &fmt)
+{
+ m_format = fmt;
+ m_bufferSize = m_format.bytesForDuration(DEFAULT_BUFFER_DURATION);
+}
+
+QAudioFormat QWasmAudioSource::format() const
+{
+ return m_format;
+}
+
+void QWasmAudioSource::setVolume(qreal volume)
+{
+ m_volume = volume;
+}
+
+qreal QWasmAudioSource::volume() const
+{
+ return m_volume;
+}
+
+QWasmAudioSourceDevice::QWasmAudioSourceDevice(QWasmAudioSource *in) : QIODevice(in), m_in(in)
+{
+
+}
+
+qint64 QWasmAudioSourceDevice::readData(char *data, qint64 maxlen)
+{
+ int samples;
+ alcGetIntegerv(m_in->aldata->device, ALC_CAPTURE_SAMPLES, 1, &samples);
+ samples = qMin(samples, m_in->m_format.framesForBytes(maxlen));
+ auto bytes = m_in->m_format.bytesForFrames(samples);
+ alcGetError(m_in->aldata->device);
+ alcCaptureSamples(m_in->aldata->device, data, samples);
+ if (m_in->m_volume < 1)
+ QAudioHelperInternal::qMultiplySamples(m_in->m_volume, m_in->m_format, data, data, bytes);
+ auto err = alcGetError(m_in->aldata->device);
+ if (err) {
+ qWarning() << alcGetString(m_in->aldata->device, err);
+ m_in->setError(QAudio::FatalError);
+ return 0;
+ }
+ m_in->m_processed += bytes;
+ return bytes;
+}
+
+qint64 QWasmAudioSourceDevice::writeData(const char *data, qint64 len)
+{
+ Q_UNREACHABLE();
+ Q_UNUSED(data);
+ Q_UNUSED(len);
+ return 0;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/wasm/qwasmaudiosource_p.h b/src/multimedia/wasm/qwasmaudiosource_p.h
new file mode 100644
index 000000000..97b4ec52a
--- /dev/null
+++ b/src/multimedia/wasm/qwasmaudiosource_p.h
@@ -0,0 +1,75 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMAUDIOSOURCE_H
+#define QWASMAUDIOSOURCE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qaudiosystem_p.h>
+#include <QTimer>
+#include <QElapsedTimer>
+
+QT_BEGIN_NAMESPACE
+
+class ALData;
+
+class QWasmAudioSource : public QPlatformAudioSource
+{
+ Q_OBJECT
+
+ QByteArray m_name;
+ ALData *aldata = nullptr;
+ QTimer *m_timer = nullptr;
+ QIODevice *m_device = nullptr;
+ QAudioFormat m_format;
+ qreal m_volume = 1;
+ qsizetype m_bufferSize;
+ bool m_running = false;
+ bool m_suspended = false;
+ QAudio::Error m_error;
+ bool m_pullMode;
+ char *m_tmpData = nullptr;
+ QElapsedTimer m_elapsedTimer;
+ int m_notifyInterval = 0;
+ quint64 m_processed = 0;
+
+ void writeBuffer();
+public:
+ QWasmAudioSource(const QByteArray &device, QObject *parent);
+
+public:
+ void start(QIODevice *device) override;
+ QIODevice *start() override;
+ void start(bool mode);
+ void stop() override;
+ void reset() override;
+ void suspend() override;
+ void resume() override;
+ qsizetype bytesReady() const override;
+ void setBufferSize(qsizetype value) override;
+ qsizetype bufferSize() const override;
+ qint64 processedUSecs() const override;
+ QAudio::Error error() const override;
+ QAudio::State state() const override;
+ void setFormat(const QAudioFormat &fmt) override;
+ QAudioFormat format() const override;
+ void setVolume(qreal volume) override;
+ qreal volume() const override;
+
+ friend class QWasmAudioSourceDevice;
+ void setError(const QAudio::Error &error);
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMAUDIOSOURCE_H
diff --git a/src/multimedia/wasm/qwasmmediadevices.cpp b/src/multimedia/wasm/qwasmmediadevices.cpp
new file mode 100644
index 000000000..4e59fd161
--- /dev/null
+++ b/src/multimedia/wasm/qwasmmediadevices.cpp
@@ -0,0 +1,276 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmmediadevices_p.h"
+#include "private/qcameradevice_p.h"
+#include "private/qplatformmediaintegration_p.h"
+#include "qwasmaudiosource_p.h"
+#include "qwasmaudiosink_p.h"
+#include "qwasmaudiodevice_p.h"
+#include <AL/al.h>
+#include <AL/alc.h>
+
+#include <QMap>
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(qWasmMediaDevices, "qt.multimedia.wasm.mediadevices")
+
+QWasmCameraDevices::QWasmCameraDevices(QPlatformMediaIntegration *integration)
+ : QPlatformVideoDevices(integration)
+{
+ m_mediaDevices = QPlatformMediaIntegration::instance()->mediaDevices();
+}
+
+QList<QCameraDevice> QWasmCameraDevices::videoDevices() const
+{
+ QWasmMediaDevices *wasmMediaDevices = reinterpret_cast<QWasmMediaDevices *>(m_mediaDevices);
+ return wasmMediaDevices ? wasmMediaDevices->videoInputs() : QList<QCameraDevice>();
+}
+
+QWasmMediaDevices::QWasmMediaDevices()
+{
+ initDevices();
+}
+
+void QWasmMediaDevices::initDevices()
+{
+ if (m_initDone)
+ return;
+
+ m_initDone = true;
+ getOpenALAudioDevices();
+ getMediaDevices(); // asynchronous
+}
+
+QList<QAudioDevice> QWasmMediaDevices::audioInputs() const
+{
+ return m_audioInputs.values();
+}
+
+QList<QAudioDevice> QWasmMediaDevices::audioOutputs() const
+{
+ return m_audioOutputs.values();
+}
+
+QList<QCameraDevice> QWasmMediaDevices::videoInputs() const
+{
+ return m_cameraDevices.values();
+}
+
+QPlatformAudioSource *QWasmMediaDevices::createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ return new QWasmAudioSource(deviceInfo.id(), parent);
+}
+
+QPlatformAudioSink *QWasmMediaDevices::createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ return new QWasmAudioSink(deviceInfo.id(), parent);
+}
+
+void QWasmMediaDevices::parseDevices(emscripten::val devices)
+{
+ if (devices.isNull() || devices.isUndefined()) {
+ qWarning() << "Something went wrong enumerating devices";
+ return;
+ }
+
+ QList<std::string> cameraDevicesToRemove = m_cameraDevices.keys();
+ QList<std::string> audioOutputsToRemove;
+ QList<std::string> audioInputsToRemove;
+
+ if (m_firstInit) {
+ m_firstInit = false;
+ qWarning() << "m_audioInputs count" << m_audioInputs.count();
+
+ } else {
+ audioOutputsToRemove = m_audioOutputs.keys();
+ audioInputsToRemove = m_audioInputs.keys();
+ m_audioInputsAdded = false;
+ m_audioOutputsAdded = false;
+ }
+ m_videoInputsAdded = false;
+
+ bool m_videoInputsRemoved = false;
+ bool m_audioInputsRemoved = false;
+ bool m_audioOutputsRemoved = false;
+
+ for (int i = 0; i < devices["length"].as<int>(); i++) {
+
+ emscripten::val mediaDevice = devices[i];
+
+ std::string defaultDeviceLabel = "";
+
+ const std::string deviceKind = mediaDevice["kind"].as<std::string>();
+ const std::string label = mediaDevice["label"].as<std::string>();
+ const std::string deviceId = mediaDevice["deviceId"].as<std::string>();
+
+ qCDebug(qWasmMediaDevices) << QString::fromStdString(deviceKind)
+ << QString::fromStdString(deviceId)
+ << QString::fromStdString(label);
+
+ if (deviceKind.empty())
+ continue;
+
+ if (deviceId == std::string("default")) {
+ // chrome specifies the default device with this as deviceId
+ // and then prepends "Default - " with the name of the device
+ // in the label
+ if (label.empty())
+ continue;
+
+ defaultDeviceLabel = label;
+ continue;
+ }
+
+ const bool isDefault = false; // FIXME
+ // (defaultDeviceLabel.find(label) != std::string::npos);
+
+ if (deviceKind == std::string("videoinput")) {
+ if (!m_cameraDevices.contains(deviceId)) {
+ QCameraDevicePrivate *camera = new QCameraDevicePrivate; // QSharedData
+ camera->id = QString::fromStdString(deviceId).toUtf8();
+ camera->description = QString::fromUtf8(label.c_str());
+ camera->isDefault = isDefault;
+
+ m_cameraDevices.insert(deviceId, camera->create());
+ m_videoInputsAdded = true;
+ }
+ cameraDevicesToRemove.removeOne(deviceId);
+ } else if (deviceKind == std::string("audioinput")) {
+ if (!m_audioInputs.contains(deviceId)) {
+ m_audioInputs.insert(deviceId,
+ (new QWasmAudioDevice(deviceId.c_str(), label.c_str(),
+ isDefault, QAudioDevice::Input))
+ ->create());
+
+ m_audioInputsAdded = true;
+ }
+ audioInputsToRemove.removeOne(deviceId);
+ } else if (deviceKind == std::string("audiooutput")) {
+ if (!m_audioOutputs.contains(deviceId)) {
+ m_audioOutputs.insert(deviceId,
+ (new QWasmAudioDevice(deviceId.c_str(), label.c_str(),
+ isDefault, QAudioDevice::Input))
+ ->create());
+
+ m_audioOutputsAdded = true;
+ }
+ audioOutputsToRemove.removeOne(deviceId);
+ }
+ // if permissions are given label will hold the actual
+ // camera name, such as "Live! Cam Sync 1080p (041e:409d)"
+ }
+ if (!m_firstInit)
+ getOpenALAudioDevices();
+
+ // any left here were removed
+ int j = 0;
+ for (; j < cameraDevicesToRemove.count(); j++) {
+ m_cameraDevices.remove(cameraDevicesToRemove.at(j));
+ }
+ m_videoInputsRemoved = !cameraDevicesToRemove.isEmpty();
+
+ for (j = 0; j < audioInputsToRemove.count(); j++) {
+ m_audioInputs.remove(audioInputsToRemove.at(j));
+ }
+ m_audioInputsRemoved = !audioInputsToRemove.isEmpty();
+
+ for (j = 0; j < audioOutputsToRemove.count(); j++) {
+ m_audioOutputs.remove(audioOutputsToRemove.at(j));
+ }
+ m_audioOutputsRemoved = !audioOutputsToRemove.isEmpty();
+
+ if (m_videoInputsAdded || m_videoInputsRemoved)
+ emit videoInputsChanged();
+ if (m_audioInputsAdded || m_audioInputsRemoved)
+ emit audioInputsChanged();
+ if (m_audioOutputsAdded || m_audioOutputsRemoved)
+ emit audioOutputsChanged();
+
+ m_firstInit = false;
+
+}
+
+void QWasmMediaDevices::getMediaDevices()
+{
+ emscripten::val navigator = emscripten::val::global("navigator");
+ m_jsMediaDevicesInterface = navigator["mediaDevices"];
+
+ if (m_jsMediaDevicesInterface.isNull() || m_jsMediaDevicesInterface.isUndefined()) {
+ qWarning() << "No media devices found";
+ return;
+ }
+
+ if (qstdweb::haveAsyncify()) {
+#ifdef QT_HAVE_EMSCRIPTEN_ASYNCIFY
+ emscripten::val devicesList = m_jsMediaDevicesInterface.call<emscripten::val>("enumerateDevices").await();
+ if (devicesList.isNull() || devicesList.isUndefined()) {
+ qWarning() << "devices list error";
+ return;
+ }
+
+ parseDevices(devicesList);
+#endif
+ } else {
+ qstdweb::PromiseCallbacks enumerateDevicesCallback{
+ .thenFunc =
+ [&](emscripten::val devices) {
+ parseDevices(devices);
+ },
+ .catchFunc =
+ [this](emscripten::val error) {
+ qWarning() << "mediadevices enumerateDevices fail"
+ << QString::fromStdString(error["name"].as<std::string>())
+ << QString::fromStdString(error["message"].as<std::string>());
+ m_initDone = false;
+ }
+ };
+
+ qstdweb::Promise::make(m_jsMediaDevicesInterface,
+ QStringLiteral("enumerateDevices"),
+ std::move(enumerateDevicesCallback));
+
+ // setup devicechange monitor
+ m_deviceChangedCallback = std::make_unique<qstdweb::EventCallback>(
+ m_jsMediaDevicesInterface, "devicechange",
+ [this, enumerateDevicesCallback](emscripten::val) {
+ qstdweb::Promise::make(m_jsMediaDevicesInterface,
+ QStringLiteral("enumerateDevices"),
+ std::move(enumerateDevicesCallback));
+ });
+ }
+
+}
+
+void QWasmMediaDevices::getOpenALAudioDevices()
+{
+ // VM3959:4 The AudioContext was not allowed to start.
+ // It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
+ auto capture = alcGetString(nullptr, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
+ // present even if there is no capture device
+ if (capture && !m_audioOutputs.contains(capture)) {
+ m_audioInputs.insert(capture,
+ (new QWasmAudioDevice(capture, "WebAssembly audio capture device",
+ true, QAudioDevice::Input))
+ ->create());
+ m_audioInputsAdded = true;
+ emit audioInputsChanged();
+ }
+
+ auto playback = alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER);
+ // present even if there is no playback device
+ if (playback && !m_audioOutputs.contains(capture)) {
+ m_audioOutputs.insert(playback,
+ (new QWasmAudioDevice(playback, "WebAssembly audio playback device",
+ true, QAudioDevice::Output))
+ ->create());
+ emit audioOutputsChanged();
+ }
+ m_firstInit = true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/wasm/qwasmmediadevices_p.h b/src/multimedia/wasm/qwasmmediadevices_p.h
new file mode 100644
index 000000000..b97036f97
--- /dev/null
+++ b/src/multimedia/wasm/qwasmmediadevices_p.h
@@ -0,0 +1,89 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMMEDIADEVICES_H
+#define QWASMMEDIADEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediadevices_p.h>
+
+#include <private/qplatformvideodevices_p.h>
+
+#include <QtCore/private/qstdweb_p.h>
+#include <qaudio.h>
+#include <qaudiodevice.h>
+#include <qcameradevice.h>
+#include <qset.h>
+#include <QtCore/qloggingcategory.h>
+
+#include <emscripten.h>
+#include <emscripten/val.h>
+#include <emscripten/bind.h>
+#include <QMapIterator>
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qWasmMediaDevices)
+
+class QWasmAudioEngine;
+
+class QWasmCameraDevices : public QPlatformVideoDevices
+{
+ Q_OBJECT
+public:
+ QWasmCameraDevices(QPlatformMediaIntegration *integration);
+
+ QList<QCameraDevice> videoDevices() const override;
+private:
+ // weak
+ QPlatformMediaDevices *m_mediaDevices;
+};
+
+class QWasmMediaDevices : public QPlatformMediaDevices
+{
+public:
+ QWasmMediaDevices();
+
+ QList<QAudioDevice> audioInputs() const override;
+ QList<QAudioDevice> audioOutputs() const override;
+ QList<QCameraDevice> videoInputs() const;
+
+ QPlatformAudioSource *createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+ QPlatformAudioSink *createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+ void initDevices();
+
+private:
+ void updateCameraDevices();
+ void getMediaDevices();
+ void getOpenALAudioDevices();
+ void parseDevices(emscripten::val devices);
+
+ QMap <std::string, QAudioDevice> m_audioOutputs;
+ QMap <std::string, QAudioDevice> m_audioInputs;
+ QMap <std::string, QCameraDevice> m_cameraDevices;
+
+
+ std::unique_ptr<qstdweb::EventCallback> m_deviceChangedCallback;
+
+ bool m_videoInputsAdded = false;
+ bool m_audioInputsAdded = false;
+ bool m_audioOutputsAdded = false;
+ emscripten::val m_jsMediaDevicesInterface = emscripten::val::undefined();
+ bool m_initDone = false;
+ bool m_firstInit = false;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/windows/qcomptr_p.h b/src/multimedia/windows/qcomptr_p.h
new file mode 100644
index 000000000..befc97f11
--- /dev/null
+++ b/src/multimedia/windows/qcomptr_p.h
@@ -0,0 +1,33 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCOMPTR_P_H
+#define QCOMPTR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qt_windows.h>
+#include <wrl/client.h>
+
+using Microsoft::WRL::ComPtr;
+
+template<typename T, typename... Args>
+ComPtr<T> makeComObject(Args &&...args)
+{
+ ComPtr<T> p;
+ // Don't use Attach because of MINGW64 bug
+ // #892 Microsoft::WRL::ComPtr::Attach leaks references
+ *p.GetAddressOf() = new T(std::forward<Args>(args)...);
+ return p;
+}
+
+#endif
diff --git a/src/multimedia/windows/qcomtaskresource_p.h b/src/multimedia/windows/qcomtaskresource_p.h
new file mode 100644
index 000000000..90554da5e
--- /dev/null
+++ b/src/multimedia/windows/qcomtaskresource_p.h
@@ -0,0 +1,152 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QCOMTASKRESOURCE_P_H
+#define QCOMTASKRESOURCE_P_H
+
+#include <QtCore/qassert.h>
+
+#include <objbase.h>
+#include <algorithm>
+#include <type_traits>
+#include <utility>
+
+class QEmptyDeleter final
+{
+public:
+ template<typename T>
+ void operator()(T /*element*/) const
+ {
+ }
+};
+
+class QComDeleter final
+{
+public:
+ template<typename T>
+ void operator()(T element) const
+ {
+ element->Release();
+ }
+};
+
+template<typename T>
+class QComTaskResourceBase
+{
+public:
+ QComTaskResourceBase(const QComTaskResourceBase<T> &source) = delete;
+ QComTaskResourceBase &operator=(const QComTaskResourceBase<T> &right) = delete;
+
+ explicit operator bool() const { return m_resource != nullptr; }
+
+ T *get() const { return m_resource; }
+
+protected:
+ QComTaskResourceBase() = default;
+ explicit QComTaskResourceBase(T *const resource) : m_resource(resource) { }
+
+ T *release() { return std::exchange(m_resource, nullptr); }
+
+ void reset(T *const resource = nullptr)
+ {
+ if (m_resource != resource) {
+ if (m_resource)
+ CoTaskMemFree(m_resource);
+ m_resource = resource;
+ }
+ }
+
+ T *m_resource = nullptr;
+};
+
+template<typename T, typename TElementDeleter = QEmptyDeleter>
+class QComTaskResource final : public QComTaskResourceBase<T>
+{
+ using Base = QComTaskResourceBase<T>;
+
+public:
+ using Base::QComTaskResourceBase;
+
+ ~QComTaskResource() { reset(); }
+
+ T *operator->() const { return m_resource; }
+ T &operator*() const { return *m_resource; }
+
+ T **address()
+ {
+ Q_ASSERT(m_resource == nullptr);
+ return &m_resource;
+ }
+
+ using Base::release;
+ using Base::reset;
+
+private:
+ using Base::m_resource;
+};
+
+template<typename T, typename TElementDeleter>
+class QComTaskResource<T[], TElementDeleter> final : public QComTaskResourceBase<T>
+{
+ using Base = QComTaskResourceBase<T>;
+
+public:
+ QComTaskResource() = default;
+ explicit QComTaskResource(T *const resource, const std::size_t size)
+ : Base(resource), m_size(size)
+ {
+ }
+
+ ~QComTaskResource() { reset(); }
+
+ T &operator[](const std::size_t index) const
+ {
+ Q_ASSERT(index < m_size);
+ return m_resource[index];
+ }
+
+ T *release()
+ {
+ m_size = 0;
+
+ return Base::release();
+ }
+
+ void reset() { reset(nullptr, 0); }
+
+ void reset(T *const resource, const std::size_t size)
+ {
+ if (m_resource != resource) {
+ resetElements();
+
+ Base::reset(resource);
+
+ m_size = size;
+ }
+ }
+
+private:
+ void resetElements()
+ {
+ if constexpr (!std::is_same_v<TElementDeleter, QEmptyDeleter>) {
+ std::for_each(m_resource, m_resource + m_size, TElementDeleter());
+ }
+ }
+
+ std::size_t m_size = 0;
+
+ using Base::m_resource;
+};
+
+#endif
diff --git a/src/multimedia/windows/qwindowsaudiodevice.cpp b/src/multimedia/windows/qwindowsaudiodevice.cpp
new file mode 100644
index 000000000..f22567cbf
--- /dev/null
+++ b/src/multimedia/windows/qwindowsaudiodevice.cpp
@@ -0,0 +1,229 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// INTERNAL USE ONLY: Do NOT use for any other purpose.
+//
+
+#include "qwindowsaudiodevice_p.h"
+#include "qwindowsaudioutils_p.h"
+
+#include <QtCore/qt_windows.h>
+#include <QtCore/QDataStream>
+#include <QtCore/QIODevice>
+
+#include <audioclient.h>
+#include <mmsystem.h>
+
+#include <initguid.h>
+#include <wtypes.h>
+#include <propkeydef.h>
+#include <mmdeviceapi.h>
+
+QT_BEGIN_NAMESPACE
+
+QWindowsAudioDeviceInfo::QWindowsAudioDeviceInfo(QByteArray dev, ComPtr<IMMDevice> immDev, int waveID, const QString &description, QAudioDevice::Mode mode)
+ : QAudioDevicePrivate(dev, mode),
+ m_devId(waveID),
+ m_immDev(std::move(immDev))
+{
+ Q_ASSERT(m_immDev);
+
+ this->description = description;
+
+ ComPtr<IAudioClient> audioClient;
+ HRESULT hr = m_immDev->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER, nullptr,
+ (void **)audioClient.GetAddressOf());
+ if (SUCCEEDED(hr)) {
+ WAVEFORMATEX *pwfx = nullptr;
+ hr = audioClient->GetMixFormat(&pwfx);
+ if (SUCCEEDED(hr))
+ preferredFormat = QWindowsAudioUtils::waveFormatExToFormat(*pwfx);
+ }
+
+ if (!preferredFormat.isValid()) {
+ preferredFormat.setSampleRate(44100);
+ preferredFormat.setChannelCount(2);
+ preferredFormat.setSampleFormat(QAudioFormat::Int16);
+ }
+
+ DWORD fmt = 0;
+
+ if(mode == QAudioDevice::Output) {
+ WAVEOUTCAPS woc;
+ if (waveOutGetDevCaps(m_devId, &woc, sizeof(WAVEOUTCAPS)) == MMSYSERR_NOERROR)
+ fmt = woc.dwFormats;
+ } else {
+ WAVEINCAPS woc;
+ if (waveInGetDevCaps(m_devId, &woc, sizeof(WAVEINCAPS)) == MMSYSERR_NOERROR)
+ fmt = woc.dwFormats;
+ }
+
+ if (!fmt)
+ return;
+
+ // Check sample size
+ if ((fmt & WAVE_FORMAT_1M08)
+ || (fmt & WAVE_FORMAT_1S08)
+ || (fmt & WAVE_FORMAT_2M08)
+ || (fmt & WAVE_FORMAT_2S08)
+ || (fmt & WAVE_FORMAT_4M08)
+ || (fmt & WAVE_FORMAT_4S08)
+ || (fmt & WAVE_FORMAT_48M08)
+ || (fmt & WAVE_FORMAT_48S08)
+ || (fmt & WAVE_FORMAT_96M08)
+ || (fmt & WAVE_FORMAT_96S08)) {
+ supportedSampleFormats.append(QAudioFormat::UInt8);
+ }
+ if ((fmt & WAVE_FORMAT_1M16)
+ || (fmt & WAVE_FORMAT_1S16)
+ || (fmt & WAVE_FORMAT_2M16)
+ || (fmt & WAVE_FORMAT_2S16)
+ || (fmt & WAVE_FORMAT_4M16)
+ || (fmt & WAVE_FORMAT_4S16)
+ || (fmt & WAVE_FORMAT_48M16)
+ || (fmt & WAVE_FORMAT_48S16)
+ || (fmt & WAVE_FORMAT_96M16)
+ || (fmt & WAVE_FORMAT_96S16)) {
+ supportedSampleFormats.append(QAudioFormat::Int16);
+ }
+
+ minimumSampleRate = std::numeric_limits<int>::max();
+ maximumSampleRate = 0;
+ // Check sample rate
+ if ((fmt & WAVE_FORMAT_1M08)
+ || (fmt & WAVE_FORMAT_1S08)
+ || (fmt & WAVE_FORMAT_1M16)
+ || (fmt & WAVE_FORMAT_1S16)) {
+ minimumSampleRate = qMin(minimumSampleRate, 11025);
+ maximumSampleRate = qMax(maximumSampleRate, 11025);
+ }
+ if ((fmt & WAVE_FORMAT_2M08)
+ || (fmt & WAVE_FORMAT_2S08)
+ || (fmt & WAVE_FORMAT_2M16)
+ || (fmt & WAVE_FORMAT_2S16)) {
+ minimumSampleRate = qMin(minimumSampleRate, 22050);
+ maximumSampleRate = qMax(maximumSampleRate, 22050);
+ }
+ if ((fmt & WAVE_FORMAT_4M08)
+ || (fmt & WAVE_FORMAT_4S08)
+ || (fmt & WAVE_FORMAT_4M16)
+ || (fmt & WAVE_FORMAT_4S16)) {
+ minimumSampleRate = qMin(minimumSampleRate, 44100);
+ maximumSampleRate = qMax(maximumSampleRate, 44100);
+ }
+ if ((fmt & WAVE_FORMAT_48M08)
+ || (fmt & WAVE_FORMAT_48S08)
+ || (fmt & WAVE_FORMAT_48M16)
+ || (fmt & WAVE_FORMAT_48S16)) {
+ minimumSampleRate = qMin(minimumSampleRate, 48000);
+ maximumSampleRate = qMax(maximumSampleRate, 48000);
+ }
+ if ((fmt & WAVE_FORMAT_96M08)
+ || (fmt & WAVE_FORMAT_96S08)
+ || (fmt & WAVE_FORMAT_96M16)
+ || (fmt & WAVE_FORMAT_96S16)) {
+ minimumSampleRate = qMin(minimumSampleRate, 96000);
+ maximumSampleRate = qMax(maximumSampleRate, 96000);
+ }
+ if (minimumSampleRate == std::numeric_limits<int>::max())
+ minimumSampleRate = 0;
+
+ minimumChannelCount = std::numeric_limits<int>::max();
+ maximumChannelCount = 0;
+ // Check channel count
+ if (fmt & WAVE_FORMAT_1M08
+ || fmt & WAVE_FORMAT_1M16
+ || fmt & WAVE_FORMAT_2M08
+ || fmt & WAVE_FORMAT_2M16
+ || fmt & WAVE_FORMAT_4M08
+ || fmt & WAVE_FORMAT_4M16
+ || fmt & WAVE_FORMAT_48M08
+ || fmt & WAVE_FORMAT_48M16
+ || fmt & WAVE_FORMAT_96M08
+ || fmt & WAVE_FORMAT_96M16) {
+ minimumChannelCount = 1;
+ maximumChannelCount = 1;
+ }
+ if (fmt & WAVE_FORMAT_1S08
+ || fmt & WAVE_FORMAT_1S16
+ || fmt & WAVE_FORMAT_2S08
+ || fmt & WAVE_FORMAT_2S16
+ || fmt & WAVE_FORMAT_4S08
+ || fmt & WAVE_FORMAT_4S16
+ || fmt & WAVE_FORMAT_48S08
+ || fmt & WAVE_FORMAT_48S16
+ || fmt & WAVE_FORMAT_96S08
+ || fmt & WAVE_FORMAT_96S16) {
+ minimumChannelCount = qMin(minimumChannelCount, 2);
+ maximumChannelCount = qMax(maximumChannelCount, 2);
+ }
+
+ if (minimumChannelCount == std::numeric_limits<int>::max())
+ minimumChannelCount = 0;
+
+ // WAVEOUTCAPS and WAVEINCAPS contains information only for the previously tested parameters.
+ // WaveOut and WaveInt might actually support more formats, the only way to know is to try
+ // opening the device with it.
+ QAudioFormat testFormat;
+ testFormat.setChannelCount(maximumChannelCount);
+ testFormat.setSampleRate(maximumSampleRate);
+ const QAudioFormat defaultTestFormat(testFormat);
+
+ // Check if float samples are supported
+ testFormat.setSampleFormat(QAudioFormat::Float);
+ if (testSettings(testFormat))
+ supportedSampleFormats.append(QAudioFormat::Float);
+
+ // Check channel counts > 2
+ testFormat = defaultTestFormat;
+ for (int i = 18; i > 2; --i) { // <mmreg.h> defines 18 different channels
+ testFormat.setChannelCount(i);
+ if (testSettings(testFormat)) {
+ maximumChannelCount = i;
+ break;
+ }
+ }
+
+ channelConfiguration = QAudioFormat::defaultChannelConfigForChannelCount(maximumChannelCount);
+
+ ComPtr<IPropertyStore> props;
+ hr = m_immDev->OpenPropertyStore(STGM_READ, props.GetAddressOf());
+ if (SUCCEEDED(hr)) {
+ PROPVARIANT var;
+ PropVariantInit(&var);
+ hr = props->GetValue(PKEY_AudioEndpoint_PhysicalSpeakers, &var);
+ if (SUCCEEDED(hr) && var.uintVal != 0)
+ channelConfiguration = QWindowsAudioUtils::maskToChannelConfig(var.uintVal, maximumChannelCount);
+ }
+}
+
+QWindowsAudioDeviceInfo::~QWindowsAudioDeviceInfo()
+{
+}
+
+bool QWindowsAudioDeviceInfo::testSettings(const QAudioFormat& format) const
+{
+ WAVEFORMATEXTENSIBLE wfx;
+ if (QWindowsAudioUtils::formatToWaveFormatExtensible(format, wfx)) {
+ // query only, do not open device
+ if (mode == QAudioDevice::Output) {
+ return (waveOutOpen(NULL, UINT_PTR(m_devId), &wfx.Format, 0, 0,
+ WAVE_FORMAT_QUERY) == MMSYSERR_NOERROR);
+ } else { // AudioInput
+ return (waveInOpen(NULL, UINT_PTR(m_devId), &wfx.Format, 0, 0,
+ WAVE_FORMAT_QUERY) == MMSYSERR_NOERROR);
+ }
+ }
+
+ return false;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/windows/qwindowsaudiodevice_p.h b/src/multimedia/windows/qwindowsaudiodevice_p.h
new file mode 100644
index 000000000..b2af4bfe0
--- /dev/null
+++ b/src/multimedia/windows/qwindowsaudiodevice_p.h
@@ -0,0 +1,60 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+
+#ifndef QWINDOWSAUDIODEVICEINFO_H
+#define QWINDOWSAUDIODEVICEINFO_H
+
+#include <QtCore/qbytearray.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qdebug.h>
+
+#include <QtMultimedia/qaudiodevice.h>
+#include <private/qaudiosystem_p.h>
+#include <private/qaudiodevice_p.h>
+#include <qcomptr_p.h>
+
+struct IMMDevice;
+
+QT_BEGIN_NAMESPACE
+
+const unsigned int MAX_SAMPLE_RATES = 5;
+const unsigned int SAMPLE_RATES[] = { 8000, 11025, 22050, 44100, 48000 };
+
+class QWindowsAudioDeviceInfo : public QAudioDevicePrivate
+{
+public:
+ QWindowsAudioDeviceInfo(QByteArray dev, ComPtr<IMMDevice> immdev, int waveID, const QString &description, QAudioDevice::Mode mode);
+ ~QWindowsAudioDeviceInfo();
+
+ bool open();
+ void close();
+
+ bool testSettings(const QAudioFormat& format) const;
+
+ int waveId() const { return m_devId; }
+ ComPtr<IMMDevice> immDev() const { return m_immDev; }
+
+private:
+ quint32 m_devId;
+ ComPtr<IMMDevice> m_immDev;
+};
+
+
+
+QT_END_NAMESPACE
+
+
+#endif // QWINDOWSAUDIODEVICEINFO_H
diff --git a/src/multimedia/windows/qwindowsaudiosink.cpp b/src/multimedia/windows/qwindowsaudiosink.cpp
new file mode 100644
index 000000000..404496970
--- /dev/null
+++ b/src/multimedia/windows/qwindowsaudiosink.cpp
@@ -0,0 +1,388 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// INTERNAL USE ONLY: Do NOT use for any other purpose.
+//
+
+#include "qwindowsaudiosink_p.h"
+#include "qwindowsaudioutils_p.h"
+#include "qwindowsmultimediautils_p.h"
+#include "qcomtaskresource_p.h"
+
+#include <QtCore/QDataStream>
+#include <QtCore/qtimer.h>
+#include <QtCore/qloggingcategory.h>
+#include <QtCore/qpointer.h>
+
+#include <private/qaudiohelpers_p.h>
+
+#include <audioclient.h>
+#include <mmdeviceapi.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcAudioOutput, "qt.multimedia.audiooutput")
+
+using namespace QWindowsMultimediaUtils;
+
+class OutputPrivate : public QIODevice
+{
+ Q_OBJECT
+public:
+ OutputPrivate(QWindowsAudioSink &audio) : QIODevice(&audio), audioDevice(audio) {}
+ ~OutputPrivate() override = default;
+
+ qint64 readData(char *, qint64) override { return 0; }
+ qint64 writeData(const char *data, qint64 len) override { return audioDevice.push(data, len); }
+
+private:
+ QWindowsAudioSink &audioDevice;
+};
+
+std::optional<quint32> audioClientFramesAvailable(IAudioClient *client)
+{
+ auto framesAllocated = QWindowsAudioUtils::audioClientFramesAllocated(client);
+ auto framesInUse = QWindowsAudioUtils::audioClientFramesInUse(client);
+
+ if (framesAllocated && framesInUse)
+ return *framesAllocated - *framesInUse;
+ return {};
+}
+
+QWindowsAudioSink::QWindowsAudioSink(ComPtr<IMMDevice> device, QObject *parent) :
+ QPlatformAudioSink(parent),
+ m_timer(new QTimer(this)),
+ m_pushSource(new OutputPrivate(*this)),
+ m_device(std::move(device))
+{
+ m_pushSource->open(QIODevice::WriteOnly|QIODevice::Unbuffered);
+ m_timer->setSingleShot(true);
+ m_timer->setTimerType(Qt::PreciseTimer);
+}
+
+QWindowsAudioSink::~QWindowsAudioSink()
+{
+ close();
+}
+
+qint64 QWindowsAudioSink::remainingPlayTimeUs()
+{
+ auto framesInUse = QWindowsAudioUtils::audioClientFramesInUse(m_audioClient.Get());
+ return m_resampler.outputFormat().durationForFrames(framesInUse ? *framesInUse : 0);
+}
+
+void QWindowsAudioSink::deviceStateChange(QAudio::State state, QAudio::Error error)
+{
+ if (state != deviceState) {
+ if (state == QAudio::ActiveState) {
+ m_audioClient->Start();
+ qCDebug(qLcAudioOutput) << "Audio client started";
+
+ } else if (deviceState == QAudio::ActiveState) {
+ m_timer->stop();
+ m_audioClient->Stop();
+ qCDebug(qLcAudioOutput) << "Audio client stopped";
+ }
+
+ QPointer<QWindowsAudioSink> thisGuard(this);
+ deviceState = state;
+ emit stateChanged(deviceState);
+ if (!thisGuard)
+ return;
+ }
+
+ if (error != errorState) {
+ errorState = error;
+ emit errorChanged(error);
+ }
+}
+
+QAudioFormat QWindowsAudioSink::format() const
+{
+ return m_format;
+}
+
+void QWindowsAudioSink::setFormat(const QAudioFormat& fmt)
+{
+ if (deviceState == QAudio::StoppedState)
+ m_format = fmt;
+}
+
+void QWindowsAudioSink::pullSource()
+{
+ qCDebug(qLcAudioOutput) << "Pull source";
+ if (!m_pullSource)
+ return;
+
+ auto bytesAvailable = m_pullSource->isOpen() ? qsizetype(m_pullSource->bytesAvailable()) : 0;
+ auto readLen = qMin(bytesFree(), bytesAvailable);
+ if (readLen > 0) {
+ QByteArray samples = m_pullSource->read(readLen);
+ if (samples.size() == 0) {
+ deviceStateChange(QAudio::IdleState, QAudio::IOError);
+ return;
+ } else {
+ write(samples.data(), samples.size());
+ }
+ }
+
+ auto playTimeUs = remainingPlayTimeUs();
+ if (playTimeUs == 0) {
+ deviceStateChange(QAudio::IdleState, m_pullSource->atEnd() ? QAudio::NoError : QAudio::UnderrunError);
+ } else {
+ deviceStateChange(QAudio::ActiveState, QAudio::NoError);
+ m_timer->start(playTimeUs / 2000);
+ }
+}
+
+void QWindowsAudioSink::start(QIODevice* device)
+{
+ qCDebug(qLcAudioOutput) << "start(ioDevice)" << deviceState;
+ if (deviceState != QAudio::StoppedState)
+ close();
+
+ if (device == nullptr)
+ return;
+
+ if (!open()) {
+ errorState = QAudio::OpenError;
+ emit errorChanged(QAudio::OpenError);
+ return;
+ }
+
+ m_pullSource = device;
+
+ connect(device, &QIODevice::readyRead, this, &QWindowsAudioSink::pullSource);
+ m_timer->disconnect();
+ m_timer->callOnTimeout(this, &QWindowsAudioSink::pullSource);
+ pullSource();
+}
+
+qint64 QWindowsAudioSink::push(const char *data, qint64 len)
+{
+ if (deviceState == QAudio::StoppedState)
+ return -1;
+
+ qint64 written = write(data, len);
+ if (written > 0) {
+ deviceStateChange(QAudio::ActiveState, QAudio::NoError);
+ m_timer->start(remainingPlayTimeUs() /1000);
+ }
+
+ return written;
+}
+
+QIODevice* QWindowsAudioSink::start()
+{
+ qCDebug(qLcAudioOutput) << "start()";
+ if (deviceState != QAudio::StoppedState)
+ close();
+
+ if (!open()) {
+ errorState = QAudio::OpenError;
+ emit errorChanged(QAudio::OpenError);
+ return nullptr;
+ }
+
+ deviceStateChange(QAudio::IdleState, QAudio::NoError);
+
+ m_timer->disconnect();
+ m_timer->callOnTimeout(this, [this](){
+ deviceStateChange(QAudio::IdleState, QAudio::UnderrunError);
+ });
+
+ return m_pushSource.get();
+}
+
+bool QWindowsAudioSink::open()
+{
+ if (m_audioClient)
+ return true;
+
+ HRESULT hr = m_device->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER,
+ nullptr, (void**)m_audioClient.GetAddressOf());
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioOutput) << "Failed to activate audio device" << errorString(hr);
+ return false;
+ }
+
+ auto resetClient = qScopeGuard([this](){ m_audioClient.Reset(); });
+
+ QComTaskResource<WAVEFORMATEX> pwfx;
+ hr = m_audioClient->GetMixFormat(pwfx.address());
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioOutput) << "Format unsupported" << errorString(hr);
+ return false;
+ }
+
+ if (!m_resampler.setup(m_format, QWindowsAudioUtils::waveFormatExToFormat(*pwfx))) {
+ qCWarning(qLcAudioOutput) << "Failed to set up resampler";
+ return false;
+ }
+
+ if (m_bufferSize == 0)
+ m_bufferSize = m_format.sampleRate() * m_format.bytesPerFrame() / 2;
+
+ REFERENCE_TIME requestedDuration = m_format.durationForBytes(m_bufferSize) * 10;
+
+ hr = m_audioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, 0, requestedDuration, 0, pwfx.get(),
+ nullptr);
+
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioOutput) << "Failed to initialize audio client" << errorString(hr);
+ return false;
+ }
+
+ auto framesAllocated = QWindowsAudioUtils::audioClientFramesAllocated(m_audioClient.Get());
+ if (!framesAllocated) {
+ qCWarning(qLcAudioOutput) << "Failed to get audio client buffer size";
+ return false;
+ }
+
+ m_bufferSize = m_format.bytesForDuration(
+ m_resampler.outputFormat().durationForFrames(*framesAllocated));
+
+ hr = m_audioClient->GetService(__uuidof(IAudioRenderClient), (void**)m_renderClient.GetAddressOf());
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioOutput) << "Failed to obtain audio client rendering service"
+ << errorString(hr);
+ return false;
+ }
+
+ resetClient.dismiss();
+
+ return true;
+}
+
+void QWindowsAudioSink::close()
+{
+ qCDebug(qLcAudioOutput) << "close()";
+ if (deviceState == QAudio::StoppedState)
+ return;
+
+ deviceStateChange(QAudio::StoppedState, QAudio::NoError);
+
+ if (m_pullSource)
+ disconnect(m_pullSource, &QIODevice::readyRead, this, &QWindowsAudioSink::pullSource);
+ m_audioClient.Reset();
+ m_renderClient.Reset();
+ m_pullSource = nullptr;
+}
+
+qsizetype QWindowsAudioSink::bytesFree() const
+{
+ if (!m_audioClient)
+ return 0;
+
+ auto framesAvailable = audioClientFramesAvailable(m_audioClient.Get());
+ if (framesAvailable)
+ return m_resampler.inputBufferSize(*framesAvailable * m_resampler.outputFormat().bytesPerFrame());
+ return 0;
+}
+
+void QWindowsAudioSink::setBufferSize(qsizetype value)
+{
+ if (!m_audioClient)
+ m_bufferSize = value;
+}
+
+qint64 QWindowsAudioSink::processedUSecs() const
+{
+ if (!m_audioClient)
+ return 0;
+
+ return m_format.durationForBytes(m_resampler.totalInputBytes());
+}
+
+qint64 QWindowsAudioSink::write(const char *data, qint64 len)
+{
+ Q_ASSERT(m_audioClient);
+ Q_ASSERT(m_renderClient);
+
+ qCDebug(qLcAudioOutput) << "write()" << len;
+
+ auto framesAvailable = audioClientFramesAvailable(m_audioClient.Get());
+ if (!framesAvailable)
+ return -1;
+
+ auto maxBytesCanWrite = m_format.bytesForDuration(
+ m_resampler.outputFormat().durationForFrames(*framesAvailable));
+ qsizetype writeSize = qMin(maxBytesCanWrite, len);
+
+ QByteArray writeBytes = m_resampler.resample({data, writeSize});
+ qint32 writeFramesNum = m_resampler.outputFormat().framesForBytes(writeBytes.size());
+
+ quint8 *buffer = nullptr;
+ HRESULT hr = m_renderClient->GetBuffer(writeFramesNum, &buffer);
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioOutput) << "Failed to get buffer" << errorString(hr);
+ return -1;
+ }
+
+ if (m_volume < qreal(1.0))
+ QAudioHelperInternal::qMultiplySamples(m_volume, m_resampler.outputFormat(), writeBytes.data(), buffer, writeBytes.size());
+ else
+ std::memcpy(buffer, writeBytes.data(), writeBytes.size());
+
+ DWORD flags = writeBytes.isEmpty() ? AUDCLNT_BUFFERFLAGS_SILENT : 0;
+ hr = m_renderClient->ReleaseBuffer(writeFramesNum, flags);
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioOutput) << "Failed to return buffer" << errorString(hr);
+ return -1;
+ }
+
+ return writeSize;
+}
+
+void QWindowsAudioSink::resume()
+{
+ qCDebug(qLcAudioOutput) << "resume()";
+ if (deviceState == QAudio::SuspendedState) {
+ if (m_pullSource) {
+ pullSource();
+ } else {
+ deviceStateChange(suspendedInState, QAudio::NoError);
+ if (remainingPlayTimeUs() > 0)
+ m_audioClient->Start();
+ }
+ }
+}
+
+void QWindowsAudioSink::suspend()
+{
+ qCDebug(qLcAudioOutput) << "suspend()";
+ if (deviceState == QAudio::ActiveState || deviceState == QAudio::IdleState) {
+ suspendedInState = deviceState;
+ deviceStateChange(QAudio::SuspendedState, QAudio::NoError);
+ }
+}
+
+void QWindowsAudioSink::setVolume(qreal v)
+{
+ if (qFuzzyCompare(m_volume, v))
+ return;
+
+ m_volume = qBound(qreal(0), v, qreal(1));
+}
+
+void QWindowsAudioSink::stop() {
+ // TODO: investigate and find a way to drain and stop instead of closing
+ close();
+}
+
+void QWindowsAudioSink::reset()
+{
+ close();
+}
+
+QT_END_NAMESPACE
+
+#include "qwindowsaudiosink.moc"
diff --git a/src/multimedia/windows/qwindowsaudiosink_p.h b/src/multimedia/windows/qwindowsaudiosink_p.h
new file mode 100644
index 000000000..1a98bc296
--- /dev/null
+++ b/src/multimedia/windows/qwindowsaudiosink_p.h
@@ -0,0 +1,97 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QWINDOWSAUDIOOUTPUT_H
+#define QWINDOWSAUDIOOUTPUT_H
+
+#include <QtCore/qdebug.h>
+#include <QtCore/qelapsedtimer.h>
+#include <QtCore/qiodevice.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qdatetime.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qtimer.h>
+#include <QtCore/qpointer.h>
+
+#include <QtMultimedia/qaudio.h>
+#include <QtMultimedia/qaudiodevice.h>
+#include <private/qaudiosystem_p.h>
+#include <qcomptr_p.h>
+#include <qwindowsresampler_p.h>
+
+#include <audioclient.h>
+#include <mmdeviceapi.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsResampler;
+
+class QWindowsAudioSink : public QPlatformAudioSink
+{
+ Q_OBJECT
+public:
+ QWindowsAudioSink(ComPtr<IMMDevice> device, QObject *parent);
+ ~QWindowsAudioSink();
+
+ void setFormat(const QAudioFormat& fmt) override;
+ QAudioFormat format() const override;
+ QIODevice* start() override;
+ void start(QIODevice* device) override;
+ void stop() override;
+ void reset() override;
+ void suspend() override;
+ void resume() override;
+ qsizetype bytesFree() const override;
+ void setBufferSize(qsizetype value) override;
+ qsizetype bufferSize() const override { return m_bufferSize; }
+ qint64 processedUSecs() const override;
+ QAudio::Error error() const override { return errorState; }
+ QAudio::State state() const override { return deviceState; }
+ void setVolume(qreal) override;
+ qreal volume() const override { return m_volume; }
+
+private:
+ friend class OutputPrivate;
+ qint64 write(const char *data, qint64 len);
+ qint64 push(const char *data, qint64 len);
+
+ bool open();
+ void close();
+
+ void deviceStateChange(QAudio::State, QAudio::Error);
+
+ void pullSource();
+ qint64 remainingPlayTimeUs();
+
+ QAudioFormat m_format;
+ QAudio::Error errorState = QAudio::NoError;
+ QAudio::State deviceState = QAudio::StoppedState;
+ QAudio::State suspendedInState = QAudio::SuspendedState;
+
+ qsizetype m_bufferSize = 0;
+ qreal m_volume = 1.0;
+ QTimer *m_timer = nullptr;
+ QScopedPointer<QIODevice> m_pushSource;
+ QPointer<QIODevice> m_pullSource;
+ ComPtr<IMMDevice> m_device;
+ ComPtr<IAudioClient> m_audioClient;
+ ComPtr<IAudioRenderClient> m_renderClient;
+ QWindowsResampler m_resampler;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QWINDOWSAUDIOOUTPUT_H
diff --git a/src/multimedia/windows/qwindowsaudiosource.cpp b/src/multimedia/windows/qwindowsaudiosource.cpp
new file mode 100644
index 000000000..85fc454ad
--- /dev/null
+++ b/src/multimedia/windows/qwindowsaudiosource.cpp
@@ -0,0 +1,406 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// INTERNAL USE ONLY: Do NOT use for any other purpose.
+//
+
+
+#include "qwindowsaudiosource_p.h"
+#include "qwindowsmultimediautils_p.h"
+#include "qcomtaskresource_p.h"
+
+#include <QtCore/QDataStream>
+#include <QtCore/qtimer.h>
+
+#include <private/qaudiohelpers_p.h>
+
+#include <qloggingcategory.h>
+#include <qdebug.h>
+#include <audioclient.h>
+#include <mmdeviceapi.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcAudioSource, "qt.multimedia.audiosource")
+
+using namespace QWindowsMultimediaUtils;
+
+class OurSink : public QIODevice
+{
+public:
+ OurSink(QWindowsAudioSource& source) : QIODevice(&source), m_audioSource(source) {}
+
+ qint64 bytesAvailable() const override { return m_audioSource.bytesReady(); }
+ qint64 readData(char* data, qint64 len) override { return m_audioSource.read(data, len); }
+ qint64 writeData(const char*, qint64) override { return 0; }
+
+private:
+ QWindowsAudioSource &m_audioSource;
+};
+
+QWindowsAudioSource::QWindowsAudioSource(ComPtr<IMMDevice> device, QObject *parent)
+ : QPlatformAudioSource(parent),
+ m_timer(new QTimer(this)),
+ m_device(std::move(device)),
+ m_ourSink(new OurSink(*this))
+{
+ m_ourSink->open(QIODevice::ReadOnly|QIODevice::Unbuffered);
+ m_timer->setTimerType(Qt::PreciseTimer);
+ m_timer->setSingleShot(true);
+ m_timer->callOnTimeout(this, &QWindowsAudioSource::pullCaptureClient);
+}
+
+void QWindowsAudioSource::setVolume(qreal volume)
+{
+ m_volume = qBound(qreal(0), volume, qreal(1));
+}
+
+qreal QWindowsAudioSource::volume() const
+{
+ return m_volume;
+}
+
+QWindowsAudioSource::~QWindowsAudioSource()
+{
+ stop();
+}
+
+QAudio::Error QWindowsAudioSource::error() const
+{
+ return m_errorState;
+}
+
+QAudio::State QWindowsAudioSource::state() const
+{
+ return m_deviceState;
+}
+
+void QWindowsAudioSource::setFormat(const QAudioFormat& fmt)
+{
+ if (m_deviceState == QAudio::StoppedState) {
+ m_format = fmt;
+ } else {
+ if (m_format != fmt) {
+ qWarning() << "Cannot set a new audio format, in the current state ("
+ << m_deviceState << ")";
+ }
+ }
+}
+
+QAudioFormat QWindowsAudioSource::format() const
+{
+ return m_format;
+}
+
+void QWindowsAudioSource::deviceStateChange(QAudio::State state, QAudio::Error error)
+{
+ if (state != m_deviceState) {
+ bool wasActive = m_deviceState == QAudio::ActiveState || m_deviceState == QAudio::IdleState;
+ bool isActive = state == QAudio::ActiveState || state == QAudio::IdleState;
+
+ if (isActive && !wasActive) {
+ m_audioClient->Start();
+ qCDebug(qLcAudioSource) << "Audio client started";
+
+ } else if (wasActive && !isActive) {
+ m_timer->stop();
+ m_audioClient->Stop();
+ qCDebug(qLcAudioSource) << "Audio client stopped";
+ }
+
+ m_deviceState = state;
+ emit stateChanged(m_deviceState);
+ }
+
+ if (error != m_errorState) {
+ m_errorState = error;
+ emit errorChanged(error);
+ }
+}
+
+QByteArray QWindowsAudioSource::readCaptureClientBuffer()
+{
+ UINT32 actualFrames = 0;
+ BYTE *data = nullptr;
+ DWORD flags = 0;
+ HRESULT hr = m_captureClient->GetBuffer(&data, &actualFrames, &flags, nullptr, nullptr);
+ if (FAILED(hr)) {
+ qWarning() << "IAudioCaptureClient::GetBuffer failed" << errorString(hr);
+ deviceStateChange(QAudio::IdleState, QAudio::IOError);
+ return {};
+ }
+
+ if (actualFrames == 0)
+ return {};
+
+ QByteArray out;
+ if (flags & AUDCLNT_BUFFERFLAGS_SILENT) {
+ out.resize(m_resampler.outputFormat().bytesForDuration(
+ m_resampler.inputFormat().framesForDuration(actualFrames)),
+ 0);
+ } else {
+ out = m_resampler.resample(
+ { data, m_resampler.inputFormat().bytesForFrames(actualFrames) });
+ QAudioHelperInternal::qMultiplySamples(m_volume, m_resampler.outputFormat(), out.data(), out.data(), out.size());
+ }
+
+ hr = m_captureClient->ReleaseBuffer(actualFrames);
+ if (FAILED(hr)) {
+ qWarning() << "IAudioCaptureClient::ReleaseBuffer failed" << errorString(hr);
+ deviceStateChange(QAudio::IdleState, QAudio::IOError);
+ return {};
+ }
+
+ return out;
+}
+
+void QWindowsAudioSource::schedulePull()
+{
+ auto allocated = QWindowsAudioUtils::audioClientFramesAllocated(m_audioClient.Get());
+ auto inUse = QWindowsAudioUtils::audioClientFramesInUse(m_audioClient.Get());
+
+ if (!allocated || !inUse) {
+ deviceStateChange(QAudio::IdleState, QAudio::IOError);
+ } else {
+ // Schedule the next audio pull immediately if the audio buffer is more
+ // than half-full or wait until the audio source fills at least half of it.
+ if (*inUse > *allocated / 2) {
+ m_timer->start(0);
+ } else {
+ auto timeToHalfBuffer = m_resampler.inputFormat().durationForFrames(*allocated / 2 - *inUse);
+ m_timer->start(timeToHalfBuffer / 1000);
+ }
+ }
+}
+
+void QWindowsAudioSource::pullCaptureClient()
+{
+ qCDebug(qLcAudioSource) << "Pull captureClient";
+ while (true) {
+ auto out = readCaptureClientBuffer();
+ if (out.isEmpty())
+ break;
+
+ if (m_clientSink) {
+ qint64 written = m_clientSink->write(out.data(), out.size());
+ if (written != out.size())
+ qCDebug(qLcAudioSource) << "Did not write all data to the output";
+
+ } else {
+ m_clientBufferResidue += out;
+ emit m_ourSink->readyRead();
+ }
+ }
+
+ schedulePull();
+}
+
+void QWindowsAudioSource::start(QIODevice* device)
+{
+ qCDebug(qLcAudioSource) << "start(ioDevice)";
+ if (m_deviceState != QAudio::StoppedState)
+ close();
+
+ if (device == nullptr)
+ return;
+
+ if (!open()) {
+ m_errorState = QAudio::OpenError;
+ emit errorChanged(QAudio::OpenError);
+ return;
+ }
+
+ m_clientSink = device;
+ schedulePull();
+ deviceStateChange(QAudio::ActiveState, QAudio::NoError);
+}
+
+QIODevice* QWindowsAudioSource::start()
+{
+ qCDebug(qLcAudioSource) << "start()";
+ if (m_deviceState != QAudio::StoppedState)
+ close();
+
+ if (!open()) {
+ m_errorState = QAudio::OpenError;
+ emit errorChanged(QAudio::OpenError);
+ return nullptr;
+ }
+
+ schedulePull();
+ deviceStateChange(QAudio::IdleState, QAudio::NoError);
+ return m_ourSink;
+}
+
+void QWindowsAudioSource::stop()
+{
+ if (m_deviceState == QAudio::StoppedState)
+ return;
+
+ close();
+}
+
+bool QWindowsAudioSource::open()
+{
+ HRESULT hr = m_device->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER,
+ nullptr, (void**)m_audioClient.GetAddressOf());
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioSource) << "Failed to activate audio device" << errorString(hr);
+ return false;
+ }
+
+ QComTaskResource<WAVEFORMATEX> pwfx;
+ hr = m_audioClient->GetMixFormat(pwfx.address());
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioSource) << "Format unsupported" << errorString(hr);
+ return false;
+ }
+
+ if (!m_resampler.setup(QWindowsAudioUtils::waveFormatExToFormat(*pwfx), m_format)) {
+ qCWarning(qLcAudioSource) << "Failed to set up resampler";
+ return false;
+ }
+
+ if (m_bufferSize == 0)
+ m_bufferSize = m_format.sampleRate() * m_format.bytesPerFrame() / 5; // 200ms
+
+ REFERENCE_TIME requestedDuration = m_format.durationForBytes(m_bufferSize);
+
+ hr = m_audioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, 0, requestedDuration, 0, pwfx.get(),
+ nullptr);
+
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioSource) << "Failed to initialize audio client" << errorString(hr);
+ return false;
+ }
+
+ auto framesAllocated = QWindowsAudioUtils::audioClientFramesAllocated(m_audioClient.Get());
+ if (!framesAllocated) {
+ qCWarning(qLcAudioSource) << "Failed to get audio client buffer size";
+ return false;
+ }
+
+ m_bufferSize = m_format.bytesForDuration(
+ m_resampler.inputFormat().durationForFrames(*framesAllocated));
+
+ hr = m_audioClient->GetService(__uuidof(IAudioCaptureClient), (void**)m_captureClient.GetAddressOf());
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioSource) << "Failed to obtain audio client rendering service" << errorString(hr);
+ return false;
+ }
+
+ return true;
+}
+
+void QWindowsAudioSource::close()
+{
+ qCDebug(qLcAudioSource) << "close()";
+ if (m_deviceState == QAudio::StoppedState)
+ return;
+
+ deviceStateChange(QAudio::StoppedState, QAudio::NoError);
+
+ m_clientBufferResidue.clear();
+ m_captureClient.Reset();
+ m_audioClient.Reset();
+ m_clientSink = nullptr;
+}
+
+qsizetype QWindowsAudioSource::bytesReady() const
+{
+ if (m_deviceState == QAudio::StoppedState || m_deviceState == QAudio::SuspendedState)
+ return 0;
+
+ auto frames = QWindowsAudioUtils::audioClientFramesInUse(m_audioClient.Get());
+ if (frames) {
+ auto clientBufferSize = m_resampler.outputFormat().bytesForDuration(
+ m_resampler.inputFormat().durationForFrames(*frames));
+
+ return clientBufferSize + m_clientBufferResidue.size();
+
+ } else {
+ return 0;
+ }
+}
+
+qint64 QWindowsAudioSource::read(char* data, qint64 len)
+{
+ deviceStateChange(QAudio::ActiveState, QAudio::NoError);
+ schedulePull();
+
+ if (data == nullptr || len < 0)
+ return -1;
+
+ auto offset = 0;
+ if (!m_clientBufferResidue.isEmpty()) {
+ auto copyLen = qMin(m_clientBufferResidue.size(), len);
+ memcpy(data, m_clientBufferResidue.data(), copyLen);
+ len -= copyLen;
+ offset += copyLen;
+ }
+
+ m_clientBufferResidue = QByteArray{ m_clientBufferResidue.data() + offset,
+ m_clientBufferResidue.size() - offset };
+
+ if (len > 0) {
+ auto out = readCaptureClientBuffer();
+ if (!out.isEmpty()) {
+ qsizetype copyLen = qMin(out.size(), len);
+ memcpy(data + offset, out.data(), copyLen);
+ offset += copyLen;
+
+ m_clientBufferResidue = QByteArray{ out.data() + copyLen, out.size() - copyLen };
+ }
+ }
+
+ return offset;
+}
+
+void QWindowsAudioSource::resume()
+{
+ qCDebug(qLcAudioSource) << "resume()";
+ if (m_deviceState == QAudio::SuspendedState) {
+ deviceStateChange(QAudio::ActiveState, QAudio::NoError);
+ pullCaptureClient();
+ }
+}
+
+void QWindowsAudioSource::setBufferSize(qsizetype value)
+{
+ m_bufferSize = value;
+}
+
+qsizetype QWindowsAudioSource::bufferSize() const
+{
+ return m_bufferSize;
+}
+
+qint64 QWindowsAudioSource::processedUSecs() const
+{
+ if (m_deviceState == QAudio::StoppedState)
+ return 0;
+
+ return m_resampler.outputFormat().durationForBytes(m_resampler.totalOutputBytes());
+}
+
+void QWindowsAudioSource::suspend()
+{
+ qCDebug(qLcAudioSource) << "suspend";
+ if (m_deviceState == QAudio::ActiveState || m_deviceState == QAudio::IdleState)
+ deviceStateChange(QAudio::SuspendedState, QAudio::NoError);
+}
+
+void QWindowsAudioSource::reset()
+{
+ stop();
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/windows/qwindowsaudiosource_p.h b/src/multimedia/windows/qwindowsaudiosource_p.h
new file mode 100644
index 000000000..68d57bbe1
--- /dev/null
+++ b/src/multimedia/windows/qwindowsaudiosource_p.h
@@ -0,0 +1,96 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QWINDOWSAUDIOINPUT_H
+#define QWINDOWSAUDIOINPUT_H
+
+#include "qwindowsaudioutils_p.h"
+
+#include <QtCore/qfile.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qelapsedtimer.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qdatetime.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qbytearray.h>
+
+#include <QtMultimedia/qaudio.h>
+#include <QtMultimedia/qaudiodevice.h>
+#include <private/qaudiosystem_p.h>
+
+#include <qwindowsresampler_p.h>
+
+struct IMMDevice;
+struct IAudioClient;
+struct IAudioCaptureClient;
+
+QT_BEGIN_NAMESPACE
+class QTimer;
+
+class QWindowsAudioSource : public QPlatformAudioSource
+{
+ Q_OBJECT
+public:
+ QWindowsAudioSource(ComPtr<IMMDevice> device, QObject *parent);
+ ~QWindowsAudioSource();
+
+ qint64 read(char* data, qint64 len);
+
+ void setFormat(const QAudioFormat& fmt) override;
+ QAudioFormat format() const override;
+ QIODevice* start() override;
+ void start(QIODevice* device) override;
+ void stop() override;
+ void reset() override;
+ void suspend() override;
+ void resume() override;
+ qsizetype bytesReady() const override;
+ void setBufferSize(qsizetype value) override;
+ qsizetype bufferSize() const override;
+ qint64 processedUSecs() const override;
+ QAudio::Error error() const override;
+ QAudio::State state() const override;
+ void setVolume(qreal volume) override;
+ qreal volume() const override;
+
+private:
+ void deviceStateChange(QAudio::State state, QAudio::Error error);
+ void pullCaptureClient();
+ void schedulePull();
+ QByteArray readCaptureClientBuffer();
+
+ QTimer *m_timer = nullptr;
+ ComPtr<IMMDevice> m_device;
+ ComPtr<IAudioClient> m_audioClient;
+ ComPtr<IAudioCaptureClient> m_captureClient;
+ QWindowsResampler m_resampler;
+ int m_bufferSize = 0;
+ qreal m_volume = 1.0;
+
+ QIODevice* m_ourSink = nullptr;
+ QIODevice* m_clientSink = nullptr;
+ QAudioFormat m_format;
+ QAudio::Error m_errorState = QAudio::NoError;
+ QAudio::State m_deviceState = QAudio::StoppedState;
+
+ QByteArray m_clientBufferResidue;
+
+ bool open();
+ void close();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/windows/qwindowsaudioutils.cpp b/src/multimedia/windows/qwindowsaudioutils.cpp
new file mode 100644
index 000000000..dce4a2135
--- /dev/null
+++ b/src/multimedia/windows/qwindowsaudioutils.cpp
@@ -0,0 +1,208 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsaudioutils_p.h"
+#include "qwindowsmediafoundation_p.h"
+#include "qdebug.h"
+#include "ks.h"
+#include "ksmedia.h"
+
+#include <audioclient.h>
+
+QT_BEGIN_NAMESPACE
+
+static QAudioFormat::AudioChannelPosition channelFormatMap[] =
+ { QAudioFormat::FrontLeft // SPEAKER_FRONT_LEFT (0x1)
+ , QAudioFormat::FrontRight // SPEAKER_FRONT_RIGHT (0x2)
+ , QAudioFormat::FrontCenter // SPEAKER_FRONT_CENTER (0x4)
+ , QAudioFormat::LFE // SPEAKER_LOW_FREQUENCY (0x8)
+ , QAudioFormat::BackLeft // SPEAKER_BACK_LEFT (0x10)
+ , QAudioFormat::BackRight // SPEAKER_BACK_RIGHT (0x20)
+ , QAudioFormat::FrontLeftOfCenter // SPEAKER_FRONT_LEFT_OF_CENTER (0x40)
+ , QAudioFormat::FrontRightOfCenter// SPEAKER_FRONT_RIGHT_OF_CENTER (0x80)
+ , QAudioFormat::BackCenter // SPEAKER_BACK_CENTER (0x100)
+ , QAudioFormat::SideLeft // SPEAKER_SIDE_LEFT (0x200)
+ , QAudioFormat::SideRight // SPEAKER_SIDE_RIGHT (0x400)
+ , QAudioFormat::TopCenter // SPEAKER_TOP_CENTER (0x800)
+ , QAudioFormat::TopFrontLeft // SPEAKER_TOP_FRONT_LEFT (0x1000)
+ , QAudioFormat::TopFrontCenter // SPEAKER_TOP_FRONT_CENTER (0x2000)
+ , QAudioFormat::TopFrontRight // SPEAKER_TOP_FRONT_RIGHT (0x4000)
+ , QAudioFormat::TopBackLeft // SPEAKER_TOP_BACK_LEFT (0x8000)
+ , QAudioFormat::TopBackCenter // SPEAKER_TOP_BACK_CENTER (0x10000)
+ , QAudioFormat::TopBackRight // SPEAKER_TOP_BACK_RIGHT (0x20000)
+ };
+
+QAudioFormat::ChannelConfig QWindowsAudioUtils::maskToChannelConfig(UINT32 mask, int count)
+{
+ quint32 config = 0;
+ int set = 0;
+ for (auto c : channelFormatMap) {
+ if (mask & 1) {
+ config |= QAudioFormat::channelConfig(c);
+ ++set;
+ }
+ if (set >= count)
+ break;
+ mask >>= 1;
+ }
+ return QAudioFormat::ChannelConfig(config);
+}
+
+static UINT32 channelConfigToMask(QAudioFormat::ChannelConfig config)
+{
+ UINT32 mask = 0;
+ quint32 i = 0;
+ for (auto c : channelFormatMap) {
+ if (config & QAudioFormat::channelConfig(c))
+ mask |= 1 << i;
+ ++i;
+ }
+ return mask;
+}
+
+bool QWindowsAudioUtils::formatToWaveFormatExtensible(const QAudioFormat &format, WAVEFORMATEXTENSIBLE &wfx)
+{
+ if (!format.isValid())
+ return false;
+
+ wfx.Format.nSamplesPerSec = format.sampleRate();
+ wfx.Format.wBitsPerSample = wfx.Samples.wValidBitsPerSample = format.bytesPerSample()*8;
+ wfx.Format.nChannels = format.channelCount();
+ wfx.Format.nBlockAlign = (wfx.Format.wBitsPerSample / 8) * wfx.Format.nChannels;
+ wfx.Format.nAvgBytesPerSec = wfx.Format.nBlockAlign * wfx.Format.nSamplesPerSec;
+ wfx.Format.cbSize = 0;
+
+ if (format.sampleFormat() == QAudioFormat::Float) {
+ wfx.Format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+ wfx.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
+ } else {
+ wfx.Format.wFormatTag = WAVE_FORMAT_PCM;
+ wfx.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
+ }
+
+ if (format.channelCount() > 2) {
+ wfx.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
+ wfx.Format.cbSize = 22;
+ wfx.dwChannelMask = format.channelConfig() == QAudioFormat::ChannelConfigUnknown ? KSAUDIO_SPEAKER_DIRECTOUT
+ : DWORD(format.channelConfig());
+ }
+
+ return true;
+}
+
+QAudioFormat QWindowsAudioUtils::waveFormatExToFormat(const WAVEFORMATEX &in)
+{
+ QAudioFormat out;
+ out.setSampleRate(in.nSamplesPerSec);
+ out.setChannelCount(in.nChannels);
+ if (in.wFormatTag == WAVE_FORMAT_PCM) {
+ if (in.wBitsPerSample == 8)
+ out.setSampleFormat(QAudioFormat::UInt8);
+ else if (in.wBitsPerSample == 16)
+ out.setSampleFormat(QAudioFormat::Int16);
+ else if (in.wBitsPerSample == 32)
+ out.setSampleFormat(QAudioFormat::Int32);
+ } else if (in.wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
+ if (in.cbSize >= 22) {
+ auto wfe = reinterpret_cast<const WAVEFORMATEXTENSIBLE &>(in);
+ if (wfe.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)
+ out.setSampleFormat(QAudioFormat::Float);
+ if (qPopulationCount(wfe.dwChannelMask) >= in.nChannels)
+ out.setChannelConfig(maskToChannelConfig(wfe.dwChannelMask, in.nChannels));
+ }
+ } else if (in.wFormatTag == WAVE_FORMAT_IEEE_FLOAT) {
+ out.setSampleFormat(QAudioFormat::Float);
+ }
+
+ return out;
+}
+
+QAudioFormat QWindowsAudioUtils::mediaTypeToFormat(IMFMediaType *mediaType)
+{
+ QAudioFormat format;
+ if (!mediaType)
+ return format;
+
+ UINT32 val = 0;
+ if (SUCCEEDED(mediaType->GetUINT32(MF_MT_AUDIO_NUM_CHANNELS, &val))) {
+ format.setChannelCount(int(val));
+ } else {
+ qWarning() << "Could not determine channel count from IMFMediaType";
+ return {};
+ }
+
+ if (SUCCEEDED(mediaType->GetUINT32(MF_MT_AUDIO_CHANNEL_MASK, &val))) {
+ if (int(qPopulationCount(val)) >= format.channelCount())
+ format.setChannelConfig(maskToChannelConfig(val, format.channelCount()));
+ }
+
+ if (SUCCEEDED(mediaType->GetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, &val))) {
+ format.setSampleRate(int(val));
+ }
+ UINT32 bitsPerSample = 0;
+ mediaType->GetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, &bitsPerSample);
+
+ GUID subType;
+ if (SUCCEEDED(mediaType->GetGUID(MF_MT_SUBTYPE, &subType))) {
+ if (subType == MFAudioFormat_Float) {
+ format.setSampleFormat(QAudioFormat::Float);
+ } else if (bitsPerSample == 8) {
+ format.setSampleFormat(QAudioFormat::UInt8);
+ } else if (bitsPerSample == 16) {
+ format.setSampleFormat(QAudioFormat::Int16);
+ } else if (bitsPerSample == 32){
+ format.setSampleFormat(QAudioFormat::Int32);
+ }
+ }
+ return format;
+}
+
+ComPtr<IMFMediaType> QWindowsAudioUtils::formatToMediaType(QWindowsMediaFoundation &wmf, const QAudioFormat &format)
+{
+ ComPtr<IMFMediaType> mediaType;
+
+ if (!format.isValid())
+ return mediaType;
+
+ wmf.mfCreateMediaType(mediaType.GetAddressOf());
+
+ mediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
+ if (format.sampleFormat() == QAudioFormat::Float) {
+ mediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_Float);
+ } else {
+ mediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
+ }
+
+ mediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, UINT32(format.channelCount()));
+ if (format.channelConfig() != QAudioFormat::ChannelConfigUnknown)
+ mediaType->SetUINT32(MF_MT_AUDIO_CHANNEL_MASK, channelConfigToMask(format.channelConfig()));
+ mediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, UINT32(format.sampleRate()));
+ auto alignmentBlock = UINT32(format.bytesPerFrame());
+ mediaType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, alignmentBlock);
+ auto avgBytesPerSec = UINT32(format.sampleRate() * format.bytesPerFrame());
+ mediaType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, avgBytesPerSec);
+ mediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, UINT32(format.bytesPerSample()*8));
+ mediaType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
+
+ return mediaType;
+}
+
+std::optional<quint32> QWindowsAudioUtils::audioClientFramesInUse(IAudioClient *client)
+{
+ Q_ASSERT(client);
+ UINT32 framesPadding = 0;
+ if (SUCCEEDED(client->GetCurrentPadding(&framesPadding)))
+ return framesPadding;
+ return {};
+}
+
+std::optional<quint32> QWindowsAudioUtils::audioClientFramesAllocated(IAudioClient *client)
+{
+ Q_ASSERT(client);
+ UINT32 bufferFrameCount = 0;
+ if (SUCCEEDED(client->GetBufferSize(&bufferFrameCount)))
+ return bufferFrameCount;
+ return {};
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/windows/qwindowsaudioutils_p.h b/src/multimedia/windows/qwindowsaudioutils_p.h
new file mode 100644
index 000000000..9382f372f
--- /dev/null
+++ b/src/multimedia/windows/qwindowsaudioutils_p.h
@@ -0,0 +1,45 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSAUDIOUTILS_H
+#define QWINDOWSAUDIOUTILS_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qaudioformat.h>
+#include <QtCore/qt_windows.h>
+#include <private/qcomptr_p.h>
+#include <mmreg.h>
+
+#include <optional>
+
+struct IAudioClient;
+struct IMFMediaType;
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsMediaFoundation;
+
+namespace QWindowsAudioUtils
+{
+ bool formatToWaveFormatExtensible(const QAudioFormat &format, WAVEFORMATEXTENSIBLE &wfx);
+ QAudioFormat waveFormatExToFormat(const WAVEFORMATEX &in);
+ Q_MULTIMEDIA_EXPORT QAudioFormat mediaTypeToFormat(IMFMediaType *mediaType);
+ ComPtr<IMFMediaType> formatToMediaType(QWindowsMediaFoundation &, const QAudioFormat &format);
+ QAudioFormat::ChannelConfig maskToChannelConfig(UINT32 mask, int count);
+ std::optional<quint32> audioClientFramesInUse(IAudioClient *client);
+ std::optional<quint32> audioClientFramesAllocated(IAudioClient *client);
+}
+
+QT_END_NAMESPACE
+
+#endif // QWINDOWSAUDIOUTILS_H
diff --git a/src/multimedia/windows/qwindowsmediadevices.cpp b/src/multimedia/windows/qwindowsmediadevices.cpp
new file mode 100644
index 000000000..c622a721c
--- /dev/null
+++ b/src/multimedia/windows/qwindowsmediadevices.cpp
@@ -0,0 +1,345 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsmediadevices_p.h"
+#include "qmediadevices.h"
+#include "qvarlengtharray.h"
+
+#include "qwindowsaudiosource_p.h"
+#include "qwindowsaudiosink_p.h"
+#include "qwindowsaudiodevice_p.h"
+#include "qcomtaskresource_p.h"
+
+#include <mmsystem.h>
+#include <mmddk.h>
+#include <mfobjects.h>
+#include <mfidl.h>
+#include <mferror.h>
+#include <mmdeviceapi.h>
+#include <qwindowsmfdefs_p.h>
+
+#include <QtCore/qmap.h>
+#include <private/qcomobject_p.h>
+#include <private/qsystemerror_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class CMMNotificationClient : public QComObject<IMMNotificationClient>
+{
+ ComPtr<IMMDeviceEnumerator> m_enumerator;
+ QWindowsMediaDevices *m_windowsMediaDevices;
+ QMap<QString, DWORD> m_deviceState;
+
+public:
+ CMMNotificationClient(QWindowsMediaDevices *windowsMediaDevices,
+ ComPtr<IMMDeviceEnumerator> enumerator,
+ QMap<QString, DWORD> &&deviceState)
+ : m_enumerator(enumerator),
+ m_windowsMediaDevices(windowsMediaDevices),
+ m_deviceState(deviceState)
+ {}
+
+ HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR) override
+ {
+ if (role == ERole::eMultimedia)
+ emitAudioDevicesChanged(flow);
+
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR deviceID) override
+ {
+ auto it = m_deviceState.find(QString::fromWCharArray(deviceID));
+ if (it == std::end(m_deviceState)) {
+ m_deviceState.insert(QString::fromWCharArray(deviceID), DEVICE_STATE_ACTIVE);
+ emitAudioDevicesChanged(deviceID);
+ }
+
+ return S_OK;
+ };
+
+ HRESULT STDMETHODCALLTYPE OnDeviceRemoved(LPCWSTR deviceID) override
+ {
+ auto key = QString::fromWCharArray(deviceID);
+ auto it = m_deviceState.find(key);
+ if (it != std::end(m_deviceState)) {
+ if (it.value() == DEVICE_STATE_ACTIVE)
+ emitAudioDevicesChanged(deviceID);
+ m_deviceState.remove(key);
+ }
+
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE OnDeviceStateChanged(LPCWSTR deviceID, DWORD newState) override
+ {
+ if (auto it = m_deviceState.find(QString::fromWCharArray(deviceID)); it != std::end(m_deviceState)) {
+ // If either the old state or the new state is active emit device change
+ if ((it.value() == DEVICE_STATE_ACTIVE) != (newState == DEVICE_STATE_ACTIVE)) {
+ emitAudioDevicesChanged(deviceID);
+ }
+ it.value() = newState;
+ }
+
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE OnPropertyValueChanged(LPCWSTR, const PROPERTYKEY) override
+ {
+ return S_OK;
+ }
+
+ void emitAudioDevicesChanged(EDataFlow flow)
+ {
+ // windowsMediaDevice may be deleted as we are executing the callback
+ if (flow == EDataFlow::eCapture) {
+ emit m_windowsMediaDevices->audioInputsChanged();
+ } else if (flow == EDataFlow::eRender) {
+ emit m_windowsMediaDevices->audioOutputsChanged();
+ }
+ }
+
+ void emitAudioDevicesChanged(LPCWSTR deviceID)
+ {
+ ComPtr<IMMDevice> device;
+ ComPtr<IMMEndpoint> endpoint;
+ EDataFlow flow;
+
+ if (SUCCEEDED(m_enumerator->GetDevice(deviceID, device.GetAddressOf()))
+ && SUCCEEDED(device->QueryInterface(__uuidof(IMMEndpoint), (void**)endpoint.GetAddressOf()))
+ && SUCCEEDED(endpoint->GetDataFlow(&flow)))
+ {
+ emitAudioDevicesChanged(flow);
+ }
+ }
+
+private:
+ // Destructor is not public. Caller should call Release.
+ ~CMMNotificationClient() override = default;
+};
+
+QWindowsMediaDevices::QWindowsMediaDevices()
+ : QPlatformMediaDevices()
+{
+ auto hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr,
+ CLSCTX_INPROC_SERVER,__uuidof(IMMDeviceEnumerator),
+ (void**)&m_deviceEnumerator);
+
+ if (FAILED(hr)) {
+ qWarning("Failed to instantiate IMMDeviceEnumerator (%s)."
+ "Audio device change notification will be disabled",
+ qPrintable(QSystemError::windowsComString(hr)));
+ return;
+ }
+
+ QMap<QString, DWORD> devState;
+ ComPtr<IMMDeviceCollection> devColl;
+ UINT count = 0;
+
+ if (SUCCEEDED(m_deviceEnumerator->EnumAudioEndpoints(EDataFlow::eAll, DEVICE_STATEMASK_ALL, devColl.GetAddressOf()))
+ && SUCCEEDED(devColl->GetCount(&count)))
+ {
+ for (UINT i = 0; i < count; i++) {
+ ComPtr<IMMDevice> device;
+ DWORD state = 0;
+ QComTaskResource<WCHAR> id;
+
+ if (SUCCEEDED(devColl->Item(i, device.GetAddressOf()))
+ && SUCCEEDED(device->GetState(&state))
+ && SUCCEEDED(device->GetId(id.address()))) {
+ devState.insert(QString::fromWCharArray(id.get()), state);
+ }
+ }
+ }
+
+
+ m_notificationClient = makeComObject<CMMNotificationClient>(this, m_deviceEnumerator, std::move(devState));
+ m_deviceEnumerator->RegisterEndpointNotificationCallback(m_notificationClient.Get());
+}
+
+QWindowsMediaDevices::~QWindowsMediaDevices()
+{
+ if (m_deviceEnumerator) {
+ // Note: Calling UnregisterEndpointNotificationCallback after CoUninitialize
+ // will abruptly terminate application, preventing remaining destructors from
+ // being called (QTBUG-120198).
+ m_deviceEnumerator->UnregisterEndpointNotificationCallback(m_notificationClient.Get());
+ }
+ if (m_warmUpAudioClient) {
+ HRESULT hr = m_warmUpAudioClient->Stop();
+ if (FAILED(hr)) {
+ qWarning() << "Failed to stop audio engine" << hr;
+ }
+ }
+
+ m_deviceEnumerator.Reset();
+ m_notificationClient.Reset();
+ m_warmUpAudioClient.Reset();
+}
+
+QList<QAudioDevice> QWindowsMediaDevices::availableDevices(QAudioDevice::Mode mode) const
+{
+ if (!m_deviceEnumerator)
+ return {};
+
+ const auto audioOut = mode == QAudioDevice::Output;
+
+ const auto defaultAudioDeviceID = [this, audioOut]{
+ const auto dataFlow = audioOut ? EDataFlow::eRender : EDataFlow::eCapture;
+ ComPtr<IMMDevice> dev;
+ QComTaskResource<WCHAR> id;
+ QString sid;
+
+ if (SUCCEEDED(m_deviceEnumerator->GetDefaultAudioEndpoint(dataFlow, ERole::eMultimedia, dev.GetAddressOf()))) {
+ if (dev && SUCCEEDED(dev->GetId(id.address()))) {
+ sid = QString::fromWCharArray(id.get());
+ }
+ }
+ return sid.toUtf8();
+ }();
+
+ QList<QAudioDevice> devices;
+
+ auto waveDevices = audioOut ? waveOutGetNumDevs() : waveInGetNumDevs();
+
+ for (auto waveID = 0u; waveID < waveDevices; waveID++) {
+ auto wave = IntToPtr(waveID);
+ auto waveMessage = [wave, audioOut](UINT msg, auto p0, auto p1) {
+ return audioOut ? waveOutMessage((HWAVEOUT)wave, msg, (DWORD_PTR)p0, (DWORD_PTR)p1)
+ : waveInMessage((HWAVEIN)wave, msg, (DWORD_PTR)p0, (DWORD_PTR)p1);
+ };
+
+ size_t len = 0;
+ if (waveMessage(DRV_QUERYFUNCTIONINSTANCEIDSIZE, &len, 0) != MMSYSERR_NOERROR)
+ continue;
+
+ QVarLengthArray<WCHAR> id(len);
+ if (waveMessage(DRV_QUERYFUNCTIONINSTANCEID, id.data(), len) != MMSYSERR_NOERROR)
+ continue;
+
+ ComPtr<IMMDevice> device;
+ ComPtr<IPropertyStore> props;
+ if (FAILED(m_deviceEnumerator->GetDevice(id.data(), device.GetAddressOf()))
+ || FAILED(device->OpenPropertyStore(STGM_READ, props.GetAddressOf()))) {
+ continue;
+ }
+
+ PROPVARIANT varName;
+ PropVariantInit(&varName);
+
+ if (SUCCEEDED(props->GetValue(QMM_PKEY_Device_FriendlyName, &varName))) {
+ auto description = QString::fromWCharArray(varName.pwszVal);
+ auto strID = QString::fromWCharArray(id.data()).toUtf8();
+
+ auto dev = new QWindowsAudioDeviceInfo(strID, device, waveID, description, mode);
+ dev->isDefault = strID == defaultAudioDeviceID;
+
+ devices.append(dev->create());
+ }
+ PropVariantClear(&varName);
+ }
+
+ return devices;
+}
+
+QList<QAudioDevice> QWindowsMediaDevices::audioInputs() const
+{
+ return availableDevices(QAudioDevice::Input);
+}
+
+QList<QAudioDevice> QWindowsMediaDevices::audioOutputs() const
+{
+ return availableDevices(QAudioDevice::Output);
+}
+
+QPlatformAudioSource *QWindowsMediaDevices::createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ const auto *devInfo = static_cast<const QWindowsAudioDeviceInfo *>(deviceInfo.handle());
+ return new QWindowsAudioSource(devInfo->immDev(), parent);
+}
+
+QPlatformAudioSink *QWindowsMediaDevices::createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent)
+{
+ const auto *devInfo = static_cast<const QWindowsAudioDeviceInfo *>(deviceInfo.handle());
+ return new QWindowsAudioSink(devInfo->immDev(), parent);
+}
+
+static bool isPrepareAudioEnabled()
+{
+ static bool isDisableAudioPrepareSet = false;
+ static const int disableAudioPrepare =
+ qEnvironmentVariableIntValue("QT_DISABLE_AUDIO_PREPARE", &isDisableAudioPrepareSet);
+
+ return !isDisableAudioPrepareSet || disableAudioPrepare == 0;
+}
+
+void QWindowsMediaDevices::prepareAudio()
+{
+ if (!isPrepareAudioEnabled())
+ return;
+
+ if (m_isAudioClientWarmedUp.exchange(true))
+ return;
+
+ ComPtr<IMMDeviceEnumerator> deviceEnumerator;
+ HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL,
+ __uuidof(IMMDeviceEnumerator),
+ reinterpret_cast<void **>(deviceEnumerator.GetAddressOf()));
+ if (FAILED(hr)) {
+ qWarning() << "Failed to create device enumerator" << hr;
+ return;
+ }
+
+ ComPtr<IMMDevice> device;
+ hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, device.GetAddressOf());
+ if (FAILED(hr)) {
+ if (hr != E_NOTFOUND)
+ qWarning() << "Failed to retrieve default audio endpoint" << hr;
+ return;
+ }
+
+ hr = device->Activate(__uuidof(IAudioClient3), CLSCTX_ALL, nullptr,
+ reinterpret_cast<void **>(m_warmUpAudioClient.GetAddressOf()));
+ if (FAILED(hr)) {
+ qWarning() << "Failed to activate audio engine" << hr;
+ return;
+ }
+
+ QComTaskResource<WAVEFORMATEX> deviceFormat;
+ UINT32 currentPeriodInFrames = 0;
+ hr = m_warmUpAudioClient->GetCurrentSharedModeEnginePeriod(deviceFormat.address(),
+ &currentPeriodInFrames);
+ if (FAILED(hr)) {
+ qWarning() << "Failed to retrieve the current format and periodicity of the audio engine"
+ << hr;
+ return;
+ }
+
+ UINT32 defaultPeriodInFrames = 0;
+ UINT32 fundamentalPeriodInFrames = 0;
+ UINT32 minPeriodInFrames = 0;
+ UINT32 maxPeriodInFrames = 0;
+ hr = m_warmUpAudioClient->GetSharedModeEnginePeriod(deviceFormat.get(), &defaultPeriodInFrames,
+ &fundamentalPeriodInFrames,
+ &minPeriodInFrames, &maxPeriodInFrames);
+ if (FAILED(hr)) {
+ qWarning() << "Failed to retrieve the range of periodicities supported by the audio engine"
+ << hr;
+ return;
+ }
+
+ hr = m_warmUpAudioClient->InitializeSharedAudioStream(
+ AUDCLNT_SHAREMODE_SHARED, minPeriodInFrames, deviceFormat.get(), nullptr);
+ if (FAILED(hr)) {
+ qWarning() << "Failed to initialize audio engine stream" << hr;
+ return;
+ }
+
+ hr = m_warmUpAudioClient->Start();
+ if (FAILED(hr))
+ qWarning() << "Failed to start audio engine" << hr;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/windows/qwindowsmediadevices_p.h b/src/multimedia/windows/qwindowsmediadevices_p.h
new file mode 100644
index 000000000..c82be8a0d
--- /dev/null
+++ b/src/multimedia/windows/qwindowsmediadevices_p.h
@@ -0,0 +1,65 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSMEDIADEVICES_H
+#define QWINDOWSMEDIADEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediadevices_p.h>
+#include <private/qcomptr_p.h>
+#include <QtCore/private/qfunctions_win_p.h>
+#include <private/qwindowsmediafoundation_p.h>
+
+#include <qaudiodevice.h>
+
+struct IAudioClient3;
+struct IMMDeviceEnumerator;
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsEngine;
+class CMMNotificationClient;
+
+class QWindowsMediaDevices : public QPlatformMediaDevices
+{
+public:
+ QWindowsMediaDevices();
+ virtual ~QWindowsMediaDevices();
+
+ QList<QAudioDevice> audioInputs() const override;
+ QList<QAudioDevice> audioOutputs() const override;
+ QPlatformAudioSource *createAudioSource(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+ QPlatformAudioSink *createAudioSink(const QAudioDevice &deviceInfo,
+ QObject *parent) override;
+
+ void prepareAudio() override;
+
+private:
+ QComHelper m_comRuntime;
+ QMFRuntimeInit m_wmfRuntime{ QWindowsMediaFoundation::instance() };
+ QList<QAudioDevice> availableDevices(QAudioDevice::Mode mode) const;
+
+ ComPtr<IMMDeviceEnumerator> m_deviceEnumerator;
+ ComPtr<CMMNotificationClient> m_notificationClient;
+ // The "warm-up" audio client is required to run in the background in order to keep audio engine
+ // ready for audio output immediately after creating any other subsequent audio client.
+ ComPtr<IAudioClient3> m_warmUpAudioClient;
+ std::atomic_bool m_isAudioClientWarmedUp = false;
+
+ friend CMMNotificationClient;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/windows/qwindowsmediafoundation.cpp b/src/multimedia/windows/qwindowsmediafoundation.cpp
new file mode 100644
index 000000000..7094c9551
--- /dev/null
+++ b/src/multimedia/windows/qwindowsmediafoundation.cpp
@@ -0,0 +1,70 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsmediafoundation_p.h"
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+
+Q_GLOBAL_STATIC(QWindowsMediaFoundation, s_wmf);
+
+template <typename T>
+bool setProcAddress(QSystemLibrary &lib, T &f, const char name[])
+{
+ f = reinterpret_cast<T>(lib.resolve(name));
+ return static_cast<bool>(f);
+}
+
+} // namespace
+
+QWindowsMediaFoundation *QWindowsMediaFoundation::instance()
+{
+ if (s_wmf->valid())
+ return s_wmf;
+
+ return nullptr;
+}
+
+QWindowsMediaFoundation::QWindowsMediaFoundation()
+{
+ if (!m_mfplat.load(false))
+ return;
+
+ m_valid = setProcAddress(m_mfplat, mfStartup, "MFStartup")
+ && setProcAddress(m_mfplat, mfShutdown, "MFShutdown")
+ && setProcAddress(m_mfplat, mfCreateMediaType, "MFCreateMediaType")
+ && setProcAddress(m_mfplat, mfCreateMemoryBuffer, "MFCreateMemoryBuffer")
+ && setProcAddress(m_mfplat, mfCreateSample, "MFCreateSample");
+
+ Q_ASSERT(m_valid); // If it is not valid at this point, we have a programming bug
+}
+
+QWindowsMediaFoundation::~QWindowsMediaFoundation() = default;
+
+bool QWindowsMediaFoundation::valid() const
+{
+ return m_valid;
+}
+
+QMFRuntimeInit::QMFRuntimeInit(QWindowsMediaFoundation *wmf)
+ : m_wmf{ wmf }, m_initResult{ wmf ? m_wmf->mfStartup(MF_VERSION, MFSTARTUP_FULL) : E_FAIL }
+{
+ if (m_initResult != S_OK)
+ qErrnoWarning(m_initResult, "Failed to initialize Windows Media Foundation");
+}
+
+QMFRuntimeInit::~QMFRuntimeInit()
+{
+ // According to documentation MFShutdown should be called
+ // also when MFStartup failed. This is wrong.
+ if (FAILED(m_initResult))
+ return;
+
+ const HRESULT hr = m_wmf->mfShutdown();
+ if (hr != S_OK)
+ qErrnoWarning(hr, "Failed to shut down Windows Media Foundation");
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/windows/qwindowsmediafoundation_p.h b/src/multimedia/windows/qwindowsmediafoundation_p.h
new file mode 100644
index 000000000..6dabc261e
--- /dev/null
+++ b/src/multimedia/windows/qwindowsmediafoundation_p.h
@@ -0,0 +1,59 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSMEDIAFOUNDATION_H
+#define QWINDOWSMEDIAFOUNDATION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <QtCore/private/qsystemlibrary_p.h>
+#include <mfapi.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsMediaFoundation
+{
+public:
+ static QWindowsMediaFoundation *instance();
+
+ QWindowsMediaFoundation();
+ ~QWindowsMediaFoundation();
+
+ bool valid() const;
+
+ decltype(&::MFStartup) mfStartup = nullptr;
+ decltype(&::MFShutdown) mfShutdown = nullptr;
+ decltype(&::MFCreateMediaType) mfCreateMediaType = nullptr;
+ decltype(&::MFCreateMemoryBuffer) mfCreateMemoryBuffer = nullptr;
+ decltype(&::MFCreateSample) mfCreateSample = nullptr;
+
+private:
+ QSystemLibrary m_mfplat{ QStringLiteral("Mfplat.dll") };
+ bool m_valid = false;
+};
+
+class QMFRuntimeInit
+{
+ Q_DISABLE_COPY_MOVE(QMFRuntimeInit)
+public:
+ QMFRuntimeInit(QWindowsMediaFoundation *wmf);
+ ~QMFRuntimeInit();
+
+private:
+ QWindowsMediaFoundation *m_wmf;
+ HRESULT m_initResult;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWINDOWSMEDIAFOUNDATION_H
diff --git a/src/multimedia/windows/qwindowsmfdefs.cpp b/src/multimedia/windows/qwindowsmfdefs.cpp
new file mode 100644
index 000000000..ef8c99922
--- /dev/null
+++ b/src/multimedia/windows/qwindowsmfdefs.cpp
@@ -0,0 +1,26 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsmfdefs_p.h"
+
+const GUID QMM_MFTranscodeContainerType_ADTS = {0x132fd27d, 0x0f02, 0x43de, {0xa3, 0x01, 0x38, 0xfb, 0xbb, 0xb3, 0x83, 0x4e}};
+const GUID QMM_MFTranscodeContainerType_ASF = {0x430f6f6e, 0xb6bf, 0x4fc1, {0xa0, 0xbd, 0x9e, 0xe4, 0x6e, 0xee, 0x2a, 0xfb}};
+const GUID QMM_MFTranscodeContainerType_AVI = {0x7edfe8af, 0x402f, 0x4d76, {0xa3, 0x3c, 0x61, 0x9f, 0xd1, 0x57, 0xd0, 0xf1}};
+const GUID QMM_MFTranscodeContainerType_FLAC = {0x31344aa3, 0x05a9, 0x42b5, {0x90, 0x1b, 0x8e, 0x9d, 0x42, 0x57, 0xf7, 0x5e}};
+const GUID QMM_MFTranscodeContainerType_MP3 = {0xe438b912, 0x83f1, 0x4de6, {0x9e, 0x3a, 0x9f, 0xfb, 0xc6, 0xdd, 0x24, 0xd1}};
+const GUID QMM_MFTranscodeContainerType_MPEG4 = {0xdc6cd05d, 0xb9d0, 0x40ef, {0xbd, 0x35, 0xfa, 0x62, 0x2c, 0x1a, 0xb2, 0x8a}};
+const GUID QMM_MFTranscodeContainerType_WAVE = {0x64c3453c, 0x0f26, 0x4741, {0xbe, 0x63, 0x87, 0xbd, 0xf8, 0xbb, 0x93, 0x5b}};
+
+const GUID QMM_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID = {0x8ac3587a, 0x4ae7, 0x42d8, {0x99, 0xe0, 0x0a, 0x60, 0x13, 0xee, 0xf9, 0x0f}};
+const GUID QMM_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_GUID = {0x14dd9a1c, 0x7cff, 0x41be, {0xb1, 0xb9, 0xba, 0x1a, 0xc6, 0xec, 0xb5, 0x71}};
+const GUID QMM_MF_TRANSCODE_CONTAINERTYPE = {0x150ff23f, 0x4abc, 0x478b, {0xac, 0x4f, 0xe1, 0x91, 0x6f, 0xba, 0x1c, 0xca}};
+
+const GUID QMM_MF_SD_STREAM_NAME = {0x4f1b099d, 0xd314, 0x41e5, {0xa7, 0x81, 0x7f, 0xef, 0xaa, 0x4c, 0x50, 0x1f}};
+const GUID QMM_MF_SD_LANGUAGE = {0xaf2180, 0xbdc2, 0x423c, {0xab, 0xca, 0xf5, 0x3, 0x59, 0x3b, 0xc1, 0x21}};
+
+const GUID QMM_KSCATEGORY_VIDEO_CAMERA = {0xe5323777, 0xf976, 0x4f5b, {0x9b, 0x55, 0xb9, 0x46, 0x99, 0xc4, 0x6e, 0x44}};
+const GUID QMM_KSCATEGORY_SENSOR_CAMERA = {0x24e552d7, 0x6523, 0x47f7, {0xa6, 0x47, 0xd3, 0x46, 0x5b, 0xf1, 0xf5, 0xca}};
+const GUID QMM_MR_POLICY_VOLUME_SERVICE = {0x1abaa2ac, 0x9d3b, 0x47c6, {0xab, 0x48, 0xc5, 0x95, 0x6, 0xde, 0x78, 0x4d}};
+
+const PROPERTYKEY QMM_PKEY_Device_FriendlyName = {{0xa45c254e, 0xdf1c, 0x4efd, {0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0}}, 14};
+
diff --git a/src/multimedia/windows/qwindowsmfdefs_p.h b/src/multimedia/windows/qwindowsmfdefs_p.h
new file mode 100644
index 000000000..4bb90dbe3
--- /dev/null
+++ b/src/multimedia/windows/qwindowsmfdefs_p.h
@@ -0,0 +1,94 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSMFDEFS_P_H
+#define QWINDOWSMFDEFS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qtmultimediaexports.h>
+#include <d3d9.h>
+#include <dxva2api.h>
+#include <mfidl.h>
+
+// Stuff that is missing or incorrecty defined in MinGW.
+
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MFTranscodeContainerType_ADTS;
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MFTranscodeContainerType_ASF;
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MFTranscodeContainerType_AVI;
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MFTranscodeContainerType_FLAC;
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MFTranscodeContainerType_MP3;
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MFTranscodeContainerType_MPEG4;
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MFTranscodeContainerType_WAVE;
+
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID;
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_GUID;
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MF_TRANSCODE_CONTAINERTYPE;
+
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MF_SD_STREAM_NAME;
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MF_SD_LANGUAGE;
+
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_KSCATEGORY_VIDEO_CAMERA;
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_KSCATEGORY_SENSOR_CAMERA;
+
+Q_MULTIMEDIA_EXPORT extern const GUID QMM_MR_POLICY_VOLUME_SERVICE;
+
+Q_MULTIMEDIA_EXPORT extern const PROPERTYKEY QMM_PKEY_Device_FriendlyName;
+
+extern "C" HRESULT WINAPI MFCreateDeviceSource(IMFAttributes *pAttributes, IMFMediaSource **ppSource);
+
+#define QMM_MFSESSION_GETFULLTOPOLOGY_CURRENT 1
+#define QMM_PRESENTATION_CURRENT_POSITION 0x7fffffffffffffff
+#define QMM_WININET_E_CANNOT_CONNECT ((HRESULT)0x80072EFDL)
+
+#ifndef __IMFVideoProcessor_INTERFACE_DEFINED__
+#define __IMFVideoProcessor_INTERFACE_DEFINED__
+DEFINE_GUID(IID_IMFVideoProcessor, 0x6AB0000C, 0xFECE, 0x4d1f, 0xA2,0xAC, 0xA9,0x57,0x35,0x30,0x65,0x6E);
+MIDL_INTERFACE("6AB0000C-FECE-4d1f-A2AC-A9573530656E")
+IMFVideoProcessor : public IUnknown
+{
+ virtual HRESULT STDMETHODCALLTYPE GetAvailableVideoProcessorModes(UINT *, GUID **) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetVideoProcessorCaps(LPGUID, DXVA2_VideoProcessorCaps *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetVideoProcessorMode(LPGUID) = 0;
+ virtual HRESULT STDMETHODCALLTYPE SetVideoProcessorMode(LPGUID) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetProcAmpRange(DWORD, DXVA2_ValueRange *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetProcAmpValues(DWORD, DXVA2_ProcAmpValues *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE SetProcAmpValues(DWORD, DXVA2_ProcAmpValues *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetFilteringRange(DWORD, DXVA2_ValueRange *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetFilteringValue(DWORD, DXVA2_Fixed32 *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE SetFilteringValue(DWORD, DXVA2_Fixed32 *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetBackgroundColor(COLORREF *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE SetBackgroundColor(COLORREF) = 0;
+};
+#ifdef __CRT_UUID_DECL
+__CRT_UUID_DECL(IMFVideoProcessor, 0x6AB0000C, 0xFECE, 0x4d1f, 0xA2,0xAC, 0xA9,0x57,0x35,0x30,0x65,0x6E)
+#endif
+#endif // __IMFVideoProcessor_INTERFACE_DEFINED__
+
+#ifndef __IMFSimpleAudioVolume_INTERFACE_DEFINED__
+#define __IMFSimpleAudioVolume_INTERFACE_DEFINED__
+DEFINE_GUID(IID_IMFSimpleAudioVolume, 0x089EDF13, 0xCF71, 0x4338, 0x8D,0x13, 0x9E,0x56,0x9D,0xBD,0xC3,0x19);
+MIDL_INTERFACE("089EDF13-CF71-4338-8D13-9E569DBDC319")
+IMFSimpleAudioVolume : public IUnknown
+{
+ virtual HRESULT STDMETHODCALLTYPE SetMasterVolume(float) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetMasterVolume(float *) = 0;
+ virtual HRESULT STDMETHODCALLTYPE SetMute(BOOL) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetMute(BOOL *) = 0;
+};
+#ifdef __CRT_UUID_DECL
+__CRT_UUID_DECL(IMFSimpleAudioVolume, 0x089EDF13, 0xCF71, 0x4338, 0x8D,0x13, 0x9E,0x56,0x9D,0xBD,0xC3,0x19)
+#endif
+#endif // __IMFSimpleAudioVolume_INTERFACE_DEFINED__
+
+#endif // QWINDOWSMFDEFS_P_H
+
diff --git a/src/multimedia/windows/qwindowsmultimediautils.cpp b/src/multimedia/windows/qwindowsmultimediautils.cpp
new file mode 100644
index 000000000..258cb3e96
--- /dev/null
+++ b/src/multimedia/windows/qwindowsmultimediautils.cpp
@@ -0,0 +1,215 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#if defined(WINVER) && WINVER < _WIN32_WINNT_WIN10
+# undef WINVER
+#endif
+#if !defined(WINVER)
+# define WINVER _WIN32_WINNT_WIN10 // Enables newer audio formats.
+#endif
+
+#include "qwindowsmultimediautils_p.h"
+
+#include <initguid.h>
+#include <mfapi.h>
+#include <mfidl.h>
+#include <qwindowsmfdefs_p.h>
+#include <system_error>
+
+QT_BEGIN_NAMESPACE
+
+QVideoFrameFormat::PixelFormat QWindowsMultimediaUtils::pixelFormatFromMediaSubtype(const GUID &subtype)
+{
+ if (subtype == MFVideoFormat_ARGB32)
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ return QVideoFrameFormat::Format_BGRA8888;
+#else
+ return QVideoFrameFormat::Format_ARGB8888;
+#endif
+ if (subtype == MFVideoFormat_RGB32)
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ return QVideoFrameFormat::Format_BGRX8888;
+#else
+ return QVideoFrameFormat::Format_XRGB8888;
+#endif
+ if (subtype == MFVideoFormat_AYUV)
+ return QVideoFrameFormat::Format_AYUV;
+ if (subtype == MFVideoFormat_I420)
+ return QVideoFrameFormat::Format_YUV420P;
+ if (subtype == MFVideoFormat_UYVY)
+ return QVideoFrameFormat::Format_UYVY;
+ if (subtype == MFVideoFormat_YV12)
+ return QVideoFrameFormat::Format_YV12;
+ if (subtype == MFVideoFormat_NV12)
+ return QVideoFrameFormat::Format_NV12;
+ if (subtype == MFVideoFormat_YUY2)
+ return QVideoFrameFormat::Format_YUYV;
+ if (subtype == MFVideoFormat_P010)
+ return QVideoFrameFormat::Format_P010;
+ if (subtype == MFVideoFormat_P016)
+ return QVideoFrameFormat::Format_P016;
+ if (subtype == MFVideoFormat_L8)
+ return QVideoFrameFormat::Format_Y8;
+ if (subtype == MFVideoFormat_L16)
+ return QVideoFrameFormat::Format_Y16;
+ if (subtype == MFVideoFormat_MJPG)
+ return QVideoFrameFormat::Format_Jpeg;
+
+ return QVideoFrameFormat::Format_Invalid;
+}
+
+GUID QWindowsMultimediaUtils::videoFormatForCodec(QMediaFormat::VideoCodec codec)
+{
+ switch (codec) {
+ case QMediaFormat::VideoCodec::MPEG1:
+ return MFVideoFormat_MPG1;
+ case QMediaFormat::VideoCodec::MPEG2:
+ return MFVideoFormat_MPEG2;
+ case QMediaFormat::VideoCodec::MPEG4:
+ return MFVideoFormat_MP4V;
+ case QMediaFormat::VideoCodec::H264:
+ return MFVideoFormat_H264;
+ case QMediaFormat::VideoCodec::H265:
+ return MFVideoFormat_H265;
+ case QMediaFormat::VideoCodec::VP8:
+ return MFVideoFormat_VP80;
+ case QMediaFormat::VideoCodec::VP9:
+ return MFVideoFormat_VP90;
+ case QMediaFormat::VideoCodec::AV1:
+ return MFVideoFormat_AV1;
+ case QMediaFormat::VideoCodec::WMV:
+ return MFVideoFormat_WMV3;
+ case QMediaFormat::VideoCodec::MotionJPEG:
+ return MFVideoFormat_MJPG;
+ default:
+ return MFVideoFormat_H264;
+ }
+}
+
+QMediaFormat::VideoCodec QWindowsMultimediaUtils::codecForVideoFormat(GUID format)
+{
+ if (format == MFVideoFormat_MPG1)
+ return QMediaFormat::VideoCodec::MPEG1;
+ if (format == MFVideoFormat_MPEG2)
+ return QMediaFormat::VideoCodec::MPEG2;
+ if (format == MFVideoFormat_MP4V
+ || format == MFVideoFormat_M4S2
+ || format == MFVideoFormat_MP4S
+ || format == MFVideoFormat_MP43)
+ return QMediaFormat::VideoCodec::MPEG4;
+ if (format == MFVideoFormat_H264)
+ return QMediaFormat::VideoCodec::H264;
+ if (format == MFVideoFormat_H265)
+ return QMediaFormat::VideoCodec::H265;
+ if (format == MFVideoFormat_VP80)
+ return QMediaFormat::VideoCodec::VP8;
+ if (format == MFVideoFormat_VP90)
+ return QMediaFormat::VideoCodec::VP9;
+ if (format == MFVideoFormat_AV1)
+ return QMediaFormat::VideoCodec::AV1;
+ if (format == MFVideoFormat_WMV1
+ || format == MFVideoFormat_WMV2
+ || format == MFVideoFormat_WMV3)
+ return QMediaFormat::VideoCodec::WMV;
+ if (format == MFVideoFormat_MJPG)
+ return QMediaFormat::VideoCodec::MotionJPEG;
+ return QMediaFormat::VideoCodec::Unspecified;
+}
+
+GUID QWindowsMultimediaUtils::audioFormatForCodec(QMediaFormat::AudioCodec codec)
+{
+ switch (codec) {
+ case QMediaFormat::AudioCodec::MP3:
+ return MFAudioFormat_MP3;
+ case QMediaFormat::AudioCodec::AAC:
+ return MFAudioFormat_AAC;
+ case QMediaFormat::AudioCodec::ALAC:
+ return MFAudioFormat_ALAC;
+ case QMediaFormat::AudioCodec::FLAC:
+ return MFAudioFormat_FLAC;
+ case QMediaFormat::AudioCodec::Vorbis:
+ return MFAudioFormat_Vorbis;
+ case QMediaFormat::AudioCodec::Wave:
+ return MFAudioFormat_PCM;
+ case QMediaFormat::AudioCodec::Opus:
+ return MFAudioFormat_Opus;
+ case QMediaFormat::AudioCodec::AC3:
+ return MFAudioFormat_Dolby_AC3;
+ case QMediaFormat::AudioCodec::EAC3:
+ return MFAudioFormat_Dolby_DDPlus;
+ case QMediaFormat::AudioCodec::WMA:
+ return MFAudioFormat_WMAudioV9;
+ default:
+ return MFAudioFormat_AAC;
+ }
+}
+
+QMediaFormat::AudioCodec QWindowsMultimediaUtils::codecForAudioFormat(GUID format)
+{
+ if (format == MFAudioFormat_MP3)
+ return QMediaFormat::AudioCodec::MP3;
+ if (format == MFAudioFormat_AAC)
+ return QMediaFormat::AudioCodec::AAC;
+ if (format == MFAudioFormat_ALAC)
+ return QMediaFormat::AudioCodec::ALAC;
+ if (format == MFAudioFormat_FLAC)
+ return QMediaFormat::AudioCodec::FLAC;
+ if (format == MFAudioFormat_Vorbis)
+ return QMediaFormat::AudioCodec::Vorbis;
+ if (format == MFAudioFormat_PCM)
+ return QMediaFormat::AudioCodec::Wave;
+ if (format == MFAudioFormat_Opus)
+ return QMediaFormat::AudioCodec::Opus;
+ if (format == MFAudioFormat_Dolby_AC3)
+ return QMediaFormat::AudioCodec::AC3;
+ if (format == MFAudioFormat_Dolby_DDPlus)
+ return QMediaFormat::AudioCodec::EAC3;
+ if (format == MFAudioFormat_WMAudioV8
+ || format == MFAudioFormat_WMAudioV9
+ || format == MFAudioFormat_WMAudio_Lossless)
+ return QMediaFormat::AudioCodec::WMA;
+ return QMediaFormat::AudioCodec::Unspecified;
+}
+
+GUID QWindowsMultimediaUtils::containerForVideoFileFormat(QMediaFormat::FileFormat format)
+{
+ switch (format) {
+ case QMediaFormat::FileFormat::MPEG4:
+ return QMM_MFTranscodeContainerType_MPEG4;
+ case QMediaFormat::FileFormat::WMV:
+ return QMM_MFTranscodeContainerType_ASF;
+ case QMediaFormat::FileFormat::AVI:
+ return QMM_MFTranscodeContainerType_AVI;
+ default:
+ return QMM_MFTranscodeContainerType_MPEG4;
+ }
+}
+
+GUID QWindowsMultimediaUtils::containerForAudioFileFormat(QMediaFormat::FileFormat format)
+{
+ switch (format) {
+ case QMediaFormat::FileFormat::MP3:
+ return QMM_MFTranscodeContainerType_MP3;
+ case QMediaFormat::FileFormat::AAC:
+ return QMM_MFTranscodeContainerType_ADTS;
+ case QMediaFormat::FileFormat::Mpeg4Audio:
+ return QMM_MFTranscodeContainerType_MPEG4;
+ case QMediaFormat::FileFormat::WMA:
+ return QMM_MFTranscodeContainerType_ASF;
+ case QMediaFormat::FileFormat::FLAC:
+ return QMM_MFTranscodeContainerType_FLAC;
+ case QMediaFormat::FileFormat::Wave:
+ return QMM_MFTranscodeContainerType_WAVE;
+ default:
+ return QMM_MFTranscodeContainerType_MPEG4;
+ }
+}
+
+QString QWindowsMultimediaUtils::errorString(HRESULT hr)
+{
+ return QStringLiteral("%1 %2")
+ .arg(quint32(hr), 8, 16)
+ .arg(QString::fromStdString(std::system_category().message(hr)));
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/windows/qwindowsmultimediautils_p.h b/src/multimedia/windows/qwindowsmultimediautils_p.h
new file mode 100644
index 000000000..58ecd425f
--- /dev/null
+++ b/src/multimedia/windows/qwindowsmultimediautils_p.h
@@ -0,0 +1,47 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSMULTIMEDIATUTILS_P_H
+#define QWINDOWSMULTIMEDIATUTILS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <private/qplatformmediaformatinfo_p.h>
+#include <qvideoframeformat.h>
+#include <guiddef.h>
+#include <qstring.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QWindowsMultimediaUtils {
+
+ Q_MULTIMEDIA_EXPORT QVideoFrameFormat::PixelFormat pixelFormatFromMediaSubtype(const GUID &subtype);
+
+ Q_MULTIMEDIA_EXPORT GUID videoFormatForCodec(QMediaFormat::VideoCodec codec);
+
+ Q_MULTIMEDIA_EXPORT QMediaFormat::VideoCodec codecForVideoFormat(GUID format);
+
+ Q_MULTIMEDIA_EXPORT GUID audioFormatForCodec(QMediaFormat::AudioCodec codec);
+
+ Q_MULTIMEDIA_EXPORT QMediaFormat::AudioCodec codecForAudioFormat(GUID format);
+
+ Q_MULTIMEDIA_EXPORT GUID containerForVideoFileFormat(QMediaFormat::FileFormat format);
+
+ Q_MULTIMEDIA_EXPORT GUID containerForAudioFileFormat(QMediaFormat::FileFormat format);
+
+ Q_MULTIMEDIA_EXPORT QString errorString(HRESULT hr);
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimedia/windows/qwindowsresampler.cpp b/src/multimedia/windows/qwindowsresampler.cpp
new file mode 100644
index 000000000..3c50c0c19
--- /dev/null
+++ b/src/multimedia/windows/qwindowsresampler.cpp
@@ -0,0 +1,241 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsresampler_p.h"
+#include <qwindowsaudioutils_p.h>
+#include <qloggingcategory.h>
+#include <QUuid>
+
+#include <wmcodecdsp.h>
+#include <mftransform.h>
+#include <mferror.h>
+
+QT_BEGIN_NAMESPACE
+
+QUuid qIID_IMFTransform(0xbf94c121, 0x5b05, 0x4e6f, 0x80,0x00, 0xba,0x59,0x89,0x61,0x41,0x4d);
+QUuid qCLSID_CResamplerMediaObject("f447b69e-1884-4a7e-8055-346f74d6edb3");
+
+static Q_LOGGING_CATEGORY(qLcAudioResampler, "qt.multimedia.audioresampler")
+
+QWindowsResampler::QWindowsResampler()
+{
+ CoCreateInstance(qCLSID_CResamplerMediaObject, nullptr, CLSCTX_INPROC_SERVER,
+ qIID_IMFTransform, (LPVOID*)(m_resampler.GetAddressOf()));
+ if (m_resampler)
+ m_resampler->AddInputStreams(1, &m_inputStreamID);
+}
+
+QWindowsResampler::~QWindowsResampler() = default;
+
+quint64 QWindowsResampler::outputBufferSize(quint64 inputBufferSize) const
+{
+ if (m_inputFormat.isValid() && m_outputFormat.isValid())
+ return m_outputFormat.bytesForDuration(m_inputFormat.durationForBytes(inputBufferSize));
+ else
+ return 0;
+}
+
+quint64 QWindowsResampler::inputBufferSize(quint64 outputBufferSize) const
+{
+ if (m_inputFormat.isValid() && m_outputFormat.isValid())
+ return m_inputFormat.bytesForDuration(m_outputFormat.durationForBytes(outputBufferSize));
+ else
+ return 0;
+}
+
+HRESULT QWindowsResampler::processInput(const QByteArrayView &in)
+{
+ ComPtr<IMFSample> sample;
+ HRESULT hr = m_wmf->mfCreateSample(sample.GetAddressOf());
+ if (FAILED(hr))
+ return hr;
+
+ ComPtr<IMFMediaBuffer> buffer;
+ hr = m_wmf->mfCreateMemoryBuffer(in.size(), buffer.GetAddressOf());
+ if (FAILED(hr))
+ return hr;
+
+ BYTE *data = nullptr;
+ DWORD maxLen = 0;
+ DWORD currentLen = 0;
+ hr = buffer->Lock(&data, &maxLen, &currentLen);
+ if (FAILED(hr))
+ return hr;
+
+ memcpy(data, in.data(), in.size());
+
+ hr = buffer->Unlock();
+ if (FAILED(hr))
+ return hr;
+
+ hr = buffer->SetCurrentLength(in.size());
+ if (FAILED(hr))
+ return hr;
+
+ hr = sample->AddBuffer(buffer.Get());
+ if (FAILED(hr))
+ return hr;
+
+ return m_resampler->ProcessInput(m_inputStreamID, sample.Get(), 0);
+}
+
+HRESULT QWindowsResampler::processOutput(QByteArray &out)
+{
+ ComPtr<IMFSample> sample;
+ ComPtr<IMFMediaBuffer> buffer;
+
+ if (m_resamplerNeedsSampleBuffer) {
+ HRESULT hr = m_wmf->mfCreateSample(sample.GetAddressOf());
+ if (FAILED(hr))
+ return hr;
+
+ auto expectedOutputSize = outputBufferSize(m_totalInputBytes) - m_totalOutputBytes;
+ hr = m_wmf->mfCreateMemoryBuffer(expectedOutputSize, buffer.GetAddressOf());
+ if (FAILED(hr))
+ return hr;
+
+ hr = sample->AddBuffer(buffer.Get());
+ if (FAILED(hr))
+ return hr;
+ }
+
+ HRESULT hr = S_OK;
+
+ MFT_OUTPUT_DATA_BUFFER outputDataBuffer;
+ outputDataBuffer.dwStreamID = 0;
+ do {
+ outputDataBuffer.pEvents = nullptr;
+ outputDataBuffer.dwStatus = 0;
+ outputDataBuffer.pSample = m_resamplerNeedsSampleBuffer ? sample.Get() : nullptr;
+ DWORD status = 0;
+ hr = m_resampler->ProcessOutput(0, 1, &outputDataBuffer, &status);
+ if (SUCCEEDED(hr)) {
+ ComPtr<IMFMediaBuffer> outputBuffer;
+ outputDataBuffer.pSample->ConvertToContiguousBuffer(outputBuffer.GetAddressOf());
+ DWORD len = 0;
+ BYTE *data = nullptr;
+ hr = outputBuffer->Lock(&data, nullptr, &len);
+ if (SUCCEEDED(hr))
+ out.push_back(QByteArray(reinterpret_cast<char *>(data), len));
+ outputBuffer->Unlock();
+ }
+ } while (SUCCEEDED(hr));
+
+ if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT)
+ hr = S_OK;
+
+ return hr;
+}
+
+QByteArray QWindowsResampler::resample(const QByteArrayView &in)
+{
+ m_totalInputBytes += in.size();
+
+ if (m_inputFormat == m_outputFormat) {
+ m_totalOutputBytes += in.size();
+ return {in.data(), in.size()};
+
+ } else {
+ Q_ASSERT(m_resampler && m_wmf);
+
+ QByteArray out;
+ HRESULT hr = processInput(in);
+ if (SUCCEEDED(hr))
+ hr = processOutput(out);
+
+ if (FAILED(hr))
+ qCWarning(qLcAudioResampler) << "Resampling failed" << hr;
+
+ m_totalOutputBytes += out.size();
+ return out;
+ }
+}
+
+QByteArray QWindowsResampler::resample(IMFSample *sample)
+{
+ Q_ASSERT(sample);
+
+ DWORD totalLength = 0;
+ HRESULT hr = sample->GetTotalLength(&totalLength);
+ if (FAILED(hr))
+ return {};
+
+ m_totalInputBytes += totalLength;
+
+ QByteArray out;
+
+ if (m_inputFormat == m_outputFormat) {
+ ComPtr<IMFMediaBuffer> outputBuffer;
+ sample->ConvertToContiguousBuffer(outputBuffer.GetAddressOf());
+ DWORD len = 0;
+ BYTE *data = nullptr;
+ hr = outputBuffer->Lock(&data, nullptr, &len);
+ if (SUCCEEDED(hr))
+ out.push_back(QByteArray(reinterpret_cast<char *>(data), len));
+ outputBuffer->Unlock();
+
+ } else {
+ Q_ASSERT(m_resampler && m_wmf);
+
+ hr = m_resampler->ProcessInput(m_inputStreamID, sample, 0);
+ if (SUCCEEDED(hr))
+ hr = processOutput(out);
+
+ if (FAILED(hr))
+ qCWarning(qLcAudioResampler) << "Resampling failed" << hr;
+ }
+
+ m_totalOutputBytes += out.size();
+
+ return out;
+}
+
+bool QWindowsResampler::setup(const QAudioFormat &fin, const QAudioFormat &fout)
+{
+ qCDebug(qLcAudioResampler) << "Setup audio resampler" << fin << "->" << fout;
+
+ m_totalInputBytes = 0;
+ m_totalOutputBytes = 0;
+
+ if (fin == fout) {
+ qCDebug(qLcAudioResampler) << "Pass through mode";
+ m_inputFormat = fin;
+ m_outputFormat = fout;
+ return true;
+ }
+
+ if (!m_resampler || !m_wmf)
+ return false;
+
+ ComPtr<IMFMediaType> min = QWindowsAudioUtils::formatToMediaType(*m_wmf, fin);
+ ComPtr<IMFMediaType> mout = QWindowsAudioUtils::formatToMediaType(*m_wmf, fout);
+
+ HRESULT hr = m_resampler->SetInputType(m_inputStreamID, min.Get(), 0);
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioResampler) << "Failed to set input type" << hr;
+ return false;
+ }
+
+ hr = m_resampler->SetOutputType(0, mout.Get(), 0);
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioResampler) << "Failed to set output type" << hr;
+ return false;
+ }
+
+ MFT_OUTPUT_STREAM_INFO streamInfo;
+ hr = m_resampler->GetOutputStreamInfo(0, &streamInfo);
+ if (FAILED(hr)) {
+ qCWarning(qLcAudioResampler) << "Could not obtain stream info" << hr;
+ return false;
+ }
+
+ m_resamplerNeedsSampleBuffer = (streamInfo.dwFlags
+ & (MFT_OUTPUT_STREAM_PROVIDES_SAMPLES | MFT_OUTPUT_STREAM_CAN_PROVIDE_SAMPLES)) == 0;
+
+ m_inputFormat = fin;
+ m_outputFormat = fout;
+
+ return true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/windows/qwindowsresampler_p.h b/src/multimedia/windows/qwindowsresampler_p.h
new file mode 100644
index 000000000..5885bffa6
--- /dev/null
+++ b/src/multimedia/windows/qwindowsresampler_p.h
@@ -0,0 +1,75 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#ifndef QT_QWINDOWSRESAMPLER_H
+#define QT_QWINDOWSRESAMPLER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qbytearray.h>
+#include <qbytearrayview.h>
+#include <qaudioformat.h>
+#include <private/qcomptr_p.h>
+#include <private/qwindowsmediafoundation_p.h>
+#include <qt_windows.h>
+#include <mftransform.h>
+#include <QtCore/private/qfunctions_win_p.h>
+
+struct IMFSample;
+struct IMFTransform;
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsMediaFoundation;
+
+class Q_MULTIMEDIA_EXPORT QWindowsResampler
+{
+public:
+ QWindowsResampler();
+ ~QWindowsResampler();
+
+ bool setup(const QAudioFormat &in, const QAudioFormat &out);
+
+ QByteArray resample(const QByteArrayView &in);
+ QByteArray resample(IMFSample *sample);
+
+ QAudioFormat inputFormat() const { return m_inputFormat; }
+ QAudioFormat outputFormat() const { return m_outputFormat; }
+
+ quint64 outputBufferSize(quint64 inputBufferSize) const;
+ quint64 inputBufferSize(quint64 outputBufferSize) const;
+
+ quint64 totalInputBytes() const { return m_totalInputBytes; }
+ quint64 totalOutputBytes() const { return m_totalOutputBytes; }
+
+private:
+ HRESULT processInput(const QByteArrayView &in);
+ HRESULT processOutput(QByteArray &out);
+
+ QComHelper m_comRuntime;
+ QWindowsMediaFoundation *m_wmf{ QWindowsMediaFoundation::instance() };
+ QMFRuntimeInit m_wmfRuntime{ m_wmf };
+ ComPtr<IMFTransform> m_resampler;
+
+ bool m_resamplerNeedsSampleBuffer = false;
+ quint64 m_totalInputBytes = 0;
+ quint64 m_totalOutputBytes = 0;
+ QAudioFormat m_inputFormat;
+ QAudioFormat m_outputFormat;
+
+ DWORD m_inputStreamID = 0;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_QWINDOWSRESAMPLER_H
diff --git a/src/multimediaquick/CMakeLists.txt b/src/multimediaquick/CMakeLists.txt
new file mode 100644
index 000000000..eceef4e06
--- /dev/null
+++ b/src/multimediaquick/CMakeLists.txt
@@ -0,0 +1,45 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## MultimediaQuickPrivate Module:
+#####################################################################
+
+set(qml_files
+ "Video.qml"
+)
+
+qt_internal_add_qml_module(MultimediaQuickPrivate
+ URI "QtMultimedia"
+ VERSION "${PROJECT_VERSION}"
+ PAST_MAJOR_VERSIONS 5
+ CLASS_NAME QMultimediaQuickModule
+ PLUGIN_TARGET quickmultimedia
+ NO_GENERATE_PLUGIN_SOURCE
+ NO_PLUGIN_OPTIONAL
+ DEPENDENCIES QtQuick
+ CONFIG_MODULE_NAME multimediaquick
+ INTERNAL_MODULE
+ SOURCES
+ qquickimagecapture.cpp qquickimagecapture_p.h
+ qquickimagepreviewprovider.cpp qquickimagepreviewprovider_p.h
+# qquickplaylist.cpp qquickplaylist_p.h
+ qquickmediaplayer.cpp qquickmediaplayer_p.h
+ qquickscreencapture.cpp qquickscreencapture_p.h
+ qquicksoundeffect.cpp qquicksoundeffect_p.h
+ qquickvideooutput.cpp qquickvideooutput_p.h
+ qsgvideonode_p.cpp qsgvideonode_p.h
+ qsgvideotexture.cpp qsgvideotexture_p.h
+ qtmultimediaquickglobal_p.h
+ qtmultimediaquicktypes.cpp qtmultimediaquicktypes_p.h
+ QML_FILES
+ ${qml_files}
+ PUBLIC_LIBRARIES
+ Qt::Core
+ Qt::MultimediaPrivate
+ Qt::Quick
+ Qt::QuickPrivate
+ GENERATE_CPP_EXPORTS
+)
+
+target_sources(quickmultimedia PRIVATE multimedia_plugin.cpp)
diff --git a/src/multimediaquick/Video.qml b/src/multimediaquick/Video.qml
new file mode 100644
index 000000000..80d28c805
--- /dev/null
+++ b/src/multimediaquick/Video.qml
@@ -0,0 +1,371 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+import QtQuick
+import QtMultimedia
+
+/*!
+ \qmltype Video
+ \inherits Item
+ \ingroup multimedia_qml
+ \ingroup multimedia_video_qml
+ \inqmlmodule QtMultimedia
+ \brief A convenience type for showing a specified video.
+
+ \c Video is a convenience type combining the functionality
+ of a \l MediaPlayer and a \l VideoOutput into one. It provides
+ simple video playback functionality without having to declare multiple
+ types.
+
+ The following is sample code to implement video playback in a scene.
+
+ \qml
+ Video {
+ id: video
+ width : 800
+ height : 600
+ source: "video.avi"
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ video.play()
+ }
+ }
+
+ focus: true
+ Keys.onSpacePressed: video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
+ Keys.onLeftPressed: video.position = video.position - 5000
+ Keys.onRightPressed: video.position = video.position + 5000
+ }
+ \endqml
+
+ The source file, \c video.avi, plays when you click the parent
+ of MouseArea. The video plays in an area of 800 by 600 pixels, and its \c id
+ property has the value \b{video}.
+
+ Notice that because signals for the \l Keys have been defined pressing the:
+ \list
+ \li \uicontrol Spacebar toggles the pause button.
+ \li \uicontrol{Left Arrow} moves the current position in the video to 5 seconds
+ previously.
+ \li \uicontrol{Right Arrow} advances the current position in the video by 5 seconds.
+ \endlist
+
+ Video supports un-transformed, stretched, and uniformly scaled
+ video presentation. For a description of stretched uniformly scaled
+ presentation, see the \l fillMode property description.
+
+ \sa MediaPlayer, VideoOutput
+
+\omit
+ \section1 Screen Saver
+
+ If it is likely that an application will be playing video for an extended
+ period of time without user interaction, it may be necessary to disable
+ the platform's screen saver. The \l ScreenSaver (from \l QtSystemInfo)
+ may be used to disable the screensaver in this fashion:
+
+ \qml
+ import QtSystemInfo 5.0
+
+ ScreenSaver { screenSaverEnabled: false }
+ \endqml
+\endomit
+*/
+
+// TODO: Restore Qt System Info docs when the module is released
+
+Item {
+ id: video
+ implicitWidth: videoOut.implicitWidth
+ implicitHeight: videoOut.implicitHeight
+
+ /*** Properties of VideoOutput ***/
+ /*!
+ \qmlproperty enumeration Video::fillMode
+
+ Set this property to define how the video is scaled to fit the target
+ area.
+
+ \list
+ \li VideoOutput.Stretch - the video is scaled to fit
+ \li VideoOutput.PreserveAspectFit - the video is scaled uniformly to fit without
+ cropping
+ \li VideoOutput.PreserveAspectCrop - the video is scaled uniformly to fill, cropping
+ if necessary
+ \endlist
+
+ Because this type is for convenience in QML, it does not
+ support enumerations directly, so enumerations from \c VideoOutput are
+ used to access the available fill modes.
+
+ The default fill mode is preserveAspectFit.
+ */
+ property alias fillMode: videoOut.fillMode
+
+ /*!
+ \qmlproperty int Video::orientation
+
+ The orientation of the \c Video in degrees. Only multiples of 90
+ degrees is supported, that is 0, 90, 180, 270, 360, etc.
+ */
+ property alias orientation: videoOut.orientation
+
+
+ /*** Properties of MediaPlayer ***/
+
+ /*!
+ \qmlproperty enumeration Video::playbackState
+
+ This read only property indicates the playback state of the media.
+
+ \list
+ \li MediaPlayer.PlayingState - the media is playing
+ \li MediaPlayer.PausedState - the media is paused
+ \li MediaPlayer.StoppedState - the media is stopped
+ \endlist
+
+ The default state is MediaPlayer.StoppedState.
+ */
+ property alias playbackState: player.playbackState
+
+ /*!
+ \qmlproperty real Video::bufferProgress
+
+ This property holds how much of the data buffer is currently filled,
+ from 0.0 (empty) to 1.0
+ (full).
+ */
+ property alias bufferProgress: player.bufferProgress
+
+ /*!
+ \qmlproperty int Video::duration
+
+ This property holds the duration of the media in milliseconds.
+
+ If the media doesn't have a fixed duration (a live stream for example)
+ this will be 0.
+ */
+ property alias duration: player.duration
+
+ /*!
+ \qmlproperty int Video::loops
+
+ Determines how often the media is played before stopping.
+ Set to MediaPlayer.Infinite to loop the current media file forever.
+
+ The default value is \c 1. Setting this property to \c 0 has no effect.
+ */
+ property alias loops: player.loops
+
+ /*!
+ \qmlproperty enumeration Video::error
+
+ This property holds the error state of the video. It can be one of:
+
+ \list
+ \li MediaPlayer.NoError - there is no current error.
+ \li MediaPlayer.ResourceError - the video cannot be played due to a problem
+ allocating resources.
+ \li MediaPlayer.FormatError - the video format is not supported.
+ \li MediaPlayer.NetworkError - the video cannot be played due to network issues.
+ \li MediaPlayer.AccessDenied - the video cannot be played due to insufficient
+ permissions.
+ \li MediaPlayer.ServiceMissing - the video cannot be played because the media
+ service could not be
+ instantiated.
+ \endlist
+ */
+ property alias error: player.error
+
+ /*!
+ \qmlproperty string Video::errorString
+
+ This property holds a string describing the current error condition in more detail.
+ */
+ property alias errorString: player.errorString
+
+ /*!
+ \qmlproperty bool Video::hasAudio
+
+ This property holds whether the current media has audio content.
+ */
+ property alias hasAudio: player.hasAudio
+
+ /*!
+ \qmlproperty bool Video::hasVideo
+
+ This property holds whether the current media has video content.
+ */
+ property alias hasVideo: player.hasVideo
+
+ /*!
+ \qmlproperty mediaMetaData Video::metaData
+
+ This property holds the meta data for the current media.
+
+ See \l{MediaPlayer::metaData}{MediaPlayer.metaData} for details about each meta data key.
+
+ \sa {mediaMetaData}
+ */
+ property alias metaData: player.metaData
+
+ /*!
+ \qmlproperty bool Video::muted
+
+ This property holds whether the audio output is muted.
+ */
+ property alias muted: audioOutput.muted
+
+ /*!
+ \qmlproperty real Video::playbackRate
+
+ This property holds the rate at which video is played at as a multiple
+ of the normal rate.
+ */
+ property alias playbackRate: player.playbackRate
+
+ /*!
+ \qmlproperty int Video::position
+
+ This property holds the current playback position in milliseconds.
+ */
+ property alias position: player.position
+
+ /*!
+ \qmlproperty bool Video::seekable
+
+ This property holds whether the playback position of the video can be
+ changed.
+
+ If true, calling the \l seek() method or changing the \l position property
+ will cause playback to seek to the new position.
+ */
+ property alias seekable: player.seekable
+
+ /*!
+ \qmlproperty url Video::source
+
+ This property holds the source URL of the media.
+ */
+ property alias source: player.source
+
+ /*!
+ \since 6.7
+ \qmlproperty bool Video::autoPlay
+
+ This property controls whether the media begins to play automatically after it gets loaded.
+ Defaults to \c false.
+ */
+ property alias autoPlay: player.autoPlay
+
+ /*!
+ \qmlproperty real Video::volume
+
+ This property holds the audio volume.
+
+ The volume is scaled linearly from \c 0.0 (silence) to \c 1.0
+ (full volume). Values outside this range will be clamped.
+
+ The default volume is \c 1.0.
+
+ UI volume controls should usually be scaled nonlinearly. For example,
+ using a logarithmic scale will produce linear changes in perceived
+ loudness, which is what a user would normally expect from a volume
+ control. See \l {QtAudio::convertVolume()} for more details.
+ */
+ property alias volume: audioOutput.volume
+
+ /*!
+ \qmlsignal Video::paused()
+
+ This signal is emitted when playback is paused.
+ */
+ signal paused
+
+ /*!
+ \qmlsignal Video::stopped()
+
+ This signal is emitted when playback is stopped.
+ */
+ signal stopped
+
+ /*!
+ \qmlsignal Video::playing()
+
+ This signal is emitted when playback is started or continued.
+ */
+ signal playing
+
+ /*!
+ \qmlsignal Video::errorOccurred(error, errorString)
+
+ This signal is emitted when an \a error has occurred. The \a errorString
+ parameter may contain more detailed information about the error.
+ */
+ signal errorOccurred(int error, string errorString)
+
+ VideoOutput {
+ id: videoOut
+ anchors.fill: video
+ }
+
+ MediaPlayer {
+ id: player
+ onPlaybackStateChanged: function(newState) {
+ if (newState === MediaPlayer.PausedState)
+ video.paused();
+ else if (newState === MediaPlayer.StoppedState)
+ video.stopped();
+ else
+ video.playing();
+ }
+ onErrorOccurred: function(error, errorString) {
+ video.errorOccurred(error, errorString);
+ }
+ videoOutput: videoOut
+ audioOutput: AudioOutput {
+ id: audioOutput
+ }
+ }
+
+ /*!
+ \qmlmethod Video::play()
+
+ Starts playback of the media.
+ */
+ function play() {
+ player.play();
+ }
+
+ /*!
+ \qmlmethod Video::pause()
+
+ Pauses playback of the media.
+ */
+ function pause() {
+ player.pause();
+ }
+
+ /*!
+ \qmlmethod Video::stop()
+
+ Stops playback of the media.
+ */
+ function stop() {
+ player.stop();
+ }
+
+ /*!
+ \qmlmethod Video::seek(offset)
+
+ If the \l seekable property is true, seeks the current
+ playback position to \a offset.
+
+ \sa seekable, position
+ */
+ function seek(offset) {
+ player.position = offset;
+ }
+}
diff --git a/src/multimediaquick/multimedia_plugin.cpp b/src/multimediaquick/multimedia_plugin.cpp
new file mode 100644
index 000000000..9509b4b5f
--- /dev/null
+++ b/src/multimediaquick/multimedia_plugin.cpp
@@ -0,0 +1,42 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtQml/qqmlextensionplugin.h>
+#include <QtQml/qqml.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcomponent.h>
+#include "qsoundeffect.h"
+#include "qmediaplayer.h"
+#include "qmediametadata.h"
+#include "qcamera.h"
+#include "qmediacapturesession.h"
+#include "qmediarecorder.h"
+
+#include <private/qquickimagepreviewprovider_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMultimediaQuickModule : public QQmlEngineExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
+
+public:
+ QMultimediaQuickModule(QObject *parent = nullptr)
+ : QQmlEngineExtensionPlugin(parent)
+ {
+ volatile auto registration = qml_register_types_QtMultimedia;
+ Q_UNUSED(registration);
+ }
+
+ void initializeEngine(QQmlEngine *engine, const char *uri) override
+ {
+ Q_UNUSED(uri);
+ engine->addImageProvider("camera", new QQuickImagePreviewProvider);
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "multimedia_plugin.moc"
+
diff --git a/src/multimediaquick/qquickimagecapture.cpp b/src/multimediaquick/qquickimagecapture.cpp
new file mode 100644
index 000000000..b7e56d18d
--- /dev/null
+++ b/src/multimediaquick/qquickimagecapture.cpp
@@ -0,0 +1,189 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qquickimagecapture_p.h"
+#include "qquickimagepreviewprovider_p.h"
+
+#include <QtCore/qurl.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype ImageCapture
+ \instantiates QQuickImageCapture
+ \brief An interface for capturing camera images.
+ \ingroup multimedia_qml
+ \inqmlmodule QtMultimedia
+ \ingroup camera_qml
+
+ This type allows you to capture still images and be notified when they
+ are available or saved to disk.
+
+ \qml
+ Item {
+ width: 640
+ height: 360
+
+ CaptureSession {
+ imageCapture : ImageCapture {
+ id: imageCapture
+ }
+ camera: Camera {
+ id: camera
+ }
+
+ videoOutput: videoOutput
+ }
+ VideoOutput {
+ id: videoOutput
+ anchors.fill: parent
+
+ MouseArea {
+ anchors.fill: parent;
+ onClicked: imageCapture.capture();
+ }
+ }
+
+ Image {
+ id: photoPreview
+ source: imageCapture.preview // always shows the last captured image
+ }
+ }
+ \endqml
+
+*/
+
+QQuickImageCapture::QQuickImageCapture(QObject *parent)
+ : QImageCapture(parent)
+{
+ connect(this, &QImageCapture::imageCaptured, this, &QQuickImageCapture::_q_imageCaptured);
+}
+
+QQuickImageCapture::~QQuickImageCapture() = default;
+
+/*!
+ \qmlproperty bool QtMultimedia::ImageCapture::readyForCapture
+
+ This property holds a bool value indicating whether the camera
+ is ready to capture photos or not.
+
+ Calling capture() or captureToFile() while \e ready is \c false is not permitted and
+ results in an error.
+*/
+
+/*!
+ \qmlproperty string QtMultimedia::ImageCapture::preview
+
+ This property holds a url to the latest captured image. It can be connected to the
+ source property of an \l Image element to show the last captured image.
+
+ \qml
+ CaptureSession {
+ camera: Camera {}
+ imageCapture: ImageCapture {
+ id: capture
+ }
+ }
+ Image {
+ source: capture.preview
+ }
+ \endqml
+
+ \sa saveToFile
+*/
+
+/*!
+ \qmlmethod QtMultimedia::ImageCapture::capture()
+
+ Start image capture. The \l imageCaptured and \l imageSaved signals will
+ be emitted when the capture is complete.
+
+ The captured image will be available through the preview property that can be
+ used as the source for a QML Image item. The saveToFile() method can then be used
+ save the image.
+
+ Camera saves all the capture parameters like exposure settings or
+ image processing parameters, so changes to camera parameters after
+ capture() is called do not affect previous capture requests.
+
+ capture() returns the capture requestId parameter, used with
+ imageExposed(), imageCaptured(), imageMetadataAvailable() and imageSaved() signals.
+
+ \sa readyForCapture, preview
+*/
+
+/*!
+ \qmlmethod QtMultimedia::ImageCapture::captureToFile(location)
+
+ Does the same as capture() but additionally automatically saves the captured image to the specified
+ \a location.
+
+ \sa capture
+*/
+
+QString QQuickImageCapture::preview() const
+{
+ return m_capturedImagePath;
+}
+
+/*!
+ \qmlmethod QtMultimedia::ImageCapture::saveToFile(location)
+
+ Saves the last captured image to \a location.
+
+ \sa capture, preview
+*/
+void QQuickImageCapture::saveToFile(const QUrl &location) const
+{
+ m_lastImage.save(location.toLocalFile());
+}
+
+void QQuickImageCapture::_q_imageCaptured(int id, const QImage &preview)
+{
+ QString previewId = QStringLiteral("preview_%1").arg(id);
+ QQuickImagePreviewProvider::registerPreview(previewId, preview);
+ m_capturedImagePath = QStringLiteral("image://camera/%2").arg(previewId);
+ m_lastImage = preview;
+ emit previewChanged();
+}
+
+/*!
+ \qmlsignal QtMultimedia::ImageCapture::errorOccurred(id, error, errorString)
+
+ This signal is emitted when an error occurs during capture with requested \a id.
+ \a error is an enumeration of type ImageCapture::Error.
+ A descriptive message is available in \a errorString.
+*/
+
+/*!
+ \qmlsignal QtMultimedia::ImageCapture::imageCaptured(requestId, preview)
+
+ This signal is emitted when an image with requested id \a requestId has been captured
+ but not yet saved to the filesystem. The \a preview
+ parameter is the captured image.
+
+ \sa imageSaved, preview
+*/
+
+/*!
+ \qmlsignal QtMultimedia::ImageCapture::imageSaved(id, fileName)
+
+ This signal is emitted after the image with requested \a id has been written to the filesystem.
+ The \a fileName is a local file path, not a URL.
+
+ \sa imageCaptured
+*/
+
+
+/*!
+ \qmlsignal QtMultimedia::ImageCapture::imageMetadataAvailable(id, metaData)
+
+ This signal is emitted when the image with requested \a id has new \a metaData.
+
+ \sa imageCaptured
+*/
+
+
+QT_END_NAMESPACE
+
+#include "moc_qquickimagecapture_p.cpp"
diff --git a/src/multimediaquick/qquickimagecapture_p.h b/src/multimediaquick/qquickimagecapture_p.h
new file mode 100644
index 000000000..01f21af75
--- /dev/null
+++ b/src/multimediaquick/qquickimagecapture_p.h
@@ -0,0 +1,57 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQUICKIMAGECAPTURE_H
+#define QQUICKIMAGECAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qcamera.h>
+#include <qimagecapture.h>
+#include <qmediametadata.h>
+
+#include <QtQml/qqml.h>
+#include <QtCore/private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QUrl;
+
+class QQuickImageCapture : public QImageCapture
+{
+ Q_OBJECT
+ Q_PROPERTY(QString preview READ preview NOTIFY previewChanged)
+ QML_NAMED_ELEMENT(ImageCapture)
+
+public:
+ QQuickImageCapture(QObject *parent = nullptr);
+ ~QQuickImageCapture();
+
+ QString preview() const;
+
+public Q_SLOTS:
+ void saveToFile(const QUrl &location) const;
+
+Q_SIGNALS:
+ void previewChanged();
+
+private Q_SLOTS:
+ void _q_imageCaptured(int, const QImage&);
+
+private:
+ QImage m_lastImage;
+ QString m_capturedImagePath;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediaquick/qquickimagepreviewprovider.cpp b/src/multimediaquick/qquickimagepreviewprovider.cpp
new file mode 100644
index 000000000..3b40c1c88
--- /dev/null
+++ b/src/multimediaquick/qquickimagepreviewprovider.cpp
@@ -0,0 +1,59 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qquickimagepreviewprovider_p.h"
+#include <QtCore/qmutex.h>
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+struct QQuickImagePreviewProviderPrivate
+{
+ QString id;
+ QImage image;
+ QMutex mutex;
+};
+
+Q_GLOBAL_STATIC(QQuickImagePreviewProviderPrivate, priv)
+
+QQuickImagePreviewProvider::QQuickImagePreviewProvider()
+: QQuickImageProvider(QQuickImageProvider::Image)
+{
+}
+
+QQuickImagePreviewProvider::~QQuickImagePreviewProvider()
+{
+ QQuickImagePreviewProviderPrivate *d = priv();
+ QMutexLocker lock(&d->mutex);
+ d->id.clear();
+ d->image = QImage();
+}
+
+QImage QQuickImagePreviewProvider::requestImage(const QString &id, QSize *size, const QSize& requestedSize)
+{
+ QQuickImagePreviewProviderPrivate *d = priv();
+ QMutexLocker lock(&d->mutex);
+
+ if (d->id != id)
+ return QImage();
+
+ QImage res = d->image;
+ if (!requestedSize.isEmpty())
+ res = res.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+
+ if (size)
+ *size = res.size();
+
+ return res;
+}
+
+void QQuickImagePreviewProvider::registerPreview(const QString &id, const QImage &preview)
+{
+ //only the last preview is kept
+ QQuickImagePreviewProviderPrivate *d = priv();
+ QMutexLocker lock(&d->mutex);
+ d->id = id;
+ d->image = preview;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimediaquick/qquickimagepreviewprovider_p.h b/src/multimediaquick/qquickimagepreviewprovider_p.h
new file mode 100644
index 000000000..3ffd55eff
--- /dev/null
+++ b/src/multimediaquick/qquickimagepreviewprovider_p.h
@@ -0,0 +1,35 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQUICKIMAGEPREVIEWPROVIDER_H
+#define QQUICKIMAGEPREVIEWPROVIDER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaquickglobal_p.h>
+#include <QtQuick/qquickimageprovider.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIAQUICK_EXPORT QQuickImagePreviewProvider : public QQuickImageProvider
+{
+public:
+ QQuickImagePreviewProvider();
+ ~QQuickImagePreviewProvider();
+
+ QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize) override;
+ static void registerPreview(const QString &id, const QImage &preview);
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediaquick/qquickmediaplayer.cpp b/src/multimediaquick/qquickmediaplayer.cpp
new file mode 100644
index 000000000..6b49c827e
--- /dev/null
+++ b/src/multimediaquick/qquickmediaplayer.cpp
@@ -0,0 +1,95 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qquickmediaplayer_p.h"
+#include <QtQml/qqmlcontext.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuickMediaPlayer::QQuickMediaPlayer(QObject *parent) : QMediaPlayer(parent)
+{
+ connect(this, &QMediaPlayer::positionChanged, this, &QQuickMediaPlayer::onPositionChanged);
+ connect(this, &QMediaPlayer::durationChanged, this, &QQuickMediaPlayer::onDurationChanged);
+ connect(this, &QMediaPlayer::mediaStatusChanged, this,
+ &QQuickMediaPlayer::onMediaStatusChanged);
+}
+
+void QQuickMediaPlayer::qmlSetSource(const QUrl &source)
+{
+ if (m_source == source)
+ return;
+ m_source = source;
+ m_wasMediaLoaded = false;
+ const QQmlContext *context = qmlContext(this);
+ setSource(context ? context->resolvedUrl(source) : source);
+ emit qmlSourceChanged(source);
+}
+
+QUrl QQuickMediaPlayer::qmlSource() const
+{
+ return m_source;
+}
+
+void QQuickMediaPlayer::setQmlPosition(int position)
+{
+ setPosition(static_cast<qint64>(position));
+}
+
+int QQuickMediaPlayer::qmlPosition() const
+{
+ return static_cast<int>(position());
+}
+
+int QQuickMediaPlayer::qmlDuration() const
+{
+ return static_cast<int>(duration());
+}
+
+void QQuickMediaPlayer::onPositionChanged(qint64 position)
+{
+ emit qmlPositionChanged(static_cast<int>(position));
+}
+
+void QQuickMediaPlayer::onDurationChanged(qint64 duration)
+{
+ emit qmlDurationChanged(static_cast<int>(duration));
+}
+
+void QQuickMediaPlayer::onMediaStatusChanged(QMediaPlayer::MediaStatus status)
+{
+ if (status != QMediaPlayer::LoadedMedia || std::exchange(m_wasMediaLoaded, true))
+ return;
+
+ // run with QueuedConnection to make the user able to handle the media status change
+ // by themselves, otherwise play() might change the status in the handler.
+ auto tryAutoPlay = [this]() {
+ if (m_autoPlay && mediaStatus() == QMediaPlayer::LoadedMedia)
+ play();
+ };
+
+ if (m_autoPlay)
+ QMetaObject::invokeMethod(this, tryAutoPlay, Qt::QueuedConnection);
+}
+
+/*!
+ \since 6.7
+ \qmlproperty bool QtMultimedia::MediaPlayer::autoPlay
+
+ This property controls whether the media begins to play automatically after it gets loaded.
+ Defaults to \c false.
+*/
+
+bool QQuickMediaPlayer::autoPlay() const
+{
+ return m_autoPlay;
+}
+
+void QQuickMediaPlayer::setAutoPlay(bool autoPlay)
+{
+ if (std::exchange(m_autoPlay, autoPlay) != autoPlay)
+ emit autoPlayChanged(autoPlay);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qquickmediaplayer_p.cpp"
diff --git a/src/multimediaquick/qquickmediaplayer_p.h b/src/multimediaquick/qquickmediaplayer_p.h
new file mode 100644
index 000000000..be2ad6b12
--- /dev/null
+++ b/src/multimediaquick/qquickmediaplayer_p.h
@@ -0,0 +1,75 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQUICKMEDIAPLAYER_H
+#define QQUICKMEDIAPLAYER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QMediaPlayer>
+#include <QtQml/qqml.h>
+#include <qtmultimediaquickexports.h>
+#include <qurl.h>
+#include <private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIAQUICK_EXPORT QQuickMediaPlayer : public QMediaPlayer
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ qmlSource WRITE qmlSetSource NOTIFY qmlSourceChanged FINAL)
+
+ // qml doesn't support qint64, so we have to convert to the supported type.
+ // Int is expected to be enough for actual purposes.
+ Q_PROPERTY(int duration READ qmlDuration NOTIFY qmlDurationChanged FINAL)
+ Q_PROPERTY(int position READ qmlPosition WRITE setQmlPosition NOTIFY qmlPositionChanged FINAL)
+ Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged FINAL)
+
+ QML_NAMED_ELEMENT(MediaPlayer)
+
+public:
+ QQuickMediaPlayer(QObject *parent = nullptr);
+
+ void qmlSetSource(const QUrl &source);
+
+ QUrl qmlSource() const;
+
+ void setQmlPosition(int position);
+
+ int qmlPosition() const;
+
+ int qmlDuration() const;
+
+ bool autoPlay() const;
+
+ void setAutoPlay(bool autoPlay);
+
+private:
+ void onPositionChanged(qint64 position);
+ void onDurationChanged(qint64 position);
+ void onMediaStatusChanged(QMediaPlayer::MediaStatus status);
+
+Q_SIGNALS:
+ void qmlSourceChanged(const QUrl &source);
+ void qmlPositionChanged(int position);
+ void qmlDurationChanged(int duration);
+ void autoPlayChanged(bool autoPlay);
+
+private:
+ QUrl m_source;
+ bool m_autoPlay = false;
+ bool m_wasMediaLoaded = false;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediaquick/qquickplaylist.cpp b/src/multimediaquick/qquickplaylist.cpp
new file mode 100644
index 000000000..986191647
--- /dev/null
+++ b/src/multimediaquick/qquickplaylist.cpp
@@ -0,0 +1,594 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qquickplaylist_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype PlaylistItem
+ \instantiates QQuickPlaylistItem
+ \since 5.6
+
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+ \ingroup multimedia_audio_qml
+ \ingroup multimedia_video_qml
+ \brief Defines an item in a Playlist.
+ \internal
+
+ \sa Playlist
+*/
+
+/*!
+ \qmlproperty url QtMultimedia::PlaylistItem::source
+
+ This property holds the source URL of the item.
+
+ \sa Playlist
+*/
+QQuickPlaylistItem::QQuickPlaylistItem(QObject *parent)
+ : QObject(parent)
+{
+}
+
+QUrl QQuickPlaylistItem::source() const
+{
+ return m_source;
+}
+
+void QQuickPlaylistItem::setSource(const QUrl &source)
+{
+ m_source = source;
+}
+
+/*!
+ \qmltype Playlist
+ \instantiates QQuickPlaylist
+ \since 5.6
+ \brief For specifying a list of media to be played.
+ \internal
+
+ \inqmlmodule QtMultimedia
+ \ingroup multimedia_qml
+ \ingroup multimedia_audio_qml
+ \ingroup multimedia_video_qml
+
+ The Playlist type provides a way to play a list of media with the MediaPlayer, Audio and Video
+ types. It can be used as a data source for view elements (such as ListView) and other elements
+ that interact with model data (such as Repeater). When used as a data model, each playlist
+ item's source URL can be accessed using the \c source role.
+
+ \qml
+ Item {
+ width: 400;
+ height: 300;
+
+ Audio {
+ id: player;
+ playlist: Playlist {
+ id: playlist
+ PlaylistItem { source: "song1.ogg"; }
+ PlaylistItem { source: "song2.ogg"; }
+ PlaylistItem { source: "song3.ogg"; }
+ }
+ }
+
+ ListView {
+ model: playlist;
+ delegate: Text {
+ font.pixelSize: 16;
+ text: source;
+ }
+ }
+
+ MouseArea {
+ anchors.fill: parent;
+ onPressed: {
+ if (player.playbackState != Audio.PlayingState) {
+ player.play();
+ } else {
+ player.pause();
+ }
+ }
+ }
+ }
+ \endqml
+
+ \sa MediaPlayer, Audio, Video
+*/
+
+void QQuickPlaylist::_q_mediaAboutToBeInserted(int start, int end)
+{
+ emit itemAboutToBeInserted(start, end);
+
+ beginInsertRows(QModelIndex(), start, end);
+}
+
+void QQuickPlaylist::_q_mediaInserted(int start, int end)
+{
+ endInsertRows();
+
+ emit itemCountChanged();
+ emit itemInserted(start, end);
+}
+
+void QQuickPlaylist::_q_mediaAboutToBeRemoved(int start, int end)
+{
+ emit itemAboutToBeRemoved(start, end);
+
+ beginRemoveRows(QModelIndex(), start, end);
+}
+
+void QQuickPlaylist::_q_mediaRemoved(int start, int end)
+{
+ endRemoveRows();
+
+ emit itemCountChanged();
+ emit itemRemoved(start, end);
+}
+
+void QQuickPlaylist::_q_mediaChanged(int start, int end)
+{
+ emit dataChanged(createIndex(start, 0), createIndex(end, 0));
+ emit itemChanged(start, end);
+}
+
+void QQuickPlaylist::_q_loadFailed()
+{
+ m_error = m_playlist->error();
+ m_errorString = m_playlist->errorString();
+
+ emit error(Error(m_error), m_errorString);
+ emit errorChanged();
+ emit loadFailed();
+}
+
+QQuickPlaylist::QQuickPlaylist(QObject *parent)
+ : QAbstractListModel(parent)
+ , m_playlist(nullptr)
+ , m_error(QMediaPlaylist::NoError)
+{
+}
+
+QQuickPlaylist::~QQuickPlaylist()
+{
+ delete m_playlist;
+}
+
+/*!
+ \qmlproperty enumeration QtMultimedia::Playlist::playbackMode
+
+ This property holds the order in which items in the playlist are played.
+
+ \table
+ \header \li Value \li Description
+ \row \li CurrentItemOnce
+ \li The current item is played only once.
+ \row \li CurrentItemInLoop
+ \li The current item is played repeatedly in a loop.
+ \row \li Sequential
+ \li Playback starts from the current and moves through each successive item until the last
+ is reached and then stops. The next item is a null item when the last one is currently
+ playing.
+ \row \li Loop
+ \li Playback restarts at the first item after the last has finished playing.
+ \row \li Random
+ \li Play items in random order.
+ \endtable
+ */
+QQuickPlaylist::PlaybackMode QQuickPlaylist::playbackMode() const
+{
+ return PlaybackMode(m_playlist->playbackMode());
+}
+
+void QQuickPlaylist::setPlaybackMode(PlaybackMode mode)
+{
+ if (playbackMode() == mode)
+ return;
+
+ m_playlist->setPlaybackMode(QMediaPlaylist::PlaybackMode(mode));
+}
+
+/*!
+ \qmlproperty url QtMultimedia::Playlist::currentItemsource
+
+ This property holds the source URL of the current item in the playlist.
+ */
+QUrl QQuickPlaylist::currentItemSource() const
+{
+ return m_playlist->currentMedia();
+}
+
+/*!
+ \qmlproperty int QtMultimedia::Playlist::currentIndex
+
+ This property holds the position of the current item in the playlist.
+ */
+int QQuickPlaylist::currentIndex() const
+{
+ return m_playlist->currentIndex();
+}
+
+void QQuickPlaylist::setCurrentIndex(int index)
+{
+ if (currentIndex() == index)
+ return;
+
+ m_playlist->setCurrentIndex(index);
+}
+
+/*!
+ \qmlproperty int QtMultimedia::Playlist::itemCount
+
+ This property holds the number of items in the playlist.
+ */
+int QQuickPlaylist::itemCount() const
+{
+ return m_playlist->mediaCount();
+}
+
+/*!
+ \qmlproperty enumeration QtMultimedia::Playlist::error
+
+ This property holds the error condition of the playlist.
+
+ \table
+ \header \li Value \li Description
+ \row \li NoError
+ \li No errors
+ \row \li FormatError
+ \li Format error.
+ \row \li FormatNotSupportedError
+ \li Format not supported.
+ \row \li NetworkError
+ \li Network error.
+ \row \li AccessDeniedError
+ \li Access denied error.
+ \endtable
+ */
+QQuickPlaylist::Error QQuickPlaylist::error() const
+{
+ return Error(m_error);
+}
+
+/*!
+ \qmlproperty string QtMultimedia::Playlist::errorString
+
+ This property holds a string describing the current error condition of the playlist.
+*/
+QString QQuickPlaylist::errorString() const
+{
+ return m_errorString;
+}
+
+/*!
+ \qmlmethod url QtMultimedia::Playlist::itemSource(index)
+
+ Returns the source URL of the item at the given \a index in the playlist.
+*/
+QUrl QQuickPlaylist::itemSource(int index)
+{
+ return m_playlist->media(index);
+}
+
+/*!
+ \qmlmethod int QtMultimedia::Playlist::nextIndex(steps)
+
+ Returns the index of the item in the playlist which would be current after calling next()
+ \a steps times.
+
+ Returned value depends on the size of the playlist, the current position and the playback mode.
+
+ \sa playbackMode, previousIndex()
+*/
+int QQuickPlaylist::nextIndex(int steps)
+{
+ return m_playlist->nextIndex(steps);
+}
+
+/*!
+ \qmlmethod int QtMultimedia::Playlist::previousIndex(steps)
+
+ Returns the index of the item in the playlist which would be current after calling previous()
+ \a steps times.
+
+ Returned value depends on the size of the playlist, the current position and the playback mode.
+
+ \sa playbackMode, nextIndex()
+*/
+int QQuickPlaylist::previousIndex(int steps)
+{
+ return m_playlist->previousIndex(steps);
+}
+
+/*!
+ \qmlmethod QtMultimedia::Playlist::next()
+
+ Advances to the next item in the playlist.
+*/
+void QQuickPlaylist::next()
+{
+ m_playlist->next();
+}
+
+/*!
+ \qmlmethod QtMultimedia::Playlist::previous()
+
+ Returns to the previous item in the playlist.
+*/
+void QQuickPlaylist::previous()
+{
+ m_playlist->previous();
+}
+
+/*!
+ \qmlmethod QtMultimedia::Playlist::shuffle()
+
+ Shuffles items in the playlist.
+*/
+void QQuickPlaylist::shuffle()
+{
+ m_playlist->shuffle();
+}
+
+/*!
+ \qmlmethod QtMultimedia::Playlist::load(location, format)
+
+ Loads a playlist from the given \a location. If \a format is specified, it is used, otherwise
+ the format is guessed from the location name and the data.
+
+ New items are appended to the playlist.
+
+ \c onloaded() is emitted if the playlist loads successfully, otherwise \c onLoadFailed() is
+ emitted with \l error and \l errorString defined accordingly.
+*/
+void QQuickPlaylist::load(const QUrl &location, const QString &format)
+{
+ m_error = QMediaPlaylist::NoError;
+ m_errorString = QString();
+ emit errorChanged();
+ m_playlist->load(location, format.toLatin1().constData());
+}
+
+/*!
+ \qmlmethod bool QtMultimedia::Playlist::save(location, format)
+
+ Saves the playlist to the given \a location. If \a format is specified, it is used, otherwise
+ the format is guessed from the location name.
+
+ Returns true if the playlist is saved successfully.
+*/
+bool QQuickPlaylist::save(const QUrl &location, const QString &format)
+{
+ return m_playlist->save(location, format.toLatin1().constData());
+}
+
+/*!
+ \qmlmethod bool QtMultimedia::Playlist::addItem(source)
+
+ Appends the \a source URL to the playlist.
+
+ Returns true if the \a source is added successfully.
+*/
+void QQuickPlaylist::addItem(const QUrl &source)
+{
+ m_playlist->addMedia(QUrl(source));
+}
+
+/*!
+ \qmlmethod bool QtMultimedia::Playlist::addItems(sources)
+
+ Appends the list of URLs in \a sources to the playlist.
+
+ Returns true if the \a sources are added successfully.
+
+ \since 5.7
+*/
+void QQuickPlaylist::addItems(const QList<QUrl> &sources)
+{
+ if (sources.isEmpty())
+ return;
+
+ QList<QUrl> contents;
+ QList<QUrl>::const_iterator it = sources.constBegin();
+ while (it != sources.constEnd()) {
+ contents.push_back(QUrl(*it));
+ ++it;
+ }
+ m_playlist->addMedia(contents);
+}
+
+/*!
+ \qmlmethod bool QtMultimedia::Playlist::insertItem(index, source)
+
+ Inserts the \a source URL to the playlist at the given \a index.
+
+ Returns true if the \a source is added successfully.
+*/
+bool QQuickPlaylist::insertItem(int index, const QUrl &source)
+{
+ return m_playlist->insertMedia(index, QUrl(source));
+}
+
+/*!
+ \qmlmethod bool QtMultimedia::Playlist::insertItems(index, sources)
+
+ Inserts the list of URLs in \a sources to the playlist at the given \a index.
+
+ Returns true if the \a sources are added successfully.
+
+ \since 5.7
+*/
+bool QQuickPlaylist::insertItems(int index, const QList<QUrl> &sources)
+{
+ if (sources.empty())
+ return false;
+
+ QList<QUrl> contents;
+ QList<QUrl>::const_iterator it = sources.constBegin();
+ while (it != sources.constEnd()) {
+ contents.push_back(QUrl(*it));
+ ++it;
+ }
+ return m_playlist->insertMedia(index, contents);
+}
+
+/*!
+ \qmlmethod bool QtMultimedia::Playlist::moveItem(from, to)
+
+ Moves the item at index position \a from to index position \a to.
+
+ Returns \c true if the item is moved successfully.
+
+ \since 5.7
+*/
+bool QQuickPlaylist::moveItem(int from, int to)
+{
+ return m_playlist->moveMedia(from, to);
+}
+
+/*!
+ \qmlmethod bool QtMultimedia::Playlist::removeItem(index)
+
+ Removes the item at the given \a index from the playlist.
+
+ Returns \c true if the item is removed successfully.
+*/
+bool QQuickPlaylist::removeItem(int index)
+{
+ return m_playlist->removeMedia(index);
+}
+
+/*!
+ \qmlmethod bool QtMultimedia::Playlist::removeItems(int start, int end)
+
+ Removes items in the playlist from \a start to \a end inclusive.
+
+ Returns \c true if the items are removed successfully.
+
+ \since 5.7
+*/
+bool QQuickPlaylist::removeItems(int start, int end)
+{
+ return m_playlist->removeMedia(start, end);
+}
+
+/*!
+ \qmlmethod bool QtMultimedia::Playlist::clear()
+
+ Removes all the items from the playlist.
+
+ Returns \c true if the operation is successful.
+*/
+void QQuickPlaylist::clear()
+{
+ m_playlist->clear();
+}
+
+int QQuickPlaylist::rowCount(const QModelIndex &parent) const
+{
+ if (parent.isValid())
+ return 0;
+
+ return m_playlist->mediaCount();
+}
+
+QVariant QQuickPlaylist::data(const QModelIndex &index, int role) const
+{
+ Q_UNUSED(role);
+
+ if (!index.isValid())
+ return QVariant();
+
+ return m_playlist->media(index.row());
+}
+
+QHash<int, QByteArray> QQuickPlaylist::roleNames() const
+{
+ QHash<int, QByteArray> roleNames;
+ roleNames[SourceRole] = "source";
+ return roleNames;
+}
+
+void QQuickPlaylist::classBegin()
+{
+ m_playlist = new QMediaPlaylist(this);
+
+ connect(m_playlist, SIGNAL(currentIndexChanged(int)),
+ this, SIGNAL(currentIndexChanged()));
+ connect(m_playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)),
+ this, SIGNAL(playbackModeChanged()));
+ connect(m_playlist, SIGNAL(currentMediaChanged(QUrl)),
+ this, SIGNAL(currentItemSourceChanged()));
+ connect(m_playlist, SIGNAL(mediaAboutToBeInserted(int,int)),
+ this, SLOT(_q_mediaAboutToBeInserted(int,int)));
+ connect(m_playlist, SIGNAL(mediaInserted(int,int)),
+ this, SLOT(_q_mediaInserted(int,int)));
+ connect(m_playlist, SIGNAL(mediaAboutToBeRemoved(int,int)),
+ this, SLOT(_q_mediaAboutToBeRemoved(int,int)));
+ connect(m_playlist, SIGNAL(mediaRemoved(int,int)),
+ this, SLOT(_q_mediaRemoved(int,int)));
+ connect(m_playlist, SIGNAL(mediaChanged(int,int)),
+ this, SLOT(_q_mediaChanged(int,int)));
+ connect(m_playlist, SIGNAL(loaded()),
+ this, SIGNAL(loaded()));
+ connect(m_playlist, SIGNAL(loadFailed()),
+ this, SLOT(_q_loadFailed()));
+}
+
+void QQuickPlaylist::componentComplete()
+{
+}
+
+/*!
+ \qmlsignal QtMultimedia::Playlist::itemAboutToBeInserted(start, end)
+
+ This signal is emitted when items are to be inserted into the playlist at \a start and ending at
+ \a end.
+*/
+
+/*!
+ \qmlsignal QtMultimedia::Playlist::itemInserted(start, end)
+
+ This signal is emitted after items have been inserted into the playlist. The new items are those
+ between \a start and \a end inclusive.
+*/
+
+/*!
+ \qmlsignal QtMultimedia::Playlist::itemAboutToBeRemoved(start, end)
+
+ This signal emitted when items are to be deleted from the playlist at \a start and ending at
+ \a end.
+*/
+
+/*!
+ \qmlsignal QtMultimedia::Playlist::itemRemoved(start, end)
+
+ This signal is emitted after items have been removed from the playlist. The removed items are
+ those between \a start and \a end inclusive.
+*/
+
+/*!
+ \qmlsignal QtMultimedia::Playlist::itemChanged(start, end)
+
+ This signal is emitted after items have been changed in the playlist between \a start and
+ \a end positions inclusive.
+*/
+
+/*!
+ \qmlsignal QtMultimedia::Playlist::loaded()
+
+ This signal is emitted when the playlist loading succeeded.
+*/
+
+/*!
+ \qmlsignal QtMultimedia::Playlist::loadFailed()
+
+ This signal is emitted when the playlist loading failed. \l error and \l errorString can be
+ checked for more information on the failure.
+*/
+
+QT_END_NAMESPACE
+
+#include "moc_qquickplaylist_p.cpp"
diff --git a/src/multimediaquick/qquickplaylist_p.h b/src/multimediaquick/qquickplaylist_p.h
new file mode 100644
index 000000000..4003cefe7
--- /dev/null
+++ b/src/multimediaquick/qquickplaylist_p.h
@@ -0,0 +1,171 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQUICKPLAYLIST_P_H
+#define QQUICKPLAYLIST_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/QAbstractListModel>
+#include <QtQml/qqmlparserstatus.h>
+#include <QtQml/qqml.h>
+
+#include <qmediaplaylist.h>
+#include <private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickPlaylistItem : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ source WRITE setSource)
+ QML_NAMED_ELEMENT(PlaylistItem)
+
+public:
+ QQuickPlaylistItem(QObject *parent = 0);
+
+ QUrl source() const;
+ void setSource(const QUrl &source);
+
+private:
+ QUrl m_source;
+};
+
+class QQuickPlaylist : public QAbstractListModel, public QQmlParserStatus
+{
+ Q_OBJECT
+ Q_PROPERTY(PlaybackMode playbackMode READ playbackMode WRITE setPlaybackMode NOTIFY playbackModeChanged)
+ Q_PROPERTY(QUrl currentItemSource READ currentItemSource NOTIFY currentItemSourceChanged)
+ Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
+ Q_PROPERTY(int itemCount READ itemCount NOTIFY itemCountChanged)
+ Q_PROPERTY(Error error READ error NOTIFY errorChanged)
+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
+ Q_PROPERTY(QQmlListProperty<QQuickPlaylistItem> items READ items DESIGNABLE false)
+ Q_INTERFACES(QQmlParserStatus)
+ Q_CLASSINFO("DefaultProperty", "items")
+ QML_NAMED_ELEMENT(Playlist)
+
+public:
+ enum PlaybackMode
+ {
+ CurrentItemOnce = QMediaPlaylist::CurrentItemOnce,
+ CurrentItemInLoop = QMediaPlaylist::CurrentItemInLoop,
+ Sequential = QMediaPlaylist::Sequential,
+ Loop = QMediaPlaylist::Loop,
+// Random = QMediaPlaylist::Random
+ };
+ Q_ENUM(PlaybackMode)
+
+ enum Error
+ {
+ NoError = QMediaPlaylist::NoError,
+ FormatError = QMediaPlaylist::FormatError,
+ FormatNotSupportedError = QMediaPlaylist::FormatNotSupportedError,
+ NetworkError = QMediaPlaylist::NetworkError,
+ AccessDeniedError = QMediaPlaylist::AccessDeniedError
+ };
+ Q_ENUM(Error)
+
+ enum Roles
+ {
+ SourceRole = Qt::UserRole + 1
+ };
+
+ QQuickPlaylist(QObject *parent = 0);
+ ~QQuickPlaylist();
+
+ PlaybackMode playbackMode() const;
+ void setPlaybackMode(PlaybackMode playbackMode);
+ QUrl currentItemSource() const;
+ int currentIndex() const;
+ void setCurrentIndex(int currentIndex);
+ int itemCount() const;
+ Error error() const;
+ QString errorString() const;
+ QMediaPlaylist *mediaPlaylist() const { return m_playlist; }
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+ QHash<int, QByteArray> roleNames() const override;
+
+ void classBegin() override;
+ void componentComplete() override;
+
+ QQmlListProperty<QQuickPlaylistItem> items() {
+ return QQmlListProperty<QQuickPlaylistItem>(
+ this, 0, item_append, item_count, 0, item_clear);
+ }
+ static void item_append(QQmlListProperty<QQuickPlaylistItem> *list,
+ QQuickPlaylistItem* item) {
+ static_cast<QQuickPlaylist*>(list->object)->addItem(item->source());
+ }
+ static qsizetype item_count(QQmlListProperty<QQuickPlaylistItem> *list) {
+ return static_cast<QQuickPlaylist*>(list->object)->itemCount();
+ }
+ static void item_clear(QQmlListProperty<QQuickPlaylistItem> *list) {
+ static_cast<QQuickPlaylist*>(list->object)->clear();
+ }
+
+public Q_SLOTS:
+ QUrl itemSource(int index);
+ int nextIndex(int steps = 1);
+ int previousIndex(int steps = 1);
+ void next();
+ void previous();
+ void shuffle();
+ void load(const QUrl &location, const QString &format = QString());
+ bool save(const QUrl &location, const QString &format = QString());
+ void addItem(const QUrl &source);
+ Q_REVISION(1) void addItems(const QList<QUrl> &sources);
+ bool insertItem(int index, const QUrl &source);
+ Q_REVISION(1) bool insertItems(int index, const QList<QUrl> &sources);
+ Q_REVISION(1) bool moveItem(int from, int to);
+ bool removeItem(int index);
+ Q_REVISION(1) bool removeItems(int start, int end);
+ void clear();
+
+Q_SIGNALS:
+ void playbackModeChanged();
+ void currentItemSourceChanged();
+ void currentIndexChanged();
+ void itemCountChanged();
+ void errorChanged();
+
+ void itemAboutToBeInserted(int start, int end);
+ void itemInserted(int start, int end);
+ void itemAboutToBeRemoved(int start, int end);
+ void itemRemoved(int start, int end);
+ void itemChanged(int start, int end);
+ void loaded();
+ void loadFailed();
+
+ void error(QQuickPlaylist::Error error, const QString &errorString);
+
+private Q_SLOTS:
+ void _q_mediaAboutToBeInserted(int start, int end);
+ void _q_mediaInserted(int start, int end);
+ void _q_mediaAboutToBeRemoved(int start, int end);
+ void _q_mediaRemoved(int start, int end);
+ void _q_mediaChanged(int start, int end);
+ void _q_loadFailed();
+
+private:
+ Q_DISABLE_COPY(QQuickPlaylist)
+
+ QMediaPlaylist *m_playlist;
+ QString m_errorString;
+ QMediaPlaylist::Error m_error;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediaquick/qquickscreencapture.cpp b/src/multimediaquick/qquickscreencapture.cpp
new file mode 100644
index 000000000..9c2b0ef6f
--- /dev/null
+++ b/src/multimediaquick/qquickscreencapture.cpp
@@ -0,0 +1,27 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qquickscreencapture_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QQuickScreenCatpure::QQuickScreenCatpure(QObject *parent) : QScreenCapture(parent)
+{
+ connect(this, &QScreenCapture::screenChanged, this, [this](QScreen *screen) {
+ emit QQuickScreenCatpure::screenChanged(new QQuickScreenInfo(this, screen));
+ });
+}
+
+void QQuickScreenCatpure::qmlSetScreen(const QQuickScreenInfo *info)
+{
+ setScreen(info ? info->wrappedScreen() : nullptr);
+}
+
+QQuickScreenInfo *QQuickScreenCatpure::qmlScreen()
+{
+ return new QQuickScreenInfo(this, screen());
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qquickscreencapture_p.cpp"
diff --git a/src/multimediaquick/qquickscreencapture_p.h b/src/multimediaquick/qquickscreencapture_p.h
new file mode 100644
index 000000000..2c46493f5
--- /dev/null
+++ b/src/multimediaquick/qquickscreencapture_p.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQUICKSCREENCAPTURE_H
+#define QQUICKSCREENCAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QScreenCapture>
+#include <qtmultimediaquickexports.h>
+#include <private/qglobal_p.h>
+#include <private/qquickscreen_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIAQUICK_EXPORT QQuickScreenCatpure : public QScreenCapture
+{
+ Q_OBJECT
+ Q_PROPERTY(QQuickScreenInfo *screen READ qmlScreen WRITE qmlSetScreen NOTIFY screenChanged)
+ QML_NAMED_ELEMENT(ScreenCapture)
+
+public:
+ QQuickScreenCatpure(QObject *parent = nullptr);
+
+ void qmlSetScreen(const QQuickScreenInfo *info);
+
+ QQuickScreenInfo *qmlScreen();
+
+Q_SIGNALS:
+ void screenChanged(QQuickScreenInfo *);
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediaquick/qquicksoundeffect.cpp b/src/multimediaquick/qquicksoundeffect.cpp
new file mode 100644
index 000000000..89530f07f
--- /dev/null
+++ b/src/multimediaquick/qquicksoundeffect.cpp
@@ -0,0 +1,29 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qquicksoundeffect_p.h"
+#include <QtQml/qqmlcontext.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuickSoundEffect::QQuickSoundEffect(QObject *parent) : QSoundEffect(parent) { }
+
+void QQuickSoundEffect::qmlSetSource(const QUrl &source)
+{
+ if (m_source == source)
+ return;
+
+ m_source = source;
+ const QQmlContext *context = qmlContext(this);
+ setSource(context ? context->resolvedUrl(source) : source);
+ emit sourceChanged(source);
+}
+
+QUrl QQuickSoundEffect::qmlSource() const
+{
+ return m_source;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qquicksoundeffect_p.cpp"
diff --git a/src/multimediaquick/qquicksoundeffect_p.h b/src/multimediaquick/qquicksoundeffect_p.h
new file mode 100644
index 000000000..8a7246420
--- /dev/null
+++ b/src/multimediaquick/qquicksoundeffect_p.h
@@ -0,0 +1,47 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQUICKSOUNDEFFECT_H
+#define QQUICKSOUNDEFFECT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QSoundEffect>
+#include <QtQml/qqml.h>
+#include <qtmultimediaquickexports.h>
+#include <qurl.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIAQUICK_EXPORT QQuickSoundEffect : public QSoundEffect
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ qmlSource WRITE qmlSetSource NOTIFY sourceChanged)
+ QML_NAMED_ELEMENT(SoundEffect)
+
+public:
+ QQuickSoundEffect(QObject *parent = nullptr);
+
+ void qmlSetSource(const QUrl &source);
+
+ QUrl qmlSource() const;
+
+Q_SIGNALS:
+ void sourceChanged(const QUrl &source);
+
+private:
+ QUrl m_source;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediaquick/qquickvideooutput.cpp b/src/multimediaquick/qquickvideooutput.cpp
new file mode 100644
index 000000000..8af974759
--- /dev/null
+++ b/src/multimediaquick/qquickvideooutput.cpp
@@ -0,0 +1,566 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qquickvideooutput_p.h"
+
+#include <private/qvideooutputorientationhandler_p.h>
+#include <QtMultimedia/qmediaplayer.h>
+#include <QtMultimedia/qmediacapturesession.h>
+#include <private/qfactoryloader_p.h>
+#include <QtCore/qloggingcategory.h>
+#include <qvideosink.h>
+#include <QtQuick/QQuickWindow>
+#include <private/qquickwindow_p.h>
+#include <private/qmultimediautils_p.h>
+#include <qsgvideonode_p.h>
+#include <QtCore/qrunnable.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcVideo, "qt.multimedia.video")
+
+namespace {
+
+inline bool qIsDefaultAspect(int o)
+{
+ return (o % 180) == 0;
+}
+
+/*
+ * Return the orientation normalized to 0-359
+ */
+inline int qNormalizedOrientation(int o)
+{
+ // Negative orientations give negative results
+ int o2 = o % 360;
+ if (o2 < 0)
+ o2 += 360;
+ return o2;
+}
+
+}
+
+/*!
+ \qmltype VideoOutput
+ //! \instantiates QQuickVideoOutput
+ \brief Render video or camera viewfinder.
+
+ \ingroup multimedia_qml
+ \ingroup multimedia_video_qml
+ \inqmlmodule QtMultimedia
+
+ \qml
+
+ Rectangle {
+ width: 800
+ height: 600
+ color: "black"
+
+ MediaPlayer {
+ id: player
+ source: "file://video.webm"
+ videoOutput: videoOutput
+ }
+
+ VideoOutput {
+ id: videoOutput
+ anchors.fill: parent
+ }
+ }
+
+ \endqml
+
+ The VideoOutput item supports untransformed, stretched, and uniformly scaled video presentation.
+ For a description of stretched uniformly scaled presentation, see the \l fillMode property
+ description.
+
+ \sa MediaPlayer, Camera
+
+\omit
+ \section1 Screen Saver
+
+ If it is likely that an application will be playing video for an extended
+ period of time without user interaction it may be necessary to disable
+ the platform's screen saver. The \l ScreenSaver (from \l QtSystemInfo)
+ may be used to disable the screensaver in this fashion:
+
+ \qml
+ import QtSystemInfo
+
+ ScreenSaver { screenSaverEnabled: false }
+ \endqml
+\endomit
+*/
+
+// TODO: Restore Qt System Info docs when the module is released
+
+/*!
+ \internal
+ \class QQuickVideoOutput
+ \brief The QQuickVideoOutput class provides a video output item.
+*/
+
+QQuickVideoOutput::QQuickVideoOutput(QQuickItem *parent) :
+ QQuickItem(parent)
+{
+ setFlag(ItemHasContents, true);
+
+ m_sink = new QVideoSink(this);
+ qRegisterMetaType<QVideoFrameFormat>();
+ connect(m_sink, &QVideoSink::videoFrameChanged, this,
+ [this](const QVideoFrame &frame) {
+ setFrame(frame);
+ QMetaObject::invokeMethod(this, &QQuickVideoOutput::_q_newFrame, frame.size());
+ },
+ Qt::DirectConnection);
+
+ initRhiForSink();
+}
+
+QQuickVideoOutput::~QQuickVideoOutput()
+{
+}
+
+/*!
+ \qmlproperty object QtMultimedia::VideoOutput::videoSink
+
+ This property holds the underlaying C++ QVideoSink object that is used
+ to render the video frames to this VideoOutput element.
+
+ Normal usage of VideoOutput from QML should not require using this property.
+*/
+
+QVideoSink *QQuickVideoOutput::videoSink() const
+{
+ return m_sink;
+}
+
+/*!
+ \qmlproperty enumeration QtMultimedia::VideoOutput::fillMode
+
+ Set this property to define how the video is scaled to fit the target area.
+
+ \list
+ \li Stretch - the video is scaled to fit.
+ \li PreserveAspectFit - the video is scaled uniformly to fit without cropping
+ \li PreserveAspectCrop - the video is scaled uniformly to fill, cropping if necessary
+ \endlist
+
+ The default fill mode is PreserveAspectFit.
+*/
+
+QQuickVideoOutput::FillMode QQuickVideoOutput::fillMode() const
+{
+ return FillMode(m_aspectRatioMode);
+}
+
+void QQuickVideoOutput::setFillMode(FillMode mode)
+{
+ if (mode == fillMode())
+ return;
+
+ m_aspectRatioMode = Qt::AspectRatioMode(mode);
+
+ m_geometryDirty = true;
+ update();
+
+ emit fillModeChanged(mode);
+}
+
+void QQuickVideoOutput::_q_newFrame(QSize size)
+{
+ update();
+
+ size = qRotatedFrameSize(size, m_orientation + m_frameOrientation);
+
+ if (m_nativeSize != size) {
+ m_nativeSize = size;
+
+ m_geometryDirty = true;
+
+ setImplicitWidth(size.width());
+ setImplicitHeight(size.height());
+
+ emit sourceRectChanged();
+ }
+}
+
+/* Based on fill mode and our size, figure out the source/dest rects */
+void QQuickVideoOutput::_q_updateGeometry()
+{
+ const QRectF rect(0, 0, width(), height());
+ const QRectF absoluteRect(x(), y(), width(), height());
+
+ if (!m_geometryDirty && m_lastRect == absoluteRect)
+ return;
+
+ QRectF oldContentRect(m_contentRect);
+
+ m_geometryDirty = false;
+ m_lastRect = absoluteRect;
+
+ const auto fill = m_aspectRatioMode;
+ if (m_nativeSize.isEmpty()) {
+ //this is necessary for item to receive the
+ //first paint event and configure video surface.
+ m_contentRect = rect;
+ } else if (fill == Qt::IgnoreAspectRatio) {
+ m_contentRect = rect;
+ } else {
+ QSizeF scaled = m_nativeSize;
+ scaled.scale(rect.size(), fill);
+
+ m_contentRect = QRectF(QPointF(), scaled);
+ m_contentRect.moveCenter(rect.center());
+ }
+
+ updateGeometry();
+
+ if (m_contentRect != oldContentRect)
+ emit contentRectChanged();
+}
+
+/*!
+ \qmlproperty int QtMultimedia::VideoOutput::orientation
+
+ In some cases the source video stream requires a certain
+ orientation to be correct. This includes
+ sources like a camera viewfinder, where the displayed
+ viewfinder should match reality, no matter what rotation
+ the rest of the user interface has.
+
+ This property allows you to apply a rotation (in steps
+ of 90 degrees) to compensate for any user interface
+ rotation, with positive values in the anti-clockwise direction.
+
+ The orientation change will also affect the mapping
+ of coordinates from source to viewport.
+*/
+int QQuickVideoOutput::orientation() const
+{
+ return m_orientation;
+}
+
+void QQuickVideoOutput::setOrientation(int orientation)
+{
+ // Make sure it's a multiple of 90.
+ if (orientation % 90)
+ return;
+
+ // If there's no actual change, return
+ if (m_orientation == orientation)
+ return;
+
+ // If the new orientation is the same effect
+ // as the old one, don't update the video node stuff
+ if ((m_orientation % 360) == (orientation % 360)) {
+ m_orientation = orientation;
+ emit orientationChanged();
+ return;
+ }
+
+ m_geometryDirty = true;
+
+ // Otherwise, a new orientation
+ // See if we need to change aspect ratio orientation too
+ bool oldAspect = qIsDefaultAspect(m_orientation);
+ bool newAspect = qIsDefaultAspect(orientation);
+
+ m_orientation = orientation;
+
+ if (oldAspect != newAspect) {
+ m_nativeSize.transpose();
+
+ setImplicitWidth(m_nativeSize.width());
+ setImplicitHeight(m_nativeSize.height());
+
+ // Source rectangle does not change for orientation
+ }
+
+ update();
+ emit orientationChanged();
+}
+
+/*!
+ \qmlproperty rectangle QtMultimedia::VideoOutput::contentRect
+
+ This property holds the item coordinates of the area that
+ would contain video to render. With certain fill modes,
+ this rectangle will be larger than the visible area of the
+ \c VideoOutput.
+
+ This property is useful when other coordinates are specified
+ in terms of the source dimensions - this applied for relative
+ (normalized) frame coordinates in the range of 0 to 1.0.
+
+ Areas outside this will be transparent.
+*/
+QRectF QQuickVideoOutput::contentRect() const
+{
+ return m_contentRect;
+}
+
+/*!
+ \qmlproperty rectangle QtMultimedia::VideoOutput::sourceRect
+
+ This property holds the area of the source video
+ content that is considered for rendering. The
+ values are in source pixel coordinates, adjusted for
+ the source's pixel aspect ratio.
+
+ Note that typically the top left corner of this rectangle
+ will be \c {0,0} while the width and height will be the
+ width and height of the input content. Only when the video
+ source has a viewport set, these values will differ.
+
+ The orientation setting does not affect this rectangle.
+
+ \sa QVideoFrameFormat::viewport()
+*/
+QRectF QQuickVideoOutput::sourceRect() const
+{
+ // We might have to transpose back
+ QSizeF size = m_nativeSize;
+ if (!size.isValid())
+ return {};
+
+ if (!qIsDefaultAspect(m_orientation + m_frameOrientation))
+ size.transpose();
+
+
+ // Take the viewport into account for the top left position.
+ // m_nativeSize is already adjusted to the viewport, as it originates
+ // from QVideoFrameFormat::viewport(), which includes pixel aspect ratio
+ const QRectF viewport = adjustedViewport();
+ Q_ASSERT(viewport.size() == size);
+ return QRectF(viewport.topLeft(), size);
+}
+
+void QQuickVideoOutput::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ Q_UNUSED(newGeometry);
+ Q_UNUSED(oldGeometry);
+
+ QQuickItem::geometryChange(newGeometry, oldGeometry);
+
+ // Explicitly listen to geometry changes here. This is needed since changing the position does
+ // not trigger a call to updatePaintNode().
+ // We need to react to position changes though, as the window backened's display rect gets
+ // changed in that situation.
+ _q_updateGeometry();
+}
+
+void QQuickVideoOutput::_q_invalidateSceneGraph()
+{
+ invalidateSceneGraph();
+}
+
+void QQuickVideoOutput::_q_sceneGraphInitialized()
+{
+ initRhiForSink();
+}
+
+void QQuickVideoOutput::releaseResources()
+{
+ // Called on the gui thread when the window is closed or changed.
+ invalidateSceneGraph();
+}
+
+void QQuickVideoOutput::invalidateSceneGraph()
+{
+ // Called on the render thread, e.g. when the context is lost.
+ // QMutexLocker lock(&m_frameMutex);
+ initRhiForSink();
+}
+
+void QQuickVideoOutput::initRhiForSink()
+{
+ QRhi *rhi = m_window ? QQuickWindowPrivate::get(m_window)->rhi : nullptr;
+ m_sink->setRhi(rhi);
+}
+
+void QQuickVideoOutput::itemChange(QQuickItem::ItemChange change,
+ const QQuickItem::ItemChangeData &changeData)
+{
+ if (change != QQuickItem::ItemSceneChange)
+ return;
+
+ if (changeData.window == m_window)
+ return;
+ if (m_window)
+ disconnect(m_window);
+ m_window = changeData.window;
+
+ if (m_window) {
+ // We want to receive the signals in the render thread
+ connect(m_window, &QQuickWindow::sceneGraphInitialized, this,
+ &QQuickVideoOutput::_q_sceneGraphInitialized, Qt::DirectConnection);
+ connect(m_window, &QQuickWindow::sceneGraphInvalidated, this,
+ &QQuickVideoOutput::_q_invalidateSceneGraph, Qt::DirectConnection);
+ }
+ initRhiForSink();
+}
+
+QSize QQuickVideoOutput::nativeSize() const
+{
+ return m_videoFormat.viewport().size();
+}
+
+void QQuickVideoOutput::updateGeometry()
+{
+ const QRectF viewport = m_videoFormat.viewport();
+ const QSizeF frameSize = m_videoFormat.frameSize();
+ const QRectF normalizedViewport(viewport.x() / frameSize.width(),
+ viewport.y() / frameSize.height(),
+ viewport.width() / frameSize.width(),
+ viewport.height() / frameSize.height());
+ const QRectF rect(0, 0, width(), height());
+ if (nativeSize().isEmpty()) {
+ m_renderedRect = rect;
+ m_sourceTextureRect = normalizedViewport;
+ } else if (m_aspectRatioMode == Qt::IgnoreAspectRatio) {
+ m_renderedRect = rect;
+ m_sourceTextureRect = normalizedViewport;
+ } else if (m_aspectRatioMode == Qt::KeepAspectRatio) {
+ m_sourceTextureRect = normalizedViewport;
+ m_renderedRect = contentRect();
+ } else if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
+ m_renderedRect = rect;
+ const qreal contentHeight = contentRect().height();
+ const qreal contentWidth = contentRect().width();
+
+ // Calculate the size of the source rectangle without taking the viewport into account
+ const qreal relativeOffsetLeft = -contentRect().left() / contentWidth;
+ const qreal relativeOffsetTop = -contentRect().top() / contentHeight;
+ const qreal relativeWidth = rect.width() / contentWidth;
+ const qreal relativeHeight = rect.height() / contentHeight;
+
+ // Now take the viewport size into account
+ const qreal totalOffsetLeft = normalizedViewport.x() + relativeOffsetLeft * normalizedViewport.width();
+ const qreal totalOffsetTop = normalizedViewport.y() + relativeOffsetTop * normalizedViewport.height();
+ const qreal totalWidth = normalizedViewport.width() * relativeWidth;
+ const qreal totalHeight = normalizedViewport.height() * relativeHeight;
+
+ if (qIsDefaultAspect(orientation() + m_frameOrientation)) {
+ m_sourceTextureRect = QRectF(totalOffsetLeft, totalOffsetTop,
+ totalWidth, totalHeight);
+ } else {
+ m_sourceTextureRect = QRectF(totalOffsetTop, totalOffsetLeft,
+ totalHeight, totalWidth);
+ }
+ }
+
+ if (m_videoFormat.scanLineDirection() == QVideoFrameFormat::BottomToTop) {
+ qreal top = m_sourceTextureRect.top();
+ m_sourceTextureRect.setTop(m_sourceTextureRect.bottom());
+ m_sourceTextureRect.setBottom(top);
+ }
+
+ if (m_videoFormat.isMirrored()) {
+ qreal left = m_sourceTextureRect.left();
+ m_sourceTextureRect.setLeft(m_sourceTextureRect.right());
+ m_sourceTextureRect.setRight(left);
+ }
+}
+
+QSGNode *QQuickVideoOutput::updatePaintNode(QSGNode *oldNode,
+ QQuickItem::UpdatePaintNodeData *data)
+{
+ Q_UNUSED(data);
+ _q_updateGeometry();
+
+ QSGVideoNode *videoNode = static_cast<QSGVideoNode *>(oldNode);
+
+ QMutexLocker lock(&m_frameMutex);
+
+ if (m_frameChanged) {
+ if (videoNode && videoNode->pixelFormat() != m_frame.pixelFormat()) {
+ qCDebug(qLcVideo) << "updatePaintNode: deleting old video node because frame format changed";
+ delete videoNode;
+ videoNode = nullptr;
+ }
+
+ if (!m_frame.isValid()) {
+ qCDebug(qLcVideo) << "updatePaintNode: no frames yet";
+ m_frameChanged = false;
+ return nullptr;
+ }
+
+ if (!videoNode) {
+ // Get a node that supports our frame. The surface is irrelevant, our
+ // QSGVideoItemSurface supports (logically) anything.
+ updateGeometry();
+ videoNode = new QSGVideoNode(this, m_videoFormat);
+ qCDebug(qLcVideo) << "updatePaintNode: Video node created. Handle type:" << m_frame.handleType();
+ }
+ }
+
+ if (!videoNode) {
+ m_frameChanged = false;
+ m_frame = QVideoFrame();
+ return nullptr;
+ }
+
+ if (m_frameChanged) {
+ videoNode->setCurrentFrame(m_frame);
+
+ updateHdr(videoNode);
+
+ //don't keep the frame for more than really necessary
+ m_frameChanged = false;
+ m_frame = QVideoFrame();
+ }
+
+ // Negative rotations need lots of %360
+ videoNode->setTexturedRectGeometry(m_renderedRect, m_sourceTextureRect,
+ qNormalizedOrientation(orientation()));
+
+ return videoNode;
+}
+
+void QQuickVideoOutput::updateHdr(QSGVideoNode *videoNode)
+{
+ auto *videoOutputWindow = window();
+ if (!videoOutputWindow)
+ return;
+
+ auto *swapChain = videoOutputWindow->swapChain();
+ if (!swapChain)
+ return;
+
+ const auto requiredSwapChainFormat = qGetRequiredSwapChainFormat(m_frame.surfaceFormat());
+ if (qShouldUpdateSwapChainFormat(swapChain, requiredSwapChainFormat)) {
+ auto *recreateSwapChainJob = QRunnable::create([swapChain, requiredSwapChainFormat]() {
+ swapChain->destroy();
+ swapChain->setFormat(requiredSwapChainFormat);
+ swapChain->createOrResize();
+ });
+
+ // Even though the 'recreate swap chain' job is scheduled for the current frame the
+ // effect will be visible only starting from the next frame since the recreation would
+ // happen after the actual swap.
+ videoOutputWindow->scheduleRenderJob(recreateSwapChainJob, QQuickWindow::AfterSwapStage);
+ }
+
+ videoNode->setSurfaceFormat(swapChain->format());
+ videoNode->setHdrInfo(swapChain->hdrInfo());
+}
+
+QRectF QQuickVideoOutput::adjustedViewport() const
+{
+ return m_videoFormat.viewport();
+}
+
+void QQuickVideoOutput::setFrame(const QVideoFrame &frame)
+{
+ QMutexLocker lock(&m_frameMutex);
+
+ m_videoFormat = frame.surfaceFormat();
+ m_frame = frame;
+ m_frameOrientation = static_cast<int>(frame.rotation());
+ m_frameChanged = true;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qquickvideooutput_p.cpp"
diff --git a/src/multimediaquick/qquickvideooutput_p.h b/src/multimediaquick/qquickvideooutput_p.h
new file mode 100644
index 000000000..d71051939
--- /dev/null
+++ b/src/multimediaquick/qquickvideooutput_p.h
@@ -0,0 +1,128 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQUICKVIDEOOUTPUT_P_H
+#define QQUICKVIDEOOUTPUT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qrect.h>
+#include <QtCore/qsharedpointer.h>
+#include <QtQuick/qquickitem.h>
+#include <QtCore/qpointer.h>
+#include <QtCore/qmutex.h>
+
+#include <private/qtmultimediaquickglobal_p.h>
+#include <qvideoframe.h>
+#include <qvideoframeformat.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickVideoBackend;
+class QVideoOutputOrientationHandler;
+class QVideoSink;
+class QSGVideoNode;
+
+class Q_MULTIMEDIAQUICK_EXPORT QQuickVideoOutput : public QQuickItem
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(QQuickVideoOutput)
+ Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
+ Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
+ Q_PROPERTY(QRectF sourceRect READ sourceRect NOTIFY sourceRectChanged)
+ Q_PROPERTY(QRectF contentRect READ contentRect NOTIFY contentRectChanged)
+ Q_PROPERTY(QVideoSink* videoSink READ videoSink CONSTANT)
+ Q_MOC_INCLUDE(qvideosink.h)
+ Q_MOC_INCLUDE(qvideoframe.h)
+ QML_NAMED_ELEMENT(VideoOutput)
+
+public:
+
+ enum FillMode
+ {
+ Stretch = Qt::IgnoreAspectRatio,
+ PreserveAspectFit = Qt::KeepAspectRatio,
+ PreserveAspectCrop = Qt::KeepAspectRatioByExpanding
+ };
+ Q_ENUM(FillMode)
+
+ QQuickVideoOutput(QQuickItem *parent = 0);
+ ~QQuickVideoOutput();
+
+ Q_INVOKABLE QVideoSink *videoSink() const;
+
+ FillMode fillMode() const;
+ void setFillMode(FillMode mode);
+
+ int orientation() const;
+ void setOrientation(int);
+
+ QRectF sourceRect() const;
+ QRectF contentRect() const;
+
+Q_SIGNALS:
+ void sourceChanged();
+ void fillModeChanged(QQuickVideoOutput::FillMode);
+ void orientationChanged();
+ void sourceRectChanged();
+ void contentRectChanged();
+
+protected:
+ QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
+ void itemChange(ItemChange change, const ItemChangeData &changeData) override;
+ void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
+ void releaseResources() override;
+
+private:
+ QSize nativeSize() const;
+ void updateGeometry();
+ QRectF adjustedViewport() const;
+
+ void setFrame(const QVideoFrame &frame);
+
+ void invalidateSceneGraph();
+
+ void initRhiForSink();
+ void updateHdr(QSGVideoNode *videoNode);
+
+private Q_SLOTS:
+ void _q_newFrame(QSize);
+ void _q_updateGeometry();
+ void _q_invalidateSceneGraph();
+ void _q_sceneGraphInitialized();
+
+private:
+ QSize m_nativeSize;
+
+ bool m_geometryDirty = true;
+ QRectF m_lastRect; // Cache of last rect to avoid recalculating geometry
+ QRectF m_contentRect; // Destination pixel coordinates, unclipped
+ int m_orientation = 0;
+ int m_frameOrientation = 0;
+ Qt::AspectRatioMode m_aspectRatioMode = Qt::KeepAspectRatio;
+
+ QPointer<QQuickWindow> m_window;
+ QVideoSink *m_sink = nullptr;
+ QVideoFrameFormat m_videoFormat;
+
+ QList<QVideoFrame> m_videoFrameQueue;
+ QVideoFrame m_frame;
+ bool m_frameChanged = false;
+ QMutex m_frameMutex;
+ QRectF m_renderedRect; // Destination pixel coordinates, clipped
+ QRectF m_sourceTextureRect; // Source texture coordinates
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKVIDEOOUTPUT_P_H
diff --git a/src/multimediaquick/qsgvideonode_p.cpp b/src/multimediaquick/qsgvideonode_p.cpp
new file mode 100644
index 000000000..405744507
--- /dev/null
+++ b/src/multimediaquick/qsgvideonode_p.cpp
@@ -0,0 +1,378 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qsgvideonode_p.h"
+#include "private/qmultimediautils_p.h"
+#include <QtQuick/qsgmaterial.h>
+#include "qsgvideotexture_p.h"
+#include <QtMultimedia/private/qvideotexturehelper_p.h>
+#include <private/qsginternaltextnode_p.h>
+#include <private/qquickitem_p.h>
+#include <private/qquickvideooutput_p.h>
+#include <private/qhwvideobuffer_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/* Helpers */
+static inline void qSetGeom(QSGGeometry::TexturedPoint2D *v, const QPointF &p)
+{
+ v->x = p.x();
+ v->y = p.y();
+}
+
+static inline void qSetTex(QSGGeometry::TexturedPoint2D *v, const QPointF &p)
+{
+ v->tx = p.x();
+ v->ty = p.y();
+}
+
+static inline void qSwapTex(QSGGeometry::TexturedPoint2D *v0, QSGGeometry::TexturedPoint2D *v1)
+{
+ auto tvx = v0->tx;
+ auto tvy = v0->ty;
+ v0->tx = v1->tx;
+ v0->ty = v1->ty;
+ v1->tx = tvx;
+ v1->ty = tvy;
+}
+
+class QSGVideoMaterial;
+
+class QSGVideoMaterialRhiShader : public QSGMaterialShader
+{
+public:
+ QSGVideoMaterialRhiShader(const QVideoFrameFormat &videoFormat,
+ const QRhiSwapChain::Format surfaceFormat,
+ const QRhiSwapChainHdrInfo &hdrInfo)
+ : m_videoFormat(videoFormat)
+ , m_surfaceFormat(surfaceFormat)
+ , m_hdrInfo(hdrInfo)
+ {
+ setShaderFileName(VertexStage, QVideoTextureHelper::vertexShaderFileName(m_videoFormat));
+ setShaderFileName(
+ FragmentStage,
+ QVideoTextureHelper::fragmentShaderFileName(m_videoFormat, m_surfaceFormat));
+ }
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
+ QSGMaterial *oldMaterial) override;
+
+ void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+
+protected:
+ QVideoFrameFormat m_videoFormat;
+ QRhiSwapChain::Format m_surfaceFormat;
+ QRhiSwapChainHdrInfo m_hdrInfo;
+};
+
+class QSGVideoMaterial : public QSGMaterial
+{
+public:
+ QSGVideoMaterial(const QVideoFrameFormat &videoFormat);
+
+ [[nodiscard]] QSGMaterialType *type() const override {
+ static constexpr int NFormats = QRhiSwapChain::HDRExtendedDisplayP3Linear + 1;
+ static QSGMaterialType type[QVideoFrameFormat::NPixelFormats][NFormats];
+ return &type[m_videoFormat.pixelFormat()][m_surfaceFormat];
+ }
+
+ [[nodiscard]] QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override {
+ return new QSGVideoMaterialRhiShader(m_videoFormat, m_surfaceFormat, m_hdrInfo);
+ }
+
+ int compare(const QSGMaterial *other) const override {
+ const QSGVideoMaterial *m = static_cast<const QSGVideoMaterial *>(other);
+
+ qint64 diff = m_textures[0].comparisonKey() - m->m_textures[0].comparisonKey();
+ if (!diff)
+ diff = m_textures[1].comparisonKey() - m->m_textures[1].comparisonKey();
+ if (!diff)
+ diff = m_textures[2].comparisonKey() - m->m_textures[2].comparisonKey();
+
+ return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
+ }
+
+ void updateBlending() {
+ // ### respect video formats with Alpha
+ setFlag(Blending, !qFuzzyCompare(m_opacity, float(1.0)));
+ }
+
+ void setCurrentFrame(const QVideoFrame &frame) {
+ m_currentFrame = frame;
+ m_texturesDirty = true;
+ }
+
+ void setSurfaceFormat(const QRhiSwapChain::Format surfaceFormat)
+ {
+ m_surfaceFormat = surfaceFormat;
+ }
+
+ void setHdrInfo(const QRhiSwapChainHdrInfo &hdrInfo)
+ {
+ m_hdrInfo = hdrInfo;
+ }
+
+ void updateTextures(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates);
+
+ QVideoFrameFormat m_videoFormat;
+ QRhiSwapChain::Format m_surfaceFormat = QRhiSwapChain::SDR;
+ float m_opacity = 1.0f;
+ QRhiSwapChainHdrInfo m_hdrInfo;
+
+ bool m_texturesDirty = false;
+ QVideoFrame m_currentFrame;
+
+ enum { NVideoFrameSlots = 4 };
+ QVideoFrame m_videoFrameSlots[NVideoFrameSlots];
+ std::array<QSGVideoTexture, 3> m_textures;
+ std::unique_ptr<QVideoFrameTextures> m_videoFrameTextures;
+};
+
+void QSGVideoMaterial::updateTextures(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+{
+ if (!m_texturesDirty)
+ return;
+
+ // keep the video frames alive until we know that they are not needed anymore
+ Q_ASSERT(NVideoFrameSlots >= rhi->resourceLimit(QRhi::FramesInFlight));
+ m_videoFrameSlots[rhi->currentFrameSlot()] = m_currentFrame;
+
+ // update and upload all textures
+ m_videoFrameTextures = QVideoTextureHelper::createTextures(m_currentFrame, rhi, resourceUpdates, std::move(m_videoFrameTextures));
+ if (!m_videoFrameTextures)
+ return;
+
+ for (int plane = 0; plane < 3; ++plane)
+ m_textures[plane].setRhiTexture(m_videoFrameTextures->texture(plane));
+ m_texturesDirty = false;
+}
+
+
+bool QSGVideoMaterialRhiShader::updateUniformData(RenderState &state, QSGMaterial *newMaterial,
+ QSGMaterial *oldMaterial)
+{
+ Q_UNUSED(oldMaterial);
+
+ auto m = static_cast<QSGVideoMaterial *>(newMaterial);
+
+ if (!state.isMatrixDirty() && !state.isOpacityDirty())
+ return false;
+
+ if (state.isOpacityDirty()) {
+ m->m_opacity = state.opacity();
+ m->updateBlending();
+ }
+
+ // Do this here, not in updateSampledImage. First, with multiple textures we want to
+ // do this once. More importantly, on some platforms (Android) the externalMatrix is
+ // updated by this function and we need that already in updateUniformData.
+ m->updateTextures(state.rhi(), state.resourceUpdateBatch());
+
+ float maxNits = 100; // Default to de-facto SDR nits
+ if (m_surfaceFormat == QRhiSwapChain::HDRExtendedSrgbLinear) {
+ if (m_hdrInfo.limitsType == QRhiSwapChainHdrInfo::ColorComponentValue)
+ maxNits = 100 * m_hdrInfo.limits.colorComponentValue.maxColorComponentValue;
+ else
+ maxNits = m_hdrInfo.limits.luminanceInNits.maxLuminance;
+ }
+
+ QVideoTextureHelper::updateUniformData(state.uniformData(), m_videoFormat,
+ m->m_currentFrame, state.combinedMatrix(), state.opacity(), maxNits);
+
+ return true;
+}
+
+void QSGVideoMaterialRhiShader::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ Q_UNUSED(state);
+ Q_UNUSED(oldMaterial);
+ if (binding < 1 || binding > 3)
+ return;
+
+ auto m = static_cast<QSGVideoMaterial *>(newMaterial);
+ *texture = &m->m_textures[binding - 1];
+}
+
+QSGVideoMaterial::QSGVideoMaterial(const QVideoFrameFormat &videoFormat)
+ : m_videoFormat(videoFormat)
+{
+ setFlag(Blending, false);
+}
+
+QSGVideoNode::QSGVideoNode(QQuickVideoOutput *parent, const QVideoFrameFormat &videoFormat)
+ : m_parent(parent), m_videoFormat(videoFormat)
+{
+ setFlag(QSGNode::OwnsMaterial);
+ setFlag(QSGNode::OwnsGeometry);
+ m_material = new QSGVideoMaterial(videoFormat);
+ setMaterial(m_material);
+}
+
+QSGVideoNode::~QSGVideoNode()
+{
+ delete m_subtitleTextNode;
+}
+
+void QSGVideoNode::setCurrentFrame(const QVideoFrame &frame)
+{
+ m_material->setCurrentFrame(frame);
+ markDirty(DirtyMaterial);
+ updateSubtitle(frame);
+}
+
+void QSGVideoNode::setSurfaceFormat(const QRhiSwapChain::Format surfaceFormat)
+{
+ m_material->setSurfaceFormat(surfaceFormat);
+ markDirty(DirtyMaterial);
+}
+
+void QSGVideoNode::setHdrInfo(const QRhiSwapChainHdrInfo &hdrInfo)
+{
+ m_material->setHdrInfo(hdrInfo);
+ markDirty(DirtyMaterial);
+}
+
+void QSGVideoNode::updateSubtitle(const QVideoFrame &frame)
+{
+ QSize subtitleFrameSize = m_rect.size().toSize();
+ if (subtitleFrameSize.isEmpty())
+ return;
+
+ subtitleFrameSize = qRotatedFrameSize(subtitleFrameSize, m_orientation);
+
+ if (!m_subtitleLayout.update(subtitleFrameSize, frame.subtitleText()))
+ return;
+
+ delete m_subtitleTextNode;
+ m_subtitleTextNode = nullptr;
+ if (frame.subtitleText().isEmpty())
+ return;
+
+ QQuickItemPrivate *parent_d = QQuickItemPrivate::get(m_parent);
+
+ m_subtitleTextNode = parent_d->sceneGraphContext()->createInternalTextNode(parent_d->sceneGraphRenderContext());
+ m_subtitleTextNode->setColor(Qt::white);
+ QColor bgColor = Qt::black;
+ bgColor.setAlpha(128);
+ m_subtitleTextNode->addRectangleNode(m_subtitleLayout.bounds, bgColor);
+ m_subtitleTextNode->addTextLayout(m_subtitleLayout.layout.position(), &m_subtitleLayout.layout);
+ appendChildNode(m_subtitleTextNode);
+ setSubtitleGeometry();
+}
+
+void QSGVideoNode::setSubtitleGeometry()
+{
+ if (!m_subtitleTextNode)
+ return;
+
+ if (m_material)
+ updateSubtitle(m_material->m_currentFrame);
+
+ float rotate = -1.f * m_orientation;
+ float yTranslate = 0;
+ float xTranslate = 0;
+ if (m_orientation == 90) {
+ yTranslate = m_rect.height();
+ } else if (m_orientation == 180) {
+ yTranslate = m_rect.height();
+ xTranslate = m_rect.width();
+ } else if (m_orientation == 270) {
+ xTranslate = m_rect.width();
+ }
+
+ QMatrix4x4 transform;
+ transform.translate(m_rect.x() + xTranslate, m_rect.y() + yTranslate);
+ transform.rotate(rotate, 0, 0, 1);
+
+ m_subtitleTextNode->setMatrix(transform);
+ m_subtitleTextNode->markDirty(DirtyGeometry);
+}
+
+/* Update the vertices and texture coordinates. Orientation must be in {0,90,180,270} */
+void QSGVideoNode::setTexturedRectGeometry(const QRectF &rect, const QRectF &textureRect, int orientation)
+{
+ const auto currentFrameOrientation = m_material ? static_cast<int>(m_material->m_currentFrame.rotation()) : 0;
+ bool frameChanged = false;
+ if (m_material) {
+ if (currentFrameOrientation != m_frameOrientation
+ || m_material->m_currentFrame.mirrored() != m_frameMirrored) {
+ frameChanged = true;
+ }
+ }
+ if (rect == m_rect && textureRect == m_textureRect && orientation == m_orientation
+ && !frameChanged)
+ return;
+
+ m_rect = rect;
+ m_textureRect = textureRect;
+ m_orientation = orientation;
+ if (m_material) {
+ m_frameOrientation = currentFrameOrientation;
+ m_frameMirrored = m_material->m_currentFrame.mirrored();
+ }
+ const int videoRotation = (orientation + currentFrameOrientation) % 360;
+
+ QSGGeometry *g = geometry();
+
+ if (g == nullptr)
+ g = new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4);
+
+ QSGGeometry::TexturedPoint2D *v = g->vertexDataAsTexturedPoint2D();
+
+ // Set geometry first
+ qSetGeom(v + 0, rect.topLeft());
+ qSetGeom(v + 1, rect.bottomLeft());
+ qSetGeom(v + 2, rect.topRight());
+ qSetGeom(v + 3, rect.bottomRight());
+
+ // and then texture coordinates
+ switch (videoRotation) {
+ default:
+ // tl, bl, tr, br
+ qSetTex(v + 0, textureRect.topLeft());
+ qSetTex(v + 1, textureRect.bottomLeft());
+ qSetTex(v + 2, textureRect.topRight());
+ qSetTex(v + 3, textureRect.bottomRight());
+ break;
+
+ case 90:
+ // bl, br, tl, tr
+ qSetTex(v + 0, textureRect.bottomLeft());
+ qSetTex(v + 1, textureRect.bottomRight());
+ qSetTex(v + 2, textureRect.topLeft());
+ qSetTex(v + 3, textureRect.topRight());
+ break;
+
+ case 180:
+ // br, tr, bl, tl
+ qSetTex(v + 0, textureRect.bottomRight());
+ qSetTex(v + 1, textureRect.topRight());
+ qSetTex(v + 2, textureRect.bottomLeft());
+ qSetTex(v + 3, textureRect.topLeft());
+ break;
+
+ case 270:
+ // tr, tl, br, bl
+ qSetTex(v + 0, textureRect.topRight());
+ qSetTex(v + 1, textureRect.topLeft());
+ qSetTex(v + 2, textureRect.bottomRight());
+ qSetTex(v + 3, textureRect.bottomLeft());
+ break;
+ }
+
+ if (m_material && m_material->m_currentFrame.mirrored()) {
+ qSwapTex(v + 0, v + 2);
+ qSwapTex(v + 1, v + 3);
+ }
+
+ if (!geometry())
+ setGeometry(g);
+
+ markDirty(DirtyGeometry);
+
+ setSubtitleGeometry();
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimediaquick/qsgvideonode_p.h b/src/multimediaquick/qsgvideonode_p.h
new file mode 100644
index 000000000..518fdfed2
--- /dev/null
+++ b/src/multimediaquick/qsgvideonode_p.h
@@ -0,0 +1,65 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QSGVIDEONODE_P_H
+#define QSGVIDEONODE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuick/qsgnode.h>
+#include <private/qtmultimediaquickglobal_p.h>
+#include "private/qvideotexturehelper_p.h"
+
+#include <QtMultimedia/qvideoframe.h>
+#include <QtMultimedia/qvideoframeformat.h>
+#include <QtGui/qopenglfunctions.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGVideoMaterial;
+class QQuickVideoOutput;
+class QSGInternalTextNode;
+
+class QSGVideoNode : public QSGGeometryNode
+{
+public:
+ QSGVideoNode(QQuickVideoOutput *parent, const QVideoFrameFormat &videoFormat);
+ ~QSGVideoNode();
+
+ QVideoFrameFormat::PixelFormat pixelFormat() const { return m_videoFormat.pixelFormat(); }
+ void setCurrentFrame(const QVideoFrame &frame);
+ void setSurfaceFormat(const QRhiSwapChain::Format surfaceFormat);
+ void setHdrInfo(const QRhiSwapChainHdrInfo &hdrInfo);
+
+ void setTexturedRectGeometry(const QRectF &boundingRect, const QRectF &textureRect, int orientation);
+
+private:
+ void updateSubtitle(const QVideoFrame &frame);
+ void setSubtitleGeometry();
+
+ QQuickVideoOutput *m_parent = nullptr;
+ QRectF m_rect;
+ QRectF m_textureRect;
+ int m_orientation = -1;
+ int m_frameOrientation = -1;
+ bool m_frameMirrored = false;
+
+ QVideoFrameFormat m_videoFormat;
+ QSGVideoMaterial *m_material = nullptr;
+
+ QVideoTextureHelper::SubtitleLayout m_subtitleLayout;
+ QSGInternalTextNode *m_subtitleTextNode = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGVIDEONODE_H
diff --git a/src/multimediaquick/qsgvideotexture.cpp b/src/multimediaquick/qsgvideotexture.cpp
new file mode 100644
index 000000000..aa3da9b07
--- /dev/null
+++ b/src/multimediaquick/qsgvideotexture.cpp
@@ -0,0 +1,77 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qsgvideotexture_p.h"
+#include <QtQuick/qsgtexturematerial.h>
+#include <QtQuick/qsgmaterial.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGVideoTexturePrivate
+{
+ Q_DECLARE_PUBLIC(QSGVideoTexture)
+
+private:
+ QSGVideoTexture *q_ptr = nullptr;
+ QRhiTexture::Format m_format;
+ QSize m_size;
+ QByteArray m_data;
+ QRhiTexture *m_texture = nullptr;
+};
+
+QSGVideoTexture::QSGVideoTexture()
+ : d_ptr(new QSGVideoTexturePrivate)
+{
+ d_ptr->q_ptr = this;
+
+ // Nearest filtering just looks bad for any text in videos
+ setFiltering(Linear);
+}
+
+QSGVideoTexture::~QSGVideoTexture() = default;
+
+qint64 QSGVideoTexture::comparisonKey() const
+{
+ Q_D(const QSGVideoTexture);
+ if (d->m_texture)
+ return qint64(qintptr(d->m_texture));
+
+ // two textures (and so materials) with not-yet-created texture underneath are never equal
+ return qint64(qintptr(this));
+}
+
+QRhiTexture *QSGVideoTexture::rhiTexture() const
+{
+ return d_func()->m_texture;
+}
+
+QSize QSGVideoTexture::textureSize() const
+{
+ return d_func()->m_size;
+}
+
+bool QSGVideoTexture::hasAlphaChannel() const
+{
+ Q_D(const QSGVideoTexture);
+ return d->m_format == QRhiTexture::RGBA8 || d->m_format == QRhiTexture::BGRA8;
+}
+
+bool QSGVideoTexture::hasMipmaps() const
+{
+ return mipmapFiltering() != QSGTexture::None;
+}
+
+void QSGVideoTexture::setData(QRhiTexture::Format f, const QSize &s, const uchar *data, int bytes)
+{
+ Q_D(QSGVideoTexture);
+ d->m_size = s;
+ d->m_format = f;
+ d->m_data = {reinterpret_cast<const char *>(data), bytes};
+}
+
+void QSGVideoTexture::setRhiTexture(QRhiTexture *texture)
+{
+ d_func()->m_texture = texture;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimediaquick/qsgvideotexture_p.h b/src/multimediaquick/qsgvideotexture_p.h
new file mode 100644
index 000000000..f9a7377b8
--- /dev/null
+++ b/src/multimediaquick/qsgvideotexture_p.h
@@ -0,0 +1,47 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QSGVIDEOTEXTURE_H
+#define QSGVIDEOTEXTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuick/QSGTexture>
+#include <QImage>
+#include <rhi/qrhi.h>
+#include <private/qtmultimediaquickglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGVideoTexturePrivate;
+class Q_MULTIMEDIAQUICK_EXPORT QSGVideoTexture : public QSGTexture
+{
+ Q_DECLARE_PRIVATE(QSGVideoTexture)
+public:
+ QSGVideoTexture();
+ ~QSGVideoTexture();
+
+ qint64 comparisonKey() const override;
+ QRhiTexture *rhiTexture() const override;
+ QSize textureSize() const override;
+ bool hasAlphaChannel() const override;
+ bool hasMipmaps() const override;
+ void setRhiTexture(QRhiTexture *texture);
+ void setData(QRhiTexture::Format f, const QSize &s, const uchar *data, int bytes);
+
+protected:
+ QScopedPointer<QSGVideoTexturePrivate> d_ptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGVIDEOTEXTURE_H
diff --git a/src/multimediaquick/qtmultimediaquickglobal_p.h b/src/multimediaquick/qtmultimediaquickglobal_p.h
new file mode 100644
index 000000000..44eff1649
--- /dev/null
+++ b/src/multimediaquick/qtmultimediaquickglobal_p.h
@@ -0,0 +1,28 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QMULTIMEDIAQUICKDEFS_P_H
+#define QMULTIMEDIAQUICKDEFS_P_H
+
+#include <QtCore/private/qglobal_p.h>
+#include <QtMultimediaQuick/qtmultimediaquickexports.h>
+
+QT_BEGIN_NAMESPACE
+
+void Q_MULTIMEDIAQUICK_EXPORT qml_register_types_QtMultimedia();
+
+QT_END_NAMESPACE
+
+#endif // QMULTIMEDIAQUICKDEFS_P_H
+
diff --git a/src/multimediaquick/qtmultimediaquicktypes.cpp b/src/multimediaquick/qtmultimediaquicktypes.cpp
new file mode 100644
index 000000000..7ba5711a5
--- /dev/null
+++ b/src/multimediaquick/qtmultimediaquicktypes.cpp
@@ -0,0 +1,12 @@
+// Copyright (C) 2022 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qtmultimediaquicktypes_p.h"
+
+QT_BEGIN_NAMESPACE
+
+// TODO...
+
+QT_END_NAMESPACE
+
+#include "moc_qtmultimediaquicktypes_p.cpp"
diff --git a/src/multimediaquick/qtmultimediaquicktypes_p.h b/src/multimediaquick/qtmultimediaquicktypes_p.h
new file mode 100644
index 000000000..80133c203
--- /dev/null
+++ b/src/multimediaquick/qtmultimediaquicktypes_p.h
@@ -0,0 +1,201 @@
+// Copyright (C) 2022 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QTMULTIMEDIAQUICKTYPES_H
+#define QTMULTIMEDIAQUICKTYPES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQml/qqml.h>
+#include <QtMultimedia/QtMultimedia>
+#include <private/qtmultimediaquickglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+struct QMediaCaptureSessionForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QMediaCaptureSession)
+ QML_NAMED_ELEMENT(CaptureSession) // ### MediaCaptureSession?
+};
+
+struct QCameraForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QCamera)
+ QML_NAMED_ELEMENT(Camera)
+};
+
+struct QImageCaptureForeign
+{
+ Q_GADGET
+ QML_ANONYMOUS
+ QML_FOREIGN(QImageCapture)
+};
+
+struct QScreenCaptureForeign
+{
+ Q_GADGET
+ QML_ANONYMOUS
+ QML_FOREIGN(QScreenCapture)
+};
+
+struct QScreenForeign
+{
+ Q_GADGET
+ QML_ANONYMOUS
+ QML_FOREIGN(QScreen)
+};
+
+struct QMediaRecorderForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QMediaRecorder)
+ QML_NAMED_ELEMENT(MediaRecorder)
+};
+
+struct QMediaMetaDataForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QMediaMetaData)
+ QML_NAMED_ELEMENT(mediaMetaData)
+};
+
+// To prevent the same type from being exported twice into qmltypes
+// (for value type and for the enums)
+struct QMediaMetaDataDerived : public QMediaMetaData
+{
+ Q_GADGET
+};
+
+namespace QMediaMetaDataNamespaceForeign
+{
+ Q_NAMESPACE
+ QML_FOREIGN_NAMESPACE(QMediaMetaDataDerived)
+ QML_NAMED_ELEMENT(MediaMetaData)
+};
+
+struct QMediaDevicesForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QMediaDevices)
+ QML_NAMED_ELEMENT(MediaDevices)
+};
+
+struct QAudioInputForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QAudioInput)
+ QML_NAMED_ELEMENT(AudioInput)
+};
+
+struct QAudioOutputForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QAudioOutput)
+ QML_NAMED_ELEMENT(AudioOutput)
+};
+
+struct QAudioDeviceForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QAudioDevice)
+ QML_NAMED_ELEMENT(audioDevice)
+};
+
+// To prevent the same type from being exported twice into qmltypes
+// (for value type and for the enums)
+struct QAudioDeviceDerived : public QAudioDevice
+{
+ Q_GADGET
+};
+
+namespace QAudioDeviceNamespaceForeign
+{
+ Q_NAMESPACE
+ QML_FOREIGN_NAMESPACE(QAudioDeviceDerived)
+ QML_NAMED_ELEMENT(AudioDevice)
+};
+
+struct QCameraDeviceForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QCameraDevice)
+ QML_NAMED_ELEMENT(cameraDevice)
+};
+
+// To prevent the same type from being exported twice into qmltypes
+// (for value type and for the enums)
+struct QCameraDeviceDerived : public QCameraDevice
+{
+ Q_GADGET
+};
+
+namespace QCameraDeviceNamespaceForeign
+{
+ Q_NAMESPACE
+ QML_FOREIGN_NAMESPACE(QCameraDeviceDerived)
+ QML_NAMED_ELEMENT(CameraDevice)
+};
+
+struct QMediaFormatForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QMediaFormat)
+ QML_NAMED_ELEMENT(mediaFormat)
+};
+
+// To prevent the same type from being exported twice into qmltypes
+// (for value type and for the enums)
+struct QMediaFormatDerived : public QMediaFormat
+{
+ Q_GADGET
+};
+
+namespace QMediaFormatNamespaceForeign
+{
+ Q_NAMESPACE
+ QML_FOREIGN_NAMESPACE(QMediaFormatDerived)
+ QML_NAMED_ELEMENT(MediaFormat)
+};
+
+struct QCameraFormatForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QCameraFormat)
+ QML_NAMED_ELEMENT(cameraFormat)
+};
+
+struct QVideoSinkForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QVideoSink)
+ QML_NAMED_ELEMENT(VideoSink)
+};
+
+struct QCapturableWindowForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QCapturableWindow)
+ QML_NAMED_ELEMENT(capturableWindow)
+};
+
+struct QWindowCaptureForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QWindowCapture)
+ QML_NAMED_ELEMENT(WindowCapture)
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediawidgets/CMakeLists.txt b/src/multimediawidgets/CMakeLists.txt
new file mode 100644
index 000000000..8425d3bac
--- /dev/null
+++ b/src/multimediawidgets/CMakeLists.txt
@@ -0,0 +1,34 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Generated from multimediawidgets.pro.
+
+#####################################################################
+## MultimediaWidgets Module:
+#####################################################################
+
+qt_internal_add_module(MultimediaWidgets
+ SOURCES
+ qtmultimediawidgetsglobal.h
+ qvideowidget.cpp qvideowidget.h qvideowidget_p.h
+ LIBRARIES
+ Qt::MultimediaPrivate
+ Qt::WidgetsPrivate
+ PUBLIC_LIBRARIES
+ Qt::Core
+ Qt::Gui
+ Qt::Multimedia
+ Qt::Widgets
+ PRIVATE_MODULE_INTERFACE
+ Qt::MultimediaPrivate
+ Qt::WidgetsPrivate
+ GENERATE_CPP_EXPORTS
+)
+
+## Scopes:
+#####################################################################
+
+qt_internal_extend_target(MultimediaWidgets CONDITION QT_FEATURE_graphicsview
+ SOURCES
+ qgraphicsvideoitem.cpp qgraphicsvideoitem.h
+)
diff --git a/src/multimediawidgets/doc/snippets/doc_src_qtmultimediawidgets.cpp b/src/multimediawidgets/doc/snippets/doc_src_qtmultimediawidgets.cpp
deleted file mode 100644
index 0598cfab9..000000000
--- a/src/multimediawidgets/doc/snippets/doc_src_qtmultimediawidgets.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [0]
-#include <QtMultimediaWidgets>
-//! [0]
diff --git a/src/multimediawidgets/doc/snippets/doc_src_qtmultimediawidgets.pro b/src/multimediawidgets/doc/snippets/doc_src_qtmultimediawidgets.pro
deleted file mode 100644
index 29c3e9cae..000000000
--- a/src/multimediawidgets/doc/snippets/doc_src_qtmultimediawidgets.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-#! [0]
-QT += multimediawidgets
-#! [0]
diff --git a/src/multimediawidgets/doc/snippets/multimedia-snippets/camera.cpp b/src/multimediawidgets/doc/snippets/multimedia-snippets/camera.cpp
index 2b750b625..a92c51e69 100644
--- a/src/multimediawidgets/doc/snippets/multimedia-snippets/camera.cpp
+++ b/src/multimediawidgets/doc/snippets/multimedia-snippets/camera.cpp
@@ -1,66 +1,37 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
// Camera snippets
// Extracted from src/multimedia/doc/snippets/multimedia-snippets/camera.cpp
#include "qcamera.h"
-#include "qcameraviewfinder.h"
-#include "qcameraimagecapture.h"
+#include "qvideowidget.h"
+#include "qimagecapture.h"
/* Globals so that everything is consistent. */
QCamera *camera = 0;
-QCameraViewfinder *viewfinder = 0;
-QCameraImageCapture *imageCapture = 0;
+QImageCapture *imageCapture = 0;
+QVideoWidget *viewfinder = 0;
void camera_blah()
{
//! [Camera]
+ QMediaCaptureSession captureSession;
camera = new QCamera;
+ captureSession.setCamera(camera);
- viewfinder = new QCameraViewfinder();
+ viewfinder = new QVideoWidget();
viewfinder->show();
+ captureSession.setVideoOutput(viewfinder);
- camera->setViewfinder(viewfinder);
+ imageCapture = new QImageCapture;
+ captureSession.setImageCapture(imageCapture);
- imageCapture = new QCameraImageCapture(camera);
-
- camera->setCaptureMode(QCamera::CaptureStillImage);
camera->start();
//! [Camera]
+
+ //! [Camera keys]
+ //on shutter button pressed
+ imageCapture->capture();
+ //! [Camera keys]
}
+
diff --git a/src/multimediawidgets/doc/snippets/multimedia-snippets/video.cpp b/src/multimediawidgets/doc/snippets/multimedia-snippets/video.cpp
index 917d1e318..609aa121f 100644
--- a/src/multimediawidgets/doc/snippets/multimedia-snippets/video.cpp
+++ b/src/multimediawidgets/doc/snippets/multimedia-snippets/video.cpp
@@ -1,45 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
// Video related snippets
// Extracted from src/multimedia/doc/snippets/multimedia-snippets/video.cpp
-#include "qmediaservice.h"
#include "qmediaplayer.h"
#include "qvideowidgetcontrol.h"
#include "qvideowindowcontrol.h"
@@ -54,11 +17,9 @@ class VideoExample : public QObject {
public:
void VideoGraphicsItem();
void VideoWidget();
- void VideoWidgetControl();
private:
// Common naming
- QMediaService *mediaService;
QMediaPlaylist *playlist;
QVideoWidget *videoWidget;
QFormLayout *layout;
@@ -86,14 +47,6 @@ void VideoExample::VideoWidget()
player->stop();
}
-void VideoExample::VideoWidgetControl()
-{
- //! [Video widget control]
- QVideoWidgetControl *widgetControl = mediaService->requestControl<QVideoWidgetControl *>();
- layout->addWidget(widgetControl->videoWidget());
- //! [Video widget control]
-}
-
void VideoExample::VideoGraphicsItem()
{
//! [Video graphics item]
diff --git a/src/multimediawidgets/doc/src/qtmultimediawidgets-index.qdoc b/src/multimediawidgets/doc/src/qtmultimediawidgets-index.qdoc
index 1dc2776db..18e6d8deb 100644
--- a/src/multimediawidgets/doc/src/qtmultimediawidgets-index.qdoc
+++ b/src/multimediawidgets/doc/src/qtmultimediawidgets-index.qdoc
@@ -1,70 +1,31 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2015 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page qtmultimediawidgets-index.html
\title Qt Multimedia Widgets
-\brief An essential module which provides multimedia-related widgets.
+\brief An add-on module which provides multimedia-related widgets.
Qt Multimedia Widgets provides additional multimedia-related widgets and
-controls. The classes expand the capabilities of the \l{Qt Multimedia} and
+controls. The classes expand the capabilities of the \l{Qt Multimedia} and
\l{Qt Widgets} modules.
\section1 Getting Started
-To enable Qt Multimedia Widgets in a project, add this directive into the
-C++ files:
-\code
-#include <QtMultimediaWidgets>
-\endcode
+To link against the C++ libraries, add the following to your project's
+\c CMakeLists.txt file. Substitute \c my_project with the name of your project.
-To link against the C++ libraries, add the following to your \c qmake project
-file:
\code
-QT += multimediawidgets
+find_package(Qt6 REQUIRED COMPONENTS MultimediaWidgets)
+target_link_libraries(my_project PUBLIC Qt::MultimediaWidgets)
\endcode
-\section1 Licenses and Attributions
-
-The Qt Multimedia Widgets module is available under commercial licenses from \l{The Qt Company}.
-In addition, it is available under free software licenses. Since Qt 5.4,
-these free software licenses are
-\l{GNU Lesser General Public License, version 3}, or
-the \l{GNU General Public License, version 2}.
-See \l{Qt Licensing} for further details.
-
-\section1 Related Information
-
-\section2 Reference
+\section1 References
\list
\li \l{Qt Multimedia Widgets C++ Classes}{C++ Classes}
\endlist
-\section2 Examples
+\section1 Examples
\list
\li \l{Camera Example}
\li \l{Media Player Example}
diff --git a/src/multimediawidgets/doc/src/qtmultimediawidgets.qdoc b/src/multimediawidgets/doc/src/qtmultimediawidgets.qdoc
index d7964c557..c67efcb23 100644
--- a/src/multimediawidgets/doc/src/qtmultimediawidgets.qdoc
+++ b/src/multimediawidgets/doc/src/qtmultimediawidgets.qdoc
@@ -1,45 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\module QtMultimediaWidgets
\title Qt Multimedia Widgets C++ Classes
\brief Classes provided by the Qt Multimedia Widgets module.
\qtvariable multimediawidgets
+\qtcmakepackage MultimediaWidgets
These classes are part of the \l{Qt Multimedia Widgets} module.
-To enable Qt Multimedia Widgets in a project, add this directive into the
-C++ files:
-
-\snippet doc_src_qtmultimediawidgets.cpp 0
-
-To link against the C++ libraries, add the following to your \c qmake project
-file:
-
-\snippet doc_src_qtmultimediawidgets.pro 0
*/
diff --git a/src/multimediawidgets/multimediawidgets.pro b/src/multimediawidgets/multimediawidgets.pro
deleted file mode 100644
index 82237a0be..000000000
--- a/src/multimediawidgets/multimediawidgets.pro
+++ /dev/null
@@ -1,36 +0,0 @@
-# distinct from Qt Multimedia
-TARGET = QtMultimediaWidgets
-QT = core gui multimedia widgets-private
-QT_PRIVATE += multimedia-private
-qtHaveModule(opengl) {
- QT += openglwidgets
- QT_PRIVATE += opengl
-}
-
-PRIVATE_HEADERS += \
- qvideowidget_p.h \
- qpaintervideosurface_p.h \
-
-PUBLIC_HEADERS += \
- qtmultimediawidgetdefs.h \
- qcameraviewfinder.h \
- qvideowidgetcontrol.h \
- qvideowidget.h
-
-SOURCES += \
- qcameraviewfinder.cpp \
- qpaintervideosurface.cpp \
- qvideowidgetcontrol.cpp \
- qvideowidget.cpp
-
-qtConfig(graphicsview) {
- SOURCES += qgraphicsvideoitem.cpp
- PUBLIC_HEADERS += qgraphicsvideoitem.h
-}
-
-
-HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
-
-msvc:lessThan(QMAKE_MSC_VER, 1900): QMAKE_CXXFLAGS += -Zm200
-
-load(qt_module)
diff --git a/src/multimediawidgets/qcameraviewfinder.cpp b/src/multimediawidgets/qcameraviewfinder.cpp
deleted file mode 100644
index b48e892fa..000000000
--- a/src/multimediawidgets/qcameraviewfinder.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qcameraviewfinder.h"
-#include "qvideowidget_p.h"
-
-#include <qcamera.h>
-#include <qvideodeviceselectorcontrol.h>
-#include <private/qmediaobject_p.h>
-
-#include <QtCore/QDebug>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCameraViewfinder
-
-
- \brief The QCameraViewfinder class provides a camera viewfinder widget.
-
- \inmodule QtMultimediaWidgets
- \ingroup camera
-
- \snippet multimedia-snippets/camera.cpp Camera
-
-*/
-
-class QCameraViewfinderPrivate : public QVideoWidgetPrivate
-{
- Q_DECLARE_NON_CONST_PUBLIC(QCameraViewfinder)
-public:
- QCameraViewfinderPrivate():
- QVideoWidgetPrivate()
- {
- }
-};
-
-/*!
- Constructs a new camera viewfinder widget.
-
- The \a parent is passed to QVideoWidget.
-*/
-
-QCameraViewfinder::QCameraViewfinder(QWidget *parent)
- :QVideoWidget(*new QCameraViewfinderPrivate, parent)
-{
-}
-
-/*!
- Destroys a camera viewfinder widget.
-*/
-QCameraViewfinder::~QCameraViewfinder()
-{
-}
-
-/*!
- \reimp
-*/
-QMediaObject *QCameraViewfinder::mediaObject() const
-{
- return QVideoWidget::mediaObject();
-}
-
-/*!
- \reimp
-*/
-bool QCameraViewfinder::setMediaObject(QMediaObject *object)
-{
- return QVideoWidget::setMediaObject(object);
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qcameraviewfinder.cpp"
diff --git a/src/multimediawidgets/qcameraviewfinder.h b/src/multimediawidgets/qcameraviewfinder.h
deleted file mode 100644
index eb0f396cc..000000000
--- a/src/multimediawidgets/qcameraviewfinder.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCAMERAVIEWFINDER_H
-#define QCAMERAVIEWFINDER_H
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qpair.h>
-#include <QtCore/qsize.h>
-#include <QtCore/qpoint.h>
-#include <QtCore/qrect.h>
-
-#include <QtMultimedia/qmediacontrol.h>
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmediaservice.h>
-#include <QtMultimediaWidgets/qvideowidget.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QCamera;
-
-class QCameraViewfinderPrivate;
-class Q_MULTIMEDIAWIDGETS_EXPORT QCameraViewfinder : public QVideoWidget
-{
- Q_OBJECT
-public:
- explicit QCameraViewfinder(QWidget *parent = nullptr);
- ~QCameraViewfinder();
-
- QMediaObject *mediaObject() const override;
-
-protected:
- bool setMediaObject(QMediaObject *object) override;
-
-private:
- Q_DISABLE_COPY(QCameraViewfinder)
- Q_DECLARE_PRIVATE(QCameraViewfinder)
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QCAMERA_H
diff --git a/src/multimediawidgets/qgraphicsvideoitem.cpp b/src/multimediawidgets/qgraphicsvideoitem.cpp
index 7c0521471..c82c2da3c 100644
--- a/src/multimediawidgets/qgraphicsvideoitem.cpp
+++ b/src/multimediawidgets/qgraphicsvideoitem.cpp
@@ -1,190 +1,90 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qgraphicsvideoitem.h"
-#include "qpaintervideosurface_p.h"
+#include "qvideosink.h"
-#include <qmediaobject.h>
-#include <qmediaservice.h>
-#include <qvideorenderercontrol.h>
-#include <qvideosurfaceformat.h>
+#include <qobject.h>
+#include <qvideoframe.h>
+#include <qvideoframeformat.h>
#include <QtCore/qcoreevent.h>
#include <QtCore/qpointer.h>
-#if QT_CONFIG(opengl)
-#include <QOpenGLContext>
-#endif
-
QT_BEGIN_NAMESPACE
class QGraphicsVideoItemPrivate
{
public:
QGraphicsVideoItemPrivate()
- : q_ptr(0)
- , surface(0)
- , mediaObject(0)
- , service(0)
- , rendererControl(0)
- , aspectRatioMode(Qt::KeepAspectRatio)
- , updatePaintDevice(true)
- , rect(0.0, 0.0, 320, 240)
+ : rect(0.0, 0.0, 320, 240)
{
}
- QGraphicsVideoItem *q_ptr;
+ QGraphicsVideoItem *q_ptr = nullptr;
- QPainterVideoSurface *surface;
- QPointer<QMediaObject> mediaObject;
- QMediaService *service;
- QVideoRendererControl *rendererControl;
- Qt::AspectRatioMode aspectRatioMode;
- bool updatePaintDevice;
+ QVideoSink *sink = nullptr;
QRectF rect;
QRectF boundingRect;
- QRectF sourceRect;
QSizeF nativeSize;
+ QVideoFrame m_frame;
+ Qt::AspectRatioMode m_aspectRatioMode = Qt::KeepAspectRatio;
- void clearService();
void updateRects();
- void _q_present();
- void _q_formatChanged(const QVideoSurfaceFormat &format);
- void _q_updateNativeSize();
- void _q_serviceDestroyed();
+ void _q_present(const QVideoFrame &);
};
-void QGraphicsVideoItemPrivate::clearService()
-{
- if (rendererControl) {
- surface->stop();
- rendererControl->setSurface(0);
- service->releaseControl(rendererControl);
- rendererControl = 0;
- }
- if (service) {
- QObject::disconnect(service, SIGNAL(destroyed()), q_ptr, SLOT(_q_serviceDestroyed()));
- service = 0;
- }
-}
-
void QGraphicsVideoItemPrivate::updateRects()
{
q_ptr->prepareGeometryChange();
- if (nativeSize.isEmpty()) {
- //this is necessary for item to receive the
- //first paint event and configure video surface.
- boundingRect = rect;
- } else if (aspectRatioMode == Qt::IgnoreAspectRatio) {
- boundingRect = rect;
- sourceRect = QRectF(0, 0, 1, 1);
- } else if (aspectRatioMode == Qt::KeepAspectRatio) {
+ boundingRect = rect;
+ if (nativeSize.isEmpty())
+ return;
+
+ if (m_aspectRatioMode == Qt::KeepAspectRatio) {
QSizeF size = nativeSize;
size.scale(rect.size(), Qt::KeepAspectRatio);
boundingRect = QRectF(0, 0, size.width(), size.height());
boundingRect.moveCenter(rect.center());
-
- sourceRect = QRectF(0, 0, 1, 1);
- } else if (aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
- boundingRect = rect;
-
- QSizeF size = rect.size();
- size.scale(nativeSize, Qt::KeepAspectRatio);
-
- sourceRect = QRectF(
- 0, 0, size.width() / nativeSize.width(), size.height() / nativeSize.height());
- sourceRect.moveCenter(QPointF(0.5, 0.5));
}
}
-void QGraphicsVideoItemPrivate::_q_present()
+void QGraphicsVideoItemPrivate::_q_present(const QVideoFrame &frame)
{
- if (q_ptr->isObscured()) {
- q_ptr->update(boundingRect);
- surface->setReady(true);
- } else {
- q_ptr->update(boundingRect);
- }
-}
+ m_frame = frame;
+ q_ptr->update(boundingRect);
-void QGraphicsVideoItemPrivate::_q_updateNativeSize()
-{
- const QSize &size = surface->surfaceFormat().sizeHint();
- if (nativeSize != size) {
- nativeSize = size;
+ if (frame.isValid()) {
+ const QSize &size = frame.surfaceFormat().viewport().size();
+ if (nativeSize != size) {
+ nativeSize = size;
- updateRects();
- emit q_ptr->nativeSizeChanged(nativeSize);
+ updateRects();
+ emit q_ptr->nativeSizeChanged(nativeSize);
+ }
}
}
-void QGraphicsVideoItemPrivate::_q_serviceDestroyed()
-{
- rendererControl = 0;
- service = 0;
-
- surface->stop();
-}
-
-
/*!
\class QGraphicsVideoItem
- \brief The QGraphicsVideoItem class provides a graphics item which display video produced by a QMediaObject.
+ \brief The QGraphicsVideoItem class provides a graphics item which display video produced by a QMediaPlayer or QCamera.
\inmodule QtMultimediaWidgets
\ingroup multimedia
- Attaching a QGraphicsVideoItem to a QMediaObject allows it to display
- the video or image output of that media object. A QGraphicsVideoItem
- is attached to a media object by passing a pointer to the QMediaObject
- to the setMediaObject() function.
+ Attaching a QGraphicsVideoItem to a QMediaPlayer or QCamera allows it to display
+ the video or image output of that media object.
\snippet multimedia-snippets/video.cpp Video graphics item
\b {Note}: Only a single display output can be attached to a media
object at one time.
- \sa QMediaObject, QMediaPlayer, QVideoWidget
+ \sa QMediaPlayer, QVideoWidget, QCamera
*/
/*!
@@ -197,13 +97,9 @@ QGraphicsVideoItem::QGraphicsVideoItem(QGraphicsItem *parent)
, d_ptr(new QGraphicsVideoItemPrivate)
{
d_ptr->q_ptr = this;
- d_ptr->surface = new QPainterVideoSurface;
-
- qRegisterMetaType<QVideoSurfaceFormat>();
+ d_ptr->sink = new QVideoSink(this);
- connect(d_ptr->surface, SIGNAL(frameChanged()), this, SLOT(_q_present()));
- connect(d_ptr->surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)),
- this, SLOT(_q_updateNativeSize()), Qt::QueuedConnection);
+ connect(d_ptr->sink, SIGNAL(videoFrameChanged(const QVideoFrame &)), this, SLOT(_q_present(const QVideoFrame &)));
}
/*!
@@ -211,30 +107,13 @@ QGraphicsVideoItem::QGraphicsVideoItem(QGraphicsItem *parent)
*/
QGraphicsVideoItem::~QGraphicsVideoItem()
{
- if (d_ptr->rendererControl) {
- d_ptr->rendererControl->setSurface(0);
- d_ptr->service->releaseControl(d_ptr->rendererControl);
- }
-
- delete d_ptr->surface;
delete d_ptr;
}
/*!
- \property QGraphicsVideoItem::mediaObject
- \brief the media object which provides the video displayed by a graphics
- item.
-*/
-
-QMediaObject *QGraphicsVideoItem::mediaObject() const
-{
- return d_func()->mediaObject;
-}
-
-/*!
- \since 5.15
- \property QGraphicsVideoItem::videoSurface
- \brief Returns the underlying video surface that can render video frames
+ \since 6.0
+ \property QGraphicsVideoItem::videoSink
+ \brief Returns the underlying video sink that can render video frames
to the current item.
This property is never \c nullptr.
Example of how to render video frames to QGraphicsVideoItem:
@@ -242,53 +121,9 @@ QMediaObject *QGraphicsVideoItem::mediaObject() const
\sa QMediaPlayer::setVideoOutput
*/
-QAbstractVideoSurface *QGraphicsVideoItem::videoSurface() const
+QVideoSink *QGraphicsVideoItem::videoSink() const
{
- return d_func()->surface;
-}
-
-/*!
- \internal
-*/
-bool QGraphicsVideoItem::setMediaObject(QMediaObject *object)
-{
- Q_D(QGraphicsVideoItem);
-
- if (object == d->mediaObject)
- return true;
-
- d->clearService();
-
- d->mediaObject = object;
-
- if (d->mediaObject) {
- d->service = d->mediaObject->service();
-
- if (d->service) {
- QMediaControl *control = d->service->requestControl(QVideoRendererControl_iid);
- if (control) {
- d->rendererControl = qobject_cast<QVideoRendererControl *>(control);
-
- if (d->rendererControl) {
- //don't set the surface until the item is painted
- //at least once and the surface is configured
- if (!d->updatePaintDevice)
- d->rendererControl->setSurface(d->surface);
- else
- update(boundingRect());
-
- connect(d->service, SIGNAL(destroyed()), this, SLOT(_q_serviceDestroyed()));
-
- return true;
- }
- if (control)
- d->service->releaseControl(control);
- }
- }
- }
-
- d->mediaObject = 0;
- return false;
+ return d_func()->sink;
}
/*!
@@ -298,14 +133,16 @@ bool QGraphicsVideoItem::setMediaObject(QMediaObject *object)
Qt::AspectRatioMode QGraphicsVideoItem::aspectRatioMode() const
{
- return d_func()->aspectRatioMode;
+ return d_func()->m_aspectRatioMode;
}
void QGraphicsVideoItem::setAspectRatioMode(Qt::AspectRatioMode mode)
{
Q_D(QGraphicsVideoItem);
+ if (d->m_aspectRatioMode == mode)
+ return;
- d->aspectRatioMode = mode;
+ d->m_aspectRatioMode = mode;
d->updateRects();
}
@@ -362,12 +199,6 @@ QSizeF QGraphicsVideoItem::nativeSize() const
}
/*!
- \fn QGraphicsVideoItem::nativeSizeChanged(const QSizeF &size)
-
- Signals that the native \a size of the video has changed.
-*/
-
-/*!
\reimp
*/
QRectF QGraphicsVideoItem::boundingRect() const
@@ -378,42 +209,33 @@ QRectF QGraphicsVideoItem::boundingRect() const
/*!
\reimp
*/
-void QGraphicsVideoItem::paint(
- QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+void QGraphicsVideoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_D(QGraphicsVideoItem);
Q_UNUSED(option);
Q_UNUSED(widget);
- if (d->surface && d->updatePaintDevice) {
- d->updatePaintDevice = false;
-#if QT_CONFIG(opengl)
- if (widget)
- connect(widget, SIGNAL(destroyed()), d->surface, SLOT(viewportDestroyed()));
-
- if (painter->paintEngine()->type() == QPaintEngine::OpenGL
- || painter->paintEngine()->type() == QPaintEngine::OpenGL2)
- {
- d->surface->updateGLContext();
- if (d->surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) {
- d->surface->setShaderType(QPainterVideoSurface::GlslShader);
- } else {
- d->surface->setShaderType(QPainterVideoSurface::FragmentProgramShader);
- }
- }
-#endif
- if (d->rendererControl && d->rendererControl->surface() != d->surface)
- d->rendererControl->setSurface(d->surface);
- }
-
- if (d->surface && d->surface->isActive()) {
- d->surface->paint(painter, d->boundingRect, d->sourceRect);
- d->surface->setReady(true);
- }
+ d->m_frame.paint(painter, d->rect, { Qt::transparent, d->m_aspectRatioMode });
}
/*!
+ \fn int QGraphicsVideoItem::type() const
+ \reimp
+
+ Returns an int representing the type of the video item.
+*/
+/*!
+ \variable QGraphicsVideoItem::d_ptr
+ \internal
+*/
+/*!
+ \enum QGraphicsVideoItem::anonymous
+ \internal
+
+ \omitvalue Type
+*/
+/*!
\reimp
\internal
@@ -434,3 +256,5 @@ void QGraphicsVideoItem::timerEvent(QTimerEvent *event)
QT_END_NAMESPACE
#include "moc_qgraphicsvideoitem.cpp"
+
+
diff --git a/src/multimediawidgets/qgraphicsvideoitem.h b/src/multimediawidgets/qgraphicsvideoitem.h
index 621a9852f..ce9e863a2 100644
--- a/src/multimediawidgets/qgraphicsvideoitem.h
+++ b/src/multimediawidgets/qgraphicsvideoitem.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QGRAPHICSVIDEOITEM_H
#define QGRAPHICSVIDEOITEM_H
@@ -43,30 +7,26 @@
#include <QtWidgets/qgraphicsitem.h>
#include <QtMultimediaWidgets/qvideowidget.h>
-#include <QtMultimedia/qmediabindableinterface.h>
#if QT_CONFIG(graphicsview)
QT_BEGIN_NAMESPACE
-class QVideoSurfaceFormat;
+class QVideoFrameFormat;
class QGraphicsVideoItemPrivate;
-class Q_MULTIMEDIAWIDGETS_EXPORT QGraphicsVideoItem : public QGraphicsObject, public QMediaBindableInterface
+class Q_MULTIMEDIAWIDGETS_EXPORT QGraphicsVideoItem : public QGraphicsObject
{
Q_OBJECT
- Q_INTERFACES(QMediaBindableInterface)
- Q_PROPERTY(QMediaObject* mediaObject READ mediaObject WRITE setMediaObject)
Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode)
Q_PROPERTY(QPointF offset READ offset WRITE setOffset)
Q_PROPERTY(QSizeF size READ size WRITE setSize)
Q_PROPERTY(QSizeF nativeSize READ nativeSize NOTIFY nativeSizeChanged)
- Q_PROPERTY(QAbstractVideoSurface* videoSurface READ videoSurface CONSTANT)
+ Q_PROPERTY(QVideoSink* videoSink READ videoSink CONSTANT)
public:
explicit QGraphicsVideoItem(QGraphicsItem *parent = nullptr);
~QGraphicsVideoItem();
- QMediaObject *mediaObject() const override;
- QAbstractVideoSurface *videoSurface() const;
+ Q_INVOKABLE QVideoSink *videoSink() const;
Qt::AspectRatioMode aspectRatioMode() const;
void setAspectRatioMode(Qt::AspectRatioMode mode);
@@ -97,15 +57,11 @@ protected:
void timerEvent(QTimerEvent *event) override;
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
- bool setMediaObject(QMediaObject *object) override;
-
QGraphicsVideoItemPrivate *d_ptr;
private:
Q_DECLARE_PRIVATE(QGraphicsVideoItem)
- Q_PRIVATE_SLOT(d_func(), void _q_present())
- Q_PRIVATE_SLOT(d_func(), void _q_updateNativeSize())
- Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed())
+ Q_PRIVATE_SLOT(d_func(), void _q_present(const QVideoFrame &))
};
QT_END_NAMESPACE
diff --git a/src/multimediawidgets/qpaintervideosurface.cpp b/src/multimediawidgets/qpaintervideosurface.cpp
deleted file mode 100644
index bb194bd61..000000000
--- a/src/multimediawidgets/qpaintervideosurface.cpp
+++ /dev/null
@@ -1,1733 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qpaintervideosurface_p.h"
-
-#include <qmath.h>
-
-#include <qpainter.h>
-#include <qvariant.h>
-#include <qvideosurfaceformat.h>
-
-#if QT_CONFIG(opengl)
-#include <QOpenGLContext>
-#include <QOpenGLFunctions>
-#include <QOpenGLShaderProgram>
-#include <QtGui/QWindow>
-#ifndef GL_CLAMP_TO_EDGE
-#define GL_CLAMP_TO_EDGE 0x812F
-#endif
-#ifndef GL_RGB8
-#define GL_RGB8 0x8051
-#endif
-#endif
-
-#include <QtDebug>
-QT_BEGIN_NAMESPACE
-
-QVideoSurfacePainter::~QVideoSurfacePainter()
-{
-}
-
-class QVideoSurfaceGenericPainter : public QVideoSurfacePainter
-{
-public:
- QVideoSurfaceGenericPainter();
-
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const override;
-
- bool isFormatSupported(const QVideoSurfaceFormat &format) const override;
-
- QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) override;
- void stop() override;
-
- QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame) override;
-
- QAbstractVideoSurface::Error paint(
- const QRectF &target, QPainter *painter, const QRectF &source) override;
-
- void updateColors(int brightness, int contrast, int hue, int saturation) override;
-
-private:
- QList<QVideoFrame::PixelFormat> m_imagePixelFormats;
- QVideoFrame m_frame;
- QSize m_imageSize;
- QImage::Format m_imageFormat;
- QVideoSurfaceFormat::Direction m_scanLineDirection;
- bool m_mirrored;
-};
-
-QVideoSurfaceGenericPainter::QVideoSurfaceGenericPainter()
- : m_imageFormat(QImage::Format_Invalid)
- , m_scanLineDirection(QVideoSurfaceFormat::TopToBottom)
- , m_mirrored(false)
-{
- m_imagePixelFormats << QVideoFrame::Format_RGB32;
-
- // The raster formats should be a subset of the GL formats.
-#ifndef QT_NO_OPENGL
- if (QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGLES)
-#endif
- m_imagePixelFormats << QVideoFrame::Format_RGB24;
-
- m_imagePixelFormats << QVideoFrame::Format_ARGB32
- << QVideoFrame::Format_RGB565
- << QVideoFrame::Format_Y8;
-}
-
-QList<QVideoFrame::PixelFormat> QVideoSurfaceGenericPainter::supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const
-{
- switch (handleType) {
- case QAbstractVideoBuffer::QPixmapHandle:
- case QAbstractVideoBuffer::NoHandle:
- return m_imagePixelFormats;
- default:
- ;
- }
- return QList<QVideoFrame::PixelFormat>();
-}
-
-bool QVideoSurfaceGenericPainter::isFormatSupported(const QVideoSurfaceFormat &format) const
-{
- switch (format.handleType()) {
- case QAbstractVideoBuffer::QPixmapHandle:
- return true;
- case QAbstractVideoBuffer::NoHandle:
- return m_imagePixelFormats.contains(format.pixelFormat())
- && !format.frameSize().isEmpty();
- default:
- ;
- }
- return false;
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceGenericPainter::start(const QVideoSurfaceFormat &format)
-{
- m_frame = QVideoFrame();
- m_imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
- // Do not render into ARGB32 images using QPainter.
- // Using QImage::Format_ARGB32_Premultiplied is significantly faster.
- if (m_imageFormat == QImage::Format_ARGB32)
- m_imageFormat = QImage::Format_ARGB32_Premultiplied;
-
- m_imageSize = format.frameSize();
- m_scanLineDirection = format.scanLineDirection();
- m_mirrored = format.property("mirrored").toBool();
-
- const QAbstractVideoBuffer::HandleType t = format.handleType();
- if (t == QAbstractVideoBuffer::NoHandle) {
- bool ok = m_imageFormat != QImage::Format_Invalid && !m_imageSize.isEmpty();
-#ifndef QT_NO_OPENGL
- if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES)
- ok &= format.pixelFormat() != QVideoFrame::Format_RGB24;
-#endif
- if (ok)
- return QAbstractVideoSurface::NoError;
- } else if (t == QAbstractVideoBuffer::QPixmapHandle) {
- return QAbstractVideoSurface::NoError;
- }
- return QAbstractVideoSurface::UnsupportedFormatError;
-}
-
-void QVideoSurfaceGenericPainter::stop()
-{
- m_frame = QVideoFrame();
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceGenericPainter::setCurrentFrame(const QVideoFrame &frame)
-{
- m_frame = frame;
-
- return QAbstractVideoSurface::NoError;
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceGenericPainter::paint(
- const QRectF &target, QPainter *painter, const QRectF &source)
-{
- if (!m_frame.isValid()) {
- painter->fillRect(target, Qt::black);
- return QAbstractVideoSurface::NoError;
- }
-
- if (m_frame.handleType() == QAbstractVideoBuffer::QPixmapHandle) {
- painter->drawPixmap(target, m_frame.handle().value<QPixmap>(), source);
- } else if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) {
- QImage image(
- m_frame.bits(),
- m_imageSize.width(),
- m_imageSize.height(),
- m_frame.bytesPerLine(),
- m_imageFormat);
-
- const QTransform oldTransform = painter->transform();
- QTransform transform = oldTransform;
- QRectF targetRect = target;
- if (m_scanLineDirection == QVideoSurfaceFormat::BottomToTop) {
- transform.scale(1, -1);
- transform.translate(0, -target.bottom());
- targetRect = QRectF(target.x(), 0, target.width(), target.height());
- }
-
- if (m_mirrored) {
- transform.scale(-1, 1);
- transform.translate(-target.right(), 0);
- targetRect = QRectF(0, targetRect.y(), target.width(), target.height());
- }
- painter->setTransform(transform);
- painter->drawImage(targetRect, image, source);
- painter->setTransform(oldTransform);
-
- m_frame.unmap();
- } else if (m_frame.isValid()) {
- return QAbstractVideoSurface::IncorrectFormatError;
- } else {
- painter->fillRect(target, Qt::black);
- }
- return QAbstractVideoSurface::NoError;
-}
-
-void QVideoSurfaceGenericPainter::updateColors(int, int, int, int)
-{
-}
-
-#if QT_CONFIG(opengl)
-
-#ifndef APIENTRYP
-# ifdef APIENTRY
-# define APIENTRYP APIENTRY *
-# else
-# define APIENTRY
-# define APIENTRYP *
-# endif
-#endif
-
-#ifndef GL_TEXTURE0
-# define GL_TEXTURE0 0x84C0
-# define GL_TEXTURE1 0x84C1
-# define GL_TEXTURE2 0x84C2
-#endif
-#ifndef GL_PROGRAM_ERROR_STRING_ARB
-# define GL_PROGRAM_ERROR_STRING_ARB 0x8874
-#endif
-
-#ifndef GL_UNSIGNED_SHORT_5_6_5
-# define GL_UNSIGNED_SHORT_5_6_5 33635
-#endif
-
-class QVideoSurfaceGLPainter : public QVideoSurfacePainter, protected QOpenGLFunctions
-{
-public:
- QVideoSurfaceGLPainter(QOpenGLContext *context);
- ~QVideoSurfaceGLPainter();
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const override;
-
- bool isFormatSupported(const QVideoSurfaceFormat &format) const override;
-
- void stop() override;
-
- QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame) override;
-
- QAbstractVideoSurface::Error paint(
- const QRectF &target, QPainter *painter, const QRectF &source) override;
-
- void updateColors(int brightness, int contrast, int hue, int saturation) override;
- void viewportDestroyed() override;
-
-protected:
- void initRgbTextureInfo(GLenum internalFormat, GLuint format, GLenum type, const QSize &size);
- void initYuv420PTextureInfo(const QSize &size);
- void initYv12TextureInfo(const QSize &size);
-
- bool needsSwizzling(const QVideoSurfaceFormat &format) const {
- return format.pixelFormat() == QVideoFrame::Format_RGB32
- || format.pixelFormat() == QVideoFrame::Format_ARGB32;
- }
-
- QList<QVideoFrame::PixelFormat> m_imagePixelFormats;
- QList<QVideoFrame::PixelFormat> m_glPixelFormats;
- QMatrix4x4 m_colorMatrix;
- QVideoFrame m_frame;
-
- QOpenGLContext *m_context;
- QAbstractVideoBuffer::HandleType m_handleType;
- QVideoSurfaceFormat::Direction m_scanLineDirection;
- bool m_mirrored;
- QVideoSurfaceFormat::YCbCrColorSpace m_colorSpace;
- GLenum m_textureFormat;
- GLuint m_textureInternalFormat;
- GLenum m_textureType;
- int m_textureCount;
-
- static const uint Max_Textures = 3;
- GLuint m_textureIds[Max_Textures];
- int m_textureWidths[Max_Textures];
- int m_textureHeights[Max_Textures];
- int m_textureOffsets[Max_Textures];
- bool m_yuv;
-};
-
-QVideoSurfaceGLPainter::QVideoSurfaceGLPainter(QOpenGLContext *context)
- : m_context(context)
- , m_handleType(QAbstractVideoBuffer::NoHandle)
- , m_scanLineDirection(QVideoSurfaceFormat::TopToBottom)
- , m_mirrored(false)
- , m_colorSpace(QVideoSurfaceFormat::YCbCr_BT601)
- , m_textureFormat(0)
- , m_textureInternalFormat(0)
- , m_textureType(0)
- , m_textureCount(0)
- , m_yuv(false)
-{
- memset(m_textureIds, 0, sizeof(m_textureIds));
- memset(m_textureWidths, 0, sizeof(m_textureWidths));
- memset(m_textureHeights, 0, sizeof(m_textureHeights));
- memset(m_textureOffsets, 0, sizeof(m_textureOffsets));
-
- initializeOpenGLFunctions();
-}
-
-QVideoSurfaceGLPainter::~QVideoSurfaceGLPainter()
-{
-}
-
-void QVideoSurfaceGLPainter::viewportDestroyed()
-{
- m_context = 0;
-}
-
-QList<QVideoFrame::PixelFormat> QVideoSurfaceGLPainter::supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const
-{
- switch (handleType) {
- case QAbstractVideoBuffer::NoHandle:
- return m_imagePixelFormats;
- case QAbstractVideoBuffer::QPixmapHandle:
- case QAbstractVideoBuffer::GLTextureHandle:
- return m_glPixelFormats;
- default:
- ;
- }
- return QList<QVideoFrame::PixelFormat>();
-}
-
-bool QVideoSurfaceGLPainter::isFormatSupported(const QVideoSurfaceFormat &format) const
-{
- if (format.frameSize().isEmpty()) {
- return false;
- } else {
- switch (format.handleType()) {
- case QAbstractVideoBuffer::NoHandle:
- return m_imagePixelFormats.contains(format.pixelFormat());
- case QAbstractVideoBuffer::QPixmapHandle:
- case QAbstractVideoBuffer::GLTextureHandle:
- return m_glPixelFormats.contains(format.pixelFormat());
- default:
- ;
- }
- }
- return false;
-}
-
-
-void QVideoSurfaceGLPainter::stop()
-{
- m_frame = QVideoFrame();
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceGLPainter::setCurrentFrame(const QVideoFrame &frame)
-{
- m_frame = frame;
-
- if (m_handleType == QAbstractVideoBuffer::GLTextureHandle) {
- m_textureIds[0] = frame.handle().toInt();
- glBindTexture(GL_TEXTURE_2D, m_textureIds[0]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- } else if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) {
- for (int i = 0; i < m_textureCount; ++i) {
- glBindTexture(GL_TEXTURE_2D, m_textureIds[i]);
- glTexImage2D(
- GL_TEXTURE_2D,
- 0,
- m_textureInternalFormat,
- m_textureWidths[i],
- m_textureHeights[i],
- 0,
- m_textureFormat,
- m_textureType,
- m_frame.bits() + m_textureOffsets[i]);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- }
- m_frame.unmap();
- } else if (m_handleType != QAbstractVideoBuffer::QPixmapHandle && m_frame.isValid()) {
- return QAbstractVideoSurface::IncorrectFormatError;
- }
-
- return QAbstractVideoSurface::NoError;
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceGLPainter::paint(
- const QRectF &target, QPainter *painter, const QRectF &source)
-{
- if (!m_frame.isValid()) {
- painter->fillRect(target, Qt::black);
- return QAbstractVideoSurface::NoError;
- }
-
- if (m_frame.handleType() == QAbstractVideoBuffer::QPixmapHandle) {
- painter->drawPixmap(target, m_frame.handle().value<QPixmap>(), source);
- } else if (m_frame.isValid()) {
- return QAbstractVideoSurface::IncorrectFormatError;
- } else {
- painter->fillRect(target, Qt::black);
- }
- return QAbstractVideoSurface::NoError;
-}
-
-void QVideoSurfaceGLPainter::updateColors(int brightness, int contrast, int hue, int saturation)
-{
- const qreal b = brightness / 200.0;
- const qreal c = contrast / 100.0 + 1.0;
- const qreal h = hue / 100.0;
- const qreal s = saturation / 100.0 + 1.0;
-
- const qreal cosH = qCos(M_PI * h);
- const qreal sinH = qSin(M_PI * h);
-
- const qreal h11 = 0.787 * cosH - 0.213 * sinH + 0.213;
- const qreal h21 = -0.213 * cosH + 0.143 * sinH + 0.213;
- const qreal h31 = -0.213 * cosH - 0.787 * sinH + 0.213;
-
- const qreal h12 = -0.715 * cosH - 0.715 * sinH + 0.715;
- const qreal h22 = 0.285 * cosH + 0.140 * sinH + 0.715;
- const qreal h32 = -0.715 * cosH + 0.715 * sinH + 0.715;
-
- const qreal h13 = -0.072 * cosH + 0.928 * sinH + 0.072;
- const qreal h23 = -0.072 * cosH - 0.283 * sinH + 0.072;
- const qreal h33 = 0.928 * cosH + 0.072 * sinH + 0.072;
-
- const qreal sr = (1.0 - s) * 0.3086;
- const qreal sg = (1.0 - s) * 0.6094;
- const qreal sb = (1.0 - s) * 0.0820;
-
- const qreal sr_s = sr + s;
- const qreal sg_s = sg + s;
- const qreal sb_s = sr + s;
-
- const float m4 = (s + sr + sg + sb) * (0.5 - 0.5 * c + b);
-
- m_colorMatrix(0, 0) = c * (sr_s * h11 + sg * h21 + sb * h31);
- m_colorMatrix(0, 1) = c * (sr_s * h12 + sg * h22 + sb * h32);
- m_colorMatrix(0, 2) = c * (sr_s * h13 + sg * h23 + sb * h33);
- m_colorMatrix(0, 3) = m4;
-
- m_colorMatrix(1, 0) = c * (sr * h11 + sg_s * h21 + sb * h31);
- m_colorMatrix(1, 1) = c * (sr * h12 + sg_s * h22 + sb * h32);
- m_colorMatrix(1, 2) = c * (sr * h13 + sg_s * h23 + sb * h33);
- m_colorMatrix(1, 3) = m4;
-
- m_colorMatrix(2, 0) = c * (sr * h11 + sg * h21 + sb_s * h31);
- m_colorMatrix(2, 1) = c * (sr * h12 + sg * h22 + sb_s * h32);
- m_colorMatrix(2, 2) = c * (sr * h13 + sg * h23 + sb_s * h33);
- m_colorMatrix(2, 3) = m4;
-
- m_colorMatrix(3, 0) = 0.0;
- m_colorMatrix(3, 1) = 0.0;
- m_colorMatrix(3, 2) = 0.0;
- m_colorMatrix(3, 3) = 1.0;
-
- if (m_yuv) {
- QMatrix4x4 colorSpaceMatrix;
-
- switch (m_colorSpace) {
- case QVideoSurfaceFormat::YCbCr_JPEG:
- colorSpaceMatrix = QMatrix4x4(
- 1.0f, 0.000f, 1.402f, -0.701f,
- 1.0f, -0.344f, -0.714f, 0.529f,
- 1.0f, 1.772f, 0.000f, -0.886f,
- 0.0f, 0.000f, 0.000f, 1.0000f);
- break;
- case QVideoSurfaceFormat::YCbCr_BT709:
- case QVideoSurfaceFormat::YCbCr_xvYCC709:
- colorSpaceMatrix = QMatrix4x4(
- 1.164f, 0.000f, 1.793f, -0.5727f,
- 1.164f, -0.534f, -0.213f, 0.3007f,
- 1.164f, 2.115f, 0.000f, -1.1302f,
- 0.0f, 0.000f, 0.000f, 1.0000f);
- break;
- default: //BT 601:
- colorSpaceMatrix = QMatrix4x4(
- 1.164f, 0.000f, 1.596f, -0.8708f,
- 1.164f, -0.392f, -0.813f, 0.5296f,
- 1.164f, 2.017f, 0.000f, -1.081f,
- 0.0f, 0.000f, 0.000f, 1.0000f);
- }
-
- m_colorMatrix = m_colorMatrix * colorSpaceMatrix;
- }
-}
-
-void QVideoSurfaceGLPainter::initRgbTextureInfo(
- GLenum internalFormat, GLuint format, GLenum type, const QSize &size)
-{
- m_yuv = false;
- m_textureInternalFormat = internalFormat;
- m_textureFormat = format;
- m_textureType = type;
- m_textureCount = 1; // Note: ensure this is always <= Max_Textures
- m_textureWidths[0] = size.width();
- m_textureHeights[0] = size.height();
- m_textureOffsets[0] = 0;
-}
-
-void QVideoSurfaceGLPainter::initYuv420PTextureInfo(const QSize &size)
-{
- int bytesPerLine = (size.width() + 3) & ~3;
- int bytesPerLine2 = (size.width() / 2 + 3) & ~3;
-
- m_yuv = true;
- m_textureInternalFormat = GL_LUMINANCE;
- m_textureFormat = GL_LUMINANCE;
- m_textureType = GL_UNSIGNED_BYTE;
- m_textureCount = 3; // Note: ensure this is always <= Max_Textures
- m_textureWidths[0] = bytesPerLine;
- m_textureHeights[0] = size.height();
- m_textureOffsets[0] = 0;
- m_textureWidths[1] = bytesPerLine2;
- m_textureHeights[1] = size.height() / 2;
- m_textureOffsets[1] = bytesPerLine * size.height();
- m_textureWidths[2] = bytesPerLine2;
- m_textureHeights[2] = size.height() / 2;
- m_textureOffsets[2] = bytesPerLine * size.height() + bytesPerLine2 * size.height()/2;
-}
-
-void QVideoSurfaceGLPainter::initYv12TextureInfo(const QSize &size)
-{
- int bytesPerLine = (size.width() + 3) & ~3;
- int bytesPerLine2 = (size.width() / 2 + 3) & ~3;
-
- m_yuv = true;
- m_textureInternalFormat = GL_LUMINANCE;
- m_textureFormat = GL_LUMINANCE;
- m_textureType = GL_UNSIGNED_BYTE;
- m_textureCount = 3; // Note: ensure this is always <= Max_Textures
- m_textureWidths[0] = bytesPerLine;
- m_textureHeights[0] = size.height();
- m_textureOffsets[0] = 0;
- m_textureWidths[1] = bytesPerLine2;
- m_textureHeights[1] = size.height() / 2;
- m_textureOffsets[1] = bytesPerLine * size.height() + bytesPerLine2 * size.height()/2;
- m_textureWidths[2] = bytesPerLine2;
- m_textureHeights[2] = size.height() / 2;
- m_textureOffsets[2] = bytesPerLine * size.height();
-}
-
-#if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC)
-
-# ifndef GL_FRAGMENT_PROGRAM_ARB
-# define GL_FRAGMENT_PROGRAM_ARB 0x8804
-# define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875
-# endif
-
-// Paints an RGB32 frame
-static const char *qt_arbfp_xrgbShaderProgram =
- "!!ARBfp1.0\n"
- "PARAM matrix[4] = { program.local[0..2],"
- "{ 0.0, 0.0, 0.0, 1.0 } };\n"
- "TEMP xrgb;\n"
- "TEX xrgb.xyz, fragment.texcoord[0], texture[0], 2D;\n"
- "MOV xrgb.w, matrix[3].w;\n"
- "DP4 result.color.x, xrgb.zyxw, matrix[0];\n"
- "DP4 result.color.y, xrgb.zyxw, matrix[1];\n"
- "DP4 result.color.z, xrgb.zyxw, matrix[2];\n"
- "END";
-
-// Paints an ARGB frame.
-static const char *qt_arbfp_argbShaderProgram =
- "!!ARBfp1.0\n"
- "PARAM matrix[4] = { program.local[0..2],"
- "{ 0.0, 0.0, 0.0, 1.0 } };\n"
- "TEMP argb;\n"
- "TEX argb, fragment.texcoord[0], texture[0], 2D;\n"
- "MOV argb.w, matrix[3].w;\n"
- "DP4 result.color.x, argb.zyxw, matrix[0];\n"
- "DP4 result.color.y, argb.zyxw, matrix[1];\n"
- "DP4 result.color.z, argb.zyxw, matrix[2];\n"
- "TEX result.color.w, fragment.texcoord[0], texture, 2D;\n"
- "END";
-
-// Paints an RGB(A) frame.
-static const char *qt_arbfp_rgbShaderProgram =
- "!!ARBfp1.0\n"
- "PARAM matrix[4] = { program.local[0..2],"
- "{ 0.0, 0.0, 0.0, 1.0 } };\n"
- "TEMP rgb;\n"
- "TEX rgb, fragment.texcoord[0], texture[0], 2D;\n"
- "MOV rgb.w, matrix[3].w;\n"
- "DP4 result.color.x, rgb, matrix[0];\n"
- "DP4 result.color.y, rgb, matrix[1];\n"
- "DP4 result.color.z, rgb, matrix[2];\n"
- "TEX result.color.w, fragment.texcoord[0], texture, 2D;\n"
- "END";
-
-// Paints a YUV420P or YV12 frame.
-static const char *qt_arbfp_yuvPlanarShaderProgram =
- "!!ARBfp1.0\n"
- "PARAM matrix[4] = { program.local[0..2],"
- "{ 0.0, 0.0, 0.0, 1.0 } };\n"
- "TEMP yuv;\n"
- "TEX yuv.x, fragment.texcoord[0], texture[0], 2D;\n"
- "TEX yuv.y, fragment.texcoord[0], texture[1], 2D;\n"
- "TEX yuv.z, fragment.texcoord[0], texture[2], 2D;\n"
- "MOV yuv.w, matrix[3].w;\n"
- "DP4 result.color.x, yuv, matrix[0];\n"
- "DP4 result.color.y, yuv, matrix[1];\n"
- "DP4 result.color.z, yuv, matrix[2];\n"
- "END";
-
-// Paints a YUV444 frame.
-static const char *qt_arbfp_xyuvShaderProgram =
- "!!ARBfp1.0\n"
- "PARAM matrix[4] = { program.local[0..2],"
- "{ 0.0, 0.0, 0.0, 1.0 } };\n"
- "TEMP ayuv;\n"
- "TEX ayuv, fragment.texcoord[0], texture[0], 2D;\n"
- "MOV ayuv.x, matrix[3].w;\n"
- "DP4 result.color.x, ayuv.yzwx, matrix[0];\n"
- "DP4 result.color.y, ayuv.yzwx, matrix[1];\n"
- "DP4 result.color.z, ayuv.yzwx, matrix[2];\n"
- "END";
-
-// Paints a AYUV444 frame.
-static const char *qt_arbfp_ayuvShaderProgram =
- "!!ARBfp1.0\n"
- "PARAM matrix[4] = { program.local[0..2],"
- "{ 0.0, 0.0, 0.0, 1.0 } };\n"
- "TEMP ayuv;\n"
- "TEX ayuv, fragment.texcoord[0], texture[0], 2D;\n"
- "MOV ayuv.x, matrix[3].w;\n"
- "DP4 result.color.x, ayuv.yzwx, matrix[0];\n"
- "DP4 result.color.y, ayuv.yzwx, matrix[1];\n"
- "DP4 result.color.z, ayuv.yzwx, matrix[2];\n"
- "TEX result.color.w, fragment.texcoord[0], texture, 2D;\n"
- "END";
-
-class QVideoSurfaceArbFpPainter : public QVideoSurfaceGLPainter
-{
-public:
- QVideoSurfaceArbFpPainter(QOpenGLContext *context);
-
- QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) override;
- void stop() override;
-
- QAbstractVideoSurface::Error paint(
- const QRectF &target, QPainter *painter, const QRectF &source) override;
-
-private:
- typedef void (APIENTRY *_glProgramStringARB) (GLenum, GLenum, GLsizei, const GLvoid *);
- typedef void (APIENTRY *_glBindProgramARB) (GLenum, GLuint);
- typedef void (APIENTRY *_glDeleteProgramsARB) (GLsizei, const GLuint *);
- typedef void (APIENTRY *_glGenProgramsARB) (GLsizei, GLuint *);
- typedef void (APIENTRY *_glProgramLocalParameter4fARB) (
- GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat);
- typedef void (APIENTRY *_glActiveTexture) (GLenum);
-
- _glProgramStringARB glProgramStringARB;
- _glBindProgramARB glBindProgramARB;
- _glDeleteProgramsARB glDeleteProgramsARB;
- _glGenProgramsARB glGenProgramsARB;
- _glProgramLocalParameter4fARB glProgramLocalParameter4fARB;
-
- GLuint m_programId;
- QSize m_frameSize;
-};
-
-QVideoSurfaceArbFpPainter::QVideoSurfaceArbFpPainter(QOpenGLContext *context)
- : QVideoSurfaceGLPainter(context)
- , m_programId(0)
-{
- glProgramStringARB = (_glProgramStringARB) m_context->getProcAddress(
- QByteArray("glProgramStringARB"));
- glBindProgramARB = (_glBindProgramARB) m_context->getProcAddress(
- QByteArray("glBindProgramARB"));
- glDeleteProgramsARB = (_glDeleteProgramsARB) m_context->getProcAddress(
- QByteArray("glDeleteProgramsARB"));
- glGenProgramsARB = (_glGenProgramsARB) m_context->getProcAddress(
- QByteArray("glGenProgramsARB"));
- glProgramLocalParameter4fARB = (_glProgramLocalParameter4fARB) m_context->getProcAddress(
- QByteArray("glProgramLocalParameter4fARB"));
-
- m_imagePixelFormats
- << QVideoFrame::Format_RGB32
- << QVideoFrame::Format_BGR32
- << QVideoFrame::Format_ARGB32
- << QVideoFrame::Format_RGB24
- << QVideoFrame::Format_BGR24
- << QVideoFrame::Format_RGB565
- << QVideoFrame::Format_AYUV444
- << QVideoFrame::Format_YUV444
- << QVideoFrame::Format_YV12
- << QVideoFrame::Format_YUV420P;
- m_glPixelFormats
- << QVideoFrame::Format_RGB32
- << QVideoFrame::Format_ARGB32
- << QVideoFrame::Format_BGR32
- << QVideoFrame::Format_BGRA32;
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::start(const QVideoSurfaceFormat &format)
-{
- Q_ASSERT(m_textureCount == 0);
-
- QAbstractVideoSurface::Error error = QAbstractVideoSurface::NoError;
-
- const char *program = 0;
-
- if (format.handleType() == QAbstractVideoBuffer::NoHandle) {
- switch (format.pixelFormat()) {
- case QVideoFrame::Format_RGB32:
- initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
- program = qt_arbfp_xrgbShaderProgram;
- break;
- case QVideoFrame::Format_BGR32:
- initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
- program = qt_arbfp_rgbShaderProgram;
- break;
- case QVideoFrame::Format_ARGB32:
- initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
- program = qt_arbfp_argbShaderProgram;
- break;
- case QVideoFrame::Format_RGB24:
- initRgbTextureInfo(GL_RGB8, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
- program = qt_arbfp_rgbShaderProgram;
- break;
- case QVideoFrame::Format_BGR24:
- initRgbTextureInfo(GL_RGB8, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
- program = qt_arbfp_xrgbShaderProgram;
- break;
- case QVideoFrame::Format_RGB565:
- initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, format.frameSize());
- program = qt_arbfp_rgbShaderProgram;
- break;
- case QVideoFrame::Format_YUV444:
- initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize());
- program = qt_arbfp_xyuvShaderProgram;
- m_yuv = true;
- break;
- case QVideoFrame::Format_AYUV444:
- initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
- program = qt_arbfp_ayuvShaderProgram;
- m_yuv = true;
- break;
- case QVideoFrame::Format_YV12:
- initYv12TextureInfo(format.frameSize());
- program = qt_arbfp_yuvPlanarShaderProgram;
- break;
- case QVideoFrame::Format_YUV420P:
- initYuv420PTextureInfo(format.frameSize());
- program = qt_arbfp_yuvPlanarShaderProgram;
- break;
- default:
- break;
- }
- } else if (format.handleType() == QAbstractVideoBuffer::GLTextureHandle) {
- switch (format.pixelFormat()) {
- case QVideoFrame::Format_RGB32:
- case QVideoFrame::Format_ARGB32:
- case QVideoFrame::Format_BGR32:
- case QVideoFrame::Format_BGRA32:
- m_yuv = false;
- m_textureCount = 1;
- if (needsSwizzling(format))
- program = qt_arbfp_xrgbShaderProgram;
- else
- program = qt_arbfp_rgbShaderProgram;
- break;
- default:
- break;
- }
- } else if (format.handleType() == QAbstractVideoBuffer::QPixmapHandle) {
- m_handleType = QAbstractVideoBuffer::QPixmapHandle;
- return QAbstractVideoSurface::NoError;
- }
-
- if (!program) {
- error = QAbstractVideoSurface::UnsupportedFormatError;
- } else {
- while (glGetError() != GL_NO_ERROR) { } // clear previous unrelated errors
-
- glGenProgramsARB(1, &m_programId);
-
- GLenum glError = glGetError();
- if (glError != GL_NO_ERROR) {
- qWarning("QPainterVideoSurface: ARBfb Shader allocation error %x", int(glError));
- m_textureCount = 0;
- m_programId = 0;
-
- error = QAbstractVideoSurface::ResourceError;
- } else {
- glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, m_programId);
- glProgramStringARB(
- GL_FRAGMENT_PROGRAM_ARB,
- GL_PROGRAM_FORMAT_ASCII_ARB,
- qstrlen(program),
- reinterpret_cast<const GLvoid *>(program));
-
- if ((glError = glGetError()) != GL_NO_ERROR) {
- const GLubyte* errorString = glGetString(GL_PROGRAM_ERROR_STRING_ARB);
-
- qWarning("QPainterVideoSurface: ARBfp Shader compile error %x, %s",
- int(glError),
- reinterpret_cast<const char *>(errorString));
- glDeleteProgramsARB(1, &m_programId);
-
- m_textureCount = 0;
- m_programId = 0;
-
- error = QAbstractVideoSurface::ResourceError;
- } else {
- m_handleType = format.handleType();
- m_scanLineDirection = format.scanLineDirection();
- m_mirrored = format.property("mirrored").toBool();
- m_frameSize = format.frameSize();
- m_colorSpace = format.yCbCrColorSpace();
-
- if (m_handleType == QAbstractVideoBuffer::NoHandle)
- glGenTextures(m_textureCount, m_textureIds);
- }
- }
- }
-
- return error;
-}
-
-void QVideoSurfaceArbFpPainter::stop()
-{
- if (m_context) {
- if (m_handleType != QAbstractVideoBuffer::GLTextureHandle)
- glDeleteTextures(m_textureCount, m_textureIds);
- glDeleteProgramsARB(1, &m_programId);
- }
-
- m_textureCount = 0;
- m_programId = 0;
- m_handleType = QAbstractVideoBuffer::NoHandle;
-
- QVideoSurfaceGLPainter::stop();
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::paint(
- const QRectF &target, QPainter *painter, const QRectF &source)
-{
- if (!m_frame.isValid()) {
- painter->fillRect(target, Qt::black);
- return QAbstractVideoSurface::NoError;
- }
-
- const QAbstractVideoBuffer::HandleType h = m_frame.handleType();
- if (h == QAbstractVideoBuffer::NoHandle || h == QAbstractVideoBuffer::GLTextureHandle) {
- bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST);
- bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);
-
- painter->beginNativePainting();
-
- if (stencilTestEnabled)
- glEnable(GL_STENCIL_TEST);
- if (scissorTestEnabled)
- glEnable(GL_SCISSOR_TEST);
-
- const float txLeft = m_mirrored ? source.right() / m_frameSize.width()
- : source.left() / m_frameSize.width();
- const float txRight = m_mirrored ? source.left() / m_frameSize.width()
- : source.right() / m_frameSize.width();
- const float txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
- ? source.top() / m_frameSize.height()
- : source.bottom() / m_frameSize.height();
- const float txBottom = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
- ? source.bottom() / m_frameSize.height()
- : source.top() / m_frameSize.height();
-
- const float tx_array[] =
- {
- txLeft , txBottom,
- txRight, txBottom,
- txLeft , txTop,
- txRight, txTop
- };
-
- const GLfloat v_array[] =
- {
- GLfloat(target.left()) , GLfloat(target.bottom() + 1),
- GLfloat(target.right() + 1), GLfloat(target.bottom() + 1),
- GLfloat(target.left()) , GLfloat(target.top()),
- GLfloat(target.right() + 1), GLfloat(target.top())
- };
-
- glEnable(GL_FRAGMENT_PROGRAM_ARB);
- glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, m_programId);
-
- glProgramLocalParameter4fARB(
- GL_FRAGMENT_PROGRAM_ARB,
- 0,
- m_colorMatrix(0, 0),
- m_colorMatrix(0, 1),
- m_colorMatrix(0, 2),
- m_colorMatrix(0, 3));
- glProgramLocalParameter4fARB(
- GL_FRAGMENT_PROGRAM_ARB,
- 1,
- m_colorMatrix(1, 0),
- m_colorMatrix(1, 1),
- m_colorMatrix(1, 2),
- m_colorMatrix(1, 3));
- glProgramLocalParameter4fARB(
- GL_FRAGMENT_PROGRAM_ARB,
- 2,
- m_colorMatrix(2, 0),
- m_colorMatrix(2, 1),
- m_colorMatrix(2, 2),
- m_colorMatrix(2, 3));
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, m_textureIds[0]);
-
- if (m_textureCount == 3) {
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, m_textureIds[1]);
- glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, m_textureIds[2]);
- glActiveTexture(GL_TEXTURE0);
- }
-
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, v_array);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, tx_array);
-
- glEnableVertexAttribArray(0);
- glEnableVertexAttribArray(1);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableVertexAttribArray(0);
- glDisableVertexAttribArray(1);
-
- glDisable(GL_FRAGMENT_PROGRAM_ARB);
-
- painter->endNativePainting();
-
- return QAbstractVideoSurface::NoError;
- }
-
- return QVideoSurfaceGLPainter::paint(target, painter, source);
-}
-
-#endif // !QT_OPENGL_ES && !QT_OPENGL_DYNAMIC
-
-static const char *qt_glsl_vertexShaderProgram =
- "attribute highp vec4 vertexCoordArray;\n"
- "attribute highp vec2 textureCoordArray;\n"
- "uniform highp mat4 positionMatrix;\n"
- "varying highp vec2 textureCoord;\n"
- "void main(void)\n"
- "{\n"
- " gl_Position = positionMatrix * vertexCoordArray;\n"
- " textureCoord = textureCoordArray;\n"
- "}\n";
-
-// Paints an RGB32 frame
-static const char *qt_glsl_xrgbShaderProgram =
- "uniform sampler2D texRgb;\n"
- "uniform mediump mat4 colorMatrix;\n"
- "varying highp vec2 textureCoord;\n"
- "void main(void)\n"
- "{\n"
- " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).bgr, 1.0);\n"
- " gl_FragColor = colorMatrix * color;\n"
- "}\n";
-
-// Paints an ARGB frame.
-static const char *qt_glsl_argbShaderProgram =
- "uniform sampler2D texRgb;\n"
- "uniform mediump mat4 colorMatrix;\n"
- "varying highp vec2 textureCoord;\n"
- "void main(void)\n"
- "{\n"
- " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).bgr, 1.0);\n"
- " color = colorMatrix * color;\n"
- " gl_FragColor = vec4(color.rgb, texture2D(texRgb, textureCoord.st).a);\n"
- "}\n";
-
-// Paints an RGB(A) frame.
-static const char *qt_glsl_rgbShaderProgram =
- "uniform sampler2D texRgb;\n"
- "uniform mediump mat4 colorMatrix;\n"
- "varying highp vec2 textureCoord;\n"
- "void main(void)\n"
- "{\n"
- " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).rgb, 1.0);\n"
- " color = colorMatrix * color;\n"
- " gl_FragColor = vec4(color.rgb, texture2D(texRgb, textureCoord.st).a);\n"
- "}\n";
-
-// Paints a YUV420P or YV12 frame.
-static const char *qt_glsl_yuvPlanarShaderProgram =
- "uniform sampler2D texY;\n"
- "uniform sampler2D texU;\n"
- "uniform sampler2D texV;\n"
- "uniform mediump mat4 colorMatrix;\n"
- "varying highp vec2 textureCoord;\n"
- "void main(void)\n"
- "{\n"
- " highp vec4 color = vec4(\n"
- " texture2D(texY, textureCoord.st).r,\n"
- " texture2D(texU, textureCoord.st).r,\n"
- " texture2D(texV, textureCoord.st).r,\n"
- " 1.0);\n"
- " gl_FragColor = colorMatrix * color;\n"
- "}\n";
-
-// Paints a YUV444 frame.
-static const char *qt_glsl_xyuvShaderProgram =
- "uniform sampler2D texRgb;\n"
- "uniform mediump mat4 colorMatrix;\n"
- "varying highp vec2 textureCoord;\n"
- "void main(void)\n"
- "{\n"
- " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).gba, 1.0);\n"
- " gl_FragColor = colorMatrix * color;\n"
- "}\n";
-
-// Paints a AYUV444 frame.
-static const char *qt_glsl_ayuvShaderProgram =
- "uniform sampler2D texRgb;\n"
- "uniform mediump mat4 colorMatrix;\n"
- "varying highp vec2 textureCoord;\n"
- "void main(void)\n"
- "{\n"
- " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).gba, 1.0);\n"
- " color = colorMatrix * color;\n"
- " gl_FragColor = vec4(color.rgb, texture2D(texRgb, textureCoord.st).r);\n"
- "}\n";
-
-class QVideoSurfaceGlslPainter : public QVideoSurfaceGLPainter
-{
-public:
- QVideoSurfaceGlslPainter(QOpenGLContext *context);
-
- QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) override;
- void stop() override;
-
- QAbstractVideoSurface::Error paint(
- const QRectF &target, QPainter *painter, const QRectF &source) override;
-
-private:
- QOpenGLShaderProgram m_program;
- QSize m_frameSize;
-};
-
-QVideoSurfaceGlslPainter::QVideoSurfaceGlslPainter(QOpenGLContext *context)
- : QVideoSurfaceGLPainter(context)
- , m_program(context)
-{
- m_imagePixelFormats
- << QVideoFrame::Format_RGB32
- << QVideoFrame::Format_BGR32
- << QVideoFrame::Format_ARGB32;
- if (!context->isOpenGLES()) {
- m_imagePixelFormats
- << QVideoFrame::Format_RGB24
- << QVideoFrame::Format_BGR24;
- }
- m_imagePixelFormats
- << QVideoFrame::Format_RGB565
- << QVideoFrame::Format_YUV444
- << QVideoFrame::Format_AYUV444
- << QVideoFrame::Format_YV12
- << QVideoFrame::Format_YUV420P;
- m_glPixelFormats
- << QVideoFrame::Format_RGB32
- << QVideoFrame::Format_ARGB32
- << QVideoFrame::Format_BGR32
- << QVideoFrame::Format_BGRA32;
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurfaceFormat &format)
-{
- Q_ASSERT(m_textureCount == 0);
-
- QAbstractVideoSurface::Error error = QAbstractVideoSurface::NoError;
-
- const char *fragmentProgram = 0;
-
- if (format.handleType() == QAbstractVideoBuffer::NoHandle) {
- switch (format.pixelFormat()) {
- case QVideoFrame::Format_RGB32:
- initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
- fragmentProgram = qt_glsl_xrgbShaderProgram;
- break;
- case QVideoFrame::Format_BGR32:
- initRgbTextureInfo(GL_RGB, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
- fragmentProgram = qt_glsl_rgbShaderProgram;
- break;
- case QVideoFrame::Format_ARGB32:
- initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
- fragmentProgram = qt_glsl_argbShaderProgram;
- break;
- case QVideoFrame::Format_RGB24:
- if (!m_context->isOpenGLES()) {
- initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize());
- fragmentProgram = qt_glsl_rgbShaderProgram;
- }
- break;
- case QVideoFrame::Format_BGR24:
- if (!m_context->isOpenGLES()) {
- initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize());
- fragmentProgram = qt_glsl_argbShaderProgram;
- }
- break;
- case QVideoFrame::Format_RGB565:
- initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, format.frameSize());
- fragmentProgram = qt_glsl_rgbShaderProgram;
- break;
- case QVideoFrame::Format_YUV444:
- initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize());
- fragmentProgram = qt_glsl_xyuvShaderProgram;
- m_yuv = true;
- break;
- case QVideoFrame::Format_AYUV444:
- initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
- fragmentProgram = qt_glsl_ayuvShaderProgram;
- m_yuv = true;
- break;
- case QVideoFrame::Format_YV12:
- initYv12TextureInfo(format.frameSize());
- fragmentProgram = qt_glsl_yuvPlanarShaderProgram;
- break;
- case QVideoFrame::Format_YUV420P:
- initYuv420PTextureInfo(format.frameSize());
- fragmentProgram = qt_glsl_yuvPlanarShaderProgram;
- break;
- default:
- break;
- }
- } else if (format.handleType() == QAbstractVideoBuffer::GLTextureHandle) {
- switch (format.pixelFormat()) {
- case QVideoFrame::Format_RGB32:
- case QVideoFrame::Format_ARGB32:
- case QVideoFrame::Format_BGR32:
- case QVideoFrame::Format_BGRA32:
- m_yuv = false;
- m_textureCount = 1;
- if (needsSwizzling(format))
- fragmentProgram = qt_glsl_xrgbShaderProgram;
- else
- fragmentProgram = qt_glsl_rgbShaderProgram;
- break;
- default:
- break;
- }
- } else if (format.handleType() == QAbstractVideoBuffer::QPixmapHandle) {
- m_handleType = QAbstractVideoBuffer::QPixmapHandle;
- return QAbstractVideoSurface::NoError;
- }
-
- if (!fragmentProgram) {
- error = QAbstractVideoSurface::UnsupportedFormatError;
- } else if (!m_program.addShaderFromSourceCode(QOpenGLShader::Vertex, qt_glsl_vertexShaderProgram)) {
- qWarning("QPainterVideoSurface: Vertex shader compile error %s",
- qPrintable(m_program.log()));
- error = QAbstractVideoSurface::ResourceError;
- } else if (!m_program.addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentProgram)) {
- qWarning("QPainterVideoSurface: Shader compile error %s", qPrintable(m_program.log()));
- error = QAbstractVideoSurface::ResourceError;
- m_program.removeAllShaders();
- } else if(!m_program.link()) {
- qWarning("QPainterVideoSurface: Shader link error %s", qPrintable(m_program.log()));
- m_program.removeAllShaders();
- error = QAbstractVideoSurface::ResourceError;
- } else {
- m_handleType = format.handleType();
- m_scanLineDirection = format.scanLineDirection();
- m_mirrored = format.property("mirrored").toBool();
- m_frameSize = format.frameSize();
- m_colorSpace = format.yCbCrColorSpace();
-
- if (m_handleType == QAbstractVideoBuffer::NoHandle)
- glGenTextures(m_textureCount, m_textureIds);
- }
-
- return error;
-}
-
-void QVideoSurfaceGlslPainter::stop()
-{
- if (m_context) {
- if (m_handleType != QAbstractVideoBuffer::GLTextureHandle)
- glDeleteTextures(m_textureCount, m_textureIds);
- }
-
- m_program.removeAllShaders();
-
- m_textureCount = 0;
- m_handleType = QAbstractVideoBuffer::NoHandle;
-
- QVideoSurfaceGLPainter::stop();
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::paint(
- const QRectF &target, QPainter *painter, const QRectF &source)
-{
- if (!m_frame.isValid()) {
- painter->fillRect(target, Qt::black);
- return QAbstractVideoSurface::NoError;
- }
-
- const QAbstractVideoBuffer::HandleType h = m_frame.handleType();
- if (h == QAbstractVideoBuffer::NoHandle || h == QAbstractVideoBuffer::GLTextureHandle) {
- bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST);
- bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);
-
- painter->beginNativePainting();
-
- if (stencilTestEnabled)
- glEnable(GL_STENCIL_TEST);
- if (scissorTestEnabled)
- glEnable(GL_SCISSOR_TEST);
-
- const int width = painter->viewport().width();
- const int height = painter->viewport().height();
-
- const QTransform transform = painter->deviceTransform();
-
- const GLfloat wfactor = 2.0 / width;
- const GLfloat hfactor = -2.0 / height;
-
- const GLfloat positionMatrix[4][4] =
- {
- {
- /*(0,0)*/ GLfloat(wfactor * transform.m11() - transform.m13()),
- /*(0,1)*/ GLfloat(hfactor * transform.m12() + transform.m13()),
- /*(0,2)*/ 0.0,
- /*(0,3)*/ GLfloat(transform.m13())
- }, {
- /*(1,0)*/ GLfloat(wfactor * transform.m21() - transform.m23()),
- /*(1,1)*/ GLfloat(hfactor * transform.m22() + transform.m23()),
- /*(1,2)*/ 0.0,
- /*(1,3)*/ GLfloat(transform.m23())
- }, {
- /*(2,0)*/ 0.0,
- /*(2,1)*/ 0.0,
- /*(2,2)*/ -1.0,
- /*(2,3)*/ 0.0
- }, {
- /*(3,0)*/ GLfloat(wfactor * transform.dx() - transform.m33()),
- /*(3,1)*/ GLfloat(hfactor * transform.dy() + transform.m33()),
- /*(3,2)*/ 0.0,
- /*(3,3)*/ GLfloat(transform.m33())
- }
- };
-
- const GLfloat vertexCoordArray[] =
- {
- GLfloat(target.left()) , GLfloat(target.bottom() + 1),
- GLfloat(target.right() + 1), GLfloat(target.bottom() + 1),
- GLfloat(target.left()) , GLfloat(target.top()),
- GLfloat(target.right() + 1), GLfloat(target.top())
- };
-
- const GLfloat txLeft = m_mirrored ? source.right() / m_frameSize.width()
- : source.left() / m_frameSize.width();
- const GLfloat txRight = m_mirrored ? source.left() / m_frameSize.width()
- : source.right() / m_frameSize.width();
- const GLfloat txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
- ? source.top() / m_frameSize.height()
- : source.bottom() / m_frameSize.height();
- const GLfloat txBottom = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
- ? source.bottom() / m_frameSize.height()
- : source.top() / m_frameSize.height();
-
- const GLfloat textureCoordArray[] =
- {
- txLeft , txBottom,
- txRight, txBottom,
- txLeft , txTop,
- txRight, txTop
- };
-
- m_program.bind();
-
- m_program.enableAttributeArray("vertexCoordArray");
- m_program.enableAttributeArray("textureCoordArray");
- m_program.setAttributeArray("vertexCoordArray", vertexCoordArray, 2);
- m_program.setAttributeArray("textureCoordArray", textureCoordArray, 2);
- m_program.setUniformValue("positionMatrix", positionMatrix);
-
- if (m_textureCount == 3) {
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, m_textureIds[0]);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, m_textureIds[1]);
- glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, m_textureIds[2]);
- glActiveTexture(GL_TEXTURE0);
-
- m_program.setUniformValue("texY", 0);
- m_program.setUniformValue("texU", 1);
- m_program.setUniformValue("texV", 2);
- } else {
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, m_textureIds[0]);
-
- m_program.setUniformValue("texRgb", 0);
- }
- m_program.setUniformValue("colorMatrix", m_colorMatrix);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- m_program.release();
-
- painter->endNativePainting();
-
- return QAbstractVideoSurface::NoError;
- }
-
- return QVideoSurfaceGLPainter::paint(target, painter, source);
-}
-
-#endif
-
-/*!
- \class QPainterVideoSurface
- \internal
-*/
-
-/*!
-*/
-QPainterVideoSurface::QPainterVideoSurface(QObject *parent)
- : QAbstractVideoSurface(parent)
- , m_painter(0)
-#if QT_CONFIG(opengl)
- , m_glContext(0)
- , m_shaderTypes(NoShaders)
- , m_shaderType(NoShaders)
-#endif
- , m_brightness(0)
- , m_contrast(0)
- , m_hue(0)
- , m_saturation(0)
- , m_pixelFormat(QVideoFrame::Format_Invalid)
- , m_colorsDirty(true)
- , m_ready(false)
-{
-}
-
-/*!
-*/
-QPainterVideoSurface::~QPainterVideoSurface()
-{
- if (isActive())
- m_painter->stop();
-
- delete m_painter;
-}
-
-/*!
-*/
-QList<QVideoFrame::PixelFormat> QPainterVideoSurface::supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const
-{
- if (!m_painter)
- const_cast<QPainterVideoSurface *>(this)->createPainter();
-
- return m_painter->supportedPixelFormats(handleType);
-}
-
-/*!
-*/
-bool QPainterVideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const
-{
- if (!m_painter)
- const_cast<QPainterVideoSurface *>(this)->createPainter();
-
- return m_painter->isFormatSupported(format);
-}
-
-/*!
-*/
-bool QPainterVideoSurface::start(const QVideoSurfaceFormat &format)
-{
- if (isActive())
- m_painter->stop();
-
- if (!m_painter)
- createPainter();
-
- if (format.frameSize().isEmpty()) {
- setError(UnsupportedFormatError);
- } else {
- QAbstractVideoSurface::Error error = m_painter->start(format);
-
- if (error != QAbstractVideoSurface::NoError) {
- setError(error);
- } else {
- m_pixelFormat = format.pixelFormat();
- m_frameSize = format.frameSize();
- m_sourceRect = format.viewport();
- m_colorsDirty = true;
- m_ready = true;
-
- return QAbstractVideoSurface::start(format);
- }
- }
-
- QAbstractVideoSurface::stop();
-
- return false;
-}
-
-/*!
-*/
-void QPainterVideoSurface::stop()
-{
- if (isActive()) {
- m_painter->stop();
- m_ready = false;
-
- QAbstractVideoSurface::stop();
- }
-}
-
-/*!
-*/
-bool QPainterVideoSurface::present(const QVideoFrame &frame)
-{
- if (!m_ready) {
- if (!isActive()) {
- setError(StoppedError);
- return false;
- }
- } else if (frame.isValid()
- && (frame.pixelFormat() != m_pixelFormat || frame.size() != m_frameSize)) {
- setError(IncorrectFormatError);
-
- stop();
- return false;
- } else {
- QAbstractVideoSurface::Error error = m_painter->setCurrentFrame(frame);
- if (error != QAbstractVideoSurface::NoError) {
- setError(error);
- stop();
- return false;
- }
-
- m_ready = false;
- emit frameChanged();
- }
- return true;
-}
-
-/*!
-*/
-int QPainterVideoSurface::brightness() const
-{
- return m_brightness;
-}
-
-/*!
-*/
-void QPainterVideoSurface::setBrightness(int brightness)
-{
- m_brightness = brightness;
-
- m_colorsDirty = true;
-}
-
-/*!
-*/
-int QPainterVideoSurface::contrast() const
-{
- return m_contrast;
-}
-
-/*!
-*/
-void QPainterVideoSurface::setContrast(int contrast)
-{
- m_contrast = contrast;
-
- m_colorsDirty = true;
-}
-
-/*!
-*/
-int QPainterVideoSurface::hue() const
-{
- return m_hue;
-}
-
-/*!
-*/
-void QPainterVideoSurface::setHue(int hue)
-{
- m_hue = hue;
-
- m_colorsDirty = true;
-}
-
-/*!
-*/
-int QPainterVideoSurface::saturation() const
-{
- return m_saturation;
-}
-
-/*!
-*/
-void QPainterVideoSurface::setSaturation(int saturation)
-{
- m_saturation = saturation;
-
- m_colorsDirty = true;
-}
-
-/*!
-*/
-bool QPainterVideoSurface::isReady() const
-{
- return m_ready;
-}
-
-/*!
-*/
-void QPainterVideoSurface::setReady(bool ready)
-{
- m_ready = ready;
-}
-
-/*!
-*/
-void QPainterVideoSurface::paint(QPainter *painter, const QRectF &target, const QRectF &source)
-{
- if (!isActive()) {
- painter->fillRect(target, QBrush(Qt::black));
- } else {
- if (m_colorsDirty) {
- m_painter->updateColors(m_brightness, m_contrast, m_hue, m_saturation);
- m_colorsDirty = false;
- }
-
- const QRectF sourceRect(
- m_sourceRect.x() + m_sourceRect.width() * source.x(),
- m_sourceRect.y() + m_sourceRect.height() * source.y(),
- m_sourceRect.width() * source.width(),
- m_sourceRect.height() * source.height());
-
- QAbstractVideoSurface::Error error = m_painter->paint(target, painter, sourceRect);
-
- if (error != QAbstractVideoSurface::NoError) {
- setError(error);
-
- stop();
- }
- }
-}
-
-/*!
- \fn QPainterVideoSurface::frameChanged()
-*/
-
-#if QT_CONFIG(opengl)
-
-/*!
-*/
-const QOpenGLContext *QPainterVideoSurface::glContext() const
-{
- return m_glContext;
-}
-
-/*!
-*/
-void QPainterVideoSurface::updateGLContext()
-{
- auto oldContext = m_glContext;
- m_glContext = QOpenGLContext::currentContext();
- if (oldContext == m_glContext)
- return;
-
- m_shaderTypes = NoShaders;
-
- if (m_glContext) {
- //Set a dynamic property to access the OpenGL context
- this->setProperty("GLContext", QVariant::fromValue<QObject *>(m_glContext));
-
- const QByteArray extensions(reinterpret_cast<const char *>(
- m_glContext->functions()->glGetString(GL_EXTENSIONS)));
-#if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC)
- if (extensions.contains("ARB_fragment_program"))
- m_shaderTypes |= FragmentProgramShader;
-#endif
- if (QOpenGLShaderProgram::hasOpenGLShaderPrograms(m_glContext)
-#if !defined(QT_OPENGL_ES_2) && !defined(QT_OPENGL_DYNAMIC)
- && extensions.contains("ARB_shader_objects")
-#endif
- )
- m_shaderTypes |= GlslShader;
- }
-
- ShaderType type = (m_shaderType & m_shaderTypes)
- ? m_shaderType
- : NoShaders;
-
- if (type != m_shaderType || type != NoShaders) {
- m_shaderType = type;
-
- if (isActive()) {
- m_painter->stop();
- delete m_painter;
- m_painter = 0;
- m_ready = false;
-
- setError(ResourceError);
- QAbstractVideoSurface::stop();
- }
- emit supportedFormatsChanged();
- }
-}
-
-/*!
- \enum QPainterVideoSurface::ShaderType
-
- \value NoShaders
- \value FragmentProgramShader
- \value HlslShader
-*/
-
-/*!
- \typedef QPainterVideoSurface::ShaderTypes
-*/
-
-/*!
-*/
-QPainterVideoSurface::ShaderTypes QPainterVideoSurface::supportedShaderTypes() const
-{
- return m_shaderTypes;
-}
-
-/*!
-*/
-QPainterVideoSurface::ShaderType QPainterVideoSurface::shaderType() const
-{
- return m_shaderType;
-}
-
-/*!
-*/
-void QPainterVideoSurface::setShaderType(ShaderType type)
-{
- if (!(type & m_shaderTypes))
- type = NoShaders;
-
- if (type != m_shaderType) {
- m_shaderType = type;
-
- if (isActive()) {
- m_painter->stop();
- delete m_painter;
- m_painter = 0;
- m_ready = false;
-
- setError(ResourceError);
- QAbstractVideoSurface::stop();
- } else {
- delete m_painter;
- m_painter = 0;
- }
- emit supportedFormatsChanged();
- }
-}
-
-#endif
-
-void QPainterVideoSurface::viewportDestroyed()
-{
- if (m_painter) {
- m_painter->viewportDestroyed();
-
- setError(ResourceError);
- stop();
- delete m_painter;
- m_painter = 0;
- }
-}
-
-void QPainterVideoSurface::createPainter()
-{
- Q_ASSERT(!m_painter);
-
-#if QT_CONFIG(opengl)
- switch (m_shaderType) {
-#if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC)
- case FragmentProgramShader:
- Q_ASSERT(m_glContext);
- m_painter = new QVideoSurfaceArbFpPainter(m_glContext);
- break;
-#endif // !QT_OPENGL_ES && !QT_OPENGL_DYNAMIC
- case GlslShader:
- Q_ASSERT(m_glContext);
- m_painter = new QVideoSurfaceGlslPainter(m_glContext);
- break;
- default:
- m_painter = new QVideoSurfaceGenericPainter;
- break;
- }
-#else
- m_painter = new QVideoSurfaceGenericPainter;
-#endif
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qpaintervideosurface_p.cpp"
diff --git a/src/multimediawidgets/qpaintervideosurface_p.h b/src/multimediawidgets/qpaintervideosurface_p.h
deleted file mode 100644
index 582d6944c..000000000
--- a/src/multimediawidgets/qpaintervideosurface_p.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QPAINTERVIDEOSURFACE_P_H
-#define QPAINTERVIDEOSURFACE_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <qtmultimediawidgetdefs.h>
-#include <QtCore/qsize.h>
-#include <QtGui/qimage.h>
-#include <QtGui/qmatrix4x4.h>
-#include <QtGui/qpaintengine.h>
-#include <qabstractvideosurface.h>
-#include <qvideoframe.h>
-
-QT_USE_NAMESPACE
-
-QT_BEGIN_NAMESPACE
-
-class Q_AUTOTEST_EXPORT QVideoSurfacePainter
-{
-public:
- virtual ~QVideoSurfacePainter();
-
- virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const = 0;
-
- virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const = 0;
-
- virtual QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) = 0;
- virtual void stop() = 0;
-
- virtual QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame) = 0;
-
- virtual QAbstractVideoSurface::Error paint(
- const QRectF &target, QPainter *painter, const QRectF &source) = 0;
-
- virtual void updateColors(int brightness, int contrast, int hue, int saturation) = 0;
- virtual void viewportDestroyed() {}
-};
-
-class QOpenGLContext;
-class Q_AUTOTEST_EXPORT QPainterVideoSurface : public QAbstractVideoSurface
-{
- Q_OBJECT
-public:
- explicit QPainterVideoSurface(QObject *parent = 0);
- ~QPainterVideoSurface();
-
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const override;
-
- bool isFormatSupported(const QVideoSurfaceFormat &format) const override;
-
- bool start(const QVideoSurfaceFormat &format) override;
- void stop() override;
-
- bool present(const QVideoFrame &frame) override;
-
- int brightness() const;
- void setBrightness(int brightness);
-
- int contrast() const;
- void setContrast(int contrast);
-
- int hue() const;
- void setHue(int hue);
-
- int saturation() const;
- void setSaturation(int saturation);
-
- bool isReady() const;
- void setReady(bool ready);
-
- void paint(QPainter *painter, const QRectF &target, const QRectF &source = QRectF(0, 0, 1, 1));
-
-#if QT_CONFIG(opengl)
- const QOpenGLContext *glContext() const;
- void updateGLContext();
-
- enum ShaderType
- {
- NoShaders = 0x00,
- FragmentProgramShader = 0x01,
- GlslShader = 0x02
- };
-
- Q_DECLARE_FLAGS(ShaderTypes, ShaderType)
-
- ShaderTypes supportedShaderTypes() const;
-
- ShaderType shaderType() const;
- void setShaderType(ShaderType type);
-#endif
-
-public Q_SLOTS:
- void viewportDestroyed();
-
-Q_SIGNALS:
- void frameChanged();
-
-private:
- void createPainter();
-
- QVideoSurfacePainter *m_painter;
-#if QT_CONFIG(opengl)
- QOpenGLContext *m_glContext;
- ShaderTypes m_shaderTypes;
- ShaderType m_shaderType;
-#endif
- int m_brightness;
- int m_contrast;
- int m_hue;
- int m_saturation;
-
- QVideoFrame::PixelFormat m_pixelFormat;
- QSize m_frameSize;
- QRect m_sourceRect;
- bool m_colorsDirty;
- bool m_ready;
-};
-
-#if QT_CONFIG(opengl)
-Q_DECLARE_OPERATORS_FOR_FLAGS(QPainterVideoSurface::ShaderTypes)
-#endif
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/multimediawidgets/qtmultimediawidgetdefs.h b/src/multimediawidgets/qtmultimediawidgetdefs.h
deleted file mode 100644
index d41abd689..000000000
--- a/src/multimediawidgets/qtmultimediawidgetdefs.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifndef QTMULTIMEDIAWIDGETS_P_H
-#define QTMULTIMEDIAWIDGETS_P_H
-
-#include <QtCore/qglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_STATIC
-# if defined(QT_BUILD_MULTIMEDIAWIDGETS_LIB)
-# define Q_MULTIMEDIAWIDGETS_EXPORT Q_DECL_EXPORT
-# else
-# define Q_MULTIMEDIAWIDGETS_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define Q_MULTIMEDIAWIDGETS_EXPORT
-#endif
-
-QT_END_NAMESPACE
-
-#endif // QMULTIMEDIAWIDGETS_P_H
-
diff --git a/src/multimediawidgets/qtmultimediawidgetsglobal.h b/src/multimediawidgets/qtmultimediawidgetsglobal.h
new file mode 100644
index 000000000..b7091ea40
--- /dev/null
+++ b/src/multimediawidgets/qtmultimediawidgetsglobal.h
@@ -0,0 +1,9 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QTMULTIMEDIAWIDGETSGLOBAL_H
+#define QTMULTIMEDIAWIDGETSGLOBAL_H
+
+#include <QtMultimediaWidgets/qtmultimediawidgetsexports.h>
+
+#endif // QTMULTIMEDIAWIDGETSGLOBAL_H
diff --git a/src/multimediawidgets/qvideowidget.cpp b/src/multimediawidgets/qvideowidget.cpp
index bab1ffbff..1b8c41980 100644
--- a/src/multimediawidgets/qvideowidget.cpp
+++ b/src/multimediawidgets/qvideowidget.cpp
@@ -1,52 +1,16 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include <private/qtmultimediaglobal_p.h>
#include "qvideowidget_p.h"
-#include "qpaintervideosurface_p.h"
-#include <qmediaobject.h>
-#include <qmediaservice.h>
-#include <qvideowindowcontrol.h>
-#include <qvideowidgetcontrol.h>
+#include <QtCore/qobject.h>
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <qvideosink.h>
+#include <private/qvideowindow_p.h>
-#include <qvideorenderercontrol.h>
-#include <qvideosurfaceformat.h>
+#include <qobject.h>
+#include <qvideoframeformat.h>
#include <qpainter.h>
#include <qapplication.h>
@@ -65,528 +29,6 @@ using namespace Qt;
QT_BEGIN_NAMESPACE
-QVideoWidgetControlBackend::QVideoWidgetControlBackend(
- QMediaService *service, QVideoWidgetControl *control, QWidget *widget)
- : m_service(service)
- , m_widgetControl(control)
-{
- connect(control, SIGNAL(brightnessChanged(int)), widget, SLOT(_q_brightnessChanged(int)));
- connect(control, SIGNAL(contrastChanged(int)), widget, SLOT(_q_contrastChanged(int)));
- connect(control, SIGNAL(hueChanged(int)), widget, SLOT(_q_hueChanged(int)));
- connect(control, SIGNAL(saturationChanged(int)), widget, SLOT(_q_saturationChanged(int)));
- connect(control, SIGNAL(fullScreenChanged(bool)), widget, SLOT(_q_fullScreenChanged(bool)));
-
- QBoxLayout *layout = new QVBoxLayout;
- layout->setContentsMargins(0, 0, 0, 0);
- layout->setSpacing(0);
-
- QWidget *videoWidget = control->videoWidget();
- videoWidget->setMouseTracking(widget->hasMouseTracking());
- layout->addWidget(videoWidget);
-
- widget->setLayout(layout);
-}
-
-void QVideoWidgetControlBackend::releaseControl()
-{
- m_service->releaseControl(m_widgetControl);
-}
-
-void QVideoWidgetControlBackend::setBrightness(int brightness)
-{
- m_widgetControl->setBrightness(brightness);
-}
-
-void QVideoWidgetControlBackend::setContrast(int contrast)
-{
- m_widgetControl->setContrast(contrast);
-}
-
-void QVideoWidgetControlBackend::setHue(int hue)
-{
- m_widgetControl->setHue(hue);
-}
-
-void QVideoWidgetControlBackend::setSaturation(int saturation)
-{
- m_widgetControl->setSaturation(saturation);
-}
-
-void QVideoWidgetControlBackend::setFullScreen(bool fullScreen)
-{
- m_widgetControl->setFullScreen(fullScreen);
-}
-
-
-Qt::AspectRatioMode QVideoWidgetControlBackend::aspectRatioMode() const
-{
- return m_widgetControl->aspectRatioMode();
-}
-
-void QVideoWidgetControlBackend::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- m_widgetControl->setAspectRatioMode(mode);
-}
-
-QRendererVideoWidgetBackend::QRendererVideoWidgetBackend(
- QMediaService *service, QVideoRendererControl *control, QWidget *widget)
- : m_service(service)
- , m_rendererControl(control)
- , m_widget(widget)
- , m_surface(new QPainterVideoSurface)
- , m_aspectRatioMode(Qt::KeepAspectRatio)
- , m_updatePaintDevice(true)
-{
- connect(this, SIGNAL(brightnessChanged(int)), m_widget, SLOT(_q_brightnessChanged(int)));
- connect(this, SIGNAL(contrastChanged(int)), m_widget, SLOT(_q_contrastChanged(int)));
- connect(this, SIGNAL(hueChanged(int)), m_widget, SLOT(_q_hueChanged(int)));
- connect(this, SIGNAL(saturationChanged(int)), m_widget, SLOT(_q_saturationChanged(int)));
- connect(m_surface, SIGNAL(frameChanged()), this, SLOT(frameChanged()));
- connect(m_surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)),
- this, SLOT(formatChanged(QVideoSurfaceFormat)));
-
- if (m_rendererControl)
- m_rendererControl->setSurface(m_surface);
-}
-
-QRendererVideoWidgetBackend::~QRendererVideoWidgetBackend()
-{
- delete m_surface;
-}
-
-QAbstractVideoSurface *QRendererVideoWidgetBackend::videoSurface() const
-{
- return m_surface;
-}
-
-void QRendererVideoWidgetBackend::releaseControl()
-{
- if (m_service && m_rendererControl)
- m_service->releaseControl(m_rendererControl);
-}
-
-void QRendererVideoWidgetBackend::clearSurface()
-{
- if (m_rendererControl)
- m_rendererControl->setSurface(0);
-}
-
-void QRendererVideoWidgetBackend::setBrightness(int brightness)
-{
- m_surface->setBrightness(brightness);
-
- emit brightnessChanged(brightness);
-}
-
-void QRendererVideoWidgetBackend::setContrast(int contrast)
-{
- m_surface->setContrast(contrast);
-
- emit contrastChanged(contrast);
-}
-
-void QRendererVideoWidgetBackend::setHue(int hue)
-{
- m_surface->setHue(hue);
-
- emit hueChanged(hue);
-}
-
-void QRendererVideoWidgetBackend::setSaturation(int saturation)
-{
- m_surface->setSaturation(saturation);
-
- emit saturationChanged(saturation);
-}
-
-Qt::AspectRatioMode QRendererVideoWidgetBackend::aspectRatioMode() const
-{
- return m_aspectRatioMode;
-}
-
-void QRendererVideoWidgetBackend::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- m_aspectRatioMode = mode;
-
- m_widget->updateGeometry();
-}
-
-void QRendererVideoWidgetBackend::setFullScreen(bool)
-{
-}
-
-QSize QRendererVideoWidgetBackend::sizeHint() const
-{
- return m_surface->surfaceFormat().sizeHint();
-}
-
-void QRendererVideoWidgetBackend::showEvent()
-{
-}
-
-void QRendererVideoWidgetBackend::hideEvent(QHideEvent *)
-{
-#if QT_CONFIG(opengl)
- m_updatePaintDevice = true;
-#endif
-}
-
-void QRendererVideoWidgetBackend::resizeEvent(QResizeEvent *)
-{
- updateRects();
-}
-
-void QRendererVideoWidgetBackend::moveEvent(QMoveEvent *)
-{
-}
-
-void QRendererVideoWidgetBackend::paintEvent(QPaintEvent *event)
-{
- QPainter painter(m_widget);
-
- if (m_widget->testAttribute(Qt::WA_OpaquePaintEvent)) {
- QRegion borderRegion = event->region();
- borderRegion = borderRegion.subtracted(m_boundingRect);
-
- QBrush brush = m_widget->palette().window();
-
- for (const QRect &r : borderRegion)
- painter.fillRect(r, brush);
- }
-
- if (m_surface->isActive() && m_boundingRect.intersects(event->rect())) {
- m_surface->paint(&painter, m_boundingRect, m_sourceRect);
-
- m_surface->setReady(true);
- } else {
-#if QT_CONFIG(opengl)
- if (m_updatePaintDevice && (painter.paintEngine()->type() == QPaintEngine::OpenGL
- || painter.paintEngine()->type() == QPaintEngine::OpenGL2)) {
- m_updatePaintDevice = false;
-
- m_surface->updateGLContext();
- if (m_surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) {
- m_surface->setShaderType(QPainterVideoSurface::GlslShader);
- } else {
- m_surface->setShaderType(QPainterVideoSurface::FragmentProgramShader);
- }
- }
-#endif
- }
-
-}
-
-void QRendererVideoWidgetBackend::formatChanged(const QVideoSurfaceFormat &format)
-{
- m_nativeSize = format.sizeHint();
-
- updateRects();
-
- m_widget->updateGeometry();
- m_widget->update();
-}
-
-void QRendererVideoWidgetBackend::frameChanged()
-{
- m_widget->update(m_boundingRect);
-}
-
-void QRendererVideoWidgetBackend::updateRects()
-{
- QRect rect = m_widget->rect();
-
- if (m_nativeSize.isEmpty()) {
- m_boundingRect = QRect();
- } else if (m_aspectRatioMode == Qt::IgnoreAspectRatio) {
- m_boundingRect = rect;
- m_sourceRect = QRectF(0, 0, 1, 1);
- } else if (m_aspectRatioMode == Qt::KeepAspectRatio) {
- QSize size = m_nativeSize;
- size.scale(rect.size(), Qt::KeepAspectRatio);
-
- m_boundingRect = QRect(0, 0, size.width(), size.height());
- m_boundingRect.moveCenter(rect.center());
-
- m_sourceRect = QRectF(0, 0, 1, 1);
- } else if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
- m_boundingRect = rect;
-
- QSizeF size = rect.size();
- size.scale(m_nativeSize, Qt::KeepAspectRatio);
-
- m_sourceRect = QRectF(
- 0, 0, size.width() / m_nativeSize.width(), size.height() / m_nativeSize.height());
- m_sourceRect.moveCenter(QPointF(0.5, 0.5));
- }
-}
-
-QWindowVideoWidgetBackend::QWindowVideoWidgetBackend(
- QMediaService *service, QVideoWindowControl *control, QWidget *widget)
- : m_service(service)
- , m_windowControl(control)
- , m_widget(widget)
-{
- connect(control, SIGNAL(brightnessChanged(int)), m_widget, SLOT(_q_brightnessChanged(int)));
- connect(control, SIGNAL(contrastChanged(int)), m_widget, SLOT(_q_contrastChanged(int)));
- connect(control, SIGNAL(hueChanged(int)), m_widget, SLOT(_q_hueChanged(int)));
- connect(control, SIGNAL(saturationChanged(int)), m_widget, SLOT(_q_saturationChanged(int)));
- connect(control, SIGNAL(fullScreenChanged(bool)), m_widget, SLOT(_q_fullScreenChanged(bool)));
- connect(control, SIGNAL(nativeSizeChanged()), m_widget, SLOT(_q_dimensionsChanged()));
-
- control->setWinId(widget->winId());
-#if defined(Q_OS_WIN)
- // Disable updates to avoid flickering while resizing/moving.
- m_widget->setUpdatesEnabled(false);
-#endif
-}
-
-QWindowVideoWidgetBackend::~QWindowVideoWidgetBackend()
-{
-}
-
-void QWindowVideoWidgetBackend::releaseControl()
-{
- m_service->releaseControl(m_windowControl);
-}
-
-void QWindowVideoWidgetBackend::setBrightness(int brightness)
-{
- m_windowControl->setBrightness(brightness);
-}
-
-void QWindowVideoWidgetBackend::setContrast(int contrast)
-{
- m_windowControl->setContrast(contrast);
-}
-
-void QWindowVideoWidgetBackend::setHue(int hue)
-{
- m_windowControl->setHue(hue);
-}
-
-void QWindowVideoWidgetBackend::setSaturation(int saturation)
-{
- m_windowControl->setSaturation(saturation);
-}
-
-void QWindowVideoWidgetBackend::setFullScreen(bool fullScreen)
-{
- m_windowControl->setFullScreen(fullScreen);
-}
-
-Qt::AspectRatioMode QWindowVideoWidgetBackend::aspectRatioMode() const
-{
- return m_windowControl->aspectRatioMode();
-}
-
-void QWindowVideoWidgetBackend::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- m_windowControl->setAspectRatioMode(mode);
-}
-
-QSize QWindowVideoWidgetBackend::sizeHint() const
-{
- return m_windowControl->nativeSize();
-}
-
-void QWindowVideoWidgetBackend::updateDisplayRect()
-{
- QRect rect = m_widget->rect();
- if (QHighDpiScaling::isActive()) {
- const qreal factor = QHighDpiScaling::factor(m_widget->windowHandle());
- if (!qFuzzyCompare(factor, qreal(1))) {
- rect = QRectF(QPointF(rect.topLeft()) * factor,
- QSizeF(rect.size()) * factor).toRect();
- }
- }
- m_windowControl->setDisplayRect(rect);
-}
-
-void QWindowVideoWidgetBackend::showEvent()
-{
- m_windowControl->setWinId(m_widget->winId());
- updateDisplayRect();
-
-#if defined(Q_OS_WIN)
- m_windowControl->repaint();
-#endif
-}
-
-void QWindowVideoWidgetBackend::hideEvent(QHideEvent *)
-{
-}
-
-void QWindowVideoWidgetBackend::moveEvent(QMoveEvent *)
-{
- updateDisplayRect();
-}
-
-void QWindowVideoWidgetBackend::resizeEvent(QResizeEvent *)
-{
- updateDisplayRect();
-}
-
-void QWindowVideoWidgetBackend::paintEvent(QPaintEvent *event)
-{
- if (m_widget->testAttribute(Qt::WA_OpaquePaintEvent)) {
- QPainter painter(m_widget);
-
- painter.fillRect(event->rect(), m_widget->palette().window());
- }
-
- m_windowControl->repaint();
-
- event->accept();
-}
-
-void QVideoWidgetPrivate::setCurrentControl(QVideoWidgetControlInterface *control)
-{
- if (currentControl != control) {
- currentControl = control;
-
- currentControl->setBrightness(brightness);
- currentControl->setContrast(contrast);
- currentControl->setHue(hue);
- currentControl->setSaturation(saturation);
- currentControl->setAspectRatioMode(aspectRatioMode);
- }
-}
-
-void QVideoWidgetPrivate::clearService()
-{
- if (service) {
- QObject::disconnect(service, SIGNAL(destroyed()), q_func(), SLOT(_q_serviceDestroyed()));
-
- if (widgetBackend) {
- QLayout *layout = q_func()->layout();
-
- for (QLayoutItem *item = layout->takeAt(0); item; item = layout->takeAt(0)) {
- item->widget()->setParent(0);
- delete item;
- }
- delete layout;
-
- widgetBackend->releaseControl();
-
- delete widgetBackend;
- widgetBackend = 0;
- } else if (rendererBackend) {
- rendererBackend->clearSurface();
- rendererBackend->releaseControl();
-
- delete rendererBackend;
- rendererBackend = 0;
- } else if (windowBackend) {
- windowBackend->releaseControl();
-
- delete windowBackend;
- windowBackend = 0;
- }
-
- currentBackend = 0;
- currentControl = 0;
- service = 0;
- }
-}
-
-bool QVideoWidgetPrivate::createWidgetBackend()
-{
- if (QMediaControl *control = service->requestControl(QVideoWidgetControl_iid)) {
- if (QVideoWidgetControl *widgetControl = qobject_cast<QVideoWidgetControl *>(control)) {
- widgetBackend = new QVideoWidgetControlBackend(service, widgetControl, q_func());
-
- setCurrentControl(widgetBackend);
-
- return true;
- }
- service->releaseControl(control);
- }
- return false;
-}
-
-bool QVideoWidgetPrivate::createWindowBackend()
-{
- if (QMediaControl *control = service->requestControl(QVideoWindowControl_iid)) {
- if (QVideoWindowControl *windowControl = qobject_cast<QVideoWindowControl *>(control)) {
- windowBackend = new QWindowVideoWidgetBackend(service, windowControl, q_func());
- currentBackend = windowBackend;
-
- setCurrentControl(windowBackend);
-
- return true;
- }
- service->releaseControl(control);
- }
- return false;
-}
-
-bool QVideoWidgetPrivate::createRendererBackend()
-{
- QMediaControl *control = service
- ? service->requestControl(QVideoRendererControl_iid)
- : nullptr;
- rendererBackend = new QRendererVideoWidgetBackend(service,
- qobject_cast<QVideoRendererControl *>(control), q_func());
- currentBackend = rendererBackend;
- setCurrentControl(rendererBackend);
-
- return !service || (service && control);
-}
-
-void QVideoWidgetPrivate::_q_serviceDestroyed()
-{
- if (widgetBackend)
- delete q_func()->layout();
-
- delete widgetBackend;
- delete windowBackend;
- delete rendererBackend;
-
- widgetBackend = 0;
- windowBackend = 0;
- rendererBackend = 0;
- currentControl = 0;
- currentBackend = 0;
- service = 0;
-}
-
-void QVideoWidgetPrivate::_q_brightnessChanged(int b)
-{
- if (b != brightness)
- emit q_func()->brightnessChanged(brightness = b);
-}
-
-void QVideoWidgetPrivate::_q_contrastChanged(int c)
-{
- if (c != contrast)
- emit q_func()->contrastChanged(contrast = c);
-}
-
-void QVideoWidgetPrivate::_q_hueChanged(int h)
-{
- if (h != hue)
- emit q_func()->hueChanged(hue = h);
-}
-
-void QVideoWidgetPrivate::_q_saturationChanged(int s)
-{
- if (s != saturation)
- emit q_func()->saturationChanged(saturation = s);
-}
-
-
-void QVideoWidgetPrivate::_q_fullScreenChanged(bool fullScreen)
-{
- if (!fullScreen && q_func()->isFullScreen())
- q_func()->showNormal();
-}
-
-void QVideoWidgetPrivate::_q_dimensionsChanged()
-{
- q_func()->updateGeometry();
- q_func()->update();
-}
-
/*!
\class QVideoWidget
@@ -594,21 +36,23 @@ void QVideoWidgetPrivate::_q_dimensionsChanged()
\brief The QVideoWidget class provides a widget which presents video
produced by a media object.
\ingroup multimedia
+ \ingroup multimedia_video
\inmodule QtMultimediaWidgets
- Attaching a QVideoWidget to a QMediaObject allows it to display the
- video or image output of that media object. A QVideoWidget is attached
- to media object by passing a pointer to the QMediaObject in its
- constructor, and detached by destroying the QVideoWidget.
+ Attaching a QVideoWidget to a QMediaPlayer or QCamera allows it to display the
+ video or image output of that object.
\snippet multimedia-snippets/video.cpp Video widget
\b {Note}: Only a single display output can be attached to a media
object at one time.
- \sa QMediaObject, QMediaPlayer, QGraphicsVideoItem
+ \sa QCamera, QMediaPlayer, QGraphicsVideoItem
+*/
+/*!
+ \variable QVideoWidget::d_ptr
+ \internal
*/
-
/*!
Constructs a new video widget.
@@ -619,20 +63,13 @@ QVideoWidget::QVideoWidget(QWidget *parent)
, d_ptr(new QVideoWidgetPrivate)
{
d_ptr->q_ptr = this;
-}
-
-/*!
- \internal
-*/
-QVideoWidget::QVideoWidget(QVideoWidgetPrivate &dd, QWidget *parent)
- : QWidget(parent, {})
- , d_ptr(&dd)
-{
- d_ptr->q_ptr = this;
+ d_ptr->videoWindow = new QVideoWindow;
+ d_ptr->videoWindow->setFlag(Qt::WindowTransparentForInput, true);
+ d_ptr->windowContainer = QWidget::createWindowContainer(d_ptr->videoWindow, this, Qt::WindowTransparentForInput);
+ d_ptr->windowContainer->move(0, 0);
+ d_ptr->windowContainer->resize(size());
- QPalette palette = QWidget::palette();
- palette.setColor(QPalette::Window, Qt::black);
- setPalette(palette);
+ connect(d_ptr->videoWindow, &QVideoWindow::aspectRatioModeChanged, this, &QVideoWidget::aspectRatioModeChanged);
}
/*!
@@ -640,86 +77,16 @@ QVideoWidget::QVideoWidget(QVideoWidgetPrivate &dd, QWidget *parent)
*/
QVideoWidget::~QVideoWidget()
{
- d_ptr->clearService();
-
+ delete d_ptr->videoWindow;
delete d_ptr;
}
/*!
- \property QVideoWidget::mediaObject
- \brief the media object which provides the video displayed by a widget.
+ Returns the QVideoSink instance.
*/
-
-QMediaObject *QVideoWidget::mediaObject() const
-{
- return d_func()->mediaObject;
-}
-
-/*!
- \internal
-*/
-bool QVideoWidget::setMediaObject(QMediaObject *object)
-{
- Q_D(QVideoWidget);
-
- if (object == d->mediaObject)
- return true;
-
- d->clearService();
-
- d->mediaObject = object;
-
- if (d->mediaObject)
- d->service = d->mediaObject->service();
-
- if (d->service) {
- if (d->createWidgetBackend()) {
- // Nothing to do here.
- } else if ((!window() || !window()->testAttribute(Qt::WA_DontShowOnScreen))
- && d->createWindowBackend()) {
- if (isVisible())
- d->windowBackend->showEvent();
- } else if (d->createRendererBackend()) {
- if (isVisible())
- d->rendererBackend->showEvent();
- } else {
- d->service = 0;
- d->mediaObject = 0;
-
- return false;
- }
-
- connect(d->service, SIGNAL(destroyed()), SLOT(_q_serviceDestroyed()));
- } else {
- d->mediaObject = 0;
-
- return false;
- }
-
- return true;
-}
-
-/*!
- \since 5.15
- \property QVideoWidget::videoSurface
- \brief Returns the underlaying video surface that can render video frames
- to the current widget.
- This property is never \c nullptr.
- Example of how to render video frames to QVideoWidget:
- \snippet multimedia-snippets/video.cpp Widget Surface
- \sa QMediaPlayer::setVideoOutput
-*/
-
-QAbstractVideoSurface *QVideoWidget::videoSurface() const
+QVideoSink *QVideoWidget::videoSink() const
{
- auto d = const_cast<QVideoWidgetPrivate *>(d_func());
-
- if (!d->rendererBackend) {
- d->clearService();
- d->createRendererBackend();
- }
-
- return d->rendererBackend->videoSurface();
+ return d_ptr->videoWindow->videoSink();
}
/*!
@@ -729,19 +96,12 @@ QAbstractVideoSurface *QVideoWidget::videoSurface() const
Qt::AspectRatioMode QVideoWidget::aspectRatioMode() const
{
- return d_func()->aspectRatioMode;
+ return d_ptr->videoWindow->aspectRatioMode();
}
void QVideoWidget::setAspectRatioMode(Qt::AspectRatioMode mode)
{
- Q_D(QVideoWidget);
-
- if (d->currentControl) {
- d->currentControl->setAspectRatioMode(mode);
- d->aspectRatioMode = d->currentControl->aspectRatioMode();
- } else {
- d->aspectRatioMode = mode;
- }
+ d_ptr->videoWindow->setAspectRatioMode(mode);
}
/*!
@@ -752,14 +112,22 @@ void QVideoWidget::setAspectRatioMode(Qt::AspectRatioMode mode)
void QVideoWidget::setFullScreen(bool fullScreen)
{
Q_D(QVideoWidget);
+ if (isFullScreen() == fullScreen)
+ return;
Qt::WindowFlags flags = windowFlags();
if (fullScreen) {
+ // get the position of the widget in global coordinates
+ QPoint position = mapToGlobal(QPoint(0,0));
d->nonFullScreenFlags = flags & (Qt::Window | Qt::SubWindow);
+ d_ptr->nonFullscreenPos = pos();
flags |= Qt::Window;
flags &= ~Qt::SubWindow;
setWindowFlags(flags);
+ // move the widget to the position it had on screen, so that showFullScreen() will
+ // place it on the correct screen
+ move(position);
showFullScreen();
} else {
@@ -768,187 +136,41 @@ void QVideoWidget::setFullScreen(bool fullScreen)
setWindowFlags(flags);
showNormal();
+ move(d_ptr->nonFullscreenPos);
+ d_ptr->nonFullscreenPos = {};
}
}
/*!
- \fn QVideoWidget::fullScreenChanged(bool fullScreen)
-
- Signals that the \a fullScreen mode of a video widget has changed.
-
- \sa isFullScreen()
-*/
-
-/*!
- \property QVideoWidget::brightness
- \brief an adjustment to the brightness of displayed video.
-
- Valid brightness values range between -100 and 100, the default is 0.
-*/
-
-int QVideoWidget::brightness() const
-{
- return d_func()->brightness;
-}
-
-void QVideoWidget::setBrightness(int brightness)
-{
- Q_D(QVideoWidget);
-
- int boundedBrightness = qBound(-100, brightness, 100);
-
- if (d->currentControl)
- d->currentControl->setBrightness(boundedBrightness);
- else if (d->brightness != boundedBrightness)
- emit brightnessChanged(d->brightness = boundedBrightness);
-}
-
-/*!
- \fn QVideoWidget::brightnessChanged(int brightness)
-
- Signals that a video widgets's \a brightness adjustment has changed.
-
- \sa brightness()
-*/
-
-/*!
- \property QVideoWidget::contrast
- \brief an adjustment to the contrast of displayed video.
-
- Valid contrast values range between -100 and 100, the default is 0.
-
-*/
-
-int QVideoWidget::contrast() const
-{
- return d_func()->contrast;
-}
-
-void QVideoWidget::setContrast(int contrast)
-{
- Q_D(QVideoWidget);
-
- int boundedContrast = qBound(-100, contrast, 100);
-
- if (d->currentControl)
- d->currentControl->setContrast(boundedContrast);
- else if (d->contrast != boundedContrast)
- emit contrastChanged(d->contrast = boundedContrast);
-}
-
-/*!
- \fn QVideoWidget::contrastChanged(int contrast)
-
- Signals that a video widgets's \a contrast adjustment has changed.
-
- \sa contrast()
-*/
-
-/*!
- \property QVideoWidget::hue
- \brief an adjustment to the hue of displayed video.
-
- Valid hue values range between -100 and 100, the default is 0.
-*/
-
-int QVideoWidget::hue() const
-{
- return d_func()->hue;
-}
-
-void QVideoWidget::setHue(int hue)
-{
- Q_D(QVideoWidget);
-
- int boundedHue = qBound(-100, hue, 100);
-
- if (d->currentControl)
- d->currentControl->setHue(boundedHue);
- else if (d->hue != boundedHue)
- emit hueChanged(d->hue = boundedHue);
-}
-
-/*!
- \fn QVideoWidget::hueChanged(int hue)
-
- Signals that a video widgets's \a hue has changed.
-
- \sa hue()
-*/
-
-/*!
- \property QVideoWidget::saturation
- \brief an adjustment to the saturation of displayed video.
-
- Valid saturation values range between -100 and 100, the default is 0.
-*/
-
-int QVideoWidget::saturation() const
-{
- return d_func()->saturation;
-}
-
-void QVideoWidget::setSaturation(int saturation)
-{
- Q_D(QVideoWidget);
-
- int boundedSaturation = qBound(-100, saturation, 100);
-
- if (d->currentControl)
- d->currentControl->setSaturation(boundedSaturation);
- else if (d->saturation != boundedSaturation)
- emit saturationChanged(d->saturation = boundedSaturation);
-
-}
-
-/*!
- \fn QVideoWidget::saturationChanged(int saturation)
-
- Signals that a video widgets's \a saturation has changed.
-
- \sa saturation()
-*/
-
-/*!
Returns the size hint for the current back end,
if there is one, or else the size hint from QWidget.
*/
QSize QVideoWidget::sizeHint() const
{
- Q_D(const QVideoWidget);
-
- if (d->currentBackend)
- return d->currentBackend->sizeHint();
- else
- return QWidget::sizeHint();
-
+ auto size = videoSink()->videoSize();
+ if (size.isValid())
+ return size;
+ return QWidget::sizeHint();
}
/*!
\reimp
Current event \a event.
- Returns the value of the baseclass QWidget::event(QEvent *event) function.
+ Returns the value of the base class QWidget::event(QEvent *event) function.
*/
bool QVideoWidget::event(QEvent *event)
{
Q_D(QVideoWidget);
if (event->type() == QEvent::WindowStateChange) {
- if (windowState() & Qt::WindowFullScreen) {
- if (d->currentControl)
- d->currentControl->setFullScreen(true);
-
- if (!d->wasFullScreen)
- emit fullScreenChanged(d->wasFullScreen = true);
- } else {
- if (d->currentControl)
- d->currentControl->setFullScreen(false);
-
- if (d->wasFullScreen)
- emit fullScreenChanged(d->wasFullScreen = false);
+ bool fullScreen = bool(windowState() & Qt::WindowFullScreen);
+ if (fullScreen != d->wasFullScreen) {
+ emit fullScreenChanged(fullScreen);
+ d->wasFullScreen = fullScreen;
}
}
+
return QWidget::event(event);
}
@@ -958,22 +180,7 @@ bool QVideoWidget::event(QEvent *event)
*/
void QVideoWidget::showEvent(QShowEvent *event)
{
- Q_D(QVideoWidget);
-
QWidget::showEvent(event);
-
- // The window backend won't work for re-directed windows so use the renderer backend instead.
- if (d->windowBackend && window()->testAttribute(Qt::WA_DontShowOnScreen)) {
- d->windowBackend->releaseControl();
-
- delete d->windowBackend;
- d->windowBackend = 0;
-
- d->createRendererBackend();
- }
-
- if (d->currentBackend)
- d->currentBackend->showEvent();
}
/*!
@@ -982,11 +189,6 @@ void QVideoWidget::showEvent(QShowEvent *event)
*/
void QVideoWidget::hideEvent(QHideEvent *event)
{
- Q_D(QVideoWidget);
-
- if (d->currentBackend)
- d->currentBackend->hideEvent(event);
-
QWidget::hideEvent(event);
}
@@ -996,61 +198,18 @@ void QVideoWidget::hideEvent(QHideEvent *event)
*/
void QVideoWidget::resizeEvent(QResizeEvent *event)
{
- Q_D(QVideoWidget);
-
+ d_ptr->windowContainer->resize(event->size());
QWidget::resizeEvent(event);
-
- if (d->currentBackend)
- d->currentBackend->resizeEvent(event);
}
/*!
\reimp
Handles the move \a event.
*/
-void QVideoWidget::moveEvent(QMoveEvent *event)
+void QVideoWidget::moveEvent(QMoveEvent * /*event*/)
{
- Q_D(QVideoWidget);
-
- if (d->currentBackend)
- d->currentBackend->moveEvent(event);
}
-/*!
- \reimp
- Handles the paint \a event.
- */
-void QVideoWidget::paintEvent(QPaintEvent *event)
-{
- Q_D(QVideoWidget);
-
- if (d->currentBackend) {
- d->currentBackend->paintEvent(event);
- } else if (testAttribute(Qt::WA_OpaquePaintEvent)) {
- QPainter painter(this);
-
- painter.fillRect(event->rect(), palette().window());
- }
-}
-
-#if defined(Q_OS_WIN)
-bool QVideoWidget::nativeEvent(const QByteArray &eventType, void *message, qintptr *result)
-{
- Q_D(QVideoWidget);
- Q_UNUSED(eventType);
- Q_UNUSED(result);
-
- MSG *mes = reinterpret_cast<MSG *>(message);
- if (mes->message == WM_PAINT || mes->message == WM_ERASEBKGND) {
- if (d->windowBackend)
- d->windowBackend->showEvent();
- }
-
- return false;
-}
-#endif
-
QT_END_NAMESPACE
#include "moc_qvideowidget.cpp"
-#include "moc_qvideowidget_p.cpp"
diff --git a/src/multimediawidgets/qvideowidget.h b/src/multimediawidgets/qvideowidget.h
index cabe5e840..2cd83ff47 100644
--- a/src/multimediawidgets/qvideowidget.h
+++ b/src/multimediawidgets/qvideowidget.h
@@ -1,76 +1,29 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QVIDEOWIDGET_H
#define QVIDEOWIDGET_H
#include <QtWidgets/qwidget.h>
-#include <QtMultimediaWidgets/qtmultimediawidgetdefs.h>
-#include <QtMultimedia/qmediabindableinterface.h>
+#include <QtMultimediaWidgets/qtmultimediawidgetsglobal.h>
QT_BEGIN_NAMESPACE
-
-class QMediaObject;
+class QVideoSink;
class QVideoWidgetPrivate;
-class QAbstractVideoSurface;
-class Q_MULTIMEDIAWIDGETS_EXPORT QVideoWidget : public QWidget, public QMediaBindableInterface
+class Q_MULTIMEDIAWIDGETS_EXPORT QVideoWidget : public QWidget
{
Q_OBJECT
- Q_INTERFACES(QMediaBindableInterface)
- Q_PROPERTY(QMediaObject* mediaObject READ mediaObject WRITE setMediaObject)
Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenChanged)
- Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode)
- Q_PROPERTY(int brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged)
- Q_PROPERTY(int contrast READ contrast WRITE setContrast NOTIFY contrastChanged)
- Q_PROPERTY(int hue READ hue WRITE setHue NOTIFY hueChanged)
- Q_PROPERTY(int saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
- Q_PROPERTY(QAbstractVideoSurface* videoSurface READ videoSurface CONSTANT)
+ Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode NOTIFY aspectRatioModeChanged)
public:
explicit QVideoWidget(QWidget *parent = nullptr);
~QVideoWidget();
- QMediaObject *mediaObject() const override;
- QAbstractVideoSurface *videoSurface() const;
+ Q_INVOKABLE QVideoSink *videoSink() const;
#ifdef Q_QDOC
bool isFullScreen() const;
@@ -78,30 +31,15 @@ public:
Qt::AspectRatioMode aspectRatioMode() const;
- int brightness() const;
- int contrast() const;
- int hue() const;
- int saturation() const;
-
QSize sizeHint() const override;
-#if defined(Q_OS_WIN)
- bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
-#endif
public Q_SLOTS:
void setFullScreen(bool fullScreen);
void setAspectRatioMode(Qt::AspectRatioMode mode);
- void setBrightness(int brightness);
- void setContrast(int contrast);
- void setHue(int hue);
- void setSaturation(int saturation);
Q_SIGNALS:
void fullScreenChanged(bool fullScreen);
- void brightnessChanged(int brightness);
- void contrastChanged(int contrast);
- void hueChanged(int hue);
- void saturationChanged(int saturation);
+ void aspectRatioModeChanged(Qt::AspectRatioMode mode);
protected:
bool event(QEvent *event) override;
@@ -109,22 +47,10 @@ protected:
void hideEvent(QHideEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void moveEvent(QMoveEvent *event) override;
- void paintEvent(QPaintEvent *event) override;
-
- bool setMediaObject(QMediaObject *object) override;
-
- QVideoWidget(QVideoWidgetPrivate &dd, QWidget *parent);
QVideoWidgetPrivate *d_ptr;
private:
Q_DECLARE_PRIVATE(QVideoWidget)
- Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed())
- Q_PRIVATE_SLOT(d_func(), void _q_brightnessChanged(int))
- Q_PRIVATE_SLOT(d_func(), void _q_contrastChanged(int))
- Q_PRIVATE_SLOT(d_func(), void _q_hueChanged(int))
- Q_PRIVATE_SLOT(d_func(), void _q_saturationChanged(int))
- Q_PRIVATE_SLOT(d_func(), void _q_fullScreenChanged(bool))
- Q_PRIVATE_SLOT(d_func(), void _q_dimensionsChanged())
};
QT_END_NAMESPACE
diff --git a/src/multimediawidgets/qvideowidget_p.h b/src/multimediawidgets/qvideowidget_p.h
index a3e687488..838bcfe7a 100644
--- a/src/multimediawidgets/qvideowidget_p.h
+++ b/src/multimediawidgets/qvideowidget_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QVIDEOWIDGET_P_H
#define QVIDEOWIDGET_P_H
@@ -51,209 +15,30 @@
// We mean it.
//
-#include <qtmultimediawidgetdefs.h>
+#include <QtMultimediaWidgets/qtmultimediawidgetsglobal.h>
+#include <qvideoframe.h>
#include "qvideowidget.h"
-
-#ifndef QT_NO_OPENGL
-#include <QOpenGLWidget>
-#endif
-
-#include "qpaintervideosurface_p.h"
-
-#include <QtCore/qpointer.h>
+#include "private/qglobal_p.h"
QT_BEGIN_NAMESPACE
-
-class QMediaService;
-
-class QVideoWidgetControlInterface
-{
-public:
- virtual ~QVideoWidgetControlInterface() {}
-
- virtual void setBrightness(int brightness) = 0;
- virtual void setContrast(int contrast) = 0;
- virtual void setHue(int hue) = 0;
- virtual void setSaturation(int saturation) = 0;
-
- virtual void setFullScreen(bool fullScreen) = 0;
-
- virtual Qt::AspectRatioMode aspectRatioMode() const = 0;
- virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0;
-};
-
-class QVideoWidgetBackend : public QObject, public QVideoWidgetControlInterface
-{
- Q_OBJECT
-public:
- virtual QSize sizeHint() const = 0;
-
- virtual void showEvent() = 0;
- virtual void hideEvent(QHideEvent *event) = 0;
- virtual void resizeEvent(QResizeEvent *event) = 0;
- virtual void moveEvent(QMoveEvent *event) = 0;
- virtual void paintEvent(QPaintEvent *event) = 0;
-};
-
-class QVideoWidgetControl;
-
-class QVideoWidgetControlBackend : public QObject, public QVideoWidgetControlInterface
-{
- Q_OBJECT
-public:
- QVideoWidgetControlBackend(QMediaService *service, QVideoWidgetControl *control, QWidget *widget);
-
- void releaseControl();
-
- void setBrightness(int brightness) override;
- void setContrast(int contrast) override;
- void setHue(int hue) override;
- void setSaturation(int saturation) override;
-
- void setFullScreen(bool fullScreen) override;
-
- Qt::AspectRatioMode aspectRatioMode() const override;
- void setAspectRatioMode(Qt::AspectRatioMode mode) override;
-
-private:
- QMediaService *m_service;
- QVideoWidgetControl *m_widgetControl;
-};
-
-
-class QVideoRendererControl;
-
-class QRendererVideoWidgetBackend : public QVideoWidgetBackend
-{
- Q_OBJECT
-public:
- QRendererVideoWidgetBackend(QMediaService *service, QVideoRendererControl *control, QWidget *widget);
- ~QRendererVideoWidgetBackend();
-
- QAbstractVideoSurface *videoSurface() const;
-
- void releaseControl();
- void clearSurface();
-
- void setBrightness(int brightness) override;
- void setContrast(int contrast) override;
- void setHue(int hue) override;
- void setSaturation(int saturation) override;
-
- void setFullScreen(bool fullScreen) override;
-
- Qt::AspectRatioMode aspectRatioMode() const override;
- void setAspectRatioMode(Qt::AspectRatioMode mode) override;
-
- QSize sizeHint() const override;
-
- void showEvent() override;
- void hideEvent(QHideEvent *event) override;
- void resizeEvent(QResizeEvent *event) override;
- void moveEvent(QMoveEvent *event) override;
- void paintEvent(QPaintEvent *event) override;
-
-Q_SIGNALS:
- void fullScreenChanged(bool fullScreen);
- void brightnessChanged(int brightness);
- void contrastChanged(int contrast);
- void hueChanged(int hue);
- void saturationChanged(int saturation);
-
-private Q_SLOTS:
- void formatChanged(const QVideoSurfaceFormat &format);
- void frameChanged();
-
-private:
- void updateRects();
-
- QMediaService *m_service;
- QVideoRendererControl *m_rendererControl;
- QWidget *m_widget;
- QPainterVideoSurface *m_surface;
- Qt::AspectRatioMode m_aspectRatioMode;
- QRect m_boundingRect;
- QRectF m_sourceRect;
- QSize m_nativeSize;
- bool m_updatePaintDevice;
-};
-
-class QVideoWindowControl;
-
-class QWindowVideoWidgetBackend : public QVideoWidgetBackend
-{
- Q_OBJECT
-public:
- QWindowVideoWidgetBackend(QMediaService *service, QVideoWindowControl *control, QWidget *widget);
- ~QWindowVideoWidgetBackend();
-
- void releaseControl();
-
- void setBrightness(int brightness) override;
- void setContrast(int contrast) override;
- void setHue(int hue) override;
- void setSaturation(int saturation) override;
-
- void setFullScreen(bool fullScreen) override;
-
- Qt::AspectRatioMode aspectRatioMode() const override;
- void setAspectRatioMode(Qt::AspectRatioMode mode) override;
-
- QSize sizeHint() const override;
-
- void showEvent() override;
- void hideEvent(QHideEvent *event) override;
- void resizeEvent(QResizeEvent *event) override;
- void moveEvent(QMoveEvent *event) override;
- void paintEvent(QPaintEvent *event) override;
-
-private:
- void updateDisplayRect();
-
- QMediaService *m_service;
- QVideoWindowControl *m_windowControl;
- QWidget *m_widget;
- QSize m_pixelAspectRatio;
-};
-
-class QMediaService;
-class QVideoOutputControl;
+class QObject;
+class QVideoWindow;
class QVideoWidgetPrivate
{
Q_DECLARE_PUBLIC(QVideoWidget)
public:
QVideoWidget *q_ptr = nullptr;
- QPointer<QMediaObject> mediaObject;
- QMediaService *service = nullptr;
- QVideoWidgetControlBackend *widgetBackend = nullptr;
- QWindowVideoWidgetBackend *windowBackend = nullptr;
- QRendererVideoWidgetBackend *rendererBackend = nullptr;
- QVideoWidgetControlInterface *currentControl = nullptr;
- QVideoWidgetBackend *currentBackend = nullptr;
- int brightness = 0;
- int contrast = 0;
- int hue = 0;
- int saturation = 0;
Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio;
Qt::WindowFlags nonFullScreenFlags;
bool wasFullScreen = false;
- bool createWidgetBackend();
- bool createWindowBackend();
- bool createRendererBackend();
-
- void setCurrentControl(QVideoWidgetControlInterface *control);
- void clearService();
+ QVideoWindow *videoWindow = nullptr;
+ QWidget *windowContainer = nullptr;
+ QPoint nonFullscreenPos;
- void _q_serviceDestroyed();
- void _q_brightnessChanged(int brightness);
- void _q_contrastChanged(int contrast);
- void _q_hueChanged(int hue);
- void _q_saturationChanged(int saturation);
- void _q_fullScreenChanged(bool fullScreen);
- void _q_dimensionsChanged();
+ bool createBackend();
};
QT_END_NAMESPACE
diff --git a/src/multimediawidgets/qvideowidgetcontrol.cpp b/src/multimediawidgets/qvideowidgetcontrol.cpp
deleted file mode 100644
index 7f72c620e..000000000
--- a/src/multimediawidgets/qvideowidgetcontrol.cpp
+++ /dev/null
@@ -1,224 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qvideowidgetcontrol.h"
-#include "private/qmediacontrol_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QVideoWidgetControl
-
-
- \brief The QVideoWidgetControl class provides a media control which
- implements a video widget.
-
- \inmodule QtMultimediaWidgets
- \ingroup multimedia-serv
-
- The videoWidget() property of QVideoWidgetControl provides a pointer to a
- video widget implemented by the control's media service. This widget is
- owned by the media service and so care should be taken not to delete it.
-
- \snippet multimedia-snippets/video.cpp Video widget control
-
- QVideoWidgetControl is one of number of possible video output controls.
-
- The interface name of QVideoWidgetControl is \c org.qt-project.qt.videowidgetcontrol/5.0 as
- defined in QVideoWidgetControl_iid.
-
- \sa QMediaService::requestControl(), QVideoWidget
-*/
-
-/*!
- \macro QVideoWidgetControl_iid
-
- \c org.qt-project.qt.videowidgetcontrol/5.0
-
- Defines the interface name of the QVideoWidgetControl class.
-
- \relates QVideoWidgetControl
-*/
-
-/*!
- Constructs a new video widget control with the given \a parent.
-*/
-QVideoWidgetControl::QVideoWidgetControl(QObject *parent)
- :QMediaControl(parent)
-{
-}
-
-/*!
- Destroys a video widget control.
-*/
-QVideoWidgetControl::~QVideoWidgetControl()
-{
-}
-
-/*!
- \fn QVideoWidgetControl::isFullScreen() const
-
- Returns true if the video is shown using the complete screen.
-*/
-
-/*!
- \fn QVideoWidgetControl::setFullScreen(bool fullScreen)
-
- Sets whether a video widget is in \a fullScreen mode.
-*/
-
-/*!
- \fn QVideoWidgetControl::fullScreenChanged(bool fullScreen)
-
- Signals that the \a fullScreen state of a video widget has changed.
-*/
-
-/*!
- \fn QVideoWidgetControl::aspectRatioMode() const
-
- Returns how video is scaled to fit the widget with respect to its aspect ratio.
-*/
-
-/*!
- \fn QVideoWidgetControl::setAspectRatioMode(Qt::AspectRatioMode mode)
-
- Sets the aspect ratio \a mode which determines how video is scaled to the fit the widget with
- respect to its aspect ratio.
-*/
-
-/*!
- \fn QVideoWidgetControl::brightness() const
-
- Returns the brightness adjustment applied to a video.
-
- Valid brightness values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWidgetControl::setBrightness(int brightness)
-
- Sets a \a brightness adjustment for a video.
-
- Valid brightness values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWidgetControl::brightnessChanged(int brightness)
-
- Signals that a video widget's \a brightness adjustment has changed.
-*/
-
-/*!
- \fn QVideoWidgetControl::contrast() const
-
- Returns the contrast adjustment applied to a video.
-
- Valid contrast values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWidgetControl::setContrast(int contrast)
-
- Sets the contrast adjustment for a video widget to \a contrast.
-
- Valid contrast values range between -100 and 100, the default is 0.
-*/
-
-
-/*!
- \fn QVideoWidgetControl::contrastChanged(int contrast)
-
- Signals that a video widget's \a contrast adjustment has changed.
-*/
-
-/*!
- \fn QVideoWidgetControl::hue() const
-
- Returns the hue adjustment applied to a video widget.
-
- Value hue values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWidgetControl::setHue(int hue)
-
- Sets a \a hue adjustment for a video widget.
-
- Valid hue values range between -100 and 100, the default is 0.
-*/
-
-
-/*!
- \fn QVideoWidgetControl::hueChanged(int hue)
-
- Signals that a video widget's \a hue adjustment has changed.
-*/
-
-/*!
- \fn QVideoWidgetControl::saturation() const
-
- Returns the saturation adjustment applied to a video widget.
-
- Value saturation values range between -100 and 100, the default is 0.
-*/
-
-
-/*!
- \fn QVideoWidgetControl::setSaturation(int saturation)
-
- Sets a \a saturation adjustment for a video widget.
-
- Valid saturation values range between -100 and 100, the default is 0.
-*/
-
-/*!
- \fn QVideoWidgetControl::saturationChanged(int saturation)
-
- Signals that a video widget's \a saturation adjustment has changed.
-*/
-
-/*!
- \fn QVideoWidgetControl::videoWidget()
-
- Returns the QWidget.
-*/
-
-QT_END_NAMESPACE
-
-#include "moc_qvideowidgetcontrol.cpp"
diff --git a/src/multimediawidgets/qvideowidgetcontrol.h b/src/multimediawidgets/qvideowidgetcontrol.h
deleted file mode 100644
index c0d177d08..000000000
--- a/src/multimediawidgets/qvideowidgetcontrol.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QVIDEOWIDGETCONTROL_H
-#define QVIDEOWIDGETCONTROL_H
-
-#include <QtMultimediaWidgets/qvideowidget.h>
-#include <QtMultimedia/qmediacontrol.h>
-
-#include <QtWidgets/qwidget.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class QVideoWidgetControlPrivate;
-
-class Q_MULTIMEDIAWIDGETS_EXPORT QVideoWidgetControl : public QMediaControl
-{
- Q_OBJECT
-
-public:
- virtual ~QVideoWidgetControl();
-
- virtual QWidget *videoWidget() = 0;
-
- virtual Qt::AspectRatioMode aspectRatioMode() const = 0;
- virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0;
-
- virtual bool isFullScreen() const = 0;
- virtual void setFullScreen(bool fullScreen) = 0;
-
- virtual int brightness() const = 0;
- virtual void setBrightness(int brightness) = 0;
-
- virtual int contrast() const = 0;
- virtual void setContrast(int contrast) = 0;
-
- virtual int hue() const = 0;
- virtual void setHue(int hue) = 0;
-
- virtual int saturation() const = 0;
- virtual void setSaturation(int saturation) = 0;
-
-Q_SIGNALS:
- void fullScreenChanged(bool fullScreen);
- void brightnessChanged(int brightness);
- void contrastChanged(int contrast);
- void hueChanged(int hue);
- void saturationChanged(int saturation);
-
-protected:
- explicit QVideoWidgetControl(QObject *parent = nullptr);
-};
-
-#define QVideoWidgetControl_iid "org.qt-project.qt.videowidgetcontrol/5.0"
-Q_MEDIA_DECLARE_CONTROL(QVideoWidgetControl, QVideoWidgetControl_iid)
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
new file mode 100644
index 000000000..6f1602cee
--- /dev/null
+++ b/src/plugins/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(multimedia)
diff --git a/src/plugins/alsa/alsa.json b/src/plugins/alsa/alsa.json
deleted file mode 100644
index c2b22dfec..000000000
--- a/src/plugins/alsa/alsa.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": ["alsa"]
-}
diff --git a/src/plugins/alsa/alsa.pro b/src/plugins/alsa/alsa.pro
deleted file mode 100644
index 4012bb8f6..000000000
--- a/src/plugins/alsa/alsa.pro
+++ /dev/null
@@ -1,23 +0,0 @@
-TARGET = qtaudio_alsa
-QT += multimedia-private
-
-QMAKE_USE += alsa
-
-HEADERS += \
- qalsaplugin.h \
- qalsaaudiodeviceinfo.h \
- qalsaaudioinput.h \
- qalsaaudiooutput.h
-
-SOURCES += \
- qalsaplugin.cpp \
- qalsaaudiodeviceinfo.cpp \
- qalsaaudioinput.cpp \
- qalsaaudiooutput.cpp
-
-OTHER_FILES += \
- alsa.json
-
-PLUGIN_TYPE = audio
-PLUGIN_CLASS_NAME = QAlsaPlugin
-load(qt_plugin)
diff --git a/src/plugins/alsa/qalsaaudiodeviceinfo.cpp b/src/plugins/alsa/qalsaaudiodeviceinfo.cpp
deleted file mode 100644
index 5cfcb27e0..000000000
--- a/src/plugins/alsa/qalsaaudiodeviceinfo.cpp
+++ /dev/null
@@ -1,430 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// INTERNAL USE ONLY: Do NOT use for any other purpose.
-//
-
-#include "qalsaaudiodeviceinfo.h"
-
-#include <alsa/version.h>
-
-QT_BEGIN_NAMESPACE
-
-QAlsaAudioDeviceInfo::QAlsaAudioDeviceInfo(const QByteArray &dev, QAudio::Mode mode)
-{
- handle = 0;
-
- device = QLatin1String(dev);
- this->mode = mode;
-
- checkSurround();
-}
-
-QAlsaAudioDeviceInfo::~QAlsaAudioDeviceInfo()
-{
- close();
-}
-
-bool QAlsaAudioDeviceInfo::isFormatSupported(const QAudioFormat& format) const
-{
- return testSettings(format);
-}
-
-QAudioFormat QAlsaAudioDeviceInfo::preferredFormat() const
-{
- QAudioFormat nearest;
- if(mode == QAudio::AudioOutput) {
- nearest.setSampleRate(44100);
- nearest.setChannelCount(2);
- nearest.setByteOrder(QAudioFormat::LittleEndian);
- nearest.setSampleType(QAudioFormat::SignedInt);
- nearest.setSampleSize(16);
- nearest.setCodec(QLatin1String("audio/pcm"));
- } else {
- nearest.setSampleRate(8000);
- nearest.setChannelCount(1);
- nearest.setSampleType(QAudioFormat::UnSignedInt);
- nearest.setSampleSize(8);
- nearest.setCodec(QLatin1String("audio/pcm"));
- if(!testSettings(nearest)) {
- nearest.setChannelCount(2);
- nearest.setSampleSize(16);
- nearest.setSampleType(QAudioFormat::SignedInt);
- }
- }
- return nearest;
-}
-
-QString QAlsaAudioDeviceInfo::deviceName() const
-{
- return device;
-}
-
-QStringList QAlsaAudioDeviceInfo::supportedCodecs()
-{
- updateLists();
- return codecz;
-}
-
-QList<int> QAlsaAudioDeviceInfo::supportedSampleRates()
-{
- updateLists();
- return sampleRatez;
-}
-
-QList<int> QAlsaAudioDeviceInfo::supportedChannelCounts()
-{
- updateLists();
- return channelz;
-}
-
-QList<int> QAlsaAudioDeviceInfo::supportedSampleSizes()
-{
- updateLists();
- return sizez;
-}
-
-QList<QAudioFormat::Endian> QAlsaAudioDeviceInfo::supportedByteOrders()
-{
- updateLists();
- return byteOrderz;
-}
-
-QList<QAudioFormat::SampleType> QAlsaAudioDeviceInfo::supportedSampleTypes()
-{
- updateLists();
- return typez;
-}
-
-QByteArray QAlsaAudioDeviceInfo::defaultDevice(QAudio::Mode mode)
-{
- const auto &devices = availableDevices(mode);
- if (devices.size() == 0)
- return QByteArray();
-
- return devices.first();
-}
-
-bool QAlsaAudioDeviceInfo::open()
-{
- int err = 0;
- QString dev;
-
- if (!availableDevices(mode).contains(device.toLocal8Bit()))
- return false;
-
-#if SND_LIB_VERSION < 0x1000e // 1.0.14
- if (device.compare(QLatin1String("default")) != 0)
- dev = deviceFromCardName(device);
- else
-#endif
- dev = device;
-
- if(mode == QAudio::AudioOutput) {
- err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
- } else {
- err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0);
- }
- if(err < 0) {
- handle = 0;
- return false;
- }
- return true;
-}
-
-void QAlsaAudioDeviceInfo::close()
-{
- if(handle)
- snd_pcm_close(handle);
- handle = 0;
-}
-
-bool QAlsaAudioDeviceInfo::testSettings(const QAudioFormat& format) const
-{
- // Set nearest to closest settings that do work.
- // See if what is in settings will work (return value).
- int err = -1;
- snd_pcm_t* pcmHandle;
- snd_pcm_hw_params_t *params;
- QString dev;
-
-#if SND_LIB_VERSION < 0x1000e // 1.0.14
- if (device.compare(QLatin1String("default")) != 0)
- dev = deviceFromCardName(device);
- else
-#endif
- dev = device;
-
- snd_pcm_stream_t stream = mode == QAudio::AudioOutput
- ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE;
-
- if (snd_pcm_open(&pcmHandle, dev.toLocal8Bit().constData(), stream, 0) < 0)
- return false;
-
- snd_pcm_nonblock(pcmHandle, 0);
- snd_pcm_hw_params_alloca(&params);
- snd_pcm_hw_params_any(pcmHandle, params);
-
- // set the values!
- snd_pcm_hw_params_set_channels(pcmHandle, params, format.channelCount());
- snd_pcm_hw_params_set_rate(pcmHandle, params, format.sampleRate(), 0);
-
- snd_pcm_format_t pcmFormat = SND_PCM_FORMAT_UNKNOWN;
- switch (format.sampleSize()) {
- case 8:
- if (format.sampleType() == QAudioFormat::SignedInt)
- pcmFormat = SND_PCM_FORMAT_S8;
- else if (format.sampleType() == QAudioFormat::UnSignedInt)
- pcmFormat = SND_PCM_FORMAT_U8;
- break;
- case 16:
- if (format.sampleType() == QAudioFormat::SignedInt) {
- pcmFormat = format.byteOrder() == QAudioFormat::LittleEndian
- ? SND_PCM_FORMAT_S16_LE : SND_PCM_FORMAT_S16_BE;
- } else if (format.sampleType() == QAudioFormat::UnSignedInt) {
- pcmFormat = format.byteOrder() == QAudioFormat::LittleEndian
- ? SND_PCM_FORMAT_U16_LE : SND_PCM_FORMAT_U16_BE;
- }
- break;
- case 32:
- if (format.sampleType() == QAudioFormat::SignedInt) {
- pcmFormat = format.byteOrder() == QAudioFormat::LittleEndian
- ? SND_PCM_FORMAT_S32_LE : SND_PCM_FORMAT_S32_BE;
- } else if (format.sampleType() == QAudioFormat::UnSignedInt) {
- pcmFormat = format.byteOrder() == QAudioFormat::LittleEndian
- ? SND_PCM_FORMAT_U32_LE : SND_PCM_FORMAT_U32_BE;
- } else if (format.sampleType() == QAudioFormat::Float) {
- pcmFormat = format.byteOrder() == QAudioFormat::LittleEndian
- ? SND_PCM_FORMAT_FLOAT_LE : SND_PCM_FORMAT_FLOAT_BE;
- }
- }
-
- if (pcmFormat != SND_PCM_FORMAT_UNKNOWN)
- err = snd_pcm_hw_params_set_format(pcmHandle, params, pcmFormat);
-
- // For now, just accept only audio/pcm codec
- if (!format.codec().startsWith(QLatin1String("audio/pcm")))
- err = -1;
-
- if (err >= 0 && format.channelCount() != -1) {
- err = snd_pcm_hw_params_test_channels(pcmHandle, params, format.channelCount());
- if (err >= 0)
- err = snd_pcm_hw_params_set_channels(pcmHandle, params, format.channelCount());
- }
-
- if (err >= 0 && format.sampleRate() != -1) {
- err = snd_pcm_hw_params_test_rate(pcmHandle, params, format.sampleRate(), 0);
- if (err >= 0)
- err = snd_pcm_hw_params_set_rate(pcmHandle, params, format.sampleRate(), 0);
- }
-
- if (err >= 0 && pcmFormat != SND_PCM_FORMAT_UNKNOWN)
- err = snd_pcm_hw_params_set_format(pcmHandle, params, pcmFormat);
-
- if (err >= 0)
- err = snd_pcm_hw_params(pcmHandle, params);
-
- snd_pcm_close(pcmHandle);
-
- return (err == 0);
-}
-
-void QAlsaAudioDeviceInfo::updateLists()
-{
- // redo all lists based on current settings
- sampleRatez.clear();
- channelz.clear();
- sizez.clear();
- byteOrderz.clear();
- typez.clear();
- codecz.clear();
-
- if(!handle)
- open();
-
- if(!handle)
- return;
-
- for(int i=0; i<(int)MAX_SAMPLE_RATES; i++) {
- //if(snd_pcm_hw_params_test_rate(handle, params, SAMPLE_RATES[i], dir) == 0)
- sampleRatez.append(SAMPLE_RATES[i]);
- }
- channelz.append(1);
- channelz.append(2);
- if (surround40) channelz.append(4);
- if (surround51) channelz.append(6);
- if (surround71) channelz.append(8);
- sizez.append(8);
- sizez.append(16);
- sizez.append(32);
- byteOrderz.append(QAudioFormat::LittleEndian);
- byteOrderz.append(QAudioFormat::BigEndian);
- typez.append(QAudioFormat::SignedInt);
- typez.append(QAudioFormat::UnSignedInt);
- typez.append(QAudioFormat::Float);
- codecz.append(QLatin1String("audio/pcm"));
- close();
-}
-
-QList<QByteArray> QAlsaAudioDeviceInfo::availableDevices(QAudio::Mode mode)
-{
- QList<QByteArray> devices;
- bool hasDefault = false;
-
-#if SND_LIB_VERSION >= 0x1000e // 1.0.14
- QByteArray filter;
-
- // Create a list of all current audio devices that support mode
- void **hints, **n;
- char *name, *descr, *io;
-
- if(snd_device_name_hint(-1, "pcm", &hints) < 0) {
- qWarning() << "no alsa devices available";
- return devices;
- }
- n = hints;
-
- if(mode == QAudio::AudioInput) {
- filter = "Input";
- } else {
- filter = "Output";
- }
-
- while (*n != NULL) {
- name = snd_device_name_get_hint(*n, "NAME");
- if (name != 0 && qstrcmp(name, "null") != 0) {
- descr = snd_device_name_get_hint(*n, "DESC");
- io = snd_device_name_get_hint(*n, "IOID");
-
- if ((descr != NULL) && ((io == NULL) || (io == filter))) {
- devices.append(name);
- if (strcmp(name, "default") == 0)
- hasDefault = true;
- }
-
- free(descr);
- free(io);
- }
- free(name);
- ++n;
- }
- snd_device_name_free_hint(hints);
-#else
- int idx = 0;
- char* name;
-
- while(snd_card_get_name(idx,&name) == 0) {
- devices.append(name);
- if (strcmp(name, "default") == 0)
- hasDefault = true;
- idx++;
- }
-#endif
-
- if (!hasDefault && devices.size() > 0)
- devices.prepend("default");
-
- return devices;
-}
-
-void QAlsaAudioDeviceInfo::checkSurround()
-{
- surround40 = false;
- surround51 = false;
- surround71 = false;
-
- void **hints, **n;
- char *name, *descr, *io;
-
- if(snd_device_name_hint(-1, "pcm", &hints) < 0)
- return;
-
- n = hints;
-
- while (*n != NULL) {
- name = snd_device_name_get_hint(*n, "NAME");
- descr = snd_device_name_get_hint(*n, "DESC");
- io = snd_device_name_get_hint(*n, "IOID");
- if((name != NULL) && (descr != NULL)) {
- QString deviceName = QLatin1String(name);
- if (mode == QAudio::AudioOutput) {
- if(deviceName.contains(QLatin1String("surround40")))
- surround40 = true;
- if(deviceName.contains(QLatin1String("surround51")))
- surround51 = true;
- if(deviceName.contains(QLatin1String("surround71")))
- surround71 = true;
- }
- }
- if(name != NULL)
- free(name);
- if(descr != NULL)
- free(descr);
- if(io != NULL)
- free(io);
- ++n;
- }
- snd_device_name_free_hint(hints);
-}
-
-QString QAlsaAudioDeviceInfo::deviceFromCardName(const QString &card)
-{
- int idx = 0;
- char *name;
-
- QStringView shortName = QStringView{card}.mid(card.indexOf(QLatin1String("="), 0) + 1);
-
- while (snd_card_get_name(idx, &name) == 0) {
- if (shortName.compare(QLatin1String(name)) == 0)
- break;
- idx++;
- }
-
- return QString(QLatin1String("hw:%1,0")).arg(idx);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/alsa/qalsaaudiodeviceinfo.h b/src/plugins/alsa/qalsaaudiodeviceinfo.h
deleted file mode 100644
index cdf08bfab..000000000
--- a/src/plugins/alsa/qalsaaudiodeviceinfo.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-
-#ifndef QALSAAUDIODEVICEINFO_H
-#define QALSAAUDIODEVICEINFO_H
-
-#include <alsa/asoundlib.h>
-
-#include <QtCore/qbytearray.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qlist.h>
-#include <QtCore/qdebug.h>
-
-#include <QtMultimedia/qaudio.h>
-#include <QtMultimedia/qaudiodeviceinfo.h>
-#include <QtMultimedia/qaudiosystem.h>
-
-QT_BEGIN_NAMESPACE
-
-
-const unsigned int MAX_SAMPLE_RATES = 5;
-const unsigned int SAMPLE_RATES[] =
- { 8000, 11025, 22050, 44100, 48000 };
-
-class QAlsaAudioDeviceInfo : public QAbstractAudioDeviceInfo
-{
- Q_OBJECT
-public:
- QAlsaAudioDeviceInfo(const QByteArray &dev,QAudio::Mode mode);
- ~QAlsaAudioDeviceInfo();
-
- bool testSettings(const QAudioFormat& format) const;
- void updateLists();
- QAudioFormat preferredFormat() const override;
- bool isFormatSupported(const QAudioFormat& format) const override;
- QString deviceName() const override;
- QStringList supportedCodecs() override;
- QList<int> supportedSampleRates() override;
- QList<int> supportedChannelCounts() override;
- QList<int> supportedSampleSizes() override;
- QList<QAudioFormat::Endian> supportedByteOrders() override;
- QList<QAudioFormat::SampleType> supportedSampleTypes() override;
- static QByteArray defaultDevice(QAudio::Mode mode);
- static QList<QByteArray> availableDevices(QAudio::Mode);
- static QString deviceFromCardName(const QString &card);
-
-private:
- bool open();
- void close();
-
- void checkSurround();
- bool surround40;
- bool surround51;
- bool surround71;
-
- QString device;
- QAudio::Mode mode;
- QAudioFormat nearest;
- QList<int> sampleRatez;
- QList<int> channelz;
- QList<int> sizez;
- QList<QAudioFormat::Endian> byteOrderz;
- QStringList codecz;
- QList<QAudioFormat::SampleType> typez;
- snd_pcm_t* handle;
- snd_pcm_hw_params_t *params;
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QALSAAUDIODEVICEINFO_H
diff --git a/src/plugins/alsa/qalsaaudioinput.cpp b/src/plugins/alsa/qalsaaudioinput.cpp
deleted file mode 100644
index bff23dfe1..000000000
--- a/src/plugins/alsa/qalsaaudioinput.cpp
+++ /dev/null
@@ -1,872 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// INTERNAL USE ONLY: Do NOT use for any other purpose.
-//
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qvarlengtharray.h>
-#include <QtMultimedia/private/qaudiohelpers_p.h>
-#include "qalsaaudioinput.h"
-#include "qalsaaudiodeviceinfo.h"
-
-QT_BEGIN_NAMESPACE
-
-//#define DEBUG_AUDIO 1
-
-QAlsaAudioInput::QAlsaAudioInput(const QByteArray &device)
-{
- bytesAvailable = 0;
- handle = 0;
- access = SND_PCM_ACCESS_RW_INTERLEAVED;
- pcmformat = SND_PCM_FORMAT_S16;
- buffer_size = 0;
- period_size = 0;
- buffer_time = 100000;
- period_time = 20000;
- totalTimeValue = 0;
- intervalTime = 1000;
- errorState = QAudio::NoError;
- deviceState = QAudio::StoppedState;
- audioSource = 0;
- pullMode = true;
- resuming = false;
-
- m_volume = 1.0f;
-
- m_device = device;
-
- timer = new QTimer(this);
- connect(timer,SIGNAL(timeout()),SLOT(userFeed()));
-}
-
-QAlsaAudioInput::~QAlsaAudioInput()
-{
- close();
- disconnect(timer, SIGNAL(timeout()));
- QCoreApplication::processEvents();
- delete timer;
-}
-
-void QAlsaAudioInput::setVolume(qreal vol)
-{
- m_volume = vol;
-}
-
-qreal QAlsaAudioInput::volume() const
-{
- return m_volume;
-}
-
-QAudio::Error QAlsaAudioInput::error() const
-{
- return errorState;
-}
-
-QAudio::State QAlsaAudioInput::state() const
-{
- return deviceState;
-}
-
-void QAlsaAudioInput::setFormat(const QAudioFormat& fmt)
-{
- if (deviceState == QAudio::StoppedState)
- settings = fmt;
-}
-
-QAudioFormat QAlsaAudioInput::format() const
-{
- return settings;
-}
-
-int QAlsaAudioInput::xrun_recovery(int err)
-{
- int count = 0;
- bool reset = false;
-
- // ESTRPIPE is not available in all OSes where ALSA is available
- int estrpipe = EIO;
-#ifdef ESTRPIPE
- estrpipe = ESTRPIPE;
-#endif
-
- if(err == -EPIPE) {
- errorState = QAudio::UnderrunError;
- err = snd_pcm_prepare(handle);
- if(err < 0)
- reset = true;
- else {
- bytesAvailable = checkBytesReady();
- if (bytesAvailable <= 0)
- reset = true;
- }
- } else if ((err == -estrpipe)||(err == -EIO)) {
- errorState = QAudio::IOError;
- while((err = snd_pcm_resume(handle)) == -EAGAIN){
- usleep(100);
- count++;
- if(count > 5) {
- reset = true;
- break;
- }
- }
- if(err < 0) {
- err = snd_pcm_prepare(handle);
- if(err < 0)
- reset = true;
- }
- }
- if(reset) {
- close();
- open();
- snd_pcm_prepare(handle);
- return 0;
- }
- return err;
-}
-
-int QAlsaAudioInput::setFormat()
-{
- snd_pcm_format_t format = SND_PCM_FORMAT_UNKNOWN;
-
- if(settings.sampleSize() == 8) {
- format = SND_PCM_FORMAT_U8;
- } else if(settings.sampleSize() == 16) {
- if(settings.sampleType() == QAudioFormat::SignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- format = SND_PCM_FORMAT_S16_LE;
- else
- format = SND_PCM_FORMAT_S16_BE;
- } else if(settings.sampleType() == QAudioFormat::UnSignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- format = SND_PCM_FORMAT_U16_LE;
- else
- format = SND_PCM_FORMAT_U16_BE;
- }
- } else if(settings.sampleSize() == 24) {
- if(settings.sampleType() == QAudioFormat::SignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- format = SND_PCM_FORMAT_S24_LE;
- else
- format = SND_PCM_FORMAT_S24_BE;
- } else if(settings.sampleType() == QAudioFormat::UnSignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- format = SND_PCM_FORMAT_U24_LE;
- else
- format = SND_PCM_FORMAT_U24_BE;
- }
- } else if(settings.sampleSize() == 32) {
- if(settings.sampleType() == QAudioFormat::SignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- format = SND_PCM_FORMAT_S32_LE;
- else
- format = SND_PCM_FORMAT_S32_BE;
- } else if(settings.sampleType() == QAudioFormat::UnSignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- format = SND_PCM_FORMAT_U32_LE;
- else
- format = SND_PCM_FORMAT_U32_BE;
- } else if(settings.sampleType() == QAudioFormat::Float) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- format = SND_PCM_FORMAT_FLOAT_LE;
- else
- format = SND_PCM_FORMAT_FLOAT_BE;
- }
- } else if(settings.sampleSize() == 64) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- format = SND_PCM_FORMAT_FLOAT64_LE;
- else
- format = SND_PCM_FORMAT_FLOAT64_BE;
- }
-
- return format != SND_PCM_FORMAT_UNKNOWN
- ? snd_pcm_hw_params_set_format( handle, hwparams, format)
- : -1;
-}
-
-void QAlsaAudioInput::start(QIODevice* device)
-{
- if(deviceState != QAudio::StoppedState)
- close();
-
- if(!pullMode && audioSource)
- delete audioSource;
-
- pullMode = true;
- audioSource = device;
-
- deviceState = QAudio::ActiveState;
-
- if( !open() )
- return;
-
- emit stateChanged(deviceState);
-}
-
-QIODevice* QAlsaAudioInput::start()
-{
- if(deviceState != QAudio::StoppedState)
- close();
-
- if(!pullMode && audioSource)
- delete audioSource;
-
- pullMode = false;
- audioSource = new AlsaInputPrivate(this);
- audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
-
- deviceState = QAudio::IdleState;
-
- if( !open() )
- return 0;
-
- emit stateChanged(deviceState);
-
- return audioSource;
-}
-
-void QAlsaAudioInput::stop()
-{
- if(deviceState == QAudio::StoppedState)
- return;
-
- deviceState = QAudio::StoppedState;
-
- close();
- emit stateChanged(deviceState);
-}
-
-bool QAlsaAudioInput::open()
-{
-#ifdef DEBUG_AUDIO
- QTime now(QTime::currentTime());
- qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
-#endif
- clockStamp.restart();
- timeStamp.restart();
- elapsedTimeOffset = 0;
-
- int dir;
- int err = 0;
- int count=0;
- unsigned int sampleRate=settings.sampleRate();
-
- if (!settings.isValid()) {
- qWarning("QAudioInput: open error, invalid format.");
- } else if (settings.sampleRate() <= 0) {
- qWarning("QAudioInput: open error, invalid sample rate (%d).",
- settings.sampleRate());
- } else {
- err = -1;
- }
-
- if (err == 0) {
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit errorChanged(errorState);
- return false;
- }
-
-
- if (!QAlsaAudioDeviceInfo::availableDevices(QAudio::AudioInput).contains(m_device))
- return false;
-
- QString dev;
-#if SND_LIB_VERSION < 0x1000e // 1.0.14
- if (m_device != "default")
- dev = QAlsaAudioDeviceInfo::deviceFromCardName(m_device);
- else
-#endif
- dev = m_device;
-
- // Step 1: try and open the device
- while((count < 5) && (err < 0)) {
- err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0);
- if(err < 0)
- count++;
- }
- if (( err < 0)||(handle == 0)) {
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- return false;
- }
- snd_pcm_nonblock( handle, 0 );
-
- // Step 2: Set the desired HW parameters.
- snd_pcm_hw_params_alloca( &hwparams );
-
- bool fatal = false;
- QString errMessage;
- unsigned int chunks = 8;
-
- err = snd_pcm_hw_params_any( handle, hwparams );
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_any: err = %1").arg(err);
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 );
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_access( handle, hwparams, access );
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_access: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = setFormat();
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_format: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channelCount() );
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_channels: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &sampleRate, 0 );
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir);
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir);
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params(handle, hwparams);
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params: err = %1").arg(err);
- }
- }
- if( err < 0) {
- qWarning()<<errMessage;
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- return false;
- }
- snd_pcm_hw_params_get_buffer_size(hwparams,&buffer_frames);
- buffer_size = snd_pcm_frames_to_bytes(handle,buffer_frames);
- snd_pcm_hw_params_get_period_size(hwparams,&period_frames, &dir);
- period_size = snd_pcm_frames_to_bytes(handle,period_frames);
- snd_pcm_hw_params_get_buffer_time(hwparams,&buffer_time, &dir);
- snd_pcm_hw_params_get_period_time(hwparams,&period_time, &dir);
-
- // Step 3: Set the desired SW parameters.
- snd_pcm_sw_params_t *swparams;
- snd_pcm_sw_params_alloca(&swparams);
- snd_pcm_sw_params_current(handle, swparams);
- snd_pcm_sw_params_set_start_threshold(handle,swparams,period_frames);
- snd_pcm_sw_params_set_stop_threshold(handle,swparams,buffer_frames);
- snd_pcm_sw_params_set_avail_min(handle, swparams,period_frames);
- snd_pcm_sw_params(handle, swparams);
-
- // Step 4: Prepare audio
- ringBuffer.resize(buffer_size);
- snd_pcm_prepare( handle );
- snd_pcm_start(handle);
-
- // Step 5: Setup timer
- bytesAvailable = checkBytesReady();
-
- if(pullMode)
- connect(audioSource,SIGNAL(readyRead()),this,SLOT(userFeed()));
-
- // Step 6: Start audio processing
- chunks = buffer_size/period_size;
- timer->start(period_time*chunks/2000);
-
- errorState = QAudio::NoError;
-
- totalTimeValue = 0;
-
- return true;
-}
-
-void QAlsaAudioInput::close()
-{
- timer->stop();
-
- if ( handle ) {
- snd_pcm_drop( handle );
- snd_pcm_close( handle );
- handle = 0;
- }
-}
-
-int QAlsaAudioInput::checkBytesReady()
-{
- if(resuming)
- bytesAvailable = period_size;
- else if(deviceState != QAudio::ActiveState
- && deviceState != QAudio::IdleState)
- bytesAvailable = 0;
- else {
- int frames = snd_pcm_avail_update(handle);
- if (frames < 0) {
- bytesAvailable = frames;
- } else {
- if((int)frames > (int)buffer_frames)
- frames = buffer_frames;
- bytesAvailable = snd_pcm_frames_to_bytes(handle, frames);
- }
- }
- return bytesAvailable;
-}
-
-int QAlsaAudioInput::bytesReady() const
-{
- return qMax(bytesAvailable, 0);
-}
-
-qint64 QAlsaAudioInput::read(char* data, qint64 len)
-{
- // Read in some audio data and write it to QIODevice, pull mode
- if ( !handle )
- return 0;
-
- int bytesRead = 0;
- int bytesInRingbufferBeforeRead = ringBuffer.bytesOfDataInBuffer();
-
- if (ringBuffer.bytesOfDataInBuffer() < len) {
-
- // bytesAvaiable is saved as a side effect of checkBytesReady().
- int bytesToRead = checkBytesReady();
-
- if (bytesToRead < 0) {
- // bytesAvailable as negative is error code, try to recover from it.
- xrun_recovery(bytesToRead);
- bytesToRead = checkBytesReady();
- if (bytesToRead < 0) {
- // recovery failed must stop and set error.
- close();
- errorState = QAudio::IOError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- return 0;
- }
- }
-
- bytesToRead = qMin<qint64>(len, bytesToRead);
- bytesToRead = qMin<qint64>(ringBuffer.freeBytes(), bytesToRead);
- bytesToRead -= bytesToRead % period_size;
-
- int count=0;
- int err = 0;
- QVarLengthArray<char, 4096> buffer(bytesToRead);
- while(count < 5 && bytesToRead > 0) {
- int chunks = bytesToRead / period_size;
- int frames = chunks * period_frames;
- if (frames > (int)buffer_frames)
- frames = buffer_frames;
-
- int readFrames = snd_pcm_readi(handle, buffer.data(), frames);
- bytesRead = snd_pcm_frames_to_bytes(handle, readFrames);
- if (m_volume < 1.0f)
- QAudioHelperInternal::qMultiplySamples(m_volume, settings,
- buffer.constData(),
- buffer.data(), bytesRead);
-
- if (readFrames >= 0) {
- ringBuffer.write(buffer.data(), bytesRead);
-#ifdef DEBUG_AUDIO
- qDebug() << QString::fromLatin1("read in bytes = %1 (frames=%2)").arg(bytesRead).arg(readFrames).toLatin1().constData();
-#endif
- break;
- } else if((readFrames == -EAGAIN) || (readFrames == -EINTR)) {
- errorState = QAudio::IOError;
- err = 0;
- break;
- } else {
- if(readFrames == -EPIPE) {
- errorState = QAudio::UnderrunError;
- err = snd_pcm_prepare(handle);
-#ifdef ESTRPIPE
- } else if(readFrames == -ESTRPIPE) {
- err = snd_pcm_prepare(handle);
-#endif
- }
- if(err != 0) break;
- }
- count++;
- }
-
- }
-
- bytesRead += bytesInRingbufferBeforeRead;
-
- if (bytesRead > 0) {
- // got some send it onward
-#ifdef DEBUG_AUDIO
- qDebug() << "frames to write to QIODevice = " <<
- snd_pcm_bytes_to_frames( handle, (int)bytesRead ) << " (" << bytesRead << ") bytes";
-#endif
- if (deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
- return 0;
-
- if (pullMode) {
- qint64 l = 0;
- qint64 bytesWritten = 0;
- while (ringBuffer.bytesOfDataInBuffer() > 0) {
- l = audioSource->write(ringBuffer.availableData(), ringBuffer.availableDataBlockSize());
- if (l > 0) {
- ringBuffer.readBytes(l);
- bytesWritten += l;
- } else {
- break;
- }
- }
-
- if (l < 0) {
- close();
- errorState = QAudio::IOError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- } else if (l == 0 && bytesWritten == 0) {
- if (deviceState != QAudio::IdleState) {
- errorState = QAudio::NoError;
- deviceState = QAudio::IdleState;
- emit stateChanged(deviceState);
- }
- } else {
- bytesAvailable -= bytesWritten;
- totalTimeValue += bytesWritten;
- resuming = false;
- if (deviceState != QAudio::ActiveState) {
- errorState = QAudio::NoError;
- deviceState = QAudio::ActiveState;
- emit stateChanged(deviceState);
- }
- }
-
- return bytesWritten;
- } else {
- while (ringBuffer.bytesOfDataInBuffer() > 0) {
- int size = ringBuffer.availableDataBlockSize();
- memcpy(data, ringBuffer.availableData(), size);
- data += size;
- ringBuffer.readBytes(size);
- }
-
- bytesAvailable -= bytesRead;
- totalTimeValue += bytesRead;
- resuming = false;
- if (deviceState != QAudio::ActiveState) {
- errorState = QAudio::NoError;
- deviceState = QAudio::ActiveState;
- emit stateChanged(deviceState);
- }
-
- return bytesRead;
- }
- }
-
- return 0;
-}
-
-void QAlsaAudioInput::resume()
-{
- if(deviceState == QAudio::SuspendedState) {
- int err = 0;
-
- if(handle) {
- err = snd_pcm_prepare( handle );
- if(err < 0)
- xrun_recovery(err);
-
- err = snd_pcm_start(handle);
- if(err < 0)
- xrun_recovery(err);
-
- bytesAvailable = buffer_size;
- }
- resuming = true;
- deviceState = QAudio::ActiveState;
- int chunks = buffer_size/period_size;
- timer->start(period_time*chunks/2000);
- emit stateChanged(deviceState);
- }
-}
-
-void QAlsaAudioInput::setBufferSize(int value)
-{
- buffer_size = value;
-}
-
-int QAlsaAudioInput::bufferSize() const
-{
- return buffer_size;
-}
-
-int QAlsaAudioInput::periodSize() const
-{
- return period_size;
-}
-
-void QAlsaAudioInput::setNotifyInterval(int ms)
-{
- intervalTime = qMax(0, ms);
-}
-
-int QAlsaAudioInput::notifyInterval() const
-{
- return intervalTime;
-}
-
-qint64 QAlsaAudioInput::processedUSecs() const
-{
- qint64 result = qint64(1000000) * totalTimeValue /
- (settings.channelCount()*(settings.sampleSize()/8)) /
- settings.sampleRate();
-
- return result;
-}
-
-void QAlsaAudioInput::suspend()
-{
- if(deviceState == QAudio::ActiveState||resuming) {
- snd_pcm_drain(handle);
- timer->stop();
- deviceState = QAudio::SuspendedState;
- emit stateChanged(deviceState);
- }
-}
-
-void QAlsaAudioInput::userFeed()
-{
- if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState)
- return;
-#ifdef DEBUG_AUDIO
- QTime now(QTime::currentTime());
- qDebug()<<now.second()<<"s "<<now.msec()<<"ms :userFeed() IN";
-#endif
- deviceReady();
-}
-
-bool QAlsaAudioInput::deviceReady()
-{
- if(pullMode) {
- // reads some audio data and writes it to QIODevice
- read(0, buffer_size);
- } else {
- // emits readyRead() so user will call read() on QIODevice to get some audio data
- AlsaInputPrivate* a = qobject_cast<AlsaInputPrivate*>(audioSource);
- a->trigger();
- }
- bytesAvailable = checkBytesReady();
-
- if(deviceState != QAudio::ActiveState)
- return true;
-
- if (bytesAvailable < 0) {
- // bytesAvailable as negative is error code, try to recover from it.
- xrun_recovery(bytesAvailable);
- bytesAvailable = checkBytesReady();
- if (bytesAvailable < 0) {
- // recovery failed must stop and set error.
- close();
- errorState = QAudio::IOError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- return 0;
- }
- }
-
- if(intervalTime && (timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
- emit notify();
- elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime;
- timeStamp.restart();
- }
- return true;
-}
-
-qint64 QAlsaAudioInput::elapsedUSecs() const
-{
- if (deviceState == QAudio::StoppedState)
- return 0;
-
- return clockStamp.elapsed() * qint64(1000);
-}
-
-void QAlsaAudioInput::reset()
-{
- if(handle)
- snd_pcm_reset(handle);
- stop();
- bytesAvailable = 0;
-}
-
-void QAlsaAudioInput::drain()
-{
- if(handle)
- snd_pcm_drain(handle);
-}
-
-AlsaInputPrivate::AlsaInputPrivate(QAlsaAudioInput* audio)
-{
- audioDevice = qobject_cast<QAlsaAudioInput*>(audio);
-}
-
-AlsaInputPrivate::~AlsaInputPrivate()
-{
-}
-
-qint64 AlsaInputPrivate::readData( char* data, qint64 len)
-{
- return audioDevice->read(data,len);
-}
-
-qint64 AlsaInputPrivate::writeData(const char* data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
- return 0;
-}
-
-void AlsaInputPrivate::trigger()
-{
- emit readyRead();
-}
-
-RingBuffer::RingBuffer() :
- m_head(0),
- m_tail(0)
-{
-}
-
-void RingBuffer::resize(int size)
-{
- m_data.resize(size);
-}
-
-int RingBuffer::bytesOfDataInBuffer() const
-{
- if (m_head < m_tail)
- return m_tail - m_head;
- else if (m_tail < m_head)
- return m_data.size() + m_tail - m_head;
- else
- return 0;
-}
-
-int RingBuffer::freeBytes() const
-{
- if (m_head > m_tail)
- return m_head - m_tail - 1;
- else if (m_tail > m_head)
- return m_data.size() - m_tail + m_head - 1;
- else
- return m_data.size() - 1;
-}
-
-const char *RingBuffer::availableData() const
-{
- return (m_data.constData() + m_head);
-}
-
-int RingBuffer::availableDataBlockSize() const
-{
- if (m_head > m_tail)
- return m_data.size() - m_head;
- else if (m_tail > m_head)
- return m_tail - m_head;
- else
- return 0;
-}
-
-void RingBuffer::readBytes(int bytes)
-{
- m_head = (m_head + bytes) % m_data.size();
-}
-
-void RingBuffer::write(char *data, int len)
-{
- if (m_tail + len < m_data.size()) {
- memcpy(m_data.data() + m_tail, data, len);
- m_tail += len;
- } else {
- int bytesUntilEnd = m_data.size() - m_tail;
- memcpy(m_data.data() + m_tail, data, bytesUntilEnd);
- if (len - bytesUntilEnd > 0)
- memcpy(m_data.data(), data + bytesUntilEnd, len - bytesUntilEnd);
- m_tail = len - bytesUntilEnd;
- }
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qalsaaudioinput.cpp"
diff --git a/src/plugins/alsa/qalsaaudioinput.h b/src/plugins/alsa/qalsaaudioinput.h
deleted file mode 100644
index 62e1be039..000000000
--- a/src/plugins/alsa/qalsaaudioinput.h
+++ /dev/null
@@ -1,185 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-
-#ifndef QAUDIOINPUTALSA_H
-#define QAUDIOINPUTALSA_H
-
-#include <alsa/asoundlib.h>
-
-#include <QtCore/qfile.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qtimer.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qelapsedtimer.h>
-#include <QtCore/qiodevice.h>
-
-#include <QtMultimedia/qaudio.h>
-#include <QtMultimedia/qaudiodeviceinfo.h>
-#include <QtMultimedia/qaudiosystem.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class AlsaInputPrivate;
-
-class RingBuffer
-{
-public:
- RingBuffer();
-
- void resize(int size);
-
- int bytesOfDataInBuffer() const;
- int freeBytes() const;
-
- const char *availableData() const;
- int availableDataBlockSize() const;
- void readBytes(int bytes);
-
- void write(char *data, int len);
-
-private:
- int m_head;
- int m_tail;
-
- QByteArray m_data;
-};
-
-class QAlsaAudioInput : public QAbstractAudioInput
-{
- Q_OBJECT
-public:
- QAlsaAudioInput(const QByteArray &device);
- ~QAlsaAudioInput();
-
- qint64 read(char* data, qint64 len);
-
- void start(QIODevice* device) override;
- QIODevice* start() override;
- void stop() override;
- void reset() override;
- void suspend() override;
- void resume() override;
- int bytesReady() const override;
- int periodSize() const override;
- void setBufferSize(int value) override;
- int bufferSize() const override;
- void setNotifyInterval(int milliSeconds) override;
- int notifyInterval() const override;
- qint64 processedUSecs() const override;
- qint64 elapsedUSecs() const override;
- QAudio::Error error() const override;
- QAudio::State state() const override;
- void setFormat(const QAudioFormat& fmt) override;
- QAudioFormat format() const override;
- void setVolume(qreal) override;
- qreal volume() const override;
- bool resuming;
- snd_pcm_t* handle;
- qint64 totalTimeValue;
- QIODevice* audioSource;
- QAudioFormat settings;
- QAudio::Error errorState;
- QAudio::State deviceState;
-
-private slots:
- void userFeed();
- bool deviceReady();
-
-private:
- int checkBytesReady();
- int xrun_recovery(int err);
- int setFormat();
- bool open();
- void close();
- void drain();
-
- QTimer* timer;
- QElapsedTimer timeStamp;
- QElapsedTimer clockStamp;
- qint64 elapsedTimeOffset;
- int intervalTime;
- RingBuffer ringBuffer;
- int bytesAvailable;
- QByteArray m_device;
- bool pullMode;
- int buffer_size;
- int period_size;
- unsigned int buffer_time;
- unsigned int period_time;
- snd_pcm_uframes_t buffer_frames;
- snd_pcm_uframes_t period_frames;
- snd_pcm_access_t access;
- snd_pcm_format_t pcmformat;
- snd_pcm_hw_params_t *hwparams;
- qreal m_volume;
-};
-
-class AlsaInputPrivate : public QIODevice
-{
- Q_OBJECT
-public:
- AlsaInputPrivate(QAlsaAudioInput* audio);
- ~AlsaInputPrivate();
-
- qint64 readData( char* data, qint64 len) override;
- qint64 writeData(const char* data, qint64 len) override;
-
- void trigger();
-private:
- QAlsaAudioInput *audioDevice;
-};
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/plugins/alsa/qalsaaudiooutput.cpp b/src/plugins/alsa/qalsaaudiooutput.cpp
deleted file mode 100644
index f66e5e6e8..000000000
--- a/src/plugins/alsa/qalsaaudiooutput.cpp
+++ /dev/null
@@ -1,813 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// INTERNAL USE ONLY: Do NOT use for any other purpose.
-//
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qvarlengtharray.h>
-#include <QtMultimedia/private/qaudiohelpers_p.h>
-#include "qalsaaudiooutput.h"
-#include "qalsaaudiodeviceinfo.h"
-#include <QLoggingCategory>
-
-QT_BEGIN_NAMESPACE
-
-Q_LOGGING_CATEGORY(lcAlsaOutput, "qt.multimedia.alsa.output")
-//#define DEBUG_AUDIO 1
-
-QAlsaAudioOutput::QAlsaAudioOutput(const QByteArray &device)
-{
- bytesAvailable = 0;
- handle = 0;
- access = SND_PCM_ACCESS_RW_INTERLEAVED;
- pcmformat = SND_PCM_FORMAT_S16;
- buffer_frames = 0;
- period_frames = 0;
- buffer_size = 0;
- period_size = 0;
- buffer_time = 100000;
- period_time = 20000;
- totalTimeValue = 0;
- intervalTime = 1000;
- audioBuffer = 0;
- errorState = QAudio::NoError;
- deviceState = QAudio::StoppedState;
- audioSource = 0;
- pullMode = true;
- resuming = false;
- opened = false;
-
- m_volume = 1.0f;
-
- m_device = device;
-
- timer = new QTimer(this);
- connect(timer,SIGNAL(timeout()),SLOT(userFeed()));
-}
-
-QAlsaAudioOutput::~QAlsaAudioOutput()
-{
- close();
- disconnect(timer, SIGNAL(timeout()));
- QCoreApplication::processEvents();
- delete timer;
-}
-
-void QAlsaAudioOutput::setVolume(qreal vol)
-{
- m_volume = vol;
-}
-
-qreal QAlsaAudioOutput::volume() const
-{
- return m_volume;
-}
-
-QAudio::Error QAlsaAudioOutput::error() const
-{
- return errorState;
-}
-
-QAudio::State QAlsaAudioOutput::state() const
-{
- return deviceState;
-}
-
-int QAlsaAudioOutput::xrun_recovery(int err)
-{
- int count = 0;
- bool reset = false;
-
- // ESTRPIPE is not available in all OSes where ALSA is available
- int estrpipe = EIO;
-#ifdef ESTRPIPE
- estrpipe = ESTRPIPE;
-#endif
-
- if(err == -EPIPE) {
- errorState = QAudio::UnderrunError;
- emit errorChanged(errorState);
- err = snd_pcm_prepare(handle);
- if(err < 0)
- reset = true;
-
- } else if ((err == -estrpipe)||(err == -EIO)) {
- errorState = QAudio::IOError;
- emit errorChanged(errorState);
- while((err = snd_pcm_resume(handle)) == -EAGAIN){
- usleep(100);
- count++;
- if(count > 5) {
- reset = true;
- break;
- }
- }
- if(err < 0) {
- err = snd_pcm_prepare(handle);
- if(err < 0)
- reset = true;
- }
- }
- if(reset) {
- close();
- open();
- snd_pcm_prepare(handle);
- return 0;
- }
- return err;
-}
-
-int QAlsaAudioOutput::setFormat()
-{
- snd_pcm_format_t pcmformat = SND_PCM_FORMAT_UNKNOWN;
-
- if(settings.sampleSize() == 8) {
- pcmformat = SND_PCM_FORMAT_U8;
-
- } else if(settings.sampleSize() == 16) {
- if(settings.sampleType() == QAudioFormat::SignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- pcmformat = SND_PCM_FORMAT_S16_LE;
- else
- pcmformat = SND_PCM_FORMAT_S16_BE;
- } else if(settings.sampleType() == QAudioFormat::UnSignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- pcmformat = SND_PCM_FORMAT_U16_LE;
- else
- pcmformat = SND_PCM_FORMAT_U16_BE;
- }
- } else if(settings.sampleSize() == 24) {
- if(settings.sampleType() == QAudioFormat::SignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- pcmformat = SND_PCM_FORMAT_S24_LE;
- else
- pcmformat = SND_PCM_FORMAT_S24_BE;
- } else if(settings.sampleType() == QAudioFormat::UnSignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- pcmformat = SND_PCM_FORMAT_U24_LE;
- else
- pcmformat = SND_PCM_FORMAT_U24_BE;
- }
- } else if(settings.sampleSize() == 32) {
- if(settings.sampleType() == QAudioFormat::SignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- pcmformat = SND_PCM_FORMAT_S32_LE;
- else
- pcmformat = SND_PCM_FORMAT_S32_BE;
- } else if(settings.sampleType() == QAudioFormat::UnSignedInt) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- pcmformat = SND_PCM_FORMAT_U32_LE;
- else
- pcmformat = SND_PCM_FORMAT_U32_BE;
- } else if(settings.sampleType() == QAudioFormat::Float) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- pcmformat = SND_PCM_FORMAT_FLOAT_LE;
- else
- pcmformat = SND_PCM_FORMAT_FLOAT_BE;
- }
- } else if(settings.sampleSize() == 64) {
- if(settings.byteOrder() == QAudioFormat::LittleEndian)
- pcmformat = SND_PCM_FORMAT_FLOAT64_LE;
- else
- pcmformat = SND_PCM_FORMAT_FLOAT64_BE;
- }
-
- return pcmformat != SND_PCM_FORMAT_UNKNOWN
- ? snd_pcm_hw_params_set_format( handle, hwparams, pcmformat)
- : -1;
-}
-
-void QAlsaAudioOutput::start(QIODevice* device)
-{
- if(deviceState != QAudio::StoppedState)
- deviceState = QAudio::StoppedState;
-
- errorState = QAudio::NoError;
-
- // Handle change of mode
- if(audioSource && !pullMode) {
- delete audioSource;
- audioSource = 0;
- }
-
- close();
-
- pullMode = true;
- audioSource = device;
-
- deviceState = QAudio::ActiveState;
-
- open();
-
- emit stateChanged(deviceState);
-}
-
-QIODevice* QAlsaAudioOutput::start()
-{
- if(deviceState != QAudio::StoppedState)
- deviceState = QAudio::StoppedState;
-
- errorState = QAudio::NoError;
-
- // Handle change of mode
- if(audioSource && !pullMode) {
- delete audioSource;
- audioSource = 0;
- }
-
- close();
-
- audioSource = new AlsaOutputPrivate(this);
- audioSource->open(QIODevice::WriteOnly|QIODevice::Unbuffered);
- pullMode = false;
-
- deviceState = QAudio::IdleState;
-
- open();
-
- emit stateChanged(deviceState);
-
- return audioSource;
-}
-
-void QAlsaAudioOutput::stop()
-{
- if(deviceState == QAudio::StoppedState)
- return;
- errorState = QAudio::NoError;
- deviceState = QAudio::StoppedState;
- close();
- emit stateChanged(deviceState);
-}
-
-bool QAlsaAudioOutput::open()
-{
- if(opened)
- return true;
-
-#ifdef DEBUG_AUDIO
- QTime now(QTime::currentTime());
- qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
-#endif
- timeStamp.restart();
- elapsedTimeOffset = 0;
-
- int dir;
- int err = 0;
- int count=0;
- unsigned int sampleRate=settings.sampleRate();
-
- if (!settings.isValid()) {
- qWarning("QAudioOutput: open error, invalid format.");
- } else if (settings.sampleRate() <= 0) {
- qWarning("QAudioOutput: open error, invalid sample rate (%d).",
- settings.sampleRate());
- } else {
- err = -1;
- }
-
- if (err == 0) {
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit errorChanged(errorState);
- return false;
- }
-
- QString dev;
-#if SND_LIB_VERSION < 0x1000e // 1.0.14
- if (m_device != "default")
- dev = QAlsaAudioDeviceInfo::deviceFromCardName(m_device);
- else
-#endif
- dev = m_device;
-
- // Step 1: try and open the device
- while((count < 5) && (err < 0)) {
- err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
- if(err < 0)
- count++;
- }
- if (( err < 0)||(handle == 0)) {
- errorState = QAudio::OpenError;
- emit errorChanged(errorState);
- deviceState = QAudio::StoppedState;
- return false;
- }
- snd_pcm_nonblock( handle, 0 );
-
- // Step 2: Set the desired HW parameters.
- snd_pcm_hw_params_alloca( &hwparams );
-
- bool fatal = false;
- QString errMessage;
- unsigned int chunks = 8;
-
- err = snd_pcm_hw_params_any( handle, hwparams );
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_any: err = %1").arg(err);
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 );
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_access( handle, hwparams, access );
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_access: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = setFormat();
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_format: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channelCount() );
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_channels: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &sampleRate, 0 );
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- unsigned int maxBufferTime = 0;
- unsigned int minBufferTime = 0;
- unsigned int maxPeriodTime = 0;
- unsigned int minPeriodTime = 0;
-
- err = snd_pcm_hw_params_get_buffer_time_max(hwparams, &maxBufferTime, &dir);
- if ( err >= 0)
- err = snd_pcm_hw_params_get_buffer_time_min(hwparams, &minBufferTime, &dir);
- if ( err >= 0)
- err = snd_pcm_hw_params_get_period_time_max(hwparams, &maxPeriodTime, &dir);
- if ( err >= 0)
- err = snd_pcm_hw_params_get_period_time_min(hwparams, &minPeriodTime, &dir);
-
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: buffer/period min and max: err = %1").arg(err);
- } else {
- static unsigned user_buffer_time = qEnvironmentVariableIntValue("QT_ALSA_OUTPUT_BUFFER_TIME");
- static unsigned user_period_time = qEnvironmentVariableIntValue("QT_ALSA_OUTPUT_PERIOD_TIME");
- const bool outOfRange = maxBufferTime < buffer_time || buffer_time < minBufferTime || maxPeriodTime < period_time || minPeriodTime > period_time;
- if (outOfRange || user_period_time || user_buffer_time) {
- period_time = user_period_time ? user_period_time : minPeriodTime;
- if (!user_buffer_time) {
- chunks = maxBufferTime / period_time;
- buffer_time = period_time * chunks;
- } else {
- buffer_time = user_buffer_time;
- chunks = buffer_time / period_time;
- }
- }
- qCDebug(lcAlsaOutput) << "buffer time: [" << minBufferTime << "-" << maxBufferTime << "] =" << buffer_time;
- qCDebug(lcAlsaOutput) << "period time: [" << minPeriodTime << "-" << maxPeriodTime << "] =" << period_time;
- qCDebug(lcAlsaOutput) << "chunks =" << chunks;
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir);
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir);
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err);
- }
- }
- if ( !fatal ) {
- err = snd_pcm_hw_params(handle, hwparams);
- if ( err < 0 ) {
- fatal = true;
- errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params: err = %1").arg(err);
- }
- }
- if( err < 0) {
- qWarning()<<errMessage;
- errorState = QAudio::OpenError;
- emit errorChanged(errorState);
- deviceState = QAudio::StoppedState;
- return false;
- }
- snd_pcm_hw_params_get_buffer_size(hwparams,&buffer_frames);
- buffer_size = snd_pcm_frames_to_bytes(handle,buffer_frames);
- snd_pcm_hw_params_get_period_size(hwparams,&period_frames, &dir);
- period_size = snd_pcm_frames_to_bytes(handle,period_frames);
- snd_pcm_hw_params_get_buffer_time(hwparams,&buffer_time, &dir);
- snd_pcm_hw_params_get_period_time(hwparams,&period_time, &dir);
-
- // Step 3: Set the desired SW parameters.
- snd_pcm_sw_params_t *swparams;
- snd_pcm_sw_params_alloca(&swparams);
- snd_pcm_sw_params_current(handle, swparams);
- snd_pcm_sw_params_set_start_threshold(handle,swparams,period_frames);
- snd_pcm_sw_params_set_stop_threshold(handle,swparams,buffer_frames);
- snd_pcm_sw_params_set_avail_min(handle, swparams,period_frames);
- snd_pcm_sw_params(handle, swparams);
-
- // Step 4: Prepare audio
- if(audioBuffer == 0)
- audioBuffer = new char[snd_pcm_frames_to_bytes(handle,buffer_frames)];
- snd_pcm_prepare( handle );
- snd_pcm_start(handle);
-
- // Step 5: Setup timer
- bytesAvailable = bytesFree();
-
- // Step 6: Start audio processing
- timer->start(period_time/1000);
-
- clockStamp.restart();
- timeStamp.restart();
- elapsedTimeOffset = 0;
- errorState = QAudio::NoError;
- totalTimeValue = 0;
- opened = true;
-
- return true;
-}
-
-void QAlsaAudioOutput::close()
-{
- timer->stop();
-
- if ( handle ) {
- snd_pcm_drain( handle );
- snd_pcm_close( handle );
- handle = 0;
- delete [] audioBuffer;
- audioBuffer=0;
- }
- if(!pullMode && audioSource) {
- delete audioSource;
- audioSource = 0;
- }
- opened = false;
-}
-
-int QAlsaAudioOutput::bytesFree() const
-{
- if(resuming)
- return period_size;
-
- if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
- return 0;
-
- int frames = snd_pcm_avail_update(handle);
- if (frames == -EPIPE) {
- // Try and handle buffer underrun
- int err = snd_pcm_recover(handle, frames, 0);
- if (err < 0)
- return 0;
- else
- frames = snd_pcm_avail_update(handle);
- } else if (frames < 0) {
- return 0;
- }
-
- if ((int)frames > (int)buffer_frames)
- frames = buffer_frames;
-
- return snd_pcm_frames_to_bytes(handle, frames);
-}
-
-qint64 QAlsaAudioOutput::write( const char *data, qint64 len )
-{
- // Write out some audio data
- if ( !handle )
- return 0;
-#ifdef DEBUG_AUDIO
- qDebug()<<"frames to write out = "<<
- snd_pcm_bytes_to_frames( handle, (int)len )<<" ("<<len<<") bytes";
-#endif
- int frames, err;
- int space = bytesFree();
-
- if (!space)
- return 0;
-
- if (len < space)
- space = len;
-
- frames = snd_pcm_bytes_to_frames(handle, space);
-
- if (m_volume < 1.0f) {
- QVarLengthArray<char, 4096> out(space);
- QAudioHelperInternal::qMultiplySamples(m_volume, settings, data, out.data(), space);
- err = snd_pcm_writei(handle, out.constData(), frames);
- } else {
- err = snd_pcm_writei(handle, data, frames);
- }
-
- if(err > 0) {
- totalTimeValue += err;
- resuming = false;
- errorState = QAudio::NoError;
- if (deviceState != QAudio::ActiveState) {
- deviceState = QAudio::ActiveState;
- emit stateChanged(deviceState);
- }
- return snd_pcm_frames_to_bytes( handle, err );
- } else
- err = xrun_recovery(err);
-
- if(err < 0) {
- close();
- errorState = QAudio::FatalError;
- emit errorChanged(errorState);
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- }
- return 0;
-}
-
-int QAlsaAudioOutput::periodSize() const
-{
- return period_size;
-}
-
-void QAlsaAudioOutput::setBufferSize(int value)
-{
- if(deviceState == QAudio::StoppedState)
- buffer_size = value;
-}
-
-int QAlsaAudioOutput::bufferSize() const
-{
- return buffer_size;
-}
-
-void QAlsaAudioOutput::setNotifyInterval(int ms)
-{
- intervalTime = qMax(0, ms);
-}
-
-int QAlsaAudioOutput::notifyInterval() const
-{
- return intervalTime;
-}
-
-qint64 QAlsaAudioOutput::processedUSecs() const
-{
- return qint64(1000000) * totalTimeValue / settings.sampleRate();
-}
-
-void QAlsaAudioOutput::resume()
-{
- if(deviceState == QAudio::SuspendedState) {
- int err = 0;
-
- if(handle) {
- err = snd_pcm_prepare( handle );
- if(err < 0)
- xrun_recovery(err);
-
- err = snd_pcm_start(handle);
- if(err < 0)
- xrun_recovery(err);
-
- bytesAvailable = (int)snd_pcm_frames_to_bytes(handle, buffer_frames);
- }
- resuming = true;
-
- deviceState = pullMode ? QAudio::ActiveState : QAudio::IdleState;
-
- errorState = QAudio::NoError;
- timer->start(period_time/1000);
- emit stateChanged(deviceState);
- }
-}
-
-void QAlsaAudioOutput::setFormat(const QAudioFormat& fmt)
-{
- if (deviceState == QAudio::StoppedState)
- settings = fmt;
-}
-
-QAudioFormat QAlsaAudioOutput::format() const
-{
- return settings;
-}
-
-void QAlsaAudioOutput::suspend()
-{
- if(deviceState == QAudio::ActiveState || deviceState == QAudio::IdleState || resuming) {
- snd_pcm_drain(handle);
- timer->stop();
- deviceState = QAudio::SuspendedState;
- errorState = QAudio::NoError;
- emit stateChanged(deviceState);
- }
-}
-
-void QAlsaAudioOutput::userFeed()
-{
- if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState)
- return;
-#ifdef DEBUG_AUDIO
- QTime now(QTime::currentTime());
- qDebug()<<now.second()<<"s "<<now.msec()<<"ms :userFeed() OUT";
-#endif
- if(deviceState == QAudio::IdleState)
- bytesAvailable = bytesFree();
-
- deviceReady();
-}
-
-bool QAlsaAudioOutput::deviceReady()
-{
- if(pullMode) {
- int l = 0;
- int chunks = bytesAvailable/period_size;
- if(chunks==0) {
- bytesAvailable = bytesFree();
- return false;
- }
-#ifdef DEBUG_AUDIO
- qDebug()<<"deviceReady() avail="<<bytesAvailable<<" bytes, period size="<<period_size<<" bytes";
- qDebug()<<"deviceReady() no. of chunks that can fit ="<<chunks<<", chunks in bytes ="<<period_size*chunks;
-#endif
- int input = period_frames*chunks;
- if(input > (int)buffer_frames)
- input = buffer_frames;
- l = audioSource->read(audioBuffer,snd_pcm_frames_to_bytes(handle, input));
-
- // reading can take a while and stream may have been stopped
- if (!handle)
- return false;
-
- if(l > 0) {
- // Got some data to output
- if (deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
- return true;
- qint64 bytesWritten = write(audioBuffer,l);
- if (bytesWritten != l)
- audioSource->seek(audioSource->pos()-(l-bytesWritten));
- bytesAvailable = bytesFree();
-
- } else if(l == 0) {
- // Did not get any data to output
- bytesAvailable = bytesFree();
- if(bytesAvailable > snd_pcm_frames_to_bytes(handle, buffer_frames-period_frames)) {
- // Underrun
- if (deviceState != QAudio::IdleState) {
- errorState = QAudio::UnderrunError;
- emit errorChanged(errorState);
- deviceState = QAudio::IdleState;
- emit stateChanged(deviceState);
- }
- }
-
- } else if(l < 0) {
- close();
- deviceState = QAudio::StoppedState;
- errorState = QAudio::IOError;
- emit errorChanged(errorState);
- emit stateChanged(deviceState);
- }
- } else {
- bytesAvailable = bytesFree();
- if(bytesAvailable > snd_pcm_frames_to_bytes(handle, buffer_frames-period_frames)) {
- // Underrun
- if (deviceState != QAudio::IdleState) {
- errorState = QAudio::UnderrunError;
- emit errorChanged(errorState);
- deviceState = QAudio::IdleState;
- emit stateChanged(deviceState);
- }
- }
- }
-
- if(deviceState != QAudio::ActiveState)
- return true;
-
- if(intervalTime && (timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
- emit notify();
- elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime;
- timeStamp.restart();
- }
- return true;
-}
-
-qint64 QAlsaAudioOutput::elapsedUSecs() const
-{
- if (deviceState == QAudio::StoppedState)
- return 0;
-
- return clockStamp.elapsed() * qint64(1000);
-}
-
-void QAlsaAudioOutput::reset()
-{
- if(handle)
- snd_pcm_reset(handle);
-
- stop();
-}
-
-AlsaOutputPrivate::AlsaOutputPrivate(QAlsaAudioOutput* audio)
-{
- audioDevice = qobject_cast<QAlsaAudioOutput*>(audio);
-}
-
-AlsaOutputPrivate::~AlsaOutputPrivate() {}
-
-qint64 AlsaOutputPrivate::readData( char* data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
-
- return 0;
-}
-
-qint64 AlsaOutputPrivate::writeData(const char* data, qint64 len)
-{
- int retry = 0;
- qint64 written = 0;
- if((audioDevice->deviceState == QAudio::ActiveState)
- ||(audioDevice->deviceState == QAudio::IdleState)) {
- while(written < len) {
- int chunk = audioDevice->write(data+written,(len-written));
- if(chunk <= 0)
- retry++;
- written+=chunk;
- if(retry > 10)
- return written;
- }
- }
- return written;
-
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qalsaaudiooutput.cpp"
diff --git a/src/plugins/alsa/qalsaaudiooutput.h b/src/plugins/alsa/qalsaaudiooutput.h
deleted file mode 100644
index 72b9c2e4c..000000000
--- a/src/plugins/alsa/qalsaaudiooutput.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifndef QAUDIOOUTPUTALSA_H
-#define QAUDIOOUTPUTALSA_H
-
-#include <alsa/asoundlib.h>
-
-#include <QtCore/qfile.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qtimer.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qelapsedtimer.h>
-#include <QtCore/qiodevice.h>
-
-#include <QtMultimedia/qaudio.h>
-#include <QtMultimedia/qaudiodeviceinfo.h>
-#include <QtMultimedia/qaudiosystem.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAlsaAudioOutput : public QAbstractAudioOutput
-{
- friend class AlsaOutputPrivate;
- Q_OBJECT
-public:
- QAlsaAudioOutput(const QByteArray &device);
- ~QAlsaAudioOutput();
-
- qint64 write( const char *data, qint64 len );
-
- void start(QIODevice* device) override;
- QIODevice* start() override;
- void stop() override;
- void reset() override;
- void suspend() override;
- void resume() override;
- int bytesFree() const override;
- int periodSize() const override;
- void setBufferSize(int value) override;
- int bufferSize() const override;
- void setNotifyInterval(int milliSeconds) override;
- int notifyInterval() const override;
- qint64 processedUSecs() const override;
- qint64 elapsedUSecs() const override;
- QAudio::Error error() const override;
- QAudio::State state() const override;
- void setFormat(const QAudioFormat& fmt) override;
- QAudioFormat format() const override;
- void setVolume(qreal) override;
- qreal volume() const override;
-
-
- QIODevice* audioSource;
- QAudioFormat settings;
- QAudio::Error errorState;
- QAudio::State deviceState;
-
-private slots:
- void userFeed();
- bool deviceReady();
-
-signals:
- void processMore();
-
-private:
- bool opened;
- bool pullMode;
- bool resuming;
- int buffer_size;
- int period_size;
- int intervalTime;
- qint64 totalTimeValue;
- unsigned int buffer_time;
- unsigned int period_time;
- snd_pcm_uframes_t buffer_frames;
- snd_pcm_uframes_t period_frames;
- int xrun_recovery(int err);
-
- int setFormat();
- bool open();
- void close();
-
- QTimer* timer;
- QByteArray m_device;
- int bytesAvailable;
- QElapsedTimer timeStamp;
- QElapsedTimer clockStamp;
- qint64 elapsedTimeOffset;
- char* audioBuffer;
- snd_pcm_t* handle;
- snd_pcm_access_t access;
- snd_pcm_format_t pcmformat;
- snd_pcm_hw_params_t *hwparams;
- qreal m_volume;
-};
-
-class AlsaOutputPrivate : public QIODevice
-{
- friend class QAlsaAudioOutput;
- Q_OBJECT
-public:
- AlsaOutputPrivate(QAlsaAudioOutput* audio);
- ~AlsaOutputPrivate();
-
- qint64 readData( char* data, qint64 len) override;
- qint64 writeData(const char* data, qint64 len) override;
-
-private:
- QAlsaAudioOutput *audioDevice;
-};
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/plugins/alsa/qalsaplugin.cpp b/src/plugins/alsa/qalsaplugin.cpp
deleted file mode 100644
index e52e9ee83..000000000
--- a/src/plugins/alsa/qalsaplugin.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qalsaplugin.h"
-#include "qalsaaudiodeviceinfo.h"
-#include "qalsaaudioinput.h"
-#include "qalsaaudiooutput.h"
-
-QT_BEGIN_NAMESPACE
-
-QAlsaPlugin::QAlsaPlugin(QObject *parent)
- : QAudioSystemPlugin(parent)
-{
-}
-
-QByteArray QAlsaPlugin::defaultDevice(QAudio::Mode mode) const
-{
- return QAlsaAudioDeviceInfo::defaultDevice(mode);
-}
-
-QList<QByteArray> QAlsaPlugin::availableDevices(QAudio::Mode mode) const
-{
- return QAlsaAudioDeviceInfo::availableDevices(mode);
-}
-
-QAbstractAudioInput *QAlsaPlugin::createInput(const QByteArray &device)
-{
- return new QAlsaAudioInput(device);
-}
-
-QAbstractAudioOutput *QAlsaPlugin::createOutput(const QByteArray &device)
-{
- return new QAlsaAudioOutput(device);
-}
-
-QAbstractAudioDeviceInfo *QAlsaPlugin::createDeviceInfo(const QByteArray &device, QAudio::Mode mode)
-{
- return new QAlsaAudioDeviceInfo(device, mode);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/alsa/qalsaplugin.h b/src/plugins/alsa/qalsaplugin.h
deleted file mode 100644
index cebede13b..000000000
--- a/src/plugins/alsa/qalsaplugin.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QALSAPLUGIN_H
-#define QALSAPLUGIN_H
-
-#include <QtMultimedia/qaudiosystemplugin.h>
-#include <QtMultimedia/private/qaudiosystempluginext_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAlsaPlugin : public QAudioSystemPlugin, public QAudioSystemPluginExtension
-{
- Q_OBJECT
-
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.audiosystemfactory/5.0" FILE "alsa.json")
- Q_INTERFACES(QAudioSystemPluginExtension)
-
-public:
- QAlsaPlugin(QObject *parent = 0);
- ~QAlsaPlugin() {}
-
- QByteArray defaultDevice(QAudio::Mode mode) const override;
- QList<QByteArray> availableDevices(QAudio::Mode mode) const override;
- QAbstractAudioInput *createInput(const QByteArray &device) override;
- QAbstractAudioOutput *createOutput(const QByteArray &device) override;
- QAbstractAudioDeviceInfo *createDeviceInfo(const QByteArray &device, QAudio::Mode mode) override;
-};
-
-QT_END_NAMESPACE
-
-#endif // QALSAPLUGIN_H
diff --git a/src/plugins/android/android.pro b/src/plugins/android/android.pro
deleted file mode 100644
index 37d11c86b..000000000
--- a/src/plugins/android/android.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS += src
-android: SUBDIRS += jar
diff --git a/src/plugins/android/jar/jar.pro b/src/plugins/android/jar/jar.pro
deleted file mode 100644
index 0ef830f32..000000000
--- a/src/plugins/android/jar/jar.pro
+++ /dev/null
@@ -1,21 +0,0 @@
-TARGET = Qt$${QT_MAJOR_VERSION}AndroidMultimedia
-
-load(qt_build_paths)
-CONFIG += java
-DESTDIR = $$MODULE_BASE_OUTDIR/jar
-
-JAVACLASSPATH += $$PWD/src
-
-JAVASOURCES += $$PWD/src/org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer.java \
- $$PWD/src/org/qtproject/qt/android/multimedia/QtCameraListener.java \
- $$PWD/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureListener.java \
- $$PWD/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder.java \
- $$PWD/src/org/qtproject/qt/android/multimedia/QtMultimediaUtils.java \
- $$PWD/src/org/qtproject/qt/android/multimedia/QtMediaRecorderListener.java \
- $$PWD/src/org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback.java
-
-# install
-target.path = $$[QT_INSTALL_PREFIX]/jar
-INSTALLS += target
-
-OTHER_FILES += $$JAVASOURCES
diff --git a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer.java b/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer.java
deleted file mode 100644
index aa706179c..000000000
--- a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer.java
+++ /dev/null
@@ -1,590 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtMultimedia of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt.android.multimedia;
-
-import java.io.IOException;
-import java.lang.String;
-import java.util.HashMap;
-import java.io.FileInputStream;
-
-// API is level is < 9 unless marked otherwise.
-import android.content.Context;
-import android.media.MediaPlayer;
-import android.media.AudioAttributes;
-import android.net.Uri;
-import android.util.Log;
-import java.io.FileDescriptor;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.view.SurfaceHolder;
-
-public class QtAndroidMediaPlayer
-{
- // Native callback functions for MediaPlayer
- native public void onErrorNative(int what, int extra, long id);
- native public void onBufferingUpdateNative(int percent, long id);
- native public void onProgressUpdateNative(int progress, long id);
- native public void onDurationChangedNative(int duration, long id);
- native public void onInfoNative(int what, int extra, long id);
- native public void onVideoSizeChangedNative(int width, int height, long id);
- native public void onStateChangedNative(int state, long id);
-
- private MediaPlayer mMediaPlayer = null;
- private AudioAttributes mAudioAttributes = null;
- private HashMap<String, String> mHeaders = null;
- private Uri mUri = null;
- private final long mID;
- private final Context mContext;
- private boolean mMuted = false;
- private int mVolume = 100;
- private static final String TAG = "Qt MediaPlayer";
- private SurfaceHolder mSurfaceHolder = null;
-
- private class State {
- final static int Uninitialized = 0x1 /* End */;
- final static int Idle = 0x2;
- final static int Preparing = 0x4;
- final static int Prepared = 0x8;
- final static int Initialized = 0x10;
- final static int Started = 0x20;
- final static int Stopped = 0x40;
- final static int Paused = 0x80;
- final static int PlaybackCompleted = 0x100;
- final static int Error = 0x200;
- }
-
- private volatile int mState = State.Uninitialized;
-
- /**
- * MediaPlayer OnErrorListener
- */
- private class MediaPlayerErrorListener
- implements MediaPlayer.OnErrorListener
- {
- @Override
- public boolean onError(final MediaPlayer mp,
- final int what,
- final int extra)
- {
- setState(State.Error);
- onErrorNative(what, extra, mID);
- return true;
- }
-
- }
-
- /**
- * MediaPlayer OnBufferingListener
- */
- private class MediaPlayerBufferingListener
- implements MediaPlayer.OnBufferingUpdateListener
- {
- private int mBufferPercent = -1;
- @Override
- public void onBufferingUpdate(final android.media.MediaPlayer mp,
- final int percent)
- {
- // Avoid updates when percent is unchanged.
- // E.g., we keep getting updates when percent == 100
- if (mBufferPercent == percent)
- return;
-
- onBufferingUpdateNative((mBufferPercent = percent), mID);
- }
-
- }
-
- /**
- * MediaPlayer OnCompletionListener
- */
- private class MediaPlayerCompletionListener
- implements MediaPlayer.OnCompletionListener
- {
- @Override
- public void onCompletion(final MediaPlayer mp)
- {
- setState(State.PlaybackCompleted);
- }
-
- }
-
- /**
- * MediaPlayer OnInfoListener
- */
- private class MediaPlayerInfoListener
- implements MediaPlayer.OnInfoListener
- {
- @Override
- public boolean onInfo(final MediaPlayer mp,
- final int what,
- final int extra)
- {
- onInfoNative(what, extra, mID);
- return true;
- }
-
- }
-
- /**
- * MediaPlayer OnPreparedListener
- */
- private class MediaPlayerPreparedListener
- implements MediaPlayer.OnPreparedListener
- {
-
- @Override
- public void onPrepared(final MediaPlayer mp)
- {
- setState(State.Prepared);
- onDurationChangedNative(getDuration(), mID);
- }
-
- }
-
- /**
- * MediaPlayer OnSeekCompleteListener
- */
- private class MediaPlayerSeekCompleteListener
- implements MediaPlayer.OnSeekCompleteListener
- {
-
- @Override
- public void onSeekComplete(final MediaPlayer mp)
- {
- onProgressUpdateNative(getCurrentPosition(), mID);
- }
-
- }
-
- /**
- * MediaPlayer OnVideoSizeChangedListener
- */
- private class MediaPlayerVideoSizeChangedListener
- implements MediaPlayer.OnVideoSizeChangedListener
- {
-
- @Override
- public void onVideoSizeChanged(final MediaPlayer mp,
- final int width,
- final int height)
- {
- onVideoSizeChangedNative(width, height, mID);
- }
-
- }
-
- public QtAndroidMediaPlayer(final Context context, final long id)
- {
- mID = id;
- mContext = context;
- }
-
- public MediaPlayer getMediaPlayerHandle()
- {
- return mMediaPlayer;
- }
-
- private void setState(int state)
- {
- if (mState == state)
- return;
-
- mState = state;
-
- onStateChangedNative(mState, mID);
- }
-
-
- private void init()
- {
- if (mMediaPlayer == null) {
- mMediaPlayer = new MediaPlayer();
- setState(State.Idle);
- // Make sure the new media player has the volume that was set on the QMediaPlayer
- setVolumeHelper(mMuted ? 0 : mVolume);
- setAudioAttributes(mMediaPlayer, mAudioAttributes);
- }
- }
-
- public void start()
- {
- if ((mState & (State.Prepared
- | State.Started
- | State.Paused
- | State.PlaybackCompleted)) == 0) {
- return;
- }
-
- try {
- mMediaPlayer.start();
- setState(State.Started);
- } catch (final IllegalStateException e) {
- Log.d(TAG, "" + e.getMessage());
- }
- }
-
-
- public void pause()
- {
- if ((mState & (State.Started | State.Paused | State.PlaybackCompleted)) == 0)
- return;
-
- try {
- mMediaPlayer.pause();
- setState(State.Paused);
- } catch (final IllegalStateException e) {
- Log.d(TAG, "" + e.getMessage());
- }
- }
-
-
- public void stop()
- {
- if ((mState & (State.Prepared
- | State.Started
- | State.Stopped
- | State.Paused
- | State.PlaybackCompleted)) == 0) {
- return;
- }
-
- try {
- mMediaPlayer.stop();
- setState(State.Stopped);
- } catch (final IllegalStateException e) {
- Log.d(TAG, "" + e.getMessage());
- }
- }
-
-
- public void seekTo(final int msec)
- {
- if ((mState & (State.Prepared
- | State.Started
- | State.Paused
- | State.PlaybackCompleted)) == 0) {
- return;
- }
-
- try {
- mMediaPlayer.seekTo(msec);
- } catch (final IllegalStateException e) {
- Log.d(TAG, "" + e.getMessage());
- }
- }
-
-
- public boolean isPlaying()
- {
- boolean playing = false;
- if ((mState & (State.Idle
- | State.Initialized
- | State.Prepared
- | State.Started
- | State.Paused
- | State.Stopped
- | State.PlaybackCompleted)) == 0) {
- return playing;
- }
-
- try {
- playing = mMediaPlayer.isPlaying();
- } catch (final IllegalStateException e) {
- Log.d(TAG, "" + e.getMessage());
- }
-
- return playing;
- }
-
- public void prepareAsync()
- {
- if ((mState & (State.Initialized | State.Stopped)) == 0)
- return;
-
- try {
- mMediaPlayer.prepareAsync();
- setState(State.Preparing);
- } catch (final IllegalStateException e) {
- Log.d(TAG, "" + e.getMessage());
- }
- }
-
- public void initHeaders()
- {
- mHeaders = new HashMap<String, String>();
- }
-
- public void setHeader(final String header, final String value)
- {
- mHeaders.put(header, value);
- }
-
- public void setDataSource(final String path)
- {
- if ((mState & State.Uninitialized) != 0)
- init();
-
- if ((mState & State.Idle) == 0)
- return;
-
- mMediaPlayer.setOnBufferingUpdateListener(new MediaPlayerBufferingListener());
- mMediaPlayer.setOnCompletionListener(new MediaPlayerCompletionListener());
- mMediaPlayer.setOnInfoListener(new MediaPlayerInfoListener());
- mMediaPlayer.setOnSeekCompleteListener(new MediaPlayerSeekCompleteListener());
- mMediaPlayer.setOnVideoSizeChangedListener(new MediaPlayerVideoSizeChangedListener());
- mMediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
- mMediaPlayer.setOnPreparedListener(new MediaPlayerPreparedListener());
-
- if (mSurfaceHolder != null)
- mMediaPlayer.setDisplay(mSurfaceHolder);
-
- AssetFileDescriptor afd = null;
- FileInputStream fis = null;
- try {
- mUri = Uri.parse(path);
- final boolean inAssets = (mUri.getScheme().compareTo("assets") == 0);
- if (inAssets) {
- final String asset = mUri.getPath().substring(1 /* Remove first '/' */);
- final AssetManager am = mContext.getAssets();
- afd = am.openFd(asset);
- final long offset = afd.getStartOffset();
- final long length = afd.getLength();
- FileDescriptor fd = afd.getFileDescriptor();
- mMediaPlayer.setDataSource(fd, offset, length);
- } else if (mUri.getScheme().compareTo("file") == 0) {
- fis = new FileInputStream(mUri.getPath());
- FileDescriptor fd = fis.getFD();
- mMediaPlayer.setDataSource(fd);
- } else {
- if (mHeaders.isEmpty())
- mMediaPlayer.setDataSource(path);
- else
- mMediaPlayer.setDataSource(mContext, mUri, mHeaders);
- }
- setState(State.Initialized);
- } catch (final IOException e) {
- Log.d(TAG, "" + e.getMessage());
- } catch (final IllegalArgumentException e) {
- Log.d(TAG, "" + e.getMessage());
- } catch (final SecurityException e) {
- Log.d(TAG, "" + e.getMessage());
- } catch (final IllegalStateException e) {
- Log.d(TAG, "" + e.getMessage());
- } catch (final NullPointerException e) {
- Log.d(TAG, "" + e.getMessage());
- } finally {
- try {
- if (afd != null)
- afd.close();
- if (fis != null)
- fis.close();
- } catch (final IOException ioe) { /* Ignore... */ }
-
- if ((mState & State.Initialized) == 0) {
- setState(State.Error);
- onErrorNative(MediaPlayer.MEDIA_ERROR_UNKNOWN,
- -1004 /*MEDIA_ERROR_IO*/,
- mID);
- return;
- }
- }
- }
-
-
- public int getCurrentPosition()
- {
- int currentPosition = 0;
- if ((mState & (State.Idle
- | State.Initialized
- | State.Prepared
- | State.Started
- | State.Paused
- | State.Stopped
- | State.PlaybackCompleted)) == 0) {
- return currentPosition;
- }
-
- try {
- currentPosition = mMediaPlayer.getCurrentPosition();
- } catch (final IllegalStateException e) {
- Log.d(TAG, "" + e.getMessage());
- }
-
- return currentPosition;
- }
-
-
- public int getDuration()
- {
- int duration = 0;
- if ((mState & (State.Prepared
- | State.Started
- | State.Paused
- | State.Stopped
- | State.PlaybackCompleted)) == 0) {
- return duration;
- }
-
- try {
- duration = mMediaPlayer.getDuration();
- } catch (final IllegalStateException e) {
- Log.d(TAG, "" + e.getMessage());
- }
-
- return duration;
- }
-
- public void setVolume(int volume)
- {
- if (volume < 0)
- volume = 0;
-
- if (volume > 100)
- volume = 100;
-
- mVolume = volume;
-
- if (!mMuted)
- setVolumeHelper(mVolume);
- }
-
- private void setVolumeHelper(int volume)
- {
- if ((mState & (State.Idle
- | State.Initialized
- | State.Stopped
- | State.Prepared
- | State.Started
- | State.Paused
- | State.PlaybackCompleted)) == 0) {
- return;
- }
-
- try {
- float newVolume = (float)volume / 100;
- mMediaPlayer.setVolume(newVolume, newVolume);
- } catch (final IllegalStateException e) {
- Log.d(TAG, "" + e.getMessage());
- }
- }
-
- public SurfaceHolder display()
- {
- return mSurfaceHolder;
- }
-
- public void setDisplay(SurfaceHolder sh)
- {
- mSurfaceHolder = sh;
-
- if ((mState & State.Uninitialized) != 0)
- return;
-
- mMediaPlayer.setDisplay(mSurfaceHolder);
- }
-
-
- public int getVolume()
- {
- return mVolume;
- }
-
- public void mute(final boolean mute)
- {
- mMuted = mute;
- setVolumeHelper(mute ? 0 : mVolume);
- }
-
- public boolean isMuted()
- {
- return mMuted;
- }
-
-
- public void reset()
- {
- if ((mState & (State.Idle
- | State.Initialized
- | State.Prepared
- | State.Started
- | State.Paused
- | State.Stopped
- | State.PlaybackCompleted
- | State.Error)) == 0) {
- return;
- }
-
- mMediaPlayer.reset();
- setState(State.Idle);
- }
-
- public void release()
- {
- if (mMediaPlayer != null) {
- mMediaPlayer.reset();
- mMediaPlayer.release();
- mMediaPlayer = null;
- }
-
- setState(State.Uninitialized);
- }
-
- public void setAudioAttributes(int type, int usage)
- {
- mAudioAttributes = new AudioAttributes.Builder()
- .setUsage(usage)
- .setContentType(type)
- .build();
-
- setAudioAttributes(mMediaPlayer, mAudioAttributes);
- }
-
- static private void setAudioAttributes(MediaPlayer player, AudioAttributes attr)
- {
- if (player == null || attr == null)
- return;
-
- try {
- player.setAudioAttributes(attr);
- } catch (final IllegalArgumentException e) {
- Log.d(TAG, "" + e.getMessage());
- }
- }
-}
diff --git a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtCameraListener.java b/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtCameraListener.java
deleted file mode 100644
index ff26d90c3..000000000
--- a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtCameraListener.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtMultimedia of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt.android.multimedia;
-
-import android.hardware.Camera;
-import android.graphics.ImageFormat;
-import android.graphics.SurfaceTexture;
-import android.util.Log;
-import java.lang.Math;
-
-public class QtCameraListener implements Camera.ShutterCallback,
- Camera.PictureCallback,
- Camera.AutoFocusCallback,
- Camera.PreviewCallback
-{
- private static final String TAG = "Qt Camera";
-
- private static final int BUFFER_POOL_SIZE = 2;
-
- private int m_cameraId = -1;
-
- private boolean m_notifyNewFrames = false;
- private boolean m_notifyWhenFrameAvailable = false;
- private byte[][] m_previewBuffers = null;
- private byte[] m_lastPreviewBuffer = null;
- private Camera.Size m_previewSize = null;
- private int m_previewFormat = ImageFormat.NV21; // Default preview format on all devices
- private int m_previewBytesPerLine = -1;
-
- private QtCameraListener(int id)
- {
- m_cameraId = id;
- }
-
- public void notifyNewFrames(boolean notify)
- {
- m_notifyNewFrames = notify;
- }
-
- public void notifyWhenFrameAvailable(boolean notify)
- {
- m_notifyWhenFrameAvailable = notify;
- }
-
- public byte[] lastPreviewBuffer()
- {
- return m_lastPreviewBuffer;
- }
-
- public int previewWidth()
- {
- if (m_previewSize == null)
- return -1;
-
- return m_previewSize.width;
- }
-
- public int previewHeight()
- {
- if (m_previewSize == null)
- return -1;
-
- return m_previewSize.height;
- }
-
- public int previewFormat()
- {
- return m_previewFormat;
- }
-
- public int previewBytesPerLine()
- {
- return m_previewBytesPerLine;
- }
-
- public void clearPreviewCallback(Camera camera)
- {
- camera.setPreviewCallbackWithBuffer(null);
- }
-
- public void setupPreviewCallback(Camera camera)
- {
- // Clear previous callback (also clears added buffers)
- clearPreviewCallback(camera);
- m_lastPreviewBuffer = null;
-
- final Camera.Parameters params = camera.getParameters();
- m_previewSize = params.getPreviewSize();
- m_previewFormat = params.getPreviewFormat();
-
- int bufferSizeNeeded = 0;
- if (m_previewFormat == ImageFormat.YV12) {
- // For YV12, bytes per line must be a multiple of 16
- final int yStride = (int) Math.ceil(m_previewSize.width / 16.0) * 16;
- final int uvStride = (int) Math.ceil((yStride / 2) / 16.0) * 16;
- final int ySize = yStride * m_previewSize.height;
- final int uvSize = uvStride * m_previewSize.height / 2;
- bufferSizeNeeded = ySize + uvSize * 2;
-
- m_previewBytesPerLine = yStride;
-
- } else {
- double bytesPerPixel = ImageFormat.getBitsPerPixel(m_previewFormat) / 8.0;
- bufferSizeNeeded = (int) Math.ceil(bytesPerPixel * m_previewSize.width * m_previewSize.height);
-
- // bytes per line are calculated only for the first plane
- switch (m_previewFormat) {
- case ImageFormat.NV21:
- m_previewBytesPerLine = m_previewSize.width; // 1 byte per sample and tightly packed
- break;
- case ImageFormat.RGB_565:
- case ImageFormat.YUY2:
- m_previewBytesPerLine = m_previewSize.width * 2; // 2 bytes per pixel
- break;
- default:
- m_previewBytesPerLine = -1;
- break;
- }
- }
-
- // We could keep the same buffers when they are already bigger than the required size
- // but the Android doc says the size must match, so in doubt just replace them.
- if (m_previewBuffers == null || m_previewBuffers[0].length != bufferSizeNeeded)
- m_previewBuffers = new byte[BUFFER_POOL_SIZE][bufferSizeNeeded];
-
- // Add callback and queue all buffers
- camera.setPreviewCallbackWithBuffer(this);
- for (byte[] buffer : m_previewBuffers)
- camera.addCallbackBuffer(buffer);
- }
-
- @Override
- public void onPreviewFrame(byte[] data, Camera camera)
- {
- // Re-enqueue the last buffer
- if (m_lastPreviewBuffer != null)
- camera.addCallbackBuffer(m_lastPreviewBuffer);
-
- m_lastPreviewBuffer = data;
-
- if (data != null) {
- if (m_notifyWhenFrameAvailable) {
- m_notifyWhenFrameAvailable = false;
- notifyFrameAvailable(m_cameraId);
- }
- if (m_notifyNewFrames) {
- notifyNewPreviewFrame(m_cameraId, data,
- m_previewSize.width, m_previewSize.height,
- m_previewFormat,
- m_previewBytesPerLine);
- }
- }
- }
-
- @Override
- public void onShutter()
- {
- notifyPictureExposed(m_cameraId);
- }
-
- @Override
- public void onPictureTaken(byte[] data, Camera camera)
- {
- notifyPictureCaptured(m_cameraId, data);
- }
-
- @Override
- public void onAutoFocus(boolean success, Camera camera)
- {
- notifyAutoFocusComplete(m_cameraId, success);
- }
-
- private static native void notifyAutoFocusComplete(int id, boolean success);
- private static native void notifyPictureExposed(int id);
- private static native void notifyPictureCaptured(int id, byte[] data);
- private static native void notifyNewPreviewFrame(int id, byte[] data, int width, int height,
- int pixelFormat, int bytesPerLine);
- private static native void notifyFrameAvailable(int id);
-}
diff --git a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtMediaRecorderListener.java b/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtMediaRecorderListener.java
deleted file mode 100644
index bf1763dee..000000000
--- a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtMediaRecorderListener.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtMultimedia of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt.android.multimedia;
-
-import android.media.MediaRecorder;
-
-public class QtMediaRecorderListener implements MediaRecorder.OnErrorListener, MediaRecorder.OnInfoListener
-{
- private long m_id = -1;
-
- public QtMediaRecorderListener(long id)
- {
- m_id = id;
- }
-
- @Override
- public void onError(MediaRecorder mr, int what, int extra)
- {
- notifyError(m_id, what, extra);
- }
-
- @Override
- public void onInfo(MediaRecorder mr, int what, int extra)
- {
- notifyInfo(m_id, what, extra);
- }
-
- private static native void notifyError(long id, int what, int extra);
- private static native void notifyInfo(long id, int what, int extra);
-}
diff --git a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtMultimediaUtils.java b/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtMultimediaUtils.java
deleted file mode 100644
index 28d56e0dd..000000000
--- a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtMultimediaUtils.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtMultimedia of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt.android.multimedia;
-
-import android.app.Activity;
-import android.content.Context;
-import android.view.OrientationEventListener;
-import android.os.Environment;
-import android.media.MediaScannerConnection;
-import java.lang.String;
-import java.io.File;
-
-public class QtMultimediaUtils
-{
- static private class OrientationListener extends OrientationEventListener
- {
- static public int deviceOrientation = 0;
-
- public OrientationListener(Context context)
- {
- super(context);
- }
-
- @Override
- public void onOrientationChanged(int orientation)
- {
- if (orientation == ORIENTATION_UNKNOWN)
- return;
-
- deviceOrientation = orientation;
- }
- }
-
- static private Context m_context = null;
- static private OrientationListener m_orientationListener = null;
-
- static public void setActivity(Activity qtMainActivity, Object qtActivityDelegate)
- {
- }
-
- static public void setContext(Context context)
- {
- m_context = context;
- m_orientationListener = new OrientationListener(context);
- }
-
- public QtMultimediaUtils()
- {
- }
-
- static void enableOrientationListener(boolean enable)
- {
- if (enable)
- m_orientationListener.enable();
- else
- m_orientationListener.disable();
- }
-
- static int getDeviceOrientation()
- {
- return m_orientationListener.deviceOrientation;
- }
-
- static String getDefaultMediaDirectory(int type)
- {
- String dirType = new String();
- switch (type) {
- case 0:
- dirType = Environment.DIRECTORY_MUSIC;
- break;
- case 1:
- dirType = Environment.DIRECTORY_MOVIES;
- break;
- case 2:
- dirType = Environment.DIRECTORY_DCIM;
- break;
- default:
- break;
- }
-
- File path = new File("");
- if (type == 3) {
- // There is no API for knowing the standard location for sounds
- // such as voice recording. Though, it's typically in the 'Sounds'
- // directory at the root of the external storage
- path = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
- + File.separator + "Sounds");
- } else {
- path = Environment.getExternalStoragePublicDirectory(dirType);
- }
-
- path.mkdirs(); // make sure the directory exists
-
- return path.getAbsolutePath();
- }
-
- static void registerMediaFile(String file)
- {
- MediaScannerConnection.scanFile(m_context, new String[] { file }, null, null);
- }
-}
diff --git a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback.java b/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback.java
deleted file mode 100644
index 62000716b..000000000
--- a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtMultimedia of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt.android.multimedia;
-
-import android.view.SurfaceHolder;
-
-public class QtSurfaceHolderCallback implements SurfaceHolder.Callback
-{
- private long m_id = -1;
-
- public QtSurfaceHolderCallback(long id)
- {
- m_id = id;
- }
-
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
- {
- }
-
- @Override
- public void surfaceCreated(SurfaceHolder holder)
- {
- notifySurfaceCreated(m_id);
- }
-
- @Override
- public void surfaceDestroyed(SurfaceHolder holder)
- {
- notifySurfaceDestroyed(m_id);
- }
-
-
- private static native void notifySurfaceCreated(long id);
- private static native void notifySurfaceDestroyed(long id);
-}
diff --git a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder.java b/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder.java
deleted file mode 100644
index ea7a41505..000000000
--- a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the (whatever) of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt.android.multimedia;
-
-import android.view.SurfaceHolder;
-import android.view.Surface;
-import android.graphics.Rect;
-import android.graphics.Canvas;
-
-public class QtSurfaceTextureHolder implements SurfaceHolder
-{
- private Surface surfaceTexture;
-
- public QtSurfaceTextureHolder(Surface surface)
- {
- surfaceTexture = surface;
- }
-
- @Override
- public void addCallback(SurfaceHolder.Callback callback)
- {
- }
-
- @Override
- public Surface getSurface()
- {
- return surfaceTexture;
- }
-
- @Override
- public Rect getSurfaceFrame()
- {
- return new Rect();
- }
-
- @Override
- public boolean isCreating()
- {
- return false;
- }
-
- @Override
- public Canvas lockCanvas(Rect dirty)
- {
- return new Canvas();
- }
-
- @Override
- public Canvas lockCanvas()
- {
- return new Canvas();
- }
-
- @Override
- public void removeCallback(SurfaceHolder.Callback callback)
- {
- }
-
- @Override
- public void setFixedSize(int width, int height)
- {
- }
-
- @Override
- public void setFormat(int format)
- {
- }
-
- @Override
- public void setKeepScreenOn(boolean screenOn)
- {
- }
-
- @Override
- public void setSizeFromLayout()
- {
- }
-
- @Override
- public void setType(int type)
- {
- }
-
- @Override
- public void unlockCanvasAndPost(Canvas canvas)
- {
- }
-}
diff --git a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureListener.java b/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureListener.java
deleted file mode 100644
index 4d929c6ad..000000000
--- a/src/plugins/android/jar/src/org/qtproject/qt/android/multimedia/QtSurfaceTextureListener.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtMultimedia of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-package org.qtproject.qt.android.multimedia;
-
-import android.graphics.SurfaceTexture;
-
-public class QtSurfaceTextureListener implements SurfaceTexture.OnFrameAvailableListener
-{
- private final long m_id;
-
- public QtSurfaceTextureListener(long id)
- {
- m_id = id;
- }
-
- @Override
- public void onFrameAvailable(SurfaceTexture surfaceTexture)
- {
- notifyFrameAvailable(m_id);
- }
-
- private static native void notifyFrameAvailable(long id);
-}
diff --git a/src/plugins/android/src/android_mediaservice.json b/src/plugins/android/src/android_mediaservice.json
deleted file mode 100644
index df4bccb2b..000000000
--- a/src/plugins/android/src/android_mediaservice.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["androidmultimedia"],
- "Services": ["org.qt-project.qt.camera", "org.qt-project.qt.mediaplayer", "org.qt-project.qt.audiosource"]
-}
diff --git a/src/plugins/android/src/common/common.pri b/src/plugins/android/src/common/common.pri
deleted file mode 100644
index 1b02b99ea..000000000
--- a/src/plugins/android/src/common/common.pri
+++ /dev/null
@@ -1,10 +0,0 @@
-INCLUDEPATH += $$PWD
-
-HEADERS += \
- $$PWD/qandroidglobal.h \
- $$PWD/qandroidvideooutput.h \
- $$PWD/qandroidmultimediautils.h
-
-SOURCES += \
- $$PWD/qandroidvideooutput.cpp \
- $$PWD/qandroidmultimediautils.cpp
diff --git a/src/plugins/android/src/common/qandroidglobal.h b/src/plugins/android/src/common/qandroidglobal.h
deleted file mode 100644
index e7342be97..000000000
--- a/src/plugins/android/src/common/qandroidglobal.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDGLOBAL_H
-#define QANDROIDGLOBAL_H
-
-#include <QtCore/qglobal.h>
-#include <QtCore/qloggingcategory.h>
-
-QT_BEGIN_NAMESPACE
-
-Q_DECLARE_LOGGING_CATEGORY(qtAndroidMediaPlugin)
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDGLOBAL_H
diff --git a/src/plugins/android/src/common/qandroidmultimediautils.cpp b/src/plugins/android/src/common/qandroidmultimediautils.cpp
deleted file mode 100644
index 1f03d5d29..000000000
--- a/src/plugins/android/src/common/qandroidmultimediautils.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidmultimediautils.h"
-#include "qandroidglobal.h"
-
-#include <qlist.h>
-#include <QtCore/private/qjni_p.h>
-#include <QtCore/private/qjnihelpers_p.h>
-
-QT_BEGIN_NAMESPACE
-
-int qt_findClosestValue(const QList<int> &list, int value)
-{
- if (list.size() < 2)
- return 0;
-
- int begin = 0;
- int end = list.size() - 1;
- int pivot = begin + (end - begin) / 2;
- int v = list.at(pivot);
-
- while (end - begin > 1) {
- if (value == v)
- return pivot;
-
- if (value > v)
- begin = pivot;
- else
- end = pivot;
-
- pivot = begin + (end - begin) / 2;
- v = list.at(pivot);
- }
-
- return value - v >= list.at(pivot + 1) - value ? pivot + 1 : pivot;
-}
-
-bool qt_sizeLessThan(const QSize &s1, const QSize &s2)
-{
- return s1.width() * s1.height() < s2.width() * s2.height();
-}
-
-QVideoFrame::PixelFormat qt_pixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat f)
-{
- switch (f) {
- case AndroidCamera::NV21:
- return QVideoFrame::Format_NV21;
- case AndroidCamera::YV12:
- return QVideoFrame::Format_YV12;
- case AndroidCamera::RGB565:
- return QVideoFrame::Format_RGB565;
- case AndroidCamera::YUY2:
- return QVideoFrame::Format_YUYV;
- case AndroidCamera::JPEG:
- return QVideoFrame::Format_Jpeg;
- default:
- return QVideoFrame::Format_Invalid;
- }
-}
-
-AndroidCamera::ImageFormat qt_androidImageFormatFromPixelFormat(QVideoFrame::PixelFormat f)
-{
- switch (f) {
- case QVideoFrame::Format_NV21:
- return AndroidCamera::NV21;
- case QVideoFrame::Format_YV12:
- return AndroidCamera::YV12;
- case QVideoFrame::Format_RGB565:
- return AndroidCamera::RGB565;
- case QVideoFrame::Format_YUYV:
- return AndroidCamera::YUY2;
- case QVideoFrame::Format_Jpeg:
- return AndroidCamera::JPEG;
- default:
- return AndroidCamera::UnknownImageFormat;
- }
-}
-
-static bool androidRequestPermission(const QString &key)
-{
- using namespace QtAndroidPrivate;
-
- if (androidSdkVersion() < 23)
- return true;
-
- PermissionsResult res = checkPermission(key);
- if (res == PermissionsResult::Granted) // Permission already granted?
- return true;
-
- QJNIEnvironmentPrivate env;
- const auto &results = requestPermissionsSync(env, QStringList() << key);
- if (!results.contains(key)) {
- qCWarning(qtAndroidMediaPlugin, "No permission found for key: %s", qPrintable(key));
- return false;
- }
-
- if (results[key] == PermissionsResult::Denied) {
- qCDebug(qtAndroidMediaPlugin, "%s - Permission denied by user!", qPrintable(key));
- return false;
- }
-
- return true;
-}
-
-bool qt_androidRequestCameraPermission()
-{
- return androidRequestPermission(QLatin1String("android.permission.CAMERA"));
-}
-
-bool qt_androidRequestRecordingPermission()
-{
- return androidRequestPermission(QLatin1String("android.permission.RECORD_AUDIO"));
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/common/qandroidmultimediautils.h b/src/plugins/android/src/common/qandroidmultimediautils.h
deleted file mode 100644
index 381671cb8..000000000
--- a/src/plugins/android/src/common/qandroidmultimediautils.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDMULTIMEDIAUTILS_H
-#define QANDROIDMULTIMEDIAUTILS_H
-
-#include <qglobal.h>
-#include <qsize.h>
-#include "androidcamera.h"
-
-QT_BEGIN_NAMESPACE
-
-// return the index of the closest value to <value> in <list>
-// (binary search)
-int qt_findClosestValue(const QList<int> &list, int value);
-
-bool qt_sizeLessThan(const QSize &s1, const QSize &s2);
-
-QVideoFrame::PixelFormat qt_pixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat f);
-AndroidCamera::ImageFormat qt_androidImageFormatFromPixelFormat(QVideoFrame::PixelFormat f);
-
-bool qt_androidRequestCameraPermission();
-bool qt_androidRequestRecordingPermission();
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDMULTIMEDIAUTILS_H
diff --git a/src/plugins/android/src/common/qandroidvideooutput.cpp b/src/plugins/android/src/common/qandroidvideooutput.cpp
deleted file mode 100644
index 27cea76ad..000000000
--- a/src/plugins/android/src/common/qandroidvideooutput.cpp
+++ /dev/null
@@ -1,504 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidvideooutput.h"
-
-#include "androidsurfacetexture.h"
-#include <QAbstractVideoSurface>
-#include <QVideoSurfaceFormat>
-#include <qevent.h>
-#include <qcoreapplication.h>
-#include <qopenglcontext.h>
-#include <qopenglfunctions.h>
-#include <qopenglshaderprogram.h>
-#include <qopenglframebufferobject.h>
-#include <QtCore/private/qjnihelpers_p.h>
-#include <QtGui/QWindow>
-#include <QtGui/QOffscreenSurface>
-
-QT_BEGIN_NAMESPACE
-
-static const GLfloat g_vertex_data[] = {
- -1.f, 1.f,
- 1.f, 1.f,
- 1.f, -1.f,
- -1.f, -1.f
-};
-
-static const GLfloat g_texture_data[] = {
- 0.f, 0.f,
- 1.f, 0.f,
- 1.f, 1.f,
- 0.f, 1.f
-};
-
-void OpenGLResourcesDeleter::deleteTextureHelper(quint32 id)
-{
- if (id != 0)
- glDeleteTextures(1, &id);
-}
-
-void OpenGLResourcesDeleter::deleteFboHelper(void *fbo)
-{
- delete reinterpret_cast<QOpenGLFramebufferObject *>(fbo);
-}
-
-void OpenGLResourcesDeleter::deleteShaderProgramHelper(void *prog)
-{
- delete reinterpret_cast<QOpenGLShaderProgram *>(prog);
-}
-
-void OpenGLResourcesDeleter::deleteThisHelper()
-{
- delete this;
-}
-
-class AndroidTextureVideoBuffer : public QAbstractVideoBuffer
-{
-public:
- AndroidTextureVideoBuffer(QAndroidTextureVideoOutput *output, const QSize &size)
- : QAbstractVideoBuffer(GLTextureHandle)
- , m_mapMode(NotMapped)
- , m_output(output)
- , m_size(size)
- , m_textureUpdated(false)
- {
- }
-
- virtual ~AndroidTextureVideoBuffer() {}
-
- MapMode mapMode() const { return m_mapMode; }
-
- uchar *map(MapMode mode, int *numBytes, int *bytesPerLine)
- {
- if (m_mapMode == NotMapped && mode == ReadOnly && updateFrame()) {
- m_mapMode = mode;
- m_image = m_output->m_fbo->toImage();
-
- if (numBytes)
- *numBytes = static_cast<int>(m_image.sizeInBytes());
-
- if (bytesPerLine)
- *bytesPerLine = m_image.bytesPerLine();
-
- return m_image.bits();
- } else {
- return 0;
- }
- }
-
- void unmap()
- {
- m_image = QImage();
- m_mapMode = NotMapped;
- }
-
- QVariant handle() const
- {
- AndroidTextureVideoBuffer *that = const_cast<AndroidTextureVideoBuffer*>(this);
- if (!that->updateFrame())
- return QVariant();
-
- return m_output->m_fbo->texture();
- }
-
-private:
- bool updateFrame()
- {
- // Even though the texture was updated in a previous call, we need to re-check
- // that this has not become a stale buffer, e.g., if the output size changed or
- // has since became invalid.
- if (!m_output->m_nativeSize.isValid())
- return false;
-
- // Size changed
- if (m_output->m_nativeSize != m_size)
- return false;
-
- // In the unlikely event that we don't have a valid fbo, but have a valid size,
- // force an update.
- const bool forceUpdate = !m_output->m_fbo;
-
- if (m_textureUpdated && !forceUpdate)
- return true;
-
- // update the video texture (called from the render thread)
- return (m_textureUpdated = m_output->renderFrameToFbo());
- }
-
- MapMode m_mapMode;
- QAndroidTextureVideoOutput *m_output;
- QImage m_image;
- QSize m_size;
- bool m_textureUpdated;
-};
-
-QAndroidTextureVideoOutput::QAndroidTextureVideoOutput(QObject *parent)
- : QAndroidVideoOutput(parent)
- , m_surface(0)
- , m_surfaceTexture(0)
- , m_externalTex(0)
- , m_fbo(0)
- , m_program(0)
- , m_glDeleter(0)
- , m_surfaceTextureCanAttachToContext(QtAndroidPrivate::androidSdkVersion() >= 16)
-{
-
-}
-
-QAndroidTextureVideoOutput::~QAndroidTextureVideoOutput()
-{
- delete m_offscreenSurface;
- delete m_glContext;
- clearSurfaceTexture();
-
- if (m_glDeleter) { // Make sure all of these are deleted on the render thread.
- m_glDeleter->deleteFbo(m_fbo);
- m_glDeleter->deleteShaderProgram(m_program);
- m_glDeleter->deleteTexture(m_externalTex);
- m_glDeleter->deleteThis();
- }
-}
-
-QAbstractVideoSurface *QAndroidTextureVideoOutput::surface() const
-{
- return m_surface;
-}
-
-void QAndroidTextureVideoOutput::setSurface(QAbstractVideoSurface *surface)
-{
- if (surface == m_surface)
- return;
-
- if (m_surface) {
- if (m_surface->isActive())
- m_surface->stop();
-
- if (!m_surfaceTextureCanAttachToContext)
- m_surface->setProperty("_q_GLThreadCallback", QVariant());
- }
-
- m_surface = surface;
-
- if (m_surface && !m_surfaceTextureCanAttachToContext) {
- m_surface->setProperty("_q_GLThreadCallback",
- QVariant::fromValue<QObject*>(this));
- }
-}
-
-bool QAndroidTextureVideoOutput::isReady()
-{
- return m_surfaceTextureCanAttachToContext || QOpenGLContext::currentContext() || m_externalTex;
-}
-
-bool QAndroidTextureVideoOutput::initSurfaceTexture()
-{
- if (m_surfaceTexture)
- return true;
-
- if (!m_surface)
- return false;
-
- if (!m_surfaceTextureCanAttachToContext) {
- // if we have an OpenGL context in the current thread, create a texture. Otherwise, wait
- // for the GL render thread to call us back to do it.
- if (QOpenGLContext::currentContext()) {
- glGenTextures(1, &m_externalTex);
- if (!m_glDeleter)
- m_glDeleter = new OpenGLResourcesDeleter;
- } else if (!m_externalTex) {
- return false;
- }
- }
-
- QMutexLocker locker(&m_mutex);
-
- m_surfaceTexture = new AndroidSurfaceTexture(m_externalTex);
-
- if (m_surfaceTexture->surfaceTexture() != 0) {
- connect(m_surfaceTexture, SIGNAL(frameAvailable()), this, SLOT(onFrameAvailable()));
- } else {
- delete m_surfaceTexture;
- m_surfaceTexture = 0;
- if (m_glDeleter)
- m_glDeleter->deleteTexture(m_externalTex);
- m_externalTex = 0;
- }
-
- return m_surfaceTexture != 0;
-}
-
-void QAndroidTextureVideoOutput::clearSurfaceTexture()
-{
- QMutexLocker locker(&m_mutex);
- if (m_surfaceTexture) {
- delete m_surfaceTexture;
- m_surfaceTexture = 0;
- }
-
- // Also reset the attached OpenGL texture
- // Note: The Android SurfaceTexture class does not release the texture on deletion,
- // only if detachFromGLContext() called (API level >= 16), so we'll do it manually,
- // on the render thread.
- if (m_surfaceTextureCanAttachToContext) {
- if (m_glDeleter)
- m_glDeleter->deleteTexture(m_externalTex);
- m_externalTex = 0;
- }
-}
-
-AndroidSurfaceTexture *QAndroidTextureVideoOutput::surfaceTexture()
-{
- if (!initSurfaceTexture())
- return 0;
-
- return m_surfaceTexture;
-}
-
-void QAndroidTextureVideoOutput::setVideoSize(const QSize &size)
-{
- QMutexLocker locker(&m_mutex);
- if (m_nativeSize == size)
- return;
-
- stop();
-
- m_nativeSize = size;
-}
-
-void QAndroidTextureVideoOutput::stop()
-{
- if (m_surface && m_surface->isActive())
- m_surface->stop();
- m_nativeSize = QSize();
-}
-
-void QAndroidTextureVideoOutput::reset()
-{
- // flush pending frame
- if (m_surface)
- m_surface->present(QVideoFrame());
-
- clearSurfaceTexture();
-}
-
-void QAndroidTextureVideoOutput::onFrameAvailable()
-{
- if (!m_nativeSize.isValid() || !m_surface)
- return;
-
- QAbstractVideoBuffer *buffer = new AndroidTextureVideoBuffer(this, m_nativeSize);
- QVideoFrame frame(buffer, m_nativeSize, QVideoFrame::Format_ABGR32);
-
- if (m_surface->isActive() && (m_surface->surfaceFormat().pixelFormat() != frame.pixelFormat()
- || m_surface->surfaceFormat().frameSize() != frame.size())) {
- m_surface->stop();
- }
-
- if (!m_surface->isActive()) {
- QVideoSurfaceFormat format(frame.size(), frame.pixelFormat(),
- QAbstractVideoBuffer::GLTextureHandle);
-
- m_surface->start(format);
- }
-
- if (m_surface->isActive())
- m_surface->present(frame);
-}
-
-bool QAndroidTextureVideoOutput::renderFrameToFbo()
-{
- QMutexLocker locker(&m_mutex);
-
- if (!m_nativeSize.isValid() || !m_surfaceTexture)
- return false;
-
- QOpenGLContext *shareContext = !m_glContext && m_surface
- ? qobject_cast<QOpenGLContext*>(m_surface->property("GLContext").value<QObject*>())
- : nullptr;
-
- // Make sure we have an OpenGL context to make current.
- if (shareContext || (!QOpenGLContext::currentContext() && !m_glContext)) {
- // Create Hidden QWindow surface to create context in this thread.
- m_offscreenSurface = new QWindow();
- m_offscreenSurface->setSurfaceType(QWindow::OpenGLSurface);
- // Needs geometry to be a valid surface, but size is not important.
- m_offscreenSurface->setGeometry(0, 0, 1, 1);
- m_offscreenSurface->create();
- m_offscreenSurface->moveToThread(m_surface->thread());
-
- // Create OpenGL context and set share context from surface.
- m_glContext = new QOpenGLContext();
- m_glContext->setFormat(m_offscreenSurface->requestedFormat());
-
- auto surface = qobject_cast<QAbstractVideoSurface *>(m_surface->property("videoSurface").value<QObject *>());
- if (!surface)
- surface = m_surface;
- if (shareContext)
- m_glContext->setShareContext(shareContext);
-
- if (!m_glContext->create()) {
- qWarning("Failed to create QOpenGLContext");
- return false;
- }
- }
-
- if (m_glContext)
- m_glContext->makeCurrent(m_offscreenSurface);
-
- createGLResources();
-
- m_surfaceTexture->updateTexImage();
-
- // save current render states
- GLboolean stencilTestEnabled;
- GLboolean depthTestEnabled;
- GLboolean scissorTestEnabled;
- GLboolean blendEnabled;
- glGetBooleanv(GL_STENCIL_TEST, &stencilTestEnabled);
- glGetBooleanv(GL_DEPTH_TEST, &depthTestEnabled);
- glGetBooleanv(GL_SCISSOR_TEST, &scissorTestEnabled);
- glGetBooleanv(GL_BLEND, &blendEnabled);
-
- if (stencilTestEnabled)
- glDisable(GL_STENCIL_TEST);
- if (depthTestEnabled)
- glDisable(GL_DEPTH_TEST);
- if (scissorTestEnabled)
- glDisable(GL_SCISSOR_TEST);
- if (blendEnabled)
- glDisable(GL_BLEND);
-
- m_fbo->bind();
-
- glViewport(0, 0, m_nativeSize.width(), m_nativeSize.height());
-
- m_program->bind();
- m_program->enableAttributeArray(0);
- m_program->enableAttributeArray(1);
- m_program->setUniformValue("frameTexture", GLuint(0));
- m_program->setUniformValue("texMatrix", m_surfaceTexture->getTransformMatrix());
-
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, g_vertex_data);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, g_texture_data);
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
- m_program->disableAttributeArray(0);
- m_program->disableAttributeArray(1);
-
- glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
- m_fbo->release();
-
- // restore render states
- if (stencilTestEnabled)
- glEnable(GL_STENCIL_TEST);
- if (depthTestEnabled)
- glEnable(GL_DEPTH_TEST);
- if (scissorTestEnabled)
- glEnable(GL_SCISSOR_TEST);
- if (blendEnabled)
- glEnable(GL_BLEND);
-
- return true;
-}
-
-void QAndroidTextureVideoOutput::createGLResources()
-{
- Q_ASSERT(QOpenGLContext::currentContext() != NULL);
-
- if (!m_glDeleter)
- m_glDeleter = new OpenGLResourcesDeleter;
-
- if (m_surfaceTextureCanAttachToContext && !m_externalTex) {
- m_surfaceTexture->detachFromGLContext();
- glGenTextures(1, &m_externalTex);
- m_surfaceTexture->attachToGLContext(m_externalTex);
- }
-
- if (!m_fbo || m_fbo->size() != m_nativeSize) {
- delete m_fbo;
- m_fbo = new QOpenGLFramebufferObject(m_nativeSize);
- }
-
- if (!m_program) {
- m_program = new QOpenGLShaderProgram;
-
- QOpenGLShader *vertexShader = new QOpenGLShader(QOpenGLShader::Vertex, m_program);
- vertexShader->compileSourceCode("attribute highp vec4 vertexCoordsArray; \n" \
- "attribute highp vec2 textureCoordArray; \n" \
- "uniform highp mat4 texMatrix; \n" \
- "varying highp vec2 textureCoords; \n" \
- "void main(void) \n" \
- "{ \n" \
- " gl_Position = vertexCoordsArray; \n" \
- " textureCoords = (texMatrix * vec4(textureCoordArray, 0.0, 1.0)).xy; \n" \
- "}\n");
- m_program->addShader(vertexShader);
-
- QOpenGLShader *fragmentShader = new QOpenGLShader(QOpenGLShader::Fragment, m_program);
- fragmentShader->compileSourceCode("#extension GL_OES_EGL_image_external : require \n" \
- "varying highp vec2 textureCoords; \n" \
- "uniform samplerExternalOES frameTexture; \n" \
- "void main() \n" \
- "{ \n" \
- " gl_FragColor = texture2D(frameTexture, textureCoords); \n" \
- "}\n");
- m_program->addShader(fragmentShader);
-
- m_program->bindAttributeLocation("vertexCoordsArray", 0);
- m_program->bindAttributeLocation("textureCoordArray", 1);
- m_program->link();
- }
-}
-
-void QAndroidTextureVideoOutput::customEvent(QEvent *e)
-{
- if (e->type() == QEvent::User) {
- // This is running in the render thread (OpenGL enabled)
- if (!m_surfaceTextureCanAttachToContext && !m_externalTex) {
- glGenTextures(1, &m_externalTex);
- if (!m_glDeleter) // We'll use this to cleanup GL resources in the correct thread
- m_glDeleter = new OpenGLResourcesDeleter;
- emit readyChanged(true);
- }
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/common/qandroidvideooutput.h b/src/plugins/android/src/common/qandroidvideooutput.h
deleted file mode 100644
index 456fe8e22..000000000
--- a/src/plugins/android/src/common/qandroidvideooutput.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDVIDEOOUTPUT_H
-#define QANDROIDVIDEOOUTPUT_H
-
-#include <qobject.h>
-#include <qsize.h>
-#include <qmutex.h>
-
-QT_BEGIN_NAMESPACE
-
-class AndroidSurfaceTexture;
-class AndroidSurfaceHolder;
-class QOpenGLFramebufferObject;
-class QOpenGLShaderProgram;
-class QAbstractVideoSurface;
-class QWindow;
-class QOpenGLContext;
-
-class QAndroidVideoOutput : public QObject
-{
- Q_OBJECT
-public:
- virtual ~QAndroidVideoOutput() { }
-
- virtual AndroidSurfaceTexture *surfaceTexture() { return 0; }
- virtual AndroidSurfaceHolder *surfaceHolder() { return 0; }
-
- virtual bool isReady() { return true; }
-
- virtual void setVideoSize(const QSize &) { }
- virtual void stop() { }
- virtual void reset() { }
-
-Q_SIGNALS:
- void readyChanged(bool);
-
-protected:
- QAndroidVideoOutput(QObject *parent) : QObject(parent) { }
-};
-
-class OpenGLResourcesDeleter : public QObject
-{
- Q_OBJECT
-public:
- void deleteTexture(quint32 id) { QMetaObject::invokeMethod(this, "deleteTextureHelper", Qt::AutoConnection, Q_ARG(quint32, id)); }
- void deleteFbo(QOpenGLFramebufferObject *fbo) { QMetaObject::invokeMethod(this, "deleteFboHelper", Qt::AutoConnection, Q_ARG(void *, fbo)); }
- void deleteShaderProgram(QOpenGLShaderProgram *prog) { QMetaObject::invokeMethod(this, "deleteShaderProgramHelper", Qt::AutoConnection, Q_ARG(void *, prog)); }
- void deleteThis() { QMetaObject::invokeMethod(this, "deleteThisHelper"); }
-
-private:
- Q_INVOKABLE void deleteTextureHelper(quint32 id);
- Q_INVOKABLE void deleteFboHelper(void *fbo);
- Q_INVOKABLE void deleteShaderProgramHelper(void *prog);
- Q_INVOKABLE void deleteThisHelper();
-};
-
-class QAndroidTextureVideoOutput : public QAndroidVideoOutput
-{
- Q_OBJECT
-public:
- explicit QAndroidTextureVideoOutput(QObject *parent = 0);
- ~QAndroidTextureVideoOutput() override;
-
- QAbstractVideoSurface *surface() const;
- void setSurface(QAbstractVideoSurface *surface);
-
- AndroidSurfaceTexture *surfaceTexture() override;
-
- bool isReady() override;
- void setVideoSize(const QSize &) override;
- void stop() override;
- void reset() override;
-
- void customEvent(QEvent *) override;
-
-private Q_SLOTS:
- void onFrameAvailable();
-
-private:
- bool initSurfaceTexture();
- bool renderFrameToFbo();
- void createGLResources();
-
- QMutex m_mutex;
- void clearSurfaceTexture();
-
- QAbstractVideoSurface *m_surface;
- QSize m_nativeSize;
-
- AndroidSurfaceTexture *m_surfaceTexture;
-
- quint32 m_externalTex;
- QOpenGLFramebufferObject *m_fbo;
- QOpenGLShaderProgram *m_program;
- OpenGLResourcesDeleter *m_glDeleter;
-
- bool m_surfaceTextureCanAttachToContext;
-
- QWindow *m_offscreenSurface = nullptr;
- QOpenGLContext *m_glContext = nullptr;
-
- friend class AndroidTextureVideoBuffer;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDVIDEOOUTPUT_H
diff --git a/src/plugins/android/src/mediacapture/mediacapture.pri b/src/plugins/android/src/mediacapture/mediacapture.pri
deleted file mode 100644
index a42a6a40c..000000000
--- a/src/plugins/android/src/mediacapture/mediacapture.pri
+++ /dev/null
@@ -1,53 +0,0 @@
-INCLUDEPATH += $$PWD
-
-SOURCES += \
- $$PWD/qandroidcaptureservice.cpp \
- $$PWD/qandroidcameracontrol.cpp \
- $$PWD/qandroidvideodeviceselectorcontrol.cpp \
- $$PWD/qandroidcamerasession.cpp \
- $$PWD/qandroidcamerazoomcontrol.cpp \
- $$PWD/qandroidcameraexposurecontrol.cpp \
- $$PWD/qandroidcameraimageprocessingcontrol.cpp \
- $$PWD/qandroidimageencodercontrol.cpp \
- $$PWD/qandroidcameraimagecapturecontrol.cpp \
- $$PWD/qandroidcameracapturedestinationcontrol.cpp \
- $$PWD/qandroidcameracapturebufferformatcontrol.cpp \
- $$PWD/qandroidcameraflashcontrol.cpp \
- $$PWD/qandroidcamerafocuscontrol.cpp \
- $$PWD/qandroidviewfindersettingscontrol.cpp \
- $$PWD/qandroidcameralockscontrol.cpp \
- $$PWD/qandroidcapturesession.cpp \
- $$PWD/qandroidmediarecordercontrol.cpp \
- $$PWD/qandroidaudioencodersettingscontrol.cpp \
- $$PWD/qandroidmediacontainercontrol.cpp \
- $$PWD/qandroidvideoencodersettingscontrol.cpp \
- $$PWD/qandroidaudioinputselectorcontrol.cpp \
- $$PWD/qandroidmediavideoprobecontrol.cpp \
- $$PWD/qandroidcamerainfocontrol.cpp \
- $$PWD/qandroidcameravideorenderercontrol.cpp
-
-HEADERS += \
- $$PWD/qandroidcaptureservice.h \
- $$PWD/qandroidcameracontrol.h \
- $$PWD/qandroidvideodeviceselectorcontrol.h \
- $$PWD/qandroidcamerasession.h \
- $$PWD/qandroidcamerazoomcontrol.h \
- $$PWD/qandroidcameraexposurecontrol.h \
- $$PWD/qandroidcameraimageprocessingcontrol.h \
- $$PWD/qandroidimageencodercontrol.h \
- $$PWD/qandroidcameraimagecapturecontrol.h \
- $$PWD/qandroidcameracapturedestinationcontrol.h \
- $$PWD/qandroidcameracapturebufferformatcontrol.h \
- $$PWD/qandroidcameraflashcontrol.h \
- $$PWD/qandroidcamerafocuscontrol.h \
- $$PWD/qandroidviewfindersettingscontrol.h \
- $$PWD/qandroidcameralockscontrol.h \
- $$PWD/qandroidcapturesession.h \
- $$PWD/qandroidmediarecordercontrol.h \
- $$PWD/qandroidaudioencodersettingscontrol.h \
- $$PWD/qandroidmediacontainercontrol.h \
- $$PWD/qandroidvideoencodersettingscontrol.h \
- $$PWD/qandroidaudioinputselectorcontrol.h \
- $$PWD/qandroidmediavideoprobecontrol.h \
- $$PWD/qandroidcamerainfocontrol.h \
- $$PWD/qandroidcameravideorenderercontrol.h
diff --git a/src/plugins/android/src/mediacapture/qandroidaudioencodersettingscontrol.cpp b/src/plugins/android/src/mediacapture/qandroidaudioencodersettingscontrol.cpp
deleted file mode 100644
index 4bd94425d..000000000
--- a/src/plugins/android/src/mediacapture/qandroidaudioencodersettingscontrol.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidaudioencodersettingscontrol.h"
-
-#include "qandroidcapturesession.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidAudioEncoderSettingsControl::QAndroidAudioEncoderSettingsControl(QAndroidCaptureSession *session)
- : QAudioEncoderSettingsControl()
- , m_session(session)
-{
-}
-
-QStringList QAndroidAudioEncoderSettingsControl::supportedAudioCodecs() const
-{
- return QStringList() << QLatin1String("amr-nb") << QLatin1String("amr-wb") << QLatin1String("aac");
-}
-
-QString QAndroidAudioEncoderSettingsControl::codecDescription(const QString &codecName) const
-{
- if (codecName == QLatin1String("amr-nb"))
- return tr("Adaptive Multi-Rate Narrowband (AMR-NB) audio codec");
- else if (codecName == QLatin1String("amr-wb"))
- return tr("Adaptive Multi-Rate Wideband (AMR-WB) audio codec");
- else if (codecName == QLatin1String("aac"))
- return tr("AAC Low Complexity (AAC-LC) audio codec");
-
- return QString();
-}
-
-QList<int> QAndroidAudioEncoderSettingsControl::supportedSampleRates(const QAudioEncoderSettings &settings, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- if (settings.isNull() || settings.codec().isNull() || settings.codec() == QLatin1String("aac")) {
- return QList<int>() << 8000 << 11025 << 12000 << 16000 << 22050
- << 24000 << 32000 << 44100 << 48000 << 96000;
- } else if (settings.codec() == QLatin1String("amr-nb")) {
- return QList<int>() << 8000;
- } else if (settings.codec() == QLatin1String("amr-wb")) {
- return QList<int>() << 16000;
- }
-
- return QList<int>();
-}
-
-QAudioEncoderSettings QAndroidAudioEncoderSettingsControl::audioSettings() const
-{
- return m_session->audioSettings();
-}
-
-void QAndroidAudioEncoderSettingsControl::setAudioSettings(const QAudioEncoderSettings &settings)
-{
- m_session->setAudioSettings(settings);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidaudioencodersettingscontrol.h b/src/plugins/android/src/mediacapture/qandroidaudioencodersettingscontrol.h
deleted file mode 100644
index e68bf6ef7..000000000
--- a/src/plugins/android/src/mediacapture/qandroidaudioencodersettingscontrol.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDAUDIOENCODERSETTINGSCONTROL_H
-#define QANDROIDAUDIOENCODERSETTINGSCONTROL_H
-
-#include <qaudioencodersettingscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCaptureSession;
-
-class QAndroidAudioEncoderSettingsControl : public QAudioEncoderSettingsControl
-{
- Q_OBJECT
-public:
- explicit QAndroidAudioEncoderSettingsControl(QAndroidCaptureSession *session);
-
- QStringList supportedAudioCodecs() const override;
- QString codecDescription(const QString &codecName) const override;
- QList<int> supportedSampleRates(const QAudioEncoderSettings &settings, bool *continuous = 0) const override;
- QAudioEncoderSettings audioSettings() const override;
- void setAudioSettings(const QAudioEncoderSettings &settings) override;
-
-private:
- QAndroidCaptureSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDAUDIOENCODERSETTINGSCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidaudioinputselectorcontrol.cpp b/src/plugins/android/src/mediacapture/qandroidaudioinputselectorcontrol.cpp
deleted file mode 100644
index bf2161a7e..000000000
--- a/src/plugins/android/src/mediacapture/qandroidaudioinputselectorcontrol.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidaudioinputselectorcontrol.h"
-
-#include "qandroidcapturesession.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidAudioInputSelectorControl::QAndroidAudioInputSelectorControl(QAndroidCaptureSession *session)
- : QAudioInputSelectorControl()
- , m_session(session)
-{
- connect(m_session, SIGNAL(audioInputChanged(QString)), this, SIGNAL(activeInputChanged(QString)));
-}
-
-QList<QString> QAndroidAudioInputSelectorControl::availableInputs() const
-{
- return QList<QString>() << QLatin1String("default")
- << QLatin1String("mic")
- << QLatin1String("voice_uplink")
- << QLatin1String("voice_downlink")
- << QLatin1String("voice_call")
- << QLatin1String("voice_recognition");
-}
-
-QString QAndroidAudioInputSelectorControl::inputDescription(const QString& name) const
-{
- return availableDeviceDescription(name.toLatin1());
-}
-
-QString QAndroidAudioInputSelectorControl::defaultInput() const
-{
- return QLatin1String("default");
-}
-
-QString QAndroidAudioInputSelectorControl::activeInput() const
-{
- return m_session->audioInput();
-}
-
-void QAndroidAudioInputSelectorControl::setActiveInput(const QString& name)
-{
- m_session->setAudioInput(name);
-}
-
-QList<QByteArray> QAndroidAudioInputSelectorControl::availableDevices()
-{
- return QList<QByteArray>() << "default"
- << "mic"
- << "voice_uplink"
- << "voice_downlink"
- << "voice_call"
- << "voice_recognition";
-}
-
-QString QAndroidAudioInputSelectorControl::availableDeviceDescription(const QByteArray &device)
-{
- if (device == "default")
- return QLatin1String("Default audio source");
- else if (device == "mic")
- return QLatin1String("Microphone audio source");
- else if (device == "voice_uplink")
- return QLatin1String("Voice call uplink (Tx) audio source");
- else if (device == "voice_downlink")
- return QLatin1String("Voice call downlink (Rx) audio source");
- else if (device == "voice_call")
- return QLatin1String("Voice call uplink + downlink audio source");
- else if (device == "voice_recognition")
- return QLatin1String("Microphone audio source tuned for voice recognition");
- else
- return QString();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidaudioinputselectorcontrol.h b/src/plugins/android/src/mediacapture/qandroidaudioinputselectorcontrol.h
deleted file mode 100644
index c24167fb3..000000000
--- a/src/plugins/android/src/mediacapture/qandroidaudioinputselectorcontrol.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDAUDIOINPUTSELECTORCONTROL_H
-#define QANDROIDAUDIOINPUTSELECTORCONTROL_H
-
-#include <qaudioinputselectorcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCaptureSession;
-
-class QAndroidAudioInputSelectorControl : public QAudioInputSelectorControl
-{
- Q_OBJECT
-public:
- explicit QAndroidAudioInputSelectorControl(QAndroidCaptureSession *session);
-
- QList<QString> availableInputs() const;
- QString inputDescription(const QString& name) const;
- QString defaultInput() const;
-
- QString activeInput() const;
- void setActiveInput(const QString& name);
-
- static QList<QByteArray> availableDevices();
- static QString availableDeviceDescription(const QByteArray &device);
-
-private:
- QAndroidCaptureSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDAUDIOINPUTSELECTORCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcameracapturebufferformatcontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcameracapturebufferformatcontrol.cpp
deleted file mode 100644
index a47fa4f72..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameracapturebufferformatcontrol.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcameracapturebufferformatcontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCameraCaptureBufferFormatControl::QAndroidCameraCaptureBufferFormatControl()
- : QCameraCaptureBufferFormatControl()
-{
-}
-
-QList<QVideoFrame::PixelFormat> QAndroidCameraCaptureBufferFormatControl::supportedBufferFormats() const
-{
- return (QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_Jpeg);
-}
-
-QVideoFrame::PixelFormat QAndroidCameraCaptureBufferFormatControl::bufferFormat() const
-{
- return QVideoFrame::Format_Jpeg;
-}
-
-void QAndroidCameraCaptureBufferFormatControl::setBufferFormat(QVideoFrame::PixelFormat format)
-{
- Q_UNUSED(format);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcameracapturebufferformatcontrol.h b/src/plugins/android/src/mediacapture/qandroidcameracapturebufferformatcontrol.h
deleted file mode 100644
index b27727543..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameracapturebufferformatcontrol.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERACAPTUREBUFFERFORMATCONTROL_H
-#define QANDROIDCAMERACAPTUREBUFFERFORMATCONTROL_H
-
-#include <qcameracapturebufferformatcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraCaptureBufferFormatControl : public QCameraCaptureBufferFormatControl
-{
- Q_OBJECT
-public:
- QAndroidCameraCaptureBufferFormatControl();
-
- QList<QVideoFrame::PixelFormat> supportedBufferFormats() const override;
- QVideoFrame::PixelFormat bufferFormat() const override;
- void setBufferFormat(QVideoFrame::PixelFormat format) override;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERACAPTUREBUFFERFORMATCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcameracapturedestinationcontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcameracapturedestinationcontrol.cpp
deleted file mode 100644
index 6a6847007..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameracapturedestinationcontrol.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcameracapturedestinationcontrol.h"
-
-#include "qandroidcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCameraCaptureDestinationControl::QAndroidCameraCaptureDestinationControl(QAndroidCameraSession *session)
- : QCameraCaptureDestinationControl()
- , m_session(session)
-{
- connect(m_session, SIGNAL(captureDestinationChanged(QCameraImageCapture::CaptureDestinations)),
- this, SIGNAL(captureDestinationChanged(QCameraImageCapture::CaptureDestinations)));
-}
-
-bool QAndroidCameraCaptureDestinationControl::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const
-{
- return m_session->isCaptureDestinationSupported(destination);
-}
-
-QCameraImageCapture::CaptureDestinations QAndroidCameraCaptureDestinationControl::captureDestination() const
-{
- return m_session->captureDestination();;
-}
-
-void QAndroidCameraCaptureDestinationControl::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination)
-{
- m_session->setCaptureDestination(destination);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcameracapturedestinationcontrol.h b/src/plugins/android/src/mediacapture/qandroidcameracapturedestinationcontrol.h
deleted file mode 100644
index 1edfdab12..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameracapturedestinationcontrol.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERACAPTUREDESTINATIONCONTROL_H
-#define QANDROIDCAMERACAPTUREDESTINATIONCONTROL_H
-
-#include <qcameracapturedestinationcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidCameraCaptureDestinationControl : public QCameraCaptureDestinationControl
-{
- Q_OBJECT
-public:
- explicit QAndroidCameraCaptureDestinationControl(QAndroidCameraSession *session);
-
- bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const override;
- QCameraImageCapture::CaptureDestinations captureDestination() const override;
- void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) override;
-
-private:
- QAndroidCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERACAPTUREDESTINATIONCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcameracontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcameracontrol.cpp
deleted file mode 100644
index a75215920..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameracontrol.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcameracontrol.h"
-
-#include "qandroidcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCameraControl::QAndroidCameraControl(QAndroidCameraSession *session)
- : QCameraControl(0)
- , m_cameraSession(session)
-
-{
- connect(m_cameraSession, SIGNAL(statusChanged(QCamera::Status)),
- this, SIGNAL(statusChanged(QCamera::Status)));
-
- connect(m_cameraSession, SIGNAL(stateChanged(QCamera::State)),
- this, SIGNAL(stateChanged(QCamera::State)));
-
- connect(m_cameraSession, SIGNAL(error(int,QString)), this, SIGNAL(error(int,QString)));
-
- connect(m_cameraSession, SIGNAL(captureModeChanged(QCamera::CaptureModes)),
- this, SIGNAL(captureModeChanged(QCamera::CaptureModes)));
-}
-
-QAndroidCameraControl::~QAndroidCameraControl()
-{
-}
-
-QCamera::CaptureModes QAndroidCameraControl::captureMode() const
-{
- return m_cameraSession->captureMode();
-}
-
-void QAndroidCameraControl::setCaptureMode(QCamera::CaptureModes mode)
-{
- m_cameraSession->setCaptureMode(mode);
-}
-
-bool QAndroidCameraControl::isCaptureModeSupported(QCamera::CaptureModes mode) const
-{
- return m_cameraSession->isCaptureModeSupported(mode);
-}
-
-void QAndroidCameraControl::setState(QCamera::State state)
-{
- m_cameraSession->setState(state);
-}
-
-QCamera::State QAndroidCameraControl::state() const
-{
- return m_cameraSession->state();
-}
-
-QCamera::Status QAndroidCameraControl::status() const
-{
- return m_cameraSession->status();
-}
-
-bool QAndroidCameraControl::canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const
-{
- Q_UNUSED(status);
-
- switch (changeType) {
- case QCameraControl::CaptureMode:
- case QCameraControl::ImageEncodingSettings:
- case QCameraControl::VideoEncodingSettings:
- case QCameraControl::Viewfinder:
- return true;
- default:
- return false;
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcameracontrol.h b/src/plugins/android/src/mediacapture/qandroidcameracontrol.h
deleted file mode 100644
index 80eead627..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameracontrol.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QANDROIDCAMERACONTROL_H
-#define QANDROIDCAMERACONTROL_H
-
-#include <qcameracontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidCameraControl : public QCameraControl
-{
- Q_OBJECT
-public:
- explicit QAndroidCameraControl(QAndroidCameraSession *session);
- virtual ~QAndroidCameraControl();
-
- QCamera::State state() const;
- void setState(QCamera::State state);
-
- QCamera::Status status() const;
-
- QCamera::CaptureModes captureMode() const;
- void setCaptureMode(QCamera::CaptureModes mode);
- bool isCaptureModeSupported(QCamera::CaptureModes mode) const;
-
- bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const;
-
-private:
- QAndroidCameraSession *m_cameraSession;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERACONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcameraexposurecontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcameraexposurecontrol.cpp
deleted file mode 100644
index cf4587379..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameraexposurecontrol.cpp
+++ /dev/null
@@ -1,293 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcameraexposurecontrol.h"
-
-#include "qandroidcamerasession.h"
-#include "androidcamera.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCameraExposureControl::QAndroidCameraExposureControl(QAndroidCameraSession *session)
- : QCameraExposureControl()
- , m_session(session)
- , m_minExposureCompensationIndex(0)
- , m_maxExposureCompensationIndex(0)
- , m_exposureCompensationStep(0.0)
- , m_requestedExposureCompensation(0.0)
- , m_actualExposureCompensation(0.0)
- , m_requestedExposureMode(QCameraExposure::ExposureAuto)
- , m_actualExposureMode(QCameraExposure::ExposureAuto)
-{
- connect(m_session, SIGNAL(opened()),
- this, SLOT(onCameraOpened()));
-}
-
-bool QAndroidCameraExposureControl::isParameterSupported(ExposureParameter parameter) const
-{
- if (!m_session->camera())
- return false;
-
- switch (parameter) {
- case QCameraExposureControl::ISO:
- return false;
- case QCameraExposureControl::Aperture:
- return false;
- case QCameraExposureControl::ShutterSpeed:
- return false;
- case QCameraExposureControl::ExposureCompensation:
- return !m_supportedExposureCompensations.isEmpty();
- case QCameraExposureControl::FlashPower:
- return false;
- case QCameraExposureControl::FlashCompensation:
- return false;
- case QCameraExposureControl::TorchPower:
- return false;
- case QCameraExposureControl::SpotMeteringPoint:
- return false;
- case QCameraExposureControl::ExposureMode:
- return !m_supportedExposureModes.isEmpty();
- case QCameraExposureControl::MeteringMode:
- return false;
- default:
- return false;
- }
-}
-
-QVariantList QAndroidCameraExposureControl::supportedParameterRange(ExposureParameter parameter, bool *continuous) const
-{
- if (!m_session->camera())
- return QVariantList();
-
- if (continuous)
- *continuous = false;
-
- if (parameter == QCameraExposureControl::ExposureCompensation)
- return m_supportedExposureCompensations;
- else if (parameter == QCameraExposureControl::ExposureMode)
- return m_supportedExposureModes;
-
- return QVariantList();
-}
-
-QVariant QAndroidCameraExposureControl::requestedValue(ExposureParameter parameter) const
-{
- if (parameter == QCameraExposureControl::ExposureCompensation)
- return QVariant::fromValue(m_requestedExposureCompensation);
- else if (parameter == QCameraExposureControl::ExposureMode)
- return QVariant::fromValue(m_requestedExposureMode);
-
- return QVariant();
-}
-
-QVariant QAndroidCameraExposureControl::actualValue(ExposureParameter parameter) const
-{
- if (parameter == QCameraExposureControl::ExposureCompensation)
- return QVariant::fromValue(m_actualExposureCompensation);
- else if (parameter == QCameraExposureControl::ExposureMode)
- return QVariant::fromValue(m_actualExposureMode);
-
- return QVariant();
-}
-
-bool QAndroidCameraExposureControl::setValue(ExposureParameter parameter, const QVariant& value)
-{
- if (!value.isValid())
- return false;
-
- if (parameter == QCameraExposureControl::ExposureCompensation) {
- qreal expComp = value.toReal();
- if (!qFuzzyCompare(m_requestedExposureCompensation, expComp)) {
- m_requestedExposureCompensation = expComp;
- emit requestedValueChanged(QCameraExposureControl::ExposureCompensation);
- }
-
- if (!m_session->camera())
- return true;
-
- int expCompIndex = qRound(m_requestedExposureCompensation / m_exposureCompensationStep);
- if (expCompIndex >= m_minExposureCompensationIndex
- && expCompIndex <= m_maxExposureCompensationIndex) {
- qreal comp = expCompIndex * m_exposureCompensationStep;
- m_session->camera()->setExposureCompensation(expCompIndex);
- if (!qFuzzyCompare(m_actualExposureCompensation, comp)) {
- m_actualExposureCompensation = expCompIndex * m_exposureCompensationStep;
- emit actualValueChanged(QCameraExposureControl::ExposureCompensation);
- }
-
- return true;
- }
-
- } else if (parameter == QCameraExposureControl::ExposureMode) {
- QCameraExposure::ExposureMode expMode = value.value<QCameraExposure::ExposureMode>();
- if (m_requestedExposureMode != expMode) {
- m_requestedExposureMode = expMode;
- emit requestedValueChanged(QCameraExposureControl::ExposureMode);
- }
-
- if (!m_session->camera())
- return true;
-
- if (!m_supportedExposureModes.isEmpty()) {
- m_actualExposureMode = m_requestedExposureMode;
-
- QString sceneMode;
- switch (m_requestedExposureMode) {
- case QCameraExposure::ExposureAuto:
- sceneMode = QLatin1String("auto");
- break;
- case QCameraExposure::ExposureSports:
- sceneMode = QLatin1String("sports");
- break;
- case QCameraExposure::ExposurePortrait:
- sceneMode = QLatin1String("portrait");
- break;
- case QCameraExposure::ExposureBeach:
- sceneMode = QLatin1String("beach");
- break;
- case QCameraExposure::ExposureSnow:
- sceneMode = QLatin1String("snow");
- break;
- case QCameraExposure::ExposureNight:
- sceneMode = QLatin1String("night");
- break;
- case QCameraExposure::ExposureAction:
- sceneMode = QLatin1String("action");
- break;
- case QCameraExposure::ExposureLandscape:
- sceneMode = QLatin1String("landscape");
- break;
- case QCameraExposure::ExposureNightPortrait:
- sceneMode = QLatin1String("night-portrait");
- break;
- case QCameraExposure::ExposureTheatre:
- sceneMode = QLatin1String("theatre");
- break;
- case QCameraExposure::ExposureSunset:
- sceneMode = QLatin1String("sunset");
- break;
- case QCameraExposure::ExposureSteadyPhoto:
- sceneMode = QLatin1String("steadyphoto");
- break;
- case QCameraExposure::ExposureFireworks:
- sceneMode = QLatin1String("fireworks");
- break;
- case QCameraExposure::ExposureParty:
- sceneMode = QLatin1String("party");
- break;
- case QCameraExposure::ExposureCandlelight:
- sceneMode = QLatin1String("candlelight");
- break;
- case QCameraExposure::ExposureBarcode:
- sceneMode = QLatin1String("barcode");
- break;
- default:
- sceneMode = QLatin1String("auto");
- m_actualExposureMode = QCameraExposure::ExposureAuto;
- break;
- }
-
- m_session->camera()->setSceneMode(sceneMode);
- emit actualValueChanged(QCameraExposureControl::ExposureMode);
-
- return true;
- }
- }
-
- return false;
-}
-
-void QAndroidCameraExposureControl::onCameraOpened()
-{
- m_supportedExposureCompensations.clear();
- m_minExposureCompensationIndex = m_session->camera()->getMinExposureCompensation();
- m_maxExposureCompensationIndex = m_session->camera()->getMaxExposureCompensation();
- m_exposureCompensationStep = m_session->camera()->getExposureCompensationStep();
- if (m_minExposureCompensationIndex != 0 || m_maxExposureCompensationIndex != 0) {
- for (int i = m_minExposureCompensationIndex; i <= m_maxExposureCompensationIndex; ++i)
- m_supportedExposureCompensations.append(i * m_exposureCompensationStep);
- emit parameterRangeChanged(QCameraExposureControl::ExposureCompensation);
- }
-
- m_supportedExposureModes.clear();
- QStringList sceneModes = m_session->camera()->getSupportedSceneModes();
- if (!sceneModes.isEmpty()) {
- for (int i = 0; i < sceneModes.size(); ++i) {
- const QString &sceneMode = sceneModes.at(i);
- if (sceneMode == QLatin1String("auto"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureAuto);
- else if (sceneMode == QLatin1String("beach"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureBeach);
- else if (sceneMode == QLatin1String("night"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureNight);
- else if (sceneMode == QLatin1String("portrait"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposurePortrait);
- else if (sceneMode == QLatin1String("snow"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureSnow);
- else if (sceneMode == QLatin1String("sports"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureSports);
- else if (sceneMode == QLatin1String("action"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureAction);
- else if (sceneMode == QLatin1String("landscape"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureLandscape);
- else if (sceneMode == QLatin1String("night-portrait"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureNightPortrait);
- else if (sceneMode == QLatin1String("theatre"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureTheatre);
- else if (sceneMode == QLatin1String("sunset"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureSunset);
- else if (sceneMode == QLatin1String("steadyphoto"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureSteadyPhoto);
- else if (sceneMode == QLatin1String("fireworks"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureFireworks);
- else if (sceneMode == QLatin1String("party"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureParty);
- else if (sceneMode == QLatin1String("candlelight"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureCandlelight);
- else if (sceneMode == QLatin1String("barcode"))
- m_supportedExposureModes << QVariant::fromValue(QCameraExposure::ExposureBarcode);
- }
- emit parameterRangeChanged(QCameraExposureControl::ExposureMode);
- }
-
- setValue(QCameraExposureControl::ExposureCompensation, QVariant::fromValue(m_requestedExposureCompensation));
- setValue(QCameraExposureControl::ExposureMode, QVariant::fromValue(m_requestedExposureMode));
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcameraexposurecontrol.h b/src/plugins/android/src/mediacapture/qandroidcameraexposurecontrol.h
deleted file mode 100644
index e87e6cd3a..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameraexposurecontrol.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERAEXPOSURECONTROL_H
-#define QANDROIDCAMERAEXPOSURECONTROL_H
-
-#include <qcameraexposurecontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidCameraExposureControl : public QCameraExposureControl
-{
- Q_OBJECT
-public:
- explicit QAndroidCameraExposureControl(QAndroidCameraSession *session);
-
- bool isParameterSupported(ExposureParameter parameter) const override;
- QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const override;
-
- QVariant requestedValue(ExposureParameter parameter) const override;
- QVariant actualValue(ExposureParameter parameter) const override;
- bool setValue(ExposureParameter parameter, const QVariant& value) override;
-
-private Q_SLOTS:
- void onCameraOpened();
-
-private:
- QAndroidCameraSession *m_session;
-
- QVariantList m_supportedExposureCompensations;
- QVariantList m_supportedExposureModes;
-
- int m_minExposureCompensationIndex;
- int m_maxExposureCompensationIndex;
- qreal m_exposureCompensationStep;
-
- qreal m_requestedExposureCompensation;
- qreal m_actualExposureCompensation;
- QCameraExposure::ExposureMode m_requestedExposureMode;
- QCameraExposure::ExposureMode m_actualExposureMode;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERAEXPOSURECONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcameraflashcontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcameraflashcontrol.cpp
deleted file mode 100644
index 20a4b005c..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameraflashcontrol.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcameraflashcontrol.h"
-
-#include "qandroidcamerasession.h"
-#include "androidcamera.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCameraFlashControl::QAndroidCameraFlashControl(QAndroidCameraSession *session)
- : QCameraFlashControl()
- , m_session(session)
- , m_flashMode(QCameraExposure::FlashOff)
-{
- connect(m_session, SIGNAL(opened()),
- this, SLOT(onCameraOpened()));
-}
-
-QCameraExposure::FlashModes QAndroidCameraFlashControl::flashMode() const
-{
- return m_flashMode;
-}
-
-void QAndroidCameraFlashControl::setFlashMode(QCameraExposure::FlashModes mode)
-{
- if (!m_session->camera()) {
- m_flashMode = mode;
- return;
- }
-
- if (!isFlashModeSupported(mode))
- return;
-
- // if torch was enabled, it first needs to be turned off before setting another mode
- if (m_flashMode == QCameraExposure::FlashVideoLight)
- m_session->camera()->setFlashMode(QLatin1String("off"));
-
- m_flashMode = mode;
-
- QString flashMode;
- if (mode.testFlag(QCameraExposure::FlashAuto))
- flashMode = QLatin1String("auto");
- else if (mode.testFlag(QCameraExposure::FlashOn))
- flashMode = QLatin1String("on");
- else if (mode.testFlag(QCameraExposure::FlashRedEyeReduction))
- flashMode = QLatin1String("red-eye");
- else if (mode.testFlag(QCameraExposure::FlashVideoLight))
- flashMode = QLatin1String("torch");
- else // FlashOff
- flashMode = QLatin1String("off");
-
- m_session->camera()->setFlashMode(flashMode);
-}
-
-bool QAndroidCameraFlashControl::isFlashModeSupported(QCameraExposure::FlashModes mode) const
-{
- return m_session->camera() ? m_supportedFlashModes.contains(mode) : false;
-}
-
-bool QAndroidCameraFlashControl::isFlashReady() const
-{
- // Android doesn't have an API for that
- return true;
-}
-
-void QAndroidCameraFlashControl::onCameraOpened()
-{
- m_supportedFlashModes.clear();
-
- QStringList flashModes = m_session->camera()->getSupportedFlashModes();
- for (int i = 0; i < flashModes.size(); ++i) {
- const QString &flashMode = flashModes.at(i);
- if (flashMode == QLatin1String("off"))
- m_supportedFlashModes << QCameraExposure::FlashOff;
- else if (flashMode == QLatin1String("auto"))
- m_supportedFlashModes << QCameraExposure::FlashAuto;
- else if (flashMode == QLatin1String("on"))
- m_supportedFlashModes << QCameraExposure::FlashOn;
- else if (flashMode == QLatin1String("red-eye"))
- m_supportedFlashModes << QCameraExposure::FlashRedEyeReduction;
- else if (flashMode == QLatin1String("torch"))
- m_supportedFlashModes << QCameraExposure::FlashVideoLight;
- }
-
- if (!m_supportedFlashModes.contains(m_flashMode))
- m_flashMode = QCameraExposure::FlashOff;
-
- setFlashMode(m_flashMode);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcameraflashcontrol.h b/src/plugins/android/src/mediacapture/qandroidcameraflashcontrol.h
deleted file mode 100644
index 071c45c72..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameraflashcontrol.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERAFLASHCONTROL_H
-#define QANDROIDCAMERAFLASHCONTROL_H
-
-#include <qcameraflashcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidCameraFlashControl : public QCameraFlashControl
-{
- Q_OBJECT
-public:
- explicit QAndroidCameraFlashControl(QAndroidCameraSession *session);
-
- QCameraExposure::FlashModes flashMode() const override;
- void setFlashMode(QCameraExposure::FlashModes mode) override;
- bool isFlashModeSupported(QCameraExposure::FlashModes mode) const override;
- bool isFlashReady() const override;
-
-private Q_SLOTS:
- void onCameraOpened();
-
-private:
- QAndroidCameraSession *m_session;
- QList<QCameraExposure::FlashModes> m_supportedFlashModes;
- QCameraExposure::FlashModes m_flashMode;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERAFLASHCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerafocuscontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcamerafocuscontrol.cpp
deleted file mode 100644
index 4b8a94976..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcamerafocuscontrol.cpp
+++ /dev/null
@@ -1,309 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcamerafocuscontrol.h"
-
-#include "qandroidcamerasession.h"
-#include "androidcamera.h"
-
-QT_BEGIN_NAMESPACE
-
-static QRect adjustedArea(const QRectF &area)
-{
- // Qt maps focus points in the range (0.0, 0.0) -> (1.0, 1.0)
- // Android maps focus points in the range (-1000, -1000) -> (1000, 1000)
- // Converts an area in Qt coordinates to Android coordinates
- return QRect(-1000 + qRound(area.x() * 2000),
- -1000 + qRound(area.y() * 2000),
- qRound(area.width() * 2000),
- qRound(area.height() * 2000))
- .intersected(QRect(-1000, -1000, 2000, 2000));
-}
-
-QAndroidCameraFocusControl::QAndroidCameraFocusControl(QAndroidCameraSession *session)
- : QCameraFocusControl()
- , m_session(session)
- , m_focusMode(QCameraFocus::AutoFocus)
- , m_focusPointMode(QCameraFocus::FocusPointAuto)
- , m_actualFocusPoint(0.5, 0.5)
- , m_continuousPictureFocusSupported(false)
- , m_continuousVideoFocusSupported(false)
-{
- connect(m_session, SIGNAL(opened()),
- this, SLOT(onCameraOpened()));
- connect(m_session, SIGNAL(captureModeChanged(QCamera::CaptureModes)),
- this, SLOT(onCameraCaptureModeChanged()));
-}
-
-QCameraFocus::FocusModes QAndroidCameraFocusControl::focusMode() const
-{
- return m_focusMode;
-}
-
-void QAndroidCameraFocusControl::setFocusMode(QCameraFocus::FocusModes mode)
-{
- if (!m_session->camera()) {
- setFocusModeHelper(mode);
- return;
- }
-
- if (isFocusModeSupported(mode)) {
- QString focusMode = QLatin1String("fixed");
-
- if (mode.testFlag(QCameraFocus::HyperfocalFocus)) {
- focusMode = QLatin1String("edof");
- } else if (mode.testFlag(QCameraFocus::ManualFocus)) {
- focusMode = QLatin1String("fixed");
- } else if (mode.testFlag(QCameraFocus::AutoFocus)) {
- focusMode = QLatin1String("auto");
- } else if (mode.testFlag(QCameraFocus::MacroFocus)) {
- focusMode = QLatin1String("macro");
- } else if (mode.testFlag(QCameraFocus::ContinuousFocus)) {
- if ((m_session->captureMode().testFlag(QCamera::CaptureVideo) && m_continuousVideoFocusSupported)
- || !m_continuousPictureFocusSupported) {
- focusMode = QLatin1String("continuous-video");
- } else {
- focusMode = QLatin1String("continuous-picture");
- }
- } else if (mode.testFlag(QCameraFocus::InfinityFocus)) {
- focusMode = QLatin1String("infinity");
- }
-
- m_session->camera()->setFocusMode(focusMode);
-
- // reset focus position
- m_session->camera()->cancelAutoFocus();
-
- setFocusModeHelper(mode);
- }
-}
-
-bool QAndroidCameraFocusControl::isFocusModeSupported(QCameraFocus::FocusModes mode) const
-{
- return m_session->camera() ? m_supportedFocusModes.contains(mode) : false;
-}
-
-QCameraFocus::FocusPointMode QAndroidCameraFocusControl::focusPointMode() const
-{
- return m_focusPointMode;
-}
-
-void QAndroidCameraFocusControl::setFocusPointMode(QCameraFocus::FocusPointMode mode)
-{
- if (!m_session->camera()) {
- setFocusPointModeHelper(mode);
- return;
- }
-
- if (isFocusPointModeSupported(mode)) {
- if (mode == QCameraFocus::FocusPointCustom) {
- m_actualFocusPoint = m_customFocusPoint;
- } else {
- // FocusPointAuto | FocusPointCenter
- // note: there is no way to know the actual focus point in FocusPointAuto mode,
- // so just report the focus point to be at the center of the frame
- m_actualFocusPoint = QPointF(0.5, 0.5);
- }
-
- setFocusPointModeHelper(mode);
-
- updateFocusZones();
- setCameraFocusArea();
- }
-}
-
-bool QAndroidCameraFocusControl::isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const
-{
- return m_session->camera() ? m_supportedFocusPointModes.contains(mode) : false;
-}
-
-QPointF QAndroidCameraFocusControl::customFocusPoint() const
-{
- return m_customFocusPoint;
-}
-
-void QAndroidCameraFocusControl::setCustomFocusPoint(const QPointF &point)
-{
- if (m_customFocusPoint != point) {
- m_customFocusPoint = point;
- emit customFocusPointChanged(m_customFocusPoint);
- }
-
- if (m_session->camera() && m_focusPointMode == QCameraFocus::FocusPointCustom) {
- m_actualFocusPoint = m_customFocusPoint;
- updateFocusZones();
- setCameraFocusArea();
- }
-}
-
-QCameraFocusZoneList QAndroidCameraFocusControl::focusZones() const
-{
- return m_focusZones;
-}
-
-void QAndroidCameraFocusControl::onCameraOpened()
-{
- connect(m_session->camera(), SIGNAL(previewSizeChanged()),
- this, SLOT(onViewportSizeChanged()));
- connect(m_session->camera(), SIGNAL(autoFocusStarted()),
- this, SLOT(onAutoFocusStarted()));
- connect(m_session->camera(), SIGNAL(autoFocusComplete(bool)),
- this, SLOT(onAutoFocusComplete(bool)));
-
- m_supportedFocusModes.clear();
- m_continuousPictureFocusSupported = false;
- m_continuousVideoFocusSupported = false;
- m_supportedFocusPointModes.clear();
-
- QStringList focusModes = m_session->camera()->getSupportedFocusModes();
- for (int i = 0; i < focusModes.size(); ++i) {
- const QString &focusMode = focusModes.at(i);
- if (focusMode == QLatin1String("auto")) {
- m_supportedFocusModes << QCameraFocus::AutoFocus;
- } else if (focusMode == QLatin1String("continuous-picture")) {
- m_supportedFocusModes << QCameraFocus::ContinuousFocus;
- m_continuousPictureFocusSupported = true;
- } else if (focusMode == QLatin1String("continuous-video")) {
- m_supportedFocusModes << QCameraFocus::ContinuousFocus;
- m_continuousVideoFocusSupported = true;
- } else if (focusMode == QLatin1String("edof")) {
- m_supportedFocusModes << QCameraFocus::HyperfocalFocus;
- } else if (focusMode == QLatin1String("fixed")) {
- m_supportedFocusModes << QCameraFocus::ManualFocus;
- } else if (focusMode == QLatin1String("infinity")) {
- m_supportedFocusModes << QCameraFocus::InfinityFocus;
- } else if (focusMode == QLatin1String("macro")) {
- m_supportedFocusModes << QCameraFocus::MacroFocus;
- }
- }
-
- m_supportedFocusPointModes << QCameraFocus::FocusPointAuto;
- if (m_session->camera()->getMaxNumFocusAreas() > 0)
- m_supportedFocusPointModes << QCameraFocus::FocusPointCenter << QCameraFocus::FocusPointCustom;
-
- if (!m_supportedFocusModes.contains(m_focusMode))
- setFocusModeHelper(QCameraFocus::AutoFocus);
- if (!m_supportedFocusPointModes.contains(m_focusPointMode))
- setFocusPointModeHelper(QCameraFocus::FocusPointAuto);
-
- setFocusMode(m_focusMode);
- setCustomFocusPoint(m_customFocusPoint);
- setFocusPointMode(m_focusPointMode);
-}
-
-void QAndroidCameraFocusControl::updateFocusZones(QCameraFocusZone::FocusZoneStatus status)
-{
- if (!m_session->camera())
- return;
-
- // create a focus zone (50x50 pixel) around the focus point
- m_focusZones.clear();
-
- if (!m_actualFocusPoint.isNull()) {
- QSize viewportSize = m_session->camera()->previewSize();
-
- if (!viewportSize.isValid())
- return;
-
- QSizeF focusSize(50.f / viewportSize.width(), 50.f / viewportSize.height());
- float x = qBound(qreal(0),
- m_actualFocusPoint.x() - (focusSize.width() / 2),
- 1.f - focusSize.width());
- float y = qBound(qreal(0),
- m_actualFocusPoint.y() - (focusSize.height() / 2),
- 1.f - focusSize.height());
-
- QRectF area(QPointF(x, y), focusSize);
-
- m_focusZones.append(QCameraFocusZone(area, status));
- }
-
- emit focusZonesChanged();
-}
-
-void QAndroidCameraFocusControl::setCameraFocusArea()
-{
- QList<QRect> areas;
- if (m_focusPointMode != QCameraFocus::FocusPointAuto) {
- // in FocusPointAuto mode, leave the area list empty
- // to let the driver choose the focus point.
-
- for (int i = 0; i < m_focusZones.size(); ++i)
- areas.append(adjustedArea(m_focusZones.at(i).area()));
-
- }
- m_session->camera()->setFocusAreas(areas);
-}
-
-void QAndroidCameraFocusControl::onViewportSizeChanged()
-{
- QCameraFocusZone::FocusZoneStatus status = QCameraFocusZone::Selected;
- if (!m_focusZones.isEmpty())
- status = m_focusZones.at(0).status();
- updateFocusZones(status);
- setCameraFocusArea();
-}
-
-void QAndroidCameraFocusControl::onCameraCaptureModeChanged()
-{
- if (m_session->camera() && m_focusMode == QCameraFocus::ContinuousFocus) {
- QString focusMode;
- if ((m_session->captureMode().testFlag(QCamera::CaptureVideo) && m_continuousVideoFocusSupported)
- || !m_continuousPictureFocusSupported) {
- focusMode = QLatin1String("continuous-video");
- } else {
- focusMode = QLatin1String("continuous-picture");
- }
- m_session->camera()->setFocusMode(focusMode);
- m_session->camera()->cancelAutoFocus();
- }
-}
-
-void QAndroidCameraFocusControl::onAutoFocusStarted()
-{
- updateFocusZones(QCameraFocusZone::Selected);
-}
-
-void QAndroidCameraFocusControl::onAutoFocusComplete(bool success)
-{
- if (success)
- updateFocusZones(QCameraFocusZone::Focused);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerafocuscontrol.h b/src/plugins/android/src/mediacapture/qandroidcamerafocuscontrol.h
deleted file mode 100644
index 9c606cf7d..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcamerafocuscontrol.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERAFOCUSCONTROL_H
-#define QANDROIDCAMERAFOCUSCONTROL_H
-
-#include <qcamerafocuscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidCameraFocusControl : public QCameraFocusControl
-{
- Q_OBJECT
-public:
- explicit QAndroidCameraFocusControl(QAndroidCameraSession *session);
-
- QCameraFocus::FocusModes focusMode() const override;
- void setFocusMode(QCameraFocus::FocusModes mode) override;
- bool isFocusModeSupported(QCameraFocus::FocusModes mode) const override;
- QCameraFocus::FocusPointMode focusPointMode() const override;
- void setFocusPointMode(QCameraFocus::FocusPointMode mode) override;
- bool isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const override;
- QPointF customFocusPoint() const override;
- void setCustomFocusPoint(const QPointF &point) override;
- QCameraFocusZoneList focusZones() const override;
-
-private Q_SLOTS:
- void onCameraOpened();
- void onViewportSizeChanged();
- void onCameraCaptureModeChanged();
- void onAutoFocusStarted();
- void onAutoFocusComplete(bool success);
-
-private:
- inline void setFocusModeHelper(QCameraFocus::FocusModes mode)
- {
- if (m_focusMode != mode) {
- m_focusMode = mode;
- emit focusModeChanged(mode);
- }
- }
-
- inline void setFocusPointModeHelper(QCameraFocus::FocusPointMode mode)
- {
- if (m_focusPointMode != mode) {
- m_focusPointMode = mode;
- emit focusPointModeChanged(mode);
- }
- }
-
- void updateFocusZones(QCameraFocusZone::FocusZoneStatus status = QCameraFocusZone::Selected);
- void setCameraFocusArea();
-
- QAndroidCameraSession *m_session;
-
- QCameraFocus::FocusModes m_focusMode;
- QCameraFocus::FocusPointMode m_focusPointMode;
- QPointF m_actualFocusPoint;
- QPointF m_customFocusPoint;
- QCameraFocusZoneList m_focusZones;
-
- QList<QCameraFocus::FocusModes> m_supportedFocusModes;
- bool m_continuousPictureFocusSupported;
- bool m_continuousVideoFocusSupported;
-
- QList<QCameraFocus::FocusPointMode> m_supportedFocusPointModes;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERAFOCUSCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcameraimagecapturecontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcameraimagecapturecontrol.cpp
deleted file mode 100644
index f39a53665..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameraimagecapturecontrol.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcameraimagecapturecontrol.h"
-
-#include "qandroidcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCameraImageCaptureControl::QAndroidCameraImageCaptureControl(QAndroidCameraSession *session)
- : QCameraImageCaptureControl()
- , m_session(session)
-{
- connect(m_session, SIGNAL(readyForCaptureChanged(bool)), this, SIGNAL(readyForCaptureChanged(bool)));
- connect(m_session, SIGNAL(imageExposed(int)), this, SIGNAL(imageExposed(int)));
- connect(m_session, SIGNAL(imageCaptured(int,QImage)), this, SIGNAL(imageCaptured(int,QImage)));
- connect(m_session, SIGNAL(imageMetadataAvailable(int,QString,QVariant)), this, SIGNAL(imageMetadataAvailable(int,QString,QVariant)));
- connect(m_session, SIGNAL(imageAvailable(int,QVideoFrame)), this, SIGNAL(imageAvailable(int,QVideoFrame)));
- connect(m_session, SIGNAL(imageSaved(int,QString)), this, SIGNAL(imageSaved(int,QString)));
- connect(m_session, SIGNAL(imageCaptureError(int,int,QString)), this, SIGNAL(error(int,int,QString)));
-}
-
-bool QAndroidCameraImageCaptureControl::isReadyForCapture() const
-{
- return m_session->isReadyForCapture();
-}
-
-QCameraImageCapture::DriveMode QAndroidCameraImageCaptureControl::driveMode() const
-{
- return m_session->driveMode();
-}
-
-void QAndroidCameraImageCaptureControl::setDriveMode(QCameraImageCapture::DriveMode mode)
-{
- m_session->setDriveMode(mode);
-}
-
-int QAndroidCameraImageCaptureControl::capture(const QString &fileName)
-{
- return m_session->capture(fileName);
-}
-
-void QAndroidCameraImageCaptureControl::cancelCapture()
-{
- m_session->cancelCapture();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcameraimagecapturecontrol.h b/src/plugins/android/src/mediacapture/qandroidcameraimagecapturecontrol.h
deleted file mode 100644
index cfe748c39..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameraimagecapturecontrol.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERAIMAGECAPTURECONTROL_H
-#define QANDROIDCAMERAIMAGECAPTURECONTROL_H
-
-#include <qcameraimagecapturecontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidCameraImageCaptureControl : public QCameraImageCaptureControl
-{
- Q_OBJECT
-public:
- explicit QAndroidCameraImageCaptureControl(QAndroidCameraSession *session);
-
- bool isReadyForCapture() const override;
-
- QCameraImageCapture::DriveMode driveMode() const override;
- void setDriveMode(QCameraImageCapture::DriveMode mode) override;
-
- int capture(const QString &fileName) override;
- void cancelCapture() override;
-
-private:
- QAndroidCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERAIMAGECAPTURECONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcameraimageprocessingcontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcameraimageprocessingcontrol.cpp
deleted file mode 100644
index c69f1946b..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameraimageprocessingcontrol.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcameraimageprocessingcontrol.h"
-
-#include "qandroidcamerasession.h"
-#include "androidcamera.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCameraImageProcessingControl::QAndroidCameraImageProcessingControl(QAndroidCameraSession *session)
- : QCameraImageProcessingControl()
- , m_session(session)
- , m_whiteBalanceMode(QCameraImageProcessing::WhiteBalanceAuto)
-{
- connect(m_session, SIGNAL(opened()),
- this, SLOT(onCameraOpened()));
-}
-
-bool QAndroidCameraImageProcessingControl::isParameterSupported(ProcessingParameter parameter) const
-{
- return parameter == QCameraImageProcessingControl::WhiteBalancePreset
- && m_session->camera()
- && !m_supportedWhiteBalanceModes.isEmpty();
-}
-
-bool QAndroidCameraImageProcessingControl::isParameterValueSupported(ProcessingParameter parameter,
- const QVariant &value) const
-{
- return parameter == QCameraImageProcessingControl::WhiteBalancePreset
- && m_session->camera()
- && m_supportedWhiteBalanceModes.contains(value.value<QCameraImageProcessing::WhiteBalanceMode>());
-}
-
-QVariant QAndroidCameraImageProcessingControl::parameter(ProcessingParameter parameter) const
-{
- if (parameter != QCameraImageProcessingControl::WhiteBalancePreset)
- return QVariant();
-
- return QVariant::fromValue(m_whiteBalanceMode);
-}
-
-void QAndroidCameraImageProcessingControl::setParameter(ProcessingParameter parameter, const QVariant &value)
-{
- if (parameter != QCameraImageProcessingControl::WhiteBalancePreset)
- return;
-
- QCameraImageProcessing::WhiteBalanceMode mode = value.value<QCameraImageProcessing::WhiteBalanceMode>();
-
- if (m_session->camera())
- setWhiteBalanceModeHelper(mode);
- else
- m_whiteBalanceMode = mode;
-}
-
-void QAndroidCameraImageProcessingControl::setWhiteBalanceModeHelper(QCameraImageProcessing::WhiteBalanceMode mode)
-{
- QString wb = m_supportedWhiteBalanceModes.value(mode, QString());
- if (!wb.isEmpty()) {
- m_session->camera()->setWhiteBalance(wb);
- m_whiteBalanceMode = mode;
- }
-}
-
-void QAndroidCameraImageProcessingControl::onCameraOpened()
-{
- m_supportedWhiteBalanceModes.clear();
- QStringList whiteBalanceModes = m_session->camera()->getSupportedWhiteBalance();
- for (int i = 0; i < whiteBalanceModes.size(); ++i) {
- const QString &wb = whiteBalanceModes.at(i);
- if (wb == QLatin1String("auto")) {
- m_supportedWhiteBalanceModes.insert(QCameraImageProcessing::WhiteBalanceAuto,
- QStringLiteral("auto"));
- } else if (wb == QLatin1String("cloudy-daylight")) {
- m_supportedWhiteBalanceModes.insert(QCameraImageProcessing::WhiteBalanceCloudy,
- QStringLiteral("cloudy-daylight"));
- } else if (wb == QLatin1String("daylight")) {
- m_supportedWhiteBalanceModes.insert(QCameraImageProcessing::WhiteBalanceSunlight,
- QStringLiteral("daylight"));
- } else if (wb == QLatin1String("fluorescent")) {
- m_supportedWhiteBalanceModes.insert(QCameraImageProcessing::WhiteBalanceFluorescent,
- QStringLiteral("fluorescent"));
- } else if (wb == QLatin1String("incandescent")) {
- m_supportedWhiteBalanceModes.insert(QCameraImageProcessing::WhiteBalanceTungsten,
- QStringLiteral("incandescent"));
- } else if (wb == QLatin1String("shade")) {
- m_supportedWhiteBalanceModes.insert(QCameraImageProcessing::WhiteBalanceShade,
- QStringLiteral("shade"));
- } else if (wb == QLatin1String("twilight")) {
- m_supportedWhiteBalanceModes.insert(QCameraImageProcessing::WhiteBalanceSunset,
- QStringLiteral("twilight"));
- } else if (wb == QLatin1String("warm-fluorescent")) {
- m_supportedWhiteBalanceModes.insert(QCameraImageProcessing::WhiteBalanceFlash,
- QStringLiteral("warm-fluorescent"));
- }
- }
-
- if (!m_supportedWhiteBalanceModes.contains(m_whiteBalanceMode))
- m_whiteBalanceMode = QCameraImageProcessing::WhiteBalanceAuto;
-
- setWhiteBalanceModeHelper(m_whiteBalanceMode);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcameraimageprocessingcontrol.h b/src/plugins/android/src/mediacapture/qandroidcameraimageprocessingcontrol.h
deleted file mode 100644
index 9845c80dc..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameraimageprocessingcontrol.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERAIMAGEPROCESSINGCONTROL_H
-#define QANDROIDCAMERAIMAGEPROCESSINGCONTROL_H
-
-#include <qcameraimageprocessingcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidCameraImageProcessingControl : public QCameraImageProcessingControl
-{
- Q_OBJECT
-public:
- explicit QAndroidCameraImageProcessingControl(QAndroidCameraSession *session);
-
- bool isParameterSupported(ProcessingParameter) const override;
- bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const override;
- QVariant parameter(ProcessingParameter parameter) const override;
- void setParameter(ProcessingParameter parameter, const QVariant &value) override;
-
-private Q_SLOTS:
- void onCameraOpened();
-
-private:
- void setWhiteBalanceModeHelper(QCameraImageProcessing::WhiteBalanceMode mode);
-
- QAndroidCameraSession *m_session;
-
- QCameraImageProcessing::WhiteBalanceMode m_whiteBalanceMode;
-
- QMap<QCameraImageProcessing::WhiteBalanceMode, QString> m_supportedWhiteBalanceModes;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERAIMAGEPROCESSINGCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerainfocontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcamerainfocontrol.cpp
deleted file mode 100644
index 911ffc3ca..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcamerainfocontrol.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcamerainfocontrol.h"
-
-#include "qandroidcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-QCamera::Position QAndroidCameraInfoControl::position(const QString &deviceName)
-{
- const QList<AndroidCameraInfo> &cameras = QAndroidCameraSession::availableCameras();
- for (int i = 0; i < cameras.count(); ++i) {
- const AndroidCameraInfo &info = cameras.at(i);
- if (QString::fromLatin1(info.name) == deviceName)
- return info.position;
- }
-
- return QCamera::UnspecifiedPosition;
-}
-
-int QAndroidCameraInfoControl::orientation(const QString &deviceName)
-{
- const QList<AndroidCameraInfo> &cameras = QAndroidCameraSession::availableCameras();
- for (int i = 0; i < cameras.count(); ++i) {
- const AndroidCameraInfo &info = cameras.at(i);
- if (QString::fromLatin1(info.name) == deviceName)
- return info.orientation;
- }
-
- return 0;
-}
-
-QCamera::Position QAndroidCameraInfoControl::cameraPosition(const QString &deviceName) const
-{
- return position(deviceName);
-}
-
-int QAndroidCameraInfoControl::cameraOrientation(const QString &deviceName) const
-{
- return orientation(deviceName);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerainfocontrol.h b/src/plugins/android/src/mediacapture/qandroidcamerainfocontrol.h
deleted file mode 100644
index 349c73c97..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcamerainfocontrol.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERAINFOCONTROL_H
-#define QANDROIDCAMERAINFOCONTROL_H
-
-#include <qcamerainfocontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraInfoControl : public QCameraInfoControl
-{
- Q_OBJECT
-public:
- QCamera::Position cameraPosition(const QString &deviceName) const;
- int cameraOrientation(const QString &deviceName) const;
-
- static QCamera::Position position(const QString &deviceName);
- static int orientation(const QString &deviceName);
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERAINFOCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcameralockscontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcameralockscontrol.cpp
deleted file mode 100644
index 180a2f483..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameralockscontrol.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcameralockscontrol.h"
-
-#include "qandroidcamerasession.h"
-#include "androidcamera.h"
-#include <qtimer.h>
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCameraLocksControl::QAndroidCameraLocksControl(QAndroidCameraSession *session)
- : QCameraLocksControl()
- , m_session(session)
- , m_supportedLocks(QCamera::NoLock)
- , m_focusLockStatus(QCamera::Unlocked)
- , m_exposureLockStatus(QCamera::Unlocked)
- , m_whiteBalanceLockStatus(QCamera::Unlocked)
-{
- connect(m_session, SIGNAL(opened()),
- this, SLOT(onCameraOpened()));
-
- m_recalculateTimer = new QTimer(this);
- m_recalculateTimer->setInterval(1000);
- m_recalculateTimer->setSingleShot(true);
- connect(m_recalculateTimer, SIGNAL(timeout()), this, SLOT(onRecalculateTimeOut()));
-}
-
-QCamera::LockTypes QAndroidCameraLocksControl::supportedLocks() const
-{
- return m_supportedLocks;
-}
-
-QCamera::LockStatus QAndroidCameraLocksControl::lockStatus(QCamera::LockType lock) const
-{
- if (!m_supportedLocks.testFlag(lock) || !m_session->camera())
- return QCamera::Unlocked;
-
- if (lock == QCamera::LockFocus)
- return m_focusLockStatus;
-
- if (lock == QCamera::LockExposure)
- return m_exposureLockStatus;
-
- if (lock == QCamera::LockWhiteBalance)
- return m_whiteBalanceLockStatus;
-
- return QCamera::Unlocked;
-}
-
-void QAndroidCameraLocksControl::searchAndLock(QCamera::LockTypes locks)
-{
- if (!m_session->camera())
- return;
-
- // filter out unsupported locks
- locks &= m_supportedLocks;
-
- if (locks.testFlag(QCamera::LockFocus)) {
- QString focusMode = m_session->camera()->getFocusMode();
- if (focusMode == QLatin1String("auto")
- || focusMode == QLatin1String("macro")
- || focusMode == QLatin1String("continuous-picture")
- || focusMode == QLatin1String("continuous-video")) {
-
- if (m_focusLockStatus == QCamera::Searching)
- m_session->camera()->cancelAutoFocus();
- else
- setFocusLockStatus(QCamera::Searching, QCamera::UserRequest);
-
- m_session->camera()->autoFocus();
-
- } else {
- setFocusLockStatus(QCamera::Locked, QCamera::LockAcquired);
- }
- }
-
- if (locks.testFlag(QCamera::LockExposure) && m_exposureLockStatus != QCamera::Searching) {
- if (m_session->camera()->getAutoExposureLock()) {
- // if already locked, unlock and give some time to recalculate exposure
- m_session->camera()->setAutoExposureLock(false);
- setExposureLockStatus(QCamera::Searching, QCamera::UserRequest);
- } else {
- m_session->camera()->setAutoExposureLock(true);
- setExposureLockStatus(QCamera::Locked, QCamera::LockAcquired);
- }
- }
-
- if (locks.testFlag(QCamera::LockWhiteBalance) && m_whiteBalanceLockStatus != QCamera::Searching) {
- if (m_session->camera()->getAutoWhiteBalanceLock()) {
- // if already locked, unlock and give some time to recalculate white balance
- m_session->camera()->setAutoWhiteBalanceLock(false);
- setWhiteBalanceLockStatus(QCamera::Searching, QCamera::UserRequest);
- } else {
- m_session->camera()->setAutoWhiteBalanceLock(true);
- setWhiteBalanceLockStatus(QCamera::Locked, QCamera::LockAcquired);
- }
- }
-
- if (m_exposureLockStatus == QCamera::Searching || m_whiteBalanceLockStatus == QCamera::Searching)
- m_recalculateTimer->start();
-}
-
-void QAndroidCameraLocksControl::unlock(QCamera::LockTypes locks)
-{
- if (!m_session->camera())
- return;
-
- if (m_recalculateTimer->isActive())
- m_recalculateTimer->stop();
-
- // filter out unsupported locks
- locks &= m_supportedLocks;
-
- if (locks.testFlag(QCamera::LockFocus)) {
- m_session->camera()->cancelAutoFocus();
- setFocusLockStatus(QCamera::Unlocked, QCamera::UserRequest);
- }
-
- if (locks.testFlag(QCamera::LockExposure)) {
- m_session->camera()->setAutoExposureLock(false);
- setExposureLockStatus(QCamera::Unlocked, QCamera::UserRequest);
- }
-
- if (locks.testFlag(QCamera::LockWhiteBalance)) {
- m_session->camera()->setAutoWhiteBalanceLock(false);
- setWhiteBalanceLockStatus(QCamera::Unlocked, QCamera::UserRequest);
- }
-}
-
-void QAndroidCameraLocksControl::onCameraOpened()
-{
- m_supportedLocks = QCamera::NoLock;
- m_focusLockStatus = QCamera::Unlocked;
- m_exposureLockStatus = QCamera::Unlocked;
- m_whiteBalanceLockStatus = QCamera::Unlocked;
-
- // check if focus lock is supported
- QStringList focusModes = m_session->camera()->getSupportedFocusModes();
- for (int i = 0; i < focusModes.size(); ++i) {
- const QString &focusMode = focusModes.at(i);
- if (focusMode == QLatin1String("auto")
- || focusMode == QLatin1String("continuous-picture")
- || focusMode == QLatin1String("continuous-video")
- || focusMode == QLatin1String("macro")) {
-
- m_supportedLocks |= QCamera::LockFocus;
- setFocusLockStatus(QCamera::Unlocked, QCamera::UserRequest);
-
- connect(m_session->camera(), SIGNAL(autoFocusComplete(bool)),
- this, SLOT(onCameraAutoFocusComplete(bool)));
-
- break;
- }
- }
-
- if (m_session->camera()->isAutoExposureLockSupported()) {
- m_supportedLocks |= QCamera::LockExposure;
- setExposureLockStatus(QCamera::Unlocked, QCamera::UserRequest);
- }
-
- if (m_session->camera()->isAutoWhiteBalanceLockSupported()) {
- m_supportedLocks |= QCamera::LockWhiteBalance;
- setWhiteBalanceLockStatus(QCamera::Unlocked, QCamera::UserRequest);
-
- connect(m_session->camera(), SIGNAL(whiteBalanceChanged()),
- this, SLOT(onWhiteBalanceChanged()));
- }
-}
-
-void QAndroidCameraLocksControl::onCameraAutoFocusComplete(bool success)
-{
- m_focusLockStatus = success ? QCamera::Locked : QCamera::Unlocked;
- QCamera::LockChangeReason reason = success ? QCamera::LockAcquired : QCamera::LockFailed;
- emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, reason);
-}
-
-void QAndroidCameraLocksControl::onRecalculateTimeOut()
-{
- if (m_exposureLockStatus == QCamera::Searching) {
- m_session->camera()->setAutoExposureLock(true);
- setExposureLockStatus(QCamera::Locked, QCamera::LockAcquired);
- }
-
- if (m_whiteBalanceLockStatus == QCamera::Searching) {
- m_session->camera()->setAutoWhiteBalanceLock(true);
- setWhiteBalanceLockStatus(QCamera::Locked, QCamera::LockAcquired);
- }
-}
-
-void QAndroidCameraLocksControl::onWhiteBalanceChanged()
-{
- // changing the white balance mode releases the white balance lock
- if (m_whiteBalanceLockStatus != QCamera::Unlocked)
- setWhiteBalanceLockStatus(QCamera::Unlocked, QCamera::LockLost);
-}
-
-void QAndroidCameraLocksControl::setFocusLockStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason)
-{
- m_focusLockStatus = status;
- emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, reason);
-}
-
-void QAndroidCameraLocksControl::setWhiteBalanceLockStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason)
-{
- m_whiteBalanceLockStatus = status;
- emit lockStatusChanged(QCamera::LockWhiteBalance, m_whiteBalanceLockStatus, reason);
-}
-
-void QAndroidCameraLocksControl::setExposureLockStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason)
-{
- m_exposureLockStatus = status;
- emit lockStatusChanged(QCamera::LockExposure, m_exposureLockStatus, reason);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcameralockscontrol.h b/src/plugins/android/src/mediacapture/qandroidcameralockscontrol.h
deleted file mode 100644
index 149da0f32..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameralockscontrol.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERALOCKSCONTROL_H
-#define QANDROIDCAMERALOCKSCONTROL_H
-
-#include <qcameralockscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-class QTimer;
-
-class QAndroidCameraLocksControl : public QCameraLocksControl
-{
- Q_OBJECT
-public:
- explicit QAndroidCameraLocksControl(QAndroidCameraSession *session);
-
- QCamera::LockTypes supportedLocks() const override;
- QCamera::LockStatus lockStatus(QCamera::LockType lock) const override;
- void searchAndLock(QCamera::LockTypes locks) override;
- void unlock(QCamera::LockTypes locks) override;
-
-private Q_SLOTS:
- void onCameraOpened();
- void onCameraAutoFocusComplete(bool success);
- void onRecalculateTimeOut();
- void onWhiteBalanceChanged();
-
-private:
- void setFocusLockStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason);
- void setWhiteBalanceLockStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason);
- void setExposureLockStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason);
-
- QAndroidCameraSession *m_session;
-
- QTimer *m_recalculateTimer;
-
- QCamera::LockTypes m_supportedLocks;
-
- QCamera::LockStatus m_focusLockStatus;
- QCamera::LockStatus m_exposureLockStatus;
- QCamera::LockStatus m_whiteBalanceLockStatus;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERALOCKSCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
deleted file mode 100644
index ff5c7be15..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
+++ /dev/null
@@ -1,942 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Ruslan Baratov
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcamerasession.h"
-
-#include "androidcamera.h"
-#include "androidmultimediautils.h"
-#include "qandroidvideooutput.h"
-#include "qandroidmediavideoprobecontrol.h"
-#include "qandroidmultimediautils.h"
-#include "qandroidcameravideorenderercontrol.h"
-#include <qabstractvideosurface.h>
-#include <QtConcurrent/qtconcurrentrun.h>
-#include <qfile.h>
-#include <qguiapplication.h>
-#include <qdebug.h>
-#include <qvideoframe.h>
-#include <private/qmemoryvideobuffer_p.h>
-#include <QtCore/private/qjnihelpers_p.h>
-
-QT_BEGIN_NAMESPACE
-
-Q_GLOBAL_STATIC(QList<AndroidCameraInfo>, g_availableCameras)
-
-QAndroidCameraSession::QAndroidCameraSession(QObject *parent)
- : QObject(parent)
- , m_selectedCamera(0)
- , m_camera(0)
- , m_nativeOrientation(0)
- , m_videoOutput(0)
- , m_captureMode(QCamera::CaptureStillImage)
- , m_state(QCamera::UnloadedState)
- , m_savedState(-1)
- , m_status(QCamera::UnloadedStatus)
- , m_previewStarted(false)
- , m_captureDestination(QCameraImageCapture::CaptureToFile)
- , m_captureImageDriveMode(QCameraImageCapture::SingleImageCapture)
- , m_lastImageCaptureId(0)
- , m_readyForCapture(false)
- , m_captureCanceled(false)
- , m_currentImageCaptureId(-1)
- , m_previewCallback(0)
- , m_keepActive(false)
-{
- m_mediaStorageLocation.addStorageLocation(
- QMediaStorageLocation::Pictures,
- AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::DCIM));
-
- if (qApp) {
- connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
- this, SLOT(onApplicationStateChanged(Qt::ApplicationState)));
- }
-}
-
-QAndroidCameraSession::~QAndroidCameraSession()
-{
- close();
-}
-
-void QAndroidCameraSession::setCaptureMode(QCamera::CaptureModes mode)
-{
- if (m_captureMode == mode || !isCaptureModeSupported(mode))
- return;
-
- m_captureMode = mode;
- emit captureModeChanged(m_captureMode);
-
- if (m_previewStarted && m_captureMode.testFlag(QCamera::CaptureStillImage))
- applyViewfinderSettings(m_actualImageSettings.resolution());
-}
-
-bool QAndroidCameraSession::isCaptureModeSupported(QCamera::CaptureModes mode) const
-{
- if (mode & (QCamera::CaptureStillImage & QCamera::CaptureVideo))
- return false;
-
- return true;
-}
-
-void QAndroidCameraSession::setState(QCamera::State state)
-{
- if (m_state == state)
- return;
-
- m_state = state;
- emit stateChanged(m_state);
-
- // If the application is inactive, the camera shouldn't be started. Save the desired state
- // instead and it will be set when the application becomes active.
- if (qApp->applicationState() == Qt::ApplicationActive)
- setStateHelper(state);
- else
- m_savedState = state;
-}
-
-void QAndroidCameraSession::setStateHelper(QCamera::State state)
-{
- switch (state) {
- case QCamera::UnloadedState:
- close();
- break;
- case QCamera::LoadedState:
- case QCamera::ActiveState:
- if (!m_camera && !open()) {
- m_state = QCamera::UnloadedState;
- emit stateChanged(m_state);
- emit error(QCamera::CameraError, QStringLiteral("Failed to open camera"));
- m_status = QCamera::UnloadedStatus;
- emit statusChanged(m_status);
- return;
- }
- if (state == QCamera::ActiveState)
- startPreview();
- else if (state == QCamera::LoadedState)
- stopPreview();
- break;
- }
-}
-
-void QAndroidCameraSession::updateAvailableCameras()
-{
- g_availableCameras->clear();
-
- const int numCameras = AndroidCamera::getNumberOfCameras();
- for (int i = 0; i < numCameras; ++i) {
- AndroidCameraInfo info;
- AndroidCamera::getCameraInfo(i, &info);
-
- if (!info.name.isNull())
- g_availableCameras->append(info);
- }
-}
-
-const QList<AndroidCameraInfo> &QAndroidCameraSession::availableCameras()
-{
- if (g_availableCameras->isEmpty())
- updateAvailableCameras();
-
- return *g_availableCameras;
-}
-
-bool QAndroidCameraSession::open()
-{
- close();
-
- m_status = QCamera::LoadingStatus;
- emit statusChanged(m_status);
-
- m_camera = AndroidCamera::open(m_selectedCamera);
-
- if (m_camera) {
- connect(m_camera, SIGNAL(pictureExposed()), this, SLOT(onCameraPictureExposed()));
- connect(m_camera, SIGNAL(lastPreviewFrameFetched(QVideoFrame)),
- this, SLOT(onLastPreviewFrameFetched(QVideoFrame)),
- Qt::DirectConnection);
- connect(m_camera, SIGNAL(newPreviewFrame(QVideoFrame)),
- this, SLOT(onNewPreviewFrame(QVideoFrame)),
- Qt::DirectConnection);
- connect(m_camera, SIGNAL(pictureCaptured(QByteArray)), this, SLOT(onCameraPictureCaptured(QByteArray)));
- connect(m_camera, SIGNAL(previewStarted()), this, SLOT(onCameraPreviewStarted()));
- connect(m_camera, SIGNAL(previewStopped()), this, SLOT(onCameraPreviewStopped()));
- connect(m_camera, &AndroidCamera::previewFailedToStart, this, &QAndroidCameraSession::onCameraPreviewFailedToStart);
- connect(m_camera, &AndroidCamera::takePictureFailed, this, &QAndroidCameraSession::onCameraTakePictureFailed);
-
- m_nativeOrientation = m_camera->getNativeOrientation();
-
- m_status = QCamera::LoadedStatus;
-
- if (m_camera->getPreviewFormat() != AndroidCamera::NV21)
- m_camera->setPreviewFormat(AndroidCamera::NV21);
-
- m_camera->notifyNewFrames(m_videoProbes.count() || m_previewCallback);
-
- emit opened();
- emit statusChanged(m_status);
- }
-
- return m_camera != 0;
-}
-
-void QAndroidCameraSession::close()
-{
- if (!m_camera)
- return;
-
- stopPreview();
-
- m_status = QCamera::UnloadingStatus;
- emit statusChanged(m_status);
-
- m_readyForCapture = false;
- m_currentImageCaptureId = -1;
- m_currentImageCaptureFileName.clear();
- m_actualImageSettings = m_requestedImageSettings;
- m_actualViewfinderSettings = m_requestedViewfinderSettings;
-
- m_camera->release();
- delete m_camera;
- m_camera = 0;
-
- m_status = QCamera::UnloadedStatus;
- emit statusChanged(m_status);
-}
-
-void QAndroidCameraSession::setVideoOutput(QAndroidVideoOutput *output)
-{
- if (m_videoOutput) {
- m_videoOutput->stop();
- m_videoOutput->reset();
- }
-
- if (output) {
- m_videoOutput = output;
- if (m_videoOutput->isReady())
- onVideoOutputReady(true);
- else
- connect(m_videoOutput, SIGNAL(readyChanged(bool)), this, SLOT(onVideoOutputReady(bool)));
- } else {
- m_videoOutput = 0;
- }
-}
-
-void QAndroidCameraSession::setViewfinderSettings(const QCameraViewfinderSettings &settings)
-{
- if (m_requestedViewfinderSettings == settings)
- return;
-
- m_requestedViewfinderSettings = m_actualViewfinderSettings = settings;
-
- if (m_readyForCapture)
- applyViewfinderSettings();
-}
-
-void QAndroidCameraSession::applyViewfinderSettings(const QSize &captureSize, bool restartPreview)
-{
- if (!m_camera)
- return;
-
- const QSize currentViewfinderResolution = m_camera->previewSize();
- const AndroidCamera::ImageFormat currentPreviewFormat = m_camera->getPreviewFormat();
- const AndroidCamera::FpsRange currentFpsRange = m_camera->getPreviewFpsRange();
-
- // -- adjust resolution
- QSize adjustedViewfinderResolution;
- const bool validCaptureSize = captureSize.width() > 0 && captureSize.height() > 0;
- if (m_captureMode.testFlag(QCamera::CaptureVideo)
- && validCaptureSize
- && m_camera->getPreferredPreviewSizeForVideo().isEmpty()) {
- // According to the Android doc, if getPreferredPreviewSizeForVideo() returns null, it means
- // the preview size cannot be different from the capture size
- adjustedViewfinderResolution = captureSize;
- } else {
- qreal captureAspectRatio = 0;
- if (validCaptureSize)
- captureAspectRatio = qreal(captureSize.width()) / qreal(captureSize.height());
-
- const QList<QSize> previewSizes = m_camera->getSupportedPreviewSizes();
-
- const QSize vfRes = m_requestedViewfinderSettings.resolution();
- if (vfRes.width() > 0 && vfRes.height() > 0
- && (!validCaptureSize || qAbs(captureAspectRatio - (qreal(vfRes.width()) / vfRes.height())) < 0.01)
- && previewSizes.contains(vfRes)) {
- adjustedViewfinderResolution = vfRes;
- } else if (validCaptureSize) {
- // search for viewfinder resolution with the same aspect ratio
- qreal minAspectDiff = 1;
- QSize closestResolution;
- for (int i = previewSizes.count() - 1; i >= 0; --i) {
- const QSize &size = previewSizes.at(i);
- const qreal sizeAspect = qreal(size.width()) / size.height();
- if (qFuzzyCompare(captureAspectRatio, sizeAspect)) {
- adjustedViewfinderResolution = size;
- break;
- } else if (minAspectDiff > qAbs(sizeAspect - captureAspectRatio)) {
- closestResolution = size;
- minAspectDiff = qAbs(sizeAspect - captureAspectRatio);
- }
- }
- if (!adjustedViewfinderResolution.isValid()) {
- qWarning("Cannot find a viewfinder resolution matching the capture aspect ratio.");
- if (closestResolution.isValid()) {
- adjustedViewfinderResolution = closestResolution;
- qWarning("Using closest viewfinder resolution.");
- } else {
- return;
- }
- }
- } else {
- adjustedViewfinderResolution = previewSizes.last();
- }
- }
- m_actualViewfinderSettings.setResolution(adjustedViewfinderResolution);
-
- // -- adjust pixel format
-
- AndroidCamera::ImageFormat adjustedPreviewFormat = AndroidCamera::NV21;
- if (m_requestedViewfinderSettings.pixelFormat() != QVideoFrame::Format_Invalid) {
- const AndroidCamera::ImageFormat f = AndroidImageFormatFromQtPixelFormat(m_requestedViewfinderSettings.pixelFormat());
- if (f == AndroidCamera::UnknownImageFormat || !m_camera->getSupportedPreviewFormats().contains(f))
- qWarning("Unsupported viewfinder pixel format");
- else
- adjustedPreviewFormat = f;
- }
- m_actualViewfinderSettings.setPixelFormat(QtPixelFormatFromAndroidImageFormat(adjustedPreviewFormat));
-
- // -- adjust FPS
-
- AndroidCamera::FpsRange adjustedFps = currentFpsRange;
- const AndroidCamera::FpsRange requestedFpsRange = AndroidCamera::FpsRange::makeFromQReal(m_requestedViewfinderSettings.minimumFrameRate(),
- m_requestedViewfinderSettings.maximumFrameRate());
- if (requestedFpsRange.min > 0 || requestedFpsRange.max > 0) {
- int minDist = INT_MAX;
- const QList<AndroidCamera::FpsRange> supportedFpsRanges = m_camera->getSupportedPreviewFpsRange();
- auto it = supportedFpsRanges.rbegin(), end = supportedFpsRanges.rend();
- for (; it != end; ++it) {
- int dist = (requestedFpsRange.min > 0 ? qAbs(requestedFpsRange.min - it->min) : 0)
- + (requestedFpsRange.max > 0 ? qAbs(requestedFpsRange.max - it->max) : 0);
- if (dist < minDist) {
- minDist = dist;
- adjustedFps = *it;
- if (minDist == 0)
- break; // exact match
- }
- }
- }
- m_actualViewfinderSettings.setMinimumFrameRate(adjustedFps.getMinReal());
- m_actualViewfinderSettings.setMaximumFrameRate(adjustedFps.getMaxReal());
-
- // -- Set values on camera
-
- if (currentViewfinderResolution != adjustedViewfinderResolution
- || currentPreviewFormat != adjustedPreviewFormat
- || currentFpsRange.min != adjustedFps.min
- || currentFpsRange.max != adjustedFps.max) {
-
- if (m_videoOutput)
- m_videoOutput->setVideoSize(adjustedViewfinderResolution);
-
- // if preview is started, we have to stop it first before changing its size
- if (m_previewStarted && restartPreview)
- m_camera->stopPreview();
-
- m_camera->setPreviewSize(adjustedViewfinderResolution);
- m_camera->setPreviewFormat(adjustedPreviewFormat);
- m_camera->setPreviewFpsRange(adjustedFps);
-
- // restart preview
- if (m_previewStarted && restartPreview)
- m_camera->startPreview();
- }
-}
-
-QList<QSize> QAndroidCameraSession::getSupportedPreviewSizes() const
-{
- return m_camera ? m_camera->getSupportedPreviewSizes() : QList<QSize>();
-}
-
-QList<QVideoFrame::PixelFormat> QAndroidCameraSession::getSupportedPixelFormats() const
-{
- QList<QVideoFrame::PixelFormat> formats;
-
- if (!m_camera)
- return formats;
-
- const QList<AndroidCamera::ImageFormat> nativeFormats = m_camera->getSupportedPreviewFormats();
-
- formats.reserve(nativeFormats.size());
-
- for (AndroidCamera::ImageFormat nativeFormat : nativeFormats) {
- QVideoFrame::PixelFormat format = QtPixelFormatFromAndroidImageFormat(nativeFormat);
- if (format != QVideoFrame::Format_Invalid)
- formats.append(format);
- }
-
- return formats;
-}
-
-QList<AndroidCamera::FpsRange> QAndroidCameraSession::getSupportedPreviewFpsRange() const
-{
- return m_camera ? m_camera->getSupportedPreviewFpsRange() : QList<AndroidCamera::FpsRange>();
-}
-
-struct NullSurface : QAbstractVideoSurface
-{
- NullSurface(QObject *parent = nullptr) : QAbstractVideoSurface(parent) { }
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(
- QAbstractVideoBuffer::HandleType type = QAbstractVideoBuffer::NoHandle) const override
- {
- QList<QVideoFrame::PixelFormat> result;
- if (type == QAbstractVideoBuffer::NoHandle)
- result << QVideoFrame::Format_NV21;
-
- return result;
- }
-
- bool present(const QVideoFrame &) { return false; }
-};
-
-bool QAndroidCameraSession::startPreview()
-{
- if (!m_camera)
- return false;
-
- if (m_previewStarted)
- return true;
-
- if (m_videoOutput) {
- if (!m_videoOutput->isReady())
- return true; // delay starting until the video output is ready
-
- Q_ASSERT(m_videoOutput->surfaceTexture() || m_videoOutput->surfaceHolder());
-
- if ((m_videoOutput->surfaceTexture() && !m_camera->setPreviewTexture(m_videoOutput->surfaceTexture()))
- || (m_videoOutput->surfaceHolder() && !m_camera->setPreviewDisplay(m_videoOutput->surfaceHolder())))
- return false;
- } else {
- auto control = new QAndroidCameraVideoRendererControl(this, this);
- control->setSurface(new NullSurface(this));
- qWarning() << "Starting camera without viewfinder available";
-
- return true;
- }
-
- m_status = QCamera::StartingStatus;
- emit statusChanged(m_status);
-
- applyImageSettings();
- applyViewfinderSettings(m_captureMode.testFlag(QCamera::CaptureStillImage) ? m_actualImageSettings.resolution()
- : QSize());
-
- AndroidMultimediaUtils::enableOrientationListener(true);
-
- // Before API level 24 the orientation was always 0, which is what we're expecting, so
- // we'll enforce that here.
- if (QtAndroidPrivate::androidSdkVersion() > 23)
- m_camera->setDisplayOrientation(0);
-
- m_camera->startPreview();
- m_previewStarted = true;
-
- return true;
-}
-
-void QAndroidCameraSession::stopPreview()
-{
- if (!m_camera || !m_previewStarted)
- return;
-
- m_status = QCamera::StoppingStatus;
- emit statusChanged(m_status);
-
- AndroidMultimediaUtils::enableOrientationListener(false);
-
- m_camera->stopPreview();
- m_camera->setPreviewSize(QSize());
- m_camera->setPreviewTexture(0);
- m_camera->setPreviewDisplay(0);
-
- if (m_videoOutput) {
- m_videoOutput->stop();
- m_videoOutput->reset();
- }
- m_previewStarted = false;
-}
-
-void QAndroidCameraSession::setImageSettings(const QImageEncoderSettings &settings)
-{
- if (m_requestedImageSettings == settings)
- return;
-
- m_requestedImageSettings = m_actualImageSettings = settings;
-
- applyImageSettings();
-
- if (m_readyForCapture && m_captureMode.testFlag(QCamera::CaptureStillImage))
- applyViewfinderSettings(m_actualImageSettings.resolution());
-}
-
-int QAndroidCameraSession::currentCameraRotation() const
-{
- if (!m_camera)
- return 0;
-
- // subtract natural camera orientation and physical device orientation
- int rotation = 0;
- int deviceOrientation = (AndroidMultimediaUtils::getDeviceOrientation() + 45) / 90 * 90;
- if (m_camera->getFacing() == AndroidCamera::CameraFacingFront)
- rotation = (m_nativeOrientation - deviceOrientation + 360) % 360;
- else // back-facing camera
- rotation = (m_nativeOrientation + deviceOrientation) % 360;
-
- return rotation;
-}
-
-void QAndroidCameraSession::addProbe(QAndroidMediaVideoProbeControl *probe)
-{
- m_videoProbesMutex.lock();
- if (probe)
- m_videoProbes << probe;
- if (m_camera)
- m_camera->notifyNewFrames(m_videoProbes.count() || m_previewCallback);
- m_videoProbesMutex.unlock();
-}
-
-void QAndroidCameraSession::removeProbe(QAndroidMediaVideoProbeControl *probe)
-{
- m_videoProbesMutex.lock();
- m_videoProbes.remove(probe);
- if (m_camera)
- m_camera->notifyNewFrames(m_videoProbes.count() || m_previewCallback);
- m_videoProbesMutex.unlock();
-}
-
-void QAndroidCameraSession::setPreviewFormat(AndroidCamera::ImageFormat format)
-{
- if (format == AndroidCamera::UnknownImageFormat)
- return;
-
- m_camera->setPreviewFormat(format);
-}
-
-void QAndroidCameraSession::setPreviewCallback(PreviewCallback *callback)
-{
- m_videoProbesMutex.lock();
- m_previewCallback = callback;
- if (m_camera)
- m_camera->notifyNewFrames(m_videoProbes.count() || m_previewCallback);
- m_videoProbesMutex.unlock();
-}
-
-void QAndroidCameraSession::applyImageSettings()
-{
- if (!m_camera)
- return;
-
- if (m_actualImageSettings.codec().isEmpty())
- m_actualImageSettings.setCodec(QLatin1String("jpeg"));
-
- const QSize requestedResolution = m_requestedImageSettings.resolution();
- const QList<QSize> supportedResolutions = m_camera->getSupportedPictureSizes();
- if (!requestedResolution.isValid()) {
- // if the viewfinder resolution is explicitly set, pick the highest available capture
- // resolution with the same aspect ratio
- if (m_requestedViewfinderSettings.resolution().isValid()) {
- const QSize vfResolution = m_actualViewfinderSettings.resolution();
- const qreal vfAspectRatio = qreal(vfResolution.width()) / vfResolution.height();
-
- auto it = supportedResolutions.rbegin(), end = supportedResolutions.rend();
- for (; it != end; ++it) {
- if (qAbs(vfAspectRatio - (qreal(it->width()) / it->height())) < 0.01) {
- m_actualImageSettings.setResolution(*it);
- break;
- }
- }
- } else {
- // otherwise, use the highest supported one
- m_actualImageSettings.setResolution(supportedResolutions.last());
- }
- } else if (!supportedResolutions.contains(requestedResolution)) {
- // if the requested resolution is not supported, find the closest one
- int reqPixelCount = requestedResolution.width() * requestedResolution.height();
- QList<int> supportedPixelCounts;
- for (int i = 0; i < supportedResolutions.size(); ++i) {
- const QSize &s = supportedResolutions.at(i);
- supportedPixelCounts.append(s.width() * s.height());
- }
- int closestIndex = qt_findClosestValue(supportedPixelCounts, reqPixelCount);
- m_actualImageSettings.setResolution(supportedResolutions.at(closestIndex));
- }
- m_camera->setPictureSize(m_actualImageSettings.resolution());
-
- int jpegQuality = 100;
- switch (m_requestedImageSettings.quality()) {
- case QMultimedia::VeryLowQuality:
- jpegQuality = 20;
- break;
- case QMultimedia::LowQuality:
- jpegQuality = 40;
- break;
- case QMultimedia::NormalQuality:
- jpegQuality = 60;
- break;
- case QMultimedia::HighQuality:
- jpegQuality = 80;
- break;
- case QMultimedia::VeryHighQuality:
- jpegQuality = 100;
- break;
- }
- m_camera->setJpegQuality(jpegQuality);
-}
-
-bool QAndroidCameraSession::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const
-{
- return destination & (QCameraImageCapture::CaptureToFile | QCameraImageCapture::CaptureToBuffer);
-}
-
-QCameraImageCapture::CaptureDestinations QAndroidCameraSession::captureDestination() const
-{
- return m_captureDestination;
-}
-
-void QAndroidCameraSession::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination)
-{
- if (m_captureDestination != destination) {
- m_captureDestination = destination;
- emit captureDestinationChanged(m_captureDestination);
- }
-}
-
-bool QAndroidCameraSession::isReadyForCapture() const
-{
- return m_status == QCamera::ActiveStatus && m_readyForCapture;
-}
-
-void QAndroidCameraSession::setReadyForCapture(bool ready)
-{
- if (m_readyForCapture == ready)
- return;
-
- m_readyForCapture = ready;
- emit readyForCaptureChanged(ready);
-}
-
-QCameraImageCapture::DriveMode QAndroidCameraSession::driveMode() const
-{
- return m_captureImageDriveMode;
-}
-
-void QAndroidCameraSession::setDriveMode(QCameraImageCapture::DriveMode mode)
-{
- m_captureImageDriveMode = mode;
-}
-
-int QAndroidCameraSession::capture(const QString &fileName)
-{
- ++m_lastImageCaptureId;
-
- if (!isReadyForCapture()) {
- emit imageCaptureError(m_lastImageCaptureId, QCameraImageCapture::NotReadyError,
- tr("Camera not ready"));
- return m_lastImageCaptureId;
- }
-
- if (m_captureImageDriveMode == QCameraImageCapture::SingleImageCapture) {
- setReadyForCapture(false);
-
- m_currentImageCaptureId = m_lastImageCaptureId;
- m_currentImageCaptureFileName = fileName;
-
- applyImageSettings();
- applyViewfinderSettings(m_actualImageSettings.resolution());
-
- // adjust picture rotation depending on the device orientation
- m_camera->setRotation(currentCameraRotation());
-
- m_camera->takePicture();
- } else {
- //: Drive mode is the camera's shutter mode, for example single shot, continuos exposure, etc.
- emit imageCaptureError(m_lastImageCaptureId, QCameraImageCapture::NotSupportedFeatureError,
- tr("Drive mode not supported"));
- }
-
- return m_lastImageCaptureId;
-}
-
-void QAndroidCameraSession::cancelCapture()
-{
- if (m_readyForCapture)
- return;
-
- m_captureCanceled = true;
-}
-
-void QAndroidCameraSession::onCameraTakePictureFailed()
-{
- emit imageCaptureError(m_currentImageCaptureId, QCameraImageCapture::ResourceError,
- tr("Failed to capture image"));
-
- // Preview needs to be restarted and the preview call back must be setup again
- m_camera->startPreview();
-}
-
-void QAndroidCameraSession::onCameraPictureExposed()
-{
- if (m_captureCanceled || !m_camera)
- return;
-
- emit imageExposed(m_currentImageCaptureId);
- m_camera->fetchLastPreviewFrame();
-}
-
-void QAndroidCameraSession::onLastPreviewFrameFetched(const QVideoFrame &frame)
-{
- if (m_captureCanceled || !m_camera)
- return;
-
- QtConcurrent::run(&QAndroidCameraSession::processPreviewImage, this,
- m_currentImageCaptureId,
- frame,
- m_camera->getRotation());
-}
-
-void QAndroidCameraSession::processPreviewImage(int id, const QVideoFrame &frame, int rotation)
-{
- // Preview display of front-facing cameras is flipped horizontally, but the frame data
- // we get here is not. Flip it ourselves if the camera is front-facing to match what the user
- // sees on the viewfinder.
- QTransform transform;
- if (m_camera->getFacing() == AndroidCamera::CameraFacingFront)
- transform.scale(-1, 1);
- transform.rotate(rotation);
-
- emit imageCaptured(id, frame.image().transformed(transform));
-}
-
-void QAndroidCameraSession::onNewPreviewFrame(const QVideoFrame &frame)
-{
- if (!m_camera)
- return;
-
- m_videoProbesMutex.lock();
-
- for (QAndroidMediaVideoProbeControl *probe : qAsConst(m_videoProbes))
- probe->newFrameProbed(frame);
-
- if (m_previewCallback)
- m_previewCallback->onFrameAvailable(frame);
-
- m_videoProbesMutex.unlock();
-}
-
-void QAndroidCameraSession::onCameraPictureCaptured(const QByteArray &data)
-{
- if (!m_captureCanceled) {
- // Loading and saving the captured image can be slow, do it in a separate thread
- QtConcurrent::run(&QAndroidCameraSession::processCapturedImage, this,
- m_currentImageCaptureId,
- data,
- m_actualImageSettings.resolution(),
- m_captureDestination,
- m_currentImageCaptureFileName);
- }
-
- m_captureCanceled = false;
-
- // Preview needs to be restarted after taking a picture
- if (m_camera)
- m_camera->startPreview();
-}
-
-void QAndroidCameraSession::onCameraPreviewStarted()
-{
- if (m_status == QCamera::StartingStatus) {
- m_status = QCamera::ActiveStatus;
- emit statusChanged(m_status);
- }
-
- setReadyForCapture(true);
-}
-
-void QAndroidCameraSession::onCameraPreviewFailedToStart()
-{
- if (m_status == QCamera::StartingStatus) {
- Q_EMIT error(QCamera::CameraError, tr("Camera preview failed to start."));
-
- AndroidMultimediaUtils::enableOrientationListener(false);
- m_camera->setPreviewSize(QSize());
- m_camera->setPreviewTexture(0);
- if (m_videoOutput) {
- m_videoOutput->stop();
- m_videoOutput->reset();
- }
- m_previewStarted = false;
-
- m_status = QCamera::LoadedStatus;
- emit statusChanged(m_status);
-
- setReadyForCapture(false);
- }
-}
-
-void QAndroidCameraSession::onCameraPreviewStopped()
-{
- if (m_status == QCamera::StoppingStatus) {
- m_status = QCamera::LoadedStatus;
- emit statusChanged(m_status);
- }
-
- setReadyForCapture(false);
-}
-
-void QAndroidCameraSession::processCapturedImage(int id,
- const QByteArray &data,
- const QSize &resolution,
- QCameraImageCapture::CaptureDestinations dest,
- const QString &fileName)
-{
-
-
- if (dest & QCameraImageCapture::CaptureToFile) {
- const QString actualFileName = m_mediaStorageLocation.generateFileName(fileName,
- QMediaStorageLocation::Pictures,
- QLatin1String("IMG_"),
- QLatin1String("jpg"));
-
- QFile file(actualFileName);
- if (file.open(QFile::WriteOnly)) {
- if (file.write(data) == data.size()) {
- // if the picture is saved into the standard picture location, register it
- // with the Android media scanner so it appears immediately in apps
- // such as the gallery.
- QString standardLoc = AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::DCIM);
- if (actualFileName.startsWith(standardLoc))
- AndroidMultimediaUtils::registerMediaFile(actualFileName);
-
- emit imageSaved(id, actualFileName);
- } else {
- emit imageCaptureError(id, QCameraImageCapture::OutOfSpaceError, file.errorString());
- }
- } else {
- const QString errorMessage = tr("Could not open destination file: %1").arg(actualFileName);
- emit imageCaptureError(id, QCameraImageCapture::ResourceError, errorMessage);
- }
- }
-
- if (dest & QCameraImageCapture::CaptureToBuffer) {
- QVideoFrame frame(new QMemoryVideoBuffer(data, -1), resolution, QVideoFrame::Format_Jpeg);
- emit imageAvailable(id, frame);
- }
-}
-
-QVideoFrame::PixelFormat QAndroidCameraSession::QtPixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat format)
-{
- switch (format) {
- case AndroidCamera::RGB565:
- return QVideoFrame::Format_RGB565;
- case AndroidCamera::NV21:
- return QVideoFrame::Format_NV21;
- case AndroidCamera::YUY2:
- return QVideoFrame::Format_YUYV;
- case AndroidCamera::JPEG:
- return QVideoFrame::Format_Jpeg;
- case AndroidCamera::YV12:
- return QVideoFrame::Format_YV12;
- default:
- return QVideoFrame::Format_Invalid;
- }
-}
-
-AndroidCamera::ImageFormat QAndroidCameraSession::AndroidImageFormatFromQtPixelFormat(QVideoFrame::PixelFormat format)
-{
- switch (format) {
- case QVideoFrame::Format_RGB565:
- return AndroidCamera::RGB565;
- case QVideoFrame::Format_NV21:
- return AndroidCamera::NV21;
- case QVideoFrame::Format_YUYV:
- return AndroidCamera::YUY2;
- case QVideoFrame::Format_Jpeg:
- return AndroidCamera::JPEG;
- case QVideoFrame::Format_YV12:
- return AndroidCamera::YV12;
- default:
- return AndroidCamera::UnknownImageFormat;
- }
-}
-
-void QAndroidCameraSession::onVideoOutputReady(bool ready)
-{
- if (ready && m_state == QCamera::ActiveState)
- startPreview();
-}
-
-void QAndroidCameraSession::onApplicationStateChanged(Qt::ApplicationState state)
-{
- switch (state) {
- case Qt::ApplicationInactive:
- if (!m_keepActive && m_state != QCamera::UnloadedState) {
- m_savedState = m_state;
- close();
- m_state = QCamera::UnloadedState;
- emit stateChanged(m_state);
- }
- break;
- case Qt::ApplicationActive:
- if (m_savedState != -1) {
- setStateHelper(QCamera::State(m_savedState));
- m_savedState = -1;
- }
- break;
- default:
- break;
- }
-}
-
-bool QAndroidCameraSession::requestRecordingPermission()
-{
- m_keepActive = true;
- const bool result = qt_androidRequestRecordingPermission();
- m_keepActive = false;
- return result;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerasession.h b/src/plugins/android/src/mediacapture/qandroidcamerasession.h
deleted file mode 100644
index 728dc484e..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcamerasession.h
+++ /dev/null
@@ -1,205 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Ruslan Baratov
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERASESSION_H
-#define QANDROIDCAMERASESSION_H
-
-#include <qcamera.h>
-#include <qmediaencodersettings.h>
-#include <QCameraImageCapture>
-#include <QSet>
-#include <QMutex>
-#include <private/qmediastoragelocation_p.h>
-#include "androidcamera.h"
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidVideoOutput;
-class QAndroidMediaVideoProbeControl;
-
-class QAndroidCameraSession : public QObject
-{
- Q_OBJECT
-public:
- explicit QAndroidCameraSession(QObject *parent = 0);
- ~QAndroidCameraSession();
-
- static const QList<AndroidCameraInfo> &availableCameras();
-
- void setSelectedCamera(int cameraId) { m_selectedCamera = cameraId; }
- AndroidCamera *camera() const { return m_camera; }
-
- QCamera::State state() const { return m_state; }
- void setState(QCamera::State state);
-
- QCamera::Status status() const { return m_status; }
-
- QCamera::CaptureModes captureMode() const { return m_captureMode; }
- void setCaptureMode(QCamera::CaptureModes mode);
- bool isCaptureModeSupported(QCamera::CaptureModes mode) const;
-
- QCameraViewfinderSettings viewfinderSettings() const { return m_actualViewfinderSettings; }
- void setViewfinderSettings(const QCameraViewfinderSettings &settings);
- void applyViewfinderSettings(const QSize &captureSize = QSize(), bool restartPreview = true);
-
- QAndroidVideoOutput *videoOutput() const { return m_videoOutput; }
- void setVideoOutput(QAndroidVideoOutput *output);
-
- QList<QSize> getSupportedPreviewSizes() const;
- QList<QVideoFrame::PixelFormat> getSupportedPixelFormats() const;
- QList<AndroidCamera::FpsRange> getSupportedPreviewFpsRange() const;
-
- QImageEncoderSettings imageSettings() const { return m_actualImageSettings; }
- void setImageSettings(const QImageEncoderSettings &settings);
-
- bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const;
- QCameraImageCapture::CaptureDestinations captureDestination() const;
- void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination);
-
- bool isReadyForCapture() const;
- void setReadyForCapture(bool ready);
- QCameraImageCapture::DriveMode driveMode() const;
- void setDriveMode(QCameraImageCapture::DriveMode mode);
- int capture(const QString &fileName);
- void cancelCapture();
-
- int currentCameraRotation() const;
-
- void addProbe(QAndroidMediaVideoProbeControl *probe);
- void removeProbe(QAndroidMediaVideoProbeControl *probe);
-
- void setPreviewFormat(AndroidCamera::ImageFormat format);
-
- struct PreviewCallback
- {
- virtual void onFrameAvailable(const QVideoFrame &frame) = 0;
- };
- void setPreviewCallback(PreviewCallback *callback);
- bool requestRecordingPermission();
-
-Q_SIGNALS:
- void statusChanged(QCamera::Status status);
- void stateChanged(QCamera::State);
- void error(int error, const QString &errorString);
- void captureModeChanged(QCamera::CaptureModes);
- void opened();
-
- void captureDestinationChanged(QCameraImageCapture::CaptureDestinations destination);
-
- void readyForCaptureChanged(bool);
- void imageExposed(int id);
- void imageCaptured(int id, const QImage &preview);
- void imageMetadataAvailable(int id, const QString &key, const QVariant &value);
- void imageAvailable(int id, const QVideoFrame &buffer);
- void imageSaved(int id, const QString &fileName);
- void imageCaptureError(int id, int error, const QString &errorString);
-
-private Q_SLOTS:
- void onVideoOutputReady(bool ready);
-
- void onApplicationStateChanged(Qt::ApplicationState state);
-
- void onCameraTakePictureFailed();
- void onCameraPictureExposed();
- void onCameraPictureCaptured(const QByteArray &data);
- void onLastPreviewFrameFetched(const QVideoFrame &frame);
- void onNewPreviewFrame(const QVideoFrame &frame);
- void onCameraPreviewStarted();
- void onCameraPreviewFailedToStart();
- void onCameraPreviewStopped();
-
-private:
- static void updateAvailableCameras();
-
- bool open();
- void close();
-
- bool startPreview();
- void stopPreview();
-
- void applyImageSettings();
-
- void processPreviewImage(int id, const QVideoFrame &frame, int rotation);
- void processCapturedImage(int id,
- const QByteArray &data,
- const QSize &resolution,
- QCameraImageCapture::CaptureDestinations dest,
- const QString &fileName);
-
- static QVideoFrame::PixelFormat QtPixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat);
- static AndroidCamera::ImageFormat AndroidImageFormatFromQtPixelFormat(QVideoFrame::PixelFormat);
-
- void setStateHelper(QCamera::State state);
-
- int m_selectedCamera;
- AndroidCamera *m_camera;
- int m_nativeOrientation;
- QAndroidVideoOutput *m_videoOutput;
-
- QCamera::CaptureModes m_captureMode;
- QCamera::State m_state;
- int m_savedState;
- QCamera::Status m_status;
- bool m_previewStarted;
-
- QCameraViewfinderSettings m_requestedViewfinderSettings;
- QCameraViewfinderSettings m_actualViewfinderSettings;
-
- QImageEncoderSettings m_requestedImageSettings;
- QImageEncoderSettings m_actualImageSettings;
- QCameraImageCapture::CaptureDestinations m_captureDestination;
- QCameraImageCapture::DriveMode m_captureImageDriveMode;
- int m_lastImageCaptureId;
- bool m_readyForCapture;
- bool m_captureCanceled;
- int m_currentImageCaptureId;
- QString m_currentImageCaptureFileName;
-
- QMediaStorageLocation m_mediaStorageLocation;
-
- QSet<QAndroidMediaVideoProbeControl *> m_videoProbes;
- QMutex m_videoProbesMutex;
- PreviewCallback *m_previewCallback;
- bool m_keepActive;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERASESSION_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcameravideorenderercontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcameravideorenderercontrol.cpp
deleted file mode 100644
index 2243df732..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameravideorenderercontrol.cpp
+++ /dev/null
@@ -1,281 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcameravideorenderercontrol.h"
-
-#include "qandroidcamerasession.h"
-#include "qandroidvideooutput.h"
-#include "androidsurfaceview.h"
-#include "qandroidmultimediautils.h"
-#include <qabstractvideosurface.h>
-#include <qvideosurfaceformat.h>
-#include <qcoreapplication.h>
-#include <qthread.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraDataVideoOutput : public QAndroidVideoOutput
- , public QAndroidCameraSession::PreviewCallback
-{
- Q_OBJECT
-public:
- explicit QAndroidCameraDataVideoOutput(QAndroidCameraVideoRendererControl *control);
- ~QAndroidCameraDataVideoOutput() override;
-
- AndroidSurfaceHolder *surfaceHolder() override;
-
- bool isReady() override;
-
- void stop() override;
-
-private Q_SLOTS:
- void onSurfaceCreated();
- void configureFormat();
-
-private:
- void onFrameAvailable(const QVideoFrame &frame);
- void presentFrame();
- bool event(QEvent *);
-
- QAndroidCameraVideoRendererControl *m_control;
- AndroidSurfaceView *m_surfaceView;
- QMutex m_mutex;
- QVideoFrame::PixelFormat m_pixelFormat;
- QVideoFrame m_lastFrame;
-};
-
-QAndroidCameraDataVideoOutput::QAndroidCameraDataVideoOutput(QAndroidCameraVideoRendererControl *control)
- : QAndroidVideoOutput(control)
- , m_control(control)
- , m_pixelFormat(QVideoFrame::Format_Invalid)
-{
- // The camera preview cannot be started unless we set a SurfaceTexture or a
- // SurfaceHolder. In this case we don't actually care about either of these, but since
- // we need to, we setup an offscreen dummy SurfaceView in order to be able to start
- // the camera preview. We'll then be able to use setPreviewCallbackWithBuffer() to
- // get the raw data.
-
- m_surfaceView = new AndroidSurfaceView;
-
- connect(m_surfaceView, &AndroidSurfaceView::surfaceCreated,
- this, &QAndroidCameraDataVideoOutput::onSurfaceCreated);
-
- m_surfaceView->setGeometry(-1, -1, 1, 1);
- m_surfaceView->setVisible(true);
-
- connect(m_control->cameraSession(), &QAndroidCameraSession::opened,
- this, &QAndroidCameraDataVideoOutput::configureFormat);
- connect(m_control->surface(), &QAbstractVideoSurface::supportedFormatsChanged,
- this, &QAndroidCameraDataVideoOutput::configureFormat);
- configureFormat();
-}
-
-QAndroidCameraDataVideoOutput::~QAndroidCameraDataVideoOutput()
-{
- m_control->cameraSession()->setPreviewCallback(nullptr);
- delete m_surfaceView;
-}
-
-AndroidSurfaceHolder *QAndroidCameraDataVideoOutput::surfaceHolder()
-{
- return m_surfaceView->holder();
-}
-
-bool QAndroidCameraDataVideoOutput::isReady()
-{
- return m_surfaceView->holder() && m_surfaceView->holder()->isSurfaceCreated();
-}
-
-void QAndroidCameraDataVideoOutput::onSurfaceCreated()
-{
- emit readyChanged(true);
-}
-
-void QAndroidCameraDataVideoOutput::configureFormat()
-{
- m_pixelFormat = QVideoFrame::Format_Invalid;
-
- if (!m_control->cameraSession()->camera())
- return;
-
- QList<QVideoFrame::PixelFormat> surfaceFormats = m_control->surface()->supportedPixelFormats();
- QList<AndroidCamera::ImageFormat> previewFormats = m_control->cameraSession()->camera()->getSupportedPreviewFormats();
- for (int i = 0; i < surfaceFormats.size(); ++i) {
- QVideoFrame::PixelFormat pixFormat = surfaceFormats.at(i);
- AndroidCamera::ImageFormat f = qt_androidImageFormatFromPixelFormat(pixFormat);
- if (previewFormats.contains(f)) {
- m_pixelFormat = pixFormat;
- break;
- }
- }
-
- if (m_pixelFormat == QVideoFrame::Format_Invalid) {
- m_control->cameraSession()->setPreviewCallback(nullptr);
- qWarning("The video surface is not compatible with any format supported by the camera");
- } else {
- m_control->cameraSession()->setPreviewCallback(this);
-
- if (m_control->cameraSession()->status() > QCamera::LoadedStatus)
- m_control->cameraSession()->camera()->stopPreview();
-
- m_control->cameraSession()->setPreviewFormat(qt_androidImageFormatFromPixelFormat(m_pixelFormat));
-
- if (m_control->cameraSession()->status() > QCamera::LoadedStatus)
- m_control->cameraSession()->camera()->startPreview();
- }
-}
-
-void QAndroidCameraDataVideoOutput::stop()
-{
- m_mutex.lock();
- m_lastFrame = QVideoFrame();
- m_mutex.unlock();
-
- if (m_control->surface() && m_control->surface()->isActive())
- m_control->surface()->stop();
-}
-
-void QAndroidCameraDataVideoOutput::onFrameAvailable(const QVideoFrame &frame)
-{
- m_mutex.lock();
- m_lastFrame = frame;
- m_mutex.unlock();
-
- if (thread() == QThread::currentThread())
- presentFrame();
- else
- QCoreApplication::postEvent(this, new QEvent(QEvent::User), Qt::HighEventPriority);
-}
-
-bool QAndroidCameraDataVideoOutput::event(QEvent *e)
-{
- if (e->type() == QEvent::User) {
- presentFrame();
- return true;
- }
-
- return QObject::event(e);
-}
-
-void QAndroidCameraDataVideoOutput::presentFrame()
-{
- Q_ASSERT(thread() == QThread::currentThread());
-
- QMutexLocker locker(&m_mutex);
-
- if (m_control->surface() && m_lastFrame.isValid() && m_lastFrame.pixelFormat() == m_pixelFormat) {
-
- if (m_control->surface()->isActive() && (m_control->surface()->surfaceFormat().pixelFormat() != m_lastFrame.pixelFormat()
- || m_control->surface()->surfaceFormat().frameSize() != m_lastFrame.size())) {
- m_control->surface()->stop();
- }
-
- if (!m_control->surface()->isActive()) {
- QVideoSurfaceFormat format(m_lastFrame.size(), m_lastFrame.pixelFormat(), m_lastFrame.handleType());
- // Front camera frames are automatically mirrored when using SurfaceTexture or SurfaceView,
- // but the buffers we get from the data callback are not. Tell the QAbstractVideoSurface
- // that it needs to mirror the frames.
- if (m_control->cameraSession()->camera()->getFacing() == AndroidCamera::CameraFacingFront)
- format.setProperty("mirrored", true);
-
- m_control->surface()->start(format);
- }
-
- if (m_control->surface()->isActive())
- m_control->surface()->present(m_lastFrame);
- }
-
- m_lastFrame = QVideoFrame();
-}
-
-
-QAndroidCameraVideoRendererControl::QAndroidCameraVideoRendererControl(QAndroidCameraSession *session, QObject *parent)
- : QVideoRendererControl(parent)
- , m_cameraSession(session)
- , m_surface(0)
- , m_textureOutput(0)
- , m_dataOutput(0)
-{
-}
-
-QAndroidCameraVideoRendererControl::~QAndroidCameraVideoRendererControl()
-{
- m_cameraSession->setVideoOutput(0);
-}
-
-QAbstractVideoSurface *QAndroidCameraVideoRendererControl::surface() const
-{
- return m_surface;
-}
-
-void QAndroidCameraVideoRendererControl::setSurface(QAbstractVideoSurface *surface)
-{
- if (m_surface == surface)
- return;
-
- m_surface = surface;
- QAndroidVideoOutput *oldOutput = m_textureOutput ? static_cast<QAndroidVideoOutput*>(m_textureOutput)
- : static_cast<QAndroidVideoOutput*>(m_dataOutput);
- QAndroidVideoOutput *newOutput = 0;
-
- if (m_surface) {
- if (!m_surface->supportedPixelFormats(QAbstractVideoBuffer::GLTextureHandle).isEmpty()) {
- if (!m_textureOutput) {
- m_dataOutput = 0;
- newOutput = m_textureOutput = new QAndroidTextureVideoOutput(this);
- }
- } else if (!m_dataOutput) {
- m_textureOutput = 0;
- newOutput = m_dataOutput = new QAndroidCameraDataVideoOutput(this);
- }
-
- if (m_textureOutput)
- m_textureOutput->setSurface(m_surface);
- }
-
- if (newOutput != oldOutput) {
- m_cameraSession->setVideoOutput(newOutput);
- delete oldOutput;
- }
-}
-
-QT_END_NAMESPACE
-
-#include "qandroidcameravideorenderercontrol.moc"
-
diff --git a/src/plugins/android/src/mediacapture/qandroidcameravideorenderercontrol.h b/src/plugins/android/src/mediacapture/qandroidcameravideorenderercontrol.h
deleted file mode 100644
index 538226239..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcameravideorenderercontrol.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERAVIDEORENDERERCONTROL_H
-#define QANDROIDCAMERAVIDEORENDERERCONTROL_H
-
-#include <qvideorenderercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-class QAndroidTextureVideoOutput;
-class QAndroidCameraDataVideoOutput;
-
-class QAndroidCameraVideoRendererControl : public QVideoRendererControl
-{
- Q_OBJECT
-public:
- QAndroidCameraVideoRendererControl(QAndroidCameraSession *session, QObject *parent = 0);
- ~QAndroidCameraVideoRendererControl() override;
-
- QAbstractVideoSurface *surface() const override;
- void setSurface(QAbstractVideoSurface *surface) override;
-
- QAndroidCameraSession *cameraSession() const { return m_cameraSession; }
-
-private:
- QAndroidCameraSession *m_cameraSession;
- QAbstractVideoSurface *m_surface;
- QAndroidTextureVideoOutput *m_textureOutput;
- QAndroidCameraDataVideoOutput *m_dataOutput;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERAVIDEORENDERERCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerazoomcontrol.cpp b/src/plugins/android/src/mediacapture/qandroidcamerazoomcontrol.cpp
deleted file mode 100644
index 6f94bdfe7..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcamerazoomcontrol.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcamerazoomcontrol.h"
-
-#include "qandroidcamerasession.h"
-#include "androidcamera.h"
-#include "qandroidmultimediautils.h"
-#include <qmath.h>
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCameraZoomControl::QAndroidCameraZoomControl(QAndroidCameraSession *session)
- : QCameraZoomControl()
- , m_cameraSession(session)
- , m_maximumZoom(1.0)
- , m_requestedZoom(1.0)
- , m_currentZoom(1.0)
-{
- connect(m_cameraSession, SIGNAL(opened()),
- this, SLOT(onCameraOpened()));
-}
-
-qreal QAndroidCameraZoomControl::maximumOpticalZoom() const
-{
- // Optical zoom not supported
- return 1.0;
-}
-
-qreal QAndroidCameraZoomControl::maximumDigitalZoom() const
-{
- return m_maximumZoom;
-}
-
-qreal QAndroidCameraZoomControl::requestedOpticalZoom() const
-{
- // Optical zoom not supported
- return 1.0;
-}
-
-qreal QAndroidCameraZoomControl::requestedDigitalZoom() const
-{
- return m_requestedZoom;
-}
-
-qreal QAndroidCameraZoomControl::currentOpticalZoom() const
-{
- // Optical zoom not supported
- return 1.0;
-}
-
-qreal QAndroidCameraZoomControl::currentDigitalZoom() const
-{
- return m_currentZoom;
-}
-
-void QAndroidCameraZoomControl::zoomTo(qreal optical, qreal digital)
-{
- Q_UNUSED(optical);
-
- if (!qFuzzyCompare(m_requestedZoom, digital)) {
- m_requestedZoom = digital;
- emit requestedDigitalZoomChanged(m_requestedZoom);
- }
-
- if (m_cameraSession->camera()) {
- digital = qBound(qreal(1), digital, m_maximumZoom);
- int validZoomIndex = qt_findClosestValue(m_zoomRatios, qRound(digital * 100));
- qreal newZoom = m_zoomRatios.at(validZoomIndex) / qreal(100);
- if (!qFuzzyCompare(m_currentZoom, newZoom)) {
- m_cameraSession->camera()->setZoom(validZoomIndex);
- m_currentZoom = newZoom;
- emit currentDigitalZoomChanged(m_currentZoom);
- }
- }
-}
-
-void QAndroidCameraZoomControl::onCameraOpened()
-{
- if (m_cameraSession->camera()->isZoomSupported()) {
- m_zoomRatios = m_cameraSession->camera()->getZoomRatios();
- qreal maxZoom = m_zoomRatios.last() / qreal(100);
- if (m_maximumZoom != maxZoom) {
- m_maximumZoom = maxZoom;
- emit maximumDigitalZoomChanged(m_maximumZoom);
- }
- zoomTo(1, m_requestedZoom);
- } else {
- m_zoomRatios.clear();
- if (!qFuzzyCompare(m_maximumZoom, qreal(1))) {
- m_maximumZoom = 1.0;
- emit maximumDigitalZoomChanged(m_maximumZoom);
- }
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerazoomcontrol.h b/src/plugins/android/src/mediacapture/qandroidcamerazoomcontrol.h
deleted file mode 100644
index 96fc4f77b..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcamerazoomcontrol.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAMERAZOOMCONTROL_H
-#define QANDROIDCAMERAZOOMCONTROL_H
-
-#include <qcamerazoomcontrol.h>
-#include <qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidCameraZoomControl : public QCameraZoomControl
-{
- Q_OBJECT
-public:
- explicit QAndroidCameraZoomControl(QAndroidCameraSession *session);
-
- qreal maximumOpticalZoom() const override;
- qreal maximumDigitalZoom() const override;
- qreal requestedOpticalZoom() const override;
- qreal requestedDigitalZoom() const override;
- qreal currentOpticalZoom() const override;
- qreal currentDigitalZoom() const override;
- void zoomTo(qreal optical, qreal digital) override;
-
-private Q_SLOTS:
- void onCameraOpened();
-
-private:
- QAndroidCameraSession *m_cameraSession;
-
- qreal m_maximumZoom;
- QList<int> m_zoomRatios;
- qreal m_requestedZoom;
- qreal m_currentZoom;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAMERAZOOMCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcaptureservice.cpp b/src/plugins/android/src/mediacapture/qandroidcaptureservice.cpp
deleted file mode 100644
index 65df54c3f..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcaptureservice.cpp
+++ /dev/null
@@ -1,249 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Ruslan Baratov
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcaptureservice.h"
-
-#include "qandroidmediarecordercontrol.h"
-#include "qandroidcapturesession.h"
-#include "qandroidcameracontrol.h"
-#include "qandroidcamerainfocontrol.h"
-#include "qandroidvideodeviceselectorcontrol.h"
-#include "qandroidaudioinputselectorcontrol.h"
-#include "qandroidcamerasession.h"
-#include "qandroidcameravideorenderercontrol.h"
-#include "qandroidcamerazoomcontrol.h"
-#include "qandroidcameraexposurecontrol.h"
-#include "qandroidcameraflashcontrol.h"
-#include "qandroidcamerafocuscontrol.h"
-#include "qandroidviewfindersettingscontrol.h"
-#include "qandroidcameralockscontrol.h"
-#include "qandroidcameraimageprocessingcontrol.h"
-#include "qandroidimageencodercontrol.h"
-#include "qandroidcameraimagecapturecontrol.h"
-#include "qandroidcameracapturedestinationcontrol.h"
-#include "qandroidcameracapturebufferformatcontrol.h"
-#include "qandroidaudioencodersettingscontrol.h"
-#include "qandroidvideoencodersettingscontrol.h"
-#include "qandroidmediacontainercontrol.h"
-#include "qandroidmediavideoprobecontrol.h"
-
-#include <qmediaserviceproviderplugin.h>
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCaptureService::QAndroidCaptureService(const QString &service, QObject *parent)
- : QMediaService(parent)
- , m_service(service)
- , m_videoRendererControl(0)
-{
- if (m_service == QLatin1String(Q_MEDIASERVICE_CAMERA)) {
- m_cameraSession = new QAndroidCameraSession;
- m_cameraControl = new QAndroidCameraControl(m_cameraSession);
- m_cameraInfoControl = new QAndroidCameraInfoControl;
- m_videoInputControl = new QAndroidVideoDeviceSelectorControl(m_cameraSession);
- m_cameraZoomControl = new QAndroidCameraZoomControl(m_cameraSession);
- m_cameraExposureControl = new QAndroidCameraExposureControl(m_cameraSession);
- m_cameraFlashControl = new QAndroidCameraFlashControl(m_cameraSession);
- m_cameraFocusControl = new QAndroidCameraFocusControl(m_cameraSession);
- m_viewfinderSettingsControl2 = new QAndroidViewfinderSettingsControl2(m_cameraSession);
- m_cameraLocksControl = new QAndroidCameraLocksControl(m_cameraSession);
- m_cameraImageProcessingControl = new QAndroidCameraImageProcessingControl(m_cameraSession);
- m_imageEncoderControl = new QAndroidImageEncoderControl(m_cameraSession);
- m_imageCaptureControl = new QAndroidCameraImageCaptureControl(m_cameraSession);
- m_captureDestinationControl = new QAndroidCameraCaptureDestinationControl(m_cameraSession);
- m_captureBufferFormatControl = new QAndroidCameraCaptureBufferFormatControl;
- m_audioInputControl = 0;
- } else {
- m_cameraSession = 0;
- m_cameraControl = 0;
- m_cameraInfoControl = 0;
- m_videoInputControl = 0;
- m_cameraZoomControl = 0;
- m_cameraExposureControl = 0;
- m_cameraFlashControl = 0;
- m_cameraFocusControl = 0;
- m_viewfinderSettingsControl2 = 0;
- m_cameraLocksControl = 0;
- m_cameraImageProcessingControl = 0;
- m_imageEncoderControl = 0;
- m_imageCaptureControl = 0;
- m_captureDestinationControl = 0;
- m_captureBufferFormatControl = 0;
- m_videoEncoderSettingsControl = 0;
- }
-
- m_captureSession = new QAndroidCaptureSession(m_cameraSession);
- m_recorderControl = new QAndroidMediaRecorderControl(m_captureSession);
- m_audioEncoderSettingsControl = new QAndroidAudioEncoderSettingsControl(m_captureSession);
- m_mediaContainerControl = new QAndroidMediaContainerControl(m_captureSession);
-
- if (m_service == QLatin1String(Q_MEDIASERVICE_CAMERA)) {
- m_videoEncoderSettingsControl = new QAndroidVideoEncoderSettingsControl(m_captureSession);
- } else {
- m_audioInputControl = new QAndroidAudioInputSelectorControl(m_captureSession);
- m_captureSession->setAudioInput(m_audioInputControl->defaultInput());
- }
-}
-
-QAndroidCaptureService::~QAndroidCaptureService()
-{
- delete m_audioEncoderSettingsControl;
- delete m_videoEncoderSettingsControl;
- delete m_mediaContainerControl;
- delete m_recorderControl;
- delete m_captureSession;
- delete m_cameraControl;
- delete m_cameraInfoControl;
- delete m_audioInputControl;
- delete m_videoInputControl;
- delete m_videoRendererControl;
- delete m_cameraZoomControl;
- delete m_cameraExposureControl;
- delete m_cameraFlashControl;
- delete m_cameraFocusControl;
- delete m_viewfinderSettingsControl2;
- delete m_cameraLocksControl;
- delete m_cameraImageProcessingControl;
- delete m_imageEncoderControl;
- delete m_imageCaptureControl;
- delete m_captureDestinationControl;
- delete m_captureBufferFormatControl;
- delete m_cameraSession;
-}
-
-QMediaControl *QAndroidCaptureService::requestControl(const char *name)
-{
- if (qstrcmp(name, QMediaRecorderControl_iid) == 0)
- return m_recorderControl;
-
- if (qstrcmp(name, QMediaContainerControl_iid) == 0)
- return m_mediaContainerControl;
-
- if (qstrcmp(name, QAudioEncoderSettingsControl_iid) == 0)
- return m_audioEncoderSettingsControl;
-
- if (qstrcmp(name, QVideoEncoderSettingsControl_iid) == 0)
- return m_videoEncoderSettingsControl;
-
- if (qstrcmp(name, QCameraControl_iid) == 0)
- return m_cameraControl;
-
- if (qstrcmp(name, QCameraInfoControl_iid) == 0)
- return m_cameraInfoControl;
-
- if (qstrcmp(name, QAudioInputSelectorControl_iid) == 0)
- return m_audioInputControl;
-
- if (qstrcmp(name, QVideoDeviceSelectorControl_iid) == 0)
- return m_videoInputControl;
-
- if (qstrcmp(name, QCameraZoomControl_iid) == 0)
- return m_cameraZoomControl;
-
- if (qstrcmp(name, QCameraExposureControl_iid) == 0)
- return m_cameraExposureControl;
-
- if (qstrcmp(name, QCameraFlashControl_iid) == 0)
- return m_cameraFlashControl;
-
- if (qstrcmp(name, QCameraFocusControl_iid) == 0)
- return m_cameraFocusControl;
-
- if (qstrcmp(name, QCameraViewfinderSettingsControl2_iid) == 0)
- return m_viewfinderSettingsControl2;
-
- if (qstrcmp(name, QCameraLocksControl_iid) == 0)
- return m_cameraLocksControl;
-
- if (qstrcmp(name, QCameraImageProcessingControl_iid) == 0)
- return m_cameraImageProcessingControl;
-
- if (qstrcmp(name, QImageEncoderControl_iid) == 0)
- return m_imageEncoderControl;
-
- if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0)
- return m_imageCaptureControl;
-
- if (qstrcmp(name, QCameraCaptureDestinationControl_iid) == 0)
- return m_captureDestinationControl;
-
- if (qstrcmp(name, QCameraCaptureBufferFormatControl_iid) == 0)
- return m_captureBufferFormatControl;
-
- if (qstrcmp(name, QVideoRendererControl_iid) == 0
- && m_service == QLatin1String(Q_MEDIASERVICE_CAMERA)
- && !m_videoRendererControl) {
- m_videoRendererControl = new QAndroidCameraVideoRendererControl(m_cameraSession);
- return m_videoRendererControl;
- }
-
- if (qstrcmp(name,QMediaVideoProbeControl_iid) == 0) {
- QAndroidMediaVideoProbeControl *videoProbe = 0;
- if (m_cameraSession) {
- videoProbe = new QAndroidMediaVideoProbeControl(this);
- m_cameraSession->addProbe(videoProbe);
- }
- return videoProbe;
- }
-
- return 0;
-}
-
-void QAndroidCaptureService::releaseControl(QMediaControl *control)
-{
- if (control) {
- if (control == m_videoRendererControl) {
- delete m_videoRendererControl;
- m_videoRendererControl = 0;
- return;
- }
-
- QAndroidMediaVideoProbeControl *videoProbe = qobject_cast<QAndroidMediaVideoProbeControl *>(control);
- if (videoProbe) {
- if (m_cameraSession)
- m_cameraSession->removeProbe(videoProbe);
- delete videoProbe;
- return;
- }
- }
-
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcaptureservice.h b/src/plugins/android/src/mediacapture/qandroidcaptureservice.h
deleted file mode 100644
index 85816fdd6..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcaptureservice.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Ruslan Baratov
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAPTURESERVICE_H
-#define QANDROIDCAPTURESERVICE_H
-
-#include <qmediaservice.h>
-#include <qmediacontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidMediaRecorderControl;
-class QAndroidCaptureSession;
-class QAndroidCameraControl;
-class QAndroidCameraInfoControl;
-class QAndroidVideoDeviceSelectorControl;
-class QAndroidAudioInputSelectorControl;
-class QAndroidCameraSession;
-class QAndroidCameraVideoRendererControl;
-class QAndroidCameraZoomControl;
-class QAndroidCameraExposureControl;
-class QAndroidCameraFlashControl;
-class QAndroidCameraFocusControl;
-class QAndroidViewfinderSettingsControl2;
-class QAndroidCameraLocksControl;
-class QAndroidCameraImageProcessingControl;
-class QAndroidImageEncoderControl;
-class QAndroidCameraImageCaptureControl;
-class QAndroidCameraCaptureDestinationControl;
-class QAndroidCameraCaptureBufferFormatControl;
-class QAndroidAudioEncoderSettingsControl;
-class QAndroidVideoEncoderSettingsControl;
-class QAndroidMediaContainerControl;
-
-class QAndroidCaptureService : public QMediaService
-{
- Q_OBJECT
-
-public:
- explicit QAndroidCaptureService(const QString &service, QObject *parent = 0);
- virtual ~QAndroidCaptureService();
-
- QMediaControl *requestControl(const char *name);
- void releaseControl(QMediaControl *);
-
-private:
- QString m_service;
-
- QAndroidMediaRecorderControl *m_recorderControl;
- QAndroidCaptureSession *m_captureSession;
- QAndroidCameraControl *m_cameraControl;
- QAndroidCameraInfoControl *m_cameraInfoControl;
- QAndroidVideoDeviceSelectorControl *m_videoInputControl;
- QAndroidAudioInputSelectorControl *m_audioInputControl;
- QAndroidCameraSession *m_cameraSession;
- QAndroidCameraVideoRendererControl *m_videoRendererControl;
- QAndroidCameraZoomControl *m_cameraZoomControl;
- QAndroidCameraExposureControl *m_cameraExposureControl;
- QAndroidCameraFlashControl *m_cameraFlashControl;
- QAndroidCameraFocusControl *m_cameraFocusControl;
- QAndroidViewfinderSettingsControl2 *m_viewfinderSettingsControl2;
- QAndroidCameraLocksControl *m_cameraLocksControl;
- QAndroidCameraImageProcessingControl *m_cameraImageProcessingControl;
- QAndroidImageEncoderControl *m_imageEncoderControl;
- QAndroidCameraImageCaptureControl *m_imageCaptureControl;
- QAndroidCameraCaptureDestinationControl *m_captureDestinationControl;
- QAndroidCameraCaptureBufferFormatControl *m_captureBufferFormatControl;
- QAndroidAudioEncoderSettingsControl *m_audioEncoderSettingsControl;
- QAndroidVideoEncoderSettingsControl *m_videoEncoderSettingsControl;
- QAndroidMediaContainerControl *m_mediaContainerControl;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAPTURESERVICE_H
diff --git a/src/plugins/android/src/mediacapture/qandroidcapturesession.cpp b/src/plugins/android/src/mediacapture/qandroidcapturesession.cpp
deleted file mode 100644
index 768bb4442..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcapturesession.cpp
+++ /dev/null
@@ -1,594 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcapturesession.h"
-
-#include "androidcamera.h"
-#include "qandroidcamerasession.h"
-#include "androidmultimediautils.h"
-#include "qandroidmultimediautils.h"
-#include "qandroidvideooutput.h"
-#include "qandroidglobal.h"
-
-#include <algorithm>
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCaptureSession::QAndroidCaptureSession(QAndroidCameraSession *cameraSession)
- : QObject()
- , m_mediaRecorder(0)
- , m_cameraSession(cameraSession)
- , m_audioSource(AndroidMediaRecorder::DefaultAudioSource)
- , m_duration(0)
- , m_state(QMediaRecorder::StoppedState)
- , m_status(QMediaRecorder::UnloadedStatus)
- , m_containerFormatDirty(true)
- , m_videoSettingsDirty(true)
- , m_audioSettingsDirty(true)
- , m_outputFormat(AndroidMediaRecorder::DefaultOutputFormat)
- , m_audioEncoder(AndroidMediaRecorder::DefaultAudioEncoder)
- , m_videoEncoder(AndroidMediaRecorder::DefaultVideoEncoder)
-{
- m_mediaStorageLocation.addStorageLocation(
- QMediaStorageLocation::Movies,
- AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::DCIM));
-
- m_mediaStorageLocation.addStorageLocation(
- QMediaStorageLocation::Sounds,
- AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::Sounds));
-
- if (cameraSession) {
- connect(cameraSession, SIGNAL(opened()), this, SLOT(onCameraOpened()));
- connect(cameraSession, &QAndroidCameraSession::statusChanged, this,
- [this](QCamera::Status status) {
- if (status == QCamera::UnavailableStatus) {
- setState(QMediaRecorder::StoppedState);
- setStatus(QMediaRecorder::UnavailableStatus);
- return;
- }
-
- // Stop recording when stopping the camera.
- if (status == QCamera::StoppingStatus) {
- setState(QMediaRecorder::StoppedState);
- setStatus(QMediaRecorder::UnloadedStatus);
- return;
- }
-
- if (status == QCamera::LoadingStatus)
- setStatus(QMediaRecorder::LoadingStatus);
- });
- connect(cameraSession, &QAndroidCameraSession::captureModeChanged, this,
- [this](QCamera::CaptureModes mode) {
- if (!mode.testFlag(QCamera::CaptureVideo)) {
- setState(QMediaRecorder::StoppedState);
- setStatus(QMediaRecorder::UnloadedStatus);
- }
- });
- connect(cameraSession, &QAndroidCameraSession::readyForCaptureChanged, this,
- [this](bool ready) {
- if (ready)
- setStatus(QMediaRecorder::LoadedStatus);
- });
- } else {
- // Audio-only recording.
- setStatus(QMediaRecorder::LoadedStatus);
- }
-
- m_notifyTimer.setInterval(1000);
- connect(&m_notifyTimer, SIGNAL(timeout()), this, SLOT(updateDuration()));
-}
-
-QAndroidCaptureSession::~QAndroidCaptureSession()
-{
- stop();
- delete m_mediaRecorder;
-}
-
-void QAndroidCaptureSession::setAudioInput(const QString &input)
-{
- if (m_audioInput == input)
- return;
-
- m_audioInput = input;
-
- if (m_audioInput == QLatin1String("default"))
- m_audioSource = AndroidMediaRecorder::DefaultAudioSource;
- else if (m_audioInput == QLatin1String("mic"))
- m_audioSource = AndroidMediaRecorder::Mic;
- else if (m_audioInput == QLatin1String("voice_uplink"))
- m_audioSource = AndroidMediaRecorder::VoiceUplink;
- else if (m_audioInput == QLatin1String("voice_downlink"))
- m_audioSource = AndroidMediaRecorder::VoiceDownlink;
- else if (m_audioInput == QLatin1String("voice_call"))
- m_audioSource = AndroidMediaRecorder::VoiceCall;
- else if (m_audioInput == QLatin1String("voice_recognition"))
- m_audioSource = AndroidMediaRecorder::VoiceRecognition;
- else
- m_audioSource = AndroidMediaRecorder::DefaultAudioSource;
-
- emit audioInputChanged(m_audioInput);
-}
-
-QUrl QAndroidCaptureSession::outputLocation() const
-{
- return m_actualOutputLocation;
-}
-
-bool QAndroidCaptureSession::setOutputLocation(const QUrl &location)
-{
- if (m_requestedOutputLocation == location)
- return false;
-
- m_actualOutputLocation = QUrl();
- m_requestedOutputLocation = location;
-
- if (m_requestedOutputLocation.isEmpty())
- return true;
-
- if (m_requestedOutputLocation.isValid()
- && (m_requestedOutputLocation.isLocalFile() || m_requestedOutputLocation.isRelative())) {
- return true;
- }
-
- m_requestedOutputLocation = QUrl();
- return false;
-}
-
-QMediaRecorder::State QAndroidCaptureSession::state() const
-{
- return m_state;
-}
-
-void QAndroidCaptureSession::setState(QMediaRecorder::State state)
-{
- if (m_state == state)
- return;
-
- switch (state) {
- case QMediaRecorder::StoppedState:
- stop();
- break;
- case QMediaRecorder::RecordingState:
- start();
- break;
- case QMediaRecorder::PausedState:
- // Not supported by Android API
- qWarning("QMediaRecorder::PausedState is not supported on Android");
- break;
- }
-}
-
-void QAndroidCaptureSession::start()
-{
- if (m_state == QMediaRecorder::RecordingState || m_status != QMediaRecorder::LoadedStatus)
- return;
-
- setStatus(QMediaRecorder::StartingStatus);
-
- if (m_mediaRecorder) {
- m_mediaRecorder->release();
- delete m_mediaRecorder;
- }
-
- const bool granted = m_cameraSession
- ? m_cameraSession->requestRecordingPermission()
- : qt_androidRequestRecordingPermission();
- if (!granted) {
- setStatus(QMediaRecorder::UnavailableStatus);
- Q_EMIT error(QMediaRecorder::ResourceError, QLatin1String("Permission denied."));
- return;
- }
-
- m_mediaRecorder = new AndroidMediaRecorder;
- connect(m_mediaRecorder, SIGNAL(error(int,int)), this, SLOT(onError(int,int)));
- connect(m_mediaRecorder, SIGNAL(info(int,int)), this, SLOT(onInfo(int,int)));
-
- // Set audio/video sources
- if (m_cameraSession) {
- updateViewfinder();
- m_cameraSession->camera()->unlock();
- m_mediaRecorder->setCamera(m_cameraSession->camera());
- m_mediaRecorder->setAudioSource(AndroidMediaRecorder::Camcorder);
- m_mediaRecorder->setVideoSource(AndroidMediaRecorder::Camera);
- } else {
- m_mediaRecorder->setAudioSource(m_audioSource);
- }
-
- // Set output format
- m_mediaRecorder->setOutputFormat(m_outputFormat);
-
- // Set audio encoder settings
- m_mediaRecorder->setAudioChannels(m_audioSettings.channelCount());
- m_mediaRecorder->setAudioEncodingBitRate(m_audioSettings.bitRate());
- m_mediaRecorder->setAudioSamplingRate(m_audioSettings.sampleRate());
- m_mediaRecorder->setAudioEncoder(m_audioEncoder);
-
- // Set video encoder settings
- if (m_cameraSession) {
- m_mediaRecorder->setVideoSize(m_videoSettings.resolution());
- m_mediaRecorder->setVideoFrameRate(qRound(m_videoSettings.frameRate()));
- m_mediaRecorder->setVideoEncodingBitRate(m_videoSettings.bitRate());
- m_mediaRecorder->setVideoEncoder(m_videoEncoder);
-
- m_mediaRecorder->setOrientationHint(m_cameraSession->currentCameraRotation());
- }
-
- // Set output file
- QString filePath = m_mediaStorageLocation.generateFileName(
- m_requestedOutputLocation.isLocalFile() ? m_requestedOutputLocation.toLocalFile()
- : m_requestedOutputLocation.toString(),
- m_cameraSession ? QMediaStorageLocation::Movies
- : QMediaStorageLocation::Sounds,
- m_cameraSession ? QLatin1String("VID_")
- : QLatin1String("REC_"),
- m_containerFormat);
-
- m_usedOutputLocation = QUrl::fromLocalFile(filePath);
- m_mediaRecorder->setOutputFile(filePath);
-
- // Even though the Android doc explicitly says that calling MediaRecorder.setPreviewDisplay()
- // is not necessary when the Camera already has a Surface, it doesn't actually work on some
- // devices. For example on the Samsung Galaxy Tab 2, the camera server dies after prepare()
- // and start() if MediaRecorder.setPreviewDispaly() is not called.
- if (m_cameraSession) {
- // When using a SurfaceTexture, we need to pass a new one to the MediaRecorder, not the same
- // one that is set on the Camera or it will crash, hence the reset().
- m_cameraSession->videoOutput()->reset();
- if (m_cameraSession->videoOutput()->surfaceTexture())
- m_mediaRecorder->setSurfaceTexture(m_cameraSession->videoOutput()->surfaceTexture());
- else if (m_cameraSession->videoOutput()->surfaceHolder())
- m_mediaRecorder->setSurfaceHolder(m_cameraSession->videoOutput()->surfaceHolder());
- }
-
- if (!m_mediaRecorder->prepare()) {
- emit error(QMediaRecorder::FormatError, QLatin1String("Unable to prepare the media recorder."));
- if (m_cameraSession)
- restartViewfinder();
- return;
- }
-
- if (!m_mediaRecorder->start()) {
- emit error(QMediaRecorder::FormatError, QLatin1String("Unable to start the media recorder."));
- if (m_cameraSession)
- restartViewfinder();
- return;
- }
-
- m_elapsedTime.start();
- m_notifyTimer.start();
- updateDuration();
-
- if (m_cameraSession) {
- m_cameraSession->setReadyForCapture(false);
-
- // Preview frame callback is cleared when setting up the camera with the media recorder.
- // We need to reset it.
- m_cameraSession->camera()->setupPreviewFrameCallback();
- }
-
- m_state = QMediaRecorder::RecordingState;
- emit stateChanged(m_state);
- setStatus(QMediaRecorder::RecordingStatus);
-}
-
-void QAndroidCaptureSession::stop(bool error)
-{
- if (m_state == QMediaRecorder::StoppedState || m_mediaRecorder == 0)
- return;
-
- setStatus(QMediaRecorder::FinalizingStatus);
-
- m_mediaRecorder->stop();
- m_notifyTimer.stop();
- updateDuration();
- m_elapsedTime.invalidate();
- m_mediaRecorder->release();
- delete m_mediaRecorder;
- m_mediaRecorder = 0;
-
- if (m_cameraSession && m_cameraSession->status() == QCamera::ActiveStatus) {
- // Viewport needs to be restarted after recording
- restartViewfinder();
- }
-
- if (!error) {
- // if the media is saved into the standard media location, register it
- // with the Android media scanner so it appears immediately in apps
- // such as the gallery.
- QString mediaPath = m_usedOutputLocation.toLocalFile();
- QString standardLoc = m_cameraSession ? AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::DCIM)
- : AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::Sounds);
- if (mediaPath.startsWith(standardLoc))
- AndroidMultimediaUtils::registerMediaFile(mediaPath);
-
- m_actualOutputLocation = m_usedOutputLocation;
- emit actualLocationChanged(m_actualOutputLocation);
- }
-
- m_state = QMediaRecorder::StoppedState;
- emit stateChanged(m_state);
- if (!m_cameraSession)
- setStatus(QMediaRecorder::LoadedStatus);
-}
-
-void QAndroidCaptureSession::setStatus(QMediaRecorder::Status status)
-{
- if (m_status == status)
- return;
-
- m_status = status;
- emit statusChanged(m_status);
-}
-
-QMediaRecorder::Status QAndroidCaptureSession::status() const
-{
- return m_status;
-}
-
-qint64 QAndroidCaptureSession::duration() const
-{
- return m_duration;
-}
-
-void QAndroidCaptureSession::setContainerFormat(const QString &format)
-{
- if (m_containerFormat == format)
- return;
-
- m_containerFormat = format;
- m_containerFormatDirty = true;
-}
-
-void QAndroidCaptureSession::setAudioSettings(const QAudioEncoderSettings &settings)
-{
- if (m_audioSettings == settings)
- return;
-
- m_audioSettings = settings;
- m_audioSettingsDirty = true;
-}
-
-void QAndroidCaptureSession::setVideoSettings(const QVideoEncoderSettings &settings)
-{
- if (!m_cameraSession || m_videoSettings == settings)
- return;
-
- m_videoSettings = settings;
- m_videoSettingsDirty = true;
-}
-
-void QAndroidCaptureSession::applySettings()
-{
- // container settings
- if (m_containerFormatDirty) {
- if (m_containerFormat.isEmpty()) {
- m_containerFormat = m_defaultSettings.outputFileExtension;
- m_outputFormat = m_defaultSettings.outputFormat;
- } else if (m_containerFormat == QLatin1String("3gp")) {
- m_outputFormat = AndroidMediaRecorder::THREE_GPP;
- } else if (!m_cameraSession && m_containerFormat == QLatin1String("amr")) {
- m_outputFormat = AndroidMediaRecorder::AMR_NB_Format;
- } else if (!m_cameraSession && m_containerFormat == QLatin1String("awb")) {
- m_outputFormat = AndroidMediaRecorder::AMR_WB_Format;
- } else {
- m_containerFormat = QStringLiteral("mp4");
- m_outputFormat = AndroidMediaRecorder::MPEG_4;
- }
-
- m_containerFormatDirty = false;
- }
-
- // audio settings
- if (m_audioSettingsDirty) {
- if (m_audioSettings.channelCount() <= 0)
- m_audioSettings.setChannelCount(m_defaultSettings.audioChannels);
- if (m_audioSettings.bitRate() <= 0)
- m_audioSettings.setBitRate(m_defaultSettings.audioBitRate);
- if (m_audioSettings.sampleRate() <= 0)
- m_audioSettings.setSampleRate(m_defaultSettings.audioSampleRate);
-
- if (m_audioSettings.codec().isEmpty())
- m_audioEncoder = m_defaultSettings.audioEncoder;
- else if (m_audioSettings.codec() == QLatin1String("aac"))
- m_audioEncoder = AndroidMediaRecorder::AAC;
- else if (m_audioSettings.codec() == QLatin1String("amr-nb"))
- m_audioEncoder = AndroidMediaRecorder::AMR_NB_Encoder;
- else if (m_audioSettings.codec() == QLatin1String("amr-wb"))
- m_audioEncoder = AndroidMediaRecorder::AMR_WB_Encoder;
- else
- m_audioEncoder = m_defaultSettings.audioEncoder;
-
- m_audioSettingsDirty = false;
- }
-
- // video settings
- if (m_cameraSession && m_cameraSession->camera() && m_videoSettingsDirty) {
- if (m_videoSettings.resolution().isEmpty()) {
- m_videoSettings.setResolution(m_defaultSettings.videoResolution);
- } else if (!m_supportedResolutions.contains(m_videoSettings.resolution())) {
- // if the requested resolution is not supported, find the closest one
- QSize reqSize = m_videoSettings.resolution();
- int reqPixelCount = reqSize.width() * reqSize.height();
- QList<int> supportedPixelCounts;
- for (int i = 0; i < m_supportedResolutions.size(); ++i) {
- const QSize &s = m_supportedResolutions.at(i);
- supportedPixelCounts.append(s.width() * s.height());
- }
- int closestIndex = qt_findClosestValue(supportedPixelCounts, reqPixelCount);
- m_videoSettings.setResolution(m_supportedResolutions.at(closestIndex));
- }
-
- if (m_videoSettings.frameRate() <= 0)
- m_videoSettings.setFrameRate(m_defaultSettings.videoFrameRate);
- if (m_videoSettings.bitRate() <= 0)
- m_videoSettings.setBitRate(m_defaultSettings.videoBitRate);
-
- if (m_videoSettings.codec().isEmpty())
- m_videoEncoder = m_defaultSettings.videoEncoder;
- else if (m_videoSettings.codec() == QLatin1String("h263"))
- m_videoEncoder = AndroidMediaRecorder::H263;
- else if (m_videoSettings.codec() == QLatin1String("h264"))
- m_videoEncoder = AndroidMediaRecorder::H264;
- else if (m_videoSettings.codec() == QLatin1String("mpeg4_sp"))
- m_videoEncoder = AndroidMediaRecorder::MPEG_4_SP;
- else
- m_videoEncoder = m_defaultSettings.videoEncoder;
-
- m_videoSettingsDirty = false;
- }
-}
-
-void QAndroidCaptureSession::updateViewfinder()
-{
- m_cameraSession->camera()->stopPreviewSynchronous();
- m_cameraSession->applyViewfinderSettings(m_videoSettings.resolution(), false);
-}
-
-void QAndroidCaptureSession::restartViewfinder()
-{
- if (!m_cameraSession)
- return;
-
- m_cameraSession->camera()->reconnect();
-
- // This is not necessary on most devices, but it crashes on some if we don't stop the
- // preview and reset the preview display on the camera when recording is over.
- m_cameraSession->camera()->stopPreviewSynchronous();
- m_cameraSession->videoOutput()->reset();
- if (m_cameraSession->videoOutput()->surfaceTexture())
- m_cameraSession->camera()->setPreviewTexture(m_cameraSession->videoOutput()->surfaceTexture());
- else if (m_cameraSession->videoOutput()->surfaceHolder())
- m_cameraSession->camera()->setPreviewDisplay(m_cameraSession->videoOutput()->surfaceHolder());
-
- m_cameraSession->camera()->startPreview();
- m_cameraSession->setReadyForCapture(true);
-}
-
-void QAndroidCaptureSession::updateDuration()
-{
- if (m_elapsedTime.isValid())
- m_duration = m_elapsedTime.elapsed();
-
- emit durationChanged(m_duration);
-}
-
-void QAndroidCaptureSession::onCameraOpened()
-{
- m_supportedResolutions.clear();
- m_supportedFramerates.clear();
-
- // get supported resolutions from predefined profiles
- for (int i = 0; i < 8; ++i) {
- CaptureProfile profile = getProfile(i);
- if (!profile.isNull) {
- if (i == AndroidCamcorderProfile::QUALITY_HIGH)
- m_defaultSettings = profile;
-
- if (!m_supportedResolutions.contains(profile.videoResolution))
- m_supportedResolutions.append(profile.videoResolution);
- if (!m_supportedFramerates.contains(profile.videoFrameRate))
- m_supportedFramerates.append(profile.videoFrameRate);
- }
- }
-
- std::sort(m_supportedResolutions.begin(), m_supportedResolutions.end(), qt_sizeLessThan);
- std::sort(m_supportedFramerates.begin(), m_supportedFramerates.end());
-
- applySettings();
-}
-
-QAndroidCaptureSession::CaptureProfile QAndroidCaptureSession::getProfile(int id)
-{
- CaptureProfile profile;
- const bool hasProfile = AndroidCamcorderProfile::hasProfile(m_cameraSession->camera()->cameraId(),
- AndroidCamcorderProfile::Quality(id));
-
- if (hasProfile) {
- AndroidCamcorderProfile camProfile = AndroidCamcorderProfile::get(m_cameraSession->camera()->cameraId(),
- AndroidCamcorderProfile::Quality(id));
-
- profile.outputFormat = AndroidMediaRecorder::OutputFormat(camProfile.getValue(AndroidCamcorderProfile::fileFormat));
- profile.audioEncoder = AndroidMediaRecorder::AudioEncoder(camProfile.getValue(AndroidCamcorderProfile::audioCodec));
- profile.audioBitRate = camProfile.getValue(AndroidCamcorderProfile::audioBitRate);
- profile.audioChannels = camProfile.getValue(AndroidCamcorderProfile::audioChannels);
- profile.audioSampleRate = camProfile.getValue(AndroidCamcorderProfile::audioSampleRate);
- profile.videoEncoder = AndroidMediaRecorder::VideoEncoder(camProfile.getValue(AndroidCamcorderProfile::videoCodec));
- profile.videoBitRate = camProfile.getValue(AndroidCamcorderProfile::videoBitRate);
- profile.videoFrameRate = camProfile.getValue(AndroidCamcorderProfile::videoFrameRate);
- profile.videoResolution = QSize(camProfile.getValue(AndroidCamcorderProfile::videoFrameWidth),
- camProfile.getValue(AndroidCamcorderProfile::videoFrameHeight));
-
- if (profile.outputFormat == AndroidMediaRecorder::MPEG_4)
- profile.outputFileExtension = QStringLiteral("mp4");
- else if (profile.outputFormat == AndroidMediaRecorder::THREE_GPP)
- profile.outputFileExtension = QStringLiteral("3gp");
- else if (profile.outputFormat == AndroidMediaRecorder::AMR_NB_Format)
- profile.outputFileExtension = QStringLiteral("amr");
- else if (profile.outputFormat == AndroidMediaRecorder::AMR_WB_Format)
- profile.outputFileExtension = QStringLiteral("awb");
-
- profile.isNull = false;
- }
-
- return profile;
-}
-
-void QAndroidCaptureSession::onError(int what, int extra)
-{
- Q_UNUSED(what);
- Q_UNUSED(extra);
- stop(true);
- emit error(QMediaRecorder::ResourceError, QLatin1String("Unknown error."));
-}
-
-void QAndroidCaptureSession::onInfo(int what, int extra)
-{
- Q_UNUSED(extra);
- if (what == 800) {
- // MEDIA_RECORDER_INFO_MAX_DURATION_REACHED
- setState(QMediaRecorder::StoppedState);
- emit error(QMediaRecorder::OutOfSpaceError, QLatin1String("Maximum duration reached."));
- } else if (what == 801) {
- // MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED
- setState(QMediaRecorder::StoppedState);
- emit error(QMediaRecorder::OutOfSpaceError, QLatin1String("Maximum file size reached."));
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidcapturesession.h b/src/plugins/android/src/mediacapture/qandroidcapturesession.h
deleted file mode 100644
index 8cfb9ad2a..000000000
--- a/src/plugins/android/src/mediacapture/qandroidcapturesession.h
+++ /dev/null
@@ -1,182 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCAPTURESESSION_H
-#define QANDROIDCAPTURESESSION_H
-
-#include <qobject.h>
-#include <qmediarecorder.h>
-#include <qurl.h>
-#include <qelapsedtimer.h>
-#include <qtimer.h>
-#include <private/qmediastoragelocation_p.h>
-#include "androidmediarecorder.h"
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidCaptureSession : public QObject
-{
- Q_OBJECT
-public:
- explicit QAndroidCaptureSession(QAndroidCameraSession *cameraSession = 0);
- ~QAndroidCaptureSession();
-
- QList<QSize> supportedResolutions() const { return m_supportedResolutions; }
- QList<qreal> supportedFrameRates() const { return m_supportedFramerates; }
-
- QString audioInput() const { return m_audioInput; }
- void setAudioInput(const QString &input);
-
- QUrl outputLocation() const;
- bool setOutputLocation(const QUrl &location);
-
- QMediaRecorder::State state() const;
- void setState(QMediaRecorder::State state);
-
- QMediaRecorder::Status status() const;
-
- qint64 duration() const;
-
- QString containerFormat() const { return m_containerFormat; }
- void setContainerFormat(const QString &format);
-
- QAudioEncoderSettings audioSettings() const { return m_audioSettings; }
- void setAudioSettings(const QAudioEncoderSettings &settings);
-
- QVideoEncoderSettings videoSettings() const { return m_videoSettings; }
- void setVideoSettings(const QVideoEncoderSettings &settings);
-
- void applySettings();
-
-Q_SIGNALS:
- void audioInputChanged(const QString& name);
- void stateChanged(QMediaRecorder::State state);
- void statusChanged(QMediaRecorder::Status status);
- void durationChanged(qint64 position);
- void actualLocationChanged(const QUrl &location);
- void error(int error, const QString &errorString);
-
-private Q_SLOTS:
- void updateDuration();
- void onCameraOpened();
-
- void onError(int what, int extra);
- void onInfo(int what, int extra);
-
-private:
- struct CaptureProfile {
- AndroidMediaRecorder::OutputFormat outputFormat;
- QString outputFileExtension;
-
- AndroidMediaRecorder::AudioEncoder audioEncoder;
- int audioBitRate;
- int audioChannels;
- int audioSampleRate;
-
- AndroidMediaRecorder::VideoEncoder videoEncoder;
- int videoBitRate;
- int videoFrameRate;
- QSize videoResolution;
-
- bool isNull;
-
- CaptureProfile()
- : outputFormat(AndroidMediaRecorder::MPEG_4)
- , outputFileExtension(QLatin1String("mp4"))
- , audioEncoder(AndroidMediaRecorder::DefaultAudioEncoder)
- , audioBitRate(128000)
- , audioChannels(2)
- , audioSampleRate(44100)
- , videoEncoder(AndroidMediaRecorder::DefaultVideoEncoder)
- , videoBitRate(1)
- , videoFrameRate(-1)
- , videoResolution(320, 240)
- , isNull(true)
- { }
- };
-
- CaptureProfile getProfile(int id);
-
- void start();
- void stop(bool error = false);
-
- void setStatus(QMediaRecorder::Status status);
-
- void updateViewfinder();
- void restartViewfinder();
-
- AndroidMediaRecorder *m_mediaRecorder;
- QAndroidCameraSession *m_cameraSession;
-
- QString m_audioInput;
- AndroidMediaRecorder::AudioSource m_audioSource;
-
- QMediaStorageLocation m_mediaStorageLocation;
-
- QElapsedTimer m_elapsedTime;
- QTimer m_notifyTimer;
- qint64 m_duration;
-
- QMediaRecorder::State m_state;
- QMediaRecorder::Status m_status;
- QUrl m_requestedOutputLocation;
- QUrl m_usedOutputLocation;
- QUrl m_actualOutputLocation;
-
- CaptureProfile m_defaultSettings;
-
- QString m_containerFormat;
- QAudioEncoderSettings m_audioSettings;
- QVideoEncoderSettings m_videoSettings;
- bool m_containerFormatDirty;
- bool m_videoSettingsDirty;
- bool m_audioSettingsDirty;
- AndroidMediaRecorder::OutputFormat m_outputFormat;
- AndroidMediaRecorder::AudioEncoder m_audioEncoder;
- AndroidMediaRecorder::VideoEncoder m_videoEncoder;
-
- QList<QSize> m_supportedResolutions;
- QList<qreal> m_supportedFramerates;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCAPTURESESSION_H
diff --git a/src/plugins/android/src/mediacapture/qandroidimageencodercontrol.cpp b/src/plugins/android/src/mediacapture/qandroidimageencodercontrol.cpp
deleted file mode 100644
index 666f553e5..000000000
--- a/src/plugins/android/src/mediacapture/qandroidimageencodercontrol.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidimageencodercontrol.h"
-
-#include "qandroidcamerasession.h"
-#include "androidcamera.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidImageEncoderControl::QAndroidImageEncoderControl(QAndroidCameraSession *session)
- : QImageEncoderControl()
- , m_session(session)
-{
- connect(m_session, SIGNAL(opened()),
- this, SLOT(onCameraOpened()));
-}
-
-QStringList QAndroidImageEncoderControl::supportedImageCodecs() const
-{
- return QStringList() << QLatin1String("jpeg");
-}
-
-QString QAndroidImageEncoderControl::imageCodecDescription(const QString &codecName) const
-{
- if (codecName == QLatin1String("jpeg"))
- return tr("JPEG image");
-
- return QString();
-}
-
-QList<QSize> QAndroidImageEncoderControl::supportedResolutions(const QImageEncoderSettings &settings, bool *continuous) const
-{
- Q_UNUSED(settings);
-
- if (continuous)
- *continuous = false;
-
- return m_supportedResolutions;
-}
-
-QImageEncoderSettings QAndroidImageEncoderControl::imageSettings() const
-{
- return m_session->imageSettings();
-}
-
-void QAndroidImageEncoderControl::setImageSettings(const QImageEncoderSettings &settings)
-{
- m_session->setImageSettings(settings);
-}
-
-void QAndroidImageEncoderControl::onCameraOpened()
-{
- m_supportedResolutions = m_session->camera()->getSupportedPictureSizes();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidimageencodercontrol.h b/src/plugins/android/src/mediacapture/qandroidimageencodercontrol.h
deleted file mode 100644
index 52f602e78..000000000
--- a/src/plugins/android/src/mediacapture/qandroidimageencodercontrol.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDIMAGEENCODERCONTROL_H
-#define QANDROIDIMAGEENCODERCONTROL_H
-
-#include <qimageencodercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidImageEncoderControl : public QImageEncoderControl
-{
- Q_OBJECT
-public:
- explicit QAndroidImageEncoderControl(QAndroidCameraSession *session);
-
- QStringList supportedImageCodecs() const override;
- QString imageCodecDescription(const QString &codecName) const override;
- QList<QSize> supportedResolutions(const QImageEncoderSettings &settings, bool *continuous = 0) const override;
- QImageEncoderSettings imageSettings() const override;
- void setImageSettings(const QImageEncoderSettings &settings) override;
-
-private Q_SLOTS:
- void onCameraOpened();
-
-private:
- QAndroidCameraSession *m_session;
-
- QList<QSize> m_supportedResolutions;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDIMAGEENCODERCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidmediacontainercontrol.cpp b/src/plugins/android/src/mediacapture/qandroidmediacontainercontrol.cpp
deleted file mode 100644
index bda711367..000000000
--- a/src/plugins/android/src/mediacapture/qandroidmediacontainercontrol.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidmediacontainercontrol.h"
-
-#include "qandroidcapturesession.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidMediaContainerControl::QAndroidMediaContainerControl(QAndroidCaptureSession *session)
- : QMediaContainerControl()
- , m_session(session)
-{
-}
-
-QStringList QAndroidMediaContainerControl::supportedContainers() const
-{
- return QStringList() << QLatin1String("mp4")
- << QLatin1String("3gp")
- << QLatin1String("amr")
- << QLatin1String("awb");
-}
-
-QString QAndroidMediaContainerControl::containerFormat() const
-{
- return m_session->containerFormat();
-}
-
-void QAndroidMediaContainerControl::setContainerFormat(const QString &format)
-{
- m_session->setContainerFormat(format);
-}
-
-QString QAndroidMediaContainerControl::containerDescription(const QString &formatMimeType) const
-{
- if (formatMimeType == QLatin1String("mp4"))
- return tr("MPEG4 media file format");
- else if (formatMimeType == QLatin1String("3gp"))
- return tr("3GPP media file format");
- else if (formatMimeType == QLatin1String("amr"))
- return tr("AMR NB file format");
- else if (formatMimeType == QLatin1String("awb"))
- return tr("AMR WB file format");
-
- return QString();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidmediacontainercontrol.h b/src/plugins/android/src/mediacapture/qandroidmediacontainercontrol.h
deleted file mode 100644
index 1d90fb6cd..000000000
--- a/src/plugins/android/src/mediacapture/qandroidmediacontainercontrol.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDMEDIACONTAINERCONTROL_H
-#define QANDROIDMEDIACONTAINERCONTROL_H
-
-#include <qmediacontainercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCaptureSession;
-
-class QAndroidMediaContainerControl : public QMediaContainerControl
-{
- Q_OBJECT
-public:
- QAndroidMediaContainerControl(QAndroidCaptureSession *session);
-
- QStringList supportedContainers() const override;
- QString containerFormat() const override;
- void setContainerFormat(const QString &format) override;
- QString containerDescription(const QString &formatMimeType) const override;
-
-private:
- QAndroidCaptureSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDMEDIACONTAINERCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidmediarecordercontrol.cpp b/src/plugins/android/src/mediacapture/qandroidmediarecordercontrol.cpp
deleted file mode 100644
index fa68409d3..000000000
--- a/src/plugins/android/src/mediacapture/qandroidmediarecordercontrol.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidmediarecordercontrol.h"
-
-#include "qandroidcapturesession.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidMediaRecorderControl::QAndroidMediaRecorderControl(QAndroidCaptureSession *session)
- : QMediaRecorderControl()
- , m_session(session)
-{
- connect(m_session, SIGNAL(stateChanged(QMediaRecorder::State)), this, SIGNAL(stateChanged(QMediaRecorder::State)));
- connect(m_session, SIGNAL(statusChanged(QMediaRecorder::Status)), this, SIGNAL(statusChanged(QMediaRecorder::Status)));
- connect(m_session, SIGNAL(durationChanged(qint64)), this, SIGNAL(durationChanged(qint64)));
- connect(m_session, SIGNAL(actualLocationChanged(QUrl)), this, SIGNAL(actualLocationChanged(QUrl)));
- connect(m_session, SIGNAL(error(int,QString)), this, SIGNAL(error(int,QString)));
-}
-
-QUrl QAndroidMediaRecorderControl::outputLocation() const
-{
- return m_session->outputLocation();
-}
-
-bool QAndroidMediaRecorderControl::setOutputLocation(const QUrl &location)
-{
- return m_session->setOutputLocation(location);
-}
-
-QMediaRecorder::State QAndroidMediaRecorderControl::state() const
-{
- return m_session->state();
-}
-
-QMediaRecorder::Status QAndroidMediaRecorderControl::status() const
-{
- return m_session->status();
-}
-
-qint64 QAndroidMediaRecorderControl::duration() const
-{
- return m_session->duration();
-}
-
-bool QAndroidMediaRecorderControl::isMuted() const
-{
- // No API for this in Android
- return false;
-}
-
-qreal QAndroidMediaRecorderControl::volume() const
-{
- // No API for this in Android
- return 1.0;
-}
-
-void QAndroidMediaRecorderControl::applySettings()
-{
- m_session->applySettings();
-}
-
-void QAndroidMediaRecorderControl::setState(QMediaRecorder::State state)
-{
- m_session->setState(state);
-}
-
-void QAndroidMediaRecorderControl::setMuted(bool muted)
-{
- // No API for this in Android
- Q_UNUSED(muted);
- qWarning("QMediaRecorder::setMuted() is not supported on Android.");
-}
-
-void QAndroidMediaRecorderControl::setVolume(qreal volume)
-{
- // No API for this in Android
- Q_UNUSED(volume);
- qWarning("QMediaRecorder::setVolume() is not supported on Android.");
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidmediarecordercontrol.h b/src/plugins/android/src/mediacapture/qandroidmediarecordercontrol.h
deleted file mode 100644
index 6da59a50d..000000000
--- a/src/plugins/android/src/mediacapture/qandroidmediarecordercontrol.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDMEDIARECORDERCONTROL_H
-#define QANDROIDMEDIARECORDERCONTROL_H
-
-#include <qmediarecordercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCaptureSession;
-
-class QAndroidMediaRecorderControl : public QMediaRecorderControl
-{
- Q_OBJECT
-public:
- explicit QAndroidMediaRecorderControl(QAndroidCaptureSession *session);
-
- QUrl outputLocation() const override;
- bool setOutputLocation(const QUrl &location) override;
- QMediaRecorder::State state() const override;
- QMediaRecorder::Status status() const override;
- qint64 duration() const override;
- bool isMuted() const override;
- qreal volume() const override;
- void applySettings() override;
-
-public Q_SLOTS:
- void setState(QMediaRecorder::State state) override;
- void setMuted(bool muted) override;
- void setVolume(qreal volume) override;
-
-private:
- QAndroidCaptureSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDMEDIARECORDERCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidmediavideoprobecontrol.cpp b/src/plugins/android/src/mediacapture/qandroidmediavideoprobecontrol.cpp
deleted file mode 100644
index 1995ebf6a..000000000
--- a/src/plugins/android/src/mediacapture/qandroidmediavideoprobecontrol.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Integrated Computer Solutions, Inc
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidmediavideoprobecontrol.h"
-#include <qvideoframe.h>
-
-QT_BEGIN_NAMESPACE
-
-QAndroidMediaVideoProbeControl::QAndroidMediaVideoProbeControl(QObject *parent) :
- QMediaVideoProbeControl(parent)
-{
-}
-
-QAndroidMediaVideoProbeControl::~QAndroidMediaVideoProbeControl()
-{
-
-}
-
-void QAndroidMediaVideoProbeControl::newFrameProbed(const QVideoFrame &frame)
-{
- emit videoFrameProbed(frame);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidmediavideoprobecontrol.h b/src/plugins/android/src/mediacapture/qandroidmediavideoprobecontrol.h
deleted file mode 100644
index 3306ad224..000000000
--- a/src/plugins/android/src/mediacapture/qandroidmediavideoprobecontrol.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Integrated Computer Solutions, Inc
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDMEDIAVIDEOPROBECONTROL_H
-#define QANDROIDMEDIAVIDEOPROBECONTROL_H
-
-#include <qmediavideoprobecontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidMediaVideoProbeControl : public QMediaVideoProbeControl
-{
- Q_OBJECT
-public:
- explicit QAndroidMediaVideoProbeControl(QObject *parent = 0);
- virtual ~QAndroidMediaVideoProbeControl();
-
- void newFrameProbed(const QVideoFrame& frame);
-
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDMEDIAVIDEOPROBECONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.cpp b/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.cpp
deleted file mode 100644
index 65005c796..000000000
--- a/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidvideodeviceselectorcontrol.h"
-
-#include "qandroidcamerasession.h"
-#include "androidcamera.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidVideoDeviceSelectorControl::QAndroidVideoDeviceSelectorControl(QAndroidCameraSession *session)
- : QVideoDeviceSelectorControl(0)
- , m_selectedDevice(0)
- , m_cameraSession(session)
-{
-}
-
-QAndroidVideoDeviceSelectorControl::~QAndroidVideoDeviceSelectorControl()
-{
-}
-
-int QAndroidVideoDeviceSelectorControl::deviceCount() const
-{
- return QAndroidCameraSession::availableCameras().count();
-}
-
-QString QAndroidVideoDeviceSelectorControl::deviceName(int index) const
-{
- if (index < 0 || index >= QAndroidCameraSession::availableCameras().count())
- return QString();
-
- return QString::fromLatin1(QAndroidCameraSession::availableCameras().at(index).name);
-}
-
-QString QAndroidVideoDeviceSelectorControl::deviceDescription(int index) const
-{
- if (index < 0 || index >= QAndroidCameraSession::availableCameras().count())
- return QString();
-
- return QAndroidCameraSession::availableCameras().at(index).description;
-}
-
-int QAndroidVideoDeviceSelectorControl::defaultDevice() const
-{
- return 0;
-}
-
-int QAndroidVideoDeviceSelectorControl::selectedDevice() const
-{
- return m_selectedDevice;
-}
-
-void QAndroidVideoDeviceSelectorControl::setSelectedDevice(int index)
-{
- if (index != m_selectedDevice) {
- m_selectedDevice = index;
- m_cameraSession->setSelectedCamera(m_selectedDevice);
- emit selectedDeviceChanged(index);
- emit selectedDeviceChanged(deviceName(index));
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.h b/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.h
deleted file mode 100644
index b6cc30b2d..000000000
--- a/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDVIDEODEVICESELECTORCONTROL_H
-#define QANDROIDVIDEODEVICESELECTORCONTROL_H
-
-#include <qvideodeviceselectorcontrol.h>
-#include <QtCore/qstringlist.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidVideoDeviceSelectorControl : public QVideoDeviceSelectorControl
-{
- Q_OBJECT
-public:
- explicit QAndroidVideoDeviceSelectorControl(QAndroidCameraSession *session);
- ~QAndroidVideoDeviceSelectorControl();
-
- int deviceCount() const;
-
- QString deviceName(int index) const;
- QString deviceDescription(int index) const;
-
- int defaultDevice() const;
- int selectedDevice() const;
- void setSelectedDevice(int index);
-
-private:
- int m_selectedDevice;
-
- QAndroidCameraSession *m_cameraSession;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDVIDEODEVICESELECTORCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidvideoencodersettingscontrol.cpp b/src/plugins/android/src/mediacapture/qandroidvideoencodersettingscontrol.cpp
deleted file mode 100644
index 3d67e8cfa..000000000
--- a/src/plugins/android/src/mediacapture/qandroidvideoencodersettingscontrol.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidvideoencodersettingscontrol.h"
-
-#include "qandroidcapturesession.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidVideoEncoderSettingsControl::QAndroidVideoEncoderSettingsControl(QAndroidCaptureSession *session)
- : QVideoEncoderSettingsControl()
- , m_session(session)
-{
-}
-
-QList<QSize> QAndroidVideoEncoderSettingsControl::supportedResolutions(const QVideoEncoderSettings &, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- return m_session->supportedResolutions();
-}
-
-QList<qreal> QAndroidVideoEncoderSettingsControl::supportedFrameRates(const QVideoEncoderSettings &, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- return m_session->supportedFrameRates();
-}
-
-QStringList QAndroidVideoEncoderSettingsControl::supportedVideoCodecs() const
-{
- return QStringList() << QLatin1String("h263")
- << QLatin1String("h264")
- << QLatin1String("mpeg4_sp");
-}
-
-QString QAndroidVideoEncoderSettingsControl::videoCodecDescription(const QString &codecName) const
-{
- if (codecName == QLatin1String("h263"))
- return tr("H.263 compression");
- else if (codecName == QLatin1String("h264"))
- return tr("H.264 compression");
- else if (codecName == QLatin1String("mpeg4_sp"))
- return tr("MPEG-4 SP compression");
-
- return QString();
-}
-
-QVideoEncoderSettings QAndroidVideoEncoderSettingsControl::videoSettings() const
-{
- return m_session->videoSettings();
-}
-
-void QAndroidVideoEncoderSettingsControl::setVideoSettings(const QVideoEncoderSettings &settings)
-{
- m_session->setVideoSettings(settings);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediacapture/qandroidvideoencodersettingscontrol.h b/src/plugins/android/src/mediacapture/qandroidvideoencodersettingscontrol.h
deleted file mode 100644
index 146b44ac4..000000000
--- a/src/plugins/android/src/mediacapture/qandroidvideoencodersettingscontrol.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDVIDEOENCODERSETTINGSCONTROL_H
-#define QANDROIDVIDEOENCODERSETTINGSCONTROL_H
-
-#include <qvideoencodersettingscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCaptureSession;
-
-class QAndroidVideoEncoderSettingsControl : public QVideoEncoderSettingsControl
-{
- Q_OBJECT
-public:
- explicit QAndroidVideoEncoderSettingsControl(QAndroidCaptureSession *session);
-
- QList<QSize> supportedResolutions(const QVideoEncoderSettings &settings, bool *continuous = 0) const override;
- QList<qreal> supportedFrameRates(const QVideoEncoderSettings &settings, bool *continuous = 0) const override;
- QStringList supportedVideoCodecs() const override;
- QString videoCodecDescription(const QString &codecName) const override;
- QVideoEncoderSettings videoSettings() const override;
- void setVideoSettings(const QVideoEncoderSettings &settings) override;
-
-private:
- QAndroidCaptureSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDVIDEOENCODERSETTINGSCONTROL_H
diff --git a/src/plugins/android/src/mediacapture/qandroidviewfindersettingscontrol.cpp b/src/plugins/android/src/mediacapture/qandroidviewfindersettingscontrol.cpp
deleted file mode 100644
index 01a826064..000000000
--- a/src/plugins/android/src/mediacapture/qandroidviewfindersettingscontrol.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Ruslan Baratov
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidviewfindersettingscontrol.h"
-#include "qandroidcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidViewfinderSettingsControl2::QAndroidViewfinderSettingsControl2(QAndroidCameraSession *session)
- : m_cameraSession(session)
-{
-}
-
-QList<QCameraViewfinderSettings> QAndroidViewfinderSettingsControl2::supportedViewfinderSettings() const
-{
- QList<QCameraViewfinderSettings> viewfinderSettings;
-
- const QList<QSize> previewSizes = m_cameraSession->getSupportedPreviewSizes();
- const QList<QVideoFrame::PixelFormat> pixelFormats = m_cameraSession->getSupportedPixelFormats();
- const QList<AndroidCamera::FpsRange> fpsRanges = m_cameraSession->getSupportedPreviewFpsRange();
-
- viewfinderSettings.reserve(previewSizes.size() * pixelFormats.size() * fpsRanges.size());
-
- for (const QSize& size : previewSizes) {
- for (QVideoFrame::PixelFormat pixelFormat : pixelFormats) {
- for (const AndroidCamera::FpsRange& fpsRange : fpsRanges) {
- QCameraViewfinderSettings s;
- s.setResolution(size);
- s.setPixelAspectRatio(QSize(1, 1));
- s.setPixelFormat(pixelFormat);
- s.setMinimumFrameRate(fpsRange.getMinReal());
- s.setMaximumFrameRate(fpsRange.getMaxReal());
- viewfinderSettings << s;
- }
- }
- }
- return viewfinderSettings;
-}
-
-QCameraViewfinderSettings QAndroidViewfinderSettingsControl2::viewfinderSettings() const
-{
- return m_cameraSession->viewfinderSettings();
-}
-
-void QAndroidViewfinderSettingsControl2::setViewfinderSettings(const QCameraViewfinderSettings &settings)
-{
- m_cameraSession->setViewfinderSettings(settings);
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qandroidviewfindersettingscontrol.cpp"
diff --git a/src/plugins/android/src/mediacapture/qandroidviewfindersettingscontrol.h b/src/plugins/android/src/mediacapture/qandroidviewfindersettingscontrol.h
deleted file mode 100644
index c7863a144..000000000
--- a/src/plugins/android/src/mediacapture/qandroidviewfindersettingscontrol.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Ruslan Baratov
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDVIEWFINDERSETTINGSCONTROL_H
-#define QANDROIDVIEWFINDERSETTINGSCONTROL_H
-
-#include <QtMultimedia/qcameraviewfindersettingscontrol.h>
-#include <QtMultimedia/qcameraviewfindersettings.h>
-
-#include <QtCore/qpointer.h>
-#include <QtCore/qglobal.h>
-#include <QtCore/qsize.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCameraSession;
-
-class QAndroidViewfinderSettingsControl2 : public QCameraViewfinderSettingsControl2
-{
- Q_OBJECT
-public:
- explicit QAndroidViewfinderSettingsControl2(QAndroidCameraSession *session);
-
- QList<QCameraViewfinderSettings> supportedViewfinderSettings() const override;
- QCameraViewfinderSettings viewfinderSettings() const override;
- void setViewfinderSettings(const QCameraViewfinderSettings &settings) override;
-
-private:
- QAndroidCameraSession *m_cameraSession;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDVIEWFINDERSETTINGSCONTROL_H
diff --git a/src/plugins/android/src/mediaplayer/mediaplayer.pri b/src/plugins/android/src/mediaplayer/mediaplayer.pri
deleted file mode 100644
index 3a9cef3a1..000000000
--- a/src/plugins/android/src/mediaplayer/mediaplayer.pri
+++ /dev/null
@@ -1,17 +0,0 @@
-INCLUDEPATH += $$PWD
-
-HEADERS += \
- $$PWD/qandroidmediaplayercontrol.h \
- $$PWD/qandroidmediaservice.h \
- $$PWD/qandroidmetadatareadercontrol.h \
- $$PWD/qandroidaudiorolecontrol.h \
- $$PWD/qandroidcustomaudiorolecontrol.h \
- $$PWD/qandroidmediaplayervideorenderercontrol.h
-
-SOURCES += \
- $$PWD/qandroidmediaplayercontrol.cpp \
- $$PWD/qandroidmediaservice.cpp \
- $$PWD/qandroidmetadatareadercontrol.cpp \
- $$PWD/qandroidaudiorolecontrol.cpp \
- $$PWD/qandroidcustomaudiorolecontrol.cpp \
- $$PWD/qandroidmediaplayervideorenderercontrol.cpp
diff --git a/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp
deleted file mode 100644
index 5879b0cb9..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidaudiorolecontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidAudioRoleControl::QAndroidAudioRoleControl(QObject *parent)
- : QAudioRoleControl(parent)
-{
-}
-
-QAudio::Role QAndroidAudioRoleControl::audioRole() const
-{
- return m_role;
-}
-
-void QAndroidAudioRoleControl::setAudioRole(QAudio::Role role)
-{
- if (m_role == role)
- return;
-
- m_role = role;
- emit audioRoleChanged(m_role);
-}
-
-QList<QAudio::Role> QAndroidAudioRoleControl::supportedAudioRoles() const
-{
- return QList<QAudio::Role>()
- << QAudio::VoiceCommunicationRole
- << QAudio::MusicRole
- << QAudio::VideoRole
- << QAudio::SonificationRole
- << QAudio::AlarmRole
- << QAudio::NotificationRole
- << QAudio::RingtoneRole
- << QAudio::AccessibilityRole
- << QAudio::GameRole;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h b/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h
deleted file mode 100644
index 89219e026..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDAUDIOROLECONTROL_H
-#define QANDROIDAUDIOROLECONTROL_H
-
-#include <qaudiorolecontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidAudioRoleControl : public QAudioRoleControl
-{
- Q_OBJECT
-public:
- explicit QAndroidAudioRoleControl(QObject *parent = nullptr);
-
- QAudio::Role audioRole() const override;
- void setAudioRole(QAudio::Role role) override;
- QList<QAudio::Role> supportedAudioRoles() const override;
-
-private:
- QAudio::Role m_role = QAudio::UnknownRole;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDAUDIOROLECONTROL_H
diff --git a/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp
deleted file mode 100644
index cb7b5d0af..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidcustomaudiorolecontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidCustomAudioRoleControl::QAndroidCustomAudioRoleControl(QObject *parent)
- : QCustomAudioRoleControl(parent)
-{
-}
-
-QString QAndroidCustomAudioRoleControl::customAudioRole() const
-{
- return m_role;
-}
-
-void QAndroidCustomAudioRoleControl::setCustomAudioRole(const QString &role)
-{
- if (m_role == role)
- return;
-
- m_role = role;
- emit customAudioRoleChanged(m_role);
-}
-
-QStringList QAndroidCustomAudioRoleControl::supportedCustomAudioRoles() const
-{
- return QStringList()
- << "CONTENT_TYPE_MOVIE"
- << "CONTENT_TYPE_MUSIC"
- << "CONTENT_TYPE_SONIFICATION"
- << "CONTENT_TYPE_SPEECH"
- << "USAGE_ALARM"
- << "USAGE_ASSISTANCE_ACCESSIBILITY"
- << "USAGE_ASSISTANCE_NAVIGATION_GUIDANCE"
- << "USAGE_ASSISTANCE_SONIFICATION"
- << "USAGE_ASSISTANT"
- << "USAGE_GAME"
- << "USAGE_MEDIA"
- << "USAGE_NOTIFICATION"
- << "USAGE_NOTIFICATION_COMMUNICATION_DELAYED"
- << "USAGE_NOTIFICATION_COMMUNICATION_INSTANT"
- << "USAGE_NOTIFICATION_COMMUNICATION_REQUEST"
- << "USAGE_NOTIFICATION_EVENT"
- << "USAGE_NOTIFICATION_RINGTONE"
- << "USAGE_VOICE_COMMUNICATION"
- << "USAGE_VOICE_COMMUNICATION_SIGNALLING";
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h b/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h
deleted file mode 100644
index 4604ebe67..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDCUSTOMAUDIOROLECONTROL_H
-#define QANDROIDCUSTOMAUDIOROLECONTROL_H
-
-#include <qcustomaudiorolecontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidCustomAudioRoleControl : public QCustomAudioRoleControl
-{
- Q_OBJECT
-public:
- explicit QAndroidCustomAudioRoleControl(QObject *parent = nullptr);
-
- QString customAudioRole() const override;
- void setCustomAudioRole(const QString &role) override;
- QStringList supportedCustomAudioRoles() const override;
-
-private:
- QString m_role;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDCUSTOMAUDIOROLECONTROL_H
diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp
deleted file mode 100644
index 82250b654..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp
+++ /dev/null
@@ -1,797 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidmediaplayercontrol.h"
-#include "androidmediaplayer.h"
-#include "qandroidvideooutput.h"
-
-QT_BEGIN_NAMESPACE
-
-class StateChangeNotifier
-{
-public:
- StateChangeNotifier(QAndroidMediaPlayerControl *mp)
- : mControl(mp)
- , mPreviousState(mp->state())
- , mPreviousMediaStatus(mp->mediaStatus())
- {
- ++mControl->mActiveStateChangeNotifiers;
- }
-
- ~StateChangeNotifier()
- {
- if (--mControl->mActiveStateChangeNotifiers)
- return;
-
- if (mPreviousMediaStatus != mControl->mediaStatus())
- Q_EMIT mControl->mediaStatusChanged(mControl->mediaStatus());
-
- if (mPreviousState != mControl->state())
- Q_EMIT mControl->stateChanged(mControl->state());
- }
-
-private:
- QAndroidMediaPlayerControl *mControl;
- QMediaPlayer::State mPreviousState;
- QMediaPlayer::MediaStatus mPreviousMediaStatus;
-};
-
-
-QAndroidMediaPlayerControl::QAndroidMediaPlayerControl(QObject *parent)
- : QMediaPlayerControl(parent),
- mMediaPlayer(new AndroidMediaPlayer),
- mCurrentState(QMediaPlayer::StoppedState),
- mCurrentMediaStatus(QMediaPlayer::NoMedia),
- mMediaStream(0),
- mVideoOutput(0),
- mSeekable(true),
- mBufferPercent(-1),
- mBufferFilled(false),
- mAudioAvailable(false),
- mVideoAvailable(false),
- mBuffering(false),
- mState(AndroidMediaPlayer::Uninitialized),
- mPendingState(-1),
- mPendingPosition(-1),
- mPendingSetMedia(false),
- mPendingVolume(-1),
- mPendingMute(-1),
- mReloadingMedia(false),
- mActiveStateChangeNotifiers(0),
- mPendingPlaybackRate(1.0),
- mHasPendingPlaybackRate(false)
-{
- connect(mMediaPlayer,SIGNAL(bufferingChanged(qint32)),
- this,SLOT(onBufferingChanged(qint32)));
- connect(mMediaPlayer,SIGNAL(info(qint32,qint32)),
- this,SLOT(onInfo(qint32,qint32)));
- connect(mMediaPlayer,SIGNAL(error(qint32,qint32)),
- this,SLOT(onError(qint32,qint32)));
- connect(mMediaPlayer,SIGNAL(stateChanged(qint32)),
- this,SLOT(onStateChanged(qint32)));
- connect(mMediaPlayer,SIGNAL(videoSizeChanged(qint32,qint32)),
- this,SLOT(onVideoSizeChanged(qint32,qint32)));
- connect(mMediaPlayer,SIGNAL(progressChanged(qint64)),
- this,SIGNAL(positionChanged(qint64)));
- connect(mMediaPlayer,SIGNAL(durationChanged(qint64)),
- this,SIGNAL(durationChanged(qint64)));
-}
-
-QAndroidMediaPlayerControl::~QAndroidMediaPlayerControl()
-{
- mMediaPlayer->release();
- delete mMediaPlayer;
-}
-
-QMediaPlayer::State QAndroidMediaPlayerControl::state() const
-{
- return mCurrentState;
-}
-
-QMediaPlayer::MediaStatus QAndroidMediaPlayerControl::mediaStatus() const
-{
- return mCurrentMediaStatus;
-}
-
-qint64 QAndroidMediaPlayerControl::duration() const
-{
- if ((mState & (AndroidMediaPlayer::Prepared
- | AndroidMediaPlayer::Started
- | AndroidMediaPlayer::Paused
- | AndroidMediaPlayer::Stopped
- | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
- return 0;
- }
-
- return mMediaPlayer->getDuration();
-}
-
-qint64 QAndroidMediaPlayerControl::position() const
-{
- if (mCurrentMediaStatus == QMediaPlayer::EndOfMedia)
- return duration();
-
- if ((mState & (AndroidMediaPlayer::Prepared
- | AndroidMediaPlayer::Started
- | AndroidMediaPlayer::Paused
- | AndroidMediaPlayer::PlaybackCompleted))) {
- return mMediaPlayer->getCurrentPosition();
- }
-
- return (mPendingPosition == -1) ? 0 : mPendingPosition;
-}
-
-void QAndroidMediaPlayerControl::setPosition(qint64 position)
-{
- if (!mSeekable)
- return;
-
- const int seekPosition = (position > INT_MAX) ? INT_MAX : position;
-
- if (seekPosition == this->position())
- return;
-
- StateChangeNotifier notifier(this);
-
- if (mCurrentMediaStatus == QMediaPlayer::EndOfMedia)
- setMediaStatus(QMediaPlayer::LoadedMedia);
-
- if ((mState & (AndroidMediaPlayer::Prepared
- | AndroidMediaPlayer::Started
- | AndroidMediaPlayer::Paused
- | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
- mPendingPosition = seekPosition;
- } else {
- mMediaPlayer->seekTo(seekPosition);
-
- if (mPendingPosition != -1) {
- mPendingPosition = -1;
- }
- }
-
- Q_EMIT positionChanged(seekPosition);
-}
-
-int QAndroidMediaPlayerControl::volume() const
-{
- return (mPendingVolume == -1) ? mMediaPlayer->volume() : mPendingVolume;
-}
-
-void QAndroidMediaPlayerControl::setVolume(int volume)
-{
- if ((mState & (AndroidMediaPlayer::Idle
- | AndroidMediaPlayer::Initialized
- | AndroidMediaPlayer::Stopped
- | AndroidMediaPlayer::Prepared
- | AndroidMediaPlayer::Started
- | AndroidMediaPlayer::Paused
- | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
- if (mPendingVolume != volume) {
- mPendingVolume = volume;
- Q_EMIT volumeChanged(volume);
- }
- return;
- }
-
- mMediaPlayer->setVolume(volume);
-
- if (mPendingVolume != -1) {
- mPendingVolume = -1;
- return;
- }
-
- Q_EMIT volumeChanged(volume);
-}
-
-bool QAndroidMediaPlayerControl::isMuted() const
-{
- return (mPendingMute == -1) ? mMediaPlayer->isMuted() : (mPendingMute == 1);
-}
-
-void QAndroidMediaPlayerControl::setMuted(bool muted)
-{
- if ((mState & (AndroidMediaPlayer::Idle
- | AndroidMediaPlayer::Initialized
- | AndroidMediaPlayer::Stopped
- | AndroidMediaPlayer::Prepared
- | AndroidMediaPlayer::Started
- | AndroidMediaPlayer::Paused
- | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
- if (mPendingMute != muted) {
- mPendingMute = muted;
- Q_EMIT mutedChanged(muted);
- }
- return;
- }
-
- mMediaPlayer->setMuted(muted);
-
- if (mPendingMute != -1) {
- mPendingMute = -1;
- return;
- }
-
- Q_EMIT mutedChanged(muted);
-}
-
-void QAndroidMediaPlayerControl::setAudioRole(QAudio::Role role)
-{
- mMediaPlayer->setAudioRole(role);
-}
-
-void QAndroidMediaPlayerControl::setCustomAudioRole(const QString &role)
-{
- mMediaPlayer->setCustomAudioRole(role);
-}
-
-int QAndroidMediaPlayerControl::bufferStatus() const
-{
- return mBufferFilled ? 100 : 0;
-}
-
-bool QAndroidMediaPlayerControl::isAudioAvailable() const
-{
- return mAudioAvailable;
-}
-
-bool QAndroidMediaPlayerControl::isVideoAvailable() const
-{
- return mVideoAvailable;
-}
-
-bool QAndroidMediaPlayerControl::isSeekable() const
-{
- return mSeekable;
-}
-
-QMediaTimeRange QAndroidMediaPlayerControl::availablePlaybackRanges() const
-{
- return mAvailablePlaybackRange;
-}
-
-void QAndroidMediaPlayerControl::updateAvailablePlaybackRanges()
-{
- if (mBuffering) {
- const qint64 pos = position();
- const qint64 end = (duration() / 100) * mBufferPercent;
- mAvailablePlaybackRange.addInterval(pos, end);
- } else if (mSeekable) {
- mAvailablePlaybackRange = QMediaTimeRange(0, duration());
- } else {
- mAvailablePlaybackRange = QMediaTimeRange();
- }
-
- Q_EMIT availablePlaybackRangesChanged(mAvailablePlaybackRange);
-}
-
-qreal QAndroidMediaPlayerControl::playbackRate() const
-{
- if (mHasPendingPlaybackRate ||
- (mState & (AndroidMediaPlayer::Initialized
- | AndroidMediaPlayer::Prepared
- | AndroidMediaPlayer::Started
- | AndroidMediaPlayer::Paused
- | AndroidMediaPlayer::PlaybackCompleted
- | AndroidMediaPlayer::Error)) == 0) {
- return mPendingPlaybackRate;
- }
-
- return mMediaPlayer->playbackRate();
-}
-
-void QAndroidMediaPlayerControl::setPlaybackRate(qreal rate)
-{
- if ((mState & (AndroidMediaPlayer::Initialized
- | AndroidMediaPlayer::Prepared
- | AndroidMediaPlayer::Started
- | AndroidMediaPlayer::Paused
- | AndroidMediaPlayer::PlaybackCompleted
- | AndroidMediaPlayer::Error)) == 0) {
- if (mPendingPlaybackRate != rate) {
- mPendingPlaybackRate = rate;
- mHasPendingPlaybackRate = true;
- Q_EMIT playbackRateChanged(rate);
- }
- return;
- }
-
- bool succeeded = mMediaPlayer->setPlaybackRate(rate);
-
- if (mHasPendingPlaybackRate) {
- mHasPendingPlaybackRate = false;
- mPendingPlaybackRate = qreal(1.0);
- if (!succeeded)
- Q_EMIT playbackRateChanged(playbackRate());
- } else if (succeeded) {
- Q_EMIT playbackRateChanged(rate);
- }
-}
-
-QMediaContent QAndroidMediaPlayerControl::media() const
-{
- return mMediaContent;
-}
-
-const QIODevice *QAndroidMediaPlayerControl::mediaStream() const
-{
- return mMediaStream;
-}
-
-void QAndroidMediaPlayerControl::setMedia(const QMediaContent &mediaContent,
- QIODevice *stream)
-{
- StateChangeNotifier notifier(this);
-
- mReloadingMedia = (mMediaContent == mediaContent) && !mPendingSetMedia;
-
- if (!mReloadingMedia) {
- mMediaContent = mediaContent;
- mMediaStream = stream;
- }
-
- // Release the mediaplayer if it's not in in Idle or Uninitialized state
- if ((mState & (AndroidMediaPlayer::Idle | AndroidMediaPlayer::Uninitialized)) == 0)
- mMediaPlayer->release();
-
- if (mediaContent.isNull()) {
- setMediaStatus(QMediaPlayer::NoMedia);
- } else {
- if (mVideoOutput && !mVideoOutput->isReady()) {
- // if a video output is set but the video texture is not ready, delay loading the media
- // since it can cause problems on some hardware
- mPendingSetMedia = true;
- return;
- }
-
- if (mVideoSize.isValid() && mVideoOutput)
- mVideoOutput->setVideoSize(mVideoSize);
-
- if ((mMediaPlayer->display() == 0) && mVideoOutput)
- mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture());
- mMediaPlayer->setDataSource(mediaContent.request());
- mMediaPlayer->prepareAsync();
- }
-
- if (!mReloadingMedia)
- Q_EMIT mediaChanged(mMediaContent);
-
- resetBufferingProgress();
-
- mReloadingMedia = false;
-}
-
-void QAndroidMediaPlayerControl::setVideoOutput(QAndroidVideoOutput *videoOutput)
-{
- if (mVideoOutput) {
- mMediaPlayer->setDisplay(0);
- mVideoOutput->stop();
- mVideoOutput->reset();
- }
-
- mVideoOutput = videoOutput;
-
- if (!mVideoOutput)
- return;
-
- if (mVideoOutput->isReady())
- mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture());
-
- connect(videoOutput, SIGNAL(readyChanged(bool)), this, SLOT(onVideoOutputReady(bool)));
-}
-
-void QAndroidMediaPlayerControl::play()
-{
- StateChangeNotifier notifier(this);
-
- // We need to prepare the mediaplayer again.
- if ((mState & AndroidMediaPlayer::Stopped) && !mMediaContent.isNull()) {
- setMedia(mMediaContent, mMediaStream);
- }
-
- if (!mMediaContent.isNull())
- setState(QMediaPlayer::PlayingState);
-
- if ((mState & (AndroidMediaPlayer::Prepared
- | AndroidMediaPlayer::Started
- | AndroidMediaPlayer::Paused
- | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
- mPendingState = QMediaPlayer::PlayingState;
- return;
- }
-
- mMediaPlayer->play();
-}
-
-void QAndroidMediaPlayerControl::pause()
-{
- StateChangeNotifier notifier(this);
-
- setState(QMediaPlayer::PausedState);
-
- if ((mState & (AndroidMediaPlayer::Started
- | AndroidMediaPlayer::Paused
- | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
- mPendingState = QMediaPlayer::PausedState;
- return;
- }
-
- mMediaPlayer->pause();
-}
-
-void QAndroidMediaPlayerControl::stop()
-{
- StateChangeNotifier notifier(this);
-
- setState(QMediaPlayer::StoppedState);
-
- if ((mState & (AndroidMediaPlayer::Prepared
- | AndroidMediaPlayer::Started
- | AndroidMediaPlayer::Stopped
- | AndroidMediaPlayer::Paused
- | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
- if ((mState & (AndroidMediaPlayer::Idle | AndroidMediaPlayer::Uninitialized | AndroidMediaPlayer::Error)) == 0)
- mPendingState = QMediaPlayer::StoppedState;
- return;
- }
-
- mMediaPlayer->stop();
-}
-
-void QAndroidMediaPlayerControl::onInfo(qint32 what, qint32 extra)
-{
- StateChangeNotifier notifier(this);
-
- Q_UNUSED(extra);
- switch (what) {
- case AndroidMediaPlayer::MEDIA_INFO_UNKNOWN:
- break;
- case AndroidMediaPlayer::MEDIA_INFO_VIDEO_TRACK_LAGGING:
- // IGNORE
- break;
- case AndroidMediaPlayer::MEDIA_INFO_VIDEO_RENDERING_START:
- break;
- case AndroidMediaPlayer::MEDIA_INFO_BUFFERING_START:
- mPendingState = mCurrentState;
- setState(QMediaPlayer::PausedState);
- setMediaStatus(QMediaPlayer::StalledMedia);
- break;
- case AndroidMediaPlayer::MEDIA_INFO_BUFFERING_END:
- if (mCurrentState != QMediaPlayer::StoppedState)
- flushPendingStates();
- break;
- case AndroidMediaPlayer::MEDIA_INFO_BAD_INTERLEAVING:
- break;
- case AndroidMediaPlayer::MEDIA_INFO_NOT_SEEKABLE:
- setSeekable(false);
- break;
- case AndroidMediaPlayer::MEDIA_INFO_METADATA_UPDATE:
- Q_EMIT metaDataUpdated();
- break;
- }
-}
-
-void QAndroidMediaPlayerControl::onError(qint32 what, qint32 extra)
-{
- StateChangeNotifier notifier(this);
-
- QString errorString;
- QMediaPlayer::Error error = QMediaPlayer::ResourceError;
-
- switch (what) {
- case AndroidMediaPlayer::MEDIA_ERROR_UNKNOWN:
- errorString = QLatin1String("Error:");
- break;
- case AndroidMediaPlayer::MEDIA_ERROR_SERVER_DIED:
- errorString = QLatin1String("Error: Server died");
- error = QMediaPlayer::ServiceMissingError;
- break;
- case AndroidMediaPlayer::MEDIA_ERROR_INVALID_STATE:
- errorString = QLatin1String("Error: Invalid state");
- error = QMediaPlayer::ServiceMissingError;
- break;
- }
-
- switch (extra) {
- case AndroidMediaPlayer::MEDIA_ERROR_IO: // Network OR file error
- errorString += QLatin1String(" (I/O operation failed)");
- error = QMediaPlayer::NetworkError;
- setMediaStatus(QMediaPlayer::InvalidMedia);
- break;
- case AndroidMediaPlayer::MEDIA_ERROR_MALFORMED:
- errorString += QLatin1String(" (Malformed bitstream)");
- error = QMediaPlayer::FormatError;
- setMediaStatus(QMediaPlayer::InvalidMedia);
- break;
- case AndroidMediaPlayer::MEDIA_ERROR_UNSUPPORTED:
- errorString += QLatin1String(" (Unsupported media)");
- error = QMediaPlayer::FormatError;
- setMediaStatus(QMediaPlayer::InvalidMedia);
- break;
- case AndroidMediaPlayer::MEDIA_ERROR_TIMED_OUT:
- errorString += QLatin1String(" (Timed out)");
- break;
- case AndroidMediaPlayer::MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
- errorString += QLatin1String(" (Unable to start progressive playback')");
- error = QMediaPlayer::FormatError;
- setMediaStatus(QMediaPlayer::InvalidMedia);
- break;
- case AndroidMediaPlayer::MEDIA_ERROR_BAD_THINGS_ARE_GOING_TO_HAPPEN:
- errorString += QLatin1String(" (Unknown error/Insufficient resources)");
- error = QMediaPlayer::ServiceMissingError;
- break;
- }
-
- Q_EMIT QMediaPlayerControl::error(error, errorString);
-}
-
-void QAndroidMediaPlayerControl::onBufferingChanged(qint32 percent)
-{
- StateChangeNotifier notifier(this);
-
- mBuffering = percent != 100;
- mBufferPercent = percent;
-
- updateAvailablePlaybackRanges();
-
- if (mCurrentState != QMediaPlayer::StoppedState)
- setMediaStatus(mBuffering ? QMediaPlayer::BufferingMedia : QMediaPlayer::BufferedMedia);
-}
-
-void QAndroidMediaPlayerControl::onVideoSizeChanged(qint32 width, qint32 height)
-{
- QSize newSize(width, height);
-
- if (width == 0 || height == 0 || newSize == mVideoSize)
- return;
-
- setVideoAvailable(true);
- mVideoSize = newSize;
-
- if (mVideoOutput)
- mVideoOutput->setVideoSize(mVideoSize);
-}
-
-void QAndroidMediaPlayerControl::onStateChanged(qint32 state)
-{
- // If reloading, don't report state changes unless the new state is Prepared or Error.
- if ((mState & AndroidMediaPlayer::Stopped)
- && (state & (AndroidMediaPlayer::Prepared | AndroidMediaPlayer::Error | AndroidMediaPlayer::Uninitialized)) == 0) {
- return;
- }
-
- StateChangeNotifier notifier(this);
-
- mState = state;
- switch (mState) {
- case AndroidMediaPlayer::Idle:
- break;
- case AndroidMediaPlayer::Initialized:
- break;
- case AndroidMediaPlayer::Preparing:
- if (!mReloadingMedia)
- setMediaStatus(QMediaPlayer::LoadingMedia);
- break;
- case AndroidMediaPlayer::Prepared:
- setMediaStatus(QMediaPlayer::LoadedMedia);
- if (mBuffering) {
- setMediaStatus(mBufferPercent == 100 ? QMediaPlayer::BufferedMedia
- : QMediaPlayer::BufferingMedia);
- } else {
- onBufferingChanged(100);
- }
- Q_EMIT metaDataUpdated();
- setAudioAvailable(true);
- flushPendingStates();
- break;
- case AndroidMediaPlayer::Started:
- setState(QMediaPlayer::PlayingState);
- if (mBuffering) {
- setMediaStatus(mBufferPercent == 100 ? QMediaPlayer::BufferedMedia
- : QMediaPlayer::BufferingMedia);
- } else {
- setMediaStatus(QMediaPlayer::BufferedMedia);
- }
- Q_EMIT positionChanged(position());
- break;
- case AndroidMediaPlayer::Paused:
- setState(QMediaPlayer::PausedState);
- break;
- case AndroidMediaPlayer::Error:
- setState(QMediaPlayer::StoppedState);
- setMediaStatus(QMediaPlayer::UnknownMediaStatus);
- mMediaPlayer->release();
- Q_EMIT positionChanged(0);
- break;
- case AndroidMediaPlayer::Stopped:
- setState(QMediaPlayer::StoppedState);
- setMediaStatus(QMediaPlayer::LoadedMedia);
- Q_EMIT positionChanged(0);
- break;
- case AndroidMediaPlayer::PlaybackCompleted:
- setState(QMediaPlayer::StoppedState);
- setMediaStatus(QMediaPlayer::EndOfMedia);
- break;
- case AndroidMediaPlayer::Uninitialized:
- // reset some properties (unless we reload the same media)
- if (!mReloadingMedia) {
- resetBufferingProgress();
- mPendingPosition = -1;
- mPendingSetMedia = false;
- mPendingState = -1;
-
- Q_EMIT durationChanged(0);
- Q_EMIT positionChanged(0);
-
- setAudioAvailable(false);
- setVideoAvailable(false);
- setSeekable(true);
- }
- break;
- default:
- break;
- }
-
- if ((mState & (AndroidMediaPlayer::Stopped | AndroidMediaPlayer::Uninitialized)) != 0) {
- mMediaPlayer->setDisplay(0);
- if (mVideoOutput) {
- mVideoOutput->stop();
- mVideoOutput->reset();
- }
- }
-}
-
-void QAndroidMediaPlayerControl::onVideoOutputReady(bool ready)
-{
- if ((mMediaPlayer->display() == 0) && mVideoOutput && ready)
- mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture());
-
- flushPendingStates();
-}
-
-void QAndroidMediaPlayerControl::setState(QMediaPlayer::State state)
-{
- if (mCurrentState == state)
- return;
-
- if (mCurrentState == QMediaPlayer::StoppedState && state == QMediaPlayer::PausedState)
- return;
-
- mCurrentState = state;
-}
-
-void QAndroidMediaPlayerControl::setMediaStatus(QMediaPlayer::MediaStatus status)
-{
- if (mCurrentMediaStatus == status)
- return;
-
- mCurrentMediaStatus = status;
-
- if (status == QMediaPlayer::NoMedia || status == QMediaPlayer::InvalidMedia)
- Q_EMIT durationChanged(0);
-
- if (status == QMediaPlayer::EndOfMedia)
- Q_EMIT positionChanged(position());
-
- updateBufferStatus();
-}
-
-void QAndroidMediaPlayerControl::setSeekable(bool seekable)
-{
- if (mSeekable == seekable)
- return;
-
- mSeekable = seekable;
- Q_EMIT seekableChanged(mSeekable);
-}
-
-void QAndroidMediaPlayerControl::setAudioAvailable(bool available)
-{
- if (mAudioAvailable == available)
- return;
-
- mAudioAvailable = available;
- Q_EMIT audioAvailableChanged(mAudioAvailable);
-}
-
-void QAndroidMediaPlayerControl::setVideoAvailable(bool available)
-{
- if (mVideoAvailable == available)
- return;
-
- if (!available)
- mVideoSize = QSize();
-
- mVideoAvailable = available;
- Q_EMIT videoAvailableChanged(mVideoAvailable);
-}
-
-void QAndroidMediaPlayerControl::resetBufferingProgress()
-{
- mBuffering = false;
- mBufferPercent = 0;
- mAvailablePlaybackRange = QMediaTimeRange();
-}
-
-void QAndroidMediaPlayerControl::flushPendingStates()
-{
- if (mPendingSetMedia) {
- setMedia(mMediaContent, 0);
- mPendingSetMedia = false;
- return;
- }
-
- const int newState = mPendingState;
- mPendingState = -1;
-
- if (mPendingPosition != -1)
- setPosition(mPendingPosition);
- if (mPendingVolume != -1)
- setVolume(mPendingVolume);
- if (mPendingMute != -1)
- setMuted((mPendingMute == 1));
- if (mHasPendingPlaybackRate)
- setPlaybackRate(mPendingPlaybackRate);
-
- switch (newState) {
- case QMediaPlayer::PlayingState:
- play();
- break;
- case QMediaPlayer::PausedState:
- pause();
- break;
- case QMediaPlayer::StoppedState:
- stop();
- break;
- default:
- break;
- }
-}
-
-void QAndroidMediaPlayerControl::updateBufferStatus()
-{
- bool bufferFilled = (mCurrentMediaStatus == QMediaPlayer::BufferedMedia
- || mCurrentMediaStatus == QMediaPlayer::BufferingMedia);
-
- if (mBufferFilled != bufferFilled) {
- mBufferFilled = bufferFilled;
- Q_EMIT bufferStatusChanged(bufferStatus());
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h
deleted file mode 100644
index 35f56145f..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDMEDIAPLAYERCONTROL_H
-#define QANDROIDMEDIAPLAYERCONTROL_H
-
-#include <qglobal.h>
-#include <QMediaPlayerControl>
-#include <qsize.h>
-
-QT_BEGIN_NAMESPACE
-
-class AndroidMediaPlayer;
-class QAndroidVideoOutput;
-
-class QAndroidMediaPlayerControl : public QMediaPlayerControl
-{
- Q_OBJECT
-public:
- explicit QAndroidMediaPlayerControl(QObject *parent = 0);
- ~QAndroidMediaPlayerControl() override;
-
- QMediaPlayer::State state() const override;
- QMediaPlayer::MediaStatus mediaStatus() const override;
- qint64 duration() const override;
- qint64 position() const override;
- int volume() const override;
- bool isMuted() const override;
- int bufferStatus() const override;
- bool isAudioAvailable() const override;
- bool isVideoAvailable() const override;
- bool isSeekable() const override;
- QMediaTimeRange availablePlaybackRanges() const override;
- qreal playbackRate() const override;
- void setPlaybackRate(qreal rate) override;
- QMediaContent media() const override;
- const QIODevice *mediaStream() const override;
- void setMedia(const QMediaContent &mediaContent, QIODevice *stream) override;
-
- void setVideoOutput(QAndroidVideoOutput *videoOutput);
-
-Q_SIGNALS:
- void metaDataUpdated();
-
-public Q_SLOTS:
- void setPosition(qint64 position) override;
- void play() override;
- void pause() override;
- void stop() override;
- void setVolume(int volume) override;
- void setMuted(bool muted) override;
- void setAudioRole(QAudio::Role role);
- void setCustomAudioRole(const QString &role);
-
-private Q_SLOTS:
- void onVideoOutputReady(bool ready);
- void onError(qint32 what, qint32 extra);
- void onInfo(qint32 what, qint32 extra);
- void onBufferingChanged(qint32 percent);
- void onVideoSizeChanged(qint32 width, qint32 height);
- void onStateChanged(qint32 state);
-
-private:
- AndroidMediaPlayer *mMediaPlayer;
- QMediaPlayer::State mCurrentState;
- QMediaPlayer::MediaStatus mCurrentMediaStatus;
- QMediaContent mMediaContent;
- QIODevice *mMediaStream;
- QAndroidVideoOutput *mVideoOutput;
- bool mSeekable;
- int mBufferPercent;
- bool mBufferFilled;
- bool mAudioAvailable;
- bool mVideoAvailable;
- QSize mVideoSize;
- bool mBuffering;
- QMediaTimeRange mAvailablePlaybackRange;
- int mState;
- int mPendingState;
- qint64 mPendingPosition;
- bool mPendingSetMedia;
- int mPendingVolume;
- int mPendingMute;
- bool mReloadingMedia;
- int mActiveStateChangeNotifiers;
- qreal mPendingPlaybackRate;
- bool mHasPendingPlaybackRate; // we need this because the rate can theoretically be negative
-
- void setState(QMediaPlayer::State state);
- void setMediaStatus(QMediaPlayer::MediaStatus status);
- void setSeekable(bool seekable);
- void setAudioAvailable(bool available);
- void setVideoAvailable(bool available);
- void updateAvailablePlaybackRanges();
- void resetBufferingProgress();
- void flushPendingStates();
- void updateBufferStatus();
-
- friend class StateChangeNotifier;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDMEDIAPLAYERCONTROL_H
diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.cpp
deleted file mode 100644
index 5252d60ad..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidmediaplayervideorenderercontrol.h"
-
-#include "qandroidmediaplayercontrol.h"
-#include "qandroidvideooutput.h"
-#include <qabstractvideosurface.h>
-
-QT_BEGIN_NAMESPACE
-
-QAndroidMediaPlayerVideoRendererControl::QAndroidMediaPlayerVideoRendererControl(QAndroidMediaPlayerControl *mediaPlayer, QObject *parent)
- : QVideoRendererControl(parent)
- , m_mediaPlayerControl(mediaPlayer)
- , m_surface(0)
- , m_textureOutput(new QAndroidTextureVideoOutput(this))
-{
- m_mediaPlayerControl->setVideoOutput(m_textureOutput);
-}
-
-QAndroidMediaPlayerVideoRendererControl::~QAndroidMediaPlayerVideoRendererControl()
-{
- m_mediaPlayerControl->setVideoOutput(0);
-}
-
-QAbstractVideoSurface *QAndroidMediaPlayerVideoRendererControl::surface() const
-{
- return m_surface;
-}
-
-void QAndroidMediaPlayerVideoRendererControl::setSurface(QAbstractVideoSurface *surface)
-{
- if (m_surface == surface)
- return;
-
- m_surface = surface;
- m_textureOutput->setSurface(m_surface);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.h b/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.h
deleted file mode 100644
index ef213cc57..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDMEDIAPLAYERVIDEORENDERERCONTROL_H
-#define QANDROIDMEDIAPLAYERVIDEORENDERERCONTROL_H
-
-#include <qvideorenderercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidMediaPlayerControl;
-class QAndroidTextureVideoOutput;
-
-class QAndroidMediaPlayerVideoRendererControl : public QVideoRendererControl
-{
- Q_OBJECT
-public:
- QAndroidMediaPlayerVideoRendererControl(QAndroidMediaPlayerControl *mediaPlayer, QObject *parent = 0);
- ~QAndroidMediaPlayerVideoRendererControl() override;
-
- QAbstractVideoSurface *surface() const override;
- void setSurface(QAbstractVideoSurface *surface) override;
-
-private:
- QAndroidMediaPlayerControl *m_mediaPlayerControl;
- QAbstractVideoSurface *m_surface;
- QAndroidTextureVideoOutput *m_textureOutput;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDMEDIAPLAYERVIDEORENDERERCONTROL_H
diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp b/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp
deleted file mode 100644
index c057f530a..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidmediaservice.h"
-
-#include "qandroidmediaplayercontrol.h"
-#include "qandroidmetadatareadercontrol.h"
-#include "qandroidaudiorolecontrol.h"
-#include "qandroidcustomaudiorolecontrol.h"
-#include "qandroidmediaplayervideorenderercontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-QAndroidMediaService::QAndroidMediaService(QObject *parent)
- : QMediaService(parent)
- , mAudioRoleControl(nullptr)
- , mCustomAudioRoleControl(nullptr)
- , mVideoRendererControl(0)
-{
- mMediaControl = new QAndroidMediaPlayerControl;
- mMetadataControl = new QAndroidMetaDataReaderControl;
- mAudioRoleControl = new QAndroidAudioRoleControl;
- mCustomAudioRoleControl = new QAndroidCustomAudioRoleControl;
- connect(mAudioRoleControl, &QAndroidAudioRoleControl::audioRoleChanged,
- mMediaControl, &QAndroidMediaPlayerControl::setAudioRole);
- connect(mCustomAudioRoleControl, &QAndroidCustomAudioRoleControl::customAudioRoleChanged,
- mMediaControl, &QAndroidMediaPlayerControl::setCustomAudioRole);
- connect(mMediaControl, SIGNAL(mediaChanged(QMediaContent)),
- mMetadataControl, SLOT(onMediaChanged(QMediaContent)));
- connect(mMediaControl, SIGNAL(metaDataUpdated()),
- mMetadataControl, SLOT(onUpdateMetaData()));
-}
-
-QAndroidMediaService::~QAndroidMediaService()
-{
- delete mVideoRendererControl;
- delete mCustomAudioRoleControl;
- delete mAudioRoleControl;
- delete mMetadataControl;
- delete mMediaControl;
-}
-
-QMediaControl *QAndroidMediaService::requestControl(const char *name)
-{
- if (qstrcmp(name, QMediaPlayerControl_iid) == 0)
- return mMediaControl;
-
- if (qstrcmp(name, QMetaDataReaderControl_iid) == 0)
- return mMetadataControl;
-
- if (qstrcmp(name, QAudioRoleControl_iid) == 0)
- return mAudioRoleControl;
-
- if (qstrcmp(name, QCustomAudioRoleControl_iid) == 0)
- return mCustomAudioRoleControl;
-
- if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
- if (!mVideoRendererControl) {
- mVideoRendererControl = new QAndroidMediaPlayerVideoRendererControl(mMediaControl);
- return mVideoRendererControl;
- }
- }
-
- return 0;
-}
-
-void QAndroidMediaService::releaseControl(QMediaControl *control)
-{
- if (control == mVideoRendererControl) {
- delete mVideoRendererControl;
- mVideoRendererControl = 0;
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaservice.h b/src/plugins/android/src/mediaplayer/qandroidmediaservice.h
deleted file mode 100644
index 788c11098..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidmediaservice.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDMEDIASERVICE_H
-#define QANDROIDMEDIASERVICE_H
-
-#include <QMediaService>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidMediaPlayerControl;
-class QAndroidMetaDataReaderControl;
-class QAndroidAudioRoleControl;
-class QAndroidCustomAudioRoleControl;
-class QAndroidMediaPlayerVideoRendererControl;
-
-class QAndroidMediaService : public QMediaService
-{
- Q_OBJECT
-public:
- explicit QAndroidMediaService(QObject *parent = 0);
- ~QAndroidMediaService() override;
-
- QMediaControl* requestControl(const char *name) override;
- void releaseControl(QMediaControl *control) override;
-
-private:
- QAndroidMediaPlayerControl *mMediaControl;
- QAndroidMetaDataReaderControl *mMetadataControl;
- QAndroidAudioRoleControl *mAudioRoleControl;
- QAndroidCustomAudioRoleControl *mCustomAudioRoleControl;
- QAndroidMediaPlayerVideoRendererControl *mVideoRendererControl;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDMEDIASERVICE_H
diff --git a/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.cpp
deleted file mode 100644
index de7a3aab1..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.cpp
+++ /dev/null
@@ -1,248 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidmetadatareadercontrol.h"
-
-#include "androidmediametadataretriever.h"
-#include <QtMultimedia/qmediametadata.h>
-#include <qsize.h>
-#include <QDate>
-#include <QtCore/qlist.h>
-#include <QtConcurrent/qtconcurrentrun.h>
-
-QT_BEGIN_NAMESPACE
-
-// Genre name ordered by ID
-// see: http://id3.org/id3v2.3.0#Appendix_A_-_Genre_List_from_ID3v1
-static const char* qt_ID3GenreNames[] =
-{
- "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz",
- "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno",
- "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno",
- "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental",
- "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass", "Soul", "Punk",
- "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave",
- "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy",
- "Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American",
- "Cabaret", "New Wave", "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal",
- "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock", "Folk",
- "Folk-Rock", "National Folk", "Swing", "Fast Fusion", "Bebob", "Latin", "Revival", "Celtic",
- "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock", "Psychedelic Rock",
- "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour",
- "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus",
- "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad",
- "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet", "Punk Rock", "Drum Solo", "A capella",
- "Euro-House", "Dance Hall"
-};
-
-typedef QList<QAndroidMetaDataReaderControl *> AndroidMetaDataReaders;
-Q_GLOBAL_STATIC(AndroidMetaDataReaders, g_metaDataReaders)
-Q_GLOBAL_STATIC(QMutex, g_metaDataReadersMtx)
-
-QAndroidMetaDataReaderControl::QAndroidMetaDataReaderControl(QObject *parent)
- : QMetaDataReaderControl(parent)
- , m_available(false)
-{
-}
-
-QAndroidMetaDataReaderControl::~QAndroidMetaDataReaderControl()
-{
- QMutexLocker l(g_metaDataReadersMtx);
- const int idx = g_metaDataReaders->indexOf(this);
- if (idx != -1)
- g_metaDataReaders->remove(idx);
-}
-
-bool QAndroidMetaDataReaderControl::isMetaDataAvailable() const
-{
- const QMutexLocker l(&m_mtx);
- return m_available && !m_metadata.isEmpty();
-}
-
-QVariant QAndroidMetaDataReaderControl::metaData(const QString &key) const
-{
- const QMutexLocker l(&m_mtx);
- return m_metadata.value(key);
-}
-
-QStringList QAndroidMetaDataReaderControl::availableMetaData() const
-{
- const QMutexLocker l(&m_mtx);
- return m_metadata.keys();
-}
-
-void QAndroidMetaDataReaderControl::onMediaChanged(const QMediaContent &media)
-{
- const QMutexLocker l(&m_mtx);
- m_metadata.clear();
- m_mediaContent = media;
-}
-
-void QAndroidMetaDataReaderControl::onUpdateMetaData()
-{
- {
- const QMutexLocker l(g_metaDataReadersMtx);
- if (!g_metaDataReaders->contains(this))
- g_metaDataReaders->append(this);
- }
-
- const QMutexLocker ml(&m_mtx);
- if (m_mediaContent.isNull())
- return;
-
- const QUrl &url = m_mediaContent.request().url();
- QtConcurrent::run(&extractMetadata, this, url);
-}
-
-void QAndroidMetaDataReaderControl::updateData(const QVariantMap &metadata, const QUrl &url)
-{
- const QMutexLocker l(&m_mtx);
-
- if (m_mediaContent.request().url() != url)
- return;
-
- const bool oldAvailable = m_available;
- m_metadata = metadata;
- m_available = !m_metadata.isEmpty();
-
- if (m_available != oldAvailable)
- Q_EMIT metaDataAvailableChanged(m_available);
-
- Q_EMIT metaDataChanged();
-}
-
-void QAndroidMetaDataReaderControl::extractMetadata(QAndroidMetaDataReaderControl *caller,
- const QUrl &url)
-{
- QVariantMap metadata;
-
- if (!url.isEmpty()) {
- AndroidMediaMetadataRetriever retriever;
- if (!retriever.setDataSource(url))
- return;
-
- QString mimeType = retriever.extractMetadata(AndroidMediaMetadataRetriever::MimeType);
- if (!mimeType.isNull())
- metadata.insert(QMediaMetaData::MediaType, mimeType);
-
- bool isVideo = !retriever.extractMetadata(AndroidMediaMetadataRetriever::HasVideo).isNull()
- || mimeType.startsWith(QStringLiteral("video"));
-
- QString string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Album);
- if (!string.isNull())
- metadata.insert(QMediaMetaData::AlbumTitle, string);
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::AlbumArtist);
- if (!string.isNull())
- metadata.insert(QMediaMetaData::AlbumArtist, string);
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Artist);
- if (!string.isNull()) {
- metadata.insert(isVideo ? QMediaMetaData::LeadPerformer
- : QMediaMetaData::ContributingArtist,
- string.split('/', Qt::SkipEmptyParts));
- }
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Author);
- if (!string.isNull())
- metadata.insert(QMediaMetaData::Author, string.split('/', Qt::SkipEmptyParts));
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Bitrate);
- if (!string.isNull()) {
- metadata.insert(isVideo ? QMediaMetaData::VideoBitRate
- : QMediaMetaData::AudioBitRate,
- string.toInt());
- }
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::CDTrackNumber);
- if (!string.isNull())
- metadata.insert(QMediaMetaData::TrackNumber, string.toInt());
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Composer);
- if (!string.isNull())
- metadata.insert(QMediaMetaData::Composer, string.split('/', Qt::SkipEmptyParts));
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Date);
- if (!string.isNull())
- metadata.insert(QMediaMetaData::Date, QDateTime::fromString(string, QStringLiteral("yyyyMMddTHHmmss.zzzZ")).date());
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Duration);
- if (!string.isNull())
- metadata.insert(QMediaMetaData::Duration, string.toLongLong());
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Genre);
- if (!string.isNull()) {
- // The genre can be returned as an ID3v2 id, get the name for it in that case
- if (string.startsWith('(') && string.endsWith(')')) {
- bool ok = false;
- const int genreId = QStringView{string}.mid(1, string.length() - 2).toInt(&ok);
- if (ok && genreId >= 0 && genreId <= 125)
- string = QLatin1String(qt_ID3GenreNames[genreId]);
- }
- metadata.insert(QMediaMetaData::Genre, string);
- }
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Title);
- if (!string.isNull())
- metadata.insert(QMediaMetaData::Title, string);
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::VideoHeight);
- if (!string.isNull()) {
- const int height = string.toInt();
- const int width = retriever.extractMetadata(AndroidMediaMetadataRetriever::VideoWidth).toInt();
- metadata.insert(QMediaMetaData::Resolution, QSize(width, height));
- }
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Writer);
- if (!string.isNull())
- metadata.insert(QMediaMetaData::Writer, string.split('/', Qt::SkipEmptyParts));
-
- string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Year);
- if (!string.isNull())
- metadata.insert(QMediaMetaData::Year, string.toInt());
- }
-
- const QMutexLocker lock(g_metaDataReadersMtx);
- if (!g_metaDataReaders->contains(caller))
- return;
-
- caller->updateData(metadata, url);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.h b/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.h
deleted file mode 100644
index f2b1b47f1..000000000
--- a/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDMETADATAREADERCONTROL_H
-#define QANDROIDMETADATAREADERCONTROL_H
-
-#include <QMetaDataReaderControl>
-#include <qmediacontent.h>
-#include <QMutex>
-
-QT_BEGIN_NAMESPACE
-
-class AndroidMediaMetadataRetriever;
-
-class QAndroidMetaDataReaderControl : public QMetaDataReaderControl
-{
- Q_OBJECT
-public:
- explicit QAndroidMetaDataReaderControl(QObject *parent = 0);
- ~QAndroidMetaDataReaderControl() override;
-
- bool isMetaDataAvailable() const override;
-
- QVariant metaData(const QString &key) const override;
- QStringList availableMetaData() const override;
-
-public Q_SLOTS:
- void onMediaChanged(const QMediaContent &media);
- void onUpdateMetaData();
-
-private:
- void updateData(const QVariantMap &metadata, const QUrl &url);
- static void extractMetadata(QAndroidMetaDataReaderControl *caller, const QUrl &url);
-
- mutable QMutex m_mtx;
- QMediaContent m_mediaContent;
- bool m_available;
- QVariantMap m_metadata;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDMETADATAREADERCONTROL_H
diff --git a/src/plugins/android/src/qandroidmediaserviceplugin.cpp b/src/plugins/android/src/qandroidmediaserviceplugin.cpp
deleted file mode 100644
index a66b85f98..000000000
--- a/src/plugins/android/src/qandroidmediaserviceplugin.cpp
+++ /dev/null
@@ -1,184 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qandroidmediaserviceplugin.h"
-
-#include "qandroidmediaservice.h"
-#include "qandroidcaptureservice.h"
-#include "qandroidaudioinputselectorcontrol.h"
-#include "qandroidcamerainfocontrol.h"
-#include "qandroidcamerasession.h"
-#include "androidmediaplayer.h"
-#include "androidsurfacetexture.h"
-#include "androidcamera.h"
-#include "androidmultimediautils.h"
-#include "androidmediarecorder.h"
-#include "androidsurfaceview.h"
-#include "qandroidglobal.h"
-
-QT_BEGIN_NAMESPACE
-
-Q_LOGGING_CATEGORY(qtAndroidMediaPlugin, "qt.multimedia.plugins.android")
-
-QAndroidMediaServicePlugin::QAndroidMediaServicePlugin()
-{
-}
-
-QAndroidMediaServicePlugin::~QAndroidMediaServicePlugin()
-{
-}
-
-QMediaService *QAndroidMediaServicePlugin::create(const QString &key)
-{
- if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER))
- return new QAndroidMediaService;
-
- if (key == QLatin1String(Q_MEDIASERVICE_CAMERA)
- || key == QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE)) {
- return new QAndroidCaptureService(key);
- }
-
- qCWarning(qtAndroidMediaPlugin) << "Android service plugin: unsupported key:" << key;
- return 0;
-}
-
-void QAndroidMediaServicePlugin::release(QMediaService *service)
-{
- delete service;
-}
-
-QMediaServiceProviderHint::Features QAndroidMediaServicePlugin::supportedFeatures(const QByteArray &service) const
-{
- if (service == Q_MEDIASERVICE_MEDIAPLAYER)
- return QMediaServiceProviderHint::VideoSurface;
-
- if (service == Q_MEDIASERVICE_CAMERA)
- return QMediaServiceProviderHint::VideoSurface | QMediaServiceProviderHint::RecordingSupport;
-
- if (service == Q_MEDIASERVICE_AUDIOSOURCE)
- return QMediaServiceProviderHint::RecordingSupport;
-
- return QMediaServiceProviderHint::Features();
-}
-
-QByteArray QAndroidMediaServicePlugin::defaultDevice(const QByteArray &service) const
-{
- if (service == Q_MEDIASERVICE_CAMERA && !QAndroidCameraSession::availableCameras().isEmpty())
- return QAndroidCameraSession::availableCameras().first().name;
-
- return QByteArray();
-}
-
-QList<QByteArray> QAndroidMediaServicePlugin::devices(const QByteArray &service) const
-{
- if (service == Q_MEDIASERVICE_CAMERA) {
- QList<QByteArray> devices;
- const QList<AndroidCameraInfo> &cameras = QAndroidCameraSession::availableCameras();
- for (int i = 0; i < cameras.count(); ++i)
- devices.append(cameras.at(i).name);
- return devices;
- }
-
- if (service == Q_MEDIASERVICE_AUDIOSOURCE)
- return QAndroidAudioInputSelectorControl::availableDevices();
-
- return QList<QByteArray>();
-}
-
-QString QAndroidMediaServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
-{
- if (service == Q_MEDIASERVICE_CAMERA) {
- const QList<AndroidCameraInfo> &cameras = QAndroidCameraSession::availableCameras();
- for (int i = 0; i < cameras.count(); ++i) {
- const AndroidCameraInfo &info = cameras.at(i);
- if (info.name == device)
- return info.description;
- }
- }
-
- if (service == Q_MEDIASERVICE_AUDIOSOURCE)
- return QAndroidAudioInputSelectorControl::availableDeviceDescription(device);
-
- return QString();
-}
-
-QCamera::Position QAndroidMediaServicePlugin::cameraPosition(const QByteArray &device) const
-{
- return QAndroidCameraInfoControl::position(device);
-}
-
-int QAndroidMediaServicePlugin::cameraOrientation(const QByteArray &device) const
-{
- return QAndroidCameraInfoControl::orientation(device);
-}
-
-QT_END_NAMESPACE
-
-Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
-{
- static bool initialized = false;
- if (initialized)
- return JNI_VERSION_1_6;
- initialized = true;
-
- QT_USE_NAMESPACE
- typedef union {
- JNIEnv *nativeEnvironment;
- void *venv;
- } UnionJNIEnvToVoid;
-
- UnionJNIEnvToVoid uenv;
- uenv.venv = NULL;
-
- if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_6) != JNI_OK)
- return JNI_ERR;
-
- JNIEnv *jniEnv = uenv.nativeEnvironment;
-
- if (!AndroidMediaPlayer::initJNI(jniEnv) ||
- !AndroidCamera::initJNI(jniEnv) ||
- !AndroidMediaRecorder::initJNI(jniEnv) ||
- !AndroidSurfaceHolder::initJNI(jniEnv)) {
- return JNI_ERR;
- }
-
- AndroidSurfaceTexture::initJNI(jniEnv);
-
- return JNI_VERSION_1_6;
-}
diff --git a/src/plugins/android/src/qandroidmediaserviceplugin.h b/src/plugins/android/src/qandroidmediaserviceplugin.h
deleted file mode 100644
index 3ae1a36b6..000000000
--- a/src/plugins/android/src/qandroidmediaserviceplugin.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QANDROIDMEDIASERVICEPLUGIN_H
-#define QANDROIDMEDIASERVICEPLUGIN_H
-
-#include <QMediaServiceProviderPlugin>
-
-QT_BEGIN_NAMESPACE
-
-class QAndroidMediaServicePlugin
- : public QMediaServiceProviderPlugin
- , public QMediaServiceSupportedDevicesInterface
- , public QMediaServiceDefaultDeviceInterface
- , public QMediaServiceCameraInfoInterface
- , public QMediaServiceFeaturesInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
- Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
- Q_INTERFACES(QMediaServiceCameraInfoInterface)
- Q_INTERFACES(QMediaServiceFeaturesInterface)
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0"
- FILE "android_mediaservice.json")
-
-public:
- QAndroidMediaServicePlugin();
- ~QAndroidMediaServicePlugin();
-
- QMediaService* create(QString const& key) override;
- void release(QMediaService *service) override;
-
- QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const override;
-
- QByteArray defaultDevice(const QByteArray &service) const override;
- QList<QByteArray> devices(const QByteArray &service) const override;
- QString deviceDescription(const QByteArray &service, const QByteArray &device) override;
-
- QCamera::Position cameraPosition(const QByteArray &device) const override;
- int cameraOrientation(const QByteArray &device) const override;
-};
-
-QT_END_NAMESPACE
-
-#endif // QANDROIDMEDIASERVICEPLUGIN_H
diff --git a/src/plugins/android/src/src.pro b/src/plugins/android/src/src.pro
deleted file mode 100644
index 5e47a7d09..000000000
--- a/src/plugins/android/src/src.pro
+++ /dev/null
@@ -1,20 +0,0 @@
-TARGET = qtmedia_android
-
-QT += opengl multimedia-private core-private network
-
-HEADERS += \
- qandroidmediaserviceplugin.h
-
-SOURCES += \
- qandroidmediaserviceplugin.cpp
-
-include (wrappers/jni/jni.pri)
-include (common/common.pri)
-include (mediaplayer/mediaplayer.pri)
-include (mediacapture/mediacapture.pri)
-
-OTHER_FILES += android_mediaservice.json
-
-PLUGIN_TYPE = mediaservice
-PLUGIN_CLASS_NAME = QAndroidMediaServicePlugin
-load(qt_plugin)
diff --git a/src/plugins/android/src/wrappers/jni/androidcamera.cpp b/src/plugins/android/src/wrappers/jni/androidcamera.cpp
deleted file mode 100644
index 33e819d78..000000000
--- a/src/plugins/android/src/wrappers/jni/androidcamera.cpp
+++ /dev/null
@@ -1,1712 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Ruslan Baratov
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "androidcamera.h"
-#include "androidsurfacetexture.h"
-#include "androidsurfaceview.h"
-#include "qandroidmultimediautils.h"
-#include "qandroidglobal.h"
-
-#include <qstringlist.h>
-#include <qdebug.h>
-#include <QtCore/private/qjnihelpers_p.h>
-#include <QtCore/qthread.h>
-#include <QtCore/qreadwritelock.h>
-#include <QtCore/qmutex.h>
-#include <QtMultimedia/private/qmemoryvideobuffer_p.h>
-
-#include <mutex>
-
-QT_BEGIN_NAMESPACE
-
-static const char QtCameraListenerClassName[] = "org/qtproject/qt/android/multimedia/QtCameraListener";
-
-typedef QHash<int, AndroidCamera *> CameraMap;
-Q_GLOBAL_STATIC(CameraMap, cameras)
-Q_GLOBAL_STATIC(QReadWriteLock, rwLock)
-
-static inline bool exceptionCheckAndClear(JNIEnv *env)
-{
- if (Q_UNLIKELY(env->ExceptionCheck())) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif // QT_DEBUG
- env->ExceptionClear();
- return true;
- }
-
- return false;
-}
-
-static QRect areaToRect(jobject areaObj)
-{
- QJNIObjectPrivate area(areaObj);
- QJNIObjectPrivate rect = area.getObjectField("rect", "Landroid/graphics/Rect;");
-
- return QRect(rect.getField<jint>("left"),
- rect.getField<jint>("top"),
- rect.callMethod<jint>("width"),
- rect.callMethod<jint>("height"));
-}
-
-static QJNIObjectPrivate rectToArea(const QRect &rect)
-{
- QJNIObjectPrivate jrect("android/graphics/Rect",
- "(IIII)V",
- rect.left(), rect.top(), rect.right(), rect.bottom());
-
- QJNIObjectPrivate area("android/hardware/Camera$Area",
- "(Landroid/graphics/Rect;I)V",
- jrect.object(), 500);
-
- return area;
-}
-
-// native method for QtCameraLisener.java
-static void notifyAutoFocusComplete(JNIEnv* , jobject, int id, jboolean success)
-{
- QReadLocker locker(rwLock);
- const auto it = cameras->constFind(id);
- if (Q_UNLIKELY(it == cameras->cend()))
- return;
-
- Q_EMIT (*it)->autoFocusComplete(success);
-}
-
-static void notifyPictureExposed(JNIEnv* , jobject, int id)
-{
- QReadLocker locker(rwLock);
- const auto it = cameras->constFind(id);
- if (Q_UNLIKELY(it == cameras->cend()))
- return;
-
- Q_EMIT (*it)->pictureExposed();
-}
-
-static void notifyPictureCaptured(JNIEnv *env, jobject, int id, jbyteArray data)
-{
- QReadLocker locker(rwLock);
- const auto it = cameras->constFind(id);
- if (Q_UNLIKELY(it == cameras->cend()))
- return;
-
- const int arrayLength = env->GetArrayLength(data);
- QByteArray bytes(arrayLength, Qt::Uninitialized);
- env->GetByteArrayRegion(data, 0, arrayLength, (jbyte*)bytes.data());
- Q_EMIT (*it)->pictureCaptured(bytes);
-}
-
-static void notifyNewPreviewFrame(JNIEnv *env, jobject, int id, jbyteArray data,
- int width, int height, int format, int bpl)
-{
- QReadLocker locker(rwLock);
- const auto it = cameras->constFind(id);
- if (Q_UNLIKELY(it == cameras->cend()))
- return;
-
- const int arrayLength = env->GetArrayLength(data);
- if (arrayLength == 0)
- return;
-
- QByteArray bytes(arrayLength, Qt::Uninitialized);
- env->GetByteArrayRegion(data, 0, arrayLength, (jbyte*)bytes.data());
-
- QVideoFrame frame(new QMemoryVideoBuffer(bytes, bpl),
- QSize(width, height),
- qt_pixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat(format)));
-
- Q_EMIT (*it)->newPreviewFrame(frame);
-}
-
-static void notifyFrameAvailable(JNIEnv *, jobject, int id)
-{
- QReadLocker locker(rwLock);
- const auto it = cameras->constFind(id);
- if (Q_UNLIKELY(it == cameras->cend()))
- return;
-
- (*it)->fetchLastPreviewFrame();
-}
-
-class AndroidCameraPrivate : public QObject
-{
- Q_OBJECT
-public:
- AndroidCameraPrivate();
- ~AndroidCameraPrivate();
-
- Q_INVOKABLE bool init(int cameraId);
-
- Q_INVOKABLE void release();
- Q_INVOKABLE bool lock();
- Q_INVOKABLE bool unlock();
- Q_INVOKABLE bool reconnect();
-
- Q_INVOKABLE AndroidCamera::CameraFacing getFacing();
- Q_INVOKABLE int getNativeOrientation();
-
- Q_INVOKABLE QSize getPreferredPreviewSizeForVideo();
- Q_INVOKABLE QList<QSize> getSupportedPreviewSizes();
-
- Q_INVOKABLE QList<AndroidCamera::FpsRange> getSupportedPreviewFpsRange();
-
- Q_INVOKABLE AndroidCamera::FpsRange getPreviewFpsRange();
- Q_INVOKABLE void setPreviewFpsRange(int min, int max);
-
- Q_INVOKABLE AndroidCamera::ImageFormat getPreviewFormat();
- Q_INVOKABLE void setPreviewFormat(AndroidCamera::ImageFormat fmt);
- Q_INVOKABLE QList<AndroidCamera::ImageFormat> getSupportedPreviewFormats();
-
- Q_INVOKABLE QSize previewSize() const { return m_previewSize; }
- Q_INVOKABLE QSize getPreviewSize();
- Q_INVOKABLE void updatePreviewSize();
- Q_INVOKABLE bool setPreviewTexture(void *surfaceTexture);
- Q_INVOKABLE bool setPreviewDisplay(void *surfaceHolder);
- Q_INVOKABLE void setDisplayOrientation(int degrees);
-
- Q_INVOKABLE bool isZoomSupported();
- Q_INVOKABLE int getMaxZoom();
- Q_INVOKABLE QList<int> getZoomRatios();
- Q_INVOKABLE int getZoom();
- Q_INVOKABLE void setZoom(int value);
-
- Q_INVOKABLE QString getFlashMode();
- Q_INVOKABLE void setFlashMode(const QString &value);
-
- Q_INVOKABLE QString getFocusMode();
- Q_INVOKABLE void setFocusMode(const QString &value);
-
- Q_INVOKABLE int getMaxNumFocusAreas();
- Q_INVOKABLE QList<QRect> getFocusAreas();
- Q_INVOKABLE void setFocusAreas(const QList<QRect> &areas);
-
- Q_INVOKABLE void autoFocus();
- Q_INVOKABLE void cancelAutoFocus();
-
- Q_INVOKABLE bool isAutoExposureLockSupported();
- Q_INVOKABLE bool getAutoExposureLock();
- Q_INVOKABLE void setAutoExposureLock(bool toggle);
-
- Q_INVOKABLE bool isAutoWhiteBalanceLockSupported();
- Q_INVOKABLE bool getAutoWhiteBalanceLock();
- Q_INVOKABLE void setAutoWhiteBalanceLock(bool toggle);
-
- Q_INVOKABLE int getExposureCompensation();
- Q_INVOKABLE void setExposureCompensation(int value);
- Q_INVOKABLE float getExposureCompensationStep();
- Q_INVOKABLE int getMinExposureCompensation();
- Q_INVOKABLE int getMaxExposureCompensation();
-
- Q_INVOKABLE QString getSceneMode();
- Q_INVOKABLE void setSceneMode(const QString &value);
-
- Q_INVOKABLE QString getWhiteBalance();
- Q_INVOKABLE void setWhiteBalance(const QString &value);
-
- Q_INVOKABLE void updateRotation();
-
- Q_INVOKABLE QList<QSize> getSupportedPictureSizes();
- Q_INVOKABLE void setPictureSize(const QSize &size);
- Q_INVOKABLE void setJpegQuality(int quality);
-
- Q_INVOKABLE void startPreview();
- Q_INVOKABLE void stopPreview();
-
- Q_INVOKABLE void takePicture();
-
- Q_INVOKABLE void setupPreviewFrameCallback();
- Q_INVOKABLE void notifyNewFrames(bool notify);
- Q_INVOKABLE void fetchLastPreviewFrame();
-
- Q_INVOKABLE void applyParameters();
-
- Q_INVOKABLE QStringList callParametersStringListMethod(const QByteArray &methodName);
-
- int m_cameraId;
- QRecursiveMutex m_parametersMutex;
- QSize m_previewSize;
- int m_rotation;
- QJNIObjectPrivate m_info;
- QJNIObjectPrivate m_parameters;
- QJNIObjectPrivate m_camera;
- QJNIObjectPrivate m_cameraListener;
-
-Q_SIGNALS:
- void previewSizeChanged();
- void previewStarted();
- void previewFailedToStart();
- void previewStopped();
-
- void autoFocusStarted();
-
- void whiteBalanceChanged();
-
- void takePictureFailed();
-
- void lastPreviewFrameFetched(const QVideoFrame &frame);
-};
-
-AndroidCamera::AndroidCamera(AndroidCameraPrivate *d, QThread *worker)
- : QObject(),
- d_ptr(d),
- m_worker(worker)
-
-{
- qRegisterMetaType<QList<int> >();
- qRegisterMetaType<QList<QSize> >();
- qRegisterMetaType<QList<QRect> >();
- qRegisterMetaType<ImageFormat>();
-
- connect(d, &AndroidCameraPrivate::previewSizeChanged, this, &AndroidCamera::previewSizeChanged);
- connect(d, &AndroidCameraPrivate::previewStarted, this, &AndroidCamera::previewStarted);
- connect(d, &AndroidCameraPrivate::previewFailedToStart, this, &AndroidCamera::previewFailedToStart);
- connect(d, &AndroidCameraPrivate::previewStopped, this, &AndroidCamera::previewStopped);
- connect(d, &AndroidCameraPrivate::autoFocusStarted, this, &AndroidCamera::autoFocusStarted);
- connect(d, &AndroidCameraPrivate::whiteBalanceChanged, this, &AndroidCamera::whiteBalanceChanged);
- connect(d, &AndroidCameraPrivate::takePictureFailed, this, &AndroidCamera::takePictureFailed);
- connect(d, &AndroidCameraPrivate::lastPreviewFrameFetched, this, &AndroidCamera::lastPreviewFrameFetched);
-}
-
-AndroidCamera::~AndroidCamera()
-{
- Q_D(AndroidCamera);
- if (d->m_camera.isValid()) {
- release();
- QWriteLocker locker(rwLock);
- cameras->remove(cameraId());
- }
-
- m_worker->exit();
- m_worker->wait(5000);
-}
-
-AndroidCamera *AndroidCamera::open(int cameraId)
-{
- if (!qt_androidRequestCameraPermission())
- return nullptr;
-
- AndroidCameraPrivate *d = new AndroidCameraPrivate();
- QThread *worker = new QThread;
- worker->start();
- d->moveToThread(worker);
- connect(worker, &QThread::finished, d, &AndroidCameraPrivate::deleteLater);
- bool ok = true;
- QMetaObject::invokeMethod(d, "init", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, ok), Q_ARG(int, cameraId));
- if (!ok) {
- worker->quit();
- worker->wait(5000);
- delete worker;
- return 0;
- }
-
- AndroidCamera *q = new AndroidCamera(d, worker);
- QWriteLocker locker(rwLock);
- cameras->insert(cameraId, q);
-
- return q;
-}
-
-int AndroidCamera::cameraId() const
-{
- Q_D(const AndroidCamera);
- return d->m_cameraId;
-}
-
-bool AndroidCamera::lock()
-{
- Q_D(AndroidCamera);
- bool ok = true;
- QMetaObject::invokeMethod(d, "lock", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, ok));
- return ok;
-}
-
-bool AndroidCamera::unlock()
-{
- Q_D(AndroidCamera);
- bool ok = true;
- QMetaObject::invokeMethod(d, "unlock", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, ok));
- return ok;
-}
-
-bool AndroidCamera::reconnect()
-{
- Q_D(AndroidCamera);
- bool ok = true;
- QMetaObject::invokeMethod(d, "reconnect", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, ok));
- return ok;
-}
-
-void AndroidCamera::release()
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "release", Qt::BlockingQueuedConnection);
-}
-
-AndroidCamera::CameraFacing AndroidCamera::getFacing()
-{
- Q_D(AndroidCamera);
- return d->getFacing();
-}
-
-int AndroidCamera::getNativeOrientation()
-{
- Q_D(AndroidCamera);
- return d->getNativeOrientation();
-}
-
-QSize AndroidCamera::getPreferredPreviewSizeForVideo()
-{
- Q_D(AndroidCamera);
- return d->getPreferredPreviewSizeForVideo();
-}
-
-QList<QSize> AndroidCamera::getSupportedPreviewSizes()
-{
- Q_D(AndroidCamera);
- return d->getSupportedPreviewSizes();
-}
-
-QList<AndroidCamera::FpsRange> AndroidCamera::getSupportedPreviewFpsRange()
-{
- Q_D(AndroidCamera);
- return d->getSupportedPreviewFpsRange();
-}
-
-AndroidCamera::FpsRange AndroidCamera::getPreviewFpsRange()
-{
- Q_D(AndroidCamera);
- return d->getPreviewFpsRange();
-}
-
-void AndroidCamera::setPreviewFpsRange(FpsRange range)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setPreviewFpsRange", Q_ARG(int, range.min), Q_ARG(int, range.max));
-}
-
-AndroidCamera::ImageFormat AndroidCamera::getPreviewFormat()
-{
- Q_D(AndroidCamera);
- return d->getPreviewFormat();
-}
-
-void AndroidCamera::setPreviewFormat(ImageFormat fmt)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setPreviewFormat", Q_ARG(AndroidCamera::ImageFormat, fmt));
-}
-
-QList<AndroidCamera::ImageFormat> AndroidCamera::getSupportedPreviewFormats()
-{
- Q_D(AndroidCamera);
- return d->getSupportedPreviewFormats();
-}
-
-QSize AndroidCamera::previewSize() const
-{
- Q_D(const AndroidCamera);
- return d->m_previewSize;
-}
-
-QSize AndroidCamera::actualPreviewSize()
-{
- Q_D(AndroidCamera);
- return d->getPreviewSize();
-}
-
-void AndroidCamera::setPreviewSize(const QSize &size)
-{
- Q_D(AndroidCamera);
- d->m_parametersMutex.lock();
- bool areParametersValid = d->m_parameters.isValid();
- d->m_parametersMutex.unlock();
- if (!areParametersValid)
- return;
-
- d->m_previewSize = size;
- QMetaObject::invokeMethod(d, "updatePreviewSize");
-}
-
-bool AndroidCamera::setPreviewTexture(AndroidSurfaceTexture *surfaceTexture)
-{
- Q_D(AndroidCamera);
- bool ok = true;
- QMetaObject::invokeMethod(d,
- "setPreviewTexture",
- Qt::BlockingQueuedConnection,
- Q_RETURN_ARG(bool, ok),
- Q_ARG(void *, surfaceTexture ? surfaceTexture->surfaceTexture() : 0));
- return ok;
-}
-
-bool AndroidCamera::setPreviewDisplay(AndroidSurfaceHolder *surfaceHolder)
-{
- Q_D(AndroidCamera);
- bool ok = true;
- QMetaObject::invokeMethod(d,
- "setPreviewDisplay",
- Qt::BlockingQueuedConnection,
- Q_RETURN_ARG(bool, ok),
- Q_ARG(void *, surfaceHolder ? surfaceHolder->surfaceHolder() : 0));
- return ok;
-}
-
-void AndroidCamera::setDisplayOrientation(int degrees)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setDisplayOrientation", Qt::QueuedConnection, Q_ARG(int, degrees));
-}
-
-bool AndroidCamera::isZoomSupported()
-{
- Q_D(AndroidCamera);
- return d->isZoomSupported();
-}
-
-int AndroidCamera::getMaxZoom()
-{
- Q_D(AndroidCamera);
- return d->getMaxZoom();
-}
-
-QList<int> AndroidCamera::getZoomRatios()
-{
- Q_D(AndroidCamera);
- return d->getZoomRatios();
-}
-
-int AndroidCamera::getZoom()
-{
- Q_D(AndroidCamera);
- return d->getZoom();
-}
-
-void AndroidCamera::setZoom(int value)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setZoom", Q_ARG(int, value));
-}
-
-QStringList AndroidCamera::getSupportedFlashModes()
-{
- Q_D(AndroidCamera);
- return d->callParametersStringListMethod("getSupportedFlashModes");
-}
-
-QString AndroidCamera::getFlashMode()
-{
- Q_D(AndroidCamera);
- return d->getFlashMode();
-}
-
-void AndroidCamera::setFlashMode(const QString &value)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setFlashMode", Q_ARG(QString, value));
-}
-
-QStringList AndroidCamera::getSupportedFocusModes()
-{
- Q_D(AndroidCamera);
- return d->callParametersStringListMethod("getSupportedFocusModes");
-}
-
-QString AndroidCamera::getFocusMode()
-{
- Q_D(AndroidCamera);
- return d->getFocusMode();
-}
-
-void AndroidCamera::setFocusMode(const QString &value)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setFocusMode", Q_ARG(QString, value));
-}
-
-int AndroidCamera::getMaxNumFocusAreas()
-{
- Q_D(AndroidCamera);
- return d->getMaxNumFocusAreas();
-}
-
-QList<QRect> AndroidCamera::getFocusAreas()
-{
- Q_D(AndroidCamera);
- return d->getFocusAreas();
-}
-
-void AndroidCamera::setFocusAreas(const QList<QRect> &areas)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setFocusAreas", Q_ARG(QList<QRect>, areas));
-}
-
-void AndroidCamera::autoFocus()
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "autoFocus");
-}
-
-void AndroidCamera::cancelAutoFocus()
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "cancelAutoFocus", Qt::QueuedConnection);
-}
-
-bool AndroidCamera::isAutoExposureLockSupported()
-{
- Q_D(AndroidCamera);
- return d->isAutoExposureLockSupported();
-}
-
-bool AndroidCamera::getAutoExposureLock()
-{
- Q_D(AndroidCamera);
- return d->getAutoExposureLock();
-}
-
-void AndroidCamera::setAutoExposureLock(bool toggle)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setAutoExposureLock", Q_ARG(bool, toggle));
-}
-
-bool AndroidCamera::isAutoWhiteBalanceLockSupported()
-{
- Q_D(AndroidCamera);
- return d->isAutoWhiteBalanceLockSupported();
-}
-
-bool AndroidCamera::getAutoWhiteBalanceLock()
-{
- Q_D(AndroidCamera);
- return d->getAutoWhiteBalanceLock();
-}
-
-void AndroidCamera::setAutoWhiteBalanceLock(bool toggle)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setAutoWhiteBalanceLock", Q_ARG(bool, toggle));
-}
-
-int AndroidCamera::getExposureCompensation()
-{
- Q_D(AndroidCamera);
- return d->getExposureCompensation();
-}
-
-void AndroidCamera::setExposureCompensation(int value)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setExposureCompensation", Q_ARG(int, value));
-}
-
-float AndroidCamera::getExposureCompensationStep()
-{
- Q_D(AndroidCamera);
- return d->getExposureCompensationStep();
-}
-
-int AndroidCamera::getMinExposureCompensation()
-{
- Q_D(AndroidCamera);
- return d->getMinExposureCompensation();
-}
-
-int AndroidCamera::getMaxExposureCompensation()
-{
- Q_D(AndroidCamera);
- return d->getMaxExposureCompensation();
-}
-
-QStringList AndroidCamera::getSupportedSceneModes()
-{
- Q_D(AndroidCamera);
- return d->callParametersStringListMethod("getSupportedSceneModes");
-}
-
-QString AndroidCamera::getSceneMode()
-{
- Q_D(AndroidCamera);
- return d->getSceneMode();
-}
-
-void AndroidCamera::setSceneMode(const QString &value)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setSceneMode", Q_ARG(QString, value));
-}
-
-QStringList AndroidCamera::getSupportedWhiteBalance()
-{
- Q_D(AndroidCamera);
- return d->callParametersStringListMethod("getSupportedWhiteBalance");
-}
-
-QString AndroidCamera::getWhiteBalance()
-{
- Q_D(AndroidCamera);
- return d->getWhiteBalance();
-}
-
-void AndroidCamera::setWhiteBalance(const QString &value)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setWhiteBalance", Q_ARG(QString, value));
-}
-
-void AndroidCamera::setRotation(int rotation)
-{
- Q_D(AndroidCamera);
- //We need to do it here and not in worker class because we cache rotation
- d->m_parametersMutex.lock();
- bool areParametersValid = d->m_parameters.isValid();
- d->m_parametersMutex.unlock();
- if (!areParametersValid)
- return;
-
- d->m_rotation = rotation;
- QMetaObject::invokeMethod(d, "updateRotation");
-}
-
-int AndroidCamera::getRotation() const
-{
- Q_D(const AndroidCamera);
- return d->m_rotation;
-}
-
-QList<QSize> AndroidCamera::getSupportedPictureSizes()
-{
- Q_D(AndroidCamera);
- return d->getSupportedPictureSizes();
-}
-
-void AndroidCamera::setPictureSize(const QSize &size)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setPictureSize", Q_ARG(QSize, size));
-}
-
-void AndroidCamera::setJpegQuality(int quality)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setJpegQuality", Q_ARG(int, quality));
-}
-
-void AndroidCamera::takePicture()
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "takePicture", Qt::BlockingQueuedConnection);
-}
-
-void AndroidCamera::setupPreviewFrameCallback()
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "setupPreviewFrameCallback");
-}
-
-void AndroidCamera::notifyNewFrames(bool notify)
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "notifyNewFrames", Q_ARG(bool, notify));
-}
-
-void AndroidCamera::fetchLastPreviewFrame()
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "fetchLastPreviewFrame");
-}
-
-QJNIObjectPrivate AndroidCamera::getCameraObject()
-{
- Q_D(AndroidCamera);
- return d->m_camera;
-}
-
-int AndroidCamera::getNumberOfCameras()
-{
- if (!qt_androidRequestCameraPermission())
- return 0;
-
- return QJNIObjectPrivate::callStaticMethod<jint>("android/hardware/Camera",
- "getNumberOfCameras");
-}
-
-void AndroidCamera::getCameraInfo(int id, AndroidCameraInfo *info)
-{
- Q_ASSERT(info);
-
- QJNIObjectPrivate cameraInfo("android/hardware/Camera$CameraInfo");
- QJNIObjectPrivate::callStaticMethod<void>("android/hardware/Camera",
- "getCameraInfo",
- "(ILandroid/hardware/Camera$CameraInfo;)V",
- id, cameraInfo.object());
-
- AndroidCamera::CameraFacing facing = AndroidCamera::CameraFacing(cameraInfo.getField<jint>("facing"));
- // The orientation provided by Android is counter-clockwise, we need it clockwise
- info->orientation = (360 - cameraInfo.getField<jint>("orientation")) % 360;
-
- switch (facing) {
- case AndroidCamera::CameraFacingBack:
- info->name = QByteArray("back");
- info->description = QStringLiteral("Rear-facing camera");
- info->position = QCamera::BackFace;
- break;
- case AndroidCamera::CameraFacingFront:
- info->name = QByteArray("front");
- info->description = QStringLiteral("Front-facing camera");
- info->position = QCamera::FrontFace;
- break;
- default:
- break;
- }
-}
-
-void AndroidCamera::startPreview()
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "startPreview");
-}
-
-void AndroidCamera::stopPreview()
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "stopPreview");
-}
-
-void AndroidCamera::stopPreviewSynchronous()
-{
- Q_D(AndroidCamera);
- QMetaObject::invokeMethod(d, "stopPreview", Qt::BlockingQueuedConnection);
-}
-
-AndroidCameraPrivate::AndroidCameraPrivate()
- : QObject()
-{
-}
-
-AndroidCameraPrivate::~AndroidCameraPrivate()
-{
-}
-
-static qint32 s_activeCameras = 0;
-
-bool AndroidCameraPrivate::init(int cameraId)
-{
- m_cameraId = cameraId;
- QJNIEnvironmentPrivate env;
-
- const bool opened = s_activeCameras & (1 << cameraId);
- if (opened)
- return false;
-
- m_camera = QJNIObjectPrivate::callStaticObjectMethod("android/hardware/Camera",
- "open",
- "(I)Landroid/hardware/Camera;",
- cameraId);
- if (exceptionCheckAndClear(env) || !m_camera.isValid())
- return false;
-
- m_cameraListener = QJNIObjectPrivate(QtCameraListenerClassName, "(I)V", m_cameraId);
- m_info = QJNIObjectPrivate("android/hardware/Camera$CameraInfo");
- m_camera.callStaticMethod<void>("android/hardware/Camera",
- "getCameraInfo",
- "(ILandroid/hardware/Camera$CameraInfo;)V",
- cameraId,
- m_info.object());
-
- QJNIObjectPrivate params = m_camera.callObjectMethod("getParameters",
- "()Landroid/hardware/Camera$Parameters;");
- m_parameters = QJNIObjectPrivate(params);
- s_activeCameras |= 1 << cameraId;
-
- return true;
-}
-
-void AndroidCameraPrivate::release()
-{
- m_previewSize = QSize();
- m_parametersMutex.lock();
- m_parameters = QJNIObjectPrivate();
- m_parametersMutex.unlock();
- if (m_camera.isValid()) {
- m_camera.callMethod<void>("release");
- s_activeCameras &= ~(1 << m_cameraId);
- }
-}
-
-bool AndroidCameraPrivate::lock()
-{
- QJNIEnvironmentPrivate env;
- m_camera.callMethod<void>("lock");
- return !exceptionCheckAndClear(env);
-}
-
-bool AndroidCameraPrivate::unlock()
-{
- QJNIEnvironmentPrivate env;
- m_camera.callMethod<void>("unlock");
- return !exceptionCheckAndClear(env);
-}
-
-bool AndroidCameraPrivate::reconnect()
-{
- QJNIEnvironmentPrivate env;
- m_camera.callMethod<void>("reconnect");
- return !exceptionCheckAndClear(env);
-}
-
-AndroidCamera::CameraFacing AndroidCameraPrivate::getFacing()
-{
- return AndroidCamera::CameraFacing(m_info.getField<jint>("facing"));
-}
-
-int AndroidCameraPrivate::getNativeOrientation()
-{
- return m_info.getField<jint>("orientation");
-}
-
-QSize AndroidCameraPrivate::getPreferredPreviewSizeForVideo()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return QSize();
-
- QJNIObjectPrivate size = m_parameters.callObjectMethod("getPreferredPreviewSizeForVideo",
- "()Landroid/hardware/Camera$Size;");
-
- if (!size.isValid())
- return QSize();
-
- return QSize(size.getField<jint>("width"), size.getField<jint>("height"));
-}
-
-QList<QSize> AndroidCameraPrivate::getSupportedPreviewSizes()
-{
- QList<QSize> list;
-
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (m_parameters.isValid()) {
- QJNIObjectPrivate sizeList = m_parameters.callObjectMethod("getSupportedPreviewSizes",
- "()Ljava/util/List;");
- int count = sizeList.callMethod<jint>("size");
- for (int i = 0; i < count; ++i) {
- QJNIObjectPrivate size = sizeList.callObjectMethod("get",
- "(I)Ljava/lang/Object;",
- i);
- list.append(QSize(size.getField<jint>("width"), size.getField<jint>("height")));
- }
-
- std::sort(list.begin(), list.end(), qt_sizeLessThan);
- }
-
- return list;
-}
-
-QList<AndroidCamera::FpsRange> AndroidCameraPrivate::getSupportedPreviewFpsRange()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- QJNIEnvironmentPrivate env;
-
- QList<AndroidCamera::FpsRange> rangeList;
-
- if (m_parameters.isValid()) {
- QJNIObjectPrivate rangeListNative = m_parameters.callObjectMethod("getSupportedPreviewFpsRange",
- "()Ljava/util/List;");
- int count = rangeListNative.callMethod<jint>("size");
-
- rangeList.reserve(count);
-
- for (int i = 0; i < count; ++i) {
- QJNIObjectPrivate range = rangeListNative.callObjectMethod("get",
- "(I)Ljava/lang/Object;",
- i);
-
- jintArray jRange = static_cast<jintArray>(range.object());
- jint* rangeArray = env->GetIntArrayElements(jRange, 0);
-
- AndroidCamera::FpsRange fpsRange;
-
- fpsRange.min = rangeArray[0];
- fpsRange.max = rangeArray[1];
-
- env->ReleaseIntArrayElements(jRange, rangeArray, 0);
-
- rangeList << fpsRange;
- }
- }
-
- return rangeList;
-}
-
-AndroidCamera::FpsRange AndroidCameraPrivate::getPreviewFpsRange()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- QJNIEnvironmentPrivate env;
-
- AndroidCamera::FpsRange range;
-
- if (!m_parameters.isValid())
- return range;
-
- jintArray jRangeArray = env->NewIntArray(2);
- m_parameters.callMethod<void>("getPreviewFpsRange", "([I)V", jRangeArray);
-
- jint* jRangeElements = env->GetIntArrayElements(jRangeArray, 0);
-
- range.min = jRangeElements[0];
- range.max = jRangeElements[1];
-
- env->ReleaseIntArrayElements(jRangeArray, jRangeElements, 0);
- env->DeleteLocalRef(jRangeArray);
-
- return range;
-}
-
-void AndroidCameraPrivate::setPreviewFpsRange(int min, int max)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- QJNIEnvironmentPrivate env;
- m_parameters.callMethod<void>("setPreviewFpsRange", "(II)V", min, max);
- exceptionCheckAndClear(env);
-}
-
-AndroidCamera::ImageFormat AndroidCameraPrivate::getPreviewFormat()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return AndroidCamera::UnknownImageFormat;
-
- return AndroidCamera::ImageFormat(m_parameters.callMethod<jint>("getPreviewFormat"));
-}
-
-void AndroidCameraPrivate::setPreviewFormat(AndroidCamera::ImageFormat fmt)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- m_parameters.callMethod<void>("setPreviewFormat", "(I)V", jint(fmt));
- applyParameters();
-}
-
-QList<AndroidCamera::ImageFormat> AndroidCameraPrivate::getSupportedPreviewFormats()
-{
- QList<AndroidCamera::ImageFormat> list;
-
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (m_parameters.isValid()) {
- QJNIObjectPrivate formatList = m_parameters.callObjectMethod("getSupportedPreviewFormats",
- "()Ljava/util/List;");
- int count = formatList.callMethod<jint>("size");
- for (int i = 0; i < count; ++i) {
- QJNIObjectPrivate format = formatList.callObjectMethod("get",
- "(I)Ljava/lang/Object;",
- i);
- list.append(AndroidCamera::ImageFormat(format.callMethod<jint>("intValue")));
- }
- }
-
- return list;
-}
-
-QSize AndroidCameraPrivate::getPreviewSize()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return QSize();
-
- QJNIObjectPrivate size = m_parameters.callObjectMethod("getPreviewSize",
- "()Landroid/hardware/Camera$Size;");
-
- if (!size.isValid())
- return QSize();
-
- return QSize(size.getField<jint>("width"), size.getField<jint>("height"));
-}
-
-void AndroidCameraPrivate::updatePreviewSize()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (m_previewSize.isValid()) {
- m_parameters.callMethod<void>("setPreviewSize", "(II)V", m_previewSize.width(), m_previewSize.height());
- applyParameters();
- }
-
- emit previewSizeChanged();
-}
-
-bool AndroidCameraPrivate::setPreviewTexture(void *surfaceTexture)
-{
- QJNIEnvironmentPrivate env;
- m_camera.callMethod<void>("setPreviewTexture",
- "(Landroid/graphics/SurfaceTexture;)V",
- static_cast<jobject>(surfaceTexture));
- return !exceptionCheckAndClear(env);
-}
-
-bool AndroidCameraPrivate::setPreviewDisplay(void *surfaceHolder)
-{
- QJNIEnvironmentPrivate env;
- m_camera.callMethod<void>("setPreviewDisplay",
- "(Landroid/view/SurfaceHolder;)V",
- static_cast<jobject>(surfaceHolder));
- return !exceptionCheckAndClear(env);
-}
-
-void AndroidCameraPrivate::setDisplayOrientation(int degrees)
-{
- m_camera.callMethod<void>("setDisplayOrientation", "(I)V", degrees);
-}
-
-bool AndroidCameraPrivate::isZoomSupported()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return false;
-
- return m_parameters.callMethod<jboolean>("isZoomSupported");
-}
-
-int AndroidCameraPrivate::getMaxZoom()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return 0;
-
- return m_parameters.callMethod<jint>("getMaxZoom");
-}
-
-QList<int> AndroidCameraPrivate::getZoomRatios()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- QList<int> ratios;
-
- if (m_parameters.isValid()) {
- QJNIObjectPrivate ratioList = m_parameters.callObjectMethod("getZoomRatios",
- "()Ljava/util/List;");
- int count = ratioList.callMethod<jint>("size");
- for (int i = 0; i < count; ++i) {
- QJNIObjectPrivate zoomRatio = ratioList.callObjectMethod("get",
- "(I)Ljava/lang/Object;",
- i);
-
- ratios.append(zoomRatio.callMethod<jint>("intValue"));
- }
- }
-
- return ratios;
-}
-
-int AndroidCameraPrivate::getZoom()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return 0;
-
- return m_parameters.callMethod<jint>("getZoom");
-}
-
-void AndroidCameraPrivate::setZoom(int value)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- m_parameters.callMethod<void>("setZoom", "(I)V", value);
- applyParameters();
-}
-
-QString AndroidCameraPrivate::getFlashMode()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- QString value;
-
- if (m_parameters.isValid()) {
- QJNIObjectPrivate flashMode = m_parameters.callObjectMethod("getFlashMode",
- "()Ljava/lang/String;");
- if (flashMode.isValid())
- value = flashMode.toString();
- }
-
- return value;
-}
-
-void AndroidCameraPrivate::setFlashMode(const QString &value)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- m_parameters.callMethod<void>("setFlashMode",
- "(Ljava/lang/String;)V",
- QJNIObjectPrivate::fromString(value).object());
- applyParameters();
-}
-
-QString AndroidCameraPrivate::getFocusMode()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- QString value;
-
- if (m_parameters.isValid()) {
- QJNIObjectPrivate focusMode = m_parameters.callObjectMethod("getFocusMode",
- "()Ljava/lang/String;");
- if (focusMode.isValid())
- value = focusMode.toString();
- }
-
- return value;
-}
-
-void AndroidCameraPrivate::setFocusMode(const QString &value)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- m_parameters.callMethod<void>("setFocusMode",
- "(Ljava/lang/String;)V",
- QJNIObjectPrivate::fromString(value).object());
- applyParameters();
-}
-
-int AndroidCameraPrivate::getMaxNumFocusAreas()
-{
- if (QtAndroidPrivate::androidSdkVersion() < 14)
- return 0;
-
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return 0;
-
- return m_parameters.callMethod<jint>("getMaxNumFocusAreas");
-}
-
-QList<QRect> AndroidCameraPrivate::getFocusAreas()
-{
- QList<QRect> areas;
-
- if (QtAndroidPrivate::androidSdkVersion() < 14)
- return areas;
-
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (m_parameters.isValid()) {
- QJNIObjectPrivate list = m_parameters.callObjectMethod("getFocusAreas",
- "()Ljava/util/List;");
-
- if (list.isValid()) {
- int count = list.callMethod<jint>("size");
- for (int i = 0; i < count; ++i) {
- QJNIObjectPrivate area = list.callObjectMethod("get",
- "(I)Ljava/lang/Object;",
- i);
-
- areas.append(areaToRect(area.object()));
- }
- }
- }
-
- return areas;
-}
-
-void AndroidCameraPrivate::setFocusAreas(const QList<QRect> &areas)
-{
- if (QtAndroidPrivate::androidSdkVersion() < 14)
- return;
-
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- QJNIObjectPrivate list;
-
- if (!areas.isEmpty()) {
- QJNIEnvironmentPrivate env;
- QJNIObjectPrivate arrayList("java/util/ArrayList", "(I)V", areas.size());
- for (int i = 0; i < areas.size(); ++i) {
- arrayList.callMethod<jboolean>("add",
- "(Ljava/lang/Object;)Z",
- rectToArea(areas.at(i)).object());
- exceptionCheckAndClear(env);
- }
- list = arrayList;
- }
-
- m_parameters.callMethod<void>("setFocusAreas", "(Ljava/util/List;)V", list.object());
-
- applyParameters();
-}
-
-void AndroidCameraPrivate::autoFocus()
-{
- QJNIEnvironmentPrivate env;
-
- m_camera.callMethod<void>("autoFocus",
- "(Landroid/hardware/Camera$AutoFocusCallback;)V",
- m_cameraListener.object());
-
- if (!exceptionCheckAndClear(env))
- emit autoFocusStarted();
-}
-
-void AndroidCameraPrivate::cancelAutoFocus()
-{
- QJNIEnvironmentPrivate env;
- m_camera.callMethod<void>("cancelAutoFocus");
- exceptionCheckAndClear(env);
-}
-
-bool AndroidCameraPrivate::isAutoExposureLockSupported()
-{
- if (QtAndroidPrivate::androidSdkVersion() < 14)
- return false;
-
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return false;
-
- return m_parameters.callMethod<jboolean>("isAutoExposureLockSupported");
-}
-
-bool AndroidCameraPrivate::getAutoExposureLock()
-{
- if (QtAndroidPrivate::androidSdkVersion() < 14)
- return false;
-
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return false;
-
- return m_parameters.callMethod<jboolean>("getAutoExposureLock");
-}
-
-void AndroidCameraPrivate::setAutoExposureLock(bool toggle)
-{
- if (QtAndroidPrivate::androidSdkVersion() < 14)
- return;
-
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- m_parameters.callMethod<void>("setAutoExposureLock", "(Z)V", toggle);
- applyParameters();
-}
-
-bool AndroidCameraPrivate::isAutoWhiteBalanceLockSupported()
-{
- if (QtAndroidPrivate::androidSdkVersion() < 14)
- return false;
-
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return false;
-
- return m_parameters.callMethod<jboolean>("isAutoWhiteBalanceLockSupported");
-}
-
-bool AndroidCameraPrivate::getAutoWhiteBalanceLock()
-{
- if (QtAndroidPrivate::androidSdkVersion() < 14)
- return false;
-
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return false;
-
- return m_parameters.callMethod<jboolean>("getAutoWhiteBalanceLock");
-}
-
-void AndroidCameraPrivate::setAutoWhiteBalanceLock(bool toggle)
-{
- if (QtAndroidPrivate::androidSdkVersion() < 14)
- return;
-
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- m_parameters.callMethod<void>("setAutoWhiteBalanceLock", "(Z)V", toggle);
- applyParameters();
-}
-
-int AndroidCameraPrivate::getExposureCompensation()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return 0;
-
- return m_parameters.callMethod<jint>("getExposureCompensation");
-}
-
-void AndroidCameraPrivate::setExposureCompensation(int value)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- m_parameters.callMethod<void>("setExposureCompensation", "(I)V", value);
- applyParameters();
-}
-
-float AndroidCameraPrivate::getExposureCompensationStep()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return 0;
-
- return m_parameters.callMethod<jfloat>("getExposureCompensationStep");
-}
-
-int AndroidCameraPrivate::getMinExposureCompensation()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return 0;
-
- return m_parameters.callMethod<jint>("getMinExposureCompensation");
-}
-
-int AndroidCameraPrivate::getMaxExposureCompensation()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return 0;
-
- return m_parameters.callMethod<jint>("getMaxExposureCompensation");
-}
-
-QString AndroidCameraPrivate::getSceneMode()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- QString value;
-
- if (m_parameters.isValid()) {
- QJNIObjectPrivate sceneMode = m_parameters.callObjectMethod("getSceneMode",
- "()Ljava/lang/String;");
- if (sceneMode.isValid())
- value = sceneMode.toString();
- }
-
- return value;
-}
-
-void AndroidCameraPrivate::setSceneMode(const QString &value)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- m_parameters.callMethod<void>("setSceneMode",
- "(Ljava/lang/String;)V",
- QJNIObjectPrivate::fromString(value).object());
- applyParameters();
-}
-
-QString AndroidCameraPrivate::getWhiteBalance()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- QString value;
-
- if (m_parameters.isValid()) {
- QJNIObjectPrivate wb = m_parameters.callObjectMethod("getWhiteBalance",
- "()Ljava/lang/String;");
- if (wb.isValid())
- value = wb.toString();
- }
-
- return value;
-}
-
-void AndroidCameraPrivate::setWhiteBalance(const QString &value)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- m_parameters.callMethod<void>("setWhiteBalance",
- "(Ljava/lang/String;)V",
- QJNIObjectPrivate::fromString(value).object());
- applyParameters();
-
- emit whiteBalanceChanged();
-}
-
-void AndroidCameraPrivate::updateRotation()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- m_parameters.callMethod<void>("setRotation", "(I)V", m_rotation);
- applyParameters();
-}
-
-QList<QSize> AndroidCameraPrivate::getSupportedPictureSizes()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- QList<QSize> list;
-
- if (m_parameters.isValid()) {
- QJNIObjectPrivate sizeList = m_parameters.callObjectMethod("getSupportedPictureSizes",
- "()Ljava/util/List;");
- int count = sizeList.callMethod<jint>("size");
- for (int i = 0; i < count; ++i) {
- QJNIObjectPrivate size = sizeList.callObjectMethod("get",
- "(I)Ljava/lang/Object;",
- i);
- list.append(QSize(size.getField<jint>("width"), size.getField<jint>("height")));
- }
-
- std::sort(list.begin(), list.end(), qt_sizeLessThan);
- }
-
- return list;
-}
-
-void AndroidCameraPrivate::setPictureSize(const QSize &size)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- m_parameters.callMethod<void>("setPictureSize", "(II)V", size.width(), size.height());
- applyParameters();
-}
-
-void AndroidCameraPrivate::setJpegQuality(int quality)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- if (!m_parameters.isValid())
- return;
-
- m_parameters.callMethod<void>("setJpegQuality", "(I)V", quality);
- applyParameters();
-}
-
-void AndroidCameraPrivate::startPreview()
-{
- QJNIEnvironmentPrivate env;
-
- setupPreviewFrameCallback();
- m_camera.callMethod<void>("startPreview");
-
- if (exceptionCheckAndClear(env))
- emit previewFailedToStart();
- else
- emit previewStarted();
-}
-
-void AndroidCameraPrivate::stopPreview()
-{
- QJNIEnvironmentPrivate env;
-
- // cancel any pending new frame notification
- m_cameraListener.callMethod<void>("notifyWhenFrameAvailable", "(Z)V", false);
-
- m_camera.callMethod<void>("stopPreview");
-
- exceptionCheckAndClear(env);
- emit previewStopped();
-}
-
-void AndroidCameraPrivate::takePicture()
-{
- QJNIEnvironmentPrivate env;
-
- // We must clear the preview callback before calling takePicture(), otherwise the call will
- // block and the camera server will be frozen until the next device restart...
- // That problem only happens on some devices and on the emulator
- m_cameraListener.callMethod<void>("clearPreviewCallback", "(Landroid/hardware/Camera;)V", m_camera.object());
-
- m_camera.callMethod<void>("takePicture", "(Landroid/hardware/Camera$ShutterCallback;"
- "Landroid/hardware/Camera$PictureCallback;"
- "Landroid/hardware/Camera$PictureCallback;)V",
- m_cameraListener.object(),
- jobject(0),
- m_cameraListener.object());
-
- if (exceptionCheckAndClear(env))
- emit takePictureFailed();
-}
-
-void AndroidCameraPrivate::setupPreviewFrameCallback()
-{
- m_cameraListener.callMethod<void>("setupPreviewCallback", "(Landroid/hardware/Camera;)V", m_camera.object());
-}
-
-void AndroidCameraPrivate::notifyNewFrames(bool notify)
-{
- m_cameraListener.callMethod<void>("notifyNewFrames", "(Z)V", notify);
-}
-
-void AndroidCameraPrivate::fetchLastPreviewFrame()
-{
- QJNIEnvironmentPrivate env;
- QJNIObjectPrivate data = m_cameraListener.callObjectMethod("lastPreviewBuffer", "()[B");
-
- if (!data.isValid()) {
- // If there's no buffer received yet, retry when the next one arrives
- m_cameraListener.callMethod<void>("notifyWhenFrameAvailable", "(Z)V", true);
- return;
- }
-
- const int arrayLength = env->GetArrayLength(static_cast<jbyteArray>(data.object()));
- if (arrayLength == 0)
- return;
-
- QByteArray bytes(arrayLength, Qt::Uninitialized);
- env->GetByteArrayRegion(static_cast<jbyteArray>(data.object()),
- 0,
- arrayLength,
- reinterpret_cast<jbyte *>(bytes.data()));
-
- const int width = m_cameraListener.callMethod<jint>("previewWidth");
- const int height = m_cameraListener.callMethod<jint>("previewHeight");
- const int format = m_cameraListener.callMethod<jint>("previewFormat");
- const int bpl = m_cameraListener.callMethod<jint>("previewBytesPerLine");
-
- QVideoFrame frame(new QMemoryVideoBuffer(bytes, bpl),
- QSize(width, height),
- qt_pixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat(format)));
-
- emit lastPreviewFrameFetched(frame);
-}
-
-void AndroidCameraPrivate::applyParameters()
-{
- QJNIEnvironmentPrivate env;
- m_camera.callMethod<void>("setParameters",
- "(Landroid/hardware/Camera$Parameters;)V",
- m_parameters.object());
- exceptionCheckAndClear(env);
-}
-
-QStringList AndroidCameraPrivate::callParametersStringListMethod(const QByteArray &methodName)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
-
- QStringList stringList;
-
- if (m_parameters.isValid()) {
- QJNIObjectPrivate list = m_parameters.callObjectMethod(methodName.constData(),
- "()Ljava/util/List;");
-
- if (list.isValid()) {
- int count = list.callMethod<jint>("size");
- for (int i = 0; i < count; ++i) {
- QJNIObjectPrivate string = list.callObjectMethod("get",
- "(I)Ljava/lang/Object;",
- i);
- stringList.append(string.toString());
- }
- }
- }
-
- return stringList;
-}
-
-bool AndroidCamera::initJNI(JNIEnv *env)
-{
- jclass clazz = QJNIEnvironmentPrivate::findClass(QtCameraListenerClassName,
- env);
-
- static const JNINativeMethod methods[] = {
- {"notifyAutoFocusComplete", "(IZ)V", (void *)notifyAutoFocusComplete},
- {"notifyPictureExposed", "(I)V", (void *)notifyPictureExposed},
- {"notifyPictureCaptured", "(I[B)V", (void *)notifyPictureCaptured},
- {"notifyNewPreviewFrame", "(I[BIIII)V", (void *)notifyNewPreviewFrame},
- {"notifyFrameAvailable", "(I)V", (void *)notifyFrameAvailable}
- };
-
- if (clazz && env->RegisterNatives(clazz,
- methods,
- sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
- return false;
- }
-
- return true;
-}
-
-QT_END_NAMESPACE
-
-#include "androidcamera.moc"
diff --git a/src/plugins/android/src/wrappers/jni/androidcamera.h b/src/plugins/android/src/wrappers/jni/androidcamera.h
deleted file mode 100644
index 5ae141f01..000000000
--- a/src/plugins/android/src/wrappers/jni/androidcamera.h
+++ /dev/null
@@ -1,237 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Ruslan Baratov
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ANDROIDCAMERA_H
-#define ANDROIDCAMERA_H
-
-#include <qobject.h>
-#include <QtCore/private/qjni_p.h>
-#include <qsize.h>
-#include <qrect.h>
-#include <QtMultimedia/qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-class QThread;
-
-class AndroidCameraPrivate;
-class AndroidSurfaceTexture;
-class AndroidSurfaceHolder;
-
-struct AndroidCameraInfo
-{
- QByteArray name;
- QString description;
- QCamera::Position position;
- int orientation;
-};
-Q_DECLARE_TYPEINFO(AndroidCameraInfo, Q_MOVABLE_TYPE);
-
-class AndroidCamera : public QObject
-{
- Q_OBJECT
- Q_ENUMS(CameraFacing)
- Q_ENUMS(ImageFormat)
-public:
- enum CameraFacing {
- CameraFacingBack = 0,
- CameraFacingFront = 1
- };
-
- enum ImageFormat { // same values as in android.graphics.ImageFormat Java class
- UnknownImageFormat = 0,
- RGB565 = 4,
- NV16 = 16,
- NV21 = 17,
- YUY2 = 20,
- JPEG = 256,
- YV12 = 842094169
- };
-
- // http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getSupportedPreviewFpsRange%28%29
- // "The values are multiplied by 1000 and represented in integers"
- struct FpsRange {
- int min;
- int max;
-
- FpsRange(): min(0), max(0) {}
-
- qreal getMinReal() const { return min / 1000.0; }
- qreal getMaxReal() const { return max / 1000.0; }
-
- static FpsRange makeFromQReal(qreal min, qreal max)
- {
- FpsRange range;
- range.min = static_cast<int>(min * 1000.0);
- range.max = static_cast<int>(max * 1000.0);
- return range;
- }
- };
-
- ~AndroidCamera();
-
- static AndroidCamera *open(int cameraId);
-
- int cameraId() const;
-
- bool lock();
- bool unlock();
- bool reconnect();
- void release();
-
- CameraFacing getFacing();
- int getNativeOrientation();
-
- QSize getPreferredPreviewSizeForVideo();
- QList<QSize> getSupportedPreviewSizes();
-
- QList<FpsRange> getSupportedPreviewFpsRange();
-
- FpsRange getPreviewFpsRange();
- void setPreviewFpsRange(FpsRange);
-
- ImageFormat getPreviewFormat();
- void setPreviewFormat(ImageFormat fmt);
- QList<ImageFormat> getSupportedPreviewFormats();
-
- QSize previewSize() const;
- QSize actualPreviewSize();
- void setPreviewSize(const QSize &size);
- bool setPreviewTexture(AndroidSurfaceTexture *surfaceTexture);
- bool setPreviewDisplay(AndroidSurfaceHolder *surfaceHolder);
- void setDisplayOrientation(int degrees);
-
- bool isZoomSupported();
- int getMaxZoom();
- QList<int> getZoomRatios();
- int getZoom();
- void setZoom(int value);
-
- QStringList getSupportedFlashModes();
- QString getFlashMode();
- void setFlashMode(const QString &value);
-
- QStringList getSupportedFocusModes();
- QString getFocusMode();
- void setFocusMode(const QString &value);
-
- int getMaxNumFocusAreas();
- QList<QRect> getFocusAreas();
- void setFocusAreas(const QList<QRect> &areas);
-
- void autoFocus();
- void cancelAutoFocus();
-
- bool isAutoExposureLockSupported();
- bool getAutoExposureLock();
- void setAutoExposureLock(bool toggle);
-
- bool isAutoWhiteBalanceLockSupported();
- bool getAutoWhiteBalanceLock();
- void setAutoWhiteBalanceLock(bool toggle);
-
- int getExposureCompensation();
- void setExposureCompensation(int value);
- float getExposureCompensationStep();
- int getMinExposureCompensation();
- int getMaxExposureCompensation();
-
- QStringList getSupportedSceneModes();
- QString getSceneMode();
- void setSceneMode(const QString &value);
-
- QStringList getSupportedWhiteBalance();
- QString getWhiteBalance();
- void setWhiteBalance(const QString &value);
-
- void setRotation(int rotation);
- int getRotation() const;
-
- QList<QSize> getSupportedPictureSizes();
- void setPictureSize(const QSize &size);
- void setJpegQuality(int quality);
-
- void startPreview();
- void stopPreview();
- void stopPreviewSynchronous();
-
- void takePicture();
-
- void setupPreviewFrameCallback();
- void notifyNewFrames(bool notify);
- void fetchLastPreviewFrame();
- QJNIObjectPrivate getCameraObject();
-
- static int getNumberOfCameras();
- static void getCameraInfo(int id, AndroidCameraInfo *info);
- static bool requestCameraPermission();
-
- static bool initJNI(JNIEnv *env);
-
-Q_SIGNALS:
- void previewSizeChanged();
- void previewStarted();
- void previewFailedToStart();
- void previewStopped();
-
- void autoFocusStarted();
- void autoFocusComplete(bool success);
-
- void whiteBalanceChanged();
-
- void takePictureFailed();
- void pictureExposed();
- void pictureCaptured(const QByteArray &data);
- void lastPreviewFrameFetched(const QVideoFrame &frame);
- void newPreviewFrame(const QVideoFrame &frame);
-
-private:
- AndroidCamera(AndroidCameraPrivate *d, QThread *worker);
-
- Q_DECLARE_PRIVATE(AndroidCamera)
- AndroidCameraPrivate *d_ptr;
- QScopedPointer<QThread> m_worker;
-};
-
-Q_DECLARE_METATYPE(AndroidCamera::ImageFormat)
-
-QT_END_NAMESPACE
-
-#endif // ANDROIDCAMERA_H
diff --git a/src/plugins/android/src/wrappers/jni/androidmediametadataretriever.cpp b/src/plugins/android/src/wrappers/jni/androidmediametadataretriever.cpp
deleted file mode 100644
index ce6144167..000000000
--- a/src/plugins/android/src/wrappers/jni/androidmediametadataretriever.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "androidmediametadataretriever.h"
-
-#include <QtCore/private/qjnihelpers_p.h>
-#include <QtCore/private/qjni_p.h>
-#include <QtCore/QUrl>
-#include <qdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-static bool exceptionCheckAndClear(JNIEnv *env)
-{
- if (Q_UNLIKELY(env->ExceptionCheck())) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif // QT_DEBUG
- env->ExceptionClear();
- return true;
- }
-
- return false;
-}
-
-AndroidMediaMetadataRetriever::AndroidMediaMetadataRetriever()
-{
- m_metadataRetriever = QJNIObjectPrivate("android/media/MediaMetadataRetriever");
-}
-
-AndroidMediaMetadataRetriever::~AndroidMediaMetadataRetriever()
-{
- release();
-}
-
-QString AndroidMediaMetadataRetriever::extractMetadata(MetadataKey key)
-{
- QString value;
-
- QJNIObjectPrivate metadata = m_metadataRetriever.callObjectMethod("extractMetadata",
- "(I)Ljava/lang/String;",
- jint(key));
- if (metadata.isValid())
- value = metadata.toString();
-
- return value;
-}
-
-void AndroidMediaMetadataRetriever::release()
-{
- if (!m_metadataRetriever.isValid())
- return;
-
- m_metadataRetriever.callMethod<void>("release");
-}
-
-bool AndroidMediaMetadataRetriever::setDataSource(const QUrl &url)
-{
- if (!m_metadataRetriever.isValid())
- return false;
-
- QJNIEnvironmentPrivate env;
-
- if (url.isLocalFile()) { // also includes qrc files (copied to a temp file by QMediaPlayer)
- QJNIObjectPrivate string = QJNIObjectPrivate::fromString(url.path());
- QJNIObjectPrivate fileInputStream("java/io/FileInputStream",
- "(Ljava/lang/String;)V",
- string.object());
-
- if (exceptionCheckAndClear(env))
- return false;
-
- QJNIObjectPrivate fd = fileInputStream.callObjectMethod("getFD",
- "()Ljava/io/FileDescriptor;");
- if (exceptionCheckAndClear(env)) {
- fileInputStream.callMethod<void>("close");
- exceptionCheckAndClear(env);
- return false;
- }
-
- m_metadataRetriever.callMethod<void>("setDataSource",
- "(Ljava/io/FileDescriptor;)V",
- fd.object());
-
- bool ok = !exceptionCheckAndClear(env);
-
- fileInputStream.callMethod<void>("close");
- exceptionCheckAndClear(env);
-
- if (!ok)
- return false;
- } else if (url.scheme() == QLatin1String("assets")) {
- QJNIObjectPrivate string = QJNIObjectPrivate::fromString(url.path().mid(1)); // remove first '/'
- QJNIObjectPrivate activity(QtAndroidPrivate::activity());
- QJNIObjectPrivate assetManager = activity.callObjectMethod("getAssets",
- "()Landroid/content/res/AssetManager;");
- QJNIObjectPrivate assetFd = assetManager.callObjectMethod("openFd",
- "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;",
- string.object());
- if (exceptionCheckAndClear(env))
- return false;
-
- QJNIObjectPrivate fd = assetFd.callObjectMethod("getFileDescriptor",
- "()Ljava/io/FileDescriptor;");
- if (exceptionCheckAndClear(env)) {
- assetFd.callMethod<void>("close");
- exceptionCheckAndClear(env);
- return false;
- }
-
- m_metadataRetriever.callMethod<void>("setDataSource",
- "(Ljava/io/FileDescriptor;JJ)V",
- fd.object(),
- assetFd.callMethod<jlong>("getStartOffset"),
- assetFd.callMethod<jlong>("getLength"));
-
- bool ok = !exceptionCheckAndClear(env);
-
- assetFd.callMethod<void>("close");
- exceptionCheckAndClear(env);
-
- if (!ok)
- return false;
- } else if (QtAndroidPrivate::androidSdkVersion() >= 14) {
- // On API levels >= 14, only setDataSource(String, Map<String, String>) accepts remote media
- QJNIObjectPrivate string = QJNIObjectPrivate::fromString(url.toString(QUrl::FullyEncoded));
- QJNIObjectPrivate hash("java/util/HashMap");
-
- m_metadataRetriever.callMethod<void>("setDataSource",
- "(Ljava/lang/String;Ljava/util/Map;)V",
- string.object(),
- hash.object());
- if (exceptionCheckAndClear(env))
- return false;
- } else {
- // While on API levels < 14, only setDataSource(Context, Uri) is available and works for
- // remote media...
- QJNIObjectPrivate string = QJNIObjectPrivate::fromString(url.toString(QUrl::FullyEncoded));
- QJNIObjectPrivate uri = m_metadataRetriever.callStaticObjectMethod("android/net/Uri",
- "parse",
- "(Ljava/lang/String;)Landroid/net/Uri;",
- string.object());
- if (exceptionCheckAndClear(env))
- return false;
-
- m_metadataRetriever.callMethod<void>("setDataSource",
- "(Landroid/content/Context;Landroid/net/Uri;)V",
- QtAndroidPrivate::activity(),
- uri.object());
- if (exceptionCheckAndClear(env))
- return false;
- }
-
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/wrappers/jni/androidmediametadataretriever.h b/src/plugins/android/src/wrappers/jni/androidmediametadataretriever.h
deleted file mode 100644
index 1e141813d..000000000
--- a/src/plugins/android/src/wrappers/jni/androidmediametadataretriever.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ANDROIDMEDIAMETADATARETRIEVER_H
-#define ANDROIDMEDIAMETADATARETRIEVER_H
-
-#include <QtCore/private/qjni_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class AndroidMediaMetadataRetriever
-{
-public:
- enum MetadataKey {
- Album = 1,
- AlbumArtist = 13,
- Artist = 2,
- Author = 3,
- Bitrate = 20,
- CDTrackNumber = 0,
- Compilation = 15,
- Composer = 4,
- Date = 5,
- DiscNumber = 14,
- Duration = 9,
- Genre = 6,
- HasAudio = 16,
- HasVideo = 17,
- Location = 23,
- MimeType = 12,
- NumTracks = 10,
- Title = 7,
- VideoHeight = 19,
- VideoWidth = 18,
- VideoRotation = 24,
- Writer = 11,
- Year = 8
- };
-
- AndroidMediaMetadataRetriever();
- ~AndroidMediaMetadataRetriever();
-
- QString extractMetadata(MetadataKey key);
- bool setDataSource(const QUrl &url);
-
-private:
- void release();
- QJNIObjectPrivate m_metadataRetriever;
-};
-
-QT_END_NAMESPACE
-
-#endif // ANDROIDMEDIAMETADATARETRIEVER_H
diff --git a/src/plugins/android/src/wrappers/jni/androidmediaplayer.cpp b/src/plugins/android/src/wrappers/jni/androidmediaplayer.cpp
deleted file mode 100644
index c94695de4..000000000
--- a/src/plugins/android/src/wrappers/jni/androidmediaplayer.cpp
+++ /dev/null
@@ -1,435 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "androidmediaplayer.h"
-
-#include <QString>
-#include <QtCore/private/qjni_p.h>
-#include <QtCore/private/qjnihelpers_p.h>
-#include "androidsurfacetexture.h"
-#include <QList>
-#include <QReadWriteLock>
-
-static const char QtAndroidMediaPlayerClassName[] = "org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer";
-typedef QList<AndroidMediaPlayer *> MediaPlayerList;
-Q_GLOBAL_STATIC(MediaPlayerList, mediaPlayers)
-Q_GLOBAL_STATIC(QReadWriteLock, rwLock)
-
-QT_BEGIN_NAMESPACE
-
-AndroidMediaPlayer::AndroidMediaPlayer()
- : QObject()
-{
- QWriteLocker locker(rwLock);
- auto context = QtAndroidPrivate::activity() ? QtAndroidPrivate::activity() : QtAndroidPrivate::service();
- const jlong id = reinterpret_cast<jlong>(this);
- mMediaPlayer = QJNIObjectPrivate(QtAndroidMediaPlayerClassName,
- "(Landroid/content/Context;J)V",
- context,
- id);
- mediaPlayers->append(this);
-}
-
-AndroidMediaPlayer::~AndroidMediaPlayer()
-{
- QWriteLocker locker(rwLock);
- const int i = mediaPlayers->indexOf(this);
- Q_ASSERT(i != -1);
- mediaPlayers->remove(i);
-}
-
-void AndroidMediaPlayer::release()
-{
- mMediaPlayer.callMethod<void>("release");
-}
-
-void AndroidMediaPlayer::reset()
-{
- mMediaPlayer.callMethod<void>("reset");
-}
-
-int AndroidMediaPlayer::getCurrentPosition()
-{
- return mMediaPlayer.callMethod<jint>("getCurrentPosition");
-}
-
-int AndroidMediaPlayer::getDuration()
-{
- return mMediaPlayer.callMethod<jint>("getDuration");
-}
-
-bool AndroidMediaPlayer::isPlaying()
-{
- return mMediaPlayer.callMethod<jboolean>("isPlaying");
-}
-
-int AndroidMediaPlayer::volume()
-{
- return mMediaPlayer.callMethod<jint>("getVolume");
-}
-
-bool AndroidMediaPlayer::isMuted()
-{
- return mMediaPlayer.callMethod<jboolean>("isMuted");
-}
-
-qreal AndroidMediaPlayer::playbackRate()
-{
- qreal rate(1.0);
-
- if (QtAndroidPrivate::androidSdkVersion() < 23)
- return rate;
-
- QJNIObjectPrivate player = mMediaPlayer.callObjectMethod("getMediaPlayerHandle", "()Landroid/media/MediaPlayer;");
- if (player.isValid()) {
- QJNIObjectPrivate playbackParams = player.callObjectMethod("getPlaybackParams", "()Landroid/media/PlaybackParams;");
- if (playbackParams.isValid()) {
- const qreal speed = playbackParams.callMethod<jfloat>("getSpeed", "()F");
- QJNIEnvironmentPrivate env;
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif // QT_DEBUG
- env->ExceptionClear();
- } else {
- rate = speed;
- }
- }
- }
-
- return rate;
-}
-
-jobject AndroidMediaPlayer::display()
-{
- return mMediaPlayer.callObjectMethod("display", "()Landroid/view/SurfaceHolder;").object();
-}
-
-void AndroidMediaPlayer::play()
-{
- mMediaPlayer.callMethod<void>("start");
-}
-
-void AndroidMediaPlayer::pause()
-{
- mMediaPlayer.callMethod<void>("pause");
-}
-
-void AndroidMediaPlayer::stop()
-{
- mMediaPlayer.callMethod<void>("stop");
-}
-
-void AndroidMediaPlayer::seekTo(qint32 msec)
-{
- mMediaPlayer.callMethod<void>("seekTo", "(I)V", jint(msec));
-}
-
-void AndroidMediaPlayer::setMuted(bool mute)
-{
- mMediaPlayer.callMethod<void>("mute", "(Z)V", jboolean(mute));
-}
-
-void AndroidMediaPlayer::setDataSource(const QNetworkRequest &request)
-{
- QJNIObjectPrivate string = QJNIObjectPrivate::fromString(request.url().toString(QUrl::FullyEncoded));
-
- mMediaPlayer.callMethod<void>("initHeaders", "()V");
- for (auto &header : request.rawHeaderList()) {
- auto value = request.rawHeader(header);
- mMediaPlayer.callMethod<void>("setHeader", "(Ljava/lang/String;Ljava/lang/String;)V",
- QJNIObjectPrivate::fromString(header).object(), QJNIObjectPrivate::fromString(value).object());
- }
-
- mMediaPlayer.callMethod<void>("setDataSource", "(Ljava/lang/String;)V", string.object());
-}
-
-void AndroidMediaPlayer::prepareAsync()
-{
- mMediaPlayer.callMethod<void>("prepareAsync");
-}
-
-void AndroidMediaPlayer::setVolume(int volume)
-{
- mMediaPlayer.callMethod<void>("setVolume", "(I)V", jint(volume));
-}
-
-bool AndroidMediaPlayer::setPlaybackRate(qreal rate)
-{
- if (QtAndroidPrivate::androidSdkVersion() < 23) {
- qWarning("Setting the playback rate on a media player requires Android 6.0 (API level 23) or later");
- return false;
- }
-
- QJNIEnvironmentPrivate env;
-
- QJNIObjectPrivate player = mMediaPlayer.callObjectMethod("getMediaPlayerHandle", "()Landroid/media/MediaPlayer;");
- if (player.isValid()) {
- QJNIObjectPrivate playbackParams = player.callObjectMethod("getPlaybackParams", "()Landroid/media/PlaybackParams;");
- if (playbackParams.isValid()) {
- playbackParams.callObjectMethod("setSpeed", "(F)Landroid/media/PlaybackParams;", jfloat(rate));
- // pitch can only be > 0
- if (!qFuzzyIsNull(rate))
- playbackParams.callObjectMethod("setPitch", "(F)Landroid/media/PlaybackParams;", jfloat(qAbs(rate)));
- player.callMethod<void>("setPlaybackParams", "(Landroid/media/PlaybackParams;)V", playbackParams.object());
- if (Q_UNLIKELY(env->ExceptionCheck())) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif // QT_DEBUG
- env->ExceptionClear();
- qWarning() << "Invalid playback rate" << rate;
- return false;
- } else {
- return true;
- }
- }
- }
-
- return false;
-}
-
-void AndroidMediaPlayer::setDisplay(AndroidSurfaceTexture *surfaceTexture)
-{
- mMediaPlayer.callMethod<void>("setDisplay",
- "(Landroid/view/SurfaceHolder;)V",
- surfaceTexture ? surfaceTexture->surfaceHolder() : 0);
-}
-
-void AndroidMediaPlayer::setAudioRole(QAudio::Role role)
-{
- QString str;
- switch (role) {
- case QAudio::MusicRole:
- str = QLatin1String("CONTENT_TYPE_MUSIC");
- break;
- case QAudio::VideoRole:
- str = QLatin1String("CONTENT_TYPE_MOVIE");
- break;
- case QAudio::VoiceCommunicationRole:
- str = QLatin1String("USAGE_VOICE_COMMUNICATION");
- break;
- case QAudio::AlarmRole:
- str = QLatin1String("USAGE_ALARM");
- break;
- case QAudio::NotificationRole:
- str = QLatin1String("USAGE_NOTIFICATION");
- break;
- case QAudio::RingtoneRole:
- str = QLatin1String("USAGE_NOTIFICATION_RINGTONE");
- break;
- case QAudio::AccessibilityRole:
- str = QLatin1String("USAGE_ASSISTANCE_ACCESSIBILITY");
- break;
- case QAudio::SonificationRole:
- str = QLatin1String("CONTENT_TYPE_SONIFICATION");
- break;
- case QAudio::GameRole:
- str = QLatin1String("USAGE_GAME");
- break;
- default:
- break;
- }
-
- setCustomAudioRole(str);
-}
-
-void AndroidMediaPlayer::setCustomAudioRole(const QString &role)
-{
- QStringList roles = role.split(",", Qt::SkipEmptyParts);
-
- int type = 0; // CONTENT_TYPE_UNKNOWN
- int usage = 0; // USAGE_UNKNOWN
- for (int i = 0; i < qMin(2, roles.size()); ++i) {
- auto r = roles[i];
- if (r == QLatin1String("CONTENT_TYPE_MOVIE"))
- type = 3;
- else if (r == QLatin1String("CONTENT_TYPE_MUSIC"))
- type = 2;
- else if (r == QLatin1String("CONTENT_TYPE_SONIFICATION"))
- type = 4;
- else if (r == QLatin1String("CONTENT_TYPE_SPEECH"))
- type = 1;
- else if (r == QLatin1String("USAGE_ALARM"))
- usage = 4;
- else if (r == QLatin1String("USAGE_ASSISTANCE_ACCESSIBILITY"))
- usage = 11;
- else if (r == QLatin1String("USAGE_ASSISTANCE_NAVIGATION_GUIDANCE"))
- usage = 12;
- else if (r == QLatin1String("USAGE_ASSISTANCE_SONIFICATION"))
- usage = 13;
- else if (r == QLatin1String("USAGE_ASSISTANT"))
- usage = 16;
- else if (r == QLatin1String("USAGE_GAME"))
- usage = 14;
- else if (r == QLatin1String("USAGE_MEDIA"))
- usage = 1;
- else if (r == QLatin1String("USAGE_NOTIFICATION"))
- usage = 5;
- else if (r == QLatin1String("USAGE_NOTIFICATION_COMMUNICATION_DELAYED"))
- usage = 9;
- else if (r == QLatin1String("USAGE_NOTIFICATION_COMMUNICATION_INSTANT"))
- usage = 8;
- else if (r == QLatin1String("USAGE_NOTIFICATION_COMMUNICATION_REQUEST"))
- usage = 7;
- else if (r == QLatin1String("USAGE_NOTIFICATION_EVENT"))
- usage = 10;
- else if (r == QLatin1String("USAGE_NOTIFICATION_RINGTONE"))
- usage = 6;
- else if (r == QLatin1String("USAGE_VOICE_COMMUNICATION"))
- usage = 2;
- else if (r == QLatin1String("USAGE_VOICE_COMMUNICATION_SIGNALLING"))
- usage = 3;
- }
-
- mMediaPlayer.callMethod<void>("setAudioAttributes", "(II)V", jint(type), jint(usage));
-}
-
-static void onErrorNative(JNIEnv *env, jobject thiz, jint what, jint extra, jlong id)
-{
- Q_UNUSED(env);
- Q_UNUSED(thiz);
- QReadLocker locker(rwLock);
- const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
- if (Q_UNLIKELY(i == -1))
- return;
-
- Q_EMIT (*mediaPlayers)[i]->error(what, extra);
-}
-
-static void onBufferingUpdateNative(JNIEnv *env, jobject thiz, jint percent, jlong id)
-{
- Q_UNUSED(env);
- Q_UNUSED(thiz);
- QReadLocker locker(rwLock);
- const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
- if (Q_UNLIKELY(i == -1))
- return;
-
- Q_EMIT (*mediaPlayers)[i]->bufferingChanged(percent);
-}
-
-static void onProgressUpdateNative(JNIEnv *env, jobject thiz, jint progress, jlong id)
-{
- Q_UNUSED(env);
- Q_UNUSED(thiz);
- QReadLocker locker(rwLock);
- const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
- if (Q_UNLIKELY(i == -1))
- return;
-
- Q_EMIT (*mediaPlayers)[i]->progressChanged(progress);
-}
-
-static void onDurationChangedNative(JNIEnv *env, jobject thiz, jint duration, jlong id)
-{
- Q_UNUSED(env);
- Q_UNUSED(thiz);
- QReadLocker locker(rwLock);
- const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
- if (Q_UNLIKELY(i == -1))
- return;
-
- Q_EMIT (*mediaPlayers)[i]->durationChanged(duration);
-}
-
-static void onInfoNative(JNIEnv *env, jobject thiz, jint what, jint extra, jlong id)
-{
- Q_UNUSED(env);
- Q_UNUSED(thiz);
- QReadLocker locker(rwLock);
- const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
- if (Q_UNLIKELY(i == -1))
- return;
-
- Q_EMIT (*mediaPlayers)[i]->info(what, extra);
-}
-
-static void onStateChangedNative(JNIEnv *env, jobject thiz, jint state, jlong id)
-{
- Q_UNUSED(env);
- Q_UNUSED(thiz);
- QReadLocker locker(rwLock);
- const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
- if (Q_UNLIKELY(i == -1))
- return;
-
- Q_EMIT (*mediaPlayers)[i]->stateChanged(state);
-}
-
-static void onVideoSizeChangedNative(JNIEnv *env,
- jobject thiz,
- jint width,
- jint height,
- jlong id)
-{
- Q_UNUSED(env);
- Q_UNUSED(thiz);
- QReadLocker locker(rwLock);
- const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
- if (Q_UNLIKELY(i == -1))
- return;
-
- Q_EMIT (*mediaPlayers)[i]->videoSizeChanged(width, height);
-}
-
-bool AndroidMediaPlayer::initJNI(JNIEnv *env)
-{
- jclass clazz = QJNIEnvironmentPrivate::findClass(QtAndroidMediaPlayerClassName,
- env);
-
- static const JNINativeMethod methods[] = {
- {"onErrorNative", "(IIJ)V", reinterpret_cast<void *>(onErrorNative)},
- {"onBufferingUpdateNative", "(IJ)V", reinterpret_cast<void *>(onBufferingUpdateNative)},
- {"onProgressUpdateNative", "(IJ)V", reinterpret_cast<void *>(onProgressUpdateNative)},
- {"onDurationChangedNative", "(IJ)V", reinterpret_cast<void *>(onDurationChangedNative)},
- {"onInfoNative", "(IIJ)V", reinterpret_cast<void *>(onInfoNative)},
- {"onVideoSizeChangedNative", "(IIJ)V", reinterpret_cast<void *>(onVideoSizeChangedNative)},
- {"onStateChangedNative", "(IJ)V", reinterpret_cast<void *>(onStateChangedNative)}
- };
-
- if (clazz && env->RegisterNatives(clazz,
- methods,
- sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
- return false;
- }
-
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/wrappers/jni/androidmediaplayer.h b/src/plugins/android/src/wrappers/jni/androidmediaplayer.h
deleted file mode 100644
index 37c7456f7..000000000
--- a/src/plugins/android/src/wrappers/jni/androidmediaplayer.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ANDROIDMEDIAPLAYER_H
-#define ANDROIDMEDIAPLAYER_H
-
-#include <QObject>
-#include <QNetworkRequest>
-#include <QtCore/private/qjni_p.h>
-#include <QAudio>
-
-QT_BEGIN_NAMESPACE
-
-class AndroidSurfaceTexture;
-
-class AndroidMediaPlayer : public QObject
-{
- Q_OBJECT
-public:
- AndroidMediaPlayer();
- ~AndroidMediaPlayer();
-
- enum MediaError
- {
- // What
- MEDIA_ERROR_UNKNOWN = 1,
- MEDIA_ERROR_SERVER_DIED = 100,
- MEDIA_ERROR_INVALID_STATE = -38, // Undocumented
- // Extra
- MEDIA_ERROR_IO = -1004,
- MEDIA_ERROR_MALFORMED = -1007,
- MEDIA_ERROR_UNSUPPORTED = -1010,
- MEDIA_ERROR_TIMED_OUT = -110,
- MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200,
- MEDIA_ERROR_BAD_THINGS_ARE_GOING_TO_HAPPEN = -2147483648 // Undocumented
- };
-
- enum MediaInfo
- {
- MEDIA_INFO_UNKNOWN = 1,
- MEDIA_INFO_VIDEO_TRACK_LAGGING = 700,
- MEDIA_INFO_VIDEO_RENDERING_START = 3,
- MEDIA_INFO_BUFFERING_START = 701,
- MEDIA_INFO_BUFFERING_END = 702,
- MEDIA_INFO_BAD_INTERLEAVING = 800,
- MEDIA_INFO_NOT_SEEKABLE = 801,
- MEDIA_INFO_METADATA_UPDATE = 802
- };
-
- enum MediaPlayerState
- {
- Uninitialized = 0x1, /* End */
- Idle = 0x2,
- Preparing = 0x4,
- Prepared = 0x8,
- Initialized = 0x10,
- Started = 0x20,
- Stopped = 0x40,
- Paused = 0x80,
- PlaybackCompleted = 0x100,
- Error = 0x200
- };
-
- void release();
- void reset();
-
- int getCurrentPosition();
- int getDuration();
- bool isPlaying();
- int volume();
- bool isMuted();
- qreal playbackRate();
- jobject display();
-
- void play();
- void pause();
- void stop();
- void seekTo(qint32 msec);
- void setMuted(bool mute);
- void setDataSource(const QNetworkRequest &request);
- void prepareAsync();
- void setVolume(int volume);
- bool setPlaybackRate(qreal rate);
- void setDisplay(AndroidSurfaceTexture *surfaceTexture);
- void setAudioRole(QAudio::Role role);
- void setCustomAudioRole(const QString &role);
-
- static bool initJNI(JNIEnv *env);
-
-Q_SIGNALS:
- void error(qint32 what, qint32 extra);
- void bufferingChanged(qint32 percent);
- void durationChanged(qint64 duration);
- void progressChanged(qint64 progress);
- void stateChanged(qint32 state);
- void info(qint32 what, qint32 extra);
- void videoSizeChanged(qint32 width, qint32 height);
-
-private:
- QJNIObjectPrivate mMediaPlayer;
-};
-
-QT_END_NAMESPACE
-
-#endif // ANDROIDMEDIAPLAYER_H
diff --git a/src/plugins/android/src/wrappers/jni/androidmediarecorder.cpp b/src/plugins/android/src/wrappers/jni/androidmediarecorder.cpp
deleted file mode 100644
index e5f8846b9..000000000
--- a/src/plugins/android/src/wrappers/jni/androidmediarecorder.cpp
+++ /dev/null
@@ -1,405 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "androidmediarecorder.h"
-
-#include "androidcamera.h"
-#include "androidsurfacetexture.h"
-#include "androidsurfaceview.h"
-#include "qandroidglobal.h"
-#include "qandroidmultimediautils.h"
-#include <QtCore/private/qjni_p.h>
-#include <qmap.h>
-
-QT_BEGIN_NAMESPACE
-
-typedef QMap<QString, QJNIObjectPrivate> CamcorderProfiles;
-Q_GLOBAL_STATIC(CamcorderProfiles, g_camcorderProfiles)
-
-static QString profileKey()
-{
- return QStringLiteral("%1-%2");
-}
-
-bool AndroidCamcorderProfile::hasProfile(jint cameraId, Quality quality)
-{
- if (g_camcorderProfiles->contains(profileKey().arg(cameraId).arg(quality)))
- return true;
-
- return QJNIObjectPrivate::callStaticMethod<jboolean>("android/media/CamcorderProfile",
- "hasProfile",
- "(II)Z",
- cameraId,
- quality);
-}
-
-AndroidCamcorderProfile AndroidCamcorderProfile::get(jint cameraId, Quality quality)
-{
- const QString key = profileKey().arg(cameraId).arg(quality);
- QMap<QString, QJNIObjectPrivate>::const_iterator it = g_camcorderProfiles->constFind(key);
-
- if (it != g_camcorderProfiles->constEnd())
- return AndroidCamcorderProfile(*it);
-
- QJNIObjectPrivate camProfile = QJNIObjectPrivate::callStaticObjectMethod("android/media/CamcorderProfile",
- "get",
- "(II)Landroid/media/CamcorderProfile;",
- cameraId,
- quality);
-
- return AndroidCamcorderProfile((*g_camcorderProfiles)[key] = camProfile);
-}
-
-int AndroidCamcorderProfile::getValue(AndroidCamcorderProfile::Field field) const
-{
- switch (field) {
- case audioBitRate:
- return m_camcorderProfile.getField<jint>("audioBitRate");
- case audioChannels:
- return m_camcorderProfile.getField<jint>("audioChannels");
- case audioCodec:
- return m_camcorderProfile.getField<jint>("audioCodec");
- case audioSampleRate:
- return m_camcorderProfile.getField<jint>("audioSampleRate");
- case duration:
- return m_camcorderProfile.getField<jint>("duration");
- case fileFormat:
- return m_camcorderProfile.getField<jint>("fileFormat");
- case quality:
- return m_camcorderProfile.getField<jint>("quality");
- case videoBitRate:
- return m_camcorderProfile.getField<jint>("videoBitRate");
- case videoCodec:
- return m_camcorderProfile.getField<jint>("videoCodec");
- case videoFrameHeight:
- return m_camcorderProfile.getField<jint>("videoFrameHeight");
- case videoFrameRate:
- return m_camcorderProfile.getField<jint>("videoFrameRate");
- case videoFrameWidth:
- return m_camcorderProfile.getField<jint>("videoFrameWidth");
- }
-
- return 0;
-}
-
-AndroidCamcorderProfile::AndroidCamcorderProfile(const QJNIObjectPrivate &camcorderProfile)
-{
- m_camcorderProfile = camcorderProfile;
-}
-
-static const char QtMediaRecorderListenerClassName[] = "org/qtproject/qt/android/multimedia/QtMediaRecorderListener";
-typedef QMap<jlong, AndroidMediaRecorder*> MediaRecorderMap;
-Q_GLOBAL_STATIC(MediaRecorderMap, mediaRecorders)
-
-static void notifyError(JNIEnv* , jobject, jlong id, jint what, jint extra)
-{
- AndroidMediaRecorder *obj = mediaRecorders->value(id, 0);
- if (obj)
- emit obj->error(what, extra);
-}
-
-static void notifyInfo(JNIEnv* , jobject, jlong id, jint what, jint extra)
-{
- AndroidMediaRecorder *obj = mediaRecorders->value(id, 0);
- if (obj)
- emit obj->info(what, extra);
-}
-
-AndroidMediaRecorder::AndroidMediaRecorder()
- : QObject()
- , m_id(reinterpret_cast<jlong>(this))
-{
- m_mediaRecorder = QJNIObjectPrivate("android/media/MediaRecorder");
- if (m_mediaRecorder.isValid()) {
- QJNIObjectPrivate listener(QtMediaRecorderListenerClassName, "(J)V", m_id);
- m_mediaRecorder.callMethod<void>("setOnErrorListener",
- "(Landroid/media/MediaRecorder$OnErrorListener;)V",
- listener.object());
- m_mediaRecorder.callMethod<void>("setOnInfoListener",
- "(Landroid/media/MediaRecorder$OnInfoListener;)V",
- listener.object());
- mediaRecorders->insert(m_id, this);
- }
-}
-
-AndroidMediaRecorder::~AndroidMediaRecorder()
-{
- mediaRecorders->remove(m_id);
-}
-
-void AndroidMediaRecorder::release()
-{
- m_mediaRecorder.callMethod<void>("release");
-}
-
-bool AndroidMediaRecorder::prepare()
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("prepare");
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- return false;
- }
- return true;
-}
-
-void AndroidMediaRecorder::reset()
-{
- m_mediaRecorder.callMethod<void>("reset");
-}
-
-bool AndroidMediaRecorder::start()
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("start");
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- return false;
- }
- return true;
-}
-
-void AndroidMediaRecorder::stop()
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("stop");
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-void AndroidMediaRecorder::setAudioChannels(int numChannels)
-{
- m_mediaRecorder.callMethod<void>("setAudioChannels", "(I)V", numChannels);
-}
-
-void AndroidMediaRecorder::setAudioEncoder(AudioEncoder encoder)
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("setAudioEncoder", "(I)V", int(encoder));
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-void AndroidMediaRecorder::setAudioEncodingBitRate(int bitRate)
-{
- m_mediaRecorder.callMethod<void>("setAudioEncodingBitRate", "(I)V", bitRate);
-}
-
-void AndroidMediaRecorder::setAudioSamplingRate(int samplingRate)
-{
- m_mediaRecorder.callMethod<void>("setAudioSamplingRate", "(I)V", samplingRate);
-}
-
-void AndroidMediaRecorder::setAudioSource(AudioSource source)
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("setAudioSource", "(I)V", int(source));
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-void AndroidMediaRecorder::setCamera(AndroidCamera *camera)
-{
- QJNIObjectPrivate cam = camera->getCameraObject();
- m_mediaRecorder.callMethod<void>("setCamera", "(Landroid/hardware/Camera;)V", cam.object());
-}
-
-void AndroidMediaRecorder::setVideoEncoder(VideoEncoder encoder)
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("setVideoEncoder", "(I)V", int(encoder));
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-void AndroidMediaRecorder::setVideoEncodingBitRate(int bitRate)
-{
- m_mediaRecorder.callMethod<void>("setVideoEncodingBitRate", "(I)V", bitRate);
-}
-
-void AndroidMediaRecorder::setVideoFrameRate(int rate)
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("setVideoFrameRate", "(I)V", rate);
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-void AndroidMediaRecorder::setVideoSize(const QSize &size)
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("setVideoSize", "(II)V", size.width(), size.height());
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-void AndroidMediaRecorder::setVideoSource(VideoSource source)
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("setVideoSource", "(I)V", int(source));
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-void AndroidMediaRecorder::setOrientationHint(int degrees)
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("setOrientationHint", "(I)V", degrees);
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-void AndroidMediaRecorder::setOutputFormat(OutputFormat format)
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("setOutputFormat", "(I)V", int(format));
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-void AndroidMediaRecorder::setOutputFile(const QString &path)
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("setOutputFile",
- "(Ljava/lang/String;)V",
- QJNIObjectPrivate::fromString(path).object());
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-void AndroidMediaRecorder::setSurfaceTexture(AndroidSurfaceTexture *texture)
-{
- QJNIEnvironmentPrivate env;
- m_mediaRecorder.callMethod<void>("setPreviewDisplay",
- "(Landroid/view/Surface;)V",
- texture->surface());
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-void AndroidMediaRecorder::setSurfaceHolder(AndroidSurfaceHolder *holder)
-{
- QJNIEnvironmentPrivate env;
- QJNIObjectPrivate surfaceHolder(holder->surfaceHolder());
- QJNIObjectPrivate surface = surfaceHolder.callObjectMethod("getSurface",
- "()Landroid/view/Surface;");
- if (!surface.isValid())
- return;
-
- m_mediaRecorder.callMethod<void>("setPreviewDisplay",
- "(Landroid/view/Surface;)V",
- surface.object());
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
- }
-}
-
-bool AndroidMediaRecorder::initJNI(JNIEnv *env)
-{
- jclass clazz = QJNIEnvironmentPrivate::findClass(QtMediaRecorderListenerClassName,
- env);
-
- static const JNINativeMethod methods[] = {
- {"notifyError", "(JII)V", (void *)notifyError},
- {"notifyInfo", "(JII)V", (void *)notifyInfo}
- };
-
- if (clazz && env->RegisterNatives(clazz,
- methods,
- sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
- return false;
- }
-
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/wrappers/jni/androidmediarecorder.h b/src/plugins/android/src/wrappers/jni/androidmediarecorder.h
deleted file mode 100644
index e4b3a80ea..000000000
--- a/src/plugins/android/src/wrappers/jni/androidmediarecorder.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ANDROIDMEDIARECORDER_H
-#define ANDROIDMEDIARECORDER_H
-
-#include <qobject.h>
-#include <QtCore/private/qjni_p.h>
-#include <qsize.h>
-
-QT_BEGIN_NAMESPACE
-
-class AndroidCamera;
-class AndroidSurfaceTexture;
-class AndroidSurfaceHolder;
-
-class AndroidCamcorderProfile
-{
-public:
- enum Quality { // Needs to match CamcorderProfile
- QUALITY_LOW,
- QUALITY_HIGH,
- QUALITY_QCIF,
- QUALITY_CIF,
- QUALITY_480P,
- QUALITY_720P,
- QUALITY_1080P,
- QUALITY_QVGA
- };
-
- enum Field {
- audioBitRate,
- audioChannels,
- audioCodec,
- audioSampleRate,
- duration,
- fileFormat,
- quality,
- videoBitRate,
- videoCodec,
- videoFrameHeight,
- videoFrameRate,
- videoFrameWidth
- };
-
- static bool hasProfile(jint cameraId, Quality quality);
- static AndroidCamcorderProfile get(jint cameraId, Quality quality);
- int getValue(Field field) const;
-
-private:
- AndroidCamcorderProfile(const QJNIObjectPrivate &camcorderProfile);
- QJNIObjectPrivate m_camcorderProfile;
-};
-
-class AndroidMediaRecorder : public QObject
-{
- Q_OBJECT
-public:
- enum AudioEncoder {
- DefaultAudioEncoder = 0,
- AMR_NB_Encoder = 1,
- AMR_WB_Encoder = 2,
- AAC = 3
- };
-
- enum AudioSource {
- DefaultAudioSource = 0,
- Mic = 1,
- VoiceUplink = 2,
- VoiceDownlink = 3,
- VoiceCall = 4,
- Camcorder = 5,
- VoiceRecognition = 6
- };
-
- enum VideoEncoder {
- DefaultVideoEncoder = 0,
- H263 = 1,
- H264 = 2,
- MPEG_4_SP = 3
- };
-
- enum VideoSource {
- DefaultVideoSource = 0,
- Camera = 1
- };
-
- enum OutputFormat {
- DefaultOutputFormat = 0,
- THREE_GPP = 1,
- MPEG_4 = 2,
- AMR_NB_Format = 3,
- AMR_WB_Format = 4
- };
-
- AndroidMediaRecorder();
- ~AndroidMediaRecorder();
-
- void release();
- bool prepare();
- void reset();
-
- bool start();
- void stop();
-
- void setAudioChannels(int numChannels);
- void setAudioEncoder(AudioEncoder encoder);
- void setAudioEncodingBitRate(int bitRate);
- void setAudioSamplingRate(int samplingRate);
- void setAudioSource(AudioSource source);
-
- void setCamera(AndroidCamera *camera);
- void setVideoEncoder(VideoEncoder encoder);
- void setVideoEncodingBitRate(int bitRate);
- void setVideoFrameRate(int rate);
- void setVideoSize(const QSize &size);
- void setVideoSource(VideoSource source);
-
- void setOrientationHint(int degrees);
-
- void setOutputFormat(OutputFormat format);
- void setOutputFile(const QString &path);
-
- void setSurfaceTexture(AndroidSurfaceTexture *texture);
- void setSurfaceHolder(AndroidSurfaceHolder *holder);
-
- static bool initJNI(JNIEnv *env);
-
-Q_SIGNALS:
- void error(int what, int extra);
- void info(int what, int extra);
-
-private:
- jlong m_id;
- QJNIObjectPrivate m_mediaRecorder;
-};
-
-QT_END_NAMESPACE
-
-#endif // ANDROIDMEDIARECORDER_H
diff --git a/src/plugins/android/src/wrappers/jni/androidmultimediautils.cpp b/src/plugins/android/src/wrappers/jni/androidmultimediautils.cpp
deleted file mode 100644
index 19dfbd7d2..000000000
--- a/src/plugins/android/src/wrappers/jni/androidmultimediautils.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "androidmultimediautils.h"
-
-#include <QtCore/private/qjni_p.h>
-
-QT_BEGIN_NAMESPACE
-
-
-void AndroidMultimediaUtils::enableOrientationListener(bool enable)
-{
- QJNIObjectPrivate::callStaticMethod<void>("org/qtproject/qt/android/multimedia/QtMultimediaUtils",
- "enableOrientationListener",
- "(Z)V",
- enable);
-}
-
-int AndroidMultimediaUtils::getDeviceOrientation()
-{
- return QJNIObjectPrivate::callStaticMethod<jint>("org/qtproject/qt/android/multimedia/QtMultimediaUtils",
- "getDeviceOrientation");
-}
-
-QString AndroidMultimediaUtils::getDefaultMediaDirectory(MediaType type)
-{
- QJNIObjectPrivate path = QJNIObjectPrivate::callStaticObjectMethod("org/qtproject/qt/android/multimedia/QtMultimediaUtils",
- "getDefaultMediaDirectory",
- "(I)Ljava/lang/String;",
- jint(type));
- return path.toString();
-}
-
-void AndroidMultimediaUtils::registerMediaFile(const QString &file)
-{
- QJNIObjectPrivate::callStaticMethod<void>("org/qtproject/qt/android/multimedia/QtMultimediaUtils",
- "registerMediaFile",
- "(Ljava/lang/String;)V",
- QJNIObjectPrivate::fromString(file).object());
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/wrappers/jni/androidmultimediautils.h b/src/plugins/android/src/wrappers/jni/androidmultimediautils.h
deleted file mode 100644
index 152d849e4..000000000
--- a/src/plugins/android/src/wrappers/jni/androidmultimediautils.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ANDROIDMULTIMEDIAUTILS_H
-#define ANDROIDMULTIMEDIAUTILS_H
-
-#include <qobject.h>
-#include <QtCore/private/qjni_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class AndroidMultimediaUtils
-{
-public:
- enum MediaType {
- Music = 0,
- Movies = 1,
- DCIM = 2,
- Sounds = 3
- };
-
- static void enableOrientationListener(bool enable);
- static int getDeviceOrientation();
- static QString getDefaultMediaDirectory(MediaType type);
- static void registerMediaFile(const QString &file);
-};
-
-QT_END_NAMESPACE
-
-#endif // ANDROIDMULTIMEDIAUTILS_H
diff --git a/src/plugins/android/src/wrappers/jni/androidsurfacetexture.cpp b/src/plugins/android/src/wrappers/jni/androidsurfacetexture.cpp
deleted file mode 100644
index c5b670142..000000000
--- a/src/plugins/android/src/wrappers/jni/androidsurfacetexture.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "androidsurfacetexture.h"
-#include <QtCore/private/qjni_p.h>
-#include <QtCore/private/qjnihelpers_p.h>
-#include <QtCore/qmutex.h>
-
-QT_BEGIN_NAMESPACE
-
-static const char QtSurfaceTextureListenerClassName[] = "org/qtproject/qt/android/multimedia/QtSurfaceTextureListener";
-typedef QList<jlong> SurfaceTextures;
-Q_GLOBAL_STATIC(SurfaceTextures, g_surfaceTextures);
-Q_GLOBAL_STATIC(QMutex, g_textureMutex);
-
-// native method for QtSurfaceTexture.java
-static void notifyFrameAvailable(JNIEnv* , jobject, jlong id)
-{
- const QMutexLocker lock(g_textureMutex);
- const int idx = g_surfaceTextures->indexOf(id);
- if (idx == -1)
- return;
-
- AndroidSurfaceTexture *obj = reinterpret_cast<AndroidSurfaceTexture *>(g_surfaceTextures->at(idx));
- if (obj)
- Q_EMIT obj->frameAvailable();
-}
-
-AndroidSurfaceTexture::AndroidSurfaceTexture(quint32 texName)
- : QObject()
-{
- Q_STATIC_ASSERT(sizeof (jlong) >= sizeof (void *));
- // API level 11 or higher is required
- if (QtAndroidPrivate::androidSdkVersion() < 11) {
- qWarning("Camera preview and video playback require Android 3.0 (API level 11) or later.");
- return;
- }
-
- QJNIEnvironmentPrivate env;
- m_surfaceTexture = QJNIObjectPrivate("android/graphics/SurfaceTexture", "(I)V", jint(texName));
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif // QT_DEBUG
- env->ExceptionClear();
- }
-
- if (!m_surfaceTexture.isValid())
- return;
-
- const QMutexLocker lock(g_textureMutex);
- g_surfaceTextures->append(jlong(this));
- QJNIObjectPrivate listener(QtSurfaceTextureListenerClassName, "(J)V", jlong(this));
- setOnFrameAvailableListener(listener);
-}
-
-AndroidSurfaceTexture::~AndroidSurfaceTexture()
-{
- if (QtAndroidPrivate::androidSdkVersion() > 13 && m_surface.isValid())
- m_surface.callMethod<void>("release");
-
- if (m_surfaceTexture.isValid()) {
- release();
- const QMutexLocker lock(g_textureMutex);
- const int idx = g_surfaceTextures->indexOf(jlong(this));
- if (idx != -1)
- g_surfaceTextures->remove(idx);
- }
-}
-
-QMatrix4x4 AndroidSurfaceTexture::getTransformMatrix()
-{
- QMatrix4x4 matrix;
- if (!m_surfaceTexture.isValid())
- return matrix;
-
- QJNIEnvironmentPrivate env;
-
- jfloatArray array = env->NewFloatArray(16);
- m_surfaceTexture.callMethod<void>("getTransformMatrix", "([F)V", array);
- env->GetFloatArrayRegion(array, 0, 16, matrix.data());
- env->DeleteLocalRef(array);
-
- return matrix;
-}
-
-void AndroidSurfaceTexture::release()
-{
- if (QtAndroidPrivate::androidSdkVersion() < 14)
- return;
-
- m_surfaceTexture.callMethod<void>("release");
-}
-
-void AndroidSurfaceTexture::updateTexImage()
-{
- if (!m_surfaceTexture.isValid())
- return;
-
- m_surfaceTexture.callMethod<void>("updateTexImage");
-}
-
-jobject AndroidSurfaceTexture::surfaceTexture()
-{
- return m_surfaceTexture.object();
-}
-
-jobject AndroidSurfaceTexture::surface()
-{
- if (!m_surface.isValid()) {
- m_surface = QJNIObjectPrivate("android/view/Surface",
- "(Landroid/graphics/SurfaceTexture;)V",
- m_surfaceTexture.object());
- }
-
- return m_surface.object();
-}
-
-jobject AndroidSurfaceTexture::surfaceHolder()
-{
- if (!m_surfaceHolder.isValid()) {
- m_surfaceHolder = QJNIObjectPrivate("org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder",
- "(Landroid/view/Surface;)V",
- surface());
- }
-
- return m_surfaceHolder.object();
-}
-
-void AndroidSurfaceTexture::attachToGLContext(quint32 texName)
-{
- if (QtAndroidPrivate::androidSdkVersion() < 16 || !m_surfaceTexture.isValid())
- return;
-
- m_surfaceTexture.callMethod<void>("attachToGLContext", "(I)V", texName);
-}
-
-void AndroidSurfaceTexture::detachFromGLContext()
-{
- if (QtAndroidPrivate::androidSdkVersion() < 16 || !m_surfaceTexture.isValid())
- return;
-
- m_surfaceTexture.callMethod<void>("detachFromGLContext");
-}
-
-bool AndroidSurfaceTexture::initJNI(JNIEnv *env)
-{
- // SurfaceTexture is available since API 11.
- if (QtAndroidPrivate::androidSdkVersion() < 11)
- return false;
-
- jclass clazz = QJNIEnvironmentPrivate::findClass(QtSurfaceTextureListenerClassName,
- env);
-
- static const JNINativeMethod methods[] = {
- {"notifyFrameAvailable", "(J)V", (void *)notifyFrameAvailable}
- };
-
- if (clazz && env->RegisterNatives(clazz,
- methods,
- sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
- return false;
- }
-
- return true;
-}
-
-void AndroidSurfaceTexture::setOnFrameAvailableListener(const QJNIObjectPrivate &listener)
-{
- m_surfaceTexture.callMethod<void>("setOnFrameAvailableListener",
- "(Landroid/graphics/SurfaceTexture$OnFrameAvailableListener;)V",
- listener.object());
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/wrappers/jni/androidsurfacetexture.h b/src/plugins/android/src/wrappers/jni/androidsurfacetexture.h
deleted file mode 100644
index 911711774..000000000
--- a/src/plugins/android/src/wrappers/jni/androidsurfacetexture.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ANDROIDSURFACETEXTURE_H
-#define ANDROIDSURFACETEXTURE_H
-
-#include <qobject.h>
-#include <QtCore/private/qjni_p.h>
-
-#include <QMatrix4x4>
-
-QT_BEGIN_NAMESPACE
-
-class AndroidSurfaceTexture : public QObject
-{
- Q_OBJECT
-public:
- explicit AndroidSurfaceTexture(quint32 texName);
- ~AndroidSurfaceTexture();
-
- jobject surfaceTexture();
- jobject surface();
- jobject surfaceHolder();
- inline bool isValid() const { return m_surfaceTexture.isValid(); }
-
- QMatrix4x4 getTransformMatrix();
- void release(); // API level 14
- void updateTexImage();
-
- void attachToGLContext(quint32 texName); // API level 16
- void detachFromGLContext(); // API level 16
-
- static bool initJNI(JNIEnv *env);
-
-Q_SIGNALS:
- void frameAvailable();
-
-private:
- void setOnFrameAvailableListener(const QJNIObjectPrivate &listener);
-
- QJNIObjectPrivate m_surfaceTexture;
- QJNIObjectPrivate m_surface;
- QJNIObjectPrivate m_surfaceHolder;
-};
-
-QT_END_NAMESPACE
-
-#endif // ANDROIDSURFACETEXTURE_H
diff --git a/src/plugins/android/src/wrappers/jni/androidsurfaceview.cpp b/src/plugins/android/src/wrappers/jni/androidsurfaceview.cpp
deleted file mode 100644
index d7587f479..000000000
--- a/src/plugins/android/src/wrappers/jni/androidsurfaceview.cpp
+++ /dev/null
@@ -1,195 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "androidsurfaceview.h"
-
-#include <QtCore/private/qjnihelpers_p.h>
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qlist.h>
-#include <QtCore/qmutex.h>
-#include <QtGui/qwindow.h>
-
-QT_BEGIN_NAMESPACE
-
-static const char QtSurfaceHolderCallbackClassName[] = "org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback";
-typedef QList<AndroidSurfaceHolder *> SurfaceHolders;
-Q_GLOBAL_STATIC(SurfaceHolders, surfaceHolders)
-Q_GLOBAL_STATIC(QMutex, shLock)
-
-AndroidSurfaceHolder::AndroidSurfaceHolder(QJNIObjectPrivate object)
- : m_surfaceHolder(object)
- , m_surfaceCreated(false)
-{
- if (!m_surfaceHolder.isValid())
- return;
-
- {
- QMutexLocker locker(shLock);
- surfaceHolders->append(this);
- }
-
- QJNIObjectPrivate callback(QtSurfaceHolderCallbackClassName, "(J)V", reinterpret_cast<jlong>(this));
- m_surfaceHolder.callMethod<void>("addCallback",
- "(Landroid/view/SurfaceHolder$Callback;)V",
- callback.object());
-}
-
-AndroidSurfaceHolder::~AndroidSurfaceHolder()
-{
- QMutexLocker locker(shLock);
- const int i = surfaceHolders->indexOf(this);
- if (Q_UNLIKELY(i == -1))
- return;
-
- surfaceHolders->remove(i);
-}
-
-jobject AndroidSurfaceHolder::surfaceHolder() const
-{
- return m_surfaceHolder.object();
-}
-
-bool AndroidSurfaceHolder::isSurfaceCreated() const
-{
- QMutexLocker locker(shLock);
- return m_surfaceCreated;
-}
-
-void AndroidSurfaceHolder::handleSurfaceCreated(JNIEnv*, jobject, jlong id)
-{
- QMutexLocker locker(shLock);
- const int i = surfaceHolders->indexOf(reinterpret_cast<AndroidSurfaceHolder *>(id));
- if (Q_UNLIKELY(i == -1))
- return;
-
- (*surfaceHolders)[i]->m_surfaceCreated = true;
- Q_EMIT (*surfaceHolders)[i]->surfaceCreated();
-}
-
-void AndroidSurfaceHolder::handleSurfaceDestroyed(JNIEnv*, jobject, jlong id)
-{
- QMutexLocker locker(shLock);
- const int i = surfaceHolders->indexOf(reinterpret_cast<AndroidSurfaceHolder *>(id));
- if (Q_UNLIKELY(i == -1))
- return;
-
- (*surfaceHolders)[i]->m_surfaceCreated = false;
-}
-
-bool AndroidSurfaceHolder::initJNI(JNIEnv *env)
-{
- jclass clazz = QJNIEnvironmentPrivate::findClass(QtSurfaceHolderCallbackClassName,
- env);
-
- static const JNINativeMethod methods[] = {
- {"notifySurfaceCreated", "(J)V", (void *)AndroidSurfaceHolder::handleSurfaceCreated},
- {"notifySurfaceDestroyed", "(J)V", (void *)AndroidSurfaceHolder::handleSurfaceDestroyed}
- };
-
- if (clazz && env->RegisterNatives(clazz,
- methods,
- sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
- return false;
- }
-
- return true;
-}
-
-AndroidSurfaceView::AndroidSurfaceView()
- : m_window(0)
- , m_surfaceHolder(0)
- , m_pendingVisible(-1)
-{
- QtAndroidPrivate::runOnAndroidThreadSync([this] {
- m_surfaceView = QJNIObjectPrivate("android/view/SurfaceView",
- "(Landroid/content/Context;)V",
- QtAndroidPrivate::activity());
- }, QJNIEnvironmentPrivate());
-
- Q_ASSERT(m_surfaceView.isValid());
-
- QJNIObjectPrivate holder = m_surfaceView.callObjectMethod("getHolder",
- "()Landroid/view/SurfaceHolder;");
- if (!holder.isValid()) {
- m_surfaceView = QJNIObjectPrivate();
- } else {
- m_surfaceHolder = new AndroidSurfaceHolder(holder);
- connect(m_surfaceHolder, &AndroidSurfaceHolder::surfaceCreated,
- this, &AndroidSurfaceView::surfaceCreated);
- { // Lock now to avoid a race with handleSurfaceCreated()
- QMutexLocker locker(shLock);
- m_window = QWindow::fromWinId(WId(m_surfaceView.object()));
-
- if (m_pendingVisible != -1)
- m_window->setVisible(m_pendingVisible);
- if (m_pendingGeometry.isValid())
- m_window->setGeometry(m_pendingGeometry);
- }
- }
-}
-
-AndroidSurfaceView::~AndroidSurfaceView()
-{
- delete m_surfaceHolder;
- delete m_window;
-}
-
-AndroidSurfaceHolder *AndroidSurfaceView::holder() const
-{
- return m_surfaceHolder;
-}
-
-void AndroidSurfaceView::setVisible(bool v)
-{
- if (m_window)
- m_window->setVisible(v);
- else
- m_pendingVisible = int(v);
-}
-
-void AndroidSurfaceView::setGeometry(int x, int y, int width, int height)
-{
- if (m_window)
- m_window->setGeometry(x, y, width, height);
- else
- m_pendingGeometry = QRect(x, y, width, height);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/android/src/wrappers/jni/androidsurfaceview.h b/src/plugins/android/src/wrappers/jni/androidsurfaceview.h
deleted file mode 100644
index ef603061d..000000000
--- a/src/plugins/android/src/wrappers/jni/androidsurfaceview.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ANDROIDSURFACEVIEW_H
-#define ANDROIDSURFACEVIEW_H
-
-#include <QtCore/private/qjni_p.h>
-#include <qrect.h>
-#include <QtCore/qrunnable.h>
-
-QT_BEGIN_NAMESPACE
-
-class QWindow;
-
-class AndroidSurfaceHolder : public QObject
-{
- Q_OBJECT
-public:
- ~AndroidSurfaceHolder();
-
- jobject surfaceHolder() const;
- bool isSurfaceCreated() const;
-
- static bool initJNI(JNIEnv *env);
-
-Q_SIGNALS:
- void surfaceCreated();
-
-private:
- AndroidSurfaceHolder(QJNIObjectPrivate object);
-
- static void handleSurfaceCreated(JNIEnv*, jobject, jlong id);
- static void handleSurfaceDestroyed(JNIEnv*, jobject, jlong id);
-
- QJNIObjectPrivate m_surfaceHolder;
- bool m_surfaceCreated;
-
- friend class AndroidSurfaceView;
-};
-
-class AndroidSurfaceView : public QObject
-{
- Q_OBJECT
-public:
- AndroidSurfaceView();
- ~AndroidSurfaceView();
-
- AndroidSurfaceHolder *holder() const;
-
- void setVisible(bool v);
- void setGeometry(int x, int y, int width, int height);
-
-Q_SIGNALS:
- void surfaceCreated();
-
-private:
- QJNIObjectPrivate m_surfaceView;
- QWindow *m_window;
- AndroidSurfaceHolder *m_surfaceHolder;
- int m_pendingVisible;
- QRect m_pendingGeometry;
-};
-
-QT_END_NAMESPACE
-
-#endif // ANDROIDSURFACEVIEW_H
diff --git a/src/plugins/android/src/wrappers/jni/jni.pri b/src/plugins/android/src/wrappers/jni/jni.pri
deleted file mode 100644
index 930d7e922..000000000
--- a/src/plugins/android/src/wrappers/jni/jni.pri
+++ /dev/null
@@ -1,21 +0,0 @@
-QT += core-private
-
-INCLUDEPATH += $$PWD
-
-HEADERS += \
- $$PWD/androidmediaplayer.h \
- $$PWD/androidsurfacetexture.h \
- $$PWD/androidmediametadataretriever.h \
- $$PWD/androidcamera.h \
- $$PWD/androidmultimediautils.h \
- $$PWD/androidmediarecorder.h \
- $$PWD/androidsurfaceview.h
-
-SOURCES += \
- $$PWD/androidmediaplayer.cpp \
- $$PWD/androidsurfacetexture.cpp \
- $$PWD/androidmediametadataretriever.cpp \
- $$PWD/androidcamera.cpp \
- $$PWD/androidmultimediautils.cpp \
- $$PWD/androidmediarecorder.cpp \
- $$PWD/androidsurfaceview.cpp
diff --git a/src/plugins/audiocapture/audiocapture.json b/src/plugins/audiocapture/audiocapture.json
deleted file mode 100644
index 4c7673da2..000000000
--- a/src/plugins/audiocapture/audiocapture.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["audiocapture"],
- "Services": ["org.qt-project.qt.audiosource"]
-}
diff --git a/src/plugins/audiocapture/audiocapture.pro b/src/plugins/audiocapture/audiocapture.pro
deleted file mode 100644
index ba2e5c802..000000000
--- a/src/plugins/audiocapture/audiocapture.pro
+++ /dev/null
@@ -1,27 +0,0 @@
-TARGET = qtmedia_audioengine
-QT += multimedia-private
-
-HEADERS += audioencodercontrol.h \
- audiocontainercontrol.h \
- audiomediarecordercontrol.h \
- audioinputselector.h \
- audiocaptureservice.h \
- audiocaptureserviceplugin.h \
- audiocapturesession.h \
- audiocaptureprobecontrol.h
-
-SOURCES += audioencodercontrol.cpp \
- audiocontainercontrol.cpp \
- audiomediarecordercontrol.cpp \
- audioinputselector.cpp \
- audiocaptureservice.cpp \
- audiocaptureserviceplugin.cpp \
- audiocapturesession.cpp \
- audiocaptureprobecontrol.cpp
-
-OTHER_FILES += \
- audiocapture.json
-
-PLUGIN_TYPE = mediaservice
-PLUGIN_CLASS_NAME = AudioCaptureServicePlugin
-load(qt_plugin)
diff --git a/src/plugins/audiocapture/audiocaptureprobecontrol.cpp b/src/plugins/audiocapture/audiocaptureprobecontrol.cpp
deleted file mode 100644
index dbd0da0a1..000000000
--- a/src/plugins/audiocapture/audiocaptureprobecontrol.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "audiocaptureprobecontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-AudioCaptureProbeControl::AudioCaptureProbeControl(QObject *parent):
- QMediaAudioProbeControl(parent)
-{
-}
-
-AudioCaptureProbeControl::~AudioCaptureProbeControl()
-{
-}
-
-void AudioCaptureProbeControl::bufferProbed(const char *data, quint32 size, const QAudioFormat& format)
-{
- if (!format.isValid())
- return;
-
- QAudioBuffer audioBuffer = QAudioBuffer(QByteArray::fromRawData(data, size), format);
- QMetaObject::invokeMethod(this, "audioBufferProbed", Qt::QueuedConnection, Q_ARG(QAudioBuffer, audioBuffer));
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiocaptureprobecontrol.h b/src/plugins/audiocapture/audiocaptureprobecontrol.h
deleted file mode 100644
index 00a21f031..000000000
--- a/src/plugins/audiocapture/audiocaptureprobecontrol.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AUDIOCAPTUREPROBECONTROL_H
-#define AUDIOCAPTUREPROBECONTROL_H
-
-#include <qmediaaudioprobecontrol.h>
-#include <QtCore/qmutex.h>
-#include <qaudiobuffer.h>
-
-QT_BEGIN_NAMESPACE
-
-class AudioCaptureProbeControl : public QMediaAudioProbeControl
-{
- Q_OBJECT
-public:
- explicit AudioCaptureProbeControl(QObject *parent);
- virtual ~AudioCaptureProbeControl();
-
- void bufferProbed(const char *data, quint32 size, const QAudioFormat& format);
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/audiocapture/audiocaptureservice.cpp b/src/plugins/audiocapture/audiocaptureservice.cpp
deleted file mode 100644
index f06871519..000000000
--- a/src/plugins/audiocapture/audiocaptureservice.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "audiocaptureservice.h"
-#include "audiocapturesession.h"
-#include "audioinputselector.h"
-#include "audioencodercontrol.h"
-#include "audiocontainercontrol.h"
-#include "audiomediarecordercontrol.h"
-#include "audiocaptureprobecontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-AudioCaptureService::AudioCaptureService(QObject *parent):
- QMediaService(parent)
-{
- m_session = new AudioCaptureSession(this);
- m_encoderControl = new AudioEncoderControl(m_session);
- m_containerControl = new AudioContainerControl(m_session);
- m_mediaControl = new AudioMediaRecorderControl(m_session);
- m_inputSelector = new AudioInputSelector(m_session);
-}
-
-AudioCaptureService::~AudioCaptureService()
-{
- delete m_encoderControl;
- delete m_containerControl;
- delete m_inputSelector;
- delete m_mediaControl;
- delete m_session;
-}
-
-QMediaControl *AudioCaptureService::requestControl(const char *name)
-{
- if (qstrcmp(name,QMediaRecorderControl_iid) == 0)
- return m_mediaControl;
-
- if (qstrcmp(name,QAudioEncoderSettingsControl_iid) == 0)
- return m_encoderControl;
-
- if (qstrcmp(name,QAudioInputSelectorControl_iid) == 0)
- return m_inputSelector;
-
- if (qstrcmp(name,QMediaContainerControl_iid) == 0)
- return m_containerControl;
-
- if (qstrcmp(name,QMediaAudioProbeControl_iid) == 0) {
- AudioCaptureProbeControl *probe = new AudioCaptureProbeControl(this);
- m_session->addProbe(probe);
- return probe;
- }
-
- return 0;
-}
-
-void AudioCaptureService::releaseControl(QMediaControl *control)
-{
- Q_UNUSED(control);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiocaptureservice.h b/src/plugins/audiocapture/audiocaptureservice.h
deleted file mode 100644
index fa2a35feb..000000000
--- a/src/plugins/audiocapture/audiocaptureservice.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AUDIOCAPTURESERVICE_H
-#define AUDIOCAPTURESERVICE_H
-
-#include <QtCore/qobject.h>
-
-#include "qmediaservice.h"
-
-QT_BEGIN_NAMESPACE
-
-class AudioCaptureSession;
-class AudioEncoderControl;
-class AudioContainerControl;
-class AudioMediaRecorderControl;
-class AudioInputSelector;
-
-class AudioCaptureService : public QMediaService
-{
- Q_OBJECT
-public:
- AudioCaptureService(QObject *parent = 0);
- ~AudioCaptureService();
-
- QMediaControl *requestControl(const char *interface);
- void releaseControl(QMediaControl *control);
-private:
- AudioCaptureSession *m_session;
- AudioEncoderControl *m_encoderControl;
- AudioContainerControl *m_containerControl;
- AudioInputSelector *m_inputSelector;
- AudioMediaRecorderControl *m_mediaControl;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/audiocapture/audiocaptureserviceplugin.cpp b/src/plugins/audiocapture/audiocaptureserviceplugin.cpp
deleted file mode 100644
index f45e4b7c5..000000000
--- a/src/plugins/audiocapture/audiocaptureserviceplugin.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qstring.h>
-
-#include "audiocaptureserviceplugin.h"
-#include "audiocaptureservice.h"
-
-#include "qmediaserviceproviderplugin.h"
-
-QT_BEGIN_NAMESPACE
-
-QMediaService* AudioCaptureServicePlugin::create(QString const& key)
-{
- if (key == QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE))
- return new AudioCaptureService;
-
- return 0;
-}
-
-void AudioCaptureServicePlugin::release(QMediaService *service)
-{
- delete service;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiocaptureserviceplugin.h b/src/plugins/audiocapture/audiocaptureserviceplugin.h
deleted file mode 100644
index 8d2e41924..000000000
--- a/src/plugins/audiocapture/audiocaptureserviceplugin.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef AUDIOCAPTURESERVICEPLUGIN_H
-#define AUDIOCAPTURESERVICEPLUGIN_H
-
-#include "qmediaserviceproviderplugin.h"
-
-QT_BEGIN_NAMESPACE
-
-class AudioCaptureServicePlugin : public QMediaServiceProviderPlugin
-{
- Q_OBJECT
-
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "audiocapture.json")
-
-public:
- QMediaService* create(QString const& key);
- void release(QMediaService *service);
-};
-
-QT_END_NAMESPACE
-
-#endif // AUDIOCAPTURESERVICEPLUGIN_H
diff --git a/src/plugins/audiocapture/audiocapturesession.cpp b/src/plugins/audiocapture/audiocapturesession.cpp
deleted file mode 100644
index 9bdb5a92d..000000000
--- a/src/plugins/audiocapture/audiocapturesession.cpp
+++ /dev/null
@@ -1,458 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qdir.h>
-#include <qaudiodeviceinfo.h>
-
-#include "qmediarecorder.h"
-
-#include "audiocapturesession.h"
-#include "audiocaptureprobecontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-void FileProbeProxy::startProbes(const QAudioFormat &format)
-{
- m_format = format;
-}
-
-void FileProbeProxy::stopProbes()
-{
- m_format = QAudioFormat();
-}
-
-void FileProbeProxy::addProbe(AudioCaptureProbeControl *probe)
-{
- QMutexLocker locker(&m_probeMutex);
-
- if (m_probes.contains(probe))
- return;
-
- m_probes.append(probe);
-}
-
-void FileProbeProxy::removeProbe(AudioCaptureProbeControl *probe)
-{
- QMutexLocker locker(&m_probeMutex);
- m_probes.removeOne(probe);
-}
-
-qint64 FileProbeProxy::writeData(const char *data, qint64 len)
-{
- if (m_format.isValid()) {
- QMutexLocker locker(&m_probeMutex);
-
- for (AudioCaptureProbeControl* probe : qAsConst(m_probes))
- probe->bufferProbed(data, len, m_format);
- }
-
- return QFile::writeData(data, len);
-}
-
-AudioCaptureSession::AudioCaptureSession(QObject *parent)
- : QObject(parent)
- , m_state(QMediaRecorder::StoppedState)
- , m_status(QMediaRecorder::UnloadedStatus)
- , m_audioInput(0)
- , m_deviceInfo(QAudioDeviceInfo::defaultInputDevice())
- , m_wavFile(true)
- , m_volume(1.0)
- , m_muted(false)
-{
- m_format = m_deviceInfo.preferredFormat();
-}
-
-AudioCaptureSession::~AudioCaptureSession()
-{
- setState(QMediaRecorder::StoppedState);
-}
-
-QAudioFormat AudioCaptureSession::format() const
-{
- return m_format;
-}
-
-void AudioCaptureSession::setFormat(const QAudioFormat &format)
-{
- m_format = format;
-}
-
-void AudioCaptureSession::setContainerFormat(const QString &formatMimeType)
-{
- m_wavFile = (formatMimeType.isEmpty()
- || QString::compare(formatMimeType, QLatin1String("audio/x-wav")) == 0);
-}
-
-QString AudioCaptureSession::containerFormat() const
-{
- if (m_wavFile)
- return QStringLiteral("audio/x-wav");
-
- return QStringLiteral("audio/x-raw");
-}
-
-QUrl AudioCaptureSession::outputLocation() const
-{
- return m_actualOutputLocation;
-}
-
-bool AudioCaptureSession::setOutputLocation(const QUrl& location)
-{
- if (m_requestedOutputLocation == location)
- return false;
-
- m_actualOutputLocation = QUrl();
- m_requestedOutputLocation = location;
-
- if (m_requestedOutputLocation.isEmpty())
- return true;
-
- if (m_requestedOutputLocation.isValid() && (m_requestedOutputLocation.isLocalFile()
- || m_requestedOutputLocation.isRelative())) {
- emit actualLocationChanged(m_requestedOutputLocation);
- return true;
- }
-
- m_requestedOutputLocation = QUrl();
- return false;
-}
-
-qint64 AudioCaptureSession::position() const
-{
- if (m_audioInput)
- return m_audioInput->processedUSecs() / 1000;
- return 0;
-}
-
-void AudioCaptureSession::setState(QMediaRecorder::State state)
-{
- if (m_state == state)
- return;
-
- m_state = state;
- emit stateChanged(m_state);
-
- switch (m_state) {
- case QMediaRecorder::StoppedState:
- stop();
- break;
- case QMediaRecorder::PausedState:
- pause();
- break;
- case QMediaRecorder::RecordingState:
- record();
- break;
- }
-}
-
-QMediaRecorder::State AudioCaptureSession::state() const
-{
- return m_state;
-}
-
-void AudioCaptureSession::setStatus(QMediaRecorder::Status status)
-{
- if (m_status == status)
- return;
-
- m_status = status;
- emit statusChanged(m_status);
-}
-
-QMediaRecorder::Status AudioCaptureSession::status() const
-{
- return m_status;
-}
-
-QDir AudioCaptureSession::defaultDir() const
-{
- QStringList dirCandidates;
-
- dirCandidates << QDir::home().filePath("Documents");
- dirCandidates << QDir::home().filePath("My Documents");
- dirCandidates << QDir::homePath();
- dirCandidates << QDir::currentPath();
- dirCandidates << QDir::tempPath();
-
- for (const QString &path : qAsConst(dirCandidates)) {
- QDir dir(path);
- if (dir.exists() && QFileInfo(path).isWritable())
- return dir;
- }
-
- return QDir();
-}
-
-QString AudioCaptureSession::generateFileName(const QString &requestedName,
- const QString &extension) const
-{
- if (requestedName.isEmpty())
- return generateFileName(defaultDir(), extension);
-
- QString path = requestedName;
-
- if (QFileInfo(path).isRelative())
- path = defaultDir().absoluteFilePath(path);
-
- if (QFileInfo(path).isDir())
- return generateFileName(QDir(path), extension);
-
- if (!path.endsWith(extension))
- path.append(QString(".%1").arg(extension));
-
- return path;
-}
-
-QString AudioCaptureSession::generateFileName(const QDir &dir,
- const QString &ext) const
-{
- int lastClip = 0;
- const auto list = dir.entryList(QStringList() << QString("clip_*.%1").arg(ext));
- for (const QString &fileName : list) {
- int imgNumber = QStringView{fileName}.mid(5, fileName.size()-6-ext.length()).toInt();
- lastClip = qMax(lastClip, imgNumber);
- }
-
- QString name = QString("clip_%1.%2").arg(lastClip+1,
- 4, //fieldWidth
- 10,
- QLatin1Char('0')).arg(ext);
-
- return dir.absoluteFilePath(name);
-}
-
-void AudioCaptureSession::record()
-{
- if (m_status == QMediaRecorder::PausedStatus) {
- m_audioInput->resume();
- } else {
- if (m_deviceInfo.isNull()) {
- emit error(QMediaRecorder::ResourceError,
- QStringLiteral("No input device available."));
- m_state = QMediaRecorder::StoppedState;
- emit stateChanged(m_state);
- setStatus(QMediaRecorder::UnavailableStatus);
- return;
- }
-
- setStatus(QMediaRecorder::LoadingStatus);
-
- m_format = m_deviceInfo.nearestFormat(m_format);
- m_audioInput = new QAudioInput(m_deviceInfo, m_format);
- connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)),
- this, SLOT(audioInputStateChanged(QAudio::State)));
- connect(m_audioInput, SIGNAL(notify()),
- this, SLOT(notify()));
-
-
- QString filePath = generateFileName(
- m_requestedOutputLocation.isLocalFile() ? m_requestedOutputLocation.toLocalFile()
- : m_requestedOutputLocation.toString(),
- m_wavFile ? QLatin1String("wav")
- : QLatin1String("raw"));
-
- m_actualOutputLocation = QUrl::fromLocalFile(filePath);
- if (m_actualOutputLocation != m_requestedOutputLocation)
- emit actualLocationChanged(m_actualOutputLocation);
-
- file.setFileName(filePath);
-
- setStatus(QMediaRecorder::LoadedStatus);
- setStatus(QMediaRecorder::StartingStatus);
-
- if (file.open(QIODevice::WriteOnly)) {
- if (m_wavFile) {
- memset(&header,0,sizeof(CombinedHeader));
- memcpy(header.riff.descriptor.id,"RIFF",4);
- header.riff.descriptor.size = 0xFFFFFFFF; // This should be updated on stop(), filesize-8
- memcpy(header.riff.type,"WAVE",4);
- memcpy(header.wave.descriptor.id,"fmt ",4);
- header.wave.descriptor.size = 16;
- header.wave.audioFormat = 1; // for PCM data
- header.wave.numChannels = m_format.channelCount();
- header.wave.sampleRate = m_format.sampleRate();
- header.wave.byteRate = m_format.sampleRate()*m_format.channelCount()*m_format.sampleSize()/8;
- header.wave.blockAlign = m_format.channelCount()*m_format.sampleSize()/8;
- header.wave.bitsPerSample = m_format.sampleSize();
- memcpy(header.data.descriptor.id,"data",4);
- header.data.descriptor.size = 0xFFFFFFFF; // This should be updated on stop(),samples*channels*sampleSize/8
- file.write((char*)&header,sizeof(CombinedHeader));
- }
-
- setVolumeHelper(m_muted ? 0 : m_volume);
-
- file.startProbes(m_format);
- m_audioInput->start(qobject_cast<QIODevice*>(&file));
- } else {
- delete m_audioInput;
- m_audioInput = 0;
- emit error(QMediaRecorder::ResourceError,
- QStringLiteral("Can't open output location"));
- m_state = QMediaRecorder::StoppedState;
- emit stateChanged(m_state);
- setStatus(QMediaRecorder::UnloadedStatus);
- }
- }
-}
-
-void AudioCaptureSession::pause()
-{
- m_audioInput->suspend();
-}
-
-void AudioCaptureSession::stop()
-{
- if(m_audioInput) {
- m_audioInput->stop();
- file.stopProbes();
- file.close();
- if (m_wavFile) {
- qint32 fileSize = file.size();
- file.open(QIODevice::ReadWrite | QIODevice::Unbuffered);
- file.read((char*)&header,sizeof(CombinedHeader));
- header.riff.descriptor.size = fileSize - 8; // The RIFF chunk size is the file size minus
- // the first two RIFF fields (8 bytes)
- header.data.descriptor.size = fileSize - 44; // dataSize = fileSize - headerSize (44 bytes)
- file.seek(0);
- file.write((char*)&header,sizeof(CombinedHeader));
- file.close();
- }
- delete m_audioInput;
- m_audioInput = 0;
- setStatus(QMediaRecorder::UnloadedStatus);
- }
-}
-
-void AudioCaptureSession::addProbe(AudioCaptureProbeControl *probe)
-{
- file.addProbe(probe);
-}
-
-void AudioCaptureSession::removeProbe(AudioCaptureProbeControl *probe)
-{
- file.removeProbe(probe);
-}
-
-void AudioCaptureSession::audioInputStateChanged(QAudio::State state)
-{
- switch(state) {
- case QAudio::ActiveState:
- setStatus(QMediaRecorder::RecordingStatus);
- break;
- case QAudio::SuspendedState:
- setStatus(QMediaRecorder::PausedStatus);
- break;
- case QAudio::StoppedState:
- setStatus(QMediaRecorder::FinalizingStatus);
- break;
- default:
- break;
- }
-}
-
-void AudioCaptureSession::notify()
-{
- emit positionChanged(position());
-}
-
-void AudioCaptureSession::setCaptureDevice(const QString &deviceName)
-{
- m_captureDevice = deviceName;
-
- QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
- for (int i = 0; i < devices.size(); ++i) {
- QAudioDeviceInfo info = devices.at(i);
- if (m_captureDevice == info.deviceName()){
- m_deviceInfo = info;
- return;
- }
- }
- m_deviceInfo = QAudioDeviceInfo::defaultInputDevice();
-}
-
-qreal AudioCaptureSession::volume() const
-{
- return m_volume;
-}
-
-bool AudioCaptureSession::isMuted() const
-{
- return m_muted;
-}
-
-void AudioCaptureSession::setVolume(qreal v)
-{
- qreal boundedVolume = qBound(qreal(0), v, qreal(1));
-
- if (m_volume == boundedVolume)
- return;
-
- m_volume = boundedVolume;
-
- if (!m_muted)
- setVolumeHelper(m_volume);
-
- emit volumeChanged(m_volume);
-}
-
-void AudioCaptureSession::setMuted(bool muted)
-{
- if (m_muted == muted)
- return;
-
- m_muted = muted;
-
- setVolumeHelper(m_muted ? 0 : m_volume);
-
- emit mutedChanged(m_muted);
-}
-
-void AudioCaptureSession::setVolumeHelper(qreal volume)
-{
- if (!m_audioInput)
- return;
-
- m_audioInput->setVolume(volume);
-}
-
-
-
-QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiocapturesession.h b/src/plugins/audiocapture/audiocapturesession.h
deleted file mode 100644
index 3db7a7595..000000000
--- a/src/plugins/audiocapture/audiocapturesession.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AUDIOCAPTURESESSION_H
-#define AUDIOCAPTURESESSION_H
-
-#include <QFile>
-#include <QUrl>
-#include <QDir>
-#include <QMutex>
-
-#include "audioencodercontrol.h"
-#include "audioinputselector.h"
-#include "audiomediarecordercontrol.h"
-
-#include <qaudioformat.h>
-#include <qaudioinput.h>
-#include <qaudiodeviceinfo.h>
-
-QT_BEGIN_NAMESPACE
-
-class AudioCaptureProbeControl;
-
-class FileProbeProxy: public QFile {
-public:
- void startProbes(const QAudioFormat& format);
- void stopProbes();
- void addProbe(AudioCaptureProbeControl *probe);
- void removeProbe(AudioCaptureProbeControl *probe);
-
-protected:
- virtual qint64 writeData(const char *data, qint64 len);
-
-private:
- QAudioFormat m_format;
- QList<AudioCaptureProbeControl*> m_probes;
- QMutex m_probeMutex;
-};
-
-
-class AudioCaptureSession : public QObject
-{
- Q_OBJECT
-
-public:
- AudioCaptureSession(QObject *parent = 0);
- ~AudioCaptureSession();
-
- QAudioFormat format() const;
- void setFormat(const QAudioFormat &format);
-
- QString containerFormat() const;
- void setContainerFormat(const QString &formatMimeType);
-
- QUrl outputLocation() const;
- bool setOutputLocation(const QUrl& location);
-
- qint64 position() const;
-
- void setState(QMediaRecorder::State state);
- QMediaRecorder::State state() const;
- QMediaRecorder::Status status() const;
-
- void addProbe(AudioCaptureProbeControl *probe);
- void removeProbe(AudioCaptureProbeControl *probe);
-
- void setCaptureDevice(const QString &deviceName);
-
- void setVolume(qreal v);
- qreal volume() const;
-
- void setMuted(bool muted);
- bool isMuted() const;
-
-signals:
- void stateChanged(QMediaRecorder::State state);
- void statusChanged(QMediaRecorder::Status status);
- void positionChanged(qint64 position);
- void actualLocationChanged(const QUrl &location);
- void volumeChanged(qreal volume);
- void mutedChanged(bool muted);
- void error(int error, const QString &errorString);
-
-private slots:
- void audioInputStateChanged(QAudio::State state);
- void notify();
-
-private:
- void record();
- void pause();
- void stop();
-
- void setStatus(QMediaRecorder::Status status);
-
- void setVolumeHelper(qreal volume);
-
- QDir defaultDir() const;
- QString generateFileName(const QString &requestedName,
- const QString &extension) const;
- QString generateFileName(const QDir &dir, const QString &extension) const;
-
- FileProbeProxy file;
- QString m_captureDevice;
- QUrl m_requestedOutputLocation;
- QUrl m_actualOutputLocation;
- QMediaRecorder::State m_state;
- QMediaRecorder::Status m_status;
- QAudioInput *m_audioInput;
- QAudioDeviceInfo m_deviceInfo;
- QAudioFormat m_format;
- bool m_wavFile;
- qreal m_volume;
- bool m_muted;
-
- // WAV header stuff
-
- struct chunk
- {
- char id[4];
- quint32 size;
- };
-
- struct RIFFHeader
- {
- chunk descriptor;
- char type[4];
- };
-
- struct WAVEHeader
- {
- chunk descriptor;
- quint16 audioFormat; // PCM = 1
- quint16 numChannels;
- quint32 sampleRate;
- quint32 byteRate;
- quint16 blockAlign;
- quint16 bitsPerSample;
- };
-
- struct DATAHeader
- {
- chunk descriptor;
-// quint8 data[];
- };
-
- struct CombinedHeader
- {
- RIFFHeader riff;
- WAVEHeader wave;
- DATAHeader data;
- };
-
- CombinedHeader header;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/audiocapture/audiocontainercontrol.cpp b/src/plugins/audiocapture/audiocontainercontrol.cpp
deleted file mode 100644
index fd7d12e65..000000000
--- a/src/plugins/audiocapture/audiocontainercontrol.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "audiocontainercontrol.h"
-#include "audiocapturesession.h"
-
-QT_BEGIN_NAMESPACE
-
-AudioContainerControl::AudioContainerControl(QObject *parent)
- :QMediaContainerControl(parent)
-{
- m_session = qobject_cast<AudioCaptureSession*>(parent);
-}
-
-AudioContainerControl::~AudioContainerControl()
-{
-}
-
-QStringList AudioContainerControl::supportedContainers() const
-{
- return QStringList() << QStringLiteral("audio/x-wav")
- << QStringLiteral("audio/x-raw");
-}
-
-QString AudioContainerControl::containerFormat() const
-{
- return m_session->containerFormat();
-}
-
-void AudioContainerControl::setContainerFormat(const QString &formatMimeType)
-{
- if (formatMimeType.isEmpty() || supportedContainers().contains(formatMimeType))
- m_session->setContainerFormat(formatMimeType);
-}
-
-QString AudioContainerControl::containerDescription(const QString &formatMimeType) const
-{
- if (QString::compare(formatMimeType, QLatin1String("audio/x-raw")) == 0)
- return tr("RAW (headerless) file format");
- if (QString::compare(formatMimeType, QLatin1String("audio/x-wav")) == 0)
- return tr("WAV file format");
-
- return QString();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiocontainercontrol.h b/src/plugins/audiocapture/audiocontainercontrol.h
deleted file mode 100644
index 169b3c189..000000000
--- a/src/plugins/audiocapture/audiocontainercontrol.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AUDIOCONTAINERCONTROL_H
-#define AUDIOCONTAINERCONTROL_H
-
-#include "qmediacontainercontrol.h"
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmap.h>
-
-QT_BEGIN_NAMESPACE
-
-class AudioCaptureSession;
-
-class AudioContainerControl : public QMediaContainerControl
-{
- Q_OBJECT
-public:
- AudioContainerControl(QObject *parent);
- virtual ~AudioContainerControl();
-
- QStringList supportedContainers() const;
- QString containerFormat() const;
- void setContainerFormat(const QString &formatMimeType);
- QString containerDescription(const QString &formatMimeType) const;
-
-private:
- AudioCaptureSession* m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/audiocapture/audioencodercontrol.cpp b/src/plugins/audiocapture/audioencodercontrol.cpp
deleted file mode 100644
index 6fc519cef..000000000
--- a/src/plugins/audiocapture/audioencodercontrol.cpp
+++ /dev/null
@@ -1,174 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "audioencodercontrol.h"
-#include "audiocapturesession.h"
-
-#include <qaudioformat.h>
-
-#include <QtCore/qdebug.h>
-
-#include <algorithm>
-
-QT_BEGIN_NAMESPACE
-
-static QAudioFormat audioSettingsToAudioFormat(const QAudioEncoderSettings &settings)
-{
- QAudioFormat fmt;
- fmt.setCodec(settings.codec());
- fmt.setChannelCount(settings.channelCount());
- fmt.setSampleRate(settings.sampleRate());
- int sampleSize = 16;
- if (settings.bitRate() && settings.channelCount() && settings.sampleRate())
- sampleSize = settings.bitRate() / settings.channelCount() / settings.sampleRate();
- fmt.setSampleSize(sampleSize);
- fmt.setSampleType(sampleSize == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt);
-
- fmt.setByteOrder(QAudioDeviceInfo::defaultInputDevice().preferredFormat().byteOrder());
- return fmt;
-}
-
-static QAudioEncoderSettings audioFormatToAudioSettings(const QAudioFormat &format)
-{
- QAudioEncoderSettings settings;
- settings.setCodec(format.codec());
- settings.setChannelCount(format.channelCount());
- settings.setSampleRate(format.sampleRate());
- settings.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
- settings.setBitRate(format.channelCount()
- * format.sampleSize()
- * format.sampleRate());
- return settings;
-}
-
-AudioEncoderControl::AudioEncoderControl(QObject *parent)
- :QAudioEncoderSettingsControl(parent)
-{
- m_session = qobject_cast<AudioCaptureSession*>(parent);
- update();
-}
-
-AudioEncoderControl::~AudioEncoderControl()
-{
-}
-
-QStringList AudioEncoderControl::supportedAudioCodecs() const
-{
- return QStringList() << QStringLiteral("audio/pcm");
-}
-
-QString AudioEncoderControl::codecDescription(const QString &codecName) const
-{
- if (QString::compare(codecName, QLatin1String("audio/pcm")) == 0)
- return tr("Linear PCM audio data");
-
- return QString();
-}
-
-QList<int> AudioEncoderControl::supportedSampleRates(const QAudioEncoderSettings &settings, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- if (settings.codec().isEmpty() || settings.codec() == QLatin1String("audio/pcm"))
- return m_sampleRates;
-
- return QList<int>();
-}
-
-QAudioEncoderSettings AudioEncoderControl::audioSettings() const
-{
- return audioFormatToAudioSettings(m_session->format());
-}
-
-void AudioEncoderControl::setAudioSettings(const QAudioEncoderSettings &settings)
-{
- QAudioFormat fmt = audioSettingsToAudioFormat(settings);
-
- if (settings.encodingMode() == QMultimedia::ConstantQualityEncoding) {
- fmt.setCodec("audio/pcm");
- switch (settings.quality()) {
- case QMultimedia::VeryLowQuality:
- fmt.setSampleSize(8);
- fmt.setSampleRate(8000);
- fmt.setSampleType(QAudioFormat::UnSignedInt);
- break;
- case QMultimedia::LowQuality:
- fmt.setSampleSize(8);
- fmt.setSampleRate(22050);
- fmt.setSampleType(QAudioFormat::UnSignedInt);
- break;
- case QMultimedia::HighQuality:
- fmt.setSampleSize(16);
- fmt.setSampleRate(48000);
- fmt.setSampleType(QAudioFormat::SignedInt);
- break;
- case QMultimedia::VeryHighQuality:
- fmt.setSampleSize(16);
- fmt.setSampleRate(96000);
- fmt.setSampleType(QAudioFormat::SignedInt);
- break;
- case QMultimedia::NormalQuality:
- default:
- fmt.setSampleSize(16);
- fmt.setSampleRate(44100);
- fmt.setSampleType(QAudioFormat::SignedInt);
- break;
- }
- }
-
- m_session->setFormat(fmt);
-}
-
-void AudioEncoderControl::update()
-{
- m_sampleRates.clear();
- QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
- for (int i = 0; i < devices.size(); ++i) {
- QList<int> rates = devices.at(i).supportedSampleRates();
- for (int j = 0; j < rates.size(); ++j) {
- int rate = rates.at(j);
- if (!m_sampleRates.contains(rate))
- m_sampleRates.append(rate);
- }
- }
- std::sort(m_sampleRates.begin(), m_sampleRates.end());
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audioencodercontrol.h b/src/plugins/audiocapture/audioencodercontrol.h
deleted file mode 100644
index 30de92e96..000000000
--- a/src/plugins/audiocapture/audioencodercontrol.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AUDIOENCODERCONTROL_H
-#define AUDIOENCODERCONTROL_H
-
-#include "qaudioencodersettingscontrol.h"
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmap.h>
-
-#include <qaudioformat.h>
-
-QT_BEGIN_NAMESPACE
-
-class AudioCaptureSession;
-
-class AudioEncoderControl : public QAudioEncoderSettingsControl
-{
- Q_OBJECT
-public:
- AudioEncoderControl(QObject *parent);
- virtual ~AudioEncoderControl();
-
- QStringList supportedAudioCodecs() const;
- QString codecDescription(const QString &codecName) const;
- QList<int> supportedSampleRates(const QAudioEncoderSettings &, bool *continuous = 0) const;
-
- QAudioEncoderSettings audioSettings() const;
- void setAudioSettings(const QAudioEncoderSettings&);
-
-private:
- void update();
-
- AudioCaptureSession* m_session;
- QList<int> m_sampleRates;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/audiocapture/audioinputselector.cpp b/src/plugins/audiocapture/audioinputselector.cpp
deleted file mode 100644
index 3e7e854c6..000000000
--- a/src/plugins/audiocapture/audioinputselector.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "audiocapturesession.h"
-#include "audioinputselector.h"
-
-#include <qaudiodeviceinfo.h>
-
-QT_BEGIN_NAMESPACE
-
-AudioInputSelector::AudioInputSelector(QObject *parent)
- :QAudioInputSelectorControl(parent)
-{
- m_session = qobject_cast<AudioCaptureSession*>(parent);
-
- update();
-
- m_audioInput = defaultInput();
-}
-
-AudioInputSelector::~AudioInputSelector()
-{
-}
-
-QList<QString> AudioInputSelector::availableInputs() const
-{
- return m_names;
-}
-
-QString AudioInputSelector::inputDescription(const QString& name) const
-{
- QString desc;
-
- for(int i = 0; i < m_names.count(); i++) {
- if (m_names.at(i).compare(name) == 0) {
- desc = m_names.at(i);
- break;
- }
- }
- return desc;
-}
-
-QString AudioInputSelector::defaultInput() const
-{
- return QAudioDeviceInfo::defaultInputDevice().deviceName();
-}
-
-QString AudioInputSelector::activeInput() const
-{
- return m_audioInput;
-}
-
-void AudioInputSelector::setActiveInput(const QString& name)
-{
- if (m_audioInput.compare(name) != 0) {
- m_audioInput = name;
- m_session->setCaptureDevice(name);
- emit activeInputChanged(name);
- }
-}
-
-void AudioInputSelector::update()
-{
- m_names.clear();
- m_descriptions.clear();
-
- QList<QAudioDeviceInfo> devices;
- devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
- for(int i = 0; i < devices.size(); ++i) {
- m_names.append(devices.at(i).deviceName());
- m_descriptions.append(devices.at(i).deviceName());
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audioinputselector.h b/src/plugins/audiocapture/audioinputselector.h
deleted file mode 100644
index 7a0829223..000000000
--- a/src/plugins/audiocapture/audioinputselector.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AUDIOINPUTSELECTOR_H
-#define AUDIOINPUTSELECTOR_H
-
-#include <QStringList>
-
-#include "qaudioinputselectorcontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-class AudioCaptureSession;
-
-class AudioInputSelector : public QAudioInputSelectorControl
-{
-Q_OBJECT
-public:
- AudioInputSelector(QObject *parent);
- virtual ~AudioInputSelector();
-
- QList<QString> availableInputs() const;
- QString inputDescription(const QString& name) const;
- QString defaultInput() const;
- QString activeInput() const;
-
-public Q_SLOTS:
- void setActiveInput(const QString& name);
-
-private:
- void update();
-
- QString m_audioInput;
- QList<QString> m_names;
- QList<QString> m_descriptions;
- AudioCaptureSession* m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // AUDIOINPUTSELECTOR_H
diff --git a/src/plugins/audiocapture/audiomediarecordercontrol.cpp b/src/plugins/audiocapture/audiomediarecordercontrol.cpp
deleted file mode 100644
index 767026180..000000000
--- a/src/plugins/audiocapture/audiomediarecordercontrol.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "audiocapturesession.h"
-#include "audiomediarecordercontrol.h"
-
-#include <QtCore/qdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-AudioMediaRecorderControl::AudioMediaRecorderControl(QObject *parent)
- : QMediaRecorderControl(parent)
-{
- m_session = qobject_cast<AudioCaptureSession*>(parent);
- connect(m_session, SIGNAL(positionChanged(qint64)),
- this, SIGNAL(durationChanged(qint64)));
- connect(m_session, SIGNAL(stateChanged(QMediaRecorder::State)),
- this, SIGNAL(stateChanged(QMediaRecorder::State)));
- connect(m_session, SIGNAL(statusChanged(QMediaRecorder::Status)),
- this, SIGNAL(statusChanged(QMediaRecorder::Status)));
- connect(m_session, SIGNAL(actualLocationChanged(QUrl)),
- this, SIGNAL(actualLocationChanged(QUrl)));
- connect(m_session, &AudioCaptureSession::volumeChanged,
- this, &AudioMediaRecorderControl::volumeChanged);
- connect(m_session, &AudioCaptureSession::mutedChanged,
- this, &AudioMediaRecorderControl::mutedChanged);
- connect(m_session, SIGNAL(error(int,QString)),
- this, SIGNAL(error(int,QString)));
-}
-
-AudioMediaRecorderControl::~AudioMediaRecorderControl()
-{
-}
-
-QUrl AudioMediaRecorderControl::outputLocation() const
-{
- return m_session->outputLocation();
-}
-
-bool AudioMediaRecorderControl::setOutputLocation(const QUrl& sink)
-{
- return m_session->setOutputLocation(sink);
-}
-
-QMediaRecorder::State AudioMediaRecorderControl::state() const
-{
- return m_session->state();
-}
-
-QMediaRecorder::Status AudioMediaRecorderControl::status() const
-{
- return m_session->status();
-}
-
-qint64 AudioMediaRecorderControl::duration() const
-{
- return m_session->position();
-}
-
-bool AudioMediaRecorderControl::isMuted() const
-{
- return m_session->isMuted();
-}
-
-qreal AudioMediaRecorderControl::volume() const
-{
- return m_session->volume();
-}
-
-void AudioMediaRecorderControl::setState(QMediaRecorder::State state)
-{
- m_session->setState(state);
-}
-
-void AudioMediaRecorderControl::setMuted(bool muted)
-{
- m_session->setMuted(muted);
-}
-
-void AudioMediaRecorderControl::setVolume(qreal volume)
-{
- m_session->setVolume(volume);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiomediarecordercontrol.h b/src/plugins/audiocapture/audiomediarecordercontrol.h
deleted file mode 100644
index cb6e79cb4..000000000
--- a/src/plugins/audiocapture/audiomediarecordercontrol.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AUDIOMEDIARECORDERCONTROL_H
-#define AUDIOMEDIARECORDERCONTROL_H
-
-#include <QtCore/qobject.h>
-
-#include "qmediarecorder.h"
-#include "qmediarecordercontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-class AudioCaptureSession;
-
-class AudioMediaRecorderControl : public QMediaRecorderControl
-{
- Q_OBJECT
-public:
- AudioMediaRecorderControl(QObject *parent = 0);
- ~AudioMediaRecorderControl();
-
- QUrl outputLocation() const;
- bool setOutputLocation(const QUrl &location);
-
- QMediaRecorder::State state() const;
- QMediaRecorder::Status status() const;
-
- qint64 duration() const;
-
- bool isMuted() const;
- qreal volume() const;
-
- void applySettings() {}
-
- void setState(QMediaRecorder::State state);
- void setMuted(bool);
- void setVolume(qreal volume);
-
-private:
- AudioCaptureSession* m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/avfoundation.pro b/src/plugins/avfoundation/avfoundation.pro
deleted file mode 100644
index 1110e196b..000000000
--- a/src/plugins/avfoundation/avfoundation.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS += mediaplayer
-!tvos: SUBDIRS += camera
diff --git a/src/plugins/avfoundation/camera/avfaudioencodersettingscontrol.h b/src/plugins/avfoundation/camera/avfaudioencodersettingscontrol.h
deleted file mode 100644
index 94aa6a8f0..000000000
--- a/src/plugins/avfoundation/camera/avfaudioencodersettingscontrol.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFAUDIOENCODERSETTINGSCONTROL_H
-#define AVFAUDIOENCODERSETTINGSCONTROL_H
-
-#include <qaudioencodersettingscontrol.h>
-
-@class NSDictionary;
-@class AVCaptureAudioDataOutput;
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraService;
-
-class AVFAudioEncoderSettingsControl : public QAudioEncoderSettingsControl
-{
-public:
- explicit AVFAudioEncoderSettingsControl(AVFCameraService *service);
-
- QStringList supportedAudioCodecs() const override;
- QString codecDescription(const QString &codecName) const override;
- QList<int> supportedSampleRates(const QAudioEncoderSettings &settings, bool *continuous = nullptr) const override;
- QAudioEncoderSettings audioSettings() const override;
- void setAudioSettings(const QAudioEncoderSettings &settings) override;
-
- NSDictionary *applySettings();
- void unapplySettings();
-
-private:
- AVFCameraService *m_service;
-
- QAudioEncoderSettings m_requestedSettings;
- QAudioEncoderSettings m_actualSettings;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFAUDIOENCODERSETTINGSCONTROL_H
diff --git a/src/plugins/avfoundation/camera/avfaudioencodersettingscontrol.mm b/src/plugins/avfoundation/camera/avfaudioencodersettingscontrol.mm
deleted file mode 100644
index 1aeb44ff6..000000000
--- a/src/plugins/avfoundation/camera/avfaudioencodersettingscontrol.mm
+++ /dev/null
@@ -1,226 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfaudioencodersettingscontrol.h"
-
-#include "avfcameraservice.h"
-#include "avfcamerasession.h"
-
-#include <AVFoundation/AVFoundation.h>
-#include <CoreAudio/CoreAudioTypes.h>
-
-QT_BEGIN_NAMESPACE
-
-struct AudioCodecInfo
-{
- QString description;
- int id;
-
- AudioCodecInfo() : id(0) { }
- AudioCodecInfo(const QString &desc, int i)
- : description(desc), id(i)
- { }
-};
-
-typedef QMap<QString, AudioCodecInfo> SupportedAudioCodecs;
-Q_GLOBAL_STATIC_WITH_ARGS(QString , defaultCodec, (QLatin1String("aac")))
-Q_GLOBAL_STATIC(SupportedAudioCodecs, supportedCodecs)
-
-AVFAudioEncoderSettingsControl::AVFAudioEncoderSettingsControl(AVFCameraService *service)
- : QAudioEncoderSettingsControl()
- , m_service(service)
-{
- if (supportedCodecs->isEmpty()) {
- supportedCodecs->insert(QStringLiteral("lpcm"),
- AudioCodecInfo(QStringLiteral("Linear PCM"),
- kAudioFormatLinearPCM));
- supportedCodecs->insert(QStringLiteral("ulaw"),
- AudioCodecInfo(QStringLiteral("PCM Mu-Law 2:1"),
- kAudioFormatULaw));
- supportedCodecs->insert(QStringLiteral("alaw"),
- AudioCodecInfo(QStringLiteral("PCM A-Law 2:1"),
- kAudioFormatALaw));
- supportedCodecs->insert(QStringLiteral("ima4"),
- AudioCodecInfo(QStringLiteral("IMA 4:1 ADPCM"),
- kAudioFormatAppleIMA4));
- supportedCodecs->insert(QStringLiteral("alac"),
- AudioCodecInfo(QStringLiteral("Apple Lossless Audio Codec"),
- kAudioFormatAppleLossless));
- supportedCodecs->insert(QStringLiteral("aac"),
- AudioCodecInfo(QStringLiteral("MPEG-4 Low Complexity AAC"),
- kAudioFormatMPEG4AAC));
- supportedCodecs->insert(QStringLiteral("aach"),
- AudioCodecInfo(QStringLiteral("MPEG-4 High Efficiency AAC"),
- kAudioFormatMPEG4AAC_HE));
- supportedCodecs->insert(QStringLiteral("aacl"),
- AudioCodecInfo(QStringLiteral("MPEG-4 AAC Low Delay"),
- kAudioFormatMPEG4AAC_LD));
- supportedCodecs->insert(QStringLiteral("aace"),
- AudioCodecInfo(QStringLiteral("MPEG-4 AAC Enhanced Low Delay"),
- kAudioFormatMPEG4AAC_ELD));
- supportedCodecs->insert(QStringLiteral("aacf"),
- AudioCodecInfo(QStringLiteral("MPEG-4 AAC Enhanced Low Delay with SBR"),
- kAudioFormatMPEG4AAC_ELD_SBR));
- supportedCodecs->insert(QStringLiteral("aacp"),
- AudioCodecInfo(QStringLiteral("MPEG-4 HE AAC V2"),
- kAudioFormatMPEG4AAC_HE_V2));
- supportedCodecs->insert(QStringLiteral("ilbc"),
- AudioCodecInfo(QStringLiteral("iLBC"),
- kAudioFormatiLBC));
- }
-}
-
-QStringList AVFAudioEncoderSettingsControl::supportedAudioCodecs() const
-{
- return supportedCodecs->keys();
-}
-
-QString AVFAudioEncoderSettingsControl::codecDescription(const QString &codecName) const
-{
- return supportedCodecs->value(codecName).description;
-}
-
-QList<int> AVFAudioEncoderSettingsControl::supportedSampleRates(const QAudioEncoderSettings &settings, bool *continuous) const
-{
- Q_UNUSED(settings);
-
- if (continuous)
- *continuous = true;
-
- return QList<int>() << 8000 << 96000;
-}
-
-QAudioEncoderSettings AVFAudioEncoderSettingsControl::audioSettings() const
-{
- return m_actualSettings;
-}
-
-void AVFAudioEncoderSettingsControl::setAudioSettings(const QAudioEncoderSettings &settings)
-{
- if (m_requestedSettings == settings)
- return;
-
- m_requestedSettings = m_actualSettings = settings;
-}
-
-NSDictionary *AVFAudioEncoderSettingsControl::applySettings()
-{
- if (m_service->session()->state() != QCamera::LoadedState &&
- m_service->session()->state() != QCamera::ActiveState) {
- return nil;
- }
-
- NSMutableDictionary *settings = [NSMutableDictionary dictionary];
-
- QString codec = m_requestedSettings.codec().isEmpty() ? *defaultCodec : m_requestedSettings.codec();
- if (!supportedCodecs->contains(codec)) {
- qWarning("Unsupported codec: '%s'", codec.toLocal8Bit().constData());
- codec = *defaultCodec;
- }
- [settings setObject:[NSNumber numberWithInt:supportedCodecs->value(codec).id] forKey:AVFormatIDKey];
- m_actualSettings.setCodec(codec);
-
-#ifdef Q_OS_OSX
- if (m_requestedSettings.encodingMode() == QMultimedia::ConstantQualityEncoding) {
- int quality;
- switch (m_requestedSettings.quality()) {
- case QMultimedia::VeryLowQuality:
- quality = AVAudioQualityMin;
- break;
- case QMultimedia::LowQuality:
- quality = AVAudioQualityLow;
- break;
- case QMultimedia::HighQuality:
- quality = AVAudioQualityHigh;
- break;
- case QMultimedia::VeryHighQuality:
- quality = AVAudioQualityMax;
- break;
- case QMultimedia::NormalQuality:
- default:
- quality = AVAudioQualityMedium;
- break;
- }
- [settings setObject:[NSNumber numberWithInt:quality] forKey:AVEncoderAudioQualityKey];
-
- } else
-#endif
- if (m_requestedSettings.bitRate() > 0){
- [settings setObject:[NSNumber numberWithInt:m_requestedSettings.bitRate()] forKey:AVEncoderBitRateKey];
- }
-
- int sampleRate = m_requestedSettings.sampleRate();
- int channelCount = m_requestedSettings.channelCount();
-
-#ifdef Q_OS_IOS
- // Some keys are mandatory only on iOS
- if (codec == QLatin1String("lpcm")) {
- [settings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
- [settings setObject:[NSNumber numberWithInt:NO] forKey:AVLinearPCMIsBigEndianKey];
- [settings setObject:[NSNumber numberWithInt:NO] forKey:AVLinearPCMIsFloatKey];
- [settings setObject:[NSNumber numberWithInt:NO] forKey:AVLinearPCMIsNonInterleaved];
- }
-
- if (codec == QLatin1String("alac"))
- [settings setObject:[NSNumber numberWithInt:24] forKey:AVEncoderBitDepthHintKey];
-
- if (sampleRate <= 0)
- sampleRate = codec == QLatin1String("ilbc") ? 8000 : 44100;
- if (channelCount <= 0)
- channelCount = codec == QLatin1String("ilbc") ? 1 : 2;
-#endif
-
- if (sampleRate > 0) {
- [settings setObject:[NSNumber numberWithInt:sampleRate] forKey:AVSampleRateKey];
- m_actualSettings.setSampleRate(sampleRate);
- }
- if (channelCount > 0) {
- [settings setObject:[NSNumber numberWithInt:channelCount] forKey:AVNumberOfChannelsKey];
- m_actualSettings.setChannelCount(channelCount);
- }
-
- return settings;
-}
-
-void AVFAudioEncoderSettingsControl::unapplySettings()
-{
- m_actualSettings = m_requestedSettings;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/avfoundation/camera/avfaudioinputselectorcontrol.h b/src/plugins/avfoundation/camera/avfaudioinputselectorcontrol.h
deleted file mode 100644
index a902a71f9..000000000
--- a/src/plugins/avfoundation/camera/avfaudioinputselectorcontrol.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFAUDIOINPUTSELECTORCONTROL_H
-#define AVFAUDIOINPUTSELECTORCONTROL_H
-
-#include <QtMultimedia/qaudioinputselectorcontrol.h>
-#include <QtCore/qstringlist.h>
-
-#import <AVFoundation/AVFoundation.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraSession;
-class AVFCameraService;
-
-class AVFAudioInputSelectorControl : public QAudioInputSelectorControl
-{
-Q_OBJECT
-public:
- AVFAudioInputSelectorControl(AVFCameraService *service, QObject *parent = nullptr);
- ~AVFAudioInputSelectorControl();
-
- QList<QString> availableInputs() const override;
- QString inputDescription(const QString &name) const override;
- QString defaultInput() const override;
- QString activeInput() const override;
-
-public Q_SLOTS:
- void setActiveInput(const QString &name) override;
-
-public:
- //device changed since the last createCaptureDevice()
- bool isDirty() const { return m_dirty; }
- AVCaptureDevice *createCaptureDevice();
-
-private:
- QString m_activeInput;
- bool m_dirty;
- QString m_defaultDevice;
- QStringList m_devices;
- QMap<QString, QString> m_deviceDescriptions;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfaudioinputselectorcontrol.mm b/src/plugins/avfoundation/camera/avfaudioinputselectorcontrol.mm
deleted file mode 100644
index de29fd970..000000000
--- a/src/plugins/avfoundation/camera/avfaudioinputselectorcontrol.mm
+++ /dev/null
@@ -1,119 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcameradebug.h"
-#include "avfaudioinputselectorcontrol.h"
-#include "avfcameraservice.h"
-
-#import <AVFoundation/AVFoundation.h>
-
-QT_USE_NAMESPACE
-
-AVFAudioInputSelectorControl::AVFAudioInputSelectorControl(AVFCameraService *service, QObject *parent)
- : QAudioInputSelectorControl(parent)
- , m_dirty(true)
-{
- Q_UNUSED(service);
- NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
- for (AVCaptureDevice *device in videoDevices) {
- QString deviceId = QString::fromUtf8([[device uniqueID] UTF8String]);
- m_devices << deviceId;
- m_deviceDescriptions.insert(deviceId,
- QString::fromUtf8([[device localizedName] UTF8String]));
- }
-
- AVCaptureDevice *defaultDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
- if (defaultDevice) {
- m_defaultDevice = QString::fromUtf8([defaultDevice.uniqueID UTF8String]);
- m_activeInput = m_defaultDevice;
- }
-}
-
-AVFAudioInputSelectorControl::~AVFAudioInputSelectorControl()
-{
-}
-
-QList<QString> AVFAudioInputSelectorControl::availableInputs() const
-{
- return m_devices;
-}
-
-QString AVFAudioInputSelectorControl::inputDescription(const QString &name) const
-{
- return m_deviceDescriptions.value(name);
-}
-
-QString AVFAudioInputSelectorControl::defaultInput() const
-{
- return m_defaultDevice;
-}
-
-QString AVFAudioInputSelectorControl::activeInput() const
-{
- return m_activeInput;
-}
-
-void AVFAudioInputSelectorControl::setActiveInput(const QString &name)
-{
- if (name != m_activeInput) {
- m_activeInput = name;
- m_dirty = true;
-
- Q_EMIT activeInputChanged(m_activeInput);
- }
-}
-
-AVCaptureDevice *AVFAudioInputSelectorControl::createCaptureDevice()
-{
- m_dirty = false;
- AVCaptureDevice *device = nullptr;
-
- if (!m_activeInput.isEmpty()) {
- device = [AVCaptureDevice deviceWithUniqueID:
- [NSString stringWithUTF8String:
- m_activeInput.toUtf8().constData()]];
- }
-
- if (!device)
- device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
-
- return device;
-}
-
-#include "moc_avfaudioinputselectorcontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcamera.json b/src/plugins/avfoundation/camera/avfcamera.json
deleted file mode 100644
index e4310b62c..000000000
--- a/src/plugins/avfoundation/camera/avfcamera.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["avfoundationcamera"],
- "Services": ["org.qt-project.qt.camera"]
-}
diff --git a/src/plugins/avfoundation/camera/avfcameracontrol.h b/src/plugins/avfoundation/camera/avfcameracontrol.h
deleted file mode 100644
index df371e864..000000000
--- a/src/plugins/avfoundation/camera/avfcameracontrol.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERACONTROL_H
-#define AVFCAMERACONTROL_H
-
-#include <QtCore/qobject.h>
-
-#include <QtMultimedia/qcameracontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraSession;
-class AVFCameraService;
-
-class AVFCameraControl : public QCameraControl
-{
-Q_OBJECT
-public:
- AVFCameraControl(AVFCameraService *service, QObject *parent = nullptr);
- ~AVFCameraControl();
-
- QCamera::State state() const override;
- void setState(QCamera::State state) override;
-
- QCamera::Status status() const override;
-
- QCamera::CaptureModes captureMode() const override;
- void setCaptureMode(QCamera::CaptureModes) override;
- bool isCaptureModeSupported(QCamera::CaptureModes mode) const override;
-
- bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const override;
-
-private Q_SLOTS:
- void updateStatus();
-
-private:
- AVFCameraSession *m_session;
-
- QCamera::State m_state;
- QCamera::Status m_lastStatus;
- QCamera::CaptureModes m_captureMode;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcameracontrol.mm b/src/plugins/avfoundation/camera/avfcameracontrol.mm
deleted file mode 100644
index c47eecfdf..000000000
--- a/src/plugins/avfoundation/camera/avfcameracontrol.mm
+++ /dev/null
@@ -1,134 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcameradebug.h"
-#include "avfcameracontrol.h"
-#include "avfcamerasession.h"
-#include "avfcameraservice.h"
-
-QT_USE_NAMESPACE
-
-AVFCameraControl::AVFCameraControl(AVFCameraService *service, QObject *parent)
- : QCameraControl(parent)
- , m_session(service->session())
- , m_state(QCamera::UnloadedState)
- , m_lastStatus(QCamera::UnloadedStatus)
- , m_captureMode(QCamera::CaptureStillImage)
-{
- Q_UNUSED(service);
- connect(m_session, SIGNAL(stateChanged(QCamera::State)), SLOT(updateStatus()));
- connect(this, &AVFCameraControl::captureModeChanged, m_session, &AVFCameraSession::onCaptureModeChanged);
-}
-
-AVFCameraControl::~AVFCameraControl()
-{
-}
-
-QCamera::State AVFCameraControl::state() const
-{
- return m_state;
-}
-
-void AVFCameraControl::setState(QCamera::State state)
-{
- if (m_state == state)
- return;
- m_state = state;
- m_session->setState(state);
-
- Q_EMIT stateChanged(m_state);
- updateStatus();
-}
-
-QCamera::Status AVFCameraControl::status() const
-{
- static QCamera::Status statusTable[3][3] = {
- { QCamera::UnloadedStatus, QCamera::UnloadingStatus, QCamera::StoppingStatus }, //Unloaded state
- { QCamera::LoadingStatus, QCamera::LoadedStatus, QCamera::StoppingStatus }, //Loaded state
- { QCamera::LoadingStatus, QCamera::StartingStatus, QCamera::ActiveStatus } //ActiveState
- };
-
- return statusTable[m_state][m_session->state()];
-}
-
-void AVFCameraControl::updateStatus()
-{
- QCamera::Status newStatus = status();
-
- if (m_lastStatus != newStatus) {
- qDebugCamera() << "Camera status changed: " << m_lastStatus << " -> " << newStatus;
- m_lastStatus = newStatus;
- Q_EMIT statusChanged(m_lastStatus);
- }
-}
-
-QCamera::CaptureModes AVFCameraControl::captureMode() const
-{
- return m_captureMode;
-}
-
-void AVFCameraControl::setCaptureMode(QCamera::CaptureModes mode)
-{
- if (m_captureMode == mode)
- return;
-
- if (!isCaptureModeSupported(mode)) {
- Q_EMIT error(QCamera::NotSupportedFeatureError, tr("Requested capture mode is not supported"));
- return;
- }
-
- m_captureMode = mode;
- Q_EMIT captureModeChanged(mode);
-}
-
-bool AVFCameraControl::isCaptureModeSupported(QCamera::CaptureModes mode) const
-{
- //all the capture modes are supported, including QCamera::CaptureStillImage | QCamera::CaptureVideo
- return (mode & (QCamera::CaptureStillImage | QCamera::CaptureVideo)) == mode;
-}
-
-bool AVFCameraControl::canChangeProperty(QCameraControl::PropertyChangeType changeType, QCamera::Status status) const
-{
- Q_UNUSED(changeType);
- Q_UNUSED(status);
-
- return true;
-}
-
-#include "moc_avfcameracontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcameradebug.h b/src/plugins/avfoundation/camera/avfcameradebug.h
deleted file mode 100644
index 8838122e0..000000000
--- a/src/plugins/avfoundation/camera/avfcameradebug.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFDEBUG_H
-#define AVFDEBUG_H
-
-#include "qtmultimediaglobal.h"
-
-#include <QtCore/qdebug.h>
-
-QT_USE_NAMESPACE
-
-//#define AVF_DEBUG_CAMERA
-
-#ifdef AVF_DEBUG_CAMERA
-#define qDebugCamera qDebug
-#else
-#define qDebugCamera QT_NO_QDEBUG_MACRO
-#endif
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcameradevicecontrol.h b/src/plugins/avfoundation/camera/avfcameradevicecontrol.h
deleted file mode 100644
index 0a16c0408..000000000
--- a/src/plugins/avfoundation/camera/avfcameradevicecontrol.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERADEVICECONTROL_H
-#define AVFCAMERADEVICECONTROL_H
-
-#include <QtMultimedia/qvideodeviceselectorcontrol.h>
-#include <QtCore/qstringlist.h>
-
-#import <AVFoundation/AVFoundation.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraSession;
-class AVFCameraService;
-
-class AVFCameraDeviceControl : public QVideoDeviceSelectorControl
-{
-Q_OBJECT
-public:
- AVFCameraDeviceControl(AVFCameraService *service, QObject *parent = nullptr);
- ~AVFCameraDeviceControl();
-
- int deviceCount() const override;
-
- QString deviceName(int index) const override;
- QString deviceDescription(int index) const override;
-
- int defaultDevice() const override;
- int selectedDevice() const override;
-
-public Q_SLOTS:
- void setSelectedDevice(int index) override;
-
-public:
- //device changed since the last createCaptureDevice()
- bool isDirty() const { return m_dirty; }
- AVCaptureDevice *createCaptureDevice();
-
-private:
- AVFCameraService *m_service;
-
- int m_selectedDevice;
- bool m_dirty;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcameradevicecontrol.mm b/src/plugins/avfoundation/camera/avfcameradevicecontrol.mm
deleted file mode 100644
index 907373b61..000000000
--- a/src/plugins/avfoundation/camera/avfcameradevicecontrol.mm
+++ /dev/null
@@ -1,123 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcameradebug.h"
-#include "avfcameradevicecontrol.h"
-#include "avfcameraservice.h"
-#include "avfcamerasession.h"
-
-QT_USE_NAMESPACE
-
-AVFCameraDeviceControl::AVFCameraDeviceControl(AVFCameraService *service, QObject *parent)
- : QVideoDeviceSelectorControl(parent)
- , m_service(service)
- , m_selectedDevice(0)
- , m_dirty(true)
-{
- Q_UNUSED(m_service);
-}
-
-AVFCameraDeviceControl::~AVFCameraDeviceControl()
-{
-}
-
-int AVFCameraDeviceControl::deviceCount() const
-{
- return AVFCameraSession::availableCameraDevices().count();
-}
-
-QString AVFCameraDeviceControl::deviceName(int index) const
-{
- const QList<AVFCameraInfo> &devices = AVFCameraSession::availableCameraDevices();
- if (index < 0 || index >= devices.count())
- return QString();
-
- return QString::fromUtf8(devices.at(index).deviceId);
-}
-
-QString AVFCameraDeviceControl::deviceDescription(int index) const
-{
- const QList<AVFCameraInfo> &devices = AVFCameraSession::availableCameraDevices();
- if (index < 0 || index >= devices.count())
- return QString();
-
- return devices.at(index).description;
-}
-
-int AVFCameraDeviceControl::defaultDevice() const
-{
- return AVFCameraSession::defaultCameraIndex();
-}
-
-int AVFCameraDeviceControl::selectedDevice() const
-{
- return m_selectedDevice;
-}
-
-void AVFCameraDeviceControl::setSelectedDevice(int index)
-{
- if (index >= 0 &&
- index < deviceCount() &&
- index != m_selectedDevice) {
- m_dirty = true;
- m_selectedDevice = index;
- Q_EMIT selectedDeviceChanged(index);
- Q_EMIT selectedDeviceChanged(deviceName(index));
- }
-}
-
-AVCaptureDevice *AVFCameraDeviceControl::createCaptureDevice()
-{
- m_dirty = false;
- AVCaptureDevice *device = nullptr;
-
- QString deviceId = deviceName(m_selectedDevice);
- if (!deviceId.isEmpty()) {
- device = [AVCaptureDevice deviceWithUniqueID:
- [NSString stringWithUTF8String:
- deviceId.toUtf8().constData()]];
- }
-
- if (!device)
- device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
-
- return device;
-}
-
-#include "moc_avfcameradevicecontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcameraexposurecontrol.h b/src/plugins/avfoundation/camera/avfcameraexposurecontrol.h
deleted file mode 100644
index 0e2846889..000000000
--- a/src/plugins/avfoundation/camera/avfcameraexposurecontrol.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERAEXPOSURECONTROL_H
-#define AVFCAMERAEXPOSURECONTROL_H
-
-#include <QtMultimedia/qcameraexposurecontrol.h>
-#include <QtMultimedia/qcameraexposure.h>
-
-#include <QtCore/qglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraSession;
-class AVFCameraService;
-
-class AVFCameraExposureControl : public QCameraExposureControl
-{
- Q_OBJECT
-
-public:
- AVFCameraExposureControl(AVFCameraService *service);
-
- bool isParameterSupported(ExposureParameter parameter) const override;
- QVariantList supportedParameterRange(ExposureParameter parameter,
- bool *continuous) const override;
-
- QVariant requestedValue(ExposureParameter parameter) const override;
- QVariant actualValue(ExposureParameter parameter) const override;
- bool setValue(ExposureParameter parameter, const QVariant &value) override;
-
-private Q_SLOTS:
- void cameraStateChanged();
-
-private:
- AVFCameraService *m_service;
- AVFCameraSession *m_session;
-
- QVariant m_requestedMode;
- QVariant m_requestedCompensation;
- QVariant m_requestedShutterSpeed;
- QVariant m_requestedISO;
-
- // Aux. setters:
- bool setExposureMode(const QVariant &value);
- bool setExposureCompensation(const QVariant &value);
- bool setShutterSpeed(const QVariant &value);
- bool setISO(const QVariant &value);
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcameraexposurecontrol.mm b/src/plugins/avfoundation/camera/avfcameraexposurecontrol.mm
deleted file mode 100644
index 62387604f..000000000
--- a/src/plugins/avfoundation/camera/avfcameraexposurecontrol.mm
+++ /dev/null
@@ -1,661 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcameraexposurecontrol.h"
-#include "avfcamerautility.h"
-#include "avfcamerasession.h"
-#include "avfcameraservice.h"
-#include "avfcameradebug.h"
-
-#include <QtCore/qvariant.h>
-#include <QtCore/qpointer.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qpair.h>
-
-#include <AVFoundation/AVFoundation.h>
-
-#include <limits>
-
-QT_BEGIN_NAMESPACE
-
-namespace {
-
-// All these methods to work with exposure/ISO/SS in custom mode do not support macOS.
-
-#ifdef Q_OS_IOS
-
-// Misc. helpers to check values/ranges:
-
-bool qt_check_ISO_conversion(float isoValue)
-{
- if (isoValue >= std::numeric_limits<int>::max())
- return false;
- if (isoValue <= std::numeric_limits<int>::min())
- return false;
- return true;
-}
-
-bool qt_check_ISO_range(AVCaptureDeviceFormat *format)
-{
- // Qt is using int for ISO, AVFoundation - float. It looks like the ISO range
- // at the moment can be represented by int (it's max - min > 100, etc.).
- Q_ASSERT(format);
- if (format.maxISO - format.minISO < 1.) {
- // ISO is in some strange units?
- return false;
- }
-
- return qt_check_ISO_conversion(format.minISO)
- && qt_check_ISO_conversion(format.maxISO);
-}
-
-bool qt_check_exposure_duration(AVCaptureDevice *captureDevice, CMTime duration)
-{
- Q_ASSERT(captureDevice);
-
- AVCaptureDeviceFormat *activeFormat = captureDevice.activeFormat;
- if (!activeFormat) {
- qDebugCamera() << Q_FUNC_INFO << "failed to obtain capture device format";
- return false;
- }
-
- return CMTimeCompare(duration, activeFormat.minExposureDuration) != -1
- && CMTimeCompare(activeFormat.maxExposureDuration, duration) != -1;
-}
-
-bool qt_check_ISO_value(AVCaptureDevice *captureDevice, int newISO)
-{
- Q_ASSERT(captureDevice);
-
- AVCaptureDeviceFormat *activeFormat = captureDevice.activeFormat;
- if (!activeFormat) {
- qDebugCamera() << Q_FUNC_INFO << "failed to obtain capture device format";
- return false;
- }
-
- return !(newISO < activeFormat.minISO || newISO > activeFormat.maxISO);
-}
-
-bool qt_exposure_duration_equal(AVCaptureDevice *captureDevice, qreal qDuration)
-{
- Q_ASSERT(captureDevice);
- const CMTime avDuration = CMTimeMakeWithSeconds(qDuration, captureDevice.exposureDuration.timescale);
- return !CMTimeCompare(avDuration, captureDevice.exposureDuration);
-}
-
-bool qt_iso_equal(AVCaptureDevice *captureDevice, int iso)
-{
- Q_ASSERT(captureDevice);
- return qFuzzyCompare(float(iso), captureDevice.ISO);
-}
-
-bool qt_exposure_bias_equal(AVCaptureDevice *captureDevice, qreal bias)
-{
- Q_ASSERT(captureDevice);
- return qFuzzyCompare(bias, qreal(captureDevice.exposureTargetBias));
-}
-
-// Converters:
-
-bool qt_convert_exposure_mode(AVCaptureDevice *captureDevice, QCameraExposure::ExposureMode mode,
- AVCaptureExposureMode &avMode)
-{
- // Test if mode supported and convert.
- Q_ASSERT(captureDevice);
-
- if (mode == QCameraExposure::ExposureAuto) {
- if ([captureDevice isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) {
- avMode = AVCaptureExposureModeContinuousAutoExposure;
- return true;
- }
- }
-
- if (mode == QCameraExposure::ExposureManual) {
- if ([captureDevice isExposureModeSupported:AVCaptureExposureModeCustom]) {
- avMode = AVCaptureExposureModeCustom;
- return true;
- }
- }
-
- return false;
-}
-
-// We set ISO/exposure duration with completion handlers, completion handlers try
-// to avoid dangling pointers (thus QPointer for QObjects) and not to create
-// a reference loop (in case we have ARC).
-
-void qt_set_exposure_bias(QPointer<AVFCameraService> service, QPointer<AVFCameraExposureControl> control,
- AVCaptureDevice *captureDevice, float bias)
-{
- Q_ASSERT(captureDevice);
-
- __block AVCaptureDevice *device = captureDevice; //For ARC.
-
- void (^completionHandler)(CMTime syncTime) = ^(CMTime) {
- // Test that service control is still alive and that
- // capture device is our device, if yes - emit actual value changed.
- if (service) {
- if (control) {
- if (service->session() && service->session()->videoCaptureDevice() == device)
- Q_EMIT control->actualValueChanged(int(QCameraExposureControl::ExposureCompensation));
- }
- }
- device = nil;
- };
-
- [captureDevice setExposureTargetBias:bias completionHandler:completionHandler];
-}
-
-void qt_set_duration_iso(QPointer<AVFCameraService> service, QPointer<AVFCameraExposureControl> control,
- AVCaptureDevice *captureDevice, CMTime duration, float iso)
-{
- Q_ASSERT(captureDevice);
-
- __block AVCaptureDevice *device = captureDevice; //For ARC.
- const bool setDuration = CMTimeCompare(duration, AVCaptureExposureDurationCurrent);
- const bool setISO = !qFuzzyCompare(iso, AVCaptureISOCurrent);
-
- void (^completionHandler)(CMTime syncTime) = ^(CMTime) {
- // Test that service control is still alive and that
- // capture device is our device, if yes - emit actual value changed.
- if (service) {
- if (control) {
- if (service->session() && service->session()->videoCaptureDevice() == device) {
- if (setDuration)
- Q_EMIT control->actualValueChanged(int(QCameraExposureControl::ShutterSpeed));
- if (setISO)
- Q_EMIT control->actualValueChanged(int(QCameraExposureControl::ISO));
- }
- }
- }
- device = nil;
- };
-
- [captureDevice setExposureModeCustomWithDuration:duration
- ISO:iso
- completionHandler:completionHandler];
-}
-
-#endif // defined(Q_OS_IOS)
-
-} // Unnamed namespace.
-
-AVFCameraExposureControl::AVFCameraExposureControl(AVFCameraService *service)
- : m_service(service),
- m_session(nullptr)
-{
- Q_ASSERT(service);
- m_session = m_service->session();
- Q_ASSERT(m_session);
-
- connect(m_session, SIGNAL(stateChanged(QCamera::State)), SLOT(cameraStateChanged()));
-}
-
-bool AVFCameraExposureControl::isParameterSupported(ExposureParameter parameter) const
-{
-#ifdef Q_OS_IOS
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice)
- return false;
-
- // These are the parameters we have an API to support:
- return parameter == QCameraExposureControl::ISO
- || parameter == QCameraExposureControl::ShutterSpeed
- || parameter == QCameraExposureControl::ExposureCompensation
- || parameter == QCameraExposureControl::ExposureMode;
-#else
- Q_UNUSED(parameter);
- return false;
-#endif
-}
-
-QVariantList AVFCameraExposureControl::supportedParameterRange(ExposureParameter parameter,
- bool *continuous) const
-{
- QVariantList parameterRange;
-#ifdef Q_OS_IOS
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice || !isParameterSupported(parameter)) {
- qDebugCamera() << Q_FUNC_INFO << "parameter not supported";
- return parameterRange;
- }
-
- if (continuous)
- *continuous = false;
-
- AVCaptureDeviceFormat *activeFormat = captureDevice.activeFormat;
-
- if (parameter == QCameraExposureControl::ISO) {
- if (!activeFormat) {
- qDebugCamera() << Q_FUNC_INFO << "failed to obtain capture device format";
- return parameterRange;
- }
-
- if (!qt_check_ISO_range(activeFormat)) {
- qDebugCamera() << Q_FUNC_INFO << "ISO range can not be represented as int";
- return parameterRange;
- }
-
- parameterRange << QVariant(int(activeFormat.minISO));
- parameterRange << QVariant(int(activeFormat.maxISO));
- if (continuous)
- *continuous = true;
- } else if (parameter == QCameraExposureControl::ExposureCompensation) {
- parameterRange << captureDevice.minExposureTargetBias;
- parameterRange << captureDevice.maxExposureTargetBias;
- if (continuous)
- *continuous = true;
- } else if (parameter == QCameraExposureControl::ShutterSpeed) {
- if (!activeFormat) {
- qDebugCamera() << Q_FUNC_INFO << "failed to obtain capture device format";
- return parameterRange;
- }
-
- // CMTimeGetSeconds returns Float64, test the conversion below, if it's valid?
- parameterRange << qreal(CMTimeGetSeconds(activeFormat.minExposureDuration));
- parameterRange << qreal(CMTimeGetSeconds(activeFormat.maxExposureDuration));
-
- if (continuous)
- *continuous = true;
- } else if (parameter == QCameraExposureControl::ExposureMode) {
- if ([captureDevice isExposureModeSupported:AVCaptureExposureModeCustom])
- parameterRange << QVariant::fromValue(QCameraExposure::ExposureManual);
-
- if ([captureDevice isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure])
- parameterRange << QVariant::fromValue(QCameraExposure::ExposureAuto);
- }
-#else
- Q_UNUSED(parameter);
- Q_UNUSED(continuous);
-#endif
- return parameterRange;
-}
-
-QVariant AVFCameraExposureControl::requestedValue(ExposureParameter parameter) const
-{
- if (!isParameterSupported(parameter)) {
- qDebugCamera() << Q_FUNC_INFO << "parameter not supported";
- return QVariant();
- }
-
- if (parameter == QCameraExposureControl::ExposureMode)
- return m_requestedMode;
-
- if (parameter == QCameraExposureControl::ExposureCompensation)
- return m_requestedCompensation;
-
- if (parameter == QCameraExposureControl::ShutterSpeed)
- return m_requestedShutterSpeed;
-
- if (parameter == QCameraExposureControl::ISO)
- return m_requestedISO;
-
- return QVariant();
-}
-
-QVariant AVFCameraExposureControl::actualValue(ExposureParameter parameter) const
-{
-#ifdef Q_OS_IOS
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice || !isParameterSupported(parameter)) {
- // Actually, at the moment !captiredevice => !isParameterSupported.
- qDebugCamera() << Q_FUNC_INFO << "parameter not supported";
- return QVariant();
- }
-
- if (parameter == QCameraExposureControl::ExposureMode) {
- // This code expects exposureMode to be continuous by default ...
- if (captureDevice.exposureMode == AVCaptureExposureModeContinuousAutoExposure)
- return QVariant::fromValue(QCameraExposure::ExposureAuto);
- return QVariant::fromValue(QCameraExposure::ExposureManual);
- }
-
- if (parameter == QCameraExposureControl::ExposureCompensation)
- return captureDevice.exposureTargetBias;
-
- if (parameter == QCameraExposureControl::ShutterSpeed)
- return qreal(CMTimeGetSeconds(captureDevice.exposureDuration));
-
- if (parameter == QCameraExposureControl::ISO) {
- if (captureDevice.activeFormat && qt_check_ISO_range(captureDevice.activeFormat)
- && qt_check_ISO_conversion(captureDevice.ISO)) {
- // Can be represented as int ...
- return int(captureDevice.ISO);
- } else {
- qDebugCamera() << Q_FUNC_INFO << "ISO can not be represented as int";
- return QVariant();
- }
- }
-#else
- Q_UNUSED(parameter);
-#endif
- return QVariant();
-}
-
-bool AVFCameraExposureControl::setValue(ExposureParameter parameter, const QVariant &value)
-{
- if (parameter == QCameraExposureControl::ExposureMode)
- return setExposureMode(value);
- else if (parameter == QCameraExposureControl::ExposureCompensation)
- return setExposureCompensation(value);
- else if (parameter == QCameraExposureControl::ShutterSpeed)
- return setShutterSpeed(value);
- else if (parameter == QCameraExposureControl::ISO)
- return setISO(value);
-
- return false;
-}
-
-bool AVFCameraExposureControl::setExposureMode(const QVariant &value)
-{
-#ifdef Q_OS_IOS
- if (!value.canConvert<QCameraExposure::ExposureMode>()) {
- qDebugCamera() << Q_FUNC_INFO << "invalid exposure mode value,"
- << "QCameraExposure::ExposureMode expected";
- return false;
- }
-
- const QCameraExposure::ExposureMode qtMode = value.value<QCameraExposure::ExposureMode>();
- if (qtMode != QCameraExposure::ExposureAuto && qtMode != QCameraExposure::ExposureManual) {
- qDebugCamera() << Q_FUNC_INFO << "exposure mode not supported";
- return false;
- }
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice) {
- m_requestedMode = value;
- Q_EMIT requestedValueChanged(int(QCameraExposureControl::ExposureMode));
- return true;
- }
-
- AVCaptureExposureMode avMode = AVCaptureExposureModeAutoExpose;
- if (!qt_convert_exposure_mode(captureDevice, qtMode, avMode)) {
- qDebugCamera() << Q_FUNC_INFO << "exposure mode not supported";
- return false;
- }
-
- const AVFConfigurationLock lock(captureDevice);
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock a capture device"
- << "for configuration";
- return false;
- }
-
- m_requestedMode = value;
- [captureDevice setExposureMode:avMode];
- Q_EMIT requestedValueChanged(int(QCameraExposureControl::ExposureMode));
- Q_EMIT actualValueChanged(int(QCameraExposureControl::ExposureMode));
-
- return true;
-#else
- Q_UNUSED(value);
- return false;
-#endif
-}
-
-bool AVFCameraExposureControl::setExposureCompensation(const QVariant &value)
-{
-#ifdef Q_OS_IOS
- if (!value.canConvert<qreal>()) {
- qDebugCamera() << Q_FUNC_INFO << "invalid exposure compensation"
- <<"value, floating point number expected";
- return false;
- }
-
- const qreal bias = value.toReal();
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice) {
- m_requestedCompensation = value;
- Q_EMIT requestedValueChanged(int(QCameraExposureControl::ExposureCompensation));
- return true;
- }
-
- if (bias < captureDevice.minExposureTargetBias || bias > captureDevice.maxExposureTargetBias) {
- // TODO: mixed fp types!
- qDebugCamera() << Q_FUNC_INFO << "exposure compenstation value is"
- << "out of range";
- return false;
- }
-
- const AVFConfigurationLock lock(captureDevice);
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- return false;
- }
-
- qt_set_exposure_bias(m_service, this, captureDevice, bias);
- m_requestedCompensation = value;
- Q_EMIT requestedValueChanged(int(QCameraExposureControl::ExposureCompensation));
-
- return true;
-#else
- Q_UNUSED(value);
- return false;
-#endif
-}
-
-bool AVFCameraExposureControl::setShutterSpeed(const QVariant &value)
-{
-#ifdef Q_OS_IOS
- if (value.isNull())
- return setExposureMode(QVariant::fromValue(QCameraExposure::ExposureAuto));
-
- if (!value.canConvert<qreal>()) {
- qDebugCamera() << Q_FUNC_INFO << "invalid shutter speed"
- << "value, floating point number expected";
- return false;
- }
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice) {
- m_requestedShutterSpeed = value;
- Q_EMIT requestedValueChanged(int(QCameraExposureControl::ShutterSpeed));
- return true;
- }
-
- const CMTime newDuration = CMTimeMakeWithSeconds(value.toReal(),
- captureDevice.exposureDuration.timescale);
- if (!qt_check_exposure_duration(captureDevice, newDuration)) {
- qDebugCamera() << Q_FUNC_INFO << "shutter speed value is out of range";
- return false;
- }
-
- const AVFConfigurationLock lock(captureDevice);
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- return false;
- }
-
- // Setting the shutter speed (exposure duration in Apple's terms,
- // since there is no shutter actually) will also reset
- // exposure mode into custom mode.
- qt_set_duration_iso(m_service, this, captureDevice, newDuration, AVCaptureISOCurrent);
-
- m_requestedShutterSpeed = value;
- Q_EMIT requestedValueChanged(int(QCameraExposureControl::ShutterSpeed));
-
- return true;
-#else
- Q_UNUSED(value);
- return false;
-#endif
-}
-
-bool AVFCameraExposureControl::setISO(const QVariant &value)
-{
-#ifdef Q_OS_IOS
- if (value.isNull())
- return setExposureMode(QVariant::fromValue(QCameraExposure::ExposureAuto));
-
- if (!value.canConvert<int>()) {
- qDebugCamera() << Q_FUNC_INFO << "invalid ISO value, int expected";
- return false;
- }
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice) {
- m_requestedISO = value;
- Q_EMIT requestedValueChanged(int(QCameraExposureControl::ISO));
- return true;
- }
-
- if (!qt_check_ISO_value(captureDevice, value.toInt())) {
- qDebugCamera() << Q_FUNC_INFO << "ISO value is out of range";
- return false;
- }
-
- const AVFConfigurationLock lock(captureDevice);
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock a capture device"
- << "for configuration";
- return false;
- }
-
- // Setting the ISO will also reset
- // exposure mode to the custom mode.
- qt_set_duration_iso(m_service, this, captureDevice, AVCaptureExposureDurationCurrent, value.toInt());
-
- m_requestedISO = value;
- Q_EMIT requestedValueChanged(int(QCameraExposureControl::ISO));
-
- return true;
-#else
- Q_UNUSED(value);
- return false;
-#endif
-}
-
-void AVFCameraExposureControl::cameraStateChanged()
-{
-#ifdef Q_OS_IOS
- if (m_session->state() != QCamera::ActiveState)
- return;
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice) {
- qDebugCamera() << Q_FUNC_INFO << "capture device is nil, but the session"
- << "state is 'active'";
- return;
- }
-
- Q_EMIT parameterRangeChanged(int(QCameraExposureControl::ExposureCompensation));
- Q_EMIT parameterRangeChanged(int(QCameraExposureControl::ExposureMode));
- Q_EMIT parameterRangeChanged(int(QCameraExposureControl::ShutterSpeed));
- Q_EMIT parameterRangeChanged(int(QCameraExposureControl::ISO));
-
- const AVFConfigurationLock lock(captureDevice);
-
- CMTime newDuration = AVCaptureExposureDurationCurrent;
- bool setCustomMode = false;
-
- if (!m_requestedShutterSpeed.isNull()
- && !qt_exposure_duration_equal(captureDevice, m_requestedShutterSpeed.toReal())) {
- newDuration = CMTimeMakeWithSeconds(m_requestedShutterSpeed.toReal(),
- captureDevice.exposureDuration.timescale);
- if (!qt_check_exposure_duration(captureDevice, newDuration)) {
- qDebugCamera() << Q_FUNC_INFO << "requested exposure duration is out of range";
- return;
- }
- setCustomMode = true;
- }
-
- float newISO = AVCaptureISOCurrent;
- if (!m_requestedISO.isNull() && !qt_iso_equal(captureDevice, m_requestedISO.toInt())) {
- newISO = m_requestedISO.toInt();
- if (!qt_check_ISO_value(captureDevice, newISO)) {
- qDebugCamera() << Q_FUNC_INFO << "requested ISO value is out of range";
- return;
- }
- setCustomMode = true;
- }
-
- if (!m_requestedCompensation.isNull()
- && !qt_exposure_bias_equal(captureDevice, m_requestedCompensation.toReal())) {
- // TODO: mixed fpns.
- const qreal bias = m_requestedCompensation.toReal();
- if (bias < captureDevice.minExposureTargetBias || bias > captureDevice.maxExposureTargetBias) {
- qDebugCamera() << Q_FUNC_INFO << "exposure compenstation value is"
- << "out of range";
- return;
- }
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- return;
- }
- qt_set_exposure_bias(m_service, this, captureDevice, bias);
- }
-
- // Setting shutter speed (exposure duration) or ISO values
- // also reset exposure mode into Custom. With this settings
- // we ignore any attempts to set exposure mode.
-
- if (setCustomMode) {
- if (!lock)
- qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- else
- qt_set_duration_iso(m_service, this, captureDevice, newDuration, newISO);
- return;
- }
-
- if (!m_requestedMode.isNull()) {
- QCameraExposure::ExposureMode qtMode = m_requestedMode.value<QCameraExposure::ExposureMode>();
- AVCaptureExposureMode avMode = AVCaptureExposureModeContinuousAutoExposure;
- if (!qt_convert_exposure_mode(captureDevice, qtMode, avMode)) {
- qDebugCamera() << Q_FUNC_INFO << "requested exposure mode is not supported";
- return;
- }
-
- if (avMode == captureDevice.exposureMode)
- return;
-
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- return;
- }
-
- [captureDevice setExposureMode:avMode];
- Q_EMIT actualValueChanged(int(QCameraExposureControl::ExposureMode));
- }
-#endif
-}
-
-QT_END_NAMESPACE
-
-#include "moc_avfcameraexposurecontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcameraflashcontrol.h b/src/plugins/avfoundation/camera/avfcameraflashcontrol.h
deleted file mode 100644
index 58403e829..000000000
--- a/src/plugins/avfoundation/camera/avfcameraflashcontrol.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERAFLASHCONTROL_H
-#define AVFCAMERAFLASHCONTROL_H
-
-#include <QtMultimedia/qcameraflashcontrol.h>
-#include <QtMultimedia/qcamera.h>
-
-#include <QtCore/qlist.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraService;
-class AVFCameraSession;
-
-class AVFCameraFlashControl : public QCameraFlashControl
-{
- Q_OBJECT
-public:
- AVFCameraFlashControl(AVFCameraService *service);
-
- QCameraExposure::FlashModes flashMode() const override;
- void setFlashMode(QCameraExposure::FlashModes mode) override;
- bool isFlashModeSupported(QCameraExposure::FlashModes mode) const override;
- bool isFlashReady() const override;
-
-private Q_SLOTS:
- void cameraStateChanged(QCamera::State newState);
-
-private:
- bool applyFlashSettings();
-
- AVFCameraService *m_service;
- AVFCameraSession *m_session;
-
- // Set of bits:
- QCameraExposure::FlashModes m_supportedModes;
- // Only one bit set actually:
- QCameraExposure::FlashModes m_flashMode;
-};
-
-QT_END_NAMESPACE
-
-
-#endif // AVFCAMERAFLASHCONTROL_H
-
diff --git a/src/plugins/avfoundation/camera/avfcameraflashcontrol.mm b/src/plugins/avfoundation/camera/avfcameraflashcontrol.mm
deleted file mode 100644
index 42303ce17..000000000
--- a/src/plugins/avfoundation/camera/avfcameraflashcontrol.mm
+++ /dev/null
@@ -1,233 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcameraflashcontrol.h"
-#include "avfcamerautility.h"
-#include "avfcamerasession.h"
-#include "avfcameraservice.h"
-#include "avfcameradebug.h"
-
-#include <QtCore/qdebug.h>
-
-#include <AVFoundation/AVFoundation.h>
-
-
-AVFCameraFlashControl::AVFCameraFlashControl(AVFCameraService *service)
- : m_service(service)
- , m_session(nullptr)
- , m_supportedModes(QCameraExposure::FlashOff)
- , m_flashMode(QCameraExposure::FlashOff)
-{
- Q_ASSERT(service);
- m_session = m_service->session();
- Q_ASSERT(m_session);
-
- connect(m_session, SIGNAL(stateChanged(QCamera::State)), SLOT(cameraStateChanged(QCamera::State)));
-}
-
-QCameraExposure::FlashModes AVFCameraFlashControl::flashMode() const
-{
- return m_flashMode;
-}
-
-void AVFCameraFlashControl::setFlashMode(QCameraExposure::FlashModes mode)
-{
- if (m_flashMode == mode)
- return;
-
- if (m_session->state() == QCamera::ActiveState && !isFlashModeSupported(mode)) {
- qDebugCamera() << Q_FUNC_INFO << "unsupported mode" << mode;
- return;
- }
-
- m_flashMode = mode;
-
- if (m_session->state() != QCamera::ActiveState)
- return;
-
- applyFlashSettings();
-}
-
-bool AVFCameraFlashControl::isFlashModeSupported(QCameraExposure::FlashModes mode) const
-{
- // From what QCameraExposure has, we can support only these:
- // FlashAuto = 0x1,
- // FlashOff = 0x2,
- // FlashOn = 0x4,
- // AVCaptureDevice has these flash modes:
- // AVCaptureFlashModeAuto
- // AVCaptureFlashModeOff
- // AVCaptureFlashModeOn
- // QCameraExposure also has:
- // FlashTorch = 0x20, --> "Constant light source."
- // FlashVideoLight = 0x40. --> "Constant light source."
- // AVCaptureDevice:
- // AVCaptureTorchModeOff (no mapping)
- // AVCaptureTorchModeOn --> FlashVideoLight
- // AVCaptureTorchModeAuto (no mapping)
-
- return m_supportedModes & mode;
-}
-
-bool AVFCameraFlashControl::isFlashReady() const
-{
- if (m_session->state() != QCamera::ActiveState)
- return false;
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice)
- return false;
-
- if (!captureDevice.hasFlash && !captureDevice.hasTorch)
- return false;
-
- if (!isFlashModeSupported(m_flashMode))
- return false;
-
-#ifdef Q_OS_IOS
- // AVCaptureDevice's docs:
- // "The flash may become unavailable if, for example,
- // the device overheats and needs to cool off."
- if (m_flashMode != QCameraExposure::FlashVideoLight)
- return [captureDevice isFlashAvailable];
-
- return [captureDevice isTorchAvailable];
-#endif
-
- return true;
-}
-
-void AVFCameraFlashControl::cameraStateChanged(QCamera::State newState)
-{
- if (newState == QCamera::UnloadedState) {
- m_supportedModes = QCameraExposure::FlashOff;
- Q_EMIT flashReady(false);
- } else if (newState == QCamera::ActiveState) {
- m_supportedModes = QCameraExposure::FlashOff;
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice) {
- qDebugCamera() << Q_FUNC_INFO << "no capture device in 'Active' state";
- Q_EMIT flashReady(false);
- return;
- }
-
- if (captureDevice.hasFlash) {
- if ([captureDevice isFlashModeSupported:AVCaptureFlashModeOn])
- m_supportedModes |= QCameraExposure::FlashOn;
- if ([captureDevice isFlashModeSupported:AVCaptureFlashModeAuto])
- m_supportedModes |= QCameraExposure::FlashAuto;
- }
-
- if (captureDevice.hasTorch && [captureDevice isTorchModeSupported:AVCaptureTorchModeOn])
- m_supportedModes |= QCameraExposure::FlashVideoLight;
-
- Q_EMIT flashReady(applyFlashSettings());
- }
-}
-
-bool AVFCameraFlashControl::applyFlashSettings()
-{
- Q_ASSERT(m_session->requestedState() == QCamera::ActiveState);
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice) {
- qDebugCamera() << Q_FUNC_INFO << "no capture device found";
- return false;
- }
-
- if (!isFlashModeSupported(m_flashMode)) {
- qDebugCamera() << Q_FUNC_INFO << "unsupported mode" << m_flashMode;
- return false;
- }
-
- if (!captureDevice.hasFlash && !captureDevice.hasTorch) {
- // FlashOff is the only mode we support.
- // Return false - flash is not ready.
- return false;
- }
-
- const AVFConfigurationLock lock(captureDevice);
-
- if (m_flashMode != QCameraExposure::FlashVideoLight) {
- if (captureDevice.torchMode != AVCaptureTorchModeOff) {
-#ifdef Q_OS_IOS
- if (![captureDevice isTorchAvailable]) {
- qDebugCamera() << Q_FUNC_INFO << "torch is not available at the moment";
- return false;
- }
-#endif
- captureDevice.torchMode = AVCaptureTorchModeOff;
- }
-#ifdef Q_OS_IOS
- if (![captureDevice isFlashAvailable]) {
- // We'd like to switch flash (into some mode), but it's not available:
- qDebugCamera() << Q_FUNC_INFO << "flash is not available at the moment";
- return false;
- }
-#endif
- } else {
- if (captureDevice.flashMode != AVCaptureFlashModeOff) {
-#ifdef Q_OS_IOS
- if (![captureDevice isFlashAvailable]) {
- qDebugCamera() << Q_FUNC_INFO << "flash is not available at the moment";
- return false;
- }
-#endif
- captureDevice.flashMode = AVCaptureFlashModeOff;
- }
-
-#ifdef Q_OS_IOS
- if (![captureDevice isTorchAvailable]) {
- qDebugCamera() << Q_FUNC_INFO << "torch is not available at the moment";
- return false;
- }
-#endif
- }
-
- if (m_flashMode == QCameraExposure::FlashOff)
- captureDevice.flashMode = AVCaptureFlashModeOff;
- else if (m_flashMode == QCameraExposure::FlashOn)
- captureDevice.flashMode = AVCaptureFlashModeOn;
- else if (m_flashMode == QCameraExposure::FlashAuto)
- captureDevice.flashMode = AVCaptureFlashModeAuto;
- else if (m_flashMode == QCameraExposure::FlashVideoLight)
- captureDevice.torchMode = AVCaptureTorchModeOn;
-
- return true;
-}
diff --git a/src/plugins/avfoundation/camera/avfcamerafocuscontrol.h b/src/plugins/avfoundation/camera/avfcamerafocuscontrol.h
deleted file mode 100644
index 26135e534..000000000
--- a/src/plugins/avfoundation/camera/avfcamerafocuscontrol.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERAFOCUSCONTROL_H
-#define AVFCAMERAFOCUSCONTROL_H
-
-#include <QtCore/qscopedpointer.h>
-#include <QtCore/qglobal.h>
-
-#include <qcamerafocuscontrol.h>
-
-@class AVCaptureDevice;
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraService;
-class AVFCameraSession;
-
-class AVFCameraFocusControl : public QCameraFocusControl
-{
- Q_OBJECT
-public:
- explicit AVFCameraFocusControl(AVFCameraService *service);
-
- QCameraFocus::FocusModes focusMode() const override;
- void setFocusMode(QCameraFocus::FocusModes mode) override;
- bool isFocusModeSupported(QCameraFocus::FocusModes mode) const override;
-
- QCameraFocus::FocusPointMode focusPointMode() const override;
- void setFocusPointMode(QCameraFocus::FocusPointMode mode) override;
- bool isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const override;
- QPointF customFocusPoint() const override;
- void setCustomFocusPoint(const QPointF &point) override;
-
- QCameraFocusZoneList focusZones() const override;
-
-private Q_SLOTS:
- void cameraStateChanged();
-
-private:
-
- AVFCameraSession *m_session;
- QCameraFocus::FocusModes m_focusMode;
- QCameraFocus::FocusPointMode m_focusPointMode;
- QPointF m_customFocusPoint;
- QPointF m_actualFocusPoint;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFCAMERAFOCUSCONTROL_H
diff --git a/src/plugins/avfoundation/camera/avfcamerafocuscontrol.mm b/src/plugins/avfoundation/camera/avfcamerafocuscontrol.mm
deleted file mode 100644
index 265ccf3fd..000000000
--- a/src/plugins/avfoundation/camera/avfcamerafocuscontrol.mm
+++ /dev/null
@@ -1,306 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcamerafocuscontrol.h"
-#include "avfcamerautility.h"
-#include "avfcameraservice.h"
-#include "avfcamerasession.h"
-#include "avfcameradebug.h"
-
-#include <QtCore/qdebug.h>
-
-#include <AVFoundation/AVFoundation.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace {
-
-bool qt_focus_mode_supported(QCameraFocus::FocusModes mode)
-{
- // Check if QCameraFocus::FocusMode has counterpart in AVFoundation.
-
- // AVFoundation has 'Manual', 'Auto' and 'Continuous',
- // where 'Manual' is actually 'Locked' + writable property 'lensPosition'.
- // Since Qt does not provide an API to manipulate a lens position, 'Maual' mode
- // (at the moment) is not supported.
- return mode == QCameraFocus::AutoFocus
- || mode == QCameraFocus::ContinuousFocus;
-}
-
-bool qt_focus_point_mode_supported(QCameraFocus::FocusPointMode mode)
-{
- return mode == QCameraFocus::FocusPointAuto
- || mode == QCameraFocus::FocusPointCustom
- || mode == QCameraFocus::FocusPointCenter;
-}
-
-AVCaptureFocusMode avf_focus_mode(QCameraFocus::FocusModes requestedMode)
-{
- if (requestedMode == QCameraFocus::AutoFocus)
- return AVCaptureFocusModeAutoFocus;
-
- return AVCaptureFocusModeContinuousAutoFocus;
-}
-
-}
-
-AVFCameraFocusControl::AVFCameraFocusControl(AVFCameraService *service)
- : m_session(service->session()),
- m_focusMode(QCameraFocus::ContinuousFocus),
- m_focusPointMode(QCameraFocus::FocusPointAuto),
- m_customFocusPoint(0.5f, 0.5f),
- m_actualFocusPoint(m_customFocusPoint)
-{
- Q_ASSERT(m_session);
- connect(m_session, SIGNAL(stateChanged(QCamera::State)), SLOT(cameraStateChanged()));
-}
-
-QCameraFocus::FocusModes AVFCameraFocusControl::focusMode() const
-{
- return m_focusMode;
-}
-
-void AVFCameraFocusControl::setFocusMode(QCameraFocus::FocusModes mode)
-{
- if (m_focusMode == mode)
- return;
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice) {
- if (qt_focus_mode_supported(mode)) {
- m_focusMode = mode;
- Q_EMIT focusModeChanged(m_focusMode);
- } else {
- qDebugCamera() << Q_FUNC_INFO
- << "focus mode not supported";
- }
- return;
- }
-
- if (isFocusModeSupported(mode)) {
- const AVFConfigurationLock lock(captureDevice);
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO
- << "failed to lock for configuration";
- return;
- }
-
- captureDevice.focusMode = avf_focus_mode(mode);
- m_focusMode = mode;
- } else {
- qDebugCamera() << Q_FUNC_INFO << "focus mode not supported";
- return;
- }
-
- Q_EMIT focusModeChanged(m_focusMode);
-}
-
-bool AVFCameraFocusControl::isFocusModeSupported(QCameraFocus::FocusModes mode) const
-{
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice)
- return false;
-
- if (!qt_focus_mode_supported(mode))
- return false;
-
- return [captureDevice isFocusModeSupported:avf_focus_mode(mode)];
-}
-
-QCameraFocus::FocusPointMode AVFCameraFocusControl::focusPointMode() const
-{
- return m_focusPointMode;
-}
-
-void AVFCameraFocusControl::setFocusPointMode(QCameraFocus::FocusPointMode mode)
-{
- if (m_focusPointMode == mode)
- return;
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice) {
- if (qt_focus_point_mode_supported(mode)) {
- m_focusPointMode = mode;
- Q_EMIT focusPointModeChanged(mode);
- }
- return;
- }
-
- if (isFocusPointModeSupported(mode)) {
- const AVFConfigurationLock lock(captureDevice);
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- return;
- }
-
- bool resetPOI = false;
- if (mode == QCameraFocus::FocusPointCenter || mode == QCameraFocus::FocusPointAuto) {
- if (m_actualFocusPoint != QPointF(0.5, 0.5)) {
- m_actualFocusPoint = QPointF(0.5, 0.5);
- resetPOI = true;
- }
- } else if (mode == QCameraFocus::FocusPointCustom) {
- if (m_actualFocusPoint != m_customFocusPoint) {
- m_actualFocusPoint = m_customFocusPoint;
- resetPOI = true;
- }
- } // else for any other mode in future.
-
- if (resetPOI) {
- const CGPoint focusPOI = CGPointMake(m_actualFocusPoint.x(), m_actualFocusPoint.y());
- [captureDevice setFocusPointOfInterest:focusPOI];
- }
- m_focusPointMode = mode;
- } else {
- qDebugCamera() << Q_FUNC_INFO << "focus point mode is not supported";
- return;
- }
-
- Q_EMIT focusPointModeChanged(mode);
-}
-
-bool AVFCameraFocusControl::isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const
-{
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice)
- return false;
-
- if (!qt_focus_point_mode_supported(mode))
- return false;
-
- return [captureDevice isFocusPointOfInterestSupported];
-}
-
-QPointF AVFCameraFocusControl::customFocusPoint() const
-{
- return m_customFocusPoint;
-}
-
-void AVFCameraFocusControl::setCustomFocusPoint(const QPointF &point)
-{
- if (m_customFocusPoint == point)
- return;
-
- if (!QRectF(0.f, 0.f, 1.f, 1.f).contains(point)) {
- qDebugCamera() << Q_FUNC_INFO << "invalid focus point (out of range)";
- return;
- }
-
- m_customFocusPoint = point;
- Q_EMIT customFocusPointChanged(m_customFocusPoint);
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice || m_focusPointMode != QCameraFocus::FocusPointCustom)
- return;
-
- if ([captureDevice isFocusPointOfInterestSupported]) {
- const AVFConfigurationLock lock(captureDevice);
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- return;
- }
-
- m_actualFocusPoint = m_customFocusPoint;
- const CGPoint focusPOI = CGPointMake(point.x(), point.y());
- [captureDevice setFocusPointOfInterest:focusPOI];
- if (m_focusMode != QCameraFocus::ContinuousFocus)
- [captureDevice setFocusMode:AVCaptureFocusModeAutoFocus];
- } else {
- qDebugCamera() << Q_FUNC_INFO << "focus point of interest not supported";
- return;
- }
-}
-
-QCameraFocusZoneList AVFCameraFocusControl::focusZones() const
-{
- // Unsupported.
- return QCameraFocusZoneList();
-}
-
-void AVFCameraFocusControl::cameraStateChanged()
-{
- if (m_session->state() != QCamera::ActiveState)
- return;
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice) {
- qDebugCamera() << Q_FUNC_INFO << "capture device is nil in 'active' state";
- return;
- }
-
- const AVFConfigurationLock lock(captureDevice);
- if (m_customFocusPoint != m_actualFocusPoint
- && m_focusPointMode == QCameraFocus::FocusPointCustom) {
- if (![captureDevice isFocusPointOfInterestSupported]) {
- qDebugCamera() << Q_FUNC_INFO
- << "focus point of interest not supported";
- return;
- }
-
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- return;
- }
-
- m_actualFocusPoint = m_customFocusPoint;
- const CGPoint focusPOI = CGPointMake(m_customFocusPoint.x(), m_customFocusPoint.y());
- [captureDevice setFocusPointOfInterest:focusPOI];
- }
-
- if (m_focusMode != QCameraFocus::ContinuousFocus) {
- const AVCaptureFocusMode avMode = avf_focus_mode(m_focusMode);
- if (captureDevice.focusMode != avMode) {
- if (![captureDevice isFocusModeSupported:avMode]) {
- qDebugCamera() << Q_FUNC_INFO << "focus mode not supported";
- return;
- }
-
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- return;
- }
-
- [captureDevice setFocusMode:avMode];
- }
- }
-}
-
-QT_END_NAMESPACE
-
-#include "moc_avfcamerafocuscontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcamerainfocontrol.h b/src/plugins/avfoundation/camera/avfcamerainfocontrol.h
deleted file mode 100644
index c3aa11918..000000000
--- a/src/plugins/avfoundation/camera/avfcamerainfocontrol.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERAINFOCONTROL_H
-#define AVFCAMERAINFOCONTROL_H
-
-#include <qcamerainfocontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraInfoControl : public QCameraInfoControl
-{
- Q_OBJECT
-public:
- explicit AVFCameraInfoControl(QObject *parent = nullptr);
-
- QCamera::Position cameraPosition(const QString &deviceName) const override;
- int cameraOrientation(const QString &deviceName) const override;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFCAMERAINFOCONTROL_H
diff --git a/src/plugins/avfoundation/camera/avfcamerainfocontrol.mm b/src/plugins/avfoundation/camera/avfcamerainfocontrol.mm
deleted file mode 100644
index 26905b0c2..000000000
--- a/src/plugins/avfoundation/camera/avfcamerainfocontrol.mm
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcamerainfocontrol.h"
-#include "avfcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-AVFCameraInfoControl::AVFCameraInfoControl(QObject *parent)
- : QCameraInfoControl(parent)
-{
-}
-
-QCamera::Position AVFCameraInfoControl::cameraPosition(const QString &deviceName) const
-{
- return AVFCameraSession::cameraDeviceInfo(deviceName.toUtf8()).position;
-}
-
-int AVFCameraInfoControl::cameraOrientation(const QString &deviceName) const
-{
- return AVFCameraSession::cameraDeviceInfo(deviceName.toUtf8()).orientation;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/avfoundation/camera/avfcamerametadatacontrol.h b/src/plugins/avfoundation/camera/avfcamerametadatacontrol.h
deleted file mode 100644
index cba29c394..000000000
--- a/src/plugins/avfoundation/camera/avfcamerametadatacontrol.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERAMETADATACONTROL_H
-#define AVFCAMERAMETADATACONTROL_H
-
-#include <qmetadatawritercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraService;
-
-class AVFCameraMetaDataControl : public QMetaDataWriterControl
-{
- Q_OBJECT
-public:
- AVFCameraMetaDataControl(AVFCameraService *service, QObject *parent = nullptr);
- virtual ~AVFCameraMetaDataControl();
-
- bool isMetaDataAvailable() const override;
- bool isWritable() const override;
-
- QVariant metaData(const QString &key) const override;
- void setMetaData(const QString &key, const QVariant &value) override;
- QStringList availableMetaData() const override;
-
-private:
- QMap<QString, QVariant> m_tags;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcamerametadatacontrol.mm b/src/plugins/avfoundation/camera/avfcamerametadatacontrol.mm
deleted file mode 100644
index 95a8a0d79..000000000
--- a/src/plugins/avfoundation/camera/avfcamerametadatacontrol.mm
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcamerametadatacontrol.h"
-#include "avfcamerasession.h"
-#include "avfcameraservice.h"
-
-QT_USE_NAMESPACE
-
-//metadata support is not implemented yet
-
-AVFCameraMetaDataControl::AVFCameraMetaDataControl(AVFCameraService *service, QObject *parent)
- :QMetaDataWriterControl(parent)
-{
- Q_UNUSED(service);
-}
-
-AVFCameraMetaDataControl::~AVFCameraMetaDataControl()
-{
-}
-
-bool AVFCameraMetaDataControl::isMetaDataAvailable() const
-{
- return !m_tags.isEmpty();
-}
-
-bool AVFCameraMetaDataControl::isWritable() const
-{
- return false;
-}
-
-QVariant AVFCameraMetaDataControl::metaData(const QString &key) const
-{
- return m_tags.value(key);
-}
-
-void AVFCameraMetaDataControl::setMetaData(const QString &key, const QVariant &value)
-{
- m_tags.insert(key, value);
-}
-
-QStringList AVFCameraMetaDataControl::availableMetaData() const
-{
- return m_tags.keys();
-}
-
-#include "moc_avfcamerametadatacontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcamerarenderercontrol.h b/src/plugins/avfoundation/camera/avfcamerarenderercontrol.h
deleted file mode 100644
index 3ef3d07d4..000000000
--- a/src/plugins/avfoundation/camera/avfcamerarenderercontrol.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERARENDERERCONTROL_H
-#define AVFCAMERARENDERERCONTROL_H
-
-#include <QtMultimedia/qvideorenderercontrol.h>
-#include <QtMultimedia/qvideoframe.h>
-#include <QtCore/qmutex.h>
-
-#import <AVFoundation/AVFoundation.h>
-
-@class AVFCaptureFramesDelegate;
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraSession;
-class AVFCameraService;
-class AVFCameraRendererControl;
-
-class AVFCameraRendererControl : public QVideoRendererControl
-{
-Q_OBJECT
-public:
- AVFCameraRendererControl(QObject *parent = nullptr);
- ~AVFCameraRendererControl();
-
- QAbstractVideoSurface *surface() const override;
- void setSurface(QAbstractVideoSurface *surface) override;
-
- void configureAVCaptureSession(AVFCameraSession *cameraSession);
- void syncHandleViewfinderFrame(const QVideoFrame &frame);
-
- AVCaptureVideoDataOutput *videoDataOutput() const;
-
- bool supportsTextures() const { return m_supportsTextures; }
-
-#ifdef Q_OS_IOS
- AVFCaptureFramesDelegate *captureDelegate() const;
- void resetCaptureDelegate() const;
-#endif
-
-Q_SIGNALS:
- void surfaceChanged(QAbstractVideoSurface *surface);
-
-private Q_SLOTS:
- void handleViewfinderFrame();
- void updateCaptureConnection();
-
-private:
- QAbstractVideoSurface *m_surface;
- AVFCaptureFramesDelegate *m_viewfinderFramesDelegate;
- AVFCameraSession *m_cameraSession;
- AVCaptureVideoDataOutput *m_videoDataOutput;
-
- bool m_supportsTextures;
- bool m_needsHorizontalMirroring;
-
-#ifdef Q_OS_IOS
- CVOpenGLESTextureCacheRef m_textureCache;
-#endif
-
- QVideoFrame m_lastViewfinderFrame;
- QMutex m_vfMutex;
- dispatch_queue_t m_delegateQueue;
-
- friend class CVImageVideoBuffer;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcamerarenderercontrol.mm b/src/plugins/avfoundation/camera/avfcamerarenderercontrol.mm
deleted file mode 100644
index a03d38b8c..000000000
--- a/src/plugins/avfoundation/camera/avfcamerarenderercontrol.mm
+++ /dev/null
@@ -1,411 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcameraviewfindersettingscontrol.h"
-#include "private/qabstractvideobuffer_p.h"
-#include "avfcamerarenderercontrol.h"
-#include "avfcamerasession.h"
-#include "avfcameraservice.h"
-#include "avfcameradebug.h"
-
-#ifdef Q_OS_IOS
-#include <QtGui/qopengl.h>
-#endif
-
-#include <QtMultimedia/qabstractvideosurface.h>
-#include <QtMultimedia/qabstractvideobuffer.h>
-
-#include <QtMultimedia/qvideosurfaceformat.h>
-
-QT_USE_NAMESPACE
-
-class CVImageVideoBuffer : public QAbstractPlanarVideoBuffer
-{
-public:
- CVImageVideoBuffer(CVImageBufferRef buffer, AVFCameraRendererControl *renderer)
-#ifndef Q_OS_IOS
- : QAbstractPlanarVideoBuffer(NoHandle)
-#else
- : QAbstractPlanarVideoBuffer(renderer->supportsTextures()
- && CVPixelBufferGetPixelFormatType(buffer) == kCVPixelFormatType_32BGRA
- ? GLTextureHandle : NoHandle)
- , m_texture(nullptr)
- , m_renderer(renderer)
-#endif
- , m_buffer(buffer)
- , m_mode(NotMapped)
- {
-#ifndef Q_OS_IOS
- Q_UNUSED(renderer);
-#endif // Q_OS_IOS
- CVPixelBufferRetain(m_buffer);
- }
-
- ~CVImageVideoBuffer()
- {
- CVImageVideoBuffer::unmap();
-#ifdef Q_OS_IOS
- if (m_texture)
- CFRelease(m_texture);
-#endif
- CVPixelBufferRelease(m_buffer);
- }
-
- MapMode mapMode() const { return m_mode; }
-
- int map(QAbstractVideoBuffer::MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4])
- {
- // We only support RGBA or NV12 (or Apple's version of NV12),
- // they are either 0 planes or 2.
- const size_t nPlanes = CVPixelBufferGetPlaneCount(m_buffer);
- Q_ASSERT(nPlanes <= 2);
-
- if (!nPlanes) {
- data[0] = map(mode, numBytes, bytesPerLine);
- return data[0] ? 1 : 0;
- }
-
- // For a bi-planar format we have to set the parameters correctly:
- if (mode != QAbstractVideoBuffer::NotMapped && m_mode == QAbstractVideoBuffer::NotMapped) {
- CVPixelBufferLockBaseAddress(m_buffer, mode == QAbstractVideoBuffer::ReadOnly
- ? kCVPixelBufferLock_ReadOnly
- : 0);
-
- if (numBytes)
- *numBytes = CVPixelBufferGetDataSize(m_buffer);
-
- if (bytesPerLine) {
- // At the moment we handle only bi-planar format.
- bytesPerLine[0] = CVPixelBufferGetBytesPerRowOfPlane(m_buffer, 0);
- bytesPerLine[1] = CVPixelBufferGetBytesPerRowOfPlane(m_buffer, 1);
- }
-
- if (data) {
- data[0] = static_cast<uchar*>(CVPixelBufferGetBaseAddressOfPlane(m_buffer, 0));
- data[1] = static_cast<uchar*>(CVPixelBufferGetBaseAddressOfPlane(m_buffer, 1));
- }
-
- m_mode = mode;
- }
-
- return nPlanes;
- }
-
- uchar *map(MapMode mode, int *numBytes, int *bytesPerLine)
- {
- if (mode != NotMapped && m_mode == NotMapped) {
- CVPixelBufferLockBaseAddress(m_buffer, mode == QAbstractVideoBuffer::ReadOnly
- ? kCVPixelBufferLock_ReadOnly
- : 0);
- if (numBytes)
- *numBytes = CVPixelBufferGetDataSize(m_buffer);
-
- if (bytesPerLine)
- *bytesPerLine = CVPixelBufferGetBytesPerRow(m_buffer);
-
- m_mode = mode;
- return static_cast<uchar*>(CVPixelBufferGetBaseAddress(m_buffer));
- } else {
- return nullptr;
- }
- }
-
- void unmap()
- {
- if (m_mode != NotMapped) {
- CVPixelBufferUnlockBaseAddress(m_buffer, m_mode == QAbstractVideoBuffer::ReadOnly
- ? kCVPixelBufferLock_ReadOnly
- : 0);
- m_mode = NotMapped;
- }
- }
-
- QVariant handle() const
- {
-#ifdef Q_OS_IOS
- // Called from the render thread, so there is a current OpenGL context
-
- if (!m_renderer->m_textureCache) {
- CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault,
- nullptr,
- [EAGLContext currentContext],
- nullptr,
- &m_renderer->m_textureCache);
-
- if (err != kCVReturnSuccess)
- qWarning("Error creating texture cache");
- }
-
- if (m_renderer->m_textureCache && !m_texture) {
- CVOpenGLESTextureCacheFlush(m_renderer->m_textureCache, 0);
-
- CVReturn err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault,
- m_renderer->m_textureCache,
- m_buffer,
- nullptr,
- GL_TEXTURE_2D,
- GL_RGBA,
- CVPixelBufferGetWidth(m_buffer),
- CVPixelBufferGetHeight(m_buffer),
- GL_RGBA,
- GL_UNSIGNED_BYTE,
- 0,
- &m_texture);
- if (err != kCVReturnSuccess)
- qWarning("Error creating texture from buffer");
- }
-
- if (m_texture)
- return CVOpenGLESTextureGetName(m_texture);
- else
- return 0;
-#else
- return QVariant();
-#endif
- }
-
-private:
-#ifdef Q_OS_IOS
- mutable CVOpenGLESTextureRef m_texture;
- AVFCameraRendererControl *m_renderer;
-#endif
- CVImageBufferRef m_buffer;
- MapMode m_mode;
-};
-
-
-@interface AVFCaptureFramesDelegate : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate>
-
-- (AVFCaptureFramesDelegate *) initWithRenderer:(AVFCameraRendererControl*)renderer;
-
-- (void) captureOutput:(AVCaptureOutput *)captureOutput
- didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
- fromConnection:(AVCaptureConnection *)connection;
-
-@end
-
-@implementation AVFCaptureFramesDelegate
-{
-@private
- AVFCameraRendererControl *m_renderer;
-}
-
-- (AVFCaptureFramesDelegate *) initWithRenderer:(AVFCameraRendererControl*)renderer
-{
- if (!(self = [super init]))
- return nil;
-
- self->m_renderer = renderer;
- return self;
-}
-
-- (void)captureOutput:(AVCaptureOutput *)captureOutput
- didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
- fromConnection:(AVCaptureConnection *)connection
-{
- Q_UNUSED(connection);
- Q_UNUSED(captureOutput);
-
- // NB: on iOS captureOutput/connection can be nil (when recording a video -
- // avfmediaassetwriter).
-
- CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
-
- int width = CVPixelBufferGetWidth(imageBuffer);
- int height = CVPixelBufferGetHeight(imageBuffer);
- QVideoFrame::PixelFormat format =
- AVFCameraViewfinderSettingsControl2::QtPixelFormatFromCVFormat(CVPixelBufferGetPixelFormatType(imageBuffer));
- if (format == QVideoFrame::Format_Invalid)
- return;
-
- QVideoFrame frame(new CVImageVideoBuffer(imageBuffer, m_renderer),
- QSize(width, height),
- format);
-
- m_renderer->syncHandleViewfinderFrame(frame);
-}
-
-@end
-
-
-AVFCameraRendererControl::AVFCameraRendererControl(QObject *parent)
- : QVideoRendererControl(parent)
- , m_surface(nullptr)
- , m_supportsTextures(false)
- , m_needsHorizontalMirroring(false)
-#ifdef Q_OS_IOS
- , m_textureCache(nullptr)
-#endif
-{
- m_viewfinderFramesDelegate = [[AVFCaptureFramesDelegate alloc] initWithRenderer:this];
-}
-
-AVFCameraRendererControl::~AVFCameraRendererControl()
-{
- [m_cameraSession->captureSession() removeOutput:m_videoDataOutput];
- [m_viewfinderFramesDelegate release];
- if (m_delegateQueue)
- dispatch_release(m_delegateQueue);
-#ifdef Q_OS_IOS
- if (m_textureCache)
- CFRelease(m_textureCache);
-#endif
-}
-
-QAbstractVideoSurface *AVFCameraRendererControl::surface() const
-{
- return m_surface;
-}
-
-void AVFCameraRendererControl::setSurface(QAbstractVideoSurface *surface)
-{
- if (m_surface != surface) {
- m_surface = surface;
- m_supportsTextures = m_surface
- ? !m_surface->supportedPixelFormats(QAbstractVideoBuffer::GLTextureHandle).isEmpty()
- : false;
- Q_EMIT surfaceChanged(surface);
- }
-}
-
-void AVFCameraRendererControl::configureAVCaptureSession(AVFCameraSession *cameraSession)
-{
- m_cameraSession = cameraSession;
- connect(m_cameraSession, SIGNAL(readyToConfigureConnections()),
- this, SLOT(updateCaptureConnection()));
-
- m_needsHorizontalMirroring = false;
-
- m_videoDataOutput = [[[AVCaptureVideoDataOutput alloc] init] autorelease];
-
- // Configure video output
- m_delegateQueue = dispatch_queue_create("vf_queue", nullptr);
- [m_videoDataOutput
- setSampleBufferDelegate:m_viewfinderFramesDelegate
- queue:m_delegateQueue];
-
- [m_cameraSession->captureSession() addOutput:m_videoDataOutput];
-}
-
-void AVFCameraRendererControl::updateCaptureConnection()
-{
- AVCaptureConnection *connection = [m_videoDataOutput connectionWithMediaType:AVMediaTypeVideo];
- if (connection == nil || !m_cameraSession->videoCaptureDevice())
- return;
-
- // Frames of front-facing cameras should be mirrored horizontally (it's the default when using
- // AVCaptureVideoPreviewLayer but not with AVCaptureVideoDataOutput)
- if (connection.isVideoMirroringSupported)
- connection.videoMirrored = m_cameraSession->videoCaptureDevice().position == AVCaptureDevicePositionFront;
-
- // If the connection does't support mirroring, we'll have to do it ourselves
- m_needsHorizontalMirroring = !connection.isVideoMirrored
- && m_cameraSession->videoCaptureDevice().position == AVCaptureDevicePositionFront;
-}
-
-//can be called from non main thread
-void AVFCameraRendererControl::syncHandleViewfinderFrame(const QVideoFrame &frame)
-{
- QMutexLocker lock(&m_vfMutex);
- if (!m_lastViewfinderFrame.isValid()) {
- static QMetaMethod handleViewfinderFrameSlot = metaObject()->method(
- metaObject()->indexOfMethod("handleViewfinderFrame()"));
-
- handleViewfinderFrameSlot.invoke(this, Qt::QueuedConnection);
- }
-
- m_lastViewfinderFrame = frame;
-
- if (m_cameraSession && m_lastViewfinderFrame.isValid())
- m_cameraSession->onCameraFrameFetched(m_lastViewfinderFrame);
-}
-
-AVCaptureVideoDataOutput *AVFCameraRendererControl::videoDataOutput() const
-{
- return m_videoDataOutput;
-}
-
-#ifdef Q_OS_IOS
-
-AVFCaptureFramesDelegate *AVFCameraRendererControl::captureDelegate() const
-{
- return m_viewfinderFramesDelegate;
-}
-
-void AVFCameraRendererControl::resetCaptureDelegate() const
-{
- [m_videoDataOutput setSampleBufferDelegate:m_viewfinderFramesDelegate queue:m_delegateQueue];
-}
-
-#endif
-
-void AVFCameraRendererControl::handleViewfinderFrame()
-{
- QVideoFrame frame;
- {
- QMutexLocker lock(&m_vfMutex);
- frame = m_lastViewfinderFrame;
- m_lastViewfinderFrame = QVideoFrame();
- }
-
- if (m_surface && frame.isValid()) {
- if (m_surface->isActive() && (m_surface->surfaceFormat().pixelFormat() != frame.pixelFormat()
- || m_surface->surfaceFormat().frameSize() != frame.size())) {
- m_surface->stop();
- }
-
- if (!m_surface->isActive()) {
- QVideoSurfaceFormat format(frame.size(), frame.pixelFormat(), frame.handleType());
- if (m_needsHorizontalMirroring)
- format.setProperty("mirrored", true);
-
- if (!m_surface->start(format)) {
- qWarning() << "Failed to start viewfinder m_surface, format:" << format;
- } else {
- qDebugCamera() << "Viewfinder started: " << format;
- }
- }
-
- if (m_surface->isActive())
- m_surface->present(frame);
- }
-}
-
-
-#include "moc_avfcamerarenderercontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcameraservice.h b/src/plugins/avfoundation/camera/avfcameraservice.h
deleted file mode 100644
index 1397a7dee..000000000
--- a/src/plugins/avfoundation/camera/avfcameraservice.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERASERVICE_H
-#define AVFCAMERASERVICE_H
-
-#include <QtCore/qobject.h>
-#include <QtCore/qset.h>
-#include <qmediaservice.h>
-
-
-QT_BEGIN_NAMESPACE
-class QCameraControl;
-class QMediaRecorderControl;
-class AVFCameraControl;
-class AVFCameraInfoControl;
-class AVFCameraMetaDataControl;
-class AVFVideoWindowControl;
-class AVFVideoWidgetControl;
-class AVFCameraRendererControl;
-class AVFImageCaptureControl;
-class AVFCameraSession;
-class AVFCameraDeviceControl;
-class AVFAudioInputSelectorControl;
-class AVFCameraFocusControl;
-class AVFCameraExposureControl;
-class AVFCameraZoomControl;
-class AVFCameraViewfinderSettingsControl2;
-class AVFCameraViewfinderSettingsControl;
-class AVFImageEncoderControl;
-class AVFCameraFlashControl;
-class AVFMediaRecorderControl;
-class AVFMediaRecorderControlIOS;
-class AVFAudioEncoderSettingsControl;
-class AVFVideoEncoderSettingsControl;
-class AVFMediaContainerControl;
-class AVFCameraWindowControl;
-class AVFCaptureDestinationControl;
-
-class AVFCameraService : public QMediaService
-{
-Q_OBJECT
-public:
- AVFCameraService(QObject *parent = nullptr);
- ~AVFCameraService();
-
- QMediaControl* requestControl(const char *name);
- void releaseControl(QMediaControl *control);
-
- AVFCameraSession *session() const { return m_session; }
- AVFCameraControl *cameraControl() const { return m_cameraControl; }
- AVFCameraDeviceControl *videoDeviceControl() const { return m_videoDeviceControl; }
- AVFAudioInputSelectorControl *audioInputSelectorControl() const { return m_audioInputSelectorControl; }
- AVFCameraMetaDataControl *metaDataControl() const { return m_metaDataControl; }
- QMediaRecorderControl *recorderControl() const { return m_recorderControl; }
- AVFImageCaptureControl *imageCaptureControl() const { return m_imageCaptureControl; }
- AVFCameraFocusControl *cameraFocusControl() const { return m_cameraFocusControl; }
- AVFCameraExposureControl *cameraExposureControl() const {return m_cameraExposureControl; }
- AVFCameraZoomControl *cameraZoomControl() const {return m_cameraZoomControl; }
- AVFCameraRendererControl *videoOutput() const {return m_videoOutput; }
- AVFCameraViewfinderSettingsControl2 *viewfinderSettingsControl2() const {return m_viewfinderSettingsControl2; }
- AVFCameraViewfinderSettingsControl *viewfinderSettingsControl() const {return m_viewfinderSettingsControl; }
- AVFImageEncoderControl *imageEncoderControl() const {return m_imageEncoderControl; }
- AVFCameraFlashControl *flashControl() const {return m_flashControl; }
- AVFAudioEncoderSettingsControl *audioEncoderSettingsControl() const { return m_audioEncoderSettingsControl; }
- AVFVideoEncoderSettingsControl *videoEncoderSettingsControl() const {return m_videoEncoderSettingsControl; }
- AVFMediaContainerControl *mediaContainerControl() const { return m_mediaContainerControl; }
- AVFCaptureDestinationControl *captureDestinationControl() const { return m_captureDestinationControl; }
-
-private:
- AVFCameraSession *m_session;
- AVFCameraControl *m_cameraControl;
- AVFCameraInfoControl *m_cameraInfoControl;
- AVFCameraDeviceControl *m_videoDeviceControl;
- AVFAudioInputSelectorControl *m_audioInputSelectorControl;
- AVFCameraRendererControl *m_videoOutput;
- AVFCameraMetaDataControl *m_metaDataControl;
- QMediaRecorderControl *m_recorderControl;
- AVFImageCaptureControl *m_imageCaptureControl;
- AVFCameraFocusControl *m_cameraFocusControl;
- AVFCameraExposureControl *m_cameraExposureControl;
- AVFCameraZoomControl *m_cameraZoomControl;
- AVFCameraViewfinderSettingsControl2 *m_viewfinderSettingsControl2;
- AVFCameraViewfinderSettingsControl *m_viewfinderSettingsControl;
- AVFImageEncoderControl *m_imageEncoderControl;
- AVFCameraFlashControl *m_flashControl;
- AVFAudioEncoderSettingsControl *m_audioEncoderSettingsControl;
- AVFVideoEncoderSettingsControl *m_videoEncoderSettingsControl;
- AVFMediaContainerControl *m_mediaContainerControl;
- AVFCameraWindowControl *m_captureWindowControl;
- AVFCaptureDestinationControl *m_captureDestinationControl;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcameraservice.mm b/src/plugins/avfoundation/camera/avfcameraservice.mm
deleted file mode 100644
index 79bf73910..000000000
--- a/src/plugins/avfoundation/camera/avfcameraservice.mm
+++ /dev/null
@@ -1,267 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qvariant.h>
-#include <QtCore/qdebug.h>
-
-#include "avfcameraservice.h"
-#include "avfcameracontrol.h"
-#include "avfcamerainfocontrol.h"
-#include "avfcamerasession.h"
-#include "avfcameradevicecontrol.h"
-#include "avfaudioinputselectorcontrol.h"
-#include "avfcamerametadatacontrol.h"
-#include "avfmediarecordercontrol.h"
-#include "avfimagecapturecontrol.h"
-#include "avfcamerarenderercontrol.h"
-#include "avfmediarecordercontrol.h"
-#include "avfimagecapturecontrol.h"
-#include "avfmediavideoprobecontrol.h"
-#include "avfcamerafocuscontrol.h"
-#include "avfcameraexposurecontrol.h"
-#include "avfcameraviewfindersettingscontrol.h"
-#include "avfimageencodercontrol.h"
-#include "avfcameraflashcontrol.h"
-#include "avfaudioencodersettingscontrol.h"
-#include "avfvideoencodersettingscontrol.h"
-#include "avfmediacontainercontrol.h"
-#include "avfcapturedestinationcontrol.h"
-#include "avfcamerawindowcontrol.h"
-
-#ifdef Q_OS_IOS
-#include "avfcamerazoomcontrol.h"
-#include "avfmediarecordercontrol_ios.h"
-#endif
-
-#include <private/qmediaplaylistnavigator_p.h>
-#include <qmediaplaylist.h>
-
-QT_USE_NAMESPACE
-
-AVFCameraService::AVFCameraService(QObject *parent):
- QMediaService(parent),
- m_videoOutput(nullptr),
- m_captureWindowControl(nullptr)
-{
- m_session = new AVFCameraSession(this);
- m_cameraControl = new AVFCameraControl(this);
- m_cameraInfoControl = new AVFCameraInfoControl(this);
- m_videoDeviceControl = new AVFCameraDeviceControl(this);
- m_audioInputSelectorControl = new AVFAudioInputSelectorControl(this);
-
- m_metaDataControl = new AVFCameraMetaDataControl(this);
-#ifndef Q_OS_IOS
- // This will connect a slot to 'captureModeChanged'
- // and will break viewfinder by attaching AVCaptureMovieFileOutput
- // in this slot.
- m_recorderControl = new AVFMediaRecorderControl(this);
-#else
- m_recorderControl = new AVFMediaRecorderControlIOS(this);
-#endif
- m_imageCaptureControl = new AVFImageCaptureControl(this);
- m_cameraFocusControl = new AVFCameraFocusControl(this);
- m_cameraExposureControl = nullptr;
-#ifdef Q_OS_IOS
- m_cameraExposureControl = new AVFCameraExposureControl(this);
-#endif
-
- m_cameraZoomControl = nullptr;
-#ifdef Q_OS_IOS
- m_cameraZoomControl = new AVFCameraZoomControl(this);
-#endif
- m_viewfinderSettingsControl2 = new AVFCameraViewfinderSettingsControl2(this);
- m_viewfinderSettingsControl = new AVFCameraViewfinderSettingsControl(this);
- m_imageEncoderControl = new AVFImageEncoderControl(this);
- m_flashControl = new AVFCameraFlashControl(this);
- m_audioEncoderSettingsControl = new AVFAudioEncoderSettingsControl(this);
- m_videoEncoderSettingsControl = new AVFVideoEncoderSettingsControl(this);
- m_mediaContainerControl = new AVFMediaContainerControl(this);
- m_captureDestinationControl = new AVFCaptureDestinationControl;
-}
-
-AVFCameraService::~AVFCameraService()
-{
- m_cameraControl->setState(QCamera::UnloadedState);
-
-#ifdef Q_OS_IOS
- delete m_recorderControl;
-#endif
-
- if (m_captureWindowControl) {
- m_session->setCapturePreviewOutput(nullptr);
- delete m_captureWindowControl;
- m_captureWindowControl = nullptr;
- }
-
- if (m_videoOutput) {
- m_session->setVideoOutput(nullptr);
- delete m_videoOutput;
- m_videoOutput = nullptr;
- }
-
- //delete controls before session,
- //so they have a chance to do deinitialization
- delete m_imageCaptureControl;
- //delete m_recorderControl;
- delete m_metaDataControl;
- delete m_cameraControl;
- delete m_cameraFocusControl;
- delete m_cameraExposureControl;
-#ifdef Q_OS_IOS
- delete m_cameraZoomControl;
-#endif
- delete m_viewfinderSettingsControl2;
- delete m_viewfinderSettingsControl;
- delete m_imageEncoderControl;
- delete m_flashControl;
- delete m_audioEncoderSettingsControl;
- delete m_videoEncoderSettingsControl;
- delete m_mediaContainerControl;
- delete m_captureDestinationControl;
-
- delete m_session;
-}
-
-QMediaControl *AVFCameraService::requestControl(const char *name)
-{
- if (qstrcmp(name, QCameraControl_iid) == 0)
- return m_cameraControl;
-
- if (qstrcmp(name, QCameraInfoControl_iid) == 0)
- return m_cameraInfoControl;
-
- if (qstrcmp(name, QVideoDeviceSelectorControl_iid) == 0)
- return m_videoDeviceControl;
-
- if (qstrcmp(name, QAudioInputSelectorControl_iid) == 0)
- return m_audioInputSelectorControl;
-
- //metadata support is not implemented yet
- //if (qstrcmp(name, QMetaDataWriterControl_iid) == 0)
- // return m_metaDataControl;
-
- if (qstrcmp(name, QMediaRecorderControl_iid) == 0)
- return m_recorderControl;
-
- if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0)
- return m_imageCaptureControl;
-
- if (qstrcmp(name, QCameraExposureControl_iid) == 0)
- return m_cameraExposureControl;
-
- if (qstrcmp(name, QCameraFocusControl_iid) == 0)
- return m_cameraFocusControl;
-
- if (qstrcmp(name, QCameraViewfinderSettingsControl2_iid) == 0)
- return m_viewfinderSettingsControl2;
-
- if (qstrcmp(name, QCameraViewfinderSettingsControl_iid) == 0)
- return m_viewfinderSettingsControl;
-
- if (qstrcmp(name, QImageEncoderControl_iid) == 0)
- return m_imageEncoderControl;
-
- if (qstrcmp(name, QCameraFlashControl_iid) == 0)
- return m_flashControl;
-
- if (qstrcmp(name, QAudioEncoderSettingsControl_iid) == 0)
- return m_audioEncoderSettingsControl;
-
- if (qstrcmp(name, QVideoEncoderSettingsControl_iid) == 0)
- return m_videoEncoderSettingsControl;
-
- if (qstrcmp(name, QMediaContainerControl_iid) == 0)
- return m_mediaContainerControl;
-
- if (qstrcmp(name,QMediaVideoProbeControl_iid) == 0) {
- AVFMediaVideoProbeControl *videoProbe = nullptr;
- videoProbe = new AVFMediaVideoProbeControl(this);
- m_session->addProbe(videoProbe);
- return videoProbe;
- }
-
-#ifdef Q_OS_IOS
- if (qstrcmp(name, QCameraZoomControl_iid) == 0)
- return m_cameraZoomControl;
-#endif
-
- if (qstrcmp(name, QCameraCaptureDestinationControl_iid) == 0)
- return m_captureDestinationControl;
-
- if (!m_captureWindowControl) {
- if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
- m_captureWindowControl = new AVFCameraWindowControl(this);
- m_session->setCapturePreviewOutput(m_captureWindowControl);
- return m_captureWindowControl;
- }
- }
-
- if (!m_videoOutput) {
- if (qstrcmp(name, QVideoRendererControl_iid) == 0)
- m_videoOutput = new AVFCameraRendererControl(this);
-
- if (m_videoOutput) {
- m_session->setVideoOutput(m_videoOutput);
- return m_videoOutput;
- }
- }
-
- return nullptr;
-}
-
-void AVFCameraService::releaseControl(QMediaControl *control)
-{
- AVFMediaVideoProbeControl *videoProbe = qobject_cast<AVFMediaVideoProbeControl *>(control);
- if (videoProbe) {
- m_session->removeProbe(videoProbe);
- delete videoProbe;
- } else if (m_videoOutput == control) {
- m_session->setVideoOutput(nullptr);
- delete m_videoOutput;
- m_videoOutput = nullptr;
- }
- else if (m_captureWindowControl == control) {
- m_session->setCapturePreviewOutput(nullptr);
- delete m_captureWindowControl;
- m_captureWindowControl = nullptr;
- }
-}
-
-
-#include "moc_avfcameraservice.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcameraserviceplugin.h b/src/plugins/avfoundation/camera/avfcameraserviceplugin.h
deleted file mode 100644
index bd5f83249..000000000
--- a/src/plugins/avfoundation/camera/avfcameraserviceplugin.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef AVFSERVICEPLUGIN_H
-#define AVFSERVICEPLUGIN_H
-
-#include <qmediaserviceproviderplugin.h>
-#include <QtCore/qmap.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFServicePlugin : public QMediaServiceProviderPlugin,
- public QMediaServiceSupportedDevicesInterface,
- public QMediaServiceDefaultDeviceInterface,
- public QMediaServiceCameraInfoInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
- Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
- Q_INTERFACES(QMediaServiceCameraInfoInterface)
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "avfcamera.json")
-
-public:
- AVFServicePlugin();
-
- QMediaService* create(QString const &key) override;
- void release(QMediaService *service) override;
-
- QByteArray defaultDevice(const QByteArray &service) const override;
- QList<QByteArray> devices(const QByteArray &service) const override;
- QString deviceDescription(const QByteArray &service, const QByteArray &device) override;
-
- QCamera::Position cameraPosition(const QByteArray &device) const override;
- int cameraOrientation(const QByteArray &device) const override;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcameraserviceplugin.mm b/src/plugins/avfoundation/camera/avfcameraserviceplugin.mm
deleted file mode 100644
index 08bd8c9bd..000000000
--- a/src/plugins/avfoundation/camera/avfcameraserviceplugin.mm
+++ /dev/null
@@ -1,113 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qstring.h>
-#include <QtCore/qdebug.h>
-
-#include "avfcameraserviceplugin.h"
-#include "avfcameraservice.h"
-#include "avfcamerasession.h"
-
-#include <qmediaserviceproviderplugin.h>
-
-QT_BEGIN_NAMESPACE
-
-AVFServicePlugin::AVFServicePlugin()
-{
-}
-
-QMediaService* AVFServicePlugin::create(QString const& key)
-{
- if (key == QLatin1String(Q_MEDIASERVICE_CAMERA))
- return new AVFCameraService;
- else
- qWarning() << "unsupported key:" << key;
-
- return nullptr;
-}
-
-void AVFServicePlugin::release(QMediaService *service)
-{
- delete service;
-}
-
-QByteArray AVFServicePlugin::defaultDevice(const QByteArray &service) const
-{
- if (service == Q_MEDIASERVICE_CAMERA) {
- int i = AVFCameraSession::defaultCameraIndex();
- if (i != -1)
- return AVFCameraSession::availableCameraDevices().at(i).deviceId;
- }
-
- return QByteArray();
-}
-
-QList<QByteArray> AVFServicePlugin::devices(const QByteArray &service) const
-{
- QList<QByteArray> devs;
-
- if (service == Q_MEDIASERVICE_CAMERA) {
- const QList<AVFCameraInfo> &cameras = AVFCameraSession::availableCameraDevices();
- devs.reserve(cameras.size());
- for (const AVFCameraInfo &info : cameras)
- devs.append(info.deviceId);
- }
-
- return devs;
-}
-
-QString AVFServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
-{
- if (service == Q_MEDIASERVICE_CAMERA)
- return AVFCameraSession::cameraDeviceInfo(device).description;
-
- return QString();
-}
-
-QCamera::Position AVFServicePlugin::cameraPosition(const QByteArray &device) const
-{
- return AVFCameraSession::cameraDeviceInfo(device).position;
-}
-
-int AVFServicePlugin::cameraOrientation(const QByteArray &device) const
-{
- return AVFCameraSession::cameraDeviceInfo(device).orientation;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/avfoundation/camera/avfcamerasession.h b/src/plugins/avfoundation/camera/avfcamerasession.h
deleted file mode 100644
index a449bb806..000000000
--- a/src/plugins/avfoundation/camera/avfcamerasession.h
+++ /dev/null
@@ -1,144 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERASESSION_H
-#define AVFCAMERASESSION_H
-
-#include <QtCore/qmutex.h>
-#include <QtMultimedia/qcamera.h>
-#include <QVideoFrame>
-
-#import <AVFoundation/AVFoundation.h>
-
-@class AVFCameraSessionObserver;
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraControl;
-class AVFCameraService;
-class AVFCameraRendererControl;
-class AVFMediaVideoProbeControl;
-class AVFCameraWindowControl;
-
-struct AVFCameraInfo
-{
- AVFCameraInfo() : position(QCamera::UnspecifiedPosition), orientation(0)
- { }
-
- QByteArray deviceId;
- QString description;
- QCamera::Position position;
- int orientation;
-};
-
-class AVFCameraSession : public QObject
-{
- Q_OBJECT
-public:
- AVFCameraSession(AVFCameraService *service, QObject *parent = nullptr);
- ~AVFCameraSession();
-
- static int defaultCameraIndex();
- static const QList<AVFCameraInfo> &availableCameraDevices();
- static AVFCameraInfo cameraDeviceInfo(const QByteArray &device);
- AVFCameraInfo activeCameraInfo() const { return m_activeCameraInfo; }
-
- void setVideoOutput(AVFCameraRendererControl *output);
- void setCapturePreviewOutput(AVFCameraWindowControl *output);
- AVCaptureSession *captureSession() const { return m_captureSession; }
- AVCaptureDevice *videoCaptureDevice() const;
-
- QCamera::State state() const;
- QCamera::State requestedState() const { return m_state; }
- bool isActive() const { return m_active; }
-
- void addProbe(AVFMediaVideoProbeControl *probe);
- void removeProbe(AVFMediaVideoProbeControl *probe);
- FourCharCode defaultCodec();
-
- AVCaptureDeviceInput *videoInput() const {return m_videoInput;}
-
-public Q_SLOTS:
- void setState(QCamera::State state);
-
- void processRuntimeError();
- void processSessionStarted();
- void processSessionStopped();
-
- void onCaptureModeChanged(QCamera::CaptureModes mode);
-
- void onCameraFrameFetched(const QVideoFrame &frame);
-
-Q_SIGNALS:
- void readyToConfigureConnections();
- void stateChanged(QCamera::State newState);
- void activeChanged(bool);
- void newViewfinderFrame(const QVideoFrame &frame);
- void error(int error, const QString &errorString);
-
-private:
- static void updateCameraDevices();
- void attachVideoInputDevice();
- bool applyImageEncoderSettings();
- bool applyViewfinderSettings();
-
- static int m_defaultCameraIndex;
- static QList<AVFCameraInfo> m_cameraDevices;
- AVFCameraInfo m_activeCameraInfo;
-
- AVFCameraService *m_service;
- AVFCameraRendererControl *m_videoOutput;
- AVFCameraWindowControl *m_capturePreviewWindowOutput;
-
- QCamera::State m_state;
- bool m_active;
-
- AVCaptureSession *m_captureSession;
- AVCaptureDeviceInput *m_videoInput;
- AVFCameraSessionObserver *m_observer;
-
- QSet<AVFMediaVideoProbeControl *> m_videoProbes;
- QMutex m_videoProbesMutex;
-
- FourCharCode m_defaultCodec;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcamerasession.mm b/src/plugins/avfoundation/camera/avfcamerasession.mm
deleted file mode 100644
index ebefa07e5..000000000
--- a/src/plugins/avfoundation/camera/avfcamerasession.mm
+++ /dev/null
@@ -1,492 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcameradebug.h"
-#include "avfcamerasession.h"
-#include "avfcameraservice.h"
-#include "avfcameracontrol.h"
-#include "avfcamerarenderercontrol.h"
-#include "avfcameradevicecontrol.h"
-#include "avfaudioinputselectorcontrol.h"
-#include "avfmediavideoprobecontrol.h"
-#include "avfcameraviewfindersettingscontrol.h"
-#include "avfimageencodercontrol.h"
-#include "avfcamerautility.h"
-#include "avfcamerawindowcontrol.h"
-
-#include <CoreFoundation/CoreFoundation.h>
-#include <Foundation/Foundation.h>
-
-#include <QtCore/qdatetime.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qelapsedtimer.h>
-
-#include <QtCore/qdebug.h>
-
-QT_USE_NAMESPACE
-
-int AVFCameraSession::m_defaultCameraIndex;
-QList<AVFCameraInfo> AVFCameraSession::m_cameraDevices;
-
-@interface AVFCameraSessionObserver : NSObject
-
-- (AVFCameraSessionObserver *) initWithCameraSession:(AVFCameraSession*)session;
-- (void) processRuntimeError:(NSNotification *)notification;
-- (void) processSessionStarted:(NSNotification *)notification;
-- (void) processSessionStopped:(NSNotification *)notification;
-
-@end
-
-@implementation AVFCameraSessionObserver
-{
-@private
- AVFCameraSession *m_session;
- AVCaptureSession *m_captureSession;
-}
-
-- (AVFCameraSessionObserver *) initWithCameraSession:(AVFCameraSession*)session
-{
- if (!(self = [super init]))
- return nil;
-
- self->m_session = session;
- self->m_captureSession = session->captureSession();
-
- [m_captureSession retain];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(processRuntimeError:)
- name:AVCaptureSessionRuntimeErrorNotification
- object:m_captureSession];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(processSessionStarted:)
- name:AVCaptureSessionDidStartRunningNotification
- object:m_captureSession];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(processSessionStopped:)
- name:AVCaptureSessionDidStopRunningNotification
- object:m_captureSession];
-
- return self;
-}
-
-- (void) dealloc
-{
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:AVCaptureSessionRuntimeErrorNotification
- object:m_captureSession];
-
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:AVCaptureSessionDidStartRunningNotification
- object:m_captureSession];
-
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:AVCaptureSessionDidStopRunningNotification
- object:m_captureSession];
- [m_captureSession release];
- [super dealloc];
-}
-
-- (void) processRuntimeError:(NSNotification *)notification
-{
- Q_UNUSED(notification);
- QMetaObject::invokeMethod(m_session, "processRuntimeError", Qt::AutoConnection);
-}
-
-- (void) processSessionStarted:(NSNotification *)notification
-{
- Q_UNUSED(notification);
- QMetaObject::invokeMethod(m_session, "processSessionStarted", Qt::AutoConnection);
-}
-
-- (void) processSessionStopped:(NSNotification *)notification
-{
- Q_UNUSED(notification);
- QMetaObject::invokeMethod(m_session, "processSessionStopped", Qt::AutoConnection);
-}
-
-@end
-
-AVFCameraSession::AVFCameraSession(AVFCameraService *service, QObject *parent)
- : QObject(parent)
- , m_service(service)
- , m_capturePreviewWindowOutput(nullptr)
- , m_state(QCamera::UnloadedState)
- , m_active(false)
- , m_videoInput(nil)
- , m_defaultCodec(0)
-{
- m_captureSession = [[AVCaptureSession alloc] init];
- m_observer = [[AVFCameraSessionObserver alloc] initWithCameraSession:this];
-
- //configuration is commited during transition to Active state
- [m_captureSession beginConfiguration];
-}
-
-AVFCameraSession::~AVFCameraSession()
-{
- if (m_capturePreviewWindowOutput) {
- m_capturePreviewWindowOutput->setLayer(nil);
- }
-
- if (m_videoInput) {
- [m_captureSession removeInput:m_videoInput];
- [m_videoInput release];
- }
-
- [m_observer release];
- [m_captureSession release];
-}
-
-int AVFCameraSession::defaultCameraIndex()
-{
- updateCameraDevices();
- return m_defaultCameraIndex;
-}
-
-const QList<AVFCameraInfo> &AVFCameraSession::availableCameraDevices()
-{
- updateCameraDevices();
- return m_cameraDevices;
-}
-
-AVFCameraInfo AVFCameraSession::cameraDeviceInfo(const QByteArray &device)
-{
- updateCameraDevices();
-
- for (const AVFCameraInfo &info : qAsConst(m_cameraDevices)) {
- if (info.deviceId == device)
- return info;
- }
-
- return AVFCameraInfo();
-}
-
-void AVFCameraSession::updateCameraDevices()
-{
-#ifdef Q_OS_IOS
- // Cameras can't change dynamically on iOS. Update only once.
- if (!m_cameraDevices.isEmpty())
- return;
-#else
- // On OS X, cameras can be added or removed. Update the list every time, but not more than
- // once every 500 ms
- static QElapsedTimer timer;
- if (timer.isValid() && timer.elapsed() < 500) // ms
- return;
-#endif
-
- m_defaultCameraIndex = -1;
- m_cameraDevices.clear();
-
- AVCaptureDevice *defaultDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
- NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
- for (AVCaptureDevice *device in videoDevices) {
- if (defaultDevice && [defaultDevice.uniqueID isEqualToString:device.uniqueID])
- m_defaultCameraIndex = m_cameraDevices.count();
-
- AVFCameraInfo info;
- info.deviceId = QByteArray([[device uniqueID] UTF8String]);
- info.description = QString::fromNSString([device localizedName]);
-
- // There is no API to get the camera sensor orientation, however, cameras are always
- // mounted in landscape on iDevices.
- // - Back-facing cameras have the top side of the sensor aligned with the right side of
- // the screen when held in portrait ==> 270 degrees clockwise angle
- // - Front-facing cameras have the top side of the sensor aligned with the left side of
- // the screen when held in portrait ==> 270 degrees clockwise angle
- // On OS X, the position will always be unspecified and the sensor orientation unknown.
- switch (device.position) {
- case AVCaptureDevicePositionBack:
- info.position = QCamera::BackFace;
- info.orientation = 270;
- break;
- case AVCaptureDevicePositionFront:
- info.position = QCamera::FrontFace;
- info.orientation = 270;
- break;
- default:
- info.position = QCamera::UnspecifiedPosition;
- info.orientation = 0;
- break;
- }
-
- m_cameraDevices.append(info);
- }
-
-#ifndef Q_OS_IOS
- timer.restart();
-#endif
-}
-
-void AVFCameraSession::setVideoOutput(AVFCameraRendererControl *output)
-{
- m_videoOutput = output;
- if (output)
- output->configureAVCaptureSession(this);
-}
-
-void AVFCameraSession::setCapturePreviewOutput(AVFCameraWindowControl *output)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << output;
-#endif
-
- if (m_capturePreviewWindowOutput == output)
- return;
-
- if (m_capturePreviewWindowOutput)
- m_capturePreviewWindowOutput->setLayer(nil);
-
- m_capturePreviewWindowOutput = output;
-
- if (m_capturePreviewWindowOutput) {
- AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:m_captureSession];
- m_capturePreviewWindowOutput->setLayer(previewLayer);
- if (AVFCameraViewfinderSettingsControl2 *vfControl = m_service->viewfinderSettingsControl2()) {
- m_capturePreviewWindowOutput->setNativeSize(vfControl->viewfinderSettings().resolution());
- }
- }
-}
-
-AVCaptureDevice *AVFCameraSession::videoCaptureDevice() const
-{
- if (m_videoInput)
- return m_videoInput.device;
-
- return nullptr;
-}
-
-QCamera::State AVFCameraSession::state() const
-{
- if (m_active)
- return QCamera::ActiveState;
-
- return m_state == QCamera::ActiveState ? QCamera::LoadedState : m_state;
-}
-
-void AVFCameraSession::setState(QCamera::State newState)
-{
- if (m_state == newState)
- return;
-
- qDebugCamera() << Q_FUNC_INFO << m_state << " -> " << newState;
-
- QCamera::State oldState = m_state;
- m_state = newState;
-
- //attach video input during Unloaded->Loaded transition
- if (oldState == QCamera::UnloadedState)
- attachVideoInputDevice();
-
- if (m_state == QCamera::ActiveState) {
- Q_EMIT readyToConfigureConnections();
- m_defaultCodec = 0;
- defaultCodec();
-
- bool activeFormatSet = applyImageEncoderSettings()
- | applyViewfinderSettings();
-
- [m_captureSession commitConfiguration];
-
- if (activeFormatSet) {
- // According to the doc, the capture device must be locked before
- // startRunning to prevent the format we set to be overriden by the
- // session preset.
- [videoCaptureDevice() lockForConfiguration:nil];
- }
-
- [m_captureSession startRunning];
-
- if (activeFormatSet)
- [videoCaptureDevice() unlockForConfiguration];
- }
-
- if (oldState == QCamera::ActiveState) {
- [m_captureSession stopRunning];
- [m_captureSession beginConfiguration];
- }
-
- Q_EMIT stateChanged(m_state);
-}
-
-void AVFCameraSession::processRuntimeError()
-{
- qWarning() << tr("Runtime camera error");
- Q_EMIT error(QCamera::CameraError, tr("Runtime camera error"));
-}
-
-void AVFCameraSession::processSessionStarted()
-{
- qDebugCamera() << Q_FUNC_INFO;
- if (!m_active) {
- m_active = true;
- Q_EMIT activeChanged(m_active);
- Q_EMIT stateChanged(state());
- }
-}
-
-void AVFCameraSession::processSessionStopped()
-{
- qDebugCamera() << Q_FUNC_INFO;
- if (m_active) {
- m_active = false;
- Q_EMIT activeChanged(m_active);
- Q_EMIT stateChanged(state());
- }
-}
-
-void AVFCameraSession::onCaptureModeChanged(QCamera::CaptureModes mode)
-{
- Q_UNUSED(mode);
-
- const QCamera::State s = state();
- if (s == QCamera::LoadedState || s == QCamera::ActiveState) {
- applyImageEncoderSettings();
- applyViewfinderSettings();
- }
-}
-
-void AVFCameraSession::attachVideoInputDevice()
-{
- //Attach video input device:
- if (m_service->videoDeviceControl()->isDirty()) {
- if (m_videoInput) {
- [m_captureSession removeInput:m_videoInput];
- [m_videoInput release];
- m_videoInput = nullptr;
- m_activeCameraInfo = AVFCameraInfo();
- }
-
- AVCaptureDevice *videoDevice = m_service->videoDeviceControl()->createCaptureDevice();
-
- NSError *error = nil;
- m_videoInput = [AVCaptureDeviceInput
- deviceInputWithDevice:videoDevice
- error:&error];
-
- if (!m_videoInput) {
- qWarning() << "Failed to create video device input";
- } else {
- if ([m_captureSession canAddInput:m_videoInput]) {
- m_activeCameraInfo = m_cameraDevices.at(m_service->videoDeviceControl()->selectedDevice());
- [m_videoInput retain];
- [m_captureSession addInput:m_videoInput];
- } else {
- qWarning() << "Failed to connect video device input";
- }
- }
- }
-}
-
-bool AVFCameraSession::applyImageEncoderSettings()
-{
- if (AVFImageEncoderControl *control = m_service->imageEncoderControl())
- return control->applySettings();
-
- return false;
-}
-
-bool AVFCameraSession::applyViewfinderSettings()
-{
- if (AVFCameraViewfinderSettingsControl2 *vfControl = m_service->viewfinderSettingsControl2()) {
- QCamera::CaptureModes currentMode = m_service->cameraControl()->captureMode();
- QCameraViewfinderSettings vfSettings(vfControl->requestedSettings());
- // Viewfinder and image capture solutions must be the same, if an image capture
- // resolution is set, it takes precedence over the viewfinder resolution.
- if (currentMode.testFlag(QCamera::CaptureStillImage)) {
- const QSize imageResolution(m_service->imageEncoderControl()->requestedSettings().resolution());
- if (!imageResolution.isNull() && imageResolution.isValid())
- vfSettings.setResolution(imageResolution);
- }
-
- vfControl->applySettings(vfSettings);
-
- if (m_capturePreviewWindowOutput)
- m_capturePreviewWindowOutput->setNativeSize(vfControl->viewfinderSettings().resolution());
-
- return !vfSettings.isNull();
- }
-
- return false;
-}
-
-void AVFCameraSession::addProbe(AVFMediaVideoProbeControl *probe)
-{
- m_videoProbesMutex.lock();
- if (probe)
- m_videoProbes << probe;
- m_videoProbesMutex.unlock();
-}
-
-void AVFCameraSession::removeProbe(AVFMediaVideoProbeControl *probe)
-{
- m_videoProbesMutex.lock();
- m_videoProbes.remove(probe);
- m_videoProbesMutex.unlock();
-}
-
-FourCharCode AVFCameraSession::defaultCodec()
-{
- if (!m_defaultCodec) {
- if (AVCaptureDevice *device = videoCaptureDevice()) {
- AVCaptureDeviceFormat *format = device.activeFormat;
- if (!format || !format.formatDescription)
- return m_defaultCodec;
- m_defaultCodec = CMVideoFormatDescriptionGetCodecType(format.formatDescription);
- }
- }
- return m_defaultCodec;
-}
-
-void AVFCameraSession::onCameraFrameFetched(const QVideoFrame &frame)
-{
- Q_EMIT newViewfinderFrame(frame);
-
- m_videoProbesMutex.lock();
- QSet<AVFMediaVideoProbeControl *>::const_iterator i = m_videoProbes.constBegin();
- while (i != m_videoProbes.constEnd()) {
- (*i)->newFrameProbed(frame);
- ++i;
- }
- m_videoProbesMutex.unlock();
-}
-
-#include "moc_avfcamerasession.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcamerautility.h b/src/plugins/avfoundation/camera/avfcamerautility.h
deleted file mode 100644
index 2e8bf39b4..000000000
--- a/src/plugins/avfoundation/camera/avfcamerautility.h
+++ /dev/null
@@ -1,179 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERAUTILITY_H
-#define AVFCAMERAUTILITY_H
-
-#include <QtCore/qglobal.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qlist.h>
-#include <QtCore/qpair.h>
-#include <QtCore/qsize.h>
-
-#include <AVFoundation/AVFoundation.h>
-
-// In case we have SDK below 10.7/7.0:
-@class AVCaptureDeviceFormat;
-
-QT_BEGIN_NAMESPACE
-
-class AVFConfigurationLock
-{
-public:
- explicit AVFConfigurationLock(AVCaptureDevice *captureDevice)
- : m_captureDevice(captureDevice),
- m_locked(false)
- {
- Q_ASSERT(m_captureDevice);
- NSError *error = nil;
- m_locked = [m_captureDevice lockForConfiguration:&error];
- }
-
- ~AVFConfigurationLock()
- {
- if (m_locked)
- [m_captureDevice unlockForConfiguration];
- }
-
- operator bool() const
- {
- return m_locked;
- }
-
-private:
- Q_DISABLE_COPY(AVFConfigurationLock)
-
- AVCaptureDevice *m_captureDevice;
- bool m_locked;
-};
-
-struct AVFObjectDeleter {
- static void cleanup(NSObject *obj)
- {
- if (obj)
- [obj release];
- }
-};
-
-template<class T>
-class AVFScopedPointer : public QScopedPointer<NSObject, AVFObjectDeleter>
-{
-public:
- AVFScopedPointer() {}
- explicit AVFScopedPointer(T *ptr) : QScopedPointer(ptr) {}
- operator T*() const
- {
- // Quite handy operator to enable Obj-C messages: [ptr someMethod];
- return data();
- }
-
- T *data() const
- {
- return static_cast<T *>(QScopedPointer::data());
- }
-
- T *take()
- {
- return static_cast<T *>(QScopedPointer::take());
- }
-};
-
-template<>
-class AVFScopedPointer<dispatch_queue_t>
-{
-public:
- AVFScopedPointer() : m_queue(nullptr) {}
- explicit AVFScopedPointer(dispatch_queue_t q) : m_queue(q) {}
-
- ~AVFScopedPointer()
- {
- if (m_queue)
- dispatch_release(m_queue);
- }
-
- operator dispatch_queue_t() const
- {
- // Quite handy operator to enable Obj-C messages: [ptr someMethod];
- return m_queue;
- }
-
- dispatch_queue_t data() const
- {
- return m_queue;
- }
-
- void reset(dispatch_queue_t q = nullptr)
- {
- if (m_queue)
- dispatch_release(m_queue);
- m_queue = q;
- }
-
-private:
- dispatch_queue_t m_queue;
-
- Q_DISABLE_COPY(AVFScopedPointer)
-};
-
-typedef QPair<qreal, qreal> AVFPSRange;
-AVFPSRange qt_connection_framerates(AVCaptureConnection *videoConnection);
-
-QList<AVCaptureDeviceFormat *> qt_unique_device_formats(AVCaptureDevice *captureDevice,
- FourCharCode preferredFormat);
-QSize qt_device_format_resolution(AVCaptureDeviceFormat *format);
-QSize qt_device_format_high_resolution(AVCaptureDeviceFormat *format);
-QSize qt_device_format_pixel_aspect_ratio(AVCaptureDeviceFormat *format);
-QList<AVFPSRange> qt_device_format_framerates(AVCaptureDeviceFormat *format);
-AVCaptureDeviceFormat *qt_find_best_resolution_match(AVCaptureDevice *captureDevice, const QSize &res,
- FourCharCode preferredFormat, bool stillImage = true);
-AVCaptureDeviceFormat *qt_find_best_framerate_match(AVCaptureDevice *captureDevice,
- FourCharCode preferredFormat,
- Float64 fps);
-AVFrameRateRange *qt_find_supported_framerate_range(AVCaptureDeviceFormat *format, Float64 fps);
-
-bool qt_formats_are_equal(AVCaptureDeviceFormat *f1, AVCaptureDeviceFormat *f2);
-bool qt_set_active_format(AVCaptureDevice *captureDevice, AVCaptureDeviceFormat *format, bool preserveFps);
-
-AVFPSRange qt_current_framerates(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection);
-void qt_set_framerate_limits(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection,
- qreal minFPS, qreal maxFPS);
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcamerautility.mm b/src/plugins/avfoundation/camera/avfcamerautility.mm
deleted file mode 100644
index 25ccc4b01..000000000
--- a/src/plugins/avfoundation/camera/avfcamerautility.mm
+++ /dev/null
@@ -1,575 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcamerautility.h"
-#include "avfcameradebug.h"
-
-#include <QtCore/qvector.h>
-#include <QtCore/qpair.h>
-#include <private/qmultimediautils_p.h>
-
-#include <functional>
-#include <algorithm>
-#include <limits>
-#include <tuple>
-
-QT_BEGIN_NAMESPACE
-
-AVFPSRange qt_connection_framerates(AVCaptureConnection *videoConnection)
-{
- Q_ASSERT(videoConnection);
-
- AVFPSRange newRange;
- // "The value in the videoMinFrameDuration is equivalent to the reciprocal
- // of the maximum framerate, the value in the videoMaxFrameDuration is equivalent
- // to the reciprocal of the minimum framerate."
- if (videoConnection.supportsVideoMinFrameDuration) {
- const CMTime cmMin = videoConnection.videoMinFrameDuration;
- if (CMTimeCompare(cmMin, kCMTimeInvalid)) { // Has some non-default value:
- if (const Float64 minSeconds = CMTimeGetSeconds(cmMin))
- newRange.second = 1. / minSeconds;
- }
- }
-
- if (videoConnection.supportsVideoMaxFrameDuration) {
- const CMTime cmMax = videoConnection.videoMaxFrameDuration;
- if (CMTimeCompare(cmMax, kCMTimeInvalid)) {
- if (const Float64 maxSeconds = CMTimeGetSeconds(cmMax))
- newRange.first = 1. / maxSeconds;
- }
- }
-
- return newRange;
-}
-
-namespace {
-
-inline bool qt_area_sane(const QSize &size)
-{
- return !size.isNull() && size.isValid()
- && std::numeric_limits<int>::max() / size.width() >= size.height();
-}
-
-template <template <typename...> class Comp> // std::less or std::greater (or std::equal_to)
-struct ByResolution
-{
- bool operator() (AVCaptureDeviceFormat *f1, AVCaptureDeviceFormat *f2)const
- {
- Q_ASSERT(f1 && f2);
- const QSize r1(qt_device_format_resolution(f1));
- const QSize r2(qt_device_format_resolution(f2));
- // use std::tuple for lexicograpical sorting:
- const Comp<std::tuple<int, int>> op = {};
- return op(std::make_tuple(r1.width(), r1.height()),
- std::make_tuple(r2.width(), r2.height()));
- }
-};
-
-struct FormatHasNoFPSRange : std::unary_function<AVCaptureDeviceFormat *, bool>
-{
- bool operator() (AVCaptureDeviceFormat *format)
- {
- Q_ASSERT(format);
- return !format.videoSupportedFrameRateRanges || !format.videoSupportedFrameRateRanges.count;
- }
-};
-
-Float64 qt_find_min_framerate_distance(AVCaptureDeviceFormat *format, Float64 fps)
-{
- Q_ASSERT(format && format.videoSupportedFrameRateRanges
- && format.videoSupportedFrameRateRanges.count);
-
- AVFrameRateRange *range = [format.videoSupportedFrameRateRanges objectAtIndex:0];
- Float64 distance = qAbs(range.maxFrameRate - fps);
- for (NSUInteger i = 1, e = format.videoSupportedFrameRateRanges.count; i < e; ++i) {
- range = [format.videoSupportedFrameRateRanges objectAtIndex:i];
- distance = qMin(distance, qAbs(range.maxFrameRate - fps));
- }
-
- return distance;
-}
-
-} // Unnamed namespace.
-
-QVector<AVCaptureDeviceFormat *> qt_unique_device_formats(AVCaptureDevice *captureDevice, FourCharCode filter)
-{
- // 'filter' is the format we prefer if we have duplicates.
- Q_ASSERT(captureDevice);
-
- QVector<AVCaptureDeviceFormat *> formats;
-
- if (!captureDevice.formats || !captureDevice.formats.count)
- return formats;
-
- formats.reserve(captureDevice.formats.count);
- for (AVCaptureDeviceFormat *format in captureDevice.formats) {
- const QSize resolution(qt_device_format_resolution(format));
- if (resolution.isNull() || !resolution.isValid())
- continue;
- formats << format;
- }
-
- if (!formats.size())
- return formats;
-
- std::sort(formats.begin(), formats.end(), ByResolution<std::less>());
-
- QSize size(qt_device_format_resolution(formats[0]));
- FourCharCode codec = CMVideoFormatDescriptionGetCodecType(formats[0].formatDescription);
- int last = 0;
- for (int i = 1; i < formats.size(); ++i) {
- const QSize nextSize(qt_device_format_resolution(formats[i]));
- if (nextSize == size) {
- if (codec == filter)
- continue;
- formats[last] = formats[i];
- } else {
- ++last;
- formats[last] = formats[i];
- size = nextSize;
- }
- codec = CMVideoFormatDescriptionGetCodecType(formats[i].formatDescription);
- }
- formats.resize(last + 1);
-
- return formats;
-}
-
-QSize qt_device_format_resolution(AVCaptureDeviceFormat *format)
-{
- if (!format || !format.formatDescription)
- return QSize();
-
- const CMVideoDimensions res = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
- return QSize(res.width, res.height);
-}
-
-QSize qt_device_format_high_resolution(AVCaptureDeviceFormat *format)
-{
- Q_ASSERT(format);
- QSize res;
-#if defined(Q_OS_IOS)
- const CMVideoDimensions hrDim(format.highResolutionStillImageDimensions);
- res.setWidth(hrDim.width);
- res.setHeight(hrDim.height);
-#endif
- return res;
-}
-
-QVector<AVFPSRange> qt_device_format_framerates(AVCaptureDeviceFormat *format)
-{
- Q_ASSERT(format);
-
- QVector<AVFPSRange> qtRanges;
-
- if (!format.videoSupportedFrameRateRanges || !format.videoSupportedFrameRateRanges.count)
- return qtRanges;
-
- qtRanges.reserve(format.videoSupportedFrameRateRanges.count);
- for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges)
- qtRanges << AVFPSRange(range.minFrameRate, range.maxFrameRate);
-
- return qtRanges;
-}
-
-QSize qt_device_format_pixel_aspect_ratio(AVCaptureDeviceFormat *format)
-{
- Q_ASSERT(format);
-
- if (!format.formatDescription) {
- qDebugCamera() << Q_FUNC_INFO << "no format description found";
- return QSize();
- }
-
- const CMVideoDimensions res = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
- const CGSize resPAR = CMVideoFormatDescriptionGetPresentationDimensions(format.formatDescription, true, false);
-
- if (qAbs(resPAR.width - res.width) < 1.) {
- // "Pixel aspect ratio is used to adjust the width, leaving the height alone."
- return QSize(1, 1);
- }
-
- if (!res.width || !resPAR.width)
- return QSize();
-
- int n, d;
- qt_real_to_fraction(resPAR.width > res.width
- ? res.width / qreal(resPAR.width)
- : resPAR.width / qreal(res.width),
- &n, &d);
-
- return QSize(n, d);
-}
-
-AVCaptureDeviceFormat *qt_find_best_resolution_match(AVCaptureDevice *captureDevice,
- const QSize &request,
- FourCharCode filter,
- bool stillImage)
-{
- Q_ASSERT(captureDevice);
- Q_ASSERT(!request.isNull() && request.isValid());
-
- if (!captureDevice.formats || !captureDevice.formats.count)
- return nullptr;
-
- QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(captureDevice, filter));
-
- for (int i = 0; i < formats.size(); ++i) {
- AVCaptureDeviceFormat *format = formats[i];
- if (qt_device_format_resolution(format) == request)
- return format;
- // iOS only (still images).
- if (stillImage && qt_device_format_high_resolution(format) == request)
- return format;
- }
-
- if (!qt_area_sane(request))
- return nullptr;
-
- typedef QPair<QSize, AVCaptureDeviceFormat *> FormatPair;
-
- QVector<FormatPair> pairs; // default|HR sizes
- pairs.reserve(formats.size());
-
- for (int i = 0; i < formats.size(); ++i) {
- AVCaptureDeviceFormat *format = formats[i];
- const QSize res(qt_device_format_resolution(format));
- if (!res.isNull() && res.isValid() && qt_area_sane(res))
- pairs << FormatPair(res, format);
- const QSize highRes(qt_device_format_high_resolution(format));
- if (stillImage && !highRes.isNull() && highRes.isValid() && qt_area_sane(highRes))
- pairs << FormatPair(highRes, format);
- }
-
- if (!pairs.size())
- return nullptr;
-
- AVCaptureDeviceFormat *best = pairs[0].second;
- QSize next(pairs[0].first);
- int wDiff = qAbs(request.width() - next.width());
- int hDiff = qAbs(request.height() - next.height());
- const int area = request.width() * request.height();
- int areaDiff = qAbs(area - next.width() * next.height());
- for (int i = 1; i < pairs.size(); ++i) {
- next = pairs[i].first;
- const int newWDiff = qAbs(next.width() - request.width());
- const int newHDiff = qAbs(next.height() - request.height());
- const int newAreaDiff = qAbs(area - next.width() * next.height());
-
- if ((newWDiff < wDiff && newHDiff < hDiff)
- || ((newWDiff <= wDiff || newHDiff <= hDiff) && newAreaDiff <= areaDiff)) {
- wDiff = newWDiff;
- hDiff = newHDiff;
- best = pairs[i].second;
- areaDiff = newAreaDiff;
- }
- }
-
- return best;
-}
-
-AVCaptureDeviceFormat *qt_find_best_framerate_match(AVCaptureDevice *captureDevice,
- FourCharCode filter,
- Float64 fps)
-{
- Q_ASSERT(captureDevice);
- Q_ASSERT(fps > 0.);
-
- const qreal epsilon = 0.1;
-
- QVector<AVCaptureDeviceFormat *>sorted(qt_unique_device_formats(captureDevice, filter));
- // Sort formats by their resolution in decreasing order:
- std::sort(sorted.begin(), sorted.end(), ByResolution<std::greater>());
- // We can use only formats with framerate ranges:
- sorted.erase(std::remove_if(sorted.begin(), sorted.end(), FormatHasNoFPSRange()), sorted.end());
-
- if (!sorted.size())
- return nil;
-
- for (int i = 0; i < sorted.size(); ++i) {
- AVCaptureDeviceFormat *format = sorted[i];
- for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
- if (range.maxFrameRate - range.minFrameRate < epsilon) {
- // On OS X ranges are points (built-in camera).
- if (qAbs(fps - range.maxFrameRate) < epsilon)
- return format;
- }
-
- if (fps >= range.minFrameRate && fps <= range.maxFrameRate)
- return format;
- }
- }
-
- Float64 distance = qt_find_min_framerate_distance(sorted[0], fps);
- AVCaptureDeviceFormat *match = sorted[0];
- for (int i = 1; i < sorted.size(); ++i) {
- const Float64 newDistance = qt_find_min_framerate_distance(sorted[i], fps);
- if (newDistance < distance) {
- distance = newDistance;
- match = sorted[i];
- }
- }
-
- return match;
-}
-
-AVFrameRateRange *qt_find_supported_framerate_range(AVCaptureDeviceFormat *format, Float64 fps)
-{
- Q_ASSERT(format && format.videoSupportedFrameRateRanges
- && format.videoSupportedFrameRateRanges.count);
-
- const qreal epsilon = 0.1;
-
- for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
- if (range.maxFrameRate - range.minFrameRate < epsilon) {
- // On OS X ranges are points (built-in camera).
- if (qAbs(fps - range.maxFrameRate) < epsilon)
- return range;
- }
-
- if (fps >= range.minFrameRate && fps <= range.maxFrameRate)
- return range;
- }
-
- AVFrameRateRange *match = [format.videoSupportedFrameRateRanges objectAtIndex:0];
- Float64 distance = qAbs(match.maxFrameRate - fps);
- for (NSUInteger i = 1, e = format.videoSupportedFrameRateRanges.count; i < e; ++i) {
- AVFrameRateRange *range = [format.videoSupportedFrameRateRanges objectAtIndex:i];
- const Float64 newDistance = qAbs(range.maxFrameRate - fps);
- if (newDistance < distance) {
- distance = newDistance;
- match = range;
- }
- }
-
- return match;
-}
-
-bool qt_formats_are_equal(AVCaptureDeviceFormat *f1, AVCaptureDeviceFormat *f2)
-{
- if (f1 == f2)
- return true;
-
- if (![f1.mediaType isEqualToString:f2.mediaType])
- return false;
-
- return CMFormatDescriptionEqual(f1.formatDescription, f2.formatDescription);
-}
-
-bool qt_set_active_format(AVCaptureDevice *captureDevice, AVCaptureDeviceFormat *format, bool preserveFps)
-{
- static bool firstSet = true;
-
- if (!captureDevice || !format)
- return false;
-
- if (qt_formats_are_equal(captureDevice.activeFormat, format)) {
- if (firstSet) {
- // The capture device format is persistent. The first time we set a format, report that
- // it changed even if the formats are the same.
- // This prevents the session from resetting the format to the default value.
- firstSet = false;
- return true;
- }
- return false;
- }
-
- firstSet = false;
-
- const AVFConfigurationLock lock(captureDevice);
- if (!lock) {
- qWarning("Failed to set active format (lock failed)");
- return false;
- }
-
- // Changing the activeFormat resets the frame rate.
- AVFPSRange fps;
- if (preserveFps)
- fps = qt_current_framerates(captureDevice, nil);
-
- captureDevice.activeFormat = format;
-
- if (preserveFps)
- qt_set_framerate_limits(captureDevice, nil, fps.first, fps.second);
-
- return true;
-}
-
-void qt_set_framerate_limits(AVCaptureConnection *videoConnection, qreal minFPS, qreal maxFPS)
-{
- Q_ASSERT(videoConnection);
-
- if (minFPS < 0. || maxFPS < 0. || (maxFPS && maxFPS < minFPS)) {
- qDebugCamera() << Q_FUNC_INFO << "invalid framerates (min, max):"
- << minFPS << maxFPS;
- return;
- }
-
- CMTime minDuration = kCMTimeInvalid;
- if (maxFPS > 0.) {
- if (!videoConnection.supportsVideoMinFrameDuration)
- qDebugCamera() << Q_FUNC_INFO << "maximum framerate is not supported";
- else
- minDuration = CMTimeMake(1, maxFPS);
- }
- if (videoConnection.supportsVideoMinFrameDuration)
- videoConnection.videoMinFrameDuration = minDuration;
-
- CMTime maxDuration = kCMTimeInvalid;
- if (minFPS > 0.) {
- if (!videoConnection.supportsVideoMaxFrameDuration)
- qDebugCamera() << Q_FUNC_INFO << "minimum framerate is not supported";
- else
- maxDuration = CMTimeMake(1, minFPS);
- }
- if (videoConnection.supportsVideoMaxFrameDuration)
- videoConnection.videoMaxFrameDuration = maxDuration;
-}
-
-CMTime qt_adjusted_frame_duration(AVFrameRateRange *range, qreal fps)
-{
- Q_ASSERT(range);
- Q_ASSERT(fps > 0.);
-
- if (range.maxFrameRate - range.minFrameRate < 0.1) {
- // Can happen on OS X.
- return range.minFrameDuration;
- }
-
- if (fps <= range.minFrameRate)
- return range.maxFrameDuration;
- if (fps >= range.maxFrameRate)
- return range.minFrameDuration;
-
- int n, d;
- qt_real_to_fraction(1. / fps, &n, &d);
- return CMTimeMake(n, d);
-}
-
-void qt_set_framerate_limits(AVCaptureDevice *captureDevice, qreal minFPS, qreal maxFPS)
-{
- Q_ASSERT(captureDevice);
- if (!captureDevice.activeFormat) {
- qDebugCamera() << Q_FUNC_INFO << "no active capture device format";
- return;
- }
-
- if (minFPS < 0. || maxFPS < 0. || (maxFPS && maxFPS < minFPS)) {
- qDebugCamera() << Q_FUNC_INFO << "invalid framerates (min, max):"
- << minFPS << maxFPS;
- return;
- }
-
- CMTime minFrameDuration = kCMTimeInvalid;
- CMTime maxFrameDuration = kCMTimeInvalid;
- if (maxFPS || minFPS) {
- AVFrameRateRange *range = qt_find_supported_framerate_range(captureDevice.activeFormat,
- maxFPS ? maxFPS : minFPS);
- if (!range) {
- qDebugCamera() << Q_FUNC_INFO << "no framerate range found, (min, max):"
- << minFPS << maxFPS;
- return;
- }
-
- if (maxFPS)
- minFrameDuration = qt_adjusted_frame_duration(range, maxFPS);
- if (minFPS)
- maxFrameDuration = qt_adjusted_frame_duration(range, minFPS);
- }
-
- const AVFConfigurationLock lock(captureDevice);
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- return;
- }
-
- // While Apple's docs say kCMTimeInvalid will end in default
- // settings for this format, kCMTimeInvalid on OS X ends with a runtime
- // exception:
- // "The activeVideoMinFrameDuration passed is not supported by the device."
- // Instead, use the first item in the supported frame rates.
-#ifdef Q_OS_IOS
- [captureDevice setActiveVideoMinFrameDuration:minFrameDuration];
- [captureDevice setActiveVideoMaxFrameDuration:maxFrameDuration];
-#elif defined(Q_OS_MACOS)
- if (CMTimeCompare(minFrameDuration, kCMTimeInvalid) == 0
- && CMTimeCompare(maxFrameDuration, kCMTimeInvalid) == 0) {
- AVFrameRateRange *range = captureDevice.activeFormat.videoSupportedFrameRateRanges.firstObject;
- minFrameDuration = range.minFrameDuration;
- maxFrameDuration = range.maxFrameDuration;
- }
-
- if (CMTimeCompare(minFrameDuration, kCMTimeInvalid))
- [captureDevice setActiveVideoMinFrameDuration:minFrameDuration];
-
- if (CMTimeCompare(maxFrameDuration, kCMTimeInvalid))
- [captureDevice setActiveVideoMaxFrameDuration:maxFrameDuration];
-#endif // Q_OS_MACOS
-}
-
-void qt_set_framerate_limits(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection,
- qreal minFPS, qreal maxFPS)
-{
- Q_UNUSED(videoConnection);
- Q_ASSERT(captureDevice);
- qt_set_framerate_limits(captureDevice, minFPS, maxFPS);
-}
-
-AVFPSRange qt_current_framerates(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection)
-{
- Q_UNUSED(videoConnection);
- Q_ASSERT(captureDevice);
-
- AVFPSRange fps;
- const CMTime minDuration = captureDevice.activeVideoMinFrameDuration;
- if (CMTimeCompare(minDuration, kCMTimeInvalid)) {
- if (const Float64 minSeconds = CMTimeGetSeconds(minDuration))
- fps.second = 1. / minSeconds; // Max FPS = 1 / MinDuration.
- }
-
- const CMTime maxDuration = captureDevice.activeVideoMaxFrameDuration;
- if (CMTimeCompare(maxDuration, kCMTimeInvalid)) {
- if (const Float64 maxSeconds = CMTimeGetSeconds(maxDuration))
- fps.first = 1. / maxSeconds; // Min FPS = 1 / MaxDuration.
- }
-
- return fps;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.h b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.h
deleted file mode 100644
index 7cd59117f..000000000
--- a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERAVIEWFINDERSETTINGSCONTROL_H
-#define AVFCAMERAVIEWFINDERSETTINGSCONTROL_H
-
-#include <QtMultimedia/qcameraviewfindersettingscontrol.h>
-#include <QtMultimedia/qcameraviewfindersettings.h>
-#include <QtMultimedia/qvideoframe.h>
-
-#include <QtCore/qpointer.h>
-#include <QtCore/qglobal.h>
-#include <QtCore/qsize.h>
-
-@class AVCaptureDevice;
-@class AVCaptureVideoDataOutput;
-@class AVCaptureConnection;
-@class AVCaptureDeviceFormat;
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraSession;
-class AVFCameraService;
-
-class AVFCameraViewfinderSettingsControl2 : public QCameraViewfinderSettingsControl2
-{
- Q_OBJECT
-
- friend class AVFCameraSession;
- friend class AVFCameraViewfinderSettingsControl;
-public:
- AVFCameraViewfinderSettingsControl2(AVFCameraService *service);
-
- QList<QCameraViewfinderSettings> supportedViewfinderSettings() const override;
- QCameraViewfinderSettings viewfinderSettings() const override;
- void setViewfinderSettings(const QCameraViewfinderSettings &settings) override;
-
- // "Converters":
- static QVideoFrame::PixelFormat QtPixelFormatFromCVFormat(unsigned avPixelFormat);
- static bool CVPixelFormatFromQtFormat(QVideoFrame::PixelFormat qtFormat, unsigned &conv);
-
-private:
- void setResolution(const QSize &resolution);
- void setFramerate(qreal minFPS, qreal maxFPS, bool useActive);
- void setPixelFormat(QVideoFrame::PixelFormat newFormat);
- AVCaptureDeviceFormat *findBestFormatMatch(const QCameraViewfinderSettings &settings) const;
- QList<QVideoFrame::PixelFormat> viewfinderPixelFormats() const;
- bool convertPixelFormatIfSupported(QVideoFrame::PixelFormat format, unsigned &avfFormat) const;
- bool applySettings(const QCameraViewfinderSettings &settings);
- QCameraViewfinderSettings requestedSettings() const;
-
- AVCaptureConnection *videoConnection() const;
-
- AVFCameraService *m_service;
- QCameraViewfinderSettings m_settings;
-};
-
-class AVFCameraViewfinderSettingsControl : public QCameraViewfinderSettingsControl
-{
- Q_OBJECT
-public:
- AVFCameraViewfinderSettingsControl(AVFCameraService *service);
-
- bool isViewfinderParameterSupported(ViewfinderParameter parameter) const override;
- QVariant viewfinderParameter(ViewfinderParameter parameter) const override;
- void setViewfinderParameter(ViewfinderParameter parameter, const QVariant &value) override;
-
-private:
- void setResolution(const QVariant &resolution);
- void setAspectRatio(const QVariant &aspectRatio);
- void setFrameRate(const QVariant &fps, bool max);
- void setPixelFormat(const QVariant &pf);
- bool initSettingsControl() const;
-
- AVFCameraService *m_service;
- mutable QPointer<AVFCameraViewfinderSettingsControl2> m_settingsControl;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm
deleted file mode 100644
index dd0393f96..000000000
--- a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm
+++ /dev/null
@@ -1,599 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcameraviewfindersettingscontrol.h"
-#include "avfcamerarenderercontrol.h"
-#include "avfcamerautility.h"
-#include "avfcamerasession.h"
-#include "avfcameraservice.h"
-#include "avfcameradebug.h"
-
-#include <QtMultimedia/qabstractvideosurface.h>
-
-#include <QtCore/qvariant.h>
-#include <QtCore/qvector.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qlist.h>
-#include <private/qmultimediautils_p.h>
-
-#include <algorithm>
-
-#include <AVFoundation/AVFoundation.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace {
-
-bool qt_framerates_sane(const QCameraViewfinderSettings &settings)
-{
- const qreal minFPS = settings.minimumFrameRate();
- const qreal maxFPS = settings.maximumFrameRate();
-
- if (minFPS < 0. || maxFPS < 0.)
- return false;
-
- return !maxFPS || maxFPS >= minFPS;
-}
-
-} // Unnamed namespace.
-
-AVFCameraViewfinderSettingsControl2::AVFCameraViewfinderSettingsControl2(AVFCameraService *service)
- : m_service(service)
-{
- Q_ASSERT(service);
-}
-
-QList<QCameraViewfinderSettings> AVFCameraViewfinderSettingsControl2::supportedViewfinderSettings() const
-{
- QList<QCameraViewfinderSettings> supportedSettings;
-
- AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
- if (!captureDevice) {
- qDebugCamera() << Q_FUNC_INFO << "no capture device found";
- return supportedSettings;
- }
-
- QVector<AVFPSRange> framerates;
-
- QVector<QVideoFrame::PixelFormat> pixelFormats(viewfinderPixelFormats());
-
- if (!pixelFormats.size())
- pixelFormats << QVideoFrame::Format_Invalid; // The default value.
-
- if (!captureDevice.formats || !captureDevice.formats.count) {
- qDebugCamera() << Q_FUNC_INFO << "no capture device formats found";
- return supportedSettings;
- }
-
- const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(captureDevice,
- m_service->session()->defaultCodec()));
- for (int i = 0; i < formats.size(); ++i) {
- AVCaptureDeviceFormat *format = formats[i];
-
- const QSize res(qt_device_format_resolution(format));
- if (res.isNull() || !res.isValid())
- continue;
- const QSize par(qt_device_format_pixel_aspect_ratio(format));
- if (par.isNull() || !par.isValid())
- continue;
-
- framerates = qt_device_format_framerates(format);
- if (!framerates.size())
- framerates << AVFPSRange(); // The default value.
-
- for (int i = 0; i < pixelFormats.size(); ++i) {
- for (int j = 0; j < framerates.size(); ++j) {
- QCameraViewfinderSettings newSet;
- newSet.setResolution(res);
- newSet.setPixelAspectRatio(par);
- newSet.setPixelFormat(pixelFormats[i]);
- newSet.setMinimumFrameRate(framerates[j].first);
- newSet.setMaximumFrameRate(framerates[j].second);
- supportedSettings << newSet;
- }
- }
- }
-
- return supportedSettings;
-}
-
-QCameraViewfinderSettings AVFCameraViewfinderSettingsControl2::viewfinderSettings() const
-{
- QCameraViewfinderSettings settings = m_settings;
-
- AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
- if (!captureDevice) {
- qDebugCamera() << Q_FUNC_INFO << "no capture device found";
- return settings;
- }
-
- if (m_service->session()->state() != QCamera::LoadedState &&
- m_service->session()->state() != QCamera::ActiveState) {
- return settings;
- }
-
- if (!captureDevice.activeFormat) {
- qDebugCamera() << Q_FUNC_INFO << "no active capture device format";
- return settings;
- }
-
- const QSize res(qt_device_format_resolution(captureDevice.activeFormat));
- const QSize par(qt_device_format_pixel_aspect_ratio(captureDevice.activeFormat));
- if (res.isNull() || !res.isValid() || par.isNull() || !par.isValid()) {
- qDebugCamera() << Q_FUNC_INFO << "failed to obtain resolution/pixel aspect ratio";
- return settings;
- }
-
- settings.setResolution(res);
- settings.setPixelAspectRatio(par);
-
- const AVFPSRange fps = qt_current_framerates(captureDevice, videoConnection());
- settings.setMinimumFrameRate(fps.first);
- settings.setMaximumFrameRate(fps.second);
-
- AVCaptureVideoDataOutput *videoOutput = m_service->videoOutput() ? m_service->videoOutput()->videoDataOutput() : nullptr;
- if (videoOutput) {
- NSObject *obj = [videoOutput.videoSettings objectForKey:(id)kCVPixelBufferPixelFormatTypeKey];
- if (obj && [obj isKindOfClass:[NSNumber class]]) {
- NSNumber *nsNum = static_cast<NSNumber *>(obj);
- settings.setPixelFormat(QtPixelFormatFromCVFormat([nsNum unsignedIntValue]));
- }
- }
-
- return settings;
-}
-
-void AVFCameraViewfinderSettingsControl2::setViewfinderSettings(const QCameraViewfinderSettings &settings)
-{
- if (m_settings == settings)
- return;
-
- m_settings = settings;
-#if defined(Q_OS_IOS)
- bool active = m_service->session()->state() == QCamera::ActiveState;
- if (active)
- [m_service->session()->captureSession() beginConfiguration];
- applySettings(m_settings);
- if (active)
- [m_service->session()->captureSession() commitConfiguration];
-#else
- applySettings(m_settings);
-#endif
-}
-
-QVideoFrame::PixelFormat AVFCameraViewfinderSettingsControl2::QtPixelFormatFromCVFormat(unsigned avPixelFormat)
-{
- // BGRA <-> ARGB "swap" is intentional:
- // to work correctly with GL_RGBA, color swap shaders
- // (in QSG node renderer etc.).
- switch (avPixelFormat) {
- case kCVPixelFormatType_32ARGB:
- return QVideoFrame::Format_BGRA32;
- case kCVPixelFormatType_32BGRA:
- return QVideoFrame::Format_ARGB32;
- case kCVPixelFormatType_24RGB:
- return QVideoFrame::Format_RGB24;
- case kCVPixelFormatType_24BGR:
- return QVideoFrame::Format_BGR24;
- case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
- case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange:
- return QVideoFrame::Format_NV12;
- case kCVPixelFormatType_422YpCbCr8:
- return QVideoFrame::Format_UYVY;
- case kCVPixelFormatType_422YpCbCr8_yuvs:
- return QVideoFrame::Format_YUYV;
- default:
- return QVideoFrame::Format_Invalid;
- }
-}
-
-bool AVFCameraViewfinderSettingsControl2::CVPixelFormatFromQtFormat(QVideoFrame::PixelFormat qtFormat, unsigned &conv)
-{
- // BGRA <-> ARGB "swap" is intentional:
- // to work correctly with GL_RGBA, color swap shaders
- // (in QSG node renderer etc.).
- switch (qtFormat) {
- case QVideoFrame::Format_ARGB32:
- conv = kCVPixelFormatType_32BGRA;
- break;
- case QVideoFrame::Format_BGRA32:
- conv = kCVPixelFormatType_32ARGB;
- break;
- case QVideoFrame::Format_NV12:
- conv = kCVPixelFormatType_420YpCbCr8BiPlanarFullRange;
- break;
- case QVideoFrame::Format_UYVY:
- conv = kCVPixelFormatType_422YpCbCr8;
- break;
- case QVideoFrame::Format_YUYV:
- conv = kCVPixelFormatType_422YpCbCr8_yuvs;
- break;
- // These two formats below are not supported
- // by QSGVideoNodeFactory_RGB, so for now I have to
- // disable them.
- /*
- case QVideoFrame::Format_RGB24:
- conv = kCVPixelFormatType_24RGB;
- break;
- case QVideoFrame::Format_BGR24:
- conv = kCVPixelFormatType_24BGR;
- break;
- */
- default:
- return false;
- }
-
- return true;
-}
-
-AVCaptureDeviceFormat *AVFCameraViewfinderSettingsControl2::findBestFormatMatch(const QCameraViewfinderSettings &settings) const
-{
- AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
- if (!captureDevice || settings.isNull())
- return nil;
-
- const QSize &resolution = settings.resolution();
- if (!resolution.isNull() && resolution.isValid()) {
- // Either the exact match (including high resolution for images on iOS)
- // or a format with a resolution close to the requested one.
- return qt_find_best_resolution_match(captureDevice, resolution,
- m_service->session()->defaultCodec(), false);
- }
-
- // No resolution requested, what about framerates?
- if (!qt_framerates_sane(settings)) {
- qDebugCamera() << Q_FUNC_INFO << "invalid framerate requested (min/max):"
- << settings.minimumFrameRate() << settings.maximumFrameRate();
- return nil;
- }
-
- const qreal minFPS(settings.minimumFrameRate());
- const qreal maxFPS(settings.maximumFrameRate());
- if (minFPS || maxFPS)
- return qt_find_best_framerate_match(captureDevice,
- m_service->session()->defaultCodec(),
- maxFPS ? maxFPS : minFPS);
- // Ignore PAR for the moment (PAR without resolution can
- // pick a format with really bad resolution).
- // No need to test pixel format, just return settings.
-
- return nil;
-}
-
-QVector<QVideoFrame::PixelFormat> AVFCameraViewfinderSettingsControl2::viewfinderPixelFormats() const
-{
- QVector<QVideoFrame::PixelFormat> qtFormats;
-
- AVCaptureVideoDataOutput *videoOutput = m_service->videoOutput() ? m_service->videoOutput()->videoDataOutput() : nullptr;
- if (!videoOutput) {
- qDebugCamera() << Q_FUNC_INFO << "no video output found";
- return qtFormats;
- }
-
- NSArray *pixelFormats = [videoOutput availableVideoCVPixelFormatTypes];
-
- for (NSObject *obj in pixelFormats) {
- if (![obj isKindOfClass:[NSNumber class]])
- continue;
-
- NSNumber *formatAsNSNumber = static_cast<NSNumber *>(obj);
- // It's actually FourCharCode (== UInt32):
- const QVideoFrame::PixelFormat qtFormat(QtPixelFormatFromCVFormat([formatAsNSNumber unsignedIntValue]));
- if (qtFormat != QVideoFrame::Format_Invalid
- && !qtFormats.contains(qtFormat)) { // Can happen, for example, with 8BiPlanar existing in video/full range.
- qtFormats << qtFormat;
- }
- }
-
- return qtFormats;
-}
-
-bool AVFCameraViewfinderSettingsControl2::convertPixelFormatIfSupported(QVideoFrame::PixelFormat qtFormat,
- unsigned &avfFormat)const
-{
- AVCaptureVideoDataOutput *videoOutput = m_service->videoOutput() ? m_service->videoOutput()->videoDataOutput() : nullptr;
- if (!videoOutput)
- return false;
-
- unsigned conv = 0;
- if (!CVPixelFormatFromQtFormat(qtFormat, conv))
- return false;
-
- NSArray *formats = [videoOutput availableVideoCVPixelFormatTypes];
- if (!formats || !formats.count)
- return false;
-
- if (m_service->videoOutput()->surface()) {
- const QAbstractVideoSurface *surface = m_service->videoOutput()->surface();
- QAbstractVideoBuffer::HandleType h = m_service->videoOutput()->supportsTextures()
- ? QAbstractVideoBuffer::GLTextureHandle
- : QAbstractVideoBuffer::NoHandle;
- if (!surface->supportedPixelFormats(h).contains(qtFormat))
- return false;
- }
-
- bool found = false;
- for (NSObject *obj in formats) {
- if (![obj isKindOfClass:[NSNumber class]])
- continue;
-
- NSNumber *nsNum = static_cast<NSNumber *>(obj);
- if ([nsNum unsignedIntValue] == conv) {
- avfFormat = conv;
- found = true;
- }
- }
-
- return found;
-}
-
-bool AVFCameraViewfinderSettingsControl2::applySettings(const QCameraViewfinderSettings &settings)
-{
- if (m_service->session()->state() != QCamera::LoadedState &&
- m_service->session()->state() != QCamera::ActiveState) {
- return false;
- }
-
- AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
- if (!captureDevice)
- return false;
-
- bool activeFormatChanged = false;
-
- AVCaptureDeviceFormat *match = findBestFormatMatch(settings);
- if (match) {
- activeFormatChanged = qt_set_active_format(captureDevice, match, false);
- } else {
- qDebugCamera() << Q_FUNC_INFO << "matching device format not found";
- // We still can update the pixel format at least.
- }
-
- AVCaptureVideoDataOutput *videoOutput = m_service->videoOutput() ? m_service->videoOutput()->videoDataOutput() : nullptr;
- if (videoOutput) {
- unsigned avfPixelFormat = 0;
- if (!convertPixelFormatIfSupported(settings.pixelFormat(), avfPixelFormat)) {
- // If the the pixel format is not specified or invalid, pick the preferred video surface
- // format, or if no surface is set, the preferred capture device format
-
- const QVector<QVideoFrame::PixelFormat> deviceFormats = viewfinderPixelFormats();
- QAbstractVideoSurface *surface = m_service->videoOutput()->surface();
- QVideoFrame::PixelFormat pickedFormat = deviceFormats.first();
- if (surface) {
- pickedFormat = QVideoFrame::Format_Invalid;
- QAbstractVideoBuffer::HandleType h = m_service->videoOutput()->supportsTextures()
- ? QAbstractVideoBuffer::GLTextureHandle
- : QAbstractVideoBuffer::NoHandle;
- QList<QVideoFrame::PixelFormat> surfaceFormats = surface->supportedPixelFormats(h);
- for (int i = 0; i < surfaceFormats.count(); ++i) {
- const QVideoFrame::PixelFormat surfaceFormat = surfaceFormats.at(i);
- if (deviceFormats.contains(surfaceFormat)) {
- pickedFormat = surfaceFormat;
- break;
- }
- }
- }
-
- CVPixelFormatFromQtFormat(pickedFormat, avfPixelFormat);
- }
-
- NSMutableDictionary *videoSettings = [NSMutableDictionary dictionaryWithCapacity:1];
- [videoSettings setObject:[NSNumber numberWithUnsignedInt:avfPixelFormat]
- forKey:(id)kCVPixelBufferPixelFormatTypeKey];
-
- const AVFConfigurationLock lock(captureDevice);
- if (!lock)
- qWarning("Failed to set active format (lock failed)");
-
- videoOutput.videoSettings = videoSettings;
- }
-
- qt_set_framerate_limits(captureDevice, videoConnection(), settings.minimumFrameRate(), settings.maximumFrameRate());
-
- return activeFormatChanged;
-}
-
-QCameraViewfinderSettings AVFCameraViewfinderSettingsControl2::requestedSettings() const
-{
- return m_settings;
-}
-
-AVCaptureConnection *AVFCameraViewfinderSettingsControl2::videoConnection() const
-{
- if (!m_service->videoOutput() || !m_service->videoOutput()->videoDataOutput())
- return nil;
-
- return [m_service->videoOutput()->videoDataOutput() connectionWithMediaType:AVMediaTypeVideo];
-}
-
-AVFCameraViewfinderSettingsControl::AVFCameraViewfinderSettingsControl(AVFCameraService *service)
- : m_service(service)
-{
- // Legacy viewfinder settings control.
- Q_ASSERT(service);
- initSettingsControl();
-}
-
-bool AVFCameraViewfinderSettingsControl::isViewfinderParameterSupported(ViewfinderParameter parameter) const
-{
- return parameter == Resolution
- || parameter == PixelAspectRatio
- || parameter == MinimumFrameRate
- || parameter == MaximumFrameRate
- || parameter == PixelFormat;
-}
-
-QVariant AVFCameraViewfinderSettingsControl::viewfinderParameter(ViewfinderParameter parameter) const
-{
- if (!isViewfinderParameterSupported(parameter)) {
- qDebugCamera() << Q_FUNC_INFO << "parameter is not supported";
- return QVariant();
- }
-
- if (!initSettingsControl()) {
- qDebugCamera() << Q_FUNC_INFO << "initialization failed";
- return QVariant();
- }
-
- const QCameraViewfinderSettings settings(m_settingsControl->viewfinderSettings());
- if (parameter == Resolution)
- return settings.resolution();
- if (parameter == PixelAspectRatio)
- return settings.pixelAspectRatio();
- if (parameter == MinimumFrameRate)
- return settings.minimumFrameRate();
- if (parameter == MaximumFrameRate)
- return settings.maximumFrameRate();
- if (parameter == PixelFormat)
- return QVariant::fromValue(settings.pixelFormat());
-
- return QVariant();
-}
-
-void AVFCameraViewfinderSettingsControl::setViewfinderParameter(ViewfinderParameter parameter, const QVariant &value)
-{
- if (!isViewfinderParameterSupported(parameter)) {
- qDebugCamera() << Q_FUNC_INFO << "parameter is not supported";
- return;
- }
-
- if (parameter == Resolution)
- setResolution(value);
- if (parameter == PixelAspectRatio)
- setAspectRatio(value);
- if (parameter == MinimumFrameRate)
- setFrameRate(value, false);
- if (parameter == MaximumFrameRate)
- setFrameRate(value, true);
- if (parameter == PixelFormat)
- setPixelFormat(value);
-}
-
-void AVFCameraViewfinderSettingsControl::setResolution(const QVariant &newValue)
-{
- if (!newValue.canConvert<QSize>()) {
- qDebugCamera() << Q_FUNC_INFO << "QSize type expected";
- return;
- }
-
- if (!initSettingsControl()) {
- qDebugCamera() << Q_FUNC_INFO << "initialization failed";
- return;
- }
-
- const QSize res(newValue.toSize());
- if (res.isNull() || !res.isValid()) {
- qDebugCamera() << Q_FUNC_INFO << "invalid resolution:" << res;
- return;
- }
-
- QCameraViewfinderSettings settings(m_settingsControl->viewfinderSettings());
- settings.setResolution(res);
- m_settingsControl->setViewfinderSettings(settings);
-}
-
-void AVFCameraViewfinderSettingsControl::setAspectRatio(const QVariant &newValue)
-{
- if (!newValue.canConvert<QSize>()) {
- qDebugCamera() << Q_FUNC_INFO << "QSize type expected";
- return;
- }
-
- if (!initSettingsControl()) {
- qDebugCamera() << Q_FUNC_INFO << "initialization failed";
- return;
- }
-
- const QSize par(newValue.value<QSize>());
- if (par.isNull() || !par.isValid()) {
- qDebugCamera() << Q_FUNC_INFO << "invalid pixel aspect ratio:" << par;
- return;
- }
-
- QCameraViewfinderSettings settings(m_settingsControl->viewfinderSettings());
- settings.setPixelAspectRatio(par);
- m_settingsControl->setViewfinderSettings(settings);
-}
-
-void AVFCameraViewfinderSettingsControl::setFrameRate(const QVariant &newValue, bool max)
-{
- if (!newValue.canConvert<qreal>()) {
- qDebugCamera() << Q_FUNC_INFO << "qreal type expected";
- return;
- }
-
- if (!initSettingsControl()) {
- qDebugCamera() << Q_FUNC_INFO << "initialization failed";
- return;
- }
-
- const qreal fps(newValue.toReal());
- QCameraViewfinderSettings settings(m_settingsControl->viewfinderSettings());
- max ? settings.setMaximumFrameRate(fps) : settings.setMinimumFrameRate(fps);
- m_settingsControl->setViewfinderSettings(settings);
-}
-
-void AVFCameraViewfinderSettingsControl::setPixelFormat(const QVariant &newValue)
-{
- if (!newValue.canConvert<QVideoFrame::PixelFormat>()) {
- qDebugCamera() << Q_FUNC_INFO
- << "QVideoFrame::PixelFormat type expected";
- return;
- }
-
- if (!initSettingsControl()) {
- qDebugCamera() << Q_FUNC_INFO << "initialization failed";
- return;
- }
-
- QCameraViewfinderSettings settings(m_settingsControl->viewfinderSettings());
- settings.setPixelFormat(newValue.value<QVideoFrame::PixelFormat>());
- m_settingsControl->setViewfinderSettings(settings);
-}
-
-bool AVFCameraViewfinderSettingsControl::initSettingsControl()const
-{
- if (!m_settingsControl)
- m_settingsControl = m_service->viewfinderSettingsControl2();
-
- return !m_settingsControl.isNull();
-}
-
-QT_END_NAMESPACE
-
-#include "moc_avfcameraviewfindersettingscontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcamerawindowcontrol.h b/src/plugins/avfoundation/camera/avfcamerawindowcontrol.h
deleted file mode 100644
index d1a950e38..000000000
--- a/src/plugins/avfoundation/camera/avfcamerawindowcontrol.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERAWINDOWCONTROL_H
-#define AVFCAMERAWINDOWCONTROL_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QVideoWindowControl>
-
-@class AVCaptureVideoPreviewLayer;
-#if defined(Q_OS_MACOS)
-@class NSView;
-typedef NSView NativeView;
-#else
-@class UIView;
-typedef UIView NativeView;
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraWindowControl : public QVideoWindowControl
-{
- Q_OBJECT
-public:
- AVFCameraWindowControl(QObject *parent = nullptr);
- virtual ~AVFCameraWindowControl() override;
-
- // QVideoWindowControl interface
-public:
- WId winId() const override;
- void setWinId(WId id) override;
-
- QRect displayRect() const override;
- void setDisplayRect(const QRect &rect) override;
-
- bool isFullScreen() const override;
- void setFullScreen(bool fullScreen) override;
-
- void repaint() override;
-
- QSize nativeSize() const override;
-
- Qt::AspectRatioMode aspectRatioMode() const override;
- void setAspectRatioMode(Qt::AspectRatioMode mode) override;
-
- int brightness() const override;
- void setBrightness(int brightness) override;
-
- int contrast() const override;
- void setContrast(int contrast) override;
-
- int hue() const override;
- void setHue(int hue) override;
-
- int saturation() const override;
- void setSaturation(int saturation) override;
-
- // AVF Camera implementation details
- void setNativeSize(QSize size);
- void setLayer(AVCaptureVideoPreviewLayer *capturePreviewLayer);
-
-private:
- void updateAspectRatio();
- void updateCaptureLayerBounds();
-
- void retainNativeLayer();
- void releaseNativeLayer();
-
- void attachNativeLayer();
- void detachNativeLayer();
-
- WId m_winId{0};
- QRect m_displayRect;
- bool m_fullscreen{false};
- Qt::AspectRatioMode m_aspectRatioMode{Qt::IgnoreAspectRatio};
- QSize m_nativeSize;
- AVCaptureVideoPreviewLayer *m_captureLayer{nullptr};
- NativeView *m_nativeView{nullptr};
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFCAMERAWINDOWCONTROL_H
diff --git a/src/plugins/avfoundation/camera/avfcamerawindowcontrol.mm b/src/plugins/avfoundation/camera/avfcamerawindowcontrol.mm
deleted file mode 100644
index 5154d0646..000000000
--- a/src/plugins/avfoundation/camera/avfcamerawindowcontrol.mm
+++ /dev/null
@@ -1,262 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcamerawindowcontrol.h"
-
-#import <AVFoundation/AVFoundation.h>
-#import <QuartzCore/CATransaction.h>
-
-#if QT_HAS_INCLUDE(<AppKit/AppKit.h>)
-#import <AppKit/AppKit.h>
-#endif
-
-#if QT_HAS_INCLUDE(<UIKit/UIKit.h>)
-#import <UIKit/UIKit.h>
-#endif
-
-QT_USE_NAMESPACE
-
-AVFCameraWindowControl::AVFCameraWindowControl(QObject *parent)
- : QVideoWindowControl(parent)
-{
- setObjectName(QStringLiteral("AVFCameraWindowControl"));
-}
-
-AVFCameraWindowControl::~AVFCameraWindowControl()
-{
- releaseNativeLayer();
-}
-
-WId AVFCameraWindowControl::winId() const
-{
- return m_winId;
-}
-
-void AVFCameraWindowControl::setWinId(WId id)
-{
- if (m_winId == id)
- return;
-
- m_winId = id;
-
- detachNativeLayer();
- m_nativeView = (NativeView*)m_winId;
- attachNativeLayer();
-}
-
-QRect AVFCameraWindowControl::displayRect() const
-{
- return m_displayRect;
-}
-
-void AVFCameraWindowControl::setDisplayRect(const QRect &rect)
-{
- if (m_displayRect != rect) {
- m_displayRect = rect;
- updateCaptureLayerBounds();
- }
-}
-
-bool AVFCameraWindowControl::isFullScreen() const
-{
- return m_fullscreen;
-}
-
-void AVFCameraWindowControl::setFullScreen(bool fullscreen)
-{
- if (m_fullscreen != fullscreen) {
- m_fullscreen = fullscreen;
- Q_EMIT fullScreenChanged(fullscreen);
- }
-}
-
-void AVFCameraWindowControl::repaint()
-{
- if (m_captureLayer)
- [m_captureLayer setNeedsDisplay];
-}
-
-QSize AVFCameraWindowControl::nativeSize() const
-{
- return m_nativeSize;
-}
-
-void AVFCameraWindowControl::setNativeSize(QSize size)
-{
- if (m_nativeSize != size) {
- m_nativeSize = size;
- Q_EMIT nativeSizeChanged();
- }
-}
-
-Qt::AspectRatioMode AVFCameraWindowControl::aspectRatioMode() const
-{
- return m_aspectRatioMode;
-}
-
-void AVFCameraWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- if (m_aspectRatioMode != mode) {
- m_aspectRatioMode = mode;
- updateAspectRatio();
- }
-}
-
-int AVFCameraWindowControl::brightness() const
-{
- return 0;
-}
-
-void AVFCameraWindowControl::setBrightness(int brightness)
-{
- if (0 != brightness)
- qWarning("AVFCameraWindowControl doesn't support changing Brightness");
-}
-
-int AVFCameraWindowControl::contrast() const
-{
- return 0;
-}
-
-void AVFCameraWindowControl::setContrast(int contrast)
-{
- if (0 != contrast)
- qWarning("AVFCameraWindowControl doesn't support changing Contrast");
-}
-
-int AVFCameraWindowControl::hue() const
-{
- return 0;
-}
-
-void AVFCameraWindowControl::setHue(int hue)
-{
- if (0 != hue)
- qWarning("AVFCameraWindowControl doesn't support changing Hue");
-}
-
-int AVFCameraWindowControl::saturation() const
-{
- return 0;
-}
-
-void AVFCameraWindowControl::setSaturation(int saturation)
-{
- if (0 != saturation)
- qWarning("AVFCameraWindowControl doesn't support changing Saturation");
-}
-
-void AVFCameraWindowControl::setLayer(AVCaptureVideoPreviewLayer *capturePreviewLayer)
-{
- if (m_captureLayer == capturePreviewLayer)
- return;
-
- releaseNativeLayer();
-
- m_captureLayer = capturePreviewLayer;
-
- if (m_captureLayer)
- retainNativeLayer();
-}
-
-void AVFCameraWindowControl::updateAspectRatio()
-{
- if (m_captureLayer) {
- switch (m_aspectRatioMode) {
- case Qt::IgnoreAspectRatio:
- [m_captureLayer setVideoGravity:AVLayerVideoGravityResize];
- break;
- case Qt::KeepAspectRatio:
- [m_captureLayer setVideoGravity:AVLayerVideoGravityResizeAspect];
- break;
- case Qt::KeepAspectRatioByExpanding:
- [m_captureLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
- break;
- default:
- break;
- }
- }
-}
-
-void AVFCameraWindowControl::updateCaptureLayerBounds()
-{
- if (m_captureLayer && m_nativeView) {
- [CATransaction begin];
- [CATransaction setDisableActions: YES]; // disable animation/flicks
- m_captureLayer.frame = m_displayRect.toCGRect();
- [CATransaction commit];
- }
-}
-
-void AVFCameraWindowControl::retainNativeLayer()
-{
- [m_captureLayer retain];
-
- updateAspectRatio();
- attachNativeLayer();
-}
-
-void AVFCameraWindowControl::releaseNativeLayer()
-{
- if (m_captureLayer) {
- detachNativeLayer();
- [m_captureLayer release];
- m_captureLayer = nullptr;
- }
-}
-
-void AVFCameraWindowControl::attachNativeLayer()
-{
- if (m_captureLayer && m_nativeView) {
-#if defined(Q_OS_MACOS)
- m_nativeView.wantsLayer = YES;
-#endif
- CALayer *nativeLayer = m_nativeView.layer;
- [nativeLayer addSublayer:m_captureLayer];
- updateCaptureLayerBounds();
- }
-}
-
-void AVFCameraWindowControl::detachNativeLayer()
-{
- if (m_captureLayer && m_nativeView)
- [m_captureLayer removeFromSuperlayer];
-}
-
-#include "moc_avfcamerawindowcontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcamerazoomcontrol.h b/src/plugins/avfoundation/camera/avfcamerazoomcontrol.h
deleted file mode 100644
index 2307dfc28..000000000
--- a/src/plugins/avfoundation/camera/avfcamerazoomcontrol.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAMERAZOOMCONTROL_H
-#define AVFCAMERAZOOMCONTROL_H
-
-#include <QtMultimedia/qcamerazoomcontrol.h>
-#include <QtMultimedia/qcamera.h>
-
-#include <AVFoundation/AVFoundation.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraService;
-class AVFCameraSession;
-class AVFCameraControl;
-
-class AVFCameraZoomControl : public QCameraZoomControl
-{
- Q_OBJECT
-public:
- AVFCameraZoomControl(AVFCameraService *service);
-
- qreal maximumOpticalZoom() const override;
- qreal maximumDigitalZoom() const override;
-
- qreal requestedOpticalZoom() const override;
- qreal requestedDigitalZoom() const override;
- qreal currentOpticalZoom() const override;
- qreal currentDigitalZoom() const override;
-
- void zoomTo(qreal optical, qreal digital) override;
-
-private Q_SLOTS:
- void cameraStateChanged();
-
-private:
- void zoomToRequestedDigital();
-
- AVFCameraSession *m_session;
-
- CGFloat m_maxZoomFactor;
- CGFloat m_zoomFactor;
- CGFloat m_requestedZoomFactor;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfcamerazoomcontrol.mm b/src/plugins/avfoundation/camera/avfcamerazoomcontrol.mm
deleted file mode 100644
index 119a1fc0a..000000000
--- a/src/plugins/avfoundation/camera/avfcamerazoomcontrol.mm
+++ /dev/null
@@ -1,179 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcamerazoomcontrol.h"
-#include "avfcameraservice.h"
-#include "avfcamerautility.h"
-#include "avfcamerasession.h"
-#include "avfcameracontrol.h"
-#include "avfcameradebug.h"
-
-#include <QtCore/qglobal.h>
-#include <QtCore/qdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-AVFCameraZoomControl::AVFCameraZoomControl(AVFCameraService *service)
- : m_session(service->session()),
- m_maxZoomFactor(1.),
- m_zoomFactor(1.),
- m_requestedZoomFactor(1.)
-{
- Q_ASSERT(m_session);
- connect(m_session, SIGNAL(stateChanged(QCamera::State)),
- SLOT(cameraStateChanged()));
-}
-
-qreal AVFCameraZoomControl::maximumOpticalZoom() const
-{
- // Not supported.
- return 1.;
-}
-
-qreal AVFCameraZoomControl::maximumDigitalZoom() const
-{
- return m_maxZoomFactor;
-}
-
-qreal AVFCameraZoomControl::requestedOpticalZoom() const
-{
- // Not supported.
- return 1;
-}
-
-qreal AVFCameraZoomControl::requestedDigitalZoom() const
-{
- return m_requestedZoomFactor;
-}
-
-qreal AVFCameraZoomControl::currentOpticalZoom() const
-{
- // Not supported.
- return 1.;
-}
-
-qreal AVFCameraZoomControl::currentDigitalZoom() const
-{
- return m_zoomFactor;
-}
-
-void AVFCameraZoomControl::zoomTo(qreal optical, qreal digital)
-{
- Q_UNUSED(optical);
- Q_UNUSED(digital);
-
- if (qFuzzyCompare(CGFloat(digital), m_requestedZoomFactor))
- return;
-
- m_requestedZoomFactor = digital;
- Q_EMIT requestedDigitalZoomChanged(digital);
-
- zoomToRequestedDigital();
-}
-
-void AVFCameraZoomControl::cameraStateChanged()
-{
- const QCamera::State state = m_session->state();
- if (state != QCamera::ActiveState) {
- if (state == QCamera::UnloadedState && m_maxZoomFactor > 1.) {
- m_maxZoomFactor = 1.;
- Q_EMIT maximumDigitalZoomChanged(1.);
- }
- return;
- }
-
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice || !captureDevice.activeFormat) {
- qDebugCamera() << Q_FUNC_INFO << "camera state is active, but"
- << "video capture device and/or active format is nil";
- return;
- }
-
- if (captureDevice.activeFormat.videoMaxZoomFactor > 1.) {
- if (!qFuzzyCompare(m_maxZoomFactor, captureDevice.activeFormat.videoMaxZoomFactor)) {
- m_maxZoomFactor = captureDevice.activeFormat.videoMaxZoomFactor;
- Q_EMIT maximumDigitalZoomChanged(m_maxZoomFactor);
- }
- } else if (!qFuzzyCompare(m_maxZoomFactor, CGFloat(1.))) {
- m_maxZoomFactor = 1.;
-
- Q_EMIT maximumDigitalZoomChanged(1.);
- }
-
- zoomToRequestedDigital();
-}
-
-void AVFCameraZoomControl::zoomToRequestedDigital()
-{
- AVCaptureDevice *captureDevice = m_session->videoCaptureDevice();
- if (!captureDevice || !captureDevice.activeFormat)
- return;
-
- if (qFuzzyCompare(captureDevice.activeFormat.videoMaxZoomFactor, CGFloat(1.)))
- return;
-
- const CGFloat clampedZoom = qBound(CGFloat(1.), m_requestedZoomFactor,
- captureDevice.activeFormat.videoMaxZoomFactor);
- const CGFloat deviceZoom = captureDevice.videoZoomFactor;
- if (qFuzzyCompare(clampedZoom, deviceZoom)) {
- // Nothing to set, but check if a signal must be emitted:
- if (!qFuzzyCompare(m_zoomFactor, deviceZoom)) {
- m_zoomFactor = deviceZoom;
- Q_EMIT currentDigitalZoomChanged(deviceZoom);
- }
- return;
- }
-
- const AVFConfigurationLock lock(captureDevice);
- if (!lock) {
- qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- return;
- }
-
- captureDevice.videoZoomFactor = clampedZoom;
-
- if (!qFuzzyCompare(clampedZoom, m_zoomFactor)) {
- m_zoomFactor = clampedZoom;
- Q_EMIT currentDigitalZoomChanged(clampedZoom);
- }
-}
-
-QT_END_NAMESPACE
-
-#include "moc_avfcamerazoomcontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.h b/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.h
deleted file mode 100644
index 04493437e..000000000
--- a/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFCAPTUREDESTINATIONCONTROL_H
-#define AVFCAPTUREDESTINATIONCONTROL_H
-
-#include <qcameracapturedestinationcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFCaptureDestinationControl : public QCameraCaptureDestinationControl
-{
-public:
- AVFCaptureDestinationControl() = default;
- ~AVFCaptureDestinationControl() = default;
-
- bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const override;
- QCameraImageCapture::CaptureDestinations captureDestination() const override;
- void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) override;
-
-private:
- QCameraImageCapture::CaptureDestinations m_destination = QCameraImageCapture::CaptureToFile;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFCAPTUREDESTINATIONCONTROL_H
diff --git a/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.mm b/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.mm
deleted file mode 100644
index d0700d69d..000000000
--- a/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.mm
+++ /dev/null
@@ -1,62 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcapturedestinationcontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-bool AVFCaptureDestinationControl::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const
-{
- return destination & (QCameraImageCapture::CaptureToFile | QCameraImageCapture::CaptureToBuffer);
-}
-
-QCameraImageCapture::CaptureDestinations AVFCaptureDestinationControl::captureDestination() const
-{
- return m_destination;
-}
-
-void AVFCaptureDestinationControl::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination)
-{
- if (m_destination != destination) {
- m_destination = destination;
- Q_EMIT captureDestinationChanged(m_destination);
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/avfoundation/camera/avfimagecapturecontrol.h b/src/plugins/avfoundation/camera/avfimagecapturecontrol.h
deleted file mode 100644
index 314e867e7..000000000
--- a/src/plugins/avfoundation/camera/avfimagecapturecontrol.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFIMAGECAPTURECONTROL_H
-#define AVFIMAGECAPTURECONTROL_H
-
-#import <AVFoundation/AVFoundation.h>
-
-#include <QtCore/qqueue.h>
-#include <QtCore/qsemaphore.h>
-#include <QtCore/qsharedpointer.h>
-#include <QtMultimedia/qcameraimagecapturecontrol.h>
-#include "avfcamerasession.h"
-#include "avfstoragelocation.h"
-
-QT_BEGIN_NAMESPACE
-
-class AVFImageCaptureControl : public QCameraImageCaptureControl
-{
-Q_OBJECT
-public:
- struct CaptureRequest {
- int captureId;
- QSharedPointer<QSemaphore> previewReady;
- };
-
- AVFImageCaptureControl(AVFCameraService *service, QObject *parent = nullptr);
- ~AVFImageCaptureControl();
-
- bool isReadyForCapture() const override;
-
- QCameraImageCapture::DriveMode driveMode() const override { return QCameraImageCapture::SingleImageCapture; }
- void setDriveMode(QCameraImageCapture::DriveMode ) override {}
- AVCaptureStillImageOutput *stillImageOutput() const {return m_stillImageOutput;}
-
- int capture(const QString &fileName) override;
- void cancelCapture() override;
-
-private Q_SLOTS:
- void updateCaptureConnection();
- void updateReadyStatus();
- void onNewViewfinderFrame(const QVideoFrame &frame);
-
-private:
- void makeCapturePreview(CaptureRequest request, const QVideoFrame &frame, int rotation);
-
- AVFCameraService *m_service;
- AVFCameraSession *m_session;
- AVFCameraControl *m_cameraControl;
- bool m_ready;
- int m_lastCaptureId;
- AVCaptureStillImageOutput *m_stillImageOutput;
- AVCaptureConnection *m_videoConnection;
- AVFStorageLocation m_storageLocation;
-
- QMutex m_requestsMutex;
- QQueue<CaptureRequest> m_captureRequests;
-};
-
-Q_DECLARE_TYPEINFO(AVFImageCaptureControl::CaptureRequest, Q_PRIMITIVE_TYPE);
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfimagecapturecontrol.mm b/src/plugins/avfoundation/camera/avfimagecapturecontrol.mm
deleted file mode 100644
index f2c019fdc..000000000
--- a/src/plugins/avfoundation/camera/avfimagecapturecontrol.mm
+++ /dev/null
@@ -1,266 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcameradebug.h"
-#include "avfimagecapturecontrol.h"
-#include "avfcameraservice.h"
-#include "avfcamerautility.h"
-#include "avfcameracontrol.h"
-#include "avfcapturedestinationcontrol.h"
-#include <private/qmemoryvideobuffer_p.h>
-
-#include <QtCore/qurl.h>
-#include <QtCore/qfile.h>
-#include <QtCore/qbuffer.h>
-#include <QtConcurrent/qtconcurrentrun.h>
-#include <QtGui/qimagereader.h>
-
-QT_USE_NAMESPACE
-
-AVFImageCaptureControl::AVFImageCaptureControl(AVFCameraService *service, QObject *parent)
- : QCameraImageCaptureControl(parent)
- , m_service(service)
- , m_session(service->session())
- , m_cameraControl(service->cameraControl())
- , m_ready(false)
- , m_lastCaptureId(0)
- , m_videoConnection(nil)
-{
- Q_UNUSED(service);
- m_stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
-
- NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
- AVVideoCodecJPEG, AVVideoCodecKey, nil];
-
- [m_stillImageOutput setOutputSettings:outputSettings];
- [outputSettings release];
- connect(m_cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureModes)), SLOT(updateReadyStatus()));
- connect(m_cameraControl, SIGNAL(statusChanged(QCamera::Status)), SLOT(updateReadyStatus()));
-
- connect(m_session, SIGNAL(readyToConfigureConnections()), SLOT(updateCaptureConnection()));
- connect(m_cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureModes)), SLOT(updateCaptureConnection()));
-
- connect(m_session, &AVFCameraSession::newViewfinderFrame,
- this, &AVFImageCaptureControl::onNewViewfinderFrame,
- Qt::DirectConnection);
-}
-
-AVFImageCaptureControl::~AVFImageCaptureControl()
-{
-}
-
-bool AVFImageCaptureControl::isReadyForCapture() const
-{
- return m_videoConnection &&
- m_cameraControl->captureMode().testFlag(QCamera::CaptureStillImage) &&
- m_cameraControl->status() == QCamera::ActiveStatus;
-}
-
-void AVFImageCaptureControl::updateReadyStatus()
-{
- if (m_ready != isReadyForCapture()) {
- m_ready = !m_ready;
- qDebugCamera() << "ReadyToCapture status changed:" << m_ready;
- Q_EMIT readyForCaptureChanged(m_ready);
- }
-}
-
-int AVFImageCaptureControl::capture(const QString &fileName)
-{
- m_lastCaptureId++;
-
- if (!isReadyForCapture()) {
- QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(int, m_lastCaptureId),
- Q_ARG(int, QCameraImageCapture::NotReadyError),
- Q_ARG(QString, tr("Camera not ready")));
- return m_lastCaptureId;
- }
-
- auto destination = m_service->captureDestinationControl()->captureDestination();
- QString actualFileName;
- if (destination & QCameraImageCapture::CaptureToFile) {
- actualFileName = m_storageLocation.generateFileName(fileName,
- QCamera::CaptureStillImage,
- QLatin1String("img_"),
- QLatin1String("jpg"));
-
- qDebugCamera() << "Capture image to" << actualFileName;
- }
-
- CaptureRequest request = { m_lastCaptureId, QSharedPointer<QSemaphore>::create()};
- m_requestsMutex.lock();
- m_captureRequests.enqueue(request);
- m_requestsMutex.unlock();
-
- [m_stillImageOutput captureStillImageAsynchronouslyFromConnection:m_videoConnection
- completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
-
- if (error) {
- QStringList messageParts;
- messageParts << QString::fromUtf8([[error localizedDescription] UTF8String]);
- messageParts << QString::fromUtf8([[error localizedFailureReason] UTF8String]);
- messageParts << QString::fromUtf8([[error localizedRecoverySuggestion] UTF8String]);
-
- QString errorMessage = messageParts.join(" ");
- qDebugCamera() << "Image capture failed:" << errorMessage;
-
- QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(int, request.captureId),
- Q_ARG(int, QCameraImageCapture::ResourceError),
- Q_ARG(QString, errorMessage));
- return;
- }
-
- // Wait for the preview to be generated before saving the JPEG (but only
- // if we have AVFCameraRendererControl attached).
- // It is possible to stop camera immediately after trying to capture an
- // image; this can result in a blocked callback's thread, waiting for a
- // new viewfinder's frame to arrive/semaphore to be released. It is also
- // unspecified on which thread this callback gets executed, (probably it's
- // not the same thread that initiated a capture and stopped the camera),
- // so we cannot reliably check the camera's status. Instead, we wait
- // with a timeout and treat a failure to acquire a semaphore as an error.
- if (!m_service->videoOutput() || request.previewReady->tryAcquire(1, 1000)) {
- qDebugCamera() << "Image capture completed";
-
- NSData *nsJpgData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
- QByteArray jpgData = QByteArray::fromRawData((const char *)[nsJpgData bytes], [nsJpgData length]);
-
- if (destination & QCameraImageCapture::CaptureToBuffer) {
- QBuffer data(&jpgData);
- QImageReader reader(&data, "JPEG");
- QSize size = reader.size();
- QVideoFrame frame(new QMemoryVideoBuffer(QByteArray(jpgData.constData(), jpgData.size()), -1), size, QVideoFrame::Format_Jpeg);
- QMetaObject::invokeMethod(this, "imageAvailable", Qt::QueuedConnection,
- Q_ARG(int, request.captureId),
- Q_ARG(QVideoFrame, frame));
- }
-
- if (!(destination & QCameraImageCapture::CaptureToFile))
- return;
-
- QFile f(actualFileName);
- if (f.open(QFile::WriteOnly)) {
- if (f.write(jpgData) != -1) {
- QMetaObject::invokeMethod(this, "imageSaved", Qt::QueuedConnection,
- Q_ARG(int, request.captureId),
- Q_ARG(QString, actualFileName));
- } else {
- QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(int, request.captureId),
- Q_ARG(int, QCameraImageCapture::OutOfSpaceError),
- Q_ARG(QString, f.errorString()));
- }
- } else {
- QString errorMessage = tr("Could not open destination file:\n%1").arg(actualFileName);
- QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(int, request.captureId),
- Q_ARG(int, QCameraImageCapture::ResourceError),
- Q_ARG(QString, errorMessage));
- }
- } else {
- const QLatin1String errorMessage("Image capture failed: timed out waiting"
- " for a preview frame.");
- qDebugCamera() << errorMessage;
- QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(int, request.captureId),
- Q_ARG(int, QCameraImageCapture::ResourceError),
- Q_ARG(QString, errorMessage));
- }
- }];
-
- return request.captureId;
-}
-
-void AVFImageCaptureControl::onNewViewfinderFrame(const QVideoFrame &frame)
-{
- QMutexLocker locker(&m_requestsMutex);
-
- if (m_captureRequests.isEmpty())
- return;
-
- CaptureRequest request = m_captureRequests.dequeue();
- Q_EMIT imageExposed(request.captureId);
-
- QtConcurrent::run(&AVFImageCaptureControl::makeCapturePreview, this,
- request,
- frame,
- 0 /* rotation */);
-}
-
-void AVFImageCaptureControl::makeCapturePreview(CaptureRequest request,
- const QVideoFrame &frame,
- int rotation)
-{
- QTransform transform;
- transform.rotate(rotation);
-
- Q_EMIT imageCaptured(request.captureId, frame.image().transformed(transform));
-
- request.previewReady->release();
-}
-
-void AVFImageCaptureControl::cancelCapture()
-{
- //not supported
-}
-
-void AVFImageCaptureControl::updateCaptureConnection()
-{
- if (m_session->videoCaptureDevice()
- && m_cameraControl->captureMode().testFlag(QCamera::CaptureStillImage)) {
- qDebugCamera() << Q_FUNC_INFO;
- AVCaptureSession *captureSession = m_session->captureSession();
-
- if (![captureSession.outputs containsObject:m_stillImageOutput]) {
- if ([captureSession canAddOutput:m_stillImageOutput]) {
- // Lock the video capture device to make sure the active format is not reset
- const AVFConfigurationLock lock(m_session->videoCaptureDevice());
- [captureSession addOutput:m_stillImageOutput];
- m_videoConnection = [m_stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
- updateReadyStatus();
- }
- } else {
- m_videoConnection = [m_stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
- }
- }
-}
-
-#include "moc_avfimagecapturecontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfimageencodercontrol.h b/src/plugins/avfoundation/camera/avfimageencodercontrol.h
deleted file mode 100644
index 7e2e34294..000000000
--- a/src/plugins/avfoundation/camera/avfimageencodercontrol.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFIMAGEENCODERCONTROL_H
-#define AVFIMAGEENCODERCONTROL_H
-
-#include <QtMultimedia/qmediaencodersettings.h>
-#include <QtMultimedia/qimageencodercontrol.h>
-
-#include <QtCore/qglobal.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qlist.h>
-
-@class AVCaptureDeviceFormat;
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraService;
-
-class AVFImageEncoderControl : public QImageEncoderControl
-{
- Q_OBJECT
-
- friend class AVFCameraSession;
-public:
- AVFImageEncoderControl(AVFCameraService *service);
-
- QStringList supportedImageCodecs() const override;
- QString imageCodecDescription(const QString &codecName) const override;
- QList<QSize> supportedResolutions(const QImageEncoderSettings &settings,
- bool *continuous) const override;
- QImageEncoderSettings imageSettings() const override;
- void setImageSettings(const QImageEncoderSettings &settings) override;
-
- QImageEncoderSettings requestedSettings() const;
-
-private:
- AVFCameraService *m_service;
- QImageEncoderSettings m_settings;
-
- bool applySettings();
- bool videoCaptureDeviceIsValid() const;
-};
-
-QSize qt_image_high_resolution(AVCaptureDeviceFormat *fomat);
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfimageencodercontrol.mm b/src/plugins/avfoundation/camera/avfimageencodercontrol.mm
deleted file mode 100644
index 93de3e63c..000000000
--- a/src/plugins/avfoundation/camera/avfimageencodercontrol.mm
+++ /dev/null
@@ -1,240 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcameraviewfindersettingscontrol.h"
-#include "avfimageencodercontrol.h"
-#include "avfimagecapturecontrol.h"
-#include "avfcamerautility.h"
-#include "avfcamerasession.h"
-#include "avfcameraservice.h"
-#include "avfcameradebug.h"
-#include "avfcameracontrol.h"
-
-#include <QtMultimedia/qmediaencodersettings.h>
-
-#include <QtCore/qdebug.h>
-
-#include <AVFoundation/AVFoundation.h>
-
-QT_BEGIN_NAMESPACE
-
-AVFImageEncoderControl::AVFImageEncoderControl(AVFCameraService *service)
- : m_service(service)
-{
- Q_ASSERT(service);
-}
-
-QStringList AVFImageEncoderControl::supportedImageCodecs() const
-{
- return QStringList() << QLatin1String("jpeg");
-}
-
-QString AVFImageEncoderControl::imageCodecDescription(const QString &codecName) const
-{
- if (codecName == QLatin1String("jpeg"))
- return tr("JPEG image");
-
- return QString();
-}
-
-QList<QSize> AVFImageEncoderControl::supportedResolutions(const QImageEncoderSettings &settings,
- bool *continuous) const
-{
- Q_UNUSED(settings);
-
- QList<QSize> resolutions;
-
- if (!videoCaptureDeviceIsValid())
- return resolutions;
-
- AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
- const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(captureDevice,
- m_service->session()->defaultCodec()));
-
- for (int i = 0; i < formats.size(); ++i) {
- AVCaptureDeviceFormat *format = formats[i];
-
- const QSize res(qt_device_format_resolution(format));
- if (!res.isNull() && res.isValid())
- resolutions << res;
-#ifdef Q_OS_IOS
- // From Apple's docs (iOS):
- // By default, AVCaptureStillImageOutput emits images with the same dimensions as
- // its source AVCaptureDevice instance’s activeFormat.formatDescription. However,
- // if you set this property to YES, the receiver emits still images at the capture
- // device’s highResolutionStillImageDimensions value.
- const QSize hrRes(qt_device_format_high_resolution(format));
- if (!hrRes.isNull() && hrRes.isValid())
- resolutions << res;
-#endif
- }
-
- if (continuous)
- *continuous = false;
-
- return resolutions;
-}
-
-QImageEncoderSettings AVFImageEncoderControl::requestedSettings() const
-{
- return m_settings;
-}
-
-QImageEncoderSettings AVFImageEncoderControl::imageSettings() const
-{
- QImageEncoderSettings settings;
-
- if (!videoCaptureDeviceIsValid())
- return settings;
-
- AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
- if (!captureDevice.activeFormat) {
- qDebugCamera() << Q_FUNC_INFO << "no active format";
- return settings;
- }
-
- QSize res(qt_device_format_resolution(captureDevice.activeFormat));
-#ifdef Q_OS_IOS
- if (!m_service->imageCaptureControl() || !m_service->imageCaptureControl()->stillImageOutput()) {
- qDebugCamera() << Q_FUNC_INFO << "no still image output";
- return settings;
- }
-
- AVCaptureStillImageOutput *stillImageOutput = m_service->imageCaptureControl()->stillImageOutput();
- if (stillImageOutput.highResolutionStillImageOutputEnabled)
- res = qt_device_format_high_resolution(captureDevice.activeFormat);
-#endif
- if (res.isNull() || !res.isValid()) {
- qDebugCamera() << Q_FUNC_INFO << "failed to exctract the image resolution";
- return settings;
- }
-
- settings.setResolution(res);
-
- settings.setCodec(QLatin1String("jpeg"));
-
- return settings;
-}
-
-void AVFImageEncoderControl::setImageSettings(const QImageEncoderSettings &settings)
-{
- if (m_settings == settings)
- return;
-
- m_settings = settings;
- applySettings();
-}
-
-bool AVFImageEncoderControl::applySettings()
-{
- if (!videoCaptureDeviceIsValid())
- return false;
-
- AVFCameraSession *session = m_service->session();
- if (!session || (session->state() != QCamera::ActiveState
- && session->state() != QCamera::LoadedState)
- || !m_service->cameraControl()->captureMode().testFlag(QCamera::CaptureStillImage)) {
- return false;
- }
-
- if (!m_service->imageCaptureControl()
- || !m_service->imageCaptureControl()->stillImageOutput()) {
- qDebugCamera() << Q_FUNC_INFO << "no still image output";
- return false;
- }
-
- if (m_settings.codec().size()
- && m_settings.codec() != QLatin1String("jpeg")) {
- qDebugCamera() << Q_FUNC_INFO << "unsupported codec:" << m_settings.codec();
- return false;
- }
-
- QSize res(m_settings.resolution());
- if (res.isNull()) {
- qDebugCamera() << Q_FUNC_INFO << "invalid resolution:" << res;
- return false;
- }
-
- if (!res.isValid()) {
- // Invalid == default value.
- // Here we could choose the best format available, but
- // activeFormat is already equal to 'preset high' by default,
- // which is good enough, otherwise we can end in some format with low framerates.
- return false;
- }
-
- bool activeFormatChanged = false;
-
- AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
- AVCaptureDeviceFormat *match = qt_find_best_resolution_match(captureDevice, res,
- m_service->session()->defaultCodec());
-
- if (!match) {
- qDebugCamera() << Q_FUNC_INFO << "unsupported resolution:" << res;
- return false;
- }
-
- activeFormatChanged = qt_set_active_format(captureDevice, match, true);
-
-#ifdef Q_OS_IOS
- AVCaptureStillImageOutput *imageOutput = m_service->imageCaptureControl()->stillImageOutput();
- if (res == qt_device_format_high_resolution(captureDevice.activeFormat))
- imageOutput.highResolutionStillImageOutputEnabled = YES;
- else
- imageOutput.highResolutionStillImageOutputEnabled = NO;
-#endif
-
- return activeFormatChanged;
-}
-
-bool AVFImageEncoderControl::videoCaptureDeviceIsValid() const
-{
- if (!m_service->session() || !m_service->session()->videoCaptureDevice())
- return false;
-
- AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
- if (!captureDevice.formats || !captureDevice.formats.count)
- return false;
-
- return true;
-}
-
-QT_END_NAMESPACE
-
-#include "moc_avfimageencodercontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfmediaassetwriter.h b/src/plugins/avfoundation/camera/avfmediaassetwriter.h
deleted file mode 100644
index f063dab4b..000000000
--- a/src/plugins/avfoundation/camera/avfmediaassetwriter.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFMEDIAASSETWRITER_H
-#define AVFMEDIAASSETWRITER_H
-
-#include "avfcamerautility.h"
-
-#include <QtCore/qglobal.h>
-
-#include <AVFoundation/AVFoundation.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFMediaRecorderControlIOS;
-class AVFCameraService;
-
-QT_END_NAMESPACE
-
-@interface QT_MANGLE_NAMESPACE(AVFMediaAssetWriter) : NSObject<AVCaptureVideoDataOutputSampleBufferDelegate,
- AVCaptureAudioDataOutputSampleBufferDelegate>
-- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(AVFMediaRecorderControlIOS) *)delegate;
-
-- (bool)setupWithFileURL:(NSURL *)fileURL
- cameraService:(QT_PREPEND_NAMESPACE(AVFCameraService) *)service
- audioSettings:(NSDictionary *)audioSettings
- videoSettings:(NSDictionary *)videoSettings
- transform:(CGAffineTransform)transform;
-
-// This to be called from the recorder control's thread:
-- (void)start;
-- (void)stop;
-// This to be called from the recorder control's dtor:
-- (void)abort;
-- (qint64)durationInMs;
-
-@end
-
-#endif // AVFMEDIAASSETWRITER_H
diff --git a/src/plugins/avfoundation/camera/avfmediaassetwriter.mm b/src/plugins/avfoundation/camera/avfmediaassetwriter.mm
deleted file mode 100644
index 57c5cb8c5..000000000
--- a/src/plugins/avfoundation/camera/avfmediaassetwriter.mm
+++ /dev/null
@@ -1,514 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfaudioinputselectorcontrol.h"
-#include "avfmediarecordercontrol_ios.h"
-#include "avfcamerarenderercontrol.h"
-#include "avfmediaassetwriter.h"
-#include "avfcameraservice.h"
-#include "avfcamerasession.h"
-#include "avfcameradebug.h"
-#include "avfmediacontainercontrol.h"
-
-#include <QtCore/qmetaobject.h>
-#include <QtCore/qatomic.h>
-
-QT_USE_NAMESPACE
-
-namespace {
-
-bool qt_camera_service_isValid(AVFCameraService *service)
-{
- if (!service || !service->session())
- return false;
-
- AVFCameraSession *session = service->session();
- if (!session->captureSession())
- return false;
-
- if (!session->videoInput())
- return false;
-
- if (!service->videoOutput()
- || !service->videoOutput()->videoDataOutput()) {
- return false;
- }
-
- return true;
-}
-
-enum WriterState
-{
- WriterStateIdle,
- WriterStateActive,
- WriterStateAborted
-};
-
-using AVFAtomicInt64 = QAtomicInteger<qint64>;
-
-} // unnamed namespace
-
-@interface QT_MANGLE_NAMESPACE(AVFMediaAssetWriter) (PrivateAPI)
-- (bool)addAudioCapture;
-- (bool)addWriterInputs;
-- (void)setQueues;
-- (void)updateDuration:(CMTime)newTimeStamp;
-@end
-
-@implementation QT_MANGLE_NAMESPACE(AVFMediaAssetWriter)
-{
-@private
- AVFCameraService *m_service;
-
- AVFScopedPointer<AVAssetWriterInput> m_cameraWriterInput;
- AVFScopedPointer<AVCaptureDeviceInput> m_audioInput;
- AVFScopedPointer<AVCaptureAudioDataOutput> m_audioOutput;
- AVFScopedPointer<AVAssetWriterInput> m_audioWriterInput;
-
- AVCaptureDevice *m_audioCaptureDevice;
-
- // Queue to write sample buffers:
- AVFScopedPointer<dispatch_queue_t> m_writerQueue;
- // High priority serial queue for video output:
- AVFScopedPointer<dispatch_queue_t> m_videoQueue;
- // Serial queue for audio output:
- AVFScopedPointer<dispatch_queue_t> m_audioQueue;
-
- AVFScopedPointer<AVAssetWriter> m_assetWriter;
-
- AVFMediaRecorderControlIOS *m_delegate;
-
- bool m_setStartTime;
-
- QAtomicInt m_state;
-
- CMTime m_startTime;
- CMTime m_lastTimeStamp;
-
- NSDictionary *m_audioSettings;
- NSDictionary *m_videoSettings;
-
- AVFAtomicInt64 m_durationInMs;
-}
-
-- (id)initWithDelegate:(AVFMediaRecorderControlIOS *)delegate
-{
- Q_ASSERT(delegate);
-
- if (self = [super init]) {
- m_delegate = delegate;
- m_setStartTime = true;
- m_state.storeRelaxed(WriterStateIdle);
- m_startTime = kCMTimeInvalid;
- m_lastTimeStamp = kCMTimeInvalid;
- m_durationInMs.storeRelaxed(0);
- m_audioSettings = nil;
- m_videoSettings = nil;
- }
-
- return self;
-}
-
-- (bool)setupWithFileURL:(NSURL *)fileURL
- cameraService:(AVFCameraService *)service
- audioSettings:(NSDictionary *)audioSettings
- videoSettings:(NSDictionary *)videoSettings
- transform:(CGAffineTransform)transform
-{
- Q_ASSERT(fileURL);
-
- if (!qt_camera_service_isValid(service)) {
- qDebugCamera() << Q_FUNC_INFO << "invalid camera service";
- return false;
- }
-
- m_service = service;
- m_audioSettings = audioSettings;
- m_videoSettings = videoSettings;
-
- m_writerQueue.reset(dispatch_queue_create("asset-writer-queue", DISPATCH_QUEUE_SERIAL));
- if (!m_writerQueue) {
- qDebugCamera() << Q_FUNC_INFO << "failed to create an asset writer's queue";
- return false;
- }
-
- m_videoQueue.reset(dispatch_queue_create("video-output-queue", DISPATCH_QUEUE_SERIAL));
- if (!m_videoQueue) {
- qDebugCamera() << Q_FUNC_INFO << "failed to create video queue";
- return false;
- }
- dispatch_set_target_queue(m_videoQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));
- m_audioQueue.reset(dispatch_queue_create("audio-output-queue", DISPATCH_QUEUE_SERIAL));
- if (!m_audioQueue) {
- qDebugCamera() << Q_FUNC_INFO << "failed to create audio queue";
- // But we still can write video!
- }
-
- m_assetWriter.reset([[AVAssetWriter alloc] initWithURL:fileURL
- fileType:m_service->mediaContainerControl()->fileType()
- error:nil]);
- if (!m_assetWriter) {
- qDebugCamera() << Q_FUNC_INFO << "failed to create asset writer";
- return false;
- }
-
- bool audioCaptureOn = false;
-
- if (m_audioQueue)
- audioCaptureOn = [self addAudioCapture];
-
- if (![self addWriterInputs]) {
- if (audioCaptureOn) {
- AVCaptureSession *session = m_service->session()->captureSession();
- [session removeOutput:m_audioOutput];
- [session removeInput:m_audioInput];
- m_audioOutput.reset();
- m_audioInput.reset();
- m_audioCaptureDevice = 0;
- }
- m_assetWriter.reset();
- return false;
- }
-
- m_cameraWriterInput.data().transform = transform;
-
- // Ready to start ...
- return true;
-}
-
-- (void)start
-{
- [self setQueues];
-
- m_setStartTime = true;
-
- m_state.storeRelease(WriterStateActive);
-
- [m_assetWriter startWriting];
- AVCaptureSession *session = m_service->session()->captureSession();
- if (!session.running)
- [session startRunning];
-}
-
-- (void)stop
-{
- if (m_state.loadAcquire() != WriterStateActive)
- return;
-
- if ([m_assetWriter status] != AVAssetWriterStatusWriting)
- return;
-
- // Do this here so that -
- // 1. '-abort' should not try calling finishWriting again and
- // 2. async block (see below) will know if recorder control was deleted
- // before the block's execution:
- m_state.storeRelease(WriterStateIdle);
- // Now, since we have to ensure no sample buffers are
- // appended after a call to finishWriting, we must
- // ensure writer's queue sees this change in m_state
- // _before_ we call finishWriting:
- dispatch_sync(m_writerQueue, ^{});
- // Done, but now we also want to prevent video queue
- // from updating our viewfinder:
- dispatch_sync(m_videoQueue, ^{});
-
- // Now we're safe to stop:
- [m_assetWriter finishWritingWithCompletionHandler:^{
- // This block is async, so by the time it's executed,
- // it's possible that render control was deleted already ...
- if (m_state.loadAcquire() == WriterStateAborted)
- return;
-
- AVCaptureSession *session = m_service->session()->captureSession();
- if (session.running)
- [session stopRunning];
- [session removeOutput:m_audioOutput];
- [session removeInput:m_audioInput];
- QMetaObject::invokeMethod(m_delegate, "assetWriterFinished", Qt::QueuedConnection);
- }];
-}
-
-- (void)abort
-{
- // -abort is to be called from recorder control's dtor.
-
- if (m_state.fetchAndStoreRelease(WriterStateAborted) != WriterStateActive) {
- // Not recording, nothing to stop.
- return;
- }
-
- // From Apple's docs:
- // "To guarantee that all sample buffers are successfully written,
- // you must ensure that all calls to appendSampleBuffer: and
- // appendPixelBuffer:withPresentationTime: have returned before
- // invoking this method."
- //
- // The only way we can ensure this is:
- dispatch_sync(m_writerQueue, ^{});
- // At this point next block (if any) on the writer's queue
- // will see m_state preventing it from any further processing.
- dispatch_sync(m_videoQueue, ^{});
- // After this point video queue will not try to modify our
- // viewfider, so we're safe to delete now.
-
- [m_assetWriter finishWritingWithCompletionHandler:^{
- }];
-}
-
-- (void)setStartTimeFrom:(CMSampleBufferRef)sampleBuffer
-{
- // Writer's queue only.
- Q_ASSERT(m_setStartTime);
- Q_ASSERT(sampleBuffer);
-
- if (m_state.loadAcquire() != WriterStateActive)
- return;
-
- QMetaObject::invokeMethod(m_delegate, "assetWriterStarted", Qt::QueuedConnection);
-
- m_durationInMs.storeRelease(0);
- m_startTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
- m_lastTimeStamp = m_startTime;
- [m_assetWriter startSessionAtSourceTime:m_startTime];
- m_setStartTime = false;
-}
-
-- (void)writeVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer
-{
- // This code is executed only on a writer's queue.
- Q_ASSERT(sampleBuffer);
-
- if (m_state.loadAcquire() == WriterStateActive) {
- if (m_setStartTime)
- [self setStartTimeFrom:sampleBuffer];
-
- if (m_cameraWriterInput.data().readyForMoreMediaData) {
- [self updateDuration:CMSampleBufferGetPresentationTimeStamp(sampleBuffer)];
- [m_cameraWriterInput appendSampleBuffer:sampleBuffer];
- }
- }
-
- CFRelease(sampleBuffer);
-}
-
-- (void)writeAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer
-{
- Q_ASSERT(sampleBuffer);
-
- // This code is executed only on a writer's queue.
- if (m_state.loadAcquire() == WriterStateActive) {
- if (m_setStartTime)
- [self setStartTimeFrom:sampleBuffer];
-
- if (m_audioWriterInput.data().readyForMoreMediaData) {
- [self updateDuration:CMSampleBufferGetPresentationTimeStamp(sampleBuffer)];
- [m_audioWriterInput appendSampleBuffer:sampleBuffer];
- }
- }
-
- CFRelease(sampleBuffer);
-}
-
-- (void)captureOutput:(AVCaptureOutput *)captureOutput
- didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
- fromConnection:(AVCaptureConnection *)connection
-{
- Q_UNUSED(connection);
-
- if (m_state.loadAcquire() != WriterStateActive)
- return;
-
- if (!CMSampleBufferDataIsReady(sampleBuffer)) {
- qDebugCamera() << Q_FUNC_INFO << "sample buffer is not ready, skipping.";
- return;
- }
-
- CFRetain(sampleBuffer);
-
- if (captureOutput != m_audioOutput.data()) {
- if (m_state.loadRelaxed() != WriterStateActive) {
- CFRelease(sampleBuffer);
- return;
- }
- // Find renderercontrol's delegate and invoke its method to
- // show updated viewfinder's frame.
- if (m_service && m_service->videoOutput()) {
- NSObject<AVCaptureVideoDataOutputSampleBufferDelegate> *vfDelegate =
- (NSObject<AVCaptureVideoDataOutputSampleBufferDelegate> *)m_service->videoOutput()->captureDelegate();
- if (vfDelegate)
- [vfDelegate captureOutput:nil didOutputSampleBuffer:sampleBuffer fromConnection:nil];
- }
-
- dispatch_async(m_writerQueue, ^{
- [self writeVideoSampleBuffer:sampleBuffer];
- });
- } else {
- dispatch_async(m_writerQueue, ^{
- [self writeAudioSampleBuffer:sampleBuffer];
- });
- }
-}
-
-- (bool)addAudioCapture
-{
- Q_ASSERT(m_service && m_service->session() && m_service->session()->captureSession());
-
- if (!m_service->audioInputSelectorControl())
- return false;
-
- AVCaptureSession *captureSession = m_service->session()->captureSession();
-
- m_audioCaptureDevice = m_service->audioInputSelectorControl()->createCaptureDevice();
- if (!m_audioCaptureDevice) {
- qWarning() << Q_FUNC_INFO << "no audio input device available";
- return false;
- } else {
- NSError *error = nil;
- m_audioInput.reset([[AVCaptureDeviceInput deviceInputWithDevice:m_audioCaptureDevice error:&error] retain]);
-
- if (!m_audioInput || error) {
- qWarning() << Q_FUNC_INFO << "failed to create audio device input";
- m_audioCaptureDevice = 0;
- m_audioInput.reset();
- return false;
- } else if (![captureSession canAddInput:m_audioInput]) {
- qWarning() << Q_FUNC_INFO << "could not connect the audio input";
- m_audioCaptureDevice = 0;
- m_audioInput.reset();
- return false;
- } else {
- [captureSession addInput:m_audioInput];
- }
- }
-
-
- m_audioOutput.reset([[AVCaptureAudioDataOutput alloc] init]);
- if (m_audioOutput.data() && [captureSession canAddOutput:m_audioOutput]) {
- [captureSession addOutput:m_audioOutput];
- } else {
- qDebugCamera() << Q_FUNC_INFO << "failed to add audio output";
- [captureSession removeInput:m_audioInput];
- m_audioCaptureDevice = 0;
- m_audioInput.reset();
- m_audioOutput.reset();
- return false;
- }
-
- return true;
-}
-
-- (bool)addWriterInputs
-{
- Q_ASSERT(m_service && m_service->videoOutput()
- && m_service->videoOutput()->videoDataOutput());
- Q_ASSERT(m_assetWriter.data());
-
- m_cameraWriterInput.reset([[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeVideo
- outputSettings:m_videoSettings
- sourceFormatHint:m_service->session()->videoCaptureDevice().activeFormat.formatDescription]);
- if (!m_cameraWriterInput) {
- qDebugCamera() << Q_FUNC_INFO << "failed to create camera writer input";
- return false;
- }
-
- if ([m_assetWriter canAddInput:m_cameraWriterInput]) {
- [m_assetWriter addInput:m_cameraWriterInput];
- } else {
- qDebugCamera() << Q_FUNC_INFO << "failed to add camera writer input";
- m_cameraWriterInput.reset();
- return false;
- }
-
- m_cameraWriterInput.data().expectsMediaDataInRealTime = YES;
-
- if (m_audioOutput.data()) {
- CMFormatDescriptionRef sourceFormat = m_audioCaptureDevice ? m_audioCaptureDevice.activeFormat.formatDescription : 0;
- m_audioWriterInput.reset([[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeAudio
- outputSettings:m_audioSettings
- sourceFormatHint:sourceFormat]);
- if (!m_audioWriterInput) {
- qDebugCamera() << Q_FUNC_INFO << "failed to create audio writer input";
- // But we still can record video.
- } else if ([m_assetWriter canAddInput:m_audioWriterInput]) {
- [m_assetWriter addInput:m_audioWriterInput];
- m_audioWriterInput.data().expectsMediaDataInRealTime = YES;
- } else {
- qDebugCamera() << Q_FUNC_INFO << "failed to add audio writer input";
- m_audioWriterInput.reset();
- // We can (still) write video though ...
- }
- }
-
- return true;
-}
-
-- (void)setQueues
-{
- Q_ASSERT(m_service && m_service->videoOutput() && m_service->videoOutput()->videoDataOutput());
- Q_ASSERT(m_videoQueue);
-
- [m_service->videoOutput()->videoDataOutput() setSampleBufferDelegate:self queue:m_videoQueue];
-
- if (m_audioOutput.data()) {
- Q_ASSERT(m_audioQueue);
- [m_audioOutput setSampleBufferDelegate:self queue:m_audioQueue];
- }
-}
-
-- (void)updateDuration:(CMTime)newTimeStamp
-{
- Q_ASSERT(CMTimeCompare(m_startTime, kCMTimeInvalid));
- Q_ASSERT(CMTimeCompare(m_lastTimeStamp, kCMTimeInvalid));
- if (CMTimeCompare(newTimeStamp, m_lastTimeStamp) > 0) {
-
- const CMTime duration = CMTimeSubtract(newTimeStamp, m_startTime);
- if (!CMTimeCompare(duration, kCMTimeInvalid))
- return;
-
- m_durationInMs.storeRelease(CMTimeGetSeconds(duration) * 1000);
- m_lastTimeStamp = newTimeStamp;
- }
-}
-
-- (qint64)durationInMs
-{
- return m_durationInMs.loadAcquire();
-}
-
-@end
diff --git a/src/plugins/avfoundation/camera/avfmediacontainercontrol.h b/src/plugins/avfoundation/camera/avfmediacontainercontrol.h
deleted file mode 100644
index e43e70baf..000000000
--- a/src/plugins/avfoundation/camera/avfmediacontainercontrol.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFMEDIACONTAINERCONTROL_H
-#define AVFMEDIACONTAINERCONTROL_H
-
-#include <qmediacontainercontrol.h>
-
-@class NSString;
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraService;
-
-class AVFMediaContainerControl : public QMediaContainerControl
-{
-public:
- explicit AVFMediaContainerControl(AVFCameraService *service);
-
- QStringList supportedContainers() const override;
- QString containerFormat() const override;
- void setContainerFormat(const QString &format) override;
- QString containerDescription(const QString &formatMimeType) const override;
-
- NSString *fileType() const;
-
-private:
- QString m_format;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFMEDIACONTAINERCONTROL_H
diff --git a/src/plugins/avfoundation/camera/avfmediacontainercontrol.mm b/src/plugins/avfoundation/camera/avfmediacontainercontrol.mm
deleted file mode 100644
index 89fb50a19..000000000
--- a/src/plugins/avfoundation/camera/avfmediacontainercontrol.mm
+++ /dev/null
@@ -1,112 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfmediacontainercontrol.h"
-
-#include <AVFoundation/AVMediaFormat.h>
-
-QT_BEGIN_NAMESPACE
-
-struct ContainerInfo
-{
- QString description;
- NSString *fileType;
-
- ContainerInfo() : fileType(nil) { }
- ContainerInfo(const QString &desc, NSString *type)
- : description(desc), fileType(type)
- { }
-};
-
-typedef QMap<QString, ContainerInfo> SupportedContainers;
-Q_GLOBAL_STATIC(SupportedContainers, containers);
-
-AVFMediaContainerControl::AVFMediaContainerControl(AVFCameraService *)
- : QMediaContainerControl()
- , m_format(QStringLiteral("mov")) // .mov is the default container format on Apple platforms
-{
- if (containers->isEmpty()) {
- containers->insert(QStringLiteral("mov"),
- ContainerInfo(QStringLiteral("QuickTime movie file format"),
- AVFileTypeQuickTimeMovie));
- containers->insert(QStringLiteral("mp4"),
- ContainerInfo(QStringLiteral("MPEG-4 file format"),
- AVFileTypeMPEG4));
- containers->insert(QStringLiteral("m4v"),
- ContainerInfo(QStringLiteral("iTunes video file format"),
- AVFileTypeAppleM4V));
-#ifdef Q_OS_IOS
- containers->insert(QStringLiteral("3gp"),
- ContainerInfo(QStringLiteral("3GPP file format"),
- AVFileType3GPP));
-#endif
- }
-}
-
-QStringList AVFMediaContainerControl::supportedContainers() const
-{
- return containers->keys();
-}
-
-QString AVFMediaContainerControl::containerFormat() const
-{
- return m_format;
-}
-
-void AVFMediaContainerControl::setContainerFormat(const QString &format)
-{
- if (!containers->contains(format)) {
- qWarning("Unsupported container format: '%s'", format.toLocal8Bit().constData());
- return;
- }
-
- m_format = format;
-}
-
-QString AVFMediaContainerControl::containerDescription(const QString &formatMimeType) const
-{
- return containers->value(formatMimeType).description;
-}
-
-NSString *AVFMediaContainerControl::fileType() const
-{
- return containers->value(m_format).fileType;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/avfoundation/camera/avfmediarecordercontrol.h b/src/plugins/avfoundation/camera/avfmediarecordercontrol.h
deleted file mode 100644
index fbba5eca4..000000000
--- a/src/plugins/avfoundation/camera/avfmediarecordercontrol.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFMEDIARECORDERCONTROL_H
-#define AVFMEDIARECORDERCONTROL_H
-
-#include <QtCore/qurl.h>
-#include <QtMultimedia/qmediarecordercontrol.h>
-
-#import <AVFoundation/AVFoundation.h>
-#include "avfstoragelocation.h"
-#include "avfcamerautility.h"
-
-@class AVFMediaRecorderDelegate;
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraSession;
-class AVFCameraControl;
-class AVFAudioInputSelectorControl;
-class AVFCameraService;
-
-class AVFMediaRecorderControl : public QMediaRecorderControl
-{
-Q_OBJECT
-public:
- AVFMediaRecorderControl(AVFCameraService *service, QObject *parent = nullptr);
- ~AVFMediaRecorderControl();
-
- QUrl outputLocation() const override;
- bool setOutputLocation(const QUrl &location) override;
-
- QMediaRecorder::State state() const override;
- QMediaRecorder::Status status() const override;
-
- qint64 duration() const override;
-
- bool isMuted() const override;
- qreal volume() const override;
-
- void applySettings() override;
- void unapplySettings();
-
-public Q_SLOTS:
- void setState(QMediaRecorder::State state) override;
- void setMuted(bool muted) override;
- void setVolume(qreal volume) override;
-
- void handleRecordingStarted();
- void handleRecordingFinished();
- void handleRecordingFailed(const QString &message);
-
-private Q_SLOTS:
- void setupSessionForCapture();
- void updateStatus();
-
-private:
- AVFCameraService *m_service;
- AVFCameraControl *m_cameraControl;
- AVFAudioInputSelectorControl *m_audioInputControl;
- AVFCameraSession *m_session;
-
- bool m_connected;
- QUrl m_outputLocation;
- QMediaRecorder::State m_state;
- QMediaRecorder::Status m_lastStatus;
-
- bool m_recordingStarted;
- bool m_recordingFinished;
-
- bool m_muted;
- qreal m_volume;
-
- AVCaptureDeviceInput *m_audioInput;
- AVCaptureMovieFileOutput *m_movieOutput;
- AVFMediaRecorderDelegate *m_recorderDelagate;
- AVFStorageLocation m_storageLocation;
-
- AVFPSRange m_restoreFPS;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfmediarecordercontrol.mm b/src/plugins/avfoundation/camera/avfmediarecordercontrol.mm
deleted file mode 100644
index 7296b7dc1..000000000
--- a/src/plugins/avfoundation/camera/avfmediarecordercontrol.mm
+++ /dev/null
@@ -1,430 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfcameradebug.h"
-#include "avfmediarecordercontrol.h"
-#include "avfcamerasession.h"
-#include "avfcameraservice.h"
-#include "avfcameracontrol.h"
-#include "avfaudioinputselectorcontrol.h"
-#include "avfaudioencodersettingscontrol.h"
-#include "avfvideoencodersettingscontrol.h"
-#include "avfmediacontainercontrol.h"
-
-#include <QtCore/qurl.h>
-#include <QtCore/qfileinfo.h>
-#include <QtMultimedia/qcameracontrol.h>
-
-
-QT_USE_NAMESPACE
-
-@interface AVFMediaRecorderDelegate : NSObject <AVCaptureFileOutputRecordingDelegate>
-{
-@private
- AVFMediaRecorderControl *m_recorder;
-}
-
-- (AVFMediaRecorderDelegate *) initWithRecorder:(AVFMediaRecorderControl*)recorder;
-
-- (void) captureOutput:(AVCaptureFileOutput *)captureOutput
- didStartRecordingToOutputFileAtURL:(NSURL *)fileURL
- fromConnections:(NSArray *)connections;
-
-- (void) captureOutput:(AVCaptureFileOutput *)captureOutput
- didFinishRecordingToOutputFileAtURL:(NSURL *)fileURL
- fromConnections:(NSArray *)connections
- error:(NSError *)error;
-@end
-
-@implementation AVFMediaRecorderDelegate
-
-- (AVFMediaRecorderDelegate *) initWithRecorder:(AVFMediaRecorderControl*)recorder
-{
- if (!(self = [super init]))
- return nil;
-
- self->m_recorder = recorder;
- return self;
-}
-
-- (void) captureOutput:(AVCaptureFileOutput *)captureOutput
- didStartRecordingToOutputFileAtURL:(NSURL *)fileURL
- fromConnections:(NSArray *)connections
-{
- Q_UNUSED(captureOutput);
- Q_UNUSED(fileURL);
- Q_UNUSED(connections);
-
- QMetaObject::invokeMethod(m_recorder, "handleRecordingStarted", Qt::QueuedConnection);
-}
-
-- (void) captureOutput:(AVCaptureFileOutput *)captureOutput
- didFinishRecordingToOutputFileAtURL:(NSURL *)fileURL
- fromConnections:(NSArray *)connections
- error:(NSError *)error
-{
- Q_UNUSED(captureOutput);
- Q_UNUSED(fileURL);
- Q_UNUSED(connections);
-
- if (error) {
- QStringList messageParts;
- messageParts << QString::fromUtf8([[error localizedDescription] UTF8String]);
- messageParts << QString::fromUtf8([[error localizedFailureReason] UTF8String]);
- messageParts << QString::fromUtf8([[error localizedRecoverySuggestion] UTF8String]);
-
- QString errorMessage = messageParts.join(" ");
-
- QMetaObject::invokeMethod(m_recorder, "handleRecordingFailed", Qt::QueuedConnection,
- Q_ARG(QString, errorMessage));
- } else {
- QMetaObject::invokeMethod(m_recorder, "handleRecordingFinished", Qt::QueuedConnection);
- }
-}
-
-@end
-
-
-AVFMediaRecorderControl::AVFMediaRecorderControl(AVFCameraService *service, QObject *parent)
- : QMediaRecorderControl(parent)
- , m_service(service)
- , m_cameraControl(service->cameraControl())
- , m_audioInputControl(service->audioInputSelectorControl())
- , m_session(service->session())
- , m_connected(false)
- , m_state(QMediaRecorder::StoppedState)
- , m_lastStatus(QMediaRecorder::UnloadedStatus)
- , m_recordingStarted(false)
- , m_recordingFinished(false)
- , m_muted(false)
- , m_volume(1.0)
- , m_audioInput(nil)
- , m_restoreFPS(-1, -1)
-{
- m_movieOutput = [[AVCaptureMovieFileOutput alloc] init];
- m_recorderDelagate = [[AVFMediaRecorderDelegate alloc] initWithRecorder:this];
-
- connect(m_cameraControl, SIGNAL(stateChanged(QCamera::State)), SLOT(updateStatus()));
- connect(m_cameraControl, SIGNAL(statusChanged(QCamera::Status)), SLOT(updateStatus()));
- connect(m_cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureModes)), SLOT(setupSessionForCapture()));
- connect(m_session, SIGNAL(readyToConfigureConnections()), SLOT(setupSessionForCapture()));
- connect(m_session, SIGNAL(stateChanged(QCamera::State)), SLOT(setupSessionForCapture()));
-}
-
-AVFMediaRecorderControl::~AVFMediaRecorderControl()
-{
- if (m_movieOutput) {
- [m_session->captureSession() removeOutput:m_movieOutput];
- [m_movieOutput release];
- }
-
- if (m_audioInput) {
- [m_session->captureSession() removeInput:m_audioInput];
- [m_audioInput release];
- }
-
- [m_recorderDelagate release];
-}
-
-QUrl AVFMediaRecorderControl::outputLocation() const
-{
- return m_outputLocation;
-}
-
-bool AVFMediaRecorderControl::setOutputLocation(const QUrl &location)
-{
- m_outputLocation = location;
- return location.scheme() == QLatin1String("file") || location.scheme().isEmpty();
-}
-
-QMediaRecorder::State AVFMediaRecorderControl::state() const
-{
- return m_state;
-}
-
-QMediaRecorder::Status AVFMediaRecorderControl::status() const
-{
- QMediaRecorder::Status status = m_lastStatus;
- //bool videoEnabled = m_cameraControl->captureMode().testFlag(QCamera::CaptureVideo);
-
- if (m_cameraControl->status() == QCamera::ActiveStatus && m_connected) {
- if (m_state == QMediaRecorder::StoppedState) {
- if (m_recordingStarted && !m_recordingFinished)
- status = QMediaRecorder::FinalizingStatus;
- else
- status = QMediaRecorder::LoadedStatus;
- } else {
- status = m_recordingStarted ? QMediaRecorder::RecordingStatus :
- QMediaRecorder::StartingStatus;
- }
- } else {
- //camera not started yet
- status = m_cameraControl->state() == QCamera::ActiveState && m_connected ?
- QMediaRecorder::LoadingStatus:
- QMediaRecorder::UnloadedStatus;
- }
-
- return status;
-}
-
-void AVFMediaRecorderControl::updateStatus()
-{
- QMediaRecorder::Status newStatus = status();
-
- if (m_lastStatus != newStatus) {
- qDebugCamera() << "Camera recorder status changed: " << m_lastStatus << " -> " << newStatus;
- m_lastStatus = newStatus;
- Q_EMIT statusChanged(m_lastStatus);
- }
-}
-
-
-qint64 AVFMediaRecorderControl::duration() const
-{
- if (!m_movieOutput)
- return 0;
-
- return qint64(CMTimeGetSeconds(m_movieOutput.recordedDuration) * 1000);
-}
-
-bool AVFMediaRecorderControl::isMuted() const
-{
- return m_muted;
-}
-
-qreal AVFMediaRecorderControl::volume() const
-{
- return m_volume;
-}
-
-void AVFMediaRecorderControl::applySettings()
-{
- if (m_state != QMediaRecorder::StoppedState
- || (m_session->state() != QCamera::ActiveState && m_session->state() != QCamera::LoadedState)
- || !m_service->cameraControl()->captureMode().testFlag(QCamera::CaptureVideo)) {
- return;
- }
-
- // Configure audio settings
- [m_movieOutput setOutputSettings:m_service->audioEncoderSettingsControl()->applySettings()
- forConnection:[m_movieOutput connectionWithMediaType:AVMediaTypeAudio]];
-
- // Configure video settings
- AVCaptureConnection *videoConnection = [m_movieOutput connectionWithMediaType:AVMediaTypeVideo];
- NSDictionary *videoSettings = m_service->videoEncoderSettingsControl()->applySettings(videoConnection);
-
- const AVFConfigurationLock lock(m_session->videoCaptureDevice()); // prevents activeFormat from being overridden
-
- [m_movieOutput setOutputSettings:videoSettings forConnection:videoConnection];
-}
-
-void AVFMediaRecorderControl::unapplySettings()
-{
- m_service->audioEncoderSettingsControl()->unapplySettings();
- m_service->videoEncoderSettingsControl()->unapplySettings([m_movieOutput connectionWithMediaType:AVMediaTypeVideo]);
-}
-
-void AVFMediaRecorderControl::setState(QMediaRecorder::State state)
-{
- if (m_state == state)
- return;
-
- qDebugCamera() << Q_FUNC_INFO << m_state << " -> " << state;
-
- switch (state) {
- case QMediaRecorder::RecordingState:
- {
- if (m_connected) {
- QString outputLocationPath = m_outputLocation.scheme() == QLatin1String("file") ?
- m_outputLocation.path() : m_outputLocation.toString();
-
- QString extension = m_service->mediaContainerControl()->containerFormat();
-
- QUrl actualLocation = QUrl::fromLocalFile(
- m_storageLocation.generateFileName(outputLocationPath,
- QCamera::CaptureVideo,
- QLatin1String("clip_"),
- extension));
-
- qDebugCamera() << "Video capture location:" << actualLocation.toString();
-
- applySettings();
-
- [m_movieOutput startRecordingToOutputFileURL:actualLocation.toNSURL()
- recordingDelegate:m_recorderDelagate];
-
- m_state = QMediaRecorder::RecordingState;
- m_recordingStarted = false;
- m_recordingFinished = false;
-
- Q_EMIT actualLocationChanged(actualLocation);
- updateStatus();
- Q_EMIT stateChanged(m_state);
- } else {
- Q_EMIT error(QMediaRecorder::FormatError, tr("Recorder not configured"));
- }
-
- } break;
- case QMediaRecorder::PausedState:
- {
- Q_EMIT error(QMediaRecorder::FormatError, tr("Recording pause not supported"));
- return;
- } break;
- case QMediaRecorder::StoppedState:
- {
- m_lastStatus = QMediaRecorder::FinalizingStatus;
- Q_EMIT statusChanged(m_lastStatus);
- [m_movieOutput stopRecording];
- unapplySettings();
- }
- }
-}
-
-void AVFMediaRecorderControl::setMuted(bool muted)
-{
- if (m_muted != muted) {
- m_muted = muted;
- Q_EMIT mutedChanged(muted);
- }
-}
-
-void AVFMediaRecorderControl::setVolume(qreal volume)
-{
- if (m_volume != volume) {
- m_volume = volume;
- Q_EMIT volumeChanged(volume);
- }
-}
-
-void AVFMediaRecorderControl::handleRecordingStarted()
-{
- m_recordingStarted = true;
- updateStatus();
-}
-
-void AVFMediaRecorderControl::handleRecordingFinished()
-{
- m_recordingFinished = true;
- if (m_state != QMediaRecorder::StoppedState) {
- m_state = QMediaRecorder::StoppedState;
- Q_EMIT stateChanged(m_state);
- }
- updateStatus();
-}
-
-void AVFMediaRecorderControl::handleRecordingFailed(const QString &message)
-{
- m_recordingFinished = true;
- if (m_state != QMediaRecorder::StoppedState) {
- m_state = QMediaRecorder::StoppedState;
- Q_EMIT stateChanged(m_state);
- }
- updateStatus();
-
- Q_EMIT error(QMediaRecorder::ResourceError, message);
-}
-
-void AVFMediaRecorderControl::setupSessionForCapture()
-{
- if (!m_session->videoCaptureDevice())
- return;
-
- //adding movie output causes high CPU usage even when while recording is not active,
- //connect it only while video capture mode is enabled.
- // Similarly, connect the Audio input only in that mode, since it's only necessary
- // when recording anyway. Adding an Audio input will trigger the microphone permission
- // request on iOS, but it shoudn't do so until we actually try to record.
- AVCaptureSession *captureSession = m_session->captureSession();
-
- if (!m_connected
- && m_cameraControl->captureMode().testFlag(QCamera::CaptureVideo)
- && m_session->state() != QCamera::UnloadedState) {
-
- // Lock the video capture device to make sure the active format is not reset
- const AVFConfigurationLock lock(m_session->videoCaptureDevice());
-
- // Add audio input
- // Allow recording even if something wrong happens with the audio input initialization
- AVCaptureDevice *audioDevice = m_audioInputControl->createCaptureDevice();
- if (!audioDevice) {
- qWarning("No audio input device available");
- } else {
- NSError *error = nil;
- m_audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error];
-
- if (!m_audioInput) {
- qWarning() << "Failed to create audio device input";
- } else if (![captureSession canAddInput:m_audioInput]) {
- qWarning() << "Could not connect the audio input";
- m_audioInput = nullptr;
- } else {
- [m_audioInput retain];
- [captureSession addInput:m_audioInput];
- }
- }
-
- if ([captureSession canAddOutput:m_movieOutput]) {
- [captureSession addOutput:m_movieOutput];
- m_connected = true;
- } else {
- Q_EMIT error(QMediaRecorder::ResourceError, tr("Could not connect the video recorder"));
- qWarning() << "Could not connect the video recorder";
- }
- } else if (m_connected
- && (!m_cameraControl->captureMode().testFlag(QCamera::CaptureVideo)
- || m_session->state() == QCamera::UnloadedState)) {
-
- // Lock the video capture device to make sure the active format is not reset
- const AVFConfigurationLock lock(m_session->videoCaptureDevice());
-
- [captureSession removeOutput:m_movieOutput];
-
- if (m_audioInput) {
- [captureSession removeInput:m_audioInput];
- [m_audioInput release];
- m_audioInput = nil;
- }
-
- m_connected = false;
- }
-
- updateStatus();
-}
-
-#include "moc_avfmediarecordercontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.h b/src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.h
deleted file mode 100644
index 9afb1068d..000000000
--- a/src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFMEDIARECORDERCONTROL_IOS_H
-#define AVFMEDIARECORDERCONTROL_IOS_H
-
-#include "avfmediaassetwriter.h"
-#include "avfstoragelocation.h"
-#include "avfcamerautility.h"
-
-#include <QtMultimedia/qmediarecordercontrol.h>
-#include <private/qvideooutputorientationhandler_p.h>
-
-#include <QtCore/qglobal.h>
-#include <QtCore/qurl.h>
-
-#include <AVFoundation/AVFoundation.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraService;
-class QString;
-class QUrl;
-
-class AVFMediaRecorderControlIOS : public QMediaRecorderControl
-{
- Q_OBJECT
-public:
- AVFMediaRecorderControlIOS(AVFCameraService *service, QObject *parent = nullptr);
- ~AVFMediaRecorderControlIOS() override;
-
- QUrl outputLocation() const override;
- bool setOutputLocation(const QUrl &location) override;
-
- QMediaRecorder::State state() const override;
- QMediaRecorder::Status status() const override;
-
- qint64 duration() const override;
-
- bool isMuted() const override;
- qreal volume() const override;
-
- void applySettings() override;
- void unapplySettings();
-
-public Q_SLOTS:
- void setState(QMediaRecorder::State state) override;
- void setMuted(bool muted) override;
- void setVolume(qreal volume) override;
-
-private:
-
- Q_INVOKABLE void assetWriterStarted();
- Q_INVOKABLE void assetWriterFinished();
-
-private Q_SLOTS:
- void captureModeChanged(QCamera::CaptureModes);
- void cameraStatusChanged(QCamera::Status newStatus);
-
-private:
- void stopWriter();
-
- AVFCameraService *m_service;
- AVFScopedPointer<QT_MANGLE_NAMESPACE(AVFMediaAssetWriter)> m_writer;
-
- QUrl m_outputLocation;
- AVFStorageLocation m_storageLocation;
-
- QMediaRecorder::State m_state;
- QMediaRecorder::Status m_lastStatus;
-
- NSDictionary *m_audioSettings;
- NSDictionary *m_videoSettings;
- QVideoOutputOrientationHandler m_orientationHandler;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFMEDIARECORDERCONTROL_IOS_H
diff --git a/src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm b/src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm
deleted file mode 100644
index 33064827d..000000000
--- a/src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm
+++ /dev/null
@@ -1,414 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include "avfmediarecordercontrol_ios.h"
-#include "avfcamerarenderercontrol.h"
-#include "avfcamerasession.h"
-#include "avfcameracontrol.h"
-#include "avfcameraservice.h"
-#include "avfcameradebug.h"
-#include "avfaudioencodersettingscontrol.h"
-#include "avfvideoencodersettingscontrol.h"
-#include "avfmediacontainercontrol.h"
-#include "avfcamerautility.h"
-
-#include <QtCore/qmath.h>
-#include <QtCore/qdebug.h>
-
-QT_USE_NAMESPACE
-
-namespace {
-
-bool qt_is_writable_file_URL(NSURL *fileURL)
-{
- Q_ASSERT(fileURL);
-
- if (![fileURL isFileURL])
- return false;
-
- if (NSString *path = [[fileURL path] stringByExpandingTildeInPath]) {
- return [[NSFileManager defaultManager]
- isWritableFileAtPath:[path stringByDeletingLastPathComponent]];
- }
-
- return false;
-}
-
-bool qt_file_exists(NSURL *fileURL)
-{
- Q_ASSERT(fileURL);
-
- if (NSString *path = [[fileURL path] stringByExpandingTildeInPath])
- return [[NSFileManager defaultManager] fileExistsAtPath:path];
-
- return false;
-}
-
-}
-
-AVFMediaRecorderControlIOS::AVFMediaRecorderControlIOS(AVFCameraService *service, QObject *parent)
- : QMediaRecorderControl(parent)
- , m_service(service)
- , m_state(QMediaRecorder::StoppedState)
- , m_lastStatus(QMediaRecorder::UnloadedStatus)
- , m_audioSettings(nil)
- , m_videoSettings(nil)
-{
- Q_ASSERT(service);
-
- m_writer.reset([[QT_MANGLE_NAMESPACE(AVFMediaAssetWriter) alloc] initWithDelegate:this]);
- if (!m_writer) {
- qDebugCamera() << Q_FUNC_INFO << "failed to create an asset writer";
- return;
- }
-
- AVFCameraControl *cameraControl = m_service->cameraControl();
- if (!cameraControl) {
- qDebugCamera() << Q_FUNC_INFO << "camera control is nil";
- return;
- }
-
- connect(cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureModes)),
- SLOT(captureModeChanged(QCamera::CaptureModes)));
- connect(cameraControl, SIGNAL(statusChanged(QCamera::Status)),
- SLOT(cameraStatusChanged(QCamera::Status)));
-}
-
-AVFMediaRecorderControlIOS::~AVFMediaRecorderControlIOS()
-{
- [m_writer abort];
-
- if (m_audioSettings)
- [m_audioSettings release];
- if (m_videoSettings)
- [m_videoSettings release];
-}
-
-QUrl AVFMediaRecorderControlIOS::outputLocation() const
-{
- return m_outputLocation;
-}
-
-bool AVFMediaRecorderControlIOS::setOutputLocation(const QUrl &location)
-{
- m_outputLocation = location;
- return location.scheme() == QLatin1String("file") || location.scheme().isEmpty();
-}
-
-QMediaRecorder::State AVFMediaRecorderControlIOS::state() const
-{
- return m_state;
-}
-
-QMediaRecorder::Status AVFMediaRecorderControlIOS::status() const
-{
- return m_lastStatus;
-}
-
-qint64 AVFMediaRecorderControlIOS::duration() const
-{
- return m_writer.data().durationInMs;
-}
-
-bool AVFMediaRecorderControlIOS::isMuted() const
-{
- return false;
-}
-
-qreal AVFMediaRecorderControlIOS::volume() const
-{
- return 1.;
-}
-
-void AVFMediaRecorderControlIOS::applySettings()
-{
- AVFCameraSession *session = m_service->session();
- if (!session)
- return;
-
- if (m_state != QMediaRecorder::StoppedState
- || (session->state() != QCamera::ActiveState && session->state() != QCamera::LoadedState)
- || !m_service->cameraControl()->captureMode().testFlag(QCamera::CaptureVideo)) {
- return;
- }
-
- // audio settings
- m_audioSettings = m_service->audioEncoderSettingsControl()->applySettings();
- if (m_audioSettings)
- [m_audioSettings retain];
-
- // video settings
- AVCaptureConnection *conn = [m_service->videoOutput()->videoDataOutput() connectionWithMediaType:AVMediaTypeVideo];
- m_videoSettings = m_service->videoEncoderSettingsControl()->applySettings(conn);
- if (m_videoSettings)
- [m_videoSettings retain];
-}
-
-void AVFMediaRecorderControlIOS::unapplySettings()
-{
- m_service->audioEncoderSettingsControl()->unapplySettings();
-
- AVCaptureConnection *conn = [m_service->videoOutput()->videoDataOutput() connectionWithMediaType:AVMediaTypeVideo];
- m_service->videoEncoderSettingsControl()->unapplySettings(conn);
-
- if (m_audioSettings) {
- [m_audioSettings release];
- m_audioSettings = nil;
- }
- if (m_videoSettings) {
- [m_videoSettings release];
- m_videoSettings = nil;
- }
-}
-
-void AVFMediaRecorderControlIOS::setState(QMediaRecorder::State state)
-{
- Q_ASSERT(m_service->session()
- && m_service->session()->captureSession());
-
- if (!m_writer) {
- qDebugCamera() << Q_FUNC_INFO << "Invalid recorder";
- return;
- }
-
- if (state == m_state)
- return;
-
- switch (state) {
- case QMediaRecorder::RecordingState:
- {
- AVFCameraControl *cameraControl = m_service->cameraControl();
- Q_ASSERT(cameraControl);
-
- if (!(cameraControl->captureMode() & QCamera::CaptureVideo)) {
- qDebugCamera() << Q_FUNC_INFO << "wrong capture mode, CaptureVideo expected";
- Q_EMIT error(QMediaRecorder::ResourceError, tr("Failed to start recording"));
- return;
- }
-
- if (cameraControl->status() != QCamera::ActiveStatus) {
- qDebugCamera() << Q_FUNC_INFO << "can not start record while camera is not active";
- Q_EMIT error(QMediaRecorder::ResourceError, tr("Failed to start recording"));
- return;
- }
-
- const QString path(m_outputLocation.scheme() == QLatin1String("file") ?
- m_outputLocation.path() : m_outputLocation.toString());
- const QUrl fileURL(QUrl::fromLocalFile(m_storageLocation.generateFileName(path, QCamera::CaptureVideo,
- QLatin1String("clip_"),
- m_service->mediaContainerControl()->containerFormat())));
-
- NSURL *nsFileURL = fileURL.toNSURL();
- if (!nsFileURL) {
- qWarning() << Q_FUNC_INFO << "invalid output URL:" << fileURL;
- Q_EMIT error(QMediaRecorder::ResourceError, tr("Invalid output file URL"));
- return;
- }
- if (!qt_is_writable_file_URL(nsFileURL)) {
- qWarning() << Q_FUNC_INFO << "invalid output URL:" << fileURL
- << "(the location is not writable)";
- Q_EMIT error(QMediaRecorder::ResourceError, tr("Non-writeable file location"));
- return;
- }
- if (qt_file_exists(nsFileURL)) {
- // We test for/handle this error here since AWAssetWriter will raise an
- // Objective-C exception, which is not good at all.
- qWarning() << Q_FUNC_INFO << "invalid output URL:" << fileURL
- << "(file already exists)";
- Q_EMIT error(QMediaRecorder::ResourceError, tr("File already exists"));
- return;
- }
-
- AVCaptureSession *session = m_service->session()->captureSession();
- // We stop session now so that no more frames for renderer's queue
- // generated, will restart in assetWriterStarted.
- [session stopRunning];
-
- applySettings();
-
- // Make sure the video is recorded in device orientation.
- // The top of the video will match the side of the device which is on top
- // when recording starts (regardless of the UI orientation).
- AVFCameraInfo cameraInfo = m_service->session()->activeCameraInfo();
- int screenOrientation = 360 - m_orientationHandler.currentOrientation();
- float rotation = 0;
- if (cameraInfo.position == QCamera::FrontFace)
- rotation = (screenOrientation + cameraInfo.orientation) % 360;
- else
- rotation = (screenOrientation + (360 - cameraInfo.orientation)) % 360;
-
- if ([m_writer setupWithFileURL:nsFileURL
- cameraService:m_service
- audioSettings:m_audioSettings
- videoSettings:m_videoSettings
- transform:CGAffineTransformMakeRotation(qDegreesToRadians(rotation))]) {
-
- m_state = QMediaRecorder::RecordingState;
- m_lastStatus = QMediaRecorder::StartingStatus;
-
- Q_EMIT actualLocationChanged(fileURL);
- Q_EMIT stateChanged(m_state);
- Q_EMIT statusChanged(m_lastStatus);
-
- // Apple recommends to call startRunning and do all
- // setup on a special queue, and that's what we had
- // initially (dispatch_async to writerQueue). Unfortunately,
- // writer's queue is not the only queue/thread that can
- // access/modify the session, and as a result we have
- // all possible data/race-conditions with Obj-C exceptions
- // at best and something worse in general.
- // Now we try to only modify session on the same thread.
- [m_writer start];
- } else {
- [session startRunning];
- Q_EMIT error(QMediaRecorder::FormatError, tr("Failed to start recording"));
- }
- } break;
- case QMediaRecorder::PausedState:
- {
- Q_EMIT error(QMediaRecorder::FormatError, tr("Recording pause not supported"));
- return;
- } break;
- case QMediaRecorder::StoppedState:
- {
- // Do not check the camera status, we can stop if we started.
- stopWriter();
- }
- }
-}
-
-void AVFMediaRecorderControlIOS::setMuted(bool muted)
-{
- Q_UNUSED(muted);
- qDebugCamera() << Q_FUNC_INFO << "not implemented";
-}
-
-void AVFMediaRecorderControlIOS::setVolume(qreal volume)
-{
- Q_UNUSED(volume);
- qDebugCamera() << Q_FUNC_INFO << "not implemented";
-}
-
-void AVFMediaRecorderControlIOS::assetWriterStarted()
-{
- m_lastStatus = QMediaRecorder::RecordingStatus;
- Q_EMIT statusChanged(QMediaRecorder::RecordingStatus);
-}
-
-void AVFMediaRecorderControlIOS::assetWriterFinished()
-{
- AVFCameraControl *cameraControl = m_service->cameraControl();
- Q_ASSERT(cameraControl);
-
- const QMediaRecorder::Status lastStatus = m_lastStatus;
- const QMediaRecorder::State lastState = m_state;
- if (cameraControl->captureMode() & QCamera::CaptureVideo)
- m_lastStatus = QMediaRecorder::LoadedStatus;
- else
- m_lastStatus = QMediaRecorder::UnloadedStatus;
-
- unapplySettings();
-
- m_service->videoOutput()->resetCaptureDelegate();
- [m_service->session()->captureSession() startRunning];
- m_state = QMediaRecorder::StoppedState;
- if (m_lastStatus != lastStatus)
- Q_EMIT statusChanged(m_lastStatus);
- if (m_state != lastState)
- Q_EMIT stateChanged(m_state);
-}
-
-void AVFMediaRecorderControlIOS::captureModeChanged(QCamera::CaptureModes newMode)
-{
- AVFCameraControl *cameraControl = m_service->cameraControl();
- Q_ASSERT(cameraControl);
-
- const QMediaRecorder::Status lastStatus = m_lastStatus;
-
- if (newMode & QCamera::CaptureVideo) {
- if (cameraControl->status() == QCamera::ActiveStatus)
- m_lastStatus = QMediaRecorder::LoadedStatus;
- } else {
- if (m_lastStatus == QMediaRecorder::RecordingStatus)
- return stopWriter();
- else
- m_lastStatus = QMediaRecorder::UnloadedStatus;
- }
-
- if (m_lastStatus != lastStatus)
- Q_EMIT statusChanged(m_lastStatus);
-}
-
-void AVFMediaRecorderControlIOS::cameraStatusChanged(QCamera::Status newStatus)
-{
- AVFCameraControl *cameraControl = m_service->cameraControl();
- Q_ASSERT(cameraControl);
-
- const QMediaRecorder::Status lastStatus = m_lastStatus;
- const bool isCapture = cameraControl->captureMode() & QCamera::CaptureVideo;
- if (newStatus == QCamera::StartingStatus) {
- if (isCapture && m_lastStatus == QMediaRecorder::UnloadedStatus)
- m_lastStatus = QMediaRecorder::LoadingStatus;
- } else if (newStatus == QCamera::ActiveStatus) {
- if (isCapture && m_lastStatus == QMediaRecorder::LoadingStatus)
- m_lastStatus = QMediaRecorder::LoadedStatus;
- } else {
- if (m_lastStatus == QMediaRecorder::RecordingStatus)
- return stopWriter();
- if (newStatus == QCamera::UnloadedStatus)
- m_lastStatus = QMediaRecorder::UnloadedStatus;
- }
-
- if (lastStatus != m_lastStatus)
- Q_EMIT statusChanged(m_lastStatus);
-}
-
-void AVFMediaRecorderControlIOS::stopWriter()
-{
- if (m_lastStatus == QMediaRecorder::RecordingStatus) {
- m_lastStatus = QMediaRecorder::FinalizingStatus;
-
- Q_EMIT statusChanged(m_lastStatus);
-
- [m_writer stop];
- }
-}
-
-#include "moc_avfmediarecordercontrol_ios.cpp"
diff --git a/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.h b/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.h
deleted file mode 100644
index 69a452a97..000000000
--- a/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFMEDIAVIDEOPROBECONTROL_H
-#define AVFMEDIAVIDEOPROBECONTROL_H
-
-#include <qmediavideoprobecontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFMediaVideoProbeControl : public QMediaVideoProbeControl
-{
- Q_OBJECT
-public:
- explicit AVFMediaVideoProbeControl(QObject *parent = nullptr);
- ~AVFMediaVideoProbeControl();
-
- void newFrameProbed(const QVideoFrame& frame);
-
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFMEDIAVIDEOPROBECONTROL_H
diff --git a/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.mm b/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.mm
deleted file mode 100644
index 7621661c3..000000000
--- a/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.mm
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Copyright (C) 2016 Integrated Computer Solutions, Inc
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfmediavideoprobecontrol.h"
-#include <qvideoframe.h>
-
-QT_BEGIN_NAMESPACE
-
-AVFMediaVideoProbeControl::AVFMediaVideoProbeControl(QObject *parent) :
- QMediaVideoProbeControl(parent)
-{
-}
-
-AVFMediaVideoProbeControl::~AVFMediaVideoProbeControl()
-{
-
-}
-
-void AVFMediaVideoProbeControl::newFrameProbed(const QVideoFrame &frame)
-{
- Q_EMIT videoFrameProbed(frame);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/avfoundation/camera/avfstoragelocation.h b/src/plugins/avfoundation/camera/avfstoragelocation.h
deleted file mode 100644
index 76621983d..000000000
--- a/src/plugins/avfoundation/camera/avfstoragelocation.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFSTORAGE_H
-#define AVFSTORAGE_H
-
-#include "qtmultimediaglobal.h"
-
-#include <QtCore/qdir.h>
-#include <QtMultimedia/qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFStorageLocation
-{
-public:
- AVFStorageLocation();
- ~AVFStorageLocation();
-
- QString generateFileName(const QString &requestedName,
- QCamera::CaptureMode mode,
- const QString &prefix,
- const QString &ext) const;
-
-
- QDir defaultDir(QCamera::CaptureMode mode) const;
- QString generateFileName(const QString &prefix, const QDir &dir, const QString &ext) const;
-
-private:
- mutable QMap<QString, int> m_lastUsedIndex;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/avfoundation/camera/avfstoragelocation.mm b/src/plugins/avfoundation/camera/avfstoragelocation.mm
deleted file mode 100644
index 6a1cdca17..000000000
--- a/src/plugins/avfoundation/camera/avfstoragelocation.mm
+++ /dev/null
@@ -1,136 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfstoragelocation.h"
-#include "QtCore/qstandardpaths.h"
-
-
-QT_BEGIN_NAMESPACE
-
-
-AVFStorageLocation::AVFStorageLocation()
-{
-}
-
-AVFStorageLocation::~AVFStorageLocation()
-{
-}
-
-/*!
- * Generate the actual file name from user requested one.
- * requestedName may be either empty (the default dir and naming theme is used),
- * points to existing dir (the default name used)
- * or specify the full actual path.
- */
-QString AVFStorageLocation::generateFileName(const QString &requestedName,
- QCamera::CaptureMode mode,
- const QString &prefix,
- const QString &ext) const
-{
- if (requestedName.isEmpty())
- return generateFileName(prefix, defaultDir(mode), ext);
-
- if (QFileInfo(requestedName).isDir())
- return generateFileName(prefix, QDir(requestedName), ext);
-
- return requestedName;
-}
-
-QDir AVFStorageLocation::defaultDir(QCamera::CaptureMode mode) const
-{
- QStringList dirCandidates;
-
- if (mode == QCamera::CaptureVideo) {
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
- } else {
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
- }
-
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
- dirCandidates << QDir::homePath();
- dirCandidates << QDir::currentPath();
- dirCandidates << QDir::tempPath();
-
- for (const QString &path : qAsConst(dirCandidates)) {
- if (QFileInfo(path).isWritable())
- return QDir(path);
- }
-
- return QDir();
-}
-
-QString AVFStorageLocation::generateFileName(const QString &prefix, const QDir &dir, const QString &ext) const
-{
- QString lastClipKey = dir.absolutePath()+QLatin1Char(' ')+prefix+QLatin1Char(' ')+ext;
- int lastClip = m_lastUsedIndex.value(lastClipKey, 0);
-
- if (lastClip == 0) {
- //first run, find the maximum clip number during the fist capture
- const auto list = dir.entryList(QStringList() << QString("%1*.%2").arg(prefix).arg(ext));
- for (const QString &fileName : list) {
- int imgNumber = QStringView{fileName}.mid(prefix.length(), fileName.size()-prefix.length()-ext.length()-1).toInt();
- lastClip = qMax(lastClip, imgNumber);
- }
- }
-
-
- //don't just rely on cached lastClip value,
- //someone else may create a file after camera started
- while (true) {
- QString name = QString("%1%2.%3").arg(prefix)
- .arg(lastClip+1,
- 4, //fieldWidth
- 10,
- QLatin1Char('0'))
- .arg(ext);
-
- QString path = dir.absoluteFilePath(name);
- if (!QFileInfo(path).exists()) {
- m_lastUsedIndex[lastClipKey] = lastClip+1;
- return path;
- }
-
- lastClip++;
- }
-
- return QString();
-}
-
-
-QT_END_NAMESPACE
diff --git a/src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.h b/src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.h
deleted file mode 100644
index 7c9574f3d..000000000
--- a/src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFVIDEOENCODERSETTINGSCONTROL_H
-#define AVFVIDEOENCODERSETTINGSCONTROL_H
-
-#include <qvideoencodersettingscontrol.h>
-
-#include "avfcamerautility.h"
-#import <AVFoundation/AVFoundation.h>
-
-@class NSDictionary;
-
-QT_BEGIN_NAMESPACE
-
-class AVFCameraService;
-
-class AVFVideoEncoderSettingsControl : public QVideoEncoderSettingsControl
-{
- Q_OBJECT
-
-public:
- explicit AVFVideoEncoderSettingsControl(AVFCameraService *service);
-
- QList<QSize> supportedResolutions(const QVideoEncoderSettings &requestedVideoSettings,
- bool *continuous = nullptr) const override;
-
- QList<qreal> supportedFrameRates(const QVideoEncoderSettings &requestedVideoSettings,
- bool *continuous = nullptr) const override;
-
- QStringList supportedVideoCodecs() const override;
- QString videoCodecDescription(const QString &codecName) const override;
-
- QVideoEncoderSettings videoSettings() const override;
- void setVideoSettings(const QVideoEncoderSettings &requestedVideoSettings) override;
-
- NSDictionary *applySettings(AVCaptureConnection *connection);
- void unapplySettings(AVCaptureConnection *connection);
-
-private:
- AVFCameraService *m_service;
-
- QVideoEncoderSettings m_requestedSettings;
- QVideoEncoderSettings m_actualSettings;
-
- AVCaptureDeviceFormat *m_restoreFormat;
- AVFPSRange m_restoreFps;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFVIDEOENCODERSETTINGSCONTROL_H
diff --git a/src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.mm b/src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.mm
deleted file mode 100644
index 70ec38988..000000000
--- a/src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.mm
+++ /dev/null
@@ -1,385 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfvideoencodersettingscontrol.h"
-
-#include "avfcameraservice.h"
-#include "avfcamerautility.h"
-#include "avfcamerasession.h"
-#include "avfcamerarenderercontrol.h"
-
-#include <AVFoundation/AVFoundation.h>
-
-QT_BEGIN_NAMESPACE
-
-Q_GLOBAL_STATIC_WITH_ARGS(QStringList, supportedCodecs, (QStringList() << QLatin1String("avc1")
- << QLatin1String("jpeg")
- #ifdef Q_OS_OSX
- << QLatin1String("ap4h")
- << QLatin1String("apcn")
- #endif
- ))
-
-static bool format_supports_framerate(AVCaptureDeviceFormat *format, qreal fps)
-{
- if (format && fps > qreal(0)) {
- const qreal epsilon = 0.1;
- for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
- if (range.maxFrameRate - range.minFrameRate < epsilon) {
- if (qAbs(fps - range.maxFrameRate) < epsilon)
- return true;
- }
-
- if (fps >= range.minFrameRate && fps <= range.maxFrameRate)
- return true;
- }
- }
-
- return false;
-}
-
-static bool real_list_contains(const QList<qreal> &list, qreal value)
-{
- for (qreal r : list) {
- if (qFuzzyCompare(r, value))
- return true;
- }
- return false;
-}
-
-AVFVideoEncoderSettingsControl::AVFVideoEncoderSettingsControl(AVFCameraService *service)
- : QVideoEncoderSettingsControl()
- , m_service(service)
- , m_restoreFormat(nil)
-{
-}
-
-QList<QSize> AVFVideoEncoderSettingsControl::supportedResolutions(const QVideoEncoderSettings &settings,
- bool *continuous) const
-{
- Q_UNUSED(settings);
-
- if (continuous)
- *continuous = true;
-
- // AVFoundation seems to support any resolution for recording, with the following limitations:
- // - The recording resolution can't be higher than the camera's active resolution
- // - On OS X, the recording resolution is automatically adjusted to have the same aspect ratio as
- // the camera's active resolution
- QList<QSize> resolutions;
- resolutions.append(QSize(32, 32));
-
- AVCaptureDevice *device = m_service->session()->videoCaptureDevice();
- if (device) {
- int maximumWidth = 0;
- const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(device,
- m_service->session()->defaultCodec()));
- for (int i = 0; i < formats.size(); ++i) {
- const QSize res(qt_device_format_resolution(formats[i]));
- if (res.width() > maximumWidth)
- maximumWidth = res.width();
- }
-
- if (maximumWidth > 0)
- resolutions.append(QSize(maximumWidth, maximumWidth));
- }
-
- if (resolutions.count() == 1)
- resolutions.append(QSize(3840, 3840));
-
- return resolutions;
-}
-
-QList<qreal> AVFVideoEncoderSettingsControl::supportedFrameRates(const QVideoEncoderSettings &settings,
- bool *continuous) const
-{
- QList<qreal> uniqueFrameRates;
-
- AVCaptureDevice *device = m_service->session()->videoCaptureDevice();
- if (!device)
- return uniqueFrameRates;
-
- if (continuous)
- *continuous = false;
-
- QVector<AVFPSRange> allRates;
-
- if (!settings.resolution().isValid()) {
- const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(device, 0));
- for (int i = 0; i < formats.size(); ++i) {
- AVCaptureDeviceFormat *format = formats.at(i);
- allRates += qt_device_format_framerates(format);
- }
- } else {
- AVCaptureDeviceFormat *format = qt_find_best_resolution_match(device,
- settings.resolution(),
- m_service->session()->defaultCodec());
- if (format)
- allRates = qt_device_format_framerates(format);
- }
-
- for (int j = 0; j < allRates.size(); ++j) {
- if (!real_list_contains(uniqueFrameRates, allRates[j].first))
- uniqueFrameRates.append(allRates[j].first);
- if (!real_list_contains(uniqueFrameRates, allRates[j].second))
- uniqueFrameRates.append(allRates[j].second);
- }
-
- return uniqueFrameRates;
-}
-
-QStringList AVFVideoEncoderSettingsControl::supportedVideoCodecs() const
-{
- return *supportedCodecs;
-}
-
-QString AVFVideoEncoderSettingsControl::videoCodecDescription(const QString &codecName) const
-{
- if (codecName == QLatin1String("avc1"))
- return QStringLiteral("H.264");
- else if (codecName == QLatin1String("jpeg"))
- return QStringLiteral("M-JPEG");
-#ifdef Q_OS_OSX
- else if (codecName == QLatin1String("ap4h"))
- return QStringLiteral("Apple ProRes 4444");
- else if (codecName == QLatin1String("apcn"))
- return QStringLiteral("Apple ProRes 422 Standard Definition");
-#endif
-
- return QString();
-}
-
-QVideoEncoderSettings AVFVideoEncoderSettingsControl::videoSettings() const
-{
- return m_actualSettings;
-}
-
-void AVFVideoEncoderSettingsControl::setVideoSettings(const QVideoEncoderSettings &settings)
-{
- if (m_requestedSettings == settings)
- return;
-
- m_requestedSettings = m_actualSettings = settings;
-}
-
-NSDictionary *AVFVideoEncoderSettingsControl::applySettings(AVCaptureConnection *connection)
-{
- if (m_service->session()->state() != QCamera::LoadedState &&
- m_service->session()->state() != QCamera::ActiveState) {
- return nil;
- }
-
- AVCaptureDevice *device = m_service->session()->videoCaptureDevice();
- if (!device)
- return nil;
-
- AVFPSRange currentFps = qt_current_framerates(device, connection);
- const bool needFpsChange = m_requestedSettings.frameRate() > 0
- && m_requestedSettings.frameRate() != currentFps.second;
-
- NSMutableDictionary *videoSettings = [NSMutableDictionary dictionary];
-
- // -- Codec
-
- // AVVideoCodecKey is the only mandatory key
- QString codec = m_requestedSettings.codec().isEmpty() ? supportedCodecs->first() : m_requestedSettings.codec();
- if (!supportedCodecs->contains(codec)) {
- qWarning("Unsupported codec: '%s'", codec.toLocal8Bit().constData());
- codec = supportedCodecs->first();
- }
- [videoSettings setObject:codec.toNSString() forKey:AVVideoCodecKey];
- m_actualSettings.setCodec(codec);
-
- // -- Resolution
-
- int w = m_requestedSettings.resolution().width();
- int h = m_requestedSettings.resolution().height();
-
- if (AVCaptureDeviceFormat *currentFormat = device.activeFormat) {
- CMFormatDescriptionRef formatDesc = currentFormat.formatDescription;
- CMVideoDimensions dim = CMVideoFormatDescriptionGetDimensions(formatDesc);
-
- // We have to change the device's activeFormat in 3 cases:
- // - the requested recording resolution is higher than the current device resolution
- // - the requested recording resolution has a different aspect ratio than the current device aspect ratio
- // - the requested frame rate is not available for the current device format
- AVCaptureDeviceFormat *newFormat = nil;
- if ((w <= 0 || h <= 0)
- && m_requestedSettings.frameRate() > 0
- && !format_supports_framerate(currentFormat, m_requestedSettings.frameRate())) {
-
- newFormat = qt_find_best_framerate_match(device,
- m_service->session()->defaultCodec(),
- m_requestedSettings.frameRate());
-
- } else if (w > 0 && h > 0) {
- AVCaptureDeviceFormat *f = qt_find_best_resolution_match(device,
- m_requestedSettings.resolution(),
- m_service->session()->defaultCodec());
-
- if (f) {
- CMVideoDimensions d = CMVideoFormatDescriptionGetDimensions(f.formatDescription);
- qreal fAspectRatio = qreal(d.width) / d.height;
-
- if (w > dim.width || h > dim.height
- || qAbs((qreal(dim.width) / dim.height) - fAspectRatio) > 0.01) {
- newFormat = f;
- }
- }
- }
-
- if (qt_set_active_format(device, newFormat, !needFpsChange)) {
- m_restoreFormat = [currentFormat retain];
- formatDesc = newFormat.formatDescription;
- dim = CMVideoFormatDescriptionGetDimensions(formatDesc);
- }
-
- if (w > 0 && h > 0) {
- // Make sure the recording resolution has the same aspect ratio as the device's
- // current resolution
- qreal deviceAspectRatio = qreal(dim.width) / dim.height;
- qreal recAspectRatio = qreal(w) / h;
- if (qAbs(deviceAspectRatio - recAspectRatio) > 0.01) {
- if (recAspectRatio > deviceAspectRatio)
- w = qRound(h * deviceAspectRatio);
- else
- h = qRound(w / deviceAspectRatio);
- }
-
- // recording resolution can't be higher than the device's active resolution
- w = qMin(w, dim.width);
- h = qMin(h, dim.height);
- }
- }
-
- if (w > 0 && h > 0) {
- // Width and height must be divisible by 2
- w += w & 1;
- h += h & 1;
-
- [videoSettings setObject:[NSNumber numberWithInt:w] forKey:AVVideoWidthKey];
- [videoSettings setObject:[NSNumber numberWithInt:h] forKey:AVVideoHeightKey];
- m_actualSettings.setResolution(w, h);
- } else {
- m_actualSettings.setResolution(qt_device_format_resolution(device.activeFormat));
- }
-
- // -- FPS
-
- if (needFpsChange) {
- m_restoreFps = currentFps;
- const qreal fps = m_requestedSettings.frameRate();
- qt_set_framerate_limits(device, connection, fps, fps);
- }
- m_actualSettings.setFrameRate(qt_current_framerates(device, connection).second);
-
- // -- Codec Settings
-
- NSMutableDictionary *codecProperties = [NSMutableDictionary dictionary];
- int bitrate = -1;
- float quality = -1.f;
-
- if (m_requestedSettings.encodingMode() == QMultimedia::ConstantQualityEncoding) {
- if (m_requestedSettings.quality() != QMultimedia::NormalQuality) {
- if (codec != QLatin1String("jpeg")) {
- qWarning("ConstantQualityEncoding is not supported for codec: '%s'", codec.toLocal8Bit().constData());
- } else {
- switch (m_requestedSettings.quality()) {
- case QMultimedia::VeryLowQuality:
- quality = 0.f;
- break;
- case QMultimedia::LowQuality:
- quality = 0.25f;
- break;
- case QMultimedia::HighQuality:
- quality = 0.75f;
- break;
- case QMultimedia::VeryHighQuality:
- quality = 1.f;
- break;
- default:
- quality = -1.f; // NormalQuality, let the system decide
- break;
- }
- }
- }
- } else if (m_requestedSettings.encodingMode() == QMultimedia::AverageBitRateEncoding){
- if (codec != QLatin1String("avc1"))
- qWarning("AverageBitRateEncoding is not supported for codec: '%s'", codec.toLocal8Bit().constData());
- else
- bitrate = m_requestedSettings.bitRate();
- } else {
- qWarning("Encoding mode is not supported");
- }
-
- if (bitrate != -1)
- [codecProperties setObject:[NSNumber numberWithInt:bitrate] forKey:AVVideoAverageBitRateKey];
- if (quality != -1.f)
- [codecProperties setObject:[NSNumber numberWithFloat:quality] forKey:AVVideoQualityKey];
-
- [videoSettings setObject:codecProperties forKey:AVVideoCompressionPropertiesKey];
-
- return videoSettings;
-}
-
-void AVFVideoEncoderSettingsControl::unapplySettings(AVCaptureConnection *connection)
-{
- m_actualSettings = m_requestedSettings;
-
- AVCaptureDevice *device = m_service->session()->videoCaptureDevice();
- if (!device)
- return;
-
- const bool needFpsChanged = m_restoreFps.first || m_restoreFps.second;
-
- if (m_restoreFormat) {
- qt_set_active_format(device, m_restoreFormat, !needFpsChanged);
- [m_restoreFormat release];
- m_restoreFormat = nil;
- }
-
- if (needFpsChanged) {
- qt_set_framerate_limits(device, connection, m_restoreFps.first, m_restoreFps.second);
- m_restoreFps = AVFPSRange();
- }
-}
-
-QT_END_NAMESPACE
-
-#include "moc_avfvideoencodersettingscontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/camera.pro b/src/plugins/avfoundation/camera/camera.pro
deleted file mode 100644
index 76aa8af85..000000000
--- a/src/plugins/avfoundation/camera/camera.pro
+++ /dev/null
@@ -1,94 +0,0 @@
-TARGET = qavfcamera
-
-# Avoid clash with a variable named `slots' in a Quartz header
-CONFIG += no_keywords
-
-QT += multimedia-private network
-
-LIBS += -framework CoreFoundation \
- -framework Foundation \
- -framework AudioToolbox \
- -framework CoreAudio \
- -framework QuartzCore \
- -framework CoreMedia
-osx:LIBS += -framework AppKit \
- -framework AudioUnit
-ios:LIBS += -framework CoreGraphics \
- -framework CoreVideo
-
-QMAKE_USE += avfoundation
-
-OTHER_FILES += avfcamera.json
-
-HEADERS += \
- avfcameradebug.h \
- avfcameraserviceplugin.h \
- avfcameracontrol.h \
- avfcamerametadatacontrol.h \
- avfimagecapturecontrol.h \
- avfcameraservice.h \
- avfcamerasession.h \
- avfstoragelocation.h \
- avfaudioinputselectorcontrol.h \
- avfcamerainfocontrol.h \
- avfmediavideoprobecontrol.h \
- avfcamerarenderercontrol.h \
- avfcameradevicecontrol.h \
- avfcamerafocuscontrol.h \
- avfcameraexposurecontrol.h \
- avfcamerautility.h \
- avfcameraviewfindersettingscontrol.h \
- avfimageencodercontrol.h \
- avfcameraflashcontrol.h \
- avfvideoencodersettingscontrol.h \
- avfmediacontainercontrol.h \
- avfaudioencodersettingscontrol.h \
- avfcamerawindowcontrol.h \
- avfcapturedestinationcontrol.h
-
-OBJECTIVE_SOURCES += \
- avfcameraserviceplugin.mm \
- avfcameracontrol.mm \
- avfcamerametadatacontrol.mm \
- avfimagecapturecontrol.mm \
- avfcameraservice.mm \
- avfcamerasession.mm \
- avfstoragelocation.mm \
- avfaudioinputselectorcontrol.mm \
- avfcamerainfocontrol.mm \
- avfmediavideoprobecontrol.mm \
- avfcameradevicecontrol.mm \
- avfcamerarenderercontrol.mm \
- avfcamerafocuscontrol.mm \
- avfcameraexposurecontrol.mm \
- avfcamerautility.mm \
- avfcameraviewfindersettingscontrol.mm \
- avfimageencodercontrol.mm \
- avfcameraflashcontrol.mm \
- avfvideoencodersettingscontrol.mm \
- avfmediacontainercontrol.mm \
- avfaudioencodersettingscontrol.mm \
- avfcamerawindowcontrol.mm \
- avfcapturedestinationcontrol.mm
-
-osx {
-
-HEADERS += avfmediarecordercontrol.h
-OBJECTIVE_SOURCES += avfmediarecordercontrol.mm
-
-}
-
-ios {
-
-HEADERS += avfcamerazoomcontrol.h \
- avfmediaassetwriter.h \
- avfmediarecordercontrol_ios.h
-OBJECTIVE_SOURCES += avfcamerazoomcontrol.mm \
- avfmediaassetwriter.mm \
- avfmediarecordercontrol_ios.mm
-
-}
-
-PLUGIN_TYPE = mediaservice
-PLUGIN_CLASS_NAME = AVFServicePlugin
-load(qt_plugin)
diff --git a/src/plugins/avfoundation/mediaplayer/avfdisplaylink.h b/src/plugins/avfoundation/mediaplayer/avfdisplaylink.h
deleted file mode 100644
index ba0803807..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfdisplaylink.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFDISPLAYLINK_H
-#define AVFDISPLAYLINK_H
-
-#include <QtCore/qobject.h>
-#include <QtCore/qmutex.h>
-
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
-#include <CoreVideo/CVBase.h>
-#else
-#include <QuartzCore/CVDisplayLink.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class AVFDisplayLink : public QObject
-{
- Q_OBJECT
-public:
- explicit AVFDisplayLink(QObject *parent = nullptr);
- virtual ~AVFDisplayLink();
- bool isValid() const;
- bool isActive() const;
-
-public Q_SLOTS:
- void start();
- void stop();
-
-Q_SIGNALS:
- void tick(const CVTimeStamp &ts);
-
-public:
- void displayLinkEvent(const CVTimeStamp *);
-
-protected:
- virtual bool event(QEvent *) override;
-
-private:
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
- void *m_displayLink;
-#else
- CVDisplayLinkRef m_displayLink;
-#endif
- QMutex m_displayLinkMutex;
- bool m_pendingDisplayLinkEvent;
- bool m_isActive;
- CVTimeStamp m_frameTimeStamp;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFDISPLAYLINK_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfdisplaylink.mm b/src/plugins/avfoundation/mediaplayer/avfdisplaylink.mm
deleted file mode 100644
index bae18bc0a..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfdisplaylink.mm
+++ /dev/null
@@ -1,241 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfdisplaylink.h"
-#include <QtCore/qcoreapplication.h>
-
-#ifdef QT_DEBUG_AVF
-#include <QtCore/qdebug.h>
-#endif
-
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
-#import <QuartzCore/CADisplayLink.h>
-#import <Foundation/NSRunLoop.h>
-#define _m_displayLink static_cast<DisplayLinkObserver*>(m_displayLink)
-#else
-#endif
-
-QT_USE_NAMESPACE
-
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
-@interface DisplayLinkObserver : NSObject
-
-- (void)start;
-- (void)stop;
-- (void)displayLinkNotification:(CADisplayLink *)sender;
-
-@end
-
-@implementation DisplayLinkObserver
-{
- AVFDisplayLink *m_avfDisplayLink;
- CADisplayLink *m_displayLink;
-}
-
-- (id)initWithAVFDisplayLink:(AVFDisplayLink *)link
-{
- self = [super init];
-
- if (self) {
- m_avfDisplayLink = link;
- m_displayLink = [[CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkNotification:)] retain];
- }
-
- return self;
-}
-
-- (void) dealloc
-{
- if (m_displayLink) {
- [m_displayLink release];
- m_displayLink = nullptr;
- }
-
- [super dealloc];
-}
-
-- (void)start
-{
- [m_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
-}
-
-- (void)stop
-{
- [m_displayLink removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
-}
-
-- (void)displayLinkNotification:(CADisplayLink *)sender
-{
- Q_UNUSED(sender);
- m_avfDisplayLink->displayLinkEvent(nullptr);
-}
-
-@end
-#else
-static CVReturn CVDisplayLinkCallback(CVDisplayLinkRef displayLink,
- const CVTimeStamp *inNow,
- const CVTimeStamp *inOutputTime,
- CVOptionFlags flagsIn,
- CVOptionFlags *flagsOut,
- void *displayLinkContext)
-{
- Q_UNUSED(displayLink);
- Q_UNUSED(inNow);
- Q_UNUSED(flagsIn);
- Q_UNUSED(flagsOut);
-
- AVFDisplayLink *link = (AVFDisplayLink *)displayLinkContext;
-
- link->displayLinkEvent(inOutputTime);
- return kCVReturnSuccess;
-}
-#endif
-
-AVFDisplayLink::AVFDisplayLink(QObject *parent)
- : QObject(parent)
- , m_displayLink(nullptr)
- , m_pendingDisplayLinkEvent(false)
- , m_isActive(false)
-{
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
- m_displayLink = [[DisplayLinkObserver alloc] initWithAVFDisplayLink:this];
-#else
- // create display link for the main display
- CVDisplayLinkCreateWithCGDisplay(kCGDirectMainDisplay, &m_displayLink);
- if (m_displayLink) {
- // set the current display of a display link.
- CVDisplayLinkSetCurrentCGDisplay(m_displayLink, kCGDirectMainDisplay);
-
- // set the renderer output callback function
- CVDisplayLinkSetOutputCallback(m_displayLink, &CVDisplayLinkCallback, this);
- }
-#endif
-}
-
-AVFDisplayLink::~AVFDisplayLink()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
-
- if (m_displayLink) {
- stop();
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
- [_m_displayLink release];
-#else
- CVDisplayLinkRelease(m_displayLink);
-#endif
- m_displayLink = nullptr;
- }
-}
-
-bool AVFDisplayLink::isValid() const
-{
- return m_displayLink != nullptr;
-}
-
-bool AVFDisplayLink::isActive() const
-{
- return m_isActive;
-}
-
-void AVFDisplayLink::start()
-{
- if (m_displayLink && !m_isActive) {
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
- [_m_displayLink start];
-#else
- CVDisplayLinkStart(m_displayLink);
-#endif
- m_isActive = true;
- }
-}
-
-void AVFDisplayLink::stop()
-{
- if (m_displayLink && m_isActive) {
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
- [_m_displayLink stop];
-#else
- CVDisplayLinkStop(m_displayLink);
-#endif
- m_isActive = false;
- }
-}
-
-void AVFDisplayLink::displayLinkEvent(const CVTimeStamp *ts)
-{
- // This function is called from a
- // thread != gui thread. So we post the event.
- // But we need to make sure that we don't post faster
- // than the event loop can eat:
- m_displayLinkMutex.lock();
- bool pending = m_pendingDisplayLinkEvent;
- m_pendingDisplayLinkEvent = true;
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
- Q_UNUSED(ts);
- memset(&m_frameTimeStamp, 0, sizeof(CVTimeStamp));
-#else
- m_frameTimeStamp = *ts;
-#endif
- m_displayLinkMutex.unlock();
-
- if (!pending)
- qApp->postEvent(this, new QEvent(QEvent::User), Qt::HighEventPriority);
-}
-
-bool AVFDisplayLink::event(QEvent *event)
-{
- switch (event->type()){
- case QEvent::User: {
- m_displayLinkMutex.lock();
- m_pendingDisplayLinkEvent = false;
- CVTimeStamp ts = m_frameTimeStamp;
- m_displayLinkMutex.unlock();
-
- Q_EMIT tick(ts);
-
- return false;
- }
- break;
- default:
- break;
- }
- return QObject::event(event);
-}
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayer.json b/src/plugins/avfoundation/mediaplayer/avfmediaplayer.json
deleted file mode 100644
index 5626edec0..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayer.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["avfoundationmediaplayer"],
- "Services": ["org.qt-project.qt.mediaplayer"]
-}
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayercontrol.h b/src/plugins/avfoundation/mediaplayer/avfmediaplayercontrol.h
deleted file mode 100644
index ac0ba0ab2..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayercontrol.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFMEDIAPLAYERCONTROL_H
-#define AVFMEDIAPLAYERCONTROL_H
-
-#include <QtMultimedia/QMediaPlayerControl>
-#include <QtCore/QObject>
-
-QT_BEGIN_NAMESPACE
-
-class AVFMediaPlayerSession;
-
-class AVFMediaPlayerControl : public QMediaPlayerControl
-{
- Q_OBJECT
-public:
- explicit AVFMediaPlayerControl(QObject *parent = nullptr);
- ~AVFMediaPlayerControl();
-
- void setSession(AVFMediaPlayerSession *session);
-
- QMediaPlayer::State state() const override;
- QMediaPlayer::MediaStatus mediaStatus() const override;
-
- QMediaContent media() const override;
- const QIODevice *mediaStream() const override;
- void setMedia(const QMediaContent &content, QIODevice *stream) override;
-
- qint64 position() const override;
- qint64 duration() const override;
-
- int bufferStatus() const override;
-
- int volume() const override;
- bool isMuted() const override;
-
- bool isAudioAvailable() const override;
- bool isVideoAvailable() const override;
-
- bool isSeekable() const override;
- QMediaTimeRange availablePlaybackRanges() const override;
-
- qreal playbackRate() const override;
- void setPlaybackRate(qreal rate) override;
-
-public Q_SLOTS:
- void setPosition(qint64 pos) override;
-
- void play() override;
- void pause() override;
- void stop() override;
-
- void setVolume(int volume) override;
- void setMuted(bool muted) override;
-
-private:
- AVFMediaPlayerSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFMEDIAPLAYERCONTROL_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayercontrol.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayercontrol.mm
deleted file mode 100644
index bf7ebb4a0..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayercontrol.mm
+++ /dev/null
@@ -1,192 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfmediaplayercontrol.h"
-#include "avfmediaplayersession.h"
-
-QT_USE_NAMESPACE
-
-AVFMediaPlayerControl::AVFMediaPlayerControl(QObject *parent) :
- QMediaPlayerControl(parent)
-{
-}
-
-AVFMediaPlayerControl::~AVFMediaPlayerControl()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
-}
-
-void AVFMediaPlayerControl::setSession(AVFMediaPlayerSession *session)
-{
- m_session = session;
-
- connect(m_session, SIGNAL(positionChanged(qint64)), this, SIGNAL(positionChanged(qint64)));
- connect(m_session, SIGNAL(durationChanged(qint64)), this, SIGNAL(durationChanged(qint64)));
- connect(m_session, SIGNAL(bufferStatusChanged(int)), this, SIGNAL(bufferStatusChanged(int)));
- connect(m_session, SIGNAL(stateChanged(QMediaPlayer::State)),
- this, SIGNAL(stateChanged(QMediaPlayer::State)));
- connect(m_session, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
- this, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)));
- connect(m_session, SIGNAL(volumeChanged(int)), this, SIGNAL(volumeChanged(int)));
- connect(m_session, SIGNAL(mutedChanged(bool)), this, SIGNAL(mutedChanged(bool)));
- connect(m_session, SIGNAL(audioAvailableChanged(bool)), this, SIGNAL(audioAvailableChanged(bool)));
- connect(m_session, SIGNAL(videoAvailableChanged(bool)), this, SIGNAL(videoAvailableChanged(bool)));
- connect(m_session, SIGNAL(error(int,QString)), this, SIGNAL(error(int,QString)));
- connect(m_session, &AVFMediaPlayerSession::playbackRateChanged,
- this, &AVFMediaPlayerControl::playbackRateChanged);
- connect(m_session, &AVFMediaPlayerSession::seekableChanged,
- this, &AVFMediaPlayerControl::seekableChanged);
-}
-
-QMediaPlayer::State AVFMediaPlayerControl::state() const
-{
- return m_session->state();
-}
-
-QMediaPlayer::MediaStatus AVFMediaPlayerControl::mediaStatus() const
-{
- return m_session->mediaStatus();
-}
-
-QMediaContent AVFMediaPlayerControl::media() const
-{
- return m_session->media();
-}
-
-const QIODevice *AVFMediaPlayerControl::mediaStream() const
-{
- return m_session->mediaStream();
-}
-
-void AVFMediaPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream)
-{
- const QMediaContent oldContent = m_session->media();
-
- m_session->setMedia(content, stream);
-
- if (content != oldContent)
- Q_EMIT mediaChanged(content);
-}
-
-qint64 AVFMediaPlayerControl::position() const
-{
- return m_session->position();
-}
-
-qint64 AVFMediaPlayerControl::duration() const
-{
- return m_session->duration();
-}
-
-int AVFMediaPlayerControl::bufferStatus() const
-{
- return m_session->bufferStatus();
-}
-
-int AVFMediaPlayerControl::volume() const
-{
- return m_session->volume();
-}
-
-bool AVFMediaPlayerControl::isMuted() const
-{
- return m_session->isMuted();
-}
-
-bool AVFMediaPlayerControl::isAudioAvailable() const
-{
- return m_session->isAudioAvailable();
-}
-
-bool AVFMediaPlayerControl::isVideoAvailable() const
-{
- return m_session->isVideoAvailable();
-}
-
-bool AVFMediaPlayerControl::isSeekable() const
-{
- return m_session->isSeekable();
-}
-
-QMediaTimeRange AVFMediaPlayerControl::availablePlaybackRanges() const
-{
- return m_session->availablePlaybackRanges();
-}
-
-qreal AVFMediaPlayerControl::playbackRate() const
-{
- return m_session->playbackRate();
-}
-
-void AVFMediaPlayerControl::setPlaybackRate(qreal rate)
-{
- m_session->setPlaybackRate(rate);
-}
-
-void AVFMediaPlayerControl::setPosition(qint64 pos)
-{
- m_session->setPosition(pos);
-}
-
-void AVFMediaPlayerControl::play()
-{
- m_session->play();
-}
-
-void AVFMediaPlayerControl::pause()
-{
- m_session->pause();
-}
-
-void AVFMediaPlayerControl::stop()
-{
- m_session->stop();
-}
-
-void AVFMediaPlayerControl::setVolume(int volume)
-{
- m_session->setVolume(volume);
-}
-
-void AVFMediaPlayerControl::setMuted(bool muted)
-{
- m_session->setMuted(muted);
-}
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.h b/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.h
deleted file mode 100644
index ae99c7eda..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFMEDIAPLAYERMETADATACONTROL_H
-#define AVFMEDIAPLAYERMETADATACONTROL_H
-
-#include <QtMultimedia/QMetaDataReaderControl>
-
-QT_BEGIN_NAMESPACE
-
-class AVFMediaPlayerSession;
-
-class AVFMediaPlayerMetaDataControl : public QMetaDataReaderControl
-{
- Q_OBJECT
-public:
- explicit AVFMediaPlayerMetaDataControl(AVFMediaPlayerSession *session, QObject *parent = nullptr);
- virtual ~AVFMediaPlayerMetaDataControl();
-
- bool isMetaDataAvailable() const override;
- bool isWritable() const;
-
- QVariant metaData(const QString &key) const override;
- QStringList availableMetaData() const override;
-
-private Q_SLOTS:
- void updateTags();
-
-private:
- AVFMediaPlayerSession *m_session;
- QVariantMap m_tags;
- void *m_asset;
-
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFMEDIAPLAYERMETADATACONTROL_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.mm
deleted file mode 100644
index b9ec38c0f..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.mm
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfmediaplayermetadatacontrol.h"
-#include "avfmediaplayersession.h"
-
-#include <QtMultimedia/qmediametadata.h>
-
-#import <AVFoundation/AVFoundation.h>
-
-QT_USE_NAMESPACE
-
-AVFMediaPlayerMetaDataControl::AVFMediaPlayerMetaDataControl(AVFMediaPlayerSession *session, QObject *parent)
- : QMetaDataReaderControl(parent)
- , m_session(session)
- , m_asset(nullptr)
-{
- QObject::connect(m_session, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(updateTags()));
-}
-
-AVFMediaPlayerMetaDataControl::~AVFMediaPlayerMetaDataControl()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
-}
-
-bool AVFMediaPlayerMetaDataControl::isMetaDataAvailable() const
-{
- return !m_tags.isEmpty();
-}
-
-bool AVFMediaPlayerMetaDataControl::isWritable() const
-{
- return false;
-}
-
-QVariant AVFMediaPlayerMetaDataControl::metaData(const QString &key) const
-{
- return m_tags.value(key);
-}
-
-QStringList AVFMediaPlayerMetaDataControl::availableMetaData() const
-{
- return m_tags.keys();
-}
-
-static QString itemKey(AVMetadataItem *item)
-{
- NSString *keyString = [item commonKey];
-
- if (keyString.length != 0) {
- if ([keyString isEqualToString:AVMetadataCommonKeyTitle]) {
- return QMediaMetaData::Title;
- } else if ([keyString isEqualToString: AVMetadataCommonKeySubject]) {
- return QMediaMetaData::SubTitle;
- } else if ([keyString isEqualToString: AVMetadataCommonKeyDescription]) {
- return QMediaMetaData::Description;
- } else if ([keyString isEqualToString: AVMetadataCommonKeyPublisher]) {
- return QMediaMetaData::Publisher;
- } else if ([keyString isEqualToString: AVMetadataCommonKeyCreationDate]) {
- return QMediaMetaData::Date;
- } else if ([keyString isEqualToString: AVMetadataCommonKeyType]) {
- return QMediaMetaData::MediaType;
- } else if ([keyString isEqualToString: AVMetadataCommonKeyLanguage]) {
- return QMediaMetaData::Language;
- } else if ([keyString isEqualToString: AVMetadataCommonKeyCopyrights]) {
- return QMediaMetaData::Copyright;
- } else if ([keyString isEqualToString: AVMetadataCommonKeyAlbumName]) {
- return QMediaMetaData::AlbumTitle;
- } else if ([keyString isEqualToString: AVMetadataCommonKeyAuthor]) {
- return QMediaMetaData::Author;
- } else if ([keyString isEqualToString: AVMetadataCommonKeyArtist]) {
- return QMediaMetaData::ContributingArtist;
- } else if ([keyString isEqualToString: AVMetadataCommonKeyArtwork]) {
- return QMediaMetaData::PosterUrl;
- }
- }
-
- return QString();
-}
-
-void AVFMediaPlayerMetaDataControl::updateTags()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
- AVAsset *currentAsset = static_cast<AVAsset*>(m_session->currentAssetHandle());
-
- //Don't read the tags from the same asset more than once
- if (currentAsset == m_asset)
- return;
-
- m_asset = currentAsset;
-
- QVariantMap oldTags = m_tags;
- //Since we've changed assets, clear old tags
- m_tags.clear();
- bool changed = false;
-
- // TODO: also process ID3, iTunes and QuickTime metadata
-
- NSArray *metadataItems = [currentAsset commonMetadata];
- for (AVMetadataItem* item in metadataItems) {
- const QString key = itemKey(item);
- if (!key.isEmpty()) {
- const QString value = QString::fromNSString([item stringValue]);
- if (!value.isNull()) {
- m_tags.insert(key, value);
- if (value != oldTags.value(key)) {
- changed = true;
- Q_EMIT metaDataChanged(key, value);
- }
- }
- }
- }
-
- if (oldTags.isEmpty() != m_tags.isEmpty()) {
- Q_EMIT metaDataAvailableChanged(!m_tags.isEmpty());
- changed = true;
- }
-
- if (changed)
- Q_EMIT metaDataChanged();
-}
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.h b/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.h
deleted file mode 100644
index 6a4b915cf..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFMEDIAPLAYERSERVICE_H
-#define AVFMEDIAPLAYERSERVICE_H
-
-#include <QtMultimedia/QMediaService>
-
-QT_BEGIN_NAMESPACE
-
-class AVFMediaPlayerSession;
-class AVFMediaPlayerControl;
-class AVFMediaPlayerMetaDataControl;
-class AVFVideoOutput;
-
-class AVFMediaPlayerService : public QMediaService
-{
-public:
- explicit AVFMediaPlayerService(QObject *parent = nullptr);
- ~AVFMediaPlayerService();
-
- QMediaControl* requestControl(const char *name) override;
- void releaseControl(QMediaControl *control) override;
-
-private:
- AVFMediaPlayerSession *m_session;
- AVFMediaPlayerControl *m_control;
- QMediaControl *m_videoOutput;
- AVFMediaPlayerMetaDataControl *m_playerMetaDataControl;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFMEDIAPLAYERSERVICE_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm
deleted file mode 100644
index bc59fa921..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm
+++ /dev/null
@@ -1,134 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfmediaplayerservice.h"
-#include "avfmediaplayersession.h"
-#include "avfmediaplayercontrol.h"
-#include "avfmediaplayermetadatacontrol.h"
-#include "avfvideooutput.h"
-#if QT_CONFIG(opengl)
-#include "avfvideorenderercontrol.h"
-#endif
-#ifndef QT_NO_WIDGETS
-# include "avfvideowidgetcontrol.h"
-#endif
-#include "avfvideowindowcontrol.h"
-
-#import <AVFoundation/AVFoundation.h>
-
-QT_USE_NAMESPACE
-
-AVFMediaPlayerService::AVFMediaPlayerService(QObject *parent)
- : QMediaService(parent)
- , m_videoOutput(nullptr)
-{
- m_session = new AVFMediaPlayerSession(this);
- m_control = new AVFMediaPlayerControl(this);
- m_control->setSession(m_session);
- m_playerMetaDataControl = new AVFMediaPlayerMetaDataControl(m_session, this);
-
- connect(m_control, SIGNAL(mediaChanged(QMediaContent)), m_playerMetaDataControl, SLOT(updateTags()));
-}
-
-AVFMediaPlayerService::~AVFMediaPlayerService()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
- delete m_session;
-}
-
-QMediaControl *AVFMediaPlayerService::requestControl(const char *name)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << name;
-#endif
-
- if (qstrcmp(name, QMediaPlayerControl_iid) == 0)
- return m_control;
-
- if (qstrcmp(name, QMetaDataReaderControl_iid) == 0)
- return m_playerMetaDataControl;
-
-#if QT_CONFIG(opengl)
- if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
- if (!m_videoOutput)
- m_videoOutput = new AVFVideoRendererControl(this);
-
- m_session->setVideoOutput(qobject_cast<AVFVideoOutput*>(m_videoOutput));
- return m_videoOutput;
- }
-#endif
-#ifndef QT_NO_WIDGETS
- if (qstrcmp(name, QVideoWidgetControl_iid) == 0) {
- if (!m_videoOutput)
- m_videoOutput = new AVFVideoWidgetControl(this);
-
- m_session->setVideoOutput(qobject_cast<AVFVideoOutput*>(m_videoOutput));
- return m_videoOutput;
- }
-#endif
- if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
- if (!m_videoOutput)
- m_videoOutput = new AVFVideoWindowControl(this);
-
- m_session->setVideoOutput(qobject_cast<AVFVideoOutput*>(m_videoOutput));
- return m_videoOutput;
- }
- return nullptr;
-}
-
-void AVFMediaPlayerService::releaseControl(QMediaControl *control)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << control;
-#endif
- if (m_videoOutput == control) {
-#if QT_CONFIG(opengl)
- AVFVideoRendererControl *renderControl = qobject_cast<AVFVideoRendererControl*>(m_videoOutput);
-
- if (renderControl)
- renderControl->setSurface(nullptr);
-#endif
- m_videoOutput = nullptr;
- m_session->setVideoOutput(nullptr);
-
- delete control;
- }
-}
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayerserviceplugin.h b/src/plugins/avfoundation/mediaplayer/avfmediaplayerserviceplugin.h
deleted file mode 100644
index e08f0f46e..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayerserviceplugin.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef AVFMEDIAPLAYERSERVICEPLUGIN_H
-#define AVFMEDIAPLAYERSERVICEPLUGIN_H
-
-#include <QtCore/qglobal.h>
-#include <QtMultimedia/qmediaserviceproviderplugin.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFMediaPlayerServicePlugin
- : public QMediaServiceProviderPlugin
- , public QMediaServiceSupportedFormatsInterface
- , public QMediaServiceFeaturesInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaServiceSupportedFormatsInterface)
- Q_INTERFACES(QMediaServiceFeaturesInterface)
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "avfmediaplayer.json")
-
-public:
- explicit AVFMediaPlayerServicePlugin();
-
- QMediaService* create(QString const& key) override;
- void release(QMediaService *service) override;
-
- QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const override;
- QMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const override;
- QStringList supportedMimeTypes() const override;
-
-private:
- void buildSupportedTypes();
-
- QStringList m_supportedMimeTypes;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFMEDIAPLAYERSERVICEPLUGIN_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayerserviceplugin.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayerserviceplugin.mm
deleted file mode 100644
index 59b29a3d2..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayerserviceplugin.mm
+++ /dev/null
@@ -1,107 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfmediaplayerserviceplugin.h"
-#include <QtCore/QDebug>
-
-#include "avfmediaplayerservice.h"
-
-#import <AVFoundation/AVFoundation.h>
-
-QT_USE_NAMESPACE
-
-AVFMediaPlayerServicePlugin::AVFMediaPlayerServicePlugin()
-{
- buildSupportedTypes();
-}
-
-QMediaService *AVFMediaPlayerServicePlugin::create(const QString &key)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << "AVFMediaPlayerServicePlugin::create" << key;
-#endif
- if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER))
- return new AVFMediaPlayerService;
-
- qWarning() << "unsupported key: " << key;
- return nullptr;
-}
-
-void AVFMediaPlayerServicePlugin::release(QMediaService *service)
-{
- delete service;
-}
-
-QMediaServiceProviderHint::Features AVFMediaPlayerServicePlugin::supportedFeatures(const QByteArray &service) const
-{
- if (service == Q_MEDIASERVICE_MEDIAPLAYER)
- return QMediaServiceProviderHint::VideoSurface;
- else
- return QMediaServiceProviderHint::Features();
-}
-
-QMultimedia::SupportEstimate AVFMediaPlayerServicePlugin::hasSupport(const QString &mimeType, const QStringList &codecs) const
-{
- Q_UNUSED(codecs);
-
- if (m_supportedMimeTypes.contains(mimeType))
- return QMultimedia::ProbablySupported;
-
- return QMultimedia::MaybeSupported;
-}
-
-QStringList AVFMediaPlayerServicePlugin::supportedMimeTypes() const
-{
- return m_supportedMimeTypes;
-}
-
-void AVFMediaPlayerServicePlugin::buildSupportedTypes()
-{
- //Populate m_supportedMimeTypes with mimetypes AVAsset supports
- NSArray *mimeTypes = [AVURLAsset audiovisualMIMETypes];
- for (NSString *mimeType in mimeTypes)
- {
- m_supportedMimeTypes.append(QString::fromUtf8([mimeType UTF8String]));
- }
-#ifdef QT_DEBUG_AVF
- qDebug() << "AVFMediaPlayerServicePlugin::buildSupportedTypes";
- qDebug() << "Supported Types: " << m_supportedMimeTypes;
-#endif
-
-}
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h
deleted file mode 100644
index db29e88aa..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFMEDIAPLAYERSESSION_H
-#define AVFMEDIAPLAYERSESSION_H
-
-#include <QtCore/QObject>
-#include <QtCore/QByteArray>
-#include <QtCore/QSet>
-#include <QtCore/QResource>
-
-#include <QtMultimedia/QMediaPlayerControl>
-#include <QtMultimedia/QMediaPlayer>
-
-QT_BEGIN_NAMESPACE
-
-class AVFMediaPlayerService;
-class AVFVideoOutput;
-
-class AVFMediaPlayerSession : public QObject
-{
- Q_OBJECT
-public:
- AVFMediaPlayerSession(AVFMediaPlayerService *service, QObject *parent = nullptr);
- virtual ~AVFMediaPlayerSession();
-
- void setVideoOutput(AVFVideoOutput *output);
- void *currentAssetHandle();
-
- QMediaPlayer::State state() const;
- QMediaPlayer::MediaStatus mediaStatus() const;
-
- QMediaContent media() const;
- QIODevice *mediaStream() const;
- void setMedia(const QMediaContent &content, QIODevice *stream);
-
- qint64 position() const;
- qint64 duration() const;
-
- int bufferStatus() const;
-
- int volume() const;
- bool isMuted() const;
-
- bool isAudioAvailable() const;
- bool isVideoAvailable() const;
-
- bool isSeekable() const;
- QMediaTimeRange availablePlaybackRanges() const;
-
- qreal playbackRate() const;
-
-public Q_SLOTS:
- void setPlaybackRate(qreal rate);
-
- void setPosition(qint64 pos);
-
- void play();
- void pause();
- void stop();
-
- void setVolume(int volume);
- void setMuted(bool muted);
-
- void processEOS();
- void processLoadStateChange(QMediaPlayer::State newState);
- void processPositionChange();
- void processMediaLoadError();
-
- void processLoadStateChange();
- void processLoadStateFailure();
-
- void processBufferStateChange(int bufferStatus);
-
- void processDurationChange(qint64 duration);
-
- void streamReady();
- void streamDestroyed();
-
-Q_SIGNALS:
- void positionChanged(qint64 position);
- void durationChanged(qint64 duration);
- void stateChanged(QMediaPlayer::State newState);
- void bufferStatusChanged(int bufferStatus);
- void mediaStatusChanged(QMediaPlayer::MediaStatus status);
- void volumeChanged(int volume);
- void mutedChanged(bool muted);
- void audioAvailableChanged(bool audioAvailable);
- void videoAvailableChanged(bool videoAvailable);
- void playbackRateChanged(qreal rate);
- void seekableChanged(bool seekable);
- void error(int error, const QString &errorString);
-
-private:
- void setAudioAvailable(bool available);
- void setVideoAvailable(bool available);
- void setSeekable(bool seekable);
- void resetStream(QIODevice *stream = nullptr);
-
- AVFMediaPlayerService *m_service;
- AVFVideoOutput *m_videoOutput;
-
- QMediaPlayer::State m_state;
- QMediaPlayer::MediaStatus m_mediaStatus;
- QIODevice *m_mediaStream;
- QMediaContent m_resources;
-
- bool m_muted;
- bool m_tryingAsync;
- int m_volume;
- qreal m_rate;
- qint64 m_requestedPosition;
-
- qint64 m_duration;
- int m_bufferStatus;
- bool m_videoAvailable;
- bool m_audioAvailable;
- bool m_seekable;
-
- void *m_observer;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFMEDIAPLAYERSESSION_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm
deleted file mode 100644
index 95121f58a..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm
+++ /dev/null
@@ -1,1067 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfmediaplayersession.h"
-#include "avfmediaplayerservice.h"
-#include "avfvideooutput.h"
-
-#include <qpointer.h>
-#include <QFileInfo>
-
-#import <AVFoundation/AVFoundation.h>
-
-QT_USE_NAMESPACE
-
-//AVAsset Keys
-static NSString* const AVF_TRACKS_KEY = @"tracks";
-static NSString* const AVF_PLAYABLE_KEY = @"playable";
-
-//AVPlayerItem keys
-static NSString* const AVF_STATUS_KEY = @"status";
-static NSString* const AVF_BUFFER_LIKELY_KEEP_UP_KEY = @"playbackLikelyToKeepUp";
-
-//AVPlayer keys
-static NSString* const AVF_RATE_KEY = @"rate";
-static NSString* const AVF_CURRENT_ITEM_KEY = @"currentItem";
-static NSString* const AVF_CURRENT_ITEM_DURATION_KEY = @"currentItem.duration";
-
-static void *AVFMediaPlayerSessionObserverRateObservationContext = &AVFMediaPlayerSessionObserverRateObservationContext;
-static void *AVFMediaPlayerSessionObserverStatusObservationContext = &AVFMediaPlayerSessionObserverStatusObservationContext;
-static void *AVFMediaPlayerSessionObserverBufferLikelyToKeepUpContext = &AVFMediaPlayerSessionObserverBufferLikelyToKeepUpContext;
-static void *AVFMediaPlayerSessionObserverCurrentItemObservationContext = &AVFMediaPlayerSessionObserverCurrentItemObservationContext;
-static void *AVFMediaPlayerSessionObserverCurrentItemDurationObservationContext = &AVFMediaPlayerSessionObserverCurrentItemDurationObservationContext;
-
-@interface AVFMediaPlayerSessionObserver : NSObject<AVAssetResourceLoaderDelegate>
-
-@property (readonly, getter=player) AVPlayer* m_player;
-@property (readonly, getter=playerItem) AVPlayerItem* m_playerItem;
-@property (readonly, getter=playerLayer) AVPlayerLayer* m_playerLayer;
-@property (readonly, getter=session) AVFMediaPlayerSession* m_session;
-
-- (AVFMediaPlayerSessionObserver *) initWithMediaPlayerSession:(AVFMediaPlayerSession *)session;
-- (void) setURL:(NSURL *)url mimeType:(NSString *)mimeType;
-- (void) unloadMedia;
-- (void) prepareToPlayAsset:(AVURLAsset *)asset withKeys:(NSArray *)requestedKeys;
-- (void) assetFailedToPrepareForPlayback:(NSError *)error;
-- (void) playerItemDidReachEnd:(NSNotification *)notification;
-- (void) playerItemTimeJumped:(NSNotification *)notification;
-- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
- change:(NSDictionary *)change context:(void *)context;
-- (void) detatchSession;
-- (void) dealloc;
-- (BOOL) resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest;
-@end
-
-@implementation AVFMediaPlayerSessionObserver
-{
-@private
- AVFMediaPlayerSession *m_session;
- AVPlayer *m_player;
- AVPlayerItem *m_playerItem;
- AVPlayerLayer *m_playerLayer;
- NSURL *m_URL;
- BOOL m_bufferIsLikelyToKeepUp;
- NSData *m_data;
- NSString *m_mimeType;
-}
-
-@synthesize m_player, m_playerItem, m_playerLayer, m_session;
-
-- (AVFMediaPlayerSessionObserver *) initWithMediaPlayerSession:(AVFMediaPlayerSession *)session
-{
- if (!(self = [super init]))
- return nil;
-
- self->m_session = session;
- self->m_bufferIsLikelyToKeepUp = FALSE;
- return self;
-}
-
-- (void) setURL:(NSURL *)url mimeType:(NSString *)mimeType
-{
- [m_mimeType release];
- m_mimeType = [mimeType retain];
-
- if (m_URL != url)
- {
- [m_URL release];
- m_URL = [url copy];
-
- //Create an asset for inspection of a resource referenced by a given URL.
- //Load the values for the asset keys "tracks", "playable".
-
- // use __block to avoid maintaining strong references on variables captured by the
- // following block callback
- __block AVURLAsset *asset = [[AVURLAsset URLAssetWithURL:m_URL options:nil] retain];
- [asset.resourceLoader setDelegate:self queue:dispatch_get_main_queue()];
-
- __block NSArray *requestedKeys = [[NSArray arrayWithObjects:AVF_TRACKS_KEY, AVF_PLAYABLE_KEY, nil] retain];
-
- __block AVFMediaPlayerSessionObserver *blockSelf = self;
- QPointer<AVFMediaPlayerSession> session(m_session);
-
- // Tells the asset to load the values of any of the specified keys that are not already loaded.
- [asset loadValuesAsynchronouslyForKeys:requestedKeys completionHandler:
- ^{
- dispatch_async( dispatch_get_main_queue(),
- ^{
- if (session)
- [blockSelf prepareToPlayAsset:asset withKeys:requestedKeys];
- [asset release];
- [requestedKeys release];
- });
- }];
- }
-}
-
-- (void) unloadMedia
-{
- if (m_playerItem) {
- [m_playerItem removeObserver:self forKeyPath:AVF_STATUS_KEY];
- [m_playerItem removeObserver:self forKeyPath:AVF_BUFFER_LIKELY_KEEP_UP_KEY];
-
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:AVPlayerItemDidPlayToEndTimeNotification
- object:m_playerItem];
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:AVPlayerItemTimeJumpedNotification
- object:m_playerItem];
- m_playerItem = 0;
- }
- if (m_player) {
- [m_player setRate:0.0];
- [m_player removeObserver:self forKeyPath:AVF_CURRENT_ITEM_DURATION_KEY];
- [m_player removeObserver:self forKeyPath:AVF_CURRENT_ITEM_KEY];
- [m_player removeObserver:self forKeyPath:AVF_RATE_KEY];
- [m_player release];
- m_player = 0;
- }
- if (m_playerLayer) {
- [m_playerLayer release];
- m_playerLayer = 0;
- }
-#if defined(Q_OS_IOS)
- [[AVAudioSession sharedInstance] setActive:NO error:nil];
-#endif
-}
-
-- (void) prepareToPlayAsset:(AVURLAsset *)asset
- withKeys:(NSArray *)requestedKeys
-{
- //Make sure that the value of each key has loaded successfully.
- for (NSString *thisKey in requestedKeys)
- {
- NSError *error = nil;
- AVKeyValueStatus keyStatus = [asset statusOfValueForKey:thisKey error:&error];
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << [thisKey UTF8String] << " status: " << keyStatus;
-#endif
- if (keyStatus == AVKeyValueStatusFailed)
- {
- [self assetFailedToPrepareForPlayback:error];
- return;
- }
- }
-
- //Use the AVAsset playable property to detect whether the asset can be played.
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << "isPlayable: " << [asset isPlayable];
-#endif
- if (!asset.playable)
- {
- //Generate an error describing the failure.
- NSString *localizedDescription = NSLocalizedString(@"Item cannot be played", @"Item cannot be played description");
- NSString *localizedFailureReason = NSLocalizedString(@"The assets tracks were loaded, but could not be made playable.", @"Item cannot be played failure reason");
- NSDictionary *errorDict = [NSDictionary dictionaryWithObjectsAndKeys:
- localizedDescription, NSLocalizedDescriptionKey,
- localizedFailureReason, NSLocalizedFailureReasonErrorKey,
- nil];
- NSError *assetCannotBePlayedError = [NSError errorWithDomain:@"StitchedStreamPlayer" code:0 userInfo:errorDict];
-
- [self assetFailedToPrepareForPlayback:assetCannotBePlayedError];
-
- return;
- }
-
- //At this point we're ready to set up for playback of the asset.
- //Stop observing our prior AVPlayerItem, if we have one.
- if (m_playerItem)
- {
- //Remove existing player item key value observers and notifications.
- [self unloadMedia];
- }
-
- //Create a new instance of AVPlayerItem from the now successfully loaded AVAsset.
- m_playerItem = [AVPlayerItem playerItemWithAsset:asset];
-
- //Observe the player item "status" key to determine when it is ready to play.
- [m_playerItem addObserver:self
- forKeyPath:AVF_STATUS_KEY
- options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
- context:AVFMediaPlayerSessionObserverStatusObservationContext];
-
- [m_playerItem addObserver:self
- forKeyPath:AVF_BUFFER_LIKELY_KEEP_UP_KEY
- options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
- context:AVFMediaPlayerSessionObserverBufferLikelyToKeepUpContext];
-
- //When the player item has played to its end time we'll toggle
- //the movie controller Pause button to be the Play button
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(playerItemDidReachEnd:)
- name:AVPlayerItemDidPlayToEndTimeNotification
- object:m_playerItem];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(playerItemTimeJumped:)
- name:AVPlayerItemTimeJumpedNotification
- object:m_playerItem];
-
- //Get a new AVPlayer initialized to play the specified player item.
- m_player = [AVPlayer playerWithPlayerItem:m_playerItem];
- [m_player retain];
-
- //Set the initial volume on new player object
- if (self.session) {
- [m_player setVolume:m_session->volume() / 100.0f];
- [m_player setMuted:m_session->isMuted()];
- }
-
- //Create a new player layer if we don't have one already
- if (!m_playerLayer)
- {
- m_playerLayer = [AVPlayerLayer playerLayerWithPlayer:m_player];
- [m_playerLayer retain];
- m_playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
- m_playerLayer.anchorPoint = CGPointMake(0.0f, 0.0f);
- }
-
- //Observe the AVPlayer "currentItem" property to find out when any
- //AVPlayer replaceCurrentItemWithPlayerItem: replacement will/did
- //occur.
- [m_player addObserver:self
- forKeyPath:AVF_CURRENT_ITEM_KEY
- options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
- context:AVFMediaPlayerSessionObserverCurrentItemObservationContext];
-
- //Observe the AVPlayer "rate" property to update the scrubber control.
- [m_player addObserver:self
- forKeyPath:AVF_RATE_KEY
- options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
- context:AVFMediaPlayerSessionObserverRateObservationContext];
-
- //Observe the duration for getting the buffer state
- [m_player addObserver:self
- forKeyPath:AVF_CURRENT_ITEM_DURATION_KEY
- options:0
- context:AVFMediaPlayerSessionObserverCurrentItemDurationObservationContext];
-#if defined(Q_OS_IOS)
- [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
- [[AVAudioSession sharedInstance] setActive:YES error:nil];
-#endif
-}
-
--(void) assetFailedToPrepareForPlayback:(NSError *)error
-{
- Q_UNUSED(error);
- QMetaObject::invokeMethod(m_session, "processMediaLoadError", Qt::AutoConnection);
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
- qDebug() << [[error localizedDescription] UTF8String];
- qDebug() << [[error localizedFailureReason] UTF8String];
- qDebug() << [[error localizedRecoverySuggestion] UTF8String];
-#endif
-}
-
-- (void) playerItemDidReachEnd:(NSNotification *)notification
-{
- Q_UNUSED(notification);
- if (self.session)
- QMetaObject::invokeMethod(m_session, "processEOS", Qt::AutoConnection);
-}
-
-- (void) playerItemTimeJumped:(NSNotification *)notification
-{
- Q_UNUSED(notification);
- if (self.session)
- QMetaObject::invokeMethod(m_session, "processPositionChange", Qt::AutoConnection);
-}
-
-- (void) observeValueForKeyPath:(NSString*) path
- ofObject:(id)object
- change:(NSDictionary*)change
- context:(void*)context
-{
- //AVPlayerItem "status" property value observer.
- if (context == AVFMediaPlayerSessionObserverStatusObservationContext)
- {
- AVPlayerStatus status = (AVPlayerStatus)[[change objectForKey:NSKeyValueChangeNewKey] integerValue];
- switch (status)
- {
- //Indicates that the status of the player is not yet known because
- //it has not tried to load new media resources for playback
- case AVPlayerStatusUnknown:
- {
- //QMetaObject::invokeMethod(m_session, "processLoadStateChange", Qt::AutoConnection);
- }
- break;
-
- case AVPlayerStatusReadyToPlay:
- {
- //Once the AVPlayerItem becomes ready to play, i.e.
- //[playerItem status] == AVPlayerItemStatusReadyToPlay,
- //its duration can be fetched from the item.
- if (self.session)
- QMetaObject::invokeMethod(m_session, "processLoadStateChange", Qt::AutoConnection);
- }
- break;
-
- case AVPlayerStatusFailed:
- {
- AVPlayerItem *playerItem = static_cast<AVPlayerItem*>(object);
- [self assetFailedToPrepareForPlayback:playerItem.error];
-
- if (self.session)
- QMetaObject::invokeMethod(m_session, "processLoadStateFailure", Qt::AutoConnection);
- }
- break;
- }
- }
- else if (context == AVFMediaPlayerSessionObserverBufferLikelyToKeepUpContext)
- {
- const bool isPlaybackLikelyToKeepUp = [m_playerItem isPlaybackLikelyToKeepUp];
- if (isPlaybackLikelyToKeepUp != m_bufferIsLikelyToKeepUp) {
- m_bufferIsLikelyToKeepUp = isPlaybackLikelyToKeepUp;
- QMetaObject::invokeMethod(m_session, "processBufferStateChange", Qt::AutoConnection,
- Q_ARG(int, isPlaybackLikelyToKeepUp ? 100 : 0));
- }
- }
- //AVPlayer "rate" property value observer.
- else if (context == AVFMediaPlayerSessionObserverRateObservationContext)
- {
- //QMetaObject::invokeMethod(m_session, "setPlaybackRate", Qt::AutoConnection, Q_ARG(qreal, [m_player rate]));
- }
- //AVPlayer "currentItem" property observer.
- //Called when the AVPlayer replaceCurrentItemWithPlayerItem:
- //replacement will/did occur.
- else if (context == AVFMediaPlayerSessionObserverCurrentItemObservationContext)
- {
- AVPlayerItem *newPlayerItem = [change objectForKey:NSKeyValueChangeNewKey];
- if (m_playerItem != newPlayerItem)
- m_playerItem = newPlayerItem;
- }
- else if (context == AVFMediaPlayerSessionObserverCurrentItemDurationObservationContext)
- {
- const CMTime time = [m_playerItem duration];
- const qint64 duration = static_cast<qint64>(float(time.value) / float(time.timescale) * 1000.0f);
- if (self.session)
- QMetaObject::invokeMethod(m_session, "processDurationChange", Qt::AutoConnection, Q_ARG(qint64, duration));
- }
- else
- {
- [super observeValueForKeyPath:path ofObject:object change:change context:context];
- }
-}
-
-- (void) detatchSession
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
- m_session = 0;
-}
-
-- (void) dealloc
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
- [self unloadMedia];
-
- if (m_URL) {
- [m_URL release];
- }
-
- [m_mimeType release];
- [super dealloc];
-}
-
-- (BOOL) resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
-{
- Q_UNUSED(resourceLoader);
-
- if (![loadingRequest.request.URL.scheme isEqualToString:@"iodevice"])
- return NO;
-
- QIODevice *device = m_session->mediaStream();
- if (!device)
- return NO;
-
- device->seek(loadingRequest.dataRequest.requestedOffset);
- if (loadingRequest.contentInformationRequest) {
- loadingRequest.contentInformationRequest.contentType = m_mimeType;
- loadingRequest.contentInformationRequest.contentLength = device->size();
- loadingRequest.contentInformationRequest.byteRangeAccessSupported = YES;
- }
-
- if (loadingRequest.dataRequest) {
- NSInteger requestedLength = loadingRequest.dataRequest.requestedLength;
- int maxBytes = qMin(32 * 1064, int(requestedLength));
- char buffer[maxBytes];
- NSInteger submitted = 0;
- while (submitted < requestedLength) {
- qint64 len = device->read(buffer, maxBytes);
- if (len < 1)
- break;
-
- [loadingRequest.dataRequest respondWithData:[NSData dataWithBytes:buffer length:len]];
- submitted += len;
- }
-
- // Finish loading even if not all bytes submitted.
- [loadingRequest finishLoading];
- }
-
- return YES;
-}
-@end
-
-AVFMediaPlayerSession::AVFMediaPlayerSession(AVFMediaPlayerService *service, QObject *parent)
- : QObject(parent)
- , m_service(service)
- , m_videoOutput(nullptr)
- , m_state(QMediaPlayer::StoppedState)
- , m_mediaStatus(QMediaPlayer::NoMedia)
- , m_mediaStream(nullptr)
- , m_muted(false)
- , m_tryingAsync(false)
- , m_volume(100)
- , m_rate(1.0)
- , m_requestedPosition(-1)
- , m_duration(0)
- , m_bufferStatus(0)
- , m_videoAvailable(false)
- , m_audioAvailable(false)
- , m_seekable(false)
-{
- m_observer = [[AVFMediaPlayerSessionObserver alloc] initWithMediaPlayerSession:this];
-}
-
-AVFMediaPlayerSession::~AVFMediaPlayerSession()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
- //Detatch the session from the sessionObserver (which could still be alive trying to communicate with this session).
- [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) detatchSession];
- [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) release];
-}
-
-void AVFMediaPlayerSession::setVideoOutput(AVFVideoOutput *output)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << output;
-#endif
-
- if (m_videoOutput == output)
- return;
-
- //Set the current output layer to null to stop rendering
- if (m_videoOutput) {
- m_videoOutput->setLayer(nullptr);
- }
-
- m_videoOutput = output;
-
- if (m_videoOutput && m_state != QMediaPlayer::StoppedState)
- m_videoOutput->setLayer([static_cast<AVFMediaPlayerSessionObserver*>(m_observer) playerLayer]);
-}
-
-void *AVFMediaPlayerSession::currentAssetHandle()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
- AVAsset *currentAsset = [[static_cast<AVFMediaPlayerSessionObserver*>(m_observer) playerItem] asset];
- return currentAsset;
-}
-
-QMediaPlayer::State AVFMediaPlayerSession::state() const
-{
- return m_state;
-}
-
-QMediaPlayer::MediaStatus AVFMediaPlayerSession::mediaStatus() const
-{
- return m_mediaStatus;
-}
-
-QMediaContent AVFMediaPlayerSession::media() const
-{
- return m_resources;
-}
-
-QIODevice *AVFMediaPlayerSession::mediaStream() const
-{
- return m_mediaStream;
-}
-
-static void setURL(void *observer, const QByteArray &url, const QString &mimeType = QString())
-{
- NSString *urlString = [NSString stringWithUTF8String:url.constData()];
- NSURL *nsurl = [NSURL URLWithString:urlString];
- [static_cast<AVFMediaPlayerSessionObserver*>(observer) setURL:nsurl mimeType:[NSString stringWithUTF8String:mimeType.toLatin1().constData()]];
-}
-
-static void setStreamURL(void *observer, const QByteArray &url)
-{
- setURL(observer, QByteArrayLiteral("iodevice://") + url, QFileInfo(url).suffix());
-}
-
-void AVFMediaPlayerSession::setMedia(const QMediaContent &content, QIODevice *stream)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << content.request().url();
-#endif
-
- [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) unloadMedia];
-
- m_resources = content;
- resetStream(stream);
-
- setAudioAvailable(false);
- setVideoAvailable(false);
- setSeekable(false);
- m_requestedPosition = -1;
- Q_EMIT positionChanged(position());
-
- const QMediaPlayer::MediaStatus oldMediaStatus = m_mediaStatus;
- const QMediaPlayer::State oldState = m_state;
-
- if (!m_mediaStream && (content.isNull() || content.request().url().isEmpty())) {
- m_mediaStatus = QMediaPlayer::NoMedia;
- if (m_mediaStatus != oldMediaStatus)
- Q_EMIT mediaStatusChanged(m_mediaStatus);
-
- m_state = QMediaPlayer::StoppedState;
- if (m_state != oldState)
- Q_EMIT stateChanged(m_state);
-
- return;
- }
-
- m_mediaStatus = QMediaPlayer::LoadingMedia;
- if (m_mediaStatus != oldMediaStatus)
- Q_EMIT mediaStatusChanged(m_mediaStatus);
-
- if (m_mediaStream) {
- // If there is a data, try to load it,
- // otherwise wait for readyRead.
- if (m_mediaStream->size())
- setStreamURL(m_observer, m_resources.request().url().toEncoded());
- } else {
- //Load AVURLAsset
- //initialize asset using content's URL
- setURL(m_observer, m_resources.request().url().toEncoded());
- }
-
- m_state = QMediaPlayer::StoppedState;
- if (m_state != oldState)
- Q_EMIT stateChanged(m_state);
-}
-
-qint64 AVFMediaPlayerSession::position() const
-{
- AVPlayerItem *playerItem = [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) playerItem];
-
- if (!playerItem)
- return m_requestedPosition != -1 ? m_requestedPosition : 0;
-
- CMTime time = [playerItem currentTime];
- return static_cast<quint64>(float(time.value) / float(time.timescale) * 1000.0f);
-}
-
-qint64 AVFMediaPlayerSession::duration() const
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
- return m_duration;
-}
-
-int AVFMediaPlayerSession::bufferStatus() const
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
- return m_bufferStatus;
-}
-
-int AVFMediaPlayerSession::volume() const
-{
- return m_volume;
-}
-
-bool AVFMediaPlayerSession::isMuted() const
-{
- return m_muted;
-}
-
-void AVFMediaPlayerSession::setAudioAvailable(bool available)
-{
- if (m_audioAvailable == available)
- return;
-
- m_audioAvailable = available;
- Q_EMIT audioAvailableChanged(available);
-}
-
-bool AVFMediaPlayerSession::isAudioAvailable() const
-{
- return m_audioAvailable;
-}
-
-void AVFMediaPlayerSession::setVideoAvailable(bool available)
-{
- if (m_videoAvailable == available)
- return;
-
- m_videoAvailable = available;
- Q_EMIT videoAvailableChanged(available);
-}
-
-bool AVFMediaPlayerSession::isVideoAvailable() const
-{
- return m_videoAvailable;
-}
-
-bool AVFMediaPlayerSession::isSeekable() const
-{
- return m_seekable;
-}
-
-void AVFMediaPlayerSession::setSeekable(bool seekable)
-{
- if (m_seekable == seekable)
- return;
-
- m_seekable = seekable;
- Q_EMIT seekableChanged(seekable);
-}
-
-QMediaTimeRange AVFMediaPlayerSession::availablePlaybackRanges() const
-{
- AVPlayerItem *playerItem = [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) playerItem];
-
- if (playerItem) {
- QMediaTimeRange timeRanges;
-
- NSArray *ranges = [playerItem loadedTimeRanges];
- for (NSValue *timeRange in ranges) {
- CMTimeRange currentTimeRange = [timeRange CMTimeRangeValue];
- qint64 startTime = qint64(float(currentTimeRange.start.value) / currentTimeRange.start.timescale * 1000.0);
- timeRanges.addInterval(startTime, startTime + qint64(float(currentTimeRange.duration.value) / currentTimeRange.duration.timescale * 1000.0));
- }
- if (!timeRanges.isEmpty())
- return timeRanges;
- }
- return QMediaTimeRange(0, duration());
-}
-
-qreal AVFMediaPlayerSession::playbackRate() const
-{
- return m_rate;
-}
-
-void AVFMediaPlayerSession::setPlaybackRate(qreal rate)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << rate;
-#endif
-
- if (qFuzzyCompare(m_rate, rate))
- return;
-
- m_rate = rate;
-
- AVPlayer *player = [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) player];
- if (player && m_state == QMediaPlayer::PlayingState)
- [player setRate:m_rate];
-
- Q_EMIT playbackRateChanged(m_rate);
-}
-
-void AVFMediaPlayerSession::setPosition(qint64 pos)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << pos;
-#endif
-
- if (pos == position())
- return;
-
- AVPlayerItem *playerItem = [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) playerItem];
- if (!playerItem) {
- m_requestedPosition = pos;
- Q_EMIT positionChanged(m_requestedPosition);
- return;
- }
-
- if (!isSeekable()) {
- if (m_requestedPosition != -1) {
- m_requestedPosition = -1;
- Q_EMIT positionChanged(position());
- }
- return;
- }
-
- pos = qMax(qint64(0), pos);
- if (duration() > 0)
- pos = qMin(pos, duration());
-
- CMTime newTime = [playerItem currentTime];
- newTime.value = (pos / 1000.0f) * newTime.timescale;
- [playerItem seekToTime:newTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:nil];
-
- Q_EMIT positionChanged(pos);
-
- // Reset media status if the current status is EndOfMedia
- if (m_mediaStatus == QMediaPlayer::EndOfMedia) {
- QMediaPlayer::MediaStatus newMediaStatus = (m_state == QMediaPlayer::PausedState) ? QMediaPlayer::BufferedMedia
- : QMediaPlayer::LoadedMedia;
- Q_EMIT mediaStatusChanged((m_mediaStatus = newMediaStatus));
- }
-}
-
-void AVFMediaPlayerSession::play()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << "currently: " << m_state;
-#endif
-
- if (m_mediaStatus == QMediaPlayer::NoMedia || m_mediaStatus == QMediaPlayer::InvalidMedia)
- return;
-
- if (m_state == QMediaPlayer::PlayingState)
- return;
-
- if (m_videoOutput) {
- m_videoOutput->setLayer([static_cast<AVFMediaPlayerSessionObserver*>(m_observer) playerLayer]);
- }
-
- // Reset media status if the current status is EndOfMedia
- if (m_mediaStatus == QMediaPlayer::EndOfMedia)
- setPosition(0);
-
- if (m_mediaStatus == QMediaPlayer::LoadedMedia || m_mediaStatus == QMediaPlayer::BufferedMedia) {
- // Setting the rate starts playback
- [[static_cast<AVFMediaPlayerSessionObserver*>(m_observer) player] setRate:m_rate];
- }
-
- m_state = QMediaPlayer::PlayingState;
- processLoadStateChange();
-
- Q_EMIT stateChanged(m_state);
-}
-
-void AVFMediaPlayerSession::pause()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << "currently: " << m_state;
-#endif
-
- if (m_mediaStatus == QMediaPlayer::NoMedia)
- return;
-
- if (m_state == QMediaPlayer::PausedState)
- return;
-
- m_state = QMediaPlayer::PausedState;
-
- if (m_videoOutput) {
- m_videoOutput->setLayer([static_cast<AVFMediaPlayerSessionObserver*>(m_observer) playerLayer]);
- }
-
- [[static_cast<AVFMediaPlayerSessionObserver*>(m_observer) player] pause];
-
- // Reset media status if the current status is EndOfMedia
- if (m_mediaStatus == QMediaPlayer::EndOfMedia)
- setPosition(0);
-
-
- Q_EMIT stateChanged(m_state);
-}
-
-void AVFMediaPlayerSession::stop()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << "currently: " << m_state;
-#endif
-
- if (m_state == QMediaPlayer::StoppedState)
- return;
-
- // AVPlayer doesn't have stop(), only pause() and play().
- [[static_cast<AVFMediaPlayerSessionObserver*>(m_observer) player] pause];
- setPosition(0);
-
- if (m_videoOutput) {
- m_videoOutput->setLayer(nullptr);
- }
-
- if (m_mediaStatus == QMediaPlayer::BufferedMedia)
- Q_EMIT mediaStatusChanged((m_mediaStatus = QMediaPlayer::LoadedMedia));
-
- Q_EMIT positionChanged(position());
- Q_EMIT stateChanged((m_state = QMediaPlayer::StoppedState));
-}
-
-void AVFMediaPlayerSession::setVolume(int volume)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << volume;
-#endif
-
- if (m_volume == volume)
- return;
-
- m_volume = volume;
-
- AVPlayer *player = [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) player];
- if (player)
- [player setVolume:volume / 100.0f];
-
- Q_EMIT volumeChanged(m_volume);
-}
-
-void AVFMediaPlayerSession::setMuted(bool muted)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << muted;
-#endif
-
- if (m_muted == muted)
- return;
-
- m_muted = muted;
-
- AVPlayer *player = [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) player];
- if (player)
- [player setMuted:muted];
-
- Q_EMIT mutedChanged(muted);
-}
-
-void AVFMediaPlayerSession::processEOS()
-{
- //AVPlayerItem has reached end of track/stream
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
- Q_EMIT positionChanged(position());
- m_mediaStatus = QMediaPlayer::EndOfMedia;
- m_state = QMediaPlayer::StoppedState;
-
- // At this point, frames should not be rendered anymore.
- // Clear the output layer to make sure of that.
- if (m_videoOutput)
- m_videoOutput->setLayer(nullptr);
-
- Q_EMIT mediaStatusChanged(m_mediaStatus);
- Q_EMIT stateChanged(m_state);
-}
-
-void AVFMediaPlayerSession::processLoadStateChange(QMediaPlayer::State newState)
-{
- AVPlayerStatus currentStatus = [[static_cast<AVFMediaPlayerSessionObserver*>(m_observer) player] status];
-
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << currentStatus << ", " << m_mediaStatus << ", " << newState;
-#endif
-
- if (m_mediaStatus == QMediaPlayer::NoMedia)
- return;
-
- if (currentStatus == AVPlayerStatusReadyToPlay) {
-
- QMediaPlayer::MediaStatus newStatus = m_mediaStatus;
-
- AVPlayerItem *playerItem = [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) playerItem];
-
- if (playerItem) {
- // Check each track for audio and video content
- AVAssetTrack *videoTrack = nil;
- NSArray *tracks = playerItem.tracks;
- for (AVPlayerItemTrack *track in tracks) {
- AVAssetTrack *assetTrack = track.assetTrack;
- if (assetTrack) {
- if ([assetTrack.mediaType isEqualToString:AVMediaTypeAudio])
- setAudioAvailable(true);
- if ([assetTrack.mediaType isEqualToString:AVMediaTypeVideo]) {
- setVideoAvailable(true);
- if (!videoTrack)
- videoTrack = assetTrack;
- }
- }
- }
-
- setSeekable([[playerItem seekableTimeRanges] count] > 0);
-
- // Get the native size of the video, and reset the bounds of the player layer
- AVPlayerLayer *playerLayer = [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) playerLayer];
- if (videoTrack && playerLayer) {
- if (!playerLayer.bounds.size.width || !playerLayer.bounds.size.height) {
- playerLayer.bounds = CGRectMake(0.0f, 0.0f,
- videoTrack.naturalSize.width,
- videoTrack.naturalSize.height);
- }
-
- if (m_videoOutput && newState != QMediaPlayer::StoppedState) {
- m_videoOutput->setLayer(playerLayer);
- }
- }
-
- if (m_requestedPosition != -1) {
- setPosition(m_requestedPosition);
- m_requestedPosition = -1;
- }
- }
-
- newStatus = (newState != QMediaPlayer::StoppedState) ? QMediaPlayer::BufferedMedia
- : QMediaPlayer::LoadedMedia;
-
- if (newStatus != m_mediaStatus)
- Q_EMIT mediaStatusChanged((m_mediaStatus = newStatus));
-
- }
-
- if (newState == QMediaPlayer::PlayingState && [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) player]) {
- // Setting the rate is enough to start playback, no need to call play()
- [[static_cast<AVFMediaPlayerSessionObserver*>(m_observer) player] setRate:m_rate];
- }
-}
-
-
-void AVFMediaPlayerSession::processLoadStateChange()
-{
- processLoadStateChange(m_state);
-}
-
-
-void AVFMediaPlayerSession::processLoadStateFailure()
-{
- Q_EMIT stateChanged((m_state = QMediaPlayer::StoppedState));
-}
-
-void AVFMediaPlayerSession::processBufferStateChange(int bufferStatus)
-{
- if (bufferStatus == m_bufferStatus)
- return;
-
- auto status = m_mediaStatus;
- // Buffered -> unbuffered.
- if (!bufferStatus) {
- status = QMediaPlayer::StalledMedia;
- } else if (status == QMediaPlayer::StalledMedia) {
- status = QMediaPlayer::BufferedMedia;
- // Resume playback.
- if (m_state == QMediaPlayer::PlayingState)
- [[static_cast<AVFMediaPlayerSessionObserver*>(m_observer) player] setRate:m_rate];
- }
-
- if (m_mediaStatus != status)
- Q_EMIT mediaStatusChanged(m_mediaStatus = status);
-
- m_bufferStatus = bufferStatus;
- Q_EMIT bufferStatusChanged(bufferStatus);
-}
-
-void AVFMediaPlayerSession::processDurationChange(qint64 duration)
-{
- if (duration == m_duration)
- return;
-
- m_duration = duration;
- Q_EMIT durationChanged(duration);
-}
-
-void AVFMediaPlayerSession::processPositionChange()
-{
- if (m_state == QMediaPlayer::StoppedState)
- return;
-
- Q_EMIT positionChanged(position());
-}
-
-void AVFMediaPlayerSession::processMediaLoadError()
-{
- if (m_requestedPosition != -1) {
- m_requestedPosition = -1;
- Q_EMIT positionChanged(position());
- }
-
- Q_EMIT mediaStatusChanged((m_mediaStatus = QMediaPlayer::InvalidMedia));
-
- Q_EMIT error(QMediaPlayer::FormatError, tr("Failed to load media"));
-}
-
-void AVFMediaPlayerSession::streamReady()
-{
- setStreamURL(m_observer, m_resources.request().url().toEncoded());
-}
-
-void AVFMediaPlayerSession::streamDestroyed()
-{
- resetStream(nullptr);
-}
-
-void AVFMediaPlayerSession::resetStream(QIODevice *stream)
-{
- if (m_mediaStream) {
- disconnect(m_mediaStream, &QIODevice::readyRead, this, &AVFMediaPlayerSession::streamReady);
- disconnect(m_mediaStream, &QIODevice::destroyed, this, &AVFMediaPlayerSession::streamDestroyed);
- }
-
- m_mediaStream = stream;
-
- if (m_mediaStream) {
- connect(m_mediaStream, &QIODevice::readyRead, this, &AVFMediaPlayerSession::streamReady);
- connect(m_mediaStream, &QIODevice::destroyed, this, &AVFMediaPlayerSession::streamDestroyed);
- }
-}
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.h b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.h
deleted file mode 100644
index d4f74964a..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFVIDEOFRAMERENDERER_H
-#define AVFVIDEOFRAMERENDERER_H
-
-#include <QtCore/QObject>
-#include <QtGui/QImage>
-#include <QtGui/QOpenGLContext>
-#include <QtCore/QSize>
-
-#import "Metal/Metal.h"
-#import "MetalKit/MetalKit.h"
-
-@class CARenderer;
-@class AVPlayerLayer;
-
-QT_BEGIN_NAMESPACE
-
-class QOpenGLFramebufferObject;
-class QWindow;
-class QOpenGLContext;
-class QAbstractVideoSurface;
-
-class AVFVideoFrameRenderer : public QObject
-{
-public:
- AVFVideoFrameRenderer(QAbstractVideoSurface *surface, QObject *parent = nullptr);
-
- virtual ~AVFVideoFrameRenderer();
-
- quint64 renderLayerToTexture(AVPlayerLayer *layer);
- quint64 renderLayerToMTLTexture(AVPlayerLayer *layer);
- QImage renderLayerToImage(AVPlayerLayer *layer);
-
-private:
- QOpenGLFramebufferObject* initRenderer(AVPlayerLayer *layer);
- void renderLayerToFBO(AVPlayerLayer *layer, QOpenGLFramebufferObject *fbo);
-
- CARenderer *m_videoLayerRenderer;
- QAbstractVideoSurface *m_surface;
- QOpenGLFramebufferObject *m_fbo[2];
- QWindow *m_offscreenSurface;
- QOpenGLContext *m_glContext;
- QSize m_targetSize;
-
- uint m_currentBuffer;
- bool m_isContextShared;
-
- id<MTLDevice> m_metalDevice = nil;
- id<MTLTexture> m_metalTexture = nil;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFVIDEOFRAMERENDERER_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm
deleted file mode 100644
index f81412d65..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm
+++ /dev/null
@@ -1,276 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfvideoframerenderer.h"
-
-#include <QtMultimedia/qabstractvideosurface.h>
-#include <QtOpenGL/QOpenGLFramebufferObject>
-#include <QtGui/QWindow>
-
-#ifdef QT_DEBUG_AVF
-#include <QtCore/qdebug.h>
-#endif
-
-#import <CoreVideo/CVBase.h>
-#import <AVFoundation/AVFoundation.h>
-
-QT_USE_NAMESPACE
-
-AVFVideoFrameRenderer::AVFVideoFrameRenderer(QAbstractVideoSurface *surface, QObject *parent)
- : QObject(parent)
- , m_videoLayerRenderer(nullptr)
- , m_surface(surface)
- , m_offscreenSurface(nullptr)
- , m_glContext(nullptr)
- , m_currentBuffer(1)
- , m_isContextShared(true)
-{
- m_fbo[0] = nullptr;
- m_fbo[1] = nullptr;
-}
-
-AVFVideoFrameRenderer::~AVFVideoFrameRenderer()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
-
- [m_videoLayerRenderer release];
- [m_metalDevice release];
- delete m_fbo[0];
- delete m_fbo[1];
- delete m_offscreenSurface;
- delete m_glContext;
-}
-
-quint64 AVFVideoFrameRenderer::renderLayerToTexture(AVPlayerLayer *layer)
-{
- //Is layer valid
- if (!layer)
- return 0;
-
- //If the glContext isn't shared, it doesn't make sense to return a texture for us
- if (m_offscreenSurface && !m_isContextShared)
- return 0;
-
- QOpenGLFramebufferObject *fbo = initRenderer(layer);
-
- if (!fbo)
- return 0;
-
- renderLayerToFBO(layer, fbo);
- if (m_glContext)
- m_glContext->doneCurrent();
-
- return fbo->texture();
-}
-
-quint64 AVFVideoFrameRenderer::renderLayerToMTLTexture(AVPlayerLayer *layer)
-{
- m_targetSize = QSize(layer.bounds.size.width, layer.bounds.size.height);
-
- if (!m_metalDevice)
- m_metalDevice = MTLCreateSystemDefaultDevice();
-
- if (!m_metalTexture) {
- auto desc = [[MTLTextureDescriptor alloc] init];
- desc.textureType = MTLTextureType2D;
- desc.width = NSUInteger(m_targetSize.width());
- desc.height = NSUInteger(m_targetSize.height());
- desc.resourceOptions = MTLResourceStorageModePrivate;
- desc.usage = MTLTextureUsageRenderTarget;
- desc.pixelFormat = MTLPixelFormatRGBA8Unorm;
-
- m_metalTexture = [m_metalDevice newTextureWithDescriptor: desc];
- [desc release];
- }
-
- if (!m_videoLayerRenderer) {
- m_videoLayerRenderer = [CARenderer rendererWithMTLTexture:m_metalTexture options:nil];
- [m_videoLayerRenderer retain];
- }
-
- if (m_videoLayerRenderer.layer != layer) {
- m_videoLayerRenderer.layer = layer;
- m_videoLayerRenderer.bounds = layer.bounds;
- }
-
- [m_videoLayerRenderer beginFrameAtTime:CACurrentMediaTime() timeStamp:NULL];
- [m_videoLayerRenderer addUpdateRect:layer.bounds];
- [m_videoLayerRenderer render];
- [m_videoLayerRenderer endFrame];
-
- return quint64(m_metalTexture);
-}
-
-QImage AVFVideoFrameRenderer::renderLayerToImage(AVPlayerLayer *layer)
-{
- //Is layer valid
- if (!layer) {
- return QImage();
- }
-
- QOpenGLFramebufferObject *fbo = initRenderer(layer);
-
- if (!fbo)
- return QImage();
-
- renderLayerToFBO(layer, fbo);
- QImage fboImage = fbo->toImage();
- if (m_glContext)
- m_glContext->doneCurrent();
-
- return fboImage;
-}
-
-QOpenGLFramebufferObject *AVFVideoFrameRenderer::initRenderer(AVPlayerLayer *layer)
-{
-
- //Get size from AVPlayerLayer
- m_targetSize = QSize(layer.bounds.size.width, layer.bounds.size.height);
-
- QOpenGLContext *shareContext = !m_glContext && m_surface
- ? qobject_cast<QOpenGLContext*>(m_surface->property("GLContext").value<QObject*>())
- : nullptr;
-
- //Make sure we have an OpenGL context to make current
- if (shareContext || (!QOpenGLContext::currentContext() && !m_glContext)) {
-
- //Create Hidden QWindow surface to create context in this thread
- delete m_offscreenSurface;
- m_offscreenSurface = new QWindow();
- m_offscreenSurface->setSurfaceType(QWindow::OpenGLSurface);
- //Needs geometry to be a valid surface, but size is not important
- m_offscreenSurface->setGeometry(0, 0, 1, 1);
- m_offscreenSurface->create();
-
- delete m_glContext;
- m_glContext = new QOpenGLContext();
- m_glContext->setFormat(m_offscreenSurface->requestedFormat());
-
- if (shareContext) {
- m_glContext->setShareContext(shareContext);
- m_isContextShared = true;
- } else {
-#ifdef QT_DEBUG_AVF
- qWarning("failed to get Render Thread context");
-#endif
- m_isContextShared = false;
- }
- if (!m_glContext->create()) {
- qWarning("failed to create QOpenGLContext");
- return nullptr;
- }
-
- // CARenderer must be re-created with different current context, so release it now.
- // See lines below where m_videoLayerRenderer is constructed.
- if (m_videoLayerRenderer) {
- [m_videoLayerRenderer release];
- m_videoLayerRenderer = nullptr;
- }
- }
-
- //Need current context
- if (m_glContext)
- m_glContext->makeCurrent(m_offscreenSurface);
-
- //Create the CARenderer if needed
- if (!m_videoLayerRenderer) {
- m_videoLayerRenderer = [CARenderer rendererWithCGLContext: CGLGetCurrentContext() options: nil];
- [m_videoLayerRenderer retain];
- }
-
- //Set/Change render source if needed
- if (m_videoLayerRenderer.layer != layer) {
- m_videoLayerRenderer.layer = layer;
- m_videoLayerRenderer.bounds = layer.bounds;
- }
-
- //Do we have FBO's already?
- if ((!m_fbo[0] && !m_fbo[0]) || (m_fbo[0]->size() != m_targetSize)) {
- delete m_fbo[0];
- delete m_fbo[1];
- m_fbo[0] = new QOpenGLFramebufferObject(m_targetSize);
- m_fbo[1] = new QOpenGLFramebufferObject(m_targetSize);
- }
-
- //Switch buffer target
- m_currentBuffer = !m_currentBuffer;
- return m_fbo[m_currentBuffer];
-}
-
-void AVFVideoFrameRenderer::renderLayerToFBO(AVPlayerLayer *layer, QOpenGLFramebufferObject *fbo)
-{
- //Start Rendering
- //NOTE: This rendering method will NOT work on iOS as there is no CARenderer in iOS
- if (!fbo->bind()) {
- qWarning("AVFVideoRender FBO failed to bind");
- return;
- }
-
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
-
- glViewport(0, 0, m_targetSize.width(), m_targetSize.height());
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
-
- //Render to FBO with inverted Y
- glOrtho(0.0, m_targetSize.width(), 0.0, m_targetSize.height(), 0.0, 1.0);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-
- [m_videoLayerRenderer beginFrameAtTime:CACurrentMediaTime() timeStamp:NULL];
- [m_videoLayerRenderer addUpdateRect:layer.bounds];
- [m_videoLayerRenderer render];
- [m_videoLayerRenderer endFrame];
-
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
-
- glFinish(); //Rendering needs to be done before passing texture to video frame
-
- fbo->release();
-}
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer_ios.h b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer_ios.h
deleted file mode 100644
index d1de1f511..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer_ios.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFVIDEOFRAMERENDERER_H
-#define AVFVIDEOFRAMERENDERER_H
-
-#include <QtCore/QObject>
-#include <QtGui/QImage>
-#include <QtGui/QOpenGLContext>
-#include <QtCore/QSize>
-
-#import "Metal/Metal.h"
-#import "MetalKit/MetalKit.h"
-
-@class AVPlayerLayer;
-@class AVPlayerItemVideoOutput;
-
-QT_BEGIN_NAMESPACE
-
-class QOpenGLContext;
-class QOpenGLFramebufferObject;
-class QOpenGLShaderProgram;
-class QOffscreenSurface;
-class QAbstractVideoSurface;
-
-typedef struct __CVBuffer *CVBufferRef;
-typedef CVBufferRef CVImageBufferRef;
-typedef CVImageBufferRef CVPixelBufferRef;
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
-typedef struct __CVOpenGLESTextureCache *CVOpenGLESTextureCacheRef;
-typedef CVImageBufferRef CVOpenGLESTextureRef;
-// helpers to avoid boring if def
-typedef CVOpenGLESTextureCacheRef CVOGLTextureCacheRef;
-typedef CVOpenGLESTextureRef CVOGLTextureRef;
-#define CVOGLTextureGetTarget CVOpenGLESTextureGetTarget
-#define CVOGLTextureGetName CVOpenGLESTextureGetName
-#define CVOGLTextureCacheCreate CVOpenGLESTextureCacheCreate
-#define CVOGLTextureCacheCreateTextureFromImage CVOpenGLESTextureCacheCreateTextureFromImage
-#define CVOGLTextureCacheFlush CVOpenGLESTextureCacheFlush
-#else
-typedef struct __CVOpenGLTextureCache *CVOpenGLTextureCacheRef;
-typedef CVImageBufferRef CVOpenGLTextureRef;
-// helpers to avoid boring if def
-typedef CVOpenGLTextureCacheRef CVOGLTextureCacheRef;
-typedef CVOpenGLTextureRef CVOGLTextureRef;
-#define CVOGLTextureGetTarget CVOpenGLTextureGetTarget
-#define CVOGLTextureGetName CVOpenGLTextureGetName
-#define CVOGLTextureCacheCreate CVOpenGLTextureCacheCreate
-#define CVOGLTextureCacheCreateTextureFromImage CVOpenGLTextureCacheCreateTextureFromImage
-#define CVOGLTextureCacheFlush CVOpenGLTextureCacheFlush
-#endif
-
-class AVFVideoFrameRenderer : public QObject
-{
-public:
- AVFVideoFrameRenderer(QAbstractVideoSurface *surface, QObject *parent = nullptr);
-
- virtual ~AVFVideoFrameRenderer();
-
- void setPlayerLayer(AVPlayerLayer *layer);
-
- quint64 renderLayerToTexture(AVPlayerLayer *layer);
- quint64 renderLayerToMTLTexture(AVPlayerLayer *layer);
- QImage renderLayerToImage(AVPlayerLayer *layer);
-
-private:
- void initRenderer();
- CVPixelBufferRef copyPixelBufferFromLayer(AVPlayerLayer *layer, size_t& width, size_t& height);
- CVOGLTextureRef createCacheTextureFromLayer(AVPlayerLayer *layer, size_t& width, size_t& height);
-
- QOpenGLContext *m_glContext;
- QOffscreenSurface *m_offscreenSurface;
- QAbstractVideoSurface *m_surface;
- CVOGLTextureCacheRef m_textureCache;
- AVPlayerItemVideoOutput* m_videoOutput;
- bool m_isContextShared;
-
- id<MTLDevice> m_metalDevice = nil;
- CVMetalTextureCacheRef m_metalTextureCache = nil;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFVIDEOFRAMERENDERER_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer_ios.mm b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer_ios.mm
deleted file mode 100644
index cbaa1aa11..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer_ios.mm
+++ /dev/null
@@ -1,307 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfvideoframerenderer_ios.h"
-
-#include <QtMultimedia/qabstractvideosurface.h>
-#include <QtOpenGL/QOpenGLFramebufferObject>
-#include <QtOpenGL/QOpenGLShaderProgram>
-#include <QtGui/QOffscreenSurface>
-
-#ifdef QT_DEBUG_AVF
-#include <QtCore/qdebug.h>
-#endif
-
-#import <CoreVideo/CVBase.h>
-#import <AVFoundation/AVFoundation.h>
-QT_USE_NAMESPACE
-
-AVFVideoFrameRenderer::AVFVideoFrameRenderer(QAbstractVideoSurface *surface, QObject *parent)
- : QObject(parent)
- , m_glContext(nullptr)
- , m_offscreenSurface(nullptr)
- , m_surface(surface)
- , m_textureCache(nullptr)
- , m_videoOutput(nullptr)
- , m_isContextShared(true)
-{
-}
-
-AVFVideoFrameRenderer::~AVFVideoFrameRenderer()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
-
- [m_videoOutput release]; // sending to nil is fine
- if (m_textureCache)
- CFRelease(m_textureCache);
- if (m_metalTextureCache)
- CFRelease(m_metalTextureCache);
- [m_metalDevice release];
- delete m_offscreenSurface;
- delete m_glContext;
-}
-
-void AVFVideoFrameRenderer::setPlayerLayer(AVPlayerLayer *layer)
-{
- Q_UNUSED(layer);
- if (m_videoOutput) {
- [m_videoOutput release];
- m_videoOutput = nullptr;
- // will be re-created in first call to copyPixelBufferFromLayer
- }
-}
-
-quint64 AVFVideoFrameRenderer::renderLayerToMTLTexture(AVPlayerLayer *layer)
-{
- if (!m_metalDevice)
- m_metalDevice = MTLCreateSystemDefaultDevice();
-
- if (!m_metalTextureCache) {
- CVReturn err = CVMetalTextureCacheCreate(kCFAllocatorDefault, nullptr,
- m_metalDevice, nullptr, &m_metalTextureCache);
- if (err) {
- qWarning() << "Error at CVMetalTextureCacheCreate" << err;
- return 0;
- }
- }
-
- size_t width = 0, height = 0;
- CVPixelBufferRef pixelBuffer = copyPixelBufferFromLayer(layer, width, height);
-
- if (!pixelBuffer)
- return 0;
-
- CVMetalTextureCacheFlush(m_metalTextureCache, 0);
-
- CVMetalTextureRef texture = nil;
- CVReturn err = CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, m_metalTextureCache, pixelBuffer, NULL,
- MTLPixelFormatBGRA8Unorm_sRGB, width, height, 0, &texture);
-
- if (!texture || err)
- qWarning("CVMetalTextureCacheCreateTextureFromImage failed (error: %d)", err);
-
- CVPixelBufferRelease(pixelBuffer);
- quint64 tex = 0;
- if (texture) {
- tex = quint64(CVMetalTextureGetTexture(texture));
- CFRelease(texture);
- }
-
- return tex;
-}
-
-quint64 AVFVideoFrameRenderer::renderLayerToTexture(AVPlayerLayer *layer)
-{
- initRenderer();
-
- // If the glContext isn't shared, it doesn't make sense to return a texture for us
- if (!m_isContextShared)
- return 0;
-
- size_t dummyWidth = 0, dummyHeight = 0;
- auto texture = createCacheTextureFromLayer(layer, dummyWidth, dummyHeight);
- auto tex = quint64(CVOGLTextureGetName(texture));
- CFRelease(texture);
-
- return tex;
-}
-
-static NSString* const AVF_PIXEL_FORMAT_KEY = (NSString*)kCVPixelBufferPixelFormatTypeKey;
-static NSNumber* const AVF_PIXEL_FORMAT_VALUE = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
-static NSDictionary* const AVF_OUTPUT_SETTINGS = [NSDictionary dictionaryWithObject:AVF_PIXEL_FORMAT_VALUE forKey:AVF_PIXEL_FORMAT_KEY];
-
-
-CVPixelBufferRef AVFVideoFrameRenderer::copyPixelBufferFromLayer(AVPlayerLayer *layer,
- size_t& width, size_t& height)
-{
- //Is layer valid
- if (!layer) {
-#ifdef QT_DEBUG_AVF
- qWarning("copyPixelBufferFromLayer: invalid layer");
-#endif
- return nullptr;
- }
-
- if (!m_videoOutput) {
- m_videoOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:AVF_OUTPUT_SETTINGS];
- [m_videoOutput setDelegate:nil queue:nil];
- AVPlayerItem * item = [[layer player] currentItem];
- [item addOutput:m_videoOutput];
- }
-
- CFTimeInterval currentCAFrameTime = CACurrentMediaTime();
- CMTime currentCMFrameTime = [m_videoOutput itemTimeForHostTime:currentCAFrameTime];
- // happens when buffering / loading
- if (CMTimeCompare(currentCMFrameTime, kCMTimeZero) < 0) {
- return nullptr;
- }
-
- CVPixelBufferRef pixelBuffer = [m_videoOutput copyPixelBufferForItemTime:currentCMFrameTime
- itemTimeForDisplay:nil];
- if (!pixelBuffer) {
-#ifdef QT_DEBUG_AVF
- qWarning("copyPixelBufferForItemTime returned nil");
- CMTimeShow(currentCMFrameTime);
-#endif
- return nullptr;
- }
-
- width = CVPixelBufferGetWidth(pixelBuffer);
- height = CVPixelBufferGetHeight(pixelBuffer);
- return pixelBuffer;
-}
-
-CVOGLTextureRef AVFVideoFrameRenderer::createCacheTextureFromLayer(AVPlayerLayer *layer,
- size_t& width, size_t& height)
-{
- CVPixelBufferRef pixelBuffer = copyPixelBufferFromLayer(layer, width, height);
-
- if (!pixelBuffer)
- return nullptr;
-
- CVOGLTextureCacheFlush(m_textureCache, 0);
-
- CVOGLTextureRef texture = nullptr;
- CVReturn err = CVOGLTextureCacheCreateTextureFromImage(kCFAllocatorDefault, m_textureCache, pixelBuffer, nullptr,
- GL_TEXTURE_2D, GL_RGBA,
- (GLsizei) width, (GLsizei) height,
- GL_BGRA, GL_UNSIGNED_BYTE, 0,
- &texture);
-
- if (!texture || err) {
-#ifdef QT_DEBUG_AVF
- qWarning("CVOGLTextureCacheCreateTextureFromImage failed (error: %d)", err);
-#endif
- }
-
- CVPixelBufferRelease(pixelBuffer);
-
- return texture;
-}
-
-QImage AVFVideoFrameRenderer::renderLayerToImage(AVPlayerLayer *layer)
-{
- size_t width = 0;
- size_t height = 0;
- CVPixelBufferRef pixelBuffer = copyPixelBufferFromLayer(layer, width, height);
-
- if (!pixelBuffer)
- return QImage();
-
- OSType pixelFormat = CVPixelBufferGetPixelFormatType(pixelBuffer);
- if (pixelFormat != kCVPixelFormatType_32BGRA) {
-#ifdef QT_DEBUG_AVF
- qWarning("CVPixelBuffer format is not BGRA32 (got: %d)", static_cast<quint32>(pixelFormat));
-#endif
- return QImage();
- }
-
- CVPixelBufferLockBaseAddress(pixelBuffer, 0);
- char *data = (char *)CVPixelBufferGetBaseAddress(pixelBuffer);
- size_t stride = CVPixelBufferGetBytesPerRow(pixelBuffer);
-
- // format here is not relevant, only using for storage
- QImage img = QImage(width, height, QImage::Format_ARGB32);
- for (size_t j = 0; j < height; j++) {
- memcpy(img.scanLine(j), data, width * 4);
- data += stride;
- }
-
- CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
- CVPixelBufferRelease(pixelBuffer);
- return img;
-}
-
-void AVFVideoFrameRenderer::initRenderer()
-{
- // even for using a texture directly, we need to be able to make a context current,
- // so we need an offscreen, and we shouldn't assume we can make the surface context
- // current on that offscreen, so use our own (sharing with it). Slightly
- // excessive but no performance penalty and makes the QImage path easier to maintain
-
- //Make sure we have an OpenGL context to make current
- if (!m_glContext) {
- //Create OpenGL context and set share context from surface
- QOpenGLContext *shareContext = nullptr;
- if (m_surface) {
- shareContext = qobject_cast<QOpenGLContext*>(m_surface->property("GLContext").value<QObject*>());
- }
-
- m_glContext = new QOpenGLContext();
- if (shareContext) {
- m_glContext->setShareContext(shareContext);
- m_isContextShared = true;
- } else {
-#ifdef QT_DEBUG_AVF
- qWarning("failed to get Render Thread context");
-#endif
- m_isContextShared = false;
- }
- if (!m_glContext->create()) {
-#ifdef QT_DEBUG_AVF
- qWarning("failed to create QOpenGLContext");
-#endif
- return;
- }
- }
-
- if (!m_offscreenSurface) {
- m_offscreenSurface = new QOffscreenSurface();
- m_offscreenSurface->setFormat(m_glContext->format());
- m_offscreenSurface->create();
- }
-
- //Need current context
- m_glContext->makeCurrent(m_offscreenSurface);
-
- if (!m_textureCache) {
- // Create a new open gl texture cache
- CVReturn err = CVOGLTextureCacheCreate(kCFAllocatorDefault, nullptr,
- [EAGLContext currentContext],
- nullptr, &m_textureCache);
- if (err) {
- #ifdef QT_DEBUG_AVF
- qWarning("Error at CVOGLTextureCacheCreate %d", err);
- #endif
- }
- }
-
-}
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideooutput.h b/src/plugins/avfoundation/mediaplayer/avfvideooutput.h
deleted file mode 100644
index d3bcfecf7..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideooutput.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFVIDEOOUTPUT_H
-#define AVFVIDEOOUTPUT_H
-
-#include <QtCore/qobject.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFVideoOutput
-{
-public:
- virtual ~AVFVideoOutput() {}
- virtual void setLayer(void *playerLayer) = 0;
-};
-
-#define AVFVideoOutput_iid \
- "org.qt-project.qt.AVFVideoOutput/5.0"
-Q_DECLARE_INTERFACE(AVFVideoOutput, AVFVideoOutput_iid)
-
-QT_END_NAMESPACE
-
-#endif // AVFVIDEOOUTPUT_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideooutput.mm b/src/plugins/avfoundation/mediaplayer/avfvideooutput.mm
deleted file mode 100644
index 327681f50..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideooutput.mm
+++ /dev/null
@@ -1,42 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfvideooutput.h"
-
-QT_USE_NAMESPACE
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.h b/src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.h
deleted file mode 100644
index c1a629944..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFVIDEORENDERERCONTROL_H
-#define AVFVIDEORENDERERCONTROL_H
-
-#include <QtMultimedia/QVideoRendererControl>
-#include <QtCore/QMutex>
-#include <QtCore/QSize>
-
-#include "avfvideooutput.h"
-
-#import <CoreVideo/CVBase.h>
-
-QT_BEGIN_NAMESPACE
-
-class AVFDisplayLink;
-class AVFVideoFrameRenderer;
-
-class AVFVideoRendererControl : public QVideoRendererControl, public AVFVideoOutput
-{
- Q_OBJECT
- Q_INTERFACES(AVFVideoOutput)
-public:
- explicit AVFVideoRendererControl(QObject *parent = nullptr);
- virtual ~AVFVideoRendererControl();
-
- QAbstractVideoSurface *surface() const override;
- void setSurface(QAbstractVideoSurface *surface) override;
-
- void setLayer(void *playerLayer) override;
-
-private Q_SLOTS:
- void updateVideoFrame(const CVTimeStamp &ts);
-
-Q_SIGNALS:
- void surfaceChanged(QAbstractVideoSurface *surface);
-
-private:
- void setupVideoOutput();
-
- QMutex m_mutex;
- QAbstractVideoSurface *m_surface;
-
- void *m_playerLayer;
-
- AVFVideoFrameRenderer *m_frameRenderer;
- AVFDisplayLink *m_displayLink;
- QSize m_nativeSize;
- bool m_enableOpenGL;
- bool m_enableMetal;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFVIDEORENDERERCONTROL_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.mm b/src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.mm
deleted file mode 100644
index 726dc5193..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.mm
+++ /dev/null
@@ -1,301 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfvideorenderercontrol.h"
-#include "avfdisplaylink.h"
-
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
-#include "avfvideoframerenderer_ios.h"
-#else
-#include "avfvideoframerenderer.h"
-#endif
-
-#include <QtMultimedia/qabstractvideobuffer.h>
-#include <QtMultimedia/qabstractvideosurface.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
-
-#include <private/qimagevideobuffer_p.h>
-
-#include <QtCore/qdebug.h>
-
-#import <AVFoundation/AVFoundation.h>
-
-QT_USE_NAMESPACE
-
-class TextureVideoBuffer : public QAbstractVideoBuffer
-{
-public:
- TextureVideoBuffer(HandleType type, quint64 tex)
- : QAbstractVideoBuffer(type)
- , m_texture(tex)
- {}
-
- virtual ~TextureVideoBuffer()
- {
- }
-
- MapMode mapMode() const { return NotMapped; }
- uchar *map(MapMode, int*, int*) { return 0; }
- void unmap() {}
-
- QVariant handle() const
- {
- return QVariant::fromValue<unsigned long long>(m_texture);
- }
-
-private:
- quint64 m_texture;
-};
-
-AVFVideoRendererControl::AVFVideoRendererControl(QObject *parent)
- : QVideoRendererControl(parent)
- , m_surface(nullptr)
- , m_playerLayer(nullptr)
- , m_frameRenderer(nullptr)
- , m_enableOpenGL(false)
- , m_enableMetal(false)
-
-{
- m_displayLink = new AVFDisplayLink(this);
- connect(m_displayLink, SIGNAL(tick(CVTimeStamp)), SLOT(updateVideoFrame(CVTimeStamp)));
-}
-
-AVFVideoRendererControl::~AVFVideoRendererControl()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
- m_displayLink->stop();
- [static_cast<AVPlayerLayer*>(m_playerLayer) release];
-}
-
-QAbstractVideoSurface *AVFVideoRendererControl::surface() const
-{
- return m_surface;
-}
-
-void AVFVideoRendererControl::setSurface(QAbstractVideoSurface *surface)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << "Set video surface" << surface;
-#endif
-
- //When we have a valid surface, we can setup a frame renderer
- //and schedule surface updates with the display link.
- if (surface == m_surface)
- return;
-
- QMutexLocker locker(&m_mutex);
-
- if (m_surface && m_surface->isActive())
- m_surface->stop();
-
- m_surface = surface;
-
- //If the surface changed, then the current frame renderer is no longer valid
- delete m_frameRenderer;
- m_frameRenderer = nullptr;
-
- //If there is now no surface to render too
- if (m_surface == nullptr) {
- m_displayLink->stop();
- return;
- }
-
- //Surface changed, so we need a new frame renderer
- m_frameRenderer = new AVFVideoFrameRenderer(m_surface, this);
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
- if (m_playerLayer) {
- m_frameRenderer->setPlayerLayer(static_cast<AVPlayerLayer*>(m_playerLayer));
- }
-#endif
-
- auto checkHandleType = [this] {
- m_enableOpenGL = m_surface->supportedPixelFormats(QAbstractVideoBuffer::GLTextureHandle).contains(QVideoFrame::Format_BGR32);
- m_enableMetal = m_surface->supportedPixelFormats(QAbstractVideoBuffer::MTLTextureHandle).contains(QVideoFrame::Format_BGR32);
- };
- checkHandleType();
- connect(m_surface, &QAbstractVideoSurface::supportedFormatsChanged, this, checkHandleType);
-
- //If we already have a layer, but changed surfaces start rendering again
- if (m_playerLayer && !m_displayLink->isActive()) {
- m_displayLink->start();
- }
-
-}
-
-void AVFVideoRendererControl::setLayer(void *playerLayer)
-{
- if (m_playerLayer == playerLayer)
- return;
-
- [static_cast<AVPlayerLayer*>(m_playerLayer) release];
-
- m_playerLayer = [static_cast<AVPlayerLayer*>(playerLayer) retain];
-
- //If there is an active surface, make sure it has been stopped so that
- //we can update it's state with the new content.
- if (m_surface && m_surface->isActive())
- m_surface->stop();
-
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
- if (m_frameRenderer) {
- m_frameRenderer->setPlayerLayer(static_cast<AVPlayerLayer*>(playerLayer));
- }
-#endif
-
- //If there is no layer to render, stop scheduling updates
- if (m_playerLayer == nullptr) {
- m_displayLink->stop();
- return;
- }
-
- setupVideoOutput();
-
- //If we now have both a valid surface and layer, start scheduling updates
- if (m_surface && !m_displayLink->isActive()) {
- m_displayLink->start();
- }
-}
-
-void AVFVideoRendererControl::updateVideoFrame(const CVTimeStamp &ts)
-{
- Q_UNUSED(ts);
-
- AVPlayerLayer *playerLayer = static_cast<AVPlayerLayer*>(m_playerLayer);
-
- if (!playerLayer) {
- qWarning("updateVideoFrame called without AVPlayerLayer (which shouldn't happen");
- return;
- }
-
- if (!playerLayer.readyForDisplay || !m_surface)
- return;
-
- if (m_enableMetal) {
- quint64 tex = m_frameRenderer->renderLayerToMTLTexture(playerLayer);
- if (tex == 0)
- return;
-
- auto buffer = new TextureVideoBuffer(QAbstractVideoBuffer::MTLTextureHandle, tex);
- QVideoFrame frame(buffer, m_nativeSize, QVideoFrame::Format_BGR32);
- if (m_surface->isActive() && m_surface->surfaceFormat().pixelFormat() != frame.pixelFormat())
- m_surface->stop();
-
- if (!m_surface->isActive()) {
- QVideoSurfaceFormat format(frame.size(), frame.pixelFormat(), QAbstractVideoBuffer::MTLTextureHandle);
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
- format.setScanLineDirection(QVideoSurfaceFormat::TopToBottom);
-#else
- format.setScanLineDirection(QVideoSurfaceFormat::BottomToTop);
-#endif
- if (!m_surface->start(format))
- qWarning("Failed to activate video surface");
- }
-
- if (m_surface->isActive())
- m_surface->present(frame);
-
- return;
- }
-
- if (m_enableOpenGL) {
- quint64 tex = m_frameRenderer->renderLayerToTexture(playerLayer);
- //Make sure we got a valid texture
- if (tex == 0)
- return;
-
- QAbstractVideoBuffer *buffer = new TextureVideoBuffer(QAbstractVideoBuffer::GLTextureHandle, tex);
- QVideoFrame frame = QVideoFrame(buffer, m_nativeSize, QVideoFrame::Format_BGR32);
-
- if (m_surface && frame.isValid()) {
- if (m_surface->isActive() && m_surface->surfaceFormat().pixelFormat() != frame.pixelFormat())
- m_surface->stop();
-
- if (!m_surface->isActive()) {
- QVideoSurfaceFormat format(frame.size(), frame.pixelFormat(), QAbstractVideoBuffer::GLTextureHandle);
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
- format.setScanLineDirection(QVideoSurfaceFormat::TopToBottom);
-#else
- format.setScanLineDirection(QVideoSurfaceFormat::BottomToTop);
-#endif
- if (!m_surface->start(format)) {
- //Surface doesn't support GLTextureHandle
- qWarning("Failed to activate video surface");
- }
- }
-
- if (m_surface->isActive())
- m_surface->present(frame);
- }
- } else {
- //fallback to rendering frames to QImages
- QImage frameData = m_frameRenderer->renderLayerToImage(playerLayer);
-
- if (frameData.isNull()) {
- return;
- }
-
- QAbstractVideoBuffer *buffer = new QImageVideoBuffer(frameData);
- QVideoFrame frame = QVideoFrame(buffer, m_nativeSize, QVideoFrame::Format_ARGB32);
- if (m_surface && frame.isValid()) {
- if (m_surface->isActive() && m_surface->surfaceFormat().pixelFormat() != frame.pixelFormat())
- m_surface->stop();
-
- if (!m_surface->isActive()) {
- QVideoSurfaceFormat format(frame.size(), frame.pixelFormat(), QAbstractVideoBuffer::NoHandle);
-
- if (!m_surface->start(format)) {
- qWarning("Failed to activate video surface");
- }
- }
-
- if (m_surface->isActive())
- m_surface->present(frame);
- }
-
- }
-}
-
-void AVFVideoRendererControl::setupVideoOutput()
-{
- AVPlayerLayer *playerLayer = static_cast<AVPlayerLayer*>(m_playerLayer);
- if (playerLayer)
- m_nativeSize = QSize(playerLayer.bounds.size.width, playerLayer.bounds.size.height);
-}
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideowidget.h b/src/plugins/avfoundation/mediaplayer/avfvideowidget.h
deleted file mode 100644
index faf71f1a4..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideowidget.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFVIDEOWIDGET_H
-#define AVFVIDEOWIDGET_H
-
-#include <QtWidgets/QWidget>
-
-@class AVPlayerLayer;
-#if defined(Q_OS_OSX)
-@class NSView;
-#else
-@class UIView;
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class AVFVideoWidget : public QWidget
-{
-public:
- AVFVideoWidget(QWidget *parent);
- virtual ~AVFVideoWidget();
-
- QSize sizeHint() const override;
- Qt::AspectRatioMode aspectRatioMode() const;
- void setAspectRatioMode(Qt::AspectRatioMode mode);
- void setPlayerLayer(AVPlayerLayer *layer);
-
-protected:
- void resizeEvent(QResizeEvent *) override;
- void paintEvent(QPaintEvent *) override;
-
-private:
- void updateAspectRatio();
- void updatePlayerLayerBounds(const QSize &size);
-
- QSize m_nativeSize;
- Qt::AspectRatioMode m_aspectRatioMode;
- AVPlayerLayer *m_playerLayer;
-#if defined(Q_OS_OSX)
- NSView *m_nativeView;
-#else
- UIView *m_nativeView;
-#endif
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFVIDEOWIDGET_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideowidget.mm b/src/plugins/avfoundation/mediaplayer/avfvideowidget.mm
deleted file mode 100644
index 0987342b4..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideowidget.mm
+++ /dev/null
@@ -1,187 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfvideowidget.h"
-
-#import <AVFoundation/AVFoundation.h>
-#import <QuartzCore/CATransaction.h>
-
-#if defined(Q_OS_MACOS)
-#import <AppKit/AppKit.h>
-#else
-#import <UIKit/UIKit.h>
-#endif
-
-#include <QtCore/QDebug>
-#include <QtGui/QResizeEvent>
-#include <QtGui/QPaintEvent>
-#include <QtGui/QPainter>
-
-QT_USE_NAMESPACE
-
-AVFVideoWidget::AVFVideoWidget(QWidget *parent)
- : QWidget(parent)
- , m_aspectRatioMode(Qt::KeepAspectRatio)
- , m_playerLayer(nullptr)
- , m_nativeView(nullptr)
-{
- setAutoFillBackground(false);
-}
-
-AVFVideoWidget::~AVFVideoWidget()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
-
- if (m_playerLayer) {
- [m_playerLayer removeFromSuperlayer];
- [m_playerLayer release];
- }
-}
-
-QSize AVFVideoWidget::sizeHint() const
-{
- return m_nativeSize;
-}
-
-Qt::AspectRatioMode AVFVideoWidget::aspectRatioMode() const
-{
- return m_aspectRatioMode;
-}
-
-void AVFVideoWidget::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- if (m_aspectRatioMode != mode) {
- m_aspectRatioMode = mode;
-
- updateAspectRatio();
- }
-}
-
-void AVFVideoWidget::setPlayerLayer(AVPlayerLayer *layer)
-{
- if (m_playerLayer == layer)
- return;
-
- if (!m_nativeView) {
- //make video widget a native window
-#if defined(Q_OS_OSX)
- m_nativeView = (NSView*)this->winId();
- [m_nativeView setWantsLayer:YES];
-#else
- m_nativeView = (UIView*)this->winId();
-#endif
- }
-
- if (m_playerLayer) {
- [m_playerLayer removeFromSuperlayer];
- [m_playerLayer release];
- }
-
- m_playerLayer = layer;
-
- CALayer *nativeLayer = [m_nativeView layer];
-
- if (layer) {
- [layer retain];
-
- m_nativeSize = QSize(m_playerLayer.bounds.size.width,
- m_playerLayer.bounds.size.height);
-
- updateAspectRatio();
- [nativeLayer addSublayer:m_playerLayer];
- updatePlayerLayerBounds(this->size());
- }
-#ifdef QT_DEBUG_AVF
- NSArray *sublayers = [nativeLayer sublayers];
- qDebug() << "playerlayer: " << "at z:" << [m_playerLayer zPosition]
- << " frame: " << m_playerLayer.frame.size.width << "x" << m_playerLayer.frame.size.height;
- qDebug() << "superlayer: " << "at z:" << [nativeLayer zPosition]
- << " frame: " << nativeLayer.frame.size.width << "x" << nativeLayer.frame.size.height;
- int i = 0;
- for (CALayer *layer in sublayers) {
- qDebug() << "layer " << i << ": at z:" << [layer zPosition]
- << " frame: " << layer.frame.size.width << "x" << layer.frame.size.height;
- i++;
- }
-#endif
-
-}
-
-void AVFVideoWidget::resizeEvent(QResizeEvent *event)
-{
- updatePlayerLayerBounds(event->size());
- QWidget::resizeEvent(event);
-}
-
-void AVFVideoWidget::paintEvent(QPaintEvent *event)
-{
- QPainter painter(this);
- painter.fillRect(rect(), Qt::black);
-
- QWidget::paintEvent(event);
-}
-
-void AVFVideoWidget::updateAspectRatio()
-{
- if (m_playerLayer) {
- switch (m_aspectRatioMode) {
- case Qt::IgnoreAspectRatio:
- [m_playerLayer setVideoGravity:AVLayerVideoGravityResize];
- break;
- case Qt::KeepAspectRatio:
- [m_playerLayer setVideoGravity:AVLayerVideoGravityResizeAspect];
- break;
- case Qt::KeepAspectRatioByExpanding:
- [m_playerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
- break;
- default:
- break;
- }
- }
-}
-
-void AVFVideoWidget::updatePlayerLayerBounds(const QSize &size)
-{
- [CATransaction begin];
- [CATransaction setDisableActions: YES]; // disable animation/flicks
- m_playerLayer.bounds = QRect(QPoint(0, 0), size).toCGRect();
- [CATransaction commit];
-}
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.h b/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.h
deleted file mode 100644
index 22379d273..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFVIDEOWIDGETCONTROL_H
-#define AVFVIDEOWIDGETCONTROL_H
-
-#include <qvideowidgetcontrol.h>
-#include "avfvideooutput.h"
-
-@class AVPlayerLayer;
-
-QT_BEGIN_NAMESPACE
-
-class AVFVideoWidget;
-
-class AVFVideoWidgetControl : public QVideoWidgetControl, public AVFVideoOutput
-{
- Q_OBJECT
- Q_INTERFACES(AVFVideoOutput)
-public:
- AVFVideoWidgetControl(QObject *parent = nullptr);
- virtual ~AVFVideoWidgetControl();
-
- void setLayer(void *playerLayer) override;
-
- QWidget *videoWidget() override;
-
- bool isFullScreen() const override;
- void setFullScreen(bool fullScreen) override;
-
- Qt::AspectRatioMode aspectRatioMode() const override;
- void setAspectRatioMode(Qt::AspectRatioMode mode) override;
-
- int brightness() const override;
- void setBrightness(int brightness) override;
-
- int contrast() const override;
- void setContrast(int contrast) override;
-
- int hue() const override;
- void setHue(int hue) override;
-
- int saturation() const override;
- void setSaturation(int saturation) override;
-
-private:
- AVFVideoWidget *m_videoWidget;
-
- bool m_fullscreen;
- int m_brightness;
- int m_contrast;
- int m_hue;
- int m_saturation;
-
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFVIDEOWIDGETCONTROL_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.mm b/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.mm
deleted file mode 100644
index 91ece817e..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.mm
+++ /dev/null
@@ -1,145 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfvideowidgetcontrol.h"
-#include "avfvideowidget.h"
-
-#ifdef QT_DEBUG_AVF
-#include <QtCore/QDebug>
-#endif
-
-#import <AVFoundation/AVFoundation.h>
-
-QT_USE_NAMESPACE
-
-AVFVideoWidgetControl::AVFVideoWidgetControl(QObject *parent)
- : QVideoWidgetControl(parent)
- , m_fullscreen(false)
- , m_brightness(0)
- , m_contrast(0)
- , m_hue(0)
- , m_saturation(0)
-{
- m_videoWidget = new AVFVideoWidget(nullptr);
-}
-
-AVFVideoWidgetControl::~AVFVideoWidgetControl()
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO;
-#endif
- delete m_videoWidget;
-}
-
-void AVFVideoWidgetControl::setLayer(void *playerLayer)
-{
-#ifdef QT_DEBUG_AVF
- qDebug() << Q_FUNC_INFO << playerLayer;
-#endif
-
- m_videoWidget->setPlayerLayer(static_cast<AVPlayerLayer*>(playerLayer));
-
-}
-
-QWidget *AVFVideoWidgetControl::videoWidget()
-{
- return m_videoWidget;
-}
-
-bool AVFVideoWidgetControl::isFullScreen() const
-{
- return m_fullscreen;
-}
-
-void AVFVideoWidgetControl::setFullScreen(bool fullScreen)
-{
- m_fullscreen = fullScreen;
-}
-
-Qt::AspectRatioMode AVFVideoWidgetControl::aspectRatioMode() const
-{
- return m_videoWidget->aspectRatioMode();
-}
-
-void AVFVideoWidgetControl::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- m_videoWidget->setAspectRatioMode(mode);
-}
-
-int AVFVideoWidgetControl::brightness() const
-{
- return m_brightness;
-}
-
-void AVFVideoWidgetControl::setBrightness(int brightness)
-{
- m_brightness = brightness;
-}
-
-int AVFVideoWidgetControl::contrast() const
-{
- return m_contrast;
-}
-
-void AVFVideoWidgetControl::setContrast(int contrast)
-{
- m_contrast = contrast;
-}
-
-int AVFVideoWidgetControl::hue() const
-{
- return m_hue;
-}
-
-void AVFVideoWidgetControl::setHue(int hue)
-{
- m_hue = hue;
-}
-
-int AVFVideoWidgetControl::saturation() const
-{
- return m_saturation;
-}
-
-void AVFVideoWidgetControl::setSaturation(int saturation)
-{
- m_saturation = saturation;
-}
-
-#include "moc_avfvideowidgetcontrol.cpp"
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideowindowcontrol.h b/src/plugins/avfoundation/mediaplayer/avfvideowindowcontrol.h
deleted file mode 100644
index 763656c6c..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideowindowcontrol.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef AVFVIDEOWINDOWCONTROL_H
-#define AVFVIDEOWINDOWCONTROL_H
-
-#include <QVideoWindowControl>
-
-@class AVPlayerLayer;
-#if defined(Q_OS_OSX)
-@class NSView;
-typedef NSView NativeView;
-#else
-@class UIView;
-typedef UIView NativeView;
-#endif
-
-#include "avfvideooutput.h"
-
-QT_BEGIN_NAMESPACE
-
-class AVFVideoWindowControl : public QVideoWindowControl, public AVFVideoOutput
-{
- Q_OBJECT
- Q_INTERFACES(AVFVideoOutput)
-
-public:
- AVFVideoWindowControl(QObject *parent = nullptr);
- virtual ~AVFVideoWindowControl();
-
- // QVideoWindowControl interface
-public:
- WId winId() const override;
- void setWinId(WId id) override;
-
- QRect displayRect() const override;
- void setDisplayRect(const QRect &rect) override;
-
- bool isFullScreen() const override;
- void setFullScreen(bool fullScreen) override;
-
- void repaint() override;
- QSize nativeSize() const override;
-
- Qt::AspectRatioMode aspectRatioMode() const override;
- void setAspectRatioMode(Qt::AspectRatioMode mode) override;
-
- int brightness() const override;
- void setBrightness(int brightness) override;
-
- int contrast() const override;
- void setContrast(int contrast) override;
-
- int hue() const override;
- void setHue(int hue) override;
-
- int saturation() const override;
- void setSaturation(int saturation) override;
-
- // AVFVideoOutput interface
- void setLayer(void *playerLayer) override;
-
-private:
- void updateAspectRatio();
- void updatePlayerLayerBounds();
-
- WId m_winId;
- QRect m_displayRect;
- bool m_fullscreen;
- int m_brightness;
- int m_contrast;
- int m_hue;
- int m_saturation;
- Qt::AspectRatioMode m_aspectRatioMode;
- QSize m_nativeSize;
- AVPlayerLayer *m_playerLayer;
- NativeView *m_nativeView;
-};
-
-QT_END_NAMESPACE
-
-#endif // AVFVIDEOWINDOWCONTROL_H
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideowindowcontrol.mm b/src/plugins/avfoundation/mediaplayer/avfvideowindowcontrol.mm
deleted file mode 100644
index d61129ec9..000000000
--- a/src/plugins/avfoundation/mediaplayer/avfvideowindowcontrol.mm
+++ /dev/null
@@ -1,255 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "avfvideowindowcontrol.h"
-
-#include <AVFoundation/AVFoundation.h>
-#import <QuartzCore/CATransaction.h>
-
-#if QT_HAS_INCLUDE(<AppKit/AppKit.h>)
-#include <AppKit/AppKit.h>
-#endif
-
-#if QT_HAS_INCLUDE(<UIKit/UIKit.h>)
-#include <UIKit/UIKit.h>
-#endif
-
-QT_USE_NAMESPACE
-
-AVFVideoWindowControl::AVFVideoWindowControl(QObject *parent)
- : QVideoWindowControl(parent)
- , m_winId(0)
- , m_fullscreen(false)
- , m_brightness(0)
- , m_contrast(0)
- , m_hue(0)
- , m_saturation(0)
- , m_aspectRatioMode(Qt::IgnoreAspectRatio)
- , m_playerLayer(nullptr)
- , m_nativeView(nullptr)
-{
-}
-
-AVFVideoWindowControl::~AVFVideoWindowControl()
-{
- if (m_playerLayer) {
- [m_playerLayer removeFromSuperlayer];
- [m_playerLayer release];
- }
-}
-
-WId AVFVideoWindowControl::winId() const
-{
- return m_winId;
-}
-
-void AVFVideoWindowControl::setWinId(WId id)
-{
- m_winId = id;
- m_nativeView = (NativeView*)m_winId;
-}
-
-QRect AVFVideoWindowControl::displayRect() const
-{
- return m_displayRect;
-}
-
-void AVFVideoWindowControl::setDisplayRect(const QRect &rect)
-{
- if (m_displayRect != rect) {
- m_displayRect = rect;
- updatePlayerLayerBounds();
- }
-}
-
-bool AVFVideoWindowControl::isFullScreen() const
-{
- return m_fullscreen;
-}
-
-void AVFVideoWindowControl::setFullScreen(bool fullScreen)
-{
- if (m_fullscreen != fullScreen) {
- m_fullscreen = fullScreen;
- Q_EMIT QVideoWindowControl::fullScreenChanged(fullScreen);
- }
-}
-
-void AVFVideoWindowControl::repaint()
-{
- if (m_playerLayer)
- [m_playerLayer setNeedsDisplay];
-}
-
-QSize AVFVideoWindowControl::nativeSize() const
-{
- return m_nativeSize;
-}
-
-Qt::AspectRatioMode AVFVideoWindowControl::aspectRatioMode() const
-{
- return m_aspectRatioMode;
-}
-
-void AVFVideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- if (m_aspectRatioMode != mode) {
- m_aspectRatioMode = mode;
- updateAspectRatio();
- }
-}
-
-int AVFVideoWindowControl::brightness() const
-{
- return m_brightness;
-}
-
-void AVFVideoWindowControl::setBrightness(int brightness)
-{
- if (m_brightness != brightness) {
- m_brightness = brightness;
- Q_EMIT QVideoWindowControl::brightnessChanged(brightness);
- }
-}
-
-int AVFVideoWindowControl::contrast() const
-{
- return m_contrast;
-}
-
-void AVFVideoWindowControl::setContrast(int contrast)
-{
- if (m_contrast != contrast) {
- m_contrast = contrast;
- Q_EMIT QVideoWindowControl::contrastChanged(contrast);
- }
-}
-
-int AVFVideoWindowControl::hue() const
-{
- return m_hue;
-}
-
-void AVFVideoWindowControl::setHue(int hue)
-{
- if (m_hue != hue) {
- m_hue = hue;
- Q_EMIT QVideoWindowControl::hueChanged(hue);
- }
-}
-
-int AVFVideoWindowControl::saturation() const
-{
- return m_saturation;
-}
-
-void AVFVideoWindowControl::setSaturation(int saturation)
-{
- if (m_saturation != saturation) {
- m_saturation = saturation;
- Q_EMIT QVideoWindowControl::saturationChanged(saturation);
- }
-}
-
-void AVFVideoWindowControl::setLayer(void *playerLayer)
-{
- AVPlayerLayer *layer = static_cast<AVPlayerLayer*>(playerLayer);
- if (m_playerLayer == layer)
- return;
-
- if (!m_winId) {
- qDebug("AVFVideoWindowControl: No video window");
- return;
- }
-
-#if defined(Q_OS_OSX)
- [m_nativeView setWantsLayer:YES];
-#endif
-
- if (m_playerLayer) {
- [m_playerLayer removeFromSuperlayer];
- [m_playerLayer release];
- }
-
- m_playerLayer = layer;
-
- CALayer *nativeLayer = [m_nativeView layer];
-
- if (layer) {
- [layer retain];
-
- m_nativeSize = QSize(m_playerLayer.bounds.size.width,
- m_playerLayer.bounds.size.height);
-
- updateAspectRatio();
- [nativeLayer addSublayer:m_playerLayer];
- updatePlayerLayerBounds();
- }
-}
-
-void AVFVideoWindowControl::updateAspectRatio()
-{
- if (m_playerLayer) {
- switch (m_aspectRatioMode) {
- case Qt::IgnoreAspectRatio:
- [m_playerLayer setVideoGravity:AVLayerVideoGravityResize];
- break;
- case Qt::KeepAspectRatio:
- [m_playerLayer setVideoGravity:AVLayerVideoGravityResizeAspect];
- break;
- case Qt::KeepAspectRatioByExpanding:
- [m_playerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
- break;
- default:
- break;
- }
- }
-}
-
-void AVFVideoWindowControl::updatePlayerLayerBounds()
-{
- if (m_playerLayer) {
- [CATransaction begin];
- [CATransaction setDisableActions: YES]; // disable animation/flicks
- m_playerLayer.frame = m_displayRect.toCGRect();
- [CATransaction commit];
- }
-}
-
-#include "moc_avfvideowindowcontrol.cpp"
diff --git a/src/plugins/avfoundation/mediaplayer/mediaplayer.pro b/src/plugins/avfoundation/mediaplayer/mediaplayer.pro
deleted file mode 100644
index 604866058..000000000
--- a/src/plugins/avfoundation/mediaplayer/mediaplayer.pro
+++ /dev/null
@@ -1,76 +0,0 @@
-TARGET = qavfmediaplayer
-
-#DEFINES += QT_DEBUG_AVF
-# Avoid clash with a variable named `slots' in a Quartz header
-CONFIG += no_keywords
-
-QT += opengl multimedia-private network
-
-LIBS += -framework CoreMedia -framework CoreVideo -framework QuartzCore -framework Metal
-
-QMAKE_USE += avfoundation
-
-HEADERS += \
- avfmediaplayercontrol.h \
- avfmediaplayermetadatacontrol.h \
- avfmediaplayerservice.h \
- avfmediaplayersession.h \
- avfmediaplayerserviceplugin.h \
- avfvideooutput.h \
- avfvideowindowcontrol.h
-
-OBJECTIVE_SOURCES += \
- avfmediaplayercontrol.mm \
- avfmediaplayermetadatacontrol.mm \
- avfmediaplayerservice.mm \
- avfmediaplayerserviceplugin.mm \
- avfmediaplayersession.mm \
- avfvideooutput.mm \
- avfvideowindowcontrol.mm
-
- qtHaveModule(widgets) {
- QT += multimediawidgets-private
- HEADERS += \
- avfvideowidgetcontrol.h \
- avfvideowidget.h
-
- OBJECTIVE_SOURCES += \
- avfvideowidgetcontrol.mm \
- avfvideowidget.mm
- }
-
-ios|tvos {
- qtConfig(opengl) {
- HEADERS += \
- avfvideoframerenderer_ios.h \
- avfvideorenderercontrol.h \
- avfdisplaylink.h
-
- OBJECTIVE_SOURCES += \
- avfvideoframerenderer_ios.mm \
- avfvideorenderercontrol.mm \
- avfdisplaylink.mm
- }
- LIBS += -framework Foundation
-} else {
- LIBS += -framework AppKit
-
- qtConfig(opengl) {
- HEADERS += \
- avfvideoframerenderer.h \
- avfvideorenderercontrol.h \
- avfdisplaylink.h
-
- OBJECTIVE_SOURCES += \
- avfvideoframerenderer.mm \
- avfvideorenderercontrol.mm \
- avfdisplaylink.mm
- }
-}
-
-OTHER_FILES += \
- avfmediaplayer.json
-
-PLUGIN_TYPE = mediaservice
-PLUGIN_CLASS_NAME = AVFMediaPlayerServicePlugin
-load(qt_plugin)
diff --git a/src/plugins/common/evr.pri b/src/plugins/common/evr.pri
deleted file mode 100644
index 2a1b383df..000000000
--- a/src/plugins/common/evr.pri
+++ /dev/null
@@ -1,20 +0,0 @@
-INCLUDEPATH += $$PWD/evr
-
-qtHaveModule(widgets): QT += widgets
-QT += gui-private
-
-LIBS += -lmf -lmfplat -lmfuuid -ld3d9 -ldxva2 -lwinmm -levr
-
-HEADERS += \
- $$PWD/evr/evrvideowindowcontrol.h \
- $$PWD/evr/evrcustompresenter.h \
- $$PWD/evr/evrd3dpresentengine.h \
- $$PWD/evr/evrhelpers.h \
- $$PWD/evr/evrdefs.h
-
-SOURCES += \
- $$PWD/evr/evrvideowindowcontrol.cpp \
- $$PWD/evr/evrcustompresenter.cpp \
- $$PWD/evr/evrd3dpresentengine.cpp \
- $$PWD/evr/evrhelpers.cpp \
- $$PWD/evr/evrdefs.cpp
diff --git a/src/plugins/common/evr/evrcustompresenter.cpp b/src/plugins/common/evr/evrcustompresenter.cpp
deleted file mode 100644
index b2dd0426c..000000000
--- a/src/plugins/common/evr/evrcustompresenter.cpp
+++ /dev/null
@@ -1,2062 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "evrcustompresenter.h"
-
-#include "evrd3dpresentengine.h"
-#include "evrhelpers.h"
-
-#include <QtCore/qmutex.h>
-#include <QtCore/qvarlengtharray.h>
-#include <QtCore/qrect.h>
-#include <qabstractvideosurface.h>
-#include <qthread.h>
-#include <qcoreapplication.h>
-#include <qmath.h>
-#include <QtCore/qdebug.h>
-
-#include <mutex>
-
-#include <float.h>
-#include <evcode.h>
-
-QT_BEGIN_NAMESPACE
-
-const static MFRatio g_DefaultFrameRate = { 30, 1 };
-static const DWORD SCHEDULER_TIMEOUT = 5000;
-static const MFTIME ONE_SECOND = 10000000;
-static const LONG ONE_MSEC = 1000;
-
-// Function declarations.
-static HRESULT setDesiredSampleTime(IMFSample *sample, const LONGLONG& hnsSampleTime, const LONGLONG& hnsDuration);
-static HRESULT clearDesiredSampleTime(IMFSample *sample);
-static HRESULT setMixerSourceRect(IMFTransform *mixer, const MFVideoNormalizedRect& nrcSource);
-static QVideoFrame::PixelFormat pixelFormatFromMediaType(IMFMediaType *type);
-
-static inline LONG MFTimeToMsec(const LONGLONG& time)
-{
- return (LONG)(time / (ONE_SECOND / ONE_MSEC));
-}
-
-bool qt_evr_setCustomPresenter(IUnknown *evr, EVRCustomPresenter *presenter)
-{
- if (!evr || !presenter)
- return false;
-
- HRESULT result = E_FAIL;
-
- IMFVideoRenderer *renderer = NULL;
- if (SUCCEEDED(evr->QueryInterface(IID_PPV_ARGS(&renderer)))) {
- result = renderer->InitializeRenderer(NULL, presenter);
- renderer->Release();
- }
-
- return result == S_OK;
-}
-
-class PresentSampleEvent : public QEvent
-{
-public:
- PresentSampleEvent(IMFSample *sample)
- : QEvent(QEvent::Type(EVRCustomPresenter::PresentSample))
- , m_sample(sample)
- {
- if (m_sample)
- m_sample->AddRef();
- }
-
- ~PresentSampleEvent() override
- {
- if (m_sample)
- m_sample->Release();
- }
-
- IMFSample *sample() const { return m_sample; }
-
-private:
- IMFSample *m_sample;
-};
-
-Scheduler::Scheduler(EVRCustomPresenter *presenter)
- : m_presenter(presenter)
- , m_clock(NULL)
- , m_threadID(0)
- , m_schedulerThread(0)
- , m_threadReadyEvent(0)
- , m_flushEvent(0)
- , m_playbackRate(1.0f)
- , m_perFrameInterval(0)
- , m_perFrame_1_4th(0)
- , m_lastSampleTime(0)
-{
-}
-
-Scheduler::~Scheduler()
-{
- qt_evr_safe_release(&m_clock);
- for (int i = 0; i < m_scheduledSamples.size(); ++i)
- m_scheduledSamples[i]->Release();
- m_scheduledSamples.clear();
-}
-
-void Scheduler::setFrameRate(const MFRatio& fps)
-{
- UINT64 AvgTimePerFrame = 0;
-
- // Convert to a duration.
- MFFrameRateToAverageTimePerFrame(fps.Numerator, fps.Denominator, &AvgTimePerFrame);
-
- m_perFrameInterval = (MFTIME)AvgTimePerFrame;
-
- // Calculate 1/4th of this value, because we use it frequently.
- m_perFrame_1_4th = m_perFrameInterval / 4;
-}
-
-HRESULT Scheduler::startScheduler(IMFClock *clock)
-{
- if (m_schedulerThread)
- return E_UNEXPECTED;
-
- HRESULT hr = S_OK;
- DWORD dwID = 0;
- HANDLE hObjects[2];
- DWORD dwWait = 0;
-
- if (m_clock)
- m_clock->Release();
- m_clock = clock;
- if (m_clock)
- m_clock->AddRef();
-
- // Set a high the timer resolution (ie, short timer period).
- timeBeginPeriod(1);
-
- // Create an event to wait for the thread to start.
- m_threadReadyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- if (!m_threadReadyEvent) {
- hr = HRESULT_FROM_WIN32(GetLastError());
- goto done;
- }
-
- // Create an event to wait for flush commands to complete.
- m_flushEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- if (!m_flushEvent) {
- hr = HRESULT_FROM_WIN32(GetLastError());
- goto done;
- }
-
- // Create the scheduler thread.
- m_schedulerThread = CreateThread(NULL, 0, schedulerThreadProc, (LPVOID)this, 0, &dwID);
- if (!m_schedulerThread) {
- hr = HRESULT_FROM_WIN32(GetLastError());
- goto done;
- }
-
- // Wait for the thread to signal the "thread ready" event.
- hObjects[0] = m_threadReadyEvent;
- hObjects[1] = m_schedulerThread;
- dwWait = WaitForMultipleObjects(2, hObjects, FALSE, INFINITE); // Wait for EITHER of these handles.
- if (WAIT_OBJECT_0 != dwWait) {
- // The thread terminated early for some reason. This is an error condition.
- CloseHandle(m_schedulerThread);
- m_schedulerThread = NULL;
-
- hr = E_UNEXPECTED;
- goto done;
- }
-
- m_threadID = dwID;
-
-done:
- // Regardless success/failure, we are done using the "thread ready" event.
- if (m_threadReadyEvent) {
- CloseHandle(m_threadReadyEvent);
- m_threadReadyEvent = NULL;
- }
- return hr;
-}
-
-HRESULT Scheduler::stopScheduler()
-{
- if (!m_schedulerThread)
- return S_OK;
-
- // Ask the scheduler thread to exit.
- PostThreadMessage(m_threadID, Terminate, 0, 0);
-
- // Wait for the thread to exit.
- WaitForSingleObject(m_schedulerThread, INFINITE);
-
- // Close handles.
- CloseHandle(m_schedulerThread);
- m_schedulerThread = NULL;
-
- CloseHandle(m_flushEvent);
- m_flushEvent = NULL;
-
- // Discard samples.
- m_mutex.lock();
- for (int i = 0; i < m_scheduledSamples.size(); ++i)
- m_scheduledSamples[i]->Release();
- m_scheduledSamples.clear();
- m_mutex.unlock();
-
- // Restore the timer resolution.
- timeEndPeriod(1);
-
- return S_OK;
-}
-
-HRESULT Scheduler::flush()
-{
- if (m_schedulerThread) {
- // Ask the scheduler thread to flush.
- PostThreadMessage(m_threadID, Flush, 0 , 0);
-
- // Wait for the scheduler thread to signal the flush event,
- // OR for the thread to terminate.
- HANDLE objects[] = { m_flushEvent, m_schedulerThread };
-
- WaitForMultipleObjects(ARRAYSIZE(objects), objects, FALSE, SCHEDULER_TIMEOUT);
- }
-
- return S_OK;
-}
-
-bool Scheduler::areSamplesScheduled()
-{
- QMutexLocker locker(&m_mutex);
- return m_scheduledSamples.count() > 0;
-}
-
-HRESULT Scheduler::scheduleSample(IMFSample *sample, bool presentNow)
-{
- if (!m_schedulerThread)
- return MF_E_NOT_INITIALIZED;
-
- HRESULT hr = S_OK;
- DWORD dwExitCode = 0;
-
- GetExitCodeThread(m_schedulerThread, &dwExitCode);
- if (dwExitCode != STILL_ACTIVE)
- return E_FAIL;
-
- if (presentNow || !m_clock) {
- m_presenter->presentSample(sample);
- } else {
- // Queue the sample and ask the scheduler thread to wake up.
- m_mutex.lock();
- sample->AddRef();
- m_scheduledSamples.enqueue(sample);
- m_mutex.unlock();
-
- if (SUCCEEDED(hr))
- PostThreadMessage(m_threadID, Schedule, 0, 0);
- }
-
- return hr;
-}
-
-HRESULT Scheduler::processSamplesInQueue(LONG *nextSleep)
-{
- HRESULT hr = S_OK;
- LONG wait = 0;
- IMFSample *sample = NULL;
-
- // Process samples until the queue is empty or until the wait time > 0.
- while (!m_scheduledSamples.isEmpty()) {
- m_mutex.lock();
- sample = m_scheduledSamples.dequeue();
- m_mutex.unlock();
-
- // Process the next sample in the queue. If the sample is not ready
- // for presentation. the value returned in wait is > 0, which
- // means the scheduler should sleep for that amount of time.
-
- hr = processSample(sample, &wait);
- qt_evr_safe_release(&sample);
-
- if (FAILED(hr) || wait > 0)
- break;
- }
-
- // If the wait time is zero, it means we stopped because the queue is
- // empty (or an error occurred). Set the wait time to infinite; this will
- // make the scheduler thread sleep until it gets another thread message.
- if (wait == 0)
- wait = INFINITE;
-
- *nextSleep = wait;
- return hr;
-}
-
-HRESULT Scheduler::processSample(IMFSample *sample, LONG *pNextSleep)
-{
- HRESULT hr = S_OK;
-
- LONGLONG hnsPresentationTime = 0;
- LONGLONG hnsTimeNow = 0;
- MFTIME hnsSystemTime = 0;
-
- bool presentNow = true;
- LONG nextSleep = 0;
-
- if (m_clock) {
- // Get the sample's time stamp. It is valid for a sample to
- // have no time stamp.
- hr = sample->GetSampleTime(&hnsPresentationTime);
-
- // Get the clock time. (But if the sample does not have a time stamp,
- // we don't need the clock time.)
- if (SUCCEEDED(hr))
- hr = m_clock->GetCorrelatedTime(0, &hnsTimeNow, &hnsSystemTime);
-
- // Calculate the time until the sample's presentation time.
- // A negative value means the sample is late.
- LONGLONG hnsDelta = hnsPresentationTime - hnsTimeNow;
- if (m_playbackRate < 0) {
- // For reverse playback, the clock runs backward. Therefore, the
- // delta is reversed.
- hnsDelta = - hnsDelta;
- }
-
- if (hnsDelta < - m_perFrame_1_4th) {
- // This sample is late.
- presentNow = true;
- } else if (hnsDelta > (3 * m_perFrame_1_4th)) {
- // This sample is still too early. Go to sleep.
- nextSleep = MFTimeToMsec(hnsDelta - (3 * m_perFrame_1_4th));
-
- // Adjust the sleep time for the clock rate. (The presentation clock runs
- // at m_fRate, but sleeping uses the system clock.)
- if (m_playbackRate != 0)
- nextSleep = (LONG)(nextSleep / qFabs(m_playbackRate));
-
- // Don't present yet.
- presentNow = false;
- }
- }
-
- if (presentNow) {
- m_presenter->presentSample(sample);
- } else {
- // The sample is not ready yet. Return it to the queue.
- m_mutex.lock();
- sample->AddRef();
- m_scheduledSamples.prepend(sample);
- m_mutex.unlock();
- }
-
- *pNextSleep = nextSleep;
-
- return hr;
-}
-
-DWORD WINAPI Scheduler::schedulerThreadProc(LPVOID parameter)
-{
- Scheduler* scheduler = reinterpret_cast<Scheduler*>(parameter);
- if (!scheduler)
- return -1;
- return scheduler->schedulerThreadProcPrivate();
-}
-
-DWORD Scheduler::schedulerThreadProcPrivate()
-{
- HRESULT hr = S_OK;
- MSG msg;
- LONG wait = INFINITE;
- bool exitThread = false;
-
- // Force the system to create a message queue for this thread.
- // (See MSDN documentation for PostThreadMessage.)
- PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
-
- // Signal to the scheduler that the thread is ready.
- SetEvent(m_threadReadyEvent);
-
- while (!exitThread) {
- // Wait for a thread message OR until the wait time expires.
- DWORD result = MsgWaitForMultipleObjects(0, NULL, FALSE, wait, QS_POSTMESSAGE);
-
- if (result == WAIT_TIMEOUT) {
- // If we timed out, then process the samples in the queue
- hr = processSamplesInQueue(&wait);
- if (FAILED(hr))
- exitThread = true;
- }
-
- while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- bool processSamples = true;
-
- switch (msg.message) {
- case Terminate:
- exitThread = true;
- break;
- case Flush:
- // Flushing: Clear the sample queue and set the event.
- m_mutex.lock();
- for (int i = 0; i < m_scheduledSamples.size(); ++i)
- m_scheduledSamples[i]->Release();
- m_scheduledSamples.clear();
- m_mutex.unlock();
- wait = INFINITE;
- SetEvent(m_flushEvent);
- break;
- case Schedule:
- // Process as many samples as we can.
- if (processSamples) {
- hr = processSamplesInQueue(&wait);
- if (FAILED(hr))
- exitThread = true;
- processSamples = (wait != (LONG)INFINITE);
- }
- break;
- }
- }
-
- }
-
- return (SUCCEEDED(hr) ? 0 : 1);
-}
-
-
-SamplePool::SamplePool()
- : m_initialized(false)
-{
-}
-
-SamplePool::~SamplePool()
-{
- clear();
-}
-
-HRESULT SamplePool::getSample(IMFSample **sample)
-{
- QMutexLocker locker(&m_mutex);
-
- if (!m_initialized)
- return MF_E_NOT_INITIALIZED;
-
- if (m_videoSampleQueue.isEmpty())
- return MF_E_SAMPLEALLOCATOR_EMPTY;
-
- // Get a sample from the allocated queue.
-
- // It doesn't matter if we pull them from the head or tail of the list,
- // but when we get it back, we want to re-insert it onto the opposite end.
- // (see ReturnSample)
-
- IMFSample *taken = m_videoSampleQueue.takeFirst();
-
- // Give the sample to the caller.
- *sample = taken;
- (*sample)->AddRef();
-
- taken->Release();
-
- return S_OK;
-}
-
-HRESULT SamplePool::returnSample(IMFSample *sample)
-{
- QMutexLocker locker(&m_mutex);
-
- if (!m_initialized)
- return MF_E_NOT_INITIALIZED;
-
- m_videoSampleQueue.append(sample);
- sample->AddRef();
-
- return S_OK;
-}
-
-HRESULT SamplePool::initialize(QList<IMFSample*> &samples)
-{
- QMutexLocker locker(&m_mutex);
-
- if (m_initialized)
- return MF_E_INVALIDREQUEST;
-
- // Move these samples into our allocated queue.
- for (auto sample : qAsConst(samples)) {
- sample->AddRef();
- m_videoSampleQueue.append(sample);
- }
-
- m_initialized = true;
-
- for (auto sample : qAsConst(samples))
- sample->Release();
- samples.clear();
- return S_OK;
-}
-
-HRESULT SamplePool::clear()
-{
- QMutexLocker locker(&m_mutex);
-
- for (auto sample : qAsConst(m_videoSampleQueue))
- sample->Release();
- m_videoSampleQueue.clear();
- m_initialized = false;
-
- return S_OK;
-}
-
-
-EVRCustomPresenter::EVRCustomPresenter(QAbstractVideoSurface *surface)
- : QObject()
- , m_sampleFreeCB(this, &EVRCustomPresenter::onSampleFree)
- , m_refCount(1)
- , m_renderState(RenderShutdown)
- , m_scheduler(this)
- , m_tokenCounter(0)
- , m_sampleNotify(false)
- , m_repaint(false)
- , m_prerolled(false)
- , m_endStreaming(false)
- , m_playbackRate(1.0f)
- , m_presentEngine(new D3DPresentEngine)
- , m_clock(0)
- , m_mixer(0)
- , m_mediaEventSink(0)
- , m_mediaType(0)
- , m_surface(0)
- , m_canRenderToSurface(false)
- , m_positionOffset(0)
-{
- // Initial source rectangle = (0,0,1,1)
- m_sourceRect.top = 0;
- m_sourceRect.left = 0;
- m_sourceRect.bottom = 1;
- m_sourceRect.right = 1;
-
- setSurface(surface);
-}
-
-EVRCustomPresenter::~EVRCustomPresenter()
-{
- m_scheduler.flush();
- m_scheduler.stopScheduler();
- m_samplePool.clear();
-
- qt_evr_safe_release(&m_clock);
- qt_evr_safe_release(&m_mixer);
- qt_evr_safe_release(&m_mediaEventSink);
- qt_evr_safe_release(&m_mediaType);
-
- delete m_presentEngine;
-}
-
-HRESULT EVRCustomPresenter::QueryInterface(REFIID riid, void ** ppvObject)
-{
- if (!ppvObject)
- return E_POINTER;
- if (riid == IID_IMFGetService) {
- *ppvObject = static_cast<IMFGetService*>(this);
- } else if (riid == IID_IMFTopologyServiceLookupClient) {
- *ppvObject = static_cast<IMFTopologyServiceLookupClient*>(this);
- } else if (riid == IID_IMFVideoDeviceID) {
- *ppvObject = static_cast<IMFVideoDeviceID*>(this);
- } else if (riid == IID_IMFVideoPresenter) {
- *ppvObject = static_cast<IMFVideoPresenter*>(this);
- } else if (riid == IID_IMFRateSupport) {
- *ppvObject = static_cast<IMFRateSupport*>(this);
- } else if (riid == IID_IUnknown) {
- *ppvObject = static_cast<IUnknown*>(static_cast<IMFGetService*>(this));
- } else if (riid == IID_IMFClockStateSink) {
- *ppvObject = static_cast<IMFClockStateSink*>(this);
- } else {
- *ppvObject = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
-}
-
-ULONG EVRCustomPresenter::AddRef()
-{
- return InterlockedIncrement(&m_refCount);
-}
-
-ULONG EVRCustomPresenter::Release()
-{
- ULONG uCount = InterlockedDecrement(&m_refCount);
- if (uCount == 0)
- delete this;
- return uCount;
-}
-
-HRESULT EVRCustomPresenter::GetService(REFGUID guidService, REFIID riid, LPVOID *ppvObject)
-{
- HRESULT hr = S_OK;
-
- if (!ppvObject)
- return E_POINTER;
-
- // The only service GUID that we support is MR_VIDEO_RENDER_SERVICE.
- if (guidService != mr_VIDEO_RENDER_SERVICE)
- return MF_E_UNSUPPORTED_SERVICE;
-
- // First try to get the service interface from the D3DPresentEngine object.
- hr = m_presentEngine->getService(guidService, riid, ppvObject);
- if (FAILED(hr))
- // Next, check if this object supports the interface.
- hr = QueryInterface(riid, ppvObject);
-
- return hr;
-}
-
-HRESULT EVRCustomPresenter::GetDeviceID(IID* deviceID)
-{
- if (!deviceID)
- return E_POINTER;
-
- *deviceID = iid_IDirect3DDevice9;
-
- return S_OK;
-}
-
-HRESULT EVRCustomPresenter::InitServicePointers(IMFTopologyServiceLookup *lookup)
-{
- if (!lookup)
- return E_POINTER;
-
- HRESULT hr = S_OK;
- DWORD objectCount = 0;
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- // Do not allow initializing when playing or paused.
- if (isActive())
- return MF_E_INVALIDREQUEST;
-
- qt_evr_safe_release(&m_clock);
- qt_evr_safe_release(&m_mixer);
- qt_evr_safe_release(&m_mediaEventSink);
-
- // Ask for the clock. Optional, because the EVR might not have a clock.
- objectCount = 1;
-
- lookup->LookupService(MF_SERVICE_LOOKUP_GLOBAL, 0,
- mr_VIDEO_RENDER_SERVICE, IID_PPV_ARGS(&m_clock),
- &objectCount
- );
-
- // Ask for the mixer. (Required.)
- objectCount = 1;
-
- hr = lookup->LookupService(MF_SERVICE_LOOKUP_GLOBAL, 0,
- mr_VIDEO_MIXER_SERVICE, IID_PPV_ARGS(&m_mixer),
- &objectCount
- );
-
- if (FAILED(hr))
- return hr;
-
- // Make sure that we can work with this mixer.
- hr = configureMixer(m_mixer);
- if (FAILED(hr))
- return hr;
-
- // Ask for the EVR's event-sink interface. (Required.)
- objectCount = 1;
-
- hr = lookup->LookupService(MF_SERVICE_LOOKUP_GLOBAL, 0,
- mr_VIDEO_RENDER_SERVICE, IID_PPV_ARGS(&m_mediaEventSink),
- &objectCount
- );
-
- if (SUCCEEDED(hr))
- m_renderState = RenderStopped;
-
- return hr;
-}
-
-HRESULT EVRCustomPresenter::ReleaseServicePointers()
-{
- // Enter the shut-down state.
- m_mutex.lock();
-
- m_renderState = RenderShutdown;
-
- m_mutex.unlock();
-
- // Flush any samples that were scheduled.
- flush();
-
- // Clear the media type and release related resources.
- setMediaType(NULL);
-
- // Release all services that were acquired from InitServicePointers.
- qt_evr_safe_release(&m_clock);
- qt_evr_safe_release(&m_mixer);
- qt_evr_safe_release(&m_mediaEventSink);
-
- return S_OK;
-}
-
-bool EVRCustomPresenter::isValid() const
-{
- return m_presentEngine->isValid() && m_canRenderToSurface;
-}
-
-HRESULT EVRCustomPresenter::ProcessMessage(MFVP_MESSAGE_TYPE message, ULONG_PTR param)
-{
- HRESULT hr = S_OK;
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- hr = checkShutdown();
- if (FAILED(hr))
- return hr;
-
- switch (message) {
- // Flush all pending samples.
- case MFVP_MESSAGE_FLUSH:
- hr = flush();
- break;
-
- // Renegotiate the media type with the mixer.
- case MFVP_MESSAGE_INVALIDATEMEDIATYPE:
- hr = renegotiateMediaType();
- break;
-
- // The mixer received a new input sample.
- case MFVP_MESSAGE_PROCESSINPUTNOTIFY:
- hr = processInputNotify();
- break;
-
- // Streaming is about to start.
- case MFVP_MESSAGE_BEGINSTREAMING:
- hr = beginStreaming();
- break;
-
- // Streaming has ended. (The EVR has stopped.)
- case MFVP_MESSAGE_ENDSTREAMING:
- hr = endStreaming();
- break;
-
- // All input streams have ended.
- case MFVP_MESSAGE_ENDOFSTREAM:
- // Set the EOS flag.
- m_endStreaming = true;
- // Check if it's time to send the EC_COMPLETE event to the EVR.
- hr = checkEndOfStream();
- break;
-
- // Frame-stepping is starting.
- case MFVP_MESSAGE_STEP:
- hr = prepareFrameStep(DWORD(param));
- break;
-
- // Cancels frame-stepping.
- case MFVP_MESSAGE_CANCELSTEP:
- hr = cancelFrameStep();
- break;
-
- default:
- hr = E_INVALIDARG; // Unknown message. This case should never occur.
- break;
- }
-
- return hr;
-}
-
-HRESULT EVRCustomPresenter::GetCurrentMediaType(IMFVideoMediaType **mediaType)
-{
- HRESULT hr = S_OK;
-
- if (!mediaType)
- return E_POINTER;
-
- *mediaType = NULL;
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- hr = checkShutdown();
- if (FAILED(hr))
- return hr;
-
- if (!m_mediaType)
- return MF_E_NOT_INITIALIZED;
-
- return m_mediaType->QueryInterface(IID_PPV_ARGS(mediaType));
-}
-
-HRESULT EVRCustomPresenter::OnClockStart(MFTIME, LONGLONG clockStartOffset)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- // We cannot start after shutdown.
- HRESULT hr = checkShutdown();
- if (FAILED(hr))
- return hr;
-
- // Check if the clock is already active (not stopped).
- if (isActive()) {
- m_renderState = RenderStarted;
-
- // If the clock position changes while the clock is active, it
- // is a seek request. We need to flush all pending samples.
- if (clockStartOffset != PRESENTATION_CURRENT_POSITION)
- flush();
- } else {
- m_renderState = RenderStarted;
-
- // The clock has started from the stopped state.
-
- // Possibly we are in the middle of frame-stepping OR have samples waiting
- // in the frame-step queue. Deal with these two cases first:
- hr = startFrameStep();
- if (FAILED(hr))
- return hr;
- }
-
- // Now try to get new output samples from the mixer.
- processOutputLoop();
-
- return hr;
-}
-
-HRESULT EVRCustomPresenter::OnClockRestart(MFTIME)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- HRESULT hr = checkShutdown();
- if (FAILED(hr))
- return hr;
-
- // The EVR calls OnClockRestart only while paused.
-
- m_renderState = RenderStarted;
-
- // Possibly we are in the middle of frame-stepping OR we have samples waiting
- // in the frame-step queue. Deal with these two cases first:
- hr = startFrameStep();
- if (FAILED(hr))
- return hr;
-
- // Now resume the presentation loop.
- processOutputLoop();
-
- return hr;
-}
-
-HRESULT EVRCustomPresenter::OnClockStop(MFTIME)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- HRESULT hr = checkShutdown();
- if (FAILED(hr))
- return hr;
-
- if (m_renderState != RenderStopped) {
- m_renderState = RenderStopped;
- flush();
-
- // If we are in the middle of frame-stepping, cancel it now.
- if (m_frameStep.state != FrameStepNone)
- cancelFrameStep();
- }
-
- return S_OK;
-}
-
-HRESULT EVRCustomPresenter::OnClockPause(MFTIME)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- // We cannot pause the clock after shutdown.
- HRESULT hr = checkShutdown();
-
- if (SUCCEEDED(hr))
- m_renderState = RenderPaused;
-
- return hr;
-}
-
-HRESULT EVRCustomPresenter::OnClockSetRate(MFTIME, float rate)
-{
- // Note:
- // The presenter reports its maximum rate through the IMFRateSupport interface.
- // Here, we assume that the EVR honors the maximum rate.
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- HRESULT hr = checkShutdown();
- if (FAILED(hr))
- return hr;
-
- // If the rate is changing from zero (scrubbing) to non-zero, cancel the
- // frame-step operation.
- if ((m_playbackRate == 0.0f) && (rate != 0.0f)) {
- cancelFrameStep();
- for (auto sample : qAsConst(m_frameStep.samples))
- sample->Release();
- m_frameStep.samples.clear();
- }
-
- m_playbackRate = rate;
-
- // Tell the scheduler about the new rate.
- m_scheduler.setClockRate(rate);
-
- return S_OK;
-}
-
-HRESULT EVRCustomPresenter::GetSlowestRate(MFRATE_DIRECTION, BOOL, float *rate)
-{
- if (!rate)
- return E_POINTER;
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- HRESULT hr = checkShutdown();
-
- if (SUCCEEDED(hr)) {
- // There is no minimum playback rate, so the minimum is zero.
- *rate = 0;
- }
-
- return S_OK;
-}
-
-HRESULT EVRCustomPresenter::GetFastestRate(MFRATE_DIRECTION direction, BOOL thin, float *rate)
-{
- if (!rate)
- return E_POINTER;
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- float maxRate = 0.0f;
-
- HRESULT hr = checkShutdown();
- if (FAILED(hr))
- return hr;
-
- // Get the maximum *forward* rate.
- maxRate = getMaxRate(thin);
-
- // For reverse playback, it's the negative of maxRate.
- if (direction == MFRATE_REVERSE)
- maxRate = -maxRate;
-
- *rate = maxRate;
-
- return S_OK;
-}
-
-HRESULT EVRCustomPresenter::IsRateSupported(BOOL thin, float rate, float *nearestSupportedRate)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- float maxRate = 0.0f;
- float nearestRate = rate; // If we support rate, that is the nearest.
-
- HRESULT hr = checkShutdown();
- if (FAILED(hr))
- return hr;
-
- // Find the maximum forward rate.
- // Note: We have no minimum rate (that is, we support anything down to 0).
- maxRate = getMaxRate(thin);
-
- if (qFabs(rate) > maxRate) {
- // The (absolute) requested rate exceeds the maximum rate.
- hr = MF_E_UNSUPPORTED_RATE;
-
- // The nearest supported rate is maxRate.
- nearestRate = maxRate;
- if (rate < 0) {
- // Negative for reverse playback.
- nearestRate = -nearestRate;
- }
- }
-
- // Return the nearest supported rate.
- if (nearestSupportedRate)
- *nearestSupportedRate = nearestRate;
-
- return hr;
-}
-
-void EVRCustomPresenter::supportedFormatsChanged()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- m_canRenderToSurface = false;
- m_presentEngine->setHint(D3DPresentEngine::RenderToTexture, false);
-
- // check if we can render to the surface (compatible formats)
- if (m_surface) {
- QList<QVideoFrame::PixelFormat> formats = m_surface->supportedPixelFormats(QAbstractVideoBuffer::GLTextureHandle);
- if (m_presentEngine->supportsTextureRendering() && formats.contains(QVideoFrame::Format_RGB32)) {
- m_presentEngine->setHint(D3DPresentEngine::RenderToTexture, true);
- m_canRenderToSurface = true;
- } else {
- formats = m_surface->supportedPixelFormats(QAbstractVideoBuffer::NoHandle);
- for (QVideoFrame::PixelFormat format : qAsConst(formats)) {
- if (SUCCEEDED(m_presentEngine->checkFormat(qt_evr_D3DFormatFromPixelFormat(format)))) {
- m_canRenderToSurface = true;
- break;
- }
- }
- }
- }
-
- // TODO: if media type already set, renegotiate?
-}
-
-void EVRCustomPresenter::setSurface(QAbstractVideoSurface *surface)
-{
- m_mutex.lock();
-
- if (m_surface) {
- disconnect(m_surface, &QAbstractVideoSurface::supportedFormatsChanged,
- this, &EVRCustomPresenter::supportedFormatsChanged);
- }
-
- m_surface = surface;
-
- if (m_surface) {
- connect(m_surface, &QAbstractVideoSurface::supportedFormatsChanged,
- this, &EVRCustomPresenter::supportedFormatsChanged);
- }
-
- m_mutex.unlock();
-
- supportedFormatsChanged();
-}
-
-HRESULT EVRCustomPresenter::configureMixer(IMFTransform *mixer)
-{
- // Set the zoom rectangle (ie, the source clipping rectangle).
- return setMixerSourceRect(mixer, m_sourceRect);
-}
-
-HRESULT EVRCustomPresenter::renegotiateMediaType()
-{
- HRESULT hr = S_OK;
- bool foundMediaType = false;
-
- IMFMediaType *mixerType = NULL;
- IMFMediaType *optimalType = NULL;
-
- if (!m_mixer)
- return MF_E_INVALIDREQUEST;
-
- // Loop through all of the mixer's proposed output types.
- DWORD typeIndex = 0;
- while (!foundMediaType && (hr != MF_E_NO_MORE_TYPES)) {
- qt_evr_safe_release(&mixerType);
- qt_evr_safe_release(&optimalType);
-
- // Step 1. Get the next media type supported by mixer.
- hr = m_mixer->GetOutputAvailableType(0, typeIndex++, &mixerType);
- if (FAILED(hr))
- break;
-
- // From now on, if anything in this loop fails, try the next type,
- // until we succeed or the mixer runs out of types.
-
- // Step 2. Check if we support this media type.
- if (SUCCEEDED(hr))
- hr = isMediaTypeSupported(mixerType);
-
- // Step 3. Adjust the mixer's type to match our requirements.
- if (SUCCEEDED(hr))
- hr = createOptimalVideoType(mixerType, &optimalType);
-
- // Step 4. Check if the mixer will accept this media type.
- if (SUCCEEDED(hr))
- hr = m_mixer->SetOutputType(0, optimalType, MFT_SET_TYPE_TEST_ONLY);
-
- // Step 5. Try to set the media type on ourselves.
- if (SUCCEEDED(hr))
- hr = setMediaType(optimalType);
-
- // Step 6. Set output media type on mixer.
- if (SUCCEEDED(hr)) {
- hr = m_mixer->SetOutputType(0, optimalType, 0);
-
- // If something went wrong, clear the media type.
- if (FAILED(hr))
- setMediaType(NULL);
- }
-
- if (SUCCEEDED(hr))
- foundMediaType = true;
- }
-
- qt_evr_safe_release(&mixerType);
- qt_evr_safe_release(&optimalType);
-
- return hr;
-}
-
-HRESULT EVRCustomPresenter::flush()
-{
- m_prerolled = false;
-
- // The scheduler might have samples that are waiting for
- // their presentation time. Tell the scheduler to flush.
-
- // This call blocks until the scheduler threads discards all scheduled samples.
- m_scheduler.flush();
-
- // Flush the frame-step queue.
- for (auto sample : qAsConst(m_frameStep.samples))
- sample->Release();
- m_frameStep.samples.clear();
-
- if (m_renderState == RenderStopped && m_surface && m_surface->isActive()) {
- // Repaint with black.
- presentSample(NULL);
- }
-
- return S_OK;
-}
-
-HRESULT EVRCustomPresenter::processInputNotify()
-{
- HRESULT hr = S_OK;
-
- // Set the flag that says the mixer has a new sample.
- m_sampleNotify = true;
-
- if (!m_mediaType) {
- // We don't have a valid media type yet.
- hr = MF_E_TRANSFORM_TYPE_NOT_SET;
- } else {
- // Try to process an output sample.
- processOutputLoop();
- }
- return hr;
-}
-
-HRESULT EVRCustomPresenter::beginStreaming()
-{
- HRESULT hr = S_OK;
-
- // Start the scheduler thread.
- hr = m_scheduler.startScheduler(m_clock);
-
- return hr;
-}
-
-HRESULT EVRCustomPresenter::endStreaming()
-{
- HRESULT hr = S_OK;
-
- // Stop the scheduler thread.
- hr = m_scheduler.stopScheduler();
-
- return hr;
-}
-
-HRESULT EVRCustomPresenter::checkEndOfStream()
-{
- if (!m_endStreaming) {
- // The EVR did not send the MFVP_MESSAGE_ENDOFSTREAM message.
- return S_OK;
- }
-
- if (m_sampleNotify) {
- // The mixer still has input.
- return S_OK;
- }
-
- if (m_scheduler.areSamplesScheduled()) {
- // Samples are still scheduled for rendering.
- return S_OK;
- }
-
- // Everything is complete. Now we can tell the EVR that we are done.
- notifyEvent(EC_COMPLETE, (LONG_PTR)S_OK, 0);
- m_endStreaming = false;
-
- stopSurface();
- return S_OK;
-}
-
-HRESULT EVRCustomPresenter::prepareFrameStep(DWORD steps)
-{
- HRESULT hr = S_OK;
-
- // Cache the step count.
- m_frameStep.steps += steps;
-
- // Set the frame-step state.
- m_frameStep.state = FrameStepWaitingStart;
-
- // If the clock is are already running, we can start frame-stepping now.
- // Otherwise, we will start when the clock starts.
- if (m_renderState == RenderStarted)
- hr = startFrameStep();
-
- return hr;
-}
-
-HRESULT EVRCustomPresenter::startFrameStep()
-{
- HRESULT hr = S_OK;
- IMFSample *sample = NULL;
-
- if (m_frameStep.state == FrameStepWaitingStart) {
- // We have a frame-step request, and are waiting for the clock to start.
- // Set the state to "pending," which means we are waiting for samples.
- m_frameStep.state = FrameStepPending;
-
- // If the frame-step queue already has samples, process them now.
- while (!m_frameStep.samples.isEmpty() && (m_frameStep.state == FrameStepPending)) {
- sample = m_frameStep.samples.takeFirst();
-
- hr = deliverFrameStepSample(sample);
- if (FAILED(hr))
- goto done;
-
- qt_evr_safe_release(&sample);
-
- // We break from this loop when:
- // (a) the frame-step queue is empty, or
- // (b) the frame-step operation is complete.
- }
- } else if (m_frameStep.state == FrameStepNone) {
- // We are not frame stepping. Therefore, if the frame-step queue has samples,
- // we need to process them normally.
- while (!m_frameStep.samples.isEmpty()) {
- sample = m_frameStep.samples.takeFirst();
-
- hr = deliverSample(sample, false);
- if (FAILED(hr))
- goto done;
-
- qt_evr_safe_release(&sample);
- }
- }
-
-done:
- qt_evr_safe_release(&sample);
- return hr;
-}
-
-HRESULT EVRCustomPresenter::completeFrameStep(IMFSample *sample)
-{
- HRESULT hr = S_OK;
- MFTIME sampleTime = 0;
- MFTIME systemTime = 0;
-
- // Update our state.
- m_frameStep.state = FrameStepComplete;
- m_frameStep.sampleNoRef = 0;
-
- // Notify the EVR that the frame-step is complete.
- notifyEvent(EC_STEP_COMPLETE, FALSE, 0); // FALSE = completed (not cancelled)
-
- // If we are scrubbing (rate == 0), also send the "scrub time" event.
- if (isScrubbing()) {
- // Get the time stamp from the sample.
- hr = sample->GetSampleTime(&sampleTime);
- if (FAILED(hr)) {
- // No time stamp. Use the current presentation time.
- if (m_clock)
- m_clock->GetCorrelatedTime(0, &sampleTime, &systemTime);
-
- hr = S_OK; // (Not an error condition.)
- }
-
- notifyEvent(EC_SCRUB_TIME, DWORD(sampleTime), DWORD(((sampleTime) >> 32) & 0xffffffff));
- }
- return hr;
-}
-
-HRESULT EVRCustomPresenter::cancelFrameStep()
-{
- FrameStepState oldState = m_frameStep.state;
-
- m_frameStep.state = FrameStepNone;
- m_frameStep.steps = 0;
- m_frameStep.sampleNoRef = 0;
- // Don't clear the frame-step queue yet, because we might frame step again.
-
- if (oldState > FrameStepNone && oldState < FrameStepComplete) {
- // We were in the middle of frame-stepping when it was cancelled.
- // Notify the EVR.
- notifyEvent(EC_STEP_COMPLETE, TRUE, 0); // TRUE = cancelled
- }
- return S_OK;
-}
-
-HRESULT EVRCustomPresenter::createOptimalVideoType(IMFMediaType *proposedType, IMFMediaType **optimalType)
-{
- HRESULT hr = S_OK;
-
- RECT rcOutput;
- ZeroMemory(&rcOutput, sizeof(rcOutput));
-
- MFVideoArea displayArea;
- ZeroMemory(&displayArea, sizeof(displayArea));
-
- IMFMediaType *mtOptimal = NULL;
-
- UINT64 size;
- int width;
- int height;
-
- // Clone the proposed type.
-
- hr = MFCreateMediaType(&mtOptimal);
- if (FAILED(hr))
- goto done;
-
- hr = proposedType->CopyAllItems(mtOptimal);
- if (FAILED(hr))
- goto done;
-
- // Modify the new type.
-
- hr = proposedType->GetUINT64(MF_MT_FRAME_SIZE, &size);
- width = int(HI32(size));
- height = int(LO32(size));
- rcOutput.left = 0;
- rcOutput.top = 0;
- rcOutput.right = width;
- rcOutput.bottom = height;
-
- // Set the geometric aperture, and disable pan/scan.
- displayArea = qt_evr_makeMFArea(0, 0, rcOutput.right, rcOutput.bottom);
-
- hr = mtOptimal->SetUINT32(MF_MT_PAN_SCAN_ENABLED, FALSE);
- if (FAILED(hr))
- goto done;
-
- hr = mtOptimal->SetBlob(MF_MT_GEOMETRIC_APERTURE, reinterpret_cast<UINT8*>(&displayArea),
- sizeof(displayArea));
- if (FAILED(hr))
- goto done;
-
- // Set the pan/scan aperture and the minimum display aperture. We don't care
- // about them per se, but the mixer will reject the type if these exceed the
- // frame dimentions.
- hr = mtOptimal->SetBlob(MF_MT_PAN_SCAN_APERTURE, reinterpret_cast<UINT8*>(&displayArea),
- sizeof(displayArea));
- if (FAILED(hr))
- goto done;
-
- hr = mtOptimal->SetBlob(MF_MT_MINIMUM_DISPLAY_APERTURE, reinterpret_cast<UINT8*>(&displayArea),
- sizeof(displayArea));
- if (FAILED(hr))
- goto done;
-
- // Return the pointer to the caller.
- *optimalType = mtOptimal;
- (*optimalType)->AddRef();
-
-done:
- qt_evr_safe_release(&mtOptimal);
- return hr;
-
-}
-
-HRESULT EVRCustomPresenter::setMediaType(IMFMediaType *mediaType)
-{
- // Note: mediaType can be NULL (to clear the type)
-
- // Clearing the media type is allowed in any state (including shutdown).
- if (!mediaType) {
- stopSurface();
- qt_evr_safe_release(&m_mediaType);
- releaseResources();
- return S_OK;
- }
-
- MFRatio fps = { 0, 0 };
- QList<IMFSample*> sampleQueue;
-
- // Cannot set the media type after shutdown.
- HRESULT hr = checkShutdown();
- if (FAILED(hr))
- goto done;
-
- // Check if the new type is actually different.
- // Note: This function safely handles NULL input parameters.
- if (qt_evr_areMediaTypesEqual(m_mediaType, mediaType))
- goto done; // Nothing more to do.
-
- // We're really changing the type. First get rid of the old type.
- qt_evr_safe_release(&m_mediaType);
- releaseResources();
-
- // Initialize the presenter engine with the new media type.
- // The presenter engine allocates the samples.
-
- hr = m_presentEngine->createVideoSamples(mediaType, sampleQueue);
- if (FAILED(hr))
- goto done;
-
- // Mark each sample with our token counter. If this batch of samples becomes
- // invalid, we increment the counter, so that we know they should be discarded.
- for (auto sample : qAsConst(sampleQueue)) {
- hr = sample->SetUINT32(MFSamplePresenter_SampleCounter, m_tokenCounter);
- if (FAILED(hr))
- goto done;
- }
-
- // Add the samples to the sample pool.
- hr = m_samplePool.initialize(sampleQueue);
- if (FAILED(hr))
- goto done;
-
- // Set the frame rate on the scheduler.
- if (SUCCEEDED(qt_evr_getFrameRate(mediaType, &fps)) && (fps.Numerator != 0) && (fps.Denominator != 0)) {
- m_scheduler.setFrameRate(fps);
- } else {
- // NOTE: The mixer's proposed type might not have a frame rate, in which case
- // we'll use an arbitrary default. (Although it's unlikely the video source
- // does not have a frame rate.)
- m_scheduler.setFrameRate(g_DefaultFrameRate);
- }
-
- // Store the media type.
- m_mediaType = mediaType;
- m_mediaType->AddRef();
-
- startSurface();
-
-done:
- if (FAILED(hr))
- releaseResources();
- return hr;
-}
-
-HRESULT EVRCustomPresenter::isMediaTypeSupported(IMFMediaType *proposed)
-{
- D3DFORMAT d3dFormat = D3DFMT_UNKNOWN;
- BOOL compressed = FALSE;
- MFVideoInterlaceMode interlaceMode = MFVideoInterlace_Unknown;
- MFVideoArea videoCropArea;
- UINT32 width = 0, height = 0;
-
- // Validate the format.
- HRESULT hr = qt_evr_getFourCC(proposed, reinterpret_cast<DWORD*>(&d3dFormat));
- if (FAILED(hr))
- return hr;
-
- QVideoFrame::PixelFormat pixelFormat = pixelFormatFromMediaType(proposed);
- if (pixelFormat == QVideoFrame::Format_Invalid)
- return MF_E_INVALIDMEDIATYPE;
-
- // When not rendering to texture, only accept pixel formats supported by the video surface
- if (!m_presentEngine->isTextureRenderingEnabled()
- && m_surface
- && !m_surface->supportedPixelFormats().contains(pixelFormat)) {
- return MF_E_INVALIDMEDIATYPE;
- }
-
- // Reject compressed media types.
- hr = proposed->IsCompressedFormat(&compressed);
- if (FAILED(hr))
- return hr;
-
- if (compressed)
- return MF_E_INVALIDMEDIATYPE;
-
- // The D3DPresentEngine checks whether surfaces can be created using this format
- hr = m_presentEngine->checkFormat(d3dFormat);
- if (FAILED(hr))
- return hr;
-
- // Reject interlaced formats.
- hr = proposed->GetUINT32(MF_MT_INTERLACE_MODE, reinterpret_cast<UINT32*>(&interlaceMode));
- if (FAILED(hr))
- return hr;
-
- if (interlaceMode != MFVideoInterlace_Progressive)
- return MF_E_INVALIDMEDIATYPE;
-
- hr = MFGetAttributeSize(proposed, MF_MT_FRAME_SIZE, &width, &height);
- if (FAILED(hr))
- return hr;
-
- // Validate the various apertures (cropping regions) against the frame size.
- // Any of these apertures may be unspecified in the media type, in which case
- // we ignore it. We just want to reject invalid apertures.
-
- if (SUCCEEDED(proposed->GetBlob(MF_MT_PAN_SCAN_APERTURE,
- reinterpret_cast<UINT8*>(&videoCropArea),
- sizeof(videoCropArea), nullptr))) {
- hr = qt_evr_validateVideoArea(videoCropArea, width, height);
- }
- if (SUCCEEDED(proposed->GetBlob(MF_MT_GEOMETRIC_APERTURE,
- reinterpret_cast<UINT8*>(&videoCropArea),
- sizeof(videoCropArea), nullptr))) {
- hr = qt_evr_validateVideoArea(videoCropArea, width, height);
- }
- if (SUCCEEDED(proposed->GetBlob(MF_MT_MINIMUM_DISPLAY_APERTURE,
- reinterpret_cast<UINT8*>(&videoCropArea),
- sizeof(videoCropArea), nullptr))) {
- hr = qt_evr_validateVideoArea(videoCropArea, width, height);
- }
- return hr;
-}
-
-void EVRCustomPresenter::processOutputLoop()
-{
- HRESULT hr = S_OK;
-
- // Process as many samples as possible.
- while (hr == S_OK) {
- // If the mixer doesn't have a new input sample, break from the loop.
- if (!m_sampleNotify) {
- hr = MF_E_TRANSFORM_NEED_MORE_INPUT;
- break;
- }
-
- // Try to process a sample.
- hr = processOutput();
-
- // NOTE: ProcessOutput can return S_FALSE to indicate it did not
- // process a sample. If so, break out of the loop.
- }
-
- if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) {
- // The mixer has run out of input data. Check for end-of-stream.
- checkEndOfStream();
- }
-}
-
-HRESULT EVRCustomPresenter::processOutput()
-{
- HRESULT hr = S_OK;
- DWORD status = 0;
- LONGLONG mixerStartTime = 0, mixerEndTime = 0;
- MFTIME systemTime = 0;
- BOOL repaint = m_repaint; // Temporarily store this state flag.
-
- MFT_OUTPUT_DATA_BUFFER dataBuffer;
- ZeroMemory(&dataBuffer, sizeof(dataBuffer));
-
- IMFSample *sample = NULL;
-
- // If the clock is not running, we present the first sample,
- // and then don't present any more until the clock starts.
-
- if ((m_renderState != RenderStarted) && !m_repaint && m_prerolled)
- return S_FALSE;
-
- // Make sure we have a pointer to the mixer.
- if (!m_mixer)
- return MF_E_INVALIDREQUEST;
-
- // Try to get a free sample from the video sample pool.
- hr = m_samplePool.getSample(&sample);
- if (hr == MF_E_SAMPLEALLOCATOR_EMPTY) // No free samples. Try again when a sample is released.
- return S_FALSE;
- if (FAILED(hr))
- return hr;
-
- // From now on, we have a valid video sample pointer, where the mixer will
- // write the video data.
-
- if (m_repaint) {
- // Repaint request. Ask the mixer for the most recent sample.
- setDesiredSampleTime(sample, m_scheduler.lastSampleTime(), m_scheduler.frameDuration());
-
- m_repaint = false; // OK to clear this flag now.
- } else {
- // Not a repaint request. Clear the desired sample time; the mixer will
- // give us the next frame in the stream.
- clearDesiredSampleTime(sample);
-
- if (m_clock) {
- // Latency: Record the starting time for ProcessOutput.
- m_clock->GetCorrelatedTime(0, &mixerStartTime, &systemTime);
- }
- }
-
- // Now we are ready to get an output sample from the mixer.
- dataBuffer.dwStreamID = 0;
- dataBuffer.pSample = sample;
- dataBuffer.dwStatus = 0;
-
- hr = m_mixer->ProcessOutput(0, 1, &dataBuffer, &status);
-
- if (FAILED(hr)) {
- // Return the sample to the pool.
- HRESULT hr2 = m_samplePool.returnSample(sample);
- if (FAILED(hr2)) {
- hr = hr2;
- goto done;
- }
- // Handle some known error codes from ProcessOutput.
- if (hr == MF_E_TRANSFORM_TYPE_NOT_SET) {
- // The mixer's format is not set. Negotiate a new format.
- hr = renegotiateMediaType();
- } else if (hr == MF_E_TRANSFORM_STREAM_CHANGE) {
- // There was a dynamic media type change. Clear our media type.
- setMediaType(NULL);
- } else if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) {
- // The mixer needs more input.
- // We have to wait for the mixer to get more input.
- m_sampleNotify = false;
- }
- } else {
- // We got an output sample from the mixer.
-
- if (m_clock && !repaint) {
- // Latency: Record the ending time for the ProcessOutput operation,
- // and notify the EVR of the latency.
-
- m_clock->GetCorrelatedTime(0, &mixerEndTime, &systemTime);
-
- LONGLONG latencyTime = mixerEndTime - mixerStartTime;
- notifyEvent(EC_PROCESSING_LATENCY, reinterpret_cast<LONG_PTR>(&latencyTime), 0);
- }
-
- // Set up notification for when the sample is released.
- hr = trackSample(sample);
- if (FAILED(hr))
- goto done;
-
- // Schedule the sample.
- if ((m_frameStep.state == FrameStepNone) || repaint) {
- hr = deliverSample(sample, repaint);
- if (FAILED(hr))
- goto done;
- } else {
- // We are frame-stepping (and this is not a repaint request).
- hr = deliverFrameStepSample(sample);
- if (FAILED(hr))
- goto done;
- }
-
- m_prerolled = true; // We have presented at least one sample now.
- }
-
-done:
- qt_evr_safe_release(&sample);
-
- // Important: Release any events returned from the ProcessOutput method.
- qt_evr_safe_release(&dataBuffer.pEvents);
- return hr;
-}
-
-HRESULT EVRCustomPresenter::deliverSample(IMFSample *sample, bool repaint)
-{
- // If we are not actively playing, OR we are scrubbing (rate = 0) OR this is a
- // repaint request, then we need to present the sample immediately. Otherwise,
- // schedule it normally.
-
- bool presentNow = ((m_renderState != RenderStarted) || isScrubbing() || repaint);
-
- HRESULT hr = m_scheduler.scheduleSample(sample, presentNow);
-
- if (FAILED(hr)) {
- // Notify the EVR that we have failed during streaming. The EVR will notify the
- // pipeline.
-
- notifyEvent(EC_ERRORABORT, hr, 0);
- }
-
- return hr;
-}
-
-HRESULT EVRCustomPresenter::deliverFrameStepSample(IMFSample *sample)
-{
- HRESULT hr = S_OK;
- IUnknown *unk = NULL;
-
- // For rate 0, discard any sample that ends earlier than the clock time.
- if (isScrubbing() && m_clock && qt_evr_isSampleTimePassed(m_clock, sample)) {
- // Discard this sample.
- } else if (m_frameStep.state >= FrameStepScheduled) {
- // A frame was already submitted. Put this sample on the frame-step queue,
- // in case we are asked to step to the next frame. If frame-stepping is
- // cancelled, this sample will be processed normally.
- sample->AddRef();
- m_frameStep.samples.append(sample);
- } else {
- // We're ready to frame-step.
-
- // Decrement the number of steps.
- if (m_frameStep.steps > 0)
- m_frameStep.steps--;
-
- if (m_frameStep.steps > 0) {
- // This is not the last step. Discard this sample.
- } else if (m_frameStep.state == FrameStepWaitingStart) {
- // This is the right frame, but the clock hasn't started yet. Put the
- // sample on the frame-step queue. When the clock starts, the sample
- // will be processed.
- sample->AddRef();
- m_frameStep.samples.append(sample);
- } else {
- // This is the right frame *and* the clock has started. Deliver this sample.
- hr = deliverSample(sample, false);
- if (FAILED(hr))
- goto done;
-
- // Query for IUnknown so that we can identify the sample later.
- // Per COM rules, an object always returns the same pointer when QI'ed for IUnknown.
- hr = sample->QueryInterface(IID_PPV_ARGS(&unk));
- if (FAILED(hr))
- goto done;
-
- m_frameStep.sampleNoRef = reinterpret_cast<DWORD_PTR>(unk); // No add-ref.
-
- // NOTE: We do not AddRef the IUnknown pointer, because that would prevent the
- // sample from invoking the OnSampleFree callback after the sample is presented.
- // We use this IUnknown pointer purely to identify the sample later; we never
- // attempt to dereference the pointer.
-
- m_frameStep.state = FrameStepScheduled;
- }
- }
-done:
- qt_evr_safe_release(&unk);
- return hr;
-}
-
-HRESULT EVRCustomPresenter::trackSample(IMFSample *sample)
-{
- IMFTrackedSample *tracked = NULL;
-
- HRESULT hr = sample->QueryInterface(IID_PPV_ARGS(&tracked));
-
- if (SUCCEEDED(hr))
- hr = tracked->SetAllocator(&m_sampleFreeCB, NULL);
-
- qt_evr_safe_release(&tracked);
- return hr;
-}
-
-void EVRCustomPresenter::releaseResources()
-{
- // Increment the token counter to indicate that all existing video samples
- // are "stale." As these samples get released, we'll dispose of them.
- //
- // Note: The token counter is required because the samples are shared
- // between more than one thread, and they are returned to the presenter
- // through an asynchronous callback (onSampleFree). Without the token, we
- // might accidentally re-use a stale sample after the ReleaseResources
- // method returns.
-
- m_tokenCounter++;
-
- flush();
-
- m_samplePool.clear();
-
- m_presentEngine->releaseResources();
-}
-
-HRESULT EVRCustomPresenter::onSampleFree(IMFAsyncResult *result)
-{
- IUnknown *object = NULL;
- IMFSample *sample = NULL;
- IUnknown *unk = NULL;
- UINT32 token;
-
- // Get the sample from the async result object.
- HRESULT hr = result->GetObject(&object);
- if (FAILED(hr))
- goto done;
-
- hr = object->QueryInterface(IID_PPV_ARGS(&sample));
- if (FAILED(hr))
- goto done;
-
- // If this sample was submitted for a frame-step, the frame step operation
- // is complete.
-
- if (m_frameStep.state == FrameStepScheduled) {
- // Query the sample for IUnknown and compare it to our cached value.
- hr = sample->QueryInterface(IID_PPV_ARGS(&unk));
- if (FAILED(hr))
- goto done;
-
- if (m_frameStep.sampleNoRef == reinterpret_cast<DWORD_PTR>(unk)) {
- // Notify the EVR.
- hr = completeFrameStep(sample);
- if (FAILED(hr))
- goto done;
- }
-
- // Note: Although object is also an IUnknown pointer, it is not
- // guaranteed to be the exact pointer value returned through
- // QueryInterface. Therefore, the second QueryInterface call is
- // required.
- }
-
- m_mutex.lock();
-
- token = MFGetAttributeUINT32(sample, MFSamplePresenter_SampleCounter, (UINT32)-1);
-
- if (token == m_tokenCounter) {
- // Return the sample to the sample pool.
- hr = m_samplePool.returnSample(sample);
- if (SUCCEEDED(hr)) {
- // A free sample is available. Process more data if possible.
- processOutputLoop();
- }
- }
-
- m_mutex.unlock();
-
-done:
- if (FAILED(hr))
- notifyEvent(EC_ERRORABORT, hr, 0);
- qt_evr_safe_release(&object);
- qt_evr_safe_release(&sample);
- qt_evr_safe_release(&unk);
- return hr;
-}
-
-float EVRCustomPresenter::getMaxRate(bool thin)
-{
- // Non-thinned:
- // If we have a valid frame rate and a monitor refresh rate, the maximum
- // playback rate is equal to the refresh rate. Otherwise, the maximum rate
- // is unbounded (FLT_MAX).
-
- // Thinned: The maximum rate is unbounded.
-
- float maxRate = FLT_MAX;
- MFRatio fps = { 0, 0 };
- UINT monitorRateHz = 0;
-
- if (!thin && m_mediaType) {
- qt_evr_getFrameRate(m_mediaType, &fps);
- monitorRateHz = m_presentEngine->refreshRate();
-
- if (fps.Denominator && fps.Numerator && monitorRateHz) {
- // Max Rate = Refresh Rate / Frame Rate
- maxRate = (float)MulDiv(monitorRateHz, fps.Denominator, fps.Numerator);
- }
- }
-
- return maxRate;
-}
-
-bool EVRCustomPresenter::event(QEvent *e)
-{
- switch (int(e->type())) {
- case StartSurface:
- startSurface();
- return true;
- case StopSurface:
- stopSurface();
- return true;
- case PresentSample:
- presentSample(static_cast<PresentSampleEvent *>(e)->sample());
- return true;
- default:
- break;
- }
- return QObject::event(e);
-}
-
-void EVRCustomPresenter::startSurface()
-{
- if (thread() != QThread::currentThread()) {
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StartSurface)));
- return;
- }
-
- if (!m_surface || m_surface->isActive())
- return;
-
- QVideoSurfaceFormat format = m_presentEngine->videoSurfaceFormat();
- if (!format.isValid())
- return;
-
- m_surface->start(format);
-}
-
-void EVRCustomPresenter::stopSurface()
-{
- if (thread() != QThread::currentThread()) {
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StopSurface)));
- return;
- }
-
- if (!m_surface || !m_surface->isActive())
- return;
-
- m_surface->stop();
-}
-
-void EVRCustomPresenter::presentSample(IMFSample *sample)
-{
- if (thread() != QThread::currentThread()) {
- QCoreApplication::postEvent(this, new PresentSampleEvent(sample));
- return;
- }
-
- if (!m_surface || !m_presentEngine->videoSurfaceFormat().isValid())
- return;
-
- QVideoFrame frame = m_presentEngine->makeVideoFrame(sample);
-
- // Since start/end times are related to a position when the clock is started,
- // to have times from the beginning, need to adjust it by adding seeked position.
- if (m_positionOffset) {
- if (frame.startTime())
- frame.setStartTime(frame.startTime() + m_positionOffset);
- if (frame.endTime())
- frame.setEndTime(frame.endTime() + m_positionOffset);
- }
-
- if (!m_surface->isActive() || m_surface->surfaceFormat() != m_presentEngine->videoSurfaceFormat()) {
- m_surface->stop();
- if (!m_surface->start(m_presentEngine->videoSurfaceFormat()))
- return;
- }
-
- m_surface->present(frame);
-}
-
-void EVRCustomPresenter::positionChanged(qint64 position)
-{
- m_positionOffset = position * 1000;
-}
-
-HRESULT setDesiredSampleTime(IMFSample *sample, const LONGLONG &sampleTime, const LONGLONG &duration)
-{
- if (!sample)
- return E_POINTER;
-
- HRESULT hr = S_OK;
- IMFDesiredSample *desired = NULL;
-
- hr = sample->QueryInterface(IID_PPV_ARGS(&desired));
- if (SUCCEEDED(hr))
- desired->SetDesiredSampleTimeAndDuration(sampleTime, duration);
-
- qt_evr_safe_release(&desired);
- return hr;
-}
-
-HRESULT clearDesiredSampleTime(IMFSample *sample)
-{
- if (!sample)
- return E_POINTER;
-
- HRESULT hr = S_OK;
-
- IMFDesiredSample *desired = NULL;
- IUnknown *unkSwapChain = NULL;
-
- // We store some custom attributes on the sample, so we need to cache them
- // and reset them.
- //
- // This works around the fact that IMFDesiredSample::Clear() removes all of the
- // attributes from the sample.
-
- UINT32 counter = MFGetAttributeUINT32(sample, MFSamplePresenter_SampleCounter, (UINT32)-1);
-
- hr = sample->QueryInterface(IID_PPV_ARGS(&desired));
- if (SUCCEEDED(hr)) {
- desired->Clear();
-
- hr = sample->SetUINT32(MFSamplePresenter_SampleCounter, counter);
- if (FAILED(hr))
- goto done;
- }
-
-done:
- qt_evr_safe_release(&unkSwapChain);
- qt_evr_safe_release(&desired);
- return hr;
-}
-
-HRESULT setMixerSourceRect(IMFTransform *mixer, const MFVideoNormalizedRect &sourceRect)
-{
- if (!mixer)
- return E_POINTER;
-
- IMFAttributes *attributes = NULL;
-
- HRESULT hr = mixer->GetAttributes(&attributes);
- if (SUCCEEDED(hr)) {
- hr = attributes->SetBlob(video_ZOOM_RECT, reinterpret_cast<const UINT8*>(&sourceRect),
- sizeof(sourceRect));
- attributes->Release();
- }
- return hr;
-}
-
-static QVideoFrame::PixelFormat pixelFormatFromMediaType(IMFMediaType *type)
-{
- GUID majorType;
- if (FAILED(type->GetMajorType(&majorType)))
- return QVideoFrame::Format_Invalid;
- if (majorType != MFMediaType_Video)
- return QVideoFrame::Format_Invalid;
-
- GUID subtype;
- if (FAILED(type->GetGUID(MF_MT_SUBTYPE, &subtype)))
- return QVideoFrame::Format_Invalid;
-
- if (subtype == MFVideoFormat_RGB32)
- return QVideoFrame::Format_RGB32;
- if (subtype == MFVideoFormat_ARGB32)
- return QVideoFrame::Format_ARGB32;
- if (subtype == MFVideoFormat_RGB24)
- return QVideoFrame::Format_RGB24;
- if (subtype == MFVideoFormat_RGB565)
- return QVideoFrame::Format_RGB565;
- if (subtype == MFVideoFormat_RGB555)
- return QVideoFrame::Format_RGB555;
- if (subtype == MFVideoFormat_AYUV)
- return QVideoFrame::Format_AYUV444;
- if (subtype == MFVideoFormat_I420)
- return QVideoFrame::Format_YUV420P;
- if (subtype == MFVideoFormat_UYVY)
- return QVideoFrame::Format_UYVY;
- if (subtype == MFVideoFormat_YV12)
- return QVideoFrame::Format_YV12;
- if (subtype == MFVideoFormat_NV12)
- return QVideoFrame::Format_NV12;
-
- return QVideoFrame::Format_Invalid;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/common/evr/evrcustompresenter.h b/src/plugins/common/evr/evrcustompresenter.h
deleted file mode 100644
index c1c21580e..000000000
--- a/src/plugins/common/evr/evrcustompresenter.h
+++ /dev/null
@@ -1,377 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef EVRCUSTOMPRESENTER_H
-#define EVRCUSTOMPRESENTER_H
-
-#include <QObject>
-#include <qmutex.h>
-#include <qqueue.h>
-#include <qevent.h>
-#include <qvideosurfaceformat.h>
-
-#include "evrdefs.h"
-
-QT_BEGIN_NAMESPACE
-
-class EVRCustomPresenter;
-class D3DPresentEngine;
-
-class QAbstractVideoSurface;
-
-template<class T>
-class AsyncCallback : public IMFAsyncCallback
-{
- Q_DISABLE_COPY(AsyncCallback)
-public:
- typedef HRESULT (T::*InvokeFn)(IMFAsyncResult *asyncResult);
-
- AsyncCallback(T *parent, InvokeFn fn) : m_parent(parent), m_invokeFn(fn)
- {
- }
-
- // IUnknown
- STDMETHODIMP QueryInterface(REFIID iid, void** ppv) override
- {
- if (!ppv)
- return E_POINTER;
-
- if (iid == __uuidof(IUnknown)) {
- *ppv = static_cast<IUnknown*>(static_cast<IMFAsyncCallback*>(this));
- } else if (iid == __uuidof(IMFAsyncCallback)) {
- *ppv = static_cast<IMFAsyncCallback*>(this);
- } else {
- *ppv = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
- }
-
- STDMETHODIMP_(ULONG) AddRef() override {
- // Delegate to parent class.
- return m_parent->AddRef();
- }
- STDMETHODIMP_(ULONG) Release() override {
- // Delegate to parent class.
- return m_parent->Release();
- }
-
- // IMFAsyncCallback methods
- STDMETHODIMP GetParameters(DWORD*, DWORD*) override
- {
- // Implementation of this method is optional.
- return E_NOTIMPL;
- }
-
- STDMETHODIMP Invoke(IMFAsyncResult* asyncResult) override
- {
- return (m_parent->*m_invokeFn)(asyncResult);
- }
-
- T *m_parent;
- InvokeFn m_invokeFn;
-};
-
-class Scheduler
-{
- Q_DISABLE_COPY(Scheduler)
-public:
- enum ScheduleEvent
- {
- Terminate = WM_USER,
- Schedule = WM_USER + 1,
- Flush = WM_USER + 2
- };
-
- Scheduler(EVRCustomPresenter *presenter);
- ~Scheduler();
-
- void setFrameRate(const MFRatio &fps);
- void setClockRate(float rate) { m_playbackRate = rate; }
-
- const LONGLONG &lastSampleTime() const { return m_lastSampleTime; }
- const LONGLONG &frameDuration() const { return m_perFrameInterval; }
-
- HRESULT startScheduler(IMFClock *clock);
- HRESULT stopScheduler();
-
- HRESULT scheduleSample(IMFSample *sample, bool presentNow);
- HRESULT processSamplesInQueue(LONG *nextSleep);
- HRESULT processSample(IMFSample *sample, LONG *nextSleep);
- HRESULT flush();
-
- bool areSamplesScheduled();
-
- // ThreadProc for the scheduler thread.
- static DWORD WINAPI schedulerThreadProc(LPVOID parameter);
-
-private:
- DWORD schedulerThreadProcPrivate();
-
- EVRCustomPresenter *m_presenter;
-
- QQueue<IMFSample*> m_scheduledSamples; // Samples waiting to be presented.
-
- IMFClock *m_clock; // Presentation clock. Can be NULL.
-
- DWORD m_threadID;
- HANDLE m_schedulerThread;
- HANDLE m_threadReadyEvent;
- HANDLE m_flushEvent;
-
- float m_playbackRate;
- MFTIME m_perFrameInterval; // Duration of each frame.
- LONGLONG m_perFrame_1_4th; // 1/4th of the frame duration.
- MFTIME m_lastSampleTime; // Most recent sample time.
-
- QMutex m_mutex;
-};
-
-class SamplePool
-{
- Q_DISABLE_COPY(SamplePool)
-public:
- SamplePool();
- ~SamplePool();
-
- HRESULT initialize(QList<IMFSample*> &samples);
- HRESULT clear();
-
- HRESULT getSample(IMFSample **sample);
- HRESULT returnSample(IMFSample *sample);
-
-private:
- QMutex m_mutex;
- QList<IMFSample*> m_videoSampleQueue;
- bool m_initialized;
-};
-
-class EVRCustomPresenter
- : public QObject
- , public IMFVideoDeviceID
- , public IMFVideoPresenter // Inherits IMFClockStateSink
- , public IMFRateSupport
- , public IMFGetService
- , public IMFTopologyServiceLookupClient
-{
- Q_DISABLE_COPY(EVRCustomPresenter)
-public:
- // Defines the state of the presenter.
- enum RenderState
- {
- RenderStarted = 1,
- RenderStopped,
- RenderPaused,
- RenderShutdown // Initial state.
- };
-
- // Defines the presenter's state with respect to frame-stepping.
- enum FrameStepState
- {
- FrameStepNone, // Not frame stepping.
- FrameStepWaitingStart, // Frame stepping, but the clock is not started.
- FrameStepPending, // Clock is started. Waiting for samples.
- FrameStepScheduled, // Submitted a sample for rendering.
- FrameStepComplete // Sample was rendered.
- };
-
- enum PresenterEvents
- {
- StartSurface = QEvent::User,
- StopSurface = QEvent::User + 1,
- PresentSample = QEvent::User + 2
- };
-
- EVRCustomPresenter(QAbstractVideoSurface *surface = 0);
- ~EVRCustomPresenter() override;
-
- bool isValid() const;
-
- // IUnknown methods
- STDMETHODIMP QueryInterface(REFIID riid, void ** ppv) override;
- STDMETHODIMP_(ULONG) AddRef() override;
- STDMETHODIMP_(ULONG) Release() override;
-
- // IMFGetService methods
- STDMETHODIMP GetService(REFGUID guidService, REFIID riid, LPVOID *ppvObject) override;
-
- // IMFVideoPresenter methods
- STDMETHODIMP ProcessMessage(MFVP_MESSAGE_TYPE message, ULONG_PTR param) override;
- STDMETHODIMP GetCurrentMediaType(IMFVideoMediaType** mediaType) override;
-
- // IMFClockStateSink methods
- STDMETHODIMP OnClockStart(MFTIME systemTime, LONGLONG clockStartOffset) override;
- STDMETHODIMP OnClockStop(MFTIME systemTime) override;
- STDMETHODIMP OnClockPause(MFTIME systemTime) override;
- STDMETHODIMP OnClockRestart(MFTIME systemTime) override;
- STDMETHODIMP OnClockSetRate(MFTIME systemTime, float rate) override;
-
- // IMFRateSupport methods
- STDMETHODIMP GetSlowestRate(MFRATE_DIRECTION direction, BOOL thin, float *rate) override;
- STDMETHODIMP GetFastestRate(MFRATE_DIRECTION direction, BOOL thin, float *rate) override;
- STDMETHODIMP IsRateSupported(BOOL thin, float rate, float *nearestSupportedRate) override;
-
- // IMFVideoDeviceID methods
- STDMETHODIMP GetDeviceID(IID* deviceID) override;
-
- // IMFTopologyServiceLookupClient methods
- STDMETHODIMP InitServicePointers(IMFTopologyServiceLookup *lookup) override;
- STDMETHODIMP ReleaseServicePointers() override;
-
- void supportedFormatsChanged();
- void setSurface(QAbstractVideoSurface *surface);
-
- void startSurface();
- void stopSurface();
- void presentSample(IMFSample *sample);
-
- bool event(QEvent *) override;
-
-public Q_SLOTS:
- void positionChanged(qint64 position);
-
-private:
- HRESULT checkShutdown() const
- {
- if (m_renderState == RenderShutdown)
- return MF_E_SHUTDOWN;
- else
- return S_OK;
- }
-
- // The "active" state is started or paused.
- inline bool isActive() const
- {
- return ((m_renderState == RenderStarted) || (m_renderState == RenderPaused));
- }
-
- // Scrubbing occurs when the frame rate is 0.
- inline bool isScrubbing() const { return m_playbackRate == 0.0f; }
-
- // Send an event to the EVR through its IMediaEventSink interface.
- void notifyEvent(long eventCode, LONG_PTR param1, LONG_PTR param2)
- {
- if (m_mediaEventSink)
- m_mediaEventSink->Notify(eventCode, param1, param2);
- }
-
- float getMaxRate(bool thin);
-
- // Mixer operations
- HRESULT configureMixer(IMFTransform *mixer);
-
- // Formats
- HRESULT createOptimalVideoType(IMFMediaType* proposed, IMFMediaType **optimal);
- HRESULT setMediaType(IMFMediaType *mediaType);
- HRESULT isMediaTypeSupported(IMFMediaType *mediaType);
-
- // Message handlers
- HRESULT flush();
- HRESULT renegotiateMediaType();
- HRESULT processInputNotify();
- HRESULT beginStreaming();
- HRESULT endStreaming();
- HRESULT checkEndOfStream();
-
- // Managing samples
- void processOutputLoop();
- HRESULT processOutput();
- HRESULT deliverSample(IMFSample *sample, bool repaint);
- HRESULT trackSample(IMFSample *sample);
- void releaseResources();
-
- // Frame-stepping
- HRESULT prepareFrameStep(DWORD steps);
- HRESULT startFrameStep();
- HRESULT deliverFrameStepSample(IMFSample *sample);
- HRESULT completeFrameStep(IMFSample *sample);
- HRESULT cancelFrameStep();
-
- // Callback when a video sample is released.
- HRESULT onSampleFree(IMFAsyncResult *result);
- AsyncCallback<EVRCustomPresenter> m_sampleFreeCB;
-
- // Holds information related to frame-stepping.
- struct FrameStep
- {
- FrameStepState state = FrameStepNone;
- QList<IMFSample*> samples;
- DWORD steps = 0;
- DWORD_PTR sampleNoRef = 0;
- };
-
- long m_refCount;
-
- RenderState m_renderState;
- FrameStep m_frameStep;
-
- QRecursiveMutex m_mutex;
-
- // Samples and scheduling
- Scheduler m_scheduler; // Manages scheduling of samples.
- SamplePool m_samplePool; // Pool of allocated samples.
- DWORD m_tokenCounter; // Counter. Incremented whenever we create new samples.
-
- // Rendering state
- bool m_sampleNotify; // Did the mixer signal it has an input sample?
- bool m_repaint; // Do we need to repaint the last sample?
- bool m_prerolled; // Have we presented at least one sample?
- bool m_endStreaming; // Did we reach the end of the stream (EOS)?
-
- MFVideoNormalizedRect m_sourceRect;
- float m_playbackRate;
-
- D3DPresentEngine *m_presentEngine; // Rendering engine. (Never null if the constructor succeeds.)
-
- IMFClock *m_clock; // The EVR's clock.
- IMFTransform *m_mixer; // The EVR's mixer.
- IMediaEventSink *m_mediaEventSink; // The EVR's event-sink interface.
- IMFMediaType *m_mediaType; // Output media type
-
- QAbstractVideoSurface *m_surface;
- bool m_canRenderToSurface;
- qint64 m_positionOffset; // Seek position in microseconds.
-};
-
-bool qt_evr_setCustomPresenter(IUnknown *evr, EVRCustomPresenter *presenter);
-
-QT_END_NAMESPACE
-
-#endif // EVRCUSTOMPRESENTER_H
diff --git a/src/plugins/common/evr/evrd3dpresentengine.cpp b/src/plugins/common/evr/evrd3dpresentengine.cpp
deleted file mode 100644
index 964504e48..000000000
--- a/src/plugins/common/evr/evrd3dpresentengine.cpp
+++ /dev/null
@@ -1,413 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "evrd3dpresentengine.h"
-
-#include "evrhelpers.h"
-
-#include <qabstractvideobuffer.h>
-#include <QAbstractVideoSurface>
-#include <qvideoframe.h>
-#include <QDebug>
-#include <qthread.h>
-#include <QOffscreenSurface>
-
-static const int PRESENTER_BUFFER_COUNT = 3;
-
-QT_BEGIN_NAMESPACE
-
-class IMFSampleVideoBuffer: public QAbstractVideoBuffer
-{
-public:
- IMFSampleVideoBuffer(D3DPresentEngine *engine, IMFSample *sample, QAbstractVideoBuffer::HandleType handleType)
- : QAbstractVideoBuffer(handleType)
- , m_engine(engine)
- , m_sample(sample)
- , m_surface(0)
- , m_mapMode(NotMapped)
- {
- if (m_sample) {
- m_sample->AddRef();
-
- IMFMediaBuffer *buffer;
- if (SUCCEEDED(m_sample->GetBufferByIndex(0, &buffer))) {
- MFGetService(buffer,
- mr_BUFFER_SERVICE,
- iid_IDirect3DSurface9,
- reinterpret_cast<void **>(&m_surface));
- buffer->Release();
- }
- }
- }
-
- ~IMFSampleVideoBuffer() override
- {
- if (m_surface) {
- if (m_mapMode != NotMapped)
- m_surface->UnlockRect();
- m_surface->Release();
- }
- if (m_sample)
- m_sample->Release();
- }
-
- QVariant handle() const override;
-
- MapMode mapMode() const override { return m_mapMode; }
- uchar *map(MapMode, int*, int*) override;
- void unmap() override;
-
-private:
- mutable D3DPresentEngine *m_engine;
- IMFSample *m_sample;
- IDirect3DSurface9 *m_surface;
- MapMode m_mapMode;
- mutable unsigned int m_textureId = 0;
-};
-
-uchar *IMFSampleVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
-{
- if (!m_surface || m_mapMode != NotMapped)
- return 0;
-
- D3DSURFACE_DESC desc;
- if (FAILED(m_surface->GetDesc(&desc)))
- return 0;
-
- D3DLOCKED_RECT rect;
- if (FAILED(m_surface->LockRect(&rect, NULL, mode == ReadOnly ? D3DLOCK_READONLY : 0)))
- return 0;
-
- m_mapMode = mode;
-
- if (numBytes)
- *numBytes = (int)(rect.Pitch * desc.Height);
-
- if (bytesPerLine)
- *bytesPerLine = (int)rect.Pitch;
-
- return reinterpret_cast<uchar *>(rect.pBits);
-}
-
-void IMFSampleVideoBuffer::unmap()
-{
- if (m_mapMode == NotMapped)
- return;
-
- m_mapMode = NotMapped;
- m_surface->UnlockRect();
-}
-
-QVariant IMFSampleVideoBuffer::handle() const
-{
- return m_textureId;
-}
-
-
-D3DPresentEngine::D3DPresentEngine()
- : m_deviceResetToken(0)
- , m_D3D9(0)
- , m_device(0)
- , m_deviceManager(0)
- , m_useTextureRendering(false)
-{
- ZeroMemory(&m_displayMode, sizeof(m_displayMode));
-
- HRESULT hr = initializeD3D();
-
- if (SUCCEEDED(hr)) {
- hr = createD3DDevice();
- if (FAILED(hr))
- qWarning("Failed to create D3D device");
- } else {
- qWarning("Failed to initialize D3D");
- }
-}
-
-D3DPresentEngine::~D3DPresentEngine()
-{
- releaseResources();
-
- qt_evr_safe_release(&m_device);
- qt_evr_safe_release(&m_deviceManager);
- qt_evr_safe_release(&m_D3D9);
-}
-
-HRESULT D3DPresentEngine::initializeD3D()
-{
- HRESULT hr = Direct3DCreate9Ex(D3D_SDK_VERSION, &m_D3D9);
-
- if (SUCCEEDED(hr))
- hr = DXVA2CreateDirect3DDeviceManager9(&m_deviceResetToken, &m_deviceManager);
-
- return hr;
-}
-
-HRESULT D3DPresentEngine::createD3DDevice()
-{
- HRESULT hr = S_OK;
- HWND hwnd = NULL;
- UINT uAdapterID = D3DADAPTER_DEFAULT;
- DWORD vp = 0;
-
- D3DCAPS9 ddCaps;
- ZeroMemory(&ddCaps, sizeof(ddCaps));
-
- IDirect3DDevice9Ex* device = NULL;
-
- if (!m_D3D9 || !m_deviceManager)
- return MF_E_NOT_INITIALIZED;
-
- hwnd = ::GetShellWindow();
-
- D3DPRESENT_PARAMETERS pp;
- ZeroMemory(&pp, sizeof(pp));
-
- pp.BackBufferWidth = 1;
- pp.BackBufferHeight = 1;
- pp.BackBufferFormat = D3DFMT_UNKNOWN;
- pp.BackBufferCount = 1;
- pp.Windowed = TRUE;
- pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
- pp.BackBufferFormat = D3DFMT_UNKNOWN;
- pp.hDeviceWindow = hwnd;
- pp.Flags = D3DPRESENTFLAG_VIDEO;
- pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
-
- hr = m_D3D9->GetDeviceCaps(uAdapterID, D3DDEVTYPE_HAL, &ddCaps);
- if (FAILED(hr))
- goto done;
-
- if (ddCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
- vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
- else
- vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
-
- hr = m_D3D9->CreateDeviceEx(
- uAdapterID,
- D3DDEVTYPE_HAL,
- pp.hDeviceWindow,
- vp | D3DCREATE_NOWINDOWCHANGES | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
- &pp,
- NULL,
- &device
- );
- if (FAILED(hr))
- goto done;
-
- hr = m_D3D9->GetAdapterDisplayMode(uAdapterID, &m_displayMode);
- if (FAILED(hr))
- goto done;
-
- hr = m_deviceManager->ResetDevice(device, m_deviceResetToken);
- if (FAILED(hr))
- goto done;
-
- qt_evr_safe_release(&m_device);
-
- m_device = device;
- m_device->AddRef();
-
-done:
- qt_evr_safe_release(&device);
- return hr;
-}
-
-bool D3DPresentEngine::isValid() const
-{
- return m_device != NULL;
-}
-
-void D3DPresentEngine::releaseResources()
-{
- m_surfaceFormat = QVideoSurfaceFormat();
-}
-
-HRESULT D3DPresentEngine::getService(REFGUID, REFIID riid, void** ppv)
-{
- HRESULT hr = S_OK;
-
- if (riid == __uuidof(IDirect3DDeviceManager9)) {
- if (m_deviceManager == NULL) {
- hr = MF_E_UNSUPPORTED_SERVICE;
- } else {
- *ppv = m_deviceManager;
- m_deviceManager->AddRef();
- }
- } else {
- hr = MF_E_UNSUPPORTED_SERVICE;
- }
-
- return hr;
-}
-
-HRESULT D3DPresentEngine::checkFormat(D3DFORMAT format)
-{
- if (!m_D3D9 || !m_device)
- return E_FAIL;
-
- HRESULT hr = S_OK;
-
- D3DDISPLAYMODE mode;
- D3DDEVICE_CREATION_PARAMETERS params;
-
- hr = m_device->GetCreationParameters(&params);
- if (FAILED(hr))
- return hr;
-
- UINT uAdapter = params.AdapterOrdinal;
- D3DDEVTYPE type = params.DeviceType;
-
- hr = m_D3D9->GetAdapterDisplayMode(uAdapter, &mode);
- if (FAILED(hr))
- return hr;
-
- hr = m_D3D9->CheckDeviceFormat(uAdapter, type, mode.Format,
- D3DUSAGE_RENDERTARGET,
- D3DRTYPE_SURFACE,
- format);
-
- if (m_useTextureRendering && format != D3DFMT_X8R8G8B8 && format != D3DFMT_A8R8G8B8) {
- // The texture is always in RGB32 so the d3d driver must support conversion from the
- // requested format to RGB32.
- hr = m_D3D9->CheckDeviceFormatConversion(uAdapter, type, format, D3DFMT_X8R8G8B8);
- }
-
- return hr;
-}
-
-bool D3DPresentEngine::supportsTextureRendering() const
-{
- return false;
-}
-
-void D3DPresentEngine::setHint(Hint hint, bool enable)
-{
- if (hint == RenderToTexture)
- m_useTextureRendering = enable && supportsTextureRendering();
-}
-
-HRESULT D3DPresentEngine::createVideoSamples(IMFMediaType *format, QList<IMFSample*> &videoSampleQueue)
-{
- if (!format)
- return MF_E_UNEXPECTED;
-
- HRESULT hr = S_OK;
-
- IDirect3DSurface9 *surface = NULL;
- IMFSample *videoSample = NULL;
-
- releaseResources();
-
- UINT32 width = 0, height = 0;
- hr = MFGetAttributeSize(format, MF_MT_FRAME_SIZE, &width, &height);
- if (FAILED(hr))
- return hr;
-
- DWORD d3dFormat = 0;
- hr = qt_evr_getFourCC(format, &d3dFormat);
- if (FAILED(hr))
- return hr;
-
- // Create the video samples.
- for (int i = 0; i < PRESENTER_BUFFER_COUNT; i++) {
- hr = m_device->CreateRenderTarget(width, height,
- (D3DFORMAT)d3dFormat,
- D3DMULTISAMPLE_NONE,
- 0,
- TRUE,
- &surface, NULL);
- if (FAILED(hr))
- goto done;
-
- hr = MFCreateVideoSampleFromSurface(surface, &videoSample);
- if (FAILED(hr))
- goto done;
-
- videoSample->AddRef();
- videoSampleQueue.append(videoSample);
-
- qt_evr_safe_release(&videoSample);
- qt_evr_safe_release(&surface);
- }
-
-done:
- if (SUCCEEDED(hr)) {
- m_surfaceFormat = QVideoSurfaceFormat(QSize(width, height),
- m_useTextureRendering ? QVideoFrame::Format_RGB32
- : qt_evr_pixelFormatFromD3DFormat(d3dFormat),
- m_useTextureRendering ? QAbstractVideoBuffer::GLTextureHandle
- : QAbstractVideoBuffer::NoHandle);
- UINT32 horizontal = 1, vertical = 1;
- hr = MFGetAttributeRatio(format, MF_MT_PIXEL_ASPECT_RATIO, &horizontal, &vertical);
- if (SUCCEEDED(hr))
- m_surfaceFormat.setPixelAspectRatio(horizontal, vertical);
- } else {
- releaseResources();
- }
-
- qt_evr_safe_release(&videoSample);
- qt_evr_safe_release(&surface);
- return hr;
-}
-
-QVideoFrame D3DPresentEngine::makeVideoFrame(IMFSample *sample)
-{
- if (!sample)
- return QVideoFrame();
-
- QVideoFrame frame(new IMFSampleVideoBuffer(this, sample, m_surfaceFormat.handleType()),
- m_surfaceFormat.frameSize(),
- m_surfaceFormat.pixelFormat());
-
- // WMF uses 100-nanosecond units, Qt uses microseconds
- LONGLONG startTime = 0;
- auto hr = sample->GetSampleTime(&startTime);
- if (SUCCEEDED(hr)) {
- frame.setStartTime(startTime * 0.1);
-
- LONGLONG duration = -1;
- if (SUCCEEDED(sample->GetSampleDuration(&duration)))
- frame.setEndTime((startTime + duration) * 0.1);
- }
-
- return frame;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/common/evr/evrd3dpresentengine.h b/src/plugins/common/evr/evrd3dpresentengine.h
deleted file mode 100644
index eb2def7b2..000000000
--- a/src/plugins/common/evr/evrd3dpresentengine.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef EVRD3DPRESENTENGINE_H
-#define EVRD3DPRESENTENGINE_H
-
-#include <QMutex>
-#include <QVideoSurfaceFormat>
-
-#include <d3d9.h>
-
-struct IDirect3D9Ex;
-struct IDirect3DDevice9Ex;
-struct IDirect3DDeviceManager9;
-struct IDirect3DSurface9;
-struct IDirect3DTexture9;
-struct IMFSample;
-struct IMFMediaType;
-
-// Randomly generated GUIDs
-static const GUID MFSamplePresenter_SampleCounter =
-{ 0xb0bb83cc, 0xf10f, 0x4e2e, { 0xaa, 0x2b, 0x29, 0xea, 0x5e, 0x92, 0xef, 0x85 } };
-
-QT_BEGIN_NAMESPACE
-
-class QAbstractVideoSurface;
-
-#ifdef MAYBE_ANGLE
-
-class OpenGLResources;
-
-class EGLWrapper
-{
- Q_DISABLE_COPY(EGLWrapper)
-public:
- EGLWrapper();
-
- __eglMustCastToProperFunctionPointerType getProcAddress(const char *procname);
- EGLSurface createPbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
- EGLBoolean destroySurface(EGLDisplay dpy, EGLSurface surface);
- EGLBoolean bindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
- EGLBoolean releaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
-
-private:
- typedef __eglMustCastToProperFunctionPointerType (EGLAPIENTRYP EglGetProcAddress)(const char *procname);
- typedef EGLSurface (EGLAPIENTRYP EglCreatePbufferSurface)(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
- typedef EGLBoolean (EGLAPIENTRYP EglDestroySurface)(EGLDisplay dpy, EGLSurface surface);
- typedef EGLBoolean (EGLAPIENTRYP EglBindTexImage)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
- typedef EGLBoolean (EGLAPIENTRYP EglReleaseTexImage)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
-
- EglGetProcAddress m_eglGetProcAddress;
- EglCreatePbufferSurface m_eglCreatePbufferSurface;
- EglDestroySurface m_eglDestroySurface;
- EglBindTexImage m_eglBindTexImage;
- EglReleaseTexImage m_eglReleaseTexImage;
-};
-
-#endif // MAYBE_ANGLE
-
-class D3DPresentEngine
-{
- Q_DISABLE_COPY(D3DPresentEngine)
-public:
- enum Hint
- {
- RenderToTexture
- };
-
- D3DPresentEngine();
- virtual ~D3DPresentEngine();
-
- bool isValid() const;
- void setHint(Hint hint, bool enable = true);
-
- HRESULT getService(REFGUID guidService, REFIID riid, void** ppv);
- HRESULT checkFormat(D3DFORMAT format);
- UINT refreshRate() const { return m_displayMode.RefreshRate; }
-
- bool supportsTextureRendering() const;
- bool isTextureRenderingEnabled() const { return m_useTextureRendering; }
-
- HRESULT createVideoSamples(IMFMediaType *format, QList<IMFSample*>& videoSampleQueue);
- QVideoSurfaceFormat videoSurfaceFormat() const { return m_surfaceFormat; }
- QVideoFrame makeVideoFrame(IMFSample* sample);
-
- void releaseResources();
-
-private:
- HRESULT initializeD3D();
- HRESULT createD3DDevice();
-
-
- UINT m_deviceResetToken;
- D3DDISPLAYMODE m_displayMode;
-
- IDirect3D9Ex *m_D3D9;
- IDirect3DDevice9Ex *m_device;
- IDirect3DDeviceManager9 *m_deviceManager;
-
- QVideoSurfaceFormat m_surfaceFormat;
-
- bool m_useTextureRendering;
-
-#ifdef MAYBE_ANGLE
- unsigned int updateTexture(IDirect3DSurface9 *src);
-
- OpenGLResources *m_glResources;
- IDirect3DTexture9 *m_texture;
-#endif
-
- friend class IMFSampleVideoBuffer;
-};
-
-QT_END_NAMESPACE
-
-#endif // EVRD3DPRESENTENGINE_H
diff --git a/src/plugins/common/evr/evrdefs.cpp b/src/plugins/common/evr/evrdefs.cpp
deleted file mode 100644
index e143ada0b..000000000
--- a/src/plugins/common/evr/evrdefs.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "evrdefs.h"
-
-const CLSID clsid_EnhancedVideoRenderer = { 0xfa10746c, 0x9b63, 0x4b6c, {0xbc, 0x49, 0xfc, 0x30, 0xe, 0xa5, 0xf2, 0x56} };
-const GUID mr_VIDEO_RENDER_SERVICE = { 0x1092a86c, 0xab1a, 0x459a, {0xa3, 0x36, 0x83, 0x1f, 0xbc, 0x4d, 0x11, 0xff} };
-const GUID mr_VIDEO_MIXER_SERVICE = { 0x73cd2fc, 0x6cf4, 0x40b7, {0x88, 0x59, 0xe8, 0x95, 0x52, 0xc8, 0x41, 0xf8} };
-const GUID mr_BUFFER_SERVICE = { 0xa562248c, 0x9ac6, 0x4ffc, {0x9f, 0xba, 0x3a, 0xf8, 0xf8, 0xad, 0x1a, 0x4d} };
-const GUID video_ZOOM_RECT = { 0x7aaa1638, 0x1b7f, 0x4c93, {0xbd, 0x89, 0x5b, 0x9c, 0x9f, 0xb6, 0xfc, 0xf0} };
-const GUID iid_IDirect3DDevice9 = { 0xd0223b96, 0xbf7a, 0x43fd, {0x92, 0xbd, 0xa4, 0x3b, 0xd, 0x82, 0xb9, 0xeb} };
-const GUID iid_IDirect3DSurface9 = { 0xcfbaf3a, 0x9ff6, 0x429a, {0x99, 0xb3, 0xa2, 0x79, 0x6a, 0xf8, 0xb8, 0x9b} };
diff --git a/src/plugins/common/evr/evrdefs.h b/src/plugins/common/evr/evrdefs.h
deleted file mode 100644
index 4f3dd832a..000000000
--- a/src/plugins/common/evr/evrdefs.h
+++ /dev/null
@@ -1,353 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef EVRDEFS_H
-#define EVRDEFS_H
-
-#include <d3d9.h>
-#include <evr9.h>
-#include <evr.h>
-#include <dxva2api.h>
-#include <mfapi.h>
-#include <mfidl.h>
-#include <mferror.h>
-
-extern const CLSID clsid_EnhancedVideoRenderer;
-extern const GUID mr_VIDEO_RENDER_SERVICE;
-extern const GUID mr_VIDEO_MIXER_SERVICE;
-extern const GUID mr_BUFFER_SERVICE;
-extern const GUID video_ZOOM_RECT;
-extern const GUID iid_IDirect3DDevice9;
-extern const GUID iid_IDirect3DSurface9;
-
-// The following is required to compile with MinGW
-
-extern "C" {
-HRESULT WINAPI MFCreateVideoSampleFromSurface(IUnknown *pUnkSurface, IMFSample **ppSample);
-HRESULT WINAPI Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex**);
-}
-
-#ifndef PRESENTATION_CURRENT_POSITION
-#define PRESENTATION_CURRENT_POSITION 0x7fffffffffffffff
-#endif
-
-#ifndef MF_E_SHUTDOWN
-#define MF_E_SHUTDOWN ((HRESULT)0xC00D3E85L)
-#endif
-
-#ifndef MF_E_SAMPLEALLOCATOR_EMPTY
-#define MF_E_SAMPLEALLOCATOR_EMPTY ((HRESULT)0xC00D4A3EL)
-#endif
-
-#ifndef MF_E_TRANSFORM_STREAM_CHANGE
-#define MF_E_TRANSFORM_STREAM_CHANGE ((HRESULT)0xC00D6D61L)
-#endif
-
-#ifndef MF_E_TRANSFORM_NEED_MORE_INPUT
-#define MF_E_TRANSFORM_NEED_MORE_INPUT ((HRESULT)0xC00D6D72L)
-#endif
-
-#if defined(__GNUC__) && !defined(_MFVideoNormalizedRect_)
-#define _MFVideoNormalizedRect_
-typedef struct MFVideoNormalizedRect {
- float left;
- float top;
- float right;
- float bottom;
-} MFVideoNormalizedRect;
-#endif
-
-#include <initguid.h>
-
-#ifndef __IMFGetService_INTERFACE_DEFINED__
-#define __IMFGetService_INTERFACE_DEFINED__
-DEFINE_GUID(IID_IMFGetService, 0xfa993888, 0x4383, 0x415a, 0xa9,0x30, 0xdd,0x47,0x2a,0x8c,0xf6,0xf7);
-MIDL_INTERFACE("fa993888-4383-415a-a930-dd472a8cf6f7")
-IMFGetService : public IUnknown
-{
- virtual HRESULT STDMETHODCALLTYPE GetService(REFGUID, REFIID, LPVOID *) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFGetService, 0xfa993888, 0x4383, 0x415a, 0xa9,0x30, 0xdd,0x47,0x2a,0x8c,0xf6,0xf7)
-#endif
-#endif // __IMFGetService_INTERFACE_DEFINED__
-
-#ifndef __IMFVideoDisplayControl_INTERFACE_DEFINED__
-#define __IMFVideoDisplayControl_INTERFACE_DEFINED__
-typedef enum MFVideoAspectRatioMode
-{
- MFVideoARMode_None = 0,
- MFVideoARMode_PreservePicture = 0x1,
- MFVideoARMode_PreservePixel = 0x2,
- MFVideoARMode_NonLinearStretch = 0x4,
- MFVideoARMode_Mask = 0x7
-} MFVideoAspectRatioMode;
-
-DEFINE_GUID(IID_IMFVideoDisplayControl, 0xa490b1e4, 0xab84, 0x4d31, 0xa1,0xb2, 0x18,0x1e,0x03,0xb1,0x07,0x7a);
-MIDL_INTERFACE("a490b1e4-ab84-4d31-a1b2-181e03b1077a")
-IMFVideoDisplayControl : public IUnknown
-{
- virtual HRESULT STDMETHODCALLTYPE GetNativeVideoSize(SIZE *, SIZE *) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetIdealVideoSize(SIZE *, SIZE *) = 0;
- virtual HRESULT STDMETHODCALLTYPE SetVideoPosition(const MFVideoNormalizedRect *, const LPRECT) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetVideoPosition(MFVideoNormalizedRect *, LPRECT) = 0;
- virtual HRESULT STDMETHODCALLTYPE SetAspectRatioMode(DWORD) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetAspectRatioMode(DWORD *) = 0;
- virtual HRESULT STDMETHODCALLTYPE SetVideoWindow(HWND) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetVideoWindow(HWND *) = 0;
- virtual HRESULT STDMETHODCALLTYPE RepaintVideo(void) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetCurrentImage(BITMAPINFOHEADER *, BYTE **, DWORD *, LONGLONG *) = 0;
- virtual HRESULT STDMETHODCALLTYPE SetBorderColor(COLORREF) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetBorderColor(COLORREF *) = 0;
- virtual HRESULT STDMETHODCALLTYPE SetRenderingPrefs(DWORD) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetRenderingPrefs(DWORD *) = 0;
- virtual HRESULT STDMETHODCALLTYPE SetFullscreen(BOOL) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetFullscreen(BOOL *) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFVideoDisplayControl, 0xa490b1e4, 0xab84, 0x4d31, 0xa1,0xb2, 0x18,0x1e,0x03,0xb1,0x07,0x7a)
-#endif
-#endif // __IMFVideoDisplayControl_INTERFACE_DEFINED__
-
-#ifndef __IMFVideoProcessor_INTERFACE_DEFINED__
-#define __IMFVideoProcessor_INTERFACE_DEFINED__
-DEFINE_GUID(IID_IMFVideoProcessor, 0x6AB0000C, 0xFECE, 0x4d1f, 0xA2,0xAC, 0xA9,0x57,0x35,0x30,0x65,0x6E);
-MIDL_INTERFACE("6AB0000C-FECE-4d1f-A2AC-A9573530656E")
-IMFVideoProcessor : public IUnknown
-{
- virtual HRESULT STDMETHODCALLTYPE GetAvailableVideoProcessorModes(UINT *, GUID **) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetVideoProcessorCaps(LPGUID, DXVA2_VideoProcessorCaps *) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetVideoProcessorMode(LPGUID) = 0;
- virtual HRESULT STDMETHODCALLTYPE SetVideoProcessorMode(LPGUID) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetProcAmpRange(DWORD, DXVA2_ValueRange *) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetProcAmpValues(DWORD, DXVA2_ProcAmpValues *) = 0;
- virtual HRESULT STDMETHODCALLTYPE SetProcAmpValues(DWORD, DXVA2_ProcAmpValues *) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetFilteringRange(DWORD, DXVA2_ValueRange *) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetFilteringValue(DWORD, DXVA2_Fixed32 *) = 0;
- virtual HRESULT STDMETHODCALLTYPE SetFilteringValue(DWORD, DXVA2_Fixed32 *) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetBackgroundColor(COLORREF *) = 0;
- virtual HRESULT STDMETHODCALLTYPE SetBackgroundColor(COLORREF) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFVideoProcessor, 0x6AB0000C, 0xFECE, 0x4d1f, 0xA2,0xAC, 0xA9,0x57,0x35,0x30,0x65,0x6E)
-#endif
-#endif // __IMFVideoProcessor_INTERFACE_DEFINED__
-
-#ifndef __IMFVideoDeviceID_INTERFACE_DEFINED__
-#define __IMFVideoDeviceID_INTERFACE_DEFINED__
-DEFINE_GUID(IID_IMFVideoDeviceID, 0xA38D9567, 0x5A9C, 0x4f3c, 0xB2,0x93, 0x8E,0xB4,0x15,0xB2,0x79,0xBA);
-MIDL_INTERFACE("A38D9567-5A9C-4f3c-B293-8EB415B279BA")
-IMFVideoDeviceID : public IUnknown
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE GetDeviceID(IID *pDeviceID) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFVideoDeviceID, 0xA38D9567, 0x5A9C, 0x4f3c, 0xB2,0x93, 0x8E,0xB4,0x15,0xB2,0x79,0xBA)
-#endif
-#endif // __IMFVideoDeviceID_INTERFACE_DEFINED__
-
-#ifndef __IMFClockStateSink_INTERFACE_DEFINED__
-#define __IMFClockStateSink_INTERFACE_DEFINED__
-DEFINE_GUID(IID_IMFClockStateSink, 0xF6696E82, 0x74F7, 0x4f3d, 0xA1,0x78, 0x8A,0x5E,0x09,0xC3,0x65,0x9F);
-MIDL_INTERFACE("F6696E82-74F7-4f3d-A178-8A5E09C3659F")
-IMFClockStateSink : public IUnknown
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset) = 0;
- virtual HRESULT STDMETHODCALLTYPE OnClockStop(MFTIME hnsSystemTime) = 0;
- virtual HRESULT STDMETHODCALLTYPE OnClockPause(MFTIME hnsSystemTime) = 0;
- virtual HRESULT STDMETHODCALLTYPE OnClockRestart(MFTIME hnsSystemTime) = 0;
- virtual HRESULT STDMETHODCALLTYPE OnClockSetRate(MFTIME hnsSystemTime, float flRate) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFClockStateSink, 0xF6696E82, 0x74F7, 0x4f3d, 0xA1,0x78, 0x8A,0x5E,0x09,0xC3,0x65,0x9F)
-#endif
-#endif // __IMFClockStateSink_INTERFACE_DEFINED__
-
-#ifndef __IMFVideoPresenter_INTERFACE_DEFINED__
-#define __IMFVideoPresenter_INTERFACE_DEFINED__
-typedef enum MFVP_MESSAGE_TYPE
-{
- MFVP_MESSAGE_FLUSH = 0,
- MFVP_MESSAGE_INVALIDATEMEDIATYPE = 0x1,
- MFVP_MESSAGE_PROCESSINPUTNOTIFY = 0x2,
- MFVP_MESSAGE_BEGINSTREAMING = 0x3,
- MFVP_MESSAGE_ENDSTREAMING = 0x4,
- MFVP_MESSAGE_ENDOFSTREAM = 0x5,
- MFVP_MESSAGE_STEP = 0x6,
- MFVP_MESSAGE_CANCELSTEP = 0x7
-} MFVP_MESSAGE_TYPE;
-
-DEFINE_GUID(IID_IMFVideoPresenter, 0x29AFF080, 0x182A, 0x4a5d, 0xAF,0x3B, 0x44,0x8F,0x3A,0x63,0x46,0xCB);
-MIDL_INTERFACE("29AFF080-182A-4a5d-AF3B-448F3A6346CB")
-IMFVideoPresenter : public IMFClockStateSink
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE ProcessMessage(MFVP_MESSAGE_TYPE eMessage, ULONG_PTR ulParam) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetCurrentMediaType(IMFVideoMediaType **ppMediaType) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFVideoPresenter, 0x29AFF080, 0x182A, 0x4a5d, 0xAF,0x3B, 0x44,0x8F,0x3A,0x63,0x46,0xCB)
-#endif
-#endif // __IMFVideoPresenter_INTERFACE_DEFINED__
-
-#ifndef __IMFRateSupport_INTERFACE_DEFINED__
-#define __IMFRateSupport_INTERFACE_DEFINED__
-DEFINE_GUID(IID_IMFRateSupport, 0x0a9ccdbc, 0xd797, 0x4563, 0x96,0x67, 0x94,0xec,0x5d,0x79,0x29,0x2d);
-MIDL_INTERFACE("0a9ccdbc-d797-4563-9667-94ec5d79292d")
-IMFRateSupport : public IUnknown
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE GetSlowestRate(MFRATE_DIRECTION eDirection, BOOL fThin, float *pflRate) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetFastestRate(MFRATE_DIRECTION eDirection, BOOL fThin, float *pflRate) = 0;
- virtual HRESULT STDMETHODCALLTYPE IsRateSupported(BOOL fThin, float flRate, float *pflNearestSupportedRate) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFRateSupport, 0x0a9ccdbc, 0xd797, 0x4563, 0x96,0x67, 0x94,0xec,0x5d,0x79,0x29,0x2d)
-#endif
-#endif // __IMFRateSupport_INTERFACE_DEFINED__
-
-#ifndef __IMFTopologyServiceLookup_INTERFACE_DEFINED__
-#define __IMFTopologyServiceLookup_INTERFACE_DEFINED__
-typedef enum _MF_SERVICE_LOOKUP_TYPE
-{
- MF_SERVICE_LOOKUP_UPSTREAM = 0,
- MF_SERVICE_LOOKUP_UPSTREAM_DIRECT = (MF_SERVICE_LOOKUP_UPSTREAM + 1),
- MF_SERVICE_LOOKUP_DOWNSTREAM = (MF_SERVICE_LOOKUP_UPSTREAM_DIRECT + 1),
- MF_SERVICE_LOOKUP_DOWNSTREAM_DIRECT = (MF_SERVICE_LOOKUP_DOWNSTREAM + 1),
- MF_SERVICE_LOOKUP_ALL = (MF_SERVICE_LOOKUP_DOWNSTREAM_DIRECT + 1),
- MF_SERVICE_LOOKUP_GLOBAL = (MF_SERVICE_LOOKUP_ALL + 1)
-} MF_SERVICE_LOOKUP_TYPE;
-
-DEFINE_GUID(IID_IMFTopologyServiceLookup, 0xfa993889, 0x4383, 0x415a, 0xa9,0x30, 0xdd,0x47,0x2a,0x8c,0xf6,0xf7);
-MIDL_INTERFACE("fa993889-4383-415a-a930-dd472a8cf6f7")
-IMFTopologyServiceLookup : public IUnknown
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE LookupService(MF_SERVICE_LOOKUP_TYPE Type,
- DWORD dwIndex,
- REFGUID guidService,
- REFIID riid,
- LPVOID *ppvObjects,
- DWORD *pnObjects) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFTopologyServiceLookup, 0xfa993889, 0x4383, 0x415a, 0xa9,0x30, 0xdd,0x47,0x2a,0x8c,0xf6,0xf7)
-#endif
-#endif // __IMFTopologyServiceLookup_INTERFACE_DEFINED__
-
-#ifndef __IMFTopologyServiceLookupClient_INTERFACE_DEFINED__
-#define __IMFTopologyServiceLookupClient_INTERFACE_DEFINED__
-DEFINE_GUID(IID_IMFTopologyServiceLookupClient, 0xfa99388a, 0x4383, 0x415a, 0xa9,0x30, 0xdd,0x47,0x2a,0x8c,0xf6,0xf7);
-MIDL_INTERFACE("fa99388a-4383-415a-a930-dd472a8cf6f7")
-IMFTopologyServiceLookupClient : public IUnknown
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE InitServicePointers(IMFTopologyServiceLookup *pLookup) = 0;
- virtual HRESULT STDMETHODCALLTYPE ReleaseServicePointers(void) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFTopologyServiceLookupClient, 0xfa99388a, 0x4383, 0x415a, 0xa9,0x30, 0xdd,0x47,0x2a,0x8c,0xf6,0xf7)
-#endif
-#endif // __IMFTopologyServiceLookupClient_INTERFACE_DEFINED__
-
-#ifndef __IMediaEventSink_INTERFACE_DEFINED__
-#define __IMediaEventSink_INTERFACE_DEFINED__
-DEFINE_GUID(IID_IMediaEventSink, 0x56a868a2, 0x0ad4, 0x11ce, 0xb0,0x3a, 0x00,0x20,0xaf,0x0b,0xa7,0x70);
-MIDL_INTERFACE("56a868a2-0ad4-11ce-b03a-0020af0ba770")
-IMediaEventSink : public IUnknown
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE Notify(long EventCode, LONG_PTR EventParam1, LONG_PTR EventParam2) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMediaEventSink, 0x56a868a2, 0x0ad4, 0x11ce, 0xb0,0x3a, 0x00,0x20,0xaf,0x0b,0xa7,0x70)
-#endif
-#endif // __IMediaEventSink_INTERFACE_DEFINED__
-
-#ifndef __IMFVideoRenderer_INTERFACE_DEFINED__
-#define __IMFVideoRenderer_INTERFACE_DEFINED__
-DEFINE_GUID(IID_IMFVideoRenderer, 0xDFDFD197, 0xA9CA, 0x43d8, 0xB3,0x41, 0x6A,0xF3,0x50,0x37,0x92,0xCD);
-MIDL_INTERFACE("DFDFD197-A9CA-43d8-B341-6AF3503792CD")
-IMFVideoRenderer : public IUnknown
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE InitializeRenderer(IMFTransform *pVideoMixer,
- IMFVideoPresenter *pVideoPresenter) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFVideoRenderer, 0xDFDFD197, 0xA9CA, 0x43d8, 0xB3,0x41, 0x6A,0xF3,0x50,0x37,0x92,0xCD)
-#endif
-#endif // __IMFVideoRenderer_INTERFACE_DEFINED__
-
-#ifndef __IMFTrackedSample_INTERFACE_DEFINED__
-#define __IMFTrackedSample_INTERFACE_DEFINED__
-DEFINE_GUID(IID_IMFTrackedSample, 0x245BF8E9, 0x0755, 0x40f7, 0x88,0xA5, 0xAE,0x0F,0x18,0xD5,0x5E,0x17);
-MIDL_INTERFACE("245BF8E9-0755-40f7-88A5-AE0F18D55E17")
-IMFTrackedSample : public IUnknown
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE SetAllocator(IMFAsyncCallback *pSampleAllocator, IUnknown *pUnkState) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFTrackedSample, 0x245BF8E9, 0x0755, 0x40f7, 0x88,0xA5, 0xAE,0x0F,0x18,0xD5,0x5E,0x17)
-#endif
-#endif // __IMFTrackedSample_INTERFACE_DEFINED__
-
-#ifndef __IMFDesiredSample_INTERFACE_DEFINED__
-#define __IMFDesiredSample_INTERFACE_DEFINED__
-DEFINE_GUID(IID_IMFDesiredSample, 0x56C294D0, 0x753E, 0x4260, 0x8D,0x61, 0xA3,0xD8,0x82,0x0B,0x1D,0x54);
-MIDL_INTERFACE("56C294D0-753E-4260-8D61-A3D8820B1D54")
-IMFDesiredSample : public IUnknown
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE GetDesiredSampleTimeAndDuration(LONGLONG *phnsSampleTime,
- LONGLONG *phnsSampleDuration) = 0;
- virtual void STDMETHODCALLTYPE SetDesiredSampleTimeAndDuration(LONGLONG hnsSampleTime,
- LONGLONG hnsSampleDuration) = 0;
- virtual void STDMETHODCALLTYPE Clear( void) = 0;
-};
-#ifdef __CRT_UUID_DECL
-__CRT_UUID_DECL(IMFDesiredSample, 0x56C294D0, 0x753E, 0x4260, 0x8D,0x61, 0xA3,0xD8,0x82,0x0B,0x1D,0x54)
-#endif
-#endif
-
-#endif // EVRDEFS_H
-
diff --git a/src/plugins/common/evr/evrhelpers.cpp b/src/plugins/common/evr/evrhelpers.cpp
deleted file mode 100644
index a315f1a73..000000000
--- a/src/plugins/common/evr/evrhelpers.cpp
+++ /dev/null
@@ -1,186 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "evrhelpers.h"
-
-#ifndef D3DFMT_YV12
-#define D3DFMT_YV12 (D3DFORMAT)MAKEFOURCC ('Y', 'V', '1', '2')
-#endif
-#ifndef D3DFMT_NV12
-#define D3DFMT_NV12 (D3DFORMAT)MAKEFOURCC ('N', 'V', '1', '2')
-#endif
-
-QT_BEGIN_NAMESPACE
-
-HRESULT qt_evr_getFourCC(IMFMediaType *type, DWORD *fourCC)
-{
- if (!fourCC)
- return E_POINTER;
-
- HRESULT hr = S_OK;
- GUID guidSubType = GUID_NULL;
-
- if (SUCCEEDED(hr))
- hr = type->GetGUID(MF_MT_SUBTYPE, &guidSubType);
-
- if (SUCCEEDED(hr))
- *fourCC = guidSubType.Data1;
-
- return hr;
-}
-
-bool qt_evr_areMediaTypesEqual(IMFMediaType *type1, IMFMediaType *type2)
-{
- if (!type1 && !type2)
- return true;
- if (!type1 || !type2)
- return false;
-
- DWORD dwFlags = 0;
- HRESULT hr = type1->IsEqual(type2, &dwFlags);
-
- return (hr == S_OK);
-}
-
-HRESULT qt_evr_validateVideoArea(const MFVideoArea& area, UINT32 width, UINT32 height)
-{
- float fOffsetX = qt_evr_MFOffsetToFloat(area.OffsetX);
- float fOffsetY = qt_evr_MFOffsetToFloat(area.OffsetY);
-
- if ( ((LONG)fOffsetX + area.Area.cx > (LONG)width) ||
- ((LONG)fOffsetY + area.Area.cy > (LONG)height) ) {
- return MF_E_INVALIDMEDIATYPE;
- }
- return S_OK;
-}
-
-bool qt_evr_isSampleTimePassed(IMFClock *clock, IMFSample *sample)
-{
- if (!sample || !clock)
- return false;
-
- HRESULT hr = S_OK;
- MFTIME hnsTimeNow = 0;
- MFTIME hnsSystemTime = 0;
- MFTIME hnsSampleStart = 0;
- MFTIME hnsSampleDuration = 0;
-
- hr = clock->GetCorrelatedTime(0, &hnsTimeNow, &hnsSystemTime);
-
- if (SUCCEEDED(hr))
- hr = sample->GetSampleTime(&hnsSampleStart);
-
- if (SUCCEEDED(hr))
- hr = sample->GetSampleDuration(&hnsSampleDuration);
-
- if (SUCCEEDED(hr)) {
- if (hnsSampleStart + hnsSampleDuration < hnsTimeNow)
- return true;
- }
-
- return false;
-}
-
-QVideoFrame::PixelFormat qt_evr_pixelFormatFromD3DFormat(DWORD format)
-{
- switch (format) {
- case D3DFMT_R8G8B8:
- return QVideoFrame::Format_RGB24;
- case D3DFMT_A8R8G8B8:
- return QVideoFrame::Format_ARGB32;
- case D3DFMT_X8R8G8B8:
- return QVideoFrame::Format_RGB32;
- case D3DFMT_R5G6B5:
- return QVideoFrame::Format_RGB565;
- case D3DFMT_X1R5G5B5:
- return QVideoFrame::Format_RGB555;
- case D3DFMT_A8:
- return QVideoFrame::Format_Y8;
- case D3DFMT_A8B8G8R8:
- return QVideoFrame::Format_BGRA32;
- case D3DFMT_X8B8G8R8:
- return QVideoFrame::Format_BGR32;
- case D3DFMT_UYVY:
- return QVideoFrame::Format_UYVY;
- case D3DFMT_YUY2:
- return QVideoFrame::Format_YUYV;
- case D3DFMT_NV12:
- return QVideoFrame::Format_NV12;
- case D3DFMT_YV12:
- return QVideoFrame::Format_YV12;
- case D3DFMT_UNKNOWN:
- default:
- return QVideoFrame::Format_Invalid;
- }
-}
-
-D3DFORMAT qt_evr_D3DFormatFromPixelFormat(QVideoFrame::PixelFormat format)
-{
- switch (format) {
- case QVideoFrame::Format_RGB24:
- return D3DFMT_R8G8B8;
- case QVideoFrame::Format_ARGB32:
- return D3DFMT_A8R8G8B8;
- case QVideoFrame::Format_RGB32:
- return D3DFMT_X8R8G8B8;
- case QVideoFrame::Format_RGB565:
- return D3DFMT_R5G6B5;
- case QVideoFrame::Format_RGB555:
- return D3DFMT_X1R5G5B5;
- case QVideoFrame::Format_Y8:
- return D3DFMT_A8;
- case QVideoFrame::Format_BGRA32:
- return D3DFMT_A8B8G8R8;
- case QVideoFrame::Format_BGR32:
- return D3DFMT_X8B8G8R8;
- case QVideoFrame::Format_UYVY:
- return D3DFMT_UYVY;
- case QVideoFrame::Format_YUYV:
- return D3DFMT_YUY2;
- case QVideoFrame::Format_NV12:
- return D3DFMT_NV12;
- case QVideoFrame::Format_YV12:
- return D3DFMT_YV12;
- case QVideoFrame::Format_Invalid:
- default:
- return D3DFMT_UNKNOWN;
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/common/evr/evrhelpers.h b/src/plugins/common/evr/evrhelpers.h
deleted file mode 100644
index b5bdf5ead..000000000
--- a/src/plugins/common/evr/evrhelpers.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef EVRHELPERS_H
-#define EVRHELPERS_H
-
-#include "evrdefs.h"
-#include <qvideoframe.h>
-
-QT_BEGIN_NAMESPACE
-
-template<class T>
-static inline void qt_evr_safe_release(T **unk)
-{
- if (*unk) {
- (*unk)->Release();
- *unk = NULL;
- }
-}
-
-HRESULT qt_evr_getFourCC(IMFMediaType *type, DWORD *fourCC);
-
-bool qt_evr_areMediaTypesEqual(IMFMediaType *type1, IMFMediaType *type2);
-
-HRESULT qt_evr_validateVideoArea(const MFVideoArea& area, UINT32 width, UINT32 height);
-
-bool qt_evr_isSampleTimePassed(IMFClock *clock, IMFSample *sample);
-
-inline float qt_evr_MFOffsetToFloat(const MFOffset& offset)
-{
- return offset.value + (float(offset.fract) / 65536);
-}
-
-inline MFOffset qt_evr_makeMFOffset(float v)
-{
- MFOffset offset;
- offset.value = short(v);
- offset.fract = WORD(65536 * (v-offset.value));
- return offset;
-}
-
-inline MFVideoArea qt_evr_makeMFArea(float x, float y, DWORD width, DWORD height)
-{
- MFVideoArea area;
- area.OffsetX = qt_evr_makeMFOffset(x);
- area.OffsetY = qt_evr_makeMFOffset(y);
- area.Area.cx = width;
- area.Area.cy = height;
- return area;
-}
-
-inline HRESULT qt_evr_getFrameRate(IMFMediaType *pType, MFRatio *pRatio)
-{
- return MFGetAttributeRatio(pType, MF_MT_FRAME_RATE,
- reinterpret_cast<UINT32*>(&pRatio->Numerator),
- reinterpret_cast<UINT32*>(&pRatio->Denominator));
-}
-
-QVideoFrame::PixelFormat qt_evr_pixelFormatFromD3DFormat(DWORD format);
-D3DFORMAT qt_evr_D3DFormatFromPixelFormat(QVideoFrame::PixelFormat format);
-
-QT_END_NAMESPACE
-
-#endif // EVRHELPERS_H
-
diff --git a/src/plugins/common/evr/evrvideowindowcontrol.cpp b/src/plugins/common/evr/evrvideowindowcontrol.cpp
deleted file mode 100644
index 95f63c2e7..000000000
--- a/src/plugins/common/evr/evrvideowindowcontrol.cpp
+++ /dev/null
@@ -1,362 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "evrvideowindowcontrol.h"
-
-#ifndef QT_NO_WIDGETS
-#include <qwidget.h>
-#endif
-
-EvrVideoWindowControl::EvrVideoWindowControl(QObject *parent)
- : QVideoWindowControl(parent)
- , m_windowId(0)
- , m_windowColor(RGB(0, 0, 0))
- , m_dirtyValues(0)
- , m_aspectRatioMode(Qt::KeepAspectRatio)
- , m_brightness(0)
- , m_contrast(0)
- , m_hue(0)
- , m_saturation(0)
- , m_fullScreen(false)
- , m_displayControl(0)
- , m_processor(0)
-{
-}
-
-EvrVideoWindowControl::~EvrVideoWindowControl()
-{
- clear();
-}
-
-bool EvrVideoWindowControl::setEvr(IUnknown *evr)
-{
- clear();
-
- if (!evr)
- return true;
-
- IMFGetService *service = NULL;
-
- if (SUCCEEDED(evr->QueryInterface(IID_PPV_ARGS(&service)))
- && SUCCEEDED(service->GetService(mr_VIDEO_RENDER_SERVICE, IID_PPV_ARGS(&m_displayControl)))) {
-
- service->GetService(mr_VIDEO_MIXER_SERVICE, IID_PPV_ARGS(&m_processor));
-
- setWinId(m_windowId);
- setDisplayRect(m_displayRect);
- setAspectRatioMode(m_aspectRatioMode);
- m_dirtyValues = DXVA2_ProcAmp_Brightness | DXVA2_ProcAmp_Contrast | DXVA2_ProcAmp_Hue | DXVA2_ProcAmp_Saturation;
- applyImageControls();
- }
-
- if (service)
- service->Release();
-
- return m_displayControl != NULL;
-}
-
-void EvrVideoWindowControl::clear()
-{
- if (m_displayControl)
- m_displayControl->Release();
- m_displayControl = NULL;
-
- if (m_processor)
- m_processor->Release();
- m_processor = NULL;
-}
-
-WId EvrVideoWindowControl::winId() const
-{
- return m_windowId;
-}
-
-void EvrVideoWindowControl::setWinId(WId id)
-{
- m_windowId = id;
-
-#ifndef QT_NO_WIDGETS
- if (QWidget *widget = QWidget::find(m_windowId)) {
- const QColor color = widget->palette().color(QPalette::Window);
-
- m_windowColor = RGB(color.red(), color.green(), color.blue());
- }
-#endif
-
- if (m_displayControl)
- m_displayControl->SetVideoWindow(HWND(m_windowId));
-}
-
-QRect EvrVideoWindowControl::displayRect() const
-{
- return m_displayRect;
-}
-
-void EvrVideoWindowControl::setDisplayRect(const QRect &rect)
-{
- m_displayRect = rect;
-
- if (m_displayControl) {
- RECT displayRect = { rect.left(), rect.top(), rect.right() + 1, rect.bottom() + 1 };
- QSize sourceSize = nativeSize();
-
- RECT sourceRect = { 0, 0, sourceSize.width(), sourceSize.height() };
-
- if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
- QSize clippedSize = rect.size();
- clippedSize.scale(sourceRect.right, sourceRect.bottom, Qt::KeepAspectRatio);
-
- sourceRect.left = (sourceRect.right - clippedSize.width()) / 2;
- sourceRect.top = (sourceRect.bottom - clippedSize.height()) / 2;
- sourceRect.right = sourceRect.left + clippedSize.width();
- sourceRect.bottom = sourceRect.top + clippedSize.height();
- }
-
- if (sourceSize.width() > 0 && sourceSize.height() > 0) {
- MFVideoNormalizedRect sourceNormRect;
- sourceNormRect.left = float(sourceRect.left) / float(sourceRect.right);
- sourceNormRect.top = float(sourceRect.top) / float(sourceRect.bottom);
- sourceNormRect.right = float(sourceRect.right) / float(sourceRect.right);
- sourceNormRect.bottom = float(sourceRect.bottom) / float(sourceRect.bottom);
- m_displayControl->SetVideoPosition(&sourceNormRect, &displayRect);
- } else {
- m_displayControl->SetVideoPosition(NULL, &displayRect);
- }
-
- // To refresh content immediately.
- repaint();
- }
-}
-
-bool EvrVideoWindowControl::isFullScreen() const
-{
- return m_fullScreen;
-}
-
-void EvrVideoWindowControl::setFullScreen(bool fullScreen)
-{
- if (m_fullScreen == fullScreen)
- return;
- emit fullScreenChanged(m_fullScreen = fullScreen);
-}
-
-void EvrVideoWindowControl::repaint()
-{
- QSize size = nativeSize();
- if (size.width() > 0 && size.height() > 0
- && m_displayControl
- && SUCCEEDED(m_displayControl->RepaintVideo())) {
- return;
- }
-
- PAINTSTRUCT paint;
- if (HDC dc = ::BeginPaint(HWND(m_windowId), &paint)) {
- HPEN pen = ::CreatePen(PS_SOLID, 1, m_windowColor);
- HBRUSH brush = ::CreateSolidBrush(m_windowColor);
- ::SelectObject(dc, pen);
- ::SelectObject(dc, brush);
-
- ::Rectangle(
- dc,
- m_displayRect.left(),
- m_displayRect.top(),
- m_displayRect.right() + 1,
- m_displayRect.bottom() + 1);
-
- ::DeleteObject(pen);
- ::DeleteObject(brush);
- ::EndPaint(HWND(m_windowId), &paint);
- }
-}
-
-QSize EvrVideoWindowControl::nativeSize() const
-{
- QSize size;
- if (m_displayControl) {
- SIZE sourceSize;
- if (SUCCEEDED(m_displayControl->GetNativeVideoSize(&sourceSize, 0)))
- size = QSize(sourceSize.cx, sourceSize.cy);
- }
- return size;
-}
-
-Qt::AspectRatioMode EvrVideoWindowControl::aspectRatioMode() const
-{
- return m_aspectRatioMode;
-}
-
-void EvrVideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- m_aspectRatioMode = mode;
-
- if (m_displayControl) {
- switch (mode) {
- case Qt::IgnoreAspectRatio:
- //comment from MSDN: Do not maintain the aspect ratio of the video. Stretch the video to fit the output rectangle.
- m_displayControl->SetAspectRatioMode(MFVideoARMode_None);
- break;
- case Qt::KeepAspectRatio:
- //comment from MSDN: Preserve the aspect ratio of the video by letterboxing or within the output rectangle.
- m_displayControl->SetAspectRatioMode(MFVideoARMode_PreservePicture);
- break;
- case Qt::KeepAspectRatioByExpanding:
- //for this mode, more adjustment will be done in setDisplayRect
- m_displayControl->SetAspectRatioMode(MFVideoARMode_PreservePicture);
- break;
- default:
- break;
- }
- setDisplayRect(m_displayRect);
- }
-}
-
-int EvrVideoWindowControl::brightness() const
-{
- return m_brightness;
-}
-
-void EvrVideoWindowControl::setBrightness(int brightness)
-{
- if (m_brightness == brightness)
- return;
-
- m_brightness = brightness;
-
- m_dirtyValues |= DXVA2_ProcAmp_Brightness;
-
- applyImageControls();
-
- emit brightnessChanged(brightness);
-}
-
-int EvrVideoWindowControl::contrast() const
-{
- return m_contrast;
-}
-
-void EvrVideoWindowControl::setContrast(int contrast)
-{
- if (m_contrast == contrast)
- return;
-
- m_contrast = contrast;
-
- m_dirtyValues |= DXVA2_ProcAmp_Contrast;
-
- applyImageControls();
-
- emit contrastChanged(contrast);
-}
-
-int EvrVideoWindowControl::hue() const
-{
- return m_hue;
-}
-
-void EvrVideoWindowControl::setHue(int hue)
-{
- if (m_hue == hue)
- return;
-
- m_hue = hue;
-
- m_dirtyValues |= DXVA2_ProcAmp_Hue;
-
- applyImageControls();
-
- emit hueChanged(hue);
-}
-
-int EvrVideoWindowControl::saturation() const
-{
- return m_saturation;
-}
-
-void EvrVideoWindowControl::setSaturation(int saturation)
-{
- if (m_saturation == saturation)
- return;
-
- m_saturation = saturation;
-
- m_dirtyValues |= DXVA2_ProcAmp_Saturation;
-
- applyImageControls();
-
- emit saturationChanged(saturation);
-}
-
-void EvrVideoWindowControl::applyImageControls()
-{
- if (m_processor) {
- DXVA2_ProcAmpValues values;
- if (m_dirtyValues & DXVA2_ProcAmp_Brightness) {
- values.Brightness = scaleProcAmpValue(DXVA2_ProcAmp_Brightness, m_brightness);
- }
- if (m_dirtyValues & DXVA2_ProcAmp_Contrast) {
- values.Contrast = scaleProcAmpValue(DXVA2_ProcAmp_Contrast, m_contrast);
- }
- if (m_dirtyValues & DXVA2_ProcAmp_Hue) {
- values.Hue = scaleProcAmpValue(DXVA2_ProcAmp_Hue, m_hue);
- }
- if (m_dirtyValues & DXVA2_ProcAmp_Saturation) {
- values.Saturation = scaleProcAmpValue(DXVA2_ProcAmp_Saturation, m_saturation);
- }
-
- if (SUCCEEDED(m_processor->SetProcAmpValues(m_dirtyValues, &values))) {
- m_dirtyValues = 0;
- }
- }
-}
-
-DXVA2_Fixed32 EvrVideoWindowControl::scaleProcAmpValue(DWORD prop, int value) const
-{
- float scaledValue = 0.0;
-
- DXVA2_ValueRange range;
- if (SUCCEEDED(m_processor->GetProcAmpRange(prop, &range))) {
- scaledValue = DXVA2FixedToFloat(range.DefaultValue);
- if (value > 0)
- scaledValue += float(value) * (DXVA2FixedToFloat(range.MaxValue) - DXVA2FixedToFloat(range.DefaultValue)) / 100;
- else if (value < 0)
- scaledValue -= float(value) * (DXVA2FixedToFloat(range.MinValue) - DXVA2FixedToFloat(range.DefaultValue)) / 100;
- }
-
- return DXVA2FloatToFixed(scaledValue);
-}
diff --git a/src/plugins/common/evr/evrvideowindowcontrol.h b/src/plugins/common/evr/evrvideowindowcontrol.h
deleted file mode 100644
index ce3b7746f..000000000
--- a/src/plugins/common/evr/evrvideowindowcontrol.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef EVRVIDEOWINDOWCONTROL_H
-#define EVRVIDEOWINDOWCONTROL_H
-
-#include "qvideowindowcontrol.h"
-
-#include "evrdefs.h"
-
-QT_BEGIN_NAMESPACE
-
-class EvrVideoWindowControl : public QVideoWindowControl
-{
- Q_OBJECT
-public:
- EvrVideoWindowControl(QObject *parent = 0);
- ~EvrVideoWindowControl() override;
-
- bool setEvr(IUnknown *evr);
-
- WId winId() const override;
- void setWinId(WId id) override;
-
- QRect displayRect() const override;
- void setDisplayRect(const QRect &rect) override;
-
- bool isFullScreen() const override;
- void setFullScreen(bool fullScreen) override;
-
- void repaint() override;
-
- QSize nativeSize() const override;
-
- Qt::AspectRatioMode aspectRatioMode() const override;
- void setAspectRatioMode(Qt::AspectRatioMode mode) override;
-
- int brightness() const override;
- void setBrightness(int brightness) override;
-
- int contrast() const override;
- void setContrast(int contrast) override;
-
- int hue() const override;
- void setHue(int hue) override;
-
- int saturation() const override;
- void setSaturation(int saturation) override;
-
- void applyImageControls();
-
-private:
- void clear();
- DXVA2_Fixed32 scaleProcAmpValue(DWORD prop, int value) const;
-
- WId m_windowId;
- COLORREF m_windowColor;
- DWORD m_dirtyValues;
- Qt::AspectRatioMode m_aspectRatioMode;
- QRect m_displayRect;
- int m_brightness;
- int m_contrast;
- int m_hue;
- int m_saturation;
- bool m_fullScreen;
-
- IMFVideoDisplayControl *m_displayControl;
- IMFVideoProcessor *m_processor;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/coreaudio/coreaudio.json b/src/plugins/coreaudio/coreaudio.json
deleted file mode 100644
index a31d52107..000000000
--- a/src/plugins/coreaudio/coreaudio.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": ["default"]
-}
diff --git a/src/plugins/coreaudio/coreaudio.pro b/src/plugins/coreaudio/coreaudio.pro
deleted file mode 100644
index 50159311a..000000000
--- a/src/plugins/coreaudio/coreaudio.pro
+++ /dev/null
@@ -1,39 +0,0 @@
-TARGET = qtaudio_coreaudio
-QT += multimedia-private
-
-OTHER_FILES += \
- coreaudio.json
-
-#DEFINES += QT_DEBUG_COREAUDIO
-
-HEADERS += \
- coreaudiodeviceinfo.h \
- coreaudioinput.h \
- coreaudiooutput.h \
- coreaudioplugin.h \
- coreaudioutils.h
-
-OBJECTIVE_SOURCES += \
- coreaudiodeviceinfo.mm \
- coreaudioinput.mm \
- coreaudiooutput.mm \
- coreaudioplugin.mm \
- coreaudioutils.mm
-
-ios|tvos {
- HEADERS += coreaudiosessionmanager.h
- OBJECTIVE_SOURCES += coreaudiosessionmanager.mm
- LIBS += -framework Foundation -framework AVFoundation
-} else {
- LIBS += \
- -framework ApplicationServices \
- -framework AudioUnit
-}
-
-LIBS += \
- -framework CoreAudio \
- -framework AudioToolbox
-
-PLUGIN_TYPE = audio
-PLUGIN_CLASS_NAME = CoreAudioPlugin
-load(qt_plugin)
diff --git a/src/plugins/coreaudio/coreaudiodeviceinfo.h b/src/plugins/coreaudio/coreaudiodeviceinfo.h
deleted file mode 100644
index 08c3961e6..000000000
--- a/src/plugins/coreaudio/coreaudiodeviceinfo.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef IOSAUDIODEVICEINFO_H
-#define IOSAUDIODEVICEINFO_H
-
-#include <qaudiosystem.h>
-
-#if defined(Q_OS_OSX)
-# include <CoreAudio/CoreAudio.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class CoreAudioDeviceInfo : public QAbstractAudioDeviceInfo
-{
- Q_OBJECT
-
-public:
- CoreAudioDeviceInfo(const QByteArray &device, QAudio::Mode mode);
- ~CoreAudioDeviceInfo() {}
-
- QAudioFormat preferredFormat() const;
- bool isFormatSupported(const QAudioFormat &format) const;
- QString deviceName() const;
- QStringList supportedCodecs();
- QList<int> supportedSampleRates();
- QList<int> supportedChannelCounts();
- QList<int> supportedSampleSizes();
- QList<QAudioFormat::Endian> supportedByteOrders();
- QList<QAudioFormat::SampleType> supportedSampleTypes();
-
- static QByteArray defaultDevice(QAudio::Mode mode);
- static QList<QByteArray> availableDevices(QAudio::Mode mode);
-
-private:
-#if defined(Q_OS_OSX)
- AudioDeviceID m_deviceId;
-#endif
-
- QString m_device;
- QAudio::Mode m_mode;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/coreaudio/coreaudiodeviceinfo.mm b/src/plugins/coreaudio/coreaudiodeviceinfo.mm
deleted file mode 100644
index 94ed6dc24..000000000
--- a/src/plugins/coreaudio/coreaudiodeviceinfo.mm
+++ /dev/null
@@ -1,346 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "coreaudiodeviceinfo.h"
-#include "coreaudioutils.h"
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
-# include "coreaudiosessionmanager.h"
-#endif
-
-#include <QtCore/QDataStream>
-#include <QtCore/QDebug>
-#include <QtCore/QSet>
-#include <QIODevice>
-
-QT_BEGIN_NAMESPACE
-
-CoreAudioDeviceInfo::CoreAudioDeviceInfo(const QByteArray &device, QAudio::Mode mode)
- : m_mode(mode)
-{
-#if defined(Q_OS_OSX)
- quint32 deviceID;
-
- QDataStream dataStream(device);
- dataStream >> deviceID >> m_device;
- m_deviceId = AudioDeviceID(deviceID);
-#else //iOS
- m_device = device;
-#endif
-}
-
-
-QAudioFormat CoreAudioDeviceInfo::preferredFormat() const
-{
- QAudioFormat format;
-
-#if defined(Q_OS_OSX)
- UInt32 propSize = 0;
- AudioObjectPropertyScope audioDevicePropertyScope = m_mode == QAudio::AudioInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
- AudioObjectPropertyAddress audioDevicePropertyStreamsAddress = { kAudioDevicePropertyStreams,
- audioDevicePropertyScope,
- kAudioObjectPropertyElementMaster };
-
- if (AudioObjectGetPropertyDataSize(m_deviceId, &audioDevicePropertyStreamsAddress, 0, NULL, &propSize) == noErr) {
-
- const int sc = propSize / sizeof(AudioStreamID);
-
- if (sc > 0) {
- AudioStreamID* streams = new AudioStreamID[sc];
-
- if (AudioObjectGetPropertyData(m_deviceId, &audioDevicePropertyStreamsAddress, 0, NULL, &propSize, streams) == noErr) {
-
- AudioObjectPropertyAddress audioDevicePhysicalFormatPropertyAddress = { kAudioStreamPropertyPhysicalFormat,
- kAudioObjectPropertyScopeGlobal,
- kAudioObjectPropertyElementMaster };
-
- for (int i = 0; i < sc; ++i) {
- if (AudioObjectGetPropertyDataSize(streams[i], &audioDevicePhysicalFormatPropertyAddress, 0, NULL, &propSize) == noErr) {
- AudioStreamBasicDescription sf;
-
- if (AudioObjectGetPropertyData(streams[i], &audioDevicePhysicalFormatPropertyAddress, 0, NULL, &propSize, &sf) == noErr) {
- format = CoreAudioUtils::toQAudioFormat(sf);
- break;
- } else {
- qWarning() << "QAudioDeviceInfo: Unable to find perferedFormat for stream";
- }
- } else {
- qWarning() << "QAudioDeviceInfo: Unable to find size of perferedFormat for stream";
- }
- }
- }
-
- delete[] streams;
- }
- }
-#else //iOS
- format.setSampleSize(16);
- if (m_mode == QAudio::AudioInput) {
- format.setChannelCount(1);
- format.setSampleRate(8000);
- } else {
- format.setChannelCount(2);
- format.setSampleRate(44100);
- }
- format.setCodec(QString::fromLatin1("audio/pcm"));
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::SignedInt);
-#endif
-
- return format;
-}
-
-
-bool CoreAudioDeviceInfo::isFormatSupported(const QAudioFormat &format) const
-{
- CoreAudioDeviceInfo *self = const_cast<CoreAudioDeviceInfo*>(this);
-
- //Sample rates are more of a suggestion with CoreAudio so as long as we get a
- //sane value then we can likely use it.
- return format.isValid()
- && format.codec() == QString::fromLatin1("audio/pcm")
- && format.sampleRate() > 0
- && self->supportedChannelCounts().contains(format.channelCount())
- && self->supportedSampleSizes().contains(format.sampleSize());
-}
-
-
-QString CoreAudioDeviceInfo::deviceName() const
-{
- return m_device;
-}
-
-
-QStringList CoreAudioDeviceInfo::supportedCodecs()
-{
- return QStringList() << QString::fromLatin1("audio/pcm");
-}
-
-
-QList<int> CoreAudioDeviceInfo::supportedSampleRates()
-{
- QSet<int> sampleRates;
-
-#if defined(Q_OS_OSX)
- UInt32 propSize = 0;
- AudioObjectPropertyScope scope = m_mode == QAudio::AudioInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
- AudioObjectPropertyAddress availableNominalSampleRatesAddress = { kAudioDevicePropertyAvailableNominalSampleRates,
- scope,
- kAudioObjectPropertyElementMaster };
-
- if (AudioObjectGetPropertyDataSize(m_deviceId, &availableNominalSampleRatesAddress, 0, NULL, &propSize) == noErr) {
- const int pc = propSize / sizeof(AudioValueRange);
-
- if (pc > 0) {
- AudioValueRange* vr = new AudioValueRange[pc];
-
- if (AudioObjectGetPropertyData(m_deviceId, &availableNominalSampleRatesAddress, 0, NULL, &propSize, vr) == noErr) {
- for (int i = 0; i < pc; ++i) {
- sampleRates << vr[i].mMinimum << vr[i].mMaximum;
- }
- }
-
- delete[] vr;
- }
- }
-#else //iOS
- //iOS doesn't have a way to query available sample rates
- //instead we provide reasonable targets
- //It may be necessary have CoreAudioSessionManger test combinations
- //with available hardware
- sampleRates << 8000 << 11025 << 22050 << 44100 << 48000;
-#endif
- return sampleRates.values();
-}
-
-
-QList<int> CoreAudioDeviceInfo::supportedChannelCounts()
-{
- static QList<int> supportedChannels;
-
- if (supportedChannels.isEmpty()) {
- // If the number of channels is not supported by an audio device, Core Audio will
- // automatically convert the audio data.
- for (int i = 1; i <= 16; ++i)
- supportedChannels.append(i);
- }
-
- return supportedChannels;
-}
-
-
-QList<int> CoreAudioDeviceInfo::supportedSampleSizes()
-{
- return QList<int>() << 8 << 16 << 24 << 32 << 64;
-}
-
-
-QList<QAudioFormat::Endian> CoreAudioDeviceInfo::supportedByteOrders()
-{
- return QList<QAudioFormat::Endian>() << QAudioFormat::LittleEndian << QAudioFormat::BigEndian;
-}
-
-
-QList<QAudioFormat::SampleType> CoreAudioDeviceInfo::supportedSampleTypes()
-{
- return QList<QAudioFormat::SampleType>() << QAudioFormat::SignedInt << QAudioFormat::UnSignedInt << QAudioFormat::Float;
-}
-
-#if defined(Q_OS_OSX)
-// XXX: remove at some future date
-static inline QString cfStringToQString(CFStringRef str)
-{
- CFIndex length = CFStringGetLength(str);
- const UniChar *chars = CFStringGetCharactersPtr(str);
- if (chars)
- return QString(reinterpret_cast<const QChar *>(chars), length);
-
- UniChar buffer[length];
- CFStringGetCharacters(str, CFRangeMake(0, length), buffer);
- return QString(reinterpret_cast<const QChar *>(buffer), length);
-}
-
-static QByteArray get_device_info(AudioDeviceID audioDevice, QAudio::Mode mode)
-{
- UInt32 size;
- QByteArray device;
- QDataStream ds(&device, QIODevice::WriteOnly);
- AudioStreamBasicDescription sf;
- CFStringRef name;
- Boolean isInput = mode == QAudio::AudioInput;
- AudioObjectPropertyScope audioPropertyScope = isInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
-
- // Id
- ds << quint32(audioDevice);
-
- // Mode //TODO: Why don't we use the Stream Format we ask for?
- size = sizeof(AudioStreamBasicDescription);
- AudioObjectPropertyAddress audioDeviceStreamFormatPropertyAddress = { kAudioDevicePropertyStreamFormat,
- audioPropertyScope,
- kAudioObjectPropertyElementMaster };
-
- if (AudioObjectGetPropertyData(audioDevice, &audioDeviceStreamFormatPropertyAddress, 0, NULL, &size, &sf) != noErr) {
- return QByteArray();
- }
-
- // Name
- size = sizeof(CFStringRef);
- AudioObjectPropertyAddress audioDeviceNamePropertyAddress = { kAudioObjectPropertyName,
- audioPropertyScope,
- kAudioObjectPropertyElementMaster };
-
- if (AudioObjectGetPropertyData(audioDevice, &audioDeviceNamePropertyAddress, 0, NULL, &size, &name) != noErr) {
- qWarning() << "QAudioDeviceInfo: Unable to find device name";
- return QByteArray();
- }
- ds << cfStringToQString(name);
-
- CFRelease(name);
-
- return device;
-}
-#endif
-
-QByteArray CoreAudioDeviceInfo::defaultDevice(QAudio::Mode mode)
-{
-#if defined(Q_OS_OSX)
- AudioDeviceID audioDevice;
- UInt32 size = sizeof(audioDevice);
- const AudioObjectPropertySelector selector = (mode == QAudio::AudioOutput) ? kAudioHardwarePropertyDefaultOutputDevice
- : kAudioHardwarePropertyDefaultInputDevice;
- AudioObjectPropertyAddress defaultDevicePropertyAddress = { selector,
- kAudioObjectPropertyScopeGlobal,
- kAudioObjectPropertyElementMaster };
-
- if (AudioObjectGetPropertyData(kAudioObjectSystemObject,
- &defaultDevicePropertyAddress,
- 0, NULL, &size, &audioDevice) != noErr) {
- qWarning("QAudioDeviceInfo: Unable to find default %s device", (mode == QAudio::AudioOutput) ? "output" : "input");
- return QByteArray();
- }
-
- return get_device_info(audioDevice, mode);
-#else //iOS
- const auto &devices = (mode == QAudio::AudioOutput) ? CoreAudioSessionManager::instance().outputDevices()
- : CoreAudioSessionManager::instance().inputDevices();
- return !devices.isEmpty() ? devices.first() : QByteArray();
-#endif
-}
-
-QList<QByteArray> CoreAudioDeviceInfo::availableDevices(QAudio::Mode mode)
-{
- QList<QByteArray> devices;
-#if defined(Q_OS_OSX)
- UInt32 propSize = 0;
- AudioObjectPropertyAddress audioDevicesPropertyAddress = { kAudioHardwarePropertyDevices,
- kAudioObjectPropertyScopeGlobal,
- kAudioObjectPropertyElementMaster };
-
- if (AudioObjectGetPropertyDataSize(kAudioObjectSystemObject,
- &audioDevicesPropertyAddress,
- 0, NULL, &propSize) == noErr) {
-
- const int dc = propSize / sizeof(AudioDeviceID);
-
- if (dc > 0) {
- AudioDeviceID* audioDevices = new AudioDeviceID[dc];
-
- if (AudioObjectGetPropertyData(kAudioObjectSystemObject, &audioDevicesPropertyAddress, 0, NULL, &propSize, audioDevices) == noErr) {
- for (int i = 0; i < dc; ++i) {
- const QByteArray &info = get_device_info(audioDevices[i], mode);
- if (!info.isNull())
- devices << info;
- }
- }
-
- delete[] audioDevices;
- }
- }
-#else //iOS
- if (mode == QAudio::AudioOutput)
- return CoreAudioSessionManager::instance().outputDevices();
- if (mode == QAudio::AudioInput)
- return CoreAudioSessionManager::instance().inputDevices();
-#endif
-
- return devices;
-}
-
-QT_END_NAMESPACE
-
-#include "moc_coreaudiodeviceinfo.cpp"
diff --git a/src/plugins/coreaudio/coreaudioinput.h b/src/plugins/coreaudio/coreaudioinput.h
deleted file mode 100644
index 40455b3db..000000000
--- a/src/plugins/coreaudio/coreaudioinput.h
+++ /dev/null
@@ -1,266 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef IOSAUDIOINPUT_H
-#define IOSAUDIOINPUT_H
-
-#include <qaudiosystem.h>
-#include <AudioUnit/AudioUnit.h>
-#include <CoreAudio/CoreAudioTypes.h>
-#include <AudioToolbox/AudioToolbox.h>
-
-#include <QtCore/QIODevice>
-#include <QtCore/QWaitCondition>
-#include <QtCore/QMutex>
-#include <QtCore/QTimer>
-
-QT_BEGIN_NAMESPACE
-
-class CoreAudioRingBuffer;
-class CoreAudioPacketFeeder;
-class CoreAudioInputBuffer;
-class CoreAudioInputDevice;
-
-class CoreAudioBufferList
-{
-public:
- CoreAudioBufferList(AudioStreamBasicDescription const& streamFormat);
- CoreAudioBufferList(AudioStreamBasicDescription const& streamFormat, char *buffer, int bufferSize);
- CoreAudioBufferList(AudioStreamBasicDescription const& streamFormat, int framesToBuffer);
-
- ~CoreAudioBufferList();
-
- AudioBufferList* audioBufferList() const { return m_bufferList; }
- char *data(int buffer = 0) const;
- qint64 bufferSize(int buffer = 0) const;
- int frameCount(int buffer = 0) const;
- int packetCount(int buffer = 0) const;
- int packetSize() const;
- void reset();
-
-private:
- bool m_owner;
- int m_dataSize;
- AudioStreamBasicDescription m_streamDescription;
- AudioBufferList *m_bufferList;
-};
-
-class CoreAudioPacketFeeder
-{
-public:
- CoreAudioPacketFeeder(CoreAudioBufferList *abl);
-
- bool feed(AudioBufferList& dst, UInt32& packetCount);
- bool empty() const;
-
-private:
- UInt32 m_totalPackets;
- UInt32 m_position;
- CoreAudioBufferList *m_audioBufferList;
-};
-
-class CoreAudioInputBuffer : public QObject
-{
- Q_OBJECT
-
-public:
- CoreAudioInputBuffer(int bufferSize,
- int maxPeriodSize,
- AudioStreamBasicDescription const& inputFormat,
- AudioStreamBasicDescription const& outputFormat,
- QObject *parent);
-
- ~CoreAudioInputBuffer();
-
- qreal volume() const;
- void setVolume(qreal v);
-
- qint64 renderFromDevice(AudioUnit audioUnit,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber,
- UInt32 inNumberFrames);
-
- qint64 readBytes(char *data, qint64 len);
-
- void setFlushDevice(QIODevice *device);
-
- void startFlushTimer();
- void stopFlushTimer();
-
- void flush(bool all = false);
- void reset();
- int available() const;
- int used() const;
-
-signals:
- void readyRead();
-
-private slots:
- void flushBuffer();
-
-private:
- bool m_deviceError;
- int m_maxPeriodSize;
- int m_periodTime;
- QIODevice *m_device;
- QTimer *m_flushTimer;
- CoreAudioRingBuffer *m_buffer;
- CoreAudioBufferList *m_inputBufferList;
- AudioConverterRef m_audioConverter;
- AudioStreamBasicDescription m_inputFormat;
- AudioStreamBasicDescription m_outputFormat;
- QAudioFormat m_qFormat;
- qreal m_volume;
-
- const static OSStatus as_empty = 'qtem';
-
- // Converter callback
- static OSStatus converterCallback(AudioConverterRef inAudioConverter,
- UInt32 *ioNumberDataPackets,
- AudioBufferList *ioData,
- AudioStreamPacketDescription **outDataPacketDescription,
- void *inUserData);
-};
-
-class CoreAudioInputDevice : public QIODevice
-{
- Q_OBJECT
-
-public:
- CoreAudioInputDevice(CoreAudioInputBuffer *audioBuffer, QObject *parent);
-
- qint64 readData(char *data, qint64 len);
- qint64 writeData(const char *data, qint64 len);
-
- bool isSequential() const { return true; }
-
-private:
- CoreAudioInputBuffer *m_audioBuffer;
-};
-
-class CoreAudioInput : public QAbstractAudioInput
-{
- Q_OBJECT
-
-public:
- CoreAudioInput(const QByteArray &device);
- ~CoreAudioInput();
-
- void start(QIODevice *device);
- QIODevice *start();
- void stop();
- void reset();
- void suspend();
- void resume();
- int bytesReady() const;
- int periodSize() const;
- void setBufferSize(int value);
- int bufferSize() const;
- void setNotifyInterval(int milliSeconds);
- int notifyInterval() const;
- qint64 processedUSecs() const;
- qint64 elapsedUSecs() const;
- QAudio::Error error() const;
- QAudio::State state() const;
- void setFormat(const QAudioFormat &format);
- QAudioFormat format() const;
-
- void setVolume(qreal volume);
- qreal volume() const;
-
-private slots:
- void deviceStoppped();
-
-private:
- enum {
- Running,
- Stopped
- };
-
- bool open();
- void close();
-
- void audioThreadStart();
- void audioThreadStop();
-
- void audioDeviceStop();
- void audioDeviceActive();
- void audioDeviceFull();
- void audioDeviceError();
-
- void startTimers();
- void stopTimers();
-
- // Input callback
- static OSStatus inputCallback(void *inRefCon,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber,
- UInt32 inNumberFrames,
- AudioBufferList *ioData);
-
- QByteArray m_device;
- bool m_isOpen;
- int m_periodSizeBytes;
- int m_internalBufferSize;
- qint64 m_totalFrames;
- QAudioFormat m_audioFormat;
- QIODevice *m_audioIO;
- AudioUnit m_audioUnit;
-#if defined(Q_OS_OSX)
- AudioDeviceID m_audioDeviceId;
-#endif
- Float64 m_clockFrequency;
- UInt64 m_startTime;
- QAudio::Error m_errorCode;
- QAudio::State m_stateCode;
- CoreAudioInputBuffer *m_audioBuffer;
- QMutex m_mutex;
- QWaitCondition m_threadFinished;
- QAtomicInt m_audioThreadState;
- QTimer *m_intervalTimer;
- AudioStreamBasicDescription m_streamFormat;
- AudioStreamBasicDescription m_deviceFormat;
- QAbstractAudioDeviceInfo *m_audioDeviceInfo;
- qreal m_volume;
-};
-
-QT_END_NAMESPACE
-
-#endif // IOSAUDIOINPUT_H
diff --git a/src/plugins/coreaudio/coreaudioinput.mm b/src/plugins/coreaudio/coreaudioinput.mm
deleted file mode 100644
index 9f6a1f7bc..000000000
--- a/src/plugins/coreaudio/coreaudioinput.mm
+++ /dev/null
@@ -1,1005 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "coreaudioinput.h"
-#include "coreaudiosessionmanager.h"
-#include "coreaudiodeviceinfo.h"
-#include "coreaudioutils.h"
-
-#if defined(Q_OS_OSX)
-# include <AudioUnit/AudioComponent.h>
-#endif
-
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
-# include "coreaudiosessionmanager.h"
-#endif
-
-#include <QtMultimedia/private/qaudiohelpers_p.h>
-#include <QtCore/QDataStream>
-#include <QtCore/QDebug>
-
-QT_BEGIN_NAMESPACE
-
-static const int DEFAULT_BUFFER_SIZE = 4 * 1024;
-
-CoreAudioBufferList::CoreAudioBufferList(const AudioStreamBasicDescription &streamFormat)
- : m_owner(false)
- , m_streamDescription(streamFormat)
-{
- const bool isInterleaved = (m_streamDescription.mFormatFlags & kAudioFormatFlagIsNonInterleaved) == 0;
- const int numberOfBuffers = isInterleaved ? 1 : m_streamDescription.mChannelsPerFrame;
-
- m_dataSize = 0;
-
- m_bufferList = reinterpret_cast<AudioBufferList*>(malloc(sizeof(AudioBufferList) +
- (sizeof(AudioBuffer) * numberOfBuffers)));
-
- m_bufferList->mNumberBuffers = numberOfBuffers;
- for (int i = 0; i < numberOfBuffers; ++i) {
- m_bufferList->mBuffers[i].mNumberChannels = isInterleaved ? numberOfBuffers : 1;
- m_bufferList->mBuffers[i].mDataByteSize = 0;
- m_bufferList->mBuffers[i].mData = 0;
- }
-}
-
-CoreAudioBufferList::CoreAudioBufferList(const AudioStreamBasicDescription &streamFormat, char *buffer, int bufferSize)
- : m_owner(false)
- , m_streamDescription(streamFormat)
- , m_bufferList(0)
-{
- m_dataSize = bufferSize;
-
- m_bufferList = reinterpret_cast<AudioBufferList*>(malloc(sizeof(AudioBufferList) + sizeof(AudioBuffer)));
-
- m_bufferList->mNumberBuffers = 1;
- m_bufferList->mBuffers[0].mNumberChannels = 1;
- m_bufferList->mBuffers[0].mDataByteSize = m_dataSize;
- m_bufferList->mBuffers[0].mData = buffer;
-}
-
-CoreAudioBufferList::CoreAudioBufferList(const AudioStreamBasicDescription &streamFormat, int framesToBuffer)
- : m_owner(true)
- , m_streamDescription(streamFormat)
- , m_bufferList(0)
-{
- const bool isInterleaved = (m_streamDescription.mFormatFlags & kAudioFormatFlagIsNonInterleaved) == 0;
- const int numberOfBuffers = isInterleaved ? 1 : m_streamDescription.mChannelsPerFrame;
-
- m_dataSize = framesToBuffer * m_streamDescription.mBytesPerFrame;
-
- m_bufferList = reinterpret_cast<AudioBufferList*>(malloc(sizeof(AudioBufferList) +
- (sizeof(AudioBuffer) * numberOfBuffers)));
- m_bufferList->mNumberBuffers = numberOfBuffers;
- for (int i = 0; i < numberOfBuffers; ++i) {
- m_bufferList->mBuffers[i].mNumberChannels = isInterleaved ? numberOfBuffers : 1;
- m_bufferList->mBuffers[i].mDataByteSize = m_dataSize;
- m_bufferList->mBuffers[i].mData = malloc(m_dataSize);
- }
-}
-
-CoreAudioBufferList::~CoreAudioBufferList()
-{
- if (m_owner) {
- for (UInt32 i = 0; i < m_bufferList->mNumberBuffers; ++i)
- free(m_bufferList->mBuffers[i].mData);
- }
-
- free(m_bufferList);
-}
-
-char *CoreAudioBufferList::data(int buffer) const
-{
- return static_cast<char*>(m_bufferList->mBuffers[buffer].mData);
-}
-
-qint64 CoreAudioBufferList::bufferSize(int buffer) const
-{
- return m_bufferList->mBuffers[buffer].mDataByteSize;
-}
-
-int CoreAudioBufferList::frameCount(int buffer) const
-{
- return m_bufferList->mBuffers[buffer].mDataByteSize / m_streamDescription.mBytesPerFrame;
-}
-
-int CoreAudioBufferList::packetCount(int buffer) const
-{
- return m_bufferList->mBuffers[buffer].mDataByteSize / m_streamDescription.mBytesPerPacket;
-}
-
-int CoreAudioBufferList::packetSize() const
-{
- return m_streamDescription.mBytesPerPacket;
-}
-
-void CoreAudioBufferList::reset()
-{
- for (UInt32 i = 0; i < m_bufferList->mNumberBuffers; ++i) {
- m_bufferList->mBuffers[i].mDataByteSize = m_dataSize;
- m_bufferList->mBuffers[i].mData = 0;
- }
-}
-
-CoreAudioPacketFeeder::CoreAudioPacketFeeder(CoreAudioBufferList *abl)
- : m_audioBufferList(abl)
-{
- m_totalPackets = m_audioBufferList->packetCount();
- m_position = 0;
-}
-
-bool CoreAudioPacketFeeder::feed(AudioBufferList &dst, UInt32 &packetCount)
-{
- if (m_position == m_totalPackets) {
- dst.mBuffers[0].mDataByteSize = 0;
- packetCount = 0;
- return false;
- }
-
- if (m_totalPackets - m_position < packetCount)
- packetCount = m_totalPackets - m_position;
-
- dst.mBuffers[0].mDataByteSize = packetCount * m_audioBufferList->packetSize();
- dst.mBuffers[0].mData = m_audioBufferList->data() + (m_position * m_audioBufferList->packetSize());
-
- m_position += packetCount;
-
- return true;
-}
-
-bool CoreAudioPacketFeeder::empty() const
-{
- return m_position == m_totalPackets;
-}
-
-CoreAudioInputBuffer::CoreAudioInputBuffer(int bufferSize, int maxPeriodSize, const AudioStreamBasicDescription &inputFormat, const AudioStreamBasicDescription &outputFormat, QObject *parent)
- : QObject(parent)
- , m_deviceError(false)
- , m_device(0)
- , m_audioConverter(0)
- , m_inputFormat(inputFormat)
- , m_outputFormat(outputFormat)
- , m_volume(qreal(1.0f))
-{
- m_maxPeriodSize = maxPeriodSize;
- m_periodTime = m_maxPeriodSize / m_outputFormat.mBytesPerFrame * 1000 / m_outputFormat.mSampleRate;
-
- m_buffer = new CoreAudioRingBuffer(bufferSize);
-
- m_inputBufferList = new CoreAudioBufferList(m_inputFormat);
-
- m_flushTimer = new QTimer(this);
- connect(m_flushTimer, SIGNAL(timeout()), SLOT(flushBuffer()));
-
- if (CoreAudioUtils::toQAudioFormat(inputFormat) != CoreAudioUtils::toQAudioFormat(outputFormat)) {
- if (AudioConverterNew(&m_inputFormat, &m_outputFormat, &m_audioConverter) != noErr) {
- qWarning() << "QAudioInput: Unable to create an Audio Converter";
- m_audioConverter = 0;
- }
- }
-
- m_qFormat = CoreAudioUtils::toQAudioFormat(inputFormat); // we adjust volume before conversion
-}
-
-CoreAudioInputBuffer::~CoreAudioInputBuffer()
-{
- delete m_buffer;
-}
-
-qreal CoreAudioInputBuffer::volume() const
-{
- return m_volume;
-}
-
-void CoreAudioInputBuffer::setVolume(qreal v)
-{
- m_volume = v;
-}
-
-qint64 CoreAudioInputBuffer::renderFromDevice(AudioUnit audioUnit, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames)
-{
- const bool pullMode = m_device == 0;
-
- OSStatus err;
- qint64 framesRendered = 0;
-
- m_inputBufferList->reset();
- err = AudioUnitRender(audioUnit,
- ioActionFlags,
- inTimeStamp,
- inBusNumber,
- inNumberFrames,
- m_inputBufferList->audioBufferList());
-
- // adjust volume, if necessary
- if (!qFuzzyCompare(m_volume, qreal(1.0f))) {
- QAudioHelperInternal::qMultiplySamples(m_volume,
- m_qFormat,
- m_inputBufferList->data(), /* input */
- m_inputBufferList->data(), /* output */
- m_inputBufferList->bufferSize());
- }
-
- if (m_audioConverter != 0) {
- CoreAudioPacketFeeder feeder(m_inputBufferList);
-
- int copied = 0;
- const int available = m_buffer->free();
-
- while (err == noErr && !feeder.empty()) {
- CoreAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available - copied);
-
- if (region.second == 0)
- break;
-
- AudioBufferList output;
- output.mNumberBuffers = 1;
- output.mBuffers[0].mNumberChannels = 1;
- output.mBuffers[0].mDataByteSize = region.second;
- output.mBuffers[0].mData = region.first;
-
- UInt32 packetSize = region.second / m_outputFormat.mBytesPerPacket;
- err = AudioConverterFillComplexBuffer(m_audioConverter,
- converterCallback,
- &feeder,
- &packetSize,
- &output,
- 0);
- region.second = output.mBuffers[0].mDataByteSize;
- copied += region.second;
-
- m_buffer->releaseWriteRegion(region);
- }
-
- framesRendered += copied / m_outputFormat.mBytesPerFrame;
- }
- else {
- const int available = m_inputBufferList->bufferSize();
- bool wecan = true;
- int copied = 0;
-
- while (wecan && copied < available) {
- CoreAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available - copied);
-
- if (region.second > 0) {
- memcpy(region.first, m_inputBufferList->data() + copied, region.second);
- copied += region.second;
- }
- else
- wecan = false;
-
- m_buffer->releaseWriteRegion(region);
- }
-
- framesRendered = copied / m_outputFormat.mBytesPerFrame;
- }
-
- if (pullMode && framesRendered > 0)
- emit readyRead();
-
- return framesRendered;
-}
-
-qint64 CoreAudioInputBuffer::readBytes(char *data, qint64 len)
-{
- bool wecan = true;
- qint64 bytesCopied = 0;
-
- len -= len % m_maxPeriodSize;
- while (wecan && bytesCopied < len) {
- CoreAudioRingBuffer::Region region = m_buffer->acquireReadRegion(len - bytesCopied);
-
- if (region.second > 0) {
- memcpy(data + bytesCopied, region.first, region.second);
- bytesCopied += region.second;
- }
- else
- wecan = false;
-
- m_buffer->releaseReadRegion(region);
- }
-
- return bytesCopied;
-}
-
-void CoreAudioInputBuffer::setFlushDevice(QIODevice *device)
-{
- if (m_device != device)
- m_device = device;
-}
-
-void CoreAudioInputBuffer::startFlushTimer()
-{
- if (m_device != 0) {
- // We use the period time for the timer, since that's
- // around the buffer size (pre conversion >.>)
- m_flushTimer->start(qMax(1, m_periodTime));
- }
-}
-
-void CoreAudioInputBuffer::stopFlushTimer()
-{
- m_flushTimer->stop();
-}
-
-void CoreAudioInputBuffer::flush(bool all)
-{
- if (m_device == 0)
- return;
-
- const int used = m_buffer->used();
- const int readSize = all ? used : used - (used % m_maxPeriodSize);
-
- if (readSize > 0) {
- bool wecan = true;
- int flushed = 0;
-
- while (!m_deviceError && wecan && flushed < readSize) {
- CoreAudioRingBuffer::Region region = m_buffer->acquireReadRegion(readSize - flushed);
-
- if (region.second > 0) {
- int bytesWritten = m_device->write(region.first, region.second);
- if (bytesWritten < 0) {
- stopFlushTimer();
- m_deviceError = true;
- }
- else {
- region.second = bytesWritten;
- flushed += bytesWritten;
- wecan = bytesWritten != 0;
- }
- }
- else
- wecan = false;
-
- m_buffer->releaseReadRegion(region);
- }
- }
-}
-
-void CoreAudioInputBuffer::reset()
-{
- m_buffer->reset();
- m_deviceError = false;
-}
-
-int CoreAudioInputBuffer::available() const
-{
- return m_buffer->free();
-}
-
-int CoreAudioInputBuffer::used() const
-{
- return m_buffer->used();
-}
-
-void CoreAudioInputBuffer::flushBuffer()
-{
- flush();
-}
-
-OSStatus CoreAudioInputBuffer::converterCallback(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets, AudioBufferList *ioData, AudioStreamPacketDescription **outDataPacketDescription, void *inUserData)
-{
- Q_UNUSED(inAudioConverter);
- Q_UNUSED(outDataPacketDescription);
-
- CoreAudioPacketFeeder* feeder = static_cast<CoreAudioPacketFeeder*>(inUserData);
-
- if (!feeder->feed(*ioData, *ioNumberDataPackets))
- return as_empty;
-
- return noErr;
-}
-
-CoreAudioInputDevice::CoreAudioInputDevice(CoreAudioInputBuffer *audioBuffer, QObject *parent)
- : QIODevice(parent)
- , m_audioBuffer(audioBuffer)
-{
- open(QIODevice::ReadOnly | QIODevice::Unbuffered);
- connect(m_audioBuffer, SIGNAL(readyRead()), SIGNAL(readyRead()));
-}
-
-qint64 CoreAudioInputDevice::readData(char *data, qint64 len)
-{
- return m_audioBuffer->readBytes(data, len);
-}
-
-qint64 CoreAudioInputDevice::writeData(const char *data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
-
- return 0;
-}
-
-CoreAudioInput::CoreAudioInput(const QByteArray &device)
- : m_isOpen(false)
- , m_internalBufferSize(DEFAULT_BUFFER_SIZE)
- , m_totalFrames(0)
- , m_audioUnit(0)
- , m_clockFrequency(CoreAudioUtils::frequency() / 1000)
- , m_startTime(0)
- , m_errorCode(QAudio::NoError)
- , m_stateCode(QAudio::StoppedState)
- , m_audioBuffer(0)
- , m_volume(1.0)
-{
-#if defined(Q_OS_OSX)
- quint32 deviceId;
- QDataStream dataStream(device);
- dataStream >> deviceId >> m_device;
- m_audioDeviceId = AudioDeviceID(deviceId);
-#else //iOS
- m_device = device;
-#endif
-
- m_audioDeviceInfo = new CoreAudioDeviceInfo(device, QAudio::AudioInput);
-
- m_intervalTimer = new QTimer(this);
- m_intervalTimer->setInterval(1000);
- connect(m_intervalTimer, SIGNAL(timeout()), this, SIGNAL(notify()));
-}
-
-
-CoreAudioInput::~CoreAudioInput()
-{
- close();
- delete m_audioDeviceInfo;
-}
-
-bool CoreAudioInput::open()
-{
-#if defined(Q_OS_IOS)
- CoreAudioSessionManager::instance().setCategory(CoreAudioSessionManager::PlayAndRecord, CoreAudioSessionManager::MixWithOthers);
- CoreAudioSessionManager::instance().setActive(true);
-#endif
-
- if (m_isOpen)
- return true;
-
- UInt32 size = 0;
-
- AudioComponentDescription componentDescription;
- componentDescription.componentType = kAudioUnitType_Output;
-#if defined(Q_OS_OSX)
- componentDescription.componentSubType = kAudioUnitSubType_HALOutput;
-#else
- componentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
-#endif
- componentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
- componentDescription.componentFlags = 0;
- componentDescription.componentFlagsMask = 0;
-
- AudioComponent component = AudioComponentFindNext(0, &componentDescription);
- if (component == 0) {
- qWarning() << "QAudioInput: Failed to find Output component";
- return false;
- }
-
- if (AudioComponentInstanceNew(component, &m_audioUnit) != noErr) {
- qWarning() << "QAudioInput: Unable to Open Output Component";
- return false;
- }
-
- // Set mode
- // switch to input mode
- UInt32 enable = 1;
- if (AudioUnitSetProperty(m_audioUnit,
- kAudioOutputUnitProperty_EnableIO,
- kAudioUnitScope_Input,
- 1,
- &enable,
- sizeof(enable)) != noErr) {
- qWarning() << "QAudioInput: Unable to switch to input mode (Enable Input)";
- return false;
- }
-
- enable = 0;
- if (AudioUnitSetProperty(m_audioUnit,
- kAudioOutputUnitProperty_EnableIO,
- kAudioUnitScope_Output,
- 0,
- &enable,
- sizeof(enable)) != noErr) {
- qWarning() << "QAudioInput: Unable to switch to input mode (Disable output)";
- return false;
- }
-
- // register callback
- AURenderCallbackStruct callback;
- callback.inputProc = inputCallback;
- callback.inputProcRefCon = this;
-
- if (AudioUnitSetProperty(m_audioUnit,
- kAudioOutputUnitProperty_SetInputCallback,
- kAudioUnitScope_Global,
- 0,
- &callback,
- sizeof(callback)) != noErr) {
- qWarning() << "QAudioInput: Failed to set AudioUnit callback";
- return false;
- }
-
-#if defined(Q_OS_OSX)
- //Set Audio Device
- if (AudioUnitSetProperty(m_audioUnit,
- kAudioOutputUnitProperty_CurrentDevice,
- kAudioUnitScope_Global,
- 0,
- &m_audioDeviceId,
- sizeof(m_audioDeviceId)) != noErr) {
- qWarning() << "QAudioInput: Unable to use configured device";
- return false;
- }
-#endif
-
- //set format
- m_streamFormat = CoreAudioUtils::toAudioStreamBasicDescription(m_audioFormat);
-
-#if defined(Q_OS_OSX)
- if (m_audioFormat == m_audioDeviceInfo->preferredFormat()) {
-#endif
-
- m_deviceFormat = m_streamFormat;
- AudioUnitSetProperty(m_audioUnit,
- kAudioUnitProperty_StreamFormat,
- kAudioUnitScope_Output,
- 1,
- &m_deviceFormat,
- sizeof(m_deviceFormat));
-#if defined(Q_OS_OSX)
- } else {
- size = sizeof(m_deviceFormat);
- if (AudioUnitGetProperty(m_audioUnit,
- kAudioUnitProperty_StreamFormat,
- kAudioUnitScope_Input,
- 1,
- &m_deviceFormat,
- &size) != noErr) {
- qWarning() << "QAudioInput: Unable to retrieve device format";
- return false;
- }
-
- if (AudioUnitSetProperty(m_audioUnit,
- kAudioUnitProperty_StreamFormat,
- kAudioUnitScope_Output,
- 1,
- &m_deviceFormat,
- sizeof(m_deviceFormat)) != noErr) {
- qWarning() << "QAudioInput: Unable to set device format";
- return false;
- }
- }
-#endif
-
- //setup buffers
- UInt32 numberOfFrames;
-#if defined(Q_OS_OSX)
- size = sizeof(UInt32);
- if (AudioUnitGetProperty(m_audioUnit,
- kAudioDevicePropertyBufferFrameSize,
- kAudioUnitScope_Global,
- 0,
- &numberOfFrames,
- &size) != noErr) {
- qWarning() << "QAudioInput: Failed to get audio period size";
- return false;
- }
- //BUG: numberOfFrames gets ignored after this point
-
- AudioValueRange bufferRange;
- size = sizeof(AudioValueRange);
-
- if (AudioUnitGetProperty(m_audioUnit,
- kAudioDevicePropertyBufferFrameSizeRange,
- kAudioUnitScope_Global,
- 0,
- &bufferRange,
- &size) != noErr) {
- qWarning() << "QAudioInput: Failed to get audio period size range";
- return false;
- }
-
- // See if the requested buffer size is permissible
- numberOfFrames = qBound((UInt32)bufferRange.mMinimum, m_internalBufferSize / m_streamFormat.mBytesPerFrame, (UInt32)bufferRange.mMaximum);
-
- // Set it back
- if (AudioUnitSetProperty(m_audioUnit,
- kAudioDevicePropertyBufferFrameSize,
- kAudioUnitScope_Global,
- 0,
- &numberOfFrames,
- sizeof(UInt32)) != noErr) {
- qWarning() << "QAudioInput: Failed to set audio buffer size";
- return false;
- }
-#else //iOS
- Float32 bufferSize = CoreAudioSessionManager::instance().currentIOBufferDuration();
- bufferSize *= m_streamFormat.mSampleRate;
- numberOfFrames = bufferSize;
-#endif
-
- // Now allocate a few buffers to be safe.
- m_periodSizeBytes = m_internalBufferSize = numberOfFrames * m_streamFormat.mBytesPerFrame;
-
- m_audioBuffer = new CoreAudioInputBuffer(m_internalBufferSize * 4,
- m_periodSizeBytes,
- m_deviceFormat,
- m_streamFormat,
- this);
-
- m_audioBuffer->setVolume(m_volume);
- m_audioIO = new CoreAudioInputDevice(m_audioBuffer, this);
-
- // Init
- if (AudioUnitInitialize(m_audioUnit) != noErr) {
- qWarning() << "QAudioInput: Failed to initialize AudioUnit";
- return false;
- }
-
- m_isOpen = true;
-
- return m_isOpen;
-
-}
-
-void CoreAudioInput::close()
-{
- if (m_audioUnit != 0) {
- AudioOutputUnitStop(m_audioUnit);
- AudioUnitUninitialize(m_audioUnit);
- AudioComponentInstanceDispose(m_audioUnit);
- }
-
- delete m_audioBuffer;
-}
-
-void CoreAudioInput::start(QIODevice *device)
-{
- QIODevice* op = device;
-
- if (!m_audioDeviceInfo->isFormatSupported(m_audioFormat) || !open()) {
- m_stateCode = QAudio::StoppedState;
- m_errorCode = QAudio::OpenError;
- return;
- }
-
- reset();
- m_audioBuffer->reset();
- m_audioBuffer->setFlushDevice(op);
-
- if (op == 0)
- op = m_audioIO;
-
- // Start
- m_startTime = CoreAudioUtils::currentTime();
- m_totalFrames = 0;
-
- m_stateCode = QAudio::IdleState;
- m_errorCode = QAudio::NoError;
- emit stateChanged(m_stateCode);
-
- audioThreadStart();
-}
-
-
-QIODevice *CoreAudioInput::start()
-{
- QIODevice* op = 0;
-
- if (!m_audioDeviceInfo->isFormatSupported(m_audioFormat) || !open()) {
- m_stateCode = QAudio::StoppedState;
- m_errorCode = QAudio::OpenError;
- return m_audioIO;
- }
-
- reset();
- m_audioBuffer->reset();
- m_audioBuffer->setFlushDevice(op);
-
- if (op == 0)
- op = m_audioIO;
-
- // Start
- m_startTime = CoreAudioUtils::currentTime();
- m_totalFrames = 0;
-
- m_stateCode = QAudio::IdleState;
- m_errorCode = QAudio::NoError;
- emit stateChanged(m_stateCode);
-
- audioThreadStart();
-
- return op;
-}
-
-
-void CoreAudioInput::stop()
-{
- QMutexLocker lock(&m_mutex);
- if (m_stateCode != QAudio::StoppedState) {
- audioThreadStop();
- m_audioBuffer->flush(true);
-
- m_errorCode = QAudio::NoError;
- m_stateCode = QAudio::StoppedState;
- QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, m_stateCode));
- }
-}
-
-
-void CoreAudioInput::reset()
-{
- QMutexLocker lock(&m_mutex);
- if (m_stateCode != QAudio::StoppedState) {
- audioThreadStop();
-
- m_errorCode = QAudio::NoError;
- m_stateCode = QAudio::StoppedState;
- m_audioBuffer->reset();
- QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, m_stateCode));
- }
-}
-
-
-void CoreAudioInput::suspend()
-{
- QMutexLocker lock(&m_mutex);
- if (m_stateCode == QAudio::ActiveState || m_stateCode == QAudio::IdleState) {
- audioThreadStop();
-
- m_errorCode = QAudio::NoError;
- m_stateCode = QAudio::SuspendedState;
- QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, m_stateCode));
- }
-}
-
-
-void CoreAudioInput::resume()
-{
- QMutexLocker lock(&m_mutex);
- if (m_stateCode == QAudio::SuspendedState) {
- audioThreadStart();
-
- m_errorCode = QAudio::NoError;
- m_stateCode = QAudio::ActiveState;
- QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, m_stateCode));
- }
-}
-
-
-int CoreAudioInput::bytesReady() const
-{
- if (!m_audioBuffer)
- return 0;
- return m_audioBuffer->used();
-}
-
-
-int CoreAudioInput::periodSize() const
-{
- return m_periodSizeBytes;
-}
-
-
-void CoreAudioInput::setBufferSize(int value)
-{
- m_internalBufferSize = value;
-}
-
-
-int CoreAudioInput::bufferSize() const
-{
- return m_internalBufferSize;
-}
-
-
-void CoreAudioInput::setNotifyInterval(int milliSeconds)
-{
- if (m_intervalTimer->interval() == milliSeconds)
- return;
-
- if (milliSeconds <= 0)
- milliSeconds = 0;
-
- m_intervalTimer->setInterval(milliSeconds);
-}
-
-
-int CoreAudioInput::notifyInterval() const
-{
- return m_intervalTimer->interval();
-}
-
-
-qint64 CoreAudioInput::processedUSecs() const
-{
- return m_totalFrames * 1000000 / m_audioFormat.sampleRate();
-}
-
-
-qint64 CoreAudioInput::elapsedUSecs() const
-{
- if (m_stateCode == QAudio::StoppedState)
- return 0;
-
- return (CoreAudioUtils::currentTime() - m_startTime) / (m_clockFrequency / 1000);
-}
-
-
-QAudio::Error CoreAudioInput::error() const
-{
- return m_errorCode;
-}
-
-
-QAudio::State CoreAudioInput::state() const
-{
- return m_stateCode;
-}
-
-
-void CoreAudioInput::setFormat(const QAudioFormat &format)
-{
- if (m_stateCode == QAudio::StoppedState)
- m_audioFormat = format;
-}
-
-
-QAudioFormat CoreAudioInput::format() const
-{
- return m_audioFormat;
-}
-
-
-void CoreAudioInput::setVolume(qreal volume)
-{
- m_volume = volume;
- if (m_audioBuffer)
- m_audioBuffer->setVolume(m_volume);
-}
-
-
-qreal CoreAudioInput::volume() const
-{
- return m_volume;
-}
-
-void CoreAudioInput::deviceStoppped()
-{
- stopTimers();
- emit stateChanged(m_stateCode);
-}
-
-void CoreAudioInput::audioThreadStart()
-{
- startTimers();
- m_audioThreadState.storeRelaxed(Running);
- AudioOutputUnitStart(m_audioUnit);
-}
-
-void CoreAudioInput::audioThreadStop()
-{
- stopTimers();
- if (m_audioThreadState.testAndSetAcquire(Running, Stopped))
- m_threadFinished.wait(&m_mutex);
-}
-
-void CoreAudioInput::audioDeviceStop()
-{
- AudioOutputUnitStop(m_audioUnit);
- m_audioThreadState.storeRelaxed(Stopped);
- m_threadFinished.wakeOne();
-}
-
-void CoreAudioInput::audioDeviceActive()
-{
- if (m_stateCode == QAudio::IdleState) {
- QMutexLocker lock(&m_mutex);
- m_stateCode = QAudio::ActiveState;
- emit stateChanged(m_stateCode);
- }
-}
-
-void CoreAudioInput::audioDeviceFull()
-{
- if (m_stateCode == QAudio::ActiveState) {
- QMutexLocker lock(&m_mutex);
- m_errorCode = QAudio::UnderrunError;
- m_stateCode = QAudio::IdleState;
- emit stateChanged(m_stateCode);
- }
-}
-
-void CoreAudioInput::audioDeviceError()
-{
- if (m_stateCode == QAudio::ActiveState) {
- QMutexLocker lock(&m_mutex);
- audioDeviceStop();
-
- m_errorCode = QAudio::IOError;
- m_stateCode = QAudio::StoppedState;
- QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection);
- }
-}
-
-void CoreAudioInput::startTimers()
-{
- m_audioBuffer->startFlushTimer();
- if (m_intervalTimer->interval() > 0)
- m_intervalTimer->start();
-}
-
-void CoreAudioInput::stopTimers()
-{
- m_audioBuffer->stopFlushTimer();
- m_intervalTimer->stop();
-}
-
-OSStatus CoreAudioInput::inputCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
-{
- Q_UNUSED(ioData);
-
- CoreAudioInput* d = static_cast<CoreAudioInput*>(inRefCon);
-
- const int threadState = d->m_audioThreadState.loadAcquire();
- if (threadState == Stopped)
- d->audioDeviceStop();
- else {
- qint64 framesWritten;
-
- framesWritten = d->m_audioBuffer->renderFromDevice(d->m_audioUnit,
- ioActionFlags,
- inTimeStamp,
- inBusNumber,
- inNumberFrames);
-
- if (framesWritten > 0) {
- d->m_totalFrames += framesWritten;
- d->audioDeviceActive();
- } else if (framesWritten == 0)
- d->audioDeviceFull();
- else if (framesWritten < 0)
- d->audioDeviceError();
- }
-
- return noErr;
-}
-
-QT_END_NAMESPACE
-
-#include "moc_coreaudioinput.cpp"
diff --git a/src/plugins/coreaudio/coreaudiooutput.h b/src/plugins/coreaudio/coreaudiooutput.h
deleted file mode 100644
index 97b1e0438..000000000
--- a/src/plugins/coreaudio/coreaudiooutput.h
+++ /dev/null
@@ -1,205 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef IOSAUDIOOUTPUT_H
-#define IOSAUDIOOUTPUT_H
-
-#include <qaudiosystem.h>
-
-#if defined(Q_OS_OSX)
-# include <CoreAudio/CoreAudio.h>
-#endif
-#include <AudioUnit/AudioUnit.h>
-#include <CoreAudio/CoreAudioTypes.h>
-
-#include <QtCore/QIODevice>
-#include <QtCore/QWaitCondition>
-#include <QtCore/QMutex>
-
-QT_BEGIN_NAMESPACE
-
-class CoreAudioOutputBuffer;
-class QTimer;
-class CoreAudioDeviceInfo;
-class CoreAudioRingBuffer;
-
-class CoreAudioOutputBuffer : public QObject
-{
- Q_OBJECT
-
-public:
- CoreAudioOutputBuffer(int bufferSize, int maxPeriodSize, QAudioFormat const& audioFormat);
- ~CoreAudioOutputBuffer();
-
- qint64 readFrames(char *data, qint64 maxFrames);
- qint64 writeBytes(const char *data, qint64 maxSize);
-
- int available() const;
- void reset();
-
- void setPrefetchDevice(QIODevice *device);
-
- void startFillTimer();
- void stopFillTimer();
-
-signals:
- void readyRead();
-
-private slots:
- void fillBuffer();
-
-private:
- bool m_deviceError;
- int m_maxPeriodSize;
- int m_bytesPerFrame;
- int m_periodTime;
- QIODevice *m_device;
- QTimer *m_fillTimer;
- CoreAudioRingBuffer *m_buffer;
-};
-
-class CoreAudioOutputDevice : public QIODevice
-{
-public:
- CoreAudioOutputDevice(CoreAudioOutputBuffer *audioBuffer, QObject *parent);
-
- qint64 readData(char *data, qint64 len);
- qint64 writeData(const char *data, qint64 len);
-
- bool isSequential() const { return true; }
-
-private:
- CoreAudioOutputBuffer *m_audioBuffer;
-};
-
-
-class CoreAudioOutput : public QAbstractAudioOutput
-{
- Q_OBJECT
-
-public:
- CoreAudioOutput(const QByteArray &device);
- ~CoreAudioOutput();
-
- void start(QIODevice *device);
- QIODevice *start();
- void stop();
- void reset();
- void suspend();
- void resume();
- int bytesFree() const;
- int periodSize() const;
- void setBufferSize(int value);
- int bufferSize() const;
- void setNotifyInterval(int milliSeconds);
- int notifyInterval() const;
- qint64 processedUSecs() const;
- qint64 elapsedUSecs() const;
- QAudio::Error error() const;
- QAudio::State state() const;
- void setFormat(const QAudioFormat &format);
- QAudioFormat format() const;
-
- void setVolume(qreal volume);
- qreal volume() const;
-
- void setCategory(const QString &category);
- QString category() const;
-
-private slots:
- void deviceStopped();
- void inputReady();
-
-private:
- enum {
- Running,
- Draining,
- Stopped
- };
-
- static OSStatus renderCallback(void *inRefCon,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber,
- UInt32 inNumberFrames,
- AudioBufferList *ioData);
-
- bool open();
- void close();
- void audioThreadStart();
- void audioThreadStop();
- void audioThreadDrain();
- void audioDeviceStop();
- void audioDeviceIdle();
- void audioDeviceError();
-
- void startTimers();
- void stopTimers();
-
- QByteArray m_device;
-
- bool m_isOpen;
- int m_internalBufferSize;
- int m_periodSizeBytes;
- qint64 m_totalFrames;
- QAudioFormat m_audioFormat;
- QIODevice *m_audioIO;
-#if defined(Q_OS_OSX)
- AudioDeviceID m_audioDeviceId;
-#endif
- AudioUnit m_audioUnit;
- Float64 m_clockFrequency;
- UInt64 m_startTime;
- AudioStreamBasicDescription m_streamFormat;
- CoreAudioOutputBuffer *m_audioBuffer;
- QAtomicInt m_audioThreadState;
- QWaitCondition m_threadFinished;
- QMutex m_mutex;
- QTimer *m_intervalTimer;
- CoreAudioDeviceInfo *m_audioDeviceInfo;
- qreal m_cachedVolume;
- qreal m_volume;
- bool m_pullMode;
-
- QAudio::Error m_errorCode;
- QAudio::State m_stateCode;
-};
-
-QT_END_NAMESPACE
-
-#endif // IOSAUDIOOUTPUT_H
diff --git a/src/plugins/coreaudio/coreaudiooutput.mm b/src/plugins/coreaudio/coreaudiooutput.mm
deleted file mode 100644
index 1138de3e2..000000000
--- a/src/plugins/coreaudio/coreaudiooutput.mm
+++ /dev/null
@@ -1,752 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "coreaudiooutput.h"
-#include "coreaudiosessionmanager.h"
-#include "coreaudiodeviceinfo.h"
-#include "coreaudioutils.h"
-
-#include <QtCore/QDataStream>
-#include <QtCore/QTimer>
-#include <QtCore/QDebug>
-
-#include <AudioUnit/AudioUnit.h>
-#include <AudioToolbox/AudioToolbox.h>
-#if defined(Q_OS_OSX)
-# include <AudioUnit/AudioComponent.h>
-#endif
-
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
-# include <QtMultimedia/private/qaudiohelpers_p.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-static const int DEFAULT_BUFFER_SIZE = 8 * 1024;
-
-CoreAudioOutputBuffer::CoreAudioOutputBuffer(int bufferSize, int maxPeriodSize, const QAudioFormat &audioFormat)
- : m_deviceError(false)
- , m_maxPeriodSize(maxPeriodSize)
- , m_device(0)
-{
- m_buffer = new CoreAudioRingBuffer(bufferSize + (bufferSize % maxPeriodSize == 0 ? 0 : maxPeriodSize - (bufferSize % maxPeriodSize)));
- m_bytesPerFrame = (audioFormat.sampleSize() / 8) * audioFormat.channelCount();
- m_periodTime = m_maxPeriodSize / m_bytesPerFrame * 1000 / audioFormat.sampleRate();
-
- m_fillTimer = new QTimer(this);
- connect(m_fillTimer, SIGNAL(timeout()), SLOT(fillBuffer()));
-}
-
-CoreAudioOutputBuffer::~CoreAudioOutputBuffer()
-{
- delete m_buffer;
-}
-
-qint64 CoreAudioOutputBuffer::readFrames(char *data, qint64 maxFrames)
-{
- bool wecan = true;
- qint64 framesRead = 0;
-
- while (wecan && framesRead < maxFrames) {
- CoreAudioRingBuffer::Region region = m_buffer->acquireReadRegion((maxFrames - framesRead) * m_bytesPerFrame);
-
- if (region.second > 0) {
- // Ensure that we only read whole frames.
- region.second -= region.second % m_bytesPerFrame;
-
- if (region.second > 0) {
- memcpy(data + (framesRead * m_bytesPerFrame), region.first, region.second);
- framesRead += region.second / m_bytesPerFrame;
- } else
- wecan = false; // If there is only a partial frame left we should exit.
- }
- else
- wecan = false;
-
- m_buffer->releaseReadRegion(region);
- }
-
- if (framesRead == 0 && m_deviceError)
- framesRead = -1;
-
- return framesRead;
-}
-
-qint64 CoreAudioOutputBuffer::writeBytes(const char *data, qint64 maxSize)
-{
- bool wecan = true;
- qint64 bytesWritten = 0;
-
- maxSize -= maxSize % m_bytesPerFrame;
- while (wecan && bytesWritten < maxSize) {
- CoreAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(maxSize - bytesWritten);
-
- if (region.second > 0) {
- memcpy(region.first, data + bytesWritten, region.second);
- bytesWritten += region.second;
- }
- else
- wecan = false;
-
- m_buffer->releaseWriteRegion(region);
- }
-
- if (bytesWritten > 0)
- emit readyRead();
-
- return bytesWritten;
-}
-
-int CoreAudioOutputBuffer::available() const
-{
- return m_buffer->free();
-}
-
-void CoreAudioOutputBuffer::reset()
-{
- m_buffer->reset();
- m_device = 0;
- m_deviceError = false;
-}
-
-void CoreAudioOutputBuffer::setPrefetchDevice(QIODevice *device)
-{
- if (m_device != device) {
- m_device = device;
- if (m_device != 0)
- fillBuffer();
- }
-}
-
-void CoreAudioOutputBuffer::startFillTimer()
-{
- if (m_device != 0)
- m_fillTimer->start(m_buffer->size() / 2 / m_maxPeriodSize * m_periodTime);
-}
-
-void CoreAudioOutputBuffer::stopFillTimer()
-{
- m_fillTimer->stop();
-}
-
-void CoreAudioOutputBuffer::fillBuffer()
-{
- const int free = m_buffer->free();
- const int writeSize = free - (free % m_maxPeriodSize);
-
- if (writeSize > 0) {
- bool wecan = true;
- int filled = 0;
-
- while (!m_deviceError && wecan && filled < writeSize) {
- CoreAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(writeSize - filled);
-
- if (region.second > 0) {
- region.second = m_device->read(region.first, region.second);
- if (region.second > 0)
- filled += region.second;
- else if (region.second == 0)
- wecan = false;
- else if (region.second < 0) {
- m_fillTimer->stop();
- region.second = 0;
- m_deviceError = true;
- }
- }
- else
- wecan = false;
-
- m_buffer->releaseWriteRegion(region);
- }
-
- if (filled > 0)
- emit readyRead();
- }
-}
-
-CoreAudioOutputDevice::CoreAudioOutputDevice(CoreAudioOutputBuffer *audioBuffer, QObject *parent)
- : QIODevice(parent)
- , m_audioBuffer(audioBuffer)
-{
- open(QIODevice::WriteOnly | QIODevice::Unbuffered);
-}
-
-qint64 CoreAudioOutputDevice::readData(char *data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
-
- return 0;
-}
-
-qint64 CoreAudioOutputDevice::writeData(const char *data, qint64 len)
-{
- return m_audioBuffer->writeBytes(data, len);
-}
-
-CoreAudioOutput::CoreAudioOutput(const QByteArray &device)
- : m_isOpen(false)
- , m_internalBufferSize(DEFAULT_BUFFER_SIZE)
- , m_totalFrames(0)
- , m_audioIO(0)
- , m_audioUnit(0)
- , m_startTime(0)
- , m_audioBuffer(0)
- , m_cachedVolume(1.0)
- , m_volume(1.0)
- , m_pullMode(false)
- , m_errorCode(QAudio::NoError)
- , m_stateCode(QAudio::StoppedState)
-{
-#if defined(Q_OS_OSX)
- quint32 deviceID;
- QDataStream dataStream(device);
- dataStream >> deviceID >> m_device;
- m_audioDeviceId = AudioDeviceID(deviceID);
-#else //iOS
- m_device = device;
-#endif
-
- m_clockFrequency = CoreAudioUtils::frequency() / 1000;
- m_audioDeviceInfo = new CoreAudioDeviceInfo(device, QAudio::AudioOutput);
- m_audioThreadState.storeRelaxed(Stopped);
-
- m_intervalTimer = new QTimer(this);
- m_intervalTimer->setInterval(1000);
- connect(m_intervalTimer, SIGNAL(timeout()), this, SIGNAL(notify()));
-}
-
-CoreAudioOutput::~CoreAudioOutput()
-{
- close();
- delete m_audioDeviceInfo;
-}
-
-void CoreAudioOutput::start(QIODevice *device)
-{
- QIODevice* op = device;
-
- if (!m_audioDeviceInfo->isFormatSupported(m_audioFormat) || !open()) {
- m_stateCode = QAudio::StoppedState;
- m_errorCode = QAudio::OpenError;
- return;
- }
-
- reset();
- m_audioBuffer->reset();
- m_audioBuffer->setPrefetchDevice(op);
-
- if (op == 0) {
- op = m_audioIO;
- m_stateCode = QAudio::IdleState;
- }
- else
- m_stateCode = QAudio::ActiveState;
-
- // Start
- m_pullMode = true;
- m_errorCode = QAudio::NoError;
- m_totalFrames = 0;
- m_startTime = CoreAudioUtils::currentTime();
-
- if (m_stateCode == QAudio::ActiveState)
- audioThreadStart();
-
- emit stateChanged(m_stateCode);
-}
-
-QIODevice *CoreAudioOutput::start()
-{
- if (!m_audioDeviceInfo->isFormatSupported(m_audioFormat) || !open()) {
- m_stateCode = QAudio::StoppedState;
- m_errorCode = QAudio::OpenError;
- return m_audioIO;
- }
-
- reset();
- m_audioBuffer->reset();
- m_audioBuffer->setPrefetchDevice(0);
-
- m_stateCode = QAudio::IdleState;
-
- // Start
- m_pullMode = false;
- m_errorCode = QAudio::NoError;
- m_totalFrames = 0;
- m_startTime = CoreAudioUtils::currentTime();
-
- emit stateChanged(m_stateCode);
-
- return m_audioIO;
-}
-
-void CoreAudioOutput::stop()
-{
- QMutexLocker lock(&m_mutex);
- if (m_stateCode != QAudio::StoppedState) {
- audioThreadDrain();
-
- m_stateCode = QAudio::StoppedState;
- m_errorCode = QAudio::NoError;
- emit stateChanged(m_stateCode);
- }
-}
-
-void CoreAudioOutput::reset()
-{
- QMutexLocker lock(&m_mutex);
- if (m_stateCode != QAudio::StoppedState) {
- audioThreadStop();
-
- m_stateCode = QAudio::StoppedState;
- m_errorCode = QAudio::NoError;
- emit stateChanged(m_stateCode);
- }
-}
-
-void CoreAudioOutput::suspend()
-{
- QMutexLocker lock(&m_mutex);
- if (m_stateCode == QAudio::ActiveState || m_stateCode == QAudio::IdleState) {
- audioThreadStop();
-
- m_stateCode = QAudio::SuspendedState;
- m_errorCode = QAudio::NoError;
- emit stateChanged(m_stateCode);
- }
-}
-
-void CoreAudioOutput::resume()
-{
- QMutexLocker lock(&m_mutex);
- if (m_stateCode == QAudio::SuspendedState) {
- audioThreadStart();
-
- m_stateCode = m_pullMode ? QAudio::ActiveState : QAudio::IdleState;
- m_errorCode = QAudio::NoError;
- emit stateChanged(m_stateCode);
- }
-}
-
-int CoreAudioOutput::bytesFree() const
-{
- return m_audioBuffer->available();
-}
-
-int CoreAudioOutput::periodSize() const
-{
- return m_periodSizeBytes;
-}
-
-void CoreAudioOutput::setBufferSize(int value)
-{
- if (m_stateCode == QAudio::StoppedState)
- m_internalBufferSize = value;
-}
-
-int CoreAudioOutput::bufferSize() const
-{
- return m_internalBufferSize;
-}
-
-void CoreAudioOutput::setNotifyInterval(int milliSeconds)
-{
- if (m_intervalTimer->interval() == milliSeconds)
- return;
-
- if (milliSeconds <= 0)
- milliSeconds = 0;
-
- m_intervalTimer->setInterval(milliSeconds);
-}
-
-int CoreAudioOutput::notifyInterval() const
-{
- return m_intervalTimer->interval();
-}
-
-qint64 CoreAudioOutput::processedUSecs() const
-{
- return m_totalFrames * 1000000 / m_audioFormat.sampleRate();
-}
-
-qint64 CoreAudioOutput::elapsedUSecs() const
-{
- if (m_stateCode == QAudio::StoppedState)
- return 0;
-
- return (CoreAudioUtils::currentTime() - m_startTime) / (m_clockFrequency / 1000);
-}
-
-QAudio::Error CoreAudioOutput::error() const
-{
- return m_errorCode;
-}
-
-QAudio::State CoreAudioOutput::state() const
-{
- return m_stateCode;
-}
-
-void CoreAudioOutput::setFormat(const QAudioFormat &format)
-{
- if (m_stateCode == QAudio::StoppedState)
- m_audioFormat = format;
-}
-
-QAudioFormat CoreAudioOutput::format() const
-{
- return m_audioFormat;
-}
-
-void CoreAudioOutput::setVolume(qreal volume)
-{
- m_cachedVolume = qBound(qreal(0.0), volume, qreal(1.0));
- if (!m_isOpen)
- return;
-
-#if defined(Q_OS_OSX)
- //on OS X the volume can be set directly on the AudioUnit
- if (AudioUnitSetParameter(m_audioUnit,
- kHALOutputParam_Volume,
- kAudioUnitScope_Global,
- 0 /* bus */,
- m_cachedVolume,
- 0) == noErr)
- m_volume = m_cachedVolume;
-#endif
-}
-
-qreal CoreAudioOutput::volume() const
-{
- return m_cachedVolume;
-}
-
-void CoreAudioOutput::setCategory(const QString &category)
-{
- Q_UNUSED(category);
-}
-
-QString CoreAudioOutput::category() const
-{
- return QString();
-}
-
-void CoreAudioOutput::deviceStopped()
-{
- m_intervalTimer->stop();
- emit stateChanged(m_stateCode);
-}
-
-void CoreAudioOutput::inputReady()
-{
- QMutexLocker lock(&m_mutex);
- if (m_stateCode == QAudio::IdleState) {
- audioThreadStart();
-
- m_stateCode = QAudio::ActiveState;
- m_errorCode = QAudio::NoError;
-
- emit stateChanged(m_stateCode);
- }
-}
-
-OSStatus CoreAudioOutput::renderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
-{
- Q_UNUSED(ioActionFlags);
- Q_UNUSED(inTimeStamp);
- Q_UNUSED(inBusNumber);
- Q_UNUSED(inNumberFrames);
-
- CoreAudioOutput* d = static_cast<CoreAudioOutput*>(inRefCon);
-
- const int threadState = d->m_audioThreadState.fetchAndAddAcquire(0);
- if (threadState == Stopped) {
- ioData->mBuffers[0].mDataByteSize = 0;
- d->audioDeviceStop();
- }
- else {
- const UInt32 bytesPerFrame = d->m_streamFormat.mBytesPerFrame;
- qint64 framesRead;
-
- framesRead = d->m_audioBuffer->readFrames((char*)ioData->mBuffers[0].mData,
- ioData->mBuffers[0].mDataByteSize / bytesPerFrame);
-
- if (framesRead > 0) {
- ioData->mBuffers[0].mDataByteSize = framesRead * bytesPerFrame;
- d->m_totalFrames += framesRead;
-
-#if defined(Q_OS_MACOS)
- // If playback is already stopped.
- if (threadState != Running) {
- qreal oldVolume = d->m_cachedVolume;
- // Decrease volume smoothly.
- d->setVolume(d->m_volume / 2);
- d->m_cachedVolume = oldVolume;
- }
-#elif defined(Q_OS_IOS) || defined(Q_OS_TVOS)
- // on iOS we have to adjust the sound volume ourselves
- if (!qFuzzyCompare(d->m_cachedVolume, qreal(1.0f))) {
- QAudioHelperInternal::qMultiplySamples(d->m_cachedVolume,
- d->m_audioFormat,
- ioData->mBuffers[0].mData, /* input */
- ioData->mBuffers[0].mData, /* output */
- ioData->mBuffers[0].mDataByteSize);
- }
-#endif
-
- }
- else {
- ioData->mBuffers[0].mDataByteSize = 0;
- if (framesRead == 0) {
- if (threadState == Draining)
- d->audioDeviceStop();
- else
- d->audioDeviceIdle();
- }
- else
- d->audioDeviceError();
- }
- }
-
- return noErr;
-}
-
-bool CoreAudioOutput::open()
-{
-#if defined(Q_OS_IOS)
- // Set default category to Ambient (implies MixWithOthers). This makes sure audio stops playing
- // if the screen is locked or if the Silent switch is toggled.
- CoreAudioSessionManager::instance().setCategory(CoreAudioSessionManager::Ambient, CoreAudioSessionManager::None);
- CoreAudioSessionManager::instance().setActive(true);
-#endif
-
- if (m_errorCode != QAudio::NoError)
- return false;
-
- if (m_isOpen) {
- setVolume(m_cachedVolume);
- return true;
- }
-
- AudioComponentDescription componentDescription;
- componentDescription.componentType = kAudioUnitType_Output;
-#if defined(Q_OS_OSX)
- componentDescription.componentSubType = kAudioUnitSubType_HALOutput;
-#else
- componentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
-#endif
- componentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
- componentDescription.componentFlags = 0;
- componentDescription.componentFlagsMask = 0;
-
- AudioComponent component = AudioComponentFindNext(0, &componentDescription);
- if (component == 0) {
- qWarning() << "QAudioOutput: Failed to find Output component";
- return false;
- }
-
- if (AudioComponentInstanceNew(component, &m_audioUnit) != noErr) {
- qWarning() << "QAudioOutput: Unable to Open Output Component";
- return false;
- }
-
- // register callback
- AURenderCallbackStruct callback;
- callback.inputProc = renderCallback;
- callback.inputProcRefCon = this;
-
- if (AudioUnitSetProperty(m_audioUnit,
- kAudioUnitProperty_SetRenderCallback,
- kAudioUnitScope_Global,
- 0,
- &callback,
- sizeof(callback)) != noErr) {
- qWarning() << "QAudioOutput: Failed to set AudioUnit callback";
- return false;
- }
-
-#if defined(Q_OS_OSX)
- //Set Audio Device
- if (AudioUnitSetProperty(m_audioUnit,
- kAudioOutputUnitProperty_CurrentDevice,
- kAudioUnitScope_Global,
- 0,
- &m_audioDeviceId,
- sizeof(m_audioDeviceId)) != noErr) {
- qWarning() << "QAudioOutput: Unable to use configured device";
- return false;
- }
-#endif
-
- // Set stream format
- m_streamFormat = CoreAudioUtils::toAudioStreamBasicDescription(m_audioFormat);
-
- UInt32 size = sizeof(m_streamFormat);
- if (AudioUnitSetProperty(m_audioUnit,
- kAudioUnitProperty_StreamFormat,
- kAudioUnitScope_Input,
- 0,
- &m_streamFormat,
- size) != noErr) {
- qWarning() << "QAudioOutput: Unable to Set Stream information";
- return false;
- }
-
- // Allocate buffer
- UInt32 numberOfFrames = 0;
-#if defined(Q_OS_OSX)
- size = sizeof(UInt32);
- if (AudioUnitGetProperty(m_audioUnit,
- kAudioDevicePropertyBufferFrameSize,
- kAudioUnitScope_Global,
- 0,
- &numberOfFrames,
- &size) != noErr) {
- qWarning() << "QAudioInput: Failed to get audio period size";
- return false;
- }
-#else //iOS
- Float32 bufferSize = CoreAudioSessionManager::instance().currentIOBufferDuration();
- bufferSize *= m_streamFormat.mSampleRate;
- numberOfFrames = bufferSize;
-#endif
-
- m_periodSizeBytes = numberOfFrames * m_streamFormat.mBytesPerFrame;
- if (m_internalBufferSize < m_periodSizeBytes * 2)
- m_internalBufferSize = m_periodSizeBytes * 2;
- else
- m_internalBufferSize -= m_internalBufferSize % m_streamFormat.mBytesPerFrame;
-
- m_audioBuffer = new CoreAudioOutputBuffer(m_internalBufferSize, m_periodSizeBytes, m_audioFormat);
- connect(m_audioBuffer, SIGNAL(readyRead()), SLOT(inputReady())); //Pull
-
- m_audioIO = new CoreAudioOutputDevice(m_audioBuffer, this);
-
- //Init
- if (AudioUnitInitialize(m_audioUnit)) {
- qWarning() << "QAudioOutput: Failed to initialize AudioUnit";
- return false;
- }
-
- m_isOpen = true;
-
- setVolume(m_cachedVolume);
-
- return true;
-}
-
-void CoreAudioOutput::close()
-{
- if (m_audioUnit != 0) {
- AudioOutputUnitStop(m_audioUnit);
- AudioUnitUninitialize(m_audioUnit);
- AudioComponentInstanceDispose(m_audioUnit);
- }
-
- delete m_audioBuffer;
-}
-
-void CoreAudioOutput::audioThreadStart()
-{
- startTimers();
- m_audioThreadState.storeRelaxed(Running);
- AudioOutputUnitStart(m_audioUnit);
-}
-
-void CoreAudioOutput::audioThreadStop()
-{
- stopTimers();
- if (m_audioThreadState.testAndSetAcquire(Running, Stopped))
- m_threadFinished.wait(&m_mutex, 500);
-}
-
-void CoreAudioOutput::audioThreadDrain()
-{
- stopTimers();
- if (m_audioThreadState.testAndSetAcquire(Running, Draining))
- m_threadFinished.wait(&m_mutex, 500);
-}
-
-void CoreAudioOutput::audioDeviceStop()
-{
- AudioOutputUnitStop(m_audioUnit);
- m_audioThreadState.storeRelaxed(Stopped);
- m_threadFinished.wakeOne();
-}
-
-void CoreAudioOutput::audioDeviceIdle()
-{
- if (m_stateCode == QAudio::ActiveState) {
- QMutexLocker lock(&m_mutex);
- audioDeviceStop();
-
- m_errorCode = QAudio::UnderrunError;
- m_stateCode = QAudio::IdleState;
- QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection);
- }
-}
-
-void CoreAudioOutput::audioDeviceError()
-{
- if (m_stateCode == QAudio::ActiveState) {
- QMutexLocker lock(&m_mutex);
- audioDeviceStop();
-
- m_errorCode = QAudio::IOError;
- m_stateCode = QAudio::StoppedState;
- QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection);
- }
-}
-
-void CoreAudioOutput::startTimers()
-{
- m_audioBuffer->startFillTimer();
- if (m_intervalTimer->interval() > 0)
- m_intervalTimer->start();
-}
-
-void CoreAudioOutput::stopTimers()
-{
- m_audioBuffer->stopFillTimer();
- m_intervalTimer->stop();
-}
-
-QT_END_NAMESPACE
-
-#include "moc_coreaudiooutput.cpp"
diff --git a/src/plugins/coreaudio/coreaudioplugin.h b/src/plugins/coreaudio/coreaudioplugin.h
deleted file mode 100644
index 5407bdeb9..000000000
--- a/src/plugins/coreaudio/coreaudioplugin.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef IOSAUDIOPLUGIN_H
-#define IOSAUDIOPLUGIN_H
-
-#include <QtMultimedia/qaudiosystemplugin.h>
-#include <QtMultimedia/private/qaudiosystempluginext_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class CoreAudioPlugin : public QAudioSystemPlugin, public QAudioSystemPluginExtension
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.audiosystemfactory/5.0" FILE "coreaudio.json")
- Q_INTERFACES(QAudioSystemPluginExtension)
-
-public:
- explicit CoreAudioPlugin(QObject *parent = 0);
- ~CoreAudioPlugin() {}
-
- QByteArray defaultDevice(QAudio::Mode mode) const override;
- QList<QByteArray> availableDevices(QAudio::Mode mode) const override;
- QAbstractAudioInput *createInput(const QByteArray &device) override;
- QAbstractAudioOutput *createOutput(const QByteArray &device) override;
- QAbstractAudioDeviceInfo *createDeviceInfo(const QByteArray &device, QAudio::Mode mode) override;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/coreaudio/coreaudioplugin.mm b/src/plugins/coreaudio/coreaudioplugin.mm
deleted file mode 100644
index ac51b9cd0..000000000
--- a/src/plugins/coreaudio/coreaudioplugin.mm
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "coreaudioplugin.h"
-
-#include "coreaudiodeviceinfo.h"
-#include "coreaudioinput.h"
-#include "coreaudiooutput.h"
-
-QT_BEGIN_NAMESPACE
-
-CoreAudioPlugin::CoreAudioPlugin(QObject *parent)
- : QAudioSystemPlugin(parent)
-{
-}
-
-QByteArray CoreAudioPlugin::defaultDevice(QAudio::Mode mode) const
-{
- return CoreAudioDeviceInfo::defaultDevice(mode);
-}
-
-QList<QByteArray> CoreAudioPlugin::availableDevices(QAudio::Mode mode) const
-{
- return CoreAudioDeviceInfo::availableDevices(mode);
-}
-
-
-QAbstractAudioInput *CoreAudioPlugin::createInput(const QByteArray &device)
-{
- return new CoreAudioInput(device);
-}
-
-
-QAbstractAudioOutput *CoreAudioPlugin::createOutput(const QByteArray &device)
-{
- return new CoreAudioOutput(device);
-}
-
-
-QAbstractAudioDeviceInfo *CoreAudioPlugin::createDeviceInfo(const QByteArray &device, QAudio::Mode mode)
-{
- return new CoreAudioDeviceInfo(device, mode);
-}
-
-QT_END_NAMESPACE
-
-#include "moc_coreaudioplugin.cpp"
diff --git a/src/plugins/coreaudio/coreaudiosessionmanager.h b/src/plugins/coreaudio/coreaudiosessionmanager.h
deleted file mode 100644
index 73ef9f303..000000000
--- a/src/plugins/coreaudio/coreaudiosessionmanager.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef IOSAUDIOSESSIONMANAGER_H
-#define IOSAUDIOSESSIONMANAGER_H
-
-#include <QObject>
-#ifdef QT_DEBUG_COREAUDIO
-# include <QtCore/QDebug>
-#endif
-
-@class CoreAudioSessionObserver;
-
-QT_BEGIN_NAMESPACE
-
-class CoreAudioSessionManager : public QObject
-{
- Q_OBJECT
-public:
- enum AudioSessionCategorys {
- Ambient,
- SoloAmbient,
- Playback,
- Record,
- PlayAndRecord,
- AudioProcessing,
- MultiRoute
- };
- enum AudioSessionCategoryOptions {
- None = 0,
- MixWithOthers = 1,
- DuckOthers = 2,
- AllowBluetooth = 4,
- DefaultToSpeaker = 8
- };
- enum AudioSessionModes {
- Default,
- VoiceChat,
- GameChat,
- VideoRecording,
- Measurement,
- MoviePlayback
- };
-
- static CoreAudioSessionManager& instance();
-
- bool setActive(bool active);
- bool setCategory(AudioSessionCategorys category, AudioSessionCategoryOptions options = None);
- bool setMode(AudioSessionModes mode);
-
- AudioSessionCategorys category();
- AudioSessionModes mode();
-
- QList<QByteArray> inputDevices();
- QList<QByteArray> outputDevices();
-
- float currentIOBufferDuration();
- float preferredSampleRate();
-
-signals:
- void activeChanged();
- void categoryChanged();
- void modeChanged();
- void routeChanged();
- void inputDevicesAvailableChanged();
- void outputDevicesAvailableChanged();
-
-private:
- CoreAudioSessionManager();
- ~CoreAudioSessionManager();
- CoreAudioSessionManager(CoreAudioSessionManager const &copy);
- CoreAudioSessionManager& operator =(CoreAudioSessionManager const &copy);
-
- CoreAudioSessionObserver *m_sessionObserver;
-};
-
-#ifdef QT_DEBUG_COREAUDIO
-QDebug operator <<(QDebug dbg, CoreAudioSessionManager::AudioSessionCategorys category);
-QDebug operator <<(QDebug dbg, CoreAudioSessionManager::AudioSessionCategoryOptions option);
-QDebug operator <<(QDebug dbg, CoreAudioSessionManager::AudioSessionModes mode);
-#endif
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(CoreAudioSessionManager::AudioSessionCategorys)
-Q_DECLARE_METATYPE(CoreAudioSessionManager::AudioSessionCategoryOptions)
-Q_DECLARE_METATYPE(CoreAudioSessionManager::AudioSessionModes)
-
-#endif // IOSAUDIOSESSIONMANAGER_H
diff --git a/src/plugins/coreaudio/coreaudiosessionmanager.mm b/src/plugins/coreaudio/coreaudiosessionmanager.mm
deleted file mode 100644
index 372c49491..000000000
--- a/src/plugins/coreaudio/coreaudiosessionmanager.mm
+++ /dev/null
@@ -1,472 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "coreaudiosessionmanager.h"
-#import <AVFoundation/AVAudioSession.h>
-#import <Foundation/Foundation.h>
-
-QT_BEGIN_NAMESPACE
-
-@interface CoreAudioSessionObserver : NSObject
-{
- CoreAudioSessionManager *m_sessionManager;
- AVAudioSession *m_audioSession;
-}
-
-@property (readonly, getter=sessionManager) CoreAudioSessionManager *m_sessionManager;
-@property (readonly, getter=audioSession) AVAudioSession *m_audioSession;
-
--(CoreAudioSessionObserver *)initWithAudioSessionManager:(CoreAudioSessionManager *)sessionManager;
-
--(BOOL)activateAudio;
--(BOOL)deactivateAudio;
-
-//Notification handlers
--(void)audioSessionInterruption:(NSNotification *)notification;
--(void)audioSessionRouteChange:(NSNotification *)notification;
--(void)audioSessionMediaServicesWereReset:(NSNotification *)notification;
-
-@end //interface CoreAudioSessionObserver
-
-@implementation CoreAudioSessionObserver
-
-@synthesize m_sessionManager, m_audioSession;
-
--(CoreAudioSessionObserver *)initWithAudioSessionManager:(CoreAudioSessionManager *)sessionManager
-{
- if (!(self = [super init]))
- return nil;
-
- self->m_sessionManager = sessionManager;
- self->m_audioSession = [AVAudioSession sharedInstance];
-
- //Set up observers
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(audioSessionInterruption:)
- name:AVAudioSessionInterruptionNotification
- object:self->m_audioSession];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(audioSessionMediaServicesWereReset:)
- name:AVAudioSessionMediaServicesWereResetNotification
- object:self->m_audioSession];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(audioSessionRouteChange:)
- name:AVAudioSessionRouteChangeNotification
- object:self->m_audioSession];
-
- return self;
-}
-
--(void)dealloc
-{
-#ifdef QT_DEBUG_COREAUDIO
- qDebug() << Q_FUNC_INFO;
-#endif
-
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:AVAudioSessionInterruptionNotification
- object:self->m_audioSession];
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:AVAudioSessionMediaServicesWereResetNotification
- object:self->m_audioSession];
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:AVAudioSessionRouteChangeNotification
- object:self->m_audioSession];
-
- [super dealloc];
-}
-
--(BOOL)activateAudio
-{
- NSError *error = nil;
- BOOL success = [self->m_audioSession setActive:YES error:&error];
- if (![self->m_audioSession setActive:YES error:&error]) {
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audio session activation failed: %s", [[error localizedDescription] UTF8String]);
- } else {
- qDebug("audio session activated");
-#endif
- }
-
- return success;
-}
-
--(BOOL)deactivateAudio
-{
- NSError *error = nil;
- BOOL success = [m_audioSession setActive:NO error:&error];
-#ifdef QT_DEBUG_COREAUDIO
- if (!success) {
- qDebug("%s", [[error localizedDescription] UTF8String]);
- }
-#endif
- return success;
-}
-
--(void)audioSessionInterruption:(NSNotification *)notification
-{
- NSNumber *type = [[notification userInfo] valueForKey:AVAudioSessionInterruptionTypeKey];
- if ([type intValue] == AVAudioSessionInterruptionTypeBegan) {
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audioSession Interuption begain");
-#endif
- } else if ([type intValue] == AVAudioSessionInterruptionTypeEnded) {
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audioSession Interuption ended");
-#endif
- NSNumber *option = [[notification userInfo] valueForKey:AVAudioSessionInterruptionOptionKey];
- if ([option intValue] == AVAudioSessionInterruptionOptionShouldResume) {
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audioSession is active and immediately ready to be used.");
-#endif
- } else {
- [self activateAudio];
- }
- }
-}
-
--(void)audioSessionMediaServicesWereReset:(NSNotification *)notification
-{
- Q_UNUSED(notification);
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audioSession Media Services were reset");
-#endif
- //Reactivate audio when this occurs
- [self activateAudio];
-}
-
--(void)audioSessionRouteChange:(NSNotification *)notification
-{
- NSNumber *reason = [[notification userInfo] valueForKey:AVAudioSessionRouteChangeReasonKey];
- NSUInteger reasonEnum = [reason intValue];
-
- if (reasonEnum == AVAudioSessionRouteChangeReasonUnknown) {
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audioSession route changed. reason: unknown");
-#endif
- } else if (reasonEnum == AVAudioSessionRouteChangeReasonNewDeviceAvailable) {
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audioSession route changed. reason: new device available");
-#endif
- } else if (reasonEnum == AVAudioSessionRouteChangeReasonOldDeviceUnavailable) {
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audioSession route changed. reason: old device unavailable");
-#endif
- } else if (reasonEnum == AVAudioSessionRouteChangeReasonCategoryChange) {
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audioSession route changed. reason: category changed");
-#endif
- } else if (reasonEnum == AVAudioSessionRouteChangeReasonOverride) {
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audioSession route changed. reason: override");
-#endif
- } else if (reasonEnum == AVAudioSessionRouteChangeReasonWakeFromSleep) {
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audioSession route changed. reason: woken from sleep");
-#endif
- } else if (reasonEnum == AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory) {
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("audioSession route changed. reason: no suitable route for category");
-#endif
- }
-
-}
-
-@end //implementation CoreAudioSessionObserver
-
-CoreAudioSessionManager::CoreAudioSessionManager() :
- QObject(0)
-{
- m_sessionObserver = [[CoreAudioSessionObserver alloc] initWithAudioSessionManager:this];
-}
-
-CoreAudioSessionManager::~CoreAudioSessionManager()
-{
-#ifdef QT_DEBUG_COREAUDIO
- qDebug() << Q_FUNC_INFO;
-#endif
- [m_sessionObserver release];
-}
-
-
-CoreAudioSessionManager &CoreAudioSessionManager::instance()
-{
- static CoreAudioSessionManager instance;
- return instance;
-}
-
-bool CoreAudioSessionManager::setActive(bool active)
-{
- if (active) {
- return [m_sessionObserver activateAudio];
- } else {
- return [m_sessionObserver deactivateAudio];
- }
-}
-
-bool CoreAudioSessionManager::setCategory(CoreAudioSessionManager::AudioSessionCategorys category, CoreAudioSessionManager::AudioSessionCategoryOptions options)
-{
- NSString *targetCategory = nil;
-
- switch (category) {
- case CoreAudioSessionManager::Ambient:
- targetCategory = AVAudioSessionCategoryAmbient;
- break;
- case CoreAudioSessionManager::SoloAmbient:
- targetCategory = AVAudioSessionCategorySoloAmbient;
- break;
- case CoreAudioSessionManager::Playback:
- targetCategory = AVAudioSessionCategoryPlayback;
- break;
- case CoreAudioSessionManager::Record:
- targetCategory = AVAudioSessionCategoryRecord;
- break;
- case CoreAudioSessionManager::PlayAndRecord:
- targetCategory = AVAudioSessionCategoryPlayAndRecord;
- break;
- case CoreAudioSessionManager::AudioProcessing:
-#ifndef Q_OS_TVOS
- targetCategory = AVAudioSessionCategoryAudioProcessing;
-#endif
- break;
- case CoreAudioSessionManager::MultiRoute:
- targetCategory = AVAudioSessionCategoryMultiRoute;
- break;
- }
-
- if (targetCategory == nil)
- return false;
-
- return [[m_sessionObserver audioSession] setCategory:targetCategory
- withOptions:(AVAudioSessionCategoryOptions)options
- error:nil];
-}
-
-bool CoreAudioSessionManager::setMode(CoreAudioSessionManager::AudioSessionModes mode)
-{
- NSString *targetMode = nil;
- switch (mode) {
- case CoreAudioSessionManager::Default:
- targetMode = AVAudioSessionModeDefault;
- break;
- case CoreAudioSessionManager::VoiceChat:
- targetMode = AVAudioSessionModeVoiceChat;
- break;
- case CoreAudioSessionManager::GameChat:
- targetMode = AVAudioSessionModeGameChat;
- break;
- case CoreAudioSessionManager::VideoRecording:
- targetMode = AVAudioSessionModeVideoRecording;
- break;
- case CoreAudioSessionManager::Measurement:
- targetMode = AVAudioSessionModeMeasurement;
- break;
- case CoreAudioSessionManager::MoviePlayback:
- targetMode = AVAudioSessionModeMoviePlayback;
- break;
- }
-
- if (targetMode == nil)
- return false;
-
- return [[m_sessionObserver audioSession] setMode:targetMode error:nil];
-
-}
-
-CoreAudioSessionManager::AudioSessionCategorys CoreAudioSessionManager::category()
-{
- NSString *category = [[m_sessionObserver audioSession] category];
- AudioSessionCategorys localCategory = Ambient;
-
- if (category == AVAudioSessionCategoryAmbient) {
- localCategory = Ambient;
- } else if (category == AVAudioSessionCategorySoloAmbient) {
- localCategory = SoloAmbient;
- } else if (category == AVAudioSessionCategoryPlayback) {
- localCategory = Playback;
- } else if (category == AVAudioSessionCategoryRecord) {
- localCategory = Record;
- } else if (category == AVAudioSessionCategoryPlayAndRecord) {
- localCategory = PlayAndRecord;
-#ifndef Q_OS_TVOS
- } else if (category == AVAudioSessionCategoryAudioProcessing) {
- localCategory = AudioProcessing;
-#endif
- } else if (category == AVAudioSessionCategoryMultiRoute) {
- localCategory = MultiRoute;
- }
-
- return localCategory;
-}
-
-CoreAudioSessionManager::AudioSessionModes CoreAudioSessionManager::mode()
-{
- NSString *mode = [[m_sessionObserver audioSession] mode];
- AudioSessionModes localMode = Default;
-
- if (mode == AVAudioSessionModeDefault) {
- localMode = Default;
- } else if (mode == AVAudioSessionModeVoiceChat) {
- localMode = VoiceChat;
- } else if (mode == AVAudioSessionModeGameChat) {
- localMode = GameChat;
- } else if (mode == AVAudioSessionModeVideoRecording) {
- localMode = VideoRecording;
- } else if (mode == AVAudioSessionModeMeasurement) {
- localMode = Measurement;
- } else if (mode == AVAudioSessionModeMoviePlayback) {
- localMode = MoviePlayback;
- }
-
- return localMode;
-}
-
-QList<QByteArray> CoreAudioSessionManager::inputDevices()
-{
- //TODO: Add support for USB input devices
- //Right now the default behavior on iOS is to have only one input route
- //at a time.
- QList<QByteArray> inputDevices;
- inputDevices << "default";
- return inputDevices;
-}
-
-QList<QByteArray> CoreAudioSessionManager::outputDevices()
-{
- //TODO: Add support for USB output devices
- //Right now the default behavior on iOS is to have only one output route
- //at a time.
- QList<QByteArray> outputDevices;
- outputDevices << "default";
- return outputDevices;
-}
-
-float CoreAudioSessionManager::currentIOBufferDuration()
-{
- return [[m_sessionObserver audioSession] IOBufferDuration];
-}
-
-float CoreAudioSessionManager::preferredSampleRate()
-{
- return [[m_sessionObserver audioSession] preferredSampleRate];
-}
-
-#ifdef QT_DEBUG_COREAUDIO
-QDebug operator<<(QDebug dbg, CoreAudioSessionManager::AudioSessionCategorys category)
-{
- QDebug output = dbg.nospace();
- switch (category) {
- case CoreAudioSessionManager::Ambient:
- output << "AudioSessionCategoryAmbient";
- break;
- case CoreAudioSessionManager::SoloAmbient:
- output << "AudioSessionCategorySoloAmbient";
- break;
- case CoreAudioSessionManager::Playback:
- output << "AudioSessionCategoryPlayback";
- break;
- case CoreAudioSessionManager::Record:
- output << "AudioSessionCategoryRecord";
- break;
- case CoreAudioSessionManager::PlayAndRecord:
- output << "AudioSessionCategoryPlayAndRecord";
- break;
- case CoreAudioSessionManager::AudioProcessing:
- output << "AudioSessionCategoryAudioProcessing";
- break;
- case CoreAudioSessionManager::MultiRoute:
- output << "AudioSessionCategoryMultiRoute";
- break;
- }
- return output;
-}
-
-QDebug operator<<(QDebug dbg, CoreAudioSessionManager::AudioSessionCategoryOptions option)
-{
- QDebug output = dbg.nospace();
- switch (option) {
- case CoreAudioSessionManager::None:
- output << "AudioSessionCategoryOptionNone";
- break;
- case CoreAudioSessionManager::MixWithOthers:
- output << "AudioSessionCategoryOptionMixWithOthers";
- break;
- case CoreAudioSessionManager::DuckOthers:
- output << "AudioSessionCategoryOptionDuckOthers";
- break;
- case CoreAudioSessionManager::AllowBluetooth:
- output << "AudioSessionCategoryOptionAllowBluetooth";
- break;
- case CoreAudioSessionManager::DefaultToSpeaker:
- output << "AudioSessionCategoryOptionDefaultToSpeaker";
- break;
- }
- return output;
-}
-
-QDebug operator<<(QDebug dbg, CoreAudioSessionManager::AudioSessionModes mode)
-{
- QDebug output = dbg.nospace();
- switch (mode) {
- case CoreAudioSessionManager::Default:
- output << "AudioSessionModeDefault";
- break;
- case CoreAudioSessionManager::VoiceChat:
- output << "AudioSessionModeVoiceChat";
- break;
- case CoreAudioSessionManager::GameChat:
- output << "AudioSessionModeGameChat";
- break;
- case CoreAudioSessionManager::VideoRecording:
- output << "AudioSessionModeVideoRecording";
- break;
- case CoreAudioSessionManager::Measurement:
- output << "AudioSessionModeMeasurement";
- break;
- case CoreAudioSessionManager::MoviePlayback:
- output << "AudioSessionModeMoviePlayback";
- break;
- }
- return output;
-}
-#endif
-
-QT_END_NAMESPACE
-
-#include "moc_coreaudiosessionmanager.cpp"
diff --git a/src/plugins/coreaudio/coreaudioutils.h b/src/plugins/coreaudio/coreaudioutils.h
deleted file mode 100644
index 7b67f9e41..000000000
--- a/src/plugins/coreaudio/coreaudioutils.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef IOSAUDIOUTILS_H
-#define IOSAUDIOUTILS_H
-
-#include <CoreAudio/CoreAudioTypes.h>
-
-#include <QtMultimedia/QAudioFormat>
-#include <QtCore/qglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-class CoreAudioUtils
-{
-public:
- static quint64 currentTime();
- static double frequency();
- static QAudioFormat toQAudioFormat(const AudioStreamBasicDescription& streamFormat);
- static AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& audioFormat);
-
-private:
- static void initialize();
- static double sFrequency;
- static bool sIsInitialized;
-};
-
-class CoreAudioRingBuffer
-{
-public:
- typedef QPair<char*, int> Region;
-
- CoreAudioRingBuffer(int bufferSize);
- ~CoreAudioRingBuffer();
-
- Region acquireReadRegion(int size);
- void releaseReadRegion(Region const& region);
- Region acquireWriteRegion(int size);
- void releaseWriteRegion(Region const& region);
-
- int used() const;
- int free() const;
- int size() const;
-
- void reset();
-
-private:
- int m_bufferSize;
- int m_readPos;
- int m_writePos;
- char* m_buffer;
- QAtomicInt m_bufferUsed;
-};
-
-QT_END_NAMESPACE
-
-#endif // IOSAUDIOUTILS_H
diff --git a/src/plugins/coreaudio/coreaudioutils.mm b/src/plugins/coreaudio/coreaudioutils.mm
deleted file mode 100644
index 1f9b9866c..000000000
--- a/src/plugins/coreaudio/coreaudioutils.mm
+++ /dev/null
@@ -1,198 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "coreaudioutils.h"
-#include <mach/mach_time.h>
-
-QT_BEGIN_NAMESPACE
-
-double CoreAudioUtils::sFrequency = 0.0;
-bool CoreAudioUtils::sIsInitialized = false;
-
-void CoreAudioUtils::initialize()
-{
- struct mach_timebase_info timeBaseInfo;
- mach_timebase_info(&timeBaseInfo);
- sFrequency = static_cast<double>(timeBaseInfo.denom) / static_cast<double>(timeBaseInfo.numer);
- sFrequency *= 1000000000.0;
-
- sIsInitialized = true;
-}
-
-
-quint64 CoreAudioUtils::currentTime()
-{
- return mach_absolute_time();
-}
-
-double CoreAudioUtils::frequency()
-{
- if (!sIsInitialized)
- initialize();
- return sFrequency;
-}
-
-QAudioFormat CoreAudioUtils::toQAudioFormat(AudioStreamBasicDescription const& sf)
-{
- QAudioFormat audioFormat;
-
- audioFormat.setSampleRate(sf.mSampleRate);
- audioFormat.setChannelCount(sf.mChannelsPerFrame);
- audioFormat.setSampleSize(sf.mBitsPerChannel);
- audioFormat.setCodec(QString::fromLatin1("audio/pcm"));
- audioFormat.setByteOrder((sf.mFormatFlags & kAudioFormatFlagIsBigEndian) != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian);
- QAudioFormat::SampleType type = QAudioFormat::UnSignedInt;
- if ((sf.mFormatFlags & kAudioFormatFlagIsSignedInteger) != 0)
- type = QAudioFormat::SignedInt;
- else if ((sf.mFormatFlags & kAudioFormatFlagIsFloat) != 0)
- type = QAudioFormat::Float;
- audioFormat.setSampleType(type);
-
- return audioFormat;
-}
-
-AudioStreamBasicDescription CoreAudioUtils::toAudioStreamBasicDescription(QAudioFormat const& audioFormat)
-{
- AudioStreamBasicDescription sf;
-
- sf.mFormatFlags = kAudioFormatFlagIsPacked;
- sf.mSampleRate = audioFormat.sampleRate();
- sf.mFramesPerPacket = 1;
- sf.mChannelsPerFrame = audioFormat.channelCount();
- sf.mBitsPerChannel = audioFormat.sampleSize();
- sf.mBytesPerFrame = sf.mChannelsPerFrame * (sf.mBitsPerChannel / 8);
- sf.mBytesPerPacket = sf.mFramesPerPacket * sf.mBytesPerFrame;
- sf.mFormatID = kAudioFormatLinearPCM;
-
- switch (audioFormat.sampleType()) {
- case QAudioFormat::SignedInt: sf.mFormatFlags |= kAudioFormatFlagIsSignedInteger; break;
- case QAudioFormat::UnSignedInt: /* default */ break;
- case QAudioFormat::Float: sf.mFormatFlags |= kAudioFormatFlagIsFloat; break;
- case QAudioFormat::Unknown: default: break;
- }
-
- if (audioFormat.byteOrder() == QAudioFormat::BigEndian)
- sf.mFormatFlags |= kAudioFormatFlagIsBigEndian;
-
- return sf;
-}
-
-// QAudioRingBuffer
-CoreAudioRingBuffer::CoreAudioRingBuffer(int bufferSize):
- m_bufferSize(bufferSize)
-{
- m_buffer = new char[m_bufferSize];
- reset();
-}
-
-CoreAudioRingBuffer::~CoreAudioRingBuffer()
-{
- delete[] m_buffer;
-}
-
-CoreAudioRingBuffer::Region CoreAudioRingBuffer::acquireReadRegion(int size)
-{
- const int used = m_bufferUsed.fetchAndAddAcquire(0);
-
- if (used > 0) {
- const int readSize = qMin(size, qMin(m_bufferSize - m_readPos, used));
-
- return readSize > 0 ? Region(m_buffer + m_readPos, readSize) : Region(0, 0);
- }
-
- return Region(0, 0);
-}
-
-void CoreAudioRingBuffer::releaseReadRegion(const CoreAudioRingBuffer::Region &region)
-{
- m_readPos = (m_readPos + region.second) % m_bufferSize;
-
- m_bufferUsed.fetchAndAddRelease(-region.second);
-}
-
-CoreAudioRingBuffer::Region CoreAudioRingBuffer::acquireWriteRegion(int size)
-{
- const int free = m_bufferSize - m_bufferUsed.fetchAndAddAcquire(0);
-
- Region output;
-
- if (free > 0) {
- const int writeSize = qMin(size, qMin(m_bufferSize - m_writePos, free));
- output = writeSize > 0 ? Region(m_buffer + m_writePos, writeSize) : Region(0, 0);
- } else {
- output = Region(0, 0);
- }
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("acquireWriteRegion(%d) free: %d returning Region(%p, %d)", size, free, output.first, output.second);
-#endif
- return output;
-}
-void CoreAudioRingBuffer::releaseWriteRegion(const CoreAudioRingBuffer::Region &region)
-{
- m_writePos = (m_writePos + region.second) % m_bufferSize;
-
- m_bufferUsed.fetchAndAddRelease(region.second);
-#ifdef QT_DEBUG_COREAUDIO
- qDebug("releaseWriteRegion(%p,%d): m_writePos:%d", region.first, region.second, m_writePos);
-#endif
-}
-
-int CoreAudioRingBuffer::used() const
-{
- return m_bufferUsed.loadRelaxed();
-}
-
-int CoreAudioRingBuffer::free() const
-{
- return m_bufferSize - m_bufferUsed.loadRelaxed();
-}
-
-int CoreAudioRingBuffer::size() const
-{
- return m_bufferSize;
-}
-
-void CoreAudioRingBuffer::reset()
-{
- m_readPos = 0;
- m_writePos = 0;
- m_bufferUsed.storeRelaxed(0);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/camera.pri b/src/plugins/directshow/camera/camera.pri
deleted file mode 100644
index 3be1acc49..000000000
--- a/src/plugins/directshow/camera/camera.pri
+++ /dev/null
@@ -1,37 +0,0 @@
-INCLUDEPATH += $$PWD
-
-win32: DEFINES += _CRT_SECURE_NO_WARNINGS
-
-HEADERS += \
- $$PWD/dscameraservice.h \
- $$PWD/dscameracontrol.h \
- $$PWD/dsvideorenderer.h \
- $$PWD/dsvideodevicecontrol.h \
- $$PWD/dsimagecapturecontrol.h \
- $$PWD/dscamerasession.h \
- $$PWD/directshowcameraglobal.h \
- $$PWD/dscameraviewfindersettingscontrol.h \
- $$PWD/dscameraimageprocessingcontrol.h \
- $$PWD/directshowcameraexposurecontrol.h \
- $$PWD/directshowcameracapturedestinationcontrol.h \
- $$PWD/directshowcameracapturebufferformatcontrol.h \
- $$PWD/directshowcamerazoomcontrol.h \
- $$PWD/directshowcameraimageencodercontrol.h
-
-SOURCES += \
- $$PWD/dscameraservice.cpp \
- $$PWD/dscameracontrol.cpp \
- $$PWD/dsvideorenderer.cpp \
- $$PWD/dsvideodevicecontrol.cpp \
- $$PWD/dsimagecapturecontrol.cpp \
- $$PWD/dscamerasession.cpp \
- $$PWD/dscameraviewfindersettingscontrol.cpp \
- $$PWD/dscameraimageprocessingcontrol.cpp \
- $$PWD/directshowcameraexposurecontrol.cpp \
- $$PWD/directshowcameracapturedestinationcontrol.cpp \
- $$PWD/directshowcameracapturebufferformatcontrol.cpp \
- $$PWD/directshowcamerazoomcontrol.cpp \
- $$PWD/directshowcameraimageencodercontrol.cpp
-
-*-msvc*:INCLUDEPATH += $$(DXSDK_DIR)/include
-QMAKE_USE += directshow
diff --git a/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.cpp b/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.cpp
deleted file mode 100644
index cc0a0ad17..000000000
--- a/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowcameracapturebufferformatcontrol.h"
-
-#include "dscamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-DirectShowCameraCaptureBufferFormatControl::DirectShowCameraCaptureBufferFormatControl()
-{
-}
-
-QList<QVideoFrame::PixelFormat> DirectShowCameraCaptureBufferFormatControl::supportedBufferFormats() const
-{
- return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB32;
-}
-
-QVideoFrame::PixelFormat DirectShowCameraCaptureBufferFormatControl::bufferFormat() const
-{
- return QVideoFrame::Format_RGB32;
-}
-
-void DirectShowCameraCaptureBufferFormatControl::setBufferFormat(QVideoFrame::PixelFormat format)
-{
- Q_UNUSED(format);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.h b/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.h
deleted file mode 100644
index cacd3652b..000000000
--- a/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWCAMERACAPTUREBUFFERFORMATCONTROL_H
-#define DIRECTSHOWCAMERACAPTUREBUFFERFORMATCONTROL_H
-
-#include <QtMultimedia/qcameracapturebufferformatcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowCameraCaptureBufferFormatControl : public QCameraCaptureBufferFormatControl
-{
- Q_OBJECT
-public:
- DirectShowCameraCaptureBufferFormatControl();
-
- QList<QVideoFrame::PixelFormat> supportedBufferFormats() const override;
- QVideoFrame::PixelFormat bufferFormat() const override;
- void setBufferFormat(QVideoFrame::PixelFormat format) override;
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWCAMERACAPTUREBUFFERFORMATCONTROL_H
diff --git a/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.cpp b/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.cpp
deleted file mode 100644
index bfb10fc03..000000000
--- a/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowcameracapturedestinationcontrol.h"
-
-#include "dscamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-DirectShowCameraCaptureDestinationControl::DirectShowCameraCaptureDestinationControl(DSCameraSession *session)
- : m_session(session)
-{
- connect(m_session, &DSCameraSession::captureDestinationChanged,
- this, &DirectShowCameraCaptureDestinationControl::captureDestinationChanged);
-}
-
-bool DirectShowCameraCaptureDestinationControl::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const
-{
- return m_session->isCaptureDestinationSupported(destination);
-}
-
-QCameraImageCapture::CaptureDestinations DirectShowCameraCaptureDestinationControl::captureDestination() const
-{
- return m_session->captureDestination();
-}
-
-void DirectShowCameraCaptureDestinationControl::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination)
-{
- m_session->setCaptureDestination(destination);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.h b/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.h
deleted file mode 100644
index 224df9dbc..000000000
--- a/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWCAMERACAPTUREDESTINATIONCONTROL_H
-#define DIRECTSHOWCAMERACAPTUREDESTINATIONCONTROL_H
-
-#include <QtMultimedia/qcameracapturedestinationcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class DSCameraSession;
-
-class DirectShowCameraCaptureDestinationControl : public QCameraCaptureDestinationControl
-{
- Q_OBJECT
-public:
- DirectShowCameraCaptureDestinationControl(DSCameraSession *session);
-
- bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const override;
- QCameraImageCapture::CaptureDestinations captureDestination() const override;
- void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) override;
-
-private:
- DSCameraSession *m_session;
-
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWCAMERACAPTUREDESTINATIONCONTROL_H
diff --git a/src/plugins/directshow/camera/directshowcameraexposurecontrol.cpp b/src/plugins/directshow/camera/directshowcameraexposurecontrol.cpp
deleted file mode 100644
index 6f138450c..000000000
--- a/src/plugins/directshow/camera/directshowcameraexposurecontrol.cpp
+++ /dev/null
@@ -1,413 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowcameraexposurecontrol.h"
-#include "dscamerasession.h"
-#include "directshowglobal.h"
-#include "directshowutils.h"
-
-#include <functional>
-#include <cmath>
-
-QT_BEGIN_NAMESPACE
-
-static qreal convertToSec(long v) { return (v < 0) ? (1 / std::pow(2., qreal(v))) : std::pow(2., qreal(v)); }
-static Q_DECL_CONSTEXPR qreal convertToFvalue(long v) { return qreal(v) / 10.; }
-
-DirectShowCameraExposureControl::DirectShowCameraExposureControl(DSCameraSession *session)
- : m_session(session)
- , m_shutterSpeedValues({ 0, 0, 0, 0, 0 })
- , m_apertureValues({ 0, 0, 0, 0, 0 })
- , m_requestedShutterSpeed(qreal(0.0))
- , m_currentShutterSpeed(qreal(-1.0))
- , m_requestedAperture(qreal(0.0))
- , m_currentAperture(qreal(-1.0))
- , m_requestedExposureMode(QCameraExposure::ExposureAuto)
- , m_currentExposureMode(QCameraExposure::ExposureAuto)
-{
- Q_ASSERT(m_session);
- connect(m_session, &DSCameraSession::statusChanged,
- this, &DirectShowCameraExposureControl::onStatusChanged);
-}
-
-bool DirectShowCameraExposureControl::isParameterSupported(QCameraExposureControl::ExposureParameter parameter) const
-{
- switch (parameter) {
- case QCameraExposureControl::Aperture:
- return (m_apertureValues.caps & CameraControl_Flags_Manual);
- case QCameraExposureControl::ShutterSpeed:
- return (m_shutterSpeedValues.caps & CameraControl_Flags_Manual);
- case QCameraExposureControl::ExposureMode:
- return true;
- default:
- break;
- }
- return false;
-}
-
-QVariantList DirectShowCameraExposureControl::supportedParameterRange(QCameraExposureControl::ExposureParameter parameter,
- bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- if (parameter == ShutterSpeed)
- return m_supportedShutterSpeeds;
-
- if (parameter == Aperture)
- return m_supportedApertureValues;
-
- if (parameter == ExposureMode)
- return m_supportedExposureModes;
-
- return QVariantList();
-}
-
-QVariant DirectShowCameraExposureControl::requestedValue(QCameraExposureControl::ExposureParameter parameter) const
-{
- if (parameter == ShutterSpeed)
- return QVariant::fromValue(m_requestedShutterSpeed);
-
- if (parameter == Aperture)
- return QVariant::fromValue(m_requestedAperture);
-
- if (parameter == ExposureMode)
- return QVariant::fromValue(m_requestedExposureMode);
-
- return QVariant();
-}
-
-QVariant DirectShowCameraExposureControl::actualValue(QCameraExposureControl::ExposureParameter parameter) const
-{
- if (parameter == ExposureMode)
- return QVariant::fromValue(m_currentExposureMode);
-
- if (parameter == ShutterSpeed) {
- return qFuzzyCompare(m_currentShutterSpeed, qreal(-1.0))
- ? QVariant()
- : QVariant::fromValue(m_currentShutterSpeed);
- }
-
- if (parameter == Aperture) {
- return qFuzzyCompare(m_currentAperture, qreal(-1.0))
- ? QVariant()
- : QVariant::fromValue(m_currentAperture);
- }
-
- return QVariant();
-}
-
-bool DirectShowCameraExposureControl::setValue(QCameraExposureControl::ExposureParameter parameter,
- const QVariant &value)
-{
- IAMCameraControl *cameraControl = nullptr;
- const DirectShowUtils::ScopedSafeRelease<IAMCameraControl> rControl { &cameraControl };
- if (!m_session->getCameraControlInterface(&cameraControl))
- return false;
-
- // Reset exposure mode if the value is invalid.
- if (!value.isValid()) {
- m_requestedExposureMode = QCameraExposure::ExposureAuto;
- return setExposureMode(cameraControl, m_requestedExposureMode);
- }
-
- if (parameter == ShutterSpeed || parameter == Aperture) {
- bool ok = false;
- const qreal newValue = value.toReal(&ok);
- if (!ok)
- return false;
-
- // Change the exposure mode first
- setExposureMode(cameraControl, QCameraExposure::ExposureManual);
-
- if (parameter == ShutterSpeed) {
- m_requestedShutterSpeed = newValue;
- return setShutterSpeed(cameraControl, m_requestedShutterSpeed);
- }
- m_requestedAperture = newValue;
- return setAperture(cameraControl, m_requestedAperture);
- }
-
- if (parameter == ExposureMode) {
- m_requestedExposureMode = value.value<QCameraExposure::ExposureMode>();
- return setExposureMode(cameraControl, m_requestedExposureMode);
- }
-
- return false;
-}
-
-void DirectShowCameraExposureControl::onStatusChanged(QCamera::Status status)
-{
- const bool shouldUpdate = (qFuzzyCompare(m_currentAperture, qreal(-1.0)) && qFuzzyCompare(m_currentShutterSpeed, qreal(-1.0)));
-
- if (status == QCamera::LoadedStatus && shouldUpdate)
- updateExposureSettings();
-
- if (status == QCamera::UnloadedStatus) {
- m_supportedApertureValues.clear();
- m_supportedExposureModes.clear();
- m_supportedShutterSpeeds.clear();
- m_currentAperture = qreal(-1.0);
- m_currentShutterSpeed = qreal(-1.0);
- m_currentExposureMode = QCameraExposure::ExposureAuto;
- }
-}
-
-void DirectShowCameraExposureControl::updateExposureSettings()
-{
- IAMCameraControl *cameraControl = nullptr;
- const DirectShowUtils::ScopedSafeRelease<IAMCameraControl> rControl { &cameraControl };
- if (!m_session->getCameraControlInterface(&cameraControl))
- return;
-
- const auto updateValues = [cameraControl](long property,
- ExposureValues &currentValues,
- QVariantList &parameterRange,
- const std::function<qreal(long)> &converter,
- bool *changed) -> bool {
- ExposureValues values { 0, 0, 0, 0, 0 };
- if (FAILED(cameraControl->GetRange(property,
- &values.minValue,
- &values.maxValue,
- &values.stepping,
- &values.defaultValue,
- &values.caps))) {
- return false;
- }
-
- const bool minValueChanged = values.minValue != currentValues.minValue;
- const bool maxValueChanged = values.maxValue != currentValues.maxValue;
- const bool steppingChanged = values.stepping != currentValues.stepping;
-
- if (minValueChanged || maxValueChanged || steppingChanged) {
- parameterRange.clear();
- long nextValue = values.minValue;
- while (nextValue != values.maxValue && values.stepping != 0) {
- parameterRange << converter(nextValue);
- nextValue += values.stepping;
- }
-
- if (changed)
- *changed = true;
- }
-
- currentValues = values;
- return true;
- };
-
- const auto getCurrentValue = [cameraControl](long property, const std::function<qreal(long)> &converter, qreal *value) -> bool {
- long currentValue;
- long currentFlags;
- if (FAILED(cameraControl->Get(property, &currentValue, &currentFlags)))
- return false;
-
- *value = converter(currentValue);
- return true;
- };
-
- // Shutter speed
- bool changed = false;
- if (!updateValues(CameraControl_Exposure, m_shutterSpeedValues, m_supportedShutterSpeeds, convertToSec, &changed))
- qCDebug(qtDirectShowPlugin, "Unable to update the shutter speed values");
-
- if (changed)
- Q_EMIT parameterRangeChanged(int(ShutterSpeed));
-
- if ((m_shutterSpeedValues.caps & CameraControl_Flags_Manual)) {
- if (getCurrentValue(CameraControl_Exposure, convertToSec, &m_currentShutterSpeed)) {
- if (m_currentExposureMode == QCameraExposure::ExposureManual)
- setShutterSpeed(cameraControl, m_requestedShutterSpeed);
- } else {
- m_currentShutterSpeed = qreal(-1.0);
- qCDebug(qtDirectShowPlugin, "Unable to get the current shutter speed!");
- }
- }
-
- // Aperture
- changed = false;
- if (!updateValues(CameraControl_Iris, m_apertureValues, m_supportedApertureValues, convertToFvalue, &changed))
- qCDebug(qtDirectShowPlugin, "Unable to update the aperture values");
-
- if (changed)
- Q_EMIT parameterRangeChanged(int(Aperture));
-
- if (getCurrentValue(CameraControl_Iris, convertToFvalue, &m_currentAperture)) {
- if (m_currentExposureMode == QCameraExposure::ExposureManual)
- setAperture(cameraControl, m_requestedAperture);
- } else {
- m_currentAperture = qreal(-1.0);
- qCDebug(qtDirectShowPlugin, "Unable to get the current aperture value!");
- }
-
- // Update exposure modes
- const bool hasAutoExposure = (m_apertureValues.caps & CameraControl_Flags_Auto)
- || (m_shutterSpeedValues.caps & CameraControl_Flags_Auto);
- const bool hasManualExposure = (m_apertureValues.caps & CameraControl_Flags_Manual)
- || (m_shutterSpeedValues.caps & CameraControl_Flags_Manual);
-
- QVariantList exposureModes;
- if (hasAutoExposure && !m_supportedExposureModes.contains(QVariant::fromValue(QCameraExposure::ExposureAuto)))
- exposureModes << QVariant::fromValue(QCameraExposure::ExposureAuto);
-
- if (hasManualExposure && !m_supportedExposureModes.contains(QVariant::fromValue(QCameraExposure::ExposureManual)))
- exposureModes << QVariant::fromValue(QCameraExposure::ExposureManual);
-
- if (!exposureModes.isEmpty() || !m_supportedExposureModes.isEmpty()) {
- m_supportedExposureModes = exposureModes;
- Q_EMIT parameterRangeChanged(int(ExposureMode));
- }
-}
-
-bool DirectShowCameraExposureControl::setShutterSpeed(IAMCameraControl *cameraControl, qreal shutterSpeed)
-{
- if (m_currentExposureMode != QCameraExposure::ExposureManual) {
- qCDebug(qtDirectShowPlugin, "Trying to set shutter speed value while in auto exposure mode!");
- return false;
- }
-
- if (qFuzzyCompare(m_currentShutterSpeed, shutterSpeed))
- return true;
-
- if ((m_shutterSpeedValues.caps & CameraControl_Flags_Manual) == 0)
- return false;
-
- if (!m_supportedShutterSpeeds.contains(QVariant::fromValue(shutterSpeed)))
- return false;
-
- if (qFuzzyIsNull(shutterSpeed) || (shutterSpeed < qreal(0.0)))
- return false;
-
- const long newValue = long(log2(shutterSpeed));
- if (FAILED(cameraControl->Set(CameraControl_Exposure, newValue, CameraControl_Flags_Manual))) {
- qCDebug(qtDirectShowPlugin, "Unable to set shutter speed value to: %d", int(shutterSpeed));
- return false;
- }
-
- m_currentShutterSpeed = shutterSpeed;
- Q_EMIT actualValueChanged(int(ShutterSpeed));
- return true;
-}
-
-bool DirectShowCameraExposureControl::setAperture(IAMCameraControl *cameraControl, qreal aperture)
-{
- if (m_currentExposureMode != QCameraExposure::ExposureManual) {
- qCDebug(qtDirectShowPlugin, "Trying to set aperture value while in auto exposure mode!");
- return false;
- }
-
- if (qFuzzyCompare(m_currentAperture, aperture))
- return true;
-
- if ((m_apertureValues.caps & CameraControl_Flags_Manual) == 0)
- return false;
-
- if (!m_supportedApertureValues.contains(QVariant::fromValue(aperture)))
- return false;
-
- if (aperture < qreal(0.0))
- return false;
-
- const long newValue = long(10 * aperture);
- if (FAILED(cameraControl->Set(CameraControl_Iris, newValue, CameraControl_Flags_Manual))) {
- qCDebug(qtDirectShowPlugin, "Unable to set aperture value to: %d", int(aperture));
- return false;
- }
-
- m_currentAperture = aperture;
- Q_EMIT actualValueChanged(int(Aperture));
-
- return true;
-}
-
-bool DirectShowCameraExposureControl::setExposureMode(IAMCameraControl *cameraControl, QCameraExposure::ExposureMode mode)
-{
- if (m_currentExposureMode == mode)
- return true;
-
- bool exposureModeChanged = true;
-
- // Set auto exposure mode
- if (mode == QCameraExposure::ExposureAuto) {
- if ((m_apertureValues.caps & CameraControl_Flags_Auto)
- && FAILED(cameraControl->Set(CameraControl_Iris, 0, CameraControl_Flags_Auto))) {
- qCDebug(qtDirectShowPlugin, "Setting auto exposure mode failed!");
- exposureModeChanged = false;
- }
-
- if ((m_shutterSpeedValues.caps & CameraControl_Flags_Auto)
- && FAILED(cameraControl->Set(CameraControl_Exposure, 0, CameraControl_Flags_Auto))) {
- qCDebug(qtDirectShowPlugin, "Setting auto exposure mode failed");
- exposureModeChanged = false;
- }
-
- if (exposureModeChanged) {
- m_currentExposureMode = mode;
- Q_EMIT actualValueChanged(int(ExposureMode));
- }
-
- return exposureModeChanged;
- }
-
- // Change the current exposure mode to manual first.
- m_currentExposureMode = QCameraExposure::ExposureManual;
-
- const qreal newShutterSpeed = qFuzzyCompare(m_requestedShutterSpeed, -1.0)
- ? convertToSec(m_shutterSpeedValues.defaultValue)
- : m_requestedShutterSpeed;
- if ((m_shutterSpeedValues.caps & CameraControl_Flags_Manual))
- setShutterSpeed(cameraControl, newShutterSpeed);
-
- const qreal newAperture = qFuzzyCompare(m_requestedAperture, -1.0)
- ? convertToFvalue(m_apertureValues.defaultValue)
- : m_requestedAperture;
- if ((m_apertureValues.caps & CameraControl_Flags_Manual))
- setAperture(cameraControl, newAperture);
-
-
- // Check if any of the values changed.
- exposureModeChanged = (qFuzzyCompare(m_currentShutterSpeed, newShutterSpeed)
- || qFuzzyCompare(m_currentAperture, newAperture));
-
- if (exposureModeChanged)
- Q_EMIT actualValueChanged(int(ExposureMode));
-
- return exposureModeChanged;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/directshowcameraexposurecontrol.h b/src/plugins/directshow/camera/directshowcameraexposurecontrol.h
deleted file mode 100644
index db3fc5984..000000000
--- a/src/plugins/directshow/camera/directshowcameraexposurecontrol.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWCAMERAEXPOSURECONTROL_H
-#define DIRECTSHOWCAMERAEXPOSURECONTROL_H
-
-#include <QtMultimedia/qcameraexposurecontrol.h>
-
-struct IAMCameraControl;
-
-QT_BEGIN_NAMESPACE
-
-class DSCameraSession;
-
-class DirectShowCameraExposureControl : public QCameraExposureControl
-{
- Q_OBJECT
-public:
- DirectShowCameraExposureControl(DSCameraSession *session);
-
- bool isParameterSupported(ExposureParameter parameter) const override;
- QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const override;
- QVariant requestedValue(ExposureParameter parameter) const override;
- QVariant actualValue(ExposureParameter parameter) const override;
- bool setValue(ExposureParameter parameter, const QVariant &value) override;
-
-private Q_SLOTS:
- void onStatusChanged(QCamera::Status status);
-
-private:
- DSCameraSession *m_session;
-
- struct ExposureValues
- {
- long caps;
- long minValue;
- long maxValue;
- long stepping;
- long defaultValue;
- } m_shutterSpeedValues, m_apertureValues;
-
- qreal m_requestedShutterSpeed;
- qreal m_currentShutterSpeed;
-
- qreal m_requestedAperture;
- qreal m_currentAperture;
-
- QVariantList m_supportedShutterSpeeds;
- QVariantList m_supportedApertureValues;
- QVariantList m_supportedExposureModes;
-
- QCameraExposure::ExposureMode m_requestedExposureMode;
- QCameraExposure::ExposureMode m_currentExposureMode;
-
- void updateExposureSettings();
-
- bool setShutterSpeed(IAMCameraControl *cameraControl, qreal shutterSpeed);
- bool setAperture(IAMCameraControl *cameraControl, qreal aperture);
- bool setExposureMode(IAMCameraControl *cameraControl, QCameraExposure::ExposureMode mode);
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWCAMERAEXPOSURECONTROL_H
diff --git a/src/plugins/directshow/camera/directshowcameraglobal.h b/src/plugins/directshow/camera/directshowcameraglobal.h
deleted file mode 100644
index 917ae2dc7..000000000
--- a/src/plugins/directshow/camera/directshowcameraglobal.h
+++ /dev/null
@@ -1,231 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWCAMERAGLOBAL_H
-#define DIRECTSHOWCAMERAGLOBAL_H
-
-#include <QtCore/qglobal.h>
-
-#include <dshow.h>
-
-extern const GUID MEDIASUBTYPE_RGB24;
-extern const GUID MEDIASUBTYPE_RGB32;
-extern const GUID MEDIASUBTYPE_YUY2;
-extern const GUID MEDIASUBTYPE_MJPG;
-extern const GUID MEDIASUBTYPE_RGB555;
-extern const GUID MEDIASUBTYPE_YVU9;
-extern const GUID MEDIASUBTYPE_UYVY;
-extern const GUID PIN_CATEGORY_CAPTURE;
-extern const GUID PIN_CATEGORY_PREVIEW;
-
-extern const IID IID_IPropertyBag;
-extern const IID IID_ISampleGrabber;
-extern const IID IID_ICaptureGraphBuilder2;
-extern const IID IID_IAMStreamConfig;
-
-
-extern const CLSID CLSID_CVidCapClassManager;
-extern const CLSID CLSID_VideoInputDeviceCategory;
-extern const CLSID CLSID_SampleGrabber;
-extern const CLSID CLSID_CaptureGraphBuilder2;
-
-#define SAFE_RELEASE(x) { if (x) x->Release(); x = nullptr; }
-
-typedef struct IFileSinkFilter *LPFILESINKFILTER;
-typedef struct IAMCopyCaptureFileProgress *LPAMCOPYCAPTUREFILEPROGRESS;
-
-#ifndef __ICaptureGraphBuilder2_INTERFACE_DEFINED__
-#define __ICaptureGraphBuilder2_INTERFACE_DEFINED__
-struct ICaptureGraphBuilder2 : public IUnknown
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE SetFiltergraph(
- /* [in] */ IGraphBuilder *pfg) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE GetFiltergraph(
- /* [out] */ IGraphBuilder **ppfg) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE SetOutputFileName(
- /* [in] */ const GUID *pType,
- /* [in] */ LPCOLESTR lpstrFile,
- /* [out] */ IBaseFilter **ppf,
- /* [out] */ IFileSinkFilter **ppSink) = 0;
-
- virtual /* [local] */ HRESULT STDMETHODCALLTYPE FindInterface(
- /* [in] */ const GUID *pCategory,
- /* [in] */ const GUID *pType,
- /* [in] */ IBaseFilter *pf,
- /* [in] */ REFIID riid,
- /* [out] */ void **ppint) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE RenderStream(
- /* [in] */ const GUID *pCategory,
- /* [in] */ const GUID *pType,
- /* [in] */ IUnknown *pSource,
- /* [in] */ IBaseFilter *pfCompressor,
- /* [in] */ IBaseFilter *pfRenderer) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE ControlStream(
- /* [in] */ const GUID *pCategory,
- /* [in] */ const GUID *pType,
- /* [in] */ IBaseFilter *pFilter,
- /* [in] */ REFERENCE_TIME *pstart,
- /* [in] */ REFERENCE_TIME *pstop,
- /* [in] */ WORD wStartCookie,
- /* [in] */ WORD wStopCookie) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE AllocCapFile(
- /* [in] */ LPCOLESTR lpstr,
- /* [in] */ DWORDLONG dwlSize) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE CopyCaptureFile(
- /* [in] */ LPOLESTR lpwstrOld,
- /* [in] */ LPOLESTR lpwstrNew,
- /* [in] */ int fAllowEscAbort,
- /* [in] */ IAMCopyCaptureFileProgress *pCallback) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE FindPin(
- /* [in] */ IUnknown *pSource,
- /* [in] */ PIN_DIRECTION pindir,
- /* [in] */ const GUID *pCategory,
- /* [in] */ const GUID *pType,
- /* [in] */ BOOL fUnconnected,
- /* [in] */ int num,
- /* [out] */ IPin **ppPin) = 0;
-
-};
-#endif
-
-#ifndef __IAMStreamConfig_INTERFACE_DEFINED__
-#define __IAMStreamConfig_INTERFACE_DEFINED__
-struct IAMStreamConfig : public IUnknown
-{
-public:
- virtual HRESULT STDMETHODCALLTYPE SetFormat(
- /* [in] */ AM_MEDIA_TYPE *pmt) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE GetFormat(
- /* [out] */ AM_MEDIA_TYPE **ppmt) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE GetNumberOfCapabilities(
- /* [out] */ int *piCount,
- /* [out] */ int *piSize) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE GetStreamCaps(
- /* [in] */ int iIndex,
- /* [out] */ AM_MEDIA_TYPE **ppmt,
- /* [out] */ BYTE *pSCC) = 0;
-
-};
-#endif
-
-#ifndef __IErrorLog_INTERFACE_DEFINED__
-#define __IErrorLog_INTERFACE_DEFINED__
-struct IErrorLog : public IUnknown
- {
- public:
- virtual HRESULT STDMETHODCALLTYPE AddError(
- /* [in] */ LPCOLESTR pszPropName,
- /* [in] */ EXCEPINFO *pExcepInfo) = 0;
-
- };
-#endif
-
-#ifndef __IPropertyBag_INTERFACE_DEFINED__
-#define __IPropertyBag_INTERFACE_DEFINED__
-struct IPropertyBag : public IUnknown
-{
-public:
- virtual /* [local] */ HRESULT STDMETHODCALLTYPE Read(
- /* [in] */ LPCOLESTR pszPropName,
- /* [out][in] */ VARIANT *pVar,
- /* [in] */ IErrorLog *pErrorLog) = 0;
-
- virtual HRESULT STDMETHODCALLTYPE Write(
- /* [in] */ LPCOLESTR pszPropName,
- /* [in] */ VARIANT *pVar) = 0;
-
-};
-#endif
-
-typedef struct IMediaSample *LPMEDIASAMPLE;
-
-EXTERN_C const IID IID_ISampleGrabberCB;
-
-#ifndef __ISampleGrabberCB_INTERFACE_DEFINED__
-#define __ISampleGrabberCB_INTERFACE_DEFINED__
-
-#undef INTERFACE
-#define INTERFACE ISampleGrabberCB
-DECLARE_INTERFACE_(ISampleGrabberCB, IUnknown)
-{
-// STDMETHOD(QueryInterface) (THIS_ const GUID *, void **) PURE;
- STDMETHOD(QueryInterface) (THIS_ REFIID riid, void **) PURE;
- STDMETHOD_(ULONG, AddRef) (THIS) PURE;
- STDMETHOD_(ULONG, Release) (THIS) PURE;
- STDMETHOD_(HRESULT, SampleCB) (THIS_ double, LPMEDIASAMPLE) PURE;
- STDMETHOD_(HRESULT, BufferCB) (THIS_ double, BYTE *, long) PURE;
-};
-#undef INTERFACE
-
-#endif
-
-
-#ifndef __ISampleGrabber_INTERFACE_DEFINED__
-#define __ISampleGrabber_INTERFACE_DEFINED__
-
-#define INTERFACE ISampleGrabber
-DECLARE_INTERFACE_(ISampleGrabber,IUnknown)
-{
- STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
- STDMETHOD_(ULONG,AddRef)(THIS) PURE;
- STDMETHOD_(ULONG,Release)(THIS) PURE;
- STDMETHOD(SetOneShot)(THIS_ BOOL) PURE;
- STDMETHOD(SetMediaType)(THIS_ const AM_MEDIA_TYPE*) PURE;
- STDMETHOD(GetConnectedMediaType)(THIS_ AM_MEDIA_TYPE*) PURE;
- STDMETHOD(SetBufferSamples)(THIS_ BOOL) PURE;
- STDMETHOD(GetCurrentBuffer)(THIS_ long*,long*) PURE;
- STDMETHOD(GetCurrentSample)(THIS_ IMediaSample**) PURE;
- STDMETHOD(SetCallback)(THIS_ ISampleGrabberCB *,long) PURE;
-};
-#undef INTERFACE
-#endif
-
-
-#endif
diff --git a/src/plugins/directshow/camera/directshowcameraimageencodercontrol.cpp b/src/plugins/directshow/camera/directshowcameraimageencodercontrol.cpp
deleted file mode 100644
index 912f67a2d..000000000
--- a/src/plugins/directshow/camera/directshowcameraimageencodercontrol.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowcameraimageencodercontrol.h"
-#include "dscamerasession.h"
-#include <QImageWriter>
-
-QT_BEGIN_NAMESPACE
-
-DirectShowCameraImageEncoderControl::DirectShowCameraImageEncoderControl(DSCameraSession *session)
- : QImageEncoderControl(session)
- , m_session(session)
-{
-}
-
-QList<QSize> DirectShowCameraImageEncoderControl::supportedResolutions(const QImageEncoderSettings &settings, bool *continuous) const
-{
- QList<QSize> res;
- if (!settings.codec().isEmpty() && !supportedImageCodecs().contains(settings.codec(), Qt::CaseInsensitive))
- return res;
-
- QList<QSize> resolutions = m_session->supportedResolutions(continuous);
- QSize r = settings.resolution();
- if (!r.isValid())
- return resolutions;
-
- if (resolutions.contains(r))
- res << settings.resolution();
-
- return res;
-}
-
-QStringList DirectShowCameraImageEncoderControl::supportedImageCodecs() const
-{
- QStringList supportedCodecs;
- for (const QByteArray &type: QImageWriter::supportedImageFormats()) {
- supportedCodecs << type;
- }
-
- return supportedCodecs;
-}
-
-QString DirectShowCameraImageEncoderControl::imageCodecDescription(const QString &codecName) const
-{
- Q_UNUSED(codecName);
- return QString();
-}
-
-QImageEncoderSettings DirectShowCameraImageEncoderControl::imageSettings() const
-{
- return m_session->imageEncoderSettings();
-}
-
-void DirectShowCameraImageEncoderControl::setImageSettings(const QImageEncoderSettings &settings)
-{
- m_session->setImageEncoderSettings(settings);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/directshowcameraimageencodercontrol.h b/src/plugins/directshow/camera/directshowcameraimageencodercontrol.h
deleted file mode 100644
index 6891bea77..000000000
--- a/src/plugins/directshow/camera/directshowcameraimageencodercontrol.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWCAMERAIMAGEENCODERCONTROL_H
-#define DIRECTSHOWCAMERAIMAGEENCODERCONTROL_H
-
-#include <qimageencodercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class DSCameraSession;
-class DirectShowCameraImageEncoderControl : public QImageEncoderControl
-{
- Q_OBJECT
-public:
- DirectShowCameraImageEncoderControl(DSCameraSession *session);
-
- QList<QSize> supportedResolutions(
- const QImageEncoderSettings &settings = QImageEncoderSettings(),
- bool *continuous = nullptr) const override;
-
- QStringList supportedImageCodecs() const override;
- QString imageCodecDescription(const QString &formatName) const override;
-
- QImageEncoderSettings imageSettings() const override;
- void setImageSettings(const QImageEncoderSettings &settings) override;
-
-private:
- DSCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWCAMERAIMAGEENCODERCONTROL_H
diff --git a/src/plugins/directshow/camera/directshowcamerazoomcontrol.cpp b/src/plugins/directshow/camera/directshowcamerazoomcontrol.cpp
deleted file mode 100644
index 079976e15..000000000
--- a/src/plugins/directshow/camera/directshowcamerazoomcontrol.cpp
+++ /dev/null
@@ -1,209 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowcamerazoomcontrol.h"
-#include "dscamerasession.h"
-#include "directshowutils.h"
-
-QT_BEGIN_NAMESPACE
-
-inline static qreal defaultZoomValue() { return qreal(1.0); }
-
-DirectShowCameraZoomControl::DirectShowCameraZoomControl(DSCameraSession *session)
- : m_session(session)
- , m_opticalZoom({0, 0, 0, 0, 0})
- , m_currentOpticalZoom(qreal(0.0))
- , m_requestedOpticalZoom(qreal(0.0))
- , m_maxOpticalZoom(qreal(1.0))
-{
- Q_ASSERT(m_session);
- connect(m_session, &DSCameraSession::statusChanged,
- this, &DirectShowCameraZoomControl::onStatusChanged);
-}
-
-qreal DirectShowCameraZoomControl::maximumOpticalZoom() const
-{
- return m_maxOpticalZoom;
-}
-
-qreal DirectShowCameraZoomControl::maximumDigitalZoom() const
-{
- return defaultZoomValue();
-}
-
-qreal DirectShowCameraZoomControl::requestedOpticalZoom() const
-{
- return qMax(defaultZoomValue(), m_requestedOpticalZoom);
-}
-
-qreal DirectShowCameraZoomControl::requestedDigitalZoom() const
-{
- return defaultZoomValue();
-}
-
-qreal DirectShowCameraZoomControl::currentOpticalZoom() const
-{
- return qMax(defaultZoomValue(), m_currentOpticalZoom);
-}
-
-qreal DirectShowCameraZoomControl::currentDigitalZoom() const
-{
- return defaultZoomValue();
-}
-
-void DirectShowCameraZoomControl::zoomTo(qreal optical, qreal digital)
-{
- Q_UNUSED(digital);
- if (!(m_opticalZoom.caps & CameraControl_Flags_Manual))
- return;
-
- if (qFuzzyCompare(optical, m_requestedOpticalZoom))
- return;
-
- m_requestedOpticalZoom = optical;
- Q_EMIT requestedOpticalZoomChanged(m_requestedOpticalZoom);
-
- if (qFuzzyCompare(m_requestedOpticalZoom, m_currentOpticalZoom))
- return;
-
- if (m_session->status() != QCamera::LoadedStatus && m_session->status() != QCamera::ActiveStatus)
- return; // We'll wait until the camera is loaded, see: statusChanged connection
-
- opticalZoomToPrivate(optical);
-}
-
-void DirectShowCameraZoomControl::onStatusChanged(QCamera::Status status)
-{
- if (status == QCamera::LoadedStatus) {
- updateZoomValues();
- } else if (status == QCamera::UnloadedStatus) {
- SecureZeroMemory(&m_opticalZoom, sizeof(ZoomValues));
- m_currentOpticalZoom = qreal(0.0);
- m_requestedOpticalZoom = qreal(0.0);
- }
-
-}
-
-void DirectShowCameraZoomControl::updateZoomValues()
-{
- IAMCameraControl *cameraControl = nullptr;
- const DirectShowUtils::ScopedSafeRelease<IAMCameraControl> rControl { &cameraControl };
- if (!m_session->getCameraControlInterface(&cameraControl))
- return;
-
- ZoomValues values { 0, 0, 0, 0, 0 };
- // Zoom levels in DS are in the range [10, 600]
- // The default zoom is device specific.
- HRESULT hr = cameraControl->GetRange(CameraControl_Zoom,
- &values.minZoom,
- &values.maxZoom,
- &values.stepping,
- &values.defaultZoom,
- &values.caps);
-
- if (FAILED(hr)) {
- qCDebug(qtDirectShowPlugin, "Getting the camera's zoom properties failed");
- SecureZeroMemory(&m_opticalZoom, sizeof(ZoomValues));
- return;
- }
-
- if (!(values.caps & CameraControl_Flags_Manual)) {
- qCDebug(qtDirectShowPlugin, "Camera does not support manual zoom");
- SecureZeroMemory(&m_opticalZoom, sizeof(ZoomValues));
- return;
- }
-
- if (values.maxZoom != m_opticalZoom.maxZoom) {
- const qreal newMaxZoomScale = (values.minZoom == 0) ? defaultZoomValue()
- : (qreal(values.maxZoom) / qreal(values.minZoom));
- if (!qFuzzyCompare(newMaxZoomScale, m_maxOpticalZoom)) {
- m_maxOpticalZoom = newMaxZoomScale;
- Q_EMIT maximumOpticalZoomChanged(m_maxOpticalZoom);
- }
- }
-
- m_opticalZoom = values;
-
- long currentZoom = 0;
- long flags = 0;
- if (FAILED(cameraControl->Get(CameraControl_Zoom, &currentZoom, &flags))) {
- qCDebug(qtDirectShowPlugin, "Getting the camera's current zoom value failed!");
- return;
- }
-
- qreal currentOpticalZoom = (m_opticalZoom.minZoom == 0) ? defaultZoomValue()
- : (qreal(currentZoom) / qreal(m_opticalZoom.minZoom));
- currentOpticalZoom = qMax(defaultZoomValue(), currentOpticalZoom);
- if (!qFuzzyCompare(m_currentOpticalZoom, currentOpticalZoom)) {
- m_currentOpticalZoom = currentOpticalZoom;
- Q_EMIT currentOpticalZoomChanged(m_currentOpticalZoom);
- }
-
- // Check if there is a pending zoom value.
- if (!qFuzzyCompare(m_currentOpticalZoom, m_requestedOpticalZoom) && !qFuzzyIsNull(m_requestedOpticalZoom))
- opticalZoomToPrivate(m_requestedOpticalZoom);
-}
-
-bool DirectShowCameraZoomControl::opticalZoomToPrivate(qreal scaleFactor)
-{
- IAMCameraControl *cameraControl = nullptr;
- const DirectShowUtils::ScopedSafeRelease<IAMCameraControl> rControl { &cameraControl };
- if (!m_session->getCameraControlInterface(&cameraControl))
- return false;
-
- // Convert to DS zoom value
- const int newDSOpticalZoom = qRound(m_opticalZoom.minZoom * scaleFactor);
- long newDSOpticalZoomAdjusted = newDSOpticalZoom - (newDSOpticalZoom % m_opticalZoom.stepping);
- newDSOpticalZoomAdjusted = qBound(m_opticalZoom.minZoom, newDSOpticalZoomAdjusted, m_opticalZoom.maxZoom);
-
- if (FAILED(cameraControl->Set(CameraControl_Zoom, newDSOpticalZoomAdjusted, CameraControl_Flags_Manual))) {
- qCDebug(qtDirectShowPlugin, "Setting the camera's zoom value failed");
- return false;
- }
-
- const qreal newScaleFactor = (m_opticalZoom.minZoom == 0) ? defaultZoomValue()
- : (qreal(newDSOpticalZoomAdjusted) / qreal(m_opticalZoom.minZoom));
- // convert back to Qt scale value
- m_currentOpticalZoom = qMax(defaultZoomValue(), newScaleFactor);
- Q_EMIT currentOpticalZoomChanged(m_currentOpticalZoom);
-
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/directshowcamerazoomcontrol.h b/src/plugins/directshow/camera/directshowcamerazoomcontrol.h
deleted file mode 100644
index f6fb05b0e..000000000
--- a/src/plugins/directshow/camera/directshowcamerazoomcontrol.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWCAMERAZOOMCONTROL_H
-#define DIRECTSHOWCAMERAZOOMCONTROL_H
-
-#include <QtMultimedia/qcamerazoomcontrol.h>
-#include <QtMultimedia/qcamera.h>
-
-QT_BEGIN_NAMESPACE
-
-class DSCameraSession;
-
-class DirectShowCameraZoomControl : public QCameraZoomControl
-{
- Q_OBJECT
-public:
- DirectShowCameraZoomControl(DSCameraSession *session);
-
- qreal maximumOpticalZoom() const override;
- qreal maximumDigitalZoom() const override;
- qreal requestedOpticalZoom() const override;
- qreal requestedDigitalZoom() const override;
- qreal currentOpticalZoom() const override;
- qreal currentDigitalZoom() const override;
- void zoomTo(qreal optical, qreal digital) override;
-
-private Q_SLOTS:
- void onStatusChanged(QCamera::Status status);
-
-private:
- DSCameraSession *m_session;
- struct ZoomValues
- {
- long maxZoom;
- long minZoom;
- long stepping;
- long defaultZoom;
- long caps;
- } m_opticalZoom;
-
- qreal m_currentOpticalZoom;
- qreal m_requestedOpticalZoom;
- qreal m_maxOpticalZoom;
-
- void updateZoomValues();
- bool opticalZoomToPrivate(qreal value);
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWCAMERAZOOMCONTROL_H
diff --git a/src/plugins/directshow/camera/dscameracontrol.cpp b/src/plugins/directshow/camera/dscameracontrol.cpp
deleted file mode 100644
index 3f60ec848..000000000
--- a/src/plugins/directshow/camera/dscameracontrol.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qdebug.h>
-
-#include "dscameracontrol.h"
-#include "dscameraservice.h"
-#include "dscamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-DSCameraControl::DSCameraControl(QObject *parent)
- : QCameraControl(parent)
-{
- m_session = qobject_cast<DSCameraSession*>(parent);
- connect(m_session, &DSCameraSession::statusChanged, this,
- [&](QCamera::Status status) {
- if (status == QCamera::UnloadedStatus)
- m_state = QCamera::UnloadedState;
- emit statusChanged(status);
- });
- connect(m_session, &DSCameraSession::cameraError,
- this, &DSCameraControl::error);
-}
-
-DSCameraControl::~DSCameraControl() = default;
-
-void DSCameraControl::setState(QCamera::State state)
-{
- if (m_state == state)
- return;
-
- bool succeeded = false;
- switch (state) {
- case QCamera::UnloadedState:
- succeeded = m_session->unload();
- break;
- case QCamera::LoadedState:
- case QCamera::ActiveState:
- if (m_state == QCamera::UnloadedState && !m_session->load())
- return;
-
- if (state == QCamera::ActiveState)
- succeeded = m_session->startPreview();
- else
- succeeded = m_session->stopPreview();
-
- break;
- }
-
- if (succeeded) {
- m_state = state;
- emit stateChanged(m_state);
- }
-}
-
-bool DSCameraControl::isCaptureModeSupported(QCamera::CaptureModes mode) const
-{
- bool bCaptureSupported = false;
- switch (mode) {
- case QCamera::CaptureStillImage:
- bCaptureSupported = true;
- break;
- case QCamera::CaptureVideo:
- bCaptureSupported = false;
- break;
- }
- return bCaptureSupported;
-}
-
-void DSCameraControl::setCaptureMode(QCamera::CaptureModes mode)
-{
- if (m_captureMode != mode && isCaptureModeSupported(mode)) {
- m_captureMode = mode;
- emit captureModeChanged(mode);
- }
-}
-
-QCamera::Status DSCameraControl::status() const
-{
- return m_session->status();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/dscameracontrol.h b/src/plugins/directshow/camera/dscameracontrol.h
deleted file mode 100644
index 2087623d1..000000000
--- a/src/plugins/directshow/camera/dscameracontrol.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DSCAMERACONTROL_H
-#define DSCAMERACONTROL_H
-
-#include <QtCore/qobject.h>
-#include <qcameracontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class DSCameraSession;
-
-
-class DSCameraControl : public QCameraControl
-{
- Q_OBJECT
-public:
- DSCameraControl(QObject *parent = nullptr);
- ~DSCameraControl() override;
-
- QCamera::State state() const override { return m_state; }
-
- QCamera::CaptureModes captureMode() const override { return m_captureMode; }
- void setCaptureMode(QCamera::CaptureModes mode) override;
-
- void setState(QCamera::State state) override;
-
- QCamera::Status status() const override;
- bool isCaptureModeSupported(QCamera::CaptureModes mode) const override;
- bool canChangeProperty(PropertyChangeType, QCamera::Status) const override
- { return false; }
-
-private:
- DSCameraSession *m_session;
- QCamera::State m_state = QCamera::UnloadedState;
- QCamera::CaptureModes m_captureMode = QCamera::CaptureStillImage;
-};
-
-QT_END_NAMESPACE
-
-#endif
-
-
diff --git a/src/plugins/directshow/camera/dscameraimageprocessingcontrol.cpp b/src/plugins/directshow/camera/dscameraimageprocessingcontrol.cpp
deleted file mode 100644
index 6d0f45ae9..000000000
--- a/src/plugins/directshow/camera/dscameraimageprocessingcontrol.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "dscameraimageprocessingcontrol.h"
-#include "dscamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-DSCameraImageProcessingControl::DSCameraImageProcessingControl(DSCameraSession *session)
- : QCameraImageProcessingControl(session)
- , m_session(session)
-{
-}
-
-DSCameraImageProcessingControl::~DSCameraImageProcessingControl() = default;
-
-bool DSCameraImageProcessingControl::isParameterSupported(
- QCameraImageProcessingControl::ProcessingParameter parameter) const
-{
- return m_session->isImageProcessingParameterSupported(parameter);
-}
-
-bool DSCameraImageProcessingControl::isParameterValueSupported(
- QCameraImageProcessingControl::ProcessingParameter parameter,
- const QVariant &value) const
-{
- return m_session->isImageProcessingParameterValueSupported(parameter, value);
-}
-
-QVariant DSCameraImageProcessingControl::parameter(
- QCameraImageProcessingControl::ProcessingParameter parameter) const
-{
- return m_session->imageProcessingParameter(parameter);
-}
-
-void DSCameraImageProcessingControl::setParameter(QCameraImageProcessingControl::ProcessingParameter parameter,
- const QVariant &value)
-{
- m_session->setImageProcessingParameter(parameter, value);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/dscameraimageprocessingcontrol.h b/src/plugins/directshow/camera/dscameraimageprocessingcontrol.h
deleted file mode 100644
index 48f1b6b2c..000000000
--- a/src/plugins/directshow/camera/dscameraimageprocessingcontrol.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DSCAMERAIMAGEPROCESSINGCONTROL_H
-#define DSCAMERAIMAGEPROCESSINGCONTROL_H
-
-#include <qcamera.h>
-#include <qcameraimageprocessingcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class DSCameraSession;
-
-class DSCameraImageProcessingControl : public QCameraImageProcessingControl
-{
- Q_OBJECT
-
-public:
- DSCameraImageProcessingControl(DSCameraSession *session);
- ~DSCameraImageProcessingControl() override;
-
- bool isParameterSupported(ProcessingParameter) const override;
- bool isParameterValueSupported(ProcessingParameter parameter,
- const QVariant &value) const override;
- QVariant parameter(ProcessingParameter parameter) const override;
- void setParameter(ProcessingParameter parameter, const QVariant &value) override;
-
-private:
- DSCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // DSCAMERAIMAGEPROCESSINGCONTROL_H
diff --git a/src/plugins/directshow/camera/dscameraservice.cpp b/src/plugins/directshow/camera/dscameraservice.cpp
deleted file mode 100644
index ff488cf09..000000000
--- a/src/plugins/directshow/camera/dscameraservice.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qvariant.h>
-#include <QtCore/qdebug.h>
-
-#include "dscameraservice.h"
-#include "dscameracontrol.h"
-#include "dscamerasession.h"
-#include "dsvideorenderer.h"
-#include "dsvideodevicecontrol.h"
-#include "dsimagecapturecontrol.h"
-#include "dscameraviewfindersettingscontrol.h"
-#include "dscameraimageprocessingcontrol.h"
-#include "directshowcameraexposurecontrol.h"
-#include "directshowcameracapturedestinationcontrol.h"
-#include "directshowcameracapturebufferformatcontrol.h"
-#include "directshowvideoprobecontrol.h"
-#include "directshowcamerazoomcontrol.h"
-#include "directshowcameraimageencodercontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-DSCameraService::DSCameraService(QObject *parent):
- QMediaService(parent)
- , m_session(new DSCameraSession(this))
- , m_control(new DSCameraControl(m_session))
- , m_videoDevice(new DSVideoDeviceControl(m_session))
- , m_imageCapture(new DSImageCaptureControl(m_session))
- , m_viewfinderSettings(new DSCameraViewfinderSettingsControl(m_session))
- , m_imageProcessingControl(new DSCameraImageProcessingControl(m_session))
- , m_exposureControl(new DirectShowCameraExposureControl(m_session))
- , m_captureDestinationControl(new DirectShowCameraCaptureDestinationControl(m_session))
- , m_captureBufferFormatControl(new DirectShowCameraCaptureBufferFormatControl)
- , m_zoomControl(new DirectShowCameraZoomControl(m_session))
- , m_imageEncoderControl(new DirectShowCameraImageEncoderControl(m_session))
-{
-}
-
-DSCameraService::~DSCameraService()
-{
- delete m_control;
- delete m_viewfinderSettings;
- delete m_imageProcessingControl;
- delete m_videoDevice;
- delete m_videoRenderer;
- delete m_imageCapture;
- delete m_imageEncoderControl;
- delete m_session;
- delete m_exposureControl;
- delete m_captureDestinationControl;
- delete m_captureBufferFormatControl;
- delete m_videoProbeControl;
- delete m_zoomControl;
-}
-
-QMediaControl* DSCameraService::requestControl(const char *name)
-{
- if(qstrcmp(name,QCameraControl_iid) == 0)
- return m_control;
-
- if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0)
- return m_imageCapture;
-
- if (qstrcmp(name,QVideoRendererControl_iid) == 0) {
- if (!m_videoRenderer) {
- m_videoRenderer = new DSVideoRendererControl(m_session, this);
- return m_videoRenderer;
- }
- }
-
- if (qstrcmp(name,QVideoDeviceSelectorControl_iid) == 0)
- return m_videoDevice;
-
- if (qstrcmp(name, QCameraViewfinderSettingsControl2_iid) == 0)
- return m_viewfinderSettings;
-
- if (qstrcmp(name, QCameraImageProcessingControl_iid) == 0)
- return m_imageProcessingControl;
-
- if (qstrcmp(name, QCameraExposureControl_iid) == 0)
- return m_exposureControl;
-
- if (qstrcmp(name, QCameraCaptureDestinationControl_iid) == 0)
- return m_captureDestinationControl;
-
- if (qstrcmp(name, QCameraCaptureBufferFormatControl_iid) == 0)
- return m_captureBufferFormatControl;
-
- if (qstrcmp(name, QMediaVideoProbeControl_iid) == 0) {
- if (!m_videoProbeControl)
- m_videoProbeControl = new DirectShowVideoProbeControl;
-
- m_videoProbeControl->ref();
- m_session->addVideoProbe(m_videoProbeControl);
- return m_videoProbeControl;
- }
-
- if (qstrcmp(name, QCameraZoomControl_iid) == 0)
- return m_zoomControl;
-
- if (qstrcmp(name, QImageEncoderControl_iid) == 0)
- return m_imageEncoderControl;
-
- return nullptr;
-}
-
-void DSCameraService::releaseControl(QMediaControl *control)
-{
- if (control == m_videoRenderer) {
- delete m_videoRenderer;
- m_videoRenderer = nullptr;
- return;
- }
-
- if (control == m_videoProbeControl) {
- m_session->removeVideoProbe(m_videoProbeControl);
- if (!m_videoProbeControl->deref()) {
- delete m_videoProbeControl;
- m_videoProbeControl = nullptr;
- }
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/dscameraservice.h b/src/plugins/directshow/camera/dscameraservice.h
deleted file mode 100644
index 6ea85b725..000000000
--- a/src/plugins/directshow/camera/dscameraservice.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DSCAMERASERVICE_H
-#define DSCAMERASERVICE_H
-
-#include <QtCore/qobject.h>
-
-#include <qmediaservice.h>
-
-QT_BEGIN_NAMESPACE
-
-class DSCameraControl;
-class DSCameraSession;
-class DSVideoDeviceControl;
-class DSImageCaptureControl;
-class DSCameraViewfinderSettingsControl;
-class DSCameraImageProcessingControl;
-class DirectShowCameraExposureControl;
-class DirectShowCameraCaptureDestinationControl;
-class DirectShowCameraCaptureBufferFormatControl;
-class DirectShowVideoProbeControl;
-class DirectShowCameraZoomControl;
-class DirectShowCameraImageEncoderControl;
-
-class DSCameraService : public QMediaService
-{
- Q_OBJECT
-
-public:
- DSCameraService(QObject *parent = nullptr);
- ~DSCameraService() override;
-
- QMediaControl* requestControl(const char *name) override;
- void releaseControl(QMediaControl *control) override;
-
-private:
- DSCameraSession *m_session;
- DSCameraControl *m_control;
- DSVideoDeviceControl *m_videoDevice;
- QMediaControl *m_videoRenderer = nullptr;
- DSImageCaptureControl *m_imageCapture;
- DSCameraViewfinderSettingsControl *m_viewfinderSettings;
- DSCameraImageProcessingControl *m_imageProcessingControl;
- DirectShowCameraExposureControl *m_exposureControl;
- DirectShowCameraCaptureDestinationControl *m_captureDestinationControl;
- DirectShowCameraCaptureBufferFormatControl *m_captureBufferFormatControl;
- DirectShowVideoProbeControl *m_videoProbeControl = nullptr;
- DirectShowCameraZoomControl *m_zoomControl;
- DirectShowCameraImageEncoderControl *m_imageEncoderControl;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp
deleted file mode 100644
index 7ceefe2c5..000000000
--- a/src/plugins/directshow/camera/dscamerasession.cpp
+++ /dev/null
@@ -1,1177 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qdebug.h>
-#include <QFile>
-#include <QtConcurrent/QtConcurrentRun>
-#include <QtMultimedia/qabstractvideobuffer.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
-#include <QtMultimedia/qcameraimagecapture.h>
-#include <private/qmemoryvideobuffer_p.h>
-
-#include "dscamerasession.h"
-#include "dsvideorenderer.h"
-#include "directshowsamplegrabber.h"
-#include "directshowcameraglobal.h"
-#include "directshowmediatype.h"
-#include "directshowutils.h"
-#include "directshowvideoprobecontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-DSCameraSession::DSCameraSession(QObject *parent)
- : QObject(parent)
-{
- connect(this, &DSCameraSession::statusChanged,
- this, &DSCameraSession::updateReadyForCapture);
-
- m_deviceLostEventTimer.setSingleShot(true);
- connect(&m_deviceLostEventTimer, &QTimer::timeout, [&]() {
- IMediaEvent *pEvent = com_cast<IMediaEvent>(m_filterGraph, IID_IMediaEvent);
- if (!pEvent)
- return;
-
- long eventCode;
- LONG_PTR param1;
- LONG_PTR param2;
- while (pEvent->GetEvent(&eventCode, &param1, &param2, 0) == S_OK) {
- switch (eventCode) {
- case EC_DEVICE_LOST:
- unload();
- break;
- default:
- break;
- }
-
- pEvent->FreeEventParams(eventCode, param1, param2);
- }
-
- pEvent->Release();
- });
-}
-
-DSCameraSession::~DSCameraSession()
-{
- unload();
-}
-
-void DSCameraSession::setSurface(QAbstractVideoSurface* surface)
-{
- m_surface = surface;
-}
-
-void DSCameraSession::setDevice(const QString &device)
-{
- m_sourceDeviceName = device;
-}
-
-QCameraViewfinderSettings DSCameraSession::viewfinderSettings() const
-{
- return m_status == QCamera::ActiveStatus ? m_actualViewfinderSettings : m_viewfinderSettings;
-}
-
-void DSCameraSession::setViewfinderSettings(const QCameraViewfinderSettings &settings)
-{
- m_viewfinderSettings = settings;
-}
-
-qreal DSCameraSession::scaledImageProcessingParameterValue(
- const ImageProcessingParameterInfo &sourceValueInfo)
-{
- if (sourceValueInfo.currentValue == sourceValueInfo.defaultValue)
- return 0.0f;
- if (sourceValueInfo.currentValue < sourceValueInfo.defaultValue) {
- return ((sourceValueInfo.currentValue - sourceValueInfo.minimumValue)
- / qreal(sourceValueInfo.defaultValue - sourceValueInfo.minimumValue))
- + (-1.0f);
- }
- return ((sourceValueInfo.currentValue - sourceValueInfo.defaultValue)
- / qreal(sourceValueInfo.maximumValue - sourceValueInfo.defaultValue));
-}
-
-qint32 DSCameraSession::sourceImageProcessingParameterValue(
- qreal scaledValue, const ImageProcessingParameterInfo &valueRange)
-{
- if (qFuzzyIsNull(scaledValue))
- return valueRange.defaultValue;
- if (scaledValue < 0.0f) {
- return ((scaledValue - (-1.0f)) * (valueRange.defaultValue - valueRange.minimumValue))
- + valueRange.minimumValue;
- }
- return (scaledValue * (valueRange.maximumValue - valueRange.defaultValue))
- + valueRange.defaultValue;
-}
-
-static QCameraImageProcessingControl::ProcessingParameter searchRelatedResultingParameter(
- QCameraImageProcessingControl::ProcessingParameter sourceParameter)
-{
- if (sourceParameter == QCameraImageProcessingControl::WhiteBalancePreset)
- return QCameraImageProcessingControl::ColorTemperature;
- return sourceParameter;
-}
-
-bool DSCameraSession::isImageProcessingParameterSupported(
- QCameraImageProcessingControl::ProcessingParameter parameter) const
-{
- const QCameraImageProcessingControl::ProcessingParameter resultingParameter =
- searchRelatedResultingParameter(parameter);
-
- return m_imageProcessingParametersInfos.contains(resultingParameter);
-}
-
-bool DSCameraSession::isImageProcessingParameterValueSupported(
- QCameraImageProcessingControl::ProcessingParameter parameter,
- const QVariant &value) const
-{
- const QCameraImageProcessingControl::ProcessingParameter resultingParameter =
- searchRelatedResultingParameter(parameter);
-
- QMap<QCameraImageProcessingControl::ProcessingParameter,
- ImageProcessingParameterInfo>::const_iterator sourceValueInfo =
- m_imageProcessingParametersInfos.constFind(resultingParameter);
-
- if (sourceValueInfo == m_imageProcessingParametersInfos.constEnd())
- return false;
-
- switch (parameter) {
-
- case QCameraImageProcessingControl::WhiteBalancePreset: {
- const QCameraImageProcessing::WhiteBalanceMode checkedValue =
- value.value<QCameraImageProcessing::WhiteBalanceMode>();
- // Supports only the Manual and the Auto values
- if (checkedValue != QCameraImageProcessing::WhiteBalanceManual
- && checkedValue != QCameraImageProcessing::WhiteBalanceAuto) {
- return false;
- }
- }
- break;
-
- case QCameraImageProcessingControl::ColorTemperature: {
- const qint32 checkedValue = value.toInt();
- if (checkedValue < (*sourceValueInfo).minimumValue
- || checkedValue > (*sourceValueInfo).maximumValue) {
- return false;
- }
- }
- break;
-
- case QCameraImageProcessingControl::ContrastAdjustment: // falling back
- case QCameraImageProcessingControl::SaturationAdjustment: // falling back
- case QCameraImageProcessingControl::BrightnessAdjustment: // falling back
- case QCameraImageProcessingControl::SharpeningAdjustment: {
- const qint32 sourceValue = sourceImageProcessingParameterValue(
- value.toReal(), (*sourceValueInfo));
- if (sourceValue < (*sourceValueInfo).minimumValue
- || sourceValue > (*sourceValueInfo).maximumValue)
- return false;
- }
- break;
-
- default:
- return false;
- }
-
- return true;
-}
-
-QVariant DSCameraSession::imageProcessingParameter(
- QCameraImageProcessingControl::ProcessingParameter parameter) const
-{
- if (!m_graphBuilder) {
- auto it = m_pendingImageProcessingParametrs.find(parameter);
- return it != m_pendingImageProcessingParametrs.end() ? it.value() : QVariant();
- }
-
- const QCameraImageProcessingControl::ProcessingParameter resultingParameter =
- searchRelatedResultingParameter(parameter);
-
- QMap<QCameraImageProcessingControl::ProcessingParameter,
- ImageProcessingParameterInfo>::const_iterator sourceValueInfo =
- m_imageProcessingParametersInfos.constFind(resultingParameter);
-
- if (sourceValueInfo == m_imageProcessingParametersInfos.constEnd())
- return QVariant();
-
- switch (parameter) {
-
- case QCameraImageProcessingControl::WhiteBalancePreset:
- return QVariant::fromValue<QCameraImageProcessing::WhiteBalanceMode>(
- (*sourceValueInfo).capsFlags == VideoProcAmp_Flags_Auto
- ? QCameraImageProcessing::WhiteBalanceAuto
- : QCameraImageProcessing::WhiteBalanceManual);
-
- case QCameraImageProcessingControl::ColorTemperature:
- return QVariant::fromValue<qint32>((*sourceValueInfo).currentValue);
-
- case QCameraImageProcessingControl::ContrastAdjustment: // falling back
- case QCameraImageProcessingControl::SaturationAdjustment: // falling back
- case QCameraImageProcessingControl::BrightnessAdjustment: // falling back
- case QCameraImageProcessingControl::SharpeningAdjustment:
- return scaledImageProcessingParameterValue((*sourceValueInfo));
-
- default:
- return QVariant();
- }
-}
-
-void DSCameraSession::setImageProcessingParameter(
- QCameraImageProcessingControl::ProcessingParameter parameter,
- const QVariant &value)
-{
- if (!m_graphBuilder) {
- m_pendingImageProcessingParametrs.insert(parameter, value);
- return;
- }
-
- const QCameraImageProcessingControl::ProcessingParameter resultingParameter =
- searchRelatedResultingParameter(parameter);
-
- QMap<QCameraImageProcessingControl::ProcessingParameter,
- ImageProcessingParameterInfo>::iterator sourceValueInfo =
- m_imageProcessingParametersInfos.find(resultingParameter);
-
- if (sourceValueInfo == m_imageProcessingParametersInfos.end())
- return;
-
- LONG sourceValue = 0;
- LONG capsFlags = VideoProcAmp_Flags_Manual;
-
- switch (parameter) {
-
- case QCameraImageProcessingControl::WhiteBalancePreset: {
- const QCameraImageProcessing::WhiteBalanceMode checkedValue =
- value.value<QCameraImageProcessing::WhiteBalanceMode>();
- // Supports only the Manual and the Auto values
- if (checkedValue == QCameraImageProcessing::WhiteBalanceManual)
- capsFlags = VideoProcAmp_Flags_Manual;
- else if (checkedValue == QCameraImageProcessing::WhiteBalanceAuto)
- capsFlags = VideoProcAmp_Flags_Auto;
- else
- return;
-
- sourceValue = ((*sourceValueInfo).hasBeenExplicitlySet)
- ? (*sourceValueInfo).currentValue
- : (*sourceValueInfo).defaultValue;
- }
- break;
-
- case QCameraImageProcessingControl::ColorTemperature:
- sourceValue = value.isValid() ?
- value.value<qint32>() : (*sourceValueInfo).defaultValue;
- capsFlags = (*sourceValueInfo).capsFlags;
- break;
-
- case QCameraImageProcessingControl::ContrastAdjustment: // falling back
- case QCameraImageProcessingControl::SaturationAdjustment: // falling back
- case QCameraImageProcessingControl::BrightnessAdjustment: // falling back
- case QCameraImageProcessingControl::SharpeningAdjustment:
- if (value.isValid()) {
- sourceValue = sourceImageProcessingParameterValue(
- value.toReal(), (*sourceValueInfo));
- } else {
- sourceValue = (*sourceValueInfo).defaultValue;
- }
- break;
-
- default:
- return;
- }
-
- IAMVideoProcAmp *pVideoProcAmp = nullptr;
- HRESULT hr = m_graphBuilder->FindInterface(
- nullptr,
- nullptr,
- m_sourceFilter,
- IID_IAMVideoProcAmp,
- reinterpret_cast<void**>(&pVideoProcAmp)
- );
-
- if (FAILED(hr) || !pVideoProcAmp) {
- qWarning() << "failed to find the video proc amp";
- return;
- }
-
- hr = pVideoProcAmp->Set(
- (*sourceValueInfo).videoProcAmpProperty,
- sourceValue,
- capsFlags);
-
- pVideoProcAmp->Release();
-
- if (FAILED(hr)) {
- qWarning() << "failed to set the parameter value";
- } else {
- (*sourceValueInfo).capsFlags = capsFlags;
- (*sourceValueInfo).hasBeenExplicitlySet = true;
- (*sourceValueInfo).currentValue = sourceValue;
- }
-}
-
-bool DSCameraSession::getCameraControlInterface(IAMCameraControl **cameraControl) const
-{
- if (!m_sourceFilter) {
- qCDebug(qtDirectShowPlugin, "getCameraControlInterface failed: No capture filter!");
- return false;
- }
-
- if (!cameraControl) {
- qCDebug(qtDirectShowPlugin, "getCameraControlInterface failed: Invalid out argument!");
- return false;
- }
-
- if (FAILED(m_sourceFilter->QueryInterface(IID_IAMCameraControl, reinterpret_cast<void **>(cameraControl)))) {
- qCDebug(qtDirectShowPlugin, "getCameraControlInterface failed: Querying camera control failed!");
- return false;
- }
-
- return true;
-}
-
-bool DSCameraSession::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const
-{
- return destination & (QCameraImageCapture::CaptureToFile | QCameraImageCapture::CaptureToBuffer);
-}
-
-QCameraImageCapture::CaptureDestinations DSCameraSession::captureDestination() const
-{
- return m_captureDestinations;
-}
-
-void DSCameraSession::setCaptureDestination(QCameraImageCapture::CaptureDestinations destinations)
-{
- if (m_captureDestinations == destinations)
- return;
-
- m_captureDestinations = destinations;
- Q_EMIT captureDestinationChanged(m_captureDestinations);
-}
-
-void DSCameraSession::addVideoProbe(DirectShowVideoProbeControl *probe)
-{
- const QMutexLocker locker(&m_probeMutex);
- m_videoProbeControl = probe;
-}
-
-void DSCameraSession::removeVideoProbe(DirectShowVideoProbeControl *probe)
-{
- Q_UNUSED(probe);
- Q_ASSERT(m_videoProbeControl == probe);
- const QMutexLocker locker(&m_probeMutex);
- m_videoProbeControl = nullptr;
-}
-
-bool DSCameraSession::load()
-{
- unload();
-
- setStatus(QCamera::LoadingStatus);
-
- bool succeeded = createFilterGraph();
- if (succeeded)
- setStatus(QCamera::LoadedStatus);
- else
- setStatus(QCamera::UnavailableStatus);
-
- return succeeded;
-}
-
-bool DSCameraSession::unload()
-{
- if (!m_graphBuilder)
- return false;
-
- if (!stopPreview())
- return false;
-
- setStatus(QCamera::UnloadingStatus);
-
- m_needsHorizontalMirroring = false;
- m_supportedViewfinderSettings.clear();
- m_supportedFormats.clear();
- SAFE_RELEASE(m_sourceFilter);
- SAFE_RELEASE(m_nullRendererFilter);
- SAFE_RELEASE(m_filterGraph);
- SAFE_RELEASE(m_graphBuilder);
- SAFE_RELEASE(m_outputPin);
-
- setStatus(QCamera::UnloadedStatus);
-
- return true;
-}
-
-bool DSCameraSession::startPreview()
-{
- if (m_previewStarted)
- return true;
-
- if (!m_graphBuilder)
- return false;
-
- setStatus(QCamera::StartingStatus);
-
- QString errorString;
- HRESULT hr = S_OK;
- IMediaControl* pControl = nullptr;
-
- if (!configurePreviewFormat()) {
- errorString = tr("Failed to configure preview format");
- goto failed;
- }
-
- if (!connectGraph()) {
- errorString = tr("Failed to connect graph");
- goto failed;
- }
-
- if (m_surface)
- m_surface->start(m_previewSurfaceFormat);
-
- hr = m_filterGraph->QueryInterface(IID_IMediaControl, reinterpret_cast<void**>(&pControl));
- if (FAILED(hr)) {
- errorString = tr("Failed to get stream control");
- goto failed;
- }
- hr = pControl->Run();
- pControl->Release();
-
- if (FAILED(hr)) {
- errorString = tr("Failed to start");
- goto failed;
- }
-
- setStatus(QCamera::ActiveStatus);
- m_previewStarted = true;
- return true;
-
-failed:
- // go back to a clean state
- if (m_surface && m_surface->isActive())
- m_surface->stop();
- disconnectGraph();
- setError(QCamera::CameraError, errorString, hr);
- return false;
-}
-
-bool DSCameraSession::stopPreview()
-{
- if (!m_previewStarted)
- return true;
-
- setStatus(QCamera::StoppingStatus);
-
- if (m_previewSampleGrabber)
- m_previewSampleGrabber->stop();
-
- QString errorString;
- IMediaControl* pControl = nullptr;
- HRESULT hr = m_filterGraph->QueryInterface(IID_IMediaControl,
- reinterpret_cast<void**>(&pControl));
- if (FAILED(hr)) {
- errorString = tr("Failed to get stream control");
- goto failed;
- }
-
- hr = pControl->Stop();
- pControl->Release();
- if (FAILED(hr)) {
- errorString = tr("Failed to stop");
- goto failed;
- }
-
- disconnectGraph();
-
- m_sourceFormat.clear();
-
- m_previewStarted = false;
- setStatus(QCamera::LoadedStatus);
- return true;
-
-failed:
- setError(QCamera::CameraError, errorString, hr);
- return false;
-}
-
-void DSCameraSession::setError(int error, const QString &errorString, HRESULT hr)
-{
- qErrnoWarning(hr, "[0x%x] %s", hr, qPrintable(errorString));
- emit cameraError(error, errorString);
- setStatus(QCamera::UnloadedStatus);
-}
-
-void DSCameraSession::setStatus(QCamera::Status status)
-{
- if (m_status == status)
- return;
-
- m_status = status;
- emit statusChanged(m_status);
-}
-
-bool DSCameraSession::isReadyForCapture()
-{
- return m_readyForCapture;
-}
-
-void DSCameraSession::updateReadyForCapture()
-{
- bool isReady = (m_status == QCamera::ActiveStatus && m_imageCaptureFileName.isEmpty());
- if (isReady != m_readyForCapture) {
- m_readyForCapture = isReady;
- emit readyForCaptureChanged(isReady);
- }
-}
-
-int DSCameraSession::captureImage(const QString &fileName)
-{
- ++m_imageIdCounter;
-
- if (!m_readyForCapture) {
- emit captureError(m_imageIdCounter, QCameraImageCapture::NotReadyError,
- tr("Camera not ready for capture"));
- return m_imageIdCounter;
- }
-
- const QString ext = !m_imageEncoderSettings.codec().isEmpty()
- ? m_imageEncoderSettings.codec().toLower()
- : QLatin1String("jpg");
- m_imageCaptureFileName = m_fileNameGenerator.generateFileName(fileName,
- QMediaStorageLocation::Pictures,
- QLatin1String("IMG_"),
- ext);
-
- updateReadyForCapture();
-
- m_captureMutex.lock();
- m_currentImageId = m_imageIdCounter;
- m_captureMutex.unlock();
-
- return m_imageIdCounter;
-}
-
-void DSCameraSession::onFrameAvailable(double time, const QByteArray &data)
-{
- // !!! Not called on the main thread
- Q_UNUSED(time);
-
- m_presentMutex.lock();
-
- // In case the source produces frames faster than we can display them,
- // only keep the most recent one
- m_currentFrame = QVideoFrame(new QMemoryVideoBuffer(data, m_stride),
- m_previewSize,
- m_previewPixelFormat);
-
- m_presentMutex.unlock();
-
- {
- const QMutexLocker locker(&m_probeMutex);
- if (m_currentFrame.isValid() && m_videoProbeControl)
- Q_EMIT m_videoProbeControl->videoFrameProbed(m_currentFrame);
- }
-
- // Image capture
- QMutexLocker locker(&m_captureMutex);
- if (m_currentImageId != -1 && !m_capturedFrame.isValid()) {
- m_capturedFrame = m_currentFrame;
- QMetaObject::invokeMethod(this, "imageExposed", Qt::QueuedConnection, Q_ARG(int, m_currentImageId));
- }
-
- QMetaObject::invokeMethod(this, "presentFrame", Qt::QueuedConnection);
-}
-
-void DSCameraSession::presentFrame()
-{
- // If no frames provided from ISampleGrabber for some time
- // the device might be potentially unplugged.
- m_deviceLostEventTimer.start(100);
-
- m_presentMutex.lock();
-
- if (m_currentFrame.isValid() && m_surface) {
- m_surface->present(m_currentFrame);
- m_currentFrame = QVideoFrame();
- }
-
- m_presentMutex.unlock();
-
- QImage captureImage;
- const int captureId = m_currentImageId;
-
- m_captureMutex.lock();
-
- if (m_capturedFrame.isValid()) {
-
- captureImage = m_capturedFrame.image();
-
- const bool needsVerticalMirroring = m_previewSurfaceFormat.scanLineDirection() != QVideoSurfaceFormat::TopToBottom;
- captureImage = captureImage.mirrored(m_needsHorizontalMirroring, needsVerticalMirroring); // also causes a deep copy of the data
-
- QtConcurrent::run(&DSCameraSession::processCapturedImage, this,
- m_currentImageId, m_captureDestinations, captureImage, m_imageCaptureFileName);
-
- m_imageCaptureFileName.clear();
- m_currentImageId = -1;
-
- m_capturedFrame = QVideoFrame();
- }
-
- m_captureMutex.unlock();
-
- if (!captureImage.isNull())
- emit imageCaptured(captureId, captureImage);
-
- updateReadyForCapture();
-}
-
-void DSCameraSession::processCapturedImage(int id,
- QCameraImageCapture::CaptureDestinations captureDestinations,
- const QImage &image,
- const QString &path)
-{
- const QString format = m_imageEncoderSettings.codec();
- if (captureDestinations & QCameraImageCapture::CaptureToFile) {
- if (image.save(path, !format.isEmpty() ? format.toUtf8().constData() : "JPG")) {
- Q_EMIT imageSaved(id, path);
- } else {
- Q_EMIT captureError(id, QCameraImageCapture::ResourceError,
- tr("Could not save image to file."));
- }
- }
-
- if (captureDestinations & QCameraImageCapture::CaptureToBuffer)
- Q_EMIT imageAvailable(id, QVideoFrame(image));
-}
-
-bool DSCameraSession::createFilterGraph()
-{
- // Previously containered in <qedit.h>.
- static const CLSID cLSID_NullRenderer = { 0xC1F400A4, 0x3F08, 0x11d3, { 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37 } };
-
- QString errorString;
- HRESULT hr;
- IMoniker* pMoniker = nullptr;
- ICreateDevEnum* pDevEnum = nullptr;
- IEnumMoniker* pEnum = nullptr;
-
- // Create the filter graph
- hr = CoCreateInstance(CLSID_FilterGraph, nullptr, CLSCTX_INPROC,
- IID_IGraphBuilder, reinterpret_cast<void**>(&m_filterGraph));
- if (FAILED(hr)) {
- errorString = tr("Failed to create filter graph");
- goto failed;
- }
-
- // Create the capture graph builder
- hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, nullptr, CLSCTX_INPROC,
- IID_ICaptureGraphBuilder2,
- reinterpret_cast<void**>(&m_graphBuilder));
- if (FAILED(hr)) {
- errorString = tr("Failed to create graph builder");
- goto failed;
- }
-
- // Attach the filter graph to the capture graph
- hr = m_graphBuilder->SetFiltergraph(m_filterGraph);
- if (FAILED(hr)) {
- errorString = tr("Failed to connect capture graph and filter graph");
- goto failed;
- }
-
- // Find the Capture device
- hr = CoCreateInstance(CLSID_SystemDeviceEnum, nullptr,
- CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
- reinterpret_cast<void**>(&pDevEnum));
- if (SUCCEEDED(hr)) {
- // Create an enumerator for the video capture category
- hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0);
- pDevEnum->Release();
- if (S_OK == hr) {
- pEnum->Reset();
- IMalloc *mallocInterface = nullptr;
- CoGetMalloc(1, (LPMALLOC*)&mallocInterface);
- //go through and find all video capture devices
- while (pEnum->Next(1, &pMoniker, nullptr) == S_OK) {
-
- BSTR strName = nullptr;
- hr = pMoniker->GetDisplayName(nullptr, nullptr, &strName);
- if (SUCCEEDED(hr)) {
- QString output = QString::fromWCharArray(strName);
- mallocInterface->Free(strName);
- if (m_sourceDeviceName.contains(output)) {
- hr = pMoniker->BindToObject(nullptr, nullptr, IID_IBaseFilter,
- reinterpret_cast<void**>(&m_sourceFilter));
- if (SUCCEEDED(hr)) {
- pMoniker->Release();
- break;
- }
- }
- }
- pMoniker->Release();
- }
- mallocInterface->Release();
- if (nullptr == m_sourceFilter)
- {
- if (m_sourceDeviceName.contains(QLatin1String("default")))
- {
- pEnum->Reset();
- // still have to loop to discard bind to storage failure case
- while (pEnum->Next(1, &pMoniker, nullptr) == S_OK) {
- IPropertyBag *pPropBag = nullptr;
-
- hr = pMoniker->BindToStorage(nullptr, nullptr, IID_IPropertyBag,
- reinterpret_cast<void**>(&pPropBag));
- if (FAILED(hr)) {
- pMoniker->Release();
- continue; // Don't panic yet
- }
-
- // No need to get the description, just grab it
-
- hr = pMoniker->BindToObject(nullptr, nullptr, IID_IBaseFilter,
- reinterpret_cast<void**>(&m_sourceFilter));
- pPropBag->Release();
- pMoniker->Release();
- if (SUCCEEDED(hr))
- break; // done, stop looping through
- qWarning("Object bind failed");
- }
- }
- }
- pEnum->Release();
- }
- }
-
- if (!m_sourceFilter) {
- errorString = tr("No capture device found");
- goto failed;
- }
-
- if (!DirectShowUtils::getPin(m_sourceFilter, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE, &m_outputPin, &hr))
- qWarning() << "Failed to get the pin for the video control:" << hr;
-
- // Sample grabber filter
- if (!m_previewSampleGrabber) {
- m_previewSampleGrabber = new DirectShowSampleGrabber(this);
- connect(m_previewSampleGrabber, &DirectShowSampleGrabber::bufferAvailable,
- this, &DSCameraSession::onFrameAvailable, Qt::DirectConnection);
- }
-
-
- // Null renderer. Input connected to the sample grabber's output. Simply
- // discard the samples it receives.
- hr = CoCreateInstance(cLSID_NullRenderer, nullptr, CLSCTX_INPROC,
- IID_IBaseFilter, (void**)&m_nullRendererFilter);
- if (FAILED(hr)) {
- errorString = tr("Failed to create null renderer");
- goto failed;
- }
-
- updateSourceCapabilities();
-
- return true;
-
-failed:
- m_needsHorizontalMirroring = false;
- SAFE_RELEASE(m_sourceFilter);
- SAFE_RELEASE(m_nullRendererFilter);
- SAFE_RELEASE(m_filterGraph);
- SAFE_RELEASE(m_graphBuilder);
- setError(QCamera::CameraError, errorString, hr);
-
- return false;
-}
-
-bool DSCameraSession::configurePreviewFormat()
-{
- // Resolve viewfinder settings
- int settingsIndex = 0;
- const QSize captureResolution = m_imageEncoderSettings.resolution();
- const QSize resolution = captureResolution.isValid() ? captureResolution : m_viewfinderSettings.resolution();
- QCameraViewfinderSettings resolvedViewfinderSettings;
- for (const QCameraViewfinderSettings &s : qAsConst(m_supportedViewfinderSettings)) {
- if ((resolution.isEmpty() || resolution == s.resolution())
- && (qFuzzyIsNull(m_viewfinderSettings.minimumFrameRate()) || qFuzzyCompare((float)m_viewfinderSettings.minimumFrameRate(), (float)s.minimumFrameRate()))
- && (qFuzzyIsNull(m_viewfinderSettings.maximumFrameRate()) || qFuzzyCompare((float)m_viewfinderSettings.maximumFrameRate(), (float)s.maximumFrameRate()))
- && (m_viewfinderSettings.pixelFormat() == QVideoFrame::Format_Invalid || m_viewfinderSettings.pixelFormat() == s.pixelFormat())
- && (m_viewfinderSettings.pixelAspectRatio().isEmpty() || m_viewfinderSettings.pixelAspectRatio() == s.pixelAspectRatio())) {
- resolvedViewfinderSettings = s;
- break;
- }
- ++settingsIndex;
- }
-
- if (resolvedViewfinderSettings.isNull()) {
- qWarning("Invalid viewfinder settings");
- return false;
- }
-
- m_actualViewfinderSettings = resolvedViewfinderSettings;
-
- m_sourceFormat = m_supportedFormats[settingsIndex];
- // Set frame rate.
- // We don't care about the minimumFrameRate, DirectShow only allows to set an
- // average frame rate, so set that to the maximumFrameRate.
- VIDEOINFOHEADER *videoInfo = reinterpret_cast<VIDEOINFOHEADER*>(m_sourceFormat->pbFormat);
- videoInfo->AvgTimePerFrame = 10000000 / resolvedViewfinderSettings.maximumFrameRate();
-
- m_previewPixelFormat = resolvedViewfinderSettings.pixelFormat();
- const AM_MEDIA_TYPE *resolvedGrabberFormat = &m_sourceFormat;
-
- if (m_surface) {
- const auto surfaceFormats = m_surface->supportedPixelFormats(QAbstractVideoBuffer::NoHandle);
- if (!surfaceFormats.contains(m_previewPixelFormat)) {
- if (surfaceFormats.contains(QVideoFrame::Format_RGB32)) {
- // As a fallback, we support RGB32, if the capture source doesn't support
- // that format, the graph builder will automatically insert a
- // converter (when possible).
-
- static const AM_MEDIA_TYPE rgb32GrabberFormat { MEDIATYPE_Video, MEDIASUBTYPE_ARGB32, 0, 0, 0, FORMAT_VideoInfo, nullptr, 0, nullptr};
- resolvedGrabberFormat = &rgb32GrabberFormat;
- m_previewPixelFormat = QVideoFrame::Format_RGB32;
-
- } else {
- qWarning() << "Video surface needs to support at least RGB32 pixel format";
- return false;
- }
- }
- }
-
- m_previewSize = resolvedViewfinderSettings.resolution();
- m_previewSurfaceFormat = QVideoSurfaceFormat(m_previewSize,
- m_previewPixelFormat,
- QAbstractVideoBuffer::NoHandle);
- m_previewSurfaceFormat.setScanLineDirection(DirectShowMediaType::scanLineDirection(m_previewPixelFormat, videoInfo->bmiHeader));
- m_stride = DirectShowMediaType::bytesPerLine(m_previewSurfaceFormat);
-
- HRESULT hr;
- IAMStreamConfig* pConfig = nullptr;
- hr = m_graphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
- m_sourceFilter, IID_IAMStreamConfig,
- reinterpret_cast<void**>(&pConfig));
- if (FAILED(hr)) {
- qWarning() << "Failed to get config for capture device";
- return false;
- }
-
- hr = pConfig->SetFormat(&m_sourceFormat);
-
- pConfig->Release();
-
- if (FAILED(hr)) {
- qWarning() << "Unable to set video format on capture device";
- return false;
- }
-
- if (!m_previewSampleGrabber->setMediaType(resolvedGrabberFormat))
- return false;
-
- m_previewSampleGrabber->start(DirectShowSampleGrabber::CallbackMethod::BufferCB);
-
- return true;
-}
-
-void DSCameraSession::updateImageProcessingParametersInfos()
-{
- if (!m_graphBuilder) {
- qWarning() << "failed to access to the graph builder";
- return;
- }
-
- IAMVideoProcAmp *pVideoProcAmp = nullptr;
- const HRESULT hr = m_graphBuilder->FindInterface(
- nullptr,
- nullptr,
- m_sourceFilter,
- IID_IAMVideoProcAmp,
- reinterpret_cast<void**>(&pVideoProcAmp)
- );
-
- if (FAILED(hr) || !pVideoProcAmp) {
- qWarning() << "failed to find the video proc amp";
- return;
- }
-
- for (int property = VideoProcAmp_Brightness; property <= VideoProcAmp_Gain; ++property) {
-
- QCameraImageProcessingControl::ProcessingParameter processingParameter; // not initialized
-
- switch (property) {
- case VideoProcAmp_Brightness:
- processingParameter = QCameraImageProcessingControl::BrightnessAdjustment;
- break;
- case VideoProcAmp_Contrast:
- processingParameter = QCameraImageProcessingControl::ContrastAdjustment;
- break;
- case VideoProcAmp_Saturation:
- processingParameter = QCameraImageProcessingControl::SaturationAdjustment;
- break;
- case VideoProcAmp_Sharpness:
- processingParameter = QCameraImageProcessingControl::SharpeningAdjustment;
- break;
- case VideoProcAmp_WhiteBalance:
- processingParameter = QCameraImageProcessingControl::ColorTemperature;
- break;
- default: // unsupported or not implemented yet parameter
- continue;
- }
-
- ImageProcessingParameterInfo sourceValueInfo;
- LONG steppingDelta = 0;
-
- HRESULT hr = pVideoProcAmp->GetRange(
- property,
- &sourceValueInfo.minimumValue,
- &sourceValueInfo.maximumValue,
- &steppingDelta,
- &sourceValueInfo.defaultValue,
- &sourceValueInfo.capsFlags);
-
- if (FAILED(hr))
- continue;
-
- hr = pVideoProcAmp->Get(
- property,
- &sourceValueInfo.currentValue,
- &sourceValueInfo.capsFlags);
-
- if (FAILED(hr))
- continue;
-
- sourceValueInfo.videoProcAmpProperty = static_cast<VideoProcAmpProperty>(property);
-
- m_imageProcessingParametersInfos.insert(processingParameter, sourceValueInfo);
- }
-
- pVideoProcAmp->Release();
-
- for (auto it = m_pendingImageProcessingParametrs.cbegin();
- it != m_pendingImageProcessingParametrs.cend();
- ++it) {
- setImageProcessingParameter(it.key(), it.value());
- }
- m_pendingImageProcessingParametrs.clear();
-}
-
-bool DSCameraSession::connectGraph()
-{
- HRESULT hr = m_filterGraph->AddFilter(m_sourceFilter, L"Capture Filter");
- if (FAILED(hr)) {
- qWarning() << "failed to add capture filter to graph";
- return false;
- }
-
- if (FAILED(m_filterGraph->AddFilter(m_previewSampleGrabber->filter(), L"Sample Grabber"))) {
- qWarning() << "failed to add sample grabber to graph";
- return false;
- }
-
- hr = m_filterGraph->AddFilter(m_nullRendererFilter, L"Null Renderer");
- if (FAILED(hr)) {
- qWarning() << "failed to add null renderer to graph";
- return false;
- }
-
- hr = m_graphBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
- m_sourceFilter,
- m_previewSampleGrabber->filter(),
- m_nullRendererFilter);
- if (FAILED(hr)) {
- qWarning() << "Graph failed to connect filters" << hr;
- return false;
- }
-
- return true;
-}
-
-void DSCameraSession::disconnectGraph()
-{
- // To avoid increasing the memory usage every time the graph is re-connected it's
- // important that all filters are released; also the ones added by the "Intelligent Connect".
- IEnumFilters *enumFilters = nullptr;
- if (SUCCEEDED(m_filterGraph->EnumFilters(&enumFilters))) {
- IBaseFilter *filter = nullptr;
- while (enumFilters->Next(1, &filter, nullptr) == S_OK) {
- m_filterGraph->RemoveFilter(filter);
- enumFilters->Reset();
- filter->Release();
- }
- enumFilters->Release();
- }
-}
-
-static bool qt_frameRateRangeGreaterThan(const QCamera::FrameRateRange &r1, const QCamera::FrameRateRange &r2)
-{
- return r1.maximumFrameRate > r2.maximumFrameRate;
-}
-
-void DSCameraSession::updateSourceCapabilities()
-{
- HRESULT hr;
- AM_MEDIA_TYPE *pmt = nullptr;
- VIDEOINFOHEADER *pvi = nullptr;
- VIDEO_STREAM_CONFIG_CAPS scc;
- IAMStreamConfig* pConfig = nullptr;
-
- m_supportedViewfinderSettings.clear();
- m_needsHorizontalMirroring = false;
- m_supportedFormats.clear();
- m_imageProcessingParametersInfos.clear();
-
- IAMVideoControl *pVideoControl = nullptr;
- hr = m_graphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
- m_sourceFilter, IID_IAMVideoControl,
- reinterpret_cast<void**>(&pVideoControl));
- if (FAILED(hr)) {
- qWarning() << "Failed to get the video control";
- } else if (m_outputPin) {
- long supportedModes;
- hr = pVideoControl->GetCaps(m_outputPin, &supportedModes);
- if (FAILED(hr)) {
- qWarning() << "Failed to get the supported modes of the video control";
- } else if (supportedModes & VideoControlFlag_FlipHorizontal) {
- long mode;
- hr = pVideoControl->GetMode(m_outputPin, &mode);
- if (FAILED(hr))
- qWarning() << "Failed to get the mode of the video control";
- else if (supportedModes & VideoControlFlag_FlipHorizontal)
- m_needsHorizontalMirroring = (mode & VideoControlFlag_FlipHorizontal);
- }
- pVideoControl->Release();
- }
-
- hr = m_graphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
- m_sourceFilter, IID_IAMStreamConfig,
- reinterpret_cast<void**>(&pConfig));
- if (FAILED(hr)) {
- qWarning() << "failed to get config on capture device";
- return;
- }
-
- int iCount;
- int iSize;
- hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize);
- if (FAILED(hr)) {
- qWarning() << "failed to get capabilities";
- return;
- }
-
- for (int iIndex = 0; iIndex < iCount; ++iIndex) {
- hr = pConfig->GetStreamCaps(iIndex, &pmt, reinterpret_cast<BYTE*>(&scc));
- if (hr == S_OK) {
- QVideoFrame::PixelFormat pixelFormat = DirectShowMediaType::pixelFormatFromType(pmt);
-
- if (pmt->majortype == MEDIATYPE_Video
- && pmt->formattype == FORMAT_VideoInfo
- && pixelFormat != QVideoFrame::Format_Invalid) {
-
- pvi = reinterpret_cast<VIDEOINFOHEADER*>(pmt->pbFormat);
- QSize resolution(pvi->bmiHeader.biWidth, pvi->bmiHeader.biHeight);
-
- QList<QCamera::FrameRateRange> frameRateRanges;
-
- if (pVideoControl && m_outputPin) {
- long listSize = 0;
- LONGLONG *frameRates = nullptr;
- SIZE size = { resolution.width(), resolution.height() };
- hr = pVideoControl->GetFrameRateList(m_outputPin, iIndex, size, &listSize, &frameRates);
- if (hr == S_OK && listSize > 0 && frameRates) {
- for (long i = 0; i < listSize; ++i) {
- qreal fr = qreal(10000000) / frameRates[i];
- frameRateRanges.append(QCamera::FrameRateRange(fr, fr));
- }
-
- // Make sure higher frame rates come first
- std::sort(frameRateRanges.begin(), frameRateRanges.end(), qt_frameRateRangeGreaterThan);
- }
-
- CoTaskMemFree(frameRates);
- }
-
- if (frameRateRanges.isEmpty()) {
- frameRateRanges.append(QCamera::FrameRateRange(qreal(10000000) / scc.MaxFrameInterval,
- qreal(10000000) / scc.MinFrameInterval));
- }
-
- for (const QCamera::FrameRateRange &frameRateRange : qAsConst(frameRateRanges)) {
- QCameraViewfinderSettings settings;
- settings.setResolution(resolution);
- settings.setMinimumFrameRate(frameRateRange.minimumFrameRate);
- settings.setMaximumFrameRate(frameRateRange.maximumFrameRate);
- settings.setPixelFormat(pixelFormat);
- settings.setPixelAspectRatio(1, 1);
- m_supportedViewfinderSettings.append(settings);
- m_supportedFormats.append(DirectShowMediaType(*pmt));
- }
- } else {
- OLECHAR *guidString = nullptr;
- StringFromCLSID(pmt->subtype, &guidString);
- if (guidString)
- qWarning() << "Unsupported media type:" << QString::fromWCharArray(guidString);
- ::CoTaskMemFree(guidString);
- }
-
- DirectShowMediaType::deleteType(pmt);
- }
- }
-
- pConfig->Release();
-
- updateImageProcessingParametersInfos();
-}
-
-QList<QSize> DSCameraSession::supportedResolutions(bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- QList<QSize> res;
- for (auto &settings : m_supportedViewfinderSettings) {
- auto size = settings.resolution();
- if (!res.contains(size))
- res << size;
- }
-
- std::sort(res.begin(), res.end(), [](const QSize &r1, const QSize &r2) {
- return qlonglong(r1.width()) * r1.height() < qlonglong(r2.width()) * r2.height();
- });
-
- return res;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/dscamerasession.h b/src/plugins/directshow/camera/dscamerasession.h
deleted file mode 100644
index 9f88163b9..000000000
--- a/src/plugins/directshow/camera/dscamerasession.h
+++ /dev/null
@@ -1,242 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DSCAMERASESSION_H
-#define DSCAMERASESSION_H
-
-#include <QtCore/qobject.h>
-#include <QTime>
-#include <QUrl>
-#include <QMutex>
-#include <QTimer>
-#include <qcamera.h>
-#include <QtMultimedia/qvideoframe.h>
-#include <QtMultimedia/qabstractvideosurface.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
-#include <QtMultimedia/qcameraimageprocessingcontrol.h>
-#include <QtMultimedia/qcameraimagecapture.h>
-#include <QtMultimedia/qmediaencodersettings.h>
-#include <private/qmediastoragelocation_p.h>
-
-#include <tchar.h>
-#include <dshow.h>
-#include <objbase.h>
-#include <initguid.h>
-#include "directshowmediatype.h"
-#ifdef Q_CC_MSVC
-# pragma comment(lib, "strmiids.lib")
-# pragma comment(lib, "ole32.lib")
-#endif // Q_CC_MSVC
-#include <windows.h>
-
-#ifdef Q_CC_MSVC
-# pragma include_alias("dxtrans.h","qedit.h")
-#endif // Q_CC_MSVC
-#define __IDxtCompositor_INTERFACE_DEFINED__
-#define __IDxtAlphaSetter_INTERFACE_DEFINED__
-#define __IDxtJpeg_INTERFACE_DEFINED__
-#define __IDxtKey_INTERFACE_DEFINED__
-
-struct ICaptureGraphBuilder2;
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowSampleGrabber;
-class DirectShowVideoProbeControl;
-
-class DSCameraSession : public QObject
-{
- Q_OBJECT
-public:
- DSCameraSession(QObject *parent = nullptr);
- ~DSCameraSession() override;
-
- QCamera::Status status() const { return m_status; }
-
- void setDevice(const QString &device);
-
- bool load();
- bool unload();
- bool startPreview();
- bool stopPreview();
-
- bool isReadyForCapture();
- int captureImage(const QString &fileName);
-
- void setSurface(QAbstractVideoSurface* surface);
-
- QCameraViewfinderSettings viewfinderSettings() const;
- void setViewfinderSettings(const QCameraViewfinderSettings &settings);
-
- QList<QCameraViewfinderSettings> supportedViewfinderSettings() const
- { return m_supportedViewfinderSettings; }
-
- bool isImageProcessingParameterSupported(
- QCameraImageProcessingControl::ProcessingParameter) const;
-
- bool isImageProcessingParameterValueSupported(
- QCameraImageProcessingControl::ProcessingParameter,
- const QVariant &) const;
-
- QVariant imageProcessingParameter(
- QCameraImageProcessingControl::ProcessingParameter) const;
-
- void setImageProcessingParameter(
- QCameraImageProcessingControl::ProcessingParameter,
- const QVariant &);
-
- bool getCameraControlInterface(IAMCameraControl **cameraControl) const;
-
- bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const;
- QCameraImageCapture::CaptureDestinations captureDestination() const;
- void setCaptureDestination(QCameraImageCapture::CaptureDestinations destinations);
-
- void addVideoProbe(DirectShowVideoProbeControl *probe);
- void removeVideoProbe(DirectShowVideoProbeControl *probe);
-
- QList<QSize> supportedResolutions(bool *continuous) const;
- QImageEncoderSettings imageEncoderSettings() const { return m_imageEncoderSettings; }
- void setImageEncoderSettings(const QImageEncoderSettings &settings)
- { m_imageEncoderSettings = settings; }
-
-Q_SIGNALS:
- void statusChanged(QCamera::Status);
- void imageExposed(int id);
- void imageCaptured(int id, const QImage &preview);
- void imageSaved(int id, const QString &fileName);
- void imageAvailable(int id, const QVideoFrame &buffer);
- void readyForCaptureChanged(bool);
- void captureError(int id, int error, const QString &errorString);
- void captureDestinationChanged(QCameraImageCapture::CaptureDestinations);
- void cameraError(int error, const QString &errorString);
-
-private Q_SLOTS:
- void presentFrame();
- void updateReadyForCapture();
-
-private:
- struct ImageProcessingParameterInfo
- {
- LONG minimumValue = 0;
- LONG maximumValue = 0;
- LONG defaultValue = 0;
- LONG currentValue = 0;
- LONG capsFlags = 0;
- bool hasBeenExplicitlySet = false;
- VideoProcAmpProperty videoProcAmpProperty = VideoProcAmp_Brightness;
- };
-
- void setStatus(QCamera::Status status);
-
- void onFrameAvailable(double time, const QByteArray &data);
- void processCapturedImage(int id, QCameraImageCapture::CaptureDestinations captureDestinations, const QImage &image, const QString &path);
-
- bool createFilterGraph();
- bool connectGraph();
- void disconnectGraph();
- void updateSourceCapabilities();
- bool configurePreviewFormat();
- void updateImageProcessingParametersInfos();
- void setError(int error, const QString &errorString, HRESULT hr);
-
- // These static functions are used for scaling of adjustable parameters,
- // which have the ranges from -1.0 to +1.0 in the QCameraImageProcessing API.
- static qreal scaledImageProcessingParameterValue(
- const ImageProcessingParameterInfo &sourceValueInfo);
- static qint32 sourceImageProcessingParameterValue(
- qreal scaledValue, const ImageProcessingParameterInfo &sourceValueInfo);
-
- QMutex m_presentMutex;
- QMutex m_captureMutex;
-
- ICaptureGraphBuilder2* m_graphBuilder = nullptr;
- IGraphBuilder* m_filterGraph = nullptr;
-
- // Source (camera)
- QString m_sourceDeviceName = QLatin1String("default");
- IBaseFilter* m_sourceFilter = nullptr;
- bool m_needsHorizontalMirroring = false;
- QList<DirectShowMediaType> m_supportedFormats;
- QList<QCameraViewfinderSettings> m_supportedViewfinderSettings;
- DirectShowMediaType m_sourceFormat;
- QMap<QCameraImageProcessingControl::ProcessingParameter, ImageProcessingParameterInfo> m_imageProcessingParametersInfos;
-
- // Preview
- DirectShowSampleGrabber *m_previewSampleGrabber = nullptr;
- IBaseFilter *m_nullRendererFilter = nullptr;
- QVideoFrame m_currentFrame;
- bool m_previewStarted = false;
- QAbstractVideoSurface* m_surface = nullptr;
- QVideoSurfaceFormat m_previewSurfaceFormat;
- QVideoFrame::PixelFormat m_previewPixelFormat = QVideoFrame::Format_RGB32;
- QSize m_previewSize;
- int m_stride = -1;
- QCameraViewfinderSettings m_viewfinderSettings;
- QCameraViewfinderSettings m_actualViewfinderSettings;
-
- // Image capture
- QString m_imageCaptureFileName;
- QMediaStorageLocation m_fileNameGenerator;
- bool m_readyForCapture = false;
- int m_imageIdCounter = 0;
- int m_currentImageId = -1;
- QVideoFrame m_capturedFrame;
- QCameraImageCapture::CaptureDestinations m_captureDestinations = QCameraImageCapture::CaptureToFile;
-
- // Video probe
- QMutex m_probeMutex;
- DirectShowVideoProbeControl *m_videoProbeControl = nullptr;
-
- QImageEncoderSettings m_imageEncoderSettings;
-
- // Internal state
- QCamera::Status m_status = QCamera::UnloadedStatus;
- QTimer m_deviceLostEventTimer;
-
- QMap<QCameraImageProcessingControl::ProcessingParameter, QVariant> m_pendingImageProcessingParametrs;
-
- IPin *m_outputPin = nullptr;
-
- friend class SampleGrabberCallbackPrivate;
-};
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.cpp b/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.cpp
deleted file mode 100644
index 655a47d07..000000000
--- a/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "dscameraviewfindersettingscontrol.h"
-#include "dscamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-DSCameraViewfinderSettingsControl::DSCameraViewfinderSettingsControl(DSCameraSession *session)
- : QCameraViewfinderSettingsControl2(session)
- , m_session(session)
-{
-}
-
-QList<QCameraViewfinderSettings> DSCameraViewfinderSettingsControl::supportedViewfinderSettings() const
-{
- return m_session->supportedViewfinderSettings();
-}
-
-QCameraViewfinderSettings DSCameraViewfinderSettingsControl::viewfinderSettings() const
-{
- return m_session->viewfinderSettings();
-}
-
-void DSCameraViewfinderSettingsControl::setViewfinderSettings(const QCameraViewfinderSettings &settings)
-{
- m_session->setViewfinderSettings(settings);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.h b/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.h
deleted file mode 100644
index a2b646edf..000000000
--- a/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DSCAMERAVIEWFINDERSETTINGSCONTROL_H
-#define DSCAMERAVIEWFINDERSETTINGSCONTROL_H
-
-#include <qcameraviewfindersettingscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class DSCameraSession;
-
-class DSCameraViewfinderSettingsControl : public QCameraViewfinderSettingsControl2
-{
-public:
- DSCameraViewfinderSettingsControl(DSCameraSession *session);
-
- QList<QCameraViewfinderSettings> supportedViewfinderSettings() const override;
-
- QCameraViewfinderSettings viewfinderSettings() const override;
- void setViewfinderSettings(const QCameraViewfinderSettings &settings) override;
-
-private:
- DSCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // DSCAMERAVIEWFINDERSETTINGSCONTROL_H
diff --git a/src/plugins/directshow/camera/dsimagecapturecontrol.cpp b/src/plugins/directshow/camera/dsimagecapturecontrol.cpp
deleted file mode 100644
index e4d2eee30..000000000
--- a/src/plugins/directshow/camera/dsimagecapturecontrol.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/QDebug>
-
-#include "dsimagecapturecontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-DSImageCaptureControl::DSImageCaptureControl(DSCameraSession *session)
- : QCameraImageCaptureControl(session)
- , m_session(session)
-{
- connect(m_session, &DSCameraSession::imageExposed,
- this, &DSImageCaptureControl::imageExposed);
- connect(m_session, &DSCameraSession::imageCaptured,
- this, &DSImageCaptureControl::imageCaptured);
- connect(m_session, &DSCameraSession::imageSaved,
- this, &DSImageCaptureControl::imageSaved);
- connect(m_session, &DSCameraSession::readyForCaptureChanged,
- this, &DSImageCaptureControl::readyForCaptureChanged);
- connect(m_session, &DSCameraSession::captureError,
- this, &DSImageCaptureControl::error);
- connect(m_session, &DSCameraSession::imageAvailable,
- this, &DSImageCaptureControl::imageAvailable);
-}
-
-DSImageCaptureControl::~DSImageCaptureControl() = default;
-
-bool DSImageCaptureControl::isReadyForCapture() const
-{
- return m_session->isReadyForCapture();
-}
-
-int DSImageCaptureControl::capture(const QString &fileName)
-{
- return m_session->captureImage(fileName);
-}
-
-QCameraImageCapture::DriveMode DSImageCaptureControl::driveMode() const
-{
- return QCameraImageCapture::SingleImageCapture;
-}
-
-void DSImageCaptureControl::setDriveMode(QCameraImageCapture::DriveMode mode)
-{
- if (mode != QCameraImageCapture::SingleImageCapture)
- qWarning("Drive mode not supported.");
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/plugins/directshow/camera/dsimagecapturecontrol.h b/src/plugins/directshow/camera/dsimagecapturecontrol.h
deleted file mode 100644
index c619de1a1..000000000
--- a/src/plugins/directshow/camera/dsimagecapturecontrol.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DSIMAGECAPTURECONTROL_H
-#define DSIMAGECAPTURECONTROL_H
-
-#include <qcameraimagecapturecontrol.h>
-#include "dscamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-class DSImageCaptureControl : public QCameraImageCaptureControl
-{
- Q_OBJECT
-public:
- DSImageCaptureControl(DSCameraSession *session);
- ~DSImageCaptureControl() override;
-
- bool isReadyForCapture() const override;
- int capture(const QString &fileName) override;
-
- QCameraImageCapture::DriveMode driveMode() const override;
- void setDriveMode(QCameraImageCapture::DriveMode mode) override;
-
- void cancelCapture() override {}
-
-private:
- DSCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // DSCAPTURECONTROL_H
diff --git a/src/plugins/directshow/camera/dsvideodevicecontrol.cpp b/src/plugins/directshow/camera/dsvideodevicecontrol.cpp
deleted file mode 100644
index 0f08154f1..000000000
--- a/src/plugins/directshow/camera/dsvideodevicecontrol.cpp
+++ /dev/null
@@ -1,186 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QDebug>
-#include <QFile>
-#include <qelapsedtimer.h>
-
-#include "dsvideodevicecontrol.h"
-#include "dscamerasession.h"
-
-#include <tchar.h>
-#include <dshow.h>
-#include <objbase.h>
-#include <initguid.h>
-#include <ocidl.h>
-#include <string.h>
-
-extern const CLSID CLSID_VideoInputDeviceCategory;
-
-QT_BEGIN_NAMESPACE
-
-Q_GLOBAL_STATIC(QList<DSVideoDeviceInfo>, deviceList)
-
-DSVideoDeviceControl::DSVideoDeviceControl(QObject *parent)
- : QVideoDeviceSelectorControl(parent)
-{
- m_session = qobject_cast<DSCameraSession*>(parent);
- selected = 0;
-}
-
-int DSVideoDeviceControl::deviceCount() const
-{
- updateDevices();
- return deviceList->count();
-}
-
-QString DSVideoDeviceControl::deviceName(int index) const
-{
- updateDevices();
-
- if (index >= 0 && index <= deviceList->count())
- return QString::fromUtf8(deviceList->at(index).first.constData());
-
- return QString();
-}
-
-QString DSVideoDeviceControl::deviceDescription(int index) const
-{
- updateDevices();
-
- if (index >= 0 && index <= deviceList->count())
- return deviceList->at(index).second;
-
- return QString();
-}
-
-int DSVideoDeviceControl::defaultDevice() const
-{
- return 0;
-}
-
-int DSVideoDeviceControl::selectedDevice() const
-{
- return selected;
-}
-
-void DSVideoDeviceControl::setSelectedDevice(int index)
-{
- updateDevices();
-
- if (index >= 0 && index < deviceList->count()) {
- if (m_session) {
- QString device = deviceList->at(index).first;
- if (device.startsWith("ds:"))
- device.remove(0,3);
- m_session->setDevice(device);
- }
- selected = index;
- }
-}
-
-const QList<DSVideoDeviceInfo> &DSVideoDeviceControl::availableDevices()
-{
- updateDevices();
- return *deviceList;
-}
-
-void DSVideoDeviceControl::updateDevices()
-{
- static QElapsedTimer timer;
- if (timer.isValid() && timer.elapsed() < 500) // ms
- return;
-
- deviceList->clear();
-
- ICreateDevEnum* pDevEnum = nullptr;
- IEnumMoniker* pEnum = nullptr;
- // Create the System device enumerator
- HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, nullptr,
- CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
- reinterpret_cast<void**>(&pDevEnum));
- if (SUCCEEDED(hr)) {
- // Create the enumerator for the video capture category
- hr = pDevEnum->CreateClassEnumerator(
- CLSID_VideoInputDeviceCategory, &pEnum, 0);
- if (S_OK == hr) {
- pEnum->Reset();
- // go through and find all video capture devices
- IMoniker* pMoniker = nullptr;
- IMalloc *mallocInterface = nullptr;
- CoGetMalloc(1, (LPMALLOC*)&mallocInterface);
- while (pEnum->Next(1, &pMoniker, nullptr) == S_OK) {
- BSTR strName = nullptr;
- hr = pMoniker->GetDisplayName(nullptr, nullptr, &strName);
- if (SUCCEEDED(hr)) {
- QString output(QString::fromWCharArray(strName));
- mallocInterface->Free(strName);
-
- DSVideoDeviceInfo devInfo;
- devInfo.first = output.toUtf8();
-
- IPropertyBag *pPropBag;
- hr = pMoniker->BindToStorage(nullptr, nullptr, IID_IPropertyBag,
- reinterpret_cast<void**>(&pPropBag));
- if (SUCCEEDED(hr)) {
- // Find the description
- VARIANT varName;
- varName.vt = VT_BSTR;
- hr = pPropBag->Read(L"FriendlyName", &varName, nullptr);
- if (SUCCEEDED(hr)) {
- output = QString::fromWCharArray(varName.bstrVal);
- }
- pPropBag->Release();
- }
- devInfo.second = output;
-
- deviceList->append(devInfo);
- }
- pMoniker->Release();
- }
- mallocInterface->Release();
- pEnum->Release();
- }
- pDevEnum->Release();
- }
-
- timer.restart();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/camera/dsvideodevicecontrol.h b/src/plugins/directshow/camera/dsvideodevicecontrol.h
deleted file mode 100644
index 24a5b61a1..000000000
--- a/src/plugins/directshow/camera/dsvideodevicecontrol.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DSVIDEODEVICECONTROL_H
-#define DSVIDEODEVICECONTROL_H
-
-#include <qvideodeviceselectorcontrol.h>
-#include <QStringList>
-
-QT_BEGIN_NAMESPACE
-class DSCameraSession;
-
-//QTM_USE_NAMESPACE
-
-using DSVideoDeviceInfo = QPair<QByteArray, QString>;
-
-class DSVideoDeviceControl : public QVideoDeviceSelectorControl
-{
- Q_OBJECT
-public:
- DSVideoDeviceControl(QObject *parent = nullptr);
-
- int deviceCount() const override;
- QString deviceName(int index) const override;
- QString deviceDescription(int index) const override;
- int defaultDevice() const override;
- int selectedDevice() const override;
-
- static const QList<DSVideoDeviceInfo> &availableDevices();
-
-public Q_SLOTS:
- void setSelectedDevice(int index) override;
-
-private:
- static void updateDevices();
-
- DSCameraSession* m_session;
- int selected;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/camera/dsvideorenderer.cpp b/src/plugins/directshow/camera/dsvideorenderer.cpp
deleted file mode 100644
index cde63af65..000000000
--- a/src/plugins/directshow/camera/dsvideorenderer.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qdebug.h>
-
-#include "dsvideorenderer.h"
-
-QT_BEGIN_NAMESPACE
-
-DSVideoRendererControl::DSVideoRendererControl(DSCameraSession* session, QObject *parent)
- :QVideoRendererControl(parent),
- m_session(session)
-{
-}
-
-DSVideoRendererControl::~DSVideoRendererControl() = default;
-
-QAbstractVideoSurface* DSVideoRendererControl::surface() const
-{
- return m_surface;
-}
-
-void DSVideoRendererControl::setSurface(QAbstractVideoSurface *surface)
-{
- m_surface = surface;
- if(m_session)
- m_session->setSurface(m_surface);
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/plugins/directshow/camera/dsvideorenderer.h b/src/plugins/directshow/camera/dsvideorenderer.h
deleted file mode 100644
index a6a1f8103..000000000
--- a/src/plugins/directshow/camera/dsvideorenderer.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DSVIDEORENDERER_H
-#define DSVIDEORENDERER_H
-
-#include <qvideorenderercontrol.h>
-#include "dscamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-
-class DSVideoRendererControl : public QVideoRendererControl
-{
- Q_OBJECT
-public:
- DSVideoRendererControl(DSCameraSession* session, QObject *parent = nullptr);
- ~DSVideoRendererControl() override;
-
- QAbstractVideoSurface *surface() const override;
- void setSurface(QAbstractVideoSurface *surface) override;
-
- void setSession(DSCameraSession* session);
-
-private:
- QAbstractVideoSurface* m_surface = nullptr;
- DSCameraSession* m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // DSVIDEORENDERER_H
diff --git a/src/plugins/directshow/common/common.pri b/src/plugins/directshow/common/common.pri
deleted file mode 100644
index 43acff8a5..000000000
--- a/src/plugins/directshow/common/common.pri
+++ /dev/null
@@ -1,29 +0,0 @@
-INCLUDEPATH += $$PWD
-
-HEADERS += \
- $$PWD/directshowbasefilter.h \
- $$PWD/directshoweventloop.h \
- $$PWD/directshowglobal.h \
- $$PWD/directshowmediatype.h \
- $$PWD/directshowmediatypeenum.h \
- $$PWD/directshowobject.h \
- $$PWD/directshowpin.h \
- $$PWD/directshowpinenum.h \
- $$PWD/directshowvideobuffer.h \
- $$PWD/directshowutils.h \
- $$PWD/directshowvideoprobecontrol.h \
- $$PWD/directshowaudioprobecontrol.h \
- $$PWD/directshowsamplegrabber.h
-
-SOURCES += \
- $$PWD/directshowbasefilter.cpp \
- $$PWD/directshoweventloop.cpp \
- $$PWD/directshowmediatype.cpp \
- $$PWD/directshowmediatypeenum.cpp \
- $$PWD/directshowpin.cpp \
- $$PWD/directshowpinenum.cpp \
- $$PWD/directshowvideobuffer.cpp \
- $$PWD/directshowutils.cpp \
- $$PWD/directshowvideoprobecontrol.cpp \
- $$PWD/directshowaudioprobecontrol.cpp \
- $$PWD/directshowsamplegrabber.cpp
diff --git a/src/plugins/directshow/common/directshowaudioprobecontrol.cpp b/src/plugins/directshow/common/directshowaudioprobecontrol.cpp
deleted file mode 100644
index 55ef70178..000000000
--- a/src/plugins/directshow/common/directshowaudioprobecontrol.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowaudioprobecontrol.h"
-#include "directshowglobal.h"
-
-QT_BEGIN_NAMESPACE
-
-DirectShowAudioProbeControl::DirectShowAudioProbeControl(QObject *p)
- : QMediaAudioProbeControl(p)
-{
-
-}
-
-DirectShowAudioProbeControl::~DirectShowAudioProbeControl()
-{
- if (m_ref.deref())
- qCWarning(qtDirectShowPlugin, "QAudioProbe control destroyed while it's still being referenced!!!");
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/common/directshowaudioprobecontrol.h b/src/plugins/directshow/common/directshowaudioprobecontrol.h
deleted file mode 100644
index 034e958fd..000000000
--- a/src/plugins/directshow/common/directshowaudioprobecontrol.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWAUDIOPROBECONTROL_H
-#define DIRECTSHOWAUDIOPROBECONTROL_H
-
-#include <qmediaaudioprobecontrol.h>
-
-#include <QtCore/qglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowAudioProbeControl : public QMediaAudioProbeControl
-{
- Q_OBJECT
-public:
- explicit DirectShowAudioProbeControl(QObject *p = nullptr);
- ~DirectShowAudioProbeControl() override;
-
- bool ref() { return m_ref.ref(); }
- bool deref() { return m_ref.deref(); }
-private:
- QAtomicInt m_ref;
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWAUDIOPROBECONTROL_H
diff --git a/src/plugins/directshow/common/directshowbasefilter.cpp b/src/plugins/directshow/common/directshowbasefilter.cpp
deleted file mode 100644
index 6099981cf..000000000
--- a/src/plugins/directshow/common/directshowbasefilter.cpp
+++ /dev/null
@@ -1,251 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowbasefilter.h"
-
-#include "directshowpinenum.h"
-
-#include <mutex>
-
-QT_BEGIN_NAMESPACE
-
-DirectShowBaseFilter::DirectShowBaseFilter()
- = default;
-
-DirectShowBaseFilter::~DirectShowBaseFilter()
-{
- if (m_clock) {
- m_clock->Release();
- m_clock = nullptr;
- }
-}
-
-HRESULT DirectShowBaseFilter::GetClassID(CLSID *pClassID)
-{
- *pClassID = CLSID_NULL;
- return S_OK;
-}
-
-HRESULT DirectShowBaseFilter::NotifyEvent(long eventCode, LONG_PTR eventParam1, LONG_PTR eventParam2)
-{
- IMediaEventSink *sink = m_sink;
- if (sink) {
- if (eventCode == EC_COMPLETE)
- eventParam2 = (LONG_PTR)(IBaseFilter*)this;
-
- return sink->Notify(eventCode, eventParam1, eventParam2);
- }
- return E_NOTIMPL;
-}
-
-HRESULT DirectShowBaseFilter::Run(REFERENCE_TIME tStart)
-{
- Q_UNUSED(tStart);
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- m_startTime = tStart;
-
- if (m_state == State_Stopped){
- HRESULT hr = Pause();
- if (FAILED(hr))
- return hr;
- }
-
- m_state = State_Running;
-
- return S_OK;
-}
-
-HRESULT DirectShowBaseFilter::Pause()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- if (m_state == State_Stopped) {
- const QList<DirectShowPin *> pinList = pins();
- for (DirectShowPin *pin : pinList) {
- if (pin->isConnected()) {
- HRESULT hr = pin->setActive(true);
- if (FAILED(hr))
- return hr;
- }
- }
- }
-
- m_state = State_Paused;
-
- return S_OK;
-}
-
-HRESULT DirectShowBaseFilter::Stop()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- HRESULT hr = S_OK;
-
- if (m_state != State_Stopped) {
- const QList<DirectShowPin *> pinList = pins();
- for (DirectShowPin *pin : pinList) {
- if (pin->isConnected()) {
- HRESULT hrTmp = pin->setActive(false);
- if (FAILED(hrTmp) && SUCCEEDED(hr))
- hr = hrTmp;
- }
- }
- }
-
- m_state = State_Stopped;
-
- return hr;
-}
-
-HRESULT DirectShowBaseFilter::GetState(DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
-{
- Q_UNUSED(dwMilliSecsTimeout);
-
- if (!pState) {
- return E_POINTER;
- } else {
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- *pState = m_state;
-
- return S_OK;
- }
-}
-
-HRESULT DirectShowBaseFilter::SetSyncSource(IReferenceClock *pClock)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- if (m_clock)
- m_clock->Release();
-
- m_clock = pClock;
-
- if (m_clock)
- m_clock->AddRef();
-
- return S_OK;
-}
-
-HRESULT DirectShowBaseFilter::GetSyncSource(IReferenceClock **ppClock)
-{
- if (!ppClock)
- return E_POINTER;
-
- if (!m_clock) {
- *ppClock = nullptr;
- return S_FALSE;
- }
- m_clock->AddRef();
- *ppClock = m_clock;
- return S_OK;
-}
-
-HRESULT DirectShowBaseFilter::EnumPins(IEnumPins **ppEnum)
-{
- if (!ppEnum)
- return E_POINTER;
- *ppEnum = new DirectShowPinEnum(this);
- return S_OK;
-}
-
-HRESULT DirectShowBaseFilter::FindPin(LPCWSTR Id, IPin **ppPin)
-{
- if (!ppPin || !Id)
- return E_POINTER;
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
- const QList<DirectShowPin *> pinList = pins();
- for (DirectShowPin *pin : pinList) {
- if (pin->name() == QStringView(Id)) {
- pin->AddRef();
- *ppPin = pin;
- return S_OK;
- }
- }
-
- *ppPin = nullptr;
- return VFW_E_NOT_FOUND;
-}
-
-HRESULT DirectShowBaseFilter::JoinFilterGraph(IFilterGraph *pGraph, LPCWSTR pName)
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- m_filterName = QString::fromWCharArray(pName);
- m_graph = pGraph;
- m_sink = nullptr;
-
- if (m_graph) {
- if (SUCCEEDED(m_graph->QueryInterface(IID_PPV_ARGS(&m_sink))))
- m_sink->Release(); // we don't keep a reference on it
- }
-
- return S_OK;
-}
-
-HRESULT DirectShowBaseFilter::QueryFilterInfo(FILTER_INFO *pInfo)
-{
- if (!pInfo)
- return E_POINTER;
-
- QString name = m_filterName;
-
- if (name.length() >= MAX_FILTER_NAME)
- name.truncate(MAX_FILTER_NAME - 1);
-
- int length = name.toWCharArray(pInfo->achName);
- pInfo->achName[length] = '\0';
-
- if (m_graph)
- m_graph->AddRef();
-
- pInfo->pGraph = m_graph;
-
- return S_OK;
-}
-
-HRESULT DirectShowBaseFilter::QueryVendorInfo(LPWSTR *pVendorInfo)
-{
- Q_UNUSED(pVendorInfo);
- return E_NOTIMPL;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/common/directshowbasefilter.h b/src/plugins/directshow/common/directshowbasefilter.h
deleted file mode 100644
index ce30891d7..000000000
--- a/src/plugins/directshow/common/directshowbasefilter.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWBASEFILTER_H
-#define DIRECTSHOWBASEFILTER_H
-
-#include "directshowpin.h"
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowBaseFilter : public IBaseFilter
-{
-public:
- DirectShowBaseFilter();
- virtual ~DirectShowBaseFilter();
-
- FILTER_STATE state() const { return m_state; }
- HRESULT NotifyEvent(long eventCode, LONG_PTR eventParam1, LONG_PTR eventParam2);
-
- virtual QList<DirectShowPin *> pins() = 0;
-
- // IPersist
- STDMETHODIMP GetClassID(CLSID *pClassID) override;
-
- // IMediaFilter
- STDMETHODIMP Run(REFERENCE_TIME tStart) override;
- STDMETHODIMP Pause() override;
- STDMETHODIMP Stop() override;
-
- STDMETHODIMP GetState(DWORD dwMilliSecsTimeout, FILTER_STATE *pState) override;
-
- STDMETHODIMP SetSyncSource(IReferenceClock *pClock) override;
- STDMETHODIMP GetSyncSource(IReferenceClock **ppClock) override;
-
- // IBaseFilter
- STDMETHODIMP EnumPins(IEnumPins **ppEnum) override;
- STDMETHODIMP FindPin(LPCWSTR Id, IPin **ppPin) override;
-
- STDMETHODIMP JoinFilterGraph(IFilterGraph *pGraph, LPCWSTR pName) override;
-
- STDMETHODIMP QueryFilterInfo(FILTER_INFO *pInfo) override;
- STDMETHODIMP QueryVendorInfo(LPWSTR *pVendorInfo) override;
-
-protected:
- QRecursiveMutex m_mutex;
- FILTER_STATE m_state = State_Stopped;
- IFilterGraph *m_graph = nullptr;
- IReferenceClock *m_clock = nullptr;
- IMediaEventSink *m_sink = nullptr;
- QString m_filterName;
- REFERENCE_TIME m_startTime = 0;
-
-private:
- Q_DISABLE_COPY(DirectShowBaseFilter)
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWBASEFILTER_H
diff --git a/src/plugins/directshow/common/directshoweventloop.cpp b/src/plugins/directshow/common/directshoweventloop.cpp
deleted file mode 100644
index 692c873cf..000000000
--- a/src/plugins/directshow/common/directshoweventloop.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <directshoweventloop.h>
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qcoreevent.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowPostedEvent
-{
- Q_DISABLE_COPY(DirectShowPostedEvent)
-public:
- DirectShowPostedEvent(QObject *receiver, QEvent *event)
- : receiver(receiver)
- , event(event)
- {
- }
-
- ~DirectShowPostedEvent()
- {
- delete event;
- }
-
- QObject *receiver;
- QEvent *event;
- DirectShowPostedEvent *next = nullptr;
-};
-
-DirectShowEventLoop::DirectShowEventLoop(QObject *parent)
- : QObject(parent)
- , m_eventHandle(::CreateEvent(nullptr, FALSE, FALSE, nullptr))
- , m_waitHandle(::CreateEvent(nullptr, FALSE, FALSE, nullptr))
-{
-}
-
-DirectShowEventLoop::~DirectShowEventLoop()
-{
- ::CloseHandle(m_eventHandle);
- ::CloseHandle(m_waitHandle);
-
- for (DirectShowPostedEvent *post = m_postsHead; post; post = m_postsHead) {
- m_postsHead = m_postsHead->next;
-
- delete post;
- }
-}
-
-void DirectShowEventLoop::wait(QMutex *mutex)
-{
- ::ResetEvent(m_waitHandle);
-
- mutex->unlock();
-
- HANDLE handles[] = { m_eventHandle, m_waitHandle };
- while (::WaitForMultipleObjects(2, handles, false, INFINITE) == WAIT_OBJECT_0)
- processEvents();
-
- mutex->lock();
-}
-
-void DirectShowEventLoop::wake()
-{
- ::SetEvent(m_waitHandle);
-}
-
-void DirectShowEventLoop::postEvent(QObject *receiver, QEvent *event)
-{
- QMutexLocker locker(&m_mutex);
-
- DirectShowPostedEvent *post = new DirectShowPostedEvent(receiver, event);
-
- if (m_postsTail)
- m_postsTail->next = post;
- else
- m_postsHead = post;
-
- m_postsTail = post;
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::User));
- ::SetEvent(m_eventHandle);
-}
-
-void DirectShowEventLoop::customEvent(QEvent *event)
-{
- if (event->type() == QEvent::User) {
- processEvents();
- } else {
- QObject::customEvent(event);
- }
-}
-
-void DirectShowEventLoop::processEvents()
-{
- QMutexLocker locker(&m_mutex);
-
- ::ResetEvent(m_eventHandle);
-
- while(m_postsHead) {
- DirectShowPostedEvent *post = m_postsHead;
- m_postsHead = m_postsHead->next;
-
- if (!m_postsHead)
- m_postsTail = nullptr;
-
- locker.unlock();
- QCoreApplication::sendEvent(post->receiver, post->event);
- delete post;
- locker.relock();
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/common/directshoweventloop.h b/src/plugins/directshow/common/directshoweventloop.h
deleted file mode 100644
index 984bd23a4..000000000
--- a/src/plugins/directshow/common/directshoweventloop.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWEVENTLOOP_H
-#define DIRECTSHOWEVENTLOOP_H
-
-#include <QtCore/qmutex.h>
-#include <QtCore/qobject.h>
-#include <QtCore/qwaitcondition.h>
-
-#include <qt_windows.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowPostedEvent;
-
-class DirectShowEventLoop : public QObject
-{
- Q_OBJECT
-public:
- DirectShowEventLoop(QObject *parent = nullptr);
- ~DirectShowEventLoop() override;
-
- void wait(QMutex *mutex);
- void wake();
-
- void postEvent(QObject *object, QEvent *event);
-
-protected:
- void customEvent(QEvent *event) override;
-
-private:
- void processEvents();
-
- DirectShowPostedEvent *m_postsHead = nullptr;
- DirectShowPostedEvent *m_postsTail = nullptr;
- HANDLE m_eventHandle;
- HANDLE m_waitHandle;
- QMutex m_mutex;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/common/directshowglobal.h b/src/plugins/directshow/common/directshowglobal.h
deleted file mode 100644
index 12693e4f1..000000000
--- a/src/plugins/directshow/common/directshowglobal.h
+++ /dev/null
@@ -1,160 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWGLOBAL_H
-#define DIRECTSHOWGLOBAL_H
-
-#include <dshow.h>
-
-#include <QtCore/qglobal.h>
-#include <QtCore/qloggingcategory.h>
-
-QT_BEGIN_NAMESPACE
-
-Q_DECLARE_LOGGING_CATEGORY(qtDirectShowPlugin)
-
-QT_END_NAMESPACE
-
-template <typename T> T *com_cast(IUnknown *unknown, const IID &iid)
-{
- T *iface = nullptr;
- return unknown && unknown->QueryInterface(iid, reinterpret_cast<void **>(&iface)) == S_OK
- ? iface
- : nullptr;
-}
-
-template <typename T> T *com_new(const IID &clsid)
-{
- T *object = nullptr;
- return CoCreateInstance(
- clsid,
- nullptr,
- CLSCTX_INPROC_SERVER,
- IID_PPV_ARGS(&object)) == S_OK
- ? object
- : nullptr;
-}
-
-template <typename T> T *com_new(const IID &clsid, const IID &iid)
-{
- T *object = nullptr;
- return CoCreateInstance(
- clsid,
- nullptr,
- CLSCTX_INPROC_SERVER,
- iid,
- reinterpret_cast<void **>(&object)) == S_OK
- ? object
- : nullptr;
-}
-
-DEFINE_GUID(MEDIASUBTYPE_I420,
- 0x30323449,0x0000,0x0010,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71);
-
-#ifndef __IFilterGraph2_INTERFACE_DEFINED__
-#define __IFilterGraph2_INTERFACE_DEFINED__
-#define INTERFACE IFilterGraph2
-DECLARE_INTERFACE_(IFilterGraph2 ,IGraphBuilder)
-{
- STDMETHOD(AddSourceFilterForMoniker)(THIS_ IMoniker *, IBindCtx *, LPCWSTR,IBaseFilter **) PURE;
- STDMETHOD(ReconnectEx)(THIS_ IPin *, const AM_MEDIA_TYPE *) PURE;
- STDMETHOD(RenderEx)(IPin *, DWORD, DWORD *) PURE;
-};
-#undef INTERFACE
-#endif
-
-#ifndef __IAMFilterMiscFlags_INTERFACE_DEFINED__
-#define __IAMFilterMiscFlags_INTERFACE_DEFINED__
-#define INTERFACE IAMFilterMiscFlags
-DECLARE_INTERFACE_(IAMFilterMiscFlags ,IUnknown)
-{
- STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
- STDMETHOD_(ULONG,AddRef)(THIS) PURE;
- STDMETHOD_(ULONG,Release)(THIS) PURE;
- STDMETHOD_(ULONG,GetMiscFlags)(THIS) PURE;
-};
-#undef INTERFACE
-#endif
-
-#ifndef __IFileSourceFilter_INTERFACE_DEFINED__
-#define __IFileSourceFilter_INTERFACE_DEFINED__
-#define INTERFACE IFileSourceFilter
-DECLARE_INTERFACE_(IFileSourceFilter ,IUnknown)
-{
- STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
- STDMETHOD_(ULONG,AddRef)(THIS) PURE;
- STDMETHOD_(ULONG,Release)(THIS) PURE;
- STDMETHOD(Load)(THIS_ LPCOLESTR, const AM_MEDIA_TYPE *) PURE;
- STDMETHOD(GetCurFile)(THIS_ LPOLESTR *ppszFileName, AM_MEDIA_TYPE *) PURE;
-};
-#undef INTERFACE
-#endif
-
-#ifndef __IAMOpenProgress_INTERFACE_DEFINED__
-#define __IAMOpenProgress_INTERFACE_DEFINED__
-#undef INTERFACE
-#define INTERFACE IAMOpenProgress
-DECLARE_INTERFACE_(IAMOpenProgress ,IUnknown)
-{
- STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
- STDMETHOD_(ULONG,AddRef)(THIS) PURE;
- STDMETHOD_(ULONG,Release)(THIS) PURE;
- STDMETHOD(QueryProgress)(THIS_ LONGLONG *, LONGLONG *) PURE;
- STDMETHOD(AbortOperation)(THIS) PURE;
-};
-#undef INTERFACE
-#endif
-
-#ifndef __IFilterChain_INTERFACE_DEFINED__
-#define __IFilterChain_INTERFACE_DEFINED__
-#define INTERFACE IFilterChain
-DECLARE_INTERFACE_(IFilterChain ,IUnknown)
-{
- STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
- STDMETHOD_(ULONG,AddRef)(THIS) PURE;
- STDMETHOD_(ULONG,Release)(THIS) PURE;
- STDMETHOD(StartChain)(IBaseFilter *, IBaseFilter *) PURE;
- STDMETHOD(PauseChain)(IBaseFilter *, IBaseFilter *) PURE;
- STDMETHOD(StopChain)(IBaseFilter *, IBaseFilter *) PURE;
- STDMETHOD(RemoveChain)(IBaseFilter *, IBaseFilter *) PURE;
-};
-#undef INTERFACE
-#endif
-
-#endif
diff --git a/src/plugins/directshow/common/directshowmediatype.cpp b/src/plugins/directshow/common/directshowmediatype.cpp
deleted file mode 100644
index 3429f4848..000000000
--- a/src/plugins/directshow/common/directshowmediatype.cpp
+++ /dev/null
@@ -1,352 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowmediatype.h"
-#include "directshowglobal.h"
-
-#include <initguid.h>
-
-DEFINE_GUID(MEDIASUBTYPE_Y800, 0x30303859, 0x0000, 0x0010, 0x80, 0x00,
- 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
-
-namespace
-{
- struct TypeLookup
- {
- QVideoFrame::PixelFormat pixelFormat;
- GUID mediaType;
- };
-
- static const TypeLookup qt_typeLookup[] =
- {
- { QVideoFrame::Format_ARGB32, MEDIASUBTYPE_ARGB32 },
- { QVideoFrame::Format_RGB32, MEDIASUBTYPE_RGB32 },
- { QVideoFrame::Format_BGR24, MEDIASUBTYPE_RGB24 },
- { QVideoFrame::Format_RGB565, MEDIASUBTYPE_RGB565 },
- { QVideoFrame::Format_RGB555, MEDIASUBTYPE_RGB555 },
- { QVideoFrame::Format_AYUV444, MEDIASUBTYPE_AYUV },
- { QVideoFrame::Format_YUYV, MEDIASUBTYPE_YUY2 },
- { QVideoFrame::Format_UYVY, MEDIASUBTYPE_UYVY },
- { QVideoFrame::Format_IMC1, MEDIASUBTYPE_IMC1 },
- { QVideoFrame::Format_IMC2, MEDIASUBTYPE_IMC2 },
- { QVideoFrame::Format_IMC3, MEDIASUBTYPE_IMC3 },
- { QVideoFrame::Format_IMC4, MEDIASUBTYPE_IMC4 },
- { QVideoFrame::Format_YV12, MEDIASUBTYPE_YV12 },
- { QVideoFrame::Format_NV12, MEDIASUBTYPE_NV12 },
- { QVideoFrame::Format_YUV420P, MEDIASUBTYPE_IYUV },
- { QVideoFrame::Format_YUV420P, MEDIASUBTYPE_I420 },
- { QVideoFrame::Format_Jpeg, MEDIASUBTYPE_MJPG },
- { QVideoFrame::Format_Y8, MEDIASUBTYPE_Y800 },
- };
-}
-
-bool DirectShowMediaType::isPartiallySpecified(const AM_MEDIA_TYPE *mediaType)
-{
- return mediaType->majortype == GUID_NULL || mediaType->formattype == GUID_NULL;
-}
-
-DirectShowMediaType::DirectShowMediaType()
- : mediaType({ GUID_NULL, GUID_NULL, TRUE, FALSE, 1, GUID_NULL, nullptr, 0, nullptr})
-{
-}
-
-DirectShowMediaType::DirectShowMediaType(const AM_MEDIA_TYPE &type)
- : DirectShowMediaType()
-{
- copy(&mediaType, &type);
-}
-
-DirectShowMediaType::DirectShowMediaType(AM_MEDIA_TYPE &&type)
- : DirectShowMediaType()
-{
- move(&mediaType, type);
-}
-
-DirectShowMediaType::DirectShowMediaType(const DirectShowMediaType &other)
- : DirectShowMediaType()
-{
- copy(&mediaType, &other.mediaType);
-}
-
-DirectShowMediaType::DirectShowMediaType(DirectShowMediaType &&other) noexcept
- : DirectShowMediaType()
-{
- move(&mediaType, other.mediaType);
-}
-
-DirectShowMediaType &DirectShowMediaType::operator=(const DirectShowMediaType &other)
-{
- copy(&mediaType, &other.mediaType);
- return *this;
-}
-
-DirectShowMediaType &DirectShowMediaType::operator=(DirectShowMediaType &&other) noexcept
-{
- move(&mediaType, other.mediaType);
- return *this;
-}
-
-void DirectShowMediaType::init(AM_MEDIA_TYPE *type)
-{
- Q_ASSERT(type);
- SecureZeroMemory(reinterpret_cast<void *>(type), sizeof(AM_MEDIA_TYPE));
- type->lSampleSize = 1;
- type->bFixedSizeSamples = TRUE;
-}
-
-void DirectShowMediaType::copy(AM_MEDIA_TYPE *target, const AM_MEDIA_TYPE *source)
-{
- if (!(target && source))
- return;
-
- if (target == source)
- return;
-
- clear(*target);
-
- copyToUninitialized(target, source);
-}
-
-void DirectShowMediaType::copyToUninitialized(AM_MEDIA_TYPE *target, const AM_MEDIA_TYPE *source)
-{
- *target = *source;
-
- if (source->cbFormat > 0) {
- target->pbFormat = reinterpret_cast<PBYTE>(CoTaskMemAlloc(source->cbFormat));
- memcpy(target->pbFormat, source->pbFormat, source->cbFormat);
- }
- if (target->pUnk)
- target->pUnk->AddRef();
-}
-
-void DirectShowMediaType::move(AM_MEDIA_TYPE *target, AM_MEDIA_TYPE **source)
-{
- if (!target || !source || !(*source))
- return;
-
- if (target == *source)
- return;
-
- clear(*target);
- *target = *(*source);
- SecureZeroMemory(reinterpret_cast<void *>(*source), sizeof(AM_MEDIA_TYPE));
- *source = nullptr;
-}
-
-void DirectShowMediaType::move(AM_MEDIA_TYPE *target, AM_MEDIA_TYPE &source)
-{
- AM_MEDIA_TYPE *srcPtr = &source;
- move(target, &srcPtr);
-}
-
-/**
- * @brief DirectShowMediaType::deleteType - Used for AM_MEDIA_TYPE structures that have
- * been allocated by CoTaskMemAlloc or CreateMediaType.
- * @param type
- */
-void DirectShowMediaType::deleteType(AM_MEDIA_TYPE *type)
-{
- if (!type)
- return;
-
- clear(*type);
- CoTaskMemFree(type);
-}
-
-bool DirectShowMediaType::isCompatible(const AM_MEDIA_TYPE *a, const AM_MEDIA_TYPE *b)
-{
- if (b->majortype != GUID_NULL && a->majortype != b->majortype)
- return false;
-
- if (b->subtype != GUID_NULL && a->subtype != b->subtype)
- return false;
-
- if (b->formattype != GUID_NULL) {
- if (a->formattype != b->formattype)
- return false;
- if (a->cbFormat != b->cbFormat)
- return false;
- if (a->cbFormat != 0 && memcmp(a->pbFormat, b->pbFormat, a->cbFormat) != 0)
- return false;
- }
-
- return true;
-}
-
-/**
- * @brief DirectShowMediaType::clear - Clears all member data, and releases allocated buffers.
- * Use this to release automatic AM_MEDIA_TYPE structures.
- * @param type
- */
-void DirectShowMediaType::clear(AM_MEDIA_TYPE &type)
-{
- if (type.cbFormat > 0)
- CoTaskMemFree(type.pbFormat);
-
- if (type.pUnk)
- type.pUnk->Release();
-
- SecureZeroMemory(&type, sizeof(type));
-}
-
-
-GUID DirectShowMediaType::convertPixelFormat(QVideoFrame::PixelFormat format)
-{
- for (const auto &lookupType : qt_typeLookup) {
- if (lookupType.pixelFormat == format)
- return lookupType.mediaType;
- }
-
- return MEDIASUBTYPE_None;
-}
-
-QVideoSurfaceFormat DirectShowMediaType::videoFormatFromType(const AM_MEDIA_TYPE *type)
-{
- if (!type)
- return QVideoSurfaceFormat();
-
- for (const auto &lookupType : qt_typeLookup) {
- if (IsEqualGUID(lookupType.mediaType, type->subtype) && type->cbFormat > 0) {
- if (IsEqualGUID(type->formattype, FORMAT_VideoInfo)) {
- VIDEOINFOHEADER *header = reinterpret_cast<VIDEOINFOHEADER *>(type->pbFormat);
-
- QVideoSurfaceFormat format(
- QSize(header->bmiHeader.biWidth, qAbs(header->bmiHeader.biHeight)),
- lookupType.pixelFormat);
-
- if (header->AvgTimePerFrame > 0)
- format.setFrameRate(10000 /header->AvgTimePerFrame);
-
- format.setScanLineDirection(scanLineDirection(format.pixelFormat(), header->bmiHeader));
-
- return format;
- }
- if (IsEqualGUID(type->formattype, FORMAT_VideoInfo2)) {
- VIDEOINFOHEADER2 *header = reinterpret_cast<VIDEOINFOHEADER2 *>(type->pbFormat);
-
- QVideoSurfaceFormat format(
- QSize(header->bmiHeader.biWidth, qAbs(header->bmiHeader.biHeight)),
- lookupType.pixelFormat);
-
- if (header->AvgTimePerFrame > 0)
- format.setFrameRate(10000 / header->AvgTimePerFrame);
-
- format.setScanLineDirection(scanLineDirection(format.pixelFormat(), header->bmiHeader));
-
- return format;
- }
- }
- }
- return QVideoSurfaceFormat();
-}
-
-QVideoFrame::PixelFormat DirectShowMediaType::pixelFormatFromType(const AM_MEDIA_TYPE *type)
-{
- if (!type)
- return QVideoFrame::Format_Invalid;
-
- for (const auto &lookupType : qt_typeLookup) {
- if (IsEqualGUID(lookupType.mediaType, type->subtype))
- return lookupType.pixelFormat;
- }
-
- return QVideoFrame::Format_Invalid;
-}
-
-#define PAD_TO_DWORD(x) (((x) + 3) & ~3)
-int DirectShowMediaType::bytesPerLine(const QVideoSurfaceFormat &format)
-{
- switch (format.pixelFormat()) {
- // 32 bpp packed formats.
- case QVideoFrame::Format_ARGB32:
- case QVideoFrame::Format_RGB32:
- case QVideoFrame::Format_AYUV444:
- return format.frameWidth() * 4;
- // 24 bpp packed formats.
- case QVideoFrame::Format_RGB24:
- case QVideoFrame::Format_BGR24:
- return PAD_TO_DWORD(format.frameWidth() * 3);
- // 16 bpp packed formats.
- case QVideoFrame::Format_RGB565:
- case QVideoFrame::Format_RGB555:
- case QVideoFrame::Format_YUYV:
- case QVideoFrame::Format_UYVY:
- return PAD_TO_DWORD(format.frameWidth() * 2);
- // Planar formats.
- case QVideoFrame::Format_YV12:
- case QVideoFrame::Format_YUV420P:
- case QVideoFrame::Format_IMC1:
- case QVideoFrame::Format_IMC2:
- case QVideoFrame::Format_IMC3:
- case QVideoFrame::Format_IMC4:
- case QVideoFrame::Format_NV12:
- return format.frameWidth();
- default:
- return 0;
- }
-}
-
-QVideoSurfaceFormat::Direction DirectShowMediaType::scanLineDirection(QVideoFrame::PixelFormat pixelFormat, const BITMAPINFOHEADER &bmiHeader)
-{
- /* MSDN http://msdn.microsoft.com/en-us/library/windows/desktop/dd318229(v=vs.85).aspx */
- /* For uncompressed RGB bitmaps:
- * if biHeight is positive, the bitmap is a bottom-up DIB with the origin at the lower left corner.
- * If biHeight is negative, the bitmap is a top-down DIB with the origin at the upper left corner.
- *
- * For YUV bitmaps:
- * the bitmap is always top-down, regardless of the sign of biHeight.
- * Decoders should offer YUV formats with postive biHeight, but for backward compatibility they should accept YUV formats with either positive or negative biHeight.
- *
- * For compressed formats:
- * biHeight must be positive, regardless of image orientation.
- */
- switch (pixelFormat)
- {
- case QVideoFrame::Format_ARGB32:
- case QVideoFrame::Format_RGB32:
- case QVideoFrame::Format_RGB24:
- case QVideoFrame::Format_RGB565:
- case QVideoFrame::Format_RGB555:
- return bmiHeader.biHeight < 0
- ? QVideoSurfaceFormat::TopToBottom
- : QVideoSurfaceFormat::BottomToTop;
- default:
- return QVideoSurfaceFormat::TopToBottom;
- }
-}
diff --git a/src/plugins/directshow/common/directshowmediatype.h b/src/plugins/directshow/common/directshowmediatype.h
deleted file mode 100644
index ee44329a5..000000000
--- a/src/plugins/directshow/common/directshowmediatype.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWMEDIATYPE_H
-#define DIRECTSHOWMEDIATYPE_H
-
-#include <dshow.h>
-
-#include <qvideosurfaceformat.h>
-
-#include <dvdmedia.h>
-#include <QtCore/qglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowMediaType
-{
-public:
- DirectShowMediaType();
- DirectShowMediaType(const DirectShowMediaType &other);
- DirectShowMediaType(DirectShowMediaType &&other) noexcept;
- explicit DirectShowMediaType(const AM_MEDIA_TYPE &type);
- explicit DirectShowMediaType(AM_MEDIA_TYPE &&type);
- ~DirectShowMediaType() { clear(mediaType); }
-
- DirectShowMediaType &operator =(const DirectShowMediaType &other);
- DirectShowMediaType &operator =(DirectShowMediaType &&other) noexcept;
-
- void clear() { clear(mediaType); }
-
- inline AM_MEDIA_TYPE *operator &() Q_DECL_NOTHROW { return &mediaType; }
- inline AM_MEDIA_TYPE *operator ->() Q_DECL_NOTHROW { return &mediaType; }
-
- inline const AM_MEDIA_TYPE *operator &() const Q_DECL_NOTHROW { return &mediaType; }
- inline const AM_MEDIA_TYPE *operator ->() const Q_DECL_NOTHROW { return &mediaType; }
-
- static void init(AM_MEDIA_TYPE *type);
- static void copy(AM_MEDIA_TYPE *target, const AM_MEDIA_TYPE *source);
- static void copyToUninitialized(AM_MEDIA_TYPE *target, const AM_MEDIA_TYPE *source);
- static void move(AM_MEDIA_TYPE *target, AM_MEDIA_TYPE **source);
- static void move(AM_MEDIA_TYPE *target, AM_MEDIA_TYPE &source);
- static void clear(AM_MEDIA_TYPE &type);
- static void deleteType(AM_MEDIA_TYPE *type);
- static bool isPartiallySpecified(const AM_MEDIA_TYPE *mediaType);
- static bool isCompatible(const AM_MEDIA_TYPE *a, const AM_MEDIA_TYPE *b);
- static GUID convertPixelFormat(QVideoFrame::PixelFormat format);
-
- static QVideoSurfaceFormat videoFormatFromType(const AM_MEDIA_TYPE *type);
- static QVideoFrame::PixelFormat pixelFormatFromType(const AM_MEDIA_TYPE *type);
- static int bytesPerLine(const QVideoSurfaceFormat &format);
- static QVideoSurfaceFormat::Direction scanLineDirection(QVideoFrame::PixelFormat pixelFormat, const BITMAPINFOHEADER &bmiHeader);
-
-private:
- AM_MEDIA_TYPE mediaType;
-};
-
-Q_DECLARE_TYPEINFO(DirectShowMediaType, Q_MOVABLE_TYPE);
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/common/directshowmediatypeenum.cpp b/src/plugins/directshow/common/directshowmediatypeenum.cpp
deleted file mode 100644
index 02281bb98..000000000
--- a/src/plugins/directshow/common/directshowmediatypeenum.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowmediatypeenum.h"
-
-#include "directshowpin.h"
-
-DirectShowMediaTypeEnum::DirectShowMediaTypeEnum(DirectShowPin *pin)
- : m_pin(pin)
- , m_mediaTypes(pin->supportedMediaTypes())
-{
- m_pin->AddRef();
-}
-
-DirectShowMediaTypeEnum::DirectShowMediaTypeEnum(const QList<DirectShowMediaType> &types)
- : m_mediaTypes(types)
-{
-}
-
-DirectShowMediaTypeEnum::~DirectShowMediaTypeEnum()
-{
- if (m_pin)
- m_pin->Release();
-}
-
-HRESULT DirectShowMediaTypeEnum::QueryInterface(REFIID riid, void **ppv)
-{
- if (ppv == nullptr)
- return E_POINTER;
- if (riid == IID_IUnknown)
- *ppv = static_cast<IUnknown *>(this);
- else if (riid == IID_IEnumMediaTypes)
- *ppv = static_cast<IEnumMediaTypes *>(this);
- else
- return E_NOINTERFACE;
- AddRef();
- return S_OK;
-}
-
-HRESULT DirectShowMediaTypeEnum::Next(ULONG cMediaTypes, AM_MEDIA_TYPE **ppMediaTypes, ULONG *pcFetched)
-{
- if (!ppMediaTypes || (!pcFetched && cMediaTypes != 1))
- return E_POINTER;
-
- ULONG count = qBound<ULONG>(0, cMediaTypes, m_mediaTypes.count() - m_index);
-
- for (ULONG i = 0; i < count; ++i, ++m_index) {
- ppMediaTypes[i] = reinterpret_cast<AM_MEDIA_TYPE *>(CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE)));
- DirectShowMediaType::copyToUninitialized(ppMediaTypes[i], &m_mediaTypes.at(m_index));
- }
-
- if (pcFetched)
- *pcFetched = count;
-
- return count == cMediaTypes ? S_OK : S_FALSE;
-}
-
-HRESULT DirectShowMediaTypeEnum::Skip(ULONG cMediaTypes)
-{
- m_index = qMin(int(m_index + cMediaTypes), m_mediaTypes.count());
- return m_index < m_mediaTypes.count() ? S_OK : S_FALSE;
-}
-
-HRESULT DirectShowMediaTypeEnum::Reset()
-{
- m_index = 0;
- return S_OK;
-}
-
-HRESULT DirectShowMediaTypeEnum::Clone(IEnumMediaTypes **ppEnum)
-{
- if (!ppEnum)
- return E_POINTER;
- *ppEnum = m_pin ? new DirectShowMediaTypeEnum(m_pin) : new DirectShowMediaTypeEnum(m_mediaTypes);
- return S_OK;
-}
-
diff --git a/src/plugins/directshow/common/directshowmediatypeenum.h b/src/plugins/directshow/common/directshowmediatypeenum.h
deleted file mode 100644
index a5c347004..000000000
--- a/src/plugins/directshow/common/directshowmediatypeenum.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWMEDIATYPEENUM_H
-#define DIRECTSHOWMEDIATYPEENUM_H
-
-#include "directshowobject.h"
-#include <qlist.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowPin;
-class DirectShowMediaType;
-
-class DirectShowMediaTypeEnum : public IEnumMediaTypes
-{
- COM_REF_MIXIN
-public:
- DirectShowMediaTypeEnum(DirectShowPin *pin);
- DirectShowMediaTypeEnum(const QList<DirectShowMediaType> &types);
- virtual ~DirectShowMediaTypeEnum();
-
- STDMETHODIMP QueryInterface(REFIID riid, void **ppv) override;
-
- // IEnumMediaTypes
- STDMETHODIMP Next(ULONG cMediaTypes, AM_MEDIA_TYPE **ppMediaTypes, ULONG *pcFetched) override;
- STDMETHODIMP Skip(ULONG cMediaTypes) override;
- STDMETHODIMP Reset() override;
- STDMETHODIMP Clone(IEnumMediaTypes **ppEnum) override;
-
-private:
- Q_DISABLE_COPY(DirectShowMediaTypeEnum)
-
- DirectShowPin *m_pin = nullptr;
- QList<DirectShowMediaType> m_mediaTypes;
- int m_index = 0;
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWMEDIATYPEENUM_H
diff --git a/src/plugins/directshow/common/directshowobject.h b/src/plugins/directshow/common/directshowobject.h
deleted file mode 100644
index 5a8c05a3e..000000000
--- a/src/plugins/directshow/common/directshowobject.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWOBJECT_H
-#define DIRECTSHOWOBJECT_H
-
-#include "directshowglobal.h"
-
-QT_BEGIN_NAMESPACE
-
-#define COM_REF_MIXIN \
- volatile ULONG m_ref = 1; \
-public: \
- STDMETHODIMP_(ULONG) AddRef() override \
- { \
- return InterlockedIncrement(&m_ref); \
- } \
- STDMETHODIMP_(ULONG) Release() override \
- { \
- const ULONG ref = InterlockedDecrement(&m_ref); \
- if (ref == 0) \
- delete this; \
- return ref; \
- }
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWOBJECT_H
diff --git a/src/plugins/directshow/common/directshowpin.cpp b/src/plugins/directshow/common/directshowpin.cpp
deleted file mode 100644
index d80b0b08e..000000000
--- a/src/plugins/directshow/common/directshowpin.cpp
+++ /dev/null
@@ -1,696 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowpin.h"
-
-#include "directshowmediatype.h"
-#include "directshowbasefilter.h"
-#include "directshowmediatypeenum.h"
-
-#include <qdebug.h>
-
-#include <mutex>
-
-QT_BEGIN_NAMESPACE
-
-DirectShowPin::DirectShowPin(DirectShowBaseFilter *filter, const QString &name, PIN_DIRECTION direction)
- : m_filter(filter)
- , m_name(name)
- , m_direction(direction)
-{
-}
-
-DirectShowPin::~DirectShowPin() = default;
-
-HRESULT DirectShowPin::Connect(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt)
-{
- if (!pReceivePin)
- return E_POINTER;
-
- HRESULT hr = E_FAIL;
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- if (m_peerPin)
- return VFW_E_ALREADY_CONNECTED;
- if (m_filter->state() != State_Stopped)
- return VFW_E_NOT_STOPPED;
-
- PIN_DIRECTION pd;
- pReceivePin->QueryDirection(&pd);
- if (pd == m_direction)
- return VFW_E_INVALID_DIRECTION;
-
- if (pmt != nullptr && DirectShowMediaType::isPartiallySpecified(pmt)) {
- // If the type is fully specified, use it
- hr = tryConnect(pReceivePin, pmt);
- } else {
- IEnumMediaTypes *enumMediaTypes = nullptr;
-
- // First, try the receiving pin's preferred types
- if (SUCCEEDED(pReceivePin->EnumMediaTypes(&enumMediaTypes))) {
- hr = tryMediaTypes(pReceivePin, pmt, enumMediaTypes);
- enumMediaTypes->Release();
- }
- // Then, try this pin's preferred types
- if (FAILED(hr) && SUCCEEDED(EnumMediaTypes(&enumMediaTypes))) {
- hr = tryMediaTypes(pReceivePin, pmt, enumMediaTypes);
- enumMediaTypes->Release();
- }
- }
-
- if (FAILED(hr)) {
- return ((hr != E_FAIL) && (hr != E_INVALIDARG) && (hr != VFW_E_TYPE_NOT_ACCEPTED))
- ? hr : VFW_E_NO_ACCEPTABLE_TYPES;
- }
-
- return S_OK;
-}
-
-HRESULT DirectShowPin::tryMediaTypes(IPin *pin, const AM_MEDIA_TYPE *partialType, IEnumMediaTypes *enumMediaTypes)
-{
- HRESULT hr = enumMediaTypes->Reset();
- if (FAILED(hr))
- return hr;
-
- AM_MEDIA_TYPE *mediaType = nullptr;
- ULONG mediaCount = 0;
- HRESULT hrFailure = VFW_E_NO_ACCEPTABLE_TYPES;
-
- for (; enumMediaTypes->Next(1, &mediaType, &mediaCount) == S_OK;) {
-
- if (mediaType && (partialType == nullptr || DirectShowMediaType::isCompatible(mediaType, partialType))) {
- hr = tryConnect(pin, mediaType);
-
- if (FAILED(hr) && (hr != E_FAIL)
- && (hr != E_INVALIDARG)
- && (hr != VFW_E_TYPE_NOT_ACCEPTED)) {
- hrFailure = hr;
- }
- }
-
- if (mediaType)
- DirectShowMediaType::deleteType(mediaType);
-
- if (SUCCEEDED(hr))
- return S_OK;
- }
-
- return hrFailure;
-}
-
-HRESULT DirectShowPin::tryConnect(IPin *pin, const AM_MEDIA_TYPE *type)
-{
- if (!isMediaTypeSupported(type))
- return VFW_E_TYPE_NOT_ACCEPTED;
-
- m_peerPin = pin;
- m_peerPin->AddRef();
-
- HRESULT hr;
- if (!setMediaType(type)) {
- hr = VFW_E_TYPE_NOT_ACCEPTED;
- } else {
- hr = pin->ReceiveConnection(this, type);
- if (SUCCEEDED(hr)) {
- hr = completeConnection(pin);
- if (FAILED(hr))
- pin->Disconnect();
- }
- }
-
- if (FAILED(hr)) {
- connectionEnded();
- m_peerPin->Release();
- m_peerPin = nullptr;
- setMediaType(nullptr);
- return hr;
- }
-
- return S_OK;
-}
-
-HRESULT DirectShowPin::ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt)
-{
- if (!pConnector || !pmt)
- return E_POINTER;
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- if (m_peerPin)
- return VFW_E_ALREADY_CONNECTED;
- if (m_filter->state() != State_Stopped)
- return VFW_E_NOT_STOPPED;
-
- PIN_DIRECTION pd;
- pConnector->QueryDirection(&pd);
- if (pd == m_direction)
- return VFW_E_INVALID_DIRECTION;
-
- if (!isMediaTypeSupported(pmt))
- return VFW_E_TYPE_NOT_ACCEPTED;
-
- m_peerPin = pConnector;
- m_peerPin->AddRef();
-
- HRESULT hr;
- if (!setMediaType(pmt))
- hr = VFW_E_TYPE_NOT_ACCEPTED;
- else
- hr = completeConnection(pConnector);
-
- if (FAILED(hr)) {
- connectionEnded();
- m_peerPin->Release();
- m_peerPin = nullptr;
- setMediaType(nullptr);
- return hr;
- }
-
- return S_OK;
-}
-
-HRESULT DirectShowPin::Disconnect()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- if (m_filter->state() != State_Stopped)
- return VFW_E_NOT_STOPPED;
-
- if (m_peerPin) {
- HRESULT hr = connectionEnded();
- if (FAILED(hr))
- return hr;
-
- m_peerPin->Release();
- m_peerPin = nullptr;
-
- setMediaType(nullptr);
-
- return S_OK;
- }
-
- return S_FALSE;
-}
-
-HRESULT DirectShowPin::ConnectedTo(IPin **ppPin)
-{
- if (!ppPin)
- return E_POINTER;
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
- if (!m_peerPin) {
- *ppPin = nullptr;
- return VFW_E_NOT_CONNECTED;
- }
- m_peerPin->AddRef();
- *ppPin = m_peerPin;
- return S_OK;
-}
-
-HRESULT DirectShowPin::ConnectionMediaType(AM_MEDIA_TYPE *pmt)
-{
- if (!pmt)
- return E_POINTER;
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
- if (!m_peerPin) {
- DirectShowMediaType::init(pmt);
- return VFW_E_NOT_CONNECTED;
- }
- DirectShowMediaType::copy(pmt, &m_mediaType);
- return S_OK;
-}
-
-HRESULT DirectShowPin::QueryPinInfo(PIN_INFO *pInfo)
-{
- if (!pInfo)
- return E_POINTER;
-
- pInfo->pFilter = m_filter;
- if (m_filter)
- m_filter->AddRef();
- pInfo->dir = m_direction;
-
- QString name = m_name;
- if (name.length() >= MAX_PIN_NAME)
- name.truncate(MAX_PIN_NAME - 1);
- int length = name.toWCharArray(pInfo->achName);
- pInfo->achName[length] = '\0';
-
- return S_OK;
-}
-
-HRESULT DirectShowPin::QueryId(LPWSTR *Id)
-{
- if (!Id)
- return E_POINTER;
- const int bytes = (m_name.length() + 1) * 2;
- *Id = static_cast<LPWSTR>(::CoTaskMemAlloc(bytes));
- ::memcpy(*Id, m_name.utf16(), bytes);
- return S_OK;
-}
-
-HRESULT DirectShowPin::QueryAccept(const AM_MEDIA_TYPE *pmt)
-{
- if (!pmt)
- return E_POINTER;
-
- if (!isMediaTypeSupported(pmt))
- return S_FALSE;
-
- return S_OK;
-}
-
-HRESULT DirectShowPin::EnumMediaTypes(IEnumMediaTypes **ppEnum)
-{
- if (!ppEnum)
- return E_POINTER;
- *ppEnum = new DirectShowMediaTypeEnum(this);
- return S_OK;
-}
-
-HRESULT DirectShowPin::QueryInternalConnections(IPin **apPin, ULONG *nPin)
-{
- Q_UNUSED(apPin);
- Q_UNUSED(nPin);
- return E_NOTIMPL;
-}
-
-HRESULT DirectShowPin::EndOfStream()
-{
- return S_OK;
-}
-
-HRESULT DirectShowPin::BeginFlush()
-{
- return E_UNEXPECTED;
-}
-
-HRESULT DirectShowPin::EndFlush()
-{
- return E_UNEXPECTED;
-}
-
-HRESULT DirectShowPin::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
-{
- Q_UNUSED(tStart);
- Q_UNUSED(tStop);
- Q_UNUSED(dRate);
- return S_OK;
-}
-
-HRESULT DirectShowPin::QueryDirection(PIN_DIRECTION *pPinDir)
-{
- if (!pPinDir)
- return E_POINTER;
- *pPinDir = m_direction;
- return S_OK;
-}
-
-QList<DirectShowMediaType> DirectShowPin::supportedMediaTypes()
-{
- return QList<DirectShowMediaType>();
-}
-
-bool DirectShowPin::setMediaType(const AM_MEDIA_TYPE *type)
-{
- if (!type)
- m_mediaType.clear();
- else
- DirectShowMediaType::copy(&m_mediaType, type);
-
- return true;
-}
-
-HRESULT DirectShowPin::completeConnection(IPin *pin)
-{
- Q_UNUSED(pin);
- return S_OK;
-}
-
-HRESULT DirectShowPin::connectionEnded()
-{
- return S_OK;
-}
-
-HRESULT DirectShowPin::setActive(bool active)
-{
- Q_UNUSED(active);
- return S_OK;
-}
-
-
-/* DirectShowOutputPin */
-
-DirectShowOutputPin::DirectShowOutputPin(DirectShowBaseFilter *filter, const QString &name)
- : DirectShowPin(filter, name, PINDIR_OUTPUT)
-{
-
-}
-
-DirectShowOutputPin::~DirectShowOutputPin() = default;
-
-HRESULT DirectShowOutputPin::completeConnection(IPin *pin)
-{
- if (!pin)
- return E_POINTER;
-
- Q_ASSERT(m_inputPin == nullptr);
- Q_ASSERT(m_allocator == nullptr);
-
- HRESULT hr = pin->QueryInterface(IID_PPV_ARGS(&m_inputPin));
- if (FAILED(hr))
- return hr;
-
- ALLOCATOR_PROPERTIES prop;
- ZeroMemory(&prop, sizeof(prop));
- m_inputPin->GetAllocatorRequirements(&prop);
- if (prop.cBuffers <= 0)
- prop.cBuffers = 1;
- if (prop.cbBuffer <= 0)
- prop.cbBuffer = 1;
- if (prop.cbAlign <= 0)
- prop.cbAlign = 1;
-
- // Use the connected input pin's allocator if it has one
- hr = m_inputPin->GetAllocator(&m_allocator);
- if (SUCCEEDED(hr)) {
- ALLOCATOR_PROPERTIES actualProperties;
- hr = m_allocator->SetProperties(&prop, &actualProperties);
-
- if (SUCCEEDED(hr)) {
- hr = m_inputPin->NotifyAllocator(m_allocator, FALSE);
- if (SUCCEEDED(hr))
- return S_OK;
- }
-
- m_allocator->Release();
- m_allocator = nullptr;
- }
-
- // Otherwise, allocate its own allocator
- m_allocator = com_new<IMemAllocator>(CLSID_MemoryAllocator);
- if (!m_allocator) {
- hr = E_OUTOFMEMORY;
- } else {
- ALLOCATOR_PROPERTIES actualProperties;
- hr = m_allocator->SetProperties(&prop, &actualProperties);
-
- if (SUCCEEDED(hr)) {
- hr = m_inputPin->NotifyAllocator(m_allocator, FALSE);
- if (SUCCEEDED(hr))
- return S_OK;
- }
-
- m_allocator->Release();
- m_allocator = nullptr;
- }
-
- return hr;
-}
-
-HRESULT DirectShowOutputPin::connectionEnded()
-{
- if (m_allocator) {
- HRESULT hr = m_allocator->Decommit();
- if (FAILED(hr))
- return hr;
-
- m_allocator->Release();
- m_allocator = nullptr;
- }
-
- if (m_inputPin) {
- m_inputPin->Release();
- m_inputPin = nullptr;
- }
-
- return S_OK;
-}
-
-HRESULT DirectShowOutputPin::setActive(bool active)
-{
- if (!m_allocator)
- return VFW_E_NO_ALLOCATOR;
-
- return active ? m_allocator->Commit()
- : m_allocator->Decommit();
-}
-
-HRESULT DirectShowOutputPin::EndOfStream()
-{
- return E_UNEXPECTED;
-}
-
-
-/* DirectShowInputPin */
-
-DirectShowInputPin::DirectShowInputPin(DirectShowBaseFilter *filter, const QString &name)
- : DirectShowPin(filter, name, PINDIR_INPUT)
-{
- ZeroMemory(&m_sampleProperties, sizeof(m_sampleProperties));
-}
-
-DirectShowInputPin::~DirectShowInputPin() = default;
-
-HRESULT DirectShowInputPin::connectionEnded()
-{
- if (m_allocator) {
- HRESULT hr = m_allocator->Decommit();
- if (FAILED(hr))
- return hr;
-
- m_allocator->Release();
- m_allocator = nullptr;
- }
-
- return S_OK;
-}
-
-HRESULT DirectShowInputPin::setActive(bool active)
-{
- if (!active) {
- m_inErrorState = false;
-
- if (!m_allocator)
- return VFW_E_NO_ALLOCATOR;
-
- m_flushing = false;
- return m_allocator->Decommit();
- }
-
- return S_OK;
-}
-
-HRESULT DirectShowInputPin::EndOfStream()
-{
- if (m_filter->state() == State_Stopped)
- return VFW_E_WRONG_STATE;
- if (m_flushing)
- return S_FALSE;
- if (m_inErrorState)
- return VFW_E_RUNTIME_ERROR;
-
- return S_OK;
-}
-
-HRESULT DirectShowInputPin::BeginFlush()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
- m_flushing = true;
- return S_OK;
-}
-
-HRESULT DirectShowInputPin::EndFlush()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
- m_flushing = false;
- m_inErrorState = false;
- return S_OK;
-}
-
-HRESULT DirectShowInputPin::GetAllocator(IMemAllocator **ppAllocator)
-{
- if (!ppAllocator)
- return E_POINTER;
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- if (!m_allocator) {
- m_allocator = com_new<IMemAllocator>(CLSID_MemoryAllocator);;
- if (!m_allocator)
- return E_OUTOFMEMORY;
- }
-
- *ppAllocator = m_allocator;
- m_allocator->AddRef();
-
- return S_OK;
-}
-
-HRESULT DirectShowInputPin::NotifyAllocator(IMemAllocator *pAllocator, BOOL bReadOnly)
-{
- Q_UNUSED(bReadOnly);
-
- if (!pAllocator)
- return E_POINTER;
-
- const std::lock_guard<QRecursiveMutex> locker(m_mutex);
-
- if (m_allocator)
- m_allocator->Release();
-
- m_allocator = pAllocator;
- m_allocator->AddRef();
-
- return S_OK;
-}
-
-HRESULT DirectShowInputPin::GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps)
-{
- Q_UNUSED(pProps);
- return E_NOTIMPL;
-}
-
-HRESULT DirectShowInputPin::Receive(IMediaSample *pSample)
-{
- if (!pSample)
- return E_POINTER;
- if (m_filter->state() == State_Stopped)
- return VFW_E_WRONG_STATE;
- if (m_flushing)
- return S_FALSE;
- if (m_inErrorState)
- return VFW_E_RUNTIME_ERROR;
-
- HRESULT hr = S_OK;
-
- IMediaSample2 *sample2;
- if (SUCCEEDED(pSample->QueryInterface(IID_PPV_ARGS(&sample2)))) {
- hr = sample2->GetProperties(sizeof(m_sampleProperties),
- reinterpret_cast<PBYTE>(&m_sampleProperties));
- sample2->Release();
- if (FAILED(hr))
- return hr;
- } else {
- m_sampleProperties.cbData = sizeof(m_sampleProperties);
- m_sampleProperties.dwTypeSpecificFlags = 0;
- m_sampleProperties.dwStreamId = AM_STREAM_MEDIA;
- m_sampleProperties.dwSampleFlags = 0;
- if (pSample->IsDiscontinuity() == S_OK)
- m_sampleProperties.dwSampleFlags |= AM_SAMPLE_DATADISCONTINUITY;
- if (pSample->IsPreroll() == S_OK)
- m_sampleProperties.dwSampleFlags |= AM_SAMPLE_PREROLL;
- if (pSample->IsSyncPoint() == S_OK)
- m_sampleProperties.dwSampleFlags |= AM_SAMPLE_SPLICEPOINT;
- if (SUCCEEDED(pSample->GetTime(&m_sampleProperties.tStart,
- &m_sampleProperties.tStop))) {
- m_sampleProperties.dwSampleFlags |= AM_SAMPLE_TIMEVALID | AM_SAMPLE_STOPVALID;
- }
- if (pSample->GetMediaType(&m_sampleProperties.pMediaType) == S_OK)
- m_sampleProperties.dwSampleFlags |= AM_SAMPLE_TYPECHANGED;
- pSample->GetPointer(&m_sampleProperties.pbBuffer);
- m_sampleProperties.lActual = pSample->GetActualDataLength();
- m_sampleProperties.cbBuffer = pSample->GetSize();
- }
-
-
- if (!(m_sampleProperties.dwSampleFlags & AM_SAMPLE_TYPECHANGED))
- return S_OK;
-
- if (isMediaTypeSupported(m_sampleProperties.pMediaType))
- return S_OK;
-
- m_inErrorState = true;
- EndOfStream();
- m_filter->NotifyEvent(EC_ERRORABORT, VFW_E_TYPE_NOT_ACCEPTED, 0);
- return VFW_E_INVALIDMEDIATYPE;
-}
-
-HRESULT DirectShowInputPin::ReceiveMultiple(IMediaSample **pSamples, long nSamples, long *nSamplesProcessed)
-{
- if (!pSamples || !nSamplesProcessed)
- return E_POINTER;
-
- HRESULT hr = S_OK;
- *nSamplesProcessed = 0;
- while (nSamples-- > 0) {
- hr = Receive(pSamples[*nSamplesProcessed]);
- if (hr != S_OK)
- break;
- (*nSamplesProcessed)++;
- }
- return hr;
-}
-
-HRESULT DirectShowInputPin::ReceiveCanBlock()
-{
- int outputPins = 0;
-
- const QList<DirectShowPin *> pinList = m_filter->pins();
- for (DirectShowPin *pin : pinList) {
- PIN_DIRECTION pd;
- HRESULT hr = pin->QueryDirection(&pd);
- if (FAILED(hr))
- return hr;
-
- if (pd == PINDIR_OUTPUT) {
- IPin *connected;
- hr = pin->ConnectedTo(&connected);
- if (SUCCEEDED(hr)) {
- ++outputPins;
- IMemInputPin *inputPin;
- hr = connected->QueryInterface(IID_PPV_ARGS(&inputPin));
- connected->Release();
- if (SUCCEEDED(hr)) {
- hr = inputPin->ReceiveCanBlock();
- inputPin->Release();
- if (hr != S_FALSE)
- return S_OK;
- } else {
- return S_OK;
- }
- }
- }
- }
-
- return outputPins == 0 ? S_OK : S_FALSE;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/common/directshowpin.h b/src/plugins/directshow/common/directshowpin.h
deleted file mode 100644
index 160191ef3..000000000
--- a/src/plugins/directshow/common/directshowpin.h
+++ /dev/null
@@ -1,180 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWPIN_H
-#define DIRECTSHOWPIN_H
-
-#include "directshowobject.h"
-
-#include "directshowmediatype.h"
-#include <qstring.h>
-#include <qmutex.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowBaseFilter;
-
-class DirectShowPin : public IPin
-{
-public:
- virtual ~DirectShowPin();
-
- QString name() const { return m_name; }
- bool isConnected() const { return m_peerPin != nullptr; }
-
- virtual bool isMediaTypeSupported(const AM_MEDIA_TYPE *type) = 0;
- virtual QList<DirectShowMediaType> supportedMediaTypes();
- virtual bool setMediaType(const AM_MEDIA_TYPE *type);
-
- virtual HRESULT completeConnection(IPin *pin);
- virtual HRESULT connectionEnded();
-
- virtual HRESULT setActive(bool active);
-
- // IPin
- STDMETHODIMP Connect(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt) override;
- STDMETHODIMP ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt) override;
- STDMETHODIMP Disconnect() override;
- STDMETHODIMP ConnectedTo(IPin **ppPin) override;
-
- STDMETHODIMP ConnectionMediaType(AM_MEDIA_TYPE *pmt) override;
-
- STDMETHODIMP QueryPinInfo(PIN_INFO *pInfo) override;
- STDMETHODIMP QueryId(LPWSTR *Id) override;
-
- STDMETHODIMP QueryAccept(const AM_MEDIA_TYPE *pmt) override;
-
- STDMETHODIMP EnumMediaTypes(IEnumMediaTypes **ppEnum) override;
-
- STDMETHODIMP QueryInternalConnections(IPin **apPin, ULONG *nPin) override;
-
- STDMETHODIMP EndOfStream() override;
-
- STDMETHODIMP BeginFlush() override;
- STDMETHODIMP EndFlush() override;
-
- STDMETHODIMP NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) override;
-
- STDMETHODIMP QueryDirection(PIN_DIRECTION *pPinDir) override;
-
-protected:
- DirectShowPin(DirectShowBaseFilter *filter, const QString &name, PIN_DIRECTION direction);
-
- QRecursiveMutex m_mutex;
-
- DirectShowBaseFilter *m_filter;
- QString m_name;
- PIN_DIRECTION m_direction;
-
- IPin *m_peerPin = nullptr;
- DirectShowMediaType m_mediaType;
-
-private:
- Q_DISABLE_COPY(DirectShowPin)
- HRESULT tryMediaTypes(IPin *pin, const AM_MEDIA_TYPE *type, IEnumMediaTypes *enumMediaTypes);
- HRESULT tryConnect(IPin *pin, const AM_MEDIA_TYPE *type);
-};
-
-
-class DirectShowOutputPin : public DirectShowPin
-{
-public:
- ~DirectShowOutputPin() override;
-
- // DirectShowPin
- HRESULT completeConnection(IPin *pin) override;
- HRESULT connectionEnded() override;
- HRESULT setActive(bool active) override;
-
- // IPin
- STDMETHODIMP EndOfStream() override;
-
-protected:
- DirectShowOutputPin(DirectShowBaseFilter *filter, const QString &name);
-
- IMemAllocator *m_allocator = nullptr;
- IMemInputPin *m_inputPin = nullptr;
-
-private:
- Q_DISABLE_COPY(DirectShowOutputPin)
-};
-
-
-class DirectShowInputPin : public DirectShowPin
- , public IMemInputPin
-{
-public:
- ~DirectShowInputPin() override;
-
- const AM_SAMPLE2_PROPERTIES *currentSampleProperties() const { return &m_sampleProperties; }
-
- // DirectShowPin
- HRESULT connectionEnded() override;
- HRESULT setActive(bool active) override;
-
- // IPin
- STDMETHODIMP EndOfStream() override;
- STDMETHODIMP BeginFlush() override;
- STDMETHODIMP EndFlush() override;
-
- // IMemInputPin
- STDMETHODIMP GetAllocator(IMemAllocator **ppAllocator) override;
- STDMETHODIMP NotifyAllocator(IMemAllocator *pAllocator, BOOL bReadOnly) override;
- STDMETHODIMP GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps) override;
-
- STDMETHODIMP Receive(IMediaSample *pSample) override;
- STDMETHODIMP ReceiveMultiple(IMediaSample **pSamples, long nSamples,
- long *nSamplesProcessed) override;
- STDMETHODIMP ReceiveCanBlock() override;
-
-protected:
- DirectShowInputPin(DirectShowBaseFilter *filter, const QString &name);
-
- IMemAllocator *m_allocator = nullptr;
- bool m_flushing = false;
- bool m_inErrorState = false;
- AM_SAMPLE2_PROPERTIES m_sampleProperties;
-
-private:
- Q_DISABLE_COPY(DirectShowInputPin)
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWPIN_H
diff --git a/src/plugins/directshow/common/directshowpinenum.cpp b/src/plugins/directshow/common/directshowpinenum.cpp
deleted file mode 100644
index 7ba1bb6e9..000000000
--- a/src/plugins/directshow/common/directshowpinenum.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowpinenum.h"
-#include "directshowbasefilter.h"
-
-QT_BEGIN_NAMESPACE
-
-DirectShowPinEnum::DirectShowPinEnum(DirectShowBaseFilter *filter)
- : m_filter(filter)
-{
- m_filter->AddRef();
- const QList<DirectShowPin *> pinList = filter->pins();
- for (DirectShowPin *pin : pinList) {
- pin->AddRef();
- m_pins.append(pin);
- }
-}
-
-DirectShowPinEnum::DirectShowPinEnum(const QList<IPin *> &pins)
- : m_pins(pins)
-{
- for (IPin *pin : qAsConst(m_pins))
- pin->AddRef();
-}
-
-DirectShowPinEnum::~DirectShowPinEnum()
-{
- for (IPin *pin : qAsConst(m_pins))
- pin->Release();
- if (m_filter)
- m_filter->Release();
-}
-
-HRESULT DirectShowPinEnum::QueryInterface(REFIID riid, void **ppv)
-{
- if (ppv == nullptr)
- return E_POINTER;
- if (riid == IID_IUnknown)
- *ppv = static_cast<IUnknown *>(this);
- else if (riid == IID_IEnumPins)
- *ppv = static_cast<IEnumPins *>(this);
- else
- return E_NOINTERFACE;
- AddRef();
- return S_OK;
-}
-
-HRESULT DirectShowPinEnum::Next(ULONG cPins, IPin **ppPins, ULONG *pcFetched)
-{
- if (!ppPins || (!pcFetched && cPins != 1))
- return E_POINTER;
-
- ULONG count = qBound<ULONG>(0, cPins, m_pins.count() - m_index);
-
- for (ULONG i = 0; i < count; ++i, ++m_index) {
- ppPins[i] = m_pins.at(m_index);
- ppPins[i]->AddRef();
- }
-
- if (pcFetched)
- *pcFetched = count;
-
- return count == cPins ? S_OK : S_FALSE;
-}
-
-HRESULT DirectShowPinEnum::Skip(ULONG cPins)
-{
- m_index = qMin(int(m_index + cPins), m_pins.count());
-
- return m_index < m_pins.count() ? S_OK : S_FALSE;
-}
-
-HRESULT DirectShowPinEnum::Reset()
-{
- m_index = 0;
-
- return S_OK;
-}
-
-HRESULT DirectShowPinEnum::Clone(IEnumPins **ppEnum)
-{
- if (!ppEnum)
- return E_POINTER;
- *ppEnum = m_filter ? new DirectShowPinEnum(m_filter) : new DirectShowPinEnum(m_pins);
- return S_OK;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/common/directshowpinenum.h b/src/plugins/directshow/common/directshowpinenum.h
deleted file mode 100644
index aada1a71e..000000000
--- a/src/plugins/directshow/common/directshowpinenum.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWPINENUM_H
-#define DIRECTSHOWPINENUM_H
-
-#include <dshow.h>
-
-#include <QtCore/qlist.h>
-#include "directshowpin.h"
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowBaseFilter;
-
-class DirectShowPinEnum : public IEnumPins
-{
- COM_REF_MIXIN
-public:
- DirectShowPinEnum(DirectShowBaseFilter *filter);
- DirectShowPinEnum(const QList<IPin *> &pins);
- virtual ~DirectShowPinEnum();
-
- STDMETHODIMP QueryInterface(REFIID riid, void **ppv) override;
-
- // IEnumPins
- STDMETHODIMP Next(ULONG cPins, IPin **ppPins, ULONG *pcFetched) override;
- STDMETHODIMP Skip(ULONG cPins) override;
- STDMETHODIMP Reset() override;
- STDMETHODIMP Clone(IEnumPins **ppEnum) override;
-
-private:
- Q_DISABLE_COPY(DirectShowPinEnum)
-
- DirectShowBaseFilter *m_filter = nullptr;
- QList<IPin *> m_pins;
- int m_index = 0;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/common/directshowsamplegrabber.cpp b/src/plugins/directshow/common/directshowsamplegrabber.cpp
deleted file mode 100644
index a9e74f9db..000000000
--- a/src/plugins/directshow/common/directshowsamplegrabber.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowsamplegrabber.h"
-
-#include "directshowglobal.h"
-#include "directshowutils.h"
-
-
-QT_BEGIN_NAMESPACE
-
-// Previously contained in <qedit.h>.
-static const IID iID_ISampleGrabber = { 0x6B652FFF, 0x11FE, 0x4fce, { 0x92, 0xAD, 0x02, 0x66, 0xB5, 0xD7, 0xC7, 0x8F } };
-static const CLSID cLSID_SampleGrabber = { 0xC1F400A0, 0x3F08, 0x11d3, { 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37 } };
-
-class SampleGrabberCallbackPrivate : public ISampleGrabberCB
-{
- Q_DISABLE_COPY(SampleGrabberCallbackPrivate)
-public:
- explicit SampleGrabberCallbackPrivate(DirectShowSampleGrabber *grabber)
- : m_ref(1)
- , m_grabber(grabber)
- { }
-
- virtual ~SampleGrabberCallbackPrivate() = default;
-
- STDMETHODIMP_(ULONG) AddRef() override
- {
- return InterlockedIncrement(&m_ref);
- }
-
- STDMETHODIMP_(ULONG) Release() override
- {
- ULONG ref = InterlockedDecrement(&m_ref);
- if (ref == 0)
- delete this;
- return ref;
- }
-
- STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject) override
- {
- if (nullptr == ppvObject)
- return E_POINTER;
-
- if (riid == IID_IUnknown /*__uuidof(IUnknown) */ ) {
- AddRef();
- *ppvObject = static_cast<IUnknown *>(this);
- return S_OK;
- }
- if (riid == IID_ISampleGrabberCB /*__uuidof(ISampleGrabberCB)*/ ) {
- AddRef();
- *ppvObject = static_cast<ISampleGrabberCB *>(this);
- return S_OK;
- }
- return E_NOTIMPL;
- }
-
- STDMETHODIMP SampleCB(double time, IMediaSample *mediaSample) override
- {
- if (m_grabber)
- Q_EMIT m_grabber->sampleAvailable(time, mediaSample);
-
- return S_OK;
- }
-
- STDMETHODIMP BufferCB(double time, BYTE *buffer, long bufferLen) override
- {
- if (m_grabber) {
- // Deep copy, the data might be modified or freed after the callback returns
- QByteArray data(reinterpret_cast<const char *>(buffer), bufferLen);
- Q_EMIT m_grabber->bufferAvailable(time, data);
- }
- return S_OK;
- }
-
-private:
- ULONG m_ref;
- DirectShowSampleGrabber *m_grabber;
-};
-
-DirectShowSampleGrabber::DirectShowSampleGrabber(QObject *p)
- : QObject(p)
-{
- // Create sample grabber filter
- HRESULT hr = CoCreateInstance(cLSID_SampleGrabber, nullptr, CLSCTX_INPROC, iID_ISampleGrabber, reinterpret_cast<void **>(&m_sampleGrabber));
-
- if (FAILED(hr)) {
- qCWarning(qtDirectShowPlugin, "Failed to create sample grabber");
- return;
- }
-
- hr = m_sampleGrabber->QueryInterface(IID_IBaseFilter, reinterpret_cast<void **>(&m_filter));
- if (FAILED(hr))
- qCWarning(qtDirectShowPlugin, "Failed to get base filter interface");
-}
-
-DirectShowSampleGrabber::~DirectShowSampleGrabber()
-{
- stop();
- SAFE_RELEASE(m_sampleGabberCb);
- SAFE_RELEASE(m_filter);
- SAFE_RELEASE(m_sampleGrabber);
-}
-
-void DirectShowSampleGrabber::stop()
-{
- if (!m_sampleGrabber)
- return;
-
- if (FAILED(m_sampleGrabber->SetCallback(nullptr, static_cast<long>(m_callbackType)))) {
- qCWarning(qtDirectShowPlugin, "Failed to stop sample grabber callback");
- return;
- }
-}
-
-bool DirectShowSampleGrabber::getConnectedMediaType(AM_MEDIA_TYPE *mediaType)
-{
- Q_ASSERT(mediaType);
-
- if (!isValid())
- return false;
-
- if (FAILED(m_sampleGrabber->GetConnectedMediaType(mediaType))) {
- qCWarning(qtDirectShowPlugin, "Failed to retrieve the connected media type");
- return false;
- }
-
- return true;
-}
-
-bool DirectShowSampleGrabber::setMediaType(const AM_MEDIA_TYPE *mediaType)
-{
- Q_ASSERT(mediaType);
-
- if (FAILED(m_sampleGrabber->SetMediaType(mediaType))) {
- qCWarning(qtDirectShowPlugin, "Failed to set media type");
- return false;
- }
-
- return true;
-}
-
-void DirectShowSampleGrabber::start(DirectShowSampleGrabber::CallbackMethod method,
- bool oneShot,
- bool bufferSamples)
-{
- if (!m_sampleGrabber)
- return;
-
- stop();
-
- if (!m_sampleGabberCb)
- m_sampleGabberCb = new SampleGrabberCallbackPrivate(this);
-
- m_callbackType = method;
- m_sampleGrabber->SetCallback(m_sampleGabberCb, static_cast<long>(method));
- m_sampleGrabber->SetOneShot(oneShot);
- m_sampleGrabber->SetBufferSamples(bufferSamples);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/common/directshowsamplegrabber.h b/src/plugins/directshow/common/directshowsamplegrabber.h
deleted file mode 100644
index 5fc61de14..000000000
--- a/src/plugins/directshow/common/directshowsamplegrabber.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWSAMPLEGRABBER_H
-#define DIRECTSHOWSAMPLEGRABBER_H
-
-#include <QtCore/qglobal.h>
-#include <QtCore/qobject.h>
-
-// TODO: Fix this.
-#include <directshowcameraglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-class SampleGrabberCallbackPrivate;
-
-class DirectShowSampleGrabber : public QObject
-{
- Q_OBJECT
-public:
- DirectShowSampleGrabber(QObject *p = nullptr);
- ~DirectShowSampleGrabber();
-
- // 0 = ISampleGrabberCB::SampleCB, 1 = ISampleGrabberCB::BufferCB
- enum class CallbackMethod : long
- {
- SampleCB,
- BufferCB
- };
-
- bool isValid() const { return m_filter && m_sampleGrabber; }
- bool getConnectedMediaType(AM_MEDIA_TYPE *mediaType);
- bool setMediaType(const AM_MEDIA_TYPE *mediaType);
-
- void stop();
- void start(CallbackMethod method, bool oneShot = false, bool bufferSamples = false);
-
- IBaseFilter *filter() const { return m_filter; }
-
-Q_SIGNALS:
- void sampleAvailable(double time, IMediaSample *sample);
- void bufferAvailable(double time, const QByteArray &data);
-
-private:
- IBaseFilter *m_filter = nullptr;
- ISampleGrabber *m_sampleGrabber = nullptr;
- SampleGrabberCallbackPrivate *m_sampleGabberCb = nullptr;
- CallbackMethod m_callbackType= CallbackMethod::BufferCB;
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWSAMPLEGRABBER_H
diff --git a/src/plugins/directshow/common/directshowutils.cpp b/src/plugins/directshow/common/directshowutils.cpp
deleted file mode 100644
index 9222ad779..000000000
--- a/src/plugins/directshow/common/directshowutils.cpp
+++ /dev/null
@@ -1,346 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowutils.h"
-
-QT_BEGIN_NAMESPACE
-
-/**
- * @brief DirectShowUtils::isPinConnected
- * @param pin
- * @param hrOut
- * @return
- */
-bool DirectShowUtils::isPinConnected(IPin *pin, HRESULT *hrOut)
-{
- IPin *connectedPin = nullptr;
- const ScopedSafeRelease<IPin> releasePin { &connectedPin };
- HRESULT hr = S_OK;
- if (!hrOut)
- hrOut = &hr;
-
- *hrOut = pin->ConnectedTo(&connectedPin);
- if (*hrOut == VFW_E_NOT_CONNECTED) { // Not an error in this case
- *hrOut = S_OK;
- return false;
- }
-
- if (FAILED(*hrOut)) {
- qCDebug(qtDirectShowPlugin, "Querying pin connection failed!");
- return false;
- }
-
- return true;
-}
-
-/**
- * @brief DirectShowUtils::hasPinDirection
- * @param pin
- * @param direction
- * @param hrOut
- * @return
- */
-bool DirectShowUtils::hasPinDirection(IPin *pin, PIN_DIRECTION direction, HRESULT *hrOut)
-{
- PIN_DIRECTION pinDir;
- HRESULT hr = S_OK;
- if (!hrOut)
- hrOut = &hr;
-
- *hrOut = pin->QueryDirection(&pinDir);
-
- if (FAILED(*hrOut)) {
- qCDebug(qtDirectShowPlugin, "Querying pin direction failed!");
- return false;
- }
-
- return (pinDir == direction);
-}
-
-bool pinMatchesCategory(IPin* pPin, REFGUID category)
-{
- bool found = false;
- IKsPropertySet *pKs = nullptr;
- DirectShowUtils::ScopedSafeRelease<IKsPropertySet> ks_property { &pKs };
- HRESULT hr = pPin->QueryInterface(IID_PPV_ARGS(&pKs));
-
- if (SUCCEEDED(hr)) {
- GUID pin_category;
- DWORD return_value;
- hr = pKs->Get(AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0,
- &pin_category, sizeof(pin_category), &return_value);
- if (SUCCEEDED(hr) && (return_value == sizeof(pin_category)))
- found = (pin_category == category);
- }
-
- return found;
-}
-
-/**
- * @brief DirectShowUtils::getPin
- * @param filter
- * @param pinDirection
- * @param pin
- * @param hrOut
- * @return
- */
-bool DirectShowUtils::getPin(IBaseFilter *filter, PIN_DIRECTION pinDirection, REFGUID category, IPin **pin, HRESULT *hrOut)
-{
- IEnumPins *enumPins = nullptr;
- const ScopedSafeRelease<IEnumPins> releaseEnumPins { &enumPins };
- HRESULT hr S_OK;
- if (!hrOut)
- hrOut = &hr;
-
- *hrOut = filter->EnumPins(&enumPins);
- if (FAILED(*hrOut)) {
- qCDebug(qtDirectShowPlugin, "Unable to retrieve pins from the filter!");
- return false;
- }
-
- enumPins->Reset();
- IPin *nextPin = nullptr;
- while (enumPins->Next(1, &nextPin, nullptr) == S_OK) {
- const ScopedSafeRelease<IPin> releasePin { &nextPin };
- PIN_DIRECTION currentPinDir;
- *hrOut = nextPin->QueryDirection(&currentPinDir);
- if (currentPinDir == pinDirection) {
- if (category == GUID_NULL || pinMatchesCategory(nextPin, category)) {
- *pin = nextPin;
- (*pin)->AddRef();
- return true;
- }
- }
- }
-
- return false;
-}
-
-/**
- * @brief DirectShowUtils::matchPin
- * @param pin
- * @param pinDirection
- * @param shouldBeConnected
- * @param hrOut
- * @return
- */
-bool DirectShowUtils::matchPin(IPin *pin, PIN_DIRECTION pinDirection, BOOL shouldBeConnected, HRESULT *hrOut)
-{
- HRESULT hr = S_OK;
- if (!hrOut)
- hrOut = &hr;
-
- const BOOL isConnected = isPinConnected(pin, hrOut);
- if (FAILED(*hrOut)) // Error reason will already be logged, so just return.
- return false;
-
- if (isConnected == shouldBeConnected)
- return hasPinDirection(pin, pinDirection, hrOut);
-
- return false;
-}
-
-/**
- * @brief DirectShowUtils::findUnconnectedPin
- * @param filter
- * @param pinDirection
- * @param pin
- * @param hrOut
- * @return
- */
-bool DirectShowUtils::findUnconnectedPin(IBaseFilter *filter, PIN_DIRECTION pinDirection, IPin **pin, HRESULT *hrOut)
-{
- HRESULT hr = S_OK;
- if (!hrOut)
- hrOut = &hr;
-
- IEnumPins *enumPins = nullptr;
- const ScopedSafeRelease<IEnumPins> releaseEnumPins { &enumPins };
- *hrOut = filter->EnumPins(&enumPins);
- if (FAILED(*hrOut)) {
- qCDebug(qtDirectShowPlugin, "Unable to retrieve pins from the DS filter");
- return false;
- }
-
- IPin *nextPin = nullptr;
- while (S_OK == enumPins->Next(1, &nextPin, nullptr)) {
- const ScopedSafeRelease<IPin> releaseNextPin { &nextPin };
- if (matchPin(nextPin, pinDirection, FALSE, hrOut)) {
- *pin = nextPin;
- (*pin)->AddRef();
- return true;
- }
- }
-
- qCDebug(qtDirectShowPlugin, "No unconnected pins found");
- *hrOut = VFW_E_NOT_FOUND;
-
- return false;
-}
-
-/**
- * @brief DirectShowUtils::connectFilters - Attempts to connect \a outputPin to \a filter
- * @param graph
- * @param outputPin
- * @param filter
- * @param hrOut
- * @return
- */
-bool DirectShowUtils::connectFilters(IGraphBuilder *graph, IPin *outputPin, IBaseFilter *filter, HRESULT *hrOut)
-{
-
- // Find an input pin on the downstream filter.
- HRESULT hr = S_OK;
- if (!hrOut)
- hrOut = &hr;
-
- IPin *inputPin = nullptr;
- const ScopedSafeRelease<IPin> releaseInputPin { &inputPin };
- if (!findUnconnectedPin(filter, PINDIR_INPUT, &inputPin, hrOut))
- return false;
-
-
- // Try to connect them.
- *hrOut = graph->Connect(outputPin, inputPin);
- if (FAILED(*hrOut)) {
- qCDebug(qtDirectShowPlugin, "Unable to connect output pin to filter!");
- return false;
- }
-
- return true;
-}
-
-/**
- * @brief DirectShowUtils::connectFilters - Attempts to connect \a filter to \a inputPin.
- * @param graph
- * @param filter
- * @param inputPin
- * @param hrOut
- * @return
- */
-bool DirectShowUtils::connectFilters(IGraphBuilder *graph, IBaseFilter *filter, IPin *inputPin, HRESULT *hrOut)
-{
- HRESULT hr = S_OK;
- if (!hrOut)
- hrOut = &hr;
-
- IPin *outputPin = nullptr;
- const ScopedSafeRelease<IPin> releaseOutputPin { &outputPin };
- // Find an output pin on the upstream filter.
- if (findUnconnectedPin(filter, PINDIR_OUTPUT, &outputPin, hrOut))
- return false;
-
- *hrOut = graph->Connect(outputPin, inputPin);
- if (FAILED(*hrOut)) {
- qCDebug(qtDirectShowPlugin, "Unable to connect filter to input pin!");
- return false;
- }
-
- return true;
-}
-
-/**
- * @brief DirectShowUtils::connectFilters - Attempts to connect the \a upstreamFilter to \a downstreamFilter.
- * @param graph
- * @param upstreamFilter
- * @param downstreamFilter
- * @param autoConnect - If set to true all filters in the graph will be considered.
- * @param hrOut
- * @return true if the the filters were connected, false otherwise.
- */
-bool DirectShowUtils::connectFilters(IGraphBuilder *graph,
- IBaseFilter *upstreamFilter,
- IBaseFilter *downstreamFilter,
- bool autoConnect,
- HRESULT *hrOut)
-{
- HRESULT hr = S_OK;
- if (!hrOut)
- hrOut = &hr;
-
- const auto findAndConnect = [graph, downstreamFilter, hrOut](IBaseFilter *filter) -> bool {
- IPin *outputPin = nullptr;
- const ScopedSafeRelease<IPin> releaseOutputPin { &outputPin };
- if (findUnconnectedPin(filter, PINDIR_OUTPUT, &outputPin, hrOut))
- return connectFilters(graph, outputPin, downstreamFilter, hrOut);
-
- return false;
- };
-
- // Try to connect to the upstream filter first.
- if (findAndConnect(upstreamFilter))
- return true;
-
- const auto getFilters = [graph, hrOut]() -> IEnumFilters * {
- IEnumFilters *f = nullptr;
- *hrOut = graph->EnumFilters(&f);
- return f;
- };
- IEnumFilters *filters = autoConnect ? getFilters()
- : nullptr;
- const ScopedSafeRelease<IEnumFilters> releaseEnumFilters { &filters };
- if (!filters) {
- qCDebug(qtDirectShowPlugin, "No filters found!");
- return false;
- }
-
- IBaseFilter *nextFilter = nullptr;
- while (S_OK == filters->Next(1, &nextFilter, nullptr)) {
- const ScopedSafeRelease<IBaseFilter> releaseNextFilter { &nextFilter };
- if (nextFilter && findAndConnect(nextFilter))
- return true;
- }
-
- return false;
-}
-
-thread_local static int g_refCount = 0;
-void DirectShowUtils::CoInitializeIfNeeded()
-{
- if (++g_refCount == 1)
- ::CoInitialize(nullptr);
-}
-
-void DirectShowUtils::CoUninitializeIfNeeded()
-{
- if (--g_refCount == 0)
- ::CoUninitialize();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/common/directshowutils.h b/src/plugins/directshow/common/directshowutils.h
deleted file mode 100644
index ec761abe6..000000000
--- a/src/plugins/directshow/common/directshowutils.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWUTILS_H
-#define DIRECTSHOWUTILS_H
-
-#include "directshowglobal.h"
-
-QT_BEGIN_NAMESPACE
-
-namespace DirectShowUtils
-{
-template <typename T>
-void safeRelease(T **iface) {
- if (!iface)
- return;
-
- if (!*iface)
- return;
-
- (*iface)->Release();
- *iface = nullptr;
-}
-
-template <typename T>
-struct ScopedSafeRelease
-{
- T **iunknown;
- ~ScopedSafeRelease()
- {
- DirectShowUtils::safeRelease(iunknown);
- }
-};
-
-bool getPin(IBaseFilter *filter, PIN_DIRECTION pinDirection, REFGUID category, IPin **pin, HRESULT *hrOut);
-bool isPinConnected(IPin *pin, HRESULT *hrOut = nullptr);
-bool hasPinDirection(IPin *pin, PIN_DIRECTION direction, HRESULT *hrOut = nullptr);
-bool matchPin(IPin *pin, PIN_DIRECTION pinDirection, BOOL shouldBeConnected, HRESULT *hrOut = nullptr);
-bool findUnconnectedPin(IBaseFilter *filter, PIN_DIRECTION pinDirection, IPin **pin, HRESULT *hrOut = nullptr);
-bool connectFilters(IGraphBuilder *graph, IPin *outputPin, IBaseFilter *filter, HRESULT *hrOut = nullptr);
-bool connectFilters(IGraphBuilder *graph, IBaseFilter *filter, IPin *inputPin, HRESULT *hrOut = nullptr);
-bool connectFilters(IGraphBuilder *graph,
- IBaseFilter *upstreamFilter,
- IBaseFilter *downstreamFilter,
- bool autoConnect = false,
- HRESULT *hrOut = nullptr);
-
-void CoInitializeIfNeeded();
-void CoUninitializeIfNeeded();
-
-}
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWUTILS_H
diff --git a/src/plugins/directshow/common/directshowvideobuffer.cpp b/src/plugins/directshow/common/directshowvideobuffer.cpp
deleted file mode 100644
index fc329f58a..000000000
--- a/src/plugins/directshow/common/directshowvideobuffer.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowvideobuffer.h"
-
-QT_BEGIN_NAMESPACE
-
-DirectShowVideoBuffer::DirectShowVideoBuffer(IMediaSample *sample, int bytesPerLine)
- : QAbstractVideoBuffer(NoHandle)
- , m_sample(sample)
- , m_bytesPerLine(bytesPerLine)
- , m_mapMode(NotMapped)
-{
- m_sample->AddRef();
-}
-
-DirectShowVideoBuffer::~DirectShowVideoBuffer()
-{
- m_sample->Release();
-}
-
-uchar *DirectShowVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
-{
- if (m_mapMode == NotMapped && mode != NotMapped) {
- if (numBytes)
- *numBytes = m_sample->GetActualDataLength();
-
- if (bytesPerLine)
- *bytesPerLine = m_bytesPerLine;
-
- BYTE *bytes = nullptr;
-
- if (m_sample->GetPointer(&bytes) == S_OK) {
- m_mapMode = mode;
-
- return reinterpret_cast<uchar *>(bytes);
- }
- }
- return nullptr;
-}
-
-void DirectShowVideoBuffer::unmap()
-{
- m_mapMode = NotMapped;
-}
-
-QAbstractVideoBuffer::MapMode DirectShowVideoBuffer::mapMode() const
-{
- return m_mapMode;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/common/directshowvideobuffer.h b/src/plugins/directshow/common/directshowvideobuffer.h
deleted file mode 100644
index a85a3ca34..000000000
--- a/src/plugins/directshow/common/directshowvideobuffer.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWVIDEOBUFFER_H
-#define DIRECTSHOWVIDEOBUFFER_H
-
-#include <dshow.h>
-
-#include <qabstractvideobuffer.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowVideoBuffer : public QAbstractVideoBuffer
-{
-public:
- DirectShowVideoBuffer(IMediaSample *sample, int bytesPerLine);
- ~DirectShowVideoBuffer() override;
-
- IMediaSample *sample() { return m_sample; }
-
- uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) override;
- void unmap() override;
-
- MapMode mapMode() const override;
-
-private:
- IMediaSample *m_sample;
- int m_bytesPerLine;
- MapMode m_mapMode;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/common/directshowvideoprobecontrol.cpp b/src/plugins/directshow/common/directshowvideoprobecontrol.cpp
deleted file mode 100644
index 0e2e68864..000000000
--- a/src/plugins/directshow/common/directshowvideoprobecontrol.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowvideoprobecontrol.h"
-#include "directshowglobal.h"
-
-QT_BEGIN_NAMESPACE
-
-DirectShowVideoProbeControl::DirectShowVideoProbeControl(QObject *p)
- : QMediaVideoProbeControl(p)
-{
-
-}
-
-DirectShowVideoProbeControl::~DirectShowVideoProbeControl()
-{
- if (m_ref.deref())
- qCWarning(qtDirectShowPlugin, "QVideoProbe control destroyed while it's still being referenced!!!");
-}
-
-void DirectShowVideoProbeControl::probeVideoFrame(const QVideoFrame &frame)
-{
- emit videoFrameProbed(frame);
- m_frameProbed = true;
-}
-
-void DirectShowVideoProbeControl::flushVideoFrame()
-{
- if (m_frameProbed)
- emit flush();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/common/directshowvideoprobecontrol.h b/src/plugins/directshow/common/directshowvideoprobecontrol.h
deleted file mode 100644
index 57839f8d3..000000000
--- a/src/plugins/directshow/common/directshowvideoprobecontrol.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWVIDEOPROBECONTROL_H
-#define DIRECTSHOWVIDEOPROBECONTROL_H
-
-#include <qmediavideoprobecontrol.h>
-
-#include <QtCore/qglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowVideoProbeControl : public QMediaVideoProbeControl
-{
- Q_OBJECT
-public:
- explicit DirectShowVideoProbeControl(QObject *p = nullptr);
- ~DirectShowVideoProbeControl();
-
- bool ref() { return m_ref.ref(); }
- bool deref() { return m_ref.deref(); }
- void probeVideoFrame(const QVideoFrame &frame);
- void flushVideoFrame();
-private:
- QAtomicInt m_ref;
- bool m_frameProbed = false;
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWVIDEOPROBECONTROL_H
diff --git a/src/plugins/directshow/directshow.json b/src/plugins/directshow/directshow.json
deleted file mode 100644
index b1783b5ed..000000000
--- a/src/plugins/directshow/directshow.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["directshow"],
- "Services": ["org.qt-project.qt.camera", "org.qt-project.qt.mediaplayer"]
-}
diff --git a/src/plugins/directshow/directshow.pro b/src/plugins/directshow/directshow.pro
deleted file mode 100644
index 27bb3abb8..000000000
--- a/src/plugins/directshow/directshow.pro
+++ /dev/null
@@ -1,32 +0,0 @@
-TARGET = dsengine
-QT += multimedia-private
-
-win32:!qtHaveModule(opengl)|qtConfig(dynamicgl) {
- LIBS_PRIVATE += -lgdi32 -luser32
-}
-
-HEADERS += dsserviceplugin.h
-SOURCES += dsserviceplugin.cpp
-
-# Remove WINVER/_WIN32_WINNT definitions added to qt_build_config.prf
-# by qtbase/d57a7c41712f8627a462d893329dc3f0dbb52d32 since the multimedia
-# headers of MinGW 5.3/7.1 are too broken to compile with 0x0601.
-mingw {
- DEFINES -= WINVER=0x0601 _WIN32_WINNT=0x0601
- DEFINES += NO_DSHOW_STRSAFE
-}
-
-mingw {
- LIBS_PRIVATE += -lamstrmid
-}
-
-include(common/common.pri)
-include(player/player.pri)
-include(camera/camera.pri)
-
-OTHER_FILES += \
- directshow.json
-
-PLUGIN_TYPE = mediaservice
-PLUGIN_CLASS_NAME = DSServicePlugin
-load(qt_plugin)
diff --git a/src/plugins/directshow/dsserviceplugin.cpp b/src/plugins/directshow/dsserviceplugin.cpp
deleted file mode 100644
index 18a807fd1..000000000
--- a/src/plugins/directshow/dsserviceplugin.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <dshow.h>
-
-#include <QtCore/qstring.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/QFile>
-
-#include "directshowglobal.h"
-#include "dsserviceplugin.h"
-
-#include "dsvideodevicecontrol.h"
-#include <dshow.h>
-#include "dscameraservice.h"
-
-#include "directshowplayerservice.h"
-
-#include <qmediaserviceproviderplugin.h>
-#include "directshowutils.h"
-
-extern const CLSID CLSID_VideoInputDeviceCategory;
-
-
-#ifndef _STRSAFE_H_INCLUDED_
-#include <tchar.h>
-#endif
-#include <dshow.h>
-#include <objbase.h>
-#include <initguid.h>
-#ifdef Q_CC_MSVC
-# pragma comment(lib, "strmiids.lib")
-# pragma comment(lib, "ole32.lib")
-#endif // Q_CC_MSVC
-#include <windows.h>
-#include <ocidl.h>
-
-QT_BEGIN_NAMESPACE
-Q_LOGGING_CATEGORY(qtDirectShowPlugin, "qt.multimedia.plugins.directshow")
-
-QMediaService* DSServicePlugin::create(QString const& key)
-{
- if (key == QLatin1String(Q_MEDIASERVICE_CAMERA)) {
- DirectShowUtils::CoInitializeIfNeeded();
- return new DSCameraService;
- }
-
- if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER)) {
- DirectShowUtils::CoInitializeIfNeeded();
- return new DirectShowPlayerService;
- }
-
- return nullptr;
-}
-
-void DSServicePlugin::release(QMediaService *service)
-{
- delete service;
- DirectShowUtils::CoUninitializeIfNeeded();
-}
-
-QMediaServiceProviderHint::Features DSServicePlugin::supportedFeatures(
- const QByteArray &service) const
-{
- return service == Q_MEDIASERVICE_MEDIAPLAYER
- ? (QMediaServiceProviderHint::StreamPlayback | QMediaServiceProviderHint::VideoSurface)
- : QMediaServiceProviderHint::Features();
-}
-
-QByteArray DSServicePlugin::defaultDevice(const QByteArray &service) const
-{
- if (service == Q_MEDIASERVICE_CAMERA) {
- DirectShowUtils::CoInitializeIfNeeded();
- const QList<DSVideoDeviceInfo> &devs = DSVideoDeviceControl::availableDevices();
- DirectShowUtils::CoUninitializeIfNeeded();
- if (!devs.isEmpty())
- return devs.first().first;
- }
- return QByteArray();
-}
-
-QList<QByteArray> DSServicePlugin::devices(const QByteArray &service) const
-{
- QList<QByteArray> result;
-
- if (service == Q_MEDIASERVICE_CAMERA) {
- DirectShowUtils::CoInitializeIfNeeded();
- const QList<DSVideoDeviceInfo> &devs = DSVideoDeviceControl::availableDevices();
- DirectShowUtils::CoUninitializeIfNeeded();
- for (const DSVideoDeviceInfo &info : devs)
- result.append(info.first);
- }
-
- return result;
-}
-
-QString DSServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
-{
- if (service == Q_MEDIASERVICE_CAMERA) {
- DirectShowUtils::CoInitializeIfNeeded();
- const QList<DSVideoDeviceInfo> &devs = DSVideoDeviceControl::availableDevices();
- DirectShowUtils::CoUninitializeIfNeeded();
- for (const DSVideoDeviceInfo &info : devs) {
- if (info.first == device)
- return info.second;
- }
- }
- return QString();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/dsserviceplugin.h b/src/plugins/directshow/dsserviceplugin.h
deleted file mode 100644
index 55db9310c..000000000
--- a/src/plugins/directshow/dsserviceplugin.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DSSERVICEPLUGIN_H
-#define DSSERVICEPLUGIN_H
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "qmediaserviceproviderplugin.h"
-
-QT_BEGIN_NAMESPACE
-
-class DSServicePlugin
- : public QMediaServiceProviderPlugin
- , public QMediaServiceSupportedDevicesInterface
- , public QMediaServiceDefaultDeviceInterface
- , public QMediaServiceFeaturesInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
- Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
- Q_INTERFACES(QMediaServiceFeaturesInterface)
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "directshow.json")
-
-public:
- QMediaService* create(QString const& key) override;
- void release(QMediaService *service) override;
-
- QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const override;
-
- QByteArray defaultDevice(const QByteArray &service) const override;
- QList<QByteArray> devices(const QByteArray &service) const override;
- QString deviceDescription(const QByteArray &service, const QByteArray &device) override;
-};
-
-QT_END_NAMESPACE
-
-#endif // DSSERVICEPLUGIN_H
diff --git a/src/plugins/directshow/player/directshowaudioendpointcontrol.cpp b/src/plugins/directshow/player/directshowaudioendpointcontrol.cpp
deleted file mode 100644
index f4e45cdd8..000000000
--- a/src/plugins/directshow/player/directshowaudioendpointcontrol.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowaudioendpointcontrol.h"
-
-#include "directshowglobal.h"
-#include "directshowplayerservice.h"
-
-QT_BEGIN_NAMESPACE
-
-DirectShowAudioEndpointControl::DirectShowAudioEndpointControl(
- DirectShowPlayerService *service, QObject *parent)
- : QAudioOutputSelectorControl(parent)
- , m_service(service)
-{
- if (CreateBindCtx(0, &m_bindContext) == S_OK) {
- m_deviceEnumerator = com_new<ICreateDevEnum>(CLSID_SystemDeviceEnum);
-
- updateEndpoints();
-
- setActiveOutput(m_defaultEndpoint);
- }
-}
-
-DirectShowAudioEndpointControl::~DirectShowAudioEndpointControl()
-{
- for (IMoniker *moniker : qAsConst(m_devices))
- moniker->Release();
-
- if (m_bindContext)
- m_bindContext->Release();
-
- if (m_deviceEnumerator)
- m_deviceEnumerator->Release();
-}
-
-QList<QString> DirectShowAudioEndpointControl::availableOutputs() const
-{
- return m_devices.keys();
-}
-
-QString DirectShowAudioEndpointControl::outputDescription(const QString &name) const
-{
-#ifdef __IPropertyBag_INTERFACE_DEFINED__
- QString description;
-
- if (IMoniker *moniker = m_devices.value(name, 0)) {
- IPropertyBag *propertyBag = nullptr;
- if (SUCCEEDED(moniker->BindToStorage(
- nullptr, nullptr, IID_IPropertyBag, reinterpret_cast<void **>(&propertyBag)))) {
- VARIANT name;
- VariantInit(&name);
- if (SUCCEEDED(propertyBag->Read(L"FriendlyName", &name, nullptr)))
- description = QString::fromWCharArray(name.bstrVal);
- VariantClear(&name);
- propertyBag->Release();
- }
- }
-
- return description;
-#else
- return name.section(QLatin1Char('\\'), -1);
-#endif
-}
-
-QString DirectShowAudioEndpointControl::defaultOutput() const
-{
- return m_defaultEndpoint;
-}
-
-QString DirectShowAudioEndpointControl::activeOutput() const
-{
- return m_activeEndpoint;
-}
-
-void DirectShowAudioEndpointControl::setActiveOutput(const QString &name)
-{
- if (m_activeEndpoint == name)
- return;
-
- if (IMoniker *moniker = m_devices.value(name, 0)) {
- IBaseFilter *filter = nullptr;
-
- if (moniker->BindToObject(
- m_bindContext,
- nullptr,
- IID_IBaseFilter,
- reinterpret_cast<void **>(&filter)) == S_OK) {
- m_service->setAudioOutput(filter);
-
- filter->Release();
- }
- }
-}
-
-void DirectShowAudioEndpointControl::updateEndpoints()
-{
- IMalloc *oleMalloc = nullptr;
- if (m_deviceEnumerator && CoGetMalloc(1, &oleMalloc) == S_OK) {
- IEnumMoniker *monikers = nullptr;
-
- if (m_deviceEnumerator->CreateClassEnumerator(
- CLSID_AudioRendererCategory, &monikers, 0) == S_OK) {
- for (IMoniker *moniker = nullptr; monikers->Next(1, &moniker, nullptr) == S_OK; moniker->Release()) {
- OLECHAR *string = nullptr;
- if (moniker->GetDisplayName(m_bindContext, nullptr, &string) == S_OK) {
- QString deviceId = QString::fromWCharArray(string);
- oleMalloc->Free(string);
-
- moniker->AddRef();
- m_devices.insert(deviceId, moniker);
-
- if (m_defaultEndpoint.isEmpty()
- || deviceId.endsWith(QLatin1String("Default DirectSound Device"))) {
- m_defaultEndpoint = deviceId;
- }
- }
- }
- monikers->Release();
- }
- oleMalloc->Release();
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/player/directshowaudioendpointcontrol.h b/src/plugins/directshow/player/directshowaudioendpointcontrol.h
deleted file mode 100644
index 05c4eb990..000000000
--- a/src/plugins/directshow/player/directshowaudioendpointcontrol.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWAUDIOENDPOINTCONTROL_H
-#define DIRECTSHOWAUDIOENDPOINTCONTROL_H
-
-#include "qaudiooutputselectorcontrol.h"
-
-#include <dshow.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowPlayerService;
-
-class DirectShowAudioEndpointControl : public QAudioOutputSelectorControl
-{
- Q_OBJECT
-public:
- DirectShowAudioEndpointControl(DirectShowPlayerService *service, QObject *parent = nullptr);
- ~DirectShowAudioEndpointControl() override;
-
- QList<QString> availableOutputs() const override;
-
- QString outputDescription(const QString &name) const override;
-
- QString defaultOutput() const override;
- QString activeOutput() const override;
-
- void setActiveOutput(const QString& name) override;
-
-private:
- void updateEndpoints();
-
- DirectShowPlayerService *m_service;
- IBindCtx *m_bindContext = nullptr;
- ICreateDevEnum *m_deviceEnumerator = nullptr;
-
- QMap<QString, IMoniker *> m_devices;
- QString m_defaultEndpoint;
- QString m_activeEndpoint;
-};
-
-QT_END_NAMESPACE
-
-#endif
-
diff --git a/src/plugins/directshow/player/directshowevrvideowindowcontrol.cpp b/src/plugins/directshow/player/directshowevrvideowindowcontrol.cpp
deleted file mode 100644
index 89bfc1467..000000000
--- a/src/plugins/directshow/player/directshowevrvideowindowcontrol.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowevrvideowindowcontrol.h"
-
-#include "directshowglobal.h"
-
-DirectShowEvrVideoWindowControl::DirectShowEvrVideoWindowControl(QObject *parent)
- : EvrVideoWindowControl(parent)
-{
-}
-
-DirectShowEvrVideoWindowControl::~DirectShowEvrVideoWindowControl()
-{
- if (m_evrFilter)
- m_evrFilter->Release();
-}
-
-IBaseFilter *DirectShowEvrVideoWindowControl::filter()
-{
- if (!m_evrFilter) {
- m_evrFilter = com_new<IBaseFilter>(clsid_EnhancedVideoRenderer);
- if (!setEvr(m_evrFilter)) {
- m_evrFilter->Release();
- m_evrFilter = nullptr;
- }
- }
-
- return m_evrFilter;
-}
diff --git a/src/plugins/directshow/player/directshowevrvideowindowcontrol.h b/src/plugins/directshow/player/directshowevrvideowindowcontrol.h
deleted file mode 100644
index edbde78d6..000000000
--- a/src/plugins/directshow/player/directshowevrvideowindowcontrol.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWEVRVIDEOWINDOWCONTROL_H
-#define DIRECTSHOWEVRVIDEOWINDOWCONTROL_H
-
-#include "evrvideowindowcontrol.h"
-
-struct IBaseFilter;
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowEvrVideoWindowControl : public EvrVideoWindowControl
-{
-public:
- DirectShowEvrVideoWindowControl(QObject *parent = nullptr);
- ~DirectShowEvrVideoWindowControl();
-
- IBaseFilter *filter();
-
-private:
- IBaseFilter *m_evrFilter = nullptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // DIRECTSHOWEVRVIDEOWINDOWCONTROL_H
diff --git a/src/plugins/directshow/player/directshowioreader.cpp b/src/plugins/directshow/player/directshowioreader.cpp
deleted file mode 100644
index 3318d57b5..000000000
--- a/src/plugins/directshow/player/directshowioreader.cpp
+++ /dev/null
@@ -1,462 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowioreader.h"
-
-#include "directshoweventloop.h"
-#include "directshowglobal.h"
-#include "directshowiosource.h"
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qcoreevent.h>
-#include <QtCore/qiodevice.h>
-#include <QtCore/qthread.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowSampleRequest
-{
-public:
- DirectShowSampleRequest(
- IMediaSample *sample, DWORD_PTR userData, LONGLONG position, LONG length, BYTE *buffer)
- : sample(sample)
- , userData(userData)
- , position(position)
- , length(length)
- , buffer(buffer)
- {
- }
-
- DirectShowSampleRequest *remove() { DirectShowSampleRequest *n = next; delete this; return n; }
-
- DirectShowSampleRequest *next = nullptr;
- IMediaSample *sample;
- DWORD_PTR userData;
- LONGLONG position;
- LONG length;
- BYTE *buffer;
- HRESULT result = S_FALSE;
-};
-
-DirectShowIOReader::DirectShowIOReader(
- QIODevice *device, DirectShowIOSource *source, DirectShowEventLoop *loop)
- : m_source(source)
- , m_device(device)
- , m_loop(loop)
-{
- moveToThread(device->thread());
-
- connect(device, &QIODevice::readyRead, this, &DirectShowIOReader::readyRead);
-}
-
-DirectShowIOReader::~DirectShowIOReader()
-{
- flushRequests();
-}
-
-HRESULT DirectShowIOReader::QueryInterface(REFIID riid, void **ppvObject)
-{
- return m_source->QueryInterface(riid, ppvObject);
-}
-
-ULONG DirectShowIOReader::AddRef()
-{
- return m_source->AddRef();
-}
-
-ULONG DirectShowIOReader::Release()
-{
- return m_source->Release();
-}
-
-// IAsyncReader
-HRESULT DirectShowIOReader::RequestAllocator(
- IMemAllocator *pPreferred, ALLOCATOR_PROPERTIES *pProps, IMemAllocator **ppActual)
-{
- if (!ppActual || !pProps)
- return E_POINTER;
-
- ALLOCATOR_PROPERTIES actualProperties;
-
- if (pProps->cbAlign == 0)
- pProps->cbAlign = 1;
-
- if (pPreferred && pPreferred->SetProperties(pProps, &actualProperties) == S_OK) {
- pPreferred->AddRef();
-
- *ppActual = pPreferred;
- m_source->setAllocator(*ppActual);
- return S_OK;
- }
-
- *ppActual = com_new<IMemAllocator>(CLSID_MemoryAllocator);
- if (*ppActual) {
- if ((*ppActual)->SetProperties(pProps, &actualProperties) == S_OK) {
- m_source->setAllocator(*ppActual);
- return S_OK;
- }
- (*ppActual)->Release();
- }
- ppActual = nullptr;
- return E_FAIL;
-}
-
-HRESULT DirectShowIOReader::Request(IMediaSample *pSample, DWORD_PTR dwUser)
-{
- QMutexLocker locker(&m_mutex);
-
- if (!pSample)
- return E_POINTER;
- if (m_flushing)
- return VFW_E_WRONG_STATE;
-
- REFERENCE_TIME startTime = 0;
- REFERENCE_TIME endTime = 0;
- BYTE *buffer;
-
- if (pSample->GetTime(&startTime, &endTime) != S_OK
- || pSample->GetPointer(&buffer) != S_OK) {
- return VFW_E_SAMPLE_TIME_NOT_SET;
- }
- LONGLONG position = startTime / 10000000;
- LONG length = qMin<qint64>((endTime - startTime) / 10000000, m_availableLength);
-
- auto request = new DirectShowSampleRequest(pSample, dwUser, position, length, buffer);
-
- if (m_pendingTail) {
- m_pendingTail->next = request;
- } else {
- m_pendingHead = request;
- m_loop->postEvent(this, new QEvent(QEvent::User));
- }
- m_pendingTail = request;
-
- return S_OK;
-}
-
-HRESULT DirectShowIOReader::WaitForNext(
- DWORD dwTimeout, IMediaSample **ppSample, DWORD_PTR *pdwUser)
-{
- if (!ppSample || !pdwUser)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
-
- do {
- if (m_readyHead) {
- DirectShowSampleRequest *request = m_readyHead;
-
- *ppSample = request->sample;
- *pdwUser = request->userData;
-
- HRESULT hr = request->result;
-
- m_readyHead = request->next;
-
- if (!m_readyHead)
- m_readyTail = nullptr;
-
- delete request;
-
- return hr;
- }
- if (m_flushing) {
- *ppSample = nullptr;
- *pdwUser = 0;
-
- return VFW_E_WRONG_STATE;
- }
- } while (m_wait.wait(&m_mutex, dwTimeout));
-
- *ppSample = nullptr;
- *pdwUser = 0;
-
- return VFW_E_TIMEOUT;
-}
-
-HRESULT DirectShowIOReader::SyncReadAligned(IMediaSample *pSample)
-{
- if (!pSample)
- return E_POINTER;
-
- REFERENCE_TIME startTime = 0;
- REFERENCE_TIME endTime = 0;
- BYTE *buffer;
-
- if (pSample->GetTime(&startTime, &endTime) != S_OK
- || pSample->GetPointer(&buffer) != S_OK) {
- return VFW_E_SAMPLE_TIME_NOT_SET;
- }
- LONGLONG position = startTime / 10000000;
- LONG length = (endTime - startTime) / 10000000;
-
- QMutexLocker locker(&m_mutex);
-
- if (thread() == QThread::currentThread()) {
- qint64 bytesRead = 0;
-
- HRESULT hr = blockingRead(position, length, buffer, &bytesRead);
- if (SUCCEEDED(hr))
- pSample->SetActualDataLength(bytesRead);
-
- return hr;
- }
- m_synchronousPosition = position;
- m_synchronousLength = length;
- m_synchronousBuffer = buffer;
-
- m_loop->postEvent(this, new QEvent(QEvent::User));
-
- m_wait.wait(&m_mutex);
-
- m_synchronousBuffer = nullptr;
-
- if (SUCCEEDED(m_synchronousResult))
- pSample->SetActualDataLength(m_synchronousBytesRead);
-
- return m_synchronousResult;
-}
-
-HRESULT DirectShowIOReader::SyncRead(LONGLONG llPosition, LONG lLength, BYTE *pBuffer)
-{
- if (!pBuffer)
- return E_POINTER;
-
- if (thread() == QThread::currentThread()) {
- qint64 bytesRead;
- return blockingRead(llPosition, lLength, pBuffer, &bytesRead);
- }
- QMutexLocker locker(&m_mutex);
-
- m_synchronousPosition = llPosition;
- m_synchronousLength = lLength;
- m_synchronousBuffer = pBuffer;
-
- m_loop->postEvent(this, new QEvent(QEvent::User));
-
- m_wait.wait(&m_mutex);
-
- m_synchronousBuffer = nullptr;
-
- return m_synchronousResult;
-}
-
-HRESULT DirectShowIOReader::Length(LONGLONG *pTotal, LONGLONG *pAvailable)
-{
- if (!pTotal || !pAvailable)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
- *pTotal = m_totalLength;
- *pAvailable = m_availableLength;
- return S_OK;
-}
-
-
-HRESULT DirectShowIOReader::BeginFlush()
-{
- QMutexLocker locker(&m_mutex);
-
- if (m_flushing)
- return S_FALSE;
-
- m_flushing = true;
-
- flushRequests();
-
- m_wait.wakeAll();
-
- return S_OK;
-}
-
-HRESULT DirectShowIOReader::EndFlush()
-{
- QMutexLocker locker(&m_mutex);
-
- if (!m_flushing)
- return S_FALSE;
-
- m_flushing = false;
-
- return S_OK;
-}
-
-void DirectShowIOReader::customEvent(QEvent *event)
-{
- if (event->type() == QEvent::User) {
- readyRead();
- } else {
- QObject::customEvent(event);
- }
-}
-
-void DirectShowIOReader::readyRead()
-{
- QMutexLocker locker(&m_mutex);
-
- m_availableLength = m_device->bytesAvailable() + m_device->pos();
- m_totalLength = m_device->size();
-
- if (m_synchronousBuffer) {
- if (nonBlockingRead(
- m_synchronousPosition,
- m_synchronousLength,
- m_synchronousBuffer,
- &m_synchronousBytesRead,
- &m_synchronousResult)) {
- m_wait.wakeAll();
- }
- } else {
- qint64 bytesRead = 0;
-
- while (m_pendingHead && nonBlockingRead(
- m_pendingHead->position,
- m_pendingHead->length,
- m_pendingHead->buffer,
- &bytesRead,
- &m_pendingHead->result)) {
- m_pendingHead->sample->SetActualDataLength(bytesRead);
-
- if (m_readyTail)
- m_readyTail->next = m_pendingHead;
- m_readyTail = m_pendingHead;
-
- m_pendingHead = m_pendingHead->next;
-
- m_readyTail->next = nullptr;
-
- if (!m_pendingHead)
- m_pendingTail = nullptr;
-
- if (!m_readyHead)
- m_readyHead = m_readyTail;
-
- m_wait.wakeAll();
- }
- }
-}
-
-HRESULT DirectShowIOReader::blockingRead(
- LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead)
-{
- *bytesRead = 0;
-
- if (qint64(position) > m_device->size())
- return S_FALSE;
-
- const qint64 maxSize = qMin<qint64>(m_device->size(), position + length);
-
- while (m_device->bytesAvailable() + m_device->pos() < maxSize) {
- if (!m_device->waitForReadyRead(-1))
- return S_FALSE;
- }
-
- if (m_device->pos() != position && !m_device->seek(position))
- return S_FALSE;
-
- const qint64 maxBytes = qMin<qint64>(length, m_device->bytesAvailable());
-
- *bytesRead = m_device->read(reinterpret_cast<char *>(buffer), maxBytes);
-
- if (*bytesRead != length) {
- ::memset(buffer + *bytesRead, 0, length - *bytesRead);
-
- return S_FALSE;
- }
- return S_OK;
-}
-
-bool DirectShowIOReader::nonBlockingRead(
- LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead, HRESULT *result)
-{
- const qint64 maxSize = qMin<qint64>(m_device->size(), position + length);
-
- if (position > m_device->size()) {
- *bytesRead = 0;
- *result = S_FALSE;
-
- return true;
- }
- if (m_device->bytesAvailable() + m_device->pos() >= maxSize) {
- if (m_device->pos() != position && !m_device->seek(position)) {
- *bytesRead = 0;
- *result = S_FALSE;
-
- return true;
- }
- const qint64 maxBytes = qMin<qint64>(length, m_device->bytesAvailable());
-
- *bytesRead = m_device->read(reinterpret_cast<char *>(buffer), maxBytes);
-
- if (*bytesRead != length) {
- ::memset(buffer + *bytesRead, 0, length - *bytesRead);
-
- *result = S_FALSE;
- } else {
- *result = S_OK;
- }
-
- return true;
- }
- return false;
-}
-
-void DirectShowIOReader::flushRequests()
-{
- while (m_pendingHead) {
- m_pendingHead->result = VFW_E_WRONG_STATE;
-
- if (m_readyTail)
- m_readyTail->next = m_pendingHead;
-
- m_readyTail = m_pendingHead;
-
- m_pendingHead = m_pendingHead->next;
-
- m_readyTail->next = nullptr;
-
- if (!m_pendingHead)
- m_pendingTail = nullptr;
-
- if (!m_readyHead)
- m_readyHead = m_readyTail;
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/player/directshowioreader.h b/src/plugins/directshow/player/directshowioreader.h
deleted file mode 100644
index a0f2d7adb..000000000
--- a/src/plugins/directshow/player/directshowioreader.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWIOREADER_H
-#define DIRECTSHOWIOREADER_H
-
-#include <dshow.h>
-
-#include <QtCore/qmutex.h>
-#include <QtCore/qobject.h>
-#include <QtCore/qwaitcondition.h>
-
-QT_BEGIN_NAMESPACE
-class QIODevice;
-
-class DirectShowEventLoop;
-class DirectShowIOSource;
-class DirectShowSampleRequest;
-
-class DirectShowIOReader : public QObject, public IAsyncReader
-{
- Q_OBJECT
-public:
- DirectShowIOReader(QIODevice *device, DirectShowIOSource *source, DirectShowEventLoop *loop);
- ~DirectShowIOReader() override;
-
- // IUnknown
- HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override;
- ULONG STDMETHODCALLTYPE AddRef() override;
- ULONG STDMETHODCALLTYPE Release() override;
-
- // IAsyncReader
- HRESULT STDMETHODCALLTYPE RequestAllocator(
- IMemAllocator *pPreferred, ALLOCATOR_PROPERTIES *pProps,
- IMemAllocator **ppActual) override;
-
- HRESULT STDMETHODCALLTYPE Request(IMediaSample *pSample, DWORD_PTR dwUser) override;
-
- HRESULT STDMETHODCALLTYPE WaitForNext(
- DWORD dwTimeout, IMediaSample **ppSample, DWORD_PTR *pdwUser) override;
-
- HRESULT STDMETHODCALLTYPE SyncReadAligned(IMediaSample *pSample) override;
-
- HRESULT STDMETHODCALLTYPE SyncRead(LONGLONG llPosition, LONG lLength, BYTE *pBuffer) override;
-
- HRESULT STDMETHODCALLTYPE Length(LONGLONG *pTotal, LONGLONG *pAvailable) override;
-
- HRESULT STDMETHODCALLTYPE BeginFlush() override;
- HRESULT STDMETHODCALLTYPE EndFlush() override;
-
-protected:
- void customEvent(QEvent *event) override;
-
-private Q_SLOTS:
- void readyRead();
-
-private:
- HRESULT blockingRead(LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead);
- bool nonBlockingRead(
- LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead, HRESULT *result);
- void flushRequests();
-
- DirectShowIOSource *m_source;
- QIODevice *m_device;
- DirectShowEventLoop *m_loop;
- DirectShowSampleRequest *m_pendingHead = nullptr;
- DirectShowSampleRequest *m_pendingTail = nullptr;
- DirectShowSampleRequest *m_readyHead = nullptr;
- DirectShowSampleRequest *m_readyTail = nullptr;
- LONGLONG m_synchronousPosition = 0;
- LONG m_synchronousLength = 0;
- qint64 m_synchronousBytesRead = 0;
- BYTE *m_synchronousBuffer = nullptr;
- HRESULT m_synchronousResult = S_OK;
- LONGLONG m_totalLength = 0;
- LONGLONG m_availableLength = 0;
- bool m_flushing = false;
- QMutex m_mutex;
- QWaitCondition m_wait;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/player/directshowiosource.cpp b/src/plugins/directshow/player/directshowiosource.cpp
deleted file mode 100644
index 54c043c17..000000000
--- a/src/plugins/directshow/player/directshowiosource.cpp
+++ /dev/null
@@ -1,530 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "directshowiosource.h"
-
-#include "directshowglobal.h"
-#include "directshowmediatype.h"
-#include "directshowmediatypeenum.h"
-#include "directshowpinenum.h"
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qurl.h>
-
-QT_BEGIN_NAMESPACE
-
-static const GUID directshow_subtypes[] =
-{
- MEDIASUBTYPE_NULL,
- MEDIASUBTYPE_Avi,
- MEDIASUBTYPE_Asf,
- MEDIASUBTYPE_MPEG1Video,
- MEDIASUBTYPE_QTMovie,
- MEDIASUBTYPE_WAVE,
- MEDIASUBTYPE_AIFF,
- MEDIASUBTYPE_AU,
- MEDIASUBTYPE_DssVideo,
- MEDIASUBTYPE_MPEG1Audio,
- MEDIASUBTYPE_MPEG1System,
- MEDIASUBTYPE_MPEG1VideoCD
-};
-
-DirectShowIOSource::DirectShowIOSource(DirectShowEventLoop *loop)
- : m_loop(loop)
-{
- // This filter has only one possible output type, that is, a stream of data
- // with no particular subtype. The graph builder will try every demux/decode filters
- // to find one able to decode the stream.
- //
- // The filter works in pull mode, the downstream filter is responsible for requesting
- // samples from this one.
- //
- AM_MEDIA_TYPE type
- {
- MEDIATYPE_Stream, // majortype
- MEDIASUBTYPE_NULL, // subtype
- TRUE, // bFixedSizeSamples
- FALSE, // bTemporalCompression
- 1, // lSampleSize
- GUID_NULL, // formattype
- nullptr, // pUnk
- 0, // cbFormat
- nullptr, // pbFormat
- };
-
- for (const auto &directshowSubtype : directshow_subtypes) {
- type.subtype = directshowSubtype;
- m_supportedMediaTypes.append(DirectShowMediaType(type));
- }
-}
-
-DirectShowIOSource::~DirectShowIOSource()
-{
- Q_ASSERT(m_ref == 0);
-
- delete m_reader;
-}
-
-void DirectShowIOSource::setDevice(QIODevice *device)
-{
- Q_ASSERT(!m_reader);
-
- m_reader = new DirectShowIOReader(device, this, m_loop);
-}
-
-void DirectShowIOSource::setAllocator(IMemAllocator *allocator)
-{
- if (m_allocator == allocator)
- return;
-
- if (m_allocator)
- m_allocator->Release();
-
- m_allocator = allocator;
-
- if (m_allocator)
- m_allocator->AddRef();
-}
-
-// IUnknown
-HRESULT DirectShowIOSource::QueryInterface(REFIID riid, void **ppvObject)
-{
- // 2dd74950-a890-11d1-abe8-00a0c905f375
- static const GUID iid_IAmFilterMiscFlags = {
- 0x2dd74950, 0xa890, 0x11d1, {0xab, 0xe8, 0x00, 0xa0, 0xc9, 0x05, 0xf3, 0x75}};
-
- if (!ppvObject)
- return E_POINTER;
-
- if (riid == IID_IUnknown || riid == IID_IPersist || riid == IID_IMediaFilter
- || riid == IID_IBaseFilter) {
- *ppvObject = static_cast<IBaseFilter *>(this);
- } else if (riid == iid_IAmFilterMiscFlags) {
- *ppvObject = static_cast<IAMFilterMiscFlags *>(this);
- } else if (riid == IID_IPin) {
- *ppvObject = static_cast<IPin *>(this);
- } else if (riid == IID_IAsyncReader) {
- m_queriedForAsyncReader = true;
- *ppvObject = static_cast<IAsyncReader *>(m_reader);
- } else {
- *ppvObject = nullptr;
-
- return E_NOINTERFACE;
- }
-
- AddRef();
-
- return S_OK;
-}
-
-ULONG DirectShowIOSource::AddRef()
-{
- return InterlockedIncrement(&m_ref);
-}
-
-ULONG DirectShowIOSource::Release()
-{
- ULONG ref = InterlockedDecrement(&m_ref);
-
- if (ref == 0) {
- delete this;
- }
-
- return ref;
-}
-
-// IPersist
-HRESULT DirectShowIOSource::GetClassID(CLSID *pClassID)
-{
- *pClassID = CLSID_NULL;
-
- return S_OK;
-}
-
-// IMediaFilter
-HRESULT DirectShowIOSource::Run(REFERENCE_TIME tStart)
-{
- Q_UNUSED(tStart);
- QMutexLocker locker(&m_mutex);
-
- m_state = State_Running;
-
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::Pause()
-{
- QMutexLocker locker(&m_mutex);
-
- m_state = State_Paused;
-
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::Stop()
-{
- QMutexLocker locker(&m_mutex);
-
- m_state = State_Stopped;
-
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::GetState(DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
-{
- Q_UNUSED(dwMilliSecsTimeout);
-
- if (!pState)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
- *pState = m_state;
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::SetSyncSource(IReferenceClock *pClock)
-{
- QMutexLocker locker(&m_mutex);
-
- if (m_clock)
- m_clock->Release();
-
- m_clock = pClock;
-
- if (m_clock)
- m_clock->AddRef();
-
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::GetSyncSource(IReferenceClock **ppClock)
-{
- if (!ppClock)
- return E_POINTER;
-
- if (!m_clock) {
- *ppClock = nullptr;
- return S_FALSE;
- }
- m_clock->AddRef();
- *ppClock = m_clock;
- return S_OK;
-}
-
-// IBaseFilter
-HRESULT DirectShowIOSource::EnumPins(IEnumPins **ppEnum)
-{
- if (!ppEnum)
- return E_POINTER;
-
- *ppEnum = new DirectShowPinEnum(QList<IPin *>() << this);
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::FindPin(LPCWSTR Id, IPin **ppPin)
-{
- if (!ppPin || !Id)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
- if (m_pinId == QStringView(Id)) {
- AddRef();
- *ppPin = this;
- return S_OK;
- }
- *ppPin = nullptr;
- return VFW_E_NOT_FOUND;
-}
-
-HRESULT DirectShowIOSource::JoinFilterGraph(IFilterGraph *pGraph, LPCWSTR pName)
-{
- QMutexLocker locker(&m_mutex);
-
- m_graph = pGraph;
- m_filterName = QString::fromWCharArray(pName);
-
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::QueryFilterInfo(FILTER_INFO *pInfo)
-{
- if (!pInfo)
- return E_POINTER;
-
- QString name = m_filterName;
- if (name.length() >= MAX_FILTER_NAME)
- name.truncate(MAX_FILTER_NAME - 1);
-
- int length = name.toWCharArray(pInfo->achName);
- pInfo->achName[length] = '\0';
-
- if (m_graph)
- m_graph->AddRef();
-
- pInfo->pGraph = m_graph;
-
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::QueryVendorInfo(LPWSTR *pVendorInfo)
-{
- Q_UNUSED(pVendorInfo);
-
- return E_NOTIMPL;
-}
-
-// IAMFilterMiscFlags
-ULONG DirectShowIOSource::GetMiscFlags()
-{
- return AM_FILTER_MISC_FLAGS_IS_SOURCE;
-}
-
-// IPin
-HRESULT DirectShowIOSource::Connect(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt)
-{
- if (!pReceivePin)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
-
- if (m_state != State_Stopped)
- return VFW_E_NOT_STOPPED;
-
- if (m_peerPin)
- return VFW_E_ALREADY_CONNECTED;
-
- // If we get a type from the graph manager, check that we support that
- if (pmt && pmt->majortype != MEDIATYPE_Stream)
- return VFW_E_TYPE_NOT_ACCEPTED;
-
- // This filter only works in pull mode, the downstream filter must query for the
- // AsyncReader interface during ReceiveConnection().
- // If it doesn't, we can't connect to it.
- m_queriedForAsyncReader = false;
- HRESULT hr = 0;
- // Negotiation of media type
- // - Complete'ish type (Stream with subtype specified).
- if (pmt && pmt->subtype != MEDIASUBTYPE_NULL /* aka. GUID_NULL */) {
- hr = pReceivePin->ReceiveConnection(this, pmt);
- // Update the media type for the current connection.
- if (SUCCEEDED(hr))
- DirectShowMediaType::copy(&m_connectionMediaType, pmt);
- } else if (pmt && pmt->subtype == MEDIATYPE_NULL) { // - Partial type (Stream, but no subtype specified).
- DirectShowMediaType::copy(&m_connectionMediaType, pmt);
- // Check if the receiving pin accepts any of the streaming subtypes.
- for (const DirectShowMediaType &t : qAsConst(m_supportedMediaTypes)) {
- m_connectionMediaType->subtype = t->subtype;
- hr = pReceivePin->ReceiveConnection(this, &m_connectionMediaType);
- if (SUCCEEDED(hr))
- break;
- }
- } else { // - No media type specified.
- // Check if the receiving pin accepts any of the streaming types.
- for (const DirectShowMediaType &t : qAsConst(m_supportedMediaTypes)) {
- hr = pReceivePin->ReceiveConnection(this, &t);
- if (SUCCEEDED(hr)) {
- m_connectionMediaType = t;
- break;
- }
- }
- }
-
- if (SUCCEEDED(hr) && m_queriedForAsyncReader) {
- m_peerPin = pReceivePin;
- m_peerPin->AddRef();
- } else {
- pReceivePin->Disconnect();
- if (m_allocator) {
- m_allocator->Release();
- m_allocator = nullptr;
- }
- if (!m_queriedForAsyncReader)
- hr = VFW_E_NO_TRANSPORT;
-
- m_connectionMediaType.clear();
- }
-
- return hr;
-}
-
-HRESULT DirectShowIOSource::ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt)
-{
- Q_UNUSED(pConnector);
- Q_UNUSED(pmt);
- // Output pin.
- return E_NOTIMPL;
-}
-
-HRESULT DirectShowIOSource::Disconnect()
-{
- QMutexLocker locker(&m_mutex);
-
- if (!m_peerPin)
- return S_FALSE;
- if (m_state != State_Stopped)
- return VFW_E_NOT_STOPPED;
-
- HRESULT hr = m_peerPin->Disconnect();
- if (!SUCCEEDED(hr))
- return hr;
-
- if (m_allocator) {
- m_allocator->Release();
- m_allocator = nullptr;
- }
-
- m_peerPin->Release();
- m_peerPin = nullptr;
-
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::ConnectedTo(IPin **ppPin)
-{
- if (!ppPin)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
- if (!m_peerPin) {
- *ppPin = nullptr;
- return VFW_E_NOT_CONNECTED;
- }
- m_peerPin->AddRef();
- *ppPin = m_peerPin;
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::ConnectionMediaType(AM_MEDIA_TYPE *pmt)
-{
- if (!pmt)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
- if (!m_peerPin) {
- pmt = nullptr;
- return VFW_E_NOT_CONNECTED;
- }
- DirectShowMediaType::copy(pmt, &m_connectionMediaType);
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::QueryPinInfo(PIN_INFO *pInfo)
-{
- if (!pInfo)
- return E_POINTER;
-
- AddRef();
-
- pInfo->pFilter = this;
- pInfo->dir = PINDIR_OUTPUT;
-
- const int bytes = qMin(MAX_FILTER_NAME, (m_pinId.length() + 1) * 2);
-
- ::memcpy(pInfo->achName, m_pinId.utf16(), bytes);
-
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::QueryId(LPWSTR *Id)
-{
- if (!Id)
- return E_POINTER;
-
- const int bytes = (m_pinId.length() + 1) * 2;
- *Id = static_cast<LPWSTR>(::CoTaskMemAlloc(bytes));
- ::memcpy(*Id, m_pinId.utf16(), bytes);
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::QueryAccept(const AM_MEDIA_TYPE *pmt)
-{
- if (!pmt)
- return E_POINTER;
- return pmt->majortype == MEDIATYPE_Stream ? S_OK : S_FALSE;
-}
-
-HRESULT DirectShowIOSource::EnumMediaTypes(IEnumMediaTypes **ppEnum)
-{
- if (!ppEnum)
- return E_POINTER;
- *ppEnum = new DirectShowMediaTypeEnum(m_supportedMediaTypes);
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::QueryInternalConnections(IPin **apPin, ULONG *nPin)
-{
- Q_UNUSED(apPin);
- Q_UNUSED(nPin);
-
- return E_NOTIMPL;
-}
-
-HRESULT DirectShowIOSource::EndOfStream()
-{
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::BeginFlush()
-{
- return m_reader->BeginFlush();
-}
-
-HRESULT DirectShowIOSource::EndFlush()
-{
- return m_reader->EndFlush();
-}
-
-HRESULT DirectShowIOSource::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
-{
- Q_UNUSED(tStart);
- Q_UNUSED(tStop);
- Q_UNUSED(dRate);
-
- return S_OK;
-}
-
-HRESULT DirectShowIOSource::QueryDirection(PIN_DIRECTION *pPinDir)
-{
- if (!pPinDir)
- return E_POINTER;
- *pPinDir = PINDIR_OUTPUT;
- return S_OK;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/player/directshowiosource.h b/src/plugins/directshow/player/directshowiosource.h
deleted file mode 100644
index 837842518..000000000
--- a/src/plugins/directshow/player/directshowiosource.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWIOSOURCE_H
-#define DIRECTSHOWIOSOURCE_H
-
-#include "directshowglobal.h"
-#include "directshowioreader.h"
-#include "directshowmediatype.h"
-
-#include <QtCore/qfile.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowIOSource
- : public IBaseFilter
- , public IAMFilterMiscFlags
- , public IPin
-{
- Q_DISABLE_COPY(DirectShowIOSource)
-public:
- DirectShowIOSource(DirectShowEventLoop *loop);
- virtual ~DirectShowIOSource();
-
- void setDevice(QIODevice *device);
- void setAllocator(IMemAllocator *allocator);
-
- // IUnknown
- HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override;
- ULONG STDMETHODCALLTYPE AddRef() override;
- ULONG STDMETHODCALLTYPE Release() override;
-
- // IPersist
- HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID) override;
-
- // IMediaFilter
- HRESULT STDMETHODCALLTYPE Run(REFERENCE_TIME tStart) override;
- HRESULT STDMETHODCALLTYPE Pause() override;
- HRESULT STDMETHODCALLTYPE Stop() override;
-
- HRESULT STDMETHODCALLTYPE GetState(DWORD dwMilliSecsTimeout, FILTER_STATE *pState) override;
-
- HRESULT STDMETHODCALLTYPE SetSyncSource(IReferenceClock *pClock) override;
- HRESULT STDMETHODCALLTYPE GetSyncSource(IReferenceClock **ppClock) override;
-
- // IBaseFilter
- HRESULT STDMETHODCALLTYPE EnumPins(IEnumPins **ppEnum) override;
- HRESULT STDMETHODCALLTYPE FindPin(LPCWSTR Id, IPin **ppPin) override;
-
- HRESULT STDMETHODCALLTYPE JoinFilterGraph(IFilterGraph *pGraph, LPCWSTR pName) override;
-
- HRESULT STDMETHODCALLTYPE QueryFilterInfo(FILTER_INFO *pInfo) override;
- HRESULT STDMETHODCALLTYPE QueryVendorInfo(LPWSTR *pVendorInfo) override;
-
- // IAMFilterMiscFlags
- ULONG STDMETHODCALLTYPE GetMiscFlags() override;
-
- // IPin
- HRESULT STDMETHODCALLTYPE Connect(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt) override;
- HRESULT STDMETHODCALLTYPE ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt) override;
- HRESULT STDMETHODCALLTYPE Disconnect() override;
- HRESULT STDMETHODCALLTYPE ConnectedTo(IPin **ppPin) override;
-
- HRESULT STDMETHODCALLTYPE ConnectionMediaType(AM_MEDIA_TYPE *pmt) override;
-
- HRESULT STDMETHODCALLTYPE QueryPinInfo(PIN_INFO *pInfo) override;
- HRESULT STDMETHODCALLTYPE QueryId(LPWSTR *Id) override;
-
- HRESULT STDMETHODCALLTYPE QueryAccept(const AM_MEDIA_TYPE *pmt) override;
-
- HRESULT STDMETHODCALLTYPE EnumMediaTypes(IEnumMediaTypes **ppEnum) override;
-
- HRESULT STDMETHODCALLTYPE QueryInternalConnections(IPin **apPin, ULONG *nPin) override;
-
- HRESULT STDMETHODCALLTYPE EndOfStream() override;
-
- HRESULT STDMETHODCALLTYPE BeginFlush() override;
- HRESULT STDMETHODCALLTYPE EndFlush() override;
-
- HRESULT STDMETHODCALLTYPE NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop,
- double dRate) override;
-
- HRESULT STDMETHODCALLTYPE QueryDirection(PIN_DIRECTION *pPinDir) override;
-
-private:
- volatile LONG m_ref = 1;
- FILTER_STATE m_state = State_Stopped;
- DirectShowIOReader *m_reader = nullptr;
- DirectShowEventLoop *m_loop;
- IFilterGraph *m_graph = nullptr;
- IReferenceClock *m_clock = nullptr;
- IMemAllocator *m_allocator = nullptr;
- IPin *m_peerPin = nullptr;
- DirectShowMediaType m_connectionMediaType;
- QList<DirectShowMediaType> m_supportedMediaTypes;
- QString m_filterName;
- const QString m_pinId = QLatin1String("Data");
- bool m_queriedForAsyncReader = false;
- QMutex m_mutex;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/player/directshowmetadatacontrol.cpp b/src/plugins/directshow/player/directshowmetadatacontrol.cpp
deleted file mode 100644
index 61138951c..000000000
--- a/src/plugins/directshow/player/directshowmetadatacontrol.cpp
+++ /dev/null
@@ -1,697 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <dshow.h>
-#ifdef min
-#undef min
-#endif
-#ifdef max
-#undef max
-#endif
-
-#include <QtMultimedia/qmediametadata.h>
-#include <QtCore/qcoreapplication.h>
-#include <QSize>
-#include <qdatetime.h>
-#include <qimage.h>
-
-#include <initguid.h>
-#include <qnetwork.h>
-
-#include "directshowmetadatacontrol.h"
-#include "directshowplayerservice.h"
-
-#include <QtMultimedia/private/qtmultimedia-config_p.h>
-
-#if QT_CONFIG(wmsdk)
-#include <wmsdk.h>
-#endif
-
-#if QT_CONFIG(wshellitem)
-#include <shlobj.h>
-#include <propkeydef.h>
-#include <private/qsystemlibrary_p.h>
-
-DEFINE_PROPERTYKEY(PKEY_Author, 0xF29F85E0, 0x4FF9, 0x1068, 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9, 4);
-DEFINE_PROPERTYKEY(PKEY_Title, 0xF29F85E0, 0x4FF9, 0x1068, 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9, 2);
-DEFINE_PROPERTYKEY(PKEY_Media_SubTitle, 0x56A3372E, 0xCE9C, 0x11D2, 0x9F, 0x0E, 0x00, 0x60, 0x97, 0xC6, 0x86, 0xF6, 38);
-DEFINE_PROPERTYKEY(PKEY_ParentalRating, 0x64440492, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 21);
-DEFINE_PROPERTYKEY(PKEY_Comment, 0xF29F85E0, 0x4FF9, 0x1068, 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9, 6);
-DEFINE_PROPERTYKEY(PKEY_Copyright, 0x64440492, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 11);
-DEFINE_PROPERTYKEY(PKEY_Media_ProviderStyle, 0x64440492, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 40);
-DEFINE_PROPERTYKEY(PKEY_Media_Year, 0x56A3372E, 0xCE9C, 0x11D2, 0x9F, 0x0E, 0x00, 0x60, 0x97, 0xC6, 0x86, 0xF6, 5);
-DEFINE_PROPERTYKEY(PKEY_Media_DateEncoded, 0x2E4B640D, 0x5019, 0x46D8, 0x88, 0x81, 0x55, 0x41, 0x4C, 0xC5, 0xCA, 0xA0, 100);
-DEFINE_PROPERTYKEY(PKEY_Rating, 0x64440492, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 9);
-DEFINE_PROPERTYKEY(PKEY_Keywords, 0xF29F85E0, 0x4FF9, 0x1068, 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9, 5);
-DEFINE_PROPERTYKEY(PKEY_Language, 0xD5CDD502, 0x2E9C, 0x101B, 0x93, 0x97, 0x08, 0x00, 0x2B, 0x2C, 0xF9, 0xAE, 28);
-DEFINE_PROPERTYKEY(PKEY_Media_Publisher, 0x64440492, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 30);
-DEFINE_PROPERTYKEY(PKEY_Media_Duration, 0x64440490, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 3);
-DEFINE_PROPERTYKEY(PKEY_Audio_EncodingBitrate, 0x64440490, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 4);
-DEFINE_PROPERTYKEY(PKEY_Media_AverageLevel, 0x09EDD5B6, 0xB301, 0x43C5, 0x99, 0x90, 0xD0, 0x03, 0x02, 0xEF, 0xFD, 0x46, 100);
-DEFINE_PROPERTYKEY(PKEY_Audio_ChannelCount, 0x64440490, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 7);
-DEFINE_PROPERTYKEY(PKEY_Audio_PeakValue, 0x2579E5D0, 0x1116, 0x4084, 0xBD, 0x9A, 0x9B, 0x4F, 0x7C, 0xB4, 0xDF, 0x5E, 100);
-DEFINE_PROPERTYKEY(PKEY_Audio_SampleRate, 0x64440490, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 5);
-DEFINE_PROPERTYKEY(PKEY_Audio_Format, 0x64440490, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 2);
-DEFINE_PROPERTYKEY(PKEY_Music_AlbumTitle, 0x56A3372E, 0xCE9C, 0x11D2, 0x9F, 0x0E, 0x00, 0x60, 0x97, 0xC6, 0x86, 0xF6, 4);
-DEFINE_PROPERTYKEY(PKEY_Music_AlbumArtist, 0x56A3372E, 0xCE9C, 0x11D2, 0x9F, 0x0E, 0x00, 0x60, 0x97, 0xC6, 0x86, 0xF6, 13);
-DEFINE_PROPERTYKEY(PKEY_Music_Artist, 0x56A3372E, 0xCE9C, 0x11D2, 0x9F, 0x0E, 0x00, 0x60, 0x97, 0xC6, 0x86, 0xF6, 2);
-DEFINE_PROPERTYKEY(PKEY_Music_Composer, 0x64440492, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 19);
-DEFINE_PROPERTYKEY(PKEY_Music_Conductor, 0x56A3372E, 0xCE9C, 0x11D2, 0x9F, 0x0E, 0x00, 0x60, 0x97, 0xC6, 0x86, 0xF6, 36);
-DEFINE_PROPERTYKEY(PKEY_Music_Lyrics, 0x56A3372E, 0xCE9C, 0x11D2, 0x9F, 0x0E, 0x00, 0x60, 0x97, 0xC6, 0x86, 0xF6, 12);
-DEFINE_PROPERTYKEY(PKEY_Music_Mood, 0x56A3372E, 0xCE9C, 0x11D2, 0x9F, 0x0E, 0x00, 0x60, 0x97, 0xC6, 0x86, 0xF6, 39);
-DEFINE_PROPERTYKEY(PKEY_Music_TrackNumber, 0x56A3372E, 0xCE9C, 0x11D2, 0x9F, 0x0E, 0x00, 0x60, 0x97, 0xC6, 0x86, 0xF6, 7);
-DEFINE_PROPERTYKEY(PKEY_Music_Genre, 0x56A3372E, 0xCE9C, 0x11D2, 0x9F, 0x0E, 0x00, 0x60, 0x97, 0xC6, 0x86, 0xF6, 11);
-DEFINE_PROPERTYKEY(PKEY_ThumbnailStream, 0xF29F85E0, 0x4FF9, 0x1068, 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9, 27);
-DEFINE_PROPERTYKEY(PKEY_Video_FrameHeight, 0x64440491, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 4);
-DEFINE_PROPERTYKEY(PKEY_Video_FrameWidth, 0x64440491, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 3);
-DEFINE_PROPERTYKEY(PKEY_Video_HorizontalAspectRatio, 0x64440491, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 42);
-DEFINE_PROPERTYKEY(PKEY_Video_VerticalAspectRatio, 0x64440491, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 45);
-DEFINE_PROPERTYKEY(PKEY_Video_FrameRate, 0x64440491, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 6);
-DEFINE_PROPERTYKEY(PKEY_Video_EncodingBitrate, 0x64440491, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 8);
-DEFINE_PROPERTYKEY(PKEY_Video_Director, 0x64440492, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 20);
-DEFINE_PROPERTYKEY(PKEY_Video_Compression, 0x64440491, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 10);
-DEFINE_PROPERTYKEY(PKEY_Media_Writer, 0x64440492, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03, 23);
-
-static QString nameForGUIDString(const QString &guid)
-{
- // Audio formats
- if (guid == "{00001610-0000-0010-8000-00AA00389B71}" || guid == "{000000FF-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("MPEG AAC Audio");
- if (guid == "{00001600-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("MPEG ADTS AAC Audio");
- if (guid == "{00000092-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Dolby AC-3 SPDIF");
- if (guid == "{E06D802C-DB46-11CF-B4D1-00805F6CBBEA}" || guid == "{00002000-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Dolby AC-3");
- if (guid == "{A7FB87AF-2D02-42FB-A4D4-05CD93843BDD}")
- return QStringLiteral("Dolby Digital Plus");
- if (guid == "{00000009-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("DRM");
- if (guid == "{00000008-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Digital Theater Systems Audio (DTS)");
- if (guid == "{00000003-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("IEEE Float Audio");
- if (guid == "{00000055-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("MPEG Audio Layer-3 (MP3)");
- if (guid == "{00000050-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("MPEG-1 Audio");
- if (guid == "{2E6D7033-767A-494D-B478-F29D25DC9037}")
- return QStringLiteral("MPEG Audio Layer 1/2");
- if (guid == "{0000000A-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Windows Media Audio Voice");
- if (guid == "{00000001-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Uncompressed PCM Audio");
- if (guid == "{00000164-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Windows Media Audio 9 SPDIF");
- if (guid == "{00000161-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Windows Media Audio 8 (WMA2)");
- if (guid == "{00000162-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Windows Media Audio 9 (WMA3");
- if (guid == "{00000163-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Windows Media Audio 9 Lossless");
- if (guid == "{8D2FD10B-5841-4a6b-8905-588FEC1ADED9}")
- return QStringLiteral("Vorbis");
- if (guid == "{0000F1AC-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Free Lossless Audio Codec (FLAC)");
- if (guid == "{00006C61-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Apple Lossless Audio Codec (ALAC)");
-
- // Video formats
- if (guid == "{35327664-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("DVCPRO 25 (DV25)");
- if (guid == "{30357664-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("DVCPRO 50 (DV50)");
- if (guid == "{20637664-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("DVC/DV Video");
- if (guid == "{31687664-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("DVCPRO 100 (DVH1)");
- if (guid == "{64687664-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("HD-DVCR (DVHD)");
- if (guid == "{64737664-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("SDL-DVCR (DVSD)");
- if (guid == "{6C737664-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("SD-DVCR (DVSL)");
- if (guid == "{33363248-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("H.263 Video");
- if (guid == "{34363248-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("H.264 Video");
- if (guid == "{35363248-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("H.265 Video");
- if (guid == "{43564548-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("High Efficiency Video Coding (HEVC)");
- if (guid == "{3253344D-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("MPEG-4 part 2 Video (M4S2)");
- if (guid == "{47504A4D-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Motion JPEG (MJPG)");
- if (guid == "{3334504D-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Microsoft MPEG 4 version 3 (MP43)");
- if (guid == "{5334504D-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("ISO MPEG 4 version 1 (MP4S)");
- if (guid == "{5634504D-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("MPEG-4 part 2 Video (MP4V)");
- if (guid == "{E06D8026-DB46-11CF-B4D1-00805F6CBBEA}")
- return QStringLiteral("MPEG-2 Video");
- if (guid == "{3147504D-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("MPEG-1 Video");
- if (guid == "{3153534D-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Windows Media Screen 1 (MSS1)");
- if (guid == "{3253534D-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Windows Media Video 9 Screen (MSS2)");
- if (guid == "{31564D57-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Windows Media Video 7 (WMV1)");
- if (guid == "{32564D57-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Windows Media Video 8 (WMV2)");
- if (guid == "{33564D57-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Windows Media Video 9 (WMV3)");
- if (guid == "{31435657-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("Windows Media Video VC1 (WVC1)");
- if (guid == "{30385056-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("VP8 Video");
- if (guid == "{30395056-0000-0010-8000-00AA00389B71}")
- return QStringLiteral("VP9 Video");
- return QStringLiteral("Unknown codec");
-}
-
-typedef HRESULT (WINAPI *q_SHCreateItemFromParsingName)(PCWSTR, IBindCtx *, const GUID&, void **);
-static q_SHCreateItemFromParsingName sHCreateItemFromParsingName = nullptr;
-#endif
-
-#if QT_CONFIG(wmsdk)
-
-namespace
-{
- struct QWMMetaDataKey
- {
- QString qtName;
- const wchar_t *wmName;
-
- QWMMetaDataKey(const QString &qtn, const wchar_t *wmn) : qtName(qtn), wmName(wmn) { }
- };
-}
-
-using QWMMetaDataKeys = QList<QWMMetaDataKey>;
-Q_GLOBAL_STATIC(QWMMetaDataKeys, metadataKeys)
-
-static const QWMMetaDataKeys *qt_wmMetaDataKeys()
-{
- if (metadataKeys->isEmpty()) {
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Title, L"Title"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::SubTitle, L"WM/SubTitle"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Author, L"Author"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Comment, L"Comment"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Description, L"Description"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Category, L"WM/Category"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Genre, L"WM/Genre"));
- //metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Date, 0));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Year, L"WM/Year"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::UserRating, L"Rating"));
- //metadataKeys->append(QWMMetaDataKey(QMediaMetaData::MetaDatawords, 0));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Language, L"WM/Language"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Publisher, L"WM/Publisher"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Copyright, L"Copyright"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::ParentalRating, L"WM/ParentalRating"));
- //metadataKeys->append(QWMMetaDataKey(QMediaMetaData::RatingOrganisation, L"RatingOrganisation"));
-
- // Media
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Size, L"FileSize"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::MediaType, L"MediaType"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Duration, L"Duration"));
-
- // Audio
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::AudioBitRate, L"AudioBitRate"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::AudioCodec, L"AudioCodec"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::ChannelCount, L"ChannelCount"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::SampleRate, L"Frequency"));
-
- // Music
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::AlbumTitle, L"WM/AlbumTitle"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::AlbumArtist, L"WM/AlbumArtist"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::ContributingArtist, L"Author"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Composer, L"WM/Composer"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Conductor, L"WM/Conductor"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Lyrics, L"WM/Lyrics"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Mood, L"WM/Mood"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::TrackNumber, L"WM/TrackNumber"));
- //metadataKeys->append(QWMMetaDataKey(QMediaMetaData::TrackCount, 0));
- //metadataKeys->append(QWMMetaDataKey(QMediaMetaData::CoverArtUriSmall, 0));
- //metadataKeys->append(QWMMetaDataKey(QMediaMetaData::CoverArtUriLarge, 0));
-
- // Image/Video
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Resolution, L"WM/VideoHeight"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::PixelAspectRatio, L"AspectRatioX"));
-
- // Video
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::VideoFrameRate, L"WM/VideoFrameRate"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::VideoBitRate, L"VideoBitRate"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::VideoCodec, L"VideoCodec"));
-
- //metadataKeys->append(QWMMetaDataKey(QMediaMetaData::PosterUri, 0));
-
- // Movie
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::ChapterNumber, L"ChapterNumber"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Director, L"WM/Director"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::LeadPerformer, L"LeadPerformer"));
- metadataKeys->append(QWMMetaDataKey(QMediaMetaData::Writer, L"WM/Writer"));
- }
-
- return metadataKeys;
-}
-
-static QVariant getValue(IWMHeaderInfo *header, const wchar_t *key)
-{
- WORD streamNumber = 0;
- WMT_ATTR_DATATYPE type = WMT_TYPE_DWORD;
- WORD size = 0;
-
- if (header->GetAttributeByName(&streamNumber, key, &type, nullptr, &size) == S_OK) {
- switch (type) {
- case WMT_TYPE_DWORD:
- if (size == sizeof(DWORD)) {
- DWORD word;
- if (header->GetAttributeByName(
- &streamNumber,
- key,
- &type,
- reinterpret_cast<BYTE *>(&word),
- &size) == S_OK) {
- return int(word);
- }
- }
- break;
- case WMT_TYPE_STRING:
- {
- QString string;
- string.resize(size / 2); // size is in bytes, string is in UTF16
-
- if (header->GetAttributeByName(
- &streamNumber,
- key,
- &type,
- reinterpret_cast<BYTE *>(string.data()),
- &size) == S_OK) {
- return string;
- }
- }
- break;
- case WMT_TYPE_BINARY:
- {
- QByteArray bytes;
- bytes.resize(size);
- if (header->GetAttributeByName(
- &streamNumber,
- key,
- &type,
- reinterpret_cast<BYTE *>(bytes.data()),
- &size) == S_OK) {
- return bytes;
- }
- }
- break;
- case WMT_TYPE_BOOL:
- if (size == sizeof(DWORD)) {
- DWORD word;
- if (header->GetAttributeByName(
- &streamNumber,
- key,
- &type,
- reinterpret_cast<BYTE *>(&word),
- &size) == S_OK) {
- return bool(word);
- }
- }
- break;
- case WMT_TYPE_QWORD:
- if (size == sizeof(QWORD)) {
- QWORD word;
- if (header->GetAttributeByName(
- &streamNumber,
- key,
- &type,
- reinterpret_cast<BYTE *>(&word),
- &size) == S_OK) {
- return qint64(word);
- }
- }
- break;
- case WMT_TYPE_WORD:
- if (size == sizeof(WORD)){
- WORD word;
- if (header->GetAttributeByName(
- &streamNumber,
- key,
- &type,
- reinterpret_cast<BYTE *>(&word),
- &size) == S_OK) {
- return short(word);
- }
- }
- break;
- case WMT_TYPE_GUID:
- if (size == 16) {
- }
- break;
- default:
- break;
- }
- }
- return QVariant();
-}
-#endif
-
-#if QT_CONFIG(wshellitem)
-static QVariant convertValue(const PROPVARIANT& var)
-{
- QVariant value;
- switch (var.vt) {
- case VT_LPWSTR:
- value = QString::fromUtf16(reinterpret_cast<const ushort*>(var.pwszVal));
- break;
- case VT_UI4:
- value = uint(var.ulVal);
- break;
- case VT_UI8:
- value = qulonglong(var.uhVal.QuadPart);
- break;
- case VT_BOOL:
- value = bool(var.boolVal);
- break;
- case VT_FILETIME:
- SYSTEMTIME sysDate;
- if (!FileTimeToSystemTime(&var.filetime, &sysDate))
- break;
- value = QDate(sysDate.wYear, sysDate.wMonth, sysDate.wDay);
- break;
- case VT_STREAM:
- {
- STATSTG stat;
- if (FAILED(var.pStream->Stat(&stat, STATFLAG_NONAME)))
- break;
- void *data = malloc(stat.cbSize.QuadPart);
- ULONG read = 0;
- if (FAILED(var.pStream->Read(data, stat.cbSize.QuadPart, &read))) {
- free(data);
- break;
- }
- value = QImage::fromData(reinterpret_cast<const uchar*>(data), read);
- free(data);
- }
- break;
- case VT_VECTOR | VT_LPWSTR:
- QStringList vList;
- for (ULONG i = 0; i < var.calpwstr.cElems; ++i)
- vList.append(QString::fromUtf16(reinterpret_cast<const ushort*>(var.calpwstr.pElems[i])));
- value = vList;
- break;
- }
- return value;
-}
-#endif
-
-DirectShowMetaDataControl::DirectShowMetaDataControl(QObject *parent)
- : QMetaDataReaderControl(parent)
-{
-}
-
-DirectShowMetaDataControl::~DirectShowMetaDataControl() = default;
-
-bool DirectShowMetaDataControl::isMetaDataAvailable() const
-{
- return m_available;
-}
-
-QVariant DirectShowMetaDataControl::metaData(const QString &key) const
-{
- return m_metadata.value(key);
-}
-
-QStringList DirectShowMetaDataControl::availableMetaData() const
-{
- return m_metadata.keys();
-}
-
-static QString convertBSTR(BSTR *string)
-{
- QString value = QString::fromUtf16(reinterpret_cast<ushort *>(*string),
- ::SysStringLen(*string));
-
- ::SysFreeString(*string);
- string = nullptr;
-
- return value;
-}
-
-void DirectShowMetaDataControl::setMetadata(const QVariantMap &metadata)
-{
- m_metadata = metadata;
- setMetadataAvailable(!m_metadata.isEmpty());
-}
-
-void DirectShowMetaDataControl::updateMetadata(const QString &fileSrc, QVariantMap &metadata)
-{
-#if QT_CONFIG(wshellitem)
- if (!sHCreateItemFromParsingName) {
- QSystemLibrary lib(QStringLiteral("shell32"));
- sHCreateItemFromParsingName = (q_SHCreateItemFromParsingName)(lib.resolve("SHCreateItemFromParsingName"));
- }
-
- if (!fileSrc.isEmpty() && sHCreateItemFromParsingName) {
- IShellItem2* shellItem = nullptr;
- if (sHCreateItemFromParsingName(reinterpret_cast<const WCHAR*>(fileSrc.utf16()),
- nullptr, IID_PPV_ARGS(&shellItem)) == S_OK) {
-
- IPropertyStore *pStore = nullptr;
- if (shellItem->GetPropertyStore(GPS_DEFAULT, IID_PPV_ARGS(&pStore)) == S_OK) {
- DWORD cProps;
- if (SUCCEEDED(pStore->GetCount(&cProps))) {
- for (DWORD i = 0; i < cProps; ++i)
- {
- PROPERTYKEY key;
- PROPVARIANT var;
- PropVariantInit(&var);
- if (FAILED(pStore->GetAt(i, &key)))
- continue;
- if (FAILED(pStore->GetValue(key, &var)))
- continue;
-
- if (IsEqualPropertyKey(key, PKEY_Author)) {
- metadata.insert(QMediaMetaData::Author, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Title)) {
- metadata.insert(QMediaMetaData::Title, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Media_SubTitle)) {
- metadata.insert(QMediaMetaData::SubTitle, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_ParentalRating)) {
- metadata.insert(QMediaMetaData::ParentalRating, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Comment)) {
- metadata.insert(QMediaMetaData::Description, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Copyright)) {
- metadata.insert(QMediaMetaData::Copyright, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Media_ProviderStyle)) {
- metadata.insert(QMediaMetaData::Genre, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Media_Year)) {
- metadata.insert(QMediaMetaData::Year, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Media_DateEncoded)) {
- metadata.insert(QMediaMetaData::Date, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Rating)) {
- metadata.insert(QMediaMetaData::UserRating,
- int((convertValue(var).toUInt() - 1) / qreal(98) * 100));
- } else if (IsEqualPropertyKey(key, PKEY_Keywords)) {
- metadata.insert(QMediaMetaData::Keywords, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Language)) {
- metadata.insert(QMediaMetaData::Language, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Media_Publisher)) {
- metadata.insert(QMediaMetaData::Publisher, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Media_Duration)) {
- metadata.insert(QMediaMetaData::Duration,
- (convertValue(var).toLongLong() + 10000) / 10000);
- } else if (IsEqualPropertyKey(key, PKEY_Audio_EncodingBitrate)) {
- metadata.insert(QMediaMetaData::AudioBitRate, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Media_AverageLevel)) {
- metadata.insert(QMediaMetaData::AverageLevel, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Audio_ChannelCount)) {
- metadata.insert(QMediaMetaData::ChannelCount, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Audio_PeakValue)) {
- metadata.insert(QMediaMetaData::PeakValue, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Audio_SampleRate)) {
- metadata.insert(QMediaMetaData::SampleRate, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Music_AlbumTitle)) {
- metadata.insert(QMediaMetaData::AlbumTitle, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Music_AlbumArtist)) {
- metadata.insert(QMediaMetaData::AlbumArtist, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Music_Artist)) {
- metadata.insert(QMediaMetaData::ContributingArtist, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Music_Composer)) {
- metadata.insert(QMediaMetaData::Composer, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Music_Conductor)) {
- metadata.insert(QMediaMetaData::Conductor, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Music_Lyrics)) {
- metadata.insert(QMediaMetaData::Lyrics, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Music_Mood)) {
- metadata.insert(QMediaMetaData::Mood, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Music_TrackNumber)) {
- metadata.insert(QMediaMetaData::TrackNumber, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Music_Genre)) {
- metadata.insert(QMediaMetaData::Genre, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_ThumbnailStream)) {
- metadata.insert(QMediaMetaData::ThumbnailImage, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Video_FrameHeight)) {
- QSize res;
- res.setHeight(convertValue(var).toUInt());
- if (SUCCEEDED(pStore->GetValue(PKEY_Video_FrameWidth, &var)))
- res.setWidth(convertValue(var).toUInt());
- metadata.insert(QMediaMetaData::Resolution, res);
- } else if (IsEqualPropertyKey(key, PKEY_Video_HorizontalAspectRatio)) {
- QSize aspectRatio;
- aspectRatio.setWidth(convertValue(var).toUInt());
- if (SUCCEEDED(pStore->GetValue(PKEY_Video_VerticalAspectRatio, &var)))
- aspectRatio.setHeight(convertValue(var).toUInt());
- metadata.insert(QMediaMetaData::PixelAspectRatio, aspectRatio);
- } else if (IsEqualPropertyKey(key, PKEY_Video_FrameRate)) {
- metadata.insert(QMediaMetaData::VideoFrameRate,
- convertValue(var).toReal() / 1000);
- } else if (IsEqualPropertyKey(key, PKEY_Video_EncodingBitrate)) {
- metadata.insert(QMediaMetaData::VideoBitRate, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Video_Director)) {
- metadata.insert(QMediaMetaData::Director, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Media_Writer)) {
- metadata.insert(QMediaMetaData::Writer, convertValue(var));
- } else if (IsEqualPropertyKey(key, PKEY_Video_Compression)) {
- metadata.insert(QMediaMetaData::VideoCodec, nameForGUIDString(convertValue(var).toString()));
- } else if (IsEqualPropertyKey(key, PKEY_Audio_Format)) {
- metadata.insert(QMediaMetaData::AudioCodec, nameForGUIDString(convertValue(var).toString()));
- }
-
- PropVariantClear(&var);
- }
- }
-
- pStore->Release();
- }
-
- shellItem->Release();
- }
- }
-#else
- Q_UNUSED(fileSrc);
- Q_UNUSED(metadata);
-#endif
-}
-
-void DirectShowMetaDataControl::updateMetadata(IFilterGraph2 *graph, IBaseFilter *source, QVariantMap &metadata)
-{
-#if QT_CONFIG(wmsdk)
- if (IWMHeaderInfo *info = com_cast<IWMHeaderInfo>(source, IID_IWMHeaderInfo)) {
- const auto keys = *qt_wmMetaDataKeys();
- for (const QWMMetaDataKey &key : keys) {
- QVariant var = getValue(info, key.wmName);
- if (var.isValid()) {
- if (key.qtName == QMediaMetaData::Duration) {
- // duration is provided in 100-nanosecond units, convert to milliseconds
- var = (var.toLongLong() + 10000) / 10000;
- } else if (key.qtName == QMediaMetaData::Resolution) {
- QSize res;
- res.setHeight(var.toUInt());
- res.setWidth(getValue(info, L"WM/VideoWidth").toUInt());
- var = res;
- } else if (key.qtName == QMediaMetaData::VideoFrameRate) {
- var = var.toReal() / 1000.f;
- } else if (key.qtName == QMediaMetaData::PixelAspectRatio) {
- QSize aspectRatio;
- aspectRatio.setWidth(var.toUInt());
- aspectRatio.setHeight(getValue(info, L"AspectRatioY").toUInt());
- var = aspectRatio;
- } else if (key.qtName == QMediaMetaData::UserRating) {
- var = (var.toUInt() - 1) / qreal(98) * 100;
- }
-
- metadata.insert(key.qtName, var);
- }
- }
-
- info->Release();
- }
-
- if (!metadata.isEmpty())
- return;
-#endif
- {
- IAMMediaContent *content = nullptr;
-
- if ((!graph || graph->QueryInterface(
- IID_IAMMediaContent, reinterpret_cast<void **>(&content)) != S_OK)
- && (!source || source->QueryInterface(
- IID_IAMMediaContent, reinterpret_cast<void **>(&content)) != S_OK)) {
- content = nullptr;
- }
-
- if (content) {
- BSTR string = nullptr;
-
- if (content->get_AuthorName(&string) == S_OK)
- metadata.insert(QMediaMetaData::Author, convertBSTR(&string));
-
- if (content->get_Title(&string) == S_OK)
- metadata.insert(QMediaMetaData::Title, convertBSTR(&string));
-
- if (content->get_Description(&string) == S_OK)
- metadata.insert(QMediaMetaData::Description, convertBSTR(&string));
-
- if (content->get_Rating(&string) == S_OK)
- metadata.insert(QMediaMetaData::UserRating, convertBSTR(&string));
-
- if (content->get_Copyright(&string) == S_OK)
- metadata.insert(QMediaMetaData::Copyright, convertBSTR(&string));
-
- content->Release();
- }
- }
-}
-
-void DirectShowMetaDataControl::setMetadataAvailable(bool available)
-{
- if (m_available == available)
- return;
-
- m_available = available;
-
- // If the metadata is not available, notify about it immediately.
- Qt::ConnectionType type = m_available ? Qt::QueuedConnection : Qt::AutoConnection;
- QMetaObject::invokeMethod(this, "metaDataAvailableChanged", type, Q_ARG(bool, m_available));
- // Currently the metadata is changed only with its availability.
- QMetaObject::invokeMethod(this, "metaDataChanged", type);
-}
diff --git a/src/plugins/directshow/player/directshowmetadatacontrol.h b/src/plugins/directshow/player/directshowmetadatacontrol.h
deleted file mode 100644
index e66127ab3..000000000
--- a/src/plugins/directshow/player/directshowmetadatacontrol.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWMETADATACONTROL_H
-#define DIRECTSHOWMETADATACONTROL_H
-
-#include <dshow.h>
-
-#include <qmetadatareadercontrol.h>
-
-#include "directshowglobal.h"
-
-#include <QtCore/qcoreevent.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowMetaDataControl : public QMetaDataReaderControl
-{
- Q_OBJECT
-public:
- DirectShowMetaDataControl(QObject *parent = nullptr);
- ~DirectShowMetaDataControl() override;
-
- bool isMetaDataAvailable() const override;
-
- QVariant metaData(const QString &key) const override;
- QStringList availableMetaData() const override;
-
- void setMetadata(const QVariantMap &metadata);
-
- static void updateMetadata(const QString &fileSrc, QVariantMap &metadata);
- static void updateMetadata(IFilterGraph2 *graph, IBaseFilter *source, QVariantMap &metadata);
-
-private:
- void setMetadataAvailable(bool available);
-
- enum Event
- {
- MetaDataChanged = QEvent::User
- };
-
- QVariantMap m_metadata;
- bool m_available = false;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/player/directshowplayercontrol.cpp b/src/plugins/directshow/player/directshowplayercontrol.cpp
deleted file mode 100644
index 50e8d6421..000000000
--- a/src/plugins/directshow/player/directshowplayercontrol.cpp
+++ /dev/null
@@ -1,397 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <dshow.h>
-
-#include "directshowplayercontrol.h"
-
-#include "directshowplayerservice.h"
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qmath.h>
-#include <qaudio.h>
-
-DirectShowPlayerControl::DirectShowPlayerControl(DirectShowPlayerService *service, QObject *parent)
- : QMediaPlayerControl(parent)
- , m_service(service)
-{
-}
-
-DirectShowPlayerControl::~DirectShowPlayerControl()
-{
- if (m_audio)
- m_audio->Release();
-}
-
-QMediaPlayer::State DirectShowPlayerControl::state() const
-{
- return m_state;
-}
-
-QMediaPlayer::MediaStatus DirectShowPlayerControl::mediaStatus() const
-{
- return m_status;
-}
-
-qint64 DirectShowPlayerControl::duration() const
-{
- return m_duration;
-}
-
-qint64 DirectShowPlayerControl::position() const
-{
- if (m_pendingPosition != -1)
- return m_pendingPosition;
-
- return m_service->position();
-}
-
-void DirectShowPlayerControl::setPosition(qint64 position)
-{
- if (m_status == QMediaPlayer::EndOfMedia) {
- m_status = QMediaPlayer::LoadedMedia;
- emit mediaStatusChanged(m_status);
- }
-
- if (m_state == QMediaPlayer::StoppedState) {
- if (m_pendingPosition != position) {
- m_pendingPosition = position;
- emit positionChanged(m_pendingPosition);
- }
- return;
- }
-
- m_service->seek(position);
- m_pendingPosition = -1;
-}
-
-int DirectShowPlayerControl::volume() const
-{
- return m_volume;
-}
-
-void DirectShowPlayerControl::setVolume(int volume)
-{
- int boundedVolume = qBound(0, volume, 100);
-
- if (m_volume == boundedVolume)
- return;
-
- m_volume = boundedVolume;
-
- if (!m_muted)
- setVolumeHelper(m_volume);
-
- emit volumeChanged(m_volume);
-}
-
-bool DirectShowPlayerControl::isMuted() const
-{
- return m_muted;
-}
-
-void DirectShowPlayerControl::setMuted(bool muted)
-{
- if (m_muted == muted)
- return;
-
- m_muted = muted;
-
- setVolumeHelper(m_muted ? 0 : m_volume);
-
- emit mutedChanged(m_muted);
-}
-
-void DirectShowPlayerControl::setVolumeHelper(int volume)
-{
- if (!m_audio)
- return;
-
- long adjustedVolume;
- if (volume == 0) {
- adjustedVolume = -10000; // -100 dB (lower limit for put_Volume())
- } else if (volume == 100) {
- adjustedVolume = 0;
- } else {
- adjustedVolume = QAudio::convertVolume(volume / qreal(100),
- QAudio::LinearVolumeScale,
- QAudio::DecibelVolumeScale) * 100;
- }
-
- m_audio->put_Volume(adjustedVolume);
-}
-
-int DirectShowPlayerControl::bufferStatus() const
-{
- return m_service->bufferStatus();
-}
-
-bool DirectShowPlayerControl::isAudioAvailable() const
-{
- return m_streamTypes & DirectShowPlayerService::AudioStream;
-}
-
-bool DirectShowPlayerControl::isVideoAvailable() const
-{
- return m_streamTypes & DirectShowPlayerService::VideoStream;
-}
-
-bool DirectShowPlayerControl::isSeekable() const
-{
- return m_seekable;
-}
-
-QMediaTimeRange DirectShowPlayerControl::availablePlaybackRanges() const
-{
- return m_service->availablePlaybackRanges();
-}
-
-qreal DirectShowPlayerControl::playbackRate() const
-{
- return m_playbackRate;
-}
-
-void DirectShowPlayerControl::setPlaybackRate(qreal rate)
-{
- if (!qFuzzyCompare(m_playbackRate, rate)) {
- m_service->setRate(rate);
-
- emit playbackRateChanged(m_playbackRate = rate);
- }
-}
-
-QMediaContent DirectShowPlayerControl::media() const
-{
- return m_media;
-}
-
-const QIODevice *DirectShowPlayerControl::mediaStream() const
-{
- return m_stream;
-}
-
-void DirectShowPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream)
-{
- if (m_media == media && m_stream == stream)
- return;
-
- m_pendingPosition = -1;
- m_emitPosition = -1;
-
- m_media = media;
- m_stream = stream;
-
- m_updateProperties &= PlaybackRateProperty;
-
- m_service->load(media, stream);
-
- emit mediaChanged(m_media);
- emitPropertyChanges();
-}
-
-void DirectShowPlayerControl::play()
-{
- playOrPause(QMediaPlayer::PlayingState);
-}
-
-void DirectShowPlayerControl::pause()
-{
- playOrPause(QMediaPlayer::PausedState);
-}
-
-void DirectShowPlayerControl::playOrPause(QMediaPlayer::State state)
-{
- if (m_status == QMediaPlayer::NoMedia || state == QMediaPlayer::StoppedState)
- return;
- if (m_status == QMediaPlayer::InvalidMedia) {
- setMedia(m_media, m_stream);
- if (m_error != QMediaPlayer::NoError)
- return;
- }
-
- m_emitPosition = -1;
- m_state = state;
-
- if (m_pendingPosition != -1)
- setPosition(m_pendingPosition);
-
- if (state == QMediaPlayer::PausedState)
- m_service->pause();
- else
- m_service->play();
-
- emit stateChanged(m_state);
-}
-
-void DirectShowPlayerControl::stop()
-{
- m_emitPosition = -1;
- m_service->stop();
- emit stateChanged(m_state = QMediaPlayer::StoppedState);
-}
-
-void DirectShowPlayerControl::customEvent(QEvent *event)
-{
- if (event->type() == QEvent::Type(PropertiesChanged)) {
- emitPropertyChanges();
-
- event->accept();
- } else {
- QMediaPlayerControl::customEvent(event);
- }
-}
-
-void DirectShowPlayerControl::emitPropertyChanges()
-{
- int properties = m_updateProperties;
- m_updateProperties = 0;
-
- if (properties & StatusProperty)
- emit mediaStatusChanged(m_status);
-
- if ((properties & ErrorProperty) && m_error != QMediaPlayer::NoError)
- emit error(m_error, m_errorString);
-
- if (properties & PlaybackRateProperty)
- emit playbackRateChanged(m_playbackRate);
-
- if (properties & StreamTypesProperty) {
- emit audioAvailableChanged(m_streamTypes & DirectShowPlayerService::AudioStream);
- emit videoAvailableChanged(m_streamTypes & DirectShowPlayerService::VideoStream);
- }
-
- if (properties & PositionProperty && m_emitPosition != -1)
- emit positionChanged(m_emitPosition);
-
- if (properties & DurationProperty)
- emit durationChanged(m_duration);
-
- if (properties & SeekableProperty)
- emit seekableChanged(m_seekable);
-
- if (properties & StateProperty)
- emit stateChanged(m_state);
-}
-
-void DirectShowPlayerControl::scheduleUpdate(int properties)
-{
- if (m_updateProperties == 0)
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(PropertiesChanged)));
-
- m_updateProperties |= properties;
-}
-
-void DirectShowPlayerControl::updateState(QMediaPlayer::State state)
-{
- if (m_state != state) {
- m_state = state;
-
- scheduleUpdate(StateProperty);
- }
-}
-
-void DirectShowPlayerControl::updateStatus(QMediaPlayer::MediaStatus status)
-{
- if (m_status != status) {
- m_status = status;
-
- scheduleUpdate(StatusProperty);
- }
-}
-
-void DirectShowPlayerControl::updateMediaInfo(qint64 duration, int streamTypes, bool seekable)
-{
- int properties = 0;
-
- if (m_duration != duration) {
- m_duration = duration;
-
- properties |= DurationProperty;
- }
- if (m_streamTypes != streamTypes) {
- m_streamTypes = streamTypes;
-
- properties |= StreamTypesProperty;
- }
-
- if (m_seekable != seekable) {
- m_seekable = seekable;
-
- properties |= SeekableProperty;
- }
-
- if (properties != 0)
- scheduleUpdate(properties);
-}
-
-void DirectShowPlayerControl::updatePlaybackRate(qreal rate)
-{
- if (!qFuzzyCompare(m_playbackRate, rate)) {
- m_playbackRate = rate;
-
- scheduleUpdate(PlaybackRateProperty);
- }
-}
-
-void DirectShowPlayerControl::updateAudioOutput(IBaseFilter *filter)
-{
- if (m_audio)
- m_audio->Release();
-
- m_audio = com_cast<IBasicAudio>(filter, IID_IBasicAudio);
- setVolumeHelper(m_muted ? 0 : m_volume);
-}
-
-void DirectShowPlayerControl::updateError(QMediaPlayer::Error error, const QString &errorString)
-{
- m_error = error;
- m_errorString = errorString;
-
- if (m_error != QMediaPlayer::NoError)
- scheduleUpdate(ErrorProperty);
-}
-
-void DirectShowPlayerControl::updatePosition(qint64 position)
-{
- if (m_emitPosition != position) {
- m_emitPosition = position;
-
- scheduleUpdate(PositionProperty);
- }
-}
diff --git a/src/plugins/directshow/player/directshowplayercontrol.h b/src/plugins/directshow/player/directshowplayercontrol.h
deleted file mode 100644
index 122f5be2f..000000000
--- a/src/plugins/directshow/player/directshowplayercontrol.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWPLAYERCONTROL_H
-#define DIRECTSHOWPLAYERCONTROL_H
-
-#include <dshow.h>
-
-#include "qmediacontent.h"
-#include "qmediaplayercontrol.h"
-
-#include <QtCore/qcoreevent.h>
-
-#include "directshowplayerservice.h"
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowPlayerControl : public QMediaPlayerControl
-{
- Q_OBJECT
-public:
- DirectShowPlayerControl(DirectShowPlayerService *service, QObject *parent = nullptr);
- ~DirectShowPlayerControl() override;
-
- QMediaPlayer::State state() const override;
-
- QMediaPlayer::MediaStatus mediaStatus() const override;
-
- qint64 duration() const override;
-
- qint64 position() const override;
- void setPosition(qint64 position) override;
-
- int volume() const override;
- void setVolume(int volume) override;
-
- bool isMuted() const override;
- void setMuted(bool muted) override;
-
- int bufferStatus() const override;
-
- bool isAudioAvailable() const override;
- bool isVideoAvailable() const override;
-
- bool isSeekable() const override;
-
- QMediaTimeRange availablePlaybackRanges() const override;
-
- qreal playbackRate() const override;
- void setPlaybackRate(qreal rate) override;
-
- QMediaContent media() const override;
- const QIODevice *mediaStream() const override;
- void setMedia(const QMediaContent &media, QIODevice *stream) override;
-
- void play() override;
- void pause() override;
- void stop() override;
-
- void updateState(QMediaPlayer::State state);
- void updateStatus(QMediaPlayer::MediaStatus status);
- void updateMediaInfo(qint64 duration, int streamTypes, bool seekable);
- void updatePlaybackRate(qreal rate);
- void updateAudioOutput(IBaseFilter *filter);
- void updateError(QMediaPlayer::Error error, const QString &errorString);
- void updatePosition(qint64 position);
-
-protected:
- void customEvent(QEvent *event) override;
-
-private:
- enum Properties
- {
- StateProperty = 0x01,
- StatusProperty = 0x02,
- StreamTypesProperty = 0x04,
- DurationProperty = 0x08,
- PlaybackRateProperty = 0x10,
- SeekableProperty = 0x20,
- ErrorProperty = 0x40,
- PositionProperty = 0x80
- };
-
- enum Event
- {
- PropertiesChanged = QEvent::User
- };
-
- void playOrPause(QMediaPlayer::State state);
-
- void scheduleUpdate(int properties);
- void emitPropertyChanges();
- void setVolumeHelper(int volume);
-
- DirectShowPlayerService *m_service;
- IBasicAudio *m_audio = nullptr;
- QIODevice *m_stream = nullptr;
- int m_updateProperties = 0;
- QMediaPlayer::State m_state = QMediaPlayer::StoppedState;
- QMediaPlayer::MediaStatus m_status = QMediaPlayer::NoMedia;
- QMediaPlayer::Error m_error = QMediaPlayer::NoError;
- int m_streamTypes = 0;
- int m_volume = 100;
- bool m_muted = false;
- qint64 m_emitPosition = -1;
- qint64 m_pendingPosition = -1;
- qint64 m_duration = 0;
- qreal m_playbackRate = 0;
- bool m_seekable = false;
- QMediaContent m_media;
- QString m_errorString;
-
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/player/directshowplayerservice.cpp b/src/plugins/directshow/player/directshowplayerservice.cpp
deleted file mode 100644
index ce5c9fe56..000000000
--- a/src/plugins/directshow/player/directshowplayerservice.cpp
+++ /dev/null
@@ -1,1812 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <dshow.h>
-#ifdef min
-#undef min
-#endif
-#ifdef max
-#undef max
-#endif
-
-#include "directshowplayerservice.h"
-
-#include "directshowaudioendpointcontrol.h"
-#include "directshowmetadatacontrol.h"
-#include "vmr9videowindowcontrol.h"
-#include "directshowiosource.h"
-#include "directshowplayercontrol.h"
-#include "directshowvideorenderercontrol.h"
-#include "directshowutils.h"
-#include "directshowglobal.h"
-#include "directshowaudioprobecontrol.h"
-#include "directshowvideoprobecontrol.h"
-#include "directshowsamplegrabber.h"
-
-#if QT_CONFIG(evr)
-#include "directshowevrvideowindowcontrol.h"
-#else
-#include <mmreg.h>
-#endif
-
-#include "qmediacontent.h"
-
-#include <QtMultimedia/private/qtmultimedia-config_p.h>
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qdatetime.h>
-#include <QtCore/qdir.h>
-#include <QtCore/qthread.h>
-#include <QtCore/qvarlengtharray.h>
-#include <QtCore/qsize.h>
-
-#include <QtMultimedia/qaudiobuffer.h>
-#include <QtMultimedia/qvideoframe.h>
-#include <QtMultimedia/private/qmemoryvideobuffer_p.h>
-
-#if QT_CONFIG(wmsdk)
-# include <wmsdk.h>
-#endif
-
-#ifndef Q_CC_MINGW
-# include <comdef.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-Q_GLOBAL_STATIC(DirectShowEventLoop, qt_directShowEventLoop)
-
-static QString comError(HRESULT hr)
-{
-#ifndef Q_CC_MINGW // MinGW 5.3 no longer has swprintf_s().
- _com_error error(hr);
- return QString::fromWCharArray(error.ErrorMessage());
-#else
- Q_UNUSED(hr);
- return QString();
-#endif
-}
-
-// QMediaPlayer uses millisecond time units, direct show uses 100 nanosecond units.
-static const int qt_directShowTimeScale = 10000;
-
-class DirectShowPlayerServiceThread : public QThread
-{
-public:
- DirectShowPlayerServiceThread(DirectShowPlayerService *service)
- : m_service(service)
- {
- }
-
-protected:
- void run() override { m_service->run(); }
-
-private:
- DirectShowPlayerService *m_service;
-};
-
-DirectShowPlayerService::DirectShowPlayerService(QObject *parent)
- : QMediaService(parent)
- , m_loop(qt_directShowEventLoop())
- , m_taskHandle(::CreateEvent(nullptr, FALSE, FALSE, nullptr))
-{
- m_playerControl = new DirectShowPlayerControl(this);
- m_metaDataControl = new DirectShowMetaDataControl(this);
- m_audioEndpointControl = new DirectShowAudioEndpointControl(this);
-
- m_taskThread = new DirectShowPlayerServiceThread(this);
- m_taskThread->start();
-}
-
-DirectShowPlayerService::~DirectShowPlayerService()
-{
- {
- QMutexLocker locker(&m_mutex);
-
- releaseGraph();
-
- m_pendingTasks = Shutdown;
- ::SetEvent(m_taskHandle);
- }
-
- m_taskThread->wait();
- delete m_taskThread;
-
- if (m_audioOutput) {
- m_audioOutput->Release();
- m_audioOutput = nullptr;
- }
-
- if (m_videoOutput) {
- m_videoOutput->Release();
- m_videoOutput = nullptr;
- }
-
- delete m_playerControl;
- delete m_audioEndpointControl;
- delete m_metaDataControl;
- delete m_videoRendererControl;
- delete m_videoWindowControl;
- delete m_audioProbeControl;
- delete m_videoProbeControl;
-
- ::CloseHandle(m_taskHandle);
-}
-
-QMediaControl *DirectShowPlayerService::requestControl(const char *name)
-{
- if (qstrcmp(name, QMediaPlayerControl_iid) == 0)
- return m_playerControl;
- if (qstrcmp(name, QAudioOutputSelectorControl_iid) == 0)
- return m_audioEndpointControl;
- if (qstrcmp(name, QMetaDataReaderControl_iid) == 0)
- return m_metaDataControl;
- if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
- if (!m_videoRendererControl && !m_videoWindowControl) {
- m_videoRendererControl = new DirectShowVideoRendererControl(m_loop);
-
- connect(m_videoRendererControl, &DirectShowVideoRendererControl::filterChanged,
- this, &DirectShowPlayerService::videoOutputChanged);
-
- return m_videoRendererControl;
- }
- return nullptr;
- }
- if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
- if (!m_videoRendererControl && !m_videoWindowControl) {
- IBaseFilter *filter{};
-
-#if QT_CONFIG(evr)
- if (!qgetenv("QT_DIRECTSHOW_NO_EVR").toInt()) {
- DirectShowEvrVideoWindowControl *evrControl = new DirectShowEvrVideoWindowControl;
- if ((filter = evrControl->filter()))
- m_videoWindowControl = evrControl;
- else
- delete evrControl;
- }
-#endif
- // Fall back to the VMR9 if the EVR is not available
- if (!m_videoWindowControl) {
- Vmr9VideoWindowControl *vmr9Control = new Vmr9VideoWindowControl;
- filter = vmr9Control->filter();
- m_videoWindowControl = vmr9Control;
- }
-
- setVideoOutput(filter);
-
- return m_videoWindowControl;
- }
- return nullptr;
- }
- if (qstrcmp(name, QMediaAudioProbeControl_iid) == 0) {
- if (!m_audioProbeControl)
- m_audioProbeControl = new DirectShowAudioProbeControl();
- m_audioProbeControl->ref();
- updateAudioProbe();
- return m_audioProbeControl;
- }
- if (qstrcmp(name, QMediaVideoProbeControl_iid) == 0) {
- if (!m_videoProbeControl)
- m_videoProbeControl = new DirectShowVideoProbeControl();
- m_videoProbeControl->ref();
- updateVideoProbe();
- return m_videoProbeControl;
- }
- return nullptr;
-}
-
-void DirectShowPlayerService::releaseControl(QMediaControl *control)
-{
- if (!control) {
- qWarning("QMediaService::releaseControl():"
- " Attempted release of null control");
- } else if (control == m_videoRendererControl) {
- setVideoOutput(nullptr);
-
- delete m_videoRendererControl;
-
- m_videoRendererControl = nullptr;
- } else if (control == m_videoWindowControl) {
- setVideoOutput(nullptr);
-
- delete m_videoWindowControl;
-
- m_videoWindowControl = nullptr;
- } else if (control == m_audioProbeControl) {
- if (!m_audioProbeControl->deref()) {
- DirectShowAudioProbeControl *old = m_audioProbeControl;
- m_audioProbeControl = nullptr;
- updateAudioProbe();
- delete old;
- }
- } else if (control == m_videoProbeControl) {
- if (!m_videoProbeControl->deref()) {
- DirectShowVideoProbeControl *old = m_videoProbeControl;
- m_videoProbeControl = nullptr;
- updateVideoProbe();
- delete old;
- }
- }
-}
-
-void DirectShowPlayerService::load(const QMediaContent &media, QIODevice *stream)
-{
- QMutexLocker locker(&m_mutex);
-
- m_pendingTasks = 0;
-
- if (m_graph)
- releaseGraph();
-
- m_url = media.request().url();
-
- m_stream = stream;
- m_error = QMediaPlayer::NoError;
- m_errorString = QString();
- m_position = 0;
- m_seekPosition = -1;
- m_duration = 0;
- m_streamTypes = 0;
- m_executedTasks = 0;
- m_buffering = false;
- m_seekable = false;
- m_atEnd = false;
- m_dontCacheNextSeekResult = false;
- m_metaDataControl->setMetadata(QVariantMap());
-
- if (m_url.isEmpty() && !stream) {
- m_pendingTasks = 0;
- m_graphStatus = NoMedia;
- } else if (stream && (!stream->isReadable() || stream->isSequential())) {
- m_pendingTasks = 0;
- m_graphStatus = InvalidMedia;
- m_error = QMediaPlayer::ResourceError;
- } else {
- // {36b73882-c2c8-11cf-8b46-00805f6cef60}
- static const GUID iid_IFilterGraph2 = {
- 0x36b73882, 0xc2c8, 0x11cf, {0x8b, 0x46, 0x00, 0x80, 0x5f, 0x6c, 0xef, 0x60} };
- m_graphStatus = Loading;
-
- DirectShowUtils::CoInitializeIfNeeded();
- m_graph = com_new<IFilterGraph2>(CLSID_FilterGraph, iid_IFilterGraph2);
- m_graphBuilder = com_new<ICaptureGraphBuilder2>(CLSID_CaptureGraphBuilder2, IID_ICaptureGraphBuilder2);
-
- // Attach the filter graph to the capture graph.
- HRESULT hr = m_graphBuilder->SetFiltergraph(m_graph);
- if (FAILED(hr)) {
- qCWarning(qtDirectShowPlugin, "[0x%x] Failed to attach filter to capture graph", hr);
- m_graphBuilder->Release();
- m_graphBuilder = nullptr;
- }
-
- if (stream)
- m_pendingTasks = SetStreamSource;
- else
- m_pendingTasks = SetUrlSource;
-
- ::SetEvent(m_taskHandle);
- }
-
- m_playerControl->updateError(m_error, m_errorString);
- m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable);
- m_playerControl->updateState(QMediaPlayer::StoppedState);
- m_playerControl->updatePosition(m_position);
- updateStatus();
-}
-
-void DirectShowPlayerService::doSetUrlSource(QMutexLocker *locker)
-{
- IBaseFilter *source = nullptr;
-
- HRESULT hr = E_FAIL;
- if (m_url.scheme() == QLatin1String("http") || m_url.scheme() == QLatin1String("https")) {
- static const GUID clsid_WMAsfReader = {
- 0x187463a0, 0x5bb7, 0x11d3, {0xac, 0xbe, 0x00, 0x80, 0xc7, 0x5e, 0x24, 0x6e} };
-
- // {56a868a6-0ad4-11ce-b03a-0020af0ba770}
- static const GUID iid_IFileSourceFilter = {
- 0x56a868a6, 0x0ad4, 0x11ce, {0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70} };
-
- if (IFileSourceFilter *fileSource = com_new<IFileSourceFilter>(clsid_WMAsfReader, iid_IFileSourceFilter)) {
- locker->unlock();
- hr = fileSource->Load(reinterpret_cast<const OLECHAR *>(m_url.toString().utf16()), nullptr);
-
- if (SUCCEEDED(hr)) {
- source = com_cast<IBaseFilter>(fileSource, IID_IBaseFilter);
-
- if (!SUCCEEDED(hr = m_graph->AddFilter(source, L"Source")) && source) {
- source->Release();
- source = nullptr;
- }
- }
- fileSource->Release();
- locker->relock();
- }
- }
-
- if (!SUCCEEDED(hr)) {
- locker->unlock();
- const QString urlString = m_url.isLocalFile()
- ? QDir::toNativeSeparators(m_url.toLocalFile()) : m_url.toString();
- hr = m_graph->AddSourceFilter(
- reinterpret_cast<const OLECHAR *>(urlString.utf16()), L"Source", &source);
- locker->relock();
- }
-
- if (SUCCEEDED(hr)) {
- m_executedTasks = SetSource;
- m_pendingTasks |= Render;
-
- if (m_audioOutput)
- m_pendingTasks |= SetAudioOutput;
- if (m_videoOutput)
- m_pendingTasks |= SetVideoOutput;
- if (m_audioProbeControl)
- m_pendingTasks |= SetAudioProbe;
- if (m_videoProbeControl)
- m_pendingTasks |= SetVideoProbe;
-
- if (m_rate != 1.0)
- m_pendingTasks |= SetRate;
-
- m_source = source;
- } else {
- m_graphStatus = InvalidMedia;
-
- switch (hr) {
- case VFW_E_UNKNOWN_FILE_TYPE:
- m_error = QMediaPlayer::FormatError;
- m_errorString = QString();
- break;
- default:
- m_error = QMediaPlayer::ResourceError;
- m_errorString = QString();
- qWarning("DirectShowPlayerService::doSetUrlSource: Unresolved error code 0x%x (%s)",
- uint(hr), qPrintable(comError(hr)));
- break;
- }
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error)));
- }
-}
-
-void DirectShowPlayerService::doSetStreamSource(QMutexLocker *locker)
-{
- Q_UNUSED(locker);
- DirectShowIOSource *source = new DirectShowIOSource(m_loop);
- source->setDevice(m_stream);
-
- const HRESULT hr = m_graph->AddFilter(source, L"Source");
- if (SUCCEEDED(hr)) {
- m_executedTasks = SetSource;
- m_pendingTasks |= Render;
-
- if (m_audioOutput)
- m_pendingTasks |= SetAudioOutput;
- if (m_videoOutput)
- m_pendingTasks |= SetVideoOutput;
-
- if (m_rate != 1.0)
- m_pendingTasks |= SetRate;
-
- m_source = source;
- } else {
- source->Release();
-
- m_pendingTasks = 0;
- m_graphStatus = InvalidMedia;
-
- m_error = QMediaPlayer::ResourceError;
- m_errorString = QString();
- qWarning("DirectShowPlayerService::doPlay: Unresolved error code 0x%x (%s)",
- uint(hr), qPrintable(comError(hr)));
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error)));
- }
-}
-
-void DirectShowPlayerService::doRender(QMutexLocker *locker)
-{
- m_pendingTasks |= m_executedTasks & (Play | Pause);
-
- if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) {
- control->Stop();
- control->Release();
- }
-
- if (m_pendingTasks & SetAudioOutput) {
- m_graph->AddFilter(m_audioOutput, L"AudioOutput");
-
- m_pendingTasks ^= SetAudioOutput;
- m_executedTasks |= SetAudioOutput;
- }
- if (m_pendingTasks & SetVideoOutput) {
- m_graph->AddFilter(m_videoOutput, L"VideoOutput");
-
- m_pendingTasks ^= SetVideoOutput;
- m_executedTasks |= SetVideoOutput;
- }
-
- if (m_pendingTasks & SetAudioProbe) {
- doSetAudioProbe(locker);
- m_pendingTasks ^= SetAudioProbe;
- m_executedTasks |= SetAudioProbe;
- }
-
- if (m_pendingTasks & SetVideoProbe) {
- doSetVideoProbe(locker);
- m_pendingTasks ^= SetVideoProbe;
- m_executedTasks |= SetVideoProbe;
- }
-
- IFilterGraph2 *graph = m_graph;
- graph->AddRef();
-
- QVarLengthArray<IBaseFilter *, 16> filters;
- m_source->AddRef();
- filters.append(m_source);
-
- bool rendered = false;
-
- HRESULT renderHr = S_OK;
-
- while (!filters.isEmpty()) {
- IEnumPins *pins = nullptr;
- IBaseFilter *filter = filters[filters.size() - 1];
- filters.removeLast();
-
- if (!(m_pendingTasks & ReleaseFilters) && SUCCEEDED(filter->EnumPins(&pins))) {
- int outputs = 0;
- for (IPin *pin = nullptr; pins->Next(1, &pin, nullptr) == S_OK; pin->Release()) {
- PIN_DIRECTION direction;
- if (pin->QueryDirection(&direction) == S_OK && direction == PINDIR_OUTPUT) {
- ++outputs;
-
- IPin *peer = nullptr;
- if (pin->ConnectedTo(&peer) == S_OK) {
- PIN_INFO peerInfo;
- if (SUCCEEDED(peer->QueryPinInfo(&peerInfo)))
- filters.append(peerInfo.pFilter);
- peer->Release();
- } else {
- locker->unlock();
- HRESULT hr = graph->RenderEx(pin, /*AM_RENDEREX_RENDERTOEXISTINGRENDERERS*/ 1, nullptr);
- if (SUCCEEDED(hr)) {
- rendered = true;
- m_error = QMediaPlayer::NoError;
- } else if (!(m_executedTasks & SetVideoOutput)) {
- // Do not return an error if no video output is set yet.
- rendered = true;
- // Remember the error in this case.
- // Handle it when playing is requested and no video output has been provided.
- m_error = QMediaPlayer::ResourceError;
- m_errorString = QString("%1: %2").arg(__FUNCTION__).arg(qt_error_string(hr));
- } else if (renderHr == S_OK || renderHr == VFW_E_NO_DECOMPRESSOR){
- renderHr = hr;
- }
- locker->relock();
- }
- }
- }
-
- pins->Release();
-
- if (outputs == 0)
- rendered = true;
- }
- filter->Release();
- }
-
- if (m_audioOutput && !isConnected(m_audioOutput, PINDIR_INPUT)) {
- graph->RemoveFilter(m_audioOutput);
-
- m_executedTasks &= ~SetAudioOutput;
- }
-
- if (m_videoOutput && !isConnected(m_videoOutput, PINDIR_INPUT)) {
- graph->RemoveFilter(m_videoOutput);
-
- m_executedTasks &= ~SetVideoOutput;
- }
-
- graph->Release();
-
- if (!(m_pendingTasks & ReleaseFilters)) {
- if (rendered) {
- if (!(m_executedTasks & FinalizeLoad))
- m_pendingTasks |= FinalizeLoad;
- } else {
- m_pendingTasks = 0;
-
- m_graphStatus = InvalidMedia;
-
- if (!m_audioOutput && !m_videoOutput) {
- m_error = QMediaPlayer::ResourceError;
- m_errorString = QString();
- } else {
- switch (renderHr) {
- case VFW_E_UNSUPPORTED_AUDIO:
- case VFW_E_UNSUPPORTED_VIDEO:
- case VFW_E_UNSUPPORTED_STREAM:
- m_error = QMediaPlayer::FormatError;
- m_errorString = QString();
- break;
- default:
- m_error = QMediaPlayer::ResourceError;
- m_errorString = QString();
- qWarning("DirectShowPlayerService::doRender: Unresolved error code 0x%x (%s)",
- uint(renderHr), qPrintable(comError(renderHr)));
- }
- }
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error)));
- }
-
- m_executedTasks |= Render;
- }
-}
-
-void DirectShowPlayerService::doFinalizeLoad(QMutexLocker *locker)
-{
- if (m_graphStatus != Loaded) {
- if (IMediaEvent *event = com_cast<IMediaEvent>(m_graph, IID_IMediaEvent)) {
- event->GetEventHandle(reinterpret_cast<OAEVENT *>(&m_eventHandle));
- event->Release();
- }
- if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) {
- LONGLONG duration = 0;
- seeking->GetDuration(&duration);
- m_duration = duration / qt_directShowTimeScale;
-
- DWORD capabilities = 0;
- seeking->GetCapabilities(&capabilities);
- m_seekable = capabilities & AM_SEEKING_CanSeekAbsolute;
-
- seeking->Release();
- }
- }
-
- if ((m_executedTasks & SetOutputs) == SetOutputs) {
- m_streamTypes = AudioStream | VideoStream;
- } else {
- m_streamTypes = findStreamTypes(m_source);
- }
-
- m_executedTasks |= FinalizeLoad;
-
- m_graphStatus = Loaded;
-
- // Do not block gui thread while updating metadata from file.
- locker->unlock();
- DirectShowMetaDataControl::updateMetadata(m_url.toString(), m_metadata);
- locker->relock();
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(FinalizedLoad)));
-}
-
-void DirectShowPlayerService::releaseGraph()
-{
- if (m_videoProbeControl)
- m_videoProbeControl->flushVideoFrame();
-
- if (m_graph) {
- if (m_executingTask != 0) {
- // {8E1C39A1-DE53-11cf-AA63-0080C744528D}
- static const GUID iid_IAMOpenProgress = {
- 0x8E1C39A1, 0xDE53, 0x11cf, {0xAA, 0x63, 0x00, 0x80, 0xC7, 0x44, 0x52, 0x8D} };
-
- if (IAMOpenProgress *progress = com_cast<IAMOpenProgress>(
- m_graph, iid_IAMOpenProgress)) {
- progress->AbortOperation();
- progress->Release();
- }
- m_graph->Abort();
- }
-
- m_pendingTasks = ReleaseGraph;
-
- ::SetEvent(m_taskHandle);
-
- m_loop->wait(&m_mutex);
- DirectShowUtils::CoUninitializeIfNeeded();
- }
-}
-
-void DirectShowPlayerService::doReleaseGraph(QMutexLocker *locker)
-{
- Q_UNUSED(locker);
-
- if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) {
- control->Stop();
- control->Release();
- }
-
- doReleaseAudioProbe(locker);
- doReleaseVideoProbe(locker);
-
- if (m_source) {
- m_source->Release();
- m_source = nullptr;
- }
-
- m_eventHandle = nullptr;
-
- m_graph->Release();
- m_graph = nullptr;
-
- if (m_graphBuilder) {
- m_graphBuilder->Release();
- m_graphBuilder = nullptr;
- }
-
- m_loop->wake();
-}
-
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_GCC("-Wmissing-field-initializers")
-
-void DirectShowPlayerService::doSetVideoProbe(QMutexLocker *locker)
-{
- Q_UNUSED(locker);
-
- if (!m_graph || !m_graphBuilder) {
- qCWarning(qtDirectShowPlugin, "Attempting to set a video probe without a valid graph!");
- return;
- }
-
- // Create the sample grabber, if necessary.
- if (!m_videoSampleGrabber) {
- m_videoSampleGrabber = new DirectShowSampleGrabber;
- connect(m_videoSampleGrabber, &DirectShowSampleGrabber::bufferAvailable, this, &DirectShowPlayerService::onVideoBufferAvailable);
- }
-
- if (FAILED(m_graph->AddFilter(m_videoSampleGrabber->filter(), L"Video Sample Grabber"))) {
- qCWarning(qtDirectShowPlugin, "Failed to add the video sample grabber into the graph!");
- return;
- }
-
- DirectShowMediaType mediaType({ MEDIATYPE_Video, MEDIASUBTYPE_ARGB32 });
- m_videoSampleGrabber->setMediaType(&mediaType);
-
- // Connect source filter to sample grabber filter.
- HRESULT hr = m_graphBuilder->RenderStream(nullptr, &MEDIATYPE_Video,
- m_source, nullptr, m_videoSampleGrabber->filter());
- if (FAILED(hr)) {
- qCWarning(qtDirectShowPlugin, "[0x%x] Failed to connect the video sample grabber", hr);
- return;
- }
-
- m_videoSampleGrabber->start(DirectShowSampleGrabber::CallbackMethod::BufferCB);
-}
-
-void DirectShowPlayerService::doSetAudioProbe(QMutexLocker *locker)
-{
- Q_UNUSED(locker);
-
- if (!m_graph) {
- qCWarning(qtDirectShowPlugin, "Attempting to set an audio probe without a valid graph!");
- return;
- }
-
- // Create the sample grabber, if necessary.
- if (!m_audioSampleGrabber) {
- m_audioSampleGrabber = new DirectShowSampleGrabber;
- connect(m_audioSampleGrabber, &DirectShowSampleGrabber::bufferAvailable, this, &DirectShowPlayerService::onAudioBufferAvailable);
- }
-
- static const AM_MEDIA_TYPE mediaType { MEDIATYPE_Audio, MEDIASUBTYPE_PCM };
- m_audioSampleGrabber->setMediaType(&mediaType);
-
- if (FAILED(m_graph->AddFilter(m_audioSampleGrabber->filter(), L"Audio Sample Grabber"))) {
- qCWarning(qtDirectShowPlugin, "Failed to add the audio sample grabber into the graph!");
- return;
- }
-
- if (!DirectShowUtils::connectFilters(m_graph, m_source, m_audioSampleGrabber->filter(), true)) {
- // Connect source filter to sample grabber filter.
- HRESULT hr = m_graphBuilder
- ? m_graphBuilder->RenderStream(nullptr, &MEDIATYPE_Audio,
- m_source, nullptr, m_audioSampleGrabber->filter())
- : E_FAIL;
- if (FAILED(hr)) {
- qCWarning(qtDirectShowPlugin, "[0x%x] Failed to connect the audio sample grabber", hr);
- return;
- }
- }
-
- m_audioSampleGrabber->start(DirectShowSampleGrabber::CallbackMethod::BufferCB);
-}
-
-QT_WARNING_POP
-
-void DirectShowPlayerService::doReleaseVideoProbe(QMutexLocker *locker)
-{
- Q_UNUSED(locker);
-
- if (!m_graph)
- return;
-
- if (!m_videoSampleGrabber)
- return;
-
- m_videoSampleGrabber->stop();
- HRESULT hr = m_graph->RemoveFilter(m_videoSampleGrabber->filter());
- if (FAILED(hr)) {
- qCWarning(qtDirectShowPlugin, "Failed to remove the video sample grabber!");
- return;
- }
-
- m_videoSampleGrabber->deleteLater();
- m_videoSampleGrabber = nullptr;
-}
-
-void DirectShowPlayerService::doReleaseAudioProbe(QMutexLocker *locker)
-{
- Q_UNUSED(locker);
-
- if (!m_graph)
- return;
-
- if (!m_audioSampleGrabber)
- return;
-
- m_audioSampleGrabber->stop();
- HRESULT hr = m_graph->RemoveFilter(m_audioSampleGrabber->filter());
- if (FAILED(hr)) {
- qCWarning(qtDirectShowPlugin, "Failed to remove the audio sample grabber!");
- return;
- }
-
- m_audioSampleGrabber->deleteLater();
- m_audioSampleGrabber = nullptr;
-}
-
-int DirectShowPlayerService::findStreamTypes(IBaseFilter *source) const
-{
- QVarLengthArray<IBaseFilter *, 16> filters;
- source->AddRef();
- filters.append(source);
-
- int streamTypes = 0;
-
- while (!filters.isEmpty()) {
- IEnumPins *pins = nullptr;
- IBaseFilter *filter = filters[filters.size() - 1];
- filters.removeLast();
-
- if (SUCCEEDED(filter->EnumPins(&pins))) {
- for (IPin *pin = nullptr; pins->Next(1, &pin, nullptr) == S_OK; pin->Release()) {
- PIN_DIRECTION direction;
- if (pin->QueryDirection(&direction) == S_OK && direction == PINDIR_OUTPUT) {
- DirectShowMediaType connectionType;
- if (SUCCEEDED(pin->ConnectionMediaType(&connectionType))) {
- IPin *peer = nullptr;
-
- if (connectionType->majortype == MEDIATYPE_Audio) {
- streamTypes |= AudioStream;
- } else if (connectionType->majortype == MEDIATYPE_Video) {
- streamTypes |= VideoStream;
- } else if (SUCCEEDED(pin->ConnectedTo(&peer))) {
- PIN_INFO peerInfo;
- if (SUCCEEDED(peer->QueryPinInfo(&peerInfo)))
- filters.append(peerInfo.pFilter);
- peer->Release();
- }
- } else {
- streamTypes |= findStreamType(pin);
- }
- }
- }
- pins->Release();
- }
- filter->Release();
- }
- return streamTypes;
-}
-
-int DirectShowPlayerService::findStreamType(IPin *pin) const
-{
- IEnumMediaTypes *types;
-
- if (SUCCEEDED(pin->EnumMediaTypes(&types))) {
- bool video = false;
- bool audio = false;
- bool other = false;
-
- for (AM_MEDIA_TYPE *type = nullptr;
- types->Next(1, &type, nullptr) == S_OK;
- DirectShowMediaType::deleteType(type)) {
- if (type->majortype == MEDIATYPE_Audio)
- audio = true;
- else if (type->majortype == MEDIATYPE_Video)
- video = true;
- else
- other = true;
- }
- types->Release();
-
- if (other)
- return 0;
- else if (audio && !video)
- return AudioStream;
- else if (!audio && video)
- return VideoStream;
- else
- return 0;
- } else {
- return 0;
- }
-}
-
-void DirectShowPlayerService::play()
-{
- QMutexLocker locker(&m_mutex);
-
- m_pendingTasks &= ~Pause;
- m_pendingTasks |= Play;
-
- if (m_executedTasks & Render) {
- if (m_executedTasks & Stop) {
- m_atEnd = false;
- if (m_seekPosition == -1) {
- m_dontCacheNextSeekResult = true;
- m_seekPosition = 0;
- m_position = 0;
- m_pendingTasks |= Seek;
- }
- m_executedTasks ^= Stop;
- }
-
- ::SetEvent(m_taskHandle);
- }
-
- updateStatus();
-}
-
-void DirectShowPlayerService::doPlay(QMutexLocker *locker)
-{
- // Invalidate if there is an error while loading.
- if (m_error != QMediaPlayer::NoError) {
- m_graphStatus = InvalidMedia;
- if (!m_errorString.isEmpty())
- qWarning("%s", qPrintable(m_errorString));
- m_errorString = QString();
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error)));
- return;
- }
-
- if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) {
- locker->unlock();
- HRESULT hr = control->Run();
- locker->relock();
-
- control->Release();
-
- if (SUCCEEDED(hr)) {
- m_executedTasks |= Play;
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StatusChange)));
- } else {
- m_error = QMediaPlayer::ResourceError;
- m_errorString = QString();
- qWarning("DirectShowPlayerService::doPlay: Unresolved error code 0x%x (%s)",
- uint(hr), qPrintable(comError(hr)));
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error)));
- }
- }
-}
-
-void DirectShowPlayerService::pause()
-{
- QMutexLocker locker(&m_mutex);
-
- m_pendingTasks &= ~Play;
- m_pendingTasks |= Pause;
-
- if (m_executedTasks & Render) {
- if (m_executedTasks & Stop) {
- if (m_seekPosition == -1) {
- m_dontCacheNextSeekResult = true;
- m_seekPosition = 0;
- m_position = 0;
- m_pendingTasks |= Seek;
- }
- m_executedTasks ^= Stop;
- }
-
- ::SetEvent(m_taskHandle);
- }
-
- updateStatus();
-}
-
-void DirectShowPlayerService::doPause(QMutexLocker *locker)
-{
- if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) {
- locker->unlock();
- HRESULT hr = control->Pause();
- locker->relock();
-
- control->Release();
-
- if (SUCCEEDED(hr)) {
- IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking);
- if (!m_atEnd && seeking) {
- LONGLONG position = 0;
-
- seeking->GetCurrentPosition(&position);
- seeking->Release();
-
- m_position = position / qt_directShowTimeScale;
- } else {
- m_position = 0;
- m_atEnd = false;
- }
-
- m_executedTasks |= Pause;
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StatusChange)));
- } else {
- m_error = QMediaPlayer::ResourceError;
- m_errorString = QString();
- qWarning("DirectShowPlayerService::doPause: Unresolved error code 0x%x (%s)",
- uint(hr), qPrintable(comError(hr)));
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error)));
- }
- }
-}
-
-void DirectShowPlayerService::stop()
-{
- QMutexLocker locker(&m_mutex);
-
- m_pendingTasks &= ~(Play | Pause | Seek);
-
- if ((m_executingTask | m_executedTasks) & (Play | Pause | Seek)) {
- m_pendingTasks |= Stop;
- if (m_videoProbeControl)
- m_videoProbeControl->flushVideoFrame();
-
- ::SetEvent(m_taskHandle);
-
- m_loop->wait(&m_mutex);
- }
-
- updateStatus();
-}
-
-void DirectShowPlayerService::doStop(QMutexLocker *locker)
-{
- Q_UNUSED(locker);
- if (m_executedTasks & (Play | Pause)) {
- if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) {
- control->Stop();
- control->Release();
- }
-
- m_seekPosition = 0;
- m_position = 0;
- m_dontCacheNextSeekResult = true;
- m_pendingTasks |= Seek;
-
- m_executedTasks &= ~(Play | Pause);
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StatusChange)));
- }
-
- m_executedTasks |= Stop;
-
- m_loop->wake();
-}
-
-void DirectShowPlayerService::setRate(qreal rate)
-{
- QMutexLocker locker(&m_mutex);
-
- m_rate = rate;
-
- m_pendingTasks |= SetRate;
-
- if (m_executedTasks & FinalizeLoad)
- ::SetEvent(m_taskHandle);
-}
-
-void DirectShowPlayerService::doSetRate(QMutexLocker *locker)
-{
- if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) {
- // Cache current values as we can't query IMediaSeeking during a seek due to the
- // possibility of a deadlock when flushing the VideoSurfaceFilter.
- LONGLONG currentPosition = 0;
- seeking->GetCurrentPosition(&currentPosition);
- m_position = currentPosition / qt_directShowTimeScale;
-
- LONGLONG minimum = 0;
- LONGLONG maximum = 0;
- m_playbackRange = SUCCEEDED(seeking->GetAvailable(&minimum, &maximum))
- ? QMediaTimeRange(minimum / qt_directShowTimeScale, maximum / qt_directShowTimeScale)
- : QMediaTimeRange();
-
- locker->unlock();
- HRESULT hr = seeking->SetRate(m_rate);
- locker->relock();
-
- if (!SUCCEEDED(hr)) {
- qWarning("%s: Audio device or filter does not support rate: %.2f. " \
- "Falling back to previous value.", __FUNCTION__, m_rate);
-
- double rate = 0.0;
- m_rate = SUCCEEDED(seeking->GetRate(&rate))
- ? rate
- : 1.0;
- }
-
- seeking->Release();
- } else if (m_rate != 1.0) {
- m_rate = 1.0;
- }
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(RateChange)));
-}
-
-qint64 DirectShowPlayerService::position() const
-{
- QMutexLocker locker(const_cast<QMutex *>(&m_mutex));
-
- if (m_graphStatus == Loaded) {
- if (m_executingTask == Seek || m_executingTask == SetRate || (m_pendingTasks & Seek))
- return m_position;
- if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) {
- LONGLONG position = 0;
-
- seeking->GetCurrentPosition(&position);
- seeking->Release();
-
- const_cast<qint64 &>(m_position) = position / qt_directShowTimeScale;
-
- return m_position;
- }
- }
- return 0;
-}
-
-QMediaTimeRange DirectShowPlayerService::availablePlaybackRanges() const
-{
- QMutexLocker locker(const_cast<QMutex *>(&m_mutex));
-
- if (m_graphStatus == Loaded) {
- if (m_executingTask == Seek || m_executingTask == SetRate || (m_pendingTasks & Seek))
- return m_playbackRange;
- if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) {
- LONGLONG minimum = 0;
- LONGLONG maximum = 0;
-
- HRESULT hr = seeking->GetAvailable(&minimum, &maximum);
- seeking->Release();
-
- if (SUCCEEDED(hr))
- return QMediaTimeRange(minimum, maximum);
- }
- }
- return QMediaTimeRange();
-}
-
-void DirectShowPlayerService::seek(qint64 position)
-{
- QMutexLocker locker(&m_mutex);
-
- m_seekPosition = position;
-
- m_pendingTasks |= Seek;
-
- if (m_executedTasks & FinalizeLoad)
- ::SetEvent(m_taskHandle);
-}
-
-void DirectShowPlayerService::doSeek(QMutexLocker *locker)
-{
- if (m_seekPosition == -1)
- return;
-
- if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) {
- LONGLONG seekPosition = LONGLONG(m_seekPosition) * qt_directShowTimeScale;
-
- // Cache current values as we can't query IMediaSeeking during a seek due to the
- // possibility of a deadlock when flushing the VideoSurfaceFilter.
- LONGLONG currentPosition = 0;
- if (!m_dontCacheNextSeekResult) {
- seeking->GetCurrentPosition(&currentPosition);
- m_position = currentPosition / qt_directShowTimeScale;
- }
-
- LONGLONG minimum = 0;
- LONGLONG maximum = 0;
- m_playbackRange = SUCCEEDED(seeking->GetAvailable(&minimum, &maximum))
- ? QMediaTimeRange(
- minimum / qt_directShowTimeScale, maximum / qt_directShowTimeScale)
- : QMediaTimeRange();
-
- locker->unlock();
- seeking->SetPositions(
- &seekPosition, AM_SEEKING_AbsolutePositioning, nullptr, AM_SEEKING_NoPositioning);
- locker->relock();
-
- if (!m_dontCacheNextSeekResult) {
- seeking->GetCurrentPosition(&currentPosition);
- m_position = currentPosition / qt_directShowTimeScale;
- }
-
- seeking->Release();
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(PositionChange)));
- }
-
- m_seekPosition = -1;
- m_dontCacheNextSeekResult = false;
-}
-
-int DirectShowPlayerService::bufferStatus() const
-{
-#if QT_CONFIG(wmsdk)
- QMutexLocker locker(const_cast<QMutex *>(&m_mutex));
-
- if (IWMReaderAdvanced2 *reader = com_cast<IWMReaderAdvanced2>(
- m_source, IID_IWMReaderAdvanced2)) {
- DWORD percentage = 0;
-
- reader->GetBufferProgress(&percentage, nullptr);
- reader->Release();
-
- return percentage;
- }
- return 0;
-#else
- return 0;
-#endif
-}
-
-void DirectShowPlayerService::setAudioOutput(IBaseFilter *filter)
-{
- QMutexLocker locker(&m_mutex);
-
- if (m_graph) {
- if (m_audioOutput) {
- if (m_executedTasks & SetAudioOutput) {
- m_pendingTasks |= ReleaseAudioOutput;
-
- ::SetEvent(m_taskHandle);
-
- m_loop->wait(&m_mutex);
- }
- m_audioOutput->Release();
- }
-
- m_audioOutput = filter;
-
- if (m_audioOutput) {
- m_audioOutput->AddRef();
-
- m_pendingTasks |= SetAudioOutput;
-
- if (m_executedTasks & SetSource) {
- m_pendingTasks |= Render;
-
- ::SetEvent(m_taskHandle);
- }
- } else {
- m_pendingTasks &= ~ SetAudioOutput;
- }
- } else {
- if (m_audioOutput)
- m_audioOutput->Release();
-
- m_audioOutput = filter;
-
- if (m_audioOutput)
- m_audioOutput->AddRef();
- }
-
- m_playerControl->updateAudioOutput(m_audioOutput);
-}
-
-void DirectShowPlayerService::doReleaseAudioOutput(QMutexLocker *locker)
-{
- Q_UNUSED(locker);
- m_pendingTasks |= m_executedTasks & (Play | Pause);
-
- if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) {
- control->Stop();
- control->Release();
- }
-
- IBaseFilter *decoder = getConnected(m_audioOutput, PINDIR_INPUT);
- if (!decoder) {
- decoder = m_audioOutput;
- decoder->AddRef();
- }
-
- // {DCFBDCF6-0DC2-45f5-9AB2-7C330EA09C29}
- static const GUID iid_IFilterChain = {
- 0xDCFBDCF6, 0x0DC2, 0x45f5, {0x9A, 0xB2, 0x7C, 0x33, 0x0E, 0xA0, 0x9C, 0x29} };
-
- if (IFilterChain *chain = com_cast<IFilterChain>(m_graph, iid_IFilterChain)) {
- chain->RemoveChain(decoder, m_audioOutput);
- chain->Release();
- } else {
- m_graph->RemoveFilter(m_audioOutput);
- }
-
- decoder->Release();
-
- m_executedTasks &= ~SetAudioOutput;
-
- m_loop->wake();
-}
-
-void DirectShowPlayerService::setVideoOutput(IBaseFilter *filter)
-{
- QMutexLocker locker(&m_mutex);
-
- if (m_graph) {
- if (m_videoOutput) {
- if (m_executedTasks & SetVideoOutput) {
- m_pendingTasks |= ReleaseVideoOutput;
-
- ::SetEvent(m_taskHandle);
-
- m_loop->wait(&m_mutex);
- }
- m_videoOutput->Release();
- }
-
- m_videoOutput = filter;
-
- if (m_videoOutput) {
- m_videoOutput->AddRef();
-
- m_pendingTasks |= SetVideoOutput;
-
- if (m_executedTasks & SetSource) {
- m_pendingTasks |= Render;
-
- ::SetEvent(m_taskHandle);
- }
- }
- } else {
- if (m_videoOutput)
- m_videoOutput->Release();
-
- m_videoOutput = filter;
-
- if (m_videoOutput)
- m_videoOutput->AddRef();
- }
-}
-
-void DirectShowPlayerService::updateAudioProbe()
-{
- QMutexLocker locker(&m_mutex);
-
- // Set/Activate the audio probe.
- if (m_graph) {
- // If we don't have a audio probe, then stop and release the audio sample grabber
- if (!m_audioProbeControl && (m_executedTasks & SetAudioProbe)) {
- m_pendingTasks |= ReleaseAudioProbe;
- ::SetEvent(m_taskHandle);
- m_loop->wait(&m_mutex);
- } else if (m_audioProbeControl) {
- m_pendingTasks |= SetAudioProbe;
- }
- }
-}
-
-void DirectShowPlayerService::updateVideoProbe()
-{
- QMutexLocker locker(&m_mutex);
-
- // Set/Activate the video probe.
- if (m_graph) {
- // If we don't have a video probe, then stop and release the video sample grabber
- if (!m_videoProbeControl && (m_executedTasks & SetVideoProbe)) {
- m_pendingTasks |= ReleaseVideoProbe;
- ::SetEvent(m_taskHandle);
- m_loop->wait(&m_mutex);
- } else if (m_videoProbeControl){
- m_pendingTasks |= SetVideoProbe;
- }
- }
-}
-
-void DirectShowPlayerService::doReleaseVideoOutput(QMutexLocker *locker)
-{
- Q_UNUSED(locker);
- m_pendingTasks |= m_executedTasks & (Play | Pause);
-
- if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) {
- control->Stop();
- control->Release();
- }
-
- IBaseFilter *intermediate = nullptr;
- if (!SUCCEEDED(m_graph->FindFilterByName(L"Color Space Converter", &intermediate))) {
- intermediate = m_videoOutput;
- intermediate->AddRef();
- }
-
- IBaseFilter *decoder = getConnected(intermediate, PINDIR_INPUT);
- if (!decoder) {
- decoder = intermediate;
- decoder->AddRef();
- }
-
- // {DCFBDCF6-0DC2-45f5-9AB2-7C330EA09C29}
- static const GUID iid_IFilterChain = {
- 0xDCFBDCF6, 0x0DC2, 0x45f5, {0x9A, 0xB2, 0x7C, 0x33, 0x0E, 0xA0, 0x9C, 0x29} };
-
- if (IFilterChain *chain = com_cast<IFilterChain>(m_graph, iid_IFilterChain)) {
- chain->RemoveChain(decoder, m_videoOutput);
- chain->Release();
- } else {
- m_graph->RemoveFilter(m_videoOutput);
- }
-
- intermediate->Release();
- decoder->Release();
-
- m_executedTasks &= ~SetVideoOutput;
-
- m_loop->wake();
-}
-
-void DirectShowPlayerService::customEvent(QEvent *event)
-{
- if (event->type() == QEvent::Type(FinalizedLoad)) {
- QMutexLocker locker(&m_mutex);
-
- m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable);
- if (m_metadata.isEmpty())
- DirectShowMetaDataControl::updateMetadata(m_graph, m_source, m_metadata);
-
- m_metaDataControl->setMetadata(m_metadata);
- m_metadata.clear();
-
- updateStatus();
- } else if (event->type() == QEvent::Type(Error)) {
- QMutexLocker locker(&m_mutex);
-
- if (m_error != QMediaPlayer::NoError) {
- m_playerControl->updateError(m_error, m_errorString);
- m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable);
- m_playerControl->updateState(QMediaPlayer::StoppedState);
- updateStatus();
- }
- } else if (event->type() == QEvent::Type(RateChange)) {
- QMutexLocker locker(&m_mutex);
-
- m_playerControl->updatePlaybackRate(m_rate);
- } else if (event->type() == QEvent::Type(StatusChange)) {
- QMutexLocker locker(&m_mutex);
-
- updateStatus();
- m_playerControl->updatePosition(m_position);
- } else if (event->type() == QEvent::Type(DurationChange)) {
- QMutexLocker locker(&m_mutex);
-
- m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable);
- } else if (event->type() == QEvent::Type(EndOfMedia)) {
- QMutexLocker locker(&m_mutex);
-
- if (m_atEnd) {
- m_playerControl->updateState(QMediaPlayer::StoppedState);
- m_playerControl->updateStatus(QMediaPlayer::EndOfMedia);
- m_playerControl->updatePosition(m_position);
- if (m_videoProbeControl)
- m_videoProbeControl->flushVideoFrame();
- }
- } else if (event->type() == QEvent::Type(PositionChange)) {
- QMutexLocker locker(&m_mutex);
-
- if (m_playerControl->mediaStatus() == QMediaPlayer::EndOfMedia)
- m_playerControl->updateStatus(QMediaPlayer::LoadedMedia);
- m_playerControl->updatePosition(m_position);
- // Emits only when seek has been performed.
- if (m_videoRendererControl)
- emit m_videoRendererControl->positionChanged(m_position);
- } else {
- QMediaService::customEvent(event);
- }
-}
-
-void DirectShowPlayerService::videoOutputChanged()
-{
- setVideoOutput(m_videoRendererControl->filter());
-}
-
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_GCC("-Wmissing-field-initializers")
-
-void DirectShowPlayerService::onAudioBufferAvailable(double time, const QByteArray &data)
-{
- QMutexLocker locker(&m_mutex);
- if (!m_audioProbeControl || !m_audioSampleGrabber)
- return;
-
- DirectShowMediaType mt(AM_MEDIA_TYPE { GUID_NULL });
- const bool ok = m_audioSampleGrabber->getConnectedMediaType(&mt);
- if (!ok)
- return;
-
- if (mt->majortype != MEDIATYPE_Audio)
- return;
-
- if (mt->subtype != MEDIASUBTYPE_PCM)
- return;
-
- const bool isWfx = ((mt->formattype == FORMAT_WaveFormatEx) && (mt->cbFormat >= sizeof(WAVEFORMATEX)));
- WAVEFORMATEX *wfx = isWfx ? reinterpret_cast<WAVEFORMATEX *>(mt->pbFormat) : nullptr;
-
- if (!wfx)
- return;
-
- if (wfx->wFormatTag != WAVE_FORMAT_PCM && wfx->wFormatTag != WAVE_FORMAT_EXTENSIBLE)
- return;
-
- if ((wfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE) && (wfx->cbSize >= sizeof(WAVEFORMATEXTENSIBLE))) {
- WAVEFORMATEXTENSIBLE *wfxe = reinterpret_cast<WAVEFORMATEXTENSIBLE *>(wfx);
- if (wfxe->SubFormat != KSDATAFORMAT_SUBTYPE_PCM)
- return;
- }
-
- QAudioFormat format;
- format.setSampleRate(wfx->nSamplesPerSec);
- format.setChannelCount(wfx->nChannels);
- format.setSampleSize(wfx->wBitsPerSample);
- format.setCodec("audio/pcm");
- format.setByteOrder(QAudioFormat::LittleEndian);
- if (format.sampleSize() == 8)
- format.setSampleType(QAudioFormat::UnSignedInt);
- else
- format.setSampleType(QAudioFormat::SignedInt);
-
- const quint64 startTime = quint64(time * 1000.);
- QAudioBuffer audioBuffer(data,
- format,
- startTime);
-
- Q_EMIT m_audioProbeControl->audioBufferProbed(audioBuffer);
-}
-
-void DirectShowPlayerService::onVideoBufferAvailable(double time, const QByteArray &data)
-{
- Q_UNUSED(time);
-
- QMutexLocker locker(&m_mutex);
- if (!m_videoProbeControl || !m_videoSampleGrabber)
- return;
-
- DirectShowMediaType mt(AM_MEDIA_TYPE { GUID_NULL });
- const bool ok = m_videoSampleGrabber->getConnectedMediaType(&mt);
- if (!ok)
- return;
-
- if (mt->majortype != MEDIATYPE_Video)
- return;
-
- QVideoFrame::PixelFormat format = DirectShowMediaType::pixelFormatFromType(&mt);
- if (format == QVideoFrame::Format_Invalid) {
- qCWarning(qtDirectShowPlugin, "Invalid format, stopping video probes!");
- m_videoSampleGrabber->stop();
- return;
- }
-
- const QVideoSurfaceFormat &videoFormat = DirectShowMediaType::videoFormatFromType(&mt);
- if (!videoFormat.isValid())
- return;
-
- const QSize &size = videoFormat.frameSize();
-
- const int bytesPerLine = DirectShowMediaType::bytesPerLine(videoFormat);
- QVideoFrame frame(new QMemoryVideoBuffer(data, bytesPerLine),
- size,
- format);
-
- m_videoProbeControl->probeVideoFrame(frame);
-}
-
-QT_WARNING_POP
-
-void DirectShowPlayerService::graphEvent(QMutexLocker *locker)
-{
- Q_UNUSED(locker);
- if (IMediaEvent *event = com_cast<IMediaEvent>(m_graph, IID_IMediaEvent)) {
- long eventCode;
- LONG_PTR param1;
- LONG_PTR param2;
-
- while (event->GetEvent(&eventCode, &param1, &param2, 0) == S_OK) {
- switch (eventCode) {
- case EC_BUFFERING_DATA:
- m_buffering = param1;
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StatusChange)));
- break;
- case EC_COMPLETE:
- m_executedTasks &= ~(Play | Pause);
- m_executedTasks |= Stop;
-
- m_buffering = false;
- m_atEnd = true;
-
- if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) {
- LONGLONG position = 0;
-
- seeking->GetCurrentPosition(&position);
- seeking->Release();
-
- m_position = position / qt_directShowTimeScale;
- }
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(EndOfMedia)));
- break;
- case EC_LENGTH_CHANGED:
- if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) {
- LONGLONG duration = 0;
- seeking->GetDuration(&duration);
- m_duration = duration / qt_directShowTimeScale;
-
- DWORD capabilities = 0;
- seeking->GetCapabilities(&capabilities);
- m_seekable = capabilities & AM_SEEKING_CanSeekAbsolute;
-
- seeking->Release();
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::Type(DurationChange)));
- }
- break;
- default:
- break;
- }
-
- event->FreeEventParams(eventCode, param1, param2);
- }
- event->Release();
- }
-}
-
-void DirectShowPlayerService::updateStatus()
-{
- switch (m_graphStatus) {
- case NoMedia:
- m_playerControl->updateStatus(QMediaPlayer::NoMedia);
- break;
- case Loading:
- m_playerControl->updateStatus(QMediaPlayer::LoadingMedia);
- break;
- case Loaded:
- if ((m_executingTask | m_executedTasks) & (Play | Pause)) {
- if (m_buffering)
- m_playerControl->updateStatus(QMediaPlayer::BufferingMedia);
- else
- m_playerControl->updateStatus(QMediaPlayer::BufferedMedia);
- } else {
- m_playerControl->updateStatus(QMediaPlayer::LoadedMedia);
- }
- break;
- case InvalidMedia:
- m_playerControl->updateStatus(QMediaPlayer::InvalidMedia);
- break;
- default:
- m_playerControl->updateStatus(QMediaPlayer::UnknownMediaStatus);
- }
-}
-
-bool DirectShowPlayerService::isConnected(IBaseFilter *filter, PIN_DIRECTION direction) const
-{
- bool connected = false;
-
- IEnumPins *pins = nullptr;
-
- if (SUCCEEDED(filter->EnumPins(&pins))) {
- for (IPin *pin = nullptr; pins->Next(1, &pin, nullptr) == S_OK; pin->Release()) {
- PIN_DIRECTION dir;
- if (SUCCEEDED(pin->QueryDirection(&dir)) && dir == direction) {
- IPin *peer = nullptr;
- if (SUCCEEDED(pin->ConnectedTo(&peer))) {
- connected = true;
-
- peer->Release();
- }
- }
- }
- pins->Release();
- }
- return connected;
-}
-
-IBaseFilter *DirectShowPlayerService::getConnected(
- IBaseFilter *filter, PIN_DIRECTION direction) const
-{
- IBaseFilter *connected = nullptr;
-
- IEnumPins *pins = nullptr;
-
- if (SUCCEEDED(filter->EnumPins(&pins))) {
- for (IPin *pin = nullptr; pins->Next(1, &pin, nullptr) == S_OK; pin->Release()) {
- PIN_DIRECTION dir;
- if (SUCCEEDED(pin->QueryDirection(&dir)) && dir == direction) {
- IPin *peer = nullptr;
- if (SUCCEEDED(pin->ConnectedTo(&peer))) {
- PIN_INFO info;
-
- if (SUCCEEDED(peer->QueryPinInfo(&info))) {
- if (connected) {
- qWarning("DirectShowPlayerService::getConnected: "
- "Multiple connected filters");
- connected->Release();
- }
- connected = info.pFilter;
- }
- peer->Release();
- }
- }
- }
- pins->Release();
- }
- return connected;
-}
-
-void DirectShowPlayerService::run()
-{
- QMutexLocker locker(&m_mutex);
-
- for (;;) {
- while (m_pendingTasks == 0) {
- DWORD result = 0;
-
- locker.unlock();
- if (m_eventHandle) {
- HANDLE handles[] = { m_taskHandle, m_eventHandle };
-
- result = ::WaitForMultipleObjects(2, handles, false, INFINITE);
- } else {
- result = ::WaitForSingleObject(m_taskHandle, INFINITE);
- }
- locker.relock();
-
- if (result == WAIT_OBJECT_0 + 1) {
- graphEvent(&locker);
- }
- }
-
- if (m_pendingTasks & ReleaseGraph) {
- m_pendingTasks ^= ReleaseGraph;
- m_executingTask = ReleaseGraph;
-
- doReleaseGraph(&locker);
- //if the graph is released, we should not process other operations later
- if (m_pendingTasks & Shutdown) {
- m_pendingTasks = 0;
- return;
- }
- m_pendingTasks = 0;
- } else if (m_pendingTasks & Shutdown) {
- return;
- } else if (m_pendingTasks & ReleaseAudioOutput) {
- m_pendingTasks ^= ReleaseAudioOutput;
- m_executingTask = ReleaseAudioOutput;
-
- doReleaseAudioOutput(&locker);
- } else if (m_pendingTasks & ReleaseVideoOutput) {
- m_pendingTasks ^= ReleaseVideoOutput;
- m_executingTask = ReleaseVideoOutput;
-
- doReleaseVideoOutput(&locker);
- } else if (m_pendingTasks & ReleaseAudioProbe) {
- m_pendingTasks ^= ReleaseAudioProbe;
- m_executingTask = ReleaseAudioProbe;
-
- doReleaseAudioProbe(&locker);
- } else if (m_pendingTasks & ReleaseVideoProbe) {
- m_pendingTasks ^= ReleaseVideoProbe;
- m_executingTask = ReleaseVideoProbe;
-
- doReleaseVideoProbe(&locker);
- } else if (m_pendingTasks & SetUrlSource) {
- m_pendingTasks ^= SetUrlSource;
- m_executingTask = SetUrlSource;
-
- doSetUrlSource(&locker);
- } else if (m_pendingTasks & SetStreamSource) {
- m_pendingTasks ^= SetStreamSource;
- m_executingTask = SetStreamSource;
-
- doSetStreamSource(&locker);
- } else if (m_pendingTasks & SetAudioProbe) {
- m_pendingTasks ^= SetAudioProbe;
- m_executingTask = SetAudioProbe;
-
- doSetAudioProbe(&locker);
- } else if (m_pendingTasks & SetVideoProbe) {
- m_pendingTasks ^= SetVideoProbe;
- m_executingTask = SetVideoProbe;
-
- doSetVideoProbe(&locker);
- } else if (m_pendingTasks & Render) {
- m_pendingTasks ^= Render;
- m_executingTask = Render;
-
- doRender(&locker);
- } else if (!(m_executedTasks & Render)) {
- m_pendingTasks &= ~(FinalizeLoad | SetRate | Stop | Pause | Seek | Play);
- } else if (m_pendingTasks & FinalizeLoad) {
- m_pendingTasks ^= FinalizeLoad;
- m_executingTask = FinalizeLoad;
-
- doFinalizeLoad(&locker);
- } else if (m_pendingTasks & Stop) {
- m_pendingTasks ^= Stop;
- m_executingTask = Stop;
-
- doStop(&locker);
- } else if (m_pendingTasks & SetRate) {
- m_pendingTasks ^= SetRate;
- m_executingTask = SetRate;
-
- doSetRate(&locker);
- } else if (m_pendingTasks & Pause) {
- m_pendingTasks ^= Pause;
- m_executingTask = Pause;
-
- doPause(&locker);
- } else if (m_pendingTasks & Seek) {
- m_pendingTasks ^= Seek;
- m_executingTask = Seek;
-
- doSeek(&locker);
- } else if (m_pendingTasks & Play) {
- m_pendingTasks ^= Play;
- m_executingTask = Play;
-
- doPlay(&locker);
- }
- m_executingTask = 0;
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/player/directshowplayerservice.h b/src/plugins/directshow/player/directshowplayerservice.h
deleted file mode 100644
index e0b011f4a..000000000
--- a/src/plugins/directshow/player/directshowplayerservice.h
+++ /dev/null
@@ -1,240 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWPLAYERSERVICE_H
-#define DIRECTSHOWPLAYERSERVICE_H
-
-#include <dshow.h>
-
-#include "qmediaplayer.h"
-#include "qmediaservice.h"
-#include "qmediatimerange.h"
-
-#include "directshoweventloop.h"
-#include "directshowglobal.h"
-
-#include <QtCore/qcoreevent.h>
-#include <QtCore/qmutex.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qwaitcondition.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowAudioEndpointControl;
-class DirectShowMetaDataControl;
-class DirectShowPlayerControl;
-class DirectShowVideoRendererControl;
-class DirectShowAudioProbeControl;
-class DirectShowVideoProbeControl;
-class DirectShowSampleGrabber;
-
-class QMediaContent;
-class QVideoWindowControl;
-
-class DirectShowPlayerService : public QMediaService
-{
- Q_OBJECT
-public:
- enum StreamType
- {
- AudioStream = 0x01,
- VideoStream = 0x02
- };
-
- DirectShowPlayerService(QObject *parent = nullptr);
- ~DirectShowPlayerService() override;
-
- QMediaControl *requestControl(const char *name) override;
- void releaseControl(QMediaControl *control) override;
-
- void load(const QMediaContent &media, QIODevice *stream);
- void play();
- void pause();
- void stop();
-
- qint64 position() const;
- QMediaTimeRange availablePlaybackRanges() const;
-
- void seek(qint64 position);
- void setRate(qreal rate);
-
- int bufferStatus() const;
-
- void setAudioOutput(IBaseFilter *filter);
- void setVideoOutput(IBaseFilter *filter);
-
-protected:
- void customEvent(QEvent *event) override;
-
-private Q_SLOTS:
- void videoOutputChanged();
-
- void onAudioBufferAvailable(double time, const QByteArray &data);
- void onVideoBufferAvailable(double time, const QByteArray &data);
-
-private:
- void releaseGraph();
- void updateStatus();
-
- void updateAudioProbe();
- void updateVideoProbe();
-
- int findStreamTypes(IBaseFilter *source) const;
- int findStreamType(IPin *pin) const;
-
- bool isConnected(IBaseFilter *filter, PIN_DIRECTION direction) const;
- IBaseFilter *getConnected(IBaseFilter *filter, PIN_DIRECTION direction) const;
-
- void run();
-
- void doSetUrlSource(QMutexLocker *locker);
- void doSetStreamSource(QMutexLocker *locker);
- void doRender(QMutexLocker *locker);
- void doFinalizeLoad(QMutexLocker *locker);
- void doSetRate(QMutexLocker *locker);
- void doSeek(QMutexLocker *locker);
- void doPlay(QMutexLocker *locker);
- void doPause(QMutexLocker *locker);
- void doStop(QMutexLocker *locker);
- void doReleaseAudioOutput(QMutexLocker *locker);
- void doReleaseVideoOutput(QMutexLocker *locker);
- void doReleaseGraph(QMutexLocker *locker);
- void doSetVideoProbe(QMutexLocker *locker);
- void doSetAudioProbe(QMutexLocker *locker);
- void doReleaseVideoProbe(QMutexLocker *locker);
- void doReleaseAudioProbe(QMutexLocker *locker);
-
- void graphEvent(QMutexLocker *locker);
-
- enum Task
- {
- Shutdown = 0x00001,
- SetUrlSource = 0x00002,
- SetStreamSource = 0x00004,
- SetSource = SetUrlSource | SetStreamSource,
- SetAudioOutput = 0x00008,
- SetVideoOutput = 0x00010,
- SetOutputs = SetAudioOutput | SetVideoOutput,
- SetAudioProbe = 0x00020,
- SetVideoProbe = 0x00040,
- SetProbes = SetAudioProbe | SetVideoProbe,
- Render = 0x00080,
- FinalizeLoad = 0x00100,
- SetRate = 0x00200,
- Seek = 0x00400,
- Play = 0x00800,
- Pause = 0x01000,
- Stop = 0x02000,
- ReleaseGraph = 0x04000,
- ReleaseAudioOutput = 0x08000,
- ReleaseVideoOutput = 0x10000,
- ReleaseAudioProbe = 0x20000,
- ReleaseVideoProbe = 0x40000,
- ReleaseFilters = ReleaseGraph | ReleaseAudioOutput
- | ReleaseVideoOutput | ReleaseAudioProbe
- | ReleaseVideoProbe
- };
-
- enum Event
- {
- FinalizedLoad = QEvent::User,
- Error,
- RateChange,
- Started,
- Paused,
- DurationChange,
- StatusChange,
- EndOfMedia,
- PositionChange
- };
-
- enum GraphStatus
- {
- NoMedia,
- Loading,
- Loaded,
- InvalidMedia
- };
-
- DirectShowPlayerControl *m_playerControl = nullptr;
- DirectShowMetaDataControl *m_metaDataControl = nullptr;
- DirectShowVideoRendererControl *m_videoRendererControl = nullptr;
- QVideoWindowControl *m_videoWindowControl = nullptr;
- DirectShowAudioEndpointControl *m_audioEndpointControl = nullptr;
- DirectShowAudioProbeControl *m_audioProbeControl = nullptr;
- DirectShowVideoProbeControl *m_videoProbeControl = nullptr;
- DirectShowSampleGrabber *m_audioSampleGrabber = nullptr;
- DirectShowSampleGrabber *m_videoSampleGrabber = nullptr;
-
- QThread *m_taskThread = nullptr;
- DirectShowEventLoop *m_loop;
- int m_pendingTasks = 0;
- int m_executingTask = 0;
- int m_executedTasks = 0;
- int m_streamTypes = 0;
- HANDLE m_taskHandle;
- HANDLE m_eventHandle = nullptr;
- GraphStatus m_graphStatus = NoMedia;
- QMediaPlayer::Error m_error = QMediaPlayer::NoError;
- QIODevice *m_stream = nullptr;
- IFilterGraph2 *m_graph = nullptr;
- ICaptureGraphBuilder2 *m_graphBuilder = nullptr;
- IBaseFilter *m_source = nullptr;
- IBaseFilter *m_audioOutput = nullptr;
- IBaseFilter *m_videoOutput = nullptr;
- qreal m_rate = 1;
- qint64 m_position = 0;
- qint64 m_seekPosition = -1;
- qint64 m_duration = 0;
- QMediaTimeRange m_playbackRange;
- QUrl m_url;
- QString m_errorString;
- QMutex m_mutex;
- bool m_buffering = false;
- bool m_seekable = false;
- bool m_atEnd = false;
- bool m_dontCacheNextSeekResult = false;
- QVariantMap m_metadata;
-
- friend class DirectShowPlayerServiceThread;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/player/directshowvideorenderercontrol.cpp b/src/plugins/directshow/player/directshowvideorenderercontrol.cpp
deleted file mode 100644
index 0b1f0de2f..000000000
--- a/src/plugins/directshow/player/directshowvideorenderercontrol.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "directshowvideorenderercontrol.h"
-
-#include "videosurfacefilter.h"
-
-#if QT_CONFIG(evr)
-#include "evrcustompresenter.h"
-#endif
-
-#include <qabstractvideosurface.h>
-
-DirectShowVideoRendererControl::DirectShowVideoRendererControl(DirectShowEventLoop *loop, QObject *parent)
- : QVideoRendererControl(parent)
- , m_loop(loop)
-{
-}
-
-DirectShowVideoRendererControl::~DirectShowVideoRendererControl()
-{
-#if QT_CONFIG(evr)
- if (m_evrPresenter) {
- m_evrPresenter->setSurface(nullptr);
- m_evrPresenter->Release();
- }
-#endif
- if (m_filter)
- m_filter->Release();
-}
-
-QAbstractVideoSurface *DirectShowVideoRendererControl::surface() const
-{
- return m_surface;
-}
-
-void DirectShowVideoRendererControl::setSurface(QAbstractVideoSurface *surface)
-{
- if (m_surface == surface)
- return;
-
-#if QT_CONFIG(evr)
- if (m_evrPresenter) {
- m_evrPresenter->setSurface(nullptr);
- m_evrPresenter->Release();
- m_evrPresenter = nullptr;
- }
-#endif
-
- if (m_filter) {
- m_filter->Release();
- m_filter = nullptr;
- }
-
- m_surface = surface;
-
- if (m_surface) {
-#if QT_CONFIG(evr)
- if (!qgetenv("QT_DIRECTSHOW_NO_EVR").toInt()) {
- m_filter = com_new<IBaseFilter>(clsid_EnhancedVideoRenderer);
- m_evrPresenter = new EVRCustomPresenter(m_surface);
- connect(this, &DirectShowVideoRendererControl::positionChanged, m_evrPresenter, &EVRCustomPresenter::positionChanged);
- if (!m_evrPresenter->isValid() || !qt_evr_setCustomPresenter(m_filter, m_evrPresenter)) {
- m_filter->Release();
- m_filter = nullptr;
- m_evrPresenter->Release();
- m_evrPresenter = nullptr;
- }
- }
-
- if (!m_filter)
-#endif
- {
- m_filter = new VideoSurfaceFilter(m_surface, m_loop);
- }
- }
-
- emit filterChanged();
-}
-
-IBaseFilter *DirectShowVideoRendererControl::filter()
-{
- return m_filter;
-}
diff --git a/src/plugins/directshow/player/directshowvideorenderercontrol.h b/src/plugins/directshow/player/directshowvideorenderercontrol.h
deleted file mode 100644
index 9326a2748..000000000
--- a/src/plugins/directshow/player/directshowvideorenderercontrol.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DIRECTSHOWVIDEORENDERERCONTROL_H
-#define DIRECTSHOWVIDEORENDERERCONTROL_H
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <dshow.h>
-
-#include "qvideorenderercontrol.h"
-
-#include <QtMultimedia/private/qtmultimedia-config_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class DirectShowEventLoop;
-#if QT_CONFIG(evr)
-class EVRCustomPresenter;
-#endif
-
-class DirectShowVideoRendererControl : public QVideoRendererControl
-{
- Q_OBJECT
-public:
- DirectShowVideoRendererControl(DirectShowEventLoop *loop, QObject *parent = nullptr);
- ~DirectShowVideoRendererControl() override;
-
- QAbstractVideoSurface *surface() const override;
- void setSurface(QAbstractVideoSurface *surface) override;
-
- IBaseFilter *filter();
-
-Q_SIGNALS:
- void filterChanged();
- void positionChanged(qint64 position);
-
-private:
- DirectShowEventLoop *m_loop;
- QAbstractVideoSurface *m_surface = nullptr;
- IBaseFilter *m_filter = nullptr;
-#if QT_CONFIG(evr)
- EVRCustomPresenter *m_evrPresenter = nullptr;
-#endif
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/player/player.pri b/src/plugins/directshow/player/player.pri
deleted file mode 100644
index ec1066db7..000000000
--- a/src/plugins/directshow/player/player.pri
+++ /dev/null
@@ -1,45 +0,0 @@
-INCLUDEPATH += $$PWD
-
-QMAKE_USE += directshow
-LIBS += -lgdi32
-
-mingw: LIBS_PRIVATE += -lksuser
-
-qtHaveModule(widgets): QT += widgets
-
-HEADERS += \
- $$PWD/directshowioreader.h \
- $$PWD/directshowiosource.h \
- $$PWD/directshowplayercontrol.h \
- $$PWD/directshowplayerservice.h \
- $$PWD/directshowvideorenderercontrol.h \
- $$PWD/videosurfacefilter.h \
- $$PWD/directshowaudioendpointcontrol.h \
- $$PWD/directshowmetadatacontrol.h \
- $$PWD/vmr9videowindowcontrol.h
-
-SOURCES += \
- $$PWD/directshowioreader.cpp \
- $$PWD/directshowiosource.cpp \
- $$PWD/directshowplayercontrol.cpp \
- $$PWD/directshowplayerservice.cpp \
- $$PWD/directshowvideorenderercontrol.cpp \
- $$PWD/videosurfacefilter.cpp \
- $$PWD/directshowaudioendpointcontrol.cpp \
- $$PWD/directshowmetadatacontrol.cpp \
- $$PWD/vmr9videowindowcontrol.cpp
-
-qtConfig(evr) {
- include($$PWD/../../common/evr.pri)
-
- HEADERS += \
- $$PWD/directshowevrvideowindowcontrol.h
-
- SOURCES += \
- $$PWD/directshowevrvideowindowcontrol.cpp
-} else {
- LIBS += -lwinmm
-}
-
-qtConfig(wshellitem): \
- QT += core-private
diff --git a/src/plugins/directshow/player/videosurfacefilter.cpp b/src/plugins/directshow/player/videosurfacefilter.cpp
deleted file mode 100644
index 4b7afc266..000000000
--- a/src/plugins/directshow/player/videosurfacefilter.cpp
+++ /dev/null
@@ -1,810 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "videosurfacefilter.h"
-
-#include "directshoweventloop.h"
-#include "directshowglobal.h"
-#include "directshowvideobuffer.h"
-
-#include <QtCore/qthread.h>
-#include <QtCore/qloggingcategory.h>
-#include <qabstractvideosurface.h>
-
-#include <mutex>
-
-#include <initguid.h>
-
-QT_BEGIN_NAMESPACE
-
-Q_LOGGING_CATEGORY(qLcRenderFilter, "qt.multimedia.plugins.directshow.renderfilter")
-
-// { e23cad72-153d-406c-bf3f-4c4b523d96f2 }
-DEFINE_GUID(CLSID_VideoSurfaceFilter,
-0xe23cad72, 0x153d, 0x406c, 0xbf, 0x3f, 0x4c, 0x4b, 0x52, 0x3d, 0x96, 0xf2);
-
-class VideoSurfaceInputPin : public DirectShowInputPin
-{
- COM_REF_MIXIN
-public:
- VideoSurfaceInputPin(VideoSurfaceFilter *filter);
-
- STDMETHODIMP QueryInterface(REFIID riid, void **ppv) override;
-
- bool isMediaTypeSupported(const AM_MEDIA_TYPE *type) override;
- bool setMediaType(const AM_MEDIA_TYPE *type) override;
-
- HRESULT completeConnection(IPin *pin) override;
- HRESULT connectionEnded() override;
-
- // IPin
- STDMETHODIMP ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt) override;
- STDMETHODIMP Disconnect() override;
- STDMETHODIMP EndOfStream() override;
- STDMETHODIMP BeginFlush() override;
- STDMETHODIMP EndFlush() override;
-
- // IMemInputPin
- STDMETHODIMP GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps) override;
- STDMETHODIMP Receive(IMediaSample *pMediaSample) override;
-
-private:
- VideoSurfaceFilter *m_videoSurfaceFilter;
-};
-
-VideoSurfaceInputPin::VideoSurfaceInputPin(VideoSurfaceFilter *filter)
- : DirectShowInputPin(filter, QStringLiteral("Input"))
- , m_videoSurfaceFilter(filter)
-{
-}
-
-HRESULT VideoSurfaceInputPin::QueryInterface(REFIID riid, void **ppv)
-{
- if (ppv == nullptr)
- return E_POINTER;
- if (riid == IID_IUnknown)
- *ppv = static_cast<IUnknown *>(static_cast<DirectShowPin *>(this));
- else if (riid == IID_IPin)
- *ppv = static_cast<IPin *>(this);
- else if (riid == IID_IMemInputPin)
- *ppv =static_cast<IMemInputPin*>(this);
- else
- return E_NOINTERFACE;
- AddRef();
- return S_OK;
-}
-
-bool VideoSurfaceInputPin::isMediaTypeSupported(const AM_MEDIA_TYPE *type)
-{
- return m_videoSurfaceFilter->isMediaTypeSupported(type);
-}
-
-bool VideoSurfaceInputPin::setMediaType(const AM_MEDIA_TYPE *type)
-{
- if (!DirectShowInputPin::setMediaType(type))
- return false;
-
- return m_videoSurfaceFilter->setMediaType(type);
-}
-
-HRESULT VideoSurfaceInputPin::completeConnection(IPin *pin)
-{
- HRESULT hr = DirectShowInputPin::completeConnection(pin);
- if (FAILED(hr))
- return hr;
-
- return m_videoSurfaceFilter->completeConnection(pin);
-}
-
-HRESULT VideoSurfaceInputPin::connectionEnded()
-{
- HRESULT hr = DirectShowInputPin::connectionEnded();
- if (FAILED(hr))
- return hr;
-
- return m_videoSurfaceFilter->connectionEnded();
-}
-
-HRESULT VideoSurfaceInputPin::ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt)
-{
- QMutexLocker lock(&m_videoSurfaceFilter->m_mutex);
- return DirectShowInputPin::ReceiveConnection(pConnector, pmt);
-}
-
-HRESULT VideoSurfaceInputPin::Disconnect()
-{
- QMutexLocker lock(&m_videoSurfaceFilter->m_mutex);
- return DirectShowInputPin::Disconnect();
-}
-
-HRESULT VideoSurfaceInputPin::EndOfStream()
-{
- QMutexLocker lock(&m_videoSurfaceFilter->m_mutex);
- const std::lock_guard<QRecursiveMutex> renderLocker(m_videoSurfaceFilter->m_renderMutex);
-
- HRESULT hr = DirectShowInputPin::EndOfStream();
- if (hr != S_OK)
- return hr;
-
- return m_videoSurfaceFilter->EndOfStream();
-}
-
-HRESULT VideoSurfaceInputPin::BeginFlush()
-{
- QMutexLocker lock(&m_videoSurfaceFilter->m_mutex);
- {
- const std::lock_guard<QRecursiveMutex> renderLocker(m_videoSurfaceFilter->m_renderMutex);
- DirectShowInputPin::BeginFlush();
- m_videoSurfaceFilter->BeginFlush();
- }
- m_videoSurfaceFilter->resetEOS();
-
- return S_OK;
-}
-
-HRESULT VideoSurfaceInputPin::EndFlush()
-{
- QMutexLocker lock(&m_videoSurfaceFilter->m_mutex);
- const std::lock_guard<QRecursiveMutex> renderLocker(m_videoSurfaceFilter->m_renderMutex);
-
- HRESULT hr = m_videoSurfaceFilter->EndFlush();
- if (SUCCEEDED(hr))
- hr = DirectShowInputPin::EndFlush();
- return hr;
-}
-
-HRESULT VideoSurfaceInputPin::GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps)
-{
- if (!pProps)
- return E_POINTER;
-
- // We need at least two allocated buffers, one for holding the frame currently being
- // rendered and another one to decode the following frame at the same time.
- pProps->cBuffers = 2;
-
- return S_OK;
-}
-
-HRESULT VideoSurfaceInputPin::Receive(IMediaSample *pMediaSample)
-{
- HRESULT hr = m_videoSurfaceFilter->Receive(pMediaSample);
- if (FAILED(hr)) {
- QMutexLocker locker(&m_videoSurfaceFilter->m_mutex);
- if (m_videoSurfaceFilter->state() != State_Stopped && !m_flushing && !m_inErrorState) {
- m_videoSurfaceFilter->NotifyEvent(EC_ERRORABORT, hr, 0);
- {
- const std::lock_guard<QRecursiveMutex> renderLocker(m_videoSurfaceFilter->m_renderMutex);
- if (m_videoSurfaceFilter->m_running && !m_videoSurfaceFilter->m_EOSDelivered)
- m_videoSurfaceFilter->notifyEOS();
- }
- m_inErrorState = true;
- }
- }
-
- return hr;
-}
-
-
-VideoSurfaceFilter::VideoSurfaceFilter(QAbstractVideoSurface *surface, DirectShowEventLoop *loop, QObject *parent)
- : QObject(parent)
- , m_loop(loop)
- , m_surface(surface)
- , m_renderEvent(CreateEvent(nullptr, FALSE, FALSE, nullptr))
- , m_flushEvent(CreateEvent(nullptr, TRUE, FALSE, nullptr))
-{
- supportedFormatsChanged();
- connect(surface, &QAbstractVideoSurface::supportedFormatsChanged,
- this, &VideoSurfaceFilter::supportedFormatsChanged);
-}
-
-VideoSurfaceFilter::~VideoSurfaceFilter()
-{
- clearPendingSample();
-
- if (m_pin)
- m_pin->Release();
-
- CloseHandle(m_flushEvent);
- CloseHandle(m_renderEvent);
-}
-
-HRESULT VideoSurfaceFilter::QueryInterface(REFIID riid, void **ppv)
-{
- if (ppv == nullptr)
- return E_POINTER;
- if (riid == IID_IUnknown)
- *ppv = static_cast<IUnknown *>(static_cast<DirectShowBaseFilter *>(this));
- else if (riid == IID_IPersist || riid == IID_IMediaFilter || riid == IID_IBaseFilter)
- *ppv = static_cast<IBaseFilter *>(this);
- else if (riid == IID_IAMFilterMiscFlags)
- *ppv = static_cast<IAMFilterMiscFlags *>(this);
- else
- return E_NOINTERFACE;
- AddRef();
- return S_OK;
-}
-
-QList<DirectShowPin *> VideoSurfaceFilter::pins()
-{
- if (!m_pin)
- m_pin = new VideoSurfaceInputPin(this);
-
- return QList<DirectShowPin *>() << m_pin;
-}
-
-HRESULT VideoSurfaceFilter::GetClassID(CLSID *pClassID)
-{
- *pClassID = CLSID_VideoSurfaceFilter;
- return S_OK;
-}
-
-ULONG VideoSurfaceFilter::GetMiscFlags()
-{
- return AM_FILTER_MISC_FLAGS_IS_RENDERER;
-}
-
-void VideoSurfaceFilter::supportedFormatsChanged()
-{
- QWriteLocker writeLocker(&m_typesLock);
-
- qCDebug(qLcRenderFilter, "supportedFormatChanged");
-
- m_supportedTypes.clear();
-
- const QList<QVideoFrame::PixelFormat> formats = m_surface->supportedPixelFormats();
- m_supportedTypes.reserve(formats.count());
-
- for (QVideoFrame::PixelFormat format : formats) {
- GUID subtype = DirectShowMediaType::convertPixelFormat(format);
- if (!IsEqualGUID(subtype, MEDIASUBTYPE_None)) {
- qCDebug(qLcRenderFilter) << " " << format;
- m_supportedTypes.append(subtype);
- }
- }
-}
-
-bool VideoSurfaceFilter::isMediaTypeSupported(const AM_MEDIA_TYPE *type)
-{
- if (type->majortype != MEDIATYPE_Video || type->bFixedSizeSamples == FALSE)
- return false;
-
- QReadLocker readLocker(&m_typesLock);
-
- for (const GUID &supportedType : m_supportedTypes) {
- if (IsEqualGUID(supportedType, type->subtype))
- return true;
- }
-
- return false;
-}
-
-bool VideoSurfaceFilter::setMediaType(const AM_MEDIA_TYPE *type)
-{
- if (!type) {
- qCDebug(qLcRenderFilter, "clear media type");
- m_surfaceFormat = QVideoSurfaceFormat();
- m_bytesPerLine = 0;
- return true;
- }
- m_surfaceFormat = DirectShowMediaType::videoFormatFromType(type);
- m_bytesPerLine = DirectShowMediaType::bytesPerLine(m_surfaceFormat);
- qCDebug(qLcRenderFilter) << "setMediaType -->" << m_surfaceFormat;
- return m_surfaceFormat.isValid();
-}
-
-HRESULT VideoSurfaceFilter::completeConnection(IPin *pin)
-{
- Q_UNUSED(pin);
-
- qCDebug(qLcRenderFilter, "completeConnection");
-
- return startSurface() ? S_OK : VFW_E_TYPE_NOT_ACCEPTED;
-}
-
-HRESULT VideoSurfaceFilter::connectionEnded()
-{
- qCDebug(qLcRenderFilter, "connectionEnded");
-
- stopSurface();
-
- return S_OK;
-}
-
-HRESULT VideoSurfaceFilter::Run(REFERENCE_TIME tStart)
-{
- QMutexLocker locker(&m_mutex);
-
- if (m_state == State_Running)
- return S_OK;
-
- qCDebug(qLcRenderFilter, "Run (start=%lli)", tStart);
-
- HRESULT hr = DirectShowBaseFilter::Run(tStart);
- if (FAILED(hr))
- return hr;
-
- ResetEvent(m_flushEvent);
-
- IMemAllocator *allocator;
- if (SUCCEEDED(m_pin->GetAllocator(&allocator))) {
- allocator->Commit();
- allocator->Release();
- }
-
- const std::lock_guard<QRecursiveMutex> renderLocker(m_renderMutex);
-
- m_running = true;
-
- if (!m_pendingSample)
- checkEOS();
- else if (!scheduleSample(m_pendingSample))
- SetEvent(m_renderEvent); // render immediately
-
- return S_OK;
-}
-
-HRESULT VideoSurfaceFilter::Pause()
-{
- QMutexLocker locker(&m_mutex);
-
- if (m_state == State_Paused)
- return S_OK;
-
- qCDebug(qLcRenderFilter, "Pause");
-
- HRESULT hr = DirectShowBaseFilter::Pause();
- if (FAILED(hr))
- return hr;
-
- m_renderMutex.lock();
- m_EOSDelivered = false;
- m_running = false;
- m_renderMutex.unlock();
-
- resetEOSTimer();
- ResetEvent(m_flushEvent);
- unscheduleSample();
-
- IMemAllocator *allocator;
- if (SUCCEEDED(m_pin->GetAllocator(&allocator))) {
- allocator->Commit();
- allocator->Release();
- }
-
- return S_OK;
-}
-
-HRESULT VideoSurfaceFilter::Stop()
-{
- QMutexLocker locker(&m_mutex);
-
- if (m_state == State_Stopped)
- return S_OK;
-
- qCDebug(qLcRenderFilter, "Stop");
-
- DirectShowBaseFilter::Stop();
-
- clearPendingSample();
-
- m_renderMutex.lock();
- m_EOSDelivered = false;
- m_running = false;
- m_renderMutex.unlock();
-
- SetEvent(m_flushEvent);
- resetEOS();
- unscheduleSample();
- flushSurface();
-
- IMemAllocator *allocator;
- if (SUCCEEDED(m_pin->GetAllocator(&allocator))) {
- allocator->Decommit();
- allocator->Release();
- }
-
- return S_OK;
-}
-
-HRESULT VideoSurfaceFilter::EndOfStream()
-{
- const std::lock_guard<QRecursiveMutex> renderLocker(m_renderMutex);
-
- qCDebug(qLcRenderFilter, "EndOfStream");
-
- m_EOS = true;
-
- if (!m_pendingSample && m_running)
- checkEOS();
-
- stopSurface();
- return S_OK;
-}
-
-HRESULT VideoSurfaceFilter::BeginFlush()
-{
- qCDebug(qLcRenderFilter, "BeginFlush");
-
- SetEvent(m_flushEvent);
- unscheduleSample();
- clearPendingSample();
-
- return S_OK;
-}
-
-HRESULT VideoSurfaceFilter::EndFlush()
-{
- qCDebug(qLcRenderFilter, "EndFlush");
-
- ResetEvent(m_flushEvent);
- return S_OK;
-}
-
-HRESULT VideoSurfaceFilter::Receive(IMediaSample *pMediaSample)
-{
- {
- QMutexLocker locker(&m_mutex);
-
- qCDebug(qLcRenderFilter, "Receive (sample=%p)", pMediaSample);
-
- HRESULT hr = m_pin->DirectShowInputPin::Receive(pMediaSample);
- if (hr != S_OK) {
- qCDebug(qLcRenderFilter, " can't receive sample (error %X)", uint(hr));
- return E_FAIL;
- }
-
- // If the format dynamically changed, the sample contains information about the new format.
- // We need to reset the format and restart the QAbstractVideoSurface.
- if (m_pin->currentSampleProperties()->pMediaType
- && (!m_pin->setMediaType(m_pin->currentSampleProperties()->pMediaType)
- || !restartSurface())) {
- qCWarning(qLcRenderFilter, " dynamic format change failed, aborting rendering");
- NotifyEvent(EC_ERRORABORT, VFW_E_TYPE_NOT_ACCEPTED, 0);
- return VFW_E_INVALIDMEDIATYPE;
- }
-
- {
- const std::lock_guard<QRecursiveMutex> locker(m_renderMutex);
-
- if (m_pendingSample || m_EOS)
- return E_UNEXPECTED;
-
- if (m_running && !scheduleSample(pMediaSample)) {
- qCWarning(qLcRenderFilter, " sample can't be scheduled, discarding it");
- return S_OK;
- }
-
- m_pendingSample = pMediaSample;
- m_pendingSample->AddRef();
- m_pendingSampleEndTime = m_pin->currentSampleProperties()->tStop;
- }
-
- if (m_state == State_Paused) // Render immediately
- renderPendingSample();
- }
-
- qCDebug(qLcRenderFilter, " waiting for render time");
-
- // Wait for render time. The clock will wake us up whenever the time comes.
- // It can also be interrupted by a flush, pause or stop.
- HANDLE waitObjects[] = { m_flushEvent, m_renderEvent };
- DWORD result = WAIT_TIMEOUT;
- while (result == WAIT_TIMEOUT)
- result = WaitForMultipleObjects(2, waitObjects, FALSE, INFINITE);
-
- if (result == WAIT_OBJECT_0) {
- // render interrupted (flush, pause, stop)
- qCDebug(qLcRenderFilter, " rendering of sample %p interrupted", pMediaSample);
- return S_OK;
- }
-
- m_adviseCookie = 0;
-
- QMutexLocker locker(&m_mutex);
-
- // State might have changed just before the lock
- if (m_state == State_Stopped) {
- qCDebug(qLcRenderFilter, " state changed to Stopped, discarding sample (%p)", pMediaSample);
- return S_OK;
- }
-
- std::unique_lock<QRecursiveMutex> renderLocker(m_renderMutex);
-
- // Flush or pause might have happened just before the lock
- if (m_pendingSample && m_running) {
- renderLocker.unlock();
- renderPendingSample();
- renderLocker.lock();
- } else {
- qCDebug(qLcRenderFilter, " discarding sample (%p)", pMediaSample);
- }
-
- clearPendingSample();
- checkEOS();
- ResetEvent(m_renderEvent);
-
- return S_OK;
-}
-
-bool VideoSurfaceFilter::scheduleSample(IMediaSample *sample)
-{
- if (!sample)
- return false;
-
- qCDebug(qLcRenderFilter, "scheduleSample (sample=%p)", sample);
-
- REFERENCE_TIME sampleStart, sampleEnd;
- if (FAILED(sample->GetTime(&sampleStart, &sampleEnd)) || !m_clock) {
- qCDebug(qLcRenderFilter, " render now");
- SetEvent(m_renderEvent); // Render immediately
- return true;
- }
-
- if (sampleEnd < sampleStart) { // incorrect times
- qCWarning(qLcRenderFilter, " invalid sample times (start=%lli, end=%lli)", sampleStart, sampleEnd);
- return false;
- }
-
- HRESULT hr = m_clock->AdviseTime(m_startTime, sampleStart, (HEVENT)m_renderEvent, &m_adviseCookie);
- if (FAILED(hr)) {
- qCWarning(qLcRenderFilter, " clock failed to advise time (error=%X)", uint(hr));
- return false;
- }
-
- return true;
-}
-
-void VideoSurfaceFilter::unscheduleSample()
-{
- if (m_adviseCookie) {
- qCDebug(qLcRenderFilter, "unscheduleSample");
- m_clock->Unadvise(m_adviseCookie);
- m_adviseCookie = 0;
- }
-
- ResetEvent(m_renderEvent);
-}
-
-void VideoSurfaceFilter::clearPendingSample()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_renderMutex);
- if (m_pendingSample) {
- qCDebug(qLcRenderFilter, "clearPendingSample");
- m_pendingSample->Release();
- m_pendingSample = nullptr;
- }
-}
-
-void QT_WIN_CALLBACK EOSTimerCallback(UINT, UINT, DWORD_PTR dwUser, DWORD_PTR, DWORD_PTR)
-{
- VideoSurfaceFilter *that = reinterpret_cast<VideoSurfaceFilter *>(dwUser);
- that->onEOSTimerTimeout();
-}
-
-void VideoSurfaceFilter::onEOSTimerTimeout()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_renderMutex);
-
- if (m_EOSTimer) {
- m_EOSTimer = 0;
- checkEOS();
- }
-}
-
-void VideoSurfaceFilter::checkEOS()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_renderMutex);
-
- if (!m_EOS || m_EOSDelivered || m_EOSTimer)
- return;
-
- if (!m_clock) {
- notifyEOS();
- return;
- }
-
- REFERENCE_TIME eosTime = m_startTime + m_pendingSampleEndTime;
- REFERENCE_TIME currentTime;
- m_clock->GetTime(&currentTime);
- LONG delay = LONG((eosTime - currentTime) / 10000);
-
- if (delay < 1) {
- notifyEOS();
- } else {
- qCDebug(qLcRenderFilter, "will trigger EOS in %li", delay);
-
- m_EOSTimer = timeSetEvent(delay,
- 1,
- EOSTimerCallback,
- reinterpret_cast<DWORD_PTR>(this),
- TIME_ONESHOT | TIME_CALLBACK_FUNCTION | TIME_KILL_SYNCHRONOUS);
-
- if (!m_EOSTimer) {
- qDebug("Error with timer");
- notifyEOS();
- }
- }
-}
-
-void VideoSurfaceFilter::notifyEOS()
-{
- const std::lock_guard<QRecursiveMutex> locker(m_renderMutex);
-
- if (!m_running)
- return;
-
- qCDebug(qLcRenderFilter, "notifyEOS, delivering EC_COMPLETE event");
-
- m_EOSTimer = 0;
- m_EOSDelivered = true;
- NotifyEvent(EC_COMPLETE, S_OK, (LONG_PTR)(IBaseFilter *)this);
-}
-
-void VideoSurfaceFilter::resetEOS()
-{
- resetEOSTimer();
-
- const std::lock_guard<QRecursiveMutex> locker(m_renderMutex);
-
- if (m_EOS)
- qCDebug(qLcRenderFilter, "resetEOS (delivered=%s)", m_EOSDelivered ? "true" : "false");
-
- m_EOS = false;
- m_EOSDelivered = false;
- m_pendingSampleEndTime = 0;
-}
-
-void VideoSurfaceFilter::resetEOSTimer()
-{
- if (m_EOSTimer) {
- timeKillEvent(m_EOSTimer);
- m_EOSTimer = 0;
- }
-}
-
-bool VideoSurfaceFilter::startSurface()
-{
- if (QThread::currentThread() != thread()) {
- m_loop->postEvent(this, new QEvent(QEvent::Type(StartSurface)));
- m_waitSurface.wait(&m_mutex);
- return m_surfaceStarted;
- }
- m_surfaceStarted = m_surface->start(m_surfaceFormat);
- qCDebug(qLcRenderFilter, "startSurface %s", m_surfaceStarted ? "succeeded" : "failed");
- return m_surfaceStarted;
-}
-
-void VideoSurfaceFilter::stopSurface()
-{
- if (!m_surfaceStarted)
- return;
-
- if (QThread::currentThread() != thread()) {
- m_loop->postEvent(this, new QEvent(QEvent::Type(StopSurface)));
- m_waitSurface.wait(&m_mutex);
- } else {
- qCDebug(qLcRenderFilter, "stopSurface");
- m_surface->stop();
- m_surfaceStarted = false;
- }
-}
-
-bool VideoSurfaceFilter::restartSurface()
-{
- if (QThread::currentThread() != thread()) {
- m_loop->postEvent(this, new QEvent(QEvent::Type(RestartSurface)));
- m_waitSurface.wait(&m_mutex);
- return m_surfaceStarted;
- }
- m_surface->stop();
- m_surfaceStarted = m_surface->start(m_surfaceFormat);
- qCDebug(qLcRenderFilter, "restartSurface %s", m_surfaceStarted ? "succeeded" : "failed");
- return m_surfaceStarted;
-}
-
-void VideoSurfaceFilter::flushSurface()
-{
- if (QThread::currentThread() != thread()) {
- m_loop->postEvent(this, new QEvent(QEvent::Type(FlushSurface)));
- m_waitSurface.wait(&m_mutex);
- } else {
- qCDebug(qLcRenderFilter, "flushSurface");
- m_surface->present(QVideoFrame());
- }
-}
-
-void VideoSurfaceFilter::renderPendingSample()
-{
- if (QThread::currentThread() != thread()) {
- m_loop->postEvent(this, new QEvent(QEvent::Type(RenderSample)));
- m_waitSurface.wait(&m_mutex);
- } else {
- const std::lock_guard<QRecursiveMutex> locker(m_renderMutex);
- if (!m_pendingSample)
- return;
-
- qCDebug(qLcRenderFilter, "presentSample (sample=%p)", m_pendingSample);
-
- m_surface->present(QVideoFrame(new DirectShowVideoBuffer(m_pendingSample, m_bytesPerLine),
- m_surfaceFormat.frameSize(),
- m_surfaceFormat.pixelFormat()));
- }
-}
-
-bool VideoSurfaceFilter::event(QEvent *e)
-{
- switch (e->type()) {
- case StartSurface: {
- QMutexLocker locker(&m_mutex);
- startSurface();
- m_waitSurface.wakeAll();
- return true;
- }
- case StopSurface: {
- QMutexLocker locker(&m_mutex);
- stopSurface();
- m_waitSurface.wakeAll();
- return true;
- }
- case RestartSurface: {
- QMutexLocker locker(&m_mutex);
- restartSurface();
- m_waitSurface.wakeAll();
- return true;
- }
- case FlushSurface: {
- QMutexLocker locker(&m_mutex);
- flushSurface();
- m_waitSurface.wakeAll();
- return true;
- }
- case RenderSample: {
- QMutexLocker locker(&m_mutex);
- renderPendingSample();
- m_waitSurface.wakeAll();
- return true;
- }
- default:
- break;
- }
-
- return QObject::event(e);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/directshow/player/videosurfacefilter.h b/src/plugins/directshow/player/videosurfacefilter.h
deleted file mode 100644
index 9e56f4b65..000000000
--- a/src/plugins/directshow/player/videosurfacefilter.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef VIDEOSURFACEFILTER_H
-#define VIDEOSURFACEFILTER_H
-
-#include "directshowbasefilter.h"
-
-#include <QtCore/qcoreevent.h>
-#include <QtCore/qmutex.h>
-#include <qreadwritelock.h>
-#include <qsemaphore.h>
-#include <qwaitcondition.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAbstractVideoSurface;
-
-class DirectShowEventLoop;
-class VideoSurfaceInputPin;
-
-class VideoSurfaceFilter : public QObject
- , public DirectShowBaseFilter
- , public IAMFilterMiscFlags
-{
- Q_OBJECT
- COM_REF_MIXIN
-public:
- VideoSurfaceFilter(QAbstractVideoSurface *surface, DirectShowEventLoop *loop, QObject *parent = nullptr);
- ~VideoSurfaceFilter();
-
- STDMETHODIMP QueryInterface(REFIID riid, void **ppv) override;
-
- // DirectShowBaseFilter
- QList<DirectShowPin *> pins() override;
-
- // IPersist
- STDMETHODIMP GetClassID(CLSID *pClassID) override;
-
- // IMediaFilter
- STDMETHODIMP Run(REFERENCE_TIME tStart) override;
- STDMETHODIMP Pause() override;
- STDMETHODIMP Stop() override;
-
- // IAMFilterMiscFlags
- STDMETHODIMP_(ULONG) GetMiscFlags() override;
-
- // DirectShowPin (delegate)
- bool isMediaTypeSupported(const AM_MEDIA_TYPE *type);
- bool setMediaType(const AM_MEDIA_TYPE *type);
- HRESULT completeConnection(IPin *pin);
- HRESULT connectionEnded();
-
- // IPin (delegate)
- HRESULT EndOfStream();
- HRESULT BeginFlush();
- HRESULT EndFlush();
-
- // IMemInputPin (delegate)
- HRESULT Receive(IMediaSample *pMediaSample);
-
-private Q_SLOTS:
- void supportedFormatsChanged();
- void checkEOS();
-
-private:
- enum Events {
- StartSurface = QEvent::User,
- StopSurface = QEvent::User + 1,
- RestartSurface = QEvent::User + 2,
- FlushSurface = QEvent::User + 3,
- RenderSample = QEvent::User + 4
- };
-
- bool event(QEvent *) override;
-
- bool startSurface();
- void stopSurface();
- bool restartSurface();
- void flushSurface();
-
- bool scheduleSample(IMediaSample *sample);
- void unscheduleSample();
- void renderPendingSample();
- void clearPendingSample();
-
- void notifyEOS();
- void resetEOS();
- void resetEOSTimer();
- void onEOSTimerTimeout();
-
- friend void QT_WIN_CALLBACK EOSTimerCallback(UINT, UINT, DWORD_PTR dwUser, DWORD_PTR, DWORD_PTR);
-
- QMutex m_mutex;
-
- DirectShowEventLoop *m_loop;
- VideoSurfaceInputPin *m_pin = nullptr;
-
- QWaitCondition m_waitSurface;
- QAbstractVideoSurface *m_surface;
- QVideoSurfaceFormat m_surfaceFormat;
- int m_bytesPerLine = 0;
- bool m_surfaceStarted = false;
-
- QList<GUID> m_supportedTypes;
- QReadWriteLock m_typesLock;
-
- QRecursiveMutex m_renderMutex;
- bool m_running = false;
- IMediaSample *m_pendingSample = nullptr;
- REFERENCE_TIME m_pendingSampleEndTime = 0;
- HANDLE m_renderEvent;
- HANDLE m_flushEvent;
- DWORD_PTR m_adviseCookie = 0;
-
- bool m_EOS = false;
- bool m_EOSDelivered = false;
- UINT m_EOSTimer = 0;
-
- friend class VideoSurfaceInputPin;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/directshow/player/vmr9videowindowcontrol.cpp b/src/plugins/directshow/player/vmr9videowindowcontrol.cpp
deleted file mode 100644
index 63c945622..000000000
--- a/src/plugins/directshow/player/vmr9videowindowcontrol.cpp
+++ /dev/null
@@ -1,326 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "vmr9videowindowcontrol.h"
-
-#include "directshowglobal.h"
-
-#ifndef QT_NO_WIDGETS
-#include <QtGui/QPalette>
-#include <QtWidgets/QWidget>
-#endif
-
-Vmr9VideoWindowControl::Vmr9VideoWindowControl(QObject *parent)
- : QVideoWindowControl(parent)
- , m_filter(com_new<IBaseFilter>(CLSID_VideoMixingRenderer9))
-{
- if (IVMRFilterConfig9 *config = com_cast<IVMRFilterConfig9>(m_filter, IID_IVMRFilterConfig9)) {
- config->SetRenderingMode(VMR9Mode_Windowless);
- config->SetNumberOfStreams(1);
- config->Release();
- }
-}
-
-Vmr9VideoWindowControl::~Vmr9VideoWindowControl()
-{
- if (m_filter)
- m_filter->Release();
-}
-
-
-WId Vmr9VideoWindowControl::winId() const
-{
- return m_windowId;
-
-}
-
-void Vmr9VideoWindowControl::setWinId(WId id)
-{
- m_windowId = id;
-
-#ifndef QT_NO_WIDGETS
- if (QWidget *widget = QWidget::find(m_windowId)) {
- const QColor color = widget->palette().color(QPalette::Window);
-
- m_windowColor = RGB(color.red(), color.green(), color.blue());
- }
-#endif
-
- if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(
- m_filter, IID_IVMRWindowlessControl9)) {
- control->SetVideoClippingWindow(reinterpret_cast<HWND>(m_windowId));
- control->SetBorderColor(m_windowColor);
- control->Release();
- }
-}
-
-QRect Vmr9VideoWindowControl::displayRect() const
-{
- return m_displayRect;
-}
-
-void Vmr9VideoWindowControl::setDisplayRect(const QRect &rect)
-{
- m_displayRect = rect;
-
- if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(
- m_filter, IID_IVMRWindowlessControl9)) {
- RECT sourceRect = { 0, 0, 0, 0 };
- RECT displayRect = { rect.left(), rect.top(), rect.right() + 1, rect.bottom() + 1 };
-
- control->GetNativeVideoSize(&sourceRect.right, &sourceRect.bottom, nullptr, nullptr);
-
- if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
- QSize clippedSize = rect.size();
- clippedSize.scale(sourceRect.right, sourceRect.bottom, Qt::KeepAspectRatio);
-
- sourceRect.left = (sourceRect.right - clippedSize.width()) / 2;
- sourceRect.top = (sourceRect.bottom - clippedSize.height()) / 2;
- sourceRect.right = sourceRect.left + clippedSize.width();
- sourceRect.bottom = sourceRect.top + clippedSize.height();
- }
-
- control->SetVideoPosition(&sourceRect, &displayRect);
- control->Release();
- }
-}
-
-bool Vmr9VideoWindowControl::isFullScreen() const
-{
- return m_fullScreen;
-}
-
-void Vmr9VideoWindowControl::setFullScreen(bool fullScreen)
-{
- emit fullScreenChanged(m_fullScreen = fullScreen);
-}
-
-void Vmr9VideoWindowControl::repaint()
-{
- PAINTSTRUCT paint;
-
- if (HDC dc = ::BeginPaint(reinterpret_cast<HWND>(m_windowId), &paint)) {
- HRESULT hr = E_FAIL;
-
- if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(
- m_filter, IID_IVMRWindowlessControl9)) {
- hr = control->RepaintVideo(reinterpret_cast<HWND>(m_windowId), dc);
- control->Release();
- }
-
- if (!SUCCEEDED(hr)) {
- HPEN pen = ::CreatePen(PS_SOLID, 1, m_windowColor);
- HBRUSH brush = ::CreateSolidBrush(m_windowColor);
- ::SelectObject(dc, pen);
- ::SelectObject(dc, brush);
-
- ::Rectangle(
- dc,
- m_displayRect.left(),
- m_displayRect.top(),
- m_displayRect.right() + 1,
- m_displayRect.bottom() + 1);
-
- ::DeleteObject(pen);
- ::DeleteObject(brush);
- }
- ::EndPaint(reinterpret_cast<HWND>(m_windowId), &paint);
- }
-}
-
-QSize Vmr9VideoWindowControl::nativeSize() const
-{
- QSize size;
-
- if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(
- m_filter, IID_IVMRWindowlessControl9)) {
- LONG width;
- LONG height;
-
- if (control->GetNativeVideoSize(&width, &height, nullptr, nullptr) == S_OK)
- size = QSize(width, height);
- control->Release();
- }
- return size;
-}
-
-Qt::AspectRatioMode Vmr9VideoWindowControl::aspectRatioMode() const
-{
- return m_aspectRatioMode;
-}
-
-void Vmr9VideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- m_aspectRatioMode = mode;
-
- if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(
- m_filter, IID_IVMRWindowlessControl9)) {
- switch (mode) {
- case Qt::IgnoreAspectRatio:
- control->SetAspectRatioMode(VMR9ARMode_None);
- break;
- case Qt::KeepAspectRatio:
- control->SetAspectRatioMode(VMR9ARMode_LetterBox);
- break;
- case Qt::KeepAspectRatioByExpanding:
- control->SetAspectRatioMode(VMR9ARMode_LetterBox);
- setDisplayRect(m_displayRect);
- break;
- default:
- break;
- }
- control->Release();
- }
-}
-
-int Vmr9VideoWindowControl::brightness() const
-{
- return m_brightness;
-}
-
-void Vmr9VideoWindowControl::setBrightness(int brightness)
-{
- m_brightness = brightness;
-
- m_dirtyValues |= ProcAmpControl9_Brightness;
-
- setProcAmpValues();
-
- emit brightnessChanged(brightness);
-}
-
-int Vmr9VideoWindowControl::contrast() const
-{
- return m_contrast;
-}
-
-void Vmr9VideoWindowControl::setContrast(int contrast)
-{
- m_contrast = contrast;
-
- m_dirtyValues |= ProcAmpControl9_Contrast;
-
- setProcAmpValues();
-
- emit contrastChanged(contrast);
-}
-
-int Vmr9VideoWindowControl::hue() const
-{
- return m_hue;
-}
-
-void Vmr9VideoWindowControl::setHue(int hue)
-{
- m_hue = hue;
-
- m_dirtyValues |= ProcAmpControl9_Hue;
-
- setProcAmpValues();
-
- emit hueChanged(hue);
-}
-
-int Vmr9VideoWindowControl::saturation() const
-{
- return m_saturation;
-}
-
-void Vmr9VideoWindowControl::setSaturation(int saturation)
-{
- m_saturation = saturation;
-
- m_dirtyValues |= ProcAmpControl9_Saturation;
-
- setProcAmpValues();
-
- emit saturationChanged(saturation);
-}
-
-void Vmr9VideoWindowControl::setProcAmpValues()
-{
- if (IVMRMixerControl9 *control = com_cast<IVMRMixerControl9>(m_filter, IID_IVMRMixerControl9)) {
- VMR9ProcAmpControl procAmp;
- procAmp.dwSize = sizeof(VMR9ProcAmpControl);
- procAmp.dwFlags = m_dirtyValues;
-
- if (m_dirtyValues & ProcAmpControl9_Brightness) {
- procAmp.Brightness = scaleProcAmpValue(
- control, ProcAmpControl9_Brightness, m_brightness);
- }
- if (m_dirtyValues & ProcAmpControl9_Contrast) {
- procAmp.Contrast = scaleProcAmpValue(
- control, ProcAmpControl9_Contrast, m_contrast);
- }
- if (m_dirtyValues & ProcAmpControl9_Hue) {
- procAmp.Hue = scaleProcAmpValue(
- control, ProcAmpControl9_Hue, m_hue);
- }
- if (m_dirtyValues & ProcAmpControl9_Saturation) {
- procAmp.Saturation = scaleProcAmpValue(
- control, ProcAmpControl9_Saturation, m_saturation);
- }
-
- if (SUCCEEDED(control->SetProcAmpControl(0, &procAmp))) {
- m_dirtyValues = 0;
- }
-
- control->Release();
- }
-}
-
-float Vmr9VideoWindowControl::scaleProcAmpValue(
- IVMRMixerControl9 *control, VMR9ProcAmpControlFlags property, int value) const
-{
- float scaledValue = 0.0;
-
- VMR9ProcAmpControlRange range;
- range.dwSize = sizeof(VMR9ProcAmpControlRange);
- range.dwProperty = property;
-
- if (SUCCEEDED(control->GetProcAmpControlRange(0, &range))) {
- scaledValue = range.DefaultValue;
- if (value > 0)
- scaledValue += float(value) * (range.MaxValue - range.DefaultValue) / 100;
- else if (value < 0)
- scaledValue -= float(value) * (range.MinValue - range.DefaultValue) / 100;
- }
-
- return scaledValue;
-}
diff --git a/src/plugins/directshow/player/vmr9videowindowcontrol.h b/src/plugins/directshow/player/vmr9videowindowcontrol.h
deleted file mode 100644
index 2a6f008f3..000000000
--- a/src/plugins/directshow/player/vmr9videowindowcontrol.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef VMR9VIDEOWINDOWCONTROL_H
-#define VMR9VIDEOWINDOWCONTROL_H
-
-#include "qvideowindowcontrol.h"
-
-#include <dshow.h>
-#include <d3d9.h>
-#include <vmr9.h>
-
-QT_BEGIN_NAMESPACE
-
-class Vmr9VideoWindowControl : public QVideoWindowControl
-{
- Q_OBJECT
-public:
- Vmr9VideoWindowControl(QObject *parent = nullptr);
- ~Vmr9VideoWindowControl() override;
-
- IBaseFilter *filter() const { return m_filter; }
-
- WId winId() const override;
- void setWinId(WId id) override;
-
- QRect displayRect() const override;
- void setDisplayRect(const QRect &rect) override;
-
- bool isFullScreen() const override;
- void setFullScreen(bool fullScreen) override;
-
- void repaint() override;
-
- QSize nativeSize() const override;
-
- Qt::AspectRatioMode aspectRatioMode() const override;
- void setAspectRatioMode(Qt::AspectRatioMode mode) override;
-
- int brightness() const override;
- void setBrightness(int brightness) override;
-
- int contrast() const override;
- void setContrast(int contrast) override;
-
- int hue() const override;
- void setHue(int hue) override;
-
- int saturation() const override;
- void setSaturation(int saturation) override;
-
-private:
- void setProcAmpValues();
- float scaleProcAmpValue(
- IVMRMixerControl9 *control, VMR9ProcAmpControlFlags property, int value) const;
-
- IBaseFilter *m_filter;
- WId m_windowId = 0;
- COLORREF m_windowColor = RGB(0, 0, 0);
- DWORD m_dirtyValues = 0;
- Qt::AspectRatioMode m_aspectRatioMode = Qt::KeepAspectRatio;
- QRect m_displayRect;
- int m_brightness = 0;
- int m_contrast = 0;
- int m_hue = 0;
- int m_saturation = 0;
- bool m_fullScreen = false;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/audiodecoder/audiodecoder.json b/src/plugins/gstreamer/audiodecoder/audiodecoder.json
deleted file mode 100644
index 4314f2efa..000000000
--- a/src/plugins/gstreamer/audiodecoder/audiodecoder.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["gstreameraudiodecode"],
- "Services": ["org.qt-project.qt.audiodecode"]
-}
diff --git a/src/plugins/gstreamer/audiodecoder/audiodecoder.pro b/src/plugins/gstreamer/audiodecoder/audiodecoder.pro
deleted file mode 100644
index 4e816e920..000000000
--- a/src/plugins/gstreamer/audiodecoder/audiodecoder.pro
+++ /dev/null
@@ -1,24 +0,0 @@
-TARGET = gstaudiodecoder
-
-include(../common.pri)
-
-INCLUDEPATH += $$PWD
-
-HEADERS += \
- $$PWD/qgstreameraudiodecodercontrol.h \
- $$PWD/qgstreameraudiodecoderservice.h \
- $$PWD/qgstreameraudiodecodersession.h \
- $$PWD/qgstreameraudiodecoderserviceplugin.h
-
-SOURCES += \
- $$PWD/qgstreameraudiodecodercontrol.cpp \
- $$PWD/qgstreameraudiodecoderservice.cpp \
- $$PWD/qgstreameraudiodecodersession.cpp \
- $$PWD/qgstreameraudiodecoderserviceplugin.cpp
-
-OTHER_FILES += \
- audiodecoder.json
-
-PLUGIN_TYPE = mediaservice
-PLUGIN_CLASS_NAME = QGstreamerAudioDecoderServicePlugin
-load(qt_plugin)
diff --git a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodercontrol.cpp b/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodercontrol.cpp
deleted file mode 100644
index e9a7a5332..000000000
--- a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodercontrol.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreameraudiodecodercontrol.h"
-#include "qgstreameraudiodecodersession.h"
-
-#include <QtCore/qdir.h>
-#include <QtCore/qsocketnotifier.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qdebug.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-QT_BEGIN_NAMESPACE
-
-QGstreamerAudioDecoderControl::QGstreamerAudioDecoderControl(QGstreamerAudioDecoderSession *session, QObject *parent)
- : QAudioDecoderControl(parent)
- , m_session(session)
-{
- connect(m_session, SIGNAL(bufferAvailableChanged(bool)), this, SIGNAL(bufferAvailableChanged(bool)));
- connect(m_session, SIGNAL(bufferReady()), this, SIGNAL(bufferReady()));
- connect(m_session, SIGNAL(error(int,QString)), this, SIGNAL(error(int,QString)));
- connect(m_session, SIGNAL(formatChanged(QAudioFormat)), this, SIGNAL(formatChanged(QAudioFormat)));
- connect(m_session, SIGNAL(sourceChanged()), this, SIGNAL(sourceChanged()));
- connect(m_session, SIGNAL(stateChanged(QAudioDecoder::State)), this, SIGNAL(stateChanged(QAudioDecoder::State)));
- connect(m_session, SIGNAL(finished()), this, SIGNAL(finished()));
- connect(m_session, SIGNAL(positionChanged(qint64)), this, SIGNAL(positionChanged(qint64)));
- connect(m_session, SIGNAL(durationChanged(qint64)), this, SIGNAL(durationChanged(qint64)));
-}
-
-QGstreamerAudioDecoderControl::~QGstreamerAudioDecoderControl()
-{
-
-}
-
-QAudioDecoder::State QGstreamerAudioDecoderControl::state() const
-{
- return m_session->pendingState();
-}
-
-QString QGstreamerAudioDecoderControl::sourceFilename() const
-{
- return m_session->sourceFilename();
-}
-
-void QGstreamerAudioDecoderControl::setSourceFilename(const QString &fileName)
-{
- m_session->setSourceFilename(fileName);
-}
-
-QIODevice* QGstreamerAudioDecoderControl::sourceDevice() const
-{
- return m_session->sourceDevice();
-}
-
-void QGstreamerAudioDecoderControl::setSourceDevice(QIODevice *device)
-{
- m_session->setSourceDevice(device);
-}
-
-void QGstreamerAudioDecoderControl::start()
-{
- m_session->start();
-}
-
-void QGstreamerAudioDecoderControl::stop()
-{
- m_session->stop();
-}
-
-QAudioFormat QGstreamerAudioDecoderControl::audioFormat() const
-{
- return m_session->audioFormat();
-}
-
-void QGstreamerAudioDecoderControl::setAudioFormat(const QAudioFormat &format)
-{
- m_session->setAudioFormat(format);
-}
-
-QAudioBuffer QGstreamerAudioDecoderControl::read()
-{
- return m_session->read();
-}
-
-bool QGstreamerAudioDecoderControl::bufferAvailable() const
-{
- return m_session->bufferAvailable();
-}
-
-qint64 QGstreamerAudioDecoderControl::position() const
-{
- return m_session->position();
-}
-
-qint64 QGstreamerAudioDecoderControl::duration() const
-{
- return m_session->duration();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodercontrol.h b/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodercontrol.h
deleted file mode 100644
index f5e26e553..000000000
--- a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodercontrol.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERPLAYERCONTROL_H
-#define QGSTREAMERPLAYERCONTROL_H
-
-#include <QtCore/qobject.h>
-#include <QtCore/qstack.h>
-
-#include <qaudioformat.h>
-#include <qaudiobuffer.h>
-#include <qaudiodecoder.h>
-#include <qaudiodecodercontrol.h>
-
-#include <limits.h>
-
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerAudioDecoderSession;
-class QGstreamerAudioDecoderService;
-
-class QGstreamerAudioDecoderControl : public QAudioDecoderControl
-{
- Q_OBJECT
-
-public:
- QGstreamerAudioDecoderControl(QGstreamerAudioDecoderSession *session, QObject *parent = 0);
- ~QGstreamerAudioDecoderControl();
-
- QAudioDecoder::State state() const override;
-
- QString sourceFilename() const override;
- void setSourceFilename(const QString &fileName) override;
-
- QIODevice* sourceDevice() const override;
- void setSourceDevice(QIODevice *device) override;
-
- void start() override;
- void stop() override;
-
- QAudioFormat audioFormat() const override;
- void setAudioFormat(const QAudioFormat &format) override;
-
- QAudioBuffer read() override;
- bool bufferAvailable() const override;
-
- qint64 position() const override;
- qint64 duration() const override;
-
-private:
- // Stuff goes here
-
- QGstreamerAudioDecoderSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderservice.cpp b/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderservice.cpp
deleted file mode 100644
index 67b49be7e..000000000
--- a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderservice.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qvariant.h>
-#include <QtCore/qdebug.h>
-
-#include "qgstreameraudiodecoderservice.h"
-#include "qgstreameraudiodecodercontrol.h"
-#include "qgstreameraudiodecodersession.h"
-
-QT_BEGIN_NAMESPACE
-
-QGstreamerAudioDecoderService::QGstreamerAudioDecoderService(QObject *parent)
- : QMediaService(parent)
-{
- m_session = new QGstreamerAudioDecoderSession(this);
- m_control = new QGstreamerAudioDecoderControl(m_session, this);
-}
-
-QGstreamerAudioDecoderService::~QGstreamerAudioDecoderService()
-{
-}
-
-QMediaControl *QGstreamerAudioDecoderService::requestControl(const char *name)
-{
- if (qstrcmp(name, QAudioDecoderControl_iid) == 0)
- return m_control;
-
- return 0;
-}
-
-void QGstreamerAudioDecoderService::releaseControl(QMediaControl *control)
-{
- Q_UNUSED(control);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderservice.h b/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderservice.h
deleted file mode 100644
index 6e52b9d87..000000000
--- a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderservice.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERAUDIODECODERSERVICE_H
-#define QGSTREAMERAUDIODECODERSERVICE_H
-
-#include <QtCore/qobject.h>
-#include <QtCore/qiodevice.h>
-
-#include <qmediaservice.h>
-
-QT_BEGIN_NAMESPACE
-class QGstreamerAudioDecoderControl;
-class QGstreamerAudioDecoderSession;
-
-class QGstreamerAudioDecoderService : public QMediaService
-{
- Q_OBJECT
-public:
- QGstreamerAudioDecoderService(QObject *parent = 0);
- ~QGstreamerAudioDecoderService();
-
- QMediaControl *requestControl(const char *name) override;
- void releaseControl(QMediaControl *control) override;
-
-private:
- QGstreamerAudioDecoderControl *m_control;
- QGstreamerAudioDecoderSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderserviceplugin.cpp b/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderserviceplugin.cpp
deleted file mode 100644
index 463ed2d92..000000000
--- a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderserviceplugin.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreameraudiodecoderserviceplugin.h"
-
-#include "qgstreameraudiodecoderservice.h"
-#include <private/qgstutils_p.h>
-
-#include <QtCore/qstring.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/QDir>
-#include <QtCore/QDebug>
-
-// #define QT_SUPPORTEDMIMETYPES_DEBUG
-
-QMediaService* QGstreamerAudioDecoderServicePlugin::create(const QString &key)
-{
- QGstUtils::initializeGst();
-
- if (key == QLatin1String(Q_MEDIASERVICE_AUDIODECODER))
- return new QGstreamerAudioDecoderService;
-
- qWarning() << "Gstreamer audio decoder service plugin: unsupported key:" << key;
- return 0;
-}
-
-void QGstreamerAudioDecoderServicePlugin::release(QMediaService *service)
-{
- delete service;
-}
-
-QMultimedia::SupportEstimate QGstreamerAudioDecoderServicePlugin::hasSupport(const QString &mimeType,
- const QStringList &codecs) const
-{
- if (m_supportedMimeTypeSet.isEmpty())
- updateSupportedMimeTypes();
-
- return QGstUtils::hasSupport(mimeType, codecs, m_supportedMimeTypeSet);
-}
-
-static bool isDecoderOrDemuxer(GstElementFactory *factory)
-{
-#if GST_CHECK_VERSION(0, 10, 31)
- return gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_DEMUXER)
- || gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_DECODER
- | GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO);
-#else
- return (factory
- && (qstrcmp(factory->details.klass, "Codec/Decoder/Audio") == 0
- || qstrcmp(factory->details.klass, "Codec/Demux") == 0));
-#endif
-}
-
-void QGstreamerAudioDecoderServicePlugin::updateSupportedMimeTypes() const
-{
- m_supportedMimeTypeSet = QGstUtils::supportedMimeTypes(isDecoderOrDemuxer);
-}
-
-QStringList QGstreamerAudioDecoderServicePlugin::supportedMimeTypes() const
-{
- return QStringList();
-}
-
diff --git a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderserviceplugin.h b/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderserviceplugin.h
deleted file mode 100644
index d1b96043b..000000000
--- a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecoderserviceplugin.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERAUDIODECODERSERVICEPLUGIN_H
-#define QGSTREAMERAUDIODECODERSERVICEPLUGIN_H
-
-#include <qmediaserviceproviderplugin.h>
-#include <QtCore/qset.h>
-#include <QtCore/QObject>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerAudioDecoderServicePlugin
- : public QMediaServiceProviderPlugin
- , public QMediaServiceSupportedFormatsInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaServiceSupportedFormatsInterface)
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "audiodecoder.json")
-
-public:
- QMediaService* create(const QString &key) override;
- void release(QMediaService *service) override;
-
- QMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList &codecs) const override;
- QStringList supportedMimeTypes() const override;
-
-private:
- void updateSupportedMimeTypes() const;
-
- mutable QSet<QString> m_supportedMimeTypeSet;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERAUDIODECODERSERVICEPLUGIN_H
diff --git a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.cpp b/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.cpp
deleted file mode 100644
index d6b8ad759..000000000
--- a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.cpp
+++ /dev/null
@@ -1,614 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-//#define DEBUG_DECODER
-
-#include "qgstreameraudiodecodersession.h"
-#include <private/qgstreamerbushelper_p.h>
-
-#include <private/qgstutils_p.h>
-
-#include <gst/gstvalue.h>
-#include <gst/base/gstbasesrc.h>
-
-#include <QtCore/qdatetime.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qsize.h>
-#include <QtCore/qtimer.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qdir.h>
-#include <QtCore/qstandardpaths.h>
-#include <QtCore/qurl.h>
-
-#define MAX_BUFFERS_IN_QUEUE 4
-
-QT_BEGIN_NAMESPACE
-
-typedef enum {
- GST_PLAY_FLAG_VIDEO = 0x00000001,
- GST_PLAY_FLAG_AUDIO = 0x00000002,
- GST_PLAY_FLAG_TEXT = 0x00000004,
- GST_PLAY_FLAG_VIS = 0x00000008,
- GST_PLAY_FLAG_SOFT_VOLUME = 0x00000010,
- GST_PLAY_FLAG_NATIVE_AUDIO = 0x00000020,
- GST_PLAY_FLAG_NATIVE_VIDEO = 0x00000040,
- GST_PLAY_FLAG_DOWNLOAD = 0x00000080,
- GST_PLAY_FLAG_BUFFERING = 0x000000100
-} GstPlayFlags;
-
-QGstreamerAudioDecoderSession::QGstreamerAudioDecoderSession(QObject *parent)
- : QObject(parent),
- m_state(QAudioDecoder::StoppedState),
- m_pendingState(QAudioDecoder::StoppedState),
- m_busHelper(0),
- m_bus(0),
- m_playbin(0),
- m_outputBin(0),
- m_audioConvert(0),
- m_appSink(0),
-#if QT_CONFIG(gstreamer_app)
- m_appSrc(0),
-#endif
- mDevice(0),
- m_buffersAvailable(0),
- m_position(-1),
- m_duration(-1),
- m_durationQueries(0)
-{
- // Create pipeline here
- m_playbin = gst_element_factory_make(QT_GSTREAMER_PLAYBIN_ELEMENT_NAME, NULL);
-
- if (m_playbin != 0) {
- // Sort out messages
- m_bus = gst_element_get_bus(m_playbin);
- m_busHelper = new QGstreamerBusHelper(m_bus, this);
- m_busHelper->installMessageFilter(this);
-
- // Set the rest of the pipeline up
- setAudioFlags(true);
-
- m_audioConvert = gst_element_factory_make("audioconvert", NULL);
-
- m_outputBin = gst_bin_new("audio-output-bin");
- gst_bin_add(GST_BIN(m_outputBin), m_audioConvert);
-
- // add ghostpad
- GstPad *pad = gst_element_get_static_pad(m_audioConvert, "sink");
- Q_ASSERT(pad);
- gst_element_add_pad(GST_ELEMENT(m_outputBin), gst_ghost_pad_new("sink", pad));
- gst_object_unref(GST_OBJECT(pad));
-
- g_object_set(G_OBJECT(m_playbin), "audio-sink", m_outputBin, NULL);
-#if QT_CONFIG(gstreamer_app)
- g_signal_connect(G_OBJECT(m_playbin), "deep-notify::source", (GCallback) &QGstreamerAudioDecoderSession::configureAppSrcElement, (gpointer)this);
-#endif
-
- // Set volume to 100%
- gdouble volume = 1.0;
- g_object_set(G_OBJECT(m_playbin), "volume", volume, NULL);
- }
-}
-
-QGstreamerAudioDecoderSession::~QGstreamerAudioDecoderSession()
-{
- if (m_playbin) {
- stop();
-
- delete m_busHelper;
-#if QT_CONFIG(gstreamer_app)
- delete m_appSrc;
-#endif
- gst_object_unref(GST_OBJECT(m_bus));
- gst_object_unref(GST_OBJECT(m_playbin));
- }
-}
-
-#if QT_CONFIG(gstreamer_app)
-void QGstreamerAudioDecoderSession::configureAppSrcElement(GObject* object, GObject *orig, GParamSpec *pspec, QGstreamerAudioDecoderSession* self)
-{
- Q_UNUSED(object);
- Q_UNUSED(pspec);
-
- // In case we switch from appsrc to not
- if (!self->appsrc())
- return;
-
- GstElement *appsrc;
- g_object_get(orig, "source", &appsrc, NULL);
-
- if (!self->appsrc()->setup(appsrc))
- qWarning()<<"Could not setup appsrc element";
-
- g_object_unref(G_OBJECT(appsrc));
-}
-#endif
-
-bool QGstreamerAudioDecoderSession::processBusMessage(const QGstreamerMessage &message)
-{
- GstMessage* gm = message.rawMessage();
- if (gm) {
- if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_DURATION) {
- updateDuration();
- } else if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_playbin)) {
- switch (GST_MESSAGE_TYPE(gm)) {
- case GST_MESSAGE_STATE_CHANGED:
- {
- GstState oldState;
- GstState newState;
- GstState pending;
-
- gst_message_parse_state_changed(gm, &oldState, &newState, &pending);
-
-#ifdef DEBUG_DECODER
- QStringList states;
- states << "GST_STATE_VOID_PENDING" << "GST_STATE_NULL" << "GST_STATE_READY" << "GST_STATE_PAUSED" << "GST_STATE_PLAYING";
-
- qDebug() << QString("state changed: old: %1 new: %2 pending: %3") \
- .arg(states[oldState]) \
- .arg(states[newState]) \
- .arg(states[pending]) << "internal" << m_state;
-#endif
-
- QAudioDecoder::State prevState = m_state;
-
- switch (newState) {
- case GST_STATE_VOID_PENDING:
- case GST_STATE_NULL:
- m_state = QAudioDecoder::StoppedState;
- break;
- case GST_STATE_READY:
- m_state = QAudioDecoder::StoppedState;
- break;
- case GST_STATE_PLAYING:
- m_state = QAudioDecoder::DecodingState;
- break;
- case GST_STATE_PAUSED:
- m_state = QAudioDecoder::DecodingState;
-
- //gstreamer doesn't give a reliable indication the duration
- //information is ready, GST_MESSAGE_DURATION is not sent by most elements
- //the duration is queried up to 5 times with increasing delay
- m_durationQueries = 5;
- updateDuration();
- break;
- }
-
- if (prevState != m_state)
- emit stateChanged(m_state);
- }
- break;
-
- case GST_MESSAGE_EOS:
- m_pendingState = m_state = QAudioDecoder::StoppedState;
- emit finished();
- emit stateChanged(m_state);
- break;
-
- case GST_MESSAGE_ERROR: {
- GError *err;
- gchar *debug;
- gst_message_parse_error(gm, &err, &debug);
- if (err->domain == GST_STREAM_ERROR && err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND)
- processInvalidMedia(QAudioDecoder::FormatError, tr("Cannot play stream of type: <unknown>"));
- else
- processInvalidMedia(QAudioDecoder::ResourceError, QString::fromUtf8(err->message));
- qWarning() << "Error:" << QString::fromUtf8(err->message);
- g_error_free(err);
- g_free(debug);
- }
- break;
- case GST_MESSAGE_WARNING:
- {
- GError *err;
- gchar *debug;
- gst_message_parse_warning (gm, &err, &debug);
- qWarning() << "Warning:" << QString::fromUtf8(err->message);
- g_error_free (err);
- g_free (debug);
- }
- break;
-#ifdef DEBUG_DECODER
- case GST_MESSAGE_INFO:
- {
- GError *err;
- gchar *debug;
- gst_message_parse_info (gm, &err, &debug);
- qDebug() << "Info:" << QString::fromUtf8(err->message);
- g_error_free (err);
- g_free (debug);
- }
- break;
-#endif
- default:
- break;
- }
- } else if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ERROR) {
- GError *err;
- gchar *debug;
- gst_message_parse_error(gm, &err, &debug);
- QAudioDecoder::Error qerror = QAudioDecoder::ResourceError;
- if (err->domain == GST_STREAM_ERROR) {
- switch (err->code) {
- case GST_STREAM_ERROR_DECRYPT:
- case GST_STREAM_ERROR_DECRYPT_NOKEY:
- qerror = QAudioDecoder::AccessDeniedError;
- break;
- case GST_STREAM_ERROR_FORMAT:
- case GST_STREAM_ERROR_DEMUX:
- case GST_STREAM_ERROR_DECODE:
- case GST_STREAM_ERROR_WRONG_TYPE:
- case GST_STREAM_ERROR_TYPE_NOT_FOUND:
- case GST_STREAM_ERROR_CODEC_NOT_FOUND:
- qerror = QAudioDecoder::FormatError;
- break;
- default:
- break;
- }
- } else if (err->domain == GST_CORE_ERROR) {
- switch (err->code) {
- case GST_CORE_ERROR_MISSING_PLUGIN:
- qerror = QAudioDecoder::FormatError;
- break;
- default:
- break;
- }
- }
-
- processInvalidMedia(qerror, QString::fromUtf8(err->message));
- g_error_free(err);
- g_free(debug);
- }
- }
-
- return false;
-}
-
-QString QGstreamerAudioDecoderSession::sourceFilename() const
-{
- return mSource;
-}
-
-void QGstreamerAudioDecoderSession::setSourceFilename(const QString &fileName)
-{
- stop();
- mDevice = 0;
-#if QT_CONFIG(gstreamer_app)
- if (m_appSrc)
- m_appSrc->deleteLater();
- m_appSrc = 0;
-#endif
-
- bool isSignalRequired = (mSource != fileName);
- mSource = fileName;
- if (isSignalRequired)
- emit sourceChanged();
-}
-
-QIODevice *QGstreamerAudioDecoderSession::sourceDevice() const
-{
- return mDevice;
-}
-
-void QGstreamerAudioDecoderSession::setSourceDevice(QIODevice *device)
-{
- stop();
- mSource.clear();
- bool isSignalRequired = (mDevice != device);
- mDevice = device;
- if (isSignalRequired)
- emit sourceChanged();
-}
-
-void QGstreamerAudioDecoderSession::start()
-{
- if (!m_playbin) {
- processInvalidMedia(QAudioDecoder::ResourceError, "Playbin element is not valid");
- return;
- }
-
- addAppSink();
-
- if (!mSource.isEmpty()) {
- g_object_set(G_OBJECT(m_playbin), "uri", QUrl::fromLocalFile(mSource).toEncoded().constData(), NULL);
- } else if (mDevice) {
-#if QT_CONFIG(gstreamer_app)
- // make sure we can read from device
- if (!mDevice->isOpen() || !mDevice->isReadable()) {
- processInvalidMedia(QAudioDecoder::AccessDeniedError, "Unable to read from specified device");
- return;
- }
-
- if (!m_appSrc)
- m_appSrc = new QGstAppSrc(this);
- m_appSrc->setStream(mDevice);
-
- g_object_set(G_OBJECT(m_playbin), "uri", "appsrc://", NULL);
-#endif
- } else {
- return;
- }
-
- // Set audio format
- if (m_appSink) {
- if (mFormat.isValid()) {
- setAudioFlags(false);
- GstCaps *caps = QGstUtils::capsForAudioFormat(mFormat);
- gst_app_sink_set_caps(m_appSink, caps);
- gst_caps_unref(caps);
- } else {
- // We want whatever the native audio format is
- setAudioFlags(true);
- gst_app_sink_set_caps(m_appSink, NULL);
- }
- }
-
- m_pendingState = QAudioDecoder::DecodingState;
- if (gst_element_set_state(m_playbin, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
- qWarning() << "GStreamer; Unable to start decoding process";
- m_pendingState = m_state = QAudioDecoder::StoppedState;
-
- emit stateChanged(m_state);
- }
-}
-
-void QGstreamerAudioDecoderSession::stop()
-{
- if (m_playbin) {
- gst_element_set_state(m_playbin, GST_STATE_NULL);
- removeAppSink();
-
- QAudioDecoder::State oldState = m_state;
- m_pendingState = m_state = QAudioDecoder::StoppedState;
-
- // GStreamer thread is stopped. Can safely access m_buffersAvailable
- if (m_buffersAvailable != 0) {
- m_buffersAvailable = 0;
- emit bufferAvailableChanged(false);
- }
-
- if (m_position != -1) {
- m_position = -1;
- emit positionChanged(m_position);
- }
-
- if (m_duration != -1) {
- m_duration = -1;
- emit durationChanged(m_duration);
- }
-
- if (oldState != m_state)
- emit stateChanged(m_state);
- }
-}
-
-QAudioFormat QGstreamerAudioDecoderSession::audioFormat() const
-{
- return mFormat;
-}
-
-void QGstreamerAudioDecoderSession::setAudioFormat(const QAudioFormat &format)
-{
- if (mFormat != format) {
- mFormat = format;
- emit formatChanged(mFormat);
- }
-}
-
-QAudioBuffer QGstreamerAudioDecoderSession::read()
-{
- QAudioBuffer audioBuffer;
-
- int buffersAvailable;
- {
- QMutexLocker locker(&m_buffersMutex);
- buffersAvailable = m_buffersAvailable;
-
- // need to decrement before pulling a buffer
- // to make sure assert in QGstreamerAudioDecoderSession::new_buffer works
- m_buffersAvailable--;
- }
-
-
- if (buffersAvailable) {
- if (buffersAvailable == 1)
- emit bufferAvailableChanged(false);
-
- const char* bufferData = 0;
- int bufferSize = 0;
-
-#if GST_CHECK_VERSION(1,0,0)
- GstSample *sample = gst_app_sink_pull_sample(m_appSink);
- GstBuffer *buffer = gst_sample_get_buffer(sample);
- GstMapInfo mapInfo;
- gst_buffer_map(buffer, &mapInfo, GST_MAP_READ);
- bufferData = (const char*)mapInfo.data;
- bufferSize = mapInfo.size;
- QAudioFormat format = QGstUtils::audioFormatForSample(sample);
-#else
- GstBuffer *buffer = gst_app_sink_pull_buffer(m_appSink);
- bufferData = (const char*)buffer->data;
- bufferSize = buffer->size;
- QAudioFormat format = QGstUtils::audioFormatForBuffer(buffer);
-#endif
-
- if (format.isValid()) {
- // XXX At the moment we have to copy data from GstBuffer into QAudioBuffer.
- // We could improve performance by implementing QAbstractAudioBuffer for GstBuffer.
- qint64 position = getPositionFromBuffer(buffer);
- audioBuffer = QAudioBuffer(QByteArray((const char*)bufferData, bufferSize), format, position);
- position /= 1000; // convert to milliseconds
- if (position != m_position) {
- m_position = position;
- emit positionChanged(m_position);
- }
- }
-#if GST_CHECK_VERSION(1,0,0)
- gst_buffer_unmap(buffer, &mapInfo);
- gst_sample_unref(sample);
-#else
- gst_buffer_unref(buffer);
-#endif
- }
-
- return audioBuffer;
-}
-
-bool QGstreamerAudioDecoderSession::bufferAvailable() const
-{
- QMutexLocker locker(&m_buffersMutex);
- return m_buffersAvailable > 0;
-}
-
-qint64 QGstreamerAudioDecoderSession::position() const
-{
- return m_position;
-}
-
-qint64 QGstreamerAudioDecoderSession::duration() const
-{
- return m_duration;
-}
-
-void QGstreamerAudioDecoderSession::processInvalidMedia(QAudioDecoder::Error errorCode, const QString& errorString)
-{
- stop();
- emit error(int(errorCode), errorString);
-}
-
-GstFlowReturn QGstreamerAudioDecoderSession::new_sample(GstAppSink *, gpointer user_data)
-{
- // "Note that the preroll buffer will also be returned as the first buffer when calling gst_app_sink_pull_buffer()."
- QGstreamerAudioDecoderSession *session = reinterpret_cast<QGstreamerAudioDecoderSession*>(user_data);
-
- int buffersAvailable;
- {
- QMutexLocker locker(&session->m_buffersMutex);
- buffersAvailable = session->m_buffersAvailable;
- session->m_buffersAvailable++;
- Q_ASSERT(session->m_buffersAvailable <= MAX_BUFFERS_IN_QUEUE);
- }
-
- if (!buffersAvailable)
- QMetaObject::invokeMethod(session, "bufferAvailableChanged", Qt::QueuedConnection, Q_ARG(bool, true));
- QMetaObject::invokeMethod(session, "bufferReady", Qt::QueuedConnection);
- return GST_FLOW_OK;
-}
-
-void QGstreamerAudioDecoderSession::setAudioFlags(bool wantNativeAudio)
-{
- int flags = 0;
- if (m_playbin) {
- g_object_get(G_OBJECT(m_playbin), "flags", &flags, NULL);
- // make sure not to use GST_PLAY_FLAG_NATIVE_AUDIO unless desired
- // it prevents audio format conversion
- flags &= ~(GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_TEXT | GST_PLAY_FLAG_VIS | GST_PLAY_FLAG_NATIVE_AUDIO);
- flags |= GST_PLAY_FLAG_AUDIO;
- if (wantNativeAudio)
- flags |= GST_PLAY_FLAG_NATIVE_AUDIO;
- g_object_set(G_OBJECT(m_playbin), "flags", flags, NULL);
- }
-}
-
-void QGstreamerAudioDecoderSession::addAppSink()
-{
- if (m_appSink)
- return;
-
- m_appSink = (GstAppSink*)gst_element_factory_make("appsink", NULL);
-
- GstAppSinkCallbacks callbacks;
- memset(&callbacks, 0, sizeof(callbacks));
-#if GST_CHECK_VERSION(1,0,0)
- callbacks.new_sample = &new_sample;
-#else
- callbacks.new_buffer = &new_sample;
-#endif
- gst_app_sink_set_callbacks(m_appSink, &callbacks, this, NULL);
- gst_app_sink_set_max_buffers(m_appSink, MAX_BUFFERS_IN_QUEUE);
- gst_base_sink_set_sync(GST_BASE_SINK(m_appSink), FALSE);
-
- gst_bin_add(GST_BIN(m_outputBin), GST_ELEMENT(m_appSink));
- gst_element_link(m_audioConvert, GST_ELEMENT(m_appSink));
-}
-
-void QGstreamerAudioDecoderSession::removeAppSink()
-{
- if (!m_appSink)
- return;
-
- gst_element_unlink(m_audioConvert, GST_ELEMENT(m_appSink));
- gst_bin_remove(GST_BIN(m_outputBin), GST_ELEMENT(m_appSink));
-
- m_appSink = 0;
-}
-
-void QGstreamerAudioDecoderSession::updateDuration()
-{
- gint64 gstDuration = 0;
- int duration = -1;
-
- if (m_playbin && qt_gst_element_query_duration(m_playbin, GST_FORMAT_TIME, &gstDuration))
- duration = gstDuration / 1000000;
-
- if (m_duration != duration) {
- m_duration = duration;
- emit durationChanged(m_duration);
- }
-
- if (m_duration > 0)
- m_durationQueries = 0;
-
- if (m_durationQueries > 0) {
- //increase delay between duration requests
- int delay = 25 << (5 - m_durationQueries);
- QTimer::singleShot(delay, this, SLOT(updateDuration()));
- m_durationQueries--;
- }
-}
-
-qint64 QGstreamerAudioDecoderSession::getPositionFromBuffer(GstBuffer* buffer)
-{
- qint64 position = GST_BUFFER_TIMESTAMP(buffer);
- if (position >= 0)
- position = position / G_GINT64_CONSTANT(1000); // microseconds
- else
- position = -1;
- return position;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.h b/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.h
deleted file mode 100644
index 385908cbd..000000000
--- a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERPLAYERSESSION_H
-#define QGSTREAMERPLAYERSESSION_H
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <QObject>
-#include <QtCore/qmutex.h>
-#include "qgstreameraudiodecodercontrol.h"
-#include <private/qgstreamerbushelper_p.h>
-#include "qaudiodecoder.h"
-
-#if QT_CONFIG(gstreamer_app)
-#include <private/qgstappsrc_p.h>
-#endif
-
-#include <gst/gst.h>
-#include <gst/app/gstappsink.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerBusHelper;
-class QGstreamerMessage;
-
-class QGstreamerAudioDecoderSession : public QObject,
- public QGstreamerBusMessageFilter
-{
-Q_OBJECT
-Q_INTERFACES(QGstreamerBusMessageFilter)
-
-public:
- QGstreamerAudioDecoderSession(QObject *parent);
- virtual ~QGstreamerAudioDecoderSession();
-
- QGstreamerBusHelper *bus() const { return m_busHelper; }
-
- QAudioDecoder::State state() const { return m_state; }
- QAudioDecoder::State pendingState() const { return m_pendingState; }
-
- bool processBusMessage(const QGstreamerMessage &message) override;
-
-#if QT_CONFIG(gstreamer_app)
- QGstAppSrc *appsrc() const { return m_appSrc; }
- static void configureAppSrcElement(GObject*, GObject*, GParamSpec*,QGstreamerAudioDecoderSession* _this);
-#endif
-
- QString sourceFilename() const;
- void setSourceFilename(const QString &fileName);
-
- QIODevice* sourceDevice() const;
- void setSourceDevice(QIODevice *device);
-
- void start();
- void stop();
-
- QAudioFormat audioFormat() const;
- void setAudioFormat(const QAudioFormat &format);
-
- QAudioBuffer read();
- bool bufferAvailable() const;
-
- qint64 position() const;
- qint64 duration() const;
-
- static GstFlowReturn new_sample(GstAppSink *sink, gpointer user_data);
-
-signals:
- void stateChanged(QAudioDecoder::State newState);
- void formatChanged(const QAudioFormat &format);
- void sourceChanged();
-
- void error(int error, const QString &errorString);
-
- void bufferReady();
- void bufferAvailableChanged(bool available);
- void finished();
-
- void positionChanged(qint64 position);
- void durationChanged(qint64 duration);
-
-private slots:
- void updateDuration();
-
-private:
- void setAudioFlags(bool wantNativeAudio);
- void addAppSink();
- void removeAppSink();
-
- void processInvalidMedia(QAudioDecoder::Error errorCode, const QString& errorString);
- static qint64 getPositionFromBuffer(GstBuffer* buffer);
-
- QAudioDecoder::State m_state;
- QAudioDecoder::State m_pendingState;
- QGstreamerBusHelper *m_busHelper;
- GstBus *m_bus;
- GstElement *m_playbin;
- GstElement *m_outputBin;
- GstElement *m_audioConvert;
- GstAppSink *m_appSink;
-
-#if QT_CONFIG(gstreamer_app)
- QGstAppSrc *m_appSrc;
-#endif
-
- QString mSource;
- QIODevice *mDevice; // QWeakPointer perhaps
- QAudioFormat mFormat;
-
- mutable QMutex m_buffersMutex;
- int m_buffersAvailable;
-
- qint64 m_position;
- qint64 m_duration;
-
- int m_durationQueries;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERPLAYERSESSION_H
diff --git a/src/plugins/gstreamer/camerabin/camerabin.json b/src/plugins/gstreamer/camerabin/camerabin.json
deleted file mode 100644
index 3246b4683..000000000
--- a/src/plugins/gstreamer/camerabin/camerabin.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["gstreamercamerabin"],
- "Services": ["org.qt-project.qt.camera"]
-}
diff --git a/src/plugins/gstreamer/camerabin/camerabin.pro b/src/plugins/gstreamer/camerabin/camerabin.pro
deleted file mode 100644
index 183ddf2d4..000000000
--- a/src/plugins/gstreamer/camerabin/camerabin.pro
+++ /dev/null
@@ -1,85 +0,0 @@
-TARGET = gstcamerabin
-
-QT += multimedia-private
-
-include(../common.pri)
-
-INCLUDEPATH += $$PWD \
- $${SOURCE_DIR}/src/multimedia
-
-INCLUDEPATH += camerabin
-
-
-HEADERS += \
- $$PWD/camerabinserviceplugin.h \
- $$PWD/camerabinservice.h \
- $$PWD/camerabinsession.h \
- $$PWD/camerabincontrol.h \
- $$PWD/camerabinaudioencoder.h \
- $$PWD/camerabinimageencoder.h \
- $$PWD/camerabinrecorder.h \
- $$PWD/camerabincontainer.h \
- $$PWD/camerabinimagecapture.h \
- $$PWD/camerabinzoom.h \
- $$PWD/camerabinimageprocessing.h \
- $$PWD/camerabinmetadata.h \
- $$PWD/camerabinvideoencoder.h \
- $$PWD/camerabinresourcepolicy.h \
- $$PWD/camerabincapturedestination.h \
- $$PWD/camerabincapturebufferformat.h \
- $$PWD/camerabinviewfindersettings.h \
- $$PWD/camerabinviewfindersettings2.h \
- $$PWD/camerabininfocontrol.h
-
-SOURCES += \
- $$PWD/camerabinserviceplugin.cpp \
- $$PWD/camerabinservice.cpp \
- $$PWD/camerabinsession.cpp \
- $$PWD/camerabincontrol.cpp \
- $$PWD/camerabinaudioencoder.cpp \
- $$PWD/camerabincontainer.cpp \
- $$PWD/camerabinimagecapture.cpp \
- $$PWD/camerabinimageencoder.cpp \
- $$PWD/camerabinzoom.cpp \
- $$PWD/camerabinimageprocessing.cpp \
- $$PWD/camerabinmetadata.cpp \
- $$PWD/camerabinrecorder.cpp \
- $$PWD/camerabinvideoencoder.cpp \
- $$PWD/camerabinresourcepolicy.cpp \
- $$PWD/camerabincapturedestination.cpp \
- $$PWD/camerabinviewfindersettings.cpp \
- $$PWD/camerabinviewfindersettings2.cpp \
- $$PWD/camerabincapturebufferformat.cpp \
- $$PWD/camerabininfocontrol.cpp
-
-qtConfig(gstreamer_photography) {
- HEADERS += \
- $$PWD/camerabinfocus.h \
- $$PWD/camerabinexposure.h \
- $$PWD/camerabinflash.h \
- $$PWD/camerabinlocks.h
-
- SOURCES += \
- $$PWD/camerabinexposure.cpp \
- $$PWD/camerabinflash.cpp \
- $$PWD/camerabinfocus.cpp \
- $$PWD/camerabinlocks.cpp
-
- QMAKE_USE += gstreamer_photography
- DEFINES += GST_USE_UNSTABLE_API #prevents warnings because of unstable photography API
-}
-
-qtConfig(linux_v4l) {
- HEADERS += \
- $$PWD/camerabinv4limageprocessing.h
-
- SOURCES += \
- $$PWD/camerabinv4limageprocessing.cpp
-}
-
-OTHER_FILES += \
- camerabin.json
-
-PLUGIN_TYPE = mediaservice
-PLUGIN_CLASS_NAME = CameraBinServicePlugin
-load(qt_plugin)
diff --git a/src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp b/src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp
deleted file mode 100644
index e5e253194..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "camerabinaudioencoder.h"
-#include "camerabincontainer.h"
-#include <private/qgstutils_p.h>
-
-#include <QtCore/qdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-CameraBinAudioEncoder::CameraBinAudioEncoder(QObject *parent)
- :QAudioEncoderSettingsControl(parent)
-#if QT_CONFIG(gstreamer_encodingprofiles)
- , m_codecs(QGstCodecsInfo::AudioEncoder)
-#endif
-{
-}
-
-CameraBinAudioEncoder::~CameraBinAudioEncoder()
-{
-}
-
-QStringList CameraBinAudioEncoder::supportedAudioCodecs() const
-{
-#if QT_CONFIG(gstreamer_encodingprofiles)
- return m_codecs.supportedCodecs();
-#else
- return QStringList();
-#endif
-}
-
-QString CameraBinAudioEncoder::codecDescription(const QString &codecName) const
-{
-#if QT_CONFIG(gstreamer_encodingprofiles)
- return m_codecs.codecDescription(codecName);
-#else
- Q_UNUSED(codecName);
- return QString();
-#endif
-}
-
-QList<int> CameraBinAudioEncoder::supportedSampleRates(const QAudioEncoderSettings &, bool *) const
-{
- //TODO check element caps to find actual values
-
- return QList<int>();
-}
-
-QAudioEncoderSettings CameraBinAudioEncoder::audioSettings() const
-{
- return m_audioSettings;
-}
-
-void CameraBinAudioEncoder::setAudioSettings(const QAudioEncoderSettings &settings)
-{
- if (m_audioSettings != settings) {
- m_audioSettings = settings;
- m_actualAudioSettings = settings;
- emit settingsChanged();
- }
-}
-
-QAudioEncoderSettings CameraBinAudioEncoder::actualAudioSettings() const
-{
- return m_actualAudioSettings;
-}
-
-void CameraBinAudioEncoder::setActualAudioSettings(const QAudioEncoderSettings &settings)
-{
- m_actualAudioSettings = settings;
-}
-
-void CameraBinAudioEncoder::resetActualSettings()
-{
- m_actualAudioSettings = m_audioSettings;
-}
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
-
-GstEncodingProfile *CameraBinAudioEncoder::createProfile()
-{
- QString codec = m_actualAudioSettings.codec();
- QString preset = m_actualAudioSettings.encodingOption(QStringLiteral("preset")).toString();
- GstCaps *caps;
-
- if (codec.isEmpty())
- return 0;
- else
- caps = gst_caps_from_string(codec.toLatin1());
-
- GstEncodingProfile *profile = (GstEncodingProfile *)gst_encoding_audio_profile_new(
- caps,
- !preset.isEmpty() ? preset.toLatin1().constData() : NULL, //preset
- NULL, //restriction
- 0); //presence
-
- gst_caps_unref(caps);
-
- return profile;
-}
-
-#endif
-
-void CameraBinAudioEncoder::applySettings(GstElement *encoder)
-{
- GObjectClass * const objectClass = G_OBJECT_GET_CLASS(encoder);
- const char * const name = qt_gst_element_get_factory_name(encoder);
-
- const bool isVorbis = qstrcmp(name, "vorbisenc") == 0;
-
- const int bitRate = m_actualAudioSettings.bitRate();
- if (!isVorbis && bitRate == -1) {
- // Bit rate is invalid, don't evaluate the remaining conditions unless the encoder is
- // vorbisenc which is known to accept -1 as an unspecified bitrate.
- } else if (g_object_class_find_property(objectClass, "bitrate")) {
- g_object_set(G_OBJECT(encoder), "bitrate", bitRate, NULL);
- } else if (g_object_class_find_property(objectClass, "target-bitrate")) {
- g_object_set(G_OBJECT(encoder), "target-bitrate", bitRate, NULL);
- }
-
- if (isVorbis) {
- static const double qualities[] = { 0.1, 0.3, 0.5, 0.7, 1.0 };
- g_object_set(G_OBJECT(encoder), "quality", qualities[m_actualAudioSettings.quality()], NULL);
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinaudioencoder.h b/src/plugins/gstreamer/camerabin/camerabinaudioencoder.h
deleted file mode 100644
index b8091c8ca..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinaudioencoder.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINAUDIOENCODE_H
-#define CAMERABINAUDIOENCODE_H
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <qaudioencodersettingscontrol.h>
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmap.h>
-#include <QtCore/qset.h>
-
-#include <gst/gst.h>
-#include <gst/pbutils/pbutils.h>
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
-#include <gst/pbutils/encoding-profile.h>
-#include <private/qgstcodecsinfo_p.h>
-#endif
-
-#include <qaudioformat.h>
-
-QT_BEGIN_NAMESPACE
-class CameraBinSession;
-
-class CameraBinAudioEncoder : public QAudioEncoderSettingsControl
-{
- Q_OBJECT
-public:
- CameraBinAudioEncoder(QObject *parent);
- virtual ~CameraBinAudioEncoder();
-
- QStringList supportedAudioCodecs() const override;
- QString codecDescription(const QString &codecName) const override;
-
- QStringList supportedEncodingOptions(const QString &codec) const;
- QVariant encodingOption(const QString &codec, const QString &name) const;
- void setEncodingOption(const QString &codec, const QString &name, const QVariant &value);
-
- QList<int> supportedSampleRates(const QAudioEncoderSettings &settings = QAudioEncoderSettings(),
- bool *isContinuous = 0) const override;
- QList<int> supportedChannelCounts(const QAudioEncoderSettings &settings = QAudioEncoderSettings()) const;
- QList<int> supportedSampleSizes(const QAudioEncoderSettings &settings = QAudioEncoderSettings()) const;
-
- QAudioEncoderSettings audioSettings() const override;
- void setAudioSettings(const QAudioEncoderSettings &) override;
-
- QAudioEncoderSettings actualAudioSettings() const;
- void setActualAudioSettings(const QAudioEncoderSettings&);
- void resetActualSettings();
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
- GstEncodingProfile *createProfile();
-#endif
-
- void applySettings(GstElement *element);
-
-Q_SIGNALS:
- void settingsChanged();
-
-private:
-#if QT_CONFIG(gstreamer_encodingprofiles)
- QGstCodecsInfo m_codecs;
-#endif
-
- QAudioEncoderSettings m_actualAudioSettings;
- QAudioEncoderSettings m_audioSettings;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.cpp b/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.cpp
deleted file mode 100644
index 8b3e10546..000000000
--- a/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabincapturebufferformat.h"
-#include "camerabinsession.h"
-
-QT_BEGIN_NAMESPACE
-
-CameraBinCaptureBufferFormat::CameraBinCaptureBufferFormat(CameraBinSession *session)
- :QCameraCaptureBufferFormatControl(session)
- , m_session(session)
- , m_format(QVideoFrame::Format_Jpeg)
-{
-}
-
-CameraBinCaptureBufferFormat::~CameraBinCaptureBufferFormat()
-{
-}
-
-QList<QVideoFrame::PixelFormat> CameraBinCaptureBufferFormat::supportedBufferFormats() const
-{
- //the exact YUV format is unknown with camerabin until the first capture is requested
- return QList<QVideoFrame::PixelFormat>()
- << QVideoFrame::Format_Jpeg;
-}
-
-QVideoFrame::PixelFormat CameraBinCaptureBufferFormat::bufferFormat() const
-{
- return m_format;
-}
-
-void CameraBinCaptureBufferFormat::setBufferFormat(QVideoFrame::PixelFormat format)
-{
- if (m_format != format) {
- m_format = format;
- emit bufferFormatChanged(format);
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.h b/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.h
deleted file mode 100644
index 7051913a7..000000000
--- a/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINCAPTUREBUFFERFORMAT_H
-#define CAMERABINCAPTUREBUFFERFORMAT_H
-
-#include <qcamera.h>
-#include <qcameracapturebufferformatcontrol.h>
-
-#include <gst/gst.h>
-#include <glib.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-
-QT_USE_NAMESPACE
-
-class CameraBinCaptureBufferFormat : public QCameraCaptureBufferFormatControl
-{
- Q_OBJECT
-public:
- CameraBinCaptureBufferFormat(CameraBinSession *session);
- virtual ~CameraBinCaptureBufferFormat();
-
- QList<QVideoFrame::PixelFormat> supportedBufferFormats() const override;
-
- QVideoFrame::PixelFormat bufferFormat() const override;
- void setBufferFormat(QVideoFrame::PixelFormat format) override;
-
-private:
- CameraBinSession *m_session;
- QVideoFrame::PixelFormat m_format;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/camerabin/camerabincapturedestination.cpp b/src/plugins/gstreamer/camerabin/camerabincapturedestination.cpp
deleted file mode 100644
index 90ae81c86..000000000
--- a/src/plugins/gstreamer/camerabin/camerabincapturedestination.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabincapturedestination.h"
-#include "camerabinsession.h"
-
-QT_BEGIN_NAMESPACE
-
-CameraBinCaptureDestination::CameraBinCaptureDestination(CameraBinSession *session)
- :QCameraCaptureDestinationControl(session)
- , m_session(session)
- , m_destination(QCameraImageCapture::CaptureToFile)
-{
-}
-
-CameraBinCaptureDestination::~CameraBinCaptureDestination()
-{
-}
-
-
-bool CameraBinCaptureDestination::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const
-{
- //capture to buffer, file and both are supported.
- return destination & (QCameraImageCapture::CaptureToFile | QCameraImageCapture::CaptureToBuffer);
-}
-
-QCameraImageCapture::CaptureDestinations CameraBinCaptureDestination::captureDestination() const
-{
- return m_destination;
-}
-
-void CameraBinCaptureDestination::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination)
-{
- if (m_destination != destination) {
- m_destination = destination;
- emit captureDestinationChanged(m_destination);
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabincapturedestination.h b/src/plugins/gstreamer/camerabin/camerabincapturedestination.h
deleted file mode 100644
index bc24a23d8..000000000
--- a/src/plugins/gstreamer/camerabin/camerabincapturedestination.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINCAPTUREDESTINATION_H
-#define CAMERABINCAPTUREDESTINATION_H
-
-#include <qcameraimagecapture.h>
-#include <qcameracapturedestinationcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-
-QT_USE_NAMESPACE
-
-class CameraBinCaptureDestination : public QCameraCaptureDestinationControl
-{
- Q_OBJECT
-public:
- CameraBinCaptureDestination(CameraBinSession *session);
- virtual ~CameraBinCaptureDestination();
-
- bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const override;
- QCameraImageCapture::CaptureDestinations captureDestination() const override;
- void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) override;
-
-private:
- CameraBinSession *m_session;
- QCameraImageCapture::CaptureDestinations m_destination;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINFLASHCONTROL_H
diff --git a/src/plugins/gstreamer/camerabin/camerabincontainer.cpp b/src/plugins/gstreamer/camerabin/camerabincontainer.cpp
deleted file mode 100644
index 0de9b25d8..000000000
--- a/src/plugins/gstreamer/camerabin/camerabincontainer.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "camerabincontainer.h"
-#include <private/qgstutils_p.h>
-
-#include <QtCore/qdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-CameraBinContainer::CameraBinContainer(QObject *parent)
- :QMediaContainerControl(parent)
-#if QT_CONFIG(gstreamer_encodingprofiles)
- , m_supportedContainers(QGstCodecsInfo::Muxer)
-#endif
-{
-}
-
-QStringList CameraBinContainer::supportedContainers() const
-{
-#if QT_CONFIG(gstreamer_encodingprofiles)
- return m_supportedContainers.supportedCodecs();
-#else
- return QStringList();
-#endif
-}
-
-QString CameraBinContainer::containerDescription(const QString &formatMimeType) const
-{
-#if QT_CONFIG(gstreamer_encodingprofiles)
- return m_supportedContainers.codecDescription(formatMimeType);
-#else
- Q_UNUSED(formatMimeType);
- return QString();
-#endif
-}
-
-QString CameraBinContainer::containerFormat() const
-{
- return m_format;
-}
-
-void CameraBinContainer::setContainerFormat(const QString &format)
-{
-#if QT_CONFIG(gstreamer_encodingprofiles)
- if (m_format != format) {
- m_format = format;
- m_actualFormat = format;
- emit settingsChanged();
- }
-#endif
-}
-
-QString CameraBinContainer::actualContainerFormat() const
-{
- return m_actualFormat;
-}
-
-void CameraBinContainer::setActualContainerFormat(const QString &containerFormat)
-{
-#if QT_CONFIG(gstreamer_encodingprofiles)
- m_actualFormat = containerFormat;
-#endif
-}
-
-void CameraBinContainer::resetActualContainerFormat()
-{
- m_actualFormat = m_format;
-}
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
-
-GstEncodingContainerProfile *CameraBinContainer::createProfile()
-{
- GstCaps *caps = nullptr;
-
- if (m_actualFormat.isEmpty()) {
- return 0;
- } else {
- QString format = m_actualFormat;
- const QStringList supportedFormats = m_supportedContainers.supportedCodecs();
-
- //if format is not in the list of supported gstreamer mime types,
- //try to find the mime type with matching extension
- if (!supportedFormats.contains(format)) {
- format.clear();
- QString extension = QGstUtils::fileExtensionForMimeType(m_actualFormat);
- for (const QString &formatCandidate : supportedFormats) {
- if (QGstUtils::fileExtensionForMimeType(formatCandidate) == extension) {
- format = formatCandidate;
- break;
- }
- }
- }
-
- if (format.isEmpty())
- return nullptr;
-
- caps = gst_caps_from_string(format.toLatin1());
- }
-
- GstEncodingContainerProfile *profile = (GstEncodingContainerProfile *)gst_encoding_container_profile_new(
- "camerabin2_profile",
- (gchar *)"custom camera profile",
- caps,
- NULL); //preset
-
- gst_caps_unref(caps);
-
- return profile;
-}
-
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabincontainer.h b/src/plugins/gstreamer/camerabin/camerabincontainer.h
deleted file mode 100644
index 738e55e2a..000000000
--- a/src/plugins/gstreamer/camerabin/camerabincontainer.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef CAMERABINMEDIACONTAINERCONTROL_H
-#define CAMERABINMEDIACONTAINERCONTROL_H
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <qmediacontainercontrol.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qset.h>
-
-#include <gst/gst.h>
-#include <gst/pbutils/pbutils.h>
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
-#include <gst/pbutils/encoding-profile.h>
-#include <private/qgstcodecsinfo_p.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinContainer : public QMediaContainerControl
-{
-Q_OBJECT
-public:
- CameraBinContainer(QObject *parent);
- virtual ~CameraBinContainer() {}
-
- QStringList supportedContainers() const override;
- QString containerDescription(const QString &formatMimeType) const override;
-
- QString containerFormat() const override;
- void setContainerFormat(const QString &format) override;
-
- QString actualContainerFormat() const;
- void setActualContainerFormat(const QString &containerFormat);
- void resetActualContainerFormat();
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
- GstEncodingContainerProfile *createProfile();
-#endif
-
-Q_SIGNALS:
- void settingsChanged();
-
-private:
- QString m_format;
- QString m_actualFormat;
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
- QGstCodecsInfo m_supportedContainers;
-#endif
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINMEDIACONTAINERCONTROL_H
diff --git a/src/plugins/gstreamer/camerabin/camerabincontrol.cpp b/src/plugins/gstreamer/camerabin/camerabincontrol.cpp
deleted file mode 100644
index 155887054..000000000
--- a/src/plugins/gstreamer/camerabin/camerabincontrol.cpp
+++ /dev/null
@@ -1,309 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "camerabincontrol.h"
-#include "camerabincontainer.h"
-#include "camerabinaudioencoder.h"
-#include "camerabinvideoencoder.h"
-#include "camerabinimageencoder.h"
-#include "camerabinresourcepolicy.h"
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qfile.h>
-#include <QtCore/qmetaobject.h>
-
-QT_BEGIN_NAMESPACE
-
-//#define CAMEABIN_DEBUG 1
-#define ENUM_NAME(c,e,v) (c::staticMetaObject.enumerator(c::staticMetaObject.indexOfEnumerator(e)).valueToKey((v)))
-
-CameraBinControl::CameraBinControl(CameraBinSession *session)
- :QCameraControl(session),
- m_session(session),
- m_state(QCamera::UnloadedState),
- m_reloadPending(false)
-{
- connect(m_session, SIGNAL(statusChanged(QCamera::Status)),
- this, SIGNAL(statusChanged(QCamera::Status)));
-
- connect(m_session, SIGNAL(viewfinderChanged()),
- SLOT(reloadLater()));
- connect(m_session, SIGNAL(readyChanged(bool)),
- SLOT(reloadLater()));
- connect(m_session, SIGNAL(error(int,QString)),
- SLOT(handleCameraError(int,QString)));
-
- m_resourcePolicy = new CamerabinResourcePolicy(this);
- connect(m_resourcePolicy, SIGNAL(resourcesGranted()),
- SLOT(handleResourcesGranted()));
- connect(m_resourcePolicy, SIGNAL(resourcesDenied()),
- SLOT(handleResourcesLost()));
- connect(m_resourcePolicy, SIGNAL(resourcesLost()),
- SLOT(handleResourcesLost()));
-
- connect(m_session, SIGNAL(busyChanged(bool)),
- SLOT(handleBusyChanged(bool)));
-}
-
-CameraBinControl::~CameraBinControl()
-{
-}
-
-QCamera::CaptureModes CameraBinControl::captureMode() const
-{
- return m_session->captureMode();
-}
-
-void CameraBinControl::setCaptureMode(QCamera::CaptureModes mode)
-{
- if (m_session->captureMode() != mode) {
- m_session->setCaptureMode(mode);
-
- if (m_state == QCamera::ActiveState) {
- m_resourcePolicy->setResourceSet(
- captureMode() == QCamera::CaptureStillImage ?
- CamerabinResourcePolicy::ImageCaptureResources :
- CamerabinResourcePolicy::VideoCaptureResources);
- }
- emit captureModeChanged(mode);
- }
-}
-
-bool CameraBinControl::isCaptureModeSupported(QCamera::CaptureModes mode) const
-{
- return mode == QCamera::CaptureStillImage || mode == QCamera::CaptureVideo;
-}
-
-void CameraBinControl::setState(QCamera::State state)
-{
-#ifdef CAMEABIN_DEBUG
- qDebug() << Q_FUNC_INFO << ENUM_NAME(QCamera, "State", state);
-#endif
- if (m_state != state) {
- m_state = state;
-
- //special case for stopping the camera while it's busy,
- //it should be delayed until the camera is idle
- if ((state == QCamera::LoadedState || state == QCamera::UnloadedState) &&
- m_session->status() == QCamera::ActiveStatus &&
- m_session->isBusy()) {
-#ifdef CAMEABIN_DEBUG
- qDebug() << Q_FUNC_INFO << "Camera is busy,"
- << state == QCamera::LoadedState ? "QCamera::stop()" : "QCamera::unload()"
- << "is delayed";
-#endif
- emit stateChanged(m_state);
- return;
- }
-
- CamerabinResourcePolicy::ResourceSet resourceSet = CamerabinResourcePolicy::NoResources;
- switch (state) {
- case QCamera::UnloadedState:
- resourceSet = CamerabinResourcePolicy::NoResources;
- break;
- case QCamera::LoadedState:
- resourceSet = CamerabinResourcePolicy::LoadedResources;
- break;
- case QCamera::ActiveState:
- resourceSet = captureMode() == QCamera::CaptureStillImage ?
- CamerabinResourcePolicy::ImageCaptureResources :
- CamerabinResourcePolicy::VideoCaptureResources;
- break;
- }
-
- m_resourcePolicy->setResourceSet(resourceSet);
-
- if (m_resourcePolicy->isResourcesGranted()) {
- //postpone changing to Active if the session is nor ready yet
- if (state == QCamera::ActiveState) {
- if (m_session->isReady()) {
- m_session->setState(state);
- } else {
-#ifdef CAMEABIN_DEBUG
- qDebug() << "Camera session is not ready yet, postpone activating";
-#endif
- }
- } else
- m_session->setState(state);
- }
-
- emit stateChanged(m_state);
- }
-}
-
-QCamera::State CameraBinControl::state() const
-{
- return m_state;
-}
-
-QCamera::Status CameraBinControl::status() const
-{
- return m_session->status();
-}
-
-void CameraBinControl::reloadLater()
-{
-#ifdef CAMEABIN_DEBUG
- qDebug() << "CameraBinControl: reload pipeline requested" << ENUM_NAME(QCamera, "State", m_state);
-#endif
- if (!m_reloadPending && m_state == QCamera::ActiveState) {
- m_reloadPending = true;
-
- if (!m_session->isBusy()) {
- m_session->setState(QCamera::LoadedState);
- QMetaObject::invokeMethod(this, "delayedReload", Qt::QueuedConnection);
- }
- }
-}
-
-void CameraBinControl::handleResourcesLost()
-{
-#ifdef CAMEABIN_DEBUG
- qDebug() << Q_FUNC_INFO << ENUM_NAME(QCamera, "State", m_state);
-#endif
- m_session->setState(QCamera::UnloadedState);
-}
-
-void CameraBinControl::handleResourcesGranted()
-{
-#ifdef CAMEABIN_DEBUG
- qDebug() << Q_FUNC_INFO << ENUM_NAME(QCamera, "State", m_state);
-#endif
-
- //camera will be started soon by delayedReload()
- if (m_reloadPending && m_state == QCamera::ActiveState)
- return;
-
- if (m_state == QCamera::ActiveState && m_session->isReady())
- m_session->setState(QCamera::ActiveState);
- else if (m_state == QCamera::LoadedState)
- m_session->setState(QCamera::LoadedState);
-}
-
-void CameraBinControl::handleBusyChanged(bool busy)
-{
- if (!busy && m_session->status() == QCamera::ActiveStatus) {
- if (m_state != QCamera::ActiveState) {
- //handle delayed stop()/unload() because of busy camera
-
- CamerabinResourcePolicy::ResourceSet resourceSet = CamerabinResourcePolicy::NoResources;
- switch (m_state) {
- case QCamera::UnloadedState:
- resourceSet = CamerabinResourcePolicy::NoResources;
- break;
- case QCamera::LoadedState:
- resourceSet = CamerabinResourcePolicy::LoadedResources;
- break;
- default:
- Q_ASSERT(false);
- break;
- }
-
- m_resourcePolicy->setResourceSet(resourceSet);
- m_session->setState(m_state);
- } else if (m_reloadPending) {
- //handle delayed reload because of busy camera
- m_session->setState(QCamera::LoadedState);
- QMetaObject::invokeMethod(this, "delayedReload", Qt::QueuedConnection);
- }
- }
-}
-
-void CameraBinControl::handleCameraError(int errorCode, const QString &errorString)
-{
- emit error(errorCode, errorString);
- setState(QCamera::UnloadedState);
-}
-
-void CameraBinControl::delayedReload()
-{
-#ifdef CAMEABIN_DEBUG
- qDebug() << "CameraBinControl: reload pipeline";
-#endif
- if (m_reloadPending) {
- m_reloadPending = false;
- if (m_state == QCamera::ActiveState &&
- m_session->isReady() &&
- m_resourcePolicy->isResourcesGranted()) {
- m_session->setState(QCamera::ActiveState);
- }
- }
-}
-
-bool CameraBinControl::canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const
-{
- Q_UNUSED(status);
-
- switch (changeType) {
- case QCameraControl::Viewfinder:
- return true;
- case QCameraControl::CaptureMode:
- case QCameraControl::ImageEncodingSettings:
- case QCameraControl::VideoEncodingSettings:
- case QCameraControl::ViewfinderSettings:
- default:
- return status != QCamera::ActiveStatus;
- }
-}
-
-#define VIEWFINDER_COLORSPACE_CONVERSION 0x00000004
-
-bool CameraBinControl::viewfinderColorSpaceConversion() const
-{
- gint flags = 0;
- g_object_get(G_OBJECT(m_session->cameraBin()), "flags", &flags, NULL);
-
- return flags & VIEWFINDER_COLORSPACE_CONVERSION;
-}
-
-void CameraBinControl::setViewfinderColorSpaceConversion(bool enabled)
-{
- gint flags = 0;
- g_object_get(G_OBJECT(m_session->cameraBin()), "flags", &flags, NULL);
-
- if (enabled)
- flags |= VIEWFINDER_COLORSPACE_CONVERSION;
- else
- flags &= ~VIEWFINDER_COLORSPACE_CONVERSION;
-
- g_object_set(G_OBJECT(m_session->cameraBin()), "flags", flags, NULL);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabincontrol.h b/src/plugins/gstreamer/camerabin/camerabincontrol.h
deleted file mode 100644
index 56c02dad4..000000000
--- a/src/plugins/gstreamer/camerabin/camerabincontrol.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef CAMERABINCONTROL_H
-#define CAMERABINCONTROL_H
-
-#include <QHash>
-#include <qcameracontrol.h>
-#include "camerabinsession.h"
-
-QT_BEGIN_NAMESPACE
-
-class CamerabinResourcePolicy;
-
-class CameraBinControl : public QCameraControl
-{
- Q_OBJECT
- Q_PROPERTY(bool viewfinderColorSpaceConversion READ viewfinderColorSpaceConversion WRITE setViewfinderColorSpaceConversion)
-public:
- CameraBinControl( CameraBinSession *session );
- virtual ~CameraBinControl();
-
- bool isValid() const { return true; }
-
- QCamera::State state() const override;
- void setState(QCamera::State state) override;
-
- QCamera::Status status() const override;
-
- QCamera::CaptureModes captureMode() const override;
- void setCaptureMode(QCamera::CaptureModes mode) override;
-
- bool isCaptureModeSupported(QCamera::CaptureModes mode) const override;
- bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const override;
- bool viewfinderColorSpaceConversion() const;
-
- CamerabinResourcePolicy *resourcePolicy() { return m_resourcePolicy; }
-
-public slots:
- void reloadLater();
- void setViewfinderColorSpaceConversion(bool enabled);
-
-private slots:
- void delayedReload();
-
- void handleResourcesGranted();
- void handleResourcesLost();
-
- void handleBusyChanged(bool);
- void handleCameraError(int error, const QString &errorString);
-
-private:
- void updateSupportedResolutions(const QString &device);
-
- CameraBinSession *m_session;
- QCamera::State m_state;
- CamerabinResourcePolicy *m_resourcePolicy;
-
- bool m_reloadPending;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINCONTROL_H
diff --git a/src/plugins/gstreamer/camerabin/camerabinexposure.cpp b/src/plugins/gstreamer/camerabin/camerabinexposure.cpp
deleted file mode 100644
index 35d3e7c8f..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinexposure.cpp
+++ /dev/null
@@ -1,285 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabinexposure.h"
-#include "camerabinsession.h"
-#include <gst/interfaces/photography.h>
-
-#include <QDebug>
-
-#if !GST_CHECK_VERSION(1,0,0)
-typedef GstSceneMode GstPhotographySceneMode;
-#endif
-
-QT_BEGIN_NAMESPACE
-
-CameraBinExposure::CameraBinExposure(CameraBinSession *session)
- :QCameraExposureControl(session),
- m_session(session)
-{
-}
-
-CameraBinExposure::~CameraBinExposure()
-{
-}
-
-bool CameraBinExposure::isParameterSupported(ExposureParameter parameter) const
-{
- switch (parameter) {
- case QCameraExposureControl::ExposureCompensation:
- case QCameraExposureControl::ISO:
- case QCameraExposureControl::Aperture:
- case QCameraExposureControl::ShutterSpeed:
- return true;
- default:
- return false;
- }
-}
-
-QVariantList CameraBinExposure::supportedParameterRange(ExposureParameter parameter,
- bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- QVariantList res;
- switch (parameter) {
- case QCameraExposureControl::ExposureCompensation:
- if (continuous)
- *continuous = true;
- res << -2.0 << 2.0;
- break;
- case QCameraExposureControl::ISO:
- res << 100 << 200 << 400;
- break;
- case QCameraExposureControl::Aperture:
- res << 2.8;
- break;
- default:
- break;
- }
-
- return res;
-}
-
-QVariant CameraBinExposure::requestedValue(ExposureParameter parameter) const
-{
- return m_requestedValues.value(parameter);
-}
-
-QVariant CameraBinExposure::actualValue(ExposureParameter parameter) const
-{
- switch (parameter) {
- case QCameraExposureControl::ExposureCompensation:
- {
- gfloat ev;
- gst_photography_get_ev_compensation(m_session->photography(), &ev);
- return QVariant(ev);
- }
- case QCameraExposureControl::ISO:
- {
- guint isoSpeed = 0;
- gst_photography_get_iso_speed(m_session->photography(), &isoSpeed);
- return QVariant(isoSpeed);
- }
- case QCameraExposureControl::Aperture:
- return QVariant(2.8);
- case QCameraExposureControl::ShutterSpeed:
- {
- guint32 shutterSpeed = 0;
- gst_photography_get_exposure(m_session->photography(), &shutterSpeed);
-
- return QVariant(shutterSpeed/1000000.0);
- }
- case QCameraExposureControl::ExposureMode:
- {
- GstPhotographySceneMode sceneMode;
- gst_photography_get_scene_mode(m_session->photography(), &sceneMode);
-
- switch (sceneMode) {
- case GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT:
- return QVariant::fromValue(QCameraExposure::ExposurePortrait);
- case GST_PHOTOGRAPHY_SCENE_MODE_SPORT:
- return QVariant::fromValue(QCameraExposure::ExposureSports);
- case GST_PHOTOGRAPHY_SCENE_MODE_NIGHT:
- return QVariant::fromValue(QCameraExposure::ExposureNight);
- case GST_PHOTOGRAPHY_SCENE_MODE_MANUAL:
- return QVariant::fromValue(QCameraExposure::ExposureManual);
- case GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE:
- return QVariant::fromValue(QCameraExposure::ExposureLandscape);
-#if GST_CHECK_VERSION(1, 2, 0)
- case GST_PHOTOGRAPHY_SCENE_MODE_SNOW:
- return QVariant::fromValue(QCameraExposure::ExposureSnow);
- case GST_PHOTOGRAPHY_SCENE_MODE_BEACH:
- return QVariant::fromValue(QCameraExposure::ExposureBeach);
- case GST_PHOTOGRAPHY_SCENE_MODE_ACTION:
- return QVariant::fromValue(QCameraExposure::ExposureAction);
- case GST_PHOTOGRAPHY_SCENE_MODE_NIGHT_PORTRAIT:
- return QVariant::fromValue(QCameraExposure::ExposureNightPortrait);
- case GST_PHOTOGRAPHY_SCENE_MODE_THEATRE:
- return QVariant::fromValue(QCameraExposure::ExposureTheatre);
- case GST_PHOTOGRAPHY_SCENE_MODE_SUNSET:
- return QVariant::fromValue(QCameraExposure::ExposureSunset);
- case GST_PHOTOGRAPHY_SCENE_MODE_STEADY_PHOTO:
- return QVariant::fromValue(QCameraExposure::ExposureSteadyPhoto);
- case GST_PHOTOGRAPHY_SCENE_MODE_FIREWORKS:
- return QVariant::fromValue(QCameraExposure::ExposureFireworks);
- case GST_PHOTOGRAPHY_SCENE_MODE_PARTY:
- return QVariant::fromValue(QCameraExposure::ExposureParty);
- case GST_PHOTOGRAPHY_SCENE_MODE_CANDLELIGHT:
- return QVariant::fromValue(QCameraExposure::ExposureCandlelight);
- case GST_PHOTOGRAPHY_SCENE_MODE_BARCODE:
- return QVariant::fromValue(QCameraExposure::ExposureBarcode);
-#endif
- //no direct mapping available so mapping to auto mode
- case GST_PHOTOGRAPHY_SCENE_MODE_CLOSEUP:
- case GST_PHOTOGRAPHY_SCENE_MODE_AUTO:
- default:
- return QVariant::fromValue(QCameraExposure::ExposureAuto);
- }
- }
- case QCameraExposureControl::MeteringMode:
- return QCameraExposure::MeteringMatrix;
- default:
- return QVariant();
- }
-}
-
-bool CameraBinExposure::setValue(ExposureParameter parameter, const QVariant& value)
-{
- QVariant oldValue = actualValue(parameter);
-
- switch (parameter) {
- case QCameraExposureControl::ExposureCompensation:
- gst_photography_set_ev_compensation(m_session->photography(), value.toReal());
- break;
- case QCameraExposureControl::ISO:
- gst_photography_set_iso_speed(m_session->photography(), value.toInt());
- break;
- case QCameraExposureControl::Aperture:
- gst_photography_set_aperture(m_session->photography(), guint(value.toReal()*1000000));
- break;
- case QCameraExposureControl::ShutterSpeed:
- gst_photography_set_exposure(m_session->photography(), guint(value.toReal()*1000000));
- break;
- case QCameraExposureControl::ExposureMode:
- {
- QCameraExposure::ExposureMode mode = value.value<QCameraExposure::ExposureMode>();
- GstPhotographySceneMode sceneMode;
-
- gst_photography_get_scene_mode(m_session->photography(), &sceneMode);
-
- switch (mode) {
- case QCameraExposure::ExposureManual:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_MANUAL;
- break;
- case QCameraExposure::ExposurePortrait:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT;
- break;
- case QCameraExposure::ExposureSports:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SPORT;
- break;
- case QCameraExposure::ExposureNight:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_NIGHT;
- break;
- case QCameraExposure::ExposureAuto:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_AUTO;
- break;
- case QCameraExposure::ExposureLandscape:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE;
- break;
-#if GST_CHECK_VERSION(1, 2, 0)
- case QCameraExposure::ExposureSnow:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SNOW;
- break;
- case QCameraExposure::ExposureBeach:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_BEACH;
- break;
- case QCameraExposure::ExposureAction:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_ACTION;
- break;
- case QCameraExposure::ExposureNightPortrait:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_NIGHT_PORTRAIT;
- break;
- case QCameraExposure::ExposureTheatre:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_THEATRE;
- break;
- case QCameraExposure::ExposureSunset:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SUNSET;
- break;
- case QCameraExposure::ExposureSteadyPhoto:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_STEADY_PHOTO;
- break;
- case QCameraExposure::ExposureFireworks:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_FIREWORKS;
- break;
- case QCameraExposure::ExposureParty:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_PARTY;
- break;
- case QCameraExposure::ExposureCandlelight:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_CANDLELIGHT;
- break;
- case QCameraExposure::ExposureBarcode:
- sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_BARCODE;
- break;
-#endif
- default:
- break;
- }
-
- gst_photography_set_scene_mode(m_session->photography(), sceneMode);
- break;
- }
- default:
- return false;
- }
-
- if (!qFuzzyCompare(m_requestedValues.value(parameter).toReal(), value.toReal())) {
- m_requestedValues[parameter] = value;
- emit requestedValueChanged(parameter);
- }
-
- QVariant newValue = actualValue(parameter);
- if (!qFuzzyCompare(oldValue.toReal(), newValue.toReal()))
- emit actualValueChanged(parameter);
-
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinexposure.h b/src/plugins/gstreamer/camerabin/camerabinexposure.h
deleted file mode 100644
index db16bed24..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinexposure.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINEXPOSURECONTROL_H
-#define CAMERABINEXPOSURECONTROL_H
-
-#include <qcamera.h>
-#include <qcameraexposurecontrol.h>
-
-#include <gst/gst.h>
-#include <glib.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-
-class CameraBinExposure : public QCameraExposureControl
-{
- Q_OBJECT
-
-public:
- CameraBinExposure(CameraBinSession *session);
- virtual ~CameraBinExposure();
-
- bool isParameterSupported(ExposureParameter parameter) const override;
- QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const override;
-
- QVariant requestedValue(ExposureParameter parameter) const override;
- QVariant actualValue(ExposureParameter parameter) const override;
- bool setValue(ExposureParameter parameter, const QVariant &value) override;
-
-private:
- CameraBinSession *m_session;
- QHash<ExposureParameter, QVariant> m_requestedValues;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINEXPOSURECONTROL_H
diff --git a/src/plugins/gstreamer/camerabin/camerabinflash.cpp b/src/plugins/gstreamer/camerabin/camerabinflash.cpp
deleted file mode 100644
index 2bf7a2776..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinflash.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabinflash.h"
-#include "camerabinsession.h"
-#include <gst/interfaces/photography.h>
-
-#include <QDebug>
-
-#if !GST_CHECK_VERSION(1,0,0)
-typedef GstFlashMode GstPhotographyFlashMode;
-#endif
-
-QT_BEGIN_NAMESPACE
-
-CameraBinFlash::CameraBinFlash(CameraBinSession *session)
- :QCameraFlashControl(session),
- m_session(session)
-{
-}
-
-CameraBinFlash::~CameraBinFlash()
-{
-}
-
-QCameraExposure::FlashModes CameraBinFlash::flashMode() const
-{
- GstPhotographyFlashMode flashMode;
- gst_photography_get_flash_mode(m_session->photography(), &flashMode);
-
- QCameraExposure::FlashModes modes;
- switch (flashMode) {
- case GST_PHOTOGRAPHY_FLASH_MODE_AUTO: modes |= QCameraExposure::FlashAuto; break;
- case GST_PHOTOGRAPHY_FLASH_MODE_OFF: modes |= QCameraExposure::FlashOff; break;
- case GST_PHOTOGRAPHY_FLASH_MODE_ON: modes |= QCameraExposure::FlashOn; break;
- case GST_PHOTOGRAPHY_FLASH_MODE_FILL_IN: modes |= QCameraExposure::FlashFill; break;
- case GST_PHOTOGRAPHY_FLASH_MODE_RED_EYE: modes |= QCameraExposure::FlashRedEyeReduction; break;
- default:
- modes |= QCameraExposure::FlashAuto;
- break;
- }
- return modes;
-}
-
-void CameraBinFlash::setFlashMode(QCameraExposure::FlashModes mode)
-{
- GstPhotographyFlashMode flashMode;
- gst_photography_get_flash_mode(m_session->photography(), &flashMode);
-
- if (mode.testFlag(QCameraExposure::FlashAuto)) flashMode = GST_PHOTOGRAPHY_FLASH_MODE_AUTO;
- else if (mode.testFlag(QCameraExposure::FlashOff)) flashMode = GST_PHOTOGRAPHY_FLASH_MODE_OFF;
- else if (mode.testFlag(QCameraExposure::FlashOn)) flashMode = GST_PHOTOGRAPHY_FLASH_MODE_ON;
- else if (mode.testFlag(QCameraExposure::FlashFill)) flashMode = GST_PHOTOGRAPHY_FLASH_MODE_FILL_IN;
- else if (mode.testFlag(QCameraExposure::FlashRedEyeReduction)) flashMode = GST_PHOTOGRAPHY_FLASH_MODE_RED_EYE;
-
- gst_photography_set_flash_mode(m_session->photography(), flashMode);
-}
-
-bool CameraBinFlash::isFlashModeSupported(QCameraExposure::FlashModes mode) const
-{
- return mode == QCameraExposure::FlashOff ||
- mode == QCameraExposure::FlashOn ||
- mode == QCameraExposure::FlashAuto ||
- mode == QCameraExposure::FlashRedEyeReduction ||
- mode == QCameraExposure::FlashFill;
-}
-
-bool CameraBinFlash::isFlashReady() const
-{
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinflash.h b/src/plugins/gstreamer/camerabin/camerabinflash.h
deleted file mode 100644
index 0efd100a7..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinflash.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINFLASHCONTROL_H
-#define CAMERABINFLASHCONTROL_H
-
-#include <qcamera.h>
-#include <qcameraflashcontrol.h>
-
-#include <gst/gst.h>
-#include <glib.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-
-class CameraBinFlash : public QCameraFlashControl
-{
- Q_OBJECT
-public:
- CameraBinFlash(CameraBinSession *session);
- virtual ~CameraBinFlash();
-
- QCameraExposure::FlashModes flashMode() const override;
- void setFlashMode(QCameraExposure::FlashModes mode) override;
- bool isFlashModeSupported(QCameraExposure::FlashModes mode) const override;
-
- bool isFlashReady() const override;
-
-private:
- CameraBinSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINFLASHCONTROL_H
-
diff --git a/src/plugins/gstreamer/camerabin/camerabinfocus.cpp b/src/plugins/gstreamer/camerabin/camerabinfocus.cpp
deleted file mode 100644
index 33ac7e3d7..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinfocus.cpp
+++ /dev/null
@@ -1,540 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabinfocus.h"
-#include "camerabinsession.h"
-
-#include <gst/interfaces/photography.h>
-
-#include <QDebug>
-#include <QtCore/qcoreevent.h>
-#include <QtCore/qmetaobject.h>
-
-#include <private/qgstutils_p.h>
-
-#if !GST_CHECK_VERSION(1,0,0)
-typedef GstFocusMode GstPhotographyFocusMode;
-#endif
-
-//#define CAMERABIN_DEBUG 1
-
-QT_BEGIN_NAMESPACE
-
-CameraBinFocus::CameraBinFocus(CameraBinSession *session)
- :QCameraFocusControl(session),
-#if GST_CHECK_VERSION(1,0,0)
- QGstreamerBufferProbe(ProbeBuffers),
-#endif
- m_session(session),
- m_cameraStatus(QCamera::UnloadedStatus),
- m_focusMode(QCameraFocus::AutoFocus),
- m_focusPointMode(QCameraFocus::FocusPointAuto),
- m_focusStatus(QCamera::Unlocked),
- m_focusZoneStatus(QCameraFocusZone::Selected),
- m_focusPoint(0.5, 0.5),
- m_focusRect(0, 0, 0.3, 0.3)
-{
- m_focusRect.moveCenter(m_focusPoint);
-
- gst_photography_set_focus_mode(m_session->photography(), GST_PHOTOGRAPHY_FOCUS_MODE_AUTO);
-
- connect(m_session, SIGNAL(statusChanged(QCamera::Status)),
- this, SLOT(_q_handleCameraStatusChange(QCamera::Status)));
-}
-
-CameraBinFocus::~CameraBinFocus()
-{
-}
-
-QCameraFocus::FocusModes CameraBinFocus::focusMode() const
-{
- return m_focusMode;
-}
-
-void CameraBinFocus::setFocusMode(QCameraFocus::FocusModes mode)
-{
- GstPhotographyFocusMode photographyMode;
-
- switch (mode) {
- case QCameraFocus::AutoFocus:
- photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_AUTO;
- break;
- case QCameraFocus::HyperfocalFocus:
- photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_HYPERFOCAL;
- break;
- case QCameraFocus::InfinityFocus:
- photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_INFINITY;
- break;
- case QCameraFocus::ContinuousFocus:
- photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_NORMAL;
- break;
- case QCameraFocus::MacroFocus:
- photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_MACRO;
- break;
- default:
- if (mode & QCameraFocus::AutoFocus) {
- photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_AUTO;
- break;
- } else {
- return;
- }
- }
-
- if (gst_photography_set_focus_mode(m_session->photography(), photographyMode))
- m_focusMode = mode;
-}
-
-bool CameraBinFocus::isFocusModeSupported(QCameraFocus::FocusModes mode) const
-{
- switch (mode) {
- case QCameraFocus::AutoFocus:
- case QCameraFocus::HyperfocalFocus:
- case QCameraFocus::InfinityFocus:
- case QCameraFocus::ContinuousFocus:
- case QCameraFocus::MacroFocus:
- return true;
- default:
- return mode & QCameraFocus::AutoFocus;
- }
-}
-
-QCameraFocus::FocusPointMode CameraBinFocus::focusPointMode() const
-{
- return m_focusPointMode;
-}
-
-void CameraBinFocus::setFocusPointMode(QCameraFocus::FocusPointMode mode)
-{
- GstElement *source = m_session->cameraSource();
-
- if (m_focusPointMode == mode || !source)
- return;
-
-#if GST_CHECK_VERSION(1,0,0)
- if (m_focusPointMode == QCameraFocus::FocusPointFaceDetection) {
- g_object_set (G_OBJECT(source), "detect-faces", FALSE, NULL);
-
- if (GstPad *pad = gst_element_get_static_pad(source, "vfsrc")) {
- removeProbeFromPad(pad);
- gst_object_unref(GST_OBJECT(pad));
- }
-
- m_faceResetTimer.stop();
- m_faceFocusRects.clear();
-
- QMutexLocker locker(&m_mutex);
- m_faces.clear();
- }
-#endif
-
- if (m_focusPointMode != QCameraFocus::FocusPointAuto)
- resetFocusPoint();
-
- switch (mode) {
- case QCameraFocus::FocusPointAuto:
- case QCameraFocus::FocusPointCustom:
- break;
-#if GST_CHECK_VERSION(1,0,0)
- case QCameraFocus::FocusPointFaceDetection:
- if (g_object_class_find_property(G_OBJECT_GET_CLASS(source), "detect-faces")) {
- if (GstPad *pad = gst_element_get_static_pad(source, "vfsrc")) {
- addProbeToPad(pad);
- g_object_set (G_OBJECT(source), "detect-faces", TRUE, NULL);
- break;
- }
- }
- return;
-#endif
- default:
- return;
- }
-
- m_focusPointMode = mode;
- emit focusPointModeChanged(m_focusPointMode);
- emit focusZonesChanged();
-}
-
-bool CameraBinFocus::isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const
-{
- switch (mode) {
- case QCameraFocus::FocusPointAuto:
- case QCameraFocus::FocusPointCustom:
- return true;
-#if GST_CHECK_VERSION(1,0,0)
- case QCameraFocus::FocusPointFaceDetection:
- if (GstElement *source = m_session->cameraSource())
- return g_object_class_find_property(G_OBJECT_GET_CLASS(source), "detect-faces");
- return false;
-#endif
- default:
- return false;
- }
-}
-
-QPointF CameraBinFocus::customFocusPoint() const
-{
- return m_focusPoint;
-}
-
-void CameraBinFocus::setCustomFocusPoint(const QPointF &point)
-{
- if (m_focusPoint != point) {
- m_focusPoint = point;
-
- // Bound the focus point so the focus rect remains entirely within the unit square.
- m_focusPoint.setX(qBound(m_focusRect.width() / 2, m_focusPoint.x(), 1 - m_focusRect.width() / 2));
- m_focusPoint.setY(qBound(m_focusRect.height() / 2, m_focusPoint.y(), 1 - m_focusRect.height() / 2));
-
- if (m_focusPointMode == QCameraFocus::FocusPointCustom) {
- const QRectF focusRect = m_focusRect;
- m_focusRect.moveCenter(m_focusPoint);
-
- updateRegionOfInterest(m_focusRect);
-
- if (focusRect != m_focusRect) {
- emit focusZonesChanged();
- }
- }
-
- emit customFocusPointChanged(m_focusPoint);
- }
-}
-
-QCameraFocusZoneList CameraBinFocus::focusZones() const
-{
- QCameraFocusZoneList zones;
-
- if (m_focusPointMode != QCameraFocus::FocusPointFaceDetection) {
- zones.append(QCameraFocusZone(m_focusRect, m_focusZoneStatus));
-#if GST_CHECK_VERSION(1,0,0)
- } else for (const QRect &face : qAsConst(m_faceFocusRects)) {
- const QRectF normalizedRect(
- face.x() / qreal(m_viewfinderResolution.width()),
- face.y() / qreal(m_viewfinderResolution.height()),
- face.width() / qreal(m_viewfinderResolution.width()),
- face.height() / qreal(m_viewfinderResolution.height()));
- zones.append(QCameraFocusZone(normalizedRect, m_focusZoneStatus));
-#endif
- }
- return zones;
-}
-
-void CameraBinFocus::handleFocusMessage(GstMessage *gm)
-{
- //it's a sync message, so it's called from non main thread
- const GstStructure *structure = gst_message_get_structure(gm);
- if (gst_structure_has_name(structure, GST_PHOTOGRAPHY_AUTOFOCUS_DONE)) {
- gint status = GST_PHOTOGRAPHY_FOCUS_STATUS_NONE;
- gst_structure_get_int (structure, "status", &status);
- QCamera::LockStatus focusStatus = m_focusStatus;
- QCamera::LockChangeReason reason = QCamera::UserRequest;
-
- switch (status) {
- case GST_PHOTOGRAPHY_FOCUS_STATUS_FAIL:
- focusStatus = QCamera::Unlocked;
- reason = QCamera::LockFailed;
- break;
- case GST_PHOTOGRAPHY_FOCUS_STATUS_SUCCESS:
- focusStatus = QCamera::Locked;
- break;
- case GST_PHOTOGRAPHY_FOCUS_STATUS_NONE:
- break;
- case GST_PHOTOGRAPHY_FOCUS_STATUS_RUNNING:
- focusStatus = QCamera::Searching;
- break;
- default:
- break;
- }
-
- static int signalIndex = metaObject()->indexOfSlot(
- "_q_setFocusStatus(QCamera::LockStatus,QCamera::LockChangeReason)");
- metaObject()->method(signalIndex).invoke(this,
- Qt::QueuedConnection,
- Q_ARG(QCamera::LockStatus,focusStatus),
- Q_ARG(QCamera::LockChangeReason,reason));
- }
-}
-
-void CameraBinFocus::_q_setFocusStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason)
-{
-#ifdef CAMERABIN_DEBUG
- qDebug() << Q_FUNC_INFO << "Current:"
- << m_focusStatus
- << "New:"
- << status << reason;
-#endif
-
- if (m_focusStatus != status) {
- m_focusStatus = status;
-
- QCameraFocusZone::FocusZoneStatus zonesStatus =
- m_focusStatus == QCamera::Locked ?
- QCameraFocusZone::Focused : QCameraFocusZone::Selected;
-
- if (m_focusZoneStatus != zonesStatus) {
- m_focusZoneStatus = zonesStatus;
- emit focusZonesChanged();
- }
-
-#if GST_CHECK_VERSION(1,0,0)
- if (m_focusPointMode == QCameraFocus::FocusPointFaceDetection
- && m_focusStatus == QCamera::Unlocked) {
- _q_updateFaces();
- }
-#endif
-
- emit _q_focusStatusChanged(m_focusStatus, reason);
- }
-}
-
-void CameraBinFocus::_q_handleCameraStatusChange(QCamera::Status status)
-{
- m_cameraStatus = status;
- if (status == QCamera::ActiveStatus) {
- if (GstPad *pad = gst_element_get_static_pad(m_session->cameraSource(), "vfsrc")) {
- if (GstCaps *caps = qt_gst_pad_get_current_caps(pad)) {
- if (GstStructure *structure = gst_caps_get_structure(caps, 0)) {
- int width = 0;
- int height = 0;
- gst_structure_get_int(structure, "width", &width);
- gst_structure_get_int(structure, "height", &height);
- setViewfinderResolution(QSize(width, height));
- }
- gst_caps_unref(caps);
- }
- gst_object_unref(GST_OBJECT(pad));
- }
- if (m_focusPointMode == QCameraFocus::FocusPointCustom) {
- updateRegionOfInterest(m_focusRect);
- }
- } else {
- _q_setFocusStatus(QCamera::Unlocked, QCamera::LockLost);
-
- resetFocusPoint();
- }
-}
-
-void CameraBinFocus::_q_startFocusing()
-{
- _q_setFocusStatus(QCamera::Searching, QCamera::UserRequest);
- gst_photography_set_autofocus(m_session->photography(), TRUE);
-}
-
-void CameraBinFocus::_q_stopFocusing()
-{
- gst_photography_set_autofocus(m_session->photography(), FALSE);
- _q_setFocusStatus(QCamera::Unlocked, QCamera::UserRequest);
-}
-
-void CameraBinFocus::setViewfinderResolution(const QSize &resolution)
-{
- if (resolution != m_viewfinderResolution) {
- m_viewfinderResolution = resolution;
- if (!resolution.isEmpty()) {
- const QPointF center = m_focusRect.center();
- m_focusRect.setWidth(m_focusRect.height() * resolution.height() / resolution.width());
- m_focusRect.moveCenter(center);
- }
- }
-}
-
-void CameraBinFocus::resetFocusPoint()
-{
- const QRectF focusRect = m_focusRect;
- m_focusPoint = QPointF(0.5, 0.5);
- m_focusRect.moveCenter(m_focusPoint);
-
- updateRegionOfInterest(QList<QRect>());
-
- if (focusRect != m_focusRect) {
- emit customFocusPointChanged(m_focusPoint);
- emit focusZonesChanged();
- }
-}
-
-static void appendRegion(GValue *regions, int priority, const QRect &rectangle)
-{
- GstStructure *region = gst_structure_new(
- "region",
- "region-x" , G_TYPE_UINT , rectangle.x(),
- "region-y" , G_TYPE_UINT, rectangle.y(),
- "region-w" , G_TYPE_UINT , rectangle.width(),
- "region-h" , G_TYPE_UINT, rectangle.height(),
- "region-priority" , G_TYPE_UINT, priority,
- NULL);
-
- GValue regionValue = G_VALUE_INIT;
- g_value_init(&regionValue, GST_TYPE_STRUCTURE);
- gst_value_set_structure(&regionValue, region);
- gst_structure_free(region);
-
- gst_value_list_append_value(regions, &regionValue);
- g_value_unset(&regionValue);
-}
-
-void CameraBinFocus::updateRegionOfInterest(const QRectF &rectangle)
-{
- updateRegionOfInterest(QList<QRect>() << QRect(
- rectangle.x() * m_viewfinderResolution.width(),
- rectangle.y() * m_viewfinderResolution.height(),
- rectangle.width() * m_viewfinderResolution.width(),
- rectangle.height() * m_viewfinderResolution.height()));
-}
-
-void CameraBinFocus::updateRegionOfInterest(const QList<QRect> &rectangles)
-{
- if (m_cameraStatus != QCamera::ActiveStatus)
- return;
-
- GstElement * const cameraSource = m_session->cameraSource();
- if (!cameraSource)
- return;
-
- GValue regions = G_VALUE_INIT;
- g_value_init(&regions, GST_TYPE_LIST);
-
- if (rectangles.isEmpty()) {
- appendRegion(&regions, 0, QRect(0, 0, 0, 0));
- } else {
- // Add padding around small face rectangles so the auto focus has a reasonable amount
- // of image to work with.
- const int minimumDimension = qMin(
- m_viewfinderResolution.width(), m_viewfinderResolution.height()) * 0.3;
- const QRect viewfinderRectangle(QPoint(0, 0), m_viewfinderResolution);
-
- for (const QRect &rectangle : rectangles) {
- QRect paddedRectangle(
- 0,
- 0,
- qMax(rectangle.width(), minimumDimension),
- qMax(rectangle.height(), minimumDimension));
- paddedRectangle.moveCenter(rectangle.center());
-
- appendRegion(&regions, 1, viewfinderRectangle.intersected(paddedRectangle));
- }
- }
-
- GstStructure *regionsOfInterest = gst_structure_new(
- "regions-of-interest",
- "frame-width" , G_TYPE_UINT , m_viewfinderResolution.width(),
- "frame-height" , G_TYPE_UINT, m_viewfinderResolution.height(),
- NULL);
- gst_structure_set_value(regionsOfInterest, "regions", &regions);
- g_value_unset(&regions);
-
- GstEvent *event = gst_event_new_custom(GST_EVENT_CUSTOM_UPSTREAM, regionsOfInterest);
- gst_element_send_event(cameraSource, event);
-}
-
-#if GST_CHECK_VERSION(1,0,0)
-
-void CameraBinFocus::_q_updateFaces()
-{
- if (m_focusPointMode != QCameraFocus::FocusPointFaceDetection
- || m_focusStatus != QCamera::Unlocked) {
- return;
- }
-
- QList<QRect> faces;
-
- {
- QMutexLocker locker(&m_mutex);
- faces = m_faces;
- }
-
- if (!faces.isEmpty()) {
- m_faceResetTimer.stop();
- m_faceFocusRects = faces;
- updateRegionOfInterest(m_faceFocusRects);
- emit focusZonesChanged();
- } else {
- m_faceResetTimer.start(500, this);
- }
-}
-
-void CameraBinFocus::timerEvent(QTimerEvent *event)
-{
- if (event->timerId() == m_faceResetTimer.timerId()) {
- m_faceResetTimer.stop();
-
- if (m_focusStatus == QCamera::Unlocked) {
- m_faceFocusRects.clear();
- updateRegionOfInterest(m_faceFocusRects);
- emit focusZonesChanged();
- }
- } else {
- QCameraFocusControl::timerEvent(event);
- }
-}
-
-bool CameraBinFocus::probeBuffer(GstBuffer *buffer)
-{
- QList<QRect> faces;
-
-#if GST_CHECK_VERSION(1,1,3)
- gpointer state = NULL;
- const GstMetaInfo *info = GST_VIDEO_REGION_OF_INTEREST_META_INFO;
-
- while (GstMeta *meta = gst_buffer_iterate_meta(buffer, &state)) {
- if (meta->info->api != info->api)
- continue;
-
- GstVideoRegionOfInterestMeta *region = reinterpret_cast<GstVideoRegionOfInterestMeta *>(meta);
-
- faces.append(QRect(region->x, region->y, region->w, region->h));
- }
-#else
- Q_UNUSED(buffer);
-#endif
-
- QMutexLocker locker(&m_mutex);
-
- if (m_faces != faces) {
- m_faces = faces;
-
- static const int signalIndex = metaObject()->indexOfSlot("_q_updateFaces()");
- metaObject()->method(signalIndex).invoke(this, Qt::QueuedConnection);
- }
-
- return true;
-}
-
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinfocus.h b/src/plugins/gstreamer/camerabin/camerabinfocus.h
deleted file mode 100644
index 0fca02c35..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinfocus.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINFOCUSCONTROL_H
-#define CAMERABINFOCUSCONTROL_H
-
-#include <qcamera.h>
-#include <qcamerafocuscontrol.h>
-
-#include <private/qgstreamerbufferprobe_p.h>
-
-#include <qbasictimer.h>
-#include <qlist.h>
-#include <qmutex.h>
-
-#include <gst/gst.h>
-#include <glib.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-
-class CameraBinFocus
- : public QCameraFocusControl
-#if GST_CHECK_VERSION(1,0,0)
- , QGstreamerBufferProbe
-#endif
-{
- Q_OBJECT
-
-public:
- CameraBinFocus(CameraBinSession *session);
- virtual ~CameraBinFocus();
-
- QCameraFocus::FocusModes focusMode() const override;
- void setFocusMode(QCameraFocus::FocusModes mode) override;
- bool isFocusModeSupported(QCameraFocus::FocusModes mode) const override;
-
- QCameraFocus::FocusPointMode focusPointMode() const override;
- void setFocusPointMode(QCameraFocus::FocusPointMode mode) override;
- bool isFocusPointModeSupported(QCameraFocus::FocusPointMode) const override;
- QPointF customFocusPoint() const override;
- void setCustomFocusPoint(const QPointF &point) override;
-
- QCameraFocusZoneList focusZones() const override;
-
- void handleFocusMessage(GstMessage*);
- QCamera::LockStatus focusStatus() const { return m_focusStatus; }
-
-Q_SIGNALS:
- void _q_focusStatusChanged(QCamera::LockStatus status, QCamera::LockChangeReason reason);
-
-public Q_SLOTS:
- void _q_startFocusing();
- void _q_stopFocusing();
-
- void setViewfinderResolution(const QSize &resolution);
-
-#if GST_CHECK_VERSION(1,0,0)
-protected:
- void timerEvent(QTimerEvent *event) override;
-#endif
-
-private Q_SLOTS:
- void _q_setFocusStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason);
- void _q_handleCameraStatusChange(QCamera::Status status);
-
-#if GST_CHECK_VERSION(1,0,0)
- void _q_updateFaces();
-#endif
-
-private:
- void resetFocusPoint();
- void updateRegionOfInterest(const QRectF &rectangle);
- void updateRegionOfInterest(const QList<QRect> &rectangles);
-
-#if GST_CHECK_VERSION(1,0,0)
- bool probeBuffer(GstBuffer *buffer) override;
-#endif
-
- CameraBinSession *m_session;
- QCamera::Status m_cameraStatus;
- QCameraFocus::FocusModes m_focusMode;
- QCameraFocus::FocusPointMode m_focusPointMode;
- QCamera::LockStatus m_focusStatus;
- QCameraFocusZone::FocusZoneStatus m_focusZoneStatus;
- QPointF m_focusPoint;
- QRectF m_focusRect;
- QSize m_viewfinderResolution;
- QList<QRect> m_faces;
- QList<QRect> m_faceFocusRects;
- QBasicTimer m_faceResetTimer;
- mutable QMutex m_mutex;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINFOCUSCONTROL_H
diff --git a/src/plugins/gstreamer/camerabin/camerabinimagecapture.cpp b/src/plugins/gstreamer/camerabin/camerabinimagecapture.cpp
deleted file mode 100644
index b164bc31a..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinimagecapture.cpp
+++ /dev/null
@@ -1,380 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabinimagecapture.h"
-#include "camerabincontrol.h"
-#include "camerabincapturedestination.h"
-#include "camerabincapturebufferformat.h"
-#include "camerabinsession.h"
-#include "camerabinresourcepolicy.h"
-#include <private/qgstvideobuffer_p.h>
-#include <private/qvideosurfacegstsink_p.h>
-#include <private/qgstutils_p.h>
-#include <QtMultimedia/qmediametadata.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qbuffer.h>
-#include <QtGui/qimagereader.h>
-
-//#define DEBUG_CAPTURE
-
-#define IMAGE_DONE_SIGNAL "image-done"
-
-QT_BEGIN_NAMESPACE
-
-CameraBinImageCapture::CameraBinImageCapture(CameraBinSession *session)
- :QCameraImageCaptureControl(session)
- , m_encoderProbe(this)
- , m_muxerProbe(this)
- , m_session(session)
- , m_jpegEncoderElement(0)
- , m_metadataMuxerElement(0)
- , m_requestId(0)
- , m_ready(false)
-{
- connect(m_session, SIGNAL(statusChanged(QCamera::Status)), SLOT(updateState()));
- connect(m_session, SIGNAL(imageExposed(int)), this, SIGNAL(imageExposed(int)));
- connect(m_session, SIGNAL(imageCaptured(int,QImage)), this, SIGNAL(imageCaptured(int,QImage)));
- connect(m_session->cameraControl()->resourcePolicy(), SIGNAL(canCaptureChanged()), this, SLOT(updateState()));
-
- m_session->bus()->installMessageFilter(this);
-}
-
-CameraBinImageCapture::~CameraBinImageCapture()
-{
-}
-
-bool CameraBinImageCapture::isReadyForCapture() const
-{
- return m_ready;
-}
-
-int CameraBinImageCapture::capture(const QString &fileName)
-{
- m_requestId++;
-
- if (!m_ready) {
- emit error(m_requestId, QCameraImageCapture::NotReadyError, tr("Camera not ready"));
- return m_requestId;
- }
-
-#ifdef DEBUG_CAPTURE
- qDebug() << Q_FUNC_INFO << m_requestId << fileName;
-#endif
- m_session->captureImage(m_requestId, fileName);
- return m_requestId;
-}
-
-void CameraBinImageCapture::cancelCapture()
-{
-}
-
-void CameraBinImageCapture::updateState()
-{
- bool ready = m_session->status() == QCamera::ActiveStatus
- && m_session->cameraControl()->resourcePolicy()->canCapture();
- if (m_ready != ready) {
-#ifdef DEBUG_CAPTURE
- qDebug() << "readyForCaptureChanged" << ready;
-#endif
- emit readyForCaptureChanged(m_ready = ready);
- }
-}
-
-#if GST_CHECK_VERSION(1,0,0)
-GstPadProbeReturn CameraBinImageCapture::encoderEventProbe(
- GstPad *, GstPadProbeInfo *info, gpointer user_data)
-{
- GstEvent * const event = gst_pad_probe_info_get_event(info);
-#else
-gboolean CameraBinImageCapture::encoderEventProbe(
- GstElement *, GstEvent *event, gpointer user_data)
-{
-#endif
- CameraBinImageCapture * const self = static_cast<CameraBinImageCapture *>(user_data);
- if (event && GST_EVENT_TYPE(event) == GST_EVENT_TAG) {
- GstTagList *gstTags;
- gst_event_parse_tag(event, &gstTags);
- QMap<QByteArray, QVariant> extendedTags = QGstUtils::gstTagListToMap(gstTags);
-
-#ifdef DEBUG_CAPTURE
- qDebug() << QString(gst_structure_to_string(gst_event_get_structure(event))).right(768);
- qDebug() << "Capture event probe" << extendedTags;
-#endif
-
- QVariantMap tags;
- tags[QMediaMetaData::ISOSpeedRatings] = extendedTags.value("capturing-iso-speed");
- tags[QMediaMetaData::DigitalZoomRatio] = extendedTags.value("capturing-digital-zoom-ratio");
- tags[QMediaMetaData::ExposureTime] = extendedTags.value("capturing-shutter-speed");
- tags[QMediaMetaData::WhiteBalance] = extendedTags.value("capturing-white-balance");
- tags[QMediaMetaData::Flash] = extendedTags.value("capturing-flash-fired");
- tags[QMediaMetaData::FocalLengthIn35mmFilm] = extendedTags.value("capturing-focal-length");
- tags[QMediaMetaData::MeteringMode] = extendedTags.value("capturing-metering-mode");
- tags[QMediaMetaData::ExposureMode] = extendedTags.value("capturing-exposure-mode");
- tags[QMediaMetaData::FNumber] = extendedTags.value("capturing-focal-ratio");
- tags[QMediaMetaData::ExposureMode] = extendedTags.value("capturing-exposure-mode");
-
- for (auto i = tags.cbegin(), end = tags.cend(); i != end; ++i) {
- if (i.value().isValid()) {
- QMetaObject::invokeMethod(self, "imageMetadataAvailable",
- Qt::QueuedConnection,
- Q_ARG(int, self->m_requestId),
- Q_ARG(QString, i.key()),
- Q_ARG(QVariant, i.value()));
- }
- }
- }
-#if GST_CHECK_VERSION(1,0,0)
- return GST_PAD_PROBE_OK;
-#else
- return TRUE;
-#endif
-}
-
-void CameraBinImageCapture::EncoderProbe::probeCaps(GstCaps *caps)
-{
-#if GST_CHECK_VERSION(1,0,0)
- capture->m_bufferFormat = QGstUtils::formatForCaps(caps, &capture->m_videoInfo);
-#else
- int bytesPerLine = 0;
- QVideoSurfaceFormat format = QGstUtils::formatForCaps(caps, &bytesPerLine);
- capture->m_bytesPerLine = bytesPerLine;
- capture->m_bufferFormat = format;
-#endif
-}
-
-bool CameraBinImageCapture::EncoderProbe::probeBuffer(GstBuffer *buffer)
-{
- CameraBinSession * const session = capture->m_session;
-
-#ifdef DEBUG_CAPTURE
- qDebug() << "Uncompressed buffer probe";
-#endif
-
- QCameraImageCapture::CaptureDestinations destination =
- session->captureDestinationControl()->captureDestination();
- QVideoFrame::PixelFormat format = session->captureBufferFormatControl()->bufferFormat();
-
- if (destination & QCameraImageCapture::CaptureToBuffer) {
- if (format != QVideoFrame::Format_Jpeg) {
-#ifdef DEBUG_CAPTURE
- qDebug() << "imageAvailable(uncompressed):" << format;
-#endif
-#if GST_CHECK_VERSION(1,0,0)
- QGstVideoBuffer *videoBuffer = new QGstVideoBuffer(buffer, capture->m_videoInfo);
-#else
- QGstVideoBuffer *videoBuffer = new QGstVideoBuffer(buffer, capture->m_bytesPerLine);
-#endif
-
- QVideoFrame frame(
- videoBuffer,
- capture->m_bufferFormat.frameSize(),
- capture->m_bufferFormat.pixelFormat());
-
- QMetaObject::invokeMethod(capture, "imageAvailable",
- Qt::QueuedConnection,
- Q_ARG(int, capture->m_requestId),
- Q_ARG(QVideoFrame, frame));
- }
- }
-
- //keep the buffer if capture to file or jpeg buffer capture was reuqsted
- bool keepBuffer = (destination & QCameraImageCapture::CaptureToFile) ||
- ((destination & QCameraImageCapture::CaptureToBuffer) &&
- format == QVideoFrame::Format_Jpeg);
-
- return keepBuffer;
-}
-
-void CameraBinImageCapture::MuxerProbe::probeCaps(GstCaps *caps)
-{
- capture->m_jpegResolution = QGstUtils::capsCorrectedResolution(caps);
-}
-
-bool CameraBinImageCapture::MuxerProbe::probeBuffer(GstBuffer *buffer)
-{
- CameraBinSession * const session = capture->m_session;
-
- QCameraImageCapture::CaptureDestinations destination =
- session->captureDestinationControl()->captureDestination();
-
- if ((destination & QCameraImageCapture::CaptureToBuffer) &&
- session->captureBufferFormatControl()->bufferFormat() == QVideoFrame::Format_Jpeg) {
-
- QSize resolution = capture->m_jpegResolution;
- //if resolution is not presented in caps, try to find it from encoded jpeg data:
-#if GST_CHECK_VERSION(1,0,0)
- GstMapInfo mapInfo;
- if (resolution.isEmpty() && gst_buffer_map(buffer, &mapInfo, GST_MAP_READ)) {
- QBuffer data;
- data.setData(reinterpret_cast<const char*>(mapInfo.data), mapInfo.size);
-
- QImageReader reader(&data, "JPEG");
- resolution = reader.size();
-
- gst_buffer_unmap(buffer, &mapInfo);
- }
-
- GstVideoInfo info;
- gst_video_info_set_format(
- &info, GST_VIDEO_FORMAT_ENCODED, resolution.width(), resolution.height());
- QGstVideoBuffer *videoBuffer = new QGstVideoBuffer(buffer, info);
-#else
- if (resolution.isEmpty()) {
- QBuffer data;
- data.setData(reinterpret_cast<const char*>(GST_BUFFER_DATA(buffer)), GST_BUFFER_SIZE(buffer));
- QImageReader reader(&data, "JPEG");
- resolution = reader.size();
- }
-
- QGstVideoBuffer *videoBuffer = new QGstVideoBuffer(buffer,
- -1); //bytesPerLine is not available for jpegs
-#endif
-
-
- QVideoFrame frame(videoBuffer,
- resolution,
- QVideoFrame::Format_Jpeg);
- QMetaObject::invokeMethod(capture, "imageAvailable",
- Qt::QueuedConnection,
- Q_ARG(int, capture->m_requestId),
- Q_ARG(QVideoFrame, frame));
- }
-
-
- // Theoretically we could drop the buffer here when don't want to capture to file but that
- // prevents camerabin from recognizing that capture has been completed and returning
- // to its idle state.
- return true;
-}
-
-
-bool CameraBinImageCapture::processBusMessage(const QGstreamerMessage &message)
-{
- //Install metadata event and buffer probes
-
- //The image capture pipiline is built dynamically,
- //it's necessary to wait until jpeg encoder is added to pipeline
-
- GstMessage *gm = message.rawMessage();
- if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_STATE_CHANGED) {
- GstState oldState;
- GstState newState;
- GstState pending;
- gst_message_parse_state_changed(gm, &oldState, &newState, &pending);
-
- if (newState == GST_STATE_READY) {
- GstElement *element = GST_ELEMENT(GST_MESSAGE_SRC(gm));
- if (!element)
- return false;
-
- gchar *name = gst_element_get_name(element);
- QString elementName = QString::fromLatin1(name);
- g_free(name);
-#if !GST_CHECK_VERSION(1,0,0)
- GstElementClass *elementClass = GST_ELEMENT_GET_CLASS(element);
- QString elementLongName = elementClass->details.longname;
-#endif
- if (elementName.contains("jpegenc") && element != m_jpegEncoderElement) {
- m_jpegEncoderElement = element;
- GstPad *sinkpad = gst_element_get_static_pad(element, "sink");
-
- //metadata event probe is installed before jpeg encoder
- //to emit metadata available signal as soon as possible.
-#ifdef DEBUG_CAPTURE
- qDebug() << "install metadata probe";
-#endif
-#if GST_CHECK_VERSION(1,0,0)
- gst_pad_add_probe(
- sinkpad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, encoderEventProbe, this, NULL);
-#else
- gst_pad_add_event_probe(sinkpad, G_CALLBACK(encoderEventProbe), this);
-#endif
-#ifdef DEBUG_CAPTURE
- qDebug() << "install uncompressed buffer probe";
-#endif
- m_encoderProbe.addProbeToPad(sinkpad, true);
-
- gst_object_unref(sinkpad);
- } else if ((elementName.contains("jifmux")
-#if !GST_CHECK_VERSION(1,0,0)
- || elementLongName == QLatin1String("JPEG stream muxer")
-#endif
- || elementName.startsWith("metadatamux"))
- && element != m_metadataMuxerElement) {
- //Jpeg encoded buffer probe is added after jifmux/metadatamux
- //element to ensure the resulting jpeg buffer contains capture metadata
- m_metadataMuxerElement = element;
-
- GstPad *srcpad = gst_element_get_static_pad(element, "src");
-#ifdef DEBUG_CAPTURE
- qDebug() << "install jpeg buffer probe";
-#endif
- m_muxerProbe.addProbeToPad(srcpad);
-
- gst_object_unref(srcpad);
- }
- }
- } else if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT) {
- if (GST_MESSAGE_SRC(gm) == (GstObject *)m_session->cameraBin()) {
- const GstStructure *structure = gst_message_get_structure(gm);
-
- if (gst_structure_has_name (structure, "image-done")) {
- const gchar *fileName = gst_structure_get_string (structure, "filename");
-#ifdef DEBUG_CAPTURE
- qDebug() << "Image saved" << fileName;
-#endif
-
- if (m_session->captureDestinationControl()->captureDestination() & QCameraImageCapture::CaptureToFile) {
- emit imageSaved(m_requestId, QString::fromUtf8(fileName));
- } else {
-#ifdef DEBUG_CAPTURE
- qDebug() << Q_FUNC_INFO << "Dropped saving file" << fileName;
-#endif
- QFileInfo info(QString::fromUtf8(fileName));
- if (info.exists() && info.isFile())
- QFile(info.absoluteFilePath()).remove();
- }
- }
- }
- }
-
- return false;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinimagecapture.h b/src/plugins/gstreamer/camerabin/camerabinimagecapture.h
deleted file mode 100644
index 5e00ab6d5..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinimagecapture.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef CAMERABINIMAGECAPTURECONTROL_H
-#define CAMERABINIMAGECAPTURECONTROL_H
-
-#include <qcameraimagecapturecontrol.h>
-#include "camerabinsession.h"
-
-#include <qvideosurfaceformat.h>
-
-#include <private/qgstreamerbufferprobe_p.h>
-
-#if GST_CHECK_VERSION(1,0,0)
-#include <gst/video/video.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinImageCapture : public QCameraImageCaptureControl, public QGstreamerBusMessageFilter
-{
- Q_OBJECT
- Q_INTERFACES(QGstreamerBusMessageFilter)
-public:
- CameraBinImageCapture(CameraBinSession *session);
- virtual ~CameraBinImageCapture();
-
- QCameraImageCapture::DriveMode driveMode() const override { return QCameraImageCapture::SingleImageCapture; }
- void setDriveMode(QCameraImageCapture::DriveMode) override {}
-
- bool isReadyForCapture() const override;
- int capture(const QString &fileName) override;
- void cancelCapture() override;
-
- bool processBusMessage(const QGstreamerMessage &message) override;
-
-private slots:
- void updateState();
-
-private:
-#if GST_CHECK_VERSION(1,0,0)
- static GstPadProbeReturn encoderEventProbe(GstPad *, GstPadProbeInfo *info, gpointer user_data);
-#else
- static gboolean encoderEventProbe(GstElement *, GstEvent *event, gpointer user_data);
-#endif
-
- class EncoderProbe : public QGstreamerBufferProbe
- {
- public:
- EncoderProbe(CameraBinImageCapture *capture) : capture(capture) {}
- void probeCaps(GstCaps *caps) override;
- bool probeBuffer(GstBuffer *buffer) override;
-
- private:
- CameraBinImageCapture * const capture;
- } m_encoderProbe;
-
- class MuxerProbe : public QGstreamerBufferProbe
- {
- public:
- MuxerProbe(CameraBinImageCapture *capture) : capture(capture) {}
- void probeCaps(GstCaps *caps) override;
- bool probeBuffer(GstBuffer *buffer) override;
-
- private:
- CameraBinImageCapture * const capture;
-
- } m_muxerProbe;
-
- QVideoSurfaceFormat m_bufferFormat;
- QSize m_jpegResolution;
- CameraBinSession *m_session;
- GstElement *m_jpegEncoderElement;
- GstElement *m_metadataMuxerElement;
-#if GST_CHECK_VERSION(1,0,0)
- GstVideoInfo m_videoInfo;
-#else
- int m_bytesPerLine;
-#endif
- int m_requestId;
- bool m_ready;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINCAPTURECORNTROL_H
diff --git a/src/plugins/gstreamer/camerabin/camerabinimageencoder.cpp b/src/plugins/gstreamer/camerabin/camerabinimageencoder.cpp
deleted file mode 100644
index 8c4eaec70..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinimageencoder.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabinimageencoder.h"
-#include "camerabinsession.h"
-
-#include <QtCore/qdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-CameraBinImageEncoder::CameraBinImageEncoder(CameraBinSession *session)
- :QImageEncoderControl(session), m_session(session)
-{
-}
-
-CameraBinImageEncoder::~CameraBinImageEncoder()
-{
-}
-
-QList<QSize> CameraBinImageEncoder::supportedResolutions(const QImageEncoderSettings &, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- return m_session->supportedResolutions(qMakePair<int,int>(0,0), continuous, QCamera::CaptureStillImage);
-}
-
-QStringList CameraBinImageEncoder::supportedImageCodecs() const
-{
- return QStringList() << "jpeg";
-}
-
-QString CameraBinImageEncoder::imageCodecDescription(const QString &codecName) const
-{
- if (codecName == "jpeg")
- return tr("JPEG image");
-
- return QString();
-}
-
-QImageEncoderSettings CameraBinImageEncoder::imageSettings() const
-{
- return m_settings;
-}
-
-void CameraBinImageEncoder::setImageSettings(const QImageEncoderSettings &settings)
-{
- m_settings = settings;
- emit settingsChanged();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinimageencoder.h b/src/plugins/gstreamer/camerabin/camerabinimageencoder.h
deleted file mode 100644
index 96f7ae7aa..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinimageencoder.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINIMAGEENCODE_H
-#define CAMERABINIMAGEENCODE_H
-
-#include <qimageencodercontrol.h>
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmap.h>
-
-#include <gst/gst.h>
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-
-class CameraBinImageEncoder : public QImageEncoderControl
-{
- Q_OBJECT
-public:
- CameraBinImageEncoder(CameraBinSession *session);
- virtual ~CameraBinImageEncoder();
-
- QList<QSize> supportedResolutions(const QImageEncoderSettings &settings = QImageEncoderSettings(),
- bool *continuous = 0) const override;
-
- QStringList supportedImageCodecs() const override;
- QString imageCodecDescription(const QString &formatName) const override;
-
- QImageEncoderSettings imageSettings() const override;
- void setImageSettings(const QImageEncoderSettings &settings) override;
-
-Q_SIGNALS:
- void settingsChanged();
-
-private:
- QImageEncoderSettings m_settings;
-
- CameraBinSession *m_session;
-
- // Added
- QStringList m_codecs;
- QMap<QString,QByteArray> m_elementNames;
- QMap<QString,QString> m_codecDescriptions;
- QMap<QString,QStringList> m_codecOptions;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp b/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp
deleted file mode 100644
index 9d281e10c..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp
+++ /dev/null
@@ -1,441 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "camerabinimageprocessing.h"
-#include "camerabinsession.h"
-
-#if QT_CONFIG(linux_v4l)
-#include "camerabinv4limageprocessing.h"
-#endif
-
-#if GST_CHECK_VERSION(1,0,0)
-# include <gst/video/colorbalance.h>
-#else
-# include <gst/interfaces/colorbalance.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-CameraBinImageProcessing::CameraBinImageProcessing(CameraBinSession *session)
- : QCameraImageProcessingControl(session)
- , m_session(session)
- , m_whiteBalanceMode(QCameraImageProcessing::WhiteBalanceAuto)
-#if QT_CONFIG(linux_v4l)
- , m_v4lImageControl(nullptr)
-#endif
-{
-#if QT_CONFIG(gstreamer_photography)
- if (m_session->photography()) {
- m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_AUTO] = QCameraImageProcessing::WhiteBalanceAuto;
- m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_DAYLIGHT] = QCameraImageProcessing::WhiteBalanceSunlight;
- m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_CLOUDY] = QCameraImageProcessing::WhiteBalanceCloudy;
- m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_SUNSET] = QCameraImageProcessing::WhiteBalanceSunset;
- m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_TUNGSTEN] = QCameraImageProcessing::WhiteBalanceTungsten;
- m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_FLUORESCENT] = QCameraImageProcessing::WhiteBalanceFluorescent;
- unlockWhiteBalance();
- }
-
-#if GST_CHECK_VERSION(1, 0, 0)
- m_filterMap.insert(QCameraImageProcessing::ColorFilterNone, GST_PHOTOGRAPHY_COLOR_TONE_MODE_NORMAL);
- if (m_session->photography()) {
- m_filterMap.insert(QCameraImageProcessing::ColorFilterSepia, GST_PHOTOGRAPHY_COLOR_TONE_MODE_SEPIA);
- m_filterMap.insert(QCameraImageProcessing::ColorFilterGrayscale, GST_PHOTOGRAPHY_COLOR_TONE_MODE_GRAYSCALE);
- m_filterMap.insert(QCameraImageProcessing::ColorFilterNegative, GST_PHOTOGRAPHY_COLOR_TONE_MODE_NEGATIVE);
- m_filterMap.insert(QCameraImageProcessing::ColorFilterSolarize, GST_PHOTOGRAPHY_COLOR_TONE_MODE_SOLARIZE);
-#if GST_CHECK_VERSION(1, 2, 0)
- m_filterMap.insert(QCameraImageProcessing::ColorFilterPosterize, GST_PHOTOGRAPHY_COLOR_TONE_MODE_POSTERIZE);
- m_filterMap.insert(QCameraImageProcessing::ColorFilterWhiteboard, GST_PHOTOGRAPHY_COLOR_TONE_MODE_WHITEBOARD);
- m_filterMap.insert(QCameraImageProcessing::ColorFilterBlackboard, GST_PHOTOGRAPHY_COLOR_TONE_MODE_BLACKBOARD);
- m_filterMap.insert(QCameraImageProcessing::ColorFilterAqua, GST_PHOTOGRAPHY_COLOR_TONE_MODE_AQUA);
-#endif
- }
-#else
- m_filterMap.insert(QCameraImageProcessing::ColorFilterNone, GST_PHOTOGRAPHY_COLOUR_TONE_MODE_NORMAL);
- if (m_session->photography()) {
- m_filterMap.insert(QCameraImageProcessing::ColorFilterSepia, GST_PHOTOGRAPHY_COLOUR_TONE_MODE_SEPIA);
- m_filterMap.insert(QCameraImageProcessing::ColorFilterGrayscale, GST_PHOTOGRAPHY_COLOUR_TONE_MODE_GRAYSCALE);
- m_filterMap.insert(QCameraImageProcessing::ColorFilterNegative, GST_PHOTOGRAPHY_COLOUR_TONE_MODE_NEGATIVE);
- m_filterMap.insert(QCameraImageProcessing::ColorFilterSolarize, GST_PHOTOGRAPHY_COLOUR_TONE_MODE_SOLARIZE);
- }
-#endif
-#endif
-
-#if QT_CONFIG(linux_v4l)
- m_v4lImageControl = new CameraBinV4LImageProcessing(m_session);
- connect(m_session, &CameraBinSession::statusChanged,
- m_v4lImageControl, &CameraBinV4LImageProcessing::updateParametersInfo);
-#endif
-
- updateColorBalanceValues();
-}
-
-CameraBinImageProcessing::~CameraBinImageProcessing()
-{
-}
-
-void CameraBinImageProcessing::updateColorBalanceValues()
-{
- if (!GST_IS_COLOR_BALANCE(m_session->cameraBin())) {
- // Camerabin doesn't implement gstcolorbalance interface
- return;
- }
-
- GstColorBalance *balance = GST_COLOR_BALANCE(m_session->cameraBin());
- const GList *controls = gst_color_balance_list_channels(balance);
-
- const GList *item;
- GstColorBalanceChannel *channel;
- gint cur_value;
- qreal scaledValue = 0;
-
- for (item = controls; item; item = g_list_next (item)) {
- channel = (GstColorBalanceChannel *)item->data;
- cur_value = gst_color_balance_get_value (balance, channel);
-
- //map the [min_value..max_value] range to [-1.0 .. 1.0]
- if (channel->min_value != channel->max_value) {
- scaledValue = qreal(cur_value - channel->min_value) /
- (channel->max_value - channel->min_value) * 2 - 1;
- }
-
- if (!g_ascii_strcasecmp (channel->label, "brightness")) {
- m_values[QCameraImageProcessingControl::BrightnessAdjustment] = scaledValue;
- } else if (!g_ascii_strcasecmp (channel->label, "contrast")) {
- m_values[QCameraImageProcessingControl::ContrastAdjustment] = scaledValue;
- } else if (!g_ascii_strcasecmp (channel->label, "saturation")) {
- m_values[QCameraImageProcessingControl::SaturationAdjustment] = scaledValue;
- }
- }
-}
-
-bool CameraBinImageProcessing::setColorBalanceValue(const QString& channel, qreal value)
-{
-
- if (!GST_IS_COLOR_BALANCE(m_session->cameraBin())) {
- // Camerabin doesn't implement gstcolorbalance interface
- return false;
- }
-
- GstColorBalance *balance = GST_COLOR_BALANCE(m_session->cameraBin());
- const GList *controls = gst_color_balance_list_channels(balance);
-
- const GList *item;
- GstColorBalanceChannel *colorBalanceChannel;
-
- for (item = controls; item; item = g_list_next (item)) {
- colorBalanceChannel = (GstColorBalanceChannel *)item->data;
-
- if (!g_ascii_strcasecmp (colorBalanceChannel->label, channel.toLatin1())) {
- //map the [-1.0 .. 1.0] range to [min_value..max_value]
- gint scaledValue = colorBalanceChannel->min_value + qRound(
- (value+1.0)/2.0 * (colorBalanceChannel->max_value - colorBalanceChannel->min_value));
-
- gst_color_balance_set_value (balance, colorBalanceChannel, scaledValue);
- return true;
- }
- }
-
- return false;
-}
-
-QCameraImageProcessing::WhiteBalanceMode CameraBinImageProcessing::whiteBalanceMode() const
-{
- return m_whiteBalanceMode;
-}
-
-bool CameraBinImageProcessing::setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode)
-{
-#if QT_CONFIG(gstreamer_photography)
- if (isWhiteBalanceModeSupported(mode)) {
- m_whiteBalanceMode = mode;
-#if GST_CHECK_VERSION(1, 2, 0)
- GstPhotographyWhiteBalanceMode currentMode;
- if (gst_photography_get_white_balance_mode(m_session->photography(), &currentMode)
- && currentMode != GST_PHOTOGRAPHY_WB_MODE_MANUAL)
-#endif
- {
- unlockWhiteBalance();
- return true;
- }
- }
-#else
- Q_UNUSED(mode);
-#endif
- return false;
-}
-
-bool CameraBinImageProcessing::isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode mode) const
-{
-#if QT_CONFIG(gstreamer_photography)
- return m_mappedWbValues.values().contains(mode);
-#else
- Q_UNUSED(mode);
- return false;
-#endif
-}
-
-bool CameraBinImageProcessing::isParameterSupported(QCameraImageProcessingControl::ProcessingParameter parameter) const
-{
-#if QT_CONFIG(gstreamer_photography)
- if (parameter == QCameraImageProcessingControl::WhiteBalancePreset
- || parameter == QCameraImageProcessingControl::ColorFilter) {
- if (m_session->photography())
- return true;
- }
-#endif
-
- if (parameter == QCameraImageProcessingControl::Contrast
- || parameter == QCameraImageProcessingControl::Brightness
- || parameter == QCameraImageProcessingControl::Saturation) {
- if (GST_IS_COLOR_BALANCE(m_session->cameraBin()))
- return true;
- }
-
-#if QT_CONFIG(linux_v4l)
- if (m_v4lImageControl->isParameterSupported(parameter))
- return true;
-#endif
-
- return false;
-}
-
-bool CameraBinImageProcessing::isParameterValueSupported(QCameraImageProcessingControl::ProcessingParameter parameter, const QVariant &value) const
-{
- switch (parameter) {
- case ContrastAdjustment:
- case BrightnessAdjustment:
- case SaturationAdjustment: {
- const bool isGstColorBalanceValueSupported = GST_IS_COLOR_BALANCE(m_session->cameraBin())
- && qAbs(value.toReal()) <= 1.0;
-#if QT_CONFIG(linux_v4l)
- if (!isGstColorBalanceValueSupported)
- return m_v4lImageControl->isParameterValueSupported(parameter, value);
-#endif
- return isGstColorBalanceValueSupported;
- }
- case SharpeningAdjustment: {
-#if QT_CONFIG(linux_v4l)
- return m_v4lImageControl->isParameterValueSupported(parameter, value);
-#else
- return false;
-#endif
- }
- case WhiteBalancePreset: {
- const QCameraImageProcessing::WhiteBalanceMode mode =
- value.value<QCameraImageProcessing::WhiteBalanceMode>();
- const bool isPhotographyWhiteBalanceSupported = isWhiteBalanceModeSupported(mode);
-#if QT_CONFIG(linux_v4l)
- if (!isPhotographyWhiteBalanceSupported)
- return m_v4lImageControl->isParameterValueSupported(parameter, value);
-#endif
- return isPhotographyWhiteBalanceSupported;
- }
- case ColorTemperature: {
-#if QT_CONFIG(linux_v4l)
- return m_v4lImageControl->isParameterValueSupported(parameter, value);
-#else
- return false;
-#endif
- }
- case ColorFilter: {
- const QCameraImageProcessing::ColorFilter filter = value.value<QCameraImageProcessing::ColorFilter>();
-#if QT_CONFIG(gstreamer_photography)
- return m_filterMap.contains(filter);
-#else
- return filter == QCameraImageProcessing::ColorFilterNone;
-#endif
- }
- default:
- break;
- }
-
- return false;
-}
-
-QVariant CameraBinImageProcessing::parameter(
- QCameraImageProcessingControl::ProcessingParameter parameter) const
-{
- switch (parameter) {
- case QCameraImageProcessingControl::WhiteBalancePreset: {
- const QCameraImageProcessing::WhiteBalanceMode mode = whiteBalanceMode();
-#if QT_CONFIG(linux_v4l)
- if (mode == QCameraImageProcessing::WhiteBalanceAuto
- || mode == QCameraImageProcessing::WhiteBalanceManual) {
- return m_v4lImageControl->parameter(parameter);
- }
-#endif
- return QVariant::fromValue<QCameraImageProcessing::WhiteBalanceMode>(mode);
- }
- case QCameraImageProcessingControl::ColorTemperature: {
-#if QT_CONFIG(linux_v4l)
- return m_v4lImageControl->parameter(parameter);
-#else
- return QVariant();
-#endif
- }
- case QCameraImageProcessingControl::ColorFilter:
-#if QT_CONFIG(gstreamer_photography)
- if (GstPhotography *photography = m_session->photography()) {
-#if GST_CHECK_VERSION(1, 0, 0)
- GstPhotographyColorToneMode mode = GST_PHOTOGRAPHY_COLOR_TONE_MODE_NORMAL;
- gst_photography_get_color_tone_mode(photography, &mode);
-#else
- GstColourToneMode mode = GST_PHOTOGRAPHY_COLOUR_TONE_MODE_NORMAL;
- gst_photography_get_colour_tone_mode(photography, &mode);
-#endif
- return QVariant::fromValue(m_filterMap.key(mode, QCameraImageProcessing::ColorFilterNone));
- }
-#endif
- return QVariant::fromValue(QCameraImageProcessing::ColorFilterNone);
- default: {
- const bool isGstParameterSupported = m_values.contains(parameter);
-#if QT_CONFIG(linux_v4l)
- if (!isGstParameterSupported) {
- if (parameter == QCameraImageProcessingControl::BrightnessAdjustment
- || parameter == QCameraImageProcessingControl::ContrastAdjustment
- || parameter == QCameraImageProcessingControl::SaturationAdjustment
- || parameter == QCameraImageProcessingControl::SharpeningAdjustment) {
- return m_v4lImageControl->parameter(parameter);
- }
- }
-#endif
- return isGstParameterSupported
- ? QVariant(m_values.value(parameter))
- : QVariant();
- }
- }
-}
-
-void CameraBinImageProcessing::setParameter(QCameraImageProcessingControl::ProcessingParameter parameter,
- const QVariant &value)
-{
- switch (parameter) {
- case ContrastAdjustment: {
- if (!setColorBalanceValue("contrast", value.toReal())) {
-#if QT_CONFIG(linux_v4l)
- m_v4lImageControl->setParameter(parameter, value);
-#endif
- }
- }
- break;
- case BrightnessAdjustment: {
- if (!setColorBalanceValue("brightness", value.toReal())) {
-#if QT_CONFIG(linux_v4l)
- m_v4lImageControl->setParameter(parameter, value);
-#endif
- }
- }
- break;
- case SaturationAdjustment: {
- if (!setColorBalanceValue("saturation", value.toReal())) {
-#if QT_CONFIG(linux_v4l)
- m_v4lImageControl->setParameter(parameter, value);
-#endif
- }
- }
- break;
- case SharpeningAdjustment: {
-#if QT_CONFIG(linux_v4l)
- m_v4lImageControl->setParameter(parameter, value);
-#endif
- }
- break;
- case WhiteBalancePreset: {
- if (!setWhiteBalanceMode(value.value<QCameraImageProcessing::WhiteBalanceMode>())) {
-#if QT_CONFIG(linux_v4l)
- const QCameraImageProcessing::WhiteBalanceMode mode =
- value.value<QCameraImageProcessing::WhiteBalanceMode>();
- if (mode == QCameraImageProcessing::WhiteBalanceAuto
- || mode == QCameraImageProcessing::WhiteBalanceManual) {
- m_v4lImageControl->setParameter(parameter, value);
- return;
- }
-#endif
- }
- }
- break;
- case QCameraImageProcessingControl::ColorTemperature: {
-#if QT_CONFIG(linux_v4l)
- m_v4lImageControl->setParameter(parameter, value);
-#endif
- break;
- }
- case QCameraImageProcessingControl::ColorFilter:
-#if QT_CONFIG(gstreamer_photography)
- if (GstPhotography *photography = m_session->photography()) {
-#if GST_CHECK_VERSION(1, 0, 0)
- gst_photography_set_color_tone_mode(photography, m_filterMap.value(
- value.value<QCameraImageProcessing::ColorFilter>(),
- GST_PHOTOGRAPHY_COLOR_TONE_MODE_NORMAL));
-#else
- gst_photography_set_colour_tone_mode(photography, m_filterMap.value(
- value.value<QCameraImageProcessing::ColorFilter>(),
- GST_PHOTOGRAPHY_COLOUR_TONE_MODE_NORMAL));
-#endif
- }
-#endif
- break;
- default:
- break;
- }
-
- updateColorBalanceValues();
-}
-
-#if QT_CONFIG(gstreamer_photography)
-void CameraBinImageProcessing::lockWhiteBalance()
-{
-#if GST_CHECK_VERSION(1, 2, 0)
- if (GstPhotography *photography = m_session->photography()) {
- gst_photography_set_white_balance_mode(photography, GST_PHOTOGRAPHY_WB_MODE_MANUAL);
- }
-#endif
-}
-
-void CameraBinImageProcessing::unlockWhiteBalance()
-{
- if (GstPhotography *photography = m_session->photography()) {
- gst_photography_set_white_balance_mode(
- photography, m_mappedWbValues.key(m_whiteBalanceMode));
- }
-}
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.h b/src/plugins/gstreamer/camerabin/camerabinimageprocessing.h
deleted file mode 100644
index 259138e91..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINIMAGEPROCESSINGCONTROL_H
-#define CAMERABINIMAGEPROCESSINGCONTROL_H
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <qcamera.h>
-#include <qcameraimageprocessingcontrol.h>
-
-#include <gst/gst.h>
-#include <glib.h>
-
-#if QT_CONFIG(gstreamer_photography)
-# include <gst/interfaces/photography.h>
-# if !GST_CHECK_VERSION(1,0,0)
-typedef GstWhiteBalanceMode GstPhotographyWhiteBalanceMode;
-typedef GstColourToneMode GstPhotographyColorToneMode;
-# endif
-#endif
-
-QT_BEGIN_NAMESPACE
-
-#if QT_CONFIG(linux_v4l)
-class CameraBinV4LImageProcessing;
-#endif
-
-class CameraBinSession;
-
-class CameraBinImageProcessing : public QCameraImageProcessingControl
-{
- Q_OBJECT
-
-public:
- CameraBinImageProcessing(CameraBinSession *session);
- virtual ~CameraBinImageProcessing();
-
- QCameraImageProcessing::WhiteBalanceMode whiteBalanceMode() const;
- bool setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode);
- bool isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode mode) const;
-
- bool isParameterSupported(ProcessingParameter) const override;
- bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const override;
- QVariant parameter(ProcessingParameter parameter) const override;
- void setParameter(ProcessingParameter parameter, const QVariant &value) override;
-
-#if QT_CONFIG(gstreamer_photography)
- void lockWhiteBalance();
- void unlockWhiteBalance();
-#endif
-
-private:
- bool setColorBalanceValue(const QString& channel, qreal value);
- void updateColorBalanceValues();
-
-private:
- CameraBinSession *m_session;
- QMap<QCameraImageProcessingControl::ProcessingParameter, int> m_values;
-#if QT_CONFIG(gstreamer_photography)
- QMap<GstPhotographyWhiteBalanceMode, QCameraImageProcessing::WhiteBalanceMode> m_mappedWbValues;
- QMap<QCameraImageProcessing::ColorFilter, GstPhotographyColorToneMode> m_filterMap;
-#endif
- QCameraImageProcessing::WhiteBalanceMode m_whiteBalanceMode;
-
-#if QT_CONFIG(linux_v4l)
- CameraBinV4LImageProcessing *m_v4lImageControl;
-#endif
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINIMAGEPROCESSINGCONTROL_H
diff --git a/src/plugins/gstreamer/camerabin/camerabininfocontrol.cpp b/src/plugins/gstreamer/camerabin/camerabininfocontrol.cpp
deleted file mode 100644
index 6aa3aeb61..000000000
--- a/src/plugins/gstreamer/camerabin/camerabininfocontrol.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include "camerabininfocontrol.h"
-
-#include <private/qgstutils_p.h>
-
-QT_BEGIN_NAMESPACE
-
-CameraBinInfoControl::CameraBinInfoControl(GstElementFactory *sourceFactory, QObject *parent)
- : QCameraInfoControl(parent)
- , m_sourceFactory(sourceFactory)
-{
- gst_object_ref(GST_OBJECT(m_sourceFactory));
-}
-
-CameraBinInfoControl::~CameraBinInfoControl()
-{
- gst_object_unref(GST_OBJECT(m_sourceFactory));
-}
-
-QCamera::Position CameraBinInfoControl::cameraPosition(const QString &device) const
-{
- return QGstUtils::cameraPosition(device, m_sourceFactory);
-}
-
-int CameraBinInfoControl::cameraOrientation(const QString &device) const
-{
- return QGstUtils::cameraOrientation(device, m_sourceFactory);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabininfocontrol.h b/src/plugins/gstreamer/camerabin/camerabininfocontrol.h
deleted file mode 100644
index 9c801e804..000000000
--- a/src/plugins/gstreamer/camerabin/camerabininfocontrol.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABININFOCONTROL_H
-#define CAMERABININFOCONTROL_H
-
-#include <qcamerainfocontrol.h>
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinInfoControl : public QCameraInfoControl
-{
- Q_OBJECT
-public:
- CameraBinInfoControl(GstElementFactory *sourceFactory, QObject *parent);
- ~CameraBinInfoControl();
-
- QCamera::Position cameraPosition(const QString &deviceName) const override;
- int cameraOrientation(const QString &deviceName) const override;
-
-private:
- GstElementFactory * const m_sourceFactory;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/camerabin/camerabinlocks.cpp b/src/plugins/gstreamer/camerabin/camerabinlocks.cpp
deleted file mode 100644
index 89be2ac5d..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinlocks.cpp
+++ /dev/null
@@ -1,259 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabinlocks.h"
-#include "camerabinsession.h"
-#include "camerabinfocus.h"
-#include "camerabinimageprocessing.h"
-
-#include <QtCore/qcoreevent.h>
-
-#include <gst/interfaces/photography.h>
-
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-CameraBinLocks::CameraBinLocks(CameraBinSession *session)
- :QCameraLocksControl(session),
- m_session(session),
- m_focus(m_session->cameraFocusControl())
-{
- connect(m_focus, SIGNAL(_q_focusStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason)),
- this, SLOT(updateFocusStatus(QCamera::LockStatus,QCamera::LockChangeReason)));
-}
-
-CameraBinLocks::~CameraBinLocks()
-{
-}
-
-QCamera::LockTypes CameraBinLocks::supportedLocks() const
-{
- QCamera::LockTypes locks = QCamera::LockFocus;
-
-#if GST_CHECK_VERSION(1, 2, 0)
- if (GstPhotography *photography = m_session->photography()) {
- if (gst_photography_get_capabilities(photography) & GST_PHOTOGRAPHY_CAPS_WB_MODE)
- locks |= QCamera::LockWhiteBalance;
-
- if (GstElement *source = m_session->cameraSource()) {
- if (g_object_class_find_property(
- G_OBJECT_GET_CLASS(source), "exposure-mode")) {
- locks |= QCamera::LockExposure;
- }
- }
- }
-#endif
-
- return locks;
-}
-
-QCamera::LockStatus CameraBinLocks::lockStatus(QCamera::LockType lock) const
-{
- switch (lock) {
- case QCamera::LockFocus:
- return m_focus->focusStatus();
-#if GST_CHECK_VERSION(1, 2, 0)
- case QCamera::LockExposure:
- if (m_pendingLocks & QCamera::LockExposure)
- return QCamera::Searching;
- return isExposureLocked() ? QCamera::Locked : QCamera::Unlocked;
- case QCamera::LockWhiteBalance:
- if (m_pendingLocks & QCamera::LockWhiteBalance)
- return QCamera::Searching;
- return isWhiteBalanceLocked() ? QCamera::Locked : QCamera::Unlocked;
-#endif
- default:
- return QCamera::Unlocked;
- }
-}
-
-void CameraBinLocks::searchAndLock(QCamera::LockTypes locks)
-{
- m_pendingLocks &= ~locks;
-
- if (locks & QCamera::LockFocus) {
- m_pendingLocks |= QCamera::LockFocus;
- m_focus->_q_startFocusing();
- }
-#if GST_CHECK_VERSION(1, 2, 0)
- if (!m_pendingLocks)
- m_lockTimer.stop();
-
- if (locks & QCamera::LockExposure) {
- if (isExposureLocked()) {
- unlockExposure(QCamera::Searching, QCamera::UserRequest);
- m_pendingLocks |= QCamera::LockExposure;
- m_lockTimer.start(1000, this);
- } else {
- lockExposure(QCamera::UserRequest);
- }
- }
- if (locks & QCamera::LockWhiteBalance) {
- if (isWhiteBalanceLocked()) {
- unlockWhiteBalance(QCamera::Searching, QCamera::UserRequest);
- m_pendingLocks |= QCamera::LockWhiteBalance;
- m_lockTimer.start(1000, this);
- } else {
- lockWhiteBalance(QCamera::UserRequest);
- }
- }
-#endif
-
-}
-
-void CameraBinLocks::unlock(QCamera::LockTypes locks)
-{
- m_pendingLocks &= ~locks;
-
- if (locks & QCamera::LockFocus)
- m_focus->_q_stopFocusing();
-
-#if GST_CHECK_VERSION(1, 2, 0)
- if (!m_pendingLocks)
- m_lockTimer.stop();
-
- if (locks & QCamera::LockExposure)
- unlockExposure(QCamera::Unlocked, QCamera::UserRequest);
- if (locks & QCamera::LockWhiteBalance)
- unlockWhiteBalance(QCamera::Unlocked, QCamera::UserRequest);
-#endif
-}
-
-void CameraBinLocks::updateFocusStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason)
-{
- if (status != QCamera::Searching)
- m_pendingLocks &= ~QCamera::LockFocus;
-
-#if GST_CHECK_VERSION(1, 2, 0)
- if (status == QCamera::Locked && !m_lockTimer.isActive()) {
- if (m_pendingLocks & QCamera::LockExposure)
- lockExposure(QCamera::LockAcquired);
- if (m_pendingLocks & QCamera::LockWhiteBalance)
- lockWhiteBalance(QCamera::LockAcquired);
- }
-#endif
- emit lockStatusChanged(QCamera::LockFocus, status, reason);
-}
-
-#if GST_CHECK_VERSION(1, 2, 0)
-
-void CameraBinLocks::timerEvent(QTimerEvent *event)
-{
- if (event->timerId() != m_lockTimer.timerId())
- return QCameraLocksControl::timerEvent(event);
-
- m_lockTimer.stop();
-
- if (!(m_pendingLocks & QCamera::LockFocus)) {
- if (m_pendingLocks & QCamera::LockExposure)
- lockExposure(QCamera::LockAcquired);
- if (m_pendingLocks & QCamera::LockWhiteBalance)
- lockWhiteBalance(QCamera::LockAcquired);
- }
-}
-
-bool CameraBinLocks::isExposureLocked() const
-{
- if (GstElement *source = m_session->cameraSource()) {
- GstPhotographyExposureMode exposureMode = GST_PHOTOGRAPHY_EXPOSURE_MODE_AUTO;
- g_object_get (G_OBJECT(source), "exposure-mode", &exposureMode, NULL);
- return exposureMode == GST_PHOTOGRAPHY_EXPOSURE_MODE_MANUAL;
- } else {
- return false;
- }
-}
-
-void CameraBinLocks::lockExposure(QCamera::LockChangeReason reason)
-{
- GstElement *source = m_session->cameraSource();
- if (!source)
- return;
-
- m_pendingLocks &= ~QCamera::LockExposure;
- g_object_set(
- G_OBJECT(source),
- "exposure-mode",
- GST_PHOTOGRAPHY_EXPOSURE_MODE_MANUAL,
- NULL);
- emit lockStatusChanged(QCamera::LockExposure, QCamera::Locked, reason);
-}
-
-void CameraBinLocks::unlockExposure(QCamera::LockStatus status, QCamera::LockChangeReason reason)
-{
- GstElement *source = m_session->cameraSource();
- if (!source)
- return;
-
- g_object_set(
- G_OBJECT(source),
- "exposure-mode",
- GST_PHOTOGRAPHY_EXPOSURE_MODE_AUTO,
- NULL);
- emit lockStatusChanged(QCamera::LockExposure, status, reason);
-}
-
-bool CameraBinLocks::isWhiteBalanceLocked() const
-{
- if (GstPhotography *photography = m_session->photography()) {
- GstPhotographyWhiteBalanceMode whiteBalanceMode;
- return gst_photography_get_white_balance_mode(photography, &whiteBalanceMode)
- && whiteBalanceMode == GST_PHOTOGRAPHY_WB_MODE_MANUAL;
- } else {
- return false;
- }
-}
-
-void CameraBinLocks::lockWhiteBalance(QCamera::LockChangeReason reason)
-{
- m_pendingLocks &= ~QCamera::LockWhiteBalance;
- m_session->imageProcessingControl()->lockWhiteBalance();
- emit lockStatusChanged(QCamera::LockWhiteBalance, QCamera::Locked, reason);
-}
-
-void CameraBinLocks::unlockWhiteBalance(
- QCamera::LockStatus status, QCamera::LockChangeReason reason)
-{
- m_session->imageProcessingControl()->lockWhiteBalance();
- emit lockStatusChanged(QCamera::LockWhiteBalance, status, reason);
-}
-
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinlocks.h b/src/plugins/gstreamer/camerabin/camerabinlocks.h
deleted file mode 100644
index cd592ffd2..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinlocks.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINLOCKSCONTROL_H
-#define CAMERABINLOCKSCONTROL_H
-
-#include <qcamera.h>
-#include <qcameralockscontrol.h>
-
-#include <QtCore/qbasictimer.h>
-
-#include <gst/gst.h>
-#include <glib.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-class CameraBinFocus;
-
-class CameraBinLocks : public QCameraLocksControl
-{
- Q_OBJECT
-
-public:
- CameraBinLocks(CameraBinSession *session);
- virtual ~CameraBinLocks();
-
- QCamera::LockTypes supportedLocks() const override;
-
- QCamera::LockStatus lockStatus(QCamera::LockType lock) const override;
-
- void searchAndLock(QCamera::LockTypes locks) override;
- void unlock(QCamera::LockTypes locks) override;
-
-protected:
-#if GST_CHECK_VERSION(1, 2, 0)
- void timerEvent(QTimerEvent *event) override;
-#endif
-
-private slots:
- void updateFocusStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason);
-
-private:
-#if GST_CHECK_VERSION(1, 2, 0)
- bool isExposureLocked() const;
- void lockExposure(QCamera::LockChangeReason reason);
- void unlockExposure(QCamera::LockStatus status, QCamera::LockChangeReason reason);
-
- bool isWhiteBalanceLocked() const;
- void lockWhiteBalance(QCamera::LockChangeReason reason);
- void unlockWhiteBalance(QCamera::LockStatus status, QCamera::LockChangeReason reason);
-#endif
-
- CameraBinSession *m_session;
- CameraBinFocus *m_focus;
- QBasicTimer m_lockTimer;
- QCamera::LockTypes m_pendingLocks;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/camerabin/camerabinmetadata.cpp b/src/plugins/gstreamer/camerabin/camerabinmetadata.cpp
deleted file mode 100644
index afda2346d..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinmetadata.cpp
+++ /dev/null
@@ -1,234 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabinmetadata.h"
-
-#include <QtMultimedia/qmediametadata.h>
-
-#include <gst/gst.h>
-#include <gst/gstversion.h>
-#include <private/qgstutils_p.h>
-
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-namespace {
- struct QGStreamerMetaDataKey
- {
- QString qtName;
- const char *gstName;
- QVariant::Type type;
-
- QGStreamerMetaDataKey(const QString &qtn, const char *gstn, QVariant::Type t)
- : qtName(qtn)
- , gstName(gstn)
- , type(t)
- { }
- };
-}
-
-typedef QList<QGStreamerMetaDataKey> QGStreamerMetaDataKeys;
-Q_GLOBAL_STATIC(QGStreamerMetaDataKeys, metadataKeys)
-
-static const QGStreamerMetaDataKeys *qt_gstreamerMetaDataKeys()
-{
- if (metadataKeys->isEmpty()) {
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Title, GST_TAG_TITLE, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::SubTitle, 0, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Author, 0, QVariant::String));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Comment, GST_TAG_COMMENT, QVariant::String));
-#if GST_CHECK_VERSION(0,10,31)
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Date, GST_TAG_DATE_TIME, QVariant::DateTime));
-#endif
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Description, GST_TAG_DESCRIPTION, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Category, 0, QVariant::String));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Genre, GST_TAG_GENRE, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Year, 0, QVariant::Int));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::UserRating, , QVariant::Int));
-
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Language, GST_TAG_LANGUAGE_CODE, QVariant::String));
-
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Publisher, GST_TAG_ORGANIZATION, QVariant::String));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Copyright, GST_TAG_COPYRIGHT, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::ParentalRating, 0, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::RatingOrganisation, 0, QVariant::String));
-
- // Media
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Size, 0, QVariant::Int));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::MediaType, 0, QVariant::String));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Duration, GST_TAG_DURATION, QVariant::Int));
-
- // Audio
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::AudioBitRate, GST_TAG_BITRATE, QVariant::Int));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::AudioCodec, GST_TAG_AUDIO_CODEC, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::ChannelCount, 0, QVariant::Int));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::SampleRate, 0, QVariant::Int));
-
- // Music
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::AlbumTitle, GST_TAG_ALBUM, QVariant::String));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::AlbumArtist, GST_TAG_ARTIST, QVariant::String));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::ContributingArtist, GST_TAG_PERFORMER, QVariant::String));
-#if GST_CHECK_VERSION(0,10,19)
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Composer, GST_TAG_COMPOSER, QVariant::String));
-#endif
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Conductor, 0, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Lyrics, 0, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Mood, 0, QVariant::String));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::TrackNumber, GST_TAG_TRACK_NUMBER, QVariant::Int));
-
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::CoverArtUrlSmall, 0, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::CoverArtUrlLarge, 0, QVariant::String));
-
- // Image/Video
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Resolution, 0, QVariant::Size));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::PixelAspectRatio, 0, QVariant::Size));
-
- // Video
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::VideoFrameRate, 0, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::VideoBitRate, 0, QVariant::Double));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::VideoCodec, GST_TAG_VIDEO_CODEC, QVariant::String));
-
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::PosterUrl, 0, QVariant::String));
-
- // Movie
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::ChapterNumber, 0, QVariant::Int));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Director, 0, QVariant::String));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::LeadPerformer, GST_TAG_PERFORMER, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Writer, 0, QVariant::String));
-#if GST_CHECK_VERSION(0,10,30)
- // Photos
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::CameraManufacturer, GST_TAG_DEVICE_MANUFACTURER, QVariant::String));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::CameraModel, GST_TAG_DEVICE_MODEL, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Event, 0, QVariant::String));
- //metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Subject, 0, QVariant::String));
-
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::Orientation, GST_TAG_IMAGE_ORIENTATION, QVariant::String));
-
- // GPS
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::GPSLatitude, GST_TAG_GEO_LOCATION_LATITUDE, QVariant::Double));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::GPSLongitude, GST_TAG_GEO_LOCATION_LONGITUDE, QVariant::Double));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::GPSAltitude, GST_TAG_GEO_LOCATION_ELEVATION, QVariant::Double));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::GPSTrack, GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION, QVariant::Double));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::GPSSpeed, GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, QVariant::Double));
- metadataKeys->append(QGStreamerMetaDataKey(QMediaMetaData::GPSImgDirection, GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, QVariant::Double));
-#endif
- }
-
- return metadataKeys;
-}
-
-CameraBinMetaData::CameraBinMetaData(QObject *parent)
- :QMetaDataWriterControl(parent)
-{
-}
-
-QVariant CameraBinMetaData::metaData(const QString &key) const
-{
-#if GST_CHECK_VERSION(0,10,30)
- if (key == QMediaMetaData::Orientation) {
- return QGstUtils::fromGStreamerOrientation(m_values.value(QByteArray(GST_TAG_IMAGE_ORIENTATION)));
- } else if (key == QMediaMetaData::GPSSpeed) {
- const double metersPerSec = m_values.value(QByteArray(GST_TAG_GEO_LOCATION_MOVEMENT_SPEED)).toDouble();
- return (metersPerSec * 3600) / 1000;
- }
-#endif
-
- const auto keys = *qt_gstreamerMetaDataKeys();
- for (const QGStreamerMetaDataKey &metadataKey : keys) {
- if (metadataKey.qtName == key)
- return m_values.value(QByteArray::fromRawData(metadataKey.gstName, qstrlen(metadataKey.gstName)));
- }
- return QVariant();
-}
-
-void CameraBinMetaData::setMetaData(const QString &key, const QVariant &value)
-{
- QVariant correctedValue = value;
-#if GST_CHECK_VERSION(0,10,30)
- if (value.isValid()) {
- if (key == QMediaMetaData::Orientation) {
- correctedValue = QGstUtils::toGStreamerOrientation(value);
- } else if (key == QMediaMetaData::GPSSpeed) {
- // kilometers per hour to meters per second.
- correctedValue = (value.toDouble() * 1000) / 3600;
- }
- }
-#endif
-
- const auto keys = *qt_gstreamerMetaDataKeys();
- for (const QGStreamerMetaDataKey &metadataKey : keys) {
- if (metadataKey.qtName == key) {
- const char *name = metadataKey.gstName;
-
- if (correctedValue.isValid()) {
- correctedValue.convert(metadataKey.type);
- m_values.insert(QByteArray::fromRawData(name, qstrlen(name)), correctedValue);
- } else {
- m_values.remove(QByteArray::fromRawData(name, qstrlen(name)));
- }
-
- emit QMetaDataWriterControl::metaDataChanged();
- emit metaDataChanged(m_values);
-
- return;
- }
- }
-}
-
-QStringList CameraBinMetaData::availableMetaData() const
-{
- static QMap<QByteArray, QString> keysMap;
- if (keysMap.isEmpty()) {
- const auto keys = *qt_gstreamerMetaDataKeys();
- for (const QGStreamerMetaDataKey &metadataKey : keys)
- keysMap[QByteArray(metadataKey.gstName)] = metadataKey.qtName;
- }
-
- QStringList res;
- for (auto it = m_values.keyBegin(), end = m_values.keyEnd(); it != end; ++it) {
- QString tag = keysMap.value(*it);
- if (!tag.isEmpty())
- res.append(tag);
- }
-
- return res;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinmetadata.h b/src/plugins/gstreamer/camerabin/camerabinmetadata.h
deleted file mode 100644
index 5fef7e388..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinmetadata.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINCAPTUREMETADATACONTROL_H
-#define CAMERABINCAPTUREMETADATACONTROL_H
-
-#include <qmetadatawritercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinMetaData : public QMetaDataWriterControl
-{
- Q_OBJECT
-public:
- CameraBinMetaData(QObject *parent);
- virtual ~CameraBinMetaData() {}
-
-
- bool isMetaDataAvailable() const override { return true; }
- bool isWritable() const override { return true; }
-
- QVariant metaData(const QString &key) const override;
- void setMetaData(const QString &key, const QVariant &value) override;
- QStringList availableMetaData() const override;
-
-Q_SIGNALS:
- void metaDataChanged(const QMap<QByteArray, QVariant>&);
-
-private:
- QMap<QByteArray, QVariant> m_values;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINCAPTUREMETADATACONTROL_H
diff --git a/src/plugins/gstreamer/camerabin/camerabinrecorder.cpp b/src/plugins/gstreamer/camerabin/camerabinrecorder.cpp
deleted file mode 100644
index b3505231b..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinrecorder.cpp
+++ /dev/null
@@ -1,298 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabinrecorder.h"
-#include "camerabincontrol.h"
-#include "camerabinresourcepolicy.h"
-#include "camerabinaudioencoder.h"
-#include "camerabinvideoencoder.h"
-#include "camerabincontainer.h"
-#include <QtCore/QDebug>
-
-
-QT_BEGIN_NAMESPACE
-
-CameraBinRecorder::CameraBinRecorder(CameraBinSession *session)
- :QMediaRecorderControl(session),
- m_session(session),
- m_state(QMediaRecorder::StoppedState),
- m_status(QMediaRecorder::UnloadedStatus)
-{
- connect(m_session, SIGNAL(statusChanged(QCamera::Status)), SLOT(updateStatus()));
- connect(m_session, SIGNAL(pendingStateChanged(QCamera::State)), SLOT(updateStatus()));
- connect(m_session, SIGNAL(busyChanged(bool)), SLOT(updateStatus()));
-
- connect(m_session, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64)));
- connect(m_session, SIGNAL(mutedChanged(bool)), this, SIGNAL(mutedChanged(bool)));
- connect(m_session->cameraControl()->resourcePolicy(), SIGNAL(canCaptureChanged()),
- this, SLOT(updateStatus()));
-}
-
-CameraBinRecorder::~CameraBinRecorder()
-{
-}
-
-QUrl CameraBinRecorder::outputLocation() const
-{
- return m_session->outputLocation();
-}
-
-bool CameraBinRecorder::setOutputLocation(const QUrl &sink)
-{
- m_session->setOutputLocation(sink);
- return true;
-}
-
-QMediaRecorder::State CameraBinRecorder::state() const
-{
- return m_state;
-}
-
-QMediaRecorder::Status CameraBinRecorder::status() const
-{
- return m_status;
-}
-
-void CameraBinRecorder::updateStatus()
-{
- QCamera::Status sessionStatus = m_session->status();
-
- QMediaRecorder::State oldState = m_state;
- QMediaRecorder::Status oldStatus = m_status;
-
- if (sessionStatus == QCamera::ActiveStatus &&
- m_session->captureMode().testFlag(QCamera::CaptureVideo)) {
-
- if (!m_session->cameraControl()->resourcePolicy()->canCapture()) {
- m_status = QMediaRecorder::UnavailableStatus;
- m_state = QMediaRecorder::StoppedState;
- m_session->stopVideoRecording();
- } else if (m_state == QMediaRecorder::RecordingState) {
- m_status = QMediaRecorder::RecordingStatus;
- } else {
- m_status = m_session->isBusy() ?
- QMediaRecorder::FinalizingStatus :
- QMediaRecorder::LoadedStatus;
- }
- } else {
- if (m_state == QMediaRecorder::RecordingState) {
- m_state = QMediaRecorder::StoppedState;
- m_session->stopVideoRecording();
- }
- m_status = m_session->pendingState() == QCamera::ActiveState
- && m_session->captureMode().testFlag(QCamera::CaptureVideo)
- ? QMediaRecorder::LoadingStatus
- : QMediaRecorder::UnloadedStatus;
- }
-
- if (m_state != oldState)
- emit stateChanged(m_state);
-
- if (m_status != oldStatus)
- emit statusChanged(m_status);
-}
-
-qint64 CameraBinRecorder::duration() const
-{
- return m_session->duration();
-}
-
-
-void CameraBinRecorder::applySettings()
-{
-#if QT_CONFIG(gstreamer_encodingprofiles)
- CameraBinContainer *containerControl = m_session->mediaContainerControl();
- CameraBinAudioEncoder *audioEncoderControl = m_session->audioEncodeControl();
- CameraBinVideoEncoder *videoEncoderControl = m_session->videoEncodeControl();
-
- containerControl->resetActualContainerFormat();
- audioEncoderControl->resetActualSettings();
- videoEncoderControl->resetActualSettings();
-
- //encodebin doesn't like the encoding profile with ANY caps,
- //if container and codecs are not specified,
- //try to find a commonly used supported combination
- if (containerControl->containerFormat().isEmpty() &&
- audioEncoderControl->audioSettings().codec().isEmpty() &&
- videoEncoderControl->videoSettings().codec().isEmpty()) {
-
- QList<QStringList> candidates;
-
- // By order of preference
-
- // .mp4 (h264, AAC)
- candidates.append(QStringList() << "video/quicktime, variant=(string)iso" << "video/x-h264" << "audio/mpeg, mpegversion=(int)4");
-
- // .mp4 (h264, AC3)
- candidates.append(QStringList() << "video/quicktime, variant=(string)iso" << "video/x-h264" << "audio/x-ac3");
-
- // .mp4 (h264, MP3)
- candidates.append(QStringList() << "video/quicktime, variant=(string)iso" << "video/x-h264" << "audio/mpeg, mpegversion=(int)1, layer=(int)3");
-
- // .mkv (h264, AAC)
- candidates.append(QStringList() << "video/x-matroska" << "video/x-h264" << "audio/mpeg, mpegversion=(int)4");
-
- // .mkv (h264, AC3)
- candidates.append(QStringList() << "video/x-matroska" << "video/x-h264" << "audio/x-ac3");
-
- // .mkv (h264, MP3)
- candidates.append(QStringList() << "video/x-matroska" << "video/x-h264" << "audio/mpeg, mpegversion=(int)1, layer=(int)3");
-
- // .mov (h264, AAC)
- candidates.append(QStringList() << "video/quicktime" << "video/x-h264" << "audio/mpeg, mpegversion=(int)4");
-
- // .mov (h264, MP3)
- candidates.append(QStringList() << "video/quicktime" << "video/x-h264" << "audio/mpeg, mpegversion=(int)1, layer=(int)3");
-
- // .webm (VP8, Vorbis)
- candidates.append(QStringList() << "video/webm" << "video/x-vp8" << "audio/x-vorbis");
-
- // .ogg (Theora, Vorbis)
- candidates.append(QStringList() << "application/ogg" << "video/x-theora" << "audio/x-vorbis");
-
- // .avi (DivX, MP3)
- candidates.append(QStringList() << "video/x-msvideo" << "video/x-divx" << "audio/mpeg, mpegversion=(int)1, layer=(int)3");
-
- for (const QStringList &candidate : qAsConst(candidates)) {
- if (containerControl->supportedContainers().contains(candidate[0]) &&
- videoEncoderControl->supportedVideoCodecs().contains(candidate[1]) &&
- audioEncoderControl->supportedAudioCodecs().contains(candidate[2])) {
- containerControl->setActualContainerFormat(candidate[0]);
-
- QVideoEncoderSettings videoSettings = videoEncoderControl->videoSettings();
- videoSettings.setCodec(candidate[1]);
- videoEncoderControl->setActualVideoSettings(videoSettings);
-
- QAudioEncoderSettings audioSettings = audioEncoderControl->audioSettings();
- audioSettings.setCodec(candidate[2]);
- audioEncoderControl->setActualAudioSettings(audioSettings);
-
- break;
- }
- }
- }
-#endif
-}
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
-
-GstEncodingContainerProfile *CameraBinRecorder::videoProfile()
-{
- GstEncodingContainerProfile *containerProfile = m_session->mediaContainerControl()->createProfile();
-
- if (containerProfile) {
- GstEncodingProfile *audioProfile = m_session->audioEncodeControl()->createProfile();
- GstEncodingProfile *videoProfile = m_session->videoEncodeControl()->createProfile();
-
- if (audioProfile) {
- if (!gst_encoding_container_profile_add_profile(containerProfile, audioProfile))
- gst_encoding_profile_unref(audioProfile);
- }
- if (videoProfile) {
- if (!gst_encoding_container_profile_add_profile(containerProfile, videoProfile))
- gst_encoding_profile_unref(videoProfile);
- }
- }
-
- return containerProfile;
-}
-
-#endif
-
-void CameraBinRecorder::setState(QMediaRecorder::State state)
-{
- if (m_state == state)
- return;
-
- QMediaRecorder::State oldState = m_state;
- QMediaRecorder::Status oldStatus = m_status;
-
- switch (state) {
- case QMediaRecorder::StoppedState:
- m_state = state;
- m_status = QMediaRecorder::FinalizingStatus;
- m_session->stopVideoRecording();
- break;
- case QMediaRecorder::PausedState:
- emit error(QMediaRecorder::ResourceError, tr("QMediaRecorder::pause() is not supported by camerabin2."));
- break;
- case QMediaRecorder::RecordingState:
-
- if (m_session->status() != QCamera::ActiveStatus) {
- emit error(QMediaRecorder::ResourceError, tr("Service has not been started"));
- } else if (!m_session->cameraControl()->resourcePolicy()->canCapture()) {
- emit error(QMediaRecorder::ResourceError, tr("Recording permissions are not available"));
- } else {
- m_session->recordVideo();
- m_state = state;
- m_status = QMediaRecorder::RecordingStatus;
- emit actualLocationChanged(m_session->outputLocation());
- }
- }
-
- if (m_state != oldState)
- emit stateChanged(m_state);
-
- if (m_status != oldStatus)
- emit statusChanged(m_status);
-}
-
-bool CameraBinRecorder::isMuted() const
-{
- return m_session->isMuted();
-}
-
-qreal CameraBinRecorder::volume() const
-{
- return 1.0;
-}
-
-void CameraBinRecorder::setMuted(bool muted)
-{
- m_session->setMuted(muted);
-}
-
-void CameraBinRecorder::setVolume(qreal volume)
-{
- if (!qFuzzyCompare(volume, qreal(1.0)))
- qWarning() << "Media service doesn't support recorder audio gain.";
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/plugins/gstreamer/camerabin/camerabinrecorder.h b/src/plugins/gstreamer/camerabin/camerabinrecorder.h
deleted file mode 100644
index 8bd922fb8..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinrecorder.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef CAMERABINRECORDERCONTROL_H
-#define CAMERABINRECORDERCONTROL_H
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <qmediarecordercontrol.h>
-#include "camerabinsession.h"
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
-#include <gst/pbutils/encoding-profile.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinRecorder : public QMediaRecorderControl
-{
- Q_OBJECT
-
-public:
- CameraBinRecorder(CameraBinSession *session);
- virtual ~CameraBinRecorder();
-
- QUrl outputLocation() const override;
- bool setOutputLocation(const QUrl &sink) override;
-
- QMediaRecorder::State state() const override;
- QMediaRecorder::Status status() const override;
-
- qint64 duration() const override;
-
- bool isMuted() const override;
- qreal volume() const override;
-
- void applySettings() override;
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
- GstEncodingContainerProfile *videoProfile();
-#endif
-
-public slots:
- void setState(QMediaRecorder::State state) override;
- void setMuted(bool) override;
- void setVolume(qreal volume) override;
-
- void updateStatus();
-
-private:
- CameraBinSession *m_session;
- QMediaRecorder::State m_state;
- QMediaRecorder::Status m_status;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINCAPTURECORNTROL_H
diff --git a/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.cpp b/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.cpp
deleted file mode 100644
index 6da86e569..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.cpp
+++ /dev/null
@@ -1,242 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "QtMultimedia/private/qtmultimediaglobal_p.h"
-#include "camerabinresourcepolicy.h"
-//#define DEBUG_RESOURCE_POLICY
-#include <QtCore/qdebug.h>
-#include <QtCore/qset.h>
-
-#if QT_CONFIG(resourcepolicy)
-#include <policy/resource.h>
-#include <policy/resources.h>
-#include <policy/resource-set.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-CamerabinResourcePolicy::CamerabinResourcePolicy(QObject *parent) :
- QObject(parent),
- m_resourceSet(NoResources),
- m_releasingResources(false),
- m_canCapture(false)
-{
-#if QT_CONFIG(resourcepolicy)
- //loaded resource set is also kept requested for image and video capture sets
- m_resource = new ResourcePolicy::ResourceSet("camera");
- m_resource->setAlwaysReply();
- m_resource->initAndConnect();
-
- connect(m_resource, SIGNAL(resourcesGranted(QList<ResourcePolicy::ResourceType>)),
- SLOT(handleResourcesGranted()));
- connect(m_resource, SIGNAL(resourcesDenied()), SIGNAL(resourcesDenied()));
- connect(m_resource, SIGNAL(lostResources()), SLOT(handleResourcesLost()));
- connect(m_resource, SIGNAL(resourcesReleased()), SLOT(handleResourcesReleased()));
- connect(m_resource, SIGNAL(resourcesBecameAvailable(QList<ResourcePolicy::ResourceType>)),
- this, SLOT(resourcesAvailable()));
- connect(m_resource, SIGNAL(updateOK()), this, SLOT(updateCanCapture()));
-#endif
-}
-
-CamerabinResourcePolicy::~CamerabinResourcePolicy()
-{
-#if QT_CONFIG(resourcepolicy)
- //ensure the resources are released
- if (m_resourceSet != NoResources)
- setResourceSet(NoResources);
-
- //don't delete the resource set until resources are released
- if (m_releasingResources) {
- m_resource->connect(m_resource, SIGNAL(resourcesReleased()),
- SLOT(deleteLater()));
- } else {
- delete m_resource;
- m_resource = 0;
- }
-#endif
-}
-
-CamerabinResourcePolicy::ResourceSet CamerabinResourcePolicy::resourceSet() const
-{
- return m_resourceSet;
-}
-
-void CamerabinResourcePolicy::setResourceSet(CamerabinResourcePolicy::ResourceSet set)
-{
- CamerabinResourcePolicy::ResourceSet oldSet = m_resourceSet;
- m_resourceSet = set;
-
-#ifdef DEBUG_RESOURCE_POLICY
- qDebug() << Q_FUNC_INFO << set;
-#endif
-
-#if QT_CONFIG(resourcepolicy)
- QSet<ResourcePolicy::ResourceType> requestedTypes;
-
- switch (set) {
- case NoResources:
- break;
- case LoadedResources:
- requestedTypes << ResourcePolicy::LensCoverType //to detect lens cover is opened/closed
- << ResourcePolicy::VideoRecorderType; //to open camera device
- break;
- case ImageCaptureResources:
- requestedTypes << ResourcePolicy::LensCoverType
- << ResourcePolicy::VideoPlaybackType
- << ResourcePolicy::VideoRecorderType
- << ResourcePolicy::LedsType;
- break;
- case VideoCaptureResources:
- requestedTypes << ResourcePolicy::LensCoverType
- << ResourcePolicy::VideoPlaybackType
- << ResourcePolicy::VideoRecorderType
- << ResourcePolicy::AudioPlaybackType
- << ResourcePolicy::AudioRecorderType
- << ResourcePolicy::LedsType;
- break;
- }
-
- QSet<ResourcePolicy::ResourceType> currentTypes;
- const auto resources = m_resource->resources();
- currentTypes.reserve(resources.size());
- for (ResourcePolicy::Resource *resource : resources)
- currentTypes << resource->type();
-
- const auto diffCurrentWithRequested = currentTypes - requestedTypes;
- for (ResourcePolicy::ResourceType resourceType : diffCurrentWithRequested)
- m_resource->deleteResource(resourceType);
-
- const auto diffRequestedWithCurrent = requestedTypes - currentTypes;
- for (ResourcePolicy::ResourceType resourceType : diffRequestedWithCurrent) {
- if (resourceType == ResourcePolicy::LensCoverType) {
- ResourcePolicy::LensCoverResource *lensCoverResource = new ResourcePolicy::LensCoverResource;
- lensCoverResource->setOptional(true);
- m_resource->addResourceObject(lensCoverResource);
- } else if (resourceType == ResourcePolicy::AudioPlaybackType) {
- ResourcePolicy::Resource *resource = new ResourcePolicy::AudioResource;
- resource->setOptional(true);
- m_resource->addResourceObject(resource);
- } else if (resourceType == ResourcePolicy::AudioRecorderType) {
- ResourcePolicy::Resource *resource = new ResourcePolicy::AudioRecorderResource;
- resource->setOptional(true);
- m_resource->addResourceObject(resource);
- } else {
- m_resource->addResource(resourceType);
- }
- }
-
- m_resource->update();
- if (set != NoResources) {
- m_resource->acquire();
- } else {
- if (oldSet != NoResources) {
- m_releasingResources = true;
- m_resource->release();
- }
- }
-#else
- Q_UNUSED(oldSet);
- updateCanCapture();
-#endif
-}
-
-bool CamerabinResourcePolicy::isResourcesGranted() const
-{
-#if QT_CONFIG(resourcepolicy)
- const auto resources = m_resource->resources();
- for (ResourcePolicy::Resource *resource : resources)
- if (!resource->isOptional() && !resource->isGranted())
- return false;
-#endif
- return true;
-}
-
-void CamerabinResourcePolicy::handleResourcesLost()
-{
- updateCanCapture();
- emit resourcesLost();
-}
-
-void CamerabinResourcePolicy::handleResourcesGranted()
-{
- updateCanCapture();
- emit resourcesGranted();
-}
-
-void CamerabinResourcePolicy::handleResourcesReleased()
-{
-#if QT_CONFIG(resourcepolicy)
-#ifdef DEBUG_RESOURCE_POLICY
- qDebug() << Q_FUNC_INFO;
-#endif
- m_releasingResources = false;
-#endif
- updateCanCapture();
-}
-
-void CamerabinResourcePolicy::resourcesAvailable()
-{
-#if QT_CONFIG(resourcepolicy)
- if (m_resourceSet != NoResources) {
- m_resource->acquire();
- }
-#endif
-}
-
-bool CamerabinResourcePolicy::canCapture() const
-{
- return m_canCapture;
-}
-
-void CamerabinResourcePolicy::updateCanCapture()
-{
- const bool wasAbleToRecord = m_canCapture;
- m_canCapture = (m_resourceSet == VideoCaptureResources) || (m_resourceSet == ImageCaptureResources);
-#if QT_CONFIG(resourcepolicy)
- const auto resources = m_resource->resources();
- for (ResourcePolicy::Resource *resource : resources) {
- if (resource->type() != ResourcePolicy::LensCoverType)
- m_canCapture = m_canCapture && resource->isGranted();
- }
-#endif
- if (wasAbleToRecord != m_canCapture)
- emit canCaptureChanged();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.h b/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.h
deleted file mode 100644
index c54595bcc..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERARESOURCEPOLICY_H
-#define CAMERARESOURCEPOLICY_H
-
-#include <QtCore/qobject.h>
-
-namespace ResourcePolicy {
-class ResourceSet;
-};
-
-QT_BEGIN_NAMESPACE
-
-class CamerabinResourcePolicy : public QObject
-{
- Q_OBJECT
-public:
- enum ResourceSet {
- NoResources,
- LoadedResources,
- ImageCaptureResources,
- VideoCaptureResources
- };
-
- CamerabinResourcePolicy(QObject *parent);
- ~CamerabinResourcePolicy();
-
- ResourceSet resourceSet() const;
- void setResourceSet(ResourceSet set);
-
- bool isResourcesGranted() const;
-
- bool canCapture() const;
-
-Q_SIGNALS:
- void resourcesDenied();
- void resourcesGranted();
- void resourcesLost();
- void canCaptureChanged();
-
-private Q_SLOTS:
- void handleResourcesLost();
- void handleResourcesGranted();
- void handleResourcesReleased();
- void resourcesAvailable();
- void updateCanCapture();
-
-
-private:
- ResourceSet m_resourceSet;
- ResourcePolicy::ResourceSet *m_resource;
- bool m_releasingResources;
- bool m_canCapture;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/camerabin/camerabinservice.cpp b/src/plugins/gstreamer/camerabin/camerabinservice.cpp
deleted file mode 100644
index a68ecfdbe..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinservice.cpp
+++ /dev/null
@@ -1,271 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "camerabinservice.h"
-#include "camerabinsession.h"
-#include "camerabinrecorder.h"
-#include "camerabincontainer.h"
-#include "camerabinaudioencoder.h"
-#include "camerabinvideoencoder.h"
-#include "camerabinimageencoder.h"
-#include "camerabincontrol.h"
-#include "camerabinmetadata.h"
-#include "camerabininfocontrol.h"
-
-#if QT_CONFIG(gstreamer_photography)
-#include "camerabinexposure.h"
-#include "camerabinflash.h"
-#include "camerabinfocus.h"
-#include "camerabinlocks.h"
-#endif
-
-#include "camerabinimagecapture.h"
-#include "camerabinimageprocessing.h"
-#include "camerabincapturebufferformat.h"
-#include "camerabincapturedestination.h"
-#include "camerabinviewfindersettings.h"
-#include "camerabinviewfindersettings2.h"
-#include "camerabinzoom.h"
-#include <private/qgstreamerbushelper_p.h>
-#include <private/qgstutils_p.h>
-
-#include <private/qgstreameraudioinputselector_p.h>
-#include <private/qgstreamervideoinputdevicecontrol_p.h>
-
-#if defined(HAVE_WIDGETS)
-#include <private/qgstreamervideowidget_p.h>
-#endif
-#include <private/qgstreamervideowindow_p.h>
-#include <private/qgstreamervideorenderer_p.h>
-#include <private/qmediaserviceprovider_p.h>
-
-#include <QtCore/qdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-CameraBinService::CameraBinService(GstElementFactory *sourceFactory, QObject *parent):
- QMediaService(parent),
- m_cameraInfoControl(0),
- m_viewfinderSettingsControl(0),
- m_viewfinderSettingsControl2(0)
-{
- m_captureSession = 0;
- m_metaDataControl = 0;
-
- m_audioInputSelector = 0;
- m_videoInputDevice = 0;
-
- m_videoOutput = 0;
- m_videoRenderer = 0;
- m_videoWindow = 0;
-#if defined(HAVE_WIDGETS)
- m_videoWidgetControl = 0;
-#endif
- m_imageCaptureControl = 0;
-
- m_captureSession = new CameraBinSession(sourceFactory, this);
- m_videoInputDevice = new QGstreamerVideoInputDeviceControl(sourceFactory, m_captureSession);
- m_imageCaptureControl = new CameraBinImageCapture(m_captureSession);
-
- connect(m_videoInputDevice, SIGNAL(selectedDeviceChanged(QString)),
- m_captureSession, SLOT(setDevice(QString)));
-
- if (m_videoInputDevice->deviceCount())
- m_captureSession->setDevice(m_videoInputDevice->deviceName(m_videoInputDevice->selectedDevice()));
-
- m_videoRenderer = new QGstreamerVideoRenderer(this);
-
- m_videoWindow = new QGstreamerVideoWindow(this);
- // If the GStreamer video sink is not available, don't provide the video window control since
- // it won't work anyway.
- if (!m_videoWindow->videoSink()) {
- delete m_videoWindow;
- m_videoWindow = 0;
- }
-#if defined(HAVE_WIDGETS)
- m_videoWidgetControl = new QGstreamerVideoWidgetControl(this);
-
- // If the GStreamer video sink is not available, don't provide the video widget control since
- // it won't work anyway. QVideoWidget will fall back to QVideoRendererControl in that case.
- if (!m_videoWidgetControl->videoSink()) {
- delete m_videoWidgetControl;
- m_videoWidgetControl = 0;
- }
-#endif
-
- m_audioInputSelector = new QGstreamerAudioInputSelector(this);
- connect(m_audioInputSelector, SIGNAL(activeInputChanged(QString)), m_captureSession, SLOT(setCaptureDevice(QString)));
-
- if (m_captureSession && m_audioInputSelector->availableInputs().size() > 0)
- m_captureSession->setCaptureDevice(m_audioInputSelector->defaultInput());
-
- m_metaDataControl = new CameraBinMetaData(this);
- connect(m_metaDataControl, SIGNAL(metaDataChanged(QMap<QByteArray,QVariant>)),
- m_captureSession, SLOT(setMetaData(QMap<QByteArray,QVariant>)));
-}
-
-CameraBinService::~CameraBinService()
-{
-}
-
-QMediaControl *CameraBinService::requestControl(const char *name)
-{
- if (!m_captureSession)
- return 0;
-
- if (!m_videoOutput) {
- if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
- m_videoOutput = m_videoRenderer;
- } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
- m_videoOutput = m_videoWindow;
- }
-#if defined(HAVE_WIDGETS)
- else if (qstrcmp(name, QVideoWidgetControl_iid) == 0) {
- m_videoOutput = m_videoWidgetControl;
- }
-#endif
-
- if (m_videoOutput) {
- m_captureSession->setViewfinder(m_videoOutput);
- return m_videoOutput;
- }
- }
-
- if (qstrcmp(name, QMediaVideoProbeControl_iid) == 0)
- return m_captureSession->videoProbe();
-
- if (qstrcmp(name,QAudioInputSelectorControl_iid) == 0)
- return m_audioInputSelector;
-
- if (qstrcmp(name,QVideoDeviceSelectorControl_iid) == 0)
- return m_videoInputDevice;
-
- if (qstrcmp(name,QMediaRecorderControl_iid) == 0)
- return m_captureSession->recorderControl();
-
- if (qstrcmp(name,QAudioEncoderSettingsControl_iid) == 0)
- return m_captureSession->audioEncodeControl();
-
- if (qstrcmp(name,QVideoEncoderSettingsControl_iid) == 0)
- return m_captureSession->videoEncodeControl();
-
- if (qstrcmp(name,QImageEncoderControl_iid) == 0)
- return m_captureSession->imageEncodeControl();
-
-
- if (qstrcmp(name,QMediaContainerControl_iid) == 0)
- return m_captureSession->mediaContainerControl();
-
- if (qstrcmp(name,QCameraControl_iid) == 0)
- return m_captureSession->cameraControl();
-
- if (qstrcmp(name,QMetaDataWriterControl_iid) == 0)
- return m_metaDataControl;
-
- if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0)
- return m_imageCaptureControl;
-
-#if QT_CONFIG(gstreamer_photography)
- if (qstrcmp(name, QCameraExposureControl_iid) == 0)
- return m_captureSession->cameraExposureControl();
-
- if (qstrcmp(name, QCameraFlashControl_iid) == 0)
- return m_captureSession->cameraFlashControl();
-
- if (qstrcmp(name, QCameraFocusControl_iid) == 0)
- return m_captureSession->cameraFocusControl();
-
- if (qstrcmp(name, QCameraLocksControl_iid) == 0)
- return m_captureSession->cameraLocksControl();
-#endif
-
- if (qstrcmp(name, QCameraZoomControl_iid) == 0)
- return m_captureSession->cameraZoomControl();
-
- if (qstrcmp(name, QCameraImageProcessingControl_iid) == 0)
- return m_captureSession->imageProcessingControl();
-
- if (qstrcmp(name, QCameraCaptureDestinationControl_iid) == 0)
- return m_captureSession->captureDestinationControl();
-
- if (qstrcmp(name, QCameraCaptureBufferFormatControl_iid) == 0)
- return m_captureSession->captureBufferFormatControl();
-
- if (qstrcmp(name, QCameraViewfinderSettingsControl_iid) == 0) {
- if (!m_viewfinderSettingsControl)
- m_viewfinderSettingsControl = new CameraBinViewfinderSettings(m_captureSession);
- return m_viewfinderSettingsControl;
- }
-
- if (qstrcmp(name, QCameraViewfinderSettingsControl2_iid) == 0) {
- if (!m_viewfinderSettingsControl2)
- m_viewfinderSettingsControl2 = new CameraBinViewfinderSettings2(m_captureSession);
- return m_viewfinderSettingsControl2;
- }
-
- if (qstrcmp(name, QCameraInfoControl_iid) == 0) {
- if (!m_cameraInfoControl)
- m_cameraInfoControl = new CameraBinInfoControl(m_captureSession->sourceFactory(), this);
- return m_cameraInfoControl;
- }
-
- return 0;
-}
-
-void CameraBinService::releaseControl(QMediaControl *control)
-{
- if (control && control == m_videoOutput) {
- m_videoOutput = 0;
- m_captureSession->setViewfinder(0);
- }
-}
-
-bool CameraBinService::isCameraBinAvailable()
-{
- GstElementFactory *factory = gst_element_factory_find(QT_GSTREAMER_CAMERABIN_ELEMENT_NAME);
- if (factory) {
- gst_object_unref(GST_OBJECT(factory));
- return true;
- }
-
- return false;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinservice.h b/src/plugins/gstreamer/camerabin/camerabinservice.h
deleted file mode 100644
index 44afef25f..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinservice.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINCAPTURESERVICE_H
-#define CAMERABINCAPTURESERVICE_H
-
-#include <qmediaservice.h>
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-class QAudioInputSelectorControl;
-class QVideoDeviceSelectorControl;
-
-
-class CameraBinSession;
-class CameraBinControl;
-class QGstreamerMessage;
-class QGstreamerBusHelper;
-class QGstreamerVideoRenderer;
-class QGstreamerVideoWindow;
-class QGstreamerVideoWidgetControl;
-class QGstreamerElementFactory;
-class CameraBinMetaData;
-class CameraBinImageCapture;
-class CameraBinMetaData;
-class CameraBinViewfinderSettings;
-class CameraBinViewfinderSettings2;
-
-class CameraBinService : public QMediaService
-{
- Q_OBJECT
-
-public:
- CameraBinService(GstElementFactory *sourceFactory, QObject *parent = 0);
- virtual ~CameraBinService();
-
- QMediaControl *requestControl(const char *name) override;
- void releaseControl(QMediaControl *) override;
-
- static bool isCameraBinAvailable();
-
-private:
- void setAudioPreview(GstElement*);
-
- CameraBinSession *m_captureSession;
- CameraBinMetaData *m_metaDataControl;
-
- QAudioInputSelectorControl *m_audioInputSelector;
- QVideoDeviceSelectorControl *m_videoInputDevice;
-
- QMediaControl *m_videoOutput;
-
- QMediaControl *m_videoRenderer;
- QGstreamerVideoWindow *m_videoWindow;
-#if defined(HAVE_WIDGETS)
- QGstreamerVideoWidgetControl *m_videoWidgetControl;
-#endif
- CameraBinImageCapture *m_imageCaptureControl;
- QMediaControl *m_cameraInfoControl;
-
- CameraBinViewfinderSettings *m_viewfinderSettingsControl;
- CameraBinViewfinderSettings2 *m_viewfinderSettingsControl2;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINCAPTURESERVICE_H
diff --git a/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp b/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp
deleted file mode 100644
index 4f45a0a2f..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qstring.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/QDir>
-#include <QtCore/QDebug>
-
-#include "camerabinserviceplugin.h"
-
-#include "camerabinservice.h"
-#include <private/qgstutils_p.h>
-
-QT_BEGIN_NAMESPACE
-
-template <typename T, int N> static int lengthOf(const T(&)[N]) { return N; }
-
-CameraBinServicePlugin::CameraBinServicePlugin()
- : m_sourceFactory(0)
-{
-}
-
-CameraBinServicePlugin::~CameraBinServicePlugin()
-{
- if (m_sourceFactory)
- gst_object_unref(GST_OBJECT(m_sourceFactory));
-}
-
-QMediaService* CameraBinServicePlugin::create(const QString &key)
-{
- QGstUtils::initializeGst();
-
- if (key == QLatin1String(Q_MEDIASERVICE_CAMERA)) {
- if (!CameraBinService::isCameraBinAvailable()) {
- guint major, minor, micro, nano;
- gst_version(&major, &minor, &micro, &nano);
- qWarning("Error: cannot create camera service, the 'camerabin' plugin is missing for "
- "GStreamer %u.%u."
- "\nPlease install the 'bad' GStreamer plugin package.",
- major, minor);
- return nullptr;
- }
-
- return new CameraBinService(sourceFactory());
- }
-
- qWarning() << "Gstreamer camerabin service plugin: unsupported key:" << key;
- return 0;
-}
-
-void CameraBinServicePlugin::release(QMediaService *service)
-{
- delete service;
-}
-
-QMediaServiceProviderHint::Features CameraBinServicePlugin::supportedFeatures(
- const QByteArray &service) const
-{
- if (service == Q_MEDIASERVICE_CAMERA)
- return QMediaServiceProviderHint::VideoSurface;
-
- return QMediaServiceProviderHint::Features();
-}
-
-QByteArray CameraBinServicePlugin::defaultDevice(const QByteArray &service) const
-{
- return service == Q_MEDIASERVICE_CAMERA
- ? QGstUtils::enumerateCameras(sourceFactory()).value(0).name.toUtf8()
- : QByteArray();
-}
-
-QList<QByteArray> CameraBinServicePlugin::devices(const QByteArray &service) const
-{
-
- return service == Q_MEDIASERVICE_CAMERA
- ? QGstUtils::cameraDevices(m_sourceFactory)
- : QList<QByteArray>();
-}
-
-QString CameraBinServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &deviceName)
-{
- return service == Q_MEDIASERVICE_CAMERA
- ? QGstUtils::cameraDescription(deviceName, m_sourceFactory)
- : QString();
-}
-
-QVariant CameraBinServicePlugin::deviceProperty(const QByteArray &service, const QByteArray &device, const QByteArray &property)
-{
- Q_UNUSED(service);
- Q_UNUSED(device);
- Q_UNUSED(property);
- return QVariant();
-}
-
-QCamera::Position CameraBinServicePlugin::cameraPosition(const QByteArray &deviceName) const
-{
- return QGstUtils::cameraPosition(deviceName, m_sourceFactory);
-}
-
-int CameraBinServicePlugin::cameraOrientation(const QByteArray &deviceName) const
-{
- return QGstUtils::cameraOrientation(deviceName, m_sourceFactory);
-}
-
-GstElementFactory *CameraBinServicePlugin::sourceFactory() const
-{
- if (!m_sourceFactory) {
- GstElementFactory *factory = 0;
- const QByteArray envCandidate = qgetenv("QT_GSTREAMER_CAMERABIN_SRC");
- if (!envCandidate.isEmpty())
- factory = gst_element_factory_find(envCandidate.constData());
-
- static const char *candidates[] = { "subdevsrc", "wrappercamerabinsrc" };
- for (int i = 0; !factory && i < lengthOf(candidates); ++i)
- factory = gst_element_factory_find(candidates[i]);
-
- if (factory) {
- m_sourceFactory = GST_ELEMENT_FACTORY(gst_plugin_feature_load(
- GST_PLUGIN_FEATURE(factory)));
- gst_object_unref((GST_OBJECT(factory)));
- }
- }
-
- return m_sourceFactory;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinserviceplugin.h b/src/plugins/gstreamer/camerabin/camerabinserviceplugin.h
deleted file mode 100644
index b31e44459..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinserviceplugin.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef CAMERABINSERVICEPLUGIN_H
-#define CAMERABINSERVICEPLUGIN_H
-
-#include <qmediaserviceproviderplugin.h>
-#include <private/qgstreamervideoinputdevicecontrol_p.h>
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinServicePlugin
- : public QMediaServiceProviderPlugin
- , public QMediaServiceSupportedDevicesInterface
- , public QMediaServiceDefaultDeviceInterface
- , public QMediaServiceFeaturesInterface
- , public QMediaServiceCameraInfoInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
- Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
- Q_INTERFACES(QMediaServiceFeaturesInterface)
- Q_INTERFACES(QMediaServiceCameraInfoInterface)
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "camerabin.json")
-public:
- CameraBinServicePlugin();
- ~CameraBinServicePlugin();
-
- QMediaService* create(const QString &key) override;
- void release(QMediaService *service) override;
-
- QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const override;
-
- QByteArray defaultDevice(const QByteArray &service) const override;
- QList<QByteArray> devices(const QByteArray &service) const override;
- QString deviceDescription(const QByteArray &service, const QByteArray &device) override;
- QVariant deviceProperty(const QByteArray &service, const QByteArray &device, const QByteArray &property);
-
- QCamera::Position cameraPosition(const QByteArray &device) const override;
- int cameraOrientation(const QByteArray &device) const override;
-
-private:
- GstElementFactory *sourceFactory() const;
-
- mutable GstElementFactory *m_sourceFactory;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERCAPTURESERVICEPLUGIN_H
diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp
deleted file mode 100644
index 22f5fb116..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp
+++ /dev/null
@@ -1,1587 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "camerabinsession.h"
-#include "camerabincontrol.h"
-#include "camerabinrecorder.h"
-#include "camerabincontainer.h"
-#include "camerabinaudioencoder.h"
-#include "camerabinvideoencoder.h"
-#include "camerabinimageencoder.h"
-
-#if QT_CONFIG(gstreamer_photography)
-#include "camerabinexposure.h"
-#include "camerabinflash.h"
-#include "camerabinfocus.h"
-#include "camerabinlocks.h"
-#endif
-
-#include "camerabinzoom.h"
-#include "camerabinimageprocessing.h"
-#include "camerabinviewfindersettings.h"
-
-#include "camerabincapturedestination.h"
-#include "camerabincapturebufferformat.h"
-#include <private/qgstreamerbushelper_p.h>
-#include <private/qgstreamervideorendererinterface_p.h>
-#include <private/qgstutils_p.h>
-#include <qmediarecorder.h>
-#include <qvideosurfaceformat.h>
-
-#if QT_CONFIG(gstreamer_photography)
-#include <gst/interfaces/photography.h>
-#endif
-
-#include <gst/gsttagsetter.h>
-#include <gst/gstversion.h>
-
-#include <QtCore/qdebug.h>
-#include <QCoreApplication>
-#include <QtCore/qmetaobject.h>
-#include <QtGui/qdesktopservices.h>
-
-#include <QtGui/qimage.h>
-#include <QtCore/qdatetime.h>
-
-#include <algorithm>
-
-//#define CAMERABIN_DEBUG 1
-//#define CAMERABIN_DEBUG_DUMP_BIN 1
-#define ENUM_NAME(c,e,v) (c::staticMetaObject.enumerator(c::staticMetaObject.indexOfEnumerator(e)).valueToKey((v)))
-
-#define FILENAME_PROPERTY "location"
-#define MODE_PROPERTY "mode"
-#define MUTE_PROPERTY "mute"
-#define IMAGE_PP_PROPERTY "image-post-processing"
-#define IMAGE_ENCODER_PROPERTY "image-encoder"
-#define VIDEO_PP_PROPERTY "video-post-processing"
-#define VIEWFINDER_SINK_PROPERTY "viewfinder-sink"
-#define CAMERA_SOURCE_PROPERTY "camera-source"
-#define AUDIO_SOURCE_PROPERTY "audio-source"
-#define SUPPORTED_IMAGE_CAPTURE_CAPS_PROPERTY "image-capture-supported-caps"
-#define SUPPORTED_VIDEO_CAPTURE_CAPS_PROPERTY "video-capture-supported-caps"
-#define SUPPORTED_VIEWFINDER_CAPS_PROPERTY "viewfinder-supported-caps"
-#define AUDIO_CAPTURE_CAPS_PROPERTY "audio-capture-caps"
-#define IMAGE_CAPTURE_CAPS_PROPERTY "image-capture-caps"
-#define VIDEO_CAPTURE_CAPS_PROPERTY "video-capture-caps"
-#define VIEWFINDER_CAPS_PROPERTY "viewfinder-caps"
-#define PREVIEW_CAPS_PROPERTY "preview-caps"
-#define POST_PREVIEWS_PROPERTY "post-previews"
-
-
-#define CAPTURE_START "start-capture"
-#define CAPTURE_STOP "stop-capture"
-
-#define FILESINK_BIN_NAME "videobin-filesink"
-
-#define CAMERABIN_IMAGE_MODE 1
-#define CAMERABIN_VIDEO_MODE 2
-
-#define PREVIEW_CAPS_4_3 \
- "video/x-raw-rgb, width = (int) 640, height = (int) 480"
-
-QT_BEGIN_NAMESPACE
-
-CameraBinSession::CameraBinSession(GstElementFactory *sourceFactory, QObject *parent)
- :QObject(parent),
- m_recordingActive(false),
- m_status(QCamera::UnloadedStatus),
- m_pendingState(QCamera::UnloadedState),
- m_muted(false),
- m_busy(false),
- m_captureMode(QCamera::CaptureStillImage),
- m_audioInputFactory(0),
- m_videoInputFactory(0),
- m_viewfinder(0),
- m_viewfinderInterface(0),
-#if QT_CONFIG(gstreamer_photography)
- m_cameraExposureControl(0),
- m_cameraFlashControl(0),
- m_cameraFocusControl(0),
- m_cameraLocksControl(0),
-#endif
- m_cameraSrc(0),
- m_videoSrc(0),
- m_viewfinderElement(0),
- m_sourceFactory(sourceFactory),
- m_viewfinderHasChanged(true),
- m_inputDeviceHasChanged(true),
- m_usingWrapperCameraBinSrc(false),
- m_viewfinderProbe(this),
- m_audioSrc(0),
- m_audioConvert(0),
- m_capsFilter(0),
- m_fileSink(0),
- m_audioEncoder(0),
- m_videoEncoder(0),
- m_muxer(0)
-{
- if (m_sourceFactory)
- gst_object_ref(GST_OBJECT(m_sourceFactory));
- m_camerabin = gst_element_factory_make(QT_GSTREAMER_CAMERABIN_ELEMENT_NAME, "camerabin");
-
- g_signal_connect(G_OBJECT(m_camerabin), "notify::idle", G_CALLBACK(updateBusyStatus), this);
- g_signal_connect(G_OBJECT(m_camerabin), "element-added", G_CALLBACK(elementAdded), this);
- g_signal_connect(G_OBJECT(m_camerabin), "element-removed", G_CALLBACK(elementRemoved), this);
- qt_gst_object_ref_sink(m_camerabin);
-
- m_bus = gst_element_get_bus(m_camerabin);
-
- m_busHelper = new QGstreamerBusHelper(m_bus, this);
- m_busHelper->installMessageFilter(this);
-
- m_cameraControl = new CameraBinControl(this);
- m_audioEncodeControl = new CameraBinAudioEncoder(this);
- m_videoEncodeControl = new CameraBinVideoEncoder(this);
- m_imageEncodeControl = new CameraBinImageEncoder(this);
- m_recorderControl = new CameraBinRecorder(this);
- m_mediaContainerControl = new CameraBinContainer(this);
- m_cameraZoomControl = new CameraBinZoom(this);
- m_imageProcessingControl = new CameraBinImageProcessing(this);
- m_captureDestinationControl = new CameraBinCaptureDestination(this);
- m_captureBufferFormatControl = new CameraBinCaptureBufferFormat(this);
-
- QByteArray envFlags = qgetenv("QT_GSTREAMER_CAMERABIN_FLAGS");
- if (!envFlags.isEmpty())
- g_object_set(G_OBJECT(m_camerabin), "flags", envFlags.toInt(), NULL);
-
- //post image preview in RGB format
- g_object_set(G_OBJECT(m_camerabin), POST_PREVIEWS_PROPERTY, TRUE, NULL);
-
-#if GST_CHECK_VERSION(1,0,0)
- GstCaps *previewCaps = gst_caps_new_simple(
- "video/x-raw",
- "format", G_TYPE_STRING, "RGBx",
- NULL);
-#else
- GstCaps *previewCaps = gst_caps_from_string("video/x-raw-rgb");
-#endif
-
- g_object_set(G_OBJECT(m_camerabin), PREVIEW_CAPS_PROPERTY, previewCaps, NULL);
- gst_caps_unref(previewCaps);
-}
-
-CameraBinSession::~CameraBinSession()
-{
- if (m_camerabin) {
- if (m_viewfinderInterface)
- m_viewfinderInterface->stopRenderer();
-
- gst_element_set_state(m_camerabin, GST_STATE_NULL);
- gst_element_get_state(m_camerabin, NULL, NULL, GST_CLOCK_TIME_NONE);
- gst_object_unref(GST_OBJECT(m_bus));
- gst_object_unref(GST_OBJECT(m_camerabin));
- }
- if (m_viewfinderElement)
- gst_object_unref(GST_OBJECT(m_viewfinderElement));
-
- if (m_sourceFactory)
- gst_object_unref(GST_OBJECT(m_sourceFactory));
-
- if (m_cameraSrc)
- gst_object_unref(GST_OBJECT(m_cameraSrc));
-
- if (m_videoSrc)
- gst_object_unref(GST_OBJECT(m_videoSrc));
-}
-
-#if QT_CONFIG(gstreamer_photography)
-GstPhotography *CameraBinSession::photography()
-{
- if (GST_IS_PHOTOGRAPHY(m_camerabin)) {
- return GST_PHOTOGRAPHY(m_camerabin);
- }
-
- GstElement * const source = buildCameraSource();
-
- if (source && GST_IS_PHOTOGRAPHY(source))
- return GST_PHOTOGRAPHY(source);
-
- return 0;
-}
-
-CameraBinExposure *CameraBinSession::cameraExposureControl()
-{
- if (!m_cameraExposureControl && photography())
- m_cameraExposureControl = new CameraBinExposure(this);
- return m_cameraExposureControl;
-}
-
-CameraBinFlash *CameraBinSession::cameraFlashControl()
-{
- if (!m_cameraFlashControl && photography())
- m_cameraFlashControl = new CameraBinFlash(this);
- return m_cameraFlashControl;
-}
-
-CameraBinFocus *CameraBinSession::cameraFocusControl()
-{
- if (!m_cameraFocusControl && photography())
- m_cameraFocusControl = new CameraBinFocus(this);
- return m_cameraFocusControl;
-}
-
-CameraBinLocks *CameraBinSession::cameraLocksControl()
-{
- if (!m_cameraLocksControl && photography())
- m_cameraLocksControl = new CameraBinLocks(this);
- return m_cameraLocksControl;
-}
-#endif
-
-bool CameraBinSession::setupCameraBin()
-{
- if (!buildCameraSource())
- return false;
-
- if (m_viewfinderHasChanged) {
- if (m_viewfinderElement) {
- GstPad *pad = gst_element_get_static_pad(m_viewfinderElement, "sink");
- m_viewfinderProbe.removeProbeFromPad(pad);
- gst_object_unref(GST_OBJECT(pad));
- gst_object_unref(GST_OBJECT(m_viewfinderElement));
- }
-
- m_viewfinderElement = m_viewfinderInterface ? m_viewfinderInterface->videoSink() : 0;
-#if CAMERABIN_DEBUG
- qDebug() << Q_FUNC_INFO << "Viewfinder changed, reconfigure.";
-#endif
- m_viewfinderHasChanged = false;
- if (!m_viewfinderElement) {
- if (m_pendingState == QCamera::ActiveState)
- qWarning() << "Starting camera without viewfinder available";
- m_viewfinderElement = gst_element_factory_make("fakesink", NULL);
- }
-
- GstPad *pad = gst_element_get_static_pad(m_viewfinderElement, "sink");
- m_viewfinderProbe.addProbeToPad(pad);
- gst_object_unref(GST_OBJECT(pad));
-
- g_object_set(G_OBJECT(m_viewfinderElement), "sync", FALSE, NULL);
- qt_gst_object_ref_sink(GST_OBJECT(m_viewfinderElement));
- gst_element_set_state(m_camerabin, GST_STATE_NULL);
- g_object_set(G_OBJECT(m_camerabin), VIEWFINDER_SINK_PROPERTY, m_viewfinderElement, NULL);
- }
-
- return true;
-}
-
-static GstCaps *resolutionToCaps(const QSize &resolution,
- qreal frameRate = 0.0,
- QVideoFrame::PixelFormat pixelFormat = QVideoFrame::Format_Invalid)
-{
- GstCaps *caps = 0;
- if (pixelFormat == QVideoFrame::Format_Invalid)
- caps = QGstUtils::videoFilterCaps();
- else
- caps = QGstUtils::capsForFormats(QList<QVideoFrame::PixelFormat>() << pixelFormat);
-
- if (!resolution.isEmpty()) {
- gst_caps_set_simple(
- caps,
- "width", G_TYPE_INT, resolution.width(),
- "height", G_TYPE_INT, resolution.height(),
- NULL);
- }
-
- if (frameRate > 0.0) {
- gint numerator;
- gint denominator;
- qt_gst_util_double_to_fraction(frameRate, &numerator, &denominator);
-
- gst_caps_set_simple(
- caps,
- "framerate", GST_TYPE_FRACTION, numerator, denominator,
- NULL);
- }
-
- return caps;
-}
-
-void CameraBinSession::setupCaptureResolution()
-{
- QSize viewfinderResolution = m_viewfinderSettings.resolution();
- qreal viewfinderFrameRate = m_viewfinderSettings.maximumFrameRate();
- QVideoFrame::PixelFormat viewfinderPixelFormat = m_viewfinderSettings.pixelFormat();
- const QSize imageResolution = m_imageEncodeControl->imageSettings().resolution();
- const QSize videoResolution = m_videoEncodeControl->actualVideoSettings().resolution();
-
- // WrapperCameraBinSrc cannot have different caps on its imgsrc, vidsrc and vfsrc pads.
- // If capture resolution is specified, use it also for the viewfinder to avoid caps negotiation
- // to fail.
- if (m_usingWrapperCameraBinSrc) {
- if (viewfinderResolution.isEmpty()) {
- if (m_captureMode == QCamera::CaptureStillImage && !imageResolution.isEmpty())
- viewfinderResolution = imageResolution;
- else if (m_captureMode == QCamera::CaptureVideo && !videoResolution.isEmpty())
- viewfinderResolution = videoResolution;
- }
-
- // Make sure we don't use incompatible frame rate and pixel format with the new resolution
- if (viewfinderResolution != m_viewfinderSettings.resolution() &&
- (!qFuzzyIsNull(viewfinderFrameRate) || viewfinderPixelFormat != QVideoFrame::Format_Invalid)) {
-
- enum {
- Nothing = 0x0,
- OnlyFrameRate = 0x1,
- OnlyPixelFormat = 0x2,
- Both = 0x4
- };
- quint8 found = Nothing;
- auto viewfinderSettings = supportedViewfinderSettings();
- for (int i = 0; i < viewfinderSettings.count() && !(found & Both); ++i) {
- const QCameraViewfinderSettings &s = viewfinderSettings.at(i);
- if (s.resolution() == viewfinderResolution) {
- if ((qFuzzyIsNull(viewfinderFrameRate) || s.maximumFrameRate() == viewfinderFrameRate)
- && (viewfinderPixelFormat == QVideoFrame::Format_Invalid || s.pixelFormat() == viewfinderPixelFormat))
- found |= Both;
- else if (s.maximumFrameRate() == viewfinderFrameRate)
- found |= OnlyFrameRate;
- else if (s.pixelFormat() == viewfinderPixelFormat)
- found |= OnlyPixelFormat;
- }
- }
-
- if (found & Both) {
- // no-op
- } else if (found & OnlyPixelFormat) {
- viewfinderFrameRate = qreal(0);
- } else if (found & OnlyFrameRate) {
- viewfinderPixelFormat = QVideoFrame::Format_Invalid;
- } else {
- viewfinderPixelFormat = QVideoFrame::Format_Invalid;
- viewfinderFrameRate = qreal(0);
- }
- }
- }
-
- GstCaps *caps = resolutionToCaps(imageResolution);
- g_object_set(m_camerabin, IMAGE_CAPTURE_CAPS_PROPERTY, caps, NULL);
- gst_caps_unref(caps);
-
- qreal framerate = m_videoEncodeControl->videoSettings().frameRate();
- caps = resolutionToCaps(videoResolution, framerate);
- g_object_set(m_camerabin, VIDEO_CAPTURE_CAPS_PROPERTY, caps, NULL);
- gst_caps_unref(caps);
-
- caps = resolutionToCaps(viewfinderResolution, viewfinderFrameRate, viewfinderPixelFormat);
- g_object_set(m_camerabin, VIEWFINDER_CAPS_PROPERTY, caps, NULL);
- gst_caps_unref(caps);
-
- // Special case when using mfw_v4lsrc
- if (m_videoSrc && qstrcmp(qt_gst_element_get_factory_name(m_videoSrc), "mfw_v4lsrc") == 0) {
- int capMode = 0;
- if (viewfinderResolution == QSize(320, 240))
- capMode = 1;
- else if (viewfinderResolution == QSize(720, 480))
- capMode = 2;
- else if (viewfinderResolution == QSize(720, 576))
- capMode = 3;
- else if (viewfinderResolution == QSize(1280, 720))
- capMode = 4;
- else if (viewfinderResolution == QSize(1920, 1080))
- capMode = 5;
- g_object_set(G_OBJECT(m_videoSrc), "capture-mode", capMode, NULL);
-
- if (!qFuzzyIsNull(viewfinderFrameRate)) {
- int n, d;
- qt_gst_util_double_to_fraction(viewfinderFrameRate, &n, &d);
- g_object_set(G_OBJECT(m_videoSrc), "fps-n", n, NULL);
- g_object_set(G_OBJECT(m_videoSrc), "fps-d", d, NULL);
- }
- }
-
- if (m_videoEncoder)
- m_videoEncodeControl->applySettings(m_videoEncoder);
-}
-
-void CameraBinSession::setAudioCaptureCaps()
-{
- QAudioEncoderSettings settings = m_audioEncodeControl->audioSettings();
- const int sampleRate = settings.sampleRate();
- const int channelCount = settings.channelCount();
-
- if (sampleRate <= 0 && channelCount <=0)
- return;
-
-#if GST_CHECK_VERSION(1,0,0)
- GstStructure *structure = gst_structure_new_empty(QT_GSTREAMER_RAW_AUDIO_MIME);
-#else
- GstStructure *structure = gst_structure_new(
- QT_GSTREAMER_RAW_AUDIO_MIME,
- "endianness", G_TYPE_INT, 1234,
- "signed", G_TYPE_BOOLEAN, TRUE,
- "width", G_TYPE_INT, 16,
- "depth", G_TYPE_INT, 16,
- NULL);
-#endif
- if (sampleRate > 0)
- gst_structure_set(structure, "rate", G_TYPE_INT, sampleRate, NULL);
- if (channelCount > 0)
- gst_structure_set(structure, "channels", G_TYPE_INT, channelCount, NULL);
-
- GstCaps *caps = gst_caps_new_full(structure, NULL);
- g_object_set(G_OBJECT(m_camerabin), AUDIO_CAPTURE_CAPS_PROPERTY, caps, NULL);
- gst_caps_unref(caps);
-
- if (m_audioEncoder)
- m_audioEncodeControl->applySettings(m_audioEncoder);
-}
-
-GstElement *CameraBinSession::buildCameraSource()
-{
-#if CAMERABIN_DEBUG
- qDebug() << Q_FUNC_INFO;
-#endif
- if (m_inputDevice.isEmpty())
- return nullptr;
-
- if (!m_inputDeviceHasChanged)
- return m_cameraSrc;
-
- m_inputDeviceHasChanged = false;
- m_usingWrapperCameraBinSrc = false;
-
- GstElement *camSrc = 0;
- g_object_get(G_OBJECT(m_camerabin), CAMERA_SOURCE_PROPERTY, &camSrc, NULL);
-
- if (!m_cameraSrc && m_sourceFactory)
- m_cameraSrc = gst_element_factory_create(m_sourceFactory, "camera_source");
-
- // If gstreamer has set a default source use it.
- if (!m_cameraSrc)
- m_cameraSrc = camSrc;
-
- if (m_cameraSrc) {
-#if CAMERABIN_DEBUG
- qDebug() << "set camera device" << m_inputDevice;
-#endif
- m_usingWrapperCameraBinSrc = qstrcmp(qt_gst_element_get_factory_name(m_cameraSrc), "wrappercamerabinsrc") == 0;
-
- if (g_object_class_find_property(G_OBJECT_GET_CLASS(m_cameraSrc), "video-source")) {
- if (!m_videoSrc) {
- /* QT_GSTREAMER_CAMERABIN_VIDEOSRC can be used to set the video source element.
-
- --- Usage
-
- QT_GSTREAMER_CAMERABIN_VIDEOSRC=[drivername=elementname[,drivername2=elementname2 ...],][elementname]
-
- --- Examples
-
- Always use 'somevideosrc':
- QT_GSTREAMER_CAMERABIN_VIDEOSRC="somevideosrc"
-
- Use 'somevideosrc' when the device driver is 'somedriver', otherwise use default:
- QT_GSTREAMER_CAMERABIN_VIDEOSRC="somedriver=somevideosrc"
-
- Use 'somevideosrc' when the device driver is 'somedriver', otherwise use 'somevideosrc2'
- QT_GSTREAMER_CAMERABIN_VIDEOSRC="somedriver=somevideosrc,somevideosrc2"
- */
- const QByteArray envVideoSource = qgetenv("QT_GSTREAMER_CAMERABIN_VIDEOSRC");
-
- if (!envVideoSource.isEmpty()) {
- const QList<QByteArray> sources = envVideoSource.split(',');
- for (const QByteArray &source : sources) {
- QList<QByteArray> keyValue = source.split('=');
- QByteArray name = keyValue.at(0);
- if (keyValue.count() > 1 && keyValue.at(0) == QGstUtils::cameraDriver(m_inputDevice, m_sourceFactory))
- name = keyValue.at(1);
-
- GError *error = NULL;
- GstElement *element = gst_parse_launch(name, &error);
-
- if (error) {
- g_printerr("ERROR: %s: %s\n", name.constData(), GST_STR_NULL(error->message));
- g_clear_error(&error);
- }
- if (element) {
- m_videoSrc = element;
- break;
- }
- }
- } else if (m_videoInputFactory) {
- m_videoSrc = m_videoInputFactory->buildElement();
- }
-
- if (!m_videoSrc)
- m_videoSrc = gst_element_factory_make("v4l2src", "camera_source");
-
- if (!m_videoSrc)
- m_videoSrc = gst_element_factory_make("ksvideosrc", "camera_source");
-
- if (!m_videoSrc)
- m_videoSrc = gst_element_factory_make("avfvideosrc", "camera_source");
-
- if (m_videoSrc)
- g_object_set(G_OBJECT(m_cameraSrc), "video-source", m_videoSrc, NULL);
- }
-
- if (m_videoSrc) {
- if (g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSrc), "device"))
- g_object_set(G_OBJECT(m_videoSrc), "device", m_inputDevice.toUtf8().constData(), NULL);
-
- if (g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSrc), "device-path"))
- g_object_set(G_OBJECT(m_videoSrc), "device-path", m_inputDevice.toUtf8().constData(), NULL);
-
- if (g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSrc), "device-index"))
- g_object_set(G_OBJECT(m_videoSrc), "device-index", m_inputDevice.toInt(), NULL);
- }
- } else if (g_object_class_find_property(G_OBJECT_GET_CLASS(m_cameraSrc), "camera-device")) {
- if (m_inputDevice == QLatin1String("secondary")) {
- g_object_set(G_OBJECT(m_cameraSrc), "camera-device", 1, NULL);
- } else {
- g_object_set(G_OBJECT(m_cameraSrc), "camera-device", 0, NULL);
- }
- }
- }
-
- if (m_cameraSrc != camSrc) {
- g_object_set(G_OBJECT(m_camerabin), CAMERA_SOURCE_PROPERTY, m_cameraSrc, NULL);
- // Unref only if camSrc is not m_cameraSrc to prevent double unrefing.
- if (camSrc)
- gst_object_unref(GST_OBJECT(camSrc));
- }
-
- return m_cameraSrc;
-}
-
-void CameraBinSession::captureImage(int requestId, const QString &fileName)
-{
- const QString actualFileName = m_mediaStorageLocation.generateFileName(fileName,
- QMediaStorageLocation::Pictures,
- QLatin1String("IMG_"),
- QLatin1String("jpg"));
-
- m_requestId = requestId;
-
-#if CAMERABIN_DEBUG
- qDebug() << Q_FUNC_INFO << m_requestId << fileName << "actual file name:" << actualFileName;
-#endif
-
- g_object_set(G_OBJECT(m_camerabin), FILENAME_PROPERTY, actualFileName.toLocal8Bit().constData(), NULL);
-
- g_signal_emit_by_name(G_OBJECT(m_camerabin), CAPTURE_START, NULL);
-
- m_imageFileName = actualFileName;
-}
-
-void CameraBinSession::setCaptureMode(QCamera::CaptureModes mode)
-{
- m_captureMode = mode;
-
- switch (m_captureMode) {
- case QCamera::CaptureStillImage:
- g_object_set(m_camerabin, MODE_PROPERTY, CAMERABIN_IMAGE_MODE, NULL);
- break;
- case QCamera::CaptureVideo:
- g_object_set(m_camerabin, MODE_PROPERTY, CAMERABIN_VIDEO_MODE, NULL);
- break;
- }
-
- m_recorderControl->updateStatus();
-}
-
-QUrl CameraBinSession::outputLocation() const
-{
- //return the location service wrote data to, not one set by user, it can be empty.
- return m_actualSink;
-}
-
-bool CameraBinSession::setOutputLocation(const QUrl& sink)
-{
- if (!sink.isRelative() && !sink.isLocalFile()) {
- qWarning("Output location must be a local file");
- return false;
- }
-
- m_sink = m_actualSink = sink;
- return true;
-}
-
-void CameraBinSession::setDevice(const QString &device)
-{
- if (m_inputDevice != device) {
- m_inputDevice = device;
- m_inputDeviceHasChanged = true;
- }
-}
-
-void CameraBinSession::setAudioInput(QGstreamerElementFactory *audioInput)
-{
- m_audioInputFactory = audioInput;
-}
-
-void CameraBinSession::setVideoInput(QGstreamerElementFactory *videoInput)
-{
- m_videoInputFactory = videoInput;
- m_inputDeviceHasChanged = true;
-}
-
-bool CameraBinSession::isReady() const
-{
- //it's possible to use QCamera without any viewfinder attached
- return !m_viewfinderInterface || m_viewfinderInterface->isReady();
-}
-
-void CameraBinSession::setViewfinder(QObject *viewfinder)
-{
- if (m_viewfinderInterface)
- m_viewfinderInterface->stopRenderer();
-
- m_viewfinderInterface = qobject_cast<QGstreamerVideoRendererInterface*>(viewfinder);
- if (!m_viewfinderInterface)
- viewfinder = 0;
-
- if (m_viewfinder != viewfinder) {
- bool oldReady = isReady();
-
- if (m_viewfinder) {
- disconnect(m_viewfinder, SIGNAL(sinkChanged()),
- this, SLOT(handleViewfinderChange()));
- disconnect(m_viewfinder, SIGNAL(readyChanged(bool)),
- this, SIGNAL(readyChanged(bool)));
-
- m_busHelper->removeMessageFilter(m_viewfinder);
- }
-
- m_viewfinder = viewfinder;
- m_viewfinderHasChanged = true;
-
- if (m_viewfinder) {
- connect(m_viewfinder, SIGNAL(sinkChanged()),
- this, SLOT(handleViewfinderChange()));
- connect(m_viewfinder, SIGNAL(readyChanged(bool)),
- this, SIGNAL(readyChanged(bool)));
-
- m_busHelper->installMessageFilter(m_viewfinder);
- }
-
- emit viewfinderChanged();
- if (oldReady != isReady())
- emit readyChanged(isReady());
- }
-}
-
-static QList<QCameraViewfinderSettings> capsToViewfinderSettings(GstCaps *supportedCaps)
-{
- QList<QCameraViewfinderSettings> settings;
-
- if (!supportedCaps)
- return settings;
-
- supportedCaps = qt_gst_caps_normalize(supportedCaps);
-
- // Convert caps to QCameraViewfinderSettings
- for (uint i = 0; i < gst_caps_get_size(supportedCaps); ++i) {
- const GstStructure *structure = gst_caps_get_structure(supportedCaps, i);
-
- QCameraViewfinderSettings s;
- s.setResolution(QGstUtils::structureResolution(structure));
- s.setPixelFormat(QGstUtils::structurePixelFormat(structure));
- s.setPixelAspectRatio(QGstUtils::structurePixelAspectRatio(structure));
-
- QPair<qreal, qreal> frameRateRange = QGstUtils::structureFrameRateRange(structure);
- s.setMinimumFrameRate(frameRateRange.first);
- s.setMaximumFrameRate(frameRateRange.second);
-
- if (!s.resolution().isEmpty()
- && s.pixelFormat() != QVideoFrame::Format_Invalid
- && !settings.contains(s)) {
- settings.append(s);
- }
- }
-
- gst_caps_unref(supportedCaps);
- return settings;
-}
-
-QList<QCameraViewfinderSettings> CameraBinSession::supportedViewfinderSettings() const
-{
- if (m_status >= QCamera::LoadedStatus && m_supportedViewfinderSettings.isEmpty()) {
- m_supportedViewfinderSettings =
- capsToViewfinderSettings(supportedCaps(QCamera::CaptureViewfinder));
- }
-
- return m_supportedViewfinderSettings;
-}
-
-QCameraViewfinderSettings CameraBinSession::viewfinderSettings() const
-{
- return m_status == QCamera::ActiveStatus ? m_actualViewfinderSettings : m_viewfinderSettings;
-}
-
-void CameraBinSession::ViewfinderProbe::probeCaps(GstCaps *caps)
-{
- QGstreamerVideoProbeControl::probeCaps(caps);
-
- // Update actual viewfinder settings on viewfinder caps change
- const GstStructure *s = gst_caps_get_structure(caps, 0);
- const QPair<qreal, qreal> frameRate = QGstUtils::structureFrameRateRange(s);
- session->m_actualViewfinderSettings.setResolution(QGstUtils::structureResolution(s));
- session->m_actualViewfinderSettings.setMinimumFrameRate(frameRate.first);
- session->m_actualViewfinderSettings.setMaximumFrameRate(frameRate.second);
- session->m_actualViewfinderSettings.setPixelFormat(QGstUtils::structurePixelFormat(s));
- session->m_actualViewfinderSettings.setPixelAspectRatio(QGstUtils::structurePixelAspectRatio(s));
-}
-
-void CameraBinSession::handleViewfinderChange()
-{
- //the viewfinder will be reloaded
- //shortly when the pipeline is started
- m_viewfinderHasChanged = true;
- emit viewfinderChanged();
-}
-
-void CameraBinSession::setStatus(QCamera::Status status)
-{
- if (m_status == status)
- return;
-
- m_status = status;
- emit statusChanged(m_status);
-
- setStateHelper(m_pendingState);
-}
-
-QCamera::Status CameraBinSession::status() const
-{
- return m_status;
-}
-
-QCamera::State CameraBinSession::pendingState() const
-{
- return m_pendingState;
-}
-
-void CameraBinSession::setState(QCamera::State newState)
-{
- if (newState == m_pendingState)
- return;
-
- m_pendingState = newState;
- emit pendingStateChanged(m_pendingState);
-
-#if CAMERABIN_DEBUG
- qDebug() << Q_FUNC_INFO << newState;
-#endif
-
- setStateHelper(newState);
-}
-
-void CameraBinSession::setStateHelper(QCamera::State state)
-{
- switch (state) {
- case QCamera::UnloadedState:
- unload();
- break;
- case QCamera::LoadedState:
- if (m_status == QCamera::ActiveStatus)
- stop();
- else if (m_status == QCamera::UnloadedStatus)
- load();
- break;
- case QCamera::ActiveState:
- // If the viewfinder changed while in the loaded state, we need to reload the pipeline
- if (m_status == QCamera::LoadedStatus && !m_viewfinderHasChanged)
- start();
- else if (m_status == QCamera::UnloadedStatus || m_viewfinderHasChanged)
- load();
- }
-}
-
-void CameraBinSession::setError(int err, const QString &errorString)
-{
- // Emit only first error
- if (m_pendingState == QCamera::UnloadedState)
- return;
-
- setState(QCamera::UnloadedState);
- emit error(err, errorString);
- setStatus(QCamera::UnloadedStatus);
-}
-
-void CameraBinSession::load()
-{
- if (m_status != QCamera::UnloadedStatus && !m_viewfinderHasChanged)
- return;
-
- setStatus(QCamera::LoadingStatus);
-
- gst_element_set_state(m_camerabin, GST_STATE_NULL);
-
- if (!setupCameraBin()) {
- setError(QCamera::CameraError, QStringLiteral("No camera source available"));
- return;
- }
-
- m_recorderControl->applySettings();
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
- GstEncodingContainerProfile *profile = m_recorderControl->videoProfile();
- if (profile) {
- g_object_set (G_OBJECT(m_camerabin),
- "video-profile",
- profile,
- NULL);
- gst_encoding_profile_unref(profile);
- }
-#endif
-
- gst_element_set_state(m_camerabin, GST_STATE_READY);
-}
-
-void CameraBinSession::unload()
-{
- if (m_status == QCamera::UnloadedStatus || m_status == QCamera::UnloadingStatus)
- return;
-
- setStatus(QCamera::UnloadingStatus);
-
- if (m_recordingActive)
- stopVideoRecording();
-
- if (m_viewfinderInterface)
- m_viewfinderInterface->stopRenderer();
-
- gst_element_set_state(m_camerabin, GST_STATE_NULL);
-
- if (m_busy)
- emit busyChanged(m_busy = false);
-
- m_supportedViewfinderSettings.clear();
-
- setStatus(QCamera::UnloadedStatus);
-}
-
-void CameraBinSession::start()
-{
- if (m_status != QCamera::LoadedStatus)
- return;
-
- setStatus(QCamera::StartingStatus);
-
- setAudioCaptureCaps();
-
- setupCaptureResolution();
-
- gst_element_set_state(m_camerabin, GST_STATE_PLAYING);
-}
-
-void CameraBinSession::stop()
-{
- if (m_status != QCamera::ActiveStatus)
- return;
-
- setStatus(QCamera::StoppingStatus);
-
- if (m_recordingActive)
- stopVideoRecording();
-
- if (m_viewfinderInterface)
- m_viewfinderInterface->stopRenderer();
-
- gst_element_set_state(m_camerabin, GST_STATE_READY);
-}
-
-bool CameraBinSession::isBusy() const
-{
- return m_busy;
-}
-
-void CameraBinSession::updateBusyStatus(GObject *o, GParamSpec *p, gpointer d)
-{
- Q_UNUSED(p);
- CameraBinSession *session = reinterpret_cast<CameraBinSession *>(d);
-
- gboolean idle = false;
- g_object_get(o, "idle", &idle, NULL);
- bool busy = !idle;
-
- if (session->m_busy != busy) {
- session->m_busy = busy;
- QMetaObject::invokeMethod(session, "busyChanged",
- Qt::QueuedConnection,
- Q_ARG(bool, busy));
- }
-}
-
-qint64 CameraBinSession::duration() const
-{
- if (m_camerabin) {
- GstElement *fileSink = gst_bin_get_by_name(GST_BIN(m_camerabin), FILESINK_BIN_NAME);
- if (fileSink) {
- GstFormat format = GST_FORMAT_TIME;
- gint64 duration = 0;
- bool ret = qt_gst_element_query_position(fileSink, format, &duration);
- gst_object_unref(GST_OBJECT(fileSink));
- if (ret)
- return duration / 1000000;
- }
- }
-
- return 0;
-}
-
-bool CameraBinSession::isMuted() const
-{
- return m_muted;
-}
-
-void CameraBinSession::setMuted(bool muted)
-{
- if (m_muted != muted) {
- m_muted = muted;
-
- if (m_camerabin)
- g_object_set(G_OBJECT(m_camerabin), MUTE_PROPERTY, m_muted, NULL);
- emit mutedChanged(m_muted);
- }
-}
-
-void CameraBinSession::setCaptureDevice(const QString &deviceName)
-{
- m_captureDevice = deviceName;
-}
-
-void CameraBinSession::setMetaData(const QMap<QByteArray, QVariant> &data)
-{
- m_metaData = data;
-
- if (m_camerabin)
- QGstUtils::setMetaData(m_camerabin, data);
-}
-
-bool CameraBinSession::processSyncMessage(const QGstreamerMessage &message)
-{
- GstMessage* gm = message.rawMessage();
-
- if (gm && GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT) {
- const GstStructure *st = gst_message_get_structure(gm);
- const GValue *sampleValue = 0;
- if (m_captureMode == QCamera::CaptureStillImage
- && gst_structure_has_name(st, "preview-image")
-#if GST_CHECK_VERSION(1,0,0)
- && gst_structure_has_field_typed(st, "sample", GST_TYPE_SAMPLE)
- && (sampleValue = gst_structure_get_value(st, "sample"))) {
- GstSample * const sample = gst_value_get_sample(sampleValue);
- GstCaps * const previewCaps = gst_sample_get_caps(sample);
- GstBuffer * const buffer = gst_sample_get_buffer(sample);
-#else
- && gst_structure_has_field_typed(st, "buffer", GST_TYPE_BUFFER)
- && (sampleValue = gst_structure_get_value(st, "buffer"))) {
- GstBuffer * const buffer = gst_value_get_buffer(sampleValue);
-#endif
-
- QImage image;
-#if GST_CHECK_VERSION(1,0,0)
- GstVideoInfo previewInfo;
- if (gst_video_info_from_caps(&previewInfo, previewCaps))
- image = QGstUtils::bufferToImage(buffer, previewInfo);
-#else
- image = QGstUtils::bufferToImage(buffer);
- gst_buffer_unref(buffer);
-#endif
- if (!image.isNull()) {
- static QMetaMethod exposedSignal = QMetaMethod::fromSignal(&CameraBinSession::imageExposed);
- exposedSignal.invoke(this,
- Qt::QueuedConnection,
- Q_ARG(int,m_requestId));
-
- static QMetaMethod capturedSignal = QMetaMethod::fromSignal(&CameraBinSession::imageCaptured);
- capturedSignal.invoke(this,
- Qt::QueuedConnection,
- Q_ARG(int,m_requestId),
- Q_ARG(QImage,image));
- }
- return true;
- }
-#if QT_CONFIG(gstreamer_photography)
- if (gst_structure_has_name(st, GST_PHOTOGRAPHY_AUTOFOCUS_DONE))
- m_cameraFocusControl->handleFocusMessage(gm);
-#endif
- }
-
- return false;
-}
-
-bool CameraBinSession::processBusMessage(const QGstreamerMessage &message)
-{
- GstMessage* gm = message.rawMessage();
-
- if (gm) {
- if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ERROR) {
- GError *err;
- gchar *debug;
- gst_message_parse_error (gm, &err, &debug);
-
- QString message;
-
- if (err && err->message) {
- message = QString::fromUtf8(err->message);
- qWarning() << "CameraBin error:" << message;
-#if CAMERABIN_DEBUG
- qWarning() << QString::fromUtf8(debug);
-#endif
- }
-
- // Only report error messages from camerabin or video source
- if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_camerabin)
- || GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_videoSrc)) {
- if (message.isEmpty())
- message = tr("Camera error");
-
- setError(int(QMediaRecorder::ResourceError), message);
- }
-
-#ifdef CAMERABIN_DEBUG_DUMP_BIN
- _gst_debug_bin_to_dot_file_with_ts(GST_BIN(m_camerabin),
- GstDebugGraphDetails(GST_DEBUG_GRAPH_SHOW_ALL /* GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE | GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS | GST_DEBUG_GRAPH_SHOW_STATES*/),
- "camerabin_error");
-#endif
-
-
- if (err)
- g_error_free (err);
-
- if (debug)
- g_free (debug);
- }
-
- if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_WARNING) {
- GError *err;
- gchar *debug;
- gst_message_parse_warning (gm, &err, &debug);
-
- if (err && err->message)
- qWarning() << "CameraBin warning:" << QString::fromUtf8(err->message);
-
- if (err)
- g_error_free (err);
- if (debug)
- g_free (debug);
- }
-
- if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_camerabin)) {
- switch (GST_MESSAGE_TYPE(gm)) {
- case GST_MESSAGE_DURATION:
- break;
-
- case GST_MESSAGE_STATE_CHANGED:
- {
-
- GstState oldState;
- GstState newState;
- GstState pending;
-
- gst_message_parse_state_changed(gm, &oldState, &newState, &pending);
-
-
-#if CAMERABIN_DEBUG
- QStringList states;
- states << "GST_STATE_VOID_PENDING" << "GST_STATE_NULL" << "GST_STATE_READY" << "GST_STATE_PAUSED" << "GST_STATE_PLAYING";
-
-
- qDebug() << QString("state changed: old: %1 new: %2 pending: %3") \
- .arg(states[oldState]) \
- .arg(states[newState]) \
- .arg(states[pending]);
-#endif
-
-#ifdef CAMERABIN_DEBUG_DUMP_BIN
- _gst_debug_bin_to_dot_file_with_ts(GST_BIN(m_camerabin),
- GstDebugGraphDetails(GST_DEBUG_GRAPH_SHOW_ALL /*GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE | GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS | GST_DEBUG_GRAPH_SHOW_STATES*/),
- "camerabin");
-#endif
-
- switch (newState) {
- case GST_STATE_VOID_PENDING:
- case GST_STATE_NULL:
- setStatus(QCamera::UnloadedStatus);
- break;
- case GST_STATE_READY:
- if (oldState == GST_STATE_NULL)
- m_supportedViewfinderSettings.clear();
-
- setMetaData(m_metaData);
- setStatus(QCamera::LoadedStatus);
- break;
- case GST_STATE_PLAYING:
- setStatus(QCamera::ActiveStatus);
- break;
- case GST_STATE_PAUSED:
- default:
- break;
- }
- }
- break;
- default:
- break;
- }
- }
- }
-
- return false;
-}
-
-QGstreamerVideoProbeControl *CameraBinSession::videoProbe()
-{
- return &m_viewfinderProbe;
-}
-
-QString CameraBinSession::currentContainerFormat() const
-{
- if (!m_muxer)
- return QString();
-
- QString format;
-
- if (GstPad *srcPad = gst_element_get_static_pad(m_muxer, "src")) {
- if (GstCaps *caps = qt_gst_pad_get_caps(srcPad)) {
- gchar *capsString = gst_caps_to_string(caps);
- format = QString::fromLatin1(capsString);
- if (capsString)
- g_free(capsString);
- gst_caps_unref(caps);
- }
- gst_object_unref(GST_OBJECT(srcPad));
- }
-
- return format;
-}
-
-void CameraBinSession::recordVideo()
-{
- QString format = currentContainerFormat();
- if (format.isEmpty())
- format = m_mediaContainerControl->actualContainerFormat();
-
- const QString fileName = m_sink.isLocalFile() ? m_sink.toLocalFile() : m_sink.toString();
- const QFileInfo fileInfo(fileName);
- const QString extension = fileInfo.suffix().isEmpty()
- ? QGstUtils::fileExtensionForMimeType(format)
- : fileInfo.suffix();
-
- const QString actualFileName = m_mediaStorageLocation.generateFileName(fileName,
- QMediaStorageLocation::Movies,
- QLatin1String("clip_"),
- extension);
-
- m_recordingActive = true;
- m_actualSink = QUrl::fromLocalFile(actualFileName);
-
- g_object_set(G_OBJECT(m_camerabin), FILENAME_PROPERTY, QFile::encodeName(actualFileName).constData(), NULL);
-
- g_signal_emit_by_name(G_OBJECT(m_camerabin), CAPTURE_START, NULL);
-}
-
-void CameraBinSession::stopVideoRecording()
-{
- m_recordingActive = false;
- g_signal_emit_by_name(G_OBJECT(m_camerabin), CAPTURE_STOP, NULL);
-}
-
-//internal, only used by CameraBinSession::supportedFrameRates.
-//recursively fills the list of framerates res from value data.
-static void readValue(const GValue *value, QList< QPair<int,int> > *res, bool *continuous)
-{
- if (GST_VALUE_HOLDS_FRACTION(value)) {
- int num = gst_value_get_fraction_numerator(value);
- int denum = gst_value_get_fraction_denominator(value);
-
- *res << QPair<int,int>(num, denum);
- } else if (GST_VALUE_HOLDS_FRACTION_RANGE(value)) {
- const GValue *rateValueMin = gst_value_get_fraction_range_min(value);
- const GValue *rateValueMax = gst_value_get_fraction_range_max(value);
-
- if (continuous)
- *continuous = true;
-
- readValue(rateValueMin, res, continuous);
- readValue(rateValueMax, res, continuous);
- } else if (GST_VALUE_HOLDS_LIST(value)) {
- for (uint i=0; i<gst_value_list_get_size(value); i++) {
- readValue(gst_value_list_get_value(value, i), res, continuous);
- }
- }
-}
-
-static bool rateLessThan(const QPair<int,int> &r1, const QPair<int,int> &r2)
-{
- return r1.first*r2.second < r2.first*r1.second;
-}
-
-GstCaps *CameraBinSession::supportedCaps(QCamera::CaptureModes mode) const
-{
- GstCaps *supportedCaps = 0;
-
- // When using wrappercamerabinsrc, get the supported caps directly from the video source element.
- // This makes sure we only get the caps actually supported by the video source element.
- if (m_videoSrc) {
- GstPad *pad = gst_element_get_static_pad(m_videoSrc, "src");
- if (pad) {
- supportedCaps = qt_gst_pad_get_caps(pad);
- gst_object_unref(GST_OBJECT(pad));
- }
- }
-
- // Otherwise, let the camerabin handle this.
- if (!supportedCaps) {
- const gchar *prop;
- switch (mode) {
- case QCamera::CaptureStillImage:
- prop = SUPPORTED_IMAGE_CAPTURE_CAPS_PROPERTY;
- break;
- case QCamera::CaptureVideo:
- prop = SUPPORTED_VIDEO_CAPTURE_CAPS_PROPERTY;
- break;
- case QCamera::CaptureViewfinder:
- default:
- prop = SUPPORTED_VIEWFINDER_CAPS_PROPERTY;
- break;
- }
-
- g_object_get(G_OBJECT(m_camerabin), prop, &supportedCaps, NULL);
- }
-
- return supportedCaps;
-}
-
-QList< QPair<int,int> > CameraBinSession::supportedFrameRates(const QSize &frameSize, bool *continuous) const
-{
- QList< QPair<int,int> > res;
-
- GstCaps *supportedCaps = this->supportedCaps(QCamera::CaptureVideo);
-
- if (!supportedCaps)
- return res;
-
- GstCaps *caps = 0;
-
- if (frameSize.isEmpty()) {
- caps = gst_caps_copy(supportedCaps);
- } else {
- GstCaps *filter = QGstUtils::videoFilterCaps();
- gst_caps_set_simple(
- filter,
- "width", G_TYPE_INT, frameSize.width(),
- "height", G_TYPE_INT, frameSize.height(),
- NULL);
-
- caps = gst_caps_intersect(supportedCaps, filter);
- gst_caps_unref(filter);
- }
- gst_caps_unref(supportedCaps);
-
- //simplify to the list of rates only:
- caps = gst_caps_make_writable(caps);
- for (uint i=0; i<gst_caps_get_size(caps); i++) {
- GstStructure *structure = gst_caps_get_structure(caps, i);
- gst_structure_set_name(structure, "video/x-raw");
-#if GST_CHECK_VERSION(1,2,0)
- gst_caps_set_features(caps, i, NULL);
-#endif
- const GValue *oldRate = gst_structure_get_value(structure, "framerate");
- if (!oldRate)
- continue;
-
- GValue rate;
- memset(&rate, 0, sizeof(rate));
- g_value_init(&rate, G_VALUE_TYPE(oldRate));
- g_value_copy(oldRate, &rate);
- gst_structure_remove_all_fields(structure);
- gst_structure_set_value(structure, "framerate", &rate);
- g_value_unset(&rate);
- }
-#if GST_CHECK_VERSION(1,0,0)
- caps = gst_caps_simplify(caps);
-#else
- gst_caps_do_simplify(caps);
-#endif
-
- for (uint i=0; i<gst_caps_get_size(caps); i++) {
- GstStructure *structure = gst_caps_get_structure(caps, i);
- const GValue *rateValue = gst_structure_get_value(structure, "framerate");
- if (!rateValue)
- continue;
-
- readValue(rateValue, &res, continuous);
- }
-
- std::sort(res.begin(), res.end(), rateLessThan);
-
-#if CAMERABIN_DEBUG
- qDebug() << "Supported rates:" << caps;
- qDebug() << res;
-#endif
-
- gst_caps_unref(caps);
-
- return res;
-}
-
-//internal, only used by CameraBinSession::supportedResolutions
-//recursively find the supported resolutions range.
-static QPair<int,int> valueRange(const GValue *value, bool *continuous)
-{
- int minValue = 0;
- int maxValue = 0;
-
- if (g_value_type_compatible(G_VALUE_TYPE(value), G_TYPE_INT)) {
- minValue = maxValue = g_value_get_int(value);
- } else if (GST_VALUE_HOLDS_INT_RANGE(value)) {
- minValue = gst_value_get_int_range_min(value);
- maxValue = gst_value_get_int_range_max(value);
- *continuous = true;
- } else if (GST_VALUE_HOLDS_LIST(value)) {
- for (uint i=0; i<gst_value_list_get_size(value); i++) {
- QPair<int,int> res = valueRange(gst_value_list_get_value(value, i), continuous);
-
- if (res.first > 0 && minValue > 0)
- minValue = qMin(minValue, res.first);
- else //select non 0 valid value
- minValue = qMax(minValue, res.first);
-
- maxValue = qMax(maxValue, res.second);
- }
- }
-
- return QPair<int,int>(minValue, maxValue);
-}
-
-static bool resolutionLessThan(const QSize &r1, const QSize &r2)
-{
- return qlonglong(r1.width()) * r1.height() < qlonglong(r2.width()) * r2.height();
-}
-
-
-QList<QSize> CameraBinSession::supportedResolutions(QPair<int,int> rate,
- bool *continuous,
- QCamera::CaptureModes mode) const
-{
- QList<QSize> res;
-
- if (continuous)
- *continuous = false;
-
- GstCaps *supportedCaps = this->supportedCaps(mode);
-
-#if CAMERABIN_DEBUG
- qDebug() << "Source caps:" << supportedCaps;
-#endif
-
- if (!supportedCaps)
- return res;
-
- GstCaps *caps = 0;
- bool isContinuous = false;
-
- if (rate.first <= 0 || rate.second <= 0) {
- caps = gst_caps_copy(supportedCaps);
- } else {
- GstCaps *filter = QGstUtils::videoFilterCaps();
- gst_caps_set_simple(
- filter,
- "framerate" , GST_TYPE_FRACTION , rate.first, rate.second,
- NULL);
- caps = gst_caps_intersect(supportedCaps, filter);
- gst_caps_unref(filter);
- }
- gst_caps_unref(supportedCaps);
-
- //simplify to the list of resolutions only:
- caps = gst_caps_make_writable(caps);
- for (uint i=0; i<gst_caps_get_size(caps); i++) {
- GstStructure *structure = gst_caps_get_structure(caps, i);
- gst_structure_set_name(structure, "video/x-raw");
-#if GST_CHECK_VERSION(1,2,0)
- gst_caps_set_features(caps, i, NULL);
-#endif
- const GValue *oldW = gst_structure_get_value(structure, "width");
- const GValue *oldH = gst_structure_get_value(structure, "height");
- if (!oldW || !oldH)
- continue;
-
- GValue w;
- memset(&w, 0, sizeof(GValue));
- GValue h;
- memset(&h, 0, sizeof(GValue));
- g_value_init(&w, G_VALUE_TYPE(oldW));
- g_value_init(&h, G_VALUE_TYPE(oldH));
- g_value_copy(oldW, &w);
- g_value_copy(oldH, &h);
- gst_structure_remove_all_fields(structure);
- gst_structure_set_value(structure, "width", &w);
- gst_structure_set_value(structure, "height", &h);
- g_value_unset(&w);
- g_value_unset(&h);
- }
-
-#if GST_CHECK_VERSION(1,0,0)
- caps = gst_caps_simplify(caps);
-#else
- gst_caps_do_simplify(caps);
-#endif
-
-
- for (uint i=0; i<gst_caps_get_size(caps); i++) {
- GstStructure *structure = gst_caps_get_structure(caps, i);
- const GValue *wValue = gst_structure_get_value(structure, "width");
- const GValue *hValue = gst_structure_get_value(structure, "height");
- if (!wValue || !hValue)
- continue;
-
- QPair<int,int> wRange = valueRange(wValue, &isContinuous);
- QPair<int,int> hRange = valueRange(hValue, &isContinuous);
-
- QSize minSize(wRange.first, hRange.first);
- QSize maxSize(wRange.second, hRange.second);
-
- if (!minSize.isEmpty())
- res << minSize;
-
- if (minSize != maxSize && !maxSize.isEmpty())
- res << maxSize;
- }
-
-
- std::sort(res.begin(), res.end(), resolutionLessThan);
-
- //if the range is continuos, populate is with the common rates
- if (isContinuous && res.size() >= 2) {
- //fill the ragne with common value
- static const QList<QSize> commonSizes =
- QList<QSize>() << QSize(128, 96)
- << QSize(160,120)
- << QSize(176, 144)
- << QSize(320, 240)
- << QSize(352, 288)
- << QSize(640, 480)
- << QSize(848, 480)
- << QSize(854, 480)
- << QSize(1024, 768)
- << QSize(1280, 720) // HD 720
- << QSize(1280, 1024)
- << QSize(1600, 1200)
- << QSize(1920, 1080) // HD
- << QSize(1920, 1200)
- << QSize(2048, 1536)
- << QSize(2560, 1600)
- << QSize(2580, 1936);
- QSize minSize = res.first();
- QSize maxSize = res.last();
- res.clear();
-
- for (const QSize &candidate : commonSizes) {
- int w = candidate.width();
- int h = candidate.height();
-
- if (w > maxSize.width() && h > maxSize.height())
- break;
-
- if (w >= minSize.width() && h >= minSize.height() &&
- w <= maxSize.width() && h <= maxSize.height())
- res << candidate;
- }
-
- if (res.isEmpty() || res.first() != minSize)
- res.prepend(minSize);
-
- if (res.last() != maxSize)
- res.append(maxSize);
- }
-
-#if CAMERABIN_DEBUG
- qDebug() << "Supported resolutions:" << gst_caps_to_string(caps);
- qDebug() << res;
-#endif
-
- gst_caps_unref(caps);
-
- if (continuous)
- *continuous = isContinuous;
-
- return res;
-}
-
-void CameraBinSession::elementAdded(GstBin *, GstElement *element, CameraBinSession *session)
-{
- GstElementFactory *factory = gst_element_get_factory(element);
-
- if (GST_IS_BIN(element)) {
- g_signal_connect(G_OBJECT(element), "element-added", G_CALLBACK(elementAdded), session);
- g_signal_connect(G_OBJECT(element), "element-removed", G_CALLBACK(elementRemoved), session);
- } else if (!factory) {
- // no-op
-#if GST_CHECK_VERSION(0,10,31)
- } else if (gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_AUDIO_ENCODER)) {
-#else
- } else if (strstr(gst_element_factory_get_klass(factory), "Encoder/Audio") != NULL) {
-#endif
- session->m_audioEncoder = element;
-
- session->m_audioEncodeControl->applySettings(element);
-#if GST_CHECK_VERSION(0,10,31)
- } else if (gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_VIDEO_ENCODER)) {
-#else
- } else if (strstr(gst_element_factory_get_klass(factory), "Encoder/Video") != NULL) {
-#endif
- session->m_videoEncoder = element;
-
- session->m_videoEncodeControl->applySettings(element);
-#if GST_CHECK_VERSION(0,10,31)
- } else if (gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_MUXER)) {
-#else
- } else if (strstr(gst_element_factory_get_klass(factory), "Muxer") != NULL) {
-#endif
- session->m_muxer = element;
- }
-}
-
-void CameraBinSession::elementRemoved(GstBin *, GstElement *element, CameraBinSession *session)
-{
- if (element == session->m_audioEncoder)
- session->m_audioEncoder = 0;
- else if (element == session->m_videoEncoder)
- session->m_videoEncoder = 0;
- else if (element == session->m_muxer)
- session->m_muxer = 0;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.h b/src/plugins/gstreamer/camerabin/camerabinsession.h
deleted file mode 100644
index 999398fa4..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinsession.h
+++ /dev/null
@@ -1,291 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINCAPTURESESSION_H
-#define CAMERABINCAPTURESESSION_H
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <qmediarecordercontrol.h>
-
-#include <QtCore/qurl.h>
-#include <QtCore/qdir.h>
-
-#include <gst/gst.h>
-#if QT_CONFIG(gstreamer_photography)
-#include <gst/interfaces/photography.h>
-#endif
-
-#include <private/qgstreamerbushelper_p.h>
-#include <private/qgstreamervideoprobecontrol_p.h>
-#include <private/qmediastoragelocation_p.h>
-#include "qcamera.h"
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerMessage;
-class QGstreamerBusHelper;
-class CameraBinControl;
-class CameraBinAudioEncoder;
-class CameraBinVideoEncoder;
-class CameraBinImageEncoder;
-class CameraBinRecorder;
-class CameraBinContainer;
-class CameraBinExposure;
-class CameraBinFlash;
-class CameraBinFocus;
-class CameraBinImageProcessing;
-class CameraBinLocks;
-class CameraBinZoom;
-class CameraBinCaptureDestination;
-class CameraBinCaptureBufferFormat;
-class QGstreamerVideoRendererInterface;
-class CameraBinViewfinderSettings;
-
-class QGstreamerElementFactory
-{
-public:
- virtual GstElement *buildElement() = 0;
-};
-
-class CameraBinSession : public QObject,
- public QGstreamerBusMessageFilter,
- public QGstreamerSyncMessageFilter
-{
- Q_OBJECT
- Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
- Q_INTERFACES(QGstreamerBusMessageFilter QGstreamerSyncMessageFilter)
-public:
- CameraBinSession(GstElementFactory *sourceFactory, QObject *parent);
- ~CameraBinSession();
-
-#if QT_CONFIG(gstreamer_photography)
- GstPhotography *photography();
-#endif
- GstElement *cameraBin() { return m_camerabin; }
- GstElement *cameraSource() { return m_cameraSrc; }
- QGstreamerBusHelper *bus() { return m_busHelper; }
-
- QList< QPair<int,int> > supportedFrameRates(const QSize &frameSize, bool *continuous) const;
- QList<QSize> supportedResolutions(QPair<int,int> rate, bool *continuous, QCamera::CaptureModes mode) const;
-
- QCamera::CaptureModes captureMode() { return m_captureMode; }
- void setCaptureMode(QCamera::CaptureModes mode);
-
- QUrl outputLocation() const;
- bool setOutputLocation(const QUrl& sink);
-
- GstElement *buildCameraSource();
- GstElementFactory *sourceFactory() const { return m_sourceFactory; }
-
- CameraBinControl *cameraControl() const { return m_cameraControl; }
- CameraBinAudioEncoder *audioEncodeControl() const { return m_audioEncodeControl; }
- CameraBinVideoEncoder *videoEncodeControl() const { return m_videoEncodeControl; }
- CameraBinImageEncoder *imageEncodeControl() const { return m_imageEncodeControl; }
-
-#if QT_CONFIG(gstreamer_photography)
- CameraBinExposure *cameraExposureControl();
- CameraBinFlash *cameraFlashControl();
- CameraBinFocus *cameraFocusControl();
- CameraBinLocks *cameraLocksControl();
-#endif
-
- CameraBinZoom *cameraZoomControl() const { return m_cameraZoomControl; }
- CameraBinImageProcessing *imageProcessingControl() const { return m_imageProcessingControl; }
- CameraBinCaptureDestination *captureDestinationControl() const { return m_captureDestinationControl; }
- CameraBinCaptureBufferFormat *captureBufferFormatControl() const { return m_captureBufferFormatControl; }
-
- CameraBinRecorder *recorderControl() const { return m_recorderControl; }
- CameraBinContainer *mediaContainerControl() const { return m_mediaContainerControl; }
-
- QGstreamerElementFactory *audioInput() const { return m_audioInputFactory; }
- void setAudioInput(QGstreamerElementFactory *audioInput);
-
- QGstreamerElementFactory *videoInput() const { return m_videoInputFactory; }
- void setVideoInput(QGstreamerElementFactory *videoInput);
- bool isReady() const;
-
- QObject *viewfinder() const { return m_viewfinder; }
- void setViewfinder(QObject *viewfinder);
-
- QList<QCameraViewfinderSettings> supportedViewfinderSettings() const;
- QCameraViewfinderSettings viewfinderSettings() const;
- void setViewfinderSettings(const QCameraViewfinderSettings &settings) { m_viewfinderSettings = settings; }
-
- void captureImage(int requestId, const QString &fileName);
-
- QCamera::Status status() const;
- QCamera::State pendingState() const;
- bool isBusy() const;
-
- qint64 duration() const;
-
- void recordVideo();
- void stopVideoRecording();
-
- bool isMuted() const;
-
- QString device() const { return m_inputDevice; }
-
- bool processSyncMessage(const QGstreamerMessage &message) override;
- bool processBusMessage(const QGstreamerMessage &message) override;
-
- QGstreamerVideoProbeControl *videoProbe();
-
-signals:
- void statusChanged(QCamera::Status status);
- void pendingStateChanged(QCamera::State state);
- void durationChanged(qint64 duration);
- void error(int error, const QString &errorString);
- void imageExposed(int requestId);
- void imageCaptured(int requestId, const QImage &img);
- void mutedChanged(bool);
- void viewfinderChanged();
- void readyChanged(bool);
- void busyChanged(bool);
-
-public slots:
- void setDevice(const QString &device);
- void setState(QCamera::State);
- void setCaptureDevice(const QString &deviceName);
- void setMetaData(const QMap<QByteArray, QVariant>&);
- void setMuted(bool);
-
-private slots:
- void handleViewfinderChange();
- void setupCaptureResolution();
-
-private:
- void load();
- void unload();
- void start();
- void stop();
-
- void setStatus(QCamera::Status status);
- void setStateHelper(QCamera::State state);
- void setError(int error, const QString &errorString);
-
- bool setupCameraBin();
- void setAudioCaptureCaps();
- GstCaps *supportedCaps(QCamera::CaptureModes mode) const;
- static void updateBusyStatus(GObject *o, GParamSpec *p, gpointer d);
-
- QString currentContainerFormat() const;
-
- static void elementAdded(GstBin *bin, GstElement *element, CameraBinSession *session);
- static void elementRemoved(GstBin *bin, GstElement *element, CameraBinSession *session);
-
- QUrl m_sink;
- QUrl m_actualSink;
- bool m_recordingActive;
- QString m_captureDevice;
- QCamera::Status m_status;
- QCamera::State m_pendingState;
- QString m_inputDevice;
- bool m_muted;
- bool m_busy;
- QMediaStorageLocation m_mediaStorageLocation;
-
- QCamera::CaptureModes m_captureMode;
- QMap<QByteArray, QVariant> m_metaData;
-
- QGstreamerElementFactory *m_audioInputFactory;
- QGstreamerElementFactory *m_videoInputFactory;
- QObject *m_viewfinder;
- QGstreamerVideoRendererInterface *m_viewfinderInterface;
- mutable QList<QCameraViewfinderSettings> m_supportedViewfinderSettings;
- QCameraViewfinderSettings m_viewfinderSettings;
- QCameraViewfinderSettings m_actualViewfinderSettings;
-
- CameraBinControl *m_cameraControl;
- CameraBinAudioEncoder *m_audioEncodeControl;
- CameraBinVideoEncoder *m_videoEncodeControl;
- CameraBinImageEncoder *m_imageEncodeControl;
- CameraBinRecorder *m_recorderControl;
- CameraBinContainer *m_mediaContainerControl;
-#if QT_CONFIG(gstreamer_photography)
- CameraBinExposure *m_cameraExposureControl;
- CameraBinFlash *m_cameraFlashControl;
- CameraBinFocus *m_cameraFocusControl;
- CameraBinLocks *m_cameraLocksControl;
-#endif
- CameraBinZoom *m_cameraZoomControl;
- CameraBinImageProcessing *m_imageProcessingControl;
- CameraBinCaptureDestination *m_captureDestinationControl;
- CameraBinCaptureBufferFormat *m_captureBufferFormatControl;
-
- QGstreamerBusHelper *m_busHelper;
- GstBus* m_bus;
- GstElement *m_camerabin;
- GstElement *m_cameraSrc;
- GstElement *m_videoSrc;
- GstElement *m_viewfinderElement;
- GstElementFactory *m_sourceFactory;
- bool m_viewfinderHasChanged;
- bool m_inputDeviceHasChanged;
- bool m_usingWrapperCameraBinSrc;
-
- class ViewfinderProbe : public QGstreamerVideoProbeControl {
- public:
- ViewfinderProbe(CameraBinSession *s)
- : QGstreamerVideoProbeControl(s)
- , session(s)
- {}
-
- void probeCaps(GstCaps *caps) override;
-
- private:
- CameraBinSession * const session;
- } m_viewfinderProbe;
-
- GstElement *m_audioSrc;
- GstElement *m_audioConvert;
- GstElement *m_capsFilter;
- GstElement *m_fileSink;
- GstElement *m_audioEncoder;
- GstElement *m_videoEncoder;
- GstElement *m_muxer;
-
-public:
- QString m_imageFileName;
- int m_requestId;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINCAPTURESESSION_H
diff --git a/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp b/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp
deleted file mode 100644
index 5b0c0d234..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.cpp
+++ /dev/null
@@ -1,316 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabinv4limageprocessing.h"
-#include "camerabinsession.h"
-
-#include <QDebug>
-
-#include <private/qcore_unix_p.h>
-#include <linux/videodev2.h>
-
-QT_BEGIN_NAMESPACE
-
-CameraBinV4LImageProcessing::CameraBinV4LImageProcessing(CameraBinSession *session)
- : QCameraImageProcessingControl(session)
- , m_session(session)
-{
-}
-
-CameraBinV4LImageProcessing::~CameraBinV4LImageProcessing()
-{
-}
-
-bool CameraBinV4LImageProcessing::isParameterSupported(
- ProcessingParameter parameter) const
-{
- return m_parametersInfo.contains(parameter);
-}
-
-bool CameraBinV4LImageProcessing::isParameterValueSupported(
- ProcessingParameter parameter, const QVariant &value) const
-{
- QMap<ProcessingParameter, SourceParameterValueInfo>::const_iterator sourceValueInfo =
- m_parametersInfo.constFind(parameter);
- if (sourceValueInfo == m_parametersInfo.constEnd())
- return false;
-
- switch (parameter) {
-
- case QCameraImageProcessingControl::WhiteBalancePreset: {
- const QCameraImageProcessing::WhiteBalanceMode checkedValue =
- value.value<QCameraImageProcessing::WhiteBalanceMode>();
- const QCameraImageProcessing::WhiteBalanceMode firstAllowedValue =
- (*sourceValueInfo).minimumValue ? QCameraImageProcessing::WhiteBalanceAuto
- : QCameraImageProcessing::WhiteBalanceManual;
- const QCameraImageProcessing::WhiteBalanceMode secondAllowedValue =
- (*sourceValueInfo).maximumValue ? QCameraImageProcessing::WhiteBalanceAuto
- : QCameraImageProcessing::WhiteBalanceManual;
- if (checkedValue != firstAllowedValue
- && checkedValue != secondAllowedValue) {
- return false;
- }
- }
- break;
-
- case QCameraImageProcessingControl::ColorTemperature: {
- const qint32 checkedValue = value.toInt();
- if (checkedValue < (*sourceValueInfo).minimumValue
- || checkedValue > (*sourceValueInfo).maximumValue) {
- return false;
- }
- }
- break;
-
- case QCameraImageProcessingControl::ContrastAdjustment: // falling back
- case QCameraImageProcessingControl::SaturationAdjustment: // falling back
- case QCameraImageProcessingControl::BrightnessAdjustment: // falling back
- case QCameraImageProcessingControl::SharpeningAdjustment: {
- const qint32 sourceValue = sourceImageProcessingParameterValue(
- value.toReal(), (*sourceValueInfo));
- if (sourceValue < (*sourceValueInfo).minimumValue
- || sourceValue > (*sourceValueInfo).maximumValue) {
- return false;
- }
- }
- break;
-
- default:
- return false;
- }
-
- return true;
-}
-
-QVariant CameraBinV4LImageProcessing::parameter(
- ProcessingParameter parameter) const
-{
- QMap<ProcessingParameter, SourceParameterValueInfo>::const_iterator sourceValueInfo =
- m_parametersInfo.constFind(parameter);
- if (sourceValueInfo == m_parametersInfo.constEnd()) {
- if (!m_parametersInfo.empty())
- qWarning() << "Unable to get the unsupported parameter:" << parameter;
- return QVariant();
- }
-
- const QString deviceName = m_session->device();
- const int fd = qt_safe_open(deviceName.toLocal8Bit().constData(), O_RDONLY);
- if (fd == -1) {
- qWarning() << "Unable to open the camera" << deviceName
- << "for read to get the parameter value:" << qt_error_string(errno);
- return QVariant();
- }
-
- struct v4l2_control control;
- ::memset(&control, 0, sizeof(control));
- control.id = (*sourceValueInfo).cid;
-
- const bool ret = (::ioctl(fd, VIDIOC_G_CTRL, &control) == 0);
-
- qt_safe_close(fd);
-
- if (!ret) {
- qWarning() << "Unable to get the parameter value:" << parameter << ":" << qt_error_string(errno);
- return QVariant();
- }
-
- switch (parameter) {
-
- case QCameraImageProcessingControl::WhiteBalancePreset:
- return QVariant::fromValue<QCameraImageProcessing::WhiteBalanceMode>(
- control.value ? QCameraImageProcessing::WhiteBalanceAuto
- : QCameraImageProcessing::WhiteBalanceManual);
-
- case QCameraImageProcessingControl::ColorTemperature:
- return QVariant::fromValue<qint32>(control.value);
-
- case QCameraImageProcessingControl::ContrastAdjustment: // falling back
- case QCameraImageProcessingControl::SaturationAdjustment: // falling back
- case QCameraImageProcessingControl::BrightnessAdjustment: // falling back
- case QCameraImageProcessingControl::SharpeningAdjustment: {
- return scaledImageProcessingParameterValue(
- control.value, (*sourceValueInfo));
- }
-
- default:
- return QVariant();
- }
-}
-
-void CameraBinV4LImageProcessing::setParameter(
- ProcessingParameter parameter, const QVariant &value)
-{
- QMap<ProcessingParameter, SourceParameterValueInfo>::const_iterator sourceValueInfo =
- m_parametersInfo.constFind(parameter);
- if (sourceValueInfo == m_parametersInfo.constEnd()) {
- if (!m_parametersInfo.empty())
- qWarning() << "Unable to set the unsupported parameter:" << parameter;
- return;
- }
-
- const QString deviceName = m_session->device();
- const int fd = qt_safe_open(deviceName.toLocal8Bit().constData(), O_WRONLY);
- if (fd == -1) {
- qWarning() << "Unable to open the camera" << deviceName
- << "for write to set the parameter value:" << qt_error_string(errno);
- return;
- }
-
- struct v4l2_control control;
- ::memset(&control, 0, sizeof(control));
- control.id = (*sourceValueInfo).cid;
-
- switch (parameter) {
-
- case QCameraImageProcessingControl::WhiteBalancePreset: {
- const QCameraImageProcessing::WhiteBalanceMode m =
- value.value<QCameraImageProcessing::WhiteBalanceMode>();
- if (m != QCameraImageProcessing::WhiteBalanceAuto
- && m != QCameraImageProcessing::WhiteBalanceManual) {
- qt_safe_close(fd);
- return;
- }
-
- control.value = (m == QCameraImageProcessing::WhiteBalanceAuto) ? true : false;
- }
- break;
-
- case QCameraImageProcessingControl::ColorTemperature:
- control.value = value.toInt();
- break;
-
- case QCameraImageProcessingControl::ContrastAdjustment: // falling back
- case QCameraImageProcessingControl::SaturationAdjustment: // falling back
- case QCameraImageProcessingControl::BrightnessAdjustment: // falling back
- case QCameraImageProcessingControl::SharpeningAdjustment:
- control.value = sourceImageProcessingParameterValue(
- value.toReal(), (*sourceValueInfo));
- break;
-
- default:
- qt_safe_close(fd);
- return;
- }
-
- if (::ioctl(fd, VIDIOC_S_CTRL, &control) != 0)
- qWarning() << "Unable to set the parameter value:" << parameter << ":" << qt_error_string(errno);
-
- qt_safe_close(fd);
-}
-
-void CameraBinV4LImageProcessing::updateParametersInfo(
- QCamera::Status cameraStatus)
-{
- if (cameraStatus == QCamera::UnloadedStatus)
- m_parametersInfo.clear();
- else if (cameraStatus == QCamera::LoadedStatus) {
- const QString deviceName = m_session->device();
- const int fd = qt_safe_open(deviceName.toLocal8Bit().constData(), O_RDONLY);
- if (fd == -1) {
- qWarning() << "Unable to open the camera" << deviceName
- << "for read to query the parameter info:" << qt_error_string(errno);
- return;
- }
-
- static const struct SupportedParameterEntry {
- quint32 cid;
- QCameraImageProcessingControl::ProcessingParameter parameter;
- } supportedParametersEntries[] = {
- { V4L2_CID_AUTO_WHITE_BALANCE, QCameraImageProcessingControl::WhiteBalancePreset },
- { V4L2_CID_WHITE_BALANCE_TEMPERATURE, QCameraImageProcessingControl::ColorTemperature },
- { V4L2_CID_CONTRAST, QCameraImageProcessingControl::ContrastAdjustment },
- { V4L2_CID_SATURATION, QCameraImageProcessingControl::SaturationAdjustment },
- { V4L2_CID_BRIGHTNESS, QCameraImageProcessingControl::BrightnessAdjustment },
- { V4L2_CID_SHARPNESS, QCameraImageProcessingControl::SharpeningAdjustment }
- };
-
- for (int i = 0; i < int(sizeof(supportedParametersEntries) / sizeof(SupportedParameterEntry)); ++i) {
- struct v4l2_queryctrl queryControl;
- ::memset(&queryControl, 0, sizeof(queryControl));
- queryControl.id = supportedParametersEntries[i].cid;
-
- if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) != 0) {
- qWarning() << "Unable to query the parameter info:" << supportedParametersEntries[i].parameter
- << ":" << qt_error_string(errno);
- continue;
- }
-
- SourceParameterValueInfo sourceValueInfo;
- sourceValueInfo.cid = queryControl.id;
- sourceValueInfo.defaultValue = queryControl.default_value;
- sourceValueInfo.maximumValue = queryControl.maximum;
- sourceValueInfo.minimumValue = queryControl.minimum;
-
- m_parametersInfo.insert(supportedParametersEntries[i].parameter, sourceValueInfo);
- }
-
- qt_safe_close(fd);
- }
-}
-
-qreal CameraBinV4LImageProcessing::scaledImageProcessingParameterValue(
- qint32 sourceValue, const SourceParameterValueInfo &sourceValueInfo)
-{
- if (sourceValue == sourceValueInfo.defaultValue) {
- return 0.0f;
- } else if (sourceValue < sourceValueInfo.defaultValue) {
- return ((sourceValue - sourceValueInfo.minimumValue)
- / qreal(sourceValueInfo.defaultValue - sourceValueInfo.minimumValue))
- + (-1.0f);
- } else {
- return ((sourceValue - sourceValueInfo.defaultValue)
- / qreal(sourceValueInfo.maximumValue - sourceValueInfo.defaultValue));
- }
-}
-
-qint32 CameraBinV4LImageProcessing::sourceImageProcessingParameterValue(
- qreal scaledValue, const SourceParameterValueInfo &valueRange)
-{
- if (qFuzzyIsNull(scaledValue)) {
- return valueRange.defaultValue;
- } else if (scaledValue < 0.0f) {
- return ((scaledValue - (-1.0f)) * (valueRange.defaultValue - valueRange.minimumValue))
- + valueRange.minimumValue;
- } else {
- return (scaledValue * (valueRange.maximumValue - valueRange.defaultValue))
- + valueRange.defaultValue;
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h b/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h
deleted file mode 100644
index a38dc78da..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinv4limageprocessing.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINV4LIMAGEPROCESSINGCONTROL_H
-#define CAMERABINV4LIMAGEPROCESSINGCONTROL_H
-
-#include <qcamera.h>
-#include <qcameraimageprocessingcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-
-class CameraBinV4LImageProcessing : public QCameraImageProcessingControl
-{
- Q_OBJECT
-
-public:
- CameraBinV4LImageProcessing(CameraBinSession *session);
- virtual ~CameraBinV4LImageProcessing();
-
- bool isParameterSupported(ProcessingParameter) const override;
- bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const override;
- QVariant parameter(ProcessingParameter parameter) const override;
- void setParameter(ProcessingParameter parameter, const QVariant &value) override;
-
-public slots:
- void updateParametersInfo(QCamera::Status cameraStatus);
-
-private:
- struct SourceParameterValueInfo {
- SourceParameterValueInfo()
- : cid(0)
- {
- }
-
- qint32 defaultValue;
- qint32 minimumValue;
- qint32 maximumValue;
- quint32 cid; // V4L control id
- };
-
- static qreal scaledImageProcessingParameterValue(
- qint32 sourceValue, const SourceParameterValueInfo &sourceValueInfo);
- static qint32 sourceImageProcessingParameterValue(
- qreal scaledValue, const SourceParameterValueInfo &valueRange);
-private:
- CameraBinSession *m_session;
- QMap<ProcessingParameter, SourceParameterValueInfo> m_parametersInfo;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINV4LIMAGEPROCESSINGCONTROL_H
diff --git a/src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp b/src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp
deleted file mode 100644
index 5bba2ddb5..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp
+++ /dev/null
@@ -1,239 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "camerabinvideoencoder.h"
-#include "camerabinsession.h"
-#include "camerabincontainer.h"
-#include <private/qgstutils_p.h>
-
-#include <QtCore/qdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-CameraBinVideoEncoder::CameraBinVideoEncoder(CameraBinSession *session)
- :QVideoEncoderSettingsControl(session)
- , m_session(session)
-#if QT_CONFIG(gstreamer_encodingprofiles)
- , m_codecs(QGstCodecsInfo::VideoEncoder)
-#endif
-{
-}
-
-CameraBinVideoEncoder::~CameraBinVideoEncoder()
-{
-}
-
-QList<QSize> CameraBinVideoEncoder::supportedResolutions(const QVideoEncoderSettings &settings, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- QPair<int,int> rate = rateAsRational(settings.frameRate());
-
- //select the closest supported rational rate to settings.frameRate()
-
- return m_session->supportedResolutions(rate, continuous, QCamera::CaptureVideo);
-}
-
-QList< qreal > CameraBinVideoEncoder::supportedFrameRates(const QVideoEncoderSettings &settings, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- QList< qreal > res;
-
- const auto rates = m_session->supportedFrameRates(settings.resolution(), continuous);
- for (const auto &rate : rates) {
- if (rate.second > 0)
- res << qreal(rate.first)/rate.second;
- }
-
- return res;
-}
-
-QStringList CameraBinVideoEncoder::supportedVideoCodecs() const
-{
-#if QT_CONFIG(gstreamer_encodingprofiles)
- return m_codecs.supportedCodecs();
-#else
- return QStringList();
-#endif
-}
-
-QString CameraBinVideoEncoder::videoCodecDescription(const QString &codecName) const
-{
-#if QT_CONFIG(gstreamer_encodingprofiles)
- return m_codecs.codecDescription(codecName);
-#else
- Q_UNUSED(codecName);
- return QString();
-#endif
-}
-
-QVideoEncoderSettings CameraBinVideoEncoder::videoSettings() const
-{
- return m_videoSettings;
-}
-
-void CameraBinVideoEncoder::setVideoSettings(const QVideoEncoderSettings &settings)
-{
- if (m_videoSettings != settings) {
- m_actualVideoSettings = settings;
- m_videoSettings = settings;
- emit settingsChanged();
- }
-}
-
-QVideoEncoderSettings CameraBinVideoEncoder::actualVideoSettings() const
-{
- return m_actualVideoSettings;
-}
-
-void CameraBinVideoEncoder::setActualVideoSettings(const QVideoEncoderSettings &settings)
-{
- m_actualVideoSettings = settings;
-}
-
-void CameraBinVideoEncoder::resetActualSettings()
-{
- m_actualVideoSettings = m_videoSettings;
-}
-
-
-QPair<int,int> CameraBinVideoEncoder::rateAsRational(qreal frameRate) const
-{
- if (frameRate > 0.001) {
- //convert to rational number
- QList<int> denumCandidates;
- denumCandidates << 1 << 2 << 3 << 5 << 10 << 25 << 30 << 50 << 100 << 1001 << 1000;
-
- qreal error = 1.0;
- int num = 1;
- int denum = 1;
-
- for (int curDenum : qAsConst(denumCandidates)) {
- int curNum = qRound(frameRate*curDenum);
- qreal curError = qAbs(qreal(curNum)/curDenum - frameRate);
-
- if (curError < error) {
- error = curError;
- num = curNum;
- denum = curDenum;
- }
-
- if (curError < 1e-8)
- break;
- }
-
- return QPair<int,int>(num,denum);
- }
-
- return QPair<int,int>();
-}
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
-
-GstEncodingProfile *CameraBinVideoEncoder::createProfile()
-{
- QString codec = m_actualVideoSettings.codec();
- GstCaps *caps = !codec.isEmpty() ? gst_caps_from_string(codec.toLatin1()) : nullptr;
-
- if (!caps)
- return nullptr;
-
- QString preset = m_actualVideoSettings.encodingOption(QStringLiteral("preset")).toString();
- GstEncodingVideoProfile *profile = gst_encoding_video_profile_new(
- caps,
- !preset.isEmpty() ? preset.toLatin1().constData() : NULL, //preset
- NULL, //restriction
- 1); //presence
-
- gst_caps_unref(caps);
-
- gst_encoding_video_profile_set_pass(profile, 0);
- gst_encoding_video_profile_set_variableframerate(profile, TRUE);
-
- return (GstEncodingProfile *)profile;
-}
-
-#endif
-
-void CameraBinVideoEncoder::applySettings(GstElement *encoder)
-{
- GObjectClass * const objectClass = G_OBJECT_GET_CLASS(encoder);
- const char * const name = qt_gst_element_get_factory_name(encoder);
-
- const int bitRate = m_actualVideoSettings.bitRate();
- if (bitRate == -1) {
- // Bit rate is invalid, don't evaluate the remaining conditions.
- } else if (g_object_class_find_property(objectClass, "bitrate")) {
- g_object_set(G_OBJECT(encoder), "bitrate", bitRate, NULL);
- } else if (g_object_class_find_property(objectClass, "target-bitrate")) {
- g_object_set(G_OBJECT(encoder), "target-bitrate", bitRate, NULL);
- }
-
- if (qstrcmp(name, "theoraenc") == 0) {
- static const int qualities[] = { 8, 16, 32, 45, 60 };
- g_object_set(G_OBJECT(encoder), "quality", qualities[m_actualVideoSettings.quality()], NULL);
- } else if (qstrncmp(name, "avenc_", 6) == 0) {
- if (g_object_class_find_property(objectClass, "pass")) {
- static const int modes[] = { 0, 2, 512, 1024 };
- g_object_set(G_OBJECT(encoder), "pass", modes[m_actualVideoSettings.encodingMode()], NULL);
- }
- if (g_object_class_find_property(objectClass, "quantizer")) {
- static const double qualities[] = { 20, 8.0, 3.0, 2.5, 2.0 };
- g_object_set(G_OBJECT(encoder), "quantizer", qualities[m_actualVideoSettings.quality()], NULL);
- }
- } else if (qstrncmp(name, "omx", 3) == 0) {
- if (!g_object_class_find_property(objectClass, "control-rate")) {
- } else switch (m_actualVideoSettings.encodingMode()) {
- case QMultimedia::ConstantBitRateEncoding:
- g_object_set(G_OBJECT(encoder), "control-rate", 2, NULL);
- break;
- case QMultimedia::AverageBitRateEncoding:
- g_object_set(G_OBJECT(encoder), "control-rate", 1, NULL);
- break;
- default:
- g_object_set(G_OBJECT(encoder), "control-rate", 0, NULL);
- }
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinvideoencoder.h b/src/plugins/gstreamer/camerabin/camerabinvideoencoder.h
deleted file mode 100644
index 24013ceab..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinvideoencoder.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINVIDEOENCODE_H
-#define CAMERABINVIDEOENCODE_H
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <qvideoencodersettingscontrol.h>
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmap.h>
-#include <QtCore/qset.h>
-
-#include <gst/gst.h>
-#include <gst/pbutils/pbutils.h>
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
-#include <gst/pbutils/encoding-profile.h>
-#include <private/qgstcodecsinfo_p.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-
-class CameraBinVideoEncoder : public QVideoEncoderSettingsControl
-{
- Q_OBJECT
-public:
- CameraBinVideoEncoder(CameraBinSession *session);
- virtual ~CameraBinVideoEncoder();
-
- QList<QSize> supportedResolutions(const QVideoEncoderSettings &settings = QVideoEncoderSettings(),
- bool *continuous = 0) const override;
-
- QList< qreal > supportedFrameRates(const QVideoEncoderSettings &settings = QVideoEncoderSettings(),
- bool *continuous = 0) const override;
-
- QPair<int,int> rateAsRational(qreal) const;
-
- QStringList supportedVideoCodecs() const override;
- QString videoCodecDescription(const QString &codecName) const override;
-
- QVideoEncoderSettings videoSettings() const override;
- void setVideoSettings(const QVideoEncoderSettings &settings) override;
-
- QVideoEncoderSettings actualVideoSettings() const;
- void setActualVideoSettings(const QVideoEncoderSettings&);
- void resetActualSettings();
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
- GstEncodingProfile *createProfile();
-#endif
-
- void applySettings(GstElement *encoder);
-
-Q_SIGNALS:
- void settingsChanged();
-
-private:
- CameraBinSession *m_session;
-
-#if QT_CONFIG(gstreamer_encodingprofiles)
- QGstCodecsInfo m_codecs;
-#endif
-
- QVideoEncoderSettings m_actualVideoSettings;
- QVideoEncoderSettings m_videoSettings;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/camerabin/camerabinviewfindersettings.cpp b/src/plugins/gstreamer/camerabin/camerabinviewfindersettings.cpp
deleted file mode 100644
index 0e14a15e5..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinviewfindersettings.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include "camerabinviewfindersettings.h"
-#include "camerabinsession.h"
-
-QT_BEGIN_NAMESPACE
-
-
-CameraBinViewfinderSettings::CameraBinViewfinderSettings(CameraBinSession *session)
- : QCameraViewfinderSettingsControl(session)
- , m_session(session)
-{
-}
-
-CameraBinViewfinderSettings::~CameraBinViewfinderSettings()
-{
-}
-
-bool CameraBinViewfinderSettings::isViewfinderParameterSupported(ViewfinderParameter parameter) const
-{
- switch (parameter) {
- case Resolution:
- case PixelAspectRatio:
- case MinimumFrameRate:
- case MaximumFrameRate:
- case PixelFormat:
- return true;
- case UserParameter:
- return false;
- }
- return false;
-}
-
-QVariant CameraBinViewfinderSettings::viewfinderParameter(ViewfinderParameter parameter) const
-{
- switch (parameter) {
- case Resolution:
- return m_session->viewfinderSettings().resolution();
- case PixelAspectRatio:
- return m_session->viewfinderSettings().pixelAspectRatio();
- case MinimumFrameRate:
- return m_session->viewfinderSettings().minimumFrameRate();
- case MaximumFrameRate:
- return m_session->viewfinderSettings().maximumFrameRate();
- case PixelFormat:
- return m_session->viewfinderSettings().pixelFormat();
- case UserParameter:
- return QVariant();
- }
- return false;
-}
-
-void CameraBinViewfinderSettings::setViewfinderParameter(ViewfinderParameter parameter, const QVariant &value)
-{
- QCameraViewfinderSettings settings = m_session->viewfinderSettings();
-
- switch (parameter) {
- case Resolution:
- settings.setResolution(value.toSize());
- break;
- case PixelAspectRatio:
- settings.setPixelAspectRatio(value.toSize());
- break;
- case MinimumFrameRate:
- settings.setMinimumFrameRate(value.toReal());
- break;
- case MaximumFrameRate:
- settings.setMaximumFrameRate(value.toReal());
- break;
- case PixelFormat:
- settings.setPixelFormat(qvariant_cast<QVideoFrame::PixelFormat>(value));
- case UserParameter:
- break;
- }
-
- m_session->setViewfinderSettings(settings);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinviewfindersettings.h b/src/plugins/gstreamer/camerabin/camerabinviewfindersettings.h
deleted file mode 100644
index 59a0ca8a9..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinviewfindersettings.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd.
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINVIEWFINDERSETTINGS_H
-#define CAMERABINVIEWFINDERSETTINGS_H
-
-#include <qcameraviewfindersettingscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-
-class CameraBinViewfinderSettings : public QCameraViewfinderSettingsControl
-{
- Q_OBJECT
-public:
- CameraBinViewfinderSettings(CameraBinSession *session);
- ~CameraBinViewfinderSettings();
-
- bool isViewfinderParameterSupported(ViewfinderParameter parameter) const override;
- QVariant viewfinderParameter(ViewfinderParameter parameter) const override;
- void setViewfinderParameter(ViewfinderParameter parameter, const QVariant &value) override;
-
-private:
- CameraBinSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/camerabin/camerabinviewfindersettings2.cpp b/src/plugins/gstreamer/camerabin/camerabinviewfindersettings2.cpp
deleted file mode 100644
index a7199216e..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinviewfindersettings2.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabinviewfindersettings2.h"
-#include "camerabinsession.h"
-
-QT_BEGIN_NAMESPACE
-
-CameraBinViewfinderSettings2::CameraBinViewfinderSettings2(CameraBinSession *session)
- : QCameraViewfinderSettingsControl2(session)
- , m_session(session)
-{
-
-}
-
-CameraBinViewfinderSettings2::~CameraBinViewfinderSettings2()
-{
-
-}
-
-QList<QCameraViewfinderSettings> CameraBinViewfinderSettings2::supportedViewfinderSettings() const
-{
- return m_session->supportedViewfinderSettings();
-}
-
-QCameraViewfinderSettings CameraBinViewfinderSettings2::viewfinderSettings() const
-{
- return m_session->viewfinderSettings();
-}
-
-void CameraBinViewfinderSettings2::setViewfinderSettings(const QCameraViewfinderSettings &settings)
-{
- m_session->setViewfinderSettings(settings);
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/plugins/gstreamer/camerabin/camerabinviewfindersettings2.h b/src/plugins/gstreamer/camerabin/camerabinviewfindersettings2.h
deleted file mode 100644
index 5e03b007a..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinviewfindersettings2.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINVIEWFINDERSETTINGS2_H
-#define CAMERABINVIEWFINDERSETTINGS2_H
-
-#include <qcameraviewfindersettingscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-
-class CameraBinViewfinderSettings2 : public QCameraViewfinderSettingsControl2
-{
- Q_OBJECT
-public:
- CameraBinViewfinderSettings2(CameraBinSession *session);
- ~CameraBinViewfinderSettings2();
-
- QList<QCameraViewfinderSettings> supportedViewfinderSettings() const override;
-
- QCameraViewfinderSettings viewfinderSettings() const override;
- void setViewfinderSettings(const QCameraViewfinderSettings &settings) override;
-
-private:
- CameraBinSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINVIEWFINDERSETTINGS2_H
diff --git a/src/plugins/gstreamer/camerabin/camerabinzoom.cpp b/src/plugins/gstreamer/camerabin/camerabinzoom.cpp
deleted file mode 100644
index 401e13207..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinzoom.cpp
+++ /dev/null
@@ -1,147 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "camerabinzoom.h"
-#include "camerabinsession.h"
-
-#define ZOOM_PROPERTY "zoom"
-#define MAX_ZOOM_PROPERTY "max-zoom"
-
-QT_BEGIN_NAMESPACE
-
-CameraBinZoom::CameraBinZoom(CameraBinSession *session)
- : QCameraZoomControl(session)
- , m_session(session)
- , m_requestedOpticalZoom(1.0)
- , m_requestedDigitalZoom(1.0)
-{
- GstElement *camerabin = m_session->cameraBin();
- g_signal_connect(G_OBJECT(camerabin), "notify::zoom", G_CALLBACK(updateZoom), this);
- g_signal_connect(G_OBJECT(camerabin), "notify::max-zoom", G_CALLBACK(updateMaxZoom), this);
-}
-
-CameraBinZoom::~CameraBinZoom()
-{
-}
-
-qreal CameraBinZoom::maximumOpticalZoom() const
-{
- return 1.0;
-}
-
-qreal CameraBinZoom::maximumDigitalZoom() const
-{
- gfloat zoomFactor = 1.0;
- g_object_get(GST_BIN(m_session->cameraBin()), MAX_ZOOM_PROPERTY, &zoomFactor, NULL);
- return zoomFactor;
-}
-
-qreal CameraBinZoom::requestedDigitalZoom() const
-{
- return m_requestedDigitalZoom;
-}
-
-qreal CameraBinZoom::requestedOpticalZoom() const
-{
- return m_requestedOpticalZoom;
-}
-
-qreal CameraBinZoom::currentOpticalZoom() const
-{
- return 1.0;
-}
-
-qreal CameraBinZoom::currentDigitalZoom() const
-{
- gfloat zoomFactor = 1.0;
- g_object_get(GST_BIN(m_session->cameraBin()), ZOOM_PROPERTY, &zoomFactor, NULL);
- return zoomFactor;
-}
-
-void CameraBinZoom::zoomTo(qreal optical, qreal digital)
-{
- qreal oldDigitalZoom = currentDigitalZoom();
-
- if (m_requestedDigitalZoom != digital) {
- m_requestedDigitalZoom = digital;
- emit requestedDigitalZoomChanged(digital);
- }
-
- if (m_requestedOpticalZoom != optical) {
- m_requestedOpticalZoom = optical;
- emit requestedOpticalZoomChanged(optical);
- }
-
- digital = qBound(qreal(1.0), digital, maximumDigitalZoom());
- g_object_set(GST_BIN(m_session->cameraBin()), ZOOM_PROPERTY, digital, NULL);
-
- qreal newDigitalZoom = currentDigitalZoom();
- if (!qFuzzyCompare(oldDigitalZoom, newDigitalZoom))
- emit currentDigitalZoomChanged(digital);
-}
-
-void CameraBinZoom::updateZoom(GObject *o, GParamSpec *p, gpointer d)
-{
- Q_UNUSED(p);
-
- gfloat zoomFactor = 1.0;
- g_object_get(o, ZOOM_PROPERTY, &zoomFactor, NULL);
-
- CameraBinZoom *zoom = reinterpret_cast<CameraBinZoom *>(d);
-
- QMetaObject::invokeMethod(zoom, "currentDigitalZoomChanged",
- Qt::QueuedConnection,
- Q_ARG(qreal, zoomFactor));
-}
-
-void CameraBinZoom::updateMaxZoom(GObject *o, GParamSpec *p, gpointer d)
-{
- Q_UNUSED(p);
-
- gfloat zoomFactor = 1.0;
- g_object_get(o, MAX_ZOOM_PROPERTY, &zoomFactor, NULL);
-
- CameraBinZoom *zoom = reinterpret_cast<CameraBinZoom *>(d);
-
- QMetaObject::invokeMethod(zoom, "maximumDigitalZoomChanged",
- Qt::QueuedConnection,
- Q_ARG(qreal, zoomFactor));
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinzoom.h b/src/plugins/gstreamer/camerabin/camerabinzoom.h
deleted file mode 100644
index 858ada2da..000000000
--- a/src/plugins/gstreamer/camerabin/camerabinzoom.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERABINZOOMCONTROL_H
-#define CAMERABINZOOMCONTROL_H
-
-#include <qcamerazoomcontrol.h>
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-class CameraBinSession;
-
-class CameraBinZoom : public QCameraZoomControl
-{
- Q_OBJECT
-public:
- CameraBinZoom(CameraBinSession *session);
- virtual ~CameraBinZoom();
-
- qreal maximumOpticalZoom() const override;
- qreal maximumDigitalZoom() const override;
-
- qreal requestedOpticalZoom() const override;
- qreal requestedDigitalZoom() const override;
- qreal currentOpticalZoom() const override;
- qreal currentDigitalZoom() const override;
-
- void zoomTo(qreal optical, qreal digital) override;
-
-private:
- static void updateZoom(GObject *o, GParamSpec *p, gpointer d);
- static void updateMaxZoom(GObject *o, GParamSpec *p, gpointer d);
-
- CameraBinSession *m_session;
- qreal m_requestedOpticalZoom;
- qreal m_requestedDigitalZoom;
-};
-
-QT_END_NAMESPACE
-
-#endif // CAMERABINZOOMCONTROL_H
diff --git a/src/plugins/gstreamer/common.pri b/src/plugins/gstreamer/common.pri
deleted file mode 100644
index d0c5c7bdd..000000000
--- a/src/plugins/gstreamer/common.pri
+++ /dev/null
@@ -1,15 +0,0 @@
-QT += core-private multimedia-private multimediagsttools-private network
-
-qtHaveModule(widgets) {
- QT += widgets multimediawidgets-private
- DEFINES += HAVE_WIDGETS
-}
-
-QMAKE_USE += gstreamer
-
-qtConfig(resourcepolicy): \
- QMAKE_USE += libresourceqt5
-
-qtConfig(gstreamer_app): \
- QMAKE_USE += gstreamer_app
-
diff --git a/src/plugins/gstreamer/gstreamer.json b/src/plugins/gstreamer/gstreamer.json
deleted file mode 100644
index 0656cce4f..000000000
--- a/src/plugins/gstreamer/gstreamer.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["gstreamer"],
- "Services": ["org.qt-project.qt.mediaplayer", "org.qt-project.qt.audiosource", "org.qt-project.qt.camera", "org.qt-project.qt.audiodecode"]
-}
diff --git a/src/plugins/gstreamer/gstreamer.pro b/src/plugins/gstreamer/gstreamer.pro
deleted file mode 100644
index 5fb8f83c6..000000000
--- a/src/plugins/gstreamer/gstreamer.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS += \
- audiodecoder \
- camerabin \
- mediaplayer \
- mediacapture
-
-OTHER_FILES += \
- gstreamer.json
diff --git a/src/plugins/gstreamer/mediacapture/mediacapture.json b/src/plugins/gstreamer/mediacapture/mediacapture.json
deleted file mode 100644
index 68ca3f55b..000000000
--- a/src/plugins/gstreamer/mediacapture/mediacapture.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["gstreamermediacapture"],
- "Services": ["org.qt-project.qt.audiosource"]
-}
diff --git a/src/plugins/gstreamer/mediacapture/mediacapture.pro b/src/plugins/gstreamer/mediacapture/mediacapture.pro
deleted file mode 100644
index 17248a495..000000000
--- a/src/plugins/gstreamer/mediacapture/mediacapture.pro
+++ /dev/null
@@ -1,52 +0,0 @@
-TARGET = gstmediacapture
-
-include(../common.pri)
-
-INCLUDEPATH += $$PWD
-
-HEADERS += $$PWD/qgstreamercaptureservice.h \
- $$PWD/qgstreamercapturesession.h \
- $$PWD/qgstreameraudioencode.h \
- $$PWD/qgstreamervideoencode.h \
- $$PWD/qgstreamerrecordercontrol.h \
- $$PWD/qgstreamermediacontainercontrol.h \
- $$PWD/qgstreamercameracontrol.h \
- $$PWD/qgstreamercapturemetadatacontrol.h \
- $$PWD/qgstreamerimagecapturecontrol.h \
- $$PWD/qgstreamerimageencode.h \
- $$PWD/qgstreamercaptureserviceplugin.h
-
-SOURCES += $$PWD/qgstreamercaptureservice.cpp \
- $$PWD/qgstreamercapturesession.cpp \
- $$PWD/qgstreameraudioencode.cpp \
- $$PWD/qgstreamervideoencode.cpp \
- $$PWD/qgstreamerrecordercontrol.cpp \
- $$PWD/qgstreamermediacontainercontrol.cpp \
- $$PWD/qgstreamercameracontrol.cpp \
- $$PWD/qgstreamercapturemetadatacontrol.cpp \
- $$PWD/qgstreamerimagecapturecontrol.cpp \
- $$PWD/qgstreamerimageencode.cpp \
- $$PWD/qgstreamercaptureserviceplugin.cpp
-
-# Camera usage with gstreamer needs to have
-#CONFIG += use_gstreamer_camera
-
-use_gstreamer_camera:qtConfig(linux_v4l) {
- DEFINES += USE_GSTREAMER_CAMERA
-
- OTHER_FILES += \
- mediacapturecamera.json
-
- HEADERS += \
- $$PWD/qgstreamerv4l2input.h
- SOURCES += \
- $$PWD/qgstreamerv4l2input.cpp
-
-} else {
- OTHER_FILES += \
- mediacapture.json
-}
-
-PLUGIN_TYPE = mediaservice
-PLUGIN_CLASS_NAME = QGstreamerCaptureServicePlugin
-load(qt_plugin)
diff --git a/src/plugins/gstreamer/mediacapture/mediacapturecamera.json b/src/plugins/gstreamer/mediacapture/mediacapturecamera.json
deleted file mode 100644
index f5fba17e6..000000000
--- a/src/plugins/gstreamer/mediacapture/mediacapturecamera.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["gstreamermediacapture"],
- "Services": ["org.qt-project.qt.audiosource", "org.qt-project.qt.camera"]
-}
diff --git a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.cpp b/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.cpp
deleted file mode 100644
index 1a35c5cf6..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.cpp
+++ /dev/null
@@ -1,239 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreameraudioencode.h"
-#include "qgstreamercapturesession.h"
-#include "qgstreamermediacontainercontrol.h"
-#include <private/qgstutils_p.h>
-
-#include <QtCore/qdebug.h>
-
-#include <math.h>
-
-QGstreamerAudioEncode::QGstreamerAudioEncode(QObject *parent)
- :QAudioEncoderSettingsControl(parent)
- , m_codecs(QGstCodecsInfo::AudioEncoder)
-{
-}
-
-QGstreamerAudioEncode::~QGstreamerAudioEncode()
-{
-}
-
-QStringList QGstreamerAudioEncode::supportedAudioCodecs() const
-{
- return m_codecs.supportedCodecs();
-}
-
-QString QGstreamerAudioEncode::codecDescription(const QString &codecName) const
-{
- return m_codecs.codecDescription(codecName);
-}
-
-QStringList QGstreamerAudioEncode::supportedEncodingOptions(const QString &codec) const
-{
- return m_codecs.codecOptions(codec);
-}
-
-QVariant QGstreamerAudioEncode::encodingOption(
- const QString &codec, const QString &name) const
-{
- return m_options[codec].value(name);
-}
-
-void QGstreamerAudioEncode::setEncodingOption(
- const QString &codec, const QString &name, const QVariant &value)
-{
- m_options[codec][name] = value;
-}
-
-QList<int> QGstreamerAudioEncode::supportedSampleRates(const QAudioEncoderSettings &, bool *) const
-{
- //TODO check element caps to find actual values
-
- return QList<int>();
-}
-
-QAudioEncoderSettings QGstreamerAudioEncode::audioSettings() const
-{
- return m_audioSettings;
-}
-
-void QGstreamerAudioEncode::setAudioSettings(const QAudioEncoderSettings &settings)
-{
- m_audioSettings = settings;
-}
-
-
-GstElement *QGstreamerAudioEncode::createEncoder()
-{
- QString codec = m_audioSettings.codec();
- GstElement *encoderElement = gst_element_factory_make(m_codecs.codecElement(codec).constData(), NULL);
- if (!encoderElement)
- return 0;
-
- GstBin * encoderBin = GST_BIN(gst_bin_new("audio-encoder-bin"));
-
- GstElement *sinkCapsFilter = gst_element_factory_make("capsfilter", NULL);
- GstElement *srcCapsFilter = gst_element_factory_make("capsfilter", NULL);
-
- gst_bin_add_many(encoderBin, sinkCapsFilter, encoderElement, srcCapsFilter, NULL);
- gst_element_link_many(sinkCapsFilter, encoderElement, srcCapsFilter, NULL);
-
- // add ghostpads
- GstPad *pad = gst_element_get_static_pad(sinkCapsFilter, "sink");
- gst_element_add_pad(GST_ELEMENT(encoderBin), gst_ghost_pad_new("sink", pad));
- gst_object_unref(GST_OBJECT(pad));
-
- pad = gst_element_get_static_pad(srcCapsFilter, "src");
- gst_element_add_pad(GST_ELEMENT(encoderBin), gst_ghost_pad_new("src", pad));
- gst_object_unref(GST_OBJECT(pad));
-
- if (m_audioSettings.sampleRate() > 0 || m_audioSettings.channelCount() > 0) {
- GstCaps *caps = gst_caps_new_empty();
- GstStructure *structure = qt_gst_structure_new_empty(QT_GSTREAMER_RAW_AUDIO_MIME);
-
- if (m_audioSettings.sampleRate() > 0)
- gst_structure_set(structure, "rate", G_TYPE_INT, m_audioSettings.sampleRate(), NULL );
-
- if (m_audioSettings.channelCount() > 0)
- gst_structure_set(structure, "channels", G_TYPE_INT, m_audioSettings.channelCount(), NULL );
-
- gst_caps_append_structure(caps,structure);
-
- g_object_set(G_OBJECT(sinkCapsFilter), "caps", caps, NULL);
-
- gst_caps_unref(caps);
- }
-
- // Some encoders support several codecs. Setting a caps filter downstream with the desired
- // codec (which is actually a string representation of the caps) will make sure we use the
- // correct codec.
- GstCaps *caps = gst_caps_from_string(codec.toUtf8().constData());
- g_object_set(G_OBJECT(srcCapsFilter), "caps", caps, NULL);
- gst_caps_unref(caps);
-
- if (encoderElement) {
- if (m_audioSettings.encodingMode() == QMultimedia::ConstantQualityEncoding) {
- QMultimedia::EncodingQuality qualityValue = m_audioSettings.quality();
-
- if (codec == QLatin1String("audio/x-vorbis")) {
- double qualityTable[] = {
- 0.1, //VeryLow
- 0.3, //Low
- 0.5, //Normal
- 0.7, //High
- 1.0 //VeryHigh
- };
- g_object_set(G_OBJECT(encoderElement), "quality", qualityTable[qualityValue], NULL);
- } else if (codec == QLatin1String("audio/mpeg")) {
- g_object_set(G_OBJECT(encoderElement), "target", 0, NULL); //constant quality mode
- qreal quality[] = {
- 1, //VeryLow
- 3, //Low
- 5, //Normal
- 7, //High
- 9 //VeryHigh
- };
- g_object_set(G_OBJECT(encoderElement), "quality", quality[qualityValue], NULL);
- } else if (codec == QLatin1String("audio/x-speex")) {
- //0-10 range with default 8
- double qualityTable[] = {
- 2, //VeryLow
- 5, //Low
- 8, //Normal
- 9, //High
- 10 //VeryHigh
- };
- g_object_set(G_OBJECT(encoderElement), "quality", qualityTable[qualityValue], NULL);
- } else if (codec.startsWith("audio/AMR")) {
- int band[] = {
- 0, //VeryLow
- 2, //Low
- 4, //Normal
- 6, //High
- 7 //VeryHigh
- };
-
- g_object_set(G_OBJECT(encoderElement), "band-mode", band[qualityValue], NULL);
- }
- } else {
- int bitrate = m_audioSettings.bitRate();
- if (bitrate > 0) {
- if (codec == QLatin1String("audio/mpeg")) {
- g_object_set(G_OBJECT(encoderElement), "target", 1, NULL); //constant bitrate mode
- }
- g_object_set(G_OBJECT(encoderElement), "bitrate", bitrate, NULL);
- }
- }
-
- QMap<QString, QVariant> options = m_options.value(codec);
- for (auto it = options.cbegin(), end = options.cend(); it != end; ++it) {
- const QString &option = it.key();
- const QVariant &value = it.value();
-
- switch (value.type()) {
- case QVariant::Int:
- g_object_set(G_OBJECT(encoderElement), option.toLatin1(), value.toInt(), NULL);
- break;
- case QVariant::Bool:
- g_object_set(G_OBJECT(encoderElement), option.toLatin1(), value.toBool(), NULL);
- break;
- case QVariant::Double:
- g_object_set(G_OBJECT(encoderElement), option.toLatin1(), value.toDouble(), NULL);
- break;
- case QVariant::String:
- g_object_set(G_OBJECT(encoderElement), option.toLatin1(), value.toString().toUtf8().constData(), NULL);
- break;
- default:
- qWarning() << "unsupported option type:" << option << value;
- break;
- }
-
- }
- }
-
- return GST_ELEMENT(encoderBin);
-}
-
-
-QSet<QString> QGstreamerAudioEncode::supportedStreamTypes(const QString &codecName) const
-{
- return m_codecs.supportedStreamTypes(codecName);
-}
diff --git a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.h b/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.h
deleted file mode 100644
index 0cfbb4e91..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERAUDIOENCODE_H
-#define QGSTREAMERAUDIOENCODE_H
-
-#include <qaudioencodersettingscontrol.h>
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmap.h>
-#include <QtCore/qset.h>
-
-#include <gst/gst.h>
-
-#include <qaudioformat.h>
-#include <private/qgstcodecsinfo_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerCaptureSession;
-
-class QGstreamerAudioEncode : public QAudioEncoderSettingsControl
-{
- Q_OBJECT
-public:
- QGstreamerAudioEncode(QObject *parent);
- virtual ~QGstreamerAudioEncode();
-
- QStringList supportedAudioCodecs() const override;
- QString codecDescription(const QString &codecName) const override;
-
- QStringList supportedEncodingOptions(const QString &codec) const;
- QVariant encodingOption(const QString &codec, const QString &name) const;
- void setEncodingOption(const QString &codec, const QString &name, const QVariant &value);
-
- QList<int> supportedSampleRates(const QAudioEncoderSettings &settings = QAudioEncoderSettings(),
- bool *isContinuous = 0) const override;
- QList<int> supportedChannelCounts(const QAudioEncoderSettings &settings = QAudioEncoderSettings()) const;
- QList<int> supportedSampleSizes(const QAudioEncoderSettings &settings = QAudioEncoderSettings()) const;
-
- QAudioEncoderSettings audioSettings() const override;
- void setAudioSettings(const QAudioEncoderSettings &) override;
-
- GstElement *createEncoder();
-
- QSet<QString> supportedStreamTypes(const QString &codecName) const;
-
-private:
- QGstCodecsInfo m_codecs;
-
- QMap<QString, QMap<QString, QVariant> > m_options;
-
- QAudioEncoderSettings m_audioSettings;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.cpp
deleted file mode 100644
index 601a09e31..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamercameracontrol.h"
-#include "qgstreamerimageencode.h"
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qfile.h>
-
-
-QGstreamerCameraControl::QGstreamerCameraControl(QGstreamerCaptureSession *session)
- :QCameraControl(session),
- m_captureMode(QCamera::CaptureStillImage),
- m_session(session),
- m_state(QCamera::UnloadedState),
- m_status(QCamera::UnloadedStatus),
- m_reloadPending(false)
-
-{
- connect(m_session, SIGNAL(stateChanged(QGstreamerCaptureSession::State)),
- this, SLOT(updateStatus()));
-
- connect(m_session->imageEncodeControl(), SIGNAL(settingsChanged()),
- SLOT(reloadLater()));
- connect(m_session, SIGNAL(viewfinderChanged()),
- SLOT(reloadLater()));
- connect(m_session, SIGNAL(readyChanged(bool)),
- SLOT(reloadLater()));
-
- m_session->setCaptureMode(QGstreamerCaptureSession::Image);
-}
-
-QGstreamerCameraControl::~QGstreamerCameraControl()
-{
-}
-
-void QGstreamerCameraControl::setCaptureMode(QCamera::CaptureModes mode)
-{
- if (m_captureMode == mode || !isCaptureModeSupported(mode))
- return;
-
- m_captureMode = mode;
-
- switch (mode) {
- case QCamera::CaptureViewfinder:
- case QCamera::CaptureStillImage:
- m_session->setCaptureMode(QGstreamerCaptureSession::Image);
- break;
- case QCamera::CaptureVideo:
- m_session->setCaptureMode(QGstreamerCaptureSession::AudioAndVideo);
- break;
- case QCamera::CaptureVideo | QCamera::CaptureStillImage:
- m_session->setCaptureMode(QGstreamerCaptureSession::AudioAndVideoAndImage);
- break;
- }
-
- emit captureModeChanged(mode);
- updateStatus();
- reloadLater();
-}
-
-bool QGstreamerCameraControl::isCaptureModeSupported(QCamera::CaptureModes mode) const
-{
- //only CaptureStillImage and CaptureVideo bits are allowed
- return (mode & (QCamera::CaptureStillImage | QCamera::CaptureVideo)) == mode;
-}
-
-void QGstreamerCameraControl::setState(QCamera::State state)
-{
- if (m_state == state)
- return;
-
- m_state = state;
- switch (state) {
- case QCamera::UnloadedState:
- case QCamera::LoadedState:
- m_session->setState(QGstreamerCaptureSession::StoppedState);
- break;
- case QCamera::ActiveState:
- //postpone changing to Active if the session is nor ready yet
- if (m_session->isReady()) {
- m_session->setState(QGstreamerCaptureSession::PreviewState);
- } else {
-#ifdef CAMEABIN_DEBUG
- qDebug() << "Camera session is not ready yet, postpone activating";
-#endif
- }
- break;
- default:
- emit error(QCamera::NotSupportedFeatureError, tr("State not supported."));
- }
-
- updateStatus();
- emit stateChanged(m_state);
-}
-
-QCamera::State QGstreamerCameraControl::state() const
-{
- return m_state;
-}
-
-void QGstreamerCameraControl::updateStatus()
-{
- QCamera::Status oldStatus = m_status;
-
- switch (m_state) {
- case QCamera::UnloadedState:
- m_status = QCamera::UnloadedStatus;
- break;
- case QCamera::LoadedState:
- m_status = QCamera::LoadedStatus;
- break;
- case QCamera::ActiveState:
- if (m_session->state() == QGstreamerCaptureSession::StoppedState)
- m_status = QCamera::StartingStatus;
- else
- m_status = QCamera::ActiveStatus;
- break;
- }
-
- if (oldStatus != m_status) {
- //qDebug() << "Status changed:" << m_status;
- emit statusChanged(m_status);
- }
-}
-
-void QGstreamerCameraControl::reloadLater()
-{
- //qDebug() << "reload pipeline requested";
- if (!m_reloadPending && m_state == QCamera::ActiveState) {
- m_reloadPending = true;
- m_session->setState(QGstreamerCaptureSession::StoppedState);
- QMetaObject::invokeMethod(this, "reloadPipeline", Qt::QueuedConnection);
- }
-}
-
-void QGstreamerCameraControl::reloadPipeline()
-{
- //qDebug() << "reload pipeline";
- if (m_reloadPending) {
- m_reloadPending = false;
- if (m_state == QCamera::ActiveState && m_session->isReady()) {
- m_session->setState(QGstreamerCaptureSession::PreviewState);
- }
- }
-}
-
-bool QGstreamerCameraControl::canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const
-{
- Q_UNUSED(status);
-
- switch (changeType) {
- case QCameraControl::CaptureMode:
- case QCameraControl::ImageEncodingSettings:
- case QCameraControl::VideoEncodingSettings:
- case QCameraControl::Viewfinder:
- return true;
- default:
- return false;
- }
-}
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.h b/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.h
deleted file mode 100644
index 0e53f0890..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QGSTREAMERCAMERACONTROL_H
-#define QGSTREAMERCAMERACONTROL_H
-
-#include <QHash>
-#include <qcameracontrol.h>
-#include "qgstreamercapturesession.h"
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerCameraControl : public QCameraControl
-{
- Q_OBJECT
-public:
- QGstreamerCameraControl( QGstreamerCaptureSession *session );
- virtual ~QGstreamerCameraControl();
-
- bool isValid() const { return true; }
-
- QCamera::State state() const override;
- void setState(QCamera::State state) override;
-
- QCamera::Status status() const override { return m_status; }
-
- QCamera::CaptureModes captureMode() const override { return m_captureMode; }
- void setCaptureMode(QCamera::CaptureModes mode) override;
-
- bool isCaptureModeSupported(QCamera::CaptureModes mode) const override;
-
- QCamera::LockTypes supportedLocks() const
- {
- return QCamera::NoLock;
- }
-
- bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const override;
-
-public slots:
- void reloadLater();
-
-private slots:
- void updateStatus();
- void reloadPipeline();
-
-
-private:
- QCamera::CaptureModes m_captureMode;
- QGstreamerCaptureSession *m_session;
- QCamera::State m_state;
- QCamera::Status m_status;
- bool m_reloadPending;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERCAMERACONTROL_H
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp
deleted file mode 100644
index 6139c57bf..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamercapturemetadatacontrol.h"
-
-#include <QtMultimedia/qmediametadata.h>
-
-#include <gst/gst.h>
-#include <gst/gstversion.h>
-
-
-typedef QMap<QString, QByteArray> QGstreamerMetaDataKeyLookup;
-Q_GLOBAL_STATIC(QGstreamerMetaDataKeyLookup, metadataKeys)
-
-static const QGstreamerMetaDataKeyLookup *qt_gstreamerMetaDataKeys()
-{
- if (metadataKeys->isEmpty()) {
- metadataKeys->insert(QMediaMetaData::Title, GST_TAG_TITLE);
- metadataKeys->insert(QMediaMetaData::SubTitle, 0);
- //metadataKeys->insert(QMediaMetaData::Author, 0);
- metadataKeys->insert(QMediaMetaData::Comment, GST_TAG_COMMENT);
- metadataKeys->insert(QMediaMetaData::Description, GST_TAG_DESCRIPTION);
- //metadataKeys->insert(QMediaMetaData::Category, 0);
- metadataKeys->insert(QMediaMetaData::Genre, GST_TAG_GENRE);
- //metadataKeys->insert(QMediaMetaData::Year, 0);
- //metadataKeys->insert(QMediaMetaData::UserRating, 0);
-
- metadataKeys->insert(QMediaMetaData::Language, GST_TAG_LANGUAGE_CODE);
-
- metadataKeys->insert(QMediaMetaData::Publisher, GST_TAG_ORGANIZATION);
- metadataKeys->insert(QMediaMetaData::Copyright, GST_TAG_COPYRIGHT);
- //metadataKeys->insert(QMediaMetaData::ParentalRating, 0);
- //metadataKeys->insert(QMediaMetaData::RatingOrganisation, 0);
-
- // Media
- //metadataKeys->insert(QMediaMetaData::Size, 0);
- //metadataKeys->insert(QMediaMetaData::MediaType, 0);
- metadataKeys->insert(QMediaMetaData::Duration, GST_TAG_DURATION);
-
- // Audio
- metadataKeys->insert(QMediaMetaData::AudioBitRate, GST_TAG_BITRATE);
- metadataKeys->insert(QMediaMetaData::AudioCodec, GST_TAG_AUDIO_CODEC);
- //metadataKeys->insert(QMediaMetaData::ChannelCount, 0);
- //metadataKeys->insert(QMediaMetaData::SampleRate, 0);
-
- // Music
- metadataKeys->insert(QMediaMetaData::AlbumTitle, GST_TAG_ALBUM);
- metadataKeys->insert(QMediaMetaData::AlbumArtist, GST_TAG_ARTIST);
- metadataKeys->insert(QMediaMetaData::ContributingArtist, GST_TAG_PERFORMER);
- metadataKeys->insert(QMediaMetaData::Composer, GST_TAG_COMPOSER);
- //metadataKeys->insert(QMediaMetaData::Conductor, 0);
- //metadataKeys->insert(QMediaMetaData::Lyrics, 0);
- //metadataKeys->insert(QMediaMetaData::Mood, 0);
- metadataKeys->insert(QMediaMetaData::TrackNumber, GST_TAG_TRACK_NUMBER);
-
- //metadataKeys->insert(QMediaMetaData::CoverArtUrlSmall, 0);
- //metadataKeys->insert(QMediaMetaData::CoverArtUrlLarge, 0);
-
- // Image/Video
- //metadataKeys->insert(QMediaMetaData::Resolution, 0);
- //metadataKeys->insert(QMediaMetaData::PixelAspectRatio, 0);
-
- // Video
- //metadataKeys->insert(QMediaMetaData::VideoFrameRate, 0);
- //metadataKeys->insert(QMediaMetaData::VideoBitRate, 0);
- metadataKeys->insert(QMediaMetaData::VideoCodec, GST_TAG_VIDEO_CODEC);
-
- //metadataKeys->insert(QMediaMetaData::PosterUrl, 0);
-
- // Movie
- //metadataKeys->insert(QMediaMetaData::ChapterNumber, 0);
- //metadataKeys->insert(QMediaMetaData::Director, 0);
- metadataKeys->insert(QMediaMetaData::LeadPerformer, GST_TAG_PERFORMER);
- //metadataKeys->insert(QMediaMetaData::Writer, 0);
-
- // Photos
- //metadataKeys->insert(QMediaMetaData::CameraManufacturer, 0);
- //metadataKeys->insert(QMediaMetaData::CameraModel, 0);
- //metadataKeys->insert(QMediaMetaData::Event, 0);
- //metadataKeys->insert(QMediaMetaData::Subject, 0 }
- }
-
- return metadataKeys;
-}
-
-QGstreamerCaptureMetaDataControl::QGstreamerCaptureMetaDataControl(QObject *parent)
- :QMetaDataWriterControl(parent)
-{
-}
-
-QVariant QGstreamerCaptureMetaDataControl::metaData(const QString &key) const
-{
- QGstreamerMetaDataKeyLookup::const_iterator it = qt_gstreamerMetaDataKeys()->find(key);
- if (it != qt_gstreamerMetaDataKeys()->constEnd())
- return m_values.value(it.value());
-
- return QVariant();
-}
-
-void QGstreamerCaptureMetaDataControl::setMetaData(const QString &key, const QVariant &value)
-{
- QGstreamerMetaDataKeyLookup::const_iterator it = qt_gstreamerMetaDataKeys()->find(key);
- if (it != qt_gstreamerMetaDataKeys()->constEnd()) {
- m_values.insert(it.value(), value);
-
- emit QMetaDataWriterControl::metaDataChanged();
- emit QMetaDataWriterControl::metaDataChanged(key, value);
- emit metaDataChanged(m_values);
- }
-}
-
-QStringList QGstreamerCaptureMetaDataControl::availableMetaData() const
-{
- QStringList res;
- for (auto it = m_values.keyBegin(), end = m_values.keyEnd(); it != end; ++it) {
- QString tag = qt_gstreamerMetaDataKeys()->key(*it);
- if (!tag.isEmpty())
- res.append(tag);
- }
-
- return res;
-}
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.h b/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.h
deleted file mode 100644
index 6839bbe68..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERCAPTUREMETADATACONTROL_H
-#define QGSTREAMERCAPTUREMETADATACONTROL_H
-
-#include <qmetadatawritercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerCaptureMetaDataControl : public QMetaDataWriterControl
-{
- Q_OBJECT
-public:
- QGstreamerCaptureMetaDataControl(QObject *parent);
- ~QGstreamerCaptureMetaDataControl() {}
-
-
- bool isMetaDataAvailable() const override { return true; }
- bool isWritable() const override { return true; }
-
- QVariant metaData(const QString &key) const override;
- void setMetaData(const QString &key, const QVariant &value) override;
- QStringList availableMetaData() const override;
-
-Q_SIGNALS:
- void metaDataChanged(const QMap<QByteArray, QVariant>&);
-
-private:
- QMap<QByteArray, QVariant> m_values;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERCAPTUREMETADATACONTROL_H
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.cpp
deleted file mode 100644
index dc99cbe0e..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.cpp
+++ /dev/null
@@ -1,227 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamercaptureservice.h"
-#include "qgstreamercapturesession.h"
-#include "qgstreamerrecordercontrol.h"
-#include "qgstreamermediacontainercontrol.h"
-#include "qgstreameraudioencode.h"
-#include "qgstreamervideoencode.h"
-#include "qgstreamerimageencode.h"
-#include "qgstreamercameracontrol.h"
-#include <private/qgstreamerbushelper_p.h>
-#include "qgstreamercapturemetadatacontrol.h"
-
-#if defined(USE_GSTREAMER_CAMERA)
-#include "qgstreamerv4l2input.h"
-#endif
-
-#include "qgstreamerimagecapturecontrol.h"
-#include <private/qgstreameraudioinputselector_p.h>
-#include <private/qgstreamervideoinputdevicecontrol_p.h>
-#include <private/qgstreameraudioprobecontrol_p.h>
-
-#include <private/qgstreamervideorenderer_p.h>
-#include <private/qgstreamervideowindow_p.h>
-
-#if defined(HAVE_WIDGETS)
-#include <private/qgstreamervideowidget_p.h>
-#endif
-
-#include <qmediaserviceproviderplugin.h>
-
-QT_BEGIN_NAMESPACE
-
-QGstreamerCaptureService::QGstreamerCaptureService(const QString &service, QObject *parent)
- : QMediaService(parent)
- , m_captureSession(0)
- , m_cameraControl(0)
-#if defined(USE_GSTREAMER_CAMERA)
- , m_videoInput(0)
-#endif
- , m_metaDataControl(0)
- , m_audioInputSelector(0)
- , m_videoInputDevice(0)
- , m_videoOutput(0)
- , m_videoRenderer(0)
- , m_videoWindow(0)
-#if defined(HAVE_WIDGETS)
- , m_videoWidgetControl(0)
-#endif
- , m_imageCaptureControl(0)
- , m_audioProbeControl(0)
-{
- if (service == Q_MEDIASERVICE_AUDIOSOURCE) {
- m_captureSession = new QGstreamerCaptureSession(QGstreamerCaptureSession::Audio, this);
- }
-
-#if defined(USE_GSTREAMER_CAMERA)
- if (service == Q_MEDIASERVICE_CAMERA) {
- m_captureSession = new QGstreamerCaptureSession(QGstreamerCaptureSession::AudioAndVideo, this);
- m_cameraControl = new QGstreamerCameraControl(m_captureSession);
- m_videoInput = new QGstreamerV4L2Input(this);
- m_captureSession->setVideoInput(m_videoInput);
- m_videoInputDevice = new QGstreamerVideoInputDeviceControl(this);
-
- connect(m_videoInputDevice, SIGNAL(selectedDeviceChanged(QString)),
- m_videoInput, SLOT(setDevice(QString)));
-
- if (m_videoInputDevice->deviceCount())
- m_videoInput->setDevice(m_videoInputDevice->deviceName(m_videoInputDevice->selectedDevice()));
-
- m_videoRenderer = new QGstreamerVideoRenderer(this);
-
- m_videoWindow = new QGstreamerVideoWindow(this);
- // If the GStreamer video sink is not available, don't provide the video window control since
- // it won't work anyway.
- if (!m_videoWindow->videoSink()) {
- delete m_videoWindow;
- m_videoWindow = 0;
- }
-
-#if defined(HAVE_WIDGETS)
- m_videoWidgetControl = new QGstreamerVideoWidgetControl(this);
-
- // If the GStreamer video sink is not available, don't provide the video widget control since
- // it won't work anyway. QVideoWidget will fall back to QVideoRendererControl in that case.
- if (!m_videoWidgetControl->videoSink()) {
- delete m_videoWidgetControl;
- m_videoWidgetControl = 0;
- }
-#endif
- m_imageCaptureControl = new QGstreamerImageCaptureControl(m_captureSession);
- }
-#endif
-
- m_audioInputSelector = new QGstreamerAudioInputSelector(this);
- connect(m_audioInputSelector, SIGNAL(activeInputChanged(QString)), m_captureSession, SLOT(setCaptureDevice(QString)));
-
- if (m_captureSession && m_audioInputSelector->availableInputs().size() > 0)
- m_captureSession->setCaptureDevice(m_audioInputSelector->defaultInput());
-
- m_metaDataControl = new QGstreamerCaptureMetaDataControl(this);
- connect(m_metaDataControl, SIGNAL(metaDataChanged(QMap<QByteArray,QVariant>)),
- m_captureSession, SLOT(setMetaData(QMap<QByteArray,QVariant>)));
-}
-
-QGstreamerCaptureService::~QGstreamerCaptureService()
-{
-}
-
-QMediaControl *QGstreamerCaptureService::requestControl(const char *name)
-{
- if (!m_captureSession)
- return 0;
-
- if (qstrcmp(name,QAudioInputSelectorControl_iid) == 0)
- return m_audioInputSelector;
-
- if (qstrcmp(name,QVideoDeviceSelectorControl_iid) == 0)
- return m_videoInputDevice;
-
- if (qstrcmp(name,QMediaRecorderControl_iid) == 0)
- return m_captureSession->recorderControl();
-
- if (qstrcmp(name,QAudioEncoderSettingsControl_iid) == 0)
- return m_captureSession->audioEncodeControl();
-
- if (qstrcmp(name,QVideoEncoderSettingsControl_iid) == 0)
- return m_captureSession->videoEncodeControl();
-
- if (qstrcmp(name,QImageEncoderControl_iid) == 0)
- return m_captureSession->imageEncodeControl();
-
-
- if (qstrcmp(name,QMediaContainerControl_iid) == 0)
- return m_captureSession->mediaContainerControl();
-
- if (qstrcmp(name,QCameraControl_iid) == 0)
- return m_cameraControl;
-
- if (qstrcmp(name,QMetaDataWriterControl_iid) == 0)
- return m_metaDataControl;
-
- if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0)
- return m_imageCaptureControl;
-
- if (qstrcmp(name,QMediaAudioProbeControl_iid) == 0) {
- if (!m_audioProbeControl) {
- m_audioProbeControl = new QGstreamerAudioProbeControl(this);
- m_captureSession->addProbe(m_audioProbeControl);
- }
- m_audioProbeControl->ref.ref();
- return m_audioProbeControl;
- }
-
- if (!m_videoOutput) {
- if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
- m_videoOutput = m_videoRenderer;
- } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
- m_videoOutput = m_videoWindow;
- }
-#if defined(HAVE_WIDGETS)
- else if (qstrcmp(name, QVideoWidgetControl_iid) == 0) {
- m_videoOutput = m_videoWidgetControl;
- }
-#endif
-
- if (m_videoOutput) {
- m_captureSession->setVideoPreview(m_videoOutput);
- return m_videoOutput;
- }
- }
-
- return 0;
-}
-
-void QGstreamerCaptureService::releaseControl(QMediaControl *control)
-{
- if (!control) {
- return;
- } else if (control == m_videoOutput) {
- m_videoOutput = 0;
- m_captureSession->setVideoPreview(0);
- } else if (control == m_audioProbeControl && !m_audioProbeControl->ref.deref()) {
- m_captureSession->removeProbe(m_audioProbeControl);
- delete m_audioProbeControl;
- m_audioProbeControl = 0;
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.h b/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.h
deleted file mode 100644
index aba98d495..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERCAPTURESERVICE_H
-#define QGSTREAMERCAPTURESERVICE_H
-
-#include <qmediaservice.h>
-#include <qmediacontrol.h>
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-class QAudioInputSelectorControl;
-class QVideoDeviceSelectorControl;
-
-class QGstreamerAudioProbeControl;
-class QGstreamerCaptureSession;
-class QGstreamerCameraControl;
-class QGstreamerMessage;
-class QGstreamerBusHelper;
-class QGstreamerVideoRenderer;
-class QGstreamerVideoWindow;
-class QGstreamerVideoWidgetControl;
-class QGstreamerElementFactory;
-class QGstreamerCaptureMetaDataControl;
-class QGstreamerImageCaptureControl;
-class QGstreamerV4L2Input;
-
-class QGstreamerCaptureService : public QMediaService
-{
- Q_OBJECT
-
-public:
- QGstreamerCaptureService(const QString &service, QObject *parent = 0);
- virtual ~QGstreamerCaptureService();
-
- QMediaControl *requestControl(const char *name) override;
- void releaseControl(QMediaControl *) override;
-
-private:
- void setAudioPreview(GstElement *);
-
- QGstreamerCaptureSession *m_captureSession;
- QGstreamerCameraControl *m_cameraControl;
-#if defined(USE_GSTREAMER_CAMERA)
- QGstreamerV4L2Input *m_videoInput;
-#endif
- QGstreamerCaptureMetaDataControl *m_metaDataControl;
-
- QAudioInputSelectorControl *m_audioInputSelector;
- QVideoDeviceSelectorControl *m_videoInputDevice;
-
- QMediaControl *m_videoOutput;
-
- QGstreamerVideoRenderer *m_videoRenderer;
- QGstreamerVideoWindow *m_videoWindow;
-#if defined(HAVE_WIDGETS)
- QGstreamerVideoWidgetControl *m_videoWidgetControl;
-#endif
- QGstreamerImageCaptureControl *m_imageCaptureControl;
-
- QGstreamerAudioProbeControl *m_audioProbeControl;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERCAPTURESERVICE_H
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.cpp
deleted file mode 100644
index 2a2dec60a..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qstring.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/QDir>
-#include <QtCore/QDebug>
-
-#include "qgstreamercaptureserviceplugin.h"
-
-//#define QT_SUPPORTEDMIMETYPES_DEBUG
-
-#include "qgstreamercaptureservice.h"
-#include <private/qgstutils_p.h>
-
-QMediaService* QGstreamerCaptureServicePlugin::create(const QString &key)
-{
- QGstUtils::initializeGst();
-
- if (key == QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE))
- return new QGstreamerCaptureService(key);
-
-#if defined(USE_GSTREAMER_CAMERA)
- if (key == QLatin1String(Q_MEDIASERVICE_CAMERA))
- return new QGstreamerCaptureService(key);
-#endif
-
- qWarning() << "Gstreamer capture service plugin: unsupported key:" << key;
- return 0;
-}
-
-void QGstreamerCaptureServicePlugin::release(QMediaService *service)
-{
- delete service;
-}
-
-#if defined(USE_GSTREAMER_CAMERA)
-QMediaServiceProviderHint::Features QGstreamerCaptureServicePlugin::supportedFeatures(
- const QByteArray &service) const
-{
- if (service == Q_MEDIASERVICE_CAMERA)
- return QMediaServiceProviderHint::VideoSurface;
-
- return QMediaServiceProviderHint::Features();
-}
-
-QByteArray QGstreamerCaptureServicePlugin::defaultDevice(const QByteArray &service) const
-{
- return service == Q_MEDIASERVICE_CAMERA
- ? QGstUtils::enumerateCameras().value(0).name.toUtf8()
- : QByteArray();
-}
-
-QList<QByteArray> QGstreamerCaptureServicePlugin::devices(const QByteArray &service) const
-{
- return service == Q_MEDIASERVICE_CAMERA ? QGstUtils::cameraDevices() : QList<QByteArray>();
-}
-
-QString QGstreamerCaptureServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
-{
- return service == Q_MEDIASERVICE_CAMERA ? QGstUtils::cameraDescription(device) : QString();
-}
-
-QVariant QGstreamerCaptureServicePlugin::deviceProperty(const QByteArray &service, const QByteArray &device, const QByteArray &property)
-{
- Q_UNUSED(service);
- Q_UNUSED(device);
- Q_UNUSED(property);
- return QVariant();
-}
-
-#endif
-
-QMultimedia::SupportEstimate QGstreamerCaptureServicePlugin::hasSupport(const QString &mimeType,
- const QStringList& codecs) const
-{
- if (m_supportedMimeTypeSet.isEmpty())
- updateSupportedMimeTypes();
-
- return QGstUtils::hasSupport(mimeType, codecs, m_supportedMimeTypeSet);
-}
-
-
-static bool isEncoderOrMuxer(GstElementFactory *factory)
-{
-#if GST_CHECK_VERSION(0, 10, 31)
- return gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_MUXER)
- || gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_ENCODER);
-#else
- return (factory
- && (qstrcmp(factory->details.klass, "Codec/Encoder/Audio") == 0
- || qstrcmp(factory->details.klass, "Codec/Encoder/Video") == 0
- || qstrcmp(factory->details.klass, "Codec/Muxer") == 0 ));
-#endif
-}
-
-void QGstreamerCaptureServicePlugin::updateSupportedMimeTypes() const
-{
- m_supportedMimeTypeSet = QGstUtils::supportedMimeTypes(isEncoderOrMuxer);
-}
-
-QStringList QGstreamerCaptureServicePlugin::supportedMimeTypes() const
-{
- return QStringList();
-}
-
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.h b/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.h
deleted file mode 100644
index d8b7e9768..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QGSTREAMERCAPTURESERVICEPLUGIN_H
-#define QGSTREAMERCAPTURESERVICEPLUGIN_H
-
-#include <qmediaserviceproviderplugin.h>
-#include <QtCore/qset.h>
-#include <QtCore/QObject>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerCaptureServicePlugin
- : public QMediaServiceProviderPlugin
-#if defined(USE_GSTREAMER_CAMERA)
- , public QMediaServiceSupportedDevicesInterface
- , public QMediaServiceDefaultDeviceInterface
- , public QMediaServiceFeaturesInterface
-#endif
- , public QMediaServiceSupportedFormatsInterface
-{
- Q_OBJECT
-#if defined(USE_GSTREAMER_CAMERA)
- Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
- Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
- Q_INTERFACES(QMediaServiceFeaturesInterface)
-#endif
- Q_INTERFACES(QMediaServiceSupportedFormatsInterface)
-#if defined(USE_GSTREAMER_CAMERA)
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "mediacapturecamera.json")
-#else
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "mediacapture.json")
-#endif
-public:
- QMediaService* create(const QString &key) override;
- void release(QMediaService *service) override;
-
-#if defined(USE_GSTREAMER_CAMERA)
- QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const override;
-
- QByteArray defaultDevice(const QByteArray &service) const override;
- QList<QByteArray> devices(const QByteArray &service) const override;
- QString deviceDescription(const QByteArray &service, const QByteArray &device) override;
- QVariant deviceProperty(const QByteArray &service, const QByteArray &device, const QByteArray &property);
-#endif
-
- QMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList &codecs) const override;
- QStringList supportedMimeTypes() const override;
-
-private:
- void updateSupportedMimeTypes() const;
-
- mutable QSet<QString> m_supportedMimeTypeSet; //for fast access
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERCAPTURESERVICEPLUGIN_H
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp
deleted file mode 100644
index 4363f6d3b..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp
+++ /dev/null
@@ -1,1032 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamercapturesession.h"
-#include "qgstreamerrecordercontrol.h"
-#include "qgstreamermediacontainercontrol.h"
-#include "qgstreameraudioencode.h"
-#include "qgstreamervideoencode.h"
-#include "qgstreamerimageencode.h"
-#include <qmediarecorder.h>
-#include <private/qgstreamervideorendererinterface_p.h>
-#include <private/qgstreameraudioprobecontrol_p.h>
-#include <private/qgstreamerbushelper_p.h>
-#include <private/qgstutils_p.h>
-
-#include <gst/gsttagsetter.h>
-#include <gst/gstversion.h>
-#include <gst/video/video.h>
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qset.h>
-#include <QCoreApplication>
-#include <QtCore/qmetaobject.h>
-#include <QtCore/qfile.h>
-#include <QtGui/qimage.h>
-
-QT_BEGIN_NAMESPACE
-
-QGstreamerCaptureSession::QGstreamerCaptureSession(QGstreamerCaptureSession::CaptureMode captureMode, QObject *parent)
- :QObject(parent),
- m_state(StoppedState),
- m_pendingState(StoppedState),
- m_waitingForEos(false),
- m_pipelineMode(EmptyPipeline),
- m_captureMode(captureMode),
- m_audioProbe(0),
- m_audioInputFactory(0),
- m_audioPreviewFactory(0),
- m_videoInputFactory(0),
- m_viewfinder(0),
- m_viewfinderInterface(0),
- m_audioSrc(0),
- m_audioTee(0),
- m_audioPreviewQueue(0),
- m_audioPreview(0),
- m_audioVolume(0),
- m_muted(false),
- m_volume(1.0),
- m_videoSrc(0),
- m_videoTee(0),
- m_videoPreviewQueue(0),
- m_videoPreview(0),
- m_imageCaptureBin(0),
- m_encodeBin(0),
- m_passImage(false),
- m_passPrerollImage(false)
-{
- m_pipeline = gst_pipeline_new("media-capture-pipeline");
- qt_gst_object_ref_sink(m_pipeline);
-
- m_bus = gst_element_get_bus(m_pipeline);
- m_busHelper = new QGstreamerBusHelper(m_bus, this);
- m_busHelper->installMessageFilter(this);
-
- m_audioEncodeControl = new QGstreamerAudioEncode(this);
- m_videoEncodeControl = new QGstreamerVideoEncode(this);
- m_imageEncodeControl = new QGstreamerImageEncode(this);
- m_recorderControl = new QGstreamerRecorderControl(this);
- connect(m_recorderControl, &QGstreamerRecorderControl::error, [](int e, const QString &str) {
- qWarning() << QMediaRecorder::Error(e) << ":" << str.toLatin1().constData();
- });
- m_mediaContainerControl = new QGstreamerMediaContainerControl(this);
-}
-
-QGstreamerCaptureSession::~QGstreamerCaptureSession()
-{
- setState(StoppedState);
- gst_element_set_state(m_pipeline, GST_STATE_NULL);
- gst_object_unref(GST_OBJECT(m_bus));
- gst_object_unref(GST_OBJECT(m_pipeline));
-}
-
-void QGstreamerCaptureSession::setCaptureMode(CaptureMode mode)
-{
- m_captureMode = mode;
-}
-
-GstElement *QGstreamerCaptureSession::buildEncodeBin()
-{
- GstElement *encodeBin = gst_bin_new("encode-bin");
-
- GstElement *muxer = gst_element_factory_make( m_mediaContainerControl->formatElementName().constData(), "muxer");
- if (!muxer) {
- qWarning() << "Could not create a media muxer element:" << m_mediaContainerControl->formatElementName();
- gst_object_unref(encodeBin);
- return 0;
- }
-
- // Output location was rejected in setOutputlocation() if not a local file
- QUrl actualSink = QUrl::fromLocalFile(QDir::currentPath()).resolved(m_sink);
- GstElement *fileSink = gst_element_factory_make("filesink", "filesink");
- g_object_set(G_OBJECT(fileSink), "location", QFile::encodeName(actualSink.toLocalFile()).constData(), NULL);
- gst_bin_add_many(GST_BIN(encodeBin), muxer, fileSink, NULL);
-
- if (!gst_element_link(muxer, fileSink)) {
- gst_object_unref(encodeBin);
- return 0;
- }
-
- if (m_captureMode & Audio) {
- GstElement *audioConvert = gst_element_factory_make("audioconvert", "audioconvert");
- GstElement *audioQueue = gst_element_factory_make("queue", "audio-encode-queue");
- m_audioVolume = gst_element_factory_make("volume", "volume");
- gst_bin_add_many(GST_BIN(encodeBin), audioConvert, audioQueue, m_audioVolume, NULL);
-
- GstElement *audioEncoder = m_audioEncodeControl->createEncoder();
- if (!audioEncoder) {
- gst_object_unref(encodeBin);
- qWarning() << "Could not create an audio encoder element:" << m_audioEncodeControl->audioSettings().codec();
- return 0;
- }
-
- gst_bin_add(GST_BIN(encodeBin), audioEncoder);
-
- if (!gst_element_link_many(audioConvert, audioQueue, m_audioVolume, audioEncoder, muxer, NULL)) {
- m_audioVolume = 0;
- gst_object_unref(encodeBin);
- return 0;
- }
-
- g_object_set(G_OBJECT(m_audioVolume), "mute", m_muted, NULL);
- g_object_set(G_OBJECT(m_audioVolume), "volume", m_volume, NULL);
-
- // add ghostpads
- GstPad *pad = gst_element_get_static_pad(audioConvert, "sink");
- gst_element_add_pad(GST_ELEMENT(encodeBin), gst_ghost_pad_new("audiosink", pad));
- gst_object_unref(GST_OBJECT(pad));
- }
-
- if (m_captureMode & Video) {
- GstElement *videoQueue = gst_element_factory_make("queue", "video-encode-queue");
- GstElement *colorspace = gst_element_factory_make(QT_GSTREAMER_COLORCONVERSION_ELEMENT_NAME, "videoconvert-encoder");
- GstElement *videoscale = gst_element_factory_make("videoscale","videoscale-encoder");
- gst_bin_add_many(GST_BIN(encodeBin), videoQueue, colorspace, videoscale, NULL);
-
- GstElement *videoEncoder = m_videoEncodeControl->createEncoder();
- if (!videoEncoder) {
- gst_object_unref(encodeBin);
- qWarning() << "Could not create a video encoder element:" << m_videoEncodeControl->videoSettings().codec();
- return 0;
- }
-
- gst_bin_add(GST_BIN(encodeBin), videoEncoder);
-
- if (!gst_element_link_many(videoQueue, colorspace, videoscale, videoEncoder, muxer, NULL)) {
- gst_object_unref(encodeBin);
- return 0;
- }
-
- // add ghostpads
- GstPad *pad = gst_element_get_static_pad(videoQueue, "sink");
- gst_element_add_pad(GST_ELEMENT(encodeBin), gst_ghost_pad_new("videosink", pad));
- gst_object_unref(GST_OBJECT(pad));
- }
-
- return encodeBin;
-}
-
-GstElement *QGstreamerCaptureSession::buildAudioSrc()
-{
- GstElement *audioSrc = 0;
- if (m_audioInputFactory)
- audioSrc = m_audioInputFactory->buildElement();
- else {
- QString elementName = "alsasrc";
- QString device;
-
- if (m_captureDevice.startsWith("alsa:")) {
- device = m_captureDevice.mid(QString("alsa:").length());
- } else if (m_captureDevice.startsWith("oss:")) {
- elementName = "osssrc";
- device = m_captureDevice.mid(QString("oss:").length());
- } else if (m_captureDevice.startsWith("pulseaudio:")) {
- elementName = "pulsesrc";
- } else {
- elementName = "autoaudiosrc";
- }
-
- audioSrc = gst_element_factory_make(elementName.toLatin1().constData(), "audio_src");
- if (audioSrc && !device.isEmpty())
- g_object_set(G_OBJECT(audioSrc), "device", device.toLocal8Bit().constData(), NULL);
- }
-
- if (!audioSrc) {
- emit error(int(QMediaRecorder::ResourceError), tr("Could not create an audio source element"));
- audioSrc = gst_element_factory_make("fakesrc", NULL);
- }
-
- return audioSrc;
-}
-
-GstElement *QGstreamerCaptureSession::buildAudioPreview()
-{
- GstElement *previewElement = 0;
-
- if (m_audioPreviewFactory) {
- previewElement = m_audioPreviewFactory->buildElement();
- } else {
-
-
-#if 1
- previewElement = gst_element_factory_make("fakesink", "audio-preview");
-#else
- GstElement *bin = gst_bin_new("audio-preview-bin");
- GstElement *visual = gst_element_factory_make("libvisual_lv_scope", "audio-preview");
- GstElement *sink = gst_element_factory_make("ximagesink", NULL);
- gst_bin_add_many(GST_BIN(bin), visual, sink, NULL);
- gst_element_link_many(visual,sink, NULL);
-
-
- // add ghostpads
- GstPad *pad = gst_element_get_static_pad(visual, "sink");
- Q_ASSERT(pad);
- gst_element_add_pad(GST_ELEMENT(bin), gst_ghost_pad_new("audiosink", pad));
- gst_object_unref(GST_OBJECT(pad));
-
- previewElement = bin;
-#endif
- }
-
- return previewElement;
-}
-
-GstElement *QGstreamerCaptureSession::buildVideoSrc()
-{
- GstElement *videoSrc = 0;
- if (m_videoInputFactory) {
- videoSrc = m_videoInputFactory->buildElement();
- } else {
- videoSrc = gst_element_factory_make("videotestsrc", "video_test_src");
- //videoSrc = gst_element_factory_make("v4l2src", "video_test_src");
- }
-
- return videoSrc;
-}
-
-GstElement *QGstreamerCaptureSession::buildVideoPreview()
-{
- GstElement *previewElement = 0;
-
- if (m_viewfinderInterface) {
- GstElement *bin = gst_bin_new("video-preview-bin");
- GstElement *colorspace = gst_element_factory_make(QT_GSTREAMER_COLORCONVERSION_ELEMENT_NAME, "videoconvert-preview");
- GstElement *capsFilter = gst_element_factory_make("capsfilter", "capsfilter-video-preview");
- GstElement *preview = m_viewfinderInterface->videoSink();
-
- gst_bin_add_many(GST_BIN(bin), colorspace, capsFilter, preview, NULL);
- gst_element_link(colorspace,capsFilter);
- gst_element_link(capsFilter,preview);
-
- QSize resolution;
- qreal frameRate = 0;
-
- if (m_captureMode & Video) {
- QVideoEncoderSettings videoSettings = m_videoEncodeControl->videoSettings();
- resolution = videoSettings.resolution();
- frameRate = videoSettings.frameRate();
- } else if (m_captureMode & Image) {
- resolution = m_imageEncodeControl->imageSettings().resolution();
- }
-
- GstCaps *caps = QGstUtils::videoFilterCaps();
-
- if (!resolution.isEmpty()) {
- gst_caps_set_simple(caps, "width", G_TYPE_INT, resolution.width(), NULL);
- gst_caps_set_simple(caps, "height", G_TYPE_INT, resolution.height(), NULL);
- }
- if (frameRate > 0.001) {
- QPair<int,int> rate = m_videoEncodeControl->rateAsRational();
-
- //qDebug() << "frame rate:" << num << denum;
-
- gst_caps_set_simple(caps, "framerate", GST_TYPE_FRACTION, rate.first, rate.second, NULL);
- }
-
- //qDebug() << "set video preview caps filter:" << gst_caps_to_string(caps);
-
- g_object_set(G_OBJECT(capsFilter), "caps", caps, NULL);
-
- gst_caps_unref(caps);
-
- // add ghostpads
- GstPad *pad = gst_element_get_static_pad(colorspace, "sink");
- Q_ASSERT(pad);
- gst_element_add_pad(GST_ELEMENT(bin), gst_ghost_pad_new("videosink", pad));
- gst_object_unref(GST_OBJECT(pad));
-
- previewElement = bin;
- } else {
-#if 1
- previewElement = gst_element_factory_make("fakesink", "video-preview");
-#else
- GstElement *bin = gst_bin_new("video-preview-bin");
- GstElement *colorspace = gst_element_factory_make(QT_GSTREAMER_COLORCONVERSION_ELEMENT_NAME, "videoconvert-preview");
- GstElement *preview = gst_element_factory_make("ximagesink", "video-preview");
- gst_bin_add_many(GST_BIN(bin), colorspace, preview, NULL);
- gst_element_link(colorspace,preview);
-
- // add ghostpads
- GstPad *pad = gst_element_get_static_pad(colorspace, "sink");
- Q_ASSERT(pad);
- gst_element_add_pad(GST_ELEMENT(bin), gst_ghost_pad_new("videosink", pad));
- gst_object_unref(GST_OBJECT(pad));
-
- previewElement = bin;
-#endif
- }
-
- return previewElement;
-}
-
-void QGstreamerCaptureSession::probeCaps(GstCaps *caps)
-{
-#if GST_CHECK_VERSION(1,0,0)
- gst_video_info_from_caps(&m_previewInfo, caps);
-#else
- Q_UNUSED(caps);
-#endif
-}
-
-bool QGstreamerCaptureSession::probeBuffer(GstBuffer *buffer)
-{
- if (m_passPrerollImage) {
- m_passImage = false;
- m_passPrerollImage = false;
-
- return true;
- } else if (!m_passImage) {
- return false;
- }
-
- m_passImage = false;
-
-#if GST_CHECK_VERSION(1,0,0)
- QImage img = QGstUtils::bufferToImage(buffer, m_previewInfo);
-#else
- QImage img = QGstUtils::bufferToImage(buffer);
-#endif
-
- if (img.isNull())
- return true;
-
- static QMetaMethod exposedSignal = QMetaMethod::fromSignal(&QGstreamerCaptureSession::imageExposed);
- exposedSignal.invoke(this,
- Qt::QueuedConnection,
- Q_ARG(int,m_imageRequestId));
-
- static QMetaMethod capturedSignal = QMetaMethod::fromSignal(&QGstreamerCaptureSession::imageCaptured);
- capturedSignal.invoke(this,
- Qt::QueuedConnection,
- Q_ARG(int,m_imageRequestId),
- Q_ARG(QImage,img));
-
- return true;
-}
-
-static gboolean saveImageFilter(GstElement *element,
- GstBuffer *buffer,
- GstPad *pad,
- void *appdata)
-{
- Q_UNUSED(element);
- Q_UNUSED(pad);
- QGstreamerCaptureSession *session = (QGstreamerCaptureSession *)appdata;
-
- QString fileName = session->m_imageFileName;
-
- if (!fileName.isEmpty()) {
- QFile f(fileName);
- if (f.open(QFile::WriteOnly)) {
-#if GST_CHECK_VERSION(1,0,0)
- GstMapInfo info;
- if (gst_buffer_map(buffer, &info, GST_MAP_READ)) {
- f.write(reinterpret_cast<const char *>(info.data), info.size);
- gst_buffer_unmap(buffer, &info);
- }
-#else
- f.write(reinterpret_cast<const char *>(buffer->data), buffer->size);
-#endif
- f.close();
-
- static QMetaMethod savedSignal = QMetaMethod::fromSignal(&QGstreamerCaptureSession::imageSaved);
- savedSignal.invoke(session,
- Qt::QueuedConnection,
- Q_ARG(int,session->m_imageRequestId),
- Q_ARG(QString,fileName));
- }
- }
-
- return TRUE;
-}
-
-GstElement *QGstreamerCaptureSession::buildImageCapture()
-{
- GstElement *bin = gst_bin_new("image-capture-bin");
- GstElement *queue = gst_element_factory_make("queue", "queue-image-capture");
- GstElement *colorspace = gst_element_factory_make(QT_GSTREAMER_COLORCONVERSION_ELEMENT_NAME, "videoconvert-image-capture");
- GstElement *encoder = gst_element_factory_make("jpegenc", "image-encoder");
- GstElement *sink = gst_element_factory_make("fakesink","sink-image-capture");
-
- GstPad *pad = gst_element_get_static_pad(queue, "src");
- Q_ASSERT(pad);
-
- addProbeToPad(pad, false);
-
- gst_object_unref(GST_OBJECT(pad));
-
- g_object_set(G_OBJECT(sink), "signal-handoffs", TRUE, NULL);
- g_signal_connect(G_OBJECT(sink), "handoff", G_CALLBACK(saveImageFilter), this);
-
- gst_bin_add_many(GST_BIN(bin), queue, colorspace, encoder, sink, NULL);
- gst_element_link_many(queue, colorspace, encoder, sink, NULL);
-
- // add ghostpads
- pad = gst_element_get_static_pad(queue, "sink");
- Q_ASSERT(pad);
- gst_element_add_pad(GST_ELEMENT(bin), gst_ghost_pad_new("imagesink", pad));
- gst_object_unref(GST_OBJECT(pad));
-
- m_passImage = false;
- m_passPrerollImage = true;
- m_imageFileName = QString();
-
- return bin;
-}
-
-void QGstreamerCaptureSession::captureImage(int requestId, const QString &fileName)
-{
- m_imageRequestId = requestId;
- m_imageFileName = fileName;
- m_passImage = true;
-}
-
-
-#define REMOVE_ELEMENT(element) { if (element) {gst_bin_remove(GST_BIN(m_pipeline), element); element = 0;} }
-#define UNREF_ELEMENT(element) { if (element) { gst_object_unref(GST_OBJECT(element)); element = 0; } }
-
-bool QGstreamerCaptureSession::rebuildGraph(QGstreamerCaptureSession::PipelineMode newMode)
-{
- removeAudioBufferProbe();
- REMOVE_ELEMENT(m_audioSrc);
- REMOVE_ELEMENT(m_audioPreview);
- REMOVE_ELEMENT(m_audioPreviewQueue);
- REMOVE_ELEMENT(m_audioTee);
- REMOVE_ELEMENT(m_videoSrc);
- REMOVE_ELEMENT(m_videoPreview);
- REMOVE_ELEMENT(m_videoPreviewQueue);
- REMOVE_ELEMENT(m_videoTee);
- REMOVE_ELEMENT(m_encodeBin);
- REMOVE_ELEMENT(m_imageCaptureBin);
- m_audioVolume = 0;
-
- bool ok = true;
-
- switch (newMode) {
- case EmptyPipeline:
- break;
- case PreviewPipeline:
- if (m_captureMode & Audio) {
- m_audioSrc = buildAudioSrc();
- m_audioPreview = buildAudioPreview();
-
- ok &= m_audioSrc && m_audioPreview;
-
- if (ok) {
- gst_bin_add_many(GST_BIN(m_pipeline), m_audioSrc, m_audioPreview, NULL);
- ok &= gst_element_link(m_audioSrc, m_audioPreview);
- } else {
- UNREF_ELEMENT(m_audioSrc);
- UNREF_ELEMENT(m_audioPreview);
- }
- }
- if (m_captureMode & Video || m_captureMode & Image) {
- m_videoSrc = buildVideoSrc();
- m_videoTee = gst_element_factory_make("tee", "video-preview-tee");
- m_videoPreviewQueue = gst_element_factory_make("queue", "video-preview-queue");
- m_videoPreview = buildVideoPreview();
- m_imageCaptureBin = buildImageCapture();
-
- ok &= m_videoSrc && m_videoTee && m_videoPreviewQueue && m_videoPreview && m_imageCaptureBin;
-
- if (ok) {
- gst_bin_add_many(GST_BIN(m_pipeline), m_videoSrc, m_videoTee,
- m_videoPreviewQueue, m_videoPreview,
- m_imageCaptureBin, NULL);
-
- ok &= gst_element_link(m_videoSrc, m_videoTee);
- ok &= gst_element_link(m_videoTee, m_videoPreviewQueue);
- ok &= gst_element_link(m_videoPreviewQueue, m_videoPreview);
- ok &= gst_element_link(m_videoTee, m_imageCaptureBin);
- } else {
- UNREF_ELEMENT(m_videoSrc);
- UNREF_ELEMENT(m_videoTee);
- UNREF_ELEMENT(m_videoPreviewQueue);
- UNREF_ELEMENT(m_videoPreview);
- UNREF_ELEMENT(m_imageCaptureBin);
- }
- }
- break;
- case RecordingPipeline:
- m_encodeBin = buildEncodeBin();
- gst_bin_add(GST_BIN(m_pipeline), m_encodeBin);
-
- if (m_captureMode & Audio) {
- m_audioSrc = buildAudioSrc();
- ok &= m_audioSrc != 0;
-
- gst_bin_add(GST_BIN(m_pipeline), m_audioSrc);
- ok &= gst_element_link(m_audioSrc, m_encodeBin);
- }
-
- if (m_captureMode & Video) {
- m_videoSrc = buildVideoSrc();
- ok &= m_videoSrc != 0;
-
- gst_bin_add(GST_BIN(m_pipeline), m_videoSrc);
- ok &= gst_element_link(m_videoSrc, m_encodeBin);
- }
-
- if (!m_metaData.isEmpty())
- setMetaData(m_metaData);
-
- break;
- case PreviewAndRecordingPipeline:
- m_encodeBin = buildEncodeBin();
- if (m_encodeBin)
- gst_bin_add(GST_BIN(m_pipeline), m_encodeBin);
-
- ok &= m_encodeBin != 0;
-
- if (ok && m_captureMode & Audio) {
- m_audioSrc = buildAudioSrc();
- m_audioPreview = buildAudioPreview();
- m_audioTee = gst_element_factory_make("tee", NULL);
- m_audioPreviewQueue = gst_element_factory_make("queue", NULL);
-
- ok &= m_audioSrc && m_audioPreview && m_audioTee && m_audioPreviewQueue;
-
- if (ok) {
- gst_bin_add_many(GST_BIN(m_pipeline), m_audioSrc, m_audioTee,
- m_audioPreviewQueue, m_audioPreview, NULL);
- ok &= gst_element_link(m_audioSrc, m_audioTee);
- ok &= gst_element_link(m_audioTee, m_audioPreviewQueue);
- ok &= gst_element_link(m_audioPreviewQueue, m_audioPreview);
- ok &= gst_element_link(m_audioTee, m_encodeBin);
- } else {
- UNREF_ELEMENT(m_audioSrc);
- UNREF_ELEMENT(m_audioPreview);
- UNREF_ELEMENT(m_audioTee);
- UNREF_ELEMENT(m_audioPreviewQueue);
- }
- }
-
- if (ok && (m_captureMode & Video || m_captureMode & Image)) {
- m_videoSrc = buildVideoSrc();
- m_videoPreview = buildVideoPreview();
- m_videoTee = gst_element_factory_make("tee", NULL);
- m_videoPreviewQueue = gst_element_factory_make("queue", NULL);
-
- ok &= m_videoSrc && m_videoPreview && m_videoTee && m_videoPreviewQueue;
-
- if (ok) {
- gst_bin_add_many(GST_BIN(m_pipeline), m_videoSrc, m_videoTee,
- m_videoPreviewQueue, m_videoPreview, NULL);
- ok &= gst_element_link(m_videoSrc, m_videoTee);
- ok &= gst_element_link(m_videoTee, m_videoPreviewQueue);
- ok &= gst_element_link(m_videoPreviewQueue, m_videoPreview);
- } else {
- UNREF_ELEMENT(m_videoSrc);
- UNREF_ELEMENT(m_videoTee);
- UNREF_ELEMENT(m_videoPreviewQueue);
- UNREF_ELEMENT(m_videoPreview);
- }
-
- if (ok && (m_captureMode & Video))
- ok &= gst_element_link(m_videoTee, m_encodeBin);
- }
-
- if (!m_metaData.isEmpty())
- setMetaData(m_metaData);
-
-
- break;
- }
-
- if (!ok) {
- emit error(int(QMediaRecorder::FormatError),tr("Failed to build media capture pipeline."));
- }
-
- dumpGraph( QString("rebuild_graph_%1_%2").arg(m_pipelineMode).arg(newMode) );
-#ifdef QT_GST_CAPTURE_DEBUG
- if (m_encodeBin) {
- QString fileName = QString("rebuild_graph_encode_%1_%2").arg(m_pipelineMode).arg(newMode);
- GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(m_encodeBin), GST_DEBUG_GRAPH_SHOW_ALL, fileName.toLatin1());
- }
-#endif
-
- if (ok) {
- addAudioBufferProbe();
- m_pipelineMode = newMode;
- } else {
- m_pipelineMode = EmptyPipeline;
-
- REMOVE_ELEMENT(m_audioSrc);
- REMOVE_ELEMENT(m_audioPreview);
- REMOVE_ELEMENT(m_audioPreviewQueue);
- REMOVE_ELEMENT(m_audioTee);
- REMOVE_ELEMENT(m_videoSrc);
- REMOVE_ELEMENT(m_videoPreview);
- REMOVE_ELEMENT(m_videoPreviewQueue);
- REMOVE_ELEMENT(m_videoTee);
- REMOVE_ELEMENT(m_encodeBin);
- }
-
- return ok;
-}
-
-void QGstreamerCaptureSession::dumpGraph(const QString &fileName)
-{
-#ifdef QT_GST_CAPTURE_DEBUG
- GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(m_pipeline),
- GstDebugGraphDetails(/*GST_DEBUG_GRAPH_SHOW_ALL |*/ GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE | GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS | GST_DEBUG_GRAPH_SHOW_STATES),
- fileName.toLatin1());
-#else
- Q_UNUSED(fileName);
-#endif
-}
-
-QUrl QGstreamerCaptureSession::outputLocation() const
-{
- return m_sink;
-}
-
-bool QGstreamerCaptureSession::setOutputLocation(const QUrl& sink)
-{
- if (!sink.isRelative() && !sink.isLocalFile()) {
- qWarning("Output location must be a local file");
- return false;
- }
-
- m_sink = sink;
- return true;
-}
-
-void QGstreamerCaptureSession::setAudioInput(QGstreamerElementFactory *audioInput)
-{
- m_audioInputFactory = audioInput;
-}
-
-void QGstreamerCaptureSession::setAudioPreview(QGstreamerElementFactory *audioPreview)
-{
- m_audioPreviewFactory = audioPreview;
-}
-
-void QGstreamerCaptureSession::setVideoInput(QGstreamerVideoInput *videoInput)
-{
- m_videoInputFactory = videoInput;
-}
-
-void QGstreamerCaptureSession::setVideoPreview(QObject *viewfinder)
-{
- m_viewfinderInterface = qobject_cast<QGstreamerVideoRendererInterface*>(viewfinder);
- if (!m_viewfinderInterface)
- viewfinder = 0;
-
- if (m_viewfinder != viewfinder) {
- bool oldReady = isReady();
-
- if (m_viewfinder) {
- disconnect(m_viewfinder, SIGNAL(sinkChanged()),
- this, SIGNAL(viewfinderChanged()));
- disconnect(m_viewfinder, SIGNAL(readyChanged(bool)),
- this, SIGNAL(readyChanged(bool)));
-
- m_busHelper->removeMessageFilter(m_viewfinder);
- }
-
- m_viewfinder = viewfinder;
- //m_viewfinderHasChanged = true;
-
- if (m_viewfinder) {
- connect(m_viewfinder, SIGNAL(sinkChanged()),
- this, SIGNAL(viewfinderChanged()));
- connect(m_viewfinder, SIGNAL(readyChanged(bool)),
- this, SIGNAL(readyChanged(bool)));
-
- m_busHelper->installMessageFilter(m_viewfinder);
- }
-
- emit viewfinderChanged();
- if (oldReady != isReady())
- emit readyChanged(isReady());
- }
-}
-
-bool QGstreamerCaptureSession::isReady() const
-{
- //it's possible to use QCamera without any viewfinder attached
- return !m_viewfinderInterface || m_viewfinderInterface->isReady();
-}
-
-QGstreamerCaptureSession::State QGstreamerCaptureSession::state() const
-{
- return m_state;
-}
-
-QGstreamerCaptureSession::State QGstreamerCaptureSession::pendingState() const
-{
- return m_pendingState;
-}
-
-void QGstreamerCaptureSession::setState(QGstreamerCaptureSession::State newState)
-{
- if (newState == m_pendingState && !m_waitingForEos)
- return;
-
- m_pendingState = newState;
-
- PipelineMode newMode = EmptyPipeline;
-
- switch (newState) {
- case PausedState:
- case RecordingState:
- newMode = PreviewAndRecordingPipeline;
- break;
- case PreviewState:
- newMode = PreviewPipeline;
- break;
- case StoppedState:
- newMode = EmptyPipeline;
- break;
- }
-
- if (newMode != m_pipelineMode) {
- if (m_pipelineMode == PreviewAndRecordingPipeline) {
- if (!m_waitingForEos) {
- m_waitingForEos = true;
- //qDebug() << "Waiting for EOS";
- // Unless gstreamer is in GST_STATE_PLAYING our EOS message will not be received.
- gst_element_set_state(m_pipeline, GST_STATE_PLAYING);
- //with live sources it's necessary to send EOS even to pipeline
- //before going to STOPPED state
- gst_element_send_event(m_pipeline, gst_event_new_eos());
-
- return;
- } else {
- m_waitingForEos = false;
- //qDebug() << "EOS received";
- }
- }
-
- //select suitable default codecs/containers, if necessary
- m_recorderControl->applySettings();
-
- gst_element_set_state(m_pipeline, GST_STATE_NULL);
-
- if (!rebuildGraph(newMode)) {
- m_pendingState = StoppedState;
- m_state = StoppedState;
- emit stateChanged(StoppedState);
-
- return;
- }
- }
-
- switch (newState) {
- case PausedState:
- gst_element_set_state(m_pipeline, GST_STATE_PAUSED);
- break;
- case RecordingState:
- case PreviewState:
- gst_element_set_state(m_pipeline, GST_STATE_PLAYING);
- break;
- case StoppedState:
- gst_element_set_state(m_pipeline, GST_STATE_NULL);
- }
-
- //we have to do it here, since gstreamer will not emit bus messages any more
- if (newState == StoppedState) {
- m_state = StoppedState;
- emit stateChanged(StoppedState);
- }
-}
-
-
-qint64 QGstreamerCaptureSession::duration() const
-{
- gint64 duration = 0;
- if (m_encodeBin && qt_gst_element_query_position(m_encodeBin, GST_FORMAT_TIME, &duration))
- return duration / 1000000;
- else
- return 0;
-}
-
-void QGstreamerCaptureSession::setCaptureDevice(const QString &deviceName)
-{
- m_captureDevice = deviceName;
-}
-
-void QGstreamerCaptureSession::setMetaData(const QMap<QByteArray, QVariant> &data)
-{
- //qDebug() << "QGstreamerCaptureSession::setMetaData" << data;
- m_metaData = data;
-
- if (m_encodeBin)
- QGstUtils::setMetaData(GST_BIN(m_encodeBin), data);
-}
-
-bool QGstreamerCaptureSession::processBusMessage(const QGstreamerMessage &message)
-{
- GstMessage* gm = message.rawMessage();
-
- if (gm) {
- if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ERROR) {
- GError *err;
- gchar *debug;
- gst_message_parse_error (gm, &err, &debug);
- emit error(int(QMediaRecorder::ResourceError),QString::fromUtf8(err->message));
- g_error_free (err);
- g_free (debug);
- }
-
- if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_pipeline)) {
- switch (GST_MESSAGE_TYPE(gm)) {
- case GST_MESSAGE_DURATION:
- break;
-
- case GST_MESSAGE_EOS:
- if (m_waitingForEos)
- setState(m_pendingState);
- break;
-
- case GST_MESSAGE_STATE_CHANGED:
- {
-
- GstState oldState;
- GstState newState;
- GstState pending;
-
- gst_message_parse_state_changed(gm, &oldState, &newState, &pending);
-
- QStringList states;
- states << "GST_STATE_VOID_PENDING" << "GST_STATE_NULL" << "GST_STATE_READY" << "GST_STATE_PAUSED" << "GST_STATE_PLAYING";
-
- /*
- qDebug() << QString("state changed: old: %1 new: %2 pending: %3") \
- .arg(states[oldState]) \
- .arg(states[newState]) \
- .arg(states[pending]);
-
- #define ENUM_NAME(c,e,v) (c::staticMetaObject.enumerator(c::staticMetaObject.indexOfEnumerator(e)).valueToKey((v)))
-
- qDebug() << "Current session state:" << ENUM_NAME(QGstreamerCaptureSession,"State",m_state);
- qDebug() << "Pending session state:" << ENUM_NAME(QGstreamerCaptureSession,"State",m_pendingState);
- */
-
- switch (newState) {
- case GST_STATE_VOID_PENDING:
- case GST_STATE_NULL:
- case GST_STATE_READY:
- if (m_state != StoppedState && m_pendingState == StoppedState) {
- emit stateChanged(m_state = StoppedState);
- dumpGraph("stopped");
- }
- break;
- case GST_STATE_PAUSED:
- if (m_state != PausedState && m_pendingState == PausedState)
- emit stateChanged(m_state = PausedState);
- dumpGraph("paused");
-
- if (m_pipelineMode == RecordingPipeline && !m_metaData.isEmpty())
- setMetaData(m_metaData);
- break;
- case GST_STATE_PLAYING:
- {
- if ((m_pendingState == PreviewState || m_pendingState == RecordingState) &&
- m_state != m_pendingState)
- {
- m_state = m_pendingState;
- emit stateChanged(m_state);
- }
-
- if (m_pipelineMode == PreviewPipeline)
- dumpGraph("preview");
- else
- dumpGraph("recording");
- }
- break;
- }
- }
- break;
- default:
- break;
- }
- //qDebug() << "New session state:" << ENUM_NAME(QGstreamerCaptureSession,"State",m_state);
- }
- }
- return false;
-}
-
-void QGstreamerCaptureSession::setMuted(bool muted)
-{
- if (bool(m_muted) != muted) {
- m_muted = muted;
- if (m_audioVolume)
- g_object_set(G_OBJECT(m_audioVolume), "mute", m_muted, NULL);
-
- emit mutedChanged(muted);
- }
-}
-
-void QGstreamerCaptureSession::setVolume(qreal volume)
-{
- if (!qFuzzyCompare(double(volume), m_volume)) {
- m_volume = volume;
- if (m_audioVolume)
- g_object_set(G_OBJECT(m_audioVolume), "volume", m_volume, NULL);
-
- emit volumeChanged(volume);
- }
-}
-
-void QGstreamerCaptureSession::addProbe(QGstreamerAudioProbeControl* probe)
-{
- Q_ASSERT(!m_audioProbe);
- m_audioProbe = probe;
- addAudioBufferProbe();
-}
-
-void QGstreamerCaptureSession::removeProbe(QGstreamerAudioProbeControl* probe)
-{
- Q_ASSERT(m_audioProbe == probe);
- removeAudioBufferProbe();
- m_audioProbe = 0;
-}
-
-GstPad *QGstreamerCaptureSession::getAudioProbePad()
-{
- // first see if preview element is available
- if (m_audioPreview) {
- GstPad *pad = gst_element_get_static_pad(m_audioPreview, "sink");
- if (pad)
- return pad;
- }
-
- // preview element is not available,
- // try to use sink pin of audio encoder.
- if (m_encodeBin) {
- GstElement *audioEncoder = gst_bin_get_by_name(GST_BIN(m_encodeBin), "audio-encoder-bin");
- if (audioEncoder) {
- GstPad *pad = gst_element_get_static_pad(audioEncoder, "sink");
- gst_object_unref(audioEncoder);
- if (pad)
- return pad;
- }
- }
-
- return 0;
-}
-
-void QGstreamerCaptureSession::removeAudioBufferProbe()
-{
- if (!m_audioProbe)
- return;
-
- GstPad *pad = getAudioProbePad();
- if (pad) {
- m_audioProbe->removeProbeFromPad(pad);
- gst_object_unref(GST_OBJECT(pad));
- }
-}
-
-void QGstreamerCaptureSession::addAudioBufferProbe()
-{
- if (!m_audioProbe)
- return;
-
- GstPad *pad = getAudioProbePad();
- if (pad) {
- m_audioProbe->addProbeToPad(pad);
- gst_object_unref(GST_OBJECT(pad));
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.h b/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.h
deleted file mode 100644
index e0c9107a7..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.h
+++ /dev/null
@@ -1,244 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERCAPTURESESSION_H
-#define QGSTREAMERCAPTURESESSION_H
-
-#include <qmediarecordercontrol.h>
-#include <qmediarecorder.h>
-
-#include <QtCore/qmutex.h>
-#include <QtCore/qurl.h>
-
-#include <gst/gst.h>
-#include <gst/video/video.h>
-
-#include <private/qgstreamerbushelper_p.h>
-#include <private/qgstreamerbufferprobe_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerMessage;
-class QGstreamerBusHelper;
-class QGstreamerAudioEncode;
-class QGstreamerVideoEncode;
-class QGstreamerImageEncode;
-class QGstreamerRecorderControl;
-class QGstreamerMediaContainerControl;
-class QGstreamerVideoRendererInterface;
-class QGstreamerAudioProbeControl;
-
-class QGstreamerElementFactory
-{
-public:
- virtual GstElement *buildElement() = 0;
- virtual void prepareWinId() {}
-};
-
-class QGstreamerVideoInput : public QGstreamerElementFactory
-{
-public:
- virtual QList<qreal> supportedFrameRates(const QSize &frameSize = QSize()) const = 0;
- virtual QList<QSize> supportedResolutions(qreal frameRate = -1) const = 0;
-};
-
-class QGstreamerCaptureSession
- : public QObject
- , public QGstreamerBusMessageFilter
- , private QGstreamerBufferProbe
-{
- Q_OBJECT
- Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
- Q_ENUMS(State)
- Q_ENUMS(CaptureMode)
- Q_INTERFACES(QGstreamerBusMessageFilter)
-public:
- enum CaptureMode { Audio = 1,
- Video = 2,
- Image = 4,
- AudioAndVideo = Audio | Video,
- AudioAndVideoAndImage = Audio | Video | Image
- };
- enum State { StoppedState, PreviewState, PausedState, RecordingState };
-
- QGstreamerCaptureSession(CaptureMode captureMode, QObject *parent);
- ~QGstreamerCaptureSession();
-
- QGstreamerBusHelper *bus() { return m_busHelper; }
-
- CaptureMode captureMode() const { return m_captureMode; }
- void setCaptureMode(CaptureMode);
-
- QUrl outputLocation() const;
- bool setOutputLocation(const QUrl& sink);
-
- QGstreamerAudioEncode *audioEncodeControl() const { return m_audioEncodeControl; }
- QGstreamerVideoEncode *videoEncodeControl() const { return m_videoEncodeControl; }
- QGstreamerImageEncode *imageEncodeControl() const { return m_imageEncodeControl; }
-
- QGstreamerRecorderControl *recorderControl() const { return m_recorderControl; }
- QGstreamerMediaContainerControl *mediaContainerControl() const { return m_mediaContainerControl; }
-
- QGstreamerElementFactory *audioInput() const { return m_audioInputFactory; }
- void setAudioInput(QGstreamerElementFactory *audioInput);
-
- QGstreamerElementFactory *audioPreview() const { return m_audioPreviewFactory; }
- void setAudioPreview(QGstreamerElementFactory *audioPreview);
-
- QGstreamerVideoInput *videoInput() const { return m_videoInputFactory; }
- void setVideoInput(QGstreamerVideoInput *videoInput);
-
- QObject *videoPreview() const { return m_viewfinder; }
- void setVideoPreview(QObject *viewfinder);
-
- void captureImage(int requestId, const QString &fileName);
-
- State state() const;
- State pendingState() const;
-
- qint64 duration() const;
- bool isMuted() const { return m_muted; }
- qreal volume() const { return m_volume; }
-
- bool isReady() const;
-
- bool processBusMessage(const QGstreamerMessage &message) override;
-
- void addProbe(QGstreamerAudioProbeControl* probe);
- void removeProbe(QGstreamerAudioProbeControl* probe);
-
-signals:
- void stateChanged(QGstreamerCaptureSession::State state);
- void durationChanged(qint64 duration);
- void error(int error, const QString &errorString);
- void imageExposed(int requestId);
- void imageCaptured(int requestId, const QImage &img);
- void imageSaved(int requestId, const QString &path);
- void mutedChanged(bool);
- void volumeChanged(qreal);
- void readyChanged(bool);
- void viewfinderChanged();
-
-public slots:
- void setState(QGstreamerCaptureSession::State);
- void setCaptureDevice(const QString &deviceName);
-
- void dumpGraph(const QString &fileName);
-
- void setMetaData(const QMap<QByteArray, QVariant>&);
- void setMuted(bool);
- void setVolume(qreal volume);
-
-private:
- void probeCaps(GstCaps *caps) override;
- bool probeBuffer(GstBuffer *buffer) override;
-
- enum PipelineMode { EmptyPipeline, PreviewPipeline, RecordingPipeline, PreviewAndRecordingPipeline };
-
- GstElement *buildEncodeBin();
- GstElement *buildAudioSrc();
- GstElement *buildAudioPreview();
- GstElement *buildVideoSrc();
- GstElement *buildVideoPreview();
- GstElement *buildImageCapture();
-
- bool rebuildGraph(QGstreamerCaptureSession::PipelineMode newMode);
-
- GstPad *getAudioProbePad();
- void removeAudioBufferProbe();
- void addAudioBufferProbe();
-
- QUrl m_sink;
- QString m_captureDevice;
- State m_state;
- State m_pendingState;
- bool m_waitingForEos;
- PipelineMode m_pipelineMode;
- QGstreamerCaptureSession::CaptureMode m_captureMode;
- QMap<QByteArray, QVariant> m_metaData;
-
- QGstreamerAudioProbeControl *m_audioProbe;
-
- QGstreamerElementFactory *m_audioInputFactory;
- QGstreamerElementFactory *m_audioPreviewFactory;
- QGstreamerVideoInput *m_videoInputFactory;
- QObject *m_viewfinder;
- QGstreamerVideoRendererInterface *m_viewfinderInterface;
-
- QGstreamerAudioEncode *m_audioEncodeControl;
- QGstreamerVideoEncode *m_videoEncodeControl;
- QGstreamerImageEncode *m_imageEncodeControl;
- QGstreamerRecorderControl *m_recorderControl;
- QGstreamerMediaContainerControl *m_mediaContainerControl;
-
- QGstreamerBusHelper *m_busHelper;
- GstBus* m_bus;
- GstElement *m_pipeline;
-
- GstElement *m_audioSrc;
- GstElement *m_audioTee;
- GstElement *m_audioPreviewQueue;
- GstElement *m_audioPreview;
- GstElement *m_audioVolume;
- gboolean m_muted;
- double m_volume;
-
- GstElement *m_videoSrc;
- GstElement *m_videoTee;
- GstElement *m_videoPreviewQueue;
- GstElement *m_videoPreview;
-
- GstElement *m_imageCaptureBin;
-
- GstElement *m_encodeBin;
-
-#if GST_CHECK_VERSION(1,0,0)
- GstVideoInfo m_previewInfo;
-#endif
-
-public:
- bool m_passImage;
- bool m_passPrerollImage;
- QString m_imageFileName;
- int m_imageRequestId;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERCAPTURESESSION_H
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.cpp
deleted file mode 100644
index 120c19af6..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamerimagecapturecontrol.h"
-#include <QtCore/QDebug>
-#include <QtCore/QDir>
-
-QGstreamerImageCaptureControl::QGstreamerImageCaptureControl(QGstreamerCaptureSession *session)
- :QCameraImageCaptureControl(session), m_session(session), m_ready(false), m_lastId(0)
-{
- connect(m_session, SIGNAL(stateChanged(QGstreamerCaptureSession::State)), SLOT(updateState()));
- connect(m_session, SIGNAL(imageExposed(int)), this, SIGNAL(imageExposed(int)));
- connect(m_session, SIGNAL(imageCaptured(int,QImage)), this, SIGNAL(imageCaptured(int,QImage)));
- connect(m_session, SIGNAL(imageSaved(int,QString)), this, SIGNAL(imageSaved(int,QString)));
-}
-
-QGstreamerImageCaptureControl::~QGstreamerImageCaptureControl()
-{
-}
-
-bool QGstreamerImageCaptureControl::isReadyForCapture() const
-{
- return m_ready;
-}
-
-int QGstreamerImageCaptureControl::capture(const QString &fileName)
-{
- m_lastId++;
-
- //it's allowed to request image capture while camera is starting
- if (m_session->pendingState() == QGstreamerCaptureSession::StoppedState ||
- !(m_session->captureMode() & QGstreamerCaptureSession::Image)) {
- //emit error in the next event loop,
- //so application can associate it with returned request id.
- QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
- Q_ARG(int, m_lastId),
- Q_ARG(int, QCameraImageCapture::NotReadyError),
- Q_ARG(QString,tr("Not ready to capture")));
-
- return m_lastId;
- }
-
- QString path = fileName;
- if (path.isEmpty()) {
- int lastImage = 0;
- QDir outputDir = QDir::currentPath();
- const auto list = outputDir.entryList(QStringList() << "img_*.jpg");
- for (const QString &fileName : list) {
- int imgNumber = QStringView{fileName}.mid(4, fileName.size()-8).toInt();
- lastImage = qMax(lastImage, imgNumber);
- }
-
- path = QString("img_%1.jpg").arg(lastImage+1,
- 4, //fieldWidth
- 10,
- QLatin1Char('0'));
- }
-
- m_session->captureImage(m_lastId, path);
-
- return m_lastId;
-}
-
-void QGstreamerImageCaptureControl::cancelCapture()
-{
-
-}
-
-void QGstreamerImageCaptureControl::updateState()
-{
- bool ready = (m_session->state() == QGstreamerCaptureSession::PreviewState) &&
- (m_session->captureMode() & QGstreamerCaptureSession::Image);
-
- if (m_ready != ready) {
- emit readyForCaptureChanged(m_ready = ready);
- }
-}
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.h b/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.h
deleted file mode 100644
index f58cf09c5..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QGSTREAMERIMAGECAPTURECONTROL_H
-#define QGSTREAMERIMAGECAPTURECONTROL_H
-
-#include <qcameraimagecapturecontrol.h>
-#include "qgstreamercapturesession.h"
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerImageCaptureControl : public QCameraImageCaptureControl
-{
- Q_OBJECT
-public:
- QGstreamerImageCaptureControl(QGstreamerCaptureSession *session);
- virtual ~QGstreamerImageCaptureControl();
-
- QCameraImageCapture::DriveMode driveMode() const override { return QCameraImageCapture::SingleImageCapture; }
- void setDriveMode(QCameraImageCapture::DriveMode) override {}
-
- bool isReadyForCapture() const override;
- int capture(const QString &fileName) override;
- void cancelCapture() override;
-
-private slots:
- void updateState();
-
-private:
- QGstreamerCaptureSession *m_session;
- bool m_ready;
- int m_lastId;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERCAPTURECORNTROL_H
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.cpp b/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.cpp
deleted file mode 100644
index f9e6ce9ef..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamerimageencode.h"
-#include "qgstreamercapturesession.h"
-
-#include <QtCore/qdebug.h>
-
-#include <math.h>
-
-QGstreamerImageEncode::QGstreamerImageEncode(QGstreamerCaptureSession *session)
- :QImageEncoderControl(session), m_session(session)
-{
-}
-
-QGstreamerImageEncode::~QGstreamerImageEncode()
-{
-}
-
-QList<QSize> QGstreamerImageEncode::supportedResolutions(const QImageEncoderSettings &, bool *continuous) const
-{
- if (continuous)
- *continuous = m_session->videoInput() != 0;
-
- return m_session->videoInput() ? m_session->videoInput()->supportedResolutions() : QList<QSize>();
-}
-
-QStringList QGstreamerImageEncode::supportedImageCodecs() const
-{
- return QStringList() << "jpeg";
-}
-
-QString QGstreamerImageEncode::imageCodecDescription(const QString &codecName) const
-{
- if (codecName == "jpeg")
- return tr("JPEG image encoder");
-
- return QString();
-}
-
-QImageEncoderSettings QGstreamerImageEncode::imageSettings() const
-{
- return m_settings;
-}
-
-void QGstreamerImageEncode::setImageSettings(const QImageEncoderSettings &settings)
-{
- if (m_settings != settings) {
- m_settings = settings;
- emit settingsChanged();
- }
-}
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.h b/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.h
deleted file mode 100644
index f3ebd3e90..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERIMAGEENCODE_H
-#define QGSTREAMERIMAGEENCODE_H
-
-#include <qimageencodercontrol.h>
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmap.h>
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerCaptureSession;
-
-class QGstreamerImageEncode : public QImageEncoderControl
-{
- Q_OBJECT
-public:
- QGstreamerImageEncode(QGstreamerCaptureSession *session);
- virtual ~QGstreamerImageEncode();
-
- QList<QSize> supportedResolutions(const QImageEncoderSettings &settings = QImageEncoderSettings(),
- bool *continuous = 0) const override;
-
- QStringList supportedImageCodecs() const override;
- QString imageCodecDescription(const QString &codecName) const override;
-
- QImageEncoderSettings imageSettings() const override;
- void setImageSettings(const QImageEncoderSettings &settings) override;
-
-Q_SIGNALS:
- void settingsChanged();
-
-private:
- QImageEncoderSettings m_settings;
-
- QGstreamerCaptureSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.cpp
deleted file mode 100644
index 33351476d..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamermediacontainercontrol.h"
-
-#include <private/qgstutils_p.h>
-
-#include <QtCore/qdebug.h>
-
-QGstreamerMediaContainerControl::QGstreamerMediaContainerControl(QObject *parent)
- :QMediaContainerControl(parent)
- , m_containers(QGstCodecsInfo::Muxer)
-{
-}
-
-QSet<QString> QGstreamerMediaContainerControl::supportedStreamTypes(const QString &container) const
-{
- return m_containers.supportedStreamTypes(container);
-}
-
-QString QGstreamerMediaContainerControl::containerExtension() const
-{
- return QGstUtils::fileExtensionForMimeType(m_format);
-}
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.h b/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.h
deleted file mode 100644
index 02c7346b1..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QGSTREAMERMEDIACONTAINERCONTROL_H
-#define QGSTREAMERMEDIACONTAINERCONTROL_H
-
-#include <qmediacontainercontrol.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qset.h>
-
-#include <private/qgstcodecsinfo_p.h>
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerMediaContainerControl : public QMediaContainerControl
-{
-Q_OBJECT
-public:
- QGstreamerMediaContainerControl(QObject *parent);
- ~QGstreamerMediaContainerControl() {}
-
- QStringList supportedContainers() const override { return m_containers.supportedCodecs(); }
- QString containerFormat() const override { return m_format; }
- void setContainerFormat(const QString &formatMimeType) override { m_format = formatMimeType; }
-
- QString containerDescription(const QString &formatMimeType) const override { return m_containers.codecDescription(formatMimeType); }
-
- QByteArray formatElementName() const { return m_containers.codecElement(containerFormat()); }
-
- QSet<QString> supportedStreamTypes(const QString &container) const;
-
- QString containerExtension() const;
-
-private:
- QString m_format;
- QGstCodecsInfo m_containers;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERMEDIACONTAINERCONTROL_H
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp
deleted file mode 100644
index d7f4ec035..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp
+++ /dev/null
@@ -1,372 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamerrecordercontrol.h"
-#include "qgstreameraudioencode.h"
-#include "qgstreamervideoencode.h"
-#include "qgstreamermediacontainercontrol.h"
-#include <QtCore/QDebug>
-#include <QtGui/qdesktopservices.h>
-#include <QStandardPaths>
-
-QGstreamerRecorderControl::QGstreamerRecorderControl(QGstreamerCaptureSession *session)
- :QMediaRecorderControl(session),
- m_session(session),
- m_state(QMediaRecorder::StoppedState),
- m_status(QMediaRecorder::UnloadedStatus)
-{
- connect(m_session, SIGNAL(stateChanged(QGstreamerCaptureSession::State)), SLOT(updateStatus()));
- connect(m_session, SIGNAL(error(int,QString)), SLOT(handleSessionError(int,QString)));
- connect(m_session, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64)));
- connect(m_session, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool)));
- connect(m_session, SIGNAL(volumeChanged(qreal)), SIGNAL(volumeChanged(qreal)));
- m_hasPreviewState = m_session->captureMode() != QGstreamerCaptureSession::Audio;
-}
-
-QGstreamerRecorderControl::~QGstreamerRecorderControl()
-{
-}
-
-QUrl QGstreamerRecorderControl::outputLocation() const
-{
- return m_session->outputLocation();
-}
-
-bool QGstreamerRecorderControl::setOutputLocation(const QUrl &sink)
-{
- m_outputLocation = sink;
- m_session->setOutputLocation(sink);
- return true;
-}
-
-
-QMediaRecorder::State QGstreamerRecorderControl::state() const
-{
- return m_state;
-}
-
-QMediaRecorder::Status QGstreamerRecorderControl::status() const
-{
- static QMediaRecorder::Status statusTable[3][3] = {
- //Stopped recorder state:
- { QMediaRecorder::LoadedStatus, QMediaRecorder::FinalizingStatus, QMediaRecorder::FinalizingStatus },
- //Recording recorder state:
- { QMediaRecorder::StartingStatus, QMediaRecorder::RecordingStatus, QMediaRecorder::PausedStatus },
- //Paused recorder state:
- { QMediaRecorder::StartingStatus, QMediaRecorder::RecordingStatus, QMediaRecorder::PausedStatus }
- };
-
- QMediaRecorder::State sessionState = QMediaRecorder::StoppedState;
-
- switch ( m_session->state() ) {
- case QGstreamerCaptureSession::RecordingState:
- sessionState = QMediaRecorder::RecordingState;
- break;
- case QGstreamerCaptureSession::PausedState:
- sessionState = QMediaRecorder::PausedState;
- break;
- case QGstreamerCaptureSession::PreviewState:
- case QGstreamerCaptureSession::StoppedState:
- sessionState = QMediaRecorder::StoppedState;
- break;
- }
-
- return statusTable[m_state][sessionState];
-}
-
-void QGstreamerRecorderControl::updateStatus()
-{
- QMediaRecorder::Status newStatus = status();
- if (m_status != newStatus) {
- m_status = newStatus;
- emit statusChanged(m_status);
- // If stop has been called and session state became stopped.
- if (m_status == QMediaRecorder::LoadedStatus)
- emit stateChanged(m_state);
- }
-}
-
-void QGstreamerRecorderControl::handleSessionError(int code, const QString &description)
-{
- emit error(code, description);
- stop();
-}
-
-qint64 QGstreamerRecorderControl::duration() const
-{
- return m_session->duration();
-}
-
-void QGstreamerRecorderControl::setState(QMediaRecorder::State state)
-{
- switch (state) {
- case QMediaRecorder::StoppedState:
- stop();
- break;
- case QMediaRecorder::PausedState:
- pause();
- break;
- case QMediaRecorder::RecordingState:
- record();
- break;
- }
-}
-
-void QGstreamerRecorderControl::record()
-{
- if (m_state == QMediaRecorder::RecordingState)
- return;
-
- m_state = QMediaRecorder::RecordingState;
-
- if (m_outputLocation.isEmpty()) {
- QString container = m_session->mediaContainerControl()->containerExtension();
- if (container.isEmpty())
- container = "raw";
-
- m_session->setOutputLocation(QUrl(generateFileName(defaultDir(), container)));
- }
-
- m_session->dumpGraph("before-record");
- if (!m_hasPreviewState || m_session->state() != QGstreamerCaptureSession::StoppedState) {
- m_session->setState(QGstreamerCaptureSession::RecordingState);
- } else
- emit error(QMediaRecorder::ResourceError, tr("Service has not been started"));
-
- m_session->dumpGraph("after-record");
-
- emit stateChanged(m_state);
- updateStatus();
-
- emit actualLocationChanged(m_session->outputLocation());
-}
-
-void QGstreamerRecorderControl::pause()
-{
- if (m_state == QMediaRecorder::PausedState)
- return;
-
- m_state = QMediaRecorder::PausedState;
-
- m_session->dumpGraph("before-pause");
- if (!m_hasPreviewState || m_session->state() != QGstreamerCaptureSession::StoppedState) {
- m_session->setState(QGstreamerCaptureSession::PausedState);
- } else
- emit error(QMediaRecorder::ResourceError, tr("Service has not been started"));
-
- emit stateChanged(m_state);
- updateStatus();
-}
-
-void QGstreamerRecorderControl::stop()
-{
- if (m_state == QMediaRecorder::StoppedState)
- return;
-
- m_state = QMediaRecorder::StoppedState;
-
- if (!m_hasPreviewState) {
- m_session->setState(QGstreamerCaptureSession::StoppedState);
- } else {
- if (m_session->state() != QGstreamerCaptureSession::StoppedState)
- m_session->setState(QGstreamerCaptureSession::PreviewState);
- }
-
- updateStatus();
-}
-
-void QGstreamerRecorderControl::applySettings()
-{
- //Check the codecs are compatible with container,
- //and choose the compatible codecs/container if omitted
- QGstreamerAudioEncode *audioEncodeControl = m_session->audioEncodeControl();
- QGstreamerVideoEncode *videoEncodeControl = m_session->videoEncodeControl();
- QGstreamerMediaContainerControl *mediaContainerControl = m_session->mediaContainerControl();
-
- bool needAudio = m_session->captureMode() & QGstreamerCaptureSession::Audio;
- bool needVideo = m_session->captureMode() & QGstreamerCaptureSession::Video;
-
- QStringList containerCandidates;
- if (mediaContainerControl->containerFormat().isEmpty())
- containerCandidates = mediaContainerControl->supportedContainers();
- else
- containerCandidates << mediaContainerControl->containerFormat();
-
-
- QStringList audioCandidates;
- if (needAudio) {
- QAudioEncoderSettings audioSettings = audioEncodeControl->audioSettings();
- if (audioSettings.codec().isEmpty())
- audioCandidates = audioEncodeControl->supportedAudioCodecs();
- else
- audioCandidates << audioSettings.codec();
- }
-
- QStringList videoCandidates;
- if (needVideo) {
- QVideoEncoderSettings videoSettings = videoEncodeControl->videoSettings();
- if (videoSettings.codec().isEmpty())
- videoCandidates = videoEncodeControl->supportedVideoCodecs();
- else
- videoCandidates << videoSettings.codec();
- }
-
- QString container;
- QString audioCodec;
- QString videoCodec;
-
- for (const QString &containerCandidate : qAsConst(containerCandidates)) {
- QSet<QString> supportedTypes = mediaContainerControl->supportedStreamTypes(containerCandidate);
-
- audioCodec.clear();
- videoCodec.clear();
-
- if (needAudio) {
- bool found = false;
- for (const QString &audioCandidate : qAsConst(audioCandidates)) {
- QSet<QString> audioTypes = audioEncodeControl->supportedStreamTypes(audioCandidate);
- if (audioTypes.intersects(supportedTypes)) {
- found = true;
- audioCodec = audioCandidate;
- break;
- }
- }
- if (!found)
- continue;
- }
-
- if (needVideo) {
- bool found = false;
- for (const QString &videoCandidate : qAsConst(videoCandidates)) {
- QSet<QString> videoTypes = videoEncodeControl->supportedStreamTypes(videoCandidate);
- if (videoTypes.intersects(supportedTypes)) {
- found = true;
- videoCodec = videoCandidate;
- break;
- }
- }
- if (!found)
- continue;
- }
-
- container = containerCandidate;
- break;
- }
-
- if (container.isEmpty()) {
- emit error(QMediaRecorder::FormatError, tr("Not compatible codecs and container format."));
- } else {
- mediaContainerControl->setContainerFormat(container);
-
- if (needAudio) {
- QAudioEncoderSettings audioSettings = audioEncodeControl->audioSettings();
- audioSettings.setCodec(audioCodec);
- audioEncodeControl->setAudioSettings(audioSettings);
- }
-
- if (needVideo) {
- QVideoEncoderSettings videoSettings = videoEncodeControl->videoSettings();
- videoSettings.setCodec(videoCodec);
- videoEncodeControl->setVideoSettings(videoSettings);
- }
- }
-}
-
-
-bool QGstreamerRecorderControl::isMuted() const
-{
- return m_session->isMuted();
-}
-
-qreal QGstreamerRecorderControl::volume() const
-{
- return m_session->volume();
-}
-
-void QGstreamerRecorderControl::setMuted(bool muted)
-{
- m_session->setMuted(muted);
-}
-
-void QGstreamerRecorderControl::setVolume(qreal volume)
-{
- m_session->setVolume(volume);
-}
-
-QDir QGstreamerRecorderControl::defaultDir() const
-{
- QStringList dirCandidates;
-
- if (m_session->captureMode() & QGstreamerCaptureSession::Video)
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
- else
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
-
- dirCandidates << QDir::home().filePath("Documents");
- dirCandidates << QDir::home().filePath("My Documents");
- dirCandidates << QDir::homePath();
- dirCandidates << QDir::currentPath();
- dirCandidates << QDir::tempPath();
-
- for (const QString &path : qAsConst(dirCandidates)) {
- QDir dir(path);
- if (dir.exists() && QFileInfo(path).isWritable())
- return dir;
- }
-
- return QDir();
-}
-
-QString QGstreamerRecorderControl::generateFileName(const QDir &dir, const QString &ext) const
-{
-
- int lastClip = 0;
- const auto list = dir.entryList(QStringList() << QString("clip_*.%1").arg(ext));
- for (const QString &fileName : list) {
- int imgNumber = QStringView{fileName}.mid(5, fileName.size()-6-ext.length()).toInt();
- lastClip = qMax(lastClip, imgNumber);
- }
-
- QString name = QString("clip_%1.%2").arg(lastClip+1,
- 4, //fieldWidth
- 10,
- QLatin1Char('0')).arg(ext);
-
- return dir.absoluteFilePath(name);
-}
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.h b/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.h
deleted file mode 100644
index b80716f4c..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QGSTREAMERRECORDERCONTROL_H
-#define QGSTREAMERRECORDERCONTROL_H
-
-#include <QtCore/QDir>
-
-#include <qmediarecordercontrol.h>
-#include "qgstreamercapturesession.h"
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerRecorderControl : public QMediaRecorderControl
-{
- Q_OBJECT
-
-public:
- QGstreamerRecorderControl(QGstreamerCaptureSession *session);
- virtual ~QGstreamerRecorderControl();
-
- QUrl outputLocation() const override;
- bool setOutputLocation(const QUrl &sink) override;
-
- QMediaRecorder::State state() const override;
- QMediaRecorder::Status status() const override;
-
- qint64 duration() const override;
-
- bool isMuted() const override;
- qreal volume() const override;
-
- void applySettings() override;
-
-public slots:
- void setState(QMediaRecorder::State state) override;
- void record();
- void pause();
- void stop();
- void setMuted(bool) override;
- void setVolume(qreal volume) override;
-
-private slots:
- void updateStatus();
- void handleSessionError(int code, const QString &description);
-
-private:
- QDir defaultDir() const;
- QString generateFileName(const QDir &dir, const QString &ext) const;
-
- QUrl m_outputLocation;
- QGstreamerCaptureSession *m_session;
- QMediaRecorder::State m_state;
- QMediaRecorder::Status m_status;
- bool m_hasPreviewState;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERCAPTURECORNTROL_H
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.cpp b/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.cpp
deleted file mode 100644
index ef0832f7e..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.cpp
+++ /dev/null
@@ -1,286 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamerv4l2input.h"
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qfile.h>
-
-#include <private/qcore_unix_p.h>
-#include <linux/videodev2.h>
-
-#include <algorithm>
-
-QT_BEGIN_NAMESPACE
-static inline uint qHash(const QSize& key) { return uint(key.width()*256+key.height()); }
-
-static bool operator<(const QSize &s1, const QSize s2)
-{
- return s1.width()*s1.height() < s2.width()*s2.height();
-}
-QT_END_NAMESPACE
-
-QGstreamerV4L2Input::QGstreamerV4L2Input(QObject *parent)
- :QObject(parent)
-{
-}
-
-QGstreamerV4L2Input::~QGstreamerV4L2Input()
-{
-}
-
-GstElement *QGstreamerV4L2Input::buildElement()
-{
- GstElement *camera = gst_element_factory_make("v4l2src", "camera_source");
- if (camera && !m_device.isEmpty() )
- g_object_set(G_OBJECT(camera), "device", m_device.constData(), NULL);
-
- return camera;
-}
-
-void QGstreamerV4L2Input::setDevice(const QByteArray &newDevice)
-{
- if (m_device != newDevice) {
- m_device = newDevice;
- updateSupportedResolutions(newDevice);
- }
-}
-
-void QGstreamerV4L2Input::setDevice(const QString &device)
-{
- setDevice(QFile::encodeName(device));
-}
-
-void QGstreamerV4L2Input::updateSupportedResolutions(const QByteArray &device)
-{
- m_frameRates.clear();
- m_resolutions.clear();
- m_ratesByResolution.clear();
-
- QSet<QSize> allResolutions;
- QSet<int> allFrameRates;
-
- QFile f(device);
-
- if (!f.open(QFile::ReadOnly))
- return;
-
- int fd = f.handle();
-
- //get the list of formats:
- QList<quint32> supportedFormats;
-
- {
- v4l2_fmtdesc fmt;
- memset(&fmt, 0, sizeof(v4l2_fmtdesc));
-
- fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- int sanity = 0;
-
- for (fmt.index = 0;; fmt.index++) {
- if (sanity++ > 8)
- break;
- if( ::ioctl(fd, VIDIOC_ENUM_FMT, &fmt) == -1) {
- if(errno == EINVAL)
- break;
- }
- supportedFormats.append(fmt.pixelformat);
- }
- }
-
- QList<QSize> commonSizes;
- commonSizes << QSize(128, 96)
- <<QSize(160,120)
- <<QSize(176, 144)
- <<QSize(320, 240)
- <<QSize(352, 288)
- <<QSize(640, 480)
- <<QSize(1024, 768)
- <<QSize(1280, 1024)
- <<QSize(1600, 1200)
- <<QSize(1920, 1200)
- <<QSize(2048, 1536)
- <<QSize(2560, 1600)
- <<QSize(2580, 1936);
-
- QList<int> commonRates;
- commonRates << 05*1000 << 75*1000 << 10*1000 << 15*1000 << 20*1000
- << 24*1000 << 25*1000 << 30*1000 << 50*1000 << 60*1000;
-
-
- //get the list of resolutions:
-
- for (quint32 format : qAsConst(supportedFormats)) {
- struct v4l2_frmsizeenum formatSize;
- memset(&formatSize, 0, sizeof(formatSize));
- formatSize.pixel_format = format;
-
- QList<QSize> sizeList;
-
- if (0) {
- char formatStr[5];
- memcpy(formatStr, &format, 4);
- formatStr[4] = 0;
- //qDebug() << "trying format" << formatStr;
- }
-
- for (int i=0;;i++) {
- formatSize.index = i;
- if (ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &formatSize) < 0)
- break;
-
- if (formatSize.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
- sizeList.append(QSize(formatSize.discrete.width, formatSize.discrete.height));
- } else {
-
- for (const QSize& candidate : qAsConst(commonSizes)) {
- if (candidate.width() <= (int)formatSize.stepwise.max_width &&
- candidate.height() >= (int)formatSize.stepwise.min_width &&
- candidate.width() % formatSize.stepwise.step_width == 0 &&
- candidate.height() <= (int)formatSize.stepwise.max_height &&
- candidate.height() >= (int)formatSize.stepwise.min_height &&
- candidate.height() % formatSize.stepwise.step_height == 0) {
- sizeList.append(candidate);
- }
- }
-
- if (!sizeList.contains(QSize(formatSize.stepwise.min_width, formatSize.stepwise.min_height)))
- sizeList.prepend(QSize(formatSize.stepwise.min_width, formatSize.stepwise.min_height));
-
- if (!sizeList.contains(QSize(formatSize.stepwise.max_width, formatSize.stepwise.max_height)))
- sizeList.append(QSize(formatSize.stepwise.max_width, formatSize.stepwise.max_height));
-
- break; //stepwise values are returned only for index 0
- }
-
- }
-
- //and frameRates for each resolution.
-
- for (const QSize &s : qAsConst(sizeList)) {
- allResolutions.insert(s);
-
- struct v4l2_frmivalenum formatInterval;
- memset(&formatInterval, 0, sizeof(formatInterval));
- formatInterval.pixel_format = format;
- formatInterval.width = s.width();
- formatInterval.height = s.height();
-
- QList<int> frameRates; //in 1/1000 of fps
-
- for (int i=0; ; i++) {
- formatInterval.index = i;
-
- if (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &formatInterval) < 0)
- break;
-
- if (formatInterval.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
- //converts seconds to fps*1000
- if (formatInterval.discrete.numerator)
- frameRates.append(qRound(formatInterval.discrete.denominator*1000.0 / formatInterval.discrete.numerator));
- } else {
- if (formatInterval.stepwise.min.numerator == 0 ||
- formatInterval.stepwise.max.numerator == 0) {
- qWarning() << "received invalid frame interval";
- break;
- }
-
-
- int minRate = qRound(formatInterval.stepwise.min.denominator*1000.0 /
- formatInterval.stepwise.min.numerator);
-
- int maxRate = qRound(formatInterval.stepwise.max.denominator*1000.0 /
- formatInterval.stepwise.max.numerator);
-
-
- for (int candidate : qAsConst(commonRates)) {
- if (candidate >= minRate && candidate <= maxRate)
- frameRates.append(candidate);
- }
-
- if (!frameRates.contains(minRate))
- frameRates.prepend(minRate);
-
- if (!frameRates.contains(maxRate))
- frameRates.append(maxRate);
-
- break; //stepwise values are returned only for index 0
- }
- }
- allFrameRates.unite(frameRates.toSet());
- m_ratesByResolution[s].unite(frameRates.toSet());
- }
- }
-
- f.close();
-
- for (int rate : qAsConst(allFrameRates)) {
- m_frameRates.append(rate/1000.0);
- }
-
- std::sort(m_frameRates.begin(), m_frameRates.end());
-
- m_resolutions = allResolutions.toList();
- std::sort(m_resolutions.begin(), m_resolutions.end());
-
- //qDebug() << "frame rates:" << m_frameRates;
- //qDebug() << "resolutions:" << m_resolutions;
-}
-
-
-QList<qreal> QGstreamerV4L2Input::supportedFrameRates(const QSize &frameSize) const
-{
- if (frameSize.isEmpty())
- return m_frameRates;
- else {
- QList<qreal> res;
- const auto rates = m_ratesByResolution[frameSize];
- res.reserve(rates.size());
- for (int rate : rates) {
- res.append(rate/1000.0);
- }
- return res;
- }
-}
-
-QList<QSize> QGstreamerV4L2Input::supportedResolutions(qreal frameRate) const
-{
- Q_UNUSED(frameRate);
- return m_resolutions;
-}
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.h b/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.h
deleted file mode 100644
index a82c7cf4b..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QGSTREAMERV4L2INPUT_H
-#define QGSTREAMERV4L2INPUT_H
-
-#include <QtCore/qhash.h>
-#include <QtCore/qbytearray.h>
-#include <QtCore/qlist.h>
-#include <QtCore/qsize.h>
-#include "qgstreamercapturesession.h"
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerV4L2Input : public QObject, public QGstreamerVideoInput
-{
- Q_OBJECT
-public:
- QGstreamerV4L2Input(QObject *parent = 0);
- virtual ~QGstreamerV4L2Input();
-
- GstElement *buildElement() override;
-
- QList<qreal> supportedFrameRates(const QSize &frameSize = QSize()) const override;
- QList<QSize> supportedResolutions(qreal frameRate = -1) const override;
-
- QByteArray device() const;
-
-public slots:
- void setDevice(const QByteArray &device);
- void setDevice(const QString &device);
-
-private:
- void updateSupportedResolutions(const QByteArray &device);
-
- QList<qreal> m_frameRates;
- QList<QSize> m_resolutions;
-
- QHash<QSize, QSet<int> > m_ratesByResolution;
-
- QByteArray m_device;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERV4L2INPUT_H
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.cpp b/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.cpp
deleted file mode 100644
index a2ed1d288..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.cpp
+++ /dev/null
@@ -1,296 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamervideoencode.h"
-#include "qgstreamercapturesession.h"
-#include "qgstreamermediacontainercontrol.h"
-#include <private/qgstutils_p.h>
-#include <QtCore/qdebug.h>
-
-#include <math.h>
-
-QGstreamerVideoEncode::QGstreamerVideoEncode(QGstreamerCaptureSession *session)
- :QVideoEncoderSettingsControl(session), m_session(session)
- , m_codecs(QGstCodecsInfo::VideoEncoder)
-{
-}
-
-QGstreamerVideoEncode::~QGstreamerVideoEncode()
-{
-}
-
-QList<QSize> QGstreamerVideoEncode::supportedResolutions(const QVideoEncoderSettings &, bool *continuous) const
-{
- if (continuous)
- *continuous = m_session->videoInput() != 0;
-
- return m_session->videoInput() ? m_session->videoInput()->supportedResolutions() : QList<QSize>();
-}
-
-QList< qreal > QGstreamerVideoEncode::supportedFrameRates(const QVideoEncoderSettings &, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- return m_session->videoInput() ? m_session->videoInput()->supportedFrameRates() : QList<qreal>();
-}
-
-QStringList QGstreamerVideoEncode::supportedVideoCodecs() const
-{
- return m_codecs.supportedCodecs();
-}
-
-QString QGstreamerVideoEncode::videoCodecDescription(const QString &codecName) const
-{
- return m_codecs.codecDescription(codecName);
-}
-
-QStringList QGstreamerVideoEncode::supportedEncodingOptions(const QString &codec) const
-{
- return m_codecs.codecOptions(codec);
-}
-
-QVariant QGstreamerVideoEncode::encodingOption(const QString &codec, const QString &name) const
-{
- return m_options[codec].value(name);
-}
-
-void QGstreamerVideoEncode::setEncodingOption(
- const QString &codec, const QString &name, const QVariant &value)
-{
- m_options[codec][name] = value;
-}
-
-QVideoEncoderSettings QGstreamerVideoEncode::videoSettings() const
-{
- return m_videoSettings;
-}
-
-void QGstreamerVideoEncode::setVideoSettings(const QVideoEncoderSettings &settings)
-{
- m_videoSettings = settings;
-}
-
-GstElement *QGstreamerVideoEncode::createEncoder()
-{
- QString codec = m_videoSettings.codec();
- GstElement *encoderElement = gst_element_factory_make(m_codecs.codecElement(codec).constData(), "video-encoder");
- if (!encoderElement)
- return 0;
-
- GstBin *encoderBin = GST_BIN(gst_bin_new("video-encoder-bin"));
-
- GstElement *sinkCapsFilter = gst_element_factory_make("capsfilter", "capsfilter-video");
- GstElement *srcCapsFilter = gst_element_factory_make("capsfilter", "capsfilter-video");
- gst_bin_add_many(encoderBin, sinkCapsFilter, srcCapsFilter, NULL);
-
- GstElement *colorspace = gst_element_factory_make(QT_GSTREAMER_COLORCONVERSION_ELEMENT_NAME, NULL);
- gst_bin_add(encoderBin, colorspace);
- gst_bin_add(encoderBin, encoderElement);
-
- gst_element_link_many(sinkCapsFilter, colorspace, encoderElement, srcCapsFilter, NULL);
-
- // add ghostpads
- GstPad *pad = gst_element_get_static_pad(sinkCapsFilter, "sink");
- gst_element_add_pad(GST_ELEMENT(encoderBin), gst_ghost_pad_new("sink", pad));
- gst_object_unref(GST_OBJECT(pad));
-
- pad = gst_element_get_static_pad(srcCapsFilter, "src");
- gst_element_add_pad(GST_ELEMENT(encoderBin), gst_ghost_pad_new("src", pad));
- gst_object_unref(GST_OBJECT(pad));
-
- if (encoderElement) {
- if (m_videoSettings.encodingMode() == QMultimedia::ConstantQualityEncoding) {
- QMultimedia::EncodingQuality qualityValue = m_videoSettings.quality();
-
- if (codec == QLatin1String("video/x-h264")) {
- //constant quantizer mode
- g_object_set(G_OBJECT(encoderElement), "pass", 4, NULL);
- int qualityTable[] = {
- 50, //VeryLow
- 35, //Low
- 21, //Normal
- 15, //High
- 8 //VeryHigh
- };
- g_object_set(G_OBJECT(encoderElement), "quantizer", qualityTable[qualityValue], NULL);
- } else if (codec == QLatin1String("video/x-xvid")) {
- //constant quantizer mode
- g_object_set(G_OBJECT(encoderElement), "pass", 3, NULL);
- int qualityTable[] = {
- 32, //VeryLow
- 12, //Low
- 5, //Normal
- 3, //High
- 2 //VeryHigh
- };
- int quant = qualityTable[qualityValue];
- g_object_set(G_OBJECT(encoderElement), "quantizer", quant, NULL);
- } else if (codec.startsWith(QLatin1String("video/mpeg"))) {
- //constant quantizer mode
- g_object_set(G_OBJECT(encoderElement), "pass", 2, NULL);
- //quant from 1 to 30, default ~3
- double qualityTable[] = {
- 20, //VeryLow
- 8.0, //Low
- 3.0, //Normal
- 2.5, //High
- 2.0 //VeryHigh
- };
- double quant = qualityTable[qualityValue];
- g_object_set(G_OBJECT(encoderElement), "quantizer", quant, NULL);
- } else if (codec == QLatin1String("video/x-theora")) {
- int qualityTable[] = {
- 8, //VeryLow
- 16, //Low
- 32, //Normal
- 45, //High
- 60 //VeryHigh
- };
- //quality from 0 to 63
- int quality = qualityTable[qualityValue];
- g_object_set(G_OBJECT(encoderElement), "quality", quality, NULL);
- }
- } else {
- int bitrate = m_videoSettings.bitRate();
- if (bitrate > 0) {
- g_object_set(G_OBJECT(encoderElement), "bitrate", bitrate, NULL);
- }
- }
-
- QMap<QString,QVariant> options = m_options.value(codec);
- for (auto it = options.cbegin(), end = options.cend(); it != end; ++it) {
- const QString &option = it.key();
- const QVariant &value = it.value();
-
- switch (value.type()) {
- case QVariant::Int:
- g_object_set(G_OBJECT(encoderElement), option.toLatin1(), value.toInt(), NULL);
- break;
- case QVariant::Bool:
- g_object_set(G_OBJECT(encoderElement), option.toLatin1(), value.toBool(), NULL);
- break;
- case QVariant::Double:
- g_object_set(G_OBJECT(encoderElement), option.toLatin1(), value.toDouble(), NULL);
- break;
- case QVariant::String:
- g_object_set(G_OBJECT(encoderElement), option.toLatin1(), value.toString().toUtf8().constData(), NULL);
- break;
- default:
- qWarning() << "unsupported option type:" << option << value;
- break;
- }
-
- }
- }
-
- if (!m_videoSettings.resolution().isEmpty() || m_videoSettings.frameRate() > 0.001) {
- GstCaps *caps = QGstUtils::videoFilterCaps();
-
- if (!m_videoSettings.resolution().isEmpty()) {
- gst_caps_set_simple(
- caps,
- "width", G_TYPE_INT, m_videoSettings.resolution().width(),
- "height", G_TYPE_INT, m_videoSettings.resolution().height(),
- NULL);
- }
-
- if (m_videoSettings.frameRate() > 0.001) {
- QPair<int,int> rate = rateAsRational();
- gst_caps_set_simple(
- caps,
- "framerate", GST_TYPE_FRACTION, rate.first, rate.second,
- NULL);
- }
-
- //qDebug() << "set video caps filter:" << gst_caps_to_string(caps);
-
- g_object_set(G_OBJECT(sinkCapsFilter), "caps", caps, NULL);
-
- gst_caps_unref(caps);
- }
-
- // Some encoders support several codecs. Setting a caps filter downstream with the desired
- // codec (which is actually a string representation of the caps) will make sure we use the
- // correct codec.
- GstCaps *caps = gst_caps_from_string(codec.toUtf8().constData());
- g_object_set(G_OBJECT(srcCapsFilter), "caps", caps, NULL);
- gst_caps_unref(caps);
-
- return GST_ELEMENT(encoderBin);
-}
-
-QPair<int,int> QGstreamerVideoEncode::rateAsRational() const
-{
- qreal frameRate = m_videoSettings.frameRate();
-
- if (frameRate > 0.001) {
- //convert to rational number
- QList<int> denumCandidates;
- denumCandidates << 1 << 2 << 3 << 5 << 10 << 1001 << 1000;
-
- qreal error = 1.0;
- int num = 1;
- int denum = 1;
-
- for (int curDenum : qAsConst(denumCandidates)) {
- int curNum = qRound(frameRate*curDenum);
- qreal curError = qAbs(qreal(curNum)/curDenum - frameRate);
-
- if (curError < error) {
- error = curError;
- num = curNum;
- denum = curDenum;
- }
-
- if (curError < 1e-8)
- break;
- }
-
- return QPair<int,int>(num,denum);
- }
-
- return QPair<int,int>();
-}
-
-
-QSet<QString> QGstreamerVideoEncode::supportedStreamTypes(const QString &codecName) const
-{
- return m_codecs.supportedStreamTypes(codecName);
-}
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.h b/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.h
deleted file mode 100644
index a35e2b456..000000000
--- a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERVIDEOENCODE_H
-#define QGSTREAMERVIDEOENCODE_H
-
-#include <qvideoencodersettingscontrol.h>
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmap.h>
-#include <QtCore/qset.h>
-
-#include <private/qgstcodecsinfo_p.h>
-
-#include <gst/gst.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerCaptureSession;
-
-class QGstreamerVideoEncode : public QVideoEncoderSettingsControl
-{
- Q_OBJECT
-public:
- QGstreamerVideoEncode(QGstreamerCaptureSession *session);
- virtual ~QGstreamerVideoEncode();
-
- QList<QSize> supportedResolutions(const QVideoEncoderSettings &settings = QVideoEncoderSettings(),
- bool *continuous = 0) const override;
-
- QList< qreal > supportedFrameRates(const QVideoEncoderSettings &settings = QVideoEncoderSettings(),
- bool *continuous = 0) const override;
-
- QPair<int,int> rateAsRational() const;
-
- QStringList supportedVideoCodecs() const override;
- QString videoCodecDescription(const QString &codecName) const override;
-
- QVideoEncoderSettings videoSettings() const override;
- void setVideoSettings(const QVideoEncoderSettings &settings) override;
-
- QStringList supportedEncodingOptions(const QString &codec) const;
- QVariant encodingOption(const QString &codec, const QString &name) const;
- void setEncodingOption(const QString &codec, const QString &name, const QVariant &value);
-
- GstElement *createEncoder();
-
- QSet<QString> supportedStreamTypes(const QString &codecName) const;
-
-private:
- QGstreamerCaptureSession *m_session;
-
- QGstCodecsInfo m_codecs;
-
- QVideoEncoderSettings m_videoSettings;
- QMap<QString, QMap<QString, QVariant> > m_options;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/mediaplayer/mediaplayer.json b/src/plugins/gstreamer/mediaplayer/mediaplayer.json
deleted file mode 100644
index bd1a7e64d..000000000
--- a/src/plugins/gstreamer/mediaplayer/mediaplayer.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["gstreamermediaplayer"],
- "Services": ["org.qt-project.qt.mediaplayer"]
-}
diff --git a/src/plugins/gstreamer/mediaplayer/mediaplayer.pro b/src/plugins/gstreamer/mediaplayer/mediaplayer.pro
deleted file mode 100644
index 8150d8f5b..000000000
--- a/src/plugins/gstreamer/mediaplayer/mediaplayer.pro
+++ /dev/null
@@ -1,26 +0,0 @@
-TARGET = gstmediaplayer
-
-include(../common.pri)
-
-INCLUDEPATH += $$PWD
-
-HEADERS += \
- $$PWD/qgstreamerplayerservice.h \
- $$PWD/qgstreamerstreamscontrol.h \
- $$PWD/qgstreamermetadataprovider.h \
- $$PWD/qgstreameravailabilitycontrol.h \
- $$PWD/qgstreamerplayerserviceplugin.h
-
-SOURCES += \
- $$PWD/qgstreamerplayerservice.cpp \
- $$PWD/qgstreamerstreamscontrol.cpp \
- $$PWD/qgstreamermetadataprovider.cpp \
- $$PWD/qgstreameravailabilitycontrol.cpp \
- $$PWD/qgstreamerplayerserviceplugin.cpp
-
-OTHER_FILES += \
- mediaplayer.json
-
-PLUGIN_TYPE = mediaservice
-PLUGIN_CLASS_NAME = QGstreamerPlayerServicePlugin
-load(qt_plugin)
diff --git a/src/plugins/gstreamer/mediaplayer/qgstreameravailabilitycontrol.cpp b/src/plugins/gstreamer/mediaplayer/qgstreameravailabilitycontrol.cpp
deleted file mode 100644
index d2bfbb03a..000000000
--- a/src/plugins/gstreamer/mediaplayer/qgstreameravailabilitycontrol.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreameravailabilitycontrol.h"
-#include <private/qmediaresourceset_p.h>
-
-QT_BEGIN_NAMESPACE
-
-QGStreamerAvailabilityControl::QGStreamerAvailabilityControl(
- QMediaPlayerResourceSetInterface *resources, QObject *parent)
- : QMediaAvailabilityControl(parent)
- , m_resources(resources)
-{
- Q_ASSERT(m_resources);
- connect(m_resources, SIGNAL(availabilityChanged(bool)), this, SLOT(handleAvailabilityChanged()));
-}
-
-void QGStreamerAvailabilityControl::handleAvailabilityChanged()
-{
- emit availabilityChanged(this->availability());
-}
-
-QMultimedia::AvailabilityStatus QGStreamerAvailabilityControl::availability() const
-{
- return m_resources->isAvailable() ? QMultimedia::Available : QMultimedia::Busy;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/mediaplayer/qgstreameravailabilitycontrol.h b/src/plugins/gstreamer/mediaplayer/qgstreameravailabilitycontrol.h
deleted file mode 100644
index e100fccc8..000000000
--- a/src/plugins/gstreamer/mediaplayer/qgstreameravailabilitycontrol.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERAVAILABILITYCONTROL_H
-#define QGSTREAMERAVAILABILITYCONTROL_H
-
-#include <QObject>
-#include <qmediaavailabilitycontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QMediaPlayerResourceSetInterface;
-class QGStreamerAvailabilityControl : public QMediaAvailabilityControl
-{
- Q_OBJECT
-public:
- QGStreamerAvailabilityControl(QMediaPlayerResourceSetInterface *resources, QObject *parent = 0);
- QMultimedia::AvailabilityStatus availability() const override;
-
-private Q_SLOTS:
- void handleAvailabilityChanged();
-
-private:
- QMediaPlayerResourceSetInterface *m_resources = nullptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERAVAILABILITYCONTROL_H
diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp
deleted file mode 100644
index bd503d3a1..000000000
--- a/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamermetadataprovider.h"
-#include <private/qgstreamerplayersession_p.h>
-#include <QDebug>
-#include <QtMultimedia/qmediametadata.h>
-
-#include <gst/gstversion.h>
-#include <private/qgstutils_p.h>
-
-QT_BEGIN_NAMESPACE
-
-typedef QMap<QByteArray, QString> QGstreamerMetaDataKeyLookup;
-Q_GLOBAL_STATIC(QGstreamerMetaDataKeyLookup, metadataKeys)
-
-static const QGstreamerMetaDataKeyLookup *qt_gstreamerMetaDataKeys()
-{
- if (metadataKeys->isEmpty()) {
- metadataKeys->insert(GST_TAG_TITLE, QMediaMetaData::Title);
- //metadataKeys->insert(0, QMediaMetaData::SubTitle);
- //metadataKeys->insert(0, QMediaMetaData::Author);
- metadataKeys->insert(GST_TAG_COMMENT, QMediaMetaData::Comment);
- metadataKeys->insert(GST_TAG_DESCRIPTION, QMediaMetaData::Description);
- //metadataKeys->insert(0, QMediaMetaData::Category);
- metadataKeys->insert(GST_TAG_GENRE, QMediaMetaData::Genre);
- metadataKeys->insert("year", QMediaMetaData::Year);
- //metadataKeys->insert(0, QMediaMetaData::UserRating);
-
- metadataKeys->insert(GST_TAG_LANGUAGE_CODE, QMediaMetaData::Language);
-
- metadataKeys->insert(GST_TAG_ORGANIZATION, QMediaMetaData::Publisher);
- metadataKeys->insert(GST_TAG_COPYRIGHT, QMediaMetaData::Copyright);
- //metadataKeys->insert(0, QMediaMetaData::ParentalRating);
- //metadataKeys->insert(0, QMediaMetaData::RatingOrganisation);
-
- // Media
- //metadataKeys->insert(0, QMediaMetaData::Size);
- //metadataKeys->insert(0,QMediaMetaData::MediaType );
- metadataKeys->insert(GST_TAG_DURATION, QMediaMetaData::Duration);
-
- // Audio
- metadataKeys->insert(GST_TAG_BITRATE, QMediaMetaData::AudioBitRate);
- metadataKeys->insert(GST_TAG_AUDIO_CODEC, QMediaMetaData::AudioCodec);
- //metadataKeys->insert(0, QMediaMetaData::ChannelCount);
- //metadataKeys->insert(0, QMediaMetaData::SampleRate);
-
- // Music
- metadataKeys->insert(GST_TAG_ALBUM, QMediaMetaData::AlbumTitle);
-#if GST_CHECK_VERSION(0, 10, 25)
- metadataKeys->insert(GST_TAG_ALBUM_ARTIST, QMediaMetaData::AlbumArtist);
-#endif
- metadataKeys->insert(GST_TAG_ARTIST, QMediaMetaData::ContributingArtist);
- //metadataKeys->insert(0, QMediaMetaData::Conductor);
- //metadataKeys->insert(0, QMediaMetaData::Lyrics);
- //metadataKeys->insert(0, QMediaMetaData::Mood);
- metadataKeys->insert(GST_TAG_TRACK_NUMBER, QMediaMetaData::TrackNumber);
-
- //metadataKeys->insert(0, QMediaMetaData::CoverArtUrlSmall);
- //metadataKeys->insert(0, QMediaMetaData::CoverArtUrlLarge);
- metadataKeys->insert(GST_TAG_PREVIEW_IMAGE, QMediaMetaData::ThumbnailImage);
- metadataKeys->insert(GST_TAG_IMAGE, QMediaMetaData::CoverArtImage);
-
- // Image/Video
- metadataKeys->insert("resolution", QMediaMetaData::Resolution);
- metadataKeys->insert("pixel-aspect-ratio", QMediaMetaData::PixelAspectRatio);
-#if GST_CHECK_VERSION(0,10,30)
- metadataKeys->insert(GST_TAG_IMAGE_ORIENTATION, QMediaMetaData::Orientation);
-#endif
-
- // Video
- //metadataKeys->insert(0, QMediaMetaData::VideoFrameRate);
- //metadataKeys->insert(0, QMediaMetaData::VideoBitRate);
- metadataKeys->insert(GST_TAG_VIDEO_CODEC, QMediaMetaData::VideoCodec);
-
- //metadataKeys->insert(0, QMediaMetaData::PosterUrl);
-
- // Movie
- //metadataKeys->insert(0, QMediaMetaData::ChapterNumber);
- //metadataKeys->insert(0, QMediaMetaData::Director);
- metadataKeys->insert(GST_TAG_PERFORMER, QMediaMetaData::LeadPerformer);
- //metadataKeys->insert(0, QMediaMetaData::Writer);
-
- // Photos
- //metadataKeys->insert(0, QMediaMetaData::CameraManufacturer);
- //metadataKeys->insert(0, QMediaMetaData::CameraModel);
- //metadataKeys->insert(0, QMediaMetaData::Event);
- //metadataKeys->insert(0, QMediaMetaData::Subject);
- }
-
- return metadataKeys;
-}
-
-QGstreamerMetaDataProvider::QGstreamerMetaDataProvider(QGstreamerPlayerSession *session, QObject *parent)
- :QMetaDataReaderControl(parent), m_session(session)
-{
- connect(m_session, SIGNAL(tagsChanged()), SLOT(updateTags()));
-}
-
-QGstreamerMetaDataProvider::~QGstreamerMetaDataProvider()
-{
-}
-
-bool QGstreamerMetaDataProvider::isMetaDataAvailable() const
-{
- return !m_session->tags().isEmpty();
-}
-
-bool QGstreamerMetaDataProvider::isWritable() const
-{
- return false;
-}
-
-QVariant QGstreamerMetaDataProvider::metaData(const QString &key) const
-{
-#if GST_CHECK_VERSION(0,10,30)
- if (key == QMediaMetaData::Orientation)
- return QGstUtils::fromGStreamerOrientation(m_tags.value(key));
-#endif
- return m_tags.value(key);
-}
-
-QStringList QGstreamerMetaDataProvider::availableMetaData() const
-{
- return m_tags.keys();
-}
-
-void QGstreamerMetaDataProvider::updateTags()
-{
- QVariantMap oldTags = m_tags;
- m_tags.clear();
- bool changed = false;
-
- const auto tags = m_session->tags();
- for (auto i = tags.cbegin(), end = tags.cend(); i != end; ++i) {
- //use gstreamer native keys for elements not in our key map
- QString key = qt_gstreamerMetaDataKeys()->value(i.key(), i.key());
- m_tags.insert(key, i.value());
- if (i.value() != oldTags.value(key)) {
- changed = true;
- emit metaDataChanged(key, i.value());
- }
- }
-
- if (oldTags.isEmpty() != m_tags.isEmpty()) {
- emit metaDataAvailableChanged(isMetaDataAvailable());
- changed = true;
- }
-
- if (changed)
- emit metaDataChanged();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.h b/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.h
deleted file mode 100644
index 691453a42..000000000
--- a/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERMETADATAPROVIDER_H
-#define QGSTREAMERMETADATAPROVIDER_H
-
-#include <qmetadatareadercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerPlayerSession;
-
-class QGstreamerMetaDataProvider : public QMetaDataReaderControl
-{
- Q_OBJECT
-public:
- QGstreamerMetaDataProvider( QGstreamerPlayerSession *session, QObject *parent );
- virtual ~QGstreamerMetaDataProvider();
-
- bool isMetaDataAvailable() const override;
- bool isWritable() const;
-
- QVariant metaData(const QString &key) const override;
- QStringList availableMetaData() const override;
-
-private slots:
- void updateTags();
-
-private:
- QGstreamerPlayerSession *m_session = nullptr;
- QVariantMap m_tags;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERMETADATAPROVIDER_H
diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp
deleted file mode 100644
index 4bf4a0a57..000000000
--- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <QtCore/qvariant.h>
-#include <QtCore/qdebug.h>
-
-#if defined(HAVE_WIDGETS)
-#include <QtWidgets/qwidget.h>
-#endif
-
-#include "qgstreamerplayerservice.h"
-#include "qgstreamermetadataprovider.h"
-#include "qgstreameravailabilitycontrol.h"
-
-#if defined(HAVE_WIDGETS)
-#include <private/qgstreamervideowidget_p.h>
-#endif
-#include <private/qgstreamervideowindow_p.h>
-#include <private/qgstreamervideorenderer_p.h>
-
-#include "qgstreamerstreamscontrol.h"
-#include <private/qgstreameraudioprobecontrol_p.h>
-#include <private/qgstreamervideoprobecontrol_p.h>
-#include <private/qgstreamerplayersession_p.h>
-#include <private/qgstreamerplayercontrol_p.h>
-
-#include <private/qmediaplaylistnavigator_p.h>
-#include <qmediaplaylist.h>
-#include <private/qmediaresourceset_p.h>
-
-QT_BEGIN_NAMESPACE
-
-QGstreamerPlayerService::QGstreamerPlayerService(QObject *parent)
- : QMediaService(parent)
-{
- m_session = new QGstreamerPlayerSession(this);
- m_control = new QGstreamerPlayerControl(m_session, this);
- m_metaData = new QGstreamerMetaDataProvider(m_session, this);
- m_streamsControl = new QGstreamerStreamsControl(m_session,this);
- m_availabilityControl = new QGStreamerAvailabilityControl(m_control->resources(), this);
- m_videoRenderer = new QGstreamerVideoRenderer(this);
- m_videoWindow = new QGstreamerVideoWindow(this);
- // If the GStreamer video sink is not available, don't provide the video window control since
- // it won't work anyway.
- if (!m_videoWindow->videoSink()) {
- delete m_videoWindow;
- m_videoWindow = 0;
- }
-
-#if defined(HAVE_WIDGETS)
- m_videoWidget = new QGstreamerVideoWidgetControl(this);
-
- // If the GStreamer video sink is not available, don't provide the video widget control since
- // it won't work anyway.
- // QVideoWidget will fall back to QVideoRendererControl in that case.
- if (!m_videoWidget->videoSink()) {
- delete m_videoWidget;
- m_videoWidget = 0;
- }
-#endif
-}
-
-QGstreamerPlayerService::~QGstreamerPlayerService()
-{
-}
-
-QMediaControl *QGstreamerPlayerService::requestControl(const char *name)
-{
- if (qstrcmp(name,QMediaPlayerControl_iid) == 0)
- return m_control;
-
- if (qstrcmp(name,QMetaDataReaderControl_iid) == 0)
- return m_metaData;
-
- if (qstrcmp(name,QMediaStreamsControl_iid) == 0)
- return m_streamsControl;
-
- if (qstrcmp(name, QMediaAvailabilityControl_iid) == 0)
- return m_availabilityControl;
-
- if (qstrcmp(name, QMediaVideoProbeControl_iid) == 0) {
- if (!m_videoProbeControl) {
- increaseVideoRef();
- m_videoProbeControl = new QGstreamerVideoProbeControl(this);
- m_session->addProbe(m_videoProbeControl);
- }
- m_videoProbeControl->ref.ref();
- return m_videoProbeControl;
- }
-
- if (qstrcmp(name, QMediaAudioProbeControl_iid) == 0) {
- if (!m_audioProbeControl) {
- m_audioProbeControl = new QGstreamerAudioProbeControl(this);
- m_session->addProbe(m_audioProbeControl);
- }
- m_audioProbeControl->ref.ref();
- return m_audioProbeControl;
- }
-
- if (!m_videoOutput) {
- if (qstrcmp(name, QVideoRendererControl_iid) == 0)
- m_videoOutput = m_videoRenderer;
- else if (qstrcmp(name, QVideoWindowControl_iid) == 0)
- m_videoOutput = m_videoWindow;
-#if defined(HAVE_WIDGETS)
- else if (qstrcmp(name, QVideoWidgetControl_iid) == 0)
- m_videoOutput = m_videoWidget;
-#endif
-
- if (m_videoOutput) {
- increaseVideoRef();
- m_control->setVideoOutput(m_videoOutput);
- return m_videoOutput;
- }
- }
-
- return 0;
-}
-
-void QGstreamerPlayerService::releaseControl(QMediaControl *control)
-{
- if (!control) {
- return;
- } else if (control == m_videoOutput) {
- m_videoOutput = 0;
- m_control->setVideoOutput(0);
- decreaseVideoRef();
- } else if (control == m_videoProbeControl && !m_videoProbeControl->ref.deref()) {
- m_session->removeProbe(m_videoProbeControl);
- delete m_videoProbeControl;
- m_videoProbeControl = 0;
- decreaseVideoRef();
- } else if (control == m_audioProbeControl && !m_audioProbeControl->ref.deref()) {
- m_session->removeProbe(m_audioProbeControl);
- delete m_audioProbeControl;
- m_audioProbeControl = 0;
- }
-}
-
-void QGstreamerPlayerService::increaseVideoRef()
-{
- m_videoReferenceCount++;
- if (m_videoReferenceCount == 1) {
- m_control->resources()->setVideoEnabled(true);
- }
-}
-
-void QGstreamerPlayerService::decreaseVideoRef()
-{
- m_videoReferenceCount--;
- if (m_videoReferenceCount == 0) {
- m_control->resources()->setVideoEnabled(false);
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h b/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h
deleted file mode 100644
index f88f0ae38..000000000
--- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERPLAYERSERVICE_H
-#define QGSTREAMERPLAYERSERVICE_H
-
-#include <QtCore/qobject.h>
-#include <QtCore/qiodevice.h>
-
-#include <qmediaservice.h>
-
-QT_BEGIN_NAMESPACE
-class QMediaPlayerControl;
-class QMediaPlaylist;
-class QMediaPlaylistNavigator;
-
-class QGstreamerMetaData;
-class QGstreamerPlayerControl;
-class QGstreamerPlayerSession;
-class QGstreamerMetaDataProvider;
-class QGstreamerStreamsControl;
-class QGstreamerVideoRenderer;
-class QGstreamerVideoWindow;
-class QGstreamerVideoWidgetControl;
-class QGStreamerAvailabilityControl;
-class QGstreamerAudioProbeControl;
-class QGstreamerVideoProbeControl;
-
-class QGstreamerPlayerService : public QMediaService
-{
- Q_OBJECT
-public:
- QGstreamerPlayerService(QObject *parent = 0);
- ~QGstreamerPlayerService();
-
- QMediaControl *requestControl(const char *name) override;
- void releaseControl(QMediaControl *control) override;
-
-private:
- QGstreamerPlayerControl *m_control = nullptr;
- QGstreamerPlayerSession *m_session = nullptr;
- QGstreamerMetaDataProvider *m_metaData = nullptr;
- QGstreamerStreamsControl *m_streamsControl = nullptr;
- QGStreamerAvailabilityControl *m_availabilityControl = nullptr;
-
- QGstreamerAudioProbeControl *m_audioProbeControl = nullptr;
- QGstreamerVideoProbeControl *m_videoProbeControl = nullptr;
-
- QMediaControl *m_videoOutput = nullptr;
- QMediaControl *m_videoRenderer = nullptr;
- QGstreamerVideoWindow *m_videoWindow = nullptr;
-#if defined(HAVE_WIDGETS)
- QGstreamerVideoWidgetControl *m_videoWidget = nullptr;
-#endif
-
- void increaseVideoRef();
- void decreaseVideoRef();
- int m_videoReferenceCount = 0;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerserviceplugin.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamerplayerserviceplugin.cpp
deleted file mode 100644
index db266a10e..000000000
--- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerserviceplugin.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/QDir>
-#include <QtCore/QDebug>
-
-#include "qgstreamerplayerserviceplugin.h"
-
-//#define QT_SUPPORTEDMIMETYPES_DEBUG
-
-#include "qgstreamerplayerservice.h"
-#include <private/qgstutils_p.h>
-
-QMediaService* QGstreamerPlayerServicePlugin::create(const QString &key)
-{
- QGstUtils::initializeGst();
-
- if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER))
- return new QGstreamerPlayerService;
-
- qWarning() << "Gstreamer service plugin: unsupported key:" << key;
- return 0;
-}
-
-void QGstreamerPlayerServicePlugin::release(QMediaService *service)
-{
- delete service;
-}
-
-QMediaServiceProviderHint::Features QGstreamerPlayerServicePlugin::supportedFeatures(
- const QByteArray &service) const
-{
- if (service == Q_MEDIASERVICE_MEDIAPLAYER)
- return
-#if QT_CONFIG(gstreamer_app)
- QMediaServiceProviderHint::StreamPlayback |
-#endif
- QMediaServiceProviderHint::VideoSurface;
- else
- return QMediaServiceProviderHint::Features();
-}
-
-QMultimedia::SupportEstimate QGstreamerPlayerServicePlugin::hasSupport(const QString &mimeType,
- const QStringList &codecs) const
-{
- if (m_supportedMimeTypeSet.isEmpty())
- updateSupportedMimeTypes();
-
- return QGstUtils::hasSupport(mimeType, codecs, m_supportedMimeTypeSet);
-}
-
-static bool isDecoderOrDemuxer(GstElementFactory *factory)
-{
-#if GST_CHECK_VERSION(0, 10 ,31)
- return gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_DEMUXER)
- || gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_DECODER);
-#else
- return (factory
- && (qstrcmp(factory->details.klass, "Codec/Decoder/Audio") == 0
- || qstrcmp(factory->details.klass, "Codec/Decoder/Video") == 0
- || qstrcmp(factory->details.klass, "Codec/Demux") == 0 ));
-#endif
-}
-
-void QGstreamerPlayerServicePlugin::updateSupportedMimeTypes() const
-{
- m_supportedMimeTypeSet = QGstUtils::supportedMimeTypes(isDecoderOrDemuxer);
-}
-
-QStringList QGstreamerPlayerServicePlugin::supportedMimeTypes() const
-{
- return QStringList();
-}
-
diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerserviceplugin.h b/src/plugins/gstreamer/mediaplayer/qgstreamerplayerserviceplugin.h
deleted file mode 100644
index 71eece23e..000000000
--- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerserviceplugin.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef QGSTREAMERPLAYERSERVICEPLUGIN_H
-#define QGSTREAMERPLAYERSERVICEPLUGIN_H
-
-#include <qmediaserviceproviderplugin.h>
-#include <QtCore/qset.h>
-#include <QtCore/QObject>
-
-QT_BEGIN_NAMESPACE
-
-
-class QGstreamerPlayerServicePlugin
- : public QMediaServiceProviderPlugin
- , public QMediaServiceFeaturesInterface
- , public QMediaServiceSupportedFormatsInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaServiceFeaturesInterface)
- Q_INTERFACES(QMediaServiceSupportedFormatsInterface)
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "mediaplayer.json")
-public:
- QMediaService* create(const QString &key) override;
- void release(QMediaService *service) override;
-
- QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const override;
-
- QMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList &codecs) const override;
- QStringList supportedMimeTypes() const override;
-
-private:
- void updateSupportedMimeTypes() const;
-
- mutable QSet<QString> m_supportedMimeTypeSet; //for fast access
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERPLAYERSERVICEPLUGIN_H
-
diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.cpp
deleted file mode 100644
index 4f5c3f0b2..000000000
--- a/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgstreamerstreamscontrol.h"
-#include <private/qgstreamerplayersession_p.h>
-
-QGstreamerStreamsControl::QGstreamerStreamsControl(QGstreamerPlayerSession *session, QObject *parent)
- :QMediaStreamsControl(parent), m_session(session)
-{
- connect(m_session, SIGNAL(streamsChanged()), SIGNAL(streamsChanged()));
-}
-
-QGstreamerStreamsControl::~QGstreamerStreamsControl()
-{
-}
-
-int QGstreamerStreamsControl::streamCount()
-{
- return m_session->streamCount();
-}
-
-QMediaStreamsControl::StreamType QGstreamerStreamsControl::streamType(int streamNumber)
-{
- return m_session->streamType(streamNumber);
-}
-
-QVariant QGstreamerStreamsControl::metaData(int streamNumber, const QString &key)
-{
- return m_session->streamProperties(streamNumber).value(key);
-}
-
-bool QGstreamerStreamsControl::isActive(int streamNumber)
-{
- return streamNumber != -1 && streamNumber == m_session->activeStream(streamType(streamNumber));
-}
-
-void QGstreamerStreamsControl::setActive(int streamNumber, bool state)
-{
- QMediaStreamsControl::StreamType type = m_session->streamType(streamNumber);
- if (type == QMediaStreamsControl::UnknownStream)
- return;
-
- if (state)
- m_session->setActiveStream(type, streamNumber);
- else {
- //only one active stream of certain type is supported
- if (m_session->activeStream(type) == streamNumber)
- m_session->setActiveStream(type, -1);
- }
-}
-
diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.h b/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.h
deleted file mode 100644
index 41932095c..000000000
--- a/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGSTREAMERSTREAMSCONTROL_H
-#define QGSTREAMERSTREAMSCONTROL_H
-
-#include <qmediastreamscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class QGstreamerPlayerSession;
-
-class QGstreamerStreamsControl : public QMediaStreamsControl
-{
- Q_OBJECT
-public:
- QGstreamerStreamsControl(QGstreamerPlayerSession *session, QObject *parent);
- virtual ~QGstreamerStreamsControl();
-
- int streamCount() override;
- StreamType streamType(int streamNumber) override;
-
- QVariant metaData(int streamNumber, const QString &key) override;
-
- bool isActive(int streamNumber) override;
- void setActive(int streamNumber, bool state) override;
-
-private:
- QGstreamerPlayerSession *m_session = nullptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGSTREAMERSTREAMSCONTROL_H
-
diff --git a/src/plugins/m3u/m3u.json b/src/plugins/m3u/m3u.json
deleted file mode 100644
index 2d69fab8e..000000000
--- a/src/plugins/m3u/m3u.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": ["m3u"]
-}
diff --git a/src/plugins/m3u/m3u.pro b/src/plugins/m3u/m3u.pro
deleted file mode 100644
index d46911e0d..000000000
--- a/src/plugins/m3u/m3u.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-TARGET = qtmultimedia_m3u
-QT += multimedia-private
-
-HEADERS += qm3uhandler.h
-SOURCES += qm3uhandler.cpp
-
-OTHER_FILES += \
- m3u.json
-
-PLUGIN_TYPE = playlistformats
-PLUGIN_CLASS_NAME = QM3uPlaylistPlugin
-load(qt_plugin)
diff --git a/src/plugins/m3u/qm3uhandler.cpp b/src/plugins/m3u/qm3uhandler.cpp
deleted file mode 100644
index b88e3e292..000000000
--- a/src/plugins/m3u/qm3uhandler.cpp
+++ /dev/null
@@ -1,229 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qm3uhandler.h"
-#include <QtCore/qiodevice.h>
-#include <QtCore/qfileinfo.h>
-#include <QtCore/qtextstream.h>
-#include <QFile>
-#include <QUrl>
-
-
-class QM3uPlaylistReader : public QMediaPlaylistReader
-{
-public:
- QM3uPlaylistReader(QIODevice *device)
- :m_ownDevice(false), m_device(device), m_textStream(new QTextStream(m_device))
- {
- readItem();
- }
-
- QM3uPlaylistReader(const QUrl& location)
- :m_location(location), m_ownDevice(true)
- {
- QFile *f = new QFile(location.toLocalFile());
- if (f->open(QIODevice::ReadOnly | QIODevice::Text)) {
- m_device = f;
- m_textStream = new QTextStream(m_device);
- readItem();
- } else {
- delete f;
- m_device = 0;
- m_textStream = 0;
- }
- }
-
- virtual ~QM3uPlaylistReader()
- {
- if (m_ownDevice) {
- delete m_device;
- }
- delete m_textStream;
- }
-
- bool atEnd() const override
- {
- //we can't just use m_textStream->atEnd(),
- //for files with empty lines/comments at end
- return nextResource.isNull();
- }
-
- QMediaContent readItem() override
- {
- QMediaContent item;
- if (!nextResource.isNull())
- item = QMediaContent(nextResource);
-
- nextResource = QMediaContent();
-
- while (m_textStream && !m_textStream->atEnd()) {
- QString line = m_textStream->readLine().trimmed();
- if (line.isEmpty() || line[0] == '#' || line.size() > 4096)
- continue;
-
- QUrl fileUrl = QUrl::fromLocalFile(line);
- QUrl url(line);
-
- //m3u may contain url encoded entries or absolute/relative file names
- //prefer existing file if any
- QList<QUrl> candidates;
- if (!m_location.isEmpty()) {
- candidates << m_location.resolved(fileUrl);
- candidates << m_location.resolved(url);
- }
- candidates << fileUrl;
- candidates << url;
-
- for (const QUrl &candidate : qAsConst(candidates)) {
- if (QFile::exists(candidate.toLocalFile())) {
- nextResource = candidate;
- break;
- }
- }
-
- if (nextResource.isNull()) {
- //assume the relative urls are file names, not encoded urls if m3u is local file
- if (!m_location.isEmpty() && url.isRelative()) {
- if (m_location.scheme() == QLatin1String("file"))
- nextResource = m_location.resolved(fileUrl);
- else
- nextResource = m_location.resolved(url);
- } else {
- nextResource = QMediaContent(QUrl::fromUserInput(line));
- }
- }
-
- break;
- }
-
- return item;
- }
-
- void close() override
- {
- }
-
-private:
- QUrl m_location;
- bool m_ownDevice;
- QIODevice *m_device;
- QTextStream *m_textStream;
- QMediaContent nextResource;
-};
-
-class QM3uPlaylistWriter : public QMediaPlaylistWriter
-{
-public:
- QM3uPlaylistWriter(QIODevice *device)
- :m_device(device), m_textStream(new QTextStream(m_device))
- {
- }
-
- virtual ~QM3uPlaylistWriter()
- {
- delete m_textStream;
- }
-
- bool writeItem(const QMediaContent& item) override
- {
- *m_textStream << item.request().url().toString() << Qt::endl;
- return true;
- }
-
- void close() override
- {
- }
-
-private:
- QIODevice *m_device;
- QTextStream *m_textStream;
-};
-
-
-QM3uPlaylistPlugin::QM3uPlaylistPlugin(QObject *parent)
- :QMediaPlaylistIOPlugin(parent)
-{
-}
-
-QM3uPlaylistPlugin::~QM3uPlaylistPlugin()
-{
-}
-
-bool QM3uPlaylistPlugin::canRead(QIODevice *device, const QByteArray &format) const
-{
- return device->isReadable() && (format == "m3u" || format == "m3u8" || format.isEmpty());
-}
-
-bool QM3uPlaylistPlugin::canRead(const QUrl& location, const QByteArray &format) const
-{
- if (!QFileInfo(location.toLocalFile()).isReadable())
- return false;
-
- if (format == "m3u" || format == "m3u8")
- return true;
-
- if (!format.isEmpty())
- return false;
- QString localFile = location.toLocalFile().toLower();
- return localFile.endsWith(QLatin1String("m3u")) || localFile.endsWith(QLatin1String("m3u8"));
-}
-
-bool QM3uPlaylistPlugin::canWrite(QIODevice *device, const QByteArray &format) const
-{
- return device->isOpen() && device->isWritable() && (format == "m3u" || format == "m3u8");
-}
-
-QMediaPlaylistReader *QM3uPlaylistPlugin::createReader(QIODevice *device, const QByteArray &format)
-{
- Q_UNUSED(format);
- return new QM3uPlaylistReader(device);
-}
-
-QMediaPlaylistReader *QM3uPlaylistPlugin::createReader(const QUrl& location, const QByteArray &format)
-{
- Q_UNUSED(format);
- return new QM3uPlaylistReader(location);
-}
-
-QMediaPlaylistWriter *QM3uPlaylistPlugin::createWriter(QIODevice *device, const QByteArray &format)
-{
- Q_UNUSED(format);
- return new QM3uPlaylistWriter(device);
-}
-
diff --git a/src/plugins/m3u/qm3uhandler.h b/src/plugins/m3u/qm3uhandler.h
deleted file mode 100644
index 1bc0684d3..000000000
--- a/src/plugins/m3u/qm3uhandler.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QM3UHANDLER_H
-#define QM3UHANDLER_H
-
-#include <private/qmediaplaylistioplugin_p.h>
-#include <QtCore/QObject>
-
-QT_USE_NAMESPACE
-
-class QM3uPlaylistPlugin : public QMediaPlaylistIOPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaplaylistio/5.0" FILE "m3u.json")
-
-public:
- explicit QM3uPlaylistPlugin(QObject *parent = 0);
- virtual ~QM3uPlaylistPlugin();
-
- bool canRead(QIODevice *device, const QByteArray &format = QByteArray()) const override;
- bool canRead(const QUrl& location, const QByteArray &format = QByteArray()) const override;
-
- bool canWrite(QIODevice *device, const QByteArray &format) const override;
-
- QMediaPlaylistReader *createReader(QIODevice *device, const QByteArray &format = QByteArray()) override;
- QMediaPlaylistReader *createReader(const QUrl& location, const QByteArray &format = QByteArray()) override;
-
- QMediaPlaylistWriter *createWriter(QIODevice *device, const QByteArray &format) override;
-};
-
-#endif // QM3UHANDLER_H
diff --git a/src/plugins/multimedia/CMakeLists.txt b/src/plugins/multimedia/CMakeLists.txt
new file mode 100644
index 000000000..5bc39c1f8
--- /dev/null
+++ b/src/plugins/multimedia/CMakeLists.txt
@@ -0,0 +1,24 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(QT_FEATURE_ffmpeg)
+ add_subdirectory(ffmpeg)
+endif()
+if(QT_FEATURE_gstreamer)
+ add_subdirectory(gstreamer)
+endif()
+if(ANDROID)
+ add_subdirectory(android)
+endif()
+if(WASM)
+ add_subdirectory(wasm)
+endif()
+if(APPLE AND NOT WATCHOS)
+ add_subdirectory(darwin)
+endif()
+if(QT_FEATURE_wmf)
+ add_subdirectory(windows)
+endif()
+if(QT_FEATURE_mmrenderer)
+ add_subdirectory(qnx)
+endif()
diff --git a/src/plugins/multimedia/android/CMakeLists.txt b/src/plugins/multimedia/android/CMakeLists.txt
new file mode 100644
index 000000000..31a94ff4f
--- /dev/null
+++ b/src/plugins/multimedia/android/CMakeLists.txt
@@ -0,0 +1,62 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_internal_add_plugin(QAndroidMediaPlugin
+ OUTPUT_NAME androidmediaplugin
+ PLUGIN_TYPE multimedia
+ SOURCES
+ common/qandroidaudiooutput_p.h
+ common/qandroidaudioinput.cpp common/qandroidaudioinput_p.h
+ audio/qandroidaudiodecoder.cpp audio/qandroidaudiodecoder_p.h
+ common/qandroidglobal_p.h
+ common/qandroidmultimediautils.cpp common/qandroidmultimediautils_p.h
+ common/qandroidvideosink.cpp common/qandroidvideosink_p.h
+ common/qandroidvideooutput.cpp common/qandroidvideooutput_p.h
+ mediacapture/qandroidcamera.cpp mediacapture/qandroidcamera_p.h
+ mediacapture/qandroidimagecapture.cpp mediacapture/qandroidimagecapture_p.h
+ mediacapture/qandroidcamerasession.cpp mediacapture/qandroidcamerasession_p.h
+ mediacapture/qandroidmediacapturesession.cpp mediacapture/qandroidmediacapturesession_p.h
+ mediacapture/qandroidcapturesession.cpp mediacapture/qandroidcapturesession_p.h
+ mediacapture/qandroidmediaencoder.cpp mediacapture/qandroidmediaencoder_p.h
+ mediaplayer/qandroidmediaplayer.cpp mediaplayer/qandroidmediaplayer_p.h
+ mediaplayer/qandroidmetadata.cpp mediaplayer/qandroidmetadata_p.h
+ qandroidformatsinfo.cpp qandroidformatsinfo_p.h
+ qandroidintegration.cpp qandroidintegration_p.h
+ wrappers/jni/androidcamera.cpp wrappers/jni/androidcamera_p.h
+ wrappers/jni/androidmediametadataretriever.cpp wrappers/jni/androidmediametadataretriever_p.h
+ wrappers/jni/androidmediaplayer.cpp wrappers/jni/androidmediaplayer_p.h
+ wrappers/jni/androidmediarecorder.cpp wrappers/jni/androidmediarecorder_p.h
+ wrappers/jni/androidmultimediautils.cpp wrappers/jni/androidmultimediautils_p.h
+ wrappers/jni/androidsurfacetexture.cpp wrappers/jni/androidsurfacetexture_p.h
+ wrappers/jni/androidsurfaceview.cpp wrappers/jni/androidsurfaceview_p.h
+ NO_UNITY_BUILD_SOURCES
+ # Resolves two problems:
+ # - Collision of `rwLock` with wrappers/jni/androidmediaplayer.cpp
+ # - and redefinition of `notifyFrameAvailable` with different signature
+ # with wrappers/jni/androidsurfacetexture.cpp
+ wrappers/jni/androidcamera.cpp
+ INCLUDE_DIRECTORIES
+ audio
+ common
+ mediacapture
+ mediaplayer
+ wrappers/jni
+ ../android
+ LIBRARIES
+ Qt::MultimediaPrivate
+ Qt::CorePrivate
+ OpenSLES
+ mediandk
+)
+
+set_property(TARGET QAndroidMediaPlugin APPEND PROPERTY QT_ANDROID_BUNDLED_JAR_DEPENDENCIES
+ jar/Qt${QtMultimedia_VERSION_MAJOR}AndroidMultimedia.jar:org.qtproject.qt.android.multimedia.QtMultimediaUtils
+)
+set_property(TARGET QAndroidMediaPlugin APPEND PROPERTY QT_ANDROID_LIB_DEPENDENCIES
+ ${INSTALL_PLUGINSDIR}/multimedia/libplugins_multimedia_androidmediaplugin.so
+)
+set_property(TARGET QAndroidMediaPlugin APPEND PROPERTY QT_ANDROID_PERMISSIONS
+ android.permission.CAMERA android.permission.RECORD_AUDIO
+ android.permission.BLUETOOTH
+ android.permission.MODIFY_AUDIO_SETTINGS
+)
diff --git a/src/plugins/multimedia/android/android.json b/src/plugins/multimedia/android/android.json
new file mode 100644
index 000000000..6843bd330
--- /dev/null
+++ b/src/plugins/multimedia/android/android.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "android" ]
+}
diff --git a/src/plugins/multimedia/android/audio/qandroidaudiodecoder.cpp b/src/plugins/multimedia/android/audio/qandroidaudiodecoder.cpp
new file mode 100644
index 000000000..d200a72b5
--- /dev/null
+++ b/src/plugins/multimedia/android/audio/qandroidaudiodecoder.cpp
@@ -0,0 +1,437 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qandroidaudiodecoder_p.h"
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qjniobject.h>
+#include <QtCore/qjnienvironment.h>
+#include <QtCore/private/qandroidextras_p.h>
+#include <qloggingcategory.h>
+#include <QTimer>
+#include <QFile>
+#include <QDir>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+QT_BEGIN_NAMESPACE
+
+static const char tempFile[] = "encoded.wav";
+constexpr int dequeueTimeout = 5000;
+static Q_LOGGING_CATEGORY(adLogger, "QAndroidAudioDecoder")
+
+Decoder::Decoder()
+ : m_format(AMediaFormat_new())
+{}
+
+Decoder::~Decoder()
+{
+ if (m_codec) {
+ AMediaCodec_delete(m_codec);
+ m_codec = nullptr;
+ }
+
+ if (m_extractor) {
+ AMediaExtractor_delete(m_extractor);
+ m_extractor = nullptr;
+ }
+
+ if (m_format) {
+ AMediaFormat_delete(m_format);
+ m_format = nullptr;
+ }
+}
+
+void Decoder::stop()
+{
+ if (!m_codec)
+ return;
+
+ const media_status_t err = AMediaCodec_stop(m_codec);
+ if (err != AMEDIA_OK)
+ qCWarning(adLogger) << "stop() error: " << err;
+}
+
+void Decoder::setSource(const QUrl &source)
+{
+ const QJniObject path = QJniObject::callStaticObjectMethod(
+ "org/qtproject/qt/android/multimedia/QtMultimediaUtils",
+ "getMimeType",
+ "(Landroid/content/Context;Ljava/lang/String;)Ljava/lang/String;",
+ QNativeInterface::QAndroidApplication::context().object(),
+ QJniObject::fromString(source.path()).object());
+
+ const QString mime = path.isValid() ? path.toString() : "";
+
+ if (!mime.isEmpty() && !mime.contains("audio", Qt::CaseInsensitive)) {
+ m_formatError = tr("Cannot set source, invalid mime type for the source provided.");
+ return;
+ }
+
+ if (!m_extractor)
+ m_extractor = AMediaExtractor_new();
+
+ QFile file(source.path());
+ if (!file.open(QFile::ReadOnly)) {
+ emit error(QAudioDecoder::ResourceError, tr("Cannot open the file"));
+ return;
+ }
+
+ const int fd = file.handle();
+
+ if (fd < 0) {
+ emit error(QAudioDecoder::ResourceError, tr("Invalid fileDescriptor for source."));
+ return;
+ }
+ const int size = file.size();
+ media_status_t status = AMediaExtractor_setDataSourceFd(m_extractor, fd, 0,
+ size > 0 ? size : LONG_MAX);
+ close(fd);
+
+ if (status != AMEDIA_OK) {
+ if (m_extractor) {
+ AMediaExtractor_delete(m_extractor);
+ m_extractor = nullptr;
+ }
+ m_formatError = tr("Setting source for Audio Decoder failed.");
+ }
+}
+
+void Decoder::createDecoder()
+{
+ // get encoded format for decoder
+ m_format = AMediaExtractor_getTrackFormat(m_extractor, 0);
+
+ const char *mime;
+ if (!AMediaFormat_getString(m_format, AMEDIAFORMAT_KEY_MIME, &mime)) {
+ if (m_extractor) {
+ AMediaExtractor_delete(m_extractor);
+ m_extractor = nullptr;
+ }
+ emit error(QAudioDecoder::FormatError, tr("Format not supported by Audio Decoder."));
+
+ return;
+ }
+
+ // get audio duration from source
+ int64_t durationUs;
+ AMediaFormat_getInt64(m_format, AMEDIAFORMAT_KEY_DURATION, &durationUs);
+ emit durationChanged(durationUs / 1000);
+
+ // set default output audio format from input file
+ if (!m_outputFormat.isValid()) {
+ int32_t sampleRate;
+ AMediaFormat_getInt32(m_format, AMEDIAFORMAT_KEY_SAMPLE_RATE, &sampleRate);
+ m_outputFormat.setSampleRate(sampleRate);
+ int32_t channelCount;
+ AMediaFormat_getInt32(m_format, AMEDIAFORMAT_KEY_CHANNEL_COUNT, &channelCount);
+ m_outputFormat.setChannelCount(channelCount);
+ m_outputFormat.setSampleFormat(QAudioFormat::Int16);
+ }
+
+ m_codec = AMediaCodec_createDecoderByType(mime);
+}
+
+void Decoder::doDecode()
+{
+ if (!m_formatError.isEmpty()) {
+ emit error(QAudioDecoder::FormatError, m_formatError);
+ return;
+ }
+
+ if (!m_extractor) {
+ emit error(QAudioDecoder::ResourceError, tr("Cannot decode, source not set."));
+ return;
+ }
+
+ createDecoder();
+
+ if (!m_codec) {
+ emit error(QAudioDecoder::ResourceError, tr("Audio Decoder could not be created."));
+ return;
+ }
+
+ media_status_t status = AMediaCodec_configure(m_codec, m_format, nullptr /* surface */,
+ nullptr /* crypto */, 0);
+
+ if (status != AMEDIA_OK) {
+ emit error(QAudioDecoder::ResourceError, tr("Audio Decoder failed configuration."));
+ return;
+ }
+
+ status = AMediaCodec_start(m_codec);
+ if (status != AMEDIA_OK) {
+ emit error(QAudioDecoder::ResourceError, tr("Audio Decoder failed to start."));
+ return;
+ }
+
+ AMediaExtractor_selectTrack(m_extractor, 0);
+
+ emit decodingChanged(true);
+ m_inputEOS = false;
+ while (!m_inputEOS) {
+ // handle input buffer
+ const ssize_t bufferIdx = AMediaCodec_dequeueInputBuffer(m_codec, dequeueTimeout);
+
+ if (bufferIdx >= 0) {
+ size_t bufferSize = {};
+ uint8_t *buffer = AMediaCodec_getInputBuffer(m_codec, bufferIdx, &bufferSize);
+ const int sample = AMediaExtractor_readSampleData(m_extractor, buffer, bufferSize);
+ if (sample < 0) {
+ m_inputEOS = true;
+ break;
+ }
+
+ const int64_t presentationTimeUs = AMediaExtractor_getSampleTime(m_extractor);
+ AMediaCodec_queueInputBuffer(m_codec, bufferIdx, 0, sample, presentationTimeUs,
+ m_inputEOS ? AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM : 0);
+ AMediaExtractor_advance(m_extractor);
+
+ // handle output buffer
+ AMediaCodecBufferInfo info;
+ ssize_t idx = AMediaCodec_dequeueOutputBuffer(m_codec, &info, dequeueTimeout);
+
+ while (idx == AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED
+ || idx == AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED) {
+ if (idx == AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED)
+ qCWarning(adLogger) << "dequeueOutputBuffer() status: outputFormat changed";
+
+ idx = AMediaCodec_dequeueOutputBuffer(m_codec, &info, dequeueTimeout);
+ }
+
+ if (idx >= 0) {
+ if (info.flags & AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM)
+ break;
+
+ if (info.size > 0) {
+ size_t bufferSize;
+ const uint8_t *bufferData = AMediaCodec_getOutputBuffer(m_codec, idx,
+ &bufferSize);
+ const QByteArray data((const char*)(bufferData + info.offset), info.size);
+ auto audioBuffer = QAudioBuffer(data, m_outputFormat, presentationTimeUs);
+ if (presentationTimeUs >= 0)
+ emit positionChanged(std::move(audioBuffer), presentationTimeUs / 1000);
+
+ AMediaCodec_releaseOutputBuffer(m_codec, idx, false);
+ }
+ } else if (idx == AMEDIACODEC_INFO_TRY_AGAIN_LATER) {
+ qCWarning(adLogger) << "dequeueOutputBuffer() status: try again later";
+ break;
+ } else {
+ qCWarning(adLogger) <<
+ "AMediaCodec_dequeueOutputBuffer() status: invalid buffer idx " << idx;
+ }
+ } else {
+ qCWarning(adLogger) << "dequeueInputBuffer() status: invalid buffer idx " << bufferIdx;
+ }
+ }
+ emit finished();
+}
+
+QAndroidAudioDecoder::QAndroidAudioDecoder(QAudioDecoder *parent)
+ : QPlatformAudioDecoder(parent),
+ m_decoder(new Decoder())
+{
+ connect(m_decoder, &Decoder::positionChanged, this, &QAndroidAudioDecoder::positionChanged);
+ connect(m_decoder, &Decoder::durationChanged, this, &QAndroidAudioDecoder::durationChanged);
+ connect(m_decoder, &Decoder::error, this, &QAndroidAudioDecoder::error);
+ connect(m_decoder, &Decoder::finished, this, &QAndroidAudioDecoder::finished);
+ connect(m_decoder, &Decoder::decodingChanged, this, &QPlatformAudioDecoder::setIsDecoding);
+ connect(this, &QAndroidAudioDecoder::setSourceUrl, m_decoder, & Decoder::setSource);
+}
+
+QAndroidAudioDecoder::~QAndroidAudioDecoder()
+{
+ m_decoder->thread()->quit();
+ m_decoder->thread()->wait();
+ delete m_threadDecoder;
+ delete m_decoder;
+}
+
+void QAndroidAudioDecoder::setSource(const QUrl &fileName)
+{
+ if (!requestPermissions())
+ return;
+
+ if (isDecoding())
+ return;
+
+ m_device = nullptr;
+ error(QAudioDecoder::NoError, QStringLiteral(""));
+
+ if (m_source != fileName) {
+ m_source = fileName;
+ emit setSourceUrl(m_source);
+ sourceChanged();
+ }
+}
+
+void QAndroidAudioDecoder::setSourceDevice(QIODevice *device)
+{
+ if (isDecoding())
+ return;
+
+ m_source.clear();
+ if (m_device != device) {
+ m_device = device;
+
+ if (!requestPermissions())
+ return;
+
+ sourceChanged();
+ }
+}
+
+void QAndroidAudioDecoder::start()
+{
+ if (isDecoding())
+ return;
+
+ m_position = -1;
+
+ if (m_device && (!m_device->isOpen() || !m_device->isReadable())) {
+ emit error(QAudioDecoder::ResourceError,
+ QString::fromUtf8("Unable to read from the specified device"));
+ return;
+ }
+
+ if (!m_threadDecoder) {
+ m_threadDecoder = new QThread(this);
+ m_decoder->moveToThread(m_threadDecoder);
+ m_threadDecoder->start();
+ }
+
+ decode();
+}
+
+void QAndroidAudioDecoder::stop()
+{
+ if (!isDecoding() && m_position < 0 && m_duration < 0)
+ return;
+
+ m_decoder->stop();
+ m_audioBuffer.clear();
+ m_position = -1;
+ m_duration = -1;
+ setIsDecoding(false);
+
+ emit bufferAvailableChanged(false);
+ emit QPlatformAudioDecoder::positionChanged(m_position);
+}
+
+QAudioBuffer QAndroidAudioDecoder::read()
+{
+ if (!m_audioBuffer.isEmpty()) {
+ QPair<QAudioBuffer, int> buffer = m_audioBuffer.takeFirst();
+ m_position = buffer.second;
+ emit QPlatformAudioDecoder::positionChanged(buffer.second);
+ return buffer.first;
+ }
+
+ // no buffers available
+ return {};
+}
+
+bool QAndroidAudioDecoder::bufferAvailable() const
+{
+ return m_audioBuffer.size() > 0;
+}
+
+qint64 QAndroidAudioDecoder::position() const
+{
+ return m_position;
+}
+
+qint64 QAndroidAudioDecoder::duration() const
+{
+ return m_duration;
+}
+
+void QAndroidAudioDecoder::positionChanged(QAudioBuffer audioBuffer, qint64 position)
+{
+ m_audioBuffer.append(QPair<QAudioBuffer, int>(audioBuffer, position));
+ m_position = position;
+ emit bufferReady();
+}
+
+void QAndroidAudioDecoder::durationChanged(qint64 duration)
+{
+ m_duration = duration;
+ emit QPlatformAudioDecoder::durationChanged(duration);
+}
+
+void QAndroidAudioDecoder::error(const QAudioDecoder::Error err, const QString &errorString)
+{
+ stop();
+ emit QPlatformAudioDecoder::error(err, errorString);
+}
+
+void QAndroidAudioDecoder::finished()
+{
+ emit bufferAvailableChanged(m_audioBuffer.size() > 0);
+
+ if (m_duration != -1)
+ emit durationChanged(m_duration);
+
+ // remove temp file when decoding is finished
+ QFile(QString(QDir::tempPath()).append(QString::fromUtf8(tempFile))).remove();
+ emit QPlatformAudioDecoder::finished();
+}
+
+bool QAndroidAudioDecoder::requestPermissions()
+{
+ const auto writeRes = QtAndroidPrivate::requestPermission(QStringLiteral("android.permission.WRITE_EXTERNAL_STORAGE"));
+ if (writeRes.result() == QtAndroidPrivate::Authorized)
+ return true;
+
+ return false;
+}
+
+void QAndroidAudioDecoder::decode()
+{
+ if (m_device) {
+ connect(m_device, &QIODevice::readyRead, this, &QAndroidAudioDecoder::readDevice);
+ if (m_device->bytesAvailable())
+ readDevice();
+ } else {
+ QTimer::singleShot(0, m_decoder, &Decoder::doDecode);
+ }
+}
+
+bool QAndroidAudioDecoder::createTempFile()
+{
+ QFile file = QFile(QDir::tempPath().append(QString::fromUtf8(tempFile)), this);
+
+ bool success = file.open(QIODevice::QIODevice::ReadWrite);
+ if (!success)
+ emit error(QAudioDecoder::ResourceError, tr("Error opening temporary file: %1").arg(file.errorString()));
+
+ success &= (file.write(m_deviceBuffer) == m_deviceBuffer.size());
+ if (!success)
+ emit error(QAudioDecoder::ResourceError, tr("Error while writing data to temporary file"));
+
+ file.close();
+ m_deviceBuffer.clear();
+ if (success)
+ m_decoder->setSource(file.fileName());
+
+ return success;
+}
+
+void QAndroidAudioDecoder::readDevice() {
+ m_deviceBuffer.append(m_device->readAll());
+ if (m_device->atEnd()) {
+ disconnect(m_device, &QIODevice::readyRead, this, &QAndroidAudioDecoder::readDevice);
+ if (!createTempFile()) {
+ m_deviceBuffer.clear();
+ stop();
+ return;
+ }
+ QTimer::singleShot(0, m_decoder, &Decoder::doDecode);
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qandroidaudiodecoder_p.cpp"
diff --git a/src/plugins/multimedia/android/audio/qandroidaudiodecoder_p.h b/src/plugins/multimedia/android/audio/qandroidaudiodecoder_p.h
new file mode 100644
index 000000000..65a0f1855
--- /dev/null
+++ b/src/plugins/multimedia/android/audio/qandroidaudiodecoder_p.h
@@ -0,0 +1,118 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDAUDIODECODER_P_H
+#define QANDROIDAUDIODECODER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+#include "private/qplatformaudiodecoder_p.h"
+
+#include <QtCore/qurl.h>
+#include <QThread>
+
+#include "media/NdkMediaCodec.h"
+#include "media/NdkMediaExtractor.h"
+#include "media/NdkMediaFormat.h"
+#include "media/NdkMediaError.h"
+
+
+QT_USE_NAMESPACE
+
+class Decoder : public QObject
+{
+ Q_OBJECT
+public:
+ Decoder();
+ ~Decoder();
+
+public slots:
+ void setSource(const QUrl &source);
+ void doDecode();
+ void stop();
+
+signals:
+ void positionChanged(const QAudioBuffer &buffer, qint64 position);
+ void durationChanged(const qint64 duration);
+ void error(const QAudioDecoder::Error error, const QString &errorString);
+ void finished();
+ void decodingChanged(bool decoding);
+
+private:
+ void createDecoder();
+
+ AMediaCodec *m_codec = nullptr;
+ AMediaExtractor *m_extractor = nullptr;
+ AMediaFormat *m_format = nullptr;
+
+ QAudioFormat m_outputFormat;
+ QString m_formatError;
+ bool m_inputEOS;
+};
+
+
+class QAndroidAudioDecoder : public QPlatformAudioDecoder
+{
+ Q_OBJECT
+public:
+ QAndroidAudioDecoder(QAudioDecoder *parent);
+ virtual ~QAndroidAudioDecoder();
+
+ QUrl source() const override { return m_source; }
+ void setSource(const QUrl &fileName) override;
+
+ QIODevice *sourceDevice() const override { return m_device; }
+ void setSourceDevice(QIODevice *device) override;
+
+ void start() override;
+ void stop() override;
+
+ QAudioFormat audioFormat() const override { return {}; }
+ void setAudioFormat(const QAudioFormat &/*format*/) override {}
+
+ QAudioBuffer read() override;
+ bool bufferAvailable() const override;
+
+ qint64 position() const override;
+ qint64 duration() const override;
+
+signals:
+ void setSourceUrl(const QUrl &source);
+
+private slots:
+ void positionChanged(QAudioBuffer audioBuffer, qint64 position);
+ void durationChanged(qint64 duration);
+ void error(const QAudioDecoder::Error error, const QString &errorString);
+ void readDevice();
+ void finished();
+
+private:
+ bool requestPermissions();
+ bool createTempFile();
+ void decode();
+
+ QIODevice *m_device = nullptr;
+ Decoder *m_decoder;
+
+ QList<QPair<QAudioBuffer, int>> m_audioBuffer;
+ QUrl m_source;
+
+ qint64 m_position = -1;
+ qint64 m_duration = -1;
+
+ QByteArray m_deviceBuffer;
+
+ QThread *m_threadDecoder = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDAUDIODECODER_P_H
diff --git a/src/plugins/multimedia/android/common/qandroidaudioinput.cpp b/src/plugins/multimedia/android/common/qandroidaudioinput.cpp
new file mode 100644
index 000000000..a1eb9258b
--- /dev/null
+++ b/src/plugins/multimedia/android/common/qandroidaudioinput.cpp
@@ -0,0 +1,47 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidaudioinput_p.h"
+
+#include <qaudioinput.h>
+
+#include <QtCore/qjniobject.h>
+
+QT_BEGIN_NAMESPACE
+
+QAndroidAudioInput::QAndroidAudioInput(QAudioInput *parent)
+ : QObject(parent),
+ QPlatformAudioInput(parent)
+{
+ m_muted = isMuted();
+}
+
+QAndroidAudioInput::~QAndroidAudioInput()
+{
+ setMuted(m_muted);
+}
+
+void QAndroidAudioInput::setMuted(bool muted)
+{
+ bool isInputMuted = isMuted();
+ if (muted != isInputMuted) {
+ QJniObject::callStaticMethod<void>(
+ "org/qtproject/qt/android/multimedia/QtAudioDeviceManager",
+ "setInputMuted",
+ "(Z)V",
+ muted);
+ emit mutedChanged(muted);
+ }
+}
+
+bool QAndroidAudioInput::isMuted() const
+{
+ return QJniObject::callStaticMethod<jboolean>(
+ "org/qtproject/qt/android/multimedia/QtAudioDeviceManager",
+ "isMicrophoneMute",
+ "()Z");
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qandroidaudioinput_p.cpp"
diff --git a/src/plugins/multimedia/android/common/qandroidaudioinput_p.h b/src/plugins/multimedia/android/common/qandroidaudioinput_p.h
new file mode 100644
index 000000000..ef59da8ec
--- /dev/null
+++ b/src/plugins/multimedia/android/common/qandroidaudioinput_p.h
@@ -0,0 +1,47 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDAUDIOINPUT_H
+#define QANDROIDAUDIOINPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+
+#include <private/qtmultimediaglobal_p.h>
+#include <private/qplatformaudioinput_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIA_EXPORT QAndroidAudioInput : public QObject, public QPlatformAudioInput
+{
+ Q_OBJECT
+
+public:
+ explicit QAndroidAudioInput(QAudioInput *parent);
+ ~QAndroidAudioInput();
+
+ void setMuted(bool muted) override;
+
+ bool isMuted() const;
+
+Q_SIGNALS:
+ void mutedChanged(bool muted);
+
+private:
+ bool m_muted = false;
+
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/android/common/qandroidaudiooutput_p.h b/src/plugins/multimedia/android/common/qandroidaudiooutput_p.h
new file mode 100644
index 000000000..d5d25b458
--- /dev/null
+++ b/src/plugins/multimedia/android/common/qandroidaudiooutput_p.h
@@ -0,0 +1,30 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QANDROIDAUDIOOUTPUT_H
+#define QANDROIDAUDIOOUTPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformaudiooutput_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIA_EXPORT QAndroidAudioOutput : public QPlatformAudioOutput
+{
+public:
+ QAndroidAudioOutput(QAudioOutput *qq) : QPlatformAudioOutput(qq) {}
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QANDROIDAUDIOOUTPUT_H
diff --git a/src/plugins/multimedia/android/common/qandroidglobal_p.h b/src/plugins/multimedia/android/common/qandroidglobal_p.h
new file mode 100644
index 000000000..1022fa061
--- /dev/null
+++ b/src/plugins/multimedia/android/common/qandroidglobal_p.h
@@ -0,0 +1,28 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDGLOBAL_H
+#define QANDROIDGLOBAL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <QtCore/qglobal.h>
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qtAndroidMediaPlugin)
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDGLOBAL_H
diff --git a/src/plugins/multimedia/android/common/qandroidmultimediautils.cpp b/src/plugins/multimedia/android/common/qandroidmultimediautils.cpp
new file mode 100644
index 000000000..6e4b95fe9
--- /dev/null
+++ b/src/plugins/multimedia/android/common/qandroidmultimediautils.cpp
@@ -0,0 +1,125 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidmultimediautils_p.h"
+#include "qandroidglobal_p.h"
+
+#include <qlist.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qpermissions.h>
+#include <QtCore/private/qandroidextras_p.h>
+
+QT_BEGIN_NAMESPACE
+
+int qt_findClosestValue(const QList<int> &list, int value)
+{
+ if (list.size() < 2)
+ return 0;
+
+ int begin = 0;
+ int end = list.size() - 1;
+ int pivot = begin + (end - begin) / 2;
+ int v = list.at(pivot);
+
+ while (end - begin > 1) {
+ if (value == v)
+ return pivot;
+
+ if (value > v)
+ begin = pivot;
+ else
+ end = pivot;
+
+ pivot = begin + (end - begin) / 2;
+ v = list.at(pivot);
+ }
+
+ return value - v >= list.at(pivot + 1) - value ? pivot + 1 : pivot;
+}
+
+bool qt_sizeLessThan(const QSize &s1, const QSize &s2)
+{
+ return s1.width() * s1.height() < s2.width() * s2.height();
+}
+
+QVideoFrameFormat::PixelFormat qt_pixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat f)
+{
+ switch (f) {
+ case AndroidCamera::NV21:
+ return QVideoFrameFormat::Format_NV21;
+ case AndroidCamera::YV12:
+ return QVideoFrameFormat::Format_YV12;
+ case AndroidCamera::YUY2:
+ return QVideoFrameFormat::Format_YUYV;
+ case AndroidCamera::JPEG:
+ return QVideoFrameFormat::Format_Jpeg;
+ default:
+ return QVideoFrameFormat::Format_Invalid;
+ }
+}
+
+AndroidCamera::ImageFormat qt_androidImageFormatFromPixelFormat(QVideoFrameFormat::PixelFormat f)
+{
+ switch (f) {
+ case QVideoFrameFormat::Format_NV21:
+ return AndroidCamera::NV21;
+ case QVideoFrameFormat::Format_YV12:
+ return AndroidCamera::YV12;
+ case QVideoFrameFormat::Format_YUYV:
+ return AndroidCamera::YUY2;
+ case QVideoFrameFormat::Format_Jpeg:
+ return AndroidCamera::JPEG;
+ default:
+ return AndroidCamera::UnknownImageFormat;
+ }
+}
+
+static bool androidRequestPermission(const QString &permission)
+{
+ if (QNativeInterface::QAndroidApplication::sdkVersion() < 23)
+ return true;
+
+ // Permission already granted?
+ if (QtAndroidPrivate::checkPermission(permission).result() == QtAndroidPrivate::Authorized)
+ return true;
+
+ if (QtAndroidPrivate::requestPermission(permission).result() != QtAndroidPrivate::Authorized)
+ return false;
+
+ return true;
+}
+
+static bool androidCheckPermission(const QPermission &permission)
+{
+ return qApp->checkPermission(permission) == Qt::PermissionStatus::Granted;
+}
+
+bool qt_androidCheckCameraPermission()
+{
+ const QCameraPermission permission;
+ const auto granted = androidCheckPermission(permission);
+ if (!granted)
+ qCDebug(qtAndroidMediaPlugin, "Camera permission not granted!");
+ return granted;
+}
+
+bool qt_androidCheckMicrophonePermission()
+{
+ const QMicrophonePermission permission;
+ const auto granted = androidCheckPermission(permission);
+ if (!granted)
+ qCDebug(qtAndroidMediaPlugin, "Microphone permission not granted!");
+ return granted;
+}
+
+bool qt_androidRequestWriteStoragePermission()
+{
+ if (!androidRequestPermission(QStringLiteral("android.permission.WRITE_EXTERNAL_STORAGE"))) {
+ qCDebug(qtAndroidMediaPlugin, "Storage permission denied by user!");
+ return false;
+ }
+
+ return true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/android/common/qandroidmultimediautils_p.h b/src/plugins/multimedia/android/common/qandroidmultimediautils_p.h
new file mode 100644
index 000000000..5fe841e8c
--- /dev/null
+++ b/src/plugins/multimedia/android/common/qandroidmultimediautils_p.h
@@ -0,0 +1,40 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDMULTIMEDIAUTILS_H
+#define QANDROIDMULTIMEDIAUTILS_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qglobal.h>
+#include <qsize.h>
+#include "androidcamera_p.h"
+
+QT_BEGIN_NAMESPACE
+
+// return the index of the closest value to <value> in <list>
+// (binary search)
+int qt_findClosestValue(const QList<int> &list, int value);
+
+bool qt_sizeLessThan(const QSize &s1, const QSize &s2);
+
+QVideoFrameFormat::PixelFormat qt_pixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat f);
+AndroidCamera::ImageFormat qt_androidImageFormatFromPixelFormat(QVideoFrameFormat::PixelFormat f);
+
+bool qt_androidRequestWriteStoragePermission();
+
+bool qt_androidCheckCameraPermission();
+bool qt_androidCheckMicrophonePermission();
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDMULTIMEDIAUTILS_H
diff --git a/src/plugins/multimedia/android/common/qandroidvideooutput.cpp b/src/plugins/multimedia/android/common/qandroidvideooutput.cpp
new file mode 100644
index 000000000..0724a8359
--- /dev/null
+++ b/src/plugins/multimedia/android/common/qandroidvideooutput.cpp
@@ -0,0 +1,468 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidvideooutput_p.h"
+#include "androidsurfacetexture_p.h"
+
+#include <rhi/qrhi.h>
+#include <QtGui/private/qopenglextensions_p.h>
+#include <private/qhwvideobuffer_p.h>
+#include <private/qvideoframeconverter_p.h>
+#include <private/qplatformvideosink_p.h>
+#include <private/qvideoframe_p.h>
+#include <qvideosink.h>
+#include <qopenglcontext.h>
+#include <qopenglfunctions.h>
+#include <qvideoframeformat.h>
+#include <qthread.h>
+#include <qfile.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidVideoFrameTextures : public QVideoFrameTextures
+{
+public:
+ QAndroidVideoFrameTextures(QRhi *rhi, QSize size, quint64 handle)
+ {
+ m_tex.reset(rhi->newTexture(QRhiTexture::RGBA8, size, 1));
+ m_tex->createFrom({quint64(handle), 0});
+ }
+
+ QRhiTexture *texture(uint plane) const override
+ {
+ return plane == 0 ? m_tex.get() : nullptr;
+ }
+
+private:
+ std::unique_ptr<QRhiTexture> m_tex;
+};
+
+// QRhiWithThreadGuard keeps QRhi and QThread (that created it) alive to allow proper cleaning
+class QRhiWithThreadGuard : public QObject {
+ Q_OBJECT
+public:
+ QRhiWithThreadGuard(std::shared_ptr<QRhi> r, std::shared_ptr<AndroidTextureThread> t)
+ : m_guardRhi(std::move(r)), m_thread(std::move(t)) {}
+ ~QRhiWithThreadGuard();
+protected:
+ std::shared_ptr<QRhi> m_guardRhi;
+private:
+ std::shared_ptr<AndroidTextureThread> m_thread;
+};
+
+class AndroidTextureVideoBuffer : public QRhiWithThreadGuard, public QHwVideoBuffer
+{
+public:
+ AndroidTextureVideoBuffer(std::shared_ptr<QRhi> rhi,
+ std::shared_ptr<AndroidTextureThread> thread,
+ std::unique_ptr<QRhiTexture> tex, const QSize &size)
+ : QRhiWithThreadGuard(std::move(rhi), std::move(thread)),
+ QHwVideoBuffer(QVideoFrame::RhiTextureHandle, m_guardRhi.get()),
+ m_size(size),
+ m_tex(std::move(tex))
+ {}
+
+ MapData map(QtVideo::MapMode mode) override;
+
+ void unmap() override
+ {
+ m_image = {};
+ m_mapMode = QtVideo::MapMode::NotMapped;
+ }
+
+ std::unique_ptr<QVideoFrameTextures> mapTextures(QRhi *rhi) override
+ {
+ return std::make_unique<QAndroidVideoFrameTextures>(rhi, m_size, m_tex->nativeTexture().object);
+ }
+
+private:
+ QSize m_size;
+ std::unique_ptr<QRhiTexture> m_tex;
+ QImage m_image;
+ QtVideo::MapMode m_mapMode = QtVideo::MapMode::NotMapped;
+};
+
+class ImageFromVideoFrameHelper : public QHwVideoBuffer
+{
+public:
+ ImageFromVideoFrameHelper(AndroidTextureVideoBuffer &atvb)
+ : QHwVideoBuffer(QVideoFrame::RhiTextureHandle, atvb.rhi()), m_atvb(atvb)
+ {}
+ std::unique_ptr<QVideoFrameTextures> mapTextures(QRhi *rhi) override
+ {
+ return m_atvb.mapTextures(rhi);
+ }
+
+ MapData map(QtVideo::MapMode) override { return {}; }
+ void unmap() override {}
+
+private:
+ AndroidTextureVideoBuffer &m_atvb;
+};
+
+QAbstractVideoBuffer::MapData AndroidTextureVideoBuffer::map(QtVideo::MapMode mode)
+{
+ QAbstractVideoBuffer::MapData mapData;
+
+ if (m_mapMode == QtVideo::MapMode::NotMapped && mode == QtVideo::MapMode::ReadOnly) {
+ m_mapMode = QtVideo::MapMode::ReadOnly;
+ m_image = qImageFromVideoFrame(QVideoFramePrivate::createFrame(
+ std::make_unique<ImageFromVideoFrameHelper>(*this),
+ QVideoFrameFormat(m_size, QVideoFrameFormat::Format_RGBA8888)));
+ mapData.planeCount = 1;
+ mapData.bytesPerLine[0] = m_image.bytesPerLine();
+ mapData.dataSize[0] = static_cast<int>(m_image.sizeInBytes());
+ mapData.data[0] = m_image.bits();
+ }
+
+ return mapData;
+}
+
+static const float g_quad[] = {
+ -1.f, -1.f, 0.f, 0.f,
+ -1.f, 1.f, 0.f, 1.f,
+ 1.f, 1.f, 1.f, 1.f,
+ 1.f, -1.f, 1.f, 0.f
+};
+
+class TextureCopy
+{
+ static QShader getShader(const QString &name)
+ {
+ QFile f(name);
+ if (f.open(QIODevice::ReadOnly))
+ return QShader::fromSerialized(f.readAll());
+ return {};
+ }
+
+public:
+ TextureCopy(QRhi *rhi, QRhiTexture *externalTex)
+ : m_rhi(rhi)
+ {
+ m_vertexBuffer.reset(m_rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(g_quad)));
+ m_vertexBuffer->create();
+
+ m_uniformBuffer.reset(m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64 + 64 + 4 + 4));
+ m_uniformBuffer->create();
+
+ m_sampler.reset(m_rhi->newSampler(QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None,
+ QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge));
+ m_sampler->create();
+
+ m_srb.reset(m_rhi->newShaderResourceBindings());
+ m_srb->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, m_uniformBuffer.get()),
+ QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, externalTex, m_sampler.get())
+ });
+ m_srb->create();
+
+ m_vertexShader = getShader(QStringLiteral(":/qt-project.org/multimedia/shaders/externalsampler.vert.qsb"));
+ Q_ASSERT(m_vertexShader.isValid());
+ m_fragmentShader = getShader(QStringLiteral(":/qt-project.org/multimedia/shaders/externalsampler.frag.qsb"));
+ Q_ASSERT(m_fragmentShader.isValid());
+ }
+
+ std::unique_ptr<QRhiTexture> copyExternalTexture(QSize size, const QMatrix4x4 &externalTexMatrix);
+
+private:
+ QRhi *m_rhi = nullptr;
+ std::unique_ptr<QRhiBuffer> m_vertexBuffer;
+ std::unique_ptr<QRhiBuffer> m_uniformBuffer;
+ std::unique_ptr<QRhiSampler> m_sampler;
+ std::unique_ptr<QRhiShaderResourceBindings> m_srb;
+ QShader m_vertexShader;
+ QShader m_fragmentShader;
+};
+
+static std::unique_ptr<QRhiGraphicsPipeline> newGraphicsPipeline(QRhi *rhi,
+ QRhiShaderResourceBindings *shaderResourceBindings,
+ QRhiRenderPassDescriptor *renderPassDescriptor,
+ QShader vertexShader,
+ QShader fragmentShader)
+{
+ std::unique_ptr<QRhiGraphicsPipeline> gp(rhi->newGraphicsPipeline());
+ gp->setTopology(QRhiGraphicsPipeline::TriangleFan);
+ gp->setShaderStages({
+ { QRhiShaderStage::Vertex, vertexShader },
+ { QRhiShaderStage::Fragment, fragmentShader }
+ });
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({
+ { 4 * sizeof(float) }
+ });
+ inputLayout.setAttributes({
+ { 0, 0, QRhiVertexInputAttribute::Float2, 0 },
+ { 0, 1, QRhiVertexInputAttribute::Float2, 2 * sizeof(float) }
+ });
+ gp->setVertexInputLayout(inputLayout);
+ gp->setShaderResourceBindings(shaderResourceBindings);
+ gp->setRenderPassDescriptor(renderPassDescriptor);
+ gp->create();
+
+ return gp;
+}
+
+std::unique_ptr<QRhiTexture> TextureCopy::copyExternalTexture(QSize size, const QMatrix4x4 &externalTexMatrix)
+{
+ std::unique_ptr<QRhiTexture> tex(m_rhi->newTexture(QRhiTexture::RGBA8, size, 1, QRhiTexture::RenderTarget));
+ if (!tex->create()) {
+ qWarning("Failed to create frame texture");
+ return {};
+ }
+
+ std::unique_ptr<QRhiTextureRenderTarget> renderTarget(m_rhi->newTextureRenderTarget({ { tex.get() } }));
+ std::unique_ptr<QRhiRenderPassDescriptor> renderPassDescriptor(renderTarget->newCompatibleRenderPassDescriptor());
+ renderTarget->setRenderPassDescriptor(renderPassDescriptor.get());
+ renderTarget->create();
+
+ QRhiResourceUpdateBatch *rub = m_rhi->nextResourceUpdateBatch();
+ rub->uploadStaticBuffer(m_vertexBuffer.get(), g_quad);
+
+ QMatrix4x4 identity;
+ char *p = m_uniformBuffer->beginFullDynamicBufferUpdateForCurrentFrame();
+ memcpy(p, identity.constData(), 64);
+ memcpy(p + 64, externalTexMatrix.constData(), 64);
+ float opacity = 1.0f;
+ memcpy(p + 64 + 64, &opacity, 4);
+ m_uniformBuffer->endFullDynamicBufferUpdateForCurrentFrame();
+
+ auto graphicsPipeline = newGraphicsPipeline(m_rhi, m_srb.get(), renderPassDescriptor.get(),
+ m_vertexShader, m_fragmentShader);
+
+ const QRhiCommandBuffer::VertexInput vbufBinding(m_vertexBuffer.get(), 0);
+
+ QRhiCommandBuffer *cb = nullptr;
+ if (m_rhi->beginOffscreenFrame(&cb) != QRhi::FrameOpSuccess)
+ return {};
+
+ cb->beginPass(renderTarget.get(), Qt::transparent, { 1.0f, 0 }, rub);
+ cb->setGraphicsPipeline(graphicsPipeline.get());
+ cb->setViewport({0, 0, float(size.width()), float(size.height())});
+ cb->setShaderResources(m_srb.get());
+ cb->setVertexInput(0, 1, &vbufBinding);
+ cb->draw(4);
+ cb->endPass();
+ m_rhi->endOffscreenFrame();
+
+ QOpenGLContext *ctx = QOpenGLContext::currentContext();
+ QOpenGLFunctions *f = ctx->functions();
+ static_cast<QOpenGLExtensions *>(f)->flushShared();
+
+ return tex;
+}
+
+static QMatrix4x4 extTransformMatrix(AndroidSurfaceTexture *surfaceTexture)
+{
+ QMatrix4x4 m = surfaceTexture->getTransformMatrix();
+ // flip it back, see
+ // http://androidxref.com/9.0.0_r3/xref/frameworks/native/libs/gui/GLConsumer.cpp#866
+ // (NB our matrix ctor takes row major)
+ static const QMatrix4x4 flipV(1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f);
+ m *= flipV;
+ return m;
+}
+
+class AndroidTextureThread : public QThread
+{
+ Q_OBJECT
+public:
+ AndroidTextureThread(QAndroidTextureVideoOutput * vo)
+ : QThread()
+ , m_videoOutput(vo)
+ {
+ }
+
+ ~AndroidTextureThread() {
+ QMetaObject::invokeMethod(this,
+ &AndroidTextureThread::clearSurfaceTexture, Qt::BlockingQueuedConnection);
+ this->quit();
+ this->wait();
+ }
+
+ void start()
+ {
+ QThread::start();
+ moveToThread(this);
+ }
+
+ void initRhi(QOpenGLContext *context)
+ {
+ QRhiGles2InitParams params;
+ params.shareContext = context;
+ params.fallbackSurface = QRhiGles2InitParams::newFallbackSurface();
+ m_rhi.reset(QRhi::create(QRhi::OpenGLES2, &params));
+ }
+
+public slots:
+ void onFrameAvailable(quint64 index)
+ {
+ // Check if 'm_surfaceTexture' is not reset and if the current index is the same that
+ // was used for creating connection because there can be pending frames in queue.
+ if (m_surfaceTexture && m_surfaceTexture->index() == index) {
+ m_surfaceTexture->updateTexImage();
+ auto matrix = extTransformMatrix(m_surfaceTexture.get());
+ auto tex = m_textureCopy->copyExternalTexture(m_size, matrix);
+ auto *buffer = new AndroidTextureVideoBuffer(m_rhi, m_videoOutput->getSurfaceThread(), std::move(tex), m_size);
+ QVideoFrame frame(buffer, QVideoFrameFormat(m_size, QVideoFrameFormat::Format_RGBA8888));
+ emit newFrame(frame);
+ }
+ }
+
+ void clearFrame() { emit newFrame({}); }
+
+ void setFrameSize(QSize size) { m_size = size; }
+
+ void clearSurfaceTexture()
+ {
+ m_surfaceTexture.reset();
+ m_texture.reset();
+ m_textureCopy.reset();
+ m_rhi.reset();
+ }
+
+ AndroidSurfaceTexture *createSurfaceTexture(QRhi *rhi)
+ {
+ if (m_surfaceTexture)
+ return m_surfaceTexture.get();
+
+ QOpenGLContext *ctx = rhi
+ ? static_cast<const QRhiGles2NativeHandles *>(rhi->nativeHandles())->context
+ : nullptr;
+ initRhi(ctx);
+
+ m_texture.reset(m_rhi->newTexture(QRhiTexture::RGBA8, m_size, 1, QRhiTexture::ExternalOES));
+ m_texture->create();
+ m_surfaceTexture = std::make_unique<AndroidSurfaceTexture>(m_texture->nativeTexture().object);
+ if (m_surfaceTexture->surfaceTexture()) {
+ const quint64 index = m_surfaceTexture->index();
+ connect(m_surfaceTexture.get(), &AndroidSurfaceTexture::frameAvailable, this,
+ [this, index] () { this->onFrameAvailable(index); });
+
+ m_textureCopy = std::make_unique<TextureCopy>(m_rhi.get(), m_texture.get());
+
+ } else {
+ m_texture.reset();
+ m_surfaceTexture.reset();
+ }
+
+ return m_surfaceTexture.get();
+ }
+
+signals:
+ void newFrame(const QVideoFrame &);
+
+private:
+ QAndroidTextureVideoOutput * m_videoOutput;
+ std::shared_ptr<QRhi> m_rhi;
+ std::unique_ptr<AndroidSurfaceTexture> m_surfaceTexture;
+ std::unique_ptr<QRhiTexture> m_texture;
+ std::unique_ptr<TextureCopy> m_textureCopy;
+ QSize m_size;
+};
+
+QRhiWithThreadGuard::~QRhiWithThreadGuard() {
+ // It may happen that reseting m_rhi shared_ptr will delete it (if it is the last reference)
+ // QRHI need to be deleted from the thread that created it.
+ QMetaObject::invokeMethod(m_thread.get(), [&]() {m_guardRhi.reset();}, Qt::BlockingQueuedConnection);
+}
+
+QAndroidTextureVideoOutput::QAndroidTextureVideoOutput(QVideoSink *sink, QObject *parent)
+ : QAndroidVideoOutput(parent)
+ , m_sink(sink)
+{
+ if (!m_sink) {
+ qDebug() << "Cannot create QAndroidTextureVideoOutput without a sink.";
+ m_surfaceThread = nullptr;
+ return;
+ }
+
+ startNewSurfaceThread();
+}
+
+void QAndroidTextureVideoOutput::startNewSurfaceThread()
+{
+ m_surfaceThread = std::make_shared<AndroidTextureThread>(this);
+ connect(m_surfaceThread.get(), &AndroidTextureThread::newFrame,
+ this, &QAndroidTextureVideoOutput::newFrame);
+ m_surfaceThread->start();
+}
+
+QAndroidTextureVideoOutput::~QAndroidTextureVideoOutput()
+{
+ // Make sure that no more VideFrames will be created by surfaceThread
+ QMetaObject::invokeMethod(m_surfaceThread.get(),
+ &AndroidTextureThread::clearSurfaceTexture, Qt::BlockingQueuedConnection);
+}
+
+void QAndroidTextureVideoOutput::setSubtitle(const QString &subtitle)
+{
+ if (m_sink) {
+ auto *sink = m_sink->platformVideoSink();
+ if (sink)
+ sink->setSubtitleText(subtitle);
+ }
+}
+
+bool QAndroidTextureVideoOutput::shouldTextureBeUpdated() const
+{
+ return m_sink->rhi() && m_surfaceCreatedWithoutRhi;
+}
+
+AndroidSurfaceTexture *QAndroidTextureVideoOutput::surfaceTexture()
+{
+ if (!m_sink)
+ return nullptr;
+
+ AndroidSurfaceTexture *surface = nullptr;
+ QMetaObject::invokeMethod(m_surfaceThread.get(), [&]() {
+ auto rhi = m_sink->rhi();
+ if (!rhi) {
+ m_surfaceCreatedWithoutRhi = true;
+ }
+ else if (m_surfaceCreatedWithoutRhi) {
+ m_surfaceThread->clearSurfaceTexture();
+ m_surfaceCreatedWithoutRhi = false;
+ }
+ surface = m_surfaceThread->createSurfaceTexture(rhi);
+ },
+ Qt::BlockingQueuedConnection);
+ return surface;
+}
+
+void QAndroidTextureVideoOutput::setVideoSize(const QSize &size)
+{
+ if (m_nativeSize == size)
+ return;
+
+ m_nativeSize = size;
+ QMetaObject::invokeMethod(m_surfaceThread.get(),
+ [&](){ m_surfaceThread->setFrameSize(size); },
+ Qt::BlockingQueuedConnection);
+}
+
+void QAndroidTextureVideoOutput::stop()
+{
+ m_nativeSize = {};
+ QMetaObject::invokeMethod(m_surfaceThread.get(), [&](){ m_surfaceThread->clearFrame(); });
+}
+
+void QAndroidTextureVideoOutput::reset()
+{
+ if (m_sink)
+ m_sink->platformVideoSink()->setVideoFrame({});
+ QMetaObject::invokeMethod(m_surfaceThread.get(), &AndroidTextureThread::clearSurfaceTexture);
+}
+
+void QAndroidTextureVideoOutput::newFrame(const QVideoFrame &frame)
+{
+ if (m_sink)
+ m_sink->setVideoFrame(frame);
+}
+
+QT_END_NAMESPACE
+
+#include "qandroidvideooutput.moc"
+#include "moc_qandroidvideooutput_p.cpp"
diff --git a/src/plugins/multimedia/android/common/qandroidvideooutput_p.h b/src/plugins/multimedia/android/common/qandroidvideooutput_p.h
new file mode 100644
index 000000000..7c9be5aee
--- /dev/null
+++ b/src/plugins/multimedia/android/common/qandroidvideooutput_p.h
@@ -0,0 +1,93 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDVIDEOOUTPUT_H
+#define QANDROIDVIDEOOUTPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qsize.h>
+#include <qmutex.h>
+#include <qreadwritelock.h>
+#include <qabstractvideobuffer.h>
+#include <qmatrix4x4.h>
+#include <qoffscreensurface.h>
+#include <rhi/qrhi.h>
+
+QT_BEGIN_NAMESPACE
+
+class AndroidSurfaceTexture;
+class AndroidSurfaceHolder;
+class QVideoSink;
+
+class QAndroidVideoOutput : public QObject
+{
+ Q_OBJECT
+public:
+ virtual ~QAndroidVideoOutput() { }
+
+ virtual AndroidSurfaceTexture *surfaceTexture() { return 0; }
+ virtual AndroidSurfaceHolder *surfaceHolder() { return 0; }
+
+ virtual bool isReady() { return true; }
+
+ virtual void setVideoSize(const QSize &) { }
+ virtual void start() { }
+ virtual void stop() { }
+ virtual void reset() { }
+ virtual QSize getVideoSize() const { return QSize(0, 0); }
+
+Q_SIGNALS:
+ void readyChanged(bool);
+
+protected:
+ QAndroidVideoOutput(QObject *parent) : QObject(parent) { }
+};
+
+class AndroidTextureThread;
+class QAndroidTextureVideoOutput : public QAndroidVideoOutput
+{
+ Q_OBJECT
+public:
+ explicit QAndroidTextureVideoOutput(QVideoSink *sink, QObject *parent = 0);
+ ~QAndroidTextureVideoOutput() override;
+
+ QVideoSink *surface() const { return m_sink; }
+ bool shouldTextureBeUpdated() const;
+
+ AndroidSurfaceTexture *surfaceTexture() override;
+
+ void setVideoSize(const QSize &) override;
+ void stop() override;
+ void reset() override;
+ QSize getVideoSize() const override { return m_nativeSize; }
+
+ void setSubtitle(const QString &subtitle);
+ std::shared_ptr<AndroidTextureThread> getSurfaceThread() { return m_surfaceThread; }
+private Q_SLOTS:
+ void newFrame(const QVideoFrame &);
+
+private:
+ void startNewSurfaceThread();
+ QVideoSink *m_sink = nullptr;
+ QSize m_nativeSize;
+ bool m_surfaceCreatedWithoutRhi = false;
+
+ std::shared_ptr<AndroidTextureThread> m_surfaceThread;
+};
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QList<QRhiResource *>)
+Q_DECLARE_METATYPE(QRhi*)
+
+#endif // QANDROIDVIDEOOUTPUT_H
diff --git a/src/plugins/multimedia/android/common/qandroidvideosink.cpp b/src/plugins/multimedia/android/common/qandroidvideosink.cpp
new file mode 100644
index 000000000..3da5eab31
--- /dev/null
+++ b/src/plugins/multimedia/android/common/qandroidvideosink.cpp
@@ -0,0 +1,35 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidvideosink_p.h"
+#include <rhi/qrhi.h>
+
+#include <QtCore/qdebug.h>
+
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+QAndroidVideoSink::QAndroidVideoSink(QVideoSink *parent)
+ : QPlatformVideoSink(parent)
+{
+}
+
+QAndroidVideoSink::~QAndroidVideoSink()
+{
+}
+
+void QAndroidVideoSink::setRhi(QRhi *rhi)
+{
+ if (rhi && rhi->backend() != QRhi::OpenGLES2)
+ rhi = nullptr;
+ if (m_rhi == rhi)
+ return;
+
+ m_rhi = rhi;
+ emit rhiChanged(rhi);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qandroidvideosink_p.cpp"
diff --git a/src/plugins/multimedia/android/common/qandroidvideosink_p.h b/src/plugins/multimedia/android/common/qandroidvideosink_p.h
new file mode 100644
index 000000000..9afc58f65
--- /dev/null
+++ b/src/plugins/multimedia/android/common/qandroidvideosink_p.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDVIDEOSINK_P_H
+#define QANDROIDVIDEOSINK_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <private/qplatformvideosink_p.h>
+
+#include <qvideosink.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidVideoSink
+ : public QPlatformVideoSink
+{
+ Q_OBJECT
+public:
+ explicit QAndroidVideoSink(QVideoSink *parent = 0);
+ ~QAndroidVideoSink();
+
+ void setRhi(QRhi *rhi) override;
+
+private:
+ QRhi *m_rhi = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidcamera.cpp b/src/plugins/multimedia/android/mediacapture/qandroidcamera.cpp
new file mode 100644
index 000000000..52d2e00f6
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidcamera.cpp
@@ -0,0 +1,562 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidcamera_p.h"
+#include "qandroidcamerasession_p.h"
+#include "qandroidcapturesession_p.h"
+#include "qandroidmediacapturesession_p.h"
+#include <qmediadevices.h>
+#include <qcameradevice.h>
+#include <qtimer.h>
+#include "qandroidmultimediautils_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QAndroidCamera::QAndroidCamera(QCamera *camera)
+ : QPlatformCamera(camera)
+{
+ Q_ASSERT(camera);
+}
+
+QAndroidCamera::~QAndroidCamera()
+{
+}
+
+void QAndroidCamera::setActive(bool active)
+{
+ if (m_cameraSession) {
+ m_cameraSession->setActive(active);
+ } else {
+ isPendingSetActive = active;
+ }
+}
+
+bool QAndroidCamera::isActive() const
+{
+ return m_cameraSession ? m_cameraSession->isActive() : false;
+}
+
+void QAndroidCamera::setCamera(const QCameraDevice &camera)
+{
+ m_cameraDev = camera;
+
+ if (m_cameraSession) {
+ int id = 0;
+ auto cameras = QMediaDevices::videoInputs();
+ for (int i = 0; i < cameras.size(); ++i) {
+ if (cameras.at(i) == camera) {
+ id = i;
+ break;
+ }
+ }
+ if (id != m_cameraSession->getSelectedCameraId()) {
+ m_cameraSession->setSelectedCameraId(id);
+ reactivateCameraSession();
+ }
+ }
+}
+
+void QAndroidCamera::reactivateCameraSession()
+{
+ if (m_cameraSession->isActive()) {
+ if (m_service->captureSession() &&
+ m_service->captureSession()->state() == QMediaRecorder::RecordingState) {
+ m_service->captureSession()->stop();
+ qWarning() << "Changing camera during recording not supported";
+ }
+ m_cameraSession->setActive(false);
+ m_cameraSession->setActive(true);
+ }
+}
+
+bool QAndroidCamera::setCameraFormat(const QCameraFormat &format)
+{
+ m_cameraFormat = format;
+
+ if (m_cameraSession)
+ m_cameraSession->setCameraFormat(m_cameraFormat);
+
+ return true;
+}
+
+void QAndroidCamera::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ QAndroidMediaCaptureSession *captureSession = static_cast<QAndroidMediaCaptureSession *>(session);
+ if (m_service == captureSession)
+ return;
+
+ m_service = captureSession;
+ if (!m_service) {
+ disconnect(m_cameraSession,nullptr,this,nullptr);
+ m_cameraSession = nullptr;
+ return;
+ }
+
+ m_cameraSession = m_service->cameraSession();
+ Q_ASSERT(m_cameraSession);
+ if (!m_cameraFormat.isNull())
+ m_cameraSession->setCameraFormat(m_cameraFormat);
+
+ setCamera(m_cameraDev);
+
+ connect(m_cameraSession, &QAndroidCameraSession::activeChanged, this, &QAndroidCamera::activeChanged);
+ connect(m_cameraSession, &QAndroidCameraSession::error, this, &QAndroidCamera::error);
+ connect(m_cameraSession, &QAndroidCameraSession::opened, this, &QAndroidCamera::onCameraOpened);
+
+ if (isPendingSetActive) {
+ setActive(true);
+ isPendingSetActive = false;
+ }
+}
+
+void QAndroidCamera::setFocusMode(QCamera::FocusMode mode)
+{
+ if (!m_cameraSession || !m_cameraSession->camera())
+ return;
+
+ if (isFocusModeSupported(mode)) {
+ QString focusMode;
+
+ switch (mode) {
+ case QCamera::FocusModeHyperfocal:
+ focusMode = QLatin1String("edof");
+ break;
+ case QCamera::FocusModeInfinity: // not 100%, but close
+ focusMode = QLatin1String("infinity");
+ break;
+ case QCamera::FocusModeManual:
+ focusMode = QLatin1String("fixed");
+ break;
+ case QCamera::FocusModeAutoNear:
+ focusMode = QLatin1String("macro");
+ break;
+ case QCamera::FocusModeAuto:
+ case QCamera::FocusModeAutoFar:
+ if (1) { // ###?
+ focusMode = QLatin1String("continuous-video");
+ } else {
+ focusMode = QLatin1String("continuous-picture");
+ }
+ break;
+ }
+
+ m_cameraSession->camera()->setFocusMode(focusMode);
+
+ // reset focus position
+ m_cameraSession->camera()->cancelAutoFocus();
+
+ focusModeChanged(mode);
+ }
+}
+
+bool QAndroidCamera::isFocusModeSupported(QCamera::FocusMode mode) const
+{
+ return (m_cameraSession && m_cameraSession->camera()) ? m_supportedFocusModes.contains(mode) : false;
+}
+
+void QAndroidCamera::onCameraOpened()
+{
+ Q_ASSERT(m_cameraSession);
+ connect(m_cameraSession->camera(), &AndroidCamera::previewSizeChanged, this, &QAndroidCamera::setCameraFocusArea);
+
+ m_supportedFocusModes.clear();
+ m_continuousPictureFocusSupported = false;
+ m_continuousVideoFocusSupported = false;
+ m_focusPointSupported = false;
+
+ QStringList focusModes = m_cameraSession->camera()->getSupportedFocusModes();
+ for (int i = 0; i < focusModes.size(); ++i) {
+ const QString &focusMode = focusModes.at(i);
+ if (focusMode == QLatin1String("continuous-picture")) {
+ m_supportedFocusModes << QCamera::FocusModeAuto;
+ m_continuousPictureFocusSupported = true;
+ } else if (focusMode == QLatin1String("continuous-video")) {
+ m_supportedFocusModes << QCamera::FocusModeAuto;
+ m_continuousVideoFocusSupported = true;
+ } else if (focusMode == QLatin1String("edof")) {
+ m_supportedFocusModes << QCamera::FocusModeHyperfocal;
+ } else if (focusMode == QLatin1String("fixed")) {
+ m_supportedFocusModes << QCamera::FocusModeManual;
+ } else if (focusMode == QLatin1String("infinity")) {
+ m_supportedFocusModes << QCamera::FocusModeInfinity;
+ } else if (focusMode == QLatin1String("macro")) {
+ m_supportedFocusModes << QCamera::FocusModeAutoNear;
+ }
+ }
+
+ if (m_cameraSession->camera()->getMaxNumFocusAreas() > 0)
+ m_focusPointSupported = true;
+
+ auto m = focusMode();
+ if (!m_supportedFocusModes.contains(m))
+ m = QCamera::FocusModeAuto;
+
+ setFocusMode(m);
+ setCustomFocusPoint(focusPoint());
+
+ if (m_cameraSession->camera()->isZoomSupported()) {
+ m_zoomRatios = m_cameraSession->camera()->getZoomRatios();
+ qreal maxZoom = m_zoomRatios.last() / qreal(100);
+ maximumZoomFactorChanged(maxZoom);
+ zoomTo(1, -1);
+ } else {
+ m_zoomRatios.clear();
+ maximumZoomFactorChanged(1.0);
+ }
+
+ m_minExposureCompensationIndex = m_cameraSession->camera()->getMinExposureCompensation();
+ m_maxExposureCompensationIndex = m_cameraSession->camera()->getMaxExposureCompensation();
+ m_exposureCompensationStep = m_cameraSession->camera()->getExposureCompensationStep();
+ exposureCompensationRangeChanged(m_minExposureCompensationIndex*m_exposureCompensationStep,
+ m_maxExposureCompensationIndex*m_exposureCompensationStep);
+
+ m_supportedExposureModes.clear();
+ QStringList sceneModes = m_cameraSession->camera()->getSupportedSceneModes();
+ if (!sceneModes.isEmpty()) {
+ for (int i = 0; i < sceneModes.size(); ++i) {
+ const QString &sceneMode = sceneModes.at(i);
+ if (sceneMode == QLatin1String("auto"))
+ m_supportedExposureModes << QCamera::ExposureAuto;
+ else if (sceneMode == QLatin1String("beach"))
+ m_supportedExposureModes << QCamera::ExposureBeach;
+ else if (sceneMode == QLatin1String("night"))
+ m_supportedExposureModes << QCamera::ExposureNight;
+ else if (sceneMode == QLatin1String("portrait"))
+ m_supportedExposureModes << QCamera::ExposurePortrait;
+ else if (sceneMode == QLatin1String("snow"))
+ m_supportedExposureModes << QCamera::ExposureSnow;
+ else if (sceneMode == QLatin1String("sports"))
+ m_supportedExposureModes << QCamera::ExposureSports;
+ else if (sceneMode == QLatin1String("action"))
+ m_supportedExposureModes << QCamera::ExposureAction;
+ else if (sceneMode == QLatin1String("landscape"))
+ m_supportedExposureModes << QCamera::ExposureLandscape;
+ else if (sceneMode == QLatin1String("night-portrait"))
+ m_supportedExposureModes << QCamera::ExposureNightPortrait;
+ else if (sceneMode == QLatin1String("theatre"))
+ m_supportedExposureModes << QCamera::ExposureTheatre;
+ else if (sceneMode == QLatin1String("sunset"))
+ m_supportedExposureModes << QCamera::ExposureSunset;
+ else if (sceneMode == QLatin1String("steadyphoto"))
+ m_supportedExposureModes << QCamera::ExposureSteadyPhoto;
+ else if (sceneMode == QLatin1String("fireworks"))
+ m_supportedExposureModes << QCamera::ExposureFireworks;
+ else if (sceneMode == QLatin1String("party"))
+ m_supportedExposureModes << QCamera::ExposureParty;
+ else if (sceneMode == QLatin1String("candlelight"))
+ m_supportedExposureModes << QCamera::ExposureCandlelight;
+ else if (sceneMode == QLatin1String("barcode"))
+ m_supportedExposureModes << QCamera::ExposureBarcode;
+ }
+ }
+
+ setExposureCompensation(exposureCompensation());
+ setExposureMode(exposureMode());
+
+ isFlashSupported = false;
+ isFlashAutoSupported = false;
+ isTorchSupported = false;
+
+ QStringList flashModes = m_cameraSession->camera()->getSupportedFlashModes();
+ for (int i = 0; i < flashModes.size(); ++i) {
+ const QString &flashMode = flashModes.at(i);
+ if (flashMode == QLatin1String("auto"))
+ isFlashAutoSupported = true;
+ else if (flashMode == QLatin1String("on"))
+ isFlashSupported = true;
+ else if (flashMode == QLatin1String("torch"))
+ isTorchSupported = true;
+ }
+
+ setFlashMode(flashMode());
+
+ m_supportedWhiteBalanceModes.clear();
+ QStringList whiteBalanceModes = m_cameraSession->camera()->getSupportedWhiteBalance();
+ for (int i = 0; i < whiteBalanceModes.size(); ++i) {
+ const QString &wb = whiteBalanceModes.at(i);
+ if (wb == QLatin1String("auto")) {
+ m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceAuto,
+ QStringLiteral("auto"));
+ } else if (wb == QLatin1String("cloudy-daylight")) {
+ m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceCloudy,
+ QStringLiteral("cloudy-daylight"));
+ } else if (wb == QLatin1String("daylight")) {
+ m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceSunlight,
+ QStringLiteral("daylight"));
+ } else if (wb == QLatin1String("fluorescent")) {
+ m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceFluorescent,
+ QStringLiteral("fluorescent"));
+ } else if (wb == QLatin1String("incandescent")) {
+ m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceTungsten,
+ QStringLiteral("incandescent"));
+ } else if (wb == QLatin1String("shade")) {
+ m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceShade,
+ QStringLiteral("shade"));
+ } else if (wb == QLatin1String("twilight")) {
+ m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceSunset,
+ QStringLiteral("twilight"));
+ } else if (wb == QLatin1String("warm-fluorescent")) {
+ m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceFlash,
+ QStringLiteral("warm-fluorescent"));
+ }
+ }
+
+}
+
+//void QAndroidCameraFocusControl::onCameraCaptureModeChanged()
+//{
+// if (m_cameraSession->camera() && m_focusMode == QCamera::FocusModeAudio) {
+// QString focusMode;
+// if ((m_cameraSession->captureMode().testFlag(QCamera::CaptureVideo) && m_continuousVideoFocusSupported)
+// || !m_continuousPictureFocusSupported) {
+// focusMode = QLatin1String("continuous-video");
+// } else {
+// focusMode = QLatin1String("continuous-picture");
+// }
+// m_cameraSession->camera()->setFocusMode(focusMode);
+// m_cameraSession->camera()->cancelAutoFocus();
+// }
+//}
+
+static QRect adjustedArea(const QRectF &area)
+{
+ // Qt maps focus points in the range (0.0, 0.0) -> (1.0, 1.0)
+ // Android maps focus points in the range (-1000, -1000) -> (1000, 1000)
+ // Converts an area in Qt coordinates to Android coordinates
+ return QRect(-1000 + qRound(area.x() * 2000),
+ -1000 + qRound(area.y() * 2000),
+ qRound(area.width() * 2000),
+ qRound(area.height() * 2000))
+ .intersected(QRect(-1000, -1000, 2000, 2000));
+}
+
+void QAndroidCamera::setCameraFocusArea()
+{
+ if (!m_cameraSession)
+ return;
+
+ QList<QRect> areas;
+ auto focusPoint = customFocusPoint();
+ if (QRectF(0., 0., 1., 1.).contains(focusPoint)) {
+ // in FocusPointAuto mode, leave the area list empty
+ // to let the driver choose the focus point.
+ QSize viewportSize = m_cameraSession->camera()->previewSize();
+
+ if (!viewportSize.isValid())
+ return;
+
+ // Set up a 50x50 pixel focus area around the focal point
+ QSizeF focusSize(50.f / viewportSize.width(), 50.f / viewportSize.height());
+ float x = qBound(qreal(0),
+ focusPoint.x() - (focusSize.width() / 2),
+ 1.f - focusSize.width());
+ float y = qBound(qreal(0),
+ focusPoint.y() - (focusSize.height() / 2),
+ 1.f - focusSize.height());
+
+ QRectF area(QPointF(x, y), focusSize);
+
+ areas.append(adjustedArea(area));
+ }
+ m_cameraSession->camera()->setFocusAreas(areas);
+}
+
+void QAndroidCamera::zoomTo(float factor, float rate)
+{
+ Q_UNUSED(rate);
+
+ if (zoomFactor() == factor)
+ return;
+
+ if (!m_cameraSession || !m_cameraSession->camera())
+ return;
+
+ factor = qBound(qreal(1), factor, maxZoomFactor());
+ int validZoomIndex = qt_findClosestValue(m_zoomRatios, qRound(factor * 100));
+ float newZoom = m_zoomRatios.at(validZoomIndex) / qreal(100);
+ m_cameraSession->camera()->setZoom(validZoomIndex);
+ zoomFactorChanged(newZoom);
+}
+
+void QAndroidCamera::setFlashMode(QCamera::FlashMode mode)
+{
+ if (!m_cameraSession || !m_cameraSession->camera())
+ return;
+
+ if (!isFlashModeSupported(mode))
+ return;
+
+ QString flashMode;
+ if (mode == QCamera::FlashAuto)
+ flashMode = QLatin1String("auto");
+ else if (mode == QCamera::FlashOn)
+ flashMode = QLatin1String("on");
+ else // FlashOff
+ flashMode = QLatin1String("off");
+
+ m_cameraSession->camera()->setFlashMode(flashMode);
+ flashModeChanged(mode);
+}
+
+bool QAndroidCamera::isFlashModeSupported(QCamera::FlashMode mode) const
+{
+ if (!m_cameraSession || !m_cameraSession->camera())
+ return false;
+ switch (mode) {
+ case QCamera::FlashOff:
+ return true;
+ case QCamera::FlashOn:
+ return isFlashSupported;
+ case QCamera::FlashAuto:
+ return isFlashAutoSupported;
+ }
+}
+
+bool QAndroidCamera::isFlashReady() const
+{
+ // Android doesn't have an API for that
+ return true;
+}
+
+void QAndroidCamera::setTorchMode(QCamera::TorchMode mode)
+{
+ if (!m_cameraSession)
+ return;
+ auto *camera = m_cameraSession->camera();
+ if (!camera || !isTorchSupported || mode == QCamera::TorchAuto)
+ return;
+
+ if (mode == QCamera::TorchOn) {
+ camera->setFlashMode(QLatin1String("torch"));
+ } else if (mode == QCamera::TorchOff) {
+ // if torch was enabled, it first needs to be turned off before restoring the flash mode
+ camera->setFlashMode(QLatin1String("off"));
+ setFlashMode(flashMode());
+ }
+ torchModeChanged(mode);
+}
+
+bool QAndroidCamera::isTorchModeSupported(QCamera::TorchMode mode) const
+{
+ if (!m_cameraSession || !m_cameraSession->camera())
+ return false;
+ switch (mode) {
+ case QCamera::TorchOff:
+ return true;
+ case QCamera::TorchOn:
+ return isTorchSupported;
+ case QCamera::TorchAuto:
+ return false;
+ }
+}
+
+void QAndroidCamera::setExposureMode(QCamera::ExposureMode mode)
+{
+ if (exposureMode() == mode)
+ return;
+
+ if (!m_cameraSession || !m_cameraSession->camera())
+ return;
+
+ if (!m_supportedExposureModes.contains(mode))
+ return;
+
+ QString sceneMode;
+ switch (mode) {
+ case QCamera::ExposureAuto:
+ sceneMode = QLatin1String("auto");
+ break;
+ case QCamera::ExposureSports:
+ sceneMode = QLatin1String("sports");
+ break;
+ case QCamera::ExposurePortrait:
+ sceneMode = QLatin1String("portrait");
+ break;
+ case QCamera::ExposureBeach:
+ sceneMode = QLatin1String("beach");
+ break;
+ case QCamera::ExposureSnow:
+ sceneMode = QLatin1String("snow");
+ break;
+ case QCamera::ExposureNight:
+ sceneMode = QLatin1String("night");
+ break;
+ case QCamera::ExposureAction:
+ sceneMode = QLatin1String("action");
+ break;
+ case QCamera::ExposureLandscape:
+ sceneMode = QLatin1String("landscape");
+ break;
+ case QCamera::ExposureNightPortrait:
+ sceneMode = QLatin1String("night-portrait");
+ break;
+ case QCamera::ExposureTheatre:
+ sceneMode = QLatin1String("theatre");
+ break;
+ case QCamera::ExposureSunset:
+ sceneMode = QLatin1String("sunset");
+ break;
+ case QCamera::ExposureSteadyPhoto:
+ sceneMode = QLatin1String("steadyphoto");
+ break;
+ case QCamera::ExposureFireworks:
+ sceneMode = QLatin1String("fireworks");
+ break;
+ case QCamera::ExposureParty:
+ sceneMode = QLatin1String("party");
+ break;
+ case QCamera::ExposureCandlelight:
+ sceneMode = QLatin1String("candlelight");
+ break;
+ case QCamera::ExposureBarcode:
+ sceneMode = QLatin1String("barcode");
+ break;
+ default:
+ sceneMode = QLatin1String("auto");
+ mode = QCamera::ExposureAuto;
+ break;
+ }
+
+ m_cameraSession->camera()->setSceneMode(sceneMode);
+ exposureModeChanged(mode);
+}
+
+bool QAndroidCamera::isExposureModeSupported(QCamera::ExposureMode mode) const
+{
+ return m_supportedExposureModes.contains(mode);
+}
+
+void QAndroidCamera::setExposureCompensation(float bias)
+{
+ if (exposureCompensation() == bias || !m_cameraSession || !m_cameraSession->camera())
+ return;
+
+ int biasIndex = qRound(bias / m_exposureCompensationStep);
+ biasIndex = qBound(m_minExposureCompensationIndex, biasIndex, m_maxExposureCompensationIndex);
+ float comp = biasIndex * m_exposureCompensationStep;
+ m_cameraSession->camera()->setExposureCompensation(biasIndex);
+ exposureCompensationChanged(comp);
+}
+
+bool QAndroidCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const
+{
+ return m_supportedWhiteBalanceModes.contains(mode);
+}
+
+void QAndroidCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)
+{
+ if (!m_cameraSession)
+ return;
+ auto *camera = m_cameraSession->camera();
+ if (!camera)
+ return;
+ QString wb = m_supportedWhiteBalanceModes.value(mode, QString());
+ if (!wb.isEmpty()) {
+ camera->setWhiteBalance(wb);
+ whiteBalanceModeChanged(mode);
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qandroidcamera_p.cpp"
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidcamera_p.h b/src/plugins/multimedia/android/mediacapture/qandroidcamera_p.h
new file mode 100644
index 000000000..77bbc3133
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidcamera_p.h
@@ -0,0 +1,99 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#ifndef QANDROIDCAMERACONTROL_H
+#define QANDROIDCAMERACONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformcamera_p.h>
+
+#include <qmap.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidCameraSession;
+class QAndroidCameraVideoRendererControl;
+class QAndroidMediaCaptureSession;
+
+class QAndroidCamera : public QPlatformCamera
+{
+ Q_OBJECT
+public:
+ explicit QAndroidCamera(QCamera *camera);
+ virtual ~QAndroidCamera();
+
+ bool isActive() const override;
+ void setActive(bool active) override;
+
+ void setCamera(const QCameraDevice &camera) override;
+ bool setCameraFormat(const QCameraFormat &format) override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session) override;
+
+ void setFocusMode(QCamera::FocusMode mode) override;
+ bool isFocusModeSupported(QCamera::FocusMode mode) const override;
+
+ void zoomTo(float factor, float rate) override;
+
+ void setFlashMode(QCamera::FlashMode mode) override;
+ bool isFlashModeSupported(QCamera::FlashMode mode) const override;
+ bool isFlashReady() const override;
+
+ void setTorchMode(QCamera::TorchMode mode) override;
+ bool isTorchModeSupported(QCamera::TorchMode mode) const override;
+
+ void setExposureMode(QCamera::ExposureMode mode) override;
+ bool isExposureModeSupported(QCamera::ExposureMode mode) const override;
+
+ void setExposureCompensation(float bias) override;
+
+ bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override;
+ void setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) override;
+
+private Q_SLOTS:
+ void onCameraOpened();
+ void setCameraFocusArea();
+
+private:
+ void reactivateCameraSession();
+
+ QAndroidCameraSession *m_cameraSession = nullptr;
+ QAndroidMediaCaptureSession *m_service = nullptr;
+
+ QList<QCamera::FocusMode> m_supportedFocusModes;
+ bool m_continuousPictureFocusSupported = false;
+ bool m_continuousVideoFocusSupported = false;
+ bool m_focusPointSupported = false;
+
+ QList<int> m_zoomRatios;
+
+ QList<QCamera::ExposureMode> m_supportedExposureModes;
+ int m_minExposureCompensationIndex;
+ int m_maxExposureCompensationIndex;
+ qreal m_exposureCompensationStep;
+
+ bool isFlashSupported = false;
+ bool isFlashAutoSupported = false;
+ bool isTorchSupported = false;
+ bool isPendingSetActive = false;
+ QCameraDevice m_cameraDev;
+
+ QMap<QCamera::WhiteBalanceMode, QString> m_supportedWhiteBalanceModes;
+ QCameraFormat m_cameraFormat;
+};
+
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDCAMERACONTROL_H
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidcamerasession.cpp b/src/plugins/multimedia/android/mediacapture/qandroidcamerasession.cpp
new file mode 100644
index 000000000..7eda1175f
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidcamerasession.cpp
@@ -0,0 +1,808 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2016 Ruslan Baratov
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidcamerasession_p.h"
+
+#include "androidcamera_p.h"
+#include "androidmultimediautils_p.h"
+#include "qandroidvideooutput_p.h"
+#include "qandroidmultimediautils_p.h"
+#include "androidmediarecorder_p.h"
+#include <qvideosink.h>
+#include <QtConcurrent/qtconcurrentrun.h>
+#include <qfile.h>
+#include <qguiapplication.h>
+#include <qscreen.h>
+#include <qdebug.h>
+#include <qvideoframe.h>
+#include <private/qplatformimagecapture_p.h>
+#include <private/qplatformvideosink_p.h>
+#include <private/qmemoryvideobuffer_p.h>
+#include <private/qcameradevice_p.h>
+#include <private/qmediastoragelocation_p.h>
+#include <private/qvideoframe_p.h>
+#include <QImageWriter>
+
+QT_BEGIN_NAMESPACE
+
+Q_GLOBAL_STATIC(QList<QCameraDevice>, g_availableCameras)
+
+QAndroidCameraSession::QAndroidCameraSession(QObject *parent)
+ : QObject(parent)
+ , m_selectedCamera(0)
+ , m_camera(0)
+ , m_videoOutput(0)
+ , m_savedState(-1)
+ , m_previewStarted(false)
+ , m_readyForCapture(false)
+ , m_currentImageCaptureId(-1)
+ , m_previewCallback(0)
+ , m_keepActive(false)
+{
+ if (qApp) {
+ connect(qApp, &QGuiApplication::applicationStateChanged,
+ this, &QAndroidCameraSession::onApplicationStateChanged);
+
+ auto screen = qApp->primaryScreen();
+ if (screen) {
+ connect(screen, &QScreen::orientationChanged, this,
+ &QAndroidCameraSession::updateOrientation);
+ enableRotation();
+ }
+ }
+}
+
+QAndroidCameraSession::~QAndroidCameraSession()
+{
+ if (m_sink)
+ disconnect(m_retryPreviewConnection);
+ close();
+}
+
+//void QAndroidCameraSession::setCaptureMode(QCamera::CaptureModes mode)
+//{
+// if (m_captureMode == mode || !isCaptureModeSupported(mode))
+// return;
+
+// m_captureMode = mode;
+// emit captureModeChanged(m_captureMode);
+
+// if (m_previewStarted && m_captureMode.testFlag(QCamera::CaptureStillImage))
+// applyResolution(m_actualImageSettings.resolution());
+//}
+
+void QAndroidCameraSession::setActive(bool active)
+{
+ if (m_active == active)
+ return;
+
+ // If the application is inactive, the camera shouldn't be started. Save the desired state
+ // instead and it will be set when the application becomes active.
+ if (active && qApp->applicationState() == Qt::ApplicationInactive) {
+ m_isStateSaved = true;
+ m_savedState = active;
+ return;
+ }
+
+ m_isStateSaved = false;
+ m_active = active;
+ setActiveHelper(m_active);
+ emit activeChanged(m_active);
+}
+
+void QAndroidCameraSession::setActiveHelper(bool active)
+{
+ if (!active) {
+ stopPreview();
+ close();
+ } else {
+ if (!m_camera && !open()) {
+ emit error(QCamera::CameraError, QStringLiteral("Failed to open camera"));
+ return;
+ }
+ startPreview();
+ }
+}
+
+void QAndroidCameraSession::updateAvailableCameras()
+{
+ g_availableCameras->clear();
+
+ const int numCameras = AndroidCamera::getNumberOfCameras();
+ for (int i = 0; i < numCameras; ++i) {
+ QCameraDevicePrivate *info = new QCameraDevicePrivate;
+ AndroidCamera::getCameraInfo(i, info);
+
+ if (!info->id.isEmpty()) {
+ // Add supported picture and video sizes to the camera info
+ AndroidCamera *camera = AndroidCamera::open(i);
+
+ if (camera) {
+ info->videoFormats = camera->getSupportedFormats();
+ info->photoResolutions = camera->getSupportedPictureSizes();
+ }
+
+ delete camera;
+ g_availableCameras->append(info->create());
+ }
+ }
+}
+
+const QList<QCameraDevice> &QAndroidCameraSession::availableCameras()
+{
+ if (g_availableCameras->isEmpty())
+ updateAvailableCameras();
+
+ return *g_availableCameras;
+}
+
+bool QAndroidCameraSession::open()
+{
+ close();
+
+ m_camera = AndroidCamera::open(m_selectedCamera);
+
+ if (m_camera) {
+ connect(m_camera, &AndroidCamera::pictureExposed,
+ this, &QAndroidCameraSession::onCameraPictureExposed);
+ connect(m_camera, &AndroidCamera::lastPreviewFrameFetched,
+ this, &QAndroidCameraSession::onLastPreviewFrameFetched,
+ Qt::DirectConnection);
+ connect(m_camera, &AndroidCamera::newPreviewFrame,
+ this, &QAndroidCameraSession::onNewPreviewFrame,
+ Qt::DirectConnection);
+ connect(m_camera, &AndroidCamera::pictureCaptured,
+ this, &QAndroidCameraSession::onCameraPictureCaptured);
+ connect(m_camera, &AndroidCamera::previewStarted,
+ this, &QAndroidCameraSession::onCameraPreviewStarted);
+ connect(m_camera, &AndroidCamera::previewStopped,
+ this, &QAndroidCameraSession::onCameraPreviewStopped);
+ connect(m_camera, &AndroidCamera::previewFailedToStart,
+ this, &QAndroidCameraSession::onCameraPreviewFailedToStart);
+ connect(m_camera, &AndroidCamera::takePictureFailed,
+ this, &QAndroidCameraSession::onCameraTakePictureFailed);
+
+ if (m_camera->getPreviewFormat() != AndroidCamera::NV21)
+ m_camera->setPreviewFormat(AndroidCamera::NV21);
+
+ m_camera->notifyNewFrames(m_previewCallback);
+
+ emit opened();
+ setActive(true);
+ }
+
+ return m_camera != 0;
+}
+
+void QAndroidCameraSession::close()
+{
+ if (!m_camera)
+ return;
+
+ stopPreview();
+
+ m_readyForCapture = false;
+ m_currentImageCaptureId = -1;
+ m_currentImageCaptureFileName.clear();
+ m_actualImageSettings = m_requestedImageSettings;
+
+ m_camera->release();
+ delete m_camera;
+ m_camera = 0;
+
+ setActive(false);
+}
+
+void QAndroidCameraSession::setVideoOutput(QAndroidVideoOutput *output)
+{
+ if (m_videoOutput) {
+ m_videoOutput->stop();
+ m_videoOutput->reset();
+ }
+
+ if (output) {
+ m_videoOutput = output;
+ if (m_videoOutput->isReady()) {
+ onVideoOutputReady(true);
+ } else {
+ connect(m_videoOutput, &QAndroidVideoOutput::readyChanged,
+ this, &QAndroidCameraSession::onVideoOutputReady);
+ }
+ } else {
+ m_videoOutput = 0;
+ }
+}
+
+void QAndroidCameraSession::setCameraFormat(const QCameraFormat &format)
+{
+ m_requestedFpsRange.min = format.minFrameRate();
+ m_requestedFpsRange.max = format.maxFrameRate();
+ m_requestedPixelFromat = AndroidCamera::AndroidImageFormatFromQtPixelFormat(format.pixelFormat());
+
+ m_requestedImageSettings.setResolution(format.resolution());
+ m_actualImageSettings.setResolution(format.resolution());
+ if (m_readyForCapture)
+ applyResolution(m_actualImageSettings.resolution());
+}
+
+void QAndroidCameraSession::applyResolution(const QSize &captureSize, bool restartPreview)
+{
+ if (!m_camera)
+ return;
+
+ const QSize currentViewfinderResolution = m_camera->previewSize();
+ const AndroidCamera::ImageFormat currentPreviewFormat = m_camera->getPreviewFormat();
+ const AndroidCamera::FpsRange currentFpsRange = m_camera->getPreviewFpsRange();
+
+ // -- adjust resolution
+ QSize adjustedViewfinderResolution;
+ const QList<QSize> previewSizes = m_camera->getSupportedPreviewSizes();
+
+ const bool validCaptureSize = captureSize.width() > 0 && captureSize.height() > 0;
+ if (validCaptureSize
+ && m_camera->getPreferredPreviewSizeForVideo().isEmpty()) {
+ // According to the Android doc, if getPreferredPreviewSizeForVideo() returns null, it means
+ // the preview size cannot be different from the capture size
+ adjustedViewfinderResolution = captureSize;
+ } else {
+ qreal captureAspectRatio = 0;
+ if (validCaptureSize)
+ captureAspectRatio = qreal(captureSize.width()) / qreal(captureSize.height());
+
+ if (validCaptureSize) {
+ // search for viewfinder resolution with the same aspect ratio
+ qreal minAspectDiff = 1;
+ QSize closestResolution;
+ for (int i = previewSizes.count() - 1; i >= 0; --i) {
+ const QSize &size = previewSizes.at(i);
+ const qreal sizeAspect = qreal(size.width()) / size.height();
+ if (qFuzzyCompare(captureAspectRatio, sizeAspect)) {
+ adjustedViewfinderResolution = size;
+ break;
+ } else if (minAspectDiff > qAbs(sizeAspect - captureAspectRatio)) {
+ closestResolution = size;
+ minAspectDiff = qAbs(sizeAspect - captureAspectRatio);
+ }
+ }
+ if (!adjustedViewfinderResolution.isValid()) {
+ qWarning("Cannot find a viewfinder resolution matching the capture aspect ratio.");
+ if (closestResolution.isValid()) {
+ adjustedViewfinderResolution = closestResolution;
+ qWarning("Using closest viewfinder resolution.");
+ } else {
+ return;
+ }
+ }
+ } else {
+ adjustedViewfinderResolution = previewSizes.last();
+ }
+ }
+
+ // -- adjust pixel format
+
+ AndroidCamera::ImageFormat adjustedPreviewFormat = m_requestedPixelFromat;
+ if (adjustedPreviewFormat == AndroidCamera::UnknownImageFormat)
+ adjustedPreviewFormat = AndroidCamera::NV21;
+
+ // -- adjust FPS
+
+ AndroidCamera::FpsRange adjustedFps = m_requestedFpsRange;
+ if (adjustedFps.min == 0 || adjustedFps.max == 0)
+ adjustedFps = currentFpsRange;
+
+ // -- Set values on camera
+
+ // fix the resolution of output based on the orientation
+ QSize cameraOutputResolution = adjustedViewfinderResolution;
+ QSize videoOutputResolution = adjustedViewfinderResolution;
+ QSize currentVideoOutputResolution = m_videoOutput ? m_videoOutput->getVideoSize() : QSize(0, 0);
+ const int rotation = currentCameraRotation();
+ // only transpose if it's valid for the preview
+ if (rotation == 90 || rotation == 270) {
+ videoOutputResolution.transpose();
+ if (previewSizes.contains(cameraOutputResolution.transposed()))
+ cameraOutputResolution.transpose();
+ }
+
+ if (currentViewfinderResolution != cameraOutputResolution
+ || (m_videoOutput && currentVideoOutputResolution != videoOutputResolution)
+ || currentPreviewFormat != adjustedPreviewFormat || currentFpsRange.min != adjustedFps.min
+ || currentFpsRange.max != adjustedFps.max) {
+ if (m_videoOutput) {
+ m_videoOutput->setVideoSize(videoOutputResolution);
+ }
+
+ // if preview is started, we have to stop it first before changing its size
+ if (m_previewStarted && restartPreview)
+ m_camera->stopPreview();
+
+ m_camera->setPreviewSize(cameraOutputResolution);
+ m_camera->setPreviewFormat(adjustedPreviewFormat);
+ m_camera->setPreviewFpsRange(adjustedFps);
+
+ // restart preview
+ if (m_previewStarted && restartPreview)
+ m_camera->startPreview();
+ }
+}
+
+QList<QSize> QAndroidCameraSession::getSupportedPreviewSizes() const
+{
+ return m_camera ? m_camera->getSupportedPreviewSizes() : QList<QSize>();
+}
+
+QList<QVideoFrameFormat::PixelFormat> QAndroidCameraSession::getSupportedPixelFormats() const
+{
+ QList<QVideoFrameFormat::PixelFormat> formats;
+
+ if (!m_camera)
+ return formats;
+
+ const QList<AndroidCamera::ImageFormat> nativeFormats = m_camera->getSupportedPreviewFormats();
+
+ formats.reserve(nativeFormats.size());
+
+ for (AndroidCamera::ImageFormat nativeFormat : nativeFormats) {
+ QVideoFrameFormat::PixelFormat format = AndroidCamera::QtPixelFormatFromAndroidImageFormat(nativeFormat);
+ if (format != QVideoFrameFormat::Format_Invalid)
+ formats.append(format);
+ }
+
+ return formats;
+}
+
+QList<AndroidCamera::FpsRange> QAndroidCameraSession::getSupportedPreviewFpsRange() const
+{
+ return m_camera ? m_camera->getSupportedPreviewFpsRange() : QList<AndroidCamera::FpsRange>();
+}
+
+
+bool QAndroidCameraSession::startPreview()
+{
+ if (!m_camera || !m_videoOutput)
+ return false;
+
+ if (m_previewStarted)
+ return true;
+
+ if (!m_videoOutput->isReady())
+ return true; // delay starting until the video output is ready
+
+ Q_ASSERT(m_videoOutput->surfaceTexture() || m_videoOutput->surfaceHolder());
+
+ if ((m_videoOutput->surfaceTexture() && !m_camera->setPreviewTexture(m_videoOutput->surfaceTexture()))
+ || (m_videoOutput->surfaceHolder() && !m_camera->setPreviewDisplay(m_videoOutput->surfaceHolder())))
+ return false;
+
+ applyResolution(m_actualImageSettings.resolution());
+
+ AndroidMultimediaUtils::enableOrientationListener(true);
+
+ updateOrientation();
+ m_camera->startPreview();
+ m_previewStarted = true;
+ m_videoOutput->start();
+
+ return true;
+}
+
+QSize QAndroidCameraSession::getDefaultResolution() const
+{
+ const bool hasHighQualityProfile = AndroidCamcorderProfile::hasProfile(
+ m_camera->cameraId(),
+ AndroidCamcorderProfile::Quality(AndroidCamcorderProfile::QUALITY_HIGH));
+
+ if (hasHighQualityProfile) {
+ const AndroidCamcorderProfile camProfile = AndroidCamcorderProfile::get(
+ m_camera->cameraId(),
+ AndroidCamcorderProfile::Quality(AndroidCamcorderProfile::QUALITY_HIGH));
+
+ return QSize(camProfile.getValue(AndroidCamcorderProfile::videoFrameWidth),
+ camProfile.getValue(AndroidCamcorderProfile::videoFrameHeight));
+ }
+ return QSize();
+}
+
+void QAndroidCameraSession::stopPreview()
+{
+ if (!m_camera || !m_previewStarted)
+ return;
+
+ AndroidMultimediaUtils::enableOrientationListener(false);
+
+ m_camera->stopPreview();
+ m_camera->setPreviewSize(QSize());
+ m_camera->setPreviewTexture(0);
+ m_camera->setPreviewDisplay(0);
+
+ if (m_videoOutput) {
+ m_videoOutput->stop();
+ }
+ m_previewStarted = false;
+}
+
+void QAndroidCameraSession::setImageSettings(const QImageEncoderSettings &settings)
+{
+ if (m_requestedImageSettings == settings)
+ return;
+
+ m_requestedImageSettings = m_actualImageSettings = settings;
+
+ applyImageSettings();
+
+ if (m_readyForCapture)
+ applyResolution(m_actualImageSettings.resolution());
+}
+
+void QAndroidCameraSession::enableRotation()
+{
+ m_rotationEnabled = true;
+}
+
+void QAndroidCameraSession::disableRotation()
+{
+ m_rotationEnabled = false;
+}
+
+void QAndroidCameraSession::updateOrientation()
+{
+ if (!m_camera || !m_rotationEnabled)
+ return;
+
+ m_camera->setDisplayOrientation(currentCameraRotation());
+ applyResolution(m_actualImageSettings.resolution());
+}
+
+
+int QAndroidCameraSession::currentCameraRotation() const
+{
+ if (!m_camera)
+ return 0;
+
+ auto screen = QGuiApplication::primaryScreen();
+ auto screenOrientation = screen->orientation();
+ if (screenOrientation == Qt::PrimaryOrientation)
+ screenOrientation = screen->primaryOrientation();
+
+ int deviceOrientation = 0;
+ switch (screenOrientation) {
+ case Qt::PrimaryOrientation:
+ case Qt::PortraitOrientation:
+ break;
+ case Qt::LandscapeOrientation:
+ deviceOrientation = 90;
+ break;
+ case Qt::InvertedPortraitOrientation:
+ deviceOrientation = 180;
+ break;
+ case Qt::InvertedLandscapeOrientation:
+ deviceOrientation = 270;
+ break;
+ }
+
+ int nativeCameraOrientation = m_camera->getNativeOrientation();
+
+ int rotation;
+ // subtract natural camera orientation and physical device orientation
+ if (m_camera->getFacing() == AndroidCamera::CameraFacingFront) {
+ rotation = (nativeCameraOrientation + deviceOrientation) % 360;
+ rotation = (360 - rotation) % 360; // compensate the mirror
+ } else { // back-facing camera
+ rotation = (nativeCameraOrientation - deviceOrientation + 360) % 360;
+ }
+ return rotation;
+}
+
+void QAndroidCameraSession::setPreviewFormat(AndroidCamera::ImageFormat format)
+{
+ if (format == AndroidCamera::UnknownImageFormat)
+ return;
+
+ m_camera->setPreviewFormat(format);
+}
+
+void QAndroidCameraSession::setPreviewCallback(PreviewCallback *callback)
+{
+ m_videoFrameCallbackMutex.lock();
+ m_previewCallback = callback;
+ if (m_camera)
+ m_camera->notifyNewFrames(m_previewCallback);
+ m_videoFrameCallbackMutex.unlock();
+}
+
+void QAndroidCameraSession::applyImageSettings()
+{
+ if (!m_camera)
+ return;
+
+ // only supported format right now.
+ m_actualImageSettings.setFormat(QImageCapture::JPEG);
+
+ const QSize requestedResolution = m_requestedImageSettings.resolution();
+ const QList<QSize> supportedResolutions = m_camera->getSupportedPictureSizes();
+ if (!requestedResolution.isValid()) {
+ m_actualImageSettings.setResolution(getDefaultResolution());
+ } else if (!supportedResolutions.contains(requestedResolution)) {
+ // if the requested resolution is not supported, find the closest one
+ int reqPixelCount = requestedResolution.width() * requestedResolution.height();
+ QList<int> supportedPixelCounts;
+ for (int i = 0; i < supportedResolutions.size(); ++i) {
+ const QSize &s = supportedResolutions.at(i);
+ supportedPixelCounts.append(s.width() * s.height());
+ }
+ int closestIndex = qt_findClosestValue(supportedPixelCounts, reqPixelCount);
+ m_actualImageSettings.setResolution(supportedResolutions.at(closestIndex));
+ }
+ m_camera->setPictureSize(m_actualImageSettings.resolution());
+
+ int jpegQuality = 100;
+ switch (m_requestedImageSettings.quality()) {
+ case QImageCapture::VeryLowQuality:
+ jpegQuality = 20;
+ break;
+ case QImageCapture::LowQuality:
+ jpegQuality = 40;
+ break;
+ case QImageCapture::NormalQuality:
+ jpegQuality = 60;
+ break;
+ case QImageCapture::HighQuality:
+ jpegQuality = 80;
+ break;
+ case QImageCapture::VeryHighQuality:
+ jpegQuality = 100;
+ break;
+ }
+ m_camera->setJpegQuality(jpegQuality);
+}
+
+bool QAndroidCameraSession::isReadyForCapture() const
+{
+ return isActive() && m_readyForCapture;
+}
+
+void QAndroidCameraSession::setReadyForCapture(bool ready)
+{
+ if (m_readyForCapture == ready)
+ return;
+
+ m_readyForCapture = ready;
+ emit readyForCaptureChanged(ready);
+}
+
+int QAndroidCameraSession::captureImage()
+{
+ const int newImageCaptureId = m_currentImageCaptureId + 1;
+
+ if (!isReadyForCapture()) {
+ emit imageCaptureError(newImageCaptureId, QImageCapture::NotReadyError,
+ QPlatformImageCapture::msgCameraNotReady());
+ return newImageCaptureId;
+ }
+
+ setReadyForCapture(false);
+
+ m_currentImageCaptureId = newImageCaptureId;
+
+ applyResolution(m_actualImageSettings.resolution());
+ m_camera->takePicture();
+
+ return m_currentImageCaptureId;
+}
+
+int QAndroidCameraSession::capture(const QString &fileName)
+{
+ m_currentImageCaptureFileName = fileName;
+ m_imageCaptureToBuffer = false;
+ return captureImage();
+}
+
+int QAndroidCameraSession::captureToBuffer()
+{
+ m_currentImageCaptureFileName.clear();
+ m_imageCaptureToBuffer = true;
+ return captureImage();
+}
+
+void QAndroidCameraSession::onCameraTakePictureFailed()
+{
+ emit imageCaptureError(m_currentImageCaptureId, QImageCapture::ResourceError,
+ tr("Failed to capture image"));
+
+ // Preview needs to be restarted and the preview call back must be setup again
+ m_camera->startPreview();
+}
+
+void QAndroidCameraSession::onCameraPictureExposed()
+{
+ if (!m_camera)
+ return;
+
+ emit imageExposed(m_currentImageCaptureId);
+ m_camera->fetchLastPreviewFrame();
+}
+
+void QAndroidCameraSession::onLastPreviewFrameFetched(const QVideoFrame &frame)
+{
+ if (!m_camera)
+ return;
+
+ updateOrientation();
+
+ (void)QtConcurrent::run(&QAndroidCameraSession::processPreviewImage, this,
+ m_currentImageCaptureId, frame, currentCameraRotation());
+}
+
+void QAndroidCameraSession::processPreviewImage(int id, const QVideoFrame &frame, int rotation)
+{
+ // Preview display of front-facing cameras is flipped horizontally, but the frame data
+ // we get here is not. Flip it ourselves if the camera is front-facing to match what the user
+ // sees on the viewfinder.
+ QTransform transform;
+ transform.rotate(rotation);
+
+ if (m_camera->getFacing() == AndroidCamera::CameraFacingFront)
+ transform.scale(-1, 1);
+
+ emit imageCaptured(id, frame.toImage().transformed(transform));
+}
+
+void QAndroidCameraSession::onNewPreviewFrame(const QVideoFrame &frame)
+{
+ if (!m_camera)
+ return;
+
+ m_videoFrameCallbackMutex.lock();
+
+ if (m_previewCallback)
+ m_previewCallback->onFrameAvailable(frame);
+
+ m_videoFrameCallbackMutex.unlock();
+}
+
+void QAndroidCameraSession::onCameraPictureCaptured(const QByteArray &bytes,
+ QVideoFrameFormat::PixelFormat format, QSize size,int bytesPerLine)
+{
+ if (m_imageCaptureToBuffer) {
+ processCapturedImageToBuffer(m_currentImageCaptureId, bytes, format, size, bytesPerLine);
+ } else {
+ // Loading and saving the captured image can be slow, do it in a separate thread
+ (void)QtConcurrent::run(&QAndroidCameraSession::processCapturedImage, this,
+ m_currentImageCaptureId, bytes, m_currentImageCaptureFileName);
+ }
+
+ // Preview needs to be restarted after taking a picture
+ if (m_camera)
+ m_camera->startPreview();
+}
+
+void QAndroidCameraSession::onCameraPreviewStarted()
+{
+ setReadyForCapture(true);
+}
+
+void QAndroidCameraSession::onCameraPreviewFailedToStart()
+{
+ if (isActive()) {
+ Q_EMIT error(QCamera::CameraError, tr("Camera preview failed to start."));
+
+ AndroidMultimediaUtils::enableOrientationListener(false);
+ m_camera->setPreviewSize(QSize());
+ m_camera->setPreviewTexture(0);
+ if (m_videoOutput) {
+ m_videoOutput->stop();
+ m_videoOutput->reset();
+ }
+ m_previewStarted = false;
+
+ setActive(false);
+ setReadyForCapture(false);
+ }
+}
+
+void QAndroidCameraSession::onCameraPreviewStopped()
+{
+ if (!m_previewStarted)
+ setActive(false);
+ setReadyForCapture(false);
+}
+
+void QAndroidCameraSession::processCapturedImage(int id, const QByteArray &bytes, const QString &fileName)
+{
+ const QString actualFileName = QMediaStorageLocation::generateFileName(
+ fileName, QStandardPaths::PicturesLocation, QLatin1String("jpg"));
+ QFile writer(actualFileName);
+ if (!writer.open(QIODeviceBase::WriteOnly)) {
+ const QString errorMessage = tr("File is not available: %1").arg(writer.errorString());
+ emit imageCaptureError(id, QImageCapture::Error::ResourceError, errorMessage);
+ return;
+ }
+
+ if (writer.write(bytes) < 0) {
+ const QString errorMessage = tr("Could not save to file: %1").arg(writer.errorString());
+ emit imageCaptureError(id, QImageCapture::Error::ResourceError, errorMessage);
+ return;
+ }
+
+ writer.close();
+ if (fileName.isEmpty() || QFileInfo(fileName).isRelative())
+ AndroidMultimediaUtils::registerMediaFile(actualFileName);
+
+ emit imageSaved(id, actualFileName);
+}
+
+void QAndroidCameraSession::processCapturedImageToBuffer(int id, const QByteArray &bytes,
+ QVideoFrameFormat::PixelFormat format, QSize size, int bytesPerLine)
+{
+ QVideoFrame frame = QVideoFramePrivate::createFrame(
+ std::make_unique<QMemoryVideoBuffer>(bytes, bytesPerLine),
+ QVideoFrameFormat(size, format));
+ emit imageAvailable(id, frame);
+}
+
+void QAndroidCameraSession::onVideoOutputReady(bool ready)
+{
+ if (ready && m_active)
+ startPreview();
+}
+
+void QAndroidCameraSession::onApplicationStateChanged()
+{
+
+ switch (QGuiApplication::applicationState()) {
+ case Qt::ApplicationInactive:
+ if (!m_keepActive && m_active) {
+ m_savedState = m_active;
+ setActive(false);
+ m_isStateSaved = true;
+ }
+ break;
+ case Qt::ApplicationActive:
+ if (m_isStateSaved) {
+ setActive(m_savedState);
+ m_isStateSaved = false;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void QAndroidCameraSession::setKeepAlive(bool keepAlive)
+{
+ m_keepActive = keepAlive;
+}
+
+void QAndroidCameraSession::setVideoSink(QVideoSink *sink)
+{
+ if (m_sink == sink)
+ return;
+
+ if (m_sink)
+ disconnect(m_retryPreviewConnection);
+
+ m_sink = sink;
+
+ if (m_sink)
+ m_retryPreviewConnection =
+ connect(m_sink->platformVideoSink(), &QPlatformVideoSink::rhiChanged, this, [&]()
+ {
+ if (m_active) {
+ setActive(false);
+ setActive(true);
+ }
+ }, Qt::DirectConnection);
+ if (m_sink) {
+ delete m_textureOutput;
+ m_textureOutput = nullptr;
+
+ m_textureOutput = new QAndroidTextureVideoOutput(m_sink, this);
+ }
+
+ setVideoOutput(m_textureOutput);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qandroidcamerasession_p.cpp"
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidcamerasession_p.h b/src/plugins/multimedia/android/mediacapture/qandroidcamerasession_p.h
new file mode 100644
index 000000000..3b56d9c3b
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidcamerasession_p.h
@@ -0,0 +1,166 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 Ruslan Baratov
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDCAMERASESSION_H
+#define QANDROIDCAMERASESSION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qcamera.h>
+#include <QImageCapture>
+#include <QSet>
+#include <QMutex>
+#include <private/qplatformimagecapture_p.h>
+#include "androidcamera_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidVideoOutput;
+class QAndroidTextureVideoOutput ;
+class QVideoSink;
+
+class QAndroidCameraSession : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QAndroidCameraSession(QObject *parent = 0);
+ ~QAndroidCameraSession();
+
+ static const QList<QCameraDevice> &availableCameras();
+
+ void setSelectedCameraId(int cameraId) { m_selectedCamera = cameraId; }
+ int getSelectedCameraId() { return m_selectedCamera; }
+ AndroidCamera *camera() const { return m_camera; }
+
+ bool isActive() const { return m_active; }
+ void setActive(bool active);
+
+ void applyResolution(const QSize &captureSize = QSize(), bool restartPreview = true);
+
+ QAndroidVideoOutput *videoOutput() const { return m_videoOutput; }
+ void setVideoOutput(QAndroidVideoOutput *output);
+
+ void setCameraFormat(const QCameraFormat &format);
+
+ QList<QSize> getSupportedPreviewSizes() const;
+ QList<QVideoFrameFormat::PixelFormat> getSupportedPixelFormats() const;
+ QList<AndroidCamera::FpsRange> getSupportedPreviewFpsRange() const;
+
+ QImageEncoderSettings imageSettings() const { return m_actualImageSettings; }
+ void setImageSettings(const QImageEncoderSettings &settings);
+
+ bool isReadyForCapture() const;
+ void setReadyForCapture(bool ready);
+ int capture(const QString &fileName);
+ int captureToBuffer();
+
+ int currentCameraRotation() const;
+
+ void setPreviewFormat(AndroidCamera::ImageFormat format);
+
+ struct PreviewCallback
+ {
+ virtual void onFrameAvailable(const QVideoFrame &frame) = 0;
+ };
+ void setPreviewCallback(PreviewCallback *callback);
+
+ void setVideoSink(QVideoSink *surface);
+
+ void disableRotation();
+ void enableRotation();
+
+ void setKeepAlive(bool keepAlive);
+
+Q_SIGNALS:
+ void activeChanged(bool);
+ void error(int error, const QString &errorString);
+ void opened();
+
+ void readyForCaptureChanged(bool);
+ void imageExposed(int id);
+ void imageCaptured(int id, const QImage &preview);
+ void imageMetadataAvailable(int id, const QMediaMetaData &key);
+ void imageAvailable(int id, const QVideoFrame &buffer);
+ void imageSaved(int id, const QString &fileName);
+ void imageCaptureError(int id, int error, const QString &errorString);
+
+private Q_SLOTS:
+ void onVideoOutputReady(bool ready);
+ void updateOrientation();
+
+ void onApplicationStateChanged();
+
+ void onCameraTakePictureFailed();
+ void onCameraPictureExposed();
+ void onCameraPictureCaptured(const QByteArray &bytes, QVideoFrameFormat::PixelFormat format, QSize size, int bytesPerLine);
+ void onLastPreviewFrameFetched(const QVideoFrame &frame);
+ void onNewPreviewFrame(const QVideoFrame &frame);
+ void onCameraPreviewStarted();
+ void onCameraPreviewFailedToStart();
+ void onCameraPreviewStopped();
+
+private:
+ static void updateAvailableCameras();
+
+ bool open();
+ void close();
+
+ bool startPreview();
+ void stopPreview();
+
+ void applyImageSettings();
+
+ void processPreviewImage(int id, const QVideoFrame &frame, int rotation);
+ void processCapturedImage(int id, const QByteArray &bytes, const QString &fileName);
+ void processCapturedImageToBuffer(int id, const QByteArray &bytes,
+ QVideoFrameFormat::PixelFormat format, QSize size, int bytesPerLine);
+
+ void setActiveHelper(bool active);
+
+ int captureImage();
+
+ QSize getDefaultResolution() const;
+
+ int m_selectedCamera;
+ AndroidCamera *m_camera;
+ QAndroidVideoOutput *m_videoOutput;
+
+ bool m_active = false;
+ bool m_isStateSaved = false;
+ bool m_savedState = false;
+ bool m_previewStarted;
+
+ bool m_rotationEnabled = false;
+
+ QVideoSink *m_sink = nullptr;
+ QAndroidTextureVideoOutput *m_textureOutput = nullptr;
+
+ QImageEncoderSettings m_requestedImageSettings;
+ QImageEncoderSettings m_actualImageSettings;
+ AndroidCamera::FpsRange m_requestedFpsRange;
+ AndroidCamera::ImageFormat m_requestedPixelFromat = AndroidCamera::ImageFormat::NV21;
+
+ bool m_readyForCapture;
+ int m_currentImageCaptureId;
+ QString m_currentImageCaptureFileName;
+ bool m_imageCaptureToBuffer;
+
+ QMutex m_videoFrameCallbackMutex;
+ PreviewCallback *m_previewCallback;
+ bool m_keepActive;
+ QMetaObject::Connection m_retryPreviewConnection;
+};
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDCAMERASESSION_H
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidcapturesession.cpp b/src/plugins/multimedia/android/mediacapture/qandroidcapturesession.cpp
new file mode 100644
index 000000000..3b005e4a5
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidcapturesession.cpp
@@ -0,0 +1,473 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidcapturesession_p.h"
+
+#include "androidcamera_p.h"
+#include "qandroidcamerasession_p.h"
+#include "qaudioinput.h"
+#include "qaudiooutput.h"
+#include "androidmediaplayer_p.h"
+#include "androidmultimediautils_p.h"
+#include "qandroidmultimediautils_p.h"
+#include "qandroidvideooutput_p.h"
+#include "qandroidglobal_p.h"
+#include <private/qplatformaudioinput_p.h>
+#include <private/qplatformaudiooutput_p.h>
+#include <private/qmediarecorder_p.h>
+#include <private/qmediastoragelocation_p.h>
+#include <QtCore/qmimetype.h>
+
+#include <algorithm>
+
+QT_BEGIN_NAMESPACE
+
+QAndroidCaptureSession::QAndroidCaptureSession()
+ : QObject()
+ , m_mediaRecorder(0)
+ , m_cameraSession(0)
+ , m_duration(0)
+ , m_state(QMediaRecorder::StoppedState)
+ , m_outputFormat(AndroidMediaRecorder::DefaultOutputFormat)
+ , m_audioEncoder(AndroidMediaRecorder::DefaultAudioEncoder)
+ , m_videoEncoder(AndroidMediaRecorder::DefaultVideoEncoder)
+{
+ m_notifyTimer.setInterval(1000);
+ connect(&m_notifyTimer, &QTimer::timeout, this, &QAndroidCaptureSession::updateDuration);
+}
+
+QAndroidCaptureSession::~QAndroidCaptureSession()
+{
+ stop();
+ m_mediaRecorder = nullptr;
+ if (m_audioInput && m_audioOutput)
+ AndroidMediaPlayer::stopSoundStreaming();
+}
+
+void QAndroidCaptureSession::setCameraSession(QAndroidCameraSession *cameraSession)
+{
+ if (m_cameraSession) {
+ disconnect(m_connOpenCamera);
+ disconnect(m_connActiveChangedCamera);
+ }
+
+ m_cameraSession = cameraSession;
+ if (m_cameraSession) {
+ m_connOpenCamera = connect(cameraSession, &QAndroidCameraSession::opened,
+ this, &QAndroidCaptureSession::onCameraOpened);
+ m_connActiveChangedCamera = connect(cameraSession, &QAndroidCameraSession::activeChanged,
+ this, [this](bool isActive) {
+ if (!isActive)
+ stop();
+ });
+ }
+}
+
+void QAndroidCaptureSession::setAudioInput(QPlatformAudioInput *input)
+{
+ if (m_audioInput == input)
+ return;
+
+ if (m_audioInput) {
+ disconnect(m_audioInputChanged);
+ }
+
+ m_audioInput = input;
+
+ if (m_audioInput) {
+ m_audioInputChanged = connect(m_audioInput->q, &QAudioInput::deviceChanged, this, [this]() {
+ if (m_state == QMediaRecorder::RecordingState)
+ m_mediaRecorder->setAudioInput(m_audioInput->device.id());
+ updateStreamingState();
+ });
+ }
+ updateStreamingState();
+}
+
+void QAndroidCaptureSession::setAudioOutput(QPlatformAudioOutput *output)
+{
+ if (m_audioOutput == output)
+ return;
+
+ if (m_audioOutput)
+ disconnect(m_audioOutputChanged);
+
+ m_audioOutput = output;
+
+ if (m_audioOutput) {
+ m_audioOutputChanged = connect(m_audioOutput->q, &QAudioOutput::deviceChanged, this,
+ [this] () {
+ AndroidMediaPlayer::setAudioOutput(m_audioOutput->device.id());
+ updateStreamingState();
+ });
+ AndroidMediaPlayer::setAudioOutput(m_audioOutput->device.id());
+ }
+ updateStreamingState();
+}
+
+void QAndroidCaptureSession::updateStreamingState()
+{
+ if (m_audioInput && m_audioOutput) {
+ AndroidMediaPlayer::startSoundStreaming(m_audioInput->device.id().toInt(),
+ m_audioOutput->device.id().toInt());
+ } else {
+ AndroidMediaPlayer::stopSoundStreaming();
+ }
+}
+
+QMediaRecorder::RecorderState QAndroidCaptureSession::state() const
+{
+ return m_state;
+}
+
+void QAndroidCaptureSession::setKeepAlive(bool keepAlive)
+{
+ if (m_cameraSession)
+ m_cameraSession->setKeepAlive(keepAlive);
+}
+
+
+void QAndroidCaptureSession::start(QMediaEncoderSettings &settings, const QUrl &outputLocation)
+{
+ if (m_state == QMediaRecorder::RecordingState)
+ return;
+
+ if (!m_cameraSession && !m_audioInput) {
+ updateError(QMediaRecorder::ResourceError, QLatin1String("No devices are set"));
+ return;
+ }
+
+ setKeepAlive(true);
+
+ const bool validCameraSession = m_cameraSession && m_cameraSession->camera();
+
+ if (validCameraSession && !qt_androidCheckCameraPermission()) {
+ updateError(QMediaRecorder::ResourceError, QLatin1String("Camera permission denied."));
+ setKeepAlive(false);
+ return;
+ }
+
+ if (m_audioInput && !qt_androidCheckMicrophonePermission()) {
+ updateError(QMediaRecorder::ResourceError, QLatin1String("Microphone permission denied."));
+ setKeepAlive(false);
+ return;
+ }
+
+ m_mediaRecorder = std::make_shared<AndroidMediaRecorder>();
+ connect(m_mediaRecorder.get(), &AndroidMediaRecorder::error, this,
+ &QAndroidCaptureSession::onError);
+ connect(m_mediaRecorder.get(), &AndroidMediaRecorder::info, this,
+ &QAndroidCaptureSession::onInfo);
+
+ applySettings(settings);
+
+ // Set audio/video sources
+ if (validCameraSession) {
+ m_cameraSession->camera()->stopPreviewSynchronous();
+ m_cameraSession->camera()->unlock();
+
+ m_mediaRecorder->setCamera(m_cameraSession->camera());
+ m_mediaRecorder->setVideoSource(AndroidMediaRecorder::Camera);
+ }
+
+ if (m_audioInput) {
+ m_mediaRecorder->setAudioInput(m_audioInput->device.id());
+ if (!m_mediaRecorder->isAudioSourceSet())
+ m_mediaRecorder->setAudioSource(AndroidMediaRecorder::DefaultAudioSource);
+ }
+
+ // Set output format
+ m_mediaRecorder->setOutputFormat(m_outputFormat);
+
+ // Set video encoder settings
+ if (validCameraSession) {
+ m_mediaRecorder->setVideoSize(settings.videoResolution());
+ m_mediaRecorder->setVideoFrameRate(qRound(settings.videoFrameRate()));
+ m_mediaRecorder->setVideoEncodingBitRate(settings.videoBitRate());
+ m_mediaRecorder->setVideoEncoder(m_videoEncoder);
+
+ // media recorder is also compensanting the mirror on front camera
+ auto rotation = m_cameraSession->currentCameraRotation();
+ if (m_cameraSession->camera()->getFacing() == AndroidCamera::CameraFacingFront)
+ rotation = (360 - rotation) % 360; // remove mirror compensation
+
+ m_mediaRecorder->setOrientationHint(rotation);
+ }
+
+ // Set audio encoder settings
+ if (m_audioInput) {
+ m_mediaRecorder->setAudioChannels(settings.audioChannelCount());
+ m_mediaRecorder->setAudioEncodingBitRate(settings.audioBitRate());
+ m_mediaRecorder->setAudioSamplingRate(settings.audioSampleRate());
+ m_mediaRecorder->setAudioEncoder(m_audioEncoder);
+ }
+
+ QString extension = settings.mimeType().preferredSuffix();
+ // Set output file
+ auto location = outputLocation.toString(QUrl::PreferLocalFile);
+ QString filePath = location;
+ if (QUrl(filePath).scheme() != QLatin1String("content")) {
+ filePath = QMediaStorageLocation::generateFileName(
+ location, m_cameraSession ? QStandardPaths::MoviesLocation
+ : QStandardPaths::MusicLocation, extension);
+ }
+
+ m_usedOutputLocation = QUrl::fromLocalFile(filePath);
+ m_outputLocationIsStandard = location.isEmpty() || QFileInfo(location).isRelative();
+ m_mediaRecorder->setOutputFile(filePath);
+
+ if (validCameraSession) {
+ m_cameraSession->disableRotation();
+ }
+
+ if (!m_mediaRecorder->prepare()) {
+ updateError(QMediaRecorder::FormatError,
+ QLatin1String("Unable to prepare the media recorder."));
+ restartViewfinder();
+
+ return;
+ }
+
+ if (!m_mediaRecorder->start()) {
+ updateError(QMediaRecorder::FormatError, QMediaRecorderPrivate::msgFailedStartRecording());
+ restartViewfinder();
+
+ return;
+ }
+
+ m_elapsedTime.start();
+ m_notifyTimer.start();
+ updateDuration();
+
+ if (validCameraSession) {
+ m_cameraSession->setReadyForCapture(false);
+
+ // Preview frame callback is cleared when setting up the camera with the media recorder.
+ // We need to reset it.
+ m_cameraSession->camera()->setupPreviewFrameCallback();
+ }
+
+ m_state = QMediaRecorder::RecordingState;
+ emit stateChanged(m_state);
+}
+
+void QAndroidCaptureSession::stop(bool error)
+{
+ if (m_state == QMediaRecorder::StoppedState || m_mediaRecorder == nullptr)
+ return;
+
+ m_mediaRecorder->stop();
+ m_notifyTimer.stop();
+ updateDuration();
+ m_elapsedTime.invalidate();
+
+ m_mediaRecorder = nullptr;
+
+ if (m_cameraSession && m_cameraSession->isActive()) {
+ // Viewport needs to be restarted after recording
+ restartViewfinder();
+ }
+
+ if (!error) {
+ // if the media is saved into the standard media location, register it
+ // with the Android media scanner so it appears immediately in apps
+ // such as the gallery.
+ if (m_outputLocationIsStandard)
+ AndroidMultimediaUtils::registerMediaFile(m_usedOutputLocation.toLocalFile());
+
+ emit actualLocationChanged(m_usedOutputLocation);
+ }
+
+ m_state = QMediaRecorder::StoppedState;
+ emit stateChanged(m_state);
+}
+
+qint64 QAndroidCaptureSession::duration() const
+{
+ return m_duration;
+}
+
+void QAndroidCaptureSession::applySettings(QMediaEncoderSettings &settings)
+{
+ // container settings
+ auto fileFormat = settings.mediaFormat().fileFormat();
+ if (!m_cameraSession && fileFormat == QMediaFormat::AAC) {
+ m_outputFormat = AndroidMediaRecorder::AAC_ADTS;
+ } else if (fileFormat == QMediaFormat::Ogg) {
+ m_outputFormat = AndroidMediaRecorder::OGG;
+ } else if (fileFormat == QMediaFormat::WebM) {
+ m_outputFormat = AndroidMediaRecorder::WEBM;
+// } else if (fileFormat == QLatin1String("3gp")) {
+// m_outputFormat = AndroidMediaRecorder::THREE_GPP;
+ } else {
+ // fallback to MP4
+ m_outputFormat = AndroidMediaRecorder::MPEG_4;
+ }
+
+ // audio settings
+ if (settings.audioChannelCount() <= 0)
+ settings.setAudioChannelCount(m_defaultSettings.audioChannels);
+ if (settings.audioBitRate() <= 0)
+ settings.setAudioBitRate(m_defaultSettings.audioBitRate);
+ if (settings.audioSampleRate() <= 0)
+ settings.setAudioSampleRate(m_defaultSettings.audioSampleRate);
+
+ if (settings.audioCodec() == QMediaFormat::AudioCodec::AAC)
+ m_audioEncoder = AndroidMediaRecorder::AAC;
+ else if (settings.audioCodec() == QMediaFormat::AudioCodec::Opus)
+ m_audioEncoder = AndroidMediaRecorder::OPUS;
+ else if (settings.audioCodec() == QMediaFormat::AudioCodec::Vorbis)
+ m_audioEncoder = AndroidMediaRecorder::VORBIS;
+ else
+ m_audioEncoder = m_defaultSettings.audioEncoder;
+
+
+ // video settings
+ if (m_cameraSession && m_cameraSession->camera()) {
+ if (settings.videoResolution().isEmpty()) {
+ settings.setVideoResolution(m_defaultSettings.videoResolution);
+ } else if (!m_supportedResolutions.contains(settings.videoResolution())) {
+ // if the requested resolution is not supported, find the closest one
+ QSize reqSize = settings.videoResolution();
+ int reqPixelCount = reqSize.width() * reqSize.height();
+ QList<int> supportedPixelCounts;
+ for (int i = 0; i < m_supportedResolutions.size(); ++i) {
+ const QSize &s = m_supportedResolutions.at(i);
+ supportedPixelCounts.append(s.width() * s.height());
+ }
+ int closestIndex = qt_findClosestValue(supportedPixelCounts, reqPixelCount);
+ settings.setVideoResolution(m_supportedResolutions.at(closestIndex));
+ }
+
+ if (settings.videoFrameRate() <= 0)
+ settings.setVideoFrameRate(m_defaultSettings.videoFrameRate);
+ if (settings.videoBitRate() <= 0)
+ settings.setVideoBitRate(m_defaultSettings.videoBitRate);
+
+ if (settings.videoCodec() == QMediaFormat::VideoCodec::H264)
+ m_videoEncoder = AndroidMediaRecorder::H264;
+ else if (settings.videoCodec() == QMediaFormat::VideoCodec::H265)
+ m_videoEncoder = AndroidMediaRecorder::HEVC;
+ else if (settings.videoCodec() == QMediaFormat::VideoCodec::MPEG4)
+ m_videoEncoder = AndroidMediaRecorder::MPEG_4_SP;
+ else
+ m_videoEncoder = m_defaultSettings.videoEncoder;
+
+ }
+}
+
+void QAndroidCaptureSession::restartViewfinder()
+{
+
+ setKeepAlive(false);
+
+ if (!m_cameraSession)
+ return;
+
+ if (m_cameraSession && m_cameraSession->camera()) {
+ m_cameraSession->camera()->reconnect();
+ m_cameraSession->camera()->stopPreviewSynchronous();
+ m_cameraSession->camera()->startPreview();
+ m_cameraSession->setReadyForCapture(true);
+ m_cameraSession->enableRotation();
+ }
+
+ m_mediaRecorder = nullptr;
+}
+
+void QAndroidCaptureSession::updateDuration()
+{
+ if (m_elapsedTime.isValid())
+ m_duration = m_elapsedTime.elapsed();
+
+ emit durationChanged(m_duration);
+}
+
+void QAndroidCaptureSession::onCameraOpened()
+{
+ m_supportedResolutions.clear();
+ m_supportedFramerates.clear();
+
+ // get supported resolutions from predefined profiles
+ for (int i = 0; i < 8; ++i) {
+ CaptureProfile profile = getProfile(i);
+ if (!profile.isNull) {
+ if (i == AndroidCamcorderProfile::QUALITY_HIGH)
+ m_defaultSettings = profile;
+
+ if (!m_supportedResolutions.contains(profile.videoResolution))
+ m_supportedResolutions.append(profile.videoResolution);
+ if (!m_supportedFramerates.contains(profile.videoFrameRate))
+ m_supportedFramerates.append(profile.videoFrameRate);
+ }
+ }
+
+ std::sort(m_supportedResolutions.begin(), m_supportedResolutions.end(), qt_sizeLessThan);
+ std::sort(m_supportedFramerates.begin(), m_supportedFramerates.end());
+
+ QMediaEncoderSettings defaultSettings;
+ applySettings(defaultSettings);
+ m_cameraSession->applyResolution(defaultSettings.videoResolution());
+}
+
+QAndroidCaptureSession::CaptureProfile QAndroidCaptureSession::getProfile(int id)
+{
+ CaptureProfile profile;
+ const bool hasProfile = AndroidCamcorderProfile::hasProfile(m_cameraSession->camera()->cameraId(),
+ AndroidCamcorderProfile::Quality(id));
+
+ if (hasProfile) {
+ AndroidCamcorderProfile camProfile = AndroidCamcorderProfile::get(m_cameraSession->camera()->cameraId(),
+ AndroidCamcorderProfile::Quality(id));
+
+ profile.outputFormat = AndroidMediaRecorder::OutputFormat(camProfile.getValue(AndroidCamcorderProfile::fileFormat));
+ profile.audioEncoder = AndroidMediaRecorder::AudioEncoder(camProfile.getValue(AndroidCamcorderProfile::audioCodec));
+ profile.audioBitRate = camProfile.getValue(AndroidCamcorderProfile::audioBitRate);
+ profile.audioChannels = camProfile.getValue(AndroidCamcorderProfile::audioChannels);
+ profile.audioSampleRate = camProfile.getValue(AndroidCamcorderProfile::audioSampleRate);
+ profile.videoEncoder = AndroidMediaRecorder::VideoEncoder(camProfile.getValue(AndroidCamcorderProfile::videoCodec));
+ profile.videoBitRate = camProfile.getValue(AndroidCamcorderProfile::videoBitRate);
+ profile.videoFrameRate = camProfile.getValue(AndroidCamcorderProfile::videoFrameRate);
+ profile.videoResolution = QSize(camProfile.getValue(AndroidCamcorderProfile::videoFrameWidth),
+ camProfile.getValue(AndroidCamcorderProfile::videoFrameHeight));
+
+ if (profile.outputFormat == AndroidMediaRecorder::MPEG_4)
+ profile.outputFileExtension = QStringLiteral("mp4");
+ else if (profile.outputFormat == AndroidMediaRecorder::THREE_GPP)
+ profile.outputFileExtension = QStringLiteral("3gp");
+ else if (profile.outputFormat == AndroidMediaRecorder::AMR_NB_Format)
+ profile.outputFileExtension = QStringLiteral("amr");
+ else if (profile.outputFormat == AndroidMediaRecorder::AMR_WB_Format)
+ profile.outputFileExtension = QStringLiteral("awb");
+
+ profile.isNull = false;
+ }
+
+ return profile;
+}
+
+void QAndroidCaptureSession::onError(int what, int extra)
+{
+ Q_UNUSED(what);
+ Q_UNUSED(extra);
+ stop(true);
+ updateError(QMediaRecorder::ResourceError, QLatin1String("Unknown error."));
+}
+
+void QAndroidCaptureSession::onInfo(int what, int extra)
+{
+ Q_UNUSED(extra);
+ if (what == 800) {
+ // MEDIA_RECORDER_INFO_MAX_DURATION_REACHED
+ stop();
+ updateError(QMediaRecorder::OutOfSpaceError, QLatin1String("Maximum duration reached."));
+ } else if (what == 801) {
+ // MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED
+ stop();
+ updateError(QMediaRecorder::OutOfSpaceError, QLatin1String("Maximum file size reached."));
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qandroidcapturesession_p.cpp"
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidcapturesession_p.h b/src/plugins/multimedia/android/mediacapture/qandroidcapturesession_p.h
new file mode 100644
index 000000000..161d47994
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidcapturesession_p.h
@@ -0,0 +1,158 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDCAPTURESESSION_H
+#define QANDROIDCAPTURESESSION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qobject.h>
+#include <qmediarecorder.h>
+#include <qurl.h>
+#include <qelapsedtimer.h>
+#include <qtimer.h>
+#include "androidmediarecorder_p.h"
+#include "qandroidmediaencoder_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QAudioInput;
+class QAndroidCameraSession;
+
+class QAndroidCaptureSession : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QAndroidCaptureSession();
+ ~QAndroidCaptureSession();
+
+ QList<QSize> supportedResolutions() const { return m_supportedResolutions; }
+ QList<qreal> supportedFrameRates() const { return m_supportedFramerates; }
+
+ void setCameraSession(QAndroidCameraSession *cameraSession = 0);
+ void setAudioInput(QPlatformAudioInput *input);
+ void setAudioOutput(QPlatformAudioOutput *output);
+
+ QMediaRecorder::RecorderState state() const;
+
+ void start(QMediaEncoderSettings &settings, const QUrl &outputLocation);
+ void stop(bool error = false);
+
+ qint64 duration() const;
+
+ QMediaEncoderSettings encoderSettings() { return m_encoderSettings; }
+
+ void setMediaEncoder(QAndroidMediaEncoder *encoder) { m_mediaEncoder = encoder; }
+
+ void stateChanged(QMediaRecorder::RecorderState state) {
+ if (m_mediaEncoder)
+ m_mediaEncoder->stateChanged(state);
+ }
+ void durationChanged(qint64 position)
+ {
+ if (m_mediaEncoder)
+ m_mediaEncoder->durationChanged(position);
+ }
+ void actualLocationChanged(const QUrl &location)
+ {
+ if (m_mediaEncoder)
+ m_mediaEncoder->actualLocationChanged(location);
+ }
+ void updateError(int error, const QString &errorString)
+ {
+ if (m_mediaEncoder)
+ m_mediaEncoder->updateError(QMediaRecorder::Error(error), errorString);
+ }
+
+private Q_SLOTS:
+ void updateDuration();
+ void onCameraOpened();
+
+ void onError(int what, int extra);
+ void onInfo(int what, int extra);
+
+private:
+ void applySettings(QMediaEncoderSettings &settings);
+
+ struct CaptureProfile {
+ AndroidMediaRecorder::OutputFormat outputFormat;
+ QString outputFileExtension;
+
+ AndroidMediaRecorder::AudioEncoder audioEncoder;
+ int audioBitRate;
+ int audioChannels;
+ int audioSampleRate;
+
+ AndroidMediaRecorder::VideoEncoder videoEncoder;
+ int videoBitRate;
+ int videoFrameRate;
+ QSize videoResolution;
+
+ bool isNull;
+
+ CaptureProfile()
+ : outputFormat(AndroidMediaRecorder::MPEG_4)
+ , outputFileExtension(QLatin1String("mp4"))
+ , audioEncoder(AndroidMediaRecorder::DefaultAudioEncoder)
+ , audioBitRate(128000)
+ , audioChannels(2)
+ , audioSampleRate(44100)
+ , videoEncoder(AndroidMediaRecorder::DefaultVideoEncoder)
+ , videoBitRate(1)
+ , videoFrameRate(-1)
+ , videoResolution(1280, 720)
+ , isNull(true)
+ { }
+ };
+
+ CaptureProfile getProfile(int id);
+
+ void restartViewfinder();
+ void updateStreamingState();
+
+ QAndroidMediaEncoder *m_mediaEncoder = nullptr;
+ std::shared_ptr<AndroidMediaRecorder> m_mediaRecorder;
+ QAndroidCameraSession *m_cameraSession;
+
+ QPlatformAudioInput *m_audioInput = nullptr;
+ QPlatformAudioOutput *m_audioOutput = nullptr;
+
+ QElapsedTimer m_elapsedTime;
+ QTimer m_notifyTimer;
+ qint64 m_duration;
+
+ QMediaRecorder::RecorderState m_state;
+ QUrl m_usedOutputLocation;
+ bool m_outputLocationIsStandard = false;
+
+ CaptureProfile m_defaultSettings;
+
+ QMediaEncoderSettings m_encoderSettings;
+ AndroidMediaRecorder::OutputFormat m_outputFormat;
+ AndroidMediaRecorder::AudioEncoder m_audioEncoder;
+ AndroidMediaRecorder::VideoEncoder m_videoEncoder;
+
+ QList<QSize> m_supportedResolutions;
+ QList<qreal> m_supportedFramerates;
+
+ QMetaObject::Connection m_audioInputChanged;
+ QMetaObject::Connection m_audioOutputChanged;
+ QMetaObject::Connection m_connOpenCamera;
+ QMetaObject::Connection m_connActiveChangedCamera;
+
+ void setKeepAlive(bool keepAlive);
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDCAPTURESESSION_H
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidimagecapture.cpp b/src/plugins/multimedia/android/mediacapture/qandroidimagecapture.cpp
new file mode 100644
index 000000000..4105851ed
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidimagecapture.cpp
@@ -0,0 +1,73 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidimagecapture_p.h"
+
+#include "qandroidcamerasession_p.h"
+#include "qandroidmediacapturesession_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QAndroidImageCapture::QAndroidImageCapture(QImageCapture *parent)
+ : QPlatformImageCapture(parent)
+{
+}
+
+bool QAndroidImageCapture::isReadyForCapture() const
+{
+ return m_session->isReadyForCapture();
+}
+
+int QAndroidImageCapture::capture(const QString &fileName)
+{
+ return m_session->capture(fileName);
+}
+
+int QAndroidImageCapture::captureToBuffer()
+{
+ return m_session->captureToBuffer();
+}
+
+QImageEncoderSettings QAndroidImageCapture::imageSettings() const
+{
+ return m_session->imageSettings();
+}
+
+void QAndroidImageCapture::setImageSettings(const QImageEncoderSettings &settings)
+{
+ m_session->setImageSettings(settings);
+}
+
+void QAndroidImageCapture::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ QAndroidMediaCaptureSession *captureSession = static_cast<QAndroidMediaCaptureSession *>(session);
+ if (m_service == captureSession)
+ return;
+
+ m_service = captureSession;
+ if (!m_service) {
+ disconnect(m_session, nullptr, this, nullptr);
+ return;
+ }
+
+ m_session = m_service->cameraSession();
+ Q_ASSERT(m_session);
+
+ connect(m_session, &QAndroidCameraSession::readyForCaptureChanged,
+ this, &QAndroidImageCapture::readyForCaptureChanged);
+ connect(m_session, &QAndroidCameraSession::imageExposed,
+ this, &QAndroidImageCapture::imageExposed);
+ connect(m_session, &QAndroidCameraSession::imageCaptured,
+ this, &QAndroidImageCapture::imageCaptured);
+ connect(m_session, &QAndroidCameraSession::imageMetadataAvailable,
+ this, &QAndroidImageCapture::imageMetadataAvailable);
+ connect(m_session, &QAndroidCameraSession::imageAvailable,
+ this, &QAndroidImageCapture::imageAvailable);
+ connect(m_session, &QAndroidCameraSession::imageSaved,
+ this, &QAndroidImageCapture::imageSaved);
+ connect(m_session, &QAndroidCameraSession::imageCaptureError,
+ this, &QAndroidImageCapture::error);
+}
+QT_END_NAMESPACE
+
+#include "moc_qandroidimagecapture_p.cpp"
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidimagecapture_p.h b/src/plugins/multimedia/android/mediacapture/qandroidimagecapture_p.h
new file mode 100644
index 000000000..ac273c195
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidimagecapture_p.h
@@ -0,0 +1,48 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDCAMERAIMAGECAPTURECONTROL_H
+#define QANDROIDCAMERAIMAGECAPTURECONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformimagecapture_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidCameraSession;
+class QAndroidMediaCaptureSession;
+
+class QAndroidImageCapture : public QPlatformImageCapture
+{
+ Q_OBJECT
+public:
+ explicit QAndroidImageCapture(QImageCapture *parent = nullptr);
+
+ bool isReadyForCapture() const override;
+
+ int capture(const QString &fileName) override;
+ int captureToBuffer() override;
+
+ QImageEncoderSettings imageSettings() const override;
+ void setImageSettings(const QImageEncoderSettings &settings) override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session);
+
+private:
+ QAndroidCameraSession *m_session;
+ QAndroidMediaCaptureSession *m_service;
+};
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDCAMERAIMAGECAPTURECONTROL_H
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidmediacapturesession.cpp b/src/plugins/multimedia/android/mediacapture/qandroidmediacapturesession.cpp
new file mode 100644
index 000000000..e2b551d35
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidmediacapturesession.cpp
@@ -0,0 +1,115 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 Ruslan Baratov
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidmediacapturesession_p.h"
+
+#include "qandroidmediaencoder_p.h"
+#include "qandroidcapturesession_p.h"
+#include "qandroidcamera_p.h"
+#include "qandroidcamerasession_p.h"
+#include "qandroidimagecapture_p.h"
+#include "qmediadevices.h"
+#include "qaudiodevice.h"
+
+QT_BEGIN_NAMESPACE
+
+QAndroidMediaCaptureSession::QAndroidMediaCaptureSession()
+ : m_captureSession(new QAndroidCaptureSession())
+ , m_cameraSession(new QAndroidCameraSession())
+{
+}
+
+QAndroidMediaCaptureSession::~QAndroidMediaCaptureSession()
+{
+ delete m_captureSession;
+ delete m_cameraSession;
+}
+
+QPlatformCamera *QAndroidMediaCaptureSession::camera()
+{
+ return m_cameraControl;
+}
+
+void QAndroidMediaCaptureSession::setCamera(QPlatformCamera *camera)
+{
+ if (camera) {
+ m_captureSession->setCameraSession(m_cameraSession);
+ } else {
+ m_captureSession->setCameraSession(nullptr);
+ }
+
+ QAndroidCamera *control = static_cast<QAndroidCamera *>(camera);
+ if (m_cameraControl == control)
+ return;
+
+ if (m_cameraControl)
+ m_cameraControl->setCaptureSession(nullptr);
+
+ m_cameraControl = control;
+ if (m_cameraControl)
+ m_cameraControl->setCaptureSession(this);
+
+ emit cameraChanged();
+}
+
+QPlatformImageCapture *QAndroidMediaCaptureSession::imageCapture()
+{
+ return m_imageCaptureControl;
+}
+
+void QAndroidMediaCaptureSession::setImageCapture(QPlatformImageCapture *imageCapture)
+{
+ QAndroidImageCapture *control = static_cast<QAndroidImageCapture *>(imageCapture);
+ if (m_imageCaptureControl == control)
+ return;
+
+ if (m_imageCaptureControl)
+ m_imageCaptureControl->setCaptureSession(nullptr);
+
+ m_imageCaptureControl = control;
+ if (m_imageCaptureControl)
+ m_imageCaptureControl->setCaptureSession(this);
+}
+
+QPlatformMediaRecorder *QAndroidMediaCaptureSession::mediaRecorder()
+{
+ return m_encoder;
+}
+
+void QAndroidMediaCaptureSession::setMediaRecorder(QPlatformMediaRecorder *recorder)
+{
+ QAndroidMediaEncoder *control = static_cast<QAndroidMediaEncoder *>(recorder);
+
+ if (m_encoder == control)
+ return;
+
+ if (m_encoder)
+ m_encoder->setCaptureSession(nullptr);
+
+ m_encoder = control;
+ if (m_encoder)
+ m_encoder->setCaptureSession(this);
+
+ emit encoderChanged();
+
+}
+
+void QAndroidMediaCaptureSession::setAudioInput(QPlatformAudioInput *input)
+{
+ m_captureSession->setAudioInput(input);
+}
+
+void QAndroidMediaCaptureSession::setAudioOutput(QPlatformAudioOutput *output)
+{
+ m_captureSession->setAudioOutput(output);
+}
+
+void QAndroidMediaCaptureSession::setVideoPreview(QVideoSink *sink)
+{
+ m_cameraSession->setVideoSink(sink);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qandroidmediacapturesession_p.cpp"
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidmediacapturesession_p.h b/src/plugins/multimedia/android/mediacapture/qandroidmediacapturesession_p.h
new file mode 100644
index 000000000..90c792c32
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidmediacapturesession_p.h
@@ -0,0 +1,66 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 Ruslan Baratov
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDCAPTURESERVICE_H
+#define QANDROIDCAPTURESERVICE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediacapture_p.h>
+#include <private/qplatformmediaintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidMediaEncoder;
+class QAndroidCaptureSession;
+class QAndroidCamera;
+class QAndroidCameraSession;
+class QAndroidImageCapture;
+
+class QAndroidMediaCaptureSession : public QPlatformMediaCaptureSession
+{
+ Q_OBJECT
+
+public:
+ explicit QAndroidMediaCaptureSession();
+ virtual ~QAndroidMediaCaptureSession();
+
+ QPlatformCamera *camera() override;
+ void setCamera(QPlatformCamera *camera) override;
+
+ QPlatformImageCapture *imageCapture() override;
+ void setImageCapture(QPlatformImageCapture *imageCapture) override;
+
+ QPlatformMediaRecorder *mediaRecorder() override;
+ void setMediaRecorder(QPlatformMediaRecorder *recorder) override;
+
+ void setAudioInput(QPlatformAudioInput *input) override;
+
+ void setVideoPreview(QVideoSink *sink) override;
+
+ void setAudioOutput(QPlatformAudioOutput *output) override;
+
+ QAndroidCaptureSession *captureSession() const { return m_captureSession; }
+ QAndroidCameraSession *cameraSession() const { return m_cameraSession; }
+
+private:
+ QAndroidMediaEncoder *m_encoder = nullptr;
+ QAndroidCaptureSession *m_captureSession = nullptr;
+ QAndroidCamera *m_cameraControl = nullptr;
+ QAndroidCameraSession *m_cameraSession = nullptr;
+ QAndroidImageCapture *m_imageCaptureControl = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDCAPTURESERVICE_H
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidmediaencoder.cpp b/src/plugins/multimedia/android/mediacapture/qandroidmediaencoder.cpp
new file mode 100644
index 000000000..d3449312d
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidmediaencoder.cpp
@@ -0,0 +1,72 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidmediaencoder_p.h"
+#include "qandroidmultimediautils_p.h"
+#include "qandroidcapturesession_p.h"
+#include "qandroidmediacapturesession_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QAndroidMediaEncoder::QAndroidMediaEncoder(QMediaRecorder *parent)
+ : QPlatformMediaRecorder(parent)
+{
+}
+
+bool QAndroidMediaEncoder::isLocationWritable(const QUrl &location) const
+{
+ return location.isValid()
+ && (location.isLocalFile() || location.isRelative());
+}
+
+QMediaRecorder::RecorderState QAndroidMediaEncoder::state() const
+{
+ return m_session ? m_session->state() : QMediaRecorder::StoppedState;
+}
+
+qint64 QAndroidMediaEncoder::duration() const
+{
+ return m_session ? m_session->duration() : 0;
+
+}
+
+void QAndroidMediaEncoder::record(QMediaEncoderSettings &settings)
+{
+ if (m_session)
+ m_session->start(settings, outputLocation());
+}
+
+void QAndroidMediaEncoder::stop()
+{
+ if (m_session)
+ m_session->stop();
+}
+
+void QAndroidMediaEncoder::setOutputLocation(const QUrl &location)
+{
+ if (location.isLocalFile()) {
+ qt_androidRequestWriteStoragePermission();
+ }
+ QPlatformMediaRecorder::setOutputLocation(location);
+}
+
+void QAndroidMediaEncoder::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ QAndroidMediaCaptureSession *captureSession = static_cast<QAndroidMediaCaptureSession *>(session);
+ if (m_service == captureSession)
+ return;
+
+ if (m_service)
+ stop();
+ if (m_session)
+ m_session->setMediaEncoder(nullptr);
+
+ m_service = captureSession;
+ if (!m_service)
+ return;
+ m_session = m_service->captureSession();
+ Q_ASSERT(m_session);
+ m_session->setMediaEncoder(this);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/android/mediacapture/qandroidmediaencoder_p.h b/src/plugins/multimedia/android/mediacapture/qandroidmediaencoder_p.h
new file mode 100644
index 000000000..b46268449
--- /dev/null
+++ b/src/plugins/multimedia/android/mediacapture/qandroidmediaencoder_p.h
@@ -0,0 +1,50 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDMEDIAENCODER_H
+#define QANDROIDMEDIAENCODER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediarecorder_p.h>
+#include <private/qplatformmediacapture_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidCaptureSession;
+class QAndroidMediaCaptureSession;
+
+class QAndroidMediaEncoder : public QPlatformMediaRecorder
+{
+public:
+ explicit QAndroidMediaEncoder(QMediaRecorder *parent);
+
+ bool isLocationWritable(const QUrl &location) const override;
+ QMediaRecorder::RecorderState state() const override;
+ qint64 duration() const override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session);
+
+ void setOutputLocation(const QUrl &location) override;
+ void record(QMediaEncoderSettings &settings) override;
+ void stop() override;
+
+private:
+ friend class QAndroidCaptureSession;
+
+ QAndroidCaptureSession *m_session = nullptr;
+ QAndroidMediaCaptureSession *m_service = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDMEDIAENCODER_H
diff --git a/src/plugins/multimedia/android/mediaplayer/qandroidmediaplayer.cpp b/src/plugins/multimedia/android/mediaplayer/qandroidmediaplayer.cpp
new file mode 100644
index 000000000..b257a8986
--- /dev/null
+++ b/src/plugins/multimedia/android/mediaplayer/qandroidmediaplayer.cpp
@@ -0,0 +1,999 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidmediaplayer_p.h"
+#include "androidmediaplayer_p.h"
+#include "qandroidvideooutput_p.h"
+#include "qandroidmetadata_p.h"
+#include "qandroidaudiooutput_p.h"
+#include "qaudiooutput.h"
+
+#include <private/qplatformvideosink_p.h>
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(lcMediaPlayer, "qt.multimedia.mediaplayer.android")
+
+class StateChangeNotifier
+{
+public:
+ StateChangeNotifier(QAndroidMediaPlayer *mp)
+ : mControl(mp)
+ , mPreviousState(mp->state())
+ , mPreviousMediaStatus(mp->mediaStatus())
+ {
+ ++mControl->mActiveStateChangeNotifiers;
+ }
+
+ ~StateChangeNotifier()
+ {
+ if (--mControl->mActiveStateChangeNotifiers)
+ return;
+
+ if (mPreviousMediaStatus != mControl->mediaStatus())
+ Q_EMIT mControl->mediaStatusChanged(mControl->mediaStatus());
+
+ if (mPreviousState != mControl->state())
+ Q_EMIT mControl->stateChanged(mControl->state());
+ }
+
+private:
+ QAndroidMediaPlayer *mControl;
+ QMediaPlayer::PlaybackState mPreviousState;
+ QMediaPlayer::MediaStatus mPreviousMediaStatus;
+};
+
+QAndroidMediaPlayer::QAndroidMediaPlayer(QMediaPlayer *parent)
+ : QPlatformMediaPlayer(parent),
+ mMediaPlayer(new AndroidMediaPlayer),
+ mState(AndroidMediaPlayer::Uninitialized)
+{
+ // Set seekable to True by default. It changes if MEDIA_INFO_NOT_SEEKABLE is received
+ seekableChanged(true);
+ connect(mMediaPlayer, &AndroidMediaPlayer::bufferingChanged, this,
+ &QAndroidMediaPlayer::onBufferingChanged);
+ connect(mMediaPlayer, &AndroidMediaPlayer::info, this, &QAndroidMediaPlayer::onInfo);
+ connect(mMediaPlayer, &AndroidMediaPlayer::error, this, &QAndroidMediaPlayer::onError);
+ connect(mMediaPlayer, &AndroidMediaPlayer::stateChanged, this,
+ &QAndroidMediaPlayer::onStateChanged);
+ connect(mMediaPlayer, &AndroidMediaPlayer::videoSizeChanged, this,
+ &QAndroidMediaPlayer::onVideoSizeChanged);
+ connect(mMediaPlayer, &AndroidMediaPlayer::progressChanged, this,
+ &QAndroidMediaPlayer::positionChanged);
+ connect(mMediaPlayer, &AndroidMediaPlayer::durationChanged, this,
+ &QAndroidMediaPlayer::durationChanged);
+ connect(mMediaPlayer, &AndroidMediaPlayer::tracksInfoChanged, this,
+ &QAndroidMediaPlayer::updateTrackInfo);
+}
+
+QAndroidMediaPlayer::~QAndroidMediaPlayer()
+{
+ if (m_videoSink)
+ disconnect(m_videoSink->platformVideoSink(), nullptr, this, nullptr);
+
+ mMediaPlayer->disconnect();
+ mMediaPlayer->release();
+ delete mMediaPlayer;
+}
+
+qint64 QAndroidMediaPlayer::duration() const
+{
+ if (mediaStatus() == QMediaPlayer::NoMedia)
+ return 0;
+
+ if ((mState & (AndroidMediaPlayer::Prepared
+ | AndroidMediaPlayer::Started
+ | AndroidMediaPlayer::Paused
+ | AndroidMediaPlayer::Stopped
+ | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
+ return 0;
+ }
+
+ return mMediaPlayer->getDuration();
+}
+
+qint64 QAndroidMediaPlayer::position() const
+{
+ if (mediaStatus() == QMediaPlayer::EndOfMedia)
+ return duration();
+
+ if ((mState & (AndroidMediaPlayer::Prepared
+ | AndroidMediaPlayer::Started
+ | AndroidMediaPlayer::Paused
+ | AndroidMediaPlayer::PlaybackCompleted))) {
+ return mMediaPlayer->getCurrentPosition();
+ }
+
+ return (mPendingPosition == -1) ? 0 : mPendingPosition;
+}
+
+void QAndroidMediaPlayer::setPosition(qint64 position)
+{
+ if (!isSeekable())
+ return;
+
+ const int seekPosition = (position > INT_MAX) ? INT_MAX : position;
+
+ qint64 currentPosition = mMediaPlayer->getCurrentPosition();
+ if (seekPosition == currentPosition) {
+ // update position - will send a new frame of this position
+ // for consistency with other platforms
+ mMediaPlayer->seekTo(seekPosition);
+ return;
+ }
+ StateChangeNotifier notifier(this);
+
+ if (mediaStatus() == QMediaPlayer::EndOfMedia)
+ setMediaStatus(QMediaPlayer::LoadedMedia);
+
+ if ((mState & (AndroidMediaPlayer::Prepared
+ | AndroidMediaPlayer::Started
+ | AndroidMediaPlayer::Paused
+ | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
+ mPendingPosition = seekPosition;
+ } else {
+ mMediaPlayer->seekTo(seekPosition);
+
+ if (mPendingPosition != -1) {
+ mPendingPosition = -1;
+ }
+ }
+
+ Q_EMIT positionChanged(seekPosition);
+}
+
+void QAndroidMediaPlayer::setVolume(float volume)
+{
+ if ((mState & (AndroidMediaPlayer::Idle
+ | AndroidMediaPlayer::Initialized
+ | AndroidMediaPlayer::Stopped
+ | AndroidMediaPlayer::Prepared
+ | AndroidMediaPlayer::Started
+ | AndroidMediaPlayer::Paused
+ | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
+ mPendingVolume = volume;
+ return;
+ }
+
+ mMediaPlayer->setVolume(qRound(volume*100.));
+ mPendingVolume = -1;
+}
+
+void QAndroidMediaPlayer::setMuted(bool muted)
+{
+ if ((mState & (AndroidMediaPlayer::Idle
+ | AndroidMediaPlayer::Initialized
+ | AndroidMediaPlayer::Stopped
+ | AndroidMediaPlayer::Prepared
+ | AndroidMediaPlayer::Started
+ | AndroidMediaPlayer::Paused
+ | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
+ mPendingMute = muted;
+ return;
+ }
+
+ mMediaPlayer->setMuted(muted);
+ mPendingMute = -1;
+}
+
+QMediaMetaData QAndroidMediaPlayer::metaData() const
+{
+ return QAndroidMetaData::extractMetadata(mMediaContent);
+}
+
+float QAndroidMediaPlayer::bufferProgress() const
+{
+ return mBufferFilled ? 1. : mBufferPercent;
+}
+
+bool QAndroidMediaPlayer::isAudioAvailable() const
+{
+ return mAudioAvailable;
+}
+
+bool QAndroidMediaPlayer::isVideoAvailable() const
+{
+ return mVideoAvailable;
+}
+
+QMediaTimeRange QAndroidMediaPlayer::availablePlaybackRanges() const
+{
+ return mAvailablePlaybackRange;
+}
+
+void QAndroidMediaPlayer::updateAvailablePlaybackRanges()
+{
+ if (mBuffering) {
+ const qint64 pos = position();
+ const qint64 end = (duration() / 100) * mBufferPercent;
+ mAvailablePlaybackRange.addInterval(pos, end);
+ } else if (isSeekable()) {
+ mAvailablePlaybackRange = QMediaTimeRange(0, duration());
+ } else {
+ mAvailablePlaybackRange = QMediaTimeRange();
+ }
+
+// #### Q_EMIT availablePlaybackRangesChanged(mAvailablePlaybackRange);
+}
+
+qreal QAndroidMediaPlayer::playbackRate() const
+{
+ return mCurrentPlaybackRate;
+}
+
+void QAndroidMediaPlayer::setPlaybackRate(qreal rate)
+{
+ if (mState != AndroidMediaPlayer::Started) {
+ // If video isn't playing, changing speed rate may start it automatically
+ // It need to be postponed
+ if (mCurrentPlaybackRate != rate) {
+ mCurrentPlaybackRate = rate;
+ mHasPendingPlaybackRate = true;
+ Q_EMIT playbackRateChanged(rate);
+ }
+ return;
+ }
+
+ if (mMediaPlayer->setPlaybackRate(rate)) {
+ mCurrentPlaybackRate = rate;
+ Q_EMIT playbackRateChanged(rate);
+ }
+}
+
+QUrl QAndroidMediaPlayer::media() const
+{
+ return mMediaContent;
+}
+
+const QIODevice *QAndroidMediaPlayer::mediaStream() const
+{
+ return mMediaStream;
+}
+
+void QAndroidMediaPlayer::setMedia(const QUrl &mediaContent,
+ QIODevice *stream)
+{
+ StateChangeNotifier notifier(this);
+
+ mReloadingMedia = (mMediaContent == mediaContent) && !mPendingSetMedia;
+
+ if (!mReloadingMedia) {
+ mMediaContent = mediaContent;
+ mMediaStream = stream;
+ }
+
+ if (mediaContent.isEmpty()) {
+ setMediaStatus(QMediaPlayer::NoMedia);
+ } else {
+ if (mVideoOutput && !mVideoOutput->isReady()) {
+ // if a video output is set but the video texture is not ready, delay loading the media
+ // since it can cause problems on some hardware
+ mPendingSetMedia = true;
+ return;
+ }
+
+ if (mVideoSize.isValid() && mVideoOutput)
+ mVideoOutput->setVideoSize(mVideoSize);
+
+ if (mVideoOutput &&
+ (mMediaPlayer->display() == 0 || mVideoOutput->shouldTextureBeUpdated()))
+ mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture());
+ mMediaPlayer->setDataSource(QNetworkRequest(mediaContent));
+ mMediaPlayer->prepareAsync();
+
+ if (!mReloadingMedia)
+ setMediaStatus(QMediaPlayer::LoadingMedia);
+ }
+
+ resetBufferingProgress();
+
+ mReloadingMedia = false;
+}
+
+void QAndroidMediaPlayer::setVideoSink(QVideoSink *sink)
+{
+ if (m_videoSink == sink)
+ return;
+
+ if (m_videoSink)
+ disconnect(m_videoSink->platformVideoSink(), nullptr, this, nullptr);
+
+ m_videoSink = sink;
+
+ if (!m_videoSink) {
+ return;
+ }
+
+ if (mVideoOutput) {
+ delete mVideoOutput;
+ mVideoOutput = nullptr;
+ mMediaPlayer->setDisplay(nullptr);
+ }
+
+ mVideoOutput = new QAndroidTextureVideoOutput(sink, this);
+ connect(mVideoOutput, &QAndroidTextureVideoOutput::readyChanged, this,
+ &QAndroidMediaPlayer::onVideoOutputReady);
+ connect(mMediaPlayer, &AndroidMediaPlayer::timedTextChanged, mVideoOutput,
+ &QAndroidTextureVideoOutput::setSubtitle);
+
+ if (mVideoOutput->isReady())
+ mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture());
+
+ connect(m_videoSink->platformVideoSink(), &QPlatformVideoSink::rhiChanged, this, [&]()
+ { mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture()); });
+}
+
+void QAndroidMediaPlayer::setAudioOutput(QPlatformAudioOutput *output)
+{
+ if (m_audioOutput == output)
+ return;
+ if (m_audioOutput)
+ m_audioOutput->q->disconnect(this);
+ m_audioOutput = static_cast<QAndroidAudioOutput *>(output);
+ if (m_audioOutput) {
+ connect(m_audioOutput->q, &QAudioOutput::deviceChanged, this, &QAndroidMediaPlayer::updateAudioDevice);
+ connect(m_audioOutput->q, &QAudioOutput::volumeChanged, this, &QAndroidMediaPlayer::setVolume);
+ connect(m_audioOutput->q, &QAudioOutput::mutedChanged, this, &QAndroidMediaPlayer::setMuted);
+ updateAudioDevice();
+ }
+}
+
+void QAndroidMediaPlayer::updateAudioDevice()
+{
+ if (m_audioOutput)
+ mMediaPlayer->setAudioOutput(m_audioOutput->device.id());
+}
+
+void QAndroidMediaPlayer::play()
+{
+ StateChangeNotifier notifier(this);
+
+ resetCurrentLoop();
+
+ // We need to prepare the mediaplayer again.
+ if ((mState & AndroidMediaPlayer::Stopped) && !mMediaContent.isEmpty()) {
+ setMedia(mMediaContent, mMediaStream);
+ }
+
+ if (!mMediaContent.isEmpty())
+ stateChanged(QMediaPlayer::PlayingState);
+
+ if ((mState & (AndroidMediaPlayer::Prepared
+ | AndroidMediaPlayer::Started
+ | AndroidMediaPlayer::Paused
+ | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
+ mPendingState = QMediaPlayer::PlayingState;
+ return;
+ }
+
+ if (mVideoOutput)
+ mVideoOutput->start();
+
+ updateAudioDevice();
+
+ if (mHasPendingPlaybackRate) {
+ mHasPendingPlaybackRate = false;
+ if (mMediaPlayer->setPlaybackRate(mCurrentPlaybackRate))
+ return;
+ mCurrentPlaybackRate = mMediaPlayer->playbackRate();
+ Q_EMIT playbackRateChanged(mCurrentPlaybackRate);
+ }
+
+ mMediaPlayer->play();
+}
+
+void QAndroidMediaPlayer::pause()
+{
+ // cannot pause without media
+ if (mediaStatus() == QMediaPlayer::NoMedia)
+ return;
+
+ StateChangeNotifier notifier(this);
+
+ stateChanged(QMediaPlayer::PausedState);
+
+ if ((mState & (AndroidMediaPlayer::Started
+ | AndroidMediaPlayer::Paused
+ | AndroidMediaPlayer::PlaybackCompleted
+ | AndroidMediaPlayer::Prepared
+ | AndroidMediaPlayer::Stopped)) == 0) {
+ mPendingState = QMediaPlayer::PausedState;
+ return;
+ }
+
+ const qint64 currentPosition = mMediaPlayer->getCurrentPosition();
+ setPosition(currentPosition);
+
+ mMediaPlayer->pause();
+}
+
+void QAndroidMediaPlayer::stop()
+{
+ StateChangeNotifier notifier(this);
+
+ stateChanged(QMediaPlayer::StoppedState);
+
+ if ((mState & (AndroidMediaPlayer::Prepared
+ | AndroidMediaPlayer::Started
+ | AndroidMediaPlayer::Stopped
+ | AndroidMediaPlayer::Paused
+ | AndroidMediaPlayer::PlaybackCompleted)) == 0) {
+ if ((mState & (AndroidMediaPlayer::Idle | AndroidMediaPlayer::Uninitialized | AndroidMediaPlayer::Error)) == 0)
+ mPendingState = QMediaPlayer::StoppedState;
+ return;
+ }
+
+ if (mCurrentPlaybackRate != 1.)
+ // Playback rate need to by reapplied
+ mHasPendingPlaybackRate = true;
+
+ if (mVideoOutput)
+ mVideoOutput->stop();
+
+ mMediaPlayer->stop();
+}
+
+void QAndroidMediaPlayer::onInfo(qint32 what, qint32 extra)
+{
+ StateChangeNotifier notifier(this);
+
+ Q_UNUSED(extra);
+ switch (what) {
+ case AndroidMediaPlayer::MEDIA_INFO_UNKNOWN:
+ break;
+ case AndroidMediaPlayer::MEDIA_INFO_VIDEO_TRACK_LAGGING:
+ // IGNORE
+ break;
+ case AndroidMediaPlayer::MEDIA_INFO_VIDEO_RENDERING_START:
+ break;
+ case AndroidMediaPlayer::MEDIA_INFO_BUFFERING_START:
+ mPendingState = state();
+ stateChanged(QMediaPlayer::PausedState);
+ setMediaStatus(QMediaPlayer::StalledMedia);
+ break;
+ case AndroidMediaPlayer::MEDIA_INFO_BUFFERING_END:
+ if (state() != QMediaPlayer::StoppedState)
+ flushPendingStates();
+ break;
+ case AndroidMediaPlayer::MEDIA_INFO_BAD_INTERLEAVING:
+ break;
+ case AndroidMediaPlayer::MEDIA_INFO_NOT_SEEKABLE:
+ seekableChanged(false);
+ break;
+ case AndroidMediaPlayer::MEDIA_INFO_METADATA_UPDATE:
+ Q_EMIT metaDataChanged();
+ break;
+ }
+}
+
+void QAndroidMediaPlayer::onError(qint32 what, qint32 extra)
+{
+ StateChangeNotifier notifier(this);
+
+ QString errorString;
+ QMediaPlayer::Error error = QMediaPlayer::ResourceError;
+
+ switch (what) {
+ case AndroidMediaPlayer::MEDIA_ERROR_UNKNOWN:
+ errorString = QLatin1String("Error:");
+ break;
+ case AndroidMediaPlayer::MEDIA_ERROR_SERVER_DIED:
+ errorString = QLatin1String("Error: Server died");
+ error = QMediaPlayer::ResourceError;
+ break;
+ case AndroidMediaPlayer::MEDIA_ERROR_INVALID_STATE:
+ errorString = QLatin1String("Error: Invalid state");
+ error = QMediaPlayer::ResourceError;
+ break;
+ }
+
+ switch (extra) {
+ case AndroidMediaPlayer::MEDIA_ERROR_IO: // Network OR file error
+ errorString += QLatin1String(" (I/O operation failed)");
+ error = QMediaPlayer::NetworkError;
+ setMediaStatus(QMediaPlayer::InvalidMedia);
+ break;
+ case AndroidMediaPlayer::MEDIA_ERROR_MALFORMED:
+ errorString += QLatin1String(" (Malformed bitstream)");
+ error = QMediaPlayer::FormatError;
+ setMediaStatus(QMediaPlayer::InvalidMedia);
+ break;
+ case AndroidMediaPlayer::MEDIA_ERROR_UNSUPPORTED:
+ errorString += QLatin1String(" (Unsupported media)");
+ error = QMediaPlayer::FormatError;
+ setMediaStatus(QMediaPlayer::InvalidMedia);
+ break;
+ case AndroidMediaPlayer::MEDIA_ERROR_TIMED_OUT:
+ errorString += QLatin1String(" (Timed out)");
+ break;
+ case AndroidMediaPlayer::MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
+ errorString += QLatin1String(" (Unable to start progressive playback')");
+ error = QMediaPlayer::FormatError;
+ setMediaStatus(QMediaPlayer::InvalidMedia);
+ break;
+ case AndroidMediaPlayer::MEDIA_ERROR_BAD_THINGS_ARE_GOING_TO_HAPPEN:
+ errorString += mMediaContent.scheme() == QLatin1String("rtsp")
+ ? QLatin1String(" (Unknown error/Insufficient resources or RTSP may not be supported)")
+ : QLatin1String(" (Unknown error/Insufficient resources)");
+ error = QMediaPlayer::ResourceError;
+ break;
+ }
+
+ Q_EMIT QPlatformMediaPlayer::error(error, errorString);
+}
+
+void QAndroidMediaPlayer::onBufferingChanged(qint32 percent)
+{
+ StateChangeNotifier notifier(this);
+
+ mBuffering = percent != 100;
+ mBufferPercent = percent;
+
+ updateAvailablePlaybackRanges();
+
+ if (state() != QMediaPlayer::StoppedState)
+ setMediaStatus(mBuffering ? QMediaPlayer::BufferingMedia : QMediaPlayer::BufferedMedia);
+
+ updateBufferStatus();
+}
+
+void QAndroidMediaPlayer::onVideoSizeChanged(qint32 width, qint32 height)
+{
+ QSize newSize(width, height);
+
+ if (width == 0 || height == 0 || newSize == mVideoSize)
+ return;
+
+ setVideoAvailable(true);
+ mVideoSize = newSize;
+
+ if (mVideoOutput)
+ mVideoOutput->setVideoSize(mVideoSize);
+}
+
+void QAndroidMediaPlayer::onStateChanged(qint32 state)
+{
+ // If reloading, don't report state changes unless the new state is Prepared or Error.
+ if ((mState & AndroidMediaPlayer::Stopped)
+ && (state & (AndroidMediaPlayer::Prepared | AndroidMediaPlayer::Error | AndroidMediaPlayer::Uninitialized)) == 0) {
+ return;
+ }
+
+ StateChangeNotifier notifier(this);
+
+ mState = state;
+ switch (mState) {
+ case AndroidMediaPlayer::Idle:
+ break;
+ case AndroidMediaPlayer::Initialized:
+ break;
+ case AndroidMediaPlayer::Preparing:
+ if (!mReloadingMedia)
+ setMediaStatus(QMediaPlayer::LoadingMedia);
+ break;
+ case AndroidMediaPlayer::Prepared:
+ setMediaStatus(QMediaPlayer::LoadedMedia);
+ if (mBuffering) {
+ setMediaStatus(mBufferPercent == 100 ? QMediaPlayer::BufferedMedia
+ : QMediaPlayer::BufferingMedia);
+ } else {
+ onBufferingChanged(100);
+ }
+ setPosition(0);
+ Q_EMIT metaDataChanged();
+ setAudioAvailable(true);
+ flushPendingStates();
+ break;
+ case AndroidMediaPlayer::Started:
+ stateChanged(QMediaPlayer::PlayingState);
+ if (mBuffering) {
+ setMediaStatus(mBufferPercent == 100 ? QMediaPlayer::BufferedMedia
+ : QMediaPlayer::BufferingMedia);
+ } else {
+ setMediaStatus(QMediaPlayer::BufferedMedia);
+ }
+ Q_EMIT positionChanged(position());
+ break;
+ case AndroidMediaPlayer::Paused:
+ stateChanged(QMediaPlayer::PausedState);
+ if (mediaStatus() == QMediaPlayer::EndOfMedia) {
+ setPosition(0);
+ setMediaStatus(QMediaPlayer::BufferedMedia);
+ } else {
+ Q_EMIT positionChanged(position());
+ }
+ break;
+ case AndroidMediaPlayer::Error:
+ stateChanged(QMediaPlayer::StoppedState);
+ setMediaStatus(QMediaPlayer::InvalidMedia);
+ mMediaPlayer->release();
+ Q_EMIT positionChanged(0);
+ break;
+ case AndroidMediaPlayer::Stopped:
+ stateChanged(QMediaPlayer::StoppedState);
+ setMediaStatus(QMediaPlayer::LoadedMedia);
+ Q_EMIT positionChanged(0);
+ break;
+ case AndroidMediaPlayer::PlaybackCompleted:
+ if (doLoop()) {
+ setPosition(0);
+ mMediaPlayer->play();
+ break;
+ }
+ stateChanged(QMediaPlayer::StoppedState);
+ setMediaStatus(QMediaPlayer::EndOfMedia);
+ break;
+ case AndroidMediaPlayer::Uninitialized:
+ // reset some properties (unless we reload the same media)
+ if (!mReloadingMedia) {
+ resetBufferingProgress();
+ mPendingPosition = -1;
+ mPendingSetMedia = false;
+ mPendingState = -1;
+
+ Q_EMIT durationChanged(0);
+ Q_EMIT positionChanged(0);
+
+ setAudioAvailable(false);
+ setVideoAvailable(false);
+ seekableChanged(true);
+ }
+ break;
+ default:
+ break;
+ }
+
+ if ((mState & (AndroidMediaPlayer::Stopped | AndroidMediaPlayer::Uninitialized)) != 0) {
+ mMediaPlayer->setDisplay(0);
+ if (mVideoOutput) {
+ mVideoOutput->stop();
+ }
+ }
+}
+
+int QAndroidMediaPlayer::trackCount(TrackType trackType)
+{
+ if (!mTracksMetadata.contains(trackType))
+ return -1;
+
+ auto tracks = mTracksMetadata.value(trackType);
+ return tracks.count();
+}
+
+QMediaMetaData QAndroidMediaPlayer::trackMetaData(TrackType trackType, int streamNumber)
+{
+ if (!mTracksMetadata.contains(trackType))
+ return QMediaMetaData();
+
+ auto tracks = mTracksMetadata.value(trackType);
+ if (tracks.count() < streamNumber)
+ return QMediaMetaData();
+
+ QAndroidMetaData trackInfo = tracks.at(streamNumber);
+ return static_cast<QMediaMetaData>(trackInfo);
+}
+
+QPlatformMediaPlayer::TrackType convertTrackType(AndroidMediaPlayer::TrackType type)
+{
+ switch (type) {
+ case AndroidMediaPlayer::TrackType::Video:
+ return QPlatformMediaPlayer::TrackType::VideoStream;
+ case AndroidMediaPlayer::TrackType::Audio:
+ return QPlatformMediaPlayer::TrackType::AudioStream;
+ case AndroidMediaPlayer::TrackType::TimedText:
+ return QPlatformMediaPlayer::TrackType::SubtitleStream;
+ case AndroidMediaPlayer::TrackType::Subtitle:
+ return QPlatformMediaPlayer::TrackType::SubtitleStream;
+ case AndroidMediaPlayer::TrackType::Unknown:
+ case AndroidMediaPlayer::TrackType::Metadata:
+ return QPlatformMediaPlayer::TrackType::NTrackTypes;
+ }
+
+ return QPlatformMediaPlayer::TrackType::NTrackTypes;
+}
+
+int QAndroidMediaPlayer::convertTrackNumber(int androidTrackNumber)
+{
+ int trackNumber = androidTrackNumber;
+
+ int videoTrackCount = trackCount(QPlatformMediaPlayer::TrackType::VideoStream);
+ if (trackNumber <= videoTrackCount)
+ return trackNumber;
+
+ trackNumber = trackNumber - videoTrackCount;
+
+ int audioTrackCount = trackCount(QPlatformMediaPlayer::TrackType::AudioStream);
+ if (trackNumber <= audioTrackCount)
+ return trackNumber;
+
+ trackNumber = trackNumber - audioTrackCount;
+
+ auto subtitleTracks = mTracksMetadata.value(QPlatformMediaPlayer::TrackType::SubtitleStream);
+ int timedTextCount = 0;
+ int subtitleTextCount = 0;
+ for (const auto &track : subtitleTracks) {
+ if (track.androidTrackType() == 3) // 3 == TimedText
+ timedTextCount++;
+
+ if (track.androidTrackType() == 4) // 4 == Subtitle
+ subtitleTextCount++;
+ }
+
+ if (trackNumber <= timedTextCount)
+ return trackNumber;
+
+ trackNumber = trackNumber - timedTextCount;
+
+ if (trackNumber <= subtitleTextCount)
+ return trackNumber;
+
+ return -1;
+}
+
+int QAndroidMediaPlayer::activeTrack(TrackType trackType)
+{
+ int androidTrackNumber = -1;
+
+ switch (trackType) {
+ case QPlatformMediaPlayer::TrackType::VideoStream: {
+ if (!mIsVideoTrackEnabled)
+ return -1;
+ androidTrackNumber = mMediaPlayer->activeTrack(AndroidMediaPlayer::TrackType::Video);
+ }
+ case QPlatformMediaPlayer::TrackType::AudioStream: {
+ if (!mIsAudioTrackEnabled)
+ return -1;
+
+ androidTrackNumber = mMediaPlayer->activeTrack(AndroidMediaPlayer::TrackType::Audio);
+ }
+ case QPlatformMediaPlayer::TrackType::SubtitleStream: {
+ int timedTextSelectedTrack =
+ mMediaPlayer->activeTrack(AndroidMediaPlayer::TrackType::TimedText);
+
+ if (timedTextSelectedTrack > -1) {
+ androidTrackNumber = timedTextSelectedTrack;
+ break;
+ }
+
+ int subtitleSelectedTrack =
+ mMediaPlayer->activeTrack(AndroidMediaPlayer::TrackType::Subtitle);
+ if (subtitleSelectedTrack > -1) {
+ androidTrackNumber = subtitleSelectedTrack;
+ break;
+ }
+
+ return -1;
+ }
+ case QPlatformMediaPlayer::TrackType::NTrackTypes:
+ return -1;
+ }
+
+ return convertTrackNumber(androidTrackNumber);
+}
+
+void QAndroidMediaPlayer::disableTrack(TrackType trackType)
+{
+ const auto track = activeTrack(trackType);
+
+ switch (trackType) {
+ case VideoStream: {
+ if (track > -1) {
+ mMediaPlayer->setDisplay(nullptr);
+ mIsVideoTrackEnabled = false;
+ }
+ break;
+ }
+ case AudioStream: {
+ if (track > -1) {
+ mMediaPlayer->setMuted(true);
+ mMediaPlayer->blockAudio();
+ mIsAudioTrackEnabled = false;
+ }
+ break;
+ }
+ case SubtitleStream: {
+ // subtitles and timedtext tracks can be selected at the same time so deselect both
+ int subtitleSelectedTrack =
+ mMediaPlayer->activeTrack(AndroidMediaPlayer::TrackType::Subtitle);
+ if (subtitleSelectedTrack > -1)
+ mMediaPlayer->deselectTrack(subtitleSelectedTrack);
+
+ int timedTextSelectedTrack =
+ mMediaPlayer->activeTrack(AndroidMediaPlayer::TrackType::TimedText);
+ if (timedTextSelectedTrack > -1)
+ mMediaPlayer->deselectTrack(timedTextSelectedTrack);
+
+ break;
+ }
+ case NTrackTypes:
+ break;
+ }
+}
+
+void QAndroidMediaPlayer::setActiveTrack(TrackType trackType, int streamNumber)
+{
+
+ if (!mTracksMetadata.contains(trackType)) {
+ qCWarning(lcMediaPlayer)
+ << "Trying to set a active track which type has no available tracks.";
+ return;
+ }
+
+ const auto &tracks = mTracksMetadata.value(trackType);
+ if (streamNumber > tracks.count()) {
+ qCWarning(lcMediaPlayer) << "Trying to set a active track that does not exist.";
+ return;
+ }
+
+ // in case of < 0 deselect tracktype
+ if (streamNumber < 0) {
+ disableTrack(trackType);
+ return;
+ }
+
+ const auto currentTrack = activeTrack(trackType);
+ if (streamNumber == currentTrack) {
+ return;
+ }
+
+ if (trackType == TrackType::VideoStream && !mIsVideoTrackEnabled) {
+ // enable video stream
+ mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture());
+ mIsVideoTrackEnabled = true;
+ }
+
+ if (trackType == TrackType::AudioStream && !mIsAudioTrackEnabled) {
+ // enable audio stream
+ mMediaPlayer->unblockAudio();
+ mMediaPlayer->setMuted(false);
+ mIsAudioTrackEnabled = true;
+ }
+
+ if (trackType == TrackType::SubtitleStream) {
+ // subtitles and timedtext tracks can be selected at the same time so deselect both before
+ // selecting a new one
+ disableTrack(TrackType::SubtitleStream);
+ }
+
+ const auto &trackInfo = tracks.at(streamNumber);
+ const auto &trackNumber = trackInfo.androidTrackNumber();
+ mMediaPlayer->selectTrack(trackNumber);
+
+ emit activeTracksChanged();
+}
+
+void QAndroidMediaPlayer::positionChanged(qint64 position)
+{
+ QPlatformMediaPlayer::positionChanged(position);
+}
+
+void QAndroidMediaPlayer::durationChanged(qint64 duration)
+{
+ QPlatformMediaPlayer::durationChanged(duration);
+}
+
+void QAndroidMediaPlayer::onVideoOutputReady(bool ready)
+{
+ if ((mMediaPlayer->display() == 0) && mVideoOutput && ready)
+ mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture());
+
+ flushPendingStates();
+}
+
+void QAndroidMediaPlayer::setMediaStatus(QMediaPlayer::MediaStatus status)
+{
+ mediaStatusChanged(status);
+
+ if (status == QMediaPlayer::NoMedia || status == QMediaPlayer::InvalidMedia) {
+ Q_EMIT durationChanged(0);
+ Q_EMIT metaDataChanged();
+ setAudioAvailable(false);
+ setVideoAvailable(false);
+ }
+
+ if (status == QMediaPlayer::EndOfMedia)
+ Q_EMIT positionChanged(position());
+
+ updateBufferStatus();
+}
+
+void QAndroidMediaPlayer::setAudioAvailable(bool available)
+{
+ if (mAudioAvailable == available)
+ return;
+
+ mAudioAvailable = available;
+ Q_EMIT audioAvailableChanged(mAudioAvailable);
+}
+
+void QAndroidMediaPlayer::setVideoAvailable(bool available)
+{
+ if (mVideoAvailable == available)
+ return;
+
+ if (!available)
+ mVideoSize = QSize();
+
+ mVideoAvailable = available;
+ Q_EMIT videoAvailableChanged(mVideoAvailable);
+}
+
+void QAndroidMediaPlayer::resetBufferingProgress()
+{
+ mBuffering = false;
+ mBufferPercent = 0;
+ mAvailablePlaybackRange = QMediaTimeRange();
+}
+
+void QAndroidMediaPlayer::flushPendingStates()
+{
+ if (mPendingSetMedia) {
+ setMedia(mMediaContent, 0);
+ mPendingSetMedia = false;
+ return;
+ }
+
+ const int newState = mPendingState;
+ mPendingState = -1;
+
+ if (mPendingPosition != -1)
+ setPosition(mPendingPosition);
+ if (mPendingVolume >= 0)
+ setVolume(mPendingVolume);
+ if (mPendingMute != -1)
+ setMuted((mPendingMute == 1));
+
+ switch (newState) {
+ case QMediaPlayer::PlayingState:
+ play();
+ break;
+ case QMediaPlayer::PausedState:
+ pause();
+ break;
+ case QMediaPlayer::StoppedState:
+ stop();
+ break;
+ default:
+ break;
+ }
+}
+
+void QAndroidMediaPlayer::updateBufferStatus()
+{
+ const auto &status = mediaStatus();
+ bool bufferFilled = (status == QMediaPlayer::BufferedMedia || status == QMediaPlayer::BufferingMedia);
+
+ if (mBufferFilled != bufferFilled)
+ mBufferFilled = bufferFilled;
+
+ emit bufferProgressChanged(bufferProgress());
+}
+
+void QAndroidMediaPlayer::updateTrackInfo()
+{
+ const auto &androidTracksInfo = mMediaPlayer->tracksInfo();
+
+ // prepare mTracksMetadata
+ mTracksMetadata[TrackType::VideoStream] = QList<QAndroidMetaData>();
+ mTracksMetadata[TrackType::AudioStream] = QList<QAndroidMetaData>();
+ mTracksMetadata[TrackType::SubtitleStream] = QList<QAndroidMetaData>();
+ mTracksMetadata[TrackType::NTrackTypes] = QList<QAndroidMetaData>();
+
+ for (const auto &androidTrackInfo : androidTracksInfo) {
+
+ const auto &mediaPlayerType = convertTrackType(androidTrackInfo.trackType);
+ auto &tracks = mTracksMetadata[mediaPlayerType];
+
+ const QAndroidMetaData metadata(mediaPlayerType, androidTrackInfo.trackType,
+ androidTrackInfo.trackNumber, androidTrackInfo.mimeType,
+ androidTrackInfo.language);
+ tracks.append(metadata);
+ }
+
+ emit tracksChanged();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qandroidmediaplayer_p.cpp"
diff --git a/src/plugins/multimedia/android/mediaplayer/qandroidmediaplayer_p.h b/src/plugins/multimedia/android/mediaplayer/qandroidmediaplayer_p.h
new file mode 100644
index 000000000..dd2a3469d
--- /dev/null
+++ b/src/plugins/multimedia/android/mediaplayer/qandroidmediaplayer_p.h
@@ -0,0 +1,127 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDMEDIAPLAYERCONTROL_H
+#define QANDROIDMEDIAPLAYERCONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qglobal.h>
+#include <private/qplatformmediaplayer_p.h>
+#include <qandroidmetadata_p.h>
+#include <qmap.h>
+#include <qsize.h>
+#include <qurl.h>
+
+QT_BEGIN_NAMESPACE
+
+class AndroidMediaPlayer;
+class QAndroidTextureVideoOutput;
+class QAndroidMediaPlayerVideoRendererControl;
+class QAndroidAudioOutput;
+
+class QAndroidMediaPlayer : public QObject, public QPlatformMediaPlayer
+{
+ Q_OBJECT
+
+public:
+ explicit QAndroidMediaPlayer(QMediaPlayer *parent = 0);
+ ~QAndroidMediaPlayer() override;
+
+ qint64 duration() const override;
+ qint64 position() const override;
+ float bufferProgress() const override;
+ bool isAudioAvailable() const override;
+ bool isVideoAvailable() const override;
+ QMediaTimeRange availablePlaybackRanges() const override;
+ qreal playbackRate() const override;
+ void setPlaybackRate(qreal rate) override;
+ QUrl media() const override;
+ const QIODevice *mediaStream() const override;
+ void setMedia(const QUrl &mediaContent, QIODevice *stream) override;
+
+ QMediaMetaData metaData() const override;
+
+ void setVideoSink(QVideoSink *surface) override;
+
+ void setAudioOutput(QPlatformAudioOutput *output) override;
+ void updateAudioDevice();
+
+ void setPosition(qint64 position) override;
+ void play() override;
+ void pause() override;
+ void stop() override;
+
+ int trackCount(TrackType trackType) override;
+ QMediaMetaData trackMetaData(TrackType trackType, int streamNumber) override;
+ int activeTrack(TrackType trackType) override;
+ void setActiveTrack(TrackType trackType, int streamNumber) override;
+
+private Q_SLOTS:
+ void setVolume(float volume);
+ void setMuted(bool muted);
+ void onVideoOutputReady(bool ready);
+ void onError(qint32 what, qint32 extra);
+ void onInfo(qint32 what, qint32 extra);
+ void onBufferingChanged(qint32 percent);
+ void onVideoSizeChanged(qint32 width, qint32 height);
+ void onStateChanged(qint32 state);
+ void positionChanged(qint64 position);
+ void durationChanged(qint64 duration);
+
+private:
+ AndroidMediaPlayer *mMediaPlayer = nullptr;
+ QAndroidAudioOutput *m_audioOutput = nullptr;
+ QUrl mMediaContent;
+ QIODevice *mMediaStream = nullptr;
+ QAndroidTextureVideoOutput *mVideoOutput = nullptr;
+ QVideoSink *m_videoSink = nullptr;
+ int mBufferPercent = -1;
+ bool mBufferFilled = false;
+ bool mAudioAvailable = false;
+ bool mVideoAvailable = false;
+ QSize mVideoSize;
+ bool mBuffering = false;
+ QMediaTimeRange mAvailablePlaybackRange;
+ int mState;
+ int mPendingState = -1;
+ qint64 mPendingPosition = -1;
+ bool mPendingSetMedia = false;
+ float mPendingVolume = -1;
+ int mPendingMute = -1;
+ bool mReloadingMedia = false;
+ int mActiveStateChangeNotifiers = 0;
+ qreal mCurrentPlaybackRate = 1.;
+ bool mHasPendingPlaybackRate = false; // we need this because the rate can theoretically be negative
+ QMap<TrackType, QList<QAndroidMetaData>> mTracksMetadata;
+
+ bool mIsVideoTrackEnabled = true;
+ bool mIsAudioTrackEnabled = true;
+
+ void setMediaStatus(QMediaPlayer::MediaStatus status);
+ void setAudioAvailable(bool available);
+ void setVideoAvailable(bool available);
+ void updateAvailablePlaybackRanges();
+ void resetBufferingProgress();
+ void flushPendingStates();
+ void updateBufferStatus();
+ void updateTrackInfo();
+ void setSubtitle(QString subtitle);
+ void disableTrack(TrackType trackType);
+
+ int convertTrackNumber(int androidTrackNumber);
+ friend class StateChangeNotifier;
+};
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDMEDIAPLAYERCONTROL_H
diff --git a/src/plugins/multimedia/android/mediaplayer/qandroidmetadata.cpp b/src/plugins/multimedia/android/mediaplayer/qandroidmetadata.cpp
new file mode 100644
index 000000000..b01845fa7
--- /dev/null
+++ b/src/plugins/multimedia/android/mediaplayer/qandroidmetadata.cpp
@@ -0,0 +1,163 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidmetadata_p.h"
+
+#include "androidmediametadataretriever_p.h"
+#include <QtMultimedia/qmediametadata.h>
+#include <qsize.h>
+#include <QDate>
+#include <QtCore/qlist.h>
+#include <QtConcurrent/qtconcurrentrun.h>
+#include <QLoggingCategory>
+
+QT_BEGIN_NAMESPACE
+
+// Genre name ordered by ID
+// see: http://id3.org/id3v2.3.0#Appendix_A_-_Genre_List_from_ID3v1
+static const char* qt_ID3GenreNames[] =
+{
+ "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz",
+ "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno",
+ "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno",
+ "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental",
+ "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass", "Soul", "Punk",
+ "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave",
+ "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy",
+ "Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American",
+ "Cabaret", "New Wave", "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal",
+ "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock", "Folk",
+ "Folk-Rock", "National Folk", "Swing", "Fast Fusion", "Bebob", "Latin", "Revival", "Celtic",
+ "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock", "Psychedelic Rock",
+ "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour",
+ "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus",
+ "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad",
+ "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet", "Punk Rock", "Drum Solo", "A capella",
+ "Euro-House", "Dance Hall"
+};
+
+QMediaMetaData QAndroidMetaData::extractMetadata(const QUrl &url)
+{
+ QMediaMetaData metadata;
+
+ if (!url.isEmpty()) {
+ AndroidMediaMetadataRetriever retriever;
+ if (!retriever.setDataSource(url))
+ return metadata;
+
+ QString mimeType = retriever.extractMetadata(AndroidMediaMetadataRetriever::MimeType);
+ if (!mimeType.isNull())
+ metadata.insert(QMediaMetaData::MediaType, mimeType);
+
+ bool isVideo = !retriever.extractMetadata(AndroidMediaMetadataRetriever::HasVideo).isNull()
+ || mimeType.startsWith(QStringLiteral("video"));
+
+ QString string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Album);
+ if (!string.isNull())
+ metadata.insert(QMediaMetaData::AlbumTitle, string);
+
+ string = retriever.extractMetadata(AndroidMediaMetadataRetriever::AlbumArtist);
+ if (!string.isNull())
+ metadata.insert(QMediaMetaData::AlbumArtist, string);
+
+ string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Artist);
+ if (!string.isNull()) {
+ metadata.insert(isVideo ? QMediaMetaData::LeadPerformer
+ : QMediaMetaData::ContributingArtist,
+ string.split(QLatin1Char('/'), Qt::SkipEmptyParts));
+ }
+
+ string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Author);
+ if (!string.isNull())
+ metadata.insert(QMediaMetaData::Author, string.split(QLatin1Char('/'), Qt::SkipEmptyParts));
+
+ string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Bitrate);
+ if (!string.isNull()) {
+ metadata.insert(isVideo ? QMediaMetaData::VideoBitRate
+ : QMediaMetaData::AudioBitRate,
+ string.toInt());
+ }
+
+ string = retriever.extractMetadata(AndroidMediaMetadataRetriever::CDTrackNumber);
+ if (!string.isNull())
+ metadata.insert(QMediaMetaData::TrackNumber, string.toInt());
+
+ string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Composer);
+ if (!string.isNull())
+ metadata.insert(QMediaMetaData::Composer, string.split(QLatin1Char('/'), Qt::SkipEmptyParts));
+
+ string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Date);
+ if (!string.isNull())
+ metadata.insert(QMediaMetaData::Date, QDateTime::fromString(string, QStringLiteral("yyyyMMddTHHmmss.zzzZ")).date());
+
+ string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Duration);
+ if (!string.isNull())
+ metadata.insert(QMediaMetaData::Duration, string.toLongLong());
+
+ string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Genre);
+ if (!string.isNull()) {
+ // The genre can be returned as an ID3v2 id, get the name for it in that case
+ if (string.startsWith(QLatin1Char('(')) && string.endsWith(QLatin1Char(')'))) {
+ bool ok = false;
+ const int genreId = QStringView{string}.mid(1, string.length() - 2).toInt(&ok);
+ if (ok && genreId >= 0 && genreId <= 125)
+ string = QLatin1String(qt_ID3GenreNames[genreId]);
+ }
+ metadata.insert(QMediaMetaData::Genre, string);
+ }
+
+ string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Title);
+ if (!string.isNull())
+ metadata.insert(QMediaMetaData::Title, string);
+
+ string = retriever.extractMetadata(AndroidMediaMetadataRetriever::VideoHeight);
+ if (!string.isNull()) {
+ const int height = string.toInt();
+ const int width = retriever.extractMetadata(AndroidMediaMetadataRetriever::VideoWidth).toInt();
+ metadata.insert(QMediaMetaData::Resolution, QSize(width, height));
+ }
+
+// string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Writer);
+// if (!string.isNull())
+// metadata.insert(QMediaMetaData::Writer, string.split('/', Qt::SkipEmptyParts));
+
+ }
+
+ return metadata;
+}
+
+QLocale::Language getLocaleLanguage(const QString &language)
+{
+ // undefined language or uncoded language
+ if (language == QLatin1String("und") || language == QStringLiteral("mis"))
+ return QLocale::AnyLanguage;
+
+ return QLocale::codeToLanguage(language, QLocale::ISO639Part2);
+}
+
+QAndroidMetaData::QAndroidMetaData(int trackType, int androidTrackType, int androidTrackNumber,
+ const QString &mimeType, const QString &language)
+ : mTrackType(trackType),
+ mAndroidTrackType(androidTrackType),
+ mAndroidTrackNumber(androidTrackNumber)
+{
+ insert(QMediaMetaData::MediaType, mimeType);
+ insert(QMediaMetaData::Language, getLocaleLanguage(language));
+}
+
+int QAndroidMetaData::trackType() const
+{
+ return mTrackType;
+}
+
+int QAndroidMetaData::androidTrackType() const
+{
+ return mAndroidTrackType;
+}
+
+int QAndroidMetaData::androidTrackNumber() const
+{
+ return mAndroidTrackNumber;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/android/mediaplayer/qandroidmetadata_p.h b/src/plugins/multimedia/android/mediaplayer/qandroidmetadata_p.h
new file mode 100644
index 000000000..1bbad92dd
--- /dev/null
+++ b/src/plugins/multimedia/android/mediaplayer/qandroidmetadata_p.h
@@ -0,0 +1,47 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDMETADATA_H
+#define QANDROIDMETADATA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qmediametadata.h>
+#include <qurl.h>
+#include <QMutex>
+#include <QVariant>
+
+QT_BEGIN_NAMESPACE
+
+class AndroidMediaMetadataRetriever;
+
+class QAndroidMetaData : public QMediaMetaData
+{
+public:
+ static QMediaMetaData extractMetadata(const QUrl &url);
+
+ QAndroidMetaData(int trackType, int androidTrackType, int androidTrackNumber,
+ const QString &mimeType, const QString &language);
+
+ int trackType() const;
+ int androidTrackType() const;
+ int androidTrackNumber() const;
+
+private:
+ int mTrackType;
+ int mAndroidTrackType;
+ int mAndroidTrackNumber;
+};
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDMETADATA_H
diff --git a/src/plugins/multimedia/android/qandroidformatsinfo.cpp b/src/plugins/multimedia/android/qandroidformatsinfo.cpp
new file mode 100644
index 000000000..3b23340ce
--- /dev/null
+++ b/src/plugins/multimedia/android/qandroidformatsinfo.cpp
@@ -0,0 +1,160 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidformatsinfo_p.h"
+
+#include <QtCore/qjnienvironment.h>
+#include <QtCore/qjniobject.h>
+#include <qcoreapplication.h>
+
+static const char encoderFilter[] = ".encoder";
+static const char decoderFilter[] = ".decoder";
+
+QT_BEGIN_NAMESPACE
+
+QAndroidFormatInfo::QAndroidFormatInfo()
+{
+ // Audio/Video/Image formats with their decoder/encoder information is documented at
+ // https://developer.android.com/guide/topics/media/media-formats
+
+ const QJniObject codecsArrayObject = QJniObject::callStaticObjectMethod(
+ "org/qtproject/qt/android/multimedia/QtMultimediaUtils",
+ "getMediaCodecs",
+ "()[Ljava/lang/String;");
+ QStringList codecs;
+ QJniEnvironment env;
+ const jobjectArray devsArray = codecsArrayObject.object<jobjectArray>();
+ for (int i = 0; i < env->GetArrayLength(devsArray); ++i) {
+ const QString codec = QJniObject(env->GetObjectArrayElement(devsArray, i)).toString();
+ if (codec.contains(QStringLiteral("encoder")))
+ m_supportedEncoders.append(codec);
+ else
+ m_supportedDecoders.append(codec);
+ }
+
+ auto removeUnspecifiedValues = [](QList<CodecMap> &map) {
+ for (CodecMap &codec : map) {
+ codec.audio.removeAll(QMediaFormat::AudioCodec::Unspecified);
+ codec.video.removeAll(QMediaFormat::VideoCodec::Unspecified);
+ }
+ erase_if(map, [](const CodecMap &codec) {
+ return codec.audio.isEmpty() && codec.video.isEmpty();
+ });
+ };
+
+ {
+ const QMediaFormat::AudioCodec aac = hasDecoder(QMediaFormat::AudioCodec::AAC);
+ const QMediaFormat::AudioCodec mp3 = hasDecoder(QMediaFormat::AudioCodec::MP3);
+ const QMediaFormat::AudioCodec flac = hasDecoder(QMediaFormat::AudioCodec::FLAC);
+ const QMediaFormat::AudioCodec opus = hasDecoder(QMediaFormat::AudioCodec::Opus);
+ const QMediaFormat::AudioCodec vorbis = hasDecoder(QMediaFormat::AudioCodec::Vorbis);
+
+ const QMediaFormat::VideoCodec vp8 = hasDecoder(QMediaFormat::VideoCodec::VP8);
+ const QMediaFormat::VideoCodec vp9 = hasDecoder(QMediaFormat::VideoCodec::VP9);
+ const QMediaFormat::VideoCodec h264 = hasDecoder(QMediaFormat::VideoCodec::H264);
+ const QMediaFormat::VideoCodec h265 = hasDecoder(QMediaFormat::VideoCodec::H265);
+ const QMediaFormat::VideoCodec av1 = hasDecoder(QMediaFormat::VideoCodec::AV1);
+
+ decoders = {
+ { QMediaFormat::AAC, {aac}, {} },
+ { QMediaFormat::MP3, {mp3}, {} },
+ { QMediaFormat::FLAC, {flac}, {} },
+ { QMediaFormat::Mpeg4Audio, {mp3, aac, flac, vorbis}, {} },
+ { QMediaFormat::MPEG4, {mp3, aac, flac, vorbis}, {h264, h265, av1} },
+ { QMediaFormat::Ogg, {opus, vorbis, flac}, {} },
+ { QMediaFormat::Matroska, {mp3, opus, vorbis}, {vp8, vp9, h264, h265, av1} },
+ { QMediaFormat::WebM, {opus, vorbis}, {vp8, vp9} }
+ };
+
+ removeUnspecifiedValues(decoders);
+ }
+
+ {
+ const QMediaFormat::AudioCodec aac = hasEncoder(QMediaFormat::AudioCodec::AAC);
+ const QMediaFormat::AudioCodec mp3 = hasEncoder(QMediaFormat::AudioCodec::MP3);
+ const QMediaFormat::AudioCodec opus = hasEncoder(QMediaFormat::AudioCodec::Opus);
+ const QMediaFormat::AudioCodec vorbis = hasEncoder(QMediaFormat::AudioCodec::Vorbis);
+
+ const QMediaFormat::VideoCodec vp8 = hasEncoder(QMediaFormat::VideoCodec::VP8);
+ const QMediaFormat::VideoCodec vp9 = hasEncoder(QMediaFormat::VideoCodec::VP9);
+ const QMediaFormat::VideoCodec h264 = hasEncoder(QMediaFormat::VideoCodec::H264);
+ const QMediaFormat::VideoCodec h265 = hasEncoder(QMediaFormat::VideoCodec::H265);
+ const QMediaFormat::VideoCodec av1 = hasEncoder(QMediaFormat::VideoCodec::AV1);
+
+ // MP3 and Vorbis encoders are not supported by the default Android SDK
+ // Opus encoder available only for Android 10+
+ encoders = {
+ { QMediaFormat::AAC, {aac}, {} },
+ { QMediaFormat::MP3, {mp3}, {} },
+ // FLAC encoder is not supported by the MediaRecorder used for recording
+ // { QMediaFormat::FLAC, {flac}, {} },
+ { QMediaFormat::Mpeg4Audio, {mp3, aac, vorbis}, {} },
+ { QMediaFormat::MPEG4, {mp3, aac, vorbis}, {h264, h265, av1} },
+ { QMediaFormat::Ogg, {opus, vorbis}, {} },
+ { QMediaFormat::Matroska, {mp3, opus}, {vp8, vp9, h264, h265, av1} },
+ // NOTE: WebM seems to be documented to supported with VP8 encoder,
+ // but the Camera API doesn't work with it, keep it commented for now.
+ // { QMediaFormat::WebM, {vorbis, opus}, {vp8, vp9} }
+ };
+
+ removeUnspecifiedValues(encoders);
+ }
+
+ imageFormats << QImageCapture::JPEG;
+ // NOTE: Add later if needed, the Camera API doens't seem to work with it.
+ // imageFormats << QImageCapture::PNG << QImageCapture::WebP;
+}
+
+QAndroidFormatInfo::~QAndroidFormatInfo()
+{
+}
+
+static QString getVideoCodecName(QMediaFormat::VideoCodec codec)
+{
+ QString codecString = QMediaFormat::videoCodecName(codec);
+ if (codec == QMediaFormat::VideoCodec::H265)
+ codecString = QLatin1String("HEVC");
+ return codecString;
+}
+
+QMediaFormat::AudioCodec QAndroidFormatInfo::hasEncoder(QMediaFormat::AudioCodec codec) const
+{
+ const QString codecString = QMediaFormat::audioCodecName(codec);
+ for (auto str : m_supportedEncoders) {
+ if (str.contains(codecString + QLatin1String(encoderFilter), Qt::CaseInsensitive))
+ return codec;
+ }
+ return QMediaFormat::AudioCodec::Unspecified;
+}
+
+QMediaFormat::VideoCodec QAndroidFormatInfo::hasEncoder(QMediaFormat::VideoCodec codec) const
+{
+ const QString codecString = getVideoCodecName(codec);
+ for (auto str : m_supportedEncoders) {
+ if (str.contains(codecString + QLatin1String(encoderFilter), Qt::CaseInsensitive))
+ return codec;
+ }
+ return QMediaFormat::VideoCodec::Unspecified;
+}
+
+QMediaFormat::AudioCodec QAndroidFormatInfo::hasDecoder(QMediaFormat::AudioCodec codec) const
+{
+ const QString codecString = QMediaFormat::audioCodecName(codec);
+ for (auto str : m_supportedDecoders) {
+ if (str.contains(codecString + QLatin1String(decoderFilter), Qt::CaseInsensitive))
+ return codec;
+ }
+ return QMediaFormat::AudioCodec::Unspecified;
+}
+
+QMediaFormat::VideoCodec QAndroidFormatInfo::hasDecoder(QMediaFormat::VideoCodec codec) const
+{
+ const QString codecString = getVideoCodecName(codec);
+ for (auto str : m_supportedDecoders) {
+ if (str.contains(codecString + QLatin1String(decoderFilter), Qt::CaseInsensitive))
+ return codec;
+ }
+ return QMediaFormat::VideoCodec::Unspecified;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/android/qandroidformatsinfo_p.h b/src/plugins/multimedia/android/qandroidformatsinfo_p.h
new file mode 100644
index 000000000..2d14ad181
--- /dev/null
+++ b/src/plugins/multimedia/android/qandroidformatsinfo_p.h
@@ -0,0 +1,40 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDFORMATINFO_H
+#define QANDROIDFORMATINFO_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaformatinfo_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidFormatInfo : public QPlatformMediaFormatInfo
+{
+public:
+ QAndroidFormatInfo();
+ ~QAndroidFormatInfo();
+
+private:
+ QMediaFormat::AudioCodec hasEncoder(QMediaFormat::AudioCodec codec) const;
+ QMediaFormat::VideoCodec hasEncoder(QMediaFormat::VideoCodec codec) const;
+ QMediaFormat::AudioCodec hasDecoder(QMediaFormat::AudioCodec codec) const;
+ QMediaFormat::VideoCodec hasDecoder(QMediaFormat::VideoCodec codec) const;
+
+ QStringList m_supportedDecoders;
+ QStringList m_supportedEncoders;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/android/qandroidintegration.cpp b/src/plugins/multimedia/android/qandroidintegration.cpp
new file mode 100644
index 000000000..c7077e49d
--- /dev/null
+++ b/src/plugins/multimedia/android/qandroidintegration.cpp
@@ -0,0 +1,136 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidintegration_p.h"
+#include "qandroidglobal_p.h"
+#include "qandroidmediacapturesession_p.h"
+#include "androidmediaplayer_p.h"
+#include "qandroidcamerasession_p.h"
+#include "androidsurfacetexture_p.h"
+#include "androidsurfaceview_p.h"
+#include "androidcamera_p.h"
+#include "qandroidcamera_p.h"
+#include "qandroidimagecapture_p.h"
+#include "qandroidmediaencoder_p.h"
+#include "androidmediarecorder_p.h"
+#include "qandroidformatsinfo_p.h"
+#include "qandroidmediaplayer_p.h"
+#include "qandroidaudiooutput_p.h"
+#include "qandroidaudioinput_p.h"
+#include "qandroidvideosink_p.h"
+#include "qandroidaudiodecoder_p.h"
+#include <QtMultimedia/private/qplatformmediaplugin_p.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(qtAndroidMediaPlugin, "qt.multimedia.android")
+
+class QAndroidMediaPlugin : public QPlatformMediaPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QPlatformMediaPlugin_iid FILE "android.json")
+
+public:
+ QAndroidMediaPlugin()
+ : QPlatformMediaPlugin()
+ {}
+
+ QPlatformMediaIntegration* create(const QString &name) override
+ {
+ if (name == u"android")
+ return new QAndroidIntegration;
+ return nullptr;
+ }
+};
+
+QAndroidIntegration::QAndroidIntegration() : QPlatformMediaIntegration(QLatin1String("android")) { }
+
+QMaybe<QPlatformAudioDecoder *> QAndroidIntegration::createAudioDecoder(QAudioDecoder *decoder)
+{
+ return new QAndroidAudioDecoder(decoder);
+}
+
+QPlatformMediaFormatInfo *QAndroidIntegration::createFormatInfo()
+{
+ return new QAndroidFormatInfo;
+}
+
+QMaybe<QPlatformMediaCaptureSession *> QAndroidIntegration::createCaptureSession()
+{
+ return new QAndroidMediaCaptureSession();
+}
+
+QMaybe<QPlatformMediaPlayer *> QAndroidIntegration::createPlayer(QMediaPlayer *player)
+{
+ return new QAndroidMediaPlayer(player);
+}
+
+QMaybe<QPlatformCamera *> QAndroidIntegration::createCamera(QCamera *camera)
+{
+ return new QAndroidCamera(camera);
+}
+
+QMaybe<QPlatformMediaRecorder *> QAndroidIntegration::createRecorder(QMediaRecorder *recorder)
+{
+ return new QAndroidMediaEncoder(recorder);
+}
+
+QMaybe<QPlatformImageCapture *> QAndroidIntegration::createImageCapture(QImageCapture *imageCapture)
+{
+ return new QAndroidImageCapture(imageCapture);
+}
+
+QMaybe<QPlatformAudioOutput *> QAndroidIntegration::createAudioOutput(QAudioOutput *q)
+{
+ return new QAndroidAudioOutput(q);
+}
+
+QMaybe<QPlatformAudioInput *> QAndroidIntegration::createAudioInput(QAudioInput *audioInput)
+{
+ return new QAndroidAudioInput(audioInput);
+}
+
+QMaybe<QPlatformVideoSink *> QAndroidIntegration::createVideoSink(QVideoSink *sink)
+{
+ return new QAndroidVideoSink(sink);
+}
+
+Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
+{
+ static bool initialized = false;
+ if (initialized)
+ return JNI_VERSION_1_6;
+ initialized = true;
+
+ QT_USE_NAMESPACE
+ typedef union {
+ JNIEnv *nativeEnvironment;
+ void *venv;
+ } UnionJNIEnvToVoid;
+
+ UnionJNIEnvToVoid uenv;
+ uenv.venv = NULL;
+
+ if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_6) != JNI_OK)
+ return JNI_ERR;
+
+ if (!AndroidMediaPlayer::registerNativeMethods()
+ || !AndroidCamera::registerNativeMethods()
+ || !AndroidMediaRecorder::registerNativeMethods()
+ || !AndroidSurfaceHolder::registerNativeMethods()) {
+ return JNI_ERR;
+ }
+
+ AndroidSurfaceTexture::registerNativeMethods();
+
+ return JNI_VERSION_1_6;
+}
+
+QList<QCameraDevice> QAndroidIntegration::videoInputs()
+{
+ return QAndroidCameraSession::availableCameras();
+}
+
+QT_END_NAMESPACE
+
+#include "qandroidintegration.moc"
diff --git a/src/plugins/multimedia/android/qandroidintegration_p.h b/src/plugins/multimedia/android/qandroidintegration_p.h
new file mode 100644
index 000000000..9ef5a3267
--- /dev/null
+++ b/src/plugins/multimedia/android/qandroidintegration_p.h
@@ -0,0 +1,48 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDINTEGRATION_H
+#define QANDROIDINTEGRATION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidMediaDevices;
+
+class QAndroidIntegration : public QPlatformMediaIntegration
+{
+public:
+ QAndroidIntegration();
+
+ QMaybe<QPlatformAudioDecoder *> createAudioDecoder(QAudioDecoder *decoder) override;
+ QMaybe<QPlatformMediaCaptureSession *> createCaptureSession() override;
+ QMaybe<QPlatformMediaPlayer *> createPlayer(QMediaPlayer *player) override;
+ QMaybe<QPlatformCamera *> createCamera(QCamera *camera) override;
+ QMaybe<QPlatformMediaRecorder *> createRecorder(QMediaRecorder *recorder) override;
+ QMaybe<QPlatformImageCapture *> createImageCapture(QImageCapture *imageCapture) override;
+
+ QMaybe<QPlatformAudioOutput *> createAudioOutput(QAudioOutput *q) override;
+ QMaybe<QPlatformAudioInput *> createAudioInput(QAudioInput *audioInput) override;
+
+ QMaybe<QPlatformVideoSink *> createVideoSink(QVideoSink *) override;
+ QList<QCameraDevice> videoInputs() override;
+
+protected:
+ QPlatformMediaFormatInfo *createFormatInfo() override;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidcamera.cpp b/src/plugins/multimedia/android/wrappers/jni/androidcamera.cpp
new file mode 100644
index 000000000..cef36d7ad
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidcamera.cpp
@@ -0,0 +1,1797 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2016 Ruslan Baratov
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "androidcamera_p.h"
+#include "androidsurfacetexture_p.h"
+#include "androidsurfaceview_p.h"
+#include "qandroidmultimediautils_p.h"
+#include "qandroidglobal_p.h"
+
+#include <private/qvideoframe_p.h>
+
+#include <qhash.h>
+#include <qstringlist.h>
+#include <qdebug.h>
+#include <QtCore/qthread.h>
+#include <QtCore/qreadwritelock.h>
+#include <QtCore/qmutex.h>
+#include <QtMultimedia/private/qmemoryvideobuffer_p.h>
+#include <QtCore/qcoreapplication.h>
+
+#include <mutex>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(lcAndroidCamera, "qt.multimedia.android.camera")
+
+static const char QtCameraListenerClassName[] = "org/qtproject/qt/android/multimedia/QtCameraListener";
+
+typedef QHash<int, AndroidCamera *> CameraMap;
+Q_GLOBAL_STATIC(CameraMap, cameras)
+Q_GLOBAL_STATIC(QReadWriteLock, rwLock)
+
+static QRect areaToRect(jobject areaObj)
+{
+ QJniObject area(areaObj);
+ QJniObject rect = area.getObjectField("rect", "Landroid/graphics/Rect;");
+
+ return QRect(rect.getField<jint>("left"),
+ rect.getField<jint>("top"),
+ rect.callMethod<jint>("width"),
+ rect.callMethod<jint>("height"));
+}
+
+static QJniObject rectToArea(const QRect &rect)
+{
+ QJniObject jrect("android/graphics/Rect",
+ "(IIII)V",
+ rect.left(), rect.top(), rect.right(), rect.bottom());
+
+ QJniObject area("android/hardware/Camera$Area",
+ "(Landroid/graphics/Rect;I)V",
+ jrect.object(), 500);
+
+ return area;
+}
+
+// native method for QtCameraLisener.java
+static void notifyAutoFocusComplete(JNIEnv* , jobject, int id, jboolean success)
+{
+ QReadLocker locker(rwLock);
+ const auto it = cameras->constFind(id);
+ if (Q_UNLIKELY(it == cameras->cend()))
+ return;
+
+ Q_EMIT (*it)->autoFocusComplete(success);
+}
+
+static void notifyPictureExposed(JNIEnv* , jobject, int id)
+{
+ QReadLocker locker(rwLock);
+ const auto it = cameras->constFind(id);
+ if (Q_UNLIKELY(it == cameras->cend()))
+ return;
+
+ Q_EMIT (*it)->pictureExposed();
+}
+
+static void notifyPictureCaptured(JNIEnv *env, jobject, int id, jbyteArray data)
+{
+ QReadLocker locker(rwLock);
+ const auto it = cameras->constFind(id);
+ if (Q_UNLIKELY(it == cameras->cend())) {
+ qCWarning(lcAndroidCamera) << "Could not obtain camera!";
+ return;
+ }
+
+ AndroidCamera *camera = (*it);
+
+ const int arrayLength = env->GetArrayLength(data);
+ QByteArray bytes(arrayLength, Qt::Uninitialized);
+ env->GetByteArrayRegion(data, 0, arrayLength, reinterpret_cast<jbyte *>(bytes.data()));
+
+ auto parameters = camera->getParametersObject();
+
+ QJniObject size =
+ parameters.callObjectMethod("getPictureSize", "()Landroid/hardware/Camera$Size;");
+
+ if (!size.isValid()) {
+ qCWarning(lcAndroidCamera) << "Picture Size is not valid!";
+ return;
+ }
+
+ QSize pictureSize(size.getField<jint>("width"), size.getField<jint>("height"));
+
+ auto format = AndroidCamera::ImageFormat(parameters.callMethod<jint>("getPictureFormat"));
+
+ if (format == AndroidCamera::ImageFormat::UnknownImageFormat) {
+ qCWarning(lcAndroidCamera) << "Android Camera Image Format is UnknownImageFormat!";
+ return;
+ }
+
+ int bytesPerLine = 0;
+
+ switch (format) {
+ case AndroidCamera::ImageFormat::YV12:
+ bytesPerLine = (pictureSize.width() + 15) & ~15;
+ break;
+ case AndroidCamera::ImageFormat::NV21:
+ bytesPerLine = pictureSize.width();
+ break;
+ case AndroidCamera::ImageFormat::RGB565:
+ case AndroidCamera::ImageFormat::YUY2:
+ bytesPerLine = pictureSize.width() * 2;
+ break;
+ default:
+ bytesPerLine = -1;
+ }
+
+ auto pictureFormat = qt_pixelFormatFromAndroidImageFormat(format);
+
+ emit camera->pictureCaptured(bytes, pictureFormat, pictureSize, bytesPerLine);
+}
+
+static void notifyNewPreviewFrame(JNIEnv *env, jobject, int id, jbyteArray data,
+ int width, int height, int format, int bpl)
+{
+ QReadLocker locker(rwLock);
+ const auto it = cameras->constFind(id);
+ if (Q_UNLIKELY(it == cameras->cend()))
+ return;
+
+ const int arrayLength = env->GetArrayLength(data);
+ if (arrayLength == 0)
+ return;
+
+ QByteArray bytes(arrayLength, Qt::Uninitialized);
+ env->GetByteArrayRegion(data, 0, arrayLength, (jbyte*)bytes.data());
+
+ QVideoFrameFormat frameFormat(
+ QSize(width, height),
+ qt_pixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat(format)));
+
+ QVideoFrame frame = QVideoFramePrivate::createFrame(
+ std::make_unique<QMemoryVideoBuffer>(std::move(bytes), bpl), std::move(frameFormat));
+
+ Q_EMIT (*it)->newPreviewFrame(frame);
+}
+
+static void notifyFrameAvailable(JNIEnv *, jobject, int id)
+{
+ QReadLocker locker(rwLock);
+ const auto it = cameras->constFind(id);
+ if (Q_UNLIKELY(it == cameras->cend()))
+ return;
+
+ (*it)->fetchLastPreviewFrame();
+}
+
+class AndroidCameraPrivate : public QObject
+{
+ Q_OBJECT
+public:
+ AndroidCameraPrivate();
+ ~AndroidCameraPrivate();
+
+ Q_INVOKABLE bool init(int cameraId);
+
+ Q_INVOKABLE void release();
+ Q_INVOKABLE bool lock();
+ Q_INVOKABLE bool unlock();
+ Q_INVOKABLE bool reconnect();
+
+ Q_INVOKABLE AndroidCamera::CameraFacing getFacing();
+ Q_INVOKABLE int getNativeOrientation();
+
+ Q_INVOKABLE QSize getPreferredPreviewSizeForVideo();
+ Q_INVOKABLE QList<QSize> getSupportedPreviewSizes();
+ static QList<QSize> getSupportedPreviewSizes(QJniObject &parameters);
+
+ Q_INVOKABLE QList<AndroidCamera::FpsRange> getSupportedPreviewFpsRange();
+
+ Q_INVOKABLE AndroidCamera::FpsRange getPreviewFpsRange();
+ static AndroidCamera::FpsRange getPreviewFpsRange(QJniObject &parameters);
+ Q_INVOKABLE void setPreviewFpsRange(int min, int max);
+
+ Q_INVOKABLE AndroidCamera::ImageFormat getPreviewFormat();
+ Q_INVOKABLE void setPreviewFormat(AndroidCamera::ImageFormat fmt);
+ Q_INVOKABLE QList<AndroidCamera::ImageFormat> getSupportedPreviewFormats();
+ static QList<AndroidCamera::ImageFormat> getSupportedPreviewFormats(QJniObject &parameters);
+
+ Q_INVOKABLE QSize previewSize() const { return m_previewSize; }
+ Q_INVOKABLE QSize getPreviewSize();
+ Q_INVOKABLE void updatePreviewSize();
+ Q_INVOKABLE bool setPreviewTexture(void *surfaceTexture);
+ Q_INVOKABLE bool setPreviewDisplay(void *surfaceHolder);
+ Q_INVOKABLE void setDisplayOrientation(int degrees);
+
+ Q_INVOKABLE bool isZoomSupported();
+ Q_INVOKABLE int getMaxZoom();
+ Q_INVOKABLE QList<int> getZoomRatios();
+ Q_INVOKABLE int getZoom();
+ Q_INVOKABLE void setZoom(int value);
+
+ Q_INVOKABLE QString getFlashMode();
+ Q_INVOKABLE void setFlashMode(const QString &value);
+
+ Q_INVOKABLE QString getFocusMode();
+ Q_INVOKABLE void setFocusMode(const QString &value);
+
+ Q_INVOKABLE int getMaxNumFocusAreas();
+ Q_INVOKABLE QList<QRect> getFocusAreas();
+ Q_INVOKABLE void setFocusAreas(const QList<QRect> &areas);
+
+ Q_INVOKABLE void autoFocus();
+ Q_INVOKABLE void cancelAutoFocus();
+
+ Q_INVOKABLE bool isAutoExposureLockSupported();
+ Q_INVOKABLE bool getAutoExposureLock();
+ Q_INVOKABLE void setAutoExposureLock(bool toggle);
+
+ Q_INVOKABLE bool isAutoWhiteBalanceLockSupported();
+ Q_INVOKABLE bool getAutoWhiteBalanceLock();
+ Q_INVOKABLE void setAutoWhiteBalanceLock(bool toggle);
+
+ Q_INVOKABLE int getExposureCompensation();
+ Q_INVOKABLE void setExposureCompensation(int value);
+ Q_INVOKABLE float getExposureCompensationStep();
+ Q_INVOKABLE int getMinExposureCompensation();
+ Q_INVOKABLE int getMaxExposureCompensation();
+
+ Q_INVOKABLE QString getSceneMode();
+ Q_INVOKABLE void setSceneMode(const QString &value);
+
+ Q_INVOKABLE QString getWhiteBalance();
+ Q_INVOKABLE void setWhiteBalance(const QString &value);
+
+ Q_INVOKABLE void updateRotation();
+
+ Q_INVOKABLE QList<QSize> getSupportedPictureSizes();
+ Q_INVOKABLE QList<QSize> getSupportedVideoSizes();
+ Q_INVOKABLE void setPictureSize(const QSize &size);
+ Q_INVOKABLE void setJpegQuality(int quality);
+
+ Q_INVOKABLE void startPreview();
+ Q_INVOKABLE void stopPreview();
+
+ Q_INVOKABLE void takePicture();
+
+ Q_INVOKABLE void setupPreviewFrameCallback();
+ Q_INVOKABLE void notifyNewFrames(bool notify);
+ Q_INVOKABLE void fetchLastPreviewFrame();
+
+ Q_INVOKABLE void applyParameters();
+
+ Q_INVOKABLE QStringList callParametersStringListMethod(const QByteArray &methodName);
+
+ int m_cameraId;
+ QRecursiveMutex m_parametersMutex;
+ QSize m_previewSize;
+ int m_rotation;
+ QJniObject m_info;
+ QJniObject m_parameters;
+ QJniObject m_camera;
+ QJniObject m_cameraListener;
+
+Q_SIGNALS:
+ void previewSizeChanged();
+ void previewStarted();
+ void previewFailedToStart();
+ void previewStopped();
+
+ void autoFocusStarted();
+
+ void whiteBalanceChanged();
+
+ void takePictureFailed();
+
+ void lastPreviewFrameFetched(const QVideoFrame &frame);
+};
+
+AndroidCamera::AndroidCamera(AndroidCameraPrivate *d, QThread *worker)
+ : QObject(),
+ d_ptr(d),
+ m_worker(worker)
+
+{
+ connect(d, &AndroidCameraPrivate::previewSizeChanged, this, &AndroidCamera::previewSizeChanged);
+ connect(d, &AndroidCameraPrivate::previewStarted, this, &AndroidCamera::previewStarted);
+ connect(d, &AndroidCameraPrivate::previewFailedToStart, this, &AndroidCamera::previewFailedToStart);
+ connect(d, &AndroidCameraPrivate::previewStopped, this, &AndroidCamera::previewStopped);
+ connect(d, &AndroidCameraPrivate::autoFocusStarted, this, &AndroidCamera::autoFocusStarted);
+ connect(d, &AndroidCameraPrivate::whiteBalanceChanged, this, &AndroidCamera::whiteBalanceChanged);
+ connect(d, &AndroidCameraPrivate::takePictureFailed, this, &AndroidCamera::takePictureFailed);
+ connect(d, &AndroidCameraPrivate::lastPreviewFrameFetched, this, &AndroidCamera::lastPreviewFrameFetched);
+}
+
+AndroidCamera::~AndroidCamera()
+{
+ Q_D(AndroidCamera);
+ if (d->m_camera.isValid()) {
+ release();
+ QWriteLocker locker(rwLock);
+ cameras->remove(cameraId());
+ }
+
+ m_worker->exit();
+ m_worker->wait(5000);
+}
+
+AndroidCamera *AndroidCamera::open(int cameraId)
+{
+ if (!qt_androidCheckCameraPermission())
+ return nullptr;
+
+ AndroidCameraPrivate *d = new AndroidCameraPrivate();
+ QThread *worker = new QThread;
+ worker->start();
+ d->moveToThread(worker);
+ connect(worker, &QThread::finished, d, &AndroidCameraPrivate::deleteLater);
+ bool ok = true;
+ QMetaObject::invokeMethod(d, "init", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, ok), Q_ARG(int, cameraId));
+ if (!ok) {
+ worker->quit();
+ worker->wait(5000);
+ delete worker;
+ return 0;
+ }
+
+ AndroidCamera *q = new AndroidCamera(d, worker);
+ QWriteLocker locker(rwLock);
+ cameras->insert(cameraId, q);
+
+ return q;
+}
+
+int AndroidCamera::cameraId() const
+{
+ Q_D(const AndroidCamera);
+ return d->m_cameraId;
+}
+
+bool AndroidCamera::lock()
+{
+ Q_D(AndroidCamera);
+ bool ok = true;
+ QMetaObject::invokeMethod(d, "lock", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, ok));
+ return ok;
+}
+
+bool AndroidCamera::unlock()
+{
+ Q_D(AndroidCamera);
+ bool ok = true;
+ QMetaObject::invokeMethod(d, "unlock", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, ok));
+ return ok;
+}
+
+bool AndroidCamera::reconnect()
+{
+ Q_D(AndroidCamera);
+ bool ok = true;
+ QMetaObject::invokeMethod(d, "reconnect", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, ok));
+ return ok;
+}
+
+void AndroidCamera::release()
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "release", Qt::BlockingQueuedConnection);
+}
+
+AndroidCamera::CameraFacing AndroidCamera::getFacing()
+{
+ Q_D(AndroidCamera);
+ return d->getFacing();
+}
+
+int AndroidCamera::getNativeOrientation()
+{
+ Q_D(AndroidCamera);
+ return d->getNativeOrientation();
+}
+
+QSize AndroidCamera::getPreferredPreviewSizeForVideo()
+{
+ Q_D(AndroidCamera);
+ return d->getPreferredPreviewSizeForVideo();
+}
+
+QList<QSize> AndroidCamera::getSupportedPreviewSizes()
+{
+ Q_D(AndroidCamera);
+ return d->getSupportedPreviewSizes();
+}
+
+QList<AndroidCamera::FpsRange> AndroidCamera::getSupportedPreviewFpsRange()
+{
+ Q_D(AndroidCamera);
+ return d->getSupportedPreviewFpsRange();
+}
+
+AndroidCamera::FpsRange AndroidCamera::getPreviewFpsRange()
+{
+ Q_D(AndroidCamera);
+ return d->getPreviewFpsRange();
+}
+
+void AndroidCamera::setPreviewFpsRange(FpsRange range)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setPreviewFpsRange", Q_ARG(int, range.min), Q_ARG(int, range.max));
+}
+
+AndroidCamera::ImageFormat AndroidCamera::getPreviewFormat()
+{
+ Q_D(AndroidCamera);
+ return d->getPreviewFormat();
+}
+
+void AndroidCamera::setPreviewFormat(ImageFormat fmt)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setPreviewFormat", Q_ARG(AndroidCamera::ImageFormat, fmt));
+}
+
+QList<AndroidCamera::ImageFormat> AndroidCamera::getSupportedPreviewFormats()
+{
+ Q_D(AndroidCamera);
+ return d->getSupportedPreviewFormats();
+}
+
+QSize AndroidCamera::previewSize() const
+{
+ Q_D(const AndroidCamera);
+ return d->m_previewSize;
+}
+
+QSize AndroidCamera::actualPreviewSize()
+{
+ Q_D(AndroidCamera);
+ return d->getPreviewSize();
+}
+
+void AndroidCamera::setPreviewSize(const QSize &size)
+{
+ Q_D(AndroidCamera);
+ d->m_parametersMutex.lock();
+ bool areParametersValid = d->m_parameters.isValid();
+ d->m_parametersMutex.unlock();
+ if (!areParametersValid)
+ return;
+
+ d->m_previewSize = size;
+ QMetaObject::invokeMethod(d, "updatePreviewSize");
+}
+
+bool AndroidCamera::setPreviewTexture(AndroidSurfaceTexture *surfaceTexture)
+{
+ Q_D(AndroidCamera);
+ bool ok = true;
+ QMetaObject::invokeMethod(d,
+ "setPreviewTexture",
+ Qt::BlockingQueuedConnection,
+ Q_RETURN_ARG(bool, ok),
+ Q_ARG(void *, surfaceTexture ? surfaceTexture->surfaceTexture() : 0));
+ return ok;
+}
+
+bool AndroidCamera::setPreviewDisplay(AndroidSurfaceHolder *surfaceHolder)
+{
+ Q_D(AndroidCamera);
+ bool ok = true;
+ QMetaObject::invokeMethod(d,
+ "setPreviewDisplay",
+ Qt::BlockingQueuedConnection,
+ Q_RETURN_ARG(bool, ok),
+ Q_ARG(void *, surfaceHolder ? surfaceHolder->surfaceHolder() : 0));
+ return ok;
+}
+
+void AndroidCamera::setDisplayOrientation(int degrees)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setDisplayOrientation", Qt::QueuedConnection, Q_ARG(int, degrees));
+}
+
+bool AndroidCamera::isZoomSupported()
+{
+ Q_D(AndroidCamera);
+ return d->isZoomSupported();
+}
+
+int AndroidCamera::getMaxZoom()
+{
+ Q_D(AndroidCamera);
+ return d->getMaxZoom();
+}
+
+QList<int> AndroidCamera::getZoomRatios()
+{
+ Q_D(AndroidCamera);
+ return d->getZoomRatios();
+}
+
+int AndroidCamera::getZoom()
+{
+ Q_D(AndroidCamera);
+ return d->getZoom();
+}
+
+void AndroidCamera::setZoom(int value)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setZoom", Q_ARG(int, value));
+}
+
+QStringList AndroidCamera::getSupportedFlashModes()
+{
+ Q_D(AndroidCamera);
+ return d->callParametersStringListMethod("getSupportedFlashModes");
+}
+
+QString AndroidCamera::getFlashMode()
+{
+ Q_D(AndroidCamera);
+ return d->getFlashMode();
+}
+
+void AndroidCamera::setFlashMode(const QString &value)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setFlashMode", Q_ARG(QString, value));
+}
+
+QStringList AndroidCamera::getSupportedFocusModes()
+{
+ Q_D(AndroidCamera);
+ return d->callParametersStringListMethod("getSupportedFocusModes");
+}
+
+QString AndroidCamera::getFocusMode()
+{
+ Q_D(AndroidCamera);
+ return d->getFocusMode();
+}
+
+void AndroidCamera::setFocusMode(const QString &value)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setFocusMode", Q_ARG(QString, value));
+}
+
+int AndroidCamera::getMaxNumFocusAreas()
+{
+ Q_D(AndroidCamera);
+ return d->getMaxNumFocusAreas();
+}
+
+QList<QRect> AndroidCamera::getFocusAreas()
+{
+ Q_D(AndroidCamera);
+ return d->getFocusAreas();
+}
+
+void AndroidCamera::setFocusAreas(const QList<QRect> &areas)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setFocusAreas", Q_ARG(QList<QRect>, areas));
+}
+
+void AndroidCamera::autoFocus()
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "autoFocus");
+}
+
+void AndroidCamera::cancelAutoFocus()
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "cancelAutoFocus", Qt::QueuedConnection);
+}
+
+bool AndroidCamera::isAutoExposureLockSupported()
+{
+ Q_D(AndroidCamera);
+ return d->isAutoExposureLockSupported();
+}
+
+bool AndroidCamera::getAutoExposureLock()
+{
+ Q_D(AndroidCamera);
+ return d->getAutoExposureLock();
+}
+
+void AndroidCamera::setAutoExposureLock(bool toggle)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setAutoExposureLock", Q_ARG(bool, toggle));
+}
+
+bool AndroidCamera::isAutoWhiteBalanceLockSupported()
+{
+ Q_D(AndroidCamera);
+ return d->isAutoWhiteBalanceLockSupported();
+}
+
+bool AndroidCamera::getAutoWhiteBalanceLock()
+{
+ Q_D(AndroidCamera);
+ return d->getAutoWhiteBalanceLock();
+}
+
+void AndroidCamera::setAutoWhiteBalanceLock(bool toggle)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setAutoWhiteBalanceLock", Q_ARG(bool, toggle));
+}
+
+int AndroidCamera::getExposureCompensation()
+{
+ Q_D(AndroidCamera);
+ return d->getExposureCompensation();
+}
+
+void AndroidCamera::setExposureCompensation(int value)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setExposureCompensation", Q_ARG(int, value));
+}
+
+float AndroidCamera::getExposureCompensationStep()
+{
+ Q_D(AndroidCamera);
+ return d->getExposureCompensationStep();
+}
+
+int AndroidCamera::getMinExposureCompensation()
+{
+ Q_D(AndroidCamera);
+ return d->getMinExposureCompensation();
+}
+
+int AndroidCamera::getMaxExposureCompensation()
+{
+ Q_D(AndroidCamera);
+ return d->getMaxExposureCompensation();
+}
+
+QStringList AndroidCamera::getSupportedSceneModes()
+{
+ Q_D(AndroidCamera);
+ return d->callParametersStringListMethod("getSupportedSceneModes");
+}
+
+QString AndroidCamera::getSceneMode()
+{
+ Q_D(AndroidCamera);
+ return d->getSceneMode();
+}
+
+void AndroidCamera::setSceneMode(const QString &value)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setSceneMode", Q_ARG(QString, value));
+}
+
+QStringList AndroidCamera::getSupportedWhiteBalance()
+{
+ Q_D(AndroidCamera);
+ return d->callParametersStringListMethod("getSupportedWhiteBalance");
+}
+
+QString AndroidCamera::getWhiteBalance()
+{
+ Q_D(AndroidCamera);
+ return d->getWhiteBalance();
+}
+
+void AndroidCamera::setWhiteBalance(const QString &value)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setWhiteBalance", Q_ARG(QString, value));
+}
+
+void AndroidCamera::setRotation(int rotation)
+{
+ Q_D(AndroidCamera);
+ //We need to do it here and not in worker class because we cache rotation
+ d->m_parametersMutex.lock();
+ bool areParametersValid = d->m_parameters.isValid();
+ d->m_parametersMutex.unlock();
+ if (!areParametersValid)
+ return;
+
+ d->m_rotation = rotation;
+ QMetaObject::invokeMethod(d, "updateRotation");
+}
+
+int AndroidCamera::getRotation() const
+{
+ Q_D(const AndroidCamera);
+ return d->m_rotation;
+}
+
+QList<QSize> AndroidCamera::getSupportedPictureSizes()
+{
+ Q_D(AndroidCamera);
+ return d->getSupportedPictureSizes();
+}
+
+QList<QSize> AndroidCamera::getSupportedVideoSizes()
+{
+ Q_D(AndroidCamera);
+ return d->getSupportedVideoSizes();
+}
+
+void AndroidCamera::setPictureSize(const QSize &size)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setPictureSize", Q_ARG(QSize, size));
+}
+
+void AndroidCamera::setJpegQuality(int quality)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setJpegQuality", Q_ARG(int, quality));
+}
+
+void AndroidCamera::takePicture()
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "takePicture", Qt::BlockingQueuedConnection);
+}
+
+void AndroidCamera::setupPreviewFrameCallback()
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setupPreviewFrameCallback");
+}
+
+void AndroidCamera::notifyNewFrames(bool notify)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "notifyNewFrames", Q_ARG(bool, notify));
+}
+
+void AndroidCamera::fetchLastPreviewFrame()
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "fetchLastPreviewFrame");
+}
+
+QJniObject AndroidCamera::getCameraObject()
+{
+ Q_D(AndroidCamera);
+ return d->m_camera;
+}
+
+int AndroidCamera::getNumberOfCameras()
+{
+ if (!qt_androidCheckCameraPermission())
+ return 0;
+
+ return QJniObject::callStaticMethod<jint>("android/hardware/Camera",
+ "getNumberOfCameras");
+}
+
+void AndroidCamera::getCameraInfo(int id, QCameraDevicePrivate *info)
+{
+ Q_ASSERT(info);
+
+ QJniObject cameraInfo("android/hardware/Camera$CameraInfo");
+ QJniObject::callStaticMethod<void>("android/hardware/Camera",
+ "getCameraInfo",
+ "(ILandroid/hardware/Camera$CameraInfo;)V",
+ id, cameraInfo.object());
+
+ AndroidCamera::CameraFacing facing = AndroidCamera::CameraFacing(cameraInfo.getField<jint>("facing"));
+ // The orientation provided by Android is counter-clockwise, we need it clockwise
+ info->orientation = (360 - cameraInfo.getField<jint>("orientation")) % 360;
+
+ switch (facing) {
+ case AndroidCamera::CameraFacingBack:
+ info->id = QByteArray("back");
+ info->description = QStringLiteral("Rear-facing camera");
+ info->position = QCameraDevice::BackFace;
+ info->isDefault = true;
+ break;
+ case AndroidCamera::CameraFacingFront:
+ info->id = QByteArray("front");
+ info->description = QStringLiteral("Front-facing camera");
+ info->position = QCameraDevice::FrontFace;
+ break;
+ default:
+ break;
+ }
+ // Add a number to allow correct access to cameras on systems with two
+ // (and more) front/back cameras
+ if (id > 1) {
+ info->id.append(QByteArray::number(id));
+ info->description.append(QString(" %1").arg(id));
+ }
+}
+
+QVideoFrameFormat::PixelFormat AndroidCamera::QtPixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat format)
+{
+ switch (format) {
+ case AndroidCamera::NV21:
+ return QVideoFrameFormat::Format_NV21;
+ case AndroidCamera::YUY2:
+ return QVideoFrameFormat::Format_YUYV;
+ case AndroidCamera::JPEG:
+ return QVideoFrameFormat::Format_Jpeg;
+ case AndroidCamera::YV12:
+ return QVideoFrameFormat::Format_YV12;
+ default:
+ return QVideoFrameFormat::Format_Invalid;
+ }
+}
+
+AndroidCamera::ImageFormat AndroidCamera::AndroidImageFormatFromQtPixelFormat(QVideoFrameFormat::PixelFormat format)
+{
+ switch (format) {
+ case QVideoFrameFormat::Format_NV21:
+ return AndroidCamera::NV21;
+ case QVideoFrameFormat::Format_YUYV:
+ return AndroidCamera::YUY2;
+ case QVideoFrameFormat::Format_Jpeg:
+ return AndroidCamera::JPEG;
+ case QVideoFrameFormat::Format_YV12:
+ return AndroidCamera::YV12;
+ default:
+ return AndroidCamera::UnknownImageFormat;
+ }
+}
+
+QList<QCameraFormat> AndroidCamera::getSupportedFormats()
+{
+ QList<QCameraFormat> formats;
+ AndroidCamera::FpsRange range = getPreviewFpsRange();
+ for (const auto &previewSize : getSupportedVideoSizes()) {
+ for (const auto &previewFormat : getSupportedPreviewFormats()) {
+ QCameraFormatPrivate * format = new QCameraFormatPrivate();
+ format->pixelFormat = QtPixelFormatFromAndroidImageFormat(previewFormat);
+ format->resolution = previewSize;
+ format->minFrameRate = range.min;
+ format->maxFrameRate = range.max;
+ formats.append(format->create());
+ }
+ }
+
+ return formats;
+}
+
+void AndroidCamera::startPreview()
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "startPreview");
+}
+
+void AndroidCamera::stopPreview()
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "stopPreview");
+}
+
+void AndroidCamera::stopPreviewSynchronous()
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "stopPreview", Qt::BlockingQueuedConnection);
+}
+
+QJniObject AndroidCamera::getParametersObject()
+{
+ Q_D(AndroidCamera);
+ return d->m_parameters;
+}
+
+AndroidCameraPrivate::AndroidCameraPrivate()
+ : QObject()
+{
+}
+
+AndroidCameraPrivate::~AndroidCameraPrivate()
+{
+}
+
+static qint32 s_activeCameras = 0;
+
+bool AndroidCameraPrivate::init(int cameraId)
+{
+ m_cameraId = cameraId;
+ QJniEnvironment env;
+
+ const bool opened = s_activeCameras & (1 << cameraId);
+ if (opened)
+ return false;
+
+ m_camera = QJniObject::callStaticObjectMethod("android/hardware/Camera",
+ "open",
+ "(I)Landroid/hardware/Camera;",
+ cameraId);
+ if (!m_camera.isValid())
+ return false;
+
+ m_cameraListener = QJniObject(QtCameraListenerClassName, "(I)V", m_cameraId);
+ m_info = QJniObject("android/hardware/Camera$CameraInfo");
+ m_camera.callStaticMethod<void>("android/hardware/Camera",
+ "getCameraInfo",
+ "(ILandroid/hardware/Camera$CameraInfo;)V",
+ cameraId,
+ m_info.object());
+
+ QJniObject params = m_camera.callObjectMethod("getParameters",
+ "()Landroid/hardware/Camera$Parameters;");
+ m_parameters = QJniObject(params);
+ s_activeCameras |= 1 << cameraId;
+
+ return true;
+}
+
+void AndroidCameraPrivate::release()
+{
+ m_previewSize = QSize();
+ m_parametersMutex.lock();
+ m_parameters = QJniObject();
+ m_parametersMutex.unlock();
+ if (m_camera.isValid()) {
+ m_camera.callMethod<void>("release");
+ s_activeCameras &= ~(1 << m_cameraId);
+ }
+}
+
+bool AndroidCameraPrivate::lock()
+{
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_camera.objectClass(), "lock", "()V");
+ env->CallVoidMethod(m_camera.object(), methodId);
+
+ if (env.checkAndClearExceptions())
+ return false;
+ return true;
+}
+
+bool AndroidCameraPrivate::unlock()
+{
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_camera.objectClass(), "unlock", "()V");
+ env->CallVoidMethod(m_camera.object(), methodId);
+
+ if (env.checkAndClearExceptions())
+ return false;
+ return true;
+}
+
+bool AndroidCameraPrivate::reconnect()
+{
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_camera.objectClass(), "reconnect", "()V");
+ env->CallVoidMethod(m_camera.object(), methodId);
+
+ if (env.checkAndClearExceptions())
+ return false;
+ return true;
+}
+
+AndroidCamera::CameraFacing AndroidCameraPrivate::getFacing()
+{
+ return AndroidCamera::CameraFacing(m_info.getField<jint>("facing"));
+}
+
+int AndroidCameraPrivate::getNativeOrientation()
+{
+ return m_info.getField<jint>("orientation");
+}
+
+QSize AndroidCameraPrivate::getPreferredPreviewSizeForVideo()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return QSize();
+
+ QJniObject size = m_parameters.callObjectMethod("getPreferredPreviewSizeForVideo",
+ "()Landroid/hardware/Camera$Size;");
+
+ if (!size.isValid())
+ return QSize();
+
+ return QSize(size.getField<jint>("width"), size.getField<jint>("height"));
+}
+
+QList<QSize> AndroidCameraPrivate::getSupportedPreviewSizes()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+ return getSupportedPreviewSizes(m_parameters);
+}
+
+QList<QSize> AndroidCameraPrivate::getSupportedPreviewSizes(QJniObject &parameters)
+{
+ QList<QSize> list;
+
+ if (parameters.isValid()) {
+ QJniObject sizeList = parameters.callObjectMethod("getSupportedPreviewSizes",
+ "()Ljava/util/List;");
+ int count = sizeList.callMethod<jint>("size");
+ for (int i = 0; i < count; ++i) {
+ QJniObject size = sizeList.callObjectMethod("get",
+ "(I)Ljava/lang/Object;",
+ i);
+ list.append(QSize(size.getField<jint>("width"), size.getField<jint>("height")));
+ }
+
+ std::sort(list.begin(), list.end(), qt_sizeLessThan);
+ }
+
+ return list;
+}
+
+QList<AndroidCamera::FpsRange> AndroidCameraPrivate::getSupportedPreviewFpsRange()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ QJniEnvironment env;
+
+ QList<AndroidCamera::FpsRange> rangeList;
+
+ if (m_parameters.isValid()) {
+ QJniObject rangeListNative = m_parameters.callObjectMethod("getSupportedPreviewFpsRange",
+ "()Ljava/util/List;");
+ int count = rangeListNative.callMethod<jint>("size");
+
+ rangeList.reserve(count);
+
+ for (int i = 0; i < count; ++i) {
+ QJniObject range = rangeListNative.callObjectMethod("get",
+ "(I)Ljava/lang/Object;",
+ i);
+
+ jintArray jRange = static_cast<jintArray>(range.object());
+ jint* rangeArray = env->GetIntArrayElements(jRange, 0);
+
+ AndroidCamera::FpsRange fpsRange;
+
+ fpsRange.min = rangeArray[0];
+ fpsRange.max = rangeArray[1];
+
+ env->ReleaseIntArrayElements(jRange, rangeArray, 0);
+
+ rangeList << fpsRange;
+ }
+ }
+
+ return rangeList;
+}
+
+AndroidCamera::FpsRange AndroidCameraPrivate::getPreviewFpsRange()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+ return getPreviewFpsRange(m_parameters);
+}
+
+AndroidCamera::FpsRange AndroidCameraPrivate::getPreviewFpsRange(QJniObject &parameters)
+{
+ QJniEnvironment env;
+
+ AndroidCamera::FpsRange range;
+
+ if (!parameters.isValid())
+ return range;
+
+ jintArray jRangeArray = env->NewIntArray(2);
+ parameters.callMethod<void>("getPreviewFpsRange", "([I)V", jRangeArray);
+
+ jint* jRangeElements = env->GetIntArrayElements(jRangeArray, 0);
+
+ // Android Camera API returns values scaled by 1000, so divide here to report
+ // normal values for Qt
+ range.min = jRangeElements[0] / 1000;
+ range.max = jRangeElements[1] / 1000;
+
+ env->ReleaseIntArrayElements(jRangeArray, jRangeElements, 0);
+ env->DeleteLocalRef(jRangeArray);
+
+ return range;
+}
+
+void AndroidCameraPrivate::setPreviewFpsRange(int min, int max)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ // Android Camera API returns values scaled by 1000, so multiply here to
+ // give Android API the scale is expects
+ m_parameters.callMethod<void>("setPreviewFpsRange", "(II)V", min * 1000, max * 1000);
+}
+
+AndroidCamera::ImageFormat AndroidCameraPrivate::getPreviewFormat()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return AndroidCamera::UnknownImageFormat;
+
+ return AndroidCamera::ImageFormat(m_parameters.callMethod<jint>("getPreviewFormat"));
+}
+
+void AndroidCameraPrivate::setPreviewFormat(AndroidCamera::ImageFormat fmt)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ m_parameters.callMethod<void>("setPreviewFormat", "(I)V", jint(fmt));
+ applyParameters();
+}
+
+QList<AndroidCamera::ImageFormat> AndroidCameraPrivate::getSupportedPreviewFormats()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+ return getSupportedPreviewFormats(m_parameters);
+}
+
+QList<AndroidCamera::ImageFormat> AndroidCameraPrivate::getSupportedPreviewFormats(QJniObject &parameters)
+{
+ QList<AndroidCamera::ImageFormat> list;
+
+ if (parameters.isValid()) {
+ QJniObject formatList = parameters.callObjectMethod("getSupportedPreviewFormats",
+ "()Ljava/util/List;");
+ int count = formatList.callMethod<jint>("size");
+ for (int i = 0; i < count; ++i) {
+ QJniObject format = formatList.callObjectMethod("get",
+ "(I)Ljava/lang/Object;",
+ i);
+ list.append(AndroidCamera::ImageFormat(format.callMethod<jint>("intValue")));
+ }
+ }
+
+ return list;
+}
+
+QSize AndroidCameraPrivate::getPreviewSize()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return QSize();
+
+ QJniObject size = m_parameters.callObjectMethod("getPreviewSize",
+ "()Landroid/hardware/Camera$Size;");
+
+ if (!size.isValid())
+ return QSize();
+
+ return QSize(size.getField<jint>("width"), size.getField<jint>("height"));
+}
+
+void AndroidCameraPrivate::updatePreviewSize()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (m_previewSize.isValid()) {
+ m_parameters.callMethod<void>("setPreviewSize", "(II)V", m_previewSize.width(), m_previewSize.height());
+ applyParameters();
+ }
+
+ emit previewSizeChanged();
+}
+
+bool AndroidCameraPrivate::setPreviewTexture(void *surfaceTexture)
+{
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_camera.objectClass(), "setPreviewTexture",
+ "(Landroid/graphics/SurfaceTexture;)V");
+ env->CallVoidMethod(m_camera.object(), methodId, static_cast<jobject>(surfaceTexture));
+
+ if (env.checkAndClearExceptions())
+ return false;
+ return true;
+}
+
+bool AndroidCameraPrivate::setPreviewDisplay(void *surfaceHolder)
+{
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_camera.objectClass(), "setPreviewDisplay",
+ "(Landroid/view/SurfaceHolder;)V");
+ env->CallVoidMethod(m_camera.object(), methodId, static_cast<jobject>(surfaceHolder));
+
+ if (env.checkAndClearExceptions())
+ return false;
+ return true;
+}
+
+void AndroidCameraPrivate::setDisplayOrientation(int degrees)
+{
+ m_camera.callMethod<void>("setDisplayOrientation", "(I)V", degrees);
+ m_cameraListener.callMethod<void>("setPhotoRotation", "(I)V", degrees);
+}
+
+bool AndroidCameraPrivate::isZoomSupported()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return false;
+
+ return m_parameters.callMethod<jboolean>("isZoomSupported");
+}
+
+int AndroidCameraPrivate::getMaxZoom()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return 0;
+
+ return m_parameters.callMethod<jint>("getMaxZoom");
+}
+
+QList<int> AndroidCameraPrivate::getZoomRatios()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ QList<int> ratios;
+
+ if (m_parameters.isValid()) {
+ QJniObject ratioList = m_parameters.callObjectMethod("getZoomRatios",
+ "()Ljava/util/List;");
+ int count = ratioList.callMethod<jint>("size");
+ for (int i = 0; i < count; ++i) {
+ QJniObject zoomRatio = ratioList.callObjectMethod("get",
+ "(I)Ljava/lang/Object;",
+ i);
+
+ ratios.append(zoomRatio.callMethod<jint>("intValue"));
+ }
+ }
+
+ return ratios;
+}
+
+int AndroidCameraPrivate::getZoom()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return 0;
+
+ return m_parameters.callMethod<jint>("getZoom");
+}
+
+void AndroidCameraPrivate::setZoom(int value)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ m_parameters.callMethod<void>("setZoom", "(I)V", value);
+ applyParameters();
+}
+
+QString AndroidCameraPrivate::getFlashMode()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ QString value;
+
+ if (m_parameters.isValid()) {
+ QJniObject flashMode = m_parameters.callObjectMethod("getFlashMode",
+ "()Ljava/lang/String;");
+ if (flashMode.isValid())
+ value = flashMode.toString();
+ }
+
+ return value;
+}
+
+void AndroidCameraPrivate::setFlashMode(const QString &value)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ m_parameters.callMethod<void>("setFlashMode",
+ "(Ljava/lang/String;)V",
+ QJniObject::fromString(value).object());
+ applyParameters();
+}
+
+QString AndroidCameraPrivate::getFocusMode()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ QString value;
+
+ if (m_parameters.isValid()) {
+ QJniObject focusMode = m_parameters.callObjectMethod("getFocusMode",
+ "()Ljava/lang/String;");
+ if (focusMode.isValid())
+ value = focusMode.toString();
+ }
+
+ return value;
+}
+
+void AndroidCameraPrivate::setFocusMode(const QString &value)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ m_parameters.callMethod<void>("setFocusMode",
+ "(Ljava/lang/String;)V",
+ QJniObject::fromString(value).object());
+ applyParameters();
+}
+
+int AndroidCameraPrivate::getMaxNumFocusAreas()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return 0;
+
+ return m_parameters.callMethod<jint>("getMaxNumFocusAreas");
+}
+
+QList<QRect> AndroidCameraPrivate::getFocusAreas()
+{
+ QList<QRect> areas;
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (m_parameters.isValid()) {
+ QJniObject list = m_parameters.callObjectMethod("getFocusAreas",
+ "()Ljava/util/List;");
+
+ if (list.isValid()) {
+ int count = list.callMethod<jint>("size");
+ for (int i = 0; i < count; ++i) {
+ QJniObject area = list.callObjectMethod("get",
+ "(I)Ljava/lang/Object;",
+ i);
+
+ areas.append(areaToRect(area.object()));
+ }
+ }
+ }
+
+ return areas;
+}
+
+void AndroidCameraPrivate::setFocusAreas(const QList<QRect> &areas)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid() || areas.isEmpty())
+ return;
+
+ QJniObject list;
+
+ if (!areas.isEmpty()) {
+ QJniEnvironment env;
+ QJniObject arrayList("java/util/ArrayList", "(I)V", areas.size());
+ for (int i = 0; i < areas.size(); ++i) {
+ arrayList.callMethod<jboolean>("add",
+ "(Ljava/lang/Object;)Z",
+ rectToArea(areas.at(i)).object());
+ }
+ list = arrayList;
+ }
+
+ m_parameters.callMethod<void>("setFocusAreas", "(Ljava/util/List;)V", list.object());
+
+ applyParameters();
+}
+
+void AndroidCameraPrivate::autoFocus()
+{
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_camera.objectClass(), "autoFocus",
+ "(Landroid/hardware/Camera$AutoFocusCallback;)V");
+ env->CallVoidMethod(m_camera.object(), methodId, m_cameraListener.object());
+
+ if (!env.checkAndClearExceptions())
+ emit autoFocusStarted();
+}
+
+void AndroidCameraPrivate::cancelAutoFocus()
+{
+ QJniEnvironment env;
+ m_camera.callMethod<void>("cancelAutoFocus");
+}
+
+bool AndroidCameraPrivate::isAutoExposureLockSupported()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return false;
+
+ return m_parameters.callMethod<jboolean>("isAutoExposureLockSupported");
+}
+
+bool AndroidCameraPrivate::getAutoExposureLock()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return false;
+
+ return m_parameters.callMethod<jboolean>("getAutoExposureLock");
+}
+
+void AndroidCameraPrivate::setAutoExposureLock(bool toggle)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ m_parameters.callMethod<void>("setAutoExposureLock", "(Z)V", toggle);
+ applyParameters();
+}
+
+bool AndroidCameraPrivate::isAutoWhiteBalanceLockSupported()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return false;
+
+ return m_parameters.callMethod<jboolean>("isAutoWhiteBalanceLockSupported");
+}
+
+bool AndroidCameraPrivate::getAutoWhiteBalanceLock()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return false;
+
+ return m_parameters.callMethod<jboolean>("getAutoWhiteBalanceLock");
+}
+
+void AndroidCameraPrivate::setAutoWhiteBalanceLock(bool toggle)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ m_parameters.callMethod<void>("setAutoWhiteBalanceLock", "(Z)V", toggle);
+ applyParameters();
+}
+
+int AndroidCameraPrivate::getExposureCompensation()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return 0;
+
+ return m_parameters.callMethod<jint>("getExposureCompensation");
+}
+
+void AndroidCameraPrivate::setExposureCompensation(int value)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ m_parameters.callMethod<void>("setExposureCompensation", "(I)V", value);
+ applyParameters();
+}
+
+float AndroidCameraPrivate::getExposureCompensationStep()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return 0;
+
+ return m_parameters.callMethod<jfloat>("getExposureCompensationStep");
+}
+
+int AndroidCameraPrivate::getMinExposureCompensation()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return 0;
+
+ return m_parameters.callMethod<jint>("getMinExposureCompensation");
+}
+
+int AndroidCameraPrivate::getMaxExposureCompensation()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return 0;
+
+ return m_parameters.callMethod<jint>("getMaxExposureCompensation");
+}
+
+QString AndroidCameraPrivate::getSceneMode()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ QString value;
+
+ if (m_parameters.isValid()) {
+ QJniObject sceneMode = m_parameters.callObjectMethod("getSceneMode",
+ "()Ljava/lang/String;");
+ if (sceneMode.isValid())
+ value = sceneMode.toString();
+ }
+
+ return value;
+}
+
+void AndroidCameraPrivate::setSceneMode(const QString &value)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ m_parameters.callMethod<void>("setSceneMode",
+ "(Ljava/lang/String;)V",
+ QJniObject::fromString(value).object());
+ applyParameters();
+}
+
+QString AndroidCameraPrivate::getWhiteBalance()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ QString value;
+
+ if (m_parameters.isValid()) {
+ QJniObject wb = m_parameters.callObjectMethod("getWhiteBalance",
+ "()Ljava/lang/String;");
+ if (wb.isValid())
+ value = wb.toString();
+ }
+
+ return value;
+}
+
+void AndroidCameraPrivate::setWhiteBalance(const QString &value)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ m_parameters.callMethod<void>("setWhiteBalance",
+ "(Ljava/lang/String;)V",
+ QJniObject::fromString(value).object());
+ applyParameters();
+
+ emit whiteBalanceChanged();
+}
+
+void AndroidCameraPrivate::updateRotation()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ m_parameters.callMethod<void>("setRotation", "(I)V", m_rotation);
+ applyParameters();
+}
+
+QList<QSize> AndroidCameraPrivate::getSupportedPictureSizes()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ QList<QSize> list;
+
+ if (m_parameters.isValid()) {
+ QJniObject sizeList = m_parameters.callObjectMethod("getSupportedPictureSizes",
+ "()Ljava/util/List;");
+ int count = sizeList.callMethod<jint>("size");
+ for (int i = 0; i < count; ++i) {
+ QJniObject size = sizeList.callObjectMethod("get",
+ "(I)Ljava/lang/Object;",
+ i);
+ list.append(QSize(size.getField<jint>("width"), size.getField<jint>("height")));
+ }
+
+ std::sort(list.begin(), list.end(), qt_sizeLessThan);
+ }
+
+ return list;
+}
+
+QList<QSize> AndroidCameraPrivate::getSupportedVideoSizes()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+ QList<QSize> list;
+
+ if (m_parameters.isValid()) {
+ QJniObject sizeList = m_parameters.callObjectMethod("getSupportedVideoSizes",
+ "()Ljava/util/List;");
+ if (!sizeList.isValid())
+ return list;
+
+ int count = sizeList.callMethod<jint>("size");
+ for (int i = 0; i < count; ++i) {
+ const QJniObject size = sizeList.callObjectMethod("get", "(I)Ljava/lang/Object;", i);
+ if (size.isValid())
+ list.append(QSize(size.getField<jint>("width"), size.getField<jint>("height")));
+ }
+ std::sort(list.begin(), list.end(), qt_sizeLessThan);
+ }
+
+ return list;
+}
+
+void AndroidCameraPrivate::setPictureSize(const QSize &size)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ m_parameters.callMethod<void>("setPictureSize", "(II)V", size.width(), size.height());
+ applyParameters();
+}
+
+void AndroidCameraPrivate::setJpegQuality(int quality)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ if (!m_parameters.isValid())
+ return;
+
+ m_parameters.callMethod<void>("setJpegQuality", "(I)V", quality);
+ applyParameters();
+}
+
+void AndroidCameraPrivate::startPreview()
+{
+ setupPreviewFrameCallback();
+
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_camera.objectClass(), "startPreview", "()V");
+ env->CallVoidMethod(m_camera.object(), methodId);
+
+ if (env.checkAndClearExceptions())
+ emit previewFailedToStart();
+ else
+ emit previewStarted();
+}
+
+void AndroidCameraPrivate::stopPreview()
+{
+ // cancel any pending new frame notification
+ m_cameraListener.callMethod<void>("notifyWhenFrameAvailable", "(Z)V", false);
+ m_camera.callMethod<void>("stopPreview");
+ emit previewStopped();
+}
+
+void AndroidCameraPrivate::takePicture()
+{
+ // We must clear the preview callback before calling takePicture(), otherwise the call will
+ // block and the camera server will be frozen until the next device restart...
+ // That problem only happens on some devices and on the emulator
+ m_cameraListener.callMethod<void>("clearPreviewCallback", "(Landroid/hardware/Camera;)V", m_camera.object());
+
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_camera.objectClass(), "takePicture",
+ "(Landroid/hardware/Camera$ShutterCallback;"
+ "Landroid/hardware/Camera$PictureCallback;"
+ "Landroid/hardware/Camera$PictureCallback;)V");
+ env->CallVoidMethod(m_camera.object(), methodId, m_cameraListener.object(),
+ jobject(0), m_cameraListener.object());
+
+ if (env.checkAndClearExceptions())
+ emit takePictureFailed();
+}
+
+void AndroidCameraPrivate::setupPreviewFrameCallback()
+{
+ m_cameraListener.callMethod<void>("setupPreviewCallback", "(Landroid/hardware/Camera;)V", m_camera.object());
+}
+
+void AndroidCameraPrivate::notifyNewFrames(bool notify)
+{
+ m_cameraListener.callMethod<void>("notifyNewFrames", "(Z)V", notify);
+}
+
+void AndroidCameraPrivate::fetchLastPreviewFrame()
+{
+ QJniEnvironment env;
+ QJniObject data = m_cameraListener.callObjectMethod("lastPreviewBuffer", "()[B");
+
+ if (!data.isValid()) {
+ // If there's no buffer received yet, retry when the next one arrives
+ m_cameraListener.callMethod<void>("notifyWhenFrameAvailable", "(Z)V", true);
+ return;
+ }
+
+ const int arrayLength = env->GetArrayLength(static_cast<jbyteArray>(data.object()));
+ if (arrayLength == 0)
+ return;
+
+ QByteArray bytes(arrayLength, Qt::Uninitialized);
+ env->GetByteArrayRegion(static_cast<jbyteArray>(data.object()),
+ 0,
+ arrayLength,
+ reinterpret_cast<jbyte *>(bytes.data()));
+
+ const int width = m_cameraListener.callMethod<jint>("previewWidth");
+ const int height = m_cameraListener.callMethod<jint>("previewHeight");
+ const int format = m_cameraListener.callMethod<jint>("previewFormat");
+ const int bpl = m_cameraListener.callMethod<jint>("previewBytesPerLine");
+
+ QVideoFrameFormat frameFormat(
+ QSize(width, height),
+ qt_pixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat(format)));
+
+ QVideoFrame frame = QVideoFramePrivate::createFrame(
+ std::make_unique<QMemoryVideoBuffer>(std::move(bytes), bpl), std::move(frameFormat));
+
+ emit lastPreviewFrameFetched(frame);
+}
+
+void AndroidCameraPrivate::applyParameters()
+{
+ QJniEnvironment env;
+ m_camera.callMethod<void>("setParameters",
+ "(Landroid/hardware/Camera$Parameters;)V",
+ m_parameters.object());
+}
+
+QStringList AndroidCameraPrivate::callParametersStringListMethod(const QByteArray &methodName)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_parametersMutex);
+
+ QStringList stringList;
+
+ if (m_parameters.isValid()) {
+ QJniObject list = m_parameters.callObjectMethod(methodName.constData(),
+ "()Ljava/util/List;");
+
+ if (list.isValid()) {
+ int count = list.callMethod<jint>("size");
+ for (int i = 0; i < count; ++i) {
+ QJniObject string = list.callObjectMethod("get",
+ "(I)Ljava/lang/Object;",
+ i);
+ stringList.append(string.toString());
+ }
+ }
+ }
+
+ return stringList;
+}
+
+bool AndroidCamera::registerNativeMethods()
+{
+ static const JNINativeMethod methods[] = {
+ {"notifyAutoFocusComplete", "(IZ)V", (void *)notifyAutoFocusComplete},
+ {"notifyPictureExposed", "(I)V", (void *)notifyPictureExposed},
+ {"notifyPictureCaptured", "(I[B)V", (void *)notifyPictureCaptured},
+ {"notifyNewPreviewFrame", "(I[BIIII)V", (void *)notifyNewPreviewFrame},
+ {"notifyFrameAvailable", "(I)V", (void *)notifyFrameAvailable}
+ };
+
+ const int size = std::size(methods);
+ return QJniEnvironment().registerNativeMethods(QtCameraListenerClassName, methods, size);
+}
+
+QT_END_NAMESPACE
+
+#include "androidcamera.moc"
+#include "moc_androidcamera_p.cpp"
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidcamera_p.h b/src/plugins/multimedia/android/wrappers/jni/androidcamera_p.h
new file mode 100644
index 000000000..8375cf3b1
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidcamera_p.h
@@ -0,0 +1,208 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2016 Ruslan Baratov
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef ANDROIDCAMERA_H
+#define ANDROIDCAMERA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qobject.h>
+#include <qsize.h>
+#include <qrect.h>
+#include <QtMultimedia/qcamera.h>
+#include <QtCore/qjniobject.h>
+#include <private/qcameradevice_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QThread;
+
+class AndroidCameraPrivate;
+class AndroidSurfaceTexture;
+class AndroidSurfaceHolder;
+
+class AndroidCamera : public QObject
+{
+ Q_OBJECT
+public:
+ enum CameraFacing {
+ CameraFacingBack = 0,
+ CameraFacingFront = 1
+ };
+ Q_ENUM(CameraFacing)
+
+ enum ImageFormat { // same values as in android.graphics.ImageFormat Java class
+ UnknownImageFormat = 0,
+ RGB565 = 4,
+ NV16 = 16,
+ NV21 = 17,
+ YUY2 = 20,
+ JPEG = 256,
+ YV12 = 842094169
+ };
+ Q_ENUM(ImageFormat)
+
+ // http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getSupportedPreviewFpsRange%28%29
+ // "The values are multiplied by 1000 and represented in integers"
+ struct FpsRange {
+ int min;
+ int max;
+
+ FpsRange(): min(0), max(0) {}
+
+ qreal getMinReal() const { return min / 1000.0; }
+ qreal getMaxReal() const { return max / 1000.0; }
+
+ static FpsRange makeFromQReal(qreal min, qreal max)
+ {
+ FpsRange range;
+ range.min = static_cast<int>(min * 1000.0);
+ range.max = static_cast<int>(max * 1000.0);
+ return range;
+ }
+ };
+
+ ~AndroidCamera();
+
+ static AndroidCamera *open(int cameraId);
+
+ int cameraId() const;
+
+ bool lock();
+ bool unlock();
+ bool reconnect();
+ void release();
+
+ CameraFacing getFacing();
+ int getNativeOrientation();
+
+ QSize getPreferredPreviewSizeForVideo();
+ QList<QSize> getSupportedPreviewSizes();
+
+ QList<FpsRange> getSupportedPreviewFpsRange();
+
+ FpsRange getPreviewFpsRange();
+ void setPreviewFpsRange(FpsRange);
+
+ ImageFormat getPreviewFormat();
+ void setPreviewFormat(ImageFormat fmt);
+ QList<ImageFormat> getSupportedPreviewFormats();
+
+ QSize previewSize() const;
+ QSize actualPreviewSize();
+ void setPreviewSize(const QSize &size);
+ bool setPreviewTexture(AndroidSurfaceTexture *surfaceTexture);
+ bool setPreviewDisplay(AndroidSurfaceHolder *surfaceHolder);
+ void setDisplayOrientation(int degrees);
+
+ bool isZoomSupported();
+ int getMaxZoom();
+ QList<int> getZoomRatios();
+ int getZoom();
+ void setZoom(int value);
+
+ QStringList getSupportedFlashModes();
+ QString getFlashMode();
+ void setFlashMode(const QString &value);
+
+ QStringList getSupportedFocusModes();
+ QString getFocusMode();
+ void setFocusMode(const QString &value);
+
+ int getMaxNumFocusAreas();
+ QList<QRect> getFocusAreas();
+ void setFocusAreas(const QList<QRect> &areas);
+
+ void autoFocus();
+ void cancelAutoFocus();
+
+ bool isAutoExposureLockSupported();
+ bool getAutoExposureLock();
+ void setAutoExposureLock(bool toggle);
+
+ bool isAutoWhiteBalanceLockSupported();
+ bool getAutoWhiteBalanceLock();
+ void setAutoWhiteBalanceLock(bool toggle);
+
+ int getExposureCompensation();
+ void setExposureCompensation(int value);
+ float getExposureCompensationStep();
+ int getMinExposureCompensation();
+ int getMaxExposureCompensation();
+
+ QStringList getSupportedSceneModes();
+ QString getSceneMode();
+ void setSceneMode(const QString &value);
+
+ QStringList getSupportedWhiteBalance();
+ QString getWhiteBalance();
+ void setWhiteBalance(const QString &value);
+
+ void setRotation(int rotation);
+ int getRotation() const;
+
+ QList<QCameraFormat> getSupportedFormats();
+ QList<QSize> getSupportedPictureSizes();
+ QList<QSize> getSupportedVideoSizes();
+ void setPictureSize(const QSize &size);
+ void setJpegQuality(int quality);
+
+ void startPreview();
+ void stopPreview();
+ void stopPreviewSynchronous();
+
+ void takePicture();
+
+ void setupPreviewFrameCallback();
+ void notifyNewFrames(bool notify);
+ void fetchLastPreviewFrame();
+ QJniObject getCameraObject();
+ QJniObject getParametersObject();
+
+ static int getNumberOfCameras();
+ static void getCameraInfo(int id, QCameraDevicePrivate *info);
+ static QVideoFrameFormat::PixelFormat QtPixelFormatFromAndroidImageFormat(AndroidCamera::ImageFormat);
+ static AndroidCamera::ImageFormat AndroidImageFormatFromQtPixelFormat(QVideoFrameFormat::PixelFormat);
+ static bool requestCameraPermission();
+
+ static bool registerNativeMethods();
+Q_SIGNALS:
+ void previewSizeChanged();
+ void previewStarted();
+ void previewFailedToStart();
+ void previewStopped();
+
+ void autoFocusStarted();
+ void autoFocusComplete(bool success);
+
+ void whiteBalanceChanged();
+
+ void takePictureFailed();
+ void pictureExposed();
+ void pictureCaptured(const QByteArray &frame, QVideoFrameFormat::PixelFormat format, QSize size, int bytesPerLine);
+ void lastPreviewFrameFetched(const QVideoFrame &frame);
+ void newPreviewFrame(const QVideoFrame &frame);
+
+private:
+ AndroidCamera(AndroidCameraPrivate *d, QThread *worker);
+
+ Q_DECLARE_PRIVATE(AndroidCamera)
+ AndroidCameraPrivate *d_ptr;
+ QScopedPointer<QThread> m_worker;
+};
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(AndroidCamera::ImageFormat)
+
+#endif // ANDROIDCAMERA_H
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidmediametadataretriever.cpp b/src/plugins/multimedia/android/wrappers/jni/androidmediametadataretriever.cpp
new file mode 100644
index 000000000..25e1efdb0
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidmediametadataretriever.cpp
@@ -0,0 +1,136 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "androidmediametadataretriever_p.h"
+
+#include <QtCore/QUrl>
+#include <qdebug.h>
+#include <QtCore/qcoreapplication.h>
+
+QT_BEGIN_NAMESPACE
+
+AndroidMediaMetadataRetriever::AndroidMediaMetadataRetriever()
+{
+ m_metadataRetriever = QJniObject("android/media/MediaMetadataRetriever");
+}
+
+AndroidMediaMetadataRetriever::~AndroidMediaMetadataRetriever()
+{
+ release();
+}
+
+QString AndroidMediaMetadataRetriever::extractMetadata(MetadataKey key)
+{
+ QString value;
+
+ QJniObject metadata = m_metadataRetriever.callObjectMethod("extractMetadata",
+ "(I)Ljava/lang/String;",
+ jint(key));
+ if (metadata.isValid())
+ value = metadata.toString();
+
+ return value;
+}
+
+void AndroidMediaMetadataRetriever::release()
+{
+ if (!m_metadataRetriever.isValid())
+ return;
+
+ m_metadataRetriever.callMethod<void>("release");
+}
+
+bool AndroidMediaMetadataRetriever::setDataSource(const QUrl &url)
+{
+ if (!m_metadataRetriever.isValid())
+ return false;
+
+ QJniEnvironment env;
+ if (url.isLocalFile()) { // also includes qrc files (copied to a temp file by QMediaPlayer)
+ QJniObject string = QJniObject::fromString(url.path());
+ QJniObject fileInputStream("java/io/FileInputStream",
+ "(Ljava/lang/String;)V",
+ string.object());
+
+ if (!fileInputStream.isValid())
+ return false;
+
+ QJniObject fd = fileInputStream.callObjectMethod("getFD",
+ "()Ljava/io/FileDescriptor;");
+ if (!fd.isValid()) {
+ fileInputStream.callMethod<void>("close");
+ return false;
+ }
+
+ auto methodId = env->GetMethodID(m_metadataRetriever.objectClass(), "setDataSource",
+ "(Ljava/io/FileDescriptor;)V");
+ env->CallVoidMethod(m_metadataRetriever.object(), methodId, fd.object());
+ bool ok = !env.checkAndClearExceptions();
+ fileInputStream.callMethod<void>("close");
+ if (!ok)
+ return false;
+ } else if (url.scheme() == QLatin1String("assets")) {
+ QJniObject string = QJniObject::fromString(url.path().mid(1)); // remove first '/'
+ QJniObject activity(QNativeInterface::QAndroidApplication::context());
+ QJniObject assetManager = activity.callObjectMethod("getAssets",
+ "()Landroid/content/res/AssetManager;");
+ QJniObject assetFd = assetManager.callObjectMethod("openFd",
+ "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;",
+ string.object());
+ if (!assetFd.isValid())
+ return false;
+
+ QJniObject fd = assetFd.callObjectMethod("getFileDescriptor",
+ "()Ljava/io/FileDescriptor;");
+ if (!fd.isValid()) {
+ assetFd.callMethod<void>("close");
+ return false;
+ }
+
+ auto methodId = env->GetMethodID(m_metadataRetriever.objectClass(), "setDataSource",
+ "(Ljava/io/FileDescriptor;JJ)V");
+ env->CallVoidMethod(m_metadataRetriever.object(), methodId,
+ fd.object(),
+ assetFd.callMethod<jlong>("getStartOffset"),
+ assetFd.callMethod<jlong>("getLength"));
+ bool ok = !env.checkAndClearExceptions();
+ assetFd.callMethod<void>("close");
+
+ if (!ok)
+ return false;
+ } else if (url.scheme() != QLatin1String("content")) {
+ // On API levels >= 14, only setDataSource(String, Map<String, String>) accepts remote media
+ QJniObject string = QJniObject::fromString(url.toString(QUrl::FullyEncoded));
+ QJniObject hash("java/util/HashMap");
+
+ auto methodId = env->GetMethodID(m_metadataRetriever.objectClass(), "setDataSource",
+ "(Ljava/lang/String;Ljava/util/Map;)V");
+ env->CallVoidMethod(m_metadataRetriever.object(), methodId,
+ string.object(), hash.object());
+ if (env.checkAndClearExceptions())
+ return false;
+ } else {
+ // While on API levels < 14, only setDataSource(Context, Uri) is available and works for
+ // remote media...
+ QJniObject string = QJniObject::fromString(url.toString(QUrl::FullyEncoded));
+ QJniObject uri = m_metadataRetriever.callStaticObjectMethod(
+ "android/net/Uri",
+ "parse",
+ "(Ljava/lang/String;)Landroid/net/Uri;",
+ string.object());
+ if (!uri.isValid())
+ return false;
+
+ auto methodId = env->GetMethodID(m_metadataRetriever.objectClass(), "setDataSource",
+ "(Landroid/content/Context;Landroid/net/Uri;)V");
+ env->CallVoidMethod(m_metadataRetriever.object(), methodId,
+ QNativeInterface::QAndroidApplication::context().object(),
+ uri.object());
+ if (env.checkAndClearExceptions())
+ return false;
+ }
+
+ return true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidmediametadataretriever_p.h b/src/plugins/multimedia/android/wrappers/jni/androidmediametadataretriever_p.h
new file mode 100644
index 000000000..68e346336
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidmediametadataretriever_p.h
@@ -0,0 +1,66 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef ANDROIDMEDIAMETADATARETRIEVER_H
+#define ANDROIDMEDIAMETADATARETRIEVER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/private/qglobal_p.h>
+#include <QtCore/qurl.h>
+#include <QtCore/qjniobject.h>
+
+QT_BEGIN_NAMESPACE
+
+class AndroidMediaMetadataRetriever
+{
+public:
+ enum MetadataKey {
+ Album = 1,
+ AlbumArtist = 13,
+ Artist = 2,
+ Author = 3,
+ Bitrate = 20,
+ CDTrackNumber = 0,
+ Compilation = 15,
+ Composer = 4,
+ Date = 5,
+ DiscNumber = 14,
+ Duration = 9,
+ Genre = 6,
+ HasAudio = 16,
+ HasVideo = 17,
+ Location = 23,
+ MimeType = 12,
+ NumTracks = 10,
+ Title = 7,
+ VideoHeight = 19,
+ VideoWidth = 18,
+ VideoRotation = 24,
+ Writer = 11,
+ Year = 8
+ };
+
+ AndroidMediaMetadataRetriever();
+ ~AndroidMediaMetadataRetriever();
+
+ QString extractMetadata(MetadataKey key);
+ bool setDataSource(const QUrl &url);
+
+private:
+ void release();
+ QJniObject m_metadataRetriever;
+};
+
+QT_END_NAMESPACE
+
+#endif // ANDROIDMEDIAMETADATARETRIEVER_H
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidmediaplayer.cpp b/src/plugins/multimedia/android/wrappers/jni/androidmediaplayer.cpp
new file mode 100644
index 000000000..91f489f9e
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidmediaplayer.cpp
@@ -0,0 +1,535 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "androidmediaplayer_p.h"
+#include "androidsurfacetexture_p.h"
+
+#include <QList>
+#include <QReadWriteLock>
+#include <QString>
+#include <QtCore/qcoreapplication.h>
+#include <qloggingcategory.h>
+
+static const char QtAndroidMediaPlayerClassName[] = "org/qtproject/qt/android/multimedia/QtAndroidMediaPlayer";
+typedef QList<AndroidMediaPlayer *> MediaPlayerList;
+Q_GLOBAL_STATIC(MediaPlayerList, mediaPlayers)
+Q_GLOBAL_STATIC(QReadWriteLock, rwLock)
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(lcAudio, "qt.multimedia.audio")
+
+AndroidMediaPlayer::AndroidMediaPlayer()
+ : QObject()
+{
+ QWriteLocker locker(rwLock);
+ auto context = QNativeInterface::QAndroidApplication::context();
+ const jlong id = reinterpret_cast<jlong>(this);
+ mMediaPlayer = QJniObject(QtAndroidMediaPlayerClassName,
+ "(Landroid/content/Context;J)V",
+ context.object(),
+ id);
+ mediaPlayers->append(this);
+}
+
+AndroidMediaPlayer::~AndroidMediaPlayer()
+{
+ QWriteLocker locker(rwLock);
+ const int i = mediaPlayers->indexOf(this);
+ Q_ASSERT(i != -1);
+ mediaPlayers->remove(i);
+}
+
+void AndroidMediaPlayer::release()
+{
+ mMediaPlayer.callMethod<void>("release");
+}
+
+void AndroidMediaPlayer::reset()
+{
+ mMediaPlayer.callMethod<void>("reset");
+}
+
+int AndroidMediaPlayer::getCurrentPosition()
+{
+ return mMediaPlayer.callMethod<jint>("getCurrentPosition");
+}
+
+int AndroidMediaPlayer::getDuration()
+{
+ return mMediaPlayer.callMethod<jint>("getDuration");
+}
+
+bool AndroidMediaPlayer::isPlaying()
+{
+ return mMediaPlayer.callMethod<jboolean>("isPlaying");
+}
+
+int AndroidMediaPlayer::volume()
+{
+ return mMediaPlayer.callMethod<jint>("getVolume");
+}
+
+bool AndroidMediaPlayer::isMuted()
+{
+ return mMediaPlayer.callMethod<jboolean>("isMuted");
+}
+
+qreal AndroidMediaPlayer::playbackRate()
+{
+ qreal rate(1.0);
+
+ if (QNativeInterface::QAndroidApplication::sdkVersion() < 23)
+ return rate;
+
+ QJniObject player = mMediaPlayer.callObjectMethod("getMediaPlayerHandle",
+ "()Landroid/media/MediaPlayer;");
+ if (player.isValid()) {
+ QJniObject playbackParams = player.callObjectMethod("getPlaybackParams",
+ "()Landroid/media/PlaybackParams;");
+ if (playbackParams.isValid()) {
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(playbackParams.objectClass(), "getSpeed", "()F");
+ const qreal speed = env->CallFloatMethod(playbackParams.object(), methodId);
+ if (!env.checkAndClearExceptions())
+ rate = speed;
+ }
+ }
+
+ return rate;
+}
+
+jobject AndroidMediaPlayer::display()
+{
+ return mMediaPlayer.callObjectMethod("display", "()Landroid/view/SurfaceHolder;").object();
+}
+
+AndroidMediaPlayer::TrackInfo convertTrackInfo(int streamNumber, QJniObject androidTrackInfo)
+{
+ const QLatin1String unknownMimeType("application/octet-stream");
+ const QLatin1String undefinedLanguage("und");
+
+ if (!androidTrackInfo.isValid())
+ return { streamNumber, AndroidMediaPlayer::TrackType::Unknown, undefinedLanguage,
+ unknownMimeType };
+
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(androidTrackInfo.objectClass(), "getType", "()I");
+ const jint type = env->CallIntMethod(androidTrackInfo.object(), methodId);
+ if (env.checkAndClearExceptions())
+ return { streamNumber, AndroidMediaPlayer::TrackType::Unknown, undefinedLanguage,
+ unknownMimeType };
+
+ if (type < 0 || type > 5) {
+ return { streamNumber, AndroidMediaPlayer::TrackType::Unknown, undefinedLanguage,
+ unknownMimeType };
+ }
+
+ AndroidMediaPlayer::TrackType trackType = static_cast<AndroidMediaPlayer::TrackType>(type);
+
+ auto languageObject = androidTrackInfo.callObjectMethod("getLanguage", "()Ljava/lang/String;");
+ QString language = languageObject.isValid() ? languageObject.toString() : undefinedLanguage;
+
+ auto mimeTypeObject = androidTrackInfo.callObjectMethod("getMime", "()Ljava/lang/String;");
+ QString mimeType = mimeTypeObject.isValid() ? mimeTypeObject.toString() : unknownMimeType;
+
+ return { streamNumber, trackType, language, mimeType };
+}
+
+QList<AndroidMediaPlayer::TrackInfo> AndroidMediaPlayer::tracksInfo()
+{
+ auto androidTracksInfoObject = mMediaPlayer.callObjectMethod(
+ "getAllTrackInfo",
+ "()[Lorg/qtproject/qt/android/multimedia/QtAndroidMediaPlayer$TrackInfo;");
+
+ if (!androidTracksInfoObject.isValid())
+ return QList<AndroidMediaPlayer::TrackInfo>();
+
+ auto androidTracksInfo = androidTracksInfoObject.object<jobjectArray>();
+ if (!androidTracksInfo)
+ return QList<AndroidMediaPlayer::TrackInfo>();
+
+ QJniEnvironment environment;
+ auto numberofTracks = environment->GetArrayLength(androidTracksInfo);
+
+ QList<AndroidMediaPlayer::TrackInfo> tracksInformation;
+
+ for (int index = 0; index < numberofTracks; index++) {
+ auto androidTrackInformation = environment->GetObjectArrayElement(androidTracksInfo, index);
+
+ if (environment.checkAndClearExceptions()) {
+ continue;
+ }
+
+ auto trackInfo = convertTrackInfo(index, androidTrackInformation);
+ tracksInformation.insert(index, trackInfo);
+
+ environment->DeleteLocalRef(androidTrackInformation);
+ }
+
+ return tracksInformation;
+}
+
+int AndroidMediaPlayer::activeTrack(TrackType androidTrackType)
+{
+ int type = static_cast<int>(androidTrackType);
+ return mMediaPlayer.callMethod<jint>("getSelectedTrack", "(I)I", type);
+}
+
+void AndroidMediaPlayer::deselectTrack(int trackNumber)
+{
+ mMediaPlayer.callMethod<void>("deselectTrack", "(I)V", trackNumber);
+}
+
+void AndroidMediaPlayer::selectTrack(int trackNumber)
+{
+ mMediaPlayer.callMethod<void>("selectTrack", "(I)V", trackNumber);
+}
+
+void AndroidMediaPlayer::play()
+{
+ mMediaPlayer.callMethod<void>("start");
+}
+
+void AndroidMediaPlayer::pause()
+{
+ mMediaPlayer.callMethod<void>("pause");
+}
+
+void AndroidMediaPlayer::stop()
+{
+ mMediaPlayer.callMethod<void>("stop");
+}
+
+void AndroidMediaPlayer::seekTo(qint32 msec)
+{
+ mMediaPlayer.callMethod<void>("seekTo", "(I)V", jint(msec));
+}
+
+void AndroidMediaPlayer::setMuted(bool mute)
+{
+ if (mAudioBlocked)
+ return;
+
+ mMediaPlayer.callMethod<void>("mute", "(Z)V", jboolean(mute));
+}
+
+void AndroidMediaPlayer::setDataSource(const QNetworkRequest &request)
+{
+ QJniObject string = QJniObject::fromString(request.url().toString(QUrl::FullyEncoded));
+
+ mMediaPlayer.callMethod<void>("initHeaders", "()V");
+ for (auto &header : request.rawHeaderList()) {
+ auto value = request.rawHeader(header);
+ mMediaPlayer.callMethod<void>("setHeader", "(Ljava/lang/String;Ljava/lang/String;)V",
+ QJniObject::fromString(QLatin1String(header)).object(),
+ QJniObject::fromString(QLatin1String(value)).object());
+ }
+
+ mMediaPlayer.callMethod<void>("setDataSource", "(Ljava/lang/String;)V", string.object());
+}
+
+void AndroidMediaPlayer::prepareAsync()
+{
+ mMediaPlayer.callMethod<void>("prepareAsync");
+}
+
+void AndroidMediaPlayer::setVolume(int volume)
+{
+ if (mAudioBlocked)
+ return;
+
+ mMediaPlayer.callMethod<void>("setVolume", "(I)V", jint(volume));
+}
+
+void AndroidMediaPlayer::blockAudio()
+{
+ mAudioBlocked = true;
+}
+
+void AndroidMediaPlayer::unblockAudio()
+{
+ mAudioBlocked = false;
+}
+
+void AndroidMediaPlayer::startSoundStreaming(const int inputId, const int outputId)
+{
+ QJniObject::callStaticMethod<void>("org/qtproject/qt/android/multimedia/QtAudioDeviceManager",
+ "startSoundStreaming",
+ inputId,
+ outputId);
+}
+
+void AndroidMediaPlayer::stopSoundStreaming()
+{
+ QJniObject::callStaticMethod<void>(
+ "org/qtproject/qt/android/multimedia/QtAudioDeviceManager", "stopSoundStreaming");
+}
+
+bool AndroidMediaPlayer::setPlaybackRate(qreal rate)
+{
+ if (QNativeInterface::QAndroidApplication::sdkVersion() < 23) {
+ qWarning() << "Setting the playback rate on a media player requires"
+ << "Android 6.0 (API level 23) or later";
+ return false;
+ }
+
+ return mMediaPlayer.callMethod<jboolean>("setPlaybackRate", jfloat(rate));
+}
+
+void AndroidMediaPlayer::setDisplay(AndroidSurfaceTexture *surfaceTexture)
+{
+ mMediaPlayer.callMethod<void>("setDisplay",
+ "(Landroid/view/SurfaceHolder;)V",
+ surfaceTexture ? surfaceTexture->surfaceHolder() : 0);
+}
+
+bool AndroidMediaPlayer::setAudioOutput(const QByteArray &deviceId)
+{
+ const bool ret = QJniObject::callStaticMethod<jboolean>(
+ "org/qtproject/qt/android/multimedia/QtAudioDeviceManager",
+ "setAudioOutput",
+ "(I)Z",
+ deviceId.toInt());
+
+ if (!ret)
+ qCWarning(lcAudio) << "Output device not set";
+
+ return ret;
+}
+
+#if 0
+void AndroidMediaPlayer::setAudioRole(QAudio::Role role)
+{
+ QString r;
+ switch (role) {
+ case QAudio::MusicRole:
+ r = QLatin1String("CONTENT_TYPE_MUSIC");
+ break;
+ case QAudio::VideoRole:
+ r = QLatin1String("CONTENT_TYPE_MOVIE");
+ break;
+ case QAudio::VoiceCommunicationRole:
+ r = QLatin1String("USAGE_VOICE_COMMUNICATION");
+ break;
+ case QAudio::AlarmRole:
+ r = QLatin1String("USAGE_ALARM");
+ break;
+ case QAudio::NotificationRole:
+ r = QLatin1String("USAGE_NOTIFICATION");
+ break;
+ case QAudio::RingtoneRole:
+ r = QLatin1String("USAGE_NOTIFICATION_RINGTONE");
+ break;
+ case QAudio::AccessibilityRole:
+ r = QLatin1String("USAGE_ASSISTANCE_ACCESSIBILITY");
+ break;
+ case QAudio::SonificationRole:
+ r = QLatin1String("CONTENT_TYPE_SONIFICATION");
+ break;
+ case QAudio::GameRole:
+ r = QLatin1String("USAGE_GAME");
+ break;
+ default:
+ return;
+ }
+
+ int type = 0; // CONTENT_TYPE_UNKNOWN
+ int usage = 0; // USAGE_UNKNOWN
+
+ if (r == QLatin1String("CONTENT_TYPE_MOVIE"))
+ type = 3;
+ else if (r == QLatin1String("CONTENT_TYPE_MUSIC"))
+ type = 2;
+ else if (r == QLatin1String("CONTENT_TYPE_SONIFICATION"))
+ type = 4;
+ else if (r == QLatin1String("CONTENT_TYPE_SPEECH"))
+ type = 1;
+ else if (r == QLatin1String("USAGE_ALARM"))
+ usage = 4;
+ else if (r == QLatin1String("USAGE_ASSISTANCE_ACCESSIBILITY"))
+ usage = 11;
+ else if (r == QLatin1String("USAGE_ASSISTANCE_NAVIGATION_GUIDANCE"))
+ usage = 12;
+ else if (r == QLatin1String("USAGE_ASSISTANCE_SONIFICATION"))
+ usage = 13;
+ else if (r == QLatin1String("USAGE_ASSISTANT"))
+ usage = 16;
+ else if (r == QLatin1String("USAGE_GAME"))
+ usage = 14;
+ else if (r == QLatin1String("USAGE_MEDIA"))
+ usage = 1;
+ else if (r == QLatin1String("USAGE_NOTIFICATION"))
+ usage = 5;
+ else if (r == QLatin1String("USAGE_NOTIFICATION_COMMUNICATION_DELAYED"))
+ usage = 9;
+ else if (r == QLatin1String("USAGE_NOTIFICATION_COMMUNICATION_INSTANT"))
+ usage = 8;
+ else if (r == QLatin1String("USAGE_NOTIFICATION_COMMUNICATION_REQUEST"))
+ usage = 7;
+ else if (r == QLatin1String("USAGE_NOTIFICATION_EVENT"))
+ usage = 10;
+ else if (r == QLatin1String("USAGE_NOTIFICATION_RINGTONE"))
+ usage = 6;
+ else if (r == QLatin1String("USAGE_VOICE_COMMUNICATION"))
+ usage = 2;
+ else if (r == QLatin1String("USAGE_VOICE_COMMUNICATION_SIGNALLING"))
+ usage = 3;
+
+ mMediaPlayer.callMethod<void>("setAudioAttributes", "(II)V", jint(type), jint(usage));
+}
+#endif
+
+static void onErrorNative(JNIEnv *env, jobject thiz, jint what, jint extra, jlong id)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(thiz);
+ QReadLocker locker(rwLock);
+ const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
+ if (Q_UNLIKELY(i == -1))
+ return;
+
+ Q_EMIT (*mediaPlayers)[i]->error(what, extra);
+}
+
+static void onBufferingUpdateNative(JNIEnv *env, jobject thiz, jint percent, jlong id)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(thiz);
+ QReadLocker locker(rwLock);
+ const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
+ if (Q_UNLIKELY(i == -1))
+ return;
+
+ Q_EMIT (*mediaPlayers)[i]->bufferingChanged(percent);
+}
+
+static void onProgressUpdateNative(JNIEnv *env, jobject thiz, jint progress, jlong id)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(thiz);
+ QReadLocker locker(rwLock);
+ const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
+ if (Q_UNLIKELY(i == -1))
+ return;
+
+ Q_EMIT (*mediaPlayers)[i]->progressChanged(progress);
+}
+
+static void onDurationChangedNative(JNIEnv *env, jobject thiz, jint duration, jlong id)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(thiz);
+ QReadLocker locker(rwLock);
+ const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
+ if (Q_UNLIKELY(i == -1))
+ return;
+
+ Q_EMIT (*mediaPlayers)[i]->durationChanged(duration);
+}
+
+static void onInfoNative(JNIEnv *env, jobject thiz, jint what, jint extra, jlong id)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(thiz);
+ QReadLocker locker(rwLock);
+ const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
+ if (Q_UNLIKELY(i == -1))
+ return;
+
+ Q_EMIT (*mediaPlayers)[i]->info(what, extra);
+}
+
+static void onStateChangedNative(JNIEnv *env, jobject thiz, jint state, jlong id)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(thiz);
+ QReadLocker locker(rwLock);
+ const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
+ if (Q_UNLIKELY(i == -1))
+ return;
+
+ Q_EMIT (*mediaPlayers)[i]->stateChanged(state);
+}
+
+static void onVideoSizeChangedNative(JNIEnv *env,
+ jobject thiz,
+ jint width,
+ jint height,
+ jlong id)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(thiz);
+ QReadLocker locker(rwLock);
+ const int i = mediaPlayers->indexOf(reinterpret_cast<AndroidMediaPlayer *>(id));
+ if (Q_UNLIKELY(i == -1))
+ return;
+
+ Q_EMIT (*mediaPlayers)[i]->videoSizeChanged(width, height);
+}
+
+static AndroidMediaPlayer *getMediaPlayer(jlong ptr)
+{
+ auto mediaplayer = reinterpret_cast<AndroidMediaPlayer *>(ptr);
+ if (!mediaplayer || !mediaPlayers->contains(mediaplayer))
+ return nullptr;
+
+ return mediaplayer;
+}
+
+static void onTrackInfoChangedNative(JNIEnv *env, jobject thiz, jlong ptr)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(thiz);
+
+ QReadLocker locker(rwLock);
+ auto mediaplayer = getMediaPlayer(ptr);
+ if (!mediaplayer)
+ return;
+
+ emit mediaplayer->tracksInfoChanged();
+}
+
+static void onTimedTextChangedNative(JNIEnv *env, jobject thiz, jstring timedText, jint time,
+ jlong ptr)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(thiz);
+ Q_UNUSED(time);
+
+ QReadLocker locker(rwLock);
+
+ auto mediaplayer = getMediaPlayer(ptr);
+ if (!mediaplayer)
+ return;
+
+ QString subtitleText;
+ if (timedText != nullptr)
+ subtitleText = QString::fromUtf8(env->GetStringUTFChars(timedText, 0));
+
+ emit mediaplayer->timedTextChanged(subtitleText);
+}
+
+bool AndroidMediaPlayer::registerNativeMethods()
+{
+ static const JNINativeMethod methods[] = {
+ { "onErrorNative", "(IIJ)V", reinterpret_cast<void *>(onErrorNative) },
+ { "onBufferingUpdateNative", "(IJ)V", reinterpret_cast<void *>(onBufferingUpdateNative) },
+ { "onProgressUpdateNative", "(IJ)V", reinterpret_cast<void *>(onProgressUpdateNative) },
+ { "onDurationChangedNative", "(IJ)V", reinterpret_cast<void *>(onDurationChangedNative) },
+ { "onInfoNative", "(IIJ)V", reinterpret_cast<void *>(onInfoNative) },
+ { "onVideoSizeChangedNative", "(IIJ)V",
+ reinterpret_cast<void *>(onVideoSizeChangedNative) },
+ { "onStateChangedNative", "(IJ)V", reinterpret_cast<void *>(onStateChangedNative) },
+ { "onTrackInfoChangedNative", "(J)V", reinterpret_cast<void *>(onTrackInfoChangedNative) },
+ { "onTimedTextChangedNative", "(Ljava/lang/String;IJ)V",
+ reinterpret_cast<void *>(onTimedTextChangedNative) }
+ };
+
+ const int size = std::size(methods);
+ return QJniEnvironment().registerNativeMethods(QtAndroidMediaPlayerClassName, methods, size);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_androidmediaplayer_p.cpp"
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidmediaplayer_p.h b/src/plugins/multimedia/android/wrappers/jni/androidmediaplayer_p.h
new file mode 100644
index 000000000..66095b114
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidmediaplayer_p.h
@@ -0,0 +1,135 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef ANDROIDMEDIAPLAYER_H
+#define ANDROIDMEDIAPLAYER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QObject>
+#include <QNetworkRequest>
+#include <QtCore/qjniobject.h>
+#include <QAudio>
+
+QT_BEGIN_NAMESPACE
+
+class AndroidSurfaceTexture;
+
+class AndroidMediaPlayer : public QObject
+{
+ Q_OBJECT
+public:
+ AndroidMediaPlayer();
+ ~AndroidMediaPlayer();
+
+ enum MediaError
+ {
+ // What
+ MEDIA_ERROR_UNKNOWN = 1,
+ MEDIA_ERROR_SERVER_DIED = 100,
+ MEDIA_ERROR_INVALID_STATE = -38, // Undocumented
+ // Extra
+ MEDIA_ERROR_IO = -1004,
+ MEDIA_ERROR_MALFORMED = -1007,
+ MEDIA_ERROR_UNSUPPORTED = -1010,
+ MEDIA_ERROR_TIMED_OUT = -110,
+ MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200,
+ MEDIA_ERROR_BAD_THINGS_ARE_GOING_TO_HAPPEN = -2147483648 // Undocumented
+ };
+
+ enum MediaInfo
+ {
+ MEDIA_INFO_UNKNOWN = 1,
+ MEDIA_INFO_VIDEO_TRACK_LAGGING = 700,
+ MEDIA_INFO_VIDEO_RENDERING_START = 3,
+ MEDIA_INFO_BUFFERING_START = 701,
+ MEDIA_INFO_BUFFERING_END = 702,
+ MEDIA_INFO_BAD_INTERLEAVING = 800,
+ MEDIA_INFO_NOT_SEEKABLE = 801,
+ MEDIA_INFO_METADATA_UPDATE = 802
+ };
+
+ enum MediaPlayerState {
+ Uninitialized = 0x1, /* End */
+ Idle = 0x2,
+ Preparing = 0x4,
+ Prepared = 0x8,
+ Initialized = 0x10,
+ Started = 0x20,
+ Stopped = 0x40,
+ Paused = 0x80,
+ PlaybackCompleted = 0x100,
+ Error = 0x200
+ };
+
+ enum TrackType { Unknown = 0, Video, Audio, TimedText, Subtitle, Metadata };
+
+ struct TrackInfo
+ {
+ int trackNumber;
+ TrackType trackType;
+ QString language;
+ QString mimeType;
+ };
+
+ void release();
+ void reset();
+
+ int getCurrentPosition();
+ int getDuration();
+ bool isPlaying();
+ int volume();
+ bool isMuted();
+ qreal playbackRate();
+ jobject display();
+
+ void play();
+ void pause();
+ void stop();
+ void seekTo(qint32 msec);
+ void setMuted(bool mute);
+ void setDataSource(const QNetworkRequest &request);
+ void prepareAsync();
+ void setVolume(int volume);
+ static void startSoundStreaming(const int inputId, const int outputId);
+ static void stopSoundStreaming();
+ bool setPlaybackRate(qreal rate);
+ void setDisplay(AndroidSurfaceTexture *surfaceTexture);
+ static bool setAudioOutput(const QByteArray &deviceId);
+ QList<TrackInfo> tracksInfo();
+ int activeTrack(TrackType trackType);
+ void deselectTrack(int trackNumber);
+ void selectTrack(int trackNumber);
+
+ static bool registerNativeMethods();
+
+ void blockAudio();
+ void unblockAudio();
+Q_SIGNALS:
+ void error(qint32 what, qint32 extra);
+ void bufferingChanged(qint32 percent);
+ void durationChanged(qint64 duration);
+ void progressChanged(qint64 progress);
+ void stateChanged(qint32 state);
+ void info(qint32 what, qint32 extra);
+ void videoSizeChanged(qint32 width, qint32 height);
+ void timedTextChanged(QString text);
+ void tracksInfoChanged();
+
+private:
+ QJniObject mMediaPlayer;
+ bool mAudioBlocked = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // ANDROIDMEDIAPLAYER_H
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidmediarecorder.cpp b/src/plugins/multimedia/android/wrappers/jni/androidmediarecorder.cpp
new file mode 100644
index 000000000..a3c9f4556
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidmediarecorder.cpp
@@ -0,0 +1,337 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "androidmediarecorder_p.h"
+#include "androidcamera_p.h"
+#include "androidsurfacetexture_p.h"
+#include "androidsurfaceview_p.h"
+#include "qandroidglobal_p.h"
+#include "qandroidmultimediautils_p.h"
+
+#include <qmap.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qlogging.h>
+#include <QtCore/qurl.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(lcMediaRecorder, "qt.multimedia.mediarecorder.android")
+
+typedef QMap<QString, QJniObject> CamcorderProfiles;
+Q_GLOBAL_STATIC(CamcorderProfiles, g_camcorderProfiles)
+
+static QString profileKey()
+{
+ return QStringLiteral("%1-%2");
+}
+
+bool AndroidCamcorderProfile::hasProfile(jint cameraId, Quality quality)
+{
+ if (g_camcorderProfiles->contains(profileKey().arg(cameraId).arg(quality)))
+ return true;
+
+ return QJniObject::callStaticMethod<jboolean>("android/media/CamcorderProfile",
+ "hasProfile",
+ "(II)Z",
+ cameraId,
+ quality);
+}
+
+AndroidCamcorderProfile AndroidCamcorderProfile::get(jint cameraId, Quality quality)
+{
+ const QString key = profileKey().arg(cameraId).arg(quality);
+ QMap<QString, QJniObject>::const_iterator it = g_camcorderProfiles->constFind(key);
+
+ if (it != g_camcorderProfiles->constEnd())
+ return AndroidCamcorderProfile(*it);
+
+ QJniObject camProfile = QJniObject::callStaticObjectMethod("android/media/CamcorderProfile",
+ "get",
+ "(II)Landroid/media/CamcorderProfile;",
+ cameraId,
+ quality);
+
+ return AndroidCamcorderProfile((*g_camcorderProfiles)[key] = camProfile);
+}
+
+int AndroidCamcorderProfile::getValue(AndroidCamcorderProfile::Field field) const
+{
+ switch (field) {
+ case audioBitRate:
+ return m_camcorderProfile.getField<jint>("audioBitRate");
+ case audioChannels:
+ return m_camcorderProfile.getField<jint>("audioChannels");
+ case audioCodec:
+ return m_camcorderProfile.getField<jint>("audioCodec");
+ case audioSampleRate:
+ return m_camcorderProfile.getField<jint>("audioSampleRate");
+ case duration:
+ return m_camcorderProfile.getField<jint>("duration");
+ case fileFormat:
+ return m_camcorderProfile.getField<jint>("fileFormat");
+ case quality:
+ return m_camcorderProfile.getField<jint>("quality");
+ case videoBitRate:
+ return m_camcorderProfile.getField<jint>("videoBitRate");
+ case videoCodec:
+ return m_camcorderProfile.getField<jint>("videoCodec");
+ case videoFrameHeight:
+ return m_camcorderProfile.getField<jint>("videoFrameHeight");
+ case videoFrameRate:
+ return m_camcorderProfile.getField<jint>("videoFrameRate");
+ case videoFrameWidth:
+ return m_camcorderProfile.getField<jint>("videoFrameWidth");
+ }
+
+ return 0;
+}
+
+AndroidCamcorderProfile::AndroidCamcorderProfile(const QJniObject &camcorderProfile)
+{
+ m_camcorderProfile = camcorderProfile;
+}
+
+static const char QtMediaRecorderListenerClassName[] =
+ "org/qtproject/qt/android/multimedia/QtMediaRecorderListener";
+typedef QMap<jlong, AndroidMediaRecorder*> MediaRecorderMap;
+Q_GLOBAL_STATIC(MediaRecorderMap, mediaRecorders)
+
+static void notifyError(JNIEnv* , jobject, jlong id, jint what, jint extra)
+{
+ AndroidMediaRecorder *obj = mediaRecorders->value(id, 0);
+ if (obj)
+ emit obj->error(what, extra);
+}
+
+static void notifyInfo(JNIEnv* , jobject, jlong id, jint what, jint extra)
+{
+ AndroidMediaRecorder *obj = mediaRecorders->value(id, 0);
+ if (obj)
+ emit obj->info(what, extra);
+}
+
+AndroidMediaRecorder::AndroidMediaRecorder()
+ : QObject()
+ , m_id(reinterpret_cast<jlong>(this))
+{
+ m_mediaRecorder = QJniObject("android/media/MediaRecorder");
+ if (m_mediaRecorder.isValid()) {
+ QJniObject listener(QtMediaRecorderListenerClassName, "(J)V", m_id);
+ m_mediaRecorder.callMethod<void>("setOnErrorListener",
+ "(Landroid/media/MediaRecorder$OnErrorListener;)V",
+ listener.object());
+ m_mediaRecorder.callMethod<void>("setOnInfoListener",
+ "(Landroid/media/MediaRecorder$OnInfoListener;)V",
+ listener.object());
+ mediaRecorders->insert(m_id, this);
+ }
+}
+
+AndroidMediaRecorder::~AndroidMediaRecorder()
+{
+ if (m_isVideoSourceSet || m_isAudioSourceSet)
+ reset();
+
+ release();
+ mediaRecorders->remove(m_id);
+}
+
+void AndroidMediaRecorder::release()
+{
+ m_mediaRecorder.callMethod<void>("release");
+}
+
+bool AndroidMediaRecorder::prepare()
+{
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_mediaRecorder.objectClass(), "prepare", "()V");
+ env->CallVoidMethod(m_mediaRecorder.object(), methodId);
+
+ if (env.checkAndClearExceptions())
+ return false;
+ return true;
+}
+
+void AndroidMediaRecorder::reset()
+{
+ m_mediaRecorder.callMethod<void>("reset");
+ m_isAudioSourceSet = false; // Now setAudioSource can be used again.
+ m_isVideoSourceSet = false;
+}
+
+bool AndroidMediaRecorder::start()
+{
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_mediaRecorder.objectClass(), "start", "()V");
+ env->CallVoidMethod(m_mediaRecorder.object(), methodId);
+
+ if (env.checkAndClearExceptions())
+ return false;
+ return true;
+}
+
+void AndroidMediaRecorder::stop()
+{
+ m_mediaRecorder.callMethod<void>("stop");
+}
+
+void AndroidMediaRecorder::setAudioChannels(int numChannels)
+{
+ m_mediaRecorder.callMethod<void>("setAudioChannels", "(I)V", numChannels);
+}
+
+void AndroidMediaRecorder::setAudioEncoder(AudioEncoder encoder)
+{
+ QJniEnvironment env;
+ m_mediaRecorder.callMethod<void>("setAudioEncoder", "(I)V", int(encoder));
+}
+
+void AndroidMediaRecorder::setAudioEncodingBitRate(int bitRate)
+{
+ m_mediaRecorder.callMethod<void>("setAudioEncodingBitRate", "(I)V", bitRate);
+}
+
+void AndroidMediaRecorder::setAudioSamplingRate(int samplingRate)
+{
+ m_mediaRecorder.callMethod<void>("setAudioSamplingRate", "(I)V", samplingRate);
+}
+
+void AndroidMediaRecorder::setAudioSource(AudioSource source)
+{
+ if (!m_isAudioSourceSet) {
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_mediaRecorder.objectClass(), "setAudioSource", "(I)V");
+ env->CallVoidMethod(m_mediaRecorder.object(), methodId, source);
+ if (!env.checkAndClearExceptions())
+ m_isAudioSourceSet = true;
+ } else {
+ qCWarning(lcMediaRecorder) << "Audio source already set. Not setting a new source.";
+ }
+}
+
+bool AndroidMediaRecorder::isAudioSourceSet() const
+{
+ return m_isAudioSourceSet;
+}
+
+bool AndroidMediaRecorder::setAudioInput(const QByteArray &id)
+{
+ const bool ret = QJniObject::callStaticMethod<jboolean>(
+ "org/qtproject/qt/android/multimedia/QtAudioDeviceManager",
+ "setAudioInput",
+ "(Landroid/media/MediaRecorder;I)Z",
+ m_mediaRecorder.object(),
+ id.toInt());
+ if (!ret)
+ qCWarning(lcMediaRecorder) << "No default input device was set.";
+
+ return ret;
+}
+
+void AndroidMediaRecorder::setCamera(AndroidCamera *camera)
+{
+ QJniObject cam = camera->getCameraObject();
+ m_mediaRecorder.callMethod<void>("setCamera", "(Landroid/hardware/Camera;)V", cam.object());
+}
+
+void AndroidMediaRecorder::setVideoEncoder(VideoEncoder encoder)
+{
+ m_mediaRecorder.callMethod<void>("setVideoEncoder", "(I)V", int(encoder));
+}
+
+void AndroidMediaRecorder::setVideoEncodingBitRate(int bitRate)
+{
+ m_mediaRecorder.callMethod<void>("setVideoEncodingBitRate", "(I)V", bitRate);
+}
+
+void AndroidMediaRecorder::setVideoFrameRate(int rate)
+{
+ m_mediaRecorder.callMethod<void>("setVideoFrameRate", "(I)V", rate);
+}
+
+void AndroidMediaRecorder::setVideoSize(const QSize &size)
+{
+ m_mediaRecorder.callMethod<void>("setVideoSize", "(II)V", size.width(), size.height());
+}
+
+void AndroidMediaRecorder::setVideoSource(VideoSource source)
+{
+ QJniEnvironment env;
+
+ auto methodId = env->GetMethodID(m_mediaRecorder.objectClass(), "setVideoSource", "(I)V");
+ env->CallVoidMethod(m_mediaRecorder.object(), methodId, source);
+
+ if (!env.checkAndClearExceptions())
+ m_isVideoSourceSet = true;
+}
+
+void AndroidMediaRecorder::setOrientationHint(int degrees)
+{
+ m_mediaRecorder.callMethod<void>("setOrientationHint", "(I)V", degrees);
+}
+
+void AndroidMediaRecorder::setOutputFormat(OutputFormat format)
+{
+ QJniEnvironment env;
+ auto methodId = env->GetMethodID(m_mediaRecorder.objectClass(), "setOutputFormat", "(I)V");
+ env->CallVoidMethod(m_mediaRecorder.object(), methodId, format);
+ // setAudioSource cannot be set after outputFormat is set.
+ if (!env.checkAndClearExceptions())
+ m_isAudioSourceSet = true;
+}
+
+void AndroidMediaRecorder::setOutputFile(const QString &path)
+{
+ if (QUrl(path).scheme() == QLatin1String("content")) {
+ const QJniObject fileDescriptor = QJniObject::callStaticObjectMethod(
+ "org/qtproject/qt/android/QtNative",
+ "openFdObjectForContentUrl",
+ "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)Ljava/io/FileDescriptor;",
+ QNativeInterface::QAndroidApplication::context().object(),
+ QJniObject::fromString(path).object(),
+ QJniObject::fromString(QLatin1String("rw")).object());
+
+ m_mediaRecorder.callMethod<void>("setOutputFile",
+ "(Ljava/io/FileDescriptor;)V",
+ fileDescriptor.object());
+ } else {
+ m_mediaRecorder.callMethod<void>("setOutputFile",
+ "(Ljava/lang/String;)V",
+ QJniObject::fromString(path).object());
+ }
+}
+
+void AndroidMediaRecorder::setSurfaceTexture(AndroidSurfaceTexture *texture)
+{
+ m_mediaRecorder.callMethod<void>("setPreviewDisplay",
+ "(Landroid/view/Surface;)V",
+ texture->surface());
+}
+
+void AndroidMediaRecorder::setSurfaceHolder(AndroidSurfaceHolder *holder)
+{
+ QJniObject surfaceHolder(holder->surfaceHolder());
+ QJniObject surface = surfaceHolder.callObjectMethod("getSurface",
+ "()Landroid/view/Surface;");
+ if (!surface.isValid())
+ return;
+
+ m_mediaRecorder.callMethod<void>("setPreviewDisplay",
+ "(Landroid/view/Surface;)V",
+ surface.object());
+}
+
+bool AndroidMediaRecorder::registerNativeMethods()
+{
+ static const JNINativeMethod methods[] = {
+ {"notifyError", "(JII)V", (void *)notifyError},
+ {"notifyInfo", "(JII)V", (void *)notifyInfo}
+ };
+
+ const int size = std::size(methods);
+ return QJniEnvironment().registerNativeMethods(QtMediaRecorderListenerClassName, methods, size);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_androidmediarecorder_p.cpp"
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidmediarecorder_p.h b/src/plugins/multimedia/android/wrappers/jni/androidmediarecorder_p.h
new file mode 100644
index 000000000..ffdbcc149
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidmediarecorder_p.h
@@ -0,0 +1,161 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef ANDROIDMEDIARECORDER_H
+#define ANDROIDMEDIARECORDER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qobject.h>
+#include <QtCore/qjniobject.h>
+#include <qsize.h>
+
+QT_BEGIN_NAMESPACE
+
+class AndroidCamera;
+class AndroidSurfaceTexture;
+class AndroidSurfaceHolder;
+
+class AndroidCamcorderProfile
+{
+public:
+ enum Quality { // Needs to match CamcorderProfile
+ QUALITY_LOW,
+ QUALITY_HIGH,
+ QUALITY_QCIF,
+ QUALITY_CIF,
+ QUALITY_480P,
+ QUALITY_720P,
+ QUALITY_1080P,
+ QUALITY_QVGA
+ };
+
+ enum Field {
+ audioBitRate,
+ audioChannels,
+ audioCodec,
+ audioSampleRate,
+ duration,
+ fileFormat,
+ quality,
+ videoBitRate,
+ videoCodec,
+ videoFrameHeight,
+ videoFrameRate,
+ videoFrameWidth
+ };
+
+ static bool hasProfile(jint cameraId, Quality quality);
+ static AndroidCamcorderProfile get(jint cameraId, Quality quality);
+ int getValue(Field field) const;
+
+private:
+ AndroidCamcorderProfile(const QJniObject &camcorderProfile);
+ QJniObject m_camcorderProfile;
+};
+
+class AndroidMediaRecorder : public QObject
+{
+ Q_OBJECT
+public:
+ enum AudioEncoder {
+ DefaultAudioEncoder = 0,
+ AMR_NB_Encoder = 1,
+ AMR_WB_Encoder = 2,
+ AAC = 3,
+ OPUS = 7,
+ VORBIS = 6
+ };
+
+ enum AudioSource {
+ DefaultAudioSource = 0,
+ Mic = 1,
+ VoiceUplink = 2,
+ VoiceDownlink = 3,
+ VoiceCall = 4,
+ Camcorder = 5,
+ VoiceRecognition = 6
+ };
+
+ enum VideoEncoder {
+ DefaultVideoEncoder = 0,
+ H263 = 1,
+ H264 = 2,
+ MPEG_4_SP = 3,
+ HEVC = 5
+ };
+
+ enum VideoSource {
+ DefaultVideoSource = 0,
+ Camera = 1
+ };
+
+ enum OutputFormat {
+ DefaultOutputFormat = 0,
+ THREE_GPP = 1,
+ MPEG_4 = 2,
+ AMR_NB_Format = 3,
+ AMR_WB_Format = 4,
+ AAC_ADTS = 6,
+ OGG = 11,
+ WEBM = 9
+ };
+
+ AndroidMediaRecorder();
+ ~AndroidMediaRecorder();
+
+ void release();
+ bool prepare();
+ void reset();
+
+ bool start();
+ void stop();
+
+ void setAudioChannels(int numChannels);
+ void setAudioEncoder(AudioEncoder encoder);
+ void setAudioEncodingBitRate(int bitRate);
+ void setAudioSamplingRate(int samplingRate);
+ void setAudioSource(AudioSource source);
+ bool isAudioSourceSet() const;
+ bool setAudioInput(const QByteArray &id);
+
+ void setCamera(AndroidCamera *camera);
+ void setVideoEncoder(VideoEncoder encoder);
+ void setVideoEncodingBitRate(int bitRate);
+ void setVideoFrameRate(int rate);
+ void setVideoSize(const QSize &size);
+ void setVideoSource(VideoSource source);
+
+ void setOrientationHint(int degrees);
+
+ void setOutputFormat(OutputFormat format);
+ void setOutputFile(const QString &path);
+
+ void setSurfaceTexture(AndroidSurfaceTexture *texture);
+ void setSurfaceHolder(AndroidSurfaceHolder *holder);
+
+ static bool registerNativeMethods();
+
+Q_SIGNALS:
+ void error(int what, int extra);
+ void info(int what, int extra);
+
+private:
+ jlong m_id;
+ QJniObject m_mediaRecorder;
+ bool m_isAudioSourceSet = false;
+ bool m_isVideoSourceSet = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // ANDROIDMEDIARECORDER_H
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidmultimediautils.cpp b/src/plugins/multimedia/android/wrappers/jni/androidmultimediautils.cpp
new file mode 100644
index 000000000..9606bd6bb
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidmultimediautils.cpp
@@ -0,0 +1,43 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "androidmultimediautils_p.h"
+
+#include <QtCore/qjniobject.h>
+
+QT_BEGIN_NAMESPACE
+
+
+void AndroidMultimediaUtils::enableOrientationListener(bool enable)
+{
+ QJniObject::callStaticMethod<void>("org/qtproject/qt/android/multimedia/QtMultimediaUtils",
+ "enableOrientationListener",
+ "(Z)V",
+ enable);
+}
+
+int AndroidMultimediaUtils::getDeviceOrientation()
+{
+ return QJniObject::callStaticMethod<jint>("org/qtproject/qt/android/multimedia/QtMultimediaUtils",
+ "getDeviceOrientation");
+}
+
+QString AndroidMultimediaUtils::getDefaultMediaDirectory(MediaType type)
+{
+ QJniObject path = QJniObject::callStaticObjectMethod(
+ "org/qtproject/qt/android/multimedia/QtMultimediaUtils",
+ "getDefaultMediaDirectory",
+ "(I)Ljava/lang/String;",
+ jint(type));
+ return path.toString();
+}
+
+void AndroidMultimediaUtils::registerMediaFile(const QString &file)
+{
+ QJniObject::callStaticMethod<void>("org/qtproject/qt/android/multimedia/QtMultimediaUtils",
+ "registerMediaFile",
+ "(Ljava/lang/String;)V",
+ QJniObject::fromString(file).object());
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidmultimediautils_p.h b/src/plugins/multimedia/android/wrappers/jni/androidmultimediautils_p.h
new file mode 100644
index 000000000..ee72c3c61
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidmultimediautils_p.h
@@ -0,0 +1,40 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef ANDROIDMULTIMEDIAUTILS_H
+#define ANDROIDMULTIMEDIAUTILS_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qobject.h>
+
+QT_BEGIN_NAMESPACE
+
+class AndroidMultimediaUtils
+{
+public:
+ enum MediaType {
+ Music = 0,
+ Movies = 1,
+ DCIM = 2,
+ Sounds = 3
+ };
+
+ static void enableOrientationListener(bool enable);
+ static int getDeviceOrientation();
+ static QString getDefaultMediaDirectory(MediaType type);
+ static void registerMediaFile(const QString &file);
+};
+
+QT_END_NAMESPACE
+
+#endif // ANDROIDMULTIMEDIAUTILS_H
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidsurfacetexture.cpp b/src/plugins/multimedia/android/wrappers/jni/androidsurfacetexture.cpp
new file mode 100644
index 000000000..c5860b265
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidsurfacetexture.cpp
@@ -0,0 +1,152 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "androidsurfacetexture_p.h"
+#include <QtCore/qmutex.h>
+#include <QtCore/qcoreapplication.h>
+
+QT_BEGIN_NAMESPACE
+
+static const char QtSurfaceTextureListenerClassName[] = "org/qtproject/qt/android/multimedia/QtSurfaceTextureListener";
+typedef QList<jlong> SurfaceTextures;
+Q_GLOBAL_STATIC(SurfaceTextures, g_surfaceTextures);
+Q_GLOBAL_STATIC(QMutex, g_textureMutex);
+
+static QAtomicInteger<quint64> indexCounter = 0u;
+
+// native method for QtSurfaceTexture.java
+static void notifyFrameAvailable(JNIEnv* , jobject, jlong id)
+{
+ const QMutexLocker lock(g_textureMutex());
+ const int idx = g_surfaceTextures->indexOf(id);
+ if (idx == -1)
+ return;
+
+ AndroidSurfaceTexture *obj = reinterpret_cast<AndroidSurfaceTexture *>(g_surfaceTextures->at(idx));
+ if (obj)
+ Q_EMIT obj->frameAvailable();
+}
+
+AndroidSurfaceTexture::AndroidSurfaceTexture(quint32 texName)
+ : QObject()
+ , m_index(indexCounter.fetchAndAddRelaxed(1))
+{
+ Q_STATIC_ASSERT(sizeof (jlong) >= sizeof (void *));
+ m_surfaceTexture = QJniObject("android/graphics/SurfaceTexture", "(I)V", jint(texName));
+
+ if (!m_surfaceTexture.isValid())
+ return;
+
+ const QMutexLocker lock(g_textureMutex());
+ g_surfaceTextures->append(jlong(this));
+ QJniObject listener(QtSurfaceTextureListenerClassName, "(J)V", jlong(this));
+ setOnFrameAvailableListener(listener);
+}
+
+AndroidSurfaceTexture::~AndroidSurfaceTexture()
+{
+ if (m_surface.isValid())
+ m_surface.callMethod<void>("release");
+
+ if (m_surfaceTexture.isValid()) {
+ release();
+ const QMutexLocker lock(g_textureMutex());
+ const int idx = g_surfaceTextures->indexOf(jlong(this));
+ if (idx != -1)
+ g_surfaceTextures->remove(idx);
+ }
+}
+
+QMatrix4x4 AndroidSurfaceTexture::getTransformMatrix()
+{
+ QMatrix4x4 matrix;
+ if (!m_surfaceTexture.isValid())
+ return matrix;
+
+ QJniEnvironment env;
+ jfloatArray array = env->NewFloatArray(16);
+ m_surfaceTexture.callMethod<void>("getTransformMatrix", "([F)V", array);
+ env->GetFloatArrayRegion(array, 0, 16, matrix.data());
+ env->DeleteLocalRef(array);
+
+ return matrix;
+}
+
+void AndroidSurfaceTexture::release()
+{
+ m_surfaceTexture.callMethod<void>("release");
+}
+
+void AndroidSurfaceTexture::updateTexImage()
+{
+ if (!m_surfaceTexture.isValid())
+ return;
+
+ m_surfaceTexture.callMethod<void>("updateTexImage");
+}
+
+jobject AndroidSurfaceTexture::surfaceTexture()
+{
+ return m_surfaceTexture.object();
+}
+
+jobject AndroidSurfaceTexture::surface()
+{
+ if (!m_surface.isValid()) {
+ m_surface = QJniObject("android/view/Surface",
+ "(Landroid/graphics/SurfaceTexture;)V",
+ m_surfaceTexture.object());
+ }
+
+ return m_surface.object();
+}
+
+jobject AndroidSurfaceTexture::surfaceHolder()
+{
+ if (!m_surfaceHolder.isValid()) {
+ m_surfaceHolder = QJniObject("org/qtproject/qt/android/multimedia/QtSurfaceTextureHolder",
+ "(Landroid/view/Surface;)V",
+ surface());
+ }
+
+ return m_surfaceHolder.object();
+}
+
+void AndroidSurfaceTexture::attachToGLContext(quint32 texName)
+{
+ if (!m_surfaceTexture.isValid())
+ return;
+
+ m_surfaceTexture.callMethod<void>("attachToGLContext", "(I)V", texName);
+}
+
+void AndroidSurfaceTexture::detachFromGLContext()
+{
+ if (!m_surfaceTexture.isValid())
+ return;
+
+ m_surfaceTexture.callMethod<void>("detachFromGLContext");
+}
+
+bool AndroidSurfaceTexture::registerNativeMethods()
+{
+ static const JNINativeMethod methods[] = {
+ {"notifyFrameAvailable", "(J)V", (void *)notifyFrameAvailable}
+ };
+ const int size = std::size(methods);
+ if (QJniEnvironment().registerNativeMethods(QtSurfaceTextureListenerClassName, methods, size))
+ return false;
+
+ return true;
+}
+
+void AndroidSurfaceTexture::setOnFrameAvailableListener(const QJniObject &listener)
+{
+ m_surfaceTexture.callMethod<void>("setOnFrameAvailableListener",
+ "(Landroid/graphics/SurfaceTexture$OnFrameAvailableListener;)V",
+ listener.object());
+}
+
+QT_END_NAMESPACE
+
+#include "moc_androidsurfacetexture_p.cpp"
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidsurfacetexture_p.h b/src/plugins/multimedia/android/wrappers/jni/androidsurfacetexture_p.h
new file mode 100644
index 000000000..24581ca8d
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidsurfacetexture_p.h
@@ -0,0 +1,61 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef ANDROIDSURFACETEXTURE_H
+#define ANDROIDSURFACETEXTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qobject.h>
+#include <QtCore/qjniobject.h>
+
+#include <QMatrix4x4>
+
+QT_BEGIN_NAMESPACE
+
+class AndroidSurfaceTexture : public QObject
+{
+ Q_OBJECT
+public:
+ explicit AndroidSurfaceTexture(quint32 texName);
+ ~AndroidSurfaceTexture();
+
+ jobject surfaceTexture();
+ jobject surface();
+ jobject surfaceHolder();
+ inline bool isValid() const { return m_surfaceTexture.isValid(); }
+
+ QMatrix4x4 getTransformMatrix();
+ void release(); // API level 14
+ void updateTexImage();
+
+ void attachToGLContext(quint32 texName); // API level 16
+ void detachFromGLContext(); // API level 16
+
+ static bool registerNativeMethods();
+
+ quint64 index() const { return m_index; }
+Q_SIGNALS:
+ void frameAvailable();
+
+private:
+ void setOnFrameAvailableListener(const QJniObject &listener);
+
+ QJniObject m_surfaceTexture;
+ QJniObject m_surface;
+ QJniObject m_surfaceHolder;
+ const quint64 m_index = 0;
+};
+
+QT_END_NAMESPACE
+
+#endif // ANDROIDSURFACETEXTURE_H
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidsurfaceview.cpp b/src/plugins/multimedia/android/wrappers/jni/androidsurfaceview.cpp
new file mode 100644
index 000000000..dae9516c3
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidsurfaceview.cpp
@@ -0,0 +1,152 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "androidsurfaceview_p.h"
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qmutex.h>
+#include <QtGui/qwindow.h>
+
+QT_BEGIN_NAMESPACE
+
+static const char QtSurfaceHolderCallbackClassName[] = "org/qtproject/qt/android/multimedia/QtSurfaceHolderCallback";
+typedef QList<AndroidSurfaceHolder *> SurfaceHolders;
+Q_GLOBAL_STATIC(SurfaceHolders, surfaceHolders)
+Q_GLOBAL_STATIC(QMutex, shLock)
+
+AndroidSurfaceHolder::AndroidSurfaceHolder(QJniObject object)
+ : m_surfaceHolder(object)
+ , m_surfaceCreated(false)
+{
+ if (!m_surfaceHolder.isValid())
+ return;
+
+ {
+ QMutexLocker locker(shLock());
+ surfaceHolders->append(this);
+ }
+
+ QJniObject callback(QtSurfaceHolderCallbackClassName, "(J)V", reinterpret_cast<jlong>(this));
+ m_surfaceHolder.callMethod<void>("addCallback",
+ "(Landroid/view/SurfaceHolder$Callback;)V",
+ callback.object());
+}
+
+AndroidSurfaceHolder::~AndroidSurfaceHolder()
+{
+ QMutexLocker locker(shLock());
+ const int i = surfaceHolders->indexOf(this);
+ if (Q_UNLIKELY(i == -1))
+ return;
+
+ surfaceHolders->remove(i);
+}
+
+jobject AndroidSurfaceHolder::surfaceHolder() const
+{
+ return m_surfaceHolder.object();
+}
+
+bool AndroidSurfaceHolder::isSurfaceCreated() const
+{
+ QMutexLocker locker(shLock());
+ return m_surfaceCreated;
+}
+
+void AndroidSurfaceHolder::handleSurfaceCreated(JNIEnv*, jobject, jlong id)
+{
+ QMutexLocker locker(shLock());
+ const int i = surfaceHolders->indexOf(reinterpret_cast<AndroidSurfaceHolder *>(id));
+ if (Q_UNLIKELY(i == -1))
+ return;
+
+ (*surfaceHolders)[i]->m_surfaceCreated = true;
+ Q_EMIT (*surfaceHolders)[i]->surfaceCreated();
+}
+
+void AndroidSurfaceHolder::handleSurfaceDestroyed(JNIEnv*, jobject, jlong id)
+{
+ QMutexLocker locker(shLock());
+ const int i = surfaceHolders->indexOf(reinterpret_cast<AndroidSurfaceHolder *>(id));
+ if (Q_UNLIKELY(i == -1))
+ return;
+
+ (*surfaceHolders)[i]->m_surfaceCreated = false;
+}
+
+bool AndroidSurfaceHolder::registerNativeMethods()
+{
+ static const JNINativeMethod methods[] = {
+ {"notifySurfaceCreated", "(J)V", (void *)AndroidSurfaceHolder::handleSurfaceCreated},
+ {"notifySurfaceDestroyed", "(J)V", (void *)AndroidSurfaceHolder::handleSurfaceDestroyed}
+ };
+
+ const int size = std::size(methods);
+ return QJniEnvironment().registerNativeMethods(QtSurfaceHolderCallbackClassName, methods, size);
+}
+
+AndroidSurfaceView::AndroidSurfaceView()
+ : m_window(0)
+ , m_surfaceHolder(0)
+ , m_pendingVisible(-1)
+{
+ QNativeInterface::QAndroidApplication::runOnAndroidMainThread([this] {
+ m_surfaceView = QJniObject("android/view/SurfaceView",
+ "(Landroid/content/Context;)V",
+ QNativeInterface::QAndroidApplication::context().object());
+ }).waitForFinished();
+
+ Q_ASSERT(m_surfaceView.isValid());
+
+ QJniObject holder = m_surfaceView.callObjectMethod("getHolder",
+ "()Landroid/view/SurfaceHolder;");
+ if (!holder.isValid()) {
+ m_surfaceView = QJniObject();
+ } else {
+ m_surfaceHolder = new AndroidSurfaceHolder(holder);
+ connect(m_surfaceHolder, &AndroidSurfaceHolder::surfaceCreated,
+ this, &AndroidSurfaceView::surfaceCreated);
+ { // Lock now to avoid a race with handleSurfaceCreated()
+ QMutexLocker locker(shLock());
+ m_window = QWindow::fromWinId(WId(m_surfaceView.object()));
+
+ if (m_pendingVisible != -1)
+ m_window->setVisible(m_pendingVisible);
+ if (m_pendingGeometry.isValid())
+ m_window->setGeometry(m_pendingGeometry);
+ }
+ }
+}
+
+AndroidSurfaceView::~AndroidSurfaceView()
+{
+ delete m_surfaceHolder;
+ delete m_window;
+}
+
+AndroidSurfaceHolder *AndroidSurfaceView::holder() const
+{
+ return m_surfaceHolder;
+}
+
+void AndroidSurfaceView::setVisible(bool v)
+{
+ if (m_window)
+ m_window->setVisible(v);
+ else
+ m_pendingVisible = int(v);
+}
+
+void AndroidSurfaceView::setGeometry(int x, int y, int width, int height)
+{
+ if (m_window)
+ m_window->setGeometry(x, y, width, height);
+ else
+ m_pendingGeometry = QRect(x, y, width, height);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_androidsurfaceview_p.cpp"
diff --git a/src/plugins/multimedia/android/wrappers/jni/androidsurfaceview_p.h b/src/plugins/multimedia/android/wrappers/jni/androidsurfaceview_p.h
new file mode 100644
index 000000000..e6be60ef1
--- /dev/null
+++ b/src/plugins/multimedia/android/wrappers/jni/androidsurfaceview_p.h
@@ -0,0 +1,78 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef ANDROIDSURFACEVIEW_H
+#define ANDROIDSURFACEVIEW_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qjniobject.h>
+#include <qrect.h>
+#include <QtCore/qrunnable.h>
+#include <QtCore/qobject.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWindow;
+
+class AndroidSurfaceHolder : public QObject
+{
+ Q_OBJECT
+public:
+ ~AndroidSurfaceHolder();
+
+ jobject surfaceHolder() const;
+ bool isSurfaceCreated() const;
+
+ static bool registerNativeMethods();
+
+Q_SIGNALS:
+ void surfaceCreated();
+
+private:
+ AndroidSurfaceHolder(QJniObject object);
+
+ static void handleSurfaceCreated(JNIEnv*, jobject, jlong id);
+ static void handleSurfaceDestroyed(JNIEnv*, jobject, jlong id);
+
+ QJniObject m_surfaceHolder;
+ bool m_surfaceCreated;
+
+ friend class AndroidSurfaceView;
+};
+
+class AndroidSurfaceView : public QObject
+{
+ Q_OBJECT
+public:
+ AndroidSurfaceView();
+ ~AndroidSurfaceView();
+
+ AndroidSurfaceHolder *holder() const;
+
+ void setVisible(bool v);
+ void setGeometry(int x, int y, int width, int height);
+
+Q_SIGNALS:
+ void surfaceCreated();
+
+private:
+ QJniObject m_surfaceView;
+ QWindow *m_window;
+ AndroidSurfaceHolder *m_surfaceHolder;
+ int m_pendingVisible;
+ QRect m_pendingGeometry;
+};
+
+QT_END_NAMESPACE
+
+#endif // ANDROIDSURFACEVIEW_H
diff --git a/src/plugins/multimedia/darwin/CMakeLists.txt b/src/plugins/multimedia/darwin/CMakeLists.txt
new file mode 100644
index 000000000..0bbc054eb
--- /dev/null
+++ b/src/plugins/multimedia/darwin/CMakeLists.txt
@@ -0,0 +1,70 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+
+qt_internal_find_apple_system_framework(FWCoreMedia CoreMedia) # special case
+qt_internal_find_apple_system_framework(FWCoreAudio CoreAudio) # special case
+qt_internal_find_apple_system_framework(FWAudioUnit AudioUnit) # special case
+qt_internal_find_apple_system_framework(FWVideoToolbox VideoToolbox) # special case
+qt_internal_find_apple_system_framework(FWAVFoundation AVFoundation) # special case
+
+qt_internal_add_plugin(QDarwinMediaPlugin
+ OUTPUT_NAME darwinmediaplugin
+ PLUGIN_TYPE multimedia
+ SOURCES
+ avfaudiodecoder.mm avfaudiodecoder_p.h
+ mediaplayer/avfdisplaylink.mm mediaplayer/avfdisplaylink_p.h
+ mediaplayer/avfmediaplayer.mm mediaplayer/avfmediaplayer_p.h
+ common/avfmetadata.mm common/avfmetadata_p.h
+ mediaplayer/avfvideorenderercontrol.mm mediaplayer/avfvideorenderercontrol_p.h
+ avfvideosink.mm avfvideosink_p.h
+ avfvideobuffer.mm avfvideobuffer_p.h
+ qavfhelpers.mm qavfhelpers_p.h
+ qdarwinformatsinfo.mm qdarwinformatsinfo_p.h
+ qdarwinintegration.mm qdarwinintegration_p.h
+ INCLUDE_DIRECTORIES
+ audio
+ camera
+ common
+ mediaplayer
+ LIBRARIES
+ Qt::MultimediaPrivate
+ Qt::CorePrivate
+ ${FWCoreMedia}
+ ${FWCoreAudio}
+ ${FWCoreVideo}
+ ${FWFoundation}
+ ${FWMetal}
+ ${FWQuartzCore}
+ ${FWAudioToolbox}
+ AVFoundation::AVFoundation
+)
+
+qt_internal_extend_target(QDarwinMediaPlugin CONDITION NOT TVOS
+ SOURCES
+ camera/qavfcamerabase.mm camera/qavfcamerabase_p.h
+ camera/avfcamera.mm camera/avfcamera_p.h
+ camera/avfcameradebug_p.h
+ camera/avfaudiopreviewdelegate.mm camera/avfaudiopreviewdelegate_p.h
+ camera/avfcamerarenderer.mm camera/avfcamerarenderer_p.h
+ camera/avfcameraservice.mm camera/avfcameraservice_p.h
+ camera/avfcamerasession.mm camera/avfcamerasession_p.h
+ camera/avfcamerautility.mm camera/avfcamerautility_p.h
+ camera/avfimagecapture.mm camera/avfimagecapture_p.h
+ camera/avfmediaassetwriter.mm camera/avfmediaassetwriter_p.h
+ camera/avfmediaencoder.mm camera/avfmediaencoder_p.h
+)
+
+qt_internal_extend_target(QDarwinMediaPlugin CONDITION MACOS
+ LIBRARIES
+ ${FWAppKit}
+ ${FWAudioUnit}
+ ${FWVideoToolbox}
+ ${FWApplicationServices}
+)
+
+qt_internal_extend_target(QDarwinMediaPlugin CONDITION IOS
+ LIBRARIES
+ ${FWCoreGraphics}
+ ${FWCoreVideo}
+)
diff --git a/src/plugins/multimedia/darwin/avfaudiodecoder.mm b/src/plugins/multimedia/darwin/avfaudiodecoder.mm
new file mode 100644
index 000000000..3191b7db0
--- /dev/null
+++ b/src/plugins/multimedia/darwin/avfaudiodecoder.mm
@@ -0,0 +1,544 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfaudiodecoder_p.h"
+
+#include <QtCore/qmutex.h>
+#include <QtCore/qiodevice.h>
+#include <QMimeDatabase>
+#include <QThread>
+#include "private/qcoreaudioutils_p.h"
+#include <QtCore/qloggingcategory.h>
+
+#include <AVFoundation/AVFoundation.h>
+
+QT_USE_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcAVFAudioDecoder, "qt.multimedia.darwin.AVFAudioDecoder")
+constexpr static int MAX_BUFFERS_IN_QUEUE = 5;
+
+QAudioBuffer handleNextSampleBuffer(CMSampleBufferRef sampleBuffer)
+{
+ if (!sampleBuffer)
+ return {};
+
+ // Check format
+ CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
+ if (!formatDescription)
+ return {};
+ const AudioStreamBasicDescription* const asbd = CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription);
+ QAudioFormat qtFormat = CoreAudioUtils::toQAudioFormat(*asbd);
+ if (qtFormat.sampleFormat() == QAudioFormat::Unknown && asbd->mBitsPerChannel == 8)
+ qtFormat.setSampleFormat(QAudioFormat::UInt8);
+ if (!qtFormat.isValid())
+ return {};
+
+ // Get the required size to allocate to audioBufferList
+ size_t audioBufferListSize = 0;
+ OSStatus err = CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer,
+ &audioBufferListSize,
+ NULL,
+ 0,
+ NULL,
+ NULL,
+ kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment,
+ NULL);
+ if (err != noErr)
+ return {};
+
+ CMBlockBufferRef blockBuffer = NULL;
+ AudioBufferList* audioBufferList = (AudioBufferList*) malloc(audioBufferListSize);
+ // This ensures the buffers placed in audioBufferList are contiguous
+ err = CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer,
+ NULL,
+ audioBufferList,
+ audioBufferListSize,
+ NULL,
+ NULL,
+ kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment,
+ &blockBuffer);
+ if (err != noErr) {
+ free(audioBufferList);
+ return {};
+ }
+
+ QByteArray abuf;
+ for (UInt32 i = 0; i < audioBufferList->mNumberBuffers; i++)
+ {
+ AudioBuffer audioBuffer = audioBufferList->mBuffers[i];
+ abuf.push_back(QByteArray((const char*)audioBuffer.mData, audioBuffer.mDataByteSize));
+ }
+
+ free(audioBufferList);
+ CFRelease(blockBuffer);
+
+ CMTime sampleStartTime = (CMSampleBufferGetPresentationTimeStamp(sampleBuffer));
+ float sampleStartTimeSecs = CMTimeGetSeconds(sampleStartTime);
+
+ return QAudioBuffer(abuf, qtFormat, qint64(sampleStartTimeSecs * 1000000));
+}
+
+@interface AVFResourceReaderDelegate : NSObject <AVAssetResourceLoaderDelegate> {
+ AVFAudioDecoder *m_decoder;
+ QMutex m_mutex;
+}
+
+- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader
+ shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest;
+
+@end
+
+@implementation AVFResourceReaderDelegate
+
+- (id)initWithDecoder:(AVFAudioDecoder *)decoder
+{
+ if (!(self = [super init]))
+ return nil;
+
+ m_decoder = decoder;
+
+ return self;
+}
+
+-(BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader
+ shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
+{
+ Q_UNUSED(resourceLoader);
+
+ if (![loadingRequest.request.URL.scheme isEqualToString:@"iodevice"])
+ return NO;
+
+ QMutexLocker locker(&m_mutex);
+
+ QIODevice *device = m_decoder->sourceDevice();
+ if (!device)
+ return NO;
+
+ device->seek(loadingRequest.dataRequest.requestedOffset);
+ if (loadingRequest.contentInformationRequest) {
+ loadingRequest.contentInformationRequest.contentLength = device->size();
+ loadingRequest.contentInformationRequest.byteRangeAccessSupported = YES;
+ }
+
+ if (loadingRequest.dataRequest) {
+ NSInteger requestedLength = loadingRequest.dataRequest.requestedLength;
+ int maxBytes = qMin(32 * 1024, int(requestedLength));
+ char buffer[maxBytes];
+ NSInteger submitted = 0;
+ while (submitted < requestedLength) {
+ qint64 len = device->read(buffer, maxBytes);
+ if (len < 1)
+ break;
+
+ [loadingRequest.dataRequest respondWithData:[NSData dataWithBytes:buffer length:len]];
+ submitted += len;
+ }
+
+ // Finish loading even if not all bytes submitted.
+ [loadingRequest finishLoading];
+ }
+
+ return YES;
+}
+
+@end
+
+namespace {
+
+NSDictionary *av_audio_settings_for_format(const QAudioFormat &format)
+{
+ float sampleRate = format.sampleRate();
+ int nChannels = format.channelCount();
+ int sampleSize = format.bytesPerSample() * 8;
+ BOOL isFloat = format.sampleFormat() == QAudioFormat::Float;
+
+ NSDictionary *audioSettings = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
+ [NSNumber numberWithFloat:sampleRate], AVSampleRateKey,
+ [NSNumber numberWithInt:nChannels], AVNumberOfChannelsKey,
+ [NSNumber numberWithInt:sampleSize], AVLinearPCMBitDepthKey,
+ [NSNumber numberWithBool:isFloat], AVLinearPCMIsFloatKey,
+ [NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
+ [NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey,
+ nil];
+
+ return audioSettings;
+}
+
+QAudioFormat qt_format_for_audio_track(AVAssetTrack *track)
+{
+ QAudioFormat format;
+ CMFormatDescriptionRef desc = (__bridge CMFormatDescriptionRef)track.formatDescriptions[0];
+ const AudioStreamBasicDescription* const asbd =
+ CMAudioFormatDescriptionGetStreamBasicDescription(desc);
+ format = CoreAudioUtils::toQAudioFormat(*asbd);
+ // AudioStreamBasicDescription's mBitsPerChannel is 0 for compressed formats
+ // In this case set default Int16 sample format
+ if (asbd->mBitsPerChannel == 0)
+ format.setSampleFormat(QAudioFormat::Int16);
+ return format;
+}
+
+}
+
+struct AVFAudioDecoder::DecodingContext
+{
+ AVAssetReader *m_reader = nullptr;
+ AVAssetReaderTrackOutput *m_readerOutput = nullptr;
+
+ ~DecodingContext()
+ {
+ if (m_reader) {
+ [m_reader cancelReading];
+ [m_reader release];
+ }
+
+ [m_readerOutput release];
+ }
+};
+
+AVFAudioDecoder::AVFAudioDecoder(QAudioDecoder *parent)
+ : QPlatformAudioDecoder(parent)
+{
+ m_readingQueue = dispatch_queue_create("reader_queue", DISPATCH_QUEUE_SERIAL);
+ m_decodingQueue = dispatch_queue_create("decoder_queue", DISPATCH_QUEUE_SERIAL);
+
+ m_readerDelegate = [[AVFResourceReaderDelegate alloc] initWithDecoder:this];
+}
+
+AVFAudioDecoder::~AVFAudioDecoder()
+{
+ stop();
+
+ [m_readerDelegate release];
+ [m_asset release];
+
+ dispatch_release(m_readingQueue);
+ dispatch_release(m_decodingQueue);
+}
+
+QUrl AVFAudioDecoder::source() const
+{
+ return m_source;
+}
+
+void AVFAudioDecoder::setSource(const QUrl &fileName)
+{
+ if (!m_device && m_source == fileName)
+ return;
+
+ stop();
+ m_device = nullptr;
+ [m_asset release];
+ m_asset = nil;
+
+ m_source = fileName;
+
+ if (!m_source.isEmpty()) {
+ NSURL *nsURL = m_source.toNSURL();
+ m_asset = [[AVURLAsset alloc] initWithURL:nsURL options:nil];
+ }
+
+ sourceChanged();
+}
+
+QIODevice *AVFAudioDecoder::sourceDevice() const
+{
+ return m_device;
+}
+
+void AVFAudioDecoder::setSourceDevice(QIODevice *device)
+{
+ if (m_device == device && m_source.isEmpty())
+ return;
+
+ stop();
+ m_source.clear();
+ [m_asset release];
+ m_asset = nil;
+
+ m_device = device;
+
+ if (m_device) {
+ const QString ext = QMimeDatabase().mimeTypeForData(m_device).preferredSuffix();
+ const QString url = "iodevice:///iodevice." + ext;
+ NSString *urlString = url.toNSString();
+ NSURL *nsURL = [NSURL URLWithString:urlString];
+
+ m_asset = [[AVURLAsset alloc] initWithURL:nsURL options:nil];
+
+ // use decoding queue instead of reading queue in order to fix random stucks.
+ // Anyway, decoding queue is empty in the moment.
+ [m_asset.resourceLoader setDelegate:m_readerDelegate queue:m_decodingQueue];
+ }
+
+ sourceChanged();
+}
+
+void AVFAudioDecoder::start()
+{
+ if (m_decodingContext) {
+ qCDebug(qLcAVFAudioDecoder()) << "AVFAudioDecoder has been already started";
+ return;
+ }
+
+ positionChanged(-1);
+
+ if (m_device && (!m_device->isOpen() || !m_device->isReadable())) {
+ processInvalidMedia(QAudioDecoder::ResourceError, tr("Unable to read from specified device"));
+ return;
+ }
+
+ m_decodingContext = std::make_shared<DecodingContext>();
+ std::weak_ptr<DecodingContext> weakContext(m_decodingContext);
+
+ auto handleLoadingResult = [=]() {
+ NSError *error = nil;
+ AVKeyValueStatus status = [m_asset statusOfValueForKey:@"tracks" error:&error];
+
+ if (status == AVKeyValueStatusFailed) {
+ if (error.domain == NSURLErrorDomain)
+ processInvalidMedia(QAudioDecoder::ResourceError,
+ QString::fromNSString(error.localizedDescription));
+ else
+ processInvalidMedia(QAudioDecoder::FormatError,
+ tr("Could not load media source's tracks"));
+ } else if (status != AVKeyValueStatusLoaded) {
+ qWarning() << "Unexpected AVKeyValueStatus:" << status;
+ stop();
+ }
+ else {
+ initAssetReader();
+ }
+ };
+
+ [m_asset loadValuesAsynchronouslyForKeys:@[ @"tracks" ]
+ completionHandler:[=]() {
+ invokeWithDecodingContext(weakContext, handleLoadingResult);
+ }];
+}
+
+void AVFAudioDecoder::decBuffersCounter(uint val)
+{
+ if (val) {
+ QMutexLocker locker(&m_buffersCounterMutex);
+ m_buffersCounter -= val;
+ }
+
+ Q_ASSERT(m_buffersCounter >= 0);
+
+ m_buffersCounterCondition.wakeAll();
+}
+
+void AVFAudioDecoder::stop()
+{
+ qCDebug(qLcAVFAudioDecoder()) << "stop decoding";
+
+ m_decodingContext.reset();
+ decBuffersCounter(m_cachedBuffers.size());
+ m_cachedBuffers.clear();
+
+ bufferAvailableChanged(false);
+ positionChanged(-1);
+ durationChanged(-1);
+
+ onFinished();
+}
+
+QAudioFormat AVFAudioDecoder::audioFormat() const
+{
+ return m_format;
+}
+
+void AVFAudioDecoder::setAudioFormat(const QAudioFormat &format)
+{
+ if (m_format != format) {
+ m_format = format;
+ formatChanged(m_format);
+ }
+}
+
+QAudioBuffer AVFAudioDecoder::read()
+{
+ if (m_cachedBuffers.empty())
+ return QAudioBuffer();
+
+ Q_ASSERT(m_cachedBuffers.size() > 0);
+ QAudioBuffer buffer = m_cachedBuffers.dequeue();
+ decBuffersCounter(1);
+
+ positionChanged(buffer.startTime() / 1000);
+ bufferAvailableChanged(!m_cachedBuffers.empty());
+ return buffer;
+}
+
+void AVFAudioDecoder::processInvalidMedia(QAudioDecoder::Error errorCode,
+ const QString &errorString)
+{
+ qCDebug(qLcAVFAudioDecoder()) << "Invalid media. Error code:" << errorCode
+ << "Description:" << errorString;
+
+ Q_ASSERT(QThread::currentThread() == thread());
+
+ error(int(errorCode), errorString);
+
+ // TODO: may be check if decodingCondext was changed by
+ // user's action (restart) from the emitted error.
+ // We should handle it somehow (don't run stop, print warning or etc...)
+
+ stop();
+}
+
+void AVFAudioDecoder::onFinished()
+{
+ m_decodingContext.reset();
+
+ if (isDecoding())
+ finished();
+}
+
+void AVFAudioDecoder::initAssetReader()
+{
+ qCDebug(qLcAVFAudioDecoder()) << "Init asset reader";
+
+ Q_ASSERT(m_asset);
+ Q_ASSERT(QThread::currentThread() == thread());
+
+ NSArray<AVAssetTrack *> *tracks = [m_asset tracksWithMediaType:AVMediaTypeAudio];
+ if (!tracks.count) {
+ processInvalidMedia(QAudioDecoder::FormatError, tr("No audio tracks found"));
+ return;
+ }
+
+ AVAssetTrack *track = [tracks objectAtIndex:0];
+ QAudioFormat format = m_format.isValid() ? m_format : qt_format_for_audio_track(track);
+ if (!format.isValid()) {
+ processInvalidMedia(QAudioDecoder::FormatError, tr("Unsupported source format"));
+ return;
+ }
+
+ durationChanged(CMTimeGetSeconds(track.timeRange.duration) * 1000);
+
+ NSError *error = nil;
+ NSDictionary *audioSettings = av_audio_settings_for_format(format);
+
+ AVAssetReaderTrackOutput *readerOutput =
+ [[AVAssetReaderTrackOutput alloc] initWithTrack:track outputSettings:audioSettings];
+ AVAssetReader *reader = [[AVAssetReader alloc] initWithAsset:m_asset error:&error];
+ if (error) {
+ processInvalidMedia(QAudioDecoder::ResourceError, QString::fromNSString(error.localizedDescription));
+ return;
+ }
+ if (![reader canAddOutput:readerOutput]) {
+ processInvalidMedia(QAudioDecoder::ResourceError, tr("Failed to add asset reader output"));
+ return;
+ }
+
+ [reader addOutput:readerOutput];
+
+ Q_ASSERT(m_decodingContext);
+ m_decodingContext->m_reader = reader;
+ m_decodingContext->m_readerOutput = readerOutput;
+
+ startReading();
+}
+
+void AVFAudioDecoder::startReading()
+{
+ Q_ASSERT(m_decodingContext);
+ Q_ASSERT(m_decodingContext->m_reader);
+ Q_ASSERT(QThread::currentThread() == thread());
+
+ // Prepares the receiver for obtaining sample buffers from the asset.
+ if (![m_decodingContext->m_reader startReading]) {
+ processInvalidMedia(QAudioDecoder::ResourceError, tr("Could not start reading"));
+ return;
+ }
+
+ setIsDecoding(true);
+
+ std::weak_ptr<DecodingContext> weakContext = m_decodingContext;
+
+ // Since copyNextSampleBuffer is synchronous, submit it to an async dispatch queue
+ // to run in a separate thread. Call the handleNextSampleBuffer "callback" on another
+ // thread when new audio sample is read.
+ auto copyNextSampleBuffer = [=]() {
+ auto decodingContext = weakContext.lock();
+ if (!decodingContext)
+ return false;
+
+ CMSampleBufferRef sampleBuffer = [decodingContext->m_readerOutput copyNextSampleBuffer];
+ if (!sampleBuffer)
+ return false;
+
+ dispatch_async(m_decodingQueue, [=]() {
+ if (!weakContext.expired() && CMSampleBufferDataIsReady(sampleBuffer)) {
+ auto audioBuffer = handleNextSampleBuffer(sampleBuffer);
+
+ if (audioBuffer.isValid())
+ invokeWithDecodingContext(weakContext,
+ [=]() { handleNewAudioBuffer(audioBuffer); });
+ }
+
+ CFRelease(sampleBuffer);
+ });
+
+ return true;
+ };
+
+ dispatch_async(m_readingQueue, [=]() {
+ qCDebug(qLcAVFAudioDecoder()) << "start reading thread";
+
+ do {
+ // Note, waiting here doesn't ensure strong contol of the counter.
+ // However, it doesn't affect the logic: the reading flow works fine
+ // even if the counter is time-to-time more than max value
+ waitUntilBuffersCounterLessMax();
+ } while (copyNextSampleBuffer());
+
+ // TODO: check m_reader.status == AVAssetReaderStatusFailed
+ invokeWithDecodingContext(weakContext, [this]() { onFinished(); });
+ });
+}
+
+void AVFAudioDecoder::waitUntilBuffersCounterLessMax()
+{
+ if (m_buffersCounter >= MAX_BUFFERS_IN_QUEUE) {
+ // the check avoids extra mutex lock.
+
+ QMutexLocker locker(&m_buffersCounterMutex);
+
+ while (m_buffersCounter >= MAX_BUFFERS_IN_QUEUE)
+ m_buffersCounterCondition.wait(&m_buffersCounterMutex);
+ }
+}
+
+void AVFAudioDecoder::handleNewAudioBuffer(QAudioBuffer buffer)
+{
+ m_cachedBuffers.enqueue(buffer);
+ ++m_buffersCounter;
+
+ Q_ASSERT(m_cachedBuffers.size() == m_buffersCounter);
+
+ bufferAvailableChanged(true);
+ bufferReady();
+}
+
+/*
+ * The method calls the passed functor in the thread of AVFAudioDecoder and guarantees that
+ * the passed decoding context is not expired. In other words, it helps avoiding all callbacks
+ * after stopping of the decoder.
+ */
+template<typename F>
+void AVFAudioDecoder::invokeWithDecodingContext(std::weak_ptr<DecodingContext> weakContext, F &&f)
+{
+ if (!weakContext.expired())
+ QMetaObject::invokeMethod(this, [=]() {
+ // strong check: compare with actual decoding context.
+ // Otherwise, the context can be temporary locked by one of dispatch queues.
+ if (auto context = weakContext.lock(); context && context == m_decodingContext)
+ f();
+ });
+}
+
+#include "moc_avfaudiodecoder_p.cpp"
diff --git a/src/plugins/multimedia/darwin/avfaudiodecoder_p.h b/src/plugins/multimedia/darwin/avfaudiodecoder_p.h
new file mode 100644
index 000000000..81ef3f49e
--- /dev/null
+++ b/src/plugins/multimedia/darwin/avfaudiodecoder_p.h
@@ -0,0 +1,99 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFAUDIODECODER_H
+#define AVFAUDIODECODER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/private/qtmultimediaglobal_p.h>
+#include <QObject>
+#include <QtCore/qurl.h>
+#include <QWaitCondition>
+#include <QMutex>
+#include <QQueue>
+
+#include "private/qplatformaudiodecoder_p.h"
+#include "qaudiodecoder.h"
+
+#include <dispatch/dispatch.h>
+
+Q_FORWARD_DECLARE_OBJC_CLASS(AVURLAsset);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVAssetReader);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVAssetReaderTrackOutput);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVFResourceReaderDelegate);
+
+QT_BEGIN_NAMESPACE
+
+class AVFAudioDecoder : public QPlatformAudioDecoder
+{
+ Q_OBJECT
+
+ struct DecodingContext;
+
+public:
+ AVFAudioDecoder(QAudioDecoder *parent);
+ virtual ~AVFAudioDecoder();
+
+ QUrl source() const override;
+ void setSource(const QUrl &fileName) override;
+
+ QIODevice *sourceDevice() const override;
+ void setSourceDevice(QIODevice *device) override;
+
+ void start() override;
+ void stop() override;
+
+ QAudioFormat audioFormat() const override;
+ void setAudioFormat(const QAudioFormat &format) override;
+
+ QAudioBuffer read() override;
+
+private:
+ void handleNewAudioBuffer(QAudioBuffer);
+ void startReading();
+
+ void processInvalidMedia(QAudioDecoder::Error errorCode, const QString& errorString);
+ void initAssetReader();
+ void onFinished();
+
+ void waitUntilBuffersCounterLessMax();
+
+ void decBuffersCounter(uint val);
+
+ template<typename F>
+ void invokeWithDecodingContext(std::weak_ptr<DecodingContext> weakContext, F &&f);
+
+private:
+ QUrl m_source;
+ QIODevice *m_device = nullptr;
+ QAudioFormat m_format;
+
+ // Use a separate counter instead of buffers queue size in order to
+ // ensure atomic access and also make mutex locking shorter
+ std::atomic<int> m_buffersCounter = 0;
+ QQueue<QAudioBuffer> m_cachedBuffers;
+
+ AVURLAsset *m_asset = nullptr;
+
+ AVFResourceReaderDelegate *m_readerDelegate = nullptr;
+ dispatch_queue_t m_readingQueue;
+ dispatch_queue_t m_decodingQueue;
+
+ std::shared_ptr<DecodingContext> m_decodingContext;
+ QMutex m_buffersCounterMutex;
+ QWaitCondition m_buffersCounterCondition;
+};
+
+QT_END_NAMESPACE
+
+#endif // AVFAUDIODECODER_H
diff --git a/src/plugins/multimedia/darwin/avfvideobuffer.mm b/src/plugins/multimedia/darwin/avfvideobuffer.mm
new file mode 100644
index 000000000..57ec89ae7
--- /dev/null
+++ b/src/plugins/multimedia/darwin/avfvideobuffer.mm
@@ -0,0 +1,207 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfvideobuffer_p.h"
+#include <rhi/qrhi.h>
+#include <CoreVideo/CVMetalTexture.h>
+#include <CoreVideo/CVMetalTextureCache.h>
+#include <QtGui/qopenglcontext.h>
+
+#include <private/qvideotexturehelper_p.h>
+#include "qavfhelpers_p.h"
+
+#import <AVFoundation/AVFoundation.h>
+#import <Metal/Metal.h>
+
+QT_USE_NAMESPACE
+
+AVFVideoBuffer::AVFVideoBuffer(AVFVideoSinkInterface *sink, CVImageBufferRef buffer)
+ : QHwVideoBuffer(sink->rhi() ? QVideoFrame::RhiTextureHandle : QVideoFrame::NoHandle,
+ sink->rhi()),
+ sink(sink),
+ m_buffer(buffer)
+{
+// m_type = QVideoFrame::NoHandle;
+// qDebug() << "RHI" << m_rhi;
+ CVPixelBufferRetain(m_buffer);
+ const bool rhiIsOpenGL = sink && sink->rhi() && sink->rhi()->backend() == QRhi::OpenGLES2;
+ m_format = QAVFHelpers::videoFormatForImageBuffer(m_buffer, rhiIsOpenGL);
+}
+
+AVFVideoBuffer::~AVFVideoBuffer()
+{
+ AVFVideoBuffer::unmap();
+ for (int i = 0; i < 3; ++i)
+ if (cvMetalTexture[i])
+ CFRelease(cvMetalTexture[i]);
+#if defined(Q_OS_MACOS)
+ if (cvOpenGLTexture)
+ CVOpenGLTextureRelease(cvOpenGLTexture);
+#elif defined(Q_OS_IOS)
+ if (cvOpenGLESTexture)
+ CFRelease(cvOpenGLESTexture);
+#endif
+ CVPixelBufferRelease(m_buffer);
+}
+
+AVFVideoBuffer::MapData AVFVideoBuffer::map(QtVideo::MapMode mode)
+{
+ MapData mapData;
+
+ if (m_mode == QtVideo::MapMode::NotMapped) {
+ CVPixelBufferLockBaseAddress(m_buffer, mode == QtVideo::MapMode::ReadOnly
+ ? kCVPixelBufferLock_ReadOnly
+ : 0);
+ m_mode = mode;
+ }
+
+ mapData.planeCount = CVPixelBufferGetPlaneCount(m_buffer);
+ Q_ASSERT(mapData.planeCount <= 3);
+
+ if (!mapData.planeCount) {
+ // single plane
+ mapData.bytesPerLine[0] = CVPixelBufferGetBytesPerRow(m_buffer);
+ mapData.data[0] = static_cast<uchar*>(CVPixelBufferGetBaseAddress(m_buffer));
+ mapData.dataSize[0] = CVPixelBufferGetDataSize(m_buffer);
+ mapData.planeCount = mapData.data[0] ? 1 : 0;
+ return mapData;
+ }
+
+ // For a bi-planar or tri-planar format we have to set the parameters correctly:
+ for (int i = 0; i < mapData.planeCount; ++i) {
+ mapData.bytesPerLine[i] = CVPixelBufferGetBytesPerRowOfPlane(m_buffer, i);
+ mapData.dataSize[i] = mapData.bytesPerLine[i]*CVPixelBufferGetHeightOfPlane(m_buffer, i);
+ mapData.data[i] = static_cast<uchar*>(CVPixelBufferGetBaseAddressOfPlane(m_buffer, i));
+ }
+
+ return mapData;
+}
+
+void AVFVideoBuffer::unmap()
+{
+ if (m_mode != QtVideo::MapMode::NotMapped) {
+ CVPixelBufferUnlockBaseAddress(m_buffer, m_mode == QtVideo::MapMode::ReadOnly
+ ? kCVPixelBufferLock_ReadOnly
+ : 0);
+ m_mode = QtVideo::MapMode::NotMapped;
+ }
+}
+
+static MTLPixelFormat rhiTextureFormatToMetalFormat(QRhiTexture::Format f)
+{
+ switch (f) {
+ default:
+ case QRhiTexture::UnknownFormat:
+ return MTLPixelFormatInvalid;
+ case QRhiTexture::RGBA8:
+ return MTLPixelFormatRGBA8Unorm;
+ case QRhiTexture::BGRA8:
+ return MTLPixelFormatBGRA8Unorm;
+ case QRhiTexture::R8:
+ return MTLPixelFormatR8Unorm;
+ case QRhiTexture::RG8:
+ return MTLPixelFormatRG8Unorm;
+ case QRhiTexture::R16:
+ return MTLPixelFormatR16Unorm;
+ case QRhiTexture::RG16:
+ return MTLPixelFormatRG16Unorm;
+
+ case QRhiTexture::RGBA16F:
+ return MTLPixelFormatRGBA16Float;
+ case QRhiTexture::RGBA32F:
+ return MTLPixelFormatRGBA32Float;
+ case QRhiTexture::R16F:
+ return MTLPixelFormatR16Float;
+ case QRhiTexture::R32F:
+ return MTLPixelFormatR32Float;
+ }
+}
+
+
+quint64 AVFVideoBuffer::textureHandle(QRhi *, int plane) const
+{
+ auto *textureDescription = QVideoTextureHelper::textureDescription(m_format.pixelFormat());
+ int bufferPlanes = CVPixelBufferGetPlaneCount(m_buffer);
+// qDebug() << "texture handle" << plane << m_rhi << (m_rhi->backend() == QRhi::Metal) << bufferPlanes;
+ if (plane > 0 && plane >= bufferPlanes)
+ return 0;
+ if (!m_rhi)
+ return 0;
+ if (m_rhi->backend() == QRhi::Metal) {
+ if (!cvMetalTexture[plane]) {
+ size_t width = CVPixelBufferGetWidth(m_buffer);
+ size_t height = CVPixelBufferGetHeight(m_buffer);
+ width = textureDescription->widthForPlane(width, plane);
+ height = textureDescription->heightForPlane(height, plane);
+
+ // Create a CoreVideo pixel buffer backed Metal texture image from the texture cache.
+ QMutexLocker locker(sink->textureCacheMutex());
+ if (!metalCache && sink->cvMetalTextureCache)
+ metalCache = CVMetalTextureCacheRef(CFRetain(sink->cvMetalTextureCache));
+ if (!metalCache) {
+ qWarning("cannot create texture, Metal texture cache was released?");
+ return {};
+ }
+ auto ret = CVMetalTextureCacheCreateTextureFromImage(
+ kCFAllocatorDefault,
+ metalCache,
+ m_buffer, nil,
+ rhiTextureFormatToMetalFormat(textureDescription->textureFormat[plane]),
+ width, height,
+ plane,
+ &cvMetalTexture[plane]);
+
+ if (ret != kCVReturnSuccess)
+ qWarning() << "texture creation failed" << ret;
+// auto t = CVMetalTextureGetTexture(cvMetalTexture[plane]);
+// qDebug() << " metal texture is" << quint64(cvMetalTexture[plane]) << width << height;
+// qDebug() << " " << t.iosurfacePlane << t.pixelFormat << t.width << t.height;
+ }
+
+ // Get a Metal texture using the CoreVideo Metal texture reference.
+// qDebug() << " -> " << quint64(CVMetalTextureGetTexture(cvMetalTexture[plane]));
+ return cvMetalTexture[plane] ? quint64(CVMetalTextureGetTexture(cvMetalTexture[plane])) : 0;
+ } else if (m_rhi->backend() == QRhi::OpenGLES2) {
+#if QT_CONFIG(opengl)
+#ifdef Q_OS_MACOS
+ CVOpenGLTextureCacheFlush(sink->cvOpenGLTextureCache, 0);
+ // Create a CVPixelBuffer-backed OpenGL texture image from the texture cache.
+ const CVReturn cvret = CVOpenGLTextureCacheCreateTextureFromImage(
+ kCFAllocatorDefault,
+ sink->cvOpenGLTextureCache,
+ m_buffer,
+ nil,
+ &cvOpenGLTexture);
+ if (cvret != kCVReturnSuccess)
+ qWarning() << "OpenGL texture creation failed" << cvret;
+
+ Q_ASSERT(CVOpenGLTextureGetTarget(cvOpenGLTexture) == GL_TEXTURE_RECTANGLE);
+ // Get an OpenGL texture name from the CVPixelBuffer-backed OpenGL texture image.
+ return CVOpenGLTextureGetName(cvOpenGLTexture);
+#endif
+#ifdef Q_OS_IOS
+ CVOpenGLESTextureCacheFlush(sink->cvOpenGLESTextureCache, 0);
+ // Create a CVPixelBuffer-backed OpenGL texture image from the texture cache.
+ const CVReturn cvret = CVOpenGLESTextureCacheCreateTextureFromImage(
+ kCFAllocatorDefault,
+ sink->cvOpenGLESTextureCache,
+ m_buffer,
+ nil,
+ GL_TEXTURE_2D,
+ GL_RGBA,
+ CVPixelBufferGetWidth(m_buffer),
+ CVPixelBufferGetHeight(m_buffer),
+ GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ 0,
+ &cvOpenGLESTexture);
+ if (cvret != kCVReturnSuccess)
+ qWarning() << "OpenGL ES texture creation failed" << cvret;
+
+ // Get an OpenGL texture name from the CVPixelBuffer-backed OpenGL texture image.
+ return CVOpenGLESTextureGetName(cvOpenGLESTexture);
+#endif
+#endif
+ }
+ return 0;
+}
diff --git a/src/plugins/multimedia/darwin/avfvideobuffer_p.h b/src/plugins/multimedia/darwin/avfvideobuffer_p.h
new file mode 100644
index 000000000..f70961c15
--- /dev/null
+++ b/src/plugins/multimedia/darwin/avfvideobuffer_p.h
@@ -0,0 +1,64 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFVIDEOBUFFER_H
+#define AVFVIDEOBUFFER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qhwvideobuffer_p.h>
+#include <private/qcore_mac_p.h>
+
+#include <QtCore/qobject.h>
+#include <QtCore/qmutex.h>
+#include <avfvideosink_p.h>
+
+#include <CoreVideo/CVImageBuffer.h>
+
+#import "Metal/Metal.h"
+#import "MetalKit/MetalKit.h"
+
+QT_BEGIN_NAMESPACE
+
+struct AVFMetalTexture;
+class AVFVideoBuffer : public QHwVideoBuffer
+{
+public:
+ AVFVideoBuffer(AVFVideoSinkInterface *sink, CVImageBufferRef buffer);
+ ~AVFVideoBuffer();
+
+ MapData map(QtVideo::MapMode mode);
+ void unmap();
+
+ virtual quint64 textureHandle(QRhi *, int plane) const;
+
+ QVideoFrameFormat videoFormat() const { return m_format; }
+
+private:
+ AVFVideoSinkInterface *sink = nullptr;
+
+ mutable CVMetalTextureRef cvMetalTexture[3] = {};
+ mutable QCFType<CVMetalTextureCacheRef> metalCache;
+#if defined(Q_OS_MACOS)
+ mutable CVOpenGLTextureRef cvOpenGLTexture = nullptr;
+#elif defined(Q_OS_IOS)
+ mutable CVOpenGLESTextureRef cvOpenGLESTexture = nullptr;
+#endif
+
+ CVImageBufferRef m_buffer = nullptr;
+ QtVideo::MapMode m_mode = QtVideo::MapMode::NotMapped;
+ QVideoFrameFormat m_format;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/darwin/avfvideosink.mm b/src/plugins/multimedia/darwin/avfvideosink.mm
new file mode 100644
index 000000000..f4c8bdb2e
--- /dev/null
+++ b/src/plugins/multimedia/darwin/avfvideosink.mm
@@ -0,0 +1,228 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfvideosink_p.h"
+
+#include <rhi/qrhi.h>
+#include <QtGui/qopenglcontext.h>
+
+#include <AVFoundation/AVFoundation.h>
+#import <QuartzCore/CATransaction.h>
+
+#if __has_include(<AppKit/AppKit.h>)
+#include <AppKit/AppKit.h>
+#endif
+
+#if __has_include(<UIKit/UIKit.h>)
+#include <UIKit/UIKit.h>
+#endif
+
+QT_USE_NAMESPACE
+
+AVFVideoSink::AVFVideoSink(QVideoSink *parent)
+ : QPlatformVideoSink(parent)
+{
+}
+
+AVFVideoSink::~AVFVideoSink()
+{
+}
+
+void AVFVideoSink::setRhi(QRhi *rhi)
+{
+ if (m_rhi == rhi)
+ return;
+ m_rhi = rhi;
+ if (m_interface)
+ m_interface->setRhi(rhi);
+}
+
+void AVFVideoSink::setNativeSize(QSize size)
+{
+ if (size == nativeSize())
+ return;
+ QPlatformVideoSink::setNativeSize(size);
+ if (m_interface)
+ m_interface->nativeSizeChanged();
+}
+
+void AVFVideoSink::setVideoSinkInterface(AVFVideoSinkInterface *interface)
+{
+ m_interface = interface;
+ if (m_interface)
+ m_interface->setRhi(m_rhi);
+}
+
+AVFVideoSinkInterface::~AVFVideoSinkInterface()
+{
+ if (m_layer)
+ [m_layer release];
+ if (m_outputSettings)
+ [m_outputSettings release];
+ freeTextureCaches();
+}
+
+void AVFVideoSinkInterface::freeTextureCaches()
+{
+ if (cvMetalTextureCache)
+ CFRelease(cvMetalTextureCache);
+ cvMetalTextureCache = nullptr;
+#if defined(Q_OS_MACOS)
+ if (cvOpenGLTextureCache)
+ CFRelease(cvOpenGLTextureCache);
+ cvOpenGLTextureCache = nullptr;
+#elif defined(Q_OS_IOS)
+ if (cvOpenGLESTextureCache)
+ CFRelease(cvOpenGLESTextureCache);
+ cvOpenGLESTextureCache = nullptr;
+#endif
+}
+
+void AVFVideoSinkInterface::setVideoSink(AVFVideoSink *sink)
+{
+ if (sink == m_sink)
+ return;
+
+ if (m_sink)
+ m_sink->setVideoSinkInterface(nullptr);
+
+ m_sink = sink;
+
+ if (m_sink) {
+ m_sink->setVideoSinkInterface(this);
+ reconfigure();
+ }
+}
+
+void AVFVideoSinkInterface::setRhi(QRhi *rhi)
+{
+ QMutexLocker locker(&m_textureCacheMutex);
+ if (m_rhi == rhi)
+ return;
+ freeTextureCaches();
+ m_rhi = rhi;
+
+ if (!rhi)
+ return;
+ if (rhi->backend() == QRhi::Metal) {
+ const auto *metal = static_cast<const QRhiMetalNativeHandles *>(rhi->nativeHandles());
+
+ // Create a Metal Core Video texture cache from the pixel buffer.
+ Q_ASSERT(!cvMetalTextureCache);
+ if (CVMetalTextureCacheCreate(
+ kCFAllocatorDefault,
+ nil,
+ (id<MTLDevice>)metal->dev,
+ nil,
+ &cvMetalTextureCache) != kCVReturnSuccess) {
+ qWarning() << "Metal texture cache creation failed";
+ m_rhi = nullptr;
+ }
+ } else if (rhi->backend() == QRhi::OpenGLES2) {
+#if QT_CONFIG(opengl)
+#ifdef Q_OS_MACOS
+ const auto *gl = static_cast<const QRhiGles2NativeHandles *>(rhi->nativeHandles());
+
+ auto nsGLContext = gl->context->nativeInterface<QNativeInterface::QCocoaGLContext>()->nativeContext();
+ auto nsGLPixelFormat = nsGLContext.pixelFormat.CGLPixelFormatObj;
+
+ // Create an OpenGL CoreVideo texture cache from the pixel buffer.
+ if (CVOpenGLTextureCacheCreate(
+ kCFAllocatorDefault,
+ nullptr,
+ reinterpret_cast<CGLContextObj>(nsGLContext.CGLContextObj),
+ nsGLPixelFormat,
+ nil,
+ &cvOpenGLTextureCache)) {
+ qWarning() << "OpenGL texture cache creation failed";
+ m_rhi = nullptr;
+ }
+#endif
+#ifdef Q_OS_IOS
+ // Create an OpenGL CoreVideo texture cache from the pixel buffer.
+ if (CVOpenGLESTextureCacheCreate(
+ kCFAllocatorDefault,
+ nullptr,
+ [EAGLContext currentContext],
+ nullptr,
+ &cvOpenGLESTextureCache)) {
+ qWarning() << "OpenGL texture cache creation failed";
+ m_rhi = nullptr;
+ }
+#endif
+#else
+ m_rhi = nullptr;
+#endif // QT_CONFIG(opengl)
+ }
+ setOutputSettings();
+}
+
+void AVFVideoSinkInterface::setLayer(CALayer *layer)
+{
+ if (layer == m_layer)
+ return;
+
+ if (m_layer)
+ [m_layer release];
+
+ m_layer = layer;
+ if (m_layer)
+ [m_layer retain];
+
+ reconfigure();
+}
+
+void AVFVideoSinkInterface::setOutputSettings()
+{
+ if (m_outputSettings)
+ [m_outputSettings release];
+ m_outputSettings = nil;
+
+ // Set pixel format
+ NSDictionary *dictionary = nil;
+ if (m_rhi && m_rhi->backend() == QRhi::OpenGLES2) {
+#if QT_CONFIG(opengl)
+ dictionary = @{(NSString *)kCVPixelBufferPixelFormatTypeKey:
+ @(kCVPixelFormatType_32BGRA)
+#ifndef Q_OS_IOS // On iOS this key generates a warning about unsupported key.
+ , (NSString *)kCVPixelBufferOpenGLCompatibilityKey: @true
+#endif // Q_OS_IOS
+ };
+#endif
+ } else {
+ dictionary = @{(NSString *)kCVPixelBufferPixelFormatTypeKey:
+ @[
+ @(kCVPixelFormatType_32BGRA),
+ @(kCVPixelFormatType_32RGBA),
+ @(kCVPixelFormatType_422YpCbCr8),
+ @(kCVPixelFormatType_422YpCbCr8_yuvs),
+ @(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange),
+ @(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange),
+ @(kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange),
+ @(kCVPixelFormatType_420YpCbCr10BiPlanarFullRange),
+ @(kCVPixelFormatType_OneComponent8),
+ @(kCVPixelFormatType_OneComponent16),
+ @(kCVPixelFormatType_420YpCbCr8Planar),
+ @(kCVPixelFormatType_420YpCbCr8PlanarFullRange)
+ ]
+#ifndef Q_OS_IOS // This key is not supported and generates a warning.
+ , (NSString *)kCVPixelBufferMetalCompatibilityKey: @true
+#endif // Q_OS_IOS
+ };
+ }
+
+ m_outputSettings = [[NSDictionary alloc] initWithDictionary:dictionary];
+}
+
+void AVFVideoSinkInterface::updateLayerBounds()
+{
+ if (!m_layer)
+ return;
+ [CATransaction begin];
+ [CATransaction setDisableActions: YES]; // disable animation/flicks
+ m_layer.frame = QRectF(0, 0, nativeSize().width(), nativeSize().height()).toCGRect();
+ m_layer.bounds = m_layer.frame;
+ [CATransaction commit];
+}
+
+#include "moc_avfvideosink_p.cpp"
diff --git a/src/plugins/multimedia/darwin/avfvideosink_p.h b/src/plugins/multimedia/darwin/avfvideosink_p.h
new file mode 100644
index 000000000..9b66e79f2
--- /dev/null
+++ b/src/plugins/multimedia/darwin/avfvideosink_p.h
@@ -0,0 +1,99 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFVIDEOWINDOWCONTROL_H
+#define AVFVIDEOWINDOWCONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/QMutex>
+#include "private/qplatformvideosink_p.h"
+
+Q_FORWARD_DECLARE_OBJC_CLASS(CALayer);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVPlayerLayer);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureVideoPreviewLayer);
+
+#include <CoreVideo/CVBase.h>
+#include <CoreVideo/CVPixelBuffer.h>
+#include <CoreVideo/CVImageBuffer.h>
+
+#import "Metal/Metal.h"
+#import "MetalKit/MetalKit.h"
+
+QT_BEGIN_NAMESPACE
+
+class AVFVideoSinkInterface;
+
+class AVFVideoSink : public QPlatformVideoSink
+{
+ Q_OBJECT
+
+public:
+ AVFVideoSink(QVideoSink *parent = nullptr);
+ virtual ~AVFVideoSink();
+
+ // QPlatformVideoSink interface
+public:
+ void setRhi(QRhi *rhi) override;
+
+ void setNativeSize(QSize size);
+
+ void setVideoSinkInterface(AVFVideoSinkInterface *interface);
+
+private:
+ AVFVideoSinkInterface *m_interface = nullptr;
+ QRhi *m_rhi = nullptr;
+};
+
+class AVFVideoSinkInterface
+{
+public:
+ ~AVFVideoSinkInterface();
+
+ void setVideoSink(AVFVideoSink *sink);
+
+
+ virtual void reconfigure() = 0;
+ virtual void setRhi(QRhi *);
+ virtual void setLayer(CALayer *layer);
+ virtual void setOutputSettings();
+
+ QMutex *textureCacheMutex() { return &m_textureCacheMutex; }
+
+ QRhi *rhi() const { return m_rhi; }
+
+ void updateLayerBounds();
+ void nativeSizeChanged() { updateLayerBounds(); }
+ QSize nativeSize() const { return m_sink ? m_sink->nativeSize() : QSize(); }
+
+ CVMetalTextureCacheRef cvMetalTextureCache = nullptr;
+#if defined(Q_OS_MACOS)
+ CVOpenGLTextureCacheRef cvOpenGLTextureCache = nullptr;
+#elif defined(Q_OS_IOS)
+ CVOpenGLESTextureCacheRef cvOpenGLESTextureCache = nullptr;
+#endif
+private:
+ void freeTextureCaches();
+
+protected:
+
+ AVFVideoSink *m_sink = nullptr;
+ QRhi *m_rhi = nullptr;
+ CALayer *m_layer = nullptr;
+ NSDictionary *m_outputSettings = nullptr;
+ QMutex m_textureCacheMutex;
+};
+
+
+QT_END_NAMESPACE
+
+#endif // AVFVIDEOWINDOWCONTROL_H
diff --git a/src/plugins/multimedia/darwin/camera/avfaudiopreviewdelegate.mm b/src/plugins/multimedia/darwin/camera/avfaudiopreviewdelegate.mm
new file mode 100644
index 000000000..1b2d4b15d
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfaudiopreviewdelegate.mm
@@ -0,0 +1,98 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfcamerasession_p.h"
+#include "avfaudiopreviewdelegate_p.h"
+
+QT_USE_NAMESPACE
+
+@implementation AVFAudioPreviewDelegate
+{
+@private
+ AVSampleBufferAudioRenderer *m_audioRenderer;
+ AVFCameraSession *m_session;
+ AVSampleBufferRenderSynchronizer *m_audioBufferSynchronizer;
+ dispatch_queue_t m_audioPreviewQueue;
+}
+
+- (id)init
+{
+ if (self = [super init]) {
+ m_session = nil;
+ m_audioBufferSynchronizer = [[AVSampleBufferRenderSynchronizer alloc] init];
+ m_audioRenderer = [[AVSampleBufferAudioRenderer alloc] init];
+ [m_audioBufferSynchronizer addRenderer:m_audioRenderer];
+ return self;
+ }
+ return nil;
+}
+
+- (void)captureOutput:(AVCaptureOutput *)captureOutput
+ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
+ fromConnection:(AVCaptureConnection *)connection
+{
+ Q_UNUSED(connection);
+ Q_ASSERT(m_session);
+
+ if (!CMSampleBufferDataIsReady(sampleBuffer)) {
+ qWarning() << Q_FUNC_INFO << "sample buffer is not ready, skipping.";
+ return;
+ }
+
+ CFRetain(sampleBuffer);
+
+ dispatch_async(m_audioPreviewQueue, ^{
+ [self renderAudioSampleBuffer:sampleBuffer];
+ CFRelease(sampleBuffer);
+ });
+}
+
+- (void)renderAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer
+{
+ Q_ASSERT(sampleBuffer);
+ Q_ASSERT(m_session);
+
+ if (m_audioBufferSynchronizer && m_audioRenderer) {
+ [m_audioRenderer enqueueSampleBuffer:sampleBuffer];
+ if (m_audioBufferSynchronizer.rate == 0)
+ [m_audioBufferSynchronizer setRate:1 time:CMSampleBufferGetPresentationTimeStamp(sampleBuffer)];
+ }
+}
+
+- (void)resetAudioPreviewDelegate
+{
+ [m_session->audioOutput() setSampleBufferDelegate:self queue:m_audioPreviewQueue];
+}
+
+- (void)setupWithCaptureSession: (AVFCameraSession*)session
+ audioOutputDevice: (NSString*)deviceId
+{
+ m_session = session;
+
+ m_audioPreviewQueue = dispatch_queue_create("audio-preview-queue", nullptr);
+ [m_session->audioOutput() setSampleBufferDelegate:self queue:m_audioPreviewQueue];
+#ifdef Q_OS_MACOS
+ m_audioRenderer.audioOutputDeviceUniqueID = deviceId;
+#endif
+}
+
+- (void)setVolume: (float)volume
+{
+ m_audioRenderer.volume = volume;
+}
+
+- (void)setMuted: (bool)muted
+{
+ m_audioRenderer.muted = muted;
+}
+
+-(void)dealloc {
+ m_session = nil;
+ [m_audioRenderer release];
+ [m_audioBufferSynchronizer release];
+ dispatch_release(m_audioPreviewQueue);
+
+ [super dealloc];
+}
+
+@end
diff --git a/src/plugins/multimedia/darwin/camera/avfaudiopreviewdelegate_p.h b/src/plugins/multimedia/darwin/camera/avfaudiopreviewdelegate_p.h
new file mode 100644
index 000000000..8fa06ef39
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfaudiopreviewdelegate_p.h
@@ -0,0 +1,40 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFAUDIOPREVIEWDELEGATE_P_H
+#define AVFAUDIOPREVIEWDELEGATE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+
+#include <AVFoundation/AVFoundation.h>
+
+QT_BEGIN_NAMESPACE
+
+class AVFCameraSession;
+
+QT_END_NAMESPACE
+
+@interface AVFAudioPreviewDelegate : NSObject<AVCaptureAudioDataOutputSampleBufferDelegate>
+
+- (id)init;
+- (void)setupWithCaptureSession: (AVFCameraSession*)session
+ audioOutputDevice: (NSString*)deviceId;
+- (void)renderAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer;
+- (void)resetAudioPreviewDelegate;
+- (void)setVolume: (float)volume;
+- (void)setMuted: (bool)muted;
+
+@end
+
+#endif // AVFAUDIOPREVIEWDELEGATE_P_H
diff --git a/src/plugins/multimedia/darwin/camera/avfcamera.mm b/src/plugins/multimedia/darwin/camera/avfcamera.mm
new file mode 100644
index 000000000..05cdbae17
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfcamera.mm
@@ -0,0 +1,89 @@
+// Copyright (C) 2022 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfcameradebug_p.h"
+#include "avfcamera_p.h"
+#include "avfcamerasession_p.h"
+#include "avfcameraservice_p.h"
+#include "avfcamerautility_p.h"
+#include "avfcamerarenderer_p.h"
+#include <qmediacapturesession.h>
+
+QT_USE_NAMESPACE
+
+AVFCamera::AVFCamera(QCamera *camera)
+ : QAVFCameraBase(camera)
+{
+ Q_ASSERT(camera);
+}
+
+AVFCamera::~AVFCamera()
+{
+}
+
+void AVFCamera::setActive(bool active)
+{
+ if (m_active == active)
+ return;
+ if (m_cameraDevice.isNull() && active)
+ return;
+
+ m_active = active;
+ if (m_session)
+ m_session->setActive(active);
+
+ if (active)
+ updateCameraConfiguration();
+ Q_EMIT activeChanged(m_active);
+}
+
+void AVFCamera::setCamera(const QCameraDevice &camera)
+{
+ if (m_cameraDevice == camera)
+ return;
+ m_cameraDevice = camera;
+ if (m_session)
+ m_session->setActiveCamera(camera);
+ setCameraFormat({});
+}
+
+bool AVFCamera::setCameraFormat(const QCameraFormat &format)
+{
+ if (!format.isNull() && !m_cameraDevice.videoFormats().contains(format))
+ return false;
+
+ m_cameraFormat = format.isNull() ? findBestCameraFormat(m_cameraDevice) : format;
+
+ if (m_session)
+ m_session->setCameraFormat(m_cameraFormat);
+
+ return true;
+}
+
+void AVFCamera::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ AVFCameraService *captureSession = static_cast<AVFCameraService *>(session);
+ if (m_service == captureSession)
+ return;
+
+ if (m_session) {
+ m_session->disconnect(this);
+ m_session->setActiveCamera({});
+ m_session->setCameraFormat({});
+ }
+
+ m_service = captureSession;
+ if (!m_service) {
+ m_session = nullptr;
+ return;
+ }
+
+ m_session = m_service->session();
+ Q_ASSERT(m_session);
+
+ m_session->setActiveCamera(m_cameraDevice);
+ m_session->setCameraFormat(m_cameraFormat);
+ m_session->setActive(m_active);
+}
+
+#include "moc_avfcamera_p.cpp"
diff --git a/src/plugins/multimedia/darwin/camera/avfcamera_p.h b/src/plugins/multimedia/darwin/camera/avfcamera_p.h
new file mode 100644
index 000000000..3c3e6da09
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfcamera_p.h
@@ -0,0 +1,48 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFCAMERA_H
+#define AVFCAMERA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qavfcamerabase_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class AVFCameraSession;
+class AVFCameraService;
+class AVFCameraSession;
+
+class AVFCamera : public QAVFCameraBase
+{
+Q_OBJECT
+public:
+ AVFCamera(QCamera *camera);
+ ~AVFCamera();
+
+ void setActive(bool activce) override;
+
+ void setCamera(const QCameraDevice &camera) override;
+ bool setCameraFormat(const QCameraFormat &format) override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *) override;
+
+private:
+ friend class AVFCameraSession;
+ AVFCameraService *m_service = nullptr;
+ AVFCameraSession *m_session = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/darwin/camera/avfcameradebug_p.h b/src/plugins/multimedia/darwin/camera/avfcameradebug_p.h
new file mode 100644
index 000000000..f93c85142
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfcameradebug_p.h
@@ -0,0 +1,26 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFDEBUG_H
+#define AVFDEBUG_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qtmultimediaglobal.h"
+
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+Q_DECLARE_LOGGING_CATEGORY(qLcCamera)
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/darwin/camera/avfcamerarenderer.mm b/src/plugins/multimedia/darwin/camera/avfcamerarenderer.mm
new file mode 100644
index 000000000..63e5f9056
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfcamerarenderer.mm
@@ -0,0 +1,296 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qabstractvideobuffer.h"
+#include "private/qcameradevice_p.h"
+#include "private/qvideoframe_p.h"
+#include "avfcamerarenderer_p.h"
+#include "avfcamerasession_p.h"
+#include "avfcameraservice_p.h"
+#include "avfcameradebug_p.h"
+#include "avfcamera_p.h"
+#include <avfvideosink_p.h>
+#include <avfvideobuffer_p.h>
+#include "qvideosink.h"
+#include "qavfhelpers_p.h"
+
+#include <rhi/qrhi.h>
+
+#import <AVFoundation/AVFoundation.h>
+
+#ifdef Q_OS_IOS
+#include <QtGui/qopengl.h>
+#endif
+
+#include <QtMultimedia/qvideoframeformat.h>
+
+QT_USE_NAMESPACE
+
+@interface AVFCaptureFramesDelegate : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate>
+
+- (AVFCaptureFramesDelegate *) initWithRenderer:(AVFCameraRenderer*)renderer;
+
+- (void) captureOutput:(AVCaptureOutput *)captureOutput
+ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
+ fromConnection:(AVCaptureConnection *)connection;
+
+@end
+
+@implementation AVFCaptureFramesDelegate
+{
+@private
+ AVFCameraRenderer *m_renderer;
+}
+
+- (AVFCaptureFramesDelegate *) initWithRenderer:(AVFCameraRenderer*)renderer
+{
+ if (!(self = [super init]))
+ return nil;
+
+ self->m_renderer = renderer;
+ return self;
+}
+
+- (void)captureOutput:(AVCaptureOutput *)captureOutput
+ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
+ fromConnection:(AVCaptureConnection *)connection
+{
+ Q_UNUSED(connection);
+ Q_UNUSED(captureOutput);
+
+ // NB: on iOS captureOutput/connection can be nil (when recording a video -
+ // avfmediaassetwriter).
+
+ CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
+ auto buffer = std::make_unique<AVFVideoBuffer>(m_renderer, imageBuffer);
+ auto format = buffer->videoFormat();
+ if (!format.isValid()) {
+ return;
+ }
+
+ QVideoFrame frame = QVideoFramePrivate::createFrame(std::move(buffer), format);
+ m_renderer->syncHandleViewfinderFrame(frame);
+}
+
+@end
+
+AVFCameraRenderer::AVFCameraRenderer(QObject *parent)
+ : QObject(parent)
+{
+ m_viewfinderFramesDelegate = [[AVFCaptureFramesDelegate alloc] initWithRenderer:this];
+ connect(&m_orientationHandler, &QVideoOutputOrientationHandler::orientationChanged,
+ this, &AVFCameraRenderer::deviceOrientationChanged);
+}
+
+AVFCameraRenderer::~AVFCameraRenderer()
+{
+ [m_cameraSession->captureSession() removeOutput:m_videoDataOutput];
+ [m_viewfinderFramesDelegate release];
+ [m_videoDataOutput release];
+
+ if (m_delegateQueue)
+ dispatch_release(m_delegateQueue);
+#ifdef Q_OS_IOS
+ if (m_textureCache)
+ CFRelease(m_textureCache);
+#endif
+}
+
+void AVFCameraRenderer::reconfigure()
+{
+ QMutexLocker lock(&m_vfMutex);
+
+ // ### This is a hack, need to use a reliable way to determine the size and not use the preview layer
+ if (m_layer)
+ m_sink->setNativeSize(QSize(m_layer.bounds.size.width, m_layer.bounds.size.height));
+ nativeSizeChanged();
+ deviceOrientationChanged();
+}
+
+void AVFCameraRenderer::setOutputSettings()
+{
+ if (!m_videoDataOutput)
+ return;
+
+ if (m_cameraSession) {
+ const auto format = m_cameraSession->cameraFormat();
+ if (format.pixelFormat() != QVideoFrameFormat::Format_Invalid)
+ setPixelFormat(format.pixelFormat(), QCameraFormatPrivate::getColorRange(format));
+ }
+
+ // If no output settings set from above,
+ // it's most likely because the rhi is OpenGL
+ // and the pixel format is not BGRA.
+ // We force this in the base class implementation
+ if (!m_outputSettings)
+ AVFVideoSinkInterface::setOutputSettings();
+
+ if (m_outputSettings)
+ m_videoDataOutput.videoSettings = m_outputSettings;
+}
+
+void AVFCameraRenderer::configureAVCaptureSession(AVFCameraSession *cameraSession)
+{
+ m_cameraSession = cameraSession;
+ connect(m_cameraSession, SIGNAL(readyToConfigureConnections()),
+ this, SLOT(updateCaptureConnection()));
+
+ m_needsHorizontalMirroring = false;
+
+ m_videoDataOutput = [[AVCaptureVideoDataOutput alloc] init];
+
+ // Configure video output
+ m_delegateQueue = dispatch_queue_create("vf_queue", nullptr);
+ [m_videoDataOutput
+ setSampleBufferDelegate:m_viewfinderFramesDelegate
+ queue:m_delegateQueue];
+
+ [m_cameraSession->captureSession() addOutput:m_videoDataOutput];
+}
+
+void AVFCameraRenderer::updateCaptureConnection()
+{
+ AVCaptureConnection *connection = [m_videoDataOutput connectionWithMediaType:AVMediaTypeVideo];
+ if (connection == nil || !m_cameraSession->videoCaptureDevice())
+ return;
+
+ // Frames of front-facing cameras should be mirrored horizontally (it's the default when using
+ // AVCaptureVideoPreviewLayer but not with AVCaptureVideoDataOutput)
+ if (connection.isVideoMirroringSupported)
+ connection.videoMirrored = m_cameraSession->videoCaptureDevice().position == AVCaptureDevicePositionFront;
+
+ // If the connection does't support mirroring, we'll have to do it ourselves
+ m_needsHorizontalMirroring = !connection.isVideoMirrored
+ && m_cameraSession->videoCaptureDevice().position == AVCaptureDevicePositionFront;
+
+ deviceOrientationChanged();
+}
+
+void AVFCameraRenderer::deviceOrientationChanged(int angle)
+{
+ AVCaptureConnection *connection = [m_videoDataOutput connectionWithMediaType:AVMediaTypeVideo];
+ if (connection == nil || !m_cameraSession->videoCaptureDevice())
+ return;
+
+ if (!connection.supportsVideoOrientation)
+ return;
+
+ if (angle < 0)
+ angle = m_orientationHandler.currentOrientation();
+
+ AVCaptureVideoOrientation orientation = AVCaptureVideoOrientationPortrait;
+ switch (angle) {
+ default:
+ break;
+ case 90:
+ orientation = AVCaptureVideoOrientationLandscapeRight;
+ break;
+ case 180:
+ // this keeps the last orientation, don't do anything
+ return;
+ case 270:
+ orientation = AVCaptureVideoOrientationLandscapeLeft;
+ break;
+ }
+
+ connection.videoOrientation = orientation;
+}
+
+//can be called from non main thread
+void AVFCameraRenderer::syncHandleViewfinderFrame(const QVideoFrame &frame)
+{
+ Q_EMIT newViewfinderFrame(frame);
+
+ QMutexLocker lock(&m_vfMutex);
+
+ if (!m_lastViewfinderFrame.isValid()) {
+ static QMetaMethod handleViewfinderFrameSlot = metaObject()->method(
+ metaObject()->indexOfMethod("handleViewfinderFrame()"));
+
+ handleViewfinderFrameSlot.invoke(this, Qt::QueuedConnection);
+ }
+
+ m_lastViewfinderFrame = frame;
+}
+
+AVCaptureVideoDataOutput *AVFCameraRenderer::videoDataOutput() const
+{
+ return m_videoDataOutput;
+}
+
+AVFCaptureFramesDelegate *AVFCameraRenderer::captureDelegate() const
+{
+ return m_viewfinderFramesDelegate;
+}
+
+void AVFCameraRenderer::resetCaptureDelegate() const
+{
+ [m_videoDataOutput setSampleBufferDelegate:m_viewfinderFramesDelegate queue:m_delegateQueue];
+}
+
+void AVFCameraRenderer::handleViewfinderFrame()
+{
+ QVideoFrame frame;
+ {
+ QMutexLocker lock(&m_vfMutex);
+ frame = m_lastViewfinderFrame;
+ m_lastViewfinderFrame = QVideoFrame();
+ }
+
+ if (m_sink && frame.isValid()) {
+ // ### pass format to surface
+ QVideoFrameFormat format = frame.surfaceFormat();
+ if (m_needsHorizontalMirroring)
+ format.setMirrored(true);
+
+ m_sink->setVideoFrame(frame);
+ }
+}
+
+void AVFCameraRenderer::setPixelFormat(QVideoFrameFormat::PixelFormat pixelFormat,
+ QVideoFrameFormat::ColorRange colorRange)
+{
+ if (rhi() && rhi()->backend() == QRhi::OpenGLES2) {
+ if (pixelFormat != QVideoFrameFormat::Format_BGRA8888)
+ qWarning() << "OpenGL rhi backend only supports 32BGRA pixel format.";
+ return;
+ }
+
+ // Default to 32BGRA pixel formats on the viewfinder, in case the requested
+ // format can't be used (shouldn't happen unless the developers sets a wrong camera
+ // format on the camera).
+ auto cvPixelFormat = QAVFHelpers::toCVPixelFormat(pixelFormat, colorRange);
+ if (cvPixelFormat == CvPixelFormatInvalid) {
+ cvPixelFormat = kCVPixelFormatType_32BGRA;
+ qWarning() << "QCamera::setCameraFormat: couldn't convert requested pixel format, using ARGB32";
+ }
+
+ bool isSupported = false;
+ NSArray *supportedPixelFormats = m_videoDataOutput.availableVideoCVPixelFormatTypes;
+ for (NSNumber *currentPixelFormat in supportedPixelFormats)
+ {
+ if ([currentPixelFormat unsignedIntValue] == cvPixelFormat) {
+ isSupported = true;
+ break;
+ }
+ }
+
+ if (isSupported) {
+ NSDictionary *outputSettings = @{
+ (NSString *)
+ kCVPixelBufferPixelFormatTypeKey : [NSNumber numberWithUnsignedInt:cvPixelFormat]
+#ifndef Q_OS_IOS // On iOS this key generates a warning about 'unsupported key'.
+ ,
+ (NSString *)kCVPixelBufferMetalCompatibilityKey : @true
+#endif // Q_OS_IOS
+ };
+ if (m_outputSettings)
+ [m_outputSettings release];
+ m_outputSettings = [[NSDictionary alloc] initWithDictionary:outputSettings];
+ } else {
+ qWarning() << "QCamera::setCameraFormat: requested pixel format not supported. Did you use a camera format from another camera?";
+ }
+}
+
+#include "moc_avfcamerarenderer_p.cpp"
+
diff --git a/src/plugins/multimedia/darwin/camera/avfcamerarenderer_p.h b/src/plugins/multimedia/darwin/camera/avfcamerarenderer_p.h
new file mode 100644
index 000000000..57f665cd6
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfcamerarenderer_p.h
@@ -0,0 +1,95 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFCAMERARENDERER_H
+#define AVFCAMERARENDERER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+#include <QtMultimedia/qvideoframe.h>
+#include <QtCore/qmutex.h>
+#include <avfvideosink_p.h>
+#include <private/qvideooutputorientationhandler_p.h>
+
+#include <CoreVideo/CVBase.h>
+#include <CoreVideo/CVPixelBuffer.h>
+#include <CoreVideo/CVImageBuffer.h>
+#ifdef Q_OS_IOS
+#include <CoreVideo/CVOpenGLESTexture.h>
+#include <CoreVideo/CVOpenGLESTextureCache.h>
+#endif
+
+#include <dispatch/dispatch.h>
+
+Q_FORWARD_DECLARE_OBJC_CLASS(AVFCaptureFramesDelegate);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureVideoDataOutput);
+
+QT_BEGIN_NAMESPACE
+
+class AVFCameraSession;
+class AVFCameraService;
+class AVFCameraRenderer;
+class AVFVideoSink;
+
+class AVFCameraRenderer : public QObject, public AVFVideoSinkInterface
+{
+Q_OBJECT
+public:
+ AVFCameraRenderer(QObject *parent = nullptr);
+ ~AVFCameraRenderer();
+
+ void reconfigure() override;
+ void setOutputSettings() override;
+
+ void configureAVCaptureSession(AVFCameraSession *cameraSession);
+ void syncHandleViewfinderFrame(const QVideoFrame &frame);
+
+ AVCaptureVideoDataOutput *videoDataOutput() const;
+
+ AVFCaptureFramesDelegate *captureDelegate() const;
+ void resetCaptureDelegate() const;
+
+ void setPixelFormat(QVideoFrameFormat::PixelFormat pixelFormat,
+ QVideoFrameFormat::ColorRange colorRange);
+
+Q_SIGNALS:
+ void newViewfinderFrame(const QVideoFrame &frame);
+
+private Q_SLOTS:
+ void handleViewfinderFrame();
+ void updateCaptureConnection();
+public Q_SLOTS:
+ void deviceOrientationChanged(int angle = -1);
+
+private:
+ AVFCaptureFramesDelegate *m_viewfinderFramesDelegate = nullptr;
+ AVFCameraSession *m_cameraSession = nullptr;
+ AVCaptureVideoDataOutput *m_videoDataOutput = nullptr;
+
+ bool m_needsHorizontalMirroring = false;
+
+#ifdef Q_OS_IOS
+ CVOpenGLESTextureCacheRef m_textureCache = nullptr;
+#endif
+
+ QVideoFrame m_lastViewfinderFrame;
+ QMutex m_vfMutex;
+ dispatch_queue_t m_delegateQueue;
+ QVideoOutputOrientationHandler m_orientationHandler;
+
+ friend class CVImageVideoBuffer;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/darwin/camera/avfcameraservice.mm b/src/plugins/multimedia/darwin/camera/avfcameraservice.mm
new file mode 100644
index 000000000..b25fb50a9
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfcameraservice.mm
@@ -0,0 +1,169 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtCore/qvariant.h>
+#include <QtCore/qdebug.h>
+
+#include "avfcameraservice_p.h"
+#include "avfcamera_p.h"
+#include "avfcamerasession_p.h"
+#include "avfimagecapture_p.h"
+#include "avfcamerarenderer_p.h"
+#include "avfimagecapture_p.h"
+#include "avfmediaencoder_p.h"
+#include <qmediadevices.h>
+#include <private/qplatformaudioinput_p.h>
+#include <private/qplatformaudiooutput_p.h>
+#include <qaudioinput.h>
+#include <qaudiooutput.h>
+
+QT_USE_NAMESPACE
+
+AVFCameraService::AVFCameraService()
+{
+ m_session = new AVFCameraSession(this);
+}
+
+AVFCameraService::~AVFCameraService()
+{
+ if (m_session)
+ delete m_session;
+}
+
+QPlatformCamera *AVFCameraService::camera()
+{
+ return m_cameraControl;
+}
+
+void AVFCameraService::setCamera(QPlatformCamera *camera)
+{
+ AVFCamera *control = static_cast<AVFCamera *>(camera);
+ if (m_cameraControl == control)
+ return;
+
+ if (m_cameraControl) {
+ if (m_encoder)
+ m_cameraControl->disconnect(m_encoder);
+ m_cameraControl->setCaptureSession(nullptr);
+ }
+
+ m_cameraControl = control;
+
+ if (m_cameraControl)
+ m_cameraControl->setCaptureSession(this);
+
+ emit cameraChanged();
+}
+
+QPlatformImageCapture *AVFCameraService::imageCapture()
+{
+ return m_imageCaptureControl;
+}
+
+void AVFCameraService::setImageCapture(QPlatformImageCapture *imageCapture)
+{
+ AVFImageCapture *control = static_cast<AVFImageCapture *>(imageCapture);
+ if (m_imageCaptureControl == control)
+ return;
+
+ if (m_imageCaptureControl)
+ m_imageCaptureControl->setCaptureSession(nullptr);
+
+ m_imageCaptureControl = control;
+ if (m_imageCaptureControl)
+ m_imageCaptureControl->setCaptureSession(this);
+}
+
+QPlatformMediaRecorder *AVFCameraService::mediaRecorder()
+{
+ return m_encoder;
+}
+
+void AVFCameraService::setMediaRecorder(QPlatformMediaRecorder *recorder)
+{
+ AVFMediaEncoder *control = static_cast<AVFMediaEncoder *>(recorder);
+ if (m_encoder == control)
+ return;
+
+ if (m_encoder)
+ m_encoder->setCaptureSession(nullptr);
+
+ m_encoder = control;
+ if (m_encoder)
+ m_encoder->setCaptureSession(this);
+
+ emit encoderChanged();
+}
+
+void AVFCameraService::setAudioInput(QPlatformAudioInput *input)
+{
+ if (m_audioInput == input)
+ return;
+ if (m_audioInput)
+ m_audioInput->q->disconnect(this);
+
+ m_audioInput = input;
+
+ if (input) {
+ connect(m_audioInput->q, &QAudioInput::destroyed, this, &AVFCameraService::audioInputDestroyed);
+ connect(m_audioInput->q, &QAudioInput::deviceChanged, this, &AVFCameraService::audioInputChanged);
+ connect(m_audioInput->q, &QAudioInput::mutedChanged, this, &AVFCameraService::setAudioInputMuted);
+ connect(m_audioInput->q, &QAudioInput::volumeChanged, this, &AVFCameraService::setAudioInputVolume);
+ }
+ audioInputChanged();
+}
+
+void AVFCameraService::setAudioOutput(QPlatformAudioOutput *output)
+{
+ if (m_audioOutput == output)
+ return;
+ if (m_audioOutput)
+ m_audioOutput->q->disconnect(this);
+
+ m_audioOutput = output;
+
+ if (m_audioOutput) {
+ connect(m_audioOutput->q, &QAudioOutput::destroyed, this, &AVFCameraService::audioOutputDestroyed);
+ connect(m_audioOutput->q, &QAudioOutput::deviceChanged, this, &AVFCameraService::audioOutputChanged);
+ connect(m_audioOutput->q, &QAudioOutput::mutedChanged, this, &AVFCameraService::setAudioOutputMuted);
+ connect(m_audioOutput->q, &QAudioOutput::volumeChanged, this, &AVFCameraService::setAudioOutputVolume);
+ }
+ audioOutputChanged();
+}
+
+void AVFCameraService::audioInputChanged()
+{
+ m_session->updateAudioInput();
+}
+
+void AVFCameraService::audioOutputChanged()
+{
+ m_session->updateAudioOutput();
+}
+
+void AVFCameraService::setAudioInputMuted(bool muted)
+{
+ m_session->setAudioInputMuted(muted);
+}
+
+void AVFCameraService::setAudioInputVolume(float volume)
+{
+ m_session->setAudioInputVolume(volume);
+}
+
+void AVFCameraService::setAudioOutputMuted(bool muted)
+{
+ m_session->setAudioOutputMuted(muted);
+}
+
+void AVFCameraService::setAudioOutputVolume(float volume)
+{
+ m_session->setAudioOutputVolume(volume);
+}
+
+void AVFCameraService::setVideoPreview(QVideoSink *sink)
+{
+ m_session->setVideoSink(sink);
+}
+
+#include "moc_avfcameraservice_p.cpp"
diff --git a/src/plugins/multimedia/darwin/camera/avfcameraservice_p.h b/src/plugins/multimedia/darwin/camera/avfcameraservice_p.h
new file mode 100644
index 000000000..f3ef8d08e
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfcameraservice_p.h
@@ -0,0 +1,84 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFCAMERASERVICE_H
+#define AVFCAMERASERVICE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+#include <QtCore/qset.h>
+#include <private/qplatformmediacapture_p.h>
+
+Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureDevice);
+
+QT_BEGIN_NAMESPACE
+class QPlatformCamera;
+class QPlatformMediaRecorder;
+class AVFCamera;
+class AVFImageCapture;
+class AVFCameraSession;
+class AVFMediaEncoder;
+
+class AVFCameraService : public QPlatformMediaCaptureSession
+{
+ Q_OBJECT
+public:
+ AVFCameraService();
+ ~AVFCameraService();
+
+ QPlatformCamera *camera() override;
+ void setCamera(QPlatformCamera *camera) override;
+
+ QPlatformImageCapture *imageCapture() override;
+ void setImageCapture(QPlatformImageCapture *imageCapture) override;
+
+ QPlatformMediaRecorder *mediaRecorder() override;
+ void setMediaRecorder(QPlatformMediaRecorder *recorder) override;
+
+ void setAudioInput(QPlatformAudioInput *) override;
+ void setAudioOutput(QPlatformAudioOutput *) override;
+
+ void setVideoPreview(QVideoSink *sink) override;
+
+ AVFCameraSession *session() const { return m_session; }
+ AVFCamera *avfCameraControl() const { return m_cameraControl; }
+ AVFMediaEncoder *recorderControl() const { return m_encoder; }
+ AVFImageCapture *avfImageCaptureControl() const { return m_imageCaptureControl; }
+
+ QPlatformAudioInput *audioInput() { return m_audioInput; }
+ QPlatformAudioOutput *audioOutput() { return m_audioOutput; }
+
+public Q_SLOTS:
+ void audioInputDestroyed() { setAudioInput(nullptr); }
+ void audioInputChanged();
+ void audioOutputDestroyed() { setAudioOutput(nullptr); }
+ void audioOutputChanged();
+
+ void setAudioInputMuted(bool muted);
+ void setAudioInputVolume(float volume);
+ void setAudioOutputMuted(bool muted);
+ void setAudioOutputVolume(float volume);
+
+private:
+ QPlatformAudioInput *m_audioInput = nullptr;
+ QPlatformAudioOutput *m_audioOutput = nullptr;
+
+ AVFCameraSession *m_session = nullptr;
+ AVFCamera *m_cameraControl = nullptr;
+ AVFMediaEncoder *m_encoder = nullptr;
+ AVFImageCapture *m_imageCaptureControl = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/darwin/camera/avfcamerasession.mm b/src/plugins/multimedia/darwin/camera/avfcamerasession.mm
new file mode 100644
index 000000000..52e2eadfa
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfcamerasession.mm
@@ -0,0 +1,513 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfcameradebug_p.h"
+#include "avfcamerasession_p.h"
+#include "avfcameraservice_p.h"
+#include "avfcamera_p.h"
+#include "avfcamerarenderer_p.h"
+#include "avfimagecapture_p.h"
+#include "avfmediaencoder_p.h"
+#include "avfcamerautility_p.h"
+#include <avfvideosink_p.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <Foundation/Foundation.h>
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qdatetime.h>
+#include <QtCore/qurl.h>
+#include <QtCore/qelapsedtimer.h>
+#include <QtCore/qpermissions.h>
+#include <QtCore/qpointer.h>
+
+#include <private/qplatformaudioinput_p.h>
+#include <private/qplatformaudiooutput_p.h>
+
+#include <QtCore/qdebug.h>
+
+QT_USE_NAMESPACE
+
+@interface AVFCameraSessionObserver : NSObject
+
+- (AVFCameraSessionObserver *) initWithCameraSession:(AVFCameraSession*)session;
+- (void) processRuntimeError:(NSNotification *)notification;
+- (void) processSessionStarted:(NSNotification *)notification;
+- (void) processSessionStopped:(NSNotification *)notification;
+
+@end
+
+@implementation AVFCameraSessionObserver
+{
+@private
+ AVFCameraSession *m_session;
+ AVCaptureSession *m_captureSession;
+}
+
+- (AVFCameraSessionObserver *) initWithCameraSession:(AVFCameraSession*)session
+{
+ if (!(self = [super init]))
+ return nil;
+
+ self->m_session = session;
+ self->m_captureSession = session->captureSession();
+
+ [m_captureSession retain];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(processRuntimeError:)
+ name:AVCaptureSessionRuntimeErrorNotification
+ object:m_captureSession];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(processSessionStarted:)
+ name:AVCaptureSessionDidStartRunningNotification
+ object:m_captureSession];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(processSessionStopped:)
+ name:AVCaptureSessionDidStopRunningNotification
+ object:m_captureSession];
+
+ return self;
+}
+
+- (void) dealloc
+{
+ [[NSNotificationCenter defaultCenter] removeObserver:self
+ name:AVCaptureSessionRuntimeErrorNotification
+ object:m_captureSession];
+
+ [[NSNotificationCenter defaultCenter] removeObserver:self
+ name:AVCaptureSessionDidStartRunningNotification
+ object:m_captureSession];
+
+ [[NSNotificationCenter defaultCenter] removeObserver:self
+ name:AVCaptureSessionDidStopRunningNotification
+ object:m_captureSession];
+ [m_captureSession release];
+ [super dealloc];
+}
+
+- (void) processRuntimeError:(NSNotification *)notification
+{
+ Q_UNUSED(notification);
+ QMetaObject::invokeMethod(m_session, "processRuntimeError", Qt::AutoConnection);
+}
+
+- (void) processSessionStarted:(NSNotification *)notification
+{
+ Q_UNUSED(notification);
+ QMetaObject::invokeMethod(m_session, "processSessionStarted", Qt::AutoConnection);
+}
+
+- (void) processSessionStopped:(NSNotification *)notification
+{
+ Q_UNUSED(notification);
+ QMetaObject::invokeMethod(m_session, "processSessionStopped", Qt::AutoConnection);
+}
+
+@end
+
+AVFCameraSession::AVFCameraSession(AVFCameraService *service, QObject *parent)
+ : QObject(parent)
+ , m_service(service)
+ , m_defaultCodec(0)
+{
+ m_captureSession = [[AVCaptureSession alloc] init];
+ m_observer = [[AVFCameraSessionObserver alloc] initWithCameraSession:this];
+}
+
+AVFCameraSession::~AVFCameraSession()
+{
+ if (m_videoInput) {
+ [m_captureSession removeInput:m_videoInput];
+ [m_videoInput release];
+ }
+
+ if (m_audioInput) {
+ [m_captureSession removeInput:m_audioInput];
+ [m_audioInput release];
+ }
+
+ if (m_audioOutput) {
+ [m_captureSession removeOutput:m_audioOutput];
+ [m_audioOutput release];
+ }
+
+ if (m_videoOutput)
+ delete m_videoOutput;
+
+ [m_observer release];
+ [m_captureSession release];
+}
+
+void AVFCameraSession::setActiveCamera(const QCameraDevice &info)
+{
+ if (m_activeCameraDevice != info) {
+ m_activeCameraDevice = info;
+
+ if (checkCameraPermission())
+ updateVideoInput();
+ }
+}
+
+void AVFCameraSession::setCameraFormat(const QCameraFormat &format)
+{
+ if (m_cameraFormat == format)
+ return;
+
+ updateCameraFormat(format);
+}
+
+QCameraFormat AVFCameraSession::cameraFormat() const
+{
+ return m_cameraFormat;
+}
+
+void AVFCameraSession::updateCameraFormat(const QCameraFormat &format)
+{
+ m_cameraFormat = format;
+
+ AVCaptureDevice *captureDevice = videoCaptureDevice();
+ if (!captureDevice)
+ return;
+
+ AVCaptureDeviceFormat *newFormat = qt_convert_to_capture_device_format(captureDevice, format);
+ if (newFormat)
+ qt_set_active_format(captureDevice, newFormat, false);
+}
+
+void AVFCameraSession::setVideoOutput(AVFCameraRenderer *output)
+{
+ if (m_videoOutput == output)
+ return;
+
+ delete m_videoOutput;
+ m_videoOutput = output;
+ if (output)
+ output->configureAVCaptureSession(this);
+}
+
+void AVFCameraSession::addAudioCapture()
+{
+ if (!m_audioOutput) {
+ m_audioOutput = [[AVCaptureAudioDataOutput alloc] init];
+ if (m_audioOutput && [m_captureSession canAddOutput:m_audioOutput]) {
+ [m_captureSession addOutput:m_audioOutput];
+ } else {
+ qWarning() << Q_FUNC_INFO << "failed to add audio output";
+ }
+ }
+}
+
+AVCaptureDevice *AVFCameraSession::videoCaptureDevice() const
+{
+ if (m_videoInput)
+ return m_videoInput.device;
+
+ return nullptr;
+}
+
+AVCaptureDevice *AVFCameraSession::audioCaptureDevice() const
+{
+ if (m_audioInput)
+ return m_audioInput.device;
+
+ return nullptr;
+}
+
+void AVFCameraSession::setAudioInputVolume(float volume)
+{
+ m_inputVolume = volume;
+
+ if (m_inputMuted)
+ volume = 0.0;
+
+#ifdef Q_OS_MACOS
+ AVCaptureConnection *audioInputConnection = [m_audioOutput connectionWithMediaType:AVMediaTypeAudio];
+ NSArray<AVCaptureAudioChannel *> *audioChannels = audioInputConnection.audioChannels;
+ if (audioChannels) {
+ for (AVCaptureAudioChannel *channel in audioChannels) {
+ channel.volume = volume;
+ }
+ }
+#endif
+}
+
+void AVFCameraSession::setAudioInputMuted(bool muted)
+{
+ m_inputMuted = muted;
+ setAudioInputVolume(m_inputVolume);
+}
+
+void AVFCameraSession::setAudioOutputVolume(float volume)
+{
+ if (m_audioPreviewDelegate)
+ [m_audioPreviewDelegate setVolume:volume];
+}
+
+void AVFCameraSession::setAudioOutputMuted(bool muted)
+{
+ if (m_audioPreviewDelegate)
+ [m_audioPreviewDelegate setMuted:muted];
+}
+
+bool AVFCameraSession::isActive() const
+{
+ return m_active;
+}
+
+void AVFCameraSession::setActive(bool active)
+{
+ if (m_active == active)
+ return;
+
+ m_active = active;
+
+ qCDebug(qLcCamera) << Q_FUNC_INFO << m_active << " -> " << active;
+
+ if (active) {
+ if (!m_activeCameraDevice.isNull()) {
+ Q_EMIT readyToConfigureConnections();
+ m_defaultCodec = 0;
+ defaultCodec();
+ }
+
+ applyImageEncoderSettings();
+
+ // According to the doc, the capture device must be locked before
+ // startRunning to prevent the format we set to be overridden by the
+ // session preset.
+ [videoCaptureDevice() lockForConfiguration:nil];
+ [m_captureSession startRunning];
+ [videoCaptureDevice() unlockForConfiguration];
+ } else {
+ [m_captureSession stopRunning];
+ }
+}
+
+void AVFCameraSession::processRuntimeError()
+{
+ qWarning() << tr("Runtime camera error");
+ m_active = false;
+ Q_EMIT error(QCamera::CameraError, tr("Runtime camera error"));
+}
+
+void AVFCameraSession::processSessionStarted()
+{
+ qCDebug(qLcCamera) << Q_FUNC_INFO;
+ if (!m_active) {
+ m_active = true;
+ Q_EMIT activeChanged(m_active);
+ }
+}
+
+void AVFCameraSession::processSessionStopped()
+{
+ qCDebug(qLcCamera) << Q_FUNC_INFO;
+ if (m_active) {
+ m_active = false;
+ Q_EMIT activeChanged(m_active);
+ }
+}
+
+AVCaptureDevice *AVFCameraSession::createVideoCaptureDevice()
+{
+ AVCaptureDevice *device = nullptr;
+
+ QByteArray deviceId = m_activeCameraDevice.id();
+ if (!deviceId.isEmpty()) {
+ device = [AVCaptureDevice deviceWithUniqueID:
+ [NSString stringWithUTF8String:
+ deviceId.constData()]];
+ }
+
+ return device;
+}
+
+AVCaptureDevice *AVFCameraSession::createAudioCaptureDevice()
+{
+ AVCaptureDevice *device = nullptr;
+
+ QByteArray deviceId = m_service->audioInput() ? m_service->audioInput()->device.id()
+ : QByteArray();
+ if (!deviceId.isEmpty())
+ device = [AVCaptureDevice deviceWithUniqueID: [NSString stringWithUTF8String:deviceId.constData()]];
+
+ return device;
+}
+
+void AVFCameraSession::attachVideoInputDevice()
+{
+ if (!checkCameraPermission())
+ return;
+
+ if (m_videoInput) {
+ [m_captureSession removeInput:m_videoInput];
+ [m_videoInput release];
+ m_videoInput = nullptr;
+ }
+
+ AVCaptureDevice *videoDevice = createVideoCaptureDevice();
+ if (!videoDevice)
+ return;
+
+ m_videoInput = [AVCaptureDeviceInput
+ deviceInputWithDevice:videoDevice
+ error:nil];
+ if (m_videoInput && [m_captureSession canAddInput:m_videoInput]) {
+ [m_videoInput retain];
+ [m_captureSession addInput:m_videoInput];
+ } else {
+ qWarning() << "Failed to create video device input";
+ }
+}
+
+void AVFCameraSession::attachAudioInputDevice()
+{
+ if (m_audioInput) {
+ [m_captureSession removeInput:m_audioInput];
+ [m_audioInput release];
+ m_audioInput = nullptr;
+ }
+
+ AVCaptureDevice *audioDevice = createAudioCaptureDevice();
+ if (!audioDevice)
+ return;
+
+ m_audioInput = [AVCaptureDeviceInput
+ deviceInputWithDevice:audioDevice
+ error:nil];
+
+ if (m_audioInput && [m_captureSession canAddInput:m_audioInput]) {
+ [m_audioInput retain];
+ [m_captureSession addInput:m_audioInput];
+ } else {
+ qWarning() << "Failed to create audio device input";
+ }
+}
+
+bool AVFCameraSession::applyImageEncoderSettings()
+{
+ if (AVFImageCapture *control = m_service->avfImageCaptureControl())
+ return control->applySettings();
+
+ return false;
+}
+
+FourCharCode AVFCameraSession::defaultCodec()
+{
+ if (!m_defaultCodec) {
+ if (AVCaptureDevice *device = videoCaptureDevice()) {
+ AVCaptureDeviceFormat *format = device.activeFormat;
+ if (!format || !format.formatDescription)
+ return m_defaultCodec;
+ m_defaultCodec = CMVideoFormatDescriptionGetCodecType(format.formatDescription);
+ }
+ }
+ return m_defaultCodec;
+}
+
+void AVFCameraSession::setVideoSink(QVideoSink *sink)
+{
+ auto *videoSink = sink ? static_cast<AVFVideoSink *>(sink->platformVideoSink()) : nullptr;
+
+ if (m_videoSink == videoSink)
+ return;
+
+ m_videoSink = videoSink;
+
+ updateVideoOutput();
+}
+
+void AVFCameraSession::updateVideoInput()
+{
+ auto recorder = m_service->recorderControl();
+ if (recorder && recorder->state() == QMediaRecorder::RecordingState)
+ recorder->toggleRecord(false);
+
+ [m_captureSession beginConfiguration];
+
+ attachVideoInputDevice();
+ if (!m_activeCameraDevice.isNull() && !m_videoOutput) {
+ setVideoOutput(new AVFCameraRenderer(this));
+ connect(m_videoOutput, &AVFCameraRenderer::newViewfinderFrame,
+ this, &AVFCameraSession::newViewfinderFrame);
+ updateVideoOutput();
+ }
+ if (m_videoOutput)
+ m_videoOutput->deviceOrientationChanged();
+
+ [m_captureSession commitConfiguration];
+
+ if (recorder && recorder->state() == QMediaRecorder::RecordingState)
+ recorder->toggleRecord(true);
+ Q_EMIT readyToConfigureConnections();
+}
+
+void AVFCameraSession::updateAudioInput()
+{
+ if (!checkMicrophonePermission())
+ return;
+
+ auto recorder = m_service->recorderControl();
+ if (recorder && recorder->state() == QMediaRecorder::RecordingState)
+ recorder->toggleRecord(false);
+
+ [m_captureSession beginConfiguration];
+ if (m_audioOutput) {
+ AVCaptureConnection *lastConnection = [m_audioOutput connectionWithMediaType:AVMediaTypeAudio];
+ [m_captureSession removeConnection:lastConnection];
+ }
+ attachAudioInputDevice();
+ if (m_audioInput)
+ addAudioCapture();
+ [m_captureSession commitConfiguration];
+
+ if (recorder && recorder->state() == QMediaRecorder::RecordingState)
+ recorder->toggleRecord(true);
+}
+
+void AVFCameraSession::updateAudioOutput()
+{
+ QByteArray deviceId = m_service->audioOutput()
+ ? m_service->audioOutput()->device.id()
+ : QByteArray();
+
+ [m_audioPreviewDelegate release];
+ m_audioPreviewDelegate = nil;
+ if (!deviceId.isEmpty()) {
+ m_audioPreviewDelegate = [[AVFAudioPreviewDelegate alloc] init];
+ [m_audioPreviewDelegate setupWithCaptureSession:this
+ audioOutputDevice:[NSString stringWithUTF8String:
+ deviceId.constData()]];
+ }
+}
+
+void AVFCameraSession::updateVideoOutput()
+{
+ if (m_videoOutput)
+ m_videoOutput->setVideoSink(m_videoSink);
+}
+
+bool AVFCameraSession::checkCameraPermission()
+{
+ const QCameraPermission permission;
+ const bool granted = qApp->checkPermission(permission) == Qt::PermissionStatus::Granted;
+ if (!granted)
+ qWarning() << "Access to camera not granted";
+
+ return granted;
+}
+
+bool AVFCameraSession::checkMicrophonePermission()
+{
+ const QMicrophonePermission permission;
+ const bool granted = qApp->checkPermission(permission) == Qt::PermissionStatus::Granted;
+ if (!granted)
+ qWarning() << "Access to microphone not granted";
+
+ return granted;
+}
+
+#include "moc_avfcamerasession_p.cpp"
diff --git a/src/plugins/multimedia/darwin/camera/avfcamerasession_p.h b/src/plugins/multimedia/darwin/camera/avfcamerasession_p.h
new file mode 100644
index 000000000..76e31ab48
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfcamerasession_p.h
@@ -0,0 +1,132 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFCAMERASESSION_H
+#define AVFCAMERASESSION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qmutex.h>
+#include <QtMultimedia/qcamera.h>
+#include <QVideoFrame>
+#include <qcameradevice.h>
+#include "avfaudiopreviewdelegate_p.h"
+
+#import <AVFoundation/AVFoundation.h>
+
+@class AVFCameraSessionObserver;
+
+QT_BEGIN_NAMESPACE
+
+class AVFCamera;
+class AVFCameraService;
+class AVFCameraRenderer;
+class AVFVideoSink;
+class QVideoSink;
+
+class AVFCameraSession : public QObject
+{
+ Q_OBJECT
+public:
+ AVFCameraSession(AVFCameraService *service, QObject *parent = nullptr);
+ ~AVFCameraSession();
+
+ QCameraDevice activecameraDevice() const { return m_activeCameraDevice; }
+ void setActiveCamera(const QCameraDevice &info);
+
+ void setCameraFormat(const QCameraFormat &format);
+ QCameraFormat cameraFormat() const;
+
+ AVFCameraRenderer *videoOutput() const { return m_videoOutput; }
+ AVCaptureAudioDataOutput *audioOutput() const { return m_audioOutput; }
+ AVFAudioPreviewDelegate *audioPreviewDelegate() const { return m_audioPreviewDelegate; }
+
+ AVCaptureSession *captureSession() const { return m_captureSession; }
+ AVCaptureDevice *videoCaptureDevice() const;
+ AVCaptureDevice *audioCaptureDevice() const;
+
+ bool isActive() const;
+
+ FourCharCode defaultCodec();
+
+ AVCaptureDeviceInput *videoInput() const { return m_videoInput; }
+ AVCaptureDeviceInput *audioInput() const { return m_audioInput; }
+
+ void setVideoSink(QVideoSink *sink);
+
+ void updateVideoInput();
+
+ void updateAudioInput();
+ void updateAudioOutput();
+
+public Q_SLOTS:
+ void setActive(bool active);
+
+ void setAudioInputVolume(float volume);
+ void setAudioInputMuted(bool muted);
+ void setAudioOutputMuted(bool muted);
+ void setAudioOutputVolume(float volume);
+
+ void processRuntimeError();
+ void processSessionStarted();
+ void processSessionStopped();
+
+Q_SIGNALS:
+ void readyToConfigureConnections();
+ void activeChanged(bool);
+ void error(int error, const QString &errorString);
+ void newViewfinderFrame(const QVideoFrame &frame);
+
+private:
+ void updateCameraFormat(const QCameraFormat &format);
+
+ void setVideoOutput(AVFCameraRenderer *output);
+ void updateVideoOutput();
+
+ void addAudioCapture();
+
+ AVCaptureDevice *createVideoCaptureDevice();
+ AVCaptureDevice *createAudioCaptureDevice();
+ void attachVideoInputDevice();
+ void attachAudioInputDevice();
+ bool checkCameraPermission();
+ bool checkMicrophonePermission();
+
+ bool applyImageEncoderSettings();
+
+ QCameraDevice m_activeCameraDevice;
+ QCameraFormat m_cameraFormat;
+
+ AVFCameraService *m_service;
+ AVCaptureSession *m_captureSession;
+ AVFCameraSessionObserver *m_observer;
+
+ AVFCameraRenderer *m_videoOutput = nullptr;
+ AVFVideoSink *m_videoSink = nullptr;
+
+ AVCaptureDeviceInput *m_videoInput = nullptr;
+ AVCaptureDeviceInput *m_audioInput = nullptr;
+
+ AVCaptureAudioDataOutput *m_audioOutput = nullptr;
+ AVFAudioPreviewDelegate *m_audioPreviewDelegate = nullptr;
+
+ bool m_active = false;
+
+ float m_inputVolume = 1.0;
+ bool m_inputMuted = false;
+
+ FourCharCode m_defaultCodec;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/darwin/camera/avfcamerautility.mm b/src/plugins/multimedia/darwin/camera/avfcamerautility.mm
new file mode 100644
index 000000000..0306a31ef
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfcamerautility.mm
@@ -0,0 +1,729 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfcamerautility_p.h"
+#include "avfcameradebug_p.h"
+
+#include <QtCore/qvector.h>
+#include <QtCore/qpair.h>
+#include <private/qmultimediautils_p.h>
+#include <private/qcameradevice_p.h>
+#include "avfvideobuffer_p.h"
+#include "qavfhelpers_p.h"
+
+#include <functional>
+#include <algorithm>
+#include <limits>
+#include <tuple>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(qLcCamera, "qt.multimedia.camera")
+
+AVFPSRange qt_connection_framerates(AVCaptureConnection *videoConnection)
+{
+ Q_ASSERT(videoConnection);
+
+ AVFPSRange newRange;
+ // "The value in the videoMinFrameDuration is equivalent to the reciprocal
+ // of the maximum framerate, the value in the videoMaxFrameDuration is equivalent
+ // to the reciprocal of the minimum framerate."
+ if (videoConnection.supportsVideoMinFrameDuration) {
+ const CMTime cmMin = videoConnection.videoMinFrameDuration;
+ if (CMTimeCompare(cmMin, kCMTimeInvalid)) { // Has some non-default value:
+ if (const Float64 minSeconds = CMTimeGetSeconds(cmMin))
+ newRange.second = 1. / minSeconds;
+ }
+ }
+
+ if (videoConnection.supportsVideoMaxFrameDuration) {
+ const CMTime cmMax = videoConnection.videoMaxFrameDuration;
+ if (CMTimeCompare(cmMax, kCMTimeInvalid)) {
+ if (const Float64 maxSeconds = CMTimeGetSeconds(cmMax))
+ newRange.first = 1. / maxSeconds;
+ }
+ }
+
+ return newRange;
+}
+
+namespace {
+
+inline bool qt_area_sane(const QSize &size)
+{
+ return !size.isNull() && size.isValid()
+ && std::numeric_limits<int>::max() / size.width() >= size.height();
+}
+
+template <template <typename...> class Comp> // std::less or std::greater (or std::equal_to)
+struct ByResolution
+{
+ bool operator() (AVCaptureDeviceFormat *f1, AVCaptureDeviceFormat *f2)const
+ {
+ Q_ASSERT(f1 && f2);
+ const QSize r1(qt_device_format_resolution(f1));
+ const QSize r2(qt_device_format_resolution(f2));
+ // use std::tuple for lexicograpical sorting:
+ const Comp<std::tuple<int, int>> op = {};
+ return op(std::make_tuple(r1.width(), r1.height()),
+ std::make_tuple(r2.width(), r2.height()));
+ }
+};
+
+struct FormatHasNoFPSRange
+{
+ bool operator() (AVCaptureDeviceFormat *format) const
+ {
+ Q_ASSERT(format);
+ return !format.videoSupportedFrameRateRanges || !format.videoSupportedFrameRateRanges.count;
+ }
+};
+
+Float64 qt_find_min_framerate_distance(AVCaptureDeviceFormat *format, Float64 fps)
+{
+ Q_ASSERT(format && format.videoSupportedFrameRateRanges
+ && format.videoSupportedFrameRateRanges.count);
+
+ AVFrameRateRange *range = [format.videoSupportedFrameRateRanges objectAtIndex:0];
+ Float64 distance = qAbs(range.maxFrameRate - fps);
+ for (NSUInteger i = 1, e = format.videoSupportedFrameRateRanges.count; i < e; ++i) {
+ range = [format.videoSupportedFrameRateRanges objectAtIndex:i];
+ distance = qMin(distance, qAbs(range.maxFrameRate - fps));
+ }
+
+ return distance;
+}
+
+} // Unnamed namespace.
+
+AVCaptureDeviceFormat *
+qt_convert_to_capture_device_format(AVCaptureDevice *captureDevice,
+ const QCameraFormat &cameraFormat,
+ const std::function<bool(uint32_t)> &cvFormatValidator)
+{
+ const auto cameraFormatPrivate = QCameraFormatPrivate::handle(cameraFormat);
+ if (!cameraFormatPrivate)
+ return nil;
+
+ const auto requiredCvPixFormat = QAVFHelpers::toCVPixelFormat(cameraFormatPrivate->pixelFormat,
+ cameraFormatPrivate->colorRange);
+
+ if (requiredCvPixFormat == CvPixelFormatInvalid)
+ return nil;
+
+ AVCaptureDeviceFormat *newFormat = nil;
+ Float64 newFormatMaxFrameRate = {};
+ NSArray<AVCaptureDeviceFormat *> *formats = captureDevice.formats;
+ for (AVCaptureDeviceFormat *format in formats) {
+ CMFormatDescriptionRef formatDesc = format.formatDescription;
+ CMVideoDimensions dim = CMVideoFormatDescriptionGetDimensions(formatDesc);
+ FourCharCode cvPixFormat = CMVideoFormatDescriptionGetCodecType(formatDesc);
+
+ if (cvPixFormat != requiredCvPixFormat)
+ continue;
+
+ if (cameraFormatPrivate->resolution != QSize(dim.width, dim.height))
+ continue;
+
+ if (cvFormatValidator && !cvFormatValidator(cvPixFormat))
+ continue;
+
+ for (AVFrameRateRange *frameRateRange in format.videoSupportedFrameRateRanges) {
+ if (frameRateRange.minFrameRate >= cameraFormatPrivate->minFrameRate
+ && frameRateRange.maxFrameRate <= cameraFormatPrivate->maxFrameRate
+ && newFormatMaxFrameRate < frameRateRange.maxFrameRate) {
+ newFormat = format;
+ newFormatMaxFrameRate = frameRateRange.maxFrameRate;
+ }
+ }
+ }
+ return newFormat;
+}
+
+QVector<AVCaptureDeviceFormat *> qt_unique_device_formats(AVCaptureDevice *captureDevice, FourCharCode filter)
+{
+ // 'filter' is the format we prefer if we have duplicates.
+ Q_ASSERT(captureDevice);
+
+ QVector<AVCaptureDeviceFormat *> formats;
+
+ if (!captureDevice.formats || !captureDevice.formats.count)
+ return formats;
+
+ formats.reserve(captureDevice.formats.count);
+ for (AVCaptureDeviceFormat *format in captureDevice.formats) {
+ const QSize resolution(qt_device_format_resolution(format));
+ if (resolution.isNull() || !resolution.isValid())
+ continue;
+ formats << format;
+ }
+
+ if (!formats.size())
+ return formats;
+
+ std::sort(formats.begin(), formats.end(), ByResolution<std::less>());
+
+ QSize size(qt_device_format_resolution(formats[0]));
+ FourCharCode codec = CMVideoFormatDescriptionGetCodecType(formats[0].formatDescription);
+ int last = 0;
+ for (int i = 1; i < formats.size(); ++i) {
+ const QSize nextSize(qt_device_format_resolution(formats[i]));
+ if (nextSize == size) {
+ if (codec == filter)
+ continue;
+ formats[last] = formats[i];
+ } else {
+ ++last;
+ formats[last] = formats[i];
+ size = nextSize;
+ }
+ codec = CMVideoFormatDescriptionGetCodecType(formats[i].formatDescription);
+ }
+ formats.resize(last + 1);
+
+ return formats;
+}
+
+QSize qt_device_format_resolution(AVCaptureDeviceFormat *format)
+{
+ if (!format || !format.formatDescription)
+ return QSize();
+
+ const CMVideoDimensions res = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
+ return QSize(res.width, res.height);
+}
+
+QSize qt_device_format_high_resolution(AVCaptureDeviceFormat *format)
+{
+ Q_ASSERT(format);
+ QSize res;
+#if defined(Q_OS_IOS)
+ const CMVideoDimensions hrDim(format.highResolutionStillImageDimensions);
+ res.setWidth(hrDim.width);
+ res.setHeight(hrDim.height);
+#endif
+ return res;
+}
+
+QVector<AVFPSRange> qt_device_format_framerates(AVCaptureDeviceFormat *format)
+{
+ Q_ASSERT(format);
+
+ QVector<AVFPSRange> qtRanges;
+
+ if (!format.videoSupportedFrameRateRanges || !format.videoSupportedFrameRateRanges.count)
+ return qtRanges;
+
+ qtRanges.reserve(format.videoSupportedFrameRateRanges.count);
+ for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges)
+ qtRanges << AVFPSRange(range.minFrameRate, range.maxFrameRate);
+
+ return qtRanges;
+}
+
+QSize qt_device_format_pixel_aspect_ratio(AVCaptureDeviceFormat *format)
+{
+ Q_ASSERT(format);
+
+ if (!format.formatDescription) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "no format description found";
+ return QSize();
+ }
+
+ const CMVideoDimensions res = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
+ const CGSize resPAR = CMVideoFormatDescriptionGetPresentationDimensions(format.formatDescription, true, false);
+
+ if (qAbs(resPAR.width - res.width) < 1.) {
+ // "Pixel aspect ratio is used to adjust the width, leaving the height alone."
+ return QSize(1, 1);
+ }
+
+ if (!res.width || !resPAR.width)
+ return QSize();
+
+ auto frac = qRealToFraction(resPAR.width > res.width ? res.width / qreal(resPAR.width)
+ : resPAR.width / qreal(res.width));
+
+ return QSize(frac.numerator, frac.denominator);
+}
+
+AVCaptureDeviceFormat *qt_find_best_resolution_match(AVCaptureDevice *captureDevice,
+ const QSize &request,
+ FourCharCode filter,
+ bool stillImage)
+{
+ Q_ASSERT(captureDevice);
+ Q_ASSERT(!request.isNull() && request.isValid());
+
+ if (!captureDevice.formats || !captureDevice.formats.count)
+ return nullptr;
+
+ QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(captureDevice, filter));
+
+ for (int i = 0; i < formats.size(); ++i) {
+ AVCaptureDeviceFormat *format = formats[i];
+ if (qt_device_format_resolution(format) == request)
+ return format;
+ // iOS only (still images).
+ if (stillImage && qt_device_format_high_resolution(format) == request)
+ return format;
+ }
+
+ if (!qt_area_sane(request))
+ return nullptr;
+
+ typedef QPair<QSize, AVCaptureDeviceFormat *> FormatPair;
+
+ QVector<FormatPair> pairs; // default|HR sizes
+ pairs.reserve(formats.size());
+
+ for (int i = 0; i < formats.size(); ++i) {
+ AVCaptureDeviceFormat *format = formats[i];
+ const QSize res(qt_device_format_resolution(format));
+ if (!res.isNull() && res.isValid() && qt_area_sane(res))
+ pairs << FormatPair(res, format);
+ const QSize highRes(qt_device_format_high_resolution(format));
+ if (stillImage && !highRes.isNull() && highRes.isValid() && qt_area_sane(highRes))
+ pairs << FormatPair(highRes, format);
+ }
+
+ if (!pairs.size())
+ return nullptr;
+
+ AVCaptureDeviceFormat *best = pairs[0].second;
+ QSize next(pairs[0].first);
+ int wDiff = qAbs(request.width() - next.width());
+ int hDiff = qAbs(request.height() - next.height());
+ const int area = request.width() * request.height();
+ int areaDiff = qAbs(area - next.width() * next.height());
+ for (int i = 1; i < pairs.size(); ++i) {
+ next = pairs[i].first;
+ const int newWDiff = qAbs(next.width() - request.width());
+ const int newHDiff = qAbs(next.height() - request.height());
+ const int newAreaDiff = qAbs(area - next.width() * next.height());
+
+ if ((newWDiff < wDiff && newHDiff < hDiff)
+ || ((newWDiff <= wDiff || newHDiff <= hDiff) && newAreaDiff <= areaDiff)) {
+ wDiff = newWDiff;
+ hDiff = newHDiff;
+ best = pairs[i].second;
+ areaDiff = newAreaDiff;
+ }
+ }
+
+ return best;
+}
+
+AVCaptureDeviceFormat *qt_find_best_framerate_match(AVCaptureDevice *captureDevice,
+ FourCharCode filter,
+ Float64 fps)
+{
+ Q_ASSERT(captureDevice);
+ Q_ASSERT(fps > 0.);
+
+ const qreal epsilon = 0.1;
+
+ QVector<AVCaptureDeviceFormat *>sorted(qt_unique_device_formats(captureDevice, filter));
+ // Sort formats by their resolution in decreasing order:
+ std::sort(sorted.begin(), sorted.end(), ByResolution<std::greater>());
+ // We can use only formats with framerate ranges:
+ sorted.erase(std::remove_if(sorted.begin(), sorted.end(), FormatHasNoFPSRange()), sorted.end());
+
+ if (!sorted.size())
+ return nil;
+
+ for (int i = 0; i < sorted.size(); ++i) {
+ AVCaptureDeviceFormat *format = sorted[i];
+ for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
+ if (range.maxFrameRate - range.minFrameRate < epsilon) {
+ // On OS X ranges are points (built-in camera).
+ if (qAbs(fps - range.maxFrameRate) < epsilon)
+ return format;
+ }
+
+ if (fps >= range.minFrameRate && fps <= range.maxFrameRate)
+ return format;
+ }
+ }
+
+ Float64 distance = qt_find_min_framerate_distance(sorted[0], fps);
+ AVCaptureDeviceFormat *match = sorted[0];
+ for (int i = 1; i < sorted.size(); ++i) {
+ const Float64 newDistance = qt_find_min_framerate_distance(sorted[i], fps);
+ if (newDistance < distance) {
+ distance = newDistance;
+ match = sorted[i];
+ }
+ }
+
+ return match;
+}
+
+AVFrameRateRange *qt_find_supported_framerate_range(AVCaptureDeviceFormat *format, Float64 fps)
+{
+ Q_ASSERT(format && format.videoSupportedFrameRateRanges
+ && format.videoSupportedFrameRateRanges.count);
+
+ const qreal epsilon = 0.1;
+
+ for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
+ if (range.maxFrameRate - range.minFrameRate < epsilon) {
+ // On OS X ranges are points (built-in camera).
+ if (qAbs(fps - range.maxFrameRate) < epsilon)
+ return range;
+ }
+
+ if (fps >= range.minFrameRate && fps <= range.maxFrameRate)
+ return range;
+ }
+
+ AVFrameRateRange *match = [format.videoSupportedFrameRateRanges objectAtIndex:0];
+ Float64 distance = qAbs(match.maxFrameRate - fps);
+ for (NSUInteger i = 1, e = format.videoSupportedFrameRateRanges.count; i < e; ++i) {
+ AVFrameRateRange *range = [format.videoSupportedFrameRateRanges objectAtIndex:i];
+ const Float64 newDistance = qAbs(range.maxFrameRate - fps);
+ if (newDistance < distance) {
+ distance = newDistance;
+ match = range;
+ }
+ }
+
+ return match;
+}
+
+bool qt_format_supports_framerate(AVCaptureDeviceFormat *format, qreal fps)
+{
+ if (format && fps > qreal(0)) {
+ const qreal epsilon = 0.1;
+ for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
+ if (fps >= range.minFrameRate - epsilon && fps <= range.maxFrameRate + epsilon)
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool qt_formats_are_equal(AVCaptureDeviceFormat *f1, AVCaptureDeviceFormat *f2)
+{
+ if (f1 == f2)
+ return true;
+
+ if (![f1.mediaType isEqualToString:f2.mediaType])
+ return false;
+
+ return CMFormatDescriptionEqual(f1.formatDescription, f2.formatDescription);
+}
+
+bool qt_set_active_format(AVCaptureDevice *captureDevice, AVCaptureDeviceFormat *format, bool preserveFps)
+{
+ static bool firstSet = true;
+
+ if (!captureDevice || !format)
+ return false;
+
+ if (qt_formats_are_equal(captureDevice.activeFormat, format)) {
+ if (firstSet) {
+ // The capture device format is persistent. The first time we set a format, report that
+ // it changed even if the formats are the same.
+ // This prevents the session from resetting the format to the default value.
+ firstSet = false;
+ return true;
+ }
+ return false;
+ }
+
+ firstSet = false;
+
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qWarning("Failed to set active format (lock failed)");
+ return false;
+ }
+
+ // Changing the activeFormat resets the frame rate.
+ AVFPSRange fps;
+ if (preserveFps)
+ fps = qt_current_framerates(captureDevice, nil);
+
+ captureDevice.activeFormat = format;
+
+ if (preserveFps)
+ qt_set_framerate_limits(captureDevice, nil, fps.first, fps.second);
+
+ return true;
+}
+
+void qt_set_framerate_limits(AVCaptureConnection *videoConnection, qreal minFPS, qreal maxFPS)
+{
+ Q_ASSERT(videoConnection);
+
+ if (minFPS < 0. || maxFPS < 0. || (maxFPS && maxFPS < minFPS)) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "invalid framerates (min, max):"
+ << minFPS << maxFPS;
+ return;
+ }
+
+ CMTime minDuration = kCMTimeInvalid;
+ if (maxFPS > 0.) {
+ if (!videoConnection.supportsVideoMinFrameDuration)
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "maximum framerate is not supported";
+ else
+ minDuration = CMTimeMake(1, maxFPS);
+ }
+ if (videoConnection.supportsVideoMinFrameDuration)
+ videoConnection.videoMinFrameDuration = minDuration;
+
+ CMTime maxDuration = kCMTimeInvalid;
+ if (minFPS > 0.) {
+ if (!videoConnection.supportsVideoMaxFrameDuration)
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "minimum framerate is not supported";
+ else
+ maxDuration = CMTimeMake(1, minFPS);
+ }
+ if (videoConnection.supportsVideoMaxFrameDuration)
+ videoConnection.videoMaxFrameDuration = maxDuration;
+}
+
+CMTime qt_adjusted_frame_duration(AVFrameRateRange *range, qreal fps)
+{
+ Q_ASSERT(range);
+ Q_ASSERT(fps > 0.);
+
+ if (range.maxFrameRate - range.minFrameRate < 0.1) {
+ // Can happen on OS X.
+ return range.minFrameDuration;
+ }
+
+ if (fps <= range.minFrameRate)
+ return range.maxFrameDuration;
+ if (fps >= range.maxFrameRate)
+ return range.minFrameDuration;
+
+ auto frac = qRealToFraction(1. / fps);
+ return CMTimeMake(frac.numerator, frac.denominator);
+}
+
+void qt_set_framerate_limits(AVCaptureDevice *captureDevice, qreal minFPS, qreal maxFPS)
+{
+ Q_ASSERT(captureDevice);
+ if (!captureDevice.activeFormat) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "no active capture device format";
+ return;
+ }
+
+ if (minFPS < 0. || maxFPS < 0. || (maxFPS && maxFPS < minFPS)) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "invalid framerates (min, max):"
+ << minFPS << maxFPS;
+ return;
+ }
+
+ CMTime minFrameDuration = kCMTimeInvalid;
+ CMTime maxFrameDuration = kCMTimeInvalid;
+ if (maxFPS || minFPS) {
+ AVFrameRateRange *range = qt_find_supported_framerate_range(captureDevice.activeFormat,
+ maxFPS ? maxFPS : minFPS);
+ if (!range) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "no framerate range found, (min, max):"
+ << minFPS << maxFPS;
+ return;
+ }
+
+ if (maxFPS)
+ minFrameDuration = qt_adjusted_frame_duration(range, maxFPS);
+ if (minFPS)
+ maxFrameDuration = qt_adjusted_frame_duration(range, minFPS);
+ }
+
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to lock for configuration";
+ return;
+ }
+
+ // While Apple's docs say kCMTimeInvalid will end in default
+ // settings for this format, kCMTimeInvalid on OS X ends with a runtime
+ // exception:
+ // "The activeVideoMinFrameDuration passed is not supported by the device."
+ // Instead, use the first item in the supported frame rates.
+#ifdef Q_OS_IOS
+ [captureDevice setActiveVideoMinFrameDuration:minFrameDuration];
+ [captureDevice setActiveVideoMaxFrameDuration:maxFrameDuration];
+#elif defined(Q_OS_MACOS)
+ if (CMTimeCompare(minFrameDuration, kCMTimeInvalid) == 0
+ && CMTimeCompare(maxFrameDuration, kCMTimeInvalid) == 0) {
+ AVFrameRateRange *range = captureDevice.activeFormat.videoSupportedFrameRateRanges.firstObject;
+ minFrameDuration = range.minFrameDuration;
+ maxFrameDuration = range.maxFrameDuration;
+ }
+
+ if (CMTimeCompare(minFrameDuration, kCMTimeInvalid))
+ [captureDevice setActiveVideoMinFrameDuration:minFrameDuration];
+
+ if (CMTimeCompare(maxFrameDuration, kCMTimeInvalid))
+ [captureDevice setActiveVideoMaxFrameDuration:maxFrameDuration];
+#endif // Q_OS_MACOS
+}
+
+void qt_set_framerate_limits(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection,
+ qreal minFPS, qreal maxFPS)
+{
+ Q_UNUSED(videoConnection);
+ Q_ASSERT(captureDevice);
+ qt_set_framerate_limits(captureDevice, minFPS, maxFPS);
+}
+
+AVFPSRange qt_current_framerates(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection)
+{
+ Q_UNUSED(videoConnection);
+ Q_ASSERT(captureDevice);
+
+ AVFPSRange fps;
+ const CMTime minDuration = captureDevice.activeVideoMinFrameDuration;
+ if (CMTimeCompare(minDuration, kCMTimeInvalid)) {
+ if (const Float64 minSeconds = CMTimeGetSeconds(minDuration))
+ fps.second = 1. / minSeconds; // Max FPS = 1 / MinDuration.
+ }
+
+ const CMTime maxDuration = captureDevice.activeVideoMaxFrameDuration;
+ if (CMTimeCompare(maxDuration, kCMTimeInvalid)) {
+ if (const Float64 maxSeconds = CMTimeGetSeconds(maxDuration))
+ fps.first = 1. / maxSeconds; // Min FPS = 1 / MaxDuration.
+ }
+
+ return fps;
+}
+
+QList<AudioValueRange> qt_supported_sample_rates_for_format(int codecId)
+{
+ QList<AudioValueRange> result;
+ UInt32 format = codecId;
+ UInt32 size;
+ OSStatus err = AudioFormatGetPropertyInfo(
+ kAudioFormatProperty_AvailableEncodeSampleRates,
+ sizeof(format),
+ &format,
+ &size);
+
+ if (err != noErr)
+ return result;
+
+ UInt32 numRanges = size / sizeof(AudioValueRange);
+ AudioValueRange sampleRanges[numRanges];
+
+ err = AudioFormatGetProperty(kAudioFormatProperty_AvailableEncodeSampleRates,
+ sizeof(format),
+ &format,
+ &size,
+ sampleRanges);
+ if (err != noErr)
+ return result;
+
+ for (UInt32 i = 0; i < numRanges; i++)
+ result << sampleRanges[i];
+
+ return result;
+}
+
+QList<AudioValueRange> qt_supported_bit_rates_for_format(int codecId)
+{
+ QList<AudioValueRange> result;
+ UInt32 format = codecId;
+ UInt32 size;
+ OSStatus err = AudioFormatGetPropertyInfo(
+ kAudioFormatProperty_AvailableEncodeBitRates,
+ sizeof(format),
+ &format,
+ &size);
+
+ if (err != noErr)
+ return result;
+
+ UInt32 numRanges = size / sizeof(AudioValueRange);
+ AudioValueRange bitRanges[numRanges];
+
+ err = AudioFormatGetProperty(kAudioFormatProperty_AvailableEncodeBitRates,
+ sizeof(format),
+ &format,
+ &size,
+ bitRanges);
+ if (err != noErr)
+ return result;
+
+ for (UInt32 i = 0; i < numRanges; i++)
+ result << bitRanges[i];
+
+ return result;
+}
+
+std::optional<QList<UInt32>> qt_supported_channel_counts_for_format(int codecId)
+{
+ QList<UInt32> result;
+ AudioStreamBasicDescription sf = {};
+ sf.mFormatID = codecId;
+ UInt32 size;
+ OSStatus err = AudioFormatGetPropertyInfo(
+ kAudioFormatProperty_AvailableEncodeNumberChannels,
+ sizeof(sf),
+ &sf,
+ &size);
+
+ if (err != noErr)
+ return result;
+
+ // From Apple's docs:
+ // A value of 0xFFFFFFFF indicates that any number of channels may be encoded.
+ if (int(size) == -1)
+ return std::nullopt;
+
+ UInt32 numCounts = size / sizeof(UInt32);
+ UInt32 channelCounts[numCounts];
+
+ err = AudioFormatGetProperty(kAudioFormatProperty_AvailableEncodeNumberChannels,
+ sizeof(sf),
+ &sf,
+ &size,
+ channelCounts);
+ if (err != noErr)
+ return result;
+
+ for (UInt32 i = 0; i < numCounts; i++)
+ result << channelCounts[i];
+
+ return result;
+}
+
+QList<UInt32> qt_supported_channel_layout_tags_for_format(int codecId, int noChannels)
+{
+ QList<UInt32> result;
+ AudioStreamBasicDescription sf = {};
+ sf.mFormatID = codecId;
+ sf.mChannelsPerFrame = noChannels;
+ UInt32 size;
+ OSStatus err = AudioFormatGetPropertyInfo(
+ kAudioFormatProperty_AvailableEncodeChannelLayoutTags,
+ sizeof(sf),
+ &sf,
+ &size);
+
+ if (err != noErr)
+ return result;
+
+ UInt32 noTags = (UInt32)size / sizeof(UInt32);
+ AudioChannelLayoutTag tagsArr[noTags];
+
+ err = AudioFormatGetProperty(kAudioFormatProperty_AvailableEncodeChannelLayoutTags,
+ sizeof(sf),
+ &sf,
+ &size,
+ tagsArr);
+ if (err != noErr)
+ return result;
+
+ for (UInt32 i = 0; i < noTags; i++)
+ result << tagsArr[i];
+
+ return result;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/darwin/camera/avfcamerautility_p.h b/src/plugins/multimedia/darwin/camera/avfcamerautility_p.h
new file mode 100644
index 000000000..b5c9e9bda
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfcamerautility_p.h
@@ -0,0 +1,165 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFCAMERAUTILITY_H
+#define AVFCAMERAUTILITY_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qpair.h>
+#include <QtCore/qsize.h>
+
+#include "qcameradevice.h"
+
+#include <AVFoundation/AVFoundation.h>
+
+// In case we have SDK below 10.7/7.0:
+@class AVCaptureDeviceFormat;
+
+QT_BEGIN_NAMESPACE
+
+class AVFConfigurationLock
+{
+public:
+ explicit AVFConfigurationLock(AVCaptureDevice *captureDevice)
+ : m_captureDevice(captureDevice),
+ m_locked(false)
+ {
+ Q_ASSERT(m_captureDevice);
+ NSError *error = nil;
+ m_locked = [m_captureDevice lockForConfiguration:&error];
+ }
+
+ ~AVFConfigurationLock()
+ {
+ if (m_locked)
+ [m_captureDevice unlockForConfiguration];
+ }
+
+ operator bool() const
+ {
+ return m_locked;
+ }
+
+private:
+ Q_DISABLE_COPY(AVFConfigurationLock)
+
+ AVCaptureDevice *m_captureDevice;
+ bool m_locked;
+};
+
+struct AVFObjectDeleter {
+ void operator()(NSObject *obj)
+ {
+ if (obj)
+ [obj release];
+ }
+};
+
+template<class T>
+class AVFScopedPointer : public std::unique_ptr<NSObject, AVFObjectDeleter>
+{
+public:
+ AVFScopedPointer() {}
+ explicit AVFScopedPointer(T *ptr) : std::unique_ptr<NSObject, AVFObjectDeleter>(ptr) {}
+ operator T*() const
+ {
+ // Quite handy operator to enable Obj-C messages: [ptr someMethod];
+ return data();
+ }
+
+ T *data() const
+ {
+ return static_cast<T *>(get());
+ }
+
+ T *take()
+ {
+ return static_cast<T *>(release());
+ }
+};
+
+template<>
+class AVFScopedPointer<dispatch_queue_t>
+{
+public:
+ AVFScopedPointer() : m_queue(nullptr) {}
+ explicit AVFScopedPointer(dispatch_queue_t q) : m_queue(q) {}
+
+ ~AVFScopedPointer()
+ {
+ if (m_queue)
+ dispatch_release(m_queue);
+ }
+
+ operator dispatch_queue_t() const
+ {
+ // Quite handy operator to enable Obj-C messages: [ptr someMethod];
+ return m_queue;
+ }
+
+ dispatch_queue_t data() const
+ {
+ return m_queue;
+ }
+
+ void reset(dispatch_queue_t q = nullptr)
+ {
+ if (m_queue)
+ dispatch_release(m_queue);
+ m_queue = q;
+ }
+
+private:
+ dispatch_queue_t m_queue;
+
+ Q_DISABLE_COPY(AVFScopedPointer)
+};
+
+typedef QPair<qreal, qreal> AVFPSRange;
+AVFPSRange qt_connection_framerates(AVCaptureConnection *videoConnection);
+
+AVCaptureDeviceFormat *qt_convert_to_capture_device_format(
+ AVCaptureDevice *captureDevice, const QCameraFormat &format,
+ const std::function<bool(uint32_t)> &cvFormatValidator = nullptr);
+QList<AVCaptureDeviceFormat *> qt_unique_device_formats(AVCaptureDevice *captureDevice,
+ FourCharCode preferredFormat);
+QSize qt_device_format_resolution(AVCaptureDeviceFormat *format);
+QSize qt_device_format_high_resolution(AVCaptureDeviceFormat *format);
+QSize qt_device_format_pixel_aspect_ratio(AVCaptureDeviceFormat *format);
+QList<AVFPSRange> qt_device_format_framerates(AVCaptureDeviceFormat *format);
+AVCaptureDeviceFormat *qt_find_best_resolution_match(AVCaptureDevice *captureDevice, const QSize &res,
+ FourCharCode preferredFormat, bool stillImage = true);
+AVCaptureDeviceFormat *qt_find_best_framerate_match(AVCaptureDevice *captureDevice,
+ FourCharCode preferredFormat,
+ Float64 fps);
+AVFrameRateRange *qt_find_supported_framerate_range(AVCaptureDeviceFormat *format, Float64 fps);
+bool qt_format_supports_framerate(AVCaptureDeviceFormat *format, qreal fps);
+
+bool qt_formats_are_equal(AVCaptureDeviceFormat *f1, AVCaptureDeviceFormat *f2);
+bool qt_set_active_format(AVCaptureDevice *captureDevice, AVCaptureDeviceFormat *format, bool preserveFps);
+
+AVFPSRange qt_current_framerates(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection);
+void qt_set_framerate_limits(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection,
+ qreal minFPS, qreal maxFPS);
+
+QList<AudioValueRange> qt_supported_sample_rates_for_format(int codecId);
+QList<AudioValueRange> qt_supported_bit_rates_for_format(int codecId);
+std::optional<QList<UInt32>> qt_supported_channel_counts_for_format(int codecId);
+QList<UInt32> qt_supported_channel_layout_tags_for_format(int codecId, int noChannels);
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/darwin/camera/avfimagecapture.mm b/src/plugins/multimedia/darwin/camera/avfimagecapture.mm
new file mode 100644
index 000000000..2ee7b0597
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfimagecapture.mm
@@ -0,0 +1,385 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfcameradebug_p.h"
+#include "avfimagecapture_p.h"
+#include "avfcameraservice_p.h"
+#include "avfcamerautility_p.h"
+#include "avfcamera_p.h"
+#include "avfcamerasession_p.h"
+#include "avfcamerarenderer_p.h"
+#include "private/qmediastoragelocation_p.h"
+#include <private/qplatformimagecapture_p.h>
+#include <private/qmemoryvideobuffer_p.h>
+#include <private/qvideoframe_p.h>
+
+#include <QtCore/qurl.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qbuffer.h>
+#include <QtConcurrent/qtconcurrentrun.h>
+#include <QtGui/qimagereader.h>
+
+#import <AVFoundation/AVFoundation.h>
+
+QT_USE_NAMESPACE
+
+AVFImageCapture::AVFImageCapture(QImageCapture *parent)
+ : QPlatformImageCapture(parent)
+{
+ m_stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
+
+ NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
+ AVVideoCodecTypeJPEG, AVVideoCodecKey, nil];
+
+ [m_stillImageOutput setOutputSettings:outputSettings];
+ [outputSettings release];
+}
+
+AVFImageCapture::~AVFImageCapture()
+{
+ [m_stillImageOutput release];
+}
+
+bool AVFImageCapture::isReadyForCapture() const
+{
+ return m_cameraControl && m_videoConnection && m_cameraControl->isActive();
+}
+
+void AVFImageCapture::updateReadyStatus()
+{
+ if (m_ready != isReadyForCapture()) {
+ m_ready = !m_ready;
+ qCDebug(qLcCamera) << "ReadyToCapture status changed:" << m_ready;
+ Q_EMIT readyForCaptureChanged(m_ready);
+ }
+}
+
+int AVFImageCapture::doCapture(const QString &actualFileName)
+{
+ if (!m_session) {
+ QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
+ Q_ARG(int, m_lastCaptureId),
+ Q_ARG(int, QImageCapture::ResourceError),
+ Q_ARG(QString, QPlatformImageCapture::msgImageCaptureNotSet()));
+ return -1;
+ }
+ if (!isReadyForCapture()) {
+ QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
+ Q_ARG(int, m_lastCaptureId),
+ Q_ARG(int, QImageCapture::NotReadyError),
+ Q_ARG(QString, QPlatformImageCapture::msgCameraNotReady()));
+ return -1;
+ }
+ m_lastCaptureId++;
+
+ bool captureToBuffer = actualFileName.isEmpty();
+
+ CaptureRequest request = { m_lastCaptureId, QSharedPointer<QSemaphore>::create()};
+ m_requestsMutex.lock();
+ m_captureRequests.enqueue(request);
+ m_requestsMutex.unlock();
+
+ QString fileName(actualFileName);
+
+ [m_stillImageOutput captureStillImageAsynchronouslyFromConnection:m_videoConnection
+ completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
+
+ if (error) {
+ QStringList messageParts;
+ messageParts << QString::fromUtf8([[error localizedDescription] UTF8String]);
+ messageParts << QString::fromUtf8([[error localizedFailureReason] UTF8String]);
+ messageParts << QString::fromUtf8([[error localizedRecoverySuggestion] UTF8String]);
+
+ QString errorMessage = messageParts.join(QChar(u' '));
+ qCDebug(qLcCamera) << "Image capture failed:" << errorMessage;
+
+ QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
+ Q_ARG(int, request.captureId),
+ Q_ARG(int, QImageCapture::ResourceError),
+ Q_ARG(QString, errorMessage));
+ return;
+ }
+
+ // Wait for the preview to be generated before saving the JPEG (but only
+ // if we have AVFCameraRenderer attached).
+ // It is possible to stop camera immediately after trying to capture an
+ // image; this can result in a blocked callback's thread, waiting for a
+ // new viewfinder's frame to arrive/semaphore to be released. It is also
+ // unspecified on which thread this callback gets executed, (probably it's
+ // not the same thread that initiated a capture and stopped the camera),
+ // so we cannot reliably check the camera's status. Instead, we wait
+ // with a timeout and treat a failure to acquire a semaphore as an error.
+ if (!m_session->videoOutput() || request.previewReady->tryAcquire(1, 1000)) {
+ qCDebug(qLcCamera) << "Image capture completed";
+
+ NSData *nsJpgData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
+ QByteArray jpgData = QByteArray::fromRawData((const char *)[nsJpgData bytes], [nsJpgData length]);
+
+ if (captureToBuffer) {
+ QBuffer data(&jpgData);
+ QImageReader reader(&data, "JPEG");
+ QSize size = reader.size();
+ auto buffer = std::make_unique<QMemoryVideoBuffer>(
+ QByteArray(jpgData.constData(), jpgData.size()), -1);
+ QVideoFrame frame = QVideoFramePrivate::createFrame(
+ std::move(buffer), QVideoFrameFormat(size, QVideoFrameFormat::Format_Jpeg));
+ QMetaObject::invokeMethod(this, "imageAvailable", Qt::QueuedConnection,
+ Q_ARG(int, request.captureId),
+ Q_ARG(QVideoFrame, frame));
+ } else {
+ QFile f(fileName);
+ if (f.open(QFile::WriteOnly)) {
+ if (f.write(jpgData) != -1) {
+ QMetaObject::invokeMethod(this, "imageSaved", Qt::QueuedConnection,
+ Q_ARG(int, request.captureId),
+ Q_ARG(QString, fileName));
+ } else {
+ QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
+ Q_ARG(int, request.captureId),
+ Q_ARG(int, QImageCapture::OutOfSpaceError),
+ Q_ARG(QString, f.errorString()));
+ }
+ } else {
+ QString errorMessage = tr("Could not open destination file:\n%1").arg(fileName);
+ QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
+ Q_ARG(int, request.captureId),
+ Q_ARG(int, QImageCapture::ResourceError),
+ Q_ARG(QString, errorMessage));
+ }
+ }
+ } else {
+ const QLatin1String errorMessage("Image capture failed: timed out waiting"
+ " for a preview frame.");
+ qCDebug(qLcCamera) << errorMessage;
+ QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
+ Q_ARG(int, request.captureId),
+ Q_ARG(int, QImageCapture::ResourceError),
+ Q_ARG(QString, errorMessage));
+ }
+ }];
+
+ return request.captureId;
+}
+
+int AVFImageCapture::capture(const QString &fileName)
+{
+ auto actualFileName = QMediaStorageLocation::generateFileName(fileName, QStandardPaths::PicturesLocation, QLatin1String("jpg"));
+
+ qCDebug(qLcCamera) << "Capture image to" << actualFileName;
+ return doCapture(actualFileName);
+}
+
+int AVFImageCapture::captureToBuffer()
+{
+ return doCapture(QString());
+}
+
+void AVFImageCapture::onNewViewfinderFrame(const QVideoFrame &frame)
+{
+ QMutexLocker locker(&m_requestsMutex);
+
+ if (m_captureRequests.isEmpty())
+ return;
+
+ CaptureRequest request = m_captureRequests.dequeue();
+ Q_EMIT imageExposed(request.captureId);
+
+ (void) QtConcurrent::run(&AVFImageCapture::makeCapturePreview, this,
+ request,
+ frame,
+ 0 /* rotation */);
+}
+
+void AVFImageCapture::onCameraChanged()
+{
+ auto camera = m_service ? static_cast<AVFCamera *>(m_service->camera()) : nullptr;
+
+ if (camera == m_cameraControl)
+ return;
+
+ m_cameraControl = camera;
+
+ if (m_cameraControl)
+ connect(m_cameraControl, SIGNAL(activeChanged(bool)), this, SLOT(updateReadyStatus()));
+ updateReadyStatus();
+}
+
+void AVFImageCapture::makeCapturePreview(CaptureRequest request,
+ const QVideoFrame &frame,
+ int rotation)
+{
+ QTransform transform;
+ transform.rotate(rotation);
+
+ Q_EMIT imageCaptured(request.captureId, frame.toImage().transformed(transform));
+
+ request.previewReady->release();
+}
+
+void AVFImageCapture::updateCaptureConnection()
+{
+ if (m_session && m_session->videoCaptureDevice()) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO;
+ AVCaptureSession *captureSession = m_session->captureSession();
+
+ if (![captureSession.outputs containsObject:m_stillImageOutput]) {
+ if ([captureSession canAddOutput:m_stillImageOutput]) {
+ [captureSession beginConfiguration];
+ // Lock the video capture device to make sure the active format is not reset
+ const AVFConfigurationLock lock(m_session->videoCaptureDevice());
+ [captureSession addOutput:m_stillImageOutput];
+ m_videoConnection = [m_stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
+ [captureSession commitConfiguration];
+ updateReadyStatus();
+ }
+ } else {
+ m_videoConnection = [m_stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
+ }
+ }
+}
+
+
+QImageEncoderSettings AVFImageCapture::imageSettings() const
+{
+ QImageEncoderSettings settings;
+
+ if (!videoCaptureDeviceIsValid())
+ return settings;
+
+ AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
+ if (!captureDevice.activeFormat) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "no active format";
+ return settings;
+ }
+
+ QSize res(qt_device_format_resolution(captureDevice.activeFormat));
+#ifdef Q_OS_IOS
+ if (!m_service->avfImageCaptureControl() || !m_service->avfImageCaptureControl()->stillImageOutput()) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "no still image output";
+ return settings;
+ }
+
+ AVCaptureStillImageOutput *stillImageOutput = m_service->avfImageCaptureControl()->stillImageOutput();
+ if (stillImageOutput.highResolutionStillImageOutputEnabled)
+ res = qt_device_format_high_resolution(captureDevice.activeFormat);
+#endif
+ if (res.isNull() || !res.isValid()) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to exctract the image resolution";
+ return settings;
+ }
+
+ settings.setResolution(res);
+ settings.setFormat(QImageCapture::JPEG);
+
+ return settings;
+}
+
+void AVFImageCapture::setImageSettings(const QImageEncoderSettings &settings)
+{
+ if (m_settings == settings)
+ return;
+
+ m_settings = settings;
+ applySettings();
+}
+
+bool AVFImageCapture::applySettings()
+{
+ if (!videoCaptureDeviceIsValid())
+ return false;
+
+ AVFCameraSession *session = m_service->session();
+ if (!session)
+ return false;
+
+ if (!m_service->imageCapture()
+ || !m_service->avfImageCaptureControl()->stillImageOutput()) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "no still image output";
+ return false;
+ }
+
+ if (m_settings.format() != QImageCapture::UnspecifiedFormat && m_settings.format() != QImageCapture::JPEG) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "unsupported format:" << m_settings.format();
+ return false;
+ }
+
+ QSize res(m_settings.resolution());
+ if (res.isNull()) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "invalid resolution:" << res;
+ return false;
+ }
+
+ if (!res.isValid()) {
+ // Invalid == default value.
+ // Here we could choose the best format available, but
+ // activeFormat is already equal to 'preset high' by default,
+ // which is good enough, otherwise we can end in some format with low framerates.
+ return false;
+ }
+
+ bool activeFormatChanged = false;
+
+ AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
+ AVCaptureDeviceFormat *match = qt_find_best_resolution_match(captureDevice, res,
+ m_service->session()->defaultCodec());
+
+ if (!match) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "unsupported resolution:" << res;
+ return false;
+ }
+
+ activeFormatChanged = qt_set_active_format(captureDevice, match, true);
+
+#ifdef Q_OS_IOS
+ AVCaptureStillImageOutput *imageOutput = m_service->avfImageCaptureControl()->stillImageOutput();
+ if (res == qt_device_format_high_resolution(captureDevice.activeFormat))
+ imageOutput.highResolutionStillImageOutputEnabled = YES;
+ else
+ imageOutput.highResolutionStillImageOutputEnabled = NO;
+#endif
+
+ return activeFormatChanged;
+}
+
+void AVFImageCapture::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ AVFCameraService *captureSession = static_cast<AVFCameraService *>(session);
+ if (m_service == captureSession)
+ return;
+
+ m_service = captureSession;
+ if (!m_service) {
+ m_session->disconnect(this);
+ if (m_cameraControl)
+ m_cameraControl->disconnect(this);
+ m_session = nullptr;
+ m_cameraControl = nullptr;
+ m_videoConnection = nil;
+ } else {
+ m_session = m_service->session();
+ Q_ASSERT(m_session);
+
+ connect(m_service, &AVFCameraService::cameraChanged, this, &AVFImageCapture::onCameraChanged);
+ connect(m_session, SIGNAL(readyToConfigureConnections()), SLOT(updateCaptureConnection()));
+ connect(m_session, &AVFCameraSession::newViewfinderFrame,
+ this, &AVFImageCapture::onNewViewfinderFrame);
+ }
+
+ updateCaptureConnection();
+ onCameraChanged();
+ updateReadyStatus();
+}
+
+bool AVFImageCapture::videoCaptureDeviceIsValid() const
+{
+ if (!m_service || !m_service->session() || !m_service->session()->videoCaptureDevice())
+ return false;
+
+ AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
+ if (!captureDevice.formats || !captureDevice.formats.count)
+ return false;
+
+ return true;
+}
+
+#include "moc_avfimagecapture_p.cpp"
diff --git a/src/plugins/multimedia/darwin/camera/avfimagecapture_p.h b/src/plugins/multimedia/darwin/camera/avfimagecapture_p.h
new file mode 100644
index 000000000..0714fa3cc
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfimagecapture_p.h
@@ -0,0 +1,81 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFCAMERAIMAGECAPTURE_H
+#define AVFCAMERAIMAGECAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#import <AVFoundation/AVFoundation.h>
+
+#include <QtCore/qqueue.h>
+#include <QtCore/qsemaphore.h>
+#include <QtCore/qsharedpointer.h>
+#include <private/qplatformimagecapture_p.h>
+#include "avfcamerasession_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class AVFImageCapture : public QPlatformImageCapture
+{
+Q_OBJECT
+public:
+ struct CaptureRequest {
+ int captureId;
+ QSharedPointer<QSemaphore> previewReady;
+ };
+
+ AVFImageCapture(QImageCapture *parent = nullptr);
+ ~AVFImageCapture();
+
+ bool isReadyForCapture() const override;
+
+ AVCaptureStillImageOutput *stillImageOutput() const {return m_stillImageOutput;}
+
+ int doCapture(const QString &fileName);
+ int capture(const QString &fileName) override;
+ int captureToBuffer() override;
+
+ QImageEncoderSettings imageSettings() const override;
+ void setImageSettings(const QImageEncoderSettings &settings) override;
+ bool applySettings();
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session);
+
+private Q_SLOTS:
+ void updateCaptureConnection();
+ void updateReadyStatus();
+ void onNewViewfinderFrame(const QVideoFrame &frame);
+ void onCameraChanged();
+
+private:
+ void makeCapturePreview(CaptureRequest request, const QVideoFrame &frame, int rotation);
+ bool videoCaptureDeviceIsValid() const;
+
+ AVFCameraService *m_service = nullptr;
+ AVFCameraSession *m_session = nullptr;
+ AVFCamera *m_cameraControl = nullptr;
+ bool m_ready = false;
+ int m_lastCaptureId = 0;
+ AVCaptureStillImageOutput *m_stillImageOutput;
+ AVCaptureConnection *m_videoConnection = nullptr;
+
+ QMutex m_requestsMutex;
+ QQueue<CaptureRequest> m_captureRequests;
+ QImageEncoderSettings m_settings;
+};
+
+Q_DECLARE_TYPEINFO(AVFImageCapture::CaptureRequest, Q_PRIMITIVE_TYPE);
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/darwin/camera/avfmediaassetwriter.mm b/src/plugins/multimedia/darwin/camera/avfmediaassetwriter.mm
new file mode 100644
index 000000000..37fc69926
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfmediaassetwriter.mm
@@ -0,0 +1,556 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfmediaencoder_p.h"
+#include "avfcamerarenderer_p.h"
+#include "avfmediaassetwriter_p.h"
+#include "avfcameraservice_p.h"
+#include "avfcamerasession_p.h"
+#include "avfcameradebug_p.h"
+#include <qdarwinformatsinfo_p.h>
+#include <avfmetadata_p.h>
+
+#include <QtCore/qmetaobject.h>
+#include <QtCore/qatomic.h>
+
+QT_USE_NAMESPACE
+
+namespace {
+
+bool qt_capture_session_isValid(AVFCameraService *service)
+{
+ if (!service || !service->session())
+ return false;
+
+ AVFCameraSession *session = service->session();
+ if (!session->captureSession())
+ return false;
+
+ if (!session->videoInput() && !session->audioInput())
+ return false;
+
+ return true;
+}
+
+enum WriterState
+{
+ WriterStateIdle,
+ WriterStateActive,
+ WriterStatePaused,
+ WriterStateAborted
+};
+
+using AVFAtomicInt64 = QAtomicInteger<qint64>;
+
+} // unnamed namespace
+
+@interface QT_MANGLE_NAMESPACE(AVFMediaAssetWriter) (PrivateAPI)
+- (bool)addWriterInputs;
+- (void)setQueues;
+- (void)updateDuration:(CMTime)newTimeStamp;
+- (CMSampleBufferRef)adjustTime:(CMSampleBufferRef)sample by:(CMTime)offset;
+@end
+
+@implementation QT_MANGLE_NAMESPACE(AVFMediaAssetWriter)
+{
+@private
+ AVFCameraService *m_service;
+
+ AVFScopedPointer<AVAssetWriterInput> m_cameraWriterInput;
+ AVFScopedPointer<AVAssetWriterInput> m_audioWriterInput;
+
+ // Queue to write sample buffers:
+ AVFScopedPointer<dispatch_queue_t> m_writerQueue;
+ // High priority serial queue for video output:
+ AVFScopedPointer<dispatch_queue_t> m_videoQueue;
+ // Serial queue for audio output:
+ AVFScopedPointer<dispatch_queue_t> m_audioQueue;
+
+ AVFScopedPointer<AVAssetWriter> m_assetWriter;
+
+ AVFMediaEncoder *m_delegate;
+
+ bool m_setStartTime;
+
+ QAtomicInt m_state;
+
+ bool m_writeFirstAudioBuffer;
+
+ CMTime m_startTime;
+ CMTime m_lastTimeStamp;
+ CMTime m_lastVideoTimestamp;
+ CMTime m_lastAudioTimestamp;
+ CMTime m_timeOffset;
+ bool m_adjustTime;
+
+ NSDictionary *m_audioSettings;
+ NSDictionary *m_videoSettings;
+
+ AVFAtomicInt64 m_durationInMs;
+}
+
+- (id)initWithDelegate:(AVFMediaEncoder *)delegate
+{
+ Q_ASSERT(delegate);
+
+ if (self = [super init]) {
+ m_delegate = delegate;
+ m_setStartTime = true;
+ m_state.storeRelaxed(WriterStateIdle);
+ m_startTime = kCMTimeInvalid;
+ m_lastTimeStamp = kCMTimeInvalid;
+ m_lastAudioTimestamp = kCMTimeInvalid;
+ m_lastVideoTimestamp = kCMTimeInvalid;
+ m_timeOffset = kCMTimeInvalid;
+ m_adjustTime = false;
+ m_durationInMs.storeRelaxed(0);
+ m_audioSettings = nil;
+ m_videoSettings = nil;
+ m_writeFirstAudioBuffer = false;
+ }
+
+ return self;
+}
+
+- (bool)setupWithFileURL:(NSURL *)fileURL
+ cameraService:(AVFCameraService *)service
+ audioSettings:(NSDictionary *)audioSettings
+ videoSettings:(NSDictionary *)videoSettings
+ fileFormat:(QMediaFormat::FileFormat)fileFormat
+ transform:(CGAffineTransform)transform
+{
+ Q_ASSERT(fileURL);
+
+ if (!qt_capture_session_isValid(service)) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "invalid capture session";
+ return false;
+ }
+
+ m_service = service;
+ m_audioSettings = audioSettings;
+ m_videoSettings = videoSettings;
+
+ AVFCameraSession *session = m_service->session();
+
+ m_writerQueue.reset(dispatch_queue_create("asset-writer-queue", DISPATCH_QUEUE_SERIAL));
+ if (!m_writerQueue) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to create an asset writer's queue";
+ return false;
+ }
+
+ m_videoQueue.reset();
+ if (session->videoInput() && session->videoOutput() && session->videoOutput()->videoDataOutput()) {
+ m_videoQueue.reset(dispatch_queue_create("video-output-queue", DISPATCH_QUEUE_SERIAL));
+ if (!m_videoQueue) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to create video queue";
+ return false;
+ }
+ dispatch_set_target_queue(m_videoQueue, dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0));
+ }
+
+ m_audioQueue.reset();
+ if (session->audioInput() && session->audioOutput()) {
+ m_audioQueue.reset(dispatch_queue_create("audio-output-queue", DISPATCH_QUEUE_SERIAL));
+ if (!m_audioQueue) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to create audio queue";
+ if (!m_videoQueue)
+ return false;
+ // But we still can write video!
+ }
+ }
+
+ auto fileType = QDarwinFormatInfo::avFileTypeForContainerFormat(fileFormat);
+ m_assetWriter.reset([[AVAssetWriter alloc] initWithURL:fileURL
+ fileType:fileType
+ error:nil]);
+ if (!m_assetWriter) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to create asset writer";
+ return false;
+ }
+
+ if (!m_videoQueue)
+ m_writeFirstAudioBuffer = true;
+
+ if (![self addWriterInputs]) {
+ m_assetWriter.reset();
+ return false;
+ }
+
+ if (m_cameraWriterInput)
+ m_cameraWriterInput.data().transform = transform;
+
+ [self setMetaData:fileType];
+
+ // Ready to start ...
+ return true;
+}
+
+- (void)setMetaData:(AVFileType)fileType
+{
+ m_assetWriter.data().metadata = AVFMetaData::toAVMetadataForFormat(m_delegate->metaData(), fileType);
+}
+
+- (void)start
+{
+ [self setQueues];
+
+ m_setStartTime = true;
+
+ m_state.storeRelease(WriterStateActive);
+
+ [m_assetWriter startWriting];
+ AVCaptureSession *session = m_service->session()->captureSession();
+ if (!session.running)
+ [session startRunning];
+}
+
+- (void)stop
+{
+ if (m_state.loadAcquire() != WriterStateActive && m_state.loadAcquire() != WriterStatePaused)
+ return;
+
+ if ([m_assetWriter status] != AVAssetWriterStatusWriting
+ && [m_assetWriter status] != AVAssetWriterStatusFailed)
+ return;
+
+ // Do this here so that -
+ // 1. '-abort' should not try calling finishWriting again and
+ // 2. async block (see below) will know if recorder control was deleted
+ // before the block's execution:
+ m_state.storeRelease(WriterStateIdle);
+ // Now, since we have to ensure no sample buffers are
+ // appended after a call to finishWriting, we must
+ // ensure writer's queue sees this change in m_state
+ // _before_ we call finishWriting:
+ dispatch_sync(m_writerQueue, ^{});
+ // Done, but now we also want to prevent video queue
+ // from updating our viewfinder:
+ if (m_videoQueue)
+ dispatch_sync(m_videoQueue, ^{});
+
+ // Now we're safe to stop:
+ [m_assetWriter finishWritingWithCompletionHandler:^{
+ // This block is async, so by the time it's executed,
+ // it's possible that render control was deleted already ...
+ if (m_state.loadAcquire() == WriterStateAborted)
+ return;
+
+ AVCaptureSession *session = m_service->session()->captureSession();
+ if (session.running)
+ [session stopRunning];
+ QMetaObject::invokeMethod(m_delegate, "assetWriterFinished", Qt::QueuedConnection);
+ }];
+}
+
+- (void)abort
+{
+ // -abort is to be called from recorder control's dtor.
+
+ if (m_state.fetchAndStoreRelease(WriterStateAborted) != WriterStateActive) {
+ // Not recording, nothing to stop.
+ return;
+ }
+
+ // From Apple's docs:
+ // "To guarantee that all sample buffers are successfully written,
+ // you must ensure that all calls to appendSampleBuffer: and
+ // appendPixelBuffer:withPresentationTime: have returned before
+ // invoking this method."
+ //
+ // The only way we can ensure this is:
+ dispatch_sync(m_writerQueue, ^{});
+ // At this point next block (if any) on the writer's queue
+ // will see m_state preventing it from any further processing.
+ if (m_videoQueue)
+ dispatch_sync(m_videoQueue, ^{});
+ // After this point video queue will not try to modify our
+ // viewfider, so we're safe to delete now.
+
+ [m_assetWriter finishWritingWithCompletionHandler:^{
+ }];
+}
+
+- (void)pause
+{
+ if (m_state.loadAcquire() != WriterStateActive)
+ return;
+ if ([m_assetWriter status] != AVAssetWriterStatusWriting)
+ return;
+
+ m_state.storeRelease(WriterStatePaused);
+ m_adjustTime = true;
+}
+
+- (void)resume
+{
+ if (m_state.loadAcquire() != WriterStatePaused)
+ return;
+ if ([m_assetWriter status] != AVAssetWriterStatusWriting)
+ return;
+
+ m_state.storeRelease(WriterStateActive);
+}
+
+- (void)setStartTimeFrom:(CMSampleBufferRef)sampleBuffer
+{
+ // Writer's queue only.
+ Q_ASSERT(m_setStartTime);
+ Q_ASSERT(sampleBuffer);
+
+ if (m_state.loadAcquire() != WriterStateActive)
+ return;
+
+ QMetaObject::invokeMethod(m_delegate, "assetWriterStarted", Qt::QueuedConnection);
+
+ m_durationInMs.storeRelease(0);
+ m_startTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
+ m_lastTimeStamp = m_startTime;
+ [m_assetWriter startSessionAtSourceTime:m_startTime];
+ m_setStartTime = false;
+}
+
+- (CMSampleBufferRef)adjustTime:(CMSampleBufferRef)sample by:(CMTime)offset
+{
+ CMItemCount count;
+ CMSampleBufferGetSampleTimingInfoArray(sample, 0, nil, &count);
+ CMSampleTimingInfo* timingInfo = (CMSampleTimingInfo*) malloc(sizeof(CMSampleTimingInfo) * count);
+ CMSampleBufferGetSampleTimingInfoArray(sample, count, timingInfo, &count);
+ for (CMItemCount i = 0; i < count; i++)
+ {
+ timingInfo[i].decodeTimeStamp = CMTimeSubtract(timingInfo[i].decodeTimeStamp, offset);
+ timingInfo[i].presentationTimeStamp = CMTimeSubtract(timingInfo[i].presentationTimeStamp, offset);
+ }
+ CMSampleBufferRef updatedBuffer;
+ CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault, sample, count, timingInfo, &updatedBuffer);
+ free(timingInfo);
+ return updatedBuffer;
+}
+
+- (void)writeVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer
+{
+ // This code is executed only on a writer's queue.
+ Q_ASSERT(sampleBuffer);
+
+ if (m_state.loadAcquire() == WriterStateActive) {
+ if (m_setStartTime)
+ [self setStartTimeFrom:sampleBuffer];
+
+ if (m_cameraWriterInput.data().readyForMoreMediaData) {
+ [self updateDuration:CMSampleBufferGetPresentationTimeStamp(sampleBuffer)];
+ [m_cameraWriterInput appendSampleBuffer:sampleBuffer];
+ }
+ }
+}
+
+- (void)writeAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer
+{
+ Q_ASSERT(sampleBuffer);
+
+ // This code is executed only on a writer's queue.
+ if (m_state.loadAcquire() == WriterStateActive) {
+ if (m_setStartTime)
+ [self setStartTimeFrom:sampleBuffer];
+
+ if (m_audioWriterInput.data().readyForMoreMediaData) {
+ [self updateDuration:CMSampleBufferGetPresentationTimeStamp(sampleBuffer)];
+ [m_audioWriterInput appendSampleBuffer:sampleBuffer];
+ }
+ }
+}
+
+- (void)captureOutput:(AVCaptureOutput *)captureOutput
+ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
+ fromConnection:(AVCaptureConnection *)connection
+{
+ Q_UNUSED(connection);
+ Q_ASSERT(m_service && m_service->session());
+
+ if (m_state.loadAcquire() != WriterStateActive && m_state.loadAcquire() != WriterStatePaused)
+ return;
+
+ if ([m_assetWriter status] != AVAssetWriterStatusWriting) {
+ if ([m_assetWriter status] == AVAssetWriterStatusFailed) {
+ NSError *error = [m_assetWriter error];
+ NSString *failureReason = error.localizedFailureReason;
+ NSString *suggestion = error.localizedRecoverySuggestion;
+ NSString *errorString = suggestion ? [failureReason stringByAppendingString:suggestion] : failureReason;
+ QMetaObject::invokeMethod(m_delegate, "assetWriterError",
+ Qt::QueuedConnection,
+ Q_ARG(QString, QString::fromNSString(errorString)));
+ }
+ return;
+ }
+
+ if (!CMSampleBufferDataIsReady(sampleBuffer)) {
+ qWarning() << Q_FUNC_INFO << "sample buffer is not ready, skipping.";
+ return;
+ }
+
+ CFRetain(sampleBuffer);
+
+ bool isVideoBuffer = true;
+ isVideoBuffer = (captureOutput != m_service->session()->audioOutput());
+ if (isVideoBuffer) {
+ // Find renderercontrol's delegate and invoke its method to
+ // show updated viewfinder's frame.
+ if (m_service->session()->videoOutput()) {
+ NSObject<AVCaptureVideoDataOutputSampleBufferDelegate> *vfDelegate =
+ (NSObject<AVCaptureVideoDataOutputSampleBufferDelegate> *)m_service->session()->videoOutput()->captureDelegate();
+ if (vfDelegate) {
+ AVCaptureOutput *output = nil;
+ AVCaptureConnection *connection = nil;
+ [vfDelegate captureOutput:output didOutputSampleBuffer:sampleBuffer fromConnection:connection];
+ }
+ }
+ } else {
+ if (m_service->session()->audioOutput()) {
+ NSObject<AVCaptureAudioDataOutputSampleBufferDelegate> *audioPreviewDelegate =
+ (NSObject<AVCaptureAudioDataOutputSampleBufferDelegate> *)m_service->session()->audioPreviewDelegate();
+ if (audioPreviewDelegate) {
+ AVCaptureOutput *output = nil;
+ AVCaptureConnection *connection = nil;
+ [audioPreviewDelegate captureOutput:output didOutputSampleBuffer:sampleBuffer fromConnection:connection];
+ }
+ }
+ }
+
+ if (m_state.loadAcquire() != WriterStateActive) {
+ CFRelease(sampleBuffer);
+ return;
+ }
+
+ if (m_adjustTime) {
+ CMTime currentTimestamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
+ CMTime lastTimestamp = isVideoBuffer ? m_lastVideoTimestamp : m_lastAudioTimestamp;
+
+ if (!CMTIME_IS_INVALID(lastTimestamp)) {
+ if (!CMTIME_IS_INVALID(m_timeOffset))
+ currentTimestamp = CMTimeSubtract(currentTimestamp, m_timeOffset);
+
+ CMTime pauseDuration = CMTimeSubtract(currentTimestamp, lastTimestamp);
+
+ if (m_timeOffset.value == 0)
+ m_timeOffset = pauseDuration;
+ else
+ m_timeOffset = CMTimeAdd(m_timeOffset, pauseDuration);
+ }
+ m_lastVideoTimestamp = kCMTimeInvalid;
+ m_adjustTime = false;
+ }
+
+ if (m_timeOffset.value > 0) {
+ CFRelease(sampleBuffer);
+ sampleBuffer = [self adjustTime:sampleBuffer by:m_timeOffset];
+ }
+
+ CMTime currentTimestamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
+ CMTime currentDuration = CMSampleBufferGetDuration(sampleBuffer);
+ if (currentDuration.value > 0)
+ currentTimestamp = CMTimeAdd(currentTimestamp, currentDuration);
+
+ if (isVideoBuffer)
+ {
+ m_lastVideoTimestamp = currentTimestamp;
+ dispatch_async(m_writerQueue, ^{
+ [self writeVideoSampleBuffer:sampleBuffer];
+ m_writeFirstAudioBuffer = true;
+ CFRelease(sampleBuffer);
+ });
+ } else if (m_writeFirstAudioBuffer) {
+ m_lastAudioTimestamp = currentTimestamp;
+ dispatch_async(m_writerQueue, ^{
+ [self writeAudioSampleBuffer:sampleBuffer];
+ CFRelease(sampleBuffer);
+ });
+ }
+}
+
+- (bool)addWriterInputs
+{
+ Q_ASSERT(m_service && m_service->session());
+ Q_ASSERT(m_assetWriter.data());
+
+ AVFCameraSession *session = m_service->session();
+
+ m_cameraWriterInput.reset();
+ if (m_videoQueue)
+ {
+ Q_ASSERT(session->videoCaptureDevice() && session->videoOutput() && session->videoOutput()->videoDataOutput());
+ m_cameraWriterInput.reset([[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeVideo
+ outputSettings:m_videoSettings
+ sourceFormatHint:session->videoCaptureDevice().activeFormat.formatDescription]);
+
+ if (m_cameraWriterInput && [m_assetWriter canAddInput:m_cameraWriterInput]) {
+ [m_assetWriter addInput:m_cameraWriterInput];
+ } else {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to add camera writer input";
+ m_cameraWriterInput.reset();
+ return false;
+ }
+
+ m_cameraWriterInput.data().expectsMediaDataInRealTime = YES;
+ }
+
+ m_audioWriterInput.reset();
+ if (m_audioQueue) {
+ m_audioWriterInput.reset([[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeAudio
+ outputSettings:m_audioSettings]);
+ if (!m_audioWriterInput) {
+ qWarning() << Q_FUNC_INFO << "failed to create audio writer input";
+ // But we still can record video.
+ if (!m_cameraWriterInput)
+ return false;
+ } else if ([m_assetWriter canAddInput:m_audioWriterInput]) {
+ [m_assetWriter addInput:m_audioWriterInput];
+ m_audioWriterInput.data().expectsMediaDataInRealTime = YES;
+ } else {
+ qWarning() << Q_FUNC_INFO << "failed to add audio writer input";
+ m_audioWriterInput.reset();
+ if (!m_cameraWriterInput)
+ return false;
+ // We can (still) write video though ...
+ }
+ }
+
+ return true;
+}
+
+- (void)setQueues
+{
+ Q_ASSERT(m_service && m_service->session());
+ AVFCameraSession *session = m_service->session();
+
+ if (m_videoQueue) {
+ Q_ASSERT(session->videoOutput() && session->videoOutput()->videoDataOutput());
+ [session->videoOutput()->videoDataOutput() setSampleBufferDelegate:self queue:m_videoQueue];
+ }
+
+ if (m_audioQueue) {
+ Q_ASSERT(session->audioOutput());
+ [session->audioOutput() setSampleBufferDelegate:self queue:m_audioQueue];
+ }
+}
+
+- (void)updateDuration:(CMTime)newTimeStamp
+{
+ Q_ASSERT(CMTimeCompare(m_startTime, kCMTimeInvalid));
+ Q_ASSERT(CMTimeCompare(m_lastTimeStamp, kCMTimeInvalid));
+ if (CMTimeCompare(newTimeStamp, m_lastTimeStamp) > 0) {
+
+ const CMTime duration = CMTimeSubtract(newTimeStamp, m_startTime);
+ if (!CMTimeCompare(duration, kCMTimeInvalid))
+ return;
+
+ m_durationInMs.storeRelease(CMTimeGetSeconds(duration) * 1000);
+ m_lastTimeStamp = newTimeStamp;
+
+ m_delegate->updateDuration([self durationInMs]);
+ }
+}
+
+- (qint64)durationInMs
+{
+ return m_durationInMs.loadAcquire();
+}
+
+@end
diff --git a/src/plugins/multimedia/darwin/camera/avfmediaassetwriter_p.h b/src/plugins/multimedia/darwin/camera/avfmediaassetwriter_p.h
new file mode 100644
index 000000000..8fe3e8522
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfmediaassetwriter_p.h
@@ -0,0 +1,54 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFMEDIAASSETWRITER_H
+#define AVFMEDIAASSETWRITER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "avfcamerautility_p.h"
+#include "qmediaformat.h"
+
+#include <QtCore/qglobal.h>
+
+#include <AVFoundation/AVFoundation.h>
+
+QT_BEGIN_NAMESPACE
+
+class AVFMediaEncoder;
+class AVFCameraService;
+
+QT_END_NAMESPACE
+
+@interface QT_MANGLE_NAMESPACE(AVFMediaAssetWriter) : NSObject<AVCaptureVideoDataOutputSampleBufferDelegate,
+ AVCaptureAudioDataOutputSampleBufferDelegate>
+- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(AVFMediaEncoder) *)delegate;
+
+- (bool)setupWithFileURL:(NSURL *)fileURL
+ cameraService:(QT_PREPEND_NAMESPACE(AVFCameraService) *)service
+ audioSettings:(NSDictionary *)audioSettings
+ videoSettings:(NSDictionary *)videoSettings
+ fileFormat:(QMediaFormat::FileFormat)fileFormat
+ transform:(CGAffineTransform)transform;
+
+// This to be called from the recorder control's thread:
+- (void)start;
+- (void)stop;
+- (void)pause;
+- (void)resume;
+// This to be called from the recorder control's dtor:
+- (void)abort;
+- (qint64)durationInMs;
+
+@end
+
+#endif // AVFMEDIAASSETWRITER_H
diff --git a/src/plugins/multimedia/darwin/camera/avfmediaencoder.mm b/src/plugins/multimedia/darwin/camera/avfmediaencoder.mm
new file mode 100644
index 000000000..3fbc57995
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfmediaencoder.mm
@@ -0,0 +1,664 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#include "avfmediaencoder_p.h"
+#include "avfcamerarenderer_p.h"
+#include "avfcamerasession_p.h"
+#include "avfcamera_p.h"
+#include "avfcameraservice_p.h"
+#include "avfcameradebug_p.h"
+#include "avfcamerautility_p.h"
+#include "qaudiodevice.h"
+
+#include "qmediadevices.h"
+#include "private/qmediastoragelocation_p.h"
+#include "private/qmediarecorder_p.h"
+#include "qdarwinformatsinfo_p.h"
+#include "private/qplatformaudiooutput_p.h"
+#include <private/qplatformaudioinput_p.h>
+
+#include <QtCore/qmath.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qmimetype.h>
+
+#include <private/qcoreaudioutils_p.h>
+
+QT_USE_NAMESPACE
+
+namespace {
+
+bool qt_is_writable_file_URL(NSURL *fileURL)
+{
+ Q_ASSERT(fileURL);
+
+ if (![fileURL isFileURL])
+ return false;
+
+ if (NSString *path = [[fileURL path] stringByExpandingTildeInPath]) {
+ return [[NSFileManager defaultManager]
+ isWritableFileAtPath:[path stringByDeletingLastPathComponent]];
+ }
+
+ return false;
+}
+
+bool qt_file_exists(NSURL *fileURL)
+{
+ Q_ASSERT(fileURL);
+
+ if (NSString *path = [[fileURL path] stringByExpandingTildeInPath])
+ return [[NSFileManager defaultManager] fileExistsAtPath:path];
+
+ return false;
+}
+
+}
+
+AVFMediaEncoder::AVFMediaEncoder(QMediaRecorder *parent)
+ : QObject(parent)
+ , QPlatformMediaRecorder(parent)
+ , m_state(QMediaRecorder::StoppedState)
+ , m_duration(0)
+ , m_audioSettings(nil)
+ , m_videoSettings(nil)
+ //, m_restoreFPS(-1, -1)
+{
+ m_writer.reset([[QT_MANGLE_NAMESPACE(AVFMediaAssetWriter) alloc] initWithDelegate:this]);
+ if (!m_writer) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to create an asset writer";
+ return;
+ }
+}
+
+AVFMediaEncoder::~AVFMediaEncoder()
+{
+ [m_writer abort];
+
+ if (m_audioSettings)
+ [m_audioSettings release];
+ if (m_videoSettings)
+ [m_videoSettings release];
+}
+
+bool AVFMediaEncoder::isLocationWritable(const QUrl &location) const
+{
+ return location.scheme() == QLatin1String("file") || location.scheme().isEmpty();
+}
+
+QMediaRecorder::RecorderState AVFMediaEncoder::state() const
+{
+ return m_state;
+}
+
+qint64 AVFMediaEncoder::duration() const
+{
+ return m_duration;
+}
+
+void AVFMediaEncoder::updateDuration(qint64 duration)
+{
+ m_duration = duration;
+ durationChanged(m_duration);
+}
+
+static NSDictionary *avfAudioSettings(const QMediaEncoderSettings &encoderSettings, const QAudioFormat &format)
+{
+ NSMutableDictionary *settings = [NSMutableDictionary dictionary];
+
+ // Codec
+ int codecId = QDarwinFormatInfo::audioFormatForCodec(encoderSettings.mediaFormat().audioCodec());
+ [settings setObject:[NSNumber numberWithInt:codecId] forKey:AVFormatIDKey];
+
+ // Setting AVEncoderQualityKey is not allowed when format ID is alac or lpcm
+ if (codecId != kAudioFormatAppleLossless && codecId != kAudioFormatLinearPCM
+ && encoderSettings.encodingMode() == QMediaRecorder::ConstantQualityEncoding) {
+ // AudioQuality
+ int quality;
+ switch (encoderSettings.quality()) {
+ case QMediaRecorder::VeryLowQuality:
+ quality = AVAudioQualityMin;
+ break;
+ case QMediaRecorder::LowQuality:
+ quality = AVAudioQualityLow;
+ break;
+ case QMediaRecorder::HighQuality:
+ quality = AVAudioQualityHigh;
+ break;
+ case QMediaRecorder::VeryHighQuality:
+ quality = AVAudioQualityMax;
+ break;
+ case QMediaRecorder::NormalQuality:
+ default:
+ quality = AVAudioQualityMedium;
+ break;
+ }
+ [settings setObject:[NSNumber numberWithInt:quality] forKey:AVEncoderAudioQualityKey];
+ } else {
+ // BitRate
+ bool isBitRateSupported = false;
+ int bitRate = encoderSettings.audioBitRate();
+ if (bitRate > 0) {
+ QList<AudioValueRange> bitRates = qt_supported_bit_rates_for_format(codecId);
+ for (int i = 0; i < bitRates.count(); i++) {
+ if (bitRate >= bitRates[i].mMinimum &&
+ bitRate <= bitRates[i].mMaximum) {
+ isBitRateSupported = true;
+ break;
+ }
+ }
+ if (isBitRateSupported)
+ [settings setObject:[NSNumber numberWithInt:encoderSettings.audioBitRate()]
+ forKey:AVEncoderBitRateKey];
+ }
+ }
+
+ // SampleRate
+ int sampleRate = encoderSettings.audioSampleRate();
+ bool isSampleRateSupported = false;
+ if (sampleRate >= 8000 && sampleRate <= 192000) {
+ QList<AudioValueRange> sampleRates = qt_supported_sample_rates_for_format(codecId);
+ for (int i = 0; i < sampleRates.count(); i++) {
+ if (sampleRate >= sampleRates[i].mMinimum && sampleRate <= sampleRates[i].mMaximum) {
+ isSampleRateSupported = true;
+ break;
+ }
+ }
+ }
+ if (!isSampleRateSupported)
+ sampleRate = 44100;
+ [settings setObject:[NSNumber numberWithInt:sampleRate] forKey:AVSampleRateKey];
+
+ // Channels
+ int channelCount = encoderSettings.audioChannelCount();
+ bool isChannelCountSupported = false;
+ if (channelCount > 0) {
+ std::optional<QList<UInt32>> channelCounts = qt_supported_channel_counts_for_format(codecId);
+ // An std::nullopt result indicates that
+ // any number of channels can be encoded.
+ if (channelCounts == std::nullopt) {
+ isChannelCountSupported = true;
+ } else {
+ for (int i = 0; i < channelCounts.value().count(); i++) {
+ if ((UInt32)channelCount == channelCounts.value()[i]) {
+ isChannelCountSupported = true;
+ break;
+ }
+ }
+ }
+
+ // if channel count is provided and it's bigger than 2
+ // provide a supported channel layout
+ if (isChannelCountSupported && channelCount > 2) {
+ AudioChannelLayout channelLayout;
+ memset(&channelLayout, 0, sizeof(AudioChannelLayout));
+ auto channelLayoutTags = qt_supported_channel_layout_tags_for_format(codecId, channelCount);
+ if (channelLayoutTags.size()) {
+ channelLayout.mChannelLayoutTag = channelLayoutTags.first();
+ [settings setObject:[NSData dataWithBytes: &channelLayout length: sizeof(channelLayout)] forKey:AVChannelLayoutKey];
+ } else {
+ isChannelCountSupported = false;
+ }
+ }
+
+ if (isChannelCountSupported)
+ [settings setObject:[NSNumber numberWithInt:channelCount] forKey:AVNumberOfChannelsKey];
+ }
+
+ if (!isChannelCountSupported) {
+ // fallback to providing channel layout if channel count is not specified or supported
+ UInt32 size = 0;
+ if (format.isValid()) {
+ auto layout = CoreAudioUtils::toAudioChannelLayout(format, &size);
+ [settings setObject:[NSData dataWithBytes:layout.get() length:sizeof(AudioChannelLayout)] forKey:AVChannelLayoutKey];
+ } else {
+ // finally default to setting channel count to 1
+ [settings setObject:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
+ }
+ }
+
+ if (codecId == kAudioFormatAppleLossless)
+ [settings setObject:[NSNumber numberWithInt:24] forKey:AVEncoderBitDepthHintKey];
+
+ if (codecId == kAudioFormatLinearPCM) {
+ [settings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
+ [settings setObject:[NSNumber numberWithInt:NO] forKey:AVLinearPCMIsBigEndianKey];
+ [settings setObject:[NSNumber numberWithInt:NO] forKey:AVLinearPCMIsFloatKey];
+ [settings setObject:[NSNumber numberWithInt:NO] forKey:AVLinearPCMIsNonInterleaved];
+ }
+
+ return settings;
+}
+
+NSDictionary *avfVideoSettings(QMediaEncoderSettings &encoderSettings, AVCaptureDevice *device, AVCaptureConnection *connection, QSize nativeSize)
+{
+ if (!device)
+ return nil;
+
+
+ // ### re-add needFpsChange
+// AVFPSRange currentFps = qt_current_framerates(device, connection);
+
+ NSMutableDictionary *videoSettings = [NSMutableDictionary dictionary];
+
+ // -- Codec
+
+ // AVVideoCodecKey is the only mandatory key
+ auto codec = encoderSettings.mediaFormat().videoCodec();
+ NSString *c = QDarwinFormatInfo::videoFormatForCodec(codec);
+ [videoSettings setObject:c forKey:AVVideoCodecKey];
+ [c release];
+
+ // -- Resolution
+
+ int w = encoderSettings.videoResolution().width();
+ int h = encoderSettings.videoResolution().height();
+
+ if (AVCaptureDeviceFormat *currentFormat = device.activeFormat) {
+ CMFormatDescriptionRef formatDesc = currentFormat.formatDescription;
+ CMVideoDimensions dim = CMVideoFormatDescriptionGetDimensions(formatDesc);
+ FourCharCode formatCodec = CMVideoFormatDescriptionGetCodecType(formatDesc);
+
+ // We have to change the device's activeFormat in 3 cases:
+ // - the requested recording resolution is higher than the current device resolution
+ // - the requested recording resolution has a different aspect ratio than the current device aspect ratio
+ // - the requested frame rate is not available for the current device format
+ AVCaptureDeviceFormat *newFormat = nil;
+ if ((w <= 0 || h <= 0)
+ && encoderSettings.videoFrameRate() > 0
+ && !qt_format_supports_framerate(currentFormat, encoderSettings.videoFrameRate())) {
+
+ newFormat = qt_find_best_framerate_match(device,
+ formatCodec,
+ encoderSettings.videoFrameRate());
+
+ } else if (w > 0 && h > 0) {
+ AVCaptureDeviceFormat *f = qt_find_best_resolution_match(device,
+ encoderSettings.videoResolution(),
+ formatCodec);
+
+ if (f) {
+ CMVideoDimensions d = CMVideoFormatDescriptionGetDimensions(f.formatDescription);
+ qreal fAspectRatio = qreal(d.width) / d.height;
+
+ if (w > dim.width || h > dim.height
+ || qAbs((qreal(dim.width) / dim.height) - fAspectRatio) > 0.01) {
+ newFormat = f;
+ }
+ }
+ }
+
+ if (qt_set_active_format(device, newFormat, false /*### !needFpsChange*/)) {
+ formatDesc = newFormat.formatDescription;
+ dim = CMVideoFormatDescriptionGetDimensions(formatDesc);
+ }
+
+ if (w < 0 || h < 0) {
+ w = dim.width;
+ h = dim.height;
+ }
+
+
+ if (w > 0 && h > 0) {
+ // Make sure the recording resolution has the same aspect ratio as the device's
+ // current resolution
+ qreal deviceAspectRatio = qreal(dim.width) / dim.height;
+ qreal recAspectRatio = qreal(w) / h;
+ if (qAbs(deviceAspectRatio - recAspectRatio) > 0.01) {
+ if (recAspectRatio > deviceAspectRatio)
+ w = qRound(h * deviceAspectRatio);
+ else
+ h = qRound(w / deviceAspectRatio);
+ }
+
+ // recording resolution can't be higher than the device's active resolution
+ w = qMin(w, dim.width);
+ h = qMin(h, dim.height);
+ }
+ }
+
+ if (w > 0 && h > 0) {
+ // Width and height must be divisible by 2
+ w += w & 1;
+ h += h & 1;
+
+ bool isPortrait = nativeSize.width() < nativeSize.height();
+ // Make sure the video has the right aspect ratio
+ if (isPortrait && h < w)
+ qSwap(w, h);
+ else if (!isPortrait && w < h)
+ qSwap(w, h);
+
+ encoderSettings.setVideoResolution(QSize(w, h));
+ } else {
+ w = nativeSize.width();
+ h = nativeSize.height();
+ encoderSettings.setVideoResolution(nativeSize);
+ }
+ [videoSettings setObject:[NSNumber numberWithInt:w] forKey:AVVideoWidthKey];
+ [videoSettings setObject:[NSNumber numberWithInt:h] forKey:AVVideoHeightKey];
+
+ // -- FPS
+
+ if (true /*needFpsChange*/) {
+ const qreal fps = encoderSettings.videoFrameRate();
+ qt_set_framerate_limits(device, connection, fps, fps);
+ }
+ encoderSettings.setVideoFrameRate(qt_current_framerates(device, connection).second);
+
+ // -- Codec Settings
+
+ NSMutableDictionary *codecProperties = [NSMutableDictionary dictionary];
+ int bitrate = -1;
+ float quality = -1.f;
+
+ if (encoderSettings.encodingMode() == QMediaRecorder::ConstantQualityEncoding) {
+ if (encoderSettings.quality() != QMediaRecorder::NormalQuality) {
+ if (codec != QMediaFormat::VideoCodec::MotionJPEG) {
+ qWarning("ConstantQualityEncoding is not supported for MotionJPEG");
+ } else {
+ switch (encoderSettings.quality()) {
+ case QMediaRecorder::VeryLowQuality:
+ quality = 0.f;
+ break;
+ case QMediaRecorder::LowQuality:
+ quality = 0.25f;
+ break;
+ case QMediaRecorder::HighQuality:
+ quality = 0.75f;
+ break;
+ case QMediaRecorder::VeryHighQuality:
+ quality = 1.f;
+ break;
+ default:
+ quality = -1.f; // NormalQuality, let the system decide
+ break;
+ }
+ }
+ }
+ } else if (encoderSettings.encodingMode() == QMediaRecorder::AverageBitRateEncoding){
+ if (codec != QMediaFormat::VideoCodec::H264 && codec != QMediaFormat::VideoCodec::H265)
+ qWarning() << "AverageBitRateEncoding is not supported for codec" << QMediaFormat::videoCodecName(codec);
+ else
+ bitrate = encoderSettings.videoBitRate();
+ } else {
+ qWarning("Encoding mode is not supported");
+ }
+
+ if (bitrate != -1)
+ [codecProperties setObject:[NSNumber numberWithInt:bitrate] forKey:AVVideoAverageBitRateKey];
+ if (quality != -1.f)
+ [codecProperties setObject:[NSNumber numberWithFloat:quality] forKey:AVVideoQualityKey];
+
+ [videoSettings setObject:codecProperties forKey:AVVideoCompressionPropertiesKey];
+
+ return videoSettings;
+}
+
+void AVFMediaEncoder::applySettings(QMediaEncoderSettings &settings)
+{
+ unapplySettings();
+
+ AVFCameraSession *session = m_service->session();
+
+ // audio settings
+ const auto audioInput = m_service->audioInput();
+ const QAudioFormat audioFormat = audioInput ? audioInput->device.preferredFormat() : QAudioFormat();
+ m_audioSettings = avfAudioSettings(settings, audioFormat);
+ if (m_audioSettings)
+ [m_audioSettings retain];
+
+ // video settings
+ AVCaptureDevice *device = session->videoCaptureDevice();
+ if (!device)
+ return;
+ const AVFConfigurationLock lock(device); // prevents activeFormat from being overridden
+ AVCaptureConnection *conn = [session->videoOutput()->videoDataOutput() connectionWithMediaType:AVMediaTypeVideo];
+ auto nativeSize = session->videoOutput()->nativeSize();
+ m_videoSettings = avfVideoSettings(settings, device, conn, nativeSize);
+ if (m_videoSettings)
+ [m_videoSettings retain];
+}
+
+void AVFMediaEncoder::unapplySettings()
+{
+ if (m_audioSettings) {
+ [m_audioSettings release];
+ m_audioSettings = nil;
+ }
+ if (m_videoSettings) {
+ [m_videoSettings release];
+ m_videoSettings = nil;
+ }
+}
+
+void AVFMediaEncoder::setMetaData(const QMediaMetaData &metaData)
+{
+ m_metaData = metaData;
+}
+
+QMediaMetaData AVFMediaEncoder::metaData() const
+{
+ return m_metaData;
+}
+
+void AVFMediaEncoder::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ AVFCameraService *captureSession = static_cast<AVFCameraService *>(session);
+ if (m_service == captureSession)
+ return;
+
+ if (m_service)
+ stop();
+
+ m_service = captureSession;
+ if (!m_service)
+ return;
+
+ connect(m_service, &AVFCameraService::cameraChanged, this, &AVFMediaEncoder::onCameraChanged);
+ onCameraChanged();
+}
+
+void AVFMediaEncoder::record(QMediaEncoderSettings &settings)
+{
+ if (!m_service || !m_service->session()) {
+ qWarning() << Q_FUNC_INFO << "Encoder is not set to a capture session";
+ return;
+ }
+
+ if (!m_writer) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "Invalid recorder";
+ return;
+ }
+
+ if (QMediaRecorder::RecordingState == m_state)
+ return;
+
+ AVFCamera *cameraControl = m_service->avfCameraControl();
+ auto audioInput = m_service->audioInput();
+
+ if (!cameraControl && !audioInput) {
+ qWarning() << Q_FUNC_INFO << "Cannot record without any inputs";
+ updateError(QMediaRecorder::ResourceError, tr("No inputs specified"));
+ return;
+ }
+
+ m_service->session()->setActive(true);
+ const bool audioOnly = settings.videoCodec() == QMediaFormat::VideoCodec::Unspecified;
+ AVCaptureSession *session = m_service->session()->captureSession();
+ float rotation = 0;
+
+ if (!audioOnly) {
+ if (!cameraControl || !cameraControl->isActive()) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "can not start record while camera is not active";
+ updateError(QMediaRecorder::ResourceError,
+ QMediaRecorderPrivate::msgFailedStartRecording());
+ return;
+ }
+ }
+
+ const QString path(outputLocation().scheme() == QLatin1String("file") ?
+ outputLocation().path() : outputLocation().toString());
+ const QUrl fileURL(QUrl::fromLocalFile(QMediaStorageLocation::generateFileName(path,
+ audioOnly ? QStandardPaths::MusicLocation : QStandardPaths::MoviesLocation,
+ settings.mimeType().preferredSuffix())));
+
+ NSURL *nsFileURL = fileURL.toNSURL();
+ if (!nsFileURL) {
+ qWarning() << Q_FUNC_INFO << "invalid output URL:" << fileURL;
+ updateError(QMediaRecorder::ResourceError, tr("Invalid output file URL"));
+ return;
+ }
+ if (!qt_is_writable_file_URL(nsFileURL)) {
+ qWarning() << Q_FUNC_INFO << "invalid output URL:" << fileURL
+ << "(the location is not writable)";
+ updateError(QMediaRecorder::ResourceError, tr("Non-writeable file location"));
+ return;
+ }
+ if (qt_file_exists(nsFileURL)) {
+ // We test for/handle this error here since AWAssetWriter will raise an
+ // Objective-C exception, which is not good at all.
+ qWarning() << Q_FUNC_INFO << "invalid output URL:" << fileURL
+ << "(file already exists)";
+ updateError(QMediaRecorder::ResourceError, tr("File already exists"));
+ return;
+ }
+
+ applySettings(settings);
+
+ QVideoOutputOrientationHandler::setIsRecording(true);
+
+ // We stop session now so that no more frames for renderer's queue
+ // generated, will restart in assetWriterStarted.
+ [session stopRunning];
+
+ if ([m_writer setupWithFileURL:nsFileURL
+ cameraService:m_service
+ audioSettings:m_audioSettings
+ videoSettings:m_videoSettings
+ fileFormat:settings.fileFormat()
+ transform:CGAffineTransformMakeRotation(qDegreesToRadians(rotation))]) {
+
+ m_state = QMediaRecorder::RecordingState;
+
+ Q_EMIT actualLocationChanged(fileURL);
+ Q_EMIT stateChanged(m_state);
+
+ // Apple recommends to call startRunning and do all
+ // setup on a special queue, and that's what we had
+ // initially (dispatch_async to writerQueue). Unfortunately,
+ // writer's queue is not the only queue/thread that can
+ // access/modify the session, and as a result we have
+ // all possible data/race-conditions with Obj-C exceptions
+ // at best and something worse in general.
+ // Now we try to only modify session on the same thread.
+ [m_writer start];
+ } else {
+ [session startRunning];
+ updateError(QMediaRecorder::FormatError, QMediaRecorderPrivate::msgFailedStartRecording());
+ }
+}
+
+void AVFMediaEncoder::pause()
+{
+ if (!m_service || !m_service->session() || state() != QMediaRecorder::RecordingState)
+ return;
+
+ toggleRecord(false);
+ m_state = QMediaRecorder::PausedState;
+ stateChanged(m_state);
+}
+
+void AVFMediaEncoder::resume()
+{
+ if (!m_service || !m_service->session() || state() != QMediaRecorder::PausedState)
+ return;
+
+ toggleRecord(true);
+ m_state = QMediaRecorder::RecordingState;
+ stateChanged(m_state);
+}
+
+void AVFMediaEncoder::stop()
+{
+ if (m_state != QMediaRecorder::StoppedState) {
+ // Do not check the camera status, we can stop if we started.
+ stopWriter();
+ }
+ QVideoOutputOrientationHandler::setIsRecording(false);
+}
+
+
+void AVFMediaEncoder::toggleRecord(bool enable)
+{
+ if (!m_service || !m_service->session())
+ return;
+
+ if (!enable)
+ [m_writer pause];
+ else
+ [m_writer resume];
+}
+
+void AVFMediaEncoder::assetWriterStarted()
+{
+}
+
+void AVFMediaEncoder::assetWriterFinished()
+{
+
+ const QMediaRecorder::RecorderState lastState = m_state;
+
+ unapplySettings();
+
+ if (m_service) {
+ AVFCameraSession *session = m_service->session();
+
+ if (session->videoOutput()) {
+ session->videoOutput()->resetCaptureDelegate();
+ }
+ if (session->audioPreviewDelegate()) {
+ [session->audioPreviewDelegate() resetAudioPreviewDelegate];
+ }
+ if (session->videoOutput() || session->audioPreviewDelegate())
+ [session->captureSession() startRunning];
+ }
+
+ m_state = QMediaRecorder::StoppedState;
+ if (m_state != lastState)
+ Q_EMIT stateChanged(m_state);
+}
+
+void AVFMediaEncoder::assetWriterError(QString err)
+{
+ updateError(QMediaRecorder::FormatError, err);
+ if (m_state != QMediaRecorder::StoppedState)
+ stopWriter();
+}
+
+void AVFMediaEncoder::onCameraChanged()
+{
+ if (m_service && m_service->avfCameraControl()) {
+ AVFCamera *cameraControl = m_service->avfCameraControl();
+ connect(cameraControl, SIGNAL(activeChanged(bool)),
+ SLOT(cameraActiveChanged(bool)));
+ }
+}
+
+void AVFMediaEncoder::cameraActiveChanged(bool active)
+{
+ Q_ASSERT(m_service);
+ AVFCamera *cameraControl = m_service->avfCameraControl();
+ Q_ASSERT(cameraControl);
+
+ if (!active) {
+ return stopWriter();
+ }
+}
+
+void AVFMediaEncoder::stopWriter()
+{
+ [m_writer stop];
+}
+
+#include "moc_avfmediaencoder_p.cpp"
diff --git a/src/plugins/multimedia/darwin/camera/avfmediaencoder_p.h b/src/plugins/multimedia/darwin/camera/avfmediaencoder_p.h
new file mode 100644
index 000000000..23aced325
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/avfmediaencoder_p.h
@@ -0,0 +1,96 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFMEDIAENCODER_H
+#define AVFMEDIAENCODER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "avfmediaassetwriter_p.h"
+#include "avfcamerautility_p.h"
+#include "qaudiodevice.h"
+
+#include <private/qplatformmediarecorder_p.h>
+#include <private/qplatformmediacapture_p.h>
+#include <QtMultimedia/qmediametadata.h>
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qurl.h>
+
+#include <AVFoundation/AVFoundation.h>
+
+QT_BEGIN_NAMESPACE
+
+class AVFCameraService;
+class QString;
+class QUrl;
+
+class AVFMediaEncoder : public QObject, public QPlatformMediaRecorder
+{
+ Q_OBJECT
+public:
+ AVFMediaEncoder(QMediaRecorder *parent);
+ ~AVFMediaEncoder() override;
+
+ bool isLocationWritable(const QUrl &location) const override;
+
+ QMediaRecorder::RecorderState state() const override;
+
+ qint64 duration() const override;
+
+ void record(QMediaEncoderSettings &settings) override;
+ void pause() override;
+ void resume() override;
+ void stop() override;
+
+ void setMetaData(const QMediaMetaData &) override;
+ QMediaMetaData metaData() const override;
+
+ AVFCameraService *cameraService() const { return m_service; }
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session);
+
+ void updateDuration(qint64 duration);
+
+ void toggleRecord(bool enable);
+
+private:
+ void applySettings(QMediaEncoderSettings &settings);
+ void unapplySettings();
+
+ Q_INVOKABLE void assetWriterStarted();
+ Q_INVOKABLE void assetWriterFinished();
+ Q_INVOKABLE void assetWriterError(QString error);
+
+private Q_SLOTS:
+ void onCameraChanged();
+ void cameraActiveChanged(bool);
+
+private:
+ void stopWriter();
+
+ AVFCameraService *m_service = nullptr;
+ AVFScopedPointer<QT_MANGLE_NAMESPACE(AVFMediaAssetWriter)> m_writer;
+
+ QMediaRecorder::RecorderState m_state;
+
+ QMediaMetaData m_metaData;
+
+ qint64 m_duration;
+
+ NSDictionary *m_audioSettings;
+ NSDictionary *m_videoSettings;
+};
+
+QT_END_NAMESPACE
+
+#endif // AVFMEDIAENCODER_H
diff --git a/src/plugins/multimedia/darwin/camera/qavfcamerabase.mm b/src/plugins/multimedia/darwin/camera/qavfcamerabase.mm
new file mode 100644
index 000000000..9d99de0b9
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/qavfcamerabase.mm
@@ -0,0 +1,1084 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfcameradebug_p.h"
+#include "qavfcamerabase_p.h"
+#include "avfcamerautility_p.h"
+#include <private/qcameradevice_p.h>
+#include "qavfhelpers_p.h"
+#include <private/qplatformmediaintegration_p.h>
+#include <QtCore/qset.h>
+#include <QtCore/qsystemdetection.h>
+
+QT_USE_NAMESPACE
+
+namespace {
+
+// All these methods to work with exposure/ISO/SS in custom mode do not support macOS.
+
+#ifdef Q_OS_IOS
+
+// Misc. helpers to check values/ranges:
+
+bool qt_check_exposure_duration(AVCaptureDevice *captureDevice, CMTime duration)
+{
+ Q_ASSERT(captureDevice);
+
+ AVCaptureDeviceFormat *activeFormat = captureDevice.activeFormat;
+ if (!activeFormat) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to obtain capture device format";
+ return false;
+ }
+
+ return CMTimeCompare(duration, activeFormat.minExposureDuration) != -1
+ && CMTimeCompare(activeFormat.maxExposureDuration, duration) != -1;
+}
+
+bool qt_check_ISO_value(AVCaptureDevice *captureDevice, int newISO)
+{
+ Q_ASSERT(captureDevice);
+
+ AVCaptureDeviceFormat *activeFormat = captureDevice.activeFormat;
+ if (!activeFormat) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to obtain capture device format";
+ return false;
+ }
+
+ return !(newISO < activeFormat.minISO || newISO > activeFormat.maxISO);
+}
+
+bool qt_exposure_duration_equal(AVCaptureDevice *captureDevice, qreal qDuration)
+{
+ Q_ASSERT(captureDevice);
+ const CMTime avDuration = CMTimeMakeWithSeconds(qDuration, captureDevice.exposureDuration.timescale);
+ return !CMTimeCompare(avDuration, captureDevice.exposureDuration);
+}
+
+bool qt_iso_equal(AVCaptureDevice *captureDevice, int iso)
+{
+ Q_ASSERT(captureDevice);
+ return qFuzzyCompare(float(iso), captureDevice.ISO);
+}
+
+bool qt_exposure_bias_equal(AVCaptureDevice *captureDevice, qreal bias)
+{
+ Q_ASSERT(captureDevice);
+ return qFuzzyCompare(bias, qreal(captureDevice.exposureTargetBias));
+}
+
+// Converters:
+
+bool qt_convert_exposure_mode(AVCaptureDevice *captureDevice, QCamera::ExposureMode mode,
+ AVCaptureExposureMode &avMode)
+{
+ // Test if mode supported and convert.
+ Q_ASSERT(captureDevice);
+
+ if (mode == QCamera::ExposureAuto) {
+ if ([captureDevice isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) {
+ avMode = AVCaptureExposureModeContinuousAutoExposure;
+ return true;
+ }
+ }
+
+ if (mode == QCamera::ExposureManual) {
+ if ([captureDevice isExposureModeSupported:AVCaptureExposureModeCustom]) {
+ avMode = AVCaptureExposureModeCustom;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+#endif // defined(Q_OS_IOS)
+
+} // Unnamed namespace.
+
+
+QAVFVideoDevices::QAVFVideoDevices(QPlatformMediaIntegration *integration)
+ : QPlatformVideoDevices(integration)
+{
+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+ m_deviceConnectedObserver = [notificationCenter addObserverForName:AVCaptureDeviceWasConnectedNotification
+ object:nil
+ queue:[NSOperationQueue mainQueue]
+ usingBlock:^(NSNotification *) {
+ this->updateCameraDevices();
+ }];
+
+ m_deviceDisconnectedObserver = [notificationCenter addObserverForName:AVCaptureDeviceWasDisconnectedNotification
+ object:nil
+ queue:[NSOperationQueue mainQueue]
+ usingBlock:^(NSNotification *) {
+ this->updateCameraDevices();
+ }];
+ updateCameraDevices();
+}
+
+QAVFVideoDevices::~QAVFVideoDevices()
+{
+ NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter];
+ [notificationCenter removeObserver:(id)m_deviceConnectedObserver];
+ [notificationCenter removeObserver:(id)m_deviceDisconnectedObserver];
+}
+
+QList<QCameraDevice> QAVFVideoDevices::videoDevices() const
+{
+ return m_cameraDevices;
+}
+
+void QAVFVideoDevices::updateCameraDevices()
+{
+#ifdef Q_OS_IOS
+ // Cameras can't change dynamically on iOS. Update only once.
+ if (!m_cameraDevices.isEmpty())
+ return;
+#endif
+
+ QList<QCameraDevice> cameras;
+
+ // List of all capture device types that we want to discover. Seems that this is the
+ // only way to discover all types. This filter is mandatory and has no "unspecified"
+ // option like AVCaptureDevicePosition(Unspecified) has. Order of the list is important
+ // because discovered devices will be in the same order and we want the first one found
+ // to be our default device.
+ NSArray *discoveryDevices = @[
+#ifdef Q_OS_IOS
+ AVCaptureDeviceTypeBuiltInTripleCamera, // We always prefer triple camera.
+ AVCaptureDeviceTypeBuiltInDualCamera, // If triple is not available, we prefer
+ // dual with wide + tele lens.
+ AVCaptureDeviceTypeBuiltInDualWideCamera, // Dual with wide and ultrawide is still
+ // better than single.
+#endif
+ AVCaptureDeviceTypeBuiltInWideAngleCamera, // This is the most common single camera type.
+ // We prefer that over tele and ultra-wide.
+#ifdef Q_OS_IOS
+ AVCaptureDeviceTypeBuiltInTelephotoCamera, // Cannot imagine how, but if only tele and
+ // ultrawide are available, we prefer tele.
+ AVCaptureDeviceTypeBuiltInUltraWideCamera,
+#endif
+ ];
+
+#if QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_14_0, __IPHONE_17_0, __TVOS_NA, __WATCHOS_NA)
+ if (@available(macOS 14, iOS 17, *)) {
+ discoveryDevices = [discoveryDevices arrayByAddingObjectsFromArray: @[
+ AVCaptureDeviceTypeExternal,
+ AVCaptureDeviceTypeContinuityCamera
+ ]];
+ } else
+#endif
+ {
+#ifdef Q_OS_MACOS
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_DEPRECATED
+ discoveryDevices = [discoveryDevices arrayByAddingObjectsFromArray: @[
+ AVCaptureDeviceTypeExternalUnknown
+ ]];
+ QT_WARNING_POP
+#endif
+ }
+ // Create discovery session to discover all possible camera types of the system.
+ // Both "hard" and "soft" types.
+ AVCaptureDeviceDiscoverySession *discoverySession = [AVCaptureDeviceDiscoverySession
+ discoverySessionWithDeviceTypes:discoveryDevices
+ mediaType:AVMediaTypeVideo
+ position:AVCaptureDevicePositionUnspecified];
+ NSArray<AVCaptureDevice *> *videoDevices = discoverySession.devices;
+
+ for (AVCaptureDevice *device in videoDevices) {
+ auto info = std::make_unique<QCameraDevicePrivate>();
+ if ([videoDevices[0].uniqueID isEqualToString:device.uniqueID])
+ info->isDefault = true;
+ info->id = QByteArray([[device uniqueID] UTF8String]);
+ info->description = QString::fromNSString([device localizedName]);
+
+ qCDebug(qLcCamera) << "Handling camera info" << info->description
+ << (info->isDefault ? "(default)" : "");
+
+ QSet<QSize> photoResolutions;
+ QList<QCameraFormat> videoFormats;
+
+ for (AVCaptureDeviceFormat *format in device.formats) {
+ if (![format.mediaType isEqualToString:AVMediaTypeVideo])
+ continue;
+
+ auto dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
+ QSize resolution(dimensions.width, dimensions.height);
+ photoResolutions.insert(resolution);
+
+ float maxFrameRate = 0;
+ float minFrameRate = 1.e6;
+
+ auto encoding = CMVideoFormatDescriptionGetCodecType(format.formatDescription);
+ auto pixelFormat = QAVFHelpers::fromCVPixelFormat(encoding);
+ auto colorRange = QAVFHelpers::colorRangeForCVPixelFormat(encoding);
+ // Ignore pixel formats we can't handle
+ if (pixelFormat == QVideoFrameFormat::Format_Invalid) {
+ qCDebug(qLcCamera) << "ignore camera CV format" << encoding
+ << "as no matching video format found";
+ continue;
+ }
+
+ for (AVFrameRateRange *frameRateRange in format.videoSupportedFrameRateRanges) {
+ if (frameRateRange.minFrameRate < minFrameRate)
+ minFrameRate = frameRateRange.minFrameRate;
+ if (frameRateRange.maxFrameRate > maxFrameRate)
+ maxFrameRate = frameRateRange.maxFrameRate;
+ }
+
+#ifdef Q_OS_IOS
+ // From Apple's docs (iOS):
+ // By default, AVCaptureStillImageOutput emits images with the same dimensions as
+ // its source AVCaptureDevice instance’s activeFormat.formatDescription. However,
+ // if you set this property to YES, the receiver emits still images at the capture
+ // device’s highResolutionStillImageDimensions value.
+ const QSize hrRes(qt_device_format_high_resolution(format));
+ if (!hrRes.isNull() && hrRes.isValid())
+ photoResolutions.insert(hrRes);
+#endif
+
+ qCDebug(qLcCamera) << "Add camera format. pixelFormat:" << pixelFormat
+ << "colorRange:" << colorRange << "cvPixelFormat" << encoding
+ << "resolution:" << resolution << "frameRate: [" << minFrameRate
+ << maxFrameRate << "]";
+
+ auto *f = new QCameraFormatPrivate{ QSharedData(), pixelFormat, resolution,
+ minFrameRate, maxFrameRate, colorRange };
+ videoFormats << f->create();
+ }
+ if (videoFormats.isEmpty()) {
+ // skip broken cameras without valid formats
+ qCWarning(qLcCamera())
+ << "Skip camera" << info->description << "without supported formats";
+ continue;
+ }
+ info->videoFormats = videoFormats;
+ info->photoResolutions = photoResolutions.values();
+
+ cameras.append(info.release()->create());
+ }
+
+ if (cameras != m_cameraDevices) {
+ m_cameraDevices = cameras;
+ emit videoInputsChanged();
+ }
+}
+
+
+QAVFCameraBase::QAVFCameraBase(QCamera *camera)
+ : QPlatformCamera(camera)
+{
+ Q_ASSERT(camera);
+}
+
+QAVFCameraBase::~QAVFCameraBase()
+{
+}
+
+bool QAVFCameraBase::isActive() const
+{
+ return m_active;
+}
+
+void QAVFCameraBase::setActive(bool active)
+{
+ if (m_active == active)
+ return;
+ if (m_cameraDevice.isNull() && active)
+ return;
+
+ m_active = active;
+
+ if (active)
+ updateCameraConfiguration();
+ Q_EMIT activeChanged(m_active);
+}
+
+void QAVFCameraBase::setCamera(const QCameraDevice &camera)
+{
+ if (m_cameraDevice == camera)
+ return;
+ m_cameraDevice = camera;
+ setCameraFormat({});
+}
+
+bool QAVFCameraBase::setCameraFormat(const QCameraFormat &format)
+{
+ if (!format.isNull() && !m_cameraDevice.videoFormats().contains(format))
+ return false;
+
+ m_cameraFormat = format.isNull() ? findBestCameraFormat(m_cameraDevice) : format;
+
+ return true;
+}
+
+AVCaptureDevice *QAVFCameraBase::device() const
+{
+ AVCaptureDevice *device = nullptr;
+ QByteArray deviceId = m_cameraDevice.id();
+ if (!deviceId.isEmpty()) {
+ device = [AVCaptureDevice deviceWithUniqueID:
+ [NSString stringWithUTF8String:
+ deviceId.constData()]];
+ }
+ return device;
+}
+
+#ifdef Q_OS_IOS
+namespace
+{
+
+bool qt_focus_mode_supported(QCamera::FocusMode mode)
+{
+ // Check if QCamera::FocusMode has counterpart in AVFoundation.
+
+ // AVFoundation has 'Manual', 'Auto' and 'Continuous',
+ // where 'Manual' is actually 'Locked' + writable property 'lensPosition'.
+ return mode == QCamera::FocusModeAuto
+ || mode == QCamera::FocusModeManual;
+}
+
+AVCaptureFocusMode avf_focus_mode(QCamera::FocusMode requestedMode)
+{
+ switch (requestedMode) {
+ case QCamera::FocusModeHyperfocal:
+ case QCamera::FocusModeInfinity:
+ case QCamera::FocusModeManual:
+ return AVCaptureFocusModeLocked;
+ default:
+ return AVCaptureFocusModeContinuousAutoFocus;
+ }
+
+}
+
+}
+#endif
+
+void QAVFCameraBase::setFocusMode(QCamera::FocusMode mode)
+{
+#ifdef Q_OS_IOS
+ if (focusMode() == mode)
+ return;
+
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice) {
+ if (qt_focus_mode_supported(mode)) {
+ focusModeChanged(mode);
+ } else {
+ qCDebug(qLcCamera) << Q_FUNC_INFO
+ << "focus mode not supported";
+ }
+ return;
+ }
+
+ if (isFocusModeSupported(mode)) {
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO
+ << "failed to lock for configuration";
+ return;
+ }
+
+ captureDevice.focusMode = avf_focus_mode(mode);
+ } else {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "focus mode not supported";
+ return;
+ }
+
+ Q_EMIT focusModeChanged(mode);
+#else
+ Q_UNUSED(mode);
+#endif
+}
+
+bool QAVFCameraBase::isFocusModeSupported(QCamera::FocusMode mode) const
+{
+#ifdef Q_OS_IOS
+ AVCaptureDevice *captureDevice = device();
+ if (captureDevice) {
+ AVCaptureFocusMode avMode = avf_focus_mode(mode);
+ switch (mode) {
+ case QCamera::FocusModeAuto:
+ case QCamera::FocusModeHyperfocal:
+ case QCamera::FocusModeInfinity:
+ case QCamera::FocusModeManual:
+ return [captureDevice isFocusModeSupported:avMode];
+ case QCamera::FocusModeAutoNear:
+ Q_FALLTHROUGH();
+ case QCamera::FocusModeAutoFar:
+ return captureDevice.autoFocusRangeRestrictionSupported
+ && [captureDevice isFocusModeSupported:avMode];
+ }
+ }
+#endif
+ return mode == QCamera::FocusModeAuto; // stupid builtin webcam doesn't do any focus handling, but hey it's usually focused :)
+}
+
+void QAVFCameraBase::setCustomFocusPoint(const QPointF &point)
+{
+ if (customFocusPoint() == point)
+ return;
+
+ if (!QRectF(0.f, 0.f, 1.f, 1.f).contains(point)) {
+ // ### release custom focus point, tell the camera to focus where it wants...
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "invalid focus point (out of range)";
+ return;
+ }
+
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice)
+ return;
+
+ if ([captureDevice isFocusPointOfInterestSupported]) {
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to lock for configuration";
+ return;
+ }
+
+ const CGPoint focusPOI = CGPointMake(point.x(), point.y());
+ [captureDevice setFocusPointOfInterest:focusPOI];
+ if (focusMode() != QCamera::FocusModeAuto)
+ [captureDevice setFocusMode:AVCaptureFocusModeAutoFocus];
+
+ customFocusPointChanged(point);
+ }
+}
+
+void QAVFCameraBase::setFocusDistance(float d)
+{
+#ifdef Q_OS_IOS
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice)
+ return;
+
+ if (captureDevice.lockingFocusWithCustomLensPositionSupported) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "Setting custom focus distance not supported\n";
+ return;
+ }
+
+ {
+ AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to lock for configuration";
+ return;
+ }
+ [captureDevice setFocusModeLockedWithLensPosition:d completionHandler:nil];
+ }
+ focusDistanceChanged(d);
+#else
+ Q_UNUSED(d);
+#endif
+}
+
+void QAVFCameraBase::updateCameraConfiguration()
+{
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "capture device is nil in 'active' state";
+ return;
+ }
+
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to lock for configuration";
+ return;
+ }
+
+ if ([captureDevice isFocusPointOfInterestSupported]) {
+ auto point = customFocusPoint();
+ const CGPoint focusPOI = CGPointMake(point.x(), point.y());
+ [captureDevice setFocusPointOfInterest:focusPOI];
+ }
+
+#ifdef Q_OS_IOS
+ if (focusMode() != QCamera::FocusModeAuto) {
+ const AVCaptureFocusMode avMode = avf_focus_mode(focusMode());
+ if (captureDevice.focusMode != avMode) {
+ if ([captureDevice isFocusModeSupported:avMode]) {
+ [captureDevice setFocusMode:avMode];
+ } else {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "focus mode not supported";
+ }
+ }
+ }
+
+ if (!captureDevice.activeFormat) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "camera state is active, but active format is nil";
+ return;
+ }
+
+ minimumZoomFactorChanged(captureDevice.minAvailableVideoZoomFactor);
+ maximumZoomFactorChanged(captureDevice.activeFormat.videoMaxZoomFactor);
+
+ captureDevice.videoZoomFactor = zoomFactor();
+
+ CMTime newDuration = AVCaptureExposureDurationCurrent;
+ bool setCustomMode = false;
+
+ float exposureTime = manualExposureTime();
+ if (exposureTime > 0
+ && !qt_exposure_duration_equal(captureDevice, exposureTime)) {
+ newDuration = CMTimeMakeWithSeconds(exposureTime, captureDevice.exposureDuration.timescale);
+ if (!qt_check_exposure_duration(captureDevice, newDuration)) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "requested exposure duration is out of range";
+ return;
+ }
+ setCustomMode = true;
+ }
+
+ float newISO = AVCaptureISOCurrent;
+ int iso = manualIsoSensitivity();
+ if (iso > 0 && !qt_iso_equal(captureDevice, iso)) {
+ newISO = iso;
+ if (!qt_check_ISO_value(captureDevice, newISO)) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "requested ISO value is out of range";
+ return;
+ }
+ setCustomMode = true;
+ }
+
+ float bias = exposureCompensation();
+ if (bias != 0 && !qt_exposure_bias_equal(captureDevice, bias)) {
+ // TODO: mixed fpns.
+ if (bias < captureDevice.minExposureTargetBias || bias > captureDevice.maxExposureTargetBias) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "exposure compensation value is"
+ << "out of range";
+ return;
+ }
+ [captureDevice setExposureTargetBias:bias completionHandler:nil];
+ }
+
+ // Setting shutter speed (exposure duration) or ISO values
+ // also reset exposure mode into Custom. With this settings
+ // we ignore any attempts to set exposure mode.
+
+ if (setCustomMode) {
+ [captureDevice setExposureModeCustomWithDuration:newDuration
+ ISO:newISO
+ completionHandler:nil];
+ return;
+ }
+
+ QCamera::ExposureMode qtMode = exposureMode();
+ AVCaptureExposureMode avMode = AVCaptureExposureModeContinuousAutoExposure;
+ if (!qt_convert_exposure_mode(captureDevice, qtMode, avMode)) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "requested exposure mode is not supported";
+ return;
+ }
+
+ captureDevice.exposureMode = avMode;
+#endif
+
+ isFlashSupported = isFlashAutoSupported = false;
+ isTorchSupported = isTorchAutoSupported = false;
+
+ if (captureDevice.hasFlash) {
+ if ([captureDevice isFlashModeSupported:AVCaptureFlashModeOn])
+ isFlashSupported = true;
+ if ([captureDevice isFlashModeSupported:AVCaptureFlashModeAuto])
+ isFlashAutoSupported = true;
+ }
+
+ if (captureDevice.hasTorch) {
+ if ([captureDevice isTorchModeSupported:AVCaptureTorchModeOn])
+ isTorchSupported = true;
+ if ([captureDevice isTorchModeSupported:AVCaptureTorchModeAuto])
+ isTorchAutoSupported = true;
+ }
+
+ applyFlashSettings();
+ flashReadyChanged(isFlashSupported);
+}
+
+void QAVFCameraBase::updateCameraProperties()
+{
+ QCamera::Features features;
+ AVCaptureDevice *captureDevice = device();
+
+#ifdef Q_OS_IOS
+ features = QCamera::Feature::ColorTemperature | QCamera::Feature::ExposureCompensation |
+ QCamera::Feature::IsoSensitivity | QCamera::Feature::ManualExposureTime;
+
+ if (captureDevice && [captureDevice isLockingFocusWithCustomLensPositionSupported])
+ features |= QCamera::Feature::FocusDistance;
+#endif
+
+ if (captureDevice && [captureDevice isFocusPointOfInterestSupported])
+ features |= QCamera::Feature::CustomFocusPoint;
+
+ supportedFeaturesChanged(features);
+}
+
+void QAVFCameraBase::zoomTo(float factor, float rate)
+{
+ Q_UNUSED(factor);
+ Q_UNUSED(rate);
+
+#ifdef Q_OS_IOS
+ if (zoomFactor() == factor)
+ return;
+
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice || !captureDevice.activeFormat)
+ return;
+
+ factor = qBound(captureDevice.minAvailableVideoZoomFactor, factor,
+ captureDevice.activeFormat.videoMaxZoomFactor);
+
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to lock for configuration";
+ return;
+ }
+
+ if (rate <= 0)
+ captureDevice.videoZoomFactor = factor;
+ else
+ [captureDevice rampToVideoZoomFactor:factor withRate:rate];
+#endif
+}
+
+void QAVFCameraBase::setFlashMode(QCamera::FlashMode mode)
+{
+ if (flashMode() == mode)
+ return;
+
+ if (isActive() && !isFlashModeSupported(mode)) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "unsupported mode" << mode;
+ return;
+ }
+
+ flashModeChanged(mode);
+
+ if (!isActive())
+ return;
+
+ applyFlashSettings();
+}
+
+bool QAVFCameraBase::isFlashModeSupported(QCamera::FlashMode mode) const
+{
+ if (mode == QCamera::FlashOff)
+ return true;
+ else if (mode == QCamera::FlashOn)
+ return isFlashSupported;
+ else //if (mode == QCamera::FlashAuto)
+ return isFlashAutoSupported;
+}
+
+bool QAVFCameraBase::isFlashReady() const
+{
+ if (!isActive())
+ return false;
+
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice)
+ return false;
+
+ if (!captureDevice.hasFlash)
+ return false;
+
+ if (!isFlashModeSupported(flashMode()))
+ return false;
+
+ // AVCaptureDevice's docs:
+ // "The flash may become unavailable if, for example,
+ // the device overheats and needs to cool off."
+ return [captureDevice isFlashAvailable];
+}
+
+void QAVFCameraBase::setTorchMode(QCamera::TorchMode mode)
+{
+ if (torchMode() == mode)
+ return;
+
+ if (isActive() && !isTorchModeSupported(mode)) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "unsupported torch mode" << mode;
+ return;
+ }
+
+ torchModeChanged(mode);
+
+ if (!isActive())
+ return;
+
+ applyFlashSettings();
+}
+
+bool QAVFCameraBase::isTorchModeSupported(QCamera::TorchMode mode) const
+{
+ if (mode == QCamera::TorchOff)
+ return true;
+ else if (mode == QCamera::TorchOn)
+ return isTorchSupported;
+ else //if (mode == QCamera::TorchAuto)
+ return isTorchAutoSupported;
+}
+
+void QAVFCameraBase::setExposureMode(QCamera::ExposureMode qtMode)
+{
+#ifdef Q_OS_IOS
+ if (qtMode != QCamera::ExposureAuto && qtMode != QCamera::ExposureManual) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "exposure mode not supported";
+ return;
+ }
+
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice) {
+ exposureModeChanged(qtMode);
+ return;
+ }
+
+ AVCaptureExposureMode avMode = AVCaptureExposureModeContinuousAutoExposure;
+ if (!qt_convert_exposure_mode(captureDevice, qtMode, avMode)) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "exposure mode not supported";
+ return;
+ }
+
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to lock a capture device"
+ << "for configuration";
+ return;
+ }
+
+ [captureDevice setExposureMode:avMode];
+ exposureModeChanged(qtMode);
+#else
+ Q_UNUSED(qtMode);
+#endif
+}
+
+bool QAVFCameraBase::isExposureModeSupported(QCamera::ExposureMode mode) const
+{
+ if (mode == QCamera::ExposureAuto)
+ return true;
+ if (mode != QCamera::ExposureManual)
+ return false;
+
+ if (@available(macOS 10.15, *)) {
+ AVCaptureDevice *captureDevice = device();
+ return captureDevice && [captureDevice isExposureModeSupported:AVCaptureExposureModeCustom];
+ }
+
+ return false;
+}
+
+void QAVFCameraBase::applyFlashSettings()
+{
+ Q_ASSERT(isActive());
+
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "no capture device found";
+ return;
+ }
+
+ const AVFConfigurationLock lock(captureDevice);
+
+ if (captureDevice.hasFlash) {
+ const auto mode = flashMode();
+
+ auto setAvFlashModeSafe = [&captureDevice](AVCaptureFlashMode avFlashMode) {
+ // Note, in some cases captureDevice.hasFlash == false even though
+ // no there're no supported flash modes.
+ if ([captureDevice isFlashModeSupported:avFlashMode])
+ captureDevice.flashMode = avFlashMode;
+ else
+ qCDebug(qLcCamera) << "Attempt to setup unsupported flash mode " << avFlashMode;
+ };
+
+ if (mode == QCamera::FlashOff) {
+ setAvFlashModeSafe(AVCaptureFlashModeOff);
+ } else {
+ if ([captureDevice isFlashAvailable]) {
+ if (mode == QCamera::FlashOn)
+ setAvFlashModeSafe(AVCaptureFlashModeOn);
+ else if (mode == QCamera::FlashAuto)
+ setAvFlashModeSafe(AVCaptureFlashModeAuto);
+ } else {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "flash is not available at the moment";
+ }
+ }
+ }
+
+ if (captureDevice.hasTorch) {
+ const auto mode = torchMode();
+
+ auto setAvTorchModeSafe = [&captureDevice](AVCaptureTorchMode avTorchMode) {
+ if ([captureDevice isTorchModeSupported:avTorchMode])
+ captureDevice.torchMode = avTorchMode;
+ else
+ qCDebug(qLcCamera) << "Attempt to setup unsupported torch mode " << avTorchMode;
+ };
+
+ if (mode == QCamera::TorchOff) {
+ setAvTorchModeSafe(AVCaptureTorchModeOff);
+ } else {
+ if ([captureDevice isTorchAvailable]) {
+ if (mode == QCamera::TorchOn)
+ setAvTorchModeSafe(AVCaptureTorchModeOn);
+ else if (mode == QCamera::TorchAuto)
+ setAvTorchModeSafe(AVCaptureTorchModeAuto);
+ } else {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "torch is not available at the moment";
+ }
+ }
+ }
+}
+
+
+void QAVFCameraBase::setExposureCompensation(float bias)
+{
+#ifdef Q_OS_IOS
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice) {
+ exposureCompensationChanged(bias);
+ return;
+ }
+
+ bias = qBound(captureDevice.minExposureTargetBias, bias, captureDevice.maxExposureTargetBias);
+
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to lock for configuration";
+ return;
+ }
+
+ [captureDevice setExposureTargetBias:bias completionHandler:nil];
+ exposureCompensationChanged(bias);
+#else
+ Q_UNUSED(bias);
+#endif
+}
+
+void QAVFCameraBase::setManualExposureTime(float value)
+{
+#ifdef Q_OS_IOS
+ if (value < 0) {
+ setExposureMode(QCamera::ExposureAuto);
+ return;
+ }
+
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice) {
+ exposureTimeChanged(value);
+ return;
+ }
+
+ const CMTime newDuration = CMTimeMakeWithSeconds(value, captureDevice.exposureDuration.timescale);
+ if (!qt_check_exposure_duration(captureDevice, newDuration)) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "shutter speed value is out of range";
+ return;
+ }
+
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to lock for configuration";
+ return;
+ }
+
+ // Setting the shutter speed (exposure duration in Apple's terms,
+ // since there is no shutter actually) will also reset
+ // exposure mode into custom mode.
+ [captureDevice setExposureModeCustomWithDuration:newDuration
+ ISO:AVCaptureISOCurrent
+ completionHandler:nil];
+
+ exposureTimeChanged(value);
+
+#else
+ Q_UNUSED(value);
+#endif
+}
+
+float QAVFCameraBase::exposureTime() const
+{
+#ifdef Q_OS_IOS
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice)
+ return -1.;
+ auto duration = captureDevice.exposureDuration;
+ return CMTimeGetSeconds(duration);
+#else
+ return -1;
+#endif
+}
+
+#ifdef Q_OS_IOS
+namespace {
+
+void avf_convert_white_balance_mode(QCamera::WhiteBalanceMode qtMode,
+ AVCaptureWhiteBalanceMode &avMode)
+{
+ if (qtMode == QCamera::WhiteBalanceAuto)
+ avMode = AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance;
+ else
+ avMode = AVCaptureWhiteBalanceModeLocked;
+}
+
+bool avf_set_white_balance_mode(AVCaptureDevice *captureDevice,
+ AVCaptureWhiteBalanceMode avMode)
+{
+ Q_ASSERT(captureDevice);
+
+ const bool lock = [captureDevice lockForConfiguration:nil];
+ if (!lock) {
+ qDebug() << "Failed to lock a capture device for configuration\n";
+ return false;
+ }
+
+ captureDevice.whiteBalanceMode = avMode;
+ [captureDevice unlockForConfiguration];
+ return true;
+}
+
+bool avf_convert_temp_and_tint_to_wb_gains(AVCaptureDevice *captureDevice,
+ float temp, float tint, AVCaptureWhiteBalanceGains &wbGains)
+{
+ Q_ASSERT(captureDevice);
+
+ AVCaptureWhiteBalanceTemperatureAndTintValues wbTTValues = {
+ .temperature = temp,
+ .tint = tint
+ };
+ wbGains = [captureDevice deviceWhiteBalanceGainsForTemperatureAndTintValues:wbTTValues];
+
+ if (wbGains.redGain >= 1.0 && wbGains.redGain <= captureDevice.maxWhiteBalanceGain
+ && wbGains.greenGain >= 1.0 && wbGains.greenGain <= captureDevice.maxWhiteBalanceGain
+ && wbGains.blueGain >= 1.0 && wbGains.blueGain <= captureDevice.maxWhiteBalanceGain)
+ return true;
+
+ return false;
+}
+
+bool avf_set_white_balance_gains(AVCaptureDevice *captureDevice,
+ AVCaptureWhiteBalanceGains wbGains)
+{
+ const bool lock = [captureDevice lockForConfiguration:nil];
+ if (!lock) {
+ qDebug() << "Failed to lock a capture device for configuration\n";
+ return false;
+ }
+
+ [captureDevice setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:wbGains
+ completionHandler:nil];
+ [captureDevice unlockForConfiguration];
+ return true;
+}
+
+}
+
+bool QAVFCameraBase::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const
+{
+ if (mode == QCamera::WhiteBalanceAuto)
+ return true;
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice)
+ return false;
+ return [captureDevice isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeLocked];
+}
+
+void QAVFCameraBase::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)
+{
+ if (!isWhiteBalanceModeSupported(mode))
+ return;
+
+ AVCaptureDevice *captureDevice = device();
+ Q_ASSERT(captureDevice);
+
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to lock a capture device"
+ << "for configuration";
+ return;
+ }
+
+ AVCaptureWhiteBalanceMode avMode;
+ avf_convert_white_balance_mode(mode, avMode);
+ avf_set_white_balance_mode(captureDevice, avMode);
+
+ if (mode == QCamera::WhiteBalanceAuto || mode == QCamera::WhiteBalanceManual) {
+ whiteBalanceModeChanged(mode);
+ return;
+ }
+
+ const int colorTemp = colorTemperatureForWhiteBalance(mode);
+ AVCaptureWhiteBalanceGains wbGains;
+ if (avf_convert_temp_and_tint_to_wb_gains(captureDevice, colorTemp, 0., wbGains)
+ && avf_set_white_balance_gains(captureDevice, wbGains))
+ whiteBalanceModeChanged(mode);
+}
+
+void QAVFCameraBase::setColorTemperature(int colorTemp)
+{
+ if (colorTemp == 0) {
+ colorTemperatureChanged(colorTemp);
+ return;
+ }
+
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice || ![captureDevice isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeLocked])
+ return;
+
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to lock a capture device"
+ << "for configuration";
+ return;
+ }
+
+ AVCaptureWhiteBalanceGains wbGains;
+ if (avf_convert_temp_and_tint_to_wb_gains(captureDevice, colorTemp, 0., wbGains)
+ && avf_set_white_balance_gains(captureDevice, wbGains))
+ colorTemperatureChanged(colorTemp);
+}
+#endif
+
+void QAVFCameraBase::setManualIsoSensitivity(int value)
+{
+#ifdef Q_OS_IOS
+ if (value < 0) {
+ setExposureMode(QCamera::ExposureAuto);
+ return;
+ }
+
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice) {
+ isoSensitivityChanged(value);
+ return;
+ }
+
+ if (!qt_check_ISO_value(captureDevice, value)) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "ISO value is out of range";
+ return;
+ }
+
+ const AVFConfigurationLock lock(captureDevice);
+ if (!lock) {
+ qCDebug(qLcCamera) << Q_FUNC_INFO << "failed to lock a capture device"
+ << "for configuration";
+ return;
+ }
+
+ // Setting the ISO will also reset
+ // exposure mode to the custom mode.
+ [captureDevice setExposureModeCustomWithDuration:AVCaptureExposureDurationCurrent
+ ISO:value
+ completionHandler:nil];
+
+ isoSensitivityChanged(value);
+#else
+ Q_UNUSED(value);
+#endif
+}
+
+int QAVFCameraBase::isoSensitivity() const
+{
+ return manualIsoSensitivity();
+}
+
+
+#include "moc_qavfcamerabase_p.cpp"
diff --git a/src/plugins/multimedia/darwin/camera/qavfcamerabase_p.h b/src/plugins/multimedia/darwin/camera/qavfcamerabase_p.h
new file mode 100644
index 000000000..1ad3ba250
--- /dev/null
+++ b/src/plugins/multimedia/darwin/camera/qavfcamerabase_p.h
@@ -0,0 +1,110 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAVFCAMERABASE_H
+#define QAVFCAMERABASE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+
+#include <private/qplatformcamera_p.h>
+#include <private/qplatformvideodevices_p.h>
+
+Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureDeviceFormat);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureConnection);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureDevice);
+
+QT_BEGIN_NAMESPACE
+class QPlatformMediaIntegration;
+
+class QAVFVideoDevices : public QPlatformVideoDevices
+{
+public:
+ QAVFVideoDevices(QPlatformMediaIntegration *integration);
+ ~QAVFVideoDevices();
+
+ QList<QCameraDevice> videoDevices() const override;
+
+private:
+ void updateCameraDevices();
+
+ NSObject *m_deviceConnectedObserver;
+ NSObject *m_deviceDisconnectedObserver;
+
+ QList<QCameraDevice> m_cameraDevices;
+};
+
+
+class QAVFCameraBase : public QPlatformCamera
+{;
+Q_OBJECT
+public:
+ QAVFCameraBase(QCamera *camera);
+ ~QAVFCameraBase();
+
+ bool isActive() const override;
+ void setActive(bool activce) override;
+
+ void setCamera(const QCameraDevice &camera) override;
+ bool setCameraFormat(const QCameraFormat &format) override;
+
+ void setFocusMode(QCamera::FocusMode mode) override;
+ bool isFocusModeSupported(QCamera::FocusMode mode) const override;
+
+ void setCustomFocusPoint(const QPointF &point) override;
+
+ void setFocusDistance(float d) override;
+ void zoomTo(float factor, float rate) override;
+
+ void setFlashMode(QCamera::FlashMode mode) override;
+ bool isFlashModeSupported(QCamera::FlashMode mode) const override;
+ bool isFlashReady() const override;
+
+ void setTorchMode(QCamera::TorchMode mode) override;
+ bool isTorchModeSupported(QCamera::TorchMode mode) const override;
+
+ void setExposureMode(QCamera::ExposureMode) override;
+ bool isExposureModeSupported(QCamera::ExposureMode mode) const override;
+
+ void setExposureCompensation(float bias) override;
+ void setManualIsoSensitivity(int value) override;
+ virtual int isoSensitivity() const override;
+ void setManualExposureTime(float value) override;
+ virtual float exposureTime() const override;
+
+#ifdef Q_OS_IOS
+ // not supported on macOS
+ bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override;
+ void setWhiteBalanceMode(QCamera::WhiteBalanceMode /*mode*/) override;
+ void setColorTemperature(int /*temperature*/) override;
+#endif
+
+ AVCaptureDevice *device() const;
+
+protected:
+ void updateCameraConfiguration();
+ void updateCameraProperties();
+ void applyFlashSettings();
+
+ QCameraDevice m_cameraDevice;
+ bool m_active = false;
+private:
+ bool isFlashSupported = false;
+ bool isFlashAutoSupported = false;
+ bool isTorchSupported = false;
+ bool isTorchAutoSupported = false;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/darwin/common/avfmetadata.mm b/src/plugins/multimedia/darwin/common/avfmetadata.mm
new file mode 100644
index 000000000..da07f69c6
--- /dev/null
+++ b/src/plugins/multimedia/darwin/common/avfmetadata.mm
@@ -0,0 +1,382 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfmetadata_p.h"
+#include <qdarwinformatsinfo_p.h>
+#include <avfmediaplayer_p.h>
+
+#include <QtCore/qbuffer.h>
+#include <QtCore/qiodevice.h>
+#include <QtCore/qdatetime.h>
+#include <QtCore/qlocale.h>
+#include <QtCore/qurl.h>
+#include <QImage>
+#include <QtMultimedia/qvideoframe.h>
+
+#if __has_include(<AppKit/AppKit.h>)
+#include <AppKit/AppKit.h>
+#endif
+
+#include <CoreFoundation/CoreFoundation.h>
+
+QT_USE_NAMESPACE
+
+struct AVMetadataIDs {
+ AVMetadataIdentifier common;
+ AVMetadataIdentifier iTunes;
+ AVMetadataIdentifier quickTime;
+ AVMetadataIdentifier ID3;
+ AVMetadataIdentifier quickTimeUserData;
+ AVMetadataIdentifier isoUserData;
+};
+
+const AVMetadataIDs keyToAVMetaDataID[] = {
+ // Title
+ { AVMetadataCommonIdentifierTitle, AVMetadataIdentifieriTunesMetadataSongName,
+ AVMetadataIdentifierQuickTimeMetadataTitle,
+ AVMetadataIdentifierID3MetadataTitleDescription,
+ nil, AVMetadata3GPUserDataKeyTitle },
+ // Author
+ { AVMetadataCommonIdentifierAuthor,AVMetadataIdentifieriTunesMetadataAuthor,
+ AVMetadataIdentifierQuickTimeMetadataAuthor, nil,
+ AVMetadataQuickTimeUserDataKeyAuthor, AVMetadata3GPUserDataKeyAuthor },
+ // Comment
+ { nil, AVMetadataIdentifieriTunesMetadataUserComment,
+ AVMetadataIdentifierQuickTimeMetadataComment, AVMetadataIdentifierID3MetadataComments,
+ AVMetadataQuickTimeUserDataKeyComment, nil },
+ // Description
+ { AVMetadataCommonIdentifierDescription,AVMetadataIdentifieriTunesMetadataDescription,
+ AVMetadataIdentifierQuickTimeMetadataDescription, nil,
+ AVMetadataQuickTimeUserDataKeyDescription, AVMetadata3GPUserDataKeyDescription },
+ // Genre
+ { nil, AVMetadataIdentifieriTunesMetadataUserGenre,
+ AVMetadataIdentifierQuickTimeMetadataGenre, nil,
+ AVMetadataQuickTimeUserDataKeyGenre, AVMetadata3GPUserDataKeyGenre },
+ // Date
+ { AVMetadataCommonIdentifierCreationDate, AVMetadataIdentifieriTunesMetadataReleaseDate,
+ AVMetadataIdentifierQuickTimeMetadataCreationDate, AVMetadataIdentifierID3MetadataDate,
+ AVMetadataQuickTimeUserDataKeyCreationDate, AVMetadataISOUserDataKeyDate },
+ // Language
+ { AVMetadataCommonIdentifierLanguage, nil, nil, AVMetadataIdentifierID3MetadataLanguage, nil, nil },
+ // Publisher
+ { AVMetadataCommonIdentifierPublisher, AVMetadataIdentifieriTunesMetadataPublisher,
+ AVMetadataIdentifierQuickTimeMetadataPublisher, AVMetadataIdentifierID3MetadataPublisher, nil, nil },
+ // Copyright
+ { AVMetadataCommonIdentifierCopyrights, AVMetadataIdentifieriTunesMetadataCopyright,
+ AVMetadataIdentifierQuickTimeMetadataCopyright, AVMetadataIdentifierID3MetadataCopyright,
+ AVMetadataQuickTimeUserDataKeyCopyright, AVMetadataISOUserDataKeyCopyright },
+ // Url
+ { nil, nil, nil, AVMetadataIdentifierID3MetadataOfficialAudioSourceWebpage, nil, nil },
+ // Duration
+ { nil, nil, nil, AVMetadataIdentifierID3MetadataLength, nil, nil },
+ // MediaType
+ { AVMetadataCommonIdentifierType, nil, nil, AVMetadataIdentifierID3MetadataContentType, nil, nil },
+ // FileFormat
+ { nil, nil, nil, AVMetadataIdentifierID3MetadataFileType, nil, nil },
+ // AudioBitRate
+ { nil, nil, nil, nil, nil, nil },
+ // AudioCodec
+ { nil, nil, nil, nil, nil, nil },
+ // VideoBitRate
+ { nil, nil, nil, nil, nil, nil },
+ // VideoCodec
+ { nil, nil, nil, nil, nil, nil },
+ // VideoFrameRate
+ { nil, nil, AVMetadataIdentifierQuickTimeMetadataCameraFrameReadoutTime, nil, nil, nil },
+ // AlbumTitle
+ { AVMetadataCommonIdentifierAlbumName, AVMetadataIdentifieriTunesMetadataAlbum,
+ AVMetadataIdentifierQuickTimeMetadataAlbum, AVMetadataIdentifierID3MetadataAlbumTitle,
+ AVMetadataQuickTimeUserDataKeyAlbum, AVMetadata3GPUserDataKeyAlbumAndTrack },
+ // AlbumArtist
+ { nil, AVMetadataIdentifieriTunesMetadataAlbumArtist, nil, nil,
+ AVMetadataQuickTimeUserDataKeyArtist, AVMetadata3GPUserDataKeyPerformer },
+ // ContributingArtist
+ { AVMetadataCommonIdentifierArtist, AVMetadataIdentifieriTunesMetadataArtist,
+ AVMetadataIdentifierQuickTimeMetadataArtist, nil, nil, nil },
+ // TrackNumber
+ { nil, AVMetadataIdentifieriTunesMetadataTrackNumber,
+ nil, AVMetadataIdentifierID3MetadataTrackNumber, nil, nil },
+ // Composer
+ { nil, AVMetadataIdentifieriTunesMetadataComposer,
+ AVMetadataIdentifierQuickTimeMetadataComposer, AVMetadataIdentifierID3MetadataComposer, nil, nil },
+ // LeadPerformer
+ { nil, AVMetadataIdentifieriTunesMetadataPerformer,
+ AVMetadataIdentifierQuickTimeMetadataPerformer, AVMetadataIdentifierID3MetadataLeadPerformer, nil, nil },
+ // ThumbnailImage
+ { nil, nil, nil, AVMetadataIdentifierID3MetadataAttachedPicture, nil, nil },
+ // CoverArtImage
+ { AVMetadataCommonIdentifierArtwork, AVMetadataIdentifieriTunesMetadataCoverArt,
+ AVMetadataIdentifierQuickTimeMetadataArtwork, nil, nil, nil },
+ // Orientation
+ { nil, nil, AVMetadataIdentifierQuickTimeMetadataVideoOrientation, nil, nil, nil },
+ // Resolution
+ { nil, nil, nil, nil, nil, nil }
+};
+
+static AVMetadataIdentifier toIdentifier(QMediaMetaData::Key key, AVMetadataKeySpace keySpace)
+{
+ static_assert(sizeof(keyToAVMetaDataID)/sizeof(AVMetadataIDs) == QMediaMetaData::Key::Resolution + 1);
+
+ AVMetadataIdentifier identifier = nil;
+ if ([keySpace isEqualToString:AVMetadataKeySpaceiTunes]) {
+ identifier = keyToAVMetaDataID[key].iTunes;
+ } else if ([keySpace isEqualToString:AVMetadataKeySpaceID3]) {
+ identifier = keyToAVMetaDataID[key].ID3;
+ } else if ([keySpace isEqualToString:AVMetadataKeySpaceQuickTimeMetadata]) {
+ identifier = keyToAVMetaDataID[key].quickTime;
+ } else {
+ identifier = keyToAVMetaDataID[key].common;
+ }
+ return identifier;
+}
+
+static std::optional<QMediaMetaData::Key> toKey(AVMetadataItem *item)
+{
+ static_assert(sizeof(keyToAVMetaDataID)/sizeof(AVMetadataIDs) == QMediaMetaData::Key::Resolution + 1);
+
+ // The item identifier may be different than the ones we support,
+ // so check by common key first, as it will get the metadata
+ // irrespective of the format.
+ AVMetadataKey commonKey = item.commonKey;
+ if (commonKey.length != 0) {
+ if ([commonKey isEqualToString:AVMetadataCommonKeyTitle]) {
+ return QMediaMetaData::Title;
+ } else if ([commonKey isEqualToString:AVMetadataCommonKeyDescription]) {
+ return QMediaMetaData::Description;
+ } else if ([commonKey isEqualToString:AVMetadataCommonKeyPublisher]) {
+ return QMediaMetaData::Publisher;
+ } else if ([commonKey isEqualToString:AVMetadataCommonKeyCreationDate]) {
+ return QMediaMetaData::Date;
+ } else if ([commonKey isEqualToString:AVMetadataCommonKeyType]) {
+ return QMediaMetaData::MediaType;
+ } else if ([commonKey isEqualToString:AVMetadataCommonKeyLanguage]) {
+ return QMediaMetaData::Language;
+ } else if ([commonKey isEqualToString:AVMetadataCommonKeyCopyrights]) {
+ return QMediaMetaData::Copyright;
+ } else if ([commonKey isEqualToString:AVMetadataCommonKeyAlbumName]) {
+ return QMediaMetaData::AlbumTitle;
+ } else if ([commonKey isEqualToString:AVMetadataCommonKeyAuthor]) {
+ return QMediaMetaData::Author;
+ } else if ([commonKey isEqualToString:AVMetadataCommonKeyArtist]) {
+ return QMediaMetaData::ContributingArtist;
+ }
+ }
+
+ // Check by identifier if no common key found
+ // No need to check for the common keySpace since there's no common key
+ enum keySpaces { iTunes, QuickTime, QuickTimeUserData, IsoUserData, ID3, Other } itemKeySpace;
+ itemKeySpace = Other;
+ AVMetadataKeySpace keySpace = [item keySpace];
+ AVMetadataIdentifier identifier = [item identifier];
+
+ if ([keySpace isEqualToString:AVMetadataKeySpaceiTunes]) {
+ itemKeySpace = iTunes;
+ } else if ([keySpace isEqualToString:AVMetadataKeySpaceQuickTimeMetadata]) {
+ itemKeySpace = QuickTime;
+ } else if ([keySpace isEqualToString:AVMetadataKeySpaceQuickTimeUserData]) {
+ itemKeySpace = QuickTimeUserData;
+ } else if ([keySpace isEqualToString:AVMetadataKeySpaceISOUserData]) {
+ itemKeySpace = IsoUserData;
+ } else if (([keySpace isEqualToString:AVMetadataKeySpaceID3])) {
+ itemKeySpace = ID3;
+ }
+
+ for (int key = 0; key < QMediaMetaData::Resolution + 1; key++) {
+ AVMetadataIdentifier idForKey = nil;
+ switch (itemKeySpace) {
+ case iTunes:
+ idForKey = keyToAVMetaDataID[key].iTunes;
+ break;
+ case QuickTime:
+ idForKey = keyToAVMetaDataID[key].quickTime;
+ break;
+ case ID3:
+ idForKey = keyToAVMetaDataID[key].ID3;
+ break;
+ case QuickTimeUserData:
+ idForKey = keyToAVMetaDataID[key].quickTimeUserData;
+ break;
+ case IsoUserData:
+ idForKey = keyToAVMetaDataID[key].isoUserData;
+ break;
+ default:
+ break;
+ }
+
+ if ([identifier isEqualToString:idForKey])
+ return QMediaMetaData::Key(key);
+ }
+
+ return std::nullopt;
+}
+
+static QMediaMetaData fromAVMetadata(NSArray *metadataItems)
+{
+ QMediaMetaData metadata;
+
+ for (AVMetadataItem* item in metadataItems) {
+ auto key = toKey(item);
+ if (!key)
+ continue;
+
+ const QString value = QString::fromNSString([item stringValue]);
+ if (!value.isNull())
+ metadata.insert(*key, value);
+ }
+ return metadata;
+}
+
+QMediaMetaData AVFMetaData::fromAsset(AVAsset *asset)
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO;
+#endif
+ QMediaMetaData metadata = fromAVMetadata([asset metadata]);
+
+ // add duration
+ const CMTime time = [asset duration];
+ const qint64 duration = static_cast<qint64>(float(time.value) / float(time.timescale) * 1000.0f);
+ metadata.insert(QMediaMetaData::Duration, duration);
+
+ return metadata;
+}
+
+QMediaMetaData AVFMetaData::fromAssetTrack(AVAssetTrack *asset)
+{
+ QMediaMetaData metadata = fromAVMetadata([asset metadata]);
+ if ([asset.mediaType isEqualToString:AVMediaTypeAudio]) {
+ if (metadata.value(QMediaMetaData::Language).isNull()) {
+ auto *languageCode = asset.languageCode;
+ if (languageCode) {
+ // languageCode is encoded as ISO 639-2, which QLocale does not handle.
+ // Convert it to 639-1 first.
+ auto id = CFLocaleCreateCanonicalLanguageIdentifierFromString(kCFAllocatorDefault,
+ (__bridge CFStringRef)languageCode);
+ QString lang = QString::fromCFString(id);
+ CFRelease(id);
+ metadata.insert(QMediaMetaData::Language, QLocale::codeToLanguage(lang));
+ }
+ }
+ }
+ if ([asset.mediaType isEqualToString:AVMediaTypeVideo]) {
+ // add orientation
+ if (metadata.value(QMediaMetaData::Orientation).isNull()) {
+ QtVideo::Rotation angle = QtVideo::Rotation::None;
+ bool mirrored;
+ AVFMediaPlayer::videoOrientationForAssetTrack(asset, angle, mirrored);
+ Q_UNUSED(mirrored);
+ metadata.insert(QMediaMetaData::Orientation, int(angle));
+ }
+ }
+ return metadata;
+}
+
+static AVMutableMetadataItem *setAVMetadataItemForKey(QMediaMetaData::Key key, const QVariant &value,
+ AVMetadataKeySpace keySpace = AVMetadataKeySpaceCommon)
+{
+ AVMetadataIdentifier identifier = toIdentifier(key, keySpace);
+ if (!identifier.length)
+ return nil;
+
+ AVMutableMetadataItem *item = [AVMutableMetadataItem metadataItem];
+ item.keySpace = keySpace;
+ item.identifier = identifier;
+
+ switch (key) {
+ case QMediaMetaData::ThumbnailImage:
+ case QMediaMetaData::CoverArtImage: {
+#if defined(Q_OS_MACOS)
+ QImage img = value.value<QImage>();
+ if (!img.isNull()) {
+ QByteArray arr;
+ QBuffer buffer(&arr);
+ buffer.open(QIODevice::WriteOnly);
+ img.save(&buffer);
+ NSData *data = arr.toNSData();
+ NSImage *nsImg = [[NSImage alloc] initWithData:data];
+ item.value = nsImg;
+ [nsImg release];
+ }
+#endif
+ break;
+ }
+ case QMediaMetaData::FileFormat: {
+ QMediaFormat::FileFormat qtFormat = value.value<QMediaFormat::FileFormat>();
+ AVFileType avFormat = QDarwinFormatInfo::avFileTypeForContainerFormat(qtFormat);
+ item.value = avFormat;
+ break;
+ }
+ case QMediaMetaData::Language: {
+ QString lang = QLocale::languageToCode(value.value<QLocale::Language>());
+ if (!lang.isEmpty())
+ item.value = lang.toNSString();
+ break;
+ }
+ case QMediaMetaData::Orientation: {
+ bool ok;
+ int rotation = value.toInt(&ok);
+ if (ok)
+ item.value = [NSNumber numberWithInt:rotation];
+ }
+ default: {
+ switch (value.typeId()) {
+ case QMetaType::QString: {
+ item.value = value.toString().toNSString();
+ break;
+ }
+ case QMetaType::Int: {
+ item.value = [NSNumber numberWithInt:value.toInt()];
+ break;
+ }
+ case QMetaType::LongLong: {
+ item.value = [NSNumber numberWithLongLong:value.toLongLong()];
+ break;
+ }
+ case QMetaType::Double: {
+ item.value = [NSNumber numberWithDouble:value.toDouble()];
+ break;
+ }
+ case QMetaType::QDate:
+ case QMetaType::QDateTime: {
+ item.value = value.toDateTime().toNSDate();
+ break;
+ }
+ case QMetaType::QUrl: {
+ item.value = value.toUrl().toNSURL();
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ }
+
+ return item;
+}
+
+NSMutableArray<AVMetadataItem *> *AVFMetaData::toAVMetadataForFormat(QMediaMetaData metadata, AVFileType format)
+{
+ NSMutableArray<AVMetadataKeySpace> *keySpaces = [NSMutableArray<AVMetadataKeySpace> array];
+ if (format == AVFileTypeAppleM4A) {
+ [keySpaces addObject:AVMetadataKeySpaceiTunes];
+ } else if (format == AVFileTypeMPEGLayer3) {
+ [keySpaces addObject:AVMetadataKeySpaceID3];
+ [keySpaces addObject:AVMetadataKeySpaceiTunes];
+ } else if (format == AVFileTypeQuickTimeMovie) {
+ [keySpaces addObject:AVMetadataKeySpaceQuickTimeMetadata];
+ } else {
+ [keySpaces addObject:AVMetadataKeySpaceCommon];
+ }
+ NSMutableArray<AVMetadataItem *> *avMetaDataArr = [NSMutableArray array];
+ for (const auto &key : metadata.keys()) {
+ for (NSUInteger i = 0; i < [keySpaces count]; i++) {
+ const QVariant &value = metadata.value(key);
+ // set format-specific metadata
+ AVMetadataItem *item = setAVMetadataItemForKey(key, value, keySpaces[i]);
+ if (item)
+ [avMetaDataArr addObject:item];
+ }
+ }
+ return avMetaDataArr;
+}
+
diff --git a/src/plugins/multimedia/darwin/common/avfmetadata_p.h b/src/plugins/multimedia/darwin/common/avfmetadata_p.h
new file mode 100644
index 000000000..d1cb2e7e8
--- /dev/null
+++ b/src/plugins/multimedia/darwin/common/avfmetadata_p.h
@@ -0,0 +1,37 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFMEDIAPLAYERMETADATACONTROL_H
+#define AVFMEDIAPLAYERMETADATACONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/QMediaMetaData>
+#include <QtCore/qvariant.h>
+
+#import <AVFoundation/AVFoundation.h>
+
+QT_BEGIN_NAMESPACE
+
+class AVFMediaPlayer;
+
+class AVFMetaData
+{
+public:
+ static QMediaMetaData fromAsset(AVAsset *asset);
+ static QMediaMetaData fromAssetTrack(AVAssetTrack *asset);
+ static NSMutableArray<AVMetadataItem *> *toAVMetadataForFormat(QMediaMetaData metaData, AVFileType format);
+};
+
+QT_END_NAMESPACE
+
+#endif // AVFMEDIAPLAYERMETADATACONTROL_H
diff --git a/src/plugins/multimedia/darwin/darwin.json b/src/plugins/multimedia/darwin/darwin.json
new file mode 100644
index 000000000..f72350b17
--- /dev/null
+++ b/src/plugins/multimedia/darwin/darwin.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "darwin" ]
+}
diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink.mm b/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink.mm
new file mode 100644
index 000000000..8c6561f37
--- /dev/null
+++ b/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink.mm
@@ -0,0 +1,207 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfdisplaylink_p.h"
+#include <QtCore/qcoreapplication.h>
+
+#ifdef QT_DEBUG_AVF
+#include <QtCore/qdebug.h>
+#endif
+
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+#import <QuartzCore/CADisplayLink.h>
+#import <Foundation/NSRunLoop.h>
+#define _m_displayLink static_cast<DisplayLinkObserver*>(m_displayLink)
+#else
+#endif
+
+QT_USE_NAMESPACE
+
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+@interface DisplayLinkObserver : NSObject
+
+- (void)start;
+- (void)stop;
+- (void)displayLinkNotification:(CADisplayLink *)sender;
+
+@end
+
+@implementation DisplayLinkObserver
+{
+ AVFDisplayLink *m_avfDisplayLink;
+ CADisplayLink *m_displayLink;
+}
+
+- (id)initWithAVFDisplayLink:(AVFDisplayLink *)link
+{
+ self = [super init];
+
+ if (self) {
+ m_avfDisplayLink = link;
+ m_displayLink = [[CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkNotification:)] retain];
+ }
+
+ return self;
+}
+
+- (void) dealloc
+{
+ if (m_displayLink) {
+ [m_displayLink release];
+ m_displayLink = nullptr;
+ }
+
+ [super dealloc];
+}
+
+- (void)start
+{
+ [m_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+}
+
+- (void)stop
+{
+ [m_displayLink removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+}
+
+- (void)displayLinkNotification:(CADisplayLink *)sender
+{
+ Q_UNUSED(sender);
+ m_avfDisplayLink->displayLinkEvent(nullptr);
+}
+
+@end
+#else
+static CVReturn CVDisplayLinkCallback(CVDisplayLinkRef displayLink,
+ const CVTimeStamp *inNow,
+ const CVTimeStamp *inOutputTime,
+ CVOptionFlags flagsIn,
+ CVOptionFlags *flagsOut,
+ void *displayLinkContext)
+{
+ Q_UNUSED(displayLink);
+ Q_UNUSED(inNow);
+ Q_UNUSED(flagsIn);
+ Q_UNUSED(flagsOut);
+
+ AVFDisplayLink *link = (AVFDisplayLink *)displayLinkContext;
+
+ link->displayLinkEvent(inOutputTime);
+ return kCVReturnSuccess;
+}
+#endif
+
+AVFDisplayLink::AVFDisplayLink(QObject *parent)
+ : QObject(parent)
+ , m_displayLink(nullptr)
+ , m_pendingDisplayLinkEvent(false)
+ , m_isActive(false)
+{
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+ m_displayLink = [[DisplayLinkObserver alloc] initWithAVFDisplayLink:this];
+#else
+ // create display link for the main display
+ CVDisplayLinkCreateWithCGDisplay(kCGDirectMainDisplay, &m_displayLink);
+ if (m_displayLink) {
+ // set the current display of a display link.
+ CVDisplayLinkSetCurrentCGDisplay(m_displayLink, kCGDirectMainDisplay);
+
+ // set the renderer output callback function
+ CVDisplayLinkSetOutputCallback(m_displayLink, &CVDisplayLinkCallback, this);
+ }
+#endif
+}
+
+AVFDisplayLink::~AVFDisplayLink()
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO;
+#endif
+
+ if (m_displayLink) {
+ stop();
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+ [_m_displayLink release];
+#else
+ CVDisplayLinkRelease(m_displayLink);
+#endif
+ m_displayLink = nullptr;
+ }
+}
+
+bool AVFDisplayLink::isValid() const
+{
+ return m_displayLink != nullptr;
+}
+
+bool AVFDisplayLink::isActive() const
+{
+ return m_isActive;
+}
+
+void AVFDisplayLink::start()
+{
+ if (m_displayLink && !m_isActive) {
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+ [_m_displayLink start];
+#else
+ CVDisplayLinkStart(m_displayLink);
+#endif
+ m_isActive = true;
+ }
+}
+
+void AVFDisplayLink::stop()
+{
+ if (m_displayLink && m_isActive) {
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+ [_m_displayLink stop];
+#else
+ CVDisplayLinkStop(m_displayLink);
+#endif
+ m_isActive = false;
+ }
+}
+
+void AVFDisplayLink::displayLinkEvent(const CVTimeStamp *ts)
+{
+ // This function is called from a
+ // thread != gui thread. So we post the event.
+ // But we need to make sure that we don't post faster
+ // than the event loop can eat:
+ m_displayLinkMutex.lock();
+ bool pending = m_pendingDisplayLinkEvent;
+ m_pendingDisplayLinkEvent = true;
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+ Q_UNUSED(ts);
+ memset(&m_frameTimeStamp, 0, sizeof(CVTimeStamp));
+#else
+ m_frameTimeStamp = *ts;
+#endif
+ m_displayLinkMutex.unlock();
+
+ if (!pending)
+ qApp->postEvent(this, new QEvent(QEvent::User), Qt::HighEventPriority);
+}
+
+bool AVFDisplayLink::event(QEvent *event)
+{
+ switch (event->type()){
+ case QEvent::User: {
+ m_displayLinkMutex.lock();
+ m_pendingDisplayLinkEvent = false;
+ CVTimeStamp ts = m_frameTimeStamp;
+ m_displayLinkMutex.unlock();
+
+ Q_EMIT tick(ts);
+
+ return false;
+ }
+ break;
+ default:
+ break;
+ }
+ return QObject::event(event);
+}
+
+#include "moc_avfdisplaylink_p.cpp"
diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink_p.h b/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink_p.h
new file mode 100644
index 000000000..c4eb504a5
--- /dev/null
+++ b/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink_p.h
@@ -0,0 +1,65 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFDISPLAYLINK_H
+#define AVFDISPLAYLINK_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+#include <QtCore/qmutex.h>
+
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+#include <CoreVideo/CVBase.h>
+#else
+#include <QuartzCore/CVDisplayLink.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class AVFDisplayLink : public QObject
+{
+ Q_OBJECT
+public:
+ explicit AVFDisplayLink(QObject *parent = nullptr);
+ virtual ~AVFDisplayLink();
+ bool isValid() const;
+ bool isActive() const;
+
+public Q_SLOTS:
+ void start();
+ void stop();
+
+Q_SIGNALS:
+ void tick(const CVTimeStamp &ts);
+
+public:
+ void displayLinkEvent(const CVTimeStamp *);
+
+protected:
+ virtual bool event(QEvent *) override;
+
+private:
+#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
+ void *m_displayLink;
+#else
+ CVDisplayLinkRef m_displayLink;
+#endif
+ QMutex m_displayLinkMutex;
+ bool m_pendingDisplayLinkEvent;
+ bool m_isActive;
+ CVTimeStamp m_frameTimeStamp;
+};
+
+QT_END_NAMESPACE
+
+#endif // AVFDISPLAYLINK_H
diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer.mm b/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer.mm
new file mode 100644
index 000000000..964964a8e
--- /dev/null
+++ b/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer.mm
@@ -0,0 +1,1270 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfmediaplayer_p.h"
+#include "avfvideorenderercontrol_p.h"
+#include <avfvideosink_p.h>
+#include <avfmetadata_p.h>
+
+#include "qaudiooutput.h"
+#include "private/qplatformaudiooutput_p.h"
+
+#include <qpointer.h>
+#include <QFileInfo>
+#include <QtCore/qmath.h>
+#include <QtCore/qmutex.h>
+
+#import <AVFoundation/AVFoundation.h>
+
+QT_USE_NAMESPACE
+
+//AVAsset Keys
+static NSString* const AVF_TRACKS_KEY = @"tracks";
+static NSString* const AVF_PLAYABLE_KEY = @"playable";
+
+//AVPlayerItem keys
+static NSString* const AVF_STATUS_KEY = @"status";
+static NSString* const AVF_BUFFER_LIKELY_KEEP_UP_KEY = @"playbackLikelyToKeepUp";
+
+//AVPlayer keys
+static NSString* const AVF_RATE_KEY = @"rate";
+static NSString* const AVF_CURRENT_ITEM_KEY = @"currentItem";
+static NSString* const AVF_CURRENT_ITEM_DURATION_KEY = @"currentItem.duration";
+
+static void *AVFMediaPlayerObserverRateObservationContext = &AVFMediaPlayerObserverRateObservationContext;
+static void *AVFMediaPlayerObserverStatusObservationContext = &AVFMediaPlayerObserverStatusObservationContext;
+static void *AVFMediaPlayerObserverPresentationSizeContext = &AVFMediaPlayerObserverPresentationSizeContext;
+static void *AVFMediaPlayerObserverBufferLikelyToKeepUpContext = &AVFMediaPlayerObserverBufferLikelyToKeepUpContext;
+static void *AVFMediaPlayerObserverTracksContext = &AVFMediaPlayerObserverTracksContext;
+static void *AVFMediaPlayerObserverCurrentItemObservationContext = &AVFMediaPlayerObserverCurrentItemObservationContext;
+static void *AVFMediaPlayerObserverCurrentItemDurationObservationContext = &AVFMediaPlayerObserverCurrentItemDurationObservationContext;
+
+@interface AVFMediaPlayerObserver : NSObject<AVAssetResourceLoaderDelegate>
+
+@property (readonly, getter=player) AVPlayer* m_player;
+@property (readonly, getter=playerItem) AVPlayerItem* m_playerItem;
+@property (readonly, getter=playerLayer) AVPlayerLayer* m_playerLayer;
+@property (readonly, getter=session) AVFMediaPlayer* m_session;
+@property (retain) AVPlayerItemTrack *videoTrack;
+
+- (AVFMediaPlayerObserver *) initWithMediaPlayerSession:(AVFMediaPlayer *)session;
+- (void) setURL:(NSURL *)url mimeType:(NSString *)mimeType;
+- (void) unloadMedia;
+- (void) prepareToPlayAsset:(AVURLAsset *)asset withKeys:(NSArray *)requestedKeys;
+- (void) assetFailedToPrepareForPlayback:(NSError *)error;
+- (void) playerItemDidReachEnd:(NSNotification *)notification;
+- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
+ change:(NSDictionary *)change context:(void *)context;
+- (void) detatchSession;
+- (void) dealloc;
+- (BOOL) resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest;
+@end
+
+#ifdef Q_OS_IOS
+// Alas, no such thing as 'class variable', hence globals:
+static unsigned sessionActivationCount;
+static QMutex sessionMutex;
+#endif // Q_OS_IOS
+
+@implementation AVFMediaPlayerObserver
+{
+@private
+ AVFMediaPlayer *m_session;
+ AVPlayer *m_player;
+ AVPlayerItem *m_playerItem;
+ AVPlayerLayer *m_playerLayer;
+ NSURL *m_URL;
+ BOOL m_bufferIsLikelyToKeepUp;
+ NSData *m_data;
+ NSString *m_mimeType;
+#ifdef Q_OS_IOS
+ BOOL m_activated;
+#endif
+}
+
+@synthesize m_player, m_playerItem, m_playerLayer, m_session;
+
+#ifdef Q_OS_IOS
+- (void)setSessionActive:(BOOL)active
+{
+ const QMutexLocker lock(&sessionMutex);
+ if (active) {
+ // Don't count the same player twice if already activated,
+ // unless it tried to deactivate first:
+ if (m_activated)
+ return;
+ if (!sessionActivationCount)
+ [AVAudioSession.sharedInstance setActive:YES error:nil];
+ ++sessionActivationCount;
+ m_activated = YES;
+ } else {
+ if (!sessionActivationCount || !m_activated) {
+ qWarning("Unbalanced audio session deactivation, ignoring.");
+ return;
+ }
+ --sessionActivationCount;
+ m_activated = NO;
+ if (!sessionActivationCount)
+ [AVAudioSession.sharedInstance setActive:NO error:nil];
+ }
+}
+#endif // Q_OS_IOS
+
+- (AVFMediaPlayerObserver *) initWithMediaPlayerSession:(AVFMediaPlayer *)session
+{
+ if (!(self = [super init]))
+ return nil;
+
+ m_session = session;
+ m_bufferIsLikelyToKeepUp = FALSE;
+
+ m_playerLayer = [AVPlayerLayer playerLayerWithPlayer:nil];
+ [m_playerLayer retain];
+ m_playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
+ m_playerLayer.anchorPoint = CGPointMake(0.0f, 0.0f);
+ return self;
+}
+
+- (void) setURL:(NSURL *)url mimeType:(NSString *)mimeType
+{
+ if (!m_session)
+ return;
+
+ [m_mimeType release];
+ m_mimeType = [mimeType retain];
+
+ if (m_URL != url)
+ {
+ [m_URL release];
+ m_URL = [url copy];
+
+ //Create an asset for inspection of a resource referenced by a given URL.
+ //Load the values for the asset keys "tracks", "playable".
+
+ // use __block to avoid maintaining strong references on variables captured by the
+ // following block callback
+#if defined(Q_OS_IOS)
+ BOOL isAccessing = [m_URL startAccessingSecurityScopedResource];
+#endif
+ __block AVURLAsset *asset = [[AVURLAsset URLAssetWithURL:m_URL options:nil] retain];
+ [asset.resourceLoader setDelegate:self queue:dispatch_get_main_queue()];
+
+ __block NSArray *requestedKeys = [[NSArray arrayWithObjects:AVF_TRACKS_KEY, AVF_PLAYABLE_KEY, nil] retain];
+
+ __block AVFMediaPlayerObserver *blockSelf = [self retain];
+
+ // Tells the asset to load the values of any of the specified keys that are not already loaded.
+ [asset loadValuesAsynchronouslyForKeys:requestedKeys completionHandler:
+ ^{
+ dispatch_async( dispatch_get_main_queue(),
+ ^{
+#if defined(Q_OS_IOS)
+ if (isAccessing)
+ [m_URL stopAccessingSecurityScopedResource];
+#endif
+ [blockSelf prepareToPlayAsset:asset withKeys:requestedKeys];
+ [asset release];
+ [requestedKeys release];
+ [blockSelf release];
+ });
+ }];
+ }
+}
+
+- (void) unloadMedia
+{
+ if (m_playerItem) {
+ [m_playerItem removeObserver:self forKeyPath:@"presentationSize"];
+ [m_playerItem removeObserver:self forKeyPath:AVF_STATUS_KEY];
+ [m_playerItem removeObserver:self forKeyPath:AVF_BUFFER_LIKELY_KEEP_UP_KEY];
+ [m_playerItem removeObserver:self forKeyPath:AVF_TRACKS_KEY];
+
+ [[NSNotificationCenter defaultCenter] removeObserver:self
+ name:AVPlayerItemDidPlayToEndTimeNotification
+ object:m_playerItem];
+ m_playerItem = 0;
+ }
+ if (m_player) {
+ [m_player setRate:0.0];
+ [m_player removeObserver:self forKeyPath:AVF_CURRENT_ITEM_DURATION_KEY];
+ [m_player removeObserver:self forKeyPath:AVF_CURRENT_ITEM_KEY];
+ [m_player removeObserver:self forKeyPath:AVF_RATE_KEY];
+ [m_player release];
+ m_player = 0;
+ }
+ if (m_playerLayer)
+ m_playerLayer.player = nil;
+#if defined(Q_OS_IOS)
+ [self setSessionActive:NO];
+#endif
+}
+
+- (void) prepareToPlayAsset:(AVURLAsset *)asset
+ withKeys:(NSArray *)requestedKeys
+{
+ if (!m_session)
+ return;
+
+ //Make sure that the value of each key has loaded successfully.
+ for (NSString *thisKey in requestedKeys)
+ {
+ NSError *error = nil;
+ AVKeyValueStatus keyStatus = [asset statusOfValueForKey:thisKey error:&error];
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << [thisKey UTF8String] << " status: " << keyStatus;
+#endif
+ if (keyStatus == AVKeyValueStatusFailed)
+ {
+ [self assetFailedToPrepareForPlayback:error];
+ return;
+ }
+ }
+
+ //Use the AVAsset playable property to detect whether the asset can be played.
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << "isPlayable: " << [asset isPlayable];
+#endif
+ if (!asset.playable)
+ qWarning() << "Asset reported to be not playable. Playback of this asset may not be possible.";
+
+ //At this point we're ready to set up for playback of the asset.
+ //Stop observing our prior AVPlayerItem, if we have one.
+ if (m_playerItem)
+ {
+ //Remove existing player item key value observers and notifications.
+ [self unloadMedia];
+ }
+
+ //Create a new instance of AVPlayerItem from the now successfully loaded AVAsset.
+ m_playerItem = [AVPlayerItem playerItemWithAsset:asset];
+ if (!m_playerItem) {
+ qWarning() << "Failed to create player item";
+ //Generate an error describing the failure.
+ NSString *localizedDescription = NSLocalizedString(@"Item cannot be played", @"Item cannot be played description");
+ NSString *localizedFailureReason = NSLocalizedString(@"The assets tracks were loaded, but couldn't create player item.", @"Item cannot be played failure reason");
+ NSDictionary *errorDict = [NSDictionary dictionaryWithObjectsAndKeys:
+ localizedDescription, NSLocalizedDescriptionKey,
+ localizedFailureReason, NSLocalizedFailureReasonErrorKey,
+ nil];
+ NSError *assetCannotBePlayedError = [NSError errorWithDomain:@"StitchedStreamPlayer" code:0 userInfo:errorDict];
+
+ [self assetFailedToPrepareForPlayback:assetCannotBePlayedError];
+ return;
+ }
+
+ //Observe the player item "status" key to determine when it is ready to play.
+ [m_playerItem addObserver:self
+ forKeyPath:AVF_STATUS_KEY
+ options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
+ context:AVFMediaPlayerObserverStatusObservationContext];
+
+ [m_playerItem addObserver:self
+ forKeyPath:@"presentationSize"
+ options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
+ context:AVFMediaPlayerObserverPresentationSizeContext];
+
+ [m_playerItem addObserver:self
+ forKeyPath:AVF_BUFFER_LIKELY_KEEP_UP_KEY
+ options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
+ context:AVFMediaPlayerObserverBufferLikelyToKeepUpContext];
+
+ [m_playerItem addObserver:self
+ forKeyPath:AVF_TRACKS_KEY
+ options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
+ context:AVFMediaPlayerObserverTracksContext];
+
+ //When the player item has played to its end time we'll toggle
+ //the movie controller Pause button to be the Play button
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(playerItemDidReachEnd:)
+ name:AVPlayerItemDidPlayToEndTimeNotification
+ object:m_playerItem];
+
+ //Get a new AVPlayer initialized to play the specified player item.
+ m_player = [AVPlayer playerWithPlayerItem:m_playerItem];
+ [m_player retain];
+
+ //Set the initial volume on new player object
+ if (self.session) {
+ auto *audioOutput = m_session->m_audioOutput;
+ m_player.volume = (audioOutput ? audioOutput->volume : 1.);
+ m_player.muted = (audioOutput ? audioOutput->muted : true);
+ }
+
+ //Assign the output layer to the new player
+ m_playerLayer.player = m_player;
+
+ //Observe the AVPlayer "currentItem" property to find out when any
+ //AVPlayer replaceCurrentItemWithPlayerItem: replacement will/did
+ //occur.
+ [m_player addObserver:self
+ forKeyPath:AVF_CURRENT_ITEM_KEY
+ options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
+ context:AVFMediaPlayerObserverCurrentItemObservationContext];
+
+ //Observe the AVPlayer "rate" property to update the scrubber control.
+ [m_player addObserver:self
+ forKeyPath:AVF_RATE_KEY
+ options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
+ context:AVFMediaPlayerObserverRateObservationContext];
+
+ //Observe the duration for getting the buffer state
+ [m_player addObserver:self
+ forKeyPath:AVF_CURRENT_ITEM_DURATION_KEY
+ options:0
+ context:AVFMediaPlayerObserverCurrentItemDurationObservationContext];
+#if defined(Q_OS_IOS)
+ [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
+ [self setSessionActive:YES];
+#endif
+}
+
+-(void) assetFailedToPrepareForPlayback:(NSError *)error
+{
+ Q_UNUSED(error);
+ QMetaObject::invokeMethod(m_session, "processMediaLoadError", Qt::AutoConnection);
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO;
+ qDebug() << [[error localizedDescription] UTF8String];
+ qDebug() << [[error localizedFailureReason] UTF8String];
+ qDebug() << [[error localizedRecoverySuggestion] UTF8String];
+#endif
+}
+
+- (void) playerItemDidReachEnd:(NSNotification *)notification
+{
+ Q_UNUSED(notification);
+ if (self.session)
+ QMetaObject::invokeMethod(m_session, "processEOS", Qt::AutoConnection);
+}
+
+- (void) observeValueForKeyPath:(NSString*) path
+ ofObject:(id)object
+ change:(NSDictionary*)change
+ context:(void*)context
+{
+ //AVPlayerItem "status" property value observer.
+ if (context == AVFMediaPlayerObserverStatusObservationContext)
+ {
+ AVPlayerStatus status = (AVPlayerStatus)[[change objectForKey:NSKeyValueChangeNewKey] integerValue];
+ switch (status)
+ {
+ //Indicates that the status of the player is not yet known because
+ //it has not tried to load new media resources for playback
+ case AVPlayerStatusUnknown:
+ {
+ //QMetaObject::invokeMethod(m_session, "processLoadStateChange", Qt::AutoConnection);
+ }
+ break;
+
+ case AVPlayerStatusReadyToPlay:
+ {
+ //Once the AVPlayerItem becomes ready to play, i.e.
+ //[playerItem status] == AVPlayerItemStatusReadyToPlay,
+ //its duration can be fetched from the item.
+ if (self.session)
+ QMetaObject::invokeMethod(m_session, "processLoadStateChange", Qt::AutoConnection);
+ }
+ break;
+
+ case AVPlayerStatusFailed:
+ {
+ AVPlayerItem *playerItem = static_cast<AVPlayerItem*>(object);
+ [self assetFailedToPrepareForPlayback:playerItem.error];
+
+ if (self.session)
+ QMetaObject::invokeMethod(m_session, "processLoadStateFailure", Qt::AutoConnection);
+ }
+ break;
+ }
+ } else if (context == AVFMediaPlayerObserverPresentationSizeContext) {
+ QSize size(m_playerItem.presentationSize.width, m_playerItem.presentationSize.height);
+ QMetaObject::invokeMethod(m_session, "nativeSizeChanged", Qt::AutoConnection, Q_ARG(QSize, size));
+ } else if (context == AVFMediaPlayerObserverBufferLikelyToKeepUpContext)
+ {
+ const bool isPlaybackLikelyToKeepUp = [m_playerItem isPlaybackLikelyToKeepUp];
+ if (isPlaybackLikelyToKeepUp != m_bufferIsLikelyToKeepUp) {
+ m_bufferIsLikelyToKeepUp = isPlaybackLikelyToKeepUp;
+ QMetaObject::invokeMethod(m_session, "processBufferStateChange", Qt::AutoConnection,
+ Q_ARG(int, isPlaybackLikelyToKeepUp ? 100 : 0));
+ }
+ }
+ else if (context == AVFMediaPlayerObserverTracksContext)
+ {
+ QMetaObject::invokeMethod(m_session, "updateTracks", Qt::AutoConnection);
+ }
+ //AVPlayer "rate" property value observer.
+ else if (context == AVFMediaPlayerObserverRateObservationContext)
+ {
+ //QMetaObject::invokeMethod(m_session, "setPlaybackRate", Qt::AutoConnection, Q_ARG(qreal, [m_player rate]));
+ }
+ //AVPlayer "currentItem" property observer.
+ //Called when the AVPlayer replaceCurrentItemWithPlayerItem:
+ //replacement will/did occur.
+ else if (context == AVFMediaPlayerObserverCurrentItemObservationContext)
+ {
+ AVPlayerItem *newPlayerItem = [change objectForKey:NSKeyValueChangeNewKey];
+ if (m_playerItem != newPlayerItem)
+ m_playerItem = newPlayerItem;
+ }
+ else if (context == AVFMediaPlayerObserverCurrentItemDurationObservationContext)
+ {
+ const CMTime time = [m_playerItem duration];
+ const qint64 duration = static_cast<qint64>(float(time.value) / float(time.timescale) * 1000.0f);
+ if (self.session)
+ QMetaObject::invokeMethod(m_session, "processDurationChange", Qt::AutoConnection, Q_ARG(qint64, duration));
+ }
+ else
+ {
+ [super observeValueForKeyPath:path ofObject:object change:change context:context];
+ }
+}
+
+- (void) detatchSession
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO;
+#endif
+ m_session = 0;
+}
+
+- (void) dealloc
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO;
+#endif
+ [self unloadMedia];
+
+ if (m_URL) {
+ [m_URL release];
+ }
+
+ [m_mimeType release];
+ [m_playerLayer release];
+ [super dealloc];
+}
+
+- (BOOL) resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
+{
+ Q_UNUSED(resourceLoader);
+
+ if (![loadingRequest.request.URL.scheme isEqualToString:@"iodevice"])
+ return NO;
+
+ QIODevice *device = m_session->mediaStream();
+ if (!device)
+ return NO;
+
+ device->seek(loadingRequest.dataRequest.requestedOffset);
+ if (loadingRequest.contentInformationRequest) {
+ loadingRequest.contentInformationRequest.contentType = m_mimeType;
+ loadingRequest.contentInformationRequest.contentLength = device->size();
+ loadingRequest.contentInformationRequest.byteRangeAccessSupported = YES;
+ }
+
+ if (loadingRequest.dataRequest) {
+ NSInteger requestedLength = loadingRequest.dataRequest.requestedLength;
+ int maxBytes = qMin(32 * 1064, int(requestedLength));
+ char buffer[maxBytes];
+ NSInteger submitted = 0;
+ while (submitted < requestedLength) {
+ qint64 len = device->read(buffer, maxBytes);
+ if (len < 1)
+ break;
+
+ [loadingRequest.dataRequest respondWithData:[NSData dataWithBytes:buffer length:len]];
+ submitted += len;
+ }
+
+ // Finish loading even if not all bytes submitted.
+ [loadingRequest finishLoading];
+ }
+
+ return YES;
+}
+@end
+
+AVFMediaPlayer::AVFMediaPlayer(QMediaPlayer *player)
+ : QObject(player),
+ QPlatformMediaPlayer(player),
+ m_state(QMediaPlayer::StoppedState),
+ m_mediaStatus(QMediaPlayer::NoMedia),
+ m_mediaStream(nullptr),
+ m_rate(1.0),
+ m_requestedPosition(-1),
+ m_duration(0),
+ m_bufferProgress(0),
+ m_videoAvailable(false),
+ m_audioAvailable(false),
+ m_seekable(false)
+{
+ m_observer = [[AVFMediaPlayerObserver alloc] initWithMediaPlayerSession:this];
+ connect(&m_playbackTimer, &QTimer::timeout, this, &AVFMediaPlayer::processPositionChange);
+ setVideoOutput(new AVFVideoRendererControl(this));
+}
+
+AVFMediaPlayer::~AVFMediaPlayer()
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO;
+#endif
+ //Detatch the session from the sessionObserver (which could still be alive trying to communicate with this session).
+ [m_observer detatchSession];
+ [static_cast<AVFMediaPlayerObserver*>(m_observer) release];
+}
+
+void AVFMediaPlayer::setVideoSink(QVideoSink *sink)
+{
+ m_videoSink = sink ? static_cast<AVFVideoSink *>(sink->platformVideoSink()): nullptr;
+ m_videoOutput->setVideoSink(m_videoSink);
+}
+
+void AVFMediaPlayer::setVideoOutput(AVFVideoRendererControl *output)
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << output;
+#endif
+
+ if (m_videoOutput == output)
+ return;
+
+ //Set the current output layer to null to stop rendering
+ if (m_videoOutput) {
+ m_videoOutput->setLayer(nullptr);
+ }
+
+ m_videoOutput = output;
+
+ if (m_videoOutput && m_state != QMediaPlayer::StoppedState)
+ m_videoOutput->setLayer([static_cast<AVFMediaPlayerObserver*>(m_observer) playerLayer]);
+}
+
+AVAsset *AVFMediaPlayer::currentAssetHandle()
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO;
+#endif
+ AVAsset *currentAsset = [[static_cast<AVFMediaPlayerObserver*>(m_observer) playerItem] asset];
+ return currentAsset;
+}
+
+QMediaPlayer::PlaybackState AVFMediaPlayer::state() const
+{
+ return m_state;
+}
+
+QMediaPlayer::MediaStatus AVFMediaPlayer::mediaStatus() const
+{
+ return m_mediaStatus;
+}
+
+QUrl AVFMediaPlayer::media() const
+{
+ return m_resources;
+}
+
+QIODevice *AVFMediaPlayer::mediaStream() const
+{
+ return m_mediaStream;
+}
+
+static void setURL(AVFMediaPlayerObserver *observer, const QByteArray &url, const QString &mimeType = QString())
+{
+ NSString *urlString = [NSString stringWithUTF8String:url.constData()];
+ NSURL *nsurl = [NSURL URLWithString:urlString];
+ [observer setURL:nsurl mimeType:[NSString stringWithUTF8String:mimeType.toLatin1().constData()]];
+}
+
+static void setStreamURL(AVFMediaPlayerObserver *observer, const QByteArray &url)
+{
+ setURL(observer, QByteArrayLiteral("iodevice://") + url, QFileInfo(QString::fromUtf8(url)).suffix());
+}
+
+void AVFMediaPlayer::setMedia(const QUrl &content, QIODevice *stream)
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << content.request().url();
+#endif
+
+ [static_cast<AVFMediaPlayerObserver*>(m_observer) unloadMedia];
+
+ m_resources = content;
+ resetStream(stream);
+
+ setAudioAvailable(false);
+ setVideoAvailable(false);
+ setSeekable(false);
+ m_requestedPosition = -1;
+ orientationChanged(QtVideo::Rotation::None, false);
+ Q_EMIT positionChanged(position());
+ if (m_duration != 0) {
+ m_duration = 0;
+ Q_EMIT durationChanged(0);
+ }
+ if (!m_metaData.isEmpty()) {
+ m_metaData.clear();
+ metaDataChanged();
+ }
+ for (int i = 0; i < QPlatformMediaPlayer::NTrackTypes; ++i) {
+ tracks[i].clear();
+ nativeTracks[i].clear();
+ }
+ tracksChanged();
+
+ const QMediaPlayer::MediaStatus oldMediaStatus = m_mediaStatus;
+ const QMediaPlayer::PlaybackState oldState = m_state;
+
+ if (!m_mediaStream && content.isEmpty()) {
+ m_mediaStatus = QMediaPlayer::NoMedia;
+ if (m_mediaStatus != oldMediaStatus)
+ Q_EMIT mediaStatusChanged(m_mediaStatus);
+
+ m_state = QMediaPlayer::StoppedState;
+ if (m_state != oldState)
+ Q_EMIT stateChanged(m_state);
+
+ return;
+ }
+
+ m_mediaStatus = QMediaPlayer::LoadingMedia;
+ if (m_mediaStatus != oldMediaStatus)
+ Q_EMIT mediaStatusChanged(m_mediaStatus);
+
+ if (m_mediaStream) {
+ // If there is a data, try to load it,
+ // otherwise wait for readyRead.
+ if (m_mediaStream->size())
+ setStreamURL(m_observer, m_resources.toEncoded());
+ } else {
+ //Load AVURLAsset
+ //initialize asset using content's URL
+ setURL(m_observer, m_resources.toEncoded());
+ }
+
+ m_state = QMediaPlayer::StoppedState;
+ if (m_state != oldState)
+ Q_EMIT stateChanged(m_state);
+}
+
+qint64 AVFMediaPlayer::position() const
+{
+ AVPlayerItem *playerItem = [static_cast<AVFMediaPlayerObserver*>(m_observer) playerItem];
+
+ if (m_requestedPosition != -1)
+ return m_requestedPosition;
+
+ if (!playerItem)
+ return 0;
+
+ CMTime time = [playerItem currentTime];
+ return static_cast<quint64>(float(time.value) / float(time.timescale) * 1000.0f);
+}
+
+qint64 AVFMediaPlayer::duration() const
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO;
+#endif
+ return m_duration;
+}
+
+float AVFMediaPlayer::bufferProgress() const
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO;
+#endif
+ return m_bufferProgress/100.;
+}
+
+void AVFMediaPlayer::setAudioAvailable(bool available)
+{
+ if (m_audioAvailable == available)
+ return;
+
+ m_audioAvailable = available;
+ Q_EMIT audioAvailableChanged(available);
+}
+
+bool AVFMediaPlayer::isAudioAvailable() const
+{
+ return m_audioAvailable;
+}
+
+void AVFMediaPlayer::setVideoAvailable(bool available)
+{
+ if (m_videoAvailable == available)
+ return;
+
+ m_videoAvailable = available;
+ Q_EMIT videoAvailableChanged(available);
+}
+
+bool AVFMediaPlayer::isVideoAvailable() const
+{
+ return m_videoAvailable;
+}
+
+bool AVFMediaPlayer::isSeekable() const
+{
+ return m_seekable;
+}
+
+void AVFMediaPlayer::setSeekable(bool seekable)
+{
+ if (m_seekable == seekable)
+ return;
+
+ m_seekable = seekable;
+ Q_EMIT seekableChanged(seekable);
+}
+
+QMediaTimeRange AVFMediaPlayer::availablePlaybackRanges() const
+{
+ AVPlayerItem *playerItem = [static_cast<AVFMediaPlayerObserver*>(m_observer) playerItem];
+
+ if (playerItem) {
+ QMediaTimeRange timeRanges;
+
+ NSArray *ranges = [playerItem loadedTimeRanges];
+ for (NSValue *timeRange in ranges) {
+ CMTimeRange currentTimeRange = [timeRange CMTimeRangeValue];
+ qint64 startTime = qint64(float(currentTimeRange.start.value) / currentTimeRange.start.timescale * 1000.0);
+ timeRanges.addInterval(startTime, startTime + qint64(float(currentTimeRange.duration.value) / currentTimeRange.duration.timescale * 1000.0));
+ }
+ if (!timeRanges.isEmpty())
+ return timeRanges;
+ }
+ return QMediaTimeRange(0, duration());
+}
+
+qreal AVFMediaPlayer::playbackRate() const
+{
+ return m_rate;
+}
+
+void AVFMediaPlayer::setAudioOutput(QPlatformAudioOutput *output)
+{
+ if (m_audioOutput == output)
+ return;
+ if (m_audioOutput)
+ m_audioOutput->q->disconnect(this);
+ m_audioOutput = output;
+ if (m_audioOutput) {
+ connect(m_audioOutput->q, &QAudioOutput::deviceChanged, this, &AVFMediaPlayer::audioOutputChanged);
+ connect(m_audioOutput->q, &QAudioOutput::volumeChanged, this, &AVFMediaPlayer::setVolume);
+ connect(m_audioOutput->q, &QAudioOutput::mutedChanged, this, &AVFMediaPlayer::setMuted);
+ //connect(m_audioOutput->q, &QAudioOutput::audioRoleChanged, this, &AVFMediaPlayer::setAudioRole);
+ }
+ audioOutputChanged();
+ setMuted(m_audioOutput ? m_audioOutput->muted : true);
+ setVolume(m_audioOutput ? m_audioOutput->volume : 1.);
+}
+
+QMediaMetaData AVFMediaPlayer::metaData() const
+{
+ return m_metaData;
+}
+
+void AVFMediaPlayer::setPlaybackRate(qreal rate)
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << rate;
+#endif
+
+ if (qFuzzyCompare(m_rate, rate))
+ return;
+
+ m_rate = rate;
+
+ AVPlayer *player = [static_cast<AVFMediaPlayerObserver*>(m_observer) player];
+ if (player && m_state == QMediaPlayer::PlayingState)
+ [player setRate:m_rate];
+
+ Q_EMIT playbackRateChanged(m_rate);
+}
+
+void AVFMediaPlayer::setPosition(qint64 pos)
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << pos;
+#endif
+
+ if (pos == position())
+ return;
+
+ AVPlayerItem *playerItem = [static_cast<AVFMediaPlayerObserver*>(m_observer) playerItem];
+ if (!playerItem) {
+ m_requestedPosition = pos;
+ Q_EMIT positionChanged(m_requestedPosition);
+ return;
+ }
+
+ if (!isSeekable()) {
+ if (m_requestedPosition != -1) {
+ m_requestedPosition = -1;
+ Q_EMIT positionChanged(position());
+ }
+ return;
+ }
+
+ pos = qMax(qint64(0), pos);
+ if (duration() > 0)
+ pos = qMin(pos, duration());
+ m_requestedPosition = pos;
+
+ CMTime newTime = [playerItem currentTime];
+ newTime.value = (pos / 1000.0f) * newTime.timescale;
+ [playerItem seekToTime:newTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero
+ completionHandler:^(BOOL finished) {
+ if (finished)
+ m_requestedPosition = -1;
+ }];
+
+ Q_EMIT positionChanged(pos);
+
+ // Reset media status if the current status is EndOfMedia
+ if (m_mediaStatus == QMediaPlayer::EndOfMedia) {
+ QMediaPlayer::MediaStatus newMediaStatus = (m_state == QMediaPlayer::PausedState) ? QMediaPlayer::BufferedMedia
+ : QMediaPlayer::LoadedMedia;
+ Q_EMIT mediaStatusChanged((m_mediaStatus = newMediaStatus));
+ }
+}
+
+void AVFMediaPlayer::play()
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << "currently: " << m_state;
+#endif
+
+ if (m_mediaStatus == QMediaPlayer::NoMedia || m_mediaStatus == QMediaPlayer::InvalidMedia)
+ return;
+
+ if (m_state == QMediaPlayer::PlayingState)
+ return;
+
+ resetCurrentLoop();
+
+ if (m_videoOutput && m_videoSink)
+ m_videoOutput->setLayer([static_cast<AVFMediaPlayerObserver*>(m_observer) playerLayer]);
+
+ // Reset media status if the current status is EndOfMedia
+ if (m_mediaStatus == QMediaPlayer::EndOfMedia)
+ setPosition(0);
+
+ if (m_mediaStatus == QMediaPlayer::LoadedMedia || m_mediaStatus == QMediaPlayer::BufferedMedia) {
+ // Setting the rate starts playback
+ [[static_cast<AVFMediaPlayerObserver*>(m_observer) player] setRate:m_rate];
+ }
+
+ m_state = QMediaPlayer::PlayingState;
+ processLoadStateChange();
+
+ Q_EMIT stateChanged(m_state);
+ m_playbackTimer.start(100);
+}
+
+void AVFMediaPlayer::pause()
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << "currently: " << m_state;
+#endif
+
+ if (m_mediaStatus == QMediaPlayer::NoMedia)
+ return;
+
+ if (m_state == QMediaPlayer::PausedState)
+ return;
+
+ m_state = QMediaPlayer::PausedState;
+
+ if (m_videoOutput && m_videoSink)
+ m_videoOutput->setLayer([static_cast<AVFMediaPlayerObserver*>(m_observer) playerLayer]);
+
+ [[static_cast<AVFMediaPlayerObserver*>(m_observer) player] pause];
+
+ // Reset media status if the current status is EndOfMedia
+ if (m_mediaStatus == QMediaPlayer::EndOfMedia)
+ setPosition(0);
+
+ Q_EMIT positionChanged(position());
+ Q_EMIT stateChanged(m_state);
+ m_playbackTimer.stop();
+}
+
+void AVFMediaPlayer::stop()
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << "currently: " << m_state;
+#endif
+
+ if (m_state == QMediaPlayer::StoppedState)
+ return;
+
+ // AVPlayer doesn't have stop(), only pause() and play().
+ [[static_cast<AVFMediaPlayerObserver*>(m_observer) player] pause];
+ setPosition(0);
+
+ if (m_videoOutput)
+ m_videoOutput->setLayer(nullptr);
+
+ if (m_mediaStatus == QMediaPlayer::BufferedMedia)
+ Q_EMIT mediaStatusChanged((m_mediaStatus = QMediaPlayer::LoadedMedia));
+
+ Q_EMIT stateChanged((m_state = QMediaPlayer::StoppedState));
+ m_playbackTimer.stop();
+}
+
+void AVFMediaPlayer::setVolume(float volume)
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << volume;
+#endif
+
+ AVPlayer *player = [static_cast<AVFMediaPlayerObserver*>(m_observer) player];
+ if (player)
+ player.volume = volume;
+}
+
+void AVFMediaPlayer::setMuted(bool muted)
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << muted;
+#endif
+
+ AVPlayer *player = [static_cast<AVFMediaPlayerObserver*>(m_observer) player];
+ if (player)
+ player.muted = muted;
+}
+
+void AVFMediaPlayer::audioOutputChanged()
+{
+#ifdef Q_OS_MACOS
+ AVPlayer *player = [static_cast<AVFMediaPlayerObserver*>(m_observer) player];
+ if (!m_audioOutput || m_audioOutput->device.id().isEmpty()) {
+ player.audioOutputDeviceUniqueID = nil;
+ if (!m_audioOutput)
+ player.muted = true;
+ } else {
+ NSString *str = QString::fromUtf8(m_audioOutput->device.id()).toNSString();
+ player.audioOutputDeviceUniqueID = str;
+ }
+#endif
+}
+
+void AVFMediaPlayer::processEOS()
+{
+ if (doLoop()) {
+ setPosition(0);
+ [[static_cast<AVFMediaPlayerObserver*>(m_observer) player] setRate:m_rate];
+ return;
+ }
+
+ //AVPlayerItem has reached end of track/stream
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO;
+#endif
+ Q_EMIT positionChanged(position());
+ m_mediaStatus = QMediaPlayer::EndOfMedia;
+ m_state = QMediaPlayer::StoppedState;
+
+ if (m_videoOutput)
+ m_videoOutput->setLayer(nullptr);
+
+ Q_EMIT mediaStatusChanged(m_mediaStatus);
+ Q_EMIT stateChanged(m_state);
+}
+
+void AVFMediaPlayer::processLoadStateChange(QMediaPlayer::PlaybackState newState)
+{
+ AVPlayerStatus currentStatus = [[static_cast<AVFMediaPlayerObserver*>(m_observer) player] status];
+
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO << currentStatus << ", " << m_mediaStatus << ", " << newState;
+#endif
+
+ if (m_mediaStatus == QMediaPlayer::NoMedia)
+ return;
+
+ if (currentStatus == AVPlayerStatusReadyToPlay) {
+
+ QMediaPlayer::MediaStatus newStatus = m_mediaStatus;
+
+ AVPlayerItem *playerItem = [m_observer playerItem];
+
+ // get the meta data
+ m_metaData = AVFMetaData::fromAsset(playerItem.asset);
+ Q_EMIT metaDataChanged();
+ updateTracks();
+
+ if (playerItem) {
+ setSeekable([[playerItem seekableTimeRanges] count] > 0);
+
+ // Get the native size of the video, and reset the bounds of the player layer
+ AVPlayerLayer *playerLayer = [m_observer playerLayer];
+ if (m_observer.videoTrack && playerLayer) {
+ if (!playerLayer.bounds.size.width || !playerLayer.bounds.size.height) {
+ playerLayer.bounds = CGRectMake(0.0f, 0.0f,
+ m_observer.videoTrack.assetTrack.naturalSize.width,
+ m_observer.videoTrack.assetTrack.naturalSize.height);
+ }
+ }
+
+ if (m_requestedPosition != -1) {
+ setPosition(m_requestedPosition);
+ m_requestedPosition = -1;
+ }
+ }
+
+ newStatus = (newState != QMediaPlayer::StoppedState) ? QMediaPlayer::BufferedMedia
+ : QMediaPlayer::LoadedMedia;
+
+ if (newStatus != m_mediaStatus)
+ Q_EMIT mediaStatusChanged((m_mediaStatus = newStatus));
+
+ }
+
+ if (newState == QMediaPlayer::PlayingState && [static_cast<AVFMediaPlayerObserver*>(m_observer) player]) {
+ // Setting the rate is enough to start playback, no need to call play()
+ [[static_cast<AVFMediaPlayerObserver*>(m_observer) player] setRate:m_rate];
+ m_playbackTimer.start();
+ }
+}
+
+
+void AVFMediaPlayer::processLoadStateChange()
+{
+ processLoadStateChange(m_state);
+}
+
+
+void AVFMediaPlayer::processLoadStateFailure()
+{
+ Q_EMIT stateChanged((m_state = QMediaPlayer::StoppedState));
+}
+
+void AVFMediaPlayer::processBufferStateChange(int bufferProgress)
+{
+ if (bufferProgress == m_bufferProgress)
+ return;
+
+ auto status = m_mediaStatus;
+ // Buffered -> unbuffered.
+ if (!bufferProgress) {
+ status = QMediaPlayer::StalledMedia;
+ } else if (status == QMediaPlayer::StalledMedia) {
+ status = QMediaPlayer::BufferedMedia;
+ // Resume playback.
+ if (m_state == QMediaPlayer::PlayingState) {
+ [[static_cast<AVFMediaPlayerObserver*>(m_observer) player] setRate:m_rate];
+ m_playbackTimer.start();
+ }
+ }
+
+ if (m_mediaStatus != status)
+ Q_EMIT mediaStatusChanged(m_mediaStatus = status);
+
+ m_bufferProgress = bufferProgress;
+ Q_EMIT bufferProgressChanged(bufferProgress/100.);
+}
+
+void AVFMediaPlayer::processDurationChange(qint64 duration)
+{
+ if (duration == m_duration)
+ return;
+
+ m_duration = duration;
+ Q_EMIT durationChanged(duration);
+}
+
+void AVFMediaPlayer::processPositionChange()
+{
+ if (m_state == QMediaPlayer::StoppedState)
+ return;
+
+ Q_EMIT positionChanged(position());
+}
+
+void AVFMediaPlayer::processMediaLoadError()
+{
+ if (m_requestedPosition != -1) {
+ m_requestedPosition = -1;
+ Q_EMIT positionChanged(position());
+ }
+
+ Q_EMIT mediaStatusChanged((m_mediaStatus = QMediaPlayer::InvalidMedia));
+
+ Q_EMIT error(QMediaPlayer::FormatError, tr("Failed to load media"));
+}
+
+void AVFMediaPlayer::streamReady()
+{
+ setStreamURL(m_observer, m_resources.toEncoded());
+}
+
+void AVFMediaPlayer::streamDestroyed()
+{
+ resetStream(nullptr);
+}
+
+void AVFMediaPlayer::updateTracks()
+{
+ bool firstLoad = true;
+ for (int i = 0; i < QPlatformMediaPlayer::NTrackTypes; ++i) {
+ if (tracks[i].count())
+ firstLoad = false;
+ tracks[i].clear();
+ nativeTracks[i].clear();
+ }
+ AVPlayerItem *playerItem = [m_observer playerItem];
+ if (playerItem) {
+ // Check each track for audio and video content
+ NSArray *tracks = playerItem.tracks;
+ for (AVPlayerItemTrack *track in tracks) {
+ AVAssetTrack *assetTrack = track.assetTrack;
+ if (assetTrack) {
+ int qtTrack = -1;
+ if ([assetTrack.mediaType isEqualToString:AVMediaTypeAudio]) {
+ qtTrack = QPlatformMediaPlayer::AudioStream;
+ setAudioAvailable(true);
+ } else if ([assetTrack.mediaType isEqualToString:AVMediaTypeVideo]) {
+ qtTrack = QPlatformMediaPlayer::VideoStream;
+ setVideoAvailable(true);
+ if (m_observer.videoTrack != track) {
+ m_observer.videoTrack = track;
+ bool isMirrored = false;
+ QtVideo::Rotation orientation = QtVideo::Rotation::None;
+ videoOrientationForAssetTrack(assetTrack, orientation, isMirrored);
+ orientationChanged(orientation, isMirrored);
+ }
+ }
+ else if ([assetTrack.mediaType isEqualToString:AVMediaTypeSubtitle]) {
+ qtTrack = QPlatformMediaPlayer::SubtitleStream;
+ }
+ if (qtTrack != -1) {
+ QMediaMetaData metaData = AVFMetaData::fromAssetTrack(assetTrack);
+ this->tracks[qtTrack].append(metaData);
+ nativeTracks[qtTrack].append(track);
+ }
+ }
+ }
+ // subtitles are disabled by default
+ if (firstLoad)
+ setActiveTrack(SubtitleStream, -1);
+ }
+ Q_EMIT tracksChanged();
+}
+
+void AVFMediaPlayer::setActiveTrack(QPlatformMediaPlayer::TrackType type, int index)
+{
+ const auto &t = nativeTracks[type];
+ if (type == QPlatformMediaPlayer::SubtitleStream) {
+ // subtitle streams are not always automatically enabled on macOS/iOS.
+ // this hack ensures they get enables and we actually get the text
+ AVPlayerItem *playerItem = m_observer.m_playerItem;
+ if (playerItem) {
+ AVAsset *asset = playerItem.asset;
+ if (!asset)
+ return;
+ AVMediaSelectionGroup *group = [asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
+ if (!group)
+ return;
+ auto *options = group.options;
+ if (options.count)
+ [playerItem selectMediaOption:options.firstObject inMediaSelectionGroup:group];
+ }
+ }
+ for (int i = 0; i < t.count(); ++i)
+ t.at(i).enabled = (i == index);
+ emit activeTracksChanged();
+}
+
+int AVFMediaPlayer::activeTrack(QPlatformMediaPlayer::TrackType type)
+{
+ const auto &t = nativeTracks[type];
+ for (int i = 0; i < t.count(); ++i)
+ if (t.at(i).enabled)
+ return i;
+ return -1;
+}
+
+int AVFMediaPlayer::trackCount(QPlatformMediaPlayer::TrackType type)
+{
+ return nativeTracks[type].count();
+}
+
+QMediaMetaData AVFMediaPlayer::trackMetaData(QPlatformMediaPlayer::TrackType type, int trackNumber)
+{
+ const auto &t = tracks[type];
+ if (trackNumber < 0 || trackNumber >= t.count())
+ return QMediaMetaData();
+ return t.at(trackNumber);
+}
+
+void AVFMediaPlayer::resetStream(QIODevice *stream)
+{
+ if (m_mediaStream) {
+ disconnect(m_mediaStream, &QIODevice::readyRead, this, &AVFMediaPlayer::streamReady);
+ disconnect(m_mediaStream, &QIODevice::destroyed, this, &AVFMediaPlayer::streamDestroyed);
+ }
+
+ m_mediaStream = stream;
+
+ if (m_mediaStream) {
+ connect(m_mediaStream, &QIODevice::readyRead, this, &AVFMediaPlayer::streamReady);
+ connect(m_mediaStream, &QIODevice::destroyed, this, &AVFMediaPlayer::streamDestroyed);
+ }
+}
+
+void AVFMediaPlayer::nativeSizeChanged(QSize size)
+{
+ if (!m_videoSink)
+ return;
+ m_videoSink->setNativeSize(size);
+}
+
+void AVFMediaPlayer::orientationChanged(QtVideo::Rotation rotation, bool mirrored)
+{
+ if (!m_videoOutput)
+ return;
+
+ m_videoOutput->setVideoRotation(rotation);
+ m_videoOutput->setVideoMirrored(mirrored);
+}
+
+void AVFMediaPlayer::videoOrientationForAssetTrack(AVAssetTrack *videoTrack,
+ QtVideo::Rotation &angle,
+ bool &mirrored)
+{
+ angle = QtVideo::Rotation::None;
+ if (videoTrack) {
+ CGAffineTransform transform = videoTrack.preferredTransform;
+ if (CGAffineTransformIsIdentity(transform))
+ return;
+ qreal delta = transform.a * transform.d - transform.b * transform.c;
+ qreal radians = qAtan2(transform.b, transform.a);
+ qreal degrees = qRadiansToDegrees(radians);
+ qreal scaleX = (transform.a/qAbs(transform.a)) * qSqrt(qPow(transform.a, 2) + qPow(transform.c, 2));
+ qreal scaleY = (transform.d/abs(transform.d)) * qSqrt(qPow(transform.b, 2) + qPow(transform.d, 2));
+
+ if (delta < 0.0) { // flipped
+ if (scaleX < 0.0) {
+ // vertical flip
+ degrees = -degrees;
+ } else if (scaleY < 0.0) {
+ // horizontal flip
+ degrees = (180 + (int)degrees) % 360;
+ }
+ mirrored = true;
+ }
+
+ if (qFuzzyCompare(degrees, qreal(90)) || qFuzzyCompare(degrees, qreal(-270))) {
+ angle = QtVideo::Rotation::Clockwise90;
+ } else if (qFuzzyCompare(degrees, qreal(-90)) || qFuzzyCompare(degrees, qreal(270))) {
+ angle = QtVideo::Rotation::Clockwise270;
+ } else if (qFuzzyCompare(degrees, qreal(180)) || qFuzzyCompare(degrees, qreal(-180))) {
+ angle = QtVideo::Rotation::Clockwise180;
+ }
+ }
+}
+
+#include "moc_avfmediaplayer_p.cpp"
diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer_p.h b/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer_p.h
new file mode 100644
index 000000000..d04ab0818
--- /dev/null
+++ b/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer_p.h
@@ -0,0 +1,151 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFMEDIAPLAYER_H
+#define AVFMEDIAPLAYER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QSet>
+#include <QtCore/QResource>
+#include <QtCore/QUrl>
+#include <QtCore/QTimer>
+
+#include <private/qplatformmediaplayer_p.h>
+#include <QtMultimedia/QMediaPlayer>
+#include <QtMultimedia/QVideoFrame>
+
+Q_FORWARD_DECLARE_OBJC_CLASS(AVAsset);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVPlayerItemTrack);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVFMediaPlayerObserver);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVAssetTrack);
+
+QT_BEGIN_NAMESPACE
+
+class AVFMediaPlayer;
+class AVFVideoRendererControl;
+class AVFVideoSink;
+
+class AVFMediaPlayer : public QObject, public QPlatformMediaPlayer
+{
+ Q_OBJECT
+public:
+ AVFMediaPlayer(QMediaPlayer *parent);
+ virtual ~AVFMediaPlayer();
+
+ void setVideoSink(QVideoSink *sink) override;
+ void setVideoOutput(AVFVideoRendererControl *output);
+ AVAsset *currentAssetHandle();
+
+ QMediaPlayer::PlaybackState state() const override;
+ QMediaPlayer::MediaStatus mediaStatus() const override;
+
+ QUrl media() const override;
+ QIODevice *mediaStream() const override;
+ void setMedia(const QUrl &content, QIODevice *stream) override;
+
+ qint64 position() const override;
+ qint64 duration() const override;
+
+ float bufferProgress() const override;
+
+ bool isAudioAvailable() const override;
+ bool isVideoAvailable() const override;
+
+ bool isSeekable() const override;
+ QMediaTimeRange availablePlaybackRanges() const override;
+
+ qreal playbackRate() const override;
+
+ void setAudioOutput(QPlatformAudioOutput *output) override;
+ QPlatformAudioOutput *m_audioOutput = nullptr;
+
+ QMediaMetaData metaData() const override;
+
+ static void videoOrientationForAssetTrack(AVAssetTrack *track,
+ QtVideo::Rotation &angle,
+ bool &mirrored);
+
+public Q_SLOTS:
+ void setPlaybackRate(qreal rate) override;
+ void nativeSizeChanged(QSize size);
+
+ void setPosition(qint64 pos) override;
+
+ void play() override;
+ void pause() override;
+ void stop() override;
+
+ void setVolume(float volume);
+ void setMuted(bool muted);
+ void audioOutputChanged();
+
+ void processEOS();
+ void processLoadStateChange(QMediaPlayer::PlaybackState newState);
+ void processPositionChange();
+ void processMediaLoadError();
+
+ void processLoadStateChange();
+ void processLoadStateFailure();
+
+ void processBufferStateChange(int bufferProgress);
+
+ void processDurationChange(qint64 duration);
+
+ void streamReady();
+ void streamDestroyed();
+ void updateTracks();
+ void setActiveTrack(QPlatformMediaPlayer::TrackType type, int index) override;
+ int activeTrack(QPlatformMediaPlayer::TrackType type) override;
+ int trackCount(TrackType) override;
+ QMediaMetaData trackMetaData(TrackType type, int trackNumber) override;
+
+public:
+ QList<QMediaMetaData> tracks[QPlatformMediaPlayer::NTrackTypes];
+ QList<AVPlayerItemTrack *> nativeTracks[QPlatformMediaPlayer::NTrackTypes];
+
+private:
+ void setAudioAvailable(bool available);
+ void setVideoAvailable(bool available);
+ void setSeekable(bool seekable);
+ void resetStream(QIODevice *stream = nullptr);
+
+ void orientationChanged(QtVideo::Rotation rotation, bool mirrored);
+
+ AVFVideoRendererControl *m_videoOutput = nullptr;
+ AVFVideoSink *m_videoSink = nullptr;
+
+ QMediaPlayer::PlaybackState m_state;
+ QMediaPlayer::MediaStatus m_mediaStatus;
+ QIODevice *m_mediaStream;
+ QUrl m_resources;
+ QMediaMetaData m_metaData;
+
+ qreal m_rate;
+ qint64 m_requestedPosition;
+
+ qint64 m_duration;
+ int m_bufferProgress;
+ bool m_videoAvailable;
+ bool m_audioAvailable;
+ bool m_seekable;
+
+ AVFMediaPlayerObserver *m_observer;
+
+ QTimer m_playbackTimer;
+};
+
+QT_END_NAMESPACE
+
+#endif // AVFMEDIAPLAYER_H
diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol.mm b/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol.mm
new file mode 100644
index 000000000..66687c931
--- /dev/null
+++ b/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol.mm
@@ -0,0 +1,222 @@
+// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "avfvideorenderercontrol_p.h"
+#include "avfdisplaylink_p.h"
+#include <avfvideobuffer_p.h>
+#include "qavfhelpers_p.h"
+#include "private/qvideoframe_p.h"
+
+#include <QtMultimedia/qvideoframeformat.h>
+
+#include <avfvideosink_p.h>
+#include <rhi/qrhi.h>
+
+#include <QtCore/qdebug.h>
+
+#import <AVFoundation/AVFoundation.h>
+#include <CoreVideo/CVPixelBuffer.h>
+#include <CoreVideo/CVImageBuffer.h>
+
+QT_USE_NAMESPACE
+
+@interface SubtitleDelegate : NSObject <AVPlayerItemLegibleOutputPushDelegate>
+{
+ AVFVideoRendererControl *m_renderer;
+}
+
+- (void)legibleOutput:(AVPlayerItemLegibleOutput *)output
+ didOutputAttributedStrings:(NSArray<NSAttributedString *> *)strings
+ nativeSampleBuffers:(NSArray *)nativeSamples
+ forItemTime:(CMTime)itemTime;
+
+@end
+
+@implementation SubtitleDelegate
+
+-(id)initWithRenderer: (AVFVideoRendererControl *)renderer
+{
+ if (!(self = [super init]))
+ return nil;
+
+ m_renderer = renderer;
+
+ return self;
+}
+
+- (void)legibleOutput:(AVPlayerItemLegibleOutput *)output
+ didOutputAttributedStrings:(NSArray<NSAttributedString *> *)strings
+ nativeSampleBuffers:(NSArray *)nativeSamples
+ forItemTime:(CMTime)itemTime
+{
+ QString text;
+ for (NSAttributedString *s : strings) {
+ if (!text.isEmpty())
+ text += QChar::LineSeparator;
+ text += QString::fromNSString(s.string);
+ }
+ m_renderer->setSubtitleText(text);
+}
+
+@end
+
+
+AVFVideoRendererControl::AVFVideoRendererControl(QObject *parent)
+ : QObject(parent)
+{
+ m_displayLink = new AVFDisplayLink(this);
+ connect(m_displayLink, SIGNAL(tick(CVTimeStamp)), SLOT(updateVideoFrame(CVTimeStamp)));
+}
+
+AVFVideoRendererControl::~AVFVideoRendererControl()
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << Q_FUNC_INFO;
+#endif
+ m_displayLink->stop();
+ if (m_videoOutput)
+ [m_videoOutput release];
+ if (m_subtitleOutput)
+ [m_subtitleOutput release];
+ if (m_subtitleDelegate)
+ [m_subtitleDelegate release];
+}
+
+void AVFVideoRendererControl::reconfigure()
+{
+#ifdef QT_DEBUG_AVF
+ qDebug() << "reconfigure";
+#endif
+ if (!m_layer) {
+ m_displayLink->stop();
+ return;
+ }
+
+ QMutexLocker locker(&m_mutex);
+
+ m_displayLink->start();
+
+ nativeSizeChanged();
+}
+
+void AVFVideoRendererControl::setLayer(CALayer *layer)
+{
+ if (m_layer == layer)
+ return;
+
+ AVPlayerLayer *plLayer = playerLayer();
+ if (plLayer) {
+ if (m_videoOutput)
+ [[[plLayer player] currentItem] removeOutput:m_videoOutput];
+
+ if (m_subtitleOutput)
+ [[[plLayer player] currentItem] removeOutput:m_subtitleOutput];
+ }
+
+ if (!layer && m_sink)
+ m_sink->setVideoFrame(QVideoFrame());
+
+ AVFVideoSinkInterface::setLayer(layer);
+}
+
+void AVFVideoRendererControl::setVideoRotation(QtVideo::Rotation rotation)
+{
+ m_rotation = rotation;
+}
+
+void AVFVideoRendererControl::setVideoMirrored(bool mirrored)
+{
+ m_mirrored = mirrored;
+}
+
+void AVFVideoRendererControl::updateVideoFrame(const CVTimeStamp &ts)
+{
+ Q_UNUSED(ts);
+
+ if (!m_sink)
+ return;
+
+ if (!m_layer)
+ return;
+
+ auto *layer = playerLayer();
+ if (!layer.readyForDisplay)
+ return;
+ nativeSizeChanged();
+
+ QVideoFrame frame;
+ size_t width, height;
+ CVPixelBufferRef pixelBuffer = copyPixelBufferFromLayer(width, height);
+ if (!pixelBuffer)
+ return;
+ auto buffer = std::make_unique<AVFVideoBuffer>(this, pixelBuffer);
+ // qDebug() << "Got pixelbuffer with format" << fmt << Qt::hex <<
+ // CVPixelBufferGetPixelFormatType(pixelBuffer);
+ CVPixelBufferRelease(pixelBuffer);
+
+ frame = QVideoFramePrivate::createFrame(std::move(buffer), buffer->videoFormat());
+ frame.setRotation(m_rotation);
+ frame.setMirrored(m_mirrored);
+ m_sink->setVideoFrame(frame);
+}
+
+CVPixelBufferRef AVFVideoRendererControl::copyPixelBufferFromLayer(size_t& width, size_t& height)
+{
+ AVPlayerLayer *layer = playerLayer();
+ //Is layer valid
+ if (!layer) {
+#ifdef QT_DEBUG_AVF
+ qWarning("copyPixelBufferFromLayer: invalid layer");
+#endif
+ return nullptr;
+ }
+
+ AVPlayerItem * item = [[layer player] currentItem];
+
+ if (!m_videoOutput) {
+ if (!m_outputSettings)
+ setOutputSettings();
+ m_videoOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:m_outputSettings];
+ [m_videoOutput setDelegate:nil queue:nil];
+ }
+ if (!m_subtitleOutput) {
+ m_subtitleOutput = [[AVPlayerItemLegibleOutput alloc] init];
+ m_subtitleDelegate = [[SubtitleDelegate alloc] initWithRenderer:this];
+ [m_subtitleOutput setDelegate:m_subtitleDelegate queue:dispatch_get_main_queue()];
+ }
+ if (![item.outputs containsObject:m_videoOutput])
+ [item addOutput:m_videoOutput];
+ if (![item.outputs containsObject:m_subtitleOutput])
+ [item addOutput:m_subtitleOutput];
+
+ CFTimeInterval currentCAFrameTime = CACurrentMediaTime();
+ CMTime currentCMFrameTime = [m_videoOutput itemTimeForHostTime:currentCAFrameTime];
+ // happens when buffering / loading
+ if (CMTimeCompare(currentCMFrameTime, kCMTimeZero) < 0) {
+ return nullptr;
+ }
+
+ if (![m_videoOutput hasNewPixelBufferForItemTime:currentCMFrameTime])
+ return nullptr;
+
+ CVPixelBufferRef pixelBuffer = [m_videoOutput copyPixelBufferForItemTime:currentCMFrameTime
+ itemTimeForDisplay:nil];
+ if (!pixelBuffer) {
+#ifdef QT_DEBUG_AVF
+ qWarning("copyPixelBufferForItemTime returned nil");
+ CMTimeShow(currentCMFrameTime);
+#endif
+ return nullptr;
+ }
+
+ width = CVPixelBufferGetWidth(pixelBuffer);
+ height = CVPixelBufferGetHeight(pixelBuffer);
+// auto f = CVPixelBufferGetPixelFormatType(pixelBuffer);
+// char fmt[5];
+// memcpy(fmt, &f, 4);
+// fmt[4] = 0;
+// qDebug() << "copyPixelBuffer" << f << fmt << width << height;
+ return pixelBuffer;
+}
+
+#include "moc_avfvideorenderercontrol_p.cpp"
diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol_p.h b/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol_p.h
new file mode 100644
index 000000000..177114127
--- /dev/null
+++ b/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol_p.h
@@ -0,0 +1,72 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef AVFVIDEORENDERERCONTROL_H
+#define AVFVIDEORENDERERCONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/QObject>
+#include <QtCore/QMutex>
+#include <QtCore/QSize>
+
+#include <avfvideosink_p.h>
+
+#include <CoreVideo/CVBase.h>
+#include <CoreVideo/CVPixelBuffer.h>
+
+Q_FORWARD_DECLARE_OBJC_CLASS(CALayer);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVPlayerItemVideoOutput);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVPlayerItemLegibleOutput);
+Q_FORWARD_DECLARE_OBJC_CLASS(SubtitleDelegate);
+
+QT_BEGIN_NAMESPACE
+
+class AVFDisplayLink;
+
+class AVFVideoRendererControl : public QObject, public AVFVideoSinkInterface
+{
+ Q_OBJECT
+public:
+ explicit AVFVideoRendererControl(QObject *parent = nullptr);
+ virtual ~AVFVideoRendererControl();
+
+ // AVFVideoSinkInterface
+ void reconfigure() override;
+ void setLayer(CALayer *layer) override;
+
+ void setVideoRotation(QtVideo::Rotation);
+ void setVideoMirrored(bool mirrored);
+
+ void setSubtitleText(const QString &subtitle)
+ {
+ m_sink->setSubtitleText(subtitle);
+ }
+private Q_SLOTS:
+ void updateVideoFrame(const CVTimeStamp &ts);
+
+private:
+ AVPlayerLayer *playerLayer() const { return static_cast<AVPlayerLayer *>(m_layer); }
+ CVPixelBufferRef copyPixelBufferFromLayer(size_t& width, size_t& height);
+
+ QMutex m_mutex;
+ AVFDisplayLink *m_displayLink = nullptr;
+ AVPlayerItemVideoOutput *m_videoOutput = nullptr;
+ AVPlayerItemLegibleOutput *m_subtitleOutput = nullptr;
+ SubtitleDelegate *m_subtitleDelegate = nullptr;
+ QtVideo::Rotation m_rotation = QtVideo::Rotation::None;
+ bool m_mirrored = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // AVFVIDEORENDERERCONTROL_H
diff --git a/src/plugins/multimedia/darwin/qavfhelpers.mm b/src/plugins/multimedia/darwin/qavfhelpers.mm
new file mode 100644
index 000000000..51ae9eedc
--- /dev/null
+++ b/src/plugins/multimedia/darwin/qavfhelpers.mm
@@ -0,0 +1,143 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include <qavfhelpers_p.h>
+#include <CoreMedia/CMFormatDescription.h>
+#include <CoreVideo/CoreVideo.h>
+#include <qdebug.h>
+
+#import <CoreVideo/CoreVideo.h>
+
+namespace {
+
+using PixelFormat = QVideoFrameFormat::PixelFormat;
+using ColorRange = QVideoFrameFormat::ColorRange;
+
+// clang-format off
+constexpr std::tuple<CvPixelFormat, PixelFormat, ColorRange> PixelFormatMap[] = {
+ { kCVPixelFormatType_32ARGB, PixelFormat::Format_ARGB8888, ColorRange::ColorRange_Unknown },
+ { kCVPixelFormatType_32BGRA, PixelFormat::Format_BGRA8888, ColorRange::ColorRange_Unknown },
+ { kCVPixelFormatType_420YpCbCr8Planar, PixelFormat::Format_YUV420P, ColorRange::ColorRange_Unknown },
+ { kCVPixelFormatType_420YpCbCr8PlanarFullRange, PixelFormat::Format_YUV420P, ColorRange::ColorRange_Full },
+ { kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, PixelFormat::Format_NV12, ColorRange::ColorRange_Video },
+ { kCVPixelFormatType_420YpCbCr8BiPlanarFullRange, PixelFormat::Format_NV12, ColorRange::ColorRange_Full },
+ { kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange, PixelFormat::Format_P010, ColorRange::ColorRange_Video },
+ { kCVPixelFormatType_420YpCbCr10BiPlanarFullRange, PixelFormat::Format_P010, ColorRange::ColorRange_Full },
+ { kCVPixelFormatType_422YpCbCr8, PixelFormat::Format_UYVY, ColorRange::ColorRange_Video },
+ { kCVPixelFormatType_422YpCbCr8_yuvs, PixelFormat::Format_YUYV, ColorRange::ColorRange_Video },
+ { kCVPixelFormatType_OneComponent8, PixelFormat::Format_Y8, ColorRange::ColorRange_Unknown },
+ { kCVPixelFormatType_OneComponent16, PixelFormat::Format_Y16, ColorRange::ColorRange_Unknown },
+
+ // The cases with kCMVideoCodecType_JPEG/kCMVideoCodecType_JPEG_OpenDML as cv pixel format should be investigated.
+ // Matching kCMVideoCodecType_JPEG_OpenDML to ColorRange_Full is a little hack to distinguish between
+ // kCMVideoCodecType_JPEG and kCMVideoCodecType_JPEG_OpenDML.
+ { kCMVideoCodecType_JPEG, PixelFormat::Format_Jpeg, ColorRange::ColorRange_Unknown },
+ { kCMVideoCodecType_JPEG_OpenDML, PixelFormat::Format_Jpeg, ColorRange::ColorRange_Full }
+};
+// clang-format on
+
+template<typename Type, typename... Args>
+Type findInPixelFormatMap(Type defaultValue, Args... args)
+{
+ auto checkElement = [&](const auto &element) {
+ return ((args == std::get<Args>(element)) && ...);
+ };
+
+ auto found = std::find_if(std::begin(PixelFormatMap), std::end(PixelFormatMap), checkElement);
+ return found == std::end(PixelFormatMap) ? defaultValue : std::get<Type>(*found);
+}
+
+}
+
+ColorRange QAVFHelpers::colorRangeForCVPixelFormat(CvPixelFormat cvPixelFormat)
+{
+ return findInPixelFormatMap(ColorRange::ColorRange_Unknown, cvPixelFormat);
+}
+
+PixelFormat QAVFHelpers::fromCVPixelFormat(CvPixelFormat cvPixelFormat)
+{
+ return findInPixelFormatMap(PixelFormat::Format_Invalid, cvPixelFormat);
+}
+
+CvPixelFormat QAVFHelpers::toCVPixelFormat(PixelFormat pixelFmt, ColorRange colorRange)
+{
+ return findInPixelFormatMap(CvPixelFormatInvalid, pixelFmt, colorRange);
+}
+
+QVideoFrameFormat QAVFHelpers::videoFormatForImageBuffer(CVImageBufferRef buffer, bool openGL)
+{
+ auto cvPixelFormat = CVPixelBufferGetPixelFormatType(buffer);
+ auto pixelFormat = fromCVPixelFormat(cvPixelFormat);
+ if (openGL) {
+ if (cvPixelFormat == kCVPixelFormatType_32BGRA)
+ pixelFormat = QVideoFrameFormat::Format_SamplerRect;
+ else
+ qWarning() << "Accelerated macOS OpenGL video supports BGRA only, got CV pixel format"
+ << cvPixelFormat;
+ }
+
+ size_t width = CVPixelBufferGetWidth(buffer);
+ size_t height = CVPixelBufferGetHeight(buffer);
+
+ QVideoFrameFormat format(QSize(width, height), pixelFormat);
+
+ auto colorSpace = QVideoFrameFormat::ColorSpace_Undefined;
+ auto colorTransfer = QVideoFrameFormat::ColorTransfer_Unknown;
+
+ if (CFStringRef cSpace = reinterpret_cast<CFStringRef>(
+ CVBufferGetAttachment(buffer, kCVImageBufferYCbCrMatrixKey, nullptr))) {
+ if (CFEqual(cSpace, kCVImageBufferYCbCrMatrix_ITU_R_709_2)) {
+ colorSpace = QVideoFrameFormat::ColorSpace_BT709;
+ } else if (CFEqual(cSpace, kCVImageBufferYCbCrMatrix_ITU_R_601_4)
+ || CFEqual(cSpace, kCVImageBufferYCbCrMatrix_SMPTE_240M_1995)) {
+ colorSpace = QVideoFrameFormat::ColorSpace_BT601;
+ } else if (@available(macOS 10.11, iOS 9.0, *)) {
+ if (CFEqual(cSpace, kCVImageBufferYCbCrMatrix_ITU_R_2020)) {
+ colorSpace = QVideoFrameFormat::ColorSpace_BT2020;
+ }
+ }
+ }
+
+ if (CFStringRef cTransfer = reinterpret_cast<CFStringRef>(
+ CVBufferGetAttachment(buffer, kCVImageBufferTransferFunctionKey, nullptr))) {
+
+ if (CFEqual(cTransfer, kCVImageBufferTransferFunction_ITU_R_709_2)) {
+ colorTransfer = QVideoFrameFormat::ColorTransfer_BT709;
+ } else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_SMPTE_240M_1995)) {
+ colorTransfer = QVideoFrameFormat::ColorTransfer_BT601;
+ } else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_sRGB)) {
+ colorTransfer = QVideoFrameFormat::ColorTransfer_Gamma22;
+ } else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_UseGamma)) {
+ auto gamma = reinterpret_cast<CFNumberRef>(
+ CVBufferGetAttachment(buffer, kCVImageBufferGammaLevelKey, nullptr));
+ double g;
+ CFNumberGetValue(gamma, kCFNumberFloat32Type, &g);
+ // These are best fit values given what we have in our enum
+ if (g < 0.8)
+ ; // unknown
+ else if (g < 1.5)
+ colorTransfer = QVideoFrameFormat::ColorTransfer_Linear;
+ else if (g < 2.1)
+ colorTransfer = QVideoFrameFormat::ColorTransfer_BT709;
+ else if (g < 2.5)
+ colorTransfer = QVideoFrameFormat::ColorTransfer_Gamma22;
+ else if (g < 3.2)
+ colorTransfer = QVideoFrameFormat::ColorTransfer_Gamma28;
+ }
+ if (@available(macOS 10.12, iOS 11.0, *)) {
+ if (CFEqual(cTransfer, kCVImageBufferTransferFunction_ITU_R_2020))
+ colorTransfer = QVideoFrameFormat::ColorTransfer_BT709;
+ }
+ if (@available(macOS 10.12, iOS 11.0, *)) {
+ if (CFEqual(cTransfer, kCVImageBufferTransferFunction_ITU_R_2100_HLG)) {
+ colorTransfer = QVideoFrameFormat::ColorTransfer_STD_B67;
+ } else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ)) {
+ colorTransfer = QVideoFrameFormat::ColorTransfer_ST2084;
+ }
+ }
+ }
+
+ format.setColorRange(colorRangeForCVPixelFormat(cvPixelFormat));
+ format.setColorSpace(colorSpace);
+ format.setColorTransfer(colorTransfer);
+ return format;
+}
diff --git a/src/plugins/multimedia/darwin/qavfhelpers_p.h b/src/plugins/multimedia/darwin/qavfhelpers_p.h
new file mode 100644
index 000000000..8133d5500
--- /dev/null
+++ b/src/plugins/multimedia/darwin/qavfhelpers_p.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QAVFHELPERS_H
+#define QAVFHELPERS_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qvideoframe.h>
+#include <qvideoframeformat.h>
+
+#include <CoreVideo/CVBase.h>
+#include <CoreVideo/CVPixelBuffer.h>
+#include <CoreVideo/CVImageBuffer.h>
+
+QT_BEGIN_NAMESPACE
+
+using CvPixelFormat = unsigned;
+constexpr CvPixelFormat CvPixelFormatInvalid = 0;
+
+namespace QAVFHelpers
+{
+QVideoFrameFormat::ColorRange colorRangeForCVPixelFormat(CvPixelFormat cvPixelFormat);
+QVideoFrameFormat::PixelFormat fromCVPixelFormat(CvPixelFormat cvPixelFormat);
+CvPixelFormat toCVPixelFormat(QVideoFrameFormat::PixelFormat pixFmt,
+ QVideoFrameFormat::ColorRange colorRange);
+
+QVideoFrameFormat videoFormatForImageBuffer(CVImageBufferRef buffer, bool openGL = false);
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/darwin/qdarwinformatsinfo.mm b/src/plugins/multimedia/darwin/qdarwinformatsinfo.mm
new file mode 100644
index 000000000..582060a6c
--- /dev/null
+++ b/src/plugins/multimedia/darwin/qdarwinformatsinfo.mm
@@ -0,0 +1,211 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qdarwinformatsinfo_p.h"
+#include <AVFoundation/AVFoundation.h>
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+static struct {
+ const char *name;
+ QMediaFormat::FileFormat value;
+} mediaContainerMap[] = {
+ { "video/x-ms-asf", QMediaFormat::WMV },
+ { "video/avi", QMediaFormat::AVI },
+ { "video/x-matroska", QMediaFormat::Matroska },
+ { "video/mp4", QMediaFormat::MPEG4 },
+ { "video/quicktime", QMediaFormat::QuickTime },
+ { "video/ogg", QMediaFormat::Ogg },
+ { "audio/mp3", QMediaFormat::MP3 },
+ { "audio/flac", QMediaFormat::FLAC },
+ { nullptr, QMediaFormat::UnspecifiedFormat }
+};
+
+static struct {
+ const char *name;
+ QMediaFormat::VideoCodec value;
+} videoCodecMap[] = {
+ // See CMVideoCodecType for the four character code names of codecs
+ { "; codecs=\"mp1v\"", QMediaFormat::VideoCodec::MPEG1 },
+ { "; codecs=\"mp2v\"", QMediaFormat::VideoCodec::MPEG2 },
+ { "; codecs=\"mp4v\"", QMediaFormat::VideoCodec::MPEG4 },
+ { "; codecs=\"avc1\"", QMediaFormat::VideoCodec::H264 },
+ { "; codecs=\"hvc1\"", QMediaFormat::VideoCodec::H265 },
+ { "; codecs=\"vp09\"", QMediaFormat::VideoCodec::VP9 },
+ { "; codecs=\"av01\"", QMediaFormat::VideoCodec::AV1 }, // ### ????
+ { "; codecs=\"jpeg\"", QMediaFormat::VideoCodec::MotionJPEG },
+ { nullptr, QMediaFormat::VideoCodec::Unspecified }
+};
+
+static struct {
+ const char *name;
+ QMediaFormat::AudioCodec value;
+} audioCodecMap[] = {
+ // AudioFile.h
+ // ### The next two entries do not work, probably because they contain non a space and period and AVFoundation doesn't like that
+ // We know they are supported on all Apple platforms, so we'll add them manually below
+// { "; codecs=\".mp3\"", QMediaFormat::AudioCodec::MP3 },
+// { "; codecs=\"aac \"", QMediaFormat::AudioCodec::AAC },
+ { "; codecs=\"ac-3\"", QMediaFormat::AudioCodec::AC3 },
+ { "; codecs=\"ec-3\"", QMediaFormat::AudioCodec::EAC3 },
+ { "; codecs=\"flac\"", QMediaFormat::AudioCodec::FLAC },
+ { "; codecs=\"alac\"", QMediaFormat::AudioCodec::ALAC },
+ { "; codecs=\"opus\"", QMediaFormat::AudioCodec::Opus },
+ { nullptr, QMediaFormat::AudioCodec::Unspecified },
+};
+
+QDarwinFormatInfo::QDarwinFormatInfo()
+{
+ auto avtypes = [AVURLAsset audiovisualMIMETypes];
+ for (AVFileType filetype in avtypes) {
+ auto *m = mediaContainerMap;
+ while (m->name) {
+ if (strcmp(filetype.UTF8String, m->name)) {
+ ++m;
+ continue;
+ }
+
+ QList<QMediaFormat::VideoCodec> video;
+ QList<QMediaFormat::AudioCodec> audio;
+
+ auto *v = videoCodecMap;
+ while (v->name) {
+ QByteArray extendedMimetype = m->name;
+ extendedMimetype += v->name;
+ if ([AVURLAsset isPlayableExtendedMIMEType:[NSString stringWithUTF8String:extendedMimetype.constData()]])
+ video << v->value;
+ ++v;
+ }
+
+ auto *a = audioCodecMap;
+ while (a->name) {
+ QByteArray extendedMimetype = m->name;
+ extendedMimetype += a->name;
+ if ([AVURLAsset isPlayableExtendedMIMEType:[NSString stringWithUTF8String:extendedMimetype.constData()]])
+ audio << a->value;
+ ++a;
+ }
+ // Added manually, see comment in the list above
+ if (m->value <= QMediaFormat::AAC)
+ audio << QMediaFormat::AudioCodec::AAC;
+ if (m->value < QMediaFormat::AAC || m->value == QMediaFormat::MP3)
+ audio << QMediaFormat::AudioCodec::MP3;
+
+ decoders << CodecMap{ m->value, audio, video };
+ ++m;
+ }
+ }
+
+ // seems AVFoundation only supports those for encoding
+ encoders = {
+ { QMediaFormat::MPEG4,
+ { QMediaFormat::AudioCodec::AAC, QMediaFormat::AudioCodec::ALAC },
+ { QMediaFormat::VideoCodec::H264, QMediaFormat::VideoCodec::H265, QMediaFormat::VideoCodec::MotionJPEG } },
+ { QMediaFormat::QuickTime,
+ { QMediaFormat::AudioCodec::AAC, QMediaFormat::AudioCodec::ALAC },
+ { QMediaFormat::VideoCodec::H264, QMediaFormat::VideoCodec::H265, QMediaFormat::VideoCodec::MotionJPEG } },
+ { QMediaFormat::Mpeg4Audio,
+ { QMediaFormat::AudioCodec::AAC },
+ {} },
+ { QMediaFormat::Wave,
+ { QMediaFormat::AudioCodec::Wave },
+ {} },
+ };
+
+ // ###
+ imageFormats << QImageCapture::JPEG;
+}
+
+QDarwinFormatInfo::~QDarwinFormatInfo()
+{
+}
+
+int QDarwinFormatInfo::audioFormatForCodec(QMediaFormat::AudioCodec codec)
+{
+ int codecId = kAudioFormatMPEG4AAC;
+ switch (codec) {
+ case QMediaFormat::AudioCodec::Unspecified:
+ case QMediaFormat::AudioCodec::DolbyTrueHD:
+ case QMediaFormat::AudioCodec::Vorbis:
+ case QMediaFormat::AudioCodec::WMA:
+ // Unsupported, shouldn't happen. Fall back to AAC
+ case QMediaFormat::AudioCodec::AAC:
+ codecId = kAudioFormatMPEG4AAC;
+ break;
+ case QMediaFormat::AudioCodec::MP3:
+ codecId = kAudioFormatMPEGLayer3;
+ break;
+ case QMediaFormat::AudioCodec::AC3:
+ codecId = kAudioFormatAC3;
+ break;
+ case QMediaFormat::AudioCodec::EAC3:
+ codecId = kAudioFormatEnhancedAC3;
+ break;
+ case QMediaFormat::AudioCodec::FLAC:
+ codecId = kAudioFormatFLAC;
+ break;
+ case QMediaFormat::AudioCodec::ALAC:
+ codecId = kAudioFormatAppleLossless;
+ break;
+ case QMediaFormat::AudioCodec::Opus:
+ codecId = kAudioFormatOpus;
+ break;
+ case QMediaFormat::AudioCodec::Wave:
+ codecId = kAudioFormatLinearPCM;
+ }
+ return codecId;
+}
+
+NSString *QDarwinFormatInfo::videoFormatForCodec(QMediaFormat::VideoCodec codec)
+{
+ const char *c = "hvc1"; // fallback is H265
+ switch (codec) {
+ case QMediaFormat::VideoCodec::Unspecified:
+ case QMediaFormat::VideoCodec::VP8:
+ case QMediaFormat::VideoCodec::H265:
+ case QMediaFormat::VideoCodec::AV1:
+ case QMediaFormat::VideoCodec::Theora:
+ case QMediaFormat::VideoCodec::WMV:
+ break;
+
+ case QMediaFormat::VideoCodec::MPEG1:
+ c = "mp1v";
+ break;
+ case QMediaFormat::VideoCodec::MPEG2:
+ c = "mp2v";
+ break;
+ case QMediaFormat::VideoCodec::MPEG4:
+ c = "mp4v";
+ break;
+ case QMediaFormat::VideoCodec::H264:
+ c = "avc1";
+ break;
+ case QMediaFormat::VideoCodec::VP9:
+ c = "vp09";
+ break;
+ case QMediaFormat::VideoCodec::MotionJPEG:
+ c = "jpeg";
+ }
+ return [NSString stringWithUTF8String:c];
+}
+
+NSString *QDarwinFormatInfo::avFileTypeForContainerFormat(QMediaFormat::FileFormat container)
+{
+ switch (container) {
+ case QMediaFormat::MPEG4:
+ return AVFileTypeMPEG4;
+ case QMediaFormat::QuickTime:
+ return AVFileTypeQuickTimeMovie;
+ case QMediaFormat::MP3:
+ return AVFileTypeMPEGLayer3;
+ case QMediaFormat::Mpeg4Audio:
+ return AVFileTypeAppleM4A;
+ case QMediaFormat::Wave:
+ return AVFileTypeWAVE;
+ default:
+ return AVFileTypeQuickTimeMovie;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/darwin/qdarwinformatsinfo_p.h b/src/plugins/multimedia/darwin/qdarwinformatsinfo_p.h
new file mode 100644
index 000000000..e01486286
--- /dev/null
+++ b/src/plugins/multimedia/darwin/qdarwinformatsinfo_p.h
@@ -0,0 +1,38 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QDARWINFORMATINFO_H
+#define QDARWINFORMATINFO_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaformatinfo_p.h>
+#include <qlist.h>
+
+QT_BEGIN_NAMESPACE
+
+class QDarwinMediaDevices;
+
+class QDarwinFormatInfo : public QPlatformMediaFormatInfo
+{
+public:
+ QDarwinFormatInfo();
+ ~QDarwinFormatInfo();
+
+ static int audioFormatForCodec(QMediaFormat::AudioCodec codec);
+ static NSString *videoFormatForCodec(QMediaFormat::VideoCodec codec);
+ static NSString *avFileTypeForContainerFormat(QMediaFormat::FileFormat fileType);
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/darwin/qdarwinintegration.mm b/src/plugins/multimedia/darwin/qdarwinintegration.mm
new file mode 100644
index 000000000..0e880447e
--- /dev/null
+++ b/src/plugins/multimedia/darwin/qdarwinintegration.mm
@@ -0,0 +1,93 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qdarwinintegration_p.h"
+#include <avfmediaplayer_p.h>
+#include <avfcameraservice_p.h>
+#include <avfcamera_p.h>
+#include <avfimagecapture_p.h>
+#include <avfmediaencoder_p.h>
+#include <qdarwinformatsinfo_p.h>
+#include <avfvideosink_p.h>
+#include <avfaudiodecoder_p.h>
+#include <VideoToolbox/VideoToolbox.h>
+#include <qdebug.h>
+#include <private/qplatformmediaplugin_p.h>
+#include <qavfcamerabase_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QDarwinMediaPlugin : public QPlatformMediaPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QPlatformMediaPlugin_iid FILE "darwin.json")
+
+public:
+ QDarwinMediaPlugin()
+ : QPlatformMediaPlugin()
+ {}
+
+ QPlatformMediaIntegration* create(const QString &name) override
+ {
+ if (name == u"darwin")
+ return new QDarwinIntegration;
+ return nullptr;
+ }
+};
+
+QDarwinIntegration::QDarwinIntegration() : QPlatformMediaIntegration(QLatin1String("darwin"))
+{
+#if defined(Q_OS_MACOS) && QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_11_0)
+ if (__builtin_available(macOS 11.0, *))
+ VTRegisterSupplementalVideoDecoderIfAvailable(kCMVideoCodecType_VP9);
+#endif
+}
+
+QPlatformMediaFormatInfo *QDarwinIntegration::createFormatInfo()
+{
+ return new QDarwinFormatInfo();
+}
+
+QPlatformVideoDevices *QDarwinIntegration::createVideoDevices()
+{
+ return new QAVFVideoDevices(this);
+}
+
+QMaybe<QPlatformAudioDecoder *> QDarwinIntegration::createAudioDecoder(QAudioDecoder *decoder)
+{
+ return new AVFAudioDecoder(decoder);
+}
+
+QMaybe<QPlatformMediaCaptureSession *> QDarwinIntegration::createCaptureSession()
+{
+ return new AVFCameraService;
+}
+
+QMaybe<QPlatformMediaPlayer *> QDarwinIntegration::createPlayer(QMediaPlayer *player)
+{
+ return new AVFMediaPlayer(player);
+}
+
+QMaybe<QPlatformCamera *> QDarwinIntegration::createCamera(QCamera *camera)
+{
+ return new AVFCamera(camera);
+}
+
+QMaybe<QPlatformMediaRecorder *> QDarwinIntegration::createRecorder(QMediaRecorder *recorder)
+{
+ return new AVFMediaEncoder(recorder);
+}
+
+QMaybe<QPlatformImageCapture *> QDarwinIntegration::createImageCapture(QImageCapture *imageCapture)
+{
+ return new AVFImageCapture(imageCapture);
+}
+
+QMaybe<QPlatformVideoSink *> QDarwinIntegration::createVideoSink(QVideoSink *sink)
+{
+ return new AVFVideoSink(sink);
+}
+
+QT_END_NAMESPACE
+
+#include "qdarwinintegration.moc"
diff --git a/src/plugins/multimedia/darwin/qdarwinintegration_p.h b/src/plugins/multimedia/darwin/qdarwinintegration_p.h
new file mode 100644
index 000000000..8333de4ec
--- /dev/null
+++ b/src/plugins/multimedia/darwin/qdarwinintegration_p.h
@@ -0,0 +1,45 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QDARWININTEGRATION_H
+#define QDARWININTEGRATION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaintegration_p.h>
+
+Q_FORWARD_DECLARE_OBJC_CLASS(NSObject);
+
+QT_BEGIN_NAMESPACE
+
+class QDarwinIntegration : public QPlatformMediaIntegration
+{
+public:
+ QDarwinIntegration();
+
+ QMaybe<QPlatformAudioDecoder *> createAudioDecoder(QAudioDecoder *) override;
+ QMaybe<QPlatformMediaCaptureSession *> createCaptureSession() override;
+ QMaybe<QPlatformMediaPlayer *> createPlayer(QMediaPlayer *player) override;
+ QMaybe<QPlatformCamera *> createCamera(QCamera *camera) override;
+ QMaybe<QPlatformMediaRecorder *> createRecorder(QMediaRecorder *) override;
+ QMaybe<QPlatformImageCapture *> createImageCapture(QImageCapture *) override;
+
+ QMaybe<QPlatformVideoSink *> createVideoSink(QVideoSink *) override;
+
+protected:
+ QPlatformMediaFormatInfo *createFormatInfo() override;
+ QPlatformVideoDevices *createVideoDevices() override;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/CMakeLists.txt b/src/plugins/multimedia/ffmpeg/CMakeLists.txt
new file mode 100644
index 000000000..c6ab93273
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/CMakeLists.txt
@@ -0,0 +1,260 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_find_package(EGL)
+qt_find_package(VAAPI COMPONENTS VA DRM PROVIDED_TARGETS VAAPI::VAAPI MODULE_NAME multimedia QMAKE_LIB vaapi)
+
+qt_internal_find_apple_system_framework(FWCoreMedia CoreMedia)
+qt_internal_find_apple_system_framework(FWCoreAudio CoreAudio)
+qt_internal_find_apple_system_framework(FWAudioUnit AudioUnit)
+qt_internal_find_apple_system_framework(FWVideoToolbox VideoToolbox)
+qt_internal_find_apple_system_framework(FWAVFoundation AVFoundation)
+qt_internal_find_apple_system_framework(FWSecurity Security)
+
+qt_internal_add_plugin(QFFmpegMediaPlugin
+ OUTPUT_NAME ffmpegmediaplugin
+ PLUGIN_TYPE multimedia
+ SOURCES
+ qffmpeg.cpp qffmpeg_p.h
+ qffmpegdefs_p.h
+ qffmpegioutils.cpp qffmpegioutils_p.h
+ qffmpegavaudioformat.cpp qffmpegavaudioformat_p.h
+ qffmpegaudiodecoder.cpp qffmpegaudiodecoder_p.h
+ qffmpegaudioinput.cpp qffmpegaudioinput_p.h
+ qffmpegconverter.cpp qffmpegconverter_p.h
+ qffmpeghwaccel.cpp qffmpeghwaccel_p.h
+ qffmpegmediametadata.cpp qffmpegmediametadata_p.h
+ qffmpegmediaplayer.cpp qffmpegmediaplayer_p.h
+ qffmpegvideosink.cpp qffmpegvideosink_p.h
+ qffmpegmediaformatinfo.cpp qffmpegmediaformatinfo_p.h
+ qffmpegmediaintegration.cpp qffmpegmediaintegration_p.h
+ qffmpegvideobuffer.cpp qffmpegvideobuffer_p.h
+ qffmpegimagecapture.cpp qffmpegimagecapture_p.h
+ qffmpegmediacapturesession.cpp qffmpegmediacapturesession_p.h
+ qffmpegmediarecorder.cpp qffmpegmediarecorder_p.h
+ qffmpegthread.cpp qffmpegthread_p.h
+ qffmpegresampler.cpp qffmpegresampler_p.h
+ qffmpegencodingformatcontext.cpp qffmpegencodingformatcontext_p.h
+ qgrabwindowsurfacecapture.cpp qgrabwindowsurfacecapture_p.h
+ qffmpegsurfacecapturegrabber.cpp qffmpegsurfacecapturegrabber_p.h
+
+ qffmpegplaybackengine.cpp qffmpegplaybackengine_p.h
+ playbackengine/qffmpegplaybackenginedefs_p.h
+ playbackengine/qffmpegplaybackengineobject.cpp playbackengine/qffmpegplaybackengineobject_p.h
+ playbackengine/qffmpegdemuxer.cpp playbackengine/qffmpegdemuxer_p.h
+ playbackengine/qffmpegstreamdecoder.cpp playbackengine/qffmpegstreamdecoder_p.h
+ playbackengine/qffmpegrenderer.cpp playbackengine/qffmpegrenderer_p.h
+ playbackengine/qffmpegaudiorenderer.cpp playbackengine/qffmpegaudiorenderer_p.h
+ playbackengine/qffmpegvideorenderer.cpp playbackengine/qffmpegvideorenderer_p.h
+ playbackengine/qffmpegsubtitlerenderer.cpp playbackengine/qffmpegsubtitlerenderer_p.h
+ playbackengine/qffmpegtimecontroller.cpp playbackengine/qffmpegtimecontroller_p.h
+ playbackengine/qffmpegmediadataholder.cpp playbackengine/qffmpegmediadataholder_p.h
+ playbackengine/qffmpegcodec.cpp playbackengine/qffmpegcodec_p.h
+ playbackengine/qffmpegpacket_p.h
+ playbackengine/qffmpegframe_p.h
+ playbackengine/qffmpegpositionwithoffset_p.h
+
+ recordingengine/qffmpegaudioencoder_p.h
+ recordingengine/qffmpegaudioencoder.cpp
+ recordingengine/qffmpegaudioencoderutils_p.h
+ recordingengine/qffmpegaudioencoderutils.cpp
+ recordingengine/qffmpegencoderthread_p.h
+ recordingengine/qffmpegencoderthread.cpp
+ recordingengine/qffmpegencoderoptions_p.h
+ recordingengine/qffmpegencoderoptions.cpp
+ recordingengine/qffmpegmuxer_p.h
+ recordingengine/qffmpegmuxer.cpp
+ recordingengine/qffmpegrecordingengine_p.h
+ recordingengine/qffmpegrecordingengine.cpp
+ recordingengine/qffmpegencodinginitializer_p.h
+ recordingengine/qffmpegencodinginitializer.cpp
+ recordingengine/qffmpegrecordingengineutils_p.h
+ recordingengine/qffmpegrecordingengineutils.cpp
+ recordingengine/qffmpegvideoencoder_p.h
+ recordingengine/qffmpegvideoencoder.cpp
+ recordingengine/qffmpegvideoencoderutils_p.h
+ recordingengine/qffmpegvideoencoderutils.cpp
+ recordingengine/qffmpegvideoframeencoder_p.h
+ recordingengine/qffmpegvideoframeencoder.cpp
+
+ DEFINES
+ QT_COMPILING_FFMPEG
+ LIBRARIES
+ Qt::MultimediaPrivate
+ Qt::CorePrivate
+)
+
+if (LINUX OR ANDROID)
+ # We have 2 options: link shared stubs to QFFmpegMediaPlugin vs
+ # static compilation of the needed stubs to the FFmpeg plugin.
+ # Currently, we chose the second option so that user could trivially
+ # remove the FFmpeg libs we ship.
+ # Set QT_LINK_STUBS_TO_FFMPEG_PLUGIN = TRUE to change the behavior.
+
+ # set(QT_LINK_STUBS_TO_FFMPEG_PLUGIN TRUE)
+
+ include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtAddFFmpegStubs.cmake")
+ qt_internal_multimedia_add_ffmpeg_stubs()
+endif()
+
+
+if (QT_FEATURE_vaapi)
+ qt_internal_extend_target(QFFmpegMediaPlugin
+ SOURCES
+ qffmpeghwaccel_vaapi.cpp qffmpeghwaccel_vaapi_p.h
+ NO_UNITY_BUILD_SOURCES
+ # Conflicts with macros defined in X11.h, and Xlib.h
+ qffmpeghwaccel_vaapi.cpp
+ LIBRARIES
+ EGL::EGL
+ )
+
+ list(FIND FFMPEG_STUBS "va" va_stub_index)
+ if (NOT QT_LINK_STUBS_TO_FFMPEG_PLUGIN AND (FFMPEG_SHARED_LIBRARIES OR ${va_stub_index} EQUAL -1))
+ target_compile_definitions(QFFmpegMediaPlugin PRIVATE Q_FFMPEG_PLUGIN_STUBS_ONLY)
+ qt_internal_multimedia_find_vaapi_soversion()
+ qt_internal_multimedia_add_private_stub_to_plugin("va")
+ endif()
+endif()
+
+
+qt_internal_extend_target(QFFmpegMediaPlugin CONDITION APPLE
+ SOURCES
+ ../darwin/qavfhelpers.mm ../darwin/qavfhelpers_p.h
+ ../darwin/camera/qavfcamerabase_p.h ../darwin/camera/qavfcamerabase.mm
+ ../darwin/camera/avfcamerautility_p.h ../darwin/camera/avfcamerautility.mm
+ qffmpeghwaccel_videotoolbox.mm qffmpeghwaccel_videotoolbox_p.h
+ qavfcamera.mm qavfcamera_p.h
+ qavfsamplebufferdelegate.mm qavfsamplebufferdelegate_p.h
+
+ NO_UNITY_BUILD_SOURCES
+ qffmpeghwaccel_videotoolbox.mm # AVMediaType clash between libavformat and AVFoundation
+
+ INCLUDE_DIRECTORIES
+ ../darwin
+ ../darwin/camera
+ LIBRARIES
+ ${FWAudioToolbox}
+ ${FWCoreAudio}
+ ${FWCoreFoundation}
+ ${FWCoreMedia}
+ ${FWCoreVideo}
+ ${FWVideoToolbox}
+ ${FWSecurity}
+ AVFoundation::AVFoundation
+)
+
+qt_internal_extend_target(QFFmpegMediaPlugin CONDITION MACOS
+ SOURCES
+ qavfscreencapture.mm qavfscreencapture_p.h
+ qcgwindowcapture.mm qcgwindowcapture_p.h
+ qcgcapturablewindows.mm qcgcapturablewindows_p.h
+)
+
+qt_internal_extend_target(QFFmpegMediaPlugin CONDITION WIN32
+ SOURCES
+ ../windows/qwindowsvideodevices.cpp ../windows/qwindowsvideodevices_p.h
+ qwindowscamera.cpp qwindowscamera_p.h
+ qffmpeghwaccel_d3d11.cpp qffmpeghwaccel_d3d11_p.h
+ qgdiwindowcapture.cpp qgdiwindowcapture_p.h
+ qffmpegscreencapture_dxgi.cpp qffmpegscreencapture_dxgi_p.h
+ qwincapturablewindows.cpp qwincapturablewindows_p.h
+ INCLUDE_DIRECTORIES
+ ../windows
+ LIBRARIES
+ Qt::MultimediaPrivate
+ WMF::WMF
+ mfreadwrite
+)
+
+qt_internal_extend_target(QFFmpegMediaPlugin CONDITION QT_FEATURE_cpp_winrt
+ SOURCES
+ qffmpegwindowcapture_uwp.cpp qffmpegwindowcapture_uwp_p.h
+ INCLUDE_DIRECTORIES
+ ../windows
+ LIBRARIES
+ Dwmapi
+ Dxva2
+ windowsapp
+)
+
+qt_internal_extend_target(QFFmpegMediaPlugin CONDITION QT_FEATURE_xlib
+ SOURCES
+ qx11surfacecapture.cpp qx11surfacecapture_p.h
+ qx11capturablewindows.cpp qx11capturablewindows_p.h
+ LIBRARIES
+ X11
+ Xrandr
+ Xext
+)
+
+qt_internal_extend_target(QFFmpegMediaPlugin CONDITION QT_FEATURE_eglfs
+ SOURCES
+ qeglfsscreencapture.cpp qeglfsscreencapture_p.h
+ qopenglvideobuffer.cpp qopenglvideobuffer_p.h
+ LIBRARIES
+ Qt::OpenGLPrivate
+ Qt::Quick
+)
+
+set_source_files_properties(qx11surfacecapture.cpp qx11capturablewindows.cpp # X headers
+ PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
+
+qt_internal_extend_target(QFFmpegMediaPlugin CONDITION QT_FEATURE_linux_v4l
+ SOURCES
+ qv4l2camera.cpp qv4l2camera_p.h
+ qv4l2filedescriptor.cpp qv4l2filedescriptor_p.h
+ qv4l2memorytransfer.cpp qv4l2memorytransfer_p.h
+ qv4l2cameradevices.cpp qv4l2cameradevices_p.h
+)
+
+if (ANDROID)
+ qt_internal_extend_target(QFFmpegMediaPlugin
+ SOURCES
+ qffmpeghwaccel_mediacodec.cpp qffmpeghwaccel_mediacodec_p.h
+ qandroidcamera_p.h qandroidcamera.cpp
+ qandroidvideodevices.cpp qandroidvideodevices_p.h
+ qandroidcameraframe_p.h qandroidcameraframe.cpp
+ qandroidimagecapture_p.h qandroidimagecapture.cpp
+ ../android/wrappers/jni/androidsurfacetexture_p.h
+ ../android/wrappers/jni/androidsurfacetexture.cpp
+ NO_UNITY_BUILD_SOURCES
+ # Duplicate declration of JNI Classes using `Q_DECLARE_JNI_CLASS`
+ qandroidcamera.cpp
+ qandroidvideodevices.cpp
+ qandroidcameraframe.cpp
+ INCLUDE_DIRECTORIES
+ ${FFMPEG_DIR}/include
+ ../android/wrappers/jni/
+ LIBRARIES
+ OpenSLES
+ mediandk
+ android
+ )
+
+ set_property(TARGET QFFmpegMediaPlugin APPEND PROPERTY QT_ANDROID_LIB_DEPENDENCIES
+ ${INSTALL_PLUGINSDIR}/multimedia/libplugins_multimedia_ffmpegmediaplugin.so
+ )
+
+ set_property(TARGET QFFmpegMediaPlugin APPEND PROPERTY QT_ANDROID_PERMISSIONS
+ android.permission.CAMERA
+ android.permission.RECORD_AUDIO
+ android.permission.BLUETOOTH
+ android.permission.MODIFY_AUDIO_SETTINGS
+ )
+endif()
+
+# TODO: get libs from FindFFmpeg.cmake
+set(ffmpeg_libs FFmpeg::avformat FFmpeg::avcodec FFmpeg::swresample FFmpeg::swscale FFmpeg::avutil)
+
+if (QT_DEPLOY_FFMPEG AND NOT BUILD_SHARED_LIBS AND NOT UIKIT)
+ message(FATAL_ERROR "QT_DEPLOY_FFMPEG is not implemented yet for static builds")
+endif()
+
+if (QT_DEPLOY_FFMPEG AND FFMPEG_SHARED_LIBRARIES AND (BUILD_SHARED_LIBS OR UIKIT))
+ include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtDeployFFmpeg.cmake")
+ qt_internal_multimedia_copy_or_install_ffmpeg()
+endif()
+
+qt_internal_extend_target(QFFmpegMediaPlugin LIBRARIES ${ffmpeg_libs})
+
diff --git a/src/plugins/multimedia/ffmpeg/cmake/QtAddFFmpegStubs.cmake b/src/plugins/multimedia/ffmpeg/cmake/QtAddFFmpegStubs.cmake
new file mode 100644
index 000000000..5778ae4d2
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/cmake/QtAddFFmpegStubs.cmake
@@ -0,0 +1,199 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Utilities
+
+function(qt_internal_multimedia_find_ffmpeg_stubs)
+ foreach (stub ${FFMPEG_STUBS})
+ if (${stub} MATCHES ${vaapi_regex})
+ set(ffmpeg_has_vaapi TRUE PARENT_SCOPE)
+ elseif (${stub} MATCHES ${openssl_regex})
+ set(ffmpeg_has_openssl TRUE PARENT_SCOPE)
+ else()
+ set(unknown_ffmpeg_stubs
+ ${unknown_ffmpeg_stubs} ${stub} PARENT_SCOPE)
+ endif()
+ endforeach()
+endfunction()
+
+function(qt_internal_multimedia_check_ffmpeg_stubs_configuration)
+ if (NOT LINUX AND NOT ANDROID)
+ message(FATAL_ERROR "Currently, stubs are supported on Linux and Android")
+ endif()
+
+ if (unknown_ffmpeg_stubs)
+ message(FATAL_ERROR "Unknown ffmpeg stubs: ${unknown_ffmpeg_stubs}")
+ endif()
+
+ if (BUILD_SHARED_LIBS AND FFMPEG_SHARED_LIBRARIES AND FFMPEG_STUBS AND NOT QT_DEPLOY_FFMPEG)
+ message(FATAL_ERROR
+ "FFmpeg stubs have been found but QT_DEPLOY_FFMPEG is not specified. "
+ "Set -DQT_DEPLOY_FFMPEG=TRUE to continue.")
+ endif()
+
+ if (ffmpeg_has_vaapi AND NOT QT_FEATURE_vaapi)
+ message(FATAL_ERROR
+ "QT_FEATURE_vaapi is OFF but FFmpeg includes VAAPI.")
+ elseif (NOT ffmpeg_has_vaapi AND QT_FEATURE_vaapi)
+ message(WARNING
+ "QT_FEATURE_vaapi is ON "
+ "but FFmpeg includes VAAPI and dynamic symbols resolve is enabled.")
+ elseif(ffmpeg_has_vaapi AND NOT VAAPI_SUFFIX)
+ message(FATAL_ERROR "Cannot find VAAPI_SUFFIX, fix FindVAAPI.cmake")
+ elseif (ffmpeg_has_vaapi AND "${VAAPI_SUFFIX}" MATCHES "^1\\.32.*")
+ # drop the ancient vaapi version to avoid ABI problems
+ message(FATAL_ERROR "VAAPI ${VAAPI_SUFFIX} is not supported")
+ endif()
+
+ if (ffmpeg_has_openssl AND NOT QT_FEATURE_openssl)
+ message(FATAL_ERROR
+ "QT_FEATURE_openssl is OFF but FFmpeg includes OpenSSL.")
+ endif()
+endfunction()
+
+macro(qt_internal_multimedia_find_vaapi_soversion)
+ string(REGEX MATCH "^[0-9]+" va_soversion "${VAAPI_SUFFIX}")
+
+ set(va-drm_soversion "${va_soversion}")
+ set(va-x11_soversion "${va_soversion}")
+endmacro()
+
+macro(qt_internal_multimedia_find_openssl_soversion)
+ # Update OpenSSL variables since OPENSSL_SSL_LIBRARY is not propagated to this place in some cases.
+ qt_find_package(OpenSSL)
+
+ if (NOT OPENSSL_INCLUDE_DIR AND OPENSSL_ROOT_DIR)
+ set(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include")
+ endif()
+
+ if (LINUX)
+ if (NOT OPENSSL_SSL_LIBRARY)
+ message(FATAL_ERROR "OPENSSL_SSL_LIBRARY is not found")
+ endif()
+
+ get_filename_component(ssl_lib_realpath "${OPENSSL_SSL_LIBRARY}" REALPATH)
+ string(REGEX MATCH "[0-9]+(\\.[0-9]+)*$" ssl_soversion "${ssl_lib_realpath}")
+ string(REGEX REPLACE "^3(\\..*|$)" "3" ssl_soversion "${ssl_soversion}")
+ endif()
+
+ #TODO: enhance finding openssl version and throw an error if it's not found.
+
+ set(crypto_soversion "${ssl_soversion}")
+endmacro()
+
+function(qt_internal_multimedia_set_stub_version_script stub stub_target)
+ if ("${stub}" MATCHES "${openssl_regex}")
+ if ("${ssl_soversion}" STREQUAL "3" OR
+ (NOT ssl_soversion AND "${OPENSSL_VERSION}" MATCHES "^3\\..*"))
+ # Symbols in OpenSSL 1.* are not versioned.
+ set(file_name "openssl3.ver")
+ endif()
+ elseif("${stub}" STREQUAL "va")
+ set(file_name "va.ver")
+ endif()
+
+ if (file_name)
+ set(version_script "${CMAKE_CURRENT_SOURCE_DIR}/symbolstubs/${file_name}")
+ set_property(TARGET ${stub_target} APPEND_STRING
+ PROPERTY LINK_FLAGS " -Wl,--version-script=${version_script}")
+ set_target_properties(${stub_target} PROPERTIES LINK_DEPENDS ${version_script})
+ source_group("Stubs Version Scripts" FILES ${version_script})
+ endif()
+endfunction()
+
+function(qt_internal_multimedia_set_stub_output stub stub_target)
+ set(output_dir "${QT_BUILD_DIR}/${INSTALL_LIBDIR}")
+
+ set_target_properties(${stub_target} PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY "${output_dir}"
+ LIBRARY_OUTPUT_DIRECTORY "${output_dir}"
+ )
+
+ if (${stub}_soversion)
+ set_target_properties(${stub_target} PROPERTIES
+ VERSION "${${stub}_soversion}"
+ SOVERSION "${${stub}_soversion}")
+ endif()
+
+ qt_apply_rpaths(TARGET ${stub_target} INSTALL_PATH "${INSTALL_LIBDIR}" RELATIVE_RPATH)
+endfunction()
+
+function(qt_internal_multimedia_set_stub_include_directories stub target)
+ qt_internal_extend_target(${target}
+ CONDITION ${stub} MATCHES "${openssl_regex}"
+ INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
+
+ qt_internal_extend_target(${target}
+ CONDITION ${stub} MATCHES "${vaapi_regex}"
+ INCLUDE_DIRECTORIES "${VAAPI_INCLUDE_DIR}")
+endfunction()
+
+function(qt_internal_multimedia_set_stub_symbols_visibility stub stub_target)
+ set_target_properties(${stub_target} PROPERTIES
+ C_VISIBILITY_PRESET hidden
+ CXX_VISIBILITY_PRESET hidden)
+ target_compile_definitions(${stub_target} PRIVATE Q_EXPORT_STUB_SYMBOLS)
+endfunction()
+
+function(qt_internal_multimedia_set_stub_libraries stub stub_target)
+ qt_internal_extend_target(${stub_target} LIBRARIES Qt::Core Qt::MultimediaPrivate)
+
+ if (LINK_STUBS_TO_FFMPEG_PLUGIN AND ${stub} STREQUAL "va")
+ qt_internal_extend_target(QFFmpegMediaPlugin LIBRARIES ${stub_target})
+ endif()
+endfunction()
+
+function(qt_internal_multimedia_define_stub_needed_version stub target)
+ string(TOUPPER ${stub} prefix)
+ string(REPLACE "-" "_" prefix ${prefix})
+
+ target_compile_definitions(${target} PRIVATE
+ "${prefix}_NEEDED_SOVERSION=\"${${stub}_soversion}\"")
+endfunction()
+
+function(qt_internal_multimedia_add_shared_stub stub)
+ set(stub_target "Qt${PROJECT_VERSION_MAJOR}FFmpegStub-${stub}")
+
+ qt_add_library(${stub_target} SHARED "symbolstubs/qffmpegsymbols-${stub}.cpp")
+
+ qt_internal_multimedia_set_stub_include_directories(${stub} ${stub_target})
+ qt_internal_multimedia_set_stub_output(${stub} ${stub_target})
+ qt_internal_multimedia_set_stub_symbols_visibility(${stub} ${stub_target})
+ qt_internal_multimedia_set_stub_version_script(${stub} ${stub_target})
+ qt_internal_multimedia_define_stub_needed_version(${stub} ${stub_target})
+ qt_internal_multimedia_set_stub_libraries(${stub} ${stub_target})
+
+ qt_install(TARGETS ${stub_target} LIBRARY NAMELINK_SKIP)
+endfunction()
+
+function(qt_internal_multimedia_add_private_stub_to_plugin stub)
+ qt_internal_multimedia_set_stub_include_directories(${stub} QFFmpegMediaPlugin)
+ qt_internal_multimedia_define_stub_needed_version(${stub} QFFmpegMediaPlugin)
+ qt_internal_extend_target(QFFmpegMediaPlugin SOURCES "symbolstubs/qffmpegsymbols-${stub}.cpp")
+endfunction()
+
+# Main function
+
+set(vaapi_regex "^(va|va-drm|va-x11)$")
+set(openssl_regex "^(ssl|crypto)$")
+
+function(qt_internal_multimedia_add_ffmpeg_stubs)
+ qt_internal_multimedia_find_ffmpeg_stubs()
+ qt_internal_multimedia_check_ffmpeg_stubs_configuration()
+
+ if (ffmpeg_has_vaapi)
+ qt_internal_multimedia_find_vaapi_soversion()
+ endif()
+
+ if (ffmpeg_has_openssl)
+ qt_internal_multimedia_find_openssl_soversion()
+ endif()
+
+ foreach (stub ${FFMPEG_STUBS})
+ if (FFMPEG_SHARED_LIBRARIES)
+ qt_internal_multimedia_add_shared_stub("${stub}")
+ else()
+ qt_internal_multimedia_add_private_stub_to_plugin("${stub}")
+ endif()
+ endforeach()
+endfunction()
diff --git a/src/plugins/multimedia/ffmpeg/cmake/QtDeployFFmpeg.cmake b/src/plugins/multimedia/ffmpeg/cmake/QtDeployFFmpeg.cmake
new file mode 100644
index 000000000..5e7d4b552
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/cmake/QtDeployFFmpeg.cmake
@@ -0,0 +1,43 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+function(qt_internal_multimedia_set_ffmpeg_link_directory directory)
+ foreach (lib ${ffmpeg_libs} FFmpeg)
+ set_target_properties(${lib} PROPERTIES INTERFACE_LINK_DIRECTORIES ${directory})
+ endforeach()
+endfunction()
+
+function(qt_internal_multimedia_copy_or_install_ffmpeg)
+ if (WIN32)
+ set(install_dir ${INSTALL_BINDIR})
+ else()
+ set(install_dir ${INSTALL_LIBDIR})
+ endif()
+
+ if (QT_WILL_INSTALL)
+ qt_install(FILES "${FFMPEG_SHARED_LIBRARIES}" DESTINATION ${install_dir})
+ else()
+ # elseif(NOT WIN32) actually we can just drop the coping for unix platforms
+ # However, it makes sense to copy anyway for consistency:
+ # in order to have the same configuration for developer builds.
+
+ set(ffmpeg_output_dir "${QT_BUILD_DIR}/${install_dir}")
+ file(MAKE_DIRECTORY ${ffmpeg_output_dir})
+
+ foreach(lib_path ${FFMPEG_SHARED_LIBRARIES})
+ get_filename_component(lib_name ${lib_path} NAME)
+ if(NOT EXISTS "${ffmpeg_output_dir}/${lib_name}")
+ file(COPY ${lib_path} DESTINATION ${ffmpeg_output_dir})
+ endif()
+ endforeach()
+
+ # On Windows, shared linking goes through 'integration' static libs,
+ # otherwise we should link the directory with copied libs
+ if (NOT WIN32)
+ qt_internal_multimedia_set_ffmpeg_link_directory(${ffmpeg_output_dir})
+ endif()
+ endif()
+
+ # Should we set the compile definition for the plugin or for the QtMM module?
+ # target_compile_definitions(QFFmpegMediaPlugin PRIVATE FFMPEG_DEPLOY_FOLDER="${FFMPEG_DEPLOY_FOLDER}")
+endfunction()
diff --git a/src/plugins/multimedia/ffmpeg/ffmpeg.json b/src/plugins/multimedia/ffmpeg/ffmpeg.json
new file mode 100644
index 000000000..d8e7e4456
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/ffmpeg.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "ffmpeg" ]
+}
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer.cpp b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer.cpp
new file mode 100644
index 000000000..64bd82dc0
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer.cpp
@@ -0,0 +1,407 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "playbackengine/qffmpegaudiorenderer_p.h"
+#include "qaudiosink.h"
+#include "qaudiooutput.h"
+#include "qaudiobufferoutput.h"
+#include "private/qplatformaudiooutput_p.h"
+#include <QtCore/qloggingcategory.h>
+
+#include "qffmpegresampler_p.h"
+#include "qffmpegmediaformatinfo_p.h"
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcAudioRenderer, "qt.multimedia.ffmpeg.audiorenderer");
+
+namespace QFFmpeg {
+
+using namespace std::chrono_literals;
+using namespace std::chrono;
+
+namespace {
+constexpr auto DesiredBufferTime = 110000us;
+constexpr auto MinDesiredBufferTime = 22000us;
+constexpr auto MaxDesiredBufferTime = 64000us;
+constexpr auto MinDesiredFreeBufferTime = 10000us;
+
+// It might be changed with #ifdef, as on Linux, QPulseAudioSink has quite unstable timings,
+// and it needs much more time to make sure that the buffer is overloaded.
+constexpr auto BufferLoadingMeasureTime = 400ms;
+
+constexpr auto DurationBias = 2ms; // avoids extra timer events
+
+qreal sampleRateFactor() {
+ // Test purposes:
+ //
+ // The env var describes a factor for the sample rate of
+ // audio data that we feed to the audio sink.
+ //
+ // In some cases audio sink might consume data slightly slower or faster than expected;
+ // even though the synchronization in the audio renderer is supposed to handle it,
+ // it makes sense to experiment with QT_MEDIA_PLAYER_AUDIO_SAMPLE_RATE_FACTOR != 1.
+ //
+ // Set QT_MEDIA_PLAYER_AUDIO_SAMPLE_RATE_FACTOR > 1 (e.g. 1.01 - 1.1) to test high buffer loading
+ // or try compensating too fast data consumption by the audio sink.
+ // Set QT_MEDIA_PLAYER_AUDIO_SAMPLE_RATE_FACTOR < 1 to test low buffer loading
+ // or try compensating too slow data consumption by the audio sink.
+
+
+ static const qreal result = []() {
+ const auto sampleRateFactorStr = qEnvironmentVariable("QT_MEDIA_PLAYER_AUDIO_SAMPLE_RATE_FACTOR");
+ bool ok = false;
+ const auto result = sampleRateFactorStr.toDouble(&ok);
+ return ok ? result : 1.;
+ }();
+
+ return result;
+}
+
+QAudioFormat audioFormatFromFrame(const Frame &frame)
+{
+ return QFFmpegMediaFormatInfo::audioFormatFromCodecParameters(
+ frame.codec()->stream()->codecpar);
+}
+
+std::unique_ptr<QFFmpegResampler> createResampler(const Frame &frame,
+ const QAudioFormat &outputFormat)
+{
+ return std::make_unique<QFFmpegResampler>(frame.codec(), outputFormat, frame.pts());
+}
+
+} // namespace
+
+AudioRenderer::AudioRenderer(const TimeController &tc, QAudioOutput *output,
+ QAudioBufferOutput *bufferOutput)
+ : Renderer(tc), m_output(output), m_bufferOutput(bufferOutput)
+{
+ if (output) {
+ // TODO: implement the signals in QPlatformAudioOutput and connect to them, QTBUG-112294
+ connect(output, &QAudioOutput::deviceChanged, this, &AudioRenderer::onDeviceChanged);
+ connect(output, &QAudioOutput::volumeChanged, this, &AudioRenderer::updateVolume);
+ connect(output, &QAudioOutput::mutedChanged, this, &AudioRenderer::updateVolume);
+ }
+}
+
+void AudioRenderer::setOutput(QAudioOutput *output)
+{
+ setOutputInternal(m_output, output, [this](QAudioOutput *) { onDeviceChanged(); });
+}
+
+void AudioRenderer::setOutput(QAudioBufferOutput *bufferOutput)
+{
+ setOutputInternal(m_bufferOutput, bufferOutput,
+ [this](QAudioBufferOutput *) { m_bufferOutputChanged = true; });
+}
+
+AudioRenderer::~AudioRenderer()
+{
+ freeOutput();
+}
+
+void AudioRenderer::updateVolume()
+{
+ if (m_sink)
+ m_sink->setVolume(m_output->isMuted() ? 0.f : m_output->volume());
+}
+
+void AudioRenderer::onDeviceChanged()
+{
+ m_deviceChanged = true;
+}
+
+Renderer::RenderingResult AudioRenderer::renderInternal(Frame frame)
+{
+ if (frame.isValid())
+ updateOutputs(frame);
+
+ // push to sink first in order not to waste time on resampling
+ // for QAudioBufferOutput
+ const RenderingResult result = pushFrameToOutput(frame);
+
+ if (m_lastFramePushDone)
+ pushFrameToBufferOutput(frame);
+ // else // skip pushing the same data to QAudioBufferOutput
+
+ m_lastFramePushDone = result.done;
+
+ return result;
+}
+
+AudioRenderer::RenderingResult AudioRenderer::pushFrameToOutput(const Frame &frame)
+{
+ if (!m_ioDevice || !m_resampler)
+ return {};
+
+ Q_ASSERT(m_sink);
+
+ auto firstFrameFlagGuard = qScopeGuard([&]() { m_firstFrameToSink = false; });
+
+ const SynchronizationStamp syncStamp{ m_sink->state(), m_sink->bytesFree(),
+ m_bufferedData.offset, Clock::now() };
+
+ if (!m_bufferedData.isValid()) {
+ if (!frame.isValid()) {
+ if (std::exchange(m_drained, true))
+ return {};
+
+ const auto time = bufferLoadingTime(syncStamp);
+
+ qCDebug(qLcAudioRenderer) << "Draining AudioRenderer, time:" << time;
+
+ return { time.count() == 0, time };
+ }
+
+ m_bufferedData = { m_resampler->resample(frame.avFrame()) };
+ }
+
+ if (m_bufferedData.isValid()) {
+ // synchronize after "QIODevice::write" to deliver audio data to the sink ASAP.
+ auto syncGuard = qScopeGuard([&]() { updateSynchronization(syncStamp, frame); });
+
+ const auto bytesWritten = m_ioDevice->write(m_bufferedData.data(), m_bufferedData.size());
+
+ m_bufferedData.offset += bytesWritten;
+
+ if (m_bufferedData.size() <= 0) {
+ m_bufferedData = {};
+
+ return {};
+ }
+
+ const auto remainingDuration = durationForBytes(m_bufferedData.size());
+
+ return { false,
+ std::min(remainingDuration + DurationBias, m_timings.actualBufferDuration / 2) };
+ }
+
+ return {};
+}
+
+void AudioRenderer::pushFrameToBufferOutput(const Frame &frame)
+{
+ if (!m_bufferOutput)
+ return;
+
+ Q_ASSERT(m_bufferOutputResampler);
+
+ if (frame.isValid()) {
+ // TODO: get buffer from m_bufferedData if resample formats are equal
+ QAudioBuffer buffer = m_resampler->resample(frame.avFrame());
+ emit m_bufferOutput->audioBufferReceived(buffer);
+ } else {
+ emit m_bufferOutput->audioBufferReceived({});
+ }
+}
+
+void AudioRenderer::onPlaybackRateChanged()
+{
+ m_resampler.reset();
+}
+
+int AudioRenderer::timerInterval() const
+{
+ constexpr auto MaxFixableInterval = 50; // ms
+
+ const auto interval = Renderer::timerInterval();
+
+ if (m_firstFrameToSink || !m_sink || m_sink->state() != QAudio::IdleState
+ || interval > MaxFixableInterval)
+ return interval;
+
+ return 0;
+}
+
+void AudioRenderer::onPauseChanged()
+{
+ m_firstFrameToSink = true;
+ Renderer::onPauseChanged();
+}
+
+void AudioRenderer::initResempler(const Frame &frame)
+{
+ // We recreate resampler whenever format is changed
+
+ auto resamplerFormat = m_sinkFormat;
+ resamplerFormat.setSampleRate(
+ qRound(m_sinkFormat.sampleRate() / playbackRate() * sampleRateFactor()));
+ m_resampler = createResampler(frame, resamplerFormat);
+}
+
+void AudioRenderer::freeOutput()
+{
+ qCDebug(qLcAudioRenderer) << "Free audio output";
+ if (m_sink) {
+ m_sink->reset();
+
+ // TODO: inestigate if it's enough to reset the sink without deleting
+ m_sink.reset();
+ }
+
+ m_ioDevice = nullptr;
+
+ m_bufferedData = {};
+ m_deviceChanged = false;
+ m_sinkFormat = {};
+ m_timings = {};
+ m_bufferLoadingInfo = {};
+}
+
+void AudioRenderer::updateOutputs(const Frame &frame)
+{
+ if (m_deviceChanged) {
+ freeOutput();
+ m_resampler.reset();
+ }
+
+ if (m_bufferOutput) {
+ if (m_bufferOutputChanged) {
+ m_bufferOutputChanged = false;
+ m_bufferOutputResampler.reset();
+ }
+
+ if (!m_bufferOutputResampler) {
+ QAudioFormat outputFormat = m_bufferOutput->format();
+ if (!outputFormat.isValid())
+ outputFormat = audioFormatFromFrame(frame);
+ m_bufferOutputResampler = createResampler(frame, outputFormat);
+ }
+ }
+
+ if (!m_output)
+ return;
+
+ if (!m_sinkFormat.isValid()) {
+ m_sinkFormat = audioFormatFromFrame(frame);
+ m_sinkFormat.setChannelConfig(m_output->device().channelConfiguration());
+ }
+
+ if (!m_sink) {
+ // Insert a delay here to test time offset synchronization, e.g. QThread::sleep(1)
+ m_sink = std::make_unique<QAudioSink>(m_output->device(), m_sinkFormat);
+ updateVolume();
+ m_sink->setBufferSize(m_sinkFormat.bytesForDuration(DesiredBufferTime.count()));
+ m_ioDevice = m_sink->start();
+ m_firstFrameToSink = true;
+
+ connect(m_sink.get(), &QAudioSink::stateChanged, this,
+ &AudioRenderer::onAudioSinkStateChanged);
+
+ m_timings.actualBufferDuration = durationForBytes(m_sink->bufferSize());
+ m_timings.maxSoundDelay = qMin(MaxDesiredBufferTime,
+ m_timings.actualBufferDuration - MinDesiredFreeBufferTime);
+ m_timings.minSoundDelay = MinDesiredBufferTime;
+
+ Q_ASSERT(DurationBias < m_timings.minSoundDelay
+ && m_timings.maxSoundDelay < m_timings.actualBufferDuration);
+ }
+
+ if (!m_resampler)
+ initResempler(frame);
+}
+
+void AudioRenderer::updateSynchronization(const SynchronizationStamp &stamp, const Frame &frame)
+{
+ if (!frame.isValid())
+ return;
+
+ Q_ASSERT(m_sink);
+
+ const auto bufferLoadingTime = this->bufferLoadingTime(stamp);
+ const auto currentFrameDelay = frameDelay(frame, stamp.timePoint);
+ const auto writtenTime = durationForBytes(stamp.bufferBytesWritten);
+ const auto soundDelay = currentFrameDelay + bufferLoadingTime - writtenTime;
+
+ auto synchronize = [&](microseconds fixedDelay, microseconds targetSoundDelay) {
+ // TODO: investigate if we need sample compensation here
+
+ changeRendererTime(fixedDelay - targetSoundDelay);
+ if (qLcAudioRenderer().isDebugEnabled()) {
+ // clang-format off
+ qCDebug(qLcAudioRenderer)
+ << "Change rendering time:"
+ << "\n First frame:" << m_firstFrameToSink
+ << "\n Delay (frame+buffer-written):" << currentFrameDelay << "+"
+ << bufferLoadingTime << "-"
+ << writtenTime << "="
+ << soundDelay
+ << "\n Fixed delay:" << fixedDelay
+ << "\n Target delay:" << targetSoundDelay
+ << "\n Buffer durations (min/max/limit):" << m_timings.minSoundDelay
+ << m_timings.maxSoundDelay
+ << m_timings.actualBufferDuration
+ << "\n Audio sink state:" << stamp.audioSinkState;
+ // clang-format on
+ }
+ };
+
+ const auto loadingType = soundDelay > m_timings.maxSoundDelay ? BufferLoadingInfo::High
+ : soundDelay < m_timings.minSoundDelay ? BufferLoadingInfo::Low
+ : BufferLoadingInfo::Moderate;
+
+ if (loadingType != m_bufferLoadingInfo.type) {
+ // qCDebug(qLcAudioRenderer) << "Change buffer loading type:" <<
+ // m_bufferLoadingInfo.type
+ // << "->" << loadingType << "soundDelay:" << soundDelay;
+ m_bufferLoadingInfo = { loadingType, stamp.timePoint, soundDelay };
+ }
+
+ if (loadingType != BufferLoadingInfo::Moderate) {
+ const auto isHigh = loadingType == BufferLoadingInfo::High;
+ const auto shouldHandleIdle = stamp.audioSinkState == QAudio::IdleState && !isHigh;
+
+ auto &fixedDelay = m_bufferLoadingInfo.delay;
+
+ fixedDelay = shouldHandleIdle ? soundDelay
+ : isHigh ? qMin(soundDelay, fixedDelay)
+ : qMax(soundDelay, fixedDelay);
+
+ if (stamp.timePoint - m_bufferLoadingInfo.timePoint > BufferLoadingMeasureTime
+ || (m_firstFrameToSink && isHigh) || shouldHandleIdle) {
+ const auto targetDelay = isHigh
+ ? (m_timings.maxSoundDelay + m_timings.minSoundDelay) / 2
+ : m_timings.minSoundDelay + DurationBias;
+
+ synchronize(fixedDelay, targetDelay);
+ m_bufferLoadingInfo = { BufferLoadingInfo::Moderate, stamp.timePoint, targetDelay };
+ }
+ }
+}
+
+microseconds AudioRenderer::bufferLoadingTime(const SynchronizationStamp &syncStamp) const
+{
+ Q_ASSERT(m_sink);
+
+ if (syncStamp.audioSinkState == QAudio::IdleState)
+ return microseconds(0);
+
+ const auto bytes = qMax(m_sink->bufferSize() - syncStamp.audioSinkBytesFree, 0);
+
+#ifdef Q_OS_ANDROID
+ // The hack has been added due to QAndroidAudioSink issues (QTBUG-118609).
+ // The method QAndroidAudioSink::bytesFree returns 0 or bufferSize, intermediate values are not
+ // available now; to be fixed.
+ if (bytes == 0)
+ return m_timings.minSoundDelay + MinDesiredBufferTime;
+#endif
+
+ return durationForBytes(bytes);
+}
+
+void AudioRenderer::onAudioSinkStateChanged(QAudio::State state)
+{
+ if (state == QAudio::IdleState && !m_firstFrameToSink)
+ scheduleNextStep();
+}
+
+microseconds AudioRenderer::durationForBytes(qsizetype bytes) const
+{
+ return microseconds(m_sinkFormat.durationForBytes(static_cast<qint32>(bytes)));
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegaudiorenderer_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer_p.h
new file mode 100644
index 000000000..9a22a8a48
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer_p.h
@@ -0,0 +1,132 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGAUDIORENDERER_P_H
+#define QFFMPEGAUDIORENDERER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "playbackengine/qffmpegrenderer_p.h"
+
+#include "qaudiobuffer.h"
+
+QT_BEGIN_NAMESPACE
+
+class QAudioOutput;
+class QAudioBufferOutput;
+class QAudioSink;
+class QFFmpegResampler;
+
+namespace QFFmpeg {
+
+class AudioRenderer : public Renderer
+{
+ Q_OBJECT
+public:
+ AudioRenderer(const TimeController &tc, QAudioOutput *output, QAudioBufferOutput *bufferOutput);
+
+ void setOutput(QAudioOutput *output);
+
+ void setOutput(QAudioBufferOutput *bufferOutput);
+
+ ~AudioRenderer() override;
+
+protected:
+ using Microseconds = std::chrono::microseconds;
+ struct SynchronizationStamp
+ {
+ QAudio::State audioSinkState = QAudio::IdleState;
+ qsizetype audioSinkBytesFree = 0;
+ qsizetype bufferBytesWritten = 0;
+ TimePoint timePoint = TimePoint::max();
+ };
+
+ struct BufferLoadingInfo
+ {
+ enum Type { Low, Moderate, High };
+ Type type = Moderate;
+ TimePoint timePoint = TimePoint::max();
+ Microseconds delay = Microseconds(0);
+ };
+
+ struct AudioTimings
+ {
+ Microseconds actualBufferDuration = Microseconds(0);
+ Microseconds maxSoundDelay = Microseconds(0);
+ Microseconds minSoundDelay = Microseconds(0);
+ };
+
+ struct BufferedDataWithOffset
+ {
+ QAudioBuffer buffer;
+ qsizetype offset = 0;
+
+ bool isValid() const { return buffer.isValid(); }
+ qsizetype size() const { return buffer.byteCount() - offset; }
+ const char *data() const { return buffer.constData<char>() + offset; }
+ };
+
+ RenderingResult renderInternal(Frame frame) override;
+
+ RenderingResult pushFrameToOutput(const Frame &frame);
+
+ void pushFrameToBufferOutput(const Frame &frame);
+
+ void onPlaybackRateChanged() override;
+
+ int timerInterval() const override;
+
+ void onPauseChanged() override;
+
+ void freeOutput();
+
+ void updateOutputs(const Frame &frame);
+
+ void initResempler(const Frame &frame);
+
+ void onDeviceChanged();
+
+ void updateVolume();
+
+ void updateSynchronization(const SynchronizationStamp &stamp, const Frame &frame);
+
+ Microseconds bufferLoadingTime(const SynchronizationStamp &syncStamp) const;
+
+ void onAudioSinkStateChanged(QAudio::State state);
+
+ Microseconds durationForBytes(qsizetype bytes) const;
+
+private:
+ QPointer<QAudioOutput> m_output;
+ QPointer<QAudioBufferOutput> m_bufferOutput;
+ std::unique_ptr<QAudioSink> m_sink;
+ AudioTimings m_timings;
+ BufferLoadingInfo m_bufferLoadingInfo;
+ std::unique_ptr<QFFmpegResampler> m_resampler;
+ std::unique_ptr<QFFmpegResampler> m_bufferOutputResampler;
+ QAudioFormat m_sinkFormat;
+
+ BufferedDataWithOffset m_bufferedData;
+ QIODevice *m_ioDevice = nullptr;
+
+ bool m_lastFramePushDone = true;
+
+ bool m_deviceChanged = false;
+ bool m_bufferOutputChanged = false;
+ bool m_drained = false;
+ bool m_firstFrameToSink = true;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGAUDIORENDERER_P_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegcodec.cpp b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegcodec.cpp
new file mode 100644
index 000000000..457b3603d
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegcodec.cpp
@@ -0,0 +1,82 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "playbackengine/qffmpegcodec_p.h"
+#include "qloggingcategory.h"
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcPlaybackEngineCodec, "qt.multimedia.playbackengine.codec");
+
+namespace QFFmpeg {
+
+Codec::Data::Data(AVCodecContextUPtr context, AVStream *stream, AVFormatContext *formatContext,
+ std::unique_ptr<QFFmpeg::HWAccel> hwAccel)
+ : context(std::move(context)), stream(stream), hwAccel(std::move(hwAccel))
+{
+ if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
+ pixelAspectRatio = av_guess_sample_aspect_ratio(formatContext, stream, nullptr);
+}
+
+QMaybe<Codec> Codec::create(AVStream *stream, AVFormatContext *formatContext)
+{
+ if (!stream)
+ return { "Invalid stream" };
+
+ const AVCodec *decoder = nullptr;
+ std::unique_ptr<QFFmpeg::HWAccel> hwAccel;
+
+ if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
+ std::tie(decoder, hwAccel) = HWAccel::findDecoderWithHwAccel(stream->codecpar->codec_id);
+
+ if (!decoder)
+ decoder = QFFmpeg::findAVDecoder(stream->codecpar->codec_id);
+
+ if (!decoder)
+ return { "Failed to find a valid FFmpeg decoder" };
+
+ qCDebug(qLcPlaybackEngineCodec) << "found decoder" << decoder->name << "for id" << decoder->id;
+
+ AVCodecContextUPtr context(avcodec_alloc_context3(decoder));
+ if (!context)
+ return { "Failed to allocate a FFmpeg codec context" };
+
+ if (hwAccel)
+ context->hw_device_ctx = av_buffer_ref(hwAccel->hwDeviceContextAsBuffer());
+
+ if (context->codec_type != AVMEDIA_TYPE_AUDIO && context->codec_type != AVMEDIA_TYPE_VIDEO
+ && context->codec_type != AVMEDIA_TYPE_SUBTITLE) {
+ return { "Unknown codec type" };
+ }
+
+ int ret = avcodec_parameters_to_context(context.get(), stream->codecpar);
+ if (ret < 0)
+ return { "Failed to set FFmpeg codec parameters" };
+
+ // ### This still gives errors about wrong HW formats (as we accept all of them)
+ // But it would be good to get so we can filter out pixel format we don't support natively
+ context->get_format = QFFmpeg::getFormat;
+
+ /* Init the decoder, with reference counting and threading */
+ AVDictionaryHolder opts;
+ av_dict_set(opts, "refcounted_frames", "1", 0);
+ av_dict_set(opts, "threads", "auto", 0);
+ applyExperimentalCodecOptions(decoder, opts);
+
+ ret = avcodec_open2(context.get(), decoder, opts);
+ if (ret < 0)
+ return QString("Failed to open FFmpeg codec context " + err2str(ret));
+
+ return Codec(new Data(std::move(context), stream, formatContext, std::move(hwAccel)));
+}
+
+AVRational Codec::pixelAspectRatio(AVFrame *frame) const
+{
+ // does the same as av_guess_sample_aspect_ratio, but more efficient
+ return d->pixelAspectRatio.num && d->pixelAspectRatio.den ? d->pixelAspectRatio
+ : frame->sample_aspect_ratio;
+}
+
+QT_END_NAMESPACE
+
+} // namespace QFFmpeg
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegcodec_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegcodec_p.h
new file mode 100644
index 000000000..449fb1f65
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegcodec_p.h
@@ -0,0 +1,62 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGCODEC_P_H
+#define QFFMPEGCODEC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qshareddata.h"
+#include "qqueue.h"
+#include "private/qmultimediautils_p.h"
+#include "qffmpeg_p.h"
+#include "qffmpeghwaccel_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+class Codec
+{
+ struct Data
+ {
+ Data(AVCodecContextUPtr context, AVStream *stream, AVFormatContext *formatContext,
+ std::unique_ptr<QFFmpeg::HWAccel> hwAccel);
+ QAtomicInt ref;
+ AVCodecContextUPtr context;
+ AVStream *stream = nullptr;
+ AVRational pixelAspectRatio = { 0, 1 };
+ std::unique_ptr<QFFmpeg::HWAccel> hwAccel;
+ };
+
+public:
+ static QMaybe<Codec> create(AVStream *stream, AVFormatContext *formatContext);
+
+ AVRational pixelAspectRatio(AVFrame *frame) const;
+
+ AVCodecContext *context() const { return d->context.get(); }
+ AVStream *stream() const { return d->stream; }
+ uint streamIndex() const { return d->stream->index; }
+ HWAccel *hwAccel() const { return d->hwAccel.get(); }
+ qint64 toMs(qint64 ts) const { return timeStampMs(ts, d->stream->time_base).value_or(0); }
+ qint64 toUs(qint64 ts) const { return timeStampUs(ts, d->stream->time_base).value_or(0); }
+
+private:
+ Codec(Data *data) : d(data) { }
+ QExplicitlySharedDataPointer<Data> d;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGCODEC_P_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegdemuxer.cpp b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegdemuxer.cpp
new file mode 100644
index 000000000..8cced835c
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegdemuxer.cpp
@@ -0,0 +1,228 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "playbackengine/qffmpegdemuxer_p.h"
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+// 4 sec for buffering. TODO: maybe move to env var customization
+static constexpr qint64 MaxBufferedDurationUs = 4'000'000;
+
+// around 4 sec of hdr video
+static constexpr qint64 MaxBufferedSize = 32 * 1024 * 1024;
+
+namespace QFFmpeg {
+
+static Q_LOGGING_CATEGORY(qLcDemuxer, "qt.multimedia.ffmpeg.demuxer");
+
+static qint64 streamTimeToUs(const AVStream *stream, qint64 time)
+{
+ Q_ASSERT(stream);
+
+ const auto res = mul(time * 1000000, stream->time_base);
+ return res ? *res : time;
+}
+
+static qint64 packetEndPos(const AVStream *stream, const Packet &packet)
+{
+ return packet.loopOffset().pos
+ + streamTimeToUs(stream, packet.avPacket()->pts + packet.avPacket()->duration);
+}
+
+Demuxer::Demuxer(AVFormatContext *context, const PositionWithOffset &posWithOffset,
+ const StreamIndexes &streamIndexes, int loops)
+ : m_context(context), m_posWithOffset(posWithOffset), m_loops(loops)
+{
+ qCDebug(qLcDemuxer) << "Create demuxer."
+ << "pos:" << posWithOffset.pos << "loop offset:" << posWithOffset.offset.pos
+ << "loop index:" << posWithOffset.offset.index << "loops:" << loops;
+
+ Q_ASSERT(m_context);
+
+ for (auto i = 0; i < QPlatformMediaPlayer::NTrackTypes; ++i) {
+ if (streamIndexes[i] >= 0) {
+ const auto trackType = static_cast<QPlatformMediaPlayer::TrackType>(i);
+ qCDebug(qLcDemuxer) << "Activate demuxing stream" << i << ", trackType:" << trackType;
+ m_streams[streamIndexes[i]] = { trackType };
+ }
+ }
+}
+
+void Demuxer::doNextStep()
+{
+ ensureSeeked();
+
+ Packet packet(m_posWithOffset.offset, AVPacketUPtr{ av_packet_alloc() }, id());
+ if (av_read_frame(m_context, packet.avPacket()) < 0) {
+ ++m_posWithOffset.offset.index;
+
+ const auto loops = m_loops.loadAcquire();
+ if (loops >= 0 && m_posWithOffset.offset.index >= loops) {
+ qCDebug(qLcDemuxer) << "finish demuxing";
+
+ if (!std::exchange(m_buffered, true))
+ emit packetsBuffered();
+
+ setAtEnd(true);
+ } else {
+ m_seeked = false;
+ m_posWithOffset.pos = 0;
+ m_posWithOffset.offset.pos = m_maxPacketsEndPos;
+ m_maxPacketsEndPos = 0;
+
+ ensureSeeked();
+
+ qCDebug(qLcDemuxer) << "Demuxer loops changed. Index:" << m_posWithOffset.offset.index
+ << "Offset:" << m_posWithOffset.offset.pos;
+
+ scheduleNextStep(false);
+ }
+
+ return;
+ }
+
+ auto &avPacket = *packet.avPacket();
+
+ const auto streamIndex = avPacket.stream_index;
+ const auto stream = m_context->streams[streamIndex];
+
+ auto it = m_streams.find(streamIndex);
+ if (it != m_streams.end()) {
+ auto &streamData = it->second;
+
+ const auto endPos = packetEndPos(stream, packet);
+ m_maxPacketsEndPos = qMax(m_maxPacketsEndPos, endPos);
+
+ // Increase buffered metrics as the packet has been processed.
+
+ streamData.bufferedDuration += streamTimeToUs(stream, avPacket.duration);
+ streamData.bufferedSize += avPacket.size;
+ streamData.maxSentPacketsPos = qMax(streamData.maxSentPacketsPos, endPos);
+ updateStreamDataLimitFlag(streamData);
+
+ if (!m_buffered && streamData.isDataLimitReached) {
+ m_buffered = true;
+ emit packetsBuffered();
+ }
+
+ if (!m_firstPacketFound) {
+ m_firstPacketFound = true;
+ const auto pos = streamTimeToUs(stream, avPacket.pts);
+ emit firstPacketFound(std::chrono::steady_clock::now(), pos);
+ }
+
+ auto signal = signalByTrackType(it->second.trackType);
+ emit (this->*signal)(packet);
+ }
+
+ scheduleNextStep(false);
+}
+
+void Demuxer::onPacketProcessed(Packet packet)
+{
+ Q_ASSERT(packet.isValid());
+
+ if (packet.sourceId() != id())
+ return;
+
+ auto &avPacket = *packet.avPacket();
+
+ const auto streamIndex = avPacket.stream_index;
+ const auto stream = m_context->streams[streamIndex];
+ auto it = m_streams.find(streamIndex);
+
+ if (it != m_streams.end()) {
+ auto &streamData = it->second;
+
+ // Decrease buffered metrics as new data (the packet) has been received (buffered)
+
+ streamData.bufferedDuration -= streamTimeToUs(stream, avPacket.duration);
+ streamData.bufferedSize -= avPacket.size;
+ streamData.maxProcessedPacketPos =
+ qMax(streamData.maxProcessedPacketPos, packetEndPos(stream, packet));
+
+ Q_ASSERT(it->second.bufferedDuration >= 0);
+ Q_ASSERT(it->second.bufferedSize >= 0);
+
+ updateStreamDataLimitFlag(streamData);
+ }
+
+ scheduleNextStep();
+}
+
+bool Demuxer::canDoNextStep() const
+{
+ auto isDataLimitReached = [](const auto &streamIndexToData) {
+ return streamIndexToData.second.isDataLimitReached;
+ };
+
+ // Demuxer waits:
+ // - if it's paused
+ // - if the end has been reached
+ // - if streams are empty (probably, should be handled on the initialization)
+ // - if at least one of the streams has reached the data limit (duration or size)
+
+ return PlaybackEngineObject::canDoNextStep() && !isAtEnd() && !m_streams.empty()
+ && std::none_of(m_streams.begin(), m_streams.end(), isDataLimitReached);
+}
+
+void Demuxer::ensureSeeked()
+{
+ if (std::exchange(m_seeked, true))
+ return;
+
+ if ((m_context->ctx_flags & AVFMTCTX_UNSEEKABLE) == 0) {
+ const qint64 seekPos = m_posWithOffset.pos * AV_TIME_BASE / 1000000;
+ auto err = av_seek_frame(m_context, -1, seekPos, AVSEEK_FLAG_BACKWARD);
+
+ if (err < 0) {
+ qCWarning(qLcDemuxer) << "Failed to seek, pos" << seekPos;
+
+ // Drop an error of seeking to initial position of streams with undefined duration.
+ // This needs improvements.
+ if (seekPos != 0 || m_context->duration > 0)
+ emit error(QMediaPlayer::ResourceError,
+ QLatin1StringView("Failed to seek: ") + err2str(err));
+ }
+ }
+
+ setAtEnd(false);
+}
+
+Demuxer::RequestingSignal Demuxer::signalByTrackType(QPlatformMediaPlayer::TrackType trackType)
+{
+ switch (trackType) {
+ case QPlatformMediaPlayer::TrackType::VideoStream:
+ return &Demuxer::requestProcessVideoPacket;
+ case QPlatformMediaPlayer::TrackType::AudioStream:
+ return &Demuxer::requestProcessAudioPacket;
+ case QPlatformMediaPlayer::TrackType::SubtitleStream:
+ return &Demuxer::requestProcessSubtitlePacket;
+ default:
+ Q_ASSERT(!"Unknown track type");
+ }
+
+ return nullptr;
+}
+
+void Demuxer::setLoops(int loopsCount)
+{
+ qCDebug(qLcDemuxer) << "setLoops to demuxer" << loopsCount;
+ m_loops.storeRelease(loopsCount);
+}
+
+void Demuxer::updateStreamDataLimitFlag(StreamData &streamData)
+{
+ const auto packetsPosDiff = streamData.maxSentPacketsPos - streamData.maxProcessedPacketPos;
+ streamData.isDataLimitReached =
+ streamData.bufferedDuration >= MaxBufferedDurationUs
+ || (streamData.bufferedDuration == 0 && packetsPosDiff >= MaxBufferedDurationUs)
+ || streamData.bufferedSize >= MaxBufferedSize;
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegdemuxer_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegdemuxer_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegdemuxer_p.h
new file mode 100644
index 000000000..b72056185
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegdemuxer_p.h
@@ -0,0 +1,87 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGDEMUXER_P_H
+#define QFFMPEGDEMUXER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "playbackengine/qffmpegplaybackengineobject_p.h"
+#include "private/qplatformmediaplayer_p.h"
+#include "playbackengine/qffmpegpacket_p.h"
+#include "playbackengine/qffmpegpositionwithoffset_p.h"
+
+#include <unordered_map>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+class Demuxer : public PlaybackEngineObject
+{
+ Q_OBJECT
+public:
+ Demuxer(AVFormatContext *context, const PositionWithOffset &posWithOffset,
+ const StreamIndexes &streamIndexes, int loops);
+
+ using RequestingSignal = void (Demuxer::*)(Packet);
+ static RequestingSignal signalByTrackType(QPlatformMediaPlayer::TrackType trackType);
+
+ void setLoops(int loopsCount);
+
+public slots:
+ void onPacketProcessed(Packet);
+
+signals:
+ void requestProcessAudioPacket(Packet);
+ void requestProcessVideoPacket(Packet);
+ void requestProcessSubtitlePacket(Packet);
+ void firstPacketFound(TimePoint tp, qint64 trackPos);
+ void packetsBuffered();
+
+private:
+ bool canDoNextStep() const override;
+
+ void doNextStep() override;
+
+ void ensureSeeked();
+
+private:
+ struct StreamData
+ {
+ QPlatformMediaPlayer::TrackType trackType = QPlatformMediaPlayer::TrackType::NTrackTypes;
+ qint64 bufferedDuration = 0;
+ qint64 bufferedSize = 0;
+
+ qint64 maxSentPacketsPos = 0;
+ qint64 maxProcessedPacketPos = 0;
+
+ bool isDataLimitReached = false;
+ };
+
+ void updateStreamDataLimitFlag(StreamData &streamData);
+
+private:
+ AVFormatContext *m_context = nullptr;
+ bool m_seeked = false;
+ bool m_firstPacketFound = false;
+ std::unordered_map<int, StreamData> m_streams;
+ PositionWithOffset m_posWithOffset;
+ qint64 m_maxPacketsEndPos = 0;
+ QAtomicInt m_loops = QMediaPlayer::Once;
+ bool m_buffered = false;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE // QFFMPEGDEMUXER_P_H
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegframe_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegframe_p.h
new file mode 100644
index 000000000..84fe2fead
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegframe_p.h
@@ -0,0 +1,109 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGFRAME_P_H
+#define QFFMPEGFRAME_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpeg_p.h"
+#include "playbackengine/qffmpegcodec_p.h"
+#include "playbackengine/qffmpegpositionwithoffset_p.h"
+#include "QtCore/qsharedpointer.h"
+#include "qpointer.h"
+#include "qobject.h"
+
+#include <optional>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+struct Frame
+{
+ struct Data
+ {
+ Data(const LoopOffset &offset, AVFrameUPtr f, const Codec &codec, qint64, quint64 sourceId)
+ : loopOffset(offset), codec(codec), frame(std::move(f)), sourceId(sourceId)
+ {
+ Q_ASSERT(frame);
+ if (frame->pts != AV_NOPTS_VALUE)
+ pts = codec.toUs(frame->pts);
+ else
+ pts = codec.toUs(frame->best_effort_timestamp);
+
+ if (auto frameDuration = getAVFrameDuration(*frame)) {
+ duration = codec.toUs(frameDuration);
+ } else {
+ const auto &avgFrameRate = codec.stream()->avg_frame_rate;
+ duration = mul(qint64(1000000), { avgFrameRate.den, avgFrameRate.num }).value_or(0);
+ }
+ }
+ Data(const LoopOffset &offset, const QString &text, qint64 pts, qint64 duration,
+ quint64 sourceId)
+ : loopOffset(offset), text(text), pts(pts), duration(duration), sourceId(sourceId)
+ {
+ }
+
+ QAtomicInt ref;
+ LoopOffset loopOffset;
+ std::optional<Codec> codec;
+ AVFrameUPtr frame;
+ QString text;
+ qint64 pts = -1;
+ qint64 duration = -1;
+ quint64 sourceId = 0;
+ };
+ Frame() = default;
+
+ Frame(const LoopOffset &offset, AVFrameUPtr f, const Codec &codec, qint64 pts,
+ quint64 sourceIndex)
+ : d(new Data(offset, std::move(f), codec, pts, sourceIndex))
+ {
+ }
+ Frame(const LoopOffset &offset, const QString &text, qint64 pts, qint64 duration,
+ quint64 sourceIndex)
+ : d(new Data(offset, text, pts, duration, sourceIndex))
+ {
+ }
+ bool isValid() const { return !!d; }
+
+ AVFrame *avFrame() const { return data().frame.get(); }
+ AVFrameUPtr takeAVFrame() { return std::move(data().frame); }
+ const Codec *codec() const { return data().codec ? &data().codec.value() : nullptr; }
+ qint64 pts() const { return data().pts; }
+ qint64 duration() const { return data().duration; }
+ qint64 end() const { return data().pts + data().duration; }
+ QString text() const { return data().text; }
+ quint64 sourceId() const { return data().sourceId; };
+ const LoopOffset &loopOffset() const { return data().loopOffset; };
+ qint64 absolutePts() const { return pts() + loopOffset().pos; }
+ qint64 absoluteEnd() const { return end() + loopOffset().pos; }
+
+private:
+ Data &data() const
+ {
+ Q_ASSERT(d);
+ return *d;
+ }
+
+private:
+ QExplicitlySharedDataPointer<Data> d;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QFFmpeg::Frame);
+
+#endif // QFFMPEGFRAME_P_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegmediadataholder.cpp b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegmediadataholder.cpp
new file mode 100644
index 000000000..f92f93ddb
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegmediadataholder.cpp
@@ -0,0 +1,390 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "playbackengine/qffmpegmediadataholder_p.h"
+
+#include "qffmpegmediametadata_p.h"
+#include "qffmpegmediaformatinfo_p.h"
+#include "qffmpegioutils_p.h"
+#include "qiodevice.h"
+#include "qdatetime.h"
+#include "qloggingcategory.h"
+
+#include <math.h>
+#include <optional>
+
+extern "C" {
+#include "libavutil/display.h"
+}
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcMediaDataHolder, "qt.multimedia.ffmpeg.mediadataholder")
+
+namespace QFFmpeg {
+
+static std::optional<qint64> streamDuration(const AVStream &stream)
+{
+ const auto &factor = stream.time_base;
+
+ if (stream.duration > 0 && factor.num > 0 && factor.den > 0) {
+ return qint64(1000000) * stream.duration * factor.num / factor.den;
+ }
+
+ // In some cases ffmpeg reports negative duration that is definitely invalid.
+ // However, the correct duration may be read from the metadata.
+
+ if (stream.duration < 0) {
+ qCWarning(qLcMediaDataHolder) << "AVStream duration" << stream.duration
+ << "is invalid. Taking it from the metadata";
+ }
+
+ if (const auto duration = av_dict_get(stream.metadata, "DURATION", nullptr, 0)) {
+ const auto time = QTime::fromString(QString::fromUtf8(duration->value));
+ return qint64(1000) * time.msecsSinceStartOfDay();
+ }
+
+ return {};
+}
+
+static int streamOrientation(const AVStream *stream)
+{
+ Q_ASSERT(stream);
+
+ using SideDataSize = decltype(AVPacketSideData::size);
+ constexpr SideDataSize displayMatrixSize = sizeof(int32_t) * 9;
+ const auto *sideData = streamSideData(stream, AV_PKT_DATA_DISPLAYMATRIX);
+ if (!sideData || sideData->size < displayMatrixSize)
+ return 0;
+
+ auto displayMatrix = reinterpret_cast<const int32_t *>(sideData->data);
+ auto rotation = static_cast<int>(std::round(av_display_rotation_get(displayMatrix)));
+ // Convert counterclockwise rotation angle to clockwise, restricted to 0, 90, 180 and 270
+ if (rotation % 90 != 0)
+ return 0;
+ return rotation < 0 ? -rotation % 360 : -rotation % 360 + 360;
+}
+
+
+static bool colorTransferSupportsHdr(const AVStream *stream)
+{
+ if (!stream)
+ return false;
+
+ const AVCodecParameters *codecPar = stream->codecpar;
+ if (!codecPar)
+ return false;
+
+ const QVideoFrameFormat::ColorTransfer colorTransfer = fromAvColorTransfer(codecPar->color_trc);
+
+ // Assume that content is using HDR if the color transfer supports high
+ // dynamic range. The video may still not utilize the extended range,
+ // but we can't determine the actual range without decoding frames.
+ return colorTransfer == QVideoFrameFormat::ColorTransfer_ST2084
+ || colorTransfer == QVideoFrameFormat::ColorTransfer_STD_B67;
+}
+
+QtVideo::Rotation MediaDataHolder::rotation() const
+{
+ int orientation = m_metaData.value(QMediaMetaData::Orientation).toInt();
+ return static_cast<QtVideo::Rotation>(orientation);
+}
+
+AVFormatContext *MediaDataHolder::avContext()
+{
+ return m_context.get();
+}
+
+int MediaDataHolder::currentStreamIndex(QPlatformMediaPlayer::TrackType trackType) const
+{
+ return m_currentAVStreamIndex[trackType];
+}
+
+static void insertMediaData(QMediaMetaData &metaData, QPlatformMediaPlayer::TrackType trackType,
+ const AVStream *stream)
+{
+ Q_ASSERT(stream);
+ const auto *codecPar = stream->codecpar;
+
+ switch (trackType) {
+ case QPlatformMediaPlayer::VideoStream:
+ metaData.insert(QMediaMetaData::VideoBitRate, (int)codecPar->bit_rate);
+ metaData.insert(QMediaMetaData::VideoCodec,
+ QVariant::fromValue(QFFmpegMediaFormatInfo::videoCodecForAVCodecId(
+ codecPar->codec_id)));
+ metaData.insert(QMediaMetaData::Resolution, QSize(codecPar->width, codecPar->height));
+ metaData.insert(QMediaMetaData::VideoFrameRate,
+ qreal(stream->avg_frame_rate.num) / qreal(stream->avg_frame_rate.den));
+ metaData.insert(QMediaMetaData::Orientation, QVariant::fromValue(streamOrientation(stream)));
+ metaData.insert(QMediaMetaData::HasHdrContent, colorTransferSupportsHdr(stream));
+ break;
+ case QPlatformMediaPlayer::AudioStream:
+ metaData.insert(QMediaMetaData::AudioBitRate, (int)codecPar->bit_rate);
+ metaData.insert(QMediaMetaData::AudioCodec,
+ QVariant::fromValue(QFFmpegMediaFormatInfo::audioCodecForAVCodecId(
+ codecPar->codec_id)));
+ break;
+ default:
+ break;
+ }
+};
+
+QPlatformMediaPlayer::TrackType MediaDataHolder::trackTypeFromMediaType(int mediaType)
+{
+ switch (mediaType) {
+ case AVMEDIA_TYPE_AUDIO:
+ return QPlatformMediaPlayer::AudioStream;
+ case AVMEDIA_TYPE_VIDEO:
+ return QPlatformMediaPlayer::VideoStream;
+ case AVMEDIA_TYPE_SUBTITLE:
+ return QPlatformMediaPlayer::SubtitleStream;
+ default:
+ return QPlatformMediaPlayer::NTrackTypes;
+ }
+}
+
+namespace {
+QMaybe<AVFormatContextUPtr, MediaDataHolder::ContextError>
+loadMedia(const QUrl &mediaUrl, QIODevice *stream, const std::shared_ptr<ICancelToken> &cancelToken)
+{
+ const QByteArray url = mediaUrl.toString(QUrl::PreferLocalFile).toUtf8();
+
+ AVFormatContextUPtr context{ avformat_alloc_context() };
+
+ if (stream) {
+ if (!stream->isOpen()) {
+ if (!stream->open(QIODevice::ReadOnly))
+ return MediaDataHolder::ContextError{
+ QMediaPlayer::ResourceError, QLatin1String("Could not open source device.")
+ };
+ }
+ if (!stream->isSequential())
+ stream->seek(0);
+
+ constexpr int bufferSize = 32768;
+ unsigned char *buffer = (unsigned char *)av_malloc(bufferSize);
+ context->pb = avio_alloc_context(buffer, bufferSize, false, stream, &readQIODevice, nullptr,
+ &seekQIODevice);
+ }
+
+ AVDictionaryHolder dict;
+ constexpr auto NetworkTimeoutUs = "5000000";
+ av_dict_set(dict, "timeout", NetworkTimeoutUs, 0);
+
+ const QByteArray protocolWhitelist = qgetenv("QT_FFMPEG_PROTOCOL_WHITELIST");
+ if (!protocolWhitelist.isNull())
+ av_dict_set(dict, "protocol_whitelist", protocolWhitelist.data(), 0);
+
+ context->interrupt_callback.opaque = cancelToken.get();
+ context->interrupt_callback.callback = [](void *opaque) {
+ const auto *cancelToken = static_cast<const ICancelToken *>(opaque);
+ if (cancelToken && cancelToken->isCancelled())
+ return 1;
+ return 0;
+ };
+
+ int ret = 0;
+ {
+ AVFormatContext *contextRaw = context.release();
+ ret = avformat_open_input(&contextRaw, url.constData(), nullptr, dict);
+ context.reset(contextRaw);
+ }
+
+ if (ret < 0) {
+ auto code = QMediaPlayer::ResourceError;
+ if (ret == AVERROR(EACCES))
+ code = QMediaPlayer::AccessDeniedError;
+ else if (ret == AVERROR(EINVAL))
+ code = QMediaPlayer::FormatError;
+
+ return MediaDataHolder::ContextError{ code, QMediaPlayer::tr("Could not open file") };
+ }
+
+ ret = avformat_find_stream_info(context.get(), nullptr);
+ if (ret < 0) {
+ return MediaDataHolder::ContextError{
+ QMediaPlayer::FormatError,
+ QMediaPlayer::tr("Could not find stream information for media file")
+ };
+ }
+
+#ifndef QT_NO_DEBUG
+ av_dump_format(context.get(), 0, url.constData(), 0);
+#endif
+ return context;
+}
+
+} // namespace
+
+MediaDataHolder::Maybe MediaDataHolder::create(const QUrl &url, QIODevice *stream,
+ const std::shared_ptr<ICancelToken> &cancelToken)
+{
+ QMaybe context = loadMedia(url, stream, cancelToken);
+ if (context) {
+ // MediaDataHolder is wrapped in a shared pointer to interop with signal/slot mechanism
+ return QSharedPointer<MediaDataHolder>{ new MediaDataHolder{ std::move(context.value()), cancelToken } };
+ }
+ return context.error();
+}
+
+MediaDataHolder::MediaDataHolder(AVFormatContextUPtr context,
+ const std::shared_ptr<ICancelToken> &cancelToken)
+ : m_cancelToken{ cancelToken }
+{
+ Q_ASSERT(context);
+
+ m_context = std::move(context);
+ m_isSeekable = !(m_context->ctx_flags & AVFMTCTX_UNSEEKABLE);
+
+ for (unsigned int i = 0; i < m_context->nb_streams; ++i) {
+
+ const auto *stream = m_context->streams[i];
+ const auto trackType = trackTypeFromMediaType(stream->codecpar->codec_type);
+
+ if (trackType == QPlatformMediaPlayer::NTrackTypes)
+ continue;
+
+ if (stream->disposition & AV_DISPOSITION_ATTACHED_PIC)
+ continue; // Ignore attached picture streams because we treat them as metadata
+
+ auto metaData = QFFmpegMetaData::fromAVMetaData(stream->metadata);
+ const bool isDefault = stream->disposition & AV_DISPOSITION_DEFAULT;
+
+ if (trackType != QPlatformMediaPlayer::SubtitleStream) {
+ insertMediaData(metaData, trackType, stream);
+
+ if (isDefault && m_requestedStreams[trackType] < 0)
+ m_requestedStreams[trackType] = m_streamMap[trackType].size();
+ }
+
+ if (auto duration = streamDuration(*stream)) {
+ m_duration = qMax(m_duration, *duration);
+ metaData.insert(QMediaMetaData::Duration, *duration / qint64(1000));
+ }
+
+ m_streamMap[trackType].append({ (int)i, isDefault, metaData });
+ }
+
+ // With some media files, streams may be lacking duration info. Let's
+ // get it from ffmpeg's duration estimation instead.
+ if (m_duration == 0 && m_context->duration > 0ll) {
+ m_duration = m_context->duration;
+ }
+
+ for (auto trackType :
+ { QPlatformMediaPlayer::VideoStream, QPlatformMediaPlayer::AudioStream }) {
+ auto &requestedStream = m_requestedStreams[trackType];
+ auto &streamMap = m_streamMap[trackType];
+
+ if (requestedStream < 0 && !streamMap.empty())
+ requestedStream = 0;
+
+ if (requestedStream >= 0)
+ m_currentAVStreamIndex[trackType] = streamMap[requestedStream].avStreamIndex;
+ }
+
+ updateMetaData();
+}
+
+namespace {
+
+/*!
+ \internal
+
+ Attempt to find an attached picture from the context's streams.
+ This will find ID3v2 pictures on audio files, and also pictures
+ attached to videos.
+ */
+QImage getAttachedPicture(const AVFormatContext *context)
+{
+ if (!context)
+ return {};
+
+ for (unsigned int i = 0; i < context->nb_streams; ++i) {
+ const AVStream* stream = context->streams[i];
+ if (!stream || !(stream->disposition & AV_DISPOSITION_ATTACHED_PIC))
+ continue;
+
+ const AVPacket *compressedImage = &stream->attached_pic;
+ if (!compressedImage || !compressedImage->data || compressedImage->size <= 0)
+ continue;
+
+ // Feed raw compressed data to QImage::fromData, which will decompress it
+ // if it is a recognized format.
+ QImage image = QImage::fromData({ compressedImage->data, compressedImage->size });
+ if (!image.isNull())
+ return image;
+ }
+
+ return {};
+}
+
+}
+
+void MediaDataHolder::updateMetaData()
+{
+ m_metaData = {};
+
+ if (!m_context)
+ return;
+
+ m_metaData = QFFmpegMetaData::fromAVMetaData(m_context->metadata);
+ m_metaData.insert(QMediaMetaData::FileFormat,
+ QVariant::fromValue(QFFmpegMediaFormatInfo::fileFormatForAVInputFormat(
+ m_context->iformat)));
+ m_metaData.insert(QMediaMetaData::Duration, m_duration / qint64(1000));
+
+ if (!m_cachedThumbnail.has_value())
+ m_cachedThumbnail = getAttachedPicture(m_context.get());
+
+ if (!m_cachedThumbnail->isNull())
+ m_metaData.insert(QMediaMetaData::ThumbnailImage, m_cachedThumbnail.value());
+
+ for (auto trackType :
+ { QPlatformMediaPlayer::AudioStream, QPlatformMediaPlayer::VideoStream }) {
+ const auto streamIndex = m_currentAVStreamIndex[trackType];
+ if (streamIndex >= 0)
+ insertMediaData(m_metaData, trackType, m_context->streams[streamIndex]);
+ }
+}
+
+bool MediaDataHolder::setActiveTrack(QPlatformMediaPlayer::TrackType type, int streamNumber)
+{
+ if (!m_context)
+ return false;
+
+ if (streamNumber < 0 || streamNumber >= m_streamMap[type].size())
+ streamNumber = -1;
+ if (m_requestedStreams[type] == streamNumber)
+ return false;
+ m_requestedStreams[type] = streamNumber;
+ const int avStreamIndex = m_streamMap[type].value(streamNumber).avStreamIndex;
+
+ const int oldIndex = m_currentAVStreamIndex[type];
+ qCDebug(qLcMediaDataHolder) << ">>>>> change track" << type << "from" << oldIndex << "to"
+ << avStreamIndex;
+
+ // TODO: maybe add additional verifications
+ m_currentAVStreamIndex[type] = avStreamIndex;
+
+ updateMetaData();
+
+ return true;
+}
+
+int MediaDataHolder::activeTrack(QPlatformMediaPlayer::TrackType type) const
+{
+ return type < QPlatformMediaPlayer::NTrackTypes ? m_requestedStreams[type] : -1;
+}
+
+const QList<MediaDataHolder::StreamInfo> &MediaDataHolder::streamInfo(
+ QPlatformMediaPlayer::TrackType trackType) const
+{
+ Q_ASSERT(trackType < QPlatformMediaPlayer::NTrackTypes);
+
+ return m_streamMap[trackType];
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegmediadataholder_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegmediadataholder_p.h
new file mode 100644
index 000000000..a55b0766a
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegmediadataholder_p.h
@@ -0,0 +1,107 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGMEDIADATAHOLDER_P_H
+#define QFFMPEGMEDIADATAHOLDER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qmediametadata.h"
+#include "private/qplatformmediaplayer_p.h"
+#include "qffmpeg_p.h"
+#include "qvideoframe.h"
+#include <private/qmultimediautils_p.h>
+
+#include <array>
+#include <optional>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+struct ICancelToken
+{
+ virtual ~ICancelToken() = default;
+ virtual bool isCancelled() const = 0;
+};
+
+using AVFormatContextUPtr = std::unique_ptr<AVFormatContext, AVDeleter<decltype(&avformat_close_input), &avformat_close_input>>;
+
+class MediaDataHolder
+{
+public:
+ struct StreamInfo
+ {
+ int avStreamIndex = -1;
+ bool isDefault = false;
+ QMediaMetaData metaData;
+ };
+
+ struct ContextError
+ {
+ int code = 0;
+ QString description;
+ };
+
+ using StreamsMap = std::array<QList<StreamInfo>, QPlatformMediaPlayer::NTrackTypes>;
+ using StreamIndexes = std::array<int, QPlatformMediaPlayer::NTrackTypes>;
+
+ MediaDataHolder() = default;
+ MediaDataHolder(AVFormatContextUPtr context, const std::shared_ptr<ICancelToken> &cancelToken);
+
+ static QPlatformMediaPlayer::TrackType trackTypeFromMediaType(int mediaType);
+
+ int activeTrack(QPlatformMediaPlayer::TrackType type) const;
+
+ const QList<StreamInfo> &streamInfo(QPlatformMediaPlayer::TrackType trackType) const;
+
+ qint64 duration() const { return m_duration; }
+
+ const QMediaMetaData &metaData() const { return m_metaData; }
+
+ bool isSeekable() const { return m_isSeekable; }
+
+ QtVideo::Rotation rotation() const;
+
+ AVFormatContext *avContext();
+
+ int currentStreamIndex(QPlatformMediaPlayer::TrackType trackType) const;
+
+ using Maybe = QMaybe<QSharedPointer<MediaDataHolder>, ContextError>;
+ static Maybe create(const QUrl &url, QIODevice *stream,
+ const std::shared_ptr<ICancelToken> &cancelToken);
+
+ bool setActiveTrack(QPlatformMediaPlayer::TrackType type, int streamNumber);
+
+private:
+ void updateMetaData();
+
+ std::shared_ptr<ICancelToken> m_cancelToken; // NOTE: Cancel token may be accessed by
+ // AVFormatContext during destruction and
+ // must outlive the context object
+ AVFormatContextUPtr m_context;
+
+ bool m_isSeekable = false;
+
+ StreamIndexes m_currentAVStreamIndex = { -1, -1, -1 };
+ StreamsMap m_streamMap;
+ StreamIndexes m_requestedStreams = { -1, -1, -1 };
+ qint64 m_duration = 0;
+ QMediaMetaData m_metaData;
+ std::optional<QImage> m_cachedThumbnail;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGMEDIADATAHOLDER_P_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegpacket_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegpacket_p.h
new file mode 100644
index 000000000..5e15bf012
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegpacket_p.h
@@ -0,0 +1,61 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGPACKET_P_H
+#define QFFMPEGPACKET_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpeg_p.h"
+#include "QtCore/qsharedpointer.h"
+#include "playbackengine/qffmpegpositionwithoffset_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+struct Packet
+{
+ struct Data
+ {
+ Data(const LoopOffset &offset, AVPacketUPtr p, quint64 sourceId)
+ : loopOffset(offset), packet(std::move(p)), sourceId(sourceId)
+ {
+ }
+
+ QAtomicInt ref;
+ LoopOffset loopOffset;
+ AVPacketUPtr packet;
+ quint64 sourceId;
+ };
+ Packet() = default;
+ Packet(const LoopOffset &offset, AVPacketUPtr p, quint64 sourceId)
+ : d(new Data(offset, std::move(p), sourceId))
+ {
+ }
+
+ bool isValid() const { return !!d; }
+ AVPacket *avPacket() const { return d->packet.get(); }
+ const LoopOffset &loopOffset() const { return d->loopOffset; }
+ quint64 sourceId() const { return d->sourceId; }
+
+private:
+ QExplicitlySharedDataPointer<Data> d;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QFFmpeg::Packet)
+
+#endif // QFFMPEGPACKET_P_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackenginedefs_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackenginedefs_p.h
new file mode 100644
index 000000000..18254ef64
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackenginedefs_p.h
@@ -0,0 +1,46 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGPLAYBACKENGINEDEFS_P_H
+#define QFFMPEGPLAYBACKENGINEDEFS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+#include "qobject.h"
+#include "qpointer.h"
+
+#include <memory>
+#include <array>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+class PlaybackEngine;
+}
+
+namespace QFFmpeg {
+
+using StreamIndexes = std::array<int, 3>;
+
+class PlaybackEngineObjectsController;
+class PlaybackEngineObject;
+class Demuxer;
+class StreamDecoder;
+class Renderer;
+class SubtitleRenderer;
+class AudioRenderer;
+class VideoRenderer;
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGPLAYBACKENGINEDEFS_P_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackengineobject.cpp b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackengineobject.cpp
new file mode 100644
index 000000000..2d23802de
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackengineobject.cpp
@@ -0,0 +1,109 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "playbackengine/qffmpegplaybackengineobject_p.h"
+
+#include "qtimer.h"
+#include "qdebug.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+static QAtomicInteger<PlaybackEngineObject::Id> PersistentId = 0;
+
+PlaybackEngineObject::PlaybackEngineObject() : m_id(PersistentId.fetchAndAddRelaxed(1)) { }
+
+PlaybackEngineObject::~PlaybackEngineObject()
+{
+ if (thread() != QThread::currentThread())
+ qWarning() << "The playback engine object is being removed in an unexpected thread";
+}
+
+bool PlaybackEngineObject::isPaused() const
+{
+ return m_paused;
+}
+
+void PlaybackEngineObject::setAtEnd(bool isAtEnd)
+{
+ if (m_atEnd.testAndSetRelease(!isAtEnd, isAtEnd) && isAtEnd)
+ emit atEnd();
+}
+
+bool PlaybackEngineObject::isAtEnd() const
+{
+ return m_atEnd;
+}
+
+PlaybackEngineObject::Id PlaybackEngineObject::id() const
+{
+ return m_id;
+}
+
+void PlaybackEngineObject::setPaused(bool isPaused)
+{
+ if (m_paused.testAndSetRelease(!isPaused, isPaused))
+ QMetaObject::invokeMethod(this, &PlaybackEngineObject::onPauseChanged);
+}
+
+void PlaybackEngineObject::kill()
+{
+ m_deleting.storeRelease(true);
+
+ disconnect();
+ deleteLater();
+}
+
+bool PlaybackEngineObject::canDoNextStep() const
+{
+ return !m_paused;
+}
+
+QTimer &PlaybackEngineObject::timer()
+{
+ if (!m_timer) {
+ m_timer = std::make_unique<QTimer>();
+ m_timer->setTimerType(Qt::PreciseTimer);
+ m_timer->setSingleShot(true);
+ connect(m_timer.get(), &QTimer::timeout, this, &PlaybackEngineObject::onTimeout);
+ }
+
+ return *m_timer;
+}
+
+void PlaybackEngineObject::onTimeout()
+{
+ if (!m_deleting && canDoNextStep())
+ doNextStep();
+}
+
+int PlaybackEngineObject::timerInterval() const
+{
+ return 0;
+}
+
+void PlaybackEngineObject::onPauseChanged()
+{
+ scheduleNextStep();
+}
+
+void PlaybackEngineObject::scheduleNextStep(bool allowDoImmediatelly)
+{
+ if (!m_deleting && canDoNextStep()) {
+ const auto interval = timerInterval();
+ if (interval == 0 && allowDoImmediatelly) {
+ timer().stop();
+ doNextStep();
+ } else {
+ timer().start(interval);
+ }
+ } else {
+ timer().stop();
+ }
+}
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegplaybackengineobject_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackengineobject_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackengineobject_p.h
new file mode 100644
index 000000000..02943a55b
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackengineobject_p.h
@@ -0,0 +1,84 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGPLAYBACKENGINEOBJECT_P_H
+#define QFFMPEGPLAYBACKENGINEOBJECT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "playbackengine/qffmpegplaybackenginedefs_p.h"
+#include "qthread.h"
+#include "qatomic.h"
+
+QT_BEGIN_NAMESPACE
+
+class QTimer;
+
+namespace QFFmpeg {
+
+class PlaybackEngineObject : public QObject
+{
+ Q_OBJECT
+public:
+ using TimePoint = std::chrono::steady_clock::time_point;
+ using TimePointOpt = std::optional<TimePoint>;
+ using Id = quint64;
+
+ PlaybackEngineObject();
+
+ ~PlaybackEngineObject();
+
+ bool isPaused() const;
+
+ bool isAtEnd() const;
+
+ void kill();
+
+ void setPaused(bool isPaused);
+
+ Id id() const;
+
+signals:
+ void atEnd();
+
+ void error(int code, const QString &errorString);
+
+protected:
+ QTimer &timer();
+
+ void scheduleNextStep(bool allowDoImmediatelly = true);
+
+ virtual void onPauseChanged();
+
+ virtual bool canDoNextStep() const;
+
+ virtual int timerInterval() const;
+
+ void setAtEnd(bool isAtEnd);
+
+ virtual void doNextStep() { }
+
+private slots:
+ void onTimeout();
+
+private:
+ std::unique_ptr<QTimer> m_timer;
+
+ QAtomicInteger<bool> m_paused = true;
+ QAtomicInteger<bool> m_atEnd = false;
+ QAtomicInteger<bool> m_deleting = false;
+ const Id m_id;
+};
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGPLAYBACKENGINEOBJECT_P_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegpositionwithoffset_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegpositionwithoffset_p.h
new file mode 100644
index 000000000..a30fdc119
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegpositionwithoffset_p.h
@@ -0,0 +1,40 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef qffmpegpositionwithoffset_p_H
+#define qffmpegpositionwithoffset_p_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qtypes.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+struct LoopOffset
+{
+ qint64 pos = 0;
+ int index = 0;
+};
+
+struct PositionWithOffset
+{
+ qint64 pos = 0;
+ LoopOffset offset;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // qffmpegpositionwithoffset_p_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegrenderer.cpp b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegrenderer.cpp
new file mode 100644
index 000000000..e763c786b
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegrenderer.cpp
@@ -0,0 +1,216 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "playbackengine/qffmpegrenderer_p.h"
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+static Q_LOGGING_CATEGORY(qLcRenderer, "qt.multimedia.ffmpeg.renderer");
+
+Renderer::Renderer(const TimeController &tc, const std::chrono::microseconds &seekPosTimeOffset)
+ : m_timeController(tc),
+ m_lastFrameEnd(tc.currentPosition()),
+ m_lastPosition(m_lastFrameEnd),
+ m_seekPos(tc.currentPosition(-seekPosTimeOffset))
+{
+}
+
+void Renderer::syncSoft(TimePoint tp, qint64 trackTime)
+{
+ QMetaObject::invokeMethod(this, [this, tp, trackTime]() {
+ m_timeController.syncSoft(tp, trackTime);
+ scheduleNextStep(true);
+ });
+}
+
+qint64 Renderer::seekPosition() const
+{
+ return m_seekPos;
+}
+
+qint64 Renderer::lastPosition() const
+{
+ return m_lastPosition;
+}
+
+void Renderer::setPlaybackRate(float rate)
+{
+ QMetaObject::invokeMethod(this, [this, rate]() {
+ m_timeController.setPlaybackRate(rate);
+ onPlaybackRateChanged();
+ scheduleNextStep();
+ });
+}
+
+void Renderer::doForceStep()
+{
+ if (m_isStepForced.testAndSetOrdered(false, true))
+ QMetaObject::invokeMethod(this, [this]() {
+ // maybe set m_forceStepMaxPos
+
+ if (isAtEnd()) {
+ setForceStepDone();
+ }
+ else {
+ m_explicitNextFrameTime = Clock::now();
+ scheduleNextStep();
+ }
+ });
+}
+
+bool Renderer::isStepForced() const
+{
+ return m_isStepForced;
+}
+
+void Renderer::setInitialPosition(TimePoint tp, qint64 trackPos)
+{
+ QMetaObject::invokeMethod(this, [this, tp, trackPos]() {
+ Q_ASSERT(m_loopIndex == 0);
+ Q_ASSERT(m_frames.empty());
+
+ m_loopIndex = 0;
+ m_lastPosition.storeRelease(trackPos);
+ m_seekPos.storeRelease(trackPos);
+
+ m_timeController.sync(tp, trackPos);
+ });
+}
+
+void Renderer::onFinalFrameReceived()
+{
+ render({});
+}
+
+void Renderer::render(Frame frame)
+{
+ const auto isFrameOutdated = frame.isValid() && frame.absoluteEnd() < seekPosition();
+
+ if (isFrameOutdated) {
+ qCDebug(qLcRenderer) << "frame outdated! absEnd:" << frame.absoluteEnd() << "absPts"
+ << frame.absolutePts() << "seekPos:" << seekPosition();
+ emit frameProcessed(frame);
+ return;
+ }
+
+ m_frames.enqueue(frame);
+
+ if (m_frames.size() == 1)
+ scheduleNextStep();
+}
+
+void Renderer::onPauseChanged()
+{
+ m_timeController.setPaused(isPaused());
+ PlaybackEngineObject::onPauseChanged();
+}
+
+bool Renderer::canDoNextStep() const
+{
+ return !m_frames.empty() && (m_isStepForced || PlaybackEngineObject::canDoNextStep());
+}
+
+float Renderer::playbackRate() const
+{
+ return m_timeController.playbackRate();
+}
+
+int Renderer::timerInterval() const
+{
+ if (m_frames.empty())
+ return 0;
+
+ auto calculateInterval = [](const TimePoint &nextTime) {
+ using namespace std::chrono;
+
+ const auto delay = nextTime - Clock::now();
+ return std::max(0, static_cast<int>(duration_cast<milliseconds>(delay).count()));
+ };
+
+ if (m_explicitNextFrameTime)
+ return calculateInterval(*m_explicitNextFrameTime);
+
+ if (m_frames.front().isValid())
+ return calculateInterval(m_timeController.timeFromPosition(m_frames.front().absolutePts()));
+
+ if (m_lastFrameEnd > 0)
+ return calculateInterval(m_timeController.timeFromPosition(m_lastFrameEnd));
+
+ return 0;
+}
+
+bool Renderer::setForceStepDone()
+{
+ if (!m_isStepForced.testAndSetOrdered(true, false))
+ return false;
+
+ m_explicitNextFrameTime.reset();
+ emit forceStepDone();
+ return true;
+}
+
+void Renderer::doNextStep()
+{
+ auto frame = m_frames.front();
+
+ if (setForceStepDone()) {
+ // if (frame.isValid() && frame.pts() > m_forceStepMaxPos) {
+ // scheduleNextStep(false);
+ // return;
+ // }
+ }
+
+ const auto result = renderInternal(frame);
+
+ if (result.done) {
+ m_explicitNextFrameTime.reset();
+ m_frames.dequeue();
+
+ if (frame.isValid()) {
+ m_lastPosition.storeRelease(std::max(frame.absolutePts(), lastPosition()));
+
+ // TODO: get rid of m_lastFrameEnd or m_seekPos
+ m_lastFrameEnd = frame.absoluteEnd();
+ m_seekPos.storeRelaxed(m_lastFrameEnd);
+
+ const auto loopIndex = frame.loopOffset().index;
+ if (m_loopIndex < loopIndex) {
+ m_loopIndex = loopIndex;
+ emit loopChanged(id(), frame.loopOffset().pos, m_loopIndex);
+ }
+
+ emit frameProcessed(frame);
+ } else {
+ m_lastPosition.storeRelease(std::max(m_lastFrameEnd, lastPosition()));
+ }
+ } else {
+ m_explicitNextFrameTime = Clock::now() + result.recheckInterval;
+ }
+
+ setAtEnd(result.done && !frame.isValid());
+
+ scheduleNextStep(false);
+}
+
+std::chrono::microseconds Renderer::frameDelay(const Frame &frame, TimePoint timePoint) const
+{
+ return std::chrono::duration_cast<std::chrono::microseconds>(
+ timePoint - m_timeController.timeFromPosition(frame.absolutePts()));
+}
+
+void Renderer::changeRendererTime(std::chrono::microseconds offset)
+{
+ const auto now = Clock::now();
+ const auto pos = m_timeController.positionFromTime(now);
+ m_timeController.sync(now + offset, pos);
+ emit synchronized(id(), now + offset, pos);
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegrenderer_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegrenderer_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegrenderer_p.h
new file mode 100644
index 000000000..99c5ef1b1
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegrenderer_p.h
@@ -0,0 +1,125 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGRENDERER_P_H
+#define QFFMPEGRENDERER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "playbackengine/qffmpegplaybackengineobject_p.h"
+#include "playbackengine/qffmpegtimecontroller_p.h"
+#include "playbackengine/qffmpegframe_p.h"
+
+#include <QtCore/qpointer.h>
+
+#include <chrono>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+class Renderer : public PlaybackEngineObject
+{
+ Q_OBJECT
+public:
+ using TimePoint = TimeController::TimePoint;
+ using Clock = TimeController::Clock;
+ Renderer(const TimeController &tc, const std::chrono::microseconds &seekPosTimeOffset = {});
+
+ void syncSoft(TimePoint tp, qint64 trackPos);
+
+ qint64 seekPosition() const;
+
+ qint64 lastPosition() const;
+
+ void setPlaybackRate(float rate);
+
+ void doForceStep();
+
+ bool isStepForced() const;
+
+public slots:
+ void setInitialPosition(TimePoint tp, qint64 trackPos);
+
+ void onFinalFrameReceived();
+
+ void render(Frame);
+
+signals:
+ void frameProcessed(Frame);
+
+ void synchronized(Id id, TimePoint tp, qint64 pos);
+
+ void forceStepDone();
+
+ void loopChanged(Id id, qint64 offset, int index);
+
+protected:
+ bool setForceStepDone();
+
+ void onPauseChanged() override;
+
+ bool canDoNextStep() const override;
+
+ int timerInterval() const override;
+
+ virtual void onPlaybackRateChanged() { }
+
+ struct RenderingResult
+ {
+ bool done = true;
+ std::chrono::microseconds recheckInterval = std::chrono::microseconds(0);
+ };
+
+ virtual RenderingResult renderInternal(Frame frame) = 0;
+
+ float playbackRate() const;
+
+ std::chrono::microseconds frameDelay(const Frame &frame,
+ TimePoint timePoint = Clock::now()) const;
+
+ void changeRendererTime(std::chrono::microseconds offset);
+
+ template<typename Output, typename ChangeHandler>
+ void setOutputInternal(QPointer<Output> &actual, Output *desired, ChangeHandler &&changeHandler)
+ {
+ const auto connectionType = thread() == QThread::currentThread()
+ ? Qt::AutoConnection
+ : Qt::BlockingQueuedConnection;
+ auto doer = [desired, changeHandler, &actual]() {
+ const auto prev = std::exchange(actual, desired);
+ if (prev != desired)
+ changeHandler(prev);
+ };
+ QMetaObject::invokeMethod(this, doer, connectionType);
+ }
+
+private:
+ void doNextStep() override;
+
+private:
+ TimeController m_timeController;
+ qint64 m_lastFrameEnd = 0;
+ QAtomicInteger<qint64> m_lastPosition = 0;
+ QAtomicInteger<qint64> m_seekPos = 0;
+
+ int m_loopIndex = 0;
+ QQueue<Frame> m_frames;
+
+ QAtomicInteger<bool> m_isStepForced = false;
+ std::optional<TimePoint> m_explicitNextFrameTime;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGRENDERER_P_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegstreamdecoder.cpp b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegstreamdecoder.cpp
new file mode 100644
index 000000000..2f40c53aa
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegstreamdecoder.cpp
@@ -0,0 +1,240 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "playbackengine/qffmpegstreamdecoder_p.h"
+#include "playbackengine/qffmpegmediadataholder_p.h"
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcStreamDecoder, "qt.multimedia.ffmpeg.streamdecoder");
+
+namespace QFFmpeg {
+
+StreamDecoder::StreamDecoder(const Codec &codec, qint64 absSeekPos)
+ : m_codec(codec),
+ m_absSeekPos(absSeekPos),
+ m_trackType(MediaDataHolder::trackTypeFromMediaType(codec.context()->codec_type))
+{
+ qCDebug(qLcStreamDecoder) << "Create stream decoder, trackType" << m_trackType
+ << "absSeekPos:" << absSeekPos;
+ Q_ASSERT(m_trackType != QPlatformMediaPlayer::NTrackTypes);
+}
+
+StreamDecoder::~StreamDecoder()
+{
+ avcodec_flush_buffers(m_codec.context());
+}
+
+void StreamDecoder::onFinalPacketReceived()
+{
+ decode({});
+}
+
+void StreamDecoder::setInitialPosition(TimePoint, qint64 trackPos)
+{
+ m_absSeekPos = trackPos;
+}
+
+void StreamDecoder::decode(Packet packet)
+{
+ m_packets.enqueue(packet);
+
+ scheduleNextStep();
+}
+
+void StreamDecoder::doNextStep()
+{
+ auto packet = m_packets.dequeue();
+
+ auto decodePacket = [this](Packet packet) {
+ if (trackType() == QPlatformMediaPlayer::SubtitleStream)
+ decodeSubtitle(packet);
+ else
+ decodeMedia(packet);
+ };
+
+ if (packet.isValid() && packet.loopOffset().index != m_offset.index) {
+ decodePacket({});
+
+ qCDebug(qLcStreamDecoder) << "flush buffers due to new loop:" << packet.loopOffset().index;
+
+ avcodec_flush_buffers(m_codec.context());
+ m_offset = packet.loopOffset();
+ }
+
+ decodePacket(packet);
+
+ setAtEnd(!packet.isValid());
+
+ if (packet.isValid())
+ emit packetProcessed(packet);
+
+ scheduleNextStep(false);
+}
+
+QPlatformMediaPlayer::TrackType StreamDecoder::trackType() const
+{
+ return m_trackType;
+}
+
+qint32 StreamDecoder::maxQueueSize(QPlatformMediaPlayer::TrackType type)
+{
+ switch (type) {
+
+ case QPlatformMediaPlayer::VideoStream:
+ return 3;
+ case QPlatformMediaPlayer::AudioStream:
+ return 9;
+ case QPlatformMediaPlayer::SubtitleStream:
+ return 6; /*main packet and closing packet*/
+ default:
+ Q_UNREACHABLE_RETURN(-1);
+ }
+}
+
+void StreamDecoder::onFrameProcessed(Frame frame)
+{
+ if (frame.sourceId() != id())
+ return;
+
+ --m_pendingFramesCount;
+ Q_ASSERT(m_pendingFramesCount >= 0);
+
+ scheduleNextStep();
+}
+
+bool StreamDecoder::canDoNextStep() const
+{
+ const qint32 maxCount = maxQueueSize(m_trackType);
+
+ return !m_packets.empty() && m_pendingFramesCount < maxCount
+ && PlaybackEngineObject::canDoNextStep();
+}
+
+void StreamDecoder::onFrameFound(Frame frame)
+{
+ if (frame.isValid() && frame.absoluteEnd() < m_absSeekPos)
+ return;
+
+ Q_ASSERT(m_pendingFramesCount >= 0);
+ ++m_pendingFramesCount;
+ emit requestHandleFrame(frame);
+}
+
+void StreamDecoder::decodeMedia(Packet packet)
+{
+ auto sendPacketResult = sendAVPacket(packet);
+
+ if (sendPacketResult == AVERROR(EAGAIN)) {
+ // Doc says:
+ // AVERROR(EAGAIN): input is not accepted in the current state - user
+ // must read output with avcodec_receive_frame() (once
+ // all output is read, the packet should be resent, and
+ // the call will not fail with EAGAIN).
+ receiveAVFrames();
+ sendPacketResult = sendAVPacket(packet);
+
+ if (sendPacketResult != AVERROR(EAGAIN))
+ qWarning() << "Unexpected FFmpeg behavior";
+ }
+
+ if (sendPacketResult == 0)
+ receiveAVFrames();
+}
+
+int StreamDecoder::sendAVPacket(Packet packet)
+{
+ return avcodec_send_packet(m_codec.context(), packet.isValid() ? packet.avPacket() : nullptr);
+}
+
+void StreamDecoder::receiveAVFrames()
+{
+ while (true) {
+ auto avFrame = makeAVFrame();
+
+ const auto receiveFrameResult = avcodec_receive_frame(m_codec.context(), avFrame.get());
+
+ if (receiveFrameResult == AVERROR_EOF || receiveFrameResult == AVERROR(EAGAIN))
+ break;
+
+ if (receiveFrameResult < 0) {
+ emit error(QMediaPlayer::FormatError, err2str(receiveFrameResult));
+ break;
+ }
+
+ onFrameFound({ m_offset, std::move(avFrame), m_codec, 0, id() });
+ }
+}
+
+void StreamDecoder::decodeSubtitle(Packet packet)
+{
+ if (!packet.isValid())
+ return;
+ // qCDebug(qLcDecoder) << " decoding subtitle" << "has delay:" <<
+ // (codec->codec->capabilities & AV_CODEC_CAP_DELAY);
+ AVSubtitle subtitle;
+ memset(&subtitle, 0, sizeof(subtitle));
+ int gotSubtitle = 0;
+
+ const int res =
+ avcodec_decode_subtitle2(m_codec.context(), &subtitle, &gotSubtitle, packet.avPacket());
+ // qCDebug(qLcDecoder) << " subtitle got:" << res << gotSubtitle << subtitle.format <<
+ // Qt::hex << (quint64)subtitle.pts;
+ if (res < 0 || !gotSubtitle)
+ return;
+
+ // apparently the timestamps in the AVSubtitle structure are not always filled in
+ // if they are missing, use the packets pts and duration values instead
+ qint64 start, end;
+ if (subtitle.pts == AV_NOPTS_VALUE) {
+ start = m_codec.toUs(packet.avPacket()->pts);
+ end = start + m_codec.toUs(packet.avPacket()->duration);
+ } else {
+ auto pts = timeStampUs(subtitle.pts, AVRational{ 1, AV_TIME_BASE });
+ start = *pts + qint64(subtitle.start_display_time) * 1000;
+ end = *pts + qint64(subtitle.end_display_time) * 1000;
+ }
+
+ if (end <= start) {
+ qWarning() << "Invalid subtitle time";
+ return;
+ }
+ // qCDebug(qLcDecoder) << " got subtitle (" << start << "--" << end << "):";
+ QString text;
+ for (uint i = 0; i < subtitle.num_rects; ++i) {
+ const auto *r = subtitle.rects[i];
+ // qCDebug(qLcDecoder) << " subtitletext:" << r->text << "/" << r->ass;
+ if (i)
+ text += QLatin1Char('\n');
+ if (r->text)
+ text += QString::fromUtf8(r->text);
+ else {
+ const char *ass = r->ass;
+ int nCommas = 0;
+ while (*ass) {
+ if (nCommas == 8)
+ break;
+ if (*ass == ',')
+ ++nCommas;
+ ++ass;
+ }
+ text += QString::fromUtf8(ass);
+ }
+ }
+ text.replace(QLatin1String("\\N"), QLatin1String("\n"));
+ text.replace(QLatin1String("\\n"), QLatin1String("\n"));
+ text.replace(QLatin1String("\r\n"), QLatin1String("\n"));
+ if (text.endsWith(QLatin1Char('\n')))
+ text.chop(1);
+
+ onFrameFound({ m_offset, text, start, end - start, id() });
+
+ // TODO: maybe optimize
+ onFrameFound({ m_offset, QString(), end, 0, id() });
+}
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegstreamdecoder_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegstreamdecoder_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegstreamdecoder_p.h
new file mode 100644
index 000000000..1acc07983
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegstreamdecoder_p.h
@@ -0,0 +1,87 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGSTREAMDECODER_P_H
+#define QFFMPEGSTREAMDECODER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+#include "playbackengine/qffmpegplaybackengineobject_p.h"
+#include "playbackengine/qffmpegframe_p.h"
+#include "playbackengine/qffmpegpacket_p.h"
+#include "playbackengine/qffmpegpositionwithoffset_p.h"
+#include "private/qplatformmediaplayer_p.h"
+
+#include <optional>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+class StreamDecoder : public PlaybackEngineObject
+{
+ Q_OBJECT
+public:
+ StreamDecoder(const Codec &codec, qint64 absSeekPos);
+
+ ~StreamDecoder();
+
+ QPlatformMediaPlayer::TrackType trackType() const;
+
+ // Maximum number of frames that we are allowed to keep in render queue
+ static qint32 maxQueueSize(QPlatformMediaPlayer::TrackType type);
+
+public slots:
+ void setInitialPosition(TimePoint tp, qint64 trackPos);
+
+ void decode(Packet);
+
+ void onFinalPacketReceived();
+
+ void onFrameProcessed(Frame frame);
+
+signals:
+ void requestHandleFrame(Frame frame);
+
+ void packetProcessed(Packet);
+
+protected:
+ bool canDoNextStep() const override;
+
+ void doNextStep() override;
+
+private:
+ void decodeMedia(Packet);
+
+ void decodeSubtitle(Packet);
+
+ void onFrameFound(Frame frame);
+
+ int sendAVPacket(Packet);
+
+ void receiveAVFrames();
+
+private:
+ Codec m_codec;
+ qint64 m_absSeekPos = 0;
+ const QPlatformMediaPlayer::TrackType m_trackType;
+
+ qint32 m_pendingFramesCount = 0;
+
+ LoopOffset m_offset;
+
+ QQueue<Packet> m_packets;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGSTREAMDECODER_P_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegsubtitlerenderer.cpp b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegsubtitlerenderer.cpp
new file mode 100644
index 000000000..789c9b53b
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegsubtitlerenderer.cpp
@@ -0,0 +1,44 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "playbackengine/qffmpegsubtitlerenderer_p.h"
+
+#include "qvideosink.h"
+#include "qdebug.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+SubtitleRenderer::SubtitleRenderer(const TimeController &tc, QVideoSink *sink)
+ : Renderer(tc), m_sink(sink)
+{
+}
+
+void SubtitleRenderer::setOutput(QVideoSink *sink, bool cleanPrevSink)
+{
+ setOutputInternal(m_sink, sink, [cleanPrevSink](QVideoSink *prev) {
+ if (prev && cleanPrevSink)
+ prev->setSubtitleText({});
+ });
+}
+
+SubtitleRenderer::~SubtitleRenderer()
+{
+ if (m_sink)
+ m_sink->setSubtitleText({});
+}
+
+Renderer::RenderingResult SubtitleRenderer::renderInternal(Frame frame)
+{
+ if (m_sink)
+ m_sink->setSubtitleText(frame.isValid() ? frame.text() : QString());
+
+ return {};
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegsubtitlerenderer_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegsubtitlerenderer_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegsubtitlerenderer_p.h
new file mode 100644
index 000000000..805212e83
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegsubtitlerenderer_p.h
@@ -0,0 +1,48 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGSUBTITLERENDERER_P_H
+#define QFFMPEGSUBTITLERENDERER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "playbackengine/qffmpegrenderer_p.h"
+
+#include <QtCore/qpointer.h>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoSink;
+
+namespace QFFmpeg {
+
+class SubtitleRenderer : public Renderer
+{
+ Q_OBJECT
+public:
+ SubtitleRenderer(const TimeController &tc, QVideoSink *sink);
+
+ ~SubtitleRenderer() override;
+
+ void setOutput(QVideoSink *sink, bool cleanPrevSink = false);
+
+protected:
+ RenderingResult renderInternal(Frame frame) override;
+
+private:
+ QPointer<QVideoSink> m_sink;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGSUBTITLERENDERER_P_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegtimecontroller.cpp b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegtimecontroller.cpp
new file mode 100644
index 000000000..8352384b4
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegtimecontroller.cpp
@@ -0,0 +1,165 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "playbackengine/qffmpegtimecontroller_p.h"
+
+#include "qglobal.h"
+#include "qdebug.h"
+
+#include <algorithm>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+TimeController::TimeController()
+{
+ sync();
+}
+
+TimeController::PlaybackRate TimeController::playbackRate() const
+{
+ return m_playbackRate;
+}
+
+void TimeController::setPlaybackRate(PlaybackRate playbackRate)
+{
+ if (playbackRate == m_playbackRate)
+ return;
+
+ Q_ASSERT(playbackRate > 0.f);
+
+ scrollTimeTillNow();
+ m_playbackRate = playbackRate;
+
+ if (m_softSyncData)
+ m_softSyncData = makeSoftSyncData(m_timePoint, m_position, m_softSyncData->dstTimePoint);
+}
+
+void TimeController::sync(qint64 trackPos)
+{
+ sync(Clock::now(), trackPos);
+}
+
+void TimeController::sync(const TimePoint &tp, qint64 pos)
+{
+ m_softSyncData.reset();
+ m_position = TrackTime(pos);
+ m_timePoint = tp;
+}
+
+void TimeController::syncSoft(const TimePoint &tp, qint64 pos, const Clock::duration &fixingTime)
+{
+ const auto srcTime = Clock::now();
+ const auto srcPos = positionFromTime(srcTime, true);
+ const auto dstTime = srcTime + fixingTime;
+
+ m_position = TrackTime(pos);
+ m_timePoint = tp;
+
+ m_softSyncData = makeSoftSyncData(srcTime, TrackTime(srcPos), dstTime);
+}
+
+qint64 TimeController::currentPosition(const Clock::duration &offset) const
+{
+ return positionFromTime(Clock::now() + offset);
+}
+
+void TimeController::setPaused(bool paused)
+{
+ if (m_paused == paused)
+ return;
+
+ scrollTimeTillNow();
+ m_paused = paused;
+}
+
+qint64 TimeController::positionFromTime(TimePoint tp, bool ignorePause) const
+{
+ tp = m_paused && !ignorePause ? m_timePoint : tp;
+
+ if (m_softSyncData && tp < m_softSyncData->dstTimePoint) {
+ const PlaybackRate rate =
+ tp > m_softSyncData->srcTimePoint ? m_softSyncData->internalRate : m_playbackRate;
+
+ return (m_softSyncData->srcPosition
+ + toTrackTime((tp - m_softSyncData->srcTimePoint) * rate))
+ .count();
+ }
+
+ return positionFromTimeInternal(tp).count();
+}
+
+TimeController::TimePoint TimeController::timeFromPosition(qint64 pos, bool ignorePause) const
+{
+ auto position = m_paused && !ignorePause ? m_position : TrackTime(pos);
+
+ if (m_softSyncData && position < m_softSyncData->dstPosition) {
+ const auto rate = position > m_softSyncData->srcPosition ? m_softSyncData->internalRate
+ : m_playbackRate;
+ return m_softSyncData->srcTimePoint
+ + toClockTime((position - m_softSyncData->srcPosition) / rate);
+ }
+
+ return timeFromPositionInternal(position);
+}
+
+TimeController::SoftSyncData TimeController::makeSoftSyncData(const TimePoint &srcTp,
+ const TrackTime &srcPos,
+ const TimePoint &dstTp) const
+{
+ SoftSyncData result;
+ result.srcTimePoint = srcTp;
+ result.srcPosition = srcPos;
+ result.dstTimePoint = dstTp;
+ result.srcPosOffest = srcPos - positionFromTimeInternal(srcTp);
+ result.dstPosition = positionFromTimeInternal(dstTp);
+ result.internalRate =
+ static_cast<PlaybackRate>(toClockTime(TrackTime(result.dstPosition - srcPos)).count())
+ / (dstTp - srcTp).count();
+
+ return result;
+}
+
+TimeController::TrackTime TimeController::positionFromTimeInternal(const TimePoint &tp) const
+{
+ return m_position + toTrackTime((tp - m_timePoint) * m_playbackRate);
+}
+
+TimeController::TimePoint TimeController::timeFromPositionInternal(const TrackTime &pos) const
+{
+ return m_timePoint + toClockTime(TrackTime(pos - m_position) / m_playbackRate);
+}
+
+void TimeController::scrollTimeTillNow()
+{
+ const auto now = Clock::now();
+ if (!m_paused) {
+ m_position = positionFromTimeInternal(now);
+
+ // let's forget outdated syncronizations
+ if (m_softSyncData && m_softSyncData->dstTimePoint <= now)
+ m_softSyncData.reset();
+ } else if (m_softSyncData) {
+ m_softSyncData->dstTimePoint += now - m_timePoint;
+ m_softSyncData->srcTimePoint += now - m_timePoint;
+ }
+
+ m_timePoint = now;
+}
+
+template<typename T>
+TimeController::Clock::duration TimeController::toClockTime(const T &t)
+{
+ return std::chrono::duration_cast<Clock::duration>(t);
+}
+
+template<typename T>
+TimeController::TrackTime TimeController::toTrackTime(const T &t)
+{
+ return std::chrono::duration_cast<TrackTime>(t);
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegtimecontroller_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegtimecontroller_p.h
new file mode 100644
index 000000000..93ced7e64
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegtimecontroller_p.h
@@ -0,0 +1,94 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGTIMECONTROLLER_P_H
+#define QFFMPEGTIMECONTROLLER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qglobal.h"
+
+#include <chrono>
+#include <optional>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+class TimeController
+{
+ using TrackTime = std::chrono::microseconds;
+
+public:
+ using Clock = std::chrono::steady_clock;
+ using TimePoint = Clock::time_point;
+ using PlaybackRate = float;
+
+ TimeController();
+
+ PlaybackRate playbackRate() const;
+
+ void setPlaybackRate(PlaybackRate playbackRate);
+
+ void sync(qint64 trackPos = 0);
+
+ void sync(const TimePoint &tp, qint64 pos);
+
+ void syncSoft(const TimePoint &tp, qint64 pos,
+ const Clock::duration &fixingTime = std::chrono::seconds(4));
+
+ qint64 currentPosition(const Clock::duration &offset = Clock::duration{ 0 }) const;
+
+ void setPaused(bool paused);
+
+ qint64 positionFromTime(TimePoint tp, bool ignorePause = false) const;
+
+ TimePoint timeFromPosition(qint64 pos, bool ignorePause = false) const;
+
+private:
+ struct SoftSyncData
+ {
+ TimePoint srcTimePoint;
+ TrackTime srcPosition;
+ TimePoint dstTimePoint;
+ TrackTime srcPosOffest;
+ TrackTime dstPosition;
+ PlaybackRate internalRate = 1;
+ };
+
+ SoftSyncData makeSoftSyncData(const TimePoint &srcTp, const TrackTime &srcPos,
+ const TimePoint &dstTp) const;
+
+ TrackTime positionFromTimeInternal(const TimePoint &tp) const;
+
+ TimePoint timeFromPositionInternal(const TrackTime &pos) const;
+
+ void scrollTimeTillNow();
+
+ template<typename T>
+ static Clock::duration toClockTime(const T &t);
+
+ template<typename T>
+ static TrackTime toTrackTime(const T &t);
+
+private:
+ bool m_paused = true;
+ PlaybackRate m_playbackRate = 1;
+ TrackTime m_position;
+ TimePoint m_timePoint = {};
+ std::optional<SoftSyncData> m_softSyncData;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGTIMECONTROLLER_P_H
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegvideorenderer.cpp b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegvideorenderer.cpp
new file mode 100644
index 000000000..dceb00f83
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegvideorenderer.cpp
@@ -0,0 +1,79 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "playbackengine/qffmpegvideorenderer_p.h"
+#include "qffmpegvideobuffer_p.h"
+#include "qvideosink.h"
+#include "private/qvideoframe_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+VideoRenderer::VideoRenderer(const TimeController &tc, QVideoSink *sink, QtVideo::Rotation rotation)
+ : Renderer(tc), m_sink(sink), m_rotation(rotation)
+{
+}
+
+void VideoRenderer::setOutput(QVideoSink *sink, bool cleanPrevSink)
+{
+ setOutputInternal(m_sink, sink, [cleanPrevSink](QVideoSink *prev) {
+ if (prev && cleanPrevSink)
+ prev->setVideoFrame({});
+ });
+}
+
+VideoRenderer::RenderingResult VideoRenderer::renderInternal(Frame frame)
+{
+ if (!m_sink)
+ return {};
+
+ if (!frame.isValid()) {
+ m_sink->setVideoFrame({});
+ return {};
+ }
+
+ // qCDebug(qLcVideoRenderer) << "RHI:" << accel.isNull() << accel.rhi() << sink->rhi();
+
+ const auto codec = frame.codec();
+ Q_ASSERT(codec);
+
+#ifdef Q_OS_ANDROID
+ // QTBUG-108446
+ // In general case, just creation of frames context is not correct since
+ // frames may require additional specific data for hw contexts, so
+ // just setting of hw_frames_ctx is not enough.
+ // TODO: investigate the case in order to remove or fix the code.
+ if (codec->hwAccel() && !frame.avFrame()->hw_frames_ctx) {
+ HWAccel *hwaccel = codec->hwAccel();
+ AVFrame *avframe = frame.avFrame();
+ if (!hwaccel->hwFramesContext())
+ hwaccel->createFramesContext(AVPixelFormat(avframe->format),
+ { avframe->width, avframe->height });
+
+ if (hwaccel->hwFramesContext())
+ avframe->hw_frames_ctx = av_buffer_ref(hwaccel->hwFramesContextAsBuffer());
+ }
+#endif
+
+ const auto pixelAspectRatio = codec->pixelAspectRatio(frame.avFrame());
+ auto buffer = std::make_unique<QFFmpegVideoBuffer>(frame.takeAVFrame(), pixelAspectRatio);
+ QVideoFrameFormat format(buffer->size(), buffer->pixelFormat());
+ format.setColorSpace(buffer->colorSpace());
+ format.setColorTransfer(buffer->colorTransfer());
+ format.setColorRange(buffer->colorRange());
+ format.setMaxLuminance(buffer->maxNits());
+ format.setRotation(m_rotation);
+ QVideoFrame videoFrame = QVideoFramePrivate::createFrame(std::move(buffer), format);
+ videoFrame.setStartTime(frame.pts());
+ videoFrame.setEndTime(frame.end());
+ m_sink->setVideoFrame(videoFrame);
+
+ return {};
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegvideorenderer_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegvideorenderer_p.h b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegvideorenderer_p.h
new file mode 100644
index 000000000..4866420e8
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegvideorenderer_p.h
@@ -0,0 +1,47 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGVIDEORENDERER_P_H
+#define QFFMPEGVIDEORENDERER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "playbackengine/qffmpegrenderer_p.h"
+
+#include <QtCore/qpointer.h>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoSink;
+
+namespace QFFmpeg {
+
+class VideoRenderer : public Renderer
+{
+ Q_OBJECT
+public:
+ VideoRenderer(const TimeController &tc, QVideoSink *sink, QtVideo::Rotation rotation);
+
+ void setOutput(QVideoSink *sink, bool cleanPrevSink = false);
+
+protected:
+ RenderingResult renderInternal(Frame frame) override;
+
+private:
+ QPointer<QVideoSink> m_sink;
+ QtVideo::Rotation m_rotation;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGVIDEORENDERER_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qandroidcamera.cpp b/src/plugins/multimedia/ffmpeg/qandroidcamera.cpp
new file mode 100644
index 000000000..56725b2bb
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qandroidcamera.cpp
@@ -0,0 +1,697 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidcamera_p.h"
+
+#include <jni.h>
+#include <QMediaFormat>
+#include <memory>
+#include <optional>
+#include <qmediadevices.h>
+#include <qguiapplication.h>
+#include <qscreen.h>
+#include <QDebug>
+#include <qloggingcategory.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qpermissions.h>
+#include <QtCore/private/qandroidextras_p.h>
+#include <private/qcameradevice_p.h>
+#include <QReadWriteLock>
+#include <private/qvideoframeconverter_p.h>
+#include <private/qvideotexturehelper_p.h>
+#include <qffmpegvideobuffer_p.h>
+
+#include <qandroidcameraframe_p.h>
+#include <utility>
+
+extern "C" {
+#include "libavutil/hwcontext.h"
+#include "libavutil/pixfmt.h"
+}
+
+Q_DECLARE_JNI_CLASS(QtCamera2, "org/qtproject/qt/android/multimedia/QtCamera2");
+Q_DECLARE_JNI_CLASS(QtVideoDeviceManager,
+ "org/qtproject/qt/android/multimedia/QtVideoDeviceManager");
+
+Q_DECLARE_JNI_CLASS(AndroidImageFormat, "android/graphics/ImageFormat");
+
+Q_DECLARE_JNI_CLASS(AndroidImage, "android/media/Image")
+Q_DECLARE_JNI_TYPE(AndroidImagePlaneArray, "[Landroid/media/Image$Plane;")
+Q_DECLARE_JNI_CLASS(JavaByteBuffer, "java/nio/ByteBuffer")
+Q_DECLARE_JNI_TYPE(StringArray, "[Ljava/lang/String;")
+
+QT_BEGIN_NAMESPACE
+static Q_LOGGING_CATEGORY(qLCAndroidCamera, "qt.multimedia.ffmpeg.androidCamera");
+
+typedef QMap<QString, QAndroidCamera *> QAndroidCameraMap;
+Q_GLOBAL_STATIC(QAndroidCameraMap, g_qcameras)
+Q_GLOBAL_STATIC(QReadWriteLock, rwLock)
+
+namespace {
+
+QCameraFormat getDefaultCameraFormat()
+{
+ // default settings
+ QCameraFormatPrivate *defaultFormat = new QCameraFormatPrivate{
+ .pixelFormat = QVideoFrameFormat::Format_YUV420P,
+ .resolution = { 1920, 1080 },
+ .minFrameRate = 12,
+ .maxFrameRate = 30,
+ };
+ return defaultFormat->create();
+}
+
+bool checkCameraPermission()
+{
+ QCameraPermission permission;
+
+ const bool granted = qApp->checkPermission(permission) == Qt::PermissionStatus::Granted;
+ if (!granted)
+ qCWarning(qLCAndroidCamera) << "Access to camera not granted!";
+
+ return granted;
+}
+
+int sensorOrientation(QString cameraId)
+{
+ QJniObject deviceManager(QtJniTypes::Traits<QtJniTypes::QtVideoDeviceManager>::className(),
+ QNativeInterface::QAndroidApplication::context());
+
+ if (!deviceManager.isValid()) {
+ qCWarning(qLCAndroidCamera) << "Failed to connect to Qt Video Device Manager.";
+ return 0;
+ }
+
+ return deviceManager.callMethod<jint>("getSensorOrientation",
+ QJniObject::fromString(cameraId).object<jstring>());
+}
+} // namespace
+
+// QAndroidCamera
+
+QAndroidCamera::QAndroidCamera(QCamera *camera) : QPlatformCamera(camera)
+{
+ m_jniCamera = QJniObject(QtJniTypes::Traits<QtJniTypes::QtCamera2>::className(),
+ QNativeInterface::QAndroidApplication::context());
+
+ m_hwAccel = QFFmpeg::HWAccel::create(AVHWDeviceType::AV_HWDEVICE_TYPE_MEDIACODEC);
+ if (camera) {
+ m_cameraDevice = camera->cameraDevice();
+ m_cameraFormat = !camera->cameraFormat().isNull() ? camera->cameraFormat()
+ : getDefaultCameraFormat();
+ updateCameraCharacteristics();
+ }
+
+ if (qApp) {
+ connect(qApp, &QGuiApplication::applicationStateChanged,
+ this, &QAndroidCamera::onApplicationStateChanged);
+ }
+};
+
+QAndroidCamera::~QAndroidCamera()
+{
+ {
+ QWriteLocker locker(rwLock);
+ g_qcameras->remove(m_cameraDevice.id());
+
+ m_jniCamera.callMethod<void>("stopAndClose");
+ setState(State::Closed);
+ }
+
+ m_jniCamera.callMethod<void>("stopBackgroundThread");
+}
+
+void QAndroidCamera::setCamera(const QCameraDevice &camera)
+{
+ const bool active = isActive();
+ if (active)
+ setActive(false);
+
+ m_cameraDevice = camera;
+ updateCameraCharacteristics();
+ m_cameraFormat = getDefaultCameraFormat();
+
+ if (active)
+ setActive(true);
+}
+
+std::optional<int> QAndroidCamera::ffmpegHWPixelFormat() const
+{
+ return QFFmpegVideoBuffer::toAVPixelFormat(m_androidFramePixelFormat);
+}
+
+static void deleteFrame(void *opaque, uint8_t *data)
+{
+ Q_UNUSED(data);
+
+ auto frame = reinterpret_cast<QAndroidCameraFrame *>(opaque);
+
+ if (frame)
+ delete frame;
+}
+
+void QAndroidCamera::frameAvailable(QJniObject image, bool takePhoto)
+{
+ if (!(m_state == State::WaitingStart || m_state == State::Started) && !m_waitingForFirstFrame) {
+ qCWarning(qLCAndroidCamera) << "Received frame when not active... ignoring";
+ qCWarning(qLCAndroidCamera) << "state:" << m_state;
+ image.callMethod<void>("close");
+ return;
+ }
+
+ auto androidFrame = new QAndroidCameraFrame(image);
+ if (!androidFrame->isParsed()) {
+ qCWarning(qLCAndroidCamera) << "Failed to parse frame.. dropping frame";
+ delete androidFrame;
+ return;
+ }
+
+ int timestamp = androidFrame->timestamp();
+ m_androidFramePixelFormat = androidFrame->format();
+ if (m_waitingForFirstFrame) {
+ m_waitingForFirstFrame = false;
+ setState(State::Started);
+ }
+ auto avframe = QFFmpeg::makeAVFrame();
+
+ avframe->width = androidFrame->size().width();
+ avframe->height = androidFrame->size().height();
+ avframe->format = QFFmpegVideoBuffer::toAVPixelFormat(androidFrame->format());
+
+ avframe->extended_data = avframe->data;
+ avframe->pts = androidFrame->timestamp();
+
+ for (int planeNumber = 0; planeNumber < androidFrame->numberPlanes(); planeNumber++) {
+ QAndroidCameraFrame::Plane plane = androidFrame->plane(planeNumber);
+ avframe->linesize[planeNumber] = plane.rowStride;
+ avframe->data[planeNumber] = plane.data;
+ }
+
+ avframe->data[3] = nullptr;
+ avframe->buf[0] = nullptr;
+
+ avframe->opaque_ref = av_buffer_create(NULL, 1, deleteFrame, androidFrame, 0);
+ avframe->extended_data = avframe->data;
+ avframe->pts = timestamp;
+
+ QVideoFrameFormat format(androidFrame->size(), androidFrame->format());
+
+ QVideoFrame videoFrame(new QFFmpegVideoBuffer(std::move(avframe)), format);
+
+ if (lastTimestamp == 0)
+ lastTimestamp = timestamp;
+
+ videoFrame.setRotation(rotation());
+ videoFrame.setMirrored(m_cameraDevice.position() == QCameraDevice::Position::FrontFace);
+
+ videoFrame.setStartTime(lastTimestamp);
+ videoFrame.setEndTime(timestamp);
+
+ if (!takePhoto)
+ emit newVideoFrame(videoFrame);
+ else
+ emit onCaptured(videoFrame);
+
+ lastTimestamp = timestamp;
+}
+
+QtVideo::Rotation QAndroidCamera::rotation()
+{
+ auto screen = QGuiApplication::primaryScreen();
+ auto screenOrientation = screen->orientation();
+ if (screenOrientation == Qt::PrimaryOrientation)
+ screenOrientation = screen->primaryOrientation();
+
+ // Display rotation is the opposite direction of the physical device rotation. We need the
+ // device rotation, that's why Landscape is 270 and InvertedLandscape is 90
+ int deviceOrientation = 0;
+ switch (screenOrientation) {
+ case Qt::PrimaryOrientation:
+ case Qt::PortraitOrientation:
+ break;
+ case Qt::LandscapeOrientation:
+ deviceOrientation = 270;
+ break;
+ case Qt::InvertedPortraitOrientation:
+ deviceOrientation = 180;
+ break;
+ case Qt::InvertedLandscapeOrientation:
+ deviceOrientation = 90;
+ break;
+ }
+
+ int sign = (m_cameraDevice.position() == QCameraDevice::Position::FrontFace) ? 1 : -1;
+ int rotation = (sensorOrientation(m_cameraDevice.id()) - deviceOrientation * sign + 360) % 360;
+
+ return QtVideo::Rotation(rotation);
+}
+
+void QAndroidCamera::setActive(bool active)
+{
+ if (isActive() == active)
+ return;
+
+ if (!m_jniCamera.isValid()) {
+ updateError(QCamera::CameraError, QStringLiteral("No connection to Android Camera2 API"));
+ return;
+ }
+
+ if (active && checkCameraPermission()) {
+ QWriteLocker locker(rwLock);
+ int width = m_cameraFormat.resolution().width();
+ int height = m_cameraFormat.resolution().height();
+
+ if (width < 0 || height < 0) {
+ m_cameraFormat = getDefaultCameraFormat();
+ width = m_cameraFormat.resolution().width();
+ height = m_cameraFormat.resolution().height();
+ }
+
+ width = FFALIGN(width, 16);
+ height = FFALIGN(height, 16);
+
+ setState(State::WaitingOpen);
+ g_qcameras->insert(m_cameraDevice.id(), this);
+
+ // this should use the camera format.
+ // but there is only 2 fully supported formats on android - JPG and YUV420P
+ // and JPEG is not supported for encoding in FFmpeg, so it's locked for YUV for now.
+ const static int imageFormat =
+ QJniObject::getStaticField<QtJniTypes::AndroidImageFormat, jint>("YUV_420_888");
+ m_jniCamera.callMethod<void>("prepareCamera", jint(width), jint(height),
+ jint(imageFormat), jint(m_cameraFormat.minFrameRate()),
+ jint(m_cameraFormat.maxFrameRate()));
+
+ bool canOpen = m_jniCamera.callMethod<jboolean>(
+ "open", QJniObject::fromString(m_cameraDevice.id()).object<jstring>());
+
+ if (!canOpen) {
+ g_qcameras->remove(m_cameraDevice.id());
+ setState(State::Closed);
+ updateError(QCamera::CameraError,
+ QString("Failed to start camera: ").append(m_cameraDevice.description()));
+ }
+ } else {
+ m_jniCamera.callMethod<void>("stopAndClose");
+ m_jniCamera.callMethod<void>("clearSurfaces");
+ setState(State::Closed);
+ }
+}
+
+void QAndroidCamera::setState(QAndroidCamera::State newState)
+{
+ if (newState == m_state)
+ return;
+
+ bool wasActive = isActive();
+
+ if (newState == State::Started)
+ m_state = State::Started;
+
+ if (m_state == State::Started && newState == State::Closed)
+ m_state = State::Closed;
+
+ if ((m_state == State::WaitingOpen || m_state == State::WaitingStart)
+ && newState == State::Closed) {
+
+ m_state = State::Closed;
+
+ updateError(QCamera::CameraError,
+ QString("Failed to start Camera %1").arg(m_cameraDevice.description()));
+ }
+
+ if (m_state == State::Closed && newState == State::WaitingOpen)
+ m_state = State::WaitingOpen;
+
+ if (m_state == State::WaitingOpen && newState == State::WaitingStart)
+ m_state = State::WaitingStart;
+
+ if (wasActive != isActive())
+ emit activeChanged(isActive());
+}
+
+bool QAndroidCamera::setCameraFormat(const QCameraFormat &format)
+{
+ const auto chosenFormat = format.isNull() ? getDefaultCameraFormat() : format;
+
+ if (chosenFormat == m_cameraFormat || !m_cameraDevice.videoFormats().contains(chosenFormat))
+ return false;
+
+ m_cameraFormat = chosenFormat;
+
+ if (isActive()) {
+ // Restart the camera to set new camera format
+ setActive(false);
+ setActive(true);
+ }
+
+ return true;
+}
+
+void QAndroidCamera::updateCameraCharacteristics()
+{
+ if (m_cameraDevice.id().isEmpty()) {
+ cleanCameraCharacteristics();
+ return;
+ }
+
+ QJniObject deviceManager(QtJniTypes::Traits<QtJniTypes::QtVideoDeviceManager>::className(),
+ QNativeInterface::QAndroidApplication::context());
+
+ if (!deviceManager.isValid()) {
+ qCWarning(qLCAndroidCamera) << "Failed to connect to Qt Video Device Manager.";
+ cleanCameraCharacteristics();
+ return;
+ }
+
+ const float maxZoom = deviceManager.callMethod<jfloat>(
+ "getMaxZoom", QJniObject::fromString(m_cameraDevice.id()).object<jstring>());
+ maximumZoomFactorChanged(maxZoom);
+ if (maxZoom < zoomFactor()) {
+ zoomTo(1.0, -1.0);
+ }
+
+ m_TorchModeSupported = deviceManager.callMethod<jboolean>(
+ "isTorchModeSupported", QJniObject::fromString(m_cameraDevice.id()).object<jstring>());
+
+ m_supportedFlashModes.clear();
+ m_supportedFlashModes.append(QCamera::FlashOff);
+ QJniObject flashModesObj = deviceManager.callMethod<QtJniTypes::StringArray>(
+ "getSupportedFlashModes",
+ QJniObject::fromString(m_cameraDevice.id()).object<jstring>());
+ QJniEnvironment jniEnv;
+ jobjectArray flashModes = flashModesObj.object<jobjectArray>();
+ int size = jniEnv->GetArrayLength(flashModes);
+ for (int i = 0; i < size; ++i) {
+ QJniObject flashModeObj = jniEnv->GetObjectArrayElement(flashModes, i);
+ QString flashMode = flashModeObj.toString();
+ if (flashMode == QLatin1String("auto"))
+ m_supportedFlashModes.append(QCamera::FlashAuto);
+ else if (flashMode == QLatin1String("on"))
+ m_supportedFlashModes.append(QCamera::FlashOn);
+ }
+}
+
+void QAndroidCamera::cleanCameraCharacteristics()
+{
+ maximumZoomFactorChanged(1.0);
+ if (zoomFactor() != 1.0) {
+ zoomTo(1.0, -1.0);
+ }
+ if (torchMode() != QCamera::TorchOff) {
+ setTorchMode(QCamera::TorchOff);
+ }
+ m_TorchModeSupported = false;
+
+ if (flashMode() != QCamera::FlashOff) {
+ setFlashMode(QCamera::FlashOff);
+ }
+ m_supportedFlashModes.clear();
+ m_supportedFlashModes.append(QCamera::FlashOff);
+}
+
+void QAndroidCamera::setFlashMode(QCamera::FlashMode mode)
+{
+ if (!isFlashModeSupported(mode))
+ return;
+
+ QString flashMode;
+ switch (mode) {
+ case QCamera::FlashAuto:
+ flashMode = QLatin1String("auto");
+ break;
+ case QCamera::FlashOn:
+ flashMode = QLatin1String("on");
+ break;
+ case QCamera::FlashOff:
+ default:
+ flashMode = QLatin1String("off");
+ break;
+ }
+
+ m_jniCamera.callMethod<void>("setFlashMode", QJniObject::fromString(flashMode).object<jstring>());
+ flashModeChanged(mode);
+}
+
+bool QAndroidCamera::isFlashModeSupported(QCamera::FlashMode mode) const
+{
+ return m_supportedFlashModes.contains(mode);
+}
+
+bool QAndroidCamera::isFlashReady() const
+{
+ // Android doesn't have an API for that.
+ // Only check if device supports more flash modes than just FlashOff.
+ return m_supportedFlashModes.size() > 1;
+}
+
+bool QAndroidCamera::isTorchModeSupported(QCamera::TorchMode mode) const
+{
+ if (mode == QCamera::TorchOff)
+ return true;
+ else if (mode == QCamera::TorchOn)
+ return m_TorchModeSupported;
+
+ return false;
+}
+
+void QAndroidCamera::setTorchMode(QCamera::TorchMode mode)
+{
+ bool torchMode;
+ if (mode == QCamera::TorchOff) {
+ torchMode = false;
+ } else if (mode == QCamera::TorchOn) {
+ torchMode = true;
+ } else {
+ qWarning() << "Unknown Torch mode";
+ return;
+ }
+ m_jniCamera.callMethod<void>("setTorchMode", jboolean(torchMode));
+ torchModeChanged(mode);
+}
+
+void QAndroidCamera::zoomTo(float factor, float rate)
+{
+ Q_UNUSED(rate);
+ m_jniCamera.callMethod<void>("zoomTo", factor);
+ zoomFactorChanged(factor);
+}
+
+void QAndroidCamera::onApplicationStateChanged()
+{
+ switch (QGuiApplication::applicationState()) {
+ case Qt::ApplicationInactive:
+ if (isActive()) {
+ setActive(false);
+ m_wasActive = true;
+ }
+ break;
+ case Qt::ApplicationActive:
+ if (m_wasActive) {
+ setActive(true);
+ m_wasActive = false;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void QAndroidCamera::onCaptureSessionConfigured()
+{
+ bool canStart = m_jniCamera.callMethod<jboolean>("start", 3);
+ setState(canStart ? State::WaitingStart : State::Closed);
+}
+
+void QAndroidCamera::onCaptureSessionConfigureFailed()
+{
+ setState(State::Closed);
+}
+
+void QAndroidCamera::onCameraOpened()
+{
+ bool canStart = m_jniCamera.callMethod<jboolean>("createSession");
+ setState(canStart ? State::WaitingStart : State::Closed);
+}
+
+void QAndroidCamera::onCameraDisconnect()
+{
+ setState(State::Closed);
+}
+
+void QAndroidCamera::onCameraError(int reason)
+{
+ updateError(QCamera::CameraError,
+ QString("Capture error with Camera %1. Camera2 Api error code: %2")
+ .arg(m_cameraDevice.description())
+ .arg(reason));
+}
+
+void QAndroidCamera::onSessionActive()
+{
+ m_waitingForFirstFrame = true;
+}
+
+void QAndroidCamera::onSessionClosed()
+{
+ m_waitingForFirstFrame = false;
+ setState(State::Closed);
+}
+
+void QAndroidCamera::capture()
+{
+ m_jniCamera.callMethod<void>("takePhoto");
+}
+
+void QAndroidCamera::updateExif(const QString &filename)
+{
+ m_jniCamera.callMethod<void>("saveExifToFile", QJniObject::fromString(filename).object<jstring>());
+}
+
+void QAndroidCamera::onCaptureSessionFailed(int reason, long frameNumber)
+{
+ Q_UNUSED(frameNumber);
+
+ updateError(QCamera::CameraError,
+ QStringLiteral("Capture session failure with Camera %1. Camera2 Api error code: %2")
+ .arg(m_cameraDevice.description())
+ .arg(reason));
+}
+
+// JNI logic
+
+#define GET_CAMERA(cameraId) \
+ QString key = QJniObject(cameraId).toString(); \
+ QReadLocker locker(rwLock); \
+ if (!g_qcameras->contains(key)) { \
+ qCWarning(qLCAndroidCamera) << "Calling back a QtCamera2 after being destroyed."; \
+ return; \
+ } \
+ QAndroidCamera *camera = g_qcameras->find(key).value();
+
+static void onFrameAvailable(JNIEnv *env, jobject obj, jstring cameraId,
+ QtJniTypes::AndroidImage image)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(obj);
+ GET_CAMERA(cameraId);
+
+ camera->frameAvailable(QJniObject(image));
+}
+Q_DECLARE_JNI_NATIVE_METHOD(onFrameAvailable)
+
+static void onPhotoAvailable(JNIEnv *env, jobject obj, jstring cameraId,
+ QtJniTypes::AndroidImage image)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(obj);
+ GET_CAMERA(cameraId);
+
+ camera->frameAvailable(QJniObject(image), true);
+}
+Q_DECLARE_JNI_NATIVE_METHOD(onPhotoAvailable)
+
+
+static void onCameraOpened(JNIEnv *env, jobject obj, jstring cameraId)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(obj);
+ GET_CAMERA(cameraId);
+
+ camera->onCameraOpened();
+}
+Q_DECLARE_JNI_NATIVE_METHOD(onCameraOpened)
+
+static void onCameraDisconnect(JNIEnv *env, jobject obj, jstring cameraId)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(obj);
+ GET_CAMERA(cameraId);
+
+ camera->onCameraDisconnect();
+}
+Q_DECLARE_JNI_NATIVE_METHOD(onCameraDisconnect)
+
+static void onCameraError(JNIEnv *env, jobject obj, jstring cameraId, jint error)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(obj);
+ GET_CAMERA(cameraId);
+
+ camera->onCameraError(error);
+}
+Q_DECLARE_JNI_NATIVE_METHOD(onCameraError)
+
+static void onCaptureSessionConfigured(JNIEnv *env, jobject obj, jstring cameraId)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(obj);
+ GET_CAMERA(cameraId);
+
+ camera->onCaptureSessionConfigured();
+}
+Q_DECLARE_JNI_NATIVE_METHOD(onCaptureSessionConfigured)
+
+static void onCaptureSessionConfigureFailed(JNIEnv *env, jobject obj, jstring cameraId)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(obj);
+ GET_CAMERA(cameraId);
+
+ camera->onCaptureSessionConfigureFailed();
+}
+Q_DECLARE_JNI_NATIVE_METHOD(onCaptureSessionConfigureFailed)
+
+static void onSessionActive(JNIEnv *env, jobject obj, jstring cameraId)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(obj);
+ GET_CAMERA(cameraId);
+
+ camera->onSessionActive();
+}
+Q_DECLARE_JNI_NATIVE_METHOD(onSessionActive)
+
+static void onSessionClosed(JNIEnv *env, jobject obj, jstring cameraId)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(obj);
+ GET_CAMERA(cameraId);
+
+ camera->onSessionClosed();
+}
+Q_DECLARE_JNI_NATIVE_METHOD(onSessionClosed)
+
+static void onCaptureSessionFailed(JNIEnv *env, jobject obj, jstring cameraId, jint reason,
+ jlong framenumber)
+{
+ Q_UNUSED(env);
+ Q_UNUSED(obj);
+ GET_CAMERA(cameraId);
+
+ camera->onCaptureSessionFailed(reason, framenumber);
+}
+Q_DECLARE_JNI_NATIVE_METHOD(onCaptureSessionFailed)
+
+bool QAndroidCamera::registerNativeMethods()
+{
+ static const bool registered = []() {
+ return QJniEnvironment().registerNativeMethods(
+ QtJniTypes::Traits<QtJniTypes::QtCamera2>::className(),
+ {
+ Q_JNI_NATIVE_METHOD(onCameraOpened),
+ Q_JNI_NATIVE_METHOD(onCameraDisconnect),
+ Q_JNI_NATIVE_METHOD(onCameraError),
+ Q_JNI_NATIVE_METHOD(onCaptureSessionConfigured),
+ Q_JNI_NATIVE_METHOD(onCaptureSessionConfigureFailed),
+ Q_JNI_NATIVE_METHOD(onCaptureSessionFailed),
+ Q_JNI_NATIVE_METHOD(onFrameAvailable),
+ Q_JNI_NATIVE_METHOD(onPhotoAvailable),
+ Q_JNI_NATIVE_METHOD(onSessionActive),
+ Q_JNI_NATIVE_METHOD(onSessionClosed),
+ });
+ }();
+ return registered;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qandroidcamera_p.h b/src/plugins/multimedia/ffmpeg/qandroidcamera_p.h
new file mode 100644
index 000000000..26606a7e0
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qandroidcamera_p.h
@@ -0,0 +1,91 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDCAMERA_H
+#define QANDROIDCAMERA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpeghwaccel_p.h"
+#include <private/qplatformcamera_p.h>
+#include <QObject>
+#include <QJniObject>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoFrame;
+
+class QAndroidCamera : public QPlatformCamera
+{
+ Q_OBJECT
+public:
+ enum State { Closed, WaitingOpen, WaitingStart, Started };
+ explicit QAndroidCamera(QCamera *camera);
+ ~QAndroidCamera() override;
+
+ bool isActive() const override { return m_state == State::Started; }
+ bool isFlashModeSupported(QCamera::FlashMode mode) const override;
+ bool isFlashReady() const override;
+ bool isTorchModeSupported(QCamera::TorchMode mode) const override;
+ void setActive(bool active) override;
+ void setCamera(const QCameraDevice &camera) override;
+ bool setCameraFormat(const QCameraFormat &format) override;
+ void setFlashMode(QCamera::FlashMode mode) override;
+ void setTorchMode(QCamera::TorchMode mode) override;
+ void zoomTo(float factor, float rate) override;
+
+ std::optional<int> ffmpegHWPixelFormat() const override;
+
+ static bool registerNativeMethods();
+
+ void capture();
+ void updateExif(const QString &filename);
+public slots:
+ void onApplicationStateChanged();
+ void onCameraOpened();
+ void onCameraDisconnect();
+ void onCameraError(int error);
+ void frameAvailable(QJniObject image, bool takePhoto = false);
+ void onCaptureSessionConfigured();
+ void onCaptureSessionConfigureFailed();
+ void onCaptureSessionFailed(int reason, long frameNumber);
+ void onSessionActive();
+ void onSessionClosed();
+
+Q_SIGNALS:
+ void onCaptured(const QVideoFrame&);
+
+private:
+ bool isActivating() const { return m_state != State::Closed; }
+
+ void setState(State newState);
+ QtVideo::Rotation rotation();
+ void updateCameraCharacteristics();
+ void cleanCameraCharacteristics();
+
+ State m_state = State::Closed;
+ QCameraDevice m_cameraDevice;
+ long lastTimestamp = 0;
+ QJniObject m_jniCamera;
+
+ std::unique_ptr<QFFmpeg::HWAccel> m_hwAccel;
+
+ QVideoFrameFormat::PixelFormat m_androidFramePixelFormat;
+ QList<QCamera::FlashMode> m_supportedFlashModes;
+ bool m_waitingForFirstFrame = false;
+ bool m_TorchModeSupported = false;
+ bool m_wasActive = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDCAMERA_H
diff --git a/src/plugins/multimedia/ffmpeg/qandroidcameraframe.cpp b/src/plugins/multimedia/ffmpeg/qandroidcameraframe.cpp
new file mode 100644
index 000000000..28d02b20e
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qandroidcameraframe.cpp
@@ -0,0 +1,224 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidcameraframe_p.h"
+#include <jni.h>
+#include <QDebug>
+#include <QtCore/qjnitypes.h>
+#include <QtCore/QLoggingCategory>
+
+Q_DECLARE_JNI_CLASS(AndroidImageFormat, "android/graphics/ImageFormat");
+
+Q_DECLARE_JNI_CLASS(AndroidImage, "android/media/Image")
+Q_DECLARE_JNI_TYPE(AndroidImagePlaneArray, "[Landroid/media/Image$Plane;")
+Q_DECLARE_JNI_CLASS(JavaByteBuffer, "java/nio/ByteBuffer")
+Q_DECLARE_JNI_CLASS(QtVideoDeviceManager,
+ "org/qtproject/qt/android/multimedia/QtVideoDeviceManager");
+
+QT_BEGIN_NAMESPACE
+static Q_LOGGING_CATEGORY(qLCAndroidCameraFrame, "qt.multimedia.ffmpeg.android.camera.frame");
+
+namespace {
+bool isWorkaroundForEmulatorNeeded() {
+ const static bool workaroundForEmulator
+ = QtJniTypes::QtVideoDeviceManager::callStaticMethod<jboolean>("isEmulator");
+ return workaroundForEmulator;
+}
+}
+
+bool QAndroidCameraFrame::parse(const QJniObject &frame)
+{
+ QJniEnvironment jniEnv;
+
+ if (!frame.isValid())
+ return false;
+
+ auto planes = frame.callMethod<QtJniTypes::AndroidImagePlaneArray>("getPlanes");
+ if (!planes.isValid())
+ return false;
+
+ int numberPlanes = jniEnv->GetArrayLength(planes.object<jarray>());
+ // create and populate temporary array structure
+ int pixelStrides[numberPlanes];
+ int rowStrides[numberPlanes];
+ int bufferSize[numberPlanes];
+ uint8_t *buffer[numberPlanes];
+
+ auto resetPlane = [&](int index) {
+ if (index < 0 || index > numberPlanes)
+ return;
+
+ rowStrides[index] = 0;
+ pixelStrides[index] = 0;
+ bufferSize[index] = 0;
+ buffer[index] = nullptr;
+ };
+
+ for (int index = 0; index < numberPlanes; index++) {
+ QJniObject plane = jniEnv->GetObjectArrayElement(planes.object<jobjectArray>(), index);
+ if (jniEnv.checkAndClearExceptions() || !plane.isValid()) {
+ resetPlane(index);
+ continue;
+ }
+
+ rowStrides[index] = plane.callMethod<jint>("getRowStride");
+ pixelStrides[index] = plane.callMethod<jint>("getPixelStride");
+
+ auto byteBuffer = plane.callMethod<QtJniTypes::JavaByteBuffer>("getBuffer");
+ if (!byteBuffer.isValid()) {
+ resetPlane(index);
+ continue;
+ }
+
+ // Uses direct access which is garanteed by android to work with
+ // ImageReader bytebuffer
+ buffer[index] = static_cast<uint8_t *>(jniEnv->GetDirectBufferAddress(byteBuffer.object()));
+ bufferSize[index] = byteBuffer.callMethod<jint>("remaining");
+ }
+
+ QVideoFrameFormat::PixelFormat calculedPixelFormat = QVideoFrameFormat::Format_Invalid;
+
+ // finding the image format
+ // the ImageFormats that can happen here are stated here:
+ // https://developer.android.com/reference/android/media/Image#getFormat()
+ int format = frame.callMethod<jint>("getFormat");
+ AndroidImageFormat imageFormat = AndroidImageFormat(format);
+
+ switch (imageFormat) {
+ case AndroidImageFormat::JPEG:
+ calculedPixelFormat = QVideoFrameFormat::Format_Jpeg;
+ break;
+ case AndroidImageFormat::YUV_420_888:
+ if (numberPlanes < 3) {
+ // something went wrong on parsing. YUV_420_888 format must always have 3 planes
+ calculedPixelFormat = QVideoFrameFormat::Format_Invalid;
+ break;
+ }
+ if (pixelStrides[1] == 1)
+ calculedPixelFormat = QVideoFrameFormat::Format_YUV420P;
+ else if (pixelStrides[1] == 2 && abs(buffer[1] - buffer[2]) == 1)
+ // this can be NV21, but it will converted below
+ calculedPixelFormat = QVideoFrameFormat::Format_NV12;
+ break;
+ case AndroidImageFormat::HEIC:
+ // QImage cannot parse HEIC
+ calculedPixelFormat = QVideoFrameFormat::Format_Invalid;
+ break;
+ case AndroidImageFormat::RAW_PRIVATE:
+ case AndroidImageFormat::RAW_SENSOR:
+ // we cannot know raw formats
+ calculedPixelFormat = QVideoFrameFormat::Format_Invalid;
+ break;
+ case AndroidImageFormat::FLEX_RGBA_8888:
+ case AndroidImageFormat::FLEX_RGB_888:
+ // these formats are only returned by Mediacodec.getOutputImage, they are not used as a
+ // Camera2 Image frame return
+ calculedPixelFormat = QVideoFrameFormat::Format_Invalid;
+ break;
+ case AndroidImageFormat::YUV_422_888:
+ case AndroidImageFormat::YUV_444_888:
+ case AndroidImageFormat::YCBCR_P010:
+ // not dealing with these formats, they require higher API levels than the current Qt min
+ calculedPixelFormat = QVideoFrameFormat::Format_Invalid;
+ break;
+ default:
+ calculedPixelFormat = QVideoFrameFormat::Format_Invalid;
+ break;
+ }
+
+ if (calculedPixelFormat == QVideoFrameFormat::Format_Invalid) {
+ qCWarning(qLCAndroidCameraFrame) << "Cannot determine image format!";
+ return false;
+ }
+
+ auto copyPlane = [&](int mapIndex, int arrayIndex) {
+ if (arrayIndex >= numberPlanes)
+ return;
+
+ m_planes[mapIndex].rowStride = rowStrides[arrayIndex];
+ m_planes[mapIndex].size = bufferSize[arrayIndex];
+ m_planes[mapIndex].data = buffer[arrayIndex];
+ };
+
+ int width = frame.callMethod<jint>("getWidth");
+ int height = frame.callMethod<jint>("getHeight");
+ m_size = QSize(width, height);
+
+ switch (calculedPixelFormat) {
+ case QVideoFrameFormat::Format_YUV420P:
+ m_numberPlanes = 3;
+ copyPlane(0, 0);
+ copyPlane(1, 1);
+ copyPlane(2, 2);
+
+ if (isWorkaroundForEmulatorNeeded()) {
+ for (int i = 0; i < 3; ++i) {
+ const int dataSize = (i == 0) ? width * height : width * height / 4;
+ m_planes[i].data = new uint8_t[dataSize];
+ memcpy(m_planes[i].data, buffer[i], dataSize);
+ }
+ }
+
+ m_pixelFormat = QVideoFrameFormat::Format_YUV420P;
+ break;
+ case QVideoFrameFormat::Format_NV12:
+ m_numberPlanes = 2;
+ copyPlane(0, 0);
+ copyPlane(1, 1);
+ m_pixelFormat = QVideoFrameFormat::Format_NV12;
+ break;
+ case QVideoFrameFormat::Format_Jpeg:
+ qCWarning(qLCAndroidCameraFrame)
+ << "FFmpeg HW Mediacodec does not encode other than YCbCr formats";
+ // we still parse it to preview the frame
+ m_image = QImage::fromData(buffer[0], bufferSize[0]);
+ m_planes[0].rowStride = m_image.bytesPerLine();
+ m_planes[0].size = m_image.sizeInBytes();
+ m_planes[0].data = m_image.bits();
+ m_pixelFormat = QVideoFrameFormat::pixelFormatFromImageFormat(m_image.format());
+ break;
+ default:
+ break;
+ }
+
+ long timestamp = frame.callMethod<jlong>("getTimestamp");
+ m_timestamp = timestamp / 1000;
+
+ return true;
+}
+
+QAndroidCameraFrame::QAndroidCameraFrame(QJniObject frame)
+ : m_pixelFormat(QVideoFrameFormat::Format_Invalid), m_parsed(parse(frame))
+{
+ if (isParsed()) {
+ // holding the frame java object
+ QJniEnvironment jniEnv;
+ m_frame = jniEnv->NewGlobalRef(frame.object());
+ jniEnv.checkAndClearExceptions();
+ } else if (frame.isValid()) {
+ frame.callMethod<void>("close");
+ }
+}
+
+QAndroidCameraFrame::~QAndroidCameraFrame()
+{
+ if (!isParsed()) // nothing to clean
+ return;
+
+ QJniObject qFrame(m_frame);
+ if (qFrame.isValid())
+ qFrame.callMethod<void>("close");
+
+ QJniEnvironment jniEnv;
+ if (m_frame)
+ jniEnv->DeleteGlobalRef(m_frame);
+
+ if (isWorkaroundForEmulatorNeeded()) {
+ if (m_pixelFormat == QVideoFrameFormat::Format_YUV420P) {
+ for (int i = 0; i < 3; ++i)
+ delete[] m_planes[i].data;
+ }
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qandroidcameraframe_p.h b/src/plugins/multimedia/ffmpeg/qandroidcameraframe_p.h
new file mode 100644
index 000000000..23a737f7d
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qandroidcameraframe_p.h
@@ -0,0 +1,75 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDCAMERAFRAME_H
+#define QANDROIDCAMERAFRAME_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QVideoFrameFormat>
+#include <QJniObject>
+
+class QAndroidCameraFrame
+{
+public:
+ struct Plane
+ {
+ int pixelStride = 0;
+ int rowStride = 0;
+ int size = 0;
+ uint8_t *data;
+ };
+
+ QAndroidCameraFrame(QJniObject frame);
+ ~QAndroidCameraFrame();
+
+ QVideoFrameFormat::PixelFormat format() const { return m_pixelFormat; }
+ int numberPlanes() const { return m_numberPlanes; }
+ Plane plane(int index) const
+ {
+ if (index < 0 || index > numberPlanes())
+ return {};
+
+ return m_planes[index];
+ }
+ QSize size() const { return m_size; }
+ long timestamp() const { return m_timestamp; }
+
+ bool isParsed() const { return m_parsed; }
+
+private:
+ bool parse(const QJniObject &frame);
+ QVideoFrameFormat::PixelFormat m_pixelFormat;
+
+ QSize m_size = {};
+ long m_timestamp = 0;
+ int m_numberPlanes = 0;
+ Plane m_planes[3]; // 3 max number planes
+ jobject m_frame = nullptr;
+ bool m_parsed = false;
+ QImage m_image;
+
+ enum AndroidImageFormat {
+ RAW_SENSOR = 32,
+ YUV_420_888 = 35,
+ RAW_PRIVATE = 36,
+ YUV_422_888 = 39,
+ YUV_444_888 = 40,
+ FLEX_RGB_888 = 41,
+ FLEX_RGBA_8888 = 42,
+ YCBCR_P010 = 54,
+ JPEG = 256,
+ HEIC = 1212500294
+ };
+};
+
+#endif // QANDROIDCAMERAFRAME_H
diff --git a/src/plugins/multimedia/ffmpeg/qandroidimagecapture.cpp b/src/plugins/multimedia/ffmpeg/qandroidimagecapture.cpp
new file mode 100644
index 000000000..ed0f2de9d
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qandroidimagecapture.cpp
@@ -0,0 +1,46 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidimagecapture_p.h"
+#include <qandroidcamera_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QAndroidImageCapture::QAndroidImageCapture(QImageCapture *parent)
+ : QFFmpegImageCapture(parent)
+{
+ connect(this, &QPlatformImageCapture::imageSaved, this, &QAndroidImageCapture::updateExif);
+}
+
+QAndroidImageCapture::~QAndroidImageCapture()
+{
+}
+
+int QAndroidImageCapture::doCapture(const QString &fileName)
+{
+ auto ret = QFFmpegImageCapture::doCapture(fileName);
+ if (ret >= 0) {
+ auto androidCamera = qobject_cast<QAndroidCamera *>(videoSource());
+ if (androidCamera)
+ androidCamera->capture();
+ }
+
+ return ret;
+}
+
+void QAndroidImageCapture::setupVideoSourceConnections()
+{
+ auto androidCamera = qobject_cast<QAndroidCamera *>(videoSource());
+ if (androidCamera)
+ connect(androidCamera, &QAndroidCamera::onCaptured, this, &QAndroidImageCapture::newVideoFrame);
+ else
+ QFFmpegImageCapture::setupVideoSourceConnections();
+}
+
+void QAndroidImageCapture::updateExif(int id, const QString &filename)
+{
+ Q_UNUSED(id);
+ auto androidCamera = qobject_cast<QAndroidCamera *>(videoSource());
+ if (androidCamera)
+ androidCamera->updateExif(filename);
+}
diff --git a/src/plugins/multimedia/ffmpeg/qandroidimagecapture_p.h b/src/plugins/multimedia/ffmpeg/qandroidimagecapture_p.h
new file mode 100644
index 000000000..8a997b595
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qandroidimagecapture_p.h
@@ -0,0 +1,38 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QANDROIDIMAGECAPTURE_H
+#define QANDROIDIMAGECAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpegimagecapture_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QAndroidImageCapture : public QFFmpegImageCapture
+{
+public:
+ QAndroidImageCapture(QImageCapture *parent);
+ ~QAndroidImageCapture() override;
+
+protected:
+ void setupVideoSourceConnections() override;
+ int doCapture(const QString &fileName) override;
+
+private slots:
+ void updateExif(int id, const QString &filename);
+};
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDIMAGECAPTURE_H
diff --git a/src/plugins/multimedia/ffmpeg/qandroidvideodevices.cpp b/src/plugins/multimedia/ffmpeg/qandroidvideodevices.cpp
new file mode 100644
index 000000000..fd4221d55
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qandroidvideodevices.cpp
@@ -0,0 +1,150 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qandroidvideodevices_p.h"
+
+#include <private/qcameradevice_p.h>
+
+#include <QtCore/QLoggingCategory>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/private/qandroidextras_p.h>
+#include <QtCore/qcoreapplication_platform.h>
+#include <QJniEnvironment>
+#include <jni.h>
+
+static Q_LOGGING_CATEGORY(qLCAndroidVideoDevices, "qt.multimedia.ffmpeg.android.videoDevices")
+
+Q_DECLARE_JNI_CLASS(QtVideoDeviceManager,
+ "org/qtproject/qt/android/multimedia/QtVideoDeviceManager");
+Q_DECLARE_JNI_TYPE(StringArray, "[Ljava/lang/String;")
+Q_DECLARE_JNI_CLASS(AndroidImageFormat, "android/graphics/ImageFormat");
+
+QCameraFormat createCameraFormat(int width, int height, int fpsMin, int fpsMax)
+{
+ QCameraFormatPrivate *format = new QCameraFormatPrivate();
+
+ format->resolution = { width, height };
+
+ format->minFrameRate = fpsMin;
+ format->maxFrameRate = fpsMax;
+
+ format->pixelFormat = QVideoFrameFormat::PixelFormat::Format_YUV420P;
+
+ return format->create();
+}
+
+QList<QCameraDevice> QAndroidVideoDevices::findVideoDevices()
+{
+ QList<QCameraDevice> devices;
+
+ QJniObject deviceManager(QtJniTypes::Traits<QtJniTypes::QtVideoDeviceManager>::className(),
+ QNativeInterface::QAndroidApplication::context());
+
+ if (!deviceManager.isValid()) {
+ qCWarning(qLCAndroidVideoDevices) << "Failed to connect to Qt Video Device Manager.";
+ return devices;
+ }
+
+ QJniObject cameraIdList = deviceManager.callMethod<QtJniTypes::StringArray>("getCameraIdList");
+
+ QJniEnvironment jniEnv;
+ int numCameras = jniEnv->GetArrayLength(cameraIdList.object<jarray>());
+ if (jniEnv.checkAndClearExceptions())
+ return devices;
+
+ for (int cameraIndex = 0; cameraIndex < numCameras; cameraIndex++) {
+
+ QJniObject cameraIdObject =
+ jniEnv->GetObjectArrayElement(cameraIdList.object<jobjectArray>(), cameraIndex);
+ if (jniEnv.checkAndClearExceptions())
+ continue;
+
+ jstring cameraId = cameraIdObject.object<jstring>();
+
+ QCameraDevicePrivate *info = new QCameraDevicePrivate;
+ info->id = cameraIdObject.toString().toUtf8();
+
+ info->orientation = deviceManager.callMethod<jint>("getSensorOrientation", cameraId);
+
+ int facing = deviceManager.callMethod<jint>("getLensFacing", cameraId);
+
+ const int LENS_FACING_FRONT = 0;
+ const int LENS_FACING_BACK = 1;
+ const int LENS_FACING_EXTERNAL = 2;
+
+ switch (facing) {
+ case LENS_FACING_EXTERNAL:
+ case LENS_FACING_BACK:
+ info->position = QCameraDevice::BackFace;
+ info->description = QString("Rear Camera: %1").arg(cameraIndex);
+ break;
+ case LENS_FACING_FRONT:
+ info->position = QCameraDevice::FrontFace;
+ info->description = QString("Front Camera: %1").arg(cameraIndex);
+ break;
+ }
+
+ QJniObject fpsRangesObject =
+ deviceManager.callMethod<QtJniTypes::StringArray>("getFpsRange", cameraId);
+ jobjectArray fpsRanges = fpsRangesObject.object<jobjectArray>();
+
+ int numRanges = jniEnv->GetArrayLength(fpsRanges);
+ if (jniEnv.checkAndClearExceptions())
+ continue;
+
+ int maxFps = 0, minFps = 0;
+
+ for (int rangeIndex = 0; rangeIndex < numRanges; rangeIndex++) {
+
+ QJniObject rangeString = jniEnv->GetObjectArrayElement(fpsRanges, rangeIndex);
+ if (jniEnv.checkAndClearExceptions())
+ continue;
+
+ QString range = rangeString.toString();
+
+ range = range.remove("[");
+ range = range.remove("]");
+
+ auto split = range.split(",");
+
+ int min = split[0].toInt();
+ int max = split[1].toInt();
+
+ if (max > maxFps) {
+ maxFps = max;
+ minFps = min;
+ }
+ }
+
+ const static int imageFormat =
+ QJniObject::getStaticField<QtJniTypes::AndroidImageFormat, jint>("YUV_420_888");
+
+ QJniObject sizesObject = deviceManager.callMethod<QtJniTypes::StringArray>(
+ "getStreamConfigurationsSizes", cameraId, imageFormat);
+
+ jobjectArray streamSizes = sizesObject.object<jobjectArray>();
+ int numSizes = jniEnv->GetArrayLength(streamSizes);
+ if (jniEnv.checkAndClearExceptions())
+ continue;
+
+ for (int sizesIndex = 0; sizesIndex < numSizes; sizesIndex++) {
+
+ QJniObject sizeStringObject = jniEnv->GetObjectArrayElement(streamSizes, sizesIndex);
+ if (jniEnv.checkAndClearExceptions())
+ continue;
+
+ QString sizeString = sizeStringObject.toString();
+
+ auto split = sizeString.split("x");
+
+ int width = split[0].toInt();
+ int height = split[1].toInt();
+
+ info->videoFormats.append(createCameraFormat(width, height, minFps, maxFps));
+ }
+
+ devices.push_back(info->create());
+ }
+
+ return devices;
+}
diff --git a/src/plugins/multimedia/ffmpeg/qandroidvideodevices_p.h b/src/plugins/multimedia/ffmpeg/qandroidvideodevices_p.h
new file mode 100644
index 000000000..f89ea7f05
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qandroidvideodevices_p.h
@@ -0,0 +1,35 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFANDROIDVIDEODEVICES_H
+#define QFANDROIDVIDEODEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QObject>
+#include <private/qplatformvideodevices_p.h>
+
+class QAndroidVideoDevices : public QPlatformVideoDevices
+{
+ Q_OBJECT
+public:
+ QAndroidVideoDevices(QPlatformMediaIntegration *integration)
+ : QPlatformVideoDevices(integration), m_videoDevices(findVideoDevices()){};
+
+ QList<QCameraDevice> videoDevices() const override { return m_videoDevices; }
+
+private:
+ QList<QCameraDevice> findVideoDevices();
+ QList<QCameraDevice> m_videoDevices;
+};
+
+#endif // QFANDROIDVIDEODEVICES_H
diff --git a/src/plugins/multimedia/ffmpeg/qavfcamera.mm b/src/plugins/multimedia/ffmpeg/qavfcamera.mm
new file mode 100644
index 000000000..38b743e65
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qavfcamera.mm
@@ -0,0 +1,345 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include <qavfcamera_p.h>
+#include <qpointer.h>
+#include <qmediacapturesession.h>
+#include <private/qplatformmediacapture_p.h>
+#include "avfcamerautility_p.h"
+#include "qavfhelpers_p.h"
+#include "avfcameradebug_p.h"
+#include "qavfsamplebufferdelegate_p.h"
+#include <qvideosink.h>
+#include <rhi/qrhi.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qpermissions.h>
+#define AVMediaType XAVMediaType
+#include "qffmpegvideobuffer_p.h"
+#include "qffmpegvideosink_p.h"
+extern "C" {
+#include <libavutil/hwcontext_videotoolbox.h>
+#include <libavutil/hwcontext.h>
+}
+#undef AVMediaType
+
+QT_BEGIN_NAMESPACE
+
+using namespace QFFmpeg;
+
+QAVFCamera::QAVFCamera(QCamera *parent)
+ : QAVFCameraBase(parent)
+{
+ m_captureSession = [[AVCaptureSession alloc] init];
+ m_sampleBufferDelegate = [[QAVFSampleBufferDelegate alloc]
+ initWithFrameHandler:[this](const QVideoFrame &frame) { syncHandleFrame(frame); }];
+}
+
+QAVFCamera::~QAVFCamera()
+{
+ [m_sampleBufferDelegate release];
+ [m_videoInput release];
+ [m_videoDataOutput release];
+ [m_captureSession release];
+}
+
+bool QAVFCamera::checkCameraPermission()
+{
+ const QCameraPermission permission;
+ const bool granted = qApp->checkPermission(permission) == Qt::PermissionStatus::Granted;
+ if (!granted)
+ qWarning() << "Access to camera not granted";
+
+ return granted;
+}
+
+void QAVFCamera::updateVideoInput()
+{
+ if (!checkCameraPermission())
+ return;
+
+ [m_captureSession beginConfiguration];
+
+ attachVideoInputDevice();
+
+ if (!m_videoDataOutput) {
+ m_videoDataOutput = [[AVCaptureVideoDataOutput alloc] init];
+
+ // Configure video output
+ m_delegateQueue = dispatch_queue_create("vf_queue", nullptr);
+ [m_videoDataOutput
+ setSampleBufferDelegate:m_sampleBufferDelegate
+ queue:m_delegateQueue];
+
+ [m_captureSession addOutput:m_videoDataOutput];
+ }
+ [m_captureSession commitConfiguration];
+ deviceOrientationChanged();
+}
+
+void QAVFCamera::deviceOrientationChanged(int angle)
+{
+ AVCaptureConnection *connection = [m_videoDataOutput connectionWithMediaType:AVMediaTypeVideo];
+ if (connection == nil || !m_videoDataOutput)
+ return;
+
+ if (!connection.supportsVideoOrientation)
+ return;
+
+ if (angle < 0)
+ angle = m_orientationHandler.currentOrientation();
+
+ AVCaptureVideoOrientation orientation = AVCaptureVideoOrientationPortrait;
+ switch (angle) {
+ default:
+ break;
+ case 90:
+ orientation = AVCaptureVideoOrientationLandscapeRight;
+ break;
+ case 180:
+ // this keeps the last orientation, don't do anything
+ return;
+ case 270:
+ orientation = AVCaptureVideoOrientationLandscapeLeft;
+ break;
+ }
+
+ connection.videoOrientation = orientation;
+}
+
+void QAVFCamera::attachVideoInputDevice()
+{
+ if (m_videoInput) {
+ [m_captureSession removeInput:m_videoInput];
+ [m_videoInput release];
+ m_videoInput = nullptr;
+ }
+
+ QByteArray deviceId = m_cameraDevice.id();
+ if (deviceId.isEmpty())
+ return;
+
+ AVCaptureDevice *videoDevice = [AVCaptureDevice deviceWithUniqueID:
+ [NSString stringWithUTF8String: deviceId.constData()]];
+
+ if (!videoDevice)
+ return;
+
+ m_videoInput = [AVCaptureDeviceInput
+ deviceInputWithDevice:videoDevice
+ error:nil];
+ if (m_videoInput && [m_captureSession canAddInput:m_videoInput]) {
+ [m_videoInput retain];
+ [m_captureSession addInput:m_videoInput];
+ } else {
+ qWarning() << "Failed to create video device input";
+ }
+}
+
+AVCaptureDevice *QAVFCamera::device() const
+{
+ return m_videoInput ? m_videoInput.device : nullptr;
+}
+
+bool QAVFCamera::isActive() const
+{
+ return m_active;
+}
+
+void QAVFCamera::setActive(bool active)
+{
+ if (m_active == active)
+ return;
+ if (!checkCameraPermission())
+ return;
+
+ m_active = active;
+
+ if (active) {
+ // According to the doc, the capture device must be locked before
+ // startRunning to prevent the format we set to be overridden by the
+ // session preset.
+ [m_videoInput.device lockForConfiguration:nil];
+ [m_captureSession startRunning];
+ [m_videoInput.device unlockForConfiguration];
+ } else {
+ [m_captureSession stopRunning];
+ }
+
+ emit activeChanged(active);
+}
+
+void QAVFCamera::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ m_session = session ? session->captureSession() : nullptr;
+}
+
+void QAVFCamera::setCamera(const QCameraDevice &camera)
+{
+ if (m_cameraDevice == camera)
+ return;
+
+ m_cameraDevice = camera;
+
+ if (checkCameraPermission())
+ updateVideoInput();
+ setCameraFormat({});
+}
+
+bool QAVFCamera::setCameraFormat(const QCameraFormat &format)
+{
+ if (m_cameraFormat == format && !format.isNull())
+ return true;
+
+ if (!QAVFCameraBase::setCameraFormat(format))
+ return false;
+
+ updateCameraFormat();
+ return true;
+}
+
+void QAVFCamera::updateCameraFormat()
+{
+ m_framePixelFormat = QVideoFrameFormat::Format_Invalid;
+
+ AVCaptureDevice *captureDevice = device();
+ if (!captureDevice)
+ return;
+
+ AVCaptureDeviceFormat *newFormat = qt_convert_to_capture_device_format(
+ captureDevice, m_cameraFormat, &isCVFormatSupported);
+
+ if (!newFormat)
+ newFormat = qt_convert_to_capture_device_format(captureDevice, m_cameraFormat);
+
+ std::uint32_t cvPixelFormat = 0;
+ if (newFormat) {
+ qt_set_active_format(captureDevice, newFormat, false);
+ const auto captureDeviceCVFormat =
+ CMVideoFormatDescriptionGetCodecType(newFormat.formatDescription);
+ cvPixelFormat = setPixelFormat(m_cameraFormat.pixelFormat(), captureDeviceCVFormat);
+ if (captureDeviceCVFormat != cvPixelFormat) {
+ qCWarning(qLcCamera) << "Output CV format differs with capture device format!"
+ << cvPixelFormat << cvFormatToString(cvPixelFormat) << "vs"
+ << captureDeviceCVFormat
+ << cvFormatToString(captureDeviceCVFormat);
+
+ m_framePixelFormat = QAVFHelpers::fromCVPixelFormat(cvPixelFormat);
+ }
+ } else {
+ qWarning() << "Cannot find AVCaptureDeviceFormat; Did you use format from another camera?";
+ }
+
+ const AVPixelFormat avPixelFormat = av_map_videotoolbox_format_to_pixfmt(cvPixelFormat);
+
+ std::unique_ptr<HWAccel> hwAccel;
+
+ if (avPixelFormat == AV_PIX_FMT_NONE) {
+ qCWarning(qLcCamera) << "Videotoolbox doesn't support cvPixelFormat:" << cvPixelFormat
+ << cvFormatToString(cvPixelFormat)
+ << "Camera pix format:" << m_cameraFormat.pixelFormat();
+ } else {
+ hwAccel = HWAccel::create(AV_HWDEVICE_TYPE_VIDEOTOOLBOX);
+ qCDebug(qLcCamera) << "Create VIDEOTOOLBOX hw context" << hwAccel.get() << "for camera";
+ }
+
+ if (hwAccel) {
+ hwAccel->createFramesContext(avPixelFormat, adjustedResolution());
+ m_hwPixelFormat = hwAccel->hwFormat();
+ } else {
+ m_hwPixelFormat = AV_PIX_FMT_NONE;
+ }
+
+ [m_sampleBufferDelegate setHWAccel:std::move(hwAccel)];
+ [m_sampleBufferDelegate setVideoFormatFrameRate:m_cameraFormat.maxFrameRate()];
+}
+
+uint32_t QAVFCamera::setPixelFormat(QVideoFrameFormat::PixelFormat cameraPixelFormat,
+ uint32_t inputCvPixFormat)
+{
+ auto bestScore = MinAVScore;
+ NSNumber *bestFormat = nullptr;
+ for (NSNumber *cvPixFmtNumber in m_videoDataOutput.availableVideoCVPixelFormatTypes) {
+ auto cvPixFmt = [cvPixFmtNumber unsignedIntValue];
+ const auto pixFmt = QAVFHelpers::fromCVPixelFormat(cvPixFmt);
+ if (pixFmt == QVideoFrameFormat::Format_Invalid)
+ continue;
+
+ auto score = DefaultAVScore;
+ if (cvPixFmt == inputCvPixFormat)
+ score += 100;
+ if (pixFmt == cameraPixelFormat)
+ score += 10;
+ // if (cvPixFmt == kCVPixelFormatType_32BGRA)
+ // score += 1;
+
+ // This flag determines priorities of using ffmpeg hw frames or
+ // the exact camera format match.
+ // Maybe configure more, e.g. by some env var?
+ constexpr bool ShouldSuppressNotSupportedByFFmpeg = false;
+
+ if (!isCVFormatSupported(cvPixFmt))
+ score -= ShouldSuppressNotSupportedByFFmpeg ? 100000 : 5;
+
+ // qDebug() << "----FMT:" << pixFmt << cvPixFmt << score;
+
+ if (score > bestScore) {
+ bestScore = score;
+ bestFormat = cvPixFmtNumber;
+ }
+ }
+
+ if (!bestFormat) {
+ qWarning() << "QCamera::setCameraFormat: availableVideoCVPixelFormatTypes empty";
+ return 0;
+ }
+
+ if (bestScore < DefaultAVScore)
+ qWarning() << "QCamera::setCameraFormat: Cannot find hw FFmpeg supported cv pix format";
+
+ NSDictionary *outputSettings = @{
+ (NSString *)kCVPixelBufferPixelFormatTypeKey : bestFormat,
+ (NSString *)kCVPixelBufferMetalCompatibilityKey : @true
+ };
+ m_videoDataOutput.videoSettings = outputSettings;
+
+ return [bestFormat unsignedIntValue];
+}
+
+QSize QAVFCamera::adjustedResolution() const
+{
+ // Check, that we have matching dimesnions.
+ QSize resolution = m_cameraFormat.resolution();
+ AVCaptureConnection *connection = [m_videoDataOutput connectionWithMediaType:AVMediaTypeVideo];
+ if (!connection.supportsVideoOrientation)
+ return resolution;
+
+ // Either portrait but actually sizes of landscape, or
+ // landscape with dimensions of portrait - not what
+ // sample delegate will report (it depends on videoOrientation set).
+ const bool isPortraitOrientation = connection.videoOrientation == AVCaptureVideoOrientationPortrait;
+ const bool isPortraitResolution = resolution.height() > resolution.width();
+ if (isPortraitOrientation != isPortraitResolution)
+ resolution.transpose();
+
+ return resolution;
+}
+
+void QAVFCamera::syncHandleFrame(const QVideoFrame &frame)
+{
+ Q_EMIT newVideoFrame(frame);
+}
+
+std::optional<int> QAVFCamera::ffmpegHWPixelFormat() const
+{
+ return m_hwPixelFormat == AV_PIX_FMT_NONE ? std::optional<int>{} : m_hwPixelFormat;
+}
+
+int QAVFCamera::cameraPixelFormatScore(QVideoFrameFormat::PixelFormat pixelFormat,
+ QVideoFrameFormat::ColorRange colorRange) const
+{
+ auto cvFormat = QAVFHelpers::toCVPixelFormat(pixelFormat, colorRange);
+ return static_cast<int>(isCVFormatSupported(cvFormat));
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qavfcamera_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qavfcamera_p.h b/src/plugins/multimedia/ffmpeg/qavfcamera_p.h
new file mode 100644
index 000000000..0c88c520c
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qavfcamera_p.h
@@ -0,0 +1,90 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAVFCAMERA_H
+#define QAVFCAMERA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qavfcamerabase_p.h"
+#include <private/qplatformmediaintegration_p.h>
+#include <private/qvideooutputorientationhandler_p.h>
+#define AVMediaType XAVMediaType
+#include "qffmpeghwaccel_p.h"
+#undef AVMediaType
+
+#include <qfilesystemwatcher.h>
+#include <qsocketnotifier.h>
+#include <qmutex.h>
+
+#include <dispatch/dispatch.h>
+
+Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureSession);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureDeviceInput);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureVideoDataOutput);
+Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureDevice);
+Q_FORWARD_DECLARE_OBJC_CLASS(QAVFSampleBufferDelegate);
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegVideoSink;
+
+class QAVFCamera : public QAVFCameraBase
+{
+ Q_OBJECT
+
+public:
+ explicit QAVFCamera(QCamera *parent);
+ ~QAVFCamera();
+
+ bool isActive() const override;
+ void setActive(bool active) override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *) override;
+
+ void setCamera(const QCameraDevice &camera) override;
+ bool setCameraFormat(const QCameraFormat &format) override;
+
+ void syncHandleFrame(const QVideoFrame &frame);
+
+ void deviceOrientationChanged(int angle = -1);
+
+ std::optional<int> ffmpegHWPixelFormat() const override;
+
+ int cameraPixelFormatScore(QVideoFrameFormat::PixelFormat pixelFmt,
+ QVideoFrameFormat::ColorRange colorRange) const override;
+
+private:
+ bool checkCameraPermission();
+ void updateCameraFormat();
+ void updateVideoInput();
+ void attachVideoInputDevice();
+ uint32_t setPixelFormat(QVideoFrameFormat::PixelFormat pixelFormat, uint32_t inputCvPixFormat);
+ QSize adjustedResolution() const;
+
+ AVCaptureDevice *device() const;
+
+ QMediaCaptureSession *m_session = nullptr;
+ AVCaptureSession *m_captureSession = nullptr;
+ AVCaptureDeviceInput *m_videoInput = nullptr;
+ AVCaptureVideoDataOutput *m_videoDataOutput = nullptr;
+ QAVFSampleBufferDelegate *m_sampleBufferDelegate = nullptr;
+ dispatch_queue_t m_delegateQueue;
+ QVideoOutputOrientationHandler m_orientationHandler;
+ AVPixelFormat m_hwPixelFormat = AV_PIX_FMT_NONE;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QFFMPEGCAMERA_H
+
diff --git a/src/plugins/multimedia/ffmpeg/qavfsamplebufferdelegate.mm b/src/plugins/multimedia/ffmpeg/qavfsamplebufferdelegate.mm
new file mode 100644
index 000000000..8a4c77a9e
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qavfsamplebufferdelegate.mm
@@ -0,0 +1,224 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qavfsamplebufferdelegate_p.h"
+
+#define AVMediaType XAVMediaType
+
+#include "qffmpeghwaccel_p.h"
+#include "qavfhelpers_p.h"
+#include "qffmpegvideobuffer_p.h"
+#include "private/qvideoframe_p.h"
+
+#undef AVMediaType
+
+#include <optional>
+
+QT_USE_NAMESPACE
+
+static void releaseHwFrame(void * /*opaque*/, uint8_t *data)
+{
+ CVPixelBufferRelease(CVPixelBufferRef(data));
+}
+
+namespace {
+
+class CVImageVideoBuffer : public QAbstractVideoBuffer
+{
+public:
+ CVImageVideoBuffer(CVImageBufferRef imageBuffer) : m_buffer(imageBuffer)
+ {
+ CVPixelBufferRetain(imageBuffer);
+ }
+
+ ~CVImageVideoBuffer()
+ {
+ CVImageVideoBuffer::unmap();
+ CVPixelBufferRelease(m_buffer);
+ }
+
+ CVImageVideoBuffer::MapData map(QtVideo::MapMode mode) override
+ {
+ MapData mapData;
+
+ if (m_mode == QtVideo::MapMode::NotMapped) {
+ CVPixelBufferLockBaseAddress(
+ m_buffer, mode == QtVideo::MapMode::ReadOnly ? kCVPixelBufferLock_ReadOnly : 0);
+ m_mode = mode;
+ }
+
+ mapData.planeCount = CVPixelBufferGetPlaneCount(m_buffer);
+ Q_ASSERT(mapData.planeCount <= 3);
+
+ if (!mapData.planeCount) {
+ // single plane
+ mapData.bytesPerLine[0] = CVPixelBufferGetBytesPerRow(m_buffer);
+ mapData.data[0] = static_cast<uchar *>(CVPixelBufferGetBaseAddress(m_buffer));
+ mapData.dataSize[0] = CVPixelBufferGetDataSize(m_buffer);
+ mapData.planeCount = mapData.data[0] ? 1 : 0;
+ return mapData;
+ }
+
+ // For a bi-planar or tri-planar format we have to set the parameters correctly:
+ for (int i = 0; i < mapData.planeCount; ++i) {
+ mapData.bytesPerLine[i] = CVPixelBufferGetBytesPerRowOfPlane(m_buffer, i);
+ mapData.dataSize[i] = mapData.bytesPerLine[i] * CVPixelBufferGetHeightOfPlane(m_buffer, i);
+ mapData.data[i] = static_cast<uchar *>(CVPixelBufferGetBaseAddressOfPlane(m_buffer, i));
+ }
+
+ return mapData;
+ }
+
+ void unmap() override
+ {
+ if (m_mode != QtVideo::MapMode::NotMapped) {
+ CVPixelBufferUnlockBaseAddress(
+ m_buffer, m_mode == QtVideo::MapMode::ReadOnly ? kCVPixelBufferLock_ReadOnly : 0);
+ m_mode = QtVideo::MapMode::NotMapped;
+ }
+ }
+
+ QVideoFrameFormat format() const override { return {}; }
+
+private:
+ CVImageBufferRef m_buffer;
+ QtVideo::MapMode m_mode = QtVideo::MapMode::NotMapped;
+};
+
+}
+
+// Make sure this is compatible with the layout used in ffmpeg's hwcontext_videotoolbox
+static QFFmpeg::AVFrameUPtr allocHWFrame(AVBufferRef *hwContext, const CVPixelBufferRef &pixbuf)
+{
+ AVHWFramesContext *ctx = (AVHWFramesContext *)hwContext->data;
+ auto frame = QFFmpeg::makeAVFrame();
+ frame->hw_frames_ctx = av_buffer_ref(hwContext);
+ frame->extended_data = frame->data;
+
+ frame->buf[0] = av_buffer_create((uint8_t *)pixbuf, 1, releaseHwFrame, NULL, 0);
+ frame->data[3] = (uint8_t *)pixbuf;
+ CVPixelBufferRetain(pixbuf);
+ frame->width = ctx->width;
+ frame->height = ctx->height;
+ frame->format = AV_PIX_FMT_VIDEOTOOLBOX;
+ if (frame->width != (int)CVPixelBufferGetWidth(pixbuf)
+ || frame->height != (int)CVPixelBufferGetHeight(pixbuf)) {
+
+ // This can happen while changing camera format
+ return nullptr;
+ }
+ return frame;
+}
+
+@implementation QAVFSampleBufferDelegate {
+@private
+ std::function<void(const QVideoFrame &)> frameHandler;
+ AVBufferRef *hwFramesContext;
+ std::unique_ptr<QFFmpeg::HWAccel> m_accel;
+ qint64 startTime;
+ std::optional<qint64> baseTime;
+ qreal frameRate;
+}
+
+static QVideoFrame createHwVideoFrame(QAVFSampleBufferDelegate &delegate,
+ CVImageBufferRef imageBuffer, QVideoFrameFormat format)
+{
+ Q_ASSERT(delegate.baseTime);
+
+ if (!delegate.m_accel)
+ return {};
+
+ auto avFrame = allocHWFrame(delegate.m_accel->hwFramesContextAsBuffer(), imageBuffer);
+ if (!avFrame)
+ return {};
+
+#ifdef USE_SW_FRAMES
+ {
+ auto swFrame = QFFmpeg::makeAVFrame();
+ /* retrieve data from GPU to CPU */
+ const int ret = av_hwframe_transfer_data(swFrame.get(), avFrame.get(), 0);
+ if (ret < 0) {
+ qWarning() << "Error transferring the data to system memory:" << ret;
+ } else {
+ avFrame = std::move(swFrame);
+ }
+ }
+#endif
+
+ avFrame->pts = delegate.startTime - *delegate.baseTime;
+
+ return QVideoFramePrivate::createFrame(std::make_unique<QFFmpegVideoBuffer>(std::move(avFrame)),
+ format);
+}
+
+- (instancetype)initWithFrameHandler:(std::function<void(const QVideoFrame &)>)handler
+{
+ if (!(self = [super init]))
+ return nil;
+
+ Q_ASSERT(handler);
+
+ frameHandler = std::move(handler);
+ hwFramesContext = nullptr;
+ startTime = 0;
+ frameRate = 0.;
+ return self;
+}
+
+- (void)captureOutput:(AVCaptureOutput *)captureOutput
+ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
+ fromConnection:(AVCaptureConnection *)connection
+{
+ Q_UNUSED(connection);
+ Q_UNUSED(captureOutput);
+
+ // NB: on iOS captureOutput/connection can be nil (when recording a video -
+ // avfmediaassetwriter).
+
+ CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
+
+ if (!imageBuffer) {
+ qWarning() << "Cannot get image buffer from sample buffer";
+ return;
+ }
+
+ const CMTime time = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
+ const qint64 frameTime = time.timescale ? time.value * 1000000 / time.timescale : 0;
+ if (!baseTime) {
+ baseTime = frameTime;
+ startTime = frameTime;
+ }
+
+ QVideoFrameFormat format = QAVFHelpers::videoFormatForImageBuffer(imageBuffer);
+ if (!format.isValid()) {
+ qWarning() << "Cannot get get video format for image buffer"
+ << CVPixelBufferGetWidth(imageBuffer) << 'x'
+ << CVPixelBufferGetHeight(imageBuffer);
+ return;
+ }
+
+ format.setStreamFrameRate(frameRate);
+
+ auto frame = createHwVideoFrame(*self, imageBuffer, format);
+ if (!frame.isValid())
+ frame = QVideoFramePrivate::createFrame(std::make_unique<CVImageVideoBuffer>(imageBuffer),
+ std::move(format));
+
+ frame.setStartTime(startTime - *baseTime);
+ frame.setEndTime(frameTime - *baseTime);
+ startTime = frameTime;
+
+ frameHandler(frame);
+}
+
+- (void)setHWAccel:(std::unique_ptr<QFFmpeg::HWAccel> &&)accel
+{
+ m_accel = std::move(accel);
+}
+
+- (void)setVideoFormatFrameRate:(qreal)rate
+{
+ frameRate = rate;
+}
+
+@end
diff --git a/src/plugins/multimedia/ffmpeg/qavfsamplebufferdelegate_p.h b/src/plugins/multimedia/ffmpeg/qavfsamplebufferdelegate_p.h
new file mode 100644
index 000000000..5a7e16c71
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qavfsamplebufferdelegate_p.h
@@ -0,0 +1,51 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAVFSAMPLEBUFFERDELEGATE_P_H
+#define QAVFSAMPLEBUFFERDELEGATE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#import <AVFoundation/AVFoundation.h>
+#import <CoreVideo/CoreVideo.h>
+
+#include <qtconfigmacros.h>
+#include <qtypes.h>
+
+#include <memory>
+#include <functional>
+
+QT_BEGIN_NAMESPACE
+
+class QAVSampleBufferDelegateFrameHandler;
+class QVideoFrame;
+namespace QFFmpeg {
+class HWAccel;
+}
+
+QT_END_NAMESPACE
+
+@interface QAVFSampleBufferDelegate : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate>
+
+- (instancetype)initWithFrameHandler:(std::function<void(const QVideoFrame &)>)handler;
+
+- (void)captureOutput:(AVCaptureOutput *)captureOutput
+ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
+ fromConnection:(AVCaptureConnection *)connection;
+
+- (void)setHWAccel:(std::unique_ptr<QT_PREPEND_NAMESPACE(QFFmpeg::HWAccel)> &&)accel;
+
+- (void)setVideoFormatFrameRate:(qreal)frameRate;
+
+@end
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qavfscreencapture.mm b/src/plugins/multimedia/ffmpeg/qavfscreencapture.mm
new file mode 100644
index 000000000..715dea09c
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qavfscreencapture.mm
@@ -0,0 +1,201 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qavfscreencapture_p.h"
+#include "qavfsamplebufferdelegate_p.h"
+#include "qffmpegsurfacecapturegrabber_p.h"
+
+#include <qscreen.h>
+
+#define AVMediaType XAVMediaType
+#include "qffmpeghwaccel_p.h"
+
+extern "C" {
+#include <libavutil/hwcontext_videotoolbox.h>
+#include <libavutil/hwcontext.h>
+}
+#undef AVMediaType
+
+#include <AppKit/NSScreen.h>
+
+#include <dispatch/dispatch.h>
+
+namespace {
+
+const auto DefaultCVPixelFormat = kCVPixelFormatType_32BGRA;
+
+CGDirectDisplayID findDisplayByName(const QString &name)
+{
+ for (NSScreen *screen in NSScreen.screens) {
+ if (name == QString::fromNSString(screen.localizedName))
+ return [screen.deviceDescription[@"NSScreenNumber"] unsignedIntValue];
+ }
+ return kCGNullDirectDisplay;
+}
+}
+
+QT_BEGIN_NAMESPACE
+
+QAVFScreenCapture::QAVFScreenCapture() : QPlatformSurfaceCapture(ScreenSource{})
+{
+ CGRequestScreenCaptureAccess();
+}
+
+QAVFScreenCapture::~QAVFScreenCapture()
+{
+ resetCapture();
+}
+
+bool QAVFScreenCapture::setActiveInternal(bool active)
+{
+ if (active) {
+ if (!CGPreflightScreenCaptureAccess()) {
+ updateError(CaptureFailed, QLatin1String("Permissions denied"));
+ return false;
+ }
+
+ auto screen = source<ScreenSource>();
+
+ if (!checkScreenWithError(screen))
+ return false;
+
+ return initScreenCapture(screen);
+ } else {
+ resetCapture();
+ }
+
+ return true;
+}
+
+void QAVFScreenCapture::onNewFrame(const QVideoFrame &frame)
+{
+ // Since writing of the format is supposed to be only from one thread,
+ // the read-only comparison without a mutex is thread-safe
+ if (!m_format || m_format != frame.surfaceFormat()) {
+ QMutexLocker<QMutex> locker(&m_formatMutex);
+
+ m_format = frame.surfaceFormat();
+
+ locker.unlock();
+
+ m_waitForFormat.notify_one();
+ }
+
+ emit newVideoFrame(frame);
+}
+
+QVideoFrameFormat QAVFScreenCapture::frameFormat() const
+{
+ if (!m_grabber)
+ return {};
+
+ QMutexLocker<QMutex> locker(&m_formatMutex);
+ while (!m_format)
+ m_waitForFormat.wait(&m_formatMutex);
+ return *m_format;
+}
+
+std::optional<int> QAVFScreenCapture::ffmpegHWPixelFormat() const
+{
+ return AV_PIX_FMT_VIDEOTOOLBOX;
+}
+
+class QAVFScreenCapture::Grabber
+{
+public:
+ Grabber(QAVFScreenCapture &capture, QScreen *screen, CGDirectDisplayID screenID,
+ std::unique_ptr<QFFmpeg::HWAccel> hwAccel)
+ {
+ m_captureSession = [[AVCaptureSession alloc] init];
+
+ m_sampleBufferDelegate = [[QAVFSampleBufferDelegate alloc]
+ initWithFrameHandler:[&capture](const QVideoFrame &frame) {
+ capture.onNewFrame(frame);
+ }];
+
+ m_videoDataOutput = [[AVCaptureVideoDataOutput alloc] init];
+
+ NSDictionary *videoSettings = [NSDictionary
+ dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:DefaultCVPixelFormat],
+ kCVPixelBufferPixelFormatTypeKey, nil];
+
+ [m_videoDataOutput setVideoSettings:videoSettings];
+ [m_videoDataOutput setAlwaysDiscardsLateVideoFrames:true];
+
+ // Configure video output
+ m_dispatchQueue = dispatch_queue_create("vf_queue", nullptr);
+ [m_videoDataOutput setSampleBufferDelegate:m_sampleBufferDelegate queue:m_dispatchQueue];
+
+ [m_captureSession addOutput:m_videoDataOutput];
+
+ [m_sampleBufferDelegate setHWAccel:std::move(hwAccel)];
+
+ const auto frameRate = std::min(screen->refreshRate(), MaxScreenCaptureFrameRate);
+ [m_sampleBufferDelegate setVideoFormatFrameRate:frameRate];
+
+ m_screenInput = [[AVCaptureScreenInput alloc] initWithDisplayID:screenID];
+ [m_screenInput setMinFrameDuration:CMTimeMake(1, static_cast<int32_t>(frameRate))];
+ [m_captureSession addInput:m_screenInput];
+
+ [m_captureSession startRunning];
+ }
+
+ ~Grabber()
+ {
+ if (m_captureSession)
+ [m_captureSession stopRunning];
+
+ if (m_dispatchQueue)
+ dispatch_release(m_dispatchQueue);
+
+ [m_sampleBufferDelegate release];
+ [m_screenInput release];
+ [m_videoDataOutput release];
+ [m_captureSession release];
+ }
+
+private:
+ AVCaptureSession *m_captureSession = nullptr;
+ AVCaptureScreenInput *m_screenInput = nullptr;
+ AVCaptureVideoDataOutput *m_videoDataOutput = nullptr;
+ QAVFSampleBufferDelegate *m_sampleBufferDelegate = nullptr;
+ dispatch_queue_t m_dispatchQueue = nullptr;
+};
+
+bool QAVFScreenCapture::initScreenCapture(QScreen *screen)
+{
+ const auto screenID = findDisplayByName(screen->name());
+
+ if (screenID == kCGNullDirectDisplay) {
+ updateError(InternalError, QLatin1String("Screen exists but couldn't been found by name"));
+ return false;
+ }
+
+ auto hwAccel = QFFmpeg::HWAccel::create(AV_HWDEVICE_TYPE_VIDEOTOOLBOX);
+
+ if (!hwAccel) {
+ updateError(CaptureFailed, QLatin1String("Couldn't create videotoolbox hw acceleration"));
+ return false;
+ }
+
+ hwAccel->createFramesContext(av_map_videotoolbox_format_to_pixfmt(DefaultCVPixelFormat),
+ screen->size() * screen->devicePixelRatio());
+
+ if (!hwAccel->hwFramesContextAsBuffer()) {
+ updateError(CaptureFailed, QLatin1String("Couldn't create hw frames context"));
+ return false;
+ }
+
+ m_grabber = std::make_unique<Grabber>(*this, screen, screenID, std::move(hwAccel));
+ return true;
+}
+
+void QAVFScreenCapture::resetCapture()
+{
+ m_grabber.reset();
+ m_format = {};
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qavfscreencapture_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qavfscreencapture_p.h b/src/plugins/multimedia/ffmpeg/qavfscreencapture_p.h
new file mode 100644
index 000000000..b95aabcf3
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qavfscreencapture_p.h
@@ -0,0 +1,60 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAVFSCREENCAPTURE_H
+#define QAVFSCREENCAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qplatformsurfacecapture_p.h"
+#include <qmutex.h>
+#include <qwaitcondition.h>
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegVideoSink;
+
+class QAVFScreenCapture : public QPlatformSurfaceCapture
+{
+ Q_OBJECT
+
+ class Grabber;
+
+public:
+ explicit QAVFScreenCapture();
+ ~QAVFScreenCapture() override;
+
+ QVideoFrameFormat frameFormat() const override;
+
+ std::optional<int> ffmpegHWPixelFormat() const override;
+
+protected:
+ bool setActiveInternal(bool active) override;
+
+private:
+ void onNewFrame(const QVideoFrame &frame);
+
+ bool initScreenCapture(QScreen *screen);
+
+ void resetCapture();
+
+private:
+ std::optional<QVideoFrameFormat> m_format;
+ mutable QMutex m_formatMutex;
+ mutable QWaitCondition m_waitForFormat;
+
+ std::unique_ptr<Grabber> m_grabber;
+};
+
+QT_END_NAMESPACE
+
+#endif // QAVFSCREENCAPTURE_H
diff --git a/src/plugins/multimedia/ffmpeg/qcgcapturablewindows.mm b/src/plugins/multimedia/ffmpeg/qcgcapturablewindows.mm
new file mode 100644
index 000000000..eb2035208
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qcgcapturablewindows.mm
@@ -0,0 +1,48 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qcgcapturablewindows_p.h"
+#include "private/qcapturablewindow_p.h"
+#include "QtCore/private/qcore_mac_p.h"
+
+#include <AppKit/NSWindow.h>
+
+QT_BEGIN_NAMESPACE
+
+QList<QCapturableWindow> QCGCapturableWindows::windows() const
+{
+ QList<QCapturableWindow> result;
+ QCFType<CFArrayRef> windowList(
+ CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID));
+
+ // Iterate through the window dictionaries
+ CFIndex count = CFArrayGetCount(windowList);
+ for (CFIndex i = 0; i < count; ++i) {
+ auto windowInfo = (CFDictionaryRef)CFArrayGetValueAtIndex(windowList, i);
+ auto windowNumber = (CFNumberRef)CFDictionaryGetValue(windowInfo, kCGWindowNumber);
+ auto windowName = (CFStringRef)CFDictionaryGetValue(windowInfo, kCGWindowName);
+
+ CGWindowID windowId = 0;
+ static_assert(sizeof(windowId) == 4,
+ "CGWindowID size is not compatible with kCFNumberSInt32Type");
+ CFNumberGetValue(windowNumber, kCFNumberSInt32Type, &windowId);
+
+ auto windowData = std::make_unique<QCapturableWindowPrivate>();
+ windowData->id = static_cast<QCapturableWindowPrivate::Id>(windowId);
+ if (windowName)
+ windowData->description = QString::fromCFString(windowName);
+
+ result.push_back(windowData.release()->create());
+ }
+
+ return result;
+}
+
+bool QCGCapturableWindows::isWindowValid(const QCapturableWindowPrivate &window) const
+{
+ QCFType<CFArrayRef> windowList(
+ CGWindowListCreate(kCGWindowListOptionIncludingWindow, window.id));
+ return CFArrayGetCount(windowList) > 0;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qcgcapturablewindows_p.h b/src/plugins/multimedia/ffmpeg/qcgcapturablewindows_p.h
new file mode 100644
index 000000000..6f779ae0d
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qcgcapturablewindows_p.h
@@ -0,0 +1,32 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCGCAPTURABLEWINDOWS_P_H
+#define QCGCAPTURABLEWINDOWS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qplatformcapturablewindows_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QCGCapturableWindows : public QPlatformCapturableWindows
+{
+public:
+ QList<QCapturableWindow> windows() const override;
+
+ bool isWindowValid(const QCapturableWindowPrivate &window) const override;
+};
+
+QT_END_NAMESPACE
+
+#endif // QCGCAPTURABLEWINDOWS_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qcgwindowcapture.mm b/src/plugins/multimedia/ffmpeg/qcgwindowcapture.mm
new file mode 100644
index 000000000..6fa2f620f
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qcgwindowcapture.mm
@@ -0,0 +1,203 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qabstractvideobuffer.h"
+
+#include "qcgwindowcapture_p.h"
+#include "private/qcapturablewindow_p.h"
+#include "qffmpegsurfacecapturegrabber_p.h"
+#include "private/qvideoframe_p.h"
+
+#include "qscreen.h"
+#include "qguiapplication.h"
+#include <qmutex.h>
+#include <qwaitcondition.h>
+
+#include <ApplicationServices/ApplicationServices.h>
+#include <IOKit/graphics/IOGraphicsLib.h>
+#include <AppKit/NSScreen.h>
+#include <AppKit/NSApplication.h>
+#include <AppKit/NSWindow.h>
+
+namespace {
+
+std::optional<qreal> frameRateForWindow(CGWindowID /*wid*/)
+{
+ // TODO: detect the frame rate
+ // if (window && window.screen) {
+ // CGDirectDisplayID displayID = [window.screen.deviceDescription[@"NSScreenNumber"]
+ // unsignedIntValue]; const auto displayRefreshRate =
+ // CGDisplayModeGetRefreshRate(CGDisplayCopyDisplayMode(displayID)); if (displayRefreshRate
+ // > 0 && displayRefreshRate < frameRate) frameRate = displayRefreshRate;
+ // }
+
+ return {};
+}
+
+}
+
+QT_BEGIN_NAMESPACE
+
+class QCGImageVideoBuffer : public QAbstractVideoBuffer
+{
+public:
+ QCGImageVideoBuffer(CGImageRef image)
+ {
+ auto provider = CGImageGetDataProvider(image);
+ m_data = CGDataProviderCopyData(provider);
+ m_bytesPerLine = CGImageGetBytesPerRow(image);
+ }
+
+ ~QCGImageVideoBuffer() override { CFRelease(m_data); }
+
+ MapData map(QtVideo::MapMode mode) override
+ {
+ MapData mapData;
+ if (m_mapMode == QtVideo::MapMode::NotMapped) {
+ m_mapMode = mode;
+
+ mapData.planeCount = 1;
+ mapData.bytesPerLine[0] = static_cast<int>(m_bytesPerLine);
+ mapData.data[0] = (uchar *)CFDataGetBytePtr(m_data);
+ mapData.dataSize[0] = static_cast<int>(CFDataGetLength(m_data));
+ }
+
+ return mapData;
+ }
+
+ void unmap() override { m_mapMode = QtVideo::MapMode::NotMapped; }
+
+ QVideoFrameFormat format() const override { return {}; }
+
+private:
+ QtVideo::MapMode m_mapMode = QtVideo::MapMode::NotMapped;
+ CFDataRef m_data;
+ size_t m_bytesPerLine = 0;
+};
+
+class QCGWindowCapture::Grabber : public QFFmpegSurfaceCaptureGrabber
+{
+public:
+ Grabber(QCGWindowCapture &capture, CGWindowID wid) : m_capture(capture), m_wid(wid)
+ {
+ addFrameCallback(*this, &Grabber::onNewFrame);
+ connect(this, &Grabber::errorUpdated, &capture, &QCGWindowCapture::updateError);
+
+ if (auto screen = QGuiApplication::primaryScreen())
+ setFrameRate(screen->refreshRate());
+
+ start();
+ }
+
+ ~Grabber() override { stop(); }
+
+ QVideoFrameFormat frameFormat() const
+ {
+ QMutexLocker<QMutex> locker(&m_formatMutex);
+ while (!m_format)
+ m_waitForFormat.wait(&m_formatMutex);
+ return *m_format;
+ }
+
+protected:
+ QVideoFrame grabFrame() override
+ {
+ if (auto rate = frameRateForWindow(m_wid))
+ setFrameRate(*rate);
+
+ auto imageRef = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow,
+ m_wid, kCGWindowImageBoundsIgnoreFraming);
+ if (!imageRef) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Cannot create image by window"));
+ return {};
+ }
+
+ auto imageDeleter = qScopeGuard([imageRef]() { CGImageRelease(imageRef); });
+
+ if (CGImageGetBitsPerPixel(imageRef) != 32
+ || CGImageGetPixelFormatInfo(imageRef) != kCGImagePixelFormatPacked
+ || CGImageGetByteOrderInfo(imageRef) != kCGImageByteOrder32Little) {
+ qWarning() << "Unexpected image format. PixelFormatInfo:"
+ << CGImageGetPixelFormatInfo(imageRef)
+ << "BitsPerPixel:" << CGImageGetBitsPerPixel(imageRef) << "AlphaInfo"
+ << CGImageGetAlphaInfo(imageRef)
+ << "ByteOrderInfo:" << CGImageGetByteOrderInfo(imageRef);
+
+ updateError(QPlatformSurfaceCapture::CapturingNotSupported,
+ QLatin1String("Not supported pixel format"));
+ return {};
+ }
+
+ QVideoFrameFormat format(QSize(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)),
+ QVideoFrameFormat::Format_BGRA8888);
+ format.setStreamFrameRate(frameRate());
+
+ return QVideoFramePrivate::createFrame(std::make_unique<QCGImageVideoBuffer>(imageRef),
+ std::move(format));
+ }
+
+ void onNewFrame(QVideoFrame frame)
+ {
+ // Since writing of the format is supposed to be only from one thread,
+ // the read-only comparison without a mutex is thread-safe
+ if (!m_format || m_format != frame.surfaceFormat()) {
+ QMutexLocker<QMutex> locker(&m_formatMutex);
+
+ m_format = frame.surfaceFormat();
+
+ locker.unlock();
+
+ m_waitForFormat.notify_one();
+ }
+
+ emit m_capture.newVideoFrame(frame);
+ }
+
+private:
+ QCGWindowCapture &m_capture;
+ std::optional<QVideoFrameFormat> m_format;
+ mutable QMutex m_formatMutex;
+ mutable QWaitCondition m_waitForFormat;
+ CGWindowID m_wid;
+};
+
+QCGWindowCapture::QCGWindowCapture() : QPlatformSurfaceCapture(WindowSource{})
+{
+ CGRequestScreenCaptureAccess();
+}
+
+QCGWindowCapture::~QCGWindowCapture() = default;
+
+bool QCGWindowCapture::setActiveInternal(bool active)
+{
+ if (active) {
+ if (!CGPreflightScreenCaptureAccess()) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Permissions denied"));
+ return false;
+ }
+
+ auto window = source<WindowSource>();
+
+ auto handle = QCapturableWindowPrivate::handle(window);
+ if (!handle || !handle->id)
+ updateError(QPlatformSurfaceCapture::NotFound, QLatin1String("Invalid window"));
+ else
+ m_grabber = std::make_unique<Grabber>(*this, handle->id);
+
+ } else {
+ m_grabber.reset();
+ }
+
+ return active == static_cast<bool>(m_grabber);
+}
+
+QVideoFrameFormat QCGWindowCapture::frameFormat() const
+{
+ return m_grabber ? m_grabber->frameFormat() : QVideoFrameFormat();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qcgwindowcapture_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qcgwindowcapture_p.h b/src/plugins/multimedia/ffmpeg/qcgwindowcapture_p.h
new file mode 100644
index 000000000..796c01ab3
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qcgwindowcapture_p.h
@@ -0,0 +1,43 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCGWINDOWCAPTURE_H
+#define QCGWINDOWCAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qplatformsurfacecapture_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QCGWindowCapture : public QPlatformSurfaceCapture
+{
+ Q_OBJECT
+
+ class Grabber;
+
+public:
+ explicit QCGWindowCapture();
+ ~QCGWindowCapture() override;
+
+ QVideoFrameFormat frameFormat() const override;
+
+protected:
+ bool setActiveInternal(bool active) override;
+
+private:
+ std::unique_ptr<Grabber> m_grabber;
+};
+
+QT_END_NAMESPACE
+
+#endif // QCGWINDOWCAPTURE_H
diff --git a/src/plugins/multimedia/ffmpeg/qeglfsscreencapture.cpp b/src/plugins/multimedia/ffmpeg/qeglfsscreencapture.cpp
new file mode 100644
index 000000000..b316a5704
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qeglfsscreencapture.cpp
@@ -0,0 +1,180 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qeglfsscreencapture_p.h"
+
+#include "qffmpegsurfacecapturegrabber_p.h"
+#include "qguiapplication.h"
+#include "qopenglvideobuffer_p.h"
+#include "private/qimagevideobuffer_p.h"
+#include "private/qvideoframe_p.h"
+
+#include <QtOpenGL/private/qopenglcompositor_p.h>
+#include <QtOpenGL/private/qopenglframebufferobject_p.h>
+
+#include <QtQuick/qquickwindow.h>
+
+QT_BEGIN_NAMESPACE
+
+class QEglfsScreenCapture::Grabber : public QFFmpegSurfaceCaptureGrabber
+{
+public:
+ Grabber(QEglfsScreenCapture &screenCapture, QScreen *screen)
+ : QFFmpegSurfaceCaptureGrabber(QFFmpegSurfaceCaptureGrabber::UseCurrentThread)
+ {
+ addFrameCallback(screenCapture, &QEglfsScreenCapture::newVideoFrame);
+ connect(this, &Grabber::errorUpdated, &screenCapture, &QEglfsScreenCapture::updateError);
+ // Limit frame rate to 30 fps for performance reasons,
+ // to be reviewed at the next optimization round
+ setFrameRate(std::min(screen->refreshRate(), 30.0));
+ }
+
+ ~Grabber() override { stop(); }
+
+ QVideoFrameFormat format() { return m_format; }
+
+protected:
+ QVideoFrame grabFrame() override
+ {
+ auto nativeSize = QOpenGLCompositor::instance()->nativeTargetGeometry().size();
+ auto fbo = std::make_unique<QOpenGLFramebufferObject>(nativeSize);
+
+ if (!QOpenGLCompositor::instance()->grabToFrameBufferObject(
+ fbo.get(), QOpenGLCompositor::NotFlipped)) {
+ updateError(Error::InternalError, QLatin1String("Couldn't grab to framebuffer object"));
+ return {};
+ }
+
+ if (!fbo->isValid()) {
+ updateError(Error::InternalError, QLatin1String("Framebuffer object invalid"));
+ return {};
+ }
+
+ auto videoBuffer = std::make_unique<QOpenGLVideoBuffer>(std::move(fbo));
+
+ if (!m_format.isValid()) {
+ auto image = videoBuffer->ensureImageBuffer().underlyingImage();
+ m_format = { image.size(), QVideoFrameFormat::pixelFormatFromImageFormat(image.format()) };
+ m_format.setStreamFrameRate(frameRate());
+ }
+
+ return QVideoFrame(videoBuffer.release(), m_format);
+ }
+
+ QVideoFrameFormat m_format;
+};
+
+class QEglfsScreenCapture::QuickGrabber : public Grabber
+{
+public:
+ QuickGrabber(QEglfsScreenCapture &screenCapture, QScreen *screen, QQuickWindow *quickWindow)
+ : Grabber(screenCapture, screen), m_quickWindow(quickWindow)
+ {
+ Q_ASSERT(m_quickWindow);
+ }
+
+protected:
+ QVideoFrame grabFrame() override
+ {
+ if (!m_quickWindow) {
+ updateError(Error::InternalError, QLatin1String("Window deleted"));
+ return {};
+ }
+
+ QImage image = m_quickWindow->grabWindow();
+
+ if (image.isNull()) {
+ updateError(Error::InternalError, QLatin1String("Image invalid"));
+ return {};
+ }
+
+ if (!m_format.isValid()) {
+ m_format = { image.size(),
+ QVideoFrameFormat::pixelFormatFromImageFormat(image.format()) };
+ m_format.setStreamFrameRate(frameRate());
+ }
+
+ return QVideoFramePrivate::createFrame(
+ std::make_unique<QImageVideoBuffer>(std::move(image)), m_format);
+ }
+
+private:
+ QPointer<QQuickWindow> m_quickWindow;
+};
+
+QEglfsScreenCapture::QEglfsScreenCapture() : QPlatformSurfaceCapture(ScreenSource{}) { }
+
+QEglfsScreenCapture::~QEglfsScreenCapture() = default;
+
+QVideoFrameFormat QEglfsScreenCapture::frameFormat() const
+{
+ return m_grabber ? m_grabber->format() : QVideoFrameFormat();
+}
+
+bool QEglfsScreenCapture::setActiveInternal(bool active)
+{
+ if (static_cast<bool>(m_grabber) == active)
+ return true;
+
+ if (m_grabber)
+ m_grabber.reset();
+
+ if (!active)
+ return true;
+
+ m_grabber = createGrabber();
+
+ if (!m_grabber) {
+ // TODO: This could mean that the UI is not started yet, so we should wait and try again,
+ // and then give error if still not started. Might not be possible here.
+ return false;
+ }
+
+ m_grabber->start();
+ return true;
+}
+
+bool QEglfsScreenCapture::isSupported()
+{
+ return QGuiApplication::platformName() == QLatin1String("eglfs");
+}
+
+std::unique_ptr<QEglfsScreenCapture::Grabber> QEglfsScreenCapture::createGrabber()
+{
+ auto screen = source<ScreenSource>();
+ if (!checkScreenWithError(screen))
+ return nullptr;
+
+ QOpenGLCompositor *compositor = QOpenGLCompositor::instance();
+
+ if (compositor->context()) {
+ // Create OpenGL grabber
+ if (!compositor->targetWindow()) {
+ updateError(Error::CaptureFailed,
+ QLatin1String("Target window is not set for OpenGL compositor"));
+ return nullptr;
+ }
+
+ return std::make_unique<Grabber>(*this, screen);
+ }
+
+ // Check for QQuickWindow
+ auto windows = QGuiApplication::topLevelWindows();
+ auto it = std::find_if(windows.begin(), windows.end(), [screen](QWindow *window) {
+ auto quickWindow = qobject_cast<QQuickWindow *>(window);
+ if (!quickWindow)
+ return false;
+
+ return quickWindow->screen() == screen;
+ });
+
+ if (it != windows.end()) {
+ // Create grabber that calls QQuickWindow::grabWindow
+ return std::make_unique<QuickGrabber>(*this, screen, qobject_cast<QQuickWindow *>(*it));
+ }
+
+ updateError(Error::CaptureFailed, QLatin1String("No existing OpenGL context or QQuickWindow"));
+ return nullptr;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qeglfsscreencapture_p.h b/src/plugins/multimedia/ffmpeg/qeglfsscreencapture_p.h
new file mode 100644
index 000000000..840cdbeb0
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qeglfsscreencapture_p.h
@@ -0,0 +1,48 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QEGLFSSCREENCAPTURE_H
+#define QEGLFSSCREENCAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformsurfacecapture_p.h>
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+class QEglfsScreenCapture : public QPlatformSurfaceCapture
+{
+public:
+ QEglfsScreenCapture();
+
+ ~QEglfsScreenCapture() override;
+
+ QVideoFrameFormat frameFormat() const override;
+
+ static bool isSupported();
+
+private:
+ bool setActiveInternal(bool active) override;
+
+private:
+ class Grabber;
+ class QuickGrabber;
+
+ std::unique_ptr<Grabber> createGrabber();
+
+ std::unique_ptr<Grabber> m_grabber;
+};
+
+QT_END_NAMESPACE
+
+#endif // QEGLFSSCREENCAPTURE_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeg.cpp b/src/plugins/multimedia/ffmpeg/qffmpeg.cpp
new file mode 100644
index 000000000..ce7dfc682
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeg.cpp
@@ -0,0 +1,645 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpeg_p.h"
+
+#include <qdebug.h>
+#include <qloggingcategory.h>
+#include <qffmpeghwaccel_p.h> // TODO: probably decompose HWAccel and get rid of the header in the base utils
+
+#include <algorithm>
+#include <vector>
+#include <array>
+#include <optional>
+#include <unordered_set>
+
+extern "C" {
+#include <libavutil/pixdesc.h>
+#include <libavutil/samplefmt.h>
+
+#ifdef Q_OS_DARWIN
+#include <libavutil/hwcontext_videotoolbox.h>
+#endif
+}
+
+#ifdef Q_OS_ANDROID
+#include <QtCore/qjniobject.h>
+#include <QtCore/qjniarray.h>
+#include <QtCore/qjnitypes.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+#ifdef Q_OS_ANDROID
+Q_DECLARE_JNI_CLASS(QtVideoDeviceManager,
+ "org/qtproject/qt/android/multimedia/QtVideoDeviceManager");
+Q_DECLARE_JNI_CLASS(String, "java/lang/String");
+#endif
+
+static Q_LOGGING_CATEGORY(qLcFFmpegUtils, "qt.multimedia.ffmpeg.utils");
+
+namespace QFFmpeg {
+
+namespace {
+
+enum CodecStorageType {
+ ENCODERS,
+ DECODERS,
+
+ // TODO: maybe split sw/hw codecs
+
+ CODEC_STORAGE_TYPE_COUNT
+};
+
+using CodecsStorage = std::vector<const AVCodec *>;
+
+struct CodecsComparator
+{
+ bool operator()(const AVCodec *a, const AVCodec *b) const
+ {
+ return a->id < b->id
+ || (a->id == b->id && isAVCodecExperimental(a) < isAVCodecExperimental(b));
+ }
+
+ bool operator()(const AVCodec *a, AVCodecID id) const { return a->id < id; }
+};
+
+template<typename FlagNames>
+QString flagsToString(int flags, const FlagNames &flagNames)
+{
+ QString result;
+ int leftover = flags;
+ for (const auto &flagAndName : flagNames)
+ if ((flags & flagAndName.first) != 0) {
+ leftover &= ~flagAndName.first;
+ if (!result.isEmpty())
+ result += ", ";
+ result += flagAndName.second;
+ }
+
+ if (leftover) {
+ if (!result.isEmpty())
+ result += ", ";
+ result += QString::number(leftover, 16);
+ }
+ return result;
+}
+
+void dumpCodecInfo(const AVCodec *codec)
+{
+ using FlagNames = std::initializer_list<std::pair<int, const char *>>;
+ const auto mediaType = codec->type == AVMEDIA_TYPE_VIDEO ? "video"
+ : codec->type == AVMEDIA_TYPE_AUDIO ? "audio"
+ : codec->type == AVMEDIA_TYPE_SUBTITLE ? "subtitle"
+ : "other_type";
+
+ const auto type = av_codec_is_encoder(codec)
+ ? av_codec_is_decoder(codec) ? "encoder/decoder:" : "encoder:"
+ : "decoder:";
+
+ static const FlagNames capabilitiesNames = {
+ { AV_CODEC_CAP_DRAW_HORIZ_BAND, "DRAW_HORIZ_BAND" },
+ { AV_CODEC_CAP_DR1, "DRAW_HORIZ_DR1" },
+ { AV_CODEC_CAP_DELAY, "DELAY" },
+ { AV_CODEC_CAP_SMALL_LAST_FRAME, "SMALL_LAST_FRAME" },
+ { AV_CODEC_CAP_SUBFRAMES, "SUBFRAMES" },
+ { AV_CODEC_CAP_EXPERIMENTAL, "EXPERIMENTAL" },
+ { AV_CODEC_CAP_CHANNEL_CONF, "CHANNEL_CONF" },
+ { AV_CODEC_CAP_FRAME_THREADS, "FRAME_THREADS" },
+ { AV_CODEC_CAP_SLICE_THREADS, "SLICE_THREADS" },
+ { AV_CODEC_CAP_PARAM_CHANGE, "PARAM_CHANGE" },
+#ifdef AV_CODEC_CAP_OTHER_THREADS
+ { AV_CODEC_CAP_OTHER_THREADS, "OTHER_THREADS" },
+#endif
+ { AV_CODEC_CAP_VARIABLE_FRAME_SIZE, "VARIABLE_FRAME_SIZE" },
+ { AV_CODEC_CAP_AVOID_PROBING, "AVOID_PROBING" },
+ { AV_CODEC_CAP_HARDWARE, "HARDWARE" },
+ { AV_CODEC_CAP_HYBRID, "HYBRID" },
+ { AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, "ENCODER_REORDERED_OPAQUE" },
+#ifdef AV_CODEC_CAP_ENCODER_FLUSH
+ { AV_CODEC_CAP_ENCODER_FLUSH, "ENCODER_FLUSH" },
+#endif
+ };
+
+ qCDebug(qLcFFmpegUtils) << mediaType << type << codec->name << "id:" << codec->id
+ << "capabilities:"
+ << flagsToString(codec->capabilities, capabilitiesNames);
+
+ if (codec->pix_fmts) {
+ static const FlagNames flagNames = {
+ { AV_PIX_FMT_FLAG_BE, "BE" },
+ { AV_PIX_FMT_FLAG_PAL, "PAL" },
+ { AV_PIX_FMT_FLAG_BITSTREAM, "BITSTREAM" },
+ { AV_PIX_FMT_FLAG_HWACCEL, "HWACCEL" },
+ { AV_PIX_FMT_FLAG_PLANAR, "PLANAR" },
+ { AV_PIX_FMT_FLAG_RGB, "RGB" },
+ { AV_PIX_FMT_FLAG_ALPHA, "ALPHA" },
+ { AV_PIX_FMT_FLAG_BAYER, "BAYER" },
+ { AV_PIX_FMT_FLAG_FLOAT, "FLOAT" },
+ };
+
+ qCDebug(qLcFFmpegUtils) << " pix_fmts:";
+ for (auto f = codec->pix_fmts; *f != AV_PIX_FMT_NONE; ++f) {
+ auto desc = av_pix_fmt_desc_get(*f);
+ qCDebug(qLcFFmpegUtils)
+ << " id:" << *f << desc->name << "depth:" << desc->comp[0].depth
+ << "flags:" << flagsToString(desc->flags, flagNames);
+ }
+ } else if (codec->type == AVMEDIA_TYPE_VIDEO) {
+ qCDebug(qLcFFmpegUtils) << " pix_fmts: null";
+ }
+
+ if (codec->sample_fmts) {
+ qCDebug(qLcFFmpegUtils) << " sample_fmts:";
+ for (auto f = codec->sample_fmts; *f != AV_SAMPLE_FMT_NONE; ++f) {
+ const auto name = av_get_sample_fmt_name(*f);
+ qCDebug(qLcFFmpegUtils) << " id:" << *f << (name ? name : "unknown")
+ << "bytes_per_sample:" << av_get_bytes_per_sample(*f)
+ << "is_planar:" << av_sample_fmt_is_planar(*f);
+ }
+ } else if (codec->type == AVMEDIA_TYPE_AUDIO) {
+ qCDebug(qLcFFmpegUtils) << " sample_fmts: null";
+ }
+
+ if (avcodec_get_hw_config(codec, 0)) {
+ static const FlagNames hwConfigMethodNames = {
+ { AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX, "HW_DEVICE_CTX" },
+ { AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, "HW_FRAMES_CTX" },
+ { AV_CODEC_HW_CONFIG_METHOD_INTERNAL, "INTERNAL" },
+ { AV_CODEC_HW_CONFIG_METHOD_AD_HOC, "AD_HOC" }
+ };
+
+ qCDebug(qLcFFmpegUtils) << " hw config:";
+ for (int index = 0; auto config = avcodec_get_hw_config(codec, index); ++index) {
+ const auto pixFmtForDevice = pixelFormatForHwDevice(config->device_type);
+ auto pixFmtDesc = av_pix_fmt_desc_get(config->pix_fmt);
+ auto pixFmtForDeviceDesc = av_pix_fmt_desc_get(pixFmtForDevice);
+ qCDebug(qLcFFmpegUtils)
+ << " device_type:" << config->device_type << "pix_fmt:" << config->pix_fmt
+ << (pixFmtDesc ? pixFmtDesc->name : "unknown")
+ << "pixelFormatForHwDevice:" << pixelFormatForHwDevice(config->device_type)
+ << (pixFmtForDeviceDesc ? pixFmtForDeviceDesc->name : "unknown")
+ << "hw_config_methods:" << flagsToString(config->methods, hwConfigMethodNames);
+ }
+ }
+}
+
+bool isCodecValid(const AVCodec *codec, const std::vector<AVHWDeviceType> &availableHwDeviceTypes,
+ const std::optional<std::unordered_set<AVCodecID>> &codecAvailableOnDevice)
+{
+ if (codec->type != AVMEDIA_TYPE_VIDEO)
+ return true;
+
+ if (!codec->pix_fmts) {
+#if defined(Q_OS_LINUX) || defined(Q_OS_ANDROID)
+ // Disable V4L2 M2M codecs for encoding for now,
+ // TODO: Investigate on how to get them working
+ if (std::strstr(codec->name, "_v4l2m2m") && av_codec_is_encoder(codec))
+ return false;
+
+ // MediaCodec in Android is used for hardware-accelerated media processing. That is why
+ // before marking it as valid, we need to make sure if it is available on current device.
+ if (std::strstr(codec->name, "_mediacodec")
+ && (codec->capabilities & AV_CODEC_CAP_HARDWARE)
+ && codecAvailableOnDevice && codecAvailableOnDevice->count(codec->id) == 0)
+ return false;
+#endif
+
+ return true; // To be investigated. This happens for RAW_VIDEO, that is supposed to be OK,
+ // and with v4l2m2m codecs, that is suspicious.
+ }
+
+ if (findAVPixelFormat(codec, &isHwPixelFormat) == AV_PIX_FMT_NONE)
+ return true;
+
+ if ((codec->capabilities & AV_CODEC_CAP_HARDWARE) == 0)
+ return true;
+
+ auto checkDeviceType = [codec](AVHWDeviceType type) {
+ return isAVFormatSupported(codec, pixelFormatForHwDevice(type));
+ };
+
+ if (codecAvailableOnDevice && codecAvailableOnDevice->count(codec->id) == 0)
+ return false;
+
+ return std::any_of(availableHwDeviceTypes.begin(), availableHwDeviceTypes.end(),
+ checkDeviceType);
+}
+
+std::optional<std::unordered_set<AVCodecID>> availableHWCodecs(const CodecStorageType type)
+{
+#ifdef Q_OS_ANDROID
+ using namespace Qt::StringLiterals;
+ std::unordered_set<AVCodecID> availabeCodecs;
+
+ auto getCodecId = [] (const QString& codecName) {
+ if (codecName == "3gpp"_L1) return AV_CODEC_ID_H263;
+ if (codecName == "avc"_L1) return AV_CODEC_ID_H264;
+ if (codecName == "hevc"_L1) return AV_CODEC_ID_HEVC;
+ if (codecName == "mp4v-es"_L1) return AV_CODEC_ID_MPEG4;
+ if (codecName == "x-vnd.on2.vp8"_L1) return AV_CODEC_ID_VP8;
+ if (codecName == "x-vnd.on2.vp9"_L1) return AV_CODEC_ID_VP9;
+ return AV_CODEC_ID_NONE;
+ };
+
+ const QJniObject jniCodecs =
+ QtJniTypes::QtVideoDeviceManager::callStaticMethod<QtJniTypes::String[]>(
+ type == ENCODERS ? "getHWVideoEncoders" : "getHWVideoDecoders");
+
+ QJniArray<QtJniTypes::String> arrCodecs(jniCodecs.object<jobjectArray>());
+ for (int i = 0; i < arrCodecs.size(); ++i) {
+ availabeCodecs.insert(getCodecId(arrCodecs.at(i).toString()));
+ }
+ return availabeCodecs;
+#else
+ Q_UNUSED(type);
+ return {};
+#endif
+}
+
+const CodecsStorage &codecsStorage(CodecStorageType codecsType)
+{
+ static const auto &storages = []() {
+ std::array<CodecsStorage, CODEC_STORAGE_TYPE_COUNT> result;
+ void *opaque = nullptr;
+ const auto platformHwEncoders = availableHWCodecs(ENCODERS);
+ const auto platformHwDecoders = availableHWCodecs(DECODERS);
+
+ while (auto codec = av_codec_iterate(&opaque)) {
+ // TODO: to be investigated
+ // FFmpeg functions avcodec_find_decoder/avcodec_find_encoder
+ // find experimental codecs in the last order,
+ // now we don't consider them at all since they are supposed to
+ // be not stable, maybe we shouldn't.
+ // Currently, it's possible to turn them on for testing purposes.
+
+ static const auto experimentalCodecsEnabled =
+ qEnvironmentVariableIntValue("QT_ENABLE_EXPERIMENTAL_CODECS");
+
+ if (!experimentalCodecsEnabled && isAVCodecExperimental(codec)) {
+ qCDebug(qLcFFmpegUtils) << "Skip experimental codec" << codec->name;
+ continue;
+ }
+
+ if (av_codec_is_decoder(codec)) {
+ if (isCodecValid(codec, HWAccel::decodingDeviceTypes(), platformHwDecoders))
+ result[DECODERS].emplace_back(codec);
+ else
+ qCDebug(qLcFFmpegUtils)
+ << "Skip decoder" << codec->name
+ << "due to disabled matching hw acceleration, or dysfunctional codec";
+ }
+
+ if (av_codec_is_encoder(codec)) {
+ if (isCodecValid(codec, HWAccel::encodingDeviceTypes(), platformHwEncoders))
+ result[ENCODERS].emplace_back(codec);
+ else
+ qCDebug(qLcFFmpegUtils)
+ << "Skip encoder" << codec->name
+ << "due to disabled matching hw acceleration, or dysfunctional codec";
+ }
+ }
+
+ for (auto &storage : result) {
+ storage.shrink_to_fit();
+
+ // we should ensure the original order
+ std::stable_sort(storage.begin(), storage.end(), CodecsComparator{});
+ }
+
+ // It print pretty much logs, so let's print it only for special case
+ const bool shouldDumpCodecsInfo = qLcFFmpegUtils().isEnabled(QtDebugMsg)
+ && qEnvironmentVariableIsSet("QT_FFMPEG_DEBUG");
+
+ if (shouldDumpCodecsInfo) {
+ qCDebug(qLcFFmpegUtils) << "Advanced FFmpeg codecs info:";
+ for (auto &storage : result) {
+ std::for_each(storage.begin(), storage.end(), &dumpCodecInfo);
+ qCDebug(qLcFFmpegUtils) << "---------------------------";
+ }
+ }
+
+ return result;
+ }();
+
+ return storages[codecsType];
+}
+
+const char *preferredHwCodecNameSuffix(bool isEncoder, AVHWDeviceType deviceType)
+{
+ switch (deviceType) {
+ case AV_HWDEVICE_TYPE_VAAPI:
+ return "_vaapi";
+ case AV_HWDEVICE_TYPE_MEDIACODEC:
+ return "_mediacodec";
+ case AV_HWDEVICE_TYPE_VIDEOTOOLBOX:
+ return "_videotoolbox";
+ case AV_HWDEVICE_TYPE_D3D11VA:
+ case AV_HWDEVICE_TYPE_DXVA2:
+#if QT_FFMPEG_HAS_D3D12VA
+ case AV_HWDEVICE_TYPE_D3D12VA:
+#endif
+ return "_mf";
+ case AV_HWDEVICE_TYPE_CUDA:
+ case AV_HWDEVICE_TYPE_VDPAU:
+ return isEncoder ? "_nvenc" : "_cuvid";
+ default:
+ return nullptr;
+ }
+}
+
+template<typename CodecScoreGetter>
+const AVCodec *findAVCodec(CodecStorageType codecsType, AVCodecID codecId,
+ const CodecScoreGetter &scoreGetter)
+{
+ const auto &storage = codecsStorage(codecsType);
+ auto it = std::lower_bound(storage.begin(), storage.end(), codecId, CodecsComparator{});
+
+ const AVCodec *result = nullptr;
+ AVScore resultScore = NotSuitableAVScore;
+
+ for (; it != storage.end() && (*it)->id == codecId && resultScore != BestAVScore; ++it) {
+ const auto score = scoreGetter(*it);
+
+ if (score > resultScore) {
+ resultScore = score;
+ result = *it;
+ }
+ }
+
+ return result;
+}
+
+AVScore hwCodecNameScores(const AVCodec *codec, AVHWDeviceType deviceType)
+{
+ if (auto suffix = preferredHwCodecNameSuffix(av_codec_is_encoder(codec), deviceType)) {
+ const auto substr = strstr(codec->name, suffix);
+ if (substr && !substr[strlen(suffix)])
+ return BestAVScore;
+
+ return DefaultAVScore;
+ }
+
+ return BestAVScore;
+}
+
+const AVCodec *findAVCodec(CodecStorageType codecsType, AVCodecID codecId,
+ const std::optional<AVHWDeviceType> &deviceType,
+ const std::optional<PixelOrSampleFormat> &format)
+{
+ // TODO: remove deviceType and use only isAVFormatSupported to check the format
+
+ return findAVCodec(codecsType, codecId, [&](const AVCodec *codec) {
+ if (format && !isAVFormatSupported(codec, *format))
+ return NotSuitableAVScore;
+
+ if (!deviceType)
+ return BestAVScore; // find any codec with the id
+
+ if (*deviceType == AV_HWDEVICE_TYPE_NONE
+ && findAVFormat(codec->pix_fmts, &isSwPixelFormat) != AV_PIX_FMT_NONE)
+ return BestAVScore;
+
+ if (*deviceType != AV_HWDEVICE_TYPE_NONE) {
+ for (int index = 0; auto config = avcodec_get_hw_config(codec, index); ++index) {
+ if (config->device_type != deviceType)
+ continue;
+
+ if (format && config->pix_fmt != AV_PIX_FMT_NONE && config->pix_fmt != *format)
+ continue;
+
+ return hwCodecNameScores(codec, *deviceType);
+ }
+
+ // The situation happens mostly with encoders
+ // Probably, it's ffmpeg bug: avcodec_get_hw_config returns null even though
+ // hw acceleration is supported
+ // To be removed: only isAVFormatSupported should be used.
+ if (hasAVFormat(codec->pix_fmts, pixelFormatForHwDevice(*deviceType)))
+ return hwCodecNameScores(codec, *deviceType);
+ }
+
+ return NotSuitableAVScore;
+ });
+}
+
+} // namespace
+
+const AVCodec *findAVDecoder(AVCodecID codecId, const std::optional<AVHWDeviceType> &deviceType,
+ const std::optional<PixelOrSampleFormat> &format)
+{
+ return findAVCodec(DECODERS, codecId, deviceType, format);
+}
+
+const AVCodec *findAVEncoder(AVCodecID codecId, const std::optional<AVHWDeviceType> &deviceType,
+ const std::optional<PixelOrSampleFormat> &format)
+{
+ return findAVCodec(ENCODERS, codecId, deviceType, format);
+}
+
+const AVCodec *findAVEncoder(AVCodecID codecId,
+ const std::function<AVScore(const AVCodec *)> &scoresGetter)
+{
+ return findAVCodec(ENCODERS, codecId, scoresGetter);
+}
+
+bool isAVFormatSupported(const AVCodec *codec, PixelOrSampleFormat format)
+{
+ if (codec->type == AVMEDIA_TYPE_VIDEO) {
+ auto checkFormat = [format](AVPixelFormat f) { return f == format; };
+ return findAVPixelFormat(codec, checkFormat) != AV_PIX_FMT_NONE;
+ }
+
+ if (codec->type == AVMEDIA_TYPE_AUDIO)
+ return hasAVFormat(codec->sample_fmts, AVSampleFormat(format));
+
+ return false;
+}
+
+bool isHwPixelFormat(AVPixelFormat format)
+{
+ const auto desc = av_pix_fmt_desc_get(format);
+ return desc && (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) != 0;
+}
+
+bool isAVCodecExperimental(const AVCodec *codec)
+{
+ return (codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) != 0;
+}
+
+void applyExperimentalCodecOptions(const AVCodec *codec, AVDictionary** opts)
+{
+ if (isAVCodecExperimental(codec)) {
+ qCWarning(qLcFFmpegUtils) << "Applying the option 'strict -2' for the experimental codec"
+ << codec->name << ". it's unlikely to work properly";
+ av_dict_set(opts, "strict", "-2", 0);
+ }
+}
+
+AVPixelFormat pixelFormatForHwDevice(AVHWDeviceType deviceType)
+{
+ switch (deviceType) {
+ case AV_HWDEVICE_TYPE_VIDEOTOOLBOX:
+ return AV_PIX_FMT_VIDEOTOOLBOX;
+ case AV_HWDEVICE_TYPE_VAAPI:
+ return AV_PIX_FMT_VAAPI;
+ case AV_HWDEVICE_TYPE_MEDIACODEC:
+ return AV_PIX_FMT_MEDIACODEC;
+ case AV_HWDEVICE_TYPE_CUDA:
+ return AV_PIX_FMT_CUDA;
+ case AV_HWDEVICE_TYPE_VDPAU:
+ return AV_PIX_FMT_VDPAU;
+ case AV_HWDEVICE_TYPE_OPENCL:
+ return AV_PIX_FMT_OPENCL;
+ case AV_HWDEVICE_TYPE_QSV:
+ return AV_PIX_FMT_QSV;
+ case AV_HWDEVICE_TYPE_D3D11VA:
+ return AV_PIX_FMT_D3D11;
+#if QT_FFMPEG_HAS_D3D12VA
+ case AV_HWDEVICE_TYPE_D3D12VA:
+ return AV_PIX_FMT_D3D12;
+#endif
+ case AV_HWDEVICE_TYPE_DXVA2:
+ return AV_PIX_FMT_DXVA2_VLD;
+ case AV_HWDEVICE_TYPE_DRM:
+ return AV_PIX_FMT_DRM_PRIME;
+#if QT_FFMPEG_HAS_VULKAN
+ case AV_HWDEVICE_TYPE_VULKAN:
+ return AV_PIX_FMT_VULKAN;
+#endif
+ default:
+ return AV_PIX_FMT_NONE;
+ }
+}
+
+AVPacketSideData *addStreamSideData(AVStream *stream, AVPacketSideData sideData)
+{
+ QScopeGuard freeData([&sideData]() { av_free(sideData.data); });
+#if QT_FFMPEG_STREAM_SIDE_DATA_DEPRECATED
+ AVPacketSideData *result = av_packet_side_data_add(
+ &stream->codecpar->coded_side_data,
+ &stream->codecpar->nb_coded_side_data,
+ sideData.type,
+ sideData.data,
+ sideData.size,
+ 0);
+ if (result) {
+ // If the result is not null, the ownership is taken by AVStream,
+ // otherwise the data must be deleted.
+ freeData.dismiss();
+ return result;
+ }
+#else
+ Q_UNUSED(stream);
+ // TODO: implement for older FFmpeg versions
+ qWarning() << "Adding stream side data is not supported for FFmpeg < 6.1";
+#endif
+
+ return nullptr;
+}
+
+const AVPacketSideData *streamSideData(const AVStream *stream, AVPacketSideDataType type)
+{
+ Q_ASSERT(stream);
+
+#if QT_FFMPEG_STREAM_SIDE_DATA_DEPRECATED
+ return av_packet_side_data_get(stream->codecpar->coded_side_data,
+ stream->codecpar->nb_coded_side_data, type);
+#else
+ auto checkType = [type](const auto &item) { return item.type == type; };
+ const auto end = stream->side_data + stream->nb_side_data;
+ const auto found = std::find_if(stream->side_data, end, checkType);
+ return found == end ? nullptr : found;
+#endif
+}
+
+SwrContextUPtr createResampleContext(const AVAudioFormat &inputFormat,
+ const AVAudioFormat &outputFormat)
+{
+ SwrContext *resampler = nullptr;
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+ resampler = swr_alloc_set_opts(nullptr,
+ outputFormat.channelLayoutMask,
+ outputFormat.sampleFormat,
+ outputFormat.sampleRate,
+ inputFormat.channelLayoutMask,
+ inputFormat.sampleFormat,
+ inputFormat.sampleRate,
+ 0,
+ nullptr);
+#else
+
+#if QT_FFMPEG_SWR_CONST_CH_LAYOUT
+ using AVChannelLayoutPrm = const AVChannelLayout*;
+#else
+ using AVChannelLayoutPrm = AVChannelLayout*;
+#endif
+
+ swr_alloc_set_opts2(&resampler,
+ const_cast<AVChannelLayoutPrm>(&outputFormat.channelLayout),
+ outputFormat.sampleFormat,
+ outputFormat.sampleRate,
+ const_cast<AVChannelLayoutPrm>(&inputFormat.channelLayout),
+ inputFormat.sampleFormat,
+ inputFormat.sampleRate,
+ 0,
+ nullptr);
+#endif
+
+ swr_init(resampler);
+ return SwrContextUPtr(resampler);
+}
+
+QVideoFrameFormat::ColorTransfer fromAvColorTransfer(AVColorTransferCharacteristic colorTrc) {
+ switch (colorTrc) {
+ case AVCOL_TRC_BT709:
+ // The following three cases have transfer characteristics identical to BT709
+ case AVCOL_TRC_BT1361_ECG:
+ case AVCOL_TRC_BT2020_10:
+ case AVCOL_TRC_BT2020_12:
+ case AVCOL_TRC_SMPTE240M: // almost identical to bt709
+ return QVideoFrameFormat::ColorTransfer_BT709;
+ case AVCOL_TRC_GAMMA22:
+ case AVCOL_TRC_SMPTE428: // No idea, let's hope for the best...
+ case AVCOL_TRC_IEC61966_2_1: // sRGB, close enough to 2.2...
+ case AVCOL_TRC_IEC61966_2_4: // not quite, but probably close enough
+ return QVideoFrameFormat::ColorTransfer_Gamma22;
+ case AVCOL_TRC_GAMMA28:
+ return QVideoFrameFormat::ColorTransfer_Gamma28;
+ case AVCOL_TRC_SMPTE170M:
+ return QVideoFrameFormat::ColorTransfer_BT601;
+ case AVCOL_TRC_LINEAR:
+ return QVideoFrameFormat::ColorTransfer_Linear;
+ case AVCOL_TRC_SMPTE2084:
+ return QVideoFrameFormat::ColorTransfer_ST2084;
+ case AVCOL_TRC_ARIB_STD_B67:
+ return QVideoFrameFormat::ColorTransfer_STD_B67;
+ default:
+ break;
+ }
+ return QVideoFrameFormat::ColorTransfer_Unknown;
+}
+
+#ifdef Q_OS_DARWIN
+bool isCVFormatSupported(uint32_t cvFormat)
+{
+ return av_map_videotoolbox_format_to_pixfmt(cvFormat) != AV_PIX_FMT_NONE;
+}
+
+std::string cvFormatToString(uint32_t cvFormat)
+{
+ auto formatDescIt = std::make_reverse_iterator(reinterpret_cast<const char *>(&cvFormat));
+ return std::string(formatDescIt - 4, formatDescIt);
+}
+
+#endif
+
+} // namespace QFFmpeg
+
+QDebug operator<<(QDebug dbg, const AVRational &value)
+{
+ dbg << value.num << "/" << value.den;
+ return dbg;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeg_p.h b/src/plugins/multimedia/ffmpeg/qffmpeg_p.h
new file mode 100644
index 000000000..09bf7e4f4
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeg_p.h
@@ -0,0 +1,280 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEG_P_H
+#define QFFMPEG_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpegdefs_p.h"
+#include "qffmpegavaudioformat_p.h"
+#include <QtMultimedia/qvideoframeformat.h>
+
+#include <qstring.h>
+#include <optional>
+
+inline bool operator==(const AVRational &lhs, const AVRational &rhs)
+{
+ return lhs.num == rhs.num && lhs.den == rhs.den;
+}
+
+inline bool operator!=(const AVRational &lhs, const AVRational &rhs)
+{
+ return !(lhs == rhs);
+}
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg
+{
+
+inline std::optional<qint64> mul(qint64 a, AVRational b)
+{
+ return b.den != 0 ? (a * b.num + b.den / 2) / b.den : std::optional<qint64>{};
+}
+
+inline std::optional<qreal> mul(qreal a, AVRational b)
+{
+ return b.den != 0 ? a * qreal(b.num) / qreal(b.den) : std::optional<qreal>{};
+}
+
+inline std::optional<qint64> timeStampMs(qint64 ts, AVRational base)
+{
+ return mul(1'000 * ts, base);
+}
+
+inline std::optional<qint64> timeStampUs(qint64 ts, AVRational base)
+{
+ return mul(1'000'000 * ts, base);
+}
+
+inline std::optional<float> toFloat(AVRational r)
+{
+ return r.den != 0 ? float(r.num) / float(r.den) : std::optional<float>{};
+}
+
+inline QString err2str(int errnum)
+{
+ char buffer[AV_ERROR_MAX_STRING_SIZE + 1] = {};
+ av_make_error_string(buffer, AV_ERROR_MAX_STRING_SIZE, errnum);
+ return QString::fromLocal8Bit(buffer);
+}
+
+inline void setAVFrameTime(AVFrame &frame, int64_t pts, const AVRational &timeBase)
+{
+ frame.pts = pts;
+#if QT_FFMPEG_HAS_FRAME_TIME_BASE
+ frame.time_base = timeBase;
+#else
+ Q_UNUSED(timeBase);
+#endif
+}
+
+inline void getAVFrameTime(const AVFrame &frame, int64_t &pts, AVRational &timeBase)
+{
+ pts = frame.pts;
+#if QT_FFMPEG_HAS_FRAME_TIME_BASE
+ timeBase = frame.time_base;
+#else
+ timeBase = { 0, 1 };
+#endif
+}
+
+inline int64_t getAVFrameDuration(const AVFrame &frame)
+{
+#if QT_FFMPEG_HAS_FRAME_DURATION
+ return frame.duration;
+#else
+ Q_UNUSED(frame);
+ return 0;
+#endif
+}
+
+struct AVDictionaryHolder
+{
+ AVDictionary *opts = nullptr;
+
+ operator AVDictionary **() { return &opts; }
+
+ AVDictionaryHolder() = default;
+
+ Q_DISABLE_COPY(AVDictionaryHolder)
+
+ AVDictionaryHolder(AVDictionaryHolder &&other) noexcept
+ : opts(std::exchange(other.opts, nullptr))
+ {
+ }
+
+ ~AVDictionaryHolder()
+ {
+ if (opts)
+ av_dict_free(&opts);
+ }
+};
+
+template<typename FunctionType, FunctionType F>
+struct AVDeleter
+{
+ template<typename T>
+ void operator()(T *object) const
+ {
+ if (object)
+ F(&object);
+ }
+};
+
+using AVFrameUPtr = std::unique_ptr<AVFrame, AVDeleter<decltype(&av_frame_free), &av_frame_free>>;
+
+inline AVFrameUPtr makeAVFrame()
+{
+ return AVFrameUPtr(av_frame_alloc());
+}
+
+using AVPacketUPtr =
+ std::unique_ptr<AVPacket, AVDeleter<decltype(&av_packet_free), &av_packet_free>>;
+
+using AVCodecContextUPtr =
+ std::unique_ptr<AVCodecContext,
+ AVDeleter<decltype(&avcodec_free_context), &avcodec_free_context>>;
+
+using AVBufferUPtr =
+ std::unique_ptr<AVBufferRef, AVDeleter<decltype(&av_buffer_unref), &av_buffer_unref>>;
+
+using AVHWFramesConstraintsUPtr = std::unique_ptr<
+ AVHWFramesConstraints,
+ AVDeleter<decltype(&av_hwframe_constraints_free), &av_hwframe_constraints_free>>;
+
+using SwrContextUPtr = std::unique_ptr<SwrContext, AVDeleter<decltype(&swr_free), &swr_free>>;
+
+using PixelOrSampleFormat = int;
+using AVScore = int;
+constexpr AVScore BestAVScore = std::numeric_limits<AVScore>::max();
+constexpr AVScore DefaultAVScore = 0;
+constexpr AVScore NotSuitableAVScore = std::numeric_limits<AVScore>::min();
+constexpr AVScore MinAVScore = NotSuitableAVScore + 1;
+
+const AVCodec *findAVDecoder(AVCodecID codecId,
+ const std::optional<AVHWDeviceType> &deviceType = {},
+ const std::optional<PixelOrSampleFormat> &format = {});
+
+const AVCodec *findAVEncoder(AVCodecID codecId,
+ const std::optional<AVHWDeviceType> &deviceType = {},
+ const std::optional<PixelOrSampleFormat> &format = {});
+
+const AVCodec *findAVEncoder(AVCodecID codecId,
+ const std::function<AVScore(const AVCodec *)> &scoresGetter);
+
+bool isAVFormatSupported(const AVCodec *codec, PixelOrSampleFormat format);
+
+template<typename Format>
+bool hasAVFormat(const Format *fmts, Format format)
+{
+ return findAVFormat(fmts, [format](Format f) { return f == format; }) != Format(-1);
+}
+
+template<typename Format, typename Predicate>
+Format findAVFormat(const Format *fmts, const Predicate &predicate)
+{
+ auto scoresGetter = [&predicate](Format fmt) {
+ return predicate(fmt) ? BestAVScore : NotSuitableAVScore;
+ };
+ return findBestAVFormat(fmts, scoresGetter).first;
+}
+
+template <typename Predicate>
+const AVCodecHWConfig *findHwConfig(const AVCodec *codec, const Predicate &predicate)
+{
+ for (int i = 0; const auto hwConfig = avcodec_get_hw_config(codec, i); ++i) {
+ if (predicate(hwConfig))
+ return hwConfig;
+ }
+
+ return nullptr;
+}
+
+template <typename Predicate>
+AVPixelFormat findAVPixelFormat(const AVCodec *codec, const Predicate &predicate)
+{
+ const AVPixelFormat format = findAVFormat(codec->pix_fmts, predicate);
+ if (format != AV_PIX_FMT_NONE)
+ return format;
+
+ auto checkHwConfig = [&predicate](const AVCodecHWConfig *config) {
+ return config->pix_fmt != AV_PIX_FMT_NONE && predicate(config->pix_fmt);
+ };
+
+ if (auto hwConfig = findHwConfig(codec, checkHwConfig))
+ return hwConfig->pix_fmt;
+
+ return AV_PIX_FMT_NONE;
+}
+
+template <typename Value, typename CalculateScore>
+auto findBestAVValue(const Value *values, const CalculateScore &calculateScore,
+ Value invalidValue = {})
+{
+ using Limits = std::numeric_limits<decltype(calculateScore(*values))>;
+ std::pair result(invalidValue, Limits::min());
+ if (values) {
+ for (; *values != invalidValue && result.second != Limits::max(); ++values) {
+ const auto score = calculateScore(*values);
+ if (score > result.second)
+ result = { *values, score };
+ }
+ }
+
+ return result;
+}
+
+template <typename Format, typename CalculateScore>
+std::pair<Format, AVScore> findBestAVFormat(const Format *fmts,
+ const CalculateScore &calculateScore)
+{
+ static_assert(std::is_same_v<Format, AVSampleFormat> || std::is_same_v<Format, AVPixelFormat>,
+ "The input value is not AV format, use findBestAVValue instead.");
+ return findBestAVValue(fmts, calculateScore, Format(-1));
+}
+
+bool isHwPixelFormat(AVPixelFormat format);
+
+inline bool isSwPixelFormat(AVPixelFormat format)
+{
+ return !isHwPixelFormat(format);
+}
+
+bool isAVCodecExperimental(const AVCodec *codec);
+
+void applyExperimentalCodecOptions(const AVCodec *codec, AVDictionary** opts);
+
+AVPixelFormat pixelFormatForHwDevice(AVHWDeviceType deviceType);
+
+AVPacketSideData *addStreamSideData(AVStream *stream, AVPacketSideData sideData);
+
+const AVPacketSideData *streamSideData(const AVStream *stream, AVPacketSideDataType type);
+
+SwrContextUPtr createResampleContext(const AVAudioFormat &inputFormat,
+ const AVAudioFormat &outputFormat);
+
+QVideoFrameFormat::ColorTransfer fromAvColorTransfer(AVColorTransferCharacteristic colorTrc);
+
+#ifdef Q_OS_DARWIN
+bool isCVFormatSupported(uint32_t format);
+
+std::string cvFormatToString(uint32_t format);
+
+#endif
+}
+
+QDebug operator<<(QDebug, const AVRational &);
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegaudiodecoder.cpp b/src/plugins/multimedia/ffmpeg/qffmpegaudiodecoder.cpp
new file mode 100644
index 000000000..69820cc79
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegaudiodecoder.cpp
@@ -0,0 +1,247 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qffmpegaudiodecoder_p.h"
+#include "qffmpegresampler_p.h"
+#include "qaudiobuffer.h"
+
+#include "qffmpegplaybackengine_p.h"
+#include "playbackengine/qffmpegrenderer_p.h"
+
+#include <qloggingcategory.h>
+
+static Q_LOGGING_CATEGORY(qLcAudioDecoder, "qt.multimedia.ffmpeg.audioDecoder")
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg
+{
+
+class SteppingAudioRenderer : public Renderer
+{
+ Q_OBJECT
+public:
+ SteppingAudioRenderer(const QAudioFormat &format) : Renderer({}), m_format(format) { }
+
+ RenderingResult renderInternal(Frame frame) override
+ {
+ if (!frame.isValid())
+ return {};
+
+ if (!m_resampler)
+ m_resampler = std::make_unique<QFFmpegResampler>(frame.codec(), m_format);
+
+ emit newAudioBuffer(m_resampler->resample(frame.avFrame()));
+
+ return {};
+ }
+
+signals:
+ void newAudioBuffer(QAudioBuffer);
+
+private:
+ QAudioFormat m_format;
+ std::unique_ptr<QFFmpegResampler> m_resampler;
+};
+
+class AudioDecoder : public PlaybackEngine
+{
+ Q_OBJECT
+public:
+ explicit AudioDecoder(const QAudioFormat &format) : m_format(format) { }
+
+ RendererPtr createRenderer(QPlatformMediaPlayer::TrackType trackType) override
+ {
+ if (trackType != QPlatformMediaPlayer::AudioStream)
+ return RendererPtr{ {}, {} };
+
+ auto result = createPlaybackEngineObject<SteppingAudioRenderer>(m_format);
+ m_audioRenderer = result.get();
+
+ connect(result.get(), &SteppingAudioRenderer::newAudioBuffer, this,
+ &AudioDecoder::newAudioBuffer);
+
+ return result;
+ }
+
+ void nextBuffer()
+ {
+ Q_ASSERT(m_audioRenderer);
+ Q_ASSERT(!m_audioRenderer->isStepForced());
+
+ m_audioRenderer->doForceStep();
+ // updateObjectsPausedState();
+ }
+
+signals:
+ void newAudioBuffer(QAudioBuffer);
+
+private:
+ QPointer<Renderer> m_audioRenderer;
+ QAudioFormat m_format;
+};
+}
+
+
+QFFmpegAudioDecoder::QFFmpegAudioDecoder(QAudioDecoder *parent)
+ : QPlatformAudioDecoder(parent)
+{
+}
+
+QFFmpegAudioDecoder::~QFFmpegAudioDecoder() = default;
+
+QUrl QFFmpegAudioDecoder::source() const
+{
+ return m_url;
+}
+
+void QFFmpegAudioDecoder::setSource(const QUrl &fileName)
+{
+ stop();
+ m_sourceDevice = nullptr;
+
+ if (std::exchange(m_url, fileName) != fileName)
+ sourceChanged();
+}
+
+QIODevice *QFFmpegAudioDecoder::sourceDevice() const
+{
+ return m_sourceDevice;
+}
+
+void QFFmpegAudioDecoder::setSourceDevice(QIODevice *device)
+{
+ stop();
+ m_url.clear();
+ if (std::exchange(m_sourceDevice, device) != device)
+ sourceChanged();
+}
+
+void QFFmpegAudioDecoder::start()
+{
+ qCDebug(qLcAudioDecoder) << "start";
+ auto checkNoError = [this]() {
+ if (error() == QAudioDecoder::NoError)
+ return true;
+
+ durationChanged(-1);
+ positionChanged(-1);
+
+ m_decoder.reset();
+
+ return false;
+ };
+
+ m_decoder = std::make_unique<AudioDecoder>(m_audioFormat);
+ connect(m_decoder.get(), &AudioDecoder::errorOccured, this, &QFFmpegAudioDecoder::errorSignal);
+ connect(m_decoder.get(), &AudioDecoder::endOfStream, this, &QFFmpegAudioDecoder::done);
+ connect(m_decoder.get(), &AudioDecoder::newAudioBuffer, this,
+ &QFFmpegAudioDecoder::newAudioBuffer);
+
+ QFFmpeg::MediaDataHolder::Maybe media = QFFmpeg::MediaDataHolder::create(m_url, m_sourceDevice, nullptr);
+
+ if (media) {
+ Q_ASSERT(media.value());
+ if (media.value()->streamInfo(QPlatformMediaPlayer::AudioStream).isEmpty())
+ error(QAudioDecoder::FormatError,
+ QLatin1String("The media doesn't contain an audio stream"));
+ else
+ m_decoder->setMedia(std::move(*media.value()));
+ } else {
+ auto [code, description] = media.error();
+ errorSignal(code, description);
+ }
+
+ if (!checkNoError())
+ return;
+
+ m_decoder->setState(QMediaPlayer::PausedState);
+ if (!checkNoError())
+ return;
+
+ m_decoder->nextBuffer();
+ if (!checkNoError())
+ return;
+
+ durationChanged(m_decoder->duration() / 1000);
+ setIsDecoding(true);
+}
+
+void QFFmpegAudioDecoder::stop()
+{
+ qCDebug(qLcAudioDecoder) << ">>>>> stop";
+ if (m_decoder) {
+ m_decoder.reset();
+ done();
+ }
+}
+
+QAudioFormat QFFmpegAudioDecoder::audioFormat() const
+{
+ return m_audioFormat;
+}
+
+void QFFmpegAudioDecoder::setAudioFormat(const QAudioFormat &format)
+{
+ if (std::exchange(m_audioFormat, format) != format)
+ formatChanged(m_audioFormat);
+}
+
+QAudioBuffer QFFmpegAudioDecoder::read()
+{
+ auto buffer = std::exchange(m_audioBuffer, QAudioBuffer{});
+ if (!buffer.isValid())
+ return buffer;
+ qCDebug(qLcAudioDecoder) << "reading buffer" << buffer.startTime();
+ bufferAvailableChanged(false);
+ if (m_decoder)
+ m_decoder->nextBuffer();
+ return buffer;
+}
+
+void QFFmpegAudioDecoder::newAudioBuffer(const QAudioBuffer &b)
+{
+ Q_ASSERT(b.isValid());
+ Q_ASSERT(!m_audioBuffer.isValid());
+ Q_ASSERT(!bufferAvailable());
+
+ qCDebug(qLcAudioDecoder) << "new audio buffer" << b.startTime();
+ m_audioBuffer = b;
+ const qint64 pos = b.startTime();
+ positionChanged(pos/1000);
+ bufferAvailableChanged(b.isValid());
+ bufferReady();
+}
+
+void QFFmpegAudioDecoder::done()
+{
+ qCDebug(qLcAudioDecoder) << ">>>>> DONE!";
+ finished();
+}
+
+void QFFmpegAudioDecoder::errorSignal(int err, const QString &errorString)
+{
+ // unfortunately the error enums for QAudioDecoder and QMediaPlayer aren't identical.
+ // Map them.
+ switch (QMediaPlayer::Error(err)) {
+ case QMediaPlayer::NoError:
+ error(QAudioDecoder::NoError, errorString);
+ break;
+ case QMediaPlayer::ResourceError:
+ error(QAudioDecoder::ResourceError, errorString);
+ break;
+ case QMediaPlayer::FormatError:
+ error(QAudioDecoder::FormatError, errorString);
+ break;
+ case QMediaPlayer::NetworkError:
+ // fall through, Network error doesn't exist in QAudioDecoder
+ case QMediaPlayer::AccessDeniedError:
+ error(QAudioDecoder::AccessDeniedError, errorString);
+ break;
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegaudiodecoder_p.cpp"
+
+#include "qffmpegaudiodecoder.moc"
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegaudiodecoder_p.h b/src/plugins/multimedia/ffmpeg/qffmpegaudiodecoder_p.h
new file mode 100644
index 000000000..11816cd6f
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegaudiodecoder_p.h
@@ -0,0 +1,68 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGAUDIODECODER_H
+#define QFFMPEGAUDIODECODER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qplatformaudiodecoder_p.h"
+#include <qffmpeg_p.h>
+#include <qurl.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+class AudioDecoder;
+}
+
+class QFFmpegAudioDecoder : public QPlatformAudioDecoder
+{
+ Q_OBJECT
+
+public:
+ QFFmpegAudioDecoder(QAudioDecoder *parent);
+ virtual ~QFFmpegAudioDecoder();
+
+ QUrl source() const override;
+ void setSource(const QUrl &fileName) override;
+
+ QIODevice *sourceDevice() const override;
+ void setSourceDevice(QIODevice *device) override;
+
+ void start() override;
+ void stop() override;
+
+ QAudioFormat audioFormat() const override;
+ void setAudioFormat(const QAudioFormat &format) override;
+
+ QAudioBuffer read() override;
+
+public Q_SLOTS:
+ void newAudioBuffer(const QAudioBuffer &b);
+ void done();
+ void errorSignal(int err, const QString &errorString);
+
+private:
+ using AudioDecoder = QFFmpeg::AudioDecoder;
+
+ QUrl m_url;
+ QIODevice *m_sourceDevice = nullptr;
+ std::unique_ptr<AudioDecoder> m_decoder;
+ QAudioFormat m_audioFormat;
+
+ QAudioBuffer m_audioBuffer;
+};
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGAUDIODECODER_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegaudioinput.cpp b/src/plugins/multimedia/ffmpeg/qffmpegaudioinput.cpp
new file mode 100644
index 000000000..014c53ca4
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegaudioinput.cpp
@@ -0,0 +1,195 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qffmpegaudioinput_p.h"
+#include <qiodevice.h>
+#include <qaudiosource.h>
+#include <qaudiobuffer.h>
+#include <qatomic.h>
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+class AudioSourceIO : public QIODevice
+{
+ Q_OBJECT
+public:
+ AudioSourceIO(QFFmpegAudioInput *audioInput) : QIODevice(), m_input(audioInput)
+ {
+ m_muted = m_input->muted;
+ m_volume = m_input->volume;
+ updateVolume();
+ open(QIODevice::WriteOnly);
+ }
+
+ ~AudioSourceIO() override = default;
+
+ void setDevice(const QAudioDevice &device)
+ {
+ QMutexLocker locker(&m_mutex);
+ if (m_device == device)
+ return;
+ m_device = device;
+ QMetaObject::invokeMethod(this, "updateSource");
+ }
+ void setFrameSize(int frameSize)
+ {
+ m_bufferSize.storeRelease((frameSize > 0 && m_format.isValid())
+ ? m_format.bytesForFrames(frameSize)
+ : DefaultAudioInputBufferSize);
+ }
+ void setRunning(bool r) {
+ QMutexLocker locker(&m_mutex);
+ if (m_running == r)
+ return;
+ m_running = r;
+ QMetaObject::invokeMethod(this, "updateRunning");
+ }
+
+ void setVolume(float vol) {
+ QMutexLocker locker(&m_mutex);
+ m_volume = vol;
+ QMetaObject::invokeMethod(this, "updateVolume");
+ }
+ void setMuted(bool muted) {
+ QMutexLocker locker(&m_mutex);
+ m_muted = muted;
+ QMetaObject::invokeMethod(this, "updateVolume");
+ }
+
+ int bufferSize() const { return m_bufferSize.loadAcquire(); }
+
+protected:
+ qint64 readData(char *, qint64) override
+ {
+ return 0;
+ }
+ qint64 writeData(const char *data, qint64 len) override
+ {
+ int l = len;
+ while (len > 0) {
+ const auto bufferSize = m_bufferSize.loadAcquire();
+ int toAppend = qMin(len, bufferSize - m_pcm.size());
+ m_pcm.append(data, toAppend);
+ data += toAppend;
+ len -= toAppend;
+ if (m_pcm.size() == bufferSize)
+ sendBuffer();
+ }
+
+ return l;
+ }
+
+private Q_SLOTS:
+ void updateSource() {
+ QMutexLocker locker(&m_mutex);
+ m_format = m_device.preferredFormat();
+ if (std::exchange(m_src, nullptr))
+ m_pcm.clear();
+
+ m_src = std::make_unique<QAudioSource>(m_device, m_format);
+ updateVolume();
+ if (m_running)
+ m_src->start(this);
+ }
+ void updateVolume()
+ {
+ if (m_src)
+ m_src->setVolume(m_muted ? 0. : m_volume);
+ }
+ void updateRunning()
+ {
+ QMutexLocker locker(&m_mutex);
+ if (m_running) {
+ if (!m_src)
+ updateSource();
+ m_src->start(this);
+ } else {
+ m_src->stop();
+ }
+ }
+
+private:
+
+ void sendBuffer()
+ {
+ QAudioFormat fmt = m_src->format();
+ qint64 time = fmt.durationForBytes(m_processed);
+ QAudioBuffer buffer(m_pcm, fmt, time);
+ emit m_input->newAudioBuffer(buffer);
+ m_processed += m_pcm.size();
+ m_pcm.clear();
+ }
+
+ QMutex m_mutex;
+ QAudioDevice m_device;
+ float m_volume = 1.;
+ bool m_muted = false;
+ bool m_running = false;
+
+ QFFmpegAudioInput *m_input = nullptr;
+ std::unique_ptr<QAudioSource> m_src;
+ QAudioFormat m_format;
+ QAtomicInt m_bufferSize = DefaultAudioInputBufferSize;
+ qint64 m_processed = 0;
+ QByteArray m_pcm;
+};
+
+}
+
+QFFmpegAudioInput::QFFmpegAudioInput(QAudioInput *qq)
+ : QPlatformAudioInput(qq)
+{
+ qRegisterMetaType<QAudioBuffer>();
+
+ inputThread = std::make_unique<QThread>();
+ audioIO = new QFFmpeg::AudioSourceIO(this);
+ audioIO->moveToThread(inputThread.get());
+ inputThread->start();
+}
+
+QFFmpegAudioInput::~QFFmpegAudioInput()
+{
+ // Ensure that COM is uninitialized by nested QWindowsResampler
+ // on the same thread that initialized it.
+ audioIO->deleteLater();
+ inputThread->exit();
+ inputThread->wait();
+}
+
+void QFFmpegAudioInput::setAudioDevice(const QAudioDevice &device)
+{
+ audioIO->setDevice(device);
+}
+
+void QFFmpegAudioInput::setMuted(bool muted)
+{
+ audioIO->setMuted(muted);
+}
+
+void QFFmpegAudioInput::setVolume(float volume)
+{
+ audioIO->setVolume(volume);
+}
+
+void QFFmpegAudioInput::setFrameSize(int s)
+{
+ audioIO->setFrameSize(s);
+}
+
+void QFFmpegAudioInput::setRunning(bool b)
+{
+ audioIO->setRunning(b);
+}
+
+int QFFmpegAudioInput::bufferSize() const
+{
+ return audioIO->bufferSize();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegaudioinput_p.cpp"
+
+#include "qffmpegaudioinput.moc"
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegaudioinput_p.h b/src/plugins/multimedia/ffmpeg/qffmpegaudioinput_p.h
new file mode 100644
index 000000000..288b3f432
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegaudioinput_p.h
@@ -0,0 +1,57 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGAUDIOINPUT_H
+#define QFFMPEGAUDIOINPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformaudioinput_p.h>
+#include <private/qplatformaudiobufferinput_p.h>
+#include "qffmpegthread_p.h"
+#include <qaudioinput.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioSource;
+class QAudioBuffer;
+namespace QFFmpeg {
+class AudioSourceIO;
+}
+
+constexpr int DefaultAudioInputBufferSize = 4096;
+
+class QFFmpegAudioInput : public QPlatformAudioBufferInputBase, public QPlatformAudioInput
+{
+ // for qobject_cast
+ Q_OBJECT
+public:
+ QFFmpegAudioInput(QAudioInput *qq);
+ ~QFFmpegAudioInput();
+
+ void setAudioDevice(const QAudioDevice &/*device*/) override;
+ void setMuted(bool /*muted*/) override;
+ void setVolume(float /*volume*/) override;
+
+ void setFrameSize(int frameSize);
+ void setRunning(bool b);
+
+ int bufferSize() const;
+
+private:
+ QFFmpeg::AudioSourceIO *audioIO = nullptr;
+ std::unique_ptr<QThread> inputThread;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QPLATFORMAUDIOINPUT_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegavaudioformat.cpp b/src/plugins/multimedia/ffmpeg/qffmpegavaudioformat.cpp
new file mode 100644
index 000000000..417219a48
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegavaudioformat.cpp
@@ -0,0 +1,78 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegavaudioformat_p.h"
+#include "qaudioformat.h"
+#include "qffmpegmediaformatinfo_p.h"
+
+extern "C" {
+#include <libavutil/opt.h>
+}
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+AVAudioFormat::AVAudioFormat(const AVCodecContext *context)
+ : sampleFormat(context->sample_fmt), sampleRate(context->sample_rate)
+{
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+ if (context->channel_layout) {
+ channelLayoutMask = context->channel_layout;
+ } else {
+ const auto channelConfig =
+ QAudioFormat::defaultChannelConfigForChannelCount(context->channels);
+ channelLayoutMask = QFFmpegMediaFormatInfo::avChannelLayout(channelConfig);
+ }
+#else
+ channelLayout = context->ch_layout;
+#endif
+}
+
+AVAudioFormat::AVAudioFormat(const AVCodecParameters *codecPar)
+ : sampleFormat(AVSampleFormat(codecPar->format)), sampleRate(codecPar->sample_rate)
+{
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+ if (codecPar->channel_layout) {
+ channelLayoutMask = codecPar->channel_layout;
+ } else {
+ const auto channelConfig =
+ QAudioFormat::defaultChannelConfigForChannelCount(codecPar->channels);
+ channelLayoutMask = QFFmpegMediaFormatInfo::avChannelLayout(channelConfig);
+ }
+#else
+ channelLayout = codecPar->ch_layout;
+#endif
+}
+
+AVAudioFormat::AVAudioFormat(const QAudioFormat &audioFormat)
+ : sampleFormat(QFFmpegMediaFormatInfo::avSampleFormat(audioFormat.sampleFormat())),
+ sampleRate(audioFormat.sampleRate())
+{
+ const auto channelConfig = audioFormat.channelConfig() == QAudioFormat::ChannelConfigUnknown
+ ? QAudioFormat::defaultChannelConfigForChannelCount(audioFormat.channelCount())
+ : audioFormat.channelConfig();
+
+ const auto mask = QFFmpegMediaFormatInfo::avChannelLayout(channelConfig);
+
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+ channelLayoutMask = mask;
+#else
+ av_channel_layout_from_mask(&channelLayout, mask);
+#endif
+}
+
+bool operator==(const AVAudioFormat &lhs, const AVAudioFormat &rhs)
+{
+ return lhs.sampleFormat == rhs.sampleFormat && lhs.sampleRate == rhs.sampleRate &&
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+ lhs.channelLayoutMask == rhs.channelLayoutMask
+#else
+ lhs.channelLayout == rhs.channelLayout
+#endif
+ ;
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegavaudioformat_p.h b/src/plugins/multimedia/ffmpeg/qffmpegavaudioformat_p.h
new file mode 100644
index 000000000..9fd4dacdf
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegavaudioformat_p.h
@@ -0,0 +1,68 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGAVAUDIOFORMAT_P_H
+#define QFFMPEGAVAUDIOFORMAT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpegdefs_p.h"
+#include <private/qtmultimediaglobal_p.h>
+
+#if !QT_FFMPEG_OLD_CHANNEL_LAYOUT
+inline bool operator==(const AVChannelLayout &lhs, const AVChannelLayout &rhs)
+{
+ return lhs.order == rhs.order && lhs.nb_channels == rhs.nb_channels && lhs.u.mask == rhs.u.mask;
+}
+
+inline bool operator!=(const AVChannelLayout &lhs, const AVChannelLayout &rhs)
+{
+ return !(lhs == rhs);
+}
+
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class QAudioFormat;
+
+namespace QFFmpeg {
+
+struct AVAudioFormat
+{
+ AVAudioFormat(const AVCodecContext *context);
+
+ AVAudioFormat(const AVCodecParameters *codecPar);
+
+ AVAudioFormat(const QAudioFormat &audioFormat);
+
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+ uint64_t channelLayoutMask;
+#else
+ AVChannelLayout channelLayout;
+#endif
+ AVSampleFormat sampleFormat;
+ int sampleRate;
+};
+
+bool operator==(const AVAudioFormat &lhs, const AVAudioFormat &rhs);
+
+inline bool operator!=(const AVAudioFormat &lhs, const AVAudioFormat &rhs)
+{
+ return !(lhs == rhs);
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGAVAUDIOFORMAT_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegconverter.cpp b/src/plugins/multimedia/ffmpeg/qffmpegconverter.cpp
new file mode 100644
index 000000000..ba87ce3ed
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegconverter.cpp
@@ -0,0 +1,272 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegconverter_p.h"
+#include <QtMultimedia/qvideoframeformat.h>
+#include <QtMultimedia/qvideoframe.h>
+#include <QtCore/qloggingcategory.h>
+#include <private/qvideotexturehelper_p.h>
+
+extern "C" {
+#include <libswscale/swscale.h>
+}
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+
+Q_LOGGING_CATEGORY(lc, "qt.multimedia.ffmpeg.converter");
+
+
+// Converts to FFmpeg pixel format. This function differs from
+// QFFmpegVideoBuffer::toAVPixelFormat which only covers the subset
+// of pixel formats required for encoding. Here we need to cover more
+// pixel formats to be able to generate test images for decoding/display
+AVPixelFormat toAVPixelFormat(QVideoFrameFormat::PixelFormat pixelFormat)
+{
+ switch (pixelFormat) {
+ default:
+ case QVideoFrameFormat::Format_Invalid:
+ return AV_PIX_FMT_NONE;
+ case QVideoFrameFormat::Format_AYUV:
+ case QVideoFrameFormat::Format_AYUV_Premultiplied:
+ return AV_PIX_FMT_NONE; // TODO: Fixme (No corresponding FFmpeg format available)
+ case QVideoFrameFormat::Format_YV12:
+ case QVideoFrameFormat::Format_IMC1:
+ case QVideoFrameFormat::Format_IMC3:
+ case QVideoFrameFormat::Format_IMC2:
+ case QVideoFrameFormat::Format_IMC4:
+ return AV_PIX_FMT_YUV420P;
+ case QVideoFrameFormat::Format_Jpeg:
+ return AV_PIX_FMT_BGRA;
+ case QVideoFrameFormat::Format_ARGB8888:
+ return AV_PIX_FMT_ARGB;
+ case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
+ case QVideoFrameFormat::Format_XRGB8888:
+ return AV_PIX_FMT_0RGB;
+ case QVideoFrameFormat::Format_BGRA8888:
+ return AV_PIX_FMT_BGRA;
+ case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
+ case QVideoFrameFormat::Format_BGRX8888:
+ return AV_PIX_FMT_BGR0;
+ case QVideoFrameFormat::Format_ABGR8888:
+ return AV_PIX_FMT_ABGR;
+ case QVideoFrameFormat::Format_XBGR8888:
+ return AV_PIX_FMT_0BGR;
+ case QVideoFrameFormat::Format_RGBA8888:
+ return AV_PIX_FMT_RGBA;
+ case QVideoFrameFormat::Format_RGBX8888:
+ return AV_PIX_FMT_RGB0;
+ case QVideoFrameFormat::Format_YUV422P:
+ return AV_PIX_FMT_YUV422P;
+ case QVideoFrameFormat::Format_YUV420P:
+ return AV_PIX_FMT_YUV420P;
+ case QVideoFrameFormat::Format_YUV420P10:
+ return AV_PIX_FMT_YUV420P10;
+ case QVideoFrameFormat::Format_UYVY:
+ return AV_PIX_FMT_UYVY422;
+ case QVideoFrameFormat::Format_YUYV:
+ return AV_PIX_FMT_YUYV422;
+ case QVideoFrameFormat::Format_NV12:
+ return AV_PIX_FMT_NV12;
+ case QVideoFrameFormat::Format_NV21:
+ return AV_PIX_FMT_NV21;
+ case QVideoFrameFormat::Format_Y8:
+ return AV_PIX_FMT_GRAY8;
+ case QVideoFrameFormat::Format_Y16:
+ return AV_PIX_FMT_GRAY16;
+ case QVideoFrameFormat::Format_P010:
+ return AV_PIX_FMT_P010;
+ case QVideoFrameFormat::Format_P016:
+ return AV_PIX_FMT_P016;
+ case QVideoFrameFormat::Format_SamplerExternalOES:
+ return AV_PIX_FMT_MEDIACODEC;
+ }
+}
+
+struct SwsFrameData
+{
+ static constexpr int arraySize = 4; // Array size required by sws_scale
+ std::array<uchar *, arraySize> bits;
+ std::array<int, arraySize> stride;
+};
+
+SwsFrameData getSwsData(QVideoFrame &dst)
+{
+ switch (dst.pixelFormat()) {
+ case QVideoFrameFormat::Format_YV12:
+ case QVideoFrameFormat::Format_IMC1:
+ return { { dst.bits(0), dst.bits(2), dst.bits(1), nullptr },
+ { dst.bytesPerLine(0), dst.bytesPerLine(2), dst.bytesPerLine(1), 0 } };
+
+ case QVideoFrameFormat::Format_IMC2:
+ return { { dst.bits(0), dst.bits(1) + dst.bytesPerLine(1) / 2, dst.bits(1), nullptr },
+ { dst.bytesPerLine(0), dst.bytesPerLine(1), dst.bytesPerLine(1), 0 } };
+
+ case QVideoFrameFormat::Format_IMC4:
+ return { { dst.bits(0), dst.bits(1), dst.bits(1) + dst.bytesPerLine(1) / 2, nullptr },
+ { dst.bytesPerLine(0), dst.bytesPerLine(1), dst.bytesPerLine(1), 0 } };
+ default:
+ return { { dst.bits(0), dst.bits(1), dst.bits(2), nullptr },
+ { dst.bytesPerLine(0), dst.bytesPerLine(1), dst.bytesPerLine(2), 0 } };
+ }
+}
+
+struct SwsColorSpace
+{
+ int colorSpace;
+ int colorRange; // 0 - mpeg/video, 1 - jpeg/full
+};
+
+// Qt heuristics for determining color space requires checking
+// both frame color space and range. This function mimics logic
+// used elsewhere in Qt Multimedia.
+SwsColorSpace toSwsColorSpace(QVideoFrameFormat::ColorRange colorRange,
+ QVideoFrameFormat::ColorSpace colorSpace)
+{
+ const int avRange = colorRange == QVideoFrameFormat::ColorRange_Video ? 0 : 1;
+
+ switch (colorSpace) {
+ case QVideoFrameFormat::ColorSpace_BT601:
+ if (colorRange == QVideoFrameFormat::ColorRange_Full)
+ return { SWS_CS_ITU709, 1 }; // TODO: FIXME - Not exact match
+ return { SWS_CS_ITU601, 0 };
+ case QVideoFrameFormat::ColorSpace_BT709:
+ return { SWS_CS_ITU709, avRange };
+ case QVideoFrameFormat::ColorSpace_AdobeRgb:
+ return { SWS_CS_ITU601, 1 }; // TODO: Why do ITU601 and Adobe RGB match well?
+ case QVideoFrameFormat::ColorSpace_BT2020:
+ return { SWS_CS_BT2020, avRange };
+ case QVideoFrameFormat::ColorSpace_Undefined:
+ default:
+ return { SWS_CS_DEFAULT, avRange };
+ }
+}
+
+using SwsContextUPtr = std::unique_ptr<SwsContext, decltype(&sws_freeContext)>;
+using PixelFormat = QVideoFrameFormat::PixelFormat;
+
+// clang-format off
+
+SwsContextUPtr createConverter(const QSize &srcSize, PixelFormat srcPixFmt,
+ const QSize &dstSize, PixelFormat dstPixFmt)
+{
+ SwsContext* context = sws_getContext(
+ srcSize.width(), srcSize.height(), toAVPixelFormat(srcPixFmt),
+ dstSize.width(), dstSize.height(), toAVPixelFormat(dstPixFmt),
+ SWS_BILINEAR, nullptr, nullptr, nullptr);
+
+ return { context, &sws_freeContext };
+}
+
+bool setColorSpaceDetails(SwsContext *context,
+ const QVideoFrameFormat &srcFormat,
+ const QVideoFrameFormat &dstFormat)
+{
+ const SwsColorSpace src = toSwsColorSpace(srcFormat.colorRange(), srcFormat.colorSpace());
+ const SwsColorSpace dst = toSwsColorSpace(dstFormat.colorRange(), dstFormat.colorSpace());
+
+ constexpr int brightness = 0;
+ constexpr int contrast = 0;
+ constexpr int saturation = 0;
+ const int status = sws_setColorspaceDetails(context,
+ sws_getCoefficients(src.colorSpace), src.colorRange,
+ sws_getCoefficients(dst.colorSpace), dst.colorRange,
+ brightness, contrast, saturation);
+
+ return status == 0;
+}
+
+bool convert(SwsContext *context, QVideoFrame &src, int srcHeight, QVideoFrame &dst)
+{
+ if (!src.map(QtVideo::MapMode::ReadOnly))
+ return false;
+
+ QScopeGuard unmapSrc{[&] {
+ src.unmap();
+ }};
+
+ if (!dst.map(QtVideo::MapMode::WriteOnly))
+ return false;
+
+ QScopeGuard unmapDst{[&] {
+ dst.unmap();
+ }};
+
+ const SwsFrameData srcData = getSwsData(src);
+ const SwsFrameData dstData = getSwsData(dst);
+
+ constexpr int firstSrcSliceRow = 0;
+ const int scaledHeight = sws_scale(context,
+ srcData.bits.data(), srcData.stride.data(),
+ firstSrcSliceRow, srcHeight,
+ dstData.bits.data(), dstData.stride.data());
+
+ if (scaledHeight != srcHeight)
+ return false;
+
+ return true;
+}
+
+// Ensure even size if using planar format with chroma subsampling
+QSize adjustSize(const QSize& size, PixelFormat srcFmt, PixelFormat dstFmt)
+{
+ const auto* srcDesc = QVideoTextureHelper::textureDescription(srcFmt);
+ const auto* dstDesc = QVideoTextureHelper::textureDescription(dstFmt);
+
+ QSize output = size;
+ for (const auto desc : { srcDesc, dstDesc }) {
+ for (int i = 0; i < desc->nplanes; ++i) {
+ // TODO: Assumes that max subsampling is 2
+ if (desc->sizeScale[i].x != 1)
+ output.setWidth(output.width() & ~1); // Make even
+
+ if (desc->sizeScale[i].y != 1)
+ output.setHeight(output.height() & ~1); // Make even
+ }
+ }
+
+ return output;
+}
+
+} // namespace
+
+// Converts a video frame to the dstFormat video frame format.
+QVideoFrame convertFrame(QVideoFrame &src, const QVideoFrameFormat &dstFormat)
+{
+ if (src.size() != dstFormat.frameSize()) {
+ qCCritical(lc) << "Resizing is not supported";
+ return {};
+ }
+
+ // Adjust size to even width/height if we have chroma subsampling
+ const QSize size = adjustSize(src.size(), src.pixelFormat(), dstFormat.pixelFormat());
+ if (size != src.size())
+ qCWarning(lc) << "Input truncated to even width/height";
+
+ const SwsContextUPtr conv = createConverter(
+ size, src.pixelFormat(), size, dstFormat.pixelFormat());
+
+ if (!conv) {
+ qCCritical(lc) << "Failed to create SW converter";
+ return {};
+ }
+
+ if (!setColorSpaceDetails(conv.get(), src.surfaceFormat(), dstFormat)) {
+ qCCritical(lc) << "Failed to set color space details";
+ return {};
+ }
+
+ QVideoFrame dst{ dstFormat };
+
+ if (!convert(conv.get(), src, size.height(), dst)) {
+ qCCritical(lc) << "Frame conversion failed";
+ return {};
+ }
+
+ return dst;
+}
+
+// clang-format on
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegconverter_p.h b/src/plugins/multimedia/ffmpeg/qffmpegconverter_p.h
new file mode 100644
index 000000000..57ee3135f
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegconverter_p.h
@@ -0,0 +1,30 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGCONVERTER_P_H
+#define QFFMPEGCONVERTER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qtconfigmacros.h>
+#include <private/qtmultimediaglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoFrameFormat;
+class QVideoFrame;
+
+QVideoFrame convertFrame(QVideoFrame &src, const QVideoFrameFormat &dstFormat);
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegdefs_p.h b/src/plugins/multimedia/ffmpeg/qffmpegdefs_p.h
new file mode 100644
index 000000000..239d8ff0c
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegdefs_p.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGDEFS_P_H
+#define QFFMPEGDEFS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+extern "C" {
+#include <libavformat/avformat.h>
+#include <libavcodec/avcodec.h>
+#include <libswresample/swresample.h>
+#include <libavutil/avutil.h>
+#include <libswscale/swscale.h>
+}
+
+#define QT_FFMPEG_OLD_CHANNEL_LAYOUT (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 24, 100))
+#define QT_FFMPEG_HAS_VULKAN \
+ (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58, 91, 100)) // since ffmpeg n4.3
+#define QT_FFMPEG_HAS_FRAME_TIME_BASE \
+ (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 18, 100)) // since ffmpeg n5.0
+#define QT_FFMPEG_HAS_FRAME_DURATION \
+ (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 3, 100)) // since ffmpeg n6.0
+#define QT_FFMPEG_STREAM_SIDE_DATA_DEPRECATED \
+ (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 15, 100)) // since ffmpeg n6.1
+#define QT_FFMPEG_HAS_D3D12VA \
+ (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(59, 8, 100)) // since ffmpeg n7.0
+#define QT_FFMPEG_SWR_CONST_CH_LAYOUT (LIBSWRESAMPLE_VERSION_INT >= AV_VERSION_INT(4, 9, 100))
+#define QT_FFMPEG_AVIO_WRITE_CONST \
+ (LIBAVFORMAT_VERSION_MAJOR >= 61)
+
+#endif // QFFMPEGDEFS_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegencodingformatcontext.cpp b/src/plugins/multimedia/ffmpeg/qffmpegencodingformatcontext.cpp
new file mode 100644
index 000000000..8b367a822
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegencodingformatcontext.cpp
@@ -0,0 +1,116 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegencodingformatcontext_p.h"
+#include "qffmpegmediaformatinfo_p.h"
+#include "qffmpegioutils_p.h"
+#include "qfile.h"
+#include "QtCore/qloggingcategory.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+static Q_LOGGING_CATEGORY(qLcEncodingFormatContext, "qt.multimedia.ffmpeg.encodingformatcontext");
+
+namespace {
+// In the example https://ffmpeg.org/doxygen/trunk/avio_read_callback_8c-example.html,
+// BufferSize = 4096 is suggested, however, it might be not optimal. To be investigated.
+constexpr size_t DefaultBufferSize = 4096;
+} // namespace
+
+EncodingFormatContext::EncodingFormatContext(QMediaFormat::FileFormat fileFormat)
+ : m_avFormatContext(avformat_alloc_context())
+{
+ const AVOutputFormat *avFormat = QFFmpegMediaFormatInfo::outputFormatForFileFormat(fileFormat);
+ m_avFormatContext->oformat = const_cast<AVOutputFormat *>(avFormat); // constness varies
+}
+
+EncodingFormatContext::~EncodingFormatContext()
+{
+ closeAVIO();
+
+ avformat_free_context(m_avFormatContext);
+}
+
+void EncodingFormatContext::openAVIO(const QString &filePath)
+{
+ Q_ASSERT(!isAVIOOpen());
+ Q_ASSERT(!filePath.isEmpty());
+
+ const QByteArray filePathUtf8 = filePath.toUtf8();
+
+ std::unique_ptr<char, decltype(&av_free)> url(
+ reinterpret_cast<char *>(av_malloc(filePathUtf8.size() + 1)), &av_free);
+ memcpy(url.get(), filePathUtf8.constData(), filePathUtf8.size() + 1);
+
+ // Initialize the AVIOContext for accessing the resource indicated by the url
+ auto result = avio_open2(&m_avFormatContext->pb, url.get(), AVIO_FLAG_WRITE, nullptr, nullptr);
+
+ qCDebug(qLcEncodingFormatContext)
+ << "opened by file path:" << url.get() << ", result:" << result;
+
+ Q_ASSERT(m_avFormatContext->url == nullptr);
+ if (isAVIOOpen())
+ m_avFormatContext->url = url.release();
+ else
+ openAVIOWithQFile(filePath);
+}
+
+void EncodingFormatContext::openAVIOWithQFile(const QString &filePath)
+{
+ // QTBUG-123082, To be investigated:
+ // - should we use the logic with QFile for all file paths?
+ // - does avio_open2 handle network protocols that QFile doesn't?
+ // - which buffer size should we set to opening with QFile to ensure the best performance?
+
+ auto file = std::make_unique<QFile>(filePath);
+
+ if (!file->open(QFile::WriteOnly)) {
+ qCDebug(qLcEncodingFormatContext) << "Cannot open QFile" << filePath;
+ return;
+ }
+
+ openAVIO(file.get());
+
+ if (isAVIOOpen())
+ m_outputFile = std::move(file);
+}
+
+void EncodingFormatContext::openAVIO(QIODevice *device)
+{
+ Q_ASSERT(!isAVIOOpen());
+ Q_ASSERT(device);
+
+ if (!device->isWritable())
+ return;
+
+ auto buffer = static_cast<uint8_t *>(av_malloc(DefaultBufferSize));
+ m_avFormatContext->pb = avio_alloc_context(buffer, DefaultBufferSize, 1, device, nullptr,
+ &writeQIODevice, &seekQIODevice);
+}
+
+void EncodingFormatContext::closeAVIO()
+{
+ // Close the AVIOContext and release any file handles
+ if (isAVIOOpen()) {
+ if (m_avFormatContext->url && *m_avFormatContext->url != '\0') {
+ auto closeResult = avio_closep(&m_avFormatContext->pb);
+ Q_ASSERT(closeResult == 0);
+ } else {
+ av_free(std::exchange(m_avFormatContext->pb->buffer, nullptr));
+ avio_context_free(&m_avFormatContext->pb);
+ }
+
+ // delete url even though it might be delete by avformat_free_context to
+ // ensure consistency in openAVIO/closeAVIO.
+ av_freep(&m_avFormatContext->url);
+ m_outputFile.reset();
+ } else {
+ Q_ASSERT(!m_outputFile);
+ }
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegencodingformatcontext_p.h b/src/plugins/multimedia/ffmpeg/qffmpegencodingformatcontext_p.h
new file mode 100644
index 000000000..69d0cd873
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegencodingformatcontext_p.h
@@ -0,0 +1,60 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGENCODINGFORMATCONTEXT_P_H
+#define QFFMPEGENCODINGFORMATCONTEXT_P_H
+
+#include "qffmpegdefs_p.h"
+#include "qmediaformat.h"
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QIODevice;
+class QFile;
+
+namespace QFFmpeg {
+
+class EncodingFormatContext
+{
+public:
+ explicit EncodingFormatContext(QMediaFormat::FileFormat fileFormat);
+ ~EncodingFormatContext();
+
+ void openAVIO(const QString &filePath);
+
+ void openAVIO(QIODevice *device);
+
+ bool isAVIOOpen() const { return m_avFormatContext->pb != nullptr; }
+
+ void closeAVIO();
+
+ AVFormatContext *avFormatContext() { return m_avFormatContext; }
+
+ const AVFormatContext *avFormatContext() const { return m_avFormatContext; }
+
+private:
+ Q_DISABLE_COPY_MOVE(EncodingFormatContext)
+
+ void openAVIOWithQFile(const QString &filePath);
+
+private:
+ AVFormatContext *m_avFormatContext;
+ std::unique_ptr<QFile> m_outputFile;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGENCODINGFORMATCONTEXT_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel.cpp b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel.cpp
new file mode 100644
index 000000000..5b140f0ca
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel.cpp
@@ -0,0 +1,504 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "libavutil/version.h"
+
+#include "qffmpeghwaccel_p.h"
+#if QT_CONFIG(vaapi)
+#include "qffmpeghwaccel_vaapi_p.h"
+#endif
+#ifdef Q_OS_DARWIN
+#include "qffmpeghwaccel_videotoolbox_p.h"
+#endif
+#if QT_CONFIG(wmf)
+#include "qffmpeghwaccel_d3d11_p.h"
+#include <QtCore/private/qsystemlibrary_p.h>
+
+#endif
+#ifdef Q_OS_ANDROID
+# include "qffmpeghwaccel_mediacodec_p.h"
+#endif
+#include "qffmpeg_p.h"
+#include "qffmpegvideobuffer_p.h"
+#include "qscopedvaluerollback.h"
+#include "QtCore/qfile.h"
+
+#include <rhi/qrhi.h>
+#include <qloggingcategory.h>
+#include <unordered_set>
+#ifdef Q_OS_LINUX
+#include <QLibrary>
+#endif
+
+/* Infrastructure for HW acceleration goes into this file. */
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLHWAccel, "qt.multimedia.ffmpeg.hwaccel");
+extern bool thread_local FFmpegLogsEnabledInThread;
+
+namespace QFFmpeg {
+
+static const std::initializer_list<AVHWDeviceType> preferredHardwareAccelerators = {
+#if defined(Q_OS_ANDROID)
+ AV_HWDEVICE_TYPE_MEDIACODEC,
+#elif defined(Q_OS_LINUX)
+ AV_HWDEVICE_TYPE_CUDA,
+ AV_HWDEVICE_TYPE_VAAPI,
+
+ // TODO: investigate VDPAU advantages.
+ // nvenc/nvdec codecs use AV_HWDEVICE_TYPE_CUDA by default, but they can also use VDPAU
+ // if it's included into the ffmpeg build and vdpau drivers are installed.
+ // AV_HWDEVICE_TYPE_VDPAU
+#elif defined (Q_OS_WIN)
+ AV_HWDEVICE_TYPE_D3D11VA,
+#elif defined (Q_OS_DARWIN)
+ AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
+#endif
+};
+
+static AVBufferUPtr loadHWContext(AVHWDeviceType type)
+{
+ AVBufferRef *hwContext = nullptr;
+ qCDebug(qLHWAccel) << " Checking HW context:" << av_hwdevice_get_type_name(type);
+ int ret = av_hwdevice_ctx_create(&hwContext, type, nullptr, nullptr, 0);
+
+ if (ret == 0) {
+ qCDebug(qLHWAccel) << " Using above hw context.";
+ return AVBufferUPtr(hwContext);
+ }
+ qCDebug(qLHWAccel) << " Could not create hw context:" << ret << strerror(-ret);
+ return nullptr;
+}
+
+// FFmpeg might crash on loading non-existing hw devices.
+// Let's roughly precheck drivers/libraries.
+static bool precheckDriver(AVHWDeviceType type)
+{
+ // precheckings might need some improvements
+#if defined(Q_OS_LINUX)
+ if (type == AV_HWDEVICE_TYPE_CUDA) {
+ if (!QFile::exists(QLatin1String("/proc/driver/nvidia/version")))
+ return false;
+
+ // QTBUG-122199
+ // CUDA backend requires libnvcuvid in libavcodec
+ QLibrary lib("libnvcuvid.so");
+ if (!lib.load())
+ return false;
+ lib.unload();
+ return true;
+ }
+#elif defined(Q_OS_WINDOWS)
+ if (type == AV_HWDEVICE_TYPE_D3D11VA)
+ return QSystemLibrary(QLatin1String("d3d11.dll")).load();
+
+#if QT_FFMPEG_HAS_D3D12VA
+ if (type == AV_HWDEVICE_TYPE_D3D12VA)
+ return QSystemLibrary(QLatin1String("d3d12.dll")).load();
+#endif
+
+ if (type == AV_HWDEVICE_TYPE_DXVA2)
+ return QSystemLibrary(QLatin1String("d3d9.dll")).load();
+
+ // TODO: check nvenc/nvdec and revisit the checking
+ if (type == AV_HWDEVICE_TYPE_CUDA)
+ return QSystemLibrary(QLatin1String("nvml.dll")).load();
+#else
+ Q_UNUSED(type);
+#endif
+
+ return true;
+}
+
+static bool checkHwType(AVHWDeviceType type)
+{
+ const auto deviceName = av_hwdevice_get_type_name(type);
+ if (!deviceName) {
+ qWarning() << "Internal FFmpeg error, unknow hw type:" << type;
+ return false;
+ }
+
+ if (!precheckDriver(type)) {
+ qCDebug(qLHWAccel) << "Drivers for hw device" << deviceName << "is not installed";
+ return false;
+ }
+
+ if (type == AV_HWDEVICE_TYPE_MEDIACODEC ||
+ type == AV_HWDEVICE_TYPE_VIDEOTOOLBOX ||
+ type == AV_HWDEVICE_TYPE_D3D11VA ||
+#if QT_FFMPEG_HAS_D3D12VA
+ type == AV_HWDEVICE_TYPE_D3D12VA ||
+#endif
+ type == AV_HWDEVICE_TYPE_DXVA2)
+ return true; // Don't waste time; it's expected to work fine of the precheck is OK
+
+
+ QScopedValueRollback rollback(FFmpegLogsEnabledInThread);
+ FFmpegLogsEnabledInThread = false;
+
+ return loadHWContext(type) != nullptr;
+}
+
+static const std::vector<AVHWDeviceType> &deviceTypes()
+{
+ static const auto types = []() {
+ qCDebug(qLHWAccel) << "Check device types";
+ QElapsedTimer timer;
+ timer.start();
+
+ // gather hw pix formats
+ std::unordered_set<AVPixelFormat> hwPixFormats;
+ void *opaque = nullptr;
+ while (auto codec = av_codec_iterate(&opaque)) {
+ findAVPixelFormat(codec, [&](AVPixelFormat format) {
+ if (isHwPixelFormat(format))
+ hwPixFormats.insert(format);
+ return false;
+ });
+ }
+
+ // create a device types list
+ std::vector<AVHWDeviceType> result;
+ AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
+ while ((type = av_hwdevice_iterate_types(type)) != AV_HWDEVICE_TYPE_NONE)
+ if (hwPixFormats.count(pixelFormatForHwDevice(type)) && checkHwType(type))
+ result.push_back(type);
+ result.shrink_to_fit();
+
+ // reorder the list accordingly preferredHardwareAccelerators
+ auto it = result.begin();
+ for (const auto preffered : preferredHardwareAccelerators) {
+ auto found = std::find(it, result.end(), preffered);
+ if (found != result.end())
+ std::rotate(it++, found, std::next(found));
+ }
+
+ using namespace std::chrono;
+ qCDebug(qLHWAccel) << "Device types checked. Spent time:" << duration_cast<microseconds>(timer.durationElapsed());
+
+ return result;
+ }();
+
+ return types;
+}
+
+static std::vector<AVHWDeviceType> deviceTypes(const char *envVarName)
+{
+ const auto definedDeviceTypes = qgetenv(envVarName);
+
+ if (definedDeviceTypes.isNull())
+ return deviceTypes();
+
+ std::vector<AVHWDeviceType> result;
+ const auto definedDeviceTypesString = QString::fromUtf8(definedDeviceTypes).toLower();
+ for (const auto &deviceType : definedDeviceTypesString.split(',')) {
+ if (!deviceType.isEmpty()) {
+ const auto foundType = av_hwdevice_find_type_by_name(deviceType.toUtf8().data());
+ if (foundType == AV_HWDEVICE_TYPE_NONE)
+ qWarning() << "Unknown hw device type" << deviceType;
+ else
+ result.emplace_back(foundType);
+ }
+ }
+
+ result.shrink_to_fit();
+ return result;
+}
+
+template<typename CodecFinder>
+std::pair<const AVCodec *, std::unique_ptr<HWAccel>>
+findCodecWithHwAccel(AVCodecID id, const std::vector<AVHWDeviceType> &deviceTypes,
+ CodecFinder codecFinder,
+ const std::function<bool(const HWAccel &)> &hwAccelPredicate)
+{
+ for (auto type : deviceTypes) {
+ const auto codec = codecFinder(id, type, {});
+
+ if (!codec)
+ continue;
+
+ qCDebug(qLHWAccel) << "Found potential codec" << codec->name << "for hw accel" << type
+ << "; Checking the hw device...";
+
+ auto hwAccel = QFFmpeg::HWAccel::create(type);
+
+ if (!hwAccel)
+ continue;
+
+ if (hwAccelPredicate && !hwAccelPredicate(*hwAccel)) {
+ qCDebug(qLHWAccel) << "HW device is available but doesn't suit due to restrictions";
+ continue;
+ }
+
+ qCDebug(qLHWAccel) << "HW device is OK";
+
+ return { codec, std::move(hwAccel) };
+ }
+
+ qCDebug(qLHWAccel) << "No hw acceleration found for codec id" << id;
+
+ return { nullptr, nullptr };
+}
+
+static bool isNoConversionFormat(AVPixelFormat f)
+{
+ bool needsConversion = true;
+ QFFmpegVideoBuffer::toQtPixelFormat(f, &needsConversion);
+ return !needsConversion;
+};
+
+namespace {
+
+bool hwTextureConversionEnabled()
+{
+
+ // HW textures conversions are not stable in specific cases, dependent on the hardware and OS.
+ // We need the env var for testing with no textures conversion on the user's side.
+ static const int disableHwConversion =
+ qEnvironmentVariableIntValue("QT_DISABLE_HW_TEXTURES_CONVERSION");
+
+ return !disableHwConversion;
+}
+
+void setupDecoder(const AVPixelFormat format, AVCodecContext *const codecContext)
+{
+ if (!hwTextureConversionEnabled())
+ return;
+
+#if QT_CONFIG(wmf)
+ if (format == AV_PIX_FMT_D3D11)
+ QFFmpeg::D3D11TextureConverter::SetupDecoderTextures(codecContext);
+#elif defined Q_OS_ANDROID
+ if (format == AV_PIX_FMT_MEDIACODEC)
+ QFFmpeg::MediaCodecTextureConverter::setupDecoderSurface(codecContext);
+#else
+ Q_UNUSED(codecContext);
+ Q_UNUSED(format);
+#endif
+}
+
+} // namespace
+
+// Used for the AVCodecContext::get_format callback
+AVPixelFormat getFormat(AVCodecContext *codecContext, const AVPixelFormat *suggestedFormats)
+{
+ // First check HW accelerated codecs, the HW device context must be set
+ if (codecContext->hw_device_ctx) {
+ auto *device_ctx = (AVHWDeviceContext *)codecContext->hw_device_ctx->data;
+ std::pair formatAndScore(AV_PIX_FMT_NONE, NotSuitableAVScore);
+
+ // to be rewritten via findBestAVFormat
+ for (int i = 0;
+ const AVCodecHWConfig *config = avcodec_get_hw_config(codecContext->codec, i); i++) {
+ if (!(config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
+ continue;
+
+ if (device_ctx->type != config->device_type)
+ continue;
+
+ const bool isDeprecated = (config->methods & AV_CODEC_HW_CONFIG_METHOD_AD_HOC) != 0;
+ const bool shouldCheckCodecFormats = config->pix_fmt == AV_PIX_FMT_NONE;
+
+ auto scoresGettor = [&](AVPixelFormat format) {
+ // check in supported codec->pix_fmts;
+ // no reason to use findAVPixelFormat as we're already in the hw_config loop
+ if (shouldCheckCodecFormats && !hasAVFormat(codecContext->codec->pix_fmts, format))
+ return NotSuitableAVScore;
+
+ if (!shouldCheckCodecFormats && config->pix_fmt != format)
+ return NotSuitableAVScore;
+
+ auto result = DefaultAVScore;
+
+ if (isDeprecated)
+ result -= 10000;
+ if (isHwPixelFormat(format))
+ result += 10;
+
+ return result;
+ };
+
+ const auto found = findBestAVFormat(suggestedFormats, scoresGettor);
+
+ if (found.second > formatAndScore.second)
+ formatAndScore = found;
+ }
+
+ const auto &format = formatAndScore.first;
+ if (format != AV_PIX_FMT_NONE) {
+ setupDecoder(format, codecContext);
+ qCDebug(qLHWAccel) << "Selected format" << format << "for hw" << device_ctx->type;
+ return format;
+ }
+ }
+
+ // prefer video formats we can handle directly
+ const auto noConversionFormat = findAVFormat(suggestedFormats, &isNoConversionFormat);
+ if (noConversionFormat != AV_PIX_FMT_NONE) {
+ qCDebug(qLHWAccel) << "Selected format with no conversion" << noConversionFormat;
+ return noConversionFormat;
+ }
+
+ qCDebug(qLHWAccel) << "Selected format with conversion" << *suggestedFormats;
+
+ // take the native format, this will involve one additional format conversion on the CPU side
+ return *suggestedFormats;
+}
+
+HWAccel::~HWAccel() = default;
+
+std::unique_ptr<HWAccel> HWAccel::create(AVHWDeviceType deviceType)
+{
+ if (auto ctx = loadHWContext(deviceType))
+ return std::unique_ptr<HWAccel>(new HWAccel(std::move(ctx)));
+ else
+ return {};
+}
+
+AVPixelFormat HWAccel::format(AVFrame *frame)
+{
+ if (!frame->hw_frames_ctx)
+ return AVPixelFormat(frame->format);
+
+ auto *hwFramesContext = (AVHWFramesContext *)frame->hw_frames_ctx->data;
+ Q_ASSERT(hwFramesContext);
+ return AVPixelFormat(hwFramesContext->sw_format);
+}
+
+const std::vector<AVHWDeviceType> &HWAccel::encodingDeviceTypes()
+{
+ static const auto &result = deviceTypes("QT_FFMPEG_ENCODING_HW_DEVICE_TYPES");
+ return result;
+}
+
+const std::vector<AVHWDeviceType> &HWAccel::decodingDeviceTypes()
+{
+ static const auto &result = deviceTypes("QT_FFMPEG_DECODING_HW_DEVICE_TYPES");
+ return result;
+}
+
+AVHWDeviceContext *HWAccel::hwDeviceContext() const
+{
+ return m_hwDeviceContext ? (AVHWDeviceContext *)m_hwDeviceContext->data : nullptr;
+}
+
+AVPixelFormat HWAccel::hwFormat() const
+{
+ return pixelFormatForHwDevice(deviceType());
+}
+
+const AVHWFramesConstraints *HWAccel::constraints() const
+{
+ std::call_once(m_constraintsOnceFlag, [this]() {
+ if (auto context = hwDeviceContextAsBuffer())
+ m_constraints.reset(av_hwdevice_get_hwframe_constraints(context, nullptr));
+ });
+
+ return m_constraints.get();
+}
+
+std::pair<const AVCodec *, std::unique_ptr<HWAccel>>
+HWAccel::findEncoderWithHwAccel(AVCodecID id, const std::function<bool(const HWAccel &)>& hwAccelPredicate)
+{
+ auto finder = qOverload<AVCodecID, const std::optional<AVHWDeviceType> &,
+ const std::optional<PixelOrSampleFormat> &>(&QFFmpeg::findAVEncoder);
+ return findCodecWithHwAccel(id, encodingDeviceTypes(), finder, hwAccelPredicate);
+}
+
+std::pair<const AVCodec *, std::unique_ptr<HWAccel>>
+HWAccel::findDecoderWithHwAccel(AVCodecID id, const std::function<bool(const HWAccel &)>& hwAccelPredicate)
+{
+ return findCodecWithHwAccel(id, decodingDeviceTypes(), &QFFmpeg::findAVDecoder,
+ hwAccelPredicate);
+}
+
+AVHWDeviceType HWAccel::deviceType() const
+{
+ return m_hwDeviceContext ? hwDeviceContext()->type : AV_HWDEVICE_TYPE_NONE;
+}
+
+void HWAccel::createFramesContext(AVPixelFormat swFormat, const QSize &size)
+{
+ if (m_hwFramesContext) {
+ qWarning() << "Frames context has been already created!";
+ return;
+ }
+
+ if (!m_hwDeviceContext)
+ return;
+
+ m_hwFramesContext.reset(av_hwframe_ctx_alloc(m_hwDeviceContext.get()));
+ auto *c = (AVHWFramesContext *)m_hwFramesContext->data;
+ c->format = hwFormat();
+ c->sw_format = swFormat;
+ c->width = size.width();
+ c->height = size.height();
+ qCDebug(qLHWAccel) << "init frames context";
+ int err = av_hwframe_ctx_init(m_hwFramesContext.get());
+ if (err < 0)
+ qWarning() << "failed to init HW frame context" << err << err2str(err);
+ else
+ qCDebug(qLHWAccel) << "Initialized frames context" << size << c->format << c->sw_format;
+}
+
+AVHWFramesContext *HWAccel::hwFramesContext() const
+{
+ return m_hwFramesContext ? (AVHWFramesContext *)m_hwFramesContext->data : nullptr;
+}
+
+
+TextureConverter::TextureConverter(QRhi *rhi)
+ : d(new Data)
+{
+ d->rhi = rhi;
+}
+
+TextureSet *TextureConverter::getTextures(AVFrame *frame)
+{
+ if (!frame || isNull())
+ return nullptr;
+
+ Q_ASSERT(frame->format == d->format);
+ return d->backend->getTextures(frame);
+}
+
+void TextureConverter::updateBackend(AVPixelFormat fmt)
+{
+ d->backend = nullptr;
+ if (!d->rhi)
+ return;
+
+ if (!hwTextureConversionEnabled())
+ return;
+
+ switch (fmt) {
+#if QT_CONFIG(vaapi)
+ case AV_PIX_FMT_VAAPI:
+ d->backend = std::make_unique<VAAPITextureConverter>(d->rhi);
+ break;
+#endif
+#ifdef Q_OS_DARWIN
+ case AV_PIX_FMT_VIDEOTOOLBOX:
+ d->backend = std::make_unique<VideoToolBoxTextureConverter>(d->rhi);
+ break;
+#endif
+#if QT_CONFIG(wmf)
+ case AV_PIX_FMT_D3D11:
+ d->backend = std::make_unique<D3D11TextureConverter>(d->rhi);
+ break;
+#endif
+#ifdef Q_OS_ANDROID
+ case AV_PIX_FMT_MEDIACODEC:
+ d->backend = std::make_unique<MediaCodecTextureConverter>(d->rhi);
+ break;
+#endif
+ default:
+ break;
+ }
+ d->format = fmt;
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_d3d11.cpp b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_d3d11.cpp
new file mode 100644
index 000000000..a2533a132
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_d3d11.cpp
@@ -0,0 +1,309 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpeghwaccel_d3d11_p.h"
+#include "playbackengine/qffmpegstreamdecoder_p.h"
+
+#include <qvideoframeformat.h>
+#include "qffmpegvideobuffer_p.h"
+
+#include <private/qvideotexturehelper_p.h>
+#include <private/qcomptr_p.h>
+#include <private/quniquehandle_p.h>
+
+#include <rhi/qrhi.h>
+
+#include <qopenglfunctions.h>
+#include <qdebug.h>
+#include <qloggingcategory.h>
+
+#include <libavutil/hwcontext_d3d11va.h>
+#include <d3d11_1.h>
+#include <dxgi1_2.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+
+Q_LOGGING_CATEGORY(qLcMediaFFmpegHWAccel, "qt.multimedia.hwaccel");
+
+ComPtr<ID3D11Device1> GetD3DDevice(QRhi *rhi)
+{
+ const auto native = static_cast<const QRhiD3D11NativeHandles *>(rhi->nativeHandles());
+ if (!native)
+ return {};
+
+ const ComPtr<ID3D11Device> rhiDevice = static_cast<ID3D11Device *>(native->dev);
+
+ ComPtr<ID3D11Device1> dev1;
+ if (rhiDevice.As(&dev1) != S_OK)
+ return nullptr;
+
+ return dev1;
+}
+
+} // namespace
+namespace QFFmpeg {
+
+bool TextureBridge::copyToSharedTex(ID3D11Device *dev, ID3D11DeviceContext *ctx,
+ const ComPtr<ID3D11Texture2D> &tex, UINT index,
+ const QSize &frameSize)
+{
+ if (!ensureSrcTex(dev, tex, frameSize))
+ return false;
+
+ // Flush to ensure that texture is fully updated before we share it.
+ ctx->Flush();
+
+ if (m_srcMutex->AcquireSync(m_srcKey, INFINITE) != S_OK)
+ return false;
+
+ const UINT width = static_cast<UINT>(frameSize.width());
+ const UINT height = static_cast<UINT>(frameSize.height());
+
+ // A crop box is needed because FFmpeg may have created textures
+ // that are bigger than the frame size to account for the decoder's
+ // surface alignment requirements.
+ const D3D11_BOX crop{ 0, 0, 0, width, height, 1 };
+ ctx->CopySubresourceRegion(m_srcTex.Get(), 0, 0, 0, 0, tex.Get(), index, &crop);
+
+ m_srcMutex->ReleaseSync(m_destKey);
+ return true;
+}
+
+ComPtr<ID3D11Texture2D> TextureBridge::copyFromSharedTex(const ComPtr<ID3D11Device1> &dev,
+ const ComPtr<ID3D11DeviceContext> &ctx)
+{
+ if (!ensureDestTex(dev))
+ return {};
+
+ if (m_destMutex->AcquireSync(m_destKey, INFINITE) != S_OK)
+ return {};
+
+ ctx->CopySubresourceRegion(m_outputTex.Get(), 0, 0, 0, 0, m_destTex.Get(), 0, nullptr);
+
+ m_destMutex->ReleaseSync(m_srcKey);
+
+ return m_outputTex;
+}
+
+bool TextureBridge::ensureDestTex(const ComPtr<ID3D11Device1> &dev)
+{
+ if (m_destDevice != dev) {
+ // Destination device changed. Recreate texture.
+ m_destTex = nullptr;
+ m_destDevice = dev;
+ }
+
+ if (m_destTex)
+ return true;
+
+ if (m_destDevice->OpenSharedResource1(m_sharedHandle.get(), IID_PPV_ARGS(&m_destTex)) != S_OK)
+ return false;
+
+ CD3D11_TEXTURE2D_DESC desc{};
+ m_destTex->GetDesc(&desc);
+
+ desc.MiscFlags = 0;
+ desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
+
+ if (m_destDevice->CreateTexture2D(&desc, nullptr, m_outputTex.ReleaseAndGetAddressOf()) != S_OK)
+ return false;
+
+ if (m_destTex.As(&m_destMutex) != S_OK)
+ return false;
+
+ return true;
+}
+
+bool TextureBridge::ensureSrcTex(ID3D11Device *dev, const ComPtr<ID3D11Texture2D> &tex, const QSize &frameSize)
+{
+ if (!isSrcInitialized(dev, tex, frameSize))
+ return recreateSrc(dev, tex, frameSize);
+
+ return true;
+}
+
+bool TextureBridge::isSrcInitialized(const ID3D11Device *dev,
+ const ComPtr<ID3D11Texture2D> &tex,
+ const QSize &frameSize) const
+{
+ if (!m_srcTex)
+ return false;
+
+ // Check if device has changed
+ ComPtr<ID3D11Device> texDevice;
+ m_srcTex->GetDevice(texDevice.GetAddressOf());
+ if (dev != texDevice.Get())
+ return false;
+
+ // Check if shared texture has correct size and format
+ CD3D11_TEXTURE2D_DESC inputDesc{};
+ tex->GetDesc(&inputDesc);
+
+ CD3D11_TEXTURE2D_DESC currentDesc{};
+ m_srcTex->GetDesc(&currentDesc);
+
+ if (inputDesc.Format != currentDesc.Format)
+ return false;
+
+ const UINT width = static_cast<UINT>(frameSize.width());
+ const UINT height = static_cast<UINT>(frameSize.height());
+
+ if (currentDesc.Width != width || currentDesc.Height != height)
+ return false;
+
+ return true;
+}
+
+bool TextureBridge::recreateSrc(ID3D11Device *dev, const ComPtr<ID3D11Texture2D> &tex, const QSize &frameSize)
+{
+ m_sharedHandle.close();
+
+ CD3D11_TEXTURE2D_DESC desc{};
+ tex->GetDesc(&desc);
+
+ const UINT width = static_cast<UINT>(frameSize.width());
+ const UINT height = static_cast<UINT>(frameSize.height());
+
+ CD3D11_TEXTURE2D_DESC texDesc{ desc.Format, width, height };
+ texDesc.MipLevels = 1;
+ texDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE;
+
+ if (dev->CreateTexture2D(&texDesc, nullptr, m_srcTex.ReleaseAndGetAddressOf()) != S_OK)
+ return false;
+
+ ComPtr<IDXGIResource1> res;
+ if (m_srcTex.As(&res) != S_OK)
+ return false;
+
+ const HRESULT hr =
+ res->CreateSharedHandle(nullptr, DXGI_SHARED_RESOURCE_READ, nullptr, &m_sharedHandle);
+
+ if (hr != S_OK || !m_sharedHandle)
+ return false;
+
+ if (m_srcTex.As(&m_srcMutex) != S_OK || !m_srcMutex)
+ return false;
+
+ m_destTex = nullptr;
+ m_destMutex = nullptr;
+ return true;
+}
+
+class D3D11TextureSet : public TextureSet
+{
+public:
+ D3D11TextureSet(QRhi *rhi, ComPtr<ID3D11Texture2D> &&tex)
+ : m_owner{ rhi }, m_tex(std::move(tex))
+ {
+ }
+
+ qint64 textureHandle(QRhi *rhi, int /*plane*/) override
+ {
+ if (rhi != m_owner)
+ return 0u;
+ return reinterpret_cast<qint64>(m_tex.Get());
+ }
+
+private:
+ QRhi *m_owner = nullptr;
+ ComPtr<ID3D11Texture2D> m_tex;
+};
+
+D3D11TextureConverter::D3D11TextureConverter(QRhi *rhi)
+ : TextureConverterBackend(rhi), m_rhiDevice{ GetD3DDevice(rhi) }
+{
+ if (!m_rhiDevice)
+ return;
+
+ m_rhiDevice->GetImmediateContext(m_rhiCtx.GetAddressOf());
+}
+
+TextureSet *D3D11TextureConverter::getTextures(AVFrame *frame)
+{
+ if (!m_rhiDevice)
+ return nullptr;
+
+ if (!frame || !frame->hw_frames_ctx || frame->format != AV_PIX_FMT_D3D11)
+ return nullptr;
+
+ const auto *fCtx = reinterpret_cast<AVHWFramesContext *>(frame->hw_frames_ctx->data);
+ const auto *ctx = fCtx->device_ctx;
+
+ if (!ctx || ctx->type != AV_HWDEVICE_TYPE_D3D11VA)
+ return nullptr;
+
+ const ComPtr<ID3D11Texture2D> ffmpegTex = reinterpret_cast<ID3D11Texture2D *>(frame->data[0]);
+ const int index = static_cast<int>(reinterpret_cast<intptr_t>(frame->data[1]));
+
+ if (rhi->backend() == QRhi::D3D11) {
+ {
+ const auto *avDeviceCtx = static_cast<AVD3D11VADeviceContext *>(ctx->hwctx);
+
+ if (!avDeviceCtx)
+ return nullptr;
+
+ // Lock the FFmpeg device context while we copy from FFmpeg's
+ // frame pool into a shared texture because the underlying ID3D11DeviceContext
+ // is not thread safe.
+ avDeviceCtx->lock(avDeviceCtx->lock_ctx);
+ QScopeGuard autoUnlock([&] { avDeviceCtx->unlock(avDeviceCtx->lock_ctx); });
+
+ // Populate the shared texture with one slice from the frame pool, cropping away
+ // extra surface alignment areas that FFmpeg adds to the textures
+ QSize frameSize{ frame->width, frame->height };
+ if (!m_bridge.copyToSharedTex(avDeviceCtx->device, avDeviceCtx->device_context,
+ ffmpegTex, index, frameSize)) {
+ return nullptr;
+ }
+ }
+
+ // Get a copy of the texture on the RHI device
+ ComPtr<ID3D11Texture2D> output = m_bridge.copyFromSharedTex(m_rhiDevice, m_rhiCtx);
+
+ if (!output)
+ return nullptr;
+
+ return new D3D11TextureSet(rhi, std::move(output));
+ }
+
+ return nullptr;
+}
+
+void D3D11TextureConverter::SetupDecoderTextures(AVCodecContext *s)
+{
+ // We are holding pool frames alive for quite long, which may cause
+ // codecs to run out of frames because FFmpeg has a fixed size
+ // decoder frame pool. We must therefore add extra frames to the pool
+ // to account for the frames we keep alive. First, we need to account
+ // for the maximum number of queued frames during rendering. In
+ // addition, we add one frame for the RHI rendering pipeline, and one
+ // additional frame because we may hold one in the Qt event loop.
+
+ const qint32 maxRenderQueueSize = StreamDecoder::maxQueueSize(QPlatformMediaPlayer::VideoStream);
+ constexpr qint32 framesHeldByRhi = 1;
+ constexpr qint32 framesHeldByQtEventLoop = 1;
+ s->extra_hw_frames = maxRenderQueueSize + framesHeldByRhi + framesHeldByQtEventLoop;
+
+ int ret = avcodec_get_hw_frames_parameters(s, s->hw_device_ctx, AV_PIX_FMT_D3D11,
+ &s->hw_frames_ctx);
+ if (ret < 0) {
+ qCDebug(qLcMediaFFmpegHWAccel) << "Failed to allocate HW frames context" << ret;
+ return;
+ }
+
+ const auto *frames_ctx = reinterpret_cast<const AVHWFramesContext *>(s->hw_frames_ctx->data);
+ auto *hwctx = static_cast<AVD3D11VAFramesContext *>(frames_ctx->hwctx);
+ hwctx->MiscFlags = D3D11_RESOURCE_MISC_SHARED;
+ hwctx->BindFlags = D3D11_BIND_DECODER | D3D11_BIND_SHADER_RESOURCE;
+ ret = av_hwframe_ctx_init(s->hw_frames_ctx);
+ if (ret < 0) {
+ qCDebug(qLcMediaFFmpegHWAccel) << "Failed to initialize HW frames context" << ret;
+ av_buffer_unref(&s->hw_frames_ctx);
+ }
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_d3d11_p.h b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_d3d11_p.h
new file mode 100644
index 000000000..bfcc1f10c
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_d3d11_p.h
@@ -0,0 +1,104 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGHWACCEL_D3D11_P_H
+#define QFFMPEGHWACCEL_D3D11_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpeghwaccel_p.h"
+#include <private/quniquehandle_p.h>
+#include <private/qcomptr_p.h>
+#include <qt_windows.h>
+
+#include <d3d11.h>
+#include <d3d11_1.h>
+
+#if QT_CONFIG(wmf)
+
+QT_BEGIN_NAMESPACE
+
+class QRhi;
+
+namespace QFFmpeg {
+
+struct SharedTextureHandleTraits
+{
+ using Type = HANDLE;
+ static Type invalidValue() { return nullptr; }
+ static bool close(Type handle) { return CloseHandle(handle) != 0; }
+};
+
+using SharedTextureHandle = QUniqueHandle<SharedTextureHandleTraits>;
+
+/*! \internal Utility class for synchronized transfer of a texture between two D3D devices
+ *
+ * This class is used to copy a texture from one device to another device. This
+ * is implemented using a shared texture, along with keyed mutexes to synchronize
+ * access to the texture.
+ *
+ * This is needed because we need to copy data from FFmpeg to RHI. FFmpeg and RHI
+ * uses different D3D devices.
+ */
+class TextureBridge final
+{
+public:
+ /** Copy a texture slice at position 'index' belonging to device 'dev'
+ * into a shared texture, limiting the texture size to the frame size */
+ bool copyToSharedTex(ID3D11Device *dev, ID3D11DeviceContext *ctx,
+ const ComPtr<ID3D11Texture2D> &tex, UINT index, const QSize &frameSize);
+
+ /** Obtain a copy of the texture on a second device 'dev' */
+ ComPtr<ID3D11Texture2D> copyFromSharedTex(const ComPtr<ID3D11Device1> &dev,
+ const ComPtr<ID3D11DeviceContext> &ctx);
+
+private:
+ bool ensureDestTex(const ComPtr<ID3D11Device1> &dev);
+ bool ensureSrcTex(ID3D11Device *dev, const ComPtr<ID3D11Texture2D> &tex, const QSize &frameSize);
+ bool isSrcInitialized(const ID3D11Device *dev, const ComPtr<ID3D11Texture2D> &tex, const QSize &frameSize) const;
+ bool recreateSrc(ID3D11Device *dev, const ComPtr<ID3D11Texture2D> &tex, const QSize &frameSize);
+
+ SharedTextureHandle m_sharedHandle{};
+
+ const UINT m_srcKey = 0;
+ ComPtr<ID3D11Texture2D> m_srcTex;
+ ComPtr<IDXGIKeyedMutex> m_srcMutex;
+
+ const UINT m_destKey = 1;
+ ComPtr<ID3D11Device1> m_destDevice;
+ ComPtr<ID3D11Texture2D> m_destTex;
+ ComPtr<IDXGIKeyedMutex> m_destMutex;
+
+ ComPtr<ID3D11Texture2D> m_outputTex;
+};
+
+class D3D11TextureConverter : public TextureConverterBackend
+{
+public:
+ D3D11TextureConverter(QRhi *rhi);
+
+ TextureSet *getTextures(AVFrame *frame) override;
+
+ static void SetupDecoderTextures(AVCodecContext *s);
+
+private:
+ ComPtr<ID3D11Device1> m_rhiDevice;
+ ComPtr<ID3D11DeviceContext> m_rhiCtx;
+ TextureBridge m_bridge;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_mediacodec.cpp b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_mediacodec.cpp
new file mode 100644
index 000000000..e9dd8705a
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_mediacodec.cpp
@@ -0,0 +1,120 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpeghwaccel_mediacodec_p.h"
+
+#include "androidsurfacetexture_p.h"
+#include <rhi/qrhi.h>
+
+extern "C" {
+#include <libavcodec/mediacodec.h>
+#include <libavutil/hwcontext_mediacodec.h>
+}
+
+#if !defined(Q_OS_ANDROID)
+# error "Configuration error"
+#endif
+
+namespace QFFmpeg {
+
+class MediaCodecTextureSet : public TextureSet
+{
+public:
+ MediaCodecTextureSet(qint64 textureHandle) : handle(textureHandle) { }
+
+ qint64 textureHandle(QRhi *, int plane) override { return (plane == 0) ? handle : 0; }
+
+private:
+ qint64 handle;
+};
+
+namespace {
+
+void deleteSurface(AVHWDeviceContext *ctx)
+{
+ AndroidSurfaceTexture* s = reinterpret_cast<AndroidSurfaceTexture *>(ctx->user_opaque);
+ delete s;
+}
+
+AndroidSurfaceTexture* getTextureSurface(AVFrame *frame)
+{
+ if (!frame || !frame->hw_frames_ctx)
+ return nullptr;
+
+ auto *frameContext = reinterpret_cast<AVHWFramesContext *>(frame->hw_frames_ctx->data);
+
+ if (!frameContext || !frameContext->device_ctx)
+ return nullptr;
+
+ AVHWDeviceContext *deviceContext = frameContext->device_ctx;
+
+ return reinterpret_cast<AndroidSurfaceTexture *>(deviceContext->user_opaque);
+}
+} // namespace
+
+void MediaCodecTextureConverter::setupDecoderSurface(AVCodecContext *avCodecContext)
+{
+ std::unique_ptr<AndroidSurfaceTexture> androidSurfaceTexture(new AndroidSurfaceTexture(0));
+ AVMediaCodecContext *mediacodecContext = av_mediacodec_alloc_context();
+ av_mediacodec_default_init(avCodecContext, mediacodecContext, androidSurfaceTexture->surface());
+
+ if (!avCodecContext->hw_device_ctx || !avCodecContext->hw_device_ctx->data)
+ return;
+
+ AVHWDeviceContext *deviceContext =
+ reinterpret_cast<AVHWDeviceContext *>(avCodecContext->hw_device_ctx->data);
+
+ if (!deviceContext->hwctx)
+ return;
+
+ AVMediaCodecDeviceContext *mediaDeviceContext =
+ reinterpret_cast<AVMediaCodecDeviceContext *>(deviceContext->hwctx);
+
+ if (!mediaDeviceContext)
+ return;
+
+ mediaDeviceContext->surface = androidSurfaceTexture->surface();
+
+ Q_ASSERT(deviceContext->user_opaque == nullptr);
+ deviceContext->user_opaque = androidSurfaceTexture.release();
+ deviceContext->free = deleteSurface;
+}
+
+TextureSet *MediaCodecTextureConverter::getTextures(AVFrame *frame)
+{
+ AndroidSurfaceTexture * androidSurfaceTexture = getTextureSurface(frame);
+
+ if (!androidSurfaceTexture || !androidSurfaceTexture->isValid())
+ return {};
+
+ if (!externalTexture || m_currentSurfaceIndex != androidSurfaceTexture->index()) {
+ m_currentSurfaceIndex = androidSurfaceTexture->index();
+ androidSurfaceTexture->detachFromGLContext();
+ externalTexture = std::unique_ptr<QRhiTexture>(
+ rhi->newTexture(QRhiTexture::Format::RGBA8, { frame->width, frame->height }, 1,
+ QRhiTexture::ExternalOES));
+
+ if (!externalTexture->create()) {
+ qWarning() << "Failed to create the external texture!";
+ return {};
+ }
+
+ quint64 textureHandle = externalTexture->nativeTexture().object;
+ androidSurfaceTexture->attachToGLContext(textureHandle);
+ }
+
+ // release a MediaCodec buffer and render it to the surface
+ AVMediaCodecBuffer *buffer = (AVMediaCodecBuffer *)frame->data[3];
+
+ if (!buffer) {
+ qWarning() << "Received a frame without AVMediaCodecBuffer.";
+ } else if (av_mediacodec_release_buffer(buffer, 1) < 0) {
+ qWarning() << "Failed to render buffer to surface.";
+ return {};
+ }
+
+ androidSurfaceTexture->updateTexImage();
+
+ return new MediaCodecTextureSet(externalTexture->nativeTexture().object);
+}
+}
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_mediacodec_p.h b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_mediacodec_p.h
new file mode 100644
index 000000000..79d33d03e
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_mediacodec_p.h
@@ -0,0 +1,36 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGHWACCEL_MEDIACODEC_P_H
+#define QFFMPEGHWACCEL_MEDIACODEC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpeghwaccel_p.h"
+#include <memory>
+
+namespace QFFmpeg {
+struct Frame;
+
+class MediaCodecTextureConverter : public TextureConverterBackend
+{
+public:
+ MediaCodecTextureConverter(QRhi *rhi) : TextureConverterBackend(rhi){};
+ TextureSet *getTextures(AVFrame *frame) override;
+
+ static void setupDecoderSurface(AVCodecContext *s);
+private:
+ std::unique_ptr<QRhiTexture> externalTexture;
+ quint64 m_currentSurfaceIndex = 0;
+};
+}
+#endif // QFFMPEGHWACCEL_MEDIACODEC_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_p.h b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_p.h
new file mode 100644
index 000000000..bc6547f12
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_p.h
@@ -0,0 +1,130 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGHWACCEL_P_H
+#define QFFMPEGHWACCEL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpeg_p.h"
+#include "qvideoframeformat.h"
+#include "qabstractvideobuffer.h"
+
+#include <qshareddata.h>
+#include <memory>
+#include <functional>
+#include <mutex>
+
+QT_BEGIN_NAMESPACE
+
+class QRhi;
+class QRhiTexture;
+class QFFmpegVideoBuffer;
+
+namespace QFFmpeg {
+
+// used for the get_format callback for the decoder
+enum AVPixelFormat getFormat(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
+
+class HWAccel;
+
+class TextureSet {
+public:
+ // ### Should add QVideoFrameFormat::PixelFormat here
+ virtual ~TextureSet() {}
+ virtual qint64 textureHandle(QRhi *, int /*plane*/) { return 0; }
+};
+
+class TextureConverterBackend
+{
+public:
+ TextureConverterBackend(QRhi *rhi)
+ : rhi(rhi)
+ {}
+ virtual ~TextureConverterBackend() {}
+ virtual TextureSet *getTextures(AVFrame * /*frame*/) { return nullptr; }
+
+ QRhi *rhi = nullptr;
+};
+
+class TextureConverter
+{
+ class Data final
+ {
+ public:
+ QAtomicInt ref = 0;
+ QRhi *rhi = nullptr;
+ AVPixelFormat format = AV_PIX_FMT_NONE;
+ std::unique_ptr<TextureConverterBackend> backend;
+ };
+public:
+ TextureConverter(QRhi *rhi = nullptr);
+
+ void init(AVFrame *frame) {
+ AVPixelFormat fmt = frame ? AVPixelFormat(frame->format) : AV_PIX_FMT_NONE;
+ if (fmt != d->format)
+ updateBackend(fmt);
+ }
+ TextureSet *getTextures(AVFrame *frame);
+ bool isNull() const { return !d->backend || !d->backend->rhi; }
+
+private:
+ void updateBackend(AVPixelFormat format);
+
+ QExplicitlySharedDataPointer<Data> d;
+};
+
+class HWAccel
+{
+ AVBufferUPtr m_hwDeviceContext;
+ AVBufferUPtr m_hwFramesContext;
+
+ mutable std::once_flag m_constraintsOnceFlag;
+ mutable AVHWFramesConstraintsUPtr m_constraints;
+
+public:
+ ~HWAccel();
+
+ static std::unique_ptr<HWAccel> create(AVHWDeviceType deviceType);
+
+ static std::pair<const AVCodec *, std::unique_ptr<HWAccel>>
+ findEncoderWithHwAccel(AVCodecID id,
+ const std::function<bool(const HWAccel &)>& hwAccelPredicate = nullptr);
+
+ static std::pair<const AVCodec *, std::unique_ptr<HWAccel>>
+ findDecoderWithHwAccel(AVCodecID id,
+ const std::function<bool(const HWAccel &)>& hwAccelPredicate = nullptr);
+
+ AVHWDeviceType deviceType() const;
+
+ AVBufferRef *hwDeviceContextAsBuffer() const { return m_hwDeviceContext.get(); }
+ AVHWDeviceContext *hwDeviceContext() const;
+ AVPixelFormat hwFormat() const;
+ const AVHWFramesConstraints *constraints() const;
+
+ void createFramesContext(AVPixelFormat swFormat, const QSize &size);
+ AVBufferRef *hwFramesContextAsBuffer() const { return m_hwFramesContext.get(); }
+ AVHWFramesContext *hwFramesContext() const;
+
+ static AVPixelFormat format(AVFrame *frame);
+ static const std::vector<AVHWDeviceType> &encodingDeviceTypes();
+
+ static const std::vector<AVHWDeviceType> &decodingDeviceTypes();
+
+private:
+ HWAccel(AVBufferUPtr hwDeviceContext) : m_hwDeviceContext(std::move(hwDeviceContext)) { }
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp
new file mode 100644
index 000000000..7e46e3537
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp
@@ -0,0 +1,364 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpeghwaccel_vaapi_p.h"
+
+#if !QT_CONFIG(vaapi)
+#error "Configuration error"
+#endif
+
+#include <va/va.h>
+
+#include <qvideoframeformat.h>
+#include "qffmpegvideobuffer_p.h"
+#include "private/qvideotexturehelper_p.h"
+
+#include <rhi/qrhi.h>
+
+#include <qguiapplication.h>
+#include <qpa/qplatformnativeinterface.h>
+
+#include <qopenglfunctions.h>
+
+//#define VA_EXPORT_USE_LAYERS
+
+#if __has_include("drm/drm_fourcc.h")
+#include <drm/drm_fourcc.h>
+#elif __has_include("libdrm/drm_fourcc.h")
+#include <libdrm/drm_fourcc.h>
+#else
+// keep things building without drm_fourcc.h
+#define fourcc_code(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
+ ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
+
+#define DRM_FORMAT_RGBA8888 fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */
+#define DRM_FORMAT_RGB888 fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */
+#define DRM_FORMAT_RG88 fourcc_code('R', 'G', '8', '8') /* [15:0] R:G 8:8 little endian */
+#define DRM_FORMAT_ABGR8888 fourcc_code('A', 'B', '2', '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */
+#define DRM_FORMAT_BGR888 fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */
+#define DRM_FORMAT_GR88 fourcc_code('G', 'R', '8', '8') /* [15:0] G:R 8:8 little endian */
+#define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R */
+#define DRM_FORMAT_R16 fourcc_code('R', '1', '6', ' ') /* [15:0] R little endian */
+#define DRM_FORMAT_RGB565 fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */
+#define DRM_FORMAT_RG1616 fourcc_code('R', 'G', '3', '2') /* [31:0] R:G 16:16 little endian */
+#define DRM_FORMAT_GR1616 fourcc_code('G', 'R', '3', '2') /* [31:0] G:R 16:16 little endian */
+#define DRM_FORMAT_BGRA1010102 fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
+#endif
+
+extern "C" {
+#include <libavutil/hwcontext_vaapi.h>
+}
+
+#include <va/va_drm.h>
+#include <va/va_drmcommon.h>
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#include <unistd.h>
+
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLHWAccelVAAPI, "qt.multimedia.ffmpeg.hwaccelvaapi");
+
+namespace QFFmpeg {
+
+static const quint32 *fourccFromPixelFormat(const QVideoFrameFormat::PixelFormat format)
+{
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ const quint32 rgba_fourcc = DRM_FORMAT_ABGR8888;
+ const quint32 rg_fourcc = DRM_FORMAT_GR88;
+ const quint32 rg16_fourcc = DRM_FORMAT_GR1616;
+#else
+ const quint32 rgba_fourcc = DRM_FORMAT_RGBA8888;
+ const quint32 rg_fourcc = DRM_FORMAT_RG88;
+ const quint32 rg16_fourcc = DRM_FORMAT_RG1616;
+#endif
+
+// qCDebug(qLHWAccelVAAPI) << "Getting DRM fourcc for pixel format" << format;
+
+ switch (format) {
+ case QVideoFrameFormat::Format_Invalid:
+ case QVideoFrameFormat::Format_IMC1:
+ case QVideoFrameFormat::Format_IMC2:
+ case QVideoFrameFormat::Format_IMC3:
+ case QVideoFrameFormat::Format_IMC4:
+ case QVideoFrameFormat::Format_SamplerExternalOES:
+ case QVideoFrameFormat::Format_Jpeg:
+ case QVideoFrameFormat::Format_SamplerRect:
+ return nullptr;
+
+ case QVideoFrameFormat::Format_ARGB8888:
+ case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
+ case QVideoFrameFormat::Format_XRGB8888:
+ case QVideoFrameFormat::Format_BGRA8888:
+ case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
+ case QVideoFrameFormat::Format_BGRX8888:
+ case QVideoFrameFormat::Format_ABGR8888:
+ case QVideoFrameFormat::Format_XBGR8888:
+ case QVideoFrameFormat::Format_RGBA8888:
+ case QVideoFrameFormat::Format_RGBX8888:
+ case QVideoFrameFormat::Format_AYUV:
+ case QVideoFrameFormat::Format_AYUV_Premultiplied:
+ case QVideoFrameFormat::Format_UYVY:
+ case QVideoFrameFormat::Format_YUYV:
+ {
+ static constexpr quint32 format[] = { rgba_fourcc, 0, 0, 0 };
+ return format;
+ }
+
+ case QVideoFrameFormat::Format_Y8:
+ {
+ static constexpr quint32 format[] = { DRM_FORMAT_R8, 0, 0, 0 };
+ return format;
+ }
+ case QVideoFrameFormat::Format_Y16:
+ {
+ static constexpr quint32 format[] = { DRM_FORMAT_R16, 0, 0, 0 };
+ return format;
+ }
+
+ case QVideoFrameFormat::Format_YUV420P:
+ case QVideoFrameFormat::Format_YUV422P:
+ case QVideoFrameFormat::Format_YV12:
+ {
+ static constexpr quint32 format[] = { DRM_FORMAT_R8, DRM_FORMAT_R8, DRM_FORMAT_R8, 0 };
+ return format;
+ }
+ case QVideoFrameFormat::Format_YUV420P10:
+ {
+ static constexpr quint32 format[] = { DRM_FORMAT_R16, DRM_FORMAT_R16, DRM_FORMAT_R16, 0 };
+ return format;
+ }
+
+ case QVideoFrameFormat::Format_NV12:
+ case QVideoFrameFormat::Format_NV21:
+ {
+ static constexpr quint32 format[] = { DRM_FORMAT_R8, rg_fourcc, 0, 0 };
+ return format;
+ }
+
+ case QVideoFrameFormat::Format_P010:
+ case QVideoFrameFormat::Format_P016:
+ {
+ static constexpr quint32 format[] = { DRM_FORMAT_R16, rg16_fourcc, 0, 0 };
+ return format;
+ }
+ }
+ return nullptr;
+}
+
+class VAAPITextureSet : public TextureSet
+{
+public:
+ ~VAAPITextureSet();
+ qint64 textureHandle(QRhi *, int plane) override {
+ return textures[plane];
+ }
+
+ QRhi *rhi = nullptr;
+ QOpenGLContext *glContext = nullptr;
+ int nPlanes = 0;
+ GLuint textures[4] = {};
+};
+
+
+VAAPITextureConverter::VAAPITextureConverter(QRhi *rhi)
+ : TextureConverterBackend(nullptr)
+{
+ qCDebug(qLHWAccelVAAPI) << ">>>> Creating VAAPI HW accelerator";
+
+ if (!rhi || rhi->backend() != QRhi::OpenGLES2) {
+ qWarning() << "VAAPITextureConverter: No rhi or non openGL based RHI";
+ this->rhi = nullptr;
+ return;
+ }
+
+ auto *nativeHandles = static_cast<const QRhiGles2NativeHandles *>(rhi->nativeHandles());
+ glContext = nativeHandles->context;
+ if (!glContext) {
+ qCDebug(qLHWAccelVAAPI) << " no GL context, disabling";
+ return;
+ }
+ const QString platform = QGuiApplication::platformName();
+ QPlatformNativeInterface *pni = QGuiApplication::platformNativeInterface();
+ eglDisplay = pni->nativeResourceForIntegration(QByteArrayLiteral("egldisplay"));
+ qCDebug(qLHWAccelVAAPI) << " platform is" << platform << eglDisplay;
+
+ if (!eglDisplay) {
+ qCDebug(qLHWAccelVAAPI) << " no egl display, disabling";
+ return;
+ }
+ eglImageTargetTexture2D = eglGetProcAddress("glEGLImageTargetTexture2DOES");
+ if (!eglDisplay) {
+ qCDebug(qLHWAccelVAAPI) << " no eglImageTargetTexture2D, disabling";
+ return;
+ }
+
+ // everything ok, indicate that we can do zero copy
+ this->rhi = rhi;
+}
+
+VAAPITextureConverter::~VAAPITextureConverter()
+{
+}
+
+//#define VA_EXPORT_USE_LAYERS
+TextureSet *VAAPITextureConverter::getTextures(AVFrame *frame)
+{
+// qCDebug(qLHWAccelVAAPI) << "VAAPIAccel::getTextures";
+ if (frame->format != AV_PIX_FMT_VAAPI || !eglDisplay) {
+ qCDebug(qLHWAccelVAAPI) << "format/egl error" << frame->format << eglDisplay;
+ return nullptr;
+ }
+
+ if (!frame->hw_frames_ctx)
+ return nullptr;
+
+ auto *fCtx = (AVHWFramesContext *)frame->hw_frames_ctx->data;
+ auto *ctx = fCtx->device_ctx;
+ if (!ctx)
+ return nullptr;
+
+ auto *vaCtx = (AVVAAPIDeviceContext *)ctx->hwctx;
+ auto vaDisplay = vaCtx->display;
+ if (!vaDisplay) {
+ qCDebug(qLHWAccelVAAPI) << " no VADisplay, disabling";
+ return nullptr;
+ }
+
+ VASurfaceID vaSurface = (uintptr_t)frame->data[3];
+
+ VADRMPRIMESurfaceDescriptor prime = {};
+ if (vaExportSurfaceHandle(vaDisplay, vaSurface,
+ VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
+ VA_EXPORT_SURFACE_READ_ONLY |
+#ifdef VA_EXPORT_USE_LAYERS
+ VA_EXPORT_SURFACE_SEPARATE_LAYERS,
+#else
+ VA_EXPORT_SURFACE_COMPOSED_LAYERS,
+#endif
+ &prime) != VA_STATUS_SUCCESS)
+ {
+ qWarning() << "vaExportSurfaceHandle failed";
+ return nullptr;
+ }
+
+ // Make sure all fd's in 'prime' are closed when we return from this function
+ QScopeGuard closeObjectsGuard([&prime]() {
+ for (uint32_t i = 0; i < prime.num_objects; ++i)
+ close(prime.objects[i].fd);
+ });
+
+ // ### Check that prime.fourcc is what we expect
+ vaSyncSurface(vaDisplay, vaSurface);
+
+// qCDebug(qLHWAccelVAAPI) << "VAAPIAccel: vaSufraceDesc: width/height" << prime.width << prime.height << "num objects"
+// << prime.num_objects << "num layers" << prime.num_layers;
+
+ QOpenGLFunctions functions(glContext);
+
+ AVPixelFormat fmt = HWAccel::format(frame);
+ bool needsConversion;
+ auto qtFormat = QFFmpegVideoBuffer::toQtPixelFormat(fmt, &needsConversion);
+ auto *drm_formats = fourccFromPixelFormat(qtFormat);
+ if (!drm_formats || needsConversion) {
+ qWarning() << "can't use DMA transfer for pixel format" << fmt << qtFormat;
+ return nullptr;
+ }
+
+ auto *desc = QVideoTextureHelper::textureDescription(qtFormat);
+ int nPlanes = 0;
+ for (; nPlanes < 5; ++nPlanes) {
+ if (drm_formats[nPlanes] == 0)
+ break;
+ }
+ Q_ASSERT(nPlanes == desc->nplanes);
+ nPlanes = desc->nplanes;
+// qCDebug(qLHWAccelVAAPI) << "VAAPIAccel: nPlanes" << nPlanes;
+
+ rhi->makeThreadLocalNativeContextCurrent();
+
+ EGLImage images[4];
+ GLuint glTextures[4] = {};
+ functions.glGenTextures(nPlanes, glTextures);
+ for (int i = 0; i < nPlanes; ++i) {
+#ifdef VA_EXPORT_USE_LAYERS
+#define LAYER i
+#define PLANE 0
+ if (prime.layers[i].drm_format != drm_formats[i]) {
+ qWarning() << "expected DRM format check failed expected"
+ << Qt::hex << drm_formats[i] << "got" << prime.layers[i].drm_format;
+ }
+#else
+#define LAYER 0
+#define PLANE i
+#endif
+
+ EGLAttrib img_attr[] = {
+ EGL_LINUX_DRM_FOURCC_EXT, (EGLint)drm_formats[i],
+ EGL_WIDTH, desc->widthForPlane(frame->width, i),
+ EGL_HEIGHT, desc->heightForPlane(frame->height, i),
+ EGL_DMA_BUF_PLANE0_FD_EXT, prime.objects[prime.layers[LAYER].object_index[PLANE]].fd,
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, (EGLint)prime.layers[LAYER].offset[PLANE],
+ EGL_DMA_BUF_PLANE0_PITCH_EXT, (EGLint)prime.layers[LAYER].pitch[PLANE],
+ EGL_NONE
+ };
+ images[i] = eglCreateImage(eglDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, nullptr, img_attr);
+ if (!images[i]) {
+ const GLenum error = eglGetError();
+ if (error == EGL_BAD_MATCH) {
+ qWarning() << "eglCreateImage failed for plane" << i << "with error code EGL_BAD_MATCH, "
+ "disabling hardware acceleration. This could indicate an EGL implementation issue."
+ "\nVAAPI driver: " << vaQueryVendorString(vaDisplay)
+ << "\nEGL vendor:" << eglQueryString(eglDisplay, EGL_VENDOR);
+ this->rhi = nullptr; // Disabling texture conversion here to fix QTBUG-112312
+ return nullptr;
+ }
+ if (error) {
+ qWarning() << "eglCreateImage failed for plane" << i << "with error code" << error;
+ return nullptr;
+ }
+ }
+ functions.glActiveTexture(GL_TEXTURE0 + i);
+ functions.glBindTexture(GL_TEXTURE_2D, glTextures[i]);
+
+ PFNGLEGLIMAGETARGETTEXTURE2DOESPROC eglImageTargetTexture2D = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)this->eglImageTargetTexture2D;
+ eglImageTargetTexture2D(GL_TEXTURE_2D, images[i]);
+ GLenum error = glGetError();
+ if (error)
+ qWarning() << "eglImageTargetTexture2D failed with error code" << error;
+ }
+
+ for (int i = 0; i < nPlanes; ++i) {
+ functions.glActiveTexture(GL_TEXTURE0 + i);
+ functions.glBindTexture(GL_TEXTURE_2D, 0);
+ eglDestroyImage(eglDisplay, images[i]);
+ }
+
+ VAAPITextureSet *textureSet = new VAAPITextureSet;
+ textureSet->nPlanes = nPlanes;
+ textureSet->rhi = rhi;
+ textureSet->glContext = glContext;
+
+ for (int i = 0; i < 4; ++i)
+ textureSet->textures[i] = glTextures[i];
+// qCDebug(qLHWAccelVAAPI) << "VAAPIAccel: got textures" << textures[0] << textures[1] << textures[2] << textures[3];
+
+ return textureSet;
+}
+
+VAAPITextureSet::~VAAPITextureSet()
+{
+ if (rhi) {
+ rhi->makeThreadLocalNativeContextCurrent();
+ QOpenGLFunctions functions(glContext);
+ functions.glDeleteTextures(nPlanes, textures);
+ }
+}
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi_p.h b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi_p.h
new file mode 100644
index 000000000..03084cc72
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi_p.h
@@ -0,0 +1,48 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGHWACCEL_VAAPI_P_H
+#define QFFMPEGHWACCEL_VAAPI_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpeghwaccel_p.h"
+
+#if QT_CONFIG(vaapi)
+
+#include <qshareddata.h>
+
+QT_BEGIN_NAMESPACE
+
+class QRhi;
+class QOpenGLContext;
+
+namespace QFFmpeg {
+
+class VAAPITextureConverter : public TextureConverterBackend
+{
+public:
+ VAAPITextureConverter(QRhi *rhi);
+ ~VAAPITextureConverter();
+
+ TextureSet *getTextures(AVFrame *frame) override;
+
+ Qt::HANDLE eglDisplay = nullptr;
+ QOpenGLContext *glContext = nullptr;
+ QFunctionPointer eglImageTargetTexture2D = nullptr;
+};
+}
+
+QT_END_NAMESPACE
+
+#endif
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_videotoolbox.mm b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_videotoolbox.mm
new file mode 100644
index 000000000..948f7fc23
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_videotoolbox.mm
@@ -0,0 +1,288 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpeghwaccel_videotoolbox_p.h"
+
+#if !defined(Q_OS_DARWIN)
+#error "Configuration error"
+#endif
+
+#include <qvideoframeformat.h>
+#include <qffmpegvideobuffer_p.h>
+#include <qloggingcategory.h>
+#include "private/qvideotexturehelper_p.h"
+
+#include <rhi/qrhi.h>
+
+#include <CoreVideo/CVMetalTexture.h>
+#include <CoreVideo/CVMetalTextureCache.h>
+
+#include <qopenglcontext.h>
+#ifdef Q_OS_MACOS
+#import <AppKit/AppKit.h>
+#endif
+#ifdef Q_OS_IOS
+#import <OpenGLES/EAGL.h>
+#endif
+#import <Metal/Metal.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcVideotoolbox, "qt.multimedia.ffmpeg.videotoolbox")
+
+namespace QFFmpeg
+{
+
+static CVMetalTextureCacheRef &mtc(void *&cache) { return reinterpret_cast<CVMetalTextureCacheRef &>(cache); }
+
+class VideoToolBoxTextureSet : public TextureSet
+{
+public:
+ ~VideoToolBoxTextureSet();
+ qint64 textureHandle(QRhi *, int plane) override;
+
+ QRhi *rhi = nullptr;
+ CVMetalTextureRef cvMetalTexture[3] = {};
+
+#if defined(Q_OS_MACOS)
+ CVOpenGLTextureRef cvOpenGLTexture = nullptr;
+#elif defined(Q_OS_IOS)
+ CVOpenGLESTextureRef cvOpenGLESTexture = nullptr;
+#endif
+
+ CVImageBufferRef m_buffer = nullptr;
+};
+
+VideoToolBoxTextureConverter::VideoToolBoxTextureConverter(QRhi *rhi)
+ : TextureConverterBackend(rhi)
+{
+ if (!rhi)
+ return;
+
+ if (rhi->backend() == QRhi::Metal) {
+ const auto *metal = static_cast<const QRhiMetalNativeHandles *>(rhi->nativeHandles());
+
+ // Create a Metal Core Video texture cache from the pixel buffer.
+ Q_ASSERT(!cvMetalTextureCache);
+ if (CVMetalTextureCacheCreate(
+ kCFAllocatorDefault,
+ nil,
+ (id<MTLDevice>)metal->dev,
+ nil,
+ &mtc(cvMetalTextureCache)) != kCVReturnSuccess) {
+ qWarning() << "Metal texture cache creation failed";
+ rhi = nullptr;
+ }
+ } else if (rhi->backend() == QRhi::OpenGLES2) {
+#if QT_CONFIG(opengl)
+#ifdef Q_OS_MACOS
+ const auto *gl = static_cast<const QRhiGles2NativeHandles *>(rhi->nativeHandles());
+
+ auto nsGLContext = gl->context->nativeInterface<QNativeInterface::QCocoaGLContext>()->nativeContext();
+ auto nsGLPixelFormat = nsGLContext.pixelFormat.CGLPixelFormatObj;
+
+ // Create an OpenGL CoreVideo texture cache from the pixel buffer.
+ if (CVOpenGLTextureCacheCreate(
+ kCFAllocatorDefault,
+ nullptr,
+ reinterpret_cast<CGLContextObj>(nsGLContext.CGLContextObj),
+ nsGLPixelFormat,
+ nil,
+ &cvOpenGLTextureCache)) {
+ qWarning() << "OpenGL texture cache creation failed";
+ rhi = nullptr;
+ }
+#endif
+#ifdef Q_OS_IOS
+ // Create an OpenGL CoreVideo texture cache from the pixel buffer.
+ if (CVOpenGLESTextureCacheCreate(
+ kCFAllocatorDefault,
+ nullptr,
+ [EAGLContext currentContext],
+ nullptr,
+ &cvOpenGLESTextureCache)) {
+ qWarning() << "OpenGL texture cache creation failed";
+ rhi = nullptr;
+ }
+#endif
+#else
+ rhi = nullptr;
+#endif // QT_CONFIG(opengl)
+ }
+}
+
+VideoToolBoxTextureConverter::~VideoToolBoxTextureConverter()
+{
+ freeTextureCaches();
+}
+
+void VideoToolBoxTextureConverter::freeTextureCaches()
+{
+ if (cvMetalTextureCache)
+ CFRelease(cvMetalTextureCache);
+ cvMetalTextureCache = nullptr;
+#if defined(Q_OS_MACOS)
+ if (cvOpenGLTextureCache)
+ CFRelease(cvOpenGLTextureCache);
+ cvOpenGLTextureCache = nullptr;
+#elif defined(Q_OS_IOS)
+ if (cvOpenGLESTextureCache)
+ CFRelease(cvOpenGLESTextureCache);
+ cvOpenGLESTextureCache = nullptr;
+#endif
+}
+
+static MTLPixelFormat rhiTextureFormatToMetalFormat(QRhiTexture::Format f)
+{
+ switch (f) {
+ default:
+ case QRhiTexture::UnknownFormat:
+ return MTLPixelFormatInvalid;
+ case QRhiTexture::RGBA8:
+ return MTLPixelFormatRGBA8Unorm;
+ case QRhiTexture::BGRA8:
+ return MTLPixelFormatBGRA8Unorm;
+ case QRhiTexture::R8:
+ return MTLPixelFormatR8Unorm;
+ case QRhiTexture::RG8:
+ return MTLPixelFormatRG8Unorm;
+ case QRhiTexture::R16:
+ return MTLPixelFormatR16Unorm;
+ case QRhiTexture::RG16:
+ return MTLPixelFormatRG16Unorm;
+
+ case QRhiTexture::RGBA16F:
+ return MTLPixelFormatRGBA16Float;
+ case QRhiTexture::RGBA32F:
+ return MTLPixelFormatRGBA32Float;
+ case QRhiTexture::R16F:
+ return MTLPixelFormatR16Float;
+ case QRhiTexture::R32F:
+ return MTLPixelFormatR32Float;
+ }
+}
+
+TextureSet *VideoToolBoxTextureConverter::getTextures(AVFrame *frame)
+{
+ if (!rhi)
+ return nullptr;
+
+ bool needsConversion = false;
+ QVideoFrameFormat::PixelFormat pixelFormat = QFFmpegVideoBuffer::toQtPixelFormat(HWAccel::format(frame), &needsConversion);
+ if (needsConversion) {
+ // qDebug() << "XXXXXXXXXXXX pixel format needs conversion" << pixelFormat << HWAccel::format(frame);
+ return nullptr;
+ }
+
+ CVPixelBufferRef buffer = (CVPixelBufferRef)frame->data[3];
+
+ auto textureSet = std::make_unique<VideoToolBoxTextureSet>();
+ textureSet->m_buffer = buffer;
+ textureSet->rhi = rhi;
+ CVPixelBufferRetain(buffer);
+
+ auto *textureDescription = QVideoTextureHelper::textureDescription(pixelFormat);
+ int bufferPlanes = CVPixelBufferGetPlaneCount(buffer);
+// qDebug() << "XXXXX getTextures" << pixelFormat << bufferPlanes << buffer;
+
+ if (rhi->backend() == QRhi::Metal) {
+ for (int plane = 0; plane < bufferPlanes; ++plane) {
+ size_t width = CVPixelBufferGetWidth(buffer);
+ size_t height = CVPixelBufferGetHeight(buffer);
+ width = textureDescription->widthForPlane(width, plane);
+ height = textureDescription->heightForPlane(height, plane);
+
+ // Create a CoreVideo pixel buffer backed Metal texture image from the texture cache.
+ auto ret = CVMetalTextureCacheCreateTextureFromImage(
+ kCFAllocatorDefault,
+ mtc(cvMetalTextureCache),
+ buffer, nil,
+ rhiTextureFormatToMetalFormat(textureDescription->textureFormat[plane]),
+ width, height,
+ plane,
+ &textureSet->cvMetalTexture[plane]);
+
+ if (ret != kCVReturnSuccess)
+ qWarning() << "texture creation failed" << ret;
+// auto t = CVMetalTextureGetTexture(textureSet->cvMetalTexture[plane]);
+// qDebug() << " metal texture for plane" << plane << "is" << quint64(textureSet->cvMetalTexture[plane]) << width << height;
+// qDebug() << " " << t.iosurfacePlane << t.pixelFormat << t.width << t.height;
+ }
+ } else if (rhi->backend() == QRhi::OpenGLES2) {
+#if QT_CONFIG(opengl)
+#ifdef Q_OS_MACOS
+ CVOpenGLTextureCacheFlush(cvOpenGLTextureCache, 0);
+ // Create a CVPixelBuffer-backed OpenGL texture image from the texture cache.
+ const CVReturn cvret = CVOpenGLTextureCacheCreateTextureFromImage(
+ kCFAllocatorDefault,
+ cvOpenGLTextureCache,
+ buffer,
+ nil,
+ &textureSet->cvOpenGLTexture);
+ if (cvret != kCVReturnSuccess) {
+ qCWarning(qLcVideotoolbox) << "OpenGL texture creation failed" << cvret;
+ return nullptr;
+ }
+
+ Q_ASSERT(CVOpenGLTextureGetTarget(textureSet->cvOpenGLTexture) == GL_TEXTURE_RECTANGLE);
+#endif
+#ifdef Q_OS_IOS
+ CVOpenGLESTextureCacheFlush(cvOpenGLESTextureCache, 0);
+ // Create a CVPixelBuffer-backed OpenGL texture image from the texture cache.
+ const CVReturn cvret = CVOpenGLESTextureCacheCreateTextureFromImage(
+ kCFAllocatorDefault,
+ cvOpenGLESTextureCache,
+ buffer,
+ nil,
+ GL_TEXTURE_2D,
+ GL_RGBA,
+ CVPixelBufferGetWidth(buffer),
+ CVPixelBufferGetHeight(buffer),
+ GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ 0,
+ &textureSet->cvOpenGLESTexture);
+ if (cvret != kCVReturnSuccess) {
+ qCWarning(qLcVideotoolbox) << "OpenGL ES texture creation failed" << cvret;
+ return nullptr;
+ }
+#endif
+#endif
+ }
+
+ return textureSet.release();
+}
+
+VideoToolBoxTextureSet::~VideoToolBoxTextureSet()
+{
+ for (int i = 0; i < 4; ++i)
+ if (cvMetalTexture[i])
+ CFRelease(cvMetalTexture[i]);
+#if defined(Q_OS_MACOS)
+ if (cvOpenGLTexture)
+ CVOpenGLTextureRelease(cvOpenGLTexture);
+#elif defined(Q_OS_IOS)
+ if (cvOpenGLESTexture)
+ CFRelease(cvOpenGLESTexture);
+#endif
+ CVPixelBufferRelease(m_buffer);
+}
+
+qint64 VideoToolBoxTextureSet::textureHandle(QRhi *, int plane)
+{
+ if (rhi->backend() == QRhi::Metal)
+ return cvMetalTexture[plane] ? qint64(CVMetalTextureGetTexture(cvMetalTexture[plane])) : 0;
+#if QT_CONFIG(opengl)
+ Q_ASSERT(plane == 0);
+#ifdef Q_OS_MACOS
+ return CVOpenGLTextureGetName(cvOpenGLTexture);
+#endif
+#ifdef Q_OS_IOS
+ return CVOpenGLESTextureGetName(cvOpenGLESTexture);
+#endif
+#endif
+}
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_videotoolbox_p.h b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_videotoolbox_p.h
new file mode 100644
index 000000000..44fa32dd2
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_videotoolbox_p.h
@@ -0,0 +1,63 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGHWACCEL_VIDEOTOOLBOX_P_H
+#define QFFMPEGHWACCEL_VIDEOTOOLBOX_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpeghwaccel_p.h"
+
+#ifdef Q_OS_DARWIN
+
+#include <CoreVideo/CVBase.h>
+#include <CoreVideo/CVPixelBuffer.h>
+#include <CoreVideo/CVImageBuffer.h>
+
+#include <CoreVideo/CVMetalTexture.h>
+#if defined(Q_OS_MACOS)
+#include <CoreVideo/CVOpenGLTextureCache.h>
+#elif defined(Q_OS_IOS)
+#include <CoreVideo/CVOpenGLESTextureCache.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class QRhi;
+
+namespace QFFmpeg {
+
+class VideoToolBoxTextureConverter : public TextureConverterBackend
+{
+public:
+ VideoToolBoxTextureConverter(QRhi *rhi);
+ ~VideoToolBoxTextureConverter();
+ TextureSet *getTextures(AVFrame *frame) override;
+
+private:
+ void freeTextureCaches();
+
+ // can not forward declare that type from C++ :/
+ void *cvMetalTextureCache = nullptr;
+#if defined(Q_OS_MACOS)
+ CVOpenGLTextureCacheRef cvOpenGLTextureCache = nullptr;
+#elif defined(Q_OS_IOS)
+ CVOpenGLESTextureCacheRef cvOpenGLESTextureCache = nullptr;
+#endif
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegimagecapture.cpp b/src/plugins/multimedia/ffmpeg/qffmpegimagecapture.cpp
new file mode 100644
index 000000000..2fb878784
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegimagecapture.cpp
@@ -0,0 +1,271 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegimagecapture_p.h"
+#include <private/qplatformmediaformatinfo_p.h>
+#include <private/qplatformcamera_p.h>
+#include <private/qplatformimagecapture_p.h>
+#include <qvideoframeformat.h>
+#include <private/qmediastoragelocation_p.h>
+#include <qimagewriter.h>
+
+#include <QtCore/QDebug>
+#include <QtCore/QDir>
+#include <qstandardpaths.h>
+
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+// Probably, might be increased. To be investigated and tested on Android implementation
+static constexpr int MaxPendingImagesCount = 1;
+
+static Q_LOGGING_CATEGORY(qLcImageCapture, "qt.multimedia.imageCapture")
+
+QFFmpegImageCapture::QFFmpegImageCapture(QImageCapture *parent)
+ : QPlatformImageCapture(parent)
+{
+ qRegisterMetaType<QVideoFrame>();
+}
+
+QFFmpegImageCapture::~QFFmpegImageCapture()
+{
+}
+
+bool QFFmpegImageCapture::isReadyForCapture() const
+{
+ return m_isReadyForCapture;
+}
+
+static const char *extensionForFormat(QImageCapture::FileFormat format)
+{
+ const char *fmt = "jpg";
+ switch (format) {
+ case QImageCapture::UnspecifiedFormat:
+ case QImageCapture::JPEG:
+ fmt = "jpg";
+ break;
+ case QImageCapture::PNG:
+ fmt = "png";
+ break;
+ case QImageCapture::WebP:
+ fmt = "webp";
+ break;
+ case QImageCapture::Tiff:
+ fmt = "tiff";
+ break;
+ }
+ return fmt;
+}
+
+int QFFmpegImageCapture::capture(const QString &fileName)
+{
+ QString path = QMediaStorageLocation::generateFileName(fileName, QStandardPaths::PicturesLocation, QLatin1String(extensionForFormat(m_settings.format())));
+ return doCapture(path);
+}
+
+int QFFmpegImageCapture::captureToBuffer()
+{
+ return doCapture(QString());
+}
+
+int QFFmpegImageCapture::doCapture(const QString &fileName)
+{
+ qCDebug(qLcImageCapture) << "do capture";
+ if (!m_session) {
+ //emit error in the next event loop,
+ //so application can associate it with returned request id.
+ QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
+ Q_ARG(int, -1),
+ Q_ARG(int, QImageCapture::ResourceError),
+ Q_ARG(QString, QPlatformImageCapture::msgImageCaptureNotSet()));
+
+ qCDebug(qLcImageCapture) << "error 1";
+ return -1;
+ }
+ if (!m_videoSource) {
+ //emit error in the next event loop,
+ //so application can associate it with returned request id.
+ QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
+ Q_ARG(int, -1),
+ Q_ARG(int, QImageCapture::ResourceError),
+ Q_ARG(QString,tr("No camera available.")));
+
+ qCDebug(qLcImageCapture) << "error 2";
+ return -1;
+ }
+ if (m_pendingImages.size() >= MaxPendingImagesCount) {
+ //emit error in the next event loop,
+ //so application can associate it with returned request id.
+ QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
+ Q_ARG(int, -1),
+ Q_ARG(int, QImageCapture::NotReadyError),
+ Q_ARG(QString, QPlatformImageCapture::msgCameraNotReady()));
+
+ qCDebug(qLcImageCapture) << "error 3";
+ return -1;
+ }
+
+ m_lastId++;
+
+ m_pendingImages.enqueue({ m_lastId, fileName, QMediaMetaData{} });
+ updateReadyForCapture();
+
+ return m_lastId;
+}
+
+void QFFmpegImageCapture::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ auto *captureSession = static_cast<QFFmpegMediaCaptureSession *>(session);
+ if (m_session == captureSession)
+ return;
+
+ if (m_session) {
+ m_session->disconnect(this);
+ m_lastId = 0;
+ m_pendingImages.clear();
+ }
+
+ m_session = captureSession;
+
+ if (m_session)
+ connect(m_session, &QFFmpegMediaCaptureSession::primaryActiveVideoSourceChanged, this,
+ &QFFmpegImageCapture::onVideoSourceChanged);
+
+ onVideoSourceChanged();
+}
+
+void QFFmpegImageCapture::updateReadyForCapture()
+{
+ const bool ready = m_session && m_pendingImages.size() < MaxPendingImagesCount && m_videoSource
+ && m_videoSource->isActive();
+
+ qCDebug(qLcImageCapture) << "updateReadyForCapture" << ready;
+
+ if (std::exchange(m_isReadyForCapture, ready) != ready)
+ emit readyForCaptureChanged(ready);
+}
+
+void QFFmpegImageCapture::newVideoFrame(const QVideoFrame &frame)
+{
+ if (m_pendingImages.empty())
+ return;
+
+ auto pending = m_pendingImages.dequeue();
+
+ qCDebug(qLcImageCapture) << "Taking image" << pending.id;
+
+ emit imageExposed(pending.id);
+ // ### Add metadata from the AVFrame
+ emit imageMetadataAvailable(pending.id, pending.metaData);
+ emit imageAvailable(pending.id, frame);
+ QImage image = frame.toImage();
+ if (m_settings.resolution().isValid() && m_settings.resolution() != image.size())
+ image = image.scaled(m_settings.resolution());
+
+ emit imageCaptured(pending.id, image);
+ if (!pending.filename.isEmpty()) {
+ const char *fmt = nullptr;
+ switch (m_settings.format()) {
+ case QImageCapture::UnspecifiedFormat:
+ case QImageCapture::JPEG:
+ fmt = "jpeg";
+ break;
+ case QImageCapture::PNG:
+ fmt = "png";
+ break;
+ case QImageCapture::WebP:
+ fmt = "webp";
+ break;
+ case QImageCapture::Tiff:
+ fmt = "tiff";
+ break;
+ }
+ int quality = -1;
+ switch (m_settings.quality()) {
+ case QImageCapture::VeryLowQuality:
+ quality = 25;
+ break;
+ case QImageCapture::LowQuality:
+ quality = 50;
+ break;
+ case QImageCapture::NormalQuality:
+ break;
+ case QImageCapture::HighQuality:
+ quality = 75;
+ break;
+ case QImageCapture::VeryHighQuality:
+ quality = 99;
+ break;
+ }
+
+ QImageWriter writer(pending.filename, fmt);
+ writer.setQuality(quality);
+
+ if (writer.write(image)) {
+ emit imageSaved(pending.id, pending.filename);
+ } else {
+ QImageCapture::Error err = QImageCapture::ResourceError;
+ if (writer.error() == QImageWriter::UnsupportedFormatError)
+ err = QImageCapture::FormatError;
+ emit error(pending.id, err, writer.errorString());
+ }
+ }
+
+ updateReadyForCapture();
+}
+
+void QFFmpegImageCapture::setupVideoSourceConnections()
+{
+ connect(m_videoSource, &QPlatformCamera::newVideoFrame, this,
+ &QFFmpegImageCapture::newVideoFrame);
+}
+
+QPlatformVideoSource *QFFmpegImageCapture::videoSource() const
+{
+ return m_videoSource;
+}
+
+void QFFmpegImageCapture::onVideoSourceChanged()
+{
+ if (m_videoSource)
+ m_videoSource->disconnect(this);
+
+ m_videoSource = m_session ? m_session->primaryActiveVideoSource() : nullptr;
+
+ // TODO: optimize, setup the connection only when the capture is ready
+ if (m_videoSource)
+ setupVideoSourceConnections();
+
+ updateReadyForCapture();
+}
+
+QImageEncoderSettings QFFmpegImageCapture::imageSettings() const
+{
+ return m_settings;
+}
+
+void QFFmpegImageCapture::setImageSettings(const QImageEncoderSettings &settings)
+{
+ auto s = settings;
+ const auto supportedFormats = QPlatformMediaIntegration::instance()->formatInfo()->imageFormats;
+ if (supportedFormats.isEmpty()) {
+ emit error(-1, QImageCapture::FormatError, "No image formats supported, can't capture.");
+ return;
+ }
+ if (s.format() == QImageCapture::UnspecifiedFormat) {
+ auto f = QImageCapture::JPEG;
+ if (!supportedFormats.contains(f))
+ f = supportedFormats.first();
+ s.setFormat(f);
+ } else if (!supportedFormats.contains(settings.format())) {
+ emit error(-1, QImageCapture::FormatError, "Image format not supported.");
+ return;
+ }
+
+ m_settings = settings;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegimagecapture_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegimagecapture_p.h b/src/plugins/multimedia/ffmpeg/qffmpegimagecapture_p.h
new file mode 100644
index 000000000..d8174ae05
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegimagecapture_p.h
@@ -0,0 +1,71 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#ifndef QFFMPEGIMAGECAPTURE_H
+#define QFFMPEGIMAGECAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformimagecapture_p.h>
+#include "qffmpegmediacapturesession_p.h"
+
+#include <QtCore/qpointer.h>
+#include <qqueue.h>
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegImageCapture : public QPlatformImageCapture
+{
+ Q_OBJECT
+public:
+ QFFmpegImageCapture(QImageCapture *parent);
+ virtual ~QFFmpegImageCapture();
+
+ bool isReadyForCapture() const override;
+ int capture(const QString &fileName) override;
+ int captureToBuffer() override;
+
+ QImageEncoderSettings imageSettings() const override;
+ void setImageSettings(const QImageEncoderSettings &settings) override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session);
+
+protected:
+ virtual int doCapture(const QString &fileName);
+ virtual void setupVideoSourceConnections();
+ QPlatformVideoSource *videoSource() const;
+ void updateReadyForCapture();
+
+protected Q_SLOTS:
+ void newVideoFrame(const QVideoFrame &frame);
+ void onVideoSourceChanged();
+
+private:
+ QFFmpegMediaCaptureSession *m_session = nullptr;
+ QPointer<QPlatformVideoSource> m_videoSource;
+ int m_lastId = 0;
+ QImageEncoderSettings m_settings;
+
+ struct PendingImage {
+ int id;
+ QString filename;
+ QMediaMetaData metaData;
+ };
+
+ QQueue<PendingImage> m_pendingImages;
+ bool m_isReadyForCapture = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGSTREAMERCAPTURECORNTROL_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegioutils.cpp b/src/plugins/multimedia/ffmpeg/qffmpegioutils.cpp
new file mode 100644
index 000000000..cbef88f2b
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegioutils.cpp
@@ -0,0 +1,55 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegioutils_p.h"
+#include "qiodevice.h"
+#include "qffmpegdefs_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+int readQIODevice(void *opaque, uint8_t *buf, int buf_size)
+{
+ auto *dev = static_cast<QIODevice *>(opaque);
+ Q_ASSERT(dev);
+
+ if (dev->atEnd())
+ return AVERROR_EOF;
+ return dev->read(reinterpret_cast<char *>(buf), buf_size);
+}
+
+int writeQIODevice(void *opaque, AvioWriteBufferType buf, int buf_size)
+{
+ auto dev = static_cast<QIODevice *>(opaque);
+ Q_ASSERT(dev);
+
+ return dev->write(reinterpret_cast<const char *>(buf), buf_size);
+}
+
+int64_t seekQIODevice(void *opaque, int64_t offset, int whence)
+{
+ QIODevice *dev = static_cast<QIODevice *>(opaque);
+ Q_ASSERT(dev);
+
+ if (dev->isSequential())
+ return AVERROR(EINVAL);
+
+ if (whence & AVSEEK_SIZE)
+ return dev->size();
+
+ whence &= ~AVSEEK_FORCE;
+
+ if (whence == SEEK_CUR)
+ offset += dev->pos();
+ else if (whence == SEEK_END)
+ offset += dev->size();
+
+ if (!dev->seek(offset))
+ return AVERROR(EINVAL);
+ return offset;
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegioutils_p.h b/src/plugins/multimedia/ffmpeg/qffmpegioutils_p.h
new file mode 100644
index 000000000..7f00990f6
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegioutils_p.h
@@ -0,0 +1,40 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGIOUTILS_P_H
+#define QFFMPEGIOUTILS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qtmultimediaglobal.h"
+#include "qffmpegdefs_p.h"
+
+#include <type_traits>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+int readQIODevice(void *opaque, uint8_t *buf, int buf_size);
+
+using AvioWriteBufferType =
+ std::conditional_t<QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t *>;
+
+int writeQIODevice(void *opaque, AvioWriteBufferType buf, int buf_size);
+
+int64_t seekQIODevice(void *opaque, int64_t offset, int whence);
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGIOUTILS_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediacapturesession.cpp b/src/plugins/multimedia/ffmpeg/qffmpegmediacapturesession.cpp
new file mode 100644
index 000000000..1b6db5813
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediacapturesession.cpp
@@ -0,0 +1,318 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegmediacapturesession_p.h"
+
+#include "private/qplatformaudioinput_p.h"
+#include "private/qplatformaudiooutput_p.h"
+#include "private/qplatformsurfacecapture_p.h"
+#include "private/qplatformaudiobufferinput_p.h"
+#include "private/qplatformvideoframeinput_p.h"
+#include "private/qplatformcamera_p.h"
+
+#include "qffmpegimagecapture_p.h"
+#include "qffmpegmediarecorder_p.h"
+#include "qvideosink.h"
+#include "qffmpegaudioinput_p.h"
+#include "qaudiosink.h"
+#include "qaudiobuffer.h"
+#include "qaudiooutput.h"
+
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcFFmpegMediaCaptureSession, "qt.multimedia.ffmpeg.mediacapturesession")
+
+static int preferredAudioSinkBufferSize(const QFFmpegAudioInput &input)
+{
+ // Heuristic params to avoid jittering
+ // TODO: investigate the reason of jittering and probably reduce the factor
+ constexpr int BufferSizeFactor = 2;
+ constexpr int BufferSizeExceeding = 4096;
+
+ return input.bufferSize() * BufferSizeFactor + BufferSizeExceeding;
+}
+
+QFFmpegMediaCaptureSession::QFFmpegMediaCaptureSession()
+{
+ connect(this, &QFFmpegMediaCaptureSession::primaryActiveVideoSourceChanged, this,
+ &QFFmpegMediaCaptureSession::updateVideoFrameConnection);
+}
+
+QFFmpegMediaCaptureSession::~QFFmpegMediaCaptureSession() = default;
+
+QPlatformCamera *QFFmpegMediaCaptureSession::camera()
+{
+ return m_camera;
+}
+
+void QFFmpegMediaCaptureSession::setCamera(QPlatformCamera *camera)
+{
+ if (setVideoSource(m_camera, camera))
+ emit cameraChanged();
+}
+
+QPlatformSurfaceCapture *QFFmpegMediaCaptureSession::screenCapture()
+{
+ return m_screenCapture;
+}
+
+void QFFmpegMediaCaptureSession::setScreenCapture(QPlatformSurfaceCapture *screenCapture)
+{
+ if (setVideoSource(m_screenCapture, screenCapture))
+ emit screenCaptureChanged();
+}
+
+QPlatformSurfaceCapture *QFFmpegMediaCaptureSession::windowCapture()
+{
+ return m_windowCapture;
+}
+
+void QFFmpegMediaCaptureSession::setWindowCapture(QPlatformSurfaceCapture *windowCapture)
+{
+ if (setVideoSource(m_windowCapture, windowCapture))
+ emit windowCaptureChanged();
+}
+
+QPlatformVideoFrameInput *QFFmpegMediaCaptureSession::videoFrameInput()
+{
+ return m_videoFrameInput;
+}
+
+void QFFmpegMediaCaptureSession::setVideoFrameInput(QPlatformVideoFrameInput *input)
+{
+ if (setVideoSource(m_videoFrameInput, input))
+ emit videoFrameInputChanged();
+}
+
+QPlatformImageCapture *QFFmpegMediaCaptureSession::imageCapture()
+{
+ return m_imageCapture;
+}
+
+void QFFmpegMediaCaptureSession::setImageCapture(QPlatformImageCapture *imageCapture)
+{
+ if (m_imageCapture == imageCapture)
+ return;
+
+ if (m_imageCapture)
+ m_imageCapture->setCaptureSession(nullptr);
+
+ m_imageCapture = static_cast<QFFmpegImageCapture *>(imageCapture);
+
+ if (m_imageCapture)
+ m_imageCapture->setCaptureSession(this);
+
+ emit imageCaptureChanged();
+}
+
+void QFFmpegMediaCaptureSession::setMediaRecorder(QPlatformMediaRecorder *recorder)
+{
+ auto *r = static_cast<QFFmpegMediaRecorder *>(recorder);
+ if (m_mediaRecorder == r)
+ return;
+
+ if (m_mediaRecorder)
+ m_mediaRecorder->setCaptureSession(nullptr);
+ m_mediaRecorder = r;
+ if (m_mediaRecorder)
+ m_mediaRecorder->setCaptureSession(this);
+
+ emit encoderChanged();
+}
+
+QPlatformMediaRecorder *QFFmpegMediaCaptureSession::mediaRecorder()
+{
+ return m_mediaRecorder;
+}
+
+void QFFmpegMediaCaptureSession::setAudioInput(QPlatformAudioInput *input)
+{
+ qCDebug(qLcFFmpegMediaCaptureSession)
+ << "set audio input:" << (input ? input->device.description() : "null");
+
+ auto ffmpegAudioInput = dynamic_cast<QFFmpegAudioInput *>(input);
+ Q_ASSERT(!!input == !!ffmpegAudioInput);
+
+ if (m_audioInput == ffmpegAudioInput)
+ return;
+
+ if (m_audioInput)
+ m_audioInput->q->disconnect(this);
+
+ m_audioInput = ffmpegAudioInput;
+ if (m_audioInput)
+ // TODO: implement the signal in QPlatformAudioInput and connect to it, QTBUG-112294
+ connect(m_audioInput->q, &QAudioInput::deviceChanged, this,
+ &QFFmpegMediaCaptureSession::updateAudioSink);
+
+ updateAudioSink();
+}
+
+void QFFmpegMediaCaptureSession::setAudioBufferInput(QPlatformAudioBufferInput *input)
+{
+ // TODO: implement binding to audio sink like setAudioInput does
+ m_audioBufferInput = input;
+}
+
+void QFFmpegMediaCaptureSession::updateAudioSink()
+{
+ if (m_audioSink) {
+ m_audioSink->reset();
+ m_audioSink.reset();
+ }
+
+ if (!m_audioInput || !m_audioOutput)
+ return;
+
+ auto format = m_audioInput->device.preferredFormat();
+
+ if (!m_audioOutput->device.isFormatSupported(format))
+ qWarning() << "Audio source format" << format << "is not compatible with the audio output";
+
+ m_audioSink = std::make_unique<QAudioSink>(m_audioOutput->device, format);
+
+ m_audioBufferSize = preferredAudioSinkBufferSize(*m_audioInput);
+ m_audioSink->setBufferSize(m_audioBufferSize);
+
+ qCDebug(qLcFFmpegMediaCaptureSession)
+ << "Create audiosink, format:" << format << "bufferSize:" << m_audioSink->bufferSize()
+ << "output device:" << m_audioOutput->device.description();
+
+ m_audioIODevice = m_audioSink->start();
+ if (m_audioIODevice) {
+ auto writeToDevice = [this](const QAudioBuffer &buffer) {
+ if (m_audioBufferSize < preferredAudioSinkBufferSize(*m_audioInput)) {
+ qCDebug(qLcFFmpegMediaCaptureSession)
+ << "Recreate audiosink due to small buffer size:" << m_audioBufferSize;
+
+ updateAudioSink();
+ }
+
+ const auto written =
+ m_audioIODevice->write(buffer.data<const char>(), buffer.byteCount());
+
+ if (written < buffer.byteCount())
+ qCWarning(qLcFFmpegMediaCaptureSession)
+ << "Not all bytes written:" << written << "vs" << buffer.byteCount();
+ };
+ connect(m_audioInput, &QFFmpegAudioInput::newAudioBuffer, m_audioSink.get(), writeToDevice);
+ } else {
+ qWarning() << "Failed to start audiosink push mode";
+ }
+
+ updateVolume();
+}
+
+void QFFmpegMediaCaptureSession::updateVolume()
+{
+ if (m_audioSink)
+ m_audioSink->setVolume(m_audioOutput->muted ? 0.f : m_audioOutput->volume);
+}
+
+QPlatformAudioInput *QFFmpegMediaCaptureSession::audioInput() const
+{
+ return m_audioInput;
+}
+
+void QFFmpegMediaCaptureSession::setVideoPreview(QVideoSink *sink)
+{
+ if (std::exchange(m_videoSink, sink) == sink)
+ return;
+
+ updateVideoFrameConnection();
+}
+
+void QFFmpegMediaCaptureSession::setAudioOutput(QPlatformAudioOutput *output)
+{
+ qCDebug(qLcFFmpegMediaCaptureSession)
+ << "set audio output:" << (output ? output->device.description() : "null");
+
+ if (m_audioOutput == output)
+ return;
+
+ if (m_audioOutput)
+ m_audioOutput->q->disconnect(this);
+
+ m_audioOutput = output;
+ if (m_audioOutput) {
+ // TODO: implement the signals in QPlatformAudioOutput and connect to them, QTBUG-112294
+ connect(m_audioOutput->q, &QAudioOutput::deviceChanged, this,
+ &QFFmpegMediaCaptureSession::updateAudioSink);
+ connect(m_audioOutput->q, &QAudioOutput::volumeChanged, this,
+ &QFFmpegMediaCaptureSession::updateVolume);
+ connect(m_audioOutput->q, &QAudioOutput::mutedChanged, this,
+ &QFFmpegMediaCaptureSession::updateVolume);
+ }
+
+ updateAudioSink();
+}
+
+void QFFmpegMediaCaptureSession::updateVideoFrameConnection()
+{
+ disconnect(m_videoFrameConnection);
+
+ if (m_primaryActiveVideoSource && m_videoSink) {
+ // deliver frames directly to video sink;
+ // AutoConnection type might be a pessimization due to an extra queuing
+ // TODO: investigate and integrate direct connection
+ m_videoFrameConnection =
+ connect(m_primaryActiveVideoSource, &QPlatformVideoSource::newVideoFrame,
+ m_videoSink, &QVideoSink::setVideoFrame);
+ }
+}
+
+void QFFmpegMediaCaptureSession::updatePrimaryActiveVideoSource()
+{
+ auto sources = activeVideoSources();
+ auto source = sources.empty() ? nullptr : sources.front();
+ if (std::exchange(m_primaryActiveVideoSource, source) != source)
+ emit primaryActiveVideoSourceChanged();
+}
+
+template<typename VideoSource>
+bool QFFmpegMediaCaptureSession::setVideoSource(QPointer<VideoSource> &source,
+ VideoSource *newSource)
+{
+ if (source == newSource)
+ return false;
+
+ if (auto prevSource = std::exchange(source, newSource)) {
+ prevSource->setCaptureSession(nullptr);
+ prevSource->disconnect(this);
+ }
+
+ if (source) {
+ source->setCaptureSession(this);
+ connect(source, &QPlatformVideoSource::activeChanged, this,
+ &QFFmpegMediaCaptureSession::updatePrimaryActiveVideoSource);
+ connect(source, &QObject::destroyed, this,
+ &QFFmpegMediaCaptureSession::updatePrimaryActiveVideoSource, Qt::QueuedConnection);
+ }
+
+ updatePrimaryActiveVideoSource();
+
+ return true;
+}
+
+QPlatformVideoSource *QFFmpegMediaCaptureSession::primaryActiveVideoSource()
+{
+ return m_primaryActiveVideoSource;
+}
+
+std::vector<QPlatformAudioBufferInputBase *> QFFmpegMediaCaptureSession::activeAudioInputs() const
+{
+ std::vector<QPlatformAudioBufferInputBase *> result;
+ if (m_audioInput)
+ result.push_back(m_audioInput);
+
+ if (m_audioBufferInput)
+ result.push_back(m_audioBufferInput);
+
+ return result;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegmediacapturesession_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediacapturesession_p.h b/src/plugins/multimedia/ffmpeg/qffmpegmediacapturesession_p.h
new file mode 100644
index 000000000..25340dad5
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediacapturesession_p.h
@@ -0,0 +1,112 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGMEDIACAPTURESESSION_H
+#define QFFMPEGMEDIACAPTURESESSION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediacapture_p.h>
+#include <private/qplatformmediaintegration_p.h>
+#include "qpointer.h"
+#include "qiodevice.h"
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegMediaRecorder;
+class QFFmpegImageCapture;
+class QVideoFrame;
+class QAudioSink;
+class QFFmpegAudioInput;
+class QAudioBuffer;
+class QPlatformVideoSource;
+class QPlatformAudioBufferInput;
+class QPlatformAudioBufferInputBase;
+
+class QFFmpegMediaCaptureSession : public QPlatformMediaCaptureSession
+{
+ Q_OBJECT
+
+public:
+ using VideoSources = std::vector<QPointer<QPlatformVideoSource>>;
+
+ QFFmpegMediaCaptureSession();
+ ~QFFmpegMediaCaptureSession() override;
+
+ QPlatformCamera *camera() override;
+ void setCamera(QPlatformCamera *camera) override;
+
+ QPlatformSurfaceCapture *screenCapture() override;
+ void setScreenCapture(QPlatformSurfaceCapture *) override;
+
+ QPlatformSurfaceCapture *windowCapture() override;
+ void setWindowCapture(QPlatformSurfaceCapture *) override;
+
+ QPlatformVideoFrameInput *videoFrameInput() override;
+ void setVideoFrameInput(QPlatformVideoFrameInput *) override;
+
+ QPlatformImageCapture *imageCapture() override;
+ void setImageCapture(QPlatformImageCapture *imageCapture) override;
+
+ QPlatformMediaRecorder *mediaRecorder() override;
+ void setMediaRecorder(QPlatformMediaRecorder *recorder) override;
+
+ void setAudioInput(QPlatformAudioInput *input) override;
+ QPlatformAudioInput *audioInput() const;
+
+ void setAudioBufferInput(QPlatformAudioBufferInput *input) override;
+
+ void setVideoPreview(QVideoSink *sink) override;
+ void setAudioOutput(QPlatformAudioOutput *output) override;
+
+ QPlatformVideoSource *primaryActiveVideoSource();
+
+ // it might be moved to the base class, but it needs QPlatformAudioInput
+ // to be QPlatformAudioBufferInputBase, which might not make sense
+ std::vector<QPlatformAudioBufferInputBase *> activeAudioInputs() const;
+
+private Q_SLOTS:
+ void updateAudioSink();
+ void updateVolume();
+ void updateVideoFrameConnection();
+ void updatePrimaryActiveVideoSource();
+
+Q_SIGNALS:
+ void primaryActiveVideoSourceChanged();
+
+private:
+ template<typename VideoSource>
+ bool setVideoSource(QPointer<VideoSource> &source, VideoSource *newSource);
+
+ QPointer<QPlatformCamera> m_camera;
+ QPointer<QPlatformSurfaceCapture> m_screenCapture;
+ QPointer<QPlatformSurfaceCapture> m_windowCapture;
+ QPointer<QPlatformVideoFrameInput> m_videoFrameInput;
+ QPointer<QPlatformVideoSource> m_primaryActiveVideoSource;
+
+ QPointer<QFFmpegAudioInput> m_audioInput;
+ QPointer<QPlatformAudioBufferInput> m_audioBufferInput;
+
+ QFFmpegImageCapture *m_imageCapture = nullptr;
+ QFFmpegMediaRecorder *m_mediaRecorder = nullptr;
+ QPlatformAudioOutput *m_audioOutput = nullptr;
+ QVideoSink *m_videoSink = nullptr;
+ std::unique_ptr<QAudioSink> m_audioSink;
+ QPointer<QIODevice> m_audioIODevice;
+ qsizetype m_audioBufferSize = 0;
+
+ QMetaObject::Connection m_videoFrameConnection;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGSTREAMERCAPTURESERVICE_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo.cpp b/src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo.cpp
new file mode 100644
index 000000000..6389b4eed
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo.cpp
@@ -0,0 +1,517 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegmediaformatinfo_p.h"
+#include "qaudioformat.h"
+#include "qimagewriter.h"
+
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcMediaFormatInfo, "qt.multimedia.ffmpeg.mediaformatinfo")
+
+static struct {
+ AVCodecID id;
+ QMediaFormat::VideoCodec codec;
+} videoCodecMap [] = {
+ { AV_CODEC_ID_MPEG1VIDEO, QMediaFormat::VideoCodec::MPEG1 },
+ { AV_CODEC_ID_MPEG2VIDEO, QMediaFormat::VideoCodec::MPEG2 },
+ { AV_CODEC_ID_MPEG4, QMediaFormat::VideoCodec::MPEG4 },
+ { AV_CODEC_ID_H264, QMediaFormat::VideoCodec::H264 },
+ { AV_CODEC_ID_HEVC, QMediaFormat::VideoCodec::H265 },
+ { AV_CODEC_ID_VP8, QMediaFormat::VideoCodec::VP8 },
+ { AV_CODEC_ID_VP9, QMediaFormat::VideoCodec::VP9 },
+ { AV_CODEC_ID_AV1, QMediaFormat::VideoCodec::AV1 },
+ { AV_CODEC_ID_THEORA, QMediaFormat::VideoCodec::Theora },
+ { AV_CODEC_ID_WMV3, QMediaFormat::VideoCodec::WMV },
+ { AV_CODEC_ID_MJPEG, QMediaFormat::VideoCodec::MotionJPEG }
+};
+
+static AVCodecID codecId(QMediaFormat::VideoCodec codec)
+{
+ for (const auto &c : videoCodecMap) {
+ if (c.codec == codec)
+ return c.id;
+ }
+ return AV_CODEC_ID_NONE;
+}
+
+static struct {
+ AVCodecID id;
+ QMediaFormat::AudioCodec codec;
+} audioCodecMap [] = {
+ { AV_CODEC_ID_MP3, QMediaFormat::AudioCodec::MP3 },
+ { AV_CODEC_ID_AAC, QMediaFormat::AudioCodec::AAC },
+ { AV_CODEC_ID_AC3, QMediaFormat::AudioCodec::AC3 },
+ { AV_CODEC_ID_EAC3, QMediaFormat::AudioCodec::EAC3 },
+ { AV_CODEC_ID_FLAC, QMediaFormat::AudioCodec::FLAC },
+ { AV_CODEC_ID_TRUEHD, QMediaFormat::AudioCodec::DolbyTrueHD },
+ { AV_CODEC_ID_OPUS, QMediaFormat::AudioCodec::Opus },
+ { AV_CODEC_ID_VORBIS, QMediaFormat::AudioCodec::Vorbis },
+ { AV_CODEC_ID_PCM_S16LE, QMediaFormat::AudioCodec::Wave },
+ { AV_CODEC_ID_WMAPRO, QMediaFormat::AudioCodec::WMA },
+ { AV_CODEC_ID_ALAC, QMediaFormat::AudioCodec::ALAC }
+};
+
+static AVCodecID codecId(QMediaFormat::AudioCodec codec)
+{
+ for (const auto &c : audioCodecMap) {
+ if (c.codec == codec)
+ return c.id;
+ }
+ return AV_CODEC_ID_NONE;
+}
+
+// mimetypes are mostly copied from qmediaformat.cpp. Unfortunately, FFmpeg uses
+// in some cases slightly different mimetypes
+static const struct
+{
+ QMediaFormat::FileFormat fileFormat;
+ const char *mimeType;
+ const char *name; // disambiguate if we have several muxers/demuxers
+} map[QMediaFormat::LastFileFormat + 1] = {
+ { QMediaFormat::WMV, "video/x-ms-asf", "asf" },
+ { QMediaFormat::AVI, "video/x-msvideo", nullptr },
+ { QMediaFormat::Matroska, "video/x-matroska", nullptr },
+ { QMediaFormat::MPEG4, "video/mp4", "mp4" },
+ { QMediaFormat::Ogg, "video/ogg", nullptr },
+ // QuickTime is the same as MP4
+ { QMediaFormat::WebM, "video/webm", "webm" },
+ // Audio Formats
+ // Mpeg4Audio is the same as MP4 without the video codecs
+ { QMediaFormat::AAC, "audio/aac", nullptr },
+ // WMA is the same as WMV
+ { QMediaFormat::FLAC, "audio/x-flac", nullptr },
+ { QMediaFormat::MP3, "audio/mpeg", "mp3" },
+ { QMediaFormat::Wave, "audio/x-wav", nullptr },
+ { QMediaFormat::UnspecifiedFormat, nullptr, nullptr }
+};
+
+template <typename AVFormat>
+static QMediaFormat::FileFormat formatForAVFormat(AVFormat *format)
+{
+
+ if (!format->mime_type || !*format->mime_type)
+ return QMediaFormat::UnspecifiedFormat;
+
+ auto *m = map;
+ while (m->fileFormat != QMediaFormat::UnspecifiedFormat) {
+ if (m->mimeType && !strcmp(m->mimeType, format->mime_type)) {
+ // check if the name matches. This is used to disambiguate where FFmpeg provides
+ // multiple muxers or demuxers
+ if (!m->name || !strcmp(m->name, format->name))
+ return m->fileFormat;
+ }
+ ++m;
+ }
+
+ return QMediaFormat::UnspecifiedFormat;
+}
+
+static const AVOutputFormat *avFormatForFormat(QMediaFormat::FileFormat format)
+{
+ if (format == QMediaFormat::QuickTime || format == QMediaFormat::Mpeg4Audio)
+ format = QMediaFormat::MPEG4;
+ if (format == QMediaFormat::WMA)
+ format = QMediaFormat::WMV;
+
+ auto *m = map;
+ while (m->fileFormat != QMediaFormat::UnspecifiedFormat) {
+ if (m->fileFormat == format)
+ return av_guess_format(m->name, nullptr, m->mimeType);
+ ++m;
+ }
+
+ return nullptr;
+}
+
+
+QFFmpegMediaFormatInfo::QFFmpegMediaFormatInfo()
+{
+ qCDebug(qLcMediaFormatInfo) << ">>>> listing codecs";
+
+ QList<QMediaFormat::AudioCodec> audioEncoders;
+ QList<QMediaFormat::AudioCodec> extraAudioDecoders;
+ QList<QMediaFormat::VideoCodec> videoEncoders;
+ QList<QMediaFormat::VideoCodec> extraVideoDecoders;
+
+ const AVCodecDescriptor *descriptor = nullptr;
+ while ((descriptor = avcodec_descriptor_next(descriptor))) {
+ const bool canEncode = QFFmpeg::findAVEncoder(descriptor->id) != nullptr;
+ const bool canDecode = QFFmpeg::findAVDecoder(descriptor->id) != nullptr;
+ auto videoCodec = videoCodecForAVCodecId(descriptor->id);
+ auto audioCodec = audioCodecForAVCodecId(descriptor->id);
+ if (descriptor->type == AVMEDIA_TYPE_VIDEO && videoCodec != QMediaFormat::VideoCodec::Unspecified) {
+ if (canEncode) {
+ if (!videoEncoders.contains(videoCodec))
+ videoEncoders.append(videoCodec);
+ } else if (canDecode) {
+ if (!extraVideoDecoders.contains(videoCodec))
+ extraVideoDecoders.append(videoCodec);
+ }
+ } else if (descriptor->type == AVMEDIA_TYPE_AUDIO
+ && audioCodec != QMediaFormat::AudioCodec::Unspecified) {
+ if (canEncode) {
+ if (!audioEncoders.contains(audioCodec))
+ audioEncoders.append(audioCodec);
+ } else if (canDecode) {
+ if (!extraAudioDecoders.contains(audioCodec))
+ extraAudioDecoders.append(audioCodec);
+ }
+ }
+ }
+
+ // get demuxers
+// qCDebug(qLcMediaFormatInfo) << ">>>> Muxers";
+ void *opaque = nullptr;
+ const AVOutputFormat *outputFormat = nullptr;
+ while ((outputFormat = av_muxer_iterate(&opaque))) {
+ auto mediaFormat = formatForAVFormat(outputFormat);
+ if (mediaFormat == QMediaFormat::UnspecifiedFormat)
+ continue;
+// qCDebug(qLcMediaFormatInfo) << " mux:" << outputFormat->name << outputFormat->long_name << outputFormat->mime_type << outputFormat->extensions << mediaFormat;
+
+ CodecMap encoder;
+ encoder.format = mediaFormat;
+
+ for (auto codec : audioEncoders) {
+ auto id = codecId(codec);
+ // only add the codec if it can be used with this container
+ if (avformat_query_codec(outputFormat, id, FF_COMPLIANCE_NORMAL) == 1) {
+ // add codec for container
+// qCDebug(qLcMediaFormatInfo) << " " << codec << Qt::hex << av_codec_get_tag(outputFormat->codec_tag, id);
+ encoder.audio.append(codec);
+ }
+ }
+ for (auto codec : videoEncoders) {
+ auto id = codecId(codec);
+ // only add the codec if it can be used with this container
+ if (avformat_query_codec(outputFormat, id, FF_COMPLIANCE_NORMAL) == 1) {
+ // add codec for container
+// qCDebug(qLcMediaFormatInfo) << " " << codec << Qt::hex << av_codec_get_tag(outputFormat->codec_tag, id);
+ encoder.video.append(codec);
+ }
+ }
+
+ // sanity checks and handling special cases
+ if (encoder.audio.isEmpty() && encoder.video.isEmpty())
+ continue;
+ switch (encoder.format) {
+ case QMediaFormat::WMV:
+ // add WMA
+ encoders.append({ QMediaFormat::WMA, encoder.audio, {} });
+ break;
+ case QMediaFormat::MPEG4:
+ // add Mpeg4Audio and QuickTime
+ encoders.append({ QMediaFormat::QuickTime, encoder.audio, encoder.video });
+ encoders.append({ QMediaFormat::Mpeg4Audio, encoder.audio, {} });
+ break;
+ case QMediaFormat::Wave:
+ // FFmpeg allows other encoded formats in WAV containers, but we do not want that
+ if (!encoder.audio.contains(QMediaFormat::AudioCodec::Wave))
+ continue;
+ encoder.audio = { QMediaFormat::AudioCodec::Wave };
+ break;
+ default:
+ break;
+ }
+ encoders.append(encoder);
+ }
+
+ // FFmpeg doesn't allow querying supported codecs for decoders
+ // we take a simple approximation stating that we can decode what we
+ // can encode. That's a safe subset.
+ decoders = encoders;
+
+#ifdef Q_OS_WINDOWS
+ // MediaFoundation HVEC encoder fails when processing frames
+ for (auto &encoder : encoders) {
+ auto h265index = encoder.video.indexOf(QMediaFormat::VideoCodec::H265);
+ if (h265index >= 0)
+ encoder.video.removeAt(h265index);
+ }
+#endif
+
+// qCDebug(qLcMediaFormatInfo) << "extraDecoders:" << extraAudioDecoders << extraVideoDecoders;
+ // FFmpeg can currently only decode WMA and WMV, not encode
+ if (extraAudioDecoders.contains(QMediaFormat::AudioCodec::WMA)) {
+ decoders[QMediaFormat::WMA].audio.append(QMediaFormat::AudioCodec::WMA);
+ decoders[QMediaFormat::WMV].audio.append(QMediaFormat::AudioCodec::WMA);
+ }
+ if (extraVideoDecoders.contains(QMediaFormat::VideoCodec::WMV)) {
+ decoders[QMediaFormat::WMV].video.append(QMediaFormat::VideoCodec::WMV);
+ }
+
+ // Add image formats we support. We currently simply use Qt's built-in image write
+ // to save images. That doesn't give us HDR support or support for larger bit depths,
+ // but most cameras can currently not generate those anyway.
+ const auto imgFormats = QImageWriter::supportedImageFormats();
+ for (const auto &f : imgFormats) {
+ if (f == "png")
+ imageFormats.append(QImageCapture::PNG);
+ else if (f == "jpeg")
+ imageFormats.append(QImageCapture::JPEG);
+ else if (f == "tiff")
+ imageFormats.append(QImageCapture::Tiff);
+ else if (f == "webp")
+ imageFormats.append(QImageCapture::WebP);
+ }
+
+}
+
+QFFmpegMediaFormatInfo::~QFFmpegMediaFormatInfo() = default;
+
+QMediaFormat::AudioCodec QFFmpegMediaFormatInfo::audioCodecForAVCodecId(AVCodecID id)
+{
+ for (const auto &c : audioCodecMap) {
+ if (c.id == id)
+ return c.codec;
+ }
+ return QMediaFormat::AudioCodec::Unspecified;
+}
+
+QMediaFormat::VideoCodec QFFmpegMediaFormatInfo::videoCodecForAVCodecId(AVCodecID id)
+{
+ for (const auto &c : videoCodecMap) {
+ if (c.id == id)
+ return c.codec;
+ }
+ return QMediaFormat::VideoCodec::Unspecified;
+}
+
+QMediaFormat::FileFormat
+QFFmpegMediaFormatInfo::fileFormatForAVInputFormat(const AVInputFormat *format)
+{
+ // Seems like FFmpeg uses different names for muxers and demuxers of the same format.
+ // that makes it somewhat cumbersome to detect things correctly.
+ // The input formats have a comma separated list of short names. We check the first one of those
+ // as the docs specify that you only append to the list
+ static const struct
+ {
+ QMediaFormat::FileFormat fileFormat;
+ const char *name;
+ } map[QMediaFormat::LastFileFormat + 1] = {
+ { QMediaFormat::WMV, "asf" },
+ { QMediaFormat::AVI, "avi" },
+ { QMediaFormat::Matroska, "matroska" },
+ { QMediaFormat::MPEG4, "mov" },
+ { QMediaFormat::Ogg, "ogg" },
+ { QMediaFormat::WebM, "webm" },
+ // Audio Formats
+ // Mpeg4Audio is the same as MP4 without the video codecs
+ { QMediaFormat::AAC, "aac"},
+ // WMA is the same as WMV
+ { QMediaFormat::FLAC, "flac" },
+ { QMediaFormat::MP3, "mp3" },
+ { QMediaFormat::Wave, "wav" },
+ { QMediaFormat::UnspecifiedFormat, nullptr }
+ };
+
+ if (!format->name)
+ return QMediaFormat::UnspecifiedFormat;
+
+ auto *m = map;
+ while (m->fileFormat != QMediaFormat::UnspecifiedFormat) {
+ if (!strncmp(m->name, format->name, strlen(m->name)))
+ return m->fileFormat;
+ ++m;
+ }
+
+ return QMediaFormat::UnspecifiedFormat;
+}
+
+const AVOutputFormat *
+QFFmpegMediaFormatInfo::outputFormatForFileFormat(QMediaFormat::FileFormat format)
+{
+ return avFormatForFormat(format);
+}
+
+AVCodecID QFFmpegMediaFormatInfo::codecIdForVideoCodec(QMediaFormat::VideoCodec codec)
+{
+ return codecId(codec);
+}
+
+AVCodecID QFFmpegMediaFormatInfo::codecIdForAudioCodec(QMediaFormat::AudioCodec codec)
+{
+ return codecId(codec);
+}
+
+QAudioFormat::SampleFormat QFFmpegMediaFormatInfo::sampleFormat(AVSampleFormat format)
+{
+ switch (format) {
+ case AV_SAMPLE_FMT_NONE:
+ default:
+ return QAudioFormat::Unknown;
+ case AV_SAMPLE_FMT_U8: ///< unsigned 8 bits
+ case AV_SAMPLE_FMT_U8P: ///< unsigned 8 bits: planar
+ return QAudioFormat::UInt8;
+ case AV_SAMPLE_FMT_S16: ///< signed 16 bits
+ case AV_SAMPLE_FMT_S16P: ///< signed 16 bits: planar
+ return QAudioFormat::Int16;
+ case AV_SAMPLE_FMT_S32: ///< signed 32 bits
+ case AV_SAMPLE_FMT_S32P: ///< signed 32 bits: planar
+ return QAudioFormat::Int32;
+ case AV_SAMPLE_FMT_FLT: ///< float
+ case AV_SAMPLE_FMT_FLTP: ///< float: planar
+ return QAudioFormat::Float;
+ case AV_SAMPLE_FMT_DBL: ///< double
+ case AV_SAMPLE_FMT_DBLP: ///< double: planar
+ case AV_SAMPLE_FMT_S64: ///< signed 64 bits
+ case AV_SAMPLE_FMT_S64P: ///< signed 64 bits, planar
+ // let's use float
+ return QAudioFormat::Float;
+ }
+}
+
+AVSampleFormat QFFmpegMediaFormatInfo::avSampleFormat(QAudioFormat::SampleFormat format)
+{
+ switch (format) {
+ case QAudioFormat::UInt8:
+ return AV_SAMPLE_FMT_U8;
+ case QAudioFormat::Int16:
+ return AV_SAMPLE_FMT_S16;
+ case QAudioFormat::Int32:
+ return AV_SAMPLE_FMT_S32;
+ case QAudioFormat::Float:
+ return AV_SAMPLE_FMT_FLT;
+ default:
+ return AV_SAMPLE_FMT_NONE;
+ }
+}
+
+int64_t QFFmpegMediaFormatInfo::avChannelLayout(QAudioFormat::ChannelConfig channelConfig)
+{
+ int64_t avChannelLayout = 0;
+ if (channelConfig & (1 << QAudioFormat::FrontLeft))
+ avChannelLayout |= AV_CH_FRONT_LEFT;
+ if (channelConfig & (1 << QAudioFormat::FrontRight))
+ avChannelLayout |= AV_CH_FRONT_RIGHT;
+ if (channelConfig & (1 << QAudioFormat::FrontCenter))
+ avChannelLayout |= AV_CH_FRONT_CENTER;
+ if (channelConfig & (1 << QAudioFormat::LFE))
+ avChannelLayout |= AV_CH_LOW_FREQUENCY;
+ if (channelConfig & (1 << QAudioFormat::BackLeft))
+ avChannelLayout |= AV_CH_BACK_LEFT;
+ if (channelConfig & (1 << QAudioFormat::BackRight))
+ avChannelLayout |= AV_CH_BACK_RIGHT;
+ if (channelConfig & (1 << QAudioFormat::FrontLeftOfCenter))
+ avChannelLayout |= AV_CH_FRONT_LEFT_OF_CENTER;
+ if (channelConfig & (1 << QAudioFormat::FrontRightOfCenter))
+ avChannelLayout |= AV_CH_FRONT_RIGHT_OF_CENTER;
+ if (channelConfig & (1 << QAudioFormat::BackCenter))
+ avChannelLayout |= AV_CH_BACK_CENTER;
+ if (channelConfig & (1 << QAudioFormat::LFE2))
+ avChannelLayout |= AV_CH_LOW_FREQUENCY_2;
+ if (channelConfig & (1 << QAudioFormat::SideLeft))
+ avChannelLayout |= AV_CH_SIDE_LEFT;
+ if (channelConfig & (1 << QAudioFormat::SideRight))
+ avChannelLayout |= AV_CH_SIDE_RIGHT;
+ if (channelConfig & (1 << QAudioFormat::TopFrontLeft))
+ avChannelLayout |= AV_CH_TOP_FRONT_LEFT;
+ if (channelConfig & (1 << QAudioFormat::TopFrontRight))
+ avChannelLayout |= AV_CH_TOP_FRONT_RIGHT;
+ if (channelConfig & (1 << QAudioFormat::TopFrontCenter))
+ avChannelLayout |= AV_CH_TOP_FRONT_CENTER;
+ if (channelConfig & (1 << QAudioFormat::TopCenter))
+ avChannelLayout |= AV_CH_TOP_CENTER;
+ if (channelConfig & (1 << QAudioFormat::TopBackLeft))
+ avChannelLayout |= AV_CH_TOP_BACK_LEFT;
+ if (channelConfig & (1 << QAudioFormat::TopBackRight))
+ avChannelLayout |= AV_CH_TOP_BACK_RIGHT;
+ if (channelConfig & (1 << QAudioFormat::TopBackCenter))
+ avChannelLayout |= AV_CH_TOP_BACK_CENTER;
+ // The defines used below got added together for FFmpeg 4.4
+#ifdef AV_CH_TOP_SIDE_LEFT
+ if (channelConfig & (1 << QAudioFormat::TopSideLeft))
+ avChannelLayout |= AV_CH_TOP_SIDE_LEFT;
+ if (channelConfig & (1 << QAudioFormat::TopSideRight))
+ avChannelLayout |= AV_CH_TOP_SIDE_RIGHT;
+ if (channelConfig & (1 << QAudioFormat::BottomFrontCenter))
+ avChannelLayout |= AV_CH_BOTTOM_FRONT_CENTER;
+ if (channelConfig & (1 << QAudioFormat::BottomFrontLeft))
+ avChannelLayout |= AV_CH_BOTTOM_FRONT_LEFT;
+ if (channelConfig & (1 << QAudioFormat::BottomFrontRight))
+ avChannelLayout |= AV_CH_BOTTOM_FRONT_RIGHT;
+#endif
+ return avChannelLayout;
+}
+
+QAudioFormat::ChannelConfig QFFmpegMediaFormatInfo::channelConfigForAVLayout(int64_t avChannelLayout)
+{
+ quint32 channelConfig = 0;
+ if (avChannelLayout & AV_CH_FRONT_LEFT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::FrontLeft);
+ if (avChannelLayout & AV_CH_FRONT_RIGHT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::FrontRight);
+ if (avChannelLayout & AV_CH_FRONT_CENTER)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::FrontCenter);
+ if (avChannelLayout & AV_CH_LOW_FREQUENCY)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::LFE);
+ if (avChannelLayout & AV_CH_BACK_LEFT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::BackLeft);
+ if (avChannelLayout & AV_CH_BACK_RIGHT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::BackRight);
+ if (avChannelLayout & AV_CH_FRONT_LEFT_OF_CENTER)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::FrontLeftOfCenter);
+ if (avChannelLayout & AV_CH_FRONT_RIGHT_OF_CENTER)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::FrontRightOfCenter);
+ if (avChannelLayout & AV_CH_BACK_CENTER)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::BackCenter);
+ if (avChannelLayout & AV_CH_LOW_FREQUENCY_2)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::LFE2);
+ if (avChannelLayout & AV_CH_SIDE_LEFT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::SideLeft);
+ if (avChannelLayout & AV_CH_SIDE_RIGHT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::SideRight);
+ if (avChannelLayout & AV_CH_TOP_FRONT_LEFT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::TopFrontLeft);
+ if (avChannelLayout & AV_CH_TOP_FRONT_RIGHT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::TopFrontRight);
+ if (avChannelLayout & AV_CH_TOP_FRONT_CENTER)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::TopFrontCenter);
+ if (avChannelLayout & AV_CH_TOP_CENTER)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::TopCenter);
+ if (avChannelLayout & AV_CH_TOP_BACK_LEFT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::TopBackLeft);
+ if (avChannelLayout & AV_CH_TOP_BACK_RIGHT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::TopBackRight);
+ if (avChannelLayout & AV_CH_TOP_BACK_CENTER)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::TopBackCenter);
+ // The defines used below got added together for FFmpeg 4.4
+#ifdef AV_CH_TOP_SIDE_LEFT
+ if (avChannelLayout & AV_CH_TOP_SIDE_LEFT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::TopSideLeft);
+ if (avChannelLayout & AV_CH_TOP_SIDE_RIGHT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::TopSideRight);
+ if (avChannelLayout & AV_CH_BOTTOM_FRONT_CENTER)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::BottomFrontCenter);
+ if (avChannelLayout & AV_CH_BOTTOM_FRONT_LEFT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::BottomFrontLeft);
+ if (avChannelLayout & AV_CH_BOTTOM_FRONT_RIGHT)
+ channelConfig |= QAudioFormat::channelConfig(QAudioFormat::BottomFrontRight);
+#endif
+ return QAudioFormat::ChannelConfig(channelConfig);
+}
+
+QAudioFormat QFFmpegMediaFormatInfo::audioFormatFromCodecParameters(AVCodecParameters *codecpar)
+{
+ QAudioFormat format;
+ format.setSampleFormat(sampleFormat(AVSampleFormat(codecpar->format)));
+ format.setSampleRate(codecpar->sample_rate);
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+ uint64_t channelLayout = codecpar->channel_layout;
+ if (!channelLayout)
+ channelLayout = avChannelLayout(QAudioFormat::defaultChannelConfigForChannelCount(codecpar->channels));
+#else
+ uint64_t channelLayout = 0;
+ if (codecpar->ch_layout.order == AV_CHANNEL_ORDER_NATIVE)
+ channelLayout = codecpar->ch_layout.u.mask;
+ else
+ channelLayout = avChannelLayout(QAudioFormat::defaultChannelConfigForChannelCount(codecpar->ch_layout.nb_channels));
+#endif
+ format.setChannelConfig(channelConfigForAVLayout(channelLayout));
+ return format;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo_p.h b/src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo_p.h
new file mode 100644
index 000000000..52fcf6f72
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediaformatinfo_p.h
@@ -0,0 +1,52 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFmpegMediaFormatInfo_H
+#define QFFmpegMediaFormatInfo_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaformatinfo_p.h>
+#include <qhash.h>
+#include <qlist.h>
+#include <qaudioformat.h>
+#include "qffmpeg_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegMediaFormatInfo : public QPlatformMediaFormatInfo
+{
+public:
+ QFFmpegMediaFormatInfo();
+ ~QFFmpegMediaFormatInfo();
+
+ static QMediaFormat::VideoCodec videoCodecForAVCodecId(AVCodecID id);
+ static QMediaFormat::AudioCodec audioCodecForAVCodecId(AVCodecID id);
+ static QMediaFormat::FileFormat fileFormatForAVInputFormat(const AVInputFormat *format);
+
+ static const AVOutputFormat *outputFormatForFileFormat(QMediaFormat::FileFormat format);
+
+ static AVCodecID codecIdForVideoCodec(QMediaFormat::VideoCodec codec);
+ static AVCodecID codecIdForAudioCodec(QMediaFormat::AudioCodec codec);
+
+ static QAudioFormat::SampleFormat sampleFormat(AVSampleFormat format);
+ static AVSampleFormat avSampleFormat(QAudioFormat::SampleFormat format);
+
+ static int64_t avChannelLayout(QAudioFormat::ChannelConfig channelConfig);
+ static QAudioFormat::ChannelConfig channelConfigForAVLayout(int64_t avChannelLayout);
+
+ static QAudioFormat audioFormatFromCodecParameters(AVCodecParameters *codecPar);
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediaintegration.cpp b/src/plugins/multimedia/ffmpeg/qffmpegmediaintegration.cpp
new file mode 100644
index 000000000..ba1fff3b3
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediaintegration.cpp
@@ -0,0 +1,375 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtMultimedia/private/qplatformmediaplugin_p.h>
+#include <qcameradevice.h>
+#include "qffmpegmediaintegration_p.h"
+#include "qffmpegmediaformatinfo_p.h"
+#include "qffmpegmediaplayer_p.h"
+#include "qffmpegvideosink_p.h"
+#include "qffmpegmediacapturesession_p.h"
+#include "qffmpegmediarecorder_p.h"
+#include "qffmpegimagecapture_p.h"
+#include "qffmpegaudioinput_p.h"
+#include "qffmpegaudiodecoder_p.h"
+#include "qffmpegresampler_p.h"
+#include "qgrabwindowsurfacecapture_p.h"
+#include "qffmpegconverter_p.h"
+
+#ifdef Q_OS_MACOS
+#include <VideoToolbox/VideoToolbox.h>
+
+#include "qcgcapturablewindows_p.h"
+#include "qcgwindowcapture_p.h"
+#include "qavfscreencapture_p.h"
+#endif
+
+#ifdef Q_OS_DARWIN
+#include "qavfcamera_p.h"
+
+#elif defined(Q_OS_WINDOWS)
+#include "qwindowscamera_p.h"
+#include "qwindowsvideodevices_p.h"
+#include "qffmpegscreencapture_dxgi_p.h"
+#include "qwincapturablewindows_p.h"
+#include "qgdiwindowcapture_p.h"
+#endif
+
+#ifdef Q_OS_ANDROID
+# include "jni.h"
+# include "qandroidvideodevices_p.h"
+# include "qandroidcamera_p.h"
+# include "qandroidimagecapture_p.h"
+extern "C" {
+# include <libavutil/log.h>
+# include <libavcodec/jni.h>
+}
+#endif
+
+#if QT_CONFIG(linux_v4l)
+#include "qv4l2camera_p.h"
+#include "qv4l2cameradevices_p.h"
+#endif
+
+#if QT_CONFIG(cpp_winrt)
+#include "qffmpegwindowcapture_uwp_p.h"
+#endif
+
+#if QT_CONFIG(xlib)
+#include "qx11surfacecapture_p.h"
+#include "qx11capturablewindows_p.h"
+#endif
+
+#if QT_CONFIG(eglfs)
+#include "qeglfsscreencapture_p.h"
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegMediaPlugin : public QPlatformMediaPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QPlatformMediaPlugin_iid FILE "ffmpeg.json")
+
+public:
+ QFFmpegMediaPlugin()
+ : QPlatformMediaPlugin()
+ {}
+
+ QPlatformMediaIntegration* create(const QString &name) override
+ {
+ if (name == u"ffmpeg")
+ return new QFFmpegMediaIntegration;
+ return nullptr;
+ }
+};
+
+bool thread_local FFmpegLogsEnabledInThread = true;
+static bool UseCustomFFmpegLogger = false;
+
+static void qffmpegLogCallback(void *ptr, int level, const char *fmt, va_list vl)
+{
+ if (!FFmpegLogsEnabledInThread)
+ return;
+
+ if (!UseCustomFFmpegLogger)
+ return av_log_default_callback(ptr, level, fmt, vl);
+
+ // filter logs above the chosen level and AV_LOG_QUIET (negative level)
+ if (level < 0 || level > av_log_get_level())
+ return;
+
+ QString message = QStringLiteral("FFmpeg log: %1").arg(QString::vasprintf(fmt, vl));
+ if (message.endsWith("\n"))
+ message.removeLast();
+
+ if (level == AV_LOG_DEBUG || level == AV_LOG_TRACE)
+ qDebug() << message;
+ else if (level == AV_LOG_VERBOSE || level == AV_LOG_INFO)
+ qInfo() << message;
+ else if (level == AV_LOG_WARNING)
+ qWarning() << message;
+ else if (level == AV_LOG_ERROR || level == AV_LOG_FATAL || level == AV_LOG_PANIC)
+ qCritical() << message;
+}
+
+static void setupFFmpegLogger()
+{
+ if (qEnvironmentVariableIsSet("QT_FFMPEG_DEBUG")) {
+ av_log_set_level(AV_LOG_DEBUG);
+ UseCustomFFmpegLogger = true;
+ }
+
+ av_log_set_callback(&qffmpegLogCallback);
+}
+
+static QPlatformSurfaceCapture *createScreenCaptureByBackend(QString backend)
+{
+ if (backend == u"grabwindow")
+ return new QGrabWindowSurfaceCapture(QPlatformSurfaceCapture::ScreenSource{});
+
+#if QT_CONFIG(eglfs)
+ if (backend == u"eglfs")
+ return new QEglfsScreenCapture;
+#endif
+
+#if QT_CONFIG(xlib)
+ if (backend == u"x11")
+ return new QX11SurfaceCapture(QPlatformSurfaceCapture::ScreenSource{});
+#elif defined(Q_OS_WINDOWS)
+ if (backend == u"dxgi")
+ return new QFFmpegScreenCaptureDxgi;
+#elif defined(Q_OS_MACOS)
+ if (backend == u"avf")
+ return new QAVFScreenCapture;
+#endif
+ return nullptr;
+}
+
+static QPlatformSurfaceCapture *createWindowCaptureByBackend(QString backend)
+{
+ if (backend == u"grabwindow")
+ return new QGrabWindowSurfaceCapture(QPlatformSurfaceCapture::WindowSource{});
+
+#if QT_CONFIG(xlib)
+ if (backend == u"x11")
+ return new QX11SurfaceCapture(QPlatformSurfaceCapture::WindowSource{});
+#elif defined(Q_OS_WINDOWS)
+ if (backend == u"gdi")
+ return new QGdiWindowCapture;
+#if QT_CONFIG(cpp_winrt)
+ if (backend == u"uwp")
+ return new QFFmpegWindowCaptureUwp;
+#endif
+#elif defined(Q_OS_MACOS)
+ if (backend == u"cg")
+ return new QCGWindowCapture;
+#endif
+ return nullptr;
+}
+
+QFFmpegMediaIntegration::QFFmpegMediaIntegration()
+ : QPlatformMediaIntegration(QLatin1String("ffmpeg"))
+{
+ setupFFmpegLogger();
+
+#ifndef QT_NO_DEBUG
+ qDebug() << "Available HW decoding frameworks:";
+ for (auto type : QFFmpeg::HWAccel::decodingDeviceTypes())
+ qDebug() << " " << av_hwdevice_get_type_name(type);
+
+ qDebug() << "Available HW encoding frameworks:";
+ for (auto type : QFFmpeg::HWAccel::encodingDeviceTypes())
+ qDebug() << " " << av_hwdevice_get_type_name(type);
+#endif
+}
+
+QMaybe<QPlatformAudioDecoder *> QFFmpegMediaIntegration::createAudioDecoder(QAudioDecoder *decoder)
+{
+ return new QFFmpegAudioDecoder(decoder);
+}
+
+QMaybe<std::unique_ptr<QPlatformAudioResampler>>
+QFFmpegMediaIntegration::createAudioResampler(const QAudioFormat &inputFormat,
+ const QAudioFormat &outputFormat)
+{
+ return { std::make_unique<QFFmpegResampler>(inputFormat, outputFormat) };
+}
+
+QMaybe<QPlatformMediaCaptureSession *> QFFmpegMediaIntegration::createCaptureSession()
+{
+ return new QFFmpegMediaCaptureSession();
+}
+
+QMaybe<QPlatformMediaPlayer *> QFFmpegMediaIntegration::createPlayer(QMediaPlayer *player)
+{
+ return new QFFmpegMediaPlayer(player);
+}
+
+QMaybe<QPlatformCamera *> QFFmpegMediaIntegration::createCamera(QCamera *camera)
+{
+#ifdef Q_OS_DARWIN
+ return new QAVFCamera(camera);
+#elif defined(Q_OS_ANDROID)
+ return new QAndroidCamera(camera);
+#elif QT_CONFIG(linux_v4l)
+ return new QV4L2Camera(camera);
+#elif defined(Q_OS_WINDOWS)
+ return new QWindowsCamera(camera);
+#else
+ Q_UNUSED(camera);
+ return nullptr;//new QFFmpegCamera(camera);
+#endif
+}
+
+QPlatformSurfaceCapture *QFFmpegMediaIntegration::createScreenCapture(QScreenCapture *)
+{
+ static const QString screenCaptureBackend = qgetenv("QT_SCREEN_CAPTURE_BACKEND").toLower();
+
+ if (!screenCaptureBackend.isEmpty()) {
+ if (auto screenCapture = createScreenCaptureByBackend(screenCaptureBackend))
+ return screenCapture;
+
+ qWarning() << "Not supported QT_SCREEN_CAPTURE_BACKEND:" << screenCaptureBackend;
+ }
+
+#if QT_CONFIG(xlib)
+ if (QX11SurfaceCapture::isSupported())
+ return new QX11SurfaceCapture(QPlatformSurfaceCapture::ScreenSource{});
+#endif
+
+#if QT_CONFIG(eglfs)
+ if (QEglfsScreenCapture::isSupported())
+ return new QEglfsScreenCapture;
+#endif
+
+#if defined(Q_OS_WINDOWS)
+ return new QFFmpegScreenCaptureDxgi;
+#elif defined(Q_OS_MACOS) // TODO: probably use it for iOS as well
+ return new QAVFScreenCapture;
+#else
+ return new QGrabWindowSurfaceCapture(QPlatformSurfaceCapture::ScreenSource{});
+#endif
+}
+
+QPlatformSurfaceCapture *QFFmpegMediaIntegration::createWindowCapture(QWindowCapture *)
+{
+ static const QString windowCaptureBackend = qgetenv("QT_WINDOW_CAPTURE_BACKEND").toLower();
+
+ if (!windowCaptureBackend.isEmpty()) {
+ if (auto windowCapture = createWindowCaptureByBackend(windowCaptureBackend))
+ return windowCapture;
+
+ qWarning() << "Not supported QT_WINDOW_CAPTURE_BACKEND:" << windowCaptureBackend;
+ }
+
+#if QT_CONFIG(xlib)
+ if (QX11SurfaceCapture::isSupported())
+ return new QX11SurfaceCapture(QPlatformSurfaceCapture::WindowSource{});
+#endif
+
+#if defined(Q_OS_WINDOWS)
+# if QT_CONFIG(cpp_winrt)
+ if (QFFmpegWindowCaptureUwp::isSupported())
+ return new QFFmpegWindowCaptureUwp;
+# endif
+
+ return new QGdiWindowCapture;
+#elif defined(Q_OS_MACOS) // TODO: probably use it for iOS as well
+ return new QCGWindowCapture;
+#else
+ return new QGrabWindowSurfaceCapture(QPlatformSurfaceCapture::WindowSource{});
+#endif
+}
+
+QMaybe<QPlatformMediaRecorder *> QFFmpegMediaIntegration::createRecorder(QMediaRecorder *recorder)
+{
+ return new QFFmpegMediaRecorder(recorder);
+}
+
+QMaybe<QPlatformImageCapture *> QFFmpegMediaIntegration::createImageCapture(QImageCapture *imageCapture)
+{
+#if defined(Q_OS_ANDROID)
+ return new QAndroidImageCapture(imageCapture);
+#else
+ return new QFFmpegImageCapture(imageCapture);
+#endif
+}
+
+QMaybe<QPlatformVideoSink *> QFFmpegMediaIntegration::createVideoSink(QVideoSink *sink)
+{
+ return new QFFmpegVideoSink(sink);
+}
+
+QMaybe<QPlatformAudioInput *> QFFmpegMediaIntegration::createAudioInput(QAudioInput *input)
+{
+ return new QFFmpegAudioInput(input);
+}
+
+QVideoFrame QFFmpegMediaIntegration::convertVideoFrame(QVideoFrame &srcFrame,
+ const QVideoFrameFormat &destFormat)
+{
+ return convertFrame(srcFrame, destFormat);
+}
+
+QPlatformMediaFormatInfo *QFFmpegMediaIntegration::createFormatInfo()
+{
+ return new QFFmpegMediaFormatInfo;
+}
+
+QPlatformVideoDevices *QFFmpegMediaIntegration::createVideoDevices()
+{
+#if defined(Q_OS_ANDROID)
+ return new QAndroidVideoDevices(this);
+#elif QT_CONFIG(linux_v4l)
+ return new QV4L2CameraDevices(this);
+#elif defined Q_OS_DARWIN
+ return new QAVFVideoDevices(this);
+#elif defined(Q_OS_WINDOWS)
+ return new QWindowsVideoDevices(this);
+#else
+ return nullptr;
+#endif
+}
+
+QPlatformCapturableWindows *QFFmpegMediaIntegration::createCapturableWindows()
+{
+#if QT_CONFIG(xlib)
+ if (QX11SurfaceCapture::isSupported())
+ return new QX11CapturableWindows;
+#elif defined Q_OS_MACOS
+ return new QCGCapturableWindows;
+#elif defined(Q_OS_WINDOWS)
+ return new QWinCapturableWindows;
+#endif
+ return nullptr;
+}
+
+#ifdef Q_OS_ANDROID
+
+Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
+{
+ static bool initialized = false;
+ if (initialized)
+ return JNI_VERSION_1_6;
+ initialized = true;
+
+ QT_USE_NAMESPACE
+ void *environment;
+ if (vm->GetEnv(&environment, JNI_VERSION_1_6))
+ return JNI_ERR;
+
+ // setting our javavm into ffmpeg.
+ if (av_jni_set_java_vm(vm, nullptr))
+ return JNI_ERR;
+
+ if (!QAndroidCamera::registerNativeMethods())
+ return JNI_ERR;
+
+ return JNI_VERSION_1_6;
+}
+#endif
+
+QT_END_NAMESPACE
+
+#include "qffmpegmediaintegration.moc"
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediaintegration_p.h b/src/plugins/multimedia/ffmpeg/qffmpegmediaintegration_p.h
new file mode 100644
index 000000000..473a5f044
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediaintegration_p.h
@@ -0,0 +1,57 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERINTEGRATION_H
+#define QGSTREAMERINTEGRATION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegMediaFormatInfo;
+
+class QFFmpegMediaIntegration : public QPlatformMediaIntegration
+{
+public:
+ QFFmpegMediaIntegration();
+
+ QMaybe<QPlatformAudioDecoder *> createAudioDecoder(QAudioDecoder *decoder) override;
+ QMaybe<std::unique_ptr<QPlatformAudioResampler>> createAudioResampler(const QAudioFormat &inputFormat, const QAudioFormat &outputFormat) override;
+ QMaybe<QPlatformMediaCaptureSession *> createCaptureSession() override;
+ QMaybe<QPlatformMediaPlayer *> createPlayer(QMediaPlayer *player) override;
+ QMaybe<QPlatformCamera *> createCamera(QCamera *) override;
+ QPlatformSurfaceCapture *createScreenCapture(QScreenCapture *) override;
+ QPlatformSurfaceCapture *createWindowCapture(QWindowCapture *) override;
+ QMaybe<QPlatformMediaRecorder *> createRecorder(QMediaRecorder *) override;
+ QMaybe<QPlatformImageCapture *> createImageCapture(QImageCapture *) override;
+
+ QMaybe<QPlatformVideoSink *> createVideoSink(QVideoSink *sink) override;
+
+ QMaybe<QPlatformAudioInput *> createAudioInput(QAudioInput *input) override;
+// QPlatformAudioOutput *createAudioOutput(QAudioOutput *) override;
+
+ QVideoFrame convertVideoFrame(QVideoFrame &srcFrame,
+ const QVideoFrameFormat &destFormat) override;
+
+protected:
+ QPlatformMediaFormatInfo *createFormatInfo() override;
+
+ QPlatformVideoDevices *createVideoDevices() override;
+
+ QPlatformCapturableWindows *createCapturableWindows() override;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediametadata.cpp b/src/plugins/multimedia/ffmpeg/qffmpegmediametadata.cpp
new file mode 100644
index 000000000..465e380db
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediametadata.cpp
@@ -0,0 +1,182 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegmediametadata_p.h"
+#include <QDebug>
+#include <QtCore/qdatetime.h>
+#include <qstringlist.h>
+#include <qurl.h>
+#include <qlocale.h>
+
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcMetaData, "qt.multimedia.ffmpeg.metadata")
+
+namespace {
+
+struct ffmpegTagToMetaDataKey
+{
+ const char *tag;
+ QMediaMetaData::Key key;
+};
+
+constexpr ffmpegTagToMetaDataKey ffmpegTagToMetaDataKey[] = {
+ { "title", QMediaMetaData::Title },
+ { "comment", QMediaMetaData::Comment },
+ { "description", QMediaMetaData::Description },
+ { "genre", QMediaMetaData::Genre },
+ { "date", QMediaMetaData::Date },
+ { "year", QMediaMetaData::Date },
+ { "creation_time", QMediaMetaData::Date },
+
+ { "language", QMediaMetaData::Language },
+
+ { "copyright", QMediaMetaData::Copyright },
+
+ // Music
+ { "album", QMediaMetaData::AlbumTitle },
+ { "album_artist", QMediaMetaData::AlbumArtist },
+ { "artist", QMediaMetaData::ContributingArtist },
+ { "track", QMediaMetaData::TrackNumber },
+
+ // Movie
+ { "performer", QMediaMetaData::LeadPerformer },
+
+ { nullptr, QMediaMetaData::Title }
+};
+
+}
+
+static QMediaMetaData::Key tagToKey(const char *tag)
+{
+ const auto *map = ffmpegTagToMetaDataKey;
+ while (map->tag) {
+ if (!strcmp(map->tag, tag))
+ return map->key;
+ ++map;
+ }
+ return QMediaMetaData::Key(-1);
+}
+
+static const char *keyToTag(QMediaMetaData::Key key)
+{
+ const auto *map = ffmpegTagToMetaDataKey;
+ while (map->tag) {
+ if (map->key == key)
+ return map->tag;
+ ++map;
+ }
+ return nullptr;
+}
+
+//internal
+void QFFmpegMetaData::addEntry(QMediaMetaData &metaData, AVDictionaryEntry *entry)
+{
+ qCDebug(qLcMetaData) << " checking:" << entry->key << entry->value;
+ QByteArray tag(entry->key);
+ QMediaMetaData::Key key = tagToKey(tag.toLower());
+ if (key == QMediaMetaData::Key(-1))
+ return;
+ qCDebug(qLcMetaData) << " adding" << key;
+
+ auto *map = &metaData;
+
+ int metaTypeId = keyType(key).id();
+ switch (metaTypeId) {
+ case qMetaTypeId<QString>():
+ map->insert(key, QString::fromUtf8(entry->value));
+ return;
+ case qMetaTypeId<QStringList>():
+ map->insert(key, QString::fromUtf8(entry->value).split(QLatin1Char(',')));
+ return;
+ case qMetaTypeId<QDateTime>(): {
+ QDateTime date;
+ if (!qstrcmp(entry->key, "year")) {
+ if (map->keys().contains(QMediaMetaData::Date))
+ return;
+ date = QDateTime(QDate(QByteArray(entry->value).toInt(), 1, 1), QTime(0, 0, 0));
+ } else {
+ date = QDateTime::fromString(QString::fromUtf8(entry->value), Qt::ISODate);
+ }
+ map->insert(key, date);
+ return;
+ }
+ case qMetaTypeId<QUrl>():
+ map->insert(key, QUrl::fromEncoded(entry->value));
+ return;
+ case qMetaTypeId<qint64>():
+ map->insert(key, (qint64)QByteArray(entry->value).toLongLong());
+ return;
+ case qMetaTypeId<int>():
+ map->insert(key, QByteArray(entry->value).toInt());
+ return;
+ case qMetaTypeId<qreal>():
+ map->insert(key, (qreal)QByteArray(entry->value).toDouble());
+ return;
+ default:
+ break;
+ }
+ if (metaTypeId == qMetaTypeId<QLocale::Language>()) {
+ map->insert(key, QVariant::fromValue(QLocale::codeToLanguage(QString::fromUtf8(entry->value), QLocale::ISO639Part2)));
+ }
+}
+
+
+QMediaMetaData QFFmpegMetaData::fromAVMetaData(const AVDictionary *tags)
+{
+ QMediaMetaData metaData;
+ AVDictionaryEntry *entry = nullptr;
+ while ((entry = av_dict_get(tags, "", entry, AV_DICT_IGNORE_SUFFIX)))
+ addEntry(metaData, entry);
+
+ return metaData;
+}
+
+QByteArray QFFmpegMetaData::value(const QMediaMetaData &metaData, QMediaMetaData::Key key)
+{
+ const int metaTypeId = keyType(key).id();
+ const QVariant val = metaData.value(key);
+ switch (metaTypeId) {
+ case qMetaTypeId<QString>():
+ return val.toString().toUtf8();
+ case qMetaTypeId<QStringList>():
+ return val.toStringList().join(u",").toUtf8();
+ case qMetaTypeId<QDateTime>():
+ return val.toDateTime().toString(Qt::ISODate).toUtf8();
+ case qMetaTypeId<QUrl>():
+ return val.toUrl().toEncoded();
+ case qMetaTypeId<qint64>():
+ case qMetaTypeId<int>():
+ return QByteArray::number(val.toLongLong());
+ case qMetaTypeId<qreal>():
+ return QByteArray::number(val.toDouble());
+ default:
+ break;
+ }
+ if (metaTypeId == qMetaTypeId<QLocale::Language>())
+ return QLocale::languageToCode(val.value<QLocale::Language>(), QLocale::ISO639Part2).toUtf8();
+ return {};
+}
+
+
+AVDictionary *QFFmpegMetaData::toAVMetaData(const QMediaMetaData &metaData)
+{
+ const QList<Key> keys = metaData.keys();
+ AVDictionary *dict = nullptr;
+ for (const auto &k : keys) {
+ const char *key = ::keyToTag(k);
+ if (!key)
+ continue;
+ QByteArray val = value(metaData, k);
+ if (val.isEmpty())
+ continue;
+ av_dict_set(&dict, key, val.constData(), 0);
+ }
+ return dict;
+}
+
+
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediametadata_p.h b/src/plugins/multimedia/ffmpeg/qffmpegmediametadata_p.h
new file mode 100644
index 000000000..201287495
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediametadata_p.h
@@ -0,0 +1,35 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGMEDIAMETADATA_H
+#define QFFMPEGMEDIAMETADATA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qmediametadata.h>
+#include <qffmpeg_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegMetaData : public QMediaMetaData
+{
+public:
+ static void addEntry(QMediaMetaData &metaData, AVDictionaryEntry *entry);
+ static QMediaMetaData fromAVMetaData(const AVDictionary *tags);
+
+ static QByteArray value(const QMediaMetaData &metaData, QMediaMetaData::Key key);
+ static AVDictionary *toAVMetaData(const QMediaMetaData &metaData);
+};
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGMEDIAMETADATA_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediaplayer.cpp b/src/plugins/multimedia/ffmpeg/qffmpegmediaplayer.cpp
new file mode 100644
index 000000000..951144692
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediaplayer.cpp
@@ -0,0 +1,411 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegmediaplayer_p.h"
+#include "private/qplatformaudiooutput_p.h"
+#include "qvideosink.h"
+#include "qaudiooutput.h"
+#include "qaudiobufferoutput.h"
+
+#include "qffmpegplaybackengine_p.h"
+#include <qiodevice.h>
+#include <qvideosink.h>
+#include <qtimer.h>
+#include <QtConcurrent/QtConcurrent>
+
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+class CancelToken : public ICancelToken
+{
+public:
+
+ bool isCancelled() const override { return m_cancelled.load(std::memory_order_acquire); }
+
+ void cancel() { m_cancelled.store(true, std::memory_order_release); }
+
+private:
+ std::atomic_bool m_cancelled = false;
+};
+
+} // namespace QFFmpeg
+
+using namespace QFFmpeg;
+
+QFFmpegMediaPlayer::QFFmpegMediaPlayer(QMediaPlayer *player)
+ : QPlatformMediaPlayer(player)
+{
+ m_positionUpdateTimer.setInterval(50);
+ m_positionUpdateTimer.setTimerType(Qt::PreciseTimer);
+ connect(&m_positionUpdateTimer, &QTimer::timeout, this, &QFFmpegMediaPlayer::updatePosition);
+}
+
+QFFmpegMediaPlayer::~QFFmpegMediaPlayer()
+{
+ if (m_cancelToken)
+ m_cancelToken->cancel();
+
+ m_loadMedia.waitForFinished();
+};
+
+qint64 QFFmpegMediaPlayer::duration() const
+{
+ return m_playbackEngine ? m_playbackEngine->duration() / 1000 : 0;
+}
+
+void QFFmpegMediaPlayer::setPosition(qint64 position)
+{
+ if (mediaStatus() == QMediaPlayer::LoadingMedia)
+ return;
+
+ if (m_playbackEngine) {
+ m_playbackEngine->seek(position * 1000);
+ updatePosition();
+ }
+
+ mediaStatusChanged(QMediaPlayer::LoadedMedia);
+}
+
+void QFFmpegMediaPlayer::updatePosition()
+{
+ positionChanged(m_playbackEngine ? m_playbackEngine->currentPosition() / 1000 : 0);
+}
+
+void QFFmpegMediaPlayer::endOfStream()
+{
+ // stop update timer and report end position anyway
+ m_positionUpdateTimer.stop();
+ QPointer currentPlaybackEngine(m_playbackEngine.get());
+ positionChanged(duration());
+
+ // skip changing state and mediaStatus if playbackEngine has been recreated,
+ // e.g. if new media has been loaded as a response to positionChanged signal
+ if (currentPlaybackEngine)
+ stateChanged(QMediaPlayer::StoppedState);
+ if (currentPlaybackEngine)
+ mediaStatusChanged(QMediaPlayer::EndOfMedia);
+}
+
+void QFFmpegMediaPlayer::onLoopChanged()
+{
+ // report about finish and start
+ // reporting both signals is a bit contraversial
+ // but it eshures the idea of notifications about
+ // imporatant position points.
+ // Also, it ensures more predictable flow for testing.
+ positionChanged(duration());
+ positionChanged(0);
+ m_positionUpdateTimer.stop();
+ m_positionUpdateTimer.start();
+}
+
+void QFFmpegMediaPlayer::onBuffered()
+{
+ if (mediaStatus() == QMediaPlayer::BufferingMedia)
+ mediaStatusChanged(QMediaPlayer::BufferedMedia);
+}
+
+float QFFmpegMediaPlayer::bufferProgress() const
+{
+ return m_bufferProgress;
+}
+
+void QFFmpegMediaPlayer::mediaStatusChanged(QMediaPlayer::MediaStatus status)
+{
+ if (mediaStatus() == status)
+ return;
+
+ const auto newBufferProgress = status == QMediaPlayer::BufferingMedia ? 0.25f // to be improved
+ : status == QMediaPlayer::BufferedMedia ? 1.f
+ : 0.f;
+
+ if (!qFuzzyCompare(newBufferProgress, m_bufferProgress)) {
+ m_bufferProgress = newBufferProgress;
+ bufferProgressChanged(newBufferProgress);
+ }
+
+ QPlatformMediaPlayer::mediaStatusChanged(status);
+}
+
+QMediaTimeRange QFFmpegMediaPlayer::availablePlaybackRanges() const
+{
+ return {};
+}
+
+qreal QFFmpegMediaPlayer::playbackRate() const
+{
+ return m_playbackRate;
+}
+
+void QFFmpegMediaPlayer::setPlaybackRate(qreal rate)
+{
+ const float effectiveRate = std::max(static_cast<float>(rate), 0.0f);
+
+ if (qFuzzyCompare(m_playbackRate, effectiveRate))
+ return;
+
+ m_playbackRate = effectiveRate;
+
+ if (m_playbackEngine)
+ m_playbackEngine->setPlaybackRate(effectiveRate);
+
+ playbackRateChanged(effectiveRate);
+}
+
+QUrl QFFmpegMediaPlayer::media() const
+{
+ return m_url;
+}
+
+const QIODevice *QFFmpegMediaPlayer::mediaStream() const
+{
+ return m_device;
+}
+
+void QFFmpegMediaPlayer::handleIncorrectMedia(QMediaPlayer::MediaStatus status)
+{
+ seekableChanged(false);
+ audioAvailableChanged(false);
+ videoAvailableChanged(false);
+ metaDataChanged();
+ mediaStatusChanged(status);
+ m_playbackEngine = nullptr;
+};
+
+void QFFmpegMediaPlayer::setMedia(const QUrl &media, QIODevice *stream)
+{
+ // Wait for previous unfinished load attempts.
+ if (m_cancelToken)
+ m_cancelToken->cancel();
+
+ m_loadMedia.waitForFinished();
+
+ m_url = media;
+ m_device = stream;
+ m_playbackEngine = nullptr;
+
+ if (media.isEmpty() && !stream) {
+ handleIncorrectMedia(QMediaPlayer::NoMedia);
+ return;
+ }
+
+ mediaStatusChanged(QMediaPlayer::LoadingMedia);
+
+ m_requestedStatus = QMediaPlayer::StoppedState;
+
+ m_cancelToken = std::make_shared<CancelToken>();
+
+ // Load media asynchronously to keep GUI thread responsive while loading media
+ m_loadMedia = QtConcurrent::run([this, media, stream, cancelToken = m_cancelToken] {
+ // On worker thread
+ const MediaDataHolder::Maybe mediaHolder =
+ MediaDataHolder::create(media, stream, cancelToken);
+
+ // Transition back to calling thread using invokeMethod because
+ // QFuture continuations back on calling thread may deadlock (QTBUG-117918)
+ QMetaObject::invokeMethod(this, [this, mediaHolder, cancelToken] {
+ setMediaAsync(mediaHolder, cancelToken);
+ });
+ });
+}
+
+void QFFmpegMediaPlayer::setMediaAsync(QFFmpeg::MediaDataHolder::Maybe mediaDataHolder,
+ const std::shared_ptr<QFFmpeg::CancelToken> &cancelToken)
+{
+ Q_ASSERT(mediaStatus() == QMediaPlayer::LoadingMedia);
+
+ // If loading was cancelled, we do not emit any signals about failing
+ // to load media (or any other events). The rationale is that cancellation
+ // either happens during destruction, where the signals are no longer
+ // of interest, or it happens as a response to user requesting to load
+ // another media file. In the latter case, we don't want to risk popping
+ // up error dialogs or similar.
+ if (cancelToken->isCancelled()) {
+ return;
+ }
+
+ if (!mediaDataHolder) {
+ const auto [code, description] = mediaDataHolder.error();
+ error(code, description);
+ handleIncorrectMedia(QMediaPlayer::MediaStatus::InvalidMedia);
+ return;
+ }
+
+ m_playbackEngine = std::make_unique<PlaybackEngine>();
+
+ connect(m_playbackEngine.get(), &PlaybackEngine::endOfStream, this,
+ &QFFmpegMediaPlayer::endOfStream);
+ connect(m_playbackEngine.get(), &PlaybackEngine::errorOccured, this,
+ &QFFmpegMediaPlayer::error);
+ connect(m_playbackEngine.get(), &PlaybackEngine::loopChanged, this,
+ &QFFmpegMediaPlayer::onLoopChanged);
+ connect(m_playbackEngine.get(), &PlaybackEngine::buffered, this,
+ &QFFmpegMediaPlayer::onBuffered);
+
+ m_playbackEngine->setMedia(std::move(*mediaDataHolder.value()));
+
+ m_playbackEngine->setAudioBufferOutput(m_audioBufferOutput);
+ m_playbackEngine->setAudioSink(m_audioOutput);
+ m_playbackEngine->setVideoSink(m_videoSink);
+
+ m_playbackEngine->setLoops(loops());
+ m_playbackEngine->setPlaybackRate(m_playbackRate);
+
+ durationChanged(duration());
+ tracksChanged();
+ metaDataChanged();
+ seekableChanged(m_playbackEngine->isSeekable());
+
+ audioAvailableChanged(
+ !m_playbackEngine->streamInfo(QPlatformMediaPlayer::AudioStream).isEmpty());
+ videoAvailableChanged(
+ !m_playbackEngine->streamInfo(QPlatformMediaPlayer::VideoStream).isEmpty());
+
+ mediaStatusChanged(QMediaPlayer::LoadedMedia);
+
+ if (m_requestedStatus != QMediaPlayer::StoppedState) {
+ if (m_requestedStatus == QMediaPlayer::PlayingState)
+ play();
+ else if (m_requestedStatus == QMediaPlayer::PausedState)
+ pause();
+ }
+}
+
+void QFFmpegMediaPlayer::play()
+{
+ if (mediaStatus() == QMediaPlayer::LoadingMedia) {
+ m_requestedStatus = QMediaPlayer::PlayingState;
+ return;
+ }
+
+ if (!m_playbackEngine)
+ return;
+
+ if (mediaStatus() == QMediaPlayer::EndOfMedia && state() == QMediaPlayer::StoppedState) {
+ m_playbackEngine->seek(0);
+ positionChanged(0);
+ }
+
+ runPlayback();
+}
+
+void QFFmpegMediaPlayer::runPlayback()
+{
+ m_playbackEngine->play();
+ m_positionUpdateTimer.start();
+ stateChanged(QMediaPlayer::PlayingState);
+
+ if (mediaStatus() == QMediaPlayer::LoadedMedia || mediaStatus() == QMediaPlayer::EndOfMedia)
+ mediaStatusChanged(QMediaPlayer::BufferingMedia);
+}
+
+void QFFmpegMediaPlayer::pause()
+{
+ if (mediaStatus() == QMediaPlayer::LoadingMedia) {
+ m_requestedStatus = QMediaPlayer::PausedState;
+ return;
+ }
+
+ if (!m_playbackEngine)
+ return;
+
+ if (mediaStatus() == QMediaPlayer::EndOfMedia && state() == QMediaPlayer::StoppedState) {
+ m_playbackEngine->seek(0);
+ positionChanged(0);
+ }
+ m_playbackEngine->pause();
+ m_positionUpdateTimer.stop();
+ stateChanged(QMediaPlayer::PausedState);
+
+ if (mediaStatus() == QMediaPlayer::LoadedMedia || mediaStatus() == QMediaPlayer::EndOfMedia)
+ mediaStatusChanged(QMediaPlayer::BufferingMedia);
+}
+
+void QFFmpegMediaPlayer::stop()
+{
+ if (mediaStatus() == QMediaPlayer::LoadingMedia) {
+ m_requestedStatus = QMediaPlayer::StoppedState;
+ return;
+ }
+
+ if (!m_playbackEngine)
+ return;
+
+ m_playbackEngine->stop();
+ m_positionUpdateTimer.stop();
+ m_playbackEngine->seek(0);
+ positionChanged(0);
+ stateChanged(QMediaPlayer::StoppedState);
+ mediaStatusChanged(QMediaPlayer::LoadedMedia);
+}
+
+void QFFmpegMediaPlayer::setAudioOutput(QPlatformAudioOutput *output)
+{
+ m_audioOutput = output;
+ if (m_playbackEngine)
+ m_playbackEngine->setAudioSink(output);
+}
+
+void QFFmpegMediaPlayer::setAudioBufferOutput(QAudioBufferOutput *output) {
+ m_audioBufferOutput = output;
+ if (m_playbackEngine)
+ m_playbackEngine->setAudioBufferOutput(output);
+}
+
+QMediaMetaData QFFmpegMediaPlayer::metaData() const
+{
+ return m_playbackEngine ? m_playbackEngine->metaData() : QMediaMetaData{};
+}
+
+void QFFmpegMediaPlayer::setVideoSink(QVideoSink *sink)
+{
+ m_videoSink = sink;
+ if (m_playbackEngine)
+ m_playbackEngine->setVideoSink(sink);
+}
+
+QVideoSink *QFFmpegMediaPlayer::videoSink() const
+{
+ return m_videoSink;
+}
+
+int QFFmpegMediaPlayer::trackCount(TrackType type)
+{
+ return m_playbackEngine ? m_playbackEngine->streamInfo(type).count() : 0;
+}
+
+QMediaMetaData QFFmpegMediaPlayer::trackMetaData(TrackType type, int streamNumber)
+{
+ if (!m_playbackEngine || streamNumber < 0
+ || streamNumber >= m_playbackEngine->streamInfo(type).count())
+ return {};
+ return m_playbackEngine->streamInfo(type).at(streamNumber).metaData;
+}
+
+int QFFmpegMediaPlayer::activeTrack(TrackType type)
+{
+ return m_playbackEngine ? m_playbackEngine->activeTrack(type) : -1;
+}
+
+void QFFmpegMediaPlayer::setActiveTrack(TrackType type, int streamNumber)
+{
+ if (m_playbackEngine)
+ m_playbackEngine->setActiveTrack(type, streamNumber);
+ else
+ qWarning() << "Cannot set active track without open source";
+}
+
+void QFFmpegMediaPlayer::setLoops(int loops)
+{
+ if (m_playbackEngine)
+ m_playbackEngine->setLoops(loops);
+
+ QPlatformMediaPlayer::setLoops(loops);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegmediaplayer_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediaplayer_p.h b/src/plugins/multimedia/ffmpeg/qffmpegmediaplayer_p.h
new file mode 100644
index 000000000..4ab5701da
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediaplayer_p.h
@@ -0,0 +1,119 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QFFMPEGMEDIAPLAYER_H
+#define QFFMPEGMEDIAPLAYER_H
+
+#include <private/qplatformmediaplayer_p.h>
+#include <qmediametadata.h>
+#include <qtimer.h>
+#include <qpointer.h>
+#include <qfuture.h>
+#include "qffmpeg_p.h"
+#include "playbackengine/qffmpegmediadataholder_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+class CancelToken;
+
+class PlaybackEngine;
+}
+
+class QPlatformAudioOutput;
+
+class QFFmpegMediaPlayer : public QObject, public QPlatformMediaPlayer
+{
+ Q_OBJECT
+public:
+ QFFmpegMediaPlayer(QMediaPlayer *player);
+ ~QFFmpegMediaPlayer();
+
+ qint64 duration() const override;
+
+ void setPosition(qint64 position) override;
+
+ float bufferProgress() const override;
+
+ QMediaTimeRange availablePlaybackRanges() const override;
+
+ qreal playbackRate() const override;
+ void setPlaybackRate(qreal rate) override;
+
+ QUrl media() const override;
+ const QIODevice *mediaStream() const override;
+ void setMedia(const QUrl &media, QIODevice *stream) override;
+
+ void play() override;
+ void pause() override;
+ void stop() override;
+
+ void setAudioOutput(QPlatformAudioOutput *) override;
+
+ void setAudioBufferOutput(QAudioBufferOutput *) override;
+
+ QMediaMetaData metaData() const override;
+
+ void setVideoSink(QVideoSink *sink) override;
+ QVideoSink *videoSink() const;
+
+ int trackCount(TrackType) override;
+ QMediaMetaData trackMetaData(TrackType type, int streamNumber) override;
+ int activeTrack(TrackType) override;
+ void setActiveTrack(TrackType, int streamNumber) override;
+ void setLoops(int loops) override;
+
+private:
+ void runPlayback();
+ void handleIncorrectMedia(QMediaPlayer::MediaStatus status);
+ void setMediaAsync(QFFmpeg::MediaDataHolder::Maybe mediaDataHolder,
+ const std::shared_ptr<QFFmpeg::CancelToken> &cancelToken);
+
+ void mediaStatusChanged(QMediaPlayer::MediaStatus);
+
+private slots:
+ void updatePosition();
+ void endOfStream();
+ void error(int error, const QString &errorString)
+ {
+ QPlatformMediaPlayer::error(error, errorString);
+ }
+ void onLoopChanged();
+ void onBuffered();
+
+private:
+ QTimer m_positionUpdateTimer;
+ QMediaPlayer::PlaybackState m_requestedStatus = QMediaPlayer::StoppedState;
+
+ using PlaybackEngine = QFFmpeg::PlaybackEngine;
+
+ std::unique_ptr<PlaybackEngine> m_playbackEngine;
+ QPlatformAudioOutput *m_audioOutput = nullptr;
+ QPointer<QAudioBufferOutput> m_audioBufferOutput;
+ QPointer<QVideoSink> m_videoSink;
+
+ QUrl m_url;
+ QPointer<QIODevice> m_device;
+ float m_playbackRate = 1.;
+ float m_bufferProgress = 0.f;
+ QFuture<void> m_loadMedia;
+ std::shared_ptr<QFFmpeg::CancelToken> m_cancelToken; // For interrupting ongoing
+ // network connection attempt
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QMEDIAPLAYERCONTROL_H
+
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediarecorder.cpp b/src/plugins/multimedia/ffmpeg/qffmpegmediarecorder.cpp
new file mode 100644
index 000000000..0315a0061
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediarecorder.cpp
@@ -0,0 +1,189 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegmediarecorder_p.h"
+#include "qaudiodevice.h"
+#include <private/qmediastoragelocation_p.h>
+#include <private/qplatformcamera_p.h>
+#include <private/qplatformsurfacecapture_p.h>
+#include "qaudiosource.h"
+#include "qffmpegaudioinput_p.h"
+#include "qaudiobuffer.h"
+#include "recordingengine/qffmpegrecordingengine_p.h"
+#include "qffmpegmediacapturesession_p.h"
+
+#include <qdebug.h>
+#include <qloggingcategory.h>
+
+static Q_LOGGING_CATEGORY(qLcMediaEncoder, "qt.multimedia.ffmpeg.encoder");
+
+QT_BEGIN_NAMESPACE
+
+QFFmpegMediaRecorder::QFFmpegMediaRecorder(QMediaRecorder *parent) : QPlatformMediaRecorder(parent)
+{
+}
+
+QFFmpegMediaRecorder::~QFFmpegMediaRecorder() = default;
+
+bool QFFmpegMediaRecorder::isLocationWritable(const QUrl &) const
+{
+ return true;
+}
+
+void QFFmpegMediaRecorder::handleSessionError(QMediaRecorder::Error code, const QString &description)
+{
+ updateError(code, description);
+ stop();
+}
+
+void QFFmpegMediaRecorder::handleEndOfSourceStream()
+{
+ if (mediaRecorder()->autoStop())
+ stop();
+}
+
+void QFFmpegMediaRecorder::record(QMediaEncoderSettings &settings)
+{
+ if (!m_session || state() != QMediaRecorder::StoppedState)
+ return;
+
+ auto videoSources = m_session->activeVideoSources();
+ auto audioInputs = m_session->activeAudioInputs();
+ const auto hasVideo = !videoSources.empty();
+ const auto hasAudio = !audioInputs.empty();
+
+ if (!hasVideo && !hasAudio) {
+ updateError(QMediaRecorder::ResourceError, QMediaRecorder::tr("No video or audio input"));
+ return;
+ }
+
+ if (outputDevice() && !outputLocation().isEmpty())
+ qCWarning(qLcMediaEncoder)
+ << "Both outputDevice and outputLocation has been set to QMediaRecorder";
+
+ if (outputDevice() && !outputDevice()->isWritable())
+ qCWarning(qLcMediaEncoder) << "Output device has been set but not it's not writable";
+
+ QString actualLocation;
+ auto formatContext = std::make_unique<QFFmpeg::EncodingFormatContext>(settings.fileFormat());
+
+ if (outputDevice() && outputDevice()->isWritable()) {
+ formatContext->openAVIO(outputDevice());
+ } else {
+ actualLocation = findActualLocation(settings);
+ qCDebug(qLcMediaEncoder) << "recording new media to" << actualLocation;
+ formatContext->openAVIO(actualLocation);
+ }
+
+ qCDebug(qLcMediaEncoder) << "requested format:" << settings.fileFormat()
+ << settings.audioCodec();
+
+ if (!formatContext->isAVIOOpen()) {
+ updateError(QMediaRecorder::LocationNotWritable,
+ QMediaRecorder::tr("Cannot open the output location for writing"));
+ return;
+ }
+
+ m_recordingEngine.reset(new RecordingEngine(settings, std::move(formatContext)));
+ m_recordingEngine->setMetaData(m_metaData);
+ connect(m_recordingEngine.get(), &QFFmpeg::RecordingEngine::durationChanged, this,
+ &QFFmpegMediaRecorder::newDuration);
+ connect(m_recordingEngine.get(), &QFFmpeg::RecordingEngine::finalizationDone, this,
+ &QFFmpegMediaRecorder::finalizationDone);
+ connect(m_recordingEngine.get(), &QFFmpeg::RecordingEngine::sessionError, this,
+ &QFFmpegMediaRecorder::handleSessionError);
+ connect(m_recordingEngine.get(), &QFFmpeg::RecordingEngine::endOfSourceStreams, this,
+ &QFFmpegMediaRecorder::handleEndOfSourceStream);
+
+ auto handleStreamInitializationError = [this](QMediaRecorder::Error code,
+ const QString &description) {
+ qCWarning(qLcMediaEncoder) << "Stream initialization error:" << description;
+ updateError(code, description);
+ };
+
+ connect(m_recordingEngine.get(), &QFFmpeg::RecordingEngine::streamInitializationError, this,
+ handleStreamInitializationError);
+
+ durationChanged(0);
+ stateChanged(QMediaRecorder::RecordingState);
+ actualLocationChanged(QUrl::fromLocalFile(actualLocation));
+
+ m_recordingEngine->initialize(audioInputs, videoSources);
+}
+
+void QFFmpegMediaRecorder::pause()
+{
+ if (!m_session || state() != QMediaRecorder::RecordingState)
+ return;
+
+ Q_ASSERT(m_recordingEngine);
+ m_recordingEngine->setPaused(true);
+
+ stateChanged(QMediaRecorder::PausedState);
+}
+
+void QFFmpegMediaRecorder::resume()
+{
+ if (!m_session || state() != QMediaRecorder::PausedState)
+ return;
+
+ Q_ASSERT(m_recordingEngine);
+ m_recordingEngine->setPaused(false);
+
+ stateChanged(QMediaRecorder::RecordingState);
+}
+
+void QFFmpegMediaRecorder::stop()
+{
+ if (!m_session || state() == QMediaRecorder::StoppedState)
+ return;
+ auto * input = m_session ? m_session->audioInput() : nullptr;
+ if (input)
+ static_cast<QFFmpegAudioInput *>(input)->setRunning(false);
+ qCDebug(qLcMediaEncoder) << "stop";
+
+ m_recordingEngine.reset();
+}
+
+void QFFmpegMediaRecorder::finalizationDone()
+{
+ stateChanged(QMediaRecorder::StoppedState);
+}
+
+void QFFmpegMediaRecorder::setMetaData(const QMediaMetaData &metaData)
+{
+ if (!m_session)
+ return;
+ m_metaData = metaData;
+}
+
+QMediaMetaData QFFmpegMediaRecorder::metaData() const
+{
+ return m_metaData;
+}
+
+void QFFmpegMediaRecorder::setCaptureSession(QFFmpegMediaCaptureSession *session)
+{
+ auto *captureSession = session;
+ if (m_session == captureSession)
+ return;
+
+ if (m_session)
+ stop();
+
+ m_session = captureSession;
+ if (!m_session)
+ return;
+}
+
+void QFFmpegMediaRecorder::RecordingEngineDeleter::operator()(
+ RecordingEngine *recordingEngine) const
+{
+ // ### all of the below should be done asynchronous. finalize() should do it's work in a thread
+ // to avoid blocking the UI in case of slow codecs
+ recordingEngine->finalize();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegmediarecorder_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediarecorder_p.h b/src/plugins/multimedia/ffmpeg/qffmpegmediarecorder_p.h
new file mode 100644
index 000000000..1bca093c2
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegmediarecorder_p.h
@@ -0,0 +1,72 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGMEDIARECODER_H
+#define QFFMPEGMEDIARECODER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediarecorder_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioSource;
+class QAudioSourceIO;
+class QAudioBuffer;
+class QMediaMetaData;
+class QFFmpegMediaCaptureSession;
+
+namespace QFFmpeg {
+class RecordingEngine;
+}
+
+class QFFmpegMediaRecorder : public QObject, public QPlatformMediaRecorder
+{
+ Q_OBJECT
+public:
+ QFFmpegMediaRecorder(QMediaRecorder *parent);
+ virtual ~QFFmpegMediaRecorder();
+
+ bool isLocationWritable(const QUrl &sink) const override;
+
+ void record(QMediaEncoderSettings &settings) override;
+ void pause() override;
+ void resume() override;
+ void stop() override;
+
+ void setMetaData(const QMediaMetaData &) override;
+ QMediaMetaData metaData() const override;
+
+ void setCaptureSession(QFFmpegMediaCaptureSession *session);
+
+private Q_SLOTS:
+ void newDuration(qint64 d) { durationChanged(d); }
+ void finalizationDone();
+ void handleSessionError(QMediaRecorder::Error code, const QString &description);
+ void handleEndOfSourceStream();
+
+private:
+ using RecordingEngine = QFFmpeg::RecordingEngine;
+ struct RecordingEngineDeleter
+ {
+ void operator()(RecordingEngine *) const;
+ };
+
+ QFFmpegMediaCaptureSession *m_session = nullptr;
+ QMediaMetaData m_metaData;
+
+ std::unique_ptr<RecordingEngine, RecordingEngineDeleter> m_recordingEngine;
+};
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGMEDIARECODER_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegplaybackengine.cpp b/src/plugins/multimedia/ffmpeg/qffmpegplaybackengine.cpp
new file mode 100644
index 000000000..11dccb149
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegplaybackengine.cpp
@@ -0,0 +1,649 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qffmpegplaybackengine_p.h"
+
+#include "qvideosink.h"
+#include "qaudiooutput.h"
+#include "private/qplatformaudiooutput_p.h"
+#include "private/qplatformvideosink_p.h"
+#include "private/qaudiobufferoutput_p.h"
+#include "qiodevice.h"
+#include "playbackengine/qffmpegdemuxer_p.h"
+#include "playbackengine/qffmpegstreamdecoder_p.h"
+#include "playbackengine/qffmpegsubtitlerenderer_p.h"
+#include "playbackengine/qffmpegvideorenderer_p.h"
+#include "playbackengine/qffmpegaudiorenderer_p.h"
+
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+static Q_LOGGING_CATEGORY(qLcPlaybackEngine, "qt.multimedia.ffmpeg.playbackengine");
+
+// The helper is needed since on some compilers std::unique_ptr
+// doesn't have a default constructor in the case of sizeof(CustomDeleter) > 0
+template<typename Array>
+inline Array defaultObjectsArray()
+{
+ using T = typename Array::value_type;
+ return { T{ {}, {} }, T{ {}, {} }, T{ {}, {} } };
+}
+
+// TODO: investigate what's better: profile and try network case
+// Most likely, shouldPauseStreams = false is better because of:
+// - packet and frame buffers are not big, the saturration of the is pretty fast.
+// - after any pause a user has some preloaded buffers, so the playback is
+// supposed to be more stable in cases with a weak processor or bad internet.
+// - the code is simplier, usage is more convenient.
+//
+static constexpr bool shouldPauseStreams = false;
+
+PlaybackEngine::PlaybackEngine()
+ : m_demuxer({}, {}),
+ m_streams(defaultObjectsArray<decltype(m_streams)>()),
+ m_renderers(defaultObjectsArray<decltype(m_renderers)>())
+{
+ qCDebug(qLcPlaybackEngine) << "Create PlaybackEngine";
+ qRegisterMetaType<QFFmpeg::Packet>();
+ qRegisterMetaType<QFFmpeg::Frame>();
+}
+
+PlaybackEngine::~PlaybackEngine() {
+ qCDebug(qLcPlaybackEngine) << "Delete PlaybackEngine";
+
+ finalizeOutputs();
+ forEachExistingObject([](auto &object) { object.reset(); });
+ deleteFreeThreads();
+}
+
+void PlaybackEngine::onRendererFinished()
+{
+ auto isAtEnd = [this](auto trackType) {
+ return !m_renderers[trackType] || m_renderers[trackType]->isAtEnd();
+ };
+
+ if (!isAtEnd(QPlatformMediaPlayer::VideoStream))
+ return;
+
+ if (!isAtEnd(QPlatformMediaPlayer::AudioStream))
+ return;
+
+ if (!isAtEnd(QPlatformMediaPlayer::SubtitleStream) && !hasMediaStream())
+ return;
+
+ if (std::exchange(m_state, QMediaPlayer::StoppedState) == QMediaPlayer::StoppedState)
+ return;
+
+ finilizeTime(duration());
+
+ forceUpdate();
+
+ qCDebug(qLcPlaybackEngine) << "Playback engine end of stream";
+
+ emit endOfStream();
+}
+
+void PlaybackEngine::onRendererLoopChanged(quint64 id, qint64 offset, int loopIndex)
+{
+ if (!hasRenderer(id))
+ return;
+
+ if (loopIndex > m_currentLoopOffset.index) {
+ m_currentLoopOffset = { offset, loopIndex };
+ emit loopChanged();
+ } else if (loopIndex == m_currentLoopOffset.index && offset != m_currentLoopOffset.pos) {
+ qWarning() << "Unexpected offset for loop" << loopIndex << ":" << offset << "vs"
+ << m_currentLoopOffset.pos;
+ m_currentLoopOffset.pos = offset;
+ }
+}
+
+void PlaybackEngine::onRendererSynchronized(quint64 id, std::chrono::steady_clock::time_point tp,
+ qint64 pos)
+{
+ if (!hasRenderer(id))
+ return;
+
+ Q_ASSERT(m_renderers[QPlatformMediaPlayer::AudioStream]
+ && m_renderers[QPlatformMediaPlayer::AudioStream]->id() == id);
+
+ m_timeController.sync(tp, pos);
+
+ forEachExistingObject<Renderer>([&](auto &renderer) {
+ if (id != renderer->id())
+ renderer->syncSoft(tp, pos);
+ });
+}
+
+void PlaybackEngine::setState(QMediaPlayer::PlaybackState state) {
+ if (!m_media.avContext())
+ return;
+
+ if (state == m_state)
+ return;
+
+ const auto prevState = std::exchange(m_state, state);
+
+ if (m_state == QMediaPlayer::StoppedState) {
+ finalizeOutputs();
+ finilizeTime(0);
+ }
+
+ if (prevState == QMediaPlayer::StoppedState || m_state == QMediaPlayer::StoppedState)
+ recreateObjects();
+
+ if (prevState == QMediaPlayer::StoppedState)
+ triggerStepIfNeeded();
+
+ updateObjectsPausedState();
+}
+
+void PlaybackEngine::updateObjectsPausedState()
+{
+ const auto paused = m_state != QMediaPlayer::PlayingState;
+ m_timeController.setPaused(paused);
+
+ forEachExistingObject([&](auto &object) {
+ bool objectPaused = false;
+
+ if constexpr (std::is_same_v<decltype(*object), Renderer &>)
+ objectPaused = paused;
+ else if constexpr (shouldPauseStreams) {
+ auto streamPaused = [](bool p, auto &r) {
+ const auto needMoreFrames = r && r->stepInProgress();
+ return p && !needMoreFrames;
+ };
+
+ if constexpr (std::is_same_v<decltype(*object), StreamDecoder &>)
+ objectPaused = streamPaused(paused, renderer(object->trackType()));
+ else
+ objectPaused = std::accumulate(m_renderers.begin(), m_renderers.end(), paused,
+ streamPaused);
+ }
+
+ object->setPaused(objectPaused);
+ });
+}
+
+void PlaybackEngine::ObjectDeleter::operator()(PlaybackEngineObject *object) const
+{
+ Q_ASSERT(engine);
+ if (!std::exchange(engine->m_threadsDirty, true))
+ QMetaObject::invokeMethod(engine, &PlaybackEngine::deleteFreeThreads, Qt::QueuedConnection);
+
+ object->kill();
+}
+
+void PlaybackEngine::registerObject(PlaybackEngineObject &object)
+{
+ connect(&object, &PlaybackEngineObject::error, this, &PlaybackEngine::errorOccured);
+
+ auto threadName = objectThreadName(object);
+ auto &thread = m_threads[threadName];
+ if (!thread) {
+ thread = std::make_unique<QThread>();
+ thread->setObjectName(threadName);
+ thread->start();
+ }
+
+ Q_ASSERT(object.thread() != thread.get());
+ object.moveToThread(thread.get());
+}
+
+PlaybackEngine::RendererPtr
+PlaybackEngine::createRenderer(QPlatformMediaPlayer::TrackType trackType)
+{
+ switch (trackType) {
+ case QPlatformMediaPlayer::VideoStream:
+ return m_videoSink
+ ? createPlaybackEngineObject<VideoRenderer>(m_timeController, m_videoSink, m_media.rotation())
+ : RendererPtr{ {}, {} };
+ case QPlatformMediaPlayer::AudioStream:
+ return m_audioOutput || m_audioBufferOutput
+ ? createPlaybackEngineObject<AudioRenderer>(m_timeController, m_audioOutput, m_audioBufferOutput)
+ : RendererPtr{ {}, {} };
+ case QPlatformMediaPlayer::SubtitleStream:
+ return m_videoSink
+ ? createPlaybackEngineObject<SubtitleRenderer>(m_timeController, m_videoSink)
+ : RendererPtr{ {}, {} };
+ default:
+ return { {}, {} };
+ }
+}
+
+template<typename C, typename Action>
+void PlaybackEngine::forEachExistingObject(Action &&action)
+{
+ auto handleNotNullObject = [&](auto &object) {
+ if constexpr (std::is_base_of_v<C, std::remove_reference_t<decltype(*object)>>)
+ if (object)
+ action(object);
+ };
+
+ handleNotNullObject(m_demuxer);
+ std::for_each(m_streams.begin(), m_streams.end(), handleNotNullObject);
+ std::for_each(m_renderers.begin(), m_renderers.end(), handleNotNullObject);
+}
+
+template<typename Action>
+void PlaybackEngine::forEachExistingObject(Action &&action)
+{
+ forEachExistingObject<PlaybackEngineObject>(std::forward<Action>(action));
+}
+
+void PlaybackEngine::seek(qint64 pos)
+{
+ pos = boundPosition(pos);
+
+ m_timeController.setPaused(true);
+ m_timeController.sync(m_currentLoopOffset.pos + pos);
+
+ forceUpdate();
+}
+
+void PlaybackEngine::setLoops(int loops)
+{
+ if (!isSeekable()) {
+ qWarning() << "Cannot set loops for non-seekable source";
+ return;
+ }
+
+ if (std::exchange(m_loops, loops) == loops)
+ return;
+
+ qCDebug(qLcPlaybackEngine) << "set playback engine loops:" << loops << "prev loops:" << m_loops
+ << "index:" << m_currentLoopOffset.index;
+
+ if (m_demuxer)
+ m_demuxer->setLoops(loops);
+}
+
+void PlaybackEngine::triggerStepIfNeeded()
+{
+ if (m_state != QMediaPlayer::PausedState)
+ return;
+
+ if (m_renderers[QPlatformMediaPlayer::VideoStream])
+ m_renderers[QPlatformMediaPlayer::VideoStream]->doForceStep();
+
+ // TODO: maybe trigger SubtitleStream.
+ // If trigger it, we have to make seeking for the current subtitle frame more stable.
+ // Or set some timeout for seeking.
+}
+
+QString PlaybackEngine::objectThreadName(const PlaybackEngineObject &object)
+{
+ QString result = object.metaObject()->className();
+ if (auto stream = qobject_cast<const StreamDecoder *>(&object))
+ result += QString::number(stream->trackType());
+
+ return result;
+}
+
+void PlaybackEngine::setPlaybackRate(float rate) {
+ if (rate == playbackRate())
+ return;
+
+ m_timeController.setPlaybackRate(rate);
+ forEachExistingObject<Renderer>([rate](auto &renderer) { renderer->setPlaybackRate(rate); });
+}
+
+float PlaybackEngine::playbackRate() const {
+ return m_timeController.playbackRate();
+}
+
+void PlaybackEngine::recreateObjects()
+{
+ m_timeController.setPaused(true);
+
+ forEachExistingObject([](auto &object) { object.reset(); });
+
+ createObjectsIfNeeded();
+}
+
+void PlaybackEngine::createObjectsIfNeeded()
+{
+ if (m_state == QMediaPlayer::StoppedState || !m_media.avContext())
+ return;
+
+ for (int i = 0; i < QPlatformMediaPlayer::NTrackTypes; ++i)
+ createStreamAndRenderer(static_cast<QPlatformMediaPlayer::TrackType>(i));
+
+ createDemuxer();
+}
+
+void PlaybackEngine::forceUpdate()
+{
+ recreateObjects();
+ triggerStepIfNeeded();
+ updateObjectsPausedState();
+}
+
+void PlaybackEngine::createStreamAndRenderer(QPlatformMediaPlayer::TrackType trackType)
+{
+ auto codec = codecForTrack(trackType);
+
+ auto &renderer = m_renderers[trackType];
+
+ if (!codec)
+ return;
+
+ if (!renderer) {
+ renderer = createRenderer(trackType);
+
+ if (!renderer)
+ return;
+
+ connect(renderer.get(), &Renderer::synchronized, this,
+ &PlaybackEngine::onRendererSynchronized);
+
+ connect(renderer.get(), &Renderer::loopChanged, this,
+ &PlaybackEngine::onRendererLoopChanged);
+
+ if constexpr (shouldPauseStreams)
+ connect(renderer.get(), &Renderer::forceStepDone, this,
+ &PlaybackEngine::updateObjectsPausedState);
+
+ connect(renderer.get(), &PlaybackEngineObject::atEnd, this,
+ &PlaybackEngine::onRendererFinished);
+ }
+
+ auto &stream = m_streams[trackType] =
+ createPlaybackEngineObject<StreamDecoder>(*codec, renderer->seekPosition());
+
+ Q_ASSERT(trackType == stream->trackType());
+
+ connect(stream.get(), &StreamDecoder::requestHandleFrame, renderer.get(), &Renderer::render);
+ connect(stream.get(), &PlaybackEngineObject::atEnd, renderer.get(),
+ &Renderer::onFinalFrameReceived);
+ connect(renderer.get(), &Renderer::frameProcessed, stream.get(),
+ &StreamDecoder::onFrameProcessed);
+}
+
+std::optional<Codec> PlaybackEngine::codecForTrack(QPlatformMediaPlayer::TrackType trackType)
+{
+ const auto streamIndex = m_media.currentStreamIndex(trackType);
+ if (streamIndex < 0)
+ return {};
+
+ auto &result = m_codecs[trackType];
+
+ if (!result) {
+ qCDebug(qLcPlaybackEngine)
+ << "Create codec for stream:" << streamIndex << "trackType:" << trackType;
+ auto maybeCodec =
+ Codec::create(m_media.avContext()->streams[streamIndex], m_media.avContext());
+
+ if (!maybeCodec) {
+ emit errorOccured(QMediaPlayer::FormatError,
+ "Cannot create codec," + maybeCodec.error());
+ return {};
+ }
+
+ result = maybeCodec.value();
+ }
+
+ return result;
+}
+
+bool PlaybackEngine::hasMediaStream() const
+{
+ return m_renderers[QPlatformMediaPlayer::AudioStream]
+ || m_renderers[QPlatformMediaPlayer::VideoStream];
+}
+
+void PlaybackEngine::createDemuxer()
+{
+ std::array<int, QPlatformMediaPlayer::NTrackTypes> streamIndexes = { -1, -1, -1 };
+
+ bool hasStreams = false;
+ forEachExistingObject<StreamDecoder>([&](auto &stream) {
+ hasStreams = true;
+ const auto trackType = stream->trackType();
+ streamIndexes[trackType] = m_media.currentStreamIndex(trackType);
+ });
+
+ if (!hasStreams)
+ return;
+
+ const PositionWithOffset positionWithOffset{ currentPosition(false), m_currentLoopOffset };
+
+ m_demuxer = createPlaybackEngineObject<Demuxer>(m_media.avContext(), positionWithOffset,
+ streamIndexes, m_loops);
+
+ connect(m_demuxer.get(), &Demuxer::packetsBuffered, this, &PlaybackEngine::buffered);
+
+ forEachExistingObject<StreamDecoder>([&](auto &stream) {
+ connect(m_demuxer.get(), Demuxer::signalByTrackType(stream->trackType()), stream.get(),
+ &StreamDecoder::decode);
+ connect(m_demuxer.get(), &PlaybackEngineObject::atEnd, stream.get(),
+ &StreamDecoder::onFinalPacketReceived);
+ connect(stream.get(), &StreamDecoder::packetProcessed, m_demuxer.get(),
+ &Demuxer::onPacketProcessed);
+ });
+
+ if (!isSeekable() || duration() <= 0) {
+ // We need initial synchronization for such streams
+ forEachExistingObject([&](auto &object) {
+ using Type = std::remove_reference_t<decltype(*object)>;
+ if constexpr (!std::is_same_v<Type, Demuxer>)
+ connect(m_demuxer.get(), &Demuxer::firstPacketFound, object.get(),
+ &Type::setInitialPosition);
+ });
+
+ auto updateTimeController = [this](TimeController::TimePoint tp, qint64 pos) {
+ m_timeController.sync(tp, pos);
+ };
+
+ connect(m_demuxer.get(), &Demuxer::firstPacketFound, this, updateTimeController);
+ }
+}
+
+void PlaybackEngine::deleteFreeThreads() {
+ m_threadsDirty = false;
+ auto freeThreads = std::move(m_threads);
+
+ forEachExistingObject([&](auto &object) {
+ m_threads.insert(freeThreads.extract(objectThreadName(*object)));
+ });
+
+ for (auto &[name, thr] : freeThreads)
+ thr->quit();
+
+ for (auto &[name, thr] : freeThreads)
+ thr->wait();
+}
+
+void PlaybackEngine::setMedia(MediaDataHolder media)
+{
+ Q_ASSERT(!m_media.avContext()); // Playback engine does not support reloading media
+ Q_ASSERT(m_state == QMediaPlayer::StoppedState);
+ Q_ASSERT(m_threads.empty());
+
+ m_media = std::move(media);
+ updateVideoSinkSize();
+}
+
+void PlaybackEngine::setVideoSink(QVideoSink *sink)
+{
+ auto prev = std::exchange(m_videoSink, sink);
+ if (prev == sink)
+ return;
+
+ updateVideoSinkSize(prev);
+ updateActiveVideoOutput(sink);
+
+ if (!sink || !prev) {
+ // might need some improvements
+ forceUpdate();
+ }
+}
+
+void PlaybackEngine::setAudioSink(QPlatformAudioOutput *output) {
+ setAudioSink(output ? output->q : nullptr);
+}
+
+void PlaybackEngine::setAudioSink(QAudioOutput *output)
+{
+ QAudioOutput *prev = std::exchange(m_audioOutput, output);
+ if (prev == output)
+ return;
+
+ updateActiveAudioOutput(output);
+
+ if (!output || !prev) {
+ // might need some improvements
+ forceUpdate();
+ }
+}
+
+void PlaybackEngine::setAudioBufferOutput(QAudioBufferOutput *output)
+{
+ QAudioBufferOutput *prev = std::exchange(m_audioBufferOutput, output);
+ if (prev == output)
+ return;
+ updateActiveAudioOutput(output);
+}
+
+qint64 PlaybackEngine::currentPosition(bool topPos) const {
+ std::optional<qint64> pos;
+
+ for (size_t i = 0; i < m_renderers.size(); ++i) {
+ const auto &renderer = m_renderers[i];
+ if (!renderer)
+ continue;
+
+ // skip subtitle stream for finding lower rendering position
+ if (!topPos && i == QPlatformMediaPlayer::SubtitleStream && hasMediaStream())
+ continue;
+
+ const auto rendererPos = renderer->lastPosition();
+ pos = !pos ? rendererPos
+ : topPos ? std::max(*pos, rendererPos)
+ : std::min(*pos, rendererPos);
+ }
+
+ if (!pos)
+ pos = m_timeController.currentPosition();
+
+ return boundPosition(*pos - m_currentLoopOffset.pos);
+}
+
+qint64 PlaybackEngine::duration() const
+{
+ return m_media.duration();
+}
+
+bool PlaybackEngine::isSeekable() const { return m_media.isSeekable(); }
+
+const QList<MediaDataHolder::StreamInfo> &
+PlaybackEngine::streamInfo(QPlatformMediaPlayer::TrackType trackType) const
+{
+ return m_media.streamInfo(trackType);
+}
+
+const QMediaMetaData &PlaybackEngine::metaData() const
+{
+ return m_media.metaData();
+}
+
+int PlaybackEngine::activeTrack(QPlatformMediaPlayer::TrackType type) const
+{
+ return m_media.activeTrack(type);
+}
+
+void PlaybackEngine::setActiveTrack(QPlatformMediaPlayer::TrackType trackType, int streamNumber)
+{
+ if (!m_media.setActiveTrack(trackType, streamNumber))
+ return;
+
+ m_codecs[trackType] = {};
+
+ m_renderers[trackType].reset();
+ m_streams = defaultObjectsArray<decltype(m_streams)>();
+ m_demuxer.reset();
+
+ updateVideoSinkSize();
+ createObjectsIfNeeded();
+ updateObjectsPausedState();
+}
+
+void PlaybackEngine::finilizeTime(qint64 pos)
+{
+ Q_ASSERT(pos >= 0 && pos <= duration());
+
+ m_timeController.setPaused(true);
+ m_timeController.sync(pos);
+ m_currentLoopOffset = {};
+}
+
+void PlaybackEngine::finalizeOutputs()
+{
+ if (m_audioBufferOutput)
+ updateActiveAudioOutput(static_cast<QAudioBufferOutput *>(nullptr));
+ if (m_audioOutput)
+ updateActiveAudioOutput(static_cast<QAudioOutput *>(nullptr));
+ updateActiveVideoOutput(nullptr, true);
+}
+
+bool PlaybackEngine::hasRenderer(quint64 id) const
+{
+ return std::any_of(m_renderers.begin(), m_renderers.end(),
+ [id](auto &renderer) { return renderer && renderer->id() == id; });
+}
+
+template <typename AudioOutput>
+void PlaybackEngine::updateActiveAudioOutput(AudioOutput *output)
+{
+ if (auto renderer =
+ qobject_cast<AudioRenderer *>(m_renderers[QPlatformMediaPlayer::AudioStream].get()))
+ renderer->setOutput(output);
+}
+
+void PlaybackEngine::updateActiveVideoOutput(QVideoSink *sink, bool cleanOutput)
+{
+ if (auto renderer = qobject_cast<SubtitleRenderer *>(
+ m_renderers[QPlatformMediaPlayer::SubtitleStream].get()))
+ renderer->setOutput(sink, cleanOutput);
+ if (auto renderer =
+ qobject_cast<VideoRenderer *>(m_renderers[QPlatformMediaPlayer::VideoStream].get()))
+ renderer->setOutput(sink, cleanOutput);
+}
+
+void PlaybackEngine::updateVideoSinkSize(QVideoSink *prevSink)
+{
+ auto platformVideoSink = m_videoSink ? m_videoSink->platformVideoSink() : nullptr;
+ if (!platformVideoSink)
+ return;
+
+ if (prevSink && prevSink->platformVideoSink())
+ platformVideoSink->setNativeSize(prevSink->platformVideoSink()->nativeSize());
+ else {
+ const auto streamIndex = m_media.currentStreamIndex(QPlatformMediaPlayer::VideoStream);
+ if (streamIndex >= 0) {
+ const auto context = m_media.avContext();
+ const auto stream = context->streams[streamIndex];
+ const AVRational pixelAspectRatio =
+ av_guess_sample_aspect_ratio(context, stream, nullptr);
+ // auto size = metaData().value(QMediaMetaData::Resolution)
+ const QSize size =
+ qCalculateFrameSize({ stream->codecpar->width, stream->codecpar->height },
+ { pixelAspectRatio.num, pixelAspectRatio.den });
+
+ platformVideoSink->setNativeSize(qRotatedFrameSize(size, m_media.rotation()));
+ }
+ }
+}
+
+qint64 PlaybackEngine::boundPosition(qint64 position) const
+{
+ position = qMax(position, 0);
+ return duration() > 0 ? qMin(position, duration()) : position;
+}
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegplaybackengine_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegplaybackengine_p.h b/src/plugins/multimedia/ffmpeg/qffmpegplaybackengine_p.h
new file mode 100644
index 000000000..50c94c955
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegplaybackengine_p.h
@@ -0,0 +1,234 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGPLAYBACKENGINE_P_H
+#define QFFMPEGPLAYBACKENGINE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+/* Playback engine design description.
+ *
+ *
+ * PLAYBACK ENGINE OBJECTS
+ *
+ * - Playback engine manages 7 objects inside, each one works in a separate thread.
+ * Each object inherits PlaybackEngineObject. The objects are:
+ * Demuxer
+ * Stream Decoders: audio, video, subtitles
+ * Renderers: audio, video, subtitles
+ *
+ *
+ * THREADS:
+ *
+ * - By default, each object works in a separate thread. It's easy to reconfigure
+ * to using several objects in thread.
+ * - New thread is allocated if a new object is created and the engine doesn't
+ * have free threads. If it does, the thread is to be reused.
+ * - If all objects for some thread are deleted, the thread becomes free and the engine
+ * postpones its termination.
+ *
+ * OBJECTS WEAK CONNECTIVITY
+ *
+ * - The objects know nothing about others and about PlaybackEngine.
+ * For any interactions the objects use slots/signals.
+ *
+ * - PlaybackEngine knows the objects object and is able to create/delete them and
+ * call their public methods.
+ *
+ */
+
+#include "playbackengine/qffmpegplaybackenginedefs_p.h"
+#include "playbackengine/qffmpegtimecontroller_p.h"
+#include "playbackengine/qffmpegmediadataholder_p.h"
+#include "playbackengine/qffmpegcodec_p.h"
+#include "playbackengine/qffmpegpositionwithoffset_p.h"
+
+#include <QtCore/qpointer.h>
+
+#include <unordered_map>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioSink;
+class QVideoSink;
+class QAudioOutput;
+class QAudioBufferOutput;
+class QFFmpegMediaPlayer;
+
+namespace QFFmpeg
+{
+
+class PlaybackEngine : public QObject
+{
+ Q_OBJECT
+public:
+ PlaybackEngine();
+
+ ~PlaybackEngine() override;
+
+ void setMedia(MediaDataHolder media);
+
+ void setVideoSink(QVideoSink *sink);
+
+ void setAudioSink(QAudioOutput *output);
+
+ void setAudioSink(QPlatformAudioOutput *output);
+
+ void setAudioBufferOutput(QAudioBufferOutput *output);
+
+ void setState(QMediaPlayer::PlaybackState state);
+
+ void play() {
+ setState(QMediaPlayer::PlayingState);
+ }
+ void pause() {
+ setState(QMediaPlayer::PausedState);
+ }
+ void stop() {
+ setState(QMediaPlayer::StoppedState);
+ }
+
+ void seek(qint64 pos);
+
+ void setLoops(int loopsCount);
+
+ void setPlaybackRate(float rate);
+
+ float playbackRate() const;
+
+ void setActiveTrack(QPlatformMediaPlayer::TrackType type, int streamNumber);
+
+ qint64 currentPosition(bool topPos = true) const;
+
+ qint64 duration() const;
+
+ bool isSeekable() const;
+
+ const QList<MediaDataHolder::StreamInfo> &
+ streamInfo(QPlatformMediaPlayer::TrackType trackType) const;
+
+ const QMediaMetaData &metaData() const;
+
+ int activeTrack(QPlatformMediaPlayer::TrackType type) const;
+
+signals:
+ void endOfStream();
+ void errorOccured(int, const QString &);
+ void loopChanged();
+ void buffered();
+
+protected: // objects managing
+ struct ObjectDeleter
+ {
+ void operator()(PlaybackEngineObject *) const;
+
+ PlaybackEngine *engine = nullptr;
+ };
+
+ template<typename T>
+ using ObjectPtr = std::unique_ptr<T, ObjectDeleter>;
+
+ using RendererPtr = ObjectPtr<Renderer>;
+ using StreamPtr = ObjectPtr<StreamDecoder>;
+
+ template<typename T, typename... Args>
+ ObjectPtr<T> createPlaybackEngineObject(Args &&...args);
+
+ virtual RendererPtr createRenderer(QPlatformMediaPlayer::TrackType trackType);
+
+ template <typename AudioOutput>
+ void updateActiveAudioOutput(AudioOutput *output);
+
+ void updateActiveVideoOutput(QVideoSink *sink, bool cleanOutput = false);
+
+private:
+ void createStreamAndRenderer(QPlatformMediaPlayer::TrackType trackType);
+
+ void createDemuxer();
+
+ void registerObject(PlaybackEngineObject &object);
+
+ template<typename C, typename Action>
+ void forEachExistingObject(Action &&action);
+
+ template<typename Action>
+ void forEachExistingObject(Action &&action);
+
+ void forceUpdate();
+
+ void recreateObjects();
+
+ void createObjectsIfNeeded();
+
+ void updateObjectsPausedState();
+
+ void deleteFreeThreads();
+
+ void onRendererSynchronized(quint64 id, std::chrono::steady_clock::time_point time,
+ qint64 trackTime);
+
+ void onRendererFinished();
+
+ void onRendererLoopChanged(quint64 id, qint64 offset, int loopIndex);
+
+ void triggerStepIfNeeded();
+
+ static QString objectThreadName(const PlaybackEngineObject &object);
+
+ std::optional<Codec> codecForTrack(QPlatformMediaPlayer::TrackType trackType);
+
+ bool hasMediaStream() const;
+
+ void finilizeTime(qint64 pos);
+
+ void finalizeOutputs();
+
+ bool hasRenderer(quint64 id) const;
+
+ void updateVideoSinkSize(QVideoSink *prevSink = nullptr);
+
+ qint64 boundPosition(qint64 position) const;
+
+private:
+ MediaDataHolder m_media;
+
+ TimeController m_timeController;
+
+ std::unordered_map<QString, std::unique_ptr<QThread>> m_threads;
+ bool m_threadsDirty = false;
+
+ QPointer<QVideoSink> m_videoSink;
+ QPointer<QAudioOutput> m_audioOutput;
+ QPointer<QAudioBufferOutput> m_audioBufferOutput;
+
+ QMediaPlayer::PlaybackState m_state = QMediaPlayer::StoppedState;
+
+ ObjectPtr<Demuxer> m_demuxer;
+ std::array<StreamPtr, QPlatformMediaPlayer::NTrackTypes> m_streams;
+ std::array<RendererPtr, QPlatformMediaPlayer::NTrackTypes> m_renderers;
+
+ std::array<std::optional<Codec>, QPlatformMediaPlayer::NTrackTypes> m_codecs;
+ int m_loops = QMediaPlayer::Once;
+ LoopOffset m_currentLoopOffset;
+};
+
+template<typename T, typename... Args>
+PlaybackEngine::ObjectPtr<T> PlaybackEngine::createPlaybackEngineObject(Args &&...args)
+{
+ auto result = ObjectPtr<T>(new T(std::forward<Args>(args)...), { this });
+ registerObject(*result);
+ return result;
+}
+}
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGPLAYBACKENGINE_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegresampler.cpp b/src/plugins/multimedia/ffmpeg/qffmpegresampler.cpp
new file mode 100644
index 000000000..141a6ade2
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegresampler.cpp
@@ -0,0 +1,112 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qffmpegresampler_p.h"
+#include "playbackengine/qffmpegcodec_p.h"
+#include "qffmpegmediaformatinfo_p.h"
+#include <qloggingcategory.h>
+
+static Q_LOGGING_CATEGORY(qLcResampler, "qt.multimedia.ffmpeg.resampler")
+
+QT_BEGIN_NAMESPACE
+
+using namespace QFFmpeg;
+
+QFFmpegResampler::QFFmpegResampler(const QAudioFormat &inputFormat, const QAudioFormat &outputFormat) :
+ m_inputFormat(inputFormat), m_outputFormat(outputFormat)
+{
+ Q_ASSERT(inputFormat.isValid());
+ Q_ASSERT(outputFormat.isValid());
+
+ m_resampler =
+ createResampleContext(AVAudioFormat(m_inputFormat), AVAudioFormat(m_outputFormat));
+}
+
+QFFmpegResampler::QFFmpegResampler(const Codec *codec, const QAudioFormat &outputFormat,
+ qint64 startTime)
+ : m_outputFormat(outputFormat), m_startTime(startTime)
+{
+ Q_ASSERT(codec);
+
+ qCDebug(qLcResampler) << "createResampler";
+ const AVStream *audioStream = codec->stream();
+
+ if (!m_outputFormat.isValid())
+ // want the native format
+ m_outputFormat = QFFmpegMediaFormatInfo::audioFormatFromCodecParameters(audioStream->codecpar);
+
+ m_resampler = createResampleContext(AVAudioFormat(audioStream->codecpar),
+ AVAudioFormat(m_outputFormat));
+}
+
+QFFmpegResampler::~QFFmpegResampler() = default;
+
+QAudioBuffer QFFmpegResampler::resample(const char* data, size_t size)
+{
+ if (!m_inputFormat.isValid())
+ return {};
+
+ return resample(reinterpret_cast<const uint8_t **>(&data),
+ m_inputFormat.framesForBytes(static_cast<qint32>(size)));
+}
+
+QAudioBuffer QFFmpegResampler::resample(const AVFrame *frame)
+{
+ return resample(const_cast<const uint8_t **>(frame->extended_data), frame->nb_samples);
+}
+
+QAudioBuffer QFFmpegResampler::resample(const uint8_t **inputData, int inputSamplesCount)
+{
+ const int maxOutSamples = adjustMaxOutSamples(inputSamplesCount);
+
+ QByteArray samples(m_outputFormat.bytesForFrames(maxOutSamples), Qt::Uninitialized);
+ auto *out = reinterpret_cast<uint8_t *>(samples.data());
+ const int outSamples =
+ swr_convert(m_resampler.get(), &out, maxOutSamples, inputData, inputSamplesCount);
+
+ samples.resize(m_outputFormat.bytesForFrames(outSamples));
+
+ const qint64 startTime = m_outputFormat.durationForFrames(m_samplesProcessed) + m_startTime;
+ m_samplesProcessed += outSamples;
+
+ qCDebug(qLcResampler) << " new frame" << startTime << "in_samples" << inputSamplesCount
+ << outSamples << maxOutSamples;
+ return QAudioBuffer(samples, m_outputFormat, startTime);
+}
+
+int QFFmpegResampler::adjustMaxOutSamples(int inputSamplesCount)
+{
+ int maxOutSamples = swr_get_out_samples(m_resampler.get(), inputSamplesCount);
+
+ const auto remainingCompensationDistance = m_endCompensationSample - m_samplesProcessed;
+
+ if (remainingCompensationDistance > 0 && maxOutSamples > remainingCompensationDistance) {
+ // If the remaining compensation distance less than output frame,
+ // the ffmpeg resampler bufferises the rest of frames that makes
+ // unexpected delays on large frames.
+ // The hack might cause some compensation bias on large frames,
+ // however it's not significant for our logic, in fact.
+ // TODO: probably, it will need some improvements
+ setSampleCompensation(0, 0);
+ maxOutSamples = swr_get_out_samples(m_resampler.get(), inputSamplesCount);
+ }
+
+ return maxOutSamples;
+}
+
+void QFFmpegResampler::setSampleCompensation(qint32 delta, quint32 distance)
+{
+ const int res = swr_set_compensation(m_resampler.get(), delta, static_cast<int>(distance));
+ if (res < 0)
+ qCWarning(qLcResampler) << "swr_set_compensation fail:" << res;
+ else {
+ m_sampleCompensationDelta = delta;
+ m_endCompensationSample = m_samplesProcessed + distance;
+ }
+}
+
+qint32 QFFmpegResampler::activeSampleCompensationDelta() const
+{
+ return m_samplesProcessed < m_endCompensationSample ? m_sampleCompensationDelta : 0;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegresampler_p.h b/src/plugins/multimedia/ffmpeg/qffmpegresampler_p.h
new file mode 100644
index 000000000..530f40aa2
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegresampler_p.h
@@ -0,0 +1,62 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGRESAMPLER_P_H
+#define QFFMPEGRESAMPLER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qaudiobuffer.h"
+#include "qffmpeg_p.h"
+#include "private/qplatformaudioresampler_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg
+{
+class Codec;
+}
+
+class QFFmpegResampler : public QPlatformAudioResampler
+{
+public:
+ QFFmpegResampler(const QAudioFormat &inputFormat, const QAudioFormat &outputFormat);
+ QFFmpegResampler(const QFFmpeg::Codec *codec, const QAudioFormat &outputFormat,
+ qint64 startTime = 0);
+
+ ~QFFmpegResampler() override;
+
+ QAudioBuffer resample(const char* data, size_t size) override;
+
+ QAudioBuffer resample(const AVFrame *frame);
+
+ qint64 samplesProcessed() const { return m_samplesProcessed; }
+ void setSampleCompensation(qint32 delta, quint32 distance);
+ qint32 activeSampleCompensationDelta() const;
+
+private:
+ int adjustMaxOutSamples(int inputSamplesCount);
+
+ QAudioBuffer resample(const uint8_t **inputData, int inputSamplesCount);
+
+private:
+ QAudioFormat m_inputFormat;
+ QAudioFormat m_outputFormat;
+ qint64 m_startTime = 0;
+ QFFmpeg::SwrContextUPtr m_resampler;
+ qint64 m_samplesProcessed = 0;
+ qint64 m_endCompensationSample = std::numeric_limits<qint64>::min();
+ qint32 m_sampleCompensationDelta = 0;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp b/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp
new file mode 100644
index 000000000..feab39697
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp
@@ -0,0 +1,467 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegscreencapture_dxgi_p.h"
+#include "qffmpegsurfacecapturegrabber_p.h"
+#include "qabstractvideobuffer.h"
+#include <private/qmultimediautils_p.h>
+#include <private/qwindowsmultimediautils_p.h>
+#include <private/qvideoframe_p.h>
+#include <qtgui/qscreen_platform.h>
+#include "qvideoframe.h"
+
+#include <qloggingcategory.h>
+#include <qwaitcondition.h>
+#include <qmutex.h>
+
+#include "D3d11.h"
+#include "dxgi1_2.h"
+
+#include <system_error>
+#include <thread>
+#include <chrono>
+
+#include <mutex> // std::scoped_lock
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcScreenCaptureDxgi, "qt.multimedia.ffmpeg.screencapturedxgi")
+
+using namespace std::chrono;
+using namespace QWindowsMultimediaUtils;
+using namespace Qt::StringLiterals;
+
+namespace {
+
+// Convenience wrapper that combines an HRESULT
+// status code with an optional textual description.
+class ComStatus
+{
+public:
+ ComStatus() = default;
+ ComStatus(HRESULT hr) : m_hr{ hr } { }
+ ComStatus(HRESULT hr, QAnyStringView msg) : m_hr{ hr }, m_msg{ msg.toString() } { }
+
+ ComStatus(const ComStatus &) = default;
+ ComStatus(ComStatus &&) = default;
+ ComStatus &operator=(const ComStatus &) = default;
+ ComStatus &operator=(ComStatus &&) = default;
+
+ explicit operator bool() const { return m_hr == S_OK; }
+
+ HRESULT code() const { return m_hr; }
+ QString str() const
+ {
+ if (!m_msg)
+ return errorString(m_hr);
+ return *m_msg + " " + errorString(m_hr);
+ }
+
+private:
+ HRESULT m_hr = S_OK;
+ std::optional<QString> m_msg;
+};
+
+template <typename T>
+using ComProduct = QMaybe<ComPtr<T>, ComStatus>;
+
+}
+
+class QD3D11TextureVideoBuffer : public QAbstractVideoBuffer
+{
+public:
+ QD3D11TextureVideoBuffer(const ComPtr<ID3D11Device> &device, std::shared_ptr<QMutex> &mutex,
+ const ComPtr<ID3D11Texture2D> &texture, QSize size)
+ : m_device(device), m_texture(texture), m_ctxMutex(mutex), m_size(size)
+ {}
+
+ ~QD3D11TextureVideoBuffer()
+ {
+ QD3D11TextureVideoBuffer::unmap();
+ }
+
+ MapData map(QtVideo::MapMode mode) override
+ {
+ MapData mapData;
+ if (!m_ctx && mode == QtVideo::MapMode::ReadOnly) {
+ D3D11_TEXTURE2D_DESC texDesc = {};
+ m_texture->GetDesc(&texDesc);
+ texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
+ texDesc.Usage = D3D11_USAGE_STAGING;
+ texDesc.MiscFlags = 0;
+ texDesc.BindFlags = 0;
+
+ HRESULT hr = m_device->CreateTexture2D(&texDesc, nullptr, m_cpuTexture.GetAddressOf());
+ if (FAILED(hr)) {
+ qCDebug(qLcScreenCaptureDxgi) << "Failed to create texture with CPU access"
+ << std::system_category().message(hr).c_str();
+ qCDebug(qLcScreenCaptureDxgi) << m_device->GetDeviceRemovedReason();
+ return {};
+ }
+
+ m_device->GetImmediateContext(m_ctx.GetAddressOf());
+ m_ctxMutex->lock();
+ m_ctx->CopyResource(m_cpuTexture.Get(), m_texture.Get());
+
+ D3D11_MAPPED_SUBRESOURCE resource = {};
+ hr = m_ctx->Map(m_cpuTexture.Get(), 0, D3D11_MAP_READ, 0, &resource);
+ m_ctxMutex->unlock();
+ if (FAILED(hr)) {
+ qCDebug(qLcScreenCaptureDxgi) << "Failed to map texture" << m_cpuTexture.Get()
+ << std::system_category().message(hr).c_str();
+ return {};
+ }
+
+ m_mapMode = mode;
+ mapData.planeCount = 1;
+ mapData.bytesPerLine[0] = int(resource.RowPitch);
+ mapData.data[0] = reinterpret_cast<uchar*>(resource.pData);
+ mapData.dataSize[0] = m_size.height() * int(resource.RowPitch);
+ }
+
+ return mapData;
+ }
+
+ void unmap() override
+ {
+ if (m_mapMode == QtVideo::MapMode::NotMapped)
+ return;
+ if (m_ctx) {
+ m_ctxMutex->lock();
+ m_ctx->Unmap(m_cpuTexture.Get(), 0);
+ m_ctxMutex->unlock();
+ m_ctx.Reset();
+ }
+ m_cpuTexture.Reset();
+ m_mapMode = QtVideo::MapMode::NotMapped;
+ }
+
+ QVideoFrameFormat format() const override { return {}; }
+
+ QSize getSize() const
+ {
+ if (!m_texture)
+ return {};
+
+ D3D11_TEXTURE2D_DESC desc{};
+ m_texture->GetDesc(&desc);
+
+ return { static_cast<int>(desc.Width), static_cast<int>(desc.Height) };
+ }
+
+private:
+ ComPtr<ID3D11Device> m_device;
+ ComPtr<ID3D11Texture2D> m_texture;
+ ComPtr<ID3D11Texture2D> m_cpuTexture;
+ ComPtr<ID3D11DeviceContext> m_ctx;
+ std::shared_ptr<QMutex> m_ctxMutex;
+ QSize m_size;
+ QtVideo::MapMode m_mapMode = QtVideo::MapMode::NotMapped;
+};
+
+namespace {
+class DxgiDuplication
+{
+ struct DxgiScreen
+ {
+ ComPtr<IDXGIAdapter1> adapter;
+ ComPtr<IDXGIOutput> output;
+ };
+
+public:
+ ~DxgiDuplication()
+ {
+ if (m_releaseFrame)
+ m_dup->ReleaseFrame();
+ }
+
+ ComStatus initialize(QScreen const *screen)
+ {
+ const QMaybe<DxgiScreen, ComStatus> dxgiScreen = findDxgiScreen(screen);
+ if (!dxgiScreen)
+ return dxgiScreen.error();
+
+ const ComPtr<IDXGIAdapter1> adapter = dxgiScreen->adapter;
+
+ ComPtr<ID3D11Device> d3d11dev;
+ HRESULT hr =
+ D3D11CreateDevice(adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, 0, nullptr, 0,
+ D3D11_SDK_VERSION, d3d11dev.GetAddressOf(), nullptr, nullptr);
+ if (FAILED(hr))
+ return { hr, "Failed to create ID3D11Device device"_L1 };
+
+ ComPtr<IDXGIOutput1> output;
+ hr = dxgiScreen->output.As(&output);
+ if (FAILED(hr))
+ return { hr, "Failed to create IDXGIOutput1"_L1 };
+
+ ComPtr<IDXGIOutputDuplication> dup;
+ hr = output->DuplicateOutput(d3d11dev.Get(), dup.GetAddressOf());
+ if (FAILED(hr))
+ return { hr, "Failed to duplicate IDXGIOutput1"_L1 };
+
+ m_adapter = dxgiScreen->adapter;
+ m_output = output;
+ m_device = d3d11dev;
+ m_dup = dup;
+ return { S_OK };
+ }
+
+ bool valid() const { return m_dup != nullptr; }
+
+ QSize getFrameSize() const
+ {
+ DXGI_OUTDUPL_DESC outputDesc = {};
+ m_dup->GetDesc(&outputDesc);
+
+ return { static_cast<int>(outputDesc.ModeDesc.Width),
+ static_cast<int>(outputDesc.ModeDesc.Height) };
+ }
+
+ QMaybe<std::unique_ptr<QD3D11TextureVideoBuffer>, ComStatus> getNextVideoFrame()
+ {
+ const ComProduct<ID3D11Texture2D> texture = getNextFrame();
+
+ if (!texture)
+ return texture.error();
+
+ return std::make_unique<QD3D11TextureVideoBuffer>(m_device, m_ctxMutex, *texture,
+ getFrameSize());
+ }
+
+private:
+ ComProduct<ID3D11Texture2D> getNextFrame()
+ {
+ std::scoped_lock guard{ *m_ctxMutex };
+
+ if (m_releaseFrame) {
+ m_releaseFrame = false;
+
+ HRESULT hr = m_dup->ReleaseFrame();
+
+ if (hr != S_OK)
+ return ComStatus{ hr, "Failed to release duplication frame."_L1 };
+ }
+
+ ComPtr<IDXGIResource> frame;
+ DXGI_OUTDUPL_FRAME_INFO info;
+
+ HRESULT hr = m_dup->AcquireNextFrame(0, &info, frame.GetAddressOf());
+
+ if (hr != S_OK)
+ return { unexpect, hr, "Failed to grab the screen content"_L1 };
+
+ m_releaseFrame = true;
+
+ ComPtr<ID3D11Texture2D> tex;
+ hr = frame.As(&tex);
+ if (hr != S_OK)
+ return { unexpect, hr, "Failed to obtain D3D11 texture"_L1 };
+
+ D3D11_TEXTURE2D_DESC texDesc = {};
+ tex->GetDesc(&texDesc);
+ texDesc.MiscFlags = 0;
+ texDesc.BindFlags = 0;
+
+ ComPtr<ID3D11Texture2D> texCopy;
+ hr = m_device->CreateTexture2D(&texDesc, nullptr, texCopy.GetAddressOf());
+ if (hr != S_OK)
+ return { unexpect, hr, "Failed to create texture with CPU access"_L1 };
+
+ ComPtr<ID3D11DeviceContext> ctx;
+ m_device->GetImmediateContext(ctx.GetAddressOf());
+ ctx->CopyResource(texCopy.Get(), tex.Get());
+
+ return texCopy;
+ }
+
+ static QMaybe<DxgiScreen, ComStatus> findDxgiScreen(const QScreen *screen)
+ {
+ if (!screen)
+ return { unexpect, E_FAIL, "Cannot find nullptr screen"_L1 };
+
+ auto *winScreen = screen->nativeInterface<QNativeInterface::QWindowsScreen>();
+ HMONITOR handle = winScreen ? winScreen->handle() : nullptr;
+
+ ComPtr<IDXGIFactory1> factory;
+ HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&factory));
+ if (FAILED(hr))
+ return { unexpect, hr, "Failed to create IDXGIFactory"_L1 };
+
+ ComPtr<IDXGIAdapter1> adapter;
+ for (quint32 i = 0; factory->EnumAdapters1(i, adapter.ReleaseAndGetAddressOf()) == S_OK; i++) {
+ ComPtr<IDXGIOutput> output;
+ for (quint32 j = 0; adapter->EnumOutputs(j, output.ReleaseAndGetAddressOf()) == S_OK; ++j) {
+ DXGI_OUTPUT_DESC desc = {};
+ output->GetDesc(&desc);
+ qCDebug(qLcScreenCaptureDxgi) << i << j << QString::fromWCharArray(desc.DeviceName);
+ auto match = handle ? handle == desc.Monitor
+ : QString::fromWCharArray(desc.DeviceName) == screen->name();
+ if (match)
+ return DxgiScreen{ adapter, output };
+ }
+ }
+ return { unexpect, DXGI_ERROR_NOT_FOUND,
+ "Could not find screen adapter "_L1 + screen->name() };
+ }
+
+ ComPtr<IDXGIAdapter1> m_adapter;
+ ComPtr<IDXGIOutput> m_output;
+ ComPtr<ID3D11Device> m_device;
+ ComPtr<IDXGIOutputDuplication> m_dup;
+ bool m_releaseFrame = false;
+ std::shared_ptr<QMutex> m_ctxMutex = std::make_shared<QMutex>();
+};
+
+QSize getPhysicalSizePixels(const QScreen *screen)
+{
+ const auto *winScreen = screen->nativeInterface<QNativeInterface::QWindowsScreen>();
+ if (!winScreen)
+ return {};
+
+ const HMONITOR handle = winScreen->handle();
+ if (!handle)
+ return {};
+
+ MONITORINFO info{};
+ info.cbSize = sizeof(info);
+
+ if (!GetMonitorInfoW(handle, &info))
+ return {};
+
+ return { info.rcMonitor.right - info.rcMonitor.left,
+ info.rcMonitor.bottom - info.rcMonitor.top };
+}
+
+QVideoFrameFormat getFrameFormat(QScreen* screen)
+{
+ const QSize screenSize = getPhysicalSizePixels(screen);
+
+ QVideoFrameFormat format = { screenSize, QVideoFrameFormat::Format_BGRA8888 };
+ format.setStreamFrameRate(static_cast<int>(screen->refreshRate()));
+
+ return format;
+}
+
+} // namespace
+
+class QFFmpegScreenCaptureDxgi::Grabber : public QFFmpegSurfaceCaptureGrabber
+{
+public:
+ Grabber(QFFmpegScreenCaptureDxgi &screenCapture, QScreen *screen,
+ const QVideoFrameFormat &format)
+ : m_screen(screen)
+ , m_format(format)
+ {
+ setFrameRate(screen->refreshRate());
+ addFrameCallback(screenCapture, &QFFmpegScreenCaptureDxgi::newVideoFrame);
+ connect(this, &Grabber::errorUpdated, &screenCapture, &QFFmpegScreenCaptureDxgi::updateError);
+ }
+
+ ~Grabber() {
+ stop();
+ }
+
+ QVideoFrameFormat format() {
+ return m_format;
+ }
+
+ QVideoFrame grabFrame() override
+ {
+ QVideoFrame frame;
+ if (!m_duplication.valid()) {
+ const ComStatus status = m_duplication.initialize(m_screen);
+ if (!status) {
+ if (status.code() == E_ACCESSDENIED) {
+ // May occur for some time after pushing Ctrl+Alt+Del.
+ updateError(QPlatformSurfaceCapture::NoError, status.str());
+ qCWarning(qLcScreenCaptureDxgi) << status.str();
+ }
+ return frame;
+ }
+ }
+
+ auto maybeBuf = m_duplication.getNextVideoFrame();
+ const ComStatus &status = maybeBuf.error();
+
+ if (status.code() == DXGI_ERROR_WAIT_TIMEOUT) {
+ // All is good, we just didn't get a new frame yet
+ updateError(QPlatformSurfaceCapture::NoError, status.str());
+ } else if (status.code() == DXGI_ERROR_ACCESS_LOST) {
+ // Can happen for example when pushing Ctrl + Alt + Del
+ m_duplication = {};
+ updateError(QPlatformSurfaceCapture::NoError, status.str());
+ qCWarning(qLcScreenCaptureDxgi) << status.str();
+ } else if (!status) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed, status.str());
+ qCWarning(qLcScreenCaptureDxgi) << status.str();
+ } else if (maybeBuf) {
+ std::unique_ptr<QD3D11TextureVideoBuffer> buffer = std::move(*maybeBuf);
+
+ const QSize bufSize = buffer->getSize();
+ if (bufSize != m_format.frameSize())
+ m_format.setFrameSize(bufSize);
+
+ frame = QVideoFramePrivate::createFrame(std::move(buffer), format());
+ }
+
+ return frame;
+ }
+
+ protected:
+ void initializeGrabbingContext() override
+ {
+ m_duplication = DxgiDuplication();
+ const ComStatus status = m_duplication.initialize(m_screen);
+ if (!status) {
+ updateError(CaptureFailed, status.str());
+ return;
+ }
+
+ QFFmpegSurfaceCaptureGrabber::initializeGrabbingContext();
+ }
+
+private:
+ const QScreen *m_screen = nullptr;
+ QVideoFrameFormat m_format;
+ DxgiDuplication m_duplication;
+};
+
+QFFmpegScreenCaptureDxgi::QFFmpegScreenCaptureDxgi() : QPlatformSurfaceCapture(ScreenSource{}) { }
+
+QFFmpegScreenCaptureDxgi::~QFFmpegScreenCaptureDxgi() = default;
+
+QVideoFrameFormat QFFmpegScreenCaptureDxgi::frameFormat() const
+{
+ if (m_grabber)
+ return m_grabber->format();
+ return {};
+}
+
+bool QFFmpegScreenCaptureDxgi::setActiveInternal(bool active)
+{
+ if (static_cast<bool>(m_grabber) == active)
+ return true;
+
+ if (m_grabber) {
+ m_grabber.reset();
+ } else {
+ auto screen = source<ScreenSource>();
+
+ if (!checkScreenWithError(screen))
+ return false;
+
+ const QVideoFrameFormat format = getFrameFormat(screen);
+ if (!format.isValid()) {
+ updateError(NotFound, QLatin1String("Unable to determine screen size or format"));
+ return false;
+ }
+
+ m_grabber.reset(new Grabber(*this, screen, format));
+ m_grabber->start();
+ }
+
+ return true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi_p.h b/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi_p.h
new file mode 100644
index 000000000..8f866b135
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi_p.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGSCREENCAPTURE_WINDOWS_H
+#define QFFMPEGSCREENCAPTURE_WINDOWS_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qvideoframeformat.h"
+#include <private/qcomptr_p.h>
+#include <private/qplatformsurfacecapture_p.h>
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegScreenCaptureDxgi : public QPlatformSurfaceCapture
+{
+public:
+ explicit QFFmpegScreenCaptureDxgi();
+
+ ~QFFmpegScreenCaptureDxgi() override;
+
+ QVideoFrameFormat frameFormat() const override;
+
+private:
+ bool setActiveInternal(bool active) override;
+
+private:
+ class Grabber;
+ std::unique_ptr<Grabber> m_grabber;
+};
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGSCREENCAPTURE_WINDOWS_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegsurfacecapturegrabber.cpp b/src/plugins/multimedia/ffmpeg/qffmpegsurfacecapturegrabber.cpp
new file mode 100644
index 000000000..f708f5021
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegsurfacecapturegrabber.cpp
@@ -0,0 +1,202 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegsurfacecapturegrabber_p.h"
+
+#include <qelapsedtimer.h>
+#include <qloggingcategory.h>
+#include <qthread.h>
+#include <qtimer.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcScreenCaptureGrabber, "qt.multimedia.ffmpeg.surfacecapturegrabber");
+
+namespace {
+
+class GrabbingProfiler
+{
+public:
+ auto measure()
+ {
+ m_elapsedTimer.start();
+ return qScopeGuard([&]() {
+ const auto nsecsElapsed = m_elapsedTimer.nsecsElapsed();
+ ++m_number;
+ m_wholeTime += nsecsElapsed;
+
+#ifdef DUMP_SCREEN_CAPTURE_PROFILING
+ qDebug() << "screen grabbing time:" << nsecsElapsed << "avg:" << avgTime()
+ << "number:" << m_number;
+#endif
+ });
+ }
+
+ qreal avgTime() const
+ {
+ return m_number ? m_wholeTime / (m_number * 1000000.) : 0.;
+ }
+
+ qint64 number() const
+ {
+ return m_number;
+ }
+
+private:
+ QElapsedTimer m_elapsedTimer;
+ qint64 m_wholeTime = 0;
+ qint64 m_number = 0;
+};
+
+} // namespace
+
+struct QFFmpegSurfaceCaptureGrabber::GrabbingContext
+{
+ GrabbingProfiler profiler;
+ QTimer timer;
+ QElapsedTimer elapsedTimer;
+ qint64 lastFrameTime = 0;
+};
+
+class QFFmpegSurfaceCaptureGrabber::GrabbingThread : public QThread
+{
+public:
+ GrabbingThread(QFFmpegSurfaceCaptureGrabber& grabber)
+ : m_grabber(grabber)
+ {}
+
+protected:
+ void run() override
+ {
+ m_grabber.initializeGrabbingContext();
+
+ if (!m_grabber.isGrabbingContextInitialized())
+ return;
+
+ exec();
+ m_grabber.finalizeGrabbingContext();
+ }
+
+private:
+ QFFmpegSurfaceCaptureGrabber& m_grabber;
+};
+
+QFFmpegSurfaceCaptureGrabber::QFFmpegSurfaceCaptureGrabber(ThreadPolicy threadPolicy)
+{
+ setFrameRate(DefaultScreenCaptureFrameRate);
+
+ if (threadPolicy == CreateGrabbingThread)
+ m_thread = std::make_unique<GrabbingThread>(*this);
+}
+
+void QFFmpegSurfaceCaptureGrabber::start()
+{
+ if (m_thread)
+ m_thread->start();
+ else if (!isGrabbingContextInitialized())
+ initializeGrabbingContext();
+}
+
+QFFmpegSurfaceCaptureGrabber::~QFFmpegSurfaceCaptureGrabber() = default;
+
+void QFFmpegSurfaceCaptureGrabber::setFrameRate(qreal rate)
+{
+ rate = qBound(MinScreenCaptureFrameRate, rate, MaxScreenCaptureFrameRate);
+ if (std::exchange(m_rate, rate) != rate) {
+ qCDebug(qLcScreenCaptureGrabber) << "Screen capture rate has been changed:" << m_rate;
+
+ updateTimerInterval();
+ }
+}
+
+qreal QFFmpegSurfaceCaptureGrabber::frameRate() const
+{
+ return m_rate;
+}
+
+void QFFmpegSurfaceCaptureGrabber::stop()
+{
+ if (m_thread)
+ {
+ m_thread->quit();
+ m_thread->wait();
+ }
+ else if (isGrabbingContextInitialized())
+ {
+ finalizeGrabbingContext();
+ }
+}
+
+void QFFmpegSurfaceCaptureGrabber::updateError(QPlatformSurfaceCapture::Error error,
+ const QString &description)
+{
+ const auto prevError = std::exchange(m_prevError, error);
+
+ if (error != QPlatformSurfaceCapture::NoError
+ || prevError != QPlatformSurfaceCapture::NoError) {
+ emit errorUpdated(error, description);
+ }
+
+ updateTimerInterval();
+}
+
+void QFFmpegSurfaceCaptureGrabber::updateTimerInterval()
+{
+ const qreal rate = m_prevError && *m_prevError != QPlatformSurfaceCapture::NoError
+ ? MinScreenCaptureFrameRate
+ : m_rate;
+ const int interval = static_cast<int>(1000 / rate);
+ if (m_context && m_context->timer.interval() != interval)
+ m_context->timer.setInterval(interval);
+}
+
+void QFFmpegSurfaceCaptureGrabber::initializeGrabbingContext()
+{
+ Q_ASSERT(!isGrabbingContextInitialized());
+ qCDebug(qLcScreenCaptureGrabber) << "screen capture started";
+
+ m_context = std::make_unique<GrabbingContext>();
+ m_context->timer.setTimerType(Qt::PreciseTimer);
+ updateTimerInterval();
+
+ m_context->elapsedTimer.start();
+
+ auto doGrab = [this]() {
+ auto measure = m_context->profiler.measure();
+
+ auto frame = grabFrame();
+
+ if (frame.isValid()) {
+ frame.setStartTime(m_context->lastFrameTime);
+ frame.setEndTime(m_context->elapsedTimer.nsecsElapsed() / 1000);
+ m_context->lastFrameTime = frame.endTime();
+
+ updateError(QPlatformSurfaceCapture::NoError);
+
+ emit frameGrabbed(frame);
+ }
+ };
+
+ doGrab();
+
+ m_context->timer.callOnTimeout(&m_context->timer, doGrab);
+ m_context->timer.start();
+}
+
+void QFFmpegSurfaceCaptureGrabber::finalizeGrabbingContext()
+{
+ Q_ASSERT(isGrabbingContextInitialized());
+ qCDebug(qLcScreenCaptureGrabber)
+ << "end screen capture thread; avg grabbing time:" << m_context->profiler.avgTime()
+ << "ms, grabbings number:" << m_context->profiler.number();
+ m_context.reset();
+}
+
+bool QFFmpegSurfaceCaptureGrabber::isGrabbingContextInitialized() const
+{
+ return m_context != nullptr;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegsurfacecapturegrabber_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegsurfacecapturegrabber_p.h b/src/plugins/multimedia/ffmpeg/qffmpegsurfacecapturegrabber_p.h
new file mode 100644
index 000000000..9a617bd7a
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegsurfacecapturegrabber_p.h
@@ -0,0 +1,92 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGSURFACECAPTUREGRABBER_P_H
+#define QFFMPEGSURFACECAPTUREGRABBER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qvideoframe.h"
+#include "private/qplatformsurfacecapture_p.h"
+
+#include <memory>
+#include <optional>
+
+QT_BEGIN_NAMESPACE
+
+class QThread;
+
+static constexpr qreal DefaultScreenCaptureFrameRate = 60.;
+
+// Mac screens often support 120 frames per sec; it looks, this is not
+// needed for the capturing now since it just affects CPI without valuable
+// advantages. In the future, the frame rate should be customized by
+// user's API.
+static constexpr qreal MaxScreenCaptureFrameRate = 60.;
+static constexpr qreal MinScreenCaptureFrameRate = 1.;
+
+class QFFmpegSurfaceCaptureGrabber : public QObject
+{
+ Q_OBJECT
+public:
+ enum ThreadPolicy {
+ UseCurrentThread,
+ CreateGrabbingThread,
+ };
+
+ QFFmpegSurfaceCaptureGrabber(ThreadPolicy threadPolicy = CreateGrabbingThread);
+
+ ~QFFmpegSurfaceCaptureGrabber() override;
+
+ void start();
+ void stop();
+
+ template<typename Object, typename Method>
+ void addFrameCallback(Object &object, Method method)
+ {
+ connect(this, &QFFmpegSurfaceCaptureGrabber::frameGrabbed,
+ &object, method, Qt::DirectConnection);
+ }
+
+signals:
+ void frameGrabbed(const QVideoFrame&);
+ void errorUpdated(QPlatformSurfaceCapture::Error error, const QString &description);
+
+protected:
+ void updateError(QPlatformSurfaceCapture::Error error, const QString &description = {});
+
+ virtual QVideoFrame grabFrame() = 0;
+
+ void setFrameRate(qreal rate);
+
+ qreal frameRate() const;
+
+ void updateTimerInterval();
+
+ virtual void initializeGrabbingContext();
+ virtual void finalizeGrabbingContext();
+
+ bool isGrabbingContextInitialized() const;
+
+private:
+ struct GrabbingContext;
+ class GrabbingThread;
+
+ std::unique_ptr<GrabbingContext> m_context;
+ qreal m_rate = 0;
+ std::optional<QPlatformSurfaceCapture::Error> m_prevError;
+ std::unique_ptr<QThread> m_thread;
+};
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGSURFACECAPTUREGRABBER_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegthread.cpp b/src/plugins/multimedia/ffmpeg/qffmpegthread.cpp
new file mode 100644
index 000000000..fb14ced54
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegthread.cpp
@@ -0,0 +1,53 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegthread_p.h"
+
+
+QT_BEGIN_NAMESPACE
+
+using namespace QFFmpeg;
+
+void ConsumerThread::stopAndDelete()
+{
+ {
+ QMutexLocker locker(&m_loopDataMutex);
+ m_exit = true;
+ }
+ dataReady();
+ wait();
+ delete this;
+}
+
+void ConsumerThread::dataReady()
+{
+ m_condition.wakeAll();
+}
+
+void ConsumerThread::run()
+{
+ init();
+
+ while (true) {
+
+ {
+ QMutexLocker locker(&m_loopDataMutex);
+ while (!hasData() && !m_exit)
+ m_condition.wait(&m_loopDataMutex);
+
+ if (m_exit)
+ break;
+ }
+
+ processOne();
+ }
+
+ cleanup();
+}
+
+QMutexLocker<QMutex> ConsumerThread::lockLoopData() const
+{
+ return QMutexLocker(&m_loopDataMutex);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegthread_p.h b/src/plugins/multimedia/ffmpeg/qffmpegthread_p.h
new file mode 100644
index 000000000..a7c5b0927
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegthread_p.h
@@ -0,0 +1,96 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGTHREAD_P_H
+#define QFFMPEGTHREAD_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+
+#include <qmutex.h>
+#include <qwaitcondition.h>
+#include <qthread.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioSink;
+
+namespace QFFmpeg
+{
+
+/*!
+ FFmpeg thread that is used to implement a consumer pattern.
+
+ This thread processes work items until no more data is available.
+ When no more data is available, it sleeps until it is notified about
+ more available data.
+ */
+class ConsumerThread : public QThread
+{
+public:
+ /*!
+ Stops the thread and deletes this object
+ */
+ void stopAndDelete();
+
+protected:
+
+ /*!
+ Called on this thread when thread starts
+ */
+ virtual void init() = 0;
+
+ /*!
+ Called on this thread before thread exits
+ */
+ virtual void cleanup() = 0;
+
+ /*!
+ Process one work item. Called repeatedly until hasData() returns
+ false, in which case the thread sleeps until the next dataReady()
+ notification.
+
+ Note: processOne() should never block.
+ */
+ virtual void processOne() = 0;
+
+ /*!
+ Wake thread from sleep and process data until
+ hasData() returns false. The method is supposed to be invoked
+ right after the scope of QMutexLocker that lockLoopData returns.
+ */
+ void dataReady();
+
+ /*!
+ Must return true when data is available for processing
+ */
+ virtual bool hasData() const = 0;
+
+ /*!
+ Locks the loop data mutex. It must be used to protect loop data
+ like a queue of video frames.
+ */
+ QMutexLocker<QMutex> lockLoopData() const;
+
+private:
+ void run() final;
+
+ mutable QMutex m_loopDataMutex;
+ QWaitCondition m_condition;
+ bool m_exit = false;
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegvideobuffer.cpp b/src/plugins/multimedia/ffmpeg/qffmpegvideobuffer.cpp
new file mode 100644
index 000000000..0edf355d8
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegvideobuffer.cpp
@@ -0,0 +1,363 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegvideobuffer_p.h"
+#include "private/qvideotexturehelper_p.h"
+#include "private/qmultimediautils_p.h"
+#include "qffmpeghwaccel_p.h"
+#include "qloggingcategory.h"
+
+extern "C" {
+#include <libavutil/pixdesc.h>
+#include <libavutil/hdr_dynamic_metadata.h>
+#include <libavutil/mastering_display_metadata.h>
+}
+
+QT_BEGIN_NAMESPACE
+
+static bool isFrameFlipped(const AVFrame& frame) {
+ for (int i = 0; i < AV_NUM_DATA_POINTERS && frame.data[i]; ++i) {
+ if (frame.linesize[i] < 0)
+ return true;
+ }
+
+ return false;
+}
+
+static Q_LOGGING_CATEGORY(qLcFFmpegVideoBuffer, "qt.multimedia.ffmpeg.videobuffer");
+
+QFFmpegVideoBuffer::QFFmpegVideoBuffer(AVFrameUPtr frame, AVRational pixelAspectRatio)
+ : QHwVideoBuffer(QVideoFrame::NoHandle),
+ m_frame(frame.get()),
+ m_size(qCalculateFrameSize({ frame->width, frame->height },
+ { pixelAspectRatio.num, pixelAspectRatio.den }))
+{
+ if (frame->hw_frames_ctx) {
+ m_hwFrame = std::move(frame);
+ m_pixelFormat = toQtPixelFormat(QFFmpeg::HWAccel::format(m_hwFrame.get()));
+ return;
+ }
+
+ m_swFrame = std::move(frame);
+ m_pixelFormat = toQtPixelFormat(AVPixelFormat(m_swFrame->format));
+
+ convertSWFrame();
+}
+
+QFFmpegVideoBuffer::~QFFmpegVideoBuffer() = default;
+
+void QFFmpegVideoBuffer::convertSWFrame()
+{
+ Q_ASSERT(m_swFrame);
+
+ const auto actualAVPixelFormat = AVPixelFormat(m_swFrame->format);
+ const auto targetAVPixelFormat = toAVPixelFormat(m_pixelFormat);
+
+ if (actualAVPixelFormat != targetAVPixelFormat || isFrameFlipped(*m_swFrame)
+ || m_size != QSize(m_swFrame->width, m_swFrame->height)) {
+ Q_ASSERT(toQtPixelFormat(targetAVPixelFormat) == m_pixelFormat);
+ // convert the format into something we can handle
+ SwsContext *c = sws_getContext(m_swFrame->width, m_swFrame->height, actualAVPixelFormat,
+ m_size.width(), m_size.height(), targetAVPixelFormat,
+ SWS_BICUBIC, nullptr, nullptr, nullptr);
+
+ auto newFrame = QFFmpeg::makeAVFrame();
+ newFrame->width = m_size.width();
+ newFrame->height = m_size.height();
+ newFrame->format = targetAVPixelFormat;
+ av_frame_get_buffer(newFrame.get(), 0);
+
+ sws_scale(c, m_swFrame->data, m_swFrame->linesize, 0, m_swFrame->height, newFrame->data, newFrame->linesize);
+ if (m_frame == m_swFrame.get())
+ m_frame = newFrame.get();
+ m_swFrame = std::move(newFrame);
+ sws_freeContext(c);
+ }
+}
+
+void QFFmpegVideoBuffer::setTextureConverter(const QFFmpeg::TextureConverter &converter)
+{
+ m_textureConverter = converter;
+ m_textureConverter.init(m_hwFrame.get());
+ m_type = converter.isNull() ? QVideoFrame::NoHandle : QVideoFrame::RhiTextureHandle;
+}
+
+QVideoFrameFormat::ColorSpace QFFmpegVideoBuffer::colorSpace() const
+{
+ switch (m_frame->colorspace) {
+ default:
+ case AVCOL_SPC_UNSPECIFIED:
+ case AVCOL_SPC_RESERVED:
+ case AVCOL_SPC_FCC:
+ case AVCOL_SPC_SMPTE240M:
+ case AVCOL_SPC_YCGCO:
+ case AVCOL_SPC_SMPTE2085:
+ case AVCOL_SPC_CHROMA_DERIVED_NCL:
+ case AVCOL_SPC_CHROMA_DERIVED_CL:
+ case AVCOL_SPC_ICTCP: // BT.2100 ICtCp
+ return QVideoFrameFormat::ColorSpace_Undefined;
+ case AVCOL_SPC_RGB:
+ return QVideoFrameFormat::ColorSpace_AdobeRgb;
+ case AVCOL_SPC_BT709:
+ return QVideoFrameFormat::ColorSpace_BT709;
+ case AVCOL_SPC_BT470BG: // BT601
+ case AVCOL_SPC_SMPTE170M: // Also BT601
+ return QVideoFrameFormat::ColorSpace_BT601;
+ case AVCOL_SPC_BT2020_NCL: // Non constant luminence
+ case AVCOL_SPC_BT2020_CL: // Constant luminence
+ return QVideoFrameFormat::ColorSpace_BT2020;
+ }
+}
+
+QVideoFrameFormat::ColorTransfer QFFmpegVideoBuffer::colorTransfer() const
+{
+ return QFFmpeg::fromAvColorTransfer(m_frame->color_trc);
+}
+
+QVideoFrameFormat::ColorRange QFFmpegVideoBuffer::colorRange() const
+{
+ switch (m_frame->color_range) {
+ case AVCOL_RANGE_MPEG:
+ return QVideoFrameFormat::ColorRange_Video;
+ case AVCOL_RANGE_JPEG:
+ return QVideoFrameFormat::ColorRange_Full;
+ default:
+ return QVideoFrameFormat::ColorRange_Unknown;
+ }
+}
+
+float QFFmpegVideoBuffer::maxNits()
+{
+ float maxNits = -1;
+ for (int i = 0; i < m_frame->nb_side_data; ++i) {
+ AVFrameSideData *sd = m_frame->side_data[i];
+ // TODO: Longer term we might want to also support HDR10+ dynamic metadata
+ if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
+ auto *data = reinterpret_cast<AVMasteringDisplayMetadata *>(sd->data);
+ auto maybeLum = QFFmpeg::mul(10'000., data->max_luminance);
+ if (maybeLum)
+ maxNits = float(maybeLum.value());
+ }
+ }
+ return maxNits;
+}
+
+QAbstractVideoBuffer::MapData QFFmpegVideoBuffer::map(QtVideo::MapMode mode)
+{
+ if (!m_swFrame) {
+ Q_ASSERT(m_hwFrame && m_hwFrame->hw_frames_ctx);
+ m_swFrame = QFFmpeg::makeAVFrame();
+ /* retrieve data from GPU to CPU */
+ int ret = av_hwframe_transfer_data(m_swFrame.get(), m_hwFrame.get(), 0);
+ if (ret < 0) {
+ qWarning() << "Error transferring the data to system memory:" << ret;
+ return {};
+ }
+ convertSWFrame();
+ }
+
+ m_mode = mode;
+
+ MapData mapData;
+ auto *desc = QVideoTextureHelper::textureDescription(pixelFormat());
+ mapData.planeCount = desc->nplanes;
+ for (int i = 0; i < mapData.planeCount; ++i) {
+ Q_ASSERT(m_swFrame->linesize[i] >= 0);
+
+ mapData.data[i] = m_swFrame->data[i];
+ mapData.bytesPerLine[i] = m_swFrame->linesize[i];
+ mapData.dataSize[i] = mapData.bytesPerLine[i]*desc->heightForPlane(m_swFrame->height, i);
+ }
+
+ if ((mode & QtVideo::MapMode::WriteOnly) != QtVideo::MapMode::NotMapped && m_hwFrame) {
+ m_type = QVideoFrame::NoHandle;
+ m_hwFrame.reset();
+ if (m_textures) {
+ qCDebug(qLcFFmpegVideoBuffer)
+ << "Mapping of FFmpeg video buffer with write mode when "
+ "textures have been created. Visual artifacts might "
+ "happen if the frame is still in the rendering pipeline";
+ m_textures.reset();
+ }
+ }
+
+ return mapData;
+}
+
+void QFFmpegVideoBuffer::unmap()
+{
+ // nothing to do here for SW buffers.
+ // Set NotMapped mode to ensure map/unmap/mapMode consisteny.
+ m_mode = QtVideo::MapMode::NotMapped;
+}
+
+std::unique_ptr<QVideoFrameTextures> QFFmpegVideoBuffer::mapTextures(QRhi *)
+{
+ if (m_textures)
+ return {};
+ if (!m_hwFrame)
+ return {};
+ if (m_textureConverter.isNull()) {
+ m_textures = nullptr;
+ return {};
+ }
+
+ m_textures.reset(m_textureConverter.getTextures(m_hwFrame.get()));
+ if (!m_textures) {
+ static thread_local int lastFormat = 0;
+ if (std::exchange(lastFormat, m_hwFrame->format) != m_hwFrame->format) // prevent logging spam
+ qWarning() << " failed to get textures for frame; format:" << m_hwFrame->format;
+ }
+ return {};
+}
+
+quint64 QFFmpegVideoBuffer::textureHandle(QRhi *rhi, int plane) const
+{
+ return m_textures ? m_textures->textureHandle(rhi, plane) : 0;
+}
+
+QVideoFrameFormat::PixelFormat QFFmpegVideoBuffer::pixelFormat() const
+{
+ return m_pixelFormat;
+}
+
+QSize QFFmpegVideoBuffer::size() const
+{
+ return m_size;
+}
+
+QVideoFrameFormat::PixelFormat QFFmpegVideoBuffer::toQtPixelFormat(AVPixelFormat avPixelFormat, bool *needsConversion)
+{
+ if (needsConversion)
+ *needsConversion = false;
+
+ switch (avPixelFormat) {
+ default:
+ break;
+ case AV_PIX_FMT_NONE:
+ Q_ASSERT(!"Invalid avPixelFormat!");
+ return QVideoFrameFormat::Format_Invalid;
+ case AV_PIX_FMT_ARGB:
+ return QVideoFrameFormat::Format_ARGB8888;
+ case AV_PIX_FMT_0RGB:
+ return QVideoFrameFormat::Format_XRGB8888;
+ case AV_PIX_FMT_BGRA:
+ return QVideoFrameFormat::Format_BGRA8888;
+ case AV_PIX_FMT_BGR0:
+ return QVideoFrameFormat::Format_BGRX8888;
+ case AV_PIX_FMT_ABGR:
+ return QVideoFrameFormat::Format_ABGR8888;
+ case AV_PIX_FMT_0BGR:
+ return QVideoFrameFormat::Format_XBGR8888;
+ case AV_PIX_FMT_RGBA:
+ return QVideoFrameFormat::Format_RGBA8888;
+ case AV_PIX_FMT_RGB0:
+ return QVideoFrameFormat::Format_RGBX8888;
+
+ case AV_PIX_FMT_YUV422P:
+ return QVideoFrameFormat::Format_YUV422P;
+ case AV_PIX_FMT_YUV420P:
+ return QVideoFrameFormat::Format_YUV420P;
+ case AV_PIX_FMT_YUV420P10:
+ return QVideoFrameFormat::Format_YUV420P10;
+ case AV_PIX_FMT_UYVY422:
+ return QVideoFrameFormat::Format_UYVY;
+ case AV_PIX_FMT_YUYV422:
+ return QVideoFrameFormat::Format_YUYV;
+ case AV_PIX_FMT_NV12:
+ return QVideoFrameFormat::Format_NV12;
+ case AV_PIX_FMT_NV21:
+ return QVideoFrameFormat::Format_NV21;
+ case AV_PIX_FMT_GRAY8:
+ return QVideoFrameFormat::Format_Y8;
+ case AV_PIX_FMT_GRAY16:
+ return QVideoFrameFormat::Format_Y16;
+
+ case AV_PIX_FMT_P010:
+ return QVideoFrameFormat::Format_P010;
+ case AV_PIX_FMT_P016:
+ return QVideoFrameFormat::Format_P016;
+ case AV_PIX_FMT_MEDIACODEC:
+ return QVideoFrameFormat::Format_SamplerExternalOES;
+ }
+
+ if (needsConversion)
+ *needsConversion = true;
+
+ const AVPixFmtDescriptor *descriptor = av_pix_fmt_desc_get(avPixelFormat);
+
+ if (descriptor->flags & AV_PIX_FMT_FLAG_RGB)
+ return QVideoFrameFormat::Format_RGBA8888;
+
+ if (descriptor->comp[0].depth > 8)
+ return QVideoFrameFormat::Format_P016;
+ return QVideoFrameFormat::Format_YUV420P;
+}
+
+AVPixelFormat QFFmpegVideoBuffer::toAVPixelFormat(QVideoFrameFormat::PixelFormat pixelFormat)
+{
+ switch (pixelFormat) {
+ default:
+ case QVideoFrameFormat::Format_Invalid:
+ case QVideoFrameFormat::Format_AYUV:
+ case QVideoFrameFormat::Format_AYUV_Premultiplied:
+ case QVideoFrameFormat::Format_YV12:
+ case QVideoFrameFormat::Format_IMC1:
+ case QVideoFrameFormat::Format_IMC2:
+ case QVideoFrameFormat::Format_IMC3:
+ case QVideoFrameFormat::Format_IMC4:
+ return AV_PIX_FMT_NONE;
+ case QVideoFrameFormat::Format_Jpeg:
+ // We're using the data from the converted QImage here, which is in BGRA.
+ return AV_PIX_FMT_BGRA;
+ case QVideoFrameFormat::Format_ARGB8888:
+ return AV_PIX_FMT_ARGB;
+ case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
+ case QVideoFrameFormat::Format_XRGB8888:
+ return AV_PIX_FMT_0RGB;
+ case QVideoFrameFormat::Format_BGRA8888:
+ return AV_PIX_FMT_BGRA;
+ case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
+ case QVideoFrameFormat::Format_BGRX8888:
+ return AV_PIX_FMT_BGR0;
+ case QVideoFrameFormat::Format_ABGR8888:
+ return AV_PIX_FMT_ABGR;
+ case QVideoFrameFormat::Format_XBGR8888:
+ return AV_PIX_FMT_0BGR;
+ case QVideoFrameFormat::Format_RGBA8888:
+ return AV_PIX_FMT_RGBA;
+ // to be added in 6.8:
+ // case QVideoFrameFormat::Format_RGBA8888_Premultiplied:
+ case QVideoFrameFormat::Format_RGBX8888:
+ return AV_PIX_FMT_RGB0;
+
+ case QVideoFrameFormat::Format_YUV422P:
+ return AV_PIX_FMT_YUV422P;
+ case QVideoFrameFormat::Format_YUV420P:
+ return AV_PIX_FMT_YUV420P;
+ case QVideoFrameFormat::Format_YUV420P10:
+ return AV_PIX_FMT_YUV420P10;
+ case QVideoFrameFormat::Format_UYVY:
+ return AV_PIX_FMT_UYVY422;
+ case QVideoFrameFormat::Format_YUYV:
+ return AV_PIX_FMT_YUYV422;
+ case QVideoFrameFormat::Format_NV12:
+ return AV_PIX_FMT_NV12;
+ case QVideoFrameFormat::Format_NV21:
+ return AV_PIX_FMT_NV21;
+ case QVideoFrameFormat::Format_Y8:
+ return AV_PIX_FMT_GRAY8;
+ case QVideoFrameFormat::Format_Y16:
+ return AV_PIX_FMT_GRAY16;
+
+ case QVideoFrameFormat::Format_P010:
+ return AV_PIX_FMT_P010;
+ case QVideoFrameFormat::Format_P016:
+ return AV_PIX_FMT_P016;
+
+ case QVideoFrameFormat::Format_SamplerExternalOES:
+ return AV_PIX_FMT_MEDIACODEC;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegvideobuffer_p.h b/src/plugins/multimedia/ffmpeg/qffmpegvideobuffer_p.h
new file mode 100644
index 000000000..c61c3f5ff
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegvideobuffer_p.h
@@ -0,0 +1,71 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGVIDEOBUFFER_P_H
+#define QFFMPEGVIDEOBUFFER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qhwvideobuffer_p.h>
+#include <QtCore/qvariant.h>
+
+#include "qffmpeg_p.h"
+#include "qffmpeghwaccel_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegVideoBuffer : public QHwVideoBuffer
+{
+public:
+ using AVFrameUPtr = QFFmpeg::AVFrameUPtr;
+
+ QFFmpegVideoBuffer(AVFrameUPtr frame, AVRational pixelAspectRatio = { 1, 1 });
+ ~QFFmpegVideoBuffer() override;
+
+ MapData map(QtVideo::MapMode mode) override;
+ void unmap() override;
+
+ virtual std::unique_ptr<QVideoFrameTextures> mapTextures(QRhi *) override;
+ virtual quint64 textureHandle(QRhi *rhi, int plane) const override;
+
+ QVideoFrameFormat::PixelFormat pixelFormat() const;
+ QSize size() const;
+
+ static QVideoFrameFormat::PixelFormat toQtPixelFormat(AVPixelFormat avPixelFormat, bool *needsConversion = nullptr);
+ static AVPixelFormat toAVPixelFormat(QVideoFrameFormat::PixelFormat pixelFormat);
+
+ void convertSWFrame();
+
+ AVFrame *getHWFrame() const { return m_hwFrame.get(); }
+
+ void setTextureConverter(const QFFmpeg::TextureConverter &converter);
+
+ QVideoFrameFormat::ColorSpace colorSpace() const;
+ QVideoFrameFormat::ColorTransfer colorTransfer() const;
+ QVideoFrameFormat::ColorRange colorRange() const;
+
+ float maxNits();
+
+private:
+ QVideoFrameFormat::PixelFormat m_pixelFormat;
+ AVFrame *m_frame = nullptr;
+ AVFrameUPtr m_hwFrame;
+ AVFrameUPtr m_swFrame;
+ QSize m_size;
+ QFFmpeg::TextureConverter m_textureConverter;
+ QtVideo::MapMode m_mode = QtVideo::MapMode::NotMapped;
+ std::unique_ptr<QFFmpeg::TextureSet> m_textures;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegvideosink.cpp b/src/plugins/multimedia/ffmpeg/qffmpegvideosink.cpp
new file mode 100644
index 000000000..2f02f09c1
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegvideosink.cpp
@@ -0,0 +1,34 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include <qffmpegvideosink_p.h>
+#include <qffmpegvideobuffer_p.h>
+#include <private/qvideoframe_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QFFmpegVideoSink::QFFmpegVideoSink(QVideoSink *sink)
+ : QPlatformVideoSink(sink)
+{
+}
+
+void QFFmpegVideoSink::setRhi(QRhi *rhi)
+{
+ if (m_rhi == rhi)
+ return;
+ m_rhi = rhi;
+ textureConverter = QFFmpeg::TextureConverter(rhi);
+ emit rhiChanged(rhi);
+}
+
+void QFFmpegVideoSink::setVideoFrame(const QVideoFrame &frame)
+{
+ auto *buffer = dynamic_cast<QFFmpegVideoBuffer *>(QVideoFramePrivate::hwBuffer(frame));
+ if (buffer)
+ buffer->setTextureConverter(textureConverter);
+
+ QPlatformVideoSink::setVideoFrame(frame);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegvideosink_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegvideosink_p.h b/src/plugins/multimedia/ffmpeg/qffmpegvideosink_p.h
new file mode 100644
index 000000000..92b537ee3
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegvideosink_p.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGVIDEOSINK_H
+#define QFFMPEGVIDEOSINK_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformvideosink_p.h>
+#include <qffmpeghwaccel_p.h>
+
+QT_BEGIN_NAMESPACE
+
+// Required for QDoc workaround
+class QString;
+
+class QFFmpegVideoSink : public QPlatformVideoSink
+{
+ Q_OBJECT
+
+public:
+ QFFmpegVideoSink(QVideoSink *sink);
+ void setRhi(QRhi *rhi) override;
+
+ void setVideoFrame(const QVideoFrame &frame) override;
+
+private:
+ QFFmpeg::TextureConverter textureConverter;
+ QRhi *m_rhi = nullptr;
+};
+
+QT_END_NAMESPACE
+
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegwindowcapture_uwp.cpp b/src/plugins/multimedia/ffmpeg/qffmpegwindowcapture_uwp.cpp
new file mode 100644
index 000000000..b36279cc3
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegwindowcapture_uwp.cpp
@@ -0,0 +1,508 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegwindowcapture_uwp_p.h"
+#include "qffmpegsurfacecapturegrabber_p.h"
+#include "qabstractvideobuffer.h"
+#include <private/qvideoframe_p.h>
+
+#include <unknwn.h>
+#include <winrt/base.h>
+#include <QtCore/private/qfactorycacheregistration_p.h>
+// Workaround for Windows SDK bug.
+// See https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/47
+namespace winrt::impl
+{
+template <typename Async>
+auto wait_for(Async const& async, Windows::Foundation::TimeSpan const& timeout);
+}
+#include <winrt/Windows.Foundation.Collections.h>
+#include <winrt/Windows.Graphics.Capture.h>
+#include <winrt/Windows.Graphics.DirectX.h>
+#include <winrt/Windows.Graphics.DirectX.Direct3D11.h>
+#include <Windows.Graphics.Capture.h>
+#include <Windows.Graphics.Capture.Interop.h>
+#include <windows.graphics.directx.direct3d11.interop.h>
+
+#include <D3d11.h>
+#include <dwmapi.h>
+#include <lowlevelmonitorconfigurationapi.h>
+#include <physicalmonitorenumerationapi.h>
+
+#include "qvideoframe.h"
+#include <qwindow.h>
+#include <qthread.h>
+#include <qloggingcategory.h>
+#include <qguiapplication.h>
+#include <private/qmultimediautils_p.h>
+#include <private/qwindowsmultimediautils_p.h>
+#include <private/qcapturablewindow_p.h>
+#include <qpa/qplatformscreen_p.h>
+
+#include <memory>
+#include <system_error>
+
+QT_BEGIN_NAMESPACE
+
+using namespace winrt::Windows::Graphics::Capture;
+using namespace winrt::Windows::Graphics::DirectX;
+using namespace winrt::Windows::Graphics::DirectX::Direct3D11;
+using namespace Windows::Graphics::DirectX::Direct3D11;
+using namespace QWindowsMultimediaUtils;
+
+using winrt::check_hresult;
+using winrt::com_ptr;
+using winrt::guid_of;
+
+namespace {
+
+Q_LOGGING_CATEGORY(qLcWindowCaptureUwp, "qt.multimedia.ffmpeg.windowcapture.uwp");
+
+winrt::Windows::Graphics::SizeInt32 getWindowSize(HWND hwnd)
+{
+ RECT windowRect{};
+ ::GetWindowRect(hwnd, &windowRect);
+
+ return { windowRect.right - windowRect.left, windowRect.bottom - windowRect.top };
+}
+
+QSize asQSize(winrt::Windows::Graphics::SizeInt32 size)
+{
+ return { size.Width, size.Height };
+}
+
+struct MultithreadedApartment
+{
+ MultithreadedApartment(const MultithreadedApartment &) = delete;
+ MultithreadedApartment &operator=(const MultithreadedApartment &) = delete;
+
+ MultithreadedApartment() { winrt::init_apartment(); }
+ ~MultithreadedApartment() { winrt::uninit_apartment(); }
+};
+
+class QUwpTextureVideoBuffer : public QAbstractVideoBuffer
+{
+public:
+ QUwpTextureVideoBuffer(com_ptr<IDXGISurface> &&surface) : m_surface(surface) { }
+
+ ~QUwpTextureVideoBuffer() override { QUwpTextureVideoBuffer::unmap(); }
+
+ MapData map(QtVideo::MapMode mode) override
+ {
+ if (m_mapMode != QtVideo::MapMode::NotMapped)
+ return {};
+
+ if (mode == QtVideo::MapMode::ReadOnly) {
+ DXGI_MAPPED_RECT rect = {};
+ HRESULT hr = m_surface->Map(&rect, DXGI_MAP_READ);
+ if (SUCCEEDED(hr)) {
+ DXGI_SURFACE_DESC desc = {};
+ hr = m_surface->GetDesc(&desc);
+
+ MapData md = {};
+ md.planeCount = 1;
+ md.bytesPerLine[0] = rect.Pitch;
+ md.data[0] = rect.pBits;
+ md.dataSize[0] = rect.Pitch * desc.Height;
+
+ m_mapMode = QtVideo::MapMode::ReadOnly;
+
+ return md;
+ } else {
+ qCDebug(qLcWindowCaptureUwp) << "Failed to map DXGI surface" << errorString(hr);
+ return {};
+ }
+ }
+
+ return {};
+ }
+
+ void unmap() override
+ {
+ if (m_mapMode == QtVideo::MapMode::NotMapped)
+ return;
+
+ const HRESULT hr = m_surface->Unmap();
+ if (FAILED(hr))
+ qCDebug(qLcWindowCaptureUwp) << "Failed to unmap surface" << errorString(hr);
+
+ m_mapMode = QtVideo::MapMode::NotMapped;
+ }
+
+ QVideoFrameFormat format() const override { return {}; }
+
+private:
+ QtVideo::MapMode m_mapMode = QtVideo::MapMode::NotMapped;
+ com_ptr<IDXGISurface> m_surface;
+};
+
+struct WindowGrabber
+{
+ WindowGrabber() = default;
+
+ WindowGrabber(IDXGIAdapter1 *adapter, HWND hwnd)
+ : m_frameSize{ getWindowSize(hwnd) }, m_captureWindow{ hwnd }
+ {
+ check_hresult(D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, 0, nullptr, 0,
+ D3D11_SDK_VERSION, m_device.put(), nullptr, nullptr));
+
+ const auto captureItem = createCaptureItem(hwnd);
+
+ m_framePool = Direct3D11CaptureFramePool::CreateFreeThreaded(
+ getCaptureDevice(m_device), m_pixelFormat, 1,
+ captureItem.Size());
+
+ m_session = m_framePool.CreateCaptureSession(captureItem);
+
+ // If supported, enable cursor capture
+ if (const auto session2 = m_session.try_as<IGraphicsCaptureSession2>())
+ session2.IsCursorCaptureEnabled(true);
+
+ // If supported, disable colored border around captured window to match other platforms
+ if (const auto session3 = m_session.try_as<IGraphicsCaptureSession3>())
+ session3.IsBorderRequired(false);
+
+ m_session.StartCapture();
+ }
+
+ ~WindowGrabber()
+ {
+ m_framePool.Close();
+ m_session.Close();
+ }
+
+ com_ptr<IDXGISurface> tryGetFrame()
+ {
+ const Direct3D11CaptureFrame frame = m_framePool.TryGetNextFrame();
+ if (!frame) {
+
+ // Stop capture and report failure if window was closed. If we don't stop,
+ // testing shows that either we don't get any frames, or we get blank frames.
+ // Emitting an error will prevent this inconsistent behavior, and makes the
+ // Windows implementation behave like the Linux implementation
+ if (!IsWindow(m_captureWindow))
+ throw std::runtime_error("Window was closed");
+
+ // Blank frames may come spuriously if no new window texture
+ // is available yet.
+ return {};
+ }
+
+ if (m_frameSize != frame.ContentSize()) {
+ m_frameSize = frame.ContentSize();
+ m_framePool.Recreate(getCaptureDevice(m_device), m_pixelFormat, 1, frame.ContentSize());
+ return {};
+ }
+
+ return copyTexture(m_device, frame.Surface());
+ }
+
+private:
+ static GraphicsCaptureItem createCaptureItem(HWND hwnd)
+ {
+ const auto factory = winrt::get_activation_factory<GraphicsCaptureItem>();
+ const auto interop = factory.as<IGraphicsCaptureItemInterop>();
+
+ GraphicsCaptureItem item = { nullptr };
+ winrt::hresult status = S_OK;
+
+ // Attempt to create capture item with retry, because this occasionally fails,
+ // particularly in unit tests. When the failure code is E_INVALIDARG, it
+ // seems to help to sleep for a bit and retry. See QTBUG-116025.
+ constexpr int maxRetry = 10;
+ constexpr std::chrono::milliseconds retryDelay{ 100 };
+ for (int retryNum = 0; retryNum < maxRetry; ++retryNum) {
+
+ status = interop->CreateForWindow(hwnd, winrt::guid_of<GraphicsCaptureItem>(),
+ winrt::put_abi(item));
+
+ if (status != E_INVALIDARG)
+ break;
+
+ qCWarning(qLcWindowCaptureUwp)
+ << "Failed to create capture item:"
+ << QString::fromStdWString(winrt::hresult_error(status).message().c_str())
+ << "Retry number" << retryNum;
+
+ if (retryNum + 1 < maxRetry)
+ QThread::sleep(retryDelay);
+ }
+
+ // Throw if we fail to create the capture item
+ check_hresult(status);
+
+ return item;
+ }
+
+ static IDirect3DDevice getCaptureDevice(const com_ptr<ID3D11Device> &d3dDevice)
+ {
+ const auto dxgiDevice = d3dDevice.as<IDXGIDevice>();
+
+ com_ptr<IInspectable> device;
+ check_hresult(CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.get(), device.put()));
+
+ return device.as<IDirect3DDevice>();
+ }
+
+ static com_ptr<IDXGISurface> copyTexture(const com_ptr<ID3D11Device> &device,
+ const IDirect3DSurface &capturedTexture)
+ {
+ const auto dxgiInterop{ capturedTexture.as<IDirect3DDxgiInterfaceAccess>() };
+ if (!dxgiInterop)
+ return {};
+
+ com_ptr<IDXGISurface> dxgiSurface;
+ check_hresult(dxgiInterop->GetInterface(guid_of<IDXGISurface>(), dxgiSurface.put_void()));
+
+ DXGI_SURFACE_DESC desc = {};
+ check_hresult(dxgiSurface->GetDesc(&desc));
+
+ D3D11_TEXTURE2D_DESC texDesc = {};
+ texDesc.Width = desc.Width;
+ texDesc.Height = desc.Height;
+ texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ texDesc.Usage = D3D11_USAGE_STAGING;
+ texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
+ texDesc.MiscFlags = 0;
+ texDesc.BindFlags = 0;
+ texDesc.ArraySize = 1;
+ texDesc.MipLevels = 1;
+ texDesc.SampleDesc = { 1, 0 };
+
+ com_ptr<ID3D11Texture2D> texture;
+ check_hresult(device->CreateTexture2D(&texDesc, nullptr, texture.put()));
+
+ com_ptr<ID3D11DeviceContext> ctx;
+ device->GetImmediateContext(ctx.put());
+ ctx->CopyResource(texture.get(), dxgiSurface.as<ID3D11Resource>().get());
+
+ return texture.as<IDXGISurface>();
+ }
+
+ MultithreadedApartment m_comApartment{};
+ HWND m_captureWindow{};
+ winrt::Windows::Graphics::SizeInt32 m_frameSize{};
+ com_ptr<ID3D11Device> m_device;
+ Direct3D11CaptureFramePool m_framePool{ nullptr };
+ GraphicsCaptureSession m_session{ nullptr };
+ const DirectXPixelFormat m_pixelFormat = DirectXPixelFormat::R8G8B8A8UIntNormalized;
+};
+
+} // namespace
+
+class QFFmpegWindowCaptureUwp::Grabber : public QFFmpegSurfaceCaptureGrabber
+{
+ Q_OBJECT
+public:
+ Grabber(QFFmpegWindowCaptureUwp &capture, HWND hwnd)
+ : m_hwnd(hwnd),
+ m_format(QVideoFrameFormat(asQSize(getWindowSize(hwnd)),
+ QVideoFrameFormat::Format_RGBX8888))
+ {
+ const HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONULL);
+ m_adapter = getAdapter(monitor);
+
+ const qreal refreshRate = getMonitorRefreshRateHz(monitor);
+
+ m_format.setStreamFrameRate(refreshRate);
+ setFrameRate(refreshRate);
+
+ addFrameCallback(capture, &QFFmpegWindowCaptureUwp::newVideoFrame);
+ connect(this, &Grabber::errorUpdated, &capture, &QFFmpegWindowCaptureUwp::updateError);
+ }
+
+ ~Grabber() override { stop(); }
+
+ QVideoFrameFormat frameFormat() const { return m_format; }
+
+protected:
+
+ void initializeGrabbingContext() override
+ {
+ if (!m_adapter || !IsWindow(m_hwnd))
+ return; // Error already logged
+
+ try {
+ m_windowGrabber = std::make_unique<WindowGrabber>(m_adapter.get(), m_hwnd);
+
+ QFFmpegSurfaceCaptureGrabber::initializeGrabbingContext();
+ } catch (const winrt::hresult_error &err) {
+
+ const QString message = QLatin1String("Unable to capture window: ")
+ + QString::fromWCharArray(err.message().c_str());
+
+ updateError(InternalError, message);
+ }
+ }
+
+ void finalizeGrabbingContext() override
+ {
+ QFFmpegSurfaceCaptureGrabber::finalizeGrabbingContext();
+ m_windowGrabber = nullptr;
+ }
+
+ QVideoFrame grabFrame() override
+ {
+ try {
+ com_ptr<IDXGISurface> texture = m_windowGrabber->tryGetFrame();
+ if (!texture)
+ return {}; // No frame available yet
+
+ const QSize size = getTextureSize(texture);
+
+ m_format.setFrameSize(size);
+
+ return QVideoFramePrivate::createFrame(
+ std::make_unique<QUwpTextureVideoBuffer>(std::move(texture)), m_format);
+
+ } catch (const winrt::hresult_error &err) {
+
+ const QString message = QLatin1String("Window capture failed: ")
+ + QString::fromWCharArray(err.message().c_str());
+
+ updateError(InternalError, message);
+ } catch (const std::runtime_error& e) {
+ updateError(CaptureFailed, QString::fromLatin1(e.what()));
+ }
+
+ return {};
+ }
+
+private:
+ static com_ptr<IDXGIAdapter1> getAdapter(HMONITOR handle)
+ {
+ com_ptr<IDXGIFactory1> factory;
+ check_hresult(CreateDXGIFactory1(guid_of<IDXGIFactory1>(), factory.put_void()));
+
+ com_ptr<IDXGIAdapter1> adapter;
+ for (quint32 i = 0; factory->EnumAdapters1(i, adapter.put()) == S_OK; adapter = nullptr, i++) {
+ com_ptr<IDXGIOutput> output;
+ for (quint32 j = 0; adapter->EnumOutputs(j, output.put()) == S_OK; output = nullptr, j++) {
+ DXGI_OUTPUT_DESC desc = {};
+ HRESULT hr = output->GetDesc(&desc);
+ if (hr == S_OK && desc.Monitor == handle)
+ return adapter;
+ }
+ }
+ return {};
+ }
+
+ static QSize getTextureSize(const com_ptr<IDXGISurface> &surf)
+ {
+ if (!surf)
+ return {};
+
+ DXGI_SURFACE_DESC desc;
+ check_hresult(surf->GetDesc(&desc));
+
+ return { static_cast<int>(desc.Width), static_cast<int>(desc.Height) };
+ }
+
+ static qreal getMonitorRefreshRateHz(HMONITOR handle)
+ {
+ DWORD count = 0;
+ if (GetNumberOfPhysicalMonitorsFromHMONITOR(handle, &count)) {
+ std::vector<PHYSICAL_MONITOR> monitors{ count };
+ if (GetPhysicalMonitorsFromHMONITOR(handle, count, monitors.data())) {
+ for (const auto &monitor : std::as_const(monitors)) {
+ MC_TIMING_REPORT screenTiming = {};
+ if (GetTimingReport(monitor.hPhysicalMonitor, &screenTiming)) {
+ // Empirically we found that GetTimingReport does not return
+ // the frequency in updates per second as documented, but in
+ // updates per 100 seconds.
+ return static_cast<qreal>(screenTiming.dwVerticalFrequencyInHZ) / 100.0;
+ }
+ }
+ }
+ }
+ return DefaultScreenCaptureFrameRate;
+ }
+
+ HWND m_hwnd{};
+ com_ptr<IDXGIAdapter1> m_adapter{};
+ std::unique_ptr<WindowGrabber> m_windowGrabber;
+ QVideoFrameFormat m_format;
+};
+
+QFFmpegWindowCaptureUwp::QFFmpegWindowCaptureUwp() : QPlatformSurfaceCapture(WindowSource{})
+{
+ qCDebug(qLcWindowCaptureUwp) << "Creating UWP screen capture";
+}
+
+QFFmpegWindowCaptureUwp::~QFFmpegWindowCaptureUwp() = default;
+
+static QString isCapturableWindow(HWND hwnd)
+{
+ if (!IsWindow(hwnd))
+ return "Invalid window handle";
+
+ if (hwnd == GetShellWindow())
+ return "Cannot capture the shell window";
+
+ wchar_t className[MAX_PATH] = {};
+ GetClassName(hwnd, className, MAX_PATH);
+ if (QString::fromWCharArray(className).length() == 0)
+ return "Cannot capture windows without a class name";
+
+ if (!IsWindowVisible(hwnd))
+ return "Cannot capture invisible windows";
+
+ if (GetAncestor(hwnd, GA_ROOT) != hwnd)
+ return "Can only capture root windows";
+
+ const LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE);
+ if (style & WS_DISABLED)
+ return "Cannot capture disabled windows";
+
+ const LONG_PTR exStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
+ if (exStyle & WS_EX_TOOLWINDOW)
+ return "No tooltips";
+
+ DWORD cloaked = FALSE;
+ const HRESULT hr = DwmGetWindowAttribute(hwnd, DWMWA_CLOAKED, &cloaked, sizeof(cloaked));
+ if (SUCCEEDED(hr) && cloaked == DWM_CLOAKED_SHELL)
+ return "Cannot capture cloaked windows";
+
+ return {};
+}
+
+bool QFFmpegWindowCaptureUwp::setActiveInternal(bool active)
+{
+ if (static_cast<bool>(m_grabber) == active)
+ return false;
+
+ if (m_grabber) {
+ m_grabber.reset();
+ return true;
+ }
+
+ const auto window = source<WindowSource>();
+ const auto handle = QCapturableWindowPrivate::handle(window);
+
+ const auto hwnd = reinterpret_cast<HWND>(handle ? handle->id : 0);
+ if (const QString error = isCapturableWindow(hwnd); !error.isEmpty()) {
+ updateError(InternalError, error);
+ return false;
+ }
+
+ m_grabber = std::make_unique<Grabber>(*this, hwnd);
+ m_grabber->start();
+
+ return true;
+}
+
+bool QFFmpegWindowCaptureUwp::isSupported()
+{
+ return GraphicsCaptureSession::IsSupported();
+}
+
+QVideoFrameFormat QFFmpegWindowCaptureUwp::frameFormat() const
+{
+ if (m_grabber)
+ return m_grabber->frameFormat();
+ return {};
+}
+
+QT_END_NAMESPACE
+
+#include "qffmpegwindowcapture_uwp.moc"
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegwindowcapture_uwp_p.h b/src/plugins/multimedia/ffmpeg/qffmpegwindowcapture_uwp_p.h
new file mode 100644
index 000000000..10f6e62be
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qffmpegwindowcapture_uwp_p.h
@@ -0,0 +1,46 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGWINDOWCAPTURE_UWP_P_H
+#define QFFMPEGWINDOWCAPTURE_UWP_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qnamespace.h>
+#include "private/qplatformsurfacecapture_p.h"
+#include "qvideoframeformat.h"
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegWindowCaptureUwp : public QPlatformSurfaceCapture
+{
+public:
+ QFFmpegWindowCaptureUwp();
+ ~QFFmpegWindowCaptureUwp() override;
+
+ QVideoFrameFormat frameFormat() const override;
+
+ static bool isSupported();
+
+private:
+ class Grabber;
+
+ bool setActiveInternal(bool active) override;
+
+private:
+ std::unique_ptr<Grabber> m_grabber;
+};
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGWINDOWCAPTURE_UWP_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qgdiwindowcapture.cpp b/src/plugins/multimedia/ffmpeg/qgdiwindowcapture.cpp
new file mode 100644
index 000000000..97742043c
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qgdiwindowcapture.cpp
@@ -0,0 +1,197 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qgdiwindowcapture_p.h"
+
+#include "qvideoframe.h"
+#include "qffmpegsurfacecapturegrabber_p.h"
+#include "private/qcapturablewindow_p.h"
+#include "private/qmemoryvideobuffer_p.h"
+#include "private/qvideoframe_p.h"
+
+#include <qt_windows.h>
+#include <QtCore/qloggingcategory.h>
+
+static Q_LOGGING_CATEGORY(qLcGdiWindowCapture, "qt.multimedia.ffmpeg.gdiwindowcapture");
+
+QT_BEGIN_NAMESPACE
+
+class QGdiWindowCapture::Grabber : public QFFmpegSurfaceCaptureGrabber
+{
+public:
+ static std::unique_ptr<Grabber> create(QGdiWindowCapture &capture, HWND hWnd)
+ {
+ auto hdcWindow = GetDC(hWnd);
+ if (!hdcWindow) {
+ capture.updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Cannot create a window drawing context"));
+ return nullptr;
+ }
+
+ auto hdcMem = CreateCompatibleDC(hdcWindow);
+
+ if (!hdcMem) {
+ capture.updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Cannot create a compatible drawing context"));
+ return nullptr;
+ }
+
+ std::unique_ptr<Grabber> result(new Grabber(capture, hWnd, hdcWindow, hdcMem));
+ if (!result->update())
+ return nullptr;
+
+ result->start();
+ return result;
+ }
+
+ ~Grabber() override
+ {
+ stop();
+
+ if (m_hBitmap)
+ DeleteObject(m_hBitmap);
+
+ if (m_hdcMem)
+ DeleteDC(m_hdcMem);
+
+ if (m_hdcWindow)
+ ReleaseDC(m_hwnd, m_hdcWindow);
+ }
+
+ QVideoFrameFormat format() const { return m_format; }
+
+private:
+ Grabber(QGdiWindowCapture &capture, HWND hWnd, HDC hdcWindow, HDC hdcMem)
+ : m_hwnd(hWnd), m_hdcWindow(hdcWindow), m_hdcMem(hdcMem)
+ {
+ if (auto rate = GetDeviceCaps(hdcWindow, VREFRESH); rate > 0)
+ setFrameRate(rate);
+
+ addFrameCallback(capture, &QGdiWindowCapture::newVideoFrame);
+ connect(this, &Grabber::errorUpdated, &capture, &QGdiWindowCapture::updateError);
+ }
+
+ bool update()
+ {
+ RECT windowRect{};
+ if (!GetWindowRect(m_hwnd, &windowRect)) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Cannot get window size"));
+ return false;
+ }
+
+ const QSize size{ windowRect.right - windowRect.left, windowRect.bottom - windowRect.top };
+
+ if (m_format.isValid() && size == m_format.frameSize() && m_hBitmap)
+ return true;
+
+ if (m_hBitmap)
+ DeleteObject(std::exchange(m_hBitmap, nullptr));
+
+ if (size.isEmpty()) {
+ m_format = {};
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Invalid window size"));
+ return false;
+ }
+
+ m_hBitmap = CreateCompatibleBitmap(m_hdcWindow, size.width(), size.height());
+
+ if (!m_hBitmap) {
+ m_format = {};
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Cannot create a compatible bitmap"));
+ return false;
+ }
+
+ QVideoFrameFormat format(size, QVideoFrameFormat::Format_BGRX8888);
+ format.setStreamFrameRate(frameRate());
+ m_format = format;
+ return true;
+ }
+
+ QVideoFrame grabFrame() override
+ {
+ if (!update())
+ return {};
+
+ const auto oldBitmap = SelectObject(m_hdcMem, m_hBitmap);
+ auto deselect = qScopeGuard([&]() { SelectObject(m_hdcMem, oldBitmap); });
+
+ const auto size = m_format.frameSize();
+
+ if (!BitBlt(m_hdcMem, 0, 0, size.width(), size.height(), m_hdcWindow, 0, 0, SRCCOPY)) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Cannot copy image to the compatible DC"));
+ return {};
+ }
+
+ BITMAPINFO info{};
+ auto &header = info.bmiHeader;
+ header.biSize = sizeof(BITMAPINFOHEADER);
+ header.biWidth = size.width();
+ header.biHeight = -size.height(); // negative height to ensure top-down orientation
+ header.biPlanes = 1;
+ header.biBitCount = 32;
+ header.biCompression = BI_RGB;
+
+ const auto bytesPerLine = size.width() * 4;
+
+ QByteArray array(size.height() * bytesPerLine, Qt::Uninitialized);
+
+ const auto copiedHeight = GetDIBits(m_hdcMem, m_hBitmap, 0, size.height(), array.data(), &info, DIB_RGB_COLORS);
+ if (copiedHeight != size.height()) {
+ qCWarning(qLcGdiWindowCapture) << copiedHeight << "lines have been copied, expected:" << size.height();
+ // In practice, it might fail randomly first time after start. So we don't consider it as an error.
+ // TODO: investigate reasons and properly handle the error
+ // updateError(QPlatformSurfaceCapture::CaptureFailed,
+ // QLatin1String("Cannot get raw image data"));
+ return {};
+ }
+
+ if (header.biWidth != size.width() || header.biHeight != -size.height()
+ || header.biPlanes != 1 || header.biBitCount != 32 || header.biCompression != BI_RGB) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Output bitmap info is unexpected"));
+ return {};
+ }
+
+ return QVideoFramePrivate::createFrame(
+ std::make_unique<QMemoryVideoBuffer>(std::move(array), bytesPerLine), m_format);
+ }
+
+private:
+ HWND m_hwnd = {};
+ QVideoFrameFormat m_format;
+ HDC m_hdcWindow = {};
+ HDC m_hdcMem = {};
+ HBITMAP m_hBitmap = {};
+};
+
+QGdiWindowCapture::QGdiWindowCapture() : QPlatformSurfaceCapture(WindowSource{}) { }
+
+QGdiWindowCapture::~QGdiWindowCapture() = default;
+
+QVideoFrameFormat QGdiWindowCapture::frameFormat() const
+{
+ return m_grabber ? m_grabber->format() : QVideoFrameFormat();
+}
+
+bool QGdiWindowCapture::setActiveInternal(bool active)
+{
+ if (active == static_cast<bool>(m_grabber))
+ return true;
+
+ if (m_grabber) {
+ m_grabber.reset();
+ } else {
+ auto window = source<WindowSource>();
+ auto handle = QCapturableWindowPrivate::handle(window);
+
+ m_grabber = Grabber::create(*this, reinterpret_cast<HWND>(handle ? handle->id : 0));
+ }
+
+ return static_cast<bool>(m_grabber) == active;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qgdiwindowcapture_p.h b/src/plugins/multimedia/ffmpeg/qgdiwindowcapture_p.h
new file mode 100644
index 000000000..d4498455c
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qgdiwindowcapture_p.h
@@ -0,0 +1,43 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGDIWINDOWCAPTURE_P_H
+#define QGDIWINDOWCAPTURE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qplatformsurfacecapture_p.h"
+
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+class QGdiWindowCapture : public QPlatformSurfaceCapture
+{
+ class Grabber;
+
+public:
+ QGdiWindowCapture();
+ ~QGdiWindowCapture() override;
+
+ QVideoFrameFormat frameFormat() const override;
+
+protected:
+ bool setActiveInternal(bool active) override;
+
+private:
+ std::unique_ptr<Grabber> m_grabber;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGDIWINDOWCAPTURE_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qgrabwindowsurfacecapture.cpp b/src/plugins/multimedia/ffmpeg/qgrabwindowsurfacecapture.cpp
new file mode 100644
index 000000000..4bd1f6a65
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qgrabwindowsurfacecapture.cpp
@@ -0,0 +1,221 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qvideoframe.h"
+#include "qgrabwindowsurfacecapture_p.h"
+#include "qscreencapture.h"
+#include "qffmpegsurfacecapturegrabber_p.h"
+
+#include "private/qimagevideobuffer_p.h"
+#include "private/qcapturablewindow_p.h"
+#include "private/qvideoframe_p.h"
+
+#include "qscreen.h"
+#include "qmutex.h"
+#include "qwaitcondition.h"
+#include "qpixmap.h"
+#include "qguiapplication.h"
+#include "qwindow.h"
+#include "qpointer.h"
+
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+
+using WindowUPtr = std::unique_ptr<QWindow>;
+
+} // namespace
+
+class QGrabWindowSurfaceCapture::Grabber : public QFFmpegSurfaceCaptureGrabber
+{
+public:
+ Grabber(QGrabWindowSurfaceCapture &capture, QScreen *screen) : Grabber(capture, screen, nullptr)
+ {
+ Q_ASSERT(screen);
+ }
+
+ Grabber(QGrabWindowSurfaceCapture &capture, WindowUPtr window)
+ : Grabber(capture, nullptr, std::move(window))
+ {
+ Q_ASSERT(m_window);
+ }
+
+ ~Grabber() override {
+ stop();
+
+ Q_ASSERT(!m_screenRemovingLocked);
+ }
+
+ const QVideoFrameFormat &format()
+ {
+ QMutexLocker locker(&m_formatMutex);
+ while (!m_format)
+ m_waitForFormat.wait(&m_formatMutex);
+ return *m_format;
+ }
+
+private:
+ Grabber(QGrabWindowSurfaceCapture &capture, QScreen *screen, WindowUPtr window)
+ : QFFmpegSurfaceCaptureGrabber(
+ QGuiApplication::platformName() == QLatin1String("eglfs")
+ ? QFFmpegSurfaceCaptureGrabber::UseCurrentThread
+ : QFFmpegSurfaceCaptureGrabber::CreateGrabbingThread),
+ m_capture(capture),
+ m_screen(screen),
+ m_window(std::move(window))
+ {
+ connect(qApp, &QGuiApplication::screenRemoved, this, &Grabber::onScreenRemoved);
+ addFrameCallback(m_capture, &QGrabWindowSurfaceCapture::newVideoFrame);
+ connect(this, &Grabber::errorUpdated, &m_capture, &QGrabWindowSurfaceCapture::updateError);
+ }
+
+ void onScreenRemoved(QScreen *screen)
+ {
+ /* The hack allows to lock screens removing while QScreen::grabWindow is in progress.
+ * The current solution works since QGuiApplication::screenRemoved is emitted from
+ * the destructor of QScreen before destruction members of the object.
+ * Note, QGuiApplication works with screens in the main thread, and any removing of a screen
+ * must be synchronized with grabbing thread.
+ */
+ QMutexLocker locker(&m_screenRemovingMutex);
+
+ if (m_screenRemovingLocked) {
+ qDebug() << "Screen" << screen->name()
+ << "is removed while screen window grabbing lock is active";
+ }
+
+ while (m_screenRemovingLocked)
+ m_screenRemovingWc.wait(&m_screenRemovingMutex);
+ }
+
+ void setScreenRemovingLocked(bool locked)
+ {
+ Q_ASSERT(locked != m_screenRemovingLocked);
+
+ {
+ QMutexLocker locker(&m_screenRemovingMutex);
+ m_screenRemovingLocked = locked;
+ }
+
+ if (!locked)
+ m_screenRemovingWc.wakeAll();
+ }
+
+ void updateFormat(const QVideoFrameFormat &format)
+ {
+ if (m_format && m_format->isValid())
+ return;
+
+ {
+ QMutexLocker locker(&m_formatMutex);
+ m_format = format;
+ }
+
+ m_waitForFormat.wakeAll();
+ }
+
+ QVideoFrame grabFrame() override
+ {
+ setScreenRemovingLocked(true);
+ auto screenGuard = qScopeGuard(std::bind(&Grabber::setScreenRemovingLocked, this, false));
+
+ WId wid = m_window ? m_window->winId() : 0;
+ QScreen *screen = m_window ? m_window->screen() : m_screen ? m_screen.data() : nullptr;
+
+ if (!screen) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed, "Screen not found");
+ return {};
+ }
+
+ setFrameRate(screen->refreshRate());
+
+ QPixmap p = screen->grabWindow(wid);
+ auto buffer = std::make_unique<QImageVideoBuffer>(p.toImage());
+ const auto img = buffer->underlyingImage();
+
+ QVideoFrameFormat format(img.size(),
+ QVideoFrameFormat::pixelFormatFromImageFormat(img.format()));
+ format.setStreamFrameRate(screen->refreshRate());
+ updateFormat(format);
+
+ if (!format.isValid()) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ "Failed to grab the screen content");
+ return {};
+ }
+
+ return QVideoFramePrivate::createFrame(std::move(buffer), std::move(format));
+ }
+
+private:
+ QGrabWindowSurfaceCapture &m_capture;
+ QPointer<QScreen> m_screen;
+ WindowUPtr m_window;
+
+ QMutex m_formatMutex;
+ QWaitCondition m_waitForFormat;
+ std::optional<QVideoFrameFormat> m_format;
+
+ QMutex m_screenRemovingMutex;
+ bool m_screenRemovingLocked = false;
+ QWaitCondition m_screenRemovingWc;
+};
+
+QGrabWindowSurfaceCapture::QGrabWindowSurfaceCapture(Source initialSource)
+ : QPlatformSurfaceCapture(initialSource)
+{
+}
+
+QGrabWindowSurfaceCapture::~QGrabWindowSurfaceCapture() = default;
+
+QVideoFrameFormat QGrabWindowSurfaceCapture::frameFormat() const
+{
+ if (m_grabber)
+ return m_grabber->format();
+ else
+ return {};
+}
+
+bool QGrabWindowSurfaceCapture::setActiveInternal(bool active)
+{
+ if (active == static_cast<bool>(m_grabber))
+ return true;
+
+ if (m_grabber)
+ m_grabber.reset();
+ else
+ std::visit([this](auto source) { activate(source); }, source());
+
+ return static_cast<bool>(m_grabber) == active;
+}
+
+void QGrabWindowSurfaceCapture::activate(ScreenSource screen)
+{
+ if (!checkScreenWithError(screen))
+ return;
+
+ m_grabber = std::make_unique<Grabber>(*this, screen);
+ m_grabber->start();
+}
+
+void QGrabWindowSurfaceCapture::activate(WindowSource window)
+{
+ auto handle = QCapturableWindowPrivate::handle(window);
+ auto wid = handle ? handle->id : 0;
+ if (auto wnd = WindowUPtr(QWindow::fromWinId(wid))) {
+ if (!wnd->screen()) {
+ updateError(InternalError,
+ "Window " + QString::number(wid) + " doesn't belong to any screen");
+ } else {
+ m_grabber = std::make_unique<Grabber>(*this, std::move(wnd));
+ m_grabber->start();
+ }
+ } else {
+ updateError(NotFound,
+ "Window " + QString::number(wid) + "doesn't exist or permissions denied");
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qgrabwindowsurfacecapture_p.h b/src/plugins/multimedia/ffmpeg/qgrabwindowsurfacecapture_p.h
new file mode 100644
index 000000000..a76ce9507
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qgrabwindowsurfacecapture_p.h
@@ -0,0 +1,48 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGRABWINDOWSURFACECAPTURE_P_H
+#define QGRABWINDOWSURFACECAPTURE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qplatformsurfacecapture_p.h"
+
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+class QGrabWindowSurfaceCapture : public QPlatformSurfaceCapture
+{
+ class Grabber;
+
+public:
+ explicit QGrabWindowSurfaceCapture(Source initialSource);
+ ~QGrabWindowSurfaceCapture() override;
+
+ QVideoFrameFormat frameFormat() const override;
+
+protected:
+ bool setActiveInternal(bool active) override;
+
+private:
+ void activate(ScreenSource);
+
+ void activate(WindowSource);
+
+private:
+ std::unique_ptr<Grabber> m_grabber;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGRABWINDOWSURFACECAPTURE_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qopenglvideobuffer.cpp b/src/plugins/multimedia/ffmpeg/qopenglvideobuffer.cpp
new file mode 100644
index 000000000..4ac08fd24
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qopenglvideobuffer.cpp
@@ -0,0 +1,96 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qopenglvideobuffer_p.h"
+
+#include <qoffscreensurface.h>
+#include <qthread.h>
+#include <private/qimagevideobuffer_p.h>
+
+#include <QtOpenGL/private/qopenglcompositor_p.h>
+#include <QtOpenGL/private/qopenglframebufferobject_p.h>
+
+QT_BEGIN_NAMESPACE
+
+static QOpenGLContext *createContext(QOpenGLContext *shareContext)
+{
+ // Create an OpenGL context for the current thread. The lifetime of the context is tied to the
+ // lifetime of the current thread.
+ auto context = std::make_unique<QOpenGLContext>();
+ context->setShareContext(shareContext);
+
+ if (!context->create()) {
+ qWarning() << "Couldn't create an OpenGL context for QOpenGLVideoBuffer";
+ return nullptr;
+ }
+
+ QObject::connect(QThread::currentThread(), &QThread::finished,
+ context.get(), &QOpenGLContext::deleteLater);
+ return context.release();
+}
+
+static bool setCurrentOpenGLContext()
+{
+ auto compositorContext = QOpenGLCompositor::instance()->context();
+
+ // A thread-local variable is used to avoid creating a new context if we're called on the same
+ // thread. The context lifetime is tied to the current thread lifetime (see createContext()).
+ static thread_local QOpenGLContext *context = nullptr;
+ static thread_local QOffscreenSurface *surface = nullptr;
+
+ if (!context) {
+ context = (compositorContext->thread() == QThread::currentThread())
+ ? compositorContext
+ : createContext(compositorContext);
+
+ if (!context)
+ return false;
+
+ surface = new QOffscreenSurface(nullptr, context);
+ surface->setFormat(context->format());
+ surface->create();
+ }
+
+ return context->makeCurrent(surface);
+}
+
+QOpenGLVideoBuffer::QOpenGLVideoBuffer(std::unique_ptr<QOpenGLFramebufferObject> fbo)
+ : QHwVideoBuffer(QVideoFrame::RhiTextureHandle), m_fbo(std::move(fbo))
+{
+ Q_ASSERT(m_fbo);
+}
+
+QOpenGLVideoBuffer::~QOpenGLVideoBuffer() { }
+
+QAbstractVideoBuffer::MapData QOpenGLVideoBuffer::map(QtVideo::MapMode mode)
+{
+ return ensureImageBuffer().map(mode);
+}
+
+void QOpenGLVideoBuffer::unmap()
+{
+ if (m_imageBuffer)
+ m_imageBuffer->unmap();
+}
+
+quint64 QOpenGLVideoBuffer::textureHandle(QRhi *, int plane) const
+{
+ Q_UNUSED(plane);
+ return m_fbo->texture();
+}
+
+QImageVideoBuffer &QOpenGLVideoBuffer::ensureImageBuffer()
+{
+ // Create image buffer if not yet created.
+ // This is protected by mapMutex in QVideoFrame::map.
+ if (!m_imageBuffer) {
+ if (!setCurrentOpenGLContext())
+ qWarning() << "Failed to set current OpenGL context";
+
+ m_imageBuffer = std::make_unique<QImageVideoBuffer>(m_fbo->toImage(false));
+ }
+
+ return *m_imageBuffer;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qopenglvideobuffer_p.h b/src/plugins/multimedia/ffmpeg/qopenglvideobuffer_p.h
new file mode 100644
index 000000000..6e62625d0
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qopenglvideobuffer_p.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QOPENGLVIDEOBUFFER_P_H
+#define QOPENGLVIDEOBUFFER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qhwvideobuffer_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QImageVideoBuffer;
+class QOpenGLFramebufferObject;
+
+class QOpenGLVideoBuffer : public QHwVideoBuffer
+{
+public:
+ QOpenGLVideoBuffer(std::unique_ptr<QOpenGLFramebufferObject> fbo);
+ ~QOpenGLVideoBuffer();
+
+ MapData map(QtVideo::MapMode mode) override;
+ void unmap() override;
+ quint64 textureHandle(QRhi *, int plane) const override;
+
+ QImageVideoBuffer &ensureImageBuffer();
+
+private:
+ std::unique_ptr<QOpenGLFramebufferObject> m_fbo;
+ std::unique_ptr<QImageVideoBuffer> m_imageBuffer;
+};
+
+QT_END_NAMESPACE
+
+#endif // QOPENGLVIDEOBUFFER_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qv4l2camera.cpp b/src/plugins/multimedia/ffmpeg/qv4l2camera.cpp
new file mode 100644
index 000000000..800460f14
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qv4l2camera.cpp
@@ -0,0 +1,708 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qv4l2camera_p.h"
+#include "qv4l2filedescriptor_p.h"
+#include "qv4l2memorytransfer_p.h"
+
+#include <private/qcameradevice_p.h>
+#include <private/qmultimediautils_p.h>
+#include <private/qmemoryvideobuffer_p.h>
+#include <private/qvideoframe_p.h>
+#include <private/qcore_unix_p.h>
+
+#include <qsocketnotifier.h>
+#include <qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcV4L2Camera, "qt.multimedia.ffmpeg.v4l2camera");
+
+static const struct {
+ QVideoFrameFormat::PixelFormat fmt;
+ uint32_t v4l2Format;
+} formatMap[] = {
+ // ### How do we handle V4L2_PIX_FMT_H264 and V4L2_PIX_FMT_MPEG4?
+ { QVideoFrameFormat::Format_YUV420P, V4L2_PIX_FMT_YUV420 },
+ { QVideoFrameFormat::Format_YUV422P, V4L2_PIX_FMT_YUV422P },
+ { QVideoFrameFormat::Format_YUYV, V4L2_PIX_FMT_YUYV },
+ { QVideoFrameFormat::Format_UYVY, V4L2_PIX_FMT_UYVY },
+ { QVideoFrameFormat::Format_XBGR8888, V4L2_PIX_FMT_XBGR32 },
+ { QVideoFrameFormat::Format_XRGB8888, V4L2_PIX_FMT_XRGB32 },
+ { QVideoFrameFormat::Format_ABGR8888, V4L2_PIX_FMT_ABGR32 },
+ { QVideoFrameFormat::Format_ARGB8888, V4L2_PIX_FMT_ARGB32 },
+ { QVideoFrameFormat::Format_BGRX8888, V4L2_PIX_FMT_BGR32 },
+ { QVideoFrameFormat::Format_RGBX8888, V4L2_PIX_FMT_RGB32 },
+ { QVideoFrameFormat::Format_BGRA8888, V4L2_PIX_FMT_BGRA32 },
+ { QVideoFrameFormat::Format_RGBA8888, V4L2_PIX_FMT_RGBA32 },
+ { QVideoFrameFormat::Format_Y8, V4L2_PIX_FMT_GREY },
+ { QVideoFrameFormat::Format_Y16, V4L2_PIX_FMT_Y16 },
+ { QVideoFrameFormat::Format_NV12, V4L2_PIX_FMT_NV12 },
+ { QVideoFrameFormat::Format_NV21, V4L2_PIX_FMT_NV21 },
+ { QVideoFrameFormat::Format_Jpeg, V4L2_PIX_FMT_MJPEG },
+ { QVideoFrameFormat::Format_Jpeg, V4L2_PIX_FMT_JPEG },
+ { QVideoFrameFormat::Format_Invalid, 0 },
+};
+
+QVideoFrameFormat::PixelFormat formatForV4L2Format(uint32_t v4l2Format)
+{
+ auto *f = formatMap;
+ while (f->v4l2Format) {
+ if (f->v4l2Format == v4l2Format)
+ return f->fmt;
+ ++f;
+ }
+ return QVideoFrameFormat::Format_Invalid;
+}
+
+uint32_t v4l2FormatForPixelFormat(QVideoFrameFormat::PixelFormat format)
+{
+ auto *f = formatMap;
+ while (f->v4l2Format) {
+ if (f->fmt == format)
+ return f->v4l2Format;
+ ++f;
+ }
+ return 0;
+}
+
+QV4L2Camera::QV4L2Camera(QCamera *camera)
+ : QPlatformCamera(camera)
+{
+}
+
+QV4L2Camera::~QV4L2Camera()
+{
+ stopCapturing();
+ closeV4L2Fd();
+}
+
+bool QV4L2Camera::isActive() const
+{
+ return m_active;
+}
+
+void QV4L2Camera::setActive(bool active)
+{
+ if (m_active == active)
+ return;
+ if (m_cameraDevice.isNull() && active)
+ return;
+
+ if (m_cameraFormat.isNull())
+ resolveCameraFormat({});
+
+ m_active = active;
+ if (m_active)
+ startCapturing();
+ else
+ stopCapturing();
+
+ emit newVideoFrame({});
+
+ emit activeChanged(active);
+}
+
+void QV4L2Camera::setCamera(const QCameraDevice &camera)
+{
+ if (m_cameraDevice == camera)
+ return;
+
+ stopCapturing();
+ closeV4L2Fd();
+
+ m_cameraDevice = camera;
+ resolveCameraFormat({});
+
+ initV4L2Controls();
+
+ if (m_active)
+ startCapturing();
+}
+
+bool QV4L2Camera::setCameraFormat(const QCameraFormat &format)
+{
+ if (!format.isNull() && !m_cameraDevice.videoFormats().contains(format))
+ return false;
+
+ if (!resolveCameraFormat(format))
+ return true;
+
+ if (m_active) {
+ stopCapturing();
+ closeV4L2Fd();
+
+ initV4L2Controls();
+ startCapturing();
+ }
+
+ return true;
+}
+
+bool QV4L2Camera::resolveCameraFormat(const QCameraFormat &format)
+{
+ auto fmt = format;
+ if (fmt.isNull())
+ fmt = findBestCameraFormat(m_cameraDevice);
+
+ if (fmt == m_cameraFormat)
+ return false;
+
+ m_cameraFormat = fmt;
+ return true;
+}
+
+void QV4L2Camera::setFocusMode(QCamera::FocusMode mode)
+{
+ if (mode == focusMode())
+ return;
+
+ bool focusDist = supportedFeatures() & QCamera::Feature::FocusDistance;
+ if (!focusDist && !m_v4l2Info.rangedFocus)
+ return;
+
+ switch (mode) {
+ default:
+ case QCamera::FocusModeAuto:
+ setV4L2Parameter(V4L2_CID_FOCUS_AUTO, 1);
+ if (m_v4l2Info.rangedFocus)
+ setV4L2Parameter(V4L2_CID_AUTO_FOCUS_RANGE, V4L2_AUTO_FOCUS_RANGE_AUTO);
+ break;
+ case QCamera::FocusModeAutoNear:
+ setV4L2Parameter(V4L2_CID_FOCUS_AUTO, 1);
+ if (m_v4l2Info.rangedFocus)
+ setV4L2Parameter(V4L2_CID_AUTO_FOCUS_RANGE, V4L2_AUTO_FOCUS_RANGE_MACRO);
+ else if (focusDist)
+ setV4L2Parameter(V4L2_CID_FOCUS_ABSOLUTE, m_v4l2Info.minFocus);
+ break;
+ case QCamera::FocusModeAutoFar:
+ setV4L2Parameter(V4L2_CID_FOCUS_AUTO, 1);
+ if (m_v4l2Info.rangedFocus)
+ setV4L2Parameter(V4L2_CID_AUTO_FOCUS_RANGE, V4L2_AUTO_FOCUS_RANGE_INFINITY);
+ break;
+ case QCamera::FocusModeInfinity:
+ setV4L2Parameter(V4L2_CID_FOCUS_AUTO, 0);
+ setV4L2Parameter(V4L2_CID_FOCUS_ABSOLUTE, m_v4l2Info.maxFocus);
+ break;
+ case QCamera::FocusModeManual:
+ setV4L2Parameter(V4L2_CID_FOCUS_AUTO, 0);
+ setFocusDistance(focusDistance());
+ break;
+ }
+ focusModeChanged(mode);
+}
+
+void QV4L2Camera::setFocusDistance(float d)
+{
+ int distance = m_v4l2Info.minFocus + int((m_v4l2Info.maxFocus - m_v4l2Info.minFocus) * d);
+ setV4L2Parameter(V4L2_CID_FOCUS_ABSOLUTE, distance);
+ focusDistanceChanged(d);
+}
+
+void QV4L2Camera::zoomTo(float factor, float)
+{
+ if (m_v4l2Info.maxZoom == m_v4l2Info.minZoom)
+ return;
+ factor = qBound(1., factor, 2.);
+ int zoom = m_v4l2Info.minZoom + (factor - 1.) * (m_v4l2Info.maxZoom - m_v4l2Info.minZoom);
+ setV4L2Parameter(V4L2_CID_ZOOM_ABSOLUTE, zoom);
+ zoomFactorChanged(factor);
+}
+
+bool QV4L2Camera::isFocusModeSupported(QCamera::FocusMode mode) const
+{
+ if (supportedFeatures() & QCamera::Feature::FocusDistance &&
+ (mode == QCamera::FocusModeManual || mode == QCamera::FocusModeAutoNear || mode == QCamera::FocusModeInfinity))
+ return true;
+
+ return mode == QCamera::FocusModeAuto;
+}
+
+void QV4L2Camera::setFlashMode(QCamera::FlashMode mode)
+{
+ if (!m_v4l2Info.flashSupported || mode == QCamera::FlashOn)
+ return;
+ setV4L2Parameter(V4L2_CID_FLASH_LED_MODE, mode == QCamera::FlashAuto ? V4L2_FLASH_LED_MODE_FLASH : V4L2_FLASH_LED_MODE_NONE);
+ flashModeChanged(mode);
+}
+
+bool QV4L2Camera::isFlashModeSupported(QCamera::FlashMode mode) const
+{
+ if (m_v4l2Info.flashSupported && mode == QCamera::FlashAuto)
+ return true;
+ return mode == QCamera::FlashOff;
+}
+
+bool QV4L2Camera::isFlashReady() const
+{
+ struct v4l2_queryctrl queryControl;
+ ::memset(&queryControl, 0, sizeof(queryControl));
+ queryControl.id = V4L2_CID_AUTO_WHITE_BALANCE;
+
+ return m_v4l2FileDescriptor && m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl);
+}
+
+void QV4L2Camera::setTorchMode(QCamera::TorchMode mode)
+{
+ if (!m_v4l2Info.torchSupported || mode == QCamera::TorchOn)
+ return;
+ setV4L2Parameter(V4L2_CID_FLASH_LED_MODE, mode == QCamera::TorchOn ? V4L2_FLASH_LED_MODE_TORCH : V4L2_FLASH_LED_MODE_NONE);
+ torchModeChanged(mode);
+}
+
+bool QV4L2Camera::isTorchModeSupported(QCamera::TorchMode mode) const
+{
+ if (mode == QCamera::TorchOn)
+ return m_v4l2Info.torchSupported;
+ return mode == QCamera::TorchOff;
+}
+
+void QV4L2Camera::setExposureMode(QCamera::ExposureMode mode)
+{
+ if (m_v4l2Info.autoExposureSupported && m_v4l2Info.manualExposureSupported) {
+ if (mode != QCamera::ExposureAuto && mode != QCamera::ExposureManual)
+ return;
+ int value = QCamera::ExposureAuto ? V4L2_EXPOSURE_AUTO : V4L2_EXPOSURE_MANUAL;
+ setV4L2Parameter(V4L2_CID_EXPOSURE_AUTO, value);
+ exposureModeChanged(mode);
+ return;
+ }
+}
+
+bool QV4L2Camera::isExposureModeSupported(QCamera::ExposureMode mode) const
+{
+ if (mode == QCamera::ExposureAuto)
+ return true;
+ if (m_v4l2Info.manualExposureSupported && m_v4l2Info.autoExposureSupported)
+ return mode == QCamera::ExposureManual;
+ return false;
+}
+
+void QV4L2Camera::setExposureCompensation(float compensation)
+{
+ if ((m_v4l2Info.minExposureAdjustment != 0 || m_v4l2Info.maxExposureAdjustment != 0)) {
+ int value = qBound(m_v4l2Info.minExposureAdjustment, (int)(compensation * 1000),
+ m_v4l2Info.maxExposureAdjustment);
+ setV4L2Parameter(V4L2_CID_AUTO_EXPOSURE_BIAS, value);
+ exposureCompensationChanged(value/1000.);
+ return;
+ }
+}
+
+void QV4L2Camera::setManualIsoSensitivity(int iso)
+{
+ if (!(supportedFeatures() & QCamera::Feature::IsoSensitivity))
+ return;
+ setV4L2Parameter(V4L2_CID_ISO_SENSITIVITY_AUTO, iso <= 0 ? V4L2_ISO_SENSITIVITY_AUTO : V4L2_ISO_SENSITIVITY_MANUAL);
+ if (iso > 0) {
+ iso = qBound(minIso(), iso, maxIso());
+ setV4L2Parameter(V4L2_CID_ISO_SENSITIVITY, iso);
+ }
+ return;
+}
+
+int QV4L2Camera::isoSensitivity() const
+{
+ if (!(supportedFeatures() & QCamera::Feature::IsoSensitivity))
+ return -1;
+ return getV4L2Parameter(V4L2_CID_ISO_SENSITIVITY);
+}
+
+void QV4L2Camera::setManualExposureTime(float secs)
+{
+ if (m_v4l2Info.manualExposureSupported && m_v4l2Info.autoExposureSupported) {
+ int exposure =
+ qBound(m_v4l2Info.minExposure, qRound(secs * 10000.), m_v4l2Info.maxExposure);
+ setV4L2Parameter(V4L2_CID_EXPOSURE_ABSOLUTE, exposure);
+ exposureTimeChanged(exposure/10000.);
+ return;
+ }
+}
+
+float QV4L2Camera::exposureTime() const
+{
+ return getV4L2Parameter(V4L2_CID_EXPOSURE_ABSOLUTE)/10000.;
+}
+
+bool QV4L2Camera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const
+{
+ if (m_v4l2Info.autoWhiteBalanceSupported && m_v4l2Info.colorTemperatureSupported)
+ return true;
+
+ return mode == QCamera::WhiteBalanceAuto;
+}
+
+void QV4L2Camera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)
+{
+ Q_ASSERT(isWhiteBalanceModeSupported(mode));
+
+ int temperature = colorTemperatureForWhiteBalance(mode);
+ int t = setV4L2ColorTemperature(temperature);
+ if (t == 0)
+ mode = QCamera::WhiteBalanceAuto;
+ whiteBalanceModeChanged(mode);
+}
+
+void QV4L2Camera::setColorTemperature(int temperature)
+{
+ if (temperature == 0) {
+ setWhiteBalanceMode(QCamera::WhiteBalanceAuto);
+ return;
+ }
+
+ Q_ASSERT(isWhiteBalanceModeSupported(QCamera::WhiteBalanceManual));
+
+ int t = setV4L2ColorTemperature(temperature);
+ if (t)
+ colorTemperatureChanged(t);
+}
+
+void QV4L2Camera::readFrame()
+{
+ Q_ASSERT(m_memoryTransfer);
+
+ auto buffer = m_memoryTransfer->dequeueBuffer();
+ if (!buffer) {
+ qCWarning(qLcV4L2Camera) << "Cannot take buffer";
+
+ if (errno == ENODEV) {
+ // camera got removed while being active
+ stopCapturing();
+ closeV4L2Fd();
+ }
+
+ return;
+ }
+
+ auto videoBuffer = std::make_unique<QMemoryVideoBuffer>(buffer->data, m_bytesPerLine);
+ QVideoFrame frame = QVideoFramePrivate::createFrame(std::move(videoBuffer), frameFormat());
+
+ auto &v4l2Buffer = buffer->v4l2Buffer;
+
+ if (m_firstFrameTime.tv_sec == -1)
+ m_firstFrameTime = v4l2Buffer.timestamp;
+ qint64 secs = v4l2Buffer.timestamp.tv_sec - m_firstFrameTime.tv_sec;
+ qint64 usecs = v4l2Buffer.timestamp.tv_usec - m_firstFrameTime.tv_usec;
+ frame.setStartTime(secs*1000000 + usecs);
+ frame.setEndTime(frame.startTime() + m_frameDuration);
+
+ emit newVideoFrame(frame);
+
+ if (!m_memoryTransfer->enqueueBuffer(v4l2Buffer.index))
+ qCWarning(qLcV4L2Camera) << "Cannot add buffer";
+}
+
+void QV4L2Camera::setCameraBusy()
+{
+ m_cameraBusy = true;
+ updateError(QCamera::CameraError, QLatin1String("Camera is in use"));
+}
+
+void QV4L2Camera::initV4L2Controls()
+{
+ m_v4l2Info = {};
+ QCamera::Features features;
+
+ const QByteArray deviceName = m_cameraDevice.id();
+ Q_ASSERT(!deviceName.isEmpty());
+
+ closeV4L2Fd();
+
+ const int descriptor = qt_safe_open(deviceName.constData(), O_RDWR);
+ if (descriptor == -1) {
+ qCWarning(qLcV4L2Camera) << "Unable to open the camera" << deviceName
+ << "for read to query the parameter info:"
+ << qt_error_string(errno);
+ updateError(QCamera::CameraError, QLatin1String("Cannot open camera"));
+ return;
+ }
+
+ m_v4l2FileDescriptor = std::make_shared<QV4L2FileDescriptor>(descriptor);
+
+ qCDebug(qLcV4L2Camera) << "FD=" << descriptor;
+
+ struct v4l2_queryctrl queryControl;
+ ::memset(&queryControl, 0, sizeof(queryControl));
+ queryControl.id = V4L2_CID_AUTO_WHITE_BALANCE;
+
+ if (m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl)) {
+ m_v4l2Info.autoWhiteBalanceSupported = true;
+ setV4L2Parameter(V4L2_CID_AUTO_WHITE_BALANCE, true);
+ }
+
+ ::memset(&queryControl, 0, sizeof(queryControl));
+ queryControl.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE;
+ if (m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl)) {
+ m_v4l2Info.minColorTemp = queryControl.minimum;
+ m_v4l2Info.maxColorTemp = queryControl.maximum;
+ m_v4l2Info.colorTemperatureSupported = true;
+ features |= QCamera::Feature::ColorTemperature;
+ }
+
+ ::memset(&queryControl, 0, sizeof(queryControl));
+ queryControl.id = V4L2_CID_EXPOSURE_AUTO;
+ if (m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl)) {
+ m_v4l2Info.autoExposureSupported = true;
+ }
+
+ ::memset(&queryControl, 0, sizeof(queryControl));
+ queryControl.id = V4L2_CID_EXPOSURE_ABSOLUTE;
+ if (m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl)) {
+ m_v4l2Info.manualExposureSupported = true;
+ m_v4l2Info.minExposure = queryControl.minimum;
+ m_v4l2Info.maxExposure = queryControl.maximum;
+ features |= QCamera::Feature::ManualExposureTime;
+ }
+
+ ::memset(&queryControl, 0, sizeof(queryControl));
+ queryControl.id = V4L2_CID_AUTO_EXPOSURE_BIAS;
+ if (m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl)) {
+ m_v4l2Info.minExposureAdjustment = queryControl.minimum;
+ m_v4l2Info.maxExposureAdjustment = queryControl.maximum;
+ features |= QCamera::Feature::ExposureCompensation;
+ }
+
+ ::memset(&queryControl, 0, sizeof(queryControl));
+ queryControl.id = V4L2_CID_ISO_SENSITIVITY_AUTO;
+ if (m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl)) {
+ queryControl.id = V4L2_CID_ISO_SENSITIVITY;
+ if (m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl)) {
+ features |= QCamera::Feature::IsoSensitivity;
+ minIsoChanged(queryControl.minimum);
+ maxIsoChanged(queryControl.minimum);
+ }
+ }
+
+ ::memset(&queryControl, 0, sizeof(queryControl));
+ queryControl.id = V4L2_CID_FOCUS_ABSOLUTE;
+ if (m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl)) {
+ m_v4l2Info.minExposureAdjustment = queryControl.minimum;
+ m_v4l2Info.maxExposureAdjustment = queryControl.maximum;
+ features |= QCamera::Feature::FocusDistance;
+ }
+
+ ::memset(&queryControl, 0, sizeof(queryControl));
+ queryControl.id = V4L2_CID_AUTO_FOCUS_RANGE;
+ if (m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl)) {
+ m_v4l2Info.rangedFocus = true;
+ }
+
+ ::memset(&queryControl, 0, sizeof(queryControl));
+ queryControl.id = V4L2_CID_FLASH_LED_MODE;
+ if (m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl)) {
+ m_v4l2Info.flashSupported = queryControl.minimum <= V4L2_FLASH_LED_MODE_FLASH
+ && queryControl.maximum >= V4L2_FLASH_LED_MODE_FLASH;
+ m_v4l2Info.torchSupported = queryControl.minimum <= V4L2_FLASH_LED_MODE_TORCH
+ && queryControl.maximum >= V4L2_FLASH_LED_MODE_TORCH;
+ }
+
+ ::memset(&queryControl, 0, sizeof(queryControl));
+ queryControl.id = V4L2_CID_ZOOM_ABSOLUTE;
+ if (m_v4l2FileDescriptor->call(VIDIOC_QUERYCTRL, &queryControl)) {
+ m_v4l2Info.minZoom = queryControl.minimum;
+ m_v4l2Info.maxZoom = queryControl.maximum;
+ }
+ // zoom factors are in arbitrary units, so we simply normalize them to go from 1 to 2
+ // if they are different
+ minimumZoomFactorChanged(1);
+ maximumZoomFactorChanged(m_v4l2Info.minZoom != m_v4l2Info.maxZoom ? 2 : 1);
+
+ supportedFeaturesChanged(features);
+}
+
+void QV4L2Camera::closeV4L2Fd()
+{
+ Q_ASSERT(!m_memoryTransfer);
+
+ m_v4l2Info = {};
+ m_cameraBusy = false;
+ m_v4l2FileDescriptor = nullptr;
+}
+
+int QV4L2Camera::setV4L2ColorTemperature(int temperature)
+{
+ struct v4l2_control control;
+ ::memset(&control, 0, sizeof(control));
+
+ if (m_v4l2Info.autoWhiteBalanceSupported) {
+ setV4L2Parameter(V4L2_CID_AUTO_WHITE_BALANCE, temperature == 0 ? true : false);
+ } else if (temperature == 0) {
+ temperature = 5600;
+ }
+
+ if (temperature != 0 && m_v4l2Info.colorTemperatureSupported) {
+ temperature = qBound(m_v4l2Info.minColorTemp, temperature, m_v4l2Info.maxColorTemp);
+ if (!setV4L2Parameter(
+ V4L2_CID_WHITE_BALANCE_TEMPERATURE,
+ qBound(m_v4l2Info.minColorTemp, temperature, m_v4l2Info.maxColorTemp)))
+ temperature = 0;
+ } else {
+ temperature = 0;
+ }
+
+ return temperature;
+}
+
+bool QV4L2Camera::setV4L2Parameter(quint32 id, qint32 value)
+{
+ v4l2_control control{ id, value };
+ if (!m_v4l2FileDescriptor->call(VIDIOC_S_CTRL, &control)) {
+ qWarning() << "Unable to set the V4L2 Parameter" << Qt::hex << id << "to" << value << qt_error_string(errno);
+ return false;
+ }
+ return true;
+}
+
+int QV4L2Camera::getV4L2Parameter(quint32 id) const
+{
+ struct v4l2_control control{id, 0};
+ if (!m_v4l2FileDescriptor->call(VIDIOC_G_CTRL, &control)) {
+ qWarning() << "Unable to get the V4L2 Parameter" << Qt::hex << id << qt_error_string(errno);
+ return 0;
+ }
+ return control.value;
+}
+
+void QV4L2Camera::setV4L2CameraFormat()
+{
+ if (m_v4l2Info.formatInitialized || !m_v4l2FileDescriptor)
+ return;
+
+ Q_ASSERT(!m_cameraFormat.isNull());
+ qCDebug(qLcV4L2Camera) << "XXXXX" << this << m_cameraDevice.id() << m_cameraFormat.pixelFormat()
+ << m_cameraFormat.resolution();
+
+ v4l2_format fmt = {};
+ fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+ auto size = m_cameraFormat.resolution();
+ fmt.fmt.pix.width = size.width();
+ fmt.fmt.pix.height = size.height();
+ fmt.fmt.pix.pixelformat = v4l2FormatForPixelFormat(m_cameraFormat.pixelFormat());
+ fmt.fmt.pix.field = V4L2_FIELD_ANY;
+
+ qCDebug(qLcV4L2Camera) << "setting camera format to" << size << fmt.fmt.pix.pixelformat;
+
+ if (!m_v4l2FileDescriptor->call(VIDIOC_S_FMT, &fmt)) {
+ if (errno == EBUSY) {
+ setCameraBusy();
+ return;
+ }
+ qWarning() << "Couldn't set video format on v4l2 camera" << strerror(errno);
+ }
+
+ m_v4l2Info.formatInitialized = true;
+ m_cameraBusy = false;
+
+ m_bytesPerLine = fmt.fmt.pix.bytesperline;
+ m_imageSize = std::max(fmt.fmt.pix.sizeimage, m_bytesPerLine * fmt.fmt.pix.height);
+
+ switch (v4l2_colorspace(fmt.fmt.pix.colorspace)) {
+ default:
+ case V4L2_COLORSPACE_DCI_P3:
+ m_colorSpace = QVideoFrameFormat::ColorSpace_Undefined;
+ break;
+ case V4L2_COLORSPACE_REC709:
+ m_colorSpace = QVideoFrameFormat::ColorSpace_BT709;
+ break;
+ case V4L2_COLORSPACE_JPEG:
+ m_colorSpace = QVideoFrameFormat::ColorSpace_AdobeRgb;
+ break;
+ case V4L2_COLORSPACE_SRGB:
+ // ##### is this correct???
+ m_colorSpace = QVideoFrameFormat::ColorSpace_BT601;
+ break;
+ case V4L2_COLORSPACE_BT2020:
+ m_colorSpace = QVideoFrameFormat::ColorSpace_BT2020;
+ break;
+ }
+
+ v4l2_streamparm streamParam = {};
+ streamParam.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+ streamParam.parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
+ auto [num, den] = qRealToFraction(1./m_cameraFormat.maxFrameRate());
+ streamParam.parm.capture.timeperframe = { (uint)num, (uint)den };
+ m_v4l2FileDescriptor->call(VIDIOC_S_PARM, &streamParam);
+
+ m_frameDuration = 1000000 * streamParam.parm.capture.timeperframe.numerator
+ / streamParam.parm.capture.timeperframe.denominator;
+}
+
+void QV4L2Camera::initV4L2MemoryTransfer()
+{
+ if (m_cameraBusy)
+ return;
+
+ Q_ASSERT(!m_memoryTransfer);
+
+ m_memoryTransfer = makeUserPtrMemoryTransfer(m_v4l2FileDescriptor, m_imageSize);
+
+ if (m_memoryTransfer)
+ return;
+
+ if (errno == EBUSY) {
+ setCameraBusy();
+ return;
+ }
+
+ qCDebug(qLcV4L2Camera) << "Cannot init V4L2_MEMORY_USERPTR; trying V4L2_MEMORY_MMAP";
+
+ m_memoryTransfer = makeMMapMemoryTransfer(m_v4l2FileDescriptor);
+
+ if (!m_memoryTransfer) {
+ qCWarning(qLcV4L2Camera) << "Cannot init v4l2 memory transfer," << qt_error_string(errno);
+ updateError(QCamera::CameraError, QLatin1String("Cannot init V4L2 memory transfer"));
+ }
+}
+
+void QV4L2Camera::stopCapturing()
+{
+ if (!m_memoryTransfer || !m_v4l2FileDescriptor)
+ return;
+
+ m_notifier = nullptr;
+
+ if (!m_v4l2FileDescriptor->stopStream()) {
+ // TODO: handle the case carefully to avoid possible memory corruption
+ if (errno != ENODEV)
+ qWarning() << "failed to stop capture";
+ }
+
+ m_memoryTransfer = nullptr;
+ m_cameraBusy = false;
+}
+
+void QV4L2Camera::startCapturing()
+{
+ if (!m_v4l2FileDescriptor)
+ return;
+
+ setV4L2CameraFormat();
+ initV4L2MemoryTransfer();
+
+ if (m_cameraBusy || !m_memoryTransfer)
+ return;
+
+ if (!m_v4l2FileDescriptor->startStream()) {
+ qWarning() << "Couldn't start v4l2 camera stream";
+ return;
+ }
+
+ m_notifier =
+ std::make_unique<QSocketNotifier>(m_v4l2FileDescriptor->get(), QSocketNotifier::Read);
+ connect(m_notifier.get(), &QSocketNotifier::activated, this, &QV4L2Camera::readFrame);
+
+ m_firstFrameTime = { -1, -1 };
+}
+
+QVideoFrameFormat QV4L2Camera::frameFormat() const
+{
+ auto result = QPlatformCamera::frameFormat();
+ result.setColorSpace(m_colorSpace);
+ return result;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qv4l2camera_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qv4l2camera_p.h b/src/plugins/multimedia/ffmpeg/qv4l2camera_p.h
new file mode 100644
index 000000000..3033f5ff9
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qv4l2camera_p.h
@@ -0,0 +1,133 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QV4L2CAMERA_H
+#define QV4L2CAMERA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformcamera_p.h>
+#include <sys/time.h>
+
+QT_BEGIN_NAMESPACE
+
+class QV4L2FileDescriptor;
+class QV4L2MemoryTransfer;
+class QSocketNotifier;
+
+struct V4L2CameraInfo
+{
+ bool formatInitialized = false;
+
+ bool autoWhiteBalanceSupported = false;
+ bool colorTemperatureSupported = false;
+ bool autoExposureSupported = false;
+ bool manualExposureSupported = false;
+ bool flashSupported = false;
+ bool torchSupported = false;
+ qint32 minColorTemp = 5600; // Daylight...
+ qint32 maxColorTemp = 5600;
+ qint32 minExposure = 0;
+ qint32 maxExposure = 0;
+ qint32 minExposureAdjustment = 0;
+ qint32 maxExposureAdjustment = 0;
+ qint32 minFocus = 0;
+ qint32 maxFocus = 0;
+ qint32 rangedFocus = false;
+
+ int minZoom = 0;
+ int maxZoom = 0;
+};
+
+QVideoFrameFormat::PixelFormat formatForV4L2Format(uint32_t v4l2Format);
+uint32_t v4l2FormatForPixelFormat(QVideoFrameFormat::PixelFormat format);
+
+class QV4L2Camera : public QPlatformCamera
+{
+ Q_OBJECT
+
+public:
+ explicit QV4L2Camera(QCamera *parent);
+ ~QV4L2Camera();
+
+ bool isActive() const override;
+ void setActive(bool active) override;
+
+ void setCamera(const QCameraDevice &camera) override;
+ bool setCameraFormat(const QCameraFormat &format) override;
+ bool resolveCameraFormat(const QCameraFormat &format);
+
+ bool isFocusModeSupported(QCamera::FocusMode mode) const override;
+ void setFocusMode(QCamera::FocusMode /*mode*/) override;
+
+// void setCustomFocusPoint(const QPointF &/*point*/) override;
+ void setFocusDistance(float) override;
+ void zoomTo(float /*newZoomFactor*/, float /*rate*/ = -1.) override;
+
+ void setFlashMode(QCamera::FlashMode /*mode*/) override;
+ bool isFlashModeSupported(QCamera::FlashMode mode) const override;
+ bool isFlashReady() const override;
+
+ void setTorchMode(QCamera::TorchMode /*mode*/) override;
+ bool isTorchModeSupported(QCamera::TorchMode mode) const override;
+
+ void setExposureMode(QCamera::ExposureMode) override;
+ bool isExposureModeSupported(QCamera::ExposureMode mode) const override;
+ void setExposureCompensation(float) override;
+ int isoSensitivity() const override;
+ void setManualIsoSensitivity(int) override;
+ void setManualExposureTime(float) override;
+ float exposureTime() const override;
+
+ bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override;
+ void setWhiteBalanceMode(QCamera::WhiteBalanceMode /*mode*/) override;
+ void setColorTemperature(int /*temperature*/) override;
+
+ QVideoFrameFormat frameFormat() const override;
+
+private Q_SLOTS:
+ void readFrame();
+
+private:
+ void setCameraBusy();
+ void initV4L2Controls();
+ void closeV4L2Fd();
+ int setV4L2ColorTemperature(int temperature);
+ bool setV4L2Parameter(quint32 id, qint32 value);
+ int getV4L2Parameter(quint32 id) const;
+
+ void setV4L2CameraFormat();
+ void initV4L2MemoryTransfer();
+ void startCapturing();
+ void stopCapturing();
+
+private:
+ bool m_active = false;
+ QCameraDevice m_cameraDevice;
+
+ std::unique_ptr<QSocketNotifier> m_notifier;
+ std::unique_ptr<QV4L2MemoryTransfer> m_memoryTransfer;
+ std::shared_ptr<QV4L2FileDescriptor> m_v4l2FileDescriptor;
+
+ V4L2CameraInfo m_v4l2Info;
+
+ timeval m_firstFrameTime = { -1, -1 };
+ quint32 m_bytesPerLine = 0;
+ quint32 m_imageSize = 0;
+ QVideoFrameFormat::ColorSpace m_colorSpace = QVideoFrameFormat::ColorSpace_Undefined;
+ qint64 m_frameDuration = -1;
+ bool m_cameraBusy = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QV4L2CAMERA_H
diff --git a/src/plugins/multimedia/ffmpeg/qv4l2cameradevices.cpp b/src/plugins/multimedia/ffmpeg/qv4l2cameradevices.cpp
new file mode 100644
index 000000000..e450cf7bc
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qv4l2cameradevices.cpp
@@ -0,0 +1,182 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qv4l2cameradevices_p.h"
+#include "qv4l2filedescriptor_p.h"
+#include "qv4l2camera_p.h"
+
+#include <private/qcameradevice_p.h>
+#include <private/qcore_unix_p.h>
+
+#include <qdir.h>
+#include <qfile.h>
+#include <qdebug.h>
+#include <qloggingcategory.h>
+
+#include <linux/videodev2.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcV4L2CameraDevices, "qt.multimedia.ffmpeg.v4l2cameradevices");
+
+static bool areCamerasEqual(QList<QCameraDevice> a, QList<QCameraDevice> b)
+{
+ auto areCamerasDataEqual = [](const QCameraDevice &a, const QCameraDevice &b) {
+ Q_ASSERT(QCameraDevicePrivate::handle(a));
+ Q_ASSERT(QCameraDevicePrivate::handle(b));
+ return *QCameraDevicePrivate::handle(a) == *QCameraDevicePrivate::handle(b);
+ };
+
+ return std::equal(a.cbegin(), a.cend(), b.cbegin(), b.cend(), areCamerasDataEqual);
+}
+
+QV4L2CameraDevices::QV4L2CameraDevices(QPlatformMediaIntegration *integration)
+ : QPlatformVideoDevices(integration)
+{
+ m_deviceWatcher.addPath(QLatin1String("/dev"));
+ connect(&m_deviceWatcher, &QFileSystemWatcher::directoryChanged, this,
+ &QV4L2CameraDevices::checkCameras);
+ doCheckCameras();
+}
+
+QList<QCameraDevice> QV4L2CameraDevices::videoDevices() const
+{
+ return m_cameras;
+}
+
+void QV4L2CameraDevices::checkCameras()
+{
+ if (doCheckCameras())
+ emit videoInputsChanged();
+}
+
+bool QV4L2CameraDevices::doCheckCameras()
+{
+ QList<QCameraDevice> newCameras;
+
+ QDir dir(QLatin1String("/dev"));
+ const auto devices = dir.entryList(QDir::System);
+
+ bool first = true;
+
+ for (auto device : devices) {
+ // qCDebug(qLcV4L2Camera) << "device:" << device;
+ if (!device.startsWith(QLatin1String("video")))
+ continue;
+
+ QByteArray file = QFile::encodeName(dir.filePath(device));
+ const int fd = open(file.constData(), O_RDONLY);
+ if (fd < 0)
+ continue;
+
+ auto fileCloseGuard = qScopeGuard([fd]() { close(fd); });
+
+ v4l2_fmtdesc formatDesc = {};
+
+ struct v4l2_capability cap;
+ if (xioctl(fd, VIDIOC_QUERYCAP, &cap) < 0)
+ continue;
+
+ if (cap.device_caps & V4L2_CAP_META_CAPTURE)
+ continue;
+ if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
+ continue;
+ if (!(cap.capabilities & V4L2_CAP_STREAMING))
+ continue;
+
+ auto camera = std::make_unique<QCameraDevicePrivate>();
+
+ camera->id = file;
+ camera->description = QString::fromUtf8((const char *)cap.card);
+ qCDebug(qLcV4L2CameraDevices) << "found camera" << camera->id << camera->description;
+
+ formatDesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+ while (!xioctl(fd, VIDIOC_ENUM_FMT, &formatDesc)) {
+ auto pixelFmt = formatForV4L2Format(formatDesc.pixelformat);
+ qCDebug(qLcV4L2CameraDevices) << " " << pixelFmt;
+
+ if (pixelFmt == QVideoFrameFormat::Format_Invalid) {
+ ++formatDesc.index;
+ continue;
+ }
+
+ qCDebug(qLcV4L2CameraDevices) << "frame sizes:";
+ v4l2_frmsizeenum frameSize = {};
+ frameSize.pixel_format = formatDesc.pixelformat;
+
+ while (!xioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frameSize)) {
+ QList<QSize> resolutions;
+ if (frameSize.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
+ resolutions.append(QSize(frameSize.discrete.width,
+ frameSize.discrete.height));
+ } else {
+ resolutions.append(QSize(frameSize.stepwise.max_width,
+ frameSize.stepwise.max_height));
+ resolutions.append(QSize(frameSize.stepwise.min_width,
+ frameSize.stepwise.min_height));
+ }
+
+ for (auto resolution : resolutions) {
+ float min = 1e10;
+ float max = 0;
+ auto updateMaxMinFrameRate = [&max, &min](auto discreteFrameRate) {
+ const float rate = float(discreteFrameRate.denominator)
+ / float(discreteFrameRate.numerator);
+ if (rate > max)
+ max = rate;
+ if (rate < min)
+ min = rate;
+ };
+
+ v4l2_frmivalenum frameInterval = {};
+ frameInterval.pixel_format = formatDesc.pixelformat;
+ frameInterval.width = resolution.width();
+ frameInterval.height = resolution.height();
+
+ while (!xioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frameInterval)) {
+ if (frameInterval.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
+ updateMaxMinFrameRate(frameInterval.discrete);
+ } else {
+ updateMaxMinFrameRate(frameInterval.stepwise.max);
+ updateMaxMinFrameRate(frameInterval.stepwise.min);
+ }
+ ++frameInterval.index;
+ }
+
+ qCDebug(qLcV4L2CameraDevices) << " " << resolution << min << max;
+
+ if (min <= max) {
+ auto fmt = std::make_unique<QCameraFormatPrivate>();
+ fmt->pixelFormat = pixelFmt;
+ fmt->resolution = resolution;
+ fmt->minFrameRate = min;
+ fmt->maxFrameRate = max;
+ camera->videoFormats.append(fmt.release()->create());
+ camera->photoResolutions.append(resolution);
+ }
+ }
+ ++frameSize.index;
+ }
+ ++formatDesc.index;
+ }
+
+ if (camera->videoFormats.empty())
+ continue;
+
+ // first camera is default
+ camera->isDefault = std::exchange(first, false);
+
+ newCameras.append(camera.release()->create());
+ }
+
+ if (areCamerasEqual(m_cameras, newCameras))
+ return false;
+
+ m_cameras = std::move(newCameras);
+ return true;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qv4l2cameradevices_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/qv4l2cameradevices_p.h b/src/plugins/multimedia/ffmpeg/qv4l2cameradevices_p.h
new file mode 100644
index 000000000..ce424d3b6
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qv4l2cameradevices_p.h
@@ -0,0 +1,46 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QV4L2CAMERADEVICES_P_H
+#define QV4L2CAMERADEVICES_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformvideodevices_p.h>
+#include <private/qplatformmediaintegration_p.h>
+
+#include <qfilesystemwatcher.h>
+
+QT_BEGIN_NAMESPACE
+
+class QV4L2CameraDevices : public QPlatformVideoDevices
+{
+ Q_OBJECT
+public:
+ QV4L2CameraDevices(QPlatformMediaIntegration *integration);
+
+ QList<QCameraDevice> videoDevices() const override;
+
+public Q_SLOTS:
+ void checkCameras();
+
+private:
+ bool doCheckCameras();
+
+private:
+ QList<QCameraDevice> m_cameras;
+ QFileSystemWatcher m_deviceWatcher;
+};
+
+QT_END_NAMESPACE
+
+#endif // QV4L2CAMERADEVICES_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qv4l2filedescriptor.cpp b/src/plugins/multimedia/ffmpeg/qv4l2filedescriptor.cpp
new file mode 100644
index 000000000..7f7b099c7
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qv4l2filedescriptor.cpp
@@ -0,0 +1,71 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qv4l2filedescriptor_p.h"
+
+#include <sys/ioctl.h>
+#include <private/qcore_unix_p.h>
+
+#include <linux/videodev2.h>
+
+QT_BEGIN_NAMESPACE
+
+int xioctl(int fd, int request, void *arg)
+{
+ int res;
+
+ do {
+ res = ::ioctl(fd, request, arg);
+ } while (res == -1 && EINTR == errno);
+
+ return res;
+}
+
+QV4L2FileDescriptor::QV4L2FileDescriptor(int descriptor) : m_descriptor(descriptor)
+{
+ Q_ASSERT(descriptor >= 0);
+}
+
+QV4L2FileDescriptor::~QV4L2FileDescriptor()
+{
+ qt_safe_close(m_descriptor);
+}
+
+bool QV4L2FileDescriptor::call(int request, void *arg) const
+{
+ return ::xioctl(m_descriptor, request, arg) >= 0;
+}
+
+bool QV4L2FileDescriptor::requestBuffers(quint32 memoryType, quint32 &buffersCount) const
+{
+ v4l2_requestbuffers req = {};
+ req.count = buffersCount;
+ req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ req.memory = memoryType;
+
+ if (!call(VIDIOC_REQBUFS, &req))
+ return false;
+
+ buffersCount = req.count;
+ return true;
+}
+
+bool QV4L2FileDescriptor::startStream()
+{
+ int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ if (!call(VIDIOC_STREAMON, &type))
+ return false;
+
+ m_streamStarted = true;
+ return true;
+}
+
+bool QV4L2FileDescriptor::stopStream()
+{
+ int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ auto result = call(VIDIOC_STREAMOFF, &type);
+ m_streamStarted = false;
+ return result;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qv4l2filedescriptor_p.h b/src/plugins/multimedia/ffmpeg/qv4l2filedescriptor_p.h
new file mode 100644
index 000000000..1058c7a82
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qv4l2filedescriptor_p.h
@@ -0,0 +1,50 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QV4L2FILEDESCRIPTOR_P_H
+#define QV4L2FILEDESCRIPTOR_P_H
+
+#include <private/qtmultimediaglobal_p.h>
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+int xioctl(int fd, int request, void *arg);
+
+class QV4L2FileDescriptor
+{
+public:
+ QV4L2FileDescriptor(int descriptor);
+
+ ~QV4L2FileDescriptor();
+
+ bool call(int request, void *arg) const;
+
+ int get() const { return m_descriptor; }
+
+ bool requestBuffers(quint32 memoryType, quint32 &buffersCount) const;
+
+ bool startStream();
+
+ bool stopStream();
+
+ bool streamStarted() const { return m_streamStarted; }
+
+private:
+ int m_descriptor;
+ bool m_streamStarted = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QV4L2FILEDESCRIPTOR_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qv4l2memorytransfer.cpp b/src/plugins/multimedia/ffmpeg/qv4l2memorytransfer.cpp
new file mode 100644
index 000000000..32ee4f8f8
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qv4l2memorytransfer.cpp
@@ -0,0 +1,223 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qv4l2memorytransfer_p.h"
+#include "qv4l2filedescriptor_p.h"
+
+#include <qloggingcategory.h>
+#include <qdebug.h>
+#include <sys/mman.h>
+#include <optional>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcV4L2MemoryTransfer, "qt.multimedia.ffmpeg.v4l2camera.memorytransfer");
+
+namespace {
+
+v4l2_buffer makeV4l2Buffer(quint32 memoryType, quint32 index = 0)
+{
+ v4l2_buffer buf = {};
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = memoryType;
+ buf.index = index;
+ return buf;
+}
+
+class UserPtrMemoryTransfer : public QV4L2MemoryTransfer
+{
+public:
+ static QV4L2MemoryTransferUPtr create(QV4L2FileDescriptorPtr fileDescriptor, quint32 imageSize)
+ {
+ quint32 buffersCount = 2;
+ if (!fileDescriptor->requestBuffers(V4L2_MEMORY_USERPTR, buffersCount)) {
+ qCWarning(qLcV4L2MemoryTransfer) << "Cannot request V4L2_MEMORY_USERPTR buffers";
+ return {};
+ }
+
+ std::unique_ptr<UserPtrMemoryTransfer> result(
+ new UserPtrMemoryTransfer(std::move(fileDescriptor), buffersCount, imageSize));
+
+ return result->enqueueBuffers() ? std::move(result) : nullptr;
+ }
+
+ std::optional<Buffer> dequeueBuffer() override
+ {
+ auto v4l2Buffer = makeV4l2Buffer(V4L2_MEMORY_USERPTR);
+ if (!fileDescriptor().call(VIDIOC_DQBUF, &v4l2Buffer))
+ return {};
+
+ Q_ASSERT(v4l2Buffer.index < m_byteArrays.size());
+ Q_ASSERT(!m_byteArrays[v4l2Buffer.index].isEmpty());
+
+ return Buffer{ v4l2Buffer, std::move(m_byteArrays[v4l2Buffer.index]) };
+ }
+
+ bool enqueueBuffer(quint32 index) override
+ {
+ Q_ASSERT(index < m_byteArrays.size());
+ Q_ASSERT(m_byteArrays[index].isEmpty());
+
+ auto buf = makeV4l2Buffer(V4L2_MEMORY_USERPTR, index);
+ static_assert(sizeof(decltype(buf.m.userptr)) == sizeof(size_t), "Not compatible sizes");
+
+ m_byteArrays[index] = QByteArray(static_cast<int>(m_imageSize), Qt::Uninitialized);
+
+ buf.m.userptr = (decltype(buf.m.userptr))m_byteArrays[index].data();
+ buf.length = m_byteArrays[index].size();
+
+ if (!fileDescriptor().call(VIDIOC_QBUF, &buf)) {
+ qWarning() << "Couldn't add V4L2 buffer" << errno << strerror(errno) << index;
+ return false;
+ }
+
+ return true;
+ }
+
+ quint32 buffersCount() const override { return static_cast<quint32>(m_byteArrays.size()); }
+
+private:
+ UserPtrMemoryTransfer(QV4L2FileDescriptorPtr fileDescriptor, quint32 buffersCount,
+ quint32 imageSize)
+ : QV4L2MemoryTransfer(std::move(fileDescriptor)),
+ m_imageSize(imageSize),
+ m_byteArrays(buffersCount)
+ {
+ }
+
+private:
+ quint32 m_imageSize;
+ std::vector<QByteArray> m_byteArrays;
+};
+
+class MMapMemoryTransfer : public QV4L2MemoryTransfer
+{
+public:
+ struct MemorySpan
+ {
+ void *data = nullptr;
+ size_t size = 0;
+ bool inQueue = false;
+ };
+
+ static QV4L2MemoryTransferUPtr create(QV4L2FileDescriptorPtr fileDescriptor)
+ {
+ quint32 buffersCount = 2;
+ if (!fileDescriptor->requestBuffers(V4L2_MEMORY_MMAP, buffersCount)) {
+ qCWarning(qLcV4L2MemoryTransfer) << "Cannot request V4L2_MEMORY_MMAP buffers";
+ return {};
+ }
+
+ std::unique_ptr<MMapMemoryTransfer> result(
+ new MMapMemoryTransfer(std::move(fileDescriptor)));
+
+ return result->init(buffersCount) ? std::move(result) : nullptr;
+ }
+
+ bool init(quint32 buffersCount)
+ {
+ for (quint32 index = 0; index < buffersCount; ++index) {
+ auto buf = makeV4l2Buffer(V4L2_MEMORY_MMAP, index);
+
+ if (!fileDescriptor().call(VIDIOC_QUERYBUF, &buf)) {
+ qWarning() << "Can't map buffer" << index;
+ return false;
+ }
+
+ auto mappedData = mmap(nullptr, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED,
+ fileDescriptor().get(), buf.m.offset);
+
+ if (mappedData == MAP_FAILED) {
+ qWarning() << "mmap failed" << index << buf.length << buf.m.offset;
+ return false;
+ }
+
+ m_spans.push_back(MemorySpan{ mappedData, buf.length, false });
+ }
+
+ m_spans.shrink_to_fit();
+
+ return enqueueBuffers();
+ }
+
+ ~MMapMemoryTransfer() override
+ {
+ for (const auto &span : m_spans)
+ munmap(span.data, span.size);
+ }
+
+ std::optional<Buffer> dequeueBuffer() override
+ {
+ auto v4l2Buffer = makeV4l2Buffer(V4L2_MEMORY_MMAP);
+ if (!fileDescriptor().call(VIDIOC_DQBUF, &v4l2Buffer))
+ return {};
+
+ const auto index = v4l2Buffer.index;
+
+ Q_ASSERT(index < m_spans.size());
+
+ auto &span = m_spans[index];
+
+ Q_ASSERT(span.inQueue);
+ span.inQueue = false;
+
+ return Buffer{ v4l2Buffer,
+ QByteArray(reinterpret_cast<const char *>(span.data), span.size) };
+ }
+
+ bool enqueueBuffer(quint32 index) override
+ {
+ Q_ASSERT(index < m_spans.size());
+ Q_ASSERT(!m_spans[index].inQueue);
+
+ auto buf = makeV4l2Buffer(V4L2_MEMORY_MMAP, index);
+ if (!fileDescriptor().call(VIDIOC_QBUF, &buf))
+ return false;
+
+ m_spans[index].inQueue = true;
+ return true;
+ }
+
+ quint32 buffersCount() const override { return static_cast<quint32>(m_spans.size()); }
+
+private:
+ using QV4L2MemoryTransfer::QV4L2MemoryTransfer;
+
+private:
+ std::vector<MemorySpan> m_spans;
+};
+} // namespace
+
+QV4L2MemoryTransfer::QV4L2MemoryTransfer(QV4L2FileDescriptorPtr fileDescriptor)
+ : m_fileDescriptor(std::move(fileDescriptor))
+{
+ Q_ASSERT(m_fileDescriptor);
+ Q_ASSERT(!m_fileDescriptor->streamStarted());
+}
+
+QV4L2MemoryTransfer::~QV4L2MemoryTransfer()
+{
+ Q_ASSERT(!m_fileDescriptor->streamStarted()); // to avoid possible corruptions
+}
+
+bool QV4L2MemoryTransfer::enqueueBuffers()
+{
+ for (quint32 i = 0; i < buffersCount(); ++i)
+ if (!enqueueBuffer(i))
+ return false;
+
+ return true;
+}
+
+QV4L2MemoryTransferUPtr makeUserPtrMemoryTransfer(QV4L2FileDescriptorPtr fileDescriptor,
+ quint32 imageSize)
+{
+ return UserPtrMemoryTransfer::create(std::move(fileDescriptor), imageSize);
+}
+
+QV4L2MemoryTransferUPtr makeMMapMemoryTransfer(QV4L2FileDescriptorPtr fileDescriptor)
+{
+ return MMapMemoryTransfer::create(std::move(fileDescriptor));
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qv4l2memorytransfer_p.h b/src/plugins/multimedia/ffmpeg/qv4l2memorytransfer_p.h
new file mode 100644
index 000000000..6b5e3913f
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qv4l2memorytransfer_p.h
@@ -0,0 +1,66 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QV4L2MEMORYTRANSFER_P_H
+#define QV4L2MEMORYTRANSFER_P_H
+
+#include <private/qtmultimediaglobal_p.h>
+#include <qbytearray.h>
+#include <linux/videodev2.h>
+
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+class QV4L2FileDescriptor;
+using QV4L2FileDescriptorPtr = std::shared_ptr<QV4L2FileDescriptor>;
+
+class QV4L2MemoryTransfer
+{
+public:
+ struct Buffer
+ {
+ v4l2_buffer v4l2Buffer = {};
+ QByteArray data;
+ };
+
+ QV4L2MemoryTransfer(QV4L2FileDescriptorPtr fileDescriptor);
+
+ virtual ~QV4L2MemoryTransfer();
+
+ virtual std::optional<Buffer> dequeueBuffer() = 0;
+
+ virtual bool enqueueBuffer(quint32 index) = 0;
+
+ virtual quint32 buffersCount() const = 0;
+
+protected:
+ bool enqueueBuffers();
+
+ const QV4L2FileDescriptor &fileDescriptor() const { return *m_fileDescriptor; }
+
+private:
+ QV4L2FileDescriptorPtr m_fileDescriptor;
+};
+
+using QV4L2MemoryTransferUPtr = std::unique_ptr<QV4L2MemoryTransfer>;
+
+QV4L2MemoryTransferUPtr makeUserPtrMemoryTransfer(QV4L2FileDescriptorPtr fileDescriptor,
+ quint32 imageSize);
+
+QV4L2MemoryTransferUPtr makeMMapMemoryTransfer(QV4L2FileDescriptorPtr fileDescriptor);
+
+QT_END_NAMESPACE
+
+#endif // QV4L2MEMORYTRANSFER_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qwincapturablewindows.cpp b/src/plugins/multimedia/ffmpeg/qwincapturablewindows.cpp
new file mode 100644
index 000000000..aac77aec4
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qwincapturablewindows.cpp
@@ -0,0 +1,74 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwincapturablewindows_p.h"
+#include "private/qcapturablewindow_p.h"
+
+#include <qt_windows.h>
+
+QT_BEGIN_NAMESPACE
+
+static bool isTopLevelWindow(HWND hwnd)
+{
+ return hwnd && ::GetAncestor(hwnd, GA_ROOT) == hwnd;
+}
+
+static bool canCaptureWindow(HWND hwnd)
+{
+ Q_ASSERT(hwnd);
+
+ if (!::IsWindowVisible(hwnd))
+ return false;
+
+ RECT rect{};
+ if (!::GetWindowRect(hwnd, &rect))
+ return false;
+
+ if (rect.left >= rect.right || rect.top >= rect.bottom)
+ return false;
+
+ return true;
+}
+
+static QString windowTitle(HWND hwnd) {
+ // QTBUG-114890
+ // TODO: investigate the case when hwnd is inner and belows to another thread.
+ // It might causes deadlocks in specific cases.
+ auto titleLength = ::GetWindowTextLengthW(hwnd);
+ std::wstring buffer(titleLength + 1, L'\0');
+ titleLength = ::GetWindowTextW(hwnd, buffer.data(), titleLength + 1);
+ buffer.resize(titleLength);
+
+ return QString::fromStdWString(buffer);
+}
+
+QList<QCapturableWindow> QWinCapturableWindows::windows() const
+{
+ QList<QCapturableWindow> result;
+
+ auto windowHandler = [](HWND hwnd, LPARAM lParam) {
+ if (!canCaptureWindow(hwnd))
+ return TRUE; // Ignore window and continue enumerating
+
+ auto& windows = *reinterpret_cast<QList<QCapturableWindow>*>(lParam);
+
+ auto windowData = std::make_unique<QCapturableWindowPrivate>();
+ windowData->id = reinterpret_cast<QCapturableWindowPrivate::Id>(hwnd);
+ windowData->description = windowTitle(hwnd);
+ windows.push_back(windowData.release()->create());
+
+ return TRUE;
+ };
+
+ ::EnumWindows(windowHandler, reinterpret_cast<LPARAM>(&result));
+
+ return result;
+}
+
+bool QWinCapturableWindows::isWindowValid(const QCapturableWindowPrivate &window) const
+{
+ const auto hwnd = reinterpret_cast<HWND>(window.id);
+ return isTopLevelWindow(hwnd) && canCaptureWindow(hwnd);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qwincapturablewindows_p.h b/src/plugins/multimedia/ffmpeg/qwincapturablewindows_p.h
new file mode 100644
index 000000000..1e38708ef
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qwincapturablewindows_p.h
@@ -0,0 +1,32 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINCAPTURABLEWINDOWS_P_H
+#define QWINCAPTURABLEWINDOWS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qplatformcapturablewindows_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QWinCapturableWindows : public QPlatformCapturableWindows
+{
+public:
+ QList<QCapturableWindow> windows() const override;
+
+ bool isWindowValid(const QCapturableWindowPrivate &window) const override;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWINCAPTURABLEWINDOWS_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qwindowscamera.cpp b/src/plugins/multimedia/ffmpeg/qwindowscamera.cpp
new file mode 100644
index 000000000..61a4ebe52
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qwindowscamera.cpp
@@ -0,0 +1,330 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowscamera_p.h"
+#include "qsemaphore.h"
+#include "qmutex.h"
+
+#include <private/qmemoryvideobuffer_p.h>
+#include <private/qwindowsmfdefs_p.h>
+#include <private/qwindowsmultimediautils_p.h>
+#include <private/qvideoframe_p.h>
+#include <private/qcomobject_p.h>
+
+#include <mfapi.h>
+#include <mfidl.h>
+#include <mferror.h>
+#include <mfreadwrite.h>
+
+#include <system_error>
+
+QT_BEGIN_NAMESPACE
+
+using namespace QWindowsMultimediaUtils;
+
+class CameraReaderCallback : public QComObject<IMFSourceReaderCallback>
+{
+public:
+ //from IMFSourceReaderCallback
+ STDMETHODIMP OnReadSample(HRESULT status, DWORD, DWORD, LONGLONG timestamp, IMFSample *sample) override;
+ STDMETHODIMP OnFlush(DWORD) override;
+ STDMETHODIMP OnEvent(DWORD, IMFMediaEvent *) override { return S_OK; }
+
+ void setActiveCamera(ActiveCamera *activeCamera)
+ {
+ QMutexLocker locker(&m_mutex);
+ m_activeCamera = activeCamera;
+ }
+private:
+ // Destructor is not public. Caller should call Release.
+ ~CameraReaderCallback() override = default;
+
+ ActiveCamera *m_activeCamera = nullptr;
+ QMutex m_mutex;
+};
+
+static ComPtr<IMFSourceReader> createCameraReader(IMFMediaSource *mediaSource,
+ const ComPtr<CameraReaderCallback> &callback)
+{
+ ComPtr<IMFSourceReader> sourceReader;
+ ComPtr<IMFAttributes> readerAttributes;
+
+ HRESULT hr = MFCreateAttributes(readerAttributes.GetAddressOf(), 1);
+ if (SUCCEEDED(hr)) {
+ hr = readerAttributes->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, callback.Get());
+ if (SUCCEEDED(hr)) {
+ hr = MFCreateSourceReaderFromMediaSource(mediaSource, readerAttributes.Get(), sourceReader.GetAddressOf());
+ if (SUCCEEDED(hr))
+ return sourceReader;
+ }
+ }
+
+ qWarning() << "Failed to create camera IMFSourceReader" << hr;
+ return sourceReader;
+}
+
+static ComPtr<IMFMediaSource> createCameraSource(const QString &deviceId)
+{
+ ComPtr<IMFMediaSource> mediaSource;
+ ComPtr<IMFAttributes> sourceAttributes;
+ HRESULT hr = MFCreateAttributes(sourceAttributes.GetAddressOf(), 2);
+ if (SUCCEEDED(hr)) {
+ hr = sourceAttributes->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, QMM_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);
+ if (SUCCEEDED(hr)) {
+ hr = sourceAttributes->SetString(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK,
+ reinterpret_cast<LPCWSTR>(deviceId.utf16()));
+ if (SUCCEEDED(hr)) {
+ hr = MFCreateDeviceSource(sourceAttributes.Get(), mediaSource.GetAddressOf());
+ if (SUCCEEDED(hr))
+ return mediaSource;
+ }
+ }
+ }
+ qWarning() << "Failed to create camera IMFMediaSource" << hr;
+ return mediaSource;
+}
+
+static int calculateVideoFrameStride(IMFMediaType *videoType, int width)
+{
+ Q_ASSERT(videoType);
+
+ GUID subtype = GUID_NULL;
+ HRESULT hr = videoType->GetGUID(MF_MT_SUBTYPE, &subtype);
+ if (SUCCEEDED(hr)) {
+ LONG stride = 0;
+ hr = MFGetStrideForBitmapInfoHeader(subtype.Data1, width, &stride);
+ if (SUCCEEDED(hr))
+ return int(qAbs(stride));
+ }
+
+ qWarning() << "Failed to calculate video stride" << errorString(hr);
+ return 0;
+}
+
+static bool setCameraReaderFormat(IMFSourceReader *sourceReader, IMFMediaType *videoType)
+{
+ Q_ASSERT(sourceReader);
+ Q_ASSERT(videoType);
+
+ HRESULT hr = sourceReader->SetCurrentMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM, nullptr,
+ videoType);
+ if (FAILED(hr))
+ qWarning() << "Failed to set video format" << errorString(hr);
+
+ return SUCCEEDED(hr);
+}
+
+static ComPtr<IMFMediaType> findVideoType(IMFSourceReader *reader,
+ const QCameraFormat &format)
+{
+ for (DWORD i = 0;; ++i) {
+ ComPtr<IMFMediaType> candidate;
+ HRESULT hr = reader->GetNativeMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM, i,
+ candidate.GetAddressOf());
+ if (FAILED(hr))
+ break;
+
+ GUID subtype = GUID_NULL;
+ if (FAILED(candidate->GetGUID(MF_MT_SUBTYPE, &subtype)))
+ continue;
+
+ if (format.pixelFormat() != pixelFormatFromMediaSubtype(subtype))
+ continue;
+
+ UINT32 width = 0u;
+ UINT32 height = 0u;
+ if (FAILED(MFGetAttributeSize(candidate.Get(), MF_MT_FRAME_SIZE, &width, &height)))
+ continue;
+
+ if (format.resolution() != QSize{ int(width), int(height) })
+ continue;
+
+ return candidate;
+ }
+ return {};
+}
+
+class ActiveCamera {
+public:
+ static std::unique_ptr<ActiveCamera> create(QWindowsCamera &wc, const QCameraDevice &device, const QCameraFormat &format)
+ {
+ auto ac = std::unique_ptr<ActiveCamera>(new ActiveCamera(wc));
+ ac->m_source = createCameraSource(device.id());
+ if (!ac->m_source)
+ return {};
+
+ ac->m_readerCallback = makeComObject<CameraReaderCallback>();
+ ac->m_readerCallback->setActiveCamera(ac.get());
+ ac->m_reader = createCameraReader(ac->m_source.Get(), ac->m_readerCallback);
+ if (!ac->m_reader)
+ return {};
+
+ if (!ac->setFormat(format))
+ return {};
+
+ return ac;
+ }
+
+ bool setFormat(const QCameraFormat &format)
+ {
+ flush();
+
+ auto videoType = findVideoType(m_reader.Get(), format);
+ if (videoType) {
+ if (setCameraReaderFormat(m_reader.Get(), videoType.Get())) {
+ m_frameFormat = { format.resolution(), format.pixelFormat() };
+ m_videoFrameStride =
+ calculateVideoFrameStride(videoType.Get(), format.resolution().width());
+ }
+ }
+
+ m_reader->ReadSample(MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, nullptr, nullptr, nullptr,
+ nullptr);
+ return true;
+ }
+
+ void onReadSample(HRESULT status, LONGLONG timestamp, IMFSample *sample)
+ {
+ if (FAILED(status)) {
+ const std::string msg{ std::system_category().message(status) };
+ m_windowsCamera.updateError(QCamera::CameraError, QString::fromStdString(msg));
+ return;
+ }
+
+ if (sample) {
+ ComPtr<IMFMediaBuffer> mediaBuffer;
+ if (SUCCEEDED(sample->ConvertToContiguousBuffer(mediaBuffer.GetAddressOf()))) {
+
+ DWORD bufLen = 0;
+ BYTE *buffer = nullptr;
+ if (SUCCEEDED(mediaBuffer->Lock(&buffer, nullptr, &bufLen))) {
+ QByteArray bytes(reinterpret_cast<char*>(buffer), qsizetype(bufLen));
+ auto buffer = std::make_unique<QMemoryVideoBuffer>(std::move(bytes),
+ m_videoFrameStride);
+ QVideoFrame frame =
+ QVideoFramePrivate::createFrame(std::move(buffer), m_frameFormat);
+
+ // WMF uses 100-nanosecond units, Qt uses microseconds
+ frame.setStartTime(timestamp / 10);
+
+ LONGLONG duration = -1;
+ if (SUCCEEDED(sample->GetSampleDuration(&duration)))
+ frame.setEndTime((timestamp + duration) / 10);
+
+ emit m_windowsCamera.newVideoFrame(frame);
+ mediaBuffer->Unlock();
+ }
+ }
+ }
+
+ m_reader->ReadSample(MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, nullptr,
+ nullptr, nullptr, nullptr);
+ }
+
+ void onFlush()
+ {
+ m_flushWait.release();
+ }
+
+ ~ActiveCamera()
+ {
+ flush();
+ m_readerCallback->setActiveCamera(nullptr);
+ }
+
+private:
+ explicit ActiveCamera(QWindowsCamera &wc) : m_windowsCamera(wc), m_flushWait(0) {};
+
+ void flush()
+ {
+ if (SUCCEEDED(m_reader->Flush(MF_SOURCE_READER_FIRST_VIDEO_STREAM))) {
+ m_flushWait.acquire();
+ }
+ }
+
+ QWindowsCamera &m_windowsCamera;
+
+ QSemaphore m_flushWait;
+
+ ComPtr<IMFMediaSource> m_source;
+ ComPtr<IMFSourceReader> m_reader;
+ ComPtr<CameraReaderCallback> m_readerCallback;
+
+ QVideoFrameFormat m_frameFormat;
+ int m_videoFrameStride = 0;
+};
+
+STDMETHODIMP CameraReaderCallback::OnReadSample(HRESULT status, DWORD, DWORD, LONGLONG timestamp, IMFSample *sample)
+{
+ QMutexLocker locker(&m_mutex);
+ if (m_activeCamera)
+ m_activeCamera->onReadSample(status, timestamp, sample);
+
+ return status;
+}
+
+STDMETHODIMP CameraReaderCallback::OnFlush(DWORD)
+{
+ QMutexLocker locker(&m_mutex);
+ if (m_activeCamera)
+ m_activeCamera->onFlush();
+ return S_OK;
+}
+
+QWindowsCamera::QWindowsCamera(QCamera *camera)
+ : QPlatformCamera(camera)
+{
+ m_cameraDevice = camera ? camera->cameraDevice() : QCameraDevice{};
+}
+
+QWindowsCamera::~QWindowsCamera()
+{
+ QWindowsCamera::setActive(false);
+}
+
+void QWindowsCamera::setActive(bool active)
+{
+ if (bool(m_active) == active)
+ return;
+
+ if (active) {
+ if (m_cameraDevice.isNull())
+ return;
+
+ if (m_cameraFormat.isNull())
+ m_cameraFormat = findBestCameraFormat(m_cameraDevice);
+
+ m_active = ActiveCamera::create(*this, m_cameraDevice, m_cameraFormat);
+ if (m_active)
+ activeChanged(true);
+
+ } else {
+ m_active.reset();
+ emit activeChanged(false);
+ }
+}
+
+void QWindowsCamera::setCamera(const QCameraDevice &camera)
+{
+ bool active = bool(m_active);
+ if (active)
+ setActive(false);
+ m_cameraDevice = camera;
+ m_cameraFormat = {};
+ if (active)
+ setActive(true);
+}
+
+bool QWindowsCamera::setCameraFormat(const QCameraFormat &format)
+{
+ if (format.isNull())
+ return false;
+
+ bool ok = m_active ? m_active->setFormat(format) : true;
+ if (ok)
+ m_cameraFormat = format;
+
+ return ok;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qwindowscamera_p.h b/src/plugins/multimedia/ffmpeg/qwindowscamera_p.h
new file mode 100644
index 000000000..80c05ff59
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qwindowscamera_p.h
@@ -0,0 +1,45 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSCAMERA_H
+#define QWINDOWSCAMERA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformcamera_p.h>
+#include <private/qcomptr_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class ActiveCamera;
+
+class QWindowsCamera : public QPlatformCamera
+{
+ Q_OBJECT
+
+public:
+ explicit QWindowsCamera(QCamera *parent);
+ ~QWindowsCamera() override;
+
+ bool isActive() const override { return bool(m_active); }
+ void setActive(bool active) override;
+ void setCamera(const QCameraDevice &camera) override;
+ bool setCameraFormat(const QCameraFormat &/*format*/) override;
+
+private:
+ QCameraDevice m_cameraDevice;
+ std::unique_ptr<ActiveCamera> m_active;
+};
+
+QT_END_NAMESPACE
+
+#endif //QWINDOWSCAMERA_H
diff --git a/src/plugins/multimedia/ffmpeg/qx11capturablewindows.cpp b/src/plugins/multimedia/ffmpeg/qx11capturablewindows.cpp
new file mode 100644
index 000000000..9e57cbc64
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qx11capturablewindows.cpp
@@ -0,0 +1,74 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qx11capturablewindows_p.h"
+#include "private/qcapturablewindow_p.h"
+#include <qdebug.h>
+
+#include <X11/Xlib.h>
+
+QT_BEGIN_NAMESPACE
+
+QX11CapturableWindows::~QX11CapturableWindows()
+{
+ if (m_display)
+ XCloseDisplay(m_display);
+}
+
+QList<QCapturableWindow> QX11CapturableWindows::windows() const
+{
+ auto display = this->display();
+
+ if (!display)
+ return {};
+
+ Atom atom = XInternAtom(display, "_NET_CLIENT_LIST", true);
+ Atom actualType = 0;
+ int format = 0;
+ unsigned long windowsCount = 0;
+ unsigned long bytesAfter = 0;
+ unsigned char *data = nullptr;
+ const int status = XGetWindowProperty(display, XDefaultRootWindow(display), atom, 0L, (~0L),
+ false, AnyPropertyType, &actualType, &format,
+ &windowsCount, &bytesAfter, &data);
+
+ if (status < Success || !data)
+ return {};
+
+ QList<QCapturableWindow> result;
+
+ auto freeDataGuard = qScopeGuard([data]() { XFree(data); });
+ auto windows = reinterpret_cast<XID *>(data);
+ for (unsigned long i = 0; i < windowsCount; i++) {
+ auto windowData = std::make_unique<QCapturableWindowPrivate>();
+ windowData->id = static_cast<QCapturableWindowPrivate::Id>(windows[i]);
+
+ char *windowTitle = nullptr;
+ if (XFetchName(display, windows[i], &windowTitle) && windowTitle) {
+ windowData->description = QString::fromUtf8(windowTitle);
+ XFree(windowTitle);
+ }
+
+ if (isWindowValid(*windowData))
+ result.push_back(windowData.release()->create());
+ }
+
+ return result;
+}
+
+bool QX11CapturableWindows::isWindowValid(const QCapturableWindowPrivate &window) const
+{
+ auto display = this->display();
+ XWindowAttributes windowAttributes = {};
+ return display
+ && XGetWindowAttributes(display, static_cast<Window>(window.id), &windowAttributes) != 0
+ && windowAttributes.depth > 0;
+}
+
+Display *QX11CapturableWindows::display() const
+{
+ std::call_once(m_displayOnceFlag, [this]() { m_display = XOpenDisplay(nullptr); });
+ return m_display;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qx11capturablewindows_p.h b/src/plugins/multimedia/ffmpeg/qx11capturablewindows_p.h
new file mode 100644
index 000000000..088fe97cb
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qx11capturablewindows_p.h
@@ -0,0 +1,45 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QX11CAPTURABLEWINDOWS_P_H
+#define QX11CAPTURABLEWINDOWS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qplatformcapturablewindows_p.h"
+#include <mutex>
+
+struct _XDisplay;
+typedef struct _XDisplay Display;
+
+QT_BEGIN_NAMESPACE
+
+class QX11CapturableWindows : public QPlatformCapturableWindows
+{
+public:
+ ~QX11CapturableWindows() override;
+
+ QList<QCapturableWindow> windows() const override;
+
+ bool isWindowValid(const QCapturableWindowPrivate &window) const override;
+
+private:
+ Display *display() const;
+
+private:
+ mutable std::once_flag m_displayOnceFlag;
+ mutable Display *m_display = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QX11CAPTURABLEWINDOWS_P_H
diff --git a/src/plugins/multimedia/ffmpeg/qx11surfacecapture.cpp b/src/plugins/multimedia/ffmpeg/qx11surfacecapture.cpp
new file mode 100644
index 000000000..d9343cdfe
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qx11surfacecapture.cpp
@@ -0,0 +1,342 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qx11surfacecapture_p.h"
+#include "qffmpegsurfacecapturegrabber_p.h"
+
+#include <qvideoframe.h>
+#include <qscreen.h>
+#include <qwindow.h>
+#include <qdebug.h>
+#include <qguiapplication.h>
+#include <qloggingcategory.h>
+
+#include "private/qcapturablewindow_p.h"
+#include "private/qmemoryvideobuffer_p.h"
+#include "private/qvideoframeconversionhelper_p.h"
+#include "private/qvideoframe_p.h"
+
+#include <X11/Xlib.h>
+#include <sys/shm.h>
+#include <X11/extensions/XShm.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/Xrandr.h>
+
+#include <optional>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcX11SurfaceCapture, "qt.multimedia.ffmpeg.qx11surfacecapture");
+
+namespace {
+
+void destroyXImage(XImage* image) {
+ XDestroyImage(image); // macro
+}
+
+template <typename T, typename D>
+std::unique_ptr<T, D> makeXUptr(T* ptr, D deleter) {
+ return std::unique_ptr<T, D>(ptr, deleter);
+}
+
+int screenNumberByName(Display *display, const QString &name)
+{
+ int size = 0;
+ auto monitors = makeXUptr(
+ XRRGetMonitors(display, XDefaultRootWindow(display), true, &size),
+ &XRRFreeMonitors);
+ const auto end = monitors.get() + size;
+ auto found = std::find_if(monitors.get(), end, [&](const XRRMonitorInfo &info) {
+ auto atomName = makeXUptr(XGetAtomName(display, info.name), &XFree);
+ return atomName && name == QString::fromUtf8(atomName.get());
+ });
+
+ return found == end ? -1 : std::distance(monitors.get(), found);
+}
+
+QVideoFrameFormat::PixelFormat xImagePixelFormat(const XImage &image)
+{
+ if (image.bits_per_pixel != 32) return QVideoFrameFormat::Format_Invalid;
+
+ if (image.red_mask == 0xff0000 &&
+ image.green_mask == 0xff00 &&
+ image.blue_mask == 0xff)
+ return QVideoFrameFormat::Format_BGRX8888;
+
+ if (image.red_mask == 0xff00 &&
+ image.green_mask == 0xff0000 &&
+ image.blue_mask == 0xff000000)
+ return QVideoFrameFormat::Format_XBGR8888;
+
+ if (image.blue_mask == 0xff0000 &&
+ image.green_mask == 0xff00 &&
+ image.red_mask == 0xff)
+ return QVideoFrameFormat::Format_RGBX8888;
+
+ if (image.red_mask == 0xff00 &&
+ image.green_mask == 0xff0000 &&
+ image.blue_mask == 0xff000000)
+ return QVideoFrameFormat::Format_XRGB8888;
+
+ return QVideoFrameFormat::Format_Invalid;
+}
+
+} // namespace
+
+class QX11SurfaceCapture::Grabber : private QFFmpegSurfaceCaptureGrabber
+{
+public:
+ static std::unique_ptr<Grabber> create(QX11SurfaceCapture &capture, QScreen *screen)
+ {
+ std::unique_ptr<Grabber> result(new Grabber(capture));
+ return result->init(screen) ? std::move(result) : nullptr;
+ }
+
+ static std::unique_ptr<Grabber> create(QX11SurfaceCapture &capture, WId wid)
+ {
+ std::unique_ptr<Grabber> result(new Grabber(capture));
+ return result->init(wid) ? std::move(result) : nullptr;
+ }
+
+ ~Grabber() override
+ {
+ stop();
+
+ detachShm();
+ }
+
+ const QVideoFrameFormat &format() const { return m_format; }
+
+private:
+ Grabber(QX11SurfaceCapture &capture)
+ {
+ addFrameCallback(capture, &QX11SurfaceCapture::newVideoFrame);
+ connect(this, &Grabber::errorUpdated, &capture, &QX11SurfaceCapture::updateError);
+ }
+
+ bool createDisplay()
+ {
+ if (!m_display)
+ m_display.reset(XOpenDisplay(nullptr));
+
+ if (!m_display)
+ updateError(QPlatformSurfaceCapture::InternalError,
+ QLatin1String("Cannot open X11 display"));
+
+ return m_display != nullptr;
+ }
+
+ bool init(WId wid)
+ {
+ if (auto screen = QGuiApplication::primaryScreen())
+ setFrameRate(screen->refreshRate());
+
+ return createDisplay() && initWithXID(static_cast<XID>(wid));
+ }
+
+ bool init(QScreen *screen)
+ {
+ if (!screen) {
+ updateError(QPlatformSurfaceCapture::NotFound, QLatin1String("Screen Not Found"));
+ return false;
+ }
+
+ if (!createDisplay())
+ return false;
+
+ auto screenNumber = screenNumberByName(m_display.get(), screen->name());
+
+ if (screenNumber < 0)
+ return false;
+
+ setFrameRate(screen->refreshRate());
+
+ return initWithXID(RootWindow(m_display.get(), screenNumber));
+ }
+
+ bool initWithXID(XID xid)
+ {
+ m_xid = xid;
+
+ if (update()) {
+ start();
+ return true;
+ }
+
+ return false;
+ }
+
+ void detachShm()
+ {
+ if (std::exchange(m_attached, false)) {
+ XShmDetach(m_display.get(), &m_shmInfo);
+ shmdt(m_shmInfo.shmaddr);
+ shmctl(m_shmInfo.shmid, IPC_RMID, 0);
+ }
+ }
+
+ void attachShm()
+ {
+ Q_ASSERT(!m_attached);
+
+ m_shmInfo.shmid =
+ shmget(IPC_PRIVATE, m_xImage->bytes_per_line * m_xImage->height, IPC_CREAT | 0777);
+
+ if (m_shmInfo.shmid == -1)
+ return;
+
+ m_shmInfo.readOnly = false;
+ m_shmInfo.shmaddr = m_xImage->data = (char *)shmat(m_shmInfo.shmid, 0, 0);
+
+ m_attached = XShmAttach(m_display.get(), &m_shmInfo);
+ }
+
+ bool update()
+ {
+ XWindowAttributes wndattr = {};
+ if (XGetWindowAttributes(m_display.get(), m_xid, &wndattr) == 0) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Cannot get window attributes"));
+ return false;
+ }
+
+ // TODO: if capture windows, we should adjust offsets and size if
+ // the window is out of the screen borders
+ // m_xOffset = ...
+ // m_yOffset = ...
+
+ // check window params for the root window as well since
+ // it potentially can be changed (e.g. on VM with resizing)
+ if (!m_xImage || wndattr.width != m_xImage->width || wndattr.height != m_xImage->height
+ || wndattr.depth != m_xImage->depth || wndattr.visual->visualid != m_visualID) {
+
+ qCDebug(qLcX11SurfaceCapture) << "recreate ximage: " << wndattr.width << wndattr.height
+ << wndattr.depth << wndattr.visual->visualid;
+
+ detachShm();
+ m_xImage.reset();
+
+ m_visualID = wndattr.visual->visualid;
+ m_xImage.reset(XShmCreateImage(m_display.get(), wndattr.visual, wndattr.depth, ZPixmap,
+ nullptr, &m_shmInfo, wndattr.width, wndattr.height));
+
+ if (!m_xImage) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Cannot create image"));
+ return false;
+ }
+
+ const auto pixelFormat = xImagePixelFormat(*m_xImage);
+
+ // TODO: probably, add a converter instead
+ if (pixelFormat == QVideoFrameFormat::Format_Invalid) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Not handled pixel format, bpp=")
+ + QString::number(m_xImage->bits_per_pixel));
+ return false;
+ }
+
+ attachShm();
+
+ if (!m_attached) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String("Cannot attach shared memory"));
+ return false;
+ }
+
+ QVideoFrameFormat format(QSize(m_xImage->width, m_xImage->height), pixelFormat);
+ format.setStreamFrameRate(frameRate());
+ m_format = format;
+ }
+
+ return m_attached;
+ }
+
+protected:
+ QVideoFrame grabFrame() override
+ {
+ if (!update())
+ return {};
+
+ if (!XShmGetImage(m_display.get(), m_xid, m_xImage.get(), m_xOffset, m_yOffset,
+ AllPlanes)) {
+ updateError(QPlatformSurfaceCapture::CaptureFailed,
+ QLatin1String(
+ "Cannot get ximage; the window may be out of the screen borders"));
+ return {};
+ }
+
+ QByteArray data(m_xImage->bytes_per_line * m_xImage->height, Qt::Uninitialized);
+
+ const auto pixelSrc = reinterpret_cast<const uint32_t *>(m_xImage->data);
+ const auto pixelDst = reinterpret_cast<uint32_t *>(data.data());
+ const auto pixelCount = data.size() / 4;
+ const auto xImageAlphaVaries = false; // In known cases it doesn't vary - it's 0xff or 0xff
+
+ qCopyPixelsWithAlphaMask(pixelDst, pixelSrc, pixelCount, m_format.pixelFormat(),
+ xImageAlphaVaries);
+
+ auto buffer = std::make_unique<QMemoryVideoBuffer>(data, m_xImage->bytes_per_line);
+ return QVideoFramePrivate::createFrame(std::move(buffer), m_format);
+ }
+
+private:
+ std::optional<QPlatformSurfaceCapture::Error> m_prevGrabberError;
+ XID m_xid = None;
+ int m_xOffset = 0;
+ int m_yOffset = 0;
+ std::unique_ptr<Display, decltype(&XCloseDisplay)> m_display{ nullptr, &XCloseDisplay };
+ std::unique_ptr<XImage, decltype(&destroyXImage)> m_xImage{ nullptr, &destroyXImage };
+ XShmSegmentInfo m_shmInfo;
+ bool m_attached = false;
+ VisualID m_visualID = None;
+ QVideoFrameFormat m_format;
+};
+
+QX11SurfaceCapture::QX11SurfaceCapture(Source initialSource)
+ : QPlatformSurfaceCapture(initialSource)
+{
+ // For debug
+ // XSetErrorHandler([](Display *, XErrorEvent * e) {
+ // qDebug() << "error handler" << e->error_code;
+ // return 0;
+ // });
+}
+
+QX11SurfaceCapture::~QX11SurfaceCapture() = default;
+
+QVideoFrameFormat QX11SurfaceCapture::frameFormat() const
+{
+ return m_grabber ? m_grabber->format() : QVideoFrameFormat{};
+}
+
+bool QX11SurfaceCapture::setActiveInternal(bool active)
+{
+ qCDebug(qLcX11SurfaceCapture) << "set active" << active;
+
+ if (m_grabber)
+ m_grabber.reset();
+ else
+ std::visit([this](auto source) { activate(source); }, source());
+
+ return static_cast<bool>(m_grabber) == active;
+}
+
+void QX11SurfaceCapture::activate(ScreenSource screen)
+{
+ if (checkScreenWithError(screen))
+ m_grabber = Grabber::create(*this, screen);
+}
+
+void QX11SurfaceCapture::activate(WindowSource window)
+{
+ auto handle = QCapturableWindowPrivate::handle(window);
+ m_grabber = Grabber::create(*this, handle ? handle->id : 0);
+}
+
+bool QX11SurfaceCapture::isSupported()
+{
+ return qgetenv("XDG_SESSION_TYPE").compare(QLatin1String("x11"), Qt::CaseInsensitive) == 0;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/qx11surfacecapture_p.h b/src/plugins/multimedia/ffmpeg/qx11surfacecapture_p.h
new file mode 100644
index 000000000..7f794fd8b
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/qx11surfacecapture_p.h
@@ -0,0 +1,48 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef X11SURFACECAPTURE_P_H
+#define X11SURFACECAPTURE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qplatformsurfacecapture_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QX11SurfaceCapture : public QPlatformSurfaceCapture
+{
+ class Grabber;
+
+public:
+ explicit QX11SurfaceCapture(Source initialSource);
+ ~QX11SurfaceCapture() override;
+
+ QVideoFrameFormat frameFormat() const override;
+
+ static bool isSupported();
+
+protected:
+ bool setActiveInternal(bool active) override;
+
+private:
+ void activate(ScreenSource);
+
+ void activate(WindowSource);
+
+private:
+ std::unique_ptr<Grabber> m_grabber;
+};
+
+QT_END_NAMESPACE
+
+#endif // X11SURFACECAPTURE_P_H
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoder.cpp b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoder.cpp
new file mode 100644
index 000000000..9c8be91d1
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoder.cpp
@@ -0,0 +1,343 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qffmpegaudioencoder_p.h"
+#include "qffmpegrecordingengineutils_p.h"
+#include "qffmpegaudioencoderutils_p.h"
+#include "qffmpegaudioinput_p.h"
+#include "qffmpegencoderoptions_p.h"
+#include "qffmpegmuxer_p.h"
+#include "qffmpegrecordingengine_p.h"
+#include "qffmpegmediaformatinfo_p.h"
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+static Q_LOGGING_CATEGORY(qLcFFmpegAudioEncoder, "qt.multimedia.ffmpeg.audioencoder");
+
+AudioEncoder::AudioEncoder(RecordingEngine &recordingEngine, const QAudioFormat &sourceFormat,
+ const QMediaEncoderSettings &settings)
+ : EncoderThread(recordingEngine), m_format(sourceFormat), m_settings(settings)
+{
+ setObjectName(QLatin1String("AudioEncoder"));
+ qCDebug(qLcFFmpegAudioEncoder) << "AudioEncoder" << settings.audioCodec();
+
+ auto codecID = QFFmpegMediaFormatInfo::codecIdForAudioCodec(settings.audioCodec());
+ Q_ASSERT(avformat_query_codec(recordingEngine.avFormatContext()->oformat, codecID,
+ FF_COMPLIANCE_NORMAL));
+
+ const AVAudioFormat requestedAudioFormat(m_format);
+
+ m_avCodec = QFFmpeg::findAVEncoder(codecID, {}, requestedAudioFormat.sampleFormat);
+
+ if (!m_avCodec)
+ m_avCodec = QFFmpeg::findAVEncoder(codecID);
+
+ qCDebug(qLcFFmpegAudioEncoder) << "found audio codec" << m_avCodec->name;
+
+ Q_ASSERT(m_avCodec);
+
+ m_stream = avformat_new_stream(recordingEngine.avFormatContext(), nullptr);
+ m_stream->id = recordingEngine.avFormatContext()->nb_streams - 1;
+ m_stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+ m_stream->codecpar->codec_id = codecID;
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+ m_stream->codecpar->channel_layout =
+ adjustChannelLayout(m_avCodec->channel_layouts, requestedAudioFormat.channelLayoutMask);
+ m_stream->codecpar->channels = qPopulationCount(m_stream->codecpar->channel_layout);
+#else
+ m_stream->codecpar->ch_layout =
+ adjustChannelLayout(m_avCodec->ch_layouts, requestedAudioFormat.channelLayout);
+#endif
+ const auto sampleRate =
+ adjustSampleRate(m_avCodec->supported_samplerates, requestedAudioFormat.sampleRate);
+
+ m_stream->codecpar->sample_rate = sampleRate;
+ m_stream->codecpar->frame_size = 1024;
+ m_stream->codecpar->format =
+ adjustSampleFormat(m_avCodec->sample_fmts, requestedAudioFormat.sampleFormat);
+
+ m_stream->time_base = AVRational{ 1, sampleRate };
+
+ qCDebug(qLcFFmpegAudioEncoder) << "set stream time_base" << m_stream->time_base.num << "/"
+ << m_stream->time_base.den;
+}
+
+void AudioEncoder::open()
+{
+ m_codecContext.reset(avcodec_alloc_context3(m_avCodec));
+
+ if (m_stream->time_base.num != 1 || m_stream->time_base.den != m_format.sampleRate()) {
+ qCDebug(qLcFFmpegAudioEncoder) << "Most likely, av_format_write_header changed time base from"
+ << 1 << "/" << m_format.sampleRate() << "to"
+ << m_stream->time_base;
+ }
+
+ m_codecContext->time_base = m_stream->time_base;
+
+ avcodec_parameters_to_context(m_codecContext.get(), m_stream->codecpar);
+
+ AVDictionaryHolder opts;
+ applyAudioEncoderOptions(m_settings, m_avCodec->name, m_codecContext.get(), opts);
+ applyExperimentalCodecOptions(m_avCodec, opts);
+
+ const int res = avcodec_open2(m_codecContext.get(), m_avCodec, opts);
+
+ qCDebug(qLcFFmpegAudioEncoder) << "audio codec opened" << res;
+ qCDebug(qLcFFmpegAudioEncoder) << "audio codec params: fmt=" << m_codecContext->sample_fmt
+ << "rate=" << m_codecContext->sample_rate;
+
+ updateResampler();
+}
+
+void AudioEncoder::addBuffer(const QAudioBuffer &buffer)
+{
+ if (!buffer.isValid()) {
+ setEndOfSourceStream(true);
+ return;
+ }
+
+ setEndOfSourceStream(false);
+
+ {
+ const std::chrono::microseconds bufferDuration(buffer.duration());
+ auto guard = lockLoopData();
+
+ if (m_paused)
+ return;
+
+ // TODO: apply logic with canPushFrame
+
+ m_audioBufferQueue.push(buffer);
+ m_queueDuration += bufferDuration;
+ }
+
+ dataReady();
+}
+
+QAudioBuffer AudioEncoder::takeBuffer()
+{
+ auto locker = lockLoopData();
+ QAudioBuffer result = dequeueIfPossible(m_audioBufferQueue);
+ m_queueDuration -= std::chrono::microseconds(result.duration());
+ return result;
+}
+
+void AudioEncoder::init()
+{
+ open();
+
+ // TODO: try to address this dependency here.
+ if (auto input = qobject_cast<QFFmpegAudioInput *>(source()))
+ input->setFrameSize(m_codecContext->frame_size);
+
+ qCDebug(qLcFFmpegAudioEncoder) << "AudioEncoder::init started audio device thread.";
+}
+
+void AudioEncoder::cleanup()
+{
+ while (!m_audioBufferQueue.empty())
+ processOne();
+
+ if (m_avFrameSamplesOffset) {
+ // the size of the last frame can be less than m_codecContext->frame_size
+
+ retrievePackets();
+ sendPendingFrameToAVCodec();
+ }
+
+ while (avcodec_send_frame(m_codecContext.get(), nullptr) == AVERROR(EAGAIN))
+ retrievePackets();
+ retrievePackets();
+}
+
+bool AudioEncoder::hasData() const
+{
+ return !m_audioBufferQueue.empty();
+}
+
+void AudioEncoder::retrievePackets()
+{
+ while (1) {
+ AVPacketUPtr packet(av_packet_alloc());
+ int ret = avcodec_receive_packet(m_codecContext.get(), packet.get());
+ if (ret < 0) {
+ if (ret != AVERROR(EOF))
+ break;
+ if (ret != AVERROR(EAGAIN)) {
+ char errStr[1024];
+ av_strerror(ret, errStr, 1024);
+ qCDebug(qLcFFmpegAudioEncoder) << "receive packet" << ret << errStr;
+ }
+ break;
+ }
+
+ // qCDebug(qLcFFmpegEncoder) << "writing audio packet" << packet->size << packet->pts <<
+ // packet->dts;
+ packet->stream_index = m_stream->id;
+ m_recordingEngine.getMuxer()->addPacket(std::move(packet));
+ }
+}
+
+void AudioEncoder::processOne()
+{
+ QAudioBuffer buffer = takeBuffer();
+ Q_ASSERT(buffer.isValid());
+
+ // qCDebug(qLcFFmpegEncoder) << "new audio buffer" << buffer.byteCount() << buffer.format()
+ // << buffer.frameCount() << codec->frame_size;
+
+ if (buffer.format() != m_format) {
+ m_format = buffer.format();
+ updateResampler();
+ }
+
+ int samplesOffset = 0;
+ const int bufferSamplesCount = static_cast<int>(buffer.frameCount());
+
+ while (samplesOffset < bufferSamplesCount)
+ handleAudioData(buffer.constData<uint8_t>(), samplesOffset, bufferSamplesCount);
+
+ Q_ASSERT(samplesOffset == bufferSamplesCount);
+}
+
+bool AudioEncoder::checkIfCanPushFrame() const
+{
+ if (isRunning())
+ return m_audioBufferQueue.size() <= 1 || m_queueDuration < m_maxQueueDuration;
+ if (!isFinished())
+ return m_audioBufferQueue.empty();
+
+ return false;
+}
+
+void AudioEncoder::updateResampler()
+{
+ m_resampler.reset();
+
+ const AVAudioFormat requestedAudioFormat(m_format);
+ const AVAudioFormat codecAudioFormat(m_codecContext.get());
+
+ if (requestedAudioFormat != codecAudioFormat)
+ m_resampler = createResampleContext(requestedAudioFormat, codecAudioFormat);
+
+ qCDebug(qLcFFmpegAudioEncoder)
+ << "Resampler updated. Input format:" << m_format << "Resampler:" << m_resampler.get();
+}
+
+void AudioEncoder::ensurePendingFrame(int availableSamplesCount)
+{
+ Q_ASSERT(availableSamplesCount >= 0);
+
+ if (m_avFrame)
+ return;
+
+ m_avFrame = makeAVFrame();
+
+ m_avFrame->format = m_codecContext->sample_fmt;
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+ m_avFrame->channel_layout = m_codecContext->channel_layout;
+ m_avFrame->channels = m_codecContext->channels;
+#else
+ m_avFrame->ch_layout = m_codecContext->ch_layout;
+#endif
+ m_avFrame->sample_rate = m_codecContext->sample_rate;
+
+ const bool isFixedFrameSize = !(m_avCodec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
+ && m_codecContext->frame_size;
+ m_avFrame->nb_samples = isFixedFrameSize ? m_codecContext->frame_size : availableSamplesCount;
+ if (m_avFrame->nb_samples)
+ av_frame_get_buffer(m_avFrame.get(), 0);
+
+ const auto &timeBase = m_stream->time_base;
+ const auto pts = timeBase.den && timeBase.num
+ ? timeBase.den * m_samplesWritten / (m_codecContext->sample_rate * timeBase.num)
+ : m_samplesWritten;
+ setAVFrameTime(*m_avFrame, pts, timeBase);
+}
+
+void AudioEncoder::writeDataToPendingFrame(const uchar *data, int &samplesOffset, int samplesCount)
+{
+ Q_ASSERT(m_avFrame);
+ Q_ASSERT(m_avFrameSamplesOffset <= m_avFrame->nb_samples);
+
+ const int bytesPerSample = av_get_bytes_per_sample(m_codecContext->sample_fmt);
+ const bool isPlanar = av_sample_fmt_is_planar(m_codecContext->sample_fmt);
+
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+ const int channelsCount = m_codecContext->channels;
+#else
+ const int channelsCount = m_codecContext->ch_layout.nb_channels;
+#endif
+
+ const int audioDataOffset = isPlanar ? bytesPerSample * m_avFrameSamplesOffset
+ : bytesPerSample * m_avFrameSamplesOffset * channelsCount;
+
+ const int planesCount = isPlanar ? channelsCount : 1;
+ m_avFramePlanesData.resize(planesCount);
+ for (int plane = 0; plane < planesCount; ++plane)
+ m_avFramePlanesData[plane] = m_avFrame->extended_data[plane] + audioDataOffset;
+
+ const int samplesToRead =
+ std::min(m_avFrame->nb_samples - m_avFrameSamplesOffset, samplesCount - samplesOffset);
+
+ data += m_format.bytesForFrames(samplesOffset);
+
+ if (m_resampler) {
+ m_avFrameSamplesOffset += swr_convert(m_resampler.get(), m_avFramePlanesData.data(),
+ samplesToRead, &data, samplesToRead);
+ } else {
+ Q_ASSERT(planesCount == 1);
+ m_avFrameSamplesOffset += samplesToRead;
+ memcpy(m_avFramePlanesData[0], data, m_format.bytesForFrames(samplesToRead));
+ }
+
+ samplesOffset += samplesToRead;
+}
+
+void AudioEncoder::sendPendingFrameToAVCodec()
+{
+ Q_ASSERT(m_avFrame);
+ Q_ASSERT(m_avFrameSamplesOffset <= m_avFrame->nb_samples);
+
+ m_avFrame->nb_samples = m_avFrameSamplesOffset;
+
+ m_samplesWritten += m_avFrameSamplesOffset;
+
+ const qint64 time = m_format.durationForFrames(m_samplesWritten);
+ m_recordingEngine.newTimeStamp(time / 1000);
+
+ // qCDebug(qLcFFmpegEncoder) << "sending audio frame" << buffer.byteCount() << frame->pts <<
+ // ((double)buffer.frameCount()/frame->sample_rate);
+
+ int ret = avcodec_send_frame(m_codecContext.get(), m_avFrame.get());
+ if (ret < 0) {
+ char errStr[AV_ERROR_MAX_STRING_SIZE];
+ av_strerror(ret, errStr, AV_ERROR_MAX_STRING_SIZE);
+ qCDebug(qLcFFmpegAudioEncoder) << "error sending frame" << ret << errStr;
+ }
+
+ m_avFrame = nullptr;
+ m_avFrameSamplesOffset = 0;
+ std::fill(m_avFramePlanesData.begin(), m_avFramePlanesData.end(), nullptr);
+}
+
+void AudioEncoder::handleAudioData(const uchar *data, int &samplesOffset, int samplesCount)
+{
+ ensurePendingFrame(samplesCount - samplesOffset);
+
+ writeDataToPendingFrame(data, samplesOffset, samplesCount);
+
+ // The frame is not ready yet
+ if (m_avFrameSamplesOffset < m_avFrame->nb_samples)
+ return;
+
+ retrievePackets();
+
+ sendPendingFrameToAVCodec();
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoder_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoder_p.h
new file mode 100644
index 000000000..4408ff54f
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoder_p.h
@@ -0,0 +1,77 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGAUDIOENCODER_P_H
+#define QFFMPEGAUDIOENCODER_P_H
+
+#include "qffmpeg_p.h"
+#include "qffmpegencoderthread_p.h"
+#include "private/qplatformmediarecorder_p.h"
+#include <qaudiobuffer.h>
+#include <queue>
+#include <chrono>
+
+QT_BEGIN_NAMESPACE
+
+class QMediaEncoderSettings;
+
+namespace QFFmpeg {
+
+class AudioEncoder : public EncoderThread
+{
+public:
+ AudioEncoder(RecordingEngine &recordingEngine, const QAudioFormat &sourceFormat,
+ const QMediaEncoderSettings &settings);
+
+ void addBuffer(const QAudioBuffer &buffer);
+
+protected:
+ bool checkIfCanPushFrame() const override;
+
+private:
+ void open();
+
+ QAudioBuffer takeBuffer();
+ void retrievePackets();
+ void updateResampler();
+
+ void init() override;
+ void cleanup() override;
+ bool hasData() const override;
+ void processOne() override;
+
+ void handleAudioData(const uchar *data, int &samplesOffset, int samplesCount);
+
+ void ensurePendingFrame(int availableSamplesCount);
+
+ void writeDataToPendingFrame(const uchar *data, int &samplesOffset, int samplesCount);
+
+ void sendPendingFrameToAVCodec();
+
+private:
+ std::queue<QAudioBuffer> m_audioBufferQueue;
+
+ // Arbitrarily chosen to limit audio queue duration
+ const std::chrono::microseconds m_maxQueueDuration = std::chrono::seconds(5);
+
+ std::chrono::microseconds m_queueDuration{ 0 };
+
+ AVStream *m_stream = nullptr;
+ AVCodecContextUPtr m_codecContext;
+ QAudioFormat m_format;
+
+ SwrContextUPtr m_resampler;
+ qint64 m_samplesWritten = 0;
+ const AVCodec *m_avCodec = nullptr;
+ QMediaEncoderSettings m_settings;
+
+ AVFrameUPtr m_avFrame;
+ int m_avFrameSamplesOffset = 0;
+ std::vector<uint8_t *> m_avFramePlanesData;
+};
+
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoderutils.cpp b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoderutils.cpp
new file mode 100644
index 000000000..ea36a8138
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoderutils.cpp
@@ -0,0 +1,97 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegaudioencoderutils_p.h"
+#include "qalgorithms.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+AVSampleFormat adjustSampleFormat(const AVSampleFormat *supportedFormats, AVSampleFormat requested)
+{
+ auto calcScore = [requested](AVSampleFormat format) {
+ return format == requested ? BestAVScore
+ : format == av_get_planar_sample_fmt(requested) ? BestAVScore - 1
+ : 0;
+ };
+
+ const auto result = findBestAVFormat(supportedFormats, calcScore).first;
+ return result == AV_SAMPLE_FMT_NONE ? requested : result;
+}
+
+int adjustSampleRate(const int *supportedRates, int requested)
+{
+ auto calcScore = [requested](int rate) {
+ return requested == rate ? BestAVScore
+ : requested <= rate ? rate - requested
+ : requested - rate - 1000000;
+ };
+
+ const auto result = findBestAVValue(supportedRates, calcScore).first;
+ return result == 0 ? requested : result;
+}
+
+static AVScore calculateScoreByChannelsCount(int supportedChannelsNumber,
+ int requestedChannelsNumber)
+{
+ if (supportedChannelsNumber >= requestedChannelsNumber)
+ return requestedChannelsNumber - supportedChannelsNumber;
+
+ return supportedChannelsNumber - requestedChannelsNumber - 10000;
+}
+
+static AVScore calculateScoreByChannelsMask(int supportedChannelsNumber, uint64_t supportedMask,
+ int requestedChannelsNumber, uint64_t requestedMask)
+{
+ if ((supportedMask & requestedMask) == requestedMask)
+ return BestAVScore - qPopulationCount(supportedMask & ~requestedMask);
+
+ return calculateScoreByChannelsCount(supportedChannelsNumber, requestedChannelsNumber);
+}
+
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+
+uint64_t adjustChannelLayout(const uint64_t *supportedMasks, uint64_t requested)
+{
+ auto calcScore = [requested](uint64_t mask) {
+ return calculateScoreByChannelsMask(qPopulationCount(mask), mask,
+ qPopulationCount(requested), requested);
+ };
+
+ const auto result = findBestAVValue(supportedMasks, calcScore).first;
+ return result == 0 ? requested : result;
+}
+
+#else
+
+AVChannelLayout adjustChannelLayout(const AVChannelLayout *supportedLayouts,
+ const AVChannelLayout &requested)
+{
+ auto calcScore = [&requested](const AVChannelLayout &layout) {
+ if (layout == requested)
+ return BestAVScore;
+
+ // The only realistic case for now:
+ // layout.order == requested.order == AV_CHANNEL_ORDER_NATIVE
+ // Let's consider other orders to make safe code
+
+ if (layout.order == AV_CHANNEL_ORDER_CUSTOM || requested.order == AV_CHANNEL_ORDER_CUSTOM)
+ return calculateScoreByChannelsCount(layout.nb_channels, requested.nb_channels) - 1000;
+
+ const auto offset = layout.order == requested.order ? 1 : 100;
+
+ return calculateScoreByChannelsMask(layout.nb_channels, layout.u.mask,
+ requested.nb_channels, requested.u.mask)
+ - offset;
+ };
+
+ const auto result = findBestAVValue(supportedLayouts, calcScore);
+ return result.second == NotSuitableAVScore ? requested : result.first;
+}
+
+#endif
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoderutils_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoderutils_p.h
new file mode 100644
index 000000000..8a7c184ec
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegaudioencoderutils_p.h
@@ -0,0 +1,28 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGAUDIOENCODERUTILS_P_H
+#define QFFMPEGAUDIOENCODERUTILS_P_H
+
+#include "qffmpeg_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+AVSampleFormat adjustSampleFormat(const AVSampleFormat *supportedFormats, AVSampleFormat requested);
+
+int adjustSampleRate(const int *supportedRates, int requested);
+
+#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
+uint64_t adjustChannelLayout(const uint64_t *supportedLayouts, uint64_t requested);
+#else
+AVChannelLayout adjustChannelLayout(const AVChannelLayout *supportedLayouts,
+ const AVChannelLayout &requested);
+#endif
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGAUDIOENCODERUTILS_P_H
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderoptions.cpp b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderoptions.cpp
new file mode 100644
index 000000000..bd6a8e09b
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderoptions.cpp
@@ -0,0 +1,362 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qffmpegencoderoptions_p.h"
+
+#if QT_CONFIG(vaapi)
+#include <va/va.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+// unfortunately there is no common way to specify options for the encoders. The code here tries to map our settings sensibly
+// to options available in different encoders
+
+// For constant quality options, we're trying to map things to approx those bit rates for 1080p@30fps (in Mbps):
+// VeryLow Low Normal High VeryHigh
+// H264: 0.8M 1.5M 3.5M 6M 10M
+// H265: 0.5M 1.0M 2.5M 4M 7M
+
+[[maybe_unused]]
+static int bitrateForSettings(const QMediaEncoderSettings &settings, bool hdr = false)
+{
+ // calculate an acceptable bitrate depending on video codec, resolution, framerate and requested quality
+ // The calculations are rather heuristic here, trying to take into account how well codecs compress using
+ // the tables above.
+
+ // The table here is for 30FPS
+ const double bitsPerPixel[int(QMediaFormat::VideoCodec::LastVideoCodec)+1][QMediaRecorder::VeryHighQuality+1] = {
+ { 1.2, 2.25, 5, 9, 15 }, // MPEG1,
+ { 0.8, 1.5, 3.5, 6, 10 }, // MPEG2
+ { 0.4, 0.75, 1.75, 3, 5 }, // MPEG4
+ { 0.4, 0.75, 1.75, 3, 5 }, // H264
+ { 0.3, 0.5, 0.2, 2, 3 }, // H265
+ { 0.4, 0.75, 1.75, 3, 5 }, // VP8
+ { 0.3, 0.5, 0.2, 2, 3 }, // VP9
+ { 0.2, 0.4, 0.9, 1.5, 2.5 }, // AV1
+ { 0.4, 0.75, 1.75, 3, 5 }, // Theora
+ { 0.8, 1.5, 3.5, 6, 10 }, // WMV
+ { 16, 24, 32, 40, 48 }, // MotionJPEG
+ };
+
+ QSize s = settings.videoResolution();
+ double bitrate = bitsPerPixel[int(settings.videoCodec())][settings.quality()]*s.width()*s.height();
+
+ if (settings.videoCodec() != QMediaFormat::VideoCodec::MotionJPEG) {
+ // We assume that doubling the framerate requires 1.5 times the amount of data (not twice, as intraframe
+ // differences will be smaller). 4 times the frame rate uses thus 2.25 times the data, etc.
+ float rateMultiplier = log2(settings.videoFrameRate()/30.);
+ bitrate *= pow(1.5, rateMultiplier);
+ } else {
+ // MotionJPEG doesn't optimize between frames, so we have a linear dependency on framerate
+ bitrate *= settings.videoFrameRate()/30.;
+ }
+
+ // HDR requires 10bits per pixel instead of 8, so apply a factor of 1.25.
+ if (hdr)
+ bitrate *= 1.25;
+ return bitrate;
+}
+
+static void apply_openh264(const QMediaEncoderSettings &settings, AVCodecContext *codec,
+ AVDictionary **opts)
+{
+ if (settings.encodingMode() == QMediaRecorder::ConstantBitRateEncoding
+ || settings.encodingMode() == QMediaRecorder::AverageBitRateEncoding) {
+ codec->bit_rate = settings.videoBitRate();
+ av_dict_set(opts, "rc_mode", "bitrate", 0);
+ } else {
+ av_dict_set(opts, "rc_mode", "quality", 0);
+ static const int q[] = { 51, 48, 38, 25, 5 };
+ codec->qmax = codec->qmin = q[settings.quality()];
+ }
+}
+
+static void apply_x264(const QMediaEncoderSettings &settings, AVCodecContext *codec, AVDictionary **opts)
+{
+ if (settings.encodingMode() == QMediaRecorder::ConstantBitRateEncoding || settings.encodingMode() == QMediaRecorder::AverageBitRateEncoding) {
+ codec->bit_rate = settings.videoBitRate();
+ } else {
+ const char *scales[] = {
+ "29", "26", "23", "21", "19"
+ };
+ av_dict_set(opts, "crf", scales[settings.quality()], 0);
+ }
+}
+
+static void apply_x265(const QMediaEncoderSettings &settings, AVCodecContext *codec, AVDictionary **opts)
+{
+ if (settings.encodingMode() == QMediaRecorder::ConstantBitRateEncoding || settings.encodingMode() == QMediaRecorder::AverageBitRateEncoding) {
+ codec->bit_rate = settings.videoBitRate();
+ } else {
+ const char *scales[QMediaRecorder::VeryHighQuality+1] = {
+ "40", "34", "28", "26", "24",
+ };
+ av_dict_set(opts, "crf", scales[settings.quality()], 0);
+ }
+}
+
+static void apply_libvpx(const QMediaEncoderSettings &settings, AVCodecContext *codec, AVDictionary **opts)
+{
+ if (settings.encodingMode() == QMediaRecorder::ConstantBitRateEncoding || settings.encodingMode() == QMediaRecorder::AverageBitRateEncoding) {
+ codec->bit_rate = settings.videoBitRate();
+ } else {
+ const char *scales[QMediaRecorder::VeryHighQuality+1] = {
+ "38", "34", "31", "28", "25",
+ };
+ av_dict_set(opts, "crf", scales[settings.quality()], 0);
+ av_dict_set(opts, "b", 0, 0);
+ }
+ av_dict_set(opts, "row-mt", "1", 0); // better multithreading
+}
+
+#ifdef Q_OS_DARWIN
+static void apply_videotoolbox(const QMediaEncoderSettings &settings, AVCodecContext *codec, AVDictionary **opts)
+{
+ if (settings.encodingMode() == QMediaRecorder::ConstantBitRateEncoding || settings.encodingMode() == QMediaRecorder::AverageBitRateEncoding) {
+ codec->bit_rate = settings.videoBitRate();
+ } else {
+ // only use quality on macOS/ARM, as FFmpeg doesn't support it on the other platforms and would throw
+ // an error when initializing the codec
+#if defined(Q_OS_MACOS) && defined(Q_PROCESSOR_ARM_64)
+ // Videotoolbox describes quality as a number from 0 to 1, with low == 0.25, normal 0.5, high 0.75 and lossless = 1
+ // ffmpeg uses a different scale going from 0 to 11800.
+ // Values here are adjusted to agree approximately with the target bit rates listed above
+ const int scales[] = {
+ 3000, 4800, 5900, 6900, 7700,
+ };
+ codec->global_quality = scales[settings.quality()];
+ codec->flags |= AV_CODEC_FLAG_QSCALE;
+#else
+ codec->bit_rate = bitrateForSettings(settings);
+#endif
+ }
+
+ // Videotooldox hw acceleration fails of some hardwares,
+ // allow_sw makes sw encoding available if hw encoding failed.
+ // Under the hood, ffmpeg sets
+ // kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder instead of
+ // kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder
+ av_dict_set(opts, "allow_sw", "1", 0);
+}
+#endif
+
+#if QT_CONFIG(vaapi)
+static void apply_vaapi(const QMediaEncoderSettings &settings, AVCodecContext *codec, AVDictionary **/*opts*/)
+{
+ // See also vaapi_encode_init_rate_control() in libavcodec
+ if (settings.encodingMode() == QMediaRecorder::ConstantBitRateEncoding) {
+ codec->bit_rate = settings.videoBitRate();
+ codec->rc_max_rate = settings.videoBitRate();
+ } else if (settings.encodingMode() == QMediaRecorder::AverageBitRateEncoding) {
+ codec->bit_rate = settings.videoBitRate();
+ } else {
+ const int *quality = nullptr;
+ // unfortunately, all VA codecs use different quality scales :/
+ switch (settings.videoCodec()) {
+ case QMediaFormat::VideoCodec::MPEG2: {
+ static const int q[] = { 20, 15, 10, 8, 6 };
+ quality = q;
+ break;
+ }
+ case QMediaFormat::VideoCodec::MPEG4:
+ case QMediaFormat::VideoCodec::H264: {
+ static const int q[] = { 29, 26, 23, 21, 19 };
+ quality = q;
+ break;
+ }
+ case QMediaFormat::VideoCodec::H265: {
+ static const int q[] = { 40, 34, 28, 26, 24 };
+ quality = q;
+ break;
+ }
+ case QMediaFormat::VideoCodec::VP8: {
+ static const int q[] = { 56, 48, 40, 34, 28 };
+ quality = q;
+ break;
+ }
+ case QMediaFormat::VideoCodec::VP9: {
+ static const int q[] = { 124, 112, 100, 88, 76 };
+ quality = q;
+ break;
+ }
+ case QMediaFormat::VideoCodec::MotionJPEG: {
+ static const int q[] = { 40, 60, 80, 90, 95 };
+ quality = q;
+ break;
+ }
+ case QMediaFormat::VideoCodec::AV1:
+ case QMediaFormat::VideoCodec::Theora:
+ case QMediaFormat::VideoCodec::WMV:
+ default:
+ break;
+ }
+
+ if (quality)
+ codec->global_quality = quality[settings.quality()];
+ }
+}
+#endif
+
+static void apply_nvenc(const QMediaEncoderSettings &settings, AVCodecContext *codec,
+ AVDictionary **opts)
+{
+ switch (settings.encodingMode()) {
+ case QMediaRecorder::EncodingMode::AverageBitRateEncoding:
+ av_dict_set(opts, "vbr", "1", 0);
+ codec->bit_rate = settings.videoBitRate();
+ break;
+ case QMediaRecorder::EncodingMode::ConstantBitRateEncoding:
+ av_dict_set(opts, "cbr", "1", 0);
+ codec->bit_rate = settings.videoBitRate();
+ codec->rc_max_rate = codec->rc_min_rate = codec->bit_rate;
+ break;
+ case QMediaRecorder::EncodingMode::ConstantQualityEncoding: {
+ static const char *q[] = { "51", "48", "35", "15", "1" };
+ av_dict_set(opts, "cq", q[settings.quality()], 0);
+ } break;
+ default:
+ break;
+ }
+}
+
+#ifdef Q_OS_WINDOWS
+static void apply_mf(const QMediaEncoderSettings &settings, AVCodecContext *codec, AVDictionary **opts)
+{
+ if (settings.encodingMode() == QMediaRecorder::ConstantBitRateEncoding || settings.encodingMode() == QMediaRecorder::AverageBitRateEncoding) {
+ codec->bit_rate = settings.videoBitRate();
+ av_dict_set(opts, "rate_control", "cbr", 0);
+ } else {
+ av_dict_set(opts, "rate_control", "quality", 0);
+ const char *scales[] = {
+ "25", "50", "75", "90", "100"
+ };
+ av_dict_set(opts, "quality", scales[settings.quality()], 0);
+ }
+}
+#endif
+
+#ifdef Q_OS_ANDROID
+static void apply_mediacodec(const QMediaEncoderSettings &settings, AVCodecContext *codec,
+ AVDictionary **opts)
+{
+ codec->bit_rate = settings.videoBitRate();
+
+ const int quality[] = { 25, 50, 75, 90, 100 };
+ codec->global_quality = quality[settings.quality()];
+
+ switch (settings.encodingMode()) {
+ case QMediaRecorder::EncodingMode::AverageBitRateEncoding:
+ av_dict_set(opts, "bitrate_mode", "vbr", 1);
+ break;
+ case QMediaRecorder::EncodingMode::ConstantBitRateEncoding:
+ av_dict_set(opts, "bitrate_mode", "cbr", 1);
+ break;
+ case QMediaRecorder::EncodingMode::ConstantQualityEncoding:
+ // av_dict_set(opts, "bitrate_mode", "cq", 1);
+ av_dict_set(opts, "bitrate_mode", "cbr", 1);
+ break;
+ default:
+ break;
+ }
+
+ switch (settings.videoCodec()) {
+ case QMediaFormat::VideoCodec::H264: {
+ const char *levels[] = { "2.2", "3.2", "4.2", "5.2", "6.2" };
+ av_dict_set(opts, "level", levels[settings.quality()], 1);
+ codec->profile = FF_PROFILE_H264_HIGH;
+ break;
+ }
+ case QMediaFormat::VideoCodec::H265: {
+ const char *levels[] = { "h2.1", "h3.1", "h4.1", "h5.1", "h6.1" };
+ av_dict_set(opts, "level", levels[settings.quality()], 1);
+ codec->profile = FF_PROFILE_HEVC_MAIN;
+ break;
+ }
+ default:
+ break;
+ }
+}
+#endif
+
+namespace QFFmpeg {
+
+using ApplyOptions = void (*)(const QMediaEncoderSettings &settings, AVCodecContext *codec, AVDictionary **opts);
+
+const struct {
+ const char *name;
+ ApplyOptions apply;
+} videoCodecOptionTable[] = { { "libx264", apply_x264 },
+ { "libx265xx", apply_x265 },
+ { "libvpx", apply_libvpx },
+ { "libvpx_vp9", apply_libvpx },
+ { "libopenh264", apply_openh264 },
+ { "h264_nvenc", apply_nvenc },
+ { "hevc_nvenc", apply_nvenc },
+ { "av1_nvenc", apply_nvenc },
+#ifdef Q_OS_DARWIN
+ { "h264_videotoolbox", apply_videotoolbox },
+ { "hevc_videotoolbox", apply_videotoolbox },
+ { "prores_videotoolbox", apply_videotoolbox },
+ { "vp9_videotoolbox", apply_videotoolbox },
+#endif
+#if QT_CONFIG(vaapi)
+ { "mpeg2_vaapi", apply_vaapi },
+ { "mjpeg_vaapi", apply_vaapi },
+ { "h264_vaapi", apply_vaapi },
+ { "hevc_vaapi", apply_vaapi },
+ { "vp8_vaapi", apply_vaapi },
+ { "vp9_vaapi", apply_vaapi },
+#endif
+#ifdef Q_OS_WINDOWS
+ { "hevc_mf", apply_mf },
+ { "h264_mf", apply_mf },
+#endif
+#ifdef Q_OS_ANDROID
+ { "hevc_mediacodec", apply_mediacodec },
+ { "h264_mediacodec", apply_mediacodec },
+#endif
+ { nullptr, nullptr } };
+
+const struct {
+ const char *name;
+ ApplyOptions apply;
+} audioCodecOptionTable[] = {
+ { nullptr, nullptr }
+};
+
+void applyVideoEncoderOptions(const QMediaEncoderSettings &settings, const QByteArray &codecName, AVCodecContext *codec, AVDictionary **opts)
+{
+ av_dict_set(opts, "threads", "auto", 0); // we always want automatic threading
+
+ auto *table = videoCodecOptionTable;
+ while (table->name) {
+ if (codecName == table->name) {
+ table->apply(settings, codec, opts);
+ return;
+ }
+
+ ++table;
+ }
+}
+
+void applyAudioEncoderOptions(const QMediaEncoderSettings &settings, const QByteArray &codecName, AVCodecContext *codec, AVDictionary **opts)
+{
+ codec->thread_count = -1; // we always want automatic threading
+ if (settings.encodingMode() == QMediaRecorder::ConstantBitRateEncoding || settings.encodingMode() == QMediaRecorder::AverageBitRateEncoding)
+ codec->bit_rate = settings.audioBitRate();
+
+ auto *table = audioCodecOptionTable;
+ while (table->name) {
+ if (codecName == table->name) {
+ table->apply(settings, codec, opts);
+ return;
+ }
+
+ ++table;
+ }
+
+}
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderoptions_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderoptions_p.h
new file mode 100644
index 000000000..005ad7652
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderoptions_p.h
@@ -0,0 +1,32 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGENCODEROPTIONS_P_H
+#define QFFMPEGENCODEROPTIONS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpeghwaccel_p.h"
+#include "qvideoframeformat.h"
+#include "private/qplatformmediarecorder_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+void applyVideoEncoderOptions(const QMediaEncoderSettings &settings, const QByteArray &codecName, AVCodecContext *codec, AVDictionary **opts);
+void applyAudioEncoderOptions(const QMediaEncoderSettings &settings, const QByteArray &codecName, AVCodecContext *codec, AVDictionary **opts);
+
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderthread.cpp b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderthread.cpp
new file mode 100644
index 000000000..27dcc23af
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderthread.cpp
@@ -0,0 +1,31 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qffmpegencoderthread_p.h"
+#include "qmetaobject.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+EncoderThread::EncoderThread(RecordingEngine &recordingEngine) : m_recordingEngine(recordingEngine)
+{
+}
+
+void EncoderThread::setPaused(bool paused)
+{
+ auto guard = lockLoopData();
+ m_paused = paused;
+}
+
+void EncoderThread::setEndOfSourceStream(bool isEnd)
+{
+ m_endOfSourceStream = isEnd;
+ if (isEnd)
+ emit endOfSourceStream();
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegencoderthread_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderthread_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderthread_p.h
new file mode 100644
index 000000000..8cba7bf69
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencoderthread_p.h
@@ -0,0 +1,66 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGENCODERTHREAD_P_H
+#define QFFMPEGENCODERTHREAD_P_H
+
+#include "qffmpegthread_p.h"
+#include "qpointer.h"
+
+#include "private/qmediainputencoderinterface_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+class RecordingEngine;
+
+class EncoderThread : public ConsumerThread, public QMediaInputEncoderInterface
+{
+ Q_OBJECT
+public:
+ EncoderThread(RecordingEngine &recordingEngine);
+
+ void setPaused(bool paused);
+
+ void setSource(QObject *source) { m_source = source; }
+
+ QObject *source() const { return m_source; }
+
+ bool canPushFrame() const override { return m_canPushFrame.load(std::memory_order_relaxed); }
+
+ void setEndOfSourceStream(bool isEnd);
+
+ bool isEndOfSourceStream() const { return m_endOfSourceStream; }
+
+protected:
+ void updateCanPushFrame();
+
+ virtual bool checkIfCanPushFrame() const = 0;
+
+ auto lockLoopData()
+ {
+ return QScopeGuard([this, locker = ConsumerThread::lockLoopData()]() mutable {
+ const bool canPush = !m_paused && checkIfCanPushFrame();
+ locker.unlock();
+ if (m_canPushFrame.exchange(canPush, std::memory_order_relaxed) != canPush)
+ emit canPushFrameChanged();
+ });
+ }
+
+Q_SIGNALS:
+ void canPushFrameChanged();
+ void endOfSourceStream();
+
+protected:
+ bool m_paused = false;
+ bool m_endOfSourceStream = false;
+ std::atomic_bool m_canPushFrame = false;
+ RecordingEngine &m_recordingEngine;
+ QPointer<QObject> m_source;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencodinginitializer.cpp b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencodinginitializer.cpp
new file mode 100644
index 000000000..4f8c21bd5
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencodinginitializer.cpp
@@ -0,0 +1,165 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegencodinginitializer_p.h"
+#include "qffmpegrecordingengineutils_p.h"
+#include "qffmpegrecordingengine_p.h"
+#include "qffmpegaudioinput_p.h"
+#include "qvideoframe.h"
+
+#include "private/qplatformvideoframeinput_p.h"
+#include "private/qplatformaudiobufferinput_p.h"
+#include "private/qplatformaudiobufferinput_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+EncodingInitializer::EncodingInitializer(RecordingEngine &engine) : m_recordingEngine(engine) { }
+
+EncodingInitializer::~EncodingInitializer()
+{
+ for (QObject *source : m_pendingSources)
+ setEncoderInterface(source, nullptr);
+}
+
+void EncodingInitializer::start(const std::vector<QPlatformAudioBufferInputBase *> &audioSources,
+ const std::vector<QPlatformVideoSource *> &videoSources)
+{
+ for (auto source : audioSources) {
+ if (auto audioInput = qobject_cast<QFFmpegAudioInput *>(source))
+ m_recordingEngine.addAudioInput(audioInput);
+ else if (auto audioBufferInput = qobject_cast<QPlatformAudioBufferInput *>(source))
+ addAudioBufferInput(audioBufferInput);
+ else
+ Q_ASSERT(!"Undefined source type");
+ }
+
+ for (auto source : videoSources)
+ addVideoSource(source);
+
+ tryStartRecordingEngine();
+}
+
+void EncodingInitializer::addAudioBufferInput(QPlatformAudioBufferInput *input)
+{
+ Q_ASSERT(input);
+
+ if (input->audioFormat().isValid())
+ m_recordingEngine.addAudioBufferInput(input, {});
+ else
+ addPendingAudioBufferInput(input);
+}
+
+void EncodingInitializer::addPendingAudioBufferInput(QPlatformAudioBufferInput *input)
+{
+ addPendingSource(input);
+
+ connect(input, &QPlatformAudioBufferInput::destroyed, this, [this, input]() {
+ erasePendingSource(input, QStringLiteral("Audio source deleted"), true);
+ });
+
+ connect(input, &QPlatformAudioBufferInput::newAudioBuffer, this,
+ [this, input](const QAudioBuffer &buffer) {
+ if (buffer.isValid())
+ erasePendingSource(
+ input, [&]() { m_recordingEngine.addAudioBufferInput(input, buffer); });
+ else
+ erasePendingSource(input,
+ QStringLiteral("Audio source has sent the end frame"));
+ });
+}
+
+void EncodingInitializer::addVideoSource(QPlatformVideoSource *source)
+{
+ Q_ASSERT(source);
+ Q_ASSERT(source->isActive());
+
+ if (source->frameFormat().isValid())
+ m_recordingEngine.addVideoSource(source, {});
+ else if (source->hasError())
+ emitStreamInitializationError(QStringLiteral("Video source error: ")
+ + source->errorString());
+ else
+ addPendingVideoSource(source);
+}
+
+void EncodingInitializer::addPendingVideoSource(QPlatformVideoSource *source)
+{
+ addPendingSource(source);
+
+ connect(source, &QPlatformVideoSource::errorChanged, this, [this, source]() {
+ if (source->hasError())
+ erasePendingSource(source,
+ QStringLiteral("Videio source error: ") + source->errorString());
+ });
+
+ connect(source, &QPlatformVideoSource::destroyed, this, [this, source]() {
+ erasePendingSource(source, QStringLiteral("Source deleted"), true);
+ });
+
+ connect(source, &QPlatformVideoSource::activeChanged, this, [this, source]() {
+ if (!source->isActive())
+ erasePendingSource(source, QStringLiteral("Video source deactivated"));
+ });
+
+ connect(source, &QPlatformVideoSource::newVideoFrame, this,
+ [this, source](const QVideoFrame &frame) {
+ if (frame.isValid())
+ erasePendingSource(source,
+ [&]() { m_recordingEngine.addVideoSource(source, frame); });
+ else
+ erasePendingSource(source,
+ QStringLiteral("Video source has sent the end frame"));
+ });
+}
+
+void EncodingInitializer::tryStartRecordingEngine()
+{
+ if (m_pendingSources.empty())
+ m_recordingEngine.start();
+}
+
+void EncodingInitializer::emitStreamInitializationError(QString error)
+{
+ emit m_recordingEngine.streamInitializationError(
+ QMediaRecorder::ResourceError,
+ QStringLiteral("Video steam initialization error. ") + error);
+}
+
+void EncodingInitializer::addPendingSource(QObject *source)
+{
+ Q_ASSERT(m_pendingSources.count(source) == 0);
+
+ setEncoderInterface(source, this);
+ m_pendingSources.emplace(source);
+}
+
+template <typename F>
+void EncodingInitializer::erasePendingSource(QObject *source, F &&functionOrError, bool destroyed)
+{
+ const auto erasedCount = m_pendingSources.erase(source);
+ if (erasedCount == 0)
+ return; // got a queued event, just ignore it.
+
+ if (!destroyed) {
+ setEncoderInterface(source, nullptr);
+ disconnect(source, nullptr, this, nullptr);
+ }
+
+ if constexpr (std::is_invocable_v<F>)
+ functionOrError();
+ else
+ emitStreamInitializationError(functionOrError);
+
+ tryStartRecordingEngine();
+}
+
+bool EncodingInitializer::canPushFrame() const
+{
+ return true;
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencodinginitializer_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencodinginitializer_p.h
new file mode 100644
index 000000000..e3bcb3428
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegencodinginitializer_p.h
@@ -0,0 +1,77 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QENCODINGINITIALIZER_P_H
+#define QENCODINGINITIALIZER_P_H
+
+#include "qobject.h"
+#include "private/qmediainputencoderinterface_p.h"
+#include <unordered_set>
+#include <vector>
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegAudioInput;
+class QPlatformVideoSource;
+class QPlatformAudioBufferInput;
+class QPlatformAudioBufferInputBase;
+class QMediaInputEncoderInterface;
+
+namespace QFFmpeg {
+
+class RecordingEngine;
+
+// Initializes RecordingEngine with audio and video sources, potentially lazily
+// upon first frame arrival if video frame format is not pre-determined.
+class EncodingInitializer : public QObject, private QMediaInputEncoderInterface
+{
+public:
+ EncodingInitializer(RecordingEngine &engine);
+
+ ~EncodingInitializer() override;
+
+ void start(const std::vector<QPlatformAudioBufferInputBase *> &audioSources,
+ const std::vector<QPlatformVideoSource *> &videoSources);
+
+private:
+ void addAudioBufferInput(QPlatformAudioBufferInput *input);
+
+ void addPendingAudioBufferInput(QPlatformAudioBufferInput *input);
+
+ void addVideoSource(QPlatformVideoSource *source);
+
+ void addPendingVideoSource(QPlatformVideoSource *source);
+
+ void addPendingSource(QObject *source);
+
+ void tryStartRecordingEngine();
+
+private:
+ void emitStreamInitializationError(QString error);
+
+ template <typename F>
+ void erasePendingSource(QObject *source, F &&functionOrError, bool destroyed = false);
+
+ bool canPushFrame() const override;
+
+private:
+ RecordingEngine &m_recordingEngine;
+ std::unordered_set<QObject *> m_pendingSources;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QENCODINGINITIALIZER_P_H
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegmuxer.cpp b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegmuxer.cpp
new file mode 100644
index 000000000..6a33e79dd
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegmuxer.cpp
@@ -0,0 +1,64 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qffmpegmuxer_p.h"
+#include "qffmpegrecordingengine_p.h"
+#include "qffmpegrecordingengineutils_p.h"
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+static Q_LOGGING_CATEGORY(qLcFFmpegMuxer, "qt.multimedia.ffmpeg.muxer");
+
+Muxer::Muxer(RecordingEngine *encoder) : m_encoder(encoder)
+{
+ setObjectName(QLatin1String("Muxer"));
+}
+
+void Muxer::addPacket(AVPacketUPtr packet)
+{
+ {
+ QMutexLocker locker = lockLoopData();
+ m_packetQueue.push(std::move(packet));
+ }
+
+ // qCDebug(qLcFFmpegEncoder) << "Muxer::addPacket" << packet->pts << packet->stream_index;
+ dataReady();
+}
+
+AVPacketUPtr Muxer::takePacket()
+{
+ QMutexLocker locker = lockLoopData();
+ return dequeueIfPossible(m_packetQueue);
+}
+
+void Muxer::init()
+{
+ qCDebug(qLcFFmpegMuxer) << "Muxer::init started thread.";
+}
+
+void Muxer::cleanup()
+{
+ while (!m_packetQueue.empty())
+ processOne();
+}
+
+bool QFFmpeg::Muxer::hasData() const
+{
+ return !m_packetQueue.empty();
+}
+
+void Muxer::processOne()
+{
+ auto packet = takePacket();
+ // qCDebug(qLcFFmpegEncoder) << "writing packet to file" << packet->pts << packet->duration <<
+ // packet->stream_index;
+
+ // the function takes ownership for the packet
+ av_interleaved_write_frame(m_encoder->avFormatContext(), packet.release());
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegmuxer_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegmuxer_p.h
new file mode 100644
index 000000000..4f8f4d27a
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegmuxer_p.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGMUXER_P_H
+#define QFFMPEGMUXER_P_H
+
+#include "qffmpegthread_p.h"
+#include "qffmpeg_p.h"
+#include <queue>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+class RecordingEngine;
+
+class Muxer : public ConsumerThread
+{
+public:
+ Muxer(RecordingEngine *encoder);
+
+ void addPacket(AVPacketUPtr packet);
+
+private:
+ AVPacketUPtr takePacket();
+
+ void init() override;
+ void cleanup() override;
+ bool hasData() const override;
+ void processOne() override;
+
+private:
+ std::queue<AVPacketUPtr> m_packetQueue;
+
+ RecordingEngine *m_encoder;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengine.cpp b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengine.cpp
new file mode 100644
index 000000000..61b3b0cf6
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengine.cpp
@@ -0,0 +1,267 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qffmpegrecordingengine_p.h"
+#include "qffmpegencodinginitializer_p.h"
+#include "qffmpegaudioencoder_p.h"
+#include "qffmpegaudioinput_p.h"
+#include "qffmpegrecordingengineutils_p.h"
+
+#include "private/qmultimediautils_p.h"
+#include "private/qplatformaudiobufferinput_p.h"
+#include "private/qplatformvideosource_p.h"
+#include "private/qplatformvideoframeinput_p.h"
+
+#include "qdebug.h"
+#include "qffmpegvideoencoder_p.h"
+#include "qffmpegmediametadata_p.h"
+#include "qffmpegmuxer_p.h"
+#include "qloggingcategory.h"
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcFFmpegEncoder, "qt.multimedia.ffmpeg.encoder");
+
+namespace QFFmpeg
+{
+
+RecordingEngine::RecordingEngine(const QMediaEncoderSettings &settings,
+ std::unique_ptr<EncodingFormatContext> context)
+ : m_settings(settings), m_formatContext(std::move(context)), m_muxer(new Muxer(this))
+{
+ Q_ASSERT(m_formatContext);
+ Q_ASSERT(m_formatContext->isAVIOOpen());
+}
+
+RecordingEngine::~RecordingEngine()
+{
+}
+
+void RecordingEngine::addAudioInput(QFFmpegAudioInput *input)
+{
+ Q_ASSERT(input);
+
+ if (input->device.isNull()) {
+ emit streamInitializationError(QMediaRecorder::ResourceError,
+ QLatin1StringView("Audio device is null"));
+ return;
+ }
+
+ const QAudioFormat format = input->device.preferredFormat();
+
+ if (!format.isValid()) {
+ emit streamInitializationError(
+ QMediaRecorder::FormatError,
+ QLatin1StringView("Audio device has invalid preferred format"));
+ return;
+ }
+
+ AudioEncoder *audioEncoder = createAudioEncoder(format);
+ connectEncoderToSource(audioEncoder, input);
+
+ input->setRunning(true);
+}
+
+void RecordingEngine::addAudioBufferInput(QPlatformAudioBufferInput *input,
+ const QAudioBuffer &firstBuffer)
+{
+ Q_ASSERT(input);
+ const QAudioFormat format = firstBuffer.isValid() ? firstBuffer.format() : input->audioFormat();
+
+ AudioEncoder *audioEncoder = createAudioEncoder(format);
+
+ // set the buffer before connecting to avoid potential races
+ if (firstBuffer.isValid())
+ audioEncoder->addBuffer(firstBuffer);
+
+ connectEncoderToSource(audioEncoder, input);
+}
+
+AudioEncoder *RecordingEngine::createAudioEncoder(const QAudioFormat &format)
+{
+ Q_ASSERT(format.isValid());
+
+ auto audioEncoder = new AudioEncoder(*this, format, m_settings);
+ m_audioEncoders.push_back(audioEncoder);
+ connect(audioEncoder, &EncoderThread::endOfSourceStream, this,
+ &RecordingEngine::handleSourceEndOfStream);
+
+ return audioEncoder;
+}
+
+void RecordingEngine::addVideoSource(QPlatformVideoSource *source, const QVideoFrame &firstFrame)
+{
+ QVideoFrameFormat frameFormat =
+ firstFrame.isValid() ? firstFrame.surfaceFormat() : source->frameFormat();
+
+ Q_ASSERT(frameFormat.isValid());
+
+ if (firstFrame.isValid() && frameFormat.streamFrameRate() <= 0.f) {
+ const qint64 startTime = firstFrame.startTime();
+ const qint64 endTime = firstFrame.endTime();
+ if (startTime != -1 && endTime > startTime)
+ frameFormat.setStreamFrameRate(static_cast<qreal>(VideoFrameTimeBase)
+ / (endTime - startTime));
+ }
+
+ std::optional<AVPixelFormat> hwPixelFormat = source->ffmpegHWPixelFormat()
+ ? AVPixelFormat(*source->ffmpegHWPixelFormat())
+ : std::optional<AVPixelFormat>{};
+
+ qCDebug(qLcFFmpegEncoder) << "adding video source" << source->metaObject()->className() << ":"
+ << "pixelFormat=" << frameFormat.pixelFormat()
+ << "frameSize=" << frameFormat.frameSize()
+ << "frameRate=" << frameFormat.streamFrameRate()
+ << "ffmpegHWPixelFormat=" << (hwPixelFormat ? *hwPixelFormat : AV_PIX_FMT_NONE);
+
+ auto veUPtr = std::make_unique<VideoEncoder>(*this, m_settings, frameFormat, hwPixelFormat);
+ if (!veUPtr->isValid()) {
+ emit streamInitializationError(QMediaRecorder::FormatError,
+ QLatin1StringView("Cannot initialize encoder"));
+ return;
+ }
+
+ auto videoEncoder = veUPtr.release();
+ m_videoEncoders.append(videoEncoder);
+
+ connect(videoEncoder, &EncoderThread::endOfSourceStream, this,
+ &RecordingEngine::handleSourceEndOfStream);
+
+ // set the frame before connecting to avoid potential races
+ if (firstFrame.isValid())
+ videoEncoder->addFrame(firstFrame);
+
+ connectEncoderToSource(videoEncoder, source);
+}
+
+void RecordingEngine::start()
+{
+ Q_ASSERT(m_initializer);
+ m_initializer.reset();
+
+ if (m_audioEncoders.empty() && m_videoEncoders.empty()) {
+ emit sessionError(QMediaRecorder::ResourceError,
+ QLatin1StringView("No valid stream found for encoding"));
+ return;
+ }
+
+ qCDebug(qLcFFmpegEncoder) << "RecordingEngine::start!";
+
+ avFormatContext()->metadata = QFFmpegMetaData::toAVMetaData(m_metaData);
+
+ Q_ASSERT(!m_isHeaderWritten);
+
+ int res = avformat_write_header(avFormatContext(), nullptr);
+ if (res < 0) {
+ qWarning() << "could not write header, error:" << res << err2str(res);
+ emit sessionError(QMediaRecorder::ResourceError,
+ QLatin1StringView("Cannot start writing the stream"));
+ return;
+ }
+
+ m_isHeaderWritten = true;
+
+ qCDebug(qLcFFmpegEncoder) << "stream header is successfully written";
+
+ m_muxer->start();
+
+ forEachEncoder([](QThread *thread) { thread->start(); });
+}
+
+void RecordingEngine::initialize(const std::vector<QPlatformAudioBufferInputBase *> &audioSources,
+ const std::vector<QPlatformVideoSource *> &videoSources)
+{
+ qCDebug(qLcFFmpegEncoder) << ">>>>>>>>>>>>>>> initialize";
+
+ m_initializer = std::make_unique<EncodingInitializer>(*this);
+ m_initializer->start(audioSources, videoSources);
+}
+
+RecordingEngine::EncodingFinalizer::EncodingFinalizer(RecordingEngine &recordingEngine)
+ : m_recordingEngine(recordingEngine)
+{
+ connect(this, &QThread::finished, this, &QObject::deleteLater);
+}
+
+void RecordingEngine::EncodingFinalizer::run()
+{
+ m_recordingEngine.forEachEncoder(&EncoderThread::stopAndDelete);
+ m_recordingEngine.m_muxer->stopAndDelete();
+
+ if (m_recordingEngine.m_isHeaderWritten) {
+ const int res = av_write_trailer(m_recordingEngine.avFormatContext());
+ if (res < 0) {
+ const auto errorDescription = err2str(res);
+ qCWarning(qLcFFmpegEncoder) << "could not write trailer" << res << errorDescription;
+ emit m_recordingEngine.sessionError(QMediaRecorder::FormatError,
+ QLatin1String("Cannot write trailer: ")
+ + errorDescription);
+ }
+ }
+ // else ffmpeg might crash
+
+ // close AVIO before emitting finalizationDone.
+ m_recordingEngine.m_formatContext->closeAVIO();
+
+ qCDebug(qLcFFmpegEncoder) << " done finalizing.";
+ emit m_recordingEngine.finalizationDone();
+ auto recordingEnginePtr = &m_recordingEngine;
+ delete recordingEnginePtr;
+}
+
+void RecordingEngine::finalize()
+{
+ qCDebug(qLcFFmpegEncoder) << ">>>>>>>>>>>>>>> finalize";
+
+ m_initializer.reset();
+
+ forEachEncoder(&disconnectEncoderFromSource);
+
+ auto *finalizer = new EncodingFinalizer(*this);
+ finalizer->start();
+}
+
+void RecordingEngine::setPaused(bool paused)
+{
+ forEachEncoder(&EncoderThread::setPaused, paused);
+}
+
+void RecordingEngine::setMetaData(const QMediaMetaData &metaData)
+{
+ m_metaData = metaData;
+}
+
+void RecordingEngine::newTimeStamp(qint64 time)
+{
+ QMutexLocker locker(&m_timeMutex);
+ if (time > m_timeRecorded) {
+ m_timeRecorded = time;
+ emit durationChanged(time);
+ }
+}
+
+bool RecordingEngine::isEndOfSourceStreams() const
+{
+ auto isAtEnd = [](EncoderThread *encoder) { return encoder->isEndOfSourceStream(); };
+ return std::all_of(m_videoEncoders.cbegin(), m_videoEncoders.cend(), isAtEnd)
+ && std::all_of(m_audioEncoders.cbegin(), m_audioEncoders.cend(), isAtEnd);
+}
+
+void RecordingEngine::handleSourceEndOfStream()
+{
+ if (isEndOfSourceStreams())
+ emit endOfSourceStreams();
+}
+
+template <typename F, typename... Args>
+void RecordingEngine::forEachEncoder(F &&f, Args &&...args)
+{
+ for (AudioEncoder *audioEncoder : m_audioEncoders)
+ std::invoke(f, audioEncoder, args...);
+ for (VideoEncoder *videoEncoder : m_videoEncoders)
+ std::invoke(f, videoEncoder, args...);
+}
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qffmpegrecordingengine_p.cpp"
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengine_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengine_p.h
new file mode 100644
index 000000000..125bdc56a
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengine_p.h
@@ -0,0 +1,116 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGENCODER_P_H
+#define QFFMPEGENCODER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpegthread_p.h"
+#include "qffmpegencodingformatcontext_p.h"
+
+#include <private/qplatformmediarecorder_p.h>
+#include <qmediarecorder.h>
+
+QT_BEGIN_NAMESPACE
+
+class QFFmpegAudioInput;
+class QPlatformAudioBufferInput;
+class QPlatformAudioBufferInputBase;
+class QVideoFrame;
+class QAudioBuffer;
+class QPlatformVideoSource;
+
+namespace QFFmpeg
+{
+
+class RecordingEngine;
+class Muxer;
+class AudioEncoder;
+class VideoEncoder;
+class VideoFrameEncoder;
+class EncodingInitializer;
+
+class RecordingEngine : public QObject
+{
+ Q_OBJECT
+public:
+ RecordingEngine(const QMediaEncoderSettings &settings, std::unique_ptr<EncodingFormatContext> context);
+ ~RecordingEngine();
+
+ void initialize(const std::vector<QPlatformAudioBufferInputBase *> &audioSources,
+ const std::vector<QPlatformVideoSource *> &videoSources);
+ void finalize();
+
+ void setPaused(bool p);
+
+ void setMetaData(const QMediaMetaData &metaData);
+ AVFormatContext *avFormatContext() { return m_formatContext->avFormatContext(); }
+ Muxer *getMuxer() { return m_muxer; }
+
+ bool isEndOfSourceStreams() const;
+
+public Q_SLOTS:
+ void newTimeStamp(qint64 time);
+
+Q_SIGNALS:
+ void durationChanged(qint64 duration);
+ void sessionError(QMediaRecorder::Error code, const QString &description);
+ void streamInitializationError(QMediaRecorder::Error code, const QString &description);
+ void finalizationDone();
+ void endOfSourceStreams();
+
+private:
+ class EncodingFinalizer : public QThread
+ {
+ public:
+ EncodingFinalizer(RecordingEngine &recordingEngine);
+
+ void run() override;
+
+ private:
+ RecordingEngine &m_recordingEngine;
+ };
+
+ friend class EncodingInitializer;
+ void addAudioInput(QFFmpegAudioInput *input);
+ void addAudioBufferInput(QPlatformAudioBufferInput *input, const QAudioBuffer &firstBuffer);
+ AudioEncoder *createAudioEncoder(const QAudioFormat &format);
+
+ void addVideoSource(QPlatformVideoSource *source, const QVideoFrame &firstFrame);
+ void handleSourceEndOfStream();
+
+ void start();
+
+ template <typename F, typename... Args>
+ void forEachEncoder(F &&f, Args &&...args);
+
+private:
+ QMediaEncoderSettings m_settings;
+ QMediaMetaData m_metaData;
+ std::unique_ptr<EncodingFormatContext> m_formatContext;
+ Muxer *m_muxer = nullptr;
+
+ QList<AudioEncoder *> m_audioEncoders;
+ QList<VideoEncoder *> m_videoEncoders;
+ std::unique_ptr<EncodingInitializer> m_initializer;
+
+ QMutex m_timeMutex;
+ qint64 m_timeRecorded = 0;
+
+ bool m_isHeaderWritten = false;
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengineutils.cpp b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengineutils.cpp
new file mode 100644
index 000000000..6c2ba8b15
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengineutils.cpp
@@ -0,0 +1,63 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "recordingengine/qffmpegrecordingengineutils_p.h"
+#include "recordingengine/qffmpegencoderthread_p.h"
+#include "private/qplatformaudiobufferinput_p.h"
+#include "private/qplatformvideoframeinput_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+template <typename F>
+void doWithMediaFrameInput(QObject *source, F &&f)
+{
+ if (auto videoFrameInput = qobject_cast<QPlatformVideoFrameInput *>(source))
+ f(videoFrameInput);
+ else if (auto audioBufferInput = qobject_cast<QPlatformAudioBufferInput *>(source))
+ f(audioBufferInput);
+}
+
+void setEncoderInterface(QObject *source, QMediaInputEncoderInterface *interface)
+{
+ doWithMediaFrameInput(source, [&](auto source) {
+ using Source = std::remove_pointer_t<decltype(source)>;
+
+ source->setEncoderInterface(interface);
+ if (interface)
+ // Postpone emit 'encoderUpdated' as the encoding pipeline may be not
+ // completely ready at the moment. The case is calling QMediaRecorder::stop
+ // upon handling 'readyToSendFrame'
+ QMetaObject::invokeMethod(source, &Source::encoderUpdated, Qt::QueuedConnection);
+ else
+ emit source->encoderUpdated();
+ });
+}
+
+void setEncoderUpdateConnection(QObject *source, EncoderThread *encoder)
+{
+ doWithMediaFrameInput(source, [&](auto source) {
+ using Source = std::remove_pointer_t<decltype(source)>;
+ QObject::connect(encoder, &EncoderThread::canPushFrameChanged, source,
+ &Source::encoderUpdated);
+ });
+}
+
+void disconnectEncoderFromSource(EncoderThread *encoder)
+{
+ QObject *source = encoder->source();
+ if (!source)
+ return;
+
+ // We should address the dependency AudioEncoder from QFFmpegAudioInput to
+ // set null source here.
+ // encoder->setSource(nullptr);
+
+ QObject::disconnect(source, nullptr, encoder, nullptr);
+ setEncoderInterface(source, nullptr);
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengineutils_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengineutils_p.h
new file mode 100644
index 000000000..3ef56435a
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengineutils_p.h
@@ -0,0 +1,81 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFFMPEGRECORDINGENGINEUTILS_P_H
+#define QFFMPEGRECORDINGENGINEUTILS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qobject.h"
+#include <queue>
+
+QT_BEGIN_NAMESPACE
+
+class QMediaInputEncoderInterface;
+class QPlatformVideoSource;
+
+namespace QFFmpeg {
+
+constexpr qint64 VideoFrameTimeBase = 1000000; // us in sec
+
+class EncoderThread;
+
+template <typename T>
+T dequeueIfPossible(std::queue<T> &queue)
+{
+ if (queue.empty())
+ return T{};
+
+ auto result = std::move(queue.front());
+ queue.pop();
+ return result;
+}
+
+void setEncoderInterface(QObject *source, QMediaInputEncoderInterface *interface);
+
+void setEncoderUpdateConnection(QObject *source, EncoderThread *encoder);
+
+template <typename Encoder, typename Source>
+void connectEncoderToSource(Encoder *encoder, Source *source)
+{
+ Q_ASSERT(!encoder->source());
+ encoder->setSource(source);
+
+ if constexpr (std::is_same_v<Source, QPlatformVideoSource>) {
+ QObject::connect(source, &Source::newVideoFrame, encoder, &Encoder::addFrame,
+ Qt::DirectConnection);
+
+ QObject::connect(source, &Source::activeChanged, encoder, [=]() {
+ if (!source->isActive())
+ encoder->setEndOfSourceStream(true);
+ });
+ } else {
+ QObject::connect(source, &Source::newAudioBuffer, encoder, &Encoder::addBuffer,
+ Qt::DirectConnection);
+ }
+
+ // TODO:
+ // QObject::connect(source, &Source::disconnectedFromSession, encoder, [=]() {
+ // encoder->setSourceEndOfStream(true);
+ // });
+
+ setEncoderUpdateConnection(source, encoder);
+ setEncoderInterface(source, encoder);
+}
+
+void disconnectEncoderFromSource(EncoderThread *encoder);
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGRECORDINGENGINEUTILS_P_H
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoder.cpp b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoder.cpp
new file mode 100644
index 000000000..5ae3aa496
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoder.cpp
@@ -0,0 +1,245 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qffmpegvideoencoder_p.h"
+#include "qffmpegmuxer_p.h"
+#include "qffmpegvideobuffer_p.h"
+#include "qffmpegrecordingengine_p.h"
+#include "qffmpegvideoframeencoder_p.h"
+#include "qffmpegrecordingengineutils_p.h"
+#include "private/qvideoframe_p.h"
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+static Q_LOGGING_CATEGORY(qLcFFmpegVideoEncoder, "qt.multimedia.ffmpeg.videoencoder");
+
+VideoEncoder::VideoEncoder(RecordingEngine &recordingEngine, const QMediaEncoderSettings &settings,
+ const QVideoFrameFormat &format, std::optional<AVPixelFormat> hwFormat)
+ : EncoderThread(recordingEngine)
+{
+ setObjectName(QLatin1String("VideoEncoder"));
+
+ AVPixelFormat swFormat = QFFmpegVideoBuffer::toAVPixelFormat(format.pixelFormat());
+ AVPixelFormat ffmpegPixelFormat =
+ hwFormat && *hwFormat != AV_PIX_FMT_NONE ? *hwFormat : swFormat;
+ auto frameRate = format.streamFrameRate();
+ if (frameRate <= 0.) {
+ qWarning() << "Invalid frameRate" << frameRate << "; Using the default instead";
+
+ // set some default frame rate since ffmpeg has UB if it's 0.
+ frameRate = 30.;
+ }
+
+ m_frameEncoder = VideoFrameEncoder::create(settings,
+ format.frameSize(),
+ format.rotation(),
+ frameRate,
+ ffmpegPixelFormat,
+ swFormat,
+ recordingEngine.avFormatContext());
+}
+
+VideoEncoder::~VideoEncoder() = default;
+
+bool VideoEncoder::isValid() const
+{
+ return m_frameEncoder != nullptr;
+}
+
+void VideoEncoder::addFrame(const QVideoFrame &frame)
+{
+ if (!frame.isValid()) {
+ setEndOfSourceStream(true);
+ return;
+ }
+
+ setEndOfSourceStream(false);
+
+ {
+ auto guard = lockLoopData();
+
+ if (m_paused) {
+ m_shouldAdjustTimeBaseForNextFrame = true;
+ return;
+ }
+
+ // Drop frames if encoder can not keep up with the video source data rate;
+ // canPushFrame might be used instead
+ const bool queueFull = m_videoFrameQueue.size() >= m_maxQueueSize;
+
+ if (queueFull) {
+ qCDebug(qLcFFmpegVideoEncoder) << "RecordingEngine frame queue full. Frame lost.";
+ return;
+ }
+
+ m_videoFrameQueue.push({ frame, m_shouldAdjustTimeBaseForNextFrame });
+ m_shouldAdjustTimeBaseForNextFrame = false;
+ }
+
+ dataReady();
+}
+
+VideoEncoder::FrameInfo VideoEncoder::takeFrame()
+{
+ auto guard = lockLoopData();
+ return dequeueIfPossible(m_videoFrameQueue);
+}
+
+void VideoEncoder::retrievePackets()
+{
+ if (!m_frameEncoder)
+ return;
+ while (auto packet = m_frameEncoder->retrievePacket())
+ m_recordingEngine.getMuxer()->addPacket(std::move(packet));
+}
+
+void VideoEncoder::init()
+{
+ Q_ASSERT(isValid());
+
+ qCDebug(qLcFFmpegVideoEncoder) << "VideoEncoder::init started video device thread.";
+ bool ok = m_frameEncoder->open();
+ if (!ok)
+ emit m_recordingEngine.sessionError(QMediaRecorder::ResourceError,
+ "Could not initialize encoder");
+}
+
+void VideoEncoder::cleanup()
+{
+ while (!m_videoFrameQueue.empty())
+ processOne();
+ if (m_frameEncoder) {
+ while (m_frameEncoder->sendFrame(nullptr) == AVERROR(EAGAIN))
+ retrievePackets();
+ retrievePackets();
+ }
+}
+
+bool VideoEncoder::hasData() const
+{
+ return !m_videoFrameQueue.empty();
+}
+
+struct QVideoFrameHolder
+{
+ QVideoFrame f;
+ QImage i;
+};
+
+static void freeQVideoFrame(void *opaque, uint8_t *)
+{
+ delete reinterpret_cast<QVideoFrameHolder *>(opaque);
+}
+
+void VideoEncoder::processOne()
+{
+ retrievePackets();
+
+ FrameInfo frameInfo = takeFrame();
+ QVideoFrame &frame = frameInfo.frame;
+ Q_ASSERT(frame.isValid());
+
+ if (!isValid())
+ return;
+
+ // qCDebug(qLcFFmpegEncoder) << "new video buffer" << frame.startTime();
+
+ AVFrameUPtr avFrame;
+
+ auto *videoBuffer = dynamic_cast<QFFmpegVideoBuffer *>(QVideoFramePrivate::hwBuffer(frame));
+ if (videoBuffer) {
+ // ffmpeg video buffer, let's use the native AVFrame stored in there
+ auto *hwFrame = videoBuffer->getHWFrame();
+ if (hwFrame && hwFrame->format == m_frameEncoder->sourceFormat())
+ avFrame.reset(av_frame_clone(hwFrame));
+ }
+
+ if (!avFrame) {
+ frame.map(QtVideo::MapMode::ReadOnly);
+ auto size = frame.size();
+ avFrame = makeAVFrame();
+ avFrame->format = m_frameEncoder->sourceFormat();
+ avFrame->width = size.width();
+ avFrame->height = size.height();
+
+ for (int i = 0; i < 4; ++i) {
+ avFrame->data[i] = const_cast<uint8_t *>(frame.bits(i));
+ avFrame->linesize[i] = frame.bytesPerLine(i);
+ }
+
+ QImage img;
+ if (frame.pixelFormat() == QVideoFrameFormat::Format_Jpeg) {
+ // the QImage is cached inside the video frame, so we can take the pointer to the image
+ // data here
+ img = frame.toImage();
+ avFrame->data[0] = (uint8_t *)img.bits();
+ avFrame->linesize[0] = img.bytesPerLine();
+ }
+
+ Q_ASSERT(avFrame->data[0]);
+ // ensure the video frame and it's data is alive as long as it's being used in the encoder
+ avFrame->opaque_ref = av_buffer_create(nullptr, 0, freeQVideoFrame,
+ new QVideoFrameHolder{ frame, img }, 0);
+ }
+
+ const auto [startTime, endTime] = frameTimeStamps(frame);
+
+ if (frameInfo.shouldAdjustTimeBase) {
+ m_baseTime += startTime - m_lastFrameTime;
+ qCDebug(qLcFFmpegVideoEncoder)
+ << ">>>> adjusting base time to" << m_baseTime << startTime << m_lastFrameTime;
+ }
+
+ const qint64 time = startTime - m_baseTime;
+ m_lastFrameTime = endTime;
+
+ setAVFrameTime(*avFrame, m_frameEncoder->getPts(time), m_frameEncoder->getTimeBase());
+
+ m_recordingEngine.newTimeStamp(time / 1000);
+
+ qCDebug(qLcFFmpegVideoEncoder)
+ << ">>> sending frame" << avFrame->pts << time << m_lastFrameTime;
+ int ret = m_frameEncoder->sendFrame(std::move(avFrame));
+ if (ret < 0) {
+ qCDebug(qLcFFmpegVideoEncoder) << "error sending frame" << ret << err2str(ret);
+ emit m_recordingEngine.sessionError(QMediaRecorder::ResourceError, err2str(ret));
+ }
+}
+
+bool VideoEncoder::checkIfCanPushFrame() const
+{
+ if (isRunning())
+ return m_videoFrameQueue.size() < m_maxQueueSize;
+ if (!isFinished())
+ return m_videoFrameQueue.empty();
+
+ return false;
+}
+
+std::pair<qint64, qint64> VideoEncoder::frameTimeStamps(const QVideoFrame &frame) const
+{
+ qint64 startTime = frame.startTime();
+ qint64 endTime = frame.endTime();
+
+ if (startTime == -1) {
+ startTime = m_lastFrameTime;
+ endTime = -1;
+ }
+
+ if (endTime == -1) {
+ qreal frameRate = frame.streamFrameRate();
+ if (frameRate <= 0.)
+ frameRate = m_frameEncoder->settings().videoFrameRate();
+
+ Q_ASSERT(frameRate > 0.f);
+ endTime = startTime + static_cast<qint64>(std::round(VideoFrameTimeBase / frameRate));
+ }
+
+ return { startTime, endTime };
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoder_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoder_p.h
new file mode 100644
index 000000000..ff6a74fc8
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoder_p.h
@@ -0,0 +1,64 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGVIDEOENCODER_P_H
+#define QFFMPEGVIDEOENCODER_P_H
+
+#include "qffmpegencoderthread_p.h"
+#include "qffmpeg_p.h"
+#include <qvideoframe.h>
+#include <queue>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoFrameFormat;
+class QMediaEncoderSettings;
+
+namespace QFFmpeg {
+class VideoFrameEncoder;
+
+class VideoEncoder : public EncoderThread
+{
+public:
+ VideoEncoder(RecordingEngine &recordingEngine, const QMediaEncoderSettings &settings,
+ const QVideoFrameFormat &format, std::optional<AVPixelFormat> hwFormat);
+ ~VideoEncoder() override;
+
+ bool isValid() const;
+
+ void addFrame(const QVideoFrame &frame);
+
+protected:
+ bool checkIfCanPushFrame() const override;
+
+private:
+ struct FrameInfo
+ {
+ QVideoFrame frame;
+ bool shouldAdjustTimeBase = false;
+ };
+
+ FrameInfo takeFrame();
+ void retrievePackets();
+
+ void init() override;
+ void cleanup() override;
+ bool hasData() const override;
+ void processOne() override;
+
+ std::pair<qint64, qint64> frameTimeStamps(const QVideoFrame &frame) const;
+
+private:
+ std::queue<FrameInfo> m_videoFrameQueue;
+ const size_t m_maxQueueSize = 10; // Arbitrarily chosen to limit memory usage (332 MB @ 4K)
+
+ std::unique_ptr<VideoFrameEncoder> m_frameEncoder;
+ qint64 m_baseTime = 0;
+ bool m_shouldAdjustTimeBaseForNextFrame = true;
+ qint64 m_lastFrameTime = 0;
+};
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoderutils.cpp b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoderutils.cpp
new file mode 100644
index 000000000..eef2a64bf
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoderutils.cpp
@@ -0,0 +1,214 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegvideoencoderutils_p.h"
+#include "private/qmultimediautils_p.h"
+
+extern "C" {
+#include <libavutil/pixdesc.h>
+}
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+static AVScore calculateTargetSwFormatScore(const AVPixFmtDescriptor *sourceSwFormatDesc,
+ AVPixelFormat fmt)
+{
+ // determine the format used by the encoder.
+ // We prefer YUV422 based formats such as NV12 or P010. Selection trues to find the best
+ // matching format for the encoder depending on the bit depth of the source format
+
+ const auto *desc = av_pix_fmt_desc_get(fmt);
+ if (!desc)
+ return NotSuitableAVScore;
+
+ const int sourceDepth = sourceSwFormatDesc ? sourceSwFormatDesc->comp[0].depth : 0;
+
+ if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
+ // we really don't want HW accelerated formats here
+ return NotSuitableAVScore;
+
+ auto score = DefaultAVScore;
+
+ if (desc == sourceSwFormatDesc)
+ // prefer exact matches
+ score += 10;
+ if (desc->comp[0].depth == sourceDepth)
+ score += 100;
+ else if (desc->comp[0].depth < sourceDepth)
+ score -= 100 + (sourceDepth - desc->comp[0].depth);
+ if (desc->log2_chroma_h == 1)
+ score += 1;
+ if (desc->log2_chroma_w == 1)
+ score += 1;
+ if (desc->flags & AV_PIX_FMT_FLAG_BE)
+ score -= 10;
+ if (desc->flags & AV_PIX_FMT_FLAG_PAL)
+ // we don't want paletted formats
+ score -= 10000;
+ if (desc->flags & AV_PIX_FMT_FLAG_RGB)
+ // we don't want RGB formats
+ score -= 1000;
+
+ // qCDebug(qLcVideoFrameEncoder)
+ // << "checking format" << fmt << Qt::hex << desc->flags << desc->comp[0].depth
+ // << desc->log2_chroma_h << desc->log2_chroma_w << "score:" << score;
+
+ return score;
+}
+
+static auto targetSwFormatScoreCalculator(AVPixelFormat sourceFormat)
+{
+ const auto sourceSwFormatDesc = av_pix_fmt_desc_get(sourceFormat);
+ return [=](AVPixelFormat fmt) { return calculateTargetSwFormatScore(sourceSwFormatDesc, fmt); };
+}
+
+static bool isHwFormatAcceptedByCodec(AVPixelFormat pixFormat)
+{
+ switch (pixFormat) {
+ case AV_PIX_FMT_MEDIACODEC:
+ // Mediacodec doesn't accept AV_PIX_FMT_MEDIACODEC (QTBUG-116836)
+ return false;
+ default:
+ return true;
+ }
+}
+
+AVPixelFormat findTargetSWFormat(AVPixelFormat sourceSWFormat, const AVCodec *codec,
+ const HWAccel &accel)
+{
+ auto scoreCalculator = targetSwFormatScoreCalculator(sourceSWFormat);
+
+ const auto constraints = accel.constraints();
+ if (constraints && constraints->valid_sw_formats)
+ return findBestAVFormat(constraints->valid_sw_formats, scoreCalculator).first;
+
+ // Some codecs, e.g. mediacodec, don't expose constraints, let's find the format in
+ // codec->pix_fmts
+ if (codec->pix_fmts)
+ return findBestAVFormat(codec->pix_fmts, scoreCalculator).first;
+
+ return AV_PIX_FMT_NONE;
+}
+
+AVPixelFormat findTargetFormat(AVPixelFormat sourceFormat, AVPixelFormat sourceSWFormat,
+ const AVCodec *codec, const HWAccel *accel)
+{
+ Q_UNUSED(sourceFormat);
+
+ if (accel) {
+ const auto hwFormat = accel->hwFormat();
+
+ // TODO: handle codec->capabilities & AV_CODEC_CAP_HARDWARE here
+ if (!isHwFormatAcceptedByCodec(hwFormat))
+ return findTargetSWFormat(sourceSWFormat, codec, *accel);
+
+ const auto constraints = accel->constraints();
+ if (constraints && hasAVFormat(constraints->valid_hw_formats, hwFormat))
+ return hwFormat;
+
+ // Some codecs, don't expose constraints,
+ // let's find the format in codec->pix_fmts and hw_config
+ if (isAVFormatSupported(codec, hwFormat))
+ return hwFormat;
+ }
+
+ if (!codec->pix_fmts) {
+ qWarning() << "Codec pix formats are undefined, it's likely to behave incorrectly";
+
+ return sourceSWFormat;
+ }
+
+ auto swScoreCalculator = targetSwFormatScoreCalculator(sourceSWFormat);
+ return findBestAVFormat(codec->pix_fmts, swScoreCalculator).first;
+}
+
+std::pair<const AVCodec *, std::unique_ptr<HWAccel>> findHwEncoder(AVCodecID codecID,
+ const QSize &resolution)
+{
+ auto matchesSizeConstraints = [&resolution](const HWAccel &accel) {
+ const auto constraints = accel.constraints();
+ if (!constraints)
+ return true;
+
+ return resolution.width() >= constraints->min_width
+ && resolution.height() >= constraints->min_height
+ && resolution.width() <= constraints->max_width
+ && resolution.height() <= constraints->max_height;
+ };
+
+ // 1st - attempt to find hw accelerated encoder
+ auto result = HWAccel::findEncoderWithHwAccel(codecID, matchesSizeConstraints);
+ Q_ASSERT(!!result.first == !!result.second);
+
+ return result;
+}
+
+const AVCodec *findSwEncoder(AVCodecID codecID, AVPixelFormat sourceSWFormat)
+{
+ auto formatScoreCalculator = targetSwFormatScoreCalculator(sourceSWFormat);
+
+ return findAVEncoder(codecID, [&formatScoreCalculator](const AVCodec *codec) {
+ if (!codec->pix_fmts)
+ // codecs without pix_fmts are suspicious
+ return MinAVScore;
+
+ return findBestAVFormat(codec->pix_fmts, formatScoreCalculator).second;
+ });
+}
+
+AVRational adjustFrameRate(const AVRational *supportedRates, qreal requestedRate)
+{
+ auto calcScore = [requestedRate](const AVRational &rate) {
+ // relative comparison
+ return qMin(requestedRate * rate.den, qreal(rate.num))
+ / qMax(requestedRate * rate.den, qreal(rate.num));
+ };
+
+ const auto result = findBestAVValue(supportedRates, calcScore).first;
+ if (result.num && result.den)
+ return result;
+
+ const auto [num, den] = qRealToFraction(requestedRate);
+ return { num, den };
+}
+
+AVRational adjustFrameTimeBase(const AVRational *supportedRates, AVRational frameRate)
+{
+ // TODO: user-specified frame rate might be required.
+ if (supportedRates) {
+ auto hasFrameRate = [&]() {
+ for (auto rate = supportedRates; rate->num && rate->den; ++rate)
+ if (rate->den == frameRate.den && rate->num == frameRate.num)
+ return true;
+
+ return false;
+ };
+
+ Q_ASSERT(hasFrameRate());
+
+ return { frameRate.den, frameRate.num };
+ }
+
+ constexpr int TimeScaleFactor = 1000; // Allows not to follow fixed rate
+ return { frameRate.den, frameRate.num * TimeScaleFactor };
+}
+
+QSize adjustVideoResolution(const AVCodec *codec, QSize requestedResolution)
+{
+#ifdef Q_OS_WINDOWS
+ // TODO: investigate, there might be more encoders not supporting odd resolution
+ if (strcmp(codec->name, "h264_mf") == 0) {
+ auto makeEven = [](int size) { return size & ~1; };
+ return QSize(makeEven(requestedResolution.width()), makeEven(requestedResolution.height()));
+ }
+#else
+ Q_UNUSED(codec);
+#endif
+ return requestedResolution;
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoderutils_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoderutils_p.h
new file mode 100644
index 000000000..3a16a7de3
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoencoderutils_p.h
@@ -0,0 +1,64 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGVIDEOENCODERUTILS_P_H
+#define QFFMPEGVIDEOENCODERUTILS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpeg_p.h"
+#include "qffmpeghwaccel_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QFFmpeg {
+
+AVPixelFormat findTargetSWFormat(AVPixelFormat sourceSWFormat, const AVCodec *codec,
+ const HWAccel &accel);
+
+AVPixelFormat findTargetFormat(AVPixelFormat sourceFormat, AVPixelFormat sourceSWFormat,
+ const AVCodec *codec, const HWAccel *accel);
+
+std::pair<const AVCodec *, std::unique_ptr<HWAccel>> findHwEncoder(AVCodecID codecID,
+ const QSize &sourceSize);
+
+const AVCodec *findSwEncoder(AVCodecID codecID, AVPixelFormat sourceSWFormat);
+
+/**
+ * @brief adjustFrameRate get a rational frame rate be requested qreal rate.
+ * If the codec supports fixed frame rate (non-null supportedRates),
+ * the function selects the most suitable one,
+ * otherwise just makes AVRational from qreal.
+ */
+AVRational adjustFrameRate(const AVRational *supportedRates, qreal requestedRate);
+
+/**
+ * @brief adjustFrameTimeBase gets adjusted timebase by a list of supported frame rates
+ * and an already adjusted frame rate.
+ *
+ * Timebase is the fundamental unit of time (in seconds) in terms
+ * of which frame timestamps are represented.
+ * For fixed-fps content (non-null supportedRates),
+ * timebase should be 1/framerate.
+ *
+ * For more information, see AVStream::time_base and AVCodecContext::time_base.
+ *
+ * The adjusted time base is supposed to be set to stream and codec context.
+ */
+AVRational adjustFrameTimeBase(const AVRational *supportedRates, AVRational frameRate);
+
+QSize adjustVideoResolution(const AVCodec *codec, QSize requestedResolution);
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
+
+#endif // QFFMPEGVIDEOENCODERUTILS_P_H
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder.cpp b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder.cpp
new file mode 100644
index 000000000..6c52f1e87
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder.cpp
@@ -0,0 +1,451 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qffmpegvideoframeencoder_p.h"
+#include "qffmpegmediaformatinfo_p.h"
+#include "qffmpegencoderoptions_p.h"
+#include "qffmpegvideoencoderutils_p.h"
+#include <qloggingcategory.h>
+
+extern "C" {
+#include "libavutil/display.h"
+}
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcVideoFrameEncoder, "qt.multimedia.ffmpeg.videoencoder");
+
+namespace QFFmpeg {
+
+std::unique_ptr<VideoFrameEncoder>
+VideoFrameEncoder::create(const QMediaEncoderSettings &encoderSettings,
+ const QSize &sourceSize,
+ QtVideo::Rotation sourceRotation,
+ qreal sourceFrameRate,
+ AVPixelFormat sourceFormat,
+ AVPixelFormat sourceSWFormat,
+ AVFormatContext *formatContext)
+{
+ Q_ASSERT(isSwPixelFormat(sourceSWFormat));
+ Q_ASSERT(isHwPixelFormat(sourceFormat) || sourceSWFormat == sourceFormat);
+
+ std::unique_ptr<VideoFrameEncoder> result(new VideoFrameEncoder);
+
+ result->m_settings = encoderSettings;
+ result->m_sourceSize = sourceSize;
+ result->m_sourceFormat = sourceFormat;
+ result->m_sourceRotation = sourceRotation;
+
+ // Temporary: check isSwPixelFormat because of android issue (QTBUG-116836)
+ result->m_sourceSWFormat = isSwPixelFormat(sourceFormat) ? sourceFormat : sourceSWFormat;
+
+ if (!result->m_settings.videoResolution().isValid())
+ result->m_settings.setVideoResolution(sourceSize);
+
+ if (result->m_settings.videoFrameRate() <= 0.)
+ result->m_settings.setVideoFrameRate(sourceFrameRate);
+
+ if (!result->initCodec() || !result->initTargetFormats()
+ || !result->initCodecContext(formatContext)) {
+ return nullptr;
+ }
+
+ // TODO: make VideoFrameEncoder::private and do openning here
+ // if (!open()) {
+ // m_error = QMediaRecorder::FormatError;
+ // m_errorStr = QLatin1StringView("Cannot open codec");
+ // return;
+ // }
+
+ result->updateConversions();
+
+ return result;
+}
+
+bool VideoFrameEncoder::initCodec()
+{
+ const auto qVideoCodec = m_settings.videoCodec();
+ const auto codecID = QFFmpegMediaFormatInfo::codecIdForVideoCodec(qVideoCodec);
+ const auto resolution = m_settings.videoResolution();
+
+ std::tie(m_codec, m_accel) = findHwEncoder(codecID, resolution);
+
+ if (!m_codec)
+ m_codec = findSwEncoder(codecID, m_sourceSWFormat);
+
+ if (!m_codec) {
+ qWarning() << "Could not find encoder for codecId" << codecID;
+ return false;
+ }
+
+ qCDebug(qLcVideoFrameEncoder) << "found encoder" << m_codec->name << "for id" << m_codec->id;
+
+#ifdef Q_OS_WINDOWS
+ // TODO: investigate, there might be more encoders not supporting odd resolution
+ if (strcmp(m_codec->name, "h264_mf") == 0) {
+ auto makeEven = [](int size) { return size & ~1; };
+ const QSize fixedResolution(makeEven(resolution.width()), makeEven(resolution.height()));
+ if (fixedResolution != resolution) {
+ qCDebug(qLcVideoFrameEncoder) << "Fix odd video resolution for codec" << m_codec->name
+ << ":" << resolution << "->" << fixedResolution;
+ m_settings.setVideoResolution(fixedResolution);
+ }
+ }
+#endif
+
+ auto fixedResolution = adjustVideoResolution(m_codec, m_settings.videoResolution());
+ if (resolution != fixedResolution) {
+ qCDebug(qLcVideoFrameEncoder) << "Fix odd video resolution for codec" << m_codec->name
+ << ":" << resolution << "->" << fixedResolution;
+
+ m_settings.setVideoResolution(fixedResolution);
+ }
+
+ if (m_codec->supported_framerates && qLcVideoFrameEncoder().isEnabled(QtDebugMsg))
+ for (auto rate = m_codec->supported_framerates; rate->num && rate->den; ++rate)
+ qCDebug(qLcVideoFrameEncoder) << "supported frame rate:" << *rate;
+
+ m_codecFrameRate = adjustFrameRate(m_codec->supported_framerates, m_settings.videoFrameRate());
+ qCDebug(qLcVideoFrameEncoder) << "Adjusted frame rate:" << m_codecFrameRate;
+
+ return true;
+}
+
+bool VideoFrameEncoder::initTargetFormats()
+{
+ m_targetFormat = findTargetFormat(m_sourceFormat, m_sourceSWFormat, m_codec, m_accel.get());
+
+ if (m_targetFormat == AV_PIX_FMT_NONE) {
+ qWarning() << "Could not find target format for codecId" << m_codec->id;
+ return false;
+ }
+
+ if (isHwPixelFormat(m_targetFormat)) {
+ Q_ASSERT(m_accel);
+
+ m_targetSWFormat = findTargetSWFormat(m_sourceSWFormat, m_codec, *m_accel);
+
+ if (m_targetSWFormat == AV_PIX_FMT_NONE) {
+ qWarning() << "Cannot find software target format. sourceSWFormat:" << m_sourceSWFormat
+ << "targetFormat:" << m_targetFormat;
+ return false;
+ }
+
+ m_accel->createFramesContext(m_targetSWFormat, m_settings.videoResolution());
+ if (!m_accel->hwFramesContextAsBuffer())
+ return false;
+ } else {
+ m_targetSWFormat = m_targetFormat;
+ }
+
+ return true;
+}
+
+VideoFrameEncoder::~VideoFrameEncoder() = default;
+
+bool QFFmpeg::VideoFrameEncoder::initCodecContext(AVFormatContext *formatContext)
+{
+ m_stream = avformat_new_stream(formatContext, nullptr);
+ m_stream->id = formatContext->nb_streams - 1;
+ //qCDebug(qLcVideoFrameEncoder) << "Video stream: index" << d->stream->id;
+ m_stream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+ m_stream->codecpar->codec_id = m_codec->id;
+
+ // Apples HEVC decoders don't like the hev1 tag ffmpeg uses by default, use hvc1 as the more commonly accepted tag
+ if (m_codec->id == AV_CODEC_ID_HEVC)
+ m_stream->codecpar->codec_tag = MKTAG('h', 'v', 'c', '1');
+
+ const auto resolution = m_settings.videoResolution();
+
+ // ### Fix hardcoded values
+ m_stream->codecpar->format = m_targetFormat;
+ m_stream->codecpar->width = resolution.width();
+ m_stream->codecpar->height = resolution.height();
+ m_stream->codecpar->sample_aspect_ratio = AVRational{ 1, 1 };
+
+ if (m_sourceRotation != QtVideo::Rotation::None) {
+ constexpr auto displayMatrixSize = sizeof(int32_t) * 9;
+ AVPacketSideData sideData = { reinterpret_cast<uint8_t *>(av_malloc(displayMatrixSize)),
+ displayMatrixSize, AV_PKT_DATA_DISPLAYMATRIX };
+ av_display_rotation_set(reinterpret_cast<int32_t *>(sideData.data),
+ static_cast<double>(m_sourceRotation));
+ addStreamSideData(m_stream, sideData);
+ }
+
+ Q_ASSERT(m_codec);
+
+ m_stream->time_base = adjustFrameTimeBase(m_codec->supported_framerates, m_codecFrameRate);
+ m_codecContext.reset(avcodec_alloc_context3(m_codec));
+ if (!m_codecContext) {
+ qWarning() << "Could not allocate codec context";
+ return false;
+ }
+
+ avcodec_parameters_to_context(m_codecContext.get(), m_stream->codecpar);
+ m_codecContext->time_base = m_stream->time_base;
+ qCDebug(qLcVideoFrameEncoder) << "codecContext time base" << m_codecContext->time_base.num
+ << m_codecContext->time_base.den;
+
+ m_codecContext->framerate = m_codecFrameRate;
+ m_codecContext->pix_fmt = m_targetFormat;
+ m_codecContext->width = resolution.width();
+ m_codecContext->height = resolution.height();
+
+ if (m_accel) {
+ auto deviceContext = m_accel->hwDeviceContextAsBuffer();
+ Q_ASSERT(deviceContext);
+ m_codecContext->hw_device_ctx = av_buffer_ref(deviceContext);
+
+ if (auto framesContext = m_accel->hwFramesContextAsBuffer())
+ m_codecContext->hw_frames_ctx = av_buffer_ref(framesContext);
+ }
+
+ return true;
+}
+
+bool VideoFrameEncoder::open()
+{
+ if (!m_codecContext)
+ return false;
+
+ AVDictionaryHolder opts;
+ applyVideoEncoderOptions(m_settings, m_codec->name, m_codecContext.get(), opts);
+ applyExperimentalCodecOptions(m_codec, opts);
+
+ int res = avcodec_open2(m_codecContext.get(), m_codec, opts);
+ if (res < 0) {
+ m_codecContext.reset();
+ qWarning() << "Couldn't open codec for writing" << err2str(res);
+ return false;
+ }
+ qCDebug(qLcVideoFrameEncoder) << "video codec opened" << res << "time base"
+ << m_codecContext->time_base;
+ return true;
+}
+
+qint64 VideoFrameEncoder::getPts(qint64 us) const
+{
+ qint64 div = 1'000'000 * m_stream->time_base.num;
+ return div != 0 ? (us * m_stream->time_base.den + div / 2) / div : 0;
+}
+
+const AVRational &VideoFrameEncoder::getTimeBase() const
+{
+ return m_stream->time_base;
+}
+
+int VideoFrameEncoder::sendFrame(AVFrameUPtr frame)
+{
+ if (!m_codecContext) {
+ qWarning() << "codec context is not initialized!";
+ return AVERROR(EINVAL);
+ }
+
+ if (!frame)
+ return avcodec_send_frame(m_codecContext.get(), frame.get());
+
+ if (!updateSourceFormatAndSize(frame.get()))
+ return AVERROR(EINVAL);
+
+ int64_t pts = 0;
+ AVRational timeBase = {};
+ getAVFrameTime(*frame, pts, timeBase);
+
+ if (m_downloadFromHW) {
+ auto f = makeAVFrame();
+
+ int err = av_hwframe_transfer_data(f.get(), frame.get(), 0);
+ if (err < 0) {
+ qCDebug(qLcVideoFrameEncoder) << "Error transferring frame data to surface." << err2str(err);
+ return err;
+ }
+
+ frame = std::move(f);
+ }
+
+ if (m_converter) {
+ auto f = makeAVFrame();
+
+ f->format = m_targetSWFormat;
+ f->width = m_settings.videoResolution().width();
+ f->height = m_settings.videoResolution().height();
+
+ av_frame_get_buffer(f.get(), 0);
+ const auto scaledHeight = sws_scale(m_converter.get(), frame->data, frame->linesize, 0,
+ frame->height, f->data, f->linesize);
+
+ if (scaledHeight != f->height)
+ qCWarning(qLcVideoFrameEncoder) << "Scaled height" << scaledHeight << "!=" << f->height;
+
+ frame = std::move(f);
+ }
+
+ if (m_uploadToHW) {
+ auto *hwFramesContext = m_accel->hwFramesContextAsBuffer();
+ Q_ASSERT(hwFramesContext);
+ auto f = makeAVFrame();
+
+ if (!f)
+ return AVERROR(ENOMEM);
+ int err = av_hwframe_get_buffer(hwFramesContext, f.get(), 0);
+ if (err < 0) {
+ qCDebug(qLcVideoFrameEncoder) << "Error getting HW buffer" << err2str(err);
+ return err;
+ } else {
+ qCDebug(qLcVideoFrameEncoder) << "got HW buffer";
+ }
+ if (!f->hw_frames_ctx) {
+ qCDebug(qLcVideoFrameEncoder) << "no hw frames context";
+ return AVERROR(ENOMEM);
+ }
+ err = av_hwframe_transfer_data(f.get(), frame.get(), 0);
+ if (err < 0) {
+ qCDebug(qLcVideoFrameEncoder) << "Error transferring frame data to surface." << err2str(err);
+ return err;
+ }
+ frame = std::move(f);
+ }
+
+ qCDebug(qLcVideoFrameEncoder) << "sending frame" << pts << "*" << timeBase;
+
+ setAVFrameTime(*frame, pts, timeBase);
+ return avcodec_send_frame(m_codecContext.get(), frame.get());
+}
+
+AVPacketUPtr VideoFrameEncoder::retrievePacket()
+{
+ if (!m_codecContext)
+ return nullptr;
+
+ auto getPacket = [&]() {
+ AVPacketUPtr packet(av_packet_alloc());
+ const int ret = avcodec_receive_packet(m_codecContext.get(), packet.get());
+ if (ret < 0) {
+ if (ret != AVERROR(EOF) && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
+ qCDebug(qLcVideoFrameEncoder) << "Error receiving packet" << ret << err2str(ret);
+ return AVPacketUPtr{};
+ }
+ auto ts = timeStampMs(packet->pts, m_stream->time_base);
+
+ qCDebug(qLcVideoFrameEncoder)
+ << "got a packet" << packet->pts << packet->dts << (ts ? *ts : 0);
+
+ packet->stream_index = m_stream->id;
+ return packet;
+ };
+
+ auto fixPacketDts = [&](AVPacket &packet) {
+ // Workaround for some ffmpeg codecs bugs (e.g. nvenc)
+ // Ideally, packet->pts < packet->dts is not expected
+
+ if (packet.dts == AV_NOPTS_VALUE)
+ return true;
+
+ packet.dts -= m_packetDtsOffset;
+
+ if (packet.pts != AV_NOPTS_VALUE && packet.pts < packet.dts) {
+ m_packetDtsOffset += packet.dts - packet.pts;
+ packet.dts = packet.pts;
+
+ if (m_prevPacketDts != AV_NOPTS_VALUE && packet.dts < m_prevPacketDts) {
+ qCWarning(qLcVideoFrameEncoder)
+ << "Skip packet; failed to fix dts:" << packet.dts << m_prevPacketDts;
+ return false;
+ }
+ }
+
+ m_prevPacketDts = packet.dts;
+
+ return true;
+ };
+
+ while (auto packet = getPacket()) {
+ if (fixPacketDts(*packet))
+ return packet;
+ }
+
+ return nullptr;
+}
+
+bool VideoFrameEncoder::updateSourceFormatAndSize(const AVFrame *frame)
+{
+ Q_ASSERT(frame);
+
+ const QSize frameSize(frame->width, frame->height);
+ const AVPixelFormat frameFormat = static_cast<AVPixelFormat>(frame->format);
+
+ if (frameSize == m_sourceSize && frameFormat == m_sourceFormat)
+ return true;
+
+ auto applySourceFormatAndSize = [&](AVPixelFormat swFormat) {
+ m_sourceSize = frameSize;
+ m_sourceFormat = frameFormat;
+ m_sourceSWFormat = swFormat;
+ updateConversions();
+ return true;
+ };
+
+ if (frameFormat == m_sourceFormat)
+ return applySourceFormatAndSize(m_sourceSWFormat);
+
+ if (frameFormat == AV_PIX_FMT_NONE) {
+ qWarning() << "Got a frame with invalid pixel format";
+ return false;
+ }
+
+ if (isSwPixelFormat(frameFormat))
+ return applySourceFormatAndSize(frameFormat);
+
+ auto framesCtx = reinterpret_cast<const AVHWFramesContext *>(frame->hw_frames_ctx->data);
+ if (!framesCtx || framesCtx->sw_format == AV_PIX_FMT_NONE) {
+ qWarning() << "Cannot update conversions as hw frame has invalid framesCtx" << framesCtx;
+ return false;
+ }
+
+ return applySourceFormatAndSize(framesCtx->sw_format);
+}
+
+void VideoFrameEncoder::updateConversions()
+{
+ const bool needToScale = m_sourceSize != m_settings.videoResolution();
+ const bool zeroCopy = m_sourceFormat == m_targetFormat && !needToScale;
+
+ m_converter.reset();
+
+ if (zeroCopy) {
+ m_downloadFromHW = false;
+ m_uploadToHW = false;
+
+ qCDebug(qLcVideoFrameEncoder) << "zero copy encoding, format" << m_targetFormat;
+ // no need to initialize any converters
+ return;
+ }
+
+ m_downloadFromHW = m_sourceFormat != m_sourceSWFormat;
+ m_uploadToHW = m_targetFormat != m_targetSWFormat;
+
+ if (m_sourceSWFormat != m_targetSWFormat || needToScale) {
+ const auto targetSize = m_settings.videoResolution();
+ qCDebug(qLcVideoFrameEncoder)
+ << "video source and encoder use different formats:" << m_sourceSWFormat
+ << m_targetSWFormat << "or sizes:" << m_sourceSize << targetSize;
+
+ m_converter.reset(sws_getContext(m_sourceSize.width(), m_sourceSize.height(),
+ m_sourceSWFormat, targetSize.width(), targetSize.height(),
+ m_targetSWFormat, SWS_FAST_BILINEAR, nullptr, nullptr,
+ nullptr));
+ }
+
+ qCDebug(qLcVideoFrameEncoder) << "VideoFrameEncoder conversions initialized:"
+ << "sourceFormat:" << m_sourceFormat
+ << (isHwPixelFormat(m_sourceFormat) ? "(hw)" : "(sw)")
+ << "targetFormat:" << m_targetFormat
+ << (isHwPixelFormat(m_targetFormat) ? "(hw)" : "(sw)")
+ << "sourceSWFormat:" << m_sourceSWFormat
+ << "targetSWFormat:" << m_targetSWFormat
+ << "converter:" << m_converter.get();
+}
+
+} // namespace QFFmpeg
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder_p.h
new file mode 100644
index 000000000..af57730f2
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder_p.h
@@ -0,0 +1,93 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QFFMPEGVIDEOFRAMEENCODER_P_H
+#define QFFMPEGVIDEOFRAMEENCODER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qffmpeghwaccel_p.h"
+#include "private/qplatformmediarecorder_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QMediaEncoderSettings;
+
+namespace QFFmpeg {
+
+class VideoFrameEncoder
+{
+public:
+ static std::unique_ptr<VideoFrameEncoder> create(const QMediaEncoderSettings &encoderSettings,
+ const QSize &sourceSize,
+ QtVideo::Rotation sourceRotation,
+ qreal sourceFrameRate,
+ AVPixelFormat sourceFormat,
+ AVPixelFormat sourceSWFormat,
+ AVFormatContext *formatContext);
+
+ ~VideoFrameEncoder();
+
+ bool open();
+
+ AVPixelFormat sourceFormat() const { return m_sourceFormat; }
+ AVPixelFormat targetFormat() const { return m_targetFormat; }
+
+ qint64 getPts(qint64 ms) const;
+
+ const AVRational &getTimeBase() const;
+
+ int sendFrame(AVFrameUPtr frame);
+ AVPacketUPtr retrievePacket();
+
+ const QMediaEncoderSettings &settings() { return m_settings; }
+
+private:
+ VideoFrameEncoder() = default;
+
+ bool updateSourceFormatAndSize(const AVFrame *frame);
+
+ void updateConversions();
+
+ bool initCodec();
+
+ bool initTargetFormats();
+
+ bool initCodecContext(AVFormatContext *formatContext);
+
+private:
+ QMediaEncoderSettings m_settings;
+ QSize m_sourceSize;
+ QtVideo::Rotation m_sourceRotation = QtVideo::Rotation::None;
+
+ std::unique_ptr<HWAccel> m_accel;
+ const AVCodec *m_codec = nullptr;
+ AVStream *m_stream = nullptr;
+ AVCodecContextUPtr m_codecContext;
+ std::unique_ptr<SwsContext, decltype(&sws_freeContext)> m_converter = { nullptr,
+ &sws_freeContext };
+ AVPixelFormat m_sourceFormat = AV_PIX_FMT_NONE;
+ AVPixelFormat m_sourceSWFormat = AV_PIX_FMT_NONE;
+ AVPixelFormat m_targetFormat = AV_PIX_FMT_NONE;
+ AVPixelFormat m_targetSWFormat = AV_PIX_FMT_NONE;
+ bool m_downloadFromHW = false;
+ bool m_uploadToHW = false;
+
+ AVRational m_codecFrameRate = { 0, 1 };
+
+ int64_t m_prevPacketDts = AV_NOPTS_VALUE;
+ int64_t m_packetDtsOffset = 0;
+};
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/ffmpeg/symbolstubs/openssl3.ver b/src/plugins/multimedia/ffmpeg/symbolstubs/openssl3.ver
new file mode 100644
index 000000000..88235a94c
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/symbolstubs/openssl3.ver
@@ -0,0 +1,7 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+OPENSSL_3.0.0 {
+ global:
+ *;
+};
diff --git a/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-crypto.cpp b/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-crypto.cpp
new file mode 100644
index 000000000..fbf3b783c
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-crypto.cpp
@@ -0,0 +1,6 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtMultimedia/private/qsymbolsresolveutils_p.h>
+
+// No stub functions are needed for ffmpeg
diff --git a/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-ssl.cpp b/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-ssl.cpp
new file mode 100644
index 000000000..3e38e398c
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-ssl.cpp
@@ -0,0 +1,300 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtMultimedia/private/qsymbolsresolveutils_p.h>
+
+#include <qstringliteral.h>
+
+#include <openssl/bio.h>
+#include <openssl/ssl.h>
+#include <openssl/bn.h>
+#include <openssl/err.h>
+#include <openssl/rand.h>
+
+using namespace Qt::StringLiterals;
+
+[[maybe_unused]] static constexpr auto SHLIB_VERSION =
+#if defined(OPENSSL_SHLIB_VERSION)
+ OPENSSL_SHLIB_VERSION;
+#elif defined(SHLIB_VERSION_NUMBER)
+ SHLIB_VERSION_NUMBER;
+#endif
+
+
+#if !defined(Q_OS_ANDROID)
+CHECK_VERSIONS("ssl", SSL_NEEDED_SOVERSION, SHLIB_VERSION);
+#endif
+
+static std::unique_ptr<QLibrary> loadLib()
+{
+ auto lib = std::make_unique<QLibrary>();
+
+ auto tryLoad = [&](QString sslName, auto version) {
+ lib->setFileNameAndVersion(sslName, version);
+ return lib->load();
+ };
+
+// openssl on Android has specific suffixes
+#if defined(Q_OS_ANDROID)
+ {
+ auto suffix = qEnvironmentVariable("ANDROID_OPENSSL_SUFFIX");
+ if (suffix.isEmpty()) {
+#if (OPENSSL_VERSION_NUMBER >> 28) < 3 // major version < 3
+ suffix = "_1_1"_L1;
+#elif OPENSSL_VERSION_MAJOR == 3
+ suffix = "_3"_L1;
+#else
+ static_assert(false, "Unexpected openssl version");
+#endif
+ }
+
+ if (tryLoad("ssl"_L1 + suffix, -1))
+ return lib;
+ }
+#endif
+
+ if (tryLoad("ssl"_L1, SSL_NEEDED_SOVERSION ""_L1))
+ return lib;
+
+ return {};
+};
+
+
+BEGIN_INIT_FUNCS("ssl", loadLib)
+
+// BN functions
+
+INIT_FUNC(BN_value_one);
+INIT_FUNC(BN_mod_word);
+
+INIT_FUNC(BN_div_word)
+INIT_FUNC(BN_mul_word)
+INIT_FUNC(BN_add_word)
+INIT_FUNC(BN_sub_word)
+INIT_FUNC(BN_set_word)
+INIT_FUNC(BN_new)
+INIT_FUNC(BN_cmp)
+
+INIT_FUNC(BN_free);
+
+INIT_FUNC(BN_copy);
+
+INIT_FUNC(BN_CTX_new);
+
+INIT_FUNC(BN_CTX_free);
+INIT_FUNC(BN_CTX_start);
+
+INIT_FUNC(BN_CTX_get);
+INIT_FUNC(BN_CTX_end);
+
+INIT_FUNC(BN_rand);
+INIT_FUNC(BN_mod_exp);
+
+INIT_FUNC(BN_num_bits);
+INIT_FUNC(BN_num_bits_word);
+
+INIT_FUNC(BN_bn2hex);
+INIT_FUNC(BN_bn2dec);
+
+INIT_FUNC(BN_hex2bn);
+INIT_FUNC(BN_dec2bn);
+INIT_FUNC(BN_asc2bn);
+
+INIT_FUNC(BN_bn2bin);
+INIT_FUNC(BN_bin2bn);
+
+// BIO-related functions
+
+INIT_FUNC(BIO_new);
+INIT_FUNC(BIO_free);
+
+INIT_FUNC(BIO_read);
+INIT_FUNC(BIO_write);
+INIT_FUNC(BIO_s_mem);
+
+INIT_FUNC(BIO_set_data);
+
+INIT_FUNC(BIO_get_data);
+INIT_FUNC(BIO_set_init);
+
+INIT_FUNC(BIO_set_flags);
+INIT_FUNC(BIO_test_flags);
+INIT_FUNC(BIO_clear_flags);
+
+INIT_FUNC(BIO_meth_new);
+INIT_FUNC(BIO_meth_free);
+
+INIT_FUNC(BIO_meth_set_write);
+INIT_FUNC(BIO_meth_set_read);
+INIT_FUNC(BIO_meth_set_puts);
+INIT_FUNC(BIO_meth_set_gets);
+INIT_FUNC(BIO_meth_set_ctrl);
+INIT_FUNC(BIO_meth_set_create);
+INIT_FUNC(BIO_meth_set_destroy);
+INIT_FUNC(BIO_meth_set_callback_ctrl);
+
+// SSL functions
+
+INIT_FUNC(SSL_CTX_new);
+INIT_FUNC(SSL_CTX_up_ref);
+INIT_FUNC(SSL_CTX_free);
+
+INIT_FUNC(SSL_new);
+INIT_FUNC(SSL_up_ref);
+INIT_FUNC(SSL_free);
+
+INIT_FUNC(SSL_accept);
+INIT_FUNC(SSL_stateless);
+INIT_FUNC(SSL_connect);
+INIT_FUNC(SSL_read);
+INIT_FUNC(SSL_peek);
+INIT_FUNC(SSL_write);
+INIT_FUNC(SSL_ctrl);
+INIT_FUNC(SSL_shutdown);
+INIT_FUNC(SSL_set_bio);
+
+// options are unsigned long in openssl 1.1.1, and uint64 in 3.x.x
+INIT_FUNC(SSL_CTX_set_options);
+
+INIT_FUNC(SSL_get_error);
+INIT_FUNC(SSL_CTX_load_verify_locations);
+
+INIT_FUNC(SSL_CTX_set_verify);
+INIT_FUNC(SSL_CTX_use_PrivateKey);
+
+INIT_FUNC(SSL_CTX_use_PrivateKey_file);
+INIT_FUNC(SSL_CTX_use_certificate_chain_file);
+
+INIT_FUNC(ERR_get_error);
+
+INIT_FUNC(ERR_error_string);
+
+// TLS functions
+
+INIT_FUNC(TLS_client_method);
+INIT_FUNC(TLS_server_method);
+
+// RAND functions
+
+INIT_FUNC(RAND_bytes);
+
+END_INIT_FUNCS()
+
+//////////// Define
+
+// BN functions
+
+DEFINE_FUNC(BN_value_one, 0);
+DEFINE_FUNC(BN_mod_word, 2);
+
+DEFINE_FUNC(BN_div_word, 2)
+DEFINE_FUNC(BN_mul_word, 2)
+DEFINE_FUNC(BN_add_word, 2)
+DEFINE_FUNC(BN_sub_word, 2)
+DEFINE_FUNC(BN_set_word, 2)
+DEFINE_FUNC(BN_new, 0)
+DEFINE_FUNC(BN_cmp, 2)
+
+DEFINE_FUNC(BN_free, 1);
+
+DEFINE_FUNC(BN_copy, 2);
+
+DEFINE_FUNC(BN_CTX_new, 0);
+
+DEFINE_FUNC(BN_CTX_free, 1);
+DEFINE_FUNC(BN_CTX_start, 1);
+
+DEFINE_FUNC(BN_CTX_get, 1);
+DEFINE_FUNC(BN_CTX_end, 1);
+
+DEFINE_FUNC(BN_rand, 4);
+DEFINE_FUNC(BN_mod_exp, 5);
+
+DEFINE_FUNC(BN_num_bits, 1);
+DEFINE_FUNC(BN_num_bits_word, 1);
+
+DEFINE_FUNC(BN_bn2hex, 1);
+DEFINE_FUNC(BN_bn2dec, 1);
+
+DEFINE_FUNC(BN_hex2bn, 2);
+DEFINE_FUNC(BN_dec2bn, 2);
+DEFINE_FUNC(BN_asc2bn, 2);
+
+DEFINE_FUNC(BN_bn2bin, 2);
+DEFINE_FUNC(BN_bin2bn, 3);
+
+// BIO-related functions
+
+DEFINE_FUNC(BIO_new, 1);
+DEFINE_FUNC(BIO_free, 1);
+
+DEFINE_FUNC(BIO_read, 3, -1);
+DEFINE_FUNC(BIO_write, 3, -1);
+DEFINE_FUNC(BIO_s_mem, 0);
+
+DEFINE_FUNC(BIO_set_data, 2);
+
+DEFINE_FUNC(BIO_get_data, 1);
+DEFINE_FUNC(BIO_set_init, 2);
+
+DEFINE_FUNC(BIO_set_flags, 2);
+DEFINE_FUNC(BIO_test_flags, 2);
+DEFINE_FUNC(BIO_clear_flags, 2);
+
+DEFINE_FUNC(BIO_meth_new, 2);
+DEFINE_FUNC(BIO_meth_free, 1);
+
+DEFINE_FUNC(BIO_meth_set_write, 2);
+DEFINE_FUNC(BIO_meth_set_read, 2);
+DEFINE_FUNC(BIO_meth_set_puts, 2);
+DEFINE_FUNC(BIO_meth_set_gets, 2);
+DEFINE_FUNC(BIO_meth_set_ctrl, 2);
+DEFINE_FUNC(BIO_meth_set_create, 2);
+DEFINE_FUNC(BIO_meth_set_destroy, 2);
+DEFINE_FUNC(BIO_meth_set_callback_ctrl, 2);
+
+// SSL functions
+
+DEFINE_FUNC(SSL_CTX_new, 1);
+DEFINE_FUNC(SSL_CTX_up_ref, 1);
+DEFINE_FUNC(SSL_CTX_free, 1);
+
+DEFINE_FUNC(SSL_new, 1);
+DEFINE_FUNC(SSL_up_ref, 1);
+DEFINE_FUNC(SSL_free, 1);
+
+DEFINE_FUNC(SSL_accept, 1);
+DEFINE_FUNC(SSL_stateless, 1);
+DEFINE_FUNC(SSL_connect, 1);
+DEFINE_FUNC(SSL_read, 3, -1);
+DEFINE_FUNC(SSL_peek, 3);
+DEFINE_FUNC(SSL_write, 3, -1);
+DEFINE_FUNC(SSL_ctrl, 4);
+DEFINE_FUNC(SSL_shutdown, 1);
+DEFINE_FUNC(SSL_set_bio, 3);
+
+// options are unsigned long in openssl 1.1.1, and uint64 in 3.x.x
+DEFINE_FUNC(SSL_CTX_set_options, 2);
+
+DEFINE_FUNC(SSL_get_error, 2);
+DEFINE_FUNC(SSL_CTX_load_verify_locations, 3, -1);
+
+DEFINE_FUNC(SSL_CTX_set_verify, 3);
+DEFINE_FUNC(SSL_CTX_use_PrivateKey, 2);
+
+DEFINE_FUNC(SSL_CTX_use_PrivateKey_file, 3);
+DEFINE_FUNC(SSL_CTX_use_certificate_chain_file, 2);
+
+DEFINE_FUNC(ERR_get_error, 0);
+
+static char ErrorString[] = "Ssl not found";
+DEFINE_FUNC(ERR_error_string, 2, ErrorString);
+
+// TLS functions
+
+DEFINE_FUNC(TLS_client_method, 0);
+DEFINE_FUNC(TLS_server_method, 0);
+
+// RAND functions
+
+DEFINE_FUNC(RAND_bytes, 2);
diff --git a/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va-drm.cpp b/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va-drm.cpp
new file mode 100644
index 000000000..655a6b2b6
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va-drm.cpp
@@ -0,0 +1,14 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtMultimedia/private/qsymbolsresolveutils_p.h>
+
+#include <va/va_drm.h>
+
+CHECK_VERSIONS("va-drm", VA_DRM_NEEDED_SOVERSION, VA_MAJOR_VERSION + 1);
+
+BEGIN_INIT_FUNCS("va-drm", VA_DRM_NEEDED_SOVERSION)
+INIT_FUNC(vaGetDisplayDRM)
+END_INIT_FUNCS()
+
+DEFINE_FUNC(vaGetDisplayDRM, 1);
diff --git a/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va-x11.cpp b/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va-x11.cpp
new file mode 100644
index 000000000..3bada9e69
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va-x11.cpp
@@ -0,0 +1,14 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtMultimedia/private/qsymbolsresolveutils_p.h>
+
+#include <va/va_x11.h>
+
+CHECK_VERSIONS("va-x11", VA_X11_NEEDED_SOVERSION, VA_MAJOR_VERSION + 1);
+
+BEGIN_INIT_FUNCS("va-x11", VA_X11_NEEDED_SOVERSION)
+INIT_FUNC(vaGetDisplay)
+END_INIT_FUNCS()
+
+DEFINE_FUNC(vaGetDisplay, 1);
diff --git a/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va.cpp b/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va.cpp
new file mode 100644
index 000000000..cfd2e5686
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/symbolstubs/qffmpegsymbols-va.cpp
@@ -0,0 +1,150 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtMultimedia/private/qsymbolsresolveutils_p.h>
+
+#include <va/va.h>
+#include <va/va_str.h>
+
+// VAAPI generated the actual *.so name due to the rule:
+// https://github.com/intel/libva/blob/master/configure.ac
+//
+// The library name is generated libva.<x>.<y>.0 where
+// <x> = VA-API major version + 1
+// <y> = 100 * VA-API minor version + VA-API micro version
+CHECK_VERSIONS("va", VA_NEEDED_SOVERSION, VA_MAJOR_VERSION + 1);
+
+#ifdef Q_FFMPEG_PLUGIN_STUBS_ONLY
+constexpr const char *loggingName = "va(in plugin)";
+#else
+constexpr const char *loggingName = nullptr;
+#endif
+
+BEGIN_INIT_FUNCS("va", VA_NEEDED_SOVERSION, loggingName)
+
+
+INIT_FUNC(vaExportSurfaceHandle);
+INIT_FUNC(vaSyncSurface);
+INIT_FUNC(vaQueryVendorString);
+
+#ifndef Q_FFMPEG_PLUGIN_STUBS_ONLY
+
+INIT_FUNC(vaInitialize);
+INIT_FUNC(vaTerminate);
+INIT_FUNC(vaErrorStr);
+INIT_FUNC(vaSetErrorCallback);
+INIT_FUNC(vaSetInfoCallback);
+
+INIT_FUNC(vaCreateImage);
+INIT_FUNC(vaGetImage);
+INIT_FUNC(vaPutImage);
+INIT_FUNC(vaDeriveImage);
+INIT_FUNC(vaDestroyImage);
+INIT_FUNC(vaQueryImageFormats);
+
+INIT_FUNC(vaBeginPicture);
+INIT_FUNC(vaRenderPicture);
+INIT_FUNC(vaEndPicture);
+
+INIT_FUNC(vaCreateBuffer);
+INIT_FUNC(vaMapBuffer);
+INIT_FUNC(vaUnmapBuffer);
+#if VA_CHECK_VERSION(1, 9, 0)
+INIT_FUNC(vaSyncBuffer);
+#endif
+INIT_FUNC(vaDestroyBuffer);
+
+INIT_FUNC(vaCreateSurfaces);
+INIT_FUNC(vaDestroySurfaces);
+
+INIT_FUNC(vaCreateConfig);
+INIT_FUNC(vaGetConfigAttributes);
+INIT_FUNC(vaMaxNumProfiles);
+INIT_FUNC(vaMaxNumImageFormats);
+INIT_FUNC(vaMaxNumEntrypoints);
+INIT_FUNC(vaQueryConfigProfiles);
+INIT_FUNC(vaQueryConfigEntrypoints);
+INIT_FUNC(vaQuerySurfaceAttributes);
+INIT_FUNC(vaDestroyConfig);
+
+INIT_FUNC(vaCreateContext);
+INIT_FUNC(vaDestroyContext);
+
+INIT_FUNC(vaProfileStr);
+INIT_FUNC(vaEntrypointStr);
+
+INIT_FUNC(vaGetDisplayAttributes);
+
+INIT_FUNC(vaSetDriverName);
+
+INIT_FUNC(vaAcquireBufferHandle);
+INIT_FUNC(vaReleaseBufferHandle);
+
+#endif
+
+END_INIT_FUNCS()
+
+constexpr auto emptyString = "";
+
+DEFINE_FUNC(vaExportSurfaceHandle, 5, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaSyncSurface, 2, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaQueryVendorString, 1, emptyString);
+
+#ifndef Q_FFMPEG_PLUGIN_STUBS_ONLY
+
+DEFINE_FUNC(vaInitialize, 3, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaTerminate, 1, VA_STATUS_ERROR_OPERATION_FAILED);
+
+constexpr auto errorStr = "VAAPI is not available";
+DEFINE_FUNC(vaErrorStr, 1, errorStr);
+DEFINE_FUNC(vaSetErrorCallback, 3);
+DEFINE_FUNC(vaSetInfoCallback, 3);
+
+DEFINE_FUNC(vaCreateImage, 5, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaGetImage, 7, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaPutImage, 11, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaDeriveImage, 3, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaDestroyImage, 2, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaQueryImageFormats, 3, VA_STATUS_ERROR_OPERATION_FAILED);
+
+DEFINE_FUNC(vaBeginPicture, 3, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaRenderPicture, 4, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaEndPicture, 2, VA_STATUS_ERROR_OPERATION_FAILED);
+
+DEFINE_FUNC(vaCreateBuffer, 7, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaMapBuffer, 3, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaUnmapBuffer, 2, VA_STATUS_ERROR_OPERATION_FAILED);
+#if VA_CHECK_VERSION(1, 9, 0)
+DEFINE_FUNC(vaSyncBuffer, 3, VA_STATUS_ERROR_OPERATION_FAILED);
+#endif
+DEFINE_FUNC(vaDestroyBuffer, 2, VA_STATUS_ERROR_OPERATION_FAILED);
+
+DEFINE_FUNC(vaCreateSurfaces, 8, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaDestroySurfaces, 3, VA_STATUS_ERROR_OPERATION_FAILED);
+
+DEFINE_FUNC(vaCreateConfig, 6, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaGetConfigAttributes, 5, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaMaxNumProfiles, 1);
+DEFINE_FUNC(vaMaxNumImageFormats, 1);
+DEFINE_FUNC(vaMaxNumEntrypoints, 1);
+DEFINE_FUNC(vaQueryConfigProfiles, 3, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaQueryConfigEntrypoints, 4, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaQuerySurfaceAttributes, 4, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaDestroyConfig, 2, VA_STATUS_ERROR_OPERATION_FAILED);
+
+DEFINE_FUNC(vaCreateContext, 8);
+DEFINE_FUNC(vaDestroyContext, 2);
+
+
+DEFINE_FUNC(vaProfileStr, 1, emptyString);
+DEFINE_FUNC(vaEntrypointStr, 1, emptyString);
+
+DEFINE_FUNC(vaGetDisplayAttributes, 3, VA_STATUS_ERROR_OPERATION_FAILED);
+
+DEFINE_FUNC(vaSetDriverName, 2, VA_STATUS_ERROR_OPERATION_FAILED);
+
+DEFINE_FUNC(vaAcquireBufferHandle, 3, VA_STATUS_ERROR_OPERATION_FAILED);
+DEFINE_FUNC(vaReleaseBufferHandle, 2, VA_STATUS_ERROR_OPERATION_FAILED);
+
+#endif
+
diff --git a/src/plugins/multimedia/ffmpeg/symbolstubs/va.ver b/src/plugins/multimedia/ffmpeg/symbolstubs/va.ver
new file mode 100644
index 000000000..80c9a6dc0
--- /dev/null
+++ b/src/plugins/multimedia/ffmpeg/symbolstubs/va.ver
@@ -0,0 +1,7 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+VA_API_0.33.0 {
+ global:
+ vaCreateSurfaces;
+};
diff --git a/src/plugins/multimedia/gstreamer/CMakeLists.txt b/src/plugins/multimedia/gstreamer/CMakeLists.txt
new file mode 100644
index 000000000..1ef1f9a36
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/CMakeLists.txt
@@ -0,0 +1,73 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_find_package(EGL)
+
+qt_internal_add_module(QGstreamerMediaPluginPrivate
+ STATIC
+ INTERNAL_MODULE
+ SOURCES
+ audio/qgstreameraudiodevice.cpp audio/qgstreameraudiodevice_p.h
+ audio/qgstreameraudiodecoder.cpp audio/qgstreameraudiodecoder_p.h
+ common/qglist_helper_p.h
+ common/qgst.cpp common/qgst_p.h
+ common/qgst_debug.cpp common/qgst_debug_p.h
+ common/qgst_handle_types_p.h
+ common/qgstappsource.cpp common/qgstappsource_p.h
+ common/qgstreameraudioinput.cpp common/qgstreameraudioinput_p.h
+ common/qgstreameraudiooutput.cpp common/qgstreameraudiooutput_p.h
+ common/qgstreamerbufferprobe.cpp common/qgstreamerbufferprobe_p.h
+ common/qgstreamermetadata.cpp common/qgstreamermetadata_p.h
+ common/qgstreamermessage_p.h
+ common/qgstreamermediaplayer.cpp common/qgstreamermediaplayer_p.h
+ common/qgstreamervideooutput.cpp common/qgstreamervideooutput_p.h
+ common/qgstreamervideooverlay.cpp common/qgstreamervideooverlay_p.h
+ common/qgstreamervideosink.cpp common/qgstreamervideosink_p.h
+ common/qgstpipeline.cpp common/qgstpipeline_p.h
+ common/qgstutils.cpp common/qgstutils_p.h
+ common/qgstvideobuffer.cpp common/qgstvideobuffer_p.h
+ common/qgstvideorenderersink.cpp common/qgstvideorenderersink_p.h
+ common/qgstsubtitlesink.cpp common/qgstsubtitlesink_p.h
+ qgstreamerintegration.cpp qgstreamerintegration_p.h
+ qgstreamerformatinfo.cpp qgstreamerformatinfo_p.h
+ qgstreamervideodevices.cpp qgstreamervideodevices_p.h
+ mediacapture/qgstreamercamera.cpp mediacapture/qgstreamercamera_p.h
+ mediacapture/qgstreamerimagecapture.cpp mediacapture/qgstreamerimagecapture_p.h
+ mediacapture/qgstreamermediacapture.cpp mediacapture/qgstreamermediacapture_p.h
+ mediacapture/qgstreamermediaencoder.cpp mediacapture/qgstreamermediaencoder_p.h
+ NO_UNITY_BUILD_SOURCES
+ # Conflicts with macros defined in X11.h, and Xlib.h
+ common/qgstvideobuffer.cpp
+ common/qgstreamervideosink.cpp
+ NO_GENERATE_CPP_EXPORTS
+ DEFINES
+ GLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_26
+ PUBLIC_LIBRARIES
+ Qt::MultimediaPrivate
+ Qt::CorePrivate
+ GStreamer::GStreamer
+ GStreamer::App
+)
+
+qt_internal_extend_target(QGstreamerMediaPluginPrivate CONDITION QT_FEATURE_gstreamer_photography
+ PUBLIC_LIBRARIES
+ GStreamer::Photography
+)
+
+qt_internal_extend_target(QGstreamerMediaPluginPrivate CONDITION QT_FEATURE_gstreamer_gl
+ PUBLIC_LIBRARIES
+ GStreamer::Gl
+ LIBRARIES
+ EGL::EGL
+)
+
+qt_internal_add_plugin(QGstreamerMediaPlugin
+ OUTPUT_NAME gstreamermediaplugin
+ PLUGIN_TYPE multimedia
+ SOURCES
+ qgstreamerplugin.cpp
+ gstreamer.json
+ LIBRARIES
+ Qt::QGstreamerMediaPluginPrivate
+ Qt::MultimediaPrivate
+)
diff --git a/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodecoder.cpp b/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodecoder.cpp
new file mode 100644
index 000000000..513ab8dae
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodecoder.cpp
@@ -0,0 +1,533 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+//#define DEBUG_DECODER
+
+#include <audio/qgstreameraudiodecoder_p.h>
+
+#include <common/qgstreamermessage_p.h>
+#include <common/qgst_debug_p.h>
+#include <common/qgstutils_p.h>
+
+#include <gst/gstvalue.h>
+#include <gst/base/gstbasesrc.h>
+
+#include <QtCore/qdatetime.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qsize.h>
+#include <QtCore/qtimer.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qdir.h>
+#include <QtCore/qstandardpaths.h>
+#include <QtCore/qurl.h>
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcGstreamerAudioDecoder, "qt.multimedia.gstreameraudiodecoder");
+
+typedef enum {
+ GST_PLAY_FLAG_VIDEO = 0x00000001,
+ GST_PLAY_FLAG_AUDIO = 0x00000002,
+ GST_PLAY_FLAG_TEXT = 0x00000004,
+ GST_PLAY_FLAG_VIS = 0x00000008,
+ GST_PLAY_FLAG_SOFT_VOLUME = 0x00000010,
+ GST_PLAY_FLAG_NATIVE_AUDIO = 0x00000020,
+ GST_PLAY_FLAG_NATIVE_VIDEO = 0x00000040,
+ GST_PLAY_FLAG_DOWNLOAD = 0x00000080,
+ GST_PLAY_FLAG_BUFFERING = 0x000000100
+} GstPlayFlags;
+
+
+QMaybe<QPlatformAudioDecoder *> QGstreamerAudioDecoder::create(QAudioDecoder *parent)
+{
+ static const auto error = qGstErrorMessageIfElementsNotAvailable("audioconvert", "playbin");
+ if (error)
+ return *error;
+
+ return new QGstreamerAudioDecoder(parent);
+}
+
+QGstreamerAudioDecoder::QGstreamerAudioDecoder(QAudioDecoder *parent)
+ : QPlatformAudioDecoder(parent),
+ m_playbin{
+ QGstPipeline::adopt(GST_PIPELINE_CAST(
+ QGstElement::createFromFactory("playbin", "playbin").element())),
+ },
+ m_audioConvert{
+ QGstElement::createFromFactory("audioconvert", "audioconvert"),
+ }
+{
+ // Sort out messages
+ m_playbin.installMessageFilter(this);
+
+ // Set the rest of the pipeline up
+ setAudioFlags(true);
+
+ m_outputBin = QGstBin::create("audio-output-bin");
+ m_outputBin.add(m_audioConvert);
+
+ // add ghostpad
+ m_outputBin.addGhostPad(m_audioConvert, "sink");
+
+ g_object_set(m_playbin.object(), "audio-sink", m_outputBin.element(), NULL);
+
+ m_deepNotifySourceConnection = m_playbin.connect(
+ "deep-notify::source", (GCallback)&configureAppSrcElement, (gpointer)this);
+
+ // Set volume to 100%
+ gdouble volume = 1.0;
+ m_playbin.set("volume", volume);
+}
+
+QGstreamerAudioDecoder::~QGstreamerAudioDecoder()
+{
+ stop();
+
+ m_playbin.removeMessageFilter(this);
+
+#if QT_CONFIG(gstreamer_app)
+ delete m_appSrc;
+#endif
+}
+
+#if QT_CONFIG(gstreamer_app)
+void QGstreamerAudioDecoder::configureAppSrcElement([[maybe_unused]] GObject *object, GObject *orig,
+ [[maybe_unused]] GParamSpec *pspec,
+ QGstreamerAudioDecoder *self)
+{
+ // In case we switch from appsrc to not
+ if (!self->m_appSrc)
+ return;
+
+ QGstElementHandle appsrc;
+ g_object_get(orig, "source", &appsrc, NULL);
+
+ auto *qAppSrc = self->m_appSrc;
+ qAppSrc->setExternalAppSrc(QGstAppSrc{
+ qGstSafeCast<GstAppSrc>(appsrc.get()),
+ QGstAppSrc::NeedsRef, // CHECK: can we `release()`?
+ });
+ qAppSrc->setup(self->mDevice);
+}
+#endif
+
+bool QGstreamerAudioDecoder::processBusMessage(const QGstreamerMessage &message)
+{
+ qCDebug(qLcGstreamerAudioDecoder) << "received bus message:" << message;
+
+ GstMessage *gm = message.message();
+
+ switch (message.type()) {
+ case GST_MESSAGE_DURATION: {
+ updateDuration();
+ return false;
+ }
+
+ case GST_MESSAGE_ERROR: {
+ qCDebug(qLcGstreamerAudioDecoder) << " error" << QCompactGstMessageAdaptor(message);
+
+ QUniqueGErrorHandle err;
+ QGString debug;
+ gst_message_parse_error(gm, &err, &debug);
+
+ if (message.source() == m_playbin) {
+ if (err.get()->domain == GST_STREAM_ERROR
+ && err.get()->code == GST_STREAM_ERROR_CODEC_NOT_FOUND)
+ processInvalidMedia(QAudioDecoder::FormatError,
+ tr("Cannot play stream of type: <unknown>"));
+ else
+ processInvalidMedia(QAudioDecoder::ResourceError,
+ QString::fromUtf8(err.get()->message));
+ } else {
+ QAudioDecoder::Error qerror = QAudioDecoder::ResourceError;
+ if (err.get()->domain == GST_STREAM_ERROR) {
+ switch (err.get()->code) {
+ case GST_STREAM_ERROR_DECRYPT:
+ case GST_STREAM_ERROR_DECRYPT_NOKEY:
+ qerror = QAudioDecoder::AccessDeniedError;
+ break;
+ case GST_STREAM_ERROR_FORMAT:
+ case GST_STREAM_ERROR_DEMUX:
+ case GST_STREAM_ERROR_DECODE:
+ case GST_STREAM_ERROR_WRONG_TYPE:
+ case GST_STREAM_ERROR_TYPE_NOT_FOUND:
+ case GST_STREAM_ERROR_CODEC_NOT_FOUND:
+ qerror = QAudioDecoder::FormatError;
+ break;
+ default:
+ break;
+ }
+ } else if (err.get()->domain == GST_CORE_ERROR) {
+ switch (err.get()->code) {
+ case GST_CORE_ERROR_MISSING_PLUGIN:
+ qerror = QAudioDecoder::FormatError;
+ break;
+ default:
+ break;
+ }
+ }
+
+ processInvalidMedia(qerror, QString::fromUtf8(err.get()->message));
+ }
+ break;
+ }
+
+ default:
+ if (message.source() == m_playbin)
+ return handlePlaybinMessage(message);
+ }
+
+ return false;
+}
+
+bool QGstreamerAudioDecoder::handlePlaybinMessage(const QGstreamerMessage &message)
+{
+ GstMessage *gm = message.message();
+
+ switch (GST_MESSAGE_TYPE(gm)) {
+ case GST_MESSAGE_STATE_CHANGED: {
+ GstState oldState;
+ GstState newState;
+ GstState pending;
+
+ gst_message_parse_state_changed(gm, &oldState, &newState, &pending);
+
+ bool isDecoding = false;
+ switch (newState) {
+ case GST_STATE_VOID_PENDING:
+ case GST_STATE_NULL:
+ case GST_STATE_READY:
+ break;
+ case GST_STATE_PLAYING:
+ isDecoding = true;
+ break;
+ case GST_STATE_PAUSED:
+ isDecoding = true;
+
+ // gstreamer doesn't give a reliable indication the duration
+ // information is ready, GST_MESSAGE_DURATION is not sent by most elements
+ // the duration is queried up to 5 times with increasing delay
+ m_durationQueries = 5;
+ updateDuration();
+ break;
+ }
+
+ setIsDecoding(isDecoding);
+ break;
+ };
+
+ case GST_MESSAGE_EOS:
+ m_playbin.setState(GST_STATE_NULL);
+ finished();
+ break;
+
+ case GST_MESSAGE_ERROR:
+ Q_UNREACHABLE_RETURN(false); // handled in processBusMessage
+
+ case GST_MESSAGE_WARNING:
+ qCWarning(qLcGstreamerAudioDecoder) << "Warning:" << QCompactGstMessageAdaptor(message);
+ break;
+
+ case GST_MESSAGE_INFO: {
+ if (qLcGstreamerAudioDecoder().isDebugEnabled())
+ qCWarning(qLcGstreamerAudioDecoder) << "Info:" << QCompactGstMessageAdaptor(message);
+ break;
+ }
+ default:
+ break;
+ }
+
+ return false;
+}
+
+QUrl QGstreamerAudioDecoder::source() const
+{
+ return mSource;
+}
+
+void QGstreamerAudioDecoder::setSource(const QUrl &fileName)
+{
+ stop();
+ mDevice = nullptr;
+ delete m_appSrc;
+ m_appSrc = nullptr;
+
+ bool isSignalRequired = (mSource != fileName);
+ mSource = fileName;
+ if (isSignalRequired)
+ sourceChanged();
+}
+
+QIODevice *QGstreamerAudioDecoder::sourceDevice() const
+{
+ return mDevice;
+}
+
+void QGstreamerAudioDecoder::setSourceDevice(QIODevice *device)
+{
+ stop();
+ mSource.clear();
+ bool isSignalRequired = (mDevice != device);
+ mDevice = device;
+ if (isSignalRequired)
+ sourceChanged();
+}
+
+void QGstreamerAudioDecoder::start()
+{
+ addAppSink();
+
+ if (!mSource.isEmpty()) {
+ m_playbin.set("uri", mSource.toEncoded().constData());
+ } else if (mDevice) {
+ // make sure we can read from device
+ if (!mDevice->isOpen() || !mDevice->isReadable()) {
+ processInvalidMedia(QAudioDecoder::ResourceError, QLatin1String("Unable to read from specified device"));
+ return;
+ }
+
+ if (!m_appSrc) {
+ auto maybeAppSrc = QGstAppSource::create(this);
+ if (maybeAppSrc) {
+ m_appSrc = maybeAppSrc.value();
+ } else {
+ processInvalidMedia(QAudioDecoder::ResourceError, maybeAppSrc.error());
+ return;
+ }
+ }
+
+ m_playbin.set("uri", "appsrc://");
+ } else {
+ return;
+ }
+
+ // Set audio format
+ if (m_appSink) {
+ if (mFormat.isValid()) {
+ setAudioFlags(false);
+ auto caps = QGstUtils::capsForAudioFormat(mFormat);
+ m_appSink.setCaps(caps);
+ } else {
+ // We want whatever the native audio format is
+ setAudioFlags(true);
+ m_appSink.setCaps({});
+ }
+ }
+
+ if (m_playbin.setState(GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
+ qWarning() << "GStreamer; Unable to start decoding process";
+ m_playbin.dumpGraph("failed");
+ return;
+ }
+}
+
+void QGstreamerAudioDecoder::stop()
+{
+ m_playbin.setState(GST_STATE_NULL);
+ m_currentSessionId += 1;
+ removeAppSink();
+
+ // GStreamer thread is stopped. Can safely access m_buffersAvailable
+ if (m_buffersAvailable != 0) {
+ m_buffersAvailable = 0;
+ bufferAvailableChanged(false);
+ }
+
+ if (m_position != invalidPosition) {
+ m_position = invalidPosition;
+ positionChanged(m_position.count());
+ }
+
+ if (m_duration != invalidDuration) {
+ m_duration = invalidDuration;
+ durationChanged(m_duration.count());
+ }
+
+ setIsDecoding(false);
+}
+
+QAudioFormat QGstreamerAudioDecoder::audioFormat() const
+{
+ return mFormat;
+}
+
+void QGstreamerAudioDecoder::setAudioFormat(const QAudioFormat &format)
+{
+ if (mFormat != format) {
+ mFormat = format;
+ formatChanged(mFormat);
+ }
+}
+
+QAudioBuffer QGstreamerAudioDecoder::read()
+{
+ using namespace std::chrono;
+
+ QAudioBuffer audioBuffer;
+
+ if (m_buffersAvailable == 0)
+ return audioBuffer;
+
+ m_buffersAvailable -= 1;
+
+ if (m_buffersAvailable == 0)
+ bufferAvailableChanged(false);
+
+ QGstSampleHandle sample = m_appSink.pullSample();
+ GstBuffer *buffer = gst_sample_get_buffer(sample.get());
+ GstMapInfo mapInfo;
+ gst_buffer_map(buffer, &mapInfo, GST_MAP_READ);
+ const char *bufferData = (const char *)mapInfo.data;
+ int bufferSize = mapInfo.size;
+ QAudioFormat format = QGstUtils::audioFormatForSample(sample.get());
+
+ if (format.isValid()) {
+ // XXX At the moment we have to copy data from GstBuffer into QAudioBuffer.
+ // We could improve performance by implementing QAbstractAudioBuffer for GstBuffer.
+ nanoseconds position = getPositionFromBuffer(buffer);
+ audioBuffer = QAudioBuffer{
+ QByteArray(bufferData, bufferSize),
+ format,
+ round<microseconds>(position).count(),
+ };
+ milliseconds positionInMs = round<milliseconds>(position);
+ if (position != m_position) {
+ m_position = positionInMs;
+ positionChanged(m_position.count());
+ }
+ }
+ gst_buffer_unmap(buffer, &mapInfo);
+
+ return audioBuffer;
+}
+
+qint64 QGstreamerAudioDecoder::position() const
+{
+ return m_position.count();
+}
+
+qint64 QGstreamerAudioDecoder::duration() const
+{
+ return m_duration.count();
+}
+
+void QGstreamerAudioDecoder::processInvalidMedia(QAudioDecoder::Error errorCode, const QString& errorString)
+{
+ stop();
+ error(int(errorCode), errorString);
+}
+
+GstFlowReturn QGstreamerAudioDecoder::newSample(GstAppSink *)
+{
+ // "Note that the preroll buffer will also be returned as the first buffer when calling
+ // gst_app_sink_pull_buffer()."
+
+ QMetaObject::invokeMethod(this, [this, sessionId = m_currentSessionId] {
+ if (sessionId != m_currentSessionId)
+ return; // stop()ed before message is executed
+
+ m_buffersAvailable += 1;
+ bufferAvailableChanged(true);
+ bufferReady();
+ });
+
+ return GST_FLOW_OK;
+}
+
+GstFlowReturn QGstreamerAudioDecoder::new_sample(GstAppSink *sink, gpointer user_data)
+{
+ QGstreamerAudioDecoder *decoder = reinterpret_cast<QGstreamerAudioDecoder *>(user_data);
+ qCDebug(qLcGstreamerAudioDecoder) << "QGstreamerAudioDecoder::new_sample";
+ return decoder->newSample(sink);
+}
+
+void QGstreamerAudioDecoder::setAudioFlags(bool wantNativeAudio)
+{
+ int flags = m_playbin.getInt("flags");
+ // make sure not to use GST_PLAY_FLAG_NATIVE_AUDIO unless desired
+ // it prevents audio format conversion
+ flags &= ~(GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_TEXT | GST_PLAY_FLAG_VIS | GST_PLAY_FLAG_NATIVE_AUDIO);
+ flags |= GST_PLAY_FLAG_AUDIO;
+ if (wantNativeAudio)
+ flags |= GST_PLAY_FLAG_NATIVE_AUDIO;
+ m_playbin.set("flags", flags);
+}
+
+void QGstreamerAudioDecoder::addAppSink()
+{
+ using namespace std::chrono_literals;
+
+ if (m_appSink)
+ return;
+
+ qCDebug(qLcGstreamerAudioDecoder) << "QGstreamerAudioDecoder::addAppSink";
+ m_appSink = QGstAppSink::create("decoderAppSink");
+ GstAppSinkCallbacks callbacks{};
+ callbacks.new_sample = new_sample;
+ m_appSink.setCallbacks(callbacks, this, nullptr);
+
+#if GST_CHECK_VERSION(1, 24, 0)
+ static constexpr auto maxBufferTime = 500ms;
+ m_appSink.setMaxBufferTime(maxBufferTime);
+#else
+ static constexpr int maxBuffers = 16;
+ m_appSink.setMaxBuffers(maxBuffers);
+#endif
+
+ static constexpr bool sync = false;
+ m_appSink.setSync(sync);
+
+ QGstPipeline::modifyPipelineWhileNotRunning(m_playbin.getPipeline(), [&] {
+ m_outputBin.add(m_appSink);
+ qLinkGstElements(m_audioConvert, m_appSink);
+ });
+}
+
+void QGstreamerAudioDecoder::removeAppSink()
+{
+ if (!m_appSink)
+ return;
+
+ qCDebug(qLcGstreamerAudioDecoder) << "QGstreamerAudioDecoder::removeAppSink";
+
+ QGstPipeline::modifyPipelineWhileNotRunning(m_playbin.getPipeline(), [&] {
+ qUnlinkGstElements(m_audioConvert, m_appSink);
+ m_outputBin.stopAndRemoveElements(m_appSink);
+ });
+ m_appSink = {};
+}
+
+void QGstreamerAudioDecoder::updateDuration()
+{
+ std::chrono::milliseconds duration = m_playbin.durationInMs();
+
+ if (m_duration != duration) {
+ m_duration = duration;
+ durationChanged(m_duration.count());
+ }
+
+ if (m_duration.count() > 0)
+ m_durationQueries = 0;
+
+ if (m_durationQueries > 0) {
+ //increase delay between duration requests
+ int delay = 25 << (5 - m_durationQueries);
+ QTimer::singleShot(delay, this, &QGstreamerAudioDecoder::updateDuration);
+ m_durationQueries--;
+ }
+}
+
+std::chrono::nanoseconds QGstreamerAudioDecoder::getPositionFromBuffer(GstBuffer *buffer)
+{
+ using namespace std::chrono;
+ using namespace std::chrono_literals;
+ nanoseconds position{ GST_BUFFER_TIMESTAMP(buffer) };
+ if (position >= 0ns)
+ return position;
+ else
+ return invalidPosition;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qgstreameraudiodecoder_p.cpp"
diff --git a/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodecoder_p.h b/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodecoder_p.h
new file mode 100644
index 000000000..a5e192a38
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodecoder_p.h
@@ -0,0 +1,116 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERAUDIODECODERCONTROL_H
+#define QGSTREAMERAUDIODECODERCONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/private/qmultimediautils_p.h>
+#include <QtMultimedia/private/qplatformaudiodecoder_p.h>
+#include <QtMultimedia/private/qtmultimediaglobal_p.h>
+#include <QtMultimedia/qaudiodecoder.h>
+#include <QtCore/qobject.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qurl.h>
+
+#include <common/qgstpipeline_p.h>
+#include <common/qgst_p.h>
+
+#if QT_CONFIG(gstreamer_app)
+# include <common/qgstappsource_p.h>
+#endif
+
+#include <gst/app/gstappsink.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerMessage;
+
+class QGstreamerAudioDecoder final : public QPlatformAudioDecoder, public QGstreamerBusMessageFilter
+{
+ Q_OBJECT
+
+public:
+ static QMaybe<QPlatformAudioDecoder *> create(QAudioDecoder *parent);
+ virtual ~QGstreamerAudioDecoder();
+
+ QUrl source() const override;
+ void setSource(const QUrl &fileName) override;
+
+ QIODevice *sourceDevice() const override;
+ void setSourceDevice(QIODevice *device) override;
+
+ void start() override;
+ void stop() override;
+
+ QAudioFormat audioFormat() const override;
+ void setAudioFormat(const QAudioFormat &format) override;
+
+ QAudioBuffer read() override;
+
+ qint64 position() const override;
+ qint64 duration() const override;
+
+ // GStreamerBusMessageFilter interface
+ bool processBusMessage(const QGstreamerMessage &message) override;
+
+private slots:
+ void updateDuration();
+
+private:
+ explicit QGstreamerAudioDecoder(QAudioDecoder *parent);
+
+#if QT_CONFIG(gstreamer_app)
+ static GstFlowReturn new_sample(GstAppSink *sink, gpointer user_data);
+ GstFlowReturn newSample(GstAppSink *sink);
+
+ static void configureAppSrcElement(GObject *, GObject *, GParamSpec *,
+ QGstreamerAudioDecoder *_this);
+#endif
+
+ void setAudioFlags(bool wantNativeAudio);
+ void addAppSink();
+ void removeAppSink();
+
+ bool handlePlaybinMessage(const QGstreamerMessage &);
+
+ void processInvalidMedia(QAudioDecoder::Error errorCode, const QString &errorString);
+ static std::chrono::nanoseconds getPositionFromBuffer(GstBuffer *buffer);
+
+ QGstPipeline m_playbin;
+ QGstBin m_outputBin;
+ QGstElement m_audioConvert;
+ QGstAppSink m_appSink;
+ QGstAppSource *m_appSrc = nullptr;
+
+ QUrl mSource;
+ QIODevice *mDevice = nullptr;
+ QAudioFormat mFormat;
+
+ int m_buffersAvailable = 0;
+
+ static constexpr auto invalidDuration = std::chrono::milliseconds{ -1 };
+ static constexpr auto invalidPosition = std::chrono::milliseconds{ -1 };
+ std::chrono::milliseconds m_position{ invalidPosition };
+ std::chrono::milliseconds m_duration{ invalidDuration };
+
+ int m_durationQueries = 0;
+
+ qint32 m_currentSessionId{};
+
+ QGObjectHandlerScopedConnection m_deepNotifySourceConnection;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGSTREAMERPLAYERSESSION_H
diff --git a/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodevice.cpp b/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodevice.cpp
new file mode 100644
index 000000000..dc6975030
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodevice.cpp
@@ -0,0 +1,77 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qgstreameraudiodevice_p.h"
+
+#include <common/qgst_p.h>
+#include <common/qgstutils_p.h>
+#include <private/qplatformmediaintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QGStreamerAudioDeviceInfo::QGStreamerAudioDeviceInfo(GstDevice *d, const QByteArray &device,
+ QAudioDevice::Mode mode)
+ : QAudioDevicePrivate(device, mode),
+ gstDevice{
+ d,
+ QGstDeviceHandle::NeedsRef,
+ }
+{
+ QGString name{
+ gst_device_get_display_name(gstDevice.get()),
+ };
+ description = name.toQString();
+
+ auto caps = QGstCaps(gst_device_get_caps(gstDevice.get()), QGstCaps::HasRef);
+ int size = caps.size();
+ for (int i = 0; i < size; ++i) {
+ auto c = caps.at(i);
+ if (c.name() == "audio/x-raw") {
+ auto rate = c["rate"].toIntRange();
+ if (rate) {
+ minimumSampleRate = rate->min;
+ maximumSampleRate = rate->max;
+ }
+ auto channels = c["channels"].toIntRange();
+ if (channels) {
+ minimumChannelCount = channels->min;
+ maximumChannelCount = channels->max;
+ }
+ supportedSampleFormats = c["format"].getSampleFormats();
+ }
+ }
+
+ preferredFormat.setChannelCount(qBound(minimumChannelCount, 2, maximumChannelCount));
+ preferredFormat.setSampleRate(qBound(minimumSampleRate, 48000, maximumSampleRate));
+ QAudioFormat::SampleFormat f = QAudioFormat::Int16;
+ if (!supportedSampleFormats.contains(f))
+ f = supportedSampleFormats.value(0, QAudioFormat::Unknown);
+ preferredFormat.setSampleFormat(f);
+}
+
+QGStreamerCustomAudioDeviceInfo::QGStreamerCustomAudioDeviceInfo(
+ const QByteArray &gstreamerPipeline, QAudioDevice::Mode mode)
+ : QAudioDevicePrivate{
+ gstreamerPipeline,
+ mode,
+ }
+{
+}
+
+QAudioDevice qMakeCustomGStreamerAudioInput(const QByteArray &gstreamerPipeline)
+{
+ auto deviceInfo = std::make_unique<QGStreamerCustomAudioDeviceInfo>(gstreamerPipeline,
+ QAudioDevice::Mode::Input);
+
+ return deviceInfo.release()->create();
+}
+
+QAudioDevice qMakeCustomGStreamerAudioOutput(const QByteArray &gstreamerPipeline)
+{
+ auto deviceInfo = std::make_unique<QGStreamerCustomAudioDeviceInfo>(gstreamerPipeline,
+ QAudioDevice::Mode::Output);
+
+ return deviceInfo.release()->create();
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodevice_p.h b/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodevice_p.h
new file mode 100644
index 000000000..34d25bceb
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodevice_p.h
@@ -0,0 +1,52 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERAUDIODEVICEINFO_H
+#define QGSTREAMERAUDIODEVICEINFO_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qbytearray.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qlist.h>
+
+#include <QtMultimedia/qaudio.h>
+#include <QtMultimedia/qaudiodevice.h>
+#include <QtMultimedia/private/qaudiodevice_p.h>
+
+#include <QtQGstreamerMediaPlugin/private/qgst_handle_types_p.h>
+
+#include <gst/gst.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGStreamerAudioDeviceInfo : public QAudioDevicePrivate
+{
+public:
+ QGStreamerAudioDeviceInfo(GstDevice *gstDevice, const QByteArray &device, QAudioDevice::Mode mode);
+
+ QGstDeviceHandle gstDevice;
+};
+
+class QGStreamerCustomAudioDeviceInfo : public QAudioDevicePrivate
+{
+public:
+ QGStreamerCustomAudioDeviceInfo(const QByteArray &gstreamerPipeline, QAudioDevice::Mode mode);
+};
+
+QAudioDevice qMakeCustomGStreamerAudioInput(const QByteArray &gstreamerPipeline);
+QAudioDevice qMakeCustomGStreamerAudioOutput(const QByteArray &gstreamerPipeline);
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/plugins/multimedia/gstreamer/common/qglist_helper_p.h b/src/plugins/multimedia/gstreamer/common/qglist_helper_p.h
new file mode 100644
index 000000000..54108e1c3
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qglist_helper_p.h
@@ -0,0 +1,82 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGLIST_HELPER_P_H
+#define QGLIST_HELPER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qtconfigmacros.h>
+
+#include <glib.h>
+#include <iterator>
+
+QT_BEGIN_NAMESPACE
+
+namespace QGstUtils {
+
+template <typename ListType>
+struct GListIterator
+{
+ explicit GListIterator(const GList *element = nullptr) : element(element) { }
+
+ const ListType &operator*() const noexcept { return *operator->(); }
+ const ListType *operator->() const noexcept
+ {
+ return reinterpret_cast<const ListType *>(&element->data);
+ }
+
+ GListIterator &operator++() noexcept
+ {
+ if (element)
+ element = element->next;
+
+ return *this;
+ }
+ GListIterator operator++(int n) noexcept
+ {
+ for (int i = 0; i != n; ++i)
+ operator++();
+
+ return *this;
+ }
+
+ bool operator==(const GListIterator &r) const noexcept { return element == r.element; }
+ bool operator!=(const GListIterator &r) const noexcept { return element != r.element; }
+
+ using difference_type = std::ptrdiff_t;
+ using value_type = ListType;
+ using pointer = value_type *;
+ using reference = value_type &;
+ using iterator_category = std::input_iterator_tag;
+
+ const GList *element = nullptr;
+};
+
+template <typename ListType>
+struct GListRangeAdaptor
+{
+ static_assert(std::is_pointer_v<ListType>);
+
+ explicit GListRangeAdaptor(const GList *list) : head(list) { }
+
+ auto begin() { return GListIterator<ListType>(head); }
+ auto end() { return GListIterator<ListType>(nullptr); }
+
+ const GList *head;
+};
+
+} // namespace QGstUtils
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgst.cpp b/src/plugins/multimedia/gstreamer/common/qgst.cpp
new file mode 100644
index 000000000..4050ea06f
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgst.cpp
@@ -0,0 +1,1339 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <common/qgst_p.h>
+#include <common/qgst_debug_p.h>
+#include <common/qgstpipeline_p.h>
+#include <common/qgstreamermessage_p.h>
+
+#include <QtCore/qdebug.h>
+#include <QtMultimedia/qcameradevice.h>
+
+#include <array>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+
+struct VideoFormat
+{
+ QVideoFrameFormat::PixelFormat pixelFormat;
+ GstVideoFormat gstFormat;
+};
+
+constexpr std::array<VideoFormat, 19> qt_videoFormatLookup{ {
+ { QVideoFrameFormat::Format_YUV420P, GST_VIDEO_FORMAT_I420 },
+ { QVideoFrameFormat::Format_YUV422P, GST_VIDEO_FORMAT_Y42B },
+ { QVideoFrameFormat::Format_YV12, GST_VIDEO_FORMAT_YV12 },
+ { QVideoFrameFormat::Format_UYVY, GST_VIDEO_FORMAT_UYVY },
+ { QVideoFrameFormat::Format_YUYV, GST_VIDEO_FORMAT_YUY2 },
+ { QVideoFrameFormat::Format_NV12, GST_VIDEO_FORMAT_NV12 },
+ { QVideoFrameFormat::Format_NV21, GST_VIDEO_FORMAT_NV21 },
+ { QVideoFrameFormat::Format_AYUV, GST_VIDEO_FORMAT_AYUV },
+ { QVideoFrameFormat::Format_Y8, GST_VIDEO_FORMAT_GRAY8 },
+ { QVideoFrameFormat::Format_XRGB8888, GST_VIDEO_FORMAT_xRGB },
+ { QVideoFrameFormat::Format_XBGR8888, GST_VIDEO_FORMAT_xBGR },
+ { QVideoFrameFormat::Format_RGBX8888, GST_VIDEO_FORMAT_RGBx },
+ { QVideoFrameFormat::Format_BGRX8888, GST_VIDEO_FORMAT_BGRx },
+ { QVideoFrameFormat::Format_ARGB8888, GST_VIDEO_FORMAT_ARGB },
+ { QVideoFrameFormat::Format_ABGR8888, GST_VIDEO_FORMAT_ABGR },
+ { QVideoFrameFormat::Format_RGBA8888, GST_VIDEO_FORMAT_RGBA },
+ { QVideoFrameFormat::Format_BGRA8888, GST_VIDEO_FORMAT_BGRA },
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ { QVideoFrameFormat::Format_Y16, GST_VIDEO_FORMAT_GRAY16_LE },
+ { QVideoFrameFormat::Format_P010, GST_VIDEO_FORMAT_P010_10LE },
+#else
+ { QVideoFrameFormat::Format_Y16, GST_VIDEO_FORMAT_GRAY16_BE },
+ { QVideoFrameFormat::Format_P010, GST_VIDEO_FORMAT_P010_10BE },
+#endif
+} };
+
+int indexOfVideoFormat(QVideoFrameFormat::PixelFormat format)
+{
+ for (size_t i = 0; i < qt_videoFormatLookup.size(); ++i)
+ if (qt_videoFormatLookup[i].pixelFormat == format)
+ return int(i);
+
+ return -1;
+}
+
+int indexOfVideoFormat(GstVideoFormat format)
+{
+ for (size_t i = 0; i < qt_videoFormatLookup.size(); ++i)
+ if (qt_videoFormatLookup[i].gstFormat == format)
+ return int(i);
+
+ return -1;
+}
+
+} // namespace
+
+// QGValue
+
+QGValue::QGValue(const GValue *v) : value(v) { }
+
+bool QGValue::isNull() const
+{
+ return !value;
+}
+
+std::optional<bool> QGValue::toBool() const
+{
+ if (!G_VALUE_HOLDS_BOOLEAN(value))
+ return std::nullopt;
+ return g_value_get_boolean(value);
+}
+
+std::optional<int> QGValue::toInt() const
+{
+ if (!G_VALUE_HOLDS_INT(value))
+ return std::nullopt;
+ return g_value_get_int(value);
+}
+
+std::optional<int> QGValue::toInt64() const
+{
+ if (!G_VALUE_HOLDS_INT64(value))
+ return std::nullopt;
+ return g_value_get_int64(value);
+}
+
+const char *QGValue::toString() const
+{
+ return value ? g_value_get_string(value) : nullptr;
+}
+
+std::optional<float> QGValue::getFraction() const
+{
+ if (!GST_VALUE_HOLDS_FRACTION(value))
+ return std::nullopt;
+ return (float)gst_value_get_fraction_numerator(value)
+ / (float)gst_value_get_fraction_denominator(value);
+}
+
+std::optional<QGRange<float>> QGValue::getFractionRange() const
+{
+ if (!GST_VALUE_HOLDS_FRACTION_RANGE(value))
+ return std::nullopt;
+ QGValue min = QGValue{ gst_value_get_fraction_range_min(value) };
+ QGValue max = QGValue{ gst_value_get_fraction_range_max(value) };
+ return QGRange<float>{ *min.getFraction(), *max.getFraction() };
+}
+
+std::optional<QGRange<int>> QGValue::toIntRange() const
+{
+ if (!GST_VALUE_HOLDS_INT_RANGE(value))
+ return std::nullopt;
+ return QGRange<int>{ gst_value_get_int_range_min(value), gst_value_get_int_range_max(value) };
+}
+
+QGstStructureView QGValue::toStructure() const
+{
+ if (!value || !GST_VALUE_HOLDS_STRUCTURE(value))
+ return QGstStructureView(nullptr);
+ return QGstStructureView(gst_value_get_structure(value));
+}
+
+QGstCaps QGValue::toCaps() const
+{
+ if (!value || !GST_VALUE_HOLDS_CAPS(value))
+ return {};
+ return QGstCaps(gst_caps_copy(gst_value_get_caps(value)), QGstCaps::HasRef);
+}
+
+bool QGValue::isList() const
+{
+ return value && GST_VALUE_HOLDS_LIST(value);
+}
+
+int QGValue::listSize() const
+{
+ return gst_value_list_get_size(value);
+}
+
+QGValue QGValue::at(int index) const
+{
+ return QGValue{ gst_value_list_get_value(value, index) };
+}
+
+// QGstStructureView
+
+QGstStructureView::QGstStructureView(const GstStructure *s) : structure(s) { }
+
+QGstStructureView::QGstStructureView(const QUniqueGstStructureHandle &handle)
+ : QGstStructureView{ handle.get() }
+{
+}
+
+QUniqueGstStructureHandle QGstStructureView::clone() const
+{
+ return QUniqueGstStructureHandle{ gst_structure_copy(structure) };
+}
+
+bool QGstStructureView::isNull() const
+{
+ return !structure;
+}
+
+QByteArrayView QGstStructureView::name() const
+{
+ return gst_structure_get_name(structure);
+}
+
+QGValue QGstStructureView::operator[](const char *fieldname) const
+{
+ return QGValue{ gst_structure_get_value(structure, fieldname) };
+}
+
+QGstCaps QGstStructureView::caps() const
+{
+ return operator[]("caps").toCaps();
+}
+
+QGstTagListHandle QGstStructureView::tags() const
+{
+ QGValue tags = operator[]("tags");
+ if (tags.isNull())
+ return {};
+
+ QGstTagListHandle tagList;
+ gst_structure_get(structure, "tags", GST_TYPE_TAG_LIST, &tagList, nullptr);
+ return tagList;
+}
+
+QSize QGstStructureView::resolution() const
+{
+ QSize size;
+
+ int w, h;
+ if (structure && gst_structure_get_int(structure, "width", &w)
+ && gst_structure_get_int(structure, "height", &h)) {
+ size.rwidth() = w;
+ size.rheight() = h;
+ }
+
+ return size;
+}
+
+QVideoFrameFormat::PixelFormat QGstStructureView::pixelFormat() const
+{
+ QVideoFrameFormat::PixelFormat pixelFormat = QVideoFrameFormat::Format_Invalid;
+
+ if (!structure)
+ return pixelFormat;
+
+ if (gst_structure_has_name(structure, "video/x-raw")) {
+ const gchar *s = gst_structure_get_string(structure, "format");
+ if (s) {
+ GstVideoFormat format = gst_video_format_from_string(s);
+ int index = indexOfVideoFormat(format);
+
+ if (index != -1)
+ pixelFormat = qt_videoFormatLookup[index].pixelFormat;
+ }
+ } else if (gst_structure_has_name(structure, "image/jpeg")) {
+ pixelFormat = QVideoFrameFormat::Format_Jpeg;
+ }
+
+ return pixelFormat;
+}
+
+QGRange<float> QGstStructureView::frameRateRange() const
+{
+ float minRate = 0.;
+ float maxRate = 0.;
+
+ if (!structure)
+ return { 0.f, 0.f };
+
+ auto extractFraction = [](const GValue *v) -> float {
+ return (float)gst_value_get_fraction_numerator(v)
+ / (float)gst_value_get_fraction_denominator(v);
+ };
+ auto extractFrameRate = [&](const GValue *v) {
+ auto insert = [&](float min, float max) {
+ if (max > maxRate)
+ maxRate = max;
+ if (min < minRate)
+ minRate = min;
+ };
+
+ if (GST_VALUE_HOLDS_FRACTION(v)) {
+ float rate = extractFraction(v);
+ insert(rate, rate);
+ } else if (GST_VALUE_HOLDS_FRACTION_RANGE(v)) {
+ auto *min = gst_value_get_fraction_range_max(v);
+ auto *max = gst_value_get_fraction_range_max(v);
+ insert(extractFraction(min), extractFraction(max));
+ }
+ };
+
+ const GValue *gstFrameRates = gst_structure_get_value(structure, "framerate");
+ if (gstFrameRates) {
+ if (GST_VALUE_HOLDS_LIST(gstFrameRates)) {
+ guint nFrameRates = gst_value_list_get_size(gstFrameRates);
+ for (guint f = 0; f < nFrameRates; ++f) {
+ extractFrameRate(gst_value_list_get_value(gstFrameRates, f));
+ }
+ } else {
+ extractFrameRate(gstFrameRates);
+ }
+ } else {
+ const GValue *min = gst_structure_get_value(structure, "min-framerate");
+ const GValue *max = gst_structure_get_value(structure, "max-framerate");
+ if (min && max) {
+ minRate = extractFraction(min);
+ maxRate = extractFraction(max);
+ }
+ }
+
+ return { minRate, maxRate };
+}
+
+QGstreamerMessage QGstStructureView::getMessage()
+{
+ GstMessage *message = nullptr;
+ gst_structure_get(structure, "message", GST_TYPE_MESSAGE, &message, nullptr);
+ return QGstreamerMessage(message, QGstreamerMessage::HasRef);
+}
+
+std::optional<Fraction> QGstStructureView::pixelAspectRatio() const
+{
+ gint numerator;
+ gint denominator;
+ if (gst_structure_get_fraction(structure, "pixel-aspect-ratio", &numerator, &denominator)) {
+ return Fraction{
+ numerator,
+ denominator,
+ };
+ }
+
+ return std::nullopt;
+}
+
+// QTBUG-125249: gstreamer tries "to keep the input height (because of interlacing)". Can we align
+// the behavior between gstreamer and ffmpeg?
+static QSize qCalculateFrameSizeGStreamer(QSize resolution, Fraction par)
+{
+ if (par.numerator == par.denominator || par.numerator < 1 || par.denominator < 1)
+ return resolution;
+
+ return QSize{
+ resolution.width() * par.numerator / par.denominator,
+ resolution.height(),
+ };
+}
+
+QSize QGstStructureView::nativeSize() const
+{
+ QSize size = resolution();
+ if (!size.isValid()) {
+ qWarning() << Q_FUNC_INFO << "invalid resolution when querying nativeSize";
+ return size;
+ }
+
+ std::optional<Fraction> par = pixelAspectRatio();
+ if (par)
+ size = qCalculateFrameSizeGStreamer(size, *par);
+ return size;
+}
+
+// QGstCaps
+
+std::optional<std::pair<QVideoFrameFormat, GstVideoInfo>> QGstCaps::formatAndVideoInfo() const
+{
+ GstVideoInfo vidInfo;
+
+ bool success = gst_video_info_from_caps(&vidInfo, get());
+ if (!success)
+ return std::nullopt;
+
+ int index = indexOfVideoFormat(vidInfo.finfo->format);
+ if (index == -1)
+ return std::nullopt;
+
+ QVideoFrameFormat format(QSize(vidInfo.width, vidInfo.height),
+ qt_videoFormatLookup[index].pixelFormat);
+
+ if (vidInfo.fps_d > 0)
+ format.setStreamFrameRate(qreal(vidInfo.fps_n) / vidInfo.fps_d);
+
+ QVideoFrameFormat::ColorRange range = QVideoFrameFormat::ColorRange_Unknown;
+ switch (vidInfo.colorimetry.range) {
+ case GST_VIDEO_COLOR_RANGE_UNKNOWN:
+ break;
+ case GST_VIDEO_COLOR_RANGE_0_255:
+ range = QVideoFrameFormat::ColorRange_Full;
+ break;
+ case GST_VIDEO_COLOR_RANGE_16_235:
+ range = QVideoFrameFormat::ColorRange_Video;
+ break;
+ }
+ format.setColorRange(range);
+
+ QVideoFrameFormat::ColorSpace colorSpace = QVideoFrameFormat::ColorSpace_Undefined;
+ switch (vidInfo.colorimetry.matrix) {
+ case GST_VIDEO_COLOR_MATRIX_UNKNOWN:
+ case GST_VIDEO_COLOR_MATRIX_RGB:
+ case GST_VIDEO_COLOR_MATRIX_FCC:
+ break;
+ case GST_VIDEO_COLOR_MATRIX_BT709:
+ colorSpace = QVideoFrameFormat::ColorSpace_BT709;
+ break;
+ case GST_VIDEO_COLOR_MATRIX_BT601:
+ colorSpace = QVideoFrameFormat::ColorSpace_BT601;
+ break;
+ case GST_VIDEO_COLOR_MATRIX_SMPTE240M:
+ colorSpace = QVideoFrameFormat::ColorSpace_AdobeRgb;
+ break;
+ case GST_VIDEO_COLOR_MATRIX_BT2020:
+ colorSpace = QVideoFrameFormat::ColorSpace_BT2020;
+ break;
+ }
+ format.setColorSpace(colorSpace);
+
+ QVideoFrameFormat::ColorTransfer transfer = QVideoFrameFormat::ColorTransfer_Unknown;
+ switch (vidInfo.colorimetry.transfer) {
+ case GST_VIDEO_TRANSFER_UNKNOWN:
+ break;
+ case GST_VIDEO_TRANSFER_GAMMA10:
+ transfer = QVideoFrameFormat::ColorTransfer_Linear;
+ break;
+ case GST_VIDEO_TRANSFER_GAMMA22:
+ case GST_VIDEO_TRANSFER_SMPTE240M:
+ case GST_VIDEO_TRANSFER_SRGB:
+ case GST_VIDEO_TRANSFER_ADOBERGB:
+ transfer = QVideoFrameFormat::ColorTransfer_Gamma22;
+ break;
+ case GST_VIDEO_TRANSFER_GAMMA18:
+ case GST_VIDEO_TRANSFER_GAMMA20:
+ // not quite, but best fit
+ case GST_VIDEO_TRANSFER_BT709:
+ case GST_VIDEO_TRANSFER_BT2020_12:
+ transfer = QVideoFrameFormat::ColorTransfer_BT709;
+ break;
+ case GST_VIDEO_TRANSFER_GAMMA28:
+ transfer = QVideoFrameFormat::ColorTransfer_Gamma28;
+ break;
+ case GST_VIDEO_TRANSFER_LOG100:
+ case GST_VIDEO_TRANSFER_LOG316:
+ break;
+#if GST_CHECK_VERSION(1, 18, 0)
+ case GST_VIDEO_TRANSFER_SMPTE2084:
+ transfer = QVideoFrameFormat::ColorTransfer_ST2084;
+ break;
+ case GST_VIDEO_TRANSFER_ARIB_STD_B67:
+ transfer = QVideoFrameFormat::ColorTransfer_STD_B67;
+ break;
+ case GST_VIDEO_TRANSFER_BT2020_10:
+ transfer = QVideoFrameFormat::ColorTransfer_BT709;
+ break;
+ case GST_VIDEO_TRANSFER_BT601:
+ transfer = QVideoFrameFormat::ColorTransfer_BT601;
+ break;
+#endif
+ }
+ format.setColorTransfer(transfer);
+
+ return std::pair{
+ std::move(format),
+ vidInfo,
+ };
+}
+
+void QGstCaps::addPixelFormats(const QList<QVideoFrameFormat::PixelFormat> &formats,
+ const char *modifier)
+{
+ if (!gst_caps_is_writable(get()))
+ *this = QGstCaps(gst_caps_make_writable(release()), QGstCaps::RefMode::HasRef);
+
+ GValue list = {};
+ g_value_init(&list, GST_TYPE_LIST);
+
+ for (QVideoFrameFormat::PixelFormat format : formats) {
+ int index = indexOfVideoFormat(format);
+ if (index == -1)
+ continue;
+ GValue item = {};
+
+ g_value_init(&item, G_TYPE_STRING);
+ g_value_set_string(&item,
+ gst_video_format_to_string(qt_videoFormatLookup[index].gstFormat));
+ gst_value_list_append_value(&list, &item);
+ g_value_unset(&item);
+ }
+
+ auto *structure = gst_structure_new("video/x-raw", "framerate", GST_TYPE_FRACTION_RANGE, 0, 1,
+ INT_MAX, 1, "width", GST_TYPE_INT_RANGE, 1, INT_MAX,
+ "height", GST_TYPE_INT_RANGE, 1, INT_MAX, nullptr);
+ gst_structure_set_value(structure, "format", &list);
+ gst_caps_append_structure(get(), structure);
+ g_value_unset(&list);
+
+ if (modifier)
+ gst_caps_set_features(get(), size() - 1, gst_caps_features_from_string(modifier));
+}
+
+void QGstCaps::setResolution(QSize resolution)
+{
+ Q_ASSERT(resolution.isValid());
+ GValue width{};
+ g_value_init(&width, G_TYPE_INT);
+ g_value_set_int(&width, resolution.width());
+ GValue height{};
+ g_value_init(&height, G_TYPE_INT);
+ g_value_set_int(&height, resolution.height());
+
+ gst_caps_set_value(caps(), "width", &width);
+ gst_caps_set_value(caps(), "height", &height);
+}
+
+QGstCaps QGstCaps::fromCameraFormat(const QCameraFormat &format)
+{
+ QSize size = format.resolution();
+ GstStructure *structure = nullptr;
+ if (format.pixelFormat() == QVideoFrameFormat::Format_Jpeg) {
+ structure = gst_structure_new("image/jpeg", "width", G_TYPE_INT, size.width(), "height",
+ G_TYPE_INT, size.height(), nullptr);
+ } else {
+ int index = indexOfVideoFormat(format.pixelFormat());
+ if (index < 0)
+ return {};
+ auto gstFormat = qt_videoFormatLookup[index].gstFormat;
+ structure = gst_structure_new("video/x-raw", "format", G_TYPE_STRING,
+ gst_video_format_to_string(gstFormat), "width", G_TYPE_INT,
+ size.width(), "height", G_TYPE_INT, size.height(), nullptr);
+ }
+ auto caps = QGstCaps::create();
+ gst_caps_append_structure(caps.get(), structure);
+ return caps;
+}
+
+QGstCaps QGstCaps::copy() const
+{
+ return QGstCaps{
+ gst_caps_copy(caps()),
+ QGstCaps::HasRef,
+ };
+}
+
+QGstCaps::MemoryFormat QGstCaps::memoryFormat() const
+{
+ auto *features = gst_caps_get_features(get(), 0);
+ if (gst_caps_features_contains(features, "memory:GLMemory"))
+ return GLTexture;
+ if (gst_caps_features_contains(features, "memory:DMABuf"))
+ return DMABuf;
+ return CpuMemory;
+}
+
+int QGstCaps::size() const
+{
+ return int(gst_caps_get_size(get()));
+}
+
+QGstStructureView QGstCaps::at(int index) const
+{
+ return QGstStructureView{
+ gst_caps_get_structure(get(), index),
+ };
+}
+
+GstCaps *QGstCaps::caps() const
+{
+ return get();
+}
+
+QGstCaps QGstCaps::create()
+{
+ return QGstCaps(gst_caps_new_empty(), HasRef);
+}
+
+// QGstObject
+
+void QGstObject::set(const char *property, const char *str)
+{
+ g_object_set(get(), property, str, nullptr);
+}
+
+void QGstObject::set(const char *property, bool b)
+{
+ g_object_set(get(), property, gboolean(b), nullptr);
+}
+
+void QGstObject::set(const char *property, uint i)
+{
+ g_object_set(get(), property, guint(i), nullptr);
+}
+
+void QGstObject::set(const char *property, int i)
+{
+ g_object_set(get(), property, gint(i), nullptr);
+}
+
+void QGstObject::set(const char *property, qint64 i)
+{
+ g_object_set(get(), property, gint64(i), nullptr);
+}
+
+void QGstObject::set(const char *property, quint64 i)
+{
+ g_object_set(get(), property, guint64(i), nullptr);
+}
+
+void QGstObject::set(const char *property, double d)
+{
+ g_object_set(get(), property, gdouble(d), nullptr);
+}
+
+void QGstObject::set(const char *property, const QGstObject &o)
+{
+ g_object_set(get(), property, o.object(), nullptr);
+}
+
+void QGstObject::set(const char *property, const QGstCaps &c)
+{
+ g_object_set(get(), property, c.caps(), nullptr);
+}
+
+QGString QGstObject::getString(const char *property) const
+{
+ char *s = nullptr;
+ g_object_get(get(), property, &s, nullptr);
+ return QGString(s);
+}
+
+QGstStructureView QGstObject::getStructure(const char *property) const
+{
+ GstStructure *s = nullptr;
+ g_object_get(get(), property, &s, nullptr);
+ return QGstStructureView(s);
+}
+
+bool QGstObject::getBool(const char *property) const
+{
+ gboolean b = false;
+ g_object_get(get(), property, &b, nullptr);
+ return b;
+}
+
+uint QGstObject::getUInt(const char *property) const
+{
+ guint i = 0;
+ g_object_get(get(), property, &i, nullptr);
+ return i;
+}
+
+int QGstObject::getInt(const char *property) const
+{
+ gint i = 0;
+ g_object_get(get(), property, &i, nullptr);
+ return i;
+}
+
+quint64 QGstObject::getUInt64(const char *property) const
+{
+ guint64 i = 0;
+ g_object_get(get(), property, &i, nullptr);
+ return i;
+}
+
+qint64 QGstObject::getInt64(const char *property) const
+{
+ gint64 i = 0;
+ g_object_get(get(), property, &i, nullptr);
+ return i;
+}
+
+float QGstObject::getFloat(const char *property) const
+{
+ gfloat d = 0;
+ g_object_get(get(), property, &d, nullptr);
+ return d;
+}
+
+double QGstObject::getDouble(const char *property) const
+{
+ gdouble d = 0;
+ g_object_get(get(), property, &d, nullptr);
+ return d;
+}
+
+QGstObject QGstObject::getObject(const char *property) const
+{
+ GstObject *o = nullptr;
+ g_object_get(get(), property, &o, nullptr);
+ return QGstObject(o, HasRef);
+}
+
+QGObjectHandlerConnection QGstObject::connect(const char *name, GCallback callback,
+ gpointer userData)
+{
+ return QGObjectHandlerConnection{
+ *this,
+ g_signal_connect(get(), name, callback, userData),
+ };
+}
+
+void QGstObject::disconnect(gulong handlerId)
+{
+ g_signal_handler_disconnect(get(), handlerId);
+}
+
+GType QGstObject::type() const
+{
+ return G_OBJECT_TYPE(get());
+}
+
+QLatin1StringView QGstObject::typeName() const
+{
+ return QLatin1StringView{
+ g_type_name(type()),
+ };
+}
+
+GstObject *QGstObject::object() const
+{
+ return get();
+}
+
+QLatin1StringView QGstObject::name() const
+{
+ using namespace Qt::StringLiterals;
+
+ return get() ? QLatin1StringView{ GST_OBJECT_NAME(get()) } : "(null)"_L1;
+}
+
+// QGObjectHandlerConnection
+
+QGObjectHandlerConnection::QGObjectHandlerConnection(QGstObject object, gulong handlerId)
+ : object{ std::move(object) }, handlerId{ handlerId }
+{
+}
+
+void QGObjectHandlerConnection::disconnect()
+{
+ if (!object)
+ return;
+
+ object.disconnect(handlerId);
+ object = {};
+ handlerId = invalidHandlerId;
+}
+
+// QGObjectHandlerScopedConnection
+
+QGObjectHandlerScopedConnection::QGObjectHandlerScopedConnection(
+ QGObjectHandlerConnection connection)
+ : connection{
+ std::move(connection),
+ }
+{
+}
+
+QGObjectHandlerScopedConnection::~QGObjectHandlerScopedConnection()
+{
+ connection.disconnect();
+}
+
+void QGObjectHandlerScopedConnection::disconnect()
+{
+ connection.disconnect();
+}
+
+// QGstPad
+
+QGstPad::QGstPad(const QGstObject &o)
+ : QGstPad{
+ qGstSafeCast<GstPad>(o.object()),
+ QGstElement::NeedsRef,
+ }
+{
+}
+
+QGstPad::QGstPad(GstPad *pad, RefMode mode)
+ : QGstObject{
+ qGstCheckedCast<GstObject>(pad),
+ mode,
+ }
+{
+}
+
+QGstCaps QGstPad::currentCaps() const
+{
+ return QGstCaps(gst_pad_get_current_caps(pad()), QGstCaps::HasRef);
+}
+
+QGstCaps QGstPad::queryCaps() const
+{
+ return QGstCaps(gst_pad_query_caps(pad(), nullptr), QGstCaps::HasRef);
+}
+
+QGstTagListHandle QGstPad::tags() const
+{
+ QGstTagListHandle tagList;
+ g_object_get(object(), "tags", &tagList, nullptr);
+ return tagList;
+}
+
+std::optional<QPlatformMediaPlayer::TrackType> QGstPad::inferTrackTypeFromName() const
+{
+ using namespace Qt::Literals;
+ QLatin1StringView padName = name();
+
+ if (padName.startsWith("video_"_L1))
+ return QPlatformMediaPlayer::TrackType::VideoStream;
+ if (padName.startsWith("audio_"_L1))
+ return QPlatformMediaPlayer::TrackType::AudioStream;
+ if (padName.startsWith("text_"_L1))
+ return QPlatformMediaPlayer::TrackType::SubtitleStream;
+
+ return std::nullopt;
+}
+
+bool QGstPad::isLinked() const
+{
+ return gst_pad_is_linked(pad());
+}
+
+bool QGstPad::link(const QGstPad &sink) const
+{
+ return gst_pad_link(pad(), sink.pad()) == GST_PAD_LINK_OK;
+}
+
+bool QGstPad::unlink(const QGstPad &sink) const
+{
+ return gst_pad_unlink(pad(), sink.pad());
+}
+
+bool QGstPad::unlinkPeer() const
+{
+ return unlink(peer());
+}
+
+QGstPad QGstPad::peer() const
+{
+ return QGstPad(gst_pad_get_peer(pad()), HasRef);
+}
+
+QGstElement QGstPad::parent() const
+{
+ return QGstElement(gst_pad_get_parent_element(pad()), HasRef);
+}
+
+GstPad *QGstPad::pad() const
+{
+ return qGstCheckedCast<GstPad>(object());
+}
+
+GstEvent *QGstPad::stickyEvent(GstEventType type)
+{
+ return gst_pad_get_sticky_event(pad(), type, 0);
+}
+
+bool QGstPad::sendEvent(GstEvent *event)
+{
+ return gst_pad_send_event(pad(), event);
+}
+
+// QGstClock
+
+QGstClock::QGstClock(const QGstObject &o)
+ : QGstClock{
+ qGstSafeCast<GstClock>(o.object()),
+ QGstElement::NeedsRef,
+ }
+{
+}
+
+QGstClock::QGstClock(GstClock *clock, RefMode mode)
+ : QGstObject{
+ qGstCheckedCast<GstObject>(clock),
+ mode,
+ }
+{
+}
+
+GstClock *QGstClock::clock() const
+{
+ return qGstCheckedCast<GstClock>(object());
+}
+
+GstClockTime QGstClock::time() const
+{
+ return gst_clock_get_time(clock());
+}
+
+// QGstElement
+
+QGstElement::QGstElement(GstElement *element, RefMode mode)
+ : QGstObject{
+ qGstCheckedCast<GstObject>(element),
+ mode,
+ }
+{
+}
+
+QGstElement QGstElement::createFromFactory(const char *factory, const char *name)
+{
+ GstElement *element = gst_element_factory_make(factory, name);
+
+#ifndef QT_NO_DEBUG
+ if (!element) {
+ qWarning() << "Failed to make element" << name << "from factory" << factory;
+ return QGstElement{};
+ }
+#endif
+
+ return QGstElement{
+ element,
+ NeedsRef,
+ };
+}
+
+QGstElement QGstElement::createFromFactory(GstElementFactory *factory, const char *name)
+{
+ return QGstElement{
+ gst_element_factory_create(factory, name),
+ NeedsRef,
+ };
+}
+
+QGstElement QGstElement::createFromFactory(const QGstElementFactoryHandle &factory,
+ const char *name)
+{
+ return createFromFactory(factory.get(), name);
+}
+
+QGstElement QGstElement::createFromDevice(const QGstDeviceHandle &device, const char *name)
+{
+ return createFromDevice(device.get(), name);
+}
+
+QGstElement QGstElement::createFromDevice(GstDevice *device, const char *name)
+{
+ return QGstElement{
+ gst_device_create_element(device, name),
+ QGstElement::NeedsRef,
+ };
+}
+
+QGstElement QGstElement::createFromPipelineDescription(const char *str)
+{
+ QUniqueGErrorHandle error;
+ QGstElement element{
+ gst_parse_launch(str, &error),
+ QGstElement::NeedsRef,
+ };
+
+ if (error) // error does not mean that the element could not be constructed
+ qWarning() << "gst_parse_launch error:" << error;
+
+ return element;
+}
+
+QGstElement QGstElement::createFromPipelineDescription(const QByteArray &str)
+{
+ return createFromPipelineDescription(str.constData());
+}
+
+QGstElementFactoryHandle QGstElement::findFactory(const char *name)
+{
+ return QGstElementFactoryHandle{
+ gst_element_factory_find(name),
+ QGstElementFactoryHandle::HasRef,
+ };
+}
+
+QGstElementFactoryHandle QGstElement::findFactory(const QByteArray &name)
+{
+ return findFactory(name.constData());
+}
+
+QGstPad QGstElement::staticPad(const char *name) const
+{
+ return QGstPad(gst_element_get_static_pad(element(), name), HasRef);
+}
+
+QGstPad QGstElement::src() const
+{
+ return staticPad("src");
+}
+
+QGstPad QGstElement::sink() const
+{
+ return staticPad("sink");
+}
+
+QGstPad QGstElement::getRequestPad(const char *name) const
+{
+#if GST_CHECK_VERSION(1, 19, 1)
+ return QGstPad(gst_element_request_pad_simple(element(), name), HasRef);
+#else
+ return QGstPad(gst_element_get_request_pad(element(), name), HasRef);
+#endif
+}
+
+void QGstElement::releaseRequestPad(const QGstPad &pad) const
+{
+ return gst_element_release_request_pad(element(), pad.pad());
+}
+
+GstState QGstElement::state(std::chrono::nanoseconds timeout) const
+{
+ using namespace std::chrono_literals;
+
+ GstState state;
+ GstStateChangeReturn change =
+ gst_element_get_state(element(), &state, nullptr, timeout.count());
+
+ if (Q_UNLIKELY(change == GST_STATE_CHANGE_ASYNC))
+ qWarning() << "QGstElement::state detected an asynchronous state change. Return value not "
+ "reliable";
+
+ return state;
+}
+
+GstStateChangeReturn QGstElement::setState(GstState state)
+{
+ return gst_element_set_state(element(), state);
+}
+
+bool QGstElement::setStateSync(GstState state, std::chrono::nanoseconds timeout)
+{
+ if (state == GST_STATE_NULL) {
+ // QTBUG-125251: when changing pipeline state too quickly between NULL->PAUSED->NULL there
+ // may be a pending task to activate pads while we try to switch to NULL. This can cause an
+ // assertion failure in gstreamer. we therefore finish the state change when called on a bin
+ // or pipeline.
+ if (qIsGstObjectOfType<GstBin>(element()))
+ finishStateChange();
+ }
+
+ GstStateChangeReturn change = gst_element_set_state(element(), state);
+ if (change == GST_STATE_CHANGE_ASYNC)
+ change = gst_element_get_state(element(), nullptr, &state, timeout.count());
+
+ if (change != GST_STATE_CHANGE_SUCCESS && change != GST_STATE_CHANGE_NO_PREROLL) {
+ qWarning() << "Could not change state of" << name() << "to" << state << change;
+ dumpPipelineGraph("setStatSyncFailure");
+ }
+ return change == GST_STATE_CHANGE_SUCCESS;
+}
+
+bool QGstElement::syncStateWithParent()
+{
+ Q_ASSERT(element());
+ return gst_element_sync_state_with_parent(element()) == TRUE;
+}
+
+bool QGstElement::finishStateChange(std::chrono::nanoseconds timeout)
+{
+ GstState state, pending;
+ GstStateChangeReturn change =
+ gst_element_get_state(element(), &state, &pending, timeout.count());
+
+ if (change != GST_STATE_CHANGE_SUCCESS && change != GST_STATE_CHANGE_NO_PREROLL) {
+ qWarning() << "Could not finish change state of" << name() << change << state << pending;
+ dumpPipelineGraph("finishStateChangeFailure");
+ }
+ return change == GST_STATE_CHANGE_SUCCESS;
+}
+
+void QGstElement::lockState(bool locked)
+{
+ gst_element_set_locked_state(element(), locked);
+}
+
+bool QGstElement::isStateLocked() const
+{
+ return gst_element_is_locked_state(element());
+}
+
+void QGstElement::sendEvent(GstEvent *event) const
+{
+ gst_element_send_event(element(), event);
+}
+
+void QGstElement::sendEos() const
+{
+ sendEvent(gst_event_new_eos());
+}
+
+GstClockTime QGstElement::baseTime() const
+{
+ return gst_element_get_base_time(element());
+}
+
+void QGstElement::setBaseTime(GstClockTime time) const
+{
+ gst_element_set_base_time(element(), time);
+}
+
+GstElement *QGstElement::element() const
+{
+ return GST_ELEMENT_CAST(get());
+}
+
+QGstElement QGstElement::getParent() const
+{
+ return QGstElement{
+ qGstCheckedCast<GstElement>(gst_element_get_parent(object())),
+ QGstElement::HasRef,
+ };
+}
+
+QGstPipeline QGstElement::getPipeline() const
+{
+ QGstElement ancestor = *this;
+ for (;;) {
+ QGstElement greatAncestor = ancestor.getParent();
+ if (greatAncestor) {
+ ancestor = std::move(greatAncestor);
+ continue;
+ }
+
+ return QGstPipeline{
+ qGstSafeCast<GstPipeline>(ancestor.element()),
+ QGstPipeline::NeedsRef,
+ };
+ }
+}
+
+void QGstElement::dumpPipelineGraph(const char *filename) const
+{
+ static const bool dumpEnabled = qEnvironmentVariableIsSet("GST_DEBUG_DUMP_DOT_DIR");
+ if (dumpEnabled) {
+ QGstPipeline pipeline = getPipeline();
+ if (pipeline)
+ pipeline.dumpGraph(filename);
+ }
+}
+
+// QGstBin
+
+QGstBin QGstBin::create(const char *name)
+{
+ return QGstBin(gst_bin_new(name), NeedsRef);
+}
+
+QGstBin QGstBin::createFromFactory(const char *factory, const char *name)
+{
+ QGstElement element = QGstElement::createFromFactory(factory, name);
+ Q_ASSERT(GST_IS_BIN(element.element()));
+ return QGstBin{
+ GST_BIN(element.release()),
+ RefMode::HasRef,
+ };
+}
+
+QGstBin QGstBin::createFromPipelineDescription(const QByteArray &pipelineDescription,
+ const char *name, bool ghostUnlinkedPads)
+{
+ return createFromPipelineDescription(pipelineDescription.constData(), name, ghostUnlinkedPads);
+}
+
+QGstBin QGstBin::createFromPipelineDescription(const char *pipelineDescription, const char *name,
+ bool ghostUnlinkedPads)
+{
+ QUniqueGErrorHandle error;
+
+ GstElement *element =
+ gst_parse_bin_from_description_full(pipelineDescription, ghostUnlinkedPads,
+ /*context=*/nullptr, GST_PARSE_FLAG_NONE, &error);
+
+ if (!element) {
+ qWarning() << "Failed to make element from pipeline description" << pipelineDescription
+ << error;
+ return QGstBin{};
+ }
+
+ if (name)
+ gst_element_set_name(element, name);
+
+ return QGstBin{
+ element,
+ NeedsRef,
+ };
+}
+
+QGstBin::QGstBin(GstBin *bin, RefMode mode)
+ : QGstElement{
+ qGstCheckedCast<GstElement>(bin),
+ mode,
+ }
+{
+}
+
+GstBin *QGstBin::bin() const
+{
+ return qGstCheckedCast<GstBin>(object());
+}
+
+void QGstBin::addGhostPad(const QGstElement &child, const char *name)
+{
+ addGhostPad(name, child.staticPad(name));
+}
+
+void QGstBin::addGhostPad(const char *name, const QGstPad &pad)
+{
+ gst_element_add_pad(element(), gst_ghost_pad_new(name, pad.pad()));
+}
+
+bool QGstBin::syncChildrenState()
+{
+ return gst_bin_sync_children_states(bin());
+}
+
+void QGstBin::dumpGraph(const char *fileNamePrefix)
+{
+ if (isNull())
+ return;
+
+ GST_DEBUG_BIN_TO_DOT_FILE(bin(), GST_DEBUG_GRAPH_SHOW_VERBOSE, fileNamePrefix);
+}
+
+QGstElement QGstBin::findByName(const char *name)
+{
+ return QGstElement{
+ gst_bin_get_by_name(bin(), name),
+ QGstElement::NeedsRef,
+ };
+}
+
+// QGstBaseSink
+
+QGstBaseSink::QGstBaseSink(GstBaseSink *element, RefMode mode)
+ : QGstElement{
+ qGstCheckedCast<GstElement>(element),
+ mode,
+ }
+{
+}
+
+void QGstBaseSink::setSync(bool arg)
+{
+ gst_base_sink_set_sync(baseSink(), arg ? TRUE : FALSE);
+}
+
+GstBaseSink *QGstBaseSink::baseSink() const
+{
+ return qGstCheckedCast<GstBaseSink>(element());
+}
+
+// QGstBaseSrc
+
+QGstBaseSrc::QGstBaseSrc(GstBaseSrc *element, RefMode mode)
+ : QGstElement{
+ qGstCheckedCast<GstElement>(element),
+ mode,
+ }
+{
+}
+
+GstBaseSrc *QGstBaseSrc::baseSrc() const
+{
+ return qGstCheckedCast<GstBaseSrc>(element());
+}
+
+#if QT_CONFIG(gstreamer_app)
+
+// QGstAppSink
+
+QGstAppSink::QGstAppSink(GstAppSink *element, RefMode mode)
+ : QGstBaseSink{
+ qGstCheckedCast<GstBaseSink>(element),
+ mode,
+ }
+{
+}
+
+QGstAppSink QGstAppSink::create(const char *name)
+{
+ QGstElement created = QGstElement::createFromFactory("appsink", name);
+ return QGstAppSink{
+ qGstCheckedCast<GstAppSink>(created.element()),
+ QGstAppSink::NeedsRef,
+ };
+}
+
+GstAppSink *QGstAppSink::appSink() const
+{
+ return qGstCheckedCast<GstAppSink>(element());
+}
+
+# if GST_CHECK_VERSION(1, 24, 0)
+void QGstAppSink::setMaxBufferTime(std::chrono::nanoseconds ns)
+{
+ gst_app_sink_set_max_time(appSink(), qGstClockTimeFromChrono(ns));
+}
+# endif
+
+void QGstAppSink::setMaxBuffers(int n)
+{
+ gst_app_sink_set_max_buffers(appSink(), n);
+}
+
+void QGstAppSink::setCaps(const QGstCaps &caps)
+{
+ gst_app_sink_set_caps(appSink(), caps.caps());
+}
+
+void QGstAppSink::setCallbacks(GstAppSinkCallbacks &callbacks, gpointer user_data,
+ GDestroyNotify notify)
+{
+ gst_app_sink_set_callbacks(appSink(), &callbacks, user_data, notify);
+}
+
+QGstSampleHandle QGstAppSink::pullSample()
+{
+ return QGstSampleHandle{
+ gst_app_sink_pull_sample(appSink()),
+ QGstSampleHandle::HasRef,
+ };
+}
+
+// QGstAppSrc
+
+QGstAppSrc::QGstAppSrc(GstAppSrc *element, RefMode mode)
+ : QGstBaseSrc{
+ qGstCheckedCast<GstBaseSrc>(element),
+ mode,
+ }
+{
+}
+
+QGstAppSrc QGstAppSrc::create(const char *name)
+{
+ QGstElement created = QGstElement::createFromFactory("appsrc", name);
+ return QGstAppSrc{
+ qGstCheckedCast<GstAppSrc>(created.element()),
+ QGstAppSrc::NeedsRef,
+ };
+}
+
+GstAppSrc *QGstAppSrc::appSrc() const
+{
+ return qGstCheckedCast<GstAppSrc>(element());
+}
+
+void QGstAppSrc::setCallbacks(GstAppSrcCallbacks &callbacks, gpointer user_data,
+ GDestroyNotify notify)
+{
+ gst_app_src_set_callbacks(appSrc(), &callbacks, user_data, notify);
+}
+
+GstFlowReturn QGstAppSrc::pushBuffer(GstBuffer *buffer)
+{
+ return gst_app_src_push_buffer(appSrc(), buffer);
+}
+
+#endif
+
+QString qGstErrorMessageCannotFindElement(std::string_view element)
+{
+ return QStringLiteral("Could not find the %1 GStreamer element")
+ .arg(QLatin1StringView(element));
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgst_debug.cpp b/src/plugins/multimedia/gstreamer/common/qgst_debug.cpp
new file mode 100644
index 000000000..413b02f44
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgst_debug.cpp
@@ -0,0 +1,565 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qgst_debug_p.h"
+#include "qgstreamermessage_p.h"
+
+#include <gst/gstclock.h>
+
+QT_BEGIN_NAMESPACE
+
+// NOLINTBEGIN(performance-unnecessary-value-param)
+
+QDebug operator<<(QDebug dbg, const QGString &str)
+{
+ return dbg << str.get();
+}
+
+QDebug operator<<(QDebug dbg, const QGstCaps &caps)
+{
+ return dbg << caps.caps();
+}
+
+QDebug operator<<(QDebug dbg, const QGstStructureView &structure)
+{
+ return dbg << structure.structure;
+}
+
+QDebug operator<<(QDebug dbg, const QGValue &value)
+{
+ return dbg << value.value;
+}
+
+QDebug operator<<(QDebug dbg, const QGstreamerMessage &msg)
+{
+ return dbg << msg.message();
+}
+
+QDebug operator<<(QDebug dbg, const QUniqueGErrorHandle &handle)
+{
+ return dbg << handle.get();
+}
+
+QDebug operator<<(QDebug dbg, const QUniqueGStringHandle &handle)
+{
+ return dbg << handle.get();
+}
+
+QDebug operator<<(QDebug dbg, const QGstStreamCollectionHandle &handle)
+{
+ return dbg << handle.get();
+}
+
+QDebug operator<<(QDebug dbg, const QGstStreamHandle &handle)
+{
+ return dbg << handle.get();
+}
+
+QDebug operator<<(QDebug dbg, const QGstTagListHandle &handle)
+{
+ return dbg << handle.get();
+}
+
+QDebug operator<<(QDebug dbg, const QGstElement &element)
+{
+ return dbg << element.element();
+}
+
+QDebug operator<<(QDebug dbg, const QGstPad &pad)
+{
+ return dbg << pad.pad();
+}
+
+QDebug operator<<(QDebug dbg, const GstCaps *caps)
+{
+ if (caps)
+ return dbg << QGString(gst_caps_to_string(caps));
+ else
+ return dbg << "null";
+}
+
+QDebug operator<<(QDebug dbg, const GstVideoInfo *info)
+{
+#if GST_CHECK_VERSION(1, 20, 0)
+ return dbg << QGstCaps{
+ gst_video_info_to_caps(info),
+ QGstCaps::NeedsRef,
+ };
+#else
+ return dbg << QGstCaps{
+ gst_video_info_to_caps(const_cast<GstVideoInfo *>(info)),
+ QGstCaps::NeedsRef,
+ };
+#endif
+}
+
+QDebug operator<<(QDebug dbg, const GstStructure *structure)
+{
+ if (structure)
+ return dbg << QGString(gst_structure_to_string(structure));
+ else
+ return dbg << "null";
+}
+
+QDebug operator<<(QDebug dbg, const GstObject *object)
+{
+ dbg << QGString{gst_object_get_name(const_cast<GstObject*>(object))};
+
+ {
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+
+ dbg << "{";
+
+ guint numProperties;
+ GParamSpec **properties = g_object_class_list_properties(G_OBJECT_GET_CLASS(object), &numProperties);
+
+ for (guint i = 0; i < numProperties; i++) {
+ GParamSpec *param = properties[i];
+
+ const gchar *name = g_param_spec_get_name(param);
+ constexpr bool trace_blurb = false;
+ if constexpr (trace_blurb) {
+ const gchar *blurb = g_param_spec_get_blurb(param);
+ dbg << name << " (" << blurb << "): ";
+ } else
+ dbg << name << ": ";
+
+ bool readable = bool(param->flags & G_PARAM_READABLE);
+ if (!readable) {
+ dbg << "(not readable)";
+ } else if (QLatin1StringView(name) == QLatin1StringView("parent")) {
+ if (object->parent)
+ dbg << QGString{ gst_object_get_name(object->parent) };
+ else
+ dbg << "(none)";
+ } else {
+ GValue value = {};
+ g_object_get_property(&const_cast<GstObject *>(object)->object, param->name,
+ &value);
+ dbg << &value;
+ }
+ if (i != numProperties - 1)
+ dbg << ", ";
+ }
+
+ dbg << "}";
+
+ g_free(properties);
+ }
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, const GstElement *element)
+{
+ return dbg << GST_OBJECT_CAST(element); // LATER: output other members?
+}
+
+QDebug operator<<(QDebug dbg, const GstPad *pad)
+{
+ return dbg << GST_OBJECT_CAST(pad); // LATER: output other members?
+}
+
+QDebug operator<<(QDebug dbg, const GstDevice *device)
+{
+ GstDevice *d = const_cast<GstDevice *>(device);
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+
+ dbg << gst_device_get_display_name(d) << "(" << gst_device_get_device_class(d) << ") ";
+ dbg << "Caps: " << QGstCaps{ gst_device_get_caps(d), QGstCaps::NeedsRef, } << ", ";
+ dbg << "Properties: " << QUniqueGstStructureHandle{ gst_device_get_properties(d) }.get();
+ return dbg;
+}
+
+namespace {
+
+struct Timepoint
+{
+ explicit Timepoint(guint64 us) : ts{ us } { }
+ guint64 ts;
+};
+
+QDebug operator<<(QDebug dbg, Timepoint ts)
+{
+ char buffer[128];
+ snprintf(buffer, sizeof(buffer), "%" GST_TIME_FORMAT, GST_TIME_ARGS(ts.ts));
+ dbg << buffer;
+ return dbg;
+}
+
+} // namespace
+
+QDebug operator<<(QDebug dbg, const GstMessage *msg)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+
+ dbg << GST_MESSAGE_TYPE_NAME(msg) << ", Source: " << GST_MESSAGE_SRC_NAME(msg);
+ if (GST_MESSAGE_TIMESTAMP(msg) != 0xFFFFFFFFFFFFFFFF)
+ dbg << ", Timestamp: " << GST_MESSAGE_TIMESTAMP(msg);
+
+ switch (msg->type) {
+ case GST_MESSAGE_ERROR: {
+ QUniqueGErrorHandle err;
+ QGString debug;
+ gst_message_parse_error(const_cast<GstMessage *>(msg), &err, &debug);
+
+ dbg << ", Error: " << err << " (" << debug << ")";
+ break;
+ }
+
+ case GST_MESSAGE_WARNING: {
+ QUniqueGErrorHandle err;
+ QGString debug;
+ gst_message_parse_warning(const_cast<GstMessage *>(msg), &err, &debug);
+
+ dbg << ", Warning: " << err << " (" << debug << ")";
+ break;
+ }
+
+ case GST_MESSAGE_INFO: {
+ QUniqueGErrorHandle err;
+ QGString debug;
+ gst_message_parse_info(const_cast<GstMessage *>(msg), &err, &debug);
+
+ dbg << ", Info: " << err << " (" << debug << ")";
+ break;
+ }
+
+ case GST_MESSAGE_TAG: {
+ QGstTagListHandle tagList;
+ gst_message_parse_tag(const_cast<GstMessage *>(msg), &tagList);
+
+ dbg << ", Tags: " << tagList;
+ break;
+ }
+
+ case GST_MESSAGE_QOS: {
+ gboolean live;
+ guint64 running_time;
+ guint64 stream_time;
+ guint64 timestamp;
+ guint64 duration;
+
+ gst_message_parse_qos(const_cast<GstMessage *>(msg), &live, &running_time, &stream_time,
+ &timestamp, &duration);
+
+ dbg << ", Live: " << bool(live) << ", Running time: " << Timepoint{ running_time }
+ << ", Stream time: " << Timepoint{ stream_time }
+ << ", Timestamp: " << Timepoint{ timestamp } << ", Duration: " << Timepoint{ duration };
+ break;
+ }
+
+ case GST_MESSAGE_STATE_CHANGED: {
+ GstState oldState;
+ GstState newState;
+ GstState pending;
+
+ gst_message_parse_state_changed(const_cast<GstMessage *>(msg), &oldState, &newState,
+ &pending);
+
+ dbg << ", Transition: " << oldState << "->" << newState;
+
+ if (pending != GST_STATE_VOID_PENDING)
+ dbg << ", Pending State: " << pending;
+ break;
+ }
+
+ case GST_MESSAGE_STREAM_COLLECTION: {
+ QGstStreamCollectionHandle collection;
+ gst_message_parse_stream_collection(const_cast<GstMessage *>(msg), &collection);
+
+ dbg << ", " << collection;
+ break;
+ }
+
+ case GST_MESSAGE_STREAMS_SELECTED: {
+ QGstStreamCollectionHandle collection;
+ gst_message_parse_streams_selected(const_cast<GstMessage *>(msg), &collection);
+
+ dbg << ", " << collection;
+ break;
+ }
+
+ case GST_MESSAGE_STREAM_STATUS: {
+ GstStreamStatusType streamStatus;
+ gst_message_parse_stream_status(const_cast<GstMessage *>(msg), &streamStatus, nullptr);
+
+ dbg << ", Stream Status: " << streamStatus;
+ break;
+ }
+
+ default:
+ break;
+ }
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, const GstTagList *tagList)
+{
+ dbg << QGString{ gst_tag_list_to_string(tagList) };
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, const GstQuery *query)
+{
+ dbg << GST_QUERY_TYPE_NAME(query);
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, const GstEvent *event)
+{
+ dbg << GST_EVENT_TYPE_NAME(event);
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, const GstPadTemplate *padTemplate)
+{
+ QGstCaps caps = padTemplate
+ ? QGstCaps{ gst_pad_template_get_caps(const_cast<GstPadTemplate *>(padTemplate)), QGstCaps::HasRef, }
+ : QGstCaps{};
+
+ dbg << caps;
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, const GstStreamCollection *streamCollection)
+{
+ GstStreamCollection *collection = const_cast<GstStreamCollection *>(streamCollection);
+ guint size = gst_stream_collection_get_size(collection);
+
+ dbg << "Stream Collection: {";
+ for (guint index = 0; index != size; ++index) {
+ dbg << gst_stream_collection_get_stream(collection, index);
+ if (index + 1 != size)
+ dbg << ", ";
+ }
+
+ dbg << "}";
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, const GstStream *cstream)
+{
+ GstStream *stream = const_cast<GstStream *>(cstream);
+
+ dbg << "GstStream { ";
+ dbg << "Type: " << gst_stream_type_get_name(gst_stream_get_stream_type(stream));
+
+ QGstTagListHandle tagList{
+ gst_stream_get_tags(stream),
+ QGstTagListHandle::HasRef,
+ };
+
+ if (tagList)
+ dbg << ", Tags: " << tagList;
+
+ QGstCaps caps{
+ gst_stream_get_caps(stream),
+ QGstCaps::HasRef,
+ };
+
+ if (caps)
+ dbg << ", Caps: " << caps;
+
+ dbg << "}";
+
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, GstState state)
+{
+ return dbg << gst_element_state_get_name(state);
+}
+
+QDebug operator<<(QDebug dbg, GstStateChange transition)
+{
+ return dbg << gst_state_change_get_name(transition);
+}
+
+QDebug operator<<(QDebug dbg, GstStateChangeReturn stateChangeReturn)
+{
+ return dbg << gst_element_state_change_return_get_name(stateChangeReturn);
+}
+
+QDebug operator<<(QDebug dbg, GstMessageType type)
+{
+ return dbg << gst_message_type_get_name(type);
+}
+
+#define ADD_ENUM_SWITCH(value) \
+ case value: \
+ return dbg << #value; \
+ static_assert(true, "enforce semicolon")
+
+QDebug operator<<(QDebug dbg, GstPadDirection direction)
+{
+ switch (direction) {
+ ADD_ENUM_SWITCH(GST_PAD_UNKNOWN);
+ ADD_ENUM_SWITCH(GST_PAD_SRC);
+ ADD_ENUM_SWITCH(GST_PAD_SINK);
+ default:
+ Q_UNREACHABLE_RETURN(dbg);
+ }
+}
+
+QDebug operator<<(QDebug dbg, GstStreamStatusType type)
+{
+ switch (type) {
+ ADD_ENUM_SWITCH(GST_STREAM_STATUS_TYPE_CREATE);
+ ADD_ENUM_SWITCH(GST_STREAM_STATUS_TYPE_ENTER);
+ ADD_ENUM_SWITCH(GST_STREAM_STATUS_TYPE_LEAVE);
+ ADD_ENUM_SWITCH(GST_STREAM_STATUS_TYPE_DESTROY);
+ ADD_ENUM_SWITCH(GST_STREAM_STATUS_TYPE_START);
+ ADD_ENUM_SWITCH(GST_STREAM_STATUS_TYPE_PAUSE);
+ ADD_ENUM_SWITCH(GST_STREAM_STATUS_TYPE_STOP);
+ default:
+ Q_UNREACHABLE_RETURN(dbg);
+ }
+ return dbg;
+}
+
+#undef ADD_ENUM_SWITCH
+
+QDebug operator<<(QDebug dbg, const GValue *value)
+{
+ switch (G_VALUE_TYPE(value)) {
+ case G_TYPE_STRING:
+ return dbg << g_value_get_string(value);
+ case G_TYPE_BOOLEAN:
+ return dbg << g_value_get_boolean(value);
+ case G_TYPE_ULONG:
+ return dbg << g_value_get_ulong(value);
+ case G_TYPE_LONG:
+ return dbg << g_value_get_long(value);
+ case G_TYPE_UINT:
+ return dbg << g_value_get_uint(value);
+ case G_TYPE_INT:
+ return dbg << g_value_get_int(value);
+ case G_TYPE_UINT64:
+ return dbg << g_value_get_uint64(value);
+ case G_TYPE_INT64:
+ return dbg << g_value_get_int64(value);
+ case G_TYPE_FLOAT:
+ return dbg << g_value_get_float(value);
+ case G_TYPE_DOUBLE:
+ return dbg << g_value_get_double(value);
+ default:
+ break;
+ }
+
+ if (GST_VALUE_HOLDS_BITMASK(value)) {
+ QDebugStateSaver saver(dbg);
+ return dbg << Qt::hex << gst_value_get_bitmask(value);
+ }
+
+ if (GST_VALUE_HOLDS_FRACTION(value))
+ return dbg << gst_value_get_fraction_numerator(value) << "/"
+ << gst_value_get_fraction_denominator(value);
+
+ if (GST_VALUE_HOLDS_CAPS(value))
+ return dbg << gst_value_get_caps(value);
+
+ if (GST_VALUE_HOLDS_STRUCTURE(value))
+ return dbg << gst_value_get_structure(value);
+
+ if (GST_VALUE_HOLDS_ARRAY(value)) {
+ const guint size = gst_value_array_get_size(value);
+ const guint last = size - 1;
+ dbg << "[";
+ for (guint index = 0; index != size; ++index) {
+ dbg << gst_value_array_get_value(value, index);
+ if (index != last)
+ dbg << ", ";
+ }
+ dbg << "}";
+ return dbg;
+ }
+
+ if (G_VALUE_TYPE(value) == GST_TYPE_PAD_DIRECTION) {
+ GstPadDirection direction = static_cast<GstPadDirection>(g_value_get_enum(value));
+ return dbg << direction;
+ }
+
+ if (G_VALUE_TYPE(value) == GST_TYPE_PAD_TEMPLATE) {
+ GstPadTemplate *padTemplate = static_cast<GstPadTemplate *>(g_value_get_object(value));
+ return dbg << padTemplate;
+ }
+
+ dbg << "(not implemented: " << G_VALUE_TYPE_NAME(value) << ")";
+
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, const GError *error)
+{
+ return dbg << error->message;
+}
+
+QCompactGstMessageAdaptor::QCompactGstMessageAdaptor(const QGstreamerMessage &m)
+ : QCompactGstMessageAdaptor{
+ m.message(),
+ }
+{
+}
+
+QCompactGstMessageAdaptor::QCompactGstMessageAdaptor(GstMessage *m)
+ : msg{
+ m,
+ }
+{
+}
+
+QDebug operator<<(QDebug dbg, const QCompactGstMessageAdaptor &m)
+{
+ std::optional<QDebugStateSaver> saver(dbg);
+ dbg.nospace();
+
+ switch (GST_MESSAGE_TYPE(m.msg)) {
+ case GST_MESSAGE_ERROR: {
+ QUniqueGErrorHandle err;
+ QGString debug;
+ gst_message_parse_error(m.msg, &err, &debug);
+ dbg << err << " (" << debug << ")";
+ return dbg;
+ }
+
+ case GST_MESSAGE_WARNING: {
+ QUniqueGErrorHandle err;
+ QGString debug;
+ gst_message_parse_warning(m.msg, &err, &debug);
+ dbg << err << " (" << debug << ")";
+ return dbg;
+ }
+
+ case GST_MESSAGE_INFO: {
+ QUniqueGErrorHandle err;
+ QGString debug;
+ gst_message_parse_info(m.msg, &err, &debug);
+
+ dbg << err << " (" << debug << ")";
+ return dbg;
+ }
+
+ case GST_MESSAGE_STATE_CHANGED: {
+ GstState oldState;
+ GstState newState;
+ GstState pending;
+
+ gst_message_parse_state_changed(m.msg, &oldState, &newState, &pending);
+
+ dbg << oldState << " -> " << newState;
+ if (pending != GST_STATE_VOID_PENDING)
+ dbg << " (pending: " << pending << ")";
+ return dbg;
+ }
+
+ default: {
+ saver.reset();
+ return dbg << m.msg;
+ }
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgst_debug_p.h b/src/plugins/multimedia/gstreamer/common/qgst_debug_p.h
new file mode 100644
index 000000000..df13c6c13
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgst_debug_p.h
@@ -0,0 +1,74 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGST_DEBUG_P_H
+#define QGST_DEBUG_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qgst_p.h"
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerMessage;
+
+QDebug operator<<(QDebug, const QGstCaps &);
+QDebug operator<<(QDebug, const QGstStructureView &);
+QDebug operator<<(QDebug, const QGstElement &);
+QDebug operator<<(QDebug, const QGstPad &);
+QDebug operator<<(QDebug, const QGString &);
+QDebug operator<<(QDebug, const QGValue &);
+QDebug operator<<(QDebug, const QGstreamerMessage &);
+QDebug operator<<(QDebug, const QUniqueGErrorHandle &);
+QDebug operator<<(QDebug, const QUniqueGStringHandle &);
+QDebug operator<<(QDebug, const QGstStreamCollectionHandle &);
+QDebug operator<<(QDebug, const QGstStreamHandle &);
+QDebug operator<<(QDebug, const QGstTagListHandle &);
+
+QDebug operator<<(QDebug, const GstCaps *);
+QDebug operator<<(QDebug, const GstVideoInfo *);
+QDebug operator<<(QDebug, const GstStructure *);
+QDebug operator<<(QDebug, const GstObject *);
+QDebug operator<<(QDebug, const GstElement *);
+QDebug operator<<(QDebug, const GstPad *);
+QDebug operator<<(QDebug, const GstDevice *);
+QDebug operator<<(QDebug, const GstMessage *);
+QDebug operator<<(QDebug, const GstTagList *);
+QDebug operator<<(QDebug, const GstQuery *);
+QDebug operator<<(QDebug, const GstEvent *);
+QDebug operator<<(QDebug, const GstPadTemplate *);
+QDebug operator<<(QDebug, const GstStreamCollection *);
+QDebug operator<<(QDebug, const GstStream *);
+
+QDebug operator<<(QDebug, GstState);
+QDebug operator<<(QDebug, GstStateChange);
+QDebug operator<<(QDebug, GstStateChangeReturn);
+QDebug operator<<(QDebug, GstMessageType);
+QDebug operator<<(QDebug, GstPadDirection);
+QDebug operator<<(QDebug, GstStreamStatusType);
+
+QDebug operator<<(QDebug, const GValue *);
+QDebug operator<<(QDebug, const GError *);
+
+struct QCompactGstMessageAdaptor
+{
+ explicit QCompactGstMessageAdaptor(const QGstreamerMessage &m);
+ explicit QCompactGstMessageAdaptor(GstMessage *m);
+ GstMessage *msg;
+};
+
+QDebug operator<<(QDebug, const QCompactGstMessageAdaptor &);
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgst_handle_types_p.h b/src/plugins/multimedia/gstreamer/common/qgst_handle_types_p.h
new file mode 100644
index 000000000..9c4f5683a
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgst_handle_types_p.h
@@ -0,0 +1,269 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGST_HANDLE_TYPES_P_H
+#define QGST_HANDLE_TYPES_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/private/qcore_unix_p.h>
+#include <QtCore/private/quniquehandle_p.h>
+#include <QtCore/qtconfigmacros.h>
+
+#include <QtMultimedia/private/qtmultimedia-config_p.h>
+
+#include <gst/gst.h>
+
+#if QT_CONFIG(gstreamer_gl)
+# include <gst/gl/gstglcontext.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+namespace QGstImpl {
+
+template <typename HandleTraits>
+struct QSharedHandle : private QUniqueHandle<HandleTraits>
+{
+ using BaseClass = QUniqueHandle<HandleTraits>;
+
+ enum RefMode { HasRef, NeedsRef };
+
+ QSharedHandle() = default;
+
+ explicit QSharedHandle(typename HandleTraits::Type object, RefMode mode)
+ : BaseClass{ mode == NeedsRef ? HandleTraits::ref(object) : object }
+ {
+ }
+
+ QSharedHandle(const QSharedHandle &o)
+ : BaseClass{
+ HandleTraits::ref(o.get()),
+ }
+ {
+ }
+
+ QSharedHandle(QSharedHandle &&) noexcept = default;
+
+ QSharedHandle &operator=(const QSharedHandle &o) // NOLINT: bugprone-unhandled-self-assign
+ {
+ if (BaseClass::get() != o.get())
+ reset(HandleTraits::ref(o.get()));
+ return *this;
+ };
+
+ QSharedHandle &operator=(QSharedHandle &&) noexcept = default;
+
+ [[nodiscard]] friend bool operator==(const QSharedHandle &lhs,
+ const QSharedHandle &rhs) noexcept
+ {
+ return lhs.get() == rhs.get();
+ }
+
+ [[nodiscard]] friend bool operator!=(const QSharedHandle &lhs,
+ const QSharedHandle &rhs) noexcept
+ {
+ return lhs.get() != rhs.get();
+ }
+
+ [[nodiscard]] friend bool operator<(const QSharedHandle &lhs, const QSharedHandle &rhs) noexcept
+ {
+ return lhs.get() < rhs.get();
+ }
+
+ [[nodiscard]] friend bool operator<=(const QSharedHandle &lhs,
+ const QSharedHandle &rhs) noexcept
+ {
+ return lhs.get() <= rhs.get();
+ }
+
+ [[nodiscard]] friend bool operator>(const QSharedHandle &lhs, const QSharedHandle &rhs) noexcept
+ {
+ return lhs.get() > rhs.get();
+ }
+
+ [[nodiscard]] friend bool operator>=(const QSharedHandle &lhs,
+ const QSharedHandle &rhs) noexcept
+ {
+ return lhs.get() >= rhs.get();
+ }
+
+ using BaseClass::get;
+ using BaseClass::isValid;
+ using BaseClass::operator bool;
+ using BaseClass::release;
+ using BaseClass::reset;
+ using BaseClass::operator&;
+ using BaseClass::close;
+};
+
+struct QGstTagListHandleTraits
+{
+ using Type = GstTagList *;
+ static constexpr Type invalidValue() noexcept { return nullptr; }
+ static bool close(Type handle) noexcept
+ {
+ gst_tag_list_unref(handle);
+ return true;
+ }
+ static Type ref(Type handle) noexcept { return gst_tag_list_ref(handle); }
+};
+
+struct QGstSampleHandleTraits
+{
+ using Type = GstSample *;
+ static constexpr Type invalidValue() noexcept { return nullptr; }
+ static bool close(Type handle) noexcept
+ {
+ gst_sample_unref(handle);
+ return true;
+ }
+ static Type ref(Type handle) noexcept { return gst_sample_ref(handle); }
+};
+
+struct QUniqueGstStructureHandleTraits
+{
+ using Type = GstStructure *;
+ static constexpr Type invalidValue() noexcept { return nullptr; }
+ static bool close(Type handle) noexcept
+ {
+ gst_structure_free(handle);
+ return true;
+ }
+};
+
+struct QUniqueGStringHandleTraits
+{
+ using Type = gchar *;
+ static constexpr Type invalidValue() noexcept { return nullptr; }
+ static bool close(Type handle) noexcept
+ {
+ g_free(handle);
+ return true;
+ }
+};
+
+struct QUniqueGErrorHandleTraits
+{
+ using Type = GError *;
+ static constexpr Type invalidValue() noexcept { return nullptr; }
+ static bool close(Type handle) noexcept
+ {
+ g_error_free(handle);
+ return true;
+ }
+};
+
+
+struct QUniqueGstDateTimeHandleTraits
+{
+ using Type = GstDateTime *;
+ static constexpr Type invalidValue() noexcept { return nullptr; }
+ static bool close(Type handle) noexcept
+ {
+ gst_date_time_unref(handle);
+ return true;
+ }
+};
+
+struct QFileDescriptorHandleTraits
+{
+ using Type = int;
+ static constexpr Type invalidValue() noexcept { return -1; }
+ static bool close(Type fd) noexcept
+ {
+ int closeResult = qt_safe_close(fd);
+ return closeResult == 0;
+ }
+};
+
+template <typename GstType>
+struct QGstHandleHelper
+{
+ struct QGstSafeObjectHandleTraits
+ {
+ using Type = GstType *;
+ static constexpr Type invalidValue() noexcept { return nullptr; }
+ static bool close(Type handle) noexcept
+ {
+ gst_object_unref(G_OBJECT(handle));
+ return true;
+ }
+
+ static Type ref(Type handle) noexcept
+ {
+ gst_object_ref_sink(G_OBJECT(handle));
+ return handle;
+ }
+ };
+
+ using SharedHandle = QSharedHandle<QGstSafeObjectHandleTraits>;
+ using UniqueHandle = QUniqueHandle<QGstSafeObjectHandleTraits>;
+};
+
+template <typename GstType>
+struct QGstMiniObjectHandleHelper
+{
+ struct Traits
+ {
+ using Type = GstType *;
+ static constexpr Type invalidValue() noexcept { return nullptr; }
+ static bool close(Type handle) noexcept
+ {
+ gst_mini_object_unref(GST_MINI_OBJECT_CAST(handle));
+ return true;
+ }
+
+ static Type ref(Type handle) noexcept
+ {
+ gst_mini_object_ref(GST_MINI_OBJECT_CAST(handle));
+ return handle;
+ }
+ };
+
+ using SharedHandle = QSharedHandle<Traits>;
+ using UniqueHandle = QUniqueHandle<Traits>;
+};
+
+} // namespace QGstImpl
+
+using QGstClockHandle = QGstImpl::QGstHandleHelper<GstClock>::UniqueHandle;
+using QGstElementHandle = QGstImpl::QGstHandleHelper<GstElement>::UniqueHandle;
+using QGstElementFactoryHandle = QGstImpl::QGstHandleHelper<GstElementFactory>::SharedHandle;
+using QGstDeviceHandle = QGstImpl::QGstHandleHelper<GstDevice>::SharedHandle;
+using QGstDeviceMonitorHandle = QGstImpl::QGstHandleHelper<GstDeviceMonitor>::UniqueHandle;
+using QGstBusHandle = QGstImpl::QGstHandleHelper<GstBus>::UniqueHandle;
+using QGstStreamCollectionHandle = QGstImpl::QGstHandleHelper<GstStreamCollection>::SharedHandle;
+using QGstStreamHandle = QGstImpl::QGstHandleHelper<GstStream>::SharedHandle;
+
+using QGstTagListHandle = QGstImpl::QSharedHandle<QGstImpl::QGstTagListHandleTraits>;
+using QGstSampleHandle = QGstImpl::QSharedHandle<QGstImpl::QGstSampleHandleTraits>;
+
+using QUniqueGstStructureHandle = QUniqueHandle<QGstImpl::QUniqueGstStructureHandleTraits>;
+using QUniqueGStringHandle = QUniqueHandle<QGstImpl::QUniqueGStringHandleTraits>;
+using QUniqueGErrorHandle = QUniqueHandle<QGstImpl::QUniqueGErrorHandleTraits>;
+using QUniqueGstDateTimeHandle = QUniqueHandle<QGstImpl::QUniqueGstDateTimeHandleTraits>;
+using QFileDescriptorHandle = QUniqueHandle<QGstImpl::QFileDescriptorHandleTraits>;
+using QGstBufferHandle = QGstImpl::QGstMiniObjectHandleHelper<GstBuffer>::SharedHandle;
+using QGstContextHandle = QGstImpl::QGstMiniObjectHandleHelper<GstContext>::UniqueHandle;
+using QGstGstDateTimeHandle = QGstImpl::QGstMiniObjectHandleHelper<GstDateTime>::SharedHandle;
+using QGstPluginFeatureHandle = QGstImpl::QGstHandleHelper<GstPluginFeature>::SharedHandle;
+using QGstQueryHandle = QGstImpl::QGstMiniObjectHandleHelper<GstQuery>::SharedHandle;
+
+#if QT_CONFIG(gstreamer_gl)
+using QGstGLContextHandle = QGstImpl::QGstHandleHelper<GstGLContext>::UniqueHandle;
+using QGstGLDisplayHandle = QGstImpl::QGstHandleHelper<GstGLDisplay>::UniqueHandle;
+#endif
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgst_p.h b/src/plugins/multimedia/gstreamer/common/qgst_p.h
new file mode 100644
index 000000000..68412258e
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgst_p.h
@@ -0,0 +1,844 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGST_P_H
+#define QGST_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qdebug.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qsemaphore.h>
+
+#include <QtMultimedia/qaudioformat.h>
+#include <QtMultimedia/qvideoframe.h>
+#include <QtMultimedia/private/qtmultimediaglobal_p.h>
+#include <QtMultimedia/private/qmultimediautils_p.h>
+#include <QtMultimedia/private/qplatformmediaplayer_p.h>
+
+#include <gst/gst.h>
+#include <gst/video/video-info.h>
+
+#include "qgst_handle_types_p.h"
+
+#include <type_traits>
+
+#if QT_CONFIG(gstreamer_photography)
+# define GST_USE_UNSTABLE_API
+# include <gst/interfaces/photography.h>
+# undef GST_USE_UNSTABLE_API
+#endif
+
+#if QT_CONFIG(gstreamer_app)
+# include <gst/app/gstappsink.h>
+# include <gst/app/gstappsrc.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+namespace QGstImpl {
+
+template <typename T>
+struct GstObjectTraits
+{
+ // using Type = T;
+ // template <typename U>
+ // static bool isObjectOfType(U *);
+ // template <typename U>
+ // static T *cast(U *);
+};
+
+#define QGST_DEFINE_CAST_TRAITS(ClassName, MACRO_LABEL) \
+ template <> \
+ struct GstObjectTraits<ClassName> \
+ { \
+ using Type = ClassName; \
+ template <typename U> \
+ static bool isObjectOfType(U *arg) \
+ { \
+ return GST_IS_##MACRO_LABEL(arg); \
+ } \
+ template <typename U> \
+ static Type *cast(U *arg) \
+ { \
+ return GST_##MACRO_LABEL##_CAST(arg); \
+ } \
+ template <typename U> \
+ static Type *checked_cast(U *arg) \
+ { \
+ return GST_##MACRO_LABEL(arg); \
+ } \
+ }; \
+ static_assert(true, "ensure semicolon")
+
+#define QGST_DEFINE_CAST_TRAITS_FOR_INTERFACE(ClassName, MACRO_LABEL) \
+ template <> \
+ struct GstObjectTraits<ClassName> \
+ { \
+ using Type = ClassName; \
+ template <typename U> \
+ static bool isObjectOfType(U *arg) \
+ { \
+ return GST_IS_##MACRO_LABEL(arg); \
+ } \
+ template <typename U> \
+ static Type *cast(U *arg) \
+ { \
+ return checked_cast(arg); \
+ } \
+ template <typename U> \
+ static Type *checked_cast(U *arg) \
+ { \
+ return GST_##MACRO_LABEL(arg); \
+ } \
+ }; \
+ static_assert(true, "ensure semicolon")
+
+QGST_DEFINE_CAST_TRAITS(GstBin, BIN);
+QGST_DEFINE_CAST_TRAITS(GstClock, CLOCK);
+QGST_DEFINE_CAST_TRAITS(GstElement, ELEMENT);
+QGST_DEFINE_CAST_TRAITS(GstObject, OBJECT);
+QGST_DEFINE_CAST_TRAITS(GstPad, PAD);
+QGST_DEFINE_CAST_TRAITS(GstPipeline, PIPELINE);
+QGST_DEFINE_CAST_TRAITS(GstBaseSink, BASE_SINK);
+QGST_DEFINE_CAST_TRAITS(GstBaseSrc, BASE_SRC);
+
+QGST_DEFINE_CAST_TRAITS_FOR_INTERFACE(GstTagSetter, TAG_SETTER);
+
+#if QT_CONFIG(gstreamer_app)
+QGST_DEFINE_CAST_TRAITS(GstAppSink, APP_SINK);
+QGST_DEFINE_CAST_TRAITS(GstAppSrc, APP_SRC);
+#endif
+
+template <>
+struct GstObjectTraits<GObject>
+{
+ using Type = GObject;
+ template <typename U>
+ static bool isObjectOfType(U *arg)
+ {
+ return G_IS_OBJECT(arg);
+ }
+ template <typename U>
+ static Type *cast(U *arg)
+ {
+ return G_OBJECT(arg);
+ }
+ template <typename U>
+ static Type *checked_cast(U *arg)
+ {
+ return G_OBJECT(arg);
+ }
+};
+
+#undef QGST_DEFINE_CAST_TRAITS
+#undef QGST_DEFINE_CAST_TRAITS_FOR_INTERFACE
+
+} // namespace QGstImpl
+
+template <typename DestinationType, typename SourceType>
+bool qIsGstObjectOfType(SourceType *arg)
+{
+ using Traits = QGstImpl::GstObjectTraits<DestinationType>;
+ return arg && Traits::isObjectOfType(arg);
+}
+
+template <typename DestinationType, typename SourceType>
+DestinationType *qGstSafeCast(SourceType *arg)
+{
+ using Traits = QGstImpl::GstObjectTraits<DestinationType>;
+ if (arg && Traits::isObjectOfType(arg))
+ return Traits::cast(arg);
+ return nullptr;
+}
+
+template <typename DestinationType, typename SourceType>
+DestinationType *qGstCheckedCast(SourceType *arg)
+{
+ using Traits = QGstImpl::GstObjectTraits<DestinationType>;
+ if (arg)
+ Q_ASSERT(Traits::isObjectOfType(arg));
+ return Traits::cast(arg);
+}
+
+class QSize;
+class QGstStructureView;
+class QGstCaps;
+class QGstPipelinePrivate;
+class QCameraFormat;
+
+template <typename T> struct QGRange
+{
+ T min;
+ T max;
+};
+
+struct QGString : QUniqueGStringHandle
+{
+ using QUniqueGStringHandle::QUniqueGStringHandle;
+
+ QLatin1StringView asStringView() const { return QLatin1StringView{ get() }; }
+ QString toQString() const { return QString::fromUtf8(get()); }
+};
+
+class QGValue
+{
+public:
+ explicit QGValue(const GValue *v);
+ const GValue *value;
+
+ bool isNull() const;
+
+ std::optional<bool> toBool() const;
+ std::optional<int> toInt() const;
+ std::optional<int> toInt64() const;
+ template<typename T>
+ T *getPointer() const
+ {
+ return value ? static_cast<T *>(g_value_get_pointer(value)) : nullptr;
+ }
+
+ const char *toString() const;
+ std::optional<float> getFraction() const;
+ std::optional<QGRange<float>> getFractionRange() const;
+ std::optional<QGRange<int>> toIntRange() const;
+
+ QGstStructureView toStructure() const;
+ QGstCaps toCaps() const;
+
+ bool isList() const;
+ int listSize() const;
+ QGValue at(int index) const;
+
+ QList<QAudioFormat::SampleFormat> getSampleFormats() const;
+};
+
+namespace QGstPointerImpl {
+
+template <typename RefcountedObject>
+struct QGstRefcountingAdaptor;
+
+template <typename GstType>
+class QGstObjectWrapper
+{
+ using Adaptor = QGstRefcountingAdaptor<GstType>;
+
+ GstType *m_object = nullptr;
+
+public:
+ enum RefMode { HasRef, NeedsRef };
+
+ constexpr QGstObjectWrapper() = default;
+
+ explicit QGstObjectWrapper(GstType *object, RefMode mode) : m_object(object)
+ {
+ if (m_object && mode == NeedsRef)
+ Adaptor::ref(m_object);
+ }
+
+ QGstObjectWrapper(const QGstObjectWrapper &other) : m_object(other.m_object)
+ {
+ if (m_object)
+ Adaptor::ref(m_object);
+ }
+
+ ~QGstObjectWrapper()
+ {
+ if (m_object)
+ Adaptor::unref(m_object);
+ }
+
+ QGstObjectWrapper(QGstObjectWrapper &&other) noexcept
+ : m_object(std::exchange(other.m_object, nullptr))
+ {
+ }
+
+ QGstObjectWrapper &
+ operator=(const QGstObjectWrapper &other) // NOLINT: bugprone-unhandled-self-assign
+ {
+ if (m_object != other.m_object) {
+ GstType *originalObject = m_object;
+
+ m_object = other.m_object;
+ if (m_object)
+ Adaptor::ref(m_object);
+ if (originalObject)
+ Adaptor::unref(originalObject);
+ }
+ return *this;
+ }
+
+ QGstObjectWrapper &operator=(QGstObjectWrapper &&other) noexcept
+ {
+ if (this != &other) {
+ GstType *originalObject = m_object;
+ m_object = std::exchange(other.m_object, nullptr);
+
+ if (originalObject)
+ Adaptor::unref(originalObject);
+ }
+ return *this;
+ }
+
+ friend bool operator==(const QGstObjectWrapper &a, const QGstObjectWrapper &b)
+ {
+ return a.m_object == b.m_object;
+ }
+ friend bool operator!=(const QGstObjectWrapper &a, const QGstObjectWrapper &b)
+ {
+ return a.m_object != b.m_object;
+ }
+
+ explicit operator bool() const { return bool(m_object); }
+ bool isNull() const { return !m_object; }
+ GstType *release() { return std::exchange(m_object, nullptr); }
+
+protected:
+ GstType *get() const { return m_object; }
+};
+
+} // namespace QGstPointerImpl
+
+class QGstreamerMessage;
+
+class QGstStructureView
+{
+public:
+ const GstStructure *structure = nullptr;
+ explicit QGstStructureView(const GstStructure *);
+ explicit QGstStructureView(const QUniqueGstStructureHandle &);
+
+ QUniqueGstStructureHandle clone() const;
+
+ bool isNull() const;
+ QByteArrayView name() const;
+ QGValue operator[](const char *fieldname) const;
+
+ QGstCaps caps() const;
+ QGstTagListHandle tags() const;
+
+ QSize resolution() const;
+ QVideoFrameFormat::PixelFormat pixelFormat() const;
+ QGRange<float> frameRateRange() const;
+ QGstreamerMessage getMessage();
+ std::optional<Fraction> pixelAspectRatio() const;
+ QSize nativeSize() const;
+};
+
+template <>
+struct QGstPointerImpl::QGstRefcountingAdaptor<GstCaps>
+{
+ static void ref(GstCaps *arg) noexcept { gst_caps_ref(arg); }
+ static void unref(GstCaps *arg) noexcept { gst_caps_unref(arg); }
+};
+
+class QGstCaps : public QGstPointerImpl::QGstObjectWrapper<GstCaps>
+{
+ using BaseClass = QGstPointerImpl::QGstObjectWrapper<GstCaps>;
+
+public:
+ using BaseClass::BaseClass;
+ QGstCaps(const QGstCaps &) = default;
+ QGstCaps(QGstCaps &&) noexcept = default;
+ QGstCaps &operator=(const QGstCaps &) = default;
+ QGstCaps &operator=(QGstCaps &&) noexcept = default;
+
+ enum MemoryFormat { CpuMemory, GLTexture, DMABuf };
+
+ int size() const;
+ QGstStructureView at(int index) const;
+ GstCaps *caps() const;
+
+ MemoryFormat memoryFormat() const;
+ std::optional<std::pair<QVideoFrameFormat, GstVideoInfo>> formatAndVideoInfo() const;
+
+ void addPixelFormats(const QList<QVideoFrameFormat::PixelFormat> &formats, const char *modifier = nullptr);
+ void setResolution(QSize);
+
+ static QGstCaps create();
+
+ static QGstCaps fromCameraFormat(const QCameraFormat &format);
+
+ QGstCaps copy() const;
+};
+
+template <>
+struct QGstPointerImpl::QGstRefcountingAdaptor<GstObject>
+{
+ static void ref(GstObject *arg) noexcept { gst_object_ref_sink(arg); }
+ static void unref(GstObject *arg) noexcept { gst_object_unref(arg); }
+};
+
+class QGObjectHandlerConnection;
+
+class QGstObject : public QGstPointerImpl::QGstObjectWrapper<GstObject>
+{
+ using BaseClass = QGstPointerImpl::QGstObjectWrapper<GstObject>;
+
+public:
+ using BaseClass::BaseClass;
+ QGstObject(const QGstObject &) = default;
+ QGstObject(QGstObject &&) noexcept = default;
+
+ QGstObject &operator=(const QGstObject &) = default;
+ QGstObject &operator=(QGstObject &&) noexcept = default;
+
+ void set(const char *property, const char *str);
+ void set(const char *property, bool b);
+ void set(const char *property, uint i);
+ void set(const char *property, int i);
+ void set(const char *property, qint64 i);
+ void set(const char *property, quint64 i);
+ void set(const char *property, double d);
+ void set(const char *property, const QGstObject &o);
+ void set(const char *property, const QGstCaps &c);
+
+ QGString getString(const char *property) const;
+ QGstStructureView getStructure(const char *property) const;
+ bool getBool(const char *property) const;
+ uint getUInt(const char *property) const;
+ int getInt(const char *property) const;
+ quint64 getUInt64(const char *property) const;
+ qint64 getInt64(const char *property) const;
+ float getFloat(const char *property) const;
+ double getDouble(const char *property) const;
+ QGstObject getObject(const char *property) const;
+
+ QGObjectHandlerConnection connect(const char *name, GCallback callback, gpointer userData);
+ void disconnect(gulong handlerId);
+
+ GType type() const;
+ QLatin1StringView typeName() const;
+ GstObject *object() const;
+ QLatin1StringView name() const;
+};
+
+class QGObjectHandlerConnection
+{
+public:
+ QGObjectHandlerConnection(QGstObject object, gulong handler);
+
+ QGObjectHandlerConnection() = default;
+ QGObjectHandlerConnection(const QGObjectHandlerConnection &) = default;
+ QGObjectHandlerConnection(QGObjectHandlerConnection &&) = default;
+ QGObjectHandlerConnection &operator=(const QGObjectHandlerConnection &) = default;
+ QGObjectHandlerConnection &operator=(QGObjectHandlerConnection &&) = default;
+
+ void disconnect();
+
+private:
+ static constexpr gulong invalidHandlerId = std::numeric_limits<gulong>::max();
+
+ QGstObject object;
+ gulong handlerId = invalidHandlerId;
+};
+
+// disconnects in dtor
+class QGObjectHandlerScopedConnection
+{
+public:
+ QGObjectHandlerScopedConnection(QGObjectHandlerConnection connection);
+
+ QGObjectHandlerScopedConnection() = default;
+ QGObjectHandlerScopedConnection(const QGObjectHandlerScopedConnection &) = delete;
+ QGObjectHandlerScopedConnection &operator=(const QGObjectHandlerScopedConnection &) = delete;
+ QGObjectHandlerScopedConnection(QGObjectHandlerScopedConnection &&) = default;
+ QGObjectHandlerScopedConnection &operator=(QGObjectHandlerScopedConnection &&) = default;
+
+ ~QGObjectHandlerScopedConnection();
+
+ void disconnect();
+
+private:
+ QGObjectHandlerConnection connection;
+};
+
+class QGstElement;
+
+class QGstPad : public QGstObject
+{
+public:
+ using QGstObject::QGstObject;
+ QGstPad(const QGstPad &) = default;
+ QGstPad(QGstPad &&) noexcept = default;
+
+ explicit QGstPad(const QGstObject &o);
+ explicit QGstPad(GstPad *pad, RefMode mode);
+
+ QGstPad &operator=(const QGstPad &) = default;
+ QGstPad &operator=(QGstPad &&) noexcept = default;
+
+ QGstCaps currentCaps() const;
+ QGstCaps queryCaps() const;
+
+ QGstTagListHandle tags() const;
+
+ std::optional<QPlatformMediaPlayer::TrackType>
+ inferTrackTypeFromName() const; // for decodebin3 etc
+
+ bool isLinked() const;
+ bool link(const QGstPad &sink) const;
+ bool unlink(const QGstPad &sink) const;
+ bool unlinkPeer() const;
+ QGstPad peer() const;
+ QGstElement parent() const;
+
+ GstPad *pad() const;
+
+ GstEvent *stickyEvent(GstEventType type);
+ bool sendEvent(GstEvent *event);
+
+ template<auto Member, typename T>
+ void addProbe(T *instance, GstPadProbeType type) {
+ auto callback = [](GstPad *pad, GstPadProbeInfo *info, gpointer userData) {
+ return (static_cast<T *>(userData)->*Member)(QGstPad(pad, NeedsRef), info);
+ };
+
+ gst_pad_add_probe(pad(), type, callback, instance, nullptr);
+ }
+
+ template <typename Functor>
+ void doInIdleProbe(Functor &&work)
+ {
+ struct CallbackData {
+ QSemaphore waitDone;
+ Functor work;
+ };
+
+ CallbackData cd{
+ .waitDone = QSemaphore{},
+ .work = std::forward<Functor>(work),
+ };
+
+ auto callback= [](GstPad *, GstPadProbeInfo *, gpointer p) {
+ auto cd = reinterpret_cast<CallbackData*>(p);
+ cd->work();
+ cd->waitDone.release();
+ return GST_PAD_PROBE_REMOVE;
+ };
+
+ gst_pad_add_probe(pad(), GST_PAD_PROBE_TYPE_IDLE, callback, &cd, nullptr);
+ cd.waitDone.acquire();
+ }
+
+ template<auto Member, typename T>
+ void addEosProbe(T *instance) {
+ auto callback = [](GstPad *, GstPadProbeInfo *info, gpointer userData) {
+ if (GST_EVENT_TYPE(GST_PAD_PROBE_INFO_DATA(info)) != GST_EVENT_EOS)
+ return GST_PAD_PROBE_PASS;
+ (static_cast<T *>(userData)->*Member)();
+ return GST_PAD_PROBE_REMOVE;
+ };
+
+ gst_pad_add_probe(pad(), GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, callback, instance, nullptr);
+ }
+};
+
+class QGstClock : public QGstObject
+{
+public:
+ QGstClock() = default;
+ explicit QGstClock(const QGstObject &o);
+ explicit QGstClock(GstClock *clock, RefMode mode);
+
+ GstClock *clock() const;
+ GstClockTime time() const;
+};
+
+class QGstPipeline;
+
+class QGstElement : public QGstObject
+{
+public:
+ using QGstObject::QGstObject;
+
+ QGstElement(const QGstElement &) = default;
+ QGstElement(QGstElement &&) noexcept = default;
+ QGstElement &operator=(const QGstElement &) = default;
+ QGstElement &operator=(QGstElement &&) noexcept = default;
+
+ explicit QGstElement(GstElement *element, RefMode mode);
+ static QGstElement createFromFactory(const char *factory, const char *name = nullptr);
+ static QGstElement createFromFactory(GstElementFactory *, const char *name = nullptr);
+ static QGstElement createFromFactory(const QGstElementFactoryHandle &,
+ const char *name = nullptr);
+ static QGstElement createFromDevice(const QGstDeviceHandle &, const char *name = nullptr);
+ static QGstElement createFromDevice(GstDevice *, const char *name = nullptr);
+ static QGstElement createFromPipelineDescription(const char *);
+ static QGstElement createFromPipelineDescription(const QByteArray &);
+
+ static QGstElementFactoryHandle findFactory(const char *);
+ static QGstElementFactoryHandle findFactory(const QByteArray &name);
+
+ QGstPad staticPad(const char *name) const;
+ QGstPad src() const;
+ QGstPad sink() const;
+ QGstPad getRequestPad(const char *name) const;
+ void releaseRequestPad(const QGstPad &pad) const;
+
+ GstState state(std::chrono::nanoseconds timeout = std::chrono::seconds(0)) const;
+ GstStateChangeReturn setState(GstState state);
+ bool setStateSync(GstState state, std::chrono::nanoseconds timeout = std::chrono::seconds(1));
+ bool syncStateWithParent();
+ bool finishStateChange(std::chrono::nanoseconds timeout = std::chrono::seconds(5));
+
+ void lockState(bool locked);
+ bool isStateLocked() const;
+
+ void sendEvent(GstEvent *event) const;
+ void sendEos() const;
+
+ template <auto Member, typename T>
+ QGObjectHandlerConnection onPadAdded(T *instance)
+ {
+ struct Impl
+ {
+ static void callback(GstElement *e, GstPad *pad, gpointer userData)
+ {
+ (static_cast<T *>(userData)->*Member)(QGstElement(e, NeedsRef),
+ QGstPad(pad, NeedsRef));
+ };
+ };
+
+ return connect("pad-added", G_CALLBACK(Impl::callback), instance);
+ }
+ template <auto Member, typename T>
+ QGObjectHandlerConnection onPadRemoved(T *instance)
+ {
+ struct Impl
+ {
+ static void callback(GstElement *e, GstPad *pad, gpointer userData)
+ {
+ (static_cast<T *>(userData)->*Member)(QGstElement(e, NeedsRef),
+ QGstPad(pad, NeedsRef));
+ };
+ };
+
+ return connect("pad-removed", G_CALLBACK(Impl::callback), instance);
+ }
+ template <auto Member, typename T>
+ QGObjectHandlerConnection onNoMorePads(T *instance)
+ {
+ struct Impl
+ {
+ static void callback(GstElement *e, gpointer userData)
+ {
+ (static_cast<T *>(userData)->*Member)(QGstElement(e, NeedsRef));
+ };
+ };
+
+ return connect("no-more-pads", G_CALLBACK(Impl::callback), instance);
+ }
+
+ GstClockTime baseTime() const;
+ void setBaseTime(GstClockTime time) const;
+
+ GstElement *element() const;
+
+ QGstElement getParent() const;
+ QGstPipeline getPipeline() const;
+ void dumpPipelineGraph(const char *filename) const;
+};
+
+template <typename... Ts>
+std::enable_if_t<(std::is_base_of_v<QGstElement, Ts> && ...), void>
+qLinkGstElements(const Ts &...ts)
+{
+ bool link_success = [&] {
+ if constexpr (sizeof...(Ts) == 2)
+ return gst_element_link(ts.element()...);
+ else
+ return gst_element_link_many(ts.element()..., nullptr);
+ }();
+
+ if (Q_UNLIKELY(!link_success)) {
+ qWarning() << "qLinkGstElements: could not link elements: "
+ << std::initializer_list<const char *>{
+ (GST_ELEMENT_NAME(ts.element()))...,
+ };
+ }
+}
+
+template <typename... Ts>
+std::enable_if_t<(std::is_base_of_v<QGstElement, Ts> && ...), void>
+qUnlinkGstElements(const Ts &...ts)
+{
+ if constexpr (sizeof...(Ts) == 2)
+ gst_element_unlink(ts.element()...);
+ else
+ gst_element_unlink_many(ts.element()..., nullptr);
+}
+
+class QGstBin : public QGstElement
+{
+public:
+ using QGstElement::QGstElement;
+ QGstBin(const QGstBin &) = default;
+ QGstBin(QGstBin &&) noexcept = default;
+ QGstBin &operator=(const QGstBin &) = default;
+ QGstBin &operator=(QGstBin &&) noexcept = default;
+
+ explicit QGstBin(GstBin *bin, RefMode mode = NeedsRef);
+ static QGstBin create(const char *name);
+ static QGstBin createFromFactory(const char *factory, const char *name);
+ static QGstBin createFromPipelineDescription(const QByteArray &pipelineDescription,
+ const char *name = nullptr,
+ bool ghostUnlinkedPads = false);
+ static QGstBin createFromPipelineDescription(const char *pipelineDescription,
+ const char *name = nullptr,
+ bool ghostUnlinkedPads = false);
+
+ template <typename... Ts>
+ std::enable_if_t<(std::is_base_of_v<QGstElement, Ts> && ...), void> add(const Ts &...ts)
+ {
+ if constexpr (sizeof...(Ts) == 1)
+ gst_bin_add(bin(), ts.element()...);
+ else
+ gst_bin_add_many(bin(), ts.element()..., nullptr);
+ }
+
+ template <typename... Ts>
+ std::enable_if_t<(std::is_base_of_v<QGstElement, Ts> && ...), void> remove(const Ts &...ts)
+ {
+ if constexpr (sizeof...(Ts) == 1)
+ gst_bin_remove(bin(), ts.element()...);
+ else
+ gst_bin_remove_many(bin(), ts.element()..., nullptr);
+ }
+
+ template <typename... Ts>
+ std::enable_if_t<(std::is_base_of_v<QGstElement, Ts> && ...), void>
+ stopAndRemoveElements(Ts... ts)
+ {
+ bool stateChangeSuccessful = (ts.setStateSync(GST_STATE_NULL) && ...);
+ Q_ASSERT(stateChangeSuccessful);
+ remove(ts...);
+ }
+
+ GstBin *bin() const;
+
+ void addGhostPad(const QGstElement &child, const char *name);
+ void addGhostPad(const char *name, const QGstPad &pad);
+
+ bool syncChildrenState();
+
+ void dumpGraph(const char *fileNamePrefix);
+
+ QGstElement findByName(const char *);
+};
+
+class QGstBaseSink : public QGstElement
+{
+public:
+ using QGstElement::QGstElement;
+
+ explicit QGstBaseSink(GstBaseSink *, RefMode);
+
+ QGstBaseSink(const QGstBaseSink &) = default;
+ QGstBaseSink(QGstBaseSink &&) noexcept = default;
+ QGstBaseSink &operator=(const QGstBaseSink &) = default;
+ QGstBaseSink &operator=(QGstBaseSink &&) noexcept = default;
+
+ void setSync(bool);
+
+ GstBaseSink *baseSink() const;
+};
+
+class QGstBaseSrc : public QGstElement
+{
+public:
+ using QGstElement::QGstElement;
+
+ explicit QGstBaseSrc(GstBaseSrc *, RefMode);
+
+ QGstBaseSrc(const QGstBaseSrc &) = default;
+ QGstBaseSrc(QGstBaseSrc &&) noexcept = default;
+ QGstBaseSrc &operator=(const QGstBaseSrc &) = default;
+ QGstBaseSrc &operator=(QGstBaseSrc &&) noexcept = default;
+
+ GstBaseSrc *baseSrc() const;
+};
+
+#if QT_CONFIG(gstreamer_app)
+class QGstAppSink : public QGstBaseSink
+{
+public:
+ using QGstBaseSink::QGstBaseSink;
+
+ explicit QGstAppSink(GstAppSink *, RefMode);
+
+ QGstAppSink(const QGstAppSink &) = default;
+ QGstAppSink(QGstAppSink &&) noexcept = default;
+ QGstAppSink &operator=(const QGstAppSink &) = default;
+ QGstAppSink &operator=(QGstAppSink &&) noexcept = default;
+
+ static QGstAppSink create(const char *name);
+
+ GstAppSink *appSink() const;
+
+ void setMaxBuffers(int);
+# if GST_CHECK_VERSION(1, 24, 0)
+ void setMaxBufferTime(std::chrono::nanoseconds);
+# endif
+
+ void setCaps(const QGstCaps &caps);
+ void setCallbacks(GstAppSinkCallbacks &callbacks, gpointer user_data, GDestroyNotify notify);
+
+ QGstSampleHandle pullSample();
+};
+
+class QGstAppSrc : public QGstBaseSrc
+{
+public:
+ using QGstBaseSrc::QGstBaseSrc;
+
+ explicit QGstAppSrc(GstAppSrc *, RefMode);
+
+ QGstAppSrc(const QGstAppSrc &) = default;
+ QGstAppSrc(QGstAppSrc &&) noexcept = default;
+ QGstAppSrc &operator=(const QGstAppSrc &) = default;
+ QGstAppSrc &operator=(QGstAppSrc &&) noexcept = default;
+
+ static QGstAppSrc create(const char *name);
+
+ GstAppSrc *appSrc() const;
+
+ void setCallbacks(GstAppSrcCallbacks &callbacks, gpointer user_data, GDestroyNotify notify);
+
+ GstFlowReturn pushBuffer(GstBuffer *); // take ownership
+};
+
+#endif
+
+inline GstClockTime qGstClockTimeFromChrono(std::chrono::nanoseconds ns)
+{
+ return ns.count();
+}
+
+QString qGstErrorMessageCannotFindElement(std::string_view element);
+
+template <typename Arg, typename... Args>
+std::optional<QString> qGstErrorMessageIfElementsNotAvailable(const Arg &arg, Args... args)
+{
+ QGstElementFactoryHandle factory = QGstElement::findFactory(arg);
+ if (!factory)
+ return qGstErrorMessageCannotFindElement(arg);
+
+ if constexpr (sizeof...(args) != 0)
+ return qGstErrorMessageIfElementsNotAvailable(args...);
+ else
+ return std::nullopt;
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstappsource.cpp b/src/plugins/multimedia/gstreamer/common/qgstappsource.cpp
new file mode 100644
index 000000000..3c345de82
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstappsource.cpp
@@ -0,0 +1,319 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QDebug>
+
+#include "qgstappsource_p.h"
+#include <common/qgstutils_p.h>
+#include "qnetworkreply.h"
+#include "qloggingcategory.h"
+
+static Q_LOGGING_CATEGORY(qLcAppSrc, "qt.multimedia.appsrc")
+
+QT_BEGIN_NAMESPACE
+
+QMaybe<QGstAppSource *> QGstAppSource::create(QObject *parent)
+{
+ QGstAppSrc appsrc = QGstAppSrc::create("appsrc");
+ if (!appsrc)
+ return qGstErrorMessageCannotFindElement("appsrc");
+
+ return new QGstAppSource(appsrc, parent);
+}
+
+QGstAppSource::QGstAppSource(QGstAppSrc appsrc, QObject *parent)
+ : QObject(parent), m_appSrc(std::move(appsrc))
+{
+ m_appSrc.set("emit-signals", false);
+}
+
+QGstAppSource::~QGstAppSource()
+{
+ m_appSrc.setStateSync(GST_STATE_NULL);
+ streamDestroyed();
+ qCDebug(qLcAppSrc) << "~QGstAppSrc";
+}
+
+bool QGstAppSource::setup(QIODevice *stream, qint64 offset)
+{
+ QMutexLocker locker(&m_mutex);
+
+ if (m_appSrc.isNull())
+ return false;
+
+ if (!setStream(stream, offset))
+ return false;
+
+ GstAppSrcCallbacks callbacks{};
+ callbacks.need_data = QGstAppSource::on_need_data;
+ callbacks.enough_data = QGstAppSource::on_enough_data;
+ callbacks.seek_data = QGstAppSource::on_seek_data;
+
+ m_appSrc.setCallbacks(callbacks, this, nullptr);
+
+ GstAppSrc *appSrc = m_appSrc.appSrc();
+ m_maxBytes = gst_app_src_get_max_bytes(appSrc);
+ m_suspended = false;
+
+ if (m_sequential)
+ m_streamType = GST_APP_STREAM_TYPE_STREAM;
+ else
+ m_streamType = GST_APP_STREAM_TYPE_RANDOM_ACCESS;
+ gst_app_src_set_stream_type(appSrc, m_streamType);
+ gst_app_src_set_size(appSrc, m_sequential ? -1 : m_stream->size() - m_offset);
+
+ m_noMoreData = true;
+
+ return true;
+}
+
+void QGstAppSource::setAudioFormat(const QAudioFormat &f)
+{
+ QMutexLocker locker(&m_mutex);
+
+ m_format = f;
+ if (!m_format.isValid())
+ return;
+
+ auto caps = QGstUtils::capsForAudioFormat(m_format);
+ Q_ASSERT(!caps.isNull());
+ m_appSrc.set("caps", caps);
+ m_appSrc.set("format", GST_FORMAT_TIME);
+}
+
+void QGstAppSource::setExternalAppSrc(QGstAppSrc appsrc)
+{
+ QMutexLocker locker(&m_mutex);
+ m_appSrc = std::move(appsrc);
+}
+
+bool QGstAppSource::setStream(QIODevice *stream, qint64 offset)
+{
+ if (m_stream) {
+ disconnect(m_stream, &QIODevice::readyRead, this, &QGstAppSource::onDataReady);
+ disconnect(m_stream, &QIODevice::destroyed, this, &QGstAppSource::streamDestroyed);
+ m_stream = nullptr;
+ }
+
+ m_dataRequestSize = 0;
+ m_sequential = true;
+ m_maxBytes = 0;
+ streamedSamples = 0;
+
+ if (stream) {
+ if (!stream->isOpen() && !stream->open(QIODevice::ReadOnly))
+ return false;
+ m_stream = stream;
+ connect(m_stream, &QIODevice::destroyed, this, &QGstAppSource::streamDestroyed);
+ connect(m_stream, &QIODevice::readyRead, this, &QGstAppSource::onDataReady);
+ m_sequential = m_stream->isSequential();
+ m_offset = offset;
+ }
+ return true;
+}
+
+bool QGstAppSource::isStreamValid() const
+{
+ return m_stream != nullptr && m_stream->isOpen();
+}
+
+QGstElement QGstAppSource::element() const
+{
+ return m_appSrc;
+}
+
+void QGstAppSource::write(const char *data, qsizetype size)
+{
+ QMutexLocker locker(&m_mutex);
+
+ qCDebug(qLcAppSrc) << "write" << size << m_noMoreData << m_dataRequestSize;
+ if (!size)
+ return;
+ Q_ASSERT(!m_stream);
+ m_buffer.append(data, size);
+ m_noMoreData = false;
+ pushData();
+}
+
+bool QGstAppSource::canAcceptMoreData() const
+{
+ QMutexLocker locker(&m_mutex);
+ return m_noMoreData || m_dataRequestSize != 0;
+}
+
+void QGstAppSource::suspend()
+{
+ QMutexLocker locker(&m_mutex);
+ m_suspended = true;
+}
+
+void QGstAppSource::resume()
+{
+ QMutexLocker locker(&m_mutex);
+ m_suspended = false;
+ m_noMoreData = true;
+}
+
+void QGstAppSource::onDataReady()
+{
+ qCDebug(qLcAppSrc) << "onDataReady" << m_stream->bytesAvailable() << m_stream->size();
+ pushData();
+}
+
+void QGstAppSource::streamDestroyed()
+{
+ qCDebug(qLcAppSrc) << "stream destroyed";
+ m_stream = nullptr;
+ m_dataRequestSize = 0;
+ streamedSamples = 0;
+ sendEOS();
+}
+
+void QGstAppSource::pushData()
+{
+ if (m_appSrc.isNull() || !m_dataRequestSize || m_suspended) {
+ qCDebug(qLcAppSrc) << "push data: return immediately" << m_appSrc.isNull() << m_dataRequestSize << m_suspended;
+ return;
+ }
+
+ qCDebug(qLcAppSrc) << "pushData" << (m_stream ? m_stream : nullptr) << m_buffer.size();
+ if ((m_stream && m_stream->atEnd())) {
+ eosOrIdle();
+ qCDebug(qLcAppSrc) << "end pushData" << (m_stream ? m_stream : nullptr) << m_buffer.size();
+ return;
+ }
+
+ qint64 size;
+ if (m_stream)
+ size = m_stream->bytesAvailable();
+ else
+ size = m_buffer.size();
+
+ if (!m_dataRequestSize)
+ m_dataRequestSize = m_maxBytes;
+ size = qMin(size, (qint64)m_dataRequestSize);
+ qCDebug(qLcAppSrc) << " reading" << size << "bytes" << size << m_dataRequestSize;
+
+ GstBuffer* buffer = gst_buffer_new_and_alloc(size);
+
+ if (m_sequential || !m_stream)
+ buffer->offset = bytesReadSoFar;
+ else
+ buffer->offset = m_stream->pos();
+
+ if (m_format.isValid()) {
+ // timestamp raw audio data
+ uint nSamples = size/m_format.bytesPerFrame();
+
+ GST_BUFFER_TIMESTAMP(buffer) = gst_util_uint64_scale(streamedSamples, GST_SECOND, m_format.sampleRate());
+ GST_BUFFER_DURATION(buffer) = gst_util_uint64_scale(nSamples, GST_SECOND, m_format.sampleRate());
+ streamedSamples += nSamples;
+ }
+
+ GstMapInfo mapInfo;
+ gst_buffer_map(buffer, &mapInfo, GST_MAP_WRITE);
+ void* bufferData = mapInfo.data;
+
+ qint64 bytesRead;
+ if (m_stream)
+ bytesRead = m_stream->read((char*)bufferData, size);
+ else
+ bytesRead = m_buffer.read((char*)bufferData, size);
+ buffer->offset_end = buffer->offset + bytesRead - 1;
+ bytesReadSoFar += bytesRead;
+
+ gst_buffer_unmap(buffer, &mapInfo);
+ qCDebug(qLcAppSrc) << "pushing bytes into gstreamer" << buffer->offset << bytesRead;
+ if (bytesRead == 0) {
+ gst_buffer_unref(buffer);
+ eosOrIdle();
+ qCDebug(qLcAppSrc) << "end pushData" << (m_stream ? m_stream : nullptr) << m_buffer.size();
+ return;
+ }
+ m_noMoreData = false;
+ emit bytesProcessed(bytesRead);
+
+ GstFlowReturn ret = m_appSrc.pushBuffer(buffer);
+ if (ret == GST_FLOW_ERROR) {
+ qWarning() << "QGstAppSrc: push buffer error";
+ } else if (ret == GST_FLOW_FLUSHING) {
+ qWarning() << "QGstAppSrc: push buffer wrong state";
+ }
+ qCDebug(qLcAppSrc) << "end pushData" << (m_stream ? m_stream : nullptr) << m_buffer.size();
+
+}
+
+bool QGstAppSource::doSeek(qint64 value)
+{
+ if (isStreamValid())
+ return m_stream->seek(value + m_offset);
+ return false;
+}
+
+gboolean QGstAppSource::on_seek_data(GstAppSrc *, guint64 arg0, gpointer userdata)
+{
+ // we do get some spurious seeks to INT_MAX, ignore those
+ if (arg0 == std::numeric_limits<quint64>::max())
+ return true;
+
+ QGstAppSource *self = reinterpret_cast<QGstAppSource *>(userdata);
+ Q_ASSERT(self);
+
+ QMutexLocker locker(&self->m_mutex);
+
+ if (self->m_sequential)
+ return false;
+
+ self->doSeek(arg0);
+ return true;
+}
+
+void QGstAppSource::on_enough_data(GstAppSrc *, gpointer userdata)
+{
+ qCDebug(qLcAppSrc) << "on_enough_data";
+ QGstAppSource *self = static_cast<QGstAppSource *>(userdata);
+ Q_ASSERT(self);
+ QMutexLocker locker(&self->m_mutex);
+ self->m_dataRequestSize = 0;
+}
+
+void QGstAppSource::on_need_data(GstAppSrc *, guint arg0, gpointer userdata)
+{
+ qCDebug(qLcAppSrc) << "on_need_data requesting bytes" << arg0;
+ QGstAppSource *self = static_cast<QGstAppSource *>(userdata);
+ Q_ASSERT(self);
+ QMutexLocker locker(&self->m_mutex);
+ self->m_dataRequestSize = arg0;
+ self->pushData();
+ qCDebug(qLcAppSrc) << "done on_need_data";
+}
+
+void QGstAppSource::sendEOS()
+{
+ qCDebug(qLcAppSrc) << "sending EOS";
+ if (m_appSrc.isNull())
+ return;
+
+ gst_app_src_end_of_stream(GST_APP_SRC(m_appSrc.element()));
+}
+
+void QGstAppSource::eosOrIdle()
+{
+ qCDebug(qLcAppSrc) << "eosOrIdle";
+ if (m_appSrc.isNull())
+ return;
+
+ if (!m_sequential) {
+ sendEOS();
+ return;
+ }
+ if (m_noMoreData)
+ return;
+ qCDebug(qLcAppSrc) << " idle!";
+ m_noMoreData = true;
+ emit noMoreData();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qgstappsource_p.cpp"
diff --git a/src/plugins/multimedia/gstreamer/common/qgstappsource_p.h b/src/plugins/multimedia/gstreamer/common/qgstappsource_p.h
new file mode 100644
index 000000000..59ced00dc
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstappsource_p.h
@@ -0,0 +1,96 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTAPPSRC_H
+#define QGSTAPPSRC_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <private/qmultimediautils_p.h>
+#include <qaudioformat.h>
+
+#include <QtCore/qobject.h>
+#include <QtCore/qiodevice.h>
+#include <QtCore/private/qringbuffer_p.h>
+#include <QtCore/qatomic.h>
+#include <QtCore/qmutex.h>
+
+#include <common/qgst_p.h>
+#include <gst/app/gstappsrc.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstAppSource : public QObject
+{
+ Q_OBJECT
+public:
+ static QMaybe<QGstAppSource *> create(QObject *parent = nullptr);
+ ~QGstAppSource();
+
+ bool setup(QIODevice *stream = nullptr, qint64 offset = 0);
+ void setAudioFormat(const QAudioFormat &f);
+
+ void setExternalAppSrc(QGstAppSrc);
+ QGstElement element() const;
+
+ void write(const char *data, qsizetype size);
+
+ bool canAcceptMoreData() const;
+
+ void suspend();
+ void resume();
+
+Q_SIGNALS:
+ void bytesProcessed(int bytes);
+ void noMoreData();
+
+private Q_SLOTS:
+ void pushData();
+ bool doSeek(qint64);
+ void onDataReady();
+
+ void streamDestroyed();
+private:
+ QGstAppSource(QGstAppSrc appsrc, QObject *parent);
+
+ bool setStream(QIODevice *, qint64 offset);
+ bool isStreamValid() const;
+
+ static gboolean on_seek_data(GstAppSrc *element, guint64 arg0, gpointer userdata);
+ static void on_enough_data(GstAppSrc *element, gpointer userdata);
+ static void on_need_data(GstAppSrc *element, uint arg0, gpointer userdata);
+
+ void sendEOS();
+ void eosOrIdle();
+
+ mutable QMutex m_mutex;
+
+ QIODevice *m_stream = nullptr;
+ QRingBuffer m_buffer;
+ QAudioFormat m_format;
+
+ QGstAppSrc m_appSrc;
+ bool m_sequential = true;
+ bool m_suspended = false;
+ bool m_noMoreData = false;
+ GstAppStreamType m_streamType = GST_APP_STREAM_TYPE_RANDOM_ACCESS;
+ qint64 m_offset = 0;
+ qint64 m_maxBytes = 0;
+ qint64 bytesReadSoFar = 0;
+ QAtomicInteger<unsigned int> m_dataRequestSize = 0;
+ int streamedSamples = 0;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstpipeline.cpp b/src/plugins/multimedia/gstreamer/common/qgstpipeline.cpp
new file mode 100644
index 000000000..16b0e28a9
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstpipeline.cpp
@@ -0,0 +1,425 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtCore/qmap.h>
+#include <QtCore/qtimer.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qabstracteventdispatcher.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qproperty.h>
+
+#include "qgstpipeline_p.h"
+#include "qgstreamermessage_p.h"
+
+QT_BEGIN_NAMESPACE
+
+static constexpr GstSeekFlags rateChangeSeekFlags =
+#if GST_CHECK_VERSION(1, 18, 0)
+ GST_SEEK_FLAG_INSTANT_RATE_CHANGE;
+#else
+ GST_SEEK_FLAG_FLUSH;
+#endif
+
+class QGstPipelinePrivate : public QObject
+{
+public:
+ int m_ref = 0;
+ guint m_tag = 0;
+ GstBus *m_bus = nullptr;
+ QTimer *m_intervalTimer = nullptr;
+ QMutex filterMutex;
+ QList<QGstreamerSyncMessageFilter*> syncFilters;
+ QList<QGstreamerBusMessageFilter*> busFilters;
+ bool inStoppedState = true;
+ mutable std::chrono::nanoseconds m_position{};
+ double m_rate = 1.;
+ bool m_flushOnConfigChanges = false;
+ bool m_pendingFlush = false;
+
+ int m_configCounter = 0;
+ GstState m_savedState = GST_STATE_NULL;
+
+ explicit QGstPipelinePrivate(GstBus *bus, QObject *parent = nullptr);
+ ~QGstPipelinePrivate();
+
+ void ref() { ++ m_ref; }
+ void deref() { if (!--m_ref) delete this; }
+
+ void installMessageFilter(QGstreamerSyncMessageFilter *filter);
+ void removeMessageFilter(QGstreamerSyncMessageFilter *filter);
+ void installMessageFilter(QGstreamerBusMessageFilter *filter);
+ void removeMessageFilter(QGstreamerBusMessageFilter *filter);
+
+ void processMessage(const QGstreamerMessage &msg)
+ {
+ for (QGstreamerBusMessageFilter *filter : std::as_const(busFilters)) {
+ if (filter->processBusMessage(msg))
+ break;
+ }
+ }
+
+private:
+ static GstBusSyncReply syncGstBusFilter(GstBus *bus, GstMessage *message,
+ QGstPipelinePrivate *d)
+ {
+ if (!message)
+ return GST_BUS_PASS;
+
+ Q_UNUSED(bus);
+ QMutexLocker lock(&d->filterMutex);
+
+ for (QGstreamerSyncMessageFilter *filter : std::as_const(d->syncFilters)) {
+ if (filter->processSyncMessage(
+ QGstreamerMessage{ message, QGstreamerMessage::NeedsRef })) {
+ gst_message_unref(message);
+ return GST_BUS_DROP;
+ }
+ }
+
+ return GST_BUS_PASS;
+ }
+
+ void processMessage(GstMessage *message)
+ {
+ if (!message)
+ return;
+
+ QGstreamerMessage msg{
+ message,
+ QGstreamerMessage::NeedsRef,
+ };
+
+ processMessage(msg);
+ }
+
+ static gboolean busCallback(GstBus *, GstMessage *message, gpointer data)
+ {
+ static_cast<QGstPipelinePrivate *>(data)->processMessage(message);
+ return TRUE;
+ }
+};
+
+QGstPipelinePrivate::QGstPipelinePrivate(GstBus* bus, QObject* parent)
+ : QObject(parent),
+ m_bus(bus)
+{
+ // glib event loop can be disabled either by env variable or QT_NO_GLIB define, so check the dispacher
+ QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher();
+ const bool hasGlib = dispatcher && dispatcher->inherits("QEventDispatcherGlib");
+ if (!hasGlib) {
+ m_intervalTimer = new QTimer(this);
+ m_intervalTimer->setInterval(250);
+ QObject::connect(m_intervalTimer, &QTimer::timeout, this, [this] {
+ GstMessage *message;
+ while ((message = gst_bus_poll(m_bus, GST_MESSAGE_ANY, 0)) != nullptr) {
+ processMessage(message);
+ gst_message_unref(message);
+ }
+ });
+ m_intervalTimer->start();
+ } else {
+ m_tag = gst_bus_add_watch_full(bus, G_PRIORITY_DEFAULT, busCallback, this, nullptr);
+ }
+
+ gst_bus_set_sync_handler(bus, (GstBusSyncHandler)syncGstBusFilter, this, nullptr);
+}
+
+QGstPipelinePrivate::~QGstPipelinePrivate()
+{
+ delete m_intervalTimer;
+
+ if (m_tag)
+ gst_bus_remove_watch(m_bus);
+
+ gst_bus_set_sync_handler(m_bus, nullptr, nullptr, nullptr);
+ gst_object_unref(GST_OBJECT(m_bus));
+}
+
+void QGstPipelinePrivate::installMessageFilter(QGstreamerSyncMessageFilter *filter)
+{
+ if (filter) {
+ QMutexLocker lock(&filterMutex);
+ if (!syncFilters.contains(filter))
+ syncFilters.append(filter);
+ }
+}
+
+void QGstPipelinePrivate::removeMessageFilter(QGstreamerSyncMessageFilter *filter)
+{
+ if (filter) {
+ QMutexLocker lock(&filterMutex);
+ syncFilters.removeAll(filter);
+ }
+}
+
+void QGstPipelinePrivate::installMessageFilter(QGstreamerBusMessageFilter *filter)
+{
+ if (filter && !busFilters.contains(filter))
+ busFilters.append(filter);
+}
+
+void QGstPipelinePrivate::removeMessageFilter(QGstreamerBusMessageFilter *filter)
+{
+ if (filter)
+ busFilters.removeAll(filter);
+}
+
+QGstPipeline QGstPipeline::create(const char *name)
+{
+ GstPipeline *pipeline = qGstCheckedCast<GstPipeline>(gst_pipeline_new(name));
+ return adopt(pipeline);
+}
+
+QGstPipeline QGstPipeline::adopt(GstPipeline *pipeline)
+{
+ QGstPipelinePrivate *d = new QGstPipelinePrivate(gst_pipeline_get_bus(pipeline));
+ g_object_set_data_full(qGstCheckedCast<GObject>(pipeline), "pipeline-private", d,
+ [](gpointer ptr) {
+ delete reinterpret_cast<QGstPipelinePrivate *>(ptr);
+ return;
+ });
+
+ return QGstPipeline{
+ pipeline,
+ QGstPipeline::NeedsRef,
+ };
+}
+
+QGstPipeline::QGstPipeline(GstPipeline *p, RefMode mode) : QGstBin(qGstCheckedCast<GstBin>(p), mode)
+{
+}
+
+QGstPipeline::~QGstPipeline() = default;
+
+bool QGstPipeline::inStoppedState() const
+{
+ QGstPipelinePrivate *d = getPrivate();
+ return d->inStoppedState;
+}
+
+void QGstPipeline::setInStoppedState(bool stopped)
+{
+ QGstPipelinePrivate *d = getPrivate();
+ d->inStoppedState = stopped;
+}
+
+void QGstPipeline::setFlushOnConfigChanges(bool flush)
+{
+ QGstPipelinePrivate *d = getPrivate();
+ d->m_flushOnConfigChanges = flush;
+}
+
+void QGstPipeline::installMessageFilter(QGstreamerSyncMessageFilter *filter)
+{
+ QGstPipelinePrivate *d = getPrivate();
+ d->installMessageFilter(filter);
+}
+
+void QGstPipeline::removeMessageFilter(QGstreamerSyncMessageFilter *filter)
+{
+ QGstPipelinePrivate *d = getPrivate();
+ d->removeMessageFilter(filter);
+}
+
+void QGstPipeline::installMessageFilter(QGstreamerBusMessageFilter *filter)
+{
+ QGstPipelinePrivate *d = getPrivate();
+ d->installMessageFilter(filter);
+}
+
+void QGstPipeline::removeMessageFilter(QGstreamerBusMessageFilter *filter)
+{
+ QGstPipelinePrivate *d = getPrivate();
+ d->removeMessageFilter(filter);
+}
+
+GstStateChangeReturn QGstPipeline::setState(GstState state)
+{
+ QGstPipelinePrivate *d = getPrivate();
+ auto retval = gst_element_set_state(element(), state);
+ if (d->m_pendingFlush) {
+ d->m_pendingFlush = false;
+ flush();
+ }
+ return retval;
+}
+
+void QGstPipeline::processMessages(GstMessageType types)
+{
+ QGstPipelinePrivate *d = getPrivate();
+ QGstreamerMessage message{
+ gst_bus_pop_filtered(d->m_bus, types),
+ QGstreamerMessage::HasRef,
+ };
+ d->processMessage(message);
+}
+
+void QGstPipeline::dumpGraph(const char *fileName)
+{
+ if (isNull())
+ return;
+
+ QGstBin{ bin(), QGstBin::NeedsRef }.dumpGraph(fileName);
+}
+
+void QGstPipeline::beginConfig()
+{
+ QGstPipelinePrivate *d = getPrivate();
+ Q_ASSERT(!isNull());
+
+ ++d->m_configCounter;
+ if (d->m_configCounter > 1)
+ return;
+
+ GstState state;
+ GstState pending;
+ GstStateChangeReturn stateChangeReturn = gst_element_get_state(element(), &state, &pending, 0);
+ switch (stateChangeReturn) {
+ case GST_STATE_CHANGE_ASYNC: {
+ if (state == GST_STATE_PLAYING) {
+ // playing->paused transition in progress. wait for it to finish
+ bool stateChangeSuccessful = this->finishStateChange();
+ if (!stateChangeSuccessful)
+ qWarning() << "QGstPipeline::beginConfig: timeout when waiting for state change";
+ }
+
+ state = pending;
+ break;
+ }
+ case GST_STATE_CHANGE_FAILURE: {
+ qDebug() << "QGstPipeline::beginConfig: state change failure";
+ dumpGraph("beginConfigFailure");
+ break;
+ }
+
+ case GST_STATE_CHANGE_NO_PREROLL:
+ case GST_STATE_CHANGE_SUCCESS:
+ break;
+ }
+
+ d->m_savedState = state;
+ if (d->m_savedState == GST_STATE_PLAYING)
+ setStateSync(GST_STATE_PAUSED);
+}
+
+void QGstPipeline::endConfig()
+{
+ QGstPipelinePrivate *d = getPrivate();
+ Q_ASSERT(!isNull());
+
+ --d->m_configCounter;
+ if (d->m_configCounter)
+ return;
+
+ if (d->m_flushOnConfigChanges)
+ d->m_pendingFlush = true;
+ if (d->m_savedState == GST_STATE_PLAYING)
+ setState(GST_STATE_PLAYING);
+ d->m_savedState = GST_STATE_NULL;
+}
+
+void QGstPipeline::flush()
+{
+ seek(position());
+}
+
+void QGstPipeline::seek(std::chrono::nanoseconds pos, double rate)
+{
+ using namespace std::chrono_literals;
+
+ QGstPipelinePrivate *d = getPrivate();
+ // always adjust the rate, so it can be set before playback starts
+ // setting position needs a loaded media file that's seekable
+
+ bool success = (rate > 0)
+ ? gst_element_seek(element(), d->m_rate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
+ GST_SEEK_TYPE_SET, pos.count(), GST_SEEK_TYPE_END, 0)
+ : gst_element_seek(element(), d->m_rate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
+ GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, pos.count());
+
+ if (!success) {
+ qDebug() << "seek: gst_element_seek failed" << pos;
+ return;
+ }
+
+ d->m_position = pos;
+}
+
+void QGstPipeline::seek(std::chrono::nanoseconds pos)
+{
+ seek(pos, getPrivate()->m_rate);
+}
+
+void QGstPipeline::setPlaybackRate(double rate)
+{
+ QGstPipelinePrivate *d = getPrivate();
+ if (rate == d->m_rate)
+ return;
+
+ d->m_rate = rate;
+
+ applyPlaybackRate(/*instantRateChange =*/true);
+}
+
+double QGstPipeline::playbackRate() const
+{
+ QGstPipelinePrivate *d = getPrivate();
+ return d->m_rate;
+}
+
+void QGstPipeline::applyPlaybackRate(bool instantRateChange)
+{
+ QGstPipelinePrivate *d = getPrivate();
+
+ bool success = gst_element_seek(element(), d->m_rate, GST_FORMAT_UNDEFINED,
+ instantRateChange ? rateChangeSeekFlags : GST_SEEK_FLAG_FLUSH,
+ GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE, GST_SEEK_TYPE_NONE,
+ GST_CLOCK_TIME_NONE);
+ if (!success)
+ qDebug() << "setPlaybackRate: gst_element_seek failed";
+}
+
+void QGstPipeline::setPosition(std::chrono::nanoseconds pos)
+{
+ seek(pos);
+}
+
+std::chrono::nanoseconds QGstPipeline::position() const
+{
+ gint64 pos;
+ QGstPipelinePrivate *d = getPrivate();
+ if (gst_element_query_position(element(), GST_FORMAT_TIME, &pos))
+ d->m_position = std::chrono::nanoseconds{ pos };
+ return d->m_position;
+}
+
+std::chrono::milliseconds QGstPipeline::positionInMs() const
+{
+ using namespace std::chrono;
+ return round<milliseconds>(position());
+}
+
+std::chrono::nanoseconds QGstPipeline::duration() const
+{
+ gint64 d;
+ if (!gst_element_query_duration(element(), GST_FORMAT_TIME, &d))
+ return {};
+ return std::chrono::nanoseconds{ d };
+}
+
+std::chrono::milliseconds QGstPipeline::durationInMs() const
+{
+ using namespace std::chrono;
+ return round<milliseconds>(duration());
+}
+
+QGstPipelinePrivate *QGstPipeline::getPrivate() const
+{
+ gpointer p = g_object_get_data(qGstCheckedCast<GObject>(object()), "pipeline-private");
+ auto *d = reinterpret_cast<QGstPipelinePrivate *>(p);
+ Q_ASSERT(d);
+ return d;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgstpipeline_p.h b/src/plugins/multimedia/gstreamer/common/qgstpipeline_p.h
new file mode 100644
index 000000000..41275587e
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstpipeline_p.h
@@ -0,0 +1,122 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef qgstpipeline_p_H
+#define qgstpipeline_p_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/private/qtmultimediaglobal_p.h>
+#include <QtCore/qobject.h>
+
+#include "qgst_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerMessage;
+
+class QGstreamerSyncMessageFilter {
+public:
+ //returns true if message was processed and should be dropped, false otherwise
+ virtual bool processSyncMessage(const QGstreamerMessage &message) = 0;
+};
+
+
+class QGstreamerBusMessageFilter {
+public:
+ //returns true if message was processed and should be dropped, false otherwise
+ virtual bool processBusMessage(const QGstreamerMessage &message) = 0;
+};
+
+class QGstPipelinePrivate;
+
+class QGstPipeline : public QGstBin
+{
+public:
+ constexpr QGstPipeline() = default;
+ QGstPipeline(const QGstPipeline &) = default;
+ QGstPipeline(QGstPipeline &&) = default;
+ QGstPipeline &operator=(const QGstPipeline &) = default;
+ QGstPipeline &operator=(QGstPipeline &&) noexcept = default;
+ QGstPipeline(GstPipeline *, RefMode mode);
+ ~QGstPipeline();
+
+ // installs QGstPipelinePrivate as "pipeline-private" gobject property
+ static QGstPipeline create(const char *name);
+ static QGstPipeline adopt(GstPipeline *);
+
+ // This is needed to help us avoid sending QVideoFrames or audio buffers to the
+ // application while we're prerolling the pipeline.
+ // QMediaPlayer is still in a stopped state, while we put the gstreamer pipeline into a
+ // Paused state so that we can get the required metadata of the stream and also have a fast
+ // transition to play.
+ bool inStoppedState() const;
+ void setInStoppedState(bool stopped);
+
+ void setFlushOnConfigChanges(bool flush);
+
+ void installMessageFilter(QGstreamerSyncMessageFilter *filter);
+ void removeMessageFilter(QGstreamerSyncMessageFilter *filter);
+ void installMessageFilter(QGstreamerBusMessageFilter *filter);
+ void removeMessageFilter(QGstreamerBusMessageFilter *filter);
+
+ GstStateChangeReturn setState(GstState state);
+
+ GstPipeline *pipeline() const { return GST_PIPELINE_CAST(get()); }
+
+ void processMessages(GstMessageType = GST_MESSAGE_ANY);
+
+ void dumpGraph(const char *fileName);
+
+ template <typename Functor>
+ void modifyPipelineWhileNotRunning(Functor &&fn)
+ {
+ beginConfig();
+ fn();
+ endConfig();
+ }
+
+ template <typename Functor>
+ static void modifyPipelineWhileNotRunning(QGstPipeline &&pipeline, Functor &&fn)
+ {
+ if (pipeline)
+ pipeline.modifyPipelineWhileNotRunning(fn);
+ else
+ fn();
+ }
+
+ void flush();
+
+ void setPlaybackRate(double rate);
+ double playbackRate() const;
+ void applyPlaybackRate(bool instantRateChange);
+
+ void setPosition(std::chrono::nanoseconds pos);
+ std::chrono::nanoseconds position() const;
+ std::chrono::milliseconds positionInMs() const;
+
+ std::chrono::nanoseconds duration() const;
+ std::chrono::milliseconds durationInMs() const;
+
+private:
+ void seek(std::chrono::nanoseconds pos, double rate);
+ void seek(std::chrono::nanoseconds pos);
+
+ QGstPipelinePrivate *getPrivate() const;
+
+ void beginConfig();
+ void endConfig();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreameraudioinput.cpp b/src/plugins/multimedia/gstreamer/common/qgstreameraudioinput.cpp
new file mode 100644
index 000000000..7c620da39
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreameraudioinput.cpp
@@ -0,0 +1,137 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtMultimedia/qaudiodevice.h>
+#include <QtMultimedia/qaudioinput.h>
+
+#include <QtCore/qloggingcategory.h>
+
+#include <audio/qgstreameraudiodevice_p.h>
+#include <common/qgstreameraudioinput_p.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <utility>
+
+static Q_LOGGING_CATEGORY(qLcMediaAudioInput, "qt.multimedia.audioInput")
+
+QT_BEGIN_NAMESPACE
+
+QMaybe<QPlatformAudioInput *> QGstreamerAudioInput::create(QAudioInput *parent)
+{
+ static const auto error = qGstErrorMessageIfElementsNotAvailable("autoaudiosrc", "volume");
+ if (error)
+ return *error;
+
+ return new QGstreamerAudioInput(parent);
+}
+
+QGstreamerAudioInput::QGstreamerAudioInput(QAudioInput *parent)
+ : QObject(parent),
+ QPlatformAudioInput(parent),
+ gstAudioInput(QGstBin::create("audioInput")),
+ audioSrc{
+ QGstElement::createFromFactory("autoaudiosrc", "autoaudiosrc"),
+ },
+ audioVolume{
+ QGstElement::createFromFactory("volume", "volume"),
+ }
+{
+ gstAudioInput.add(audioSrc, audioVolume);
+ qLinkGstElements(audioSrc, audioVolume);
+
+ gstAudioInput.addGhostPad(audioVolume, "src");
+}
+
+QGstElement QGstreamerAudioInput::createGstElement()
+{
+ const auto *customDeviceInfo =
+ dynamic_cast<const QGStreamerCustomAudioDeviceInfo *>(m_audioDevice.handle());
+
+ if (customDeviceInfo) {
+ qCDebug(qLcMediaAudioInput)
+ << "requesting custom audio src element: " << customDeviceInfo->id;
+
+ QGstElement element = QGstBin::createFromPipelineDescription(customDeviceInfo->id,
+ /*name=*/nullptr,
+ /*ghostUnlinkedPads=*/true);
+ if (element)
+ return element;
+
+ qCWarning(qLcMediaAudioInput)
+ << "Cannot create audio source element:" << customDeviceInfo->id;
+ }
+
+ const QByteArray &id = m_audioDevice.id();
+ if constexpr (QT_CONFIG(pulseaudio)) {
+ QGstElement newSrc = QGstElement::createFromFactory("pulsesrc", "audiosrc");
+ if (newSrc) {
+ newSrc.set("device", id.constData());
+ return newSrc;
+ } else {
+ qWarning() << "Cannot create pulsesrc";
+ }
+ } else if constexpr (QT_CONFIG(alsa)) {
+ QGstElement newSrc = QGstElement::createFromFactory("alsasrc", "audiosrc");
+ if (newSrc) {
+ newSrc.set("device", id.constData());
+ return newSrc;
+ } else {
+ qWarning() << "Cannot create alsasrc";
+ }
+ } else {
+ auto *deviceInfo = dynamic_cast<const QGStreamerAudioDeviceInfo *>(m_audioDevice.handle());
+ if (deviceInfo && deviceInfo->gstDevice) {
+ QGstElement element = QGstElement::createFromDevice(deviceInfo->gstDevice, "audiosrc");
+ if (element)
+ return element;
+ }
+ }
+ qCWarning(qLcMediaAudioInput) << "Invalid audio device";
+ qCWarning(qLcMediaAudioInput)
+ << "Failed to create a gst element for the audio device, using a default audio source";
+ return QGstElement::createFromFactory("autoaudiosrc", "audiosrc");
+}
+
+QGstreamerAudioInput::~QGstreamerAudioInput()
+{
+ gstAudioInput.setStateSync(GST_STATE_NULL);
+}
+
+void QGstreamerAudioInput::setVolume(float volume)
+{
+ audioVolume.set("volume", volume);
+}
+
+void QGstreamerAudioInput::setMuted(bool muted)
+{
+ audioVolume.set("mute", muted);
+}
+
+void QGstreamerAudioInput::setAudioDevice(const QAudioDevice &device)
+{
+ if (device == m_audioDevice)
+ return;
+ qCDebug(qLcMediaAudioInput) << "setAudioInput" << device.description() << device.isNull();
+ m_audioDevice = device;
+
+ QGstElement newSrc = createGstElement();
+
+ QGstPipeline::modifyPipelineWhileNotRunning(gstAudioInput.getPipeline(), [&] {
+ qUnlinkGstElements(audioSrc, audioVolume);
+ gstAudioInput.stopAndRemoveElements(audioSrc);
+ audioSrc = std::move(newSrc);
+ gstAudioInput.add(audioSrc);
+ qLinkGstElements(audioSrc, audioVolume);
+ audioSrc.syncStateWithParent();
+ });
+}
+
+QAudioDevice QGstreamerAudioInput::audioInput() const
+{
+ return m_audioDevice;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreameraudioinput_p.h b/src/plugins/multimedia/gstreamer/common/qgstreameraudioinput_p.h
new file mode 100644
index 000000000..5ca0e1a49
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreameraudioinput_p.h
@@ -0,0 +1,62 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERAUDIOINPUT_P_H
+#define QGSTREAMERAUDIOINPUT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+#include <QtMultimedia/private/qmultimediautils_p.h>
+#include <QtMultimedia/private/qplatformaudioinput_p.h>
+#include <QtMultimedia/private/qtmultimediaglobal_p.h>
+#include <QtMultimedia/qaudiodevice.h>
+
+#include <common/qgst_p.h>
+#include <common/qgstpipeline_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioDevice;
+
+class QGstreamerAudioInput : public QObject, public QPlatformAudioInput
+{
+public:
+ static QMaybe<QPlatformAudioInput *> create(QAudioInput *parent);
+ ~QGstreamerAudioInput();
+
+ bool setAudioInput(const QAudioDevice &);
+ QAudioDevice audioInput() const;
+
+ void setAudioDevice(const QAudioDevice &) override;
+ void setVolume(float) override;
+ void setMuted(bool) override;
+
+ QGstElement gstElement() const { return gstAudioInput; }
+
+private:
+ explicit QGstreamerAudioInput(QAudioInput *parent);
+
+ QGstElement createGstElement();
+
+ QAudioDevice m_audioDevice;
+
+ // Gst elements
+ QGstBin gstAudioInput;
+
+ QGstElement audioSrc;
+ QGstElement audioVolume;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreameraudiooutput.cpp b/src/plugins/multimedia/gstreamer/common/qgstreameraudiooutput.cpp
new file mode 100644
index 000000000..9cea7fb62
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreameraudiooutput.cpp
@@ -0,0 +1,138 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <common/qgstreameraudiooutput_p.h>
+#include <audio/qgstreameraudiodevice_p.h>
+
+#include <QtMultimedia/qaudiodevice.h>
+#include <QtMultimedia/qaudiooutput.h>
+#include <QtCore/qloggingcategory.h>
+
+#include <utility>
+
+static Q_LOGGING_CATEGORY(qLcMediaAudioOutput, "qt.multimedia.audiooutput")
+
+QT_BEGIN_NAMESPACE
+
+QMaybe<QPlatformAudioOutput *> QGstreamerAudioOutput::create(QAudioOutput *parent)
+{
+ static const auto error = qGstErrorMessageIfElementsNotAvailable(
+ "audioconvert", "audioresample", "volume", "autoaudiosink");
+ if (error)
+ return *error;
+
+ return new QGstreamerAudioOutput(parent);
+}
+
+QGstreamerAudioOutput::QGstreamerAudioOutput(QAudioOutput *parent)
+ : QObject(parent),
+ QPlatformAudioOutput(parent),
+ gstAudioOutput(QGstBin::create("audioOutput")),
+ audioQueue{
+ QGstElement::createFromFactory("queue", "audioQueue"),
+ },
+ audioConvert{
+ QGstElement::createFromFactory("audioconvert", "audioConvert"),
+ },
+ audioResample{
+ QGstElement::createFromFactory("audioresample", "audioResample"),
+ },
+ audioVolume{
+ QGstElement::createFromFactory("volume", "volume"),
+ },
+ audioSink{
+ QGstElement::createFromFactory("autoaudiosink", "autoAudioSink"),
+ }
+{
+ gstAudioOutput.add(audioQueue, audioConvert, audioResample, audioVolume, audioSink);
+ qLinkGstElements(audioQueue, audioConvert, audioResample, audioVolume, audioSink);
+
+ gstAudioOutput.addGhostPad(audioQueue, "sink");
+}
+
+QGstElement QGstreamerAudioOutput::createGstElement()
+{
+ const auto *customDeviceInfo =
+ dynamic_cast<const QGStreamerCustomAudioDeviceInfo *>(m_audioOutput.handle());
+
+ if (customDeviceInfo) {
+ qCDebug(qLcMediaAudioOutput)
+ << "requesting custom audio sink element: " << customDeviceInfo->id;
+
+ QGstElement element =
+ QGstBin::createFromPipelineDescription(customDeviceInfo->id, /*name=*/nullptr,
+ /*ghostUnlinkedPads=*/true);
+ if (element)
+ return element;
+
+ qCWarning(qLcMediaAudioOutput)
+ << "Cannot create audio sink element:" << customDeviceInfo->id;
+ }
+
+ const QByteArray &id = m_audioOutput.id();
+ if constexpr (QT_CONFIG(pulseaudio)) {
+ QGstElement newSink = QGstElement::createFromFactory("pulsesink", "audiosink");
+ if (newSink) {
+ newSink.set("device", id.constData());
+ return newSink;
+ } else {
+ qWarning() << "Cannot create pulsesink";
+ }
+ } else if constexpr (QT_CONFIG(alsa)) {
+ QGstElement newSink = QGstElement::createFromFactory("alsasink", "audiosink");
+ if (newSink) {
+ newSink.set("device", id.constData());
+ return newSink;
+ } else {
+ qWarning() << "Cannot create alsasink";
+ }
+ } else {
+ auto *deviceInfo = dynamic_cast<const QGStreamerAudioDeviceInfo *>(m_audioOutput.handle());
+ if (deviceInfo && deviceInfo->gstDevice) {
+ QGstElement element = QGstElement::createFromDevice(deviceInfo->gstDevice, "audiosink");
+ if (element)
+ return element;
+ }
+ }
+ qCWarning(qLcMediaAudioOutput) << "Invalid audio device:" << m_audioOutput.id();
+ qCWarning(qLcMediaAudioOutput)
+ << "Failed to create a gst element for the audio device, using a default audio sink";
+ return QGstElement::createFromFactory("autoaudiosink", "audiosink");
+}
+
+QGstreamerAudioOutput::~QGstreamerAudioOutput()
+{
+ gstAudioOutput.setStateSync(GST_STATE_NULL);
+}
+
+void QGstreamerAudioOutput::setVolume(float volume)
+{
+ audioVolume.set("volume", volume);
+}
+
+void QGstreamerAudioOutput::setMuted(bool muted)
+{
+ audioVolume.set("mute", muted);
+}
+
+void QGstreamerAudioOutput::setAudioDevice(const QAudioDevice &info)
+{
+ if (info == m_audioOutput)
+ return;
+ qCDebug(qLcMediaAudioOutput) << "setAudioOutput" << info.description() << info.isNull();
+
+ m_audioOutput = info;
+
+ QGstElement newSink = createGstElement();
+
+ QGstPipeline::modifyPipelineWhileNotRunning(gstAudioOutput.getPipeline(), [&] {
+ qUnlinkGstElements(audioVolume, audioSink);
+ gstAudioOutput.stopAndRemoveElements(audioSink);
+ audioSink = std::move(newSink);
+ gstAudioOutput.add(audioSink);
+ audioSink.syncStateWithParent();
+ qLinkGstElements(audioVolume, audioSink);
+ });
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreameraudiooutput_p.h b/src/plugins/multimedia/gstreamer/common/qgstreameraudiooutput_p.h
new file mode 100644
index 000000000..dea53e5c4
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreameraudiooutput_p.h
@@ -0,0 +1,63 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERAUDIOOUTPUT_P_H
+#define QGSTREAMERAUDIOOUTPUT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+#include <QtMultimedia/private/qmultimediautils_p.h>
+#include <QtMultimedia/private/qplatformaudiooutput_p.h>
+#include <QtMultimedia/private/qtmultimediaglobal_p.h>
+#include <QtMultimedia/qaudiodevice.h>
+
+#include <common/qgst_p.h>
+#include <common/qgstpipeline_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioDevice;
+
+class QGstreamerAudioOutput : public QObject, public QPlatformAudioOutput
+{
+public:
+ static QMaybe<QPlatformAudioOutput *> create(QAudioOutput *parent);
+ ~QGstreamerAudioOutput();
+
+ void setAudioDevice(const QAudioDevice &) override;
+ void setVolume(float) override;
+ void setMuted(bool) override;
+
+ QGstElement gstElement() const { return gstAudioOutput; }
+
+private:
+ explicit QGstreamerAudioOutput(QAudioOutput *parent);
+
+ QGstElement createGstElement();
+
+ QAudioDevice m_audioOutput;
+
+ // Gst elements
+ QGstPipeline gstPipeline;
+ QGstBin gstAudioOutput;
+
+ QGstElement audioQueue;
+ QGstElement audioConvert;
+ QGstElement audioResample;
+ QGstElement audioVolume;
+ QGstElement audioSink;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamerbufferprobe.cpp b/src/plugins/multimedia/gstreamer/common/qgstreamerbufferprobe.cpp
new file mode 100644
index 000000000..9cba810db
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamerbufferprobe.cpp
@@ -0,0 +1,88 @@
+// Copyright (C) 2016 Jolla Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <common/qgstreamerbufferprobe_p.h>
+
+#include <common/qgst_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QGstreamerBufferProbe::QGstreamerBufferProbe(Flags flags)
+ : m_flags(flags)
+{
+}
+
+QGstreamerBufferProbe::~QGstreamerBufferProbe() = default;
+
+void QGstreamerBufferProbe::addProbeToPad(GstPad *pad, bool downstream)
+{
+ QGstCaps caps{
+ gst_pad_get_current_caps(pad),
+ QGstCaps::HasRef,
+ };
+
+ if (caps)
+ probeCaps(caps.caps());
+
+ if (m_flags & ProbeCaps) {
+ m_capsProbeId = gst_pad_add_probe(
+ pad,
+ downstream
+ ? GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM
+ : GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
+ capsProbe,
+ this,
+ nullptr);
+ }
+ if (m_flags & ProbeBuffers) {
+ m_bufferProbeId = gst_pad_add_probe(
+ pad, GST_PAD_PROBE_TYPE_BUFFER, bufferProbe, this, nullptr);
+ }
+}
+
+void QGstreamerBufferProbe::removeProbeFromPad(GstPad *pad)
+{
+ if (m_capsProbeId != -1) {
+ gst_pad_remove_probe(pad, m_capsProbeId);
+ m_capsProbeId = -1;
+ }
+ if (m_bufferProbeId != -1) {
+ gst_pad_remove_probe(pad, m_bufferProbeId);
+ m_bufferProbeId = -1;
+ }
+}
+
+void QGstreamerBufferProbe::probeCaps(GstCaps *)
+{
+}
+
+bool QGstreamerBufferProbe::probeBuffer(GstBuffer *)
+{
+ return true;
+}
+
+GstPadProbeReturn QGstreamerBufferProbe::capsProbe(GstPad *, GstPadProbeInfo *info, gpointer user_data)
+{
+ QGstreamerBufferProbe * const control = static_cast<QGstreamerBufferProbe *>(user_data);
+
+ if (GstEvent * const event = gst_pad_probe_info_get_event(info)) {
+ if (GST_EVENT_TYPE(event) == GST_EVENT_CAPS) {
+ GstCaps *caps;
+ gst_event_parse_caps(event, &caps);
+
+ control->probeCaps(caps);
+ }
+ }
+ return GST_PAD_PROBE_OK;
+}
+
+GstPadProbeReturn QGstreamerBufferProbe::bufferProbe(
+ GstPad *, GstPadProbeInfo *info, gpointer user_data)
+{
+ QGstreamerBufferProbe * const control = static_cast<QGstreamerBufferProbe *>(user_data);
+ if (GstBuffer * const buffer = gst_pad_probe_info_get_buffer(info))
+ return control->probeBuffer(buffer) ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP;
+ return GST_PAD_PROBE_OK;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamerbufferprobe_p.h b/src/plugins/multimedia/gstreamer/common/qgstreamerbufferprobe_p.h
new file mode 100644
index 000000000..71996a0cc
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamerbufferprobe_p.h
@@ -0,0 +1,56 @@
+// Copyright (C) 2016 Jolla Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERBUFFERPROBE_H
+#define QGSTREAMERBUFFERPROBE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <gst/gst.h>
+
+#include <QtCore/qglobal.h>
+
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerBufferProbe
+{
+public:
+ enum Flags
+ {
+ ProbeCaps = 0x01,
+ ProbeBuffers = 0x02,
+ ProbeAll = ProbeCaps | ProbeBuffers
+ };
+
+ explicit QGstreamerBufferProbe(Flags flags = ProbeAll);
+ virtual ~QGstreamerBufferProbe();
+
+ void addProbeToPad(GstPad *pad, bool downstream = true);
+ void removeProbeFromPad(GstPad *pad);
+
+protected:
+ virtual void probeCaps(GstCaps *caps);
+ virtual bool probeBuffer(GstBuffer *buffer);
+
+private:
+ static GstPadProbeReturn capsProbe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
+ static GstPadProbeReturn bufferProbe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
+ int m_capsProbeId = -1;
+ int m_bufferProbeId = -1;
+ const Flags m_flags;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGSTREAMERBUFFERPROBE_H
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp
new file mode 100644
index 000000000..1d7299da2
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp
@@ -0,0 +1,1111 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <common/qgstreamermediaplayer_p.h>
+
+#include <audio/qgstreameraudiodevice_p.h>
+#include <common/qgst_debug_p.h>
+#include <common/qgstappsource_p.h>
+#include <common/qgstpipeline_p.h>
+#include <common/qgstreameraudiooutput_p.h>
+#include <common/qgstreamermessage_p.h>
+#include <common/qgstreamermetadata_p.h>
+#include <common/qgstreamervideooutput_p.h>
+#include <common/qgstreamervideosink_p.h>
+#include <qgstreamerformatinfo_p.h>
+
+#include <QtMultimedia/qaudiodevice.h>
+#include <QtCore/qdir.h>
+#include <QtCore/qsocketnotifier.h>
+#include <QtCore/qurl.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qloggingcategory.h>
+#include <QtCore/private/quniquehandle_p.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#if QT_CONFIG(gstreamer_gl)
+# include <gst/gl/gl.h>
+#endif
+
+static Q_LOGGING_CATEGORY(qLcMediaPlayer, "qt.multimedia.player")
+
+QT_BEGIN_NAMESPACE
+
+QGstreamerMediaPlayer::TrackSelector::TrackSelector(TrackType type, QGstElement selector)
+ : selector(selector), type(type)
+{
+ selector.set("sync-streams", true);
+ selector.set("sync-mode", 1 /*clock*/);
+
+ if (type == SubtitleStream)
+ selector.set("cache-buffers", true);
+}
+
+QGstPad QGstreamerMediaPlayer::TrackSelector::createInputPad()
+{
+ auto pad = selector.getRequestPad("sink_%u");
+ tracks.append(pad);
+ return pad;
+}
+
+void QGstreamerMediaPlayer::TrackSelector::removeAllInputPads()
+{
+ for (auto &pad : tracks)
+ selector.releaseRequestPad(pad);
+ tracks.clear();
+}
+
+void QGstreamerMediaPlayer::TrackSelector::removeInputPad(QGstPad pad)
+{
+ selector.releaseRequestPad(pad);
+ tracks.removeOne(pad);
+}
+
+QGstPad QGstreamerMediaPlayer::TrackSelector::inputPad(int index)
+{
+ if (index >= 0 && index < tracks.count())
+ return tracks[index];
+ return {};
+}
+
+QGstreamerMediaPlayer::TrackSelector &QGstreamerMediaPlayer::trackSelector(TrackType type)
+{
+ auto &ts = trackSelectors[type];
+ Q_ASSERT(ts.type == type);
+ return ts;
+}
+
+void QGstreamerMediaPlayer::updateBufferProgress(float newProgress)
+{
+ if (qFuzzyIsNull(newProgress - m_bufferProgress))
+ return;
+
+ m_bufferProgress = newProgress;
+ bufferProgressChanged(m_bufferProgress);
+}
+
+void QGstreamerMediaPlayer::disconnectDecoderHandlers()
+{
+ auto handlers = std::initializer_list<QGObjectHandlerScopedConnection *>{
+ &padAdded, &padRemoved, &sourceSetup, &uridecodebinElementAdded,
+ &unknownType, &elementAdded, &elementRemoved,
+ };
+ for (QGObjectHandlerScopedConnection *handler : handlers)
+ handler->disconnect();
+
+ decodeBinQueues = 0;
+}
+
+QMaybe<QPlatformMediaPlayer *> QGstreamerMediaPlayer::create(QMediaPlayer *parent)
+{
+ auto videoOutput = QGstreamerVideoOutput::create();
+ if (!videoOutput)
+ return videoOutput.error();
+
+ static const auto error =
+ qGstErrorMessageIfElementsNotAvailable("input-selector", "decodebin", "uridecodebin");
+ if (error)
+ return *error;
+
+ return new QGstreamerMediaPlayer(videoOutput.value(), parent);
+}
+
+QGstreamerMediaPlayer::QGstreamerMediaPlayer(QGstreamerVideoOutput *videoOutput,
+ QMediaPlayer *parent)
+ : QObject(parent),
+ QPlatformMediaPlayer(parent),
+ trackSelectors{ {
+ { VideoStream,
+ QGstElement::createFromFactory("input-selector", "videoInputSelector") },
+ { AudioStream,
+ QGstElement::createFromFactory("input-selector", "audioInputSelector") },
+ { SubtitleStream,
+ QGstElement::createFromFactory("input-selector", "subTitleInputSelector") },
+ } },
+ playerPipeline(QGstPipeline::create("playerPipeline")),
+ gstVideoOutput(videoOutput)
+{
+ playerPipeline.setFlushOnConfigChanges(true);
+
+ gstVideoOutput->setParent(this);
+ gstVideoOutput->setPipeline(playerPipeline);
+
+ for (auto &ts : trackSelectors)
+ playerPipeline.add(ts.selector);
+
+ playerPipeline.installMessageFilter(static_cast<QGstreamerBusMessageFilter *>(this));
+ playerPipeline.installMessageFilter(static_cast<QGstreamerSyncMessageFilter *>(this));
+
+ QGstClockHandle systemClock{
+ gst_system_clock_obtain(),
+ };
+
+ gst_pipeline_use_clock(playerPipeline.pipeline(), systemClock.get());
+
+ connect(&positionUpdateTimer, &QTimer::timeout, this, [this] {
+ updatePositionFromPipeline();
+ });
+}
+
+QGstreamerMediaPlayer::~QGstreamerMediaPlayer()
+{
+ playerPipeline.removeMessageFilter(static_cast<QGstreamerBusMessageFilter *>(this));
+ playerPipeline.removeMessageFilter(static_cast<QGstreamerSyncMessageFilter *>(this));
+ playerPipeline.setStateSync(GST_STATE_NULL);
+}
+
+std::chrono::nanoseconds QGstreamerMediaPlayer::pipelinePosition() const
+{
+ if (m_url.isEmpty())
+ return {};
+
+ Q_ASSERT(playerPipeline);
+ return playerPipeline.position();
+}
+
+void QGstreamerMediaPlayer::updatePositionFromPipeline()
+{
+ using namespace std::chrono;
+
+ positionChanged(round<milliseconds>(pipelinePosition()));
+}
+
+void QGstreamerMediaPlayer::updateDurationFromPipeline()
+{
+ std::chrono::milliseconds d = playerPipeline.durationInMs();
+ qCDebug(qLcMediaPlayer) << "updateDurationFromPipeline" << d;
+ if (d != m_duration) {
+ m_duration = d;
+ durationChanged(m_duration);
+ }
+}
+
+qint64 QGstreamerMediaPlayer::duration() const
+{
+ return m_duration.count();
+}
+
+float QGstreamerMediaPlayer::bufferProgress() const
+{
+ return m_bufferProgress;
+}
+
+QMediaTimeRange QGstreamerMediaPlayer::availablePlaybackRanges() const
+{
+ return QMediaTimeRange();
+}
+
+qreal QGstreamerMediaPlayer::playbackRate() const
+{
+ return playerPipeline.playbackRate();
+}
+
+void QGstreamerMediaPlayer::setPlaybackRate(qreal rate)
+{
+ if (rate == m_rate)
+ return;
+
+ m_rate = rate;
+
+ playerPipeline.setPlaybackRate(rate);
+ playbackRateChanged(rate);
+}
+
+void QGstreamerMediaPlayer::setPosition(qint64 pos)
+{
+ std::chrono::milliseconds posInMs{ pos };
+ setPosition(posInMs);
+}
+
+void QGstreamerMediaPlayer::setPosition(std::chrono::milliseconds pos)
+{
+ if (pos == playerPipeline.position())
+ return;
+ playerPipeline.finishStateChange();
+ playerPipeline.setPosition(pos);
+ qCDebug(qLcMediaPlayer) << Q_FUNC_INFO << pos << playerPipeline.positionInMs();
+ if (mediaStatus() == QMediaPlayer::EndOfMedia)
+ mediaStatusChanged(QMediaPlayer::LoadedMedia);
+ positionChanged(pos);
+}
+
+void QGstreamerMediaPlayer::play()
+{
+ if (state() == QMediaPlayer::PlayingState || m_url.isEmpty())
+ return;
+
+ if (state() != QMediaPlayer::PausedState)
+ resetCurrentLoop();
+
+ playerPipeline.setInStoppedState(false);
+ if (mediaStatus() == QMediaPlayer::EndOfMedia) {
+ playerPipeline.setPosition({});
+ positionChanged(0);
+ }
+
+ qCDebug(qLcMediaPlayer) << "play().";
+ int ret = playerPipeline.setState(GST_STATE_PLAYING);
+ if (m_requiresSeekOnPlay) {
+ // Flushing the pipeline is required to get track changes
+ // immediately, when they happen while paused.
+ playerPipeline.flush();
+ m_requiresSeekOnPlay = false;
+ } else {
+ // we get an assertion failure during instant playback rate changes
+ // https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3545
+ constexpr bool performInstantRateChange = false;
+ playerPipeline.applyPlaybackRate(/*instantRateChange=*/performInstantRateChange);
+ }
+ if (ret == GST_STATE_CHANGE_FAILURE)
+ qCDebug(qLcMediaPlayer) << "Unable to set the pipeline to the playing state.";
+
+ positionUpdateTimer.start(100);
+ stateChanged(QMediaPlayer::PlayingState);
+}
+
+void QGstreamerMediaPlayer::pause()
+{
+ if (state() == QMediaPlayer::PausedState || m_url.isEmpty()
+ || m_resourceErrorState != ResourceErrorState::NoError)
+ return;
+
+ positionUpdateTimer.stop();
+ if (playerPipeline.inStoppedState()) {
+ playerPipeline.setInStoppedState(false);
+ playerPipeline.flush();
+ }
+ int ret = playerPipeline.setStateSync(GST_STATE_PAUSED);
+ if (ret == GST_STATE_CHANGE_FAILURE)
+ qCDebug(qLcMediaPlayer) << "Unable to set the pipeline to the paused state.";
+ if (mediaStatus() == QMediaPlayer::EndOfMedia) {
+ playerPipeline.setPosition({});
+ positionChanged(0);
+ } else {
+ updatePositionFromPipeline();
+ }
+ stateChanged(QMediaPlayer::PausedState);
+
+ if (m_bufferProgress > 0 || !canTrackProgress())
+ mediaStatusChanged(QMediaPlayer::BufferedMedia);
+ else
+ mediaStatusChanged(QMediaPlayer::BufferingMedia);
+}
+
+void QGstreamerMediaPlayer::stop()
+{
+ using namespace std::chrono_literals;
+ if (state() == QMediaPlayer::StoppedState) {
+ if (position() != 0) {
+ playerPipeline.setPosition({});
+ positionChanged(0ms);
+ mediaStatusChanged(QMediaPlayer::LoadedMedia);
+ }
+ return;
+ }
+ stopOrEOS(false);
+}
+
+const QGstPipeline &QGstreamerMediaPlayer::pipeline() const
+{
+ return playerPipeline;
+}
+
+void QGstreamerMediaPlayer::stopOrEOS(bool eos)
+{
+ using namespace std::chrono_literals;
+
+ positionUpdateTimer.stop();
+ playerPipeline.setInStoppedState(true);
+ bool ret = playerPipeline.setStateSync(GST_STATE_PAUSED);
+ if (!ret)
+ qCDebug(qLcMediaPlayer) << "Unable to set the pipeline to the stopped state.";
+ if (!eos) {
+ playerPipeline.setPosition(0ms);
+ positionChanged(0ms);
+ }
+ stateChanged(QMediaPlayer::StoppedState);
+ if (eos)
+ mediaStatusChanged(QMediaPlayer::EndOfMedia);
+ else
+ mediaStatusChanged(QMediaPlayer::LoadedMedia);
+ m_initialBufferProgressSent = false;
+ bufferProgressChanged(0.f);
+}
+
+void QGstreamerMediaPlayer::detectPipelineIsSeekable()
+{
+ qCDebug(qLcMediaPlayer) << "detectPipelineIsSeekable";
+ QGstQueryHandle query{
+ gst_query_new_seeking(GST_FORMAT_TIME),
+ QGstQueryHandle::HasRef,
+ };
+ gboolean canSeek = false;
+ if (gst_element_query(playerPipeline.element(), query.get())) {
+ gst_query_parse_seeking(query.get(), nullptr, &canSeek, nullptr, nullptr);
+ qCDebug(qLcMediaPlayer) << " pipeline is seekable:" << canSeek;
+ } else {
+ qCWarning(qLcMediaPlayer) << " query for seekable failed.";
+ }
+ seekableChanged(canSeek);
+}
+
+bool QGstreamerMediaPlayer::processBusMessage(const QGstreamerMessage &message)
+{
+ qCDebug(qLcMediaPlayer) << "received bus message:" << message;
+
+ GstMessage* gm = message.message();
+ switch (message.type()) {
+ case GST_MESSAGE_TAG: {
+ // #### This isn't ideal. We shouldn't catch stream specific tags here, rather the global ones
+ QGstTagListHandle tagList;
+ gst_message_parse_tag(gm, &tagList);
+
+ qCDebug(qLcMediaPlayer) << " Got tags: " << tagList.get();
+
+ QMediaMetaData originalMetaData = m_metaData;
+ extendMetaDataFromTagList(m_metaData, tagList);
+ if (originalMetaData != m_metaData)
+ metaDataChanged();
+
+ if (gstVideoOutput) {
+ QVariant rotation = m_metaData.value(QMediaMetaData::Orientation);
+ gstVideoOutput->setRotation(rotation.value<QtVideo::Rotation>());
+ }
+ break;
+ }
+ case GST_MESSAGE_DURATION_CHANGED: {
+ if (!prerolling)
+ updateDurationFromPipeline();
+
+ return false;
+ }
+ case GST_MESSAGE_EOS: {
+ positionChanged(m_duration);
+ if (doLoop()) {
+ setPosition(0);
+ break;
+ }
+ stopOrEOS(true);
+ break;
+ }
+ case GST_MESSAGE_BUFFERING: {
+ int progress = 0;
+ gst_message_parse_buffering(gm, &progress);
+
+ qCDebug(qLcMediaPlayer) << " buffering message: " << progress;
+
+ if (state() != QMediaPlayer::StoppedState && !prerolling) {
+ if (!m_initialBufferProgressSent) {
+ mediaStatusChanged(QMediaPlayer::BufferingMedia);
+ m_initialBufferProgressSent = true;
+ }
+
+ if (m_bufferProgress > 0 && progress == 0)
+ mediaStatusChanged(QMediaPlayer::StalledMedia);
+ else if (progress >= 50)
+ // QTBUG-124517: rethink buffering
+ mediaStatusChanged(QMediaPlayer::BufferedMedia);
+ else
+ mediaStatusChanged(QMediaPlayer::BufferingMedia);
+ }
+
+ updateBufferProgress(progress * 0.01);
+ break;
+ }
+ case GST_MESSAGE_STATE_CHANGED: {
+ if (message.source() != playerPipeline)
+ return false;
+
+ GstState oldState;
+ GstState newState;
+ GstState pending;
+
+ gst_message_parse_state_changed(gm, &oldState, &newState, &pending);
+ qCDebug(qLcMediaPlayer) << " state changed message from"
+ << QCompactGstMessageAdaptor(message);
+
+ switch (newState) {
+ case GST_STATE_VOID_PENDING:
+ case GST_STATE_NULL:
+ case GST_STATE_READY:
+ break;
+ case GST_STATE_PAUSED: {
+ if (prerolling) {
+ qCDebug(qLcMediaPlayer) << "Preroll done, setting status to Loaded";
+ playerPipeline.dumpGraph("playerPipelinePrerollDone");
+
+ prerolling = false;
+ updateDurationFromPipeline();
+
+ m_metaData.insert(QMediaMetaData::Duration, duration());
+ m_metaData.insert(QMediaMetaData::Url, m_url);
+ parseStreamsAndMetadata();
+ metaDataChanged();
+
+ tracksChanged();
+ mediaStatusChanged(QMediaPlayer::LoadedMedia);
+
+ if (!playerPipeline.inStoppedState()) {
+ Q_ASSERT(!m_initialBufferProgressSent);
+
+ bool immediatelySendBuffered = !canTrackProgress() || m_bufferProgress > 0;
+ mediaStatusChanged(QMediaPlayer::BufferingMedia);
+ m_initialBufferProgressSent = true;
+ if (immediatelySendBuffered)
+ mediaStatusChanged(QMediaPlayer::BufferedMedia);
+ }
+ }
+
+ break;
+ }
+ case GST_STATE_PLAYING: {
+ if (!m_initialBufferProgressSent) {
+ bool immediatelySendBuffered = !canTrackProgress() || m_bufferProgress > 0;
+ mediaStatusChanged(QMediaPlayer::BufferingMedia);
+ m_initialBufferProgressSent = true;
+ if (immediatelySendBuffered)
+ mediaStatusChanged(QMediaPlayer::BufferedMedia);
+ }
+ break;
+ }
+ }
+ break;
+ }
+ case GST_MESSAGE_ERROR: {
+ qCDebug(qLcMediaPlayer) << " error" << QCompactGstMessageAdaptor(message);
+
+ QUniqueGErrorHandle err;
+ QUniqueGStringHandle debug;
+ gst_message_parse_error(gm, &err, &debug);
+ GQuark errorDomain = err.get()->domain;
+ gint errorCode = err.get()->code;
+
+ if (errorDomain == GST_STREAM_ERROR) {
+ if (errorCode == GST_STREAM_ERROR_CODEC_NOT_FOUND)
+ error(QMediaPlayer::FormatError, tr("Cannot play stream of type: <unknown>"));
+ else {
+ error(QMediaPlayer::FormatError, QString::fromUtf8(err.get()->message));
+ }
+ } else if (errorDomain == GST_RESOURCE_ERROR) {
+ if (errorCode == GST_RESOURCE_ERROR_NOT_FOUND) {
+ if (m_resourceErrorState != ResourceErrorState::ErrorReported) {
+ // gstreamer seems to deliver multiple GST_RESOURCE_ERROR_NOT_FOUND events
+ error(QMediaPlayer::ResourceError, QString::fromUtf8(err.get()->message));
+ m_resourceErrorState = ResourceErrorState::ErrorReported;
+ m_url.clear();
+ }
+ } else {
+ error(QMediaPlayer::ResourceError, QString::fromUtf8(err.get()->message));
+ }
+ } else {
+ playerPipeline.dumpGraph("error");
+ }
+ mediaStatusChanged(QMediaPlayer::InvalidMedia);
+ break;
+ }
+
+ case GST_MESSAGE_WARNING:
+ qCWarning(qLcMediaPlayer) << "Warning:" << QCompactGstMessageAdaptor(message);
+ playerPipeline.dumpGraph("warning");
+ break;
+
+ case GST_MESSAGE_INFO:
+ if (qLcMediaPlayer().isDebugEnabled())
+ qCDebug(qLcMediaPlayer) << "Info:" << QCompactGstMessageAdaptor(message);
+ break;
+
+ case GST_MESSAGE_SEGMENT_START: {
+ qCDebug(qLcMediaPlayer) << " segment start message, updating position";
+ QGstStructureView structure(gst_message_get_structure(gm));
+ auto p = structure["position"].toInt64();
+ if (p) {
+ std::chrono::milliseconds position{
+ (*p) / 1000000,
+ };
+ positionChanged(position);
+ }
+ break;
+ }
+ case GST_MESSAGE_ELEMENT: {
+ QGstStructureView structure(gst_message_get_structure(gm));
+ auto type = structure.name();
+ if (type == "stream-topology")
+ topology = structure.clone();
+
+ break;
+ }
+
+ case GST_MESSAGE_ASYNC_DONE: {
+ detectPipelineIsSeekable();
+ break;
+ }
+
+ default:
+// qCDebug(qLcMediaPlayer) << " default message handler, doing nothing";
+
+ break;
+ }
+
+ return false;
+}
+
+bool QGstreamerMediaPlayer::processSyncMessage(const QGstreamerMessage &message)
+{
+#if QT_CONFIG(gstreamer_gl)
+ if (message.type() != GST_MESSAGE_NEED_CONTEXT)
+ return false;
+ const gchar *type = nullptr;
+ gst_message_parse_context_type (message.message(), &type);
+ if (strcmp(type, GST_GL_DISPLAY_CONTEXT_TYPE))
+ return false;
+ if (!gstVideoOutput || !gstVideoOutput->gstreamerVideoSink())
+ return false;
+ auto *context = gstVideoOutput->gstreamerVideoSink()->gstGlDisplayContext();
+ if (!context)
+ return false;
+ gst_element_set_context(GST_ELEMENT(GST_MESSAGE_SRC(message.message())), context);
+ playerPipeline.dumpGraph("need_context");
+ return true;
+#else
+ Q_UNUSED(message);
+ return false;
+#endif
+}
+
+QUrl QGstreamerMediaPlayer::media() const
+{
+ return m_url;
+}
+
+const QIODevice *QGstreamerMediaPlayer::mediaStream() const
+{
+ return m_stream;
+}
+
+void QGstreamerMediaPlayer::decoderPadAdded(const QGstElement &src, const QGstPad &pad)
+{
+ if (src != decoder)
+ return;
+
+ auto caps = pad.currentCaps();
+ auto type = caps.at(0).name();
+ qCDebug(qLcMediaPlayer) << "Received new pad" << pad.name() << "from" << src.name() << "type" << type;
+ qCDebug(qLcMediaPlayer) << " " << caps;
+
+ TrackType streamType = NTrackTypes;
+ if (type.startsWith("video/x-raw")) {
+ streamType = VideoStream;
+ } else if (type.startsWith("audio/x-raw")) {
+ streamType = AudioStream;
+ } else if (type.startsWith("text/")) {
+ streamType = SubtitleStream;
+ } else {
+ qCWarning(qLcMediaPlayer) << "Ignoring unknown media stream:" << pad.name() << type;
+ return;
+ }
+
+ auto &ts = trackSelector(streamType);
+ QGstPad sinkPad = ts.createInputPad();
+ if (!pad.link(sinkPad)) {
+ qCWarning(qLcMediaPlayer) << "Failed to add track, cannot link pads";
+ return;
+ }
+ qCDebug(qLcMediaPlayer) << "Adding track";
+
+ if (ts.trackCount() == 1) {
+ if (streamType == VideoStream) {
+ connectOutput(ts);
+ ts.setActiveInputPad(sinkPad);
+ videoAvailableChanged(true);
+ }
+ else if (streamType == AudioStream) {
+ connectOutput(ts);
+ ts.setActiveInputPad(sinkPad);
+ audioAvailableChanged(true);
+ }
+ }
+
+ if (!prerolling)
+ tracksChanged();
+
+ decoderOutputMap.emplace(pad, sinkPad);
+}
+
+void QGstreamerMediaPlayer::decoderPadRemoved(const QGstElement &src, const QGstPad &pad)
+{
+ if (src != decoder)
+ return;
+
+ qCDebug(qLcMediaPlayer) << "Removed pad" << pad.name() << "from" << src.name();
+
+ auto it = decoderOutputMap.find(pad);
+ if (it == decoderOutputMap.end())
+ return;
+ QGstPad track = it->second;
+
+ auto ts = std::find_if(std::begin(trackSelectors), std::end(trackSelectors),
+ [&](TrackSelector &ts){ return ts.selector == track.parent(); });
+ if (ts == std::end(trackSelectors))
+ return;
+
+ qCDebug(qLcMediaPlayer) << " was linked to pad" << track.name() << "from" << ts->selector.name();
+ ts->removeInputPad(track);
+
+ if (ts->trackCount() == 0) {
+ removeOutput(*ts);
+ if (ts->type == AudioStream)
+ audioAvailableChanged(false);
+ else if (ts->type == VideoStream)
+ videoAvailableChanged(false);
+ }
+
+ if (!prerolling)
+ tracksChanged();
+}
+
+void QGstreamerMediaPlayer::removeAllOutputs()
+{
+ for (auto &ts : trackSelectors) {
+ removeOutput(ts);
+ ts.removeAllInputPads();
+ }
+ audioAvailableChanged(false);
+ videoAvailableChanged(false);
+}
+
+void QGstreamerMediaPlayer::connectOutput(TrackSelector &ts)
+{
+ if (ts.isConnected)
+ return;
+
+ QGstElement e;
+ switch (ts.type) {
+ case AudioStream:
+ e = gstAudioOutput ? gstAudioOutput->gstElement() : QGstElement{};
+ break;
+ case VideoStream:
+ e = gstVideoOutput ? gstVideoOutput->gstElement() : QGstElement{};
+ break;
+ case SubtitleStream:
+ if (gstVideoOutput)
+ gstVideoOutput->linkSubtitleStream(ts.selector);
+ break;
+ default:
+ return;
+ }
+
+ if (!e.isNull()) {
+ qCDebug(qLcMediaPlayer) << "connecting output for track type" << ts.type;
+ playerPipeline.add(e);
+ qLinkGstElements(ts.selector, e);
+ e.syncStateWithParent();
+ }
+
+ ts.isConnected = true;
+}
+
+void QGstreamerMediaPlayer::removeOutput(TrackSelector &ts)
+{
+ if (!ts.isConnected)
+ return;
+
+ QGstElement e;
+ switch (ts.type) {
+ case AudioStream:
+ e = gstAudioOutput ? gstAudioOutput->gstElement() : QGstElement{};
+ break;
+ case VideoStream:
+ e = gstVideoOutput ? gstVideoOutput->gstElement() : QGstElement{};
+ break;
+ case SubtitleStream:
+ if (gstVideoOutput)
+ gstVideoOutput->unlinkSubtitleStream();
+ break;
+ default:
+ break;
+ }
+
+ if (!e.isNull()) {
+ qCDebug(qLcMediaPlayer) << "removing output for track type" << ts.type;
+ playerPipeline.stopAndRemoveElements(e);
+ }
+
+ ts.isConnected = false;
+}
+
+void QGstreamerMediaPlayer::removeDynamicPipelineElements()
+{
+ for (QGstElement *element : { &src, &decoder }) {
+ if (element->isNull())
+ continue;
+
+ element->setStateSync(GstState::GST_STATE_NULL);
+ playerPipeline.remove(*element);
+ *element = QGstElement{};
+ }
+}
+
+void QGstreamerMediaPlayer::uridecodebinElementAddedCallback(GstElement * /*uridecodebin*/,
+ GstElement *child,
+ QGstreamerMediaPlayer *)
+{
+ QGstElement c(child, QGstElement::NeedsRef);
+ qCDebug(qLcMediaPlayer) << "New element added to uridecodebin:" << c.name();
+
+ static const GType decodeBinType = [] {
+ QGstElementFactoryHandle factory = QGstElement::findFactory("decodebin");
+ return gst_element_factory_get_element_type(factory.get());
+ }();
+
+ if (c.type() == decodeBinType) {
+ qCDebug(qLcMediaPlayer) << " -> setting post-stream-topology property";
+ c.set("post-stream-topology", true);
+ }
+}
+
+void QGstreamerMediaPlayer::sourceSetupCallback(GstElement *uridecodebin, GstElement *source, QGstreamerMediaPlayer *that)
+{
+ Q_UNUSED(uridecodebin)
+ Q_UNUSED(that)
+
+ qCDebug(qLcMediaPlayer) << "Setting up source:" << g_type_name_from_instance((GTypeInstance*)source);
+
+ if (std::string_view("GstRTSPSrc") == g_type_name_from_instance((GTypeInstance *)source)) {
+ QGstElement s(source, QGstElement::NeedsRef);
+ int latency{40};
+ bool ok{false};
+ int v = qEnvironmentVariableIntValue("QT_MEDIA_RTSP_LATENCY", &ok);
+ if (ok)
+ latency = v;
+ qCDebug(qLcMediaPlayer) << " -> setting source latency to:" << latency << "ms";
+ s.set("latency", latency);
+
+ bool drop{true};
+ v = qEnvironmentVariableIntValue("QT_MEDIA_RTSP_DROP_ON_LATENCY", &ok);
+ if (ok && v == 0)
+ drop = false;
+ qCDebug(qLcMediaPlayer) << " -> setting drop-on-latency to:" << drop;
+ s.set("drop-on-latency", drop);
+
+ bool retrans{false};
+ v = qEnvironmentVariableIntValue("QT_MEDIA_RTSP_DO_RETRANSMISSION", &ok);
+ if (ok && v != 0)
+ retrans = true;
+ qCDebug(qLcMediaPlayer) << " -> setting do-retransmission to:" << retrans;
+ s.set("do-retransmission", retrans);
+ }
+}
+
+void QGstreamerMediaPlayer::unknownTypeCallback(GstElement *decodebin, GstPad *pad, GstCaps *caps,
+ QGstreamerMediaPlayer *self)
+{
+ Q_UNUSED(decodebin)
+ Q_UNUSED(pad)
+ Q_UNUSED(self)
+ qCDebug(qLcMediaPlayer) << "Unknown type:" << caps;
+
+ QMetaObject::invokeMethod(self, [self] {
+ self->stop();
+ });
+}
+
+static bool isQueue(const QGstElement &element)
+{
+ static const GType queueType = [] {
+ QGstElementFactoryHandle factory = QGstElement::findFactory("queue");
+ return gst_element_factory_get_element_type(factory.get());
+ }();
+
+ static const GType multiQueueType = [] {
+ QGstElementFactoryHandle factory = QGstElement::findFactory("multiqueue");
+ return gst_element_factory_get_element_type(factory.get());
+ }();
+
+ return element.type() == queueType || element.type() == multiQueueType;
+}
+
+void QGstreamerMediaPlayer::decodebinElementAddedCallback(GstBin * /*decodebin*/,
+ GstBin * /*sub_bin*/, GstElement *child,
+ QGstreamerMediaPlayer *self)
+{
+ QGstElement c(child, QGstElement::NeedsRef);
+ if (isQueue(c))
+ self->decodeBinQueues += 1;
+}
+
+void QGstreamerMediaPlayer::decodebinElementRemovedCallback(GstBin * /*decodebin*/,
+ GstBin * /*sub_bin*/, GstElement *child,
+ QGstreamerMediaPlayer *self)
+{
+ QGstElement c(child, QGstElement::NeedsRef);
+ if (isQueue(c))
+ self->decodeBinQueues -= 1;
+}
+
+void QGstreamerMediaPlayer::setMedia(const QUrl &content, QIODevice *stream)
+{
+ using namespace std::chrono_literals;
+
+ qCDebug(qLcMediaPlayer) << Q_FUNC_INFO << "setting location to" << content;
+
+ prerolling = true;
+ m_resourceErrorState = ResourceErrorState::NoError;
+
+ bool ret = playerPipeline.setStateSync(GST_STATE_NULL);
+ if (!ret)
+ qCDebug(qLcMediaPlayer) << "Unable to set the pipeline to the stopped state.";
+
+ m_url = content;
+ m_stream = stream;
+
+ removeDynamicPipelineElements();
+ disconnectDecoderHandlers();
+ removeAllOutputs();
+ seekableChanged(false);
+ Q_ASSERT(playerPipeline.inStoppedState());
+
+ if (m_duration != 0ms) {
+ m_duration = 0ms;
+ durationChanged(0ms);
+ }
+ stateChanged(QMediaPlayer::StoppedState);
+ if (position() != 0)
+ positionChanged(0ms);
+ if (!m_metaData.isEmpty()) {
+ m_metaData.clear();
+ metaDataChanged();
+ }
+
+ if (content.isEmpty() && !stream)
+ mediaStatusChanged(QMediaPlayer::NoMedia);
+
+ if (content.isEmpty())
+ return;
+
+ if (m_stream) {
+ if (!m_appSrc) {
+ auto maybeAppSrc = QGstAppSource::create(this);
+ if (maybeAppSrc) {
+ m_appSrc = maybeAppSrc.value();
+ } else {
+ error(QMediaPlayer::ResourceError, maybeAppSrc.error());
+ return;
+ }
+ }
+ src = m_appSrc->element();
+ decoder = QGstElement::createFromFactory("decodebin", "decoder");
+ if (!decoder) {
+ error(QMediaPlayer::ResourceError, qGstErrorMessageCannotFindElement("decodebin"));
+ return;
+ }
+ decoder.set("post-stream-topology", true);
+ decoder.set("use-buffering", true);
+ unknownType = decoder.connect("unknown-type", GCallback(unknownTypeCallback), this);
+ elementAdded = decoder.connect("deep-element-added",
+ GCallback(decodebinElementAddedCallback), this);
+ elementRemoved = decoder.connect("deep-element-removed",
+ GCallback(decodebinElementAddedCallback), this);
+
+ playerPipeline.add(src, decoder);
+ qLinkGstElements(src, decoder);
+
+ m_appSrc->setup(m_stream);
+ seekableChanged(!stream->isSequential());
+ } else {
+ // use uridecodebin
+ decoder = QGstElement::createFromFactory("uridecodebin", "decoder");
+ if (!decoder) {
+ error(QMediaPlayer::ResourceError, qGstErrorMessageCannotFindElement("uridecodebin"));
+ return;
+ }
+ playerPipeline.add(decoder);
+
+ constexpr bool hasPostStreamTopology = GST_CHECK_VERSION(1, 22, 0);
+ if constexpr (hasPostStreamTopology) {
+ decoder.set("post-stream-topology", true);
+ } else {
+ // can't set post-stream-topology to true, as uridecodebin doesn't have the property.
+ // Use a hack
+ uridecodebinElementAdded = decoder.connect(
+ "element-added", GCallback(uridecodebinElementAddedCallback), this);
+ }
+
+ sourceSetup = decoder.connect("source-setup", GCallback(sourceSetupCallback), this);
+ unknownType = decoder.connect("unknown-type", GCallback(unknownTypeCallback), this);
+
+ decoder.set("uri", content.toEncoded().constData());
+ decoder.set("use-buffering", true);
+
+ constexpr int mb = 1024 * 1024;
+ decoder.set("ring-buffer-max-size", 2 * mb);
+
+ updateBufferProgress(0.f);
+
+ elementAdded = decoder.connect("deep-element-added",
+ GCallback(decodebinElementAddedCallback), this);
+ elementRemoved = decoder.connect("deep-element-removed",
+ GCallback(decodebinElementAddedCallback), this);
+ }
+ padAdded = decoder.onPadAdded<&QGstreamerMediaPlayer::decoderPadAdded>(this);
+ padRemoved = decoder.onPadRemoved<&QGstreamerMediaPlayer::decoderPadRemoved>(this);
+
+ mediaStatusChanged(QMediaPlayer::LoadingMedia);
+ if (!playerPipeline.setStateSync(GST_STATE_PAUSED)) {
+ qCWarning(qLcMediaPlayer) << "Unable to set the pipeline to the paused state.";
+ // Note: no further error handling: errors will be delivered via a GstMessage
+ return;
+ }
+
+ playerPipeline.setPosition(0ms);
+ positionChanged(0ms);
+}
+
+void QGstreamerMediaPlayer::setAudioOutput(QPlatformAudioOutput *output)
+{
+ if (gstAudioOutput == output)
+ return;
+
+ auto &ts = trackSelector(AudioStream);
+
+ playerPipeline.modifyPipelineWhileNotRunning([&] {
+ if (gstAudioOutput)
+ removeOutput(ts);
+
+ gstAudioOutput = static_cast<QGstreamerAudioOutput *>(output);
+ if (gstAudioOutput)
+ connectOutput(ts);
+ });
+}
+
+QMediaMetaData QGstreamerMediaPlayer::metaData() const
+{
+ return m_metaData;
+}
+
+void QGstreamerMediaPlayer::setVideoSink(QVideoSink *sink)
+{
+ gstVideoOutput->setVideoSink(sink);
+}
+
+static QGstStructureView endOfChain(const QGstStructureView &s)
+{
+ QGstStructureView e = s;
+ while (1) {
+ auto next = e["next"].toStructure();
+ if (!next.isNull())
+ e = next;
+ else
+ break;
+ }
+ return e;
+}
+
+void QGstreamerMediaPlayer::parseStreamsAndMetadata()
+{
+ qCDebug(qLcMediaPlayer) << "============== parse topology ============";
+
+ if (!topology) {
+ qCDebug(qLcMediaPlayer) << " null topology";
+ return;
+ }
+
+ QGstStructureView topologyView{ topology };
+
+ QGstCaps caps = topologyView.caps();
+ extendMetaDataFromCaps(m_metaData, caps);
+
+ QGstTagListHandle tagList = QGstStructureView{ topology }.tags();
+ if (tagList)
+ extendMetaDataFromTagList(m_metaData, tagList);
+
+ QGstStructureView demux = endOfChain(topologyView);
+ QGValue next = demux["next"];
+ if (!next.isList()) {
+ qCDebug(qLcMediaPlayer) << " no additional streams";
+ metaDataChanged();
+ return;
+ }
+
+ // collect stream info
+ int size = next.listSize();
+ for (int i = 0; i < size; ++i) {
+ auto val = next.at(i);
+ caps = val.toStructure().caps();
+
+ extendMetaDataFromCaps(m_metaData, caps);
+
+ QGstStructureView structure = caps.at(0);
+
+ if (structure.name().startsWith("video/")) {
+ QSize nativeSize = structure.nativeSize();
+ gstVideoOutput->setNativeSize(nativeSize);
+ }
+ }
+
+ auto sinkPad = trackSelector(VideoStream).activeInputPad();
+ if (sinkPad) {
+ QGstTagListHandle tagList = sinkPad.tags();
+ if (tagList)
+ qCDebug(qLcMediaPlayer) << " tags=" << tagList.get();
+ else
+ qCDebug(qLcMediaPlayer) << " tags=(null)";
+ }
+
+ qCDebug(qLcMediaPlayer) << "============== end parse topology ============";
+ playerPipeline.dumpGraph("playback");
+}
+
+int QGstreamerMediaPlayer::trackCount(QPlatformMediaPlayer::TrackType type)
+{
+ return trackSelector(type).trackCount();
+}
+
+QMediaMetaData QGstreamerMediaPlayer::trackMetaData(QPlatformMediaPlayer::TrackType type, int index)
+{
+ auto track = trackSelector(type).inputPad(index);
+ if (!track)
+ return {};
+
+ QGstTagListHandle tagList = track.tags();
+ return taglistToMetaData(tagList);
+}
+
+int QGstreamerMediaPlayer::activeTrack(TrackType type)
+{
+ return trackSelector(type).activeInputIndex();
+}
+
+void QGstreamerMediaPlayer::setActiveTrack(TrackType type, int index)
+{
+ auto &ts = trackSelector(type);
+ auto track = ts.inputPad(index);
+ if (track.isNull() && index != -1) {
+ qCWarning(qLcMediaPlayer) << "Attempt to set an incorrect index" << index
+ << "for the track type" << type;
+ return;
+ }
+
+ qCDebug(qLcMediaPlayer) << "Setting the index" << index << "for the track type" << type;
+ if (type == QPlatformMediaPlayer::SubtitleStream)
+ gstVideoOutput->flushSubtitles();
+
+ playerPipeline.modifyPipelineWhileNotRunning([&] {
+ if (track.isNull()) {
+ removeOutput(ts);
+ } else {
+ ts.setActiveInputPad(track);
+ connectOutput(ts);
+ }
+ });
+
+ // seek to force an immediate change of the stream
+ if (playerPipeline.state() == GST_STATE_PLAYING)
+ playerPipeline.flush();
+ else
+ m_requiresSeekOnPlay = true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h
new file mode 100644
index 000000000..28e7a0c31
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h
@@ -0,0 +1,199 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERMEDIAPLAYER_P_H
+#define QGSTREAMERMEDIAPLAYER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qstack.h>
+#include <private/qplatformmediaplayer_p.h>
+#include <private/qtmultimediaglobal_p.h>
+#include <private/qmultimediautils_p.h>
+#include <qurl.h>
+#include <common/qgst_p.h>
+#include <common/qgstpipeline_p.h>
+
+#include <QtCore/qtimer.h>
+
+#include <array>
+
+QT_BEGIN_NAMESPACE
+
+class QNetworkAccessManager;
+class QGstreamerMessage;
+class QGstAppSource;
+class QGstreamerAudioOutput;
+class QGstreamerVideoOutput;
+
+class QGstreamerMediaPlayer : public QObject,
+ public QPlatformMediaPlayer,
+ public QGstreamerBusMessageFilter,
+ public QGstreamerSyncMessageFilter
+{
+public:
+ static QMaybe<QPlatformMediaPlayer *> create(QMediaPlayer *parent = nullptr);
+ ~QGstreamerMediaPlayer();
+
+ qint64 duration() const override;
+
+ float bufferProgress() const override;
+
+ QMediaTimeRange availablePlaybackRanges() const override;
+
+ qreal playbackRate() const override;
+ void setPlaybackRate(qreal rate) override;
+
+ QUrl media() const override;
+ const QIODevice *mediaStream() const override;
+ void setMedia(const QUrl &, QIODevice *) override;
+
+ bool streamPlaybackSupported() const override { return true; }
+
+ void setAudioOutput(QPlatformAudioOutput *output) override;
+
+ QMediaMetaData metaData() const override;
+
+ void setVideoSink(QVideoSink *sink) override;
+
+ int trackCount(TrackType) override;
+ QMediaMetaData trackMetaData(TrackType /*type*/, int /*streamNumber*/) override;
+ int activeTrack(TrackType) override;
+ void setActiveTrack(TrackType, int /*streamNumber*/) override;
+
+ void setPosition(qint64 pos) override;
+ void setPosition(std::chrono::milliseconds pos);
+
+ void play() override;
+ void pause() override;
+ void stop() override;
+
+ const QGstPipeline &pipeline() const;
+
+ bool processBusMessage(const QGstreamerMessage& message) override;
+ bool processSyncMessage(const QGstreamerMessage& message) override;
+
+private:
+ QGstreamerMediaPlayer(QGstreamerVideoOutput *videoOutput, QMediaPlayer *parent);
+
+ struct TrackSelector
+ {
+ TrackSelector(TrackType, QGstElement selector);
+ QGstPad createInputPad();
+ void removeInputPad(QGstPad pad);
+ void removeAllInputPads();
+ QGstPad inputPad(int index);
+ int activeInputIndex() const { return isConnected ? tracks.indexOf(activeInputPad()) : -1; }
+ QGstPad activeInputPad() const
+ {
+ return isConnected ? QGstPad{ selector.getObject("active-pad") } : QGstPad{};
+ }
+ void setActiveInputPad(QGstPad input) { selector.set("active-pad", input); }
+ int trackCount() const { return tracks.count(); }
+
+ QGstElement selector;
+ TrackType type;
+ QList<QGstPad> tracks;
+ bool isConnected = false;
+ };
+
+ friend class QGstreamerStreamsControl;
+ void decoderPadAdded(const QGstElement &src, const QGstPad &pad);
+ void decoderPadRemoved(const QGstElement &src, const QGstPad &pad);
+ void disconnectDecoderHandlers();
+ static void uridecodebinElementAddedCallback(GstElement *uridecodebin, GstElement *child,
+ QGstreamerMediaPlayer *that);
+ static void sourceSetupCallback(GstElement *uridecodebin, GstElement *source,
+ QGstreamerMediaPlayer *that);
+ static void unknownTypeCallback(GstElement *decodebin, GstPad *pad, GstCaps *caps,
+ QGstreamerMediaPlayer *self);
+ static void decodebinElementAddedCallback(GstBin *decodebin, GstBin *sub_bin,
+ GstElement *element, QGstreamerMediaPlayer *self);
+ static void decodebinElementRemovedCallback(GstBin *decodebin, GstBin *sub_bin,
+ GstElement *element, QGstreamerMediaPlayer *self);
+
+ void parseStreamsAndMetadata();
+ void connectOutput(TrackSelector &ts);
+ void removeOutput(TrackSelector &ts);
+ void removeDynamicPipelineElements();
+ void removeAllOutputs();
+ void stopOrEOS(bool eos);
+ bool canTrackProgress() const { return decodeBinQueues > 0; }
+ void detectPipelineIsSeekable();
+
+ std::chrono::nanoseconds pipelinePosition() const;
+ void updatePositionFromPipeline();
+ void updateDurationFromPipeline();
+ void updateBufferProgress(float);
+
+ std::array<TrackSelector, NTrackTypes> trackSelectors;
+ TrackSelector &trackSelector(TrackType type);
+
+ QMediaMetaData m_metaData;
+
+ QUrl m_url;
+ QIODevice *m_stream = nullptr;
+
+ enum class ResourceErrorState : uint8_t {
+ NoError,
+ ErrorOccurred,
+ ErrorReported,
+ };
+
+ bool prerolling = false;
+ bool m_requiresSeekOnPlay = false;
+ bool m_initialBufferProgressSent = false;
+ ResourceErrorState m_resourceErrorState = ResourceErrorState::NoError;
+ float m_rate = 1.f;
+ float m_bufferProgress = 0.f;
+ std::chrono::milliseconds m_duration{};
+ QTimer positionUpdateTimer;
+
+ QGstAppSource *m_appSrc = nullptr;
+
+ QUniqueGstStructureHandle topology;
+
+ // Gst elements
+ QGstPipeline playerPipeline;
+ QGstElement src;
+ QGstElement decoder;
+
+ QGstreamerAudioOutput *gstAudioOutput = nullptr;
+ QGstreamerVideoOutput *gstVideoOutput = nullptr;
+
+ // QGstElement streamSynchronizer;
+
+ struct QGstPadLess
+ {
+ bool operator()(const QGstPad &lhs, const QGstPad &rhs) const
+ {
+ return lhs.pad() < rhs.pad();
+ }
+ };
+
+ std::map<QGstPad, QGstPad, QGstPadLess> decoderOutputMap;
+
+ // decoder connections
+ QGObjectHandlerScopedConnection padAdded;
+ QGObjectHandlerScopedConnection padRemoved;
+ QGObjectHandlerScopedConnection sourceSetup;
+ QGObjectHandlerScopedConnection uridecodebinElementAdded;
+ QGObjectHandlerScopedConnection unknownType;
+ QGObjectHandlerScopedConnection elementAdded;
+ QGObjectHandlerScopedConnection elementRemoved;
+
+ int decodeBinQueues = 0;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamermessage_p.h b/src/plugins/multimedia/gstreamer/common/qgstreamermessage_p.h
new file mode 100644
index 000000000..9836bd0cb
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamermessage_p.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERMESSAGE_P_H
+#define QGSTREAMERMESSAGE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <common/qgst_p.h>
+
+QT_BEGIN_NAMESPACE
+
+// Required for QDoc workaround
+class QString;
+
+template <>
+struct QGstPointerImpl::QGstRefcountingAdaptor<GstMessage>
+{
+ static void ref(GstMessage *arg) noexcept { gst_message_ref(arg); }
+ static void unref(GstMessage *arg) noexcept { gst_message_unref(arg); }
+};
+
+class QGstreamerMessage : public QGstPointerImpl::QGstObjectWrapper<GstMessage>
+{
+ using BaseClass = QGstPointerImpl::QGstObjectWrapper<GstMessage>;
+
+public:
+ using BaseClass::BaseClass;
+ QGstreamerMessage(const QGstreamerMessage &) = default;
+ QGstreamerMessage(QGstreamerMessage &&) noexcept = default;
+ QGstreamerMessage &operator=(const QGstreamerMessage &) = default;
+ QGstreamerMessage &operator=(QGstreamerMessage &&) noexcept = default;
+
+ GstMessageType type() const { return GST_MESSAGE_TYPE(get()); }
+ QGstObject source() const { return QGstObject(GST_MESSAGE_SRC(get()), QGstObject::NeedsRef); }
+ QGstStructureView structure() const { return QGstStructureView(gst_message_get_structure(get())); }
+
+ GstMessage *message() const { return get(); }
+};
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QGstreamerMessage);
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamermetadata.cpp b/src/plugins/multimedia/gstreamer/common/qgstreamermetadata.cpp
new file mode 100644
index 000000000..4ac679873
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamermetadata.cpp
@@ -0,0 +1,489 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qgstreamermetadata_p.h"
+#include <QtMultimedia/qmediametadata.h>
+#include <QtMultimedia/qtvideo.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qdatetime.h>
+#include <QtCore/qlocale.h>
+#include <QtCore/qtimezone.h>
+#include <QtGui/qimage.h>
+
+#include <gst/gstversion.h>
+#include <common/qgst_handle_types_p.h>
+#include <common/qgstutils_p.h>
+#include <qgstreamerformatinfo_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+
+namespace MetadataLookupImpl {
+
+#ifdef __cpp_lib_constexpr_algorithms
+# define constexpr_lookup constexpr
+#else
+# define constexpr_lookup /*constexpr*/
+#endif
+
+struct MetadataKeyValuePair
+{
+ const char *tag;
+ QMediaMetaData::Key key;
+};
+
+constexpr const char *toTag(const char *t)
+{
+ return t;
+}
+constexpr const char *toTag(const MetadataKeyValuePair &kv)
+{
+ return kv.tag;
+}
+
+constexpr QMediaMetaData::Key toKey(QMediaMetaData::Key k)
+{
+ return k;
+}
+constexpr QMediaMetaData::Key toKey(const MetadataKeyValuePair &kv)
+{
+ return kv.key;
+}
+
+constexpr auto compareByKey = [](const auto &lhs, const auto &rhs) {
+ return toKey(lhs) < toKey(rhs);
+};
+
+constexpr auto compareByTag = [](const auto &lhs, const auto &rhs) {
+ return std::strcmp(toTag(lhs), toTag(rhs)) < 0;
+};
+
+constexpr_lookup auto makeLookupTable()
+{
+ std::array<MetadataKeyValuePair, 22> lookupTable{ {
+ { GST_TAG_TITLE, QMediaMetaData::Title },
+ { GST_TAG_COMMENT, QMediaMetaData::Comment },
+ { GST_TAG_DESCRIPTION, QMediaMetaData::Description },
+ { GST_TAG_GENRE, QMediaMetaData::Genre },
+ { GST_TAG_DATE_TIME, QMediaMetaData::Date },
+ { GST_TAG_DATE, QMediaMetaData::Date },
+
+ { GST_TAG_LANGUAGE_CODE, QMediaMetaData::Language },
+
+ { GST_TAG_ORGANIZATION, QMediaMetaData::Publisher },
+ { GST_TAG_COPYRIGHT, QMediaMetaData::Copyright },
+
+ // Media
+ { GST_TAG_DURATION, QMediaMetaData::Duration },
+
+ // Audio
+ { GST_TAG_BITRATE, QMediaMetaData::AudioBitRate },
+ { GST_TAG_AUDIO_CODEC, QMediaMetaData::AudioCodec },
+
+ // Music
+ { GST_TAG_ALBUM, QMediaMetaData::AlbumTitle },
+ { GST_TAG_ALBUM_ARTIST, QMediaMetaData::AlbumArtist },
+ { GST_TAG_ARTIST, QMediaMetaData::ContributingArtist },
+ { GST_TAG_TRACK_NUMBER, QMediaMetaData::TrackNumber },
+
+ { GST_TAG_PREVIEW_IMAGE, QMediaMetaData::ThumbnailImage },
+ { GST_TAG_IMAGE, QMediaMetaData::CoverArtImage },
+
+ // Image/Video
+ { "resolution", QMediaMetaData::Resolution },
+ { GST_TAG_IMAGE_ORIENTATION, QMediaMetaData::Orientation },
+
+ // Video
+ { GST_TAG_VIDEO_CODEC, QMediaMetaData::VideoCodec },
+
+ // Movie
+ { GST_TAG_PERFORMER, QMediaMetaData::LeadPerformer },
+ } };
+
+ std::sort(lookupTable.begin(), lookupTable.end(),
+ [](const MetadataKeyValuePair &lhs, const MetadataKeyValuePair &rhs) {
+ return std::string_view(lhs.tag) < std::string_view(rhs.tag);
+ });
+ return lookupTable;
+}
+
+constexpr_lookup auto gstTagToMetaDataKey = makeLookupTable();
+constexpr_lookup auto metaDataKeyToGstTag = [] {
+ auto array = gstTagToMetaDataKey;
+ std::sort(array.begin(), array.end(), compareByKey);
+ return array;
+}();
+
+} // namespace MetadataLookupImpl
+
+QMediaMetaData::Key tagToKey(const char *tag)
+{
+ if (tag == nullptr)
+ return QMediaMetaData::Key(-1);
+
+ using namespace MetadataLookupImpl;
+ auto foundIterator = std::lower_bound(gstTagToMetaDataKey.begin(), gstTagToMetaDataKey.end(),
+ tag, compareByTag);
+ if (std::strcmp(foundIterator->tag, tag) == 0)
+ return foundIterator->key;
+
+ return QMediaMetaData::Key(-1);
+}
+
+const char *keyToTag(QMediaMetaData::Key key)
+{
+ using namespace MetadataLookupImpl;
+ auto foundIterator = std::lower_bound(metaDataKeyToGstTag.begin(), metaDataKeyToGstTag.end(),
+ key, compareByKey);
+ if (foundIterator->key == key)
+ return foundIterator->tag;
+
+ return nullptr;
+}
+
+#undef constexpr_lookup
+
+QtVideo::Rotation parseRotationTag(const char *string)
+{
+ using namespace std::string_view_literals;
+
+ if (string == "rotate-90"sv)
+ return QtVideo::Rotation::Clockwise90;
+ if (string == "rotate-180"sv)
+ return QtVideo::Rotation::Clockwise180;
+ if (string == "rotate-270"sv)
+ return QtVideo::Rotation::Clockwise270;
+ if (string == "rotate-0"sv)
+ return QtVideo::Rotation::None;
+
+ qCritical() << "cannot parse orientation: {}" << string;
+ return QtVideo::Rotation::None;
+}
+
+QDateTime parseDate(const GValue &val)
+{
+ Q_ASSERT(G_VALUE_TYPE(&val) == G_TYPE_DATE);
+
+ const GDate *date = (const GDate *)g_value_get_boxed(&val);
+ if (!g_date_valid(date))
+ return {};
+
+ int year = g_date_get_year(date);
+ int month = g_date_get_month(date);
+ int day = g_date_get_day(date);
+ return QDateTime(QDate(year, month, day), QTime());
+}
+
+QDateTime parseDateTime(const GValue &val)
+{
+ Q_ASSERT(G_VALUE_TYPE(&val) == GST_TYPE_DATE_TIME);
+
+ const GstDateTime *dateTime = (const GstDateTime *)g_value_get_boxed(&val);
+ int year = gst_date_time_has_year(dateTime) ? gst_date_time_get_year(dateTime) : 0;
+ int month = gst_date_time_has_month(dateTime) ? gst_date_time_get_month(dateTime) : 0;
+ int day = gst_date_time_has_day(dateTime) ? gst_date_time_get_day(dateTime) : 0;
+ int hour = 0;
+ int minute = 0;
+ int second = 0;
+ float tz = 0;
+ if (gst_date_time_has_time(dateTime)) {
+ hour = gst_date_time_get_hour(dateTime);
+ minute = gst_date_time_get_minute(dateTime);
+ second = gst_date_time_get_second(dateTime);
+ tz = gst_date_time_get_time_zone_offset(dateTime);
+ }
+ return QDateTime{
+ QDate(year, month, day),
+ QTime(hour, minute, second),
+ QTimeZone(tz * 60 * 60),
+ };
+}
+
+QImage parseImage(const GValue &val)
+{
+ Q_ASSERT(G_VALUE_TYPE(&val) == GST_TYPE_SAMPLE);
+
+ GstSample *sample = (GstSample *)g_value_get_boxed(&val);
+ GstCaps *caps = gst_sample_get_caps(sample);
+ if (caps && !gst_caps_is_empty(caps)) {
+ GstStructure *structure = gst_caps_get_structure(caps, 0);
+ const gchar *name = gst_structure_get_name(structure);
+ if (QByteArray(name).startsWith("image/")) {
+ GstBuffer *buffer = gst_sample_get_buffer(sample);
+ if (buffer) {
+ GstMapInfo info;
+ gst_buffer_map(buffer, &info, GST_MAP_READ);
+ QImage image = QImage::fromData(info.data, info.size, name);
+ gst_buffer_unmap(buffer, &info);
+ return image;
+ }
+ }
+ }
+
+ return {};
+}
+
+std::optional<double> parseFractionAsDouble(const GValue &val)
+{
+ Q_ASSERT(G_VALUE_TYPE(&val) == GST_TYPE_FRACTION);
+
+ int nom = gst_value_get_fraction_numerator(&val);
+ int denom = gst_value_get_fraction_denominator(&val);
+ if (denom == 0)
+ return std::nullopt;
+ return double(nom) / double(denom);
+}
+
+constexpr std::string_view extendedComment{ GST_TAG_EXTENDED_COMMENT };
+
+void addTagsFromExtendedComment(const GstTagList *list, const gchar *tag, QMediaMetaData &metadata)
+{
+ using namespace Qt::Literals;
+ assert(tag == extendedComment);
+
+ int entryCount = gst_tag_list_get_tag_size(list, tag);
+ for (int i = 0; i != entryCount; ++i) {
+ const GValue *value = gst_tag_list_get_value_index(list, tag, i);
+
+ const QLatin1StringView strValue{ g_value_get_string(value) };
+
+ auto equalIndex = strValue.indexOf(QLatin1StringView("="));
+ if (equalIndex == -1) {
+ qDebug() << "Cannot parse GST_TAG_EXTENDED_COMMENT entry: " << value;
+ continue;
+ }
+
+ const QLatin1StringView key = strValue.first(equalIndex);
+ const QLatin1StringView valueString = strValue.last(strValue.size() - equalIndex - 1);
+
+ if (key == "DURATION"_L1) {
+ QUniqueGstDateTimeHandle duration{
+ gst_date_time_new_from_iso8601_string(valueString.data()),
+ };
+
+ if (duration) {
+ using namespace std::chrono;
+
+ auto chronoDuration = hours(gst_date_time_get_hour(duration.get()))
+ + minutes(gst_date_time_get_minute(duration.get()))
+ + seconds(gst_date_time_get_second(duration.get()))
+ + microseconds(gst_date_time_get_microsecond(duration.get()));
+
+ metadata.insert(QMediaMetaData::Duration,
+ QVariant::fromValue(round<milliseconds>(chronoDuration).count()));
+ }
+ }
+ }
+}
+
+void addTagToMetaData(const GstTagList *list, const gchar *tag, void *userdata)
+{
+ QMediaMetaData &metadata = *reinterpret_cast<QMediaMetaData *>(userdata);
+
+ QMediaMetaData::Key key = tagToKey(tag);
+ if (key == QMediaMetaData::Key(-1)) {
+ if (tag == extendedComment)
+ addTagsFromExtendedComment(list, tag, metadata);
+
+ return;
+ }
+
+ GValue val{};
+ gst_tag_list_copy_value(&val, list, tag);
+
+ GType type = G_VALUE_TYPE(&val);
+
+ if (auto entryCount = gst_tag_list_get_tag_size(list, tag) != 0; entryCount != 1)
+ qWarning() << "addTagToMetaData: invaled entry count for" << tag << "-" << entryCount;
+
+ if (type == G_TYPE_STRING) {
+ const gchar *str_value = g_value_get_string(&val);
+
+ switch (key) {
+ case QMediaMetaData::Language: {
+ metadata.insert(key,
+ QVariant::fromValue(QLocale::codeToLanguage(
+ QString::fromUtf8(str_value), QLocale::ISO639Part2)));
+ break;
+ }
+ case QMediaMetaData::Orientation: {
+ metadata.insert(key, QVariant::fromValue(parseRotationTag(str_value)));
+ break;
+ }
+ default:
+ metadata.insert(key, QString::fromUtf8(str_value));
+ break;
+ };
+ } else if (type == G_TYPE_INT) {
+ metadata.insert(key, g_value_get_int(&val));
+ } else if (type == G_TYPE_UINT) {
+ metadata.insert(key, g_value_get_uint(&val));
+ } else if (type == G_TYPE_LONG) {
+ metadata.insert(key, qint64(g_value_get_long(&val)));
+ } else if (type == G_TYPE_BOOLEAN) {
+ metadata.insert(key, g_value_get_boolean(&val));
+ } else if (type == G_TYPE_CHAR) {
+ metadata.insert(key, g_value_get_schar(&val));
+ } else if (type == G_TYPE_DOUBLE) {
+ metadata.insert(key, g_value_get_double(&val));
+ } else if (type == G_TYPE_DATE) {
+ if (!metadata.keys().contains(key)) {
+ QDateTime date = parseDate(val);
+ if (date.isValid())
+ metadata.insert(key, date);
+ }
+ } else if (type == GST_TYPE_DATE_TIME) {
+ metadata.insert(key, parseDateTime(val));
+ } else if (type == GST_TYPE_SAMPLE) {
+ QImage image = parseImage(val);
+ if (!image.isNull())
+ metadata.insert(key, image);
+ } else if (type == GST_TYPE_FRACTION) {
+ std::optional<double> fraction = parseFractionAsDouble(val);
+
+ if (fraction)
+ metadata.insert(key, *fraction);
+ }
+
+ g_value_unset(&val);
+}
+
+} // namespace
+
+QMediaMetaData taglistToMetaData(const QGstTagListHandle &handle)
+{
+ QMediaMetaData m;
+ extendMetaDataFromTagList(m, handle);
+ return m;
+}
+
+void extendMetaDataFromTagList(QMediaMetaData &metadata, const QGstTagListHandle &handle)
+{
+ if (handle)
+ gst_tag_list_foreach(handle.get(), reinterpret_cast<GstTagForeachFunc>(&addTagToMetaData),
+ &metadata);
+}
+
+static void applyMetaDataToTagSetter(const QMediaMetaData &metadata, GstTagSetter *element)
+{
+ gst_tag_setter_reset_tags(element);
+
+ for (QMediaMetaData::Key key : metadata.keys()) {
+ const char *tagName = keyToTag(key);
+ if (!tagName)
+ continue;
+ const QVariant &tagValue = metadata.value(key);
+
+ auto setTag = [&](const auto &value) {
+ gst_tag_setter_add_tags(element, GST_TAG_MERGE_REPLACE, tagName, value, nullptr);
+ };
+
+ switch (tagValue.typeId()) {
+ case QMetaType::QString:
+ setTag(tagValue.toString().toUtf8().constData());
+ break;
+ case QMetaType::Int:
+ case QMetaType::LongLong:
+ setTag(tagValue.toInt());
+ break;
+ case QMetaType::Double:
+ setTag(tagValue.toDouble());
+ break;
+ case QMetaType::QDate:
+ case QMetaType::QDateTime: {
+ QDateTime date = tagValue.toDateTime();
+
+ QGstGstDateTimeHandle dateTime{
+ gst_date_time_new(date.offsetFromUtc() / 60. / 60., date.date().year(),
+ date.date().month(), date.date().day(), date.time().hour(),
+ date.time().minute(), date.time().second()),
+ QGstGstDateTimeHandle::HasRef,
+ };
+
+ setTag(dateTime.get());
+ break;
+ }
+ default: {
+ if (tagValue.typeId() == qMetaTypeId<QLocale::Language>()) {
+ QByteArray language = QLocale::languageToCode(tagValue.value<QLocale::Language>(),
+ QLocale::ISO639Part2)
+ .toUtf8();
+ setTag(language.constData());
+ }
+
+ break;
+ }
+ }
+ }
+}
+
+void applyMetaDataToTagSetter(const QMediaMetaData &metadata, const QGstElement &element)
+{
+ GstTagSetter *tagSetter = qGstSafeCast<GstTagSetter>(element.element());
+ if (tagSetter)
+ applyMetaDataToTagSetter(metadata, tagSetter);
+ else
+ qWarning() << "applyMetaDataToTagSetter failed: element not a GstTagSetter"
+ << element.name();
+}
+
+void applyMetaDataToTagSetter(const QMediaMetaData &metadata, const QGstBin &bin)
+{
+ GstIterator *elements = gst_bin_iterate_all_by_interface(bin.bin(), GST_TYPE_TAG_SETTER);
+ GValue item = {};
+
+ while (gst_iterator_next(elements, &item) == GST_ITERATOR_OK) {
+ GstElement *element = static_cast<GstElement *>(g_value_get_object(&item));
+ if (!element)
+ continue;
+
+ GstTagSetter *tagSetter = qGstSafeCast<GstTagSetter>(element);
+
+ if (tagSetter)
+ applyMetaDataToTagSetter(metadata, tagSetter);
+ }
+
+ gst_iterator_free(elements);
+}
+
+void extendMetaDataFromCaps(QMediaMetaData &metadata, const QGstCaps &caps)
+{
+ QGstStructureView structure = caps.at(0);
+
+ QMediaFormat::FileFormat fileFormat = QGstreamerFormatInfo::fileFormatForCaps(structure);
+ if (fileFormat != QMediaFormat::FileFormat::UnspecifiedFormat) {
+ // Container caps
+ metadata.insert(QMediaMetaData::FileFormat, fileFormat);
+ return;
+ }
+
+ QMediaFormat::AudioCodec audioCodec = QGstreamerFormatInfo::audioCodecForCaps(structure);
+ if (audioCodec != QMediaFormat::AudioCodec::Unspecified) {
+ // Audio stream caps
+ metadata.insert(QMediaMetaData::AudioCodec, QVariant::fromValue(audioCodec));
+ return;
+ }
+
+ QMediaFormat::VideoCodec videoCodec = QGstreamerFormatInfo::videoCodecForCaps(structure);
+ if (videoCodec != QMediaFormat::VideoCodec::Unspecified) {
+ // Video stream caps
+ metadata.insert(QMediaMetaData::VideoCodec, QVariant::fromValue(videoCodec));
+ std::optional<float> framerate = structure["framerate"].getFraction();
+ if (framerate)
+ metadata.insert(QMediaMetaData::VideoFrameRate, *framerate);
+
+ QSize resolution = structure.resolution();
+ if (resolution.isValid())
+ metadata.insert(QMediaMetaData::Resolution, resolution);
+ }
+}
+
+QMediaMetaData capsToMetaData(const QGstCaps &caps)
+{
+ QMediaMetaData metadata;
+ extendMetaDataFromCaps(metadata, caps);
+ return metadata;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamermetadata_p.h b/src/plugins/multimedia/gstreamer/common/qgstreamermetadata_p.h
new file mode 100644
index 000000000..f04a9aba9
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamermetadata_p.h
@@ -0,0 +1,35 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERMETADATA_H
+#define QGSTREAMERMETADATA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qmediametadata.h>
+
+#include "qgst_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QMediaMetaData taglistToMetaData(const QGstTagListHandle &);
+void extendMetaDataFromTagList(QMediaMetaData &, const QGstTagListHandle &);
+
+QMediaMetaData capsToMetaData(const QGstCaps &);
+void extendMetaDataFromCaps(QMediaMetaData &, const QGstCaps &);
+
+void applyMetaDataToTagSetter(const QMediaMetaData &metadata, const QGstBin &);
+void applyMetaDataToTagSetter(const QMediaMetaData &metadata, const QGstElement &);
+
+QT_END_NAMESPACE
+
+#endif // QGSTREAMERMETADATA_H
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamervideooutput.cpp b/src/plugins/multimedia/gstreamer/common/qgstreamervideooutput.cpp
new file mode 100644
index 000000000..2f3197e92
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamervideooutput.cpp
@@ -0,0 +1,221 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtMultimedia/qvideosink.h>
+
+#include <QtCore/qloggingcategory.h>
+#include <QtCore/qthread.h>
+
+#include <common/qgstreamervideooutput_p.h>
+#include <common/qgstreamervideosink_p.h>
+#include <common/qgstsubtitlesink_p.h>
+
+static Q_LOGGING_CATEGORY(qLcMediaVideoOutput, "qt.multimedia.videooutput")
+
+QT_BEGIN_NAMESPACE
+
+QMaybe<QGstreamerVideoOutput *> QGstreamerVideoOutput::create(QObject *parent)
+{
+ QGstElement videoConvert;
+ QGstElement videoScale;
+
+ QGstElementFactoryHandle factory = QGstElement::findFactory("videoconvertscale");
+
+ if (factory) { // videoconvertscale is only available in gstreamer 1.20
+ videoConvert = QGstElement::createFromFactory(factory, "videoConvertScale");
+ } else {
+ videoConvert = QGstElement::createFromFactory("videoconvert", "videoConvert");
+ if (!videoConvert)
+ return qGstErrorMessageCannotFindElement("videoconvert");
+
+ videoScale = QGstElement::createFromFactory("videoscale", "videoScale");
+ if (!videoScale)
+ return qGstErrorMessageCannotFindElement("videoscale");
+ }
+
+ if (!QGstElement::findFactory("fakesink"))
+ return qGstErrorMessageCannotFindElement("fakesink");
+
+ return new QGstreamerVideoOutput(videoConvert, videoScale, parent);
+}
+
+QGstreamerVideoOutput::QGstreamerVideoOutput(QGstElement convert, QGstElement scale,
+ QObject *parent)
+ : QObject(parent),
+ gstVideoOutput(QGstBin::create("videoOutput")),
+ videoQueue{
+ QGstElement::createFromFactory("queue", "videoQueue"),
+ },
+ videoConvert(std::move(convert)),
+ videoScale(std::move(scale)),
+ videoSink{
+ QGstElement::createFromFactory("fakesink", "fakeVideoSink"),
+ }
+{
+ videoSink.set("sync", true);
+ videoSink.set("async", false); // no asynchronous state changes
+
+ if (videoScale) {
+ gstVideoOutput.add(videoQueue, videoConvert, videoScale, videoSink);
+ qLinkGstElements(videoQueue, videoConvert, videoScale, videoSink);
+ } else {
+ gstVideoOutput.add(videoQueue, videoConvert, videoSink);
+ qLinkGstElements(videoQueue, videoConvert, videoSink);
+ }
+
+ gstVideoOutput.addGhostPad(videoQueue, "sink");
+}
+
+QGstreamerVideoOutput::~QGstreamerVideoOutput()
+{
+ gstVideoOutput.setStateSync(GST_STATE_NULL);
+}
+
+void QGstreamerVideoOutput::setVideoSink(QVideoSink *sink)
+{
+ auto *gstVideoSink = sink ? static_cast<QGstreamerVideoSink *>(sink->platformVideoSink()) : nullptr;
+ if (gstVideoSink == m_videoSink)
+ return;
+
+ if (m_videoSink)
+ m_videoSink->setPipeline({});
+
+ m_videoSink = gstVideoSink;
+ if (m_videoSink) {
+ m_videoSink->setPipeline(gstPipeline);
+ if (nativeSize.isValid())
+ m_videoSink->setNativeSize(nativeSize);
+ }
+ QGstElement gstSink;
+ if (m_videoSink) {
+ gstSink = m_videoSink->gstSink();
+ } else {
+ gstSink = QGstElement::createFromFactory("fakesink", "fakevideosink");
+ Q_ASSERT(gstSink);
+ gstSink.set("sync", true);
+ gstSink.set("async", false); // no asynchronous state changes
+ }
+
+ if (videoSink == gstSink)
+ return;
+
+ gstPipeline.modifyPipelineWhileNotRunning([&] {
+ if (!videoSink.isNull())
+ gstVideoOutput.stopAndRemoveElements(videoSink);
+
+ videoSink = gstSink;
+ gstVideoOutput.add(videoSink);
+
+ if (videoScale)
+ qLinkGstElements(videoScale, videoSink);
+ else
+ qLinkGstElements(videoConvert, videoSink);
+
+ GstEvent *event = gst_event_new_reconfigure();
+ gst_element_send_event(videoSink.element(), event);
+ videoSink.syncStateWithParent();
+
+ doLinkSubtitleStream();
+ });
+
+ qCDebug(qLcMediaVideoOutput) << "sinkChanged" << gstSink.name();
+
+ gstPipeline.dumpGraph(videoSink.name().constData());
+}
+
+void QGstreamerVideoOutput::setPipeline(const QGstPipeline &pipeline)
+{
+ gstPipeline = pipeline;
+ if (m_videoSink)
+ m_videoSink->setPipeline(gstPipeline);
+}
+
+void QGstreamerVideoOutput::linkSubtitleStream(QGstElement src)
+{
+ qCDebug(qLcMediaVideoOutput) << "link subtitle stream" << src.isNull();
+ if (src == subtitleSrc)
+ return;
+
+ gstPipeline.modifyPipelineWhileNotRunning([&] {
+ subtitleSrc = src;
+ doLinkSubtitleStream();
+ });
+}
+
+void QGstreamerVideoOutput::unlinkSubtitleStream()
+{
+ if (subtitleSrc.isNull())
+ return;
+ qCDebug(qLcMediaVideoOutput) << "unlink subtitle stream";
+ subtitleSrc = {};
+ if (!subtitleSink.isNull()) {
+ gstPipeline.modifyPipelineWhileNotRunning([&] {
+ gstPipeline.stopAndRemoveElements(subtitleSink);
+ return;
+ });
+ subtitleSink = {};
+ }
+ if (m_videoSink)
+ m_videoSink->setSubtitleText({});
+}
+
+void QGstreamerVideoOutput::doLinkSubtitleStream()
+{
+ if (!subtitleSink.isNull()) {
+ gstPipeline.stopAndRemoveElements(subtitleSink);
+ subtitleSink = {};
+ }
+ if (!m_videoSink || subtitleSrc.isNull())
+ return;
+ if (subtitleSink.isNull()) {
+ subtitleSink = m_videoSink->subtitleSink();
+ gstPipeline.add(subtitleSink);
+ }
+ qLinkGstElements(subtitleSrc, subtitleSink);
+}
+
+void QGstreamerVideoOutput::updateNativeSize()
+{
+ if (!m_videoSink)
+ return;
+
+ m_videoSink->setNativeSize(qRotatedFrameSize(nativeSize, rotation));
+}
+
+void QGstreamerVideoOutput::setIsPreview()
+{
+ // configures the queue to be fast and lightweight for camera preview
+ // also avoids blocking the queue in case we have an encodebin attached to the tee as well
+ videoQueue.set("leaky", 2 /*downstream*/);
+ videoQueue.set("silent", true);
+ videoQueue.set("max-size-buffers", uint(1));
+ videoQueue.set("max-size-bytes", uint(0));
+ videoQueue.set("max-size-time", quint64(0));
+}
+
+void QGstreamerVideoOutput::flushSubtitles()
+{
+ if (!subtitleSink.isNull()) {
+ auto pad = subtitleSink.staticPad("sink");
+ auto *event = gst_event_new_flush_start();
+ pad.sendEvent(event);
+ event = gst_event_new_flush_stop(false);
+ pad.sendEvent(event);
+ }
+}
+
+void QGstreamerVideoOutput::setNativeSize(QSize sz)
+{
+ nativeSize = sz;
+ updateNativeSize();
+}
+
+void QGstreamerVideoOutput::setRotation(QtVideo::Rotation rot)
+{
+ rotation = rot;
+ updateNativeSize();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qgstreamervideooutput_p.cpp"
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamervideooutput_p.h b/src/plugins/multimedia/gstreamer/common/qgstreamervideooutput_p.h
new file mode 100644
index 000000000..883946dda
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamervideooutput_p.h
@@ -0,0 +1,81 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERVIDEOOUTPUT_P_H
+#define QGSTREAMERVIDEOOUTPUT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+#include <private/qtmultimediaglobal_p.h>
+#include <private/qmultimediautils_p.h>
+#include <common/qgst_p.h>
+#include <common/qgstpipeline_p.h>
+#include <common/qgstreamervideosink_p.h>
+#include <qwaitcondition.h>
+#include <qmutex.h>
+#include <qpointer.h>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoSink;
+
+class QGstreamerVideoOutput : public QObject
+{
+ Q_OBJECT
+
+public:
+ static QMaybe<QGstreamerVideoOutput *> create(QObject *parent = nullptr);
+ ~QGstreamerVideoOutput();
+
+ void setVideoSink(QVideoSink *sink);
+ QGstreamerVideoSink *gstreamerVideoSink() const { return m_videoSink; }
+
+ void setPipeline(const QGstPipeline &pipeline);
+
+ QGstElement gstElement() const { return gstVideoOutput; }
+ void linkSubtitleStream(QGstElement subtitleSrc);
+ void unlinkSubtitleStream();
+
+ void setIsPreview();
+ void flushSubtitles();
+
+ void setNativeSize(QSize);
+ void setRotation(QtVideo::Rotation);
+
+private:
+ QGstreamerVideoOutput(QGstElement videoConvert, QGstElement videoScale, QObject *parent);
+
+ void doLinkSubtitleStream();
+ void updateNativeSize();
+
+ QPointer<QGstreamerVideoSink> m_videoSink;
+
+ // Gst elements
+ QGstPipeline gstPipeline;
+
+ QGstBin gstVideoOutput;
+ QGstElement videoQueue;
+ QGstElement videoConvert;
+ QGstElement videoScale;
+ QGstElement videoSink;
+
+ QGstElement subtitleSrc;
+ QGstElement subtitleSink;
+
+ QSize nativeSize;
+ QtVideo::Rotation rotation{};
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamervideooverlay.cpp b/src/plugins/multimedia/gstreamer/common/qgstreamervideooverlay.cpp
new file mode 100644
index 000000000..6ca23006b
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamervideooverlay.cpp
@@ -0,0 +1,218 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qgstreamervideooverlay_p.h"
+
+#include <QtGui/qguiapplication.h>
+#include <QtMultimedia/private/qtmultimediaglobal_p.h>
+
+#include <common/qglist_helper_p.h>
+#include <common/qgst_p.h>
+#include <common/qgstreamermessage_p.h>
+#include <common/qgstreamervideosink_p.h>
+#include <common/qgstutils_p.h>
+
+#include <gst/video/videooverlay.h>
+
+QT_BEGIN_NAMESPACE
+
+struct ElementMap
+{
+ QStringView qtPlatform;
+ const char *gstreamerElement = nullptr;
+};
+
+// Ordered by descending priority
+static constexpr ElementMap elementMap[] = {
+ { u"xcb", "xvimagesink" },
+ { u"xcb", "ximagesink" },
+
+ // wayland
+ { u"wayland", "waylandsink" },
+};
+
+static bool qt_gst_element_is_functioning(QGstElement element)
+{
+ GstStateChangeReturn ret = element.setState(GST_STATE_READY);
+ if (ret == GST_STATE_CHANGE_SUCCESS) {
+ element.setState(GST_STATE_NULL);
+ return true;
+ }
+
+ return false;
+}
+
+static QGstElement findBestVideoSink()
+{
+ using namespace Qt::StringLiterals;
+ QString platform = QGuiApplication::platformName();
+
+ // First, try some known video sinks, depending on the Qt platform plugin in use.
+ for (const auto &i : elementMap) {
+ if (platform != i.qtPlatform)
+ continue;
+ QGstElement choice = QGstElement::createFromFactory(i.gstreamerElement, i.gstreamerElement);
+ if (choice.isNull())
+ continue;
+
+ if (qt_gst_element_is_functioning(choice))
+ return choice;
+ }
+
+ // We need a native window ID to use the GstVideoOverlay interface.
+ // Bail out if the Qt platform plugin in use cannot provide a sensible WId.
+ if (platform != QStringView{ u"xcb" } && platform != QStringView{ u"wayland" })
+ return {};
+
+ QGstElement choice;
+ // If none of the known video sinks are available, try to find one that implements the
+ // GstVideoOverlay interface and has autoplugging rank.
+ GList *list = qt_gst_video_sinks();
+ for (GstElementFactory *f : QGstUtils::GListRangeAdaptor<GstElementFactory *>(list)) {
+ if (!gst_element_factory_has_interface(f, "GstVideoOverlay"))
+ continue;
+
+ choice = QGstElement::createFromFactory(f, nullptr);
+ if (choice.isNull())
+ continue;
+
+ if (qt_gst_element_is_functioning(choice))
+ break;
+ choice = {};
+ }
+
+ gst_plugin_feature_list_free(list);
+ if (choice.isNull())
+ qWarning() << "Could not find a valid windowed video sink";
+
+ return choice;
+}
+
+QGstreamerVideoOverlay::QGstreamerVideoOverlay(QGstreamerVideoSink *parent, const QByteArray &elementName)
+ : QObject(parent)
+ , QGstreamerBufferProbe(QGstreamerBufferProbe::ProbeCaps)
+ , m_gstreamerVideoSink(parent)
+{
+ QGstElement sink;
+ if (!elementName.isEmpty())
+ sink = QGstElement::createFromFactory(elementName.constData());
+ else
+ sink = findBestVideoSink();
+
+ setVideoSink(sink);
+}
+
+QGstreamerVideoOverlay::~QGstreamerVideoOverlay()
+{
+ if (!m_videoSink.isNull()) {
+ QGstPad pad = m_videoSink.staticPad("sink");
+ removeProbeFromPad(pad.pad());
+ }
+}
+
+QGstElement QGstreamerVideoOverlay::videoSink() const
+{
+ return m_videoSink;
+}
+
+void QGstreamerVideoOverlay::setVideoSink(QGstElement sink)
+{
+ if (sink.isNull())
+ return;
+
+ m_videoSink = std::move(sink);
+
+ QGstPad pad = m_videoSink.staticPad("sink");
+ addProbeToPad(pad.pad());
+
+ auto *klass = G_OBJECT_GET_CLASS(m_videoSink.object());
+ m_hasForceAspectRatio = g_object_class_find_property(klass, "force-aspect-ratio");
+ m_hasFullscreen = g_object_class_find_property(klass, "fullscreen");
+}
+
+QSize QGstreamerVideoOverlay::nativeVideoSize() const
+{
+ return m_nativeVideoSize;
+}
+
+void QGstreamerVideoOverlay::setWindowHandle(WId id)
+{
+ m_windowId = id;
+
+ if (!m_videoSink.isNull() && GST_IS_VIDEO_OVERLAY(m_videoSink.object())) {
+ applyRenderRect();
+
+ // Properties need to be reset when changing the winId.
+ setAspectRatioMode(m_aspectRatioMode);
+ setFullScreen(m_fullScreen);
+ applyRenderRect();
+ }
+}
+
+void QGstreamerVideoOverlay::setRenderRectangle(const QRect &rect)
+{
+ renderRect = rect;
+ applyRenderRect();
+}
+
+void QGstreamerVideoOverlay::applyRenderRect()
+{
+ if (!m_windowId)
+ return;
+
+ int x = -1;
+ int y = -1;
+ int w = -1;
+ int h = -1;
+
+ if (!renderRect.isEmpty()) {
+ x = renderRect.x();
+ y = renderRect.y();
+ w = renderRect.width();
+ h = renderRect.height();
+ QSize scaledVideo = m_nativeVideoSize.scaled(w, h, m_aspectRatioMode);
+ x += (w - scaledVideo.width())/2;
+ y += (h - scaledVideo.height())/2;
+ w = scaledVideo.width();
+ h = scaledVideo.height();
+ }
+
+ if (!m_videoSink.isNull() && GST_IS_VIDEO_OVERLAY(m_videoSink.object()))
+ gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(m_videoSink.object()), x, y, w, h);
+}
+
+void QGstreamerVideoOverlay::probeCaps(GstCaps *caps)
+{
+ QSize size = QGstCaps(caps, QGstCaps::NeedsRef).at(0).resolution();
+ if (size != m_nativeVideoSize) {
+ m_nativeVideoSize = size;
+ m_gstreamerVideoSink->setNativeSize(m_nativeVideoSize);
+ applyRenderRect();
+ }
+}
+
+void QGstreamerVideoOverlay::setAspectRatioMode(Qt::AspectRatioMode mode)
+{
+ m_aspectRatioMode = mode;
+ if (m_hasForceAspectRatio)
+ m_videoSink.set("force-aspect-ratio", (mode == Qt::KeepAspectRatio));
+}
+
+void QGstreamerVideoOverlay::setFullScreen(bool fullscreen)
+{
+ m_fullScreen = fullscreen;
+ if (m_hasFullscreen)
+ m_videoSink.set("fullscreen", fullscreen);
+}
+
+bool QGstreamerVideoOverlay::processSyncMessage(const QGstreamerMessage &message)
+{
+ if (!gst_is_video_overlay_prepare_window_handle_message(message.message()))
+ return false;
+ gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(m_videoSink.object()), m_windowId);
+ return true;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qgstreamervideooverlay_p.cpp"
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamervideooverlay_p.h b/src/plugins/multimedia/gstreamer/common/qgstreamervideooverlay_p.h
new file mode 100644
index 000000000..588e8b5e4
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamervideooverlay_p.h
@@ -0,0 +1,74 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERVIDEOOVERLAY_P_H
+#define QGSTREAMERVIDEOOVERLAY_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <common/qgstpipeline_p.h>
+#include <common/qgstreamerbufferprobe_p.h>
+#include <common/qgst_p.h>
+#include <QtGui/qwindowdefs.h>
+
+QT_BEGIN_NAMESPACE
+class QGstreamerVideoSink;
+
+class QGstreamerVideoOverlay : public QObject,
+ public QGstreamerSyncMessageFilter,
+ private QGstreamerBufferProbe
+{
+ Q_OBJECT
+public:
+ explicit QGstreamerVideoOverlay(QGstreamerVideoSink *parent = nullptr,
+ const QByteArray &elementName = QByteArray());
+ virtual ~QGstreamerVideoOverlay();
+
+ QGstElement videoSink() const;
+ void setVideoSink(QGstElement);
+ QSize nativeVideoSize() const;
+
+ void setWindowHandle(WId id);
+ void setRenderRectangle(const QRect &rect);
+
+ void setAspectRatioMode(Qt::AspectRatioMode mode);
+ void setFullScreen(bool fullscreen);
+
+ bool processSyncMessage(const QGstreamerMessage &message) override;
+
+ bool isNull() const { return m_videoSink.isNull(); }
+
+Q_SIGNALS:
+ void nativeVideoSizeChanged();
+ void activeChanged();
+
+private:
+ void probeCaps(GstCaps *caps) override;
+ void applyRenderRect();
+
+ QGstreamerVideoSink *m_gstreamerVideoSink = nullptr;
+ QGstElement m_videoSink;
+ QSize m_nativeVideoSize;
+
+ bool m_hasForceAspectRatio = false;
+ bool m_hasFullscreen = false;
+ Qt::AspectRatioMode m_aspectRatioMode = Qt::KeepAspectRatio;
+ bool m_fullScreen = false;
+
+ WId m_windowId = 0;
+ QRect renderRect;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGSTREAMERVIDEOOVERLAY_P_H
+
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamervideosink.cpp b/src/plugins/multimedia/gstreamer/common/qgstreamervideosink.cpp
new file mode 100644
index 000000000..bf3ca4239
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamervideosink.cpp
@@ -0,0 +1,312 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <common/qgstreamervideosink_p.h>
+#include <common/qgstvideorenderersink_p.h>
+#include <common/qgstsubtitlesink_p.h>
+#include <common/qgst_debug_p.h>
+#include <common/qgstutils_p.h>
+#include <rhi/qrhi.h>
+
+#if QT_CONFIG(gstreamer_gl)
+#include <QGuiApplication>
+#include <QtGui/qopenglcontext.h>
+#include <QWindow>
+#include <qpa/qplatformnativeinterface.h>
+#include <gst/gl/gstglconfig.h>
+
+#if GST_GL_HAVE_WINDOW_X11 && __has_include("X11/Xlib-xcb.h")
+# include <gst/gl/x11/gstgldisplay_x11.h>
+#endif
+#if GST_GL_HAVE_PLATFORM_EGL
+# include <gst/gl/egl/gstgldisplay_egl.h>
+# include <EGL/egl.h>
+# include <EGL/eglext.h>
+#endif
+#if GST_GL_HAVE_WINDOW_WAYLAND && __has_include("wayland-client.h")
+# include <gst/gl/wayland/gstgldisplay_wayland.h>
+#endif
+#endif // #if QT_CONFIG(gstreamer_gl)
+
+#include <QtCore/qdebug.h>
+
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcGstVideoSink, "qt.multimedia.gstvideosink");
+
+QGstreamerVideoSink::QGstreamerVideoSink(QVideoSink *parent)
+ : QPlatformVideoSink{
+ parent,
+ },
+ sinkBin{
+ QGstBin::create("videoSinkBin"),
+ }
+{
+ // This is a hack for some iMX and NVidia platforms. These require the use of a special video
+ // conversion element in the pipeline before the video sink, as they unfortunately
+ // output some proprietary format from the decoder even though it's sometimes marked as
+ // a regular supported video/x-raw format.
+ //
+ // To fix this, simply insert the element into the pipeline if it's available. Otherwise
+ // we simply use an identity element.
+ QGstElementFactoryHandle factory;
+
+ // QT_GSTREAMER_OVERRIDE_VIDEO_CONVERSION_ELEMENT allows users to override the
+ // conversion element. Ideally we construct the element programatically, though.
+ QByteArray preprocessOverride = qgetenv("QT_GSTREAMER_OVERRIDE_VIDEO_CONVERSION_ELEMENT");
+ if (!preprocessOverride.isEmpty()) {
+ qCDebug(qLcGstVideoSink) << "requesting conversion element from environment:"
+ << preprocessOverride;
+
+ gstPreprocess = QGstBin::createFromPipelineDescription(preprocessOverride, nullptr,
+ /*ghostUnlinkedPads=*/true);
+ if (!gstPreprocess)
+ qCWarning(qLcGstVideoSink) << "Cannot create conversion element:" << preprocessOverride;
+ }
+
+ if (!gstPreprocess) {
+ // This is a hack for some iMX and NVidia platforms. These require the use of a special
+ // video conversion element in the pipeline before the video sink, as they unfortunately
+ // output some proprietary format from the decoder even though it's sometimes marked as
+ // a regular supported video/x-raw format.
+ static constexpr auto decodersToTest = {
+ "imxvideoconvert_g2d",
+ "nvvidconv",
+ };
+
+ for (const char *decoder : decodersToTest) {
+ factory = QGstElement::findFactory(decoder);
+ if (factory)
+ break;
+ }
+
+ if (factory) {
+ qCDebug(qLcGstVideoSink)
+ << "instantiating conversion element:"
+ << g_type_name(gst_element_factory_get_element_type(factory.get()));
+
+ gstPreprocess = QGstElement::createFromFactory(factory, "preprocess");
+ }
+ }
+
+ bool disablePixelAspectRatio =
+ qEnvironmentVariableIsSet("QT_GSTREAMER_DISABLE_PIXEL_ASPECT_RATIO");
+ if (disablePixelAspectRatio) {
+ // Enabling the pixel aspect ratio may expose a gstreamer bug on cameras that don't expose a
+ // pixel-aspect-ratio via `VIDIOC_CROPCAP`. This can cause the caps negotiation to fail.
+ // Using the QT_GSTREAMER_DISABLE_PIXEL_ASPECT_RATIO environment variable, one can disable
+ // pixel-aspect-ratio handling
+ //
+ // compare: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6242
+ gstCapsFilter =
+ QGstElement::createFromFactory("identity", "nullPixelAspectRatioCapsFilter");
+ } else {
+ gstCapsFilter = QGstElement::createFromFactory("capsfilter", "pixelAspectRatioCapsFilter");
+ QGstCaps capsFilterCaps{
+ gst_caps_new_simple("video/x-raw", "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL),
+ QGstCaps::HasRef,
+ };
+ g_object_set(gstCapsFilter.element(), "caps", capsFilterCaps.caps(), NULL);
+ }
+
+ if (gstPreprocess) {
+ sinkBin.add(gstPreprocess, gstCapsFilter);
+ qLinkGstElements(gstPreprocess, gstCapsFilter);
+ sinkBin.addGhostPad(gstPreprocess, "sink");
+ } else {
+ sinkBin.add(gstCapsFilter);
+ sinkBin.addGhostPad(gstCapsFilter, "sink");
+ }
+
+ gstSubtitleSink =
+ QGstElement(GST_ELEMENT(QGstSubtitleSink::createSink(this)), QGstElement::NeedsRef);
+}
+
+QGstreamerVideoSink::~QGstreamerVideoSink()
+{
+ emit aboutToBeDestroyed();
+
+ unrefGstContexts();
+
+ setPipeline(QGstPipeline());
+}
+
+QGstElement QGstreamerVideoSink::gstSink()
+{
+ updateSinkElement();
+ return sinkBin;
+}
+
+void QGstreamerVideoSink::setPipeline(QGstPipeline pipeline)
+{
+ gstPipeline = std::move(pipeline);
+}
+
+bool QGstreamerVideoSink::inStoppedState() const
+{
+ if (gstPipeline.isNull())
+ return true;
+ return gstPipeline.inStoppedState();
+}
+
+void QGstreamerVideoSink::setRhi(QRhi *rhi)
+{
+ if (rhi && rhi->backend() != QRhi::OpenGLES2)
+ rhi = nullptr;
+ if (m_rhi == rhi)
+ return;
+
+ m_rhi = rhi;
+ updateGstContexts();
+ if (!gstQtSink.isNull()) {
+ // force creation of a new sink with proper caps
+ createQtSink();
+ updateSinkElement();
+ }
+}
+
+void QGstreamerVideoSink::createQtSink()
+{
+ if (gstQtSink)
+ gstQtSink.setStateSync(GST_STATE_NULL);
+
+ gstQtSink = QGstElement(reinterpret_cast<GstElement *>(QGstVideoRendererSink::createSink(this)),
+ QGstElement::NeedsRef);
+}
+
+void QGstreamerVideoSink::updateSinkElement()
+{
+ QGstElement newSink;
+ if (gstQtSink.isNull())
+ createQtSink();
+ newSink = gstQtSink;
+
+ if (newSink == gstVideoSink)
+ return;
+
+ gstPipeline.modifyPipelineWhileNotRunning([&] {
+ if (!gstVideoSink.isNull())
+ sinkBin.stopAndRemoveElements(gstVideoSink);
+
+ newSink.set("async", false); // no asynchronous state changes
+
+ gstVideoSink = newSink;
+ sinkBin.add(gstVideoSink);
+ qLinkGstElements(gstCapsFilter, gstVideoSink);
+ gstVideoSink.setState(GST_STATE_PAUSED);
+ });
+
+ gstPipeline.dumpGraph("updateVideoSink");
+}
+
+void QGstreamerVideoSink::unrefGstContexts()
+{
+ m_gstGlDisplayContext.close();
+ m_gstGlLocalContext.close();
+ m_eglDisplay = nullptr;
+ m_eglImageTargetTexture2D = nullptr;
+}
+
+void QGstreamerVideoSink::updateGstContexts()
+{
+ using namespace Qt::Literals;
+
+ unrefGstContexts();
+
+#if QT_CONFIG(gstreamer_gl)
+ if (!m_rhi || m_rhi->backend() != QRhi::OpenGLES2)
+ return;
+
+ auto *nativeHandles = static_cast<const QRhiGles2NativeHandles *>(m_rhi->nativeHandles());
+ auto glContext = nativeHandles->context;
+ Q_ASSERT(glContext);
+
+ const QString platform = QGuiApplication::platformName();
+ QPlatformNativeInterface *pni = QGuiApplication::platformNativeInterface();
+ m_eglDisplay = pni->nativeResourceForIntegration("egldisplay"_ba);
+// qDebug() << "platform is" << platform << m_eglDisplay;
+
+ QGstGLDisplayHandle gstGlDisplay;
+
+ QByteArray contextName = "eglcontext"_ba;
+ GstGLPlatform glPlatform = GST_GL_PLATFORM_EGL;
+ // use the egl display if we have one
+ if (m_eglDisplay) {
+#if GST_GL_HAVE_PLATFORM_EGL
+ gstGlDisplay.reset(
+ GST_GL_DISPLAY_CAST(gst_gl_display_egl_new_with_egl_display(m_eglDisplay)));
+ m_eglImageTargetTexture2D = eglGetProcAddress("glEGLImageTargetTexture2DOES");
+#endif
+ } else {
+ auto display = pni->nativeResourceForIntegration("display"_ba);
+
+ if (display) {
+#if GST_GL_HAVE_WINDOW_X11 && __has_include("X11/Xlib-xcb.h")
+ if (platform == QLatin1String("xcb")) {
+ contextName = "glxcontext"_ba;
+ glPlatform = GST_GL_PLATFORM_GLX;
+
+ gstGlDisplay.reset(GST_GL_DISPLAY_CAST(
+ gst_gl_display_x11_new_with_display(reinterpret_cast<Display *>(display))));
+ }
+#endif
+#if GST_GL_HAVE_WINDOW_WAYLAND && __has_include("wayland-client.h")
+ if (platform.startsWith(QLatin1String("wayland"))) {
+ Q_ASSERT(!gstGlDisplay);
+ gstGlDisplay.reset(GST_GL_DISPLAY_CAST(gst_gl_display_wayland_new_with_display(
+ reinterpret_cast<struct wl_display *>(display))));
+ }
+#endif
+ }
+ }
+
+ if (!gstGlDisplay) {
+ qWarning() << "Could not create GstGLDisplay";
+ return;
+ }
+
+ void *nativeContext = pni->nativeResourceForContext(contextName, glContext);
+ if (!nativeContext)
+ qWarning() << "Could not find resource for" << contextName;
+
+ GstGLAPI glApi = QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL ? GST_GL_API_OPENGL : GST_GL_API_GLES2;
+ QGstGLContextHandle appContext{
+ gst_gl_context_new_wrapped(gstGlDisplay.get(), guintptr(nativeContext), glPlatform, glApi),
+ };
+ if (!appContext)
+ qWarning() << "Could not create wrappped context for platform:" << glPlatform;
+
+ gst_gl_context_activate(appContext.get(), true);
+
+ QUniqueGErrorHandle error;
+ gst_gl_context_fill_info(appContext.get(), &error);
+ if (error) {
+ qWarning() << "Could not fill context info:" << error;
+ error = {};
+ }
+
+ QGstGLContextHandle displayContext;
+ gst_gl_display_create_context(gstGlDisplay.get(), appContext.get(), &displayContext, &error);
+ if (error)
+ qWarning() << "Could not create display context:" << error;
+
+ appContext.close();
+
+ m_gstGlDisplayContext.reset(gst_context_new(GST_GL_DISPLAY_CONTEXT_TYPE, false));
+ gst_context_set_gl_display(m_gstGlDisplayContext.get(), gstGlDisplay.get());
+
+ m_gstGlLocalContext.reset(gst_context_new("gst.gl.local_context", false));
+ GstStructure *structure = gst_context_writable_structure(m_gstGlLocalContext.get());
+ gst_structure_set(structure, "context", GST_TYPE_GL_CONTEXT, displayContext.get(), nullptr);
+ displayContext.close();
+
+ if (!gstPipeline.isNull())
+ gst_element_set_context(gstPipeline.element(), m_gstGlLocalContext.get());
+#endif // #if QT_CONFIG(gstreamer_gl)
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qgstreamervideosink_p.cpp"
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamervideosink_p.h b/src/plugins/multimedia/gstreamer/common/qgstreamervideosink_p.h
new file mode 100644
index 000000000..da00903fb
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstreamervideosink_p.h
@@ -0,0 +1,76 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERVIDEOSINK_H
+#define QGSTREAMERVIDEOSINK_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qvideosink.h>
+#include <QtMultimedia/private/qplatformvideosink_p.h>
+
+#include <common/qgstpipeline_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerVideoSink : public QPlatformVideoSink
+{
+ Q_OBJECT
+
+public:
+ explicit QGstreamerVideoSink(QVideoSink *parent = nullptr);
+ ~QGstreamerVideoSink();
+
+ void setRhi(QRhi *rhi) override;
+ QRhi *rhi() const { return m_rhi; }
+
+ QGstElement gstSink();
+ QGstElement subtitleSink() const { return gstSubtitleSink; }
+
+ void setPipeline(QGstPipeline pipeline);
+ bool inStoppedState() const;
+
+ GstContext *gstGlDisplayContext() const { return m_gstGlDisplayContext.get(); }
+ GstContext *gstGlLocalContext() const { return m_gstGlLocalContext.get(); }
+ Qt::HANDLE eglDisplay() const { return m_eglDisplay; }
+ QFunctionPointer eglImageTargetTexture2D() const { return m_eglImageTargetTexture2D; }
+
+Q_SIGNALS:
+ void aboutToBeDestroyed();
+
+private:
+ void createQtSink();
+ void updateSinkElement();
+
+ void unrefGstContexts();
+ void updateGstContexts();
+
+ QGstPipeline gstPipeline;
+ QGstBin sinkBin;
+ QGstElement gstPreprocess;
+ QGstElement gstCapsFilter;
+ QGstElement gstVideoSink;
+ QGstElement gstQtSink;
+ QGstElement gstSubtitleSink;
+
+ QRhi *m_rhi = nullptr;
+
+ Qt::HANDLE m_eglDisplay = nullptr;
+ QFunctionPointer m_eglImageTargetTexture2D = nullptr;
+
+ QGstContextHandle m_gstGlLocalContext;
+ QGstContextHandle m_gstGlDisplayContext;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstsubtitlesink.cpp b/src/plugins/multimedia/gstreamer/common/qgstsubtitlesink.cpp
new file mode 100644
index 000000000..c6b230d85
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstsubtitlesink.cpp
@@ -0,0 +1,155 @@
+// Copyright (C) 2021 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QDebug>
+#include <QThread>
+#include <QEvent>
+
+#include "qgstreamervideosink_p.h"
+#include "qgstsubtitlesink_p.h"
+
+QT_BEGIN_NAMESPACE
+
+static GstBaseSinkClass *gst_sink_parent_class;
+static thread_local QGstreamerVideoSink *gst_current_sink;
+
+#define ST_SINK(s) QGstSubtitleSink *sink(reinterpret_cast<QGstSubtitleSink *>(s))
+
+QGstSubtitleSink *QGstSubtitleSink::createSink(QGstreamerVideoSink *sink)
+{
+ gst_current_sink = sink;
+
+ QGstSubtitleSink *gstSink = reinterpret_cast<QGstSubtitleSink *>(
+ g_object_new(QGstSubtitleSink::get_type(), nullptr));
+ g_object_set(gstSink, "async", false, nullptr);
+
+ return gstSink;
+}
+
+GType QGstSubtitleSink::get_type()
+{
+ static const GTypeInfo info =
+ {
+ sizeof(QGstSubtitleSinkClass), // class_size
+ base_init, // base_init
+ nullptr, // base_finalize
+ class_init, // class_init
+ nullptr, // class_finalize
+ nullptr, // class_data
+ sizeof(QGstSubtitleSink), // instance_size
+ 0, // n_preallocs
+ instance_init, // instance_init
+ nullptr // value_table
+ };
+
+ static const GType type = []() {
+ const auto result = g_type_register_static(
+ GST_TYPE_BASE_SINK, "QGstSubtitleSink", &info, GTypeFlags(0));
+
+ // Register the sink type to be used in custom piplines.
+ // When surface is ready the sink can be used.
+ gst_element_register(nullptr, "qtsubtitlesink", GST_RANK_PRIMARY, result);
+
+ return result;
+ }();
+
+ return type;
+}
+
+void QGstSubtitleSink::class_init(gpointer g_class, gpointer class_data)
+{
+ Q_UNUSED(class_data);
+
+ gst_sink_parent_class = reinterpret_cast<GstBaseSinkClass *>(g_type_class_peek_parent(g_class));
+
+ GstBaseSinkClass *base_sink_class = reinterpret_cast<GstBaseSinkClass *>(g_class);
+ base_sink_class->render = QGstSubtitleSink::render;
+ base_sink_class->get_caps = QGstSubtitleSink::get_caps;
+ base_sink_class->set_caps = QGstSubtitleSink::set_caps;
+ base_sink_class->propose_allocation = QGstSubtitleSink::propose_allocation;
+ base_sink_class->wait_event = QGstSubtitleSink::wait_event;
+
+ GstElementClass *element_class = reinterpret_cast<GstElementClass *>(g_class);
+ element_class->change_state = QGstSubtitleSink::change_state;
+ gst_element_class_set_metadata(element_class,
+ "Qt built-in subtitle sink",
+ "Sink/Subtitle",
+ "Qt default built-in subtitle sink",
+ "The Qt Company");
+
+ GObjectClass *object_class = reinterpret_cast<GObjectClass *>(g_class);
+ object_class->finalize = QGstSubtitleSink::finalize;
+}
+
+void QGstSubtitleSink::base_init(gpointer g_class)
+{
+ static GstStaticPadTemplate sink_pad_template = GST_STATIC_PAD_TEMPLATE(
+ "sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS("ANY"));
+
+ gst_element_class_add_pad_template(
+ GST_ELEMENT_CLASS(g_class), gst_static_pad_template_get(&sink_pad_template));
+}
+
+void QGstSubtitleSink::instance_init(GTypeInstance *instance, gpointer g_class)
+{
+ Q_UNUSED(g_class);
+ ST_SINK(instance);
+
+ Q_ASSERT(gst_current_sink);
+ sink->sink = gst_current_sink;
+ gst_current_sink = nullptr;
+}
+
+void QGstSubtitleSink::finalize(GObject *object)
+{
+ // Chain up
+ G_OBJECT_CLASS(gst_sink_parent_class)->finalize(object);
+}
+
+GstStateChangeReturn QGstSubtitleSink::change_state(GstElement *element, GstStateChange transition)
+{
+ return GST_ELEMENT_CLASS(gst_sink_parent_class)->change_state(element, transition);
+}
+
+GstCaps *QGstSubtitleSink::get_caps(GstBaseSink *base, GstCaps *filter)
+{
+ return gst_sink_parent_class->get_caps(base, filter);
+}
+
+gboolean QGstSubtitleSink::set_caps(GstBaseSink *base, GstCaps *caps)
+{
+ qDebug() << "set_caps:" << caps;
+ return gst_sink_parent_class->set_caps(base, caps);
+}
+
+gboolean QGstSubtitleSink::propose_allocation(GstBaseSink *base, GstQuery *query)
+{
+ return gst_sink_parent_class->propose_allocation(base, query);
+}
+
+GstFlowReturn QGstSubtitleSink::wait_event(GstBaseSink *base, GstEvent *event)
+{
+ GstFlowReturn retval = gst_sink_parent_class->wait_event(base, event);
+ ST_SINK(base);
+ if (event->type == GST_EVENT_GAP) {
+// qDebug() << "gap, clearing subtitle";
+ sink->sink->setSubtitleText(QString());
+ }
+ return retval;
+}
+
+GstFlowReturn QGstSubtitleSink::render(GstBaseSink *base, GstBuffer *buffer)
+{
+ ST_SINK(base);
+ GstMemory *mem = gst_buffer_get_memory(buffer, 0);
+ GstMapInfo info;
+ QString subtitle;
+ if (gst_memory_map(mem, &info, GST_MAP_READ))
+ subtitle = QString::fromUtf8(reinterpret_cast<const char *>(info.data));
+ gst_memory_unmap(mem, &info);
+// qDebug() << "render" << buffer << subtitle;
+ sink->sink->setSubtitleText(subtitle);
+ return GST_FLOW_OK;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgstsubtitlesink_p.h b/src/plugins/multimedia/gstreamer/common/qgstsubtitlesink_p.h
new file mode 100644
index 000000000..0f515cb99
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstsubtitlesink_p.h
@@ -0,0 +1,70 @@
+// Copyright (C) 2021 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTSUBTITLESINK_P_H
+#define QGSTSUBTITLESINK_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/private/qtmultimediaglobal_p.h>
+
+#include <QtCore/qlist.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qqueue.h>
+#include <QtCore/qpointer.h>
+#include <QtCore/qwaitcondition.h>
+#include <common/qgst_p.h>
+#include <gst/base/gstbasesink.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerVideoSink;
+
+class QGstSubtitleSink
+{
+public:
+ GstBaseSink parent{};
+
+ static QGstSubtitleSink *createSink(QGstreamerVideoSink *sink);
+
+private:
+ static GType get_type();
+ static void class_init(gpointer g_class, gpointer class_data);
+ static void base_init(gpointer g_class);
+ static void instance_init(GTypeInstance *instance, gpointer g_class);
+
+ static void finalize(GObject *object);
+
+ static GstStateChangeReturn change_state(GstElement *element, GstStateChange transition);
+
+ static GstCaps *get_caps(GstBaseSink *sink, GstCaps *filter);
+ static gboolean set_caps(GstBaseSink *sink, GstCaps *caps);
+
+ static gboolean propose_allocation(GstBaseSink *sink, GstQuery *query);
+
+ static GstFlowReturn wait_event(GstBaseSink * sink, GstEvent * event);
+ static GstFlowReturn render(GstBaseSink *sink, GstBuffer *buffer);
+
+private:
+ QGstreamerVideoSink *sink = nullptr;
+};
+
+
+class QGstSubtitleSinkClass
+{
+public:
+ GstBaseSinkClass parent_class;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstutils.cpp b/src/plugins/multimedia/gstreamer/common/qgstutils.cpp
new file mode 100644
index 000000000..8ec2bde3c
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstutils.cpp
@@ -0,0 +1,141 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <common/qgstutils_p.h>
+#include <common/qgst_p.h>
+
+#include <QtMultimedia/qaudioformat.h>
+
+#include <chrono>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+
+const char *audioSampleFormatNames[QAudioFormat::NSampleFormats] = {
+ nullptr,
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ "U8",
+ "S16LE",
+ "S32LE",
+ "F32LE"
+#else
+ "U8",
+ "S16BE",
+ "S32BE",
+ "F32BE"
+#endif
+};
+
+QAudioFormat::SampleFormat gstSampleFormatToSampleFormat(const char *fmt)
+{
+ if (fmt) {
+ for (int i = 1; i < QAudioFormat::NSampleFormats; ++i) {
+ if (strcmp(fmt, audioSampleFormatNames[i]))
+ continue;
+ return QAudioFormat::SampleFormat(i);
+ }
+ }
+ return QAudioFormat::Unknown;
+}
+
+} // namespace
+
+/*
+ Returns audio format for a sample \a sample.
+ If the buffer doesn't have a valid audio format, an empty QAudioFormat is returned.
+*/
+QAudioFormat QGstUtils::audioFormatForSample(GstSample *sample)
+{
+ auto caps = QGstCaps(gst_sample_get_caps(sample), QGstCaps::NeedsRef);
+ if (caps.isNull())
+ return {};
+ return audioFormatForCaps(caps);
+}
+
+QAudioFormat QGstUtils::audioFormatForCaps(const QGstCaps &caps)
+{
+ QAudioFormat format;
+ QGstStructureView s = caps.at(0);
+ if (s.name() != "audio/x-raw")
+ return format;
+
+ auto rate = s["rate"].toInt();
+ auto channels = s["channels"].toInt();
+ QAudioFormat::SampleFormat fmt = gstSampleFormatToSampleFormat(s["format"].toString());
+ if (!rate || !channels || fmt == QAudioFormat::Unknown)
+ return format;
+
+ format.setSampleRate(*rate);
+ format.setChannelCount(*channels);
+ format.setSampleFormat(fmt);
+
+ return format;
+}
+
+/*
+ Builds GstCaps for an audio format \a format.
+ Returns 0 if the audio format is not valid.
+
+ \note Caller must unreference GstCaps.
+*/
+
+QGstCaps QGstUtils::capsForAudioFormat(const QAudioFormat &format)
+{
+ if (!format.isValid())
+ return {};
+
+ auto sampleFormat = format.sampleFormat();
+ auto caps = gst_caps_new_simple(
+ "audio/x-raw",
+ "format" , G_TYPE_STRING, audioSampleFormatNames[sampleFormat],
+ "rate" , G_TYPE_INT , format.sampleRate(),
+ "channels", G_TYPE_INT , format.channelCount(),
+ "layout" , G_TYPE_STRING, "interleaved",
+ nullptr);
+
+ return QGstCaps(caps, QGstCaps::HasRef);
+}
+
+QList<QAudioFormat::SampleFormat> QGValue::getSampleFormats() const
+{
+ if (!GST_VALUE_HOLDS_LIST(value))
+ return {};
+
+ QList<QAudioFormat::SampleFormat> formats;
+ guint nFormats = gst_value_list_get_size(value);
+ for (guint f = 0; f < nFormats; ++f) {
+ QGValue v = QGValue{ gst_value_list_get_value(value, f) };
+ auto *name = v.toString();
+ QAudioFormat::SampleFormat fmt = gstSampleFormatToSampleFormat(name);
+ if (fmt == QAudioFormat::Unknown)
+ continue;
+ formats.append(fmt);
+ }
+ return formats;
+}
+
+void QGstUtils::setFrameTimeStampsFromBuffer(QVideoFrame *frame, GstBuffer *buffer)
+{
+ using namespace std::chrono;
+ using namespace std::chrono_literals;
+
+ // GStreamer uses nanoseconds, Qt uses microseconds
+ nanoseconds startTime{ GST_BUFFER_TIMESTAMP(buffer) };
+ if (startTime >= 0ns) {
+ frame->setStartTime(floor<microseconds>(startTime).count());
+
+ nanoseconds duration{ GST_BUFFER_DURATION(buffer) };
+ if (duration >= 0ns)
+ frame->setEndTime(floor<microseconds>(startTime + duration).count());
+ }
+}
+
+GList *qt_gst_video_sinks()
+{
+ return gst_element_factory_list_get_elements(GST_ELEMENT_FACTORY_TYPE_SINK
+ | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO,
+ GST_RANK_MARGINAL);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgstutils_p.h b/src/plugins/multimedia/gstreamer/common/qgstutils_p.h
new file mode 100644
index 000000000..c65fcf090
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstutils_p.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTUTILS_P_H
+#define QGSTUTILS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <gst/gstsample.h>
+#include <gst/gstbuffer.h>
+
+#include <QtCore/qglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioFormat;
+class QGstCaps;
+class QVideoFrame;
+
+namespace QGstUtils {
+QAudioFormat audioFormatForSample(GstSample *sample);
+QAudioFormat audioFormatForCaps(const QGstCaps &caps);
+QGstCaps capsForAudioFormat(const QAudioFormat &format);
+
+void setFrameTimeStampsFromBuffer(QVideoFrame *frame, GstBuffer *buffer);
+} // namespace QGstUtils
+
+GList *qt_gst_video_sinks();
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstvideobuffer.cpp b/src/plugins/multimedia/gstreamer/common/qgstvideobuffer.cpp
new file mode 100644
index 000000000..be6342ea8
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstvideobuffer.cpp
@@ -0,0 +1,393 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qgstvideobuffer_p.h"
+#include "qgstreamervideosink_p.h"
+#include <private/qvideotexturehelper_p.h>
+#include <qpa/qplatformnativeinterface.h>
+#include <qguiapplication.h>
+
+#include <gst/video/video.h>
+#include <gst/video/video-frame.h>
+#include <gst/video/gstvideometa.h>
+#include <gst/pbutils/gstpluginsbaseversion.h>
+
+#include <common/qgstutils_p.h>
+
+#if QT_CONFIG(gstreamer_gl)
+# include <QtGui/rhi/qrhi.h>
+# include <QtGui/qopenglcontext.h>
+# include <QtGui/qopenglfunctions.h>
+# include <QtGui/qopengl.h>
+
+# include <gst/gl/gstglconfig.h>
+# include <gst/gl/gstglmemory.h>
+# include <gst/gl/gstglsyncmeta.h>
+
+# include <EGL/egl.h>
+# include <EGL/eglext.h>
+
+# if QT_CONFIG(linux_dmabuf)
+# include <gst/allocators/gstdmabuf.h>
+# endif
+#endif
+
+QT_BEGIN_NAMESPACE
+
+// keep things building without drm_fourcc.h
+#define fourcc_code(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
+ ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
+
+#define DRM_FORMAT_RGBA8888 fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */
+#define DRM_FORMAT_RGB888 fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */
+#define DRM_FORMAT_RG88 fourcc_code('R', 'G', '8', '8') /* [15:0] R:G 8:8 little endian */
+#define DRM_FORMAT_ABGR8888 fourcc_code('A', 'B', '2', '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */
+#define DRM_FORMAT_BGR888 fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */
+#define DRM_FORMAT_GR88 fourcc_code('G', 'R', '8', '8') /* [15:0] G:R 8:8 little endian */
+#define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R */
+#define DRM_FORMAT_R16 fourcc_code('R', '1', '6', ' ') /* [15:0] R little endian */
+#define DRM_FORMAT_RGB565 fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */
+#define DRM_FORMAT_RG1616 fourcc_code('R', 'G', '3', '2') /* [31:0] R:G 16:16 little endian */
+#define DRM_FORMAT_GR1616 fourcc_code('G', 'R', '3', '2') /* [31:0] G:R 16:16 little endian */
+#define DRM_FORMAT_BGRA1010102 fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
+
+QGstVideoBuffer::QGstVideoBuffer(QGstBufferHandle buffer, const GstVideoInfo &info,
+ QGstreamerVideoSink *sink, const QVideoFrameFormat &frameFormat,
+ QGstCaps::MemoryFormat format)
+ : QHwVideoBuffer((sink && sink->rhi() && format != QGstCaps::CpuMemory)
+ ? QVideoFrame::RhiTextureHandle
+ : QVideoFrame::NoHandle,
+ sink ? sink->rhi() : nullptr),
+ memoryFormat(format),
+ m_frameFormat(frameFormat),
+ m_rhi(sink ? sink->rhi() : nullptr),
+ m_videoInfo(info),
+ m_buffer(std::move(buffer))
+{
+ if (sink) {
+ eglDisplay = sink->eglDisplay();
+ eglImageTargetTexture2D = sink->eglImageTargetTexture2D();
+ }
+
+#if !QT_CONFIG(gstreamer_gl)
+ Q_UNUSED(memoryFormat);
+#endif
+}
+
+QGstVideoBuffer::~QGstVideoBuffer()
+{
+ unmap();
+}
+
+QAbstractVideoBuffer::MapData QGstVideoBuffer::map(QtVideo::MapMode mode)
+{
+ const GstMapFlags flags = GstMapFlags(
+ ((mode & QtVideo::MapMode::ReadOnly ) == QtVideo::MapMode::NotMapped ? 0 : GST_MAP_READ)
+ | ((mode & QtVideo::MapMode::WriteOnly) == QtVideo::MapMode::NotMapped ? 0 : GST_MAP_WRITE));
+
+ MapData mapData;
+ if (mode == QtVideo::MapMode::NotMapped || m_mode != QtVideo::MapMode::NotMapped)
+ return mapData;
+
+ if (m_videoInfo.finfo->n_planes == 0) { // Encoded
+ if (gst_buffer_map(m_buffer.get(), &m_frame.map[0], flags)) {
+ mapData.planeCount = 1;
+ mapData.bytesPerLine[0] = -1;
+ mapData.dataSize[0] = m_frame.map[0].size;
+ mapData.data[0] = static_cast<uchar *>(m_frame.map[0].data);
+
+ m_mode = mode;
+ }
+ } else if (gst_video_frame_map(&m_frame, &m_videoInfo, m_buffer.get(), flags)) {
+ mapData.planeCount = GST_VIDEO_FRAME_N_PLANES(&m_frame);
+
+ for (guint i = 0; i < GST_VIDEO_FRAME_N_PLANES(&m_frame); ++i) {
+ mapData.bytesPerLine[i] = GST_VIDEO_FRAME_PLANE_STRIDE(&m_frame, i);
+ mapData.data[i] = static_cast<uchar *>(GST_VIDEO_FRAME_PLANE_DATA(&m_frame, i));
+ mapData.dataSize[i] = mapData.bytesPerLine[i]*GST_VIDEO_FRAME_COMP_HEIGHT(&m_frame, i);
+ }
+
+ m_mode = mode;
+ }
+ return mapData;
+}
+
+void QGstVideoBuffer::unmap()
+{
+ if (m_mode != QtVideo::MapMode::NotMapped) {
+ if (m_videoInfo.finfo->n_planes == 0)
+ gst_buffer_unmap(m_buffer.get(), &m_frame.map[0]);
+ else
+ gst_video_frame_unmap(&m_frame);
+ }
+ m_mode = QtVideo::MapMode::NotMapped;
+}
+
+#if QT_CONFIG(gstreamer_gl) && QT_CONFIG(linux_dmabuf)
+static int
+fourccFromVideoInfo(const GstVideoInfo * info, int plane)
+{
+ GstVideoFormat format = GST_VIDEO_INFO_FORMAT (info);
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ const gint rgba_fourcc = DRM_FORMAT_ABGR8888;
+ const gint rgb_fourcc = DRM_FORMAT_BGR888;
+ const gint rg_fourcc = DRM_FORMAT_GR88;
+#else
+ const gint rgba_fourcc = DRM_FORMAT_RGBA8888;
+ const gint rgb_fourcc = DRM_FORMAT_RGB888;
+ const gint rg_fourcc = DRM_FORMAT_RG88;
+#endif
+
+ GST_DEBUG ("Getting DRM fourcc for %s plane %i",
+ gst_video_format_to_string (format), plane);
+
+ switch (format) {
+ case GST_VIDEO_FORMAT_RGB16:
+ case GST_VIDEO_FORMAT_BGR16:
+ return DRM_FORMAT_RGB565;
+
+ case GST_VIDEO_FORMAT_RGB:
+ case GST_VIDEO_FORMAT_BGR:
+ return rgb_fourcc;
+
+ case GST_VIDEO_FORMAT_RGBA:
+ case GST_VIDEO_FORMAT_RGBx:
+ case GST_VIDEO_FORMAT_BGRA:
+ case GST_VIDEO_FORMAT_BGRx:
+ case GST_VIDEO_FORMAT_ARGB:
+ case GST_VIDEO_FORMAT_xRGB:
+ case GST_VIDEO_FORMAT_ABGR:
+ case GST_VIDEO_FORMAT_xBGR:
+ case GST_VIDEO_FORMAT_AYUV:
+#if GST_CHECK_PLUGINS_BASE_VERSION(1,16,0)
+ case GST_VIDEO_FORMAT_VUYA:
+#endif
+ return rgba_fourcc;
+
+ case GST_VIDEO_FORMAT_GRAY8:
+ return DRM_FORMAT_R8;
+
+ case GST_VIDEO_FORMAT_YUY2:
+ case GST_VIDEO_FORMAT_UYVY:
+ case GST_VIDEO_FORMAT_GRAY16_LE:
+ case GST_VIDEO_FORMAT_GRAY16_BE:
+ return rg_fourcc;
+
+ case GST_VIDEO_FORMAT_NV12:
+ case GST_VIDEO_FORMAT_NV21:
+ return plane == 0 ? DRM_FORMAT_R8 : rg_fourcc;
+
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ case GST_VIDEO_FORMAT_Y41B:
+ case GST_VIDEO_FORMAT_Y42B:
+ case GST_VIDEO_FORMAT_Y444:
+ return DRM_FORMAT_R8;
+
+#if GST_CHECK_PLUGINS_BASE_VERSION(1,16,0)
+ case GST_VIDEO_FORMAT_BGR10A2_LE:
+ return DRM_FORMAT_BGRA1010102;
+#endif
+
+// case GST_VIDEO_FORMAT_RGB10A2_LE:
+// return DRM_FORMAT_RGBA1010102;
+
+ case GST_VIDEO_FORMAT_P010_10LE:
+// case GST_VIDEO_FORMAT_P012_LE:
+// case GST_VIDEO_FORMAT_P016_LE:
+ return plane == 0 ? DRM_FORMAT_R16 : DRM_FORMAT_GR1616;
+
+ case GST_VIDEO_FORMAT_P010_10BE:
+// case GST_VIDEO_FORMAT_P012_BE:
+// case GST_VIDEO_FORMAT_P016_BE:
+ return plane == 0 ? DRM_FORMAT_R16 : DRM_FORMAT_RG1616;
+
+ default:
+ GST_ERROR ("Unsupported format for DMABuf.");
+ return -1;
+ }
+}
+#endif
+
+#if QT_CONFIG(gstreamer_gl)
+struct GlTextures
+{
+ uint count = 0;
+ bool owned = false;
+ std::array<guint32, QVideoTextureHelper::TextureDescription::maxPlanes> names{};
+};
+
+class QGstQVideoFrameTextures : public QVideoFrameTextures
+{
+public:
+ QGstQVideoFrameTextures(QRhi *rhi, QSize size, QVideoFrameFormat::PixelFormat format, GlTextures &textures)
+ : m_rhi(rhi)
+ , m_glTextures(textures)
+ {
+ auto desc = QVideoTextureHelper::textureDescription(format);
+ for (uint i = 0; i < textures.count; ++i) {
+ QSize planeSize(desc->widthForPlane(size.width(), int(i)),
+ desc->heightForPlane(size.height(), int(i)));
+ m_textures[i].reset(rhi->newTexture(desc->textureFormat[i], planeSize, 1, {}));
+ m_textures[i]->createFrom({textures.names[i], 0});
+ }
+ }
+
+ ~QGstQVideoFrameTextures()
+ {
+ m_rhi->makeThreadLocalNativeContextCurrent();
+ auto ctx = QOpenGLContext::currentContext();
+ if (m_glTextures.owned && ctx)
+ ctx->functions()->glDeleteTextures(int(m_glTextures.count), m_glTextures.names.data());
+ }
+
+ QRhiTexture *texture(uint plane) const override
+ {
+ return plane < m_glTextures.count ? m_textures[plane].get() : nullptr;
+ }
+
+private:
+ QRhi *m_rhi = nullptr;
+ GlTextures m_glTextures;
+ std::unique_ptr<QRhiTexture> m_textures[QVideoTextureHelper::TextureDescription::maxPlanes];
+};
+
+static GlTextures mapFromGlTexture(const QGstBufferHandle &bufferHandle, GstVideoFrame &frame,
+ GstVideoInfo &videoInfo)
+{
+ GstBuffer *buffer = bufferHandle.get();
+ auto *mem = GST_GL_BASE_MEMORY_CAST(gst_buffer_peek_memory(buffer, 0));
+ if (!mem)
+ return {};
+
+ if (!gst_video_frame_map(&frame, &videoInfo, buffer, GstMapFlags(GST_MAP_READ|GST_MAP_GL))) {
+ qWarning() << "Could not map GL textures";
+ return {};
+ }
+
+ auto *sync_meta = gst_buffer_get_gl_sync_meta(buffer);
+ GstBuffer *sync_buffer = nullptr;
+ if (!sync_meta) {
+ sync_buffer = gst_buffer_new();
+ sync_meta = gst_buffer_add_gl_sync_meta(mem->context, sync_buffer);
+ }
+ gst_gl_sync_meta_set_sync_point (sync_meta, mem->context);
+ gst_gl_sync_meta_wait (sync_meta, mem->context);
+ if (sync_buffer)
+ gst_buffer_unref(sync_buffer);
+
+ GlTextures textures;
+ textures.count = frame.info.finfo->n_planes;
+
+ for (uint i = 0; i < textures.count; ++i)
+ textures.names[i] = *(guint32 *)frame.data[i];
+
+ gst_video_frame_unmap(&frame);
+
+ return textures;
+}
+
+#if GST_GL_HAVE_PLATFORM_EGL && QT_CONFIG(linux_dmabuf)
+static GlTextures mapFromDmaBuffer(QRhi *rhi, const QGstBufferHandle &bufferHandle,
+ GstVideoFrame &frame, GstVideoInfo &videoInfo,
+ Qt::HANDLE eglDisplay, QFunctionPointer eglImageTargetTexture2D)
+{
+ GstBuffer *buffer = bufferHandle.get();
+
+ Q_ASSERT(gst_is_dmabuf_memory(gst_buffer_peek_memory(buffer, 0)));
+ Q_ASSERT(eglDisplay);
+ Q_ASSERT(eglImageTargetTexture2D);
+
+ auto *nativeHandles = static_cast<const QRhiGles2NativeHandles *>(rhi->nativeHandles());
+ auto glContext = nativeHandles->context;
+ if (!glContext) {
+ qWarning() << "no GL context";
+ return {};
+ }
+
+ if (!gst_video_frame_map(&frame, &videoInfo, buffer, GstMapFlags(GST_MAP_READ))) {
+ qDebug() << "Couldn't map DMA video frame";
+ return {};
+ }
+
+ GlTextures textures = {};
+ textures.owned = true;
+ textures.count = GST_VIDEO_FRAME_N_PLANES(&frame);
+ // int width = GST_VIDEO_FRAME_WIDTH(&frame);
+ // int height = GST_VIDEO_FRAME_HEIGHT(&frame);
+ Q_ASSERT(GST_VIDEO_FRAME_N_PLANES(&frame) == gst_buffer_n_memory(buffer));
+
+ QOpenGLFunctions functions(glContext);
+ functions.glGenTextures(int(textures.count), textures.names.data());
+
+ // qDebug() << Qt::hex << "glGenTextures: glerror" << glGetError() << "egl error" << eglGetError();
+ // qDebug() << "converting DMA buffer nPlanes=" << nPlanes << m_textures[0] << m_textures[1] << m_textures[2];
+
+ for (int i = 0; i < int(textures.count); ++i) {
+ auto offset = GST_VIDEO_FRAME_PLANE_OFFSET(&frame, i);
+ auto stride = GST_VIDEO_FRAME_PLANE_STRIDE(&frame, i);
+ int planeWidth = GST_VIDEO_FRAME_COMP_WIDTH(&frame, i);
+ int planeHeight = GST_VIDEO_FRAME_COMP_HEIGHT(&frame, i);
+ auto mem = gst_buffer_peek_memory(buffer, i);
+ int fd = gst_dmabuf_memory_get_fd(mem);
+
+ // qDebug() << " plane" << i << "size" << width << height << "stride" << stride << "offset" << offset << "fd=" << fd;
+ // ### do we need to open/close the fd?
+ // ### can we convert several planes at once?
+ // Get the correct DRM_FORMATs from the texture format in the description
+ EGLAttrib const attribute_list[] = {
+ EGL_WIDTH, planeWidth,
+ EGL_HEIGHT, planeHeight,
+ EGL_LINUX_DRM_FOURCC_EXT, fourccFromVideoInfo(&videoInfo, i),
+ EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, (EGLAttrib)offset,
+ EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
+ EGL_NONE
+ };
+ EGLImage image = eglCreateImage(eglDisplay,
+ EGL_NO_CONTEXT,
+ EGL_LINUX_DMA_BUF_EXT,
+ nullptr,
+ attribute_list);
+ if (image == EGL_NO_IMAGE_KHR) {
+ qWarning() << "could not create EGL image for plane" << i << Qt::hex << eglGetError();
+ }
+ // qDebug() << Qt::hex << "eglCreateImage: glerror" << glGetError() << "egl error" << eglGetError();
+ functions.glBindTexture(GL_TEXTURE_2D, textures.names[i]);
+ // qDebug() << Qt::hex << "bind texture: glerror" << glGetError() << "egl error" << eglGetError();
+ auto EGLImageTargetTexture2D = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglImageTargetTexture2D;
+ EGLImageTargetTexture2D(GL_TEXTURE_2D, image);
+ // qDebug() << Qt::hex << "glerror" << glGetError() << "egl error" << eglGetError();
+ eglDestroyImage(eglDisplay, image);
+ }
+ gst_video_frame_unmap(&frame);
+
+ return textures;
+}
+#endif
+#endif
+
+std::unique_ptr<QVideoFrameTextures> QGstVideoBuffer::mapTextures(QRhi *rhi)
+{
+ if (!rhi)
+ return {};
+
+#if QT_CONFIG(gstreamer_gl)
+ GlTextures textures = {};
+ if (memoryFormat == QGstCaps::GLTexture)
+ textures = mapFromGlTexture(m_buffer, m_frame, m_videoInfo);
+
+# if GST_GL_HAVE_PLATFORM_EGL && QT_CONFIG(linux_dmabuf)
+ else if (memoryFormat == QGstCaps::DMABuf)
+ textures = mapFromDmaBuffer(m_rhi, m_buffer, m_frame, m_videoInfo, eglDisplay,
+ eglImageTargetTexture2D);
+
+# endif
+ if (textures.count > 0)
+ return std::make_unique<QGstQVideoFrameTextures>(rhi, QSize{m_videoInfo.width, m_videoInfo.height},
+ m_frameFormat.pixelFormat(), textures);
+#endif
+ return {};
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgstvideobuffer_p.h b/src/plugins/multimedia/gstreamer/common/qgstvideobuffer_p.h
new file mode 100644
index 000000000..573a4662c
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstvideobuffer_p.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTVIDEOBUFFER_P_H
+#define QGSTVIDEOBUFFER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qhwvideobuffer_p.h>
+#include <QtCore/qvariant.h>
+
+#include <common/qgst_p.h>
+#include <gst/video/video.h>
+
+QT_BEGIN_NAMESPACE
+class QVideoFrameFormat;
+class QGstreamerVideoSink;
+class QOpenGLContext;
+
+class QGstVideoBuffer final : public QHwVideoBuffer
+{
+public:
+ QGstVideoBuffer(QGstBufferHandle buffer, const GstVideoInfo &info, QGstreamerVideoSink *sink,
+ const QVideoFrameFormat &frameFormat, QGstCaps::MemoryFormat format);
+ ~QGstVideoBuffer();
+
+ MapData map(QtVideo::MapMode mode) override;
+ void unmap() override;
+
+ std::unique_ptr<QVideoFrameTextures> mapTextures(QRhi *) override;
+
+private:
+ const QGstCaps::MemoryFormat memoryFormat = QGstCaps::CpuMemory;
+ const QVideoFrameFormat m_frameFormat;
+ QRhi *m_rhi = nullptr;
+ mutable GstVideoInfo m_videoInfo;
+ mutable GstVideoFrame m_frame{};
+ const QGstBufferHandle m_buffer;
+ QtVideo::MapMode m_mode = QtVideo::MapMode::NotMapped;
+ Qt::HANDLE eglDisplay = nullptr;
+ QFunctionPointer eglImageTargetTexture2D = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/common/qgstvideorenderersink.cpp b/src/plugins/multimedia/gstreamer/common/qgstvideorenderersink.cpp
new file mode 100644
index 000000000..f9c936ea6
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstvideorenderersink.cpp
@@ -0,0 +1,499 @@
+// Copyright (C) 2016 Jolla Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qgstvideorenderersink_p.h"
+
+#include <QtMultimedia/qvideoframe.h>
+#include <QtMultimedia/qvideosink.h>
+#include <QtCore/private/qfactoryloader_p.h>
+#include <QtCore/private/quniquehandle_p.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qloggingcategory.h>
+#include <QtCore/qmap.h>
+#include <QtCore/qthread.h>
+#include <QtGui/qevent.h>
+
+#include <common/qgstvideobuffer_p.h>
+#include <common/qgstreamervideosink_p.h>
+#include <common/qgst_debug_p.h>
+#include <common/qgstutils_p.h>
+
+#include <private/qvideoframe_p.h>
+
+#include <gst/video/video.h>
+#include <gst/video/gstvideometa.h>
+
+
+#include <rhi/qrhi.h>
+#if QT_CONFIG(gstreamer_gl)
+#include <gst/gl/gl.h>
+#endif // #if QT_CONFIG(gstreamer_gl)
+
+// DMA support
+#if QT_CONFIG(linux_dmabuf)
+#include <gst/allocators/gstdmabuf.h>
+#endif
+
+static Q_LOGGING_CATEGORY(qLcGstVideoRenderer, "qt.multimedia.gstvideorenderer")
+
+QT_BEGIN_NAMESPACE
+
+QGstVideoRenderer::QGstVideoRenderer(QGstreamerVideoSink *sink)
+ : m_sink(sink), m_surfaceCaps(createSurfaceCaps(sink))
+{
+ QObject::connect(
+ sink, &QGstreamerVideoSink::aboutToBeDestroyed, this,
+ [this] {
+ QMutexLocker locker(&m_sinkMutex);
+ m_sink = nullptr;
+ },
+ Qt::DirectConnection);
+}
+
+QGstVideoRenderer::~QGstVideoRenderer() = default;
+
+QGstCaps QGstVideoRenderer::createSurfaceCaps([[maybe_unused]] QGstreamerVideoSink *sink)
+{
+ QGstCaps caps = QGstCaps::create();
+
+ // All the formats that both we and gstreamer support
+ auto formats = QList<QVideoFrameFormat::PixelFormat>()
+ << QVideoFrameFormat::Format_YUV420P
+ << QVideoFrameFormat::Format_YUV422P
+ << QVideoFrameFormat::Format_YV12
+ << QVideoFrameFormat::Format_UYVY
+ << QVideoFrameFormat::Format_YUYV
+ << QVideoFrameFormat::Format_NV12
+ << QVideoFrameFormat::Format_NV21
+ << QVideoFrameFormat::Format_AYUV
+ << QVideoFrameFormat::Format_P010
+ << QVideoFrameFormat::Format_XRGB8888
+ << QVideoFrameFormat::Format_XBGR8888
+ << QVideoFrameFormat::Format_RGBX8888
+ << QVideoFrameFormat::Format_BGRX8888
+ << QVideoFrameFormat::Format_ARGB8888
+ << QVideoFrameFormat::Format_ABGR8888
+ << QVideoFrameFormat::Format_RGBA8888
+ << QVideoFrameFormat::Format_BGRA8888
+ << QVideoFrameFormat::Format_Y8
+ << QVideoFrameFormat::Format_Y16
+ ;
+#if QT_CONFIG(gstreamer_gl)
+ QRhi *rhi = sink->rhi();
+ if (rhi && rhi->backend() == QRhi::OpenGLES2) {
+ caps.addPixelFormats(formats, GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
+#if QT_CONFIG(linux_dmabuf)
+ if (sink->eglDisplay() && sink->eglImageTargetTexture2D()) {
+ // We currently do not handle planar DMA buffers, as it's somewhat unclear how to
+ // convert the planar EGLImage into something we can use from OpenGL
+ auto singlePlaneFormats = QList<QVideoFrameFormat::PixelFormat>()
+ << QVideoFrameFormat::Format_UYVY
+ << QVideoFrameFormat::Format_YUYV
+ << QVideoFrameFormat::Format_AYUV
+ << QVideoFrameFormat::Format_XRGB8888
+ << QVideoFrameFormat::Format_XBGR8888
+ << QVideoFrameFormat::Format_RGBX8888
+ << QVideoFrameFormat::Format_BGRX8888
+ << QVideoFrameFormat::Format_ARGB8888
+ << QVideoFrameFormat::Format_ABGR8888
+ << QVideoFrameFormat::Format_RGBA8888
+ << QVideoFrameFormat::Format_BGRA8888
+ << QVideoFrameFormat::Format_Y8
+ << QVideoFrameFormat::Format_Y16
+ ;
+ caps.addPixelFormats(singlePlaneFormats, GST_CAPS_FEATURE_MEMORY_DMABUF);
+ }
+#endif
+ }
+#endif
+ caps.addPixelFormats(formats);
+ return caps;
+}
+
+const QGstCaps &QGstVideoRenderer::caps()
+{
+ return m_surfaceCaps;
+}
+
+bool QGstVideoRenderer::start(const QGstCaps& caps)
+{
+ qCDebug(qLcGstVideoRenderer) << "QGstVideoRenderer::start" << caps;
+
+ {
+ m_frameRotationAngle = QtVideo::Rotation::None;
+ auto optionalFormatAndVideoInfo = caps.formatAndVideoInfo();
+ if (optionalFormatAndVideoInfo) {
+ std::tie(m_format, m_videoInfo) = std::move(*optionalFormatAndVideoInfo);
+ } else {
+ m_format = {};
+ m_videoInfo = {};
+ }
+ m_memoryFormat = caps.memoryFormat();
+ }
+
+ return true;
+}
+
+void QGstVideoRenderer::stop()
+{
+ qCDebug(qLcGstVideoRenderer) << "QGstVideoRenderer::stop";
+
+ QMetaObject::invokeMethod(this, [this] {
+ m_currentState.buffer = {};
+ m_sink->setVideoFrame(QVideoFrame{});
+ return;
+ });
+}
+
+void QGstVideoRenderer::unlock()
+{
+ qCDebug(qLcGstVideoRenderer) << "QGstVideoRenderer::unlock";
+}
+
+bool QGstVideoRenderer::proposeAllocation(GstQuery *)
+{
+ qCDebug(qLcGstVideoRenderer) << "QGstVideoRenderer::proposeAllocation";
+ return true;
+}
+
+GstFlowReturn QGstVideoRenderer::render(GstBuffer *buffer)
+{
+ qCDebug(qLcGstVideoRenderer) << "QGstVideoRenderer::render";
+
+ GstVideoCropMeta *meta = gst_buffer_get_video_crop_meta(buffer);
+ if (meta) {
+ QRect vp(meta->x, meta->y, meta->width, meta->height);
+ if (m_format.viewport() != vp) {
+ qCDebug(qLcGstVideoRenderer)
+ << Q_FUNC_INFO << " Update viewport on Metadata: [" << meta->height << "x"
+ << meta->width << " | " << meta->x << "x" << meta->y << "]";
+ // Update viewport if data is not the same
+ m_format.setViewport(vp);
+ }
+ }
+
+ RenderBufferState state{
+ .buffer = QGstBufferHandle{ buffer, QGstBufferHandle::NeedsRef },
+ .format = m_format,
+ .memoryFormat = m_memoryFormat,
+ .mirrored = m_frameMirrored,
+ .rotationAngle = m_frameRotationAngle,
+ };
+
+ qCDebug(qLcGstVideoRenderer) << " sending video frame";
+
+ QMetaObject::invokeMethod(this, [this, state = std::move(state)]() mutable {
+ if (state == m_currentState) {
+ // same buffer received twice
+ if (!m_sink || !m_sink->inStoppedState())
+ return;
+
+ qCDebug(qLcGstVideoRenderer) << " showing empty video frame";
+ m_currentVideoFrame = {};
+ m_sink->setVideoFrame(m_currentVideoFrame);
+ m_currentState = {};
+ return;
+ }
+
+ auto videoBuffer = std::make_unique<QGstVideoBuffer>(state.buffer, m_videoInfo, m_sink,
+ state.format, state.memoryFormat);
+ QVideoFrame frame = QVideoFramePrivate::createFrame(std::move(videoBuffer), state.format);
+ QGstUtils::setFrameTimeStampsFromBuffer(&frame, state.buffer.get());
+ frame.setMirrored(state.mirrored);
+ frame.setRotation(state.rotationAngle);
+ m_currentVideoFrame = std::move(frame);
+ m_currentState = std::move(state);
+
+ if (!m_sink)
+ return;
+
+ if (m_sink->inStoppedState()) {
+ qCDebug(qLcGstVideoRenderer) << " showing empty video frame";
+ m_currentVideoFrame = {};
+ }
+
+ m_sink->setVideoFrame(m_currentVideoFrame);
+ });
+
+ return GST_FLOW_OK;
+}
+
+bool QGstVideoRenderer::query(GstQuery *query)
+{
+#if QT_CONFIG(gstreamer_gl)
+ if (GST_QUERY_TYPE(query) == GST_QUERY_CONTEXT) {
+ const gchar *type;
+ gst_query_parse_context_type(query, &type);
+
+ if (strcmp(type, "gst.gl.local_context") != 0)
+ return false;
+
+ QMutexLocker locker(&m_sinkMutex);
+ if (!m_sink)
+ return false;
+
+ auto *gstGlContext = m_sink->gstGlLocalContext();
+ if (!gstGlContext)
+ return false;
+
+ gst_query_set_context(query, gstGlContext);
+
+ return true;
+ }
+#else
+ Q_UNUSED(query);
+#endif
+ return false;
+}
+
+void QGstVideoRenderer::gstEvent(GstEvent *event)
+{
+ switch (GST_EVENT_TYPE(event)) {
+ case GST_EVENT_TAG:
+ qCDebug(qLcGstVideoRenderer) << "QGstVideoRenderer::gstEvent: Tag";
+ return gstEventHandleTag(event);
+ case GST_EVENT_EOS:
+ qCDebug(qLcGstVideoRenderer) << "QGstVideoRenderer::gstEvent: EOS";
+ return gstEventHandleEOS(event);
+
+ default:
+ qCDebug(qLcGstVideoRenderer) << "QGstVideoRenderer::gstEvent: unhandled event - " << event;
+ return;
+ }
+}
+
+void QGstVideoRenderer::gstEventHandleTag(GstEvent *event)
+{
+ GstTagList *taglist = nullptr;
+ gst_event_parse_tag(event, &taglist);
+ if (!taglist)
+ return;
+
+ QGString value;
+ if (!gst_tag_list_get_string(taglist, GST_TAG_IMAGE_ORIENTATION, &value))
+ return;
+
+ constexpr const char rotate[] = "rotate-";
+ constexpr const char flipRotate[] = "flip-rotate-";
+ constexpr size_t rotateLen = sizeof(rotate) - 1;
+ constexpr size_t flipRotateLen = sizeof(flipRotate) - 1;
+
+ bool mirrored = false;
+ int rotationAngle = 0;
+
+ if (!strncmp(rotate, value.get(), rotateLen)) {
+ rotationAngle = atoi(value.get() + rotateLen);
+ } else if (!strncmp(flipRotate, value.get(), flipRotateLen)) {
+ // To flip by horizontal axis is the same as to mirror by vertical axis
+ // and rotate by 180 degrees.
+ mirrored = true;
+ rotationAngle = (180 + atoi(value.get() + flipRotateLen)) % 360;
+ }
+
+ m_frameMirrored = mirrored;
+ switch (rotationAngle) {
+ case 0:
+ m_frameRotationAngle = QtVideo::Rotation::None;
+ break;
+ case 90:
+ m_frameRotationAngle = QtVideo::Rotation::Clockwise90;
+ break;
+ case 180:
+ m_frameRotationAngle = QtVideo::Rotation::Clockwise180;
+ break;
+ case 270:
+ m_frameRotationAngle = QtVideo::Rotation::Clockwise270;
+ break;
+ default:
+ m_frameRotationAngle = QtVideo::Rotation::None;
+ }
+}
+
+void QGstVideoRenderer::gstEventHandleEOS(GstEvent *)
+{
+ stop();
+}
+
+static GstVideoSinkClass *gvrs_sink_parent_class;
+static thread_local QGstreamerVideoSink *gvrs_current_sink;
+
+#define VO_SINK(s) QGstVideoRendererSink *sink(reinterpret_cast<QGstVideoRendererSink *>(s))
+
+QGstVideoRendererSink *QGstVideoRendererSink::createSink(QGstreamerVideoSink *sink)
+{
+ setSink(sink);
+ QGstVideoRendererSink *gstSink = reinterpret_cast<QGstVideoRendererSink *>(
+ g_object_new(QGstVideoRendererSink::get_type(), nullptr));
+
+ return gstSink;
+}
+
+void QGstVideoRendererSink::setSink(QGstreamerVideoSink *sink)
+{
+ gvrs_current_sink = sink;
+}
+
+GType QGstVideoRendererSink::get_type()
+{
+ static const GTypeInfo info =
+ {
+ sizeof(QGstVideoRendererSinkClass), // class_size
+ base_init, // base_init
+ nullptr, // base_finalize
+ class_init, // class_init
+ nullptr, // class_finalize
+ nullptr, // class_data
+ sizeof(QGstVideoRendererSink), // instance_size
+ 0, // n_preallocs
+ instance_init, // instance_init
+ nullptr // value_table
+ };
+
+ static const GType type = g_type_register_static(GST_TYPE_VIDEO_SINK, "QGstVideoRendererSink",
+ &info, GTypeFlags(0));
+
+ return type;
+}
+
+void QGstVideoRendererSink::class_init(gpointer g_class, gpointer class_data)
+{
+ Q_UNUSED(class_data);
+
+ gvrs_sink_parent_class = reinterpret_cast<GstVideoSinkClass *>(g_type_class_peek_parent(g_class));
+
+ GstVideoSinkClass *video_sink_class = reinterpret_cast<GstVideoSinkClass *>(g_class);
+ video_sink_class->show_frame = QGstVideoRendererSink::show_frame;
+
+ GstBaseSinkClass *base_sink_class = reinterpret_cast<GstBaseSinkClass *>(g_class);
+ base_sink_class->get_caps = QGstVideoRendererSink::get_caps;
+ base_sink_class->set_caps = QGstVideoRendererSink::set_caps;
+ base_sink_class->propose_allocation = QGstVideoRendererSink::propose_allocation;
+ base_sink_class->stop = QGstVideoRendererSink::stop;
+ base_sink_class->unlock = QGstVideoRendererSink::unlock;
+ base_sink_class->query = QGstVideoRendererSink::query;
+ base_sink_class->event = QGstVideoRendererSink::event;
+
+ GstElementClass *element_class = reinterpret_cast<GstElementClass *>(g_class);
+ element_class->change_state = QGstVideoRendererSink::change_state;
+ gst_element_class_set_metadata(element_class,
+ "Qt built-in video renderer sink",
+ "Sink/Video",
+ "Qt default built-in video renderer sink",
+ "The Qt Company");
+
+ GObjectClass *object_class = reinterpret_cast<GObjectClass *>(g_class);
+ object_class->finalize = QGstVideoRendererSink::finalize;
+}
+
+void QGstVideoRendererSink::base_init(gpointer g_class)
+{
+ static GstStaticPadTemplate sink_pad_template = GST_STATIC_PAD_TEMPLATE(
+ "sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS(
+ "video/x-raw, "
+ "framerate = (fraction) [ 0, MAX ], "
+ "width = (int) [ 1, MAX ], "
+ "height = (int) [ 1, MAX ]"));
+
+ gst_element_class_add_pad_template(
+ GST_ELEMENT_CLASS(g_class), gst_static_pad_template_get(&sink_pad_template));
+}
+
+void QGstVideoRendererSink::instance_init(GTypeInstance *instance, gpointer g_class)
+{
+ Q_UNUSED(g_class);
+ VO_SINK(instance);
+
+ Q_ASSERT(gvrs_current_sink);
+
+ sink->renderer = new QGstVideoRenderer(gvrs_current_sink);
+ sink->renderer->moveToThread(gvrs_current_sink->thread());
+ gvrs_current_sink = nullptr;
+}
+
+void QGstVideoRendererSink::finalize(GObject *object)
+{
+ VO_SINK(object);
+
+ delete sink->renderer;
+
+ // Chain up
+ G_OBJECT_CLASS(gvrs_sink_parent_class)->finalize(object);
+}
+
+GstStateChangeReturn QGstVideoRendererSink::change_state(
+ GstElement *element, GstStateChange transition)
+{
+ return GST_ELEMENT_CLASS(gvrs_sink_parent_class)->change_state(element, transition);
+}
+
+GstCaps *QGstVideoRendererSink::get_caps(GstBaseSink *base, GstCaps *filter)
+{
+ VO_SINK(base);
+
+ QGstCaps caps = sink->renderer->caps();
+ if (filter)
+ caps = QGstCaps(gst_caps_intersect(caps.caps(), filter), QGstCaps::HasRef);
+
+ return caps.release();
+}
+
+gboolean QGstVideoRendererSink::set_caps(GstBaseSink *base, GstCaps *gcaps)
+{
+ VO_SINK(base);
+ auto caps = QGstCaps(gcaps, QGstCaps::NeedsRef);
+
+ qCDebug(qLcGstVideoRenderer) << "set_caps:" << caps;
+
+ if (caps.isNull()) {
+ sink->renderer->stop();
+ return TRUE;
+ }
+
+ return sink->renderer->start(caps);
+}
+
+gboolean QGstVideoRendererSink::propose_allocation(GstBaseSink *base, GstQuery *query)
+{
+ VO_SINK(base);
+ return sink->renderer->proposeAllocation(query);
+}
+
+gboolean QGstVideoRendererSink::stop(GstBaseSink *base)
+{
+ VO_SINK(base);
+ sink->renderer->stop();
+ return TRUE;
+}
+
+gboolean QGstVideoRendererSink::unlock(GstBaseSink *base)
+{
+ VO_SINK(base);
+ sink->renderer->unlock();
+ return TRUE;
+}
+
+GstFlowReturn QGstVideoRendererSink::show_frame(GstVideoSink *base, GstBuffer *buffer)
+{
+ VO_SINK(base);
+ return sink->renderer->render(buffer);
+}
+
+gboolean QGstVideoRendererSink::query(GstBaseSink *base, GstQuery *query)
+{
+ VO_SINK(base);
+ if (sink->renderer->query(query))
+ return TRUE;
+
+ return GST_BASE_SINK_CLASS(gvrs_sink_parent_class)->query(base, query);
+}
+
+gboolean QGstVideoRendererSink::event(GstBaseSink *base, GstEvent * event)
+{
+ VO_SINK(base);
+ sink->renderer->gstEvent(event);
+ return GST_BASE_SINK_CLASS(gvrs_sink_parent_class)->event(base, event);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/common/qgstvideorenderersink_p.h b/src/plugins/multimedia/gstreamer/common/qgstvideorenderersink_p.h
new file mode 100644
index 000000000..d9e3db462
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/common/qgstvideorenderersink_p.h
@@ -0,0 +1,138 @@
+// Copyright (C) 2016 Jolla Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTVIDEORENDERERSINK_P_H
+#define QGSTVIDEORENDERERSINK_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/qvideoframeformat.h>
+#include <QtMultimedia/qvideoframe.h>
+#include <QtMultimedia/private/qtmultimediaglobal_p.h>
+#include <QtCore/qmutex.h>
+
+#include <gst/video/gstvideosink.h>
+#include <gst/video/video.h>
+
+#include <QtCore/qlist.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qqueue.h>
+#include <QtCore/qpointer.h>
+#include <QtCore/qwaitcondition.h>
+#include <qvideoframeformat.h>
+#include <qvideoframe.h>
+#include <common/qgstvideobuffer_p.h>
+#include <common/qgst_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstVideoRenderer : public QObject
+{
+public:
+ explicit QGstVideoRenderer(QGstreamerVideoSink *);
+ ~QGstVideoRenderer();
+
+ const QGstCaps &caps();
+
+ bool start(const QGstCaps &);
+ void stop();
+ void unlock();
+ bool proposeAllocation(GstQuery *);
+ GstFlowReturn render(GstBuffer *);
+ bool query(GstQuery *);
+ void gstEvent(GstEvent *);
+
+private:
+ void notify();
+ static QGstCaps createSurfaceCaps(QGstreamerVideoSink *);
+
+ void gstEventHandleTag(GstEvent *);
+ void gstEventHandleEOS(GstEvent *);
+
+ QMutex m_sinkMutex;
+ QGstreamerVideoSink *m_sink = nullptr; // written only from qt thread. so only readers on
+ // worker threads need to acquire the lock
+
+ // --- only accessed from gstreamer thread
+ const QGstCaps m_surfaceCaps;
+ QVideoFrameFormat m_format;
+ GstVideoInfo m_videoInfo{};
+ QGstCaps::MemoryFormat m_memoryFormat = QGstCaps::CpuMemory;
+ bool m_frameMirrored = false;
+ QtVideo::Rotation m_frameRotationAngle = QtVideo::Rotation::None;
+
+ // --- only accessed from qt thread
+ QVideoFrame m_currentVideoFrame;
+
+ struct RenderBufferState
+ {
+ QGstBufferHandle buffer;
+ QVideoFrameFormat format;
+ QGstCaps::MemoryFormat memoryFormat;
+ bool mirrored;
+ QtVideo::Rotation rotationAngle;
+
+ bool operator==(const RenderBufferState &rhs) const
+ {
+ return std::tie(buffer, format, memoryFormat, mirrored, rotationAngle)
+ == std::tie(rhs.buffer, rhs.format, rhs.memoryFormat, rhs.mirrored,
+ rhs.rotationAngle);
+ }
+ };
+ RenderBufferState m_currentState;
+};
+
+class QGstVideoRendererSink
+{
+public:
+ GstVideoSink parent{};
+
+ static QGstVideoRendererSink *createSink(QGstreamerVideoSink *surface);
+ static void setSink(QGstreamerVideoSink *surface);
+
+private:
+ static GType get_type();
+ static void class_init(gpointer g_class, gpointer class_data);
+ static void base_init(gpointer g_class);
+ static void instance_init(GTypeInstance *instance, gpointer g_class);
+
+ static void finalize(GObject *object);
+
+ static GstStateChangeReturn change_state(GstElement *element, GstStateChange transition);
+
+ static GstCaps *get_caps(GstBaseSink *sink, GstCaps *filter);
+ static gboolean set_caps(GstBaseSink *sink, GstCaps *caps);
+
+ static gboolean propose_allocation(GstBaseSink *sink, GstQuery *query);
+
+ static gboolean stop(GstBaseSink *sink);
+
+ static gboolean unlock(GstBaseSink *sink);
+
+ static GstFlowReturn show_frame(GstVideoSink *sink, GstBuffer *buffer);
+ static gboolean query(GstBaseSink *element, GstQuery *query);
+ static gboolean event(GstBaseSink *element, GstEvent * event);
+
+private:
+ QGstVideoRenderer *renderer = nullptr;
+};
+
+
+class QGstVideoRendererSinkClass
+{
+public:
+ GstVideoSinkClass parent_class;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/gstreamer.json b/src/plugins/multimedia/gstreamer/gstreamer.json
new file mode 100644
index 000000000..6a709d9f4
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/gstreamer.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "gstreamer" ]
+}
diff --git a/src/plugins/multimedia/gstreamer/mediacapture/qgstreamercamera.cpp b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamercamera.cpp
new file mode 100644
index 000000000..c54e8b74b
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamercamera.cpp
@@ -0,0 +1,771 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <mediacapture/qgstreamercamera_p.h>
+
+#include <QtMultimedia/qcameradevice.h>
+#include <QtMultimedia/qmediacapturesession.h>
+#include <QtMultimedia/private/qcameradevice_p.h>
+#include <QtCore/qdebug.h>
+
+#include <common/qgst_debug_p.h>
+#include <qgstreamervideodevices_p.h>
+#include <qgstreamerintegration_p.h>
+
+#if QT_CONFIG(linux_v4l)
+#include <linux/videodev2.h>
+#include <private/qcore_unix_p.h>
+#endif
+
+
+QT_BEGIN_NAMESPACE
+
+QMaybe<QPlatformCamera *> QGstreamerCamera::create(QCamera *camera)
+{
+ static const auto error = qGstErrorMessageIfElementsNotAvailable(
+ "videotestsrc", "capsfilter", "videoconvert", "videoscale", "identity");
+ if (error)
+ return *error;
+
+ return new QGstreamerCamera(camera);
+}
+
+QGstreamerCamera::QGstreamerCamera(QCamera *camera)
+ : QGstreamerCameraBase(camera),
+ gstCameraBin{
+ QGstBin::create("camerabin"),
+ },
+ gstCamera{
+ QGstElement::createFromFactory("videotestsrc"),
+ },
+ gstCapsFilter{
+ QGstElement::createFromFactory("capsfilter", "videoCapsFilter"),
+ },
+ gstDecode{
+ QGstElement::createFromFactory("identity"),
+ },
+ gstVideoConvert{
+ QGstElement::createFromFactory("videoconvert", "videoConvert"),
+ },
+ gstVideoScale{
+ QGstElement::createFromFactory("videoscale", "videoScale"),
+ }
+{
+ gstCameraBin.add(gstCamera, gstCapsFilter, gstDecode, gstVideoConvert, gstVideoScale);
+ qLinkGstElements(gstCamera, gstCapsFilter, gstDecode, gstVideoConvert, gstVideoScale);
+ gstCameraBin.addGhostPad(gstVideoScale, "src");
+}
+
+QGstreamerCamera::~QGstreamerCamera()
+{
+ gstCameraBin.setStateSync(GST_STATE_NULL);
+}
+
+bool QGstreamerCamera::isActive() const
+{
+ return m_active;
+}
+
+void QGstreamerCamera::setActive(bool active)
+{
+ if (m_active == active)
+ return;
+ if (m_cameraDevice.isNull() && active)
+ return;
+
+ m_active = active;
+
+ emit activeChanged(active);
+}
+
+void QGstreamerCamera::setCamera(const QCameraDevice &camera)
+{
+ using namespace Qt::Literals;
+
+ if (m_cameraDevice == camera)
+ return;
+
+ m_cameraDevice = camera;
+
+ QGstElement gstNewCamera;
+ if (camera.isNull()) {
+ gstNewCamera = QGstElement::createFromFactory("videotestsrc");
+ } else {
+ auto *integration = static_cast<QGstreamerIntegration *>(QGstreamerIntegration::instance());
+ GstDevice *device = integration->videoDevice(camera.id());
+
+ if (!device) {
+ updateError(QCamera::Error::CameraError,
+ u"Failed to create GstDevice for camera: "_s
+ + QString::fromUtf8(camera.id()));
+ return;
+ }
+
+ gstNewCamera = QGstElement::createFromDevice(device, "camerasrc");
+ QUniqueGstStructureHandle properties{
+ gst_device_get_properties(device),
+ };
+
+ if (properties) {
+ QGstStructureView propertiesView{ properties };
+ if (propertiesView.name() == "v4l2deviceprovider")
+ m_v4l2DevicePath = QString::fromUtf8(propertiesView["device.path"].toString());
+ }
+ }
+
+ QCameraFormat f = findBestCameraFormat(camera);
+ auto caps = QGstCaps::fromCameraFormat(f);
+ auto gstNewDecode = QGstElement::createFromFactory(
+ f.pixelFormat() == QVideoFrameFormat::Format_Jpeg ? "jpegdec" : "identity");
+
+ QGstPipeline::modifyPipelineWhileNotRunning(gstCamera.getPipeline(), [&] {
+ gstCamera.setStateSync(GST_STATE_READY); // stop camera, as it may have active tasks
+
+ qUnlinkGstElements(gstCamera, gstCapsFilter, gstDecode, gstVideoConvert);
+ gstCameraBin.stopAndRemoveElements(gstCamera, gstDecode);
+
+ gstCapsFilter.set("caps", caps);
+
+ gstCamera = std::move(gstNewCamera);
+ gstDecode = std::move(gstNewDecode);
+
+ gstCameraBin.add(gstCamera, gstDecode);
+ qLinkGstElements(gstCamera, gstCapsFilter, gstDecode, gstVideoConvert);
+
+ gstCameraBin.syncChildrenState();
+ });
+
+ updateCameraProperties();
+}
+
+bool QGstreamerCamera::setCameraFormat(const QCameraFormat &format)
+{
+ if (!format.isNull() && !m_cameraDevice.videoFormats().contains(format))
+ return false;
+
+ QCameraFormat f = format;
+ if (f.isNull())
+ f = findBestCameraFormat(m_cameraDevice);
+
+ auto caps = QGstCaps::fromCameraFormat(f);
+
+ auto newGstDecode = QGstElement::createFromFactory(
+ f.pixelFormat() == QVideoFrameFormat::Format_Jpeg ? "jpegdec" : "identity");
+
+ QGstPipeline::modifyPipelineWhileNotRunning(gstCamera.getPipeline(), [&] {
+ gstCamera.setStateSync(GST_STATE_READY); // stop camera, as it may have active tasks
+
+ qUnlinkGstElements(gstCamera, gstCapsFilter, gstDecode, gstVideoConvert);
+ gstCameraBin.stopAndRemoveElements(gstDecode);
+
+ gstCapsFilter.set("caps", caps);
+
+ gstDecode = std::move(newGstDecode);
+
+ gstCameraBin.add(gstDecode);
+ qLinkGstElements(gstCamera, gstCapsFilter, gstDecode, gstVideoConvert);
+ gstCameraBin.syncChildrenState();
+ });
+
+ return true;
+}
+
+void QGstreamerCamera::updateCameraProperties()
+{
+#if QT_CONFIG(linux_v4l)
+ if (isV4L2Camera()) {
+ initV4L2Controls();
+ return;
+ }
+#endif
+#if QT_CONFIG(gstreamer_photography)
+ if (auto *p = photography())
+ gst_photography_set_white_balance_mode(p, GST_PHOTOGRAPHY_WB_MODE_AUTO);
+ QCamera::Features f = QCamera::Feature::ColorTemperature | QCamera::Feature::ExposureCompensation |
+ QCamera::Feature::IsoSensitivity | QCamera::Feature::ManualExposureTime;
+ supportedFeaturesChanged(f);
+#endif
+
+}
+
+#if QT_CONFIG(gstreamer_photography)
+GstPhotography *QGstreamerCamera::photography() const
+{
+ if (!gstCamera.isNull() && GST_IS_PHOTOGRAPHY(gstCamera.element()))
+ return GST_PHOTOGRAPHY(gstCamera.element());
+ return nullptr;
+}
+#endif
+
+void QGstreamerCamera::setFocusMode(QCamera::FocusMode mode)
+{
+ if (mode == focusMode())
+ return;
+
+#if QT_CONFIG(gstreamer_photography)
+ auto p = photography();
+ if (p) {
+ GstPhotographyFocusMode photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_NORMAL;
+
+ switch (mode) {
+ case QCamera::FocusModeAutoNear:
+ photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_MACRO;
+ break;
+ case QCamera::FocusModeAutoFar:
+ // not quite, but hey :)
+ Q_FALLTHROUGH();
+ case QCamera::FocusModeHyperfocal:
+ photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_HYPERFOCAL;
+ break;
+ case QCamera::FocusModeInfinity:
+ photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_INFINITY;
+ break;
+ case QCamera::FocusModeManual:
+ photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_MANUAL;
+ break;
+ default: // QCamera::FocusModeAuto:
+ break;
+ }
+
+ if (gst_photography_set_focus_mode(p, photographyMode))
+ focusModeChanged(mode);
+ }
+#endif
+}
+
+bool QGstreamerCamera::isFocusModeSupported(QCamera::FocusMode mode) const
+{
+#if QT_CONFIG(gstreamer_photography)
+ if (photography())
+ return true;
+#endif
+ return mode == QCamera::FocusModeAuto;
+}
+
+void QGstreamerCamera::setFlashMode(QCamera::FlashMode mode)
+{
+ Q_UNUSED(mode);
+
+#if QT_CONFIG(gstreamer_photography)
+ if (auto *p = photography()) {
+ GstPhotographyFlashMode flashMode;
+ gst_photography_get_flash_mode(p, &flashMode);
+
+ switch (mode) {
+ case QCamera::FlashAuto:
+ flashMode = GST_PHOTOGRAPHY_FLASH_MODE_AUTO;
+ break;
+ case QCamera::FlashOff:
+ flashMode = GST_PHOTOGRAPHY_FLASH_MODE_OFF;
+ break;
+ case QCamera::FlashOn:
+ flashMode = GST_PHOTOGRAPHY_FLASH_MODE_ON;
+ break;
+ }
+
+ if (gst_photography_set_flash_mode(p, flashMode))
+ flashModeChanged(mode);
+ }
+#endif
+}
+
+bool QGstreamerCamera::isFlashModeSupported(QCamera::FlashMode mode) const
+{
+#if QT_CONFIG(gstreamer_photography)
+ if (photography())
+ return true;
+#endif
+
+ return mode == QCamera::FlashAuto;
+}
+
+bool QGstreamerCamera::isFlashReady() const
+{
+#if QT_CONFIG(gstreamer_photography)
+ if (photography())
+ return true;
+#endif
+
+ return false;
+}
+
+void QGstreamerCamera::setExposureMode(QCamera::ExposureMode mode)
+{
+ Q_UNUSED(mode);
+#if QT_CONFIG(linux_v4l)
+ if (isV4L2Camera() && v4l2AutoExposureSupported && v4l2ManualExposureSupported) {
+ if (mode != QCamera::ExposureAuto && mode != QCamera::ExposureManual)
+ return;
+ int value = QCamera::ExposureAuto ? V4L2_EXPOSURE_AUTO : V4L2_EXPOSURE_MANUAL;
+ setV4L2Parameter(V4L2_CID_EXPOSURE_AUTO, value);
+ exposureModeChanged(mode);
+ return;
+ }
+#endif
+
+#if QT_CONFIG(gstreamer_photography)
+ auto *p = photography();
+ if (!p)
+ return;
+
+ GstPhotographySceneMode sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_AUTO;
+
+ switch (mode) {
+ case QCamera::ExposureManual:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_MANUAL;
+ break;
+ case QCamera::ExposurePortrait:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT;
+ break;
+ case QCamera::ExposureSports:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SPORT;
+ break;
+ case QCamera::ExposureNight:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_NIGHT;
+ break;
+ case QCamera::ExposureAuto:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_AUTO;
+ break;
+ case QCamera::ExposureLandscape:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE;
+ break;
+ case QCamera::ExposureSnow:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SNOW;
+ break;
+ case QCamera::ExposureBeach:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_BEACH;
+ break;
+ case QCamera::ExposureAction:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_ACTION;
+ break;
+ case QCamera::ExposureNightPortrait:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_NIGHT_PORTRAIT;
+ break;
+ case QCamera::ExposureTheatre:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_THEATRE;
+ break;
+ case QCamera::ExposureSunset:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SUNSET;
+ break;
+ case QCamera::ExposureSteadyPhoto:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_STEADY_PHOTO;
+ break;
+ case QCamera::ExposureFireworks:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_FIREWORKS;
+ break;
+ case QCamera::ExposureParty:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_PARTY;
+ break;
+ case QCamera::ExposureCandlelight:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_CANDLELIGHT;
+ break;
+ case QCamera::ExposureBarcode:
+ sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_BARCODE;
+ break;
+ default:
+ return;
+ }
+
+ if (gst_photography_set_scene_mode(p, sceneMode))
+ exposureModeChanged(mode);
+#endif
+}
+
+bool QGstreamerCamera::isExposureModeSupported(QCamera::ExposureMode mode) const
+{
+ if (mode == QCamera::ExposureAuto)
+ return true;
+#if QT_CONFIG(linux_v4l)
+ if (isV4L2Camera() && v4l2ManualExposureSupported && v4l2AutoExposureSupported)
+ return mode == QCamera::ExposureManual;
+#endif
+#if QT_CONFIG(gstreamer_photography)
+ if (photography())
+ return true;
+#endif
+
+ return false;
+}
+
+void QGstreamerCamera::setExposureCompensation(float compensation)
+{
+ Q_UNUSED(compensation);
+#if QT_CONFIG(linux_v4l)
+ if (isV4L2Camera() && (v4l2MinExposureAdjustment != 0 || v4l2MaxExposureAdjustment != 0)) {
+ int value = qBound(v4l2MinExposureAdjustment, (int)(compensation*1000), v4l2MaxExposureAdjustment);
+ setV4L2Parameter(V4L2_CID_AUTO_EXPOSURE_BIAS, value);
+ exposureCompensationChanged(value/1000.);
+ return;
+ }
+#endif
+
+#if QT_CONFIG(gstreamer_photography)
+ if (auto *p = photography()) {
+ if (gst_photography_set_ev_compensation(p, compensation))
+ exposureCompensationChanged(compensation);
+ }
+#endif
+}
+
+void QGstreamerCamera::setManualIsoSensitivity(int iso)
+{
+ Q_UNUSED(iso);
+#if QT_CONFIG(linux_v4l)
+ if (isV4L2Camera()) {
+ if (!(supportedFeatures() & QCamera::Feature::IsoSensitivity))
+ return;
+ setV4L2Parameter(V4L2_CID_ISO_SENSITIVITY_AUTO, iso <= 0 ? V4L2_ISO_SENSITIVITY_AUTO : V4L2_ISO_SENSITIVITY_MANUAL);
+ if (iso > 0) {
+ iso = qBound(minIso(), iso, maxIso());
+ setV4L2Parameter(V4L2_CID_ISO_SENSITIVITY, iso);
+ }
+ return;
+ }
+#endif
+#if QT_CONFIG(gstreamer_photography)
+ if (auto *p = photography()) {
+ if (gst_photography_set_iso_speed(p, iso))
+ isoSensitivityChanged(iso);
+ }
+#endif
+}
+
+int QGstreamerCamera::isoSensitivity() const
+{
+#if QT_CONFIG(linux_v4l)
+ if (isV4L2Camera()) {
+ if (!(supportedFeatures() & QCamera::Feature::IsoSensitivity))
+ return -1;
+ return getV4L2Parameter(V4L2_CID_ISO_SENSITIVITY);
+ }
+#endif
+#if QT_CONFIG(gstreamer_photography)
+ if (auto *p = photography()) {
+ guint speed = 0;
+ if (gst_photography_get_iso_speed(p, &speed))
+ return speed;
+ }
+#endif
+ return 100;
+}
+
+void QGstreamerCamera::setManualExposureTime(float secs)
+{
+ Q_UNUSED(secs);
+#if QT_CONFIG(linux_v4l)
+ if (isV4L2Camera() && v4l2ManualExposureSupported && v4l2AutoExposureSupported) {
+ int exposure = qBound(v4l2MinExposure, qRound(secs*10000.), v4l2MaxExposure);
+ setV4L2Parameter(V4L2_CID_EXPOSURE_ABSOLUTE, exposure);
+ exposureTimeChanged(exposure/10000.);
+ return;
+ }
+#endif
+
+#if QT_CONFIG(gstreamer_photography)
+ if (auto *p = photography()) {
+ if (gst_photography_set_exposure(p, guint(secs*1000000)))
+ exposureTimeChanged(secs);
+ }
+#endif
+}
+
+float QGstreamerCamera::exposureTime() const
+{
+#if QT_CONFIG(linux_v4l)
+ if (isV4L2Camera()) {
+ return getV4L2Parameter(V4L2_CID_EXPOSURE_ABSOLUTE)/10000.;
+ }
+#endif
+#if QT_CONFIG(gstreamer_photography)
+ if (auto *p = photography()) {
+ guint32 exposure = 0;
+ if (gst_photography_get_exposure(p, &exposure))
+ return exposure/1000000.;
+ }
+#endif
+ return -1;
+}
+
+bool QGstreamerCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const
+{
+ if (mode == QCamera::WhiteBalanceAuto)
+ return true;
+
+#if QT_CONFIG(linux_v4l)
+ if (isV4L2Camera()) {
+ if (v4l2AutoWhiteBalanceSupported && v4l2ColorTemperatureSupported)
+ return true;
+ }
+#endif
+#if QT_CONFIG(gstreamer_photography)
+ if (auto *p = photography()) {
+ Q_UNUSED(p);
+ switch (mode) {
+ case QCamera::WhiteBalanceAuto:
+ case QCamera::WhiteBalanceSunlight:
+ case QCamera::WhiteBalanceCloudy:
+ case QCamera::WhiteBalanceShade:
+ case QCamera::WhiteBalanceSunset:
+ case QCamera::WhiteBalanceTungsten:
+ case QCamera::WhiteBalanceFluorescent:
+ return true;
+ case QCamera::WhiteBalanceManual: {
+#if GST_CHECK_VERSION(1, 18, 0)
+ GstPhotographyInterface *iface = GST_PHOTOGRAPHY_GET_INTERFACE(p);
+ if (iface->set_color_temperature && iface->get_color_temperature)
+ return true;
+#endif
+ break;
+ }
+ default:
+ break;
+ }
+ }
+#endif
+
+ return mode == QCamera::WhiteBalanceAuto;
+}
+
+void QGstreamerCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)
+{
+ Q_ASSERT(isWhiteBalanceModeSupported(mode));
+
+#if QT_CONFIG(linux_v4l)
+ if (isV4L2Camera()) {
+ int temperature = colorTemperatureForWhiteBalance(mode);
+ int t = setV4L2ColorTemperature(temperature);
+ if (t == 0)
+ mode = QCamera::WhiteBalanceAuto;
+ whiteBalanceModeChanged(mode);
+ return;
+ }
+#endif
+
+#if QT_CONFIG(gstreamer_photography)
+ if (auto *p = photography()) {
+ GstPhotographyWhiteBalanceMode gstMode = GST_PHOTOGRAPHY_WB_MODE_AUTO;
+ switch (mode) {
+ case QCamera::WhiteBalanceSunlight:
+ gstMode = GST_PHOTOGRAPHY_WB_MODE_DAYLIGHT;
+ break;
+ case QCamera::WhiteBalanceCloudy:
+ gstMode = GST_PHOTOGRAPHY_WB_MODE_CLOUDY;
+ break;
+ case QCamera::WhiteBalanceShade:
+ gstMode = GST_PHOTOGRAPHY_WB_MODE_SHADE;
+ break;
+ case QCamera::WhiteBalanceSunset:
+ gstMode = GST_PHOTOGRAPHY_WB_MODE_SUNSET;
+ break;
+ case QCamera::WhiteBalanceTungsten:
+ gstMode = GST_PHOTOGRAPHY_WB_MODE_TUNGSTEN;
+ break;
+ case QCamera::WhiteBalanceFluorescent:
+ gstMode = GST_PHOTOGRAPHY_WB_MODE_FLUORESCENT;
+ break;
+ case QCamera::WhiteBalanceAuto:
+ default:
+ break;
+ }
+ if (gst_photography_set_white_balance_mode(p, gstMode)) {
+ whiteBalanceModeChanged(mode);
+ return;
+ }
+ }
+#endif
+}
+
+void QGstreamerCamera::setColorTemperature(int temperature)
+{
+ if (temperature == 0) {
+ setWhiteBalanceMode(QCamera::WhiteBalanceAuto);
+ return;
+ }
+
+ Q_ASSERT(isWhiteBalanceModeSupported(QCamera::WhiteBalanceManual));
+
+#if QT_CONFIG(linux_v4l)
+ if (isV4L2Camera()) {
+ int t = setV4L2ColorTemperature(temperature);
+ if (t)
+ colorTemperatureChanged(t);
+ return;
+ }
+#endif
+
+#if QT_CONFIG(gstreamer_photography) && GST_CHECK_VERSION(1, 18, 0)
+ if (auto *p = photography()) {
+ GstPhotographyInterface *iface = GST_PHOTOGRAPHY_GET_INTERFACE(p);
+ Q_ASSERT(iface->set_color_temperature);
+ iface->set_color_temperature(p, temperature);
+ return;
+ }
+#endif
+}
+
+#if QT_CONFIG(linux_v4l)
+bool QGstreamerCamera::isV4L2Camera() const
+{
+ return !m_v4l2DevicePath.isEmpty();
+}
+
+void QGstreamerCamera::initV4L2Controls()
+{
+ v4l2AutoWhiteBalanceSupported = false;
+ v4l2ColorTemperatureSupported = false;
+ QCamera::Features features{};
+
+ Q_ASSERT(!m_v4l2DevicePath.isEmpty());
+
+
+ withV4L2DeviceFileDescriptor([&](int fd) {
+ struct v4l2_queryctrl queryControl = {};
+ queryControl.id = V4L2_CID_AUTO_WHITE_BALANCE;
+
+ if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) {
+ v4l2AutoWhiteBalanceSupported = true;
+ setV4L2Parameter(V4L2_CID_AUTO_WHITE_BALANCE, true);
+ }
+
+ queryControl = {};
+ queryControl.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE;
+ if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) {
+ v4l2MinColorTemp = queryControl.minimum;
+ v4l2MaxColorTemp = queryControl.maximum;
+ v4l2ColorTemperatureSupported = true;
+ features |= QCamera::Feature::ColorTemperature;
+ }
+
+ queryControl = {};
+ queryControl.id = V4L2_CID_EXPOSURE_AUTO;
+ if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) {
+ v4l2AutoExposureSupported = true;
+ }
+
+ queryControl = {};
+ queryControl.id = V4L2_CID_EXPOSURE_ABSOLUTE;
+ if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) {
+ v4l2ManualExposureSupported = true;
+ v4l2MinExposure = queryControl.minimum;
+ v4l2MaxExposure = queryControl.maximum;
+ features |= QCamera::Feature::ManualExposureTime;
+ }
+
+ queryControl = {};
+ queryControl.id = V4L2_CID_AUTO_EXPOSURE_BIAS;
+ if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) {
+ v4l2MinExposureAdjustment = queryControl.minimum;
+ v4l2MaxExposureAdjustment = queryControl.maximum;
+ features |= QCamera::Feature::ExposureCompensation;
+ }
+
+ queryControl = {};
+ queryControl.id = V4L2_CID_ISO_SENSITIVITY_AUTO;
+ if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) {
+ queryControl.id = V4L2_CID_ISO_SENSITIVITY;
+ if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) {
+ features |= QCamera::Feature::IsoSensitivity;
+ minIsoChanged(queryControl.minimum);
+ maxIsoChanged(queryControl.minimum);
+ }
+ }
+ });
+
+ supportedFeaturesChanged(features);
+}
+
+int QGstreamerCamera::setV4L2ColorTemperature(int temperature)
+{
+ if (v4l2AutoWhiteBalanceSupported) {
+ setV4L2Parameter(V4L2_CID_AUTO_WHITE_BALANCE, temperature == 0 ? true : false);
+ } else if (temperature == 0) {
+ temperature = 5600;
+ }
+
+ if (temperature != 0 && v4l2ColorTemperatureSupported) {
+ temperature = qBound(v4l2MinColorTemp, temperature, v4l2MaxColorTemp);
+ if (!setV4L2Parameter(V4L2_CID_WHITE_BALANCE_TEMPERATURE, qBound(v4l2MinColorTemp, temperature, v4l2MaxColorTemp)))
+ temperature = 0;
+ } else {
+ temperature = 0;
+ }
+
+ return temperature;
+}
+
+bool QGstreamerCamera::setV4L2Parameter(quint32 id, qint32 value)
+{
+ return withV4L2DeviceFileDescriptor([&](int fd) {
+ v4l2_control control{ id, value };
+ if (::ioctl(fd, VIDIOC_S_CTRL, &control) != 0) {
+ qWarning() << "Unable to set the V4L2 Parameter" << Qt::hex << id << "to" << value
+ << qt_error_string(errno);
+ return false;
+ }
+ return true;
+ });
+}
+
+int QGstreamerCamera::getV4L2Parameter(quint32 id) const
+{
+ return withV4L2DeviceFileDescriptor([&](int fd) {
+ v4l2_control control{ id, 0 };
+ if (::ioctl(fd, VIDIOC_G_CTRL, &control) != 0) {
+ qWarning() << "Unable to get the V4L2 Parameter" << Qt::hex << id
+ << qt_error_string(errno);
+ return 0;
+ }
+ return control.value;
+ });
+}
+
+QGstreamerCustomCamera::QGstreamerCustomCamera(QCamera *camera)
+ : QGstreamerCameraBase{
+ camera,
+ },
+ m_userProvidedGstElement{
+ false,
+ }
+{
+}
+
+QGstreamerCustomCamera::QGstreamerCustomCamera(QCamera *camera, QGstElement element)
+ : QGstreamerCameraBase{
+ camera,
+ },
+ gstCamera{
+ std::move(element),
+ },
+ m_userProvidedGstElement{
+ true,
+ }
+{
+}
+
+void QGstreamerCustomCamera::setCamera(const QCameraDevice &device)
+{
+ if (m_userProvidedGstElement)
+ return;
+
+ gstCamera = QGstBin::createFromPipelineDescription(device.id(), /*name=*/nullptr,
+ /* ghostUnlinkedPads=*/true);
+}
+
+bool QGstreamerCustomCamera::isActive() const
+{
+ return m_active;
+}
+
+void QGstreamerCustomCamera::setActive(bool active)
+{
+ if (m_active == active)
+ return;
+
+ m_active = active;
+
+ emit activeChanged(active);
+}
+
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/mediacapture/qgstreamercamera_p.h b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamercamera_p.h
new file mode 100644
index 000000000..f43c01f34
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamercamera_p.h
@@ -0,0 +1,152 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERCAMERACONTROL_H
+#define QGSTREAMERCAMERACONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformcamera_p.h>
+#include <private/qmultimediautils_p.h>
+
+#include <mediacapture/qgstreamermediacapture_p.h>
+#include <common/qgst_p.h>
+#include <common/qgstpipeline_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerCameraBase : public QPlatformCamera
+{
+public:
+ using QPlatformCamera::QPlatformCamera;
+
+ virtual QGstElement gstElement() const = 0;
+};
+
+class QGstreamerCamera : public QGstreamerCameraBase
+{
+public:
+ static QMaybe<QPlatformCamera *> create(QCamera *camera);
+
+ virtual ~QGstreamerCamera();
+
+ bool isActive() const override;
+ void setActive(bool active) override;
+
+ void setCamera(const QCameraDevice &camera) override;
+ bool setCameraFormat(const QCameraFormat &format) override;
+
+ QGstElement gstElement() const override { return gstCameraBin; }
+#if QT_CONFIG(gstreamer_photography)
+ GstPhotography *photography() const;
+#endif
+
+ void setFocusMode(QCamera::FocusMode mode) override;
+ bool isFocusModeSupported(QCamera::FocusMode mode) const override;
+
+ void setFlashMode(QCamera::FlashMode mode) override;
+ bool isFlashModeSupported(QCamera::FlashMode mode) const override;
+ bool isFlashReady() const override;
+
+ void setExposureMode(QCamera::ExposureMode) override;
+ bool isExposureModeSupported(QCamera::ExposureMode mode) const override;
+ void setExposureCompensation(float) override;
+ void setManualIsoSensitivity(int) override;
+ int isoSensitivity() const override;
+ void setManualExposureTime(float) override;
+ float exposureTime() const override;
+
+ bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override;
+ void setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) override;
+ void setColorTemperature(int temperature) override;
+
+private:
+ QGstreamerCamera(QCamera *camera);
+
+ void updateCameraProperties();
+
+#if QT_CONFIG(linux_v4l)
+ bool isV4L2Camera() const;
+ void initV4L2Controls();
+ int setV4L2ColorTemperature(int temperature);
+ bool setV4L2Parameter(quint32 id, qint32 value);
+ int getV4L2Parameter(quint32 id) const;
+
+ bool v4l2AutoWhiteBalanceSupported = false;
+ bool v4l2ColorTemperatureSupported = false;
+ bool v4l2AutoExposureSupported = false;
+ bool v4l2ManualExposureSupported = false;
+ qint32 v4l2MinColorTemp = 5600; // Daylight...
+ qint32 v4l2MaxColorTemp = 5600;
+ qint32 v4l2MinExposure = 0;
+ qint32 v4l2MaxExposure = 0;
+ qint32 v4l2MinExposureAdjustment = 0;
+ qint32 v4l2MaxExposureAdjustment = 0;
+
+ template <typename Functor>
+ auto withV4L2DeviceFileDescriptor(Functor &&f) const
+ {
+ using ReturnType = std::invoke_result_t<Functor, int>;
+ Q_ASSERT(isV4L2Camera());
+
+ if (int gstreamerDeviceFd = gstCamera.getInt("device-fd"); gstreamerDeviceFd != -1)
+ return f(gstreamerDeviceFd);
+
+ auto v4l2FileDescriptor = QFileDescriptorHandle{
+ qt_safe_open(m_v4l2DevicePath.toLocal8Bit().constData(), O_RDONLY),
+ };
+ if (!v4l2FileDescriptor) {
+ qWarning() << "Unable to open the camera" << m_v4l2DevicePath
+ << "for read to query the parameter info:" << qt_error_string(errno);
+ if constexpr (std::is_void_v<ReturnType>)
+ return;
+ else
+ return ReturnType{};
+ }
+ return f(v4l2FileDescriptor.get());
+ }
+#endif
+
+ QCameraDevice m_cameraDevice;
+
+ QGstBin gstCameraBin;
+ QGstElement gstCamera;
+ QGstElement gstCapsFilter;
+ QGstElement gstDecode;
+ QGstElement gstVideoConvert;
+ QGstElement gstVideoScale;
+
+ bool m_active = false;
+ QString m_v4l2DevicePath;
+};
+
+class QGstreamerCustomCamera : public QGstreamerCameraBase
+{
+public:
+ explicit QGstreamerCustomCamera(QCamera *);
+ explicit QGstreamerCustomCamera(QCamera *, QGstElement element);
+
+ QGstElement gstElement() const override { return gstCamera; }
+ void setCamera(const QCameraDevice &) override;
+
+ bool isActive() const override;
+ void setActive(bool) override;
+
+private:
+ QGstElement gstCamera;
+ bool m_active{};
+ const bool m_userProvidedGstElement;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGSTREAMERCAMERACONTROL_H
diff --git a/src/plugins/multimedia/gstreamer/mediacapture/qgstreamerimagecapture.cpp b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamerimagecapture.cpp
new file mode 100644
index 000000000..9c21dc083
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamerimagecapture.cpp
@@ -0,0 +1,450 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qgstreamerimagecapture_p.h"
+
+#include <QtMultimedia/qvideoframeformat.h>
+#include <QtMultimedia/private/qmediastoragelocation_p.h>
+#include <QtMultimedia/private/qplatformcamera_p.h>
+#include <QtMultimedia/private/qplatformimagecapture_p.h>
+#include <QtMultimedia/private/qvideoframe_p.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qdir.h>
+#include <QtCore/qstandardpaths.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qloggingcategory.h>
+
+#include <common/qgstreamermetadata_p.h>
+#include <common/qgstvideobuffer_p.h>
+#include <common/qgstutils_p.h>
+
+#include <utility>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+Q_LOGGING_CATEGORY(qLcImageCaptureGst, "qt.multimedia.imageCapture")
+
+struct ThreadPoolSingleton
+{
+ QObject m_context;
+ QMutex m_poolMutex;
+ QThreadPool *m_instance{};
+ bool m_appUnderDestruction = false;
+
+ QThreadPool *get(const QMutexLocker<QMutex> &)
+ {
+ if (m_instance)
+ return m_instance;
+ if (m_appUnderDestruction || !qApp)
+ return nullptr;
+
+ using namespace std::chrono;
+
+ m_instance = new QThreadPool(qApp);
+ m_instance->setMaxThreadCount(1); // 1 thread;
+ static constexpr auto expiryTimeout = minutes(5);
+ m_instance->setExpiryTimeout(round<milliseconds>(expiryTimeout).count());
+
+ QObject::connect(qApp, &QCoreApplication::aboutToQuit, &m_context, [&] {
+ // we need to make sure that thread-local QRhi is destroyed before the application to
+ // prevent QTBUG-124189
+ QMutexLocker guard(&m_poolMutex);
+ delete m_instance;
+ m_instance = {};
+ m_appUnderDestruction = true;
+ });
+
+ QObject::connect(qApp, &QCoreApplication::destroyed, &m_context, [&] {
+ m_appUnderDestruction = false;
+ });
+ return m_instance;
+ }
+
+ template <typename Functor>
+ QFuture<void> run(Functor &&f)
+ {
+ QMutexLocker guard(&m_poolMutex);
+ QThreadPool *pool = get(guard);
+ if (!pool)
+ return QFuture<void>{};
+
+ return QtConcurrent::run(pool, std::forward<Functor>(f));
+ }
+};
+
+ThreadPoolSingleton s_threadPoolSingleton;
+
+}; // namespace
+
+QMaybe<QPlatformImageCapture *> QGstreamerImageCapture::create(QImageCapture *parent)
+{
+ static const auto error = qGstErrorMessageIfElementsNotAvailable(
+ "queue", "capsfilter", "videoconvert", "jpegenc", "jifmux", "fakesink");
+ if (error)
+ return *error;
+
+ return new QGstreamerImageCapture(parent);
+}
+
+QGstreamerImageCapture::QGstreamerImageCapture(QImageCapture *parent)
+ : QPlatformImageCapture(parent),
+ QGstreamerBufferProbe(ProbeBuffers),
+ bin{
+ QGstBin::create("imageCaptureBin"),
+ },
+ queue{
+ QGstElement::createFromFactory("queue", "imageCaptureQueue"),
+ },
+ filter{
+ QGstElement::createFromFactory("capsfilter", "filter"),
+ },
+ videoConvert{
+ QGstElement::createFromFactory("videoconvert", "imageCaptureConvert"),
+ },
+ encoder{
+ QGstElement::createFromFactory("jpegenc", "jpegEncoder"),
+ },
+ muxer{
+ QGstElement::createFromFactory("jifmux", "jpegMuxer"),
+ },
+ sink{
+ QGstElement::createFromFactory("fakesink", "imageCaptureSink"),
+ }
+{
+ // configures the queue to be fast, lightweight and non blocking
+ queue.set("leaky", 2 /*downstream*/);
+ queue.set("silent", true);
+ queue.set("max-size-buffers", uint(1));
+ queue.set("max-size-bytes", uint(0));
+ queue.set("max-size-time", quint64(0));
+
+ // imageCaptureSink do not wait for a preroll buffer when going READY -> PAUSED
+ // as no buffer will arrive until capture() is called
+ sink.set("async", false);
+
+ bin.add(queue, filter, videoConvert, encoder, muxer, sink);
+ qLinkGstElements(queue, filter, videoConvert, encoder, muxer, sink);
+ bin.addGhostPad(queue, "sink");
+
+ addProbeToPad(queue.staticPad("src").pad(), false);
+
+ sink.set("signal-handoffs", true);
+ m_handoffConnection = sink.connect("handoff", G_CALLBACK(&saveImageFilter), this);
+}
+
+QGstreamerImageCapture::~QGstreamerImageCapture()
+{
+ bin.setStateSync(GST_STATE_NULL);
+
+ // wait for pending futures
+ auto pendingFutures = [&] {
+ QMutexLocker guard(&m_mutex);
+ return std::move(m_pendingFutures);
+ }();
+
+ for (QFuture<void> &pendingImage : pendingFutures)
+ pendingImage.waitForFinished();
+}
+
+bool QGstreamerImageCapture::isReadyForCapture() const
+{
+ QMutexLocker guard(&m_mutex);
+ return m_session && !passImage && cameraActive;
+}
+
+int QGstreamerImageCapture::capture(const QString &fileName)
+{
+ using namespace Qt::Literals;
+ QString path = QMediaStorageLocation::generateFileName(
+ fileName, QStandardPaths::PicturesLocation, u"jpg"_s);
+ return doCapture(path);
+}
+
+int QGstreamerImageCapture::captureToBuffer()
+{
+ return doCapture(QString());
+}
+
+int QGstreamerImageCapture::doCapture(const QString &fileName)
+{
+ qCDebug(qLcImageCaptureGst) << "do capture";
+
+ {
+ QMutexLocker guard(&m_mutex);
+ if (!m_session) {
+ invokeDeferred([this] {
+ emit error(-1, QImageCapture::ResourceError,
+ QPlatformImageCapture::msgImageCaptureNotSet());
+ });
+
+ qCDebug(qLcImageCaptureGst) << "error 1";
+ return -1;
+ }
+ if (!m_session->camera()) {
+ invokeDeferred([this] {
+ emit error(-1, QImageCapture::ResourceError, tr("No camera available."));
+ });
+
+ qCDebug(qLcImageCaptureGst) << "error 2";
+ return -1;
+ }
+ if (passImage) {
+ invokeDeferred([this] {
+ emit error(-1, QImageCapture::NotReadyError,
+ QPlatformImageCapture::msgCameraNotReady());
+ });
+
+ qCDebug(qLcImageCaptureGst) << "error 3";
+ return -1;
+ }
+ m_lastId++;
+
+ pendingImages.enqueue({ m_lastId, fileName, QMediaMetaData{} });
+ // let one image pass the pipeline
+ passImage = true;
+ }
+
+ emit readyForCaptureChanged(false);
+ return m_lastId;
+}
+
+void QGstreamerImageCapture::setResolution(const QSize &resolution)
+{
+ QGstCaps padCaps = bin.staticPad("sink").currentCaps();
+ if (padCaps.isNull()) {
+ qDebug() << "Camera not ready";
+ return;
+ }
+ QGstCaps caps = padCaps.copy();
+ if (caps.isNull())
+ return;
+
+ gst_caps_set_simple(caps.caps(), "width", G_TYPE_INT, resolution.width(), "height", G_TYPE_INT,
+ resolution.height(), nullptr);
+ filter.set("caps", caps);
+}
+
+// HACK: gcc-10 and earlier reject [=,this] when building with c++17
+#if __cplusplus >= 202002L
+# define EQ_THIS_CAPTURE =, this
+#else
+# define EQ_THIS_CAPTURE =
+#endif
+
+bool QGstreamerImageCapture::probeBuffer(GstBuffer *buffer)
+{
+ QMutexLocker guard(&m_mutex);
+
+ if (!passImage)
+ return false;
+ qCDebug(qLcImageCaptureGst) << "probe buffer";
+
+ QGstBufferHandle bufferHandle{
+ buffer,
+ QGstBufferHandle::NeedsRef,
+ };
+
+ passImage = false;
+
+ bool ready = isReadyForCapture();
+ invokeDeferred([this, ready] {
+ emit readyForCaptureChanged(ready);
+ });
+
+ QGstCaps caps = bin.staticPad("sink").currentCaps();
+ auto memoryFormat = caps.memoryFormat();
+
+ GstVideoInfo previewInfo;
+ QVideoFrameFormat fmt;
+ auto optionalFormatAndVideoInfo = caps.formatAndVideoInfo();
+ if (optionalFormatAndVideoInfo)
+ std::tie(fmt, previewInfo) = std::move(*optionalFormatAndVideoInfo);
+
+ int futureId = futureIDAllocator += 1;
+
+ // ensure QVideoFrame::toImage is executed on a worker thread that is joined before the
+ // qApplication is destroyed
+ QFuture<void> future = s_threadPoolSingleton.run([EQ_THIS_CAPTURE]() mutable {
+ QMutexLocker guard(&m_mutex);
+ auto scopeExit = qScopeGuard([&] {
+ m_pendingFutures.remove(futureId);
+ });
+
+ if (!m_session) {
+ qDebug() << "QGstreamerImageCapture::probeBuffer: no session";
+ return;
+ }
+
+ auto *sink = m_session->gstreamerVideoSink();
+ auto gstBuffer = std::make_unique<QGstVideoBuffer>(std::move(bufferHandle), previewInfo,
+ sink, fmt, memoryFormat);
+
+ QVideoFrame frame = QVideoFramePrivate::createFrame(std::move(gstBuffer), fmt);
+ QImage img = frame.toImage();
+ if (img.isNull()) {
+ qDebug() << "received a null image";
+ return;
+ }
+
+ QMediaMetaData imageMetaData = metaData();
+ imageMetaData.insert(QMediaMetaData::Resolution, frame.size());
+ pendingImages.head().metaData = std::move(imageMetaData);
+ PendingImage pendingImage = pendingImages.head();
+
+ invokeDeferred([this, pendingImage = std::move(pendingImage), frame = std::move(frame),
+ img = std::move(img)]() mutable {
+ emit imageExposed(pendingImage.id);
+ qCDebug(qLcImageCaptureGst) << "Image available!";
+ emit imageAvailable(pendingImage.id, frame);
+ emit imageCaptured(pendingImage.id, img);
+ emit imageMetadataAvailable(pendingImage.id, pendingImage.metaData);
+ });
+ });
+
+ if (!future.isValid()) // during qApplication shutdown the threadpool becomes unusable
+ return true;
+
+ m_pendingFutures.insert(futureId, future);
+
+ return true;
+}
+
+#undef EQ_THIS_CAPTURE
+
+void QGstreamerImageCapture::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ QMutexLocker guard(&m_mutex);
+ QGstreamerMediaCapture *captureSession = static_cast<QGstreamerMediaCapture *>(session);
+ if (m_session == captureSession)
+ return;
+
+ bool readyForCapture = isReadyForCapture();
+ if (m_session) {
+ disconnect(m_session, nullptr, this, nullptr);
+ m_lastId = 0;
+ pendingImages.clear();
+ passImage = false;
+ cameraActive = false;
+ }
+
+ m_session = captureSession;
+ if (!m_session) {
+ if (readyForCapture)
+ emit readyForCaptureChanged(false);
+ return;
+ }
+
+ connect(m_session, &QPlatformMediaCaptureSession::cameraChanged, this,
+ &QGstreamerImageCapture::onCameraChanged);
+ onCameraChanged();
+}
+
+void QGstreamerImageCapture::setMetaData(const QMediaMetaData &m)
+{
+ {
+ QMutexLocker guard(&m_mutex);
+ QPlatformImageCapture::setMetaData(m);
+ }
+
+ // ensure taginject injects this metaData
+ applyMetaDataToTagSetter(m, muxer);
+}
+
+void QGstreamerImageCapture::cameraActiveChanged(bool active)
+{
+ qCDebug(qLcImageCaptureGst) << "cameraActiveChanged" << cameraActive << active;
+ if (cameraActive == active)
+ return;
+ cameraActive = active;
+ qCDebug(qLcImageCaptureGst) << "isReady" << isReadyForCapture();
+ emit readyForCaptureChanged(isReadyForCapture());
+}
+
+void QGstreamerImageCapture::onCameraChanged()
+{
+ QMutexLocker guard(&m_mutex);
+ if (m_session->camera()) {
+ cameraActiveChanged(m_session->camera()->isActive());
+ connect(m_session->camera(), &QPlatformCamera::activeChanged, this,
+ &QGstreamerImageCapture::cameraActiveChanged);
+ } else {
+ cameraActiveChanged(false);
+ }
+}
+
+gboolean QGstreamerImageCapture::saveImageFilter(GstElement *, GstBuffer *buffer, GstPad *,
+ QGstreamerImageCapture *capture)
+{
+ capture->saveBufferToImage(buffer);
+ return true;
+}
+
+void QGstreamerImageCapture::saveBufferToImage(GstBuffer *buffer)
+{
+ QMutexLocker guard(&m_mutex);
+ passImage = false;
+
+ if (pendingImages.isEmpty())
+ return;
+
+ PendingImage imageData = pendingImages.dequeue();
+ if (imageData.filename.isEmpty())
+ return;
+
+ int id = futureIDAllocator++;
+ QGstBufferHandle bufferHandle{
+ buffer,
+ QGstBufferHandle::NeedsRef,
+ };
+
+ QFuture<void> saveImageFuture = QtConcurrent::run([this, imageData, bufferHandle,
+ id]() mutable {
+ auto cleanup = qScopeGuard([&] {
+ QMutexLocker guard(&m_mutex);
+ m_pendingFutures.remove(id);
+ });
+
+ qCDebug(qLcImageCaptureGst) << "saving image as" << imageData.filename;
+
+ QFile f(imageData.filename);
+ if (!f.open(QFile::WriteOnly)) {
+ qCDebug(qLcImageCaptureGst) << " could not open image file for writing";
+ return;
+ }
+
+ GstMapInfo info;
+ GstBuffer *buffer = bufferHandle.get();
+ if (gst_buffer_map(buffer, &info, GST_MAP_READ)) {
+ f.write(reinterpret_cast<const char *>(info.data), info.size);
+ gst_buffer_unmap(buffer, &info);
+ }
+ f.close();
+
+ QMetaObject::invokeMethod(this, [this, imageData = std::move(imageData)]() mutable {
+ emit imageSaved(imageData.id, imageData.filename);
+ });
+ });
+
+ m_pendingFutures.insert(id, saveImageFuture);
+}
+
+QImageEncoderSettings QGstreamerImageCapture::imageSettings() const
+{
+ return m_settings;
+}
+
+void QGstreamerImageCapture::setImageSettings(const QImageEncoderSettings &settings)
+{
+ if (m_settings != settings) {
+ QSize resolution = settings.resolution();
+ if (m_settings.resolution() != resolution && !resolution.isEmpty())
+ setResolution(resolution);
+
+ m_settings = settings;
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qgstreamerimagecapture_p.cpp"
diff --git a/src/plugins/multimedia/gstreamer/mediacapture/qgstreamerimagecapture_p.h b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamerimagecapture_p.h
new file mode 100644
index 000000000..04a7c00b4
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamerimagecapture_p.h
@@ -0,0 +1,109 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERIMAGECAPTURECONTROL_H
+#define QGSTREAMERIMAGECAPTURECONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/private/qplatformimagecapture_p.h>
+#include <QtMultimedia/private/qmultimediautils_p.h>
+
+#include <QtCore/qmutex.h>
+#include <QtCore/qqueue.h>
+#include <QtConcurrent/QtConcurrentRun>
+
+#include <common/qgst_p.h>
+#include <common/qgstreamerbufferprobe_p.h>
+#include <mediacapture/qgstreamermediacapture_p.h>
+#include <gst/video/video.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerImageCapture : public QPlatformImageCapture, private QGstreamerBufferProbe
+{
+ Q_OBJECT
+
+public:
+ static QMaybe<QPlatformImageCapture *> create(QImageCapture *parent);
+ virtual ~QGstreamerImageCapture();
+
+ bool isReadyForCapture() const override;
+ int capture(const QString &fileName) override;
+ int captureToBuffer() override;
+
+ QImageEncoderSettings imageSettings() const override;
+ void setImageSettings(const QImageEncoderSettings &settings) override;
+
+ bool probeBuffer(GstBuffer *buffer) override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session);
+
+ QGstElement gstElement() const { return bin; }
+
+ void setMetaData(const QMediaMetaData &m) override;
+
+public Q_SLOTS:
+ void cameraActiveChanged(bool active);
+ void onCameraChanged();
+
+private:
+ QGstreamerImageCapture(QImageCapture *parent);
+
+ void setResolution(const QSize &resolution);
+ int doCapture(const QString &fileName);
+ static gboolean saveImageFilter(GstElement *element, GstBuffer *buffer, GstPad *pad,
+ QGstreamerImageCapture *capture);
+
+ void saveBufferToImage(GstBuffer *buffer);
+
+ mutable QRecursiveMutex
+ m_mutex; // guard all elements accessed from probeBuffer/saveBufferToImage
+ QGstreamerMediaCapture *m_session = nullptr;
+ int m_lastId = 0;
+ QImageEncoderSettings m_settings;
+
+ struct PendingImage {
+ int id;
+ QString filename;
+ QMediaMetaData metaData;
+ };
+
+ QQueue<PendingImage> pendingImages;
+
+ QGstBin bin;
+ QGstElement queue;
+ QGstElement filter;
+ QGstElement videoConvert;
+ QGstElement encoder;
+ QGstElement muxer;
+ QGstElement sink;
+ QGstPad videoSrcPad;
+
+ bool passImage = false;
+ bool cameraActive = false;
+
+ QGObjectHandlerScopedConnection m_handoffConnection;
+
+ QMap<int, QFuture<void>> m_pendingFutures;
+ int futureIDAllocator = 0;
+
+ template <typename Functor>
+ void invokeDeferred(Functor &&fn)
+ {
+ QMetaObject::invokeMethod(this, std::forward<decltype(fn)>(fn), Qt::QueuedConnection);
+ };
+};
+
+QT_END_NAMESPACE
+
+#endif // QGSTREAMERCAPTURECORNTROL_H
diff --git a/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediacapture.cpp b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediacapture.cpp
new file mode 100644
index 000000000..7ecbb07d7
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediacapture.cpp
@@ -0,0 +1,326 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <mediacapture/qgstreamermediacapture_p.h>
+#include <mediacapture/qgstreamermediaencoder_p.h>
+#include <mediacapture/qgstreamerimagecapture_p.h>
+#include <mediacapture/qgstreamercamera_p.h>
+#include <common/qgstpipeline_p.h>
+#include <common/qgstreameraudioinput_p.h>
+#include <common/qgstreameraudiooutput_p.h>
+#include <common/qgstreamervideooutput_p.h>
+
+#include <QtCore/qloggingcategory.h>
+#include <QtCore/private/quniquehandle_p.h>
+
+QT_BEGIN_NAMESPACE
+
+static void linkTeeToPad(QGstElement tee, QGstPad sink)
+{
+ if (tee.isNull() || sink.isNull())
+ return;
+
+ auto source = tee.getRequestPad("src_%u");
+ source.link(sink);
+}
+
+QMaybe<QPlatformMediaCaptureSession *> QGstreamerMediaCapture::create()
+{
+ auto videoOutput = QGstreamerVideoOutput::create();
+ if (!videoOutput)
+ return videoOutput.error();
+
+ static const auto error = qGstErrorMessageIfElementsNotAvailable("tee", "capsfilter");
+ if (error)
+ return *error;
+
+ return new QGstreamerMediaCapture(videoOutput.value());
+}
+
+QGstreamerMediaCapture::QGstreamerMediaCapture(QGstreamerVideoOutput *videoOutput)
+ : capturePipeline(QGstPipeline::create("mediaCapturePipeline")), gstVideoOutput(videoOutput)
+{
+ gstVideoOutput->setParent(this);
+ gstVideoOutput->setIsPreview();
+ gstVideoOutput->setPipeline(capturePipeline);
+
+ // Use system clock to drive all elements in the pipeline. Otherwise,
+ // the clock is sourced from the elements (e.g. from an audio source).
+ // Since the elements are added and removed dynamically the clock would
+ // also change causing lost of synchronization in the pipeline.
+
+ QGstClockHandle systemClock{
+ gst_system_clock_obtain(),
+ };
+ gst_pipeline_use_clock(capturePipeline.pipeline(), systemClock.get());
+
+ // This is the recording pipeline with only live sources, thus the pipeline
+ // will be always in the playing state.
+ capturePipeline.setState(GST_STATE_PLAYING);
+ capturePipeline.setInStoppedState(false);
+
+ capturePipeline.dumpGraph("initial");
+}
+
+QGstreamerMediaCapture::~QGstreamerMediaCapture()
+{
+ setMediaRecorder(nullptr);
+ setImageCapture(nullptr);
+ setCamera(nullptr);
+ capturePipeline.setStateSync(GST_STATE_NULL);
+}
+
+QPlatformCamera *QGstreamerMediaCapture::camera()
+{
+ return gstCamera;
+}
+
+void QGstreamerMediaCapture::setCamera(QPlatformCamera *platformCamera)
+{
+ auto *camera = static_cast<QGstreamerCameraBase *>(platformCamera);
+ if (gstCamera == camera)
+ return;
+
+ if (gstCamera) {
+ QObject::disconnect(gstCameraActiveConnection);
+ if (gstVideoTee)
+ setCameraActive(false);
+ }
+
+ gstCamera = camera;
+
+ if (gstCamera) {
+ gstCameraActiveConnection = QObject::connect(camera, &QPlatformCamera::activeChanged, this,
+ &QGstreamerMediaCapture::setCameraActive);
+ if (gstCamera->isActive())
+ setCameraActive(true);
+ }
+
+ emit cameraChanged();
+}
+
+void QGstreamerMediaCapture::setCameraActive(bool activate)
+{
+ capturePipeline.modifyPipelineWhileNotRunning([&] {
+ if (activate) {
+ QGstElement cameraElement = gstCamera->gstElement();
+ gstVideoTee = QGstElement::createFromFactory("tee", "videotee");
+ gstVideoTee.set("allow-not-linked", true);
+
+ capturePipeline.add(gstVideoOutput->gstElement(), cameraElement, gstVideoTee);
+
+ linkTeeToPad(gstVideoTee, encoderVideoSink);
+ linkTeeToPad(gstVideoTee, gstVideoOutput->gstElement().staticPad("sink"));
+ linkTeeToPad(gstVideoTee, imageCaptureSink);
+
+ qLinkGstElements(cameraElement, gstVideoTee);
+
+ capturePipeline.syncChildrenState();
+ } else {
+ if (encoderVideoCapsFilter)
+ qUnlinkGstElements(gstVideoTee, encoderVideoCapsFilter);
+ if (m_imageCapture)
+ qUnlinkGstElements(gstVideoTee, m_imageCapture->gstElement());
+
+ auto camera = gstCamera->gstElement();
+
+ capturePipeline.stopAndRemoveElements(camera, gstVideoTee,
+ gstVideoOutput->gstElement());
+
+ gstVideoTee = {};
+ gstCamera->setCaptureSession(nullptr);
+ }
+ });
+
+ capturePipeline.dumpGraph("camera");
+}
+
+QPlatformImageCapture *QGstreamerMediaCapture::imageCapture()
+{
+ return m_imageCapture;
+}
+
+void QGstreamerMediaCapture::setImageCapture(QPlatformImageCapture *imageCapture)
+{
+ QGstreamerImageCapture *control = static_cast<QGstreamerImageCapture *>(imageCapture);
+ if (m_imageCapture == control)
+ return;
+
+ capturePipeline.modifyPipelineWhileNotRunning([&] {
+ if (m_imageCapture) {
+ qUnlinkGstElements(gstVideoTee, m_imageCapture->gstElement());
+ capturePipeline.stopAndRemoveElements(m_imageCapture->gstElement());
+ imageCaptureSink = {};
+ m_imageCapture->setCaptureSession(nullptr);
+ }
+
+ m_imageCapture = control;
+ if (m_imageCapture) {
+ imageCaptureSink = m_imageCapture->gstElement().staticPad("sink");
+ capturePipeline.add(m_imageCapture->gstElement());
+ m_imageCapture->gstElement().syncStateWithParent();
+ linkTeeToPad(gstVideoTee, imageCaptureSink);
+ m_imageCapture->setCaptureSession(this);
+ }
+ });
+
+ capturePipeline.dumpGraph("imageCapture");
+
+ emit imageCaptureChanged();
+}
+
+void QGstreamerMediaCapture::setMediaRecorder(QPlatformMediaRecorder *recorder)
+{
+ QGstreamerMediaEncoder *control = static_cast<QGstreamerMediaEncoder *>(recorder);
+ if (m_mediaEncoder == control)
+ return;
+
+ if (m_mediaEncoder)
+ m_mediaEncoder->setCaptureSession(nullptr);
+ m_mediaEncoder = control;
+ if (m_mediaEncoder)
+ m_mediaEncoder->setCaptureSession(this);
+
+ emit encoderChanged();
+ capturePipeline.dumpGraph("encoder");
+}
+
+QPlatformMediaRecorder *QGstreamerMediaCapture::mediaRecorder()
+{
+ return m_mediaEncoder;
+}
+
+void QGstreamerMediaCapture::linkEncoder(QGstPad audioSink, QGstPad videoSink)
+{
+ capturePipeline.modifyPipelineWhileNotRunning([&] {
+ if (!gstVideoTee.isNull() && !videoSink.isNull()) {
+ QGstCaps caps = gstVideoTee.sink().currentCaps();
+
+ encoderVideoCapsFilter =
+ QGstElement::createFromFactory("capsfilter", "encoderVideoCapsFilter");
+ Q_ASSERT(encoderVideoCapsFilter);
+ encoderVideoCapsFilter.set("caps", caps);
+
+ capturePipeline.add(encoderVideoCapsFilter);
+
+ encoderVideoCapsFilter.src().link(videoSink);
+ linkTeeToPad(gstVideoTee, encoderVideoCapsFilter.sink());
+ encoderVideoSink = encoderVideoCapsFilter.sink();
+ }
+
+ if (!gstAudioTee.isNull() && !audioSink.isNull()) {
+ QGstCaps caps = gstAudioTee.sink().currentCaps();
+
+ encoderAudioCapsFilter =
+ QGstElement::createFromFactory("capsfilter", "encoderAudioCapsFilter");
+ Q_ASSERT(encoderAudioCapsFilter);
+ encoderAudioCapsFilter.set("caps", caps);
+
+ capturePipeline.add(encoderAudioCapsFilter);
+
+ encoderAudioCapsFilter.src().link(audioSink);
+ linkTeeToPad(gstAudioTee, encoderAudioCapsFilter.sink());
+ encoderAudioSink = encoderAudioCapsFilter.sink();
+ }
+ });
+}
+
+void QGstreamerMediaCapture::unlinkEncoder()
+{
+ capturePipeline.modifyPipelineWhileNotRunning([&] {
+ if (encoderVideoCapsFilter) {
+ qUnlinkGstElements(gstVideoTee, encoderVideoCapsFilter);
+ capturePipeline.stopAndRemoveElements(encoderVideoCapsFilter);
+ encoderVideoCapsFilter = {};
+ }
+
+ if (encoderAudioCapsFilter) {
+ qUnlinkGstElements(gstAudioTee, encoderAudioCapsFilter);
+ capturePipeline.stopAndRemoveElements(encoderAudioCapsFilter);
+ encoderAudioCapsFilter = {};
+ }
+
+ encoderAudioSink = {};
+ encoderVideoSink = {};
+ });
+}
+
+const QGstPipeline &QGstreamerMediaCapture::pipeline() const
+{
+ return capturePipeline;
+}
+
+void QGstreamerMediaCapture::setAudioInput(QPlatformAudioInput *input)
+{
+ if (gstAudioInput == input)
+ return;
+
+ capturePipeline.modifyPipelineWhileNotRunning([&] {
+ if (gstAudioInput) {
+ if (encoderAudioCapsFilter)
+ qUnlinkGstElements(gstAudioTee, encoderAudioCapsFilter);
+
+ if (gstAudioOutput) {
+ qUnlinkGstElements(gstAudioTee, gstAudioOutput->gstElement());
+ capturePipeline.stopAndRemoveElements(gstAudioOutput->gstElement());
+ }
+
+ capturePipeline.stopAndRemoveElements(gstAudioInput->gstElement(), gstAudioTee);
+ gstAudioTee = {};
+ }
+
+ gstAudioInput = static_cast<QGstreamerAudioInput *>(input);
+ if (gstAudioInput) {
+ Q_ASSERT(gstAudioTee.isNull());
+ gstAudioTee = QGstElement::createFromFactory("tee", "audiotee");
+ gstAudioTee.set("allow-not-linked", true);
+ capturePipeline.add(gstAudioInput->gstElement(), gstAudioTee);
+ qLinkGstElements(gstAudioInput->gstElement(), gstAudioTee);
+
+ if (gstAudioOutput) {
+ capturePipeline.add(gstAudioOutput->gstElement());
+ gstAudioOutput->gstElement().setState(GST_STATE_PLAYING);
+ linkTeeToPad(gstAudioTee, gstAudioOutput->gstElement().staticPad("sink"));
+ }
+
+ capturePipeline.syncChildrenState();
+
+ linkTeeToPad(gstAudioTee, encoderAudioSink);
+ }
+ });
+}
+
+void QGstreamerMediaCapture::setVideoPreview(QVideoSink *sink)
+{
+ gstVideoOutput->setVideoSink(sink);
+}
+
+void QGstreamerMediaCapture::setAudioOutput(QPlatformAudioOutput *output)
+{
+ if (gstAudioOutput == output)
+ return;
+
+ capturePipeline.modifyPipelineWhileNotRunning([&] {
+ if (gstAudioOutput && gstAudioInput) {
+ // If audio input is set, the output is in the pipeline
+ qUnlinkGstElements(gstAudioTee, gstAudioOutput->gstElement());
+ capturePipeline.stopAndRemoveElements(gstAudioOutput->gstElement());
+ }
+
+ gstAudioOutput = static_cast<QGstreamerAudioOutput *>(output);
+ if (gstAudioOutput && gstAudioInput) {
+ capturePipeline.add(gstAudioOutput->gstElement());
+ capturePipeline.syncChildrenState();
+ linkTeeToPad(gstAudioTee, gstAudioOutput->gstElement().staticPad("sink"));
+ }
+ });
+}
+
+QGstreamerVideoSink *QGstreamerMediaCapture::gstreamerVideoSink() const
+{
+ return gstVideoOutput ? gstVideoOutput->gstreamerVideoSink() : nullptr;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qgstreamermediacapture_p.cpp"
diff --git a/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediacapture_p.h b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediacapture_p.h
new file mode 100644
index 000000000..c44e31f0e
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediacapture_p.h
@@ -0,0 +1,97 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERCAPTURESERVICE_H
+#define QGSTREAMERCAPTURESERVICE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediacapture_p.h>
+#include <private/qplatformmediaintegration_p.h>
+
+#include <common/qgst_p.h>
+#include <common/qgstpipeline_p.h>
+
+#include <qtimer.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerCameraBase;
+class QGstreamerImageCapture;
+class QGstreamerMediaEncoder;
+class QGstreamerAudioInput;
+class QGstreamerAudioOutput;
+class QGstreamerVideoOutput;
+class QGstreamerVideoSink;
+
+class QGstreamerMediaCapture final : public QPlatformMediaCaptureSession
+{
+ Q_OBJECT
+
+public:
+ static QMaybe<QPlatformMediaCaptureSession *> create();
+ virtual ~QGstreamerMediaCapture();
+
+ QPlatformCamera *camera() override;
+ void setCamera(QPlatformCamera *camera) override;
+
+ QPlatformImageCapture *imageCapture() override;
+ void setImageCapture(QPlatformImageCapture *imageCapture) override;
+
+ QPlatformMediaRecorder *mediaRecorder() override;
+ void setMediaRecorder(QPlatformMediaRecorder *recorder) override;
+
+ void setAudioInput(QPlatformAudioInput *input) override;
+ QGstreamerAudioInput *audioInput() { return gstAudioInput; }
+
+ void setVideoPreview(QVideoSink *sink) override;
+ void setAudioOutput(QPlatformAudioOutput *output) override;
+
+ void linkEncoder(QGstPad audioSink, QGstPad videoSink);
+ void unlinkEncoder();
+
+ const QGstPipeline &pipeline() const;
+
+ QGstreamerVideoSink *gstreamerVideoSink() const;
+
+private:
+ void setCameraActive(bool activate);
+
+ explicit QGstreamerMediaCapture(QGstreamerVideoOutput *videoOutput);
+
+ friend QGstreamerMediaEncoder;
+ // Gst elements
+ QGstPipeline capturePipeline;
+
+ QGstreamerAudioInput *gstAudioInput = nullptr;
+ QGstreamerCameraBase *gstCamera = nullptr;
+ QMetaObject::Connection gstCameraActiveConnection;
+
+ QGstElement gstAudioTee;
+ QGstElement gstVideoTee;
+ QGstElement encoderVideoCapsFilter;
+ QGstElement encoderAudioCapsFilter;
+
+ QGstPad encoderAudioSink;
+ QGstPad encoderVideoSink;
+ QGstPad imageCaptureSink;
+
+ QGstreamerAudioOutput *gstAudioOutput = nullptr;
+ QGstreamerVideoOutput *gstVideoOutput = nullptr;
+
+ QGstreamerMediaEncoder *m_mediaEncoder = nullptr;
+ QGstreamerImageCapture *m_imageCapture = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGSTREAMERCAPTURESERVICE_H
diff --git a/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder.cpp b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder.cpp
new file mode 100644
index 000000000..4ec10ca84
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder.cpp
@@ -0,0 +1,419 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <mediacapture/qgstreamermediaencoder_p.h>
+#include <qgstreamerformatinfo_p.h>
+#include <common/qgstpipeline_p.h>
+#include <common/qgstreamermessage_p.h>
+#include <common/qgst_debug_p.h>
+#include <qgstreamerintegration_p.h>
+
+#include <QtMultimedia/private/qmediastoragelocation_p.h>
+#include <QtMultimedia/private/qplatformcamera_p.h>
+#include <QtMultimedia/qaudiodevice.h>
+
+#include <QtCore/qdebug.h>
+#include <QtCore/qeventloop.h>
+#include <QtCore/qstandardpaths.h>
+#include <QtCore/qmimetype.h>
+#include <QtCore/qloggingcategory.h>
+
+#include <gst/gsttagsetter.h>
+#include <gst/gstversion.h>
+#include <gst/video/video.h>
+#include <gst/pbutils/encoding-profile.h>
+
+static Q_LOGGING_CATEGORY(qLcMediaEncoderGst, "qt.multimedia.encoder")
+
+QT_BEGIN_NAMESPACE
+
+QGstreamerMediaEncoder::QGstreamerMediaEncoder(QMediaRecorder *parent)
+ : QPlatformMediaRecorder(parent),
+ audioPauseControl(*this),
+ videoPauseControl(*this)
+{
+ signalDurationChangedTimer.setInterval(100);
+ signalDurationChangedTimer.callOnTimeout(&signalDurationChangedTimer, [this]() {
+ durationChanged(duration());
+ });
+}
+
+QGstreamerMediaEncoder::~QGstreamerMediaEncoder()
+{
+ if (!capturePipeline.isNull()) {
+ finalize();
+ capturePipeline.removeMessageFilter(this);
+ capturePipeline.setStateSync(GST_STATE_NULL);
+ }
+}
+
+bool QGstreamerMediaEncoder::isLocationWritable(const QUrl &) const
+{
+ return true;
+}
+
+void QGstreamerMediaEncoder::handleSessionError(QMediaRecorder::Error code, const QString &description)
+{
+ updateError(code, description);
+ stop();
+}
+
+bool QGstreamerMediaEncoder::processBusMessage(const QGstreamerMessage &msg)
+{
+ constexpr bool traceStateChange = false;
+ constexpr bool traceAllEvents = false;
+
+ if constexpr (traceAllEvents)
+ qCDebug(qLcMediaEncoderGst) << "received event:" << msg;
+
+ switch (msg.type()) {
+ case GST_MESSAGE_ELEMENT: {
+ QGstStructureView s = msg.structure();
+ if (s.name() == "GstBinForwarded")
+ return processBusMessage(s.getMessage());
+
+ qCDebug(qLcMediaEncoderGst)
+ << "received element message from" << msg.source().name() << s.name();
+ return false;
+ }
+
+ case GST_MESSAGE_EOS: {
+ qCDebug(qLcMediaEncoderGst) << "received EOS from" << msg.source().name();
+ finalize();
+ return false;
+ }
+
+ case GST_MESSAGE_ERROR: {
+ qCDebug(qLcMediaEncoderGst)
+ << "received error:" << msg.source().name() << QCompactGstMessageAdaptor(msg);
+
+ QUniqueGErrorHandle err;
+ QGString debug;
+ gst_message_parse_error(msg.message(), &err, &debug);
+ updateError(QMediaRecorder::ResourceError, QString::fromUtf8(err.get()->message));
+ if (!m_finalizing)
+ stop();
+ finalize();
+ return false;
+ }
+
+ case GST_MESSAGE_STATE_CHANGED: {
+ if constexpr (traceStateChange)
+ qCDebug(qLcMediaEncoderGst)
+ << "received state change" << QCompactGstMessageAdaptor(msg);
+
+ return false;
+ }
+
+ default:
+ return false;
+ };
+}
+
+qint64 QGstreamerMediaEncoder::duration() const
+{
+ return std::max(audioPauseControl.duration, videoPauseControl.duration);
+}
+
+
+static GstEncodingContainerProfile *createContainerProfile(const QMediaEncoderSettings &settings)
+{
+ auto *formatInfo = QGstreamerIntegration::instance()->gstFormatsInfo();
+
+ auto caps = formatInfo->formatCaps(settings.fileFormat());
+
+ GstEncodingContainerProfile *profile =
+ (GstEncodingContainerProfile *)gst_encoding_container_profile_new(
+ "container_profile", (gchar *)"custom container profile",
+ const_cast<GstCaps *>(caps.caps()),
+ nullptr); // preset
+ return profile;
+}
+
+static GstEncodingProfile *createVideoProfile(const QMediaEncoderSettings &settings)
+{
+ auto *formatInfo = QGstreamerIntegration::instance()->gstFormatsInfo();
+
+ QGstCaps caps = formatInfo->videoCaps(settings.mediaFormat());
+ if (caps.isNull())
+ return nullptr;
+
+ QSize videoResolution = settings.videoResolution();
+ if (videoResolution.isValid())
+ caps.setResolution(videoResolution);
+
+ GstEncodingVideoProfile *profile =
+ gst_encoding_video_profile_new(const_cast<GstCaps *>(caps.caps()), nullptr,
+ nullptr, // restriction
+ 0); // presence
+
+ gst_encoding_video_profile_set_pass(profile, 0);
+ gst_encoding_video_profile_set_variableframerate(profile, TRUE);
+
+ return (GstEncodingProfile *)profile;
+}
+
+static GstEncodingProfile *createAudioProfile(const QMediaEncoderSettings &settings)
+{
+ auto *formatInfo = QGstreamerIntegration::instance()->gstFormatsInfo();
+
+ auto caps = formatInfo->audioCaps(settings.mediaFormat());
+ if (caps.isNull())
+ return nullptr;
+
+ GstEncodingProfile *profile =
+ (GstEncodingProfile *)gst_encoding_audio_profile_new(const_cast<GstCaps *>(caps.caps()),
+ nullptr, // preset
+ nullptr, // restriction
+ 0); // presence
+
+ return profile;
+}
+
+
+static GstEncodingContainerProfile *createEncodingProfile(const QMediaEncoderSettings &settings)
+{
+ auto *containerProfile = createContainerProfile(settings);
+ if (!containerProfile) {
+ qWarning() << "QGstreamerMediaEncoder: failed to create container profile!";
+ return nullptr;
+ }
+
+ GstEncodingProfile *audioProfile = createAudioProfile(settings);
+ GstEncodingProfile *videoProfile = nullptr;
+ if (settings.videoCodec() != QMediaFormat::VideoCodec::Unspecified)
+ videoProfile = createVideoProfile(settings);
+// qDebug() << "audio profile" << (audioProfile ? gst_caps_to_string(gst_encoding_profile_get_format(audioProfile)) : "(null)");
+// qDebug() << "video profile" << (videoProfile ? gst_caps_to_string(gst_encoding_profile_get_format(videoProfile)) : "(null)");
+// qDebug() << "conta profile" << gst_caps_to_string(gst_encoding_profile_get_format((GstEncodingProfile *)containerProfile));
+
+ if (videoProfile) {
+ if (!gst_encoding_container_profile_add_profile(containerProfile, videoProfile)) {
+ qWarning() << "QGstreamerMediaEncoder: failed to add video profile!";
+ gst_encoding_profile_unref(videoProfile);
+ }
+ }
+ if (audioProfile) {
+ if (!gst_encoding_container_profile_add_profile(containerProfile, audioProfile)) {
+ qWarning() << "QGstreamerMediaEncoder: failed to add audio profile!";
+ gst_encoding_profile_unref(audioProfile);
+ }
+ }
+
+ return containerProfile;
+}
+
+void QGstreamerMediaEncoder::PauseControl::reset()
+{
+ pauseOffsetPts = 0;
+ pauseStartPts.reset();
+ duration = 0;
+ firstBufferPts.reset();
+}
+
+void QGstreamerMediaEncoder::PauseControl::installOn(QGstPad pad)
+{
+ pad.addProbe<&QGstreamerMediaEncoder::PauseControl::processBuffer>(this, GST_PAD_PROBE_TYPE_BUFFER);
+}
+
+GstPadProbeReturn QGstreamerMediaEncoder::PauseControl::processBuffer(QGstPad, GstPadProbeInfo *info)
+{
+ auto buffer = GST_PAD_PROBE_INFO_BUFFER(info);
+ if (!buffer)
+ return GST_PAD_PROBE_OK;
+
+ buffer = gst_buffer_make_writable(buffer);
+
+ if (!buffer)
+ return GST_PAD_PROBE_OK;
+
+ GST_PAD_PROBE_INFO_DATA(info) = buffer;
+
+ if (!GST_BUFFER_PTS_IS_VALID(buffer))
+ return GST_PAD_PROBE_OK;
+
+ if (!firstBufferPts)
+ firstBufferPts = GST_BUFFER_PTS(buffer);
+
+ if (encoder.state() == QMediaRecorder::PausedState) {
+ if (!pauseStartPts)
+ pauseStartPts = GST_BUFFER_PTS(buffer);
+
+ return GST_PAD_PROBE_DROP;
+ }
+
+ if (pauseStartPts) {
+ pauseOffsetPts += GST_BUFFER_PTS(buffer) - *pauseStartPts;
+ pauseStartPts.reset();
+ }
+ GST_BUFFER_PTS(buffer) -= pauseOffsetPts;
+
+ duration = (GST_BUFFER_PTS(buffer) - *firstBufferPts) / GST_MSECOND;
+
+ return GST_PAD_PROBE_OK;
+}
+
+void QGstreamerMediaEncoder::record(QMediaEncoderSettings &settings)
+{
+ if (!m_session ||m_finalizing || state() != QMediaRecorder::StoppedState)
+ return;
+
+ const auto hasVideo = m_session->camera() && m_session->camera()->isActive();
+ const auto hasAudio = m_session->audioInput() != nullptr;
+
+ if (!hasVideo && !hasAudio) {
+ updateError(QMediaRecorder::ResourceError, QMediaRecorder::tr("No camera or audio input"));
+ return;
+ }
+
+ const auto audioOnly = settings.videoCodec() == QMediaFormat::VideoCodec::Unspecified;
+
+ auto primaryLocation = audioOnly ? QStandardPaths::MusicLocation : QStandardPaths::MoviesLocation;
+ auto container = settings.mimeType().preferredSuffix();
+ auto location = QMediaStorageLocation::generateFileName(outputLocation().toLocalFile(), primaryLocation, container);
+
+ QUrl actualSink = QUrl::fromLocalFile(QDir::currentPath()).resolved(location);
+ qCDebug(qLcMediaEncoderGst) << "recording new video to" << actualSink;
+
+ Q_ASSERT(!actualSink.isEmpty());
+
+ gstEncoder = QGstBin::createFromFactory("encodebin", "encodebin");
+ Q_ASSERT(gstEncoder);
+ auto *encodingProfile = createEncodingProfile(settings);
+ g_object_set (gstEncoder.object(), "profile", encodingProfile, nullptr);
+ gst_encoding_profile_unref(encodingProfile);
+
+ gstFileSink = QGstElement::createFromFactory("filesink", "filesink");
+ Q_ASSERT(gstFileSink);
+ gstFileSink.set("location", QFile::encodeName(actualSink.toLocalFile()).constData());
+ gstFileSink.set("async", false);
+
+ QGstPad audioSink = {};
+ QGstPad videoSink = {};
+
+ audioPauseControl.reset();
+ videoPauseControl.reset();
+
+ if (hasAudio) {
+ audioSink = gstEncoder.getRequestPad("audio_%u");
+ if (audioSink.isNull())
+ qWarning() << "Unsupported audio codec";
+ else
+ audioPauseControl.installOn(audioSink);
+ }
+
+ if (hasVideo) {
+ videoSink = gstEncoder.getRequestPad("video_%u");
+ if (videoSink.isNull())
+ qWarning() << "Unsupported video codec";
+ else
+ videoPauseControl.installOn(videoSink);
+ }
+
+ capturePipeline.modifyPipelineWhileNotRunning([&] {
+ capturePipeline.add(gstEncoder, gstFileSink);
+ qLinkGstElements(gstEncoder, gstFileSink);
+ applyMetaDataToTagSetter(m_metaData, gstEncoder);
+
+ m_session->linkEncoder(audioSink, videoSink);
+
+ gstEncoder.syncStateWithParent();
+ gstFileSink.syncStateWithParent();
+ });
+
+ signalDurationChangedTimer.start();
+ capturePipeline.dumpGraph("recording");
+
+ durationChanged(0);
+ stateChanged(QMediaRecorder::RecordingState);
+ actualLocationChanged(QUrl::fromLocalFile(location));
+}
+
+void QGstreamerMediaEncoder::pause()
+{
+ if (!m_session || m_finalizing || state() != QMediaRecorder::RecordingState)
+ return;
+ signalDurationChangedTimer.stop();
+ durationChanged(duration());
+ capturePipeline.dumpGraph("before-pause");
+ stateChanged(QMediaRecorder::PausedState);
+}
+
+void QGstreamerMediaEncoder::resume()
+{
+ capturePipeline.dumpGraph("before-resume");
+ if (!m_session || m_finalizing || state() != QMediaRecorder::PausedState)
+ return;
+ signalDurationChangedTimer.start();
+ stateChanged(QMediaRecorder::RecordingState);
+}
+
+void QGstreamerMediaEncoder::stop()
+{
+ if (!m_session || m_finalizing || state() == QMediaRecorder::StoppedState)
+ return;
+ durationChanged(duration());
+ qCDebug(qLcMediaEncoderGst) << "stop";
+ m_finalizing = true;
+ m_session->unlinkEncoder();
+ signalDurationChangedTimer.stop();
+
+ qCDebug(qLcMediaEncoderGst) << ">>>>>>>>>>>>> sending EOS";
+ gstEncoder.sendEos();
+}
+
+void QGstreamerMediaEncoder::finalize()
+{
+ if (!m_session || gstEncoder.isNull())
+ return;
+
+ qCDebug(qLcMediaEncoderGst) << "finalize";
+
+ capturePipeline.stopAndRemoveElements(gstEncoder, gstFileSink);
+ gstFileSink = {};
+ gstEncoder = {};
+ m_finalizing = false;
+ stateChanged(QMediaRecorder::StoppedState);
+}
+
+void QGstreamerMediaEncoder::setMetaData(const QMediaMetaData &metaData)
+{
+ if (!m_session)
+ return;
+ m_metaData = metaData;
+}
+
+QMediaMetaData QGstreamerMediaEncoder::metaData() const
+{
+ return m_metaData;
+}
+
+void QGstreamerMediaEncoder::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ QGstreamerMediaCapture *captureSession = static_cast<QGstreamerMediaCapture *>(session);
+ if (m_session == captureSession)
+ return;
+
+ if (m_session) {
+ stop();
+ if (m_finalizing) {
+ QEventLoop loop;
+ QObject::connect(mediaRecorder(), &QMediaRecorder::recorderStateChanged, &loop,
+ &QEventLoop::quit);
+ loop.exec();
+ }
+
+ capturePipeline.removeMessageFilter(this);
+ capturePipeline = {};
+ }
+
+ m_session = captureSession;
+ if (!m_session)
+ return;
+
+ capturePipeline = captureSession->capturePipeline;
+ capturePipeline.set("message-forward", true);
+ capturePipeline.installMessageFilter(this);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder_p.h b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder_p.h
new file mode 100644
index 000000000..56e8c193b
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder_p.h
@@ -0,0 +1,91 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+#ifndef QGSTREAMERENCODERCONTROL_H
+#define QGSTREAMERENCODERCONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <mediacapture/qgstreamermediacapture_p.h>
+#include <common/qgstreamermetadata_p.h>
+
+#include <QtMultimedia/private/qplatformmediarecorder_p.h>
+#include <QtCore/qurl.h>
+#include <QtCore/qdir.h>
+#include <QtCore/qelapsedtimer.h>
+#include <QtCore/qtimer.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMediaMetaData;
+class QGstreamerMessage;
+
+class QGstreamerMediaEncoder : public QPlatformMediaRecorder, QGstreamerBusMessageFilter
+{
+public:
+ explicit QGstreamerMediaEncoder(QMediaRecorder *parent);
+ virtual ~QGstreamerMediaEncoder();
+
+ bool isLocationWritable(const QUrl &sink) const override;
+
+ qint64 duration() const override;
+
+ void record(QMediaEncoderSettings &settings) override;
+ void pause() override;
+ void resume() override;
+ void stop() override;
+
+ void setMetaData(const QMediaMetaData &) override;
+ QMediaMetaData metaData() const override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session);
+
+ QGstElement getEncoder() { return gstEncoder; }
+private:
+ bool processBusMessage(const QGstreamerMessage& message) override;
+
+private:
+ struct PauseControl {
+ explicit PauseControl(QPlatformMediaRecorder &encoder) : encoder(encoder) { }
+
+ GstPadProbeReturn processBuffer(QGstPad pad, GstPadProbeInfo *info);
+ void installOn(QGstPad pad);
+ void reset();
+
+ QPlatformMediaRecorder &encoder;
+ GstClockTime pauseOffsetPts = 0;
+ std::optional<GstClockTime> pauseStartPts;
+ std::optional<GstClockTime> firstBufferPts;
+ qint64 duration = 0;
+ };
+
+ PauseControl audioPauseControl;
+ PauseControl videoPauseControl;
+
+ void handleSessionError(QMediaRecorder::Error code, const QString &description);
+ void finalize();
+
+ QGstreamerMediaCapture *m_session = nullptr;
+ QMediaMetaData m_metaData;
+ QTimer signalDurationChangedTimer;
+
+ QGstPipeline capturePipeline;
+ QGstBin gstEncoder;
+ QGstElement gstFileSink;
+
+ bool m_finalizing = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGSTREAMERENCODERCONTROL_H
diff --git a/src/plugins/multimedia/gstreamer/qgstreamerformatinfo.cpp b/src/plugins/multimedia/gstreamer/qgstreamerformatinfo.cpp
new file mode 100644
index 000000000..a657fc52f
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/qgstreamerformatinfo.cpp
@@ -0,0 +1,445 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <common/qglist_helper_p.h>
+#include "qgstreamerformatinfo_p.h"
+
+#include <gst/gst.h>
+
+QT_BEGIN_NAMESPACE
+
+QMediaFormat::AudioCodec QGstreamerFormatInfo::audioCodecForCaps(QGstStructureView structure)
+{
+ using namespace std::string_view_literals;
+ const char *name = structure.name().data();
+
+ if (!name || (strncmp(name, "audio/", 6) != 0))
+ return QMediaFormat::AudioCodec::Unspecified;
+ name += 6;
+ if (name == "mpeg"sv) {
+ auto version = structure["mpegversion"].toInt();
+ if (version == 1) {
+ auto layer = structure["layer"];
+ if (!layer.isNull())
+ return QMediaFormat::AudioCodec::MP3;
+ }
+ if (version == 4)
+ return QMediaFormat::AudioCodec::AAC;
+ return QMediaFormat::AudioCodec::Unspecified;
+ }
+ if (name == "x-ac3"sv)
+ return QMediaFormat::AudioCodec::AC3;
+
+ if (name == "x-eac3"sv)
+ return QMediaFormat::AudioCodec::EAC3;
+
+ if (name == "x-flac"sv)
+ return QMediaFormat::AudioCodec::FLAC;
+
+ if (name == "x-alac"sv)
+ return QMediaFormat::AudioCodec::ALAC;
+
+ if (name == "x-true-hd"sv)
+ return QMediaFormat::AudioCodec::DolbyTrueHD;
+
+ if (name == "x-vorbis"sv)
+ return QMediaFormat::AudioCodec::Vorbis;
+
+ if (name == "x-opus"sv)
+ return QMediaFormat::AudioCodec::Opus;
+
+ if (name == "x-wav"sv)
+ return QMediaFormat::AudioCodec::Wave;
+
+ if (name == "x-wma"sv)
+ return QMediaFormat::AudioCodec::WMA;
+
+ return QMediaFormat::AudioCodec::Unspecified;
+}
+
+QMediaFormat::VideoCodec QGstreamerFormatInfo::videoCodecForCaps(QGstStructureView structure)
+{
+ using namespace std::string_view_literals;
+ const char *name = structure.name().data();
+
+ if (!name || (strncmp(name, "video/", 6) != 0))
+ return QMediaFormat::VideoCodec::Unspecified;
+ name += 6;
+
+ if (name == "mpeg"sv) {
+ auto version = structure["mpegversion"].toInt();
+ if (version == 1)
+ return QMediaFormat::VideoCodec::MPEG1;
+ if (version == 2)
+ return QMediaFormat::VideoCodec::MPEG2;
+ if (version == 4)
+ return QMediaFormat::VideoCodec::MPEG4;
+ return QMediaFormat::VideoCodec::Unspecified;
+ }
+ if (name == "x-h264"sv)
+ return QMediaFormat::VideoCodec::H264;
+
+#if GST_CHECK_VERSION(1, 17, 0) // x265enc seems to be broken on 1.16 at least
+ if (name == "x-h265"sv)
+ return QMediaFormat::VideoCodec::H265;
+#endif
+
+ if (name == "x-vp8"sv)
+ return QMediaFormat::VideoCodec::VP8;
+
+ if (name == "x-vp9"sv)
+ return QMediaFormat::VideoCodec::VP9;
+
+ if (name == "x-av1"sv)
+ return QMediaFormat::VideoCodec::AV1;
+
+ if (name == "x-theora"sv)
+ return QMediaFormat::VideoCodec::Theora;
+
+ if (name == "x-jpeg"sv)
+ return QMediaFormat::VideoCodec::MotionJPEG;
+
+ if (name == "x-wmv"sv)
+ return QMediaFormat::VideoCodec::WMV;
+
+ return QMediaFormat::VideoCodec::Unspecified;
+}
+
+QMediaFormat::FileFormat QGstreamerFormatInfo::fileFormatForCaps(QGstStructureView structure)
+{
+ using namespace std::string_view_literals;
+ const char *name = structure.name().data();
+
+ if (name == "video/x-ms-asf"sv)
+ return QMediaFormat::FileFormat::WMV;
+
+ if (name == "video/x-msvideo"sv)
+ return QMediaFormat::FileFormat::AVI;
+
+ if (name == "video/x-matroska"sv)
+ return QMediaFormat::FileFormat::Matroska;
+
+ if (name == "video/quicktime"sv) {
+ const char *variant = structure["variant"].toString();
+ if (!variant)
+ return QMediaFormat::FileFormat::QuickTime;
+ if (variant == "iso"sv)
+ return QMediaFormat::FileFormat::MPEG4;
+ }
+ if (name == "video/ogg"sv)
+ return QMediaFormat::FileFormat::Ogg;
+
+ if (name == "video/webm"sv)
+ return QMediaFormat::FileFormat::WebM;
+
+ if (name == "audio/x-m4a"sv)
+ return QMediaFormat::FileFormat::Mpeg4Audio;
+
+ if (name == "audio/x-wav"sv)
+ return QMediaFormat::FileFormat::Wave;
+
+ if (name == "audio/mpeg"sv) {
+ auto mpegversion = structure["mpegversion"].toInt();
+ if (mpegversion == 1) {
+ auto layer = structure["layer"];
+ if (!layer.isNull())
+ return QMediaFormat::FileFormat::MP3;
+ }
+ }
+
+ return QMediaFormat::UnspecifiedFormat;
+}
+
+
+QImageCapture::FileFormat QGstreamerFormatInfo::imageFormatForCaps(QGstStructureView structure)
+{
+ using namespace std::string_view_literals;
+ const char *name = structure.name().data();
+
+ if (name == "image/jpeg"sv)
+ return QImageCapture::JPEG;
+
+ if (name == "image/png"sv)
+ return QImageCapture::PNG;
+
+ if (name == "image/webp"sv)
+ return QImageCapture::WebP;
+
+ if (name == "image/tiff"sv)
+ return QImageCapture::Tiff;
+
+ return QImageCapture::UnspecifiedFormat;
+}
+
+static QPair<QList<QMediaFormat::AudioCodec>, QList<QMediaFormat::VideoCodec>> getCodecsList(bool decode)
+{
+ QList<QMediaFormat::AudioCodec> audio;
+ QList<QMediaFormat::VideoCodec> video;
+
+ GstPadDirection padDirection = decode ? GST_PAD_SINK : GST_PAD_SRC;
+
+ GList *elementList = gst_element_factory_list_get_elements(decode ? GST_ELEMENT_FACTORY_TYPE_DECODER : GST_ELEMENT_FACTORY_TYPE_ENCODER,
+ GST_RANK_MARGINAL);
+
+ for (GstElementFactory *factory :
+ QGstUtils::GListRangeAdaptor<GstElementFactory *>(elementList)) {
+ for (GstStaticPadTemplate *padTemplate :
+ QGstUtils::GListRangeAdaptor<GstStaticPadTemplate *>(
+ gst_element_factory_get_static_pad_templates(factory))) {
+ if (padTemplate->direction == padDirection) {
+ auto caps = QGstCaps(gst_static_caps_get(&padTemplate->static_caps), QGstCaps::HasRef);
+
+ for (int i = 0; i < caps.size(); i++) {
+ QGstStructureView structure = caps.at(i);
+ auto a = QGstreamerFormatInfo::audioCodecForCaps(structure);
+ if (a != QMediaFormat::AudioCodec::Unspecified && !audio.contains(a))
+ audio.append(a);
+ auto v = QGstreamerFormatInfo::videoCodecForCaps(structure);
+ if (v != QMediaFormat::VideoCodec::Unspecified && !video.contains(v))
+ video.append(v);
+ }
+ }
+ }
+ }
+ gst_plugin_feature_list_free(elementList);
+ return {audio, video};
+}
+
+
+QList<QGstreamerFormatInfo::CodecMap> QGstreamerFormatInfo::getMuxerList(bool demuxer,
+ QList<QMediaFormat::AudioCodec> supportedAudioCodecs,
+ QList<QMediaFormat::VideoCodec> supportedVideoCodecs)
+{
+ QList<QGstreamerFormatInfo::CodecMap> muxers;
+
+ GstPadDirection padDirection = demuxer ? GST_PAD_SINK : GST_PAD_SRC;
+
+ GList *elementList = gst_element_factory_list_get_elements(
+ demuxer ? GST_ELEMENT_FACTORY_TYPE_DEMUXER : GST_ELEMENT_FACTORY_TYPE_MUXER,
+ GST_RANK_MARGINAL);
+
+ for (GstElementFactory *factory :
+ QGstUtils::GListRangeAdaptor<GstElementFactory *>(elementList)) {
+ QList<QMediaFormat::FileFormat> fileFormats;
+
+ for (GstStaticPadTemplate *padTemplate :
+ QGstUtils::GListRangeAdaptor<GstStaticPadTemplate *>(
+ gst_element_factory_get_static_pad_templates(factory))) {
+
+ if (padTemplate->direction == padDirection) {
+ auto caps = QGstCaps(gst_static_caps_get(&padTemplate->static_caps), QGstCaps::HasRef);
+
+ for (int i = 0; i < caps.size(); i++) {
+ QGstStructureView structure = caps.at(i);
+ auto fmt = fileFormatForCaps(structure);
+ if (fmt != QMediaFormat::UnspecifiedFormat)
+ fileFormats.append(fmt);
+ }
+ }
+ }
+ if (fileFormats.isEmpty())
+ continue;
+
+ QList<QMediaFormat::AudioCodec> audioCodecs;
+ QList<QMediaFormat::VideoCodec> videoCodecs;
+
+ for (GstStaticPadTemplate *padTemplate :
+ QGstUtils::GListRangeAdaptor<GstStaticPadTemplate *>(
+ gst_element_factory_get_static_pad_templates(factory))) {
+
+ // check the other side for supported inputs/outputs
+ if (padTemplate->direction != padDirection) {
+ auto caps = QGstCaps(gst_static_caps_get(&padTemplate->static_caps), QGstCaps::HasRef);
+
+ bool acceptsRawAudio = false;
+ for (int i = 0; i < caps.size(); i++) {
+ QGstStructureView structure = caps.at(i);
+ if (structure.name() == "audio/x-raw")
+ acceptsRawAudio = true;
+ auto audio = audioCodecForCaps(structure);
+ if (audio != QMediaFormat::AudioCodec::Unspecified && supportedAudioCodecs.contains(audio))
+ audioCodecs.append(audio);
+ auto video = videoCodecForCaps(structure);
+ if (video != QMediaFormat::VideoCodec::Unspecified && supportedVideoCodecs.contains(video))
+ videoCodecs.append(video);
+ }
+ if (acceptsRawAudio && fileFormats.size() == 1) {
+ switch (fileFormats.at(0)) {
+ case QMediaFormat::Mpeg4Audio:
+ default:
+ break;
+ case QMediaFormat::MP3:
+ audioCodecs.append(QMediaFormat::AudioCodec::MP3);
+ break;
+ case QMediaFormat::FLAC:
+ audioCodecs.append(QMediaFormat::AudioCodec::FLAC);
+ break;
+ case QMediaFormat::Wave:
+ audioCodecs.append(QMediaFormat::AudioCodec::Wave);
+ break;
+ }
+ }
+ }
+ }
+ if (!audioCodecs.isEmpty() || !videoCodecs.isEmpty()) {
+ for (auto f : std::as_const(fileFormats)) {
+ muxers.append({f, audioCodecs, videoCodecs});
+ if (f == QMediaFormat::MPEG4 && !fileFormats.contains(QMediaFormat::Mpeg4Audio)) {
+ muxers.append({QMediaFormat::Mpeg4Audio, audioCodecs, {}});
+ if (audioCodecs.contains(QMediaFormat::AudioCodec::AAC))
+ muxers.append({QMediaFormat::AAC, { QMediaFormat::AudioCodec::AAC }, {}});
+ } else if (f == QMediaFormat::WMV && !fileFormats.contains(QMediaFormat::WMA)) {
+ muxers.append({QMediaFormat::WMA, audioCodecs, {}});
+ }
+ }
+ }
+ }
+ gst_plugin_feature_list_free(elementList);
+ return muxers;
+}
+
+static QList<QImageCapture::FileFormat> getImageFormatList()
+{
+ QSet<QImageCapture::FileFormat> formats;
+
+ GList *elementList = gst_element_factory_list_get_elements(GST_ELEMENT_FACTORY_TYPE_ENCODER,
+ GST_RANK_MARGINAL);
+
+ for (GstElementFactory *factory :
+ QGstUtils::GListRangeAdaptor<GstElementFactory *>(elementList)) {
+
+ for (GstStaticPadTemplate *padTemplate :
+ QGstUtils::GListRangeAdaptor<GstStaticPadTemplate *>(
+ gst_element_factory_get_static_pad_templates(factory))) {
+ if (padTemplate->direction == GST_PAD_SRC) {
+ QGstCaps caps = QGstCaps(gst_static_caps_get(&padTemplate->static_caps), QGstCaps::HasRef);
+
+ for (int i = 0; i < caps.size(); i++) {
+ QGstStructureView structure = caps.at(i);
+ auto f = QGstreamerFormatInfo::imageFormatForCaps(structure);
+ if (f != QImageCapture::UnspecifiedFormat) {
+// qDebug() << structure.toString() << f;
+ formats.insert(f);
+ }
+ }
+ }
+ }
+ }
+ gst_plugin_feature_list_free(elementList);
+ return formats.values();
+}
+
+#if 0
+static void dumpAudioCodecs(const QList<QMediaFormat::AudioCodec> &codecList)
+{
+ qDebug() << "Audio codecs:";
+ for (const auto &c : codecList)
+ qDebug() << " " << QMediaFormat::audioCodecName(c);
+}
+
+static void dumpVideoCodecs(const QList<QMediaFormat::VideoCodec> &codecList)
+{
+ qDebug() << "Video codecs:";
+ for (const auto &c : codecList)
+ qDebug() << " " << QMediaFormat::videoCodecName(c);
+}
+
+static void dumpMuxers(const QList<QPlatformMediaFormatInfo::CodecMap> &muxerList)
+{
+ for (const auto &m : muxerList) {
+ qDebug() << " " << QMediaFormat::fileFormatName(m.format);
+ qDebug() << " Audio";
+ for (const auto &a : m.audio)
+ qDebug() << " " << QMediaFormat::audioCodecName(a);
+ qDebug() << " Video";
+ for (const auto &v : m.video)
+ qDebug() << " " << QMediaFormat::videoCodecName(v);
+ }
+
+}
+#endif
+
+QGstreamerFormatInfo::QGstreamerFormatInfo()
+{
+ auto codecs = getCodecsList(/*decode = */ true);
+ decoders = getMuxerList(true, codecs.first, codecs.second);
+
+ codecs = getCodecsList(/*decode = */ false);
+ encoders = getMuxerList(/* demuxer = */false, codecs.first, codecs.second);
+// dumpAudioCodecs(codecs.first);
+// dumpVideoCodecs(codecs.second);
+// dumpMuxers(encoders);
+
+ imageFormats = getImageFormatList();
+}
+
+QGstreamerFormatInfo::~QGstreamerFormatInfo() = default;
+
+QGstCaps QGstreamerFormatInfo::formatCaps(const QMediaFormat &f) const
+{
+ auto format = f.fileFormat();
+ Q_ASSERT(format != QMediaFormat::UnspecifiedFormat);
+
+ const char *capsForFormat[QMediaFormat::LastFileFormat + 1] = {
+ "video/x-ms-asf", // WMV
+ "video/x-msvideo", // AVI
+ "video/x-matroska", // Matroska
+ "video/quicktime, variant=(string)iso", // MPEG4
+ "video/ogg", // Ogg
+ "video/quicktime", // QuickTime
+ "video/webm", // WebM
+ "video/quicktime, variant=(string)iso", // Mpeg4Audio is the same is mp4...
+ "video/quicktime, variant=(string)iso", // AAC is also an MP4 container
+ "video/x-ms-asf", // WMA, same as WMV
+ "audio/mpeg, mpegversion=(int)1, layer=(int)3", // MP3
+ "audio/x-flac", // FLAC
+ "audio/x-wav" // Wave
+ };
+ return QGstCaps(gst_caps_from_string(capsForFormat[format]), QGstCaps::HasRef);
+}
+
+QGstCaps QGstreamerFormatInfo::audioCaps(const QMediaFormat &f) const
+{
+ auto codec = f.audioCodec();
+ if (codec == QMediaFormat::AudioCodec::Unspecified)
+ return {};
+
+ const char *capsForCodec[(int)QMediaFormat::AudioCodec::LastAudioCodec + 1] = {
+ "audio/mpeg, mpegversion=(int)1, layer=(int)3", // MP3
+ "audio/mpeg, mpegversion=(int)4", // AAC
+ "audio/x-ac3", // AC3
+ "audio/x-eac3", // EAC3
+ "audio/x-flac", // FLAC
+ "audio/x-true-hd", // DolbyTrueHD
+ "audio/x-opus", // Opus
+ "audio/x-vorbis", // Vorbis
+ "audio/x-raw", // WAVE
+ "audio/x-wma", // WMA
+ "audio/x-alac", // ALAC
+ };
+ return QGstCaps(gst_caps_from_string(capsForCodec[(int)codec]), QGstCaps::HasRef);
+}
+
+QGstCaps QGstreamerFormatInfo::videoCaps(const QMediaFormat &f) const
+{
+ auto codec = f.videoCodec();
+ if (codec == QMediaFormat::VideoCodec::Unspecified)
+ return {};
+
+ const char *capsForCodec[(int)QMediaFormat::VideoCodec::LastVideoCodec + 1] = {
+ "video/mpeg, mpegversion=(int)1", // MPEG1,
+ "video/mpeg, mpegversion=(int)2", // MPEG2,
+ "video/mpeg, mpegversion=(int)4", // MPEG4,
+ "video/x-h264", // H264,
+ "video/x-h265", // H265,
+ "video/x-vp8", // VP8,
+ "video/x-vp9", // VP9,
+ "video/x-av1", // AV1,
+ "video/x-theora", // Theora,
+ "audio/x-wmv", // WMV
+ "video/x-jpeg", // MotionJPEG,
+ };
+ return QGstCaps(gst_caps_from_string(capsForCodec[(int)codec]), QGstCaps::HasRef);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/qgstreamerformatinfo_p.h b/src/plugins/multimedia/gstreamer/qgstreamerformatinfo_p.h
new file mode 100644
index 000000000..bba10edb9
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/qgstreamerformatinfo_p.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERFORMATINFO_H
+#define QGSTREAMERFORMATINFO_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaformatinfo_p.h>
+#include <qlist.h>
+#include <common/qgst_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerFormatInfo : public QPlatformMediaFormatInfo
+{
+public:
+ QGstreamerFormatInfo();
+ ~QGstreamerFormatInfo();
+
+ QGstCaps formatCaps(const QMediaFormat &f) const;
+ QGstCaps audioCaps(const QMediaFormat &f) const;
+ QGstCaps videoCaps(const QMediaFormat &f) const;
+
+ static QMediaFormat::AudioCodec audioCodecForCaps(QGstStructureView structure);
+ static QMediaFormat::VideoCodec videoCodecForCaps(QGstStructureView structure);
+ static QMediaFormat::FileFormat fileFormatForCaps(QGstStructureView structure);
+ static QImageCapture::FileFormat imageFormatForCaps(QGstStructureView structure);
+
+ QList<CodecMap> getMuxerList(bool demuxer, QList<QMediaFormat::AudioCodec> audioCodecs, QList<QMediaFormat::VideoCodec> videoCodecs);
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/qgstreamerintegration.cpp b/src/plugins/multimedia/gstreamer/qgstreamerintegration.cpp
new file mode 100644
index 000000000..87c514f2e
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/qgstreamerintegration.cpp
@@ -0,0 +1,242 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <qgstreamerintegration_p.h>
+#include <qgstreamerformatinfo_p.h>
+#include <qgstreamervideodevices_p.h>
+#include <audio/qgstreameraudiodevice_p.h>
+#include <audio/qgstreameraudiodecoder_p.h>
+#include <common/qgstreameraudioinput_p.h>
+#include <common/qgstreameraudiooutput_p.h>
+#include <common/qgstreamermediaplayer_p.h>
+#include <common/qgstreamervideosink_p.h>
+#include <mediacapture/qgstreamercamera_p.h>
+#include <mediacapture/qgstreamerimagecapture_p.h>
+#include <mediacapture/qgstreamermediacapture_p.h>
+#include <mediacapture/qgstreamermediaencoder_p.h>
+
+#include <QtCore/qloggingcategory.h>
+#include <QtMultimedia/private/qmediaplayer_p.h>
+#include <QtMultimedia/private/qmediacapturesession_p.h>
+#include <QtMultimedia/private/qcameradevice_p.h>
+
+QT_BEGIN_NAMESPACE
+
+static thread_local bool inCustomCameraConstruction = false;
+static thread_local QGstElement pendingCameraElement{};
+
+QGStreamerPlatformSpecificInterfaceImplementation::
+ ~QGStreamerPlatformSpecificInterfaceImplementation() = default;
+
+QAudioDevice QGStreamerPlatformSpecificInterfaceImplementation::makeCustomGStreamerAudioInput(
+ const QByteArray &gstreamerPipeline)
+{
+ return qMakeCustomGStreamerAudioInput(gstreamerPipeline);
+}
+
+QAudioDevice QGStreamerPlatformSpecificInterfaceImplementation::makeCustomGStreamerAudioOutput(
+ const QByteArray &gstreamerPipeline)
+{
+ return qMakeCustomGStreamerAudioOutput(gstreamerPipeline);
+}
+
+QCamera *QGStreamerPlatformSpecificInterfaceImplementation::makeCustomGStreamerCamera(
+ const QByteArray &gstreamerPipeline, QObject *parent)
+{
+ QCameraDevicePrivate *info = new QCameraDevicePrivate;
+ info->id = gstreamerPipeline;
+ QCameraDevice device = info->create();
+
+ inCustomCameraConstruction = true;
+ auto guard = qScopeGuard([] {
+ inCustomCameraConstruction = false;
+ });
+
+ return new QCamera(device, parent);
+}
+
+QCamera *
+QGStreamerPlatformSpecificInterfaceImplementation::makeCustomGStreamerCamera(GstElement *element,
+ QObject *parent)
+{
+ QCameraDevicePrivate *info = new QCameraDevicePrivate;
+ info->id = "Custom Camera from GstElement";
+ QCameraDevice device = info->create();
+
+ pendingCameraElement = QGstElement{
+ element,
+ QGstElement::NeedsRef,
+ };
+
+ inCustomCameraConstruction = true;
+ auto guard = qScopeGuard([] {
+ inCustomCameraConstruction = false;
+ Q_ASSERT(!pendingCameraElement);
+ });
+
+ return new QCamera(device, parent);
+}
+
+GstPipeline *QGStreamerPlatformSpecificInterfaceImplementation::gstPipeline(QMediaPlayer *player)
+{
+ auto *priv = reinterpret_cast<QMediaPlayerPrivate *>(QMediaPlayerPrivate::get(player));
+ if (!priv)
+ return nullptr;
+
+ QGstreamerMediaPlayer *gstreamerPlayer = dynamic_cast<QGstreamerMediaPlayer *>(priv->control);
+ return gstreamerPlayer ? gstreamerPlayer->pipeline().pipeline() : nullptr;
+}
+
+GstPipeline *
+QGStreamerPlatformSpecificInterfaceImplementation::gstPipeline(QMediaCaptureSession *session)
+{
+ auto *priv = QMediaCaptureSessionPrivate::get(session);
+ if (!priv)
+ return nullptr;
+
+ QGstreamerMediaCapture *gstreamerCapture =
+ dynamic_cast<QGstreamerMediaCapture *>(priv->captureSession.get());
+ return gstreamerCapture ? gstreamerCapture->pipeline().pipeline() : nullptr;
+}
+
+Q_LOGGING_CATEGORY(lcGstreamer, "qt.multimedia.gstreamer")
+
+namespace {
+
+void rankDownPlugin(GstRegistry *reg, const char *name)
+{
+ QGstPluginFeatureHandle pluginFeature{
+ gst_registry_lookup_feature(reg, name),
+ QGstPluginFeatureHandle::HasRef,
+ };
+ if (pluginFeature)
+ gst_plugin_feature_set_rank(pluginFeature.get(), GST_RANK_PRIMARY - 1);
+}
+
+// https://gstreamer.freedesktop.org/documentation/vaapi/index.html
+constexpr auto vaapiPluginNames = {
+ "vaapidecodebin", "vaapih264dec", "vaapih264enc", "vaapih265dec",
+ "vaapijpegdec", "vaapijpegenc", "vaapimpeg2dec", "vaapipostproc",
+ "vaapisink", "vaapivp8dec", "vaapivp9dec",
+};
+
+// https://gstreamer.freedesktop.org/documentation/va/index.html
+constexpr auto vaPluginNames = {
+ "vaav1dec", "vacompositor", "vadeinterlace", "vah264dec", "vah264enc", "vah265dec",
+ "vajpegdec", "vampeg2dec", "vapostproc", "vavp8dec", "vavp9dec",
+};
+
+// https://gstreamer.freedesktop.org/documentation/nvcodec/index.html
+constexpr auto nvcodecPluginNames = {
+ "cudaconvert", "cudaconvertscale", "cudadownload", "cudaipcsink", "cudaipcsrc",
+ "cudascale", "cudaupload", "nvautogpuh264enc", "nvautogpuh265enc", "nvav1dec",
+ "nvcudah264enc", "nvcudah265enc", "nvd3d11h264enc", "nvd3d11h265enc", "nvh264dec",
+ "nvh264enc", "nvh265dec", "nvh265enc", "nvjpegdec", "nvjpegenc",
+ "nvmpeg2videodec", "nvmpeg4videodec", "nvmpegvideodec", "nvvp8dec", "nvvp9dec",
+};
+
+} // namespace
+
+QGstreamerIntegration::QGstreamerIntegration()
+ : QPlatformMediaIntegration(QLatin1String("gstreamer"))
+{
+ gst_init(nullptr, nullptr);
+ qCDebug(lcGstreamer) << "Using gstreamer version: " << gst_version_string();
+
+ GstRegistry *reg = gst_registry_get();
+
+ if constexpr (!GST_CHECK_VERSION(1, 22, 0)) {
+ GstRegistry* reg = gst_registry_get();
+ for (const char *name : vaapiPluginNames)
+ rankDownPlugin(reg, name);
+ }
+
+ if (qEnvironmentVariableIsSet("QT_GSTREAMER_DISABLE_VA")) {
+ for (const char *name : vaPluginNames)
+ rankDownPlugin(reg, name);
+ }
+
+ if (qEnvironmentVariableIsSet("QT_GSTREAMER_DISABLE_NVCODEC")) {
+ for (const char *name : nvcodecPluginNames)
+ rankDownPlugin(reg, name);
+ }
+}
+
+QPlatformMediaFormatInfo *QGstreamerIntegration::createFormatInfo()
+{
+ return new QGstreamerFormatInfo();
+}
+
+QPlatformVideoDevices *QGstreamerIntegration::createVideoDevices()
+{
+ return new QGstreamerVideoDevices(this);
+}
+
+const QGstreamerFormatInfo *QGstreamerIntegration::gstFormatsInfo()
+{
+ return static_cast<const QGstreamerFormatInfo *>(formatInfo());
+}
+
+QMaybe<QPlatformAudioDecoder *> QGstreamerIntegration::createAudioDecoder(QAudioDecoder *decoder)
+{
+ return QGstreamerAudioDecoder::create(decoder);
+}
+
+QMaybe<QPlatformMediaCaptureSession *> QGstreamerIntegration::createCaptureSession()
+{
+ return QGstreamerMediaCapture::create();
+}
+
+QMaybe<QPlatformMediaPlayer *> QGstreamerIntegration::createPlayer(QMediaPlayer *player)
+{
+ return QGstreamerMediaPlayer::create(player);
+}
+
+QMaybe<QPlatformCamera *> QGstreamerIntegration::createCamera(QCamera *camera)
+{
+ if (inCustomCameraConstruction) {
+ QGstElement element = std::exchange(pendingCameraElement, {});
+ return element ? new QGstreamerCustomCamera{ camera, std::move(element) }
+ : new QGstreamerCustomCamera{ camera };
+ }
+
+ return QGstreamerCamera::create(camera);
+}
+
+QMaybe<QPlatformMediaRecorder *> QGstreamerIntegration::createRecorder(QMediaRecorder *recorder)
+{
+ return new QGstreamerMediaEncoder(recorder);
+}
+
+QMaybe<QPlatformImageCapture *> QGstreamerIntegration::createImageCapture(QImageCapture *imageCapture)
+{
+ return QGstreamerImageCapture::create(imageCapture);
+}
+
+QMaybe<QPlatformVideoSink *> QGstreamerIntegration::createVideoSink(QVideoSink *sink)
+{
+ return new QGstreamerVideoSink(sink);
+}
+
+QMaybe<QPlatformAudioInput *> QGstreamerIntegration::createAudioInput(QAudioInput *q)
+{
+ return QGstreamerAudioInput::create(q);
+}
+
+QMaybe<QPlatformAudioOutput *> QGstreamerIntegration::createAudioOutput(QAudioOutput *q)
+{
+ return QGstreamerAudioOutput::create(q);
+}
+
+GstDevice *QGstreamerIntegration::videoDevice(const QByteArray &id)
+{
+ const auto devices = videoDevices();
+ return devices ? static_cast<QGstreamerVideoDevices *>(devices)->videoDevice(id) : nullptr;
+}
+
+QAbstractPlatformSpecificInterface *QGstreamerIntegration::platformSpecificInterface()
+{
+ return &m_platformSpecificImplementation;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/qgstreamerintegration_p.h b/src/plugins/multimedia/gstreamer/qgstreamerintegration_p.h
new file mode 100644
index 000000000..229bbd48e
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/qgstreamerintegration_p.h
@@ -0,0 +1,79 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERINTEGRATION_H
+#define QGSTREAMERINTEGRATION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/private/qplatformmediaintegration_p.h>
+#include <QtMultimedia/private/qgstreamer_platformspecificinterface_p.h>
+
+#include <gst/gst.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerFormatInfo;
+
+class QGStreamerPlatformSpecificInterfaceImplementation : public QGStreamerPlatformSpecificInterface
+{
+public:
+ ~QGStreamerPlatformSpecificInterfaceImplementation() override;
+
+ QAudioDevice makeCustomGStreamerAudioInput(const QByteArray &gstreamerPipeline) override;
+ QAudioDevice makeCustomGStreamerAudioOutput(const QByteArray &gstreamerPipeline) override;
+ QCamera *makeCustomGStreamerCamera(const QByteArray &gstreamerPipeline,
+ QObject *parent) override;
+
+ QCamera *makeCustomGStreamerCamera(GstElement *, QObject *parent) override;
+
+ GstPipeline *gstPipeline(QMediaPlayer *) override;
+ GstPipeline *gstPipeline(QMediaCaptureSession *) override;
+};
+
+class QGstreamerIntegration : public QPlatformMediaIntegration
+{
+public:
+ QGstreamerIntegration();
+
+ static QGstreamerIntegration *instance()
+ {
+ return static_cast<QGstreamerIntegration *>(QPlatformMediaIntegration::instance());
+ }
+
+ QMaybe<QPlatformAudioDecoder *> createAudioDecoder(QAudioDecoder *decoder) override;
+ QMaybe<QPlatformMediaCaptureSession *> createCaptureSession() override;
+ QMaybe<QPlatformMediaPlayer *> createPlayer(QMediaPlayer *player) override;
+ QMaybe<QPlatformCamera *> createCamera(QCamera *) override;
+ QMaybe<QPlatformMediaRecorder *> createRecorder(QMediaRecorder *) override;
+ QMaybe<QPlatformImageCapture *> createImageCapture(QImageCapture *) override;
+
+ QMaybe<QPlatformVideoSink *> createVideoSink(QVideoSink *sink) override;
+
+ QMaybe<QPlatformAudioInput *> createAudioInput(QAudioInput *) override;
+ QMaybe<QPlatformAudioOutput *> createAudioOutput(QAudioOutput *) override;
+
+ const QGstreamerFormatInfo *gstFormatsInfo();
+ GstDevice *videoDevice(const QByteArray &id);
+
+ QAbstractPlatformSpecificInterface *platformSpecificInterface() override;
+
+protected:
+ QPlatformMediaFormatInfo *createFormatInfo() override;
+ QPlatformVideoDevices *createVideoDevices() override;
+
+ QGStreamerPlatformSpecificInterfaceImplementation m_platformSpecificImplementation;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/gstreamer/qgstreamerplugin.cpp b/src/plugins/multimedia/gstreamer/qgstreamerplugin.cpp
new file mode 100644
index 000000000..66ad7f712
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/qgstreamerplugin.cpp
@@ -0,0 +1,28 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QtMultimedia/private/qplatformmediaplugin_p.h>
+
+#include <qgstreamerintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerMediaPlugin : public QPlatformMediaPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QPlatformMediaPlugin_iid FILE "gstreamer.json")
+
+public:
+ QGstreamerMediaPlugin() = default;
+
+ QPlatformMediaIntegration* create(const QString &name) override
+ {
+ if (name == u"gstreamer")
+ return new QGstreamerIntegration;
+ return nullptr;
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "qgstreamerplugin.moc"
diff --git a/src/plugins/multimedia/gstreamer/qgstreamervideodevices.cpp b/src/plugins/multimedia/gstreamer/qgstreamervideodevices.cpp
new file mode 100644
index 000000000..78ac16eb4
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/qgstreamervideodevices.cpp
@@ -0,0 +1,158 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qgstreamervideodevices_p.h"
+#include <QtMultimedia/qmediadevices.h>
+#include <QtMultimedia/private/qcameradevice_p.h>
+
+#include <common/qgst_p.h>
+#include <common/qgstutils_p.h>
+#include <common/qglist_helper_p.h>
+
+QT_BEGIN_NAMESPACE
+
+static gboolean deviceMonitorCallback(GstBus *, GstMessage *message, gpointer m)
+{
+ auto *manager = static_cast<QGstreamerVideoDevices *>(m);
+ QGstDeviceHandle device;
+
+ switch (GST_MESSAGE_TYPE(message)) {
+ case GST_MESSAGE_DEVICE_ADDED:
+ gst_message_parse_device_added(message, &device);
+ manager->addDevice(std::move(device));
+ break;
+ case GST_MESSAGE_DEVICE_REMOVED:
+ gst_message_parse_device_removed(message, &device);
+ manager->removeDevice(std::move(device));
+ break;
+ default:
+ break;
+ }
+
+ return G_SOURCE_CONTINUE;
+}
+
+QGstreamerVideoDevices::QGstreamerVideoDevices(QPlatformMediaIntegration *integration)
+ : QPlatformVideoDevices(integration),
+ m_deviceMonitor{
+ gst_device_monitor_new(),
+ }
+{
+ gst_device_monitor_add_filter(m_deviceMonitor.get(), "Video/Source", nullptr);
+
+ QGstBusHandle bus{
+ gst_device_monitor_get_bus(m_deviceMonitor.get()),
+ };
+ gst_bus_add_watch(bus.get(), deviceMonitorCallback, this);
+ gst_device_monitor_start(m_deviceMonitor.get());
+
+ GList *devices = gst_device_monitor_get_devices(m_deviceMonitor.get());
+
+ for (GstDevice *device : QGstUtils::GListRangeAdaptor<GstDevice *>(devices)) {
+ addDevice(QGstDeviceHandle{
+ device,
+ QGstDeviceHandle::HasRef,
+ });
+ }
+
+ g_list_free(devices);
+}
+
+QGstreamerVideoDevices::~QGstreamerVideoDevices()
+{
+ gst_device_monitor_stop(m_deviceMonitor.get());
+}
+
+QList<QCameraDevice> QGstreamerVideoDevices::videoDevices() const
+{
+ QList<QCameraDevice> devices;
+
+ for (const auto &device : m_videoSources) {
+ QCameraDevicePrivate *info = new QCameraDevicePrivate;
+
+ QGString desc{
+ gst_device_get_display_name(device.gstDevice.get()),
+ };
+ info->description = desc.toQString();
+ info->id = device.id;
+
+ QUniqueGstStructureHandle properties{
+ gst_device_get_properties(device.gstDevice.get()),
+ };
+ if (properties) {
+ QGstStructureView view{ properties };
+ auto def = view["is-default"].toBool();
+ info->isDefault = def && *def;
+ }
+
+ if (info->isDefault)
+ devices.prepend(info->create());
+ else
+ devices.append(info->create());
+
+ auto caps = QGstCaps(gst_device_get_caps(device.gstDevice.get()), QGstCaps::HasRef);
+ if (!caps.isNull()) {
+ QList<QCameraFormat> formats;
+ QSet<QSize> photoResolutions;
+
+ int size = caps.size();
+ for (int i = 0; i < size; ++i) {
+ auto cap = caps.at(i);
+
+ QSize resolution = cap.resolution();
+ if (!resolution.isValid())
+ continue;
+
+ auto pixelFormat = cap.pixelFormat();
+ auto frameRate = cap.frameRateRange();
+
+ auto *f = new QCameraFormatPrivate{ QSharedData(), pixelFormat, resolution,
+ frameRate.min, frameRate.max };
+ formats << f->create();
+ photoResolutions.insert(resolution);
+ }
+ info->videoFormats = formats;
+ // ### sort resolutions?
+ info->photoResolutions = photoResolutions.values();
+ }
+ }
+ return devices;
+}
+
+void QGstreamerVideoDevices::addDevice(QGstDeviceHandle device)
+{
+ Q_ASSERT(gst_device_has_classes(device.get(), "Video/Source"));
+
+ auto it = std::find_if(m_videoSources.begin(), m_videoSources.end(),
+ [&](const QGstRecordDevice &a) { return a.gstDevice == device; });
+
+ if (it != m_videoSources.end())
+ return;
+
+ m_videoSources.push_back(QGstRecordDevice{
+ std::move(device),
+ QByteArray::number(m_idGenerator),
+ });
+ emit videoInputsChanged();
+ m_idGenerator++;
+}
+
+void QGstreamerVideoDevices::removeDevice(QGstDeviceHandle device)
+{
+ auto it = std::find_if(m_videoSources.begin(), m_videoSources.end(),
+ [&](const QGstRecordDevice &a) { return a.gstDevice == device; });
+
+ if (it != m_videoSources.end()) {
+ m_videoSources.erase(it);
+ emit videoInputsChanged();
+ }
+}
+
+GstDevice *QGstreamerVideoDevices::videoDevice(const QByteArray &id) const
+{
+ auto it = std::find_if(m_videoSources.begin(), m_videoSources.end(),
+ [&](const QGstRecordDevice &a) { return a.id == id; });
+ return it != m_videoSources.end() ? it->gstDevice.get() : nullptr;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/gstreamer/qgstreamervideodevices_p.h b/src/plugins/multimedia/gstreamer/qgstreamervideodevices_p.h
new file mode 100644
index 000000000..a321ae66b
--- /dev/null
+++ b/src/plugins/multimedia/gstreamer/qgstreamervideodevices_p.h
@@ -0,0 +1,54 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGSTREAMERMEDIADEVICES_H
+#define QGSTREAMERMEDIADEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformvideodevices_p.h>
+#include <gst/gst.h>
+#include <qaudiodevice.h>
+#include <vector>
+
+#include <common/qgst_handle_types_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerVideoDevices : public QPlatformVideoDevices
+{
+public:
+ explicit QGstreamerVideoDevices(QPlatformMediaIntegration *integration);
+ ~QGstreamerVideoDevices();
+
+ QList<QCameraDevice> videoDevices() const override;
+ GstDevice *videoDevice(const QByteArray &id) const;
+
+ void addDevice(QGstDeviceHandle);
+ void removeDevice(QGstDeviceHandle);
+
+private:
+ struct QGstRecordDevice
+ {
+ QGstDeviceHandle gstDevice;
+ QByteArray id;
+ };
+
+ quint64 m_idGenerator = 0;
+ std::vector<QGstRecordDevice> m_videoSources;
+
+ QGstDeviceMonitorHandle m_deviceMonitor;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/CMakeLists.txt b/src/plugins/multimedia/qnx/CMakeLists.txt
new file mode 100644
index 000000000..e1ac0ffa3
--- /dev/null
+++ b/src/plugins/multimedia/qnx/CMakeLists.txt
@@ -0,0 +1,39 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+
+qt_internal_add_plugin(QQnxMediaPlugin
+ OUTPUT_NAME qnxmediaplugin
+ PLUGIN_TYPE multimedia
+ SOURCES
+ camera/qqnxcamera.cpp camera/qqnxcamera_p.h
+ camera/qqnxplatformcamera.cpp camera/qqnxplatformcamera_p.h
+ camera/qqnxcameraframebuffer.cpp camera/qqnxcameraframebuffer_p.h
+ camera/qqnximagecapture.cpp camera/qqnximagecapture_p.h
+ common/qqnxaudioinput.cpp common/qqnxaudioinput_p.h
+ common/qqnxaudiooutput.cpp common/qqnxaudiooutput_p.h
+ common/qqnxmediaeventthread.cpp common/qqnxmediaeventthread_p.h
+ common/qqnxwindowgrabber.cpp common/qqnxwindowgrabber_p.h
+ capture/qqnxaudiorecorder.cpp capture/qqnxaudiorecorder_p.h
+ capture/qqnxmediacapturesession.cpp capture/qqnxmediacapturesession_p.h
+ capture/qqnxmediarecorder.cpp capture/qqnxmediarecorder_p.h
+ mediaplayer/qqnxmediaplayer.cpp mediaplayer/qqnxmediaplayer_p.h
+ mediaplayer/qqnxmediametadata.cpp mediaplayer/qqnxmediametadata_p.h
+ mediaplayer/qqnxvideosink.cpp mediaplayer/qqnxvideosink_p.h
+ mediaplayer/qqnxmediautil.cpp mediaplayer/qqnxmediautil_p.h
+ qqnxformatinfo.cpp qqnxformatinfo_p.h
+ qqnxmediaintegration.cpp qqnxmediaintegration_p.h
+ qqnxvideodevices.cpp qqnxvideodevices_p.h
+ INCLUDE_DIRECTORIES
+ audio
+ camera
+ capture
+ common
+ mediaplayer
+ LIBRARIES
+ Qt::MultimediaPrivate
+ Qt::CorePrivate
+ MMRenderer::MMRenderer
+ strm
+ camapi
+)
diff --git a/src/plugins/multimedia/qnx/camera/qqnxcamera.cpp b/src/plugins/multimedia/qnx/camera/qqnxcamera.cpp
new file mode 100644
index 000000000..6976221bd
--- /dev/null
+++ b/src/plugins/multimedia/qnx/camera/qqnxcamera.cpp
@@ -0,0 +1,820 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qqnxcamera_p.h"
+#include "qqnxcameraframebuffer_p.h"
+#include "qqnxmediacapturesession_p.h"
+#include "qqnxvideosink_p.h"
+
+#include <qcameradevice.h>
+#include <qmediadevices.h>
+
+#include <private/qmediastoragelocation_p.h>
+
+QDebug &operator<<(QDebug &d, const QQnxCamera::VideoFormat &f)
+{
+ d << "VideoFormat - width=" << f.width
+ << "height=" << f.height
+ << "rotation=" << f.rotation
+ << "frameRate=" << f.frameRate
+ << "frameType=" << f.frameType;
+
+ return d;
+}
+
+static QString statusToString(camera_devstatus_t status)
+{
+ switch (status) {
+ case CAMERA_STATUS_DISCONNECTED:
+ return QStringLiteral("No user is connected to the camera");
+ case CAMERA_STATUS_POWERDOWN:
+ return QStringLiteral("Power down");
+ case CAMERA_STATUS_VIDEOVF:
+ return QStringLiteral("The video viewfinder has started");
+ case CAMERA_STATUS_CAPTURE_ABORTED:
+ return QStringLiteral("The capture of a still image failed and was aborted");
+ case CAMERA_STATUS_FILESIZE_WARNING:
+ return QStringLiteral("Time-remaining threshold has been exceeded");
+ case CAMERA_STATUS_FOCUS_CHANGE:
+ return QStringLiteral("The focus has changed on the camera");
+ case CAMERA_STATUS_RESOURCENOTAVAIL:
+ return QStringLiteral("The camera is about to free resources");
+ case CAMERA_STATUS_VIEWFINDER_ERROR:
+ return QStringLiteral(" An unexpected error was encountered while the "
+ "viewfinder was active");
+ case CAMERA_STATUS_MM_ERROR:
+ return QStringLiteral("The recording has stopped due to a memory error or multimedia "
+ "framework error");
+ case CAMERA_STATUS_FILESIZE_ERROR:
+ return QStringLiteral("A file has exceeded the maximum size.");
+ case CAMERA_STATUS_NOSPACE_ERROR:
+ return QStringLiteral("Not enough disk space");
+ case CAMERA_STATUS_BUFFER_UNDERFLOW:
+ return QStringLiteral("The viewfinder is out of buffers");
+ default:
+ break;
+ }
+
+ return {};
+}
+
+QT_BEGIN_NAMESPACE
+
+QQnxCamera::QQnxCamera(camera_unit_t unit, QObject *parent)
+ : QObject(parent)
+ , m_cameraUnit(unit)
+{
+ if (!m_handle.open(m_cameraUnit, CAMERA_MODE_RW))
+ qWarning("QQnxCamera: Failed to open camera (0x%x)", m_handle.lastError());
+
+ if (camera_set_vf_mode(m_handle.get(), CAMERA_VFMODE_VIDEO) != CAMERA_EOK) {
+ qWarning("QQnxCamera: unable to configure viewfinder mode");
+ return;
+ }
+
+ if (camera_set_vf_property(m_handle.get(), CAMERA_IMGPROP_CREATEWINDOW, 0,
+ CAMERA_IMGPROP_RENDERTOWINDOW, 0) != CAMERA_EOK) {
+ qWarning("QQnxCamera: failed to set camera properties");
+ return;
+ }
+
+ updateZoomLimits();
+ updateSupportedWhiteBalanceValues();
+
+ m_valid = true;
+}
+
+QQnxCamera::~QQnxCamera()
+{
+ stop();
+}
+
+camera_unit_t QQnxCamera::unit() const
+{
+ return m_cameraUnit;
+}
+
+QString QQnxCamera::name() const
+{
+ char name[CAMERA_LOCATION_NAMELEN];
+
+ if (camera_get_location_property(m_cameraUnit,
+ CAMERA_LOCATION_NAME, &name, CAMERA_LOCATION_END) != CAMERA_EOK) {
+ qWarning("QQnxCamera: unable to obtain camera name");
+ return {};
+ }
+
+ return QString::fromUtf8(name);
+}
+
+bool QQnxCamera::isValid() const
+{
+ return m_valid;
+}
+
+bool QQnxCamera::isActive() const
+{
+ return m_handle.isOpen() && m_viewfinderActive;
+}
+
+void QQnxCamera::start()
+{
+ if (isActive())
+ return;
+
+ if (camera_start_viewfinder(m_handle.get(), viewfinderCallback,
+ statusCallback, this) != CAMERA_EOK) {
+ qWarning("QQnxCamera: unable to start viewfinder");
+ return;
+ }
+
+ m_viewfinderActive = true;
+}
+
+void QQnxCamera::stop()
+{
+ if (!isActive())
+ return;
+
+ if (m_recordingVideo)
+ stopVideoRecording();
+
+ if (camera_stop_viewfinder(m_handle.get()) != CAMERA_EOK)
+ qWarning("QQnxCamera: Failed to stop camera");
+
+ m_viewfinderActive = false;
+}
+
+bool QQnxCamera::setCameraFormat(uint32_t width, uint32_t height, double frameRate)
+{
+ if (!m_handle.isOpen())
+ return false;
+
+ const camera_error_t error = camera_set_vf_property(m_handle.get(),
+ CAMERA_IMGPROP_WIDTH, width,
+ CAMERA_IMGPROP_HEIGHT, height,
+ CAMERA_IMGPROP_FRAMERATE, frameRate);
+
+ if (error != CAMERA_EOK) {
+ qWarning("QQnxCamera: failed to set camera format");
+ return false;
+ }
+
+ return true;
+}
+
+bool QQnxCamera::isFocusModeSupported(camera_focusmode_t mode) const
+{
+ return supportedFocusModes().contains(mode);
+}
+
+bool QQnxCamera::setFocusMode(camera_focusmode_t mode)
+{
+ if (!isActive())
+ return false;
+
+ const camera_error_t result = camera_set_focus_mode(m_handle.get(), mode);
+
+ if (result != CAMERA_EOK) {
+ qWarning("QQnxCamera: Unable to set focus mode (0x%x)", result);
+ return false;
+ }
+
+ focusModeChanged(mode);
+
+ return true;
+}
+
+camera_focusmode_t QQnxCamera::focusMode() const
+{
+ if (!isActive())
+ return CAMERA_FOCUSMODE_OFF;
+
+ camera_focusmode_t mode;
+
+ const camera_error_t result = camera_get_focus_mode(m_handle.get(), &mode);
+
+ if (result != CAMERA_EOK) {
+ qWarning("QQnxCamera: Unable to set focus mode (0x%x)", result);
+ return CAMERA_FOCUSMODE_OFF;
+ }
+
+ return mode;
+}
+
+QQnxCamera::VideoFormat QQnxCamera::vfFormat() const
+{
+ VideoFormat f = {};
+
+ if (camera_get_vf_property(m_handle.get(),
+ CAMERA_IMGPROP_WIDTH, &f.width,
+ CAMERA_IMGPROP_HEIGHT, &f.height,
+ CAMERA_IMGPROP_ROTATION, &f.rotation,
+ CAMERA_IMGPROP_FRAMERATE, &f.frameRate,
+ CAMERA_IMGPROP_FORMAT, &f.frameType) != CAMERA_EOK) {
+ qWarning("QQnxCamera: Failed to query video finder frameType");
+ }
+
+ return f;
+}
+
+void QQnxCamera::setVfFormat(const VideoFormat &f)
+{
+ const bool active = isActive();
+
+ if (active)
+ stop();
+
+ if (camera_set_vf_property(m_handle.get(),
+ CAMERA_IMGPROP_WIDTH, f.width,
+ CAMERA_IMGPROP_HEIGHT, f.height,
+ CAMERA_IMGPROP_ROTATION, f.rotation,
+ CAMERA_IMGPROP_FRAMERATE, f.frameRate,
+ CAMERA_IMGPROP_FORMAT, f.frameType) != CAMERA_EOK) {
+ qWarning("QQnxCamera: Failed to set video finder frameType");
+ }
+
+ if (active)
+ start();
+}
+
+QQnxCamera::VideoFormat QQnxCamera::recordingFormat() const
+{
+ VideoFormat f = {};
+
+ if (camera_get_video_property(m_handle.get(),
+ CAMERA_IMGPROP_WIDTH, &f.width,
+ CAMERA_IMGPROP_HEIGHT, &f.height,
+ CAMERA_IMGPROP_ROTATION, &f.rotation,
+ CAMERA_IMGPROP_FRAMERATE, &f.frameRate,
+ CAMERA_IMGPROP_FORMAT, &f.frameType) != CAMERA_EOK) {
+ qWarning("QQnxCamera: Failed to query recording frameType");
+ }
+
+ return f;
+}
+
+void QQnxCamera::setRecordingFormat(const VideoFormat &f)
+{
+ if (camera_set_video_property(m_handle.get(),
+ CAMERA_IMGPROP_WIDTH, f.width,
+ CAMERA_IMGPROP_HEIGHT, f.height,
+ CAMERA_IMGPROP_ROTATION, f.rotation,
+ CAMERA_IMGPROP_FRAMERATE, f.frameRate,
+ CAMERA_IMGPROP_FORMAT, f.frameType) != CAMERA_EOK) {
+ qWarning("QQnxCamera: Failed to set recording frameType");
+ }
+}
+
+void QQnxCamera::setCustomFocusPoint(const QPointF &point)
+{
+ const QSize vfSize = viewFinderSize();
+
+ if (vfSize.isEmpty())
+ return;
+
+ const auto toUint32 = [](double value) {
+ return static_cast<uint32_t>(std::max(0.0, value));
+ };
+
+ // define a 40x40 pixel focus region around the custom focus point
+ constexpr int pixelSize = 40;
+
+ const auto left = toUint32(point.x() * vfSize.width() - pixelSize / 2);
+ const auto top = toUint32(point.y() * vfSize.height() - pixelSize / 2);
+
+ camera_region_t focusRegion {
+ .left = left,
+ .top = top,
+ .width = pixelSize,
+ .height = pixelSize,
+ .extra = 0
+ };
+
+ if (camera_set_focus_regions(m_handle.get(), 1, &focusRegion) != CAMERA_EOK) {
+ qWarning("QQnxCamera: Unable to set focus region");
+ return;
+ }
+
+ if (setFocusMode(focusMode()))
+ customFocusPointChanged(point);
+}
+
+void QQnxCamera::setManualFocusStep(int step)
+{
+ if (!isActive()) {
+ qWarning("QQnxCamera: Failed to set focus distance - view finder not active");
+ return;
+ }
+
+ if (!isFocusModeSupported(CAMERA_FOCUSMODE_MANUAL)) {
+ qWarning("QQnxCamera: Failed to set focus distance - manual focus mode not supported");
+ return;
+ }
+
+ if (camera_set_manual_focus_step(m_handle.get(), step) != CAMERA_EOK)
+ qWarning("QQnxCamera: Failed to set focus distance");
+}
+
+int QQnxCamera::manualFocusStep() const
+{
+ return focusStep().step;
+}
+
+int QQnxCamera::maxFocusStep() const
+{
+ return focusStep().maxStep;
+}
+
+QQnxCamera::FocusStep QQnxCamera::focusStep() const
+{
+ constexpr FocusStep invalidStep { -1, -1 };
+
+ if (!isActive()) {
+ qWarning("QQnxCamera: Failed to query max focus distance - view finder not active");
+ return invalidStep;
+ }
+
+ if (!isFocusModeSupported(CAMERA_FOCUSMODE_MANUAL)) {
+ qWarning("QQnxCamera: Failed to query max focus distance - "
+ "manual focus mode not supported");
+ return invalidStep;
+ }
+
+ FocusStep focusStep;
+
+ if (camera_get_manual_focus_step(m_handle.get(),
+ &focusStep.maxStep, &focusStep.step) != CAMERA_EOK) {
+ qWarning("QQnxCamera: Unable to query camera focus step");
+ return invalidStep;
+ }
+
+ return focusStep;
+}
+
+
+QSize QQnxCamera::viewFinderSize() const
+{
+ // get the size of the viewfinder
+ int width = 0;
+ int height = 0;
+
+ if (camera_get_vf_property(m_handle.get(),
+ CAMERA_IMGPROP_WIDTH, width,
+ CAMERA_IMGPROP_HEIGHT, height) != CAMERA_EOK) {
+ qWarning("QQnxCamera: failed to query view finder size");
+ return {};
+ }
+
+ return { width, height };
+}
+
+uint32_t QQnxCamera::minimumZoomLevel() const
+{
+ return m_minZoom;
+}
+
+uint32_t QQnxCamera::maximumZoomLevel() const
+{
+ return m_maxZoom;
+}
+
+bool QQnxCamera::isSmoothZoom() const
+{
+ return m_smoothZoom;
+}
+
+double QQnxCamera::zoomRatio(uint32_t zoomLevel) const
+{
+ double ratio;
+
+ if (camera_get_zoom_ratio_from_zoom_level(m_handle.get(), zoomLevel, &ratio) != CAMERA_EOK) {
+ qWarning("QQnxCamera: failed to query zoom ratio from zoom level");
+ return 0.0;
+ }
+
+ return ratio;
+}
+
+bool QQnxCamera::setZoomFactor(uint32_t factor)
+{
+ if (camera_set_vf_property(m_handle.get(), CAMERA_IMGPROP_ZOOMFACTOR, factor) != CAMERA_EOK) {
+ qWarning("QQnxCamera: failed to set zoom factor");
+ return false;
+ }
+
+ return true;
+}
+
+void QQnxCamera::setEvOffset(float ev)
+{
+ if (!isActive())
+ return;
+
+ if (camera_set_ev_offset(m_handle.get(), ev) != CAMERA_EOK)
+ qWarning("QQnxCamera: Failed to set up exposure compensation");
+}
+
+uint32_t QQnxCamera::manualIsoSensitivity() const
+{
+ if (!isActive())
+ return 0;
+
+ uint32_t isoValue;
+
+ if (camera_get_manual_iso(m_handle.get(), &isoValue) != CAMERA_EOK) {
+ qWarning("QQnxCamera: Failed to query ISO value");
+ return 0;
+ }
+
+ return isoValue;
+}
+
+void QQnxCamera::setManualIsoSensitivity(uint32_t value)
+{
+ if (!isActive())
+ return;
+
+ if (camera_set_manual_iso(m_handle.get(), value) != CAMERA_EOK)
+ qWarning("QQnxCamera: Failed to set ISO value");
+}
+
+void QQnxCamera::setManualExposureTime(double seconds)
+{
+ if (!isActive())
+ return;
+
+ if (camera_set_manual_shutter_speed(m_handle.get(), seconds) != CAMERA_EOK)
+ qWarning("QQnxCamera: Failed to set exposure time");
+}
+
+double QQnxCamera::manualExposureTime() const
+{
+ if (!isActive())
+ return 0.0;
+
+ double shutterSpeed;
+
+ if (camera_get_manual_shutter_speed(m_handle.get(), &shutterSpeed) != CAMERA_EOK) {
+ qWarning("QQnxCamera: Failed to get exposure time");
+ return 0.0;
+ }
+
+ return shutterSpeed;
+}
+
+bool QQnxCamera::hasFeature(camera_feature_t feature) const
+{
+ return camera_has_feature(m_handle.get(), feature);
+}
+
+void QQnxCamera::setWhiteBalanceMode(camera_whitebalancemode_t mode)
+{
+ if (!isActive())
+ return;
+
+ if (camera_set_whitebalance_mode(m_handle.get(), mode) != CAMERA_EOK)
+ qWarning("QQnxCamera: failed to set whitebalance mode");
+}
+
+camera_whitebalancemode_t QQnxCamera::whiteBalanceMode() const
+{
+ if (!isActive())
+ return CAMERA_WHITEBALANCEMODE_OFF;
+
+ camera_whitebalancemode_t mode;
+
+ if (camera_get_whitebalance_mode(m_handle.get(), &mode) != CAMERA_EOK) {
+ qWarning("QQnxCamera: failed to get white balance mode");
+ return CAMERA_WHITEBALANCEMODE_OFF;
+ }
+
+ return mode;
+}
+
+void QQnxCamera::setManualWhiteBalance(uint32_t value)
+{
+ if (!isActive())
+ return;
+
+ if (camera_set_manual_white_balance(m_handle.get(), value) != CAMERA_EOK)
+ qWarning("QQnxCamera: failed to set manual white balance");
+}
+
+uint32_t QQnxCamera::manualWhiteBalance() const
+{
+ if (!isActive())
+ return 0;
+
+ uint32_t value;
+
+ if (camera_get_manual_white_balance(m_handle.get(), &value) != CAMERA_EOK) {
+ qWarning("QQnxCamera: failed to get manual white balance");
+ return 0;
+ }
+
+ return value;
+}
+
+bool QQnxCamera::startVideoRecording(const QString &filename)
+{
+ // when preview is video, we must ensure that the recording properties
+ // match the view finder properties
+ if (hasFeature(CAMERA_FEATURE_PREVIEWISVIDEO)) {
+ VideoFormat newFormat = vfFormat();
+
+ const QList<camera_frametype_t> recordingTypes = supportedRecordingFrameTypes();
+
+ // find a suitable matching frame type in case the current view finder
+ // frametype is not supported
+ if (newFormat.frameType != recordingFormat().frameType
+ && !recordingTypes.contains(newFormat.frameType)) {
+
+ bool found = false;
+
+ for (const camera_frametype_t type : supportedVfFrameTypes()) {
+ if (recordingTypes.contains(type)) {
+ newFormat.frameType = type;
+ found = true;
+ break;
+ }
+ }
+
+ if (found) {
+ m_originalVfFormat = vfFormat();
+
+ // reconfigure and restart the view finder
+ setVfFormat(newFormat);
+ } else {
+ qWarning("QQnxCamera: failed to find suitable frame type for recording - aborting");
+ return false;
+ }
+ }
+
+ setRecordingFormat(newFormat);
+ }
+
+ if (camera_start_video(m_handle.get(), qPrintable(filename),
+ nullptr, nullptr, nullptr) == CAMERA_EOK) {
+ m_recordingVideo = true;
+ } else {
+ qWarning("QQnxCamera: failed to start video encoding");
+ }
+
+ return m_recordingVideo;
+}
+
+void QQnxCamera::stopVideoRecording()
+{
+ m_recordingVideo = false;
+
+ if (camera_stop_video(m_handle.get()) != CAMERA_EOK)
+ qWarning("QQnxCamera: error when stopping video recording");
+
+ // restore original vf format
+ if (m_originalVfFormat) {
+ setVfFormat(*m_originalVfFormat);
+ m_originalVfFormat.reset();
+ }
+}
+
+bool QQnxCamera::isVideoEncodingSupported() const
+{
+ if (!isActive())
+ return false;
+
+ return camera_has_feature(m_handle.get(), CAMERA_FEATURE_VIDEO);
+}
+
+camera_handle_t QQnxCamera::handle() const
+{
+ return m_handle.get();
+}
+
+void QQnxCamera::updateZoomLimits()
+{
+ bool smooth;
+
+ if (camera_get_zoom_limits(m_handle.get(), &m_minZoom, &m_maxZoom, &smooth) != CAMERA_EOK) {
+ qWarning("QQnxCamera: failed to update zoom limits - using default values");
+ m_minZoom = m_maxZoom = 0;
+ }
+}
+
+void QQnxCamera::updateSupportedWhiteBalanceValues()
+{
+ uint32_t numSupported = 0;
+
+ const camera_error_t result = camera_get_supported_manual_white_balance_values(
+ m_handle.get(), 0, &numSupported, nullptr, &m_continuousWhiteBalanceValues);
+
+ if (result != CAMERA_EOK) {
+ if (result == CAMERA_EOPNOTSUPP)
+ qWarning("QQnxCamera: white balance not supported");
+ else
+ qWarning("QQnxCamera: unable to query manual white balance value count");
+
+ m_supportedWhiteBalanceValues.clear();
+
+ return;
+ }
+
+ m_supportedWhiteBalanceValues.resize(numSupported);
+
+ if (camera_get_supported_manual_white_balance_values(m_handle.get(),
+ m_supportedWhiteBalanceValues.size(),
+ &numSupported,
+ m_supportedWhiteBalanceValues.data(),
+ &m_continuousWhiteBalanceValues) != CAMERA_EOK) {
+ qWarning("QQnxCamera: unable to query manual white balance values");
+
+ m_supportedWhiteBalanceValues.clear();
+ }
+}
+
+QList<camera_vfmode_t> QQnxCamera::supportedVfModes() const
+{
+ return queryValues(camera_get_supported_vf_modes);
+}
+
+QList<camera_res_t> QQnxCamera::supportedVfResolutions() const
+{
+ return queryValues(camera_get_supported_vf_resolutions);
+}
+
+QList<camera_frametype_t> QQnxCamera::supportedVfFrameTypes() const
+{
+ return queryValues(camera_get_supported_vf_frame_types);
+}
+
+QList<camera_focusmode_t> QQnxCamera::supportedFocusModes() const
+{
+ return queryValues(camera_get_focus_modes);
+}
+
+QList<double> QQnxCamera::specifiedVfFrameRates(camera_frametype_t frameType,
+ camera_res_t resolution) const
+{
+ uint32_t numSupported = 0;
+
+ if (camera_get_specified_vf_framerates(m_handle.get(), frameType, resolution,
+ 0, &numSupported, nullptr, nullptr) != CAMERA_EOK) {
+ qWarning("QQnxCamera: unable to query specified framerates count");
+ return {};
+ }
+
+ QList<double> values(numSupported);
+
+ if (camera_get_specified_vf_framerates(m_handle.get(), frameType, resolution,
+ values.size(), &numSupported, values.data(), nullptr) != CAMERA_EOK) {
+ qWarning("QQnxCamera: unable to query specified framerates values");
+ return {};
+ }
+
+ return values;
+}
+
+QList<camera_frametype_t> QQnxCamera::supportedRecordingFrameTypes() const
+{
+ return queryValues(camera_get_video_frame_types);
+}
+
+QList<uint32_t> QQnxCamera::supportedWhiteBalanceValues() const
+{
+ return m_supportedWhiteBalanceValues;
+}
+
+bool QQnxCamera::hasContinuousWhiteBalanceValues() const
+{
+ return m_continuousWhiteBalanceValues;
+}
+
+QList<camera_unit_t> QQnxCamera::supportedUnits()
+{
+ unsigned int numSupported = 0;
+
+ if (camera_get_supported_cameras(0, &numSupported, nullptr) != CAMERA_EOK) {
+ qWarning("QQnxCamera: failed to query supported camera unit count");
+ return {};
+ }
+
+ QList<camera_unit_t> cameraUnits(numSupported);
+
+ if (camera_get_supported_cameras(cameraUnits.size(), &numSupported,
+ cameraUnits.data()) != CAMERA_EOK) {
+ qWarning("QQnxCamera: failed to enumerate supported camera units");
+ return {};
+ }
+
+ return cameraUnits;
+}
+
+template <typename T, typename U>
+QList<T> QQnxCamera::queryValues(QueryFuncPtr<T,U> func) const
+{
+ static_assert(std::is_integral_v<U>, "Parameter U must be of integral type");
+
+ U numSupported = 0;
+
+ if (func(m_handle.get(), 0, &numSupported, nullptr) != CAMERA_EOK) {
+ qWarning("QQnxCamera: unable to query camera value count");
+ return {};
+ }
+
+ QList<T> values(numSupported);
+
+ if (func(m_handle.get(), values.size(), &numSupported, values.data()) != CAMERA_EOK) {
+ qWarning("QQnxCamera: unable to query camera values");
+ return {};
+ }
+
+ return values;
+}
+
+void QQnxCamera::handleVfBuffer(camera_buffer_t *buffer)
+{
+ // process the frame on this thread before locking the mutex
+ auto frame = std::make_unique<QQnxCameraFrameBuffer>(buffer);
+
+ // skip a frame if mutex is busy
+ if (m_currentFrameMutex.tryLock()) {
+ m_currentFrame = std::move(frame);
+ m_currentFrameMutex.unlock();
+
+ Q_EMIT frameAvailable();
+ }
+}
+
+void QQnxCamera::handleVfStatus(camera_devstatus_t status, uint16_t extraData)
+{
+ QMetaObject::invokeMethod(this, "handleStatusChange", Qt::QueuedConnection,
+ Q_ARG(camera_devstatus_t, status),
+ Q_ARG(uint16_t, extraData));
+}
+
+void QQnxCamera::handleStatusChange(camera_devstatus_t status, uint16_t extraData)
+{
+ Q_UNUSED(extraData);
+
+ switch (status) {
+ case CAMERA_STATUS_BUFFER_UNDERFLOW:
+ case CAMERA_STATUS_CAPTURECOMPLETE:
+ case CAMERA_STATUS_CAPTURE_ABORTED:
+ case CAMERA_STATUS_CONNECTED:
+ case CAMERA_STATUS_DISCONNECTED:
+ case CAMERA_STATUS_FILESIZE_ERROR:
+ case CAMERA_STATUS_FILESIZE_LIMIT_WARNING:
+ case CAMERA_STATUS_FILESIZE_WARNING:
+ case CAMERA_STATUS_FLASH_LEVEL_CHANGE:
+ case CAMERA_STATUS_FOCUS_CHANGE:
+ case CAMERA_STATUS_FRAME_DROPPED:
+ case CAMERA_STATUS_LOWLIGHT:
+ case CAMERA_STATUS_MM_ERROR:
+ case CAMERA_STATUS_NOSPACE_ERROR:
+ case CAMERA_STATUS_PHOTOVF:
+ case CAMERA_STATUS_POWERDOWN:
+ case CAMERA_STATUS_POWERUP:
+ case CAMERA_STATUS_RESOURCENOTAVAIL:
+ case CAMERA_STATUS_UNKNOWN:
+ case CAMERA_STATUS_VIDEOLIGHT_CHANGE:
+ case CAMERA_STATUS_VIDEOLIGHT_LEVEL_CHANGE:
+ case CAMERA_STATUS_VIDEOVF:
+ case CAMERA_STATUS_VIDEO_PAUSE:
+ case CAMERA_STATUS_VIDEO_RESUME:
+ case CAMERA_STATUS_VIEWFINDER_ACTIVE:
+ case CAMERA_STATUS_VIEWFINDER_ERROR:
+ case CAMERA_STATUS_VIEWFINDER_FREEZE:
+ case CAMERA_STATUS_VIEWFINDER_SUSPEND:
+ case CAMERA_STATUS_VIEWFINDER_UNFREEZE:
+ case CAMERA_STATUS_VIEWFINDER_UNSUSPEND:
+ qDebug() << "QQnxCamera:" << ::statusToString(status);
+ break;
+ }
+}
+
+std::unique_ptr<QQnxCameraFrameBuffer> QQnxCamera::takeCurrentFrame()
+{
+ QMutexLocker l(&m_currentFrameMutex);
+
+ return std::move(m_currentFrame);
+}
+
+void QQnxCamera::viewfinderCallback(camera_handle_t handle, camera_buffer_t *buffer, void *arg)
+{
+ Q_UNUSED(handle);
+
+ auto *camera = static_cast<QQnxCamera*>(arg);
+ camera->handleVfBuffer(buffer);
+}
+
+void QQnxCamera::statusCallback(camera_handle_t handle, camera_devstatus_t status,
+ uint16_t extraData, void *arg)
+{
+ Q_UNUSED(handle);
+
+ auto *camera = static_cast<QQnxCamera*>(arg);
+ camera->handleVfStatus(status, extraData);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qqnxcamera_p.cpp"
diff --git a/src/plugins/multimedia/qnx/camera/qqnxcamera_p.h b/src/plugins/multimedia/qnx/camera/qqnxcamera_p.h
new file mode 100644
index 000000000..a4ddbfed6
--- /dev/null
+++ b/src/plugins/multimedia/qnx/camera/qqnxcamera_p.h
@@ -0,0 +1,201 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQNXCAMERA_H
+#define QQNXCAMERA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qqnxcamerahandle_p.h"
+
+#include <QtCore/qlist.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qobject.h>
+#include <QtCore/qurl.h>
+
+#include <camera/camera_api.h>
+#include <camera/camera_3a.h>
+
+#include <memory>
+#include <optional>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxCameraFrameBuffer;
+class QQnxMediaCaptureSession;
+class QQnxVideoSink;
+
+class QQnxCamera : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QQnxCamera(camera_unit_t unit, QObject *parent = nullptr);
+ ~QQnxCamera();
+
+ camera_unit_t unit() const;
+
+ QString name() const;
+
+ bool isValid() const;
+
+ bool isActive() const;
+ void start();
+ void stop();
+
+ bool startVideoRecording(const QString &filename);
+ void stopVideoRecording();
+
+ bool setCameraFormat(uint32_t width, uint32_t height, double frameRate);
+
+ bool isFocusModeSupported(camera_focusmode_t mode) const;
+ bool setFocusMode(camera_focusmode_t mode);
+ camera_focusmode_t focusMode() const;
+
+ void setCustomFocusPoint(const QPointF &point);
+
+ void setManualFocusStep(int step);
+ int manualFocusStep() const;
+ int maxFocusStep() const;
+
+ QSize viewFinderSize() const;
+
+ uint32_t minimumZoomLevel() const;
+ uint32_t maximumZoomLevel() const;
+ bool isSmoothZoom() const;
+ double zoomRatio(uint32_t zoomLevel) const;
+ bool setZoomFactor(uint32_t factor);
+
+ void setEvOffset(float ev);
+
+ uint32_t manualIsoSensitivity() const;
+ void setManualIsoSensitivity(uint32_t value);
+ void setManualExposureTime(double seconds);
+ double manualExposureTime() const;
+
+ void setWhiteBalanceMode(camera_whitebalancemode_t mode);
+ camera_whitebalancemode_t whiteBalanceMode() const;
+
+ void setManualWhiteBalance(uint32_t value);
+ uint32_t manualWhiteBalance() const;
+
+ bool hasFeature(camera_feature_t feature) const;
+
+ camera_handle_t handle() const;
+
+ QList<camera_vfmode_t> supportedVfModes() const;
+ QList<camera_res_t> supportedVfResolutions() const;
+ QList<camera_frametype_t> supportedVfFrameTypes() const;
+ QList<camera_focusmode_t> supportedFocusModes() const;
+ QList<double> specifiedVfFrameRates(camera_frametype_t frameType,
+ camera_res_t resolution) const;
+
+ QList<camera_frametype_t> supportedRecordingFrameTypes() const;
+
+ QList<uint32_t> supportedWhiteBalanceValues() const;
+
+ bool hasContinuousWhiteBalanceValues() const;
+
+ static QList<camera_unit_t> supportedUnits();
+
+ std::unique_ptr<QQnxCameraFrameBuffer> takeCurrentFrame();
+
+Q_SIGNALS:
+ void focusModeChanged(camera_focusmode_t mode);
+ void customFocusPointChanged(const QPointF &point);
+ void minimumZoomFactorChanged(double factor);
+
+ double maximumZoomFactorChanged(double factor);
+
+ void frameAvailable();
+
+private:
+ struct FocusStep
+ {
+ int step; // current step
+ int maxStep; // max supported step
+ };
+
+ FocusStep focusStep() const;
+
+ struct VideoFormat
+ {
+ uint32_t width;
+ uint32_t height;
+ uint32_t rotation;
+ double frameRate;
+ camera_frametype_t frameType;
+ };
+
+ friend QDebug &operator<<(QDebug&, const VideoFormat&);
+
+ VideoFormat vfFormat() const;
+ void setVfFormat(const VideoFormat &format);
+
+ VideoFormat recordingFormat() const;
+ void setRecordingFormat(const VideoFormat &format);
+
+ void updateZoomLimits();
+ void updateSupportedWhiteBalanceValues();
+ void setColorTemperatureInternal(unsigned temp);
+
+ bool isVideoEncodingSupported() const;
+
+ void handleVfBuffer(camera_buffer_t *buffer);
+
+ // viewfinder callback
+ void handleVfStatus(camera_devstatus_t status, uint16_t extraData);
+
+ // our handler running on main thread
+ Q_INVOKABLE void handleStatusChange(camera_devstatus_t status, uint16_t extraData);
+
+ template <typename T, typename U>
+ using QueryFuncPtr = camera_error_t (*)(camera_handle_t, U, U *, T *);
+
+ template <typename T, typename U>
+ QList<T> queryValues(QueryFuncPtr<T, U> func) const;
+
+ static void viewfinderCallback(camera_handle_t handle,
+ camera_buffer_t *buffer, void *arg);
+
+ static void statusCallback(camera_handle_t handle, camera_devstatus_t status,
+ uint16_t extraData, void *arg);
+
+ QQnxMediaCaptureSession *m_session = nullptr;
+
+ camera_unit_t m_cameraUnit = CAMERA_UNIT_NONE;
+
+ QQnxCameraHandle m_handle;
+
+ uint32_t m_minZoom = 0;
+ uint32_t m_maxZoom = 0;
+
+ QMutex m_currentFrameMutex;
+
+ QList<uint32_t> m_supportedWhiteBalanceValues;
+
+ std::unique_ptr<QQnxCameraFrameBuffer> m_currentFrame;
+
+ std::optional<VideoFormat> m_originalVfFormat;
+
+ bool m_viewfinderActive = false;
+ bool m_recordingVideo = false;
+ bool m_valid = false;
+ bool m_smoothZoom = false;
+ bool m_continuousWhiteBalanceValues = false;
+};
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(camera_devstatus_t)
+Q_DECLARE_METATYPE(uint16_t)
+
+#endif
diff --git a/src/plugins/multimedia/qnx/camera/qqnxcameraframebuffer.cpp b/src/plugins/multimedia/qnx/camera/qqnxcameraframebuffer.cpp
new file mode 100644
index 000000000..6595c5d42
--- /dev/null
+++ b/src/plugins/multimedia/qnx/camera/qqnxcameraframebuffer.cpp
@@ -0,0 +1,299 @@
+// Copyright (C) 2022 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxcameraframebuffer_p.h"
+
+#include <limits>
+
+template <typename T>
+static constexpr int toInt(T value)
+{
+ if constexpr (sizeof(T) >= sizeof(int)) {
+ if (std::is_signed_v<T>) {
+ return static_cast<int>(std::clamp<T>(value,
+ std::numeric_limits<int>::min(), std::numeric_limits<int>::max()));
+ } else {
+ return static_cast<int>(std::min<T>(value, std::numeric_limits<int>::max()));
+ }
+ } else {
+ return static_cast<int>(value);
+ }
+}
+
+template <typename T>
+static constexpr QSize frameSize(const T &frame)
+{
+ return { toInt(frame.width), toInt(frame.height) };
+}
+
+static constexpr QVideoFrameFormat::PixelFormat frameTypeToPixelFormat(camera_frametype_t type)
+{
+ switch (type) {
+ case CAMERA_FRAMETYPE_NV12:
+ return QVideoFrameFormat::Format_NV12;
+ case CAMERA_FRAMETYPE_RGB8888:
+ return QVideoFrameFormat::Format_ARGB8888;
+ case CAMERA_FRAMETYPE_GRAY8:
+ return QVideoFrameFormat::Format_Y8;
+ case CAMERA_FRAMETYPE_CBYCRY:
+ return QVideoFrameFormat::Format_UYVY;
+ case CAMERA_FRAMETYPE_YCBCR420P:
+ return QVideoFrameFormat::Format_YUV420P;
+ case CAMERA_FRAMETYPE_YCBYCR:
+ return QVideoFrameFormat::Format_YUYV;
+ default:
+ break;
+ }
+
+ return QVideoFrameFormat::Format_Invalid;
+}
+
+static constexpr size_t bufferDataSize(const camera_frame_nv12_t &frame)
+{
+ return frame.uv_offset + frame.uv_stride * frame.height / 2;
+}
+
+static constexpr size_t bufferDataSize(const camera_frame_rgb8888_t &frame)
+{
+ return frame.stride * frame.height;
+}
+
+static constexpr size_t bufferDataSize(const camera_frame_gray8_t &frame)
+{
+ return frame.stride * frame.height;
+}
+
+static constexpr size_t bufferDataSize(const camera_frame_cbycry_t &frame)
+{
+ return frame.bufsize;
+}
+
+static constexpr size_t bufferDataSize(const camera_frame_ycbcr420p_t &frame)
+{
+ return frame.cr_offset + frame.cr_stride * frame.height / 2;
+}
+
+static constexpr size_t bufferDataSize(const camera_frame_ycbycr_t &frame)
+{
+ return frame.stride * frame.height;
+}
+
+static constexpr size_t bufferDataSize(const camera_buffer_t *buffer)
+{
+ switch (buffer->frametype) {
+ case CAMERA_FRAMETYPE_NV12:
+ return bufferDataSize(buffer->framedesc.nv12);
+ case CAMERA_FRAMETYPE_RGB8888:
+ return bufferDataSize(buffer->framedesc.rgb8888);
+ case CAMERA_FRAMETYPE_GRAY8:
+ return bufferDataSize(buffer->framedesc.gray8);
+ case CAMERA_FRAMETYPE_CBYCRY:
+ return bufferDataSize(buffer->framedesc.cbycry);
+ case CAMERA_FRAMETYPE_YCBCR420P:
+ return bufferDataSize(buffer->framedesc.ycbcr420p);
+ case CAMERA_FRAMETYPE_YCBYCR:
+ return bufferDataSize(buffer->framedesc.ycbycr);
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+static QAbstractVideoBuffer::MapData mapData(const camera_frame_nv12_t &frame,
+ unsigned char *baseAddress)
+{
+
+ return {
+ .planeCount = 2,
+ .bytesPerLine = {
+ toInt(frame.stride),
+ toInt(frame.uv_stride)
+ },
+ .data = {
+ baseAddress,
+ baseAddress + frame.uv_offset
+ },
+ .dataSize = {
+ toInt(frame.stride * frame.height),
+ toInt(frame.uv_stride * frame.height / 2)
+ }
+ };
+}
+
+static QAbstractVideoBuffer::MapData mapData(const camera_frame_rgb8888_t &frame,
+ unsigned char *baseAddress)
+{
+ return {
+ .planeCount = 1,
+ .bytesPerLine = {
+ toInt(frame.stride)
+ },
+ .data = {
+ baseAddress
+ },
+ .dataSize = {
+ toInt(frame.stride * frame.height),
+ }
+ };
+}
+
+static QAbstractVideoBuffer::MapData mapData(const camera_frame_gray8_t &frame,
+ unsigned char *baseAddress)
+{
+ return {
+ .planeCount = 1,
+ .bytesPerLine = {
+ toInt(frame.stride)
+ },
+ .data = {
+ baseAddress
+ },
+ .dataSize = {
+ toInt(frame.stride * frame.height)
+ }
+ };
+}
+
+static QAbstractVideoBuffer::MapData mapData(const camera_frame_cbycry_t &frame,
+ unsigned char *baseAddress)
+{
+ return {
+ .planeCount = 1,
+ .bytesPerLine = {
+ toInt(frame.stride)
+ },
+ .data = {
+ baseAddress
+ },
+ .dataSize = {
+ toInt(frame.bufsize),
+ }
+ };
+}
+
+static QAbstractVideoBuffer::MapData mapData(const camera_frame_ycbcr420p_t &frame,
+ unsigned char *baseAddress)
+{
+ return {
+ .planeCount = 3,
+ .bytesPerLine = {
+ toInt(frame.y_stride),
+ frame.cb_stride,
+ frame.cr_stride,
+ },
+ .data = {
+ baseAddress,
+ baseAddress + frame.cb_offset,
+ baseAddress + frame.cr_offset,
+ },
+ .dataSize = {
+ toInt(frame.y_stride * frame.height),
+ toInt(frame.cb_stride * frame.height / 2),
+ toInt(frame.cr_stride * frame.height / 2)
+ }
+ };
+}
+
+static QAbstractVideoBuffer::MapData mapData(const camera_frame_ycbycr_t &frame,
+ unsigned char *baseAddress)
+{
+ return {
+ .planeCount = 1,
+ .bytesPerLine = {
+ toInt(frame.stride)
+ },
+ .data = {
+ baseAddress
+ },
+ .dataSize = {
+ toInt(frame.stride * frame.height)
+ }
+ };
+}
+
+static QAbstractVideoBuffer::MapData mapData(const camera_buffer_t *buffer,
+ unsigned char *baseAddress)
+{
+ switch (buffer->frametype) {
+ case CAMERA_FRAMETYPE_NV12:
+ return mapData(buffer->framedesc.nv12, baseAddress);
+ case CAMERA_FRAMETYPE_RGB8888:
+ return mapData(buffer->framedesc.rgb8888, baseAddress);
+ case CAMERA_FRAMETYPE_GRAY8:
+ return mapData(buffer->framedesc.gray8, baseAddress);
+ case CAMERA_FRAMETYPE_CBYCRY:
+ return mapData(buffer->framedesc.cbycry, baseAddress);
+ case CAMERA_FRAMETYPE_YCBCR420P:
+ return mapData(buffer->framedesc.ycbcr420p, baseAddress);
+ case CAMERA_FRAMETYPE_YCBYCR:
+ return mapData(buffer->framedesc.ycbycr, baseAddress);
+ default:
+ break;
+ }
+
+ return {};
+}
+
+static constexpr QSize frameSize(const camera_buffer_t *buffer)
+{
+ switch (buffer->frametype) {
+ case CAMERA_FRAMETYPE_NV12:
+ return frameSize(buffer->framedesc.nv12);
+ case CAMERA_FRAMETYPE_RGB8888:
+ return frameSize(buffer->framedesc.rgb8888);
+ case CAMERA_FRAMETYPE_GRAY8:
+ return frameSize(buffer->framedesc.gray8);
+ case CAMERA_FRAMETYPE_CBYCRY:
+ return frameSize(buffer->framedesc.cbycry);
+ case CAMERA_FRAMETYPE_YCBCR420P:
+ return frameSize(buffer->framedesc.ycbcr420p);
+ case CAMERA_FRAMETYPE_YCBYCR:
+ return frameSize(buffer->framedesc.ycbycr);
+ default:
+ break;
+ }
+
+ return {};
+}
+
+QT_BEGIN_NAMESPACE
+
+QQnxCameraFrameBuffer::QQnxCameraFrameBuffer(const camera_buffer_t *buffer, QRhi *rhi)
+ : QHwVideoBuffer(rhi ? QVideoFrame::RhiTextureHandle : QVideoFrame::NoHandle, rhi),
+ m_rhi(rhi),
+ m_pixelFormat(::frameTypeToPixelFormat(buffer->frametype)),
+ m_dataSize(::bufferDataSize(buffer))
+{
+ if (m_dataSize <= 0)
+ return;
+
+ m_data = std::make_unique<unsigned char[]>(m_dataSize);
+
+ memcpy(m_data.get(), buffer->framebuf, m_dataSize);
+
+ m_mapData = ::mapData(buffer, m_data.get());
+
+ m_frameSize = ::frameSize(buffer);
+}
+
+QAbstractVideoBuffer::MapData QQnxCameraFrameBuffer::map(QtVideo::MapMode)
+{
+ return m_mapData;
+}
+
+void QQnxCameraFrameBuffer::unmap()
+{
+}
+
+QVideoFrameFormat::PixelFormat QQnxCameraFrameBuffer::pixelFormat() const
+{
+ return m_pixelFormat;
+}
+
+QSize QQnxCameraFrameBuffer::size() const
+{
+ return m_frameSize;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/qnx/camera/qqnxcameraframebuffer_p.h b/src/plugins/multimedia/qnx/camera/qqnxcameraframebuffer_p.h
new file mode 100644
index 000000000..20f724552
--- /dev/null
+++ b/src/plugins/multimedia/qnx/camera/qqnxcameraframebuffer_p.h
@@ -0,0 +1,60 @@
+// Copyright (C) 2022 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QQNXCAMERAFRAMEBUFFER_H
+#define QQNXCAMERAFRAMEBUFFER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qhwvideobuffer_p.h>
+
+#include <QtCore/qsize.h>
+
+#include <camera/camera_api.h>
+
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+class QRhi;
+
+class QQnxCameraFrameBuffer : public QHwVideoBuffer
+{
+public:
+ explicit QQnxCameraFrameBuffer(const camera_buffer_t *buffer, QRhi *rhi = nullptr);
+
+ QQnxCameraFrameBuffer(const QQnxCameraFrameBuffer&) = delete;
+ QQnxCameraFrameBuffer& operator=(const QQnxCameraFrameBuffer&) = delete;
+
+ MapData map(QtVideo::MapMode mode) override;
+ void unmap() override;
+
+ QVideoFrameFormat::PixelFormat pixelFormat() const;
+
+ QSize size() const;
+
+private:
+ QRhi *m_rhi;
+
+ QVideoFrameFormat::PixelFormat m_pixelFormat;
+
+ std::unique_ptr<unsigned char[]> m_data;
+
+ size_t m_dataSize;
+
+ MapData m_mapData;
+
+ QSize m_frameSize;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/camera/qqnxcamerahandle_p.h b/src/plugins/multimedia/qnx/camera/qqnxcamerahandle_p.h
new file mode 100644
index 000000000..3d7863dc2
--- /dev/null
+++ b/src/plugins/multimedia/qnx/camera/qqnxcamerahandle_p.h
@@ -0,0 +1,102 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QQNXCAMERAHANDLE_P_H
+#define QQNXCAMERAHANDLE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <camera/camera_api.h>
+
+#include <utility>
+
+class QQnxCameraHandle
+{
+public:
+ QQnxCameraHandle() = default;
+
+ explicit QQnxCameraHandle(camera_handle_t h)
+ : m_handle (h) {}
+
+ explicit QQnxCameraHandle(QQnxCameraHandle &&other)
+ : m_handle(other.m_handle)
+ , m_lastError(other.m_lastError)
+ {
+ other = QQnxCameraHandle();
+ }
+
+ QQnxCameraHandle(const QQnxCameraHandle&) = delete;
+
+ QQnxCameraHandle& operator=(QQnxCameraHandle&& other)
+ {
+ m_handle = other.m_handle;
+ m_lastError = other.m_lastError;
+
+ other = QQnxCameraHandle();
+
+ return *this;
+ }
+
+ ~QQnxCameraHandle()
+ {
+ close();
+ }
+
+ bool open(camera_unit_t unit, uint32_t mode)
+ {
+ if (isOpen()) {
+ m_lastError = CAMERA_EALREADY;
+ return false;
+ }
+
+ return cacheError(camera_open, unit, mode, &m_handle);
+ }
+
+ bool close()
+ {
+ if (!isOpen())
+ return true;
+
+ const bool success = cacheError(camera_close, m_handle);
+ m_handle = CAMERA_HANDLE_INVALID;
+
+ return success;
+ }
+
+ camera_handle_t get() const
+ {
+ return m_handle;
+ }
+
+ bool isOpen() const
+ {
+ return m_handle != CAMERA_HANDLE_INVALID;
+ }
+
+ camera_error_t lastError() const
+ {
+ return m_lastError;
+ }
+
+private:
+ template <typename Func, typename ...Args>
+ bool cacheError(Func f, Args &&...args)
+ {
+ m_lastError = f(std::forward<Args>(args)...);
+
+ return m_lastError == CAMERA_EOK;
+ }
+
+ camera_handle_t m_handle = CAMERA_HANDLE_INVALID;
+ camera_error_t m_lastError = CAMERA_EOK;
+};
+
+#endif
diff --git a/src/plugins/multimedia/qnx/camera/qqnximagecapture.cpp b/src/plugins/multimedia/qnx/camera/qqnximagecapture.cpp
new file mode 100644
index 000000000..3983dddbb
--- /dev/null
+++ b/src/plugins/multimedia/qnx/camera/qqnximagecapture.cpp
@@ -0,0 +1,257 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qqnximagecapture_p.h"
+
+#include "qqnxplatformcamera_p.h"
+#include "qqnxmediacapturesession_p.h"
+#include "qqnxcamera_p.h"
+#include "qfile.h"
+
+#include <private/qmediastoragelocation_p.h>
+
+#include <QtCore/qfileinfo.h>
+#include <QtCore/qfuture.h>
+#include <QtCore/qpromise.h>
+#include <QtCore/qthread.h>
+
+#include <camera/camera_api.h>
+
+using namespace Qt::Literals::StringLiterals;
+
+static QString formatExtension(QImageCapture::FileFormat format)
+{
+ switch (format) {
+ case QImageCapture::JPEG:
+ return u"jpg"_s;
+ case QImageCapture::PNG:
+ return u"png"_s;
+ case QImageCapture::WebP:
+ case QImageCapture::Tiff:
+ case QImageCapture::UnspecifiedFormat:
+ break;
+ }
+
+ return {};
+}
+
+static QString resolveFileName(const QString &fileName, QImageCapture::FileFormat format)
+{
+ const QString extension = formatExtension(format);
+
+ if (extension.isEmpty())
+ return {};
+
+ if (fileName.isEmpty()) {
+ return QMediaStorageLocation::generateFileName(QString(),
+ QStandardPaths::PicturesLocation, extension);
+ }
+
+ if (fileName.endsWith(extension))
+ return QFileInfo(fileName).canonicalFilePath();
+
+ QString path = fileName;
+ path.append(u".%1"_s.arg(extension));
+
+ return QFileInfo(path).canonicalFilePath();
+}
+
+QT_BEGIN_NAMESPACE
+
+QQnxImageCapture::QQnxImageCapture(QImageCapture *parent)
+ : QPlatformImageCapture(parent)
+{
+}
+
+bool QQnxImageCapture::isReadyForCapture() const
+{
+ return m_camera && m_camera->isActive();
+}
+
+int QQnxImageCapture::capture(const QString &fileName)
+{
+ if (!isReadyForCapture()) {
+ Q_EMIT error(-1, QImageCapture::NotReadyError, QPlatformImageCapture::msgCameraNotReady());
+ return -1;
+ }
+
+ // default to PNG format if no format has been specified
+ const QImageCapture::FileFormat format =
+ m_settings.format() == QImageCapture::UnspecifiedFormat
+ ? QImageCapture::PNG : m_settings.format();
+
+ const QString resolvedFileName = resolveFileName(fileName, format);
+
+ if (resolvedFileName.isEmpty()) {
+ const QString errorMessage = (u"Invalid file format: %1"_s).arg(
+ QImageCapture::fileFormatName(format));
+
+ Q_EMIT error(-1, QImageCapture::NotSupportedFeatureError, errorMessage);
+ return -1;
+ }
+
+ const int id = m_lastId++;
+
+ auto callback = [this, id, fn=std::move(resolvedFileName)](const QVideoFrame &frame) {
+ saveFrame(id, frame, fn);
+ };
+
+ m_camera->requestVideoFrame(std::move(callback));
+
+ return id;
+}
+
+int QQnxImageCapture::captureToBuffer()
+{
+ if (!isReadyForCapture()) {
+ Q_EMIT error(-1, QImageCapture::NotReadyError, QPlatformImageCapture::msgCameraNotReady());
+ return -1;
+ }
+
+ const int id = m_lastId++;
+
+ auto callback = [this, id](const QVideoFrame &frame) { decodeFrame(id, frame); };
+
+ m_camera->requestVideoFrame(std::move(callback));
+
+ return id;
+}
+
+QFuture<QImage> QQnxImageCapture::decodeFrame(int id, const QVideoFrame &frame)
+{
+ if (!frame.isValid()) {
+ Q_EMIT error(id, QImageCapture::NotReadyError, u"Invalid frame"_s);
+ return {};
+ }
+
+ QPromise<QImage> promise;
+ QFuture<QImage> future = promise.future();
+
+ // converting a QVideoFrame to QImage is an expensive operation
+ // run it on a background thread to prevent it from stalling the UI
+ auto runner = [frame, promise=std::move(promise)]() mutable {
+ promise.start();
+ promise.addResult(frame.toImage());
+ promise.finish();
+ };
+
+ auto *worker = QThread::create(std::move(runner));
+
+ auto onFinished = [this, worker, id, future]() mutable {
+ worker->deleteLater();
+
+ if (future.isValid()) {
+ Q_EMIT imageCaptured(id, future.result());
+ } else {
+ qWarning("QQnxImageCapture: failed to capture image to buffer");
+ }
+ };
+
+ connect(worker, &QThread::finished, this, std::move(onFinished));
+
+ Q_EMIT imageExposed(id);
+
+ worker->start();
+
+ return future;
+}
+
+void QQnxImageCapture::saveFrame(int id, const QVideoFrame &frame, const QString &fileName)
+{
+ QFuture<QImage> decodeFuture = decodeFrame(id, frame);
+
+ if (decodeFuture.isCanceled())
+ return;
+
+ QPromise<bool> promise;
+ QFuture<bool> saveFuture = promise.future();
+
+ // writing a QImage to disk is a _very_ expensive operation
+ // run it on a background thread to prevent it from stalling the UI
+ auto runner = [future=std::move(decodeFuture),
+ promise=std::move(promise), fileName]() mutable {
+ promise.start();
+ promise.addResult(future.result().save(fileName));
+ promise.finish();
+ };
+
+ auto *worker = QThread::create(std::move(runner));
+
+ auto onFinished = [this, worker, id, future=std::move(saveFuture), fn=std::move(fileName)]() {
+ worker->deleteLater();
+
+ if (future.isValid() && future.result())
+ Q_EMIT imageSaved(id, fn);
+ else
+ Q_EMIT error(id, QImageCapture::NotSupportedFeatureError, u"Failed to save image"_s);
+ };
+
+ connect(worker, &QThread::finished, this, std::move(onFinished));
+
+ worker->start();
+}
+
+QImageEncoderSettings QQnxImageCapture::imageSettings() const
+{
+ return m_settings;
+}
+
+void QQnxImageCapture::setImageSettings(const QImageEncoderSettings &settings)
+{
+ m_settings = settings;
+}
+
+void QQnxImageCapture::setCaptureSession(QQnxMediaCaptureSession *captureSession)
+{
+ if (m_session == captureSession)
+ return;
+
+ if (m_session)
+ m_session->disconnect(this);
+
+ m_session = captureSession;
+
+ if (m_session) {
+ connect(m_session, &QQnxMediaCaptureSession::cameraChanged,
+ this, &QQnxImageCapture::onCameraChanged);
+ }
+
+ onCameraChanged();
+}
+
+void QQnxImageCapture::onCameraChanged()
+{
+ if (m_camera)
+ m_camera->disconnect(this);
+
+ m_camera = m_session ? static_cast<QQnxPlatformCamera*>(m_session->camera()) : nullptr;
+
+ if (m_camera) {
+ connect(m_camera, &QQnxPlatformCamera::activeChanged,
+ this, &QQnxImageCapture::onCameraChanged);
+ }
+
+ updateReadyForCapture();
+}
+
+void QQnxImageCapture::onCameraActiveChanged(bool active)
+{
+ Q_UNUSED(active);
+
+ updateReadyForCapture();
+}
+
+void QQnxImageCapture::updateReadyForCapture()
+{
+ const bool readyForCapture = isReadyForCapture();
+
+ if (m_lastReadyForCapture == readyForCapture)
+ return;
+
+ m_lastReadyForCapture = readyForCapture;
+
+ Q_EMIT readyForCaptureChanged(m_lastReadyForCapture);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qqnximagecapture_p.cpp"
diff --git a/src/plugins/multimedia/qnx/camera/qqnximagecapture_p.h b/src/plugins/multimedia/qnx/camera/qqnximagecapture_p.h
new file mode 100644
index 000000000..832039654
--- /dev/null
+++ b/src/plugins/multimedia/qnx/camera/qqnximagecapture_p.h
@@ -0,0 +1,63 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QQnxImageCapture_H
+#define QQnxImageCapture_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformimagecapture_p.h>
+
+#include <QtCore/qfuture.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxMediaCaptureSession;
+class QQnxPlatformCamera;
+
+class QThread;
+
+class QQnxImageCapture : public QPlatformImageCapture
+{
+ Q_OBJECT
+public:
+ explicit QQnxImageCapture(QImageCapture *parent);
+
+ bool isReadyForCapture() const override;
+
+ int capture(const QString &fileName) override;
+ int captureToBuffer() override;
+
+ QImageEncoderSettings imageSettings() const override;
+ void setImageSettings(const QImageEncoderSettings &settings) override;
+
+ void setCaptureSession(QQnxMediaCaptureSession *session);
+
+private:
+ QFuture<QImage> decodeFrame(int id, const QVideoFrame &frame);
+ void saveFrame(int id, const QVideoFrame &frame, const QString &fileName);
+
+ void onCameraChanged();
+ void onCameraActiveChanged(bool active);
+ void updateReadyForCapture();
+
+ QQnxMediaCaptureSession *m_session = nullptr;
+ QQnxPlatformCamera *m_camera = nullptr;
+
+ int m_lastId = 0;
+ QImageEncoderSettings m_settings;
+
+ bool m_lastReadyForCapture = false;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/camera/qqnxplatformcamera.cpp b/src/plugins/multimedia/qnx/camera/qqnxplatformcamera.cpp
new file mode 100644
index 000000000..b604f4561
--- /dev/null
+++ b/src/plugins/multimedia/qnx/camera/qqnxplatformcamera.cpp
@@ -0,0 +1,426 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#undef QT_NO_CONTEXTLESS_CONNECT // Remove after porting connect() calls
+
+#include "qqnxplatformcamera_p.h"
+#include "qqnxcameraframebuffer_p.h"
+#include "qqnxmediacapturesession_p.h"
+#include "qqnxvideosink_p.h"
+
+#include <qcameradevice.h>
+#include <qmediadevices.h>
+
+#include <private/qmediastoragelocation_p.h>
+#include <private/qvideoframe_p.h>
+
+#include <camera/camera_api.h>
+#include <camera/camera_3a.h>
+
+#include <algorithm>
+#include <array>
+
+#include <dlfcn.h>
+
+struct FocusModeMapping
+{
+ QCamera::FocusMode qt;
+ camera_focusmode_t qnx;
+};
+
+constexpr std::array<FocusModeMapping, 6> focusModes {{
+ { QCamera::FocusModeAuto, CAMERA_FOCUSMODE_CONTINUOUS_AUTO },
+ { QCamera::FocusModeAutoFar, CAMERA_FOCUSMODE_CONTINUOUS_AUTO },
+ { QCamera::FocusModeInfinity, CAMERA_FOCUSMODE_CONTINUOUS_AUTO },
+ { QCamera::FocusModeAutoNear, CAMERA_FOCUSMODE_CONTINUOUS_MACRO },
+ { QCamera::FocusModeHyperfocal, CAMERA_FOCUSMODE_EDOF },
+ { QCamera::FocusModeManual, CAMERA_FOCUSMODE_MANUAL },
+}};
+
+template <typename Mapping, typename From, typename To, size_t N>
+static constexpr To convert(const std::array<Mapping, N> &mapping,
+ From Mapping::* from, To Mapping::* to, From value, To defaultValue)
+{
+ for (const Mapping &m : mapping) {
+ const auto fromValue = m.*from;
+ const auto toValue = m.*to;
+
+ if (value == fromValue)
+ return toValue;
+ }
+
+ return defaultValue;
+}
+
+static constexpr camera_focusmode_t qnxFocusMode(QCamera::FocusMode mode)
+{
+ return convert(focusModes, &FocusModeMapping::qt,
+ &FocusModeMapping::qnx, mode, CAMERA_FOCUSMODE_CONTINUOUS_AUTO);
+}
+
+static constexpr QCamera::FocusMode qtFocusMode(camera_focusmode_t mode)
+{
+ return convert(focusModes, &FocusModeMapping::qnx,
+ &FocusModeMapping::qt, mode, QCamera::FocusModeAuto);
+}
+
+QT_BEGIN_NAMESPACE
+
+QQnxPlatformCamera::QQnxPlatformCamera(QCamera *parent)
+ : QPlatformCamera(parent)
+{
+ if (parent)
+ setCamera(parent->cameraDevice());
+ else
+ setCamera(QMediaDevices::defaultVideoInput());
+}
+
+QQnxPlatformCamera::~QQnxPlatformCamera()
+{
+ stop();
+}
+
+bool QQnxPlatformCamera::isActive() const
+{
+ return m_qnxCamera && m_qnxCamera->isActive();
+}
+
+void QQnxPlatformCamera::setActive(bool active)
+{
+ if (active)
+ start();
+ else
+ stop();
+}
+
+void QQnxPlatformCamera::start()
+{
+ if (!m_qnxCamera || isActive())
+ return;
+
+ if (m_session)
+ m_videoSink = m_session->videoSink();
+
+ m_qnxCamera->start();
+
+ Q_EMIT activeChanged(true);
+}
+
+void QQnxPlatformCamera::stop()
+{
+ if (!m_qnxCamera)
+ return;
+
+ m_qnxCamera->stop();
+
+ m_videoSink = nullptr;
+
+ Q_EMIT activeChanged(false);
+}
+
+void QQnxPlatformCamera::setCamera(const QCameraDevice &camera)
+{
+ if (m_cameraDevice == camera)
+ return;
+
+ const auto cameraUnit = static_cast<camera_unit_t>(camera.id().toUInt());
+
+ m_qnxCamera = std::make_unique<QQnxCamera>(cameraUnit);
+
+ connect(m_qnxCamera.get(), &QQnxCamera::focusModeChanged,
+ [this](camera_focusmode_t mode) { Q_EMIT focusModeChanged(qtFocusMode(mode)); });
+ connect(m_qnxCamera.get(), &QQnxCamera::customFocusPointChanged,
+ this, &QQnxPlatformCamera::customFocusPointChanged);
+ connect(m_qnxCamera.get(), &QQnxCamera::frameAvailable,
+ this, &QQnxPlatformCamera::onFrameAvailable, Qt::QueuedConnection);
+
+ m_cameraDevice = camera;
+
+ updateCameraFeatures();
+}
+
+bool QQnxPlatformCamera::setCameraFormat(const QCameraFormat &format)
+{
+ const QSize resolution = format.resolution();
+
+ if (resolution.isEmpty()) {
+ qWarning("QQnxPlatformCamera: invalid resolution requested");
+ return false;
+ }
+
+ return m_qnxCamera->setCameraFormat(resolution.width(),
+ resolution.height(), format.maxFrameRate());
+}
+
+void QQnxPlatformCamera::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ if (m_session == session)
+ return;
+
+ m_session = static_cast<QQnxMediaCaptureSession *>(session);
+}
+
+bool QQnxPlatformCamera::isFocusModeSupported(QCamera::FocusMode mode) const
+{
+ if (!m_qnxCamera)
+ return false;
+
+ return m_qnxCamera->supportedFocusModes().contains(::qnxFocusMode(mode));
+}
+
+void QQnxPlatformCamera::setFocusMode(QCamera::FocusMode mode)
+{
+ if (!m_qnxCamera)
+ return;
+
+ m_qnxCamera->setFocusMode(::qnxFocusMode(mode));
+}
+
+void QQnxPlatformCamera::setCustomFocusPoint(const QPointF &point)
+{
+ if (!m_qnxCamera)
+ return;
+
+ m_qnxCamera->setCustomFocusPoint(point);
+}
+
+void QQnxPlatformCamera::setFocusDistance(float distance)
+{
+ if (!m_qnxCamera)
+ return;
+
+ const int maxDistance = m_qnxCamera->maxFocusStep();
+
+ if (maxDistance < 0)
+ return;
+
+ const int qnxDistance = maxDistance * std::min(distance, 1.0f);
+
+ m_qnxCamera->setManualFocusStep(qnxDistance);
+}
+
+void QQnxPlatformCamera::zoomTo(float factor, float)
+{
+ if (!m_qnxCamera)
+ return;
+
+ const uint32_t minZoom = m_qnxCamera->minimumZoomLevel();
+ const uint32_t maxZoom = m_qnxCamera->maximumZoomLevel();
+
+ if (maxZoom <= minZoom)
+ return;
+
+ // QNX has an integer based API. Interpolate between the levels according to the factor we get
+ const float max = maxZoomFactor();
+ const float min = minZoomFactor();
+
+ if (max <= min)
+ return;
+
+ factor = qBound(min, factor, max) - min;
+
+ const uint32_t zoom = minZoom
+ + static_cast<uint32_t>(qRound(factor*(maxZoom - minZoom)/(max - min)));
+
+ if (m_qnxCamera->setZoomFactor(zoom))
+ zoomFactorChanged(factor);
+}
+
+void QQnxPlatformCamera::setExposureCompensation(float ev)
+{
+ if (!m_qnxCamera)
+ return;
+
+ m_qnxCamera->setEvOffset(ev);
+}
+
+int QQnxPlatformCamera::isoSensitivity() const
+{
+ if (!m_qnxCamera)
+ return 0;
+
+ return m_qnxCamera->manualIsoSensitivity();
+}
+
+void QQnxPlatformCamera::setManualIsoSensitivity(int value)
+{
+ if (!m_qnxCamera)
+ return;
+
+ const uint32_t isoValue = std::max(0, value);
+
+ m_qnxCamera->setManualIsoSensitivity(isoValue);
+}
+
+void QQnxPlatformCamera::setManualExposureTime(float seconds)
+{
+ if (!m_qnxCamera)
+ return;
+
+ m_qnxCamera->setManualExposureTime(seconds);
+}
+
+float QQnxPlatformCamera::exposureTime() const
+{
+ if (!m_qnxCamera)
+ return 0.0;
+
+ return static_cast<float>(m_qnxCamera->manualExposureTime());
+}
+
+bool QQnxPlatformCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const
+{
+ if (m_maxColorTemperature != 0)
+ return true;
+
+ return mode == QCamera::WhiteBalanceAuto;
+}
+
+void QQnxPlatformCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)
+{
+ if (!m_qnxCamera)
+ return;
+
+ if (mode == QCamera::WhiteBalanceAuto) {
+ m_qnxCamera->setWhiteBalanceMode(CAMERA_WHITEBALANCEMODE_AUTO);
+ } else {
+ m_qnxCamera->setWhiteBalanceMode(CAMERA_WHITEBALANCEMODE_MANUAL);
+ setColorTemperature(colorTemperatureForWhiteBalance(mode));
+ }
+}
+
+void QQnxPlatformCamera::setColorTemperature(int temperature)
+{
+ if (!m_qnxCamera)
+ return;
+
+ const auto normalizedTemp = std::clamp<uint32_t>(std::max(0, temperature),
+ m_minColorTemperature, m_maxColorTemperature);
+
+ if (m_qnxCamera->hasContinuousWhiteBalanceValues()) {
+ m_qnxCamera->setManualWhiteBalance(normalizedTemp);
+ } else {
+ uint32_t delta = std::numeric_limits<uint32_t>::max();
+ uint32_t closestTemp = 0;
+
+ for (uint32_t value : m_qnxCamera->supportedWhiteBalanceValues()) {
+ const auto &[min, max] = std::minmax(value, normalizedTemp);
+ const uint32_t currentDelta = max - min;
+
+ if (currentDelta < delta) {
+ closestTemp = value;
+ delta = currentDelta;
+ }
+ }
+
+ m_qnxCamera->setManualWhiteBalance(closestTemp);
+ }
+}
+
+bool QQnxPlatformCamera::startVideoRecording()
+{
+ if (!m_qnxCamera) {
+ qWarning("QQnxPlatformCamera: cannot start video recording - no no camera assigned");
+ return false;
+ }
+
+ if (!isVideoEncodingSupported()) {
+ qWarning("QQnxPlatformCamera: cannot start video recording - not supported");
+ return false;
+ }
+
+ if (!m_qnxCamera->isActive()) {
+ qWarning("QQnxPlatformCamera: cannot start video recording - camera not started");
+ return false;
+ }
+
+ const QString container = m_encoderSettings.mimeType().preferredSuffix();
+ const QString location = QMediaStorageLocation::generateFileName(m_outputUrl.toLocalFile(),
+ QStandardPaths::MoviesLocation, container);
+
+#if 0
+ {
+ static void *libScreen = nullptr;
+
+ if (!libScreen)
+ libScreen = dlopen("/usr/lib/libscreen.so.1", RTLD_GLOBAL);
+ }
+#endif
+
+ qDebug() << "Recording to" << location;
+ return m_qnxCamera->startVideoRecording(location);
+}
+
+void QQnxPlatformCamera::requestVideoFrame(VideoFrameCallback cb)
+{
+ m_videoFrameRequests.emplace_back(std::move(cb));
+}
+
+bool QQnxPlatformCamera::isVideoEncodingSupported() const
+{
+ return m_qnxCamera && m_qnxCamera->hasFeature(CAMERA_FEATURE_VIDEO);
+}
+
+void QQnxPlatformCamera::setOutputUrl(const QUrl &url)
+{
+ m_outputUrl = url;
+}
+
+void QQnxPlatformCamera::setMediaEncoderSettings(const QMediaEncoderSettings &settings)
+{
+ m_encoderSettings = settings;
+}
+
+void QQnxPlatformCamera::updateCameraFeatures()
+{
+ if (!m_qnxCamera)
+ return;
+
+ QCamera::Features features = {};
+
+ if (m_qnxCamera->hasFeature(CAMERA_FEATURE_REGIONFOCUS))
+ features |= QCamera::Feature::CustomFocusPoint;
+
+ supportedFeaturesChanged(features);
+
+ minimumZoomFactorChanged(m_qnxCamera->minimumZoomLevel());
+ maximumZoomFactorChanged(m_qnxCamera->maximumZoomLevel());
+
+ const QList<uint32_t> wbValues = m_qnxCamera->supportedWhiteBalanceValues();
+
+ if (wbValues.isEmpty()) {
+ m_minColorTemperature = m_maxColorTemperature = 0;
+ } else {
+ const auto &[minTemp, maxTemp] = std::minmax_element(wbValues.begin(), wbValues.end());
+
+ m_minColorTemperature = *minTemp;
+ m_maxColorTemperature = *maxTemp;
+ }
+}
+
+void QQnxPlatformCamera::onFrameAvailable()
+{
+ if (!m_videoSink)
+ return;
+
+ std::unique_ptr<QQnxCameraFrameBuffer> currentFrameBuffer = m_qnxCamera->takeCurrentFrame();
+
+ if (!currentFrameBuffer)
+ return;
+
+ QVideoFrameFormat format(currentFrameBuffer->size(), currentFrameBuffer->pixelFormat());
+ const QVideoFrame actualFrame =
+ QVideoFramePrivate::createFrame(std::move(currentFrameBuffer), std::move(format));
+
+ m_videoSink->setVideoFrame(actualFrame);
+
+ if (!m_videoFrameRequests.empty()) {
+ VideoFrameCallback cb = std::move(m_videoFrameRequests.front());
+ m_videoFrameRequests.pop_front();
+ cb(actualFrame);
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qqnxplatformcamera_p.cpp"
diff --git a/src/plugins/multimedia/qnx/camera/qqnxplatformcamera_p.h b/src/plugins/multimedia/qnx/camera/qqnxplatformcamera_p.h
new file mode 100644
index 000000000..3cbd17a4f
--- /dev/null
+++ b/src/plugins/multimedia/qnx/camera/qqnxplatformcamera_p.h
@@ -0,0 +1,113 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QQNXPLATFORMCAMERA_H
+#define QQNXPLATFORMCAMERA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qqnxcamera_p.h"
+
+#include <private/qplatformcamera_p.h>
+#include <private/qplatformmediarecorder_p.h>
+
+#include <QtCore/qlist.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qurl.h>
+
+#include <deque>
+#include <functional>
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxPlatformCameraFrameBuffer;
+class QQnxMediaCaptureSession;
+class QQnxVideoSink;
+class QQnxCameraFrameBuffer;
+
+class QQnxPlatformCamera : public QPlatformCamera
+{
+ Q_OBJECT
+public:
+ explicit QQnxPlatformCamera(QCamera *parent);
+ ~QQnxPlatformCamera();
+
+ bool isActive() const override;
+ void setActive(bool active) override;
+ void start();
+ void stop();
+
+ void setCamera(const QCameraDevice &camera) override;
+
+ bool setCameraFormat(const QCameraFormat &format) override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session) override;
+
+ bool isFocusModeSupported(QCamera::FocusMode mode) const override;
+ void setFocusMode(QCamera::FocusMode mode) override;
+
+ void setCustomFocusPoint(const QPointF &point) override;
+
+ void setFocusDistance(float distance) override;
+
+ void zoomTo(float newZoomFactor, float rate = -1.) override;
+
+ void setExposureCompensation(float ev) override;
+
+ int isoSensitivity() const override;
+ void setManualIsoSensitivity(int value) override;
+ void setManualExposureTime(float seconds) override;
+ float exposureTime() const override;
+
+ bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override;
+ void setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) override;
+ void setColorTemperature(int temperature) override;
+
+ void setOutputUrl(const QUrl &url);
+ void setMediaEncoderSettings(const QMediaEncoderSettings &settings);
+
+ bool startVideoRecording();
+
+ using VideoFrameCallback = std::function<void(const QVideoFrame&)>;
+ void requestVideoFrame(VideoFrameCallback cb);
+
+private:
+ void updateCameraFeatures();
+ void setColorTemperatureInternal(unsigned temp);
+
+ bool isVideoEncodingSupported() const;
+
+ void onFrameAvailable();
+
+ QQnxMediaCaptureSession *m_session = nullptr;
+ QQnxVideoSink *m_videoSink = nullptr;
+
+ QCameraDevice m_cameraDevice;
+
+ QUrl m_outputUrl;
+
+ QMediaEncoderSettings m_encoderSettings;
+
+ uint32_t m_minColorTemperature = 0;
+ uint32_t m_maxColorTemperature = 0;
+
+ QMutex m_currentFrameMutex;
+
+ std::unique_ptr<QQnxCamera> m_qnxCamera;
+ std::unique_ptr<QQnxCameraFrameBuffer> m_currentFrame;
+
+ std::deque<VideoFrameCallback> m_videoFrameRequests;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/capture/qqnxaudiorecorder.cpp b/src/plugins/multimedia/qnx/capture/qqnxaudiorecorder.cpp
new file mode 100644
index 000000000..00a20bbd7
--- /dev/null
+++ b/src/plugins/multimedia/qnx/capture/qqnxaudiorecorder.cpp
@@ -0,0 +1,284 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qqnxaudiorecorder_p.h"
+#include "qqnxmediaeventthread_p.h"
+
+#include <QtCore/qcoreapplication.h>
+
+#include <private/qmediastoragelocation_p.h>
+
+#include <mm/renderer.h>
+
+#include <sys/stat.h>
+#include <sys/strm.h>
+
+static QByteArray buildDevicePath(const QByteArray &deviceId, const QMediaEncoderSettings &settings)
+{
+ QByteArray devicePath = QByteArrayLiteral("snd:/dev/snd/") + deviceId + QByteArrayLiteral("?");
+
+ if (settings.audioSampleRate() > 0)
+ devicePath += QByteArrayLiteral("frate=") + QByteArray::number(settings.audioSampleRate());
+
+ if (settings.audioChannelCount() > 0)
+ devicePath += QByteArrayLiteral("nchan=") + QByteArray::number(settings.audioChannelCount());
+
+ return devicePath;
+}
+
+QT_BEGIN_NAMESPACE
+
+QQnxAudioRecorder::QQnxAudioRecorder(QObject *parent)
+ : QObject(parent)
+{
+ openConnection();
+}
+
+QQnxAudioRecorder::~QQnxAudioRecorder()
+{
+ stop();
+ closeConnection();
+}
+
+void QQnxAudioRecorder::openConnection()
+{
+ static int idCounter = 0;
+
+ m_connection = ConnectionUniquePtr { mmr_connect(nullptr) };
+
+ if (!m_connection) {
+ qWarning("QQnxAudioRecorder: Unable to connect to the multimedia renderer");
+ return;
+ }
+
+ m_id = idCounter++;
+
+ char contextName[256];
+
+ std::snprintf(contextName, sizeof contextName, "QQnxAudioRecorder_%d_%llu",
+ m_id, QCoreApplication::applicationPid());
+
+ m_context = ContextUniquePtr { mmr_context_create(m_connection.get(),
+ contextName, 0, S_IRWXU|S_IRWXG|S_IRWXO) };
+
+ if (m_context) {
+ startMonitoring();
+ } else {
+ qWarning("QQnxAudioRecorder: Unable to create context");
+ closeConnection();
+ }
+}
+
+void QQnxAudioRecorder::closeConnection()
+{
+ m_context.reset();
+ m_context.reset();
+
+ stopMonitoring();
+}
+
+void QQnxAudioRecorder::attach()
+{
+ if (isAttached())
+ return;
+
+ const QString container = m_encoderSettings.mimeType().preferredSuffix();
+ const QString location = QMediaStorageLocation::generateFileName(m_outputUrl.toLocalFile(),
+ QStandardPaths::MusicLocation, container);
+
+ m_audioId = mmr_output_attach(m_context.get(), qPrintable(location), "file");
+
+ if (m_audioId == -1) {
+ qWarning("QQnxAudioRecorder: mmr_output_attach() for file failed");
+ return;
+ }
+
+ configureOutputBitRate();
+
+ const QByteArray devicePath = buildDevicePath(m_inputDeviceId, m_encoderSettings);
+
+ if (mmr_input_attach(m_context.get(), devicePath.constData(), "track") != 0) {
+ qWarning("QQnxAudioRecorder: mmr_input_attach() failed");
+ detach();
+ } else {
+ Q_EMIT actualLocationChanged(location);
+ }
+}
+
+void QQnxAudioRecorder::detach()
+{
+ if (!isAttached())
+ return;
+
+ mmr_input_detach(m_context.get());
+ mmr_output_detach(m_context.get(), m_audioId);
+
+ m_audioId = -1;
+}
+
+void QQnxAudioRecorder::configureOutputBitRate()
+{
+ const int bitRate = m_encoderSettings.audioBitRate();
+
+ if (!isAttached() || bitRate <= 0)
+ return;
+
+ char buf[12];
+ std::snprintf(buf, sizeof buf, "%d", bitRate);
+
+ strm_dict_t *dict = strm_dict_new();
+ dict = strm_dict_set(dict, "audio_bitrate", buf);
+
+ if (mmr_output_parameters(m_context.get(), m_audioId, dict) != 0)
+ qWarning("mmr_output_parameters: setting bitrate failed");
+}
+
+bool QQnxAudioRecorder::isAttached() const
+{
+ return m_context && m_audioId != -1;
+}
+
+void QQnxAudioRecorder::setInputDeviceId(const QByteArray &id)
+{
+ m_inputDeviceId = id;
+}
+
+void QQnxAudioRecorder::setOutputUrl(const QUrl &url)
+{
+ m_outputUrl = url;
+}
+
+void QQnxAudioRecorder::setMediaEncoderSettings(const QMediaEncoderSettings &settings)
+{
+ m_encoderSettings = settings;
+}
+
+void QQnxAudioRecorder::record()
+{
+ if (!isAttached()) {
+ attach();
+
+ if (!isAttached())
+ return;
+ }
+
+ if (mmr_play(m_context.get()) != 0)
+ qWarning("QQnxAudioRecorder: mmr_play() failed");
+}
+
+void QQnxAudioRecorder::stop()
+{
+ if (!isAttached())
+ return;
+
+ mmr_stop(m_context.get());
+
+ detach();
+}
+
+void QQnxAudioRecorder::startMonitoring()
+{
+ m_eventThread = std::make_unique<QQnxMediaEventThread>(m_context.get());
+
+ connect(m_eventThread.get(), &QQnxMediaEventThread::eventPending,
+ this, &QQnxAudioRecorder::readEvents);
+
+ m_eventThread->setObjectName(QStringLiteral("MmrAudioEventThread-") + QString::number(m_id));
+ m_eventThread->start();
+}
+
+void QQnxAudioRecorder::stopMonitoring()
+{
+ if (m_eventThread)
+ m_eventThread.reset();
+}
+
+void QQnxAudioRecorder::readEvents()
+{
+ while (const mmr_event_t *event = mmr_event_get(m_context.get())) {
+ if (event->type == MMR_EVENT_NONE)
+ break;
+
+ switch (event->type) {
+ case MMR_EVENT_STATUS:
+ handleMmEventStatus(event);
+ break;
+ case MMR_EVENT_STATE:
+ handleMmEventState(event);
+ break;
+ case MMR_EVENT_ERROR:
+ handleMmEventError(event);
+ break;
+ case MMR_EVENT_METADATA:
+ case MMR_EVENT_NONE:
+ case MMR_EVENT_OVERFLOW:
+ case MMR_EVENT_WARNING:
+ case MMR_EVENT_PLAYLIST:
+ case MMR_EVENT_INPUT:
+ case MMR_EVENT_OUTPUT:
+ case MMR_EVENT_CTXTPAR:
+ case MMR_EVENT_TRKPAR:
+ case MMR_EVENT_OTHER:
+ break;
+ }
+ }
+
+ if (m_eventThread)
+ m_eventThread->signalRead();
+}
+
+void QQnxAudioRecorder::handleMmEventStatus(const mmr_event_t *event)
+{
+ if (!event || event->type != MMR_EVENT_STATUS)
+ return;
+
+ if (!event->pos_str)
+ return;
+
+ const QByteArray valueBa(event->pos_str);
+
+ bool ok;
+ const qint64 duration = valueBa.toLongLong(&ok);
+
+ if (!ok)
+ qCritical("Could not parse duration from '%s'", valueBa.constData());
+ else
+ durationChanged(duration);
+}
+
+void QQnxAudioRecorder::handleMmEventState(const mmr_event_t *event)
+{
+ if (!event || event->type != MMR_EVENT_STATE)
+ return;
+
+ switch (event->state) {
+ case MMR_STATE_DESTROYED:
+ case MMR_STATE_IDLE:
+ case MMR_STATE_STOPPED:
+ Q_EMIT stateChanged(QMediaRecorder::StoppedState);
+ break;
+ case MMR_STATE_PLAYING:
+ Q_EMIT stateChanged(QMediaRecorder::RecordingState);
+ break;
+ }
+}
+
+void QQnxAudioRecorder::handleMmEventError(const mmr_event_t *event)
+{
+ if (!event)
+ return;
+
+ // When playback is explicitly stopped using mmr_stop(), mm-renderer
+ // generates a STATE event. When the end of media is reached, an ERROR
+ // event is generated and the error code contained in the event information
+ // is set to MMR_ERROR_NONE. When an error causes playback to stop,
+ // the error code is set to something else.
+ if (event->details.error.info.error_code == MMR_ERROR_NONE) {
+ //TODO add error
+ Q_EMIT stateChanged(QMediaRecorder::StoppedState);
+ detach();
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qqnxaudiorecorder_p.cpp"
diff --git a/src/plugins/multimedia/qnx/capture/qqnxaudiorecorder_p.h b/src/plugins/multimedia/qnx/capture/qqnxaudiorecorder_p.h
new file mode 100644
index 000000000..f343cee14
--- /dev/null
+++ b/src/plugins/multimedia/qnx/capture/qqnxaudiorecorder_p.h
@@ -0,0 +1,103 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QQNXAUDIORECORDER_H
+#define QQNXAUDIORECORDER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "mmrenderertypes.h"
+
+#include <QByteArray>
+#include <QUrl>
+
+#include <QtCore/qobject.h>
+#include <QtCore/qtconfigmacros.h>
+
+#include <QtMultimedia/qmediarecorder.h>
+
+#include <private/qplatformmediarecorder_p.h>
+
+#include <mm/renderer.h>
+#include <mm/renderer/types.h>
+
+#include <memory>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxMediaEventThread;
+
+class QQnxAudioRecorder : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit QQnxAudioRecorder(QObject *parent = nullptr);
+ ~QQnxAudioRecorder();
+
+ void setInputDeviceId(const QByteArray &id);
+ void setOutputUrl(const QUrl &url);
+ void setMediaEncoderSettings(const QMediaEncoderSettings &settings);
+
+ void record();
+ void stop();
+
+Q_SIGNALS:
+ void stateChanged(QMediaRecorder::RecorderState state);
+ void durationChanged(qint64 durationMs);
+ void actualLocationChanged(const QUrl &location);
+
+private:
+ void openConnection();
+ void closeConnection();
+ void attach();
+ void detach();
+ void configureOutputBitRate();
+ void startMonitoring();
+ void stopMonitoring();
+ void readEvents();
+ void handleMmEventStatus(const mmr_event_t *event);
+ void handleMmEventState(const mmr_event_t *event);
+ void handleMmEventError(const mmr_event_t *event);
+
+ bool isAttached() const;
+
+ struct ContextDeleter
+ {
+ void operator()(mmr_context_t *ctx) { if (ctx) mmr_context_destroy(ctx); }
+ };
+
+ struct ConnectionDeleter
+ {
+ void operator()(mmr_connection_t *conn) { if (conn) mmr_disconnect(conn); }
+ };
+
+ using ContextUniquePtr = std::unique_ptr<mmr_context_t, ContextDeleter>;
+ ContextUniquePtr m_context;
+
+ using ConnectionUniquePtr = std::unique_ptr<mmr_connection_t, ConnectionDeleter>;
+ ConnectionUniquePtr m_connection;
+
+ int m_id = -1;
+ int m_audioId = -1;
+
+ QByteArray m_inputDeviceId;
+
+ QUrl m_outputUrl;
+
+ QMediaEncoderSettings m_encoderSettings;
+
+ std::unique_ptr<QQnxMediaEventThread> m_eventThread;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/capture/qqnxmediacapturesession.cpp b/src/plugins/multimedia/qnx/capture/qqnxmediacapturesession.cpp
new file mode 100644
index 000000000..d73ca7e54
--- /dev/null
+++ b/src/plugins/multimedia/qnx/capture/qqnxmediacapturesession.cpp
@@ -0,0 +1,121 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qqnxmediacapturesession_p.h"
+
+#include "qqnxaudioinput_p.h"
+#include "qqnxplatformcamera_p.h"
+#include "qqnximagecapture_p.h"
+#include "qqnxmediarecorder_p.h"
+#include "qqnxvideosink_p.h"
+#include "qvideosink.h"
+
+QT_BEGIN_NAMESPACE
+
+QQnxMediaCaptureSession::QQnxMediaCaptureSession()
+ : QPlatformMediaCaptureSession()
+{
+}
+
+QQnxMediaCaptureSession::~QQnxMediaCaptureSession()
+{
+}
+
+QPlatformCamera *QQnxMediaCaptureSession::camera()
+{
+ return m_camera;
+}
+
+void QQnxMediaCaptureSession::setCamera(QPlatformCamera *camera)
+{
+ if (camera == m_camera)
+ return;
+
+ if (m_camera)
+ m_camera->setCaptureSession(nullptr);
+
+ m_camera = static_cast<QQnxPlatformCamera *>(camera);
+
+ if (m_camera)
+ m_camera->setCaptureSession(this);
+
+ emit cameraChanged();
+}
+
+QPlatformImageCapture *QQnxMediaCaptureSession::imageCapture()
+{
+ return m_imageCapture;
+}
+
+void QQnxMediaCaptureSession::setImageCapture(QPlatformImageCapture *imageCapture)
+{
+ if (m_imageCapture == imageCapture)
+ return;
+
+ if (m_imageCapture)
+ m_imageCapture->setCaptureSession(nullptr);
+
+ m_imageCapture = static_cast<QQnxImageCapture *>(imageCapture);
+
+ if (m_imageCapture)
+ m_imageCapture->setCaptureSession(this);
+
+ emit imageCaptureChanged();
+}
+
+QPlatformMediaRecorder *QQnxMediaCaptureSession::mediaRecorder()
+{
+ return m_mediaRecorder;
+}
+
+void QQnxMediaCaptureSession::setMediaRecorder(QPlatformMediaRecorder *mediaRecorder)
+{
+ if (m_mediaRecorder == mediaRecorder)
+ return;
+
+ if (m_mediaRecorder)
+ m_mediaRecorder->setCaptureSession(nullptr);
+
+ m_mediaRecorder = static_cast<QQnxMediaRecorder *>(mediaRecorder);
+
+ if (m_mediaRecorder)
+ m_mediaRecorder->setCaptureSession(this);
+
+ emit encoderChanged();
+}
+
+void QQnxMediaCaptureSession::setAudioInput(QPlatformAudioInput *input)
+{
+ if (m_audioInput == input)
+ return;
+
+ m_audioInput = static_cast<QQnxAudioInput*>(input);
+}
+
+void QQnxMediaCaptureSession::setVideoPreview(QVideoSink *sink)
+{
+ auto qnxSink = sink ? static_cast<QQnxVideoSink *>(sink->platformVideoSink()) : nullptr;
+ if (m_videoSink == qnxSink)
+ return;
+ m_videoSink = qnxSink;
+}
+
+void QQnxMediaCaptureSession::setAudioOutput(QPlatformAudioOutput *output)
+{
+ if (m_audioOutput == output)
+ return;
+ m_audioOutput = output;
+}
+
+QQnxAudioInput * QQnxMediaCaptureSession::audioInput() const
+{
+ return m_audioInput;
+}
+
+QQnxVideoSink * QQnxMediaCaptureSession::videoSink() const
+{
+ return m_videoSink;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qqnxmediacapturesession_p.cpp"
diff --git a/src/plugins/multimedia/qnx/capture/qqnxmediacapturesession_p.h b/src/plugins/multimedia/qnx/capture/qqnxmediacapturesession_p.h
new file mode 100644
index 000000000..551416a61
--- /dev/null
+++ b/src/plugins/multimedia/qnx/capture/qqnxmediacapturesession_p.h
@@ -0,0 +1,67 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QQNXMEDIACAPTURESESSION_H
+#define QQNXMEDIACAPTURESESSION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QObject>
+
+#include <private/qplatformmediacapture_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxAudioInput;
+class QQnxPlatformCamera;
+class QQnxImageCapture;
+class QQnxMediaRecorder;
+class QQnxVideoSink;
+
+class QQnxMediaCaptureSession : public QPlatformMediaCaptureSession
+{
+ Q_OBJECT
+
+public:
+ QQnxMediaCaptureSession();
+ ~QQnxMediaCaptureSession();
+
+ QPlatformCamera *camera() override;
+ void setCamera(QPlatformCamera *camera) override;
+
+ QPlatformImageCapture *imageCapture() override;
+ void setImageCapture(QPlatformImageCapture *imageCapture) override;
+
+ QPlatformMediaRecorder *mediaRecorder() override;
+ void setMediaRecorder(QPlatformMediaRecorder *mediaRecorder) override;
+
+ void setAudioInput(QPlatformAudioInput *input) override;
+
+ void setVideoPreview(QVideoSink *sink) override;
+
+ void setAudioOutput(QPlatformAudioOutput *output) override;
+
+ QQnxAudioInput *audioInput() const;
+
+ QQnxVideoSink *videoSink() const;
+
+private:
+ QQnxPlatformCamera *m_camera = nullptr;
+ QQnxImageCapture *m_imageCapture = nullptr;
+ QQnxMediaRecorder *m_mediaRecorder = nullptr;
+ QQnxAudioInput *m_audioInput = nullptr;
+ QPlatformAudioOutput *m_audioOutput = nullptr;
+ QQnxVideoSink *m_videoSink = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/capture/qqnxmediarecorder.cpp b/src/plugins/multimedia/qnx/capture/qqnxmediarecorder.cpp
new file mode 100644
index 000000000..62ac030db
--- /dev/null
+++ b/src/plugins/multimedia/qnx/capture/qqnxmediarecorder.cpp
@@ -0,0 +1,115 @@
+// Copyright (C) 2016 Research In Motion
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#undef QT_NO_CONTEXTLESS_CONNECT // Remove after porting connect() calls
+
+#include "qqnxmediarecorder_p.h"
+
+#include "qqnxplatformcamera_p.h"
+#include "qqnxaudioinput_p.h"
+#include "qqnxcamera_p.h"
+#include "qqnxmediacapturesession_p.h"
+
+#include <private/qplatformcamera_p.h>
+
+#include <QDebug>
+#include <QUrl>
+
+QT_BEGIN_NAMESPACE
+
+QQnxMediaRecorder::QQnxMediaRecorder(QMediaRecorder *parent)
+ : QPlatformMediaRecorder(parent)
+{
+}
+
+bool QQnxMediaRecorder::isLocationWritable(const QUrl &/*location*/) const
+{
+ return true;
+}
+
+void QQnxMediaRecorder::setCaptureSession(QQnxMediaCaptureSession *session)
+{
+ m_session = session;
+}
+
+void QQnxMediaRecorder::record(QMediaEncoderSettings &settings)
+{
+ if (!m_session)
+ return;
+
+ m_audioRecorder.disconnect();
+
+ if (hasCamera()) {
+ startVideoRecording(settings);
+ } else {
+ QObject::connect(&m_audioRecorder, &QQnxAudioRecorder::durationChanged,
+ [this](qint64 d) { durationChanged(d); });
+
+ QObject::connect(&m_audioRecorder, &QQnxAudioRecorder::stateChanged,
+ [this](QMediaRecorder::RecorderState s) { stateChanged(s); });
+
+ QObject::connect(&m_audioRecorder, &QQnxAudioRecorder::actualLocationChanged,
+ [this](const QUrl &l) { actualLocationChanged(l); });
+
+ startAudioRecording(settings);
+ }
+}
+
+void QQnxMediaRecorder::stop()
+{
+ if (hasCamera()) {
+ stopVideoRecording();
+ } else {
+ m_audioRecorder.stop();
+ }
+}
+
+void QQnxMediaRecorder::startAudioRecording(QMediaEncoderSettings &settings)
+{
+ if (!m_session)
+ return;
+
+ QQnxAudioInput *audioInput = m_session->audioInput();
+
+ if (!audioInput)
+ return;
+
+ m_audioRecorder.setInputDeviceId(audioInput->device.id());
+ m_audioRecorder.setMediaEncoderSettings(settings);
+ m_audioRecorder.setOutputUrl(outputLocation());
+ m_audioRecorder.record();
+}
+
+void QQnxMediaRecorder::startVideoRecording(QMediaEncoderSettings &settings)
+{
+ if (!hasCamera())
+ return;
+
+ auto *camera = static_cast<QQnxPlatformCamera*>(m_session->camera());
+
+ camera->setMediaEncoderSettings(settings);
+ camera->setOutputUrl(outputLocation());
+
+ if (camera->startVideoRecording())
+ stateChanged(QMediaRecorder::RecordingState);
+}
+
+void QQnxMediaRecorder::stopVideoRecording()
+{
+ if (!hasCamera())
+ return;
+
+ auto *camera = static_cast<QQnxPlatformCamera*>(m_session->camera());
+
+ camera->stop();
+
+ stateChanged(QMediaRecorder::StoppedState);
+}
+
+bool QQnxMediaRecorder::hasCamera() const
+{
+ return m_session && m_session->camera();
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/qnx/capture/qqnxmediarecorder_p.h b/src/plugins/multimedia/qnx/capture/qqnxmediarecorder_p.h
new file mode 100644
index 000000000..8b3ea21d3
--- /dev/null
+++ b/src/plugins/multimedia/qnx/capture/qqnxmediarecorder_p.h
@@ -0,0 +1,51 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QQNXMEDIARECORDER_H
+#define QQNXMEDIARECORDER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qqnxaudiorecorder_p.h"
+
+#include <private/qplatformmediarecorder_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxMediaCaptureSession;
+
+class QQnxMediaRecorder : public QPlatformMediaRecorder
+{
+public:
+ explicit QQnxMediaRecorder(QMediaRecorder *parent);
+
+ bool isLocationWritable(const QUrl &location) const override;
+
+ void record(QMediaEncoderSettings &settings) override;
+ void stop() override;
+
+ void setCaptureSession(QQnxMediaCaptureSession *session);
+
+private:
+ bool hasCamera() const;
+
+ void startAudioRecording(QMediaEncoderSettings &settings);
+ void startVideoRecording(QMediaEncoderSettings &settings);
+ void stopVideoRecording();
+
+ QQnxAudioRecorder m_audioRecorder;
+
+ QQnxMediaCaptureSession *m_session = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/common/mmrenderertypes.h b/src/plugins/multimedia/qnx/common/mmrenderertypes.h
new file mode 100644
index 000000000..f1d498388
--- /dev/null
+++ b/src/plugins/multimedia/qnx/common/mmrenderertypes.h
@@ -0,0 +1,95 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef MMRENDERERTYPES_H
+#define MMRENDERERTYPES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <mm/renderer.h>
+#include <mm/renderer/types.h>
+
+extern "C" {
+// ### replace with proper include: mm/renderer/events.h
+typedef enum mmr_state {
+ MMR_STATE_DESTROYED,
+ MMR_STATE_IDLE,
+ MMR_STATE_STOPPED,
+ MMR_STATE_PLAYING
+} mmr_state_t;
+
+typedef enum mmr_event_type {
+ MMR_EVENT_NONE,
+ MMR_EVENT_ERROR,
+ MMR_EVENT_STATE,
+ MMR_EVENT_OVERFLOW,
+ MMR_EVENT_WARNING,
+ MMR_EVENT_STATUS,
+ MMR_EVENT_METADATA,
+ MMR_EVENT_PLAYLIST,
+ MMR_EVENT_INPUT,
+ MMR_EVENT_OUTPUT,
+ MMR_EVENT_CTXTPAR,
+ MMR_EVENT_TRKPAR,
+ MMR_EVENT_OTHER
+} mmr_event_type_t;
+
+typedef struct mmr_event {
+ mmr_event_type_t type;
+ mmr_state_t state;
+ int speed;
+ union mmr_event_details {
+
+ struct mmr_event_state {
+ mmr_state_t oldstate;
+ int oldspeed;
+ } state;
+
+ struct mmr_event_error {
+ mmr_error_info_t info;
+ } error;
+
+ struct mmr_event_warning {
+ const char *str;
+ const strm_string_t *obj;
+ } warning;
+
+ struct mmr_event_metadata {
+ unsigned index;
+ } metadata;
+
+ struct mmr_event_trkparam {
+ unsigned index;
+ } trkparam;
+
+ struct mmr_event_playlist {
+ unsigned start;
+ unsigned end;
+ unsigned length;
+ } playlist;
+
+ struct mmr_event_output {
+ unsigned id;
+ } output;
+ } details;
+
+ const strm_string_t* pos_obj;
+ const char* pos_str;
+ const strm_dict_t* data;
+ const char* objname;
+ void* usrdata;
+} mmr_event_t;
+
+const mmr_event_t* mmr_event_get(mmr_context_t *ctxt);
+
+}
+
+#endif
diff --git a/src/plugins/multimedia/qnx/common/qqnxaudioinput.cpp b/src/plugins/multimedia/qnx/common/qqnxaudioinput.cpp
new file mode 100644
index 000000000..fff3cf1eb
--- /dev/null
+++ b/src/plugins/multimedia/qnx/common/qqnxaudioinput.cpp
@@ -0,0 +1,25 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxaudioinput_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QQnxAudioInput::QQnxAudioInput(QAudioInput *parent)
+ : QPlatformAudioInput(parent)
+{
+}
+
+QQnxAudioInput::~QQnxAudioInput()
+{
+}
+
+void QQnxAudioInput::setAudioDevice(const QAudioDevice &info)
+{
+ if (info == device)
+ return;
+
+ device = info;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/qnx/common/qqnxaudioinput_p.h b/src/plugins/multimedia/qnx/common/qqnxaudioinput_p.h
new file mode 100644
index 000000000..62a573cc1
--- /dev/null
+++ b/src/plugins/multimedia/qnx/common/qqnxaudioinput_p.h
@@ -0,0 +1,33 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQNXAUDIOINPUT_P_H
+#define QQNXAUDIOINPUT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <private/qplatformaudioinput_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIA_EXPORT QQnxAudioInput : public QPlatformAudioInput
+{
+public:
+ explicit QQnxAudioInput(QAudioInput *parent);
+ ~QQnxAudioInput();
+
+ void setAudioDevice(const QAudioDevice &device) override;
+};
+
+QT_END_NAMESPACE
+#endif
diff --git a/src/plugins/multimedia/qnx/common/qqnxaudiooutput.cpp b/src/plugins/multimedia/qnx/common/qqnxaudiooutput.cpp
new file mode 100644
index 000000000..76f8fbafd
--- /dev/null
+++ b/src/plugins/multimedia/qnx/common/qqnxaudiooutput.cpp
@@ -0,0 +1,52 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxaudiooutput_p.h"
+
+#include <private/qqnxaudiodevice_p.h>
+
+#include <qaudiodevice.h>
+#include <qaudiooutput.h>
+
+#include <QtCore/qloggingcategory.h>
+
+static Q_LOGGING_CATEGORY(qLcMediaAudioOutput, "qt.multimedia.audiooutput")
+
+QT_BEGIN_NAMESPACE
+
+QQnxAudioOutput::QQnxAudioOutput(QAudioOutput *parent)
+ : QPlatformAudioOutput(parent)
+{
+}
+
+QQnxAudioOutput::~QQnxAudioOutput()
+{
+}
+
+void QQnxAudioOutput::setVolume(float vol)
+{
+ if (vol == volume)
+ return;
+ vol = volume;
+ q->volumeChanged(vol);
+}
+
+void QQnxAudioOutput::setMuted(bool m)
+{
+ if (muted == m)
+ return;
+ muted = m;
+ q->mutedChanged(muted);
+}
+
+void QQnxAudioOutput::setAudioDevice(const QAudioDevice &info)
+{
+ if (info == device)
+ return;
+ qCDebug(qLcMediaAudioOutput) << "setAudioDevice" << info.description() << info.isNull();
+ device = info;
+
+ // ### handle device changes
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/qnx/common/qqnxaudiooutput_p.h b/src/plugins/multimedia/qnx/common/qqnxaudiooutput_p.h
new file mode 100644
index 000000000..2ae5844e6
--- /dev/null
+++ b/src/plugins/multimedia/qnx/common/qqnxaudiooutput_p.h
@@ -0,0 +1,39 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQNXAUDIOOUTPUT_P_H
+#define QQNXAUDIOOUTPUT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <private/qplatformaudiooutput_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioDevice;
+class QAudioOutput;
+
+class Q_MULTIMEDIA_EXPORT QQnxAudioOutput : public QPlatformAudioOutput
+{
+public:
+ explicit QQnxAudioOutput(QAudioOutput *parent);
+ ~QQnxAudioOutput();
+
+ void setAudioDevice(const QAudioDevice &) override;
+ void setVolume(float volume) override;
+ void setMuted(bool muted) override;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/common/qqnxmediaeventthread.cpp b/src/plugins/multimedia/qnx/common/qqnxmediaeventthread.cpp
new file mode 100644
index 000000000..f0cc9b1c0
--- /dev/null
+++ b/src/plugins/multimedia/qnx/common/qqnxmediaeventthread.cpp
@@ -0,0 +1,98 @@
+// Copyright (C) 2017 QNX Software Systems. All rights reserved.
+// Copyright (C) 2021 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxmediaeventthread_p.h"
+
+#include <QtCore/QDebug>
+
+#include <errno.h>
+#include <mm/renderer/types.h>
+#include <sys/neutrino.h>
+
+extern "C" {
+// ### Include mm/renderer/events.h once we have it
+int mmr_event_arm(mmr_context_t *ctxt,
+ struct sigevent const *sev);
+}
+
+QT_BEGIN_NAMESPACE
+
+static const int c_mmrCode = _PULSE_CODE_MINAVAIL + 0;
+static const int c_readCode = _PULSE_CODE_MINAVAIL + 1;
+static const int c_quitCode = _PULSE_CODE_MINAVAIL + 2;
+
+QQnxMediaEventThread::QQnxMediaEventThread(mmr_context_t *context)
+ : QThread(),
+ m_mmrContext(context)
+{
+ if (Q_UNLIKELY((m_channelId = ChannelCreate(_NTO_CHF_DISCONNECT
+ | _NTO_CHF_UNBLOCK
+ | _NTO_CHF_PRIVATE)) == -1)) {
+ qFatal("QQnxMediaEventThread: Can't continue without a channel");
+ }
+
+ if (Q_UNLIKELY((m_connectionId = ConnectAttach(0, 0, m_channelId,
+ _NTO_SIDE_CHANNEL, 0)) == -1)) {
+ ChannelDestroy(m_channelId);
+ qFatal("QQnxMediaEventThread: Can't continue without a channel connection");
+ }
+
+ SIGEV_PULSE_INIT(&m_mmrEvent, m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_mmrCode, 0);
+}
+
+QQnxMediaEventThread::~QQnxMediaEventThread()
+{
+ // block until thread terminates
+ shutdown();
+
+ ConnectDetach(m_connectionId);
+ ChannelDestroy(m_channelId);
+}
+
+void QQnxMediaEventThread::run()
+{
+ int armResult = mmr_event_arm(m_mmrContext, &m_mmrEvent);
+ if (armResult > 0)
+ emit eventPending();
+
+ while (1) {
+ struct _pulse msg;
+ memset(&msg, 0, sizeof(msg));
+ int receiveId = MsgReceive(m_channelId, &msg, sizeof(msg), nullptr);
+ if (receiveId == 0) {
+ if (msg.code == c_mmrCode) {
+ emit eventPending();
+ } else if (msg.code == c_readCode) {
+ armResult = mmr_event_arm(m_mmrContext, &m_mmrEvent);
+ if (armResult > 0)
+ emit eventPending();
+ } else if (msg.code == c_quitCode) {
+ break;
+ } else {
+ qWarning() << Q_FUNC_INFO << "Unexpected pulse" << msg.code;
+ }
+ } else if (receiveId > 0) {
+ qWarning() << Q_FUNC_INFO << "Unexpected message" << msg.code;
+ } else {
+ qWarning() << Q_FUNC_INFO << "MsgReceive error" << strerror(errno);
+ }
+ }
+}
+
+void QQnxMediaEventThread::signalRead()
+{
+ MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_readCode, 0);
+}
+
+void QQnxMediaEventThread::shutdown()
+{
+ MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_quitCode, 0);
+
+ // block until thread terminates
+ wait();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qqnxmediaeventthread_p.cpp"
diff --git a/src/plugins/multimedia/qnx/common/qqnxmediaeventthread_p.h b/src/plugins/multimedia/qnx/common/qqnxmediaeventthread_p.h
new file mode 100644
index 000000000..a622fcb62
--- /dev/null
+++ b/src/plugins/multimedia/qnx/common/qqnxmediaeventthread_p.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2017 QNX Software Systems. All rights reserved.
+// Copyright (C) 2021 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQNXMEDIAEVENTTHREAD_P_H
+#define QQNXMEDIAEVENTTHREAD_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/QThread>
+
+#include <sys/neutrino.h>
+#include <sys/siginfo.h>
+
+QT_BEGIN_NAMESPACE
+
+typedef struct mmr_context mmr_context_t;
+
+class QQnxMediaEventThread : public QThread
+{
+ Q_OBJECT
+
+public:
+ QQnxMediaEventThread(mmr_context_t *context);
+ ~QQnxMediaEventThread() override;
+
+ void signalRead();
+
+protected:
+ void run() override;
+
+Q_SIGNALS:
+ void eventPending();
+
+private:
+ void shutdown();
+
+ int m_channelId;
+ int m_connectionId;
+ struct sigevent m_mmrEvent;
+ mmr_context_t *m_mmrContext;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQnxMediaEventThread_H
diff --git a/src/plugins/multimedia/qnx/common/qqnxwindowgrabber.cpp b/src/plugins/multimedia/qnx/common/qqnxwindowgrabber.cpp
new file mode 100644
index 000000000..28f16b70a
--- /dev/null
+++ b/src/plugins/multimedia/qnx/common/qqnxwindowgrabber.cpp
@@ -0,0 +1,435 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxwindowgrabber_p.h"
+
+#include <QAbstractEventDispatcher>
+#include <QDebug>
+#include <QGuiApplication>
+#include <QImage>
+#include <QThread>
+#include <qpa/qplatformnativeinterface.h>
+
+#include <QOpenGLContext>
+#include <QOpenGLFunctions>
+
+#include <rhi/qrhi.h>
+
+#include <cstring>
+
+#include <EGL/egl.h>
+#include <errno.h>
+
+QT_BEGIN_NAMESPACE
+
+static PFNEGLCREATEIMAGEKHRPROC s_eglCreateImageKHR;
+static PFNEGLDESTROYIMAGEKHRPROC s_eglDestroyImageKHR;
+
+class QQnxWindowGrabberImage
+{
+public:
+ QQnxWindowGrabberImage();
+ ~QQnxWindowGrabberImage();
+
+ bool initialize(screen_context_t screenContext);
+
+ QQnxWindowGrabber::BufferView getBuffer(screen_window_t window, const QSize &size);
+ GLuint getTexture(screen_window_t window, const QSize &size);
+
+private:
+ bool grab(screen_window_t window);
+ bool resize(const QSize &size);
+
+ QSize m_size;
+ screen_pixmap_t m_pixmap;
+ screen_buffer_t m_pixmapBuffer;
+ EGLImageKHR m_eglImage;
+ GLuint m_glTexture;
+ unsigned char *m_bufferAddress;
+ int m_bufferStride;
+};
+
+QQnxWindowGrabber::QQnxWindowGrabber(QObject *parent)
+ : QObject(parent),
+ m_windowParent(nullptr),
+ m_window(nullptr),
+ m_screenContext(nullptr),
+ m_rhi(nullptr),
+ m_active(false),
+ m_eglImageSupported(false),
+ m_startPending(false)
+{
+ // grab the window frame with 60 frames per second
+ m_timer.setInterval(1000/60);
+
+ connect(&m_timer, &QTimer::timeout, this, &QQnxWindowGrabber::triggerUpdate);
+
+ QCoreApplication::eventDispatcher()->installNativeEventFilter(this);
+
+ // Use of EGL images can be disabled by setting QQNX_MM_DISABLE_EGLIMAGE_SUPPORT to something
+ // non-zero. This is probably useful only to test that this path still works since it results
+ // in a high CPU load.
+ if (!s_eglCreateImageKHR && qgetenv("QQNX_MM_DISABLE_EGLIMAGE_SUPPORT").toInt() == 0) {
+ s_eglCreateImageKHR = reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(eglGetProcAddress("eglCreateImageKHR"));
+ s_eglDestroyImageKHR = reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(eglGetProcAddress("eglDestroyImageKHR"));
+ }
+
+ QPlatformNativeInterface *const nativeInterface = QGuiApplication::platformNativeInterface();
+ if (nativeInterface) {
+ m_screenContext = static_cast<screen_context_t>(
+ nativeInterface->nativeResourceForIntegration("screenContext"));
+ }
+
+ // Create a parent window for the window whose content will be grabbed. Since the
+ // window is only a buffer conduit, the characteristics of the parent window are
+ // irrelevant. The contents of the window can be grabbed so long as the window
+ // joins the parent window's group and the parent window is in this process.
+ // Using the window that displays this content isn't possible because there's no
+ // way to reliably retrieve it from this code or any calling code.
+ screen_create_window(&m_windowParent, m_screenContext);
+ screen_create_window_group(m_windowParent, nullptr);
+}
+
+QQnxWindowGrabber::~QQnxWindowGrabber()
+{
+ screen_destroy_window(m_windowParent);
+ QCoreApplication::eventDispatcher()->removeNativeEventFilter(this);
+}
+
+void QQnxWindowGrabber::setFrameRate(int frameRate)
+{
+ m_timer.setInterval(1000/frameRate);
+}
+
+void QQnxWindowGrabber::setWindowId(const QByteArray &windowId)
+{
+ m_windowId = windowId;
+}
+
+void QQnxWindowGrabber::setRhi(QRhi *rhi)
+{
+ m_rhi = rhi;
+
+ checkForEglImageExtension();
+}
+
+void QQnxWindowGrabber::start()
+{
+ if (m_active)
+ return;
+
+ if (!m_window) {
+ m_startPending = true;
+ return;
+ }
+
+ m_startPending = false;
+
+ if (!m_screenContext)
+ screen_get_window_property_pv(m_window, SCREEN_PROPERTY_CONTEXT, reinterpret_cast<void**>(&m_screenContext));
+
+ m_timer.start();
+
+ m_active = true;
+}
+
+void QQnxWindowGrabber::stop()
+{
+ if (!m_active)
+ return;
+
+ resetBuffers();
+
+ m_timer.stop();
+
+ m_active = false;
+}
+
+void QQnxWindowGrabber::pause()
+{
+ m_timer.stop();
+}
+
+void QQnxWindowGrabber::resume()
+{
+ if (!m_active)
+ return;
+
+ m_timer.start();
+}
+
+void QQnxWindowGrabber::forceUpdate()
+{
+ if (!m_active)
+ return;
+
+ triggerUpdate();
+}
+
+bool QQnxWindowGrabber::handleScreenEvent(screen_event_t screen_event)
+{
+
+ int eventType;
+ if (screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &eventType) != 0) {
+ qWarning() << "QQnxWindowGrabber: Failed to query screen event type";
+ return false;
+ }
+
+ if (eventType != SCREEN_EVENT_CREATE)
+ return false;
+
+ screen_window_t window = 0;
+ if (screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&window) != 0) {
+ qWarning() << "QQnxWindowGrabber: Failed to query window property";
+ return false;
+ }
+
+ const int maxIdStrLength = 128;
+ char idString[maxIdStrLength];
+ if (screen_get_window_property_cv(window, SCREEN_PROPERTY_ID_STRING, maxIdStrLength, idString) != 0) {
+ qWarning() << "QQnxWindowGrabber: Failed to query window ID string";
+ return false;
+ }
+
+ // Grab windows that have a non-empty ID string and a matching window id to grab
+ if (idString[0] != '\0' && m_windowId == idString) {
+ m_window = window;
+
+ if (m_startPending)
+ start();
+ }
+
+ return false;
+}
+
+bool QQnxWindowGrabber::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *)
+{
+ if (eventType == "screen_event_t") {
+ const screen_event_t event = static_cast<screen_event_t>(message);
+ return handleScreenEvent(event);
+ }
+
+ return false;
+}
+
+QByteArray QQnxWindowGrabber::windowGroupId() const
+{
+ char groupName[256];
+ memset(groupName, 0, sizeof(groupName));
+ screen_get_window_property_cv(m_windowParent,
+ SCREEN_PROPERTY_GROUP,
+ sizeof(groupName) - 1,
+ groupName);
+ return QByteArray(groupName);
+}
+
+bool QQnxWindowGrabber::isEglImageSupported() const
+{
+ return m_eglImageSupported;
+}
+
+void QQnxWindowGrabber::checkForEglImageExtension()
+{
+ m_eglImageSupported = false;
+
+ if (!m_rhi || m_rhi->backend() != QRhi::OpenGLES2)
+ return;
+
+ const EGLDisplay defaultDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+
+ const char *vendor = eglQueryString(defaultDisplay, EGL_VENDOR);
+
+ if (vendor && std::strstr(vendor, "VMWare"))
+ return;
+
+ const char *eglExtensions = eglQueryString(defaultDisplay, EGL_EXTENSIONS);
+
+ if (!eglExtensions)
+ return;
+
+ m_eglImageSupported = std::strstr(eglExtensions, "EGL_KHR_image")
+ && s_eglCreateImageKHR
+ && s_eglDestroyImageKHR;
+}
+
+void QQnxWindowGrabber::triggerUpdate()
+{
+ int size[2] = { 0, 0 };
+
+ const int result = screen_get_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, size);
+
+ if (result != 0) {
+ resetBuffers();
+ qWarning() << "QQnxWindowGrabber: cannot get window size:" << strerror(errno);
+ return;
+ }
+
+ if (m_size.width() != size[0] || m_size.height() != size[1])
+ m_size = QSize(size[0], size[1]);
+
+ emit updateScene(m_size);
+}
+
+bool QQnxWindowGrabber::selectBuffer()
+{
+ // If we're using egl images we need to double buffer since the gpu may still be using the last
+ // video frame. If we're not, it doesn't matter since the data is immediately copied.
+ if (isEglImageSupported())
+ std::swap(m_frontBuffer, m_backBuffer);
+
+ if (m_frontBuffer)
+ return true;
+
+ auto frontBuffer = std::make_unique<QQnxWindowGrabberImage>();
+
+ if (!frontBuffer->initialize(m_screenContext))
+ return false;
+
+ m_frontBuffer = std::move(frontBuffer);
+
+ return true;
+}
+
+int QQnxWindowGrabber::getNextTextureId()
+{
+ if (!selectBuffer())
+ return 0;
+
+ return m_frontBuffer->getTexture(m_window, m_size);
+}
+
+QQnxWindowGrabber::BufferView QQnxWindowGrabber::getNextBuffer()
+{
+ if (!selectBuffer())
+ return {};
+
+ return m_frontBuffer->getBuffer(m_window, m_size);
+}
+
+void QQnxWindowGrabber::resetBuffers()
+{
+ m_frontBuffer.reset();
+ m_backBuffer.reset();
+}
+
+QQnxWindowGrabberImage::QQnxWindowGrabberImage()
+ : m_pixmap(0),
+ m_pixmapBuffer(0),
+ m_eglImage(0),
+ m_glTexture(0),
+ m_bufferAddress(nullptr),
+ m_bufferStride(0)
+{
+}
+
+QQnxWindowGrabberImage::~QQnxWindowGrabberImage()
+{
+ if (m_glTexture)
+ glDeleteTextures(1, &m_glTexture);
+ if (m_eglImage)
+ s_eglDestroyImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), m_eglImage);
+ if (m_pixmap)
+ screen_destroy_pixmap(m_pixmap);
+}
+
+bool QQnxWindowGrabberImage::initialize(screen_context_t screenContext)
+{
+ if (screen_create_pixmap(&m_pixmap, screenContext) != 0) {
+ qWarning() << "QQnxWindowGrabber: cannot create pixmap:" << strerror(errno);
+ return false;
+ }
+ const int usage = SCREEN_USAGE_WRITE | SCREEN_USAGE_READ | SCREEN_USAGE_NATIVE;
+ screen_set_pixmap_property_iv(m_pixmap, SCREEN_PROPERTY_USAGE, &usage);
+
+ // XXX as a matter of fact, the underlying buffer is BGRX8888 (according to
+ // QNX, screen formats can be loose on the ARGB ordering) - as there is no
+ // SCREEN_FORMAT_BGRX8888 constant, we use SCREEN_FORMAT_RGBX8888, which
+ // carries the same depth and allows us to use the buffer.
+ const int format = SCREEN_FORMAT_RGBX8888;
+ screen_set_pixmap_property_iv(m_pixmap, SCREEN_PROPERTY_FORMAT, &format);
+
+ return true;
+}
+
+bool QQnxWindowGrabberImage::resize(const QSize &newSize)
+{
+ if (m_pixmapBuffer) {
+ screen_destroy_pixmap_buffer(m_pixmap);
+ m_pixmapBuffer = 0;
+ m_bufferAddress = 0;
+ m_bufferStride = 0;
+ }
+
+ const int size[2] = { newSize.width(), newSize.height() };
+
+ screen_set_pixmap_property_iv(m_pixmap, SCREEN_PROPERTY_BUFFER_SIZE, size);
+
+ if (screen_create_pixmap_buffer(m_pixmap) == 0) {
+ screen_get_pixmap_property_pv(m_pixmap, SCREEN_PROPERTY_RENDER_BUFFERS,
+ reinterpret_cast<void**>(&m_pixmapBuffer));
+ screen_get_buffer_property_pv(m_pixmapBuffer, SCREEN_PROPERTY_POINTER,
+ reinterpret_cast<void**>(&m_bufferAddress));
+ screen_get_buffer_property_iv(m_pixmapBuffer, SCREEN_PROPERTY_STRIDE, &m_bufferStride);
+ m_size = newSize;
+
+ return true;
+ } else {
+ m_size = QSize();
+ return false;
+ }
+}
+
+bool QQnxWindowGrabberImage::grab(screen_window_t window)
+{
+ const int rect[] = { 0, 0, m_size.width(), m_size.height() };
+ return screen_read_window(window, m_pixmapBuffer, 1, rect, 0) == 0;
+}
+
+QQnxWindowGrabber::BufferView QQnxWindowGrabberImage::getBuffer(
+ screen_window_t window, const QSize &size)
+{
+ if (size != m_size && !resize(size))
+ return {};
+
+ if (!m_bufferAddress || !grab(window))
+ return {};
+
+ return {
+ .width = m_size.width(),
+ .height = m_size.height(),
+ .stride = m_bufferStride,
+ .data = m_bufferAddress
+ };
+}
+
+GLuint QQnxWindowGrabberImage::getTexture(screen_window_t window, const QSize &size)
+{
+ if (size != m_size) {
+ // create a brand new texture to be the KHR image sibling, as
+ // previously used textures cannot be reused with new KHR image
+ // sources - note that glDeleteTextures handles nullptr gracefully
+ glDeleteTextures(1, &m_glTexture);
+ glGenTextures(1, &m_glTexture);
+
+ glBindTexture(GL_TEXTURE_2D, m_glTexture);
+ if (m_eglImage) {
+ glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, 0);
+ s_eglDestroyImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), m_eglImage);
+ m_eglImage = 0;
+ }
+ if (!resize(size))
+ return 0;
+ m_eglImage = s_eglCreateImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), EGL_NO_CONTEXT,
+ EGL_NATIVE_PIXMAP_KHR, m_pixmap, 0);
+ glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_eglImage);
+ }
+
+ if (!m_pixmap || !grab(window))
+ return 0;
+
+ return m_glTexture;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qqnxwindowgrabber_p.cpp"
diff --git a/src/plugins/multimedia/qnx/common/qqnxwindowgrabber_p.h b/src/plugins/multimedia/qnx/common/qqnxwindowgrabber_p.h
new file mode 100644
index 000000000..1ffd96b63
--- /dev/null
+++ b/src/plugins/multimedia/qnx/common/qqnxwindowgrabber_p.h
@@ -0,0 +1,114 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QQnxWindowGrabber_H
+#define QQnxWindowGrabber_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#define EGL_EGLEXT_PROTOTYPES
+#define GL_GLEXT_PROTOTYPES
+#include <EGL/egl.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <EGL/eglext.h>
+#include <QAbstractNativeEventFilter>
+#include <QObject>
+#include <QSize>
+#include <QTimer>
+
+#include <memory>
+
+#include <screen/screen.h>
+
+QT_BEGIN_NAMESPACE
+
+class QRhi;
+class QQnxWindowGrabberImage;
+
+class QQnxWindowGrabber : public QObject, public QAbstractNativeEventFilter
+{
+ Q_OBJECT
+
+public:
+ struct BufferView
+ {
+ int width = -1;
+ int height = -1;
+ int stride = -1;
+
+ unsigned char *data = nullptr;
+
+ static constexpr int pixelSize = 4; // BGRX8888;
+ };
+
+ explicit QQnxWindowGrabber(QObject *parent = 0);
+ ~QQnxWindowGrabber();
+
+ void setFrameRate(int frameRate);
+
+ void setWindowId(const QByteArray &windowId);
+
+ void setRhi(QRhi *rhi);
+
+ void start();
+ void stop();
+
+ void pause();
+ void resume();
+
+ void forceUpdate();
+
+ bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
+
+ bool handleScreenEvent(screen_event_t event);
+
+ QByteArray windowGroupId() const;
+
+ bool isEglImageSupported() const;
+
+ int getNextTextureId();
+ BufferView getNextBuffer();
+
+signals:
+ void updateScene(const QSize &size);
+
+private slots:
+ void triggerUpdate();
+
+private:
+ bool selectBuffer();
+ void resetBuffers();
+ void checkForEglImageExtension();
+
+ QTimer m_timer;
+
+ QByteArray m_windowId;
+
+ screen_window_t m_windowParent;
+ screen_window_t m_window;
+ screen_context_t m_screenContext;
+
+ std::unique_ptr<QQnxWindowGrabberImage> m_frontBuffer;
+ std::unique_ptr<QQnxWindowGrabberImage> m_backBuffer;
+
+ QSize m_size;
+
+ QRhi *m_rhi;
+
+ bool m_active;
+ bool m_eglImageSupported;
+ bool m_startPending;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/mediaplayer/qqnxmediametadata.cpp b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediametadata.cpp
new file mode 100644
index 000000000..fcd535814
--- /dev/null
+++ b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediametadata.cpp
@@ -0,0 +1,262 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qqnxmediametadata_p.h"
+
+#include <QtCore/qdebug.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qstringlist.h>
+
+#include <mm/renderer/types.h>
+#include <sys/neutrino.h>
+#include <sys/strm.h>
+
+extern "C" {
+// ### include this properly from mm/renderer/events.h once the toolchain is fixed
+extern strm_dict_t* mmr_metadata_split(strm_dict_t const *md,
+ const char *type,
+ unsigned idx);
+}
+
+static const char *strm_string_getx(const strm_string_t *sstr, const char *defaultValue)
+{
+ return sstr ? strm_string_get(sstr) : defaultValue;
+}
+
+QT_BEGIN_NAMESPACE
+
+QQnxMediaMetaData::QQnxMediaMetaData()
+{
+ clear();
+}
+
+static const char * titleKey = "md_title_name";
+static const char * artistKey = "md_title_artist";
+static const char * commentKey = "md_title_comment";
+static const char * genreKey = "md_title_genre";
+static const char * yearKey = "md_title_year";
+static const char * durationKey = "md_title_duration";
+static const char * bitRateKey = "md_title_bitrate";
+static const char * sampleKey = "md_title_samplerate";
+static const char * albumKey = "md_title_album";
+static const char * trackKey = "md_title_track";
+static const char * widthKey = "md_video_width";
+static const char * heightKey = "md_video_height";
+static const char * mediaTypeKey = "md_title_mediatype";
+static const char * pixelWidthKey = "md_video_pixel_width";
+static const char * pixelHeightKey = "md_video_pixel_height";
+static const char * seekableKey = "md_title_seekable";
+static const char * trackSampleKey = "sample_rate";
+static const char * trackBitRateKey = "bitrate";
+static const char * trackWidthKey = "width";
+static const char * trackHeightKey = "height";
+static const char * trackPixelWidthKey = "pixel_width";
+static const char * trackPixelHeightKey = "pixel_height";
+
+static const int mediaTypeAudioFlag = 4;
+static const int mediaTypeVideoFlag = 2;
+
+bool QQnxMediaMetaData::update(const strm_dict_t *dict)
+{
+ if (!dict) {
+ clear();
+ return true;
+ }
+
+ const strm_string_t *value;
+
+ value = strm_dict_find_rstr(dict, durationKey);
+ m_duration = QByteArray(strm_string_getx(value, "0")).toLongLong();
+
+ value = strm_dict_find_rstr(dict, mediaTypeKey);
+ m_mediaType = QByteArray(strm_string_getx(value, "-1")).toInt();
+
+ value = strm_dict_find_rstr(dict, titleKey);
+ m_title = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
+
+ value = strm_dict_find_rstr(dict, seekableKey);
+ m_seekable = (strcmp(strm_string_getx(value, "1"), "0") != 0);
+
+ value = strm_dict_find_rstr(dict, artistKey);
+ m_artist = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
+
+ value = strm_dict_find_rstr(dict, commentKey);
+ m_comment = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
+
+ value = strm_dict_find_rstr(dict, genreKey);
+ m_genre = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
+
+ value = strm_dict_find_rstr(dict, yearKey);
+ m_year = QByteArray(strm_string_getx(value, "0")).toInt();
+
+ value = strm_dict_find_rstr(dict, albumKey);
+ m_album = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
+
+ value = strm_dict_find_rstr(dict, trackKey);
+ m_track = QByteArray(strm_string_getx(value, "0")).toInt();
+
+ strm_dict_t *at = mmr_metadata_split(dict, "audio", 0);
+ if (at) {
+ value = strm_dict_find_rstr(at, trackSampleKey);
+ m_sampleRate = QByteArray(strm_string_getx(value, "0")).toInt();
+
+ value = strm_dict_find_rstr(at, trackBitRateKey);
+ m_audioBitRate = QByteArray(strm_string_getx(value, "0")).toInt();
+
+ strm_dict_destroy(at);
+ } else {
+ value = strm_dict_find_rstr(dict, sampleKey);
+ m_sampleRate = QByteArray(strm_string_getx(value, "0")).toInt();
+
+ value = strm_dict_find_rstr(dict, bitRateKey);
+ m_audioBitRate = QByteArray(strm_string_getx(value, "0")).toInt();
+ }
+
+ strm_dict_t *vt = mmr_metadata_split(dict, "video", 0);
+ if (vt) {
+ value = strm_dict_find_rstr(vt, trackWidthKey);
+ m_width = QByteArray(strm_string_getx(value, "0")).toInt();
+
+ value = strm_dict_find_rstr(vt, trackHeightKey);
+ m_height = QByteArray(strm_string_getx(value, "0")).toInt();
+
+ value = strm_dict_find_rstr(vt, trackPixelWidthKey);
+ m_pixelWidth = QByteArray(strm_string_getx(value, "1")).toFloat();
+
+ value = strm_dict_find_rstr(vt, trackPixelHeightKey);
+ m_pixelHeight = QByteArray(strm_string_getx(value, "1")).toFloat();
+
+ strm_dict_destroy(vt);
+ } else {
+ value = strm_dict_find_rstr(dict, widthKey);
+ m_width = QByteArray(strm_string_getx(value, "0")).toInt();
+
+ value = strm_dict_find_rstr(dict, heightKey);
+ m_height = QByteArray(strm_string_getx(value, "0")).toInt();
+
+ value = strm_dict_find_rstr(dict, pixelWidthKey);
+ m_pixelWidth = QByteArray(strm_string_getx(value, "1")).toFloat();
+
+ value = strm_dict_find_rstr(dict, pixelHeightKey);
+ m_pixelHeight = QByteArray(strm_string_getx(value, "1")).toFloat();
+ }
+
+ return true;
+}
+
+void QQnxMediaMetaData::clear()
+{
+ strm_dict_t *dict;
+ dict = strm_dict_new();
+ update(dict);
+ strm_dict_destroy(dict);
+}
+
+qlonglong QQnxMediaMetaData::duration() const
+{
+ return m_duration;
+}
+
+// Handling of pixel aspect ratio
+//
+// If the pixel aspect ratio is different from 1:1, it means the video needs to be stretched in
+// order to look natural.
+// For example, if the pixel width is 2, and the pixel height is 1, it means a video of 300x200
+// pixels needs to be displayed as 600x200 to look correct.
+// In order to support this the easiest way, we simply pretend that the actual size of the video
+// is 600x200, which will cause the video to be displayed in an aspect ratio of 3:1 instead of 3:2,
+// and therefore look correct.
+
+int QQnxMediaMetaData::height() const
+{
+ return m_height * m_pixelHeight;
+}
+
+int QQnxMediaMetaData::width() const
+{
+ return m_width * m_pixelWidth;
+}
+
+bool QQnxMediaMetaData::hasVideo() const
+{
+ // By default, assume no video if we can't extract the information
+ if (m_mediaType == -1)
+ return false;
+
+ return (m_mediaType & mediaTypeVideoFlag);
+}
+
+bool QQnxMediaMetaData::hasAudio() const
+{
+ // By default, assume audio only if we can't extract the information
+ if (m_mediaType == -1)
+ return true;
+
+ return (m_mediaType & mediaTypeAudioFlag);
+}
+
+QString QQnxMediaMetaData::title() const
+{
+ return m_title;
+}
+
+bool QQnxMediaMetaData::isSeekable() const
+{
+ return m_seekable;
+}
+
+QString QQnxMediaMetaData::artist() const
+{
+ return m_artist;
+}
+
+QString QQnxMediaMetaData::comment() const
+{
+ return m_comment;
+}
+
+QString QQnxMediaMetaData::genre() const
+{
+ return m_genre;
+}
+
+int QQnxMediaMetaData::year() const
+{
+ return m_year;
+}
+
+QString QQnxMediaMetaData::mediaType() const
+{
+ if (hasVideo())
+ return QLatin1String("video");
+ else if (hasAudio())
+ return QLatin1String("audio");
+ else
+ return QString();
+}
+
+int QQnxMediaMetaData::audioBitRate() const
+{
+ return m_audioBitRate;
+}
+
+int QQnxMediaMetaData::sampleRate() const
+{
+ return m_sampleRate;
+}
+
+QString QQnxMediaMetaData::album() const
+{
+ return m_album;
+}
+
+int QQnxMediaMetaData::track() const
+{
+ return m_track;
+}
+
+QSize QQnxMediaMetaData::resolution() const
+{
+ return QSize(width(), height());
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/qnx/mediaplayer/qqnxmediametadata_p.h b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediametadata_p.h
new file mode 100644
index 000000000..db7639dc5
--- /dev/null
+++ b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediametadata_p.h
@@ -0,0 +1,74 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QQnxMediaMetaData_H
+#define QQnxMediaMetaData_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+#include <QtCore/QSize>
+#include <QtCore/QString>
+
+typedef struct strm_dict strm_dict_t;
+
+QT_BEGIN_NAMESPACE
+
+class QQnxMediaMetaData
+{
+public:
+ QQnxMediaMetaData();
+ bool update(const strm_dict_t *dict);
+ void clear();
+
+ // Duration in milliseconds
+ qlonglong duration() const;
+
+ int height() const;
+ int width() const;
+ bool hasVideo() const;
+ bool hasAudio() const;
+ bool isSeekable() const;
+
+ QString title() const;
+ QString artist() const;
+ QString comment() const;
+ QString genre() const;
+ int year() const;
+ QString mediaType() const;
+ int audioBitRate() const;
+ int sampleRate() const;
+ QString album() const;
+ int track() const;
+ QSize resolution() const;
+
+private:
+ qlonglong m_duration;
+ int m_height;
+ int m_width;
+ int m_mediaType;
+ float m_pixelWidth;
+ float m_pixelHeight;
+ bool m_seekable;
+ QString m_title;
+ QString m_artist;
+ QString m_comment;
+ QString m_genre;
+ int m_year;
+ int m_audioBitRate;
+ int m_sampleRate;
+ QString m_album;
+ int m_track;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/mediaplayer/qqnxmediaplayer.cpp b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediaplayer.cpp
new file mode 100644
index 000000000..14b190836
--- /dev/null
+++ b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediaplayer.cpp
@@ -0,0 +1,887 @@
+// Copyright (C) 2016 Research In Motion
+// Copyright (C) 2021 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qqnxmediaplayer_p.h"
+#include "qqnxvideosink_p.h"
+#include "qqnxmediautil_p.h"
+#include "qqnxmediaeventthread_p.h"
+#include "qqnxwindowgrabber_p.h"
+
+#include <private/qhwvideobuffer_p.h>
+#include <private/qvideoframe_p.h>
+
+#include <QtCore/qabstracteventdispatcher.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qdir.h>
+#include <QtCore/qfileinfo.h>
+#include <QtCore/quuid.h>
+#include <mm/renderer.h>
+#include <qmediaplayer.h>
+#include <qqnxaudiooutput_p.h>
+#include <qaudiooutput.h>
+
+#include <errno.h>
+#include <sys/strm.h>
+#include <sys/stat.h>
+
+#include <algorithm>
+#include <tuple>
+
+static constexpr int rateToSpeed(qreal rate)
+{
+ return std::floor(rate * 1000);
+}
+
+static constexpr qreal speedToRate(int speed)
+{
+ return std::floor(speed / 1000.0);
+}
+
+static constexpr int normalizeVolume(float volume)
+{
+ return std::clamp<int>(std::floor(volume * 100.0), 0, 100);
+}
+
+static std::tuple<int, int, bool> parseBufferLevel(const QString &value)
+{
+ if (value.isEmpty())
+ return {};
+
+ const int slashPos = value.indexOf('/');
+ if (slashPos <= 0)
+ return {};
+
+ bool ok = false;
+ const int level = value.left(slashPos).toInt(&ok);
+ if (!ok || level < 0)
+ return {};
+
+ const int capacity = value.mid(slashPos + 1).toInt(&ok);
+ if (!ok || capacity < 0)
+ return {};
+
+ return { level, capacity, true };
+}
+
+class QnxTextureBuffer : public QHwVideoBuffer
+{
+public:
+ QnxTextureBuffer(QQnxWindowGrabber *QQnxWindowGrabber)
+ : QHwVideoBuffer(QVideoFrame::RhiTextureHandle)
+ {
+ m_windowGrabber = QQnxWindowGrabber;
+ m_handle = 0;
+ }
+
+ void unmap() override {}
+
+ MapData map(QtVideo::MapMode /*mode*/) override
+ {
+ return {};
+ }
+
+ quint64 textureHandle(QRhi *, int plane) const override
+ {
+ if (plane != 0)
+ return 0;
+ if (!m_handle) {
+ const_cast<QnxTextureBuffer*>(this)->m_handle = m_windowGrabber->getNextTextureId();
+ }
+ return m_handle;
+ }
+
+private:
+ QQnxWindowGrabber *m_windowGrabber;
+ quint64 m_handle;
+};
+
+class QnxRasterBuffer : public QAbstractVideoBuffer
+{
+public:
+ QnxRasterBuffer(QQnxWindowGrabber *windowGrabber) { m_windowGrabber = windowGrabber; }
+
+ MapData map(QtVideo::MapMode mode) override
+ {
+ if (mode != QtVideo::MapMode::ReadOnly)
+ return {};
+
+ if (buffer.data) {
+ qWarning("QnxRasterBuffer: need to unmap before mapping");
+ return {};
+ }
+
+ buffer = m_windowGrabber->getNextBuffer();
+
+ return {
+ .planeCount = 1,
+ .bytesPerLine = { buffer.stride },
+ .data = { buffer.data },
+ .dataSize = { buffer.width * buffer.height * buffer.pixelSize }
+ };
+ }
+
+ void unmap() override
+ {
+ buffer = {};
+ }
+
+ QVideoFrameFormat format() const override { return {}; }
+
+private:
+ QQnxWindowGrabber *m_windowGrabber;
+ QQnxWindowGrabber::BufferView buffer;
+};
+
+QT_BEGIN_NAMESPACE
+
+QQnxMediaPlayer::QQnxMediaPlayer(QMediaPlayer *parent)
+ : QObject(parent)
+ , QPlatformMediaPlayer(parent)
+ , m_windowGrabber(new QQnxWindowGrabber(this))
+{
+ m_flushPositionTimer.setSingleShot(true);
+ m_flushPositionTimer.setInterval(100);
+
+ connect(&m_flushPositionTimer, &QTimer::timeout, this, &QQnxMediaPlayer::flushPosition);
+
+ connect(m_windowGrabber, &QQnxWindowGrabber::updateScene, this, &QQnxMediaPlayer::updateScene);
+
+ openConnection();
+}
+
+QQnxMediaPlayer::~QQnxMediaPlayer()
+{
+ stop();
+ detach();
+ closeConnection();
+}
+
+void QQnxMediaPlayer::openConnection()
+{
+ static int idCounter = 0;
+
+ m_connection = mmr_connect(nullptr);
+ if (!m_connection) {
+ emitPError(QString::fromLatin1("Unable to connect to the multimedia renderer"));
+ return;
+ }
+
+ m_id = idCounter++;
+ m_contextName = QString::fromLatin1("QQnxMediaPlayer_%1_%2").arg(m_id)
+ .arg(QCoreApplication::applicationPid());
+ m_context = mmr_context_create(m_connection, m_contextName.toLatin1(),
+ 0, S_IRWXU|S_IRWXG|S_IRWXO);
+ if (!m_context) {
+ emitPError(QString::fromLatin1("Unable to create context"));
+ closeConnection();
+ return;
+ }
+
+ startMonitoring();
+}
+
+void QQnxMediaPlayer::handleMmEventState(const mmr_event_t *event)
+{
+ if (!event || event->type != MMR_EVENT_STATE)
+ return;
+
+ switch (event->state) {
+ case MMR_STATE_DESTROYED:
+ break;
+ case MMR_STATE_IDLE:
+ mediaStatusChanged(QMediaPlayer::NoMedia);
+ stateChanged(QMediaPlayer::StoppedState);
+ detachVideoOutput();
+ detachInput();
+ break;
+ case MMR_STATE_STOPPED:
+ stateChanged(QMediaPlayer::StoppedState);
+ m_windowGrabber->stop();
+
+ if (m_platformVideoSink)
+ m_platformVideoSink->setVideoFrame({});
+ break;
+ case MMR_STATE_PLAYING:
+ if (event->speed == 0) {
+ stateChanged(QMediaPlayer::PausedState);
+ m_windowGrabber->pause();
+ } else if (state() == QMediaPlayer::PausedState) {
+ m_windowGrabber->resume();
+ stateChanged(QMediaPlayer::PlayingState);
+ } else {
+ m_windowGrabber->start();
+ stateChanged(QMediaPlayer::PlayingState);
+ }
+
+ if (event->speed != m_speed) {
+ m_speed = event->speed;
+
+ if (state() != QMediaPlayer::PausedState)
+ m_configuredSpeed = m_speed;
+
+ playbackRateChanged(::speedToRate(m_speed));
+ }
+ break;
+ }
+}
+
+void QQnxMediaPlayer::handleMmEventStatus(const mmr_event_t *event)
+{
+ if (!event || event->type != MMR_EVENT_STATUS)
+ return;
+
+ if (event->data)
+ handleMmEventStatusData(event->data);
+
+ // update pos
+ if (!event->pos_str || isPendingPositionFlush())
+ return;
+
+ const QByteArray valueBa(event->pos_str);
+
+ bool ok;
+ const qint64 position = valueBa.toLongLong(&ok);
+
+ if (!ok)
+ qCritical("Could not parse position from '%s'", valueBa.constData());
+ else
+ handleMmPositionChanged(position);
+}
+
+void QQnxMediaPlayer::handleMmEventStatusData(const strm_dict_t *data)
+{
+ if (!data)
+ return;
+
+ const auto getValue = [data](const char *key) -> QString {
+ const strm_string_t *value = strm_dict_find_rstr(data, key);
+
+ if (!value)
+ return {};
+
+ return QString::fromUtf8(strm_string_get(value));
+ };
+
+ // update bufferProgress
+ const QString bufferLevel = getValue("bufferlevel");
+
+ if (!bufferLevel.isEmpty()) {
+ const auto & [level, capacity, ok] = ::parseBufferLevel(bufferLevel);
+
+ if (ok)
+ updateBufferLevel(level, capacity);
+ else
+ qCritical("Could not parse buffer capacity from '%s'", qUtf8Printable(bufferLevel));
+ }
+
+ // update MediaStatus
+ const QString bufferStatus = getValue("bufferstatus");
+ const QString suspended = getValue("suspended");
+
+ if (suspended == QStringLiteral("yes"))
+ mediaStatusChanged(QMediaPlayer::StalledMedia);
+ else if (bufferStatus == QStringLiteral("buffering"))
+ mediaStatusChanged(QMediaPlayer::BufferingMedia);
+ else if (bufferStatus == QStringLiteral("playing"))
+ mediaStatusChanged(QMediaPlayer::BufferedMedia);
+}
+
+void QQnxMediaPlayer::handleMmEventError(const mmr_event_t *event)
+{
+ if (!event)
+ return;
+
+ // When playback is explicitly stopped using mmr_stop(), mm-renderer
+ // generates a STATE event. When the end of media is reached, an ERROR
+ // event is generated and the error code contained in the event information
+ // is set to MMR_ERROR_NONE. When an error causes playback to stop,
+ // the error code is set to something else.
+ if (event->details.error.info.error_code == MMR_ERROR_NONE) {
+ mediaStatusChanged(QMediaPlayer::EndOfMedia);
+ stateChanged(QMediaPlayer::StoppedState);
+ }
+}
+
+void QQnxMediaPlayer::closeConnection()
+{
+ stopMonitoring();
+
+ if (m_context) {
+ mmr_context_destroy(m_context);
+ m_context = nullptr;
+ m_contextName.clear();
+ }
+
+ if (m_connection) {
+ mmr_disconnect(m_connection);
+ m_connection = nullptr;
+ }
+}
+
+QByteArray QQnxMediaPlayer::resourcePathForUrl(const QUrl &url)
+{
+ // If this is a local file, mmrenderer expects the file:// prefix and an absolute path.
+ // We treat URLs without scheme as local files, most likely someone just forgot to set the
+ // file:// prefix when constructing the URL.
+ if (url.isLocalFile() || url.scheme().isEmpty()) {
+ const QString relativeFilePath = url.scheme().isEmpty() ? url.path() : url.toLocalFile();
+ const QFileInfo fileInfo(relativeFilePath);
+ return QFile::encodeName(QStringLiteral("file://") + fileInfo.absoluteFilePath());
+
+ // HTTP or similar URL
+ } else {
+ return url.toEncoded();
+ }
+}
+
+void QQnxMediaPlayer::attach()
+{
+ // Should only be called in detached state
+ if (isInputAttached())
+ return;
+
+ if (!m_media.isValid() || !m_context) {
+ mediaStatusChanged(QMediaPlayer::NoMedia);
+ return;
+ }
+
+ resetMonitoring();
+
+ if (!(attachVideoOutput() && attachAudioOutput() && attachInput())) {
+ detach();
+ return;
+ }
+
+ mediaStatusChanged(QMediaPlayer::LoadedMedia);
+}
+
+bool QQnxMediaPlayer::attachVideoOutput()
+{
+ if (isVideoOutputAttached()) {
+ qWarning() << "QQnxMediaPlayer: Video output already attached!";
+ return true;
+ }
+
+ if (!m_context) {
+ qWarning() << "QQnxMediaPlayer: No media player context!";
+ return false;
+ }
+
+ const QByteArray windowGroupId = m_windowGrabber->windowGroupId();
+ if (windowGroupId.isEmpty()) {
+ qWarning() << "QQnxMediaPlayer: Unable to find window group";
+ return false;
+ }
+
+ static int winIdCounter = 0;
+
+ const QString windowName = QStringLiteral("QQnxVideoSink_%1_%2")
+ .arg(winIdCounter++)
+ .arg(QCoreApplication::applicationPid());
+
+ m_windowGrabber->setWindowId(windowName.toLatin1());
+
+ if (m_platformVideoSink)
+ m_windowGrabber->setRhi(m_platformVideoSink->rhi());
+
+ // Start with an invisible window, because we just want to grab the frames from it.
+ const QString videoDeviceUrl = QStringLiteral("screen:?winid=%1&wingrp=%2&initflags=invisible&nodstviewport=1")
+ .arg(windowName, QString::fromLatin1(windowGroupId));
+
+ m_videoId = mmr_output_attach(m_context, videoDeviceUrl.toLatin1(), "video");
+
+ if (m_videoId == -1) {
+ qWarning() << "mmr_output_attach() for video failed";
+ return false;
+ }
+
+ return true;
+}
+
+bool QQnxMediaPlayer::attachAudioOutput()
+{
+ if (isAudioOutputAttached()) {
+ qWarning() << "QQnxMediaPlayer: Audio output already attached!";
+ return true;
+ }
+
+ const QByteArray defaultAudioDevice = qgetenv("QQNX_RENDERER_DEFAULT_AUDIO_SINK");
+
+ m_audioId = mmr_output_attach(m_context,
+ defaultAudioDevice.isEmpty() ? "snd:" : defaultAudioDevice.constData(), "audio");
+
+ if (m_audioId == -1) {
+ emitMmError("mmr_output_attach() for audio failed");
+
+ return false;
+ }
+
+ return true;
+}
+
+bool QQnxMediaPlayer::attachInput()
+{
+ if (isInputAttached())
+ return true;
+
+ const QByteArray resourcePath = resourcePathForUrl(m_media);
+
+ if (resourcePath.isEmpty())
+ return false;
+
+ if (mmr_input_attach(m_context, resourcePath.constData(), "track") != 0) {
+ emitMmError(QStringLiteral("mmr_input_attach() failed for ")
+ + QString::fromUtf8(resourcePath));
+
+ mediaStatusChanged(QMediaPlayer::InvalidMedia);
+
+ return false;
+ }
+
+ m_inputAttached = true;
+
+ return true;
+}
+
+void QQnxMediaPlayer::detach()
+{
+ if (!m_context)
+ return;
+
+ if (isVideoOutputAttached())
+ detachVideoOutput();
+
+ if (isAudioOutputAttached())
+ detachAudioOutput();
+
+ if (isInputAttached())
+ detachInput();
+
+ resetMonitoring();
+}
+
+void QQnxMediaPlayer::detachVideoOutput()
+{
+ m_windowGrabber->stop();
+
+ if (m_platformVideoSink)
+ m_platformVideoSink->setVideoFrame({});
+
+ if (isVideoOutputAttached())
+ mmr_output_detach(m_context, m_videoId);
+
+ m_videoId = -1;
+}
+
+void QQnxMediaPlayer::detachAudioOutput()
+{
+ if (isAudioOutputAttached())
+ mmr_output_detach(m_context, m_audioId);
+
+ m_audioId = -1;
+}
+
+void QQnxMediaPlayer::detachInput()
+{
+ if (isInputAttached())
+ mmr_input_detach(m_context);
+
+ m_inputAttached = false;
+}
+
+bool QQnxMediaPlayer::isVideoOutputAttached() const
+{
+ return m_videoId != -1;
+}
+
+bool QQnxMediaPlayer::isAudioOutputAttached() const
+{
+ return m_audioId != -1;
+}
+
+bool QQnxMediaPlayer::isInputAttached() const
+{
+ return m_inputAttached;
+}
+
+void QQnxMediaPlayer::updateScene(const QSize &size)
+{
+ if (!m_platformVideoSink)
+ return;
+
+ QVideoFrameFormat format(size, QVideoFrameFormat::Format_BGRX8888);
+
+ const QVideoFrame actualFrame = m_windowGrabber->isEglImageSupported()
+ ? QVideoFramePrivate::createFrame(std::make_unique<QnxTextureBuffer>(m_windowGrabber),
+ std::move(format))
+ : QVideoFramePrivate::createFrame(std::make_unique<QnxRasterBuffer>(m_windowGrabber),
+ std::move(format));
+
+ m_platformVideoSink->setVideoFrame(actualFrame);
+}
+
+qint64 QQnxMediaPlayer::duration() const
+{
+ return m_metaData.duration();
+}
+
+qint64 QQnxMediaPlayer::position() const
+{
+ return m_position;
+}
+
+void QQnxMediaPlayer::setPosition(qint64 position)
+{
+ if (m_position == position)
+ return;
+
+ m_pendingPosition = position;
+ m_flushPositionTimer.start();
+}
+
+void QQnxMediaPlayer::setPositionInternal(qint64 position)
+{
+ if (!m_context || !m_metaData.isSeekable() || mediaStatus() == QMediaPlayer::NoMedia)
+ return;
+
+ if (mmr_seek(m_context, QString::number(position).toLatin1()) != 0)
+ emitMmError("Seeking failed");
+}
+
+void QQnxMediaPlayer::flushPosition()
+{
+ setPositionInternal(m_pendingPosition);
+}
+
+bool QQnxMediaPlayer::isPendingPositionFlush() const
+{
+ return m_flushPositionTimer.isActive();
+}
+
+void QQnxMediaPlayer::setDeferredSpeedEnabled(bool enabled)
+{
+ m_deferredSpeedEnabled = enabled;
+}
+
+bool QQnxMediaPlayer::isDeferredSpeedEnabled() const
+{
+ return m_deferredSpeedEnabled;
+}
+
+void QQnxMediaPlayer::setVolume(float volume)
+{
+ const int normalizedVolume = ::normalizeVolume(volume);
+
+ if (m_volume == normalizedVolume)
+ return;
+
+ m_volume = normalizedVolume;
+
+ if (!m_muted)
+ updateVolume();
+}
+
+void QQnxMediaPlayer::setMuted(bool muted)
+{
+ if (m_muted == muted)
+ return;
+
+ m_muted = muted;
+
+ updateVolume();
+}
+
+void QQnxMediaPlayer::updateVolume()
+{
+ if (!m_context || m_audioId == -1)
+ return;
+
+ const int volume = m_muted ? 0 : m_volume;
+
+ char buf[] = "100";
+ std::snprintf(buf, sizeof buf, "%d", volume);
+
+ strm_dict_t * dict = strm_dict_new();
+ dict = strm_dict_set(dict, "volume", buf);
+
+ if (mmr_output_parameters(m_context, m_audioId, dict) != 0)
+ emitMmError("mmr_output_parameters: Setting volume failed");
+}
+
+void QQnxMediaPlayer::setAudioOutput(QPlatformAudioOutput *output)
+{
+ QAudioOutput *out = output ? output->q : nullptr;
+ if (m_audioOutput == out)
+ return;
+
+ if (m_audioOutput)
+ disconnect(m_audioOutput.get());
+ m_audioOutput = out;
+ if (m_audioOutput) {
+ connect(out, &QAudioOutput::volumeChanged, this, &QQnxMediaPlayer::setVolume);
+ connect(out, &QAudioOutput::mutedChanged, this, &QQnxMediaPlayer::setMuted);
+ }
+ setVolume(out ? out->volume() : 1.);
+ setMuted(out ? out->isMuted() : true);
+}
+
+float QQnxMediaPlayer::bufferProgress() const
+{
+ // mm-renderer has buffer properties "status" and "level"
+ // QMediaPlayer's buffer status maps to mm-renderer's buffer level
+ return m_bufferLevel/100.0f;
+}
+
+bool QQnxMediaPlayer::isAudioAvailable() const
+{
+ return m_metaData.hasAudio();
+}
+
+bool QQnxMediaPlayer::isVideoAvailable() const
+{
+ return m_metaData.hasVideo();
+}
+
+bool QQnxMediaPlayer::isSeekable() const
+{
+ return m_metaData.isSeekable();
+}
+
+QMediaTimeRange QQnxMediaPlayer::availablePlaybackRanges() const
+{
+ // We can't get this information from the mmrenderer API yet, so pretend we can seek everywhere
+ return QMediaTimeRange(0, m_metaData.duration());
+}
+
+qreal QQnxMediaPlayer::playbackRate() const
+{
+ return ::speedToRate(m_speed);
+}
+
+void QQnxMediaPlayer::setPlaybackRate(qreal rate)
+{
+ if (!m_context)
+ return;
+
+ const int speed = ::rateToSpeed(rate);
+
+ if (m_speed == speed)
+ return;
+
+ // defer setting the playback speed for when play() is called to prevent
+ // mm-renderer from inadvertently transitioning into play state
+ if (isDeferredSpeedEnabled() && state() != QMediaPlayer::PlayingState) {
+ m_deferredSpeed = speed;
+ return;
+ }
+
+ if (mmr_speed_set(m_context, speed) != 0)
+ emitMmError("mmr_speed_set failed");
+}
+
+QUrl QQnxMediaPlayer::media() const
+{
+ return m_media;
+}
+
+const QIODevice *QQnxMediaPlayer::mediaStream() const
+{
+ // Always 0, we don't support QIODevice streams
+ return 0;
+}
+
+void QQnxMediaPlayer::setMedia(const QUrl &media, QIODevice *stream)
+{
+ Q_UNUSED(stream); // not supported
+
+ stop();
+ detach();
+
+ stateChanged(QMediaPlayer::StoppedState);
+ mediaStatusChanged(QMediaPlayer::LoadingMedia);
+
+ m_media = media;
+
+ updateMetaData(nullptr);
+ attach();
+}
+
+void QQnxMediaPlayer::play()
+{
+ if (!m_media.isValid() || !m_connection || !m_context || m_audioId == -1) {
+ stateChanged(QMediaPlayer::StoppedState);
+ return;
+ }
+
+ if (state() == QMediaPlayer::PlayingState)
+ return;
+
+ setDeferredSpeedEnabled(false);
+
+ if (m_deferredSpeed) {
+ setPlaybackRate(::speedToRate(*m_deferredSpeed));
+ m_deferredSpeed = {};
+ } else {
+ setPlaybackRate(::speedToRate(m_configuredSpeed));
+ }
+
+ setDeferredSpeedEnabled(true);
+
+ // Un-pause the state when it is paused
+ if (state() == QMediaPlayer::PausedState) {
+ return;
+ }
+
+
+ if (mediaStatus() == QMediaPlayer::EndOfMedia)
+ setPositionInternal(0);
+
+ resetMonitoring();
+ updateVolume();
+
+ if (mmr_play(m_context) != 0) {
+ stateChanged(QMediaPlayer::StoppedState);
+ emitMmError("mmr_play() failed");
+ return;
+ }
+
+ stateChanged(QMediaPlayer::PlayingState);
+}
+
+void QQnxMediaPlayer::pause()
+{
+ if (state() != QMediaPlayer::PlayingState)
+ return;
+
+ setPlaybackRate(0);
+}
+
+void QQnxMediaPlayer::stop()
+{
+ if (!m_context
+ || state() == QMediaPlayer::StoppedState
+ || mediaStatus() == QMediaPlayer::NoMedia)
+ return;
+
+ // mm-renderer does not rewind by default
+ setPositionInternal(0);
+
+ mmr_stop(m_context);
+}
+
+void QQnxMediaPlayer::setVideoSink(QVideoSink *videoSink)
+{
+ m_platformVideoSink = videoSink
+ ? static_cast<QQnxVideoSink *>(videoSink->platformVideoSink())
+ : nullptr;
+}
+
+void QQnxMediaPlayer::startMonitoring()
+{
+ m_eventThread = new QQnxMediaEventThread(m_context);
+
+ connect(m_eventThread, &QQnxMediaEventThread::eventPending,
+ this, &QQnxMediaPlayer::readEvents);
+
+ m_eventThread->setObjectName(QStringLiteral("MmrEventThread-") + QString::number(m_id));
+ m_eventThread->start();
+}
+
+void QQnxMediaPlayer::stopMonitoring()
+{
+ delete m_eventThread;
+ m_eventThread = nullptr;
+}
+
+void QQnxMediaPlayer::resetMonitoring()
+{
+ m_bufferLevel = 0;
+ m_position = 0;
+ m_speed = 0;
+}
+
+void QQnxMediaPlayer::handleMmPositionChanged(qint64 newPosition)
+{
+ m_position = newPosition;
+
+ if (state() == QMediaPlayer::PausedState)
+ m_windowGrabber->forceUpdate();
+
+ positionChanged(m_position);
+}
+
+void QQnxMediaPlayer::updateBufferLevel(int level, int capacity)
+{
+ m_bufferLevel = capacity == 0 ? 0 : level / static_cast<float>(capacity) * 100.0f;
+ m_bufferLevel = qBound(0, m_bufferLevel, 100);
+ bufferProgressChanged(m_bufferLevel/100.0f);
+}
+
+void QQnxMediaPlayer::updateMetaData(const strm_dict *dict)
+{
+ m_metaData.update(dict);
+
+ durationChanged(m_metaData.duration());
+ audioAvailableChanged(m_metaData.hasAudio());
+ videoAvailableChanged(m_metaData.hasVideo());
+ seekableChanged(m_metaData.isSeekable());
+}
+
+void QQnxMediaPlayer::emitMmError(const char *msg)
+{
+ emitMmError(QString::fromUtf8(msg));
+}
+
+void QQnxMediaPlayer::emitMmError(const QString &msg)
+{
+ int errorCode = MMR_ERROR_NONE;
+ const QString errorMessage = mmErrorMessage(msg, m_context, &errorCode);
+ emit error(errorCode, errorMessage);
+}
+
+void QQnxMediaPlayer::emitPError(const QString &msg)
+{
+ const QString errorMessage = QString::fromLatin1("%1: %2").arg(msg).arg(QString::fromUtf8(strerror(errno)));
+ emit error(errno, errorMessage);
+}
+
+
+void QQnxMediaPlayer::readEvents()
+{
+ while (const mmr_event_t *event = mmr_event_get(m_context)) {
+ if (event->type == MMR_EVENT_NONE)
+ break;
+
+ switch (event->type) {
+ case MMR_EVENT_STATUS:
+ handleMmEventStatus(event);
+ break;
+ case MMR_EVENT_STATE:
+ handleMmEventState(event);
+ break;
+ case MMR_EVENT_METADATA:
+ updateMetaData(event->data);
+ break;
+ case MMR_EVENT_ERROR:
+ handleMmEventError(event);
+ break;
+ case MMR_EVENT_NONE:
+ case MMR_EVENT_OVERFLOW:
+ case MMR_EVENT_WARNING:
+ case MMR_EVENT_PLAYLIST:
+ case MMR_EVENT_INPUT:
+ case MMR_EVENT_OUTPUT:
+ case MMR_EVENT_CTXTPAR:
+ case MMR_EVENT_TRKPAR:
+ case MMR_EVENT_OTHER:
+ break;
+ }
+ }
+
+ if (m_eventThread)
+ m_eventThread->signalRead();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qqnxmediaplayer_p.cpp"
diff --git a/src/plugins/multimedia/qnx/mediaplayer/qqnxmediaplayer_p.h b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediaplayer_p.h
new file mode 100644
index 000000000..c570a6334
--- /dev/null
+++ b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediaplayer_p.h
@@ -0,0 +1,167 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QQnxMediaPlayer_H
+#define QQnxMediaPlayer_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qqnxmediametadata_p.h"
+#include "mmrenderertypes.h"
+
+#include <private/qplatformmediaplayer_p.h>
+#include <QtCore/qabstractnativeeventfilter.h>
+#include <QtCore/qpointer.h>
+#include <QtCore/qtimer.h>
+
+#include <mm/renderer.h>
+#include <mm/renderer/types.h>
+
+#include <optional>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxVideoSink;
+class QQnxMediaEventThread;
+class QQnxWindowGrabber;
+
+class QQnxMediaPlayer : public QObject
+ , public QPlatformMediaPlayer
+{
+ Q_OBJECT
+public:
+ explicit QQnxMediaPlayer(QMediaPlayer *parent = nullptr);
+ ~QQnxMediaPlayer();
+
+ qint64 duration() const override;
+
+ qint64 position() const override;
+ void setPosition(qint64 position) override;
+
+ void setAudioOutput(QPlatformAudioOutput *) override;
+
+ float bufferProgress() const override;
+
+ bool isAudioAvailable() const override;
+ bool isVideoAvailable() const override;
+
+ bool isSeekable() const override;
+
+ QMediaTimeRange availablePlaybackRanges() const override;
+
+ qreal playbackRate() const override;
+ void setPlaybackRate(qreal rate) override;
+
+ QUrl media() const override;
+ const QIODevice *mediaStream() const override;
+ void setMedia(const QUrl &media, QIODevice *stream) override;
+
+ void play() override;
+ void pause() override;
+ void stop() override;
+
+ void setVideoSink(QVideoSink *videoSink);
+
+private Q_SLOTS:
+ void setVolume(float volume);
+ void setMuted(bool muted);
+ void readEvents();
+
+private:
+ void startMonitoring();
+ void stopMonitoring();
+ void resetMonitoring();
+
+ void openConnection();
+ void emitMmError(const char *msg);
+ void emitMmError(const QString &msg);
+ void emitPError(const QString &msg);
+
+ void handleMmPositionChanged(qint64 newPosition);
+ void updateBufferLevel(int level, int capacity);
+ void updateMetaData(const strm_dict_t *dict);
+
+ void handleMmEventState(const mmr_event_t *event);
+ void handleMmEventStatus(const mmr_event_t *event);
+ void handleMmEventStatusData(const strm_dict_t *data);
+ void handleMmEventError(const mmr_event_t *event);
+
+ QByteArray resourcePathForUrl(const QUrl &url);
+
+ void closeConnection();
+ void attach();
+
+ bool attachVideoOutput();
+ bool attachAudioOutput();
+ bool attachInput();
+
+ void detach();
+ void detachVideoOutput();
+ void detachAudioOutput();
+ void detachInput();
+
+ bool isVideoOutputAttached() const;
+ bool isAudioOutputAttached() const;
+ bool isInputAttached() const;
+
+ void updateScene(const QSize &size);
+
+ void updateVolume();
+
+ void setPositionInternal(qint64 position);
+ void flushPosition();
+
+ bool isPendingPositionFlush() const;
+
+ void setDeferredSpeedEnabled(bool enabled);
+ bool isDeferredSpeedEnabled() const;
+
+ mmr_context_t *m_context = nullptr;
+ mmr_connection_t *m_connection = nullptr;
+
+ QString m_contextName;
+
+ int m_id = -1;
+ int m_audioId = -1;
+ int m_volume = 50; // range is 0-100
+
+ QUrl m_media;
+ QPointer<QAudioOutput> m_audioOutput;
+ QPointer<QQnxVideoSink> m_platformVideoSink;
+
+ QQnxMediaMetaData m_metaData;
+
+ qint64 m_position = 0;
+ qint64 m_pendingPosition = 0;
+
+ int m_bufferLevel = 0;
+
+ int m_videoId = -1;
+
+ QTimer m_flushPositionTimer;
+
+ QQnxMediaEventThread *m_eventThread = nullptr;
+
+ int m_speed = 1000;
+ int m_configuredSpeed = 1000;
+
+ std::optional<int> m_deferredSpeed;
+
+ QQnxWindowGrabber* m_windowGrabber = nullptr;
+
+ bool m_inputAttached = false;
+ bool m_muted = false;
+ bool m_deferredSpeedEnabled = false;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/mediaplayer/qqnxmediautil.cpp b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediautil.cpp
new file mode 100644
index 000000000..074989642
--- /dev/null
+++ b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediautil.cpp
@@ -0,0 +1,126 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qqnxmediautil_p.h"
+
+#include <QDebug>
+#include <QDir>
+#include <QFile>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonValue>
+#include <QMutex>
+#include <QMutex>
+#include <QString>
+#include <QXmlStreamReader>
+
+#include <mm/renderer.h>
+#include <mm/renderer/types.h>
+
+QT_BEGIN_NAMESPACE
+
+struct MmError {
+ int errorCode;
+ const char *name;
+};
+
+#define MM_ERROR_ENTRY(error) { error, #error }
+static const MmError mmErrors[] = {
+ MM_ERROR_ENTRY(MMR_ERROR_NONE),
+ MM_ERROR_ENTRY(MMR_ERROR_UNKNOWN ),
+ MM_ERROR_ENTRY(MMR_ERROR_INVALID_PARAMETER ),
+ MM_ERROR_ENTRY(MMR_ERROR_INVALID_STATE),
+ MM_ERROR_ENTRY(MMR_ERROR_UNSUPPORTED_VALUE),
+ MM_ERROR_ENTRY(MMR_ERROR_UNSUPPORTED_MEDIA_TYPE),
+ MM_ERROR_ENTRY(MMR_ERROR_MEDIA_PROTECTED),
+ MM_ERROR_ENTRY(MMR_ERROR_UNSUPPORTED_OPERATION),
+ MM_ERROR_ENTRY(MMR_ERROR_READ),
+ MM_ERROR_ENTRY(MMR_ERROR_WRITE),
+ MM_ERROR_ENTRY(MMR_ERROR_MEDIA_UNAVAILABLE),
+ MM_ERROR_ENTRY(MMR_ERROR_MEDIA_CORRUPTED),
+ MM_ERROR_ENTRY(MMR_ERROR_OUTPUT_UNAVAILABLE),
+ MM_ERROR_ENTRY(MMR_ERROR_NO_MEMORY),
+ MM_ERROR_ENTRY(MMR_ERROR_RESOURCE_UNAVAILABLE),
+ MM_ERROR_ENTRY(MMR_ERROR_MEDIA_DRM_NO_RIGHTS),
+ MM_ERROR_ENTRY(MMR_ERROR_DRM_CORRUPTED_DATA_STORE),
+ MM_ERROR_ENTRY(MMR_ERROR_DRM_OUTPUT_PROTECTION),
+ MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_HDMI),
+ MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_DISPLAYPORT),
+ MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_DVI),
+ MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_ANALOG_VIDEO),
+ MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_ANALOG_AUDIO),
+ MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_TOSLINK),
+ MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_SPDIF),
+ MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_BLUETOOTH),
+ MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_WIRELESSHD),
+};
+static const unsigned int numMmErrors = sizeof(mmErrors) / sizeof(MmError);
+
+template <typename T, size_t N>
+constexpr size_t countof(T (&)[N])
+{
+ return N;
+}
+
+QString keyValueMapsLocation()
+{
+ QByteArray qtKeyValueMaps = qgetenv("QT_KEY_VALUE_MAPS");
+ if (qtKeyValueMaps.isNull())
+ return QString::fromUtf8("/etc/qt/keyvaluemaps");
+ else
+ return QString::fromUtf8(qtKeyValueMaps);
+}
+
+QJsonObject loadMapObject(const QString &keyValueMapPath)
+{
+ QFile mapFile(keyValueMapsLocation() + keyValueMapPath);
+ if (mapFile.open(QIODevice::ReadOnly)) {
+ QByteArray mapFileContents = mapFile.readAll();
+ QJsonDocument mapDocument = QJsonDocument::fromJson(mapFileContents);
+ if (mapDocument.isObject()) {
+ QJsonObject mapObject = mapDocument.object();
+ return mapObject;
+ }
+ }
+ return QJsonObject();
+}
+
+QString mmErrorMessage(const QString &msg, mmr_context_t *context, int *errorCode)
+{
+ const mmr_error_info_t * const mmError = mmr_error_info(context);
+
+ if (errorCode)
+ *errorCode = mmError->error_code;
+
+ if (mmError->error_code < numMmErrors) {
+ return QString::fromLatin1("%1: %2 (code %3)").arg(msg).arg(QString::fromUtf8(mmErrors[mmError->error_code].name))
+ .arg(mmError->error_code);
+ } else {
+ return QString::fromLatin1("%1: Unknown error code %2").arg(msg).arg(mmError->error_code);
+ }
+}
+
+bool checkForDrmPermission()
+{
+ QDir sandboxDir = QDir::home(); // always returns 'data' directory
+ sandboxDir.cdUp(); // change to app sandbox directory
+
+ QFile file(sandboxDir.filePath(QString::fromUtf8("app/native/bar-descriptor.xml")));
+ if (!file.open(QIODevice::ReadOnly)) {
+ qWarning() << "checkForDrmPermission: Unable to open bar-descriptor.xml";
+ return false;
+ }
+
+ QXmlStreamReader reader(&file);
+ while (!reader.atEnd()) {
+ reader.readNextStartElement();
+ if (reader.name() == QLatin1String("action")
+ || reader.name() == QLatin1String("permission")) {
+ if (reader.readElementText().trimmed() == QLatin1String("access_protected_media"))
+ return true;
+ }
+ }
+
+ return false;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/qnx/mediaplayer/qqnxmediautil_p.h b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediautil_p.h
new file mode 100644
index 000000000..7b709142f
--- /dev/null
+++ b/src/plugins/multimedia/qnx/mediaplayer/qqnxmediautil_p.h
@@ -0,0 +1,32 @@
+// Copyright (C) 2016 Research In Motion
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef MMRENDERERUTIL_H
+#define MMRENDERERUTIL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+#include <QtMultimedia/qaudio.h>
+
+typedef struct mmr_context mmr_context_t;
+
+QT_BEGIN_NAMESPACE
+
+class QString;
+
+QString mmErrorMessage(const QString &msg, mmr_context_t *context, int * errorCode = 0);
+
+bool checkForDrmPermission();
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/mediaplayer/qqnxvideosink.cpp b/src/plugins/multimedia/qnx/mediaplayer/qqnxvideosink.cpp
new file mode 100644
index 000000000..18d4d1828
--- /dev/null
+++ b/src/plugins/multimedia/qnx/mediaplayer/qqnxvideosink.cpp
@@ -0,0 +1,26 @@
+// Copyright (C) 2016 Research In Motion
+// Copyright (C) 2021 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxvideosink_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QQnxVideoSink::QQnxVideoSink(QVideoSink *parent)
+ : QPlatformVideoSink(parent)
+{
+}
+
+void QQnxVideoSink::setRhi(QRhi *rhi)
+{
+ m_rhi = rhi;
+}
+
+QRhi *QQnxVideoSink::rhi() const
+{
+ return m_rhi;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qqnxvideosink_p.cpp"
diff --git a/src/plugins/multimedia/qnx/mediaplayer/qqnxvideosink_p.h b/src/plugins/multimedia/qnx/mediaplayer/qqnxvideosink_p.h
new file mode 100644
index 000000000..2cc7990db
--- /dev/null
+++ b/src/plugins/multimedia/qnx/mediaplayer/qqnxvideosink_p.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2016 Research In Motion
+// Copyright (C) 2021 The Qt Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QQNXVIDFEOSINK_P_H
+#define QQNXVIDFEOSINK_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformvideosink_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxWindowGrabber;
+class QVideoSink;
+
+class QQnxVideoSink : public QPlatformVideoSink
+{
+ Q_OBJECT
+public:
+ explicit QQnxVideoSink(QVideoSink *parent = 0);
+
+ void setRhi(QRhi *) override;
+
+ QRhi *rhi() const;
+
+private:
+ QRhi *m_rhi = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/qnx.json b/src/plugins/multimedia/qnx/qnx.json
new file mode 100644
index 000000000..38df228ef
--- /dev/null
+++ b/src/plugins/multimedia/qnx/qnx.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "qnx" ]
+}
diff --git a/src/plugins/multimedia/qnx/qqnxformatinfo.cpp b/src/plugins/multimedia/qnx/qqnxformatinfo.cpp
new file mode 100644
index 000000000..77492e80d
--- /dev/null
+++ b/src/plugins/multimedia/qnx/qqnxformatinfo.cpp
@@ -0,0 +1,36 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxformatinfo_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QQnxFormatInfo::QQnxFormatInfo()
+{
+ // ### This is probably somewhat correct for encoding, but should be checked
+ encoders = {
+ { QMediaFormat::MPEG4,
+ { QMediaFormat::AudioCodec::AAC },
+ { QMediaFormat::VideoCodec::H264 } },
+ { QMediaFormat::Mpeg4Audio,
+ { QMediaFormat::AudioCodec::AAC },
+ {} },
+ { QMediaFormat::Wave,
+ { QMediaFormat::AudioCodec::Wave },
+ {} },
+ { QMediaFormat::AAC,
+ { QMediaFormat::AudioCodec::AAC },
+ {} },
+ };
+
+ // ### There can apparently be more codecs and demuxers installed on the system as plugins
+ // Need to find a way to determine the list at compile time or runtime
+ decoders = encoders;
+
+ // ###
+ imageFormats << QImageCapture::JPEG;
+}
+
+QQnxFormatInfo::~QQnxFormatInfo() = default;
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/qnx/qqnxformatinfo_p.h b/src/plugins/multimedia/qnx/qqnxformatinfo_p.h
new file mode 100644
index 000000000..aae3a026a
--- /dev/null
+++ b/src/plugins/multimedia/qnx/qqnxformatinfo_p.h
@@ -0,0 +1,33 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQNXFORMATINFO_H
+#define QQNXFORMATINFO_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaformatinfo_p.h>
+#include <qhash.h>
+#include <qlist.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxFormatInfo : public QPlatformMediaFormatInfo
+{
+public:
+ QQnxFormatInfo();
+ ~QQnxFormatInfo();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/qqnxmediaintegration.cpp b/src/plugins/multimedia/qnx/qqnxmediaintegration.cpp
new file mode 100644
index 000000000..8567a69fd
--- /dev/null
+++ b/src/plugins/multimedia/qnx/qqnxmediaintegration.cpp
@@ -0,0 +1,79 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxmediaintegration_p.h"
+#include "qqnxmediacapturesession_p.h"
+#include "qqnxmediarecorder_p.h"
+#include "qqnxformatinfo_p.h"
+#include "qqnxvideodevices_p.h"
+#include "qqnxvideosink_p.h"
+#include "qqnxmediaplayer_p.h"
+#include "qqnximagecapture_p.h"
+#include "qqnxplatformcamera_p.h"
+#include <QtMultimedia/private/qplatformmediaplugin_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxMediaPlugin : public QPlatformMediaPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QPlatformMediaPlugin_iid FILE "qnx.json")
+
+public:
+ QQnxMediaPlugin()
+ : QPlatformMediaPlugin()
+ {}
+
+ QPlatformMediaIntegration* create(const QString &name) override
+ {
+ if (name == u"qnx")
+ return new QQnxMediaIntegration;
+ return nullptr;
+ }
+};
+
+QQnxMediaIntegration::QQnxMediaIntegration() : QPlatformMediaIntegration(QLatin1String("qnx")) { }
+
+QPlatformMediaFormatInfo *QQnxMediaIntegration::createFormatInfo()
+{
+ return new QQnxFormatInfo;
+}
+
+QPlatformVideoDevices *QQnxMediaIntegration::createVideoDevices()
+{
+ return new QQnxVideoDevices(this);
+}
+
+QMaybe<QPlatformVideoSink *> QQnxMediaIntegration::createVideoSink(QVideoSink *sink)
+{
+ return new QQnxVideoSink(sink);
+}
+
+QMaybe<QPlatformMediaPlayer *> QQnxMediaIntegration::createPlayer(QMediaPlayer *parent)
+{
+ return new QQnxMediaPlayer(parent);
+}
+
+QMaybe<QPlatformMediaCaptureSession *> QQnxMediaIntegration::createCaptureSession()
+{
+ return new QQnxMediaCaptureSession();
+}
+
+QMaybe<QPlatformMediaRecorder *> QQnxMediaIntegration::createRecorder(QMediaRecorder *parent)
+{
+ return new QQnxMediaRecorder(parent);
+}
+
+QMaybe<QPlatformCamera *> QQnxMediaIntegration::createCamera(QCamera *parent)
+{
+ return new QQnxPlatformCamera(parent);
+}
+
+QMaybe<QPlatformImageCapture *> QQnxMediaIntegration::createImageCapture(QImageCapture *parent)
+{
+ return new QQnxImageCapture(parent);
+}
+
+QT_END_NAMESPACE
+
+#include "qqnxmediaintegration.moc"
diff --git a/src/plugins/multimedia/qnx/qqnxmediaintegration_p.h b/src/plugins/multimedia/qnx/qqnxmediaintegration_p.h
new file mode 100644
index 000000000..60fafc246
--- /dev/null
+++ b/src/plugins/multimedia/qnx/qqnxmediaintegration_p.h
@@ -0,0 +1,50 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQnxMediaIntegration_H
+#define QQnxMediaIntegration_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxPlayerInterface;
+class QQnxFormatInfo;
+
+class QQnxMediaIntegration : public QPlatformMediaIntegration
+{
+public:
+ QQnxMediaIntegration();
+
+ QMaybe<QPlatformVideoSink *> createVideoSink(QVideoSink *sink) override;
+
+ QMaybe<QPlatformMediaPlayer *> createPlayer(QMediaPlayer *parent) override;
+
+ QMaybe<QPlatformMediaCaptureSession *> createCaptureSession() override;
+
+ QMaybe<QPlatformMediaRecorder *> createRecorder(QMediaRecorder *parent) override;
+
+ QMaybe<QPlatformCamera *> createCamera(QCamera *parent) override;
+
+ QMaybe<QPlatformImageCapture *> createImageCapture(QImageCapture *parent) override;
+
+protected:
+ QPlatformMediaFormatInfo *createFormatInfo() override;
+
+ QPlatformVideoDevices *createVideoDevices() override;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/qnx/qqnxvideodevices.cpp b/src/plugins/multimedia/qnx/qqnxvideodevices.cpp
new file mode 100644
index 000000000..ea0cfd956
--- /dev/null
+++ b/src/plugins/multimedia/qnx/qqnxvideodevices.cpp
@@ -0,0 +1,111 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qqnxvideodevices_p.h"
+#include "qqnxcamera_p.h"
+#include "private/qcameradevice_p.h"
+#include "qcameradevice.h"
+
+#include <qdir.h>
+#include <qdebug.h>
+
+#include <optional>
+
+QT_BEGIN_NAMESPACE
+
+static QVideoFrameFormat::PixelFormat fromCameraFrametype(camera_frametype_t type)
+{
+ switch (type) {
+ default:
+ case CAMERA_FRAMETYPE_UNSPECIFIED:
+ return QVideoFrameFormat::Format_Invalid;
+ case CAMERA_FRAMETYPE_NV12:
+ return QVideoFrameFormat::Format_NV12;
+ case CAMERA_FRAMETYPE_RGB8888:
+ return QVideoFrameFormat::Format_ARGB8888;
+ case CAMERA_FRAMETYPE_JPEG:
+ return QVideoFrameFormat::Format_Jpeg;
+ case CAMERA_FRAMETYPE_GRAY8:
+ return QVideoFrameFormat::Format_Y8;
+ case CAMERA_FRAMETYPE_CBYCRY:
+ return QVideoFrameFormat::Format_UYVY;
+ case CAMERA_FRAMETYPE_YCBCR420P:
+ return QVideoFrameFormat::Format_YUV420P;
+ case CAMERA_FRAMETYPE_YCBYCR:
+ return QVideoFrameFormat::Format_YUYV;
+ }
+}
+
+static std::optional<QCameraDevice> createCameraDevice(camera_unit_t unit, bool isDefault)
+{
+ const QQnxCamera camera(unit);
+
+ if (!camera.isValid()) {
+ qWarning() << "Invalid camera unit:" << unit;
+ return {};
+ }
+
+ auto *p = new QCameraDevicePrivate;
+
+ p->id = QByteArray::number(camera.unit());
+ p->description = camera.name();
+ p->isDefault = isDefault;
+
+ const QList<camera_frametype_t> frameTypes = camera.supportedVfFrameTypes();
+
+ for (camera_res_t res : camera.supportedVfResolutions()) {
+ const QSize resolution(res.width, res.height);
+
+ p->photoResolutions.append(resolution);
+
+ for (camera_frametype_t frameType : camera.supportedVfFrameTypes()) {
+ const QVideoFrameFormat::PixelFormat pixelFormat = fromCameraFrametype(frameType);
+
+ if (pixelFormat == QVideoFrameFormat::Format_Invalid)
+ continue;
+
+ auto *f = new QCameraFormatPrivate;
+ p->videoFormats.append(f->create());
+
+ f->resolution = resolution;
+ f->pixelFormat = pixelFormat;
+ f->minFrameRate = 1.e10;
+
+ for (double fr : camera.specifiedVfFrameRates(frameType, res)) {
+ if (fr < f->minFrameRate)
+ f->minFrameRate = fr;
+ if (fr > f->maxFrameRate)
+ f->maxFrameRate = fr;
+ }
+ }
+ }
+
+ return p->create();
+}
+
+QQnxVideoDevices::QQnxVideoDevices(QPlatformMediaIntegration *integration)
+ : QPlatformVideoDevices(integration)
+{
+}
+
+QList<QCameraDevice> QQnxVideoDevices::videoDevices() const
+{
+ QList<QCameraDevice> cameras;
+
+ bool isDefault = true;
+
+ for (const camera_unit_t cameraUnit : QQnxCamera::supportedUnits()) {
+ const std::optional<QCameraDevice> cameraDevice = createCameraDevice(cameraUnit, isDefault);
+
+ if (!cameraDevice)
+ continue;
+
+ cameras.append(*cameraDevice);
+
+ isDefault = false;
+ }
+
+ return cameras;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/qnx/qqnxvideodevices_p.h b/src/plugins/multimedia/qnx/qqnxvideodevices_p.h
new file mode 100644
index 000000000..cc2284e57
--- /dev/null
+++ b/src/plugins/multimedia/qnx/qqnxvideodevices_p.h
@@ -0,0 +1,32 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QQNXVIDEODEVICES_H
+#define QQNXVIDEODEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformvideodevices_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQnxVideoDevices : public QPlatformVideoDevices
+{
+public:
+ explicit QQnxVideoDevices(QPlatformMediaIntegration *integration);
+
+ QList<QCameraDevice> videoDevices() const override;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/wasm/CMakeLists.txt b/src/plugins/multimedia/wasm/CMakeLists.txt
new file mode 100644
index 000000000..21f3e3472
--- /dev/null
+++ b/src/plugins/multimedia/wasm/CMakeLists.txt
@@ -0,0 +1,25 @@
+qt_internal_add_plugin(QWasmMediaPlugin
+ OUTPUT_NAME wasmmediaplugin
+ PLUGIN_TYPE multimedia
+ SOURCES
+ qwasmmediaintegration.cpp qwasmmediaintegration_p.h
+ mediaplayer/qwasmmediaplayer.cpp mediaplayer/qwasmmediaplayer_p.h
+ mediaplayer/qwasmvideosink.cpp mediaplayer/qwasmvideosink_p.h
+ common/qwasmvideooutput.cpp common/qwasmvideooutput_p.h
+ common/qwasmaudiooutput.cpp common/qwasmaudiooutput_p.h
+ common/qwasmaudioinput.cpp common/qwasmaudioinput_p.h
+ mediacapture/qwasmmediacapturesession.cpp mediacapture/qwasmmediacapturesession_p.h
+ mediacapture/qwasmmediarecorder.cpp mediacapture/qwasmmediarecorder_p.h
+ mediacapture/qwasmcamera.cpp mediacapture/qwasmcamera_p.h
+ mediacapture/qwasmimagecapture.cpp mediacapture/qwasmimagecapture_p.h
+ INCLUDE_DIRECTORIES
+ common
+ mediaplayer
+ mediacapture
+ LIBRARIES
+ Qt::MultimediaPrivate
+ Qt::CorePrivate
+ openal
+)
+
+target_link_libraries(QWasmMediaPlugin PUBLIC embind)
diff --git a/src/plugins/multimedia/wasm/common/qwasmaudioinput.cpp b/src/plugins/multimedia/wasm/common/qwasmaudioinput.cpp
new file mode 100644
index 000000000..a0418c5c2
--- /dev/null
+++ b/src/plugins/multimedia/wasm/common/qwasmaudioinput.cpp
@@ -0,0 +1,107 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmaudioinput_p.h"
+
+#include <qaudioinput.h>
+#include <private/qstdweb_p.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(qWasmAudioInput, "qt.multimedia.wasm.audioinput")
+
+QWasmAudioInput::QWasmAudioInput(QAudioInput *parent)
+ : QObject(parent), QPlatformAudioInput(parent)
+{
+ m_wasMuted = false;
+ setDeviceSourceStream("");
+}
+
+QWasmAudioInput::~QWasmAudioInput()
+{
+}
+
+void QWasmAudioInput::setMuted(bool muted)
+{
+ qCDebug(qWasmAudioInput) << Q_FUNC_INFO << muted;
+ if (muted == m_wasMuted)
+ return;
+ if (m_mediaStream.isNull() || m_mediaStream.isUndefined())
+ return;
+ emscripten::val audioTracks = m_mediaStream.call<emscripten::val>("getAudioTracks");
+ if (audioTracks.isNull() || audioTracks.isUndefined())
+ return;
+ if (audioTracks["length"].as<int>() < 1)
+ return;
+ audioTracks[0].set("muted", muted);
+
+ emit mutedChanged(muted);
+ m_wasMuted = muted;
+
+}
+
+bool QWasmAudioInput::isMuted() const
+{
+ return m_wasMuted;
+}
+
+void QWasmAudioInput::setAudioDevice(const QAudioDevice &audioDevice)
+{
+ if (device == audioDevice)
+ return;
+
+ device = audioDevice;
+ setDeviceSourceStream(device.id().toStdString());
+}
+
+void QWasmAudioInput::setVolume(float volume)
+{
+ Q_UNUSED(volume)
+ // TODO seems no easy way to set input volume
+}
+
+void QWasmAudioInput::setDeviceSourceStream(const std::string &id)
+{
+ qCDebug(qWasmAudioInput) << Q_FUNC_INFO << id;
+ emscripten::val navigator = emscripten::val::global("navigator");
+ emscripten::val mediaDevices = navigator["mediaDevices"];
+
+ if (mediaDevices.isNull() || mediaDevices.isUndefined()) {
+ qWarning() << "No media devices found";
+ return;
+ }
+
+ qstdweb::PromiseCallbacks getUserMediaCallback{
+ // default
+ .thenFunc =
+ [this](emscripten::val stream) {
+ qCDebug(qWasmAudioInput) << "getUserMediaSuccess";
+ m_mediaStream = stream;
+ },
+ .catchFunc =
+ [](emscripten::val error) {
+ qCDebug(qWasmAudioInput)
+ << "addCameraSourceElement getUserMedia fail"
+ << QString::fromStdString(error["name"].as<std::string>())
+ << QString::fromStdString(error["message"].as<std::string>());
+ }
+ };
+
+ emscripten::val constraints = emscripten::val::object();
+ constraints.set("audio", true);
+ if (!id.empty())
+ constraints.set("deviceId", id);
+
+ // we do it this way as this prompts user for mic permissions
+ qstdweb::Promise::make(mediaDevices, QStringLiteral("getUserMedia"),
+ std::move(getUserMediaCallback), constraints);
+}
+
+emscripten::val QWasmAudioInput::mediaStream()
+{
+ return m_mediaStream;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwasmaudioinput_p.cpp"
diff --git a/src/plugins/multimedia/wasm/common/qwasmaudioinput_p.h b/src/plugins/multimedia/wasm/common/qwasmaudioinput_p.h
new file mode 100644
index 000000000..c772ee956
--- /dev/null
+++ b/src/plugins/multimedia/wasm/common/qwasmaudioinput_p.h
@@ -0,0 +1,57 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMAUDIOINPUT_H
+#define QWASMAUDIOINPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+#include <QtCore/qloggingcategory.h>
+
+#include <private/qtmultimediaglobal_p.h>
+#include <private/qplatformaudioinput_p.h>
+
+#include <emscripten.h>
+#include <emscripten/val.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qWasmAudioInput)
+
+class QWasmAudioInput : public QObject, public QPlatformAudioInput
+{
+ Q_OBJECT
+public:
+ explicit QWasmAudioInput(QAudioInput *parent);
+ ~QWasmAudioInput();
+
+ void setMuted(bool muted) override;
+ void setAudioDevice(const QAudioDevice & device) final;
+
+ bool isMuted() const;
+ void setVolume(float volume) final;
+ emscripten::val mediaStream();
+
+
+Q_SIGNALS:
+ void mutedChanged(bool muted);
+
+private:
+ bool m_wasMuted = false;
+ void setDeviceSourceStream(const std::string &id);
+ emscripten::val m_mediaStream;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMAUDIOINPUT_H
diff --git a/src/plugins/multimedia/wasm/common/qwasmaudiooutput.cpp b/src/plugins/multimedia/wasm/common/qwasmaudiooutput.cpp
new file mode 100644
index 000000000..a9a644140
--- /dev/null
+++ b/src/plugins/multimedia/wasm/common/qwasmaudiooutput.cpp
@@ -0,0 +1,378 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <qaudiodevice.h>
+#include <qaudiooutput.h>
+#include <qwasmaudiooutput_p.h>
+
+#include <QMimeDatabase>
+#include <QtCore/qloggingcategory.h>
+#include <QMediaDevices>
+#include <QUrl>
+#include <QFile>
+#include <QMimeDatabase>
+#include <QFileInfo>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qWasmMediaAudioOutput, "qt.multimedia.wasm.audiooutput")
+
+QWasmAudioOutput::QWasmAudioOutput(QAudioOutput *parent)
+ : QPlatformAudioOutput(parent)
+{
+}
+
+QWasmAudioOutput::~QWasmAudioOutput() = default;
+
+void QWasmAudioOutput::setAudioDevice(const QAudioDevice &audioDevice)
+{
+ qCDebug(qWasmMediaAudioOutput) << Q_FUNC_INFO << device.id();
+ device = audioDevice;
+}
+
+void QWasmAudioOutput::setVideoElement(emscripten::val videoElement)
+{
+ m_videoElement = videoElement;
+}
+
+emscripten::val QWasmAudioOutput::videoElement()
+{
+ return m_videoElement;
+}
+
+void QWasmAudioOutput::setMuted(bool muted)
+{
+ emscripten::val realElement = videoElement();
+ if (!realElement.isUndefined()) {
+ realElement.set("muted", muted);
+ return;
+ }
+ if (m_audio.isUndefined() || m_audio.isNull()) {
+ qCDebug(qWasmMediaAudioOutput) << "Error"
+ << "Audio element could not be created";
+ emit errorOccured(QMediaPlayer::ResourceError,
+ QStringLiteral("Media file could not be opened"));
+ return;
+ }
+ m_audio.set("mute", muted);
+}
+
+void QWasmAudioOutput::setVolume(float volume)
+{
+ volume = qBound(qreal(0.0), volume, qreal(1.0));
+ emscripten::val realElement = videoElement();
+ if (!realElement.isUndefined()) {
+ realElement.set("volume", volume);
+ return;
+ }
+ if (m_audio.isUndefined() || m_audio.isNull()) {
+ qCDebug(qWasmMediaAudioOutput) << "Error"
+ << "Audio element not available";
+ emit errorOccured(QMediaPlayer::ResourceError,
+ QStringLiteral("Media file could not be opened"));
+ return;
+ }
+
+ m_audio.set("volume", volume);
+}
+
+void QWasmAudioOutput::setSource(const QUrl &url)
+{
+ qCDebug(qWasmMediaAudioOutput) << Q_FUNC_INFO << url;
+ if (url.isEmpty()) {
+ stop();
+ return;
+ }
+
+ createAudioElement(device.id().toStdString());
+
+ if (m_audio.isUndefined() || m_audio.isNull()) {
+ qCDebug(qWasmMediaAudioOutput) << "Error"
+ << "Audio element could not be created";
+ emit errorOccured(QMediaPlayer::ResourceError,
+ QStringLiteral("Audio element could not be created"));
+ return;
+ }
+
+ emscripten::val document = emscripten::val::global("document");
+ emscripten::val body = document["body"];
+
+ m_audio.set("id", device.id().toStdString());
+
+ body.call<void>("appendChild", m_audio);
+
+
+ if (url.isLocalFile()) { // is localfile
+ qCDebug(qWasmMediaAudioOutput) << "is localfile";
+ m_source = url.toLocalFile();
+
+ QFile mediaFile(m_source);
+ if (!mediaFile.open(QIODevice::ReadOnly)) {
+ qCDebug(qWasmMediaAudioOutput) << "Error"
+ << "Media file could not be opened";
+ emit errorOccured(QMediaPlayer::ResourceError,
+ QStringLiteral("Media file could not be opened"));
+ return;
+ }
+
+ // local files are relatively small due to browser filesystem being restricted
+ QByteArray content = mediaFile.readAll();
+
+ QMimeDatabase db;
+ qCDebug(qWasmMediaAudioOutput) << db.mimeTypeForData(content).name();
+
+ qstdweb::Blob contentBlob = qstdweb::Blob::copyFrom(content.constData(), content.size());
+ emscripten::val contentUrl =
+ qstdweb::window()["URL"].call<emscripten::val>("createObjectURL", contentBlob.val());
+
+ emscripten::val audioSourceElement =
+ document.call<emscripten::val>("createElement", std::string("source"));
+
+ audioSourceElement.set("src", contentUrl);
+
+ // work around Safari not being able to read audio from blob URLs.
+ QFileInfo info(m_source);
+ QMimeType mimeType = db.mimeTypeForFile(info);
+
+ audioSourceElement.set("type", mimeType.name().toStdString());
+ m_audio.call<void>("appendChild", audioSourceElement);
+
+ m_audio.call<void>("setAttribute", emscripten::val("srcObject"), contentUrl);
+
+ } else {
+ m_source = url.toString();
+ m_audio.set("src", m_source.toStdString());
+ }
+ m_audio.set("id", device.id().toStdString());
+
+ body.call<void>("appendChild", m_audio);
+ qCDebug(qWasmMediaAudioOutput) << Q_FUNC_INFO << device.id();
+
+ doElementCallbacks();
+}
+
+void QWasmAudioOutput::setSource(QIODevice *stream)
+{
+ m_audioIODevice = stream;
+}
+
+void QWasmAudioOutput::start()
+{
+ if (m_audio.isNull() || m_audio.isUndefined()) {
+ qCDebug(qWasmMediaAudioOutput) << "audio failed to start";
+ emit errorOccured(QMediaPlayer::ResourceError,
+ QStringLiteral("Audio element resource error"));
+ return;
+ }
+
+ m_audio.call<void>("play");
+}
+
+void QWasmAudioOutput::stop()
+{
+ if (m_audio.isNull() || m_audio.isUndefined()) {
+ qCDebug(qWasmMediaAudioOutput) << "audio failed to start";
+ emit errorOccured(QMediaPlayer::ResourceError,
+ QStringLiteral("Audio element resource error"));
+ return;
+ }
+ if (!m_source.isEmpty()) {
+ pause();
+ m_audio.set("currentTime", emscripten::val(0));
+ }
+ if (m_audioIODevice) {
+ m_audioIODevice->close();
+ delete m_audioIODevice;
+ m_audioIODevice = 0;
+ }
+}
+
+void QWasmAudioOutput::pause()
+{
+ if (m_audio.isNull() || m_audio.isUndefined()) {
+ qCDebug(qWasmMediaAudioOutput) << "audio failed to start";
+ emit errorOccured(QMediaPlayer::ResourceError,
+ QStringLiteral("Audio element resource error"));
+ return;
+ }
+ m_audio.call<emscripten::val>("pause");
+}
+
+void QWasmAudioOutput::createAudioElement(const std::string &id)
+{
+ emscripten::val document = emscripten::val::global("document");
+ m_audio = document.call<emscripten::val>("createElement", std::string("audio"));
+
+ // only works in chrome and firefox.
+ // Firefox this feature is behind media.setsinkid.enabled preferences
+ // allows user to choose audio output device
+
+ if (!m_audio.hasOwnProperty("sinkId") || m_audio["sinkId"].isUndefined()) {
+ return;
+ }
+
+ std::string usableId = id;
+ if (usableId.empty())
+ usableId = QMediaDevices::defaultAudioOutput().id();
+
+ qstdweb::PromiseCallbacks sinkIdCallbacks{
+ .thenFunc = [](emscripten::val) { qCWarning(qWasmMediaAudioOutput) << "setSinkId ok"; },
+ .catchFunc =
+ [](emscripten::val) {
+ qCWarning(qWasmMediaAudioOutput) << "Error while trying to setSinkId";
+ }
+ };
+ qstdweb::Promise::make(m_audio, "setSinkId", std::move(sinkIdCallbacks), std::move(usableId));
+
+ m_audio.set("id", usableId.c_str());
+}
+
+void QWasmAudioOutput::doElementCallbacks()
+{
+ // error
+ auto errorCallback = [&](emscripten::val event) {
+ qCDebug(qWasmMediaAudioOutput) << "error";
+ if (event.isUndefined() || event.isNull())
+ return;
+ emit errorOccured(m_audio["error"]["code"].as<int>(),
+ QString::fromStdString(m_audio["error"]["message"].as<std::string>()));
+
+ QString errorMessage =
+ QString::fromStdString(m_audio["error"]["message"].as<std::string>());
+ if (errorMessage.isEmpty()) {
+ switch (m_audio["error"]["code"].as<int>()) {
+ case AudioElementError::MEDIA_ERR_ABORTED:
+ errorMessage = QStringLiteral("aborted by the user agent at the user's request.");
+ break;
+ case AudioElementError::MEDIA_ERR_NETWORK:
+ errorMessage = QStringLiteral("network error.");
+ break;
+ case AudioElementError::MEDIA_ERR_DECODE:
+ errorMessage = QStringLiteral("decoding error.");
+ break;
+ case AudioElementError::MEDIA_ERR_SRC_NOT_SUPPORTED:
+ errorMessage = QStringLiteral("src attribute not suitable.");
+ break;
+ };
+ }
+ qCDebug(qWasmMediaAudioOutput) << m_audio["error"]["code"].as<int>() << errorMessage;
+
+ emit errorOccured(m_audio["error"]["code"].as<int>(), errorMessage);
+ };
+ m_errorChangeEvent.reset(new qstdweb::EventCallback(m_audio, "error", errorCallback));
+
+ // loadeddata
+ auto loadedDataCallback = [&](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaAudioOutput) << "loaded data";
+ qstdweb::window()["URL"].call<emscripten::val>("revokeObjectURL", m_audio["src"]);
+ };
+ m_loadedDataEvent.reset(new qstdweb::EventCallback(m_audio, "loadeddata", loadedDataCallback));
+
+ // canplay
+ auto canPlayCallback = [&](emscripten::val event) {
+ if (event.isUndefined() || event.isNull())
+ return;
+ qCDebug(qWasmMediaAudioOutput) << "can play";
+ emit readyChanged(true);
+ emit stateChanged(QWasmMediaPlayer::Preparing);
+ };
+ m_canPlayChangeEvent.reset(new qstdweb::EventCallback(m_audio, "canplay", canPlayCallback));
+
+ // canplaythrough
+ auto canPlayThroughCallback = [&](emscripten::val event) {
+ Q_UNUSED(event)
+ emit stateChanged(QWasmMediaPlayer::Prepared);
+ };
+ m_canPlayThroughChangeEvent.reset(
+ new qstdweb::EventCallback(m_audio, "canplaythrough", canPlayThroughCallback));
+
+ // play
+ auto playCallback = [&](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaAudioOutput) << "play";
+ emit stateChanged(QWasmMediaPlayer::Started);
+ };
+ m_playEvent.reset(new qstdweb::EventCallback(m_audio, "play", playCallback));
+
+ // durationchange
+ auto durationChangeCallback = [&](emscripten::val event) {
+ qCDebug(qWasmMediaAudioOutput) << "durationChange";
+
+ // duration in ms
+ emit durationChanged(event["target"]["duration"].as<double>() * 1000);
+ };
+ m_durationChangeEvent.reset(
+ new qstdweb::EventCallback(m_audio, "durationchange", durationChangeCallback));
+
+ // ended
+ auto endedCallback = [&](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaAudioOutput) << "ended";
+ m_currentMediaStatus = QMediaPlayer::EndOfMedia;
+ emit statusChanged(m_currentMediaStatus);
+ };
+ m_endedEvent.reset(new qstdweb::EventCallback(m_audio, "ended", endedCallback));
+
+ // progress (buffering progress)
+ auto progesssCallback = [&](emscripten::val event) {
+ if (event.isUndefined() || event.isNull())
+ return;
+ qCDebug(qWasmMediaAudioOutput) << "progress";
+ float duration = event["target"]["duration"].as<int>();
+ if (duration < 0) // track not exactly ready yet
+ return;
+
+ emscripten::val timeRanges = event["target"]["buffered"];
+
+ if ((!timeRanges.isNull() || !timeRanges.isUndefined())
+ && timeRanges["length"].as<int>() == 1) {
+ emscripten::val dVal = timeRanges.call<emscripten::val>("end", 0);
+
+ if (!dVal.isNull() || !dVal.isUndefined()) {
+ double bufferedEnd = dVal.as<double>();
+
+ if (duration > 0 && bufferedEnd > 0) {
+ float bufferedValue = (bufferedEnd / duration * 100);
+ qCDebug(qWasmMediaAudioOutput) << "progress buffered" << bufferedValue;
+
+ emit bufferingChanged(m_currentBufferedValue);
+ if (bufferedEnd == duration)
+ m_currentMediaStatus = QMediaPlayer::BufferedMedia;
+ else
+ m_currentMediaStatus = QMediaPlayer::BufferingMedia;
+
+ emit statusChanged(m_currentMediaStatus);
+ }
+ }
+ }
+ };
+ m_progressChangeEvent.reset(new qstdweb::EventCallback(m_audio, "progress", progesssCallback));
+
+ // timupdate
+ auto timeUpdateCallback = [&](emscripten::val event) {
+ qCDebug(qWasmMediaAudioOutput)
+ << "timeupdate" << (event["target"]["currentTime"].as<double>() * 1000);
+
+ // qt progress is ms
+ emit progressChanged(event["target"]["currentTime"].as<double>() * 1000);
+ };
+ m_timeUpdateEvent.reset(new qstdweb::EventCallback(m_audio, "timeupdate", timeUpdateCallback));
+
+ // pause
+ auto pauseCallback = [&](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaAudioOutput) << "pause";
+
+ int currentTime = m_audio["currentTime"].as<int>(); // in seconds
+ int duration = m_audio["duration"].as<int>(); // in seconds
+ if ((currentTime > 0 && currentTime < duration)) {
+ emit stateChanged(QWasmMediaPlayer::Paused);
+ } else {
+ emit stateChanged(QWasmMediaPlayer::Stopped);
+ }
+ };
+ m_pauseChangeEvent.reset(new qstdweb::EventCallback(m_audio, "pause", pauseCallback));
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/wasm/common/qwasmaudiooutput_p.h b/src/plugins/multimedia/wasm/common/qwasmaudiooutput_p.h
new file mode 100644
index 000000000..69fda120b
--- /dev/null
+++ b/src/plugins/multimedia/wasm/common/qwasmaudiooutput_p.h
@@ -0,0 +1,97 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMAUDIOOUTPUT_H
+#define QWASMAUDIOOUTPUT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformaudiooutput_p.h>
+#include "qwasmmediaplayer_p.h"
+
+#include <emscripten/val.h>
+#include <private/qstdweb_p.h>
+#include <private/qwasmaudiosink_p.h>
+#include <QIODevice>
+#include <QObject>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIA_EXPORT QWasmAudioOutput : public QObject, public QPlatformAudioOutput
+{
+ Q_OBJECT
+
+public:
+ QWasmAudioOutput(QAudioOutput *qq);
+ ~QWasmAudioOutput();
+
+ enum AudioElementError {
+ MEDIA_ERR_ABORTED = 1,
+ MEDIA_ERR_NETWORK,
+ MEDIA_ERR_DECODE,
+ MEDIA_ERR_SRC_NOT_SUPPORTED
+ };
+
+ void setAudioDevice(const QAudioDevice &device) final;
+ void setMuted(bool muted) override;
+ void setVolume(float volume) override;
+
+ void start();
+ void stop();
+ void pause();
+
+ void setSource(const QUrl &url);
+ void setSource(QIODevice *stream);
+ void setVideoElement(emscripten::val videoElement);
+
+Q_SIGNALS:
+ void readyChanged(bool);
+ void bufferingChanged(qint32 percent);
+ void errorOccured(qint32 code, const QString &message);
+ void stateChanged(QWasmMediaPlayer::QWasmMediaPlayerState newState);
+ void progressChanged(qint32 position);
+ void durationChanged(qint64 duration);
+ void statusChanged(QMediaPlayer::MediaStatus status);
+ void sizeChange(qint32 width, qint32 height);
+ void metaDataLoaded();
+
+private:
+ void doElementCallbacks();
+ void createAudioElement(const std::string &id);
+
+ emscripten::val videoElement();
+
+ QScopedPointer<QWasmAudioSink> m_sink;
+ QScopedPointer<qstdweb::EventCallback> m_playEvent;
+ QScopedPointer<qstdweb::EventCallback> m_endedEvent;
+ QScopedPointer<qstdweb::EventCallback> m_durationChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_errorChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_canPlayChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_canPlayThroughChangeEvent;
+
+ QScopedPointer<qstdweb::EventCallback> m_playingChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_progressChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_pauseChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_timeUpdateEvent;
+ QScopedPointer<qstdweb::EventCallback> m_loadedDataEvent;
+
+ QString m_source;
+ QIODevice *m_audioIODevice = nullptr;
+ emscripten::val m_audio = emscripten::val::undefined();
+ emscripten::val m_videoElement = emscripten::val::undefined();
+ QMediaPlayer::MediaStatus m_currentMediaStatus;
+ qreal m_currentBufferedValue;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMAUDIOOUTPUT_H
diff --git a/src/plugins/multimedia/wasm/common/qwasmvideooutput.cpp b/src/plugins/multimedia/wasm/common/qwasmvideooutput.cpp
new file mode 100644
index 000000000..84d325635
--- /dev/null
+++ b/src/plugins/multimedia/wasm/common/qwasmvideooutput.cpp
@@ -0,0 +1,1071 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <QDebug>
+#include <QUrl>
+#include <QPoint>
+#include <QRect>
+#include <QMediaPlayer>
+#include <QVideoFrame>
+#include <QFile>
+#include <QBuffer>
+#include <QMimeDatabase>
+#include "qwasmvideooutput_p.h"
+
+#include <qvideosink.h>
+#include <private/qplatformvideosink_p.h>
+#include <private/qmemoryvideobuffer_p.h>
+#include <private/qvideotexturehelper_p.h>
+#include <private/qvideoframe_p.h>
+#include <private/qstdweb_p.h>
+#include <QTimer>
+
+#include <emscripten/bind.h>
+#include <emscripten/html5.h>
+#include <emscripten/val.h>
+
+
+QT_BEGIN_NAMESPACE
+
+
+using namespace emscripten;
+
+Q_LOGGING_CATEGORY(qWasmMediaVideoOutput, "qt.multimedia.wasm.videooutput")
+
+// TODO unique videosurface ?
+static std::string m_videoSurfaceId;
+
+void qtVideoBeforeUnload(emscripten::val event)
+{
+ Q_UNUSED(event)
+ // large videos will leave the unloading window
+ // in a frozen state, so remove the video element first
+ emscripten::val document = emscripten::val::global("document");
+ emscripten::val videoElement =
+ document.call<emscripten::val>("getElementById", std::string(m_videoSurfaceId));
+ videoElement.call<void>("removeAttribute", emscripten::val("src"));
+ videoElement.call<void>("load");
+}
+
+EMSCRIPTEN_BINDINGS(video_module)
+{
+ emscripten::function("mbeforeUnload", qtVideoBeforeUnload);
+}
+
+static bool checkForVideoFrame()
+{
+ emscripten::val videoFrame = emscripten::val::global("VideoFrame");
+ return (!videoFrame.isNull() && !videoFrame.isUndefined());
+}
+
+QWasmVideoOutput::QWasmVideoOutput(QObject *parent) : QObject{ parent }
+{
+ m_hasVideoFrame = checkForVideoFrame();
+}
+
+void QWasmVideoOutput::setVideoSize(const QSize &newSize)
+{
+ if (m_pendingVideoSize == newSize)
+ return;
+
+ m_pendingVideoSize = newSize;
+ updateVideoElementGeometry(QRect(0, 0, m_pendingVideoSize.width(), m_pendingVideoSize.height()));
+}
+
+void QWasmVideoOutput::setVideoMode(QWasmVideoOutput::WasmVideoMode mode)
+{
+ m_currentVideoMode = mode;
+}
+
+void QWasmVideoOutput::start()
+{
+ if (m_video.isUndefined() || m_video.isNull()
+ || !m_wasmSink) {
+ // error
+ emit errorOccured(QMediaPlayer::ResourceError, QStringLiteral("video surface error"));
+ return;
+ }
+
+ switch (m_currentVideoMode) {
+ case QWasmVideoOutput::VideoOutput: {
+ emscripten::val sourceObj = m_video["src"];
+ if ((sourceObj.isUndefined() || sourceObj.isNull()) && !m_source.isEmpty()) {
+ qCDebug(qWasmMediaVideoOutput) << Q_FUNC_INFO << "calling load" << m_source;
+ m_video.set("src", m_source);
+ m_video.call<void>("load");
+ }
+ } break;
+ case QWasmVideoOutput::Camera: {
+ if (!m_cameraIsReady) {
+ m_shouldBeStarted = true;
+ }
+
+ emscripten::val stream = m_video["srcObject"];
+ if (stream.isNull() || stream.isUndefined()) { // camera device
+ qCDebug(qWasmMediaVideoOutput) << "ERROR";
+ emit errorOccured(QMediaPlayer::ResourceError, QStringLiteral("video surface error"));
+ return;
+ } else {
+ emscripten::val videoTracks = stream.call<emscripten::val>("getVideoTracks");
+ if (videoTracks.isNull() || videoTracks.isUndefined()) {
+ qCDebug(qWasmMediaVideoOutput) << Q_FUNC_INFO << "videoTracks is null";
+ emit errorOccured(QMediaPlayer::ResourceError,
+ QStringLiteral("video surface error"));
+ return;
+ }
+ if (videoTracks["length"].as<int>() == 0) {
+ qCDebug(qWasmMediaVideoOutput) << Q_FUNC_INFO << "videoTracks count is 0";
+ emit errorOccured(QMediaPlayer::ResourceError,
+ QStringLiteral("video surface error"));
+ return;
+ }
+ emscripten::val videoSettings = videoTracks[0].call<emscripten::val>("getSettings");
+ if (!videoSettings.isNull() || !videoSettings.isUndefined()) {
+ // double fRate = videoSettings["frameRate"].as<double>(); TODO
+ const int width = videoSettings["width"].as<int>();
+ const int height = videoSettings["height"].as<int>();
+
+ qCDebug(qWasmMediaVideoOutput)
+ << "width" << width << "height" << height;
+
+ updateVideoElementGeometry(QRect(0, 0, width, height));
+ }
+ }
+ } break;
+ };
+
+ m_shouldStop = false;
+ m_toBePaused = false;
+ m_video.call<void>("play");
+
+ if (m_currentVideoMode == QWasmVideoOutput::Camera) {
+ if (m_hasVideoFrame) {
+ m_video.call<emscripten::val>("requestVideoFrameCallback",
+ emscripten::val::module_property("qtVideoFrameTimerCallback"));
+ } else {
+ videoFrameTimerCallback();
+ }
+ }
+}
+
+void QWasmVideoOutput::stop()
+{
+ qCDebug(qWasmMediaVideoOutput) << Q_FUNC_INFO;
+
+ if (m_video.isUndefined() || m_video.isNull()) {
+ // error
+ emit errorOccured(QMediaPlayer::ResourceError, QStringLiteral("Resource error"));
+ return;
+ }
+ m_shouldStop = true;
+ if (m_toBePaused) {
+ // we are stopped , need to reset
+ m_toBePaused = false;
+ m_video.call<void>("load");
+ } else {
+ m_video.call<void>("pause");
+ }
+}
+
+void QWasmVideoOutput::pause()
+{
+ qCDebug(qWasmMediaVideoOutput) << Q_FUNC_INFO;
+
+ if (m_video.isUndefined() || m_video.isNull()) {
+ // error
+ emit errorOccured(QMediaPlayer::ResourceError, QStringLiteral("video surface error"));
+ return;
+ }
+ m_shouldStop = false;
+ m_toBePaused = true;
+ m_video.call<void>("pause");
+}
+
+void QWasmVideoOutput::reset()
+{
+ // flush pending frame
+ if (m_wasmSink)
+ m_wasmSink->platformVideoSink()->setVideoFrame(QVideoFrame());
+
+ m_source = "";
+ m_video.set("currentTime", emscripten::val(0));
+ m_video.call<void>("load");
+}
+
+emscripten::val QWasmVideoOutput::surfaceElement()
+{
+ return m_video;
+}
+
+void QWasmVideoOutput::setSurface(QVideoSink *surface)
+{
+ if (!surface || surface == m_wasmSink) {
+ qWarning() << "Surface not ready";
+ return;
+ }
+
+ m_wasmSink = surface;
+}
+
+bool QWasmVideoOutput::isReady() const
+{
+ if (m_video.isUndefined() || m_video.isNull()) {
+ // error
+ return false;
+ }
+
+ constexpr int hasCurrentData = 2;
+ if (!m_video.isUndefined() || !m_video.isNull())
+ return m_video["readyState"].as<int>() >= hasCurrentData;
+ else
+ return true;
+}
+
+void QWasmVideoOutput::setSource(const QUrl &url)
+{
+ qCDebug(qWasmMediaVideoOutput) << Q_FUNC_INFO << url;
+
+ if (m_video.isUndefined() || m_video.isNull()) {
+ return;
+ }
+
+ m_source = url.toString();
+ if (url.isEmpty()) {
+ stop();
+ return;
+ }
+ if (url.isLocalFile()) {
+ QFile localFile(url.toLocalFile());
+ if (localFile.open(QIODevice::ReadOnly)) {
+ QDataStream buffer(&localFile); // we will serialize the data into the file
+ setSource(buffer.device());
+ } else {
+ qWarning() << "Failed to open file";
+ }
+ return;
+ }
+
+ updateVideoElementSource(m_source);
+}
+
+void QWasmVideoOutput::updateVideoElementSource(const QString &src)
+{
+ m_video.set("src", src.toStdString());
+ m_video.call<void>("load");
+}
+
+void QWasmVideoOutput::addCameraSourceElement(const std::string &id)
+{
+ m_cameraIsReady = false;
+ emscripten::val navigator = emscripten::val::global("navigator");
+ emscripten::val mediaDevices = navigator["mediaDevices"];
+
+ if (mediaDevices.isNull() || mediaDevices.isUndefined()) {
+ qWarning() << "No media devices found";
+ emit errorOccured(QMediaPlayer::ResourceError, QStringLiteral("Resource error"));
+ return;
+ }
+
+ qstdweb::PromiseCallbacks getUserMediaCallback{
+ .thenFunc =
+ [this](emscripten::val stream) {
+ qCDebug(qWasmMediaVideoOutput) << "getUserMediaSuccess";
+
+ m_video.set("srcObject", stream);
+ m_cameraIsReady = true;
+ if (m_shouldBeStarted) {
+ start();
+ m_shouldBeStarted = false;
+ }
+ },
+ .catchFunc =
+ [](emscripten::val error) {
+ qCDebug(qWasmMediaVideoOutput)
+ << "getUserMedia fail"
+ << QString::fromStdString(error["name"].as<std::string>())
+ << QString::fromStdString(error["message"].as<std::string>());
+ }
+ };
+
+ emscripten::val constraints = emscripten::val::object();
+
+ constraints.set("audio", m_hasAudio);
+
+ emscripten::val videoContraints = emscripten::val::object();
+ videoContraints.set("exact", id);
+ videoContraints.set("deviceId", id);
+ constraints.set("video", videoContraints);
+
+ // we do it this way as this prompts user for mic/camera permissions
+ qstdweb::Promise::make(mediaDevices, QStringLiteral("getUserMedia"),
+ std::move(getUserMediaCallback), constraints);
+}
+
+void QWasmVideoOutput::setSource(QIODevice *stream)
+{
+ if (stream->bytesAvailable() == 0) {
+ qWarning() << "data not available";
+ emit errorOccured(QMediaPlayer::ResourceError, QStringLiteral("data not available"));
+ return;
+ }
+ if (m_video.isUndefined() || m_video.isNull()) {
+ emit errorOccured(QMediaPlayer::ResourceError, QStringLiteral("video surface error"));
+ return;
+ }
+
+ QMimeDatabase db;
+ QMimeType mime = db.mimeTypeForData(stream);
+
+ QByteArray buffer = stream->readAll();
+
+ qstdweb::Blob contentBlob = qstdweb::Blob::copyFrom(buffer.data(), buffer.size(), mime.name().toStdString());
+
+ emscripten::val window = qstdweb::window();
+
+ if (window["safari"].isUndefined()) {
+ emscripten::val contentUrl = window["URL"].call<emscripten::val>("createObjectURL", contentBlob.val());
+ m_video.set("src", contentUrl);
+ m_source = QString::fromStdString(contentUrl.as<std::string>());
+ } else {
+ // only Safari currently supports Blob with srcObject
+ m_video.set("srcObject", contentBlob.val());
+ }
+}
+
+void QWasmVideoOutput::setVolume(qreal volume)
+{ // between 0 - 1
+ volume = qBound(qreal(0.0), volume, qreal(1.0));
+ m_video.set("volume", volume);
+}
+
+void QWasmVideoOutput::setMuted(bool muted)
+{
+ if (m_video.isUndefined() || m_video.isNull()) {
+ // error
+ emit errorOccured(QMediaPlayer::ResourceError, QStringLiteral("video surface error"));
+ return;
+ }
+ m_video.set("muted", muted);
+}
+
+qint64 QWasmVideoOutput::getCurrentPosition()
+{
+ return (!m_video.isUndefined() || !m_video.isNull())
+ ? (m_video["currentTime"].as<double>() * 1000)
+ : 0;
+}
+
+void QWasmVideoOutput::seekTo(qint64 positionMSecs)
+{
+ if (isVideoSeekable()) {
+ float positionToSetInSeconds = float(positionMSecs) / 1000;
+ emscripten::val seekableTimeRange = m_video["seekable"];
+ if (!seekableTimeRange.isNull() || !seekableTimeRange.isUndefined()) {
+ // range user can seek
+ if (seekableTimeRange["length"].as<int>() < 1)
+ return;
+ if (positionToSetInSeconds
+ >= seekableTimeRange.call<emscripten::val>("start", 0).as<double>()
+ && positionToSetInSeconds
+ <= seekableTimeRange.call<emscripten::val>("end", 0).as<double>()) {
+ m_requestedPosition = positionToSetInSeconds;
+
+ m_video.set("currentTime", m_requestedPosition);
+ }
+ }
+ }
+ qCDebug(qWasmMediaVideoOutput) << "m_requestedPosition" << m_requestedPosition;
+}
+
+bool QWasmVideoOutput::isVideoSeekable()
+{
+ if (m_video.isUndefined() || m_video.isNull()) {
+ // error
+ emit errorOccured(QMediaPlayer::ResourceError, QStringLiteral("video surface error"));
+ return false;
+ }
+
+ emscripten::val seekableTimeRange = m_video["seekable"];
+ if (seekableTimeRange["length"].as<int>() < 1)
+ return false;
+ if (!seekableTimeRange.isNull() || !seekableTimeRange.isUndefined()) {
+ bool isit = !qFuzzyCompare(seekableTimeRange.call<emscripten::val>("start", 0).as<double>(),
+ seekableTimeRange.call<emscripten::val>("end", 0).as<double>());
+ return isit;
+ }
+ return false;
+}
+
+void QWasmVideoOutput::createVideoElement(const std::string &id)
+{
+ // TODO: there can be more than one element !!
+ qCDebug(qWasmMediaVideoOutput) << Q_FUNC_INFO << id;
+ // Create <video> element and add it to the page body
+ emscripten::val document = emscripten::val::global("document");
+ emscripten::val body = document["body"];
+
+ emscripten::val oldVideo = document.call<emscripten::val>("getElementsByClassName",
+ (m_currentVideoMode == QWasmVideoOutput::Camera
+ ? std::string("Camera")
+ : std::string("Video")));
+
+ // we don't provide alternate tracks
+ // but need to remove stale track
+ if (oldVideo["length"].as<int>() > 0)
+ oldVideo[0].call<void>("remove");
+
+ m_videoSurfaceId = id;
+ m_video = document.call<emscripten::val>("createElement", std::string("video"));
+
+ m_video.set("id", m_videoSurfaceId.c_str());
+ m_video.call<void>("setAttribute", std::string("class"),
+ (m_currentVideoMode == QWasmVideoOutput::Camera ? std::string("Camera")
+ : std::string("Video")));
+ m_video.set("data-qvideocontext",
+ emscripten::val(quintptr(reinterpret_cast<void *>(this))));
+
+ // if video
+ m_video.set("preload", "metadata");
+
+ // Uncaught DOMException: Failed to execute 'getImageData' on
+ // 'OffscreenCanvasRenderingContext2D': The canvas has been tainted by
+ // cross-origin data.
+ // TODO figure out somehow to let user choose between these
+ std::string originString = "anonymous"; // requires server Access-Control-Allow-Origin *
+ // std::string originString = "use-credentials"; // must not
+ // Access-Control-Allow-Origin *
+
+ m_video.call<void>("setAttribute", std::string("crossorigin"), originString);
+ body.call<void>("appendChild", m_video);
+
+ // Create/add video source
+ document.call<emscripten::val>("createElement",
+ std::string("source")).set("src", m_source.toStdString());
+
+ // Set position:absolute, which makes it possible to position the video
+ // element using x,y. coordinates, relative to its parent (the page's <body>
+ // element)
+ emscripten::val style = m_video["style"];
+ style.set("position", "absolute");
+ style.set("display", "none"); // hide
+
+ if (!m_source.isEmpty())
+ updateVideoElementSource(m_source);
+}
+
+void QWasmVideoOutput::createOffscreenElement(const QSize &offscreenSize)
+{
+ qCDebug(qWasmMediaVideoOutput) << Q_FUNC_INFO;
+
+ if (m_hasVideoFrame) // VideoFrame does not require offscreen canvas/context
+ return;
+
+ // create offscreen element for grabbing frames
+ // OffscreenCanvas - no safari :(
+ // https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
+
+ emscripten::val document = emscripten::val::global("document");
+
+ // TODO use correct frameBytesAllocationSize?
+ // offscreen render buffer
+ m_offscreen = emscripten::val::global("OffscreenCanvas");
+
+ if (m_offscreen.isUndefined()) {
+ // Safari OffscreenCanvas not supported, try old skool way
+ m_offscreen = document.call<emscripten::val>("createElement", std::string("canvas"));
+
+ m_offscreen.set("style",
+ "position:absolute;left:-1000px;top:-1000px"); // offscreen
+ m_offscreen.set("width", offscreenSize.width());
+ m_offscreen.set("height", offscreenSize.height());
+ m_offscreenContext = m_offscreen.call<emscripten::val>("getContext", std::string("2d"));
+ } else {
+ m_offscreen = emscripten::val::global("OffscreenCanvas")
+ .new_(offscreenSize.width(), offscreenSize.height());
+ emscripten::val offscreenAttributes = emscripten::val::array();
+ offscreenAttributes.set("willReadFrequently", true);
+ m_offscreenContext = m_offscreen.call<emscripten::val>("getContext", std::string("2d"),
+ offscreenAttributes);
+ }
+ std::string offscreenId = m_videoSurfaceId + "_offscreenOutputSurface";
+ m_offscreen.set("id", offscreenId.c_str());
+}
+
+void QWasmVideoOutput::doElementCallbacks()
+{
+ qCDebug(qWasmMediaVideoOutput) << Q_FUNC_INFO;
+
+ // event callbacks
+ // timupdate
+ auto timeUpdateCallback = [=](emscripten::val event) {
+ qCDebug(qWasmMediaVideoOutput) << "timeupdate";
+
+ // qt progress is ms
+ emit progressChanged(event["target"]["currentTime"].as<double>() * 1000);
+ };
+ m_timeUpdateEvent.reset(new qstdweb::EventCallback(m_video, "timeupdate", timeUpdateCallback));
+
+ // play
+ auto playCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "play" << m_video["src"].as<std::string>();
+ if (!m_isSeeking)
+ emit stateChanged(QWasmMediaPlayer::Preparing);
+ };
+ m_playEvent.reset(new qstdweb::EventCallback(m_video, "play", playCallback));
+
+ // ended
+ auto endedCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "ended";
+ m_currentMediaStatus = QMediaPlayer::EndOfMedia;
+ emit statusChanged(m_currentMediaStatus);
+ m_shouldStop = true;
+ stop();
+ };
+ m_endedEvent.reset(new qstdweb::EventCallback(m_video, "ended", endedCallback));
+
+ // durationchange
+ auto durationChangeCallback = [=](emscripten::val event) {
+ qCDebug(qWasmMediaVideoOutput) << "durationChange";
+
+ // qt duration is in milliseconds.
+ qint64 dur = event["target"]["duration"].as<double>() * 1000;
+ emit durationChanged(dur);
+ };
+ m_durationChangeEvent.reset(
+ new qstdweb::EventCallback(m_video, "durationchange", durationChangeCallback));
+
+ // loadeddata
+ auto loadedDataCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "loaded data";
+
+ emit stateChanged(QWasmMediaPlayer::Prepared);
+ };
+ m_loadedDataEvent.reset(new qstdweb::EventCallback(m_video, "loadeddata", loadedDataCallback));
+
+ // error
+ auto errorCallback = [=](emscripten::val event) {
+ qCDebug(qWasmMediaVideoOutput) << "error";
+ if (event.isUndefined() || event.isNull())
+ return;
+ emit errorOccured(m_video["error"]["code"].as<int>(),
+ QString::fromStdString(m_video["error"]["message"].as<std::string>()));
+ };
+ m_errorChangeEvent.reset(new qstdweb::EventCallback(m_video, "error", errorCallback));
+
+ // resize
+ auto resizeCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "resize";
+
+ updateVideoElementGeometry(
+ QRect(0, 0, m_video["videoWidth"].as<int>(), m_video["videoHeight"].as<int>()));
+ emit sizeChange(m_video["videoWidth"].as<int>(), m_video["videoHeight"].as<int>());
+
+ };
+ m_resizeChangeEvent.reset(new qstdweb::EventCallback(m_video, "resize", resizeCallback));
+
+ // loadedmetadata
+ auto loadedMetadataCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "loaded meta data";
+
+ emit metaDataLoaded();
+ };
+ m_loadedMetadataChangeEvent.reset(
+ new qstdweb::EventCallback(m_video, "loadedmetadata", loadedMetadataCallback));
+
+ // loadstart
+ auto loadStartCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "load started";
+ m_currentMediaStatus = QMediaPlayer::LoadingMedia;
+ emit statusChanged(m_currentMediaStatus);
+ m_shouldStop = false;
+ };
+ m_loadStartChangeEvent.reset(new qstdweb::EventCallback(m_video, "loadstart", loadStartCallback));
+
+ // canplay
+
+ auto canPlayCallback = [=](emscripten::val event) {
+ if (event.isUndefined() || event.isNull())
+ return;
+ qCDebug(qWasmMediaVideoOutput) << "can play"
+ << "m_requestedPosition" << m_requestedPosition;
+
+ if (!m_shouldStop)
+ emit readyChanged(true); // sets video available
+ };
+ m_canPlayChangeEvent.reset(new qstdweb::EventCallback(m_video, "canplay", canPlayCallback));
+
+ // canplaythrough
+ auto canPlayThroughCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "can play through"
+ << "m_shouldStop" << m_shouldStop;
+
+ if (m_currentMediaStatus == QMediaPlayer::EndOfMedia)
+ return;
+ if (!m_isSeeking && !m_shouldStop) {
+ emscripten::val timeRanges = m_video["buffered"];
+ if ((!timeRanges.isNull() || !timeRanges.isUndefined())
+ && timeRanges["length"].as<int>() == 1) {
+ double buffered = m_video["buffered"].call<emscripten::val>("end", 0).as<double>();
+ const double duration = m_video["duration"].as<double>();
+
+ if (duration == buffered) {
+ m_currentBufferedValue = 100;
+ emit bufferingChanged(m_currentBufferedValue);
+ }
+ }
+ m_currentMediaStatus = QMediaPlayer::LoadedMedia;
+ emit statusChanged(m_currentMediaStatus);
+ if (m_hasVideoFrame) {
+ m_video.call<emscripten::val>("requestVideoFrameCallback",
+ emscripten::val::module_property("qtVideoFrameTimerCallback"));
+ } else {
+ videoFrameTimerCallback();
+ }
+ } else {
+ m_shouldStop = false;
+ }
+ };
+ m_canPlayThroughChangeEvent.reset(
+ new qstdweb::EventCallback(m_video, "canplaythrough", canPlayThroughCallback));
+
+ // seeking
+ auto seekingCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput)
+ << "seeking started" << (m_video["currentTime"].as<double>() * 1000);
+ m_isSeeking = true;
+ };
+ m_seekingChangeEvent.reset(new qstdweb::EventCallback(m_video, "seeking", seekingCallback));
+
+ // seeked
+ auto seekedCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "seeked" << (m_video["currentTime"].as<double>() * 1000);
+ emit progressChanged(m_video["currentTime"].as<double>() * 1000);
+ m_isSeeking = false;
+ };
+ m_seekedChangeEvent.reset(new qstdweb::EventCallback(m_video, "seeked", seekedCallback));
+
+ // emptied
+ auto emptiedCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "emptied";
+ emit readyChanged(false);
+ m_currentMediaStatus = QMediaPlayer::EndOfMedia;
+ emit statusChanged(m_currentMediaStatus);
+ };
+ m_emptiedChangeEvent.reset(new qstdweb::EventCallback(m_video, "emptied", emptiedCallback));
+
+ // stalled
+ auto stalledCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "stalled";
+ m_currentMediaStatus = QMediaPlayer::StalledMedia;
+ emit statusChanged(m_currentMediaStatus);
+ };
+ m_stalledChangeEvent.reset(new qstdweb::EventCallback(m_video, "stalled", stalledCallback));
+
+ // waiting
+ auto waitingCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+
+ qCDebug(qWasmMediaVideoOutput) << "waiting";
+ // check buffer
+ };
+ m_waitingChangeEvent.reset(new qstdweb::EventCallback(m_video, "waiting", waitingCallback));
+
+ // suspend
+
+ // playing
+ auto playingCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "playing";
+ if (m_isSeeking)
+ return;
+ emit stateChanged(QWasmMediaPlayer::Started);
+ if (m_toBePaused || !m_shouldStop) { // paused
+ m_toBePaused = false;
+
+ if (m_hasVideoFrame) {
+ m_video.call<emscripten::val>("requestVideoFrameCallback",
+ emscripten::val::module_property("qtVideoFrameTimerCallback"));
+ } else {
+ videoFrameTimerCallback(); // get the ball rolling
+ }
+ }
+ };
+ m_playingChangeEvent.reset(new qstdweb::EventCallback(m_video, "playing", playingCallback));
+
+ // progress (buffering progress)
+ auto progesssCallback = [=](emscripten::val event) {
+ if (event.isUndefined() || event.isNull())
+ return;
+
+ const double duration = event["target"]["duration"].as<double>();
+ if (duration < 0) // track not exactly ready yet
+ return;
+
+ emscripten::val timeRanges = event["target"]["buffered"];
+
+ if ((!timeRanges.isNull() || !timeRanges.isUndefined())
+ && timeRanges["length"].as<int>() == 1) {
+ emscripten::val dVal = timeRanges.call<emscripten::val>("end", 0);
+ if (!dVal.isNull() || !dVal.isUndefined()) {
+ double bufferedEnd = dVal.as<double>();
+
+ if (duration > 0 && bufferedEnd > 0) {
+ const double bufferedValue = (bufferedEnd / duration * 100);
+ qCDebug(qWasmMediaVideoOutput) << "progress buffered";
+ m_currentBufferedValue = bufferedValue;
+ emit bufferingChanged(m_currentBufferedValue);
+ if (bufferedEnd == duration)
+ m_currentMediaStatus = QMediaPlayer::BufferedMedia;
+ else
+ m_currentMediaStatus = QMediaPlayer::BufferingMedia;
+ emit statusChanged(m_currentMediaStatus);
+ }
+ }
+ }
+ };
+ m_progressChangeEvent.reset(new qstdweb::EventCallback(m_video, "progress", progesssCallback));
+
+ // pause
+ auto pauseCallback = [=](emscripten::val event) {
+ Q_UNUSED(event)
+ qCDebug(qWasmMediaVideoOutput) << "pause";
+
+ const double currentTime = m_video["currentTime"].as<double>(); // in seconds
+ const double duration = m_video["duration"].as<double>(); // in seconds
+ if ((currentTime > 0 && currentTime < duration) && (!m_shouldStop && m_toBePaused)) {
+ emit stateChanged(QWasmMediaPlayer::Paused);
+ } else {
+ // stop this crazy thing!
+ m_video.set("currentTime", emscripten::val(0));
+ emit stateChanged(QWasmMediaPlayer::Stopped);
+ }
+ };
+ m_pauseChangeEvent.reset(new qstdweb::EventCallback(m_video, "pause", pauseCallback));
+
+ // onunload
+ // we use lower level events here as to avert a crash on activate using the
+ // qtdweb see _qt_beforeUnload
+ emscripten::val window = emscripten::val::global("window");
+ window.call<void>("addEventListener", std::string("beforeunload"),
+ emscripten::val::module_property("mbeforeUnload"));
+}
+
+void QWasmVideoOutput::updateVideoElementGeometry(const QRect &windowGeometry)
+{
+ qCDebug(qWasmMediaVideoOutput) << Q_FUNC_INFO << windowGeometry;
+ QRect m_videoElementSource(windowGeometry.topLeft(), windowGeometry.size());
+
+ emscripten::val style = m_video["style"];
+ style.set("left", QString("%1px").arg(m_videoElementSource.left()).toStdString());
+ style.set("top", QString("%1px").arg(m_videoElementSource.top()).toStdString());
+ style.set("width", QString("%1px").arg(m_videoElementSource.width()).toStdString());
+ style.set("height", QString("%1px").arg(m_videoElementSource.height()).toStdString());
+ style.set("z-index", "999");
+
+ if (!m_hasVideoFrame) {
+ // offscreen
+ m_offscreen.set("width", m_videoElementSource.width());
+ m_offscreen.set("height", m_videoElementSource.height());
+ }
+}
+
+qint64 QWasmVideoOutput::getDuration()
+{
+ // qt duration is in ms
+ // js is sec
+
+ if (m_video.isUndefined() || m_video.isNull())
+ return 0;
+ return m_video["duration"].as<double>() * 1000;
+}
+
+void QWasmVideoOutput::newFrame(const QVideoFrame &frame)
+{
+ m_wasmSink->setVideoFrame(frame);
+}
+
+void QWasmVideoOutput::setPlaybackRate(qreal rate)
+{
+ m_video.set("playbackRate", emscripten::val(rate));
+}
+
+qreal QWasmVideoOutput::playbackRate()
+{
+ return (m_video.isUndefined() || m_video.isNull()) ? 0 : m_video["playbackRate"].as<float>();
+}
+
+void QWasmVideoOutput::checkNetworkState()
+{
+ int netState = m_video["networkState"].as<int>();
+
+ qCDebug(qWasmMediaVideoOutput) << netState;
+
+ switch (netState) {
+ case QWasmMediaPlayer::QWasmMediaNetworkState::NetworkEmpty: // no data
+ break;
+ case QWasmMediaPlayer::QWasmMediaNetworkState::NetworkIdle:
+ break;
+ case QWasmMediaPlayer::QWasmMediaNetworkState::NetworkLoading:
+ break;
+ case QWasmMediaPlayer::QWasmMediaNetworkState::NetworkNoSource: // no source
+ emit errorOccured(netState, QStringLiteral("No media source found"));
+ break;
+ };
+}
+
+void QWasmVideoOutput::videoComputeFrame(void *context)
+{
+ if (m_offscreenContext.isUndefined() || m_offscreenContext.isNull()) {
+ qCDebug(qWasmMediaVideoOutput) << "offscreen canvas context could not be found";
+ return;
+ }
+ emscripten::val document = emscripten::val::global("document");
+
+ emscripten::val videoElement =
+ document.call<emscripten::val>("getElementById", std::string(m_videoSurfaceId));
+
+ if (videoElement.isUndefined() || videoElement.isNull()) {
+ qCDebug(qWasmMediaVideoOutput) << "video element could not be found";
+ return;
+ }
+
+ const int videoWidth = videoElement["videoWidth"].as<int>();
+ const int videoHeight = videoElement["videoHeight"].as<int>();
+
+ if (videoWidth == 0 || videoHeight == 0)
+ return;
+
+ m_offscreenContext.call<void>("drawImage", videoElement, 0, 0, videoWidth, videoHeight);
+
+ emscripten::val frame = // one frame, Uint8ClampedArray
+ m_offscreenContext.call<emscripten::val>("getImageData", 0, 0, videoWidth, videoHeight);
+
+ const QSize frameBytesAllocationSize(videoWidth, videoHeight);
+
+ // this seems to work ok, even though getImageData returns a Uint8ClampedArray
+ QByteArray frameBytes = qstdweb::Uint8Array(frame["data"]).copyToQByteArray();
+
+ QVideoFrameFormat frameFormat =
+ QVideoFrameFormat(frameBytesAllocationSize, QVideoFrameFormat::Format_RGBA8888);
+
+ auto *textureDescription = QVideoTextureHelper::textureDescription(frameFormat.pixelFormat());
+
+ QVideoFrame vFrame = QVideoFramePrivate::createFrame(
+ std::make_unique<QMemoryVideoBuffer>(
+ std::move(frameBytes),
+ textureDescription->strideForWidth(frameFormat.frameWidth())),
+ frameFormat);
+ QWasmVideoOutput *wasmVideoOutput = reinterpret_cast<QWasmVideoOutput *>(context);
+
+ if (!wasmVideoOutput->m_wasmSink) {
+ qWarning() << "ERROR ALERT!! video sink not set";
+ }
+ wasmVideoOutput->m_wasmSink->setVideoFrame(vFrame);
+}
+
+
+void QWasmVideoOutput::videoFrameCallback(emscripten::val now, emscripten::val metadata)
+{
+ Q_UNUSED(now)
+ Q_UNUSED(metadata)
+
+ emscripten::val videoElement =
+ emscripten::val::global("document").
+ call<emscripten::val>("getElementById",
+ std::string(m_videoSurfaceId));
+
+ emscripten::val oneVideoFrame = val::global("VideoFrame").new_(videoElement);
+
+ if (oneVideoFrame.isNull() || oneVideoFrame.isUndefined()) {
+ qCDebug(qWasmMediaVideoOutput) << Q_FUNC_INFO
+ << "ERROR" << "failed to construct VideoFrame";
+ return;
+ }
+ emscripten::val frameBytesAllocationSize = oneVideoFrame.call<emscripten::val>("allocationSize");
+
+ emscripten::val frameBuffer =
+ emscripten::val::global("Uint8Array").new_(frameBytesAllocationSize);
+ QWasmVideoOutput *wasmVideoOutput =
+ reinterpret_cast<QWasmVideoOutput*>(videoElement["data-qvideocontext"].as<quintptr>());
+
+ qstdweb::PromiseCallbacks copyToCallback;
+ copyToCallback.thenFunc = [wasmVideoOutput, oneVideoFrame, frameBuffer, videoElement]
+ (emscripten::val frameLayout)
+ {
+ if (frameLayout.isNull() || frameLayout.isUndefined()) {
+ qCDebug(qWasmMediaVideoOutput) << "theres no frameLayout";
+ return;
+ }
+
+ // frameBuffer now has a new frame, send to Qt
+ const QSize frameSize(oneVideoFrame["displayWidth"].as<int>(),
+ oneVideoFrame["displayHeight"].as<int>());
+
+
+ QByteArray frameBytes = QByteArray::fromEcmaUint8Array(frameBuffer);
+
+ QVideoFrameFormat::PixelFormat pixelFormat = fromJsPixelFormat(oneVideoFrame["format"].as<std::string>());
+ if (pixelFormat == QVideoFrameFormat::Format_Invalid) {
+ qWarning() << "Invalid pixel format";
+ return;
+ }
+ QVideoFrameFormat frameFormat = QVideoFrameFormat(frameSize, pixelFormat);
+
+ auto *textureDescription = QVideoTextureHelper::textureDescription(frameFormat.pixelFormat());
+
+ auto buffer = std::make_unique<QMemoryVideoBuffer>(
+ std::move(frameBytes),
+ textureDescription->strideForWidth(frameFormat.frameWidth()));
+
+ QVideoFrame vFrame =
+ QVideoFramePrivate::createFrame(std::move(buffer), std::move(frameFormat));
+
+ if (!wasmVideoOutput) {
+ qCDebug(qWasmMediaVideoOutput) << "ERROR:"
+ << "data-qvideocontext not found";
+ return;
+ }
+ if (!wasmVideoOutput->m_wasmSink) {
+ qWarning() << "ERROR ALERT!! video sink not set";
+ return;
+ }
+ wasmVideoOutput->m_wasmSink->setVideoFrame(vFrame);
+ oneVideoFrame.call<emscripten::val>("close");
+ };
+ copyToCallback.catchFunc = [&, wasmVideoOutput, oneVideoFrame, videoElement](emscripten::val error)
+ {
+ qCDebug(qWasmMediaVideoOutput) << "Error"
+ << QString::fromStdString(error["name"].as<std::string>())
+ << QString::fromStdString(error["message"].as<std::string>()) ;
+
+ oneVideoFrame.call<emscripten::val>("close");
+ wasmVideoOutput->stop();
+ return;
+ };
+
+ qstdweb::Promise::make(oneVideoFrame, "copyTo", std::move(copyToCallback), frameBuffer);
+
+ videoElement.call<emscripten::val>("requestVideoFrameCallback",
+ emscripten::val::module_property("qtVideoFrameTimerCallback"));
+
+}
+
+void QWasmVideoOutput::videoFrameTimerCallback()
+{
+ static auto frame = [](double frameTime, void *context) -> int {
+ Q_UNUSED(frameTime);
+ QWasmVideoOutput *videoOutput = reinterpret_cast<QWasmVideoOutput *>(context);
+
+ emscripten::val document = emscripten::val::global("document");
+ emscripten::val videoElement =
+ document.call<emscripten::val>("getElementById", std::string(m_videoSurfaceId));
+
+ if (videoElement["paused"].as<bool>() || videoElement["ended"].as<bool>())
+ return false;
+
+ videoOutput->videoComputeFrame(context);
+
+ return true;
+ };
+
+ emscripten_request_animation_frame_loop(frame, this);
+ // about 60 fps
+}
+
+
+QVideoFrameFormat::PixelFormat QWasmVideoOutput::fromJsPixelFormat(std::string videoFormat)
+{
+ if (videoFormat == "I420")
+ return QVideoFrameFormat::Format_YUV420P;
+ // no equivalent pixel format
+ // else if (videoFormat == "I420A")
+ else if (videoFormat == "I422")
+ return QVideoFrameFormat::Format_YUV422P;
+ // no equivalent pixel format
+ // else if (videoFormat == "I444")
+ else if (videoFormat == "NV12")
+ return QVideoFrameFormat::Format_NV12;
+ else if (videoFormat == "RGBA")
+ return QVideoFrameFormat::Format_RGBA8888;
+ else if (videoFormat == "I420")
+ return QVideoFrameFormat::Format_YUV420P;
+ else if (videoFormat == "RGBX")
+ return QVideoFrameFormat::Format_RGBX8888;
+ else if (videoFormat == "BGRA")
+ return QVideoFrameFormat::Format_BGRA8888;
+ else if (videoFormat == "BGRX")
+ return QVideoFrameFormat::Format_BGRX8888;
+
+ return QVideoFrameFormat::Format_Invalid;
+}
+
+
+emscripten::val QWasmVideoOutput::getDeviceCapabilities()
+{
+ emscripten::val stream = m_video["srcObject"];
+ if (!stream.isUndefined() || !stream["getVideoTracks"].isUndefined()) {
+ emscripten::val tracks = stream.call<emscripten::val>("getVideoTracks");
+ if (!tracks.isUndefined()) {
+ if (tracks["length"].as<int>() == 0)
+ return emscripten::val::undefined();
+
+ emscripten::val track = tracks[0];
+ if (!track.isUndefined()) {
+ emscripten::val trackCaps = emscripten::val::undefined();
+ if (!track["getCapabilities"].isUndefined())
+ trackCaps = track.call<emscripten::val>("getCapabilities");
+ else // firefox does not support getCapabilities
+ trackCaps = track.call<emscripten::val>("getSettings");
+
+ if (!trackCaps.isUndefined())
+ return trackCaps;
+ }
+ }
+ } else {
+ // camera not started track capabilities not available
+ emit errorOccured(QMediaPlayer::ResourceError, QStringLiteral("capabilities not available"));
+ }
+
+ return emscripten::val::undefined();
+}
+
+bool QWasmVideoOutput::setDeviceSetting(const std::string &key, emscripten::val value)
+{
+ emscripten::val stream = m_video["srcObject"];
+ if (stream.isNull() || stream.isUndefined()
+ || stream["getVideoTracks"].isUndefined())
+ return false;
+
+ emscripten::val tracks = stream.call<emscripten::val>("getVideoTracks");
+ if (!tracks.isNull() || !tracks.isUndefined()) {
+ if (tracks["length"].as<int>() == 0)
+ return false;
+
+ emscripten::val track = tracks[0];
+ emscripten::val contraint = emscripten::val::object();
+ contraint.set(std::move(key), value);
+ track.call<emscripten::val>("applyConstraints", contraint);
+ return true;
+ }
+
+ return false;
+}
+
+EMSCRIPTEN_BINDINGS(qtwasmvideooutput) {
+ emscripten::function("qtVideoFrameTimerCallback", &QWasmVideoOutput::videoFrameCallback);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwasmvideooutput_p.cpp"
diff --git a/src/plugins/multimedia/wasm/common/qwasmvideooutput_p.h b/src/plugins/multimedia/wasm/common/qwasmvideooutput_p.h
new file mode 100644
index 000000000..f078ffb44
--- /dev/null
+++ b/src/plugins/multimedia/wasm/common/qwasmvideooutput_p.h
@@ -0,0 +1,153 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QWASMVIDEOOUTPUT_H
+#define QWASMVIDEOOUTPUT_H
+
+#include <QObject>
+
+#include <emscripten/val.h>
+#include <QMediaPlayer>
+#include <QVideoFrame>
+
+#include "qwasmmediaplayer_p.h"
+#include <QtCore/qloggingcategory.h>
+
+#include <private/qstdweb_p.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qWasmMediaVideoOutput)
+
+class QVideoSink;
+
+class QWasmVideoOutput : public QObject
+{
+ Q_OBJECT
+public:
+ enum WasmVideoMode { VideoOutput, Camera };
+ Q_ENUM(WasmVideoMode)
+
+ explicit QWasmVideoOutput(QObject *parent = nullptr);
+
+ void setVideoSize(const QSize &);
+ void start();
+ void stop();
+ void reset();
+ void pause();
+
+ void setSurface(QVideoSink *surface);
+ emscripten::val surfaceElement();
+
+ bool isReady() const;
+
+ void setSource(const QUrl &url);
+ void setSource(QIODevice *stream);
+ void setVolume(qreal volume);
+ void setMuted(bool muted);
+
+ qint64 getCurrentPosition();
+ void seekTo(qint64 position);
+ bool isVideoSeekable();
+ void setPlaybackRate(qreal rate);
+ qreal playbackRate();
+
+ qint64 getDuration();
+ void newFrame(const QVideoFrame &newFrame);
+
+ void createVideoElement(const std::string &id);
+ void createOffscreenElement(const QSize &offscreenSize);
+ void doElementCallbacks();
+ void updateVideoElementGeometry(const QRect &windowGeometry);
+ void updateVideoElementSource(const QString &src);
+ void addCameraSourceElement(const std::string &id);
+ void removeSourceElement();
+ void setVideoMode(QWasmVideoOutput::WasmVideoMode mode);
+
+ void setHasAudio(bool needsAudio) { m_hasAudio = needsAudio; }
+
+ bool hasCapability(const QString &cap);
+ emscripten::val getDeviceCapabilities();
+ bool setDeviceSetting(const std::string &key, emscripten::val value);
+ bool isCameraReady() { return m_cameraIsReady; }
+ bool m_hasVideoFrame = false;
+
+ static void videoFrameCallback(emscripten::val now, emscripten::val metadata);
+ void videoFrameTimerCallback();
+ // mediacapturesession has the videosink
+ QVideoSink *m_wasmSink = nullptr;
+
+ emscripten::val currentVideoElement() { return m_video; }
+
+Q_SIGNALS:
+ void readyChanged(bool);
+ void bufferingChanged(qint32 percent);
+ void errorOccured(qint32 code, const QString &message);
+ void stateChanged(QWasmMediaPlayer::QWasmMediaPlayerState newState);
+ void progressChanged(qint32 position);
+ void durationChanged(qint64 duration);
+ void statusChanged(QMediaPlayer::MediaStatus status);
+ void sizeChange(qint32 width, qint32 height);
+ void metaDataLoaded();
+
+private:
+ void checkNetworkState();
+ void videoComputeFrame(void *context);
+ void getDeviceSettings();
+
+ static QVideoFrameFormat::PixelFormat fromJsPixelFormat(std::string videoFormat);
+
+ emscripten::val m_video = emscripten::val::undefined();
+ emscripten::val m_videoElementSource = emscripten::val::undefined();
+
+ QString m_source;
+ float m_requestedPosition = 0.0;
+ emscripten::val m_offscreen = emscripten::val::undefined();
+
+ bool m_shouldStop = false;
+ bool m_toBePaused = false;
+ bool m_isSeeking = false;
+ bool m_hasAudio = false;
+ bool m_cameraIsReady = false;
+ bool m_shouldBeStarted = false;
+
+ emscripten::val m_offscreenContext = emscripten::val::undefined();
+ QSize m_pendingVideoSize;
+ QWasmVideoOutput::WasmVideoMode m_currentVideoMode = QWasmVideoOutput::VideoOutput;
+ QMediaPlayer::MediaStatus m_currentMediaStatus;
+ qreal m_currentBufferedValue;
+
+ QScopedPointer<qstdweb::EventCallback> m_timeUpdateEvent;
+ QScopedPointer<qstdweb::EventCallback> m_playEvent;
+ QScopedPointer<qstdweb::EventCallback> m_endedEvent;
+ QScopedPointer<qstdweb::EventCallback> m_durationChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_loadedDataEvent;
+ QScopedPointer<qstdweb::EventCallback> m_errorChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_resizeChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_loadedMetadataChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_loadStartChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_canPlayChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_canPlayThroughChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_seekingChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_seekedChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_emptiedChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_stalledChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_waitingChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_playingChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_progressChangeEvent;
+ QScopedPointer<qstdweb::EventCallback> m_pauseChangeEvent;
+};
+
+QT_END_NAMESPACE
+#endif // QWASMVIDEOOUTPUT_H
diff --git a/src/plugins/multimedia/wasm/mediacapture/qwasmcamera.cpp b/src/plugins/multimedia/wasm/mediacapture/qwasmcamera.cpp
new file mode 100644
index 000000000..fbc5cf262
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediacapture/qwasmcamera.cpp
@@ -0,0 +1,478 @@
+// Copyright (C) 2022 The Qt Company Ltd and/or its subsidiary(-ies).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmcamera_p.h"
+#include "qmediadevices.h"
+#include <qcameradevice.h>
+#include "private/qplatformvideosink_p.h"
+#include <private/qmemoryvideobuffer_p.h>
+#include <private/qvideotexturehelper_p.h>
+#include <private/qwasmmediadevices_p.h>
+
+#include "qwasmmediacapturesession_p.h"
+#include <common/qwasmvideooutput_p.h>
+
+#include <emscripten/val.h>
+#include <emscripten/bind.h>
+#include <emscripten/html5.h>
+#include <QUuid>
+#include <QTimer>
+
+#include <private/qstdweb_p.h>
+
+Q_LOGGING_CATEGORY(qWasmCamera, "qt.multimedia.wasm.camera")
+
+QWasmCamera::QWasmCamera(QCamera *camera)
+ : QPlatformCamera(camera),
+ m_cameraOutput(new QWasmVideoOutput),
+ m_cameraIsReady(false)
+{
+ QWasmMediaDevices *wasmMediaDevices =
+ static_cast<QWasmMediaDevices *>(QPlatformMediaIntegration::instance()->mediaDevices());
+
+ connect(wasmMediaDevices, &QWasmMediaDevices::videoInputsChanged,this, [this]() {
+ const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
+
+ if (!cameras.isEmpty()) {
+ if (m_cameraDev.id().isEmpty())
+ setCamera(cameras.at(0)); // default camera
+ else
+ setCamera(m_cameraDev);
+ return;
+ }
+ });
+
+ connect(this, &QWasmCamera::cameraIsReady, this, [this]() {
+ m_cameraIsReady = true;
+ if (m_cameraShouldStartActive) {
+ QTimer::singleShot(50, this, [this]() {
+ setActive(true);
+ });
+ }
+ });
+}
+
+QWasmCamera::~QWasmCamera() = default;
+
+bool QWasmCamera::isActive() const
+{
+ return m_cameraActive;
+}
+
+void QWasmCamera::setActive(bool active)
+{
+
+ if (!m_CaptureSession) {
+ updateError(QCamera::CameraError, QStringLiteral("video surface error"));
+ m_shouldBeActive = true;
+ return;
+ }
+
+ if (!m_cameraIsReady) {
+ m_cameraShouldStartActive = true;
+ return;
+ }
+
+ QVideoSink *sink = m_CaptureSession->videoSink();
+ if (!sink) {
+ qWarning() << Q_FUNC_INFO << "sink not ready";
+ return;
+ }
+
+ m_cameraOutput->setSurface(m_CaptureSession->videoSink());
+ m_cameraActive = active;
+ m_shouldBeActive = false;
+
+ if (m_cameraActive)
+ m_cameraOutput->start();
+ else
+ m_cameraOutput->pause();
+
+ updateCameraFeatures();
+ emit activeChanged(active);
+}
+
+void QWasmCamera::setCamera(const QCameraDevice &camera)
+{
+ if (!m_cameraDev.id().isEmpty())
+ return;
+
+ m_cameraOutput->setVideoMode(QWasmVideoOutput::Camera);
+
+ constexpr QSize initialSize(0, 0);
+ constexpr QRect initialRect(QPoint(0, 0), initialSize);
+ m_cameraOutput->createVideoElement(camera.id().toStdString()); // videoElementId
+ m_cameraOutput->createOffscreenElement(initialSize);
+ m_cameraOutput->updateVideoElementGeometry(initialRect);
+
+ const auto cameras = QMediaDevices::videoInputs();
+
+ if (std::find(cameras.begin(), cameras.end(), camera) != cameras.end()) {
+ m_cameraDev = camera;
+ createCamera(m_cameraDev);
+ emit cameraIsReady();
+ return;
+ }
+
+ if (cameras.count() > 0) {
+ m_cameraDev = camera;
+ createCamera(m_cameraDev);
+ emit cameraIsReady();
+ } else {
+ updateError(QCamera::CameraError, QStringLiteral("Failed to find a camera"));
+ }
+}
+
+bool QWasmCamera::setCameraFormat(const QCameraFormat &format)
+{
+ m_cameraFormat = format;
+
+ return true;
+}
+
+void QWasmCamera::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ QWasmMediaCaptureSession *captureSession = static_cast<QWasmMediaCaptureSession *>(session);
+ if (m_CaptureSession == captureSession)
+ return;
+
+ m_CaptureSession = captureSession;
+
+ if (m_shouldBeActive)
+ setActive(true);
+}
+
+void QWasmCamera::setFocusMode(QCamera::FocusMode mode)
+{
+ if (!isFocusModeSupported(mode))
+ return;
+
+ static constexpr std::string_view focusModeString = "focusMode";
+ if (mode == QCamera::FocusModeManual)
+ m_cameraOutput->setDeviceSetting(focusModeString.data(), emscripten::val("manual"));
+ if (mode == QCamera::FocusModeAuto)
+ m_cameraOutput->setDeviceSetting(focusModeString.data(), emscripten::val("continuous"));
+ focusModeChanged(mode);
+}
+
+bool QWasmCamera::isFocusModeSupported(QCamera::FocusMode mode) const
+{
+ emscripten::val caps = m_cameraOutput->getDeviceCapabilities();
+ if (caps.isUndefined())
+ return false;
+
+ emscripten::val focusMode = caps["focusMode"];
+ if (focusMode.isUndefined())
+ return false;
+
+ std::vector<std::string> focalModes;
+
+ for (int i = 0; i < focusMode["length"].as<int>(); i++)
+ focalModes.push_back(focusMode[i].as<std::string>());
+
+ // Do we need to take into account focusDistance
+ // it is not always available, and what distance
+ // would be far/near
+
+ bool found = false;
+ switch (mode) {
+ case QCamera::FocusModeAuto:
+ return std::find(focalModes.begin(), focalModes.end(), "continuous") != focalModes.end()
+ || std::find(focalModes.begin(), focalModes.end(), "single-shot")
+ != focalModes.end();
+ case QCamera::FocusModeAutoNear:
+ case QCamera::FocusModeAutoFar:
+ case QCamera::FocusModeHyperfocal:
+ case QCamera::FocusModeInfinity:
+ break;
+ case QCamera::FocusModeManual:
+ found = std::find(focalModes.begin(), focalModes.end(), "manual") != focalModes.end();
+ };
+ return found;
+}
+
+void QWasmCamera::setTorchMode(QCamera::TorchMode mode)
+{
+ if (!isTorchModeSupported(mode))
+ return;
+
+ if (m_wasmTorchMode == mode)
+ return;
+
+ static constexpr std::string_view torchModeString = "torchMode";
+ bool hasChanged = false;
+ switch (mode) {
+ case QCamera::TorchOff:
+ m_cameraOutput->setDeviceSetting(torchModeString.data(), emscripten::val(false));
+ hasChanged = true;
+ break;
+ case QCamera::TorchOn:
+ m_cameraOutput->setDeviceSetting(torchModeString.data(), emscripten::val(true));
+ hasChanged = true;
+ break;
+ case QCamera::TorchAuto:
+ break;
+ };
+ m_wasmTorchMode = mode;
+ if (hasChanged)
+ torchModeChanged(m_wasmTorchMode);
+}
+
+bool QWasmCamera::isTorchModeSupported(QCamera::TorchMode mode) const
+{
+ if (!m_cameraIsReady)
+ return false;
+
+ emscripten::val caps = m_cameraOutput->getDeviceCapabilities();
+ if (caps.isUndefined())
+ return false;
+
+ emscripten::val exposureMode = caps["torch"];
+ if (exposureMode.isUndefined())
+ return false;
+
+ return (mode != QCamera::TorchAuto);
+}
+
+void QWasmCamera::setExposureMode(QCamera::ExposureMode mode)
+{
+ // TODO manually come up with exposureTime values ?
+ if (!isExposureModeSupported(mode))
+ return;
+
+ if (m_wasmExposureMode == mode)
+ return;
+
+ bool hasChanged = false;
+ static constexpr std::string_view exposureModeString = "exposureMode";
+ switch (mode) {
+ case QCamera::ExposureManual:
+ m_cameraOutput->setDeviceSetting(exposureModeString.data(), emscripten::val("manual"));
+ hasChanged = true;
+ break;
+ case QCamera::ExposureAuto:
+ m_cameraOutput->setDeviceSetting(exposureModeString.data(), emscripten::val("continuous"));
+ hasChanged = true;
+ break;
+ default:
+ break;
+ };
+
+ if (hasChanged) {
+ m_wasmExposureMode = mode;
+ exposureModeChanged(m_wasmExposureMode);
+ }
+}
+
+bool QWasmCamera::isExposureModeSupported(QCamera::ExposureMode mode) const
+{
+ if (!m_cameraIsReady)
+ return false;
+
+ emscripten::val caps = m_cameraOutput->getDeviceCapabilities();
+ if (caps.isUndefined())
+ return false;
+
+ emscripten::val exposureMode = caps["exposureMode"];
+ if (exposureMode.isUndefined())
+ return false;
+
+ std::vector<std::string> exposureModes;
+
+ for (int i = 0; i < exposureMode["length"].as<int>(); i++)
+ exposureModes.push_back(exposureMode[i].as<std::string>());
+
+ bool found = false;
+ switch (mode) {
+ case QCamera::ExposureAuto:
+ found = std::find(exposureModes.begin(), exposureModes.end(), "continuous")
+ != exposureModes.end();
+ break;
+ case QCamera::ExposureManual:
+ found = std::find(exposureModes.begin(), exposureModes.end(), "manual")
+ != exposureModes.end();
+ break;
+ default:
+ break;
+ };
+
+ return found;
+}
+
+void QWasmCamera::setExposureCompensation(float bias)
+{
+ if (!m_cameraIsReady)
+ return;
+
+ emscripten::val caps = m_cameraOutput->getDeviceCapabilities();
+ if (caps.isUndefined())
+ return;
+
+ emscripten::val exposureComp = caps["exposureCompensation"];
+ if (exposureComp.isUndefined())
+ return;
+ if (m_wasmExposureCompensation == bias)
+ return;
+
+ static constexpr std::string_view exposureCompensationModeString = "exposureCompensation";
+ m_cameraOutput->setDeviceSetting(exposureCompensationModeString.data(), emscripten::val(bias));
+ m_wasmExposureCompensation = bias;
+ emit exposureCompensationChanged(m_wasmExposureCompensation);
+}
+
+void QWasmCamera::setManualExposureTime(float secs)
+{
+ if (m_wasmExposureTime == secs)
+ return;
+
+ if (!m_cameraIsReady)
+ return;
+
+ emscripten::val caps = m_cameraOutput->getDeviceCapabilities();
+ emscripten::val exposureTime = caps["exposureTime"];
+ if (exposureTime.isUndefined())
+ return;
+ static constexpr std::string_view exposureTimeString = "exposureTime";
+ m_cameraOutput->setDeviceSetting(exposureTimeString.data(), emscripten::val(secs));
+ m_wasmExposureTime = secs;
+ emit exposureTimeChanged(m_wasmExposureTime);
+}
+
+int QWasmCamera::isoSensitivity() const
+{
+ if (!m_cameraIsReady)
+ return 0;
+
+ emscripten::val caps = m_cameraOutput->getDeviceCapabilities();
+ if (caps.isUndefined())
+ return false;
+
+ emscripten::val isoSpeed = caps["iso"];
+ if (isoSpeed.isUndefined())
+ return 0;
+
+ return isoSpeed.as<double>();
+}
+
+void QWasmCamera::setManualIsoSensitivity(int sens)
+{
+ if (!m_cameraIsReady)
+ return;
+
+ emscripten::val caps = m_cameraOutput->getDeviceCapabilities();
+ if (caps.isUndefined())
+ return;
+
+ emscripten::val isoSpeed = caps["iso"];
+ if (isoSpeed.isUndefined())
+ return;
+ if (m_wasmIsoSensitivity == sens)
+ return;
+ static constexpr std::string_view isoString = "iso";
+ m_cameraOutput->setDeviceSetting(isoString.data(), emscripten::val(sens));
+ m_wasmIsoSensitivity = sens;
+ emit isoSensitivityChanged(m_wasmIsoSensitivity);
+}
+
+bool QWasmCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const
+{
+ if (!m_cameraIsReady)
+ return false;
+
+ emscripten::val caps = m_cameraOutput->getDeviceCapabilities();
+ if (caps.isUndefined())
+ return false;
+
+ emscripten::val whiteBalanceMode = caps["whiteBalanceMode"];
+ if (whiteBalanceMode.isUndefined())
+ return false;
+
+ if (mode == QCamera::WhiteBalanceAuto || mode == QCamera::WhiteBalanceManual)
+ return true;
+
+ return false;
+}
+
+void QWasmCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)
+{
+ if (!isWhiteBalanceModeSupported(mode))
+ return;
+
+ if (m_wasmWhiteBalanceMode == mode)
+ return;
+
+ bool hasChanged = false;
+ static constexpr std::string_view whiteBalanceModeString = "whiteBalanceMode";
+ switch (mode) {
+ case QCamera::WhiteBalanceAuto:
+ m_cameraOutput->setDeviceSetting(whiteBalanceModeString.data(), emscripten::val("auto"));
+ hasChanged = true;
+ break;
+ case QCamera::WhiteBalanceManual:
+ m_cameraOutput->setDeviceSetting(whiteBalanceModeString.data(), emscripten::val("manual"));
+ hasChanged = true;
+ break;
+ default:
+ break;
+ };
+
+ if (hasChanged) {
+ m_wasmWhiteBalanceMode = mode;
+ emit whiteBalanceModeChanged(m_wasmWhiteBalanceMode);
+ }
+}
+
+void QWasmCamera::setColorTemperature(int temperature)
+{
+ if (!m_cameraIsReady)
+ return;
+
+ emscripten::val caps = m_cameraOutput->getDeviceCapabilities();
+ if (caps.isUndefined())
+ return;
+
+ emscripten::val whiteBalanceMode = caps["colorTemperature"];
+ if (whiteBalanceMode.isUndefined())
+ return;
+ if(m_wasmColorTemperature == temperature)
+ return;
+
+ static constexpr std::string_view colorBalanceString = "colorTemperature";
+ m_cameraOutput->setDeviceSetting(colorBalanceString.data(), emscripten::val(temperature));
+ m_wasmColorTemperature = temperature;
+ colorTemperatureChanged(m_wasmColorTemperature);
+}
+
+void QWasmCamera::createCamera(const QCameraDevice &camera)
+{
+ m_cameraOutput->addCameraSourceElement(camera.id().toStdString());
+}
+
+void QWasmCamera::updateCameraFeatures()
+{
+ if (!m_cameraIsReady)
+ return;
+
+ emscripten::val caps = m_cameraOutput->getDeviceCapabilities();
+ if (caps.isUndefined())
+ return;
+
+ QCamera::Features cameraFeatures;
+
+ if (!caps["colorTemperature"].isUndefined())
+ cameraFeatures |= QCamera::Feature::ColorTemperature;
+
+ if (!caps["exposureCompensation"].isUndefined())
+ cameraFeatures |= QCamera::Feature::ExposureCompensation;
+
+ if (!caps["iso"].isUndefined())
+ cameraFeatures |= QCamera::Feature::IsoSensitivity;
+
+ if (!caps["exposureTime"].isUndefined())
+ cameraFeatures |= QCamera::Feature::ManualExposureTime;
+
+ if (!caps["focusDistance"].isUndefined())
+ cameraFeatures |= QCamera::Feature::FocusDistance;
+
+ supportedFeaturesChanged(cameraFeatures);
+}
diff --git a/src/plugins/multimedia/wasm/mediacapture/qwasmcamera_p.h b/src/plugins/multimedia/wasm/mediacapture/qwasmcamera_p.h
new file mode 100644
index 000000000..7bb6d02d7
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediacapture/qwasmcamera_p.h
@@ -0,0 +1,99 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMCAMERA_H
+#define QWASMCAMERA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformcamera_p.h>
+#include <private/qplatformvideodevices_p.h>
+#include <common/qwasmvideooutput_p.h>
+
+#include <QCameraDevice>
+#include <QtCore/qloggingcategory.h>
+
+#include <emscripten/val.h>
+#include <emscripten/bind.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qWasmCamera)
+
+class QWasmMediaCaptureSession;
+
+class QWasmCamera : public QPlatformCamera
+{
+ Q_OBJECT
+
+public:
+ explicit QWasmCamera(QCamera *camera);
+ ~QWasmCamera();
+
+ bool isActive() const override;
+ void setActive(bool active) override;
+
+ void setCamera(const QCameraDevice &camera) override;
+ bool setCameraFormat(const QCameraFormat &format) override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session) override;
+
+ void setFocusMode(QCamera::FocusMode mode) override;
+ bool isFocusModeSupported(QCamera::FocusMode mode) const override;
+
+ void setTorchMode(QCamera::TorchMode mode) override;
+ bool isTorchModeSupported(QCamera::TorchMode mode) const override;
+
+ void setExposureMode(QCamera::ExposureMode mode) override;
+ bool isExposureModeSupported(QCamera::ExposureMode mode) const override;
+ void setExposureCompensation(float bias) override;
+
+ void setManualExposureTime(float) override;
+ int isoSensitivity() const override;
+ void setManualIsoSensitivity(int) override;
+
+ bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override;
+ void setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) override;
+
+ void setColorTemperature(int temperature) override;
+
+ QWasmVideoOutput *cameraOutput() { return m_cameraOutput.data(); }
+Q_SIGNALS:
+ void cameraIsReady();
+private:
+ void createCamera(const QCameraDevice &camera);
+ void updateCameraFeatures();
+
+ QCameraDevice m_cameraDev;
+ QWasmMediaCaptureSession *m_CaptureSession = nullptr;
+ bool m_cameraActive = false;
+ QScopedPointer <QWasmVideoOutput> m_cameraOutput;
+
+ emscripten::val supportedCapabilities = emscripten::val::object(); // browser
+ emscripten::val currentCapabilities = emscripten::val::object(); // camera track
+ emscripten::val currentSettings = emscripten::val::object(); // camera track
+
+ QCamera::TorchMode m_wasmTorchMode;
+ QCamera::ExposureMode m_wasmExposureMode;
+ float m_wasmExposureTime;
+ float m_wasmExposureCompensation;
+ int m_wasmIsoSensitivity;
+ QCamera::WhiteBalanceMode m_wasmWhiteBalanceMode;
+ int m_wasmColorTemperature;
+ bool m_cameraIsReady = false;
+ bool m_cameraShouldStartActive = false;
+ bool m_shouldBeActive = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMCAMERA_H
diff --git a/src/plugins/multimedia/wasm/mediacapture/qwasmimagecapture.cpp b/src/plugins/multimedia/wasm/mediacapture/qwasmimagecapture.cpp
new file mode 100644
index 000000000..f62d6f1a6
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediacapture/qwasmimagecapture.cpp
@@ -0,0 +1,130 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmimagecapture_p.h"
+#include <qimagewriter.h>
+#include "qwasmmediacapturesession_p.h"
+#include "qwasmcamera_p.h"
+#include "qwasmvideosink_p.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(qWasmImageCapture, "qt.multimedia.wasm.imagecapture")
+/* TODO
+signals:
+imageExposed
+*/
+QWasmImageCapture::QWasmImageCapture(QImageCapture *parent) : QPlatformImageCapture(parent) { }
+
+QWasmImageCapture::~QWasmImageCapture() = default;
+
+int QWasmImageCapture::capture(const QString &fileName)
+{
+ if (!isReadyForCapture()) {
+ emit error(m_lastId, QImageCapture::NotReadyError, msgCameraNotReady());
+ return -1;
+ }
+
+ // TODO if fileName.isEmpty() we choose filename and location
+
+ QImage image = takePicture();
+ if (image.isNull())
+ return -1;
+
+ QImageWriter writer(fileName);
+ // TODO
+ // writer.setQuality(quality);
+ // writer.setFormat("png");
+
+ if (writer.write(image)) {
+ qCDebug(qWasmImageCapture) << Q_FUNC_INFO << "image saved";
+ emit imageSaved(m_lastId, fileName);
+ } else {
+ QImageCapture::Error err = (writer.error() == QImageWriter::UnsupportedFormatError)
+ ? QImageCapture::FormatError
+ : QImageCapture::ResourceError;
+
+ emit error(m_lastId, err, writer.errorString());
+ }
+
+ return m_lastId;
+}
+
+int QWasmImageCapture::captureToBuffer()
+{
+ if (!isReadyForCapture()) {
+ emit error(m_lastId, QImageCapture::NotReadyError, msgCameraNotReady());
+ return -1;
+ }
+
+ QImage image = takePicture();
+ if (image.isNull())
+ return -1;
+
+ emit imageCaptured(m_lastId, image);
+ return m_lastId;
+}
+
+QImage QWasmImageCapture::takePicture()
+{
+ QVideoFrame thisFrame = m_captureSession->videoSink()->videoFrame();
+ if (!thisFrame.isValid())
+ return QImage();
+
+ m_lastId++;
+ emit imageAvailable(m_lastId, thisFrame);
+
+ QImage image = thisFrame.toImage();
+ if (image.isNull()) {
+ qCDebug(qWasmImageCapture) << Q_FUNC_INFO << "image is null";
+ emit error(m_lastId, QImageCapture::ResourceError, QStringLiteral("Resource error"));
+ return QImage();
+ }
+
+ emit imageCaptured(m_lastId, image);
+ if (m_settings.resolution().isValid() && m_settings.resolution() != image.size())
+ image = image.scaled(m_settings.resolution());
+
+ return image;
+}
+
+bool QWasmImageCapture::isReadyForCapture() const
+{
+ return m_isReadyForCapture;
+}
+
+QImageEncoderSettings QWasmImageCapture::imageSettings() const
+{
+ return m_settings;
+}
+
+void QWasmImageCapture::setImageSettings(const QImageEncoderSettings &settings)
+{
+ m_settings = settings;
+}
+
+void QWasmImageCapture::setReadyForCapture(bool isReady)
+{
+ if (m_isReadyForCapture != isReady) {
+ m_isReadyForCapture = isReady;
+ emit readyForCaptureChanged(m_isReadyForCapture);
+ }
+}
+
+void QWasmImageCapture::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ QWasmMediaCaptureSession *captureSession = static_cast<QWasmMediaCaptureSession *>(session);
+ // nullptr clears
+ if (m_captureSession == captureSession)
+ return;
+
+ m_isReadyForCapture = captureSession;
+ if (captureSession) {
+ m_lastId = 0;
+ m_captureSession = captureSession;
+ }
+ emit readyForCaptureChanged(m_isReadyForCapture);
+ m_captureSession = captureSession;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/wasm/mediacapture/qwasmimagecapture_p.h b/src/plugins/multimedia/wasm/mediacapture/qwasmimagecapture_p.h
new file mode 100644
index 000000000..2e9e9b227
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediacapture/qwasmimagecapture_p.h
@@ -0,0 +1,58 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMIMAGECAPTURE_H
+#define QWASMIMAGECAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QObject>
+#include <private/qplatformimagecapture_p.h>
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qWasmImageCapture)
+
+class QWasmMediaCaptureSession;
+
+class QWasmImageCapture : public QPlatformImageCapture
+{
+ Q_OBJECT
+public:
+ explicit QWasmImageCapture(QImageCapture *parent = nullptr);
+ ~QWasmImageCapture();
+
+ bool isReadyForCapture() const override;
+
+ int capture(const QString &fileName) override;
+ int captureToBuffer() override;
+
+ QImageEncoderSettings imageSettings() const override;
+ void setImageSettings(const QImageEncoderSettings &settings) override;
+
+ void setReadyForCapture(bool isReady);
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session);
+
+private:
+ QImage takePicture();
+
+ // weak
+ QWasmMediaCaptureSession *m_captureSession = nullptr;
+ QImageEncoderSettings m_settings;
+ bool m_isReadyForCapture = false;
+ int m_lastId = 0;
+};
+
+QT_END_NAMESPACE
+#endif // QWASMIMAGECAPTURE_H
diff --git a/src/plugins/multimedia/wasm/mediacapture/qwasmmediacapturesession.cpp b/src/plugins/multimedia/wasm/mediacapture/qwasmmediacapturesession.cpp
new file mode 100644
index 000000000..826650570
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediacapture/qwasmmediacapturesession.cpp
@@ -0,0 +1,111 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmmediacapturesession_p.h"
+#include "mediacapture/qwasmimagecapture_p.h"
+
+#include "qwasmcamera_p.h"
+#include <private/qplatformmediadevices_p.h>
+#include <private/qplatformmediaintegration_p.h>
+#include <private/qwasmmediadevices_p.h>
+
+Q_LOGGING_CATEGORY(qWasmMediaCaptureSession, "qt.multimedia.wasm.capturesession")
+
+QWasmMediaCaptureSession::QWasmMediaCaptureSession()
+{
+ QWasmMediaDevices *wasmMediaDevices = static_cast<QWasmMediaDevices *>(QPlatformMediaIntegration::instance()->mediaDevices());
+ wasmMediaDevices->initDevices();
+}
+
+QWasmMediaCaptureSession::~QWasmMediaCaptureSession() = default;
+
+QPlatformCamera *QWasmMediaCaptureSession::camera()
+{
+ return m_camera.data();
+}
+
+void QWasmMediaCaptureSession::setCamera(QPlatformCamera *camera)
+{
+ if (!camera) {
+ if (m_camera == nullptr)
+ return;
+ m_camera.reset(nullptr);
+ } else {
+ QWasmCamera *wasmCamera = static_cast<QWasmCamera *>(camera);
+ if (m_camera.data() == wasmCamera)
+ return;
+ m_camera.reset(wasmCamera);
+ m_camera->setCaptureSession(this);
+ }
+ emit cameraChanged();
+}
+
+QPlatformImageCapture *QWasmMediaCaptureSession::imageCapture()
+{
+ return m_imageCapture;
+}
+
+void QWasmMediaCaptureSession::setImageCapture(QPlatformImageCapture *imageCapture)
+{
+ if (m_imageCapture == imageCapture)
+ return;
+
+ if (m_imageCapture)
+ m_imageCapture->setCaptureSession(nullptr);
+
+ m_imageCapture = static_cast<QWasmImageCapture *>(imageCapture);
+
+ if (m_imageCapture) {
+ m_imageCapture->setCaptureSession(this);
+
+ m_imageCapture->setReadyForCapture(true);
+ emit imageCaptureChanged();
+ }
+}
+
+QPlatformMediaRecorder *QWasmMediaCaptureSession::mediaRecorder()
+{
+ return m_mediaRecorder;
+}
+
+void QWasmMediaCaptureSession::setMediaRecorder(QPlatformMediaRecorder *mediaRecorder)
+{
+ if (m_mediaRecorder == mediaRecorder)
+ return;
+
+ if (m_mediaRecorder)
+ m_mediaRecorder->setCaptureSession(nullptr);
+
+ m_mediaRecorder = static_cast<QWasmMediaRecorder *>(mediaRecorder);
+
+ if (m_mediaRecorder)
+ m_mediaRecorder->setCaptureSession(this);
+}
+
+void QWasmMediaCaptureSession::setAudioInput(QPlatformAudioInput *input)
+{
+ if (m_audioInput == input)
+ return;
+
+ m_needsAudio = (bool)input;
+ m_audioInput = input;
+}
+
+bool QWasmMediaCaptureSession::hasAudio()
+{
+ return m_needsAudio;
+}
+
+void QWasmMediaCaptureSession::setVideoPreview(QVideoSink *sink)
+{
+ if (m_wasmSink == sink)
+ return;
+ m_wasmSink = sink;
+}
+
+void QWasmMediaCaptureSession::setAudioOutput(QPlatformAudioOutput *output)
+{
+ if (m_audioOutput == output)
+ return;
+ m_audioOutput = output;
+}
diff --git a/src/plugins/multimedia/wasm/mediacapture/qwasmmediacapturesession_p.h b/src/plugins/multimedia/wasm/mediacapture/qwasmmediacapturesession_p.h
new file mode 100644
index 000000000..817580c90
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediacapture/qwasmmediacapturesession_p.h
@@ -0,0 +1,71 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMMEDIACAPTURESESSION_H
+#define QWASMMEDIACAPTURESESSION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qwasmimagecapture_p.h"
+
+#include <private/qplatformmediacapture_p.h>
+#include <private/qplatformmediaintegration_p.h>
+#include "qwasmmediarecorder_p.h"
+#include <QScopedPointer>
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qWasmMediaCaptureSession)
+
+class QAudioInput;
+class QWasmCamera;
+
+class QWasmMediaCaptureSession : public QPlatformMediaCaptureSession
+{
+public:
+ explicit QWasmMediaCaptureSession();
+ ~QWasmMediaCaptureSession() override;
+
+ QPlatformCamera *camera() override;
+ void setCamera(QPlatformCamera *camera) override;
+
+ QPlatformImageCapture *imageCapture() override;
+ void setImageCapture(QPlatformImageCapture *imageCapture) override;
+
+ QPlatformMediaRecorder *mediaRecorder() override;
+ void setMediaRecorder(QPlatformMediaRecorder *recorder) override;
+
+ void setAudioInput(QPlatformAudioInput *input) override;
+ QPlatformAudioInput * audioInput() const { return m_audioInput; }
+ void setVideoPreview(QVideoSink *sink) override;
+ void setAudioOutput(QPlatformAudioOutput *output) override;
+
+ bool hasAudio();
+ QVideoSink *videoSink() { return m_wasmSink; }
+
+private:
+ QWasmMediaRecorder *m_mediaRecorder = nullptr;
+
+ QScopedPointer <QWasmCamera> m_camera;
+
+ QWasmImageCapture *m_imageCapture = nullptr;
+
+ QPlatformAudioInput *m_audioInput = nullptr;
+ QPlatformAudioOutput *m_audioOutput = nullptr;
+ bool m_needsAudio = false;
+ QVideoSink *m_wasmSink = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMMEDIACAPTURESESSION_H
diff --git a/src/plugins/multimedia/wasm/mediacapture/qwasmmediarecorder.cpp b/src/plugins/multimedia/wasm/mediacapture/qwasmmediarecorder.cpp
new file mode 100644
index 000000000..98f04616a
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediacapture/qwasmmediarecorder.cpp
@@ -0,0 +1,520 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmmediarecorder_p.h"
+#include "qwasmmediacapturesession_p.h"
+#include <private/qplatformmediadevices_p.h>
+#include <private/qplatformmediaintegration_p.h>
+#include "qwasmcamera_p.h"
+#include "qwasmaudioinput_p.h"
+
+#include <private/qstdweb_p.h>
+#include <QtCore/QIODevice>
+#include <QFile>
+#include <QTimer>
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(qWasmMediaRecorder, "qt.multimedia.wasm.mediarecorder")
+
+QWasmMediaRecorder::QWasmMediaRecorder(QMediaRecorder *parent)
+ : QPlatformMediaRecorder(parent)
+{
+ m_durationTimer.reset(new QElapsedTimer());
+ QPlatformMediaIntegration::instance()->mediaDevices(); // initialize getUserMedia
+}
+
+QWasmMediaRecorder::~QWasmMediaRecorder()
+{
+ if (m_outputTarget->isOpen())
+ m_outputTarget->close();
+
+ if (!m_mediaRecorder.isNull()) {
+ m_mediaStreamDataAvailable.reset(nullptr);
+ m_mediaStreamStopped.reset(nullptr);
+ m_mediaStreamError.reset(nullptr);
+ m_mediaStreamStart.reset(nullptr);
+ }
+}
+
+bool QWasmMediaRecorder::isLocationWritable(const QUrl &location) const
+{
+ return location.isValid() && (location.isLocalFile() || location.isRelative());
+}
+
+QMediaRecorder::RecorderState QWasmMediaRecorder::state() const
+{
+ QMediaRecorder::RecorderState recordingState = QMediaRecorder::StoppedState;
+
+ if (!m_mediaRecorder.isUndefined()) {
+ std::string state = m_mediaRecorder["state"].as<std::string>();
+ if (state == "recording")
+ recordingState = QMediaRecorder::RecordingState;
+ else if (state == "paused")
+ recordingState = QMediaRecorder::PausedState;
+ }
+ return recordingState;
+}
+
+qint64 QWasmMediaRecorder::duration() const
+{ // milliseconds
+ return m_durationMs;
+}
+
+void QWasmMediaRecorder::record(QMediaEncoderSettings &settings)
+{
+ if (!m_session)
+ return;
+
+ m_mediaSettings = settings;
+ initUserMedia();
+}
+
+void QWasmMediaRecorder::pause()
+{
+ if (!m_session || (m_mediaRecorder.isUndefined() || m_mediaRecorder.isNull())) {
+ qCDebug(qWasmMediaRecorder) << Q_FUNC_INFO << "could not find MediaRecorder";
+ return;
+ }
+ m_mediaRecorder.call<void>("pause");
+ emit stateChanged(state());
+}
+
+void QWasmMediaRecorder::resume()
+{
+ if (!m_session || (m_mediaRecorder.isUndefined() || m_mediaRecorder.isNull())) {
+ qCDebug(qWasmMediaRecorder)<< Q_FUNC_INFO << "could not find MediaRecorder";
+ return;
+ }
+
+ m_mediaRecorder.call<void>("resume");
+ emit stateChanged(state());
+}
+
+void QWasmMediaRecorder::stop()
+{
+ if (!m_session || (m_mediaRecorder.isUndefined() || m_mediaRecorder.isNull())) {
+ qCDebug(qWasmMediaRecorder)<< Q_FUNC_INFO << "could not find MediaRecorder";
+ return;
+ }
+ if (m_mediaRecorder["state"].as<std::string>() == "recording")
+ m_mediaRecorder.call<void>("stop");
+}
+
+void QWasmMediaRecorder::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ m_session = static_cast<QWasmMediaCaptureSession *>(session);
+}
+
+bool QWasmMediaRecorder::hasCamera() const
+{
+ return m_session && m_session->camera();
+}
+
+void QWasmMediaRecorder::initUserMedia()
+{
+ setUpFileSink();
+ emscripten::val navigator = emscripten::val::global("navigator");
+ emscripten::val mediaDevices = navigator["mediaDevices"];
+
+ if (mediaDevices.isNull() || mediaDevices.isUndefined()) {
+ qCDebug(qWasmMediaRecorder) << "MediaDevices are undefined or null";
+ return;
+ }
+
+ if (!m_session)
+ return;
+ qCDebug(qWasmMediaRecorder) << Q_FUNC_INFO << m_session;
+
+ emscripten::val stream = emscripten::val::undefined();
+ if (hasCamera()) {
+ qCDebug(qWasmMediaRecorder) << Q_FUNC_INFO << "has camera";
+ QWasmCamera *wasmCamera = reinterpret_cast<QWasmCamera *>(m_session->camera());
+
+ if (wasmCamera) {
+ emscripten::val m_video = wasmCamera->cameraOutput()->surfaceElement();
+ if (m_video.isNull() || m_video.isUndefined()) {
+ qCDebug(qWasmMediaRecorder) << Q_FUNC_INFO << "video element not found";
+ return;
+ }
+
+ stream = m_video["srcObject"];
+ if (stream.isNull() || stream.isUndefined()) {
+ qCDebug(qWasmMediaRecorder) << Q_FUNC_INFO << "Video input stream not found";
+ return;
+ }
+ }
+ } else {
+ qCDebug(qWasmMediaRecorder) << Q_FUNC_INFO << "has audio";
+ stream = static_cast<QWasmAudioInput *>(m_session->audioInput())->mediaStream();
+
+ if (stream.isNull() || stream.isUndefined()) {
+ qCDebug(qWasmMediaRecorder) << Q_FUNC_INFO << "Audio input stream not found";
+ return;
+ }
+ }
+ if (stream.isNull() || stream.isUndefined()) {
+ qCDebug(qWasmMediaRecorder) << Q_FUNC_INFO << "No input stream found";
+ return;
+ }
+
+ setStream(stream);
+}
+
+void QWasmMediaRecorder::startAudioRecording()
+{
+ startStream();
+}
+
+void QWasmMediaRecorder::setStream(emscripten::val stream)
+{
+ emscripten::val emMediaSettings = emscripten::val::object();
+ QMediaFormat::VideoCodec videoCodec = m_mediaSettings.videoCodec();
+ QMediaFormat::AudioCodec audioCodec = m_mediaSettings.audioCodec();
+ QMediaFormat::FileFormat fileFormat = m_mediaSettings.fileFormat();
+
+ // mime and codecs
+ QString mimeCodec;
+ if (!m_mediaSettings.mimeType().name().isEmpty()) {
+ mimeCodec = m_mediaSettings.mimeType().name();
+
+ if (videoCodec != QMediaFormat::VideoCodec::Unspecified)
+ mimeCodec += QStringLiteral(": codecs=");
+
+ if (audioCodec != QMediaFormat::AudioCodec::Unspecified) {
+ // TODO
+ }
+
+ if (fileFormat != QMediaFormat::UnspecifiedFormat)
+ mimeCodec += QMediaFormat::fileFormatName(m_mediaSettings.fileFormat());
+
+ emMediaSettings.set("mimeType", mimeCodec.toStdString());
+ }
+
+ if (m_mediaSettings.audioBitRate() > 0)
+ emMediaSettings.set("audioBitsPerSecond", emscripten::val(m_mediaSettings.audioBitRate()));
+
+ if (m_mediaSettings.videoBitRate() > 0)
+ emMediaSettings.set("videoBitsPerSecond", emscripten::val(m_mediaSettings.videoBitRate()));
+
+ // create the MediaRecorder, and set up data callback
+ m_mediaRecorder = emscripten::val::global("MediaRecorder").new_(stream, emMediaSettings);
+
+ qCDebug(qWasmMediaRecorder) << Q_FUNC_INFO << "m_mediaRecorder state:"
+ << QString::fromStdString(m_mediaRecorder["state"].as<std::string>());
+
+ if (m_mediaRecorder.isNull() || m_mediaRecorder.isUndefined()) {
+ qWarning() << "MediaRecorder could not be found";
+ return;
+ }
+ m_mediaRecorder.set("data-mediarecordercontext",
+ emscripten::val(quintptr(reinterpret_cast<void *>(this))));
+
+ if (!m_mediaStreamDataAvailable.isNull()) {
+ m_mediaStreamDataAvailable.reset();
+ m_mediaStreamStopped.reset();
+ m_mediaStreamError.reset();
+ m_mediaStreamStart.reset();
+ m_mediaStreamPause.reset();
+ m_mediaStreamResume.reset();
+ }
+
+ // dataavailable
+ auto callback = [](emscripten::val blob) {
+ if (blob.isUndefined() || blob.isNull()) {
+ qCDebug(qWasmMediaRecorder) << "blob is null";
+ return;
+ }
+ if (blob["target"].isUndefined() || blob["target"].isNull())
+ return;
+ if (blob["data"].isUndefined() || blob["data"].isNull())
+ return;
+ if (blob["target"]["data-mediarecordercontext"].isUndefined()
+ || blob["target"]["data-mediarecordercontext"].isNull())
+ return;
+
+ QWasmMediaRecorder *recorder = reinterpret_cast<QWasmMediaRecorder *>(
+ blob["target"]["data-mediarecordercontext"].as<quintptr>());
+
+ if (recorder) {
+ const double timeCode =
+ blob.hasOwnProperty("timecode") ? blob["timecode"].as<double>() : 0;
+ recorder->audioDataAvailable(blob["data"], timeCode);
+ }
+ };
+
+ m_mediaStreamDataAvailable.reset(
+ new qstdweb::EventCallback(m_mediaRecorder, "dataavailable", callback));
+
+ // stopped
+ auto stoppedCallback = [](emscripten::val event) {
+ if (event.isUndefined() || event.isNull()) {
+ qCDebug(qWasmMediaRecorder) << "event is null";
+ return;
+ }
+ qCDebug(qWasmMediaRecorder)
+ << "STOPPED: state changed"
+ << QString::fromStdString(event["target"]["state"].as<std::string>());
+
+ QWasmMediaRecorder *recorder = reinterpret_cast<QWasmMediaRecorder *>(
+ event["target"]["data-mediarecordercontext"].as<quintptr>());
+
+ if (recorder) {
+ recorder->m_isRecording = false;
+ recorder->m_durationTimer->invalidate();
+
+ emit recorder->stateChanged(recorder->state());
+ }
+ };
+
+ m_mediaStreamStopped.reset(
+ new qstdweb::EventCallback(m_mediaRecorder, "stop", stoppedCallback));
+
+ // error
+ auto errorCallback = [](emscripten::val theError) {
+ if (theError.isUndefined() || theError.isNull()) {
+ qCDebug(qWasmMediaRecorder) << "error is null";
+ return;
+ }
+ qCDebug(qWasmMediaRecorder)
+ << theError["code"].as<int>()
+ << QString::fromStdString(theError["message"].as<std::string>());
+
+ QWasmMediaRecorder *recorder = reinterpret_cast<QWasmMediaRecorder *>(
+ theError["target"]["data-mediarecordercontext"].as<quintptr>());
+
+ if (recorder) {
+ recorder->updateError(QMediaRecorder::ResourceError,
+ QString::fromStdString(theError["message"].as<std::string>()));
+ emit recorder->stateChanged(recorder->state());
+ }
+ };
+
+ m_mediaStreamError.reset(new qstdweb::EventCallback(m_mediaRecorder, "error", errorCallback));
+
+ // start
+ auto startCallback = [](emscripten::val event) {
+ if (event.isUndefined() || event.isNull()) {
+ qCDebug(qWasmMediaRecorder) << "event is null";
+ return;
+ }
+
+ qCDebug(qWasmMediaRecorder)
+ << "START: state changed"
+ << QString::fromStdString(event["target"]["state"].as<std::string>());
+
+ QWasmMediaRecorder *recorder = reinterpret_cast<QWasmMediaRecorder *>(
+ event["target"]["data-mediarecordercontext"].as<quintptr>());
+
+ if (recorder) {
+ recorder->m_isRecording = true;
+ recorder->m_durationTimer->start();
+ emit recorder->stateChanged(recorder->state());
+ }
+ };
+
+ m_mediaStreamStart.reset(new qstdweb::EventCallback(m_mediaRecorder, "start", startCallback));
+
+ // pause
+ auto pauseCallback = [](emscripten::val event) {
+ if (event.isUndefined() || event.isNull()) {
+ qCDebug(qWasmMediaRecorder) << "event is null";
+ return;
+ }
+
+ qCDebug(qWasmMediaRecorder)
+ << "pause: state changed"
+ << QString::fromStdString(event["target"]["state"].as<std::string>());
+
+ QWasmMediaRecorder *recorder = reinterpret_cast<QWasmMediaRecorder *>(
+ event["target"]["data-mediarecordercontext"].as<quintptr>());
+
+ if (recorder) {
+ recorder->m_isRecording = true;
+ recorder->m_durationTimer->start();
+ emit recorder->stateChanged(recorder->state());
+ }
+ };
+
+ m_mediaStreamPause.reset(new qstdweb::EventCallback(m_mediaRecorder, "pause", pauseCallback));
+
+ // resume
+ auto resumeCallback = [](emscripten::val event) {
+ if (event.isUndefined() || event.isNull()) {
+ qCDebug(qWasmMediaRecorder) << "event is null";
+ return;
+ }
+
+ qCDebug(qWasmMediaRecorder)
+ << "resume: state changed"
+ << QString::fromStdString(event["target"]["state"].as<std::string>());
+
+ QWasmMediaRecorder *recorder = reinterpret_cast<QWasmMediaRecorder *>(
+ event["target"]["data-mediarecordercontext"].as<quintptr>());
+
+ if (recorder) {
+ recorder->m_isRecording = true;
+ recorder->m_durationTimer->start();
+ emit recorder->stateChanged(recorder->state());
+ }
+ };
+
+ m_mediaStreamResume.reset(
+ new qstdweb::EventCallback(m_mediaRecorder, "resume", resumeCallback));
+
+ // set up what options we can
+ if (hasCamera())
+ setTrackContraints(m_mediaSettings, stream);
+ else
+ startStream();
+}
+
+void QWasmMediaRecorder::audioDataAvailable(emscripten::val blob, double timeCodeDifference)
+{
+ Q_UNUSED(timeCodeDifference)
+ if (blob.isUndefined() || blob.isNull()) {
+ qCDebug(qWasmMediaRecorder) << "blob is null";
+ return;
+ }
+
+ auto fileReader = std::make_shared<qstdweb::FileReader>();
+
+ fileReader->onError([=](emscripten::val theError) {
+ updateError(QMediaRecorder::ResourceError,
+ QString::fromStdString(theError["message"].as<std::string>()));
+ });
+
+ fileReader->onAbort([=](emscripten::val) {
+ updateError(QMediaRecorder::ResourceError, QStringLiteral("File read aborted"));
+ });
+
+ fileReader->onLoad([=](emscripten::val) {
+ if (fileReader->val().isNull() || fileReader->val().isUndefined())
+ return;
+ qstdweb::ArrayBuffer result = fileReader->result();
+ if (result.val().isNull() || result.val().isUndefined())
+ return;
+ QByteArray fileContent = qstdweb::Uint8Array(result).copyToQByteArray();
+
+ if (m_isRecording && !fileContent.isEmpty()) {
+ m_durationMs = m_durationTimer->elapsed();
+ if (m_outputTarget->isOpen())
+ m_outputTarget->write(fileContent, fileContent.length());
+ // we've read everything
+ emit durationChanged(m_durationMs);
+ qCDebug(qWasmMediaRecorder) << "duration changed" << m_durationMs;
+ }
+ });
+
+ fileReader->readAsArrayBuffer(qstdweb::Blob(blob));
+}
+
+// constraints are suggestions, as not all hardware supports all settings
+void QWasmMediaRecorder::setTrackContraints(QMediaEncoderSettings &settings, emscripten::val stream)
+{
+ qCDebug(qWasmMediaRecorder) << Q_FUNC_INFO << settings.audioSampleRate();
+
+ if (stream.isUndefined() || stream.isNull()) {
+ qCDebug(qWasmMediaRecorder)<< Q_FUNC_INFO << "could not find MediaStream";
+ return;
+ }
+
+ emscripten::val navigator = emscripten::val::global("navigator");
+ emscripten::val mediaDevices = navigator["mediaDevices"];
+
+ // check which ones are supported
+ // emscripten::val allConstraints = mediaDevices.call<emscripten::val>("getSupportedConstraints");
+ // browsers only support some settings
+
+ emscripten::val videoParams = emscripten::val::object();
+ emscripten::val constraints = emscripten::val::object();
+
+ if (hasCamera()) {
+ if (settings.videoFrameRate() > 0)
+ videoParams.set("frameRate", emscripten::val(settings.videoFrameRate()));
+ if (settings.videoResolution().height() > 0)
+ videoParams.set("height",
+ emscripten::val(settings.videoResolution().height())); // viewportHeight?
+ if (settings.videoResolution().width() > 0)
+ videoParams.set("width", emscripten::val(settings.videoResolution().width()));
+
+ constraints.set("video", videoParams); // only video here
+ }
+
+ emscripten::val audioParams = emscripten::val::object();
+ if (settings.audioSampleRate() > 0)
+ audioParams.set("sampleRate", emscripten::val(settings.audioSampleRate())); // may not work
+ if (settings.audioBitRate() > 0)
+ audioParams.set("sampleSize", emscripten::val(settings.audioBitRate())); // may not work
+ if (settings.audioChannelCount() > 0)
+ audioParams.set("channelCount", emscripten::val(settings.audioChannelCount()));
+
+ constraints.set("audio", audioParams); // only audio here
+
+ if (hasCamera() && stream["active"].as<bool>()) {
+ emscripten::val videoTracks = emscripten::val::undefined();
+ videoTracks = stream.call<emscripten::val>("getVideoTracks");
+ if (videoTracks.isNull() || videoTracks.isUndefined()) {
+ qCDebug(qWasmMediaRecorder) << "no video tracks";
+ return;
+ }
+ if (videoTracks["length"].as<int>() > 0) {
+ // try to apply the video options
+ qstdweb::Promise::make(videoTracks[0], QStringLiteral("applyConstraints"),
+ { .thenFunc =
+ [this](emscripten::val result) {
+ Q_UNUSED(result)
+ startStream();
+ },
+ .catchFunc =
+ [this](emscripten::val theError) {
+ qWarning() << "setting video params failed error";
+ qCDebug(qWasmMediaRecorder)
+ << theError["code"].as<int>()
+ << QString::fromStdString(theError["message"].as<std::string>());
+ updateError(QMediaRecorder::ResourceError,
+ QString::fromStdString(theError["message"].as<std::string>()));
+ } },
+ constraints);
+ }
+ }
+}
+
+// this starts the recording stream
+void QWasmMediaRecorder::startStream()
+{
+ if (m_mediaRecorder.isUndefined() || m_mediaRecorder.isNull()) {
+ qCDebug(qWasmMediaRecorder) << Q_FUNC_INFO << "could not find MediaStream";
+ return;
+ }
+ qCDebug(qWasmMediaRecorder) << "m_mediaRecorder state:" <<
+ QString::fromStdString(m_mediaRecorder["state"].as<std::string>());
+
+ constexpr int sliceSizeInMs = 250; // TODO find what size is best
+ m_mediaRecorder.call<void>("start", emscripten::val(sliceSizeInMs));
+
+ /* this method can optionally be passed a timeslice argument with a value in milliseconds.
+ * If this is specified, the media will be captured in separate chunks of that duration,
+ * rather than the default behavior of recording the media in a single large chunk.*/
+
+ emit stateChanged(state());
+}
+
+void QWasmMediaRecorder::setUpFileSink()
+{
+ QString m_targetFileName = outputLocation().toLocalFile();
+ QString suffix = m_mediaSettings.mimeType().preferredSuffix();
+ if (m_targetFileName.isEmpty()) {
+ m_targetFileName = "/home/web_user/tmp." + suffix;
+ QPlatformMediaRecorder::setOutputLocation(m_targetFileName);
+ }
+
+ m_outputTarget = new QFile(m_targetFileName, this);
+ if (!m_outputTarget->open(QIODevice::WriteOnly)) {
+ qWarning() << "target file is not writable";
+ return;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/wasm/mediacapture/qwasmmediarecorder_p.h b/src/plugins/multimedia/wasm/mediacapture/qwasmmediarecorder_p.h
new file mode 100644
index 000000000..c325e411b
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediacapture/qwasmmediarecorder_p.h
@@ -0,0 +1,89 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMMEDIARECORDER_H
+#define QWASMMEDIARECORDER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediarecorder_p.h>
+#include <private/qplatformmediacapture_p.h>
+#include <QtCore/qglobal.h>
+#include <QtCore/qloggingcategory.h>
+#include <QElapsedTimer>
+
+#include <emscripten.h>
+#include <emscripten/val.h>
+#include <emscripten/bind.h>
+#include <private/qstdweb_p.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qWasmMediaRecorder)
+
+class QWasmMediaCaptureSession;
+class QIODevice;
+
+class QWasmMediaRecorder final : public QObject, public QPlatformMediaRecorder
+{
+ Q_OBJECT
+public:
+ explicit QWasmMediaRecorder(QMediaRecorder *parent);
+ ~QWasmMediaRecorder() final;
+
+ bool isLocationWritable(const QUrl &location) const override;
+ QMediaRecorder::RecorderState state() const override;
+ qint64 duration() const override;
+ void record(QMediaEncoderSettings &settings) override;
+ void pause() override;
+ void resume() override;
+ void stop() override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session);
+
+private:
+
+ bool hasCamera() const;
+ void startAudioRecording();
+ void setStream(emscripten::val stream);
+ void streamCallback(emscripten::val event);
+ void exceptionCallback(emscripten::val event);
+ void dataAvailableCallback(emscripten::val dataEvent);
+ void startStream();
+ void setTrackContraints(QMediaEncoderSettings &settings, emscripten::val stream);
+ void initUserMedia();
+ void audioDataAvailable(emscripten::val Blob, double timeCodeDifference);
+ void setUpFileSink();
+
+ emscripten::val m_mediaRecorder = emscripten::val::undefined();
+ emscripten::val m_mediaStream = emscripten::val::undefined();
+
+ QWasmMediaCaptureSession *m_session = nullptr;
+ QMediaEncoderSettings m_mediaSettings;
+ QIODevice *m_outputTarget;
+ QScopedPointer<qstdweb::EventCallback> m_mediaStreamDataAvailable;
+ QScopedPointer<qstdweb::EventCallback> m_mediaStreamStopped;
+ QScopedPointer<qstdweb::EventCallback> m_mediaStreamError;
+ QScopedPointer<qstdweb::EventCallback> m_mediaStreamStart;
+ QScopedPointer<qstdweb::EventCallback> m_mediaStreamPause;
+ QScopedPointer<qstdweb::EventCallback> m_mediaStreamResume;
+
+ qint64 m_durationMs = 0;
+ bool m_isRecording = false;
+ QScopedPointer <QElapsedTimer> m_durationTimer;
+
+private Q_SLOTS:
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMMEDIARECORDER_H
diff --git a/src/plugins/multimedia/wasm/mediaplayer/qwasmmediaplayer.cpp b/src/plugins/multimedia/wasm/mediaplayer/qwasmmediaplayer.cpp
new file mode 100644
index 000000000..75886b7c2
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediaplayer/qwasmmediaplayer.cpp
@@ -0,0 +1,475 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmmediaplayer_p.h"
+#include <common/qwasmvideooutput_p.h>
+#include <common/qwasmaudiooutput_p.h>
+#include "qaudiooutput.h"
+
+#include <QtCore/qloggingcategory.h>
+#include <QUuid>
+#include <QtGlobal>
+#include <QMimeDatabase>
+#include <QFileInfo>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(lcMediaPlayer, "qt.multimedia.wasm.mediaplayer");
+
+QWasmMediaPlayer::QWasmMediaPlayer(QMediaPlayer *parent)
+ : QPlatformMediaPlayer(parent),
+ m_videoOutput(new QWasmVideoOutput),
+ m_State(QWasmMediaPlayer::Idle)
+{
+ qCDebug(lcMediaPlayer) << Q_FUNC_INFO << this;
+
+}
+
+QWasmMediaPlayer::~QWasmMediaPlayer()
+{
+ delete m_videoOutput;
+}
+
+void QWasmMediaPlayer::initVideo()
+{
+ m_videoOutput->setVideoMode(QWasmVideoOutput::VideoOutput);
+ QUuid videoElementId = QUuid::createUuid();
+ qCDebug(lcMediaPlayer) << Q_FUNC_INFO << "videoElementId"<< videoElementId << this;
+
+ m_videoOutput->createVideoElement(videoElementId.toString(QUuid::WithoutBraces).toStdString());
+ m_videoOutput->doElementCallbacks();
+ m_videoOutput->createOffscreenElement(QSize(1280, 720));
+ m_videoOutput->updateVideoElementGeometry(QRect(0, 0, 1280, 720)); // initial size 720p standard
+
+ connect(m_videoOutput, &QWasmVideoOutput::bufferingChanged, this,
+ &QWasmMediaPlayer::bufferingChanged);
+ connect(m_videoOutput, &QWasmVideoOutput::errorOccured, this,
+ &QWasmMediaPlayer::errorOccured);
+ connect(m_videoOutput, &QWasmVideoOutput::stateChanged, this,
+ &QWasmMediaPlayer::mediaStateChanged);
+ connect(m_videoOutput, &QWasmVideoOutput::progressChanged, this,
+ &QWasmMediaPlayer::setPositionChanged);
+ connect(m_videoOutput, &QWasmVideoOutput::durationChanged, this,
+ &QWasmMediaPlayer::setDurationChanged);
+ connect(m_videoOutput, &QWasmVideoOutput::sizeChange, this,
+ &QWasmMediaPlayer::videoSizeChanged);
+ connect(m_videoOutput, &QWasmVideoOutput::readyChanged, this,
+ &QWasmMediaPlayer::videoOutputReady);
+ connect(m_videoOutput, &QWasmVideoOutput::statusChanged, this,
+ &QWasmMediaPlayer::onMediaStatusChanged);
+ connect(m_videoOutput, &QWasmVideoOutput::metaDataLoaded, this,
+ &QWasmMediaPlayer::videoMetaDataChanged);
+
+ setVideoAvailable(true);
+}
+
+void QWasmMediaPlayer::initAudio()
+{
+ connect(m_audioOutput->q, &QAudioOutput::deviceChanged,
+ this, &QWasmMediaPlayer::updateAudioDevice);
+ connect(m_audioOutput->q, &QAudioOutput::volumeChanged,
+ this, &QWasmMediaPlayer::volumeChanged);
+ connect(m_audioOutput->q, &QAudioOutput::mutedChanged,
+ this, &QWasmMediaPlayer::mutedChanged);
+
+ connect(m_audioOutput, &QWasmAudioOutput::bufferingChanged, this,
+ &QWasmMediaPlayer::bufferingChanged);
+ connect(m_audioOutput, &QWasmAudioOutput::errorOccured, this,
+ &QWasmMediaPlayer::errorOccured);
+ connect(m_audioOutput, &QWasmAudioOutput::progressChanged, this,
+ &QWasmMediaPlayer::setPositionChanged);
+ connect(m_audioOutput, &QWasmAudioOutput::durationChanged, this,
+ &QWasmMediaPlayer::setDurationChanged);
+ connect(m_audioOutput, &QWasmAudioOutput::statusChanged, this,
+ &QWasmMediaPlayer::onMediaStatusChanged);
+ connect(m_audioOutput, &QWasmAudioOutput::stateChanged, this,
+ &QWasmMediaPlayer::mediaStateChanged);
+ setAudioAvailable(true);
+}
+
+qint64 QWasmMediaPlayer::duration() const
+{
+ return m_videoOutput->getDuration();
+}
+
+qint64 QWasmMediaPlayer::position() const
+{
+ if (mediaStatus() == QMediaPlayer::EndOfMedia)
+ return duration();
+
+ if (m_videoAvailable)
+ return m_videoOutput->getCurrentPosition();
+
+ return 0;
+}
+
+void QWasmMediaPlayer::setPosition(qint64 position)
+{
+ if (!isSeekable())
+ return;
+
+ const int seekPosition = (position > INT_MAX) ? INT_MAX : position;
+
+ if (seekPosition == this->position())
+ return;
+
+ if (mediaStatus() == QMediaPlayer::EndOfMedia)
+ setMediaStatus(QMediaPlayer::LoadedMedia);
+
+ if (m_videoAvailable)
+ return m_videoOutput->seekTo(position);
+
+ emit positionChanged(seekPosition);
+}
+
+void QWasmMediaPlayer::volumeChanged(float gain)
+{
+ if (m_State != QWasmMediaPlayer::Started)
+ return;
+
+ if (m_videoAvailable)
+ m_videoOutput->setVolume(gain);
+}
+
+void QWasmMediaPlayer::mutedChanged(bool muted)
+{
+ if (m_State != QWasmMediaPlayer::Started)
+ return;
+
+ if (m_videoAvailable)
+ m_videoOutput->setMuted(muted);
+}
+
+float QWasmMediaPlayer::bufferProgress() const
+{
+ return qBound(0.0, (m_bufferPercent * .01), 1.0);
+}
+
+bool QWasmMediaPlayer::isAudioAvailable() const
+{
+ return m_audioAvailable;
+}
+
+bool QWasmMediaPlayer::isVideoAvailable() const
+{
+ return m_videoAvailable;
+}
+
+QMediaTimeRange QWasmMediaPlayer::availablePlaybackRanges() const
+{
+ return m_availablePlaybackRange;
+}
+
+void QWasmMediaPlayer::updateAvailablePlaybackRanges()
+{
+ if (m_buffering) {
+ const qint64 pos = position();
+ const qint64 end = (duration() / 100) * m_bufferPercent;
+ m_availablePlaybackRange.addInterval(pos, end);
+ } else if (isSeekable()) {
+ m_availablePlaybackRange = QMediaTimeRange(0, duration());
+ } else {
+ m_availablePlaybackRange = QMediaTimeRange();
+ }
+}
+
+qreal QWasmMediaPlayer::playbackRate() const
+{
+ if (m_State != QWasmMediaPlayer::Started)
+ return 0;
+
+ if (isVideoAvailable())
+ return m_videoOutput->playbackRate();
+ return 0;
+}
+
+void QWasmMediaPlayer::setPlaybackRate(qreal rate)
+{
+ if (m_State != QWasmMediaPlayer::Started || !isVideoAvailable())
+ return;
+
+ m_videoOutput->setPlaybackRate(rate);
+ emit playbackRateChanged(rate);
+}
+
+QUrl QWasmMediaPlayer::media() const
+{
+ return m_mediaContent;
+}
+
+const QIODevice *QWasmMediaPlayer::mediaStream() const
+{
+ return m_mediaStream;
+}
+
+void QWasmMediaPlayer::setMedia(const QUrl &mediaContent, QIODevice *stream)
+{
+ qCDebug(lcMediaPlayer) << Q_FUNC_INFO << mediaContent << stream;
+ QMimeDatabase db;
+
+ if (mediaContent.isEmpty()) {
+ if (stream) {
+ m_mediaStream = stream;
+ qCDebug(lcMediaPlayer) << db.mimeTypeForData(stream).name();
+ if (db.mimeTypeForData(stream).name().contains("audio")) {
+ setAudioAvailable(true);
+ m_audioOutput->setSource(m_mediaStream);
+ } else { // treat octet-stream as video
+ setVideoAvailable(true);
+ m_videoOutput->setSource(m_mediaStream);
+ }
+ } else {
+
+ setMediaStatus(QMediaPlayer::NoMedia);
+ }
+ } else {
+ QString sourceFile = mediaContent.toLocalFile();
+ qCDebug(lcMediaPlayer) << db.mimeTypeForFile(QFileInfo(sourceFile)).name();
+ if (db.mimeTypeForFile(QFileInfo(sourceFile)).name().contains("audio")) {
+ setAudioAvailable(true);
+ m_audioOutput->setSource(mediaContent);
+ } else { // treat octet-stream as video
+ setVideoAvailable(true);
+ m_videoOutput->setSource(mediaContent);
+ }
+ }
+
+ resetBufferingProgress();
+}
+
+void QWasmMediaPlayer::setVideoSink(QVideoSink *sink)
+{
+ if (m_videoSink == sink)
+ return;
+
+ m_videoSink = sink;
+
+ if (!m_videoSink)
+ return;
+
+ initVideo();
+ m_videoOutput->setSurface(sink);
+ setVideoAvailable(true);
+ if (isAudioAvailable() && m_audioOutput)
+ m_audioOutput->setVideoElement(m_videoOutput->currentVideoElement());
+}
+
+void QWasmMediaPlayer::setAudioOutput(QPlatformAudioOutput *output)
+{
+ if (m_audioOutput == output)
+ return;
+
+ if (m_audioOutput)
+ m_audioOutput->q->disconnect(this);
+ m_audioOutput = static_cast<QWasmAudioOutput *>(output);
+ setAudioAvailable(true);
+}
+
+void QWasmMediaPlayer::updateAudioDevice()
+{
+ if (m_audioOutput) {
+ m_audioOutput->setAudioDevice(m_audioOutput->q->device());
+ }
+}
+
+void QWasmMediaPlayer::play()
+{
+ resetCurrentLoop();
+
+ if (isVideoAvailable()) {
+ m_videoOutput->start();
+ m_playWhenReady = true;
+ } else {
+ initAudio();
+ if (isAudioAvailable()) {
+ m_audioOutput->start();
+ }
+ }
+
+#ifdef DEBUG_AUDIOENGINE
+ QAudioEnginePrivate::checkNoError("play");
+#endif
+}
+
+void QWasmMediaPlayer::pause()
+{
+ if ((m_State
+ & (QWasmMediaPlayer::Started | QWasmMediaPlayer::Paused
+ | QWasmMediaPlayer::PlaybackCompleted)) == 0) {
+ return;
+ }
+ if (isVideoAvailable()) {
+ m_videoOutput->pause();
+ } else {
+ m_audioOutput->pause();
+ stateChanged(QMediaPlayer::PausedState);
+ }
+}
+
+void QWasmMediaPlayer::stop()
+{
+ m_playWhenReady = false;
+
+ if (m_State == QWasmMediaPlayer::Idle || m_State == QWasmMediaPlayer::PlaybackCompleted
+ || m_State == QWasmMediaPlayer::Stopped) {
+ qWarning() << Q_FUNC_INFO << __LINE__;
+ return;
+ }
+
+ if (isVideoAvailable()) {
+ m_videoOutput->stop();
+ } else {
+ m_audioOutput->stop();
+ }
+
+}
+
+bool QWasmMediaPlayer::isSeekable() const
+{
+ return isVideoAvailable() && m_videoOutput->isVideoSeekable();
+}
+
+void QWasmMediaPlayer::errorOccured(qint32 code, const QString &message)
+{
+ QString errorString;
+ QMediaPlayer::Error error = QMediaPlayer::ResourceError;
+
+ switch (code) {
+ case QWasmMediaNetworkState::NetworkEmpty: // no data
+ break;
+ case QWasmMediaNetworkState::NetworkIdle:
+ break;
+ case QWasmMediaNetworkState::NetworkLoading:
+ break;
+ case QWasmMediaNetworkState::NetworkNoSource: // no source
+ error = QMediaPlayer::ResourceError;
+ errorString = message;
+ break;
+ };
+
+ emit QPlatformMediaPlayer::error(error, errorString);
+}
+
+void QWasmMediaPlayer::bufferingChanged(qint32 percent)
+{
+ m_buffering = percent != 100;
+ m_bufferPercent = percent;
+
+ updateAvailablePlaybackRanges();
+ emit bufferProgressChanged(bufferProgress());
+}
+
+void QWasmMediaPlayer::videoSizeChanged(qint32 width, qint32 height)
+{
+ QSize newSize(width, height);
+
+ if (width == 0 || height == 0 || newSize == m_videoSize)
+ return;
+
+ m_videoSize = newSize;
+}
+
+void QWasmMediaPlayer::mediaStateChanged(QWasmMediaPlayer::QWasmMediaPlayerState state)
+{
+ m_State = state;
+ QMediaPlayer::PlaybackState m_mediaPlayerState;
+ switch (m_State) {
+ case QWasmMediaPlayer::Started:
+ m_mediaPlayerState = QMediaPlayer::PlayingState;
+ break;
+ case QWasmMediaPlayer::Paused:
+ m_mediaPlayerState = QMediaPlayer::PausedState;
+ break;
+ case QWasmMediaPlayer::Stopped:
+ m_mediaPlayerState = QMediaPlayer::StoppedState;
+ break;
+ default:
+ m_mediaPlayerState = QMediaPlayer::StoppedState;
+ break;
+ };
+
+ QPlatformMediaPlayer::stateChanged(m_mediaPlayerState);
+}
+
+int QWasmMediaPlayer::trackCount(TrackType trackType)
+{
+ Q_UNUSED(trackType)
+ // TODO QTBUG-108517
+ return 0; // tracks.count();
+}
+
+void QWasmMediaPlayer::setPositionChanged(qint64 position)
+{
+ QPlatformMediaPlayer::positionChanged(position);
+}
+
+void QWasmMediaPlayer::setDurationChanged(qint64 duration)
+{
+ QPlatformMediaPlayer::durationChanged(duration);
+}
+
+void QWasmMediaPlayer::videoOutputReady(bool ready)
+{
+ setVideoAvailable(ready);
+
+ if (m_playWhenReady && m_videoOutput->isReady())
+ play();
+}
+
+void QWasmMediaPlayer::setMediaStatus(QMediaPlayer::MediaStatus status)
+{
+ mediaStatusChanged(status);
+
+ switch (status) {
+ case QMediaPlayer::NoMedia:
+ case QMediaPlayer::InvalidMedia:
+ emit durationChanged(0);
+ break;
+ case QMediaPlayer::EndOfMedia:
+ setPositionChanged(position());
+ default:
+ break;
+ };
+}
+
+void QWasmMediaPlayer::setAudioAvailable(bool available)
+{
+ if (m_audioAvailable == available)
+ return;
+
+ m_audioAvailable = available;
+ emit audioAvailableChanged(m_audioAvailable);
+}
+
+void QWasmMediaPlayer::setVideoAvailable(bool available)
+{
+ if (m_videoAvailable == available)
+ return;
+
+ if (!available)
+ m_videoSize = QSize();
+
+ m_videoAvailable = available;
+ emit videoAvailableChanged(m_videoAvailable);
+}
+
+void QWasmMediaPlayer::resetBufferingProgress()
+{
+ m_buffering = false;
+ m_bufferPercent = 0;
+ m_availablePlaybackRange = QMediaTimeRange();
+}
+
+void QWasmMediaPlayer::onMediaStatusChanged(QMediaPlayer::MediaStatus status)
+{
+ setMediaStatus(status);
+}
+
+void QWasmMediaPlayer::videoMetaDataChanged()
+{
+ metaDataChanged();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwasmmediaplayer_p.cpp"
diff --git a/src/plugins/multimedia/wasm/mediaplayer/qwasmmediaplayer_p.h b/src/plugins/multimedia/wasm/mediaplayer/qwasmmediaplayer_p.h
new file mode 100644
index 000000000..9269ecdb6
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediaplayer/qwasmmediaplayer_p.h
@@ -0,0 +1,124 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMMEDIAPLAYER_H
+#define QWASMMEDIAPLAYER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qglobal.h>
+#include <private/qplatformmediaplayer_p.h>
+#include <qsize.h>
+#include <qurl.h>
+#include <QtCore/qpointer.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWasmAudioOutput;
+class QWasmVideoOutput;
+
+class QWasmMediaPlayer : public QObject, public QPlatformMediaPlayer
+{
+ Q_OBJECT
+
+public:
+ explicit QWasmMediaPlayer(QMediaPlayer *parent = 0);
+ ~QWasmMediaPlayer() override;
+
+ enum QWasmMediaPlayerState {
+ Error,
+ Idle,
+ Uninitialized,
+ Preparing,
+ Prepared,
+ Started,
+ Paused,
+ Stopped,
+ PlaybackCompleted
+ };
+ Q_ENUM(QWasmMediaPlayerState)
+
+ enum QWasmMediaNetworkState { NetworkEmpty = 0, NetworkIdle, NetworkLoading, NetworkNoSource };
+ Q_ENUM(QWasmMediaNetworkState)
+
+ qint64 duration() const override;
+ qint64 position() const override;
+ float bufferProgress() const override;
+ bool isAudioAvailable() const override;
+ bool isVideoAvailable() const override;
+ QMediaTimeRange availablePlaybackRanges() const override;
+ qreal playbackRate() const override;
+ void setPlaybackRate(qreal rate) override;
+ QUrl media() const override;
+ const QIODevice *mediaStream() const override;
+ void setMedia(const QUrl &mediaContent, QIODevice *stream) override;
+ void setVideoSink(QVideoSink *surface) override;
+ void setAudioOutput(QPlatformAudioOutput *output) override;
+ void setPosition(qint64 position) override;
+ void play() override;
+ void pause() override;
+ void stop() override;
+ bool isSeekable() const override;
+ int trackCount(TrackType trackType) override;
+
+ void updateAudioDevice();
+
+private Q_SLOTS:
+ void volumeChanged(float volume);
+ void mutedChanged(bool muted);
+ void videoOutputReady(bool ready);
+ void errorOccured(qint32 code, const QString &message);
+ void bufferingChanged(qint32 percent);
+ void videoSizeChanged(qint32 width, qint32 height);
+ void mediaStateChanged(QWasmMediaPlayer::QWasmMediaPlayerState state);
+ void setPositionChanged(qint64 position);
+ void setDurationChanged(qint64 duration);
+ void videoMetaDataChanged();
+
+ void onMediaStatusChanged(QMediaPlayer::MediaStatus status);
+
+private:
+ void setMediaStatus(QMediaPlayer::MediaStatus status);
+ void setAudioAvailable(bool available);
+ void setVideoAvailable(bool available);
+ void updateAvailablePlaybackRanges();
+ void resetBufferingProgress();
+
+ void setSubtitle(QString subtitle);
+ void disableTrack(TrackType trackType);
+ void initVideo();
+ void initAudio();
+
+ friend class StateChangeNotifier;
+
+ QPointer<QWasmVideoOutput> m_videoOutput;
+ QWasmAudioOutput *m_audioOutput = nullptr;
+
+ QUrl m_mediaContent;
+ QIODevice *m_mediaStream = nullptr;
+
+ QVideoSink *m_videoSink = nullptr;
+ int m_bufferPercent = -1;
+ bool m_audioAvailable = false;
+ bool m_videoAvailable = false;
+ QSize m_videoSize;
+ bool m_buffering = false;
+ QMediaTimeRange m_availablePlaybackRange;
+ int m_State;
+
+ bool m_playWhenReady = false;
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMMEDIAPLAYER_H
diff --git a/src/plugins/multimedia/wasm/mediaplayer/qwasmvideosink.cpp b/src/plugins/multimedia/wasm/mediaplayer/qwasmvideosink.cpp
new file mode 100644
index 000000000..b6fe0e8e0
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediaplayer/qwasmvideosink.cpp
@@ -0,0 +1,26 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmvideosink_p.h"
+
+#include <QtGui/rhi/qrhi.h>
+
+QT_BEGIN_NAMESPACE
+
+QWasmVideoSink::QWasmVideoSink(QVideoSink *parent)
+ : QPlatformVideoSink(parent)
+{
+}
+
+void QWasmVideoSink::setRhi(QRhi *rhi)
+{
+ if (rhi && rhi->backend() != QRhi::OpenGLES2)
+ rhi = nullptr;
+ if (m_rhi == rhi)
+ return;
+ m_rhi = rhi;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwasmvideosink_p.cpp"
diff --git a/src/plugins/multimedia/wasm/mediaplayer/qwasmvideosink_p.h b/src/plugins/multimedia/wasm/mediaplayer/qwasmvideosink_p.h
new file mode 100644
index 000000000..5f2885249
--- /dev/null
+++ b/src/plugins/multimedia/wasm/mediaplayer/qwasmvideosink_p.h
@@ -0,0 +1,40 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QWASMVIDEOSINK_H
+#define QWASMVIDEOSINK_H
+
+#include <private/qplatformvideosink_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoSink;
+class QRhi;
+
+class QWasmVideoSink : public QPlatformVideoSink
+{
+ Q_OBJECT
+
+public:
+ explicit QWasmVideoSink(QVideoSink *parent = 0);
+
+ void setRhi(QRhi *) override;
+
+private:
+ QRhi *m_rhi = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMVIDEOSINK_H
diff --git a/src/plugins/multimedia/wasm/qwasmmediaintegration.cpp b/src/plugins/multimedia/wasm/qwasmmediaintegration.cpp
new file mode 100644
index 000000000..effc194a4
--- /dev/null
+++ b/src/plugins/multimedia/wasm/qwasmmediaintegration.cpp
@@ -0,0 +1,109 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwasmmediaintegration_p.h"
+#include <QLoggingCategory>
+
+#include <QCamera>
+#include <QCameraDevice>
+
+#include <private/qplatformmediaformatinfo_p.h>
+#include <private/qplatformmediaplugin_p.h>
+#include <private/qplatformmediadevices_p.h>
+#include <private/qplatformvideodevices_p.h>
+
+#include "mediaplayer/qwasmmediaplayer_p.h"
+#include "mediaplayer/qwasmvideosink_p.h"
+#include "qwasmaudioinput_p.h"
+#include "common/qwasmaudiooutput_p.h"
+
+#include "mediacapture/qwasmmediacapturesession_p.h"
+#include "mediacapture/qwasmmediarecorder_p.h"
+#include "mediacapture/qwasmcamera_p.h"
+#include "mediacapture/qwasmmediacapturesession_p.h"
+#include "mediacapture/qwasmimagecapture_p.h"
+
+QT_BEGIN_NAMESPACE
+
+
+class QWasmMediaPlugin : public QPlatformMediaPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QPlatformMediaPlugin_iid FILE "wasm.json")
+
+public:
+ QWasmMediaPlugin()
+ : QPlatformMediaPlugin()
+ {}
+
+ QPlatformMediaIntegration *create(const QString &name) override
+ {
+ if (name == u"wasm")
+ return new QWasmMediaIntegration;
+ return nullptr;
+ }
+};
+
+QWasmMediaIntegration::QWasmMediaIntegration()
+ : QPlatformMediaIntegration(QLatin1String("wasm")) { }
+
+QMaybe<QPlatformMediaPlayer *> QWasmMediaIntegration::createPlayer(QMediaPlayer *player)
+{
+ return new QWasmMediaPlayer(player);
+}
+
+QMaybe<QPlatformVideoSink *> QWasmMediaIntegration::createVideoSink(QVideoSink *sink)
+{
+ return new QWasmVideoSink(sink);
+}
+
+QMaybe<QPlatformAudioInput *> QWasmMediaIntegration::createAudioInput(QAudioInput *audioInput)
+{
+ return new QWasmAudioInput(audioInput);
+}
+
+QMaybe<QPlatformAudioOutput *> QWasmMediaIntegration::createAudioOutput(QAudioOutput *q)
+{
+ return new QWasmAudioOutput(q);
+}
+
+QPlatformMediaFormatInfo *QWasmMediaIntegration::createFormatInfo()
+{
+ // TODO: create custom implementation
+ return new QPlatformMediaFormatInfo;
+}
+
+QPlatformVideoDevices *QWasmMediaIntegration::createVideoDevices()
+{
+ return new QWasmCameraDevices(this);
+}
+
+QMaybe<QPlatformMediaCaptureSession *> QWasmMediaIntegration::createCaptureSession()
+{
+ return new QWasmMediaCaptureSession();
+}
+
+QMaybe<QPlatformMediaRecorder *> QWasmMediaIntegration::createRecorder(QMediaRecorder *recorder)
+{
+ return new QWasmMediaRecorder(recorder);
+}
+
+QMaybe<QPlatformCamera *> QWasmMediaIntegration::createCamera(QCamera *camera)
+{
+ return new QWasmCamera(camera);
+}
+
+QMaybe<QPlatformImageCapture *>
+QWasmMediaIntegration::createImageCapture(QImageCapture *imageCapture)
+{
+ return new QWasmImageCapture(imageCapture);
+}
+
+QList<QCameraDevice> QWasmMediaIntegration::videoInputs()
+{
+ return videoDevices()->videoDevices();
+}
+
+QT_END_NAMESPACE
+
+#include "qwasmmediaintegration.moc"
diff --git a/src/plugins/multimedia/wasm/qwasmmediaintegration_p.h b/src/plugins/multimedia/wasm/qwasmmediaintegration_p.h
new file mode 100644
index 000000000..d946c1854
--- /dev/null
+++ b/src/plugins/multimedia/wasm/qwasmmediaintegration_p.h
@@ -0,0 +1,50 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWASMMEDIAINTEGRATION_H
+#define QWASMMEDIAINTEGRATION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaintegration_p.h>
+
+#include <private/qwasmmediadevices_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWasmMediaDevices;
+
+class QWasmMediaIntegration : public QPlatformMediaIntegration
+{
+public:
+ QWasmMediaIntegration();
+
+ QMaybe<QPlatformMediaPlayer *> createPlayer(QMediaPlayer *player) override;
+ QMaybe<QPlatformVideoSink *> createVideoSink(QVideoSink *sink) override;
+
+ QMaybe<QPlatformAudioInput *> createAudioInput(QAudioInput *audioInput) override;
+ QMaybe<QPlatformAudioOutput *> createAudioOutput(QAudioOutput *q) override;
+
+ QMaybe<QPlatformMediaCaptureSession *> createCaptureSession() override;
+ QMaybe<QPlatformCamera *> createCamera(QCamera *camera) override;
+ QMaybe<QPlatformMediaRecorder *> createRecorder(QMediaRecorder *recorder) override;
+ QMaybe<QPlatformImageCapture *> createImageCapture(QImageCapture *imageCapture) override;
+ QList<QCameraDevice> videoInputs() override;
+
+protected:
+ QPlatformMediaFormatInfo *createFormatInfo() override;
+ QPlatformVideoDevices *createVideoDevices() override;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWASMMEDIAINTEGRATION_H
diff --git a/src/plugins/multimedia/wasm/wasm.json b/src/plugins/multimedia/wasm/wasm.json
new file mode 100644
index 000000000..02335aebe
--- /dev/null
+++ b/src/plugins/multimedia/wasm/wasm.json
@@ -0,0 +1,5 @@
+{
+ "Keys": [
+ "wasm"
+ ]
+}
diff --git a/src/plugins/multimedia/windows/CMakeLists.txt b/src/plugins/multimedia/windows/CMakeLists.txt
new file mode 100644
index 000000000..963081e0a
--- /dev/null
+++ b/src/plugins/multimedia/windows/CMakeLists.txt
@@ -0,0 +1,69 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_internal_add_plugin(QWindowsMediaPlugin
+ OUTPUT_NAME windowsmediaplugin
+ PLUGIN_TYPE multimedia
+ SOURCES
+ common/mfmetadata.cpp common/mfmetadata_p.h
+ decoder/mfaudiodecodercontrol.cpp decoder/mfaudiodecodercontrol_p.h
+ decoder/mfdecodersourcereader.cpp decoder/mfdecodersourcereader_p.h
+ evr/evrcustompresenter.cpp evr/evrcustompresenter_p.h
+ evr/evrd3dpresentengine.cpp evr/evrd3dpresentengine_p.h
+ evr/evrhelpers.cpp evr/evrhelpers_p.h
+ evr/evrvideowindowcontrol.cpp evr/evrvideowindowcontrol_p.h
+ mfstream.cpp mfstream_p.h
+ player/mfactivate.cpp player/mfactivate_p.h
+ player/mfevrvideowindowcontrol.cpp player/mfevrvideowindowcontrol_p.h
+ player/mfplayercontrol.cpp player/mfplayercontrol_p.h
+ player/mfplayersession.cpp player/mfplayersession_p.h
+ player/mfvideorenderercontrol.cpp player/mfvideorenderercontrol_p.h
+ mediacapture/qwindowscamera.cpp
+ mediacapture/qwindowscamera_p.h
+ mediacapture/qwindowsimagecapture.cpp
+ mediacapture/qwindowsimagecapture_p.h
+ mediacapture/qwindowsmediacapture.cpp
+ mediacapture/qwindowsmediacapture_p.h
+ mediacapture/qwindowsmediadevicereader.cpp
+ mediacapture/qwindowsmediadevicereader_p.h
+ mediacapture/qwindowsmediadevicesession.cpp
+ mediacapture/qwindowsmediadevicesession_p.h
+ mediacapture/qwindowsmediaencoder.cpp
+ mediacapture/qwindowsmediaencoder_p.h
+ qwindowsformatinfo.cpp qwindowsformatinfo_p.h
+ qwindowsintegration.cpp qwindowsintegration_p.h
+ qwindowsvideodevices.cpp qwindowsvideodevices_p.h
+ sourceresolver.cpp sourceresolver_p.h
+ INCLUDE_DIRECTORIES
+ audio
+ common
+ decoder
+ evr
+ player
+ mediacapture
+ LIBRARIES
+ Qt::MultimediaPrivate
+ Qt::CorePrivate
+ uuid
+ WMF::WMF
+ d3d9
+ dxva2
+ evr
+ gdi32
+ ksuser
+ mf
+ mfcore
+ mfplat
+ mfreadwrite
+ mfuuid
+ ole32
+ oleaut32
+ propsys
+ shlwapi
+ strmiids
+ amstrmid
+ user32
+ winmm
+ wmcodecdspuuid
+)
+
diff --git a/src/plugins/multimedia/windows/common/mfmetadata.cpp b/src/plugins/multimedia/windows/common/mfmetadata.cpp
new file mode 100644
index 000000000..cc8c425e3
--- /dev/null
+++ b/src/plugins/multimedia/windows/common/mfmetadata.cpp
@@ -0,0 +1,408 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <qmediametadata.h>
+#include <qdatetime.h>
+#include <qtimezone.h>
+#include <qimage.h>
+#include <quuid.h>
+
+#include <mfapi.h>
+#include <mfidl.h>
+#include <propvarutil.h>
+#include <propkey.h>
+
+#include "private/qwindowsmultimediautils_p.h"
+#include "mfmetadata_p.h"
+
+//#define DEBUG_MEDIAFOUNDATION
+
+static const PROPERTYKEY PROP_KEY_NULL = {GUID_NULL, 0};
+
+static QVariant convertValue(const PROPVARIANT& var)
+{
+ QVariant value;
+ switch (var.vt) {
+ case VT_LPWSTR:
+ value = QString::fromUtf16(reinterpret_cast<const char16_t *>(var.pwszVal));
+ break;
+ case VT_UI4:
+ value = uint(var.ulVal);
+ break;
+ case VT_UI8:
+ value = qulonglong(var.uhVal.QuadPart);
+ break;
+ case VT_BOOL:
+ value = bool(var.boolVal);
+ break;
+ case VT_FILETIME:
+ SYSTEMTIME t;
+ if (!FileTimeToSystemTime(&var.filetime, &t))
+ break;
+
+ value = QDateTime(QDate(t.wYear, t.wMonth, t.wDay),
+ QTime(t.wHour, t.wMinute, t.wSecond, t.wMilliseconds),
+ QTimeZone(QTimeZone::UTC));
+ break;
+ case VT_STREAM:
+ {
+ STATSTG stat;
+ if (FAILED(var.pStream->Stat(&stat, STATFLAG_NONAME)))
+ break;
+ void *data = malloc(stat.cbSize.QuadPart);
+ ULONG read = 0;
+ if (FAILED(var.pStream->Read(data, stat.cbSize.QuadPart, &read))) {
+ free(data);
+ break;
+ }
+ value = QImage::fromData((const uchar*)data, read);
+ free(data);
+ }
+ break;
+ case VT_VECTOR | VT_LPWSTR:
+ QStringList vList;
+ for (ULONG i = 0; i < var.calpwstr.cElems; ++i)
+ vList.append(QString::fromUtf16(reinterpret_cast<const char16_t *>(var.calpwstr.pElems[i])));
+ value = vList;
+ break;
+ }
+ return value;
+}
+
+static QVariant metaDataValue(IPropertyStore *content, const PROPERTYKEY &key)
+{
+ QVariant value;
+
+ PROPVARIANT var;
+ PropVariantInit(&var);
+ HRESULT hr = S_FALSE;
+ if (content)
+ hr = content->GetValue(key, &var);
+
+ if (SUCCEEDED(hr)) {
+ value = convertValue(var);
+
+ // some metadata needs to be reformatted
+ if (value.isValid() && content) {
+ if (key == PKEY_Media_ClassPrimaryID /*QMediaMetaData::MediaType*/) {
+ QString v = value.toString();
+ if (v == QLatin1String("{D1607DBC-E323-4BE2-86A1-48A42A28441E}"))
+ value = QStringLiteral("Music");
+ else if (v == QLatin1String("{DB9830BD-3AB3-4FAB-8A37-1A995F7FF74B}"))
+ value = QStringLiteral("Video");
+ else if (v == QLatin1String("{01CD0F29-DA4E-4157-897B-6275D50C4F11}"))
+ value = QStringLiteral("Audio");
+ else if (v == QLatin1String("{FCF24A76-9A57-4036-990D-E35DD8B244E1}"))
+ value = QStringLiteral("Other");
+ } else if (key == PKEY_Media_Duration) {
+ // duration is provided in 100-nanosecond units, convert to milliseconds
+ value = (value.toLongLong() + 10000) / 10000;
+ } else if (key == PKEY_Video_Compression) {
+ value = int(QWindowsMultimediaUtils::codecForVideoFormat(value.toUuid()));
+ } else if (key == PKEY_Audio_Format) {
+ value = int(QWindowsMultimediaUtils::codecForAudioFormat(value.toUuid()));
+ } else if (key == PKEY_Video_FrameHeight /*Resolution*/) {
+ QSize res;
+ res.setHeight(value.toUInt());
+ if (content && SUCCEEDED(content->GetValue(PKEY_Video_FrameWidth, &var)))
+ res.setWidth(convertValue(var).toUInt());
+ value = res;
+ } else if (key == PKEY_Video_Orientation) {
+ uint orientation = 0;
+ if (content && SUCCEEDED(content->GetValue(PKEY_Video_Orientation, &var)))
+ orientation = convertValue(var).toUInt();
+ value = orientation;
+ } else if (key == PKEY_Video_FrameRate) {
+ value = value.toReal() / 1000.f;
+ }
+ }
+ }
+
+ PropVariantClear(&var);
+ return value;
+}
+
+QMediaMetaData MFMetaData::fromNative(IMFMediaSource* mediaSource)
+{
+ QMediaMetaData metaData;
+
+ IPropertyStore *content = nullptr;
+ if (!SUCCEEDED(MFGetService(mediaSource, MF_PROPERTY_HANDLER_SERVICE, IID_PPV_ARGS(&content))))
+ return metaData;
+
+ Q_ASSERT(content);
+ DWORD cProps;
+ if (SUCCEEDED(content->GetCount(&cProps))) {
+ for (DWORD i = 0; i < cProps; i++)
+ {
+ PROPERTYKEY key;
+ if (FAILED(content->GetAt(i, &key)))
+ continue;
+ QMediaMetaData::Key mediaKey;
+ if (key == PKEY_Author) {
+ mediaKey = QMediaMetaData::Author;
+ } else if (key == PKEY_Title) {
+ mediaKey = QMediaMetaData::Title;
+// } else if (key == PKEY_Media_SubTitle) {
+// mediaKey = QMediaMetaData::SubTitle;
+// } else if (key == PKEY_ParentalRating) {
+// mediaKey = QMediaMetaData::ParentalRating;
+ } else if (key == PKEY_Media_EncodingSettings) {
+ mediaKey = QMediaMetaData::Description;
+ } else if (key == PKEY_Copyright) {
+ mediaKey = QMediaMetaData::Copyright;
+ } else if (key == PKEY_Comment) {
+ mediaKey = QMediaMetaData::Comment;
+ } else if (key == PKEY_Media_ProviderStyle) {
+ mediaKey = QMediaMetaData::Genre;
+ } else if (key == PKEY_Media_DateEncoded) {
+ mediaKey = QMediaMetaData::Date;
+// } else if (key == PKEY_Rating) {
+// mediaKey = QMediaMetaData::UserRating;
+// } else if (key == PKEY_Keywords) {
+// mediaKey = QMediaMetaData::Keywords;
+ } else if (key == PKEY_Language) {
+ mediaKey = QMediaMetaData::Language;
+ } else if (key == PKEY_Media_Publisher) {
+ mediaKey = QMediaMetaData::Publisher;
+ } else if (key == PKEY_Media_ClassPrimaryID) {
+ mediaKey = QMediaMetaData::MediaType;
+ } else if (key == PKEY_Media_Duration) {
+ mediaKey = QMediaMetaData::Duration;
+ } else if (key == PKEY_Audio_EncodingBitrate) {
+ mediaKey = QMediaMetaData::AudioBitRate;
+ } else if (key == PKEY_Audio_Format) {
+ mediaKey = QMediaMetaData::AudioCodec;
+// } else if (key == PKEY_Media_AverageLevel) {
+// mediaKey = QMediaMetaData::AverageLevel;
+// } else if (key == PKEY_Audio_ChannelCount) {
+// mediaKey = QMediaMetaData::ChannelCount;
+// } else if (key == PKEY_Audio_PeakValue) {
+// mediaKey = QMediaMetaData::PeakValue;
+// } else if (key == PKEY_Audio_SampleRate) {
+// mediaKey = QMediaMetaData::SampleRate;
+ } else if (key == PKEY_Music_AlbumTitle) {
+ mediaKey = QMediaMetaData::AlbumTitle;
+ } else if (key == PKEY_Music_AlbumArtist) {
+ mediaKey = QMediaMetaData::AlbumArtist;
+ } else if (key == PKEY_Music_Artist) {
+ mediaKey = QMediaMetaData::ContributingArtist;
+ } else if (key == PKEY_Music_Composer) {
+ mediaKey = QMediaMetaData::Composer;
+// } else if (key == PKEY_Music_Conductor) {
+// mediaKey = QMediaMetaData::Conductor;
+// } else if (key == PKEY_Music_Lyrics) {
+// mediaKey = QMediaMetaData::Lyrics;
+// } else if (key == PKEY_Music_Mood) {
+// mediaKey = QMediaMetaData::Mood;
+ } else if (key == PKEY_Music_TrackNumber) {
+ mediaKey = QMediaMetaData::TrackNumber;
+ } else if (key == PKEY_Music_Genre) {
+ mediaKey = QMediaMetaData::Genre;
+ } else if (key == PKEY_ThumbnailStream) {
+ mediaKey = QMediaMetaData::ThumbnailImage;
+ } else if (key == PKEY_Video_FrameHeight) {
+ mediaKey = QMediaMetaData::Resolution;
+ } else if (key == PKEY_Video_Orientation) {
+ mediaKey = QMediaMetaData::Orientation;
+ } else if (key == PKEY_Video_FrameRate) {
+ mediaKey = QMediaMetaData::VideoFrameRate;
+ } else if (key == PKEY_Video_EncodingBitrate) {
+ mediaKey = QMediaMetaData::VideoBitRate;
+ } else if (key == PKEY_Video_Compression) {
+ mediaKey = QMediaMetaData::VideoCodec;
+// } else if (key == PKEY_Video_Director) {
+// mediaKey = QMediaMetaData::Director;
+// } else if (key == PKEY_Media_Writer) {
+// mediaKey = QMediaMetaData::Writer;
+ } else {
+ continue;
+ }
+ metaData.insert(mediaKey, metaDataValue(content, key));
+ }
+ }
+
+ content->Release();
+
+ return metaData;
+}
+
+static REFPROPERTYKEY propertyKeyForMetaDataKey(QMediaMetaData::Key key)
+{
+ switch (key) {
+ case QMediaMetaData::Key::Title:
+ return PKEY_Title;
+ case QMediaMetaData::Key::Author:
+ return PKEY_Author;
+ case QMediaMetaData::Key::Comment:
+ return PKEY_Comment;
+ case QMediaMetaData::Key::Genre:
+ return PKEY_Music_Genre;
+ case QMediaMetaData::Key::Copyright:
+ return PKEY_Copyright;
+ case QMediaMetaData::Key::Publisher:
+ return PKEY_Media_Publisher;
+ case QMediaMetaData::Key::Url:
+ return PKEY_Media_AuthorUrl;
+ case QMediaMetaData::Key::AlbumTitle:
+ return PKEY_Music_AlbumTitle;
+ case QMediaMetaData::Key::AlbumArtist:
+ return PKEY_Music_AlbumArtist;
+ case QMediaMetaData::Key::TrackNumber:
+ return PKEY_Music_TrackNumber;
+ case QMediaMetaData::Key::Date:
+ return PKEY_Media_DateEncoded;
+ case QMediaMetaData::Key::Composer:
+ return PKEY_Music_Composer;
+ case QMediaMetaData::Key::Duration:
+ return PKEY_Media_Duration;
+ case QMediaMetaData::Key::Language:
+ return PKEY_Language;
+ case QMediaMetaData::Key::Description:
+ return PKEY_Media_EncodingSettings;
+ case QMediaMetaData::Key::AudioBitRate:
+ return PKEY_Audio_EncodingBitrate;
+ case QMediaMetaData::Key::ContributingArtist:
+ return PKEY_Music_Artist;
+ case QMediaMetaData::Key::ThumbnailImage:
+ return PKEY_ThumbnailStream;
+ case QMediaMetaData::Key::Orientation:
+ return PKEY_Video_Orientation;
+ case QMediaMetaData::Key::VideoFrameRate:
+ return PKEY_Video_FrameRate;
+ case QMediaMetaData::Key::VideoBitRate:
+ return PKEY_Video_EncodingBitrate;
+ case QMediaMetaData::MediaType:
+ return PKEY_Media_ClassPrimaryID;
+ default:
+ return PROP_KEY_NULL;
+ }
+}
+
+static void setStringProperty(IPropertyStore *content, REFPROPERTYKEY key, const QString &value)
+{
+ PROPVARIANT propValue = {};
+ if (SUCCEEDED(InitPropVariantFromString(reinterpret_cast<LPCWSTR>(value.utf16()), &propValue))) {
+ if (SUCCEEDED(PSCoerceToCanonicalValue(key, &propValue)))
+ content->SetValue(key, propValue);
+ PropVariantClear(&propValue);
+ }
+}
+
+static void setUInt32Property(IPropertyStore *content, REFPROPERTYKEY key, quint32 value)
+{
+ PROPVARIANT propValue = {};
+ if (SUCCEEDED(InitPropVariantFromUInt32(ULONG(value), &propValue))) {
+ if (SUCCEEDED(PSCoerceToCanonicalValue(key, &propValue)))
+ content->SetValue(key, propValue);
+ PropVariantClear(&propValue);
+ }
+}
+
+static void setUInt64Property(IPropertyStore *content, REFPROPERTYKEY key, quint64 value)
+{
+ PROPVARIANT propValue = {};
+ if (SUCCEEDED(InitPropVariantFromUInt64(ULONGLONG(value), &propValue))) {
+ if (SUCCEEDED(PSCoerceToCanonicalValue(key, &propValue)))
+ content->SetValue(key, propValue);
+ PropVariantClear(&propValue);
+ }
+}
+
+static void setFileTimeProperty(IPropertyStore *content, REFPROPERTYKEY key, const FILETIME *ft)
+{
+ PROPVARIANT propValue = {};
+ if (SUCCEEDED(InitPropVariantFromFileTime(ft, &propValue))) {
+ if (SUCCEEDED(PSCoerceToCanonicalValue(key, &propValue)))
+ content->SetValue(key, propValue);
+ PropVariantClear(&propValue);
+ }
+}
+
+void MFMetaData::toNative(const QMediaMetaData &metaData, IPropertyStore *content)
+{
+ if (content) {
+
+ for (const auto &key : metaData.keys()) {
+
+ QVariant value = metaData.value(key);
+
+ if (key == QMediaMetaData::Key::MediaType) {
+
+ QString strValue = metaData.stringValue(key);
+ QString v;
+
+ // Sets property to one of the MediaClassPrimaryID values defined by Microsoft:
+ // https://docs.microsoft.com/en-us/windows/win32/wmformat/wm-mediaprimaryid
+ if (strValue == QLatin1String("Music"))
+ v = QLatin1String("{D1607DBC-E323-4BE2-86A1-48A42A28441E}");
+ else if (strValue == QLatin1String("Video"))
+ v = QLatin1String("{DB9830BD-3AB3-4FAB-8A37-1A995F7FF74B}");
+ else if (strValue == QLatin1String("Audio"))
+ v = QLatin1String("{01CD0F29-DA4E-4157-897B-6275D50C4F11}");
+ else
+ v = QLatin1String("{FCF24A76-9A57-4036-990D-E35DD8B244E1}");
+
+ setStringProperty(content, PKEY_Media_ClassPrimaryID, v);
+
+ } else if (key == QMediaMetaData::Key::Duration) {
+
+ setUInt64Property(content, PKEY_Media_Duration, value.toULongLong() * 10000);
+
+ } else if (key == QMediaMetaData::Key::Resolution) {
+
+ QSize res = value.toSize();
+ setUInt32Property(content, PKEY_Video_FrameWidth, quint32(res.width()));
+ setUInt32Property(content, PKEY_Video_FrameHeight, quint32(res.height()));
+
+ } else if (key == QMediaMetaData::Key::Orientation) {
+
+ setUInt32Property(content, PKEY_Video_Orientation, value.toUInt());
+
+ } else if (key == QMediaMetaData::Key::VideoFrameRate) {
+
+ qreal fps = value.toReal();
+ setUInt32Property(content, PKEY_Video_FrameRate, quint32(fps * 1000));
+
+ } else if (key == QMediaMetaData::Key::TrackNumber) {
+
+ setUInt32Property(content, PKEY_Music_TrackNumber, value.toUInt());
+
+ } else if (key == QMediaMetaData::Key::AudioBitRate) {
+
+ setUInt32Property(content, PKEY_Audio_EncodingBitrate, value.toUInt());
+
+ } else if (key == QMediaMetaData::Key::VideoBitRate) {
+
+ setUInt32Property(content, PKEY_Video_EncodingBitrate, value.toUInt());
+
+ } else if (key == QMediaMetaData::Key::Date) {
+
+ // Convert QDateTime to FILETIME by converting to 100-nsecs since
+ // 01/01/1970 UTC and adding the difference from 1601 to 1970.
+ ULARGE_INTEGER t = {};
+ t.QuadPart = ULONGLONG(value.toDateTime().toUTC().toMSecsSinceEpoch() * 10000
+ + 116444736000000000LL);
+
+ FILETIME ft = {};
+ ft.dwHighDateTime = t.HighPart;
+ ft.dwLowDateTime = t.LowPart;
+
+ setFileTimeProperty(content, PKEY_Media_DateEncoded, &ft);
+
+ } else {
+
+ // By default use as string and let PSCoerceToCanonicalValue()
+ // do validation and type conversion.
+ REFPROPERTYKEY propKey = propertyKeyForMetaDataKey(key);
+
+ if (propKey != PROP_KEY_NULL) {
+ QString strValue = metaData.stringValue(key);
+ if (!strValue.isEmpty())
+ setStringProperty(content, propKey, strValue);
+ }
+ }
+ }
+ }
+}
+
diff --git a/src/plugins/multimedia/windows/common/mfmetadata_p.h b/src/plugins/multimedia/windows/common/mfmetadata_p.h
new file mode 100644
index 000000000..9ff196240
--- /dev/null
+++ b/src/plugins/multimedia/windows/common/mfmetadata_p.h
@@ -0,0 +1,30 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef MFMETADATACONTROL_H
+#define MFMETADATACONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qmediametadata.h>
+#include "mfidl.h"
+
+QT_USE_NAMESPACE
+
+class MFMetaData
+{
+public:
+ static QMediaMetaData fromNative(IMFMediaSource* mediaSource);
+ static void toNative(const QMediaMetaData &metaData, IPropertyStore *content);
+};
+
+#endif
diff --git a/src/plugins/multimedia/windows/decoder/mfaudiodecodercontrol.cpp b/src/plugins/multimedia/windows/decoder/mfaudiodecodercontrol.cpp
new file mode 100644
index 000000000..912ab5e94
--- /dev/null
+++ b/src/plugins/multimedia/windows/decoder/mfaudiodecodercontrol.cpp
@@ -0,0 +1,225 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <system_error>
+#include <mferror.h>
+#include <qglobal.h>
+#include "wmcodecdsp.h"
+#include "mfaudiodecodercontrol_p.h"
+#include <private/qwindowsaudioutils_p.h>
+
+QT_BEGIN_NAMESPACE
+
+MFAudioDecoderControl::MFAudioDecoderControl(QAudioDecoder *parent)
+ : QPlatformAudioDecoder(parent)
+ , m_sourceResolver(new SourceResolver)
+{
+ connect(m_sourceResolver, &SourceResolver::mediaSourceReady, this, &MFAudioDecoderControl::handleMediaSourceReady);
+ connect(m_sourceResolver, &SourceResolver::error, this, &MFAudioDecoderControl::handleMediaSourceError);
+}
+
+MFAudioDecoderControl::~MFAudioDecoderControl()
+{
+ m_sourceResolver->shutdown();
+ m_sourceResolver->Release();
+}
+
+void MFAudioDecoderControl::setSource(const QUrl &fileName)
+{
+ if (!m_device && m_source == fileName)
+ return;
+ stop();
+ m_sourceResolver->cancel();
+ m_sourceResolver->shutdown();
+ m_device = nullptr;
+ m_source = fileName;
+ sourceChanged();
+
+ if (!m_source.isEmpty()) {
+ m_sourceResolver->load(m_source, 0);
+ m_loadingSource = true;
+ }
+}
+
+void MFAudioDecoderControl::setSourceDevice(QIODevice *device)
+{
+ if (m_device == device && m_source.isEmpty())
+ return;
+ stop();
+ m_sourceResolver->cancel();
+ m_sourceResolver->shutdown();
+ m_source.clear();
+ m_device = device;
+ sourceChanged();
+
+ if (m_device) {
+ if (m_device->isOpen() && m_device->isReadable()) {
+ m_sourceResolver->load(QUrl(), m_device);
+ m_loadingSource = true;
+ }
+ }
+}
+
+void MFAudioDecoderControl::handleMediaSourceReady()
+{
+ m_loadingSource = false;
+ if (m_deferredStart) {
+ m_deferredStart = false;
+ startReadingSource(m_sourceResolver->mediaSource());
+ }
+}
+
+void MFAudioDecoderControl::handleMediaSourceError(long hr)
+{
+ m_loadingSource = false;
+ m_deferredStart = false;
+ if (hr == MF_E_UNSUPPORTED_BYTESTREAM_TYPE) {
+ error(QAudioDecoder::FormatError, tr("Unsupported media type"));
+ } else if (hr == ERROR_FILE_NOT_FOUND) {
+ error(QAudioDecoder::ResourceError, tr("Media not found"));
+ } else {
+ error(QAudioDecoder::ResourceError, tr("Unable to load specified URL")
+ + QString::fromStdString(std::system_category().message(hr)));
+ }
+}
+
+void MFAudioDecoderControl::startReadingSource(IMFMediaSource *source)
+{
+ Q_ASSERT(source);
+
+ m_decoderSourceReader = makeComObject<MFDecoderSourceReader>();
+ if (!m_decoderSourceReader) {
+ error(QAudioDecoder::ResourceError, tr("Could not instantiate MFDecoderSourceReader"));
+ return;
+ }
+
+ auto mediaType = m_decoderSourceReader->setSource(source, m_outputFormat.sampleFormat());
+ QAudioFormat mediaFormat = QWindowsAudioUtils::mediaTypeToFormat(mediaType.Get());
+ if (!mediaFormat.isValid()) {
+ error(QAudioDecoder::FormatError, tr("Invalid media format"));
+ m_decoderSourceReader.Reset();
+ return;
+ }
+
+ ComPtr<IMFPresentationDescriptor> pd;
+ if (SUCCEEDED(source->CreatePresentationDescriptor(pd.GetAddressOf()))) {
+ UINT64 duration = 0;
+ pd->GetUINT64(MF_PD_DURATION, &duration);
+ duration /= 10000;
+ m_duration = qint64(duration);
+ durationChanged(m_duration);
+ }
+
+ if (!m_resampler.setup(mediaFormat, m_outputFormat.isValid() ? m_outputFormat : mediaFormat)) {
+ qWarning() << "Failed to set up resampler";
+ return;
+ }
+
+ connect(m_decoderSourceReader.Get(), &MFDecoderSourceReader::finished, this, &MFAudioDecoderControl::handleSourceFinished);
+ connect(m_decoderSourceReader.Get(), &MFDecoderSourceReader::newSample, this, &MFAudioDecoderControl::handleNewSample);
+
+ setIsDecoding(true);
+
+ m_decoderSourceReader->readNextSample();
+}
+
+void MFAudioDecoderControl::start()
+{
+ if (isDecoding())
+ return;
+
+ if (m_loadingSource) {
+ m_deferredStart = true;
+ } else {
+ IMFMediaSource *source = m_sourceResolver->mediaSource();
+ if (!source) {
+ if (m_device)
+ error(QAudioDecoder::ResourceError, tr("Unable to read from specified device"));
+ else if (m_source.isValid())
+ error(QAudioDecoder::ResourceError, tr("Unable to load specified URL"));
+ else
+ error(QAudioDecoder::ResourceError, tr("No media source specified"));
+ return;
+ } else {
+ startReadingSource(source);
+ }
+ }
+}
+
+void MFAudioDecoderControl::stop()
+{
+ m_deferredStart = false;
+ if (!isDecoding())
+ return;
+
+ disconnect(m_decoderSourceReader.Get());
+ m_decoderSourceReader->clearSource();
+ m_decoderSourceReader.Reset();
+
+ if (bufferAvailable()) {
+ QAudioBuffer buffer;
+ m_audioBuffer.swap(buffer);
+ bufferAvailableChanged(false);
+ }
+ setIsDecoding(false);
+
+ if (m_position != -1) {
+ m_position = -1;
+ positionChanged(m_position);
+ }
+ if (m_duration != -1) {
+ m_duration = -1;
+ durationChanged(m_duration);
+ }
+}
+
+void MFAudioDecoderControl::handleNewSample(ComPtr<IMFSample> sample)
+{
+ Q_ASSERT(sample);
+
+ qint64 sampleStartTimeUs = m_resampler.outputFormat().durationForBytes(m_resampler.totalOutputBytes());
+ QByteArray out = m_resampler.resample(sample.Get());
+
+ if (out.isEmpty()) {
+ error(QAudioDecoder::Error::ResourceError, tr("Failed processing a sample"));
+
+ } else {
+ m_audioBuffer = QAudioBuffer(out, m_resampler.outputFormat(), sampleStartTimeUs);
+
+ bufferAvailableChanged(true);
+ bufferReady();
+ }
+}
+
+void MFAudioDecoderControl::handleSourceFinished()
+{
+ stop();
+ finished();
+}
+
+void MFAudioDecoderControl::setAudioFormat(const QAudioFormat &format)
+{
+ if (m_outputFormat == format)
+ return;
+ m_outputFormat = format;
+ formatChanged(m_outputFormat);
+}
+
+QAudioBuffer MFAudioDecoderControl::read()
+{
+ QAudioBuffer buffer;
+
+ if (bufferAvailable()) {
+ buffer.swap(m_audioBuffer);
+ m_position = buffer.startTime() / 1000;
+ positionChanged(m_position);
+ bufferAvailableChanged(false);
+ m_decoderSourceReader->readNextSample();
+ }
+
+ return buffer;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_mfaudiodecodercontrol_p.cpp"
diff --git a/src/plugins/multimedia/windows/decoder/mfaudiodecodercontrol_p.h b/src/plugins/multimedia/windows/decoder/mfaudiodecodercontrol_p.h
new file mode 100644
index 000000000..9bb2371ec
--- /dev/null
+++ b/src/plugins/multimedia/windows/decoder/mfaudiodecodercontrol_p.h
@@ -0,0 +1,75 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef MFAUDIODECODERCONTROL_H
+#define MFAUDIODECODERCONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "mfdecodersourcereader_p.h"
+#include <private/qplatformaudiodecoder_p.h>
+#include <sourceresolver_p.h>
+#include <private/qcomptr_p.h>
+#include <private/qwindowsresampler_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class MFAudioDecoderControl : public QPlatformAudioDecoder
+{
+ Q_OBJECT
+public:
+ MFAudioDecoderControl(QAudioDecoder *parent);
+ ~MFAudioDecoderControl() override;
+
+ QUrl source() const override { return m_source; }
+ void setSource(const QUrl &fileName) override;
+
+ QIODevice* sourceDevice() const override { return m_device; }
+ void setSourceDevice(QIODevice *device) override;
+
+ void start() override;
+ void stop() override;
+
+ QAudioFormat audioFormat() const override { return m_outputFormat; }
+ void setAudioFormat(const QAudioFormat &format) override;
+
+ QAudioBuffer read() override;
+ bool bufferAvailable() const override { return m_audioBuffer.sampleCount() > 0; }
+
+ qint64 position() const override { return m_position; }
+ qint64 duration() const override { return m_duration; }
+
+private Q_SLOTS:
+ void handleMediaSourceReady();
+ void handleMediaSourceError(long hr);
+ void handleNewSample(ComPtr<IMFSample>);
+ void handleSourceFinished();
+
+private:
+ void startReadingSource(IMFMediaSource *source);
+
+ ComPtr<MFDecoderSourceReader> m_decoderSourceReader;
+ SourceResolver *m_sourceResolver;
+ QWindowsResampler m_resampler;
+ QUrl m_source;
+ QIODevice *m_device = nullptr;
+ QAudioFormat m_outputFormat;
+ QAudioBuffer m_audioBuffer;
+ qint64 m_duration = -1;
+ qint64 m_position = -1;
+ bool m_loadingSource = false;
+ bool m_deferredStart = false;
+};
+
+QT_END_NAMESPACE
+
+#endif//MFAUDIODECODERCONTROL_H
diff --git a/src/plugins/multimedia/windows/decoder/mfdecodersourcereader.cpp b/src/plugins/multimedia/windows/decoder/mfdecodersourcereader.cpp
new file mode 100644
index 000000000..097f83437
--- /dev/null
+++ b/src/plugins/multimedia/windows/decoder/mfdecodersourcereader.cpp
@@ -0,0 +1,103 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <system_error>
+#include <mferror.h>
+#include <qlogging.h>
+#include <qdebug.h>
+#include "mfdecodersourcereader_p.h"
+
+QT_BEGIN_NAMESPACE
+
+ComPtr<IMFMediaType> MFDecoderSourceReader::setSource(IMFMediaSource *source, QAudioFormat::SampleFormat sampleFormat)
+{
+ ComPtr<IMFMediaType> mediaType;
+ m_sourceReader.Reset();
+
+ if (!source)
+ return mediaType;
+
+ ComPtr<IMFAttributes> attr;
+ MFCreateAttributes(attr.GetAddressOf(), 1);
+ if (FAILED(attr->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, this)))
+ return mediaType;
+ if (FAILED(attr->SetUINT32(MF_SOURCE_READER_DISCONNECT_MEDIASOURCE_ON_SHUTDOWN, TRUE)))
+ return mediaType;
+
+ HRESULT hr = MFCreateSourceReaderFromMediaSource(source, attr.Get(), m_sourceReader.GetAddressOf());
+ if (FAILED(hr)) {
+ qWarning() << "MFDecoderSourceReader: failed to set up source reader: "
+ << std::system_category().message(hr).c_str();
+ return mediaType;
+ }
+
+ m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_ALL_STREAMS), FALSE);
+ m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), TRUE);
+
+ ComPtr<IMFMediaType> pPartialType;
+ MFCreateMediaType(pPartialType.GetAddressOf());
+ pPartialType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
+ pPartialType->SetGUID(MF_MT_SUBTYPE, sampleFormat == QAudioFormat::Float ? MFAudioFormat_Float : MFAudioFormat_PCM);
+ m_sourceReader->SetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), nullptr, pPartialType.Get());
+ m_sourceReader->GetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), mediaType.GetAddressOf());
+ // Ensure the stream is selected.
+ m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), TRUE);
+
+ return mediaType;
+}
+
+void MFDecoderSourceReader::readNextSample()
+{
+ if (m_sourceReader)
+ m_sourceReader->ReadSample(MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, NULL, NULL, NULL, NULL);
+}
+
+//from IUnknown
+STDMETHODIMP MFDecoderSourceReader::QueryInterface(REFIID riid, LPVOID *ppvObject)
+{
+ if (!ppvObject)
+ return E_POINTER;
+ if (riid == IID_IMFSourceReaderCallback) {
+ *ppvObject = static_cast<IMFSourceReaderCallback*>(this);
+ } else if (riid == IID_IUnknown) {
+ *ppvObject = static_cast<IUnknown*>(this);
+ } else {
+ *ppvObject = NULL;
+ return E_NOINTERFACE;
+ }
+ AddRef();
+ return S_OK;
+}
+
+STDMETHODIMP_(ULONG) MFDecoderSourceReader::AddRef()
+{
+ return InterlockedIncrement(&m_cRef);
+}
+
+STDMETHODIMP_(ULONG) MFDecoderSourceReader::Release()
+{
+ LONG cRef = InterlockedDecrement(&m_cRef);
+ if (cRef == 0) {
+ this->deleteLater();
+ }
+ return cRef;
+}
+
+//from IMFSourceReaderCallback
+STDMETHODIMP MFDecoderSourceReader::OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex,
+ DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample *pSample)
+{
+ Q_UNUSED(hrStatus);
+ Q_UNUSED(dwStreamIndex);
+ Q_UNUSED(llTimestamp);
+ if (pSample) {
+ emit newSample(ComPtr<IMFSample>{pSample});
+ } else if ((dwStreamFlags & MF_SOURCE_READERF_ENDOFSTREAM) == MF_SOURCE_READERF_ENDOFSTREAM) {
+ emit finished();
+ }
+ return S_OK;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_mfdecodersourcereader_p.cpp"
diff --git a/src/plugins/multimedia/windows/decoder/mfdecodersourcereader_p.h b/src/plugins/multimedia/windows/decoder/mfdecodersourcereader_p.h
new file mode 100644
index 000000000..dee6f8bf5
--- /dev/null
+++ b/src/plugins/multimedia/windows/decoder/mfdecodersourcereader_p.h
@@ -0,0 +1,63 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef MFDECODERSOURCEREADER_H
+#define MFDECODERSOURCEREADER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <mfapi.h>
+#include <mfidl.h>
+#include <mfreadwrite.h>
+
+#include <QtCore/qobject.h>
+#include "qaudioformat.h"
+#include <private/qcomptr_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class MFDecoderSourceReader : public QObject, public IMFSourceReaderCallback
+{
+ Q_OBJECT
+public:
+ MFDecoderSourceReader() {}
+ ~MFDecoderSourceReader() override {}
+
+ void clearSource() { m_sourceReader.Reset(); }
+ ComPtr<IMFMediaType> setSource(IMFMediaSource *source, QAudioFormat::SampleFormat);
+
+ void readNextSample();
+
+ //from IUnknown
+ STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override;
+ STDMETHODIMP_(ULONG) AddRef() override;
+ STDMETHODIMP_(ULONG) Release() override;
+
+ //from IMFSourceReaderCallback
+ STDMETHODIMP OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex,
+ DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample *pSample) override;
+ STDMETHODIMP OnFlush(DWORD) override { return S_OK; }
+ STDMETHODIMP OnEvent(DWORD, IMFMediaEvent *) override { return S_OK; }
+
+Q_SIGNALS:
+ void newSample(ComPtr<IMFSample>);
+ void finished();
+
+private:
+ long m_cRef = 1;
+ ComPtr<IMFSourceReader> m_sourceReader;
+
+};
+
+QT_END_NAMESPACE
+
+#endif//MFDECODERSOURCEREADER_H
diff --git a/src/plugins/multimedia/windows/evr/evrcustompresenter.cpp b/src/plugins/multimedia/windows/evr/evrcustompresenter.cpp
new file mode 100644
index 000000000..2a3433f4d
--- /dev/null
+++ b/src/plugins/multimedia/windows/evr/evrcustompresenter.cpp
@@ -0,0 +1,1849 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "evrcustompresenter_p.h"
+
+#include "evrd3dpresentengine_p.h"
+#include "evrhelpers_p.h"
+#include <private/qwindowsmultimediautils_p.h>
+#include <private/qplatformvideosink_p.h>
+#include <private/qwindowsmfdefs_p.h>
+
+#include <rhi/qrhi.h>
+
+#include <QtCore/qmutex.h>
+#include <QtCore/qvarlengtharray.h>
+#include <QtCore/qrect.h>
+#include <qthread.h>
+#include <qcoreapplication.h>
+#include <qmath.h>
+#include <qloggingcategory.h>
+
+#include <mutex>
+
+#include <float.h>
+#include <evcode.h>
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcEvrCustomPresenter, "qt.multimedia.evrcustompresenter")
+
+const static MFRatio g_DefaultFrameRate = { 30, 1 };
+static const DWORD SCHEDULER_TIMEOUT = 5000;
+static const MFTIME ONE_SECOND = 10000000;
+static const LONG ONE_MSEC = 1000;
+
+// Function declarations.
+static HRESULT setMixerSourceRect(IMFTransform *mixer, const MFVideoNormalizedRect& nrcSource);
+static QVideoFrameFormat::PixelFormat pixelFormatFromMediaType(IMFMediaType *type);
+
+static inline LONG MFTimeToMsec(const LONGLONG& time)
+{
+ return (LONG)(time / (ONE_SECOND / ONE_MSEC));
+}
+
+bool qt_evr_setCustomPresenter(IUnknown *evr, EVRCustomPresenter *presenter)
+{
+ if (!evr || !presenter)
+ return false;
+
+ HRESULT result = E_FAIL;
+
+ IMFVideoRenderer *renderer = NULL;
+ if (SUCCEEDED(evr->QueryInterface(IID_PPV_ARGS(&renderer)))) {
+ result = renderer->InitializeRenderer(NULL, presenter);
+ renderer->Release();
+ }
+
+ return result == S_OK;
+}
+
+class PresentSampleEvent : public QEvent
+{
+public:
+ explicit PresentSampleEvent(const ComPtr<IMFSample> &sample)
+ : QEvent(static_cast<Type>(EVRCustomPresenter::PresentSample)), m_sample(sample)
+ {
+ }
+
+ ComPtr<IMFSample> sample() const { return m_sample; }
+
+private:
+ const ComPtr<IMFSample> m_sample;
+};
+
+Scheduler::Scheduler(EVRCustomPresenter *presenter)
+ : m_presenter(presenter)
+ , m_threadID(0)
+ , m_playbackRate(1.0f)
+ , m_perFrame_1_4th(0)
+{
+}
+
+Scheduler::~Scheduler()
+{
+ m_scheduledSamples.clear();
+}
+
+void Scheduler::setFrameRate(const MFRatio& fps)
+{
+ UINT64 AvgTimePerFrame = 0;
+
+ // Convert to a duration.
+ MFFrameRateToAverageTimePerFrame(fps.Numerator, fps.Denominator, &AvgTimePerFrame);
+
+ // Calculate 1/4th of this value, because we use it frequently.
+ m_perFrame_1_4th = AvgTimePerFrame / 4;
+}
+
+HRESULT Scheduler::startScheduler(ComPtr<IMFClock> clock)
+{
+ if (m_schedulerThread)
+ return E_UNEXPECTED;
+
+ HRESULT hr = S_OK;
+ DWORD dwID = 0;
+ HANDLE hObjects[2];
+ DWORD dwWait = 0;
+
+ m_clock = clock;
+
+ // Set a high the timer resolution (ie, short timer period).
+ timeBeginPeriod(1);
+
+ // Create an event to wait for the thread to start.
+ m_threadReadyEvent = EventHandle{ CreateEvent(NULL, FALSE, FALSE, NULL) };
+ if (!m_threadReadyEvent) {
+ hr = HRESULT_FROM_WIN32(GetLastError());
+ goto done;
+ }
+
+ // Create an event to wait for flush commands to complete.
+ m_flushEvent = EventHandle{ CreateEvent(NULL, FALSE, FALSE, NULL) };
+ if (!m_flushEvent) {
+ hr = HRESULT_FROM_WIN32(GetLastError());
+ goto done;
+ }
+
+ // Create the scheduler thread.
+ m_schedulerThread = ThreadHandle{ CreateThread(NULL, 0, schedulerThreadProc, (LPVOID)this, 0, &dwID) };
+ if (!m_schedulerThread) {
+ hr = HRESULT_FROM_WIN32(GetLastError());
+ goto done;
+ }
+
+ // Wait for the thread to signal the "thread ready" event.
+ hObjects[0] = m_threadReadyEvent.get();
+ hObjects[1] = m_schedulerThread.get();
+ dwWait = WaitForMultipleObjects(2, hObjects, FALSE, INFINITE); // Wait for EITHER of these handles.
+ if (WAIT_OBJECT_0 != dwWait) {
+ // The thread terminated early for some reason. This is an error condition.
+ m_schedulerThread = {};
+
+ hr = E_UNEXPECTED;
+ goto done;
+ }
+
+ m_threadID = dwID;
+
+done:
+ // Regardless success/failure, we are done using the "thread ready" event.
+ m_threadReadyEvent = {};
+
+ return hr;
+}
+
+HRESULT Scheduler::stopScheduler()
+{
+ if (!m_schedulerThread)
+ return S_OK;
+
+ // Ask the scheduler thread to exit.
+ PostThreadMessage(m_threadID, Terminate, 0, 0);
+
+ // Wait for the thread to exit.
+ WaitForSingleObject(m_schedulerThread.get(), INFINITE);
+
+ // Close handles.
+ m_schedulerThread = {};
+ m_flushEvent = {};
+
+ // Discard samples.
+ m_mutex.lock();
+ m_scheduledSamples.clear();
+ m_mutex.unlock();
+
+ // Restore the timer resolution.
+ timeEndPeriod(1);
+
+ return S_OK;
+}
+
+HRESULT Scheduler::flush()
+{
+ if (m_schedulerThread) {
+ // Ask the scheduler thread to flush.
+ PostThreadMessage(m_threadID, Flush, 0 , 0);
+
+ // Wait for the scheduler thread to signal the flush event,
+ // OR for the thread to terminate.
+ HANDLE objects[] = { m_flushEvent.get(), m_schedulerThread.get() };
+
+ WaitForMultipleObjects(ARRAYSIZE(objects), objects, FALSE, SCHEDULER_TIMEOUT);
+ }
+
+ return S_OK;
+}
+
+bool Scheduler::areSamplesScheduled()
+{
+ QMutexLocker locker(&m_mutex);
+ return m_scheduledSamples.count() > 0;
+}
+
+HRESULT Scheduler::scheduleSample(const ComPtr<IMFSample> &sample, bool presentNow)
+{
+ if (!m_schedulerThread)
+ return MF_E_NOT_INITIALIZED;
+
+ HRESULT hr = S_OK;
+ DWORD dwExitCode = 0;
+
+ GetExitCodeThread(m_schedulerThread.get(), &dwExitCode);
+ if (dwExitCode != STILL_ACTIVE)
+ return E_FAIL;
+
+ if (presentNow || !m_clock) {
+ m_presenter->presentSample(sample);
+ } else {
+ if (m_playbackRate > 0.0f && qt_evr_isSampleTimePassed(m_clock.Get(), sample.Get())) {
+ qCDebug(qLcEvrCustomPresenter) << "Discard the sample, it came too late";
+ return hr;
+ }
+
+ // Queue the sample and ask the scheduler thread to wake up.
+ m_mutex.lock();
+ m_scheduledSamples.enqueue(sample);
+ m_mutex.unlock();
+
+ if (SUCCEEDED(hr))
+ PostThreadMessage(m_threadID, Schedule, 0, 0);
+ }
+
+ return hr;
+}
+
+HRESULT Scheduler::processSamplesInQueue(LONG *nextSleep)
+{
+ HRESULT hr = S_OK;
+ LONG wait = 0;
+
+ QQueue<ComPtr<IMFSample>> scheduledSamples;
+
+ m_mutex.lock();
+ m_scheduledSamples.swap(scheduledSamples);
+ m_mutex.unlock();
+
+ // Process samples until the queue is empty or until the wait time > 0.
+ while (!scheduledSamples.isEmpty()) {
+ ComPtr<IMFSample> sample = scheduledSamples.dequeue();
+
+ // Process the next sample in the queue. If the sample is not ready
+ // for presentation. the value returned in wait is > 0, which
+ // means the scheduler should sleep for that amount of time.
+ if (isSampleReadyToPresent(sample.Get(), &wait)) {
+ m_presenter->presentSample(sample.Get());
+ continue;
+ }
+
+ if (wait > 0) {
+ // return the sample to scheduler
+ scheduledSamples.prepend(sample);
+ break;
+ }
+ }
+
+ m_mutex.lock();
+ scheduledSamples.append(std::move(m_scheduledSamples));
+ m_scheduledSamples.swap(scheduledSamples);
+ m_mutex.unlock();
+
+ // If the wait time is zero, it means we stopped because the queue is
+ // empty (or an error occurred). Set the wait time to infinite; this will
+ // make the scheduler thread sleep until it gets another thread message.
+ if (wait == 0)
+ wait = INFINITE;
+
+ *nextSleep = wait;
+ return hr;
+}
+
+bool Scheduler::isSampleReadyToPresent(IMFSample *sample, LONG *pNextSleep) const
+{
+ *pNextSleep = 0;
+ if (!m_clock)
+ return true;
+
+ MFTIME hnsPresentationTime = 0;
+ MFTIME hnsTimeNow = 0;
+ MFTIME hnsSystemTime = 0;
+
+ // Get the sample's time stamp. It is valid for a sample to
+ // have no time stamp.
+ HRESULT hr = sample->GetSampleTime(&hnsPresentationTime);
+
+ // Get the clock time. (But if the sample does not have a time stamp,
+ // we don't need the clock time.)
+ if (SUCCEEDED(hr))
+ hr = m_clock->GetCorrelatedTime(0, &hnsTimeNow, &hnsSystemTime);
+
+ // Calculate the time until the sample's presentation time.
+ // A negative value means the sample is late.
+ MFTIME hnsDelta = hnsPresentationTime - hnsTimeNow;
+ if (m_playbackRate < 0) {
+ // For reverse playback, the clock runs backward. Therefore, the
+ // delta is reversed.
+ hnsDelta = - hnsDelta;
+ }
+
+ if (hnsDelta < - m_perFrame_1_4th) {
+ // This sample is late - skip.
+ return false;
+ } else if (hnsDelta > (3 * m_perFrame_1_4th)) {
+ // This sample came too early - reschedule
+ *pNextSleep = MFTimeToMsec(hnsDelta - (3 * m_perFrame_1_4th));
+
+ // Adjust the sleep time for the clock rate. (The presentation clock runs
+ // at m_fRate, but sleeping uses the system clock.)
+ if (m_playbackRate != 0)
+ *pNextSleep = (LONG)(*pNextSleep / qFabs(m_playbackRate));
+ return *pNextSleep == 0;
+ } else {
+ // This sample can be presented right now
+ return true;
+ }
+}
+
+DWORD WINAPI Scheduler::schedulerThreadProc(LPVOID parameter)
+{
+ Scheduler* scheduler = reinterpret_cast<Scheduler*>(parameter);
+ if (!scheduler)
+ return -1;
+ return scheduler->schedulerThreadProcPrivate();
+}
+
+DWORD Scheduler::schedulerThreadProcPrivate()
+{
+ HRESULT hr = S_OK;
+ MSG msg;
+ LONG wait = INFINITE;
+ bool exitThread = false;
+
+ // Force the system to create a message queue for this thread.
+ // (See MSDN documentation for PostThreadMessage.)
+ PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
+
+ // Signal to the scheduler that the thread is ready.
+ SetEvent(m_threadReadyEvent.get());
+
+ while (!exitThread) {
+ // Wait for a thread message OR until the wait time expires.
+ DWORD result = MsgWaitForMultipleObjects(0, NULL, FALSE, wait, QS_POSTMESSAGE);
+
+ if (result == WAIT_TIMEOUT) {
+ // If we timed out, then process the samples in the queue
+ hr = processSamplesInQueue(&wait);
+ if (FAILED(hr))
+ exitThread = true;
+ }
+
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ bool processSamples = true;
+
+ switch (msg.message) {
+ case Terminate:
+ exitThread = true;
+ break;
+ case Flush:
+ // Flushing: Clear the sample queue and set the event.
+ m_mutex.lock();
+ m_scheduledSamples.clear();
+ m_mutex.unlock();
+ wait = INFINITE;
+ SetEvent(m_flushEvent.get());
+ break;
+ case Schedule:
+ // Process as many samples as we can.
+ if (processSamples) {
+ hr = processSamplesInQueue(&wait);
+ if (FAILED(hr))
+ exitThread = true;
+ processSamples = (wait != (LONG)INFINITE);
+ }
+ break;
+ }
+ }
+
+ }
+
+ return (SUCCEEDED(hr) ? 0 : 1);
+}
+
+
+SamplePool::SamplePool()
+ : m_initialized(false)
+{
+}
+
+SamplePool::~SamplePool()
+{
+ clear();
+}
+
+ComPtr<IMFSample> SamplePool::takeSample()
+{
+ QMutexLocker locker(&m_mutex);
+
+ Q_ASSERT(m_initialized);
+ if (!m_initialized) {
+ qCWarning(qLcEvrCustomPresenter) << "SamplePool is not initialized yet";
+ return nullptr;
+ }
+
+ if (m_videoSampleQueue.isEmpty()) {
+ qCDebug(qLcEvrCustomPresenter) << "SamplePool is empty";
+ return nullptr;
+ }
+
+ // Get a sample from the allocated queue.
+
+ // It doesn't matter if we pull them from the head or tail of the list,
+ // but when we get it back, we want to re-insert it onto the opposite end.
+ // (see returnSample)
+
+ return m_videoSampleQueue.takeFirst();
+}
+
+void SamplePool::returnSample(const ComPtr<IMFSample> &sample)
+{
+ QMutexLocker locker(&m_mutex);
+
+ Q_ASSERT(m_initialized);
+ if (!m_initialized) {
+ qCWarning(qLcEvrCustomPresenter) << "SamplePool is not initialized yet";
+ return;
+ }
+
+ m_videoSampleQueue.append(sample);
+}
+
+HRESULT SamplePool::initialize(QList<ComPtr<IMFSample>> &&samples)
+{
+ QMutexLocker locker(&m_mutex);
+
+ if (m_initialized)
+ return MF_E_INVALIDREQUEST;
+
+ // Move these samples into our allocated queue.
+ m_videoSampleQueue.append(std::move(samples));
+
+ m_initialized = true;
+
+ return S_OK;
+}
+
+HRESULT SamplePool::clear()
+{
+ QMutexLocker locker(&m_mutex);
+
+ m_videoSampleQueue.clear();
+ m_initialized = false;
+
+ return S_OK;
+}
+
+
+EVRCustomPresenter::EVRCustomPresenter(QVideoSink *sink)
+ : QObject()
+ , m_sampleFreeCB(this, &EVRCustomPresenter::onSampleFree)
+ , m_refCount(1)
+ , m_renderState(RenderShutdown)
+ , m_scheduler(this)
+ , m_tokenCounter(0)
+ , m_sampleNotify(false)
+ , m_prerolled(false)
+ , m_endStreaming(false)
+ , m_playbackRate(1.0f)
+ , m_presentEngine(new D3DPresentEngine(sink))
+ , m_mediaType(0)
+ , m_videoSink(0)
+ , m_canRenderToSurface(false)
+ , m_positionOffset(0)
+{
+ // Initial source rectangle = (0,0,1,1)
+ m_sourceRect.top = 0;
+ m_sourceRect.left = 0;
+ m_sourceRect.bottom = 1;
+ m_sourceRect.right = 1;
+
+ setSink(sink);
+}
+
+EVRCustomPresenter::~EVRCustomPresenter()
+{
+ m_scheduler.flush();
+ m_scheduler.stopScheduler();
+ m_samplePool.clear();
+
+ delete m_presentEngine;
+}
+
+HRESULT EVRCustomPresenter::QueryInterface(REFIID riid, void ** ppvObject)
+{
+ if (!ppvObject)
+ return E_POINTER;
+ if (riid == IID_IMFGetService) {
+ *ppvObject = static_cast<IMFGetService*>(this);
+ } else if (riid == IID_IMFTopologyServiceLookupClient) {
+ *ppvObject = static_cast<IMFTopologyServiceLookupClient*>(this);
+ } else if (riid == IID_IMFVideoDeviceID) {
+ *ppvObject = static_cast<IMFVideoDeviceID*>(this);
+ } else if (riid == IID_IMFVideoPresenter) {
+ *ppvObject = static_cast<IMFVideoPresenter*>(this);
+ } else if (riid == IID_IMFRateSupport) {
+ *ppvObject = static_cast<IMFRateSupport*>(this);
+ } else if (riid == IID_IUnknown) {
+ *ppvObject = static_cast<IUnknown*>(static_cast<IMFGetService*>(this));
+ } else if (riid == IID_IMFClockStateSink) {
+ *ppvObject = static_cast<IMFClockStateSink*>(this);
+ } else {
+ *ppvObject = NULL;
+ return E_NOINTERFACE;
+ }
+ AddRef();
+ return S_OK;
+}
+
+ULONG EVRCustomPresenter::AddRef()
+{
+ return InterlockedIncrement(&m_refCount);
+}
+
+ULONG EVRCustomPresenter::Release()
+{
+ ULONG uCount = InterlockedDecrement(&m_refCount);
+ if (uCount == 0)
+ deleteLater();
+ return uCount;
+}
+
+HRESULT EVRCustomPresenter::GetService(REFGUID guidService, REFIID riid, LPVOID *ppvObject)
+{
+ HRESULT hr = S_OK;
+
+ if (!ppvObject)
+ return E_POINTER;
+
+ // The only service GUID that we support is MR_VIDEO_RENDER_SERVICE.
+ if (guidService != MR_VIDEO_RENDER_SERVICE)
+ return MF_E_UNSUPPORTED_SERVICE;
+
+ // First try to get the service interface from the D3DPresentEngine object.
+ hr = m_presentEngine->getService(guidService, riid, ppvObject);
+ if (FAILED(hr))
+ // Next, check if this object supports the interface.
+ hr = QueryInterface(riid, ppvObject);
+
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::GetDeviceID(IID* deviceID)
+{
+ if (!deviceID)
+ return E_POINTER;
+
+ *deviceID = IID_IDirect3DDevice9;
+
+ return S_OK;
+}
+
+HRESULT EVRCustomPresenter::InitServicePointers(IMFTopologyServiceLookup *lookup)
+{
+ if (!lookup)
+ return E_POINTER;
+
+ HRESULT hr = S_OK;
+ DWORD objectCount = 0;
+
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ // Do not allow initializing when playing or paused.
+ if (isActive())
+ return MF_E_INVALIDREQUEST;
+
+ m_clock.Reset();
+ m_mixer.Reset();
+ m_mediaEventSink.Reset();
+
+ // Ask for the clock. Optional, because the EVR might not have a clock.
+ objectCount = 1;
+
+ lookup->LookupService(MF_SERVICE_LOOKUP_GLOBAL, 0,
+ MR_VIDEO_RENDER_SERVICE, IID_PPV_ARGS(&m_clock),
+ &objectCount
+ );
+
+ // Ask for the mixer. (Required.)
+ objectCount = 1;
+
+ hr = lookup->LookupService(MF_SERVICE_LOOKUP_GLOBAL, 0,
+ MR_VIDEO_MIXER_SERVICE, IID_PPV_ARGS(&m_mixer),
+ &objectCount
+ );
+
+ if (FAILED(hr))
+ return hr;
+
+ // Make sure that we can work with this mixer.
+ hr = configureMixer(m_mixer.Get());
+ if (FAILED(hr))
+ return hr;
+
+ // Ask for the EVR's event-sink interface. (Required.)
+ objectCount = 1;
+
+ hr = lookup->LookupService(MF_SERVICE_LOOKUP_GLOBAL, 0,
+ MR_VIDEO_RENDER_SERVICE, IID_PPV_ARGS(&m_mediaEventSink),
+ &objectCount
+ );
+
+ if (SUCCEEDED(hr))
+ m_renderState = RenderStopped;
+
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::ReleaseServicePointers()
+{
+ // Enter the shut-down state.
+ m_mutex.lock();
+
+ m_renderState = RenderShutdown;
+
+ m_mutex.unlock();
+
+ // Flush any samples that were scheduled.
+ flush();
+
+ // Clear the media type and release related resources.
+ setMediaType(NULL);
+
+ // Release all services that were acquired from InitServicePointers.
+ m_clock.Reset();
+ m_mixer.Reset();
+ m_mediaEventSink.Reset();
+
+ return S_OK;
+}
+
+bool EVRCustomPresenter::isValid() const
+{
+ return m_presentEngine->isValid() && m_canRenderToSurface;
+}
+
+HRESULT EVRCustomPresenter::ProcessMessage(MFVP_MESSAGE_TYPE message, ULONG_PTR param)
+{
+ HRESULT hr = S_OK;
+
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ hr = checkShutdown();
+ if (FAILED(hr))
+ return hr;
+
+ switch (message) {
+ // Flush all pending samples.
+ case MFVP_MESSAGE_FLUSH:
+ hr = flush();
+ break;
+
+ // Renegotiate the media type with the mixer.
+ case MFVP_MESSAGE_INVALIDATEMEDIATYPE:
+ hr = renegotiateMediaType();
+ break;
+
+ // The mixer received a new input sample.
+ case MFVP_MESSAGE_PROCESSINPUTNOTIFY:
+ hr = processInputNotify();
+ break;
+
+ // Streaming is about to start.
+ case MFVP_MESSAGE_BEGINSTREAMING:
+ hr = beginStreaming();
+ break;
+
+ // Streaming has ended. (The EVR has stopped.)
+ case MFVP_MESSAGE_ENDSTREAMING:
+ hr = endStreaming();
+ break;
+
+ // All input streams have ended.
+ case MFVP_MESSAGE_ENDOFSTREAM:
+ // Set the EOS flag.
+ m_endStreaming = true;
+ // Check if it's time to send the EC_COMPLETE event to the EVR.
+ hr = checkEndOfStream();
+ break;
+
+ // Frame-stepping is starting.
+ case MFVP_MESSAGE_STEP:
+ hr = prepareFrameStep(DWORD(param));
+ break;
+
+ // Cancels frame-stepping.
+ case MFVP_MESSAGE_CANCELSTEP:
+ hr = cancelFrameStep();
+ break;
+
+ default:
+ hr = E_INVALIDARG; // Unknown message. This case should never occur.
+ break;
+ }
+
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::GetCurrentMediaType(IMFVideoMediaType **mediaType)
+{
+ HRESULT hr = S_OK;
+
+ if (!mediaType)
+ return E_POINTER;
+
+ *mediaType = NULL;
+
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ hr = checkShutdown();
+ if (FAILED(hr))
+ return hr;
+
+ if (!m_mediaType)
+ return MF_E_NOT_INITIALIZED;
+
+ return m_mediaType->QueryInterface(IID_PPV_ARGS(mediaType));
+}
+
+HRESULT EVRCustomPresenter::OnClockStart(MFTIME, LONGLONG clockStartOffset)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ // We cannot start after shutdown.
+ HRESULT hr = checkShutdown();
+ if (FAILED(hr))
+ return hr;
+
+ // Check if the clock is already active (not stopped).
+ if (isActive()) {
+ m_renderState = RenderStarted;
+
+ // If the clock position changes while the clock is active, it
+ // is a seek request. We need to flush all pending samples.
+ if (clockStartOffset != QMM_PRESENTATION_CURRENT_POSITION)
+ flush();
+ } else {
+ m_renderState = RenderStarted;
+
+ // The clock has started from the stopped state.
+
+ // Possibly we are in the middle of frame-stepping OR have samples waiting
+ // in the frame-step queue. Deal with these two cases first:
+ hr = startFrameStep();
+ if (FAILED(hr))
+ return hr;
+ }
+
+ // Now try to get new output samples from the mixer.
+ processOutputLoop();
+
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::OnClockRestart(MFTIME)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ HRESULT hr = checkShutdown();
+ if (FAILED(hr))
+ return hr;
+
+ // The EVR calls OnClockRestart only while paused.
+
+ m_renderState = RenderStarted;
+
+ // Possibly we are in the middle of frame-stepping OR we have samples waiting
+ // in the frame-step queue. Deal with these two cases first:
+ hr = startFrameStep();
+ if (FAILED(hr))
+ return hr;
+
+ // Now resume the presentation loop.
+ processOutputLoop();
+
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::OnClockStop(MFTIME)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ HRESULT hr = checkShutdown();
+ if (FAILED(hr))
+ return hr;
+
+ if (m_renderState != RenderStopped) {
+ m_renderState = RenderStopped;
+ flush();
+
+ // If we are in the middle of frame-stepping, cancel it now.
+ if (m_frameStep.state != FrameStepNone)
+ cancelFrameStep();
+ }
+
+ return S_OK;
+}
+
+HRESULT EVRCustomPresenter::OnClockPause(MFTIME)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ // We cannot pause the clock after shutdown.
+ HRESULT hr = checkShutdown();
+
+ if (SUCCEEDED(hr))
+ m_renderState = RenderPaused;
+
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::OnClockSetRate(MFTIME, float rate)
+{
+ // Note:
+ // The presenter reports its maximum rate through the IMFRateSupport interface.
+ // Here, we assume that the EVR honors the maximum rate.
+
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ HRESULT hr = checkShutdown();
+ if (FAILED(hr))
+ return hr;
+
+ // If the rate is changing from zero (scrubbing) to non-zero, cancel the
+ // frame-step operation.
+ if ((m_playbackRate == 0.0f) && (rate != 0.0f)) {
+ cancelFrameStep();
+ m_frameStep.samples.clear();
+ }
+
+ m_playbackRate = rate;
+
+ // Tell the scheduler about the new rate.
+ m_scheduler.setClockRate(rate);
+
+ return S_OK;
+}
+
+HRESULT EVRCustomPresenter::GetSlowestRate(MFRATE_DIRECTION, BOOL, float *rate)
+{
+ if (!rate)
+ return E_POINTER;
+
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ HRESULT hr = checkShutdown();
+
+ if (SUCCEEDED(hr)) {
+ // There is no minimum playback rate, so the minimum is zero.
+ *rate = 0;
+ }
+
+ return S_OK;
+}
+
+HRESULT EVRCustomPresenter::GetFastestRate(MFRATE_DIRECTION direction, BOOL thin, float *rate)
+{
+ if (!rate)
+ return E_POINTER;
+
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ float maxRate = 0.0f;
+
+ HRESULT hr = checkShutdown();
+ if (FAILED(hr))
+ return hr;
+
+ // Get the maximum *forward* rate.
+ maxRate = getMaxRate(thin);
+
+ // For reverse playback, it's the negative of maxRate.
+ if (direction == MFRATE_REVERSE)
+ maxRate = -maxRate;
+
+ *rate = maxRate;
+
+ return S_OK;
+}
+
+HRESULT EVRCustomPresenter::IsRateSupported(BOOL thin, float rate, float *nearestSupportedRate)
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ float maxRate = 0.0f;
+ float nearestRate = rate; // If we support rate, that is the nearest.
+
+ HRESULT hr = checkShutdown();
+ if (FAILED(hr))
+ return hr;
+
+ // Find the maximum forward rate.
+ // Note: We have no minimum rate (that is, we support anything down to 0).
+ maxRate = getMaxRate(thin);
+
+ if (qFabs(rate) > maxRate) {
+ // The (absolute) requested rate exceeds the maximum rate.
+ hr = MF_E_UNSUPPORTED_RATE;
+
+ // The nearest supported rate is maxRate.
+ nearestRate = maxRate;
+ if (rate < 0) {
+ // Negative for reverse playback.
+ nearestRate = -nearestRate;
+ }
+ }
+
+ // Return the nearest supported rate.
+ if (nearestSupportedRate)
+ *nearestSupportedRate = nearestRate;
+
+ return hr;
+}
+
+void EVRCustomPresenter::supportedFormatsChanged()
+{
+ const std::lock_guard<QRecursiveMutex> locker(m_mutex);
+
+ m_canRenderToSurface = false;
+
+ // check if we can render to the surface (compatible formats)
+ if (m_videoSink) {
+ for (int f = 0; f < QVideoFrameFormat::NPixelFormats; ++f) {
+ // ### set a better preference order
+ QVideoFrameFormat::PixelFormat format = QVideoFrameFormat::PixelFormat(f);
+ if (SUCCEEDED(m_presentEngine->checkFormat(qt_evr_D3DFormatFromPixelFormat(format)))) {
+ m_canRenderToSurface = true;
+ break;
+ }
+ }
+ }
+
+ // TODO: if media type already set, renegotiate?
+}
+
+void EVRCustomPresenter::setSink(QVideoSink *sink)
+{
+ m_mutex.lock();
+ m_videoSink = sink;
+ m_presentEngine->setSink(sink);
+ m_mutex.unlock();
+
+ supportedFormatsChanged();
+}
+
+void EVRCustomPresenter::setCropRect(QRect cropRect)
+{
+ m_mutex.lock();
+ m_cropRect = cropRect;
+ m_mutex.unlock();
+}
+
+HRESULT EVRCustomPresenter::configureMixer(IMFTransform *mixer)
+{
+ // Set the zoom rectangle (ie, the source clipping rectangle).
+ return setMixerSourceRect(mixer, m_sourceRect);
+}
+
+HRESULT EVRCustomPresenter::renegotiateMediaType()
+{
+ HRESULT hr = S_OK;
+ bool foundMediaType = false;
+
+ IMFMediaType *mixerType = NULL;
+ IMFMediaType *optimalType = NULL;
+
+ if (!m_mixer)
+ return MF_E_INVALIDREQUEST;
+
+ // Loop through all of the mixer's proposed output types.
+ DWORD typeIndex = 0;
+ while (!foundMediaType && (hr != MF_E_NO_MORE_TYPES)) {
+ qt_evr_safe_release(&mixerType);
+ qt_evr_safe_release(&optimalType);
+
+ // Step 1. Get the next media type supported by mixer.
+ hr = m_mixer->GetOutputAvailableType(0, typeIndex++, &mixerType);
+ if (FAILED(hr))
+ break;
+
+ // From now on, if anything in this loop fails, try the next type,
+ // until we succeed or the mixer runs out of types.
+
+ // Step 2. Check if we support this media type.
+ if (SUCCEEDED(hr))
+ hr = isMediaTypeSupported(mixerType);
+
+ // Step 3. Adjust the mixer's type to match our requirements.
+ if (SUCCEEDED(hr))
+ hr = createOptimalVideoType(mixerType, &optimalType);
+
+ // Step 4. Check if the mixer will accept this media type.
+ if (SUCCEEDED(hr))
+ hr = m_mixer->SetOutputType(0, optimalType, MFT_SET_TYPE_TEST_ONLY);
+
+ // Step 5. Try to set the media type on ourselves.
+ if (SUCCEEDED(hr))
+ hr = setMediaType(optimalType);
+
+ // Step 6. Set output media type on mixer.
+ if (SUCCEEDED(hr)) {
+ hr = m_mixer->SetOutputType(0, optimalType, 0);
+
+ // If something went wrong, clear the media type.
+ if (FAILED(hr))
+ setMediaType(NULL);
+ }
+
+ if (SUCCEEDED(hr))
+ foundMediaType = true;
+ }
+
+ qt_evr_safe_release(&mixerType);
+ qt_evr_safe_release(&optimalType);
+
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::flush()
+{
+ m_prerolled = false;
+
+ // The scheduler might have samples that are waiting for
+ // their presentation time. Tell the scheduler to flush.
+
+ // This call blocks until the scheduler threads discards all scheduled samples.
+ m_scheduler.flush();
+
+ // Flush the frame-step queue.
+ m_frameStep.samples.clear();
+
+ if (m_renderState == RenderStopped && m_videoSink) {
+ // Repaint with black.
+ presentSample(nullptr);
+ }
+
+ return S_OK;
+}
+
+HRESULT EVRCustomPresenter::processInputNotify()
+{
+ HRESULT hr = S_OK;
+
+ // Set the flag that says the mixer has a new sample.
+ m_sampleNotify = true;
+
+ if (!m_mediaType) {
+ // We don't have a valid media type yet.
+ hr = MF_E_TRANSFORM_TYPE_NOT_SET;
+ } else {
+ // Try to process an output sample.
+ processOutputLoop();
+ }
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::beginStreaming()
+{
+ HRESULT hr = S_OK;
+
+ // Start the scheduler thread.
+ hr = m_scheduler.startScheduler(m_clock);
+
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::endStreaming()
+{
+ HRESULT hr = S_OK;
+
+ // Stop the scheduler thread.
+ hr = m_scheduler.stopScheduler();
+
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::checkEndOfStream()
+{
+ if (!m_endStreaming) {
+ // The EVR did not send the MFVP_MESSAGE_ENDOFSTREAM message.
+ return S_OK;
+ }
+
+ if (m_sampleNotify) {
+ // The mixer still has input.
+ return S_OK;
+ }
+
+ if (m_scheduler.areSamplesScheduled()) {
+ // Samples are still scheduled for rendering.
+ return S_OK;
+ }
+
+ // Everything is complete. Now we can tell the EVR that we are done.
+ notifyEvent(EC_COMPLETE, (LONG_PTR)S_OK, 0);
+ m_endStreaming = false;
+
+ stopSurface();
+ return S_OK;
+}
+
+HRESULT EVRCustomPresenter::prepareFrameStep(DWORD steps)
+{
+ HRESULT hr = S_OK;
+
+ // Cache the step count.
+ m_frameStep.steps += steps;
+
+ // Set the frame-step state.
+ m_frameStep.state = FrameStepWaitingStart;
+
+ // If the clock is are already running, we can start frame-stepping now.
+ // Otherwise, we will start when the clock starts.
+ if (m_renderState == RenderStarted)
+ hr = startFrameStep();
+
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::startFrameStep()
+{
+ if (m_frameStep.state == FrameStepWaitingStart) {
+ // We have a frame-step request, and are waiting for the clock to start.
+ // Set the state to "pending," which means we are waiting for samples.
+ m_frameStep.state = FrameStepPending;
+
+ // If the frame-step queue already has samples, process them now.
+ while (!m_frameStep.samples.isEmpty() && (m_frameStep.state == FrameStepPending)) {
+ const ComPtr<IMFSample> sample = m_frameStep.samples.takeFirst();
+
+ const HRESULT hr = deliverFrameStepSample(sample.Get());
+ if (FAILED(hr))
+ return hr;
+
+ // We break from this loop when:
+ // (a) the frame-step queue is empty, or
+ // (b) the frame-step operation is complete.
+ }
+ } else if (m_frameStep.state == FrameStepNone) {
+ // We are not frame stepping. Therefore, if the frame-step queue has samples,
+ // we need to process them normally.
+ while (!m_frameStep.samples.isEmpty()) {
+ const ComPtr<IMFSample> sample = m_frameStep.samples.takeFirst();
+
+ const HRESULT hr = deliverSample(sample.Get());
+ if (FAILED(hr))
+ return hr;
+ }
+ }
+
+ return S_OK;
+}
+
+HRESULT EVRCustomPresenter::completeFrameStep(const ComPtr<IMFSample> &sample)
+{
+ HRESULT hr = S_OK;
+ MFTIME sampleTime = 0;
+ MFTIME systemTime = 0;
+
+ // Update our state.
+ m_frameStep.state = FrameStepComplete;
+ m_frameStep.sampleNoRef = 0;
+
+ // Notify the EVR that the frame-step is complete.
+ notifyEvent(EC_STEP_COMPLETE, FALSE, 0); // FALSE = completed (not cancelled)
+
+ // If we are scrubbing (rate == 0), also send the "scrub time" event.
+ if (isScrubbing()) {
+ // Get the time stamp from the sample.
+ hr = sample->GetSampleTime(&sampleTime);
+ if (FAILED(hr)) {
+ // No time stamp. Use the current presentation time.
+ if (m_clock)
+ m_clock->GetCorrelatedTime(0, &sampleTime, &systemTime);
+
+ hr = S_OK; // (Not an error condition.)
+ }
+
+ notifyEvent(EC_SCRUB_TIME, DWORD(sampleTime), DWORD(((sampleTime) >> 32) & 0xffffffff));
+ }
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::cancelFrameStep()
+{
+ FrameStepState oldState = m_frameStep.state;
+
+ m_frameStep.state = FrameStepNone;
+ m_frameStep.steps = 0;
+ m_frameStep.sampleNoRef = 0;
+ // Don't clear the frame-step queue yet, because we might frame step again.
+
+ if (oldState > FrameStepNone && oldState < FrameStepComplete) {
+ // We were in the middle of frame-stepping when it was cancelled.
+ // Notify the EVR.
+ notifyEvent(EC_STEP_COMPLETE, TRUE, 0); // TRUE = cancelled
+ }
+ return S_OK;
+}
+
+HRESULT EVRCustomPresenter::createOptimalVideoType(IMFMediaType *proposedType, IMFMediaType **optimalType)
+{
+ HRESULT hr = S_OK;
+
+ RECT rcOutput;
+ ZeroMemory(&rcOutput, sizeof(rcOutput));
+
+ MFVideoArea displayArea;
+ ZeroMemory(&displayArea, sizeof(displayArea));
+
+ IMFMediaType *mtOptimal = NULL;
+
+ UINT64 size;
+ int width;
+ int height;
+
+ // Clone the proposed type.
+
+ hr = MFCreateMediaType(&mtOptimal);
+ if (FAILED(hr))
+ goto done;
+
+ hr = proposedType->CopyAllItems(mtOptimal);
+ if (FAILED(hr))
+ goto done;
+
+ // Modify the new type.
+
+ hr = proposedType->GetUINT64(MF_MT_FRAME_SIZE, &size);
+ width = int(HI32(size));
+ height = int(LO32(size));
+
+ if (m_cropRect.isValid()) {
+ rcOutput.left = m_cropRect.x();
+ rcOutput.top = m_cropRect.y();
+ rcOutput.right = m_cropRect.x() + m_cropRect.width();
+ rcOutput.bottom = m_cropRect.y() + m_cropRect.height();
+
+ m_sourceRect.left = float(m_cropRect.x()) / width;
+ m_sourceRect.top = float(m_cropRect.y()) / height;
+ m_sourceRect.right = float(m_cropRect.x() + m_cropRect.width()) / width;
+ m_sourceRect.bottom = float(m_cropRect.y() + m_cropRect.height()) / height;
+
+ if (m_mixer)
+ configureMixer(m_mixer.Get());
+ } else {
+ rcOutput.left = 0;
+ rcOutput.top = 0;
+ rcOutput.right = width;
+ rcOutput.bottom = height;
+ }
+
+ // Set the geometric aperture, and disable pan/scan.
+ displayArea = qt_evr_makeMFArea(0, 0, rcOutput.right - rcOutput.left,
+ rcOutput.bottom - rcOutput.top);
+
+ hr = mtOptimal->SetUINT32(MF_MT_PAN_SCAN_ENABLED, FALSE);
+ if (FAILED(hr))
+ goto done;
+
+ hr = mtOptimal->SetBlob(MF_MT_GEOMETRIC_APERTURE, reinterpret_cast<UINT8*>(&displayArea),
+ sizeof(displayArea));
+ if (FAILED(hr))
+ goto done;
+
+ // Set the pan/scan aperture and the minimum display aperture. We don't care
+ // about them per se, but the mixer will reject the type if these exceed the
+ // frame dimentions.
+ hr = mtOptimal->SetBlob(MF_MT_PAN_SCAN_APERTURE, reinterpret_cast<UINT8*>(&displayArea),
+ sizeof(displayArea));
+ if (FAILED(hr))
+ goto done;
+
+ hr = mtOptimal->SetBlob(MF_MT_MINIMUM_DISPLAY_APERTURE, reinterpret_cast<UINT8*>(&displayArea),
+ sizeof(displayArea));
+ if (FAILED(hr))
+ goto done;
+
+ // Return the pointer to the caller.
+ *optimalType = mtOptimal;
+ (*optimalType)->AddRef();
+
+done:
+ qt_evr_safe_release(&mtOptimal);
+ return hr;
+
+}
+
+HRESULT EVRCustomPresenter::setMediaType(IMFMediaType *mediaType)
+{
+ // Note: mediaType can be NULL (to clear the type)
+
+ // Clearing the media type is allowed in any state (including shutdown).
+ if (!mediaType) {
+ stopSurface();
+ m_mediaType.Reset();
+ releaseResources();
+ return S_OK;
+ }
+
+ MFRatio fps = { 0, 0 };
+ QList<ComPtr<IMFSample>> sampleQueue;
+
+ // Cannot set the media type after shutdown.
+ HRESULT hr = checkShutdown();
+ if (FAILED(hr))
+ goto done;
+
+ // Check if the new type is actually different.
+ // Note: This function safely handles NULL input parameters.
+ if (qt_evr_areMediaTypesEqual(m_mediaType.Get(), mediaType))
+ goto done; // Nothing more to do.
+
+ // We're really changing the type. First get rid of the old type.
+ m_mediaType.Reset();
+ releaseResources();
+
+ // Initialize the presenter engine with the new media type.
+ // The presenter engine allocates the samples.
+
+ hr = m_presentEngine->createVideoSamples(mediaType, sampleQueue, m_cropRect.size());
+ if (FAILED(hr))
+ goto done;
+
+ // Mark each sample with our token counter. If this batch of samples becomes
+ // invalid, we increment the counter, so that we know they should be discarded.
+ for (auto sample : std::as_const(sampleQueue)) {
+ hr = sample->SetUINT32(MFSamplePresenter_SampleCounter, m_tokenCounter);
+ if (FAILED(hr))
+ goto done;
+ }
+
+ // Add the samples to the sample pool.
+ hr = m_samplePool.initialize(std::move(sampleQueue));
+ if (FAILED(hr))
+ goto done;
+
+ // Set the frame rate on the scheduler.
+ if (SUCCEEDED(qt_evr_getFrameRate(mediaType, &fps)) && (fps.Numerator != 0) && (fps.Denominator != 0)) {
+ m_scheduler.setFrameRate(fps);
+ } else {
+ // NOTE: The mixer's proposed type might not have a frame rate, in which case
+ // we'll use an arbitrary default. (Although it's unlikely the video source
+ // does not have a frame rate.)
+ m_scheduler.setFrameRate(g_DefaultFrameRate);
+ }
+
+ // Store the media type.
+ m_mediaType = mediaType;
+ m_mediaType->AddRef();
+
+ startSurface();
+
+done:
+ if (FAILED(hr))
+ releaseResources();
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::isMediaTypeSupported(IMFMediaType *proposed)
+{
+ D3DFORMAT d3dFormat = D3DFMT_UNKNOWN;
+ BOOL compressed = FALSE;
+ MFVideoInterlaceMode interlaceMode = MFVideoInterlace_Unknown;
+ MFVideoArea videoCropArea;
+ UINT32 width = 0, height = 0;
+
+ // Validate the format.
+ HRESULT hr = qt_evr_getFourCC(proposed, reinterpret_cast<DWORD*>(&d3dFormat));
+ if (FAILED(hr))
+ return hr;
+
+ QVideoFrameFormat::PixelFormat pixelFormat = pixelFormatFromMediaType(proposed);
+ if (pixelFormat == QVideoFrameFormat::Format_Invalid)
+ return MF_E_INVALIDMEDIATYPE;
+
+ // Reject compressed media types.
+ hr = proposed->IsCompressedFormat(&compressed);
+ if (FAILED(hr))
+ return hr;
+
+ if (compressed)
+ return MF_E_INVALIDMEDIATYPE;
+
+ // The D3DPresentEngine checks whether surfaces can be created using this format
+ hr = m_presentEngine->checkFormat(d3dFormat);
+ if (FAILED(hr))
+ return hr;
+
+ // Reject interlaced formats.
+ hr = proposed->GetUINT32(MF_MT_INTERLACE_MODE, reinterpret_cast<UINT32*>(&interlaceMode));
+ if (FAILED(hr))
+ return hr;
+
+ if (interlaceMode != MFVideoInterlace_Progressive)
+ return MF_E_INVALIDMEDIATYPE;
+
+ hr = MFGetAttributeSize(proposed, MF_MT_FRAME_SIZE, &width, &height);
+ if (FAILED(hr))
+ return hr;
+
+ // Validate the various apertures (cropping regions) against the frame size.
+ // Any of these apertures may be unspecified in the media type, in which case
+ // we ignore it. We just want to reject invalid apertures.
+
+ if (SUCCEEDED(proposed->GetBlob(MF_MT_PAN_SCAN_APERTURE,
+ reinterpret_cast<UINT8*>(&videoCropArea),
+ sizeof(videoCropArea), nullptr))) {
+ hr = qt_evr_validateVideoArea(videoCropArea, width, height);
+ }
+ if (SUCCEEDED(proposed->GetBlob(MF_MT_GEOMETRIC_APERTURE,
+ reinterpret_cast<UINT8*>(&videoCropArea),
+ sizeof(videoCropArea), nullptr))) {
+ hr = qt_evr_validateVideoArea(videoCropArea, width, height);
+ }
+ if (SUCCEEDED(proposed->GetBlob(MF_MT_MINIMUM_DISPLAY_APERTURE,
+ reinterpret_cast<UINT8*>(&videoCropArea),
+ sizeof(videoCropArea), nullptr))) {
+ hr = qt_evr_validateVideoArea(videoCropArea, width, height);
+ }
+ return hr;
+}
+
+void EVRCustomPresenter::processOutputLoop()
+{
+ HRESULT hr = S_OK;
+
+ // Process as many samples as possible.
+ while (hr == S_OK) {
+ // If the mixer doesn't have a new input sample, break from the loop.
+ if (!m_sampleNotify) {
+ hr = MF_E_TRANSFORM_NEED_MORE_INPUT;
+ break;
+ }
+
+ // Try to process a sample.
+ hr = processOutput();
+
+ // NOTE: ProcessOutput can return S_FALSE to indicate it did not
+ // process a sample. If so, break out of the loop.
+ }
+
+ if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) {
+ // The mixer has run out of input data. Check for end-of-stream.
+ checkEndOfStream();
+ }
+}
+
+HRESULT EVRCustomPresenter::processOutput()
+{
+ // If the clock is not running, we present the first sample,
+ // and then don't present any more until the clock starts.
+ if ((m_renderState != RenderStarted) && m_prerolled)
+ return S_FALSE;
+
+ // Make sure we have a pointer to the mixer.
+ if (!m_mixer)
+ return MF_E_INVALIDREQUEST;
+
+ // Try to get a free sample from the video sample pool.
+ ComPtr<IMFSample> sample = m_samplePool.takeSample();
+ if (!sample)
+ return S_FALSE; // No free samples. Try again when a sample is released.
+
+ // From now on, we have a valid video sample pointer, where the mixer will
+ // write the video data.
+
+ LONGLONG mixerStartTime = 0, mixerEndTime = 0;
+ MFTIME systemTime = 0;
+
+ if (m_clock) {
+ // Latency: Record the starting time for ProcessOutput.
+ m_clock->GetCorrelatedTime(0, &mixerStartTime, &systemTime);
+ }
+
+ // Now we are ready to get an output sample from the mixer.
+ DWORD status = 0;
+ MFT_OUTPUT_DATA_BUFFER dataBuffer = {};
+ dataBuffer.pSample = sample.Get();
+ HRESULT hr = m_mixer->ProcessOutput(0, 1, &dataBuffer, &status);
+ // Important: Release any events returned from the ProcessOutput method.
+ qt_evr_safe_release(&dataBuffer.pEvents);
+
+ if (FAILED(hr)) {
+ // Return the sample to the pool.
+ m_samplePool.returnSample(sample);
+
+ // Handle some known error codes from ProcessOutput.
+ if (hr == MF_E_TRANSFORM_TYPE_NOT_SET) {
+ // The mixer's format is not set. Negotiate a new format.
+ hr = renegotiateMediaType();
+ } else if (hr == MF_E_TRANSFORM_STREAM_CHANGE) {
+ // There was a dynamic media type change. Clear our media type.
+ setMediaType(NULL);
+ } else if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) {
+ // The mixer needs more input.
+ // We have to wait for the mixer to get more input.
+ m_sampleNotify = false;
+ }
+
+ return hr;
+ }
+
+ // We got an output sample from the mixer.
+ if (m_clock) {
+ // Latency: Record the ending time for the ProcessOutput operation,
+ // and notify the EVR of the latency.
+
+ m_clock->GetCorrelatedTime(0, &mixerEndTime, &systemTime);
+
+ LONGLONG latencyTime = mixerEndTime - mixerStartTime;
+ notifyEvent(EC_PROCESSING_LATENCY, reinterpret_cast<LONG_PTR>(&latencyTime), 0);
+ }
+
+ // Set up notification for when the sample is released.
+ hr = trackSample(sample);
+ if (FAILED(hr))
+ return hr;
+
+ // Schedule the sample.
+ if (m_frameStep.state == FrameStepNone)
+ hr = deliverSample(sample);
+ else // We are frame-stepping
+ hr = deliverFrameStepSample(sample);
+
+ if (FAILED(hr))
+ return hr;
+
+ m_prerolled = true; // We have presented at least one sample now.
+ return S_OK;
+}
+
+HRESULT EVRCustomPresenter::deliverSample(const ComPtr<IMFSample> &sample)
+{
+ // If we are not actively playing, OR we are scrubbing (rate = 0),
+ // then we need to present the sample immediately. Otherwise,
+ // schedule it normally.
+
+ bool presentNow = ((m_renderState != RenderStarted) || isScrubbing());
+
+ HRESULT hr = m_scheduler.scheduleSample(sample, presentNow);
+
+ if (FAILED(hr)) {
+ // Notify the EVR that we have failed during streaming. The EVR will notify the
+ // pipeline.
+
+ notifyEvent(EC_ERRORABORT, hr, 0);
+ }
+
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::deliverFrameStepSample(const ComPtr<IMFSample> &sample)
+{
+ HRESULT hr = S_OK;
+ IUnknown *unk = NULL;
+
+ // For rate 0, discard any sample that ends earlier than the clock time.
+ if (isScrubbing() && m_clock && qt_evr_isSampleTimePassed(m_clock.Get(), sample.Get())) {
+ // Discard this sample.
+ } else if (m_frameStep.state >= FrameStepScheduled) {
+ // A frame was already submitted. Put this sample on the frame-step queue,
+ // in case we are asked to step to the next frame. If frame-stepping is
+ // cancelled, this sample will be processed normally.
+ m_frameStep.samples.append(sample);
+ } else {
+ // We're ready to frame-step.
+
+ // Decrement the number of steps.
+ if (m_frameStep.steps > 0)
+ m_frameStep.steps--;
+
+ if (m_frameStep.steps > 0) {
+ // This is not the last step. Discard this sample.
+ } else if (m_frameStep.state == FrameStepWaitingStart) {
+ // This is the right frame, but the clock hasn't started yet. Put the
+ // sample on the frame-step queue. When the clock starts, the sample
+ // will be processed.
+ m_frameStep.samples.append(sample);
+ } else {
+ // This is the right frame *and* the clock has started. Deliver this sample.
+ hr = deliverSample(sample);
+ if (FAILED(hr))
+ goto done;
+
+ // Query for IUnknown so that we can identify the sample later.
+ // Per COM rules, an object always returns the same pointer when QI'ed for IUnknown.
+ hr = sample->QueryInterface(IID_PPV_ARGS(&unk));
+ if (FAILED(hr))
+ goto done;
+
+ m_frameStep.sampleNoRef = reinterpret_cast<DWORD_PTR>(unk); // No add-ref.
+
+ // NOTE: We do not AddRef the IUnknown pointer, because that would prevent the
+ // sample from invoking the OnSampleFree callback after the sample is presented.
+ // We use this IUnknown pointer purely to identify the sample later; we never
+ // attempt to dereference the pointer.
+
+ m_frameStep.state = FrameStepScheduled;
+ }
+ }
+done:
+ qt_evr_safe_release(&unk);
+ return hr;
+}
+
+HRESULT EVRCustomPresenter::trackSample(const ComPtr<IMFSample> &sample)
+{
+ IMFTrackedSample *tracked = NULL;
+
+ HRESULT hr = sample->QueryInterface(IID_PPV_ARGS(&tracked));
+
+ if (SUCCEEDED(hr))
+ hr = tracked->SetAllocator(&m_sampleFreeCB, NULL);
+
+ qt_evr_safe_release(&tracked);
+ return hr;
+}
+
+void EVRCustomPresenter::releaseResources()
+{
+ // Increment the token counter to indicate that all existing video samples
+ // are "stale." As these samples get released, we'll dispose of them.
+ //
+ // Note: The token counter is required because the samples are shared
+ // between more than one thread, and they are returned to the presenter
+ // through an asynchronous callback (onSampleFree). Without the token, we
+ // might accidentally re-use a stale sample after the ReleaseResources
+ // method returns.
+
+ m_tokenCounter++;
+
+ flush();
+
+ m_samplePool.clear();
+
+ m_presentEngine->releaseResources();
+}
+
+HRESULT EVRCustomPresenter::onSampleFree(IMFAsyncResult *result)
+{
+ IUnknown *object = NULL;
+ IMFSample *sample = NULL;
+ IUnknown *unk = NULL;
+ UINT32 token;
+
+ // Get the sample from the async result object.
+ HRESULT hr = result->GetObject(&object);
+ if (FAILED(hr))
+ goto done;
+
+ hr = object->QueryInterface(IID_PPV_ARGS(&sample));
+ if (FAILED(hr))
+ goto done;
+
+ // If this sample was submitted for a frame-step, the frame step operation
+ // is complete.
+
+ if (m_frameStep.state == FrameStepScheduled) {
+ // Query the sample for IUnknown and compare it to our cached value.
+ hr = sample->QueryInterface(IID_PPV_ARGS(&unk));
+ if (FAILED(hr))
+ goto done;
+
+ if (m_frameStep.sampleNoRef == reinterpret_cast<DWORD_PTR>(unk)) {
+ // Notify the EVR.
+ hr = completeFrameStep(sample);
+ if (FAILED(hr))
+ goto done;
+ }
+
+ // Note: Although object is also an IUnknown pointer, it is not
+ // guaranteed to be the exact pointer value returned through
+ // QueryInterface. Therefore, the second QueryInterface call is
+ // required.
+ }
+
+ m_mutex.lock();
+
+ token = MFGetAttributeUINT32(sample, MFSamplePresenter_SampleCounter, (UINT32)-1);
+
+ if (token == m_tokenCounter) {
+ // Return the sample to the sample pool.
+ m_samplePool.returnSample(sample);
+ // A free sample is available. Process more data if possible.
+ processOutputLoop();
+ }
+
+ m_mutex.unlock();
+
+done:
+ if (FAILED(hr))
+ notifyEvent(EC_ERRORABORT, hr, 0);
+ qt_evr_safe_release(&object);
+ qt_evr_safe_release(&sample);
+ qt_evr_safe_release(&unk);
+ return hr;
+}
+
+float EVRCustomPresenter::getMaxRate(bool thin)
+{
+ // Non-thinned:
+ // If we have a valid frame rate and a monitor refresh rate, the maximum
+ // playback rate is equal to the refresh rate. Otherwise, the maximum rate
+ // is unbounded (FLT_MAX).
+
+ // Thinned: The maximum rate is unbounded.
+
+ float maxRate = FLT_MAX;
+ MFRatio fps = { 0, 0 };
+ UINT monitorRateHz = 0;
+
+ if (!thin && m_mediaType) {
+ qt_evr_getFrameRate(m_mediaType.Get(), &fps);
+ monitorRateHz = m_presentEngine->refreshRate();
+
+ if (fps.Denominator && fps.Numerator && monitorRateHz) {
+ // Max Rate = Refresh Rate / Frame Rate
+ maxRate = (float)MulDiv(monitorRateHz, fps.Denominator, fps.Numerator);
+ }
+ }
+
+ return maxRate;
+}
+
+bool EVRCustomPresenter::event(QEvent *e)
+{
+ switch (int(e->type())) {
+ case StartSurface:
+ startSurface();
+ return true;
+ case StopSurface:
+ stopSurface();
+ return true;
+ case PresentSample:
+ presentSample(static_cast<PresentSampleEvent *>(e)->sample());
+ return true;
+ default:
+ break;
+ }
+ return QObject::event(e);
+}
+
+void EVRCustomPresenter::startSurface()
+{
+ if (thread() != QThread::currentThread()) {
+ QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StartSurface)));
+ return;
+ }
+}
+
+void EVRCustomPresenter::stopSurface()
+{
+ if (thread() != QThread::currentThread()) {
+ QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StopSurface)));
+ return;
+ }
+}
+
+void EVRCustomPresenter::presentSample(const ComPtr<IMFSample> &sample)
+{
+ if (thread() != QThread::currentThread()) {
+ QCoreApplication::postEvent(this, new PresentSampleEvent(sample));
+ return;
+ }
+
+ if (!m_videoSink || !m_presentEngine->videoSurfaceFormat().isValid())
+ return;
+
+ QVideoFrame frame = m_presentEngine->makeVideoFrame(sample);
+
+ // Since start/end times are related to a position when the clock is started,
+ // to have times from the beginning, need to adjust it by adding seeked position.
+ if (m_positionOffset) {
+ if (frame.startTime())
+ frame.setStartTime(frame.startTime() + m_positionOffset);
+ if (frame.endTime())
+ frame.setEndTime(frame.endTime() + m_positionOffset);
+ }
+
+ ComPtr<IMFMediaType> inputStreamType;
+ if (SUCCEEDED(m_mixer->GetInputCurrentType(0, inputStreamType.GetAddressOf()))) {
+ auto rotation = static_cast<MFVideoRotationFormat>(MFGetAttributeUINT32(inputStreamType.Get(), MF_MT_VIDEO_ROTATION, 0));
+ switch (rotation) {
+ case MFVideoRotationFormat_0: frame.setRotation(QtVideo::Rotation::None); break;
+ case MFVideoRotationFormat_90: frame.setRotation(QtVideo::Rotation::Clockwise90); break;
+ case MFVideoRotationFormat_180: frame.setRotation(QtVideo::Rotation::Clockwise180); break;
+ case MFVideoRotationFormat_270: frame.setRotation(QtVideo::Rotation::Clockwise270); break;
+ default: frame.setRotation(QtVideo::Rotation::None);
+ }
+ }
+
+ m_videoSink->platformVideoSink()->setVideoFrame(frame);
+}
+
+void EVRCustomPresenter::positionChanged(qint64 position)
+{
+ m_positionOffset = position * 1000;
+}
+
+HRESULT setMixerSourceRect(IMFTransform *mixer, const MFVideoNormalizedRect &sourceRect)
+{
+ if (!mixer)
+ return E_POINTER;
+
+ IMFAttributes *attributes = NULL;
+
+ HRESULT hr = mixer->GetAttributes(&attributes);
+ if (SUCCEEDED(hr)) {
+ hr = attributes->SetBlob(VIDEO_ZOOM_RECT, reinterpret_cast<const UINT8*>(&sourceRect),
+ sizeof(sourceRect));
+ attributes->Release();
+ }
+ return hr;
+}
+
+static QVideoFrameFormat::PixelFormat pixelFormatFromMediaType(IMFMediaType *type)
+{
+ GUID majorType;
+ if (FAILED(type->GetMajorType(&majorType)))
+ return QVideoFrameFormat::Format_Invalid;
+ if (majorType != MFMediaType_Video)
+ return QVideoFrameFormat::Format_Invalid;
+
+ GUID subtype;
+ if (FAILED(type->GetGUID(MF_MT_SUBTYPE, &subtype)))
+ return QVideoFrameFormat::Format_Invalid;
+
+ return QWindowsMultimediaUtils::pixelFormatFromMediaSubtype(subtype);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/windows/evr/evrcustompresenter_p.h b/src/plugins/multimedia/windows/evr/evrcustompresenter_p.h
new file mode 100644
index 000000000..28f1cbc68
--- /dev/null
+++ b/src/plugins/multimedia/windows/evr/evrcustompresenter_p.h
@@ -0,0 +1,357 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef EVRCUSTOMPRESENTER_H
+#define EVRCUSTOMPRESENTER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QObject>
+#include <qmutex.h>
+#include <qqueue.h>
+#include <qevent.h>
+#include <qrect.h>
+#include <qvideoframeformat.h>
+#include <qvideosink.h>
+#include <qpointer.h>
+#include <private/qcomptr_p.h>
+#include "evrhelpers_p.h"
+
+#include <d3d9.h>
+#include <dxva2api.h>
+#include <evr9.h>
+#include <evr.h>
+#include <mfidl.h>
+#include <mfapi.h>
+#include <mferror.h>
+
+QT_BEGIN_NAMESPACE
+
+class EVRCustomPresenter;
+class D3DPresentEngine;
+
+template<class T>
+class AsyncCallback : public IMFAsyncCallback
+{
+ Q_DISABLE_COPY(AsyncCallback)
+public:
+ typedef HRESULT (T::*InvokeFn)(IMFAsyncResult *asyncResult);
+
+ AsyncCallback(T *parent, InvokeFn fn) : m_parent(parent), m_invokeFn(fn)
+ {
+ }
+
+ // IUnknown
+ STDMETHODIMP QueryInterface(REFIID iid, void** ppv) override
+ {
+ if (!ppv)
+ return E_POINTER;
+
+ if (iid == __uuidof(IUnknown)) {
+ *ppv = static_cast<IUnknown*>(static_cast<IMFAsyncCallback*>(this));
+ } else if (iid == __uuidof(IMFAsyncCallback)) {
+ *ppv = static_cast<IMFAsyncCallback*>(this);
+ } else {
+ *ppv = NULL;
+ return E_NOINTERFACE;
+ }
+ AddRef();
+ return S_OK;
+ }
+
+ STDMETHODIMP_(ULONG) AddRef() override {
+ // Delegate to parent class.
+ return m_parent->AddRef();
+ }
+ STDMETHODIMP_(ULONG) Release() override {
+ // Delegate to parent class.
+ return m_parent->Release();
+ }
+
+ // IMFAsyncCallback methods
+ STDMETHODIMP GetParameters(DWORD*, DWORD*) override
+ {
+ // Implementation of this method is optional.
+ return E_NOTIMPL;
+ }
+
+ STDMETHODIMP Invoke(IMFAsyncResult* asyncResult) override
+ {
+ return (m_parent->*m_invokeFn)(asyncResult);
+ }
+
+ T *m_parent;
+ InvokeFn m_invokeFn;
+};
+
+class Scheduler
+{
+ Q_DISABLE_COPY(Scheduler)
+public:
+ enum ScheduleEvent
+ {
+ Terminate = WM_USER,
+ Schedule = WM_USER + 1,
+ Flush = WM_USER + 2
+ };
+
+ Scheduler(EVRCustomPresenter *presenter);
+ ~Scheduler();
+
+ void setFrameRate(const MFRatio &fps);
+ void setClockRate(float rate) { m_playbackRate = rate; }
+
+ HRESULT startScheduler(ComPtr<IMFClock> clock);
+ HRESULT stopScheduler();
+
+ HRESULT scheduleSample(const ComPtr<IMFSample> &sample, bool presentNow);
+ HRESULT processSamplesInQueue(LONG *nextSleep);
+ HRESULT flush();
+
+ bool areSamplesScheduled();
+
+ // ThreadProc for the scheduler thread.
+ static DWORD WINAPI schedulerThreadProc(LPVOID parameter);
+
+private:
+ DWORD schedulerThreadProcPrivate();
+ bool isSampleReadyToPresent(IMFSample *sample, LONG *pNextSleep) const;
+
+ EVRCustomPresenter *m_presenter;
+
+ QQueue<ComPtr<IMFSample>> m_scheduledSamples; // Samples waiting to be presented.
+
+ ComPtr<IMFClock> m_clock; // Presentation clock. Can be NULL.
+
+ DWORD m_threadID;
+ ThreadHandle m_schedulerThread;
+ EventHandle m_threadReadyEvent;
+ EventHandle m_flushEvent;
+
+ float m_playbackRate;
+ MFTIME m_perFrame_1_4th; // 1/4th of the frame duration.
+
+ QMutex m_mutex;
+};
+
+class SamplePool
+{
+ Q_DISABLE_COPY(SamplePool)
+public:
+ SamplePool();
+ ~SamplePool();
+
+ HRESULT initialize(QList<ComPtr<IMFSample>> &&samples);
+ HRESULT clear();
+
+ ComPtr<IMFSample> takeSample();
+ void returnSample(const ComPtr<IMFSample> &sample);
+
+private:
+ QMutex m_mutex;
+ QList<ComPtr<IMFSample>> m_videoSampleQueue;
+ bool m_initialized;
+};
+
+class EVRCustomPresenter
+ : public QObject
+ , public IMFVideoDeviceID
+ , public IMFVideoPresenter // Inherits IMFClockStateSink
+ , public IMFRateSupport
+ , public IMFGetService
+ , public IMFTopologyServiceLookupClient
+{
+ Q_DISABLE_COPY(EVRCustomPresenter)
+public:
+ // Defines the state of the presenter.
+ enum RenderState
+ {
+ RenderStarted = 1,
+ RenderStopped,
+ RenderPaused,
+ RenderShutdown // Initial state.
+ };
+
+ // Defines the presenter's state with respect to frame-stepping.
+ enum FrameStepState
+ {
+ FrameStepNone, // Not frame stepping.
+ FrameStepWaitingStart, // Frame stepping, but the clock is not started.
+ FrameStepPending, // Clock is started. Waiting for samples.
+ FrameStepScheduled, // Submitted a sample for rendering.
+ FrameStepComplete // Sample was rendered.
+ };
+
+ enum PresenterEvents
+ {
+ StartSurface = QEvent::User,
+ StopSurface = QEvent::User + 1,
+ PresentSample = QEvent::User + 2
+ };
+
+ EVRCustomPresenter(QVideoSink *sink = 0);
+ ~EVRCustomPresenter() override;
+
+ bool isValid() const;
+
+ // IUnknown methods
+ STDMETHODIMP QueryInterface(REFIID riid, void ** ppv) override;
+ STDMETHODIMP_(ULONG) AddRef() override;
+ STDMETHODIMP_(ULONG) Release() override;
+
+ // IMFGetService methods
+ STDMETHODIMP GetService(REFGUID guidService, REFIID riid, LPVOID *ppvObject) override;
+
+ // IMFVideoPresenter methods
+ STDMETHODIMP ProcessMessage(MFVP_MESSAGE_TYPE message, ULONG_PTR param) override;
+ STDMETHODIMP GetCurrentMediaType(IMFVideoMediaType** mediaType) override;
+
+ // IMFClockStateSink methods
+ STDMETHODIMP OnClockStart(MFTIME systemTime, LONGLONG clockStartOffset) override;
+ STDMETHODIMP OnClockStop(MFTIME systemTime) override;
+ STDMETHODIMP OnClockPause(MFTIME systemTime) override;
+ STDMETHODIMP OnClockRestart(MFTIME systemTime) override;
+ STDMETHODIMP OnClockSetRate(MFTIME systemTime, float rate) override;
+
+ // IMFRateSupport methods
+ STDMETHODIMP GetSlowestRate(MFRATE_DIRECTION direction, BOOL thin, float *rate) override;
+ STDMETHODIMP GetFastestRate(MFRATE_DIRECTION direction, BOOL thin, float *rate) override;
+ STDMETHODIMP IsRateSupported(BOOL thin, float rate, float *nearestSupportedRate) override;
+
+ // IMFVideoDeviceID methods
+ STDMETHODIMP GetDeviceID(IID* deviceID) override;
+
+ // IMFTopologyServiceLookupClient methods
+ STDMETHODIMP InitServicePointers(IMFTopologyServiceLookup *lookup) override;
+ STDMETHODIMP ReleaseServicePointers() override;
+
+ void supportedFormatsChanged();
+ void setSink(QVideoSink *sink);
+ void setCropRect(QRect cropRect);
+
+ void startSurface();
+ void stopSurface();
+ void presentSample(const ComPtr<IMFSample> &sample);
+
+ bool event(QEvent *) override;
+
+public Q_SLOTS:
+ void positionChanged(qint64 position);
+
+private:
+ HRESULT checkShutdown() const
+ {
+ if (m_renderState == RenderShutdown)
+ return MF_E_SHUTDOWN;
+ else
+ return S_OK;
+ }
+
+ // The "active" state is started or paused.
+ inline bool isActive() const
+ {
+ return ((m_renderState == RenderStarted) || (m_renderState == RenderPaused));
+ }
+
+ // Scrubbing occurs when the frame rate is 0.
+ inline bool isScrubbing() const { return m_playbackRate == 0.0f; }
+
+ // Send an event to the EVR through its IMediaEventSink interface.
+ void notifyEvent(long eventCode, LONG_PTR param1, LONG_PTR param2)
+ {
+ if (m_mediaEventSink)
+ m_mediaEventSink->Notify(eventCode, param1, param2);
+ }
+
+ float getMaxRate(bool thin);
+
+ // Mixer operations
+ HRESULT configureMixer(IMFTransform *mixer);
+
+ // Formats
+ HRESULT createOptimalVideoType(IMFMediaType* proposed, IMFMediaType **optimal);
+ HRESULT setMediaType(IMFMediaType *mediaType);
+ HRESULT isMediaTypeSupported(IMFMediaType *mediaType);
+
+ // Message handlers
+ HRESULT flush();
+ HRESULT renegotiateMediaType();
+ HRESULT processInputNotify();
+ HRESULT beginStreaming();
+ HRESULT endStreaming();
+ HRESULT checkEndOfStream();
+
+ // Managing samples
+ void processOutputLoop();
+ HRESULT processOutput();
+ HRESULT deliverSample(const ComPtr<IMFSample> &sample);
+ HRESULT trackSample(const ComPtr<IMFSample> &sample);
+ void releaseResources();
+
+ // Frame-stepping
+ HRESULT prepareFrameStep(DWORD steps);
+ HRESULT startFrameStep();
+ HRESULT deliverFrameStepSample(const ComPtr<IMFSample> &sample);
+ HRESULT completeFrameStep(const ComPtr<IMFSample> &sample);
+ HRESULT cancelFrameStep();
+
+ // Callback when a video sample is released.
+ HRESULT onSampleFree(IMFAsyncResult *result);
+ AsyncCallback<EVRCustomPresenter> m_sampleFreeCB;
+
+ // Holds information related to frame-stepping.
+ struct FrameStep
+ {
+ FrameStepState state = FrameStepNone;
+ QList<ComPtr<IMFSample>> samples;
+ DWORD steps = 0;
+ DWORD_PTR sampleNoRef = 0;
+ };
+
+ long m_refCount;
+
+ RenderState m_renderState;
+ FrameStep m_frameStep;
+
+ QRecursiveMutex m_mutex;
+
+ // Samples and scheduling
+ Scheduler m_scheduler; // Manages scheduling of samples.
+ SamplePool m_samplePool; // Pool of allocated samples.
+ DWORD m_tokenCounter; // Counter. Incremented whenever we create new samples.
+
+ // Rendering state
+ bool m_sampleNotify; // Did the mixer signal it has an input sample?
+ bool m_prerolled; // Have we presented at least one sample?
+ bool m_endStreaming; // Did we reach the end of the stream (EOS)?
+
+ MFVideoNormalizedRect m_sourceRect;
+ float m_playbackRate;
+
+ D3DPresentEngine *m_presentEngine; // Rendering engine. (Never null if the constructor succeeds.)
+
+ ComPtr<IMFClock> m_clock; // The EVR's clock.
+ ComPtr<IMFTransform> m_mixer; // The EVR's mixer.
+ ComPtr<IMediaEventSink> m_mediaEventSink; // The EVR's event-sink interface.
+ ComPtr<IMFMediaType> m_mediaType; // Output media type
+
+ QPointer<QVideoSink> m_videoSink;
+ bool m_canRenderToSurface;
+ qint64 m_positionOffset; // Seek position in microseconds.
+ QRect m_cropRect; // Video crop rectangle
+};
+
+bool qt_evr_setCustomPresenter(IUnknown *evr, EVRCustomPresenter *presenter);
+
+QT_END_NAMESPACE
+
+#endif // EVRCUSTOMPRESENTER_H
diff --git a/src/plugins/multimedia/windows/evr/evrd3dpresentengine.cpp b/src/plugins/multimedia/windows/evr/evrd3dpresentengine.cpp
new file mode 100644
index 000000000..517f1d969
--- /dev/null
+++ b/src/plugins/multimedia/windows/evr/evrd3dpresentengine.cpp
@@ -0,0 +1,699 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "evrd3dpresentengine_p.h"
+
+#include "evrhelpers_p.h"
+
+#include <private/qhwvideobuffer_p.h>
+#include <private/qvideoframe_p.h>
+#include <qvideoframe.h>
+#include <QDebug>
+#include <qthread.h>
+#include <qvideosink.h>
+#include <qloggingcategory.h>
+
+#include <d3d11_1.h>
+
+#include <rhi/qrhi.h>
+
+#if QT_CONFIG(opengl)
+# include <qopenglcontext.h>
+# include <qopenglfunctions.h>
+# include <qoffscreensurface.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+static Q_LOGGING_CATEGORY(qLcEvrD3DPresentEngine, "qt.multimedia.evrd3dpresentengine");
+
+class IMFSampleVideoBuffer : public QHwVideoBuffer
+{
+public:
+ IMFSampleVideoBuffer(ComPtr<IDirect3DDevice9Ex> device, const ComPtr<IMFSample> &sample,
+ QRhi *rhi, QVideoFrame::HandleType type = QVideoFrame::NoHandle)
+ : QHwVideoBuffer(type, rhi),
+ m_device(device),
+ m_sample(sample),
+ m_mapMode(QtVideo::MapMode::NotMapped)
+ {
+ }
+
+ ~IMFSampleVideoBuffer() override
+ {
+ if (m_memSurface && m_mapMode != QtVideo::MapMode::NotMapped)
+ m_memSurface->UnlockRect();
+ }
+
+ MapData map(QtVideo::MapMode mode) override
+ {
+ if (!m_sample || m_mapMode != QtVideo::MapMode::NotMapped || mode != QtVideo::MapMode::ReadOnly)
+ return {};
+
+ D3DSURFACE_DESC desc;
+ if (m_memSurface) {
+ if (FAILED(m_memSurface->GetDesc(&desc)))
+ return {};
+
+ } else {
+ ComPtr<IMFMediaBuffer> buffer;
+ HRESULT hr = m_sample->GetBufferByIndex(0, buffer.GetAddressOf());
+ if (FAILED(hr))
+ return {};
+
+ ComPtr<IDirect3DSurface9> surface;
+ hr = MFGetService(buffer.Get(), MR_BUFFER_SERVICE, IID_IDirect3DSurface9, (void **)(surface.GetAddressOf()));
+ if (FAILED(hr))
+ return {};
+
+ if (FAILED(surface->GetDesc(&desc)))
+ return {};
+
+ if (FAILED(m_device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, m_memSurface.GetAddressOf(), nullptr)))
+ return {};
+
+ if (FAILED(m_device->GetRenderTargetData(surface.Get(), m_memSurface.Get()))) {
+ m_memSurface.Reset();
+ return {};
+ }
+ }
+
+ D3DLOCKED_RECT rect;
+ if (FAILED(m_memSurface->LockRect(&rect, NULL, mode == QtVideo::MapMode::ReadOnly ? D3DLOCK_READONLY : 0)))
+ return {};
+
+ m_mapMode = mode;
+
+ MapData mapData;
+ mapData.planeCount = 1;
+ mapData.bytesPerLine[0] = (int)rect.Pitch;
+ mapData.data[0] = reinterpret_cast<uchar *>(rect.pBits);
+ mapData.dataSize[0] = (int)(rect.Pitch * desc.Height);
+ return mapData;
+ }
+
+ void unmap() override
+ {
+ if (m_mapMode == QtVideo::MapMode::NotMapped)
+ return;
+
+ m_mapMode = QtVideo::MapMode::NotMapped;
+ if (m_memSurface)
+ m_memSurface->UnlockRect();
+ }
+
+protected:
+ ComPtr<IDirect3DDevice9Ex> m_device;
+ ComPtr<IMFSample> m_sample;
+
+private:
+ ComPtr<IDirect3DSurface9> m_memSurface;
+ QtVideo::MapMode m_mapMode;
+};
+
+class QVideoFrameD3D11Textures: public QVideoFrameTextures
+{
+public:
+ QVideoFrameD3D11Textures(std::unique_ptr<QRhiTexture> &&tex, ComPtr<ID3D11Texture2D> &&d3d11tex)
+ : m_tex(std::move(tex))
+ , m_d3d11tex(std::move(d3d11tex))
+ {}
+
+ QRhiTexture *texture(uint plane) const override
+ {
+ return plane == 0 ? m_tex.get() : nullptr;
+ };
+
+private:
+ std::unique_ptr<QRhiTexture> m_tex;
+ ComPtr<ID3D11Texture2D> m_d3d11tex;
+};
+
+class D3D11TextureVideoBuffer: public IMFSampleVideoBuffer
+{
+public:
+ D3D11TextureVideoBuffer(ComPtr<IDirect3DDevice9Ex> device, const ComPtr<IMFSample> &sample,
+ HANDLE sharedHandle, QRhi *rhi)
+ : IMFSampleVideoBuffer(std::move(device), sample, rhi, QVideoFrame::RhiTextureHandle)
+ , m_sharedHandle(sharedHandle)
+ {}
+
+ std::unique_ptr<QVideoFrameTextures> mapTextures(QRhi *rhi) override
+ {
+ if (!rhi || rhi->backend() != QRhi::D3D11)
+ return {};
+
+ auto nh = static_cast<const QRhiD3D11NativeHandles*>(rhi->nativeHandles());
+ if (!nh)
+ return {};
+
+ auto dev = reinterpret_cast<ID3D11Device *>(nh->dev);
+ if (!dev)
+ return {};
+
+ ComPtr<ID3D11Texture2D> d3d11tex;
+ HRESULT hr = dev->OpenSharedResource(m_sharedHandle, __uuidof(ID3D11Texture2D), (void**)(d3d11tex.GetAddressOf()));
+ if (SUCCEEDED(hr)) {
+ D3D11_TEXTURE2D_DESC desc = {};
+ d3d11tex->GetDesc(&desc);
+ QRhiTexture::Format format;
+ if (desc.Format == DXGI_FORMAT_B8G8R8A8_UNORM)
+ format = QRhiTexture::BGRA8;
+ else if (desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM)
+ format = QRhiTexture::RGBA8;
+ else
+ return {};
+
+ std::unique_ptr<QRhiTexture> tex(rhi->newTexture(format, QSize{int(desc.Width), int(desc.Height)}, 1, {}));
+ tex->createFrom({quint64(d3d11tex.Get()), 0});
+ return std::make_unique<QVideoFrameD3D11Textures>(std::move(tex), std::move(d3d11tex));
+
+ } else {
+ qCDebug(qLcEvrD3DPresentEngine) << "Failed to obtain D3D11Texture2D from D3D9Texture2D handle";
+ }
+ return {};
+ }
+
+private:
+ HANDLE m_sharedHandle = nullptr;
+};
+
+#if QT_CONFIG(opengl)
+class QVideoFrameOpenGlTextures : public QVideoFrameTextures
+{
+ struct InterOpHandles {
+ GLuint textureName = 0;
+ HANDLE device = nullptr;
+ HANDLE texture = nullptr;
+ };
+
+public:
+ Q_DISABLE_COPY(QVideoFrameOpenGlTextures);
+
+ QVideoFrameOpenGlTextures(std::unique_ptr<QRhiTexture> &&tex, const WglNvDxInterop &wgl, InterOpHandles &handles)
+ : m_tex(std::move(tex))
+ , m_wgl(wgl)
+ , m_handles(handles)
+ {}
+
+ ~QVideoFrameOpenGlTextures() override {
+ if (QOpenGLContext::currentContext()) {
+ if (!m_wgl.wglDXUnlockObjectsNV(m_handles.device, 1, &m_handles.texture))
+ qCDebug(qLcEvrD3DPresentEngine) << "Failed to unlock OpenGL texture";
+
+ if (!m_wgl.wglDXUnregisterObjectNV(m_handles.device, m_handles.texture))
+ qCDebug(qLcEvrD3DPresentEngine) << "Failed to unregister OpenGL texture";
+
+ QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
+ if (funcs)
+ funcs->glDeleteTextures(1, &m_handles.textureName);
+ else
+ qCDebug(qLcEvrD3DPresentEngine) << "Could not delete texture, OpenGL context functions missing";
+
+ if (!m_wgl.wglDXCloseDeviceNV(m_handles.device))
+ qCDebug(qLcEvrD3DPresentEngine) << "Failed to close D3D-GL device";
+
+ } else {
+ qCDebug(qLcEvrD3DPresentEngine) << "Could not release texture, OpenGL context missing";
+ }
+ }
+
+ static std::unique_ptr<QVideoFrameOpenGlTextures> create(const WglNvDxInterop &wgl, QRhi *rhi,
+ IDirect3DDevice9Ex *device, IDirect3DTexture9 *texture,
+ HANDLE sharedHandle)
+ {
+ if (!rhi || rhi->backend() != QRhi::OpenGLES2)
+ return {};
+
+ if (!QOpenGLContext::currentContext())
+ return {};
+
+ InterOpHandles handles = {};
+ handles.device = wgl.wglDXOpenDeviceNV(device);
+ if (!handles.device) {
+ qCDebug(qLcEvrD3DPresentEngine) << "Failed to open D3D device";
+ return {};
+ }
+
+ wgl.wglDXSetResourceShareHandleNV(texture, sharedHandle);
+
+ QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
+ if (funcs) {
+ funcs->glGenTextures(1, &handles.textureName);
+ handles.texture = wgl.wglDXRegisterObjectNV(handles.device, texture, handles.textureName,
+ GL_TEXTURE_2D, WglNvDxInterop::WGL_ACCESS_READ_ONLY_NV);
+ if (handles.texture) {
+ if (wgl.wglDXLockObjectsNV(handles.device, 1, &handles.texture)) {
+ D3DSURFACE_DESC desc;
+ texture->GetLevelDesc(0, &desc);
+ QRhiTexture::Format format;
+ if (desc.Format == D3DFMT_A8R8G8B8)
+ format = QRhiTexture::BGRA8;
+ else if (desc.Format == D3DFMT_A8B8G8R8)
+ format = QRhiTexture::RGBA8;
+ else
+ return {};
+
+ std::unique_ptr<QRhiTexture> tex(rhi->newTexture(format, QSize{int(desc.Width), int(desc.Height)}, 1, {}));
+ tex->createFrom({quint64(handles.textureName), 0});
+ return std::make_unique<QVideoFrameOpenGlTextures>(std::move(tex), wgl, handles);
+ }
+
+ qCDebug(qLcEvrD3DPresentEngine) << "Failed to lock OpenGL texture";
+ wgl.wglDXUnregisterObjectNV(handles.device, handles.texture);
+ } else {
+ qCDebug(qLcEvrD3DPresentEngine) << "Could not register D3D9 texture in OpenGL";
+ }
+
+ funcs->glDeleteTextures(1, &handles.textureName);
+ } else {
+ qCDebug(qLcEvrD3DPresentEngine) << "Failed generate texture names, OpenGL context functions missing";
+ }
+ return {};
+ }
+
+ QRhiTexture *texture(uint plane) const override
+ {
+ return plane == 0 ? m_tex.get() : nullptr;
+ };
+private:
+ std::unique_ptr<QRhiTexture> m_tex;
+ WglNvDxInterop m_wgl;
+ InterOpHandles m_handles;
+};
+
+class OpenGlVideoBuffer: public IMFSampleVideoBuffer
+{
+public:
+ OpenGlVideoBuffer(ComPtr<IDirect3DDevice9Ex> device, const ComPtr<IMFSample> &sample,
+ const WglNvDxInterop &wglNvDxInterop, HANDLE sharedHandle, QRhi *rhi)
+ : IMFSampleVideoBuffer(std::move(device), sample, rhi, QVideoFrame::RhiTextureHandle)
+ , m_sharedHandle(sharedHandle)
+ , m_wgl(wglNvDxInterop)
+ {}
+
+ std::unique_ptr<QVideoFrameTextures> mapTextures(QRhi *rhi) override
+ {
+ if (!m_texture) {
+ ComPtr<IMFMediaBuffer> buffer;
+ HRESULT hr = m_sample->GetBufferByIndex(0, buffer.GetAddressOf());
+ if (FAILED(hr))
+ return {};
+
+ ComPtr<IDirect3DSurface9> surface;
+ hr = MFGetService(buffer.Get(), MR_BUFFER_SERVICE, IID_IDirect3DSurface9,
+ (void **)(surface.GetAddressOf()));
+ if (FAILED(hr))
+ return {};
+
+ hr = surface->GetContainer(IID_IDirect3DTexture9, (void **)m_texture.GetAddressOf());
+ if (FAILED(hr))
+ return {};
+ }
+
+ return QVideoFrameOpenGlTextures::create(m_wgl, rhi, m_device.Get(), m_texture.Get(), m_sharedHandle);
+ }
+
+private:
+ HANDLE m_sharedHandle = nullptr;
+ WglNvDxInterop m_wgl;
+ ComPtr<IDirect3DTexture9> m_texture;
+};
+#endif
+
+D3DPresentEngine::D3DPresentEngine(QVideoSink *sink)
+ : m_deviceResetToken(0)
+{
+ ZeroMemory(&m_displayMode, sizeof(m_displayMode));
+ setSink(sink);
+}
+
+D3DPresentEngine::~D3DPresentEngine()
+{
+ releaseResources();
+}
+
+void D3DPresentEngine::setSink(QVideoSink *sink)
+{
+ if (sink == m_sink)
+ return;
+
+ m_sink = sink;
+
+ releaseResources();
+ m_device.Reset();
+ m_devices.Reset();
+ m_D3D9.Reset();
+
+ if (!m_sink)
+ return;
+
+ HRESULT hr = initializeD3D();
+
+ if (SUCCEEDED(hr)) {
+ hr = createD3DDevice();
+ if (FAILED(hr))
+ qWarning("Failed to create D3D device");
+ } else {
+ qWarning("Failed to initialize D3D");
+ }
+}
+
+HRESULT D3DPresentEngine::initializeD3D()
+{
+ HRESULT hr = Direct3DCreate9Ex(D3D_SDK_VERSION, m_D3D9.GetAddressOf());
+
+ if (SUCCEEDED(hr))
+ hr = DXVA2CreateDirect3DDeviceManager9(&m_deviceResetToken, m_devices.GetAddressOf());
+
+ return hr;
+}
+
+static bool findD3D11AdapterID(QRhi &rhi, IDirect3D9Ex *D3D9, UINT &adapterID)
+{
+ auto nh = static_cast<const QRhiD3D11NativeHandles*>(rhi.nativeHandles());
+ if (D3D9 && nh) {
+ for (auto i = 0u; i < D3D9->GetAdapterCount(); ++i) {
+ LUID luid = {};
+ D3D9->GetAdapterLUID(i, &luid);
+ if (luid.LowPart == nh->adapterLuidLow && luid.HighPart == nh->adapterLuidHigh) {
+ adapterID = i;
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+#if QT_CONFIG(opengl)
+template <typename T>
+static bool getProc(const QOpenGLContext *ctx, T &fn, const char *fName)
+{
+ fn = reinterpret_cast<T>(ctx->getProcAddress(fName));
+ return fn != nullptr;
+}
+
+static bool readWglNvDxInteropProc(WglNvDxInterop &f)
+{
+ QScopedPointer<QOffscreenSurface> surface(new QOffscreenSurface);
+ surface->create();
+ QScopedPointer<QOpenGLContext> ctx(new QOpenGLContext);
+ ctx->create();
+ ctx->makeCurrent(surface.get());
+
+ auto wglGetExtensionsStringARB = reinterpret_cast<const char* (WINAPI* )(HDC)>
+ (ctx->getProcAddress("wglGetExtensionsStringARB"));
+ if (!wglGetExtensionsStringARB) {
+ qCDebug(qLcEvrD3DPresentEngine) << "WGL extensions missing (no wglGetExtensionsStringARB function)";
+ return false;
+ }
+
+ HWND hwnd = ::GetShellWindow();
+ auto dc = ::GetDC(hwnd);
+
+ const char *wglExtString = wglGetExtensionsStringARB(dc);
+ if (!wglExtString)
+ qCDebug(qLcEvrD3DPresentEngine) << "WGL extensions missing (wglGetExtensionsStringARB returned null)";
+
+ bool hasExtension = wglExtString && strstr(wglExtString, "WGL_NV_DX_interop");
+ ReleaseDC(hwnd, dc);
+ if (!hasExtension) {
+ qCDebug(qLcEvrD3DPresentEngine) << "WGL_NV_DX_interop missing";
+ return false;
+ }
+
+ return getProc(ctx.get(), f.wglDXOpenDeviceNV, "wglDXOpenDeviceNV")
+ && getProc(ctx.get(), f.wglDXCloseDeviceNV, "wglDXCloseDeviceNV")
+ && getProc(ctx.get(), f.wglDXSetResourceShareHandleNV, "wglDXSetResourceShareHandleNV")
+ && getProc(ctx.get(), f.wglDXRegisterObjectNV, "wglDXRegisterObjectNV")
+ && getProc(ctx.get(), f.wglDXUnregisterObjectNV, "wglDXUnregisterObjectNV")
+ && getProc(ctx.get(), f.wglDXLockObjectsNV, "wglDXLockObjectsNV")
+ && getProc(ctx.get(), f.wglDXUnlockObjectsNV, "wglDXUnlockObjectsNV");
+}
+#endif
+
+namespace {
+
+bool hwTextureRenderingEnabled() {
+ // add possibility for an user to opt-out HW video rendering
+ // using the same env. variable as for FFmpeg backend
+ static bool isDisableConversionSet = false;
+ static const int disableHwConversion = qEnvironmentVariableIntValue(
+ "QT_DISABLE_HW_TEXTURES_CONVERSION", &isDisableConversionSet);
+
+ return !isDisableConversionSet || !disableHwConversion;
+}
+
+}
+
+HRESULT D3DPresentEngine::createD3DDevice()
+{
+ if (!m_D3D9 || !m_devices)
+ return MF_E_NOT_INITIALIZED;
+
+ m_useTextureRendering = false;
+ UINT adapterID = 0;
+
+ if (hwTextureRenderingEnabled()) {
+ QRhi *rhi = m_sink ? m_sink->rhi() : nullptr;
+ if (rhi) {
+ if (rhi->backend() == QRhi::D3D11) {
+ m_useTextureRendering = findD3D11AdapterID(*rhi, m_D3D9.Get(), adapterID);
+#if QT_CONFIG(opengl)
+ } else if (rhi->backend() == QRhi::OpenGLES2) {
+ m_useTextureRendering = readWglNvDxInteropProc(m_wglNvDxInterop);
+#endif
+ } else {
+ qCDebug(qLcEvrD3DPresentEngine) << "Not supported RHI backend type";
+ }
+ } else {
+ qCDebug(qLcEvrD3DPresentEngine) << "No RHI associated with this sink";
+ }
+
+ if (!m_useTextureRendering)
+ qCDebug(qLcEvrD3DPresentEngine) << "Could not find compatible RHI adapter, zero copy disabled";
+ }
+
+ D3DCAPS9 ddCaps;
+ ZeroMemory(&ddCaps, sizeof(ddCaps));
+
+ HRESULT hr = m_D3D9->GetDeviceCaps(adapterID, D3DDEVTYPE_HAL, &ddCaps);
+ if (FAILED(hr))
+ return hr;
+
+ DWORD vp = 0;
+ if (ddCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
+ vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
+ else
+ vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
+
+ D3DPRESENT_PARAMETERS pp;
+ ZeroMemory(&pp, sizeof(pp));
+
+ pp.BackBufferWidth = 1;
+ pp.BackBufferHeight = 1;
+ pp.BackBufferCount = 1;
+ pp.Windowed = TRUE;
+ pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
+ pp.BackBufferFormat = D3DFMT_UNKNOWN;
+ pp.hDeviceWindow = nullptr;
+ pp.Flags = D3DPRESENTFLAG_VIDEO;
+ pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
+
+ ComPtr<IDirect3DDevice9Ex> device;
+
+ hr = m_D3D9->CreateDeviceEx(
+ adapterID,
+ D3DDEVTYPE_HAL,
+ pp.hDeviceWindow,
+ vp | D3DCREATE_NOWINDOWCHANGES | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
+ &pp,
+ NULL,
+ device.GetAddressOf()
+ );
+ if (FAILED(hr))
+ return hr;
+
+ hr = m_D3D9->GetAdapterDisplayMode(adapterID, &m_displayMode);
+ if (FAILED(hr))
+ return hr;
+
+ hr = m_devices->ResetDevice(device.Get(), m_deviceResetToken);
+ if (FAILED(hr))
+ return hr;
+
+ m_device = device;
+ return hr;
+}
+
+bool D3DPresentEngine::isValid() const
+{
+ return m_device.Get() != nullptr;
+}
+
+void D3DPresentEngine::releaseResources()
+{
+ m_surfaceFormat = QVideoFrameFormat();
+}
+
+HRESULT D3DPresentEngine::getService(REFGUID, REFIID riid, void** ppv)
+{
+ HRESULT hr = S_OK;
+
+ if (riid == __uuidof(IDirect3DDeviceManager9)) {
+ if (!m_devices) {
+ hr = MF_E_UNSUPPORTED_SERVICE;
+ } else {
+ *ppv = m_devices.Get();
+ m_devices->AddRef();
+ }
+ } else {
+ hr = MF_E_UNSUPPORTED_SERVICE;
+ }
+
+ return hr;
+}
+
+HRESULT D3DPresentEngine::checkFormat(D3DFORMAT format)
+{
+ if (!m_D3D9 || !m_device)
+ return E_FAIL;
+
+ HRESULT hr = S_OK;
+
+ D3DDISPLAYMODE mode;
+ D3DDEVICE_CREATION_PARAMETERS params;
+
+ hr = m_device->GetCreationParameters(&params);
+ if (FAILED(hr))
+ return hr;
+
+ UINT uAdapter = params.AdapterOrdinal;
+ D3DDEVTYPE type = params.DeviceType;
+
+ hr = m_D3D9->GetAdapterDisplayMode(uAdapter, &mode);
+ if (FAILED(hr))
+ return hr;
+
+ hr = m_D3D9->CheckDeviceFormat(uAdapter, type, mode.Format,
+ D3DUSAGE_RENDERTARGET,
+ D3DRTYPE_SURFACE,
+ format);
+ if (FAILED(hr))
+ return hr;
+
+ bool ok = format == D3DFMT_X8R8G8B8
+ || format == D3DFMT_A8R8G8B8
+ || format == D3DFMT_X8B8G8R8
+ || format == D3DFMT_A8B8G8R8;
+
+ return ok ? S_OK : D3DERR_NOTAVAILABLE;
+}
+
+HRESULT D3DPresentEngine::createVideoSamples(IMFMediaType *format,
+ QList<ComPtr<IMFSample>> &videoSampleQueue,
+ QSize frameSize)
+{
+ if (!format || !m_device)
+ return MF_E_UNEXPECTED;
+
+ HRESULT hr = S_OK;
+ releaseResources();
+
+ UINT32 width = 0, height = 0;
+ hr = MFGetAttributeSize(format, MF_MT_FRAME_SIZE, &width, &height);
+ if (FAILED(hr))
+ return hr;
+
+ if (frameSize.isValid() && !frameSize.isEmpty()) {
+ width = frameSize.width();
+ height = frameSize.height();
+ }
+
+ DWORD d3dFormat = 0;
+ hr = qt_evr_getFourCC(format, &d3dFormat);
+ if (FAILED(hr))
+ return hr;
+
+ // FIXME: RHI defines only RGBA, thus add the alpha channel to the selected format
+ if (d3dFormat == D3DFMT_X8R8G8B8)
+ d3dFormat = D3DFMT_A8R8G8B8;
+ else if (d3dFormat == D3DFMT_X8B8G8R8)
+ d3dFormat = D3DFMT_A8B8G8R8;
+
+ for (int i = 0; i < PRESENTER_BUFFER_COUNT; i++) {
+ // texture ref cnt is increased by GetSurfaceLevel()/MFCreateVideoSampleFromSurface()
+ // below, so it will be destroyed only when the sample pool is released.
+ ComPtr<IDirect3DTexture9> texture;
+ HANDLE sharedHandle = nullptr;
+ hr = m_device->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, (D3DFORMAT)d3dFormat, D3DPOOL_DEFAULT, texture.GetAddressOf(), &sharedHandle);
+ if (FAILED(hr))
+ break;
+
+ ComPtr<IDirect3DSurface9> surface;
+ hr = texture->GetSurfaceLevel(0, surface.GetAddressOf());
+ if (FAILED(hr))
+ break;
+
+ ComPtr<IMFSample> videoSample;
+ hr = MFCreateVideoSampleFromSurface(surface.Get(), videoSample.GetAddressOf());
+ if (FAILED(hr))
+ break;
+
+ m_sampleTextureHandle[i] = {videoSample.Get(), sharedHandle};
+ videoSampleQueue.append(videoSample);
+ }
+
+ if (SUCCEEDED(hr)) {
+ m_surfaceFormat = QVideoFrameFormat(QSize(width, height), qt_evr_pixelFormatFromD3DFormat(d3dFormat));
+ } else {
+ releaseResources();
+ }
+
+ return hr;
+}
+
+QVideoFrame D3DPresentEngine::makeVideoFrame(const ComPtr<IMFSample> &sample)
+{
+ if (!sample)
+ return {};
+
+ HANDLE sharedHandle = nullptr;
+ for (const auto &p : m_sampleTextureHandle)
+ if (p.first == sample.Get())
+ sharedHandle = p.second;
+
+ std::unique_ptr<IMFSampleVideoBuffer> vb;
+ QRhi *rhi = m_sink ? m_sink->rhi() : nullptr;
+ if (m_useTextureRendering && sharedHandle && rhi) {
+ if (rhi->backend() == QRhi::D3D11) {
+ vb = std::make_unique<D3D11TextureVideoBuffer>(m_device, sample, sharedHandle, rhi);
+#if QT_CONFIG(opengl)
+ } else if (rhi->backend() == QRhi::OpenGLES2) {
+ vb = std::make_unique<OpenGlVideoBuffer>(m_device, sample, m_wglNvDxInterop,
+ sharedHandle, rhi);
+#endif
+ }
+ }
+
+ if (!vb)
+ vb = std::make_unique<IMFSampleVideoBuffer>(m_device, sample, rhi);
+
+ QVideoFrame frame = QVideoFramePrivate::createFrame(std::move(vb), m_surfaceFormat);
+
+ // WMF uses 100-nanosecond units, Qt uses microseconds
+ LONGLONG startTime = 0;
+ auto hr = sample->GetSampleTime(&startTime);
+ if (SUCCEEDED(hr)) {
+ frame.setStartTime(startTime / 10);
+
+ LONGLONG duration = -1;
+ if (SUCCEEDED(sample->GetSampleDuration(&duration)))
+ frame.setEndTime((startTime + duration) / 10);
+ }
+
+ return frame;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/windows/evr/evrd3dpresentengine_p.h b/src/plugins/multimedia/windows/evr/evrd3dpresentengine_p.h
new file mode 100644
index 000000000..93aa90b71
--- /dev/null
+++ b/src/plugins/multimedia/windows/evr/evrd3dpresentengine_p.h
@@ -0,0 +1,153 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef EVRD3DPRESENTENGINE_H
+#define EVRD3DPRESENTENGINE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QMutex>
+#include <QSize>
+#include <QVideoFrameFormat>
+#include <private/qcomptr_p.h>
+#include <qpointer.h>
+
+#include <d3d9.h>
+
+struct IDirect3D9Ex;
+struct IDirect3DDevice9Ex;
+struct IDirect3DDeviceManager9;
+struct IDirect3DSurface9;
+struct IDirect3DTexture9;
+struct IMFSample;
+struct IMFMediaType;
+
+QT_BEGIN_NAMESPACE
+class QVideoFrame;
+class QVideoSink;
+QT_END_NAMESPACE
+
+// Randomly generated GUIDs
+static const GUID MFSamplePresenter_SampleCounter =
+{ 0xb0bb83cc, 0xf10f, 0x4e2e, { 0xaa, 0x2b, 0x29, 0xea, 0x5e, 0x92, 0xef, 0x85 } };
+
+#if QT_CONFIG(opengl)
+# include <qopengl.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+#ifdef MAYBE_ANGLE
+
+class OpenGLResources;
+
+class EGLWrapper
+{
+ Q_DISABLE_COPY(EGLWrapper)
+public:
+ EGLWrapper();
+
+ __eglMustCastToProperFunctionPointerType getProcAddress(const char *procname);
+ EGLSurface createPbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
+ EGLBoolean destroySurface(EGLDisplay dpy, EGLSurface surface);
+ EGLBoolean bindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+ EGLBoolean releaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+
+private:
+ typedef __eglMustCastToProperFunctionPointerType (EGLAPIENTRYP EglGetProcAddress)(const char *procname);
+ typedef EGLSurface (EGLAPIENTRYP EglCreatePbufferSurface)(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
+ typedef EGLBoolean (EGLAPIENTRYP EglDestroySurface)(EGLDisplay dpy, EGLSurface surface);
+ typedef EGLBoolean (EGLAPIENTRYP EglBindTexImage)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+ typedef EGLBoolean (EGLAPIENTRYP EglReleaseTexImage)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+
+ EglGetProcAddress m_eglGetProcAddress;
+ EglCreatePbufferSurface m_eglCreatePbufferSurface;
+ EglDestroySurface m_eglDestroySurface;
+ EglBindTexImage m_eglBindTexImage;
+ EglReleaseTexImage m_eglReleaseTexImage;
+};
+
+#endif // MAYBE_ANGLE
+
+#if QT_CONFIG(opengl)
+
+struct WglNvDxInterop {
+ HANDLE (WINAPI* wglDXOpenDeviceNV) (void* dxDevice);
+ BOOL (WINAPI* wglDXCloseDeviceNV) (HANDLE hDevice);
+ HANDLE (WINAPI* wglDXRegisterObjectNV) (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access);
+ BOOL (WINAPI* wglDXSetResourceShareHandleNV) (void *dxResource, HANDLE shareHandle);
+ BOOL (WINAPI* wglDXLockObjectsNV) (HANDLE hDevice, GLint count, HANDLE *hObjects);
+ BOOL (WINAPI* wglDXUnlockObjectsNV) (HANDLE hDevice, GLint count, HANDLE *hObjects);
+ BOOL (WINAPI* wglDXUnregisterObjectNV) (HANDLE hDevice, HANDLE hObject);
+
+ static const int WGL_ACCESS_READ_ONLY_NV = 0;
+};
+
+#endif
+
+class D3DPresentEngine
+{
+ Q_DISABLE_COPY(D3DPresentEngine)
+public:
+ D3DPresentEngine(QVideoSink *sink);
+ virtual ~D3DPresentEngine();
+
+ bool isValid() const;
+
+ HRESULT getService(REFGUID guidService, REFIID riid, void** ppv);
+ HRESULT checkFormat(D3DFORMAT format);
+ UINT refreshRate() const { return m_displayMode.RefreshRate; }
+
+ HRESULT createVideoSamples(IMFMediaType *format, QList<ComPtr<IMFSample>> &videoSampleQueue,
+ QSize frameSize);
+ QVideoFrameFormat videoSurfaceFormat() const { return m_surfaceFormat; }
+ QVideoFrame makeVideoFrame(const ComPtr<IMFSample> &sample);
+
+ void releaseResources();
+ void setSink(QVideoSink *sink);
+
+private:
+ static const int PRESENTER_BUFFER_COUNT = 3;
+
+ HRESULT initializeD3D();
+ HRESULT createD3DDevice();
+
+ std::pair<IMFSample *, HANDLE> m_sampleTextureHandle[PRESENTER_BUFFER_COUNT] = {};
+
+ UINT m_deviceResetToken;
+ D3DDISPLAYMODE m_displayMode;
+
+ ComPtr<IDirect3D9Ex> m_D3D9;
+ ComPtr<IDirect3DDevice9Ex> m_device;
+ ComPtr<IDirect3DDeviceManager9> m_devices;
+
+ QVideoFrameFormat m_surfaceFormat;
+
+ QPointer<QVideoSink> m_sink;
+ bool m_useTextureRendering = false;
+#if QT_CONFIG(opengl)
+ WglNvDxInterop m_wglNvDxInterop;
+#endif
+
+#ifdef MAYBE_ANGLE
+ unsigned int updateTexture(IDirect3DSurface9 *src);
+
+ OpenGLResources *m_glResources;
+ IDirect3DTexture9 *m_texture;
+#endif
+
+ friend class IMFSampleVideoBuffer;
+};
+
+QT_END_NAMESPACE
+
+#endif // EVRD3DPRESENTENGINE_H
diff --git a/src/plugins/multimedia/windows/evr/evrhelpers.cpp b/src/plugins/multimedia/windows/evr/evrhelpers.cpp
new file mode 100644
index 000000000..bf4347c69
--- /dev/null
+++ b/src/plugins/multimedia/windows/evr/evrhelpers.cpp
@@ -0,0 +1,140 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "evrhelpers_p.h"
+
+#ifndef D3DFMT_YV12
+#define D3DFMT_YV12 (D3DFORMAT)MAKEFOURCC ('Y', 'V', '1', '2')
+#endif
+#ifndef D3DFMT_NV12
+#define D3DFMT_NV12 (D3DFORMAT)MAKEFOURCC ('N', 'V', '1', '2')
+#endif
+
+QT_BEGIN_NAMESPACE
+
+HRESULT qt_evr_getFourCC(IMFMediaType *type, DWORD *fourCC)
+{
+ if (!fourCC)
+ return E_POINTER;
+
+ HRESULT hr = S_OK;
+ GUID guidSubType = GUID_NULL;
+
+ if (SUCCEEDED(hr))
+ hr = type->GetGUID(MF_MT_SUBTYPE, &guidSubType);
+
+ if (SUCCEEDED(hr))
+ *fourCC = guidSubType.Data1;
+
+ return hr;
+}
+
+bool qt_evr_areMediaTypesEqual(IMFMediaType *type1, IMFMediaType *type2)
+{
+ if (!type1 && !type2)
+ return true;
+ if (!type1 || !type2)
+ return false;
+
+ DWORD dwFlags = 0;
+ HRESULT hr = type1->IsEqual(type2, &dwFlags);
+
+ return (hr == S_OK);
+}
+
+HRESULT qt_evr_validateVideoArea(const MFVideoArea& area, UINT32 width, UINT32 height)
+{
+ float fOffsetX = qt_evr_MFOffsetToFloat(area.OffsetX);
+ float fOffsetY = qt_evr_MFOffsetToFloat(area.OffsetY);
+
+ if ( ((LONG)fOffsetX + area.Area.cx > (LONG)width) ||
+ ((LONG)fOffsetY + area.Area.cy > (LONG)height) ) {
+ return MF_E_INVALIDMEDIATYPE;
+ }
+ return S_OK;
+}
+
+bool qt_evr_isSampleTimePassed(IMFClock *clock, IMFSample *sample)
+{
+ if (!sample || !clock)
+ return false;
+
+ HRESULT hr = S_OK;
+ MFTIME hnsTimeNow = 0;
+ MFTIME hnsSystemTime = 0;
+ MFTIME hnsSampleStart = 0;
+ MFTIME hnsSampleDuration = 0;
+
+ hr = clock->GetCorrelatedTime(0, &hnsTimeNow, &hnsSystemTime);
+
+ if (SUCCEEDED(hr))
+ hr = sample->GetSampleTime(&hnsSampleStart);
+
+ if (SUCCEEDED(hr))
+ hr = sample->GetSampleDuration(&hnsSampleDuration);
+
+ if (SUCCEEDED(hr)) {
+ if (hnsSampleStart + hnsSampleDuration < hnsTimeNow)
+ return true;
+ }
+
+ return false;
+}
+
+QVideoFrameFormat::PixelFormat qt_evr_pixelFormatFromD3DFormat(DWORD format)
+{
+ switch (format) {
+ case D3DFMT_A8R8G8B8:
+ return QVideoFrameFormat::Format_BGRA8888;
+ case D3DFMT_X8R8G8B8:
+ return QVideoFrameFormat::Format_BGRX8888;
+ case D3DFMT_A8:
+ return QVideoFrameFormat::Format_Y8;
+ case D3DFMT_A8B8G8R8:
+ return QVideoFrameFormat::Format_RGBA8888;
+ case D3DFMT_X8B8G8R8:
+ return QVideoFrameFormat::Format_RGBX8888;
+ case D3DFMT_UYVY:
+ return QVideoFrameFormat::Format_UYVY;
+ case D3DFMT_YUY2:
+ return QVideoFrameFormat::Format_YUYV;
+ case D3DFMT_NV12:
+ return QVideoFrameFormat::Format_NV12;
+ case D3DFMT_YV12:
+ return QVideoFrameFormat::Format_YV12;
+ case D3DFMT_UNKNOWN:
+ default:
+ return QVideoFrameFormat::Format_Invalid;
+ }
+}
+
+D3DFORMAT qt_evr_D3DFormatFromPixelFormat(QVideoFrameFormat::PixelFormat format)
+{
+ switch (format) {
+ case QVideoFrameFormat::Format_ARGB8888:
+ return D3DFMT_A8B8G8R8;
+ case QVideoFrameFormat::Format_BGRA8888:
+ return D3DFMT_A8R8G8B8;
+ case QVideoFrameFormat::Format_BGRX8888:
+ return D3DFMT_X8R8G8B8;
+ case QVideoFrameFormat::Format_Y8:
+ return D3DFMT_A8;
+ case QVideoFrameFormat::Format_RGBA8888:
+ return D3DFMT_A8B8G8R8;
+ case QVideoFrameFormat::Format_RGBX8888:
+ return D3DFMT_X8B8G8R8;
+ case QVideoFrameFormat::Format_UYVY:
+ return D3DFMT_UYVY;
+ case QVideoFrameFormat::Format_YUYV:
+ return D3DFMT_YUY2;
+ case QVideoFrameFormat::Format_NV12:
+ return D3DFMT_NV12;
+ case QVideoFrameFormat::Format_YV12:
+ return D3DFMT_YV12;
+ case QVideoFrameFormat::Format_Invalid:
+ default:
+ return D3DFMT_UNKNOWN;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/windows/evr/evrhelpers_p.h b/src/plugins/multimedia/windows/evr/evrhelpers_p.h
new file mode 100644
index 000000000..30779c835
--- /dev/null
+++ b/src/plugins/multimedia/windows/evr/evrhelpers_p.h
@@ -0,0 +1,93 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef EVRHELPERS_H
+#define EVRHELPERS_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qvideoframe.h>
+#include <d3d9.h>
+#include <dxva2api.h>
+#include <evr9.h>
+#include <evr.h>
+#include <mfidl.h>
+#include <mfapi.h>
+#include <mferror.h>
+#include <private/quniquehandle_p.h>
+
+QT_BEGIN_NAMESPACE
+
+template<class T>
+static inline void qt_evr_safe_release(T **unk)
+{
+ if (*unk) {
+ (*unk)->Release();
+ *unk = NULL;
+ }
+}
+
+HRESULT qt_evr_getFourCC(IMFMediaType *type, DWORD *fourCC);
+
+bool qt_evr_areMediaTypesEqual(IMFMediaType *type1, IMFMediaType *type2);
+
+HRESULT qt_evr_validateVideoArea(const MFVideoArea& area, UINT32 width, UINT32 height);
+
+bool qt_evr_isSampleTimePassed(IMFClock *clock, IMFSample *sample);
+
+inline float qt_evr_MFOffsetToFloat(const MFOffset& offset)
+{
+ return offset.value + (float(offset.fract) / 65536);
+}
+
+inline MFOffset qt_evr_makeMFOffset(float v)
+{
+ MFOffset offset;
+ offset.value = short(v);
+ offset.fract = WORD(65536 * (v-offset.value));
+ return offset;
+}
+
+inline MFVideoArea qt_evr_makeMFArea(float x, float y, DWORD width, DWORD height)
+{
+ MFVideoArea area;
+ area.OffsetX = qt_evr_makeMFOffset(x);
+ area.OffsetY = qt_evr_makeMFOffset(y);
+ area.Area.cx = width;
+ area.Area.cy = height;
+ return area;
+}
+
+inline HRESULT qt_evr_getFrameRate(IMFMediaType *pType, MFRatio *pRatio)
+{
+ return MFGetAttributeRatio(pType, MF_MT_FRAME_RATE,
+ reinterpret_cast<UINT32*>(&pRatio->Numerator),
+ reinterpret_cast<UINT32*>(&pRatio->Denominator));
+}
+
+QVideoFrameFormat::PixelFormat qt_evr_pixelFormatFromD3DFormat(DWORD format);
+D3DFORMAT qt_evr_D3DFormatFromPixelFormat(QVideoFrameFormat::PixelFormat format);
+
+struct NullHandleTraits
+{
+ using Type = HANDLE;
+ static Type invalidValue() { return nullptr; }
+ static bool close(Type handle) { return CloseHandle(handle) != 0; }
+};
+
+using EventHandle = QUniqueHandle<NullHandleTraits>;
+using ThreadHandle = QUniqueHandle<NullHandleTraits>;
+
+QT_END_NAMESPACE
+
+#endif // EVRHELPERS_H
+
diff --git a/src/plugins/multimedia/windows/evr/evrvideowindowcontrol.cpp b/src/plugins/multimedia/windows/evr/evrvideowindowcontrol.cpp
new file mode 100644
index 000000000..854c9ddb2
--- /dev/null
+++ b/src/plugins/multimedia/windows/evr/evrvideowindowcontrol.cpp
@@ -0,0 +1,228 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "evrvideowindowcontrol_p.h"
+
+QT_BEGIN_NAMESPACE
+
+EvrVideoWindowControl::EvrVideoWindowControl(QVideoSink *parent)
+ : QPlatformVideoSink(parent)
+ , m_windowId(0)
+ , m_windowColor(RGB(0, 0, 0))
+ , m_dirtyValues(0)
+ , m_aspectRatioMode(Qt::KeepAspectRatio)
+ , m_brightness(0)
+ , m_contrast(0)
+ , m_hue(0)
+ , m_saturation(0)
+ , m_fullScreen(false)
+ , m_displayControl(0)
+ , m_processor(0)
+{
+}
+
+EvrVideoWindowControl::~EvrVideoWindowControl()
+{
+ clear();
+}
+
+bool EvrVideoWindowControl::setEvr(IUnknown *evr)
+{
+ clear();
+
+ if (!evr)
+ return true;
+
+ IMFGetService *service = NULL;
+
+ if (SUCCEEDED(evr->QueryInterface(IID_PPV_ARGS(&service)))
+ && SUCCEEDED(service->GetService(MR_VIDEO_RENDER_SERVICE, IID_PPV_ARGS(&m_displayControl)))) {
+
+ service->GetService(MR_VIDEO_MIXER_SERVICE, IID_PPV_ARGS(&m_processor));
+
+ setWinId(m_windowId);
+ setDisplayRect(m_displayRect);
+ setAspectRatioMode(m_aspectRatioMode);
+ m_dirtyValues = DXVA2_ProcAmp_Brightness | DXVA2_ProcAmp_Contrast | DXVA2_ProcAmp_Hue | DXVA2_ProcAmp_Saturation;
+ applyImageControls();
+ }
+
+ if (service)
+ service->Release();
+
+ return m_displayControl != NULL;
+}
+
+void EvrVideoWindowControl::clear()
+{
+ if (m_displayControl)
+ m_displayControl->Release();
+ m_displayControl = NULL;
+
+ if (m_processor)
+ m_processor->Release();
+ m_processor = NULL;
+}
+
+void EvrVideoWindowControl::setWinId(WId id)
+{
+ m_windowId = id;
+
+ if (m_displayControl)
+ m_displayControl->SetVideoWindow(HWND(m_windowId));
+}
+
+void EvrVideoWindowControl::setDisplayRect(const QRect &rect)
+{
+ m_displayRect = rect;
+
+ if (m_displayControl) {
+ RECT displayRect = { rect.left(), rect.top(), rect.right() + 1, rect.bottom() + 1 };
+ QSize sourceSize = nativeSize();
+
+ RECT sourceRect = { 0, 0, sourceSize.width(), sourceSize.height() };
+
+ if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
+ QSize clippedSize = rect.size();
+ clippedSize.scale(sourceRect.right, sourceRect.bottom, Qt::KeepAspectRatio);
+
+ sourceRect.left = (sourceRect.right - clippedSize.width()) / 2;
+ sourceRect.top = (sourceRect.bottom - clippedSize.height()) / 2;
+ sourceRect.right = sourceRect.left + clippedSize.width();
+ sourceRect.bottom = sourceRect.top + clippedSize.height();
+ }
+
+ if (sourceSize.width() > 0 && sourceSize.height() > 0) {
+ MFVideoNormalizedRect sourceNormRect;
+ sourceNormRect.left = float(sourceRect.left) / float(sourceRect.right);
+ sourceNormRect.top = float(sourceRect.top) / float(sourceRect.bottom);
+ sourceNormRect.right = float(sourceRect.right) / float(sourceRect.right);
+ sourceNormRect.bottom = float(sourceRect.bottom) / float(sourceRect.bottom);
+ m_displayControl->SetVideoPosition(&sourceNormRect, &displayRect);
+ } else {
+ m_displayControl->SetVideoPosition(NULL, &displayRect);
+ }
+ }
+}
+
+void EvrVideoWindowControl::setFullScreen(bool fullScreen)
+{
+ if (m_fullScreen == fullScreen)
+ return;
+}
+
+void EvrVideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
+{
+ m_aspectRatioMode = mode;
+
+ if (m_displayControl) {
+ switch (mode) {
+ case Qt::IgnoreAspectRatio:
+ //comment from MSDN: Do not maintain the aspect ratio of the video. Stretch the video to fit the output rectangle.
+ m_displayControl->SetAspectRatioMode(MFVideoARMode_None);
+ break;
+ case Qt::KeepAspectRatio:
+ //comment from MSDN: Preserve the aspect ratio of the video by letterboxing or within the output rectangle.
+ m_displayControl->SetAspectRatioMode(MFVideoARMode_PreservePicture);
+ break;
+ case Qt::KeepAspectRatioByExpanding:
+ //for this mode, more adjustment will be done in setDisplayRect
+ m_displayControl->SetAspectRatioMode(MFVideoARMode_PreservePicture);
+ break;
+ default:
+ break;
+ }
+ setDisplayRect(m_displayRect);
+ }
+}
+
+void EvrVideoWindowControl::setBrightness(float brightness)
+{
+ if (m_brightness == brightness)
+ return;
+
+ m_brightness = brightness;
+
+ m_dirtyValues |= DXVA2_ProcAmp_Brightness;
+
+ applyImageControls();
+}
+
+void EvrVideoWindowControl::setContrast(float contrast)
+{
+ if (m_contrast == contrast)
+ return;
+
+ m_contrast = contrast;
+
+ m_dirtyValues |= DXVA2_ProcAmp_Contrast;
+
+ applyImageControls();
+}
+
+void EvrVideoWindowControl::setHue(float hue)
+{
+ if (m_hue == hue)
+ return;
+
+ m_hue = hue;
+
+ m_dirtyValues |= DXVA2_ProcAmp_Hue;
+
+ applyImageControls();
+}
+
+void EvrVideoWindowControl::setSaturation(float saturation)
+{
+ if (m_saturation == saturation)
+ return;
+
+ m_saturation = saturation;
+
+ m_dirtyValues |= DXVA2_ProcAmp_Saturation;
+
+ applyImageControls();
+}
+
+void EvrVideoWindowControl::applyImageControls()
+{
+ if (m_processor) {
+ DXVA2_ProcAmpValues values;
+ if (m_dirtyValues & DXVA2_ProcAmp_Brightness) {
+ values.Brightness = scaleProcAmpValue(DXVA2_ProcAmp_Brightness, m_brightness);
+ }
+ if (m_dirtyValues & DXVA2_ProcAmp_Contrast) {
+ values.Contrast = scaleProcAmpValue(DXVA2_ProcAmp_Contrast, m_contrast);
+ }
+ if (m_dirtyValues & DXVA2_ProcAmp_Hue) {
+ values.Hue = scaleProcAmpValue(DXVA2_ProcAmp_Hue, m_hue);
+ }
+ if (m_dirtyValues & DXVA2_ProcAmp_Saturation) {
+ values.Saturation = scaleProcAmpValue(DXVA2_ProcAmp_Saturation, m_saturation);
+ }
+
+ if (SUCCEEDED(m_processor->SetProcAmpValues(m_dirtyValues, &values))) {
+ m_dirtyValues = 0;
+ }
+ }
+}
+
+DXVA2_Fixed32 EvrVideoWindowControl::scaleProcAmpValue(DWORD prop, float value) const
+{
+ float scaledValue = 0.0;
+
+ DXVA2_ValueRange range;
+ if (SUCCEEDED(m_processor->GetProcAmpRange(prop, &range))) {
+ scaledValue = DXVA2FixedToFloat(range.DefaultValue);
+ if (value > 0)
+ scaledValue += float(value) * (DXVA2FixedToFloat(range.MaxValue) - DXVA2FixedToFloat(range.DefaultValue));
+ else if (value < 0)
+ scaledValue -= float(value) * (DXVA2FixedToFloat(range.MinValue) - DXVA2FixedToFloat(range.DefaultValue));
+ }
+
+ return DXVA2FloatToFixed(scaledValue);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_evrvideowindowcontrol_p.cpp"
diff --git a/src/plugins/multimedia/windows/evr/evrvideowindowcontrol_p.h b/src/plugins/multimedia/windows/evr/evrvideowindowcontrol_p.h
new file mode 100644
index 000000000..c4875d28d
--- /dev/null
+++ b/src/plugins/multimedia/windows/evr/evrvideowindowcontrol_p.h
@@ -0,0 +1,72 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef EVRVIDEOWINDOWCONTROL_H
+#define EVRVIDEOWINDOWCONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <d3d9.h>
+#include <dxva2api.h>
+#include <evr9.h>
+#include <evr.h>
+#include <private/qplatformvideosink_p.h>
+#include <private/qwindowsmfdefs_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class EvrVideoWindowControl : public QPlatformVideoSink
+{
+ Q_OBJECT
+public:
+ EvrVideoWindowControl(QVideoSink *parent = 0);
+ ~EvrVideoWindowControl() override;
+
+ bool setEvr(IUnknown *evr);
+
+ void setWinId(WId id) override;
+
+ void setDisplayRect(const QRect &rect) override;
+
+ void setFullScreen(bool fullScreen) override;
+
+ void setAspectRatioMode(Qt::AspectRatioMode mode) override;
+
+ void setBrightness(float brightness) override;
+ void setContrast(float contrast) override;
+ void setHue(float hue) override;
+ void setSaturation(float saturation) override;
+
+ void applyImageControls();
+
+private:
+ void clear();
+ DXVA2_Fixed32 scaleProcAmpValue(DWORD prop, float value) const;
+
+ WId m_windowId;
+ COLORREF m_windowColor;
+ DWORD m_dirtyValues;
+ Qt::AspectRatioMode m_aspectRatioMode;
+ QRect m_displayRect;
+ float m_brightness;
+ float m_contrast;
+ float m_hue;
+ float m_saturation;
+ bool m_fullScreen;
+
+ IMFVideoDisplayControl *m_displayControl;
+ IMFVideoProcessor *m_processor;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowscamera.cpp b/src/plugins/multimedia/windows/mediacapture/qwindowscamera.cpp
new file mode 100644
index 000000000..d5e25e1c5
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowscamera.cpp
@@ -0,0 +1,101 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowscamera_p.h"
+
+#include "qwindowsmediadevicesession_p.h"
+#include "qwindowsmediacapture_p.h"
+#include <qcameradevice.h>
+
+QT_BEGIN_NAMESPACE
+
+QWindowsCamera::QWindowsCamera(QCamera *camera)
+ : QPlatformCamera(camera)
+{
+}
+
+QWindowsCamera::~QWindowsCamera() = default;
+
+bool QWindowsCamera::isActive() const
+{
+ return m_active;
+}
+
+void QWindowsCamera::setActive(bool active)
+{
+ if (m_active == active)
+ return;
+ if (m_cameraDevice.isNull() && active)
+ return;
+ m_active = active;
+ if (m_mediaDeviceSession)
+ m_mediaDeviceSession->setActive(active);
+
+ emit activeChanged(m_active);
+}
+
+void QWindowsCamera::setCamera(const QCameraDevice &camera)
+{
+ if (m_cameraDevice == camera)
+ return;
+ m_cameraDevice = camera;
+ if (m_mediaDeviceSession)
+ m_mediaDeviceSession->setActiveCamera(camera);
+}
+
+void QWindowsCamera::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ QWindowsMediaCaptureService *captureService = static_cast<QWindowsMediaCaptureService *>(session);
+ if (m_captureService == captureService)
+ return;
+
+ if (m_mediaDeviceSession) {
+ m_mediaDeviceSession->disconnect(this);
+ m_mediaDeviceSession->setActive(false);
+ m_mediaDeviceSession->setCameraFormat({});
+ m_mediaDeviceSession->setActiveCamera({});
+ }
+
+ m_captureService = captureService;
+ if (!m_captureService) {
+ m_mediaDeviceSession = nullptr;
+ return;
+ }
+
+ m_mediaDeviceSession = m_captureService->session();
+ Q_ASSERT(m_mediaDeviceSession);
+
+ m_mediaDeviceSession->setActive(false);
+ m_mediaDeviceSession->setActiveCamera(m_cameraDevice);
+ m_mediaDeviceSession->setCameraFormat(m_cameraFormat);
+ m_mediaDeviceSession->setActive(m_active);
+
+ connect(m_mediaDeviceSession, &QWindowsMediaDeviceSession::activeChanged,
+ this, &QWindowsCamera::onActiveChanged);
+}
+
+bool QWindowsCamera::setCameraFormat(const QCameraFormat &format)
+{
+ if (!format.isNull() && !m_cameraDevice.videoFormats().contains(format))
+ return false;
+
+ m_cameraFormat = format.isNull() ? findBestCameraFormat(m_cameraDevice) : format;
+
+ if (m_mediaDeviceSession)
+ m_mediaDeviceSession->setCameraFormat(m_cameraFormat);
+ return true;
+}
+
+void QWindowsCamera::onActiveChanged(bool active)
+{
+ if (m_active == active)
+ return;
+ if (m_cameraDevice.isNull() && active)
+ return;
+ m_active = active;
+ emit activeChanged(m_active);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwindowscamera_p.cpp"
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowscamera_p.h b/src/plugins/multimedia/windows/mediacapture/qwindowscamera_p.h
new file mode 100644
index 000000000..2aec11165
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowscamera_p.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSCAMERA_H
+#define QWINDOWSCAMERA_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformcamera_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsMediaCaptureService;
+class QWindowsMediaDeviceSession;
+
+class QWindowsCamera : public QPlatformCamera
+{
+ Q_OBJECT
+public:
+ explicit QWindowsCamera(QCamera *camera);
+ virtual ~QWindowsCamera();
+
+ bool isActive() const override;
+
+ void setCamera(const QCameraDevice &camera) override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *) override;
+
+ bool setCameraFormat(const QCameraFormat &format) override;
+
+ void setActive(bool active) override;
+
+private Q_SLOTS:
+ void onActiveChanged(bool active);
+
+private:
+ QWindowsMediaCaptureService *m_captureService = nullptr;
+ QWindowsMediaDeviceSession *m_mediaDeviceSession = nullptr;
+ QCameraDevice m_cameraDevice;
+ QCameraFormat m_cameraFormat;
+ bool m_active = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWINDOWSCAMERA_H
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowsimagecapture.cpp b/src/plugins/multimedia/windows/mediacapture/qwindowsimagecapture.cpp
new file mode 100644
index 000000000..ea66d561a
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowsimagecapture.cpp
@@ -0,0 +1,207 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsimagecapture_p.h"
+
+#include "qwindowsmediadevicesession_p.h"
+#include "qwindowsmediacapture_p.h"
+#include <private/qmediastoragelocation_p.h>
+
+#include <QtConcurrent/qtconcurrentrun.h>
+#include <QtGui/qimagewriter.h>
+
+QT_BEGIN_NAMESPACE
+
+QWindowsImageCapture::QWindowsImageCapture(QImageCapture *parent)
+ : QPlatformImageCapture(parent)
+{
+}
+
+QWindowsImageCapture::~QWindowsImageCapture() = default;
+
+bool QWindowsImageCapture::isReadyForCapture() const
+{
+ if (!m_mediaDeviceSession)
+ return false;
+ return !m_capturing && m_mediaDeviceSession->isActive() && !m_mediaDeviceSession->activeCamera().isNull();
+}
+
+int QWindowsImageCapture::capture(const QString &fileName)
+{
+ auto ext = writerFormat(m_settings.format());
+ auto path = QMediaStorageLocation::generateFileName(fileName, QStandardPaths::PicturesLocation, ext);
+ return doCapture(path);
+}
+
+int QWindowsImageCapture::captureToBuffer()
+{
+ return doCapture(QString());
+}
+
+int QWindowsImageCapture::doCapture(const QString &fileName)
+{
+ if (!isReadyForCapture())
+ return -1;
+ m_fileName = fileName;
+ m_capturing = true;
+ return m_captureId;
+}
+
+QImageEncoderSettings QWindowsImageCapture::imageSettings() const
+{
+ return m_settings;
+}
+
+void QWindowsImageCapture::setImageSettings(const QImageEncoderSettings &settings)
+{
+ m_settings = settings;
+}
+
+void QWindowsImageCapture::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ QWindowsMediaCaptureService *captureService = static_cast<QWindowsMediaCaptureService *>(session);
+ if (m_captureService == captureService)
+ return;
+
+ auto readyForCapture = isReadyForCapture();
+ if (m_mediaDeviceSession)
+ disconnect(m_mediaDeviceSession, nullptr, this, nullptr);
+
+ m_captureService = captureService;
+ if (!m_captureService) {
+ if (readyForCapture)
+ emit readyForCaptureChanged(false);
+ m_mediaDeviceSession = nullptr;
+ return;
+ }
+
+ m_mediaDeviceSession = m_captureService->session();
+ Q_ASSERT(m_mediaDeviceSession);
+
+ if (isReadyForCapture() != readyForCapture)
+ emit readyForCaptureChanged(isReadyForCapture());
+
+ connect(m_mediaDeviceSession, &QWindowsMediaDeviceSession::readyForCaptureChanged,
+ this, &QWindowsImageCapture::readyForCaptureChanged);
+
+ connect(m_mediaDeviceSession, &QWindowsMediaDeviceSession::videoFrameChanged,
+ this, &QWindowsImageCapture::handleVideoFrameChanged);
+}
+
+void QWindowsImageCapture::handleVideoFrameChanged(const QVideoFrame &frame)
+{
+ if (m_capturing) {
+
+ QImage image = frame.toImage();
+
+ QSize size = m_settings.resolution();
+ if (size.isValid() && image.size() != size) {
+ image = image.scaled(size, Qt::KeepAspectRatioByExpanding);
+ if (image.size() != size) {
+ int xoff = (image.size().width() - size.width()) / 2;
+ int yoff = (image.size().height() - size.height()) / 2;
+ image = image.copy(xoff, yoff, size.width(), size.height());
+ }
+ }
+
+ emit imageExposed(m_captureId);
+ emit imageAvailable(m_captureId, frame);
+ emit imageCaptured(m_captureId, image);
+
+ QMediaMetaData metaData = this->metaData();
+ metaData.insert(QMediaMetaData::Date, QDateTime::currentDateTime());
+ metaData.insert(QMediaMetaData::Resolution, size);
+
+ emit imageMetadataAvailable(m_captureId, metaData);
+
+ if (!m_fileName.isEmpty()) {
+
+ (void)QtConcurrent::run(&QWindowsImageCapture::saveImage, this,
+ m_captureId, m_fileName, image, metaData, m_settings);
+ }
+
+ ++m_captureId;
+ m_capturing = false;
+ }
+}
+
+void QWindowsImageCapture::saveImage(int captureId, const QString &fileName,
+ const QImage &image, const QMediaMetaData &metaData,
+ const QImageEncoderSettings &settings)
+{
+ QImageWriter imageWriter;
+ imageWriter.setFileName(fileName);
+
+ QString format = writerFormat(settings.format());
+ imageWriter.setFormat(format.toUtf8());
+
+ int quality = writerQuality(format, settings.quality());
+ if (quality > -1)
+ imageWriter.setQuality(quality);
+
+ for (auto key : metaData.keys())
+ imageWriter.setText(QMediaMetaData::metaDataKeyToString(key),
+ metaData.stringValue(key));
+
+ imageWriter.write(image);
+
+ QMetaObject::invokeMethod(this, "imageSaved", Qt::QueuedConnection,
+ Q_ARG(int, captureId), Q_ARG(QString, fileName));
+}
+
+QString QWindowsImageCapture::writerFormat(QImageCapture::FileFormat reqFormat)
+{
+ QString format;
+
+ switch (reqFormat) {
+ case QImageCapture::FileFormat::JPEG:
+ format = QLatin1String("jpg");
+ break;
+ case QImageCapture::FileFormat::PNG:
+ format = QLatin1String("png");
+ break;
+ case QImageCapture::FileFormat::WebP:
+ format = QLatin1String("webp");
+ break;
+ case QImageCapture::FileFormat::Tiff:
+ format = QLatin1String("tiff");
+ break;
+ default:
+ format = QLatin1String("jpg");
+ }
+
+ auto supported = QImageWriter::supportedImageFormats();
+ for (const auto &f : supported)
+ if (format.compare(QString::fromUtf8(f), Qt::CaseInsensitive) == 0)
+ return format;
+
+ return QLatin1String("jpg");
+}
+
+int QWindowsImageCapture::writerQuality(const QString &writerFormat,
+ QImageCapture::Quality quality)
+{
+ if (writerFormat.compare(QLatin1String("jpg"), Qt::CaseInsensitive) == 0 ||
+ writerFormat.compare(QLatin1String("jpeg"), Qt::CaseInsensitive) == 0) {
+
+ switch (quality) {
+ case QImageCapture::Quality::VeryLowQuality:
+ return 10;
+ case QImageCapture::Quality::LowQuality:
+ return 30;
+ case QImageCapture::Quality::NormalQuality:
+ return 75;
+ case QImageCapture::Quality::HighQuality:
+ return 90;
+ case QImageCapture::Quality::VeryHighQuality:
+ return 98;
+ default:
+ return 75;
+ }
+ }
+ return -1;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwindowsimagecapture_p.cpp"
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowsimagecapture_p.h b/src/plugins/multimedia/windows/mediacapture/qwindowsimagecapture_p.h
new file mode 100644
index 000000000..746732e73
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowsimagecapture_p.h
@@ -0,0 +1,64 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSIMAGECAPTURE_H
+#define QWINDOWSIMAGECAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformimagecapture_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsMediaDeviceSession;
+class QWindowsMediaCaptureService;
+
+class QWindowsImageCapture : public QPlatformImageCapture
+{
+ Q_OBJECT
+public:
+ explicit QWindowsImageCapture(QImageCapture *parent);
+ virtual ~QWindowsImageCapture();
+
+ bool isReadyForCapture() const override;
+
+ int capture(const QString &fileName) override;
+ int captureToBuffer() override;
+
+ QImageEncoderSettings imageSettings() const override;
+ void setImageSettings(const QImageEncoderSettings &settings) override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session);
+
+private Q_SLOTS:
+ void handleVideoFrameChanged(const QVideoFrame &frame);
+
+private:
+ int doCapture(const QString &fileName);
+ void saveImage(int captureId, const QString &fileName,
+ const QImage &image, const QMediaMetaData &metaData,
+ const QImageEncoderSettings &settings);
+ QString writerFormat(QImageCapture::FileFormat reqFormat);
+ int writerQuality(const QString &writerFormat,
+ QImageCapture::Quality quality);
+
+ QWindowsMediaCaptureService *m_captureService = nullptr;
+ QWindowsMediaDeviceSession *m_mediaDeviceSession = nullptr;
+ QImageEncoderSettings m_settings;
+ int m_captureId = 0;
+ bool m_capturing = false;
+ QString m_fileName;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWINDOWSIMAGECAPTURE_H
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowsmediacapture.cpp b/src/plugins/multimedia/windows/mediacapture/qwindowsmediacapture.cpp
new file mode 100644
index 000000000..d349b2c43
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowsmediacapture.cpp
@@ -0,0 +1,109 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsmediacapture_p.h"
+
+#include "qwindowsmediaencoder_p.h"
+#include "qwindowscamera_p.h"
+#include "qwindowsmediadevicesession_p.h"
+#include "qwindowsimagecapture_p.h"
+#include "qmediadevices.h"
+#include "qaudiodevice.h"
+#include "private/qplatformaudioinput_p.h"
+#include "private/qplatformaudiooutput_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QWindowsMediaCaptureService::QWindowsMediaCaptureService()
+{
+ m_mediaDeviceSession = new QWindowsMediaDeviceSession(this);
+}
+
+QWindowsMediaCaptureService::~QWindowsMediaCaptureService()
+{
+ delete m_mediaDeviceSession;
+}
+
+QPlatformCamera *QWindowsMediaCaptureService::camera()
+{
+ return m_camera;
+}
+
+void QWindowsMediaCaptureService::setCamera(QPlatformCamera *camera)
+{
+ QWindowsCamera *control = static_cast<QWindowsCamera*>(camera);
+ if (m_camera == control)
+ return;
+
+ if (m_camera)
+ m_camera->setCaptureSession(nullptr);
+
+ m_camera = control;
+ if (m_camera)
+ m_camera->setCaptureSession(this);
+ emit cameraChanged();
+}
+
+QPlatformImageCapture *QWindowsMediaCaptureService::imageCapture()
+{
+ return m_imageCapture;
+}
+
+void QWindowsMediaCaptureService::setImageCapture(QPlatformImageCapture *imageCapture)
+{
+ QWindowsImageCapture *control = static_cast<QWindowsImageCapture *>(imageCapture);
+ if (m_imageCapture == control)
+ return;
+
+ if (m_imageCapture)
+ m_imageCapture->setCaptureSession(nullptr);
+
+ m_imageCapture = control;
+ if (m_imageCapture)
+ m_imageCapture->setCaptureSession(this);
+ emit imageCaptureChanged();
+}
+
+QPlatformMediaRecorder *QWindowsMediaCaptureService::mediaRecorder()
+{
+ return m_encoder;
+}
+
+void QWindowsMediaCaptureService::setMediaRecorder(QPlatformMediaRecorder *recorder)
+{
+ QWindowsMediaEncoder *control = static_cast<QWindowsMediaEncoder *>(recorder);
+ if (m_encoder == control)
+ return;
+
+ if (m_encoder)
+ m_encoder->setCaptureSession(nullptr);
+
+ m_encoder = control;
+ if (m_encoder)
+ m_encoder->setCaptureSession(this);
+ emit encoderChanged();
+}
+
+void QWindowsMediaCaptureService::setAudioInput(QPlatformAudioInput *input)
+{
+ m_mediaDeviceSession->setAudioInput(input ? input->q : nullptr);
+}
+
+void QWindowsMediaCaptureService::setAudioOutput(QPlatformAudioOutput *output)
+{
+ m_mediaDeviceSession->setAudioOutput(output ? output->q : nullptr);
+}
+
+void QWindowsMediaCaptureService::setVideoPreview(QVideoSink *sink)
+{
+ m_mediaDeviceSession->setVideoSink(sink);
+}
+
+QWindowsMediaDeviceSession *QWindowsMediaCaptureService::session() const
+{
+ return m_mediaDeviceSession;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwindowsmediacapture_p.cpp"
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowsmediacapture_p.h b/src/plugins/multimedia/windows/mediacapture/qwindowsmediacapture_p.h
new file mode 100644
index 000000000..579310afd
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowsmediacapture_p.h
@@ -0,0 +1,62 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QWINDOWSMEDIACAPTURE_H
+#define QWINDOWSMEDIACAPTURE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediacapture_p.h>
+#include <private/qplatformmediaintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsMediaEncoder;
+class QWindowsCamera;
+class QWindowsMediaDeviceSession;
+class QWindowsImageCapture;
+class QPlatformAudioInput;
+
+class QWindowsMediaCaptureService : public QPlatformMediaCaptureSession
+{
+ Q_OBJECT
+
+public:
+ QWindowsMediaCaptureService();
+ virtual ~QWindowsMediaCaptureService();
+
+ QPlatformCamera *camera() override;
+ void setCamera(QPlatformCamera *camera) override;
+
+ QPlatformImageCapture *imageCapture() override;
+ void setImageCapture(QPlatformImageCapture *imageCapture) override;
+
+ QPlatformMediaRecorder *mediaRecorder() override;
+ void setMediaRecorder(QPlatformMediaRecorder *recorder) override;
+
+ void setAudioInput(QPlatformAudioInput *) override;
+
+ void setAudioOutput(QPlatformAudioOutput *output) override;
+
+ void setVideoPreview(QVideoSink *sink) override;
+
+ QWindowsMediaDeviceSession *session() const;
+
+private:
+ QWindowsCamera *m_camera = nullptr;
+ QWindowsMediaDeviceSession *m_mediaDeviceSession = nullptr;
+ QWindowsImageCapture *m_imageCapture = nullptr;
+ QWindowsMediaEncoder *m_encoder = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWINDOWSMEDIAINTERFACE_H
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicereader.cpp b/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicereader.cpp
new file mode 100644
index 000000000..e99b95ad2
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicereader.cpp
@@ -0,0 +1,1019 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsmediadevicereader_p.h"
+
+#include "private/qwindowsmultimediautils_p.h"
+#include <qvideosink.h>
+#include <qmediadevices.h>
+#include <qaudiodevice.h>
+#include <private/qmemoryvideobuffer_p.h>
+#include <private/qvideoframe_p.h>
+#include <private/qwindowsmfdefs_p.h>
+#include <private/qcomptr_p.h>
+#include <QtCore/qdebug.h>
+
+#include <mmdeviceapi.h>
+
+QT_BEGIN_NAMESPACE
+
+enum { MEDIA_TYPE_INDEX_DEFAULT = 0xffffffff };
+
+QWindowsMediaDeviceReader::QWindowsMediaDeviceReader(QObject *parent)
+ : QObject(parent)
+{
+ m_durationTimer.setInterval(100);
+ connect(&m_durationTimer, &QTimer::timeout, this, &QWindowsMediaDeviceReader::updateDuration);
+}
+
+QWindowsMediaDeviceReader::~QWindowsMediaDeviceReader()
+{
+ stopRecording();
+ deactivate();
+}
+
+// Creates a video or audio media source specified by deviceId (symbolic link)
+HRESULT QWindowsMediaDeviceReader::createSource(const QString &deviceId, bool video, IMFMediaSource **source)
+{
+ if (!source)
+ return E_INVALIDARG;
+
+ *source = nullptr;
+ IMFAttributes *sourceAttributes = nullptr;
+
+ HRESULT hr = MFCreateAttributes(&sourceAttributes, 2);
+ if (SUCCEEDED(hr)) {
+
+ hr = sourceAttributes->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
+ video ? QMM_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID
+ : QMM_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_GUID);
+ if (SUCCEEDED(hr)) {
+
+ hr = sourceAttributes->SetString(video ? MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK
+ : MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_ENDPOINT_ID,
+ reinterpret_cast<LPCWSTR>(deviceId.utf16()));
+ if (SUCCEEDED(hr)) {
+
+ hr = MFCreateDeviceSource(sourceAttributes, source);
+ }
+ }
+ sourceAttributes->Release();
+ }
+
+ return hr;
+}
+
+// Creates a source/reader aggregating two other sources (video/audio).
+// If one of the sources is null the result will be video-only or audio-only.
+HRESULT QWindowsMediaDeviceReader::createAggregateReader(IMFMediaSource *firstSource,
+ IMFMediaSource *secondSource,
+ IMFMediaSource **aggregateSource,
+ IMFSourceReader **sourceReader)
+{
+ if ((!firstSource && !secondSource) || !aggregateSource || !sourceReader)
+ return E_INVALIDARG;
+
+ *aggregateSource = nullptr;
+ *sourceReader = nullptr;
+
+ IMFCollection *sourceCollection = nullptr;
+
+ HRESULT hr = MFCreateCollection(&sourceCollection);
+ if (SUCCEEDED(hr)) {
+
+ if (firstSource)
+ sourceCollection->AddElement(firstSource);
+
+ if (secondSource)
+ sourceCollection->AddElement(secondSource);
+
+ hr = MFCreateAggregateSource(sourceCollection, aggregateSource);
+ if (SUCCEEDED(hr)) {
+
+ IMFAttributes *readerAttributes = nullptr;
+
+ hr = MFCreateAttributes(&readerAttributes, 1);
+ if (SUCCEEDED(hr)) {
+
+ // Set callback so OnReadSample() is called for each new video frame or audio sample.
+ hr = readerAttributes->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK,
+ static_cast<IMFSourceReaderCallback*>(this));
+ if (SUCCEEDED(hr)) {
+
+ hr = MFCreateSourceReaderFromMediaSource(*aggregateSource, readerAttributes, sourceReader);
+ }
+ readerAttributes->Release();
+ }
+ }
+ sourceCollection->Release();
+ }
+ return hr;
+}
+
+// Selects the requested resolution/frame rate (if specified),
+// or chooses a high quality configuration otherwise.
+DWORD QWindowsMediaDeviceReader::findMediaTypeIndex(const QCameraFormat &reqFormat)
+{
+ DWORD mediaIndex = MEDIA_TYPE_INDEX_DEFAULT;
+
+ if (m_sourceReader && m_videoSource) {
+
+ DWORD index = 0;
+ IMFMediaType *mediaType = nullptr;
+
+ UINT32 currArea = 0;
+ float currFrameRate = 0.0f;
+
+ while (SUCCEEDED(m_sourceReader->GetNativeMediaType(DWORD(MF_SOURCE_READER_FIRST_VIDEO_STREAM),
+ index, &mediaType))) {
+
+ GUID subtype = GUID_NULL;
+ if (SUCCEEDED(mediaType->GetGUID(MF_MT_SUBTYPE, &subtype))) {
+
+ auto pixelFormat = QWindowsMultimediaUtils::pixelFormatFromMediaSubtype(subtype);
+ if (pixelFormat != QVideoFrameFormat::Format_Invalid) {
+
+ UINT32 width, height;
+ if (SUCCEEDED(MFGetAttributeSize(mediaType, MF_MT_FRAME_SIZE, &width, &height))) {
+
+ UINT32 num, den;
+ if (SUCCEEDED(MFGetAttributeRatio(mediaType, MF_MT_FRAME_RATE, &num, &den))) {
+
+ UINT32 area = width * height;
+ float frameRate = float(num) / den;
+
+ if (!reqFormat.isNull()
+ && UINT32(reqFormat.resolution().width()) == width
+ && UINT32(reqFormat.resolution().height()) == height
+ && qFuzzyCompare(reqFormat.maxFrameRate(), frameRate)
+ && reqFormat.pixelFormat() == pixelFormat) {
+ mediaType->Release();
+ return index;
+ }
+
+ if ((currFrameRate < 29.9 && currFrameRate < frameRate) ||
+ (currFrameRate == frameRate && currArea < area)) {
+ currArea = area;
+ currFrameRate = frameRate;
+ mediaIndex = index;
+ }
+ }
+ }
+ }
+ }
+ mediaType->Release();
+ ++index;
+ }
+ }
+
+ return mediaIndex;
+}
+
+
+// Prepares the source video stream and gets some metadata.
+HRESULT QWindowsMediaDeviceReader::prepareVideoStream(DWORD mediaTypeIndex)
+{
+ if (!m_sourceReader)
+ return E_FAIL;
+
+ if (!m_videoSource)
+ return S_OK; // It may be audio-only
+
+ HRESULT hr;
+
+ if (mediaTypeIndex == MEDIA_TYPE_INDEX_DEFAULT) {
+ hr = m_sourceReader->GetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_VIDEO_STREAM),
+ &m_videoMediaType);
+ } else {
+ hr = m_sourceReader->GetNativeMediaType(DWORD(MF_SOURCE_READER_FIRST_VIDEO_STREAM),
+ mediaTypeIndex, &m_videoMediaType);
+ if (SUCCEEDED(hr))
+ hr = m_sourceReader->SetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_VIDEO_STREAM),
+ nullptr, m_videoMediaType);
+ }
+
+ if (SUCCEEDED(hr)) {
+
+ GUID subtype = GUID_NULL;
+ hr = m_videoMediaType->GetGUID(MF_MT_SUBTYPE, &subtype);
+ if (SUCCEEDED(hr)) {
+
+ m_pixelFormat = QWindowsMultimediaUtils::pixelFormatFromMediaSubtype(subtype);
+
+ if (m_pixelFormat == QVideoFrameFormat::Format_Invalid) {
+ hr = E_FAIL;
+ } else {
+
+ // get the frame dimensions
+ hr = MFGetAttributeSize(m_videoMediaType, MF_MT_FRAME_SIZE, &m_frameWidth, &m_frameHeight);
+ if (SUCCEEDED(hr)) {
+
+ // and the stride, which we need to convert the frame later
+ hr = MFGetStrideForBitmapInfoHeader(subtype.Data1, m_frameWidth, &m_stride);
+ if (SUCCEEDED(hr)) {
+ m_stride = qAbs(m_stride);
+ UINT32 frameRateNum, frameRateDen;
+ hr = MFGetAttributeRatio(m_videoMediaType, MF_MT_FRAME_RATE, &frameRateNum, &frameRateDen);
+ if (SUCCEEDED(hr)) {
+
+ m_frameRate = qreal(frameRateNum) / frameRateDen;
+
+ hr = m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_FIRST_VIDEO_STREAM), TRUE);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return hr;
+}
+
+HRESULT QWindowsMediaDeviceReader::initAudioType(IMFMediaType *mediaType, UINT32 channels, UINT32 samplesPerSec, bool flt)
+{
+ if (!mediaType)
+ return E_INVALIDARG;
+
+ HRESULT hr = mediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
+ if (SUCCEEDED(hr)) {
+ hr = mediaType->SetGUID(MF_MT_SUBTYPE, flt ? MFAudioFormat_Float : MFAudioFormat_PCM);
+ if (SUCCEEDED(hr)) {
+ hr = mediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, channels);
+ if (SUCCEEDED(hr)) {
+ hr = mediaType->SetUINT32(MF_MT_AUDIO_CHANNEL_MASK,
+ (channels == 1) ? SPEAKER_FRONT_CENTER : (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT ));
+ if (SUCCEEDED(hr)) {
+ hr = mediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, samplesPerSec);
+ if (SUCCEEDED(hr)) {
+ UINT32 bitsPerSample = flt ? 32 : 16;
+ UINT32 bytesPerFrame = channels * bitsPerSample/8;
+ hr = mediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, bitsPerSample);
+ if (SUCCEEDED(hr)) {
+ hr = mediaType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, bytesPerFrame);
+ if (SUCCEEDED(hr)) {
+ hr = mediaType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, bytesPerFrame * samplesPerSec);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return hr;
+}
+
+// Prepares the source audio stream.
+HRESULT QWindowsMediaDeviceReader::prepareAudioStream()
+{
+ if (!m_sourceReader)
+ return E_FAIL;
+
+ if (!m_audioSource)
+ return S_OK; // It may be video-only
+
+ HRESULT hr = m_sourceReader->GetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM),
+ &m_audioMediaType);
+ if (SUCCEEDED(hr)) {
+ hr = initAudioType(m_audioMediaType, 2, 48000, true);
+ if (SUCCEEDED(hr)) {
+ hr = m_sourceReader->SetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM),
+ nullptr, m_audioMediaType);
+ if (SUCCEEDED(hr)) {
+ hr = m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), TRUE);
+ }
+ }
+ }
+ return hr;
+}
+
+// Retrieves the indexes for selected video/audio streams.
+HRESULT QWindowsMediaDeviceReader::initSourceIndexes()
+{
+ if (!m_sourceReader)
+ return E_FAIL;
+
+ m_sourceVideoStreamIndex = MF_SOURCE_READER_INVALID_STREAM_INDEX;
+ m_sourceAudioStreamIndex = MF_SOURCE_READER_INVALID_STREAM_INDEX;
+
+ DWORD index = 0;
+ BOOL selected = FALSE;
+
+ while (m_sourceReader->GetStreamSelection(index, &selected) == S_OK) {
+ if (selected) {
+ IMFMediaType *mediaType = nullptr;
+ if (SUCCEEDED(m_sourceReader->GetCurrentMediaType(index, &mediaType))) {
+ GUID majorType = GUID_NULL;
+ if (SUCCEEDED(mediaType->GetGUID(MF_MT_MAJOR_TYPE, &majorType))) {
+ if (majorType == MFMediaType_Video)
+ m_sourceVideoStreamIndex = index;
+ else if (majorType == MFMediaType_Audio)
+ m_sourceAudioStreamIndex = index;
+ }
+ mediaType->Release();
+ }
+ }
+ ++index;
+ }
+ if ((m_videoSource && m_sourceVideoStreamIndex == MF_SOURCE_READER_INVALID_STREAM_INDEX) ||
+ (m_audioSource && m_sourceAudioStreamIndex == MF_SOURCE_READER_INVALID_STREAM_INDEX))
+ return E_FAIL;
+ return S_OK;
+}
+
+bool QWindowsMediaDeviceReader::setAudioOutput(const QString &audioOutputId)
+{
+ QMutexLocker locker(&m_mutex);
+
+ stopMonitoring();
+
+ m_audioOutputId = audioOutputId;
+
+ if (!m_active || m_audioOutputId.isEmpty())
+ return true;
+
+ HRESULT hr = startMonitoring();
+
+ return SUCCEEDED(hr);
+}
+
+HRESULT QWindowsMediaDeviceReader::startMonitoring()
+{
+ if (m_audioOutputId.isEmpty())
+ return E_FAIL;
+
+ IMFAttributes *sinkAttributes = nullptr;
+
+ HRESULT hr = MFCreateAttributes(&sinkAttributes, 1);
+ if (SUCCEEDED(hr)) {
+
+ hr = sinkAttributes->SetString(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ID,
+ reinterpret_cast<LPCWSTR>(m_audioOutputId.utf16()));
+ if (SUCCEEDED(hr)) {
+
+ IMFMediaSink *mediaSink = nullptr;
+ hr = MFCreateAudioRenderer(sinkAttributes, &mediaSink);
+ if (SUCCEEDED(hr)) {
+
+ IMFStreamSink *streamSink = nullptr;
+ hr = mediaSink->GetStreamSinkByIndex(0, &streamSink);
+ if (SUCCEEDED(hr)) {
+
+ IMFMediaTypeHandler *typeHandler = nullptr;
+ hr = streamSink->GetMediaTypeHandler(&typeHandler);
+ if (SUCCEEDED(hr)) {
+
+ hr = typeHandler->IsMediaTypeSupported(m_audioMediaType, nullptr);
+ if (SUCCEEDED(hr)) {
+
+ hr = typeHandler->SetCurrentMediaType(m_audioMediaType);
+ if (SUCCEEDED(hr)) {
+
+ IMFAttributes *writerAttributes = nullptr;
+
+ HRESULT hr = MFCreateAttributes(&writerAttributes, 1);
+ if (SUCCEEDED(hr)) {
+
+ hr = writerAttributes->SetUINT32(MF_SINK_WRITER_DISABLE_THROTTLING, TRUE);
+ if (SUCCEEDED(hr)) {
+
+ IMFSinkWriter *sinkWriter = nullptr;
+ hr = MFCreateSinkWriterFromMediaSink(mediaSink, writerAttributes, &sinkWriter);
+ if (SUCCEEDED(hr)) {
+
+ hr = sinkWriter->SetInputMediaType(0, m_audioMediaType, nullptr);
+ if (SUCCEEDED(hr)) {
+
+ IMFSimpleAudioVolume *audioVolume = nullptr;
+
+ if (SUCCEEDED(MFGetService(mediaSink, QMM_MR_POLICY_VOLUME_SERVICE, IID_PPV_ARGS(&audioVolume)))) {
+ audioVolume->SetMasterVolume(float(m_outputVolume));
+ audioVolume->SetMute(m_outputMuted);
+ audioVolume->Release();
+ }
+
+ hr = sinkWriter->BeginWriting();
+ if (SUCCEEDED(hr)) {
+ m_monitorSink = mediaSink;
+ m_monitorSink->AddRef();
+ m_monitorWriter = sinkWriter;
+ m_monitorWriter->AddRef();
+ }
+ }
+ sinkWriter->Release();
+ }
+ }
+ writerAttributes->Release();
+ }
+ }
+ }
+ typeHandler->Release();
+ }
+ streamSink->Release();
+ }
+ mediaSink->Release();
+ }
+ }
+ sinkAttributes->Release();
+ }
+
+ return hr;
+}
+
+void QWindowsMediaDeviceReader::stopMonitoring()
+{
+ if (m_monitorWriter) {
+ m_monitorWriter->Release();
+ m_monitorWriter = nullptr;
+ }
+ if (m_monitorSink) {
+ m_monitorSink->Shutdown();
+ m_monitorSink->Release();
+ m_monitorSink = nullptr;
+ }
+}
+
+// Activates the requested camera/microphone for streaming.
+// One of the IDs may be empty for video-only/audio-only.
+bool QWindowsMediaDeviceReader::activate(const QString &cameraId,
+ const QCameraFormat &cameraFormat,
+ const QString &microphoneId)
+{
+ QMutexLocker locker(&m_mutex);
+
+ if (cameraId.isEmpty() && microphoneId.isEmpty())
+ return false;
+
+ stopMonitoring();
+ releaseResources();
+
+ m_active = false;
+ m_streaming = false;
+
+ if (!cameraId.isEmpty()) {
+ if (!SUCCEEDED(createSource(cameraId, true, &m_videoSource))) {
+ releaseResources();
+ return false;
+ }
+ }
+
+ if (!microphoneId.isEmpty()) {
+ if (!SUCCEEDED(createSource(microphoneId, false, &m_audioSource))) {
+ releaseResources();
+ return false;
+ }
+ }
+
+ if (!SUCCEEDED(createAggregateReader(m_videoSource, m_audioSource, &m_aggregateSource, &m_sourceReader))) {
+ releaseResources();
+ return false;
+ }
+
+ DWORD mediaTypeIndex = findMediaTypeIndex(cameraFormat);
+
+ if (!SUCCEEDED(prepareVideoStream(mediaTypeIndex))) {
+ releaseResources();
+ return false;
+ }
+
+ if (!SUCCEEDED(prepareAudioStream())) {
+ releaseResources();
+ return false;
+ }
+
+ if (!SUCCEEDED(initSourceIndexes())) {
+ releaseResources();
+ return false;
+ }
+
+ updateSinkInputMediaTypes();
+ startMonitoring();
+
+ // Request the first frame or audio sample.
+ if (!SUCCEEDED(m_sourceReader->ReadSample(MF_SOURCE_READER_ANY_STREAM, 0, nullptr, nullptr, nullptr, nullptr))) {
+ releaseResources();
+ return false;
+ }
+
+ m_active = true;
+ return true;
+}
+
+void QWindowsMediaDeviceReader::deactivate()
+{
+ stopMonitoring();
+ stopStreaming();
+ m_active = false;
+ m_streaming = false;
+}
+
+void QWindowsMediaDeviceReader::stopStreaming()
+{
+ QMutexLocker locker(&m_mutex);
+ releaseResources();
+}
+
+// Releases allocated streaming stuff.
+void QWindowsMediaDeviceReader::releaseResources()
+{
+ if (m_videoMediaType) {
+ m_videoMediaType->Release();
+ m_videoMediaType = nullptr;
+ }
+ if (m_audioMediaType) {
+ m_audioMediaType->Release();
+ m_audioMediaType = nullptr;
+ }
+ if (m_sourceReader) {
+ m_sourceReader->Release();
+ m_sourceReader = nullptr;
+ }
+ if (m_aggregateSource) {
+ m_aggregateSource->Release();
+ m_aggregateSource = nullptr;
+ }
+ if (m_videoSource) {
+ m_videoSource->Release();
+ m_videoSource = nullptr;
+ }
+ if (m_audioSource) {
+ m_audioSource->Release();
+ m_audioSource = nullptr;
+ }
+}
+
+HRESULT QWindowsMediaDeviceReader::createVideoMediaType(const GUID &format, UINT32 bitRate, UINT32 width,
+ UINT32 height, qreal frameRate, IMFMediaType **mediaType)
+{
+ if (!mediaType)
+ return E_INVALIDARG;
+
+ *mediaType = nullptr;
+ IMFMediaType *targetMediaType = nullptr;
+
+ if (SUCCEEDED(MFCreateMediaType(&targetMediaType))) {
+
+ if (SUCCEEDED(targetMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video))) {
+
+ if (SUCCEEDED(targetMediaType->SetGUID(MF_MT_SUBTYPE, format))) {
+
+ if (SUCCEEDED(targetMediaType->SetUINT32(MF_MT_AVG_BITRATE, bitRate))) {
+
+ if (SUCCEEDED(MFSetAttributeSize(targetMediaType, MF_MT_FRAME_SIZE, width, height))) {
+
+ if (SUCCEEDED(MFSetAttributeRatio(targetMediaType, MF_MT_FRAME_RATE,
+ UINT32(frameRate * 1000), 1000))) {
+ UINT32 t1, t2;
+ if (SUCCEEDED(MFGetAttributeRatio(m_videoMediaType, MF_MT_PIXEL_ASPECT_RATIO, &t1, &t2))) {
+
+ if (SUCCEEDED(MFSetAttributeRatio(targetMediaType, MF_MT_PIXEL_ASPECT_RATIO, t1, t2))) {
+
+ if (SUCCEEDED(m_videoMediaType->GetUINT32(MF_MT_INTERLACE_MODE, &t1))) {
+
+ if (SUCCEEDED(targetMediaType->SetUINT32(MF_MT_INTERLACE_MODE, t1))) {
+
+ *mediaType = targetMediaType;
+ return S_OK;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ targetMediaType->Release();
+ }
+ return E_FAIL;
+}
+
+HRESULT QWindowsMediaDeviceReader::createAudioMediaType(const GUID &format, UINT32 bitRate, IMFMediaType **mediaType)
+{
+ if (!mediaType)
+ return E_INVALIDARG;
+
+ *mediaType = nullptr;
+ IMFMediaType *targetMediaType = nullptr;
+
+ if (SUCCEEDED(MFCreateMediaType(&targetMediaType))) {
+
+ if (SUCCEEDED(targetMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio))) {
+
+ if (SUCCEEDED(targetMediaType->SetGUID(MF_MT_SUBTYPE, format))) {
+
+ if (bitRate == 0 || SUCCEEDED(targetMediaType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, bitRate / 8))) {
+
+ *mediaType = targetMediaType;
+ return S_OK;
+ }
+ }
+ }
+ targetMediaType->Release();
+ }
+ return E_FAIL;
+}
+
+HRESULT QWindowsMediaDeviceReader::updateSinkInputMediaTypes()
+{
+ HRESULT hr = S_OK;
+ if (m_sinkWriter) {
+ if (m_videoSource && m_videoMediaType && m_sinkVideoStreamIndex != MF_SINK_WRITER_INVALID_STREAM_INDEX) {
+ hr = m_sinkWriter->SetInputMediaType(m_sinkVideoStreamIndex, m_videoMediaType, nullptr);
+ }
+ if (SUCCEEDED(hr)) {
+ if (m_audioSource && m_audioMediaType && m_sinkAudioStreamIndex != MF_SINK_WRITER_INVALID_STREAM_INDEX) {
+ hr = m_sinkWriter->SetInputMediaType(m_sinkAudioStreamIndex, m_audioMediaType, nullptr);
+ }
+ }
+ }
+ return hr;
+}
+
+QMediaRecorder::Error QWindowsMediaDeviceReader::startRecording(
+ const QString &fileName, const GUID &container, const GUID &videoFormat, UINT32 videoBitRate,
+ UINT32 width, UINT32 height, qreal frameRate, const GUID &audioFormat, UINT32 audioBitRate)
+{
+ QMutexLocker locker(&m_mutex);
+
+ if (!m_active || m_recording || (videoFormat == GUID_NULL && audioFormat == GUID_NULL))
+ return QMediaRecorder::ResourceError;
+
+ ComPtr<IMFAttributes> writerAttributes;
+
+ HRESULT hr = MFCreateAttributes(writerAttributes.GetAddressOf(), 2);
+ if (FAILED(hr))
+ return QMediaRecorder::ResourceError;
+
+ // Set callback so OnFinalize() is called after video is saved.
+ hr = writerAttributes->SetUnknown(MF_SINK_WRITER_ASYNC_CALLBACK,
+ static_cast<IMFSinkWriterCallback*>(this));
+ if (FAILED(hr))
+ return QMediaRecorder::ResourceError;
+
+ hr = writerAttributes->SetGUID(QMM_MF_TRANSCODE_CONTAINERTYPE, container);
+ if (FAILED(hr))
+ return QMediaRecorder::ResourceError;
+
+ ComPtr<IMFSinkWriter> sinkWriter;
+ hr = MFCreateSinkWriterFromURL(reinterpret_cast<LPCWSTR>(fileName.utf16()),
+ nullptr, writerAttributes.Get(), sinkWriter.GetAddressOf());
+ if (FAILED(hr))
+ return QMediaRecorder::LocationNotWritable;
+
+ m_sinkVideoStreamIndex = MF_SINK_WRITER_INVALID_STREAM_INDEX;
+ m_sinkAudioStreamIndex = MF_SINK_WRITER_INVALID_STREAM_INDEX;
+
+ if (m_videoSource && videoFormat != GUID_NULL) {
+ IMFMediaType *targetMediaType = nullptr;
+
+ hr = createVideoMediaType(videoFormat, videoBitRate, width, height, frameRate, &targetMediaType);
+ if (SUCCEEDED(hr)) {
+
+ hr = sinkWriter->AddStream(targetMediaType, &m_sinkVideoStreamIndex);
+ if (SUCCEEDED(hr)) {
+
+ hr = sinkWriter->SetInputMediaType(m_sinkVideoStreamIndex, m_videoMediaType, nullptr);
+ }
+ targetMediaType->Release();
+ }
+ }
+
+ if (SUCCEEDED(hr)) {
+ if (m_audioSource && audioFormat != GUID_NULL) {
+ IMFMediaType *targetMediaType = nullptr;
+
+ hr = createAudioMediaType(audioFormat, audioBitRate, &targetMediaType);
+ if (SUCCEEDED(hr)) {
+
+ hr = sinkWriter->AddStream(targetMediaType, &m_sinkAudioStreamIndex);
+ if (SUCCEEDED(hr)) {
+
+ hr = sinkWriter->SetInputMediaType(m_sinkAudioStreamIndex, m_audioMediaType, nullptr);
+ }
+ targetMediaType->Release();
+ }
+ }
+ }
+
+ if (FAILED(hr))
+ return QMediaRecorder::FormatError;
+
+ hr = sinkWriter->BeginWriting();
+ if (FAILED(hr))
+ return QMediaRecorder::ResourceError;
+
+ m_sinkWriter = sinkWriter.Detach();
+ m_lastDuration = -1;
+ m_currentDuration = 0;
+ updateDuration();
+ m_durationTimer.start();
+ m_recording = true;
+ m_firstFrame = true;
+ m_paused = false;
+ m_pauseChanging = false;
+
+ return QMediaRecorder::NoError;
+}
+
+void QWindowsMediaDeviceReader::stopRecording()
+{
+ QMutexLocker locker(&m_mutex);
+
+ if (m_sinkWriter && m_recording) {
+
+ HRESULT hr = m_sinkWriter->Finalize();
+
+ if (SUCCEEDED(hr)) {
+ m_hasFinalized.wait(&m_mutex);
+ } else {
+ m_sinkWriter->Release();
+ m_sinkWriter = nullptr;
+
+ QMetaObject::invokeMethod(this, "recordingError",
+ Qt::QueuedConnection, Q_ARG(int, hr));
+ }
+ }
+
+ m_recording = false;
+ m_paused = false;
+ m_pauseChanging = false;
+
+ m_durationTimer.stop();
+ m_lastDuration = -1;
+ m_currentDuration = -1;
+}
+
+bool QWindowsMediaDeviceReader::pauseRecording()
+{
+ if (!m_recording || m_paused)
+ return false;
+ m_pauseTime = m_lastTimestamp;
+ m_paused = true;
+ m_pauseChanging = true;
+ return true;
+}
+
+bool QWindowsMediaDeviceReader::resumeRecording()
+{
+ if (!m_recording || !m_paused)
+ return false;
+ m_paused = false;
+ m_pauseChanging = true;
+ return true;
+}
+
+//from IUnknown
+STDMETHODIMP QWindowsMediaDeviceReader::QueryInterface(REFIID riid, LPVOID *ppvObject)
+{
+ if (!ppvObject)
+ return E_POINTER;
+ if (riid == IID_IMFSourceReaderCallback) {
+ *ppvObject = static_cast<IMFSourceReaderCallback*>(this);
+ } else if (riid == IID_IMFSinkWriterCallback) {
+ *ppvObject = static_cast<IMFSinkWriterCallback*>(this);
+ } else if (riid == IID_IUnknown) {
+ *ppvObject = static_cast<IUnknown*>(static_cast<IMFSourceReaderCallback*>(this));
+ } else {
+ *ppvObject = nullptr;
+ return E_NOINTERFACE;
+ }
+ AddRef();
+ return S_OK;
+}
+
+STDMETHODIMP_(ULONG) QWindowsMediaDeviceReader::AddRef(void)
+{
+ return InterlockedIncrement(&m_cRef);
+}
+
+STDMETHODIMP_(ULONG) QWindowsMediaDeviceReader::Release(void)
+{
+ LONG cRef = InterlockedDecrement(&m_cRef);
+ if (cRef == 0) {
+ this->deleteLater();
+ }
+ return cRef;
+}
+
+UINT32 QWindowsMediaDeviceReader::frameWidth() const
+{
+ return m_frameWidth;
+}
+
+UINT32 QWindowsMediaDeviceReader::frameHeight() const
+{
+ return m_frameHeight;
+}
+
+qreal QWindowsMediaDeviceReader::frameRate() const
+{
+ return m_frameRate;
+}
+
+void QWindowsMediaDeviceReader::setInputMuted(bool muted)
+{
+ m_inputMuted = muted;
+}
+
+void QWindowsMediaDeviceReader::setInputVolume(qreal volume)
+{
+ m_inputVolume = qBound(0.0, volume, 1.0);
+}
+
+void QWindowsMediaDeviceReader::setOutputMuted(bool muted)
+{
+ QMutexLocker locker(&m_mutex);
+
+ m_outputMuted = muted;
+
+ if (m_active && m_monitorSink) {
+ IMFSimpleAudioVolume *audioVolume = nullptr;
+ if (SUCCEEDED(MFGetService(m_monitorSink, QMM_MR_POLICY_VOLUME_SERVICE,
+ IID_PPV_ARGS(&audioVolume)))) {
+ audioVolume->SetMute(m_outputMuted);
+ audioVolume->Release();
+ }
+ }
+}
+
+void QWindowsMediaDeviceReader::setOutputVolume(qreal volume)
+{
+ QMutexLocker locker(&m_mutex);
+
+ m_outputVolume = qBound(0.0, volume, 1.0);
+
+ if (m_active && m_monitorSink) {
+ IMFSimpleAudioVolume *audioVolume = nullptr;
+ if (SUCCEEDED(MFGetService(m_monitorSink, QMM_MR_POLICY_VOLUME_SERVICE,
+ IID_PPV_ARGS(&audioVolume)))) {
+ audioVolume->SetMasterVolume(float(m_outputVolume));
+ audioVolume->Release();
+ }
+ }
+}
+
+void QWindowsMediaDeviceReader::updateDuration()
+{
+ if (m_currentDuration >= 0 && m_lastDuration != m_currentDuration) {
+ m_lastDuration = m_currentDuration;
+ emit durationChanged(m_currentDuration);
+ }
+}
+
+//from IMFSourceReaderCallback
+STDMETHODIMP QWindowsMediaDeviceReader::OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex,
+ DWORD dwStreamFlags, LONGLONG llTimestamp,
+ IMFSample *pSample)
+{
+ QMutexLocker locker(&m_mutex);
+
+ if (FAILED(hrStatus)) {
+ emit streamingError(int(hrStatus));
+ return hrStatus;
+ }
+
+ m_lastTimestamp = llTimestamp;
+
+ if ((dwStreamFlags & MF_SOURCE_READERF_ENDOFSTREAM) == MF_SOURCE_READERF_ENDOFSTREAM) {
+ m_streaming = false;
+ emit streamingStopped();
+ } else {
+
+ if (!m_streaming) {
+ m_streaming = true;
+ emit streamingStarted();
+ }
+ if (pSample) {
+
+ if (m_monitorWriter && dwStreamIndex == m_sourceAudioStreamIndex)
+ m_monitorWriter->WriteSample(0, pSample);
+
+ if (m_recording) {
+
+ if (m_firstFrame) {
+ m_timeOffset = llTimestamp;
+ m_firstFrame = false;
+ emit recordingStarted();
+ }
+
+ if (m_pauseChanging) {
+ // Recording time should not pass while paused.
+ if (m_paused)
+ m_pauseTime = llTimestamp;
+ else
+ m_timeOffset += llTimestamp - m_pauseTime;
+ m_pauseChanging = false;
+ }
+
+ // Send the video frame or audio sample to be encoded.
+ if (m_sinkWriter && !m_paused) {
+
+ pSample->SetSampleTime(llTimestamp - m_timeOffset);
+
+ if (dwStreamIndex == m_sourceVideoStreamIndex) {
+
+ m_sinkWriter->WriteSample(m_sinkVideoStreamIndex, pSample);
+
+ } else if (dwStreamIndex == m_sourceAudioStreamIndex) {
+
+ float volume = m_inputMuted ? 0.0f : float(m_inputVolume);
+
+ // Change the volume of the audio sample, if needed.
+ if (volume != 1.0f) {
+ IMFMediaBuffer *mediaBuffer = nullptr;
+ if (SUCCEEDED(pSample->ConvertToContiguousBuffer(&mediaBuffer))) {
+
+ DWORD bufLen = 0;
+ BYTE *buffer = nullptr;
+
+ if (SUCCEEDED(mediaBuffer->Lock(&buffer, nullptr, &bufLen))) {
+
+ float *floatBuffer = reinterpret_cast<float*>(buffer);
+
+ for (DWORD i = 0; i < bufLen/4; ++i)
+ floatBuffer[i] *= volume;
+
+ mediaBuffer->Unlock();
+ }
+ mediaBuffer->Release();
+ }
+ }
+
+ m_sinkWriter->WriteSample(m_sinkAudioStreamIndex, pSample);
+ }
+ m_currentDuration = (llTimestamp - m_timeOffset) / 10000;
+ }
+ }
+
+ // Generate a new QVideoFrame from IMFSample.
+ if (dwStreamIndex == m_sourceVideoStreamIndex) {
+ IMFMediaBuffer *mediaBuffer = nullptr;
+ if (SUCCEEDED(pSample->ConvertToContiguousBuffer(&mediaBuffer))) {
+
+ DWORD bufLen = 0;
+ BYTE *buffer = nullptr;
+
+ if (SUCCEEDED(mediaBuffer->Lock(&buffer, nullptr, &bufLen))) {
+ auto bytes = QByteArray(reinterpret_cast<char*>(buffer), bufLen);
+ QVideoFrameFormat format(QSize(m_frameWidth, m_frameHeight), m_pixelFormat);
+
+ QVideoFrame frame = QVideoFramePrivate::createFrame(
+ std::make_unique<QMemoryVideoBuffer>(std::move(bytes), m_stride),
+ std::move(format));
+
+ // WMF uses 100-nanosecond units, Qt uses microseconds
+ frame.setStartTime(llTimestamp * 0.1);
+
+ LONGLONG duration = -1;
+ if (SUCCEEDED(pSample->GetSampleDuration(&duration)))
+ frame.setEndTime((llTimestamp + duration) * 0.1);
+
+ emit videoFrameChanged(frame);
+
+ mediaBuffer->Unlock();
+ }
+ mediaBuffer->Release();
+ }
+ }
+ }
+ // request the next video frame or sound sample
+ if (m_sourceReader)
+ m_sourceReader->ReadSample(MF_SOURCE_READER_ANY_STREAM,
+ 0, nullptr, nullptr, nullptr, nullptr);
+ }
+
+ return S_OK;
+}
+
+STDMETHODIMP QWindowsMediaDeviceReader::OnFlush(DWORD)
+{
+ return S_OK;
+}
+
+STDMETHODIMP QWindowsMediaDeviceReader::OnEvent(DWORD, IMFMediaEvent*)
+{
+ return S_OK;
+}
+
+//from IMFSinkWriterCallback
+STDMETHODIMP QWindowsMediaDeviceReader::OnFinalize(HRESULT)
+{
+ QMutexLocker locker(&m_mutex);
+ if (m_sinkWriter) {
+ m_sinkWriter->Release();
+ m_sinkWriter = nullptr;
+ }
+ emit recordingStopped();
+ m_hasFinalized.notify_one();
+ return S_OK;
+}
+
+STDMETHODIMP QWindowsMediaDeviceReader::OnMarker(DWORD, LPVOID)
+{
+ return S_OK;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwindowsmediadevicereader_p.cpp"
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicereader_p.h b/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicereader_p.h
new file mode 100644
index 000000000..4699a463a
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicereader_p.h
@@ -0,0 +1,154 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSMEDIADEVICEREADER_H
+#define QWINDOWSMEDIADEVICEREADER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <mfapi.h>
+#include <mfidl.h>
+#include <mferror.h>
+#include <mfreadwrite.h>
+
+#include <QtCore/qobject.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qwaitcondition.h>
+#include <QtCore/qtimer.h>
+#include <qvideoframe.h>
+#include <qcameradevice.h>
+#include <qmediarecorder.h>
+
+QT_BEGIN_NAMESPACE
+
+class QVideoSink;
+
+class QWindowsMediaDeviceReader : public QObject,
+ public IMFSourceReaderCallback,
+ public IMFSinkWriterCallback
+{
+ Q_OBJECT
+public:
+ explicit QWindowsMediaDeviceReader(QObject *parent = nullptr);
+ ~QWindowsMediaDeviceReader();
+
+ //from IUnknown
+ STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override;
+ STDMETHODIMP_(ULONG) AddRef(void) override;
+ STDMETHODIMP_(ULONG) Release(void) override;
+
+ //from IMFSourceReaderCallback
+ STDMETHODIMP OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex,
+ DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample *pSample) override;
+ STDMETHODIMP OnFlush(DWORD dwStreamIndex) override;
+ STDMETHODIMP OnEvent(DWORD dwStreamIndex, IMFMediaEvent *pEvent) override;
+
+ //from IMFSinkWriterCallback
+ STDMETHODIMP OnFinalize(HRESULT hrStatus) override;
+ STDMETHODIMP OnMarker(DWORD dwStreamIndex, LPVOID pvContext) override;
+
+ bool activate(const QString &cameraId,
+ const QCameraFormat &cameraFormat,
+ const QString &microphoneId);
+ void deactivate();
+
+ QMediaRecorder::Error startRecording(const QString &fileName, const GUID &container,
+ const GUID &videoFormat, UINT32 videoBitRate, UINT32 width,
+ UINT32 height, qreal frameRate, const GUID &audioFormat,
+ UINT32 audioBitRate);
+ void stopRecording();
+ bool pauseRecording();
+ bool resumeRecording();
+
+ UINT32 frameWidth() const;
+ UINT32 frameHeight() const;
+ qreal frameRate() const;
+ void setInputMuted(bool muted);
+ void setInputVolume(qreal volume);
+ void setOutputMuted(bool muted);
+ void setOutputVolume(qreal volume);
+ bool setAudioOutput(const QString &audioOutputId);
+
+Q_SIGNALS:
+ void streamingStarted();
+ void streamingStopped();
+ void streamingError(int errorCode);
+ void recordingStarted();
+ void recordingStopped();
+ void recordingError(int errorCode);
+ void durationChanged(qint64 duration);
+ void videoFrameChanged(const QVideoFrame &frame);
+
+private slots:
+ void updateDuration();
+
+private:
+ HRESULT createSource(const QString &deviceId, bool video, IMFMediaSource **source);
+ HRESULT createAggregateReader(IMFMediaSource *firstSource, IMFMediaSource *secondSource,
+ IMFMediaSource **aggregateSource, IMFSourceReader **sourceReader);
+ HRESULT createVideoMediaType(const GUID &format, UINT32 bitRate, UINT32 width, UINT32 height,
+ qreal frameRate, IMFMediaType **mediaType);
+ HRESULT createAudioMediaType(const GUID &format, UINT32 bitRate, IMFMediaType **mediaType);
+ HRESULT initAudioType(IMFMediaType *mediaType, UINT32 channels, UINT32 samplesPerSec, bool flt);
+ HRESULT prepareVideoStream(DWORD mediaTypeIndex);
+ HRESULT prepareAudioStream();
+ HRESULT initSourceIndexes();
+ HRESULT updateSinkInputMediaTypes();
+ HRESULT startMonitoring();
+ void stopMonitoring();
+ void releaseResources();
+ void stopStreaming();
+ DWORD findMediaTypeIndex(const QCameraFormat &reqFormat);
+
+ long m_cRef = 1;
+ QMutex m_mutex;
+ QWaitCondition m_hasFinalized;
+ IMFMediaSource *m_videoSource = nullptr;
+ IMFMediaType *m_videoMediaType = nullptr;
+ IMFMediaSource *m_audioSource = nullptr;
+ IMFMediaType *m_audioMediaType = nullptr;
+ IMFMediaSource *m_aggregateSource = nullptr;
+ IMFSourceReader *m_sourceReader = nullptr;
+ IMFSinkWriter *m_sinkWriter = nullptr;
+ IMFMediaSink *m_monitorSink = nullptr;
+ IMFSinkWriter *m_monitorWriter = nullptr;
+ QString m_audioOutputId;
+ DWORD m_sourceVideoStreamIndex = MF_SOURCE_READER_INVALID_STREAM_INDEX;
+ DWORD m_sourceAudioStreamIndex = MF_SOURCE_READER_INVALID_STREAM_INDEX;
+ DWORD m_sinkVideoStreamIndex = MF_SINK_WRITER_INVALID_STREAM_INDEX;
+ DWORD m_sinkAudioStreamIndex = MF_SINK_WRITER_INVALID_STREAM_INDEX;
+ UINT32 m_frameWidth = 0;
+ UINT32 m_frameHeight = 0;
+ qreal m_frameRate = 0.0;
+ LONG m_stride = 0;
+ bool m_active = false;
+ bool m_streaming = false;
+ bool m_recording = false;
+ bool m_firstFrame = false;
+ bool m_paused = false;
+ bool m_pauseChanging = false;
+ bool m_inputMuted = false;
+ bool m_outputMuted = false;
+ qreal m_inputVolume = 1.0;
+ qreal m_outputVolume = 1.0;
+ QVideoFrameFormat::PixelFormat m_pixelFormat = QVideoFrameFormat::Format_Invalid;
+ LONGLONG m_timeOffset = 0;
+ LONGLONG m_pauseTime = 0;
+ LONGLONG m_lastTimestamp = 0;
+ QTimer m_durationTimer;
+ qint64 m_currentDuration = -1;
+ qint64 m_lastDuration = -1;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWINDOWSMEDIADEVICEREADER_H
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicesession.cpp b/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicesession.cpp
new file mode 100644
index 000000000..b13599444
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicesession.cpp
@@ -0,0 +1,376 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsmediadevicesession_p.h"
+
+#include "qwindowsmediadevicereader_p.h"
+#include "private/qwindowsmultimediautils_p.h"
+#include "private/qplatformvideosink_p.h"
+#include <qvideosink.h>
+#include <QtCore/qdebug.h>
+#include <qaudioinput.h>
+#include <qaudiooutput.h>
+
+QT_BEGIN_NAMESPACE
+
+QWindowsMediaDeviceSession::QWindowsMediaDeviceSession(QObject *parent)
+ : QObject(parent)
+{
+ m_mediaDeviceReader = new QWindowsMediaDeviceReader(this);
+ connect(m_mediaDeviceReader, &QWindowsMediaDeviceReader::streamingStarted,
+ this, &QWindowsMediaDeviceSession::handleStreamingStarted);
+ connect(m_mediaDeviceReader, &QWindowsMediaDeviceReader::streamingStopped,
+ this, &QWindowsMediaDeviceSession::handleStreamingStopped);
+ connect(m_mediaDeviceReader, &QWindowsMediaDeviceReader::streamingError,
+ this, &QWindowsMediaDeviceSession::handleStreamingError);
+ connect(m_mediaDeviceReader, &QWindowsMediaDeviceReader::videoFrameChanged,
+ this, &QWindowsMediaDeviceSession::handleVideoFrameChanged);
+ connect(m_mediaDeviceReader, &QWindowsMediaDeviceReader::recordingStarted,
+ this, &QWindowsMediaDeviceSession::recordingStarted);
+ connect(m_mediaDeviceReader, &QWindowsMediaDeviceReader::recordingStopped,
+ this, &QWindowsMediaDeviceSession::recordingStopped);
+ connect(m_mediaDeviceReader, &QWindowsMediaDeviceReader::recordingError,
+ this, &QWindowsMediaDeviceSession::recordingError);
+ connect(m_mediaDeviceReader, &QWindowsMediaDeviceReader::durationChanged,
+ this, &QWindowsMediaDeviceSession::durationChanged);
+}
+
+QWindowsMediaDeviceSession::~QWindowsMediaDeviceSession()
+{
+ delete m_mediaDeviceReader;
+}
+
+bool QWindowsMediaDeviceSession::isActive() const
+{
+ return m_active;
+}
+
+bool QWindowsMediaDeviceSession::isActivating() const
+{
+ return m_activating;
+}
+
+void QWindowsMediaDeviceSession::setActive(bool active)
+{
+ if ((active && (m_active || m_activating)) || (!active && !m_active && !m_activating))
+ return;
+
+ if (active) {
+ auto camId = QString::fromUtf8(m_activeCameraDevice.id());
+ auto micId = m_audioInput ? QString::fromUtf8(m_audioInput->device().id()) : QString();
+ if (!camId.isEmpty() || !micId.isEmpty()) {
+ if (m_mediaDeviceReader->activate(camId, m_cameraFormat, micId)) {
+ m_activating = true;
+ } else {
+ emit streamingError(MF_E_NOT_AVAILABLE);
+ }
+ } else {
+ qWarning() << Q_FUNC_INFO << "Camera ID and Microphone ID both undefined.";
+ }
+ } else {
+ m_mediaDeviceReader->deactivate();
+ m_active = false;
+ m_activating = false;
+ emit activeChanged(m_active);
+ emit readyForCaptureChanged(m_active);
+ }
+}
+
+void QWindowsMediaDeviceSession::reactivate()
+{
+ if (m_active || m_activating) {
+ pauseRecording();
+ setActive(false);
+ setActive(true);
+ resumeRecording();
+ }
+}
+
+void QWindowsMediaDeviceSession::setActiveCamera(const QCameraDevice &camera)
+{
+ m_activeCameraDevice = camera;
+ reactivate();
+}
+
+QCameraDevice QWindowsMediaDeviceSession::activeCamera() const
+{
+ return m_activeCameraDevice;
+}
+
+void QWindowsMediaDeviceSession::setCameraFormat(const QCameraFormat &cameraFormat)
+{
+ m_cameraFormat = cameraFormat;
+}
+
+void QWindowsMediaDeviceSession::setVideoSink(QVideoSink *surface)
+{
+ m_surface = surface;
+}
+
+void QWindowsMediaDeviceSession::handleStreamingStarted()
+{
+ if (m_activating) {
+ m_active = true;
+ m_activating = false;
+ emit activeChanged(m_active);
+ emit readyForCaptureChanged(m_active);
+ }
+}
+
+void QWindowsMediaDeviceSession::handleStreamingStopped()
+{
+ m_active = false;
+ emit activeChanged(m_active);
+ emit readyForCaptureChanged(m_active);
+}
+
+void QWindowsMediaDeviceSession::handleStreamingError(int errorCode)
+{
+ if (m_surface)
+ m_surface->platformVideoSink()->setVideoFrame(QVideoFrame());
+ emit streamingError(errorCode);
+}
+
+void QWindowsMediaDeviceSession::handleVideoFrameChanged(const QVideoFrame &frame)
+{
+ if (m_surface)
+ m_surface->platformVideoSink()->setVideoFrame(frame);
+ emit videoFrameChanged(frame);
+}
+
+void QWindowsMediaDeviceSession::setAudioInputMuted(bool muted)
+{
+ m_mediaDeviceReader->setInputMuted(muted);
+}
+
+void QWindowsMediaDeviceSession::setAudioInputVolume(float volume)
+{
+ m_mediaDeviceReader->setInputVolume(volume);
+}
+
+void QWindowsMediaDeviceSession::audioInputDeviceChanged()
+{
+ reactivate();
+}
+
+void QWindowsMediaDeviceSession::setAudioOutputMuted(bool muted)
+{
+ m_mediaDeviceReader->setOutputMuted(muted);
+}
+
+void QWindowsMediaDeviceSession::setAudioOutputVolume(float volume)
+{
+ m_mediaDeviceReader->setOutputVolume(volume);
+}
+
+void QWindowsMediaDeviceSession::audioOutputDeviceChanged()
+{
+ if (m_active || m_activating)
+ m_mediaDeviceReader->setAudioOutput(QString::fromUtf8(m_audioOutput->device().id()));
+}
+
+void QWindowsMediaDeviceSession::setAudioInput(QAudioInput *input)
+{
+ if (m_audioInput == input)
+ return;
+ if (m_audioInput)
+ m_audioInput->disconnect(this);
+ m_audioInput = input;
+
+ audioInputDeviceChanged();
+
+ if (!m_audioInput)
+ return;
+ connect(m_audioInput, &QAudioInput::mutedChanged, this, &QWindowsMediaDeviceSession::setAudioInputMuted);
+ connect(m_audioInput, &QAudioInput::volumeChanged, this, &QWindowsMediaDeviceSession::setAudioInputVolume);
+ connect(m_audioInput, &QAudioInput::deviceChanged, this, &QWindowsMediaDeviceSession::audioInputDeviceChanged);
+}
+
+void QWindowsMediaDeviceSession::setAudioOutput(QAudioOutput *output)
+{
+ if (m_audioOutput == output)
+ return;
+ if (m_audioOutput)
+ m_audioOutput->disconnect(this);
+ m_audioOutput = output;
+ if (!m_audioOutput) {
+ m_mediaDeviceReader->setAudioOutput({});
+ return;
+ }
+
+ m_mediaDeviceReader->setAudioOutput(QString::fromUtf8(m_audioOutput->device().id()));
+
+ connect(m_audioOutput, &QAudioOutput::mutedChanged, this, &QWindowsMediaDeviceSession::setAudioOutputMuted);
+ connect(m_audioOutput, &QAudioOutput::volumeChanged, this, &QWindowsMediaDeviceSession::setAudioOutputVolume);
+ connect(m_audioOutput, &QAudioOutput::deviceChanged, this, &QWindowsMediaDeviceSession::audioOutputDeviceChanged);
+}
+
+QMediaRecorder::Error QWindowsMediaDeviceSession::startRecording(QMediaEncoderSettings &settings, const QString &fileName, bool audioOnly)
+{
+ GUID container = audioOnly ? QWindowsMultimediaUtils::containerForAudioFileFormat(settings.mediaFormat().fileFormat())
+ : QWindowsMultimediaUtils::containerForVideoFileFormat(settings.mediaFormat().fileFormat());
+ GUID videoFormat = QWindowsMultimediaUtils::videoFormatForCodec(settings.videoCodec());
+ GUID audioFormat = QWindowsMultimediaUtils::audioFormatForCodec(settings.audioCodec());
+
+ QSize res = settings.videoResolution();
+ UINT32 width, height;
+ if (res.width() > 0 && res.height() > 0) {
+ width = UINT32(res.width());
+ height = UINT32(res.height());
+ } else {
+ width = m_mediaDeviceReader->frameWidth();
+ height = m_mediaDeviceReader->frameHeight();
+ settings.setVideoResolution(QSize(int(width), int(height)));
+ }
+
+ qreal frameRate = settings.videoFrameRate();
+ if (frameRate <= 0) {
+ frameRate = m_mediaDeviceReader->frameRate();
+ settings.setVideoFrameRate(frameRate);
+ }
+
+ auto quality = settings.quality();
+
+ UINT32 videoBitRate = 0;
+ if (settings.videoBitRate() > 0) {
+ videoBitRate = UINT32(settings.videoBitRate());
+ } else {
+ videoBitRate = estimateVideoBitRate(videoFormat, width, height, frameRate, quality);
+ settings.setVideoBitRate(int(videoBitRate));
+ }
+
+ UINT32 audioBitRate = 0;
+ if (settings.audioBitRate() > 0) {
+ audioBitRate = UINT32(settings.audioBitRate());
+ } else {
+ audioBitRate = estimateAudioBitRate(audioFormat, quality);
+ settings.setAudioBitRate(int(audioBitRate));
+ }
+
+ return m_mediaDeviceReader->startRecording(fileName, container, audioOnly ? GUID_NULL : videoFormat,
+ videoBitRate, width, height, frameRate,
+ audioFormat, audioBitRate);
+}
+
+void QWindowsMediaDeviceSession::stopRecording()
+{
+ m_mediaDeviceReader->stopRecording();
+}
+
+bool QWindowsMediaDeviceSession::pauseRecording()
+{
+ return m_mediaDeviceReader->pauseRecording();
+}
+
+bool QWindowsMediaDeviceSession::resumeRecording()
+{
+ return m_mediaDeviceReader->resumeRecording();
+}
+
+// empirical estimate of the required video bitrate (for H.264)
+quint32 QWindowsMediaDeviceSession::estimateVideoBitRate(const GUID &videoFormat, quint32 width, quint32 height,
+ qreal frameRate, QMediaRecorder::Quality quality)
+{
+ Q_UNUSED(videoFormat);
+
+ qreal bitsPerPixel;
+ switch (quality) {
+ case QMediaRecorder::Quality::VeryLowQuality:
+ bitsPerPixel = 0.08;
+ break;
+ case QMediaRecorder::Quality::LowQuality:
+ bitsPerPixel = 0.2;
+ break;
+ case QMediaRecorder::Quality::NormalQuality:
+ bitsPerPixel = 0.3;
+ break;
+ case QMediaRecorder::Quality::HighQuality:
+ bitsPerPixel = 0.5;
+ break;
+ case QMediaRecorder::Quality::VeryHighQuality:
+ bitsPerPixel = 0.8;
+ break;
+ default:
+ bitsPerPixel = 0.3;
+ }
+
+ // Required bitrate is not linear on the number of pixels; small resolutions
+ // require more BPP, thus the minimum values, to try to compensate it.
+ quint32 pixelsPerSec = quint32(qMax(width, 320u) * qMax(height, 240u) * qMax(frameRate, 6.0));
+ return pixelsPerSec * bitsPerPixel;
+}
+
+quint32 QWindowsMediaDeviceSession::estimateAudioBitRate(const GUID &audioFormat, QMediaRecorder::Quality quality)
+{
+ if (audioFormat == MFAudioFormat_AAC) {
+ // Bitrates supported by the AAC encoder are 96K, 128K, 160K, 192K.
+ switch (quality) {
+ case QMediaRecorder::Quality::VeryLowQuality:
+ return 96000;
+ case QMediaRecorder::Quality::LowQuality:
+ return 96000;
+ case QMediaRecorder::Quality::NormalQuality:
+ return 128000;
+ case QMediaRecorder::Quality::HighQuality:
+ return 160000;
+ case QMediaRecorder::Quality::VeryHighQuality:
+ return 192000;
+ default:
+ return 128000;
+ }
+ } else if (audioFormat == MFAudioFormat_MP3) {
+ // Bitrates supported by the MP3 encoder are
+ // 32K, 40K, 48K, 56K, 64K, 80K, 96K, 112K, 128K, 160K, 192K, 224K, 256K, 320K.
+ switch (quality) {
+ case QMediaRecorder::Quality::VeryLowQuality:
+ return 48000;
+ case QMediaRecorder::Quality::LowQuality:
+ return 96000;
+ case QMediaRecorder::Quality::NormalQuality:
+ return 128000;
+ case QMediaRecorder::Quality::HighQuality:
+ return 224000;
+ case QMediaRecorder::Quality::VeryHighQuality:
+ return 320000;
+ default:
+ return 128000;
+ }
+ } else if (audioFormat == MFAudioFormat_WMAudioV8) {
+ // Bitrates supported by the Windows Media Audio 8 encoder
+ switch (quality) {
+ case QMediaRecorder::Quality::VeryLowQuality:
+ return 32000;
+ case QMediaRecorder::Quality::LowQuality:
+ return 96000;
+ case QMediaRecorder::Quality::NormalQuality:
+ return 192000;
+ case QMediaRecorder::Quality::HighQuality:
+ return 256016;
+ case QMediaRecorder::Quality::VeryHighQuality:
+ return 320032;
+ default:
+ return 192000;
+ }
+ } else if (audioFormat == MFAudioFormat_WMAudioV9) {
+ // Bitrates supported by the Windows Media Audio 9 encoder
+ switch (quality) {
+ case QMediaRecorder::Quality::VeryLowQuality:
+ return 32000;
+ case QMediaRecorder::Quality::LowQuality:
+ return 96000;
+ case QMediaRecorder::Quality::NormalQuality:
+ return 192000;
+ case QMediaRecorder::Quality::HighQuality:
+ return 256016;
+ case QMediaRecorder::Quality::VeryHighQuality:
+ return 384000;
+ default:
+ return 192000;
+ }
+ }
+ return 0; // Use default for format
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwindowsmediadevicesession_p.cpp"
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicesession_p.h b/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicesession_p.h
new file mode 100644
index 000000000..c3998ce6c
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowsmediadevicesession_p.h
@@ -0,0 +1,100 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSMEDIADEVICESESSION_H
+#define QWINDOWSMEDIADEVICESESSION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtmultimediaglobal_p.h>
+#include <qcamera.h>
+#include <qaudiodevice.h>
+#include <private/qwindowsmultimediautils_p.h>
+#include <private/qplatformmediarecorder_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioInput;
+class QAudioOutput;
+class QVideoSink;
+class QWindowsMediaDeviceReader;
+
+class QWindowsMediaDeviceSession : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QWindowsMediaDeviceSession(QObject *parent = nullptr);
+ ~QWindowsMediaDeviceSession();
+
+ bool isActive() const;
+ void setActive(bool active);
+
+ bool isActivating() const;
+
+ void setActiveCamera(const QCameraDevice &camera);
+ QCameraDevice activeCamera() const;
+
+ void setCameraFormat(const QCameraFormat &cameraFormat);
+
+ void setVideoSink(QVideoSink *surface);
+
+public Q_SLOTS:
+ void setAudioInputMuted(bool muted);
+ void setAudioInputVolume(float volume);
+ void audioInputDeviceChanged();
+ void setAudioOutputMuted(bool muted);
+ void setAudioOutputVolume(float volume);
+ void audioOutputDeviceChanged();
+
+public:
+ void setAudioInput(QAudioInput *input);
+ void setAudioOutput(QAudioOutput *output);
+
+ QMediaRecorder::Error startRecording(QMediaEncoderSettings &settings, const QString &fileName, bool audioOnly);
+ void stopRecording();
+ bool pauseRecording();
+ bool resumeRecording();
+
+Q_SIGNALS:
+ void activeChanged(bool);
+ void readyForCaptureChanged(bool);
+ void durationChanged(qint64 duration);
+ void recordingStarted();
+ void recordingStopped();
+ void streamingError(int errorCode);
+ void recordingError(int errorCode);
+ void videoFrameChanged(const QVideoFrame &frame);
+
+private Q_SLOTS:
+ void handleStreamingStarted();
+ void handleStreamingStopped();
+ void handleStreamingError(int errorCode);
+ void handleVideoFrameChanged(const QVideoFrame &frame);
+
+private:
+ void reactivate();
+ quint32 estimateVideoBitRate(const GUID &videoFormat, quint32 width, quint32 height,
+ qreal frameRate, QMediaRecorder::Quality quality);
+ quint32 estimateAudioBitRate(const GUID &audioFormat, QMediaRecorder::Quality quality);
+ bool m_active = false;
+ bool m_activating = false;
+ QCameraDevice m_activeCameraDevice;
+ QCameraFormat m_cameraFormat;
+ QWindowsMediaDeviceReader *m_mediaDeviceReader = nullptr;
+ QAudioInput *m_audioInput = nullptr;
+ QAudioOutput *m_audioOutput = nullptr;
+ QVideoSink *m_surface = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWINDOWSMEDIADEVICESESSION_H
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowsmediaencoder.cpp b/src/plugins/multimedia/windows/mediacapture/qwindowsmediaencoder.cpp
new file mode 100644
index 000000000..512110af6
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowsmediaencoder.cpp
@@ -0,0 +1,225 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsmediaencoder_p.h"
+
+#include "qwindowsmediadevicesession_p.h"
+#include "qwindowsmediacapture_p.h"
+#include "mfmetadata_p.h"
+#include <QtCore/QUrl>
+#include <QtCore/QMimeType>
+#include <mferror.h>
+#include <shobjidl.h>
+#include <private/qmediastoragelocation_p.h>
+#include <private/qmediarecorder_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QWindowsMediaEncoder::QWindowsMediaEncoder(QMediaRecorder *parent)
+ : QObject(parent),
+ QPlatformMediaRecorder(parent)
+{
+}
+
+bool QWindowsMediaEncoder::isLocationWritable(const QUrl &location) const
+{
+ return location.scheme() == QLatin1String("file") || location.scheme().isEmpty();
+}
+
+QMediaRecorder::RecorderState QWindowsMediaEncoder::state() const
+{
+ return m_state;
+}
+
+qint64 QWindowsMediaEncoder::duration() const
+{
+ return m_duration;
+}
+
+void QWindowsMediaEncoder::record(QMediaEncoderSettings &settings)
+{
+ if (!m_captureService || !m_mediaDeviceSession) {
+ qWarning() << Q_FUNC_INFO << "Encoder is not set to a capture session";
+ return;
+ }
+ if (m_state != QMediaRecorder::StoppedState)
+ return;
+
+ m_sessionWasActive = m_mediaDeviceSession->isActive() || m_mediaDeviceSession->isActivating();
+
+ if (!m_sessionWasActive) {
+
+ m_mediaDeviceSession->setActive(true);
+
+ if (!m_mediaDeviceSession->isActivating()) {
+ updateError(QMediaRecorder::ResourceError,
+ QMediaRecorderPrivate::msgFailedStartRecording());
+ return;
+ }
+ }
+
+ const auto audioOnly = settings.videoCodec() == QMediaFormat::VideoCodec::Unspecified;
+ m_fileName = QMediaStorageLocation::generateFileName(outputLocation().toLocalFile(), audioOnly
+ ? QStandardPaths::MusicLocation
+ : QStandardPaths::MoviesLocation,
+ settings.mimeType().preferredSuffix());
+
+ QMediaRecorder::Error ec = m_mediaDeviceSession->startRecording(settings, m_fileName, audioOnly);
+ if (ec == QMediaRecorder::NoError) {
+ m_state = QMediaRecorder::RecordingState;
+
+ actualLocationChanged(QUrl::fromLocalFile(m_fileName));
+ stateChanged(m_state);
+
+ } else {
+ updateError(ec, QMediaRecorderPrivate::msgFailedStartRecording());
+ }
+}
+
+void QWindowsMediaEncoder::pause()
+{
+ if (!m_mediaDeviceSession || m_state != QMediaRecorder::RecordingState)
+ return;
+
+ if (m_mediaDeviceSession->pauseRecording()) {
+ m_state = QMediaRecorder::PausedState;
+ stateChanged(m_state);
+ } else {
+ updateError(QMediaRecorder::FormatError, tr("Failed to pause recording"));
+ }
+}
+
+void QWindowsMediaEncoder::resume()
+{
+ if (!m_mediaDeviceSession || m_state != QMediaRecorder::PausedState)
+ return;
+
+ if (m_mediaDeviceSession->resumeRecording()) {
+ m_state = QMediaRecorder::RecordingState;
+ stateChanged(m_state);
+ } else {
+ updateError(QMediaRecorder::FormatError, tr("Failed to resume recording"));
+ }
+}
+
+void QWindowsMediaEncoder::stop()
+{
+ if (m_mediaDeviceSession && m_state != QMediaRecorder::StoppedState) {
+ m_mediaDeviceSession->stopRecording();
+ if (!m_sessionWasActive)
+ m_mediaDeviceSession->setActive(false);
+ }
+}
+
+
+
+void QWindowsMediaEncoder::setCaptureSession(QPlatformMediaCaptureSession *session)
+{
+ QWindowsMediaCaptureService *captureSession = static_cast<QWindowsMediaCaptureService *>(session);
+ if (m_captureService == captureSession)
+ return;
+
+ if (m_captureService)
+ stop();
+
+ m_captureService = captureSession;
+ if (!m_captureService) {
+ m_mediaDeviceSession = nullptr;
+ return;
+ }
+
+ m_mediaDeviceSession = m_captureService->session();
+ Q_ASSERT(m_mediaDeviceSession);
+
+ connect(m_mediaDeviceSession, &QWindowsMediaDeviceSession::recordingStarted, this, &QWindowsMediaEncoder::onRecordingStarted);
+ connect(m_mediaDeviceSession, &QWindowsMediaDeviceSession::recordingStopped, this, &QWindowsMediaEncoder::onRecordingStopped);
+ connect(m_mediaDeviceSession, &QWindowsMediaDeviceSession::streamingError, this, &QWindowsMediaEncoder::onStreamingError);
+ connect(m_mediaDeviceSession, &QWindowsMediaDeviceSession::recordingError, this, &QWindowsMediaEncoder::onRecordingError);
+ connect(m_mediaDeviceSession, &QWindowsMediaDeviceSession::durationChanged, this, &QWindowsMediaEncoder::onDurationChanged);
+ connect(m_captureService, &QWindowsMediaCaptureService::cameraChanged, this, &QWindowsMediaEncoder::onCameraChanged);
+ onCameraChanged();
+}
+
+void QWindowsMediaEncoder::setMetaData(const QMediaMetaData &metaData)
+{
+ m_metaData = metaData;
+}
+
+QMediaMetaData QWindowsMediaEncoder::metaData() const
+{
+ return m_metaData;
+}
+
+void QWindowsMediaEncoder::saveMetadata()
+{
+ if (!m_metaData.isEmpty()) {
+
+ const QString nativeFileName = QDir::toNativeSeparators(m_fileName);
+
+ IPropertyStore *store = nullptr;
+
+ if (SUCCEEDED(SHGetPropertyStoreFromParsingName(reinterpret_cast<LPCWSTR>(nativeFileName.utf16()),
+ nullptr, GPS_READWRITE, IID_PPV_ARGS(&store)))) {
+
+ MFMetaData::toNative(m_metaData, store);
+
+ store->Commit();
+ store->Release();
+ }
+ }
+}
+
+void QWindowsMediaEncoder::onDurationChanged(qint64 duration)
+{
+ m_duration = duration;
+ durationChanged(m_duration);
+}
+
+void QWindowsMediaEncoder::onStreamingError(int errorCode)
+{
+ if (errorCode == MF_E_VIDEO_RECORDING_DEVICE_INVALIDATED)
+ updateError(QMediaRecorder::ResourceError, tr("Camera is no longer present"));
+ else if (errorCode == MF_E_AUDIO_RECORDING_DEVICE_INVALIDATED)
+ updateError(QMediaRecorder::ResourceError, tr("Audio input is no longer present"));
+ else
+ updateError(QMediaRecorder::ResourceError, tr("Streaming error"));
+
+ if (m_state != QMediaRecorder::StoppedState) {
+ m_mediaDeviceSession->stopRecording();
+ if (!m_sessionWasActive)
+ m_mediaDeviceSession->setActive(false);
+ }
+}
+
+void QWindowsMediaEncoder::onRecordingError(int errorCode)
+{
+ Q_UNUSED(errorCode);
+ updateError(QMediaRecorder::ResourceError, tr("Recording error"));
+
+ auto lastState = m_state;
+ m_state = QMediaRecorder::StoppedState;
+ if (m_state != lastState)
+ stateChanged(m_state);
+}
+
+void QWindowsMediaEncoder::onCameraChanged()
+{
+}
+
+void QWindowsMediaEncoder::onRecordingStarted()
+{
+}
+
+void QWindowsMediaEncoder::onRecordingStopped()
+{
+ saveMetadata();
+
+ auto lastState = m_state;
+ m_state = QMediaRecorder::StoppedState;
+ if (m_state != lastState)
+ stateChanged(m_state);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qwindowsmediaencoder_p.cpp"
diff --git a/src/plugins/multimedia/windows/mediacapture/qwindowsmediaencoder_p.h b/src/plugins/multimedia/windows/mediacapture/qwindowsmediaencoder_p.h
new file mode 100644
index 000000000..51f35ce9d
--- /dev/null
+++ b/src/plugins/multimedia/windows/mediacapture/qwindowsmediaencoder_p.h
@@ -0,0 +1,71 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QWINDOWSMEDIAENCODER_H
+#define QWINDOWSMEDIAENCODER_H
+
+#include <private/qplatformmediarecorder_p.h>
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qurl.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsMediaDeviceSession;
+class QPlatformMediaCaptureSession;
+class QWindowsMediaCaptureService;
+
+class QWindowsMediaEncoder : public QObject, public QPlatformMediaRecorder
+{
+ Q_OBJECT
+public:
+ explicit QWindowsMediaEncoder(QMediaRecorder *parent);
+
+ bool isLocationWritable(const QUrl &location) const override;
+ QMediaRecorder::RecorderState state() const override;
+ qint64 duration() const override;
+
+ void setMetaData(const QMediaMetaData &metaData) override;
+ QMediaMetaData metaData() const override;
+
+ void setCaptureSession(QPlatformMediaCaptureSession *session);
+
+ void record(QMediaEncoderSettings &settings) override;
+ void pause() override;
+ void resume() override;
+ void stop() override;
+
+private Q_SLOTS:
+ void onCameraChanged();
+ void onRecordingStarted();
+ void onRecordingStopped();
+ void onDurationChanged(qint64 duration);
+ void onStreamingError(int errorCode);
+ void onRecordingError(int errorCode);
+
+private:
+ void saveMetadata();
+
+ QWindowsMediaCaptureService *m_captureService = nullptr;
+ QWindowsMediaDeviceSession *m_mediaDeviceSession = nullptr;
+ QMediaRecorder::RecorderState m_state = QMediaRecorder::StoppedState;
+ QString m_fileName;
+ QMediaMetaData m_metaData;
+ qint64 m_duration = 0;
+ bool m_sessionWasActive = false;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/windows/mfstream.cpp b/src/plugins/multimedia/windows/mfstream.cpp
new file mode 100644
index 000000000..fb37ce293
--- /dev/null
+++ b/src/plugins/multimedia/windows/mfstream.cpp
@@ -0,0 +1,326 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "mfstream_p.h"
+#include <QtCore/qcoreapplication.h>
+
+QT_BEGIN_NAMESPACE
+//MFStream is added for supporting QIODevice type of media source.
+//It is used to delegate invocations from media foundation(through IMFByteStream) to QIODevice.
+
+MFStream::MFStream(QIODevice *stream, bool ownStream)
+ : m_cRef(1)
+ , m_stream(stream)
+ , m_ownStream(ownStream)
+ , m_currentReadResult(0)
+{
+ //Move to the thread of the stream object
+ //to make sure invocations on stream
+ //are happened in the same thread of stream object
+ this->moveToThread(stream->thread());
+}
+
+MFStream::~MFStream()
+{
+ if (m_currentReadResult)
+ m_currentReadResult->Release();
+ if (m_ownStream)
+ m_stream->deleteLater();
+}
+
+//from IUnknown
+STDMETHODIMP MFStream::QueryInterface(REFIID riid, LPVOID *ppvObject)
+{
+ if (!ppvObject)
+ return E_POINTER;
+ if (riid == IID_IMFByteStream) {
+ *ppvObject = static_cast<IMFByteStream*>(this);
+ } else if (riid == IID_IUnknown) {
+ *ppvObject = static_cast<IUnknown*>(this);
+ } else {
+ *ppvObject = NULL;
+ return E_NOINTERFACE;
+ }
+ AddRef();
+ return S_OK;
+}
+
+STDMETHODIMP_(ULONG) MFStream::AddRef(void)
+{
+ return InterlockedIncrement(&m_cRef);
+}
+
+STDMETHODIMP_(ULONG) MFStream::Release(void)
+{
+ LONG cRef = InterlockedDecrement(&m_cRef);
+ if (cRef == 0) {
+ this->deleteLater();
+ }
+ return cRef;
+}
+
+
+//from IMFByteStream
+STDMETHODIMP MFStream::GetCapabilities(DWORD *pdwCapabilities)
+{
+ if (!pdwCapabilities)
+ return E_INVALIDARG;
+ *pdwCapabilities = MFBYTESTREAM_IS_READABLE;
+ if (!m_stream->isSequential())
+ *pdwCapabilities |= MFBYTESTREAM_IS_SEEKABLE;
+ return S_OK;
+}
+
+STDMETHODIMP MFStream::GetLength(QWORD *pqwLength)
+{
+ if (!pqwLength)
+ return E_INVALIDARG;
+ QMutexLocker locker(&m_mutex);
+ *pqwLength = QWORD(m_stream->size());
+ return S_OK;
+}
+
+STDMETHODIMP MFStream::SetLength(QWORD)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MFStream::GetCurrentPosition(QWORD *pqwPosition)
+{
+ if (!pqwPosition)
+ return E_INVALIDARG;
+ QMutexLocker locker(&m_mutex);
+ *pqwPosition = m_stream->pos();
+ return S_OK;
+}
+
+STDMETHODIMP MFStream::SetCurrentPosition(QWORD qwPosition)
+{
+ QMutexLocker locker(&m_mutex);
+ //SetCurrentPosition may happend during the BeginRead/EndRead pair,
+ //refusing to execute SetCurrentPosition during that time seems to be
+ //the simplest workable solution
+ if (m_currentReadResult)
+ return S_FALSE;
+
+ bool seekOK = m_stream->seek(qint64(qwPosition));
+ if (seekOK)
+ return S_OK;
+ else
+ return S_FALSE;
+}
+
+STDMETHODIMP MFStream::IsEndOfStream(BOOL *pfEndOfStream)
+{
+ if (!pfEndOfStream)
+ return E_INVALIDARG;
+ QMutexLocker locker(&m_mutex);
+ *pfEndOfStream = m_stream->atEnd() ? TRUE : FALSE;
+ return S_OK;
+}
+
+STDMETHODIMP MFStream::Read(BYTE *pb, ULONG cb, ULONG *pcbRead)
+{
+ QMutexLocker locker(&m_mutex);
+ qint64 read = m_stream->read((char*)(pb), qint64(cb));
+ if (pcbRead)
+ *pcbRead = ULONG(read);
+ return S_OK;
+}
+
+STDMETHODIMP MFStream::BeginRead(BYTE *pb, ULONG cb, IMFAsyncCallback *pCallback,
+ IUnknown *punkState)
+{
+ if (!pCallback || !pb)
+ return E_INVALIDARG;
+
+ Q_ASSERT(m_currentReadResult == NULL);
+
+ AsyncReadState *state = new (std::nothrow) AsyncReadState(pb, cb);
+ if (state == NULL)
+ return E_OUTOFMEMORY;
+
+ HRESULT hr = MFCreateAsyncResult(state, pCallback, punkState, &m_currentReadResult);
+ state->Release();
+ if (FAILED(hr))
+ return hr;
+
+ QCoreApplication::postEvent(this, new QEvent(QEvent::User));
+ return hr;
+}
+
+STDMETHODIMP MFStream::EndRead(IMFAsyncResult* pResult, ULONG *pcbRead)
+{
+ if (!pcbRead)
+ return E_INVALIDARG;
+ IUnknown *pUnk;
+ pResult->GetObject(&pUnk);
+ AsyncReadState *state = static_cast<AsyncReadState*>(pUnk);
+ *pcbRead = state->bytesRead();
+ pUnk->Release();
+
+ m_currentReadResult->Release();
+ m_currentReadResult = NULL;
+
+ return S_OK;
+}
+
+STDMETHODIMP MFStream::Write(const BYTE *, ULONG, ULONG *)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MFStream::BeginWrite(const BYTE *, ULONG ,
+ IMFAsyncCallback *,
+ IUnknown *)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MFStream::EndWrite(IMFAsyncResult *,
+ ULONG *)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MFStream::Seek(
+ MFBYTESTREAM_SEEK_ORIGIN SeekOrigin,
+ LONGLONG llSeekOffset,
+ DWORD,
+ QWORD *pqwCurrentPosition)
+{
+ QMutexLocker locker(&m_mutex);
+ if (m_currentReadResult)
+ return S_FALSE;
+
+ qint64 pos = qint64(llSeekOffset);
+ switch (SeekOrigin) {
+ case msoBegin:
+ break;
+ case msoCurrent:
+ pos += m_stream->pos();
+ break;
+ }
+ bool seekOK = m_stream->seek(pos);
+ if (pqwCurrentPosition)
+ *pqwCurrentPosition = pos;
+ if (seekOK)
+ return S_OK;
+ else
+ return S_FALSE;
+}
+
+STDMETHODIMP MFStream::Flush()
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP MFStream::Close()
+{
+ QMutexLocker locker(&m_mutex);
+ if (m_ownStream)
+ m_stream->close();
+ return S_OK;
+}
+
+void MFStream::doRead()
+{
+ if (!m_stream)
+ return;
+
+ bool readDone = true;
+ IUnknown *pUnk = NULL;
+ HRESULT hr = m_currentReadResult->GetObject(&pUnk);
+ if (SUCCEEDED(hr)) {
+ //do actual read
+ AsyncReadState *state = static_cast<AsyncReadState*>(pUnk);
+ ULONG cbRead;
+ Read(state->pb(), state->cb() - state->bytesRead(), &cbRead);
+ pUnk->Release();
+
+ state->setBytesRead(cbRead + state->bytesRead());
+ if (state->cb() > state->bytesRead() && !m_stream->atEnd()) {
+ readDone = false;
+ }
+ }
+
+ if (readDone) {
+ //now inform the original caller
+ m_currentReadResult->SetStatus(hr);
+ MFInvokeCallback(m_currentReadResult);
+ }
+}
+
+void MFStream::customEvent(QEvent *event)
+{
+ if (event->type() != QEvent::User) {
+ QObject::customEvent(event);
+ return;
+ }
+ doRead();
+}
+
+//AsyncReadState is a helper class used in BeginRead for asynchronous operation
+//to record some BeginRead parameters, so these parameters could be
+//used later when actually executing the read operation in another thread.
+MFStream::AsyncReadState::AsyncReadState(BYTE *pb, ULONG cb)
+ : m_cRef(1)
+ , m_pb(pb)
+ , m_cb(cb)
+ , m_cbRead(0)
+{
+}
+
+//from IUnknown
+STDMETHODIMP MFStream::AsyncReadState::QueryInterface(REFIID riid, LPVOID *ppvObject)
+{
+ if (!ppvObject)
+ return E_POINTER;
+
+ if (riid == IID_IUnknown) {
+ *ppvObject = static_cast<IUnknown*>(this);
+ } else {
+ *ppvObject = NULL;
+ return E_NOINTERFACE;
+ }
+ AddRef();
+ return S_OK;
+}
+
+STDMETHODIMP_(ULONG) MFStream::AsyncReadState::AddRef(void)
+{
+ return InterlockedIncrement(&m_cRef);
+}
+
+STDMETHODIMP_(ULONG) MFStream::AsyncReadState::Release(void)
+{
+ LONG cRef = InterlockedDecrement(&m_cRef);
+ if (cRef == 0)
+ delete this;
+ // For thread safety, return a temporary variable.
+ return cRef;
+}
+
+BYTE* MFStream::AsyncReadState::pb() const
+{
+ return m_pb;
+}
+
+ULONG MFStream::AsyncReadState::cb() const
+{
+ return m_cb;
+}
+
+ULONG MFStream::AsyncReadState::bytesRead() const
+{
+ return m_cbRead;
+}
+
+void MFStream::AsyncReadState::setBytesRead(ULONG cbRead)
+{
+ m_cbRead = cbRead;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_mfstream_p.cpp"
diff --git a/src/plugins/multimedia/windows/mfstream_p.h b/src/plugins/multimedia/windows/mfstream_p.h
new file mode 100644
index 000000000..a5221ed75
--- /dev/null
+++ b/src/plugins/multimedia/windows/mfstream_p.h
@@ -0,0 +1,124 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef MFSTREAM_H
+#define MFSTREAM_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <mfapi.h>
+#include <mfidl.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qiodevice.h>
+#include <QtCore/qcoreevent.h>
+#include <QtCore/qpointer.h>
+
+QT_BEGIN_NAMESPACE
+
+class MFStream : public QObject, public IMFByteStream
+{
+ Q_OBJECT
+public:
+ MFStream(QIODevice *stream, bool ownStream);
+
+ ~MFStream();
+
+ //from IUnknown
+ STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override;
+
+ STDMETHODIMP_(ULONG) AddRef(void) override;
+
+ STDMETHODIMP_(ULONG) Release(void) override;
+
+
+ //from IMFByteStream
+ STDMETHODIMP GetCapabilities(DWORD *pdwCapabilities) override;
+
+ STDMETHODIMP GetLength(QWORD *pqwLength) override;
+
+ STDMETHODIMP SetLength(QWORD) override;
+
+ STDMETHODIMP GetCurrentPosition(QWORD *pqwPosition) override;
+
+ STDMETHODIMP SetCurrentPosition(QWORD qwPosition) override;
+
+ STDMETHODIMP IsEndOfStream(BOOL *pfEndOfStream) override;
+
+ STDMETHODIMP Read(BYTE *pb, ULONG cb, ULONG *pcbRead) override;
+
+ STDMETHODIMP BeginRead(BYTE *pb, ULONG cb, IMFAsyncCallback *pCallback,
+ IUnknown *punkState) override;
+
+ STDMETHODIMP EndRead(IMFAsyncResult* pResult, ULONG *pcbRead) override;
+
+ STDMETHODIMP Write(const BYTE *, ULONG, ULONG *) override;
+
+ STDMETHODIMP BeginWrite(const BYTE *, ULONG ,
+ IMFAsyncCallback *,
+ IUnknown *) override;
+
+ STDMETHODIMP EndWrite(IMFAsyncResult *,
+ ULONG *) override;
+
+ STDMETHODIMP Seek(
+ MFBYTESTREAM_SEEK_ORIGIN SeekOrigin,
+ LONGLONG llSeekOffset,
+ DWORD,
+ QWORD *pqwCurrentPosition) override;
+
+ STDMETHODIMP Flush() override;
+
+ STDMETHODIMP Close() override;
+
+private:
+ class AsyncReadState : public IUnknown
+ {
+ public:
+ AsyncReadState(BYTE *pb, ULONG cb);
+ virtual ~AsyncReadState() = default;
+
+ //from IUnknown
+ STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override;
+
+ STDMETHODIMP_(ULONG) AddRef(void) override;
+
+ STDMETHODIMP_(ULONG) Release(void) override;
+
+ BYTE* pb() const;
+ ULONG cb() const;
+ ULONG bytesRead() const;
+
+ void setBytesRead(ULONG cbRead);
+
+ private:
+ long m_cRef;
+ BYTE *m_pb;
+ ULONG m_cb;
+ ULONG m_cbRead;
+ };
+
+ long m_cRef;
+ QPointer<QIODevice> m_stream;
+ bool m_ownStream;
+ DWORD m_workQueueId;
+ QMutex m_mutex;
+
+ void doRead();
+
+protected:
+ void customEvent(QEvent *event) override;
+ IMFAsyncResult *m_currentReadResult;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/windows/player/mfactivate.cpp b/src/plugins/multimedia/windows/player/mfactivate.cpp
new file mode 100644
index 000000000..644c96529
--- /dev/null
+++ b/src/plugins/multimedia/windows/player/mfactivate.cpp
@@ -0,0 +1,17 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "mfactivate_p.h"
+
+#include <mfapi.h>
+
+MFAbstractActivate::MFAbstractActivate()
+{
+ MFCreateAttributes(&m_attributes, 0);
+}
+
+MFAbstractActivate::~MFAbstractActivate()
+{
+ if (m_attributes)
+ m_attributes->Release();
+}
diff --git a/src/plugins/multimedia/windows/player/mfactivate_p.h b/src/plugins/multimedia/windows/player/mfactivate_p.h
new file mode 100644
index 000000000..efe75474b
--- /dev/null
+++ b/src/plugins/multimedia/windows/player/mfactivate_p.h
@@ -0,0 +1,202 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef MFACTIVATE_H
+#define MFACTIVATE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <mfidl.h>
+#include <private/qcomobject_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QtPrivate {
+
+template <>
+struct QComObjectTraits<IMFActivate>
+{
+ static constexpr bool isGuidOf(REFIID riid) noexcept
+ {
+ return QComObjectTraits<IMFActivate, IMFAttributes>::isGuidOf(riid);
+ }
+};
+
+} // namespace QtPrivate
+
+class MFAbstractActivate : public QComObject<IMFActivate>
+{
+public:
+ explicit MFAbstractActivate();
+
+ //from IMFAttributes
+ STDMETHODIMP GetItem(REFGUID guidKey, PROPVARIANT *pValue) override
+ {
+ return m_attributes->GetItem(guidKey, pValue);
+ }
+
+ STDMETHODIMP GetItemType(REFGUID guidKey, MF_ATTRIBUTE_TYPE *pType) override
+ {
+ return m_attributes->GetItemType(guidKey, pType);
+ }
+
+ STDMETHODIMP CompareItem(REFGUID guidKey, REFPROPVARIANT Value, BOOL *pbResult) override
+ {
+ return m_attributes->CompareItem(guidKey, Value, pbResult);
+ }
+
+ STDMETHODIMP Compare(IMFAttributes *pTheirs, MF_ATTRIBUTES_MATCH_TYPE MatchType, BOOL *pbResult) override
+ {
+ return m_attributes->Compare(pTheirs, MatchType, pbResult);
+ }
+
+ STDMETHODIMP GetUINT32(REFGUID guidKey, UINT32 *punValue) override
+ {
+ return m_attributes->GetUINT32(guidKey, punValue);
+ }
+
+ STDMETHODIMP GetUINT64(REFGUID guidKey, UINT64 *punValue) override
+ {
+ return m_attributes->GetUINT64(guidKey, punValue);
+ }
+
+ STDMETHODIMP GetDouble(REFGUID guidKey, double *pfValue) override
+ {
+ return m_attributes->GetDouble(guidKey, pfValue);
+ }
+
+ STDMETHODIMP GetGUID(REFGUID guidKey, GUID *pguidValue) override
+ {
+ return m_attributes->GetGUID(guidKey, pguidValue);
+ }
+
+ STDMETHODIMP GetStringLength(REFGUID guidKey, UINT32 *pcchLength) override
+ {
+ return m_attributes->GetStringLength(guidKey, pcchLength);
+ }
+
+ STDMETHODIMP GetString(REFGUID guidKey, LPWSTR pwszValue, UINT32 cchBufSize, UINT32 *pcchLength) override
+ {
+ return m_attributes->GetString(guidKey, pwszValue, cchBufSize, pcchLength);
+ }
+
+ STDMETHODIMP GetAllocatedString(REFGUID guidKey, LPWSTR *ppwszValue, UINT32 *pcchLength) override
+ {
+ return m_attributes->GetAllocatedString(guidKey, ppwszValue, pcchLength);
+ }
+
+ STDMETHODIMP GetBlobSize(REFGUID guidKey, UINT32 *pcbBlobSize) override
+ {
+ return m_attributes->GetBlobSize(guidKey, pcbBlobSize);
+ }
+
+ STDMETHODIMP GetBlob(REFGUID guidKey, UINT8 *pBuf, UINT32 cbBufSize, UINT32 *pcbBlobSize) override
+ {
+ return m_attributes->GetBlob(guidKey, pBuf, cbBufSize, pcbBlobSize);
+ }
+
+ STDMETHODIMP GetAllocatedBlob(REFGUID guidKey, UINT8 **ppBuf, UINT32 *pcbSize) override
+ {
+ return m_attributes->GetAllocatedBlob(guidKey, ppBuf, pcbSize);
+ }
+
+ STDMETHODIMP GetUnknown(REFGUID guidKey, REFIID riid, LPVOID *ppv) override
+ {
+ return m_attributes->GetUnknown(guidKey, riid, ppv);
+ }
+
+ STDMETHODIMP SetItem(REFGUID guidKey, REFPROPVARIANT Value) override
+ {
+ return m_attributes->SetItem(guidKey, Value);
+ }
+
+ STDMETHODIMP DeleteItem(REFGUID guidKey) override
+ {
+ return m_attributes->DeleteItem(guidKey);
+ }
+
+ STDMETHODIMP DeleteAllItems() override
+ {
+ return m_attributes->DeleteAllItems();
+ }
+
+ STDMETHODIMP SetUINT32(REFGUID guidKey, UINT32 unValue) override
+ {
+ return m_attributes->SetUINT32(guidKey, unValue);
+ }
+
+ STDMETHODIMP SetUINT64(REFGUID guidKey, UINT64 unValue) override
+ {
+ return m_attributes->SetUINT64(guidKey, unValue);
+ }
+
+ STDMETHODIMP SetDouble(REFGUID guidKey, double fValue) override
+ {
+ return m_attributes->SetDouble(guidKey, fValue);
+ }
+
+ STDMETHODIMP SetGUID(REFGUID guidKey, REFGUID guidValue) override
+ {
+ return m_attributes->SetGUID(guidKey, guidValue);
+ }
+
+ STDMETHODIMP SetString(REFGUID guidKey, LPCWSTR wszValue) override
+ {
+ return m_attributes->SetString(guidKey, wszValue);
+ }
+
+ STDMETHODIMP SetBlob(REFGUID guidKey, const UINT8 *pBuf, UINT32 cbBufSize) override
+ {
+ return m_attributes->SetBlob(guidKey, pBuf, cbBufSize);
+ }
+
+ STDMETHODIMP SetUnknown(REFGUID guidKey, IUnknown *pUnknown) override
+ {
+ return m_attributes->SetUnknown(guidKey, pUnknown);
+ }
+
+ STDMETHODIMP LockStore() override
+ {
+ return m_attributes->LockStore();
+ }
+
+ STDMETHODIMP UnlockStore() override
+ {
+ return m_attributes->UnlockStore();
+ }
+
+ STDMETHODIMP GetCount(UINT32 *pcItems) override
+ {
+ return m_attributes->GetCount(pcItems);
+ }
+
+ STDMETHODIMP GetItemByIndex(UINT32 unIndex, GUID *pguidKey, PROPVARIANT *pValue) override
+ {
+ return m_attributes->GetItemByIndex(unIndex, pguidKey, pValue);
+ }
+
+ STDMETHODIMP CopyAllItems(IMFAttributes *pDest) override
+ {
+ return m_attributes->CopyAllItems(pDest);
+ }
+
+protected:
+ // Destructor is not public. Caller should call Release.
+ ~MFAbstractActivate() override;
+
+private:
+ IMFAttributes *m_attributes = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // MFACTIVATE_H
diff --git a/src/plugins/multimedia/windows/player/mfevrvideowindowcontrol.cpp b/src/plugins/multimedia/windows/player/mfevrvideowindowcontrol.cpp
new file mode 100644
index 000000000..109f7964b
--- /dev/null
+++ b/src/plugins/multimedia/windows/player/mfevrvideowindowcontrol.cpp
@@ -0,0 +1,55 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "mfevrvideowindowcontrol_p.h"
+
+#include <qdebug.h>
+
+MFEvrVideoWindowControl::MFEvrVideoWindowControl(QVideoSink *parent)
+ : EvrVideoWindowControl(parent)
+ , m_currentActivate(NULL)
+ , m_evrSink(NULL)
+{
+}
+
+MFEvrVideoWindowControl::~MFEvrVideoWindowControl()
+{
+ clear();
+}
+
+void MFEvrVideoWindowControl::clear()
+{
+ setEvr(NULL);
+
+ if (m_evrSink)
+ m_evrSink->Release();
+ if (m_currentActivate) {
+ m_currentActivate->ShutdownObject();
+ m_currentActivate->Release();
+ }
+ m_evrSink = NULL;
+ m_currentActivate = NULL;
+}
+
+IMFActivate* MFEvrVideoWindowControl::createActivate()
+{
+ clear();
+
+ if (FAILED(MFCreateVideoRendererActivate(0, &m_currentActivate))) {
+ qWarning() << "Failed to create evr video renderer activate!";
+ return NULL;
+ }
+ if (FAILED(m_currentActivate->ActivateObject(IID_IMFMediaSink, (LPVOID*)(&m_evrSink)))) {
+ qWarning() << "Failed to activate evr media sink!";
+ return NULL;
+ }
+ if (!setEvr(m_evrSink))
+ return NULL;
+
+ return m_currentActivate;
+}
+
+void MFEvrVideoWindowControl::releaseActivate()
+{
+ clear();
+}
diff --git a/src/plugins/multimedia/windows/player/mfevrvideowindowcontrol_p.h b/src/plugins/multimedia/windows/player/mfevrvideowindowcontrol_p.h
new file mode 100644
index 000000000..1ac90e8ce
--- /dev/null
+++ b/src/plugins/multimedia/windows/player/mfevrvideowindowcontrol_p.h
@@ -0,0 +1,38 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef MFEVRVIDEOWINDOWCONTROL_H
+#define MFEVRVIDEOWINDOWCONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "evrvideowindowcontrol_p.h"
+
+QT_USE_NAMESPACE
+
+class MFEvrVideoWindowControl : public EvrVideoWindowControl
+{
+public:
+ MFEvrVideoWindowControl(QVideoSink *parent = 0);
+ ~MFEvrVideoWindowControl();
+
+ IMFActivate* createActivate();
+ void releaseActivate();
+
+private:
+ void clear();
+
+ IMFActivate *m_currentActivate;
+ IMFMediaSink *m_evrSink;
+};
+
+#endif // MFEVRVIDEOWINDOWCONTROL_H
diff --git a/src/plugins/multimedia/windows/player/mfplayercontrol.cpp b/src/plugins/multimedia/windows/player/mfplayercontrol.cpp
new file mode 100644
index 000000000..ae0022773
--- /dev/null
+++ b/src/plugins/multimedia/windows/player/mfplayercontrol.cpp
@@ -0,0 +1,306 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "mfplayercontrol_p.h"
+#include "mfplayersession_p.h"
+#include "mfvideorenderercontrol_p.h"
+#include <qdebug.h>
+
+//#define DEBUG_MEDIAFOUNDATION
+
+MFPlayerControl::MFPlayerControl(QMediaPlayer *player)
+ : QPlatformMediaPlayer(player)
+ , m_state(QMediaPlayer::StoppedState)
+ , m_stateDirty(false)
+ , m_videoAvailable(false)
+ , m_audioAvailable(false)
+ , m_duration(0)
+ , m_seekable(false)
+{
+ m_session = new MFPlayerSession(this);
+}
+
+MFPlayerControl::~MFPlayerControl()
+{
+ m_session->close();
+ m_session->setPlayerControl(nullptr);
+ m_session->Release();
+}
+
+void MFPlayerControl::setMedia(const QUrl &media, QIODevice *stream)
+{
+ if (m_state != QMediaPlayer::StoppedState) {
+ changeState(QMediaPlayer::StoppedState);
+ m_session->stop(true);
+ refreshState();
+ }
+
+ m_media = media;
+ m_stream = stream;
+ resetAudioVideoAvailable();
+ handleDurationUpdate(0);
+ handleSeekableUpdate(false);
+ m_session->load(media, stream);
+}
+
+void MFPlayerControl::play()
+{
+ if (m_state == QMediaPlayer::PlayingState)
+ return;
+ resetCurrentLoop();
+ if (QMediaPlayer::InvalidMedia == m_session->status())
+ m_session->load(m_media, m_stream);
+
+ switch (m_session->status()) {
+ case QMediaPlayer::NoMedia:
+ case QMediaPlayer::InvalidMedia:
+ return;
+ case QMediaPlayer::LoadedMedia:
+ case QMediaPlayer::BufferingMedia:
+ case QMediaPlayer::BufferedMedia:
+ case QMediaPlayer::EndOfMedia:
+ changeState(QMediaPlayer::PlayingState);
+ m_session->start();
+ break;
+ default: //Loading/Stalled
+ changeState(QMediaPlayer::PlayingState);
+ break;
+ }
+ refreshState();
+}
+
+void MFPlayerControl::pause()
+{
+ if (m_state == QMediaPlayer::PausedState)
+ return;
+
+ if (m_session->status() == QMediaPlayer::NoMedia ||
+ m_session->status() == QMediaPlayer::InvalidMedia)
+ return;
+
+ changeState(QMediaPlayer::PausedState);
+ m_session->pause();
+ refreshState();
+}
+
+void MFPlayerControl::stop()
+{
+ if (m_state == QMediaPlayer::StoppedState)
+ return;
+ changeState(QMediaPlayer::StoppedState);
+ m_session->stop();
+ refreshState();
+}
+
+QMediaMetaData MFPlayerControl::metaData() const
+{
+ return m_session->metaData();
+}
+
+void MFPlayerControl::setAudioOutput(QPlatformAudioOutput *output)
+{
+ m_session->setAudioOutput(output);
+}
+
+void MFPlayerControl::setVideoSink(QVideoSink *sink)
+{
+ m_session->setVideoSink(sink);
+}
+
+void MFPlayerControl::changeState(QMediaPlayer::PlaybackState state)
+{
+ if (m_state == state)
+ return;
+ m_state = state;
+ m_stateDirty = true;
+}
+
+void MFPlayerControl::refreshState()
+{
+ if (!m_stateDirty)
+ return;
+ m_stateDirty = false;
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "MFPlayerControl::emit stateChanged" << m_state;
+#endif
+ stateChanged(m_state);
+}
+
+void MFPlayerControl::handleStatusChanged()
+{
+ QMediaPlayer::MediaStatus status = m_session->status();
+ switch (status) {
+ case QMediaPlayer::EndOfMedia:
+ if (doLoop()) {
+ setPosition(0);
+ m_session->start();
+ } else {
+ changeState(QMediaPlayer::StoppedState);
+ }
+ break;
+ case QMediaPlayer::InvalidMedia:
+ break;
+ case QMediaPlayer::LoadedMedia:
+ case QMediaPlayer::BufferingMedia:
+ case QMediaPlayer::BufferedMedia:
+ if (m_state == QMediaPlayer::PlayingState)
+ m_session->start();
+ break;
+ default:
+ break;
+ }
+ mediaStatusChanged(m_session->status());
+ refreshState();
+}
+
+void MFPlayerControl::handleTracksChanged()
+{
+ tracksChanged();
+}
+
+void MFPlayerControl::handleVideoAvailable()
+{
+ if (m_videoAvailable)
+ return;
+ m_videoAvailable = true;
+ videoAvailableChanged(m_videoAvailable);
+}
+
+void MFPlayerControl::handleAudioAvailable()
+{
+ if (m_audioAvailable)
+ return;
+ m_audioAvailable = true;
+ audioAvailableChanged(m_audioAvailable);
+}
+
+void MFPlayerControl::resetAudioVideoAvailable()
+{
+ bool videoDirty = false;
+ if (m_videoAvailable) {
+ m_videoAvailable = false;
+ videoDirty = true;
+ }
+ if (m_audioAvailable) {
+ m_audioAvailable = false;
+ audioAvailableChanged(m_audioAvailable);
+ }
+ if (videoDirty)
+ videoAvailableChanged(m_videoAvailable);
+}
+
+void MFPlayerControl::handleDurationUpdate(qint64 duration)
+{
+ if (m_duration == duration)
+ return;
+ m_duration = duration;
+ durationChanged(m_duration);
+}
+
+void MFPlayerControl::handleSeekableUpdate(bool seekable)
+{
+ if (m_seekable == seekable)
+ return;
+ m_seekable = seekable;
+ seekableChanged(m_seekable);
+}
+
+QMediaPlayer::PlaybackState MFPlayerControl::state() const
+{
+ return m_state;
+}
+
+QMediaPlayer::MediaStatus MFPlayerControl::mediaStatus() const
+{
+ return m_session->status();
+}
+
+qint64 MFPlayerControl::duration() const
+{
+ return m_duration;
+}
+
+qint64 MFPlayerControl::position() const
+{
+ return m_session->position();
+}
+
+void MFPlayerControl::setPosition(qint64 position)
+{
+ if (!m_seekable || position == m_session->position())
+ return;
+ m_session->setPosition(position);
+}
+
+float MFPlayerControl::bufferProgress() const
+{
+ return m_session->bufferProgress() / 100.;
+}
+
+bool MFPlayerControl::isAudioAvailable() const
+{
+ return m_audioAvailable;
+}
+
+bool MFPlayerControl::isVideoAvailable() const
+{
+ return m_videoAvailable;
+}
+
+bool MFPlayerControl::isSeekable() const
+{
+ return m_seekable;
+}
+
+QMediaTimeRange MFPlayerControl::availablePlaybackRanges() const
+{
+ return m_session->availablePlaybackRanges();
+}
+
+qreal MFPlayerControl::playbackRate() const
+{
+ return m_session->playbackRate();
+}
+
+void MFPlayerControl::setPlaybackRate(qreal rate)
+{
+ m_session->setPlaybackRate(rate);
+}
+
+QUrl MFPlayerControl::media() const
+{
+ return m_media;
+}
+
+const QIODevice* MFPlayerControl::mediaStream() const
+{
+ return m_stream;
+}
+
+void MFPlayerControl::handleError(QMediaPlayer::Error errorCode, const QString& errorString, bool isFatal)
+{
+ if (isFatal)
+ stop();
+ error(int(errorCode), errorString);
+}
+
+void MFPlayerControl::setActiveTrack(TrackType type, int index)
+{
+ m_session->setActiveTrack(type, index);
+}
+
+int MFPlayerControl::activeTrack(TrackType type)
+{
+ return m_session->activeTrack(type);
+}
+
+int MFPlayerControl::trackCount(TrackType type)
+{
+ return m_session->trackCount(type);
+}
+
+QMediaMetaData MFPlayerControl::trackMetaData(TrackType type, int trackNumber)
+{
+ return m_session->trackMetaData(type, trackNumber);
+}
+
diff --git a/src/plugins/multimedia/windows/player/mfplayercontrol_p.h b/src/plugins/multimedia/windows/player/mfplayercontrol_p.h
new file mode 100644
index 000000000..db863afaa
--- /dev/null
+++ b/src/plugins/multimedia/windows/player/mfplayercontrol_p.h
@@ -0,0 +1,103 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef MFPLAYERCONTROL_H
+#define MFPLAYERCONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qurl.h"
+#include "private/qplatformmediaplayer_p.h"
+
+#include <QtCore/qcoreevent.h>
+
+QT_BEGIN_NAMESPACE
+
+class MFPlayerSession;
+
+class MFPlayerControl : public QPlatformMediaPlayer
+{
+public:
+ MFPlayerControl(QMediaPlayer *player);
+ ~MFPlayerControl();
+
+ QMediaPlayer::PlaybackState state() const override;
+
+ QMediaPlayer::MediaStatus mediaStatus() const override;
+
+ qint64 duration() const override;
+
+ qint64 position() const override;
+ void setPosition(qint64 position) override;
+
+ float bufferProgress() const override;
+
+ bool isAudioAvailable() const override;
+ bool isVideoAvailable() const override;
+
+ bool isSeekable() const override;
+
+ QMediaTimeRange availablePlaybackRanges() const override;
+
+ qreal playbackRate() const override;
+ void setPlaybackRate(qreal rate) override;
+
+ QUrl media() const override;
+ const QIODevice *mediaStream() const override;
+ void setMedia(const QUrl &media, QIODevice *stream) override;
+
+ void play() override;
+ void pause() override;
+ void stop() override;
+
+ bool streamPlaybackSupported() const override { return true; }
+
+ QMediaMetaData metaData() const override;
+
+ void setAudioOutput(QPlatformAudioOutput *output) override;
+
+ void setVideoSink(QVideoSink *sink) override;
+
+ void setActiveTrack(TrackType type, int index) override;
+ int activeTrack(TrackType type) override;
+ int trackCount(TrackType type) override;
+ QMediaMetaData trackMetaData(TrackType type, int trackNumber) override;
+
+ void handleStatusChanged();
+ void handleTracksChanged();
+ void handleVideoAvailable();
+ void handleAudioAvailable();
+ void handleDurationUpdate(qint64 duration);
+ void handleSeekableUpdate(bool seekable);
+ void handleError(QMediaPlayer::Error errorCode, const QString& errorString, bool isFatal);
+
+private:
+ void changeState(QMediaPlayer::PlaybackState state);
+ void resetAudioVideoAvailable();
+ void refreshState();
+
+ QMediaPlayer::PlaybackState m_state;
+ bool m_stateDirty;
+
+ bool m_videoAvailable;
+ bool m_audioAvailable;
+ qint64 m_duration;
+ bool m_seekable;
+
+ QIODevice *m_stream;
+ QUrl m_media;
+ MFPlayerSession *m_session;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/windows/player/mfplayersession.cpp b/src/plugins/multimedia/windows/player/mfplayersession.cpp
new file mode 100644
index 000000000..16cba7266
--- /dev/null
+++ b/src/plugins/multimedia/windows/player/mfplayersession.cpp
@@ -0,0 +1,1736 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "private/qplatformmediaplayer_p.h"
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qdatetime.h>
+#include <QtCore/qthread.h>
+#include <QtCore/qvarlengtharray.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qbuffer.h>
+
+#include "private/qplatformaudiooutput_p.h"
+#include "qaudiooutput.h"
+
+#include "mfplayercontrol_p.h"
+#include "mfvideorenderercontrol_p.h"
+#include <mfmetadata_p.h>
+#include <private/qwindowsmfdefs_p.h>
+#include <private/qwindowsaudioutils_p.h>
+
+#include "mfplayersession_p.h"
+#include <mferror.h>
+#include <nserror.h>
+#include <winerror.h>
+#include "sourceresolver_p.h"
+#include <wmcodecdsp.h>
+
+#include <mmdeviceapi.h>
+#include <propvarutil.h>
+#include <functiondiscoverykeys_devpkey.h>
+
+//#define DEBUG_MEDIAFOUNDATION
+
+QT_BEGIN_NAMESPACE
+
+MFPlayerSession::MFPlayerSession(MFPlayerControl *playerControl)
+ : m_cRef(1),
+ m_playerControl(playerControl),
+ m_scrubbing(false),
+ m_restoreRate(1),
+ m_closing(false),
+ m_mediaTypes(0),
+ m_pendingRate(1),
+ m_status(QMediaPlayer::NoMedia)
+
+{
+ connect(this, &MFPlayerSession::sessionEvent, this, &MFPlayerSession::handleSessionEvent);
+
+ m_signalPositionChangeTimer.setInterval(10);
+ m_signalPositionChangeTimer.setTimerType(Qt::PreciseTimer);
+ m_signalPositionChangeTimer.callOnTimeout(this, &MFPlayerSession::timeout);
+
+ m_pendingState = NoPending;
+ ZeroMemory(&m_state, sizeof(m_state));
+ m_state.command = CmdStop;
+ m_state.prevCmd = CmdNone;
+ m_state.rate = 1.0f;
+ ZeroMemory(&m_request, sizeof(m_request));
+ m_request.command = CmdNone;
+ m_request.prevCmd = CmdNone;
+ m_request.rate = 1.0f;
+
+ m_videoRendererControl = new MFVideoRendererControl(this);
+}
+
+void MFPlayerSession::timeout()
+{
+ const qint64 pos = position();
+
+ if (pos != m_lastPosition) {
+ const bool updatePos = m_timeCounter++ % 10 == 0;
+ if (pos >= qint64(m_duration / 10000 - 20)) {
+ if (m_playerControl->doLoop()) {
+ m_session->Pause();
+ setPosition(0);
+ positionChanged(0);
+ } else {
+ if (updatePos)
+ positionChanged(pos);
+ }
+ } else {
+ if (updatePos)
+ positionChanged(pos);
+ }
+ m_lastPosition = pos;
+ }
+}
+
+void MFPlayerSession::close()
+{
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "close";
+#endif
+
+ m_signalPositionChangeTimer.stop();
+ clear();
+ if (!m_session)
+ return;
+
+ HRESULT hr = S_OK;
+ if (m_session) {
+ m_closing = true;
+ hr = m_session->Close();
+ if (SUCCEEDED(hr)) {
+ DWORD dwWaitResult = WaitForSingleObject(m_hCloseEvent.get(), 2000);
+ if (dwWaitResult == WAIT_TIMEOUT) {
+ qWarning() << "session close time out!";
+ }
+ }
+ m_closing = false;
+ }
+
+ if (SUCCEEDED(hr)) {
+ if (m_session)
+ m_session->Shutdown();
+ if (m_sourceResolver)
+ m_sourceResolver->shutdown();
+ }
+ m_sourceResolver.Reset();
+
+ m_videoRendererControl->releaseActivate();
+// } else if (m_playerService->videoWindowControl()) {
+// m_playerService->videoWindowControl()->releaseActivate();
+// }
+
+ m_session.Reset();
+ m_hCloseEvent = {};
+ m_lastPosition = -1;
+ m_position = 0;
+}
+
+void MFPlayerSession::load(const QUrl &url, QIODevice *stream)
+{
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "load";
+#endif
+ clear();
+
+ if (m_status == QMediaPlayer::LoadingMedia && m_sourceResolver)
+ m_sourceResolver->cancel();
+
+ if (url.isEmpty() && !stream) {
+ close();
+ changeStatus(QMediaPlayer::NoMedia);
+ } else if (stream && (!stream->isReadable())) {
+ close();
+ changeStatus(QMediaPlayer::InvalidMedia);
+ error(QMediaPlayer::ResourceError, tr("Invalid stream source."), true);
+ } else if (createSession()) {
+ changeStatus(QMediaPlayer::LoadingMedia);
+ m_sourceResolver->load(url, stream);
+ if (url.isLocalFile())
+ m_updateRoutingOnStart = true;
+ }
+ positionChanged(position());
+}
+
+void MFPlayerSession::handleSourceError(long hr)
+{
+ QString errorString;
+ QMediaPlayer::Error errorCode = QMediaPlayer::ResourceError;
+ switch (hr) {
+ case QMediaPlayer::FormatError:
+ errorCode = QMediaPlayer::FormatError;
+ errorString = tr("Attempting to play invalid Qt resource.");
+ break;
+ case NS_E_FILE_NOT_FOUND:
+ errorString = tr("The system cannot find the file specified.");
+ break;
+ case NS_E_SERVER_NOT_FOUND:
+ errorString = tr("The specified server could not be found.");
+ break;
+ case MF_E_UNSUPPORTED_BYTESTREAM_TYPE:
+ errorCode = QMediaPlayer::FormatError;
+ errorString = tr("Unsupported media type.");
+ break;
+ case MF_E_UNSUPPORTED_SCHEME:
+ errorCode = QMediaPlayer::ResourceError;
+ errorString = tr("Unsupported URL scheme.");
+ break;
+ case QMM_WININET_E_CANNOT_CONNECT:
+ errorCode = QMediaPlayer::NetworkError;
+ errorString = tr("Connection to server could not be established.");
+ break;
+ default:
+ qWarning() << "handleSourceError:"
+ << Qt::showbase << Qt::hex << Qt::uppercasedigits << static_cast<quint32>(hr);
+ errorString = tr("Failed to load source.");
+ break;
+ }
+ changeStatus(QMediaPlayer::InvalidMedia);
+ error(errorCode, errorString, true);
+}
+
+void MFPlayerSession::handleMediaSourceReady()
+{
+ if (QMediaPlayer::LoadingMedia != m_status || !m_sourceResolver
+ || m_sourceResolver.Get() != sender())
+ return;
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "handleMediaSourceReady";
+#endif
+ HRESULT hr = S_OK;
+ IMFMediaSource* mediaSource = m_sourceResolver->mediaSource();
+
+ DWORD dwCharacteristics = 0;
+ mediaSource->GetCharacteristics(&dwCharacteristics);
+ seekableUpdate(MFMEDIASOURCE_CAN_SEEK & dwCharacteristics);
+
+ ComPtr<IMFPresentationDescriptor> sourcePD;
+ hr = mediaSource->CreatePresentationDescriptor(&sourcePD);
+ if (SUCCEEDED(hr)) {
+ m_duration = 0;
+ m_metaData = MFMetaData::fromNative(mediaSource);
+ metaDataChanged();
+ sourcePD->GetUINT64(MF_PD_DURATION, &m_duration);
+ //convert from 100 nanosecond to milisecond
+ durationUpdate(qint64(m_duration / 10000));
+ setupPlaybackTopology(mediaSource, sourcePD.Get());
+ tracksChanged();
+ } else {
+ changeStatus(QMediaPlayer::InvalidMedia);
+ error(QMediaPlayer::ResourceError, tr("Cannot create presentation descriptor."), true);
+ }
+}
+
+bool MFPlayerSession::getStreamInfo(IMFStreamDescriptor *stream,
+ MFPlayerSession::MediaType *type,
+ QString *name,
+ QString *language,
+ GUID *format) const
+{
+ if (!stream || !type || !name || !language || !format)
+ return false;
+
+ *type = Unknown;
+ *name = QString();
+ *language = QString();
+
+ ComPtr<IMFMediaTypeHandler> typeHandler;
+
+ if (SUCCEEDED(stream->GetMediaTypeHandler(&typeHandler))) {
+
+ UINT32 len = 0;
+ if (SUCCEEDED(stream->GetStringLength(QMM_MF_SD_STREAM_NAME, &len)) && len > 0) {
+ WCHAR *wstr = new WCHAR[len+1];
+ if (SUCCEEDED(stream->GetString(QMM_MF_SD_STREAM_NAME, wstr, len+1, &len))) {
+ *name = QString::fromUtf16(reinterpret_cast<const char16_t *>(wstr));
+ }
+ delete []wstr;
+ }
+ if (SUCCEEDED(stream->GetStringLength(QMM_MF_SD_LANGUAGE, &len)) && len > 0) {
+ WCHAR *wstr = new WCHAR[len+1];
+ if (SUCCEEDED(stream->GetString(QMM_MF_SD_LANGUAGE, wstr, len+1, &len))) {
+ *language = QString::fromUtf16(reinterpret_cast<const char16_t *>(wstr));
+ }
+ delete []wstr;
+ }
+
+ GUID guidMajorType;
+ if (SUCCEEDED(typeHandler->GetMajorType(&guidMajorType))) {
+ if (guidMajorType == MFMediaType_Audio)
+ *type = Audio;
+ else if (guidMajorType == MFMediaType_Video)
+ *type = Video;
+ }
+
+ ComPtr<IMFMediaType> mediaType;
+ if (SUCCEEDED(typeHandler->GetCurrentMediaType(&mediaType))) {
+ mediaType->GetGUID(MF_MT_SUBTYPE, format);
+ }
+ }
+
+ return *type != Unknown;
+}
+
+void MFPlayerSession::setupPlaybackTopology(IMFMediaSource *source, IMFPresentationDescriptor *sourcePD)
+{
+ HRESULT hr = S_OK;
+ // Get the number of streams in the media source.
+ DWORD cSourceStreams = 0;
+ hr = sourcePD->GetStreamDescriptorCount(&cSourceStreams);
+ if (FAILED(hr)) {
+ changeStatus(QMediaPlayer::InvalidMedia);
+ error(QMediaPlayer::ResourceError, tr("Failed to get stream count."), true);
+ return;
+ }
+
+ ComPtr<IMFTopology> topology;
+ hr = MFCreateTopology(&topology);
+ if (FAILED(hr)) {
+ changeStatus(QMediaPlayer::InvalidMedia);
+ error(QMediaPlayer::ResourceError, tr("Failed to create topology."), true);
+ return;
+ }
+
+ // For each stream, create the topology nodes and add them to the topology.
+ DWORD succeededCount = 0;
+ for (DWORD i = 0; i < cSourceStreams; i++) {
+ BOOL selected = FALSE;
+ bool streamAdded = false;
+ ComPtr<IMFStreamDescriptor> streamDesc;
+
+ HRESULT hr = sourcePD->GetStreamDescriptorByIndex(i, &selected, &streamDesc);
+ if (SUCCEEDED(hr)) {
+ // The media might have multiple audio and video streams,
+ // only use one of each kind, and only if it is selected by default.
+ MediaType mediaType = Unknown;
+ QString streamName;
+ QString streamLanguage;
+ GUID format = GUID_NULL;
+
+ if (getStreamInfo(streamDesc.Get(), &mediaType, &streamName, &streamLanguage,
+ &format)) {
+
+ QPlatformMediaPlayer::TrackType trackType = (mediaType == Audio) ?
+ QPlatformMediaPlayer::AudioStream : QPlatformMediaPlayer::VideoStream;
+
+ QLocale::Language lang = streamLanguage.isEmpty() ?
+ QLocale::Language::AnyLanguage : QLocale(streamLanguage).language();
+
+ QMediaMetaData metaData;
+ metaData.insert(QMediaMetaData::Title, streamName);
+ metaData.insert(QMediaMetaData::Language, lang);
+
+ m_trackInfo[trackType].metaData.append(metaData);
+ m_trackInfo[trackType].nativeIndexes.append(i);
+ m_trackInfo[trackType].format = format;
+
+ if (((m_mediaTypes & mediaType) == 0) && selected) { // Check if this type isn't already added
+ ComPtr<IMFTopologyNode> sourceNode =
+ addSourceNode(topology.Get(), source, sourcePD, streamDesc.Get());
+ if (sourceNode) {
+ ComPtr<IMFTopologyNode> outputNode =
+ addOutputNode(mediaType, topology.Get(), 0);
+ if (outputNode) {
+ sourceNode->GetTopoNodeID(&m_trackInfo[trackType].sourceNodeId);
+ outputNode->GetTopoNodeID(&m_trackInfo[trackType].outputNodeId);
+
+ hr = sourceNode->ConnectOutput(0, outputNode.Get(), 0);
+
+ if (FAILED(hr)) {
+ error(QMediaPlayer::FormatError, tr("Unable to play any stream."), false);
+ } else {
+ m_trackInfo[trackType].currentIndex = m_trackInfo[trackType].nativeIndexes.count() - 1;
+ streamAdded = true;
+ succeededCount++;
+ m_mediaTypes |= mediaType;
+ switch (mediaType) {
+ case Audio:
+ audioAvailable();
+ break;
+ case Video:
+ videoAvailable();
+ break;
+ default:
+ break;
+ }
+ }
+ } else {
+ // remove the source node if the output node cannot be created
+ topology->RemoveNode(sourceNode.Get());
+ }
+ }
+ }
+ }
+
+ if (selected && !streamAdded)
+ sourcePD->DeselectStream(i);
+ }
+ }
+
+ if (succeededCount == 0) {
+ changeStatus(QMediaPlayer::InvalidMedia);
+ error(QMediaPlayer::ResourceError, tr("Unable to play."), true);
+ } else {
+ if (m_trackInfo[QPlatformMediaPlayer::VideoStream].outputNodeId != TOPOID(-1))
+ topology = insertMFT(topology, m_trackInfo[QPlatformMediaPlayer::VideoStream].outputNodeId);
+
+ hr = m_session->SetTopology(MFSESSION_SETTOPOLOGY_IMMEDIATE, topology.Get());
+ if (SUCCEEDED(hr)) {
+ m_updatingTopology = true;
+ } else {
+ changeStatus(QMediaPlayer::InvalidMedia);
+ error(QMediaPlayer::ResourceError, tr("Failed to set topology."), true);
+ }
+ }
+}
+
+ComPtr<IMFTopologyNode> MFPlayerSession::addSourceNode(IMFTopology *topology,
+ IMFMediaSource *source,
+ IMFPresentationDescriptor *presentationDesc,
+ IMFStreamDescriptor *streamDesc)
+{
+ ComPtr<IMFTopologyNode> node;
+ HRESULT hr = MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, &node);
+ if (SUCCEEDED(hr)) {
+ hr = node->SetUnknown(MF_TOPONODE_SOURCE, source);
+ if (SUCCEEDED(hr)) {
+ hr = node->SetUnknown(MF_TOPONODE_PRESENTATION_DESCRIPTOR, presentationDesc);
+ if (SUCCEEDED(hr)) {
+ hr = node->SetUnknown(MF_TOPONODE_STREAM_DESCRIPTOR, streamDesc);
+ if (SUCCEEDED(hr)) {
+ hr = topology->AddNode(node.Get());
+ if (SUCCEEDED(hr))
+ return node;
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+ComPtr<IMFTopologyNode> MFPlayerSession::addOutputNode(MediaType mediaType, IMFTopology *topology,
+ DWORD sinkID)
+{
+ ComPtr<IMFTopologyNode> node;
+ if (FAILED(MFCreateTopologyNode(MF_TOPOLOGY_OUTPUT_NODE, &node)))
+ return NULL;
+
+ ComPtr<IMFActivate> activate;
+ if (mediaType == Audio) {
+ if (m_audioOutput) {
+ auto id = m_audioOutput->device.id();
+ if (id.isEmpty()) {
+ qInfo() << "No audio output";
+ return NULL;
+ }
+
+ HRESULT hr = MFCreateAudioRendererActivate(&activate);
+ if (FAILED(hr)) {
+ qWarning() << "Failed to create audio renderer activate";
+ return NULL;
+ }
+
+ QString s = QString::fromUtf8(id);
+ hr = activate->SetString(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ID, (LPCWSTR)s.utf16());
+ if (FAILED(hr)) {
+ qWarning() << "Failed to set attribute for audio device"
+ << m_audioOutput->device.description();
+ return NULL;
+ }
+ }
+ } else if (mediaType == Video) {
+ activate = m_videoRendererControl->createActivate();
+
+ QSize resolution = m_metaData.value(QMediaMetaData::Resolution).toSize();
+
+ if (resolution.isValid())
+ m_videoRendererControl->setCropRect(QRect(QPoint(), resolution));
+
+ } else {
+ // Unknown stream type.
+ error(QMediaPlayer::FormatError, tr("Unknown stream type."), false);
+ }
+
+ if (!activate || FAILED(node->SetObject(activate.Get()))
+ || FAILED(node->SetUINT32(MF_TOPONODE_STREAMID, sinkID))
+ || FAILED(node->SetUINT32(MF_TOPONODE_NOSHUTDOWN_ON_REMOVE, FALSE))
+ || FAILED(topology->AddNode(node.Get()))) {
+ node.Reset();
+ }
+
+ if (activate && mediaType == Audio)
+ activate.Reset();
+
+ return node;
+}
+
+// BindOutputNode
+// Sets the IMFStreamSink pointer on an output node.
+// IMFActivate pointer in the output node must be converted to an
+// IMFStreamSink pointer before the topology loader resolves the topology.
+HRESULT BindOutputNode(IMFTopologyNode *pNode)
+{
+ ComPtr<IUnknown> nodeObject;
+ ComPtr<IMFActivate> activate;
+ ComPtr<IMFStreamSink> stream;
+ ComPtr<IMFMediaSink> sink;
+
+ HRESULT hr = pNode->GetObject(&nodeObject);
+ if (FAILED(hr))
+ return hr;
+
+ hr = nodeObject->QueryInterface(IID_PPV_ARGS(&activate));
+ if (SUCCEEDED(hr)) {
+ DWORD dwStreamID = 0;
+
+ // Try to create the media sink.
+ hr = activate->ActivateObject(IID_PPV_ARGS(&sink));
+ if (SUCCEEDED(hr))
+ dwStreamID = MFGetAttributeUINT32(pNode, MF_TOPONODE_STREAMID, 0);
+
+ if (SUCCEEDED(hr)) {
+ // First check if the media sink already has a stream sink with the requested ID.
+ hr = sink->GetStreamSinkById(dwStreamID, &stream);
+ if (FAILED(hr)) {
+ // Create the stream sink.
+ hr = sink->AddStreamSink(dwStreamID, NULL, &stream);
+ }
+ }
+
+ // Replace the node's object pointer with the stream sink.
+ if (SUCCEEDED(hr)) {
+ hr = pNode->SetObject(stream.Get());
+ }
+ } else {
+ hr = nodeObject->QueryInterface(IID_PPV_ARGS(&stream));
+ }
+
+ return hr;
+}
+
+// BindOutputNodes
+// Sets the IMFStreamSink pointers on all of the output nodes in a topology.
+HRESULT BindOutputNodes(IMFTopology *pTopology)
+{
+ ComPtr<IMFCollection> collection;
+
+ // Get the collection of output nodes.
+ HRESULT hr = pTopology->GetOutputNodeCollection(&collection);
+
+ // Enumerate all of the nodes in the collection.
+ if (SUCCEEDED(hr)) {
+ DWORD cNodes;
+ hr = collection->GetElementCount(&cNodes);
+
+ if (SUCCEEDED(hr)) {
+ for (DWORD i = 0; i < cNodes; i++) {
+ ComPtr<IUnknown> element;
+ hr = collection->GetElement(i, &element);
+ if (FAILED(hr))
+ break;
+
+ ComPtr<IMFTopologyNode> node;
+ hr = element->QueryInterface(IID_IMFTopologyNode, &node);
+ if (FAILED(hr))
+ break;
+
+ // Bind this node.
+ hr = BindOutputNode(node.Get());
+ if (FAILED(hr))
+ break;
+ }
+ }
+ }
+
+ return hr;
+}
+
+// This method binds output nodes to complete the topology,
+// then loads the topology and inserts MFT between the output node
+// and a filter connected to the output node.
+ComPtr<IMFTopology> MFPlayerSession::insertMFT(const ComPtr<IMFTopology> &topology,
+ TOPOID outputNodeId)
+{
+ bool isNewTopology = false;
+
+ ComPtr<IMFTopoLoader> topoLoader;
+ ComPtr<IMFTopology> resolvedTopology;
+ ComPtr<IMFCollection> outputNodes;
+
+ do {
+ if (FAILED(BindOutputNodes(topology.Get())))
+ break;
+
+ if (FAILED(MFCreateTopoLoader(&topoLoader)))
+ break;
+
+ if (FAILED(topoLoader->Load(topology.Get(), &resolvedTopology, NULL))) {
+ // Topology could not be resolved, adding ourselves a color converter
+ // to the topology might solve the problem
+ insertColorConverter(topology.Get(), outputNodeId);
+ if (FAILED(topoLoader->Load(topology.Get(), &resolvedTopology, NULL)))
+ break;
+ }
+
+ if (insertResizer(resolvedTopology.Get()))
+ isNewTopology = true;
+ } while (false);
+
+ if (isNewTopology) {
+ return resolvedTopology;
+ }
+
+ return topology;
+}
+
+// This method checks if the topology contains a color converter transform (CColorConvertDMO),
+// if it does it inserts a resizer transform (CResizerDMO) to handle dynamic frame size change
+// of the video stream.
+// Returns true if it inserted a resizer
+bool MFPlayerSession::insertResizer(IMFTopology *topology)
+{
+ bool inserted = false;
+ WORD elementCount = 0;
+ ComPtr<IMFTopologyNode> node;
+ ComPtr<IUnknown> object;
+ ComPtr<IWMColorConvProps> colorConv;
+ ComPtr<IMFTransform> resizer;
+ ComPtr<IMFTopologyNode> resizerNode;
+ ComPtr<IMFTopologyNode> inputNode;
+
+ HRESULT hr = topology->GetNodeCount(&elementCount);
+ if (FAILED(hr))
+ return false;
+
+ for (WORD i = 0; i < elementCount; ++i) {
+ node.Reset();
+ object.Reset();
+
+ if (FAILED(topology->GetNode(i, &node)))
+ break;
+
+ MF_TOPOLOGY_TYPE nodeType;
+ if (FAILED(node->GetNodeType(&nodeType)))
+ break;
+
+ if (nodeType != MF_TOPOLOGY_TRANSFORM_NODE)
+ continue;
+
+ if (FAILED(node->GetObject(&object)))
+ break;
+
+ if (FAILED(object->QueryInterface(IID_PPV_ARGS(&colorConv))))
+ continue;
+
+ if (FAILED(CoCreateInstance(CLSID_CResizerDMO, NULL, CLSCTX_INPROC_SERVER, IID_IMFTransform,
+ &resizer)))
+ break;
+
+ if (FAILED(MFCreateTopologyNode(MF_TOPOLOGY_TRANSFORM_NODE, &resizerNode)))
+ break;
+
+ if (FAILED(resizerNode->SetObject(resizer.Get())))
+ break;
+
+ if (FAILED(topology->AddNode(resizerNode.Get())))
+ break;
+
+ DWORD outputIndex = 0;
+ if (FAILED(node->GetInput(0, &inputNode, &outputIndex))) {
+ topology->RemoveNode(resizerNode.Get());
+ break;
+ }
+
+ if (FAILED(inputNode->ConnectOutput(0, resizerNode.Get(), 0))) {
+ topology->RemoveNode(resizerNode.Get());
+ break;
+ }
+
+ if (FAILED(resizerNode->ConnectOutput(0, node.Get(), 0))) {
+ inputNode->ConnectOutput(0, node.Get(), 0);
+ topology->RemoveNode(resizerNode.Get());
+ break;
+ }
+
+ inserted = true;
+ break;
+ }
+
+ return inserted;
+}
+
+// This method inserts a color converter (CColorConvertDMO) in the topology,
+// typically to convert to RGB format.
+// Usually this converter is automatically inserted when the topology is resolved but
+// for some reason it fails to do so in some cases, we then do it ourselves.
+void MFPlayerSession::insertColorConverter(IMFTopology *topology, TOPOID outputNodeId)
+{
+ ComPtr<IMFCollection> outputNodes;
+
+ if (FAILED(topology->GetOutputNodeCollection(&outputNodes)))
+ return;
+
+ DWORD elementCount = 0;
+ if (FAILED(outputNodes->GetElementCount(&elementCount)))
+ return;
+
+ for (DWORD n = 0; n < elementCount; n++) {
+ ComPtr<IUnknown> element;
+ ComPtr<IMFTopologyNode> node;
+ ComPtr<IMFTopologyNode> inputNode;
+ ComPtr<IMFTopologyNode> mftNode;
+ ComPtr<IMFTransform> converter;
+
+ do {
+ if (FAILED(outputNodes->GetElement(n, &element)))
+ break;
+
+ if (FAILED(element->QueryInterface(IID_IMFTopologyNode, &node)))
+ break;
+
+ TOPOID id;
+ if (FAILED(node->GetTopoNodeID(&id)))
+ break;
+
+ if (id != outputNodeId)
+ break;
+
+ DWORD outputIndex = 0;
+ if (FAILED(node->GetInput(0, &inputNode, &outputIndex)))
+ break;
+
+ if (FAILED(MFCreateTopologyNode(MF_TOPOLOGY_TRANSFORM_NODE, &mftNode)))
+ break;
+
+ if (FAILED(CoCreateInstance(CLSID_CColorConvertDMO, NULL, CLSCTX_INPROC_SERVER,
+ IID_IMFTransform, &converter)))
+ break;
+
+ if (FAILED(mftNode->SetObject(converter.Get())))
+ break;
+
+ if (FAILED(topology->AddNode(mftNode.Get())))
+ break;
+
+ if (FAILED(inputNode->ConnectOutput(0, mftNode.Get(), 0)))
+ break;
+
+ if (FAILED(mftNode->ConnectOutput(0, node.Get(), 0)))
+ break;
+
+ } while (false);
+ }
+}
+
+void MFPlayerSession::stop(bool immediate)
+{
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "stop";
+#endif
+ if (!immediate && m_pendingState != NoPending) {
+ m_request.setCommand(CmdStop);
+ } else {
+ if (m_state.command == CmdStop)
+ return;
+
+ if (m_scrubbing)
+ scrub(false);
+
+ if (SUCCEEDED(m_session->Stop())) {
+
+ m_state.setCommand(CmdStop);
+ m_pendingState = CmdPending;
+ if (m_status != QMediaPlayer::EndOfMedia) {
+ m_position = 0;
+ positionChanged(0);
+ }
+ } else {
+ error(QMediaPlayer::ResourceError, tr("Failed to stop."), true);
+ }
+ }
+}
+
+void MFPlayerSession::start()
+{
+ if (status() == QMediaPlayer::LoadedMedia && m_updateRoutingOnStart) {
+ m_updateRoutingOnStart = false;
+ updateOutputRouting();
+ }
+
+ if (m_status == QMediaPlayer::EndOfMedia) {
+ m_position = 0; // restart from the beginning
+ positionChanged(0);
+ }
+
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "start";
+#endif
+
+ if (m_pendingState != NoPending) {
+ m_request.setCommand(CmdStart);
+ } else {
+ if (m_state.command == CmdStart)
+ return;
+
+ if (m_scrubbing) {
+ scrub(false);
+ m_position = position() * 10000;
+ }
+
+ if (m_restorePosition >= 0) {
+ m_position = m_restorePosition;
+ if (!m_updatingTopology)
+ m_restorePosition = -1;
+ }
+
+ PROPVARIANT varStart;
+ InitPropVariantFromInt64(m_position, &varStart);
+
+ if (SUCCEEDED(m_session->Start(&GUID_NULL, &varStart))) {
+ m_state.setCommand(CmdStart);
+ m_pendingState = CmdPending;
+ } else {
+ error(QMediaPlayer::ResourceError, tr("failed to start playback"), true);
+ }
+ PropVariantClear(&varStart);
+ }
+}
+
+void MFPlayerSession::pause()
+{
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "pause";
+#endif
+ if (m_pendingState != NoPending) {
+ m_request.setCommand(CmdPause);
+ } else {
+ if (m_state.command == CmdPause)
+ return;
+
+ if (SUCCEEDED(m_session->Pause())) {
+ m_state.setCommand(CmdPause);
+ m_pendingState = CmdPending;
+ } else {
+ error(QMediaPlayer::ResourceError, tr("Failed to pause."), false);
+ }
+ if (m_status == QMediaPlayer::EndOfMedia) {
+ setPosition(0);
+ positionChanged(0);
+ }
+ }
+}
+
+void MFPlayerSession::changeStatus(QMediaPlayer::MediaStatus newStatus)
+{
+ if (m_status == newStatus)
+ return;
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "MFPlayerSession::changeStatus" << newStatus;
+#endif
+ m_status = newStatus;
+ statusChanged();
+}
+
+QMediaPlayer::MediaStatus MFPlayerSession::status() const
+{
+ return m_status;
+}
+
+bool MFPlayerSession::createSession()
+{
+ close();
+
+ Q_ASSERT(m_session == NULL);
+
+ HRESULT hr = MFCreateMediaSession(NULL, &m_session);
+ if (FAILED(hr)) {
+ changeStatus(QMediaPlayer::InvalidMedia);
+ error(QMediaPlayer::ResourceError, tr("Unable to create mediasession."), true);
+ return false;
+ }
+
+ m_hCloseEvent = EventHandle{ CreateEvent(NULL, FALSE, FALSE, NULL) };
+
+ hr = m_session->BeginGetEvent(this, m_session.Get());
+ if (FAILED(hr)) {
+ changeStatus(QMediaPlayer::InvalidMedia);
+ error(QMediaPlayer::ResourceError, tr("Unable to pull session events."), false);
+ close();
+ return false;
+ }
+
+ m_sourceResolver = makeComObject<SourceResolver>();
+ QObject::connect(m_sourceResolver.Get(), &SourceResolver::mediaSourceReady, this,
+ &MFPlayerSession::handleMediaSourceReady);
+ QObject::connect(m_sourceResolver.Get(), &SourceResolver::error, this,
+ &MFPlayerSession::handleSourceError);
+
+ m_position = 0;
+ return true;
+}
+
+qint64 MFPlayerSession::position()
+{
+ if (m_request.command == CmdSeek || m_request.command == CmdSeekResume)
+ return m_request.start;
+
+ if (m_pendingState == SeekPending)
+ return m_state.start;
+
+ if (m_state.command == CmdStop)
+ return m_position / 10000;
+
+ if (m_presentationClock) {
+ MFTIME time, sysTime;
+ if (FAILED(m_presentationClock->GetCorrelatedTime(0, &time, &sysTime)))
+ return m_position / 10000;
+ return qint64(time / 10000);
+ }
+ return m_position / 10000;
+}
+
+void MFPlayerSession::setPosition(qint64 position)
+{
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "setPosition";
+#endif
+ if (m_pendingState != NoPending) {
+ m_request.setCommand(CmdSeek);
+ m_request.start = position;
+ } else {
+ setPositionInternal(position, CmdNone);
+ }
+}
+
+void MFPlayerSession::setPositionInternal(qint64 position, Command requestCmd)
+{
+ if (m_status == QMediaPlayer::EndOfMedia)
+ changeStatus(QMediaPlayer::LoadedMedia);
+ if (m_state.command == CmdStop && requestCmd != CmdSeekResume) {
+ m_position = position * 10000;
+ // Even though the position is not actually set on the session yet,
+ // report it to have changed anyway for UI controls to be updated
+ positionChanged(this->position());
+ return;
+ }
+
+ if (m_state.command == CmdPause)
+ scrub(true);
+
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "setPositionInternal";
+#endif
+
+ PROPVARIANT varStart;
+ varStart.vt = VT_I8;
+ varStart.hVal.QuadPart = LONGLONG(position * 10000);
+ if (SUCCEEDED(m_session->Start(NULL, &varStart))) {
+ PropVariantClear(&varStart);
+ // Store the pending state.
+ m_state.setCommand(CmdStart);
+ m_state.start = position;
+ m_pendingState = SeekPending;
+ } else {
+ error(QMediaPlayer::ResourceError, tr("Failed to seek."), true);
+ }
+}
+
+qreal MFPlayerSession::playbackRate() const
+{
+ if (m_scrubbing)
+ return m_restoreRate;
+ return m_state.rate;
+}
+
+void MFPlayerSession::setPlaybackRate(qreal rate)
+{
+ if (m_scrubbing) {
+ m_restoreRate = rate;
+ playbackRateChanged(rate);
+ return;
+ }
+ setPlaybackRateInternal(rate);
+}
+
+void MFPlayerSession::setPlaybackRateInternal(qreal rate)
+{
+ if (rate == m_request.rate)
+ return;
+
+ m_pendingRate = rate;
+ if (!m_rateSupport)
+ return;
+
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "setPlaybackRate";
+#endif
+ BOOL isThin = FALSE;
+
+ //from MSDN http://msdn.microsoft.com/en-us/library/aa965220%28v=vs.85%29.aspx
+ //Thinning applies primarily to video streams.
+ //In thinned mode, the source drops delta frames and deliver only key frames.
+ //At very high playback rates, the source might skip some key frames (for example, deliver every other key frame).
+
+ if (FAILED(m_rateSupport->IsRateSupported(FALSE, rate, NULL))) {
+ isThin = TRUE;
+ if (FAILED(m_rateSupport->IsRateSupported(isThin, rate, NULL))) {
+ qWarning() << "unable to set playbackrate = " << rate;
+ m_pendingRate = m_request.rate = m_state.rate;
+ return;
+ }
+ }
+ if (m_pendingState != NoPending) {
+ m_request.rate = rate;
+ m_request.isThin = isThin;
+ // Remember the current transport state (play, paused, etc), so that we
+ // can restore it after the rate change, if necessary. However, if
+ // anothercommand is already pending, that one takes precedent.
+ if (m_request.command == CmdNone)
+ m_request.setCommand(m_state.command);
+ } else {
+ //No pending operation. Commit the new rate.
+ commitRateChange(rate, isThin);
+ }
+}
+
+void MFPlayerSession::commitRateChange(qreal rate, BOOL isThin)
+{
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "commitRateChange";
+#endif
+ Q_ASSERT(m_pendingState == NoPending);
+ MFTIME hnsSystemTime = 0;
+ MFTIME hnsClockTime = 0;
+ Command cmdNow = m_state.command;
+ bool resetPosition = false;
+ // Allowed rate transitions:
+ // Positive <-> negative: Stopped
+ // Negative <-> zero: Stopped
+ // Postive <-> zero: Paused or stopped
+ if ((rate > 0 && m_state.rate <= 0) || (rate < 0 && m_state.rate >= 0)) {
+ if (cmdNow == CmdStart) {
+ // Get the current clock position. This will be the restart time.
+ m_presentationClock->GetCorrelatedTime(0, &hnsClockTime, &hnsSystemTime);
+ Q_ASSERT(hnsSystemTime != 0);
+
+ if (rate < 0 || m_state.rate < 0)
+ m_request.setCommand(CmdSeekResume);
+ else if (isThin || m_state.isThin)
+ m_request.setCommand(CmdStartAndSeek);
+ else
+ m_request.setCommand(CmdStart);
+
+ // We need to stop only when dealing with negative rates
+ if (rate >= 0 && m_state.rate >= 0)
+ pause();
+ else
+ stop();
+
+ // If we deal with negative rates, we stopped the session and consequently
+ // reset the position to zero. We then need to resume to the current position.
+ m_request.start = hnsClockTime / 10000;
+ } else if (cmdNow == CmdPause) {
+ if (rate < 0 || m_state.rate < 0) {
+ // The current state is paused.
+ // For this rate change, the session must be stopped. However, the
+ // session cannot transition back from stopped to paused.
+ // Therefore, this rate transition is not supported while paused.
+ qWarning() << "Unable to change rate from positive to negative or vice versa in paused state";
+ rate = m_state.rate;
+ isThin = m_state.isThin;
+ goto done;
+ }
+
+ // This happens when resuming playback after scrubbing in pause mode.
+ // This transition requires the session to be paused. Even though our
+ // internal state is set to paused, the session might not be so we need
+ // to enforce it
+ if (rate > 0 && m_state.rate == 0) {
+ m_state.setCommand(CmdNone);
+ pause();
+ }
+ }
+ } else if (rate == 0 && m_state.rate > 0) {
+ if (cmdNow != CmdPause) {
+ // Transition to paused.
+ // This transisition requires the paused state.
+ // Pause and set the rate.
+ pause();
+
+ // Request: Switch back to current state.
+ m_request.setCommand(cmdNow);
+ }
+ } else if (rate == 0 && m_state.rate < 0) {
+ // Changing rate from negative to zero requires to stop the session
+ m_presentationClock->GetCorrelatedTime(0, &hnsClockTime, &hnsSystemTime);
+
+ m_request.setCommand(CmdSeekResume);
+
+ stop();
+
+ // Resume to the current position (stop() will reset the position to 0)
+ m_request.start = hnsClockTime / 10000;
+ } else if (!isThin && m_state.isThin) {
+ if (cmdNow == CmdStart) {
+ // When thinning, only key frames are read and presented. Going back
+ // to normal playback requires to reset the current position to force
+ // the pipeline to decode the actual frame at the current position
+ // (which might be earlier than the last decoded key frame)
+ resetPosition = true;
+ } else if (cmdNow == CmdPause) {
+ // If paused, don't reset the position until we resume, otherwise
+ // a new frame will be rendered
+ m_presentationClock->GetCorrelatedTime(0, &hnsClockTime, &hnsSystemTime);
+ m_request.setCommand(CmdSeekResume);
+ m_request.start = hnsClockTime / 10000;
+ }
+
+ }
+
+ // Set the rate.
+ if (FAILED(m_rateControl->SetRate(isThin, rate))) {
+ qWarning() << "failed to set playbackrate = " << rate;
+ rate = m_state.rate;
+ isThin = m_state.isThin;
+ goto done;
+ }
+
+ if (resetPosition) {
+ m_presentationClock->GetCorrelatedTime(0, &hnsClockTime, &hnsSystemTime);
+ setPosition(hnsClockTime / 10000);
+ }
+
+done:
+ // Adjust our current rate and requested rate.
+ m_pendingRate = m_request.rate = m_state.rate = rate;
+ if (rate != 0)
+ m_state.isThin = isThin;
+ playbackRateChanged(rate);
+}
+
+void MFPlayerSession::scrub(bool enableScrub)
+{
+ if (m_scrubbing == enableScrub)
+ return;
+
+ m_scrubbing = enableScrub;
+
+ if (!canScrub()) {
+ if (!enableScrub)
+ m_pendingRate = m_restoreRate;
+ return;
+ }
+
+ if (enableScrub) {
+ // Enter scrubbing mode. Cache the rate.
+ m_restoreRate = m_request.rate;
+ setPlaybackRateInternal(0.0f);
+ } else {
+ // Leaving scrubbing mode. Restore the old rate.
+ setPlaybackRateInternal(m_restoreRate);
+ }
+}
+
+void MFPlayerSession::setVolume(float volume)
+{
+ if (m_volume == volume)
+ return;
+ m_volume = volume;
+
+ if (!m_muted)
+ setVolumeInternal(volume);
+}
+
+void MFPlayerSession::setMuted(bool muted)
+{
+ if (m_muted == muted)
+ return;
+ m_muted = muted;
+
+ setVolumeInternal(muted ? 0 : m_volume);
+}
+
+void MFPlayerSession::setVolumeInternal(float volume)
+{
+ if (m_volumeControl) {
+ quint32 channelCount = 0;
+ if (!SUCCEEDED(m_volumeControl->GetChannelCount(&channelCount))
+ || channelCount == 0)
+ return;
+
+ for (quint32 i = 0; i < channelCount; ++i)
+ m_volumeControl->SetChannelVolume(i, volume);
+ }
+}
+
+float MFPlayerSession::bufferProgress()
+{
+ if (!m_netsourceStatistics)
+ return 0;
+ PROPVARIANT var;
+ PropVariantInit(&var);
+ PROPERTYKEY key;
+ key.fmtid = MFNETSOURCE_STATISTICS;
+ key.pid = MFNETSOURCE_BUFFERPROGRESS_ID;
+ int progress = -1;
+ // GetValue returns S_FALSE if the property is not available, which has
+ // a value > 0. We therefore can't use the SUCCEEDED macro here.
+ if (m_netsourceStatistics->GetValue(key, &var) == S_OK) {
+ progress = var.lVal;
+ PropVariantClear(&var);
+ }
+
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "bufferProgress: progress = " << progress;
+#endif
+
+ return progress/100.;
+}
+
+QMediaTimeRange MFPlayerSession::availablePlaybackRanges()
+{
+ // defaults to the whole media
+ qint64 start = 0;
+ qint64 end = qint64(m_duration / 10000);
+
+ if (m_netsourceStatistics) {
+ PROPVARIANT var;
+ PropVariantInit(&var);
+ PROPERTYKEY key;
+ key.fmtid = MFNETSOURCE_STATISTICS;
+ key.pid = MFNETSOURCE_SEEKRANGESTART_ID;
+ // GetValue returns S_FALSE if the property is not available, which has
+ // a value > 0. We therefore can't use the SUCCEEDED macro here.
+ if (m_netsourceStatistics->GetValue(key, &var) == S_OK) {
+ start = qint64(var.uhVal.QuadPart / 10000);
+ PropVariantClear(&var);
+ PropVariantInit(&var);
+ key.pid = MFNETSOURCE_SEEKRANGEEND_ID;
+ if (m_netsourceStatistics->GetValue(key, &var) == S_OK) {
+ end = qint64(var.uhVal.QuadPart / 10000);
+ PropVariantClear(&var);
+ }
+ }
+ }
+
+ return QMediaTimeRange(start, end);
+}
+
+HRESULT MFPlayerSession::QueryInterface(REFIID riid, void** ppvObject)
+{
+ if (!ppvObject)
+ return E_POINTER;
+ if (riid == IID_IMFAsyncCallback) {
+ *ppvObject = static_cast<IMFAsyncCallback*>(this);
+ } else if (riid == IID_IUnknown) {
+ *ppvObject = static_cast<IUnknown*>(this);
+ } else {
+ *ppvObject = NULL;
+ return E_NOINTERFACE;
+ }
+ return S_OK;
+}
+
+ULONG MFPlayerSession::AddRef(void)
+{
+ return InterlockedIncrement(&m_cRef);
+}
+
+ULONG MFPlayerSession::Release(void)
+{
+ LONG cRef = InterlockedDecrement(&m_cRef);
+ if (cRef == 0) {
+ deleteLater();
+
+ // In rare cases the session has queued events to be run between deleteLater and deleting,
+ // so we set the parent control to nullptr in order to prevent crashes in the cases.
+ m_playerControl = nullptr;
+ }
+ return cRef;
+}
+
+HRESULT MFPlayerSession::Invoke(IMFAsyncResult *pResult)
+{
+ if (pResult->GetStateNoAddRef() != m_session.Get())
+ return S_OK;
+
+ ComPtr<IMFMediaEvent> pEvent;
+ // Get the event from the event queue.
+ HRESULT hr = m_session->EndGetEvent(pResult, &pEvent);
+ if (FAILED(hr)) {
+ return S_OK;
+ }
+
+ MediaEventType meType = MEUnknown;
+ hr = pEvent->GetType(&meType);
+ if (FAILED(hr)) {
+ return S_OK;
+ }
+
+ if (meType == MESessionClosed) {
+ SetEvent(m_hCloseEvent.get());
+ return S_OK;
+ } else {
+ hr = m_session->BeginGetEvent(this, m_session.Get());
+ if (FAILED(hr)) {
+ return S_OK;
+ }
+ }
+
+ if (!m_closing) {
+ emit sessionEvent(pEvent);
+ }
+ return S_OK;
+}
+
+void MFPlayerSession::handleSessionEvent(const ComPtr<IMFMediaEvent> &sessionEvent)
+{
+ HRESULT hrStatus = S_OK;
+ HRESULT hr = sessionEvent->GetStatus(&hrStatus);
+ if (FAILED(hr) || !m_session) {
+ return;
+ }
+
+ MediaEventType meType = MEUnknown;
+ hr = sessionEvent->GetType(&meType);
+#ifdef DEBUG_MEDIAFOUNDATION
+ if (FAILED(hrStatus))
+ qDebug() << "handleSessionEvent: MediaEventType = " << meType << "Failed";
+ else
+ qDebug() << "handleSessionEvent: MediaEventType = " << meType;
+#endif
+
+ switch (meType) {
+ case MENonFatalError: {
+ PROPVARIANT var;
+ PropVariantInit(&var);
+ sessionEvent->GetValue(&var);
+ qWarning() << "handleSessionEvent: non fatal error = " << var.ulVal;
+ PropVariantClear(&var);
+ error(QMediaPlayer::ResourceError, tr("Media session non-fatal error."), false);
+ }
+ break;
+ case MESourceUnknown:
+ changeStatus(QMediaPlayer::InvalidMedia);
+ break;
+ case MEError:
+ if (hrStatus == MF_E_ALREADY_INITIALIZED) {
+ // Workaround for a possible WMF issue that causes an error
+ // with some specific videos, which play fine otherwise.
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "handleSessionEvent: ignoring MF_E_ALREADY_INITIALIZED";
+#endif
+ break;
+ }
+ changeStatus(QMediaPlayer::InvalidMedia);
+ qWarning() << "handleSessionEvent: serious error = "
+ << Qt::showbase << Qt::hex << Qt::uppercasedigits << static_cast<quint32>(hrStatus);
+ switch (hrStatus) {
+ case MF_E_NET_READ:
+ error(QMediaPlayer::NetworkError, tr("Error reading from the network."), true);
+ break;
+ case MF_E_NET_WRITE:
+ error(QMediaPlayer::NetworkError, tr("Error writing to the network."), true);
+ break;
+ case NS_E_FIREWALL:
+ error(QMediaPlayer::NetworkError, tr("Network packets might be blocked by a firewall."), true);
+ break;
+ case MF_E_MEDIAPROC_WRONGSTATE:
+ error(QMediaPlayer::ResourceError, tr("Media session state error."), true);
+ break;
+ case MF_E_INVALID_STREAM_DATA:
+ error(QMediaPlayer::ResourceError, tr("Invalid stream data."), true);
+ break;
+ default:
+ error(QMediaPlayer::ResourceError, tr("Media session serious error."), true);
+ break;
+ }
+ break;
+ case MESessionRateChanged:
+ // If the rate change succeeded, we've already got the rate
+ // cached. If it failed, try to get the actual rate.
+ if (FAILED(hrStatus)) {
+ PROPVARIANT var;
+ PropVariantInit(&var);
+ if (SUCCEEDED(sessionEvent->GetValue(&var)) && (var.vt == VT_R4)) {
+ m_state.rate = var.fltVal;
+ }
+ playbackRateChanged(playbackRate());
+ }
+ break;
+ case MESessionScrubSampleComplete :
+ if (m_scrubbing)
+ updatePendingCommands(CmdStart);
+ break;
+ case MESessionStarted:
+ if (m_status == QMediaPlayer::EndOfMedia
+ || m_status == QMediaPlayer::LoadedMedia) {
+ // If the session started, then enough data is buffered to play
+ changeStatus(QMediaPlayer::BufferedMedia);
+ }
+
+ updatePendingCommands(CmdStart);
+ // playback started, we can now set again the procAmpValues if they have been
+ // changed previously (these are lost when loading a new media)
+// if (m_playerService->videoWindowControl()) {
+// m_playerService->videoWindowControl()->applyImageControls();
+// }
+ m_signalPositionChangeTimer.start();
+ break;
+ case MESessionStopped:
+ if (m_status != QMediaPlayer::EndOfMedia) {
+ m_position = 0;
+
+ // Reset to Loaded status unless we are loading a new media
+ // or changing the playback rate to negative values (stop required)
+ if (m_status != QMediaPlayer::LoadingMedia && m_request.command != CmdSeekResume)
+ changeStatus(QMediaPlayer::LoadedMedia);
+ }
+ updatePendingCommands(CmdStop);
+ m_signalPositionChangeTimer.stop();
+ break;
+ case MESessionPaused:
+ m_position = position() * 10000;
+ updatePendingCommands(CmdPause);
+ m_signalPositionChangeTimer.stop();
+ if (m_status == QMediaPlayer::LoadedMedia)
+ setPosition(position());
+ break;
+ case MEReconnectStart:
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "MEReconnectStart" << ((hrStatus == S_OK) ? "OK" : "Failed");
+#endif
+ break;
+ case MEReconnectEnd:
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "MEReconnectEnd" << ((hrStatus == S_OK) ? "OK" : "Failed");
+#endif
+ break;
+ case MESessionTopologySet:
+ if (FAILED(hrStatus)) {
+ changeStatus(QMediaPlayer::InvalidMedia);
+ error(QMediaPlayer::FormatError, tr("Unsupported media, a codec is missing."), true);
+ } else {
+ // Topology is resolved and successfuly set, this happens only after loading a new media.
+ // Make sure we always start the media from the beginning
+ m_lastPosition = -1;
+ m_position = 0;
+ positionChanged(0);
+ changeStatus(QMediaPlayer::LoadedMedia);
+ }
+ break;
+ }
+
+ if (FAILED(hrStatus)) {
+ return;
+ }
+
+ switch (meType) {
+ case MEBufferingStarted:
+ changeStatus(QMediaPlayer::StalledMedia);
+ bufferProgressChanged(bufferProgress());
+ break;
+ case MEBufferingStopped:
+ changeStatus(QMediaPlayer::BufferedMedia);
+ bufferProgressChanged(bufferProgress());
+ break;
+ case MESessionEnded:
+ m_pendingState = NoPending;
+ m_state.command = CmdStop;
+ m_state.prevCmd = CmdNone;
+ m_request.command = CmdNone;
+ m_request.prevCmd = CmdNone;
+
+ //keep reporting the final position after end of media
+ m_position = qint64(m_duration);
+ positionChanged(position());
+
+ changeStatus(QMediaPlayer::EndOfMedia);
+ break;
+ case MEEndOfPresentationSegment:
+ break;
+ case MESessionTopologyStatus: {
+ UINT32 status;
+ if (SUCCEEDED(sessionEvent->GetUINT32(MF_EVENT_TOPOLOGY_STATUS, &status))) {
+ if (status == MF_TOPOSTATUS_READY) {
+ ComPtr<IMFClock> clock;
+ if (SUCCEEDED(m_session->GetClock(&clock))) {
+ clock->QueryInterface(IID_IMFPresentationClock, &m_presentationClock);
+ }
+
+ if (SUCCEEDED(MFGetService(m_session.Get(), MF_RATE_CONTROL_SERVICE,
+ IID_PPV_ARGS(&m_rateControl)))) {
+ if (SUCCEEDED(MFGetService(m_session.Get(), MF_RATE_CONTROL_SERVICE,
+ IID_PPV_ARGS(&m_rateSupport)))) {
+ if (SUCCEEDED(m_rateSupport->IsRateSupported(TRUE, 0, NULL)))
+ m_canScrub = true;
+ }
+ BOOL isThin = FALSE;
+ float rate = 1;
+ if (SUCCEEDED(m_rateControl->GetRate(&isThin, &rate))) {
+ if (m_pendingRate != rate) {
+ m_state.rate = m_request.rate = rate;
+ setPlaybackRate(m_pendingRate);
+ }
+ }
+ }
+ MFGetService(m_session.Get(), MFNETSOURCE_STATISTICS_SERVICE,
+ IID_PPV_ARGS(&m_netsourceStatistics));
+
+ if (SUCCEEDED(MFGetService(m_session.Get(), MR_STREAM_VOLUME_SERVICE,
+ IID_PPV_ARGS(&m_volumeControl))))
+ setVolumeInternal(m_muted ? 0 : m_volume);
+
+ m_updatingTopology = false;
+ stop();
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void MFPlayerSession::updatePendingCommands(Command command)
+{
+ positionChanged(position());
+ if (m_state.command != command || m_pendingState == NoPending)
+ return;
+
+ // Seek while paused completed
+ if (m_pendingState == SeekPending && m_state.prevCmd == CmdPause) {
+ m_pendingState = NoPending;
+ // A seek operation actually restarts playback. If scrubbing is possible, playback rate
+ // is set to 0.0 at this point and we just need to reset the current state to Pause.
+ // If scrubbing is not possible, the playback rate was not changed and we explicitly need
+ // to re-pause playback.
+ if (!canScrub())
+ pause();
+ else
+ m_state.setCommand(CmdPause);
+ }
+
+ m_pendingState = NoPending;
+
+ //First look for rate changes.
+ if (m_request.rate != m_state.rate) {
+ commitRateChange(m_request.rate, m_request.isThin);
+ }
+
+ // Now look for new requests.
+ if (m_pendingState == NoPending) {
+ switch (m_request.command) {
+ case CmdStart:
+ start();
+ break;
+ case CmdPause:
+ pause();
+ break;
+ case CmdStop:
+ stop();
+ break;
+ case CmdSeek:
+ case CmdSeekResume:
+ setPositionInternal(m_request.start, m_request.command);
+ break;
+ case CmdStartAndSeek:
+ start();
+ setPositionInternal(m_request.start, m_request.command);
+ break;
+ default:
+ break;
+ }
+ m_request.setCommand(CmdNone);
+ }
+
+}
+
+bool MFPlayerSession::canScrub() const
+{
+ return m_canScrub && m_rateSupport && m_rateControl;
+}
+
+void MFPlayerSession::clear()
+{
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "MFPlayerSession::clear";
+#endif
+ m_mediaTypes = 0;
+ m_canScrub = false;
+
+ m_pendingState = NoPending;
+ m_state.command = CmdStop;
+ m_state.prevCmd = CmdNone;
+ m_request.command = CmdNone;
+ m_request.prevCmd = CmdNone;
+
+ for (int i = 0; i < QPlatformMediaPlayer::NTrackTypes; ++i) {
+ m_trackInfo[i].metaData.clear();
+ m_trackInfo[i].nativeIndexes.clear();
+ m_trackInfo[i].currentIndex = -1;
+ m_trackInfo[i].sourceNodeId = TOPOID(-1);
+ m_trackInfo[i].outputNodeId = TOPOID(-1);
+ m_trackInfo[i].format = GUID_NULL;
+ }
+
+ if (!m_metaData.isEmpty()) {
+ m_metaData.clear();
+ metaDataChanged();
+ }
+
+ m_presentationClock.Reset();
+ m_rateControl.Reset();
+ m_rateSupport.Reset();
+ m_volumeControl.Reset();
+ m_netsourceStatistics.Reset();
+}
+
+void MFPlayerSession::setAudioOutput(QPlatformAudioOutput *device)
+{
+ if (m_audioOutput == device)
+ return;
+
+ if (m_audioOutput)
+ m_audioOutput->q->disconnect(this);
+
+ m_audioOutput = device;
+ if (m_audioOutput) {
+ setMuted(m_audioOutput->q->isMuted());
+ setVolume(m_audioOutput->q->volume());
+ updateOutputRouting();
+ connect(m_audioOutput->q, &QAudioOutput::deviceChanged, this, &MFPlayerSession::updateOutputRouting);
+ connect(m_audioOutput->q, &QAudioOutput::volumeChanged, this, &MFPlayerSession::setVolume);
+ connect(m_audioOutput->q, &QAudioOutput::mutedChanged, this, &MFPlayerSession::setMuted);
+ }
+}
+
+void MFPlayerSession::updateOutputRouting()
+{
+ int currentAudioTrack = m_trackInfo[QPlatformMediaPlayer::AudioStream].currentIndex;
+ if (currentAudioTrack > -1)
+ setActiveTrack(QPlatformMediaPlayer::AudioStream, currentAudioTrack);
+}
+
+void MFPlayerSession::setVideoSink(QVideoSink *sink)
+{
+ m_videoRendererControl->setSink(sink);
+}
+
+void MFPlayerSession::setActiveTrack(QPlatformMediaPlayer::TrackType type, int index)
+{
+ if (!m_session)
+ return;
+
+ // Only audio track selection is currently supported.
+ if (type != QPlatformMediaPlayer::AudioStream)
+ return;
+
+ const auto &nativeIndexes = m_trackInfo[type].nativeIndexes;
+
+ if (index < -1 || index >= nativeIndexes.count())
+ return;
+
+ // Updating the topology fails if there is a HEVC video stream,
+ // which causes other issues. Ignoring the change, for now.
+ if (m_trackInfo[QPlatformMediaPlayer::VideoStream].format == MFVideoFormat_HEVC)
+ return;
+
+ ComPtr<IMFTopology> topology;
+
+ if (SUCCEEDED(m_session->GetFullTopology(QMM_MFSESSION_GETFULLTOPOLOGY_CURRENT, 0, &topology))) {
+
+ m_restorePosition = position() * 10000;
+
+ if (m_state.command == CmdStart)
+ stop();
+
+ if (m_trackInfo[type].outputNodeId != TOPOID(-1)) {
+ ComPtr<IMFTopologyNode> node;
+ if (SUCCEEDED(topology->GetNodeByID(m_trackInfo[type].outputNodeId, &node))) {
+ topology->RemoveNode(node.Get());
+ m_trackInfo[type].outputNodeId = TOPOID(-1);
+ }
+ }
+ if (m_trackInfo[type].sourceNodeId != TOPOID(-1)) {
+ ComPtr<IMFTopologyNode> node;
+ if (SUCCEEDED(topology->GetNodeByID(m_trackInfo[type].sourceNodeId, &node))) {
+ topology->RemoveNode(node.Get());
+ m_trackInfo[type].sourceNodeId = TOPOID(-1);
+ }
+ }
+
+ IMFMediaSource *mediaSource = m_sourceResolver->mediaSource();
+
+ ComPtr<IMFPresentationDescriptor> sourcePD;
+ if (SUCCEEDED(mediaSource->CreatePresentationDescriptor(&sourcePD))) {
+
+ if (m_trackInfo[type].currentIndex >= 0 && m_trackInfo[type].currentIndex < nativeIndexes.count())
+ sourcePD->DeselectStream(nativeIndexes.at(m_trackInfo[type].currentIndex));
+
+ m_trackInfo[type].currentIndex = index;
+
+ if (index == -1) {
+ m_session->SetTopology(MFSESSION_SETTOPOLOGY_IMMEDIATE, topology.Get());
+ } else {
+ int nativeIndex = nativeIndexes.at(index);
+ sourcePD->SelectStream(nativeIndex);
+
+ ComPtr<IMFStreamDescriptor> streamDesc;
+ BOOL selected = FALSE;
+
+ if (SUCCEEDED(sourcePD->GetStreamDescriptorByIndex(nativeIndex, &selected, &streamDesc))) {
+ ComPtr<IMFTopologyNode> sourceNode = addSourceNode(
+ topology.Get(), mediaSource, sourcePD.Get(), streamDesc.Get());
+ if (sourceNode) {
+ ComPtr<IMFTopologyNode> outputNode =
+ addOutputNode(MFPlayerSession::Audio, topology.Get(), 0);
+ if (outputNode) {
+ if (SUCCEEDED(sourceNode->ConnectOutput(0, outputNode.Get(), 0))) {
+ sourceNode->GetTopoNodeID(&m_trackInfo[type].sourceNodeId);
+ outputNode->GetTopoNodeID(&m_trackInfo[type].outputNodeId);
+ m_session->SetTopology(MFSESSION_SETTOPOLOGY_IMMEDIATE,
+ topology.Get());
+ }
+ }
+ }
+ }
+ }
+ m_updatingTopology = true;
+ }
+ }
+}
+
+int MFPlayerSession::activeTrack(QPlatformMediaPlayer::TrackType type)
+{
+ if (type < 0 || type >= QPlatformMediaPlayer::NTrackTypes)
+ return -1;
+ return m_trackInfo[type].currentIndex;
+}
+
+int MFPlayerSession::trackCount(QPlatformMediaPlayer::TrackType type)
+{
+ if (type < 0 || type >= QPlatformMediaPlayer::NTrackTypes)
+ return -1;
+ return m_trackInfo[type].metaData.count();
+}
+
+QMediaMetaData MFPlayerSession::trackMetaData(QPlatformMediaPlayer::TrackType type, int trackNumber)
+{
+ if (type < 0 || type >= QPlatformMediaPlayer::NTrackTypes)
+ return {};
+
+ if (trackNumber < 0 || trackNumber >= m_trackInfo[type].metaData.count())
+ return {};
+
+ return m_trackInfo[type].metaData.at(trackNumber);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_mfplayersession_p.cpp"
diff --git a/src/plugins/multimedia/windows/player/mfplayersession_p.h b/src/plugins/multimedia/windows/player/mfplayersession_p.h
new file mode 100644
index 000000000..50141a7fb
--- /dev/null
+++ b/src/plugins/multimedia/windows/player/mfplayersession_p.h
@@ -0,0 +1,240 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef MFPLAYERSESSION_H
+#define MFPLAYERSESSION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <mfapi.h>
+#include <mfidl.h>
+
+#include "qmediaplayer.h"
+#include "qmediatimerange.h"
+
+#include <QtCore/qcoreevent.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qurl.h>
+#include <QtCore/qwaitcondition.h>
+#include <QtMultimedia/qaudioformat.h>
+#include <QtMultimedia/qvideoframeformat.h>
+#include <qaudiodevice.h>
+#include <qtimer.h>
+#include "mfplayercontrol_p.h"
+#include <private/qcomptr_p.h>
+#include <evrhelpers_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QUrl;
+
+class SourceResolver;
+class MFVideoRendererControl;
+class MFPlayerControl;
+class MFPlayerService;
+class AudioSampleGrabberCallback;
+class MFTransform;
+
+class MFPlayerSession : public QObject, public IMFAsyncCallback
+{
+ Q_OBJECT
+ friend class SourceResolver;
+public:
+ MFPlayerSession(MFPlayerControl *playerControl = 0);
+
+ STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override;
+
+ STDMETHODIMP_(ULONG) AddRef(void) override;
+
+ STDMETHODIMP_(ULONG) Release(void) override;
+
+ STDMETHODIMP Invoke(IMFAsyncResult *pResult) override;
+
+ STDMETHODIMP GetParameters(DWORD *pdwFlags, DWORD *pdwQueue) override
+ {
+ Q_UNUSED(pdwFlags);
+ Q_UNUSED(pdwQueue);
+ return E_NOTIMPL;
+ }
+
+ void load(const QUrl &media, QIODevice *stream);
+ void stop(bool immediate = false);
+ void start();
+ void pause();
+
+ QMediaPlayer::MediaStatus status() const;
+ qint64 position();
+ void setPosition(qint64 position);
+ qreal playbackRate() const;
+ void setPlaybackRate(qreal rate);
+ float bufferProgress();
+ QMediaTimeRange availablePlaybackRanges();
+
+ void changeStatus(QMediaPlayer::MediaStatus newStatus);
+
+ void close();
+
+ void setAudioOutput(QPlatformAudioOutput *device);
+
+ QMediaMetaData metaData() const { return m_metaData; }
+
+ void setVideoSink(QVideoSink *sink);
+
+ void setActiveTrack(QPlatformMediaPlayer::TrackType type, int index);
+ int activeTrack(QPlatformMediaPlayer::TrackType type);
+ int trackCount(QPlatformMediaPlayer::TrackType);
+ QMediaMetaData trackMetaData(QPlatformMediaPlayer::TrackType type, int trackNumber);
+
+ void setPlayerControl(MFPlayerControl *playerControl) { m_playerControl = playerControl; }
+
+ void statusChanged() { if (m_playerControl) m_playerControl->handleStatusChanged(); }
+ void tracksChanged() { if (m_playerControl) m_playerControl->handleTracksChanged(); }
+ void audioAvailable() { if (m_playerControl) m_playerControl->handleAudioAvailable(); }
+ void videoAvailable() { if (m_playerControl) m_playerControl->handleVideoAvailable(); }
+ void durationUpdate(qint64 duration) { if (m_playerControl) m_playerControl->handleDurationUpdate(duration); }
+ void seekableUpdate(bool seekable) { if (m_playerControl) m_playerControl->handleSeekableUpdate(seekable); }
+ void error(QMediaPlayer::Error error, QString errorString, bool isFatal) { if (m_playerControl) m_playerControl->handleError(error, errorString, isFatal); }
+ void playbackRateChanged(qreal rate) { if (m_playerControl) m_playerControl->playbackRateChanged(rate); }
+ void bufferProgressChanged(float percentFilled) { if (m_playerControl) m_playerControl->bufferProgressChanged(percentFilled); }
+ void metaDataChanged() { if (m_playerControl) m_playerControl->metaDataChanged(); }
+ void positionChanged(qint64 position) { if (m_playerControl) m_playerControl->positionChanged(position); }
+
+public Q_SLOTS:
+ void setVolume(float volume);
+ void setMuted(bool muted);
+ void updateOutputRouting();
+
+Q_SIGNALS:
+ void sessionEvent(const ComPtr<IMFMediaEvent> &sessionEvent);
+
+private Q_SLOTS:
+ void handleMediaSourceReady();
+ void handleSessionEvent(const ComPtr<IMFMediaEvent> &sessionEvent);
+ void handleSourceError(long hr);
+ void timeout();
+
+private:
+ long m_cRef;
+ MFPlayerControl *m_playerControl = nullptr;
+ MFVideoRendererControl *m_videoRendererControl = nullptr;
+ ComPtr<IMFMediaSession> m_session;
+ ComPtr<IMFPresentationClock> m_presentationClock;
+ ComPtr<IMFRateControl> m_rateControl;
+ ComPtr<IMFRateSupport> m_rateSupport;
+ ComPtr<IMFAudioStreamVolume> m_volumeControl;
+ ComPtr<IPropertyStore> m_netsourceStatistics;
+ qint64 m_position = 0;
+ qint64 m_restorePosition = -1;
+ qint64 m_timeCounter = 0;
+ UINT64 m_duration = 0;
+ bool m_updatingTopology = false;
+ bool m_updateRoutingOnStart = false;
+
+ enum Command
+ {
+ CmdNone = 0,
+ CmdStop,
+ CmdStart,
+ CmdPause,
+ CmdSeek,
+ CmdSeekResume,
+ CmdStartAndSeek
+ };
+
+ void clear();
+ void setPositionInternal(qint64 position, Command requestCmd);
+ void setPlaybackRateInternal(qreal rate);
+ void commitRateChange(qreal rate, BOOL isThin);
+ bool canScrub() const;
+ void scrub(bool enableScrub);
+ bool m_scrubbing;
+ float m_restoreRate;
+
+ ComPtr<SourceResolver> m_sourceResolver;
+ EventHandle m_hCloseEvent;
+ bool m_closing;
+
+ enum MediaType
+ {
+ Unknown = 0,
+ Audio = 1,
+ Video = 2,
+ };
+ DWORD m_mediaTypes;
+
+ enum PendingState
+ {
+ NoPending = 0,
+ CmdPending,
+ SeekPending,
+ };
+
+ struct SeekState
+ {
+ void setCommand(Command cmd) {
+ prevCmd = command;
+ command = cmd;
+ }
+ Command command;
+ Command prevCmd;
+ float rate; // Playback rate
+ BOOL isThin; // Thinned playback?
+ qint64 start; // Start position
+ };
+ SeekState m_state; // Current nominal state.
+ SeekState m_request; // Pending request.
+ PendingState m_pendingState;
+ float m_pendingRate;
+ void updatePendingCommands(Command command);
+
+ struct TrackInfo
+ {
+ QList<QMediaMetaData> metaData;
+ QList<int> nativeIndexes;
+ int currentIndex = -1;
+ TOPOID sourceNodeId = -1;
+ TOPOID outputNodeId = -1;
+ GUID format = GUID_NULL;
+ };
+ TrackInfo m_trackInfo[QPlatformMediaPlayer::NTrackTypes];
+
+ QMediaPlayer::MediaStatus m_status;
+ bool m_canScrub;
+ float m_volume = 1.;
+ bool m_muted = false;
+
+ QPlatformAudioOutput *m_audioOutput = nullptr;
+ QMediaMetaData m_metaData;
+
+ void setVolumeInternal(float volume);
+
+ bool createSession();
+ void setupPlaybackTopology(IMFMediaSource *source, IMFPresentationDescriptor *sourcePD);
+ bool getStreamInfo(IMFStreamDescriptor *stream, MFPlayerSession::MediaType *type, QString *name, QString *language, GUID *format) const;
+ ComPtr<IMFTopologyNode> addSourceNode(IMFTopology *topology, IMFMediaSource *source,
+ IMFPresentationDescriptor *presentationDesc,
+ IMFStreamDescriptor *streamDesc);
+ ComPtr<IMFTopologyNode> addOutputNode(MediaType mediaType, IMFTopology *topology, DWORD sinkID);
+
+ QAudioFormat audioFormatForMFMediaType(IMFMediaType *mediaType) const;
+
+ ComPtr<IMFTopology> insertMFT(const ComPtr<IMFTopology> &topology, TOPOID outputNodeId);
+ bool insertResizer(IMFTopology *topology);
+ void insertColorConverter(IMFTopology *topology, TOPOID outputNodeId);
+
+ QTimer m_signalPositionChangeTimer;
+ qint64 m_lastPosition = -1;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/windows/player/mfvideorenderercontrol.cpp b/src/plugins/multimedia/windows/player/mfvideorenderercontrol.cpp
new file mode 100644
index 000000000..7c79c3a8a
--- /dev/null
+++ b/src/plugins/multimedia/windows/player/mfvideorenderercontrol.cpp
@@ -0,0 +1,152 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "mfvideorenderercontrol_p.h"
+#include "mfactivate_p.h"
+
+#include "evrcustompresenter_p.h"
+
+#include <private/qplatformvideosink_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class EVRCustomPresenterActivate : public MFAbstractActivate
+{
+public:
+ EVRCustomPresenterActivate(QVideoSink *sink);
+
+ STDMETHODIMP ActivateObject(REFIID riid, void **ppv) override;
+ STDMETHODIMP ShutdownObject() override;
+ STDMETHODIMP DetachObject() override;
+
+ void setSink(QVideoSink *sink);
+ void setCropRect(QRect cropRect);
+
+private:
+ // Destructor is not public. Caller should call Release.
+ ~EVRCustomPresenterActivate() override { }
+
+ EVRCustomPresenter *m_presenter;
+ QVideoSink *m_videoSink;
+ QRect m_cropRect;
+ QMutex m_mutex;
+};
+
+
+MFVideoRendererControl::MFVideoRendererControl(QObject *parent)
+ : QObject(parent)
+{
+}
+
+MFVideoRendererControl::~MFVideoRendererControl()
+{
+ releaseActivate();
+}
+
+void MFVideoRendererControl::releaseActivate()
+{
+ if (m_sink)
+ m_sink->platformVideoSink()->setVideoFrame(QVideoFrame());
+
+ if (m_presenterActivate) {
+ m_presenterActivate->ShutdownObject();
+ m_presenterActivate->Release();
+ m_presenterActivate = NULL;
+ }
+
+ if (m_currentActivate) {
+ m_currentActivate->ShutdownObject();
+ m_currentActivate->Release();
+ }
+ m_currentActivate = NULL;
+}
+
+void MFVideoRendererControl::setSink(QVideoSink *sink)
+{
+ m_sink = sink;
+
+ if (m_presenterActivate)
+ m_presenterActivate->setSink(m_sink);
+}
+
+void MFVideoRendererControl::setCropRect(const QRect &cropRect)
+{
+ if (m_presenterActivate)
+ m_presenterActivate->setCropRect(cropRect);
+}
+
+IMFActivate* MFVideoRendererControl::createActivate()
+{
+ releaseActivate();
+
+ if (m_sink) {
+ // Create the EVR media sink, but replace the presenter with our own
+ if (SUCCEEDED(MFCreateVideoRendererActivate(::GetShellWindow(), &m_currentActivate))) {
+ m_presenterActivate = new EVRCustomPresenterActivate(m_sink);
+ m_currentActivate->SetUnknown(MF_ACTIVATE_CUSTOM_VIDEO_PRESENTER_ACTIVATE, m_presenterActivate);
+ }
+ }
+
+ return m_currentActivate;
+}
+
+EVRCustomPresenterActivate::EVRCustomPresenterActivate(QVideoSink *sink)
+ : MFAbstractActivate()
+ , m_presenter(0)
+ , m_videoSink(sink)
+{ }
+
+HRESULT EVRCustomPresenterActivate::ActivateObject(REFIID riid, void **ppv)
+{
+ if (!ppv)
+ return E_INVALIDARG;
+ QMutexLocker locker(&m_mutex);
+ if (!m_presenter) {
+ m_presenter = new EVRCustomPresenter(m_videoSink);
+ m_presenter->setCropRect(m_cropRect);
+ }
+ return m_presenter->QueryInterface(riid, ppv);
+}
+
+HRESULT EVRCustomPresenterActivate::ShutdownObject()
+{
+ // The presenter does not implement IMFShutdown so
+ // this function is the same as DetachObject()
+ return DetachObject();
+}
+
+HRESULT EVRCustomPresenterActivate::DetachObject()
+{
+ QMutexLocker locker(&m_mutex);
+ if (m_presenter) {
+ m_presenter->Release();
+ m_presenter = 0;
+ }
+ return S_OK;
+}
+
+void EVRCustomPresenterActivate::setSink(QVideoSink *sink)
+{
+ QMutexLocker locker(&m_mutex);
+ if (m_videoSink == sink)
+ return;
+
+ m_videoSink = sink;
+
+ if (m_presenter)
+ m_presenter->setSink(sink);
+}
+
+void EVRCustomPresenterActivate::setCropRect(QRect cropRect)
+{
+ QMutexLocker locker(&m_mutex);
+ if (m_cropRect == cropRect)
+ return;
+
+ m_cropRect = cropRect;
+
+ if (m_presenter)
+ m_presenter->setCropRect(cropRect);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/windows/player/mfvideorenderercontrol_p.h b/src/plugins/multimedia/windows/player/mfvideorenderercontrol_p.h
new file mode 100644
index 000000000..ed5195240
--- /dev/null
+++ b/src/plugins/multimedia/windows/player/mfvideorenderercontrol_p.h
@@ -0,0 +1,47 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef MFVIDEORENDERERCONTROL_H
+#define MFVIDEORENDERERCONTROL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qobject.h>
+#include <qpointer.h>
+#include <qrect.h>
+#include <mfobjects.h>
+
+QT_BEGIN_NAMESPACE
+class EVRCustomPresenterActivate;
+class QVideoSink;
+
+class MFVideoRendererControl : public QObject
+{
+public:
+ MFVideoRendererControl(QObject *parent = 0);
+ ~MFVideoRendererControl();
+
+ void setSink(QVideoSink *surface);
+ void setCropRect(const QRect &cropRect);
+
+ IMFActivate* createActivate();
+ void releaseActivate();
+
+private:
+ QPointer<QVideoSink> m_sink;
+ IMFActivate *m_currentActivate = nullptr;
+ EVRCustomPresenterActivate *m_presenterActivate = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/windows/qwindowsformatinfo.cpp b/src/plugins/multimedia/windows/qwindowsformatinfo.cpp
new file mode 100644
index 000000000..6ef1f7f7f
--- /dev/null
+++ b/src/plugins/multimedia/windows/qwindowsformatinfo.cpp
@@ -0,0 +1,187 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsformatinfo_p.h"
+
+#include <mfapi.h>
+#include <mftransform.h>
+#include <private/qcomptr_p.h>
+#include <private/qwindowsmultimediautils_p.h>
+#include <private/qcomtaskresource_p.h>
+
+#include <QtCore/qlist.h>
+#include <QtCore/qset.h>
+#include <QtCore/qhash.h>
+#include <QtGui/qimagewriter.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+
+template<typename T>
+using CheckedCodecs = QHash<QPair<T, QMediaFormat::ConversionMode>, bool>;
+
+bool isSupportedMFT(const GUID &category, const MFT_REGISTER_TYPE_INFO &type, QMediaFormat::ConversionMode mode)
+{
+ UINT32 count = 0;
+ IMFActivate **activateArrayRaw = nullptr;
+ HRESULT hr = MFTEnumEx(
+ category,
+ MFT_ENUM_FLAG_ALL,
+ (mode == QMediaFormat::Encode) ? nullptr : &type, // Input type
+ (mode == QMediaFormat::Encode) ? &type : nullptr, // Output type
+ &activateArrayRaw,
+ &count
+ );
+
+ if (FAILED(hr))
+ return false;
+
+ QComTaskResource<IMFActivate *[], QComDeleter> activateArray(activateArrayRaw, count);
+ for (UINT32 i = 0; i < count; ++i) {
+ ComPtr<IMFTransform> transform;
+ hr = activateArray[i]->ActivateObject(IID_PPV_ARGS(transform.GetAddressOf()));
+ if (SUCCEEDED(hr))
+ return true;
+ }
+
+ return false;
+}
+
+bool isSupportedCodec(QMediaFormat::AudioCodec codec, QMediaFormat::ConversionMode mode)
+{
+ return isSupportedMFT((mode == QMediaFormat::Encode) ? MFT_CATEGORY_AUDIO_ENCODER : MFT_CATEGORY_AUDIO_DECODER,
+ { MFMediaType_Audio, QWindowsMultimediaUtils::audioFormatForCodec(codec) },
+ mode);
+}
+
+bool isSupportedCodec(QMediaFormat::VideoCodec codec, QMediaFormat::ConversionMode mode)
+{
+ return isSupportedMFT((mode == QMediaFormat::Encode) ? MFT_CATEGORY_VIDEO_ENCODER : MFT_CATEGORY_VIDEO_DECODER,
+ { MFMediaType_Video, QWindowsMultimediaUtils::videoFormatForCodec(codec) },
+ mode);
+}
+
+template <typename T>
+bool isSupportedCodec(T codec, QMediaFormat::ConversionMode m, CheckedCodecs<T> &checkedCodecs)
+{
+ if (auto it = checkedCodecs.constFind(qMakePair(codec, m)); it != checkedCodecs.constEnd())
+ return it.value();
+
+ const bool supported = isSupportedCodec(codec, m);
+
+ checkedCodecs.insert(qMakePair(codec, m), supported);
+ return supported;
+}
+
+}
+
+static QList<QImageCapture::FileFormat> getImageFormatList()
+{
+ QList<QImageCapture::FileFormat> list;
+ const auto formats = QImageWriter::supportedImageFormats();
+
+ for (const auto &f : formats) {
+ auto format = QString::fromUtf8(f);
+ if (format.compare(QLatin1String("jpg"), Qt::CaseInsensitive) == 0)
+ list.append(QImageCapture::FileFormat::JPEG);
+ else if (format.compare(QLatin1String("png"), Qt::CaseInsensitive) == 0)
+ list.append(QImageCapture::FileFormat::PNG);
+ else if (format.compare(QLatin1String("webp"), Qt::CaseInsensitive) == 0)
+ list.append(QImageCapture::FileFormat::WebP);
+ else if (format.compare(QLatin1String("tiff"), Qt::CaseInsensitive) == 0)
+ list.append(QImageCapture::FileFormat::Tiff);
+ }
+
+ return list;
+}
+
+QWindowsFormatInfo::QWindowsFormatInfo()
+{
+ const QList<CodecMap> containerTable = {
+ { QMediaFormat::MPEG4,
+ { QMediaFormat::AudioCodec::AAC, QMediaFormat::AudioCodec::MP3, QMediaFormat::AudioCodec::ALAC, QMediaFormat::AudioCodec::AC3, QMediaFormat::AudioCodec::EAC3 },
+ { QMediaFormat::VideoCodec::H264, QMediaFormat::VideoCodec::H265, QMediaFormat::VideoCodec::MotionJPEG } },
+ { QMediaFormat::Matroska,
+ { QMediaFormat::AudioCodec::AAC, QMediaFormat::AudioCodec::MP3, QMediaFormat::AudioCodec::ALAC, QMediaFormat::AudioCodec::AC3, QMediaFormat::AudioCodec::EAC3, QMediaFormat::AudioCodec::FLAC, QMediaFormat::AudioCodec::Vorbis, QMediaFormat::AudioCodec::Opus },
+ { QMediaFormat::VideoCodec::H264, QMediaFormat::VideoCodec::H265, QMediaFormat::VideoCodec::VP8, QMediaFormat::VideoCodec::VP9, QMediaFormat::VideoCodec::MotionJPEG } },
+ { QMediaFormat::WebM,
+ { QMediaFormat::AudioCodec::Vorbis, QMediaFormat::AudioCodec::Opus },
+ { QMediaFormat::VideoCodec::VP8, QMediaFormat::VideoCodec::VP9 } },
+ { QMediaFormat::QuickTime,
+ { QMediaFormat::AudioCodec::AAC, QMediaFormat::AudioCodec::MP3, QMediaFormat::AudioCodec::ALAC, QMediaFormat::AudioCodec::AC3, QMediaFormat::AudioCodec::EAC3 },
+ { QMediaFormat::VideoCodec::H264, QMediaFormat::VideoCodec::H265, QMediaFormat::VideoCodec::MotionJPEG } },
+ { QMediaFormat::AAC,
+ { QMediaFormat::AudioCodec::AAC },
+ {} },
+ { QMediaFormat::MP3,
+ { QMediaFormat::AudioCodec::MP3 },
+ {} },
+ { QMediaFormat::FLAC,
+ { QMediaFormat::AudioCodec::FLAC },
+ {} },
+ { QMediaFormat::Mpeg4Audio,
+ { QMediaFormat::AudioCodec::AAC, QMediaFormat::AudioCodec::MP3, QMediaFormat::AudioCodec::ALAC, QMediaFormat::AudioCodec::AC3, QMediaFormat::AudioCodec::EAC3 },
+ {} },
+ { QMediaFormat::WMA,
+ { QMediaFormat::AudioCodec::WMA },
+ {} },
+ { QMediaFormat::WMV,
+ { QMediaFormat::AudioCodec::WMA },
+ { QMediaFormat::VideoCodec::WMV } }
+ };
+
+ const QSet<QMediaFormat::FileFormat> decoderFormats = {
+ QMediaFormat::MPEG4,
+ QMediaFormat::Matroska,
+ QMediaFormat::WebM,
+ QMediaFormat::QuickTime,
+ QMediaFormat::AAC,
+ QMediaFormat::MP3,
+ QMediaFormat::FLAC,
+ QMediaFormat::Mpeg4Audio,
+ QMediaFormat::WMA,
+ QMediaFormat::WMV,
+ };
+
+ const QSet<QMediaFormat::FileFormat> encoderFormats = {
+ QMediaFormat::MPEG4,
+ QMediaFormat::AAC,
+ QMediaFormat::MP3,
+ QMediaFormat::FLAC,
+ QMediaFormat::Mpeg4Audio,
+ QMediaFormat::WMA,
+ QMediaFormat::WMV,
+ };
+
+ CheckedCodecs<QMediaFormat::AudioCodec> checkedAudioCodecs;
+ CheckedCodecs<QMediaFormat::VideoCodec> checkedVideoCodecs;
+
+ auto ensureCodecs = [&] (CodecMap &codecs, QMediaFormat::ConversionMode mode) {
+ codecs.audio.removeIf([&] (auto codec) { return !isSupportedCodec(codec, mode, checkedAudioCodecs); });
+ codecs.video.removeIf([&] (auto codec) { return !isSupportedCodec(codec, mode, checkedVideoCodecs); });
+ return !codecs.video.empty() || !codecs.audio.empty();
+ };
+
+ for (const auto &codecMap : containerTable) {
+ if (decoderFormats.contains(codecMap.format)) {
+ auto m = codecMap;
+ if (ensureCodecs(m, QMediaFormat::Decode))
+ decoders.append(m);
+ }
+
+ if (encoderFormats.contains(codecMap.format)) {
+ auto m = codecMap;
+ if (ensureCodecs(m, QMediaFormat::Encode))
+ encoders.append(m);
+ }
+ }
+
+ imageFormats = getImageFormatList();
+}
+
+QWindowsFormatInfo::~QWindowsFormatInfo()
+{
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/windows/qwindowsformatinfo_p.h b/src/plugins/multimedia/windows/qwindowsformatinfo_p.h
new file mode 100644
index 000000000..31e6dd986
--- /dev/null
+++ b/src/plugins/multimedia/windows/qwindowsformatinfo_p.h
@@ -0,0 +1,31 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSFORMATSINFO_H
+#define QWINDOWSFORMATSINFO_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaformatinfo_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsFormatInfo : public QPlatformMediaFormatInfo
+{
+public:
+ QWindowsFormatInfo();
+ ~QWindowsFormatInfo();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/windows/qwindowsintegration.cpp b/src/plugins/multimedia/windows/qwindowsintegration.cpp
new file mode 100644
index 000000000..1053f3c95
--- /dev/null
+++ b/src/plugins/multimedia/windows/qwindowsintegration.cpp
@@ -0,0 +1,96 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsintegration_p.h"
+#include <private/qwindowsmediadevices_p.h>
+#include <qwindowsformatinfo_p.h>
+#include <qwindowsmediacapture_p.h>
+#include <qwindowsimagecapture_p.h>
+#include <qwindowscamera_p.h>
+#include <qwindowsmediaencoder_p.h>
+#include <mfplayercontrol_p.h>
+#include <mfaudiodecodercontrol_p.h>
+#include <mfevrvideowindowcontrol_p.h>
+#include <private/qplatformmediaplugin_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsMediaPlugin : public QPlatformMediaPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QPlatformMediaPlugin_iid FILE "windows.json")
+
+public:
+ QWindowsMediaPlugin()
+ : QPlatformMediaPlugin()
+ {}
+
+ QPlatformMediaIntegration* create(const QString &name) override
+ {
+ if (name == u"windows")
+ return new QWindowsMediaIntegration;
+ return nullptr;
+ }
+};
+
+QWindowsMediaIntegration::QWindowsMediaIntegration()
+ : QPlatformMediaIntegration(QLatin1String("windows"))
+{
+ CoInitialize(NULL);
+ MFStartup(MF_VERSION);
+}
+
+QWindowsMediaIntegration::~QWindowsMediaIntegration()
+{
+ MFShutdown();
+ CoUninitialize();
+}
+
+QPlatformMediaFormatInfo *QWindowsMediaIntegration::createFormatInfo()
+{
+ return new QWindowsFormatInfo();
+}
+
+QPlatformVideoDevices *QWindowsMediaIntegration::createVideoDevices()
+{
+ return new QWindowsVideoDevices(this);
+}
+
+QMaybe<QPlatformMediaCaptureSession *> QWindowsMediaIntegration::createCaptureSession()
+{
+ return new QWindowsMediaCaptureService();
+}
+
+QMaybe<QPlatformAudioDecoder *> QWindowsMediaIntegration::createAudioDecoder(QAudioDecoder *decoder)
+{
+ return new MFAudioDecoderControl(decoder);
+}
+
+QMaybe<QPlatformMediaPlayer *> QWindowsMediaIntegration::createPlayer(QMediaPlayer *parent)
+{
+ return new MFPlayerControl(parent);
+}
+
+QMaybe<QPlatformCamera *> QWindowsMediaIntegration::createCamera(QCamera *camera)
+{
+ return new QWindowsCamera(camera);
+}
+
+QMaybe<QPlatformMediaRecorder *> QWindowsMediaIntegration::createRecorder(QMediaRecorder *recorder)
+{
+ return new QWindowsMediaEncoder(recorder);
+}
+
+QMaybe<QPlatformImageCapture *> QWindowsMediaIntegration::createImageCapture(QImageCapture *imageCapture)
+{
+ return new QWindowsImageCapture(imageCapture);
+}
+
+QMaybe<QPlatformVideoSink *> QWindowsMediaIntegration::createVideoSink(QVideoSink *sink)
+{
+ return new MFEvrVideoWindowControl(sink);
+}
+
+QT_END_NAMESPACE
+
+#include "qwindowsintegration.moc"
diff --git a/src/plugins/multimedia/windows/qwindowsintegration_p.h b/src/plugins/multimedia/windows/qwindowsintegration_p.h
new file mode 100644
index 000000000..29498fa42
--- /dev/null
+++ b/src/plugins/multimedia/windows/qwindowsintegration_p.h
@@ -0,0 +1,51 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSINTEGRATION_H
+#define QWINDOWSINTEGRATION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformmediaintegration_p.h>
+#include "qwindowsvideodevices_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsMediaDevices;
+class QWindowsFormatInfo;
+
+class QWindowsMediaIntegration : public QPlatformMediaIntegration
+{
+ Q_OBJECT
+public:
+ QWindowsMediaIntegration();
+ ~QWindowsMediaIntegration();
+
+ QMaybe<QPlatformMediaCaptureSession *> createCaptureSession() override;
+
+ QMaybe<QPlatformAudioDecoder *> createAudioDecoder(QAudioDecoder *decoder) override;
+ QMaybe<QPlatformMediaPlayer *> createPlayer(QMediaPlayer *parent) override;
+ QMaybe<QPlatformCamera *> createCamera(QCamera *camera) override;
+ QMaybe<QPlatformMediaRecorder *> createRecorder(QMediaRecorder *recorder) override;
+ QMaybe<QPlatformImageCapture *> createImageCapture(QImageCapture *imageCapture) override;
+
+ QMaybe<QPlatformVideoSink *> createVideoSink(QVideoSink *sink) override;
+
+protected:
+ QPlatformMediaFormatInfo *createFormatInfo() override;
+
+ QPlatformVideoDevices *createVideoDevices() override;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/windows/qwindowsvideodevices.cpp b/src/plugins/multimedia/windows/qwindowsvideodevices.cpp
new file mode 100644
index 000000000..8e5081d3b
--- /dev/null
+++ b/src/plugins/multimedia/windows/qwindowsvideodevices.cpp
@@ -0,0 +1,228 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsvideodevices_p.h"
+
+#include <private/qcameradevice_p.h>
+#include <private/qwindowsmfdefs_p.h>
+#include <private/qwindowsmultimediautils_p.h>
+#include <private/qcomptr_p.h>
+#include <private/qcomtaskresource_p.h>
+
+#include <dbt.h>
+
+#include <mfapi.h>
+#include <mfreadwrite.h>
+#include <mferror.h>
+
+QT_BEGIN_NAMESPACE
+
+LRESULT QT_WIN_CALLBACK deviceNotificationWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ if (message == WM_DEVICECHANGE) {
+ auto b = (PDEV_BROADCAST_HDR)lParam;
+ if (b && b->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
+ auto wmd = reinterpret_cast<QWindowsVideoDevices *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
+ if (wmd) {
+ if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) {
+ emit wmd->videoInputsChanged();
+ }
+ }
+ }
+ }
+
+ return 1;
+}
+
+static const auto windowClassName = TEXT("QWindowsMediaDevicesMessageWindow");
+
+static HWND createMessageOnlyWindow()
+{
+ WNDCLASSEX wx = {};
+ wx.cbSize = sizeof(WNDCLASSEX);
+ wx.lpfnWndProc = deviceNotificationWndProc;
+ wx.hInstance = GetModuleHandle(nullptr);
+ wx.lpszClassName = windowClassName;
+
+ if (!RegisterClassEx(&wx))
+ return nullptr;
+
+ auto hwnd = CreateWindowEx(0, windowClassName, TEXT("Message"),
+ 0, 0, 0, 0, 0, HWND_MESSAGE, nullptr, nullptr, nullptr);
+ if (!hwnd) {
+ UnregisterClass(windowClassName, GetModuleHandle(nullptr));
+ return nullptr;
+ }
+
+ return hwnd;
+}
+
+QWindowsVideoDevices::QWindowsVideoDevices(QPlatformMediaIntegration *integration)
+ : QPlatformVideoDevices(integration)
+{
+ CoInitialize(nullptr);
+
+ m_videoDeviceMsgWindow = createMessageOnlyWindow();
+ if (m_videoDeviceMsgWindow) {
+ SetWindowLongPtr(m_videoDeviceMsgWindow, GWLP_USERDATA, (LONG_PTR)this);
+
+ DEV_BROADCAST_DEVICEINTERFACE di = {};
+ di.dbcc_size = sizeof(di);
+ di.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
+ di.dbcc_classguid = QMM_KSCATEGORY_VIDEO_CAMERA;
+
+ m_videoDeviceNotification =
+ RegisterDeviceNotification(m_videoDeviceMsgWindow, &di, DEVICE_NOTIFY_WINDOW_HANDLE);
+ if (!m_videoDeviceNotification) {
+ DestroyWindow(m_videoDeviceMsgWindow);
+ m_videoDeviceMsgWindow = nullptr;
+
+ UnregisterClass(windowClassName, GetModuleHandle(nullptr));
+ }
+ }
+
+ if (!m_videoDeviceNotification) {
+ qWarning() << "Video device change notification disabled";
+ }
+}
+
+QWindowsVideoDevices::~QWindowsVideoDevices()
+{
+ if (m_videoDeviceNotification) {
+ UnregisterDeviceNotification(m_videoDeviceNotification);
+ }
+
+ if (m_videoDeviceMsgWindow) {
+ DestroyWindow(m_videoDeviceMsgWindow);
+ UnregisterClass(windowClassName, GetModuleHandle(nullptr));
+ }
+
+ CoUninitialize();
+}
+
+static std::optional<QCameraFormat> createCameraFormat(IMFMediaType *mediaFormat)
+{
+ GUID subtype = GUID_NULL;
+ if (FAILED(mediaFormat->GetGUID(MF_MT_SUBTYPE, &subtype)))
+ return {};
+
+ auto pixelFormat = QWindowsMultimediaUtils::pixelFormatFromMediaSubtype(subtype);
+ if (pixelFormat == QVideoFrameFormat::Format_Invalid)
+ return {};
+
+ UINT32 width = 0u;
+ UINT32 height = 0u;
+ if (FAILED(MFGetAttributeSize(mediaFormat, MF_MT_FRAME_SIZE, &width, &height)))
+ return {};
+ QSize resolution{ int(width), int(height) };
+
+ UINT32 num = 0u;
+ UINT32 den = 0u;
+ float minFr = 0.f;
+ float maxFr = 0.f;
+
+ if (SUCCEEDED(MFGetAttributeRatio(mediaFormat, MF_MT_FRAME_RATE_RANGE_MIN, &num, &den)))
+ minFr = float(num) / float(den);
+
+ if (SUCCEEDED(MFGetAttributeRatio(mediaFormat, MF_MT_FRAME_RATE_RANGE_MAX, &num, &den)))
+ maxFr = float(num) / float(den);
+
+ auto *f = new QCameraFormatPrivate{ QSharedData(), pixelFormat, resolution, minFr, maxFr };
+ return f->create();
+}
+
+static QString getString(IMFActivate *device, const IID &id)
+{
+ QComTaskResource<WCHAR> str;
+ UINT32 length = 0;
+ HRESULT hr = device->GetAllocatedString(id, str.address(), &length);
+ if (SUCCEEDED(hr)) {
+ return QString::fromWCharArray(str.get());
+ } else {
+ return {};
+ }
+}
+
+static std::optional<QCameraDevice> createCameraDevice(IMFActivate *device)
+{
+ auto info = std::make_unique<QCameraDevicePrivate>();
+ info->description = getString(device, MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME);
+ info->id = getString(device, MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK).toUtf8();
+
+ IMFMediaSource *source = NULL;
+ HRESULT hr = device->ActivateObject(IID_PPV_ARGS(&source));
+ if (FAILED(hr))
+ return {};
+
+ ComPtr<IMFSourceReader> reader;
+ hr = MFCreateSourceReaderFromMediaSource(source, NULL, reader.GetAddressOf());
+ if (FAILED(hr))
+ return {};
+
+ QList<QSize> photoResolutions;
+ QList<QCameraFormat> videoFormats;
+ for (DWORD i = 0;; ++i) {
+ // Loop through the supported formats for the video device
+ ComPtr<IMFMediaType> mediaFormat;
+ hr = reader->GetNativeMediaType((DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, i,
+ mediaFormat.GetAddressOf());
+ if (FAILED(hr))
+ break;
+
+ auto maybeCamera = createCameraFormat(mediaFormat.Get());
+ if (maybeCamera) {
+ videoFormats << *maybeCamera;
+ photoResolutions << maybeCamera->resolution();
+ }
+ }
+
+ info->videoFormats = videoFormats;
+ info->photoResolutions = photoResolutions;
+ return info.release()->create();
+}
+
+static QList<QCameraDevice> readCameraDevices(IMFAttributes *attr)
+{
+ QList<QCameraDevice> cameras;
+ UINT32 count = 0;
+ IMFActivate **devicesRaw = nullptr;
+ HRESULT hr = MFEnumDeviceSources(attr, &devicesRaw, &count);
+ if (SUCCEEDED(hr)) {
+ QComTaskResource<IMFActivate *[], QComDeleter> devices(devicesRaw, count);
+
+ for (UINT32 i = 0; i < count; i++) {
+ IMFActivate *device = devices[i];
+ if (device) {
+ auto maybeCamera = createCameraDevice(device);
+ if (maybeCamera)
+ cameras << *maybeCamera;
+ }
+ }
+ }
+ return cameras;
+}
+
+QList<QCameraDevice> QWindowsVideoDevices::videoDevices() const
+{
+ QList<QCameraDevice> cameras;
+
+ ComPtr<IMFAttributes> attr;
+ HRESULT hr = MFCreateAttributes(attr.GetAddressOf(), 2);
+ if (FAILED(hr))
+ return {};
+
+ hr = attr->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
+ MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);
+ if (SUCCEEDED(hr)) {
+ cameras << readCameraDevices(attr.Get());
+
+ hr = attr->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_CATEGORY,
+ QMM_KSCATEGORY_SENSOR_CAMERA);
+ if (SUCCEEDED(hr))
+ cameras << readCameraDevices(attr.Get());
+ }
+
+ return cameras;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/multimedia/windows/qwindowsvideodevices_p.h b/src/plugins/multimedia/windows/qwindowsvideodevices_p.h
new file mode 100644
index 000000000..f8f5ed920
--- /dev/null
+++ b/src/plugins/multimedia/windows/qwindowsvideodevices_p.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSVIDEODEVICES_H
+#define QWINDOWSVIDEODEVICES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qplatformvideodevices_p.h>
+#include <QtCore/qt_windows.h>
+
+QT_BEGIN_NAMESPACE
+
+LRESULT QT_WIN_CALLBACK deviceNotificationWndProc(HWND, UINT, WPARAM, LPARAM);
+
+class QWindowsVideoDevices : public QPlatformVideoDevices
+{
+public:
+ QWindowsVideoDevices(QPlatformMediaIntegration *integration);
+ ~QWindowsVideoDevices();
+
+ QList<QCameraDevice> videoDevices() const override;
+
+private:
+ HWND m_videoDeviceMsgWindow = nullptr;
+ HDEVNOTIFY m_videoDeviceNotification = nullptr;
+
+ friend LRESULT QT_WIN_CALLBACK deviceNotificationWndProc(HWND, UINT, WPARAM, LPARAM);
+};
+
+
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/windows/sourceresolver.cpp b/src/plugins/multimedia/windows/sourceresolver.cpp
new file mode 100644
index 000000000..52fb024be
--- /dev/null
+++ b/src/plugins/multimedia/windows/sourceresolver.cpp
@@ -0,0 +1,294 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "mfstream_p.h"
+#include "sourceresolver_p.h"
+#include <mferror.h>
+#include <nserror.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qdebug.h>
+#include <QtMultimedia/qmediaplayer.h>
+
+QT_BEGIN_NAMESPACE
+
+/*
+ SourceResolver is separated from MFPlayerSession to handle the work of resolving a media source
+ asynchronously. You call SourceResolver::load to request resolving a media source asynchronously,
+ and it will emit mediaSourceReady() when resolving is done. You can call SourceResolver::cancel to
+ stop the previous load operation if there is any.
+*/
+
+SourceResolver::SourceResolver()
+ : m_cRef(1)
+ , m_cancelCookie(0)
+ , m_sourceResolver(0)
+ , m_mediaSource(0)
+ , m_stream(0)
+{
+}
+
+SourceResolver::~SourceResolver()
+{
+ shutdown();
+ if (m_mediaSource) {
+ m_mediaSource->Release();
+ m_mediaSource = NULL;
+ }
+
+ if (m_cancelCookie)
+ m_cancelCookie->Release();
+ if (m_sourceResolver)
+ m_sourceResolver->Release();
+}
+
+STDMETHODIMP SourceResolver::QueryInterface(REFIID riid, LPVOID *ppvObject)
+{
+ if (!ppvObject)
+ return E_POINTER;
+ if (riid == IID_IUnknown) {
+ *ppvObject = static_cast<IUnknown*>(this);
+ } else if (riid == IID_IMFAsyncCallback) {
+ *ppvObject = static_cast<IMFAsyncCallback*>(this);
+ } else {
+ *ppvObject = NULL;
+ return E_NOINTERFACE;
+ }
+ AddRef();
+ return S_OK;
+}
+
+STDMETHODIMP_(ULONG) SourceResolver::AddRef(void)
+{
+ return InterlockedIncrement(&m_cRef);
+}
+
+STDMETHODIMP_(ULONG) SourceResolver::Release(void)
+{
+ LONG cRef = InterlockedDecrement(&m_cRef);
+ if (cRef == 0)
+ this->deleteLater();
+ return cRef;
+}
+
+HRESULT STDMETHODCALLTYPE SourceResolver::Invoke(IMFAsyncResult *pAsyncResult)
+{
+ QMutexLocker locker(&m_mutex);
+
+ if (!m_sourceResolver)
+ return S_OK;
+
+ MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;
+ IUnknown* pSource = NULL;
+ State *state = static_cast<State*>(pAsyncResult->GetStateNoAddRef());
+
+ HRESULT hr = S_OK;
+ if (state->fromStream())
+ hr = m_sourceResolver->EndCreateObjectFromByteStream(pAsyncResult, &ObjectType, &pSource);
+ else
+ hr = m_sourceResolver->EndCreateObjectFromURL(pAsyncResult, &ObjectType, &pSource);
+
+ if (state->sourceResolver() != m_sourceResolver) {
+ //This is a cancelled one
+ return S_OK;
+ }
+
+ if (m_cancelCookie) {
+ m_cancelCookie->Release();
+ m_cancelCookie = NULL;
+ }
+
+ if (FAILED(hr)) {
+ emit error(hr);
+ return S_OK;
+ }
+
+ if (m_mediaSource) {
+ m_mediaSource->Release();
+ m_mediaSource = NULL;
+ }
+
+ hr = pSource->QueryInterface(IID_PPV_ARGS(&m_mediaSource));
+ pSource->Release();
+ if (FAILED(hr)) {
+ emit error(hr);
+ return S_OK;
+ }
+
+ emit mediaSourceReady();
+
+ return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE SourceResolver::GetParameters(DWORD*, DWORD*)
+{
+ return E_NOTIMPL;
+}
+
+void SourceResolver::load(const QUrl &url, QIODevice* stream)
+{
+ QMutexLocker locker(&m_mutex);
+ HRESULT hr = S_OK;
+ if (!m_sourceResolver)
+ hr = MFCreateSourceResolver(&m_sourceResolver);
+
+ if (m_stream) {
+ m_stream->Release();
+ m_stream = NULL;
+ }
+
+ if (FAILED(hr)) {
+ qWarning() << "Failed to create Source Resolver!";
+ emit error(hr);
+ } else if (stream) {
+ QString urlString = url.toString();
+ m_stream = new MFStream(stream, false);
+ hr = m_sourceResolver->BeginCreateObjectFromByteStream(
+ m_stream, urlString.isEmpty() ? 0 : reinterpret_cast<LPCWSTR>(urlString.utf16()),
+ MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE
+ , NULL, &m_cancelCookie, this, new State(m_sourceResolver, true));
+ if (FAILED(hr)) {
+ qWarning() << "Unsupported stream!";
+ emit error(hr);
+ }
+ } else {
+#ifdef DEBUG_MEDIAFOUNDATION
+ qDebug() << "loading :" << url;
+ qDebug() << "url path =" << url.path().mid(1);
+#endif
+#ifdef TEST_STREAMING
+ //Testing stream function
+ if (url.scheme() == QLatin1String("file")) {
+ stream = new QFile(url.path().mid(1));
+ if (stream->open(QIODevice::ReadOnly)) {
+ m_stream = new MFStream(stream, true);
+ hr = m_sourceResolver->BeginCreateObjectFromByteStream(
+ m_stream, reinterpret_cast<const OLECHAR *>(url.toString().utf16()),
+ MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE,
+ NULL, &m_cancelCookie, this, new State(m_sourceResolver, true));
+ if (FAILED(hr)) {
+ qWarning() << "Unsupported stream!";
+ emit error(hr);
+ }
+ } else {
+ delete stream;
+ emit error(QMediaPlayer::FormatError);
+ }
+ } else
+#endif
+ if (url.scheme() == QLatin1String("qrc")) {
+ // If the canonical URL refers to a Qt resource, open with QFile and use
+ // the stream playback capability to play.
+ stream = new QFile(QLatin1Char(':') + url.path());
+ if (stream->open(QIODevice::ReadOnly)) {
+ m_stream = new MFStream(stream, true);
+ hr = m_sourceResolver->BeginCreateObjectFromByteStream(
+ m_stream, reinterpret_cast<const OLECHAR *>(url.toString().utf16()),
+ MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE,
+ NULL, &m_cancelCookie, this, new State(m_sourceResolver, true));
+ if (FAILED(hr)) {
+ qWarning() << "Unsupported stream!";
+ emit error(hr);
+ }
+ } else {
+ delete stream;
+ emit error(QMediaPlayer::FormatError);
+ }
+ } else {
+ hr = m_sourceResolver->BeginCreateObjectFromURL(
+ reinterpret_cast<const OLECHAR *>(url.toString().utf16()),
+ MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE,
+ NULL, &m_cancelCookie, this, new State(m_sourceResolver, false));
+ if (FAILED(hr)) {
+ qWarning() << "Unsupported url scheme!";
+ emit error(hr);
+ }
+ }
+ }
+}
+
+void SourceResolver::cancel()
+{
+ QMutexLocker locker(&m_mutex);
+ if (m_cancelCookie) {
+ m_sourceResolver->CancelObjectCreation(m_cancelCookie);
+ m_cancelCookie->Release();
+ m_cancelCookie = NULL;
+ m_sourceResolver->Release();
+ m_sourceResolver = NULL;
+ }
+}
+
+void SourceResolver::shutdown()
+{
+ if (m_mediaSource) {
+ m_mediaSource->Shutdown();
+ m_mediaSource->Release();
+ m_mediaSource = NULL;
+ }
+
+ if (m_stream) {
+ m_stream->Release();
+ m_stream = NULL;
+ }
+}
+
+IMFMediaSource* SourceResolver::mediaSource() const
+{
+ return m_mediaSource;
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+SourceResolver::State::State(IMFSourceResolver *sourceResolver, bool fromStream)
+ : m_cRef(0)
+ , m_sourceResolver(sourceResolver)
+ , m_fromStream(fromStream)
+{
+ sourceResolver->AddRef();
+}
+
+SourceResolver::State::~State()
+{
+ m_sourceResolver->Release();
+}
+
+STDMETHODIMP SourceResolver::State::QueryInterface(REFIID riid, LPVOID *ppvObject)
+{
+ if (!ppvObject)
+ return E_POINTER;
+ if (riid == IID_IUnknown) {
+ *ppvObject = static_cast<IUnknown*>(this);
+ } else {
+ *ppvObject = NULL;
+ return E_NOINTERFACE;
+ }
+ AddRef();
+ return S_OK;
+}
+
+STDMETHODIMP_(ULONG) SourceResolver::State::AddRef(void)
+{
+ return InterlockedIncrement(&m_cRef);
+}
+
+STDMETHODIMP_(ULONG) SourceResolver::State::Release(void)
+{
+ LONG cRef = InterlockedDecrement(&m_cRef);
+ if (cRef == 0)
+ delete this;
+ // For thread safety, return a temporary variable.
+ return cRef;
+}
+
+IMFSourceResolver* SourceResolver::State::sourceResolver() const
+{
+ return m_sourceResolver;
+}
+
+bool SourceResolver::State::fromStream() const
+{
+ return m_fromStream;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_sourceresolver_p.cpp"
diff --git a/src/plugins/multimedia/windows/sourceresolver_p.h b/src/plugins/multimedia/windows/sourceresolver_p.h
new file mode 100644
index 000000000..57ac6fc9d
--- /dev/null
+++ b/src/plugins/multimedia/windows/sourceresolver_p.h
@@ -0,0 +1,83 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef SOURCERESOLVER_H
+#define SOURCERESOLVER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "mfstream_p.h"
+#include <QUrl>
+
+QT_BEGIN_NAMESPACE
+
+class SourceResolver: public QObject, public IMFAsyncCallback
+{
+ Q_OBJECT
+public:
+ SourceResolver();
+
+ ~SourceResolver();
+
+ STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override;
+ STDMETHODIMP_(ULONG) AddRef(void) override;
+ STDMETHODIMP_(ULONG) Release(void) override;
+
+ HRESULT STDMETHODCALLTYPE Invoke(IMFAsyncResult *pAsyncResult) override;
+
+ HRESULT STDMETHODCALLTYPE GetParameters(DWORD*, DWORD*) override;
+
+ void load(const QUrl &url, QIODevice* stream);
+
+ void cancel();
+
+ void shutdown();
+
+ IMFMediaSource* mediaSource() const;
+
+Q_SIGNALS:
+ void error(long hr);
+ void mediaSourceReady();
+
+private:
+ class State : public IUnknown
+ {
+ public:
+ State(IMFSourceResolver *sourceResolver, bool fromStream);
+ virtual ~State();
+
+ STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override;
+
+ STDMETHODIMP_(ULONG) AddRef(void) override;
+
+ STDMETHODIMP_(ULONG) Release(void) override;
+
+ IMFSourceResolver* sourceResolver() const;
+ bool fromStream() const;
+
+ private:
+ long m_cRef;
+ IMFSourceResolver *m_sourceResolver;
+ bool m_fromStream;
+ };
+
+ long m_cRef;
+ IUnknown *m_cancelCookie;
+ IMFSourceResolver *m_sourceResolver;
+ IMFMediaSource *m_mediaSource;
+ MFStream *m_stream;
+ QMutex m_mutex;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/multimedia/windows/windows.json b/src/plugins/multimedia/windows/windows.json
new file mode 100644
index 000000000..05032c1b7
--- /dev/null
+++ b/src/plugins/multimedia/windows/windows.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "windows" ]
+}
diff --git a/src/plugins/opensles/opensles.json b/src/plugins/opensles/opensles.json
deleted file mode 100644
index a31d52107..000000000
--- a/src/plugins/opensles/opensles.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": ["default"]
-}
diff --git a/src/plugins/opensles/opensles.pro b/src/plugins/opensles/opensles.pro
deleted file mode 100644
index 1a554f53e..000000000
--- a/src/plugins/opensles/opensles.pro
+++ /dev/null
@@ -1,25 +0,0 @@
-TARGET = qtaudio_opensles
-QT += opengl multimedia-private core-private
-
-LIBS += -lOpenSLES
-
-HEADERS += \
- qopenslesplugin.h \
- qopenslesengine.h \
- qopenslesdeviceinfo.h \
- qopenslesaudioinput.h \
- qopenslesaudiooutput.h
-
-SOURCES += \
- qopenslesplugin.cpp \
- qopenslesengine.cpp \
- qopenslesdeviceinfo.cpp \
- qopenslesaudioinput.cpp \
- qopenslesaudiooutput.cpp
-
-OTHER_FILES += \
- opensles.json
-
-PLUGIN_TYPE = audio
-PLUGIN_CLASS_NAME = QOpenSLESPlugin
-load(qt_plugin)
diff --git a/src/plugins/opensles/qopenslesaudioinput.cpp b/src/plugins/opensles/qopenslesaudioinput.cpp
deleted file mode 100644
index 9105fca4c..000000000
--- a/src/plugins/opensles/qopenslesaudioinput.cpp
+++ /dev/null
@@ -1,548 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qopenslesaudioinput.h"
-
-#include "qopenslesengine.h"
-#include <qbuffer.h>
-#include <private/qaudiohelpers_p.h>
-#include <qdebug.h>
-
-#ifdef ANDROID
-#include <SLES/OpenSLES_AndroidConfiguration.h>
-#include <QtCore/private/qjnihelpers_p.h>
-#include <QtCore/private/qjni_p.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-#define NUM_BUFFERS 2
-#define DEFAULT_PERIOD_TIME_MS 50
-#define MINIMUM_PERIOD_TIME_MS 5
-
-#ifdef ANDROID
-static bool hasRecordingPermission()
-{
- using namespace QtAndroidPrivate;
- if (androidSdkVersion() < 23)
- return true;
-
- const QString key(QLatin1String("android.permission.RECORD_AUDIO"));
- PermissionsResult res = checkPermission(key);
- if (res == PermissionsResult::Granted) // Permission already granted?
- return true;
-
- QJNIEnvironmentPrivate env;
- const auto &results = requestPermissionsSync(env, QStringList() << key);
- if (!results.contains(key)) {
- qWarning("No permission found for key: %s", qPrintable(key));
- return false;
- }
-
- if (results[key] == PermissionsResult::Denied) {
- qDebug("%s - Permission denied by user!", qPrintable(key));
- return false;
- }
-
- return true;
-}
-
-static void bufferQueueCallback(SLAndroidSimpleBufferQueueItf, void *context)
-#else
-static void bufferQueueCallback(SLBufferQueueItf, void *context)
-#endif
-{
- // Process buffer in main thread
- QMetaObject::invokeMethod(reinterpret_cast<QOpenSLESAudioInput*>(context), "processBuffer");
-}
-
-QOpenSLESAudioInput::QOpenSLESAudioInput(const QByteArray &device)
- : m_device(device)
- , m_engine(QOpenSLESEngine::instance())
- , m_recorderObject(0)
- , m_recorder(0)
- , m_bufferQueue(0)
- , m_pullMode(true)
- , m_processedBytes(0)
- , m_audioSource(0)
- , m_bufferIODevice(0)
- , m_errorState(QAudio::NoError)
- , m_deviceState(QAudio::StoppedState)
- , m_lastNotifyTime(0)
- , m_volume(1.0)
- , m_bufferSize(0)
- , m_periodSize(0)
- , m_intervalTime(1000)
- , m_buffers(new QByteArray[NUM_BUFFERS])
- , m_currentBuffer(0)
-{
-#ifdef ANDROID
- if (qstrcmp(device, QT_ANDROID_PRESET_CAMCORDER) == 0)
- m_recorderPreset = SL_ANDROID_RECORDING_PRESET_CAMCORDER;
- else if (qstrcmp(device, QT_ANDROID_PRESET_VOICE_RECOGNITION) == 0)
- m_recorderPreset = SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION;
- else if (qstrcmp(device, QT_ANDROID_PRESET_VOICE_COMMUNICATION) == 0)
- m_recorderPreset = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
- else
- m_recorderPreset = SL_ANDROID_RECORDING_PRESET_GENERIC;
-#endif
-}
-
-QOpenSLESAudioInput::~QOpenSLESAudioInput()
-{
- if (m_recorderObject)
- (*m_recorderObject)->Destroy(m_recorderObject);
- delete[] m_buffers;
-}
-
-QAudio::Error QOpenSLESAudioInput::error() const
-{
- return m_errorState;
-}
-
-QAudio::State QOpenSLESAudioInput::state() const
-{
- return m_deviceState;
-}
-
-void QOpenSLESAudioInput::setFormat(const QAudioFormat &format)
-{
- if (m_deviceState == QAudio::StoppedState)
- m_format = format;
-}
-
-QAudioFormat QOpenSLESAudioInput::format() const
-{
- return m_format;
-}
-
-void QOpenSLESAudioInput::start(QIODevice *device)
-{
- if (m_deviceState != QAudio::StoppedState)
- stopRecording();
-
- if (!m_pullMode && m_bufferIODevice) {
- m_bufferIODevice->close();
- delete m_bufferIODevice;
- m_bufferIODevice = 0;
- }
-
- m_pullMode = true;
- m_audioSource = device;
-
- if (startRecording()) {
- m_deviceState = QAudio::ActiveState;
- } else {
- m_deviceState = QAudio::StoppedState;
- Q_EMIT errorChanged(m_errorState);
- }
-
- Q_EMIT stateChanged(m_deviceState);
-}
-
-QIODevice *QOpenSLESAudioInput::start()
-{
- if (m_deviceState != QAudio::StoppedState)
- stopRecording();
-
- m_audioSource = 0;
-
- if (!m_pullMode && m_bufferIODevice) {
- m_bufferIODevice->close();
- delete m_bufferIODevice;
- }
-
- m_pullMode = false;
- m_pushBuffer.clear();
- m_bufferIODevice = new QBuffer(&m_pushBuffer);
- m_bufferIODevice->open(QIODevice::ReadOnly);
-
- if (startRecording()) {
- m_deviceState = QAudio::IdleState;
- } else {
- m_deviceState = QAudio::StoppedState;
- Q_EMIT errorChanged(m_errorState);
- m_bufferIODevice->close();
- delete m_bufferIODevice;
- m_bufferIODevice = 0;
- }
-
- Q_EMIT stateChanged(m_deviceState);
- return m_bufferIODevice;
-}
-
-bool QOpenSLESAudioInput::startRecording()
-{
- if (!hasRecordingPermission())
- return false;
-
- m_processedBytes = 0;
- m_clockStamp.restart();
- m_lastNotifyTime = 0;
-
- SLresult result;
-
- // configure audio source
- SLDataLocator_IODevice loc_dev = { SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT,
- SL_DEFAULTDEVICEID_AUDIOINPUT, NULL };
- SLDataSource audioSrc = { &loc_dev, NULL };
-
- // configure audio sink
-#ifdef ANDROID
- SLDataLocator_AndroidSimpleBufferQueue loc_bq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,
- NUM_BUFFERS };
-#else
- SLDataLocator_BufferQueue loc_bq = { SL_DATALOCATOR_BUFFERQUEUE, NUM_BUFFERS };
-#endif
-
- SLDataFormat_PCM format_pcm = QOpenSLESEngine::audioFormatToSLFormatPCM(m_format);
- SLDataSink audioSnk = { &loc_bq, &format_pcm };
-
- // create audio recorder
- // (requires the RECORD_AUDIO permission)
-#ifdef ANDROID
- const SLInterfaceID id[2] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_ANDROIDCONFIGURATION };
- const SLboolean req[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
-#else
- const SLInterfaceID id[1] = { SL_IID_BUFFERQUEUE };
- const SLboolean req[1] = { SL_BOOLEAN_TRUE };
-#endif
-
- result = (*m_engine->slEngine())->CreateAudioRecorder(m_engine->slEngine(), &m_recorderObject,
- &audioSrc, &audioSnk,
- sizeof(req) / sizeof(SLboolean), id, req);
- if (result != SL_RESULT_SUCCESS) {
- m_errorState = QAudio::OpenError;
- return false;
- }
-
-#ifdef ANDROID
- // configure recorder source
- SLAndroidConfigurationItf configItf;
- result = (*m_recorderObject)->GetInterface(m_recorderObject, SL_IID_ANDROIDCONFIGURATION,
- &configItf);
- if (result != SL_RESULT_SUCCESS) {
- m_errorState = QAudio::OpenError;
- return false;
- }
-
- result = (*configItf)->SetConfiguration(configItf, SL_ANDROID_KEY_RECORDING_PRESET,
- &m_recorderPreset, sizeof(SLuint32));
-
- SLuint32 presetValue = SL_ANDROID_RECORDING_PRESET_NONE;
- SLuint32 presetSize = 2*sizeof(SLuint32); // intentionally too big
- result = (*configItf)->GetConfiguration(configItf, SL_ANDROID_KEY_RECORDING_PRESET,
- &presetSize, (void*)&presetValue);
-
- if (result != SL_RESULT_SUCCESS || presetValue == SL_ANDROID_RECORDING_PRESET_NONE) {
- m_errorState = QAudio::OpenError;
- return false;
- }
-#endif
-
- // realize the audio recorder
- result = (*m_recorderObject)->Realize(m_recorderObject, SL_BOOLEAN_FALSE);
- if (result != SL_RESULT_SUCCESS) {
- m_errorState = QAudio::OpenError;
- return false;
- }
-
- // get the record interface
- result = (*m_recorderObject)->GetInterface(m_recorderObject, SL_IID_RECORD, &m_recorder);
- if (result != SL_RESULT_SUCCESS) {
- m_errorState = QAudio::FatalError;
- return false;
- }
-
- // get the buffer queue interface
-#ifdef ANDROID
- SLInterfaceID bufferqueueItfID = SL_IID_ANDROIDSIMPLEBUFFERQUEUE;
-#else
- SLInterfaceID bufferqueueItfID = SL_IID_BUFFERQUEUE;
-#endif
- result = (*m_recorderObject)->GetInterface(m_recorderObject, bufferqueueItfID, &m_bufferQueue);
- if (result != SL_RESULT_SUCCESS) {
- m_errorState = QAudio::FatalError;
- return false;
- }
-
- // register callback on the buffer queue
- result = (*m_bufferQueue)->RegisterCallback(m_bufferQueue, bufferQueueCallback, this);
- if (result != SL_RESULT_SUCCESS) {
- m_errorState = QAudio::FatalError;
- return false;
- }
-
- if (m_bufferSize <= 0) {
- m_bufferSize = m_format.bytesForDuration(DEFAULT_PERIOD_TIME_MS * 1000);
- } else {
- int minimumBufSize = m_format.bytesForDuration(MINIMUM_PERIOD_TIME_MS * 1000);
- if (m_bufferSize < minimumBufSize)
- m_bufferSize = minimumBufSize;
- }
-
- m_periodSize = m_bufferSize;
-
- // enqueue empty buffers to be filled by the recorder
- for (int i = 0; i < NUM_BUFFERS; ++i) {
- m_buffers[i].resize(m_periodSize);
-
- result = (*m_bufferQueue)->Enqueue(m_bufferQueue, m_buffers[i].data(), m_periodSize);
- if (result != SL_RESULT_SUCCESS) {
- m_errorState = QAudio::FatalError;
- return false;
- }
- }
-
- // start recording
- result = (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_RECORDING);
- if (result != SL_RESULT_SUCCESS) {
- m_errorState = QAudio::FatalError;
- return false;
- }
-
- m_errorState = QAudio::NoError;
-
- return true;
-}
-
-void QOpenSLESAudioInput::stop()
-{
- if (m_deviceState == QAudio::StoppedState)
- return;
-
- m_deviceState = QAudio::StoppedState;
-
- stopRecording();
-
- m_errorState = QAudio::NoError;
- Q_EMIT stateChanged(m_deviceState);
-}
-
-void QOpenSLESAudioInput::stopRecording()
-{
- flushBuffers();
-
- (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_STOPPED);
- (*m_bufferQueue)->Clear(m_bufferQueue);
-
- (*m_recorderObject)->Destroy(m_recorderObject);
- m_recorderObject = 0;
-
- for (int i = 0; i < NUM_BUFFERS; ++i)
- m_buffers[i].clear();
- m_currentBuffer = 0;
-
- if (!m_pullMode && m_bufferIODevice) {
- m_bufferIODevice->close();
- delete m_bufferIODevice;
- m_bufferIODevice = 0;
- m_pushBuffer.clear();
- }
-}
-
-void QOpenSLESAudioInput::suspend()
-{
- if (m_deviceState == QAudio::ActiveState) {
- m_deviceState = QAudio::SuspendedState;
- emit stateChanged(m_deviceState);
-
- (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_PAUSED);
- }
-}
-
-void QOpenSLESAudioInput::resume()
-{
- if (m_deviceState == QAudio::SuspendedState || m_deviceState == QAudio::IdleState) {
- (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_RECORDING);
-
- m_deviceState = QAudio::ActiveState;
- emit stateChanged(m_deviceState);
- }
-}
-
-void QOpenSLESAudioInput::processBuffer()
-{
- if (m_deviceState == QAudio::StoppedState || m_deviceState == QAudio::SuspendedState)
- return;
-
- if (m_deviceState != QAudio::ActiveState) {
- m_errorState = QAudio::NoError;
- m_deviceState = QAudio::ActiveState;
- emit stateChanged(m_deviceState);
- }
-
- QByteArray *processedBuffer = &m_buffers[m_currentBuffer];
- writeDataToDevice(processedBuffer->constData(), processedBuffer->size());
-
- // Re-enqueue the buffer
- SLresult result = (*m_bufferQueue)->Enqueue(m_bufferQueue,
- processedBuffer->data(),
- processedBuffer->size());
-
- m_currentBuffer = (m_currentBuffer + 1) % NUM_BUFFERS;
-
- // If the buffer queue is empty (shouldn't happen), stop recording.
-#ifdef ANDROID
- SLAndroidSimpleBufferQueueState state;
-#else
- SLBufferQueueState state;
-#endif
- result = (*m_bufferQueue)->GetState(m_bufferQueue, &state);
- if (result != SL_RESULT_SUCCESS || state.count == 0) {
- stop();
- m_errorState = QAudio::FatalError;
- Q_EMIT errorChanged(m_errorState);
- }
-}
-
-void QOpenSLESAudioInput::writeDataToDevice(const char *data, int size)
-{
- m_processedBytes += size;
-
- QByteArray outData;
-
- // Apply volume
- if (m_volume < 1.0f) {
- outData.resize(size);
- QAudioHelperInternal::qMultiplySamples(m_volume, m_format, data, outData.data(), size);
- } else {
- outData.append(data, size);
- }
-
- if (m_pullMode) {
- // write buffer to the QIODevice
- if (m_audioSource->write(outData) < 0) {
- stop();
- m_errorState = QAudio::IOError;
- Q_EMIT errorChanged(m_errorState);
- }
- } else {
- // emits readyRead() so user will call read() on QIODevice to get some audio data
- if (m_bufferIODevice != 0) {
- m_pushBuffer.append(outData);
- Q_EMIT m_bufferIODevice->readyRead();
- }
- }
-
- // Send notify signal if needed
- qint64 processedMsecs = processedUSecs() / 1000;
- if (m_intervalTime && (processedMsecs - m_lastNotifyTime) >= m_intervalTime) {
- Q_EMIT notify();
- m_lastNotifyTime = processedMsecs;
- }
-}
-
-void QOpenSLESAudioInput::flushBuffers()
-{
- SLmillisecond recorderPos;
- (*m_recorder)->GetPosition(m_recorder, &recorderPos);
- qint64 devicePos = processedUSecs();
-
- qint64 delta = recorderPos * 1000 - devicePos;
-
- if (delta > 0) {
- const int writeSize = qMin(m_buffers[m_currentBuffer].size(),
- m_format.bytesForDuration(delta));
- writeDataToDevice(m_buffers[m_currentBuffer].constData(), writeSize);
- }
-}
-
-int QOpenSLESAudioInput::bytesReady() const
-{
- if (m_deviceState == QAudio::ActiveState || m_deviceState == QAudio::SuspendedState)
- return m_bufferIODevice ? m_bufferIODevice->bytesAvailable() : m_periodSize;
-
- return 0;
-}
-
-void QOpenSLESAudioInput::setBufferSize(int value)
-{
- m_bufferSize = value;
-}
-
-int QOpenSLESAudioInput::bufferSize() const
-{
- return m_bufferSize;
-}
-
-int QOpenSLESAudioInput::periodSize() const
-{
- return m_periodSize;
-}
-
-void QOpenSLESAudioInput::setNotifyInterval(int ms)
-{
- m_intervalTime = qMax(0, ms);
-}
-
-int QOpenSLESAudioInput::notifyInterval() const
-{
- return m_intervalTime;
-}
-
-qint64 QOpenSLESAudioInput::processedUSecs() const
-{
- return m_format.durationForBytes(m_processedBytes);
-}
-
-qint64 QOpenSLESAudioInput::elapsedUSecs() const
-{
- if (m_deviceState == QAudio::StoppedState)
- return 0;
-
- return m_clockStamp.elapsed() * qint64(1000);
-}
-
-void QOpenSLESAudioInput::setVolume(qreal vol)
-{
- m_volume = vol;
-}
-
-qreal QOpenSLESAudioInput::volume() const
-{
- return m_volume;
-}
-
-void QOpenSLESAudioInput::reset()
-{
- stop();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/opensles/qopenslesaudioinput.h b/src/plugins/opensles/qopenslesaudioinput.h
deleted file mode 100644
index 730c58bd6..000000000
--- a/src/plugins/opensles/qopenslesaudioinput.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QOPENSLESAUDIOINPUT_H
-#define QOPENSLESAUDIOINPUT_H
-
-#include <qaudiosystem.h>
-#include <QElapsedTimer>
-#include <SLES/OpenSLES.h>
-
-#ifdef ANDROID
-#include <SLES/OpenSLES_Android.h>
-
-#define QT_ANDROID_PRESET_MIC "mic"
-#define QT_ANDROID_PRESET_CAMCORDER "camcorder"
-#define QT_ANDROID_PRESET_VOICE_RECOGNITION "voicerecognition"
-#define QT_ANDROID_PRESET_VOICE_COMMUNICATION "voicecommunication"
-
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class QOpenSLESEngine;
-class QIODevice;
-class QBuffer;
-
-class QOpenSLESAudioInput : public QAbstractAudioInput
-{
- Q_OBJECT
-
-public:
- QOpenSLESAudioInput(const QByteArray &device);
- ~QOpenSLESAudioInput();
-
- void start(QIODevice *device);
- QIODevice *start();
- void stop();
- void reset();
- void suspend();
- void resume();
- int bytesReady() const;
- int periodSize() const;
- void setBufferSize(int value);
- int bufferSize() const;
- void setNotifyInterval(int milliSeconds);
- int notifyInterval() const;
- qint64 processedUSecs() const;
- qint64 elapsedUSecs() const;
- QAudio::Error error() const;
- QAudio::State state() const;
- void setFormat(const QAudioFormat &format);
- QAudioFormat format() const;
-
- void setVolume(qreal volume);
- qreal volume() const;
-
-public Q_SLOTS:
- void processBuffer();
-
-private:
- bool startRecording();
- void stopRecording();
- void writeDataToDevice(const char *data, int size);
- void flushBuffers();
-
- QByteArray m_device;
- QOpenSLESEngine *m_engine;
- SLObjectItf m_recorderObject;
- SLRecordItf m_recorder;
-#ifdef ANDROID
- SLuint32 m_recorderPreset;
- SLAndroidSimpleBufferQueueItf m_bufferQueue;
-#else
- SLBufferQueueItf m_bufferQueue;
-#endif
-
- bool m_pullMode;
- qint64 m_processedBytes;
- QIODevice *m_audioSource;
- QBuffer *m_bufferIODevice;
- QByteArray m_pushBuffer;
- QAudioFormat m_format;
- QAudio::Error m_errorState;
- QAudio::State m_deviceState;
- QElapsedTimer m_clockStamp;
- qint64 m_lastNotifyTime;
- qreal m_volume;
- int m_bufferSize;
- int m_periodSize;
- int m_intervalTime;
- QByteArray *m_buffers;
- int m_currentBuffer;
-};
-
-QT_END_NAMESPACE
-
-#endif // QOPENSLESAUDIOINPUT_H
diff --git a/src/plugins/opensles/qopenslesaudiooutput.cpp b/src/plugins/opensles/qopenslesaudiooutput.cpp
deleted file mode 100644
index 381ce0ec2..000000000
--- a/src/plugins/opensles/qopenslesaudiooutput.cpp
+++ /dev/null
@@ -1,733 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qopenslesaudiooutput.h"
-#include "qopenslesengine.h"
-#include <QDebug>
-#include <qmath.h>
-
-#ifdef ANDROID
-#include <SLES/OpenSLES_Android.h>
-#include <SLES/OpenSLES_AndroidConfiguration.h>
-#endif // ANDROID
-
-#define BUFFER_COUNT 2
-
-QT_BEGIN_NAMESPACE
-
-static inline void openSlDebugInfo()
-{
- const QAudioFormat &format = QAudioDeviceInfo::defaultOutputDevice().preferredFormat();
- qDebug() << "======= OpenSL ES Device info ======="
- << "\nSupports low-latency playback: " << (QOpenSLESEngine::supportsLowLatency() ? "YES" : "NO")
- << "\nPreferred sample rate: " << QOpenSLESEngine::getOutputValue(QOpenSLESEngine::SampleRate, -1)
- << "\nFrames per buffer: " << QOpenSLESEngine::getOutputValue(QOpenSLESEngine::FramesPerBuffer, -1)
- << "\nPreferred Format: " << format
- << "\nLow-latency buffer size: " << QOpenSLESEngine::getLowLatencyBufferSize(format)
- << "\nDefault buffer size: " << QOpenSLESEngine::getDefaultBufferSize(format);
-}
-
-QMap<QString, qint32> QOpenSLESAudioOutput::m_categories;
-
-QOpenSLESAudioOutput::QOpenSLESAudioOutput(const QByteArray &device)
- : m_deviceName(device),
- m_state(QAudio::StoppedState),
- m_error(QAudio::NoError),
- m_outputMixObject(nullptr),
- m_playerObject(nullptr),
- m_playItf(nullptr),
- m_volumeItf(nullptr),
- m_bufferQueueItf(nullptr),
- m_audioSource(nullptr),
- m_buffers(nullptr),
- m_volume(1.0),
- m_pullMode(false),
- m_nextBuffer(0),
- m_bufferSize(0),
- m_notifyInterval(1000),
- m_periodSize(0),
- m_elapsedTime(0),
- m_processedBytes(0),
- m_availableBuffers(BUFFER_COUNT),
- m_eventMask(SL_PLAYEVENT_HEADATEND),
- m_startRequiresInit(true)
-{
-#ifndef ANDROID
- m_streamType = -1;
-#else
- m_streamType = SL_ANDROID_STREAM_MEDIA;
- m_category = QLatin1String("media");
-#endif // ANDROID
-}
-
-QOpenSLESAudioOutput::~QOpenSLESAudioOutput()
-{
- destroyPlayer();
-}
-
-QAudio::Error QOpenSLESAudioOutput::error() const
-{
- return m_error;
-}
-
-QAudio::State QOpenSLESAudioOutput::state() const
-{
- return m_state;
-}
-
-void QOpenSLESAudioOutput::start(QIODevice *device)
-{
- Q_ASSERT(device);
-
- if (m_state != QAudio::StoppedState)
- stop();
-
- if (!preparePlayer())
- return;
-
- m_pullMode = true;
- m_audioSource = device;
- m_nextBuffer = 0;
- m_processedBytes = 0;
- m_availableBuffers = BUFFER_COUNT;
- setState(QAudio::ActiveState);
- setError(QAudio::NoError);
-
- // Attempt to fill buffers first.
- for (int i = 0; i != BUFFER_COUNT; ++i) {
- const int index = i * m_bufferSize;
- const qint64 readSize = m_audioSource->read(m_buffers + index, m_bufferSize);
- if (readSize && SL_RESULT_SUCCESS != (*m_bufferQueueItf)->Enqueue(m_bufferQueueItf,
- m_buffers + index,
- readSize)) {
- setError(QAudio::FatalError);
- destroyPlayer();
- return;
- }
- m_processedBytes += readSize;
- }
-
- if (m_processedBytes < 1)
- onEOSEvent();
-
- // Change the state to playing.
- // We need to do this after filling the buffers or processedBytes might get corrupted.
- startPlayer();
-}
-
-QIODevice *QOpenSLESAudioOutput::start()
-{
- if (m_state != QAudio::StoppedState)
- stop();
-
- if (!preparePlayer())
- return nullptr;
-
- m_pullMode = false;
- m_processedBytes = 0;
- m_availableBuffers = BUFFER_COUNT;
- m_audioSource = new SLIODevicePrivate(this);
- m_audioSource->open(QIODevice::WriteOnly | QIODevice::Unbuffered);
-
- // Change the state to playing
- startPlayer();
-
- setState(QAudio::IdleState);
- return m_audioSource;
-}
-
-void QOpenSLESAudioOutput::stop()
-{
- if (m_state == QAudio::StoppedState)
- return;
-
- stopPlayer();
- setError(QAudio::NoError);
-}
-
-int QOpenSLESAudioOutput::bytesFree() const
-{
- if (m_state != QAudio::ActiveState && m_state != QAudio::IdleState)
- return 0;
-
- return m_availableBuffers.loadAcquire() ? m_bufferSize : 0;
-}
-
-int QOpenSLESAudioOutput::periodSize() const
-{
- return m_periodSize;
-}
-
-void QOpenSLESAudioOutput::setBufferSize(int value)
-{
- if (m_state != QAudio::StoppedState)
- return;
-
- m_startRequiresInit = true;
- m_bufferSize = value;
-}
-
-int QOpenSLESAudioOutput::bufferSize() const
-{
- return m_bufferSize;
-}
-
-void QOpenSLESAudioOutput::setNotifyInterval(int ms)
-{
- const int newInterval = ms > 0 ? ms : 0;
-
- if (newInterval == m_notifyInterval)
- return;
-
- const SLuint32 newEvenMask = newInterval == 0 ? m_eventMask & ~SL_PLAYEVENT_HEADATNEWPOS
- : m_eventMask & SL_PLAYEVENT_HEADATNEWPOS;
-
- if (m_state == QAudio::StoppedState) {
- m_eventMask = newEvenMask;
- m_notifyInterval = newInterval;
- return;
- }
-
- if (newEvenMask != m_eventMask
- && SL_RESULT_SUCCESS != (*m_playItf)->SetCallbackEventsMask(m_playItf, newEvenMask)) {
- return;
- }
-
- m_eventMask = newEvenMask;
-
- if (newInterval && SL_RESULT_SUCCESS != (*m_playItf)->SetPositionUpdatePeriod(m_playItf,
- newInterval)) {
- return;
- }
-
- m_notifyInterval = newInterval;
-}
-
-int QOpenSLESAudioOutput::notifyInterval() const
-{
- return m_notifyInterval;
-}
-
-qint64 QOpenSLESAudioOutput::processedUSecs() const
-{
- if (m_state == QAudio::IdleState || m_state == QAudio::SuspendedState)
- return m_format.durationForBytes(m_processedBytes);
-
- SLmillisecond processMSec = 0;
- if (m_playItf)
- (*m_playItf)->GetPosition(m_playItf, &processMSec);
-
- return processMSec * 1000;
-}
-
-void QOpenSLESAudioOutput::resume()
-{
- if (m_state != QAudio::SuspendedState)
- return;
-
- if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PLAYING)) {
- setError(QAudio::FatalError);
- destroyPlayer();
- return;
- }
-
- setState(m_pullMode ? QAudio::ActiveState : QAudio::IdleState);
- setError(QAudio::NoError);
-}
-
-void QOpenSLESAudioOutput::setFormat(const QAudioFormat &format)
-{
- m_startRequiresInit = true;
- m_format = format;
-}
-
-QAudioFormat QOpenSLESAudioOutput::format() const
-{
- return m_format;
-}
-
-void QOpenSLESAudioOutput::suspend()
-{
- if (m_state != QAudio::ActiveState && m_state != QAudio::IdleState)
- return;
-
- if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PAUSED)) {
- setError(QAudio::FatalError);
- destroyPlayer();
- return;
- }
-
- setState(QAudio::SuspendedState);
- setError(QAudio::NoError);
-}
-
-qint64 QOpenSLESAudioOutput::elapsedUSecs() const
-{
- if (m_state == QAudio::StoppedState)
- return 0;
-
- return m_clockStamp.elapsed() * qint64(1000);
-}
-
-void QOpenSLESAudioOutput::reset()
-{
- destroyPlayer();
-}
-
-void QOpenSLESAudioOutput::setVolume(qreal vol)
-{
- m_volume = qBound(qreal(0.0), vol, qreal(1.0));
- const SLmillibel newVolume = adjustVolume(m_volume);
- if (m_volumeItf && SL_RESULT_SUCCESS != (*m_volumeItf)->SetVolumeLevel(m_volumeItf, newVolume))
- qWarning() << "Unable to change volume";
-}
-
-qreal QOpenSLESAudioOutput::volume() const
-{
- return m_volume;
-}
-
-void QOpenSLESAudioOutput::setCategory(const QString &category)
-{
-#ifndef ANDROID
- Q_UNUSED(category);
-#else
- if (m_categories.isEmpty()) {
- m_categories.insert(QLatin1String("voice"), SL_ANDROID_STREAM_VOICE);
- m_categories.insert(QLatin1String("system"), SL_ANDROID_STREAM_SYSTEM);
- m_categories.insert(QLatin1String("ring"), SL_ANDROID_STREAM_RING);
- m_categories.insert(QLatin1String("media"), SL_ANDROID_STREAM_MEDIA);
- m_categories.insert(QLatin1String("alarm"), SL_ANDROID_STREAM_ALARM);
- m_categories.insert(QLatin1String("notification"), SL_ANDROID_STREAM_NOTIFICATION);
- }
-
- const SLint32 streamType = m_categories.value(category, -1);
- if (streamType == -1) {
- qWarning() << "Unknown category" << category
- << ", available categories are:" << m_categories.keys()
- << ". Defaulting to category \"media\"";
- return;
- }
-
- m_startRequiresInit = true;
- m_streamType = streamType;
- m_category = category;
-#endif // ANDROID
-}
-
-QString QOpenSLESAudioOutput::category() const
-{
- return m_category;
-}
-
-void QOpenSLESAudioOutput::onEOSEvent()
-{
- if (m_state != QAudio::ActiveState)
- return;
-
- SLBufferQueueState state;
- if (SL_RESULT_SUCCESS != (*m_bufferQueueItf)->GetState(m_bufferQueueItf, &state))
- return;
-
- if (state.count > 0)
- return;
-
- setState(QAudio::IdleState);
- setError(QAudio::UnderrunError);
-}
-
-void QOpenSLESAudioOutput::onBytesProcessed(qint64 bytes)
-{
- m_processedBytes += bytes;
-}
-
-void QOpenSLESAudioOutput::bufferAvailable(quint32 count, quint32 playIndex)
-{
- Q_UNUSED(count);
- Q_UNUSED(playIndex);
-
- if (m_state == QAudio::StoppedState)
- return;
-
- if (!m_pullMode) { // We're in push mode.
- // Signal that there is a new open slot in the buffer and return
- const int val = m_availableBuffers.fetchAndAddRelease(1) + 1;
- if (val == BUFFER_COUNT)
- QMetaObject::invokeMethod(this, "onEOSEvent", Qt::QueuedConnection);
-
- return;
- }
-
- // We're in pull mode.
- const int index = m_nextBuffer * m_bufferSize;
- const qint64 readSize = m_audioSource->read(m_buffers + index, m_bufferSize);
-
- if (readSize < 1) {
- QMetaObject::invokeMethod(this, "onEOSEvent", Qt::QueuedConnection);
- return;
- }
-
-
- if (SL_RESULT_SUCCESS != (*m_bufferQueueItf)->Enqueue(m_bufferQueueItf,
- m_buffers + index,
- readSize)) {
- setError(QAudio::FatalError);
- destroyPlayer();
- return;
- }
-
- m_nextBuffer = (m_nextBuffer + 1) % BUFFER_COUNT;
- QMetaObject::invokeMethod(this, "onBytesProcessed", Qt::QueuedConnection, Q_ARG(qint64, readSize));
-}
-
-void QOpenSLESAudioOutput::playCallback(SLPlayItf player, void *ctx, SLuint32 event)
-{
- Q_UNUSED(player);
- QOpenSLESAudioOutput *audioOutput = reinterpret_cast<QOpenSLESAudioOutput *>(ctx);
- if (event & SL_PLAYEVENT_HEADATEND)
- QMetaObject::invokeMethod(audioOutput, "onEOSEvent", Qt::QueuedConnection);
- if (event & SL_PLAYEVENT_HEADATNEWPOS)
- Q_EMIT audioOutput->notify();
-
-}
-
-void QOpenSLESAudioOutput::bufferQueueCallback(SLBufferQueueItf bufferQueue, void *ctx)
-{
- SLBufferQueueState state;
- (*bufferQueue)->GetState(bufferQueue, &state);
- QOpenSLESAudioOutput *audioOutput = reinterpret_cast<QOpenSLESAudioOutput *>(ctx);
- audioOutput->bufferAvailable(state.count, state.playIndex);
-}
-
-bool QOpenSLESAudioOutput::preparePlayer()
-{
- if (m_startRequiresInit)
- destroyPlayer();
- else
- return true;
-
- SLEngineItf engine = QOpenSLESEngine::instance()->slEngine();
- if (!engine) {
- qWarning() << "No engine";
- setError(QAudio::FatalError);
- return false;
- }
-
- SLDataLocator_BufferQueue bufferQueueLocator = { SL_DATALOCATOR_BUFFERQUEUE, BUFFER_COUNT };
- SLDataFormat_PCM pcmFormat = QOpenSLESEngine::audioFormatToSLFormatPCM(m_format);
-
- SLDataSource audioSrc = { &bufferQueueLocator, &pcmFormat };
-
- // OutputMix
- if (SL_RESULT_SUCCESS != (*engine)->CreateOutputMix(engine,
- &m_outputMixObject,
- 0,
- nullptr,
- nullptr)) {
- qWarning() << "Unable to create output mix";
- setError(QAudio::FatalError);
- return false;
- }
-
- if (SL_RESULT_SUCCESS != (*m_outputMixObject)->Realize(m_outputMixObject, SL_BOOLEAN_FALSE)) {
- qWarning() << "Unable to initialize output mix";
- setError(QAudio::FatalError);
- return false;
- }
-
- SLDataLocator_OutputMix outputMixLocator = { SL_DATALOCATOR_OUTPUTMIX, m_outputMixObject };
- SLDataSink audioSink = { &outputMixLocator, nullptr };
-
-#ifndef ANDROID
- const int iids = 2;
- const SLInterfaceID ids[iids] = { SL_IID_BUFFERQUEUE, SL_IID_VOLUME };
- const SLboolean req[iids] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
-#else
- const int iids = 3;
- const SLInterfaceID ids[iids] = { SL_IID_BUFFERQUEUE,
- SL_IID_VOLUME,
- SL_IID_ANDROIDCONFIGURATION };
- const SLboolean req[iids] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
-#endif // ANDROID
-
- // AudioPlayer
- if (SL_RESULT_SUCCESS != (*engine)->CreateAudioPlayer(engine,
- &m_playerObject,
- &audioSrc,
- &audioSink,
- iids,
- ids,
- req)) {
- qWarning() << "Unable to create AudioPlayer";
- setError(QAudio::OpenError);
- return false;
- }
-
-#ifdef ANDROID
- // Set profile/category
- SLAndroidConfigurationItf playerConfig;
- if (SL_RESULT_SUCCESS == (*m_playerObject)->GetInterface(m_playerObject,
- SL_IID_ANDROIDCONFIGURATION,
- &playerConfig)) {
- (*playerConfig)->SetConfiguration(playerConfig,
- SL_ANDROID_KEY_STREAM_TYPE,
- &m_streamType,
- sizeof(SLint32));
- }
-#endif // ANDROID
-
- if (SL_RESULT_SUCCESS != (*m_playerObject)->Realize(m_playerObject, SL_BOOLEAN_FALSE)) {
- qWarning() << "Unable to initialize AudioPlayer";
- setError(QAudio::OpenError);
- return false;
- }
-
- // Buffer interface
- if (SL_RESULT_SUCCESS != (*m_playerObject)->GetInterface(m_playerObject,
- SL_IID_BUFFERQUEUE,
- &m_bufferQueueItf)) {
- setError(QAudio::FatalError);
- return false;
- }
-
- if (SL_RESULT_SUCCESS != (*m_bufferQueueItf)->RegisterCallback(m_bufferQueueItf,
- bufferQueueCallback,
- this)) {
- setError(QAudio::FatalError);
- return false;
- }
-
- // Play interface
- if (SL_RESULT_SUCCESS != (*m_playerObject)->GetInterface(m_playerObject,
- SL_IID_PLAY,
- &m_playItf)) {
- setError(QAudio::FatalError);
- return false;
- }
-
- if (SL_RESULT_SUCCESS != (*m_playItf)->RegisterCallback(m_playItf, playCallback, this)) {
- setError(QAudio::FatalError);
- return false;
- }
-
- if (m_notifyInterval && SL_RESULT_SUCCESS == (*m_playItf)->SetPositionUpdatePeriod(m_playItf,
- m_notifyInterval)) {
- m_eventMask |= SL_PLAYEVENT_HEADATNEWPOS;
- }
-
- if (SL_RESULT_SUCCESS != (*m_playItf)->SetCallbackEventsMask(m_playItf, m_eventMask)) {
- setError(QAudio::FatalError);
- return false;
- }
-
- // Volume interface
- if (SL_RESULT_SUCCESS != (*m_playerObject)->GetInterface(m_playerObject,
- SL_IID_VOLUME,
- &m_volumeItf)) {
- setError(QAudio::FatalError);
- return false;
- }
-
- setVolume(m_volume);
-
- const int lowLatencyBufferSize = QOpenSLESEngine::getLowLatencyBufferSize(m_format);
- const int defaultBufferSize = QOpenSLESEngine::getDefaultBufferSize(m_format);
-
- if (defaultBufferSize <= 0) {
- qWarning() << "Unable to get minimum buffer size, returned" << defaultBufferSize;
- setError(QAudio::FatalError);
- return false;
- }
-
- // Buffer size
- if (m_bufferSize <= 0) {
- m_bufferSize = defaultBufferSize;
- } else if (QOpenSLESEngine::supportsLowLatency()) {
- if (m_bufferSize < lowLatencyBufferSize)
- m_bufferSize = lowLatencyBufferSize;
- } else if (m_bufferSize < defaultBufferSize) {
- m_bufferSize = defaultBufferSize;
- }
-
- m_periodSize = m_bufferSize;
-
- if (!m_buffers)
- m_buffers = new char[BUFFER_COUNT * m_bufferSize];
-
- m_clockStamp.restart();
- setError(QAudio::NoError);
- m_startRequiresInit = false;
-
- return true;
-}
-
-void QOpenSLESAudioOutput::destroyPlayer()
-{
- if (m_state != QAudio::StoppedState)
- stopPlayer();
-
- if (m_playerObject) {
- (*m_playerObject)->Destroy(m_playerObject);
- m_playerObject = nullptr;
- }
-
- if (m_outputMixObject) {
- (*m_outputMixObject)->Destroy(m_outputMixObject);
- m_outputMixObject = nullptr;
- }
-
- if (!m_pullMode && m_audioSource) {
- m_audioSource->close();
- delete m_audioSource;
- m_audioSource = nullptr;
- }
-
- delete [] m_buffers;
- m_buffers = nullptr;
- m_processedBytes = 0;
- m_nextBuffer = 0;
- m_availableBuffers.storeRelease(BUFFER_COUNT);
- m_playItf = nullptr;
- m_volumeItf = nullptr;
- m_bufferQueueItf = nullptr;
- m_startRequiresInit = true;
-}
-
-void QOpenSLESAudioOutput::stopPlayer()
-{
- setState(QAudio::StoppedState);
-
- if (m_audioSource && !m_pullMode) {
- m_audioSource->close();
- delete m_audioSource;
- m_audioSource = nullptr;
- }
-
- // We need to change the state manually...
- if (m_playItf)
- (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_STOPPED);
-
- if (m_bufferQueueItf && SL_RESULT_SUCCESS != (*m_bufferQueueItf)->Clear(m_bufferQueueItf))
- qWarning() << "Unable to clear buffer";
-}
-
-void QOpenSLESAudioOutput::startPlayer()
-{
- if (QOpenSLESEngine::printDebugInfo())
- openSlDebugInfo();
-
- if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PLAYING)) {
- setError(QAudio::FatalError);
- destroyPlayer();
- }
-}
-
-qint64 QOpenSLESAudioOutput::writeData(const char *data, qint64 len)
-{
- if (!len)
- return 0;
-
- if (len > m_bufferSize)
- len = m_bufferSize;
-
- // Acquire one slot in the buffer
- const int before = m_availableBuffers.fetchAndAddAcquire(-1);
-
- // If there where no vacant slots, then we just overdrew the buffer account...
- if (before < 1) {
- m_availableBuffers.fetchAndAddRelease(1);
- return 0;
- }
-
- const int index = m_nextBuffer * m_bufferSize;
- ::memcpy(m_buffers + index, data, len);
- const SLuint32 res = (*m_bufferQueueItf)->Enqueue(m_bufferQueueItf,
- m_buffers + index,
- len);
-
- // If we where unable to enqueue a new buffer, give back the acquired slot.
- if (res == SL_RESULT_BUFFER_INSUFFICIENT) {
- m_availableBuffers.fetchAndAddRelease(1);
- return 0;
- }
-
- if (res != SL_RESULT_SUCCESS) {
- setError(QAudio::FatalError);
- destroyPlayer();
- return -1;
- }
-
- m_processedBytes += len;
- setState(QAudio::ActiveState);
- setError(QAudio::NoError);
- m_nextBuffer = (m_nextBuffer + 1) % BUFFER_COUNT;
-
- return len;
-}
-
-inline void QOpenSLESAudioOutput::setState(QAudio::State state)
-{
- if (m_state == state)
- return;
-
- m_state = state;
- Q_EMIT stateChanged(m_state);
-}
-
-inline void QOpenSLESAudioOutput::setError(QAudio::Error error)
-{
- if (m_error == error)
- return;
-
- m_error = error;
- Q_EMIT errorChanged(m_error);
-}
-
-inline SLmillibel QOpenSLESAudioOutput::adjustVolume(qreal vol)
-{
- if (qFuzzyIsNull(vol))
- return SL_MILLIBEL_MIN;
-
- if (qFuzzyCompare(vol, qreal(1.0)))
- return 0;
-
- return QAudio::convertVolume(vol, QAudio::LinearVolumeScale, QAudio::DecibelVolumeScale) * 100;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/opensles/qopenslesaudiooutput.h b/src/plugins/opensles/qopenslesaudiooutput.h
deleted file mode 100644
index 80959df30..000000000
--- a/src/plugins/opensles/qopenslesaudiooutput.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QOPENSLESAUDIOOUTPUT_H
-#define QOPENSLESAUDIOOUTPUT_H
-
-#include <qaudiosystem.h>
-#include <SLES/OpenSLES.h>
-#include <qbytearray.h>
-#include <qmap.h>
-#include <QElapsedTimer>
-#include <QIODevice>
-
-QT_BEGIN_NAMESPACE
-
-class QOpenSLESAudioOutput : public QAbstractAudioOutput
-{
- Q_OBJECT
-
-public:
- QOpenSLESAudioOutput(const QByteArray &device);
- ~QOpenSLESAudioOutput();
-
- void start(QIODevice *device) override;
- QIODevice *start() override;
- void stop() override;
- void reset() override;
- void suspend() override;
- void resume() override;
- int bytesFree() const override;
- int periodSize() const override;
- void setBufferSize(int value) override;
- int bufferSize() const override;
- void setNotifyInterval(int milliSeconds) override;
- int notifyInterval() const override;
- qint64 processedUSecs() const override;
- qint64 elapsedUSecs() const override;
- QAudio::Error error() const override;
- QAudio::State state() const override;
- void setFormat(const QAudioFormat &format) override;
- QAudioFormat format() const override;
-
- void setVolume(qreal volume) override;
- qreal volume() const override;
-
- void setCategory(const QString &category) override;
- QString category() const override;
-
-private:
- friend class SLIODevicePrivate;
-
- Q_INVOKABLE void onEOSEvent();
- Q_INVOKABLE void onBytesProcessed(qint64 bytes);
- void bufferAvailable(quint32 count, quint32 playIndex);
-
- static void playCallback(SLPlayItf playItf, void *ctx, SLuint32 event);
- static void bufferQueueCallback(SLBufferQueueItf bufferQueue, void *ctx);
-
- bool preparePlayer();
- void destroyPlayer();
- void stopPlayer();
- void startPlayer();
- qint64 writeData(const char *data, qint64 len);
-
- void setState(QAudio::State state);
- void setError(QAudio::Error error);
-
- SLmillibel adjustVolume(qreal vol);
-
- QByteArray m_deviceName;
- QAudio::State m_state;
- QAudio::Error m_error;
- SLObjectItf m_outputMixObject;
- SLObjectItf m_playerObject;
- SLPlayItf m_playItf;
- SLVolumeItf m_volumeItf;
- SLBufferQueueItf m_bufferQueueItf;
- QIODevice *m_audioSource;
- char *m_buffers;
- qreal m_volume;
- bool m_pullMode;
- int m_nextBuffer;
- int m_bufferSize;
- int m_notifyInterval;
- int m_periodSize;
- qint64 m_elapsedTime;
- qint64 m_processedBytes;
- QAtomicInt m_availableBuffers;
- SLuint32 m_eventMask;
- bool m_startRequiresInit;
-
- qint32 m_streamType;
- QElapsedTimer m_clockStamp;
- QAudioFormat m_format;
- QString m_category;
- static QMap<QString, qint32> m_categories;
-};
-
-class SLIODevicePrivate : public QIODevice
-{
- Q_OBJECT
-
-public:
- inline SLIODevicePrivate(QOpenSLESAudioOutput *audio) : m_audioDevice(audio) {}
- inline ~SLIODevicePrivate() override {}
-
-protected:
- inline qint64 readData(char *, qint64) override { return 0; }
- inline qint64 writeData(const char *data, qint64 len) override;
-
-private:
- QOpenSLESAudioOutput *m_audioDevice;
-};
-
-qint64 SLIODevicePrivate::writeData(const char *data, qint64 len)
-{
- Q_ASSERT(m_audioDevice);
- return m_audioDevice->writeData(data, len);
-}
-
-QT_END_NAMESPACE
-
-#endif // QOPENSLESAUDIOOUTPUT_H
diff --git a/src/plugins/opensles/qopenslesdeviceinfo.cpp b/src/plugins/opensles/qopenslesdeviceinfo.cpp
deleted file mode 100644
index 8aaf67c76..000000000
--- a/src/plugins/opensles/qopenslesdeviceinfo.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qopenslesdeviceinfo.h"
-
-#include "qopenslesengine.h"
-
-QT_BEGIN_NAMESPACE
-
-QOpenSLESDeviceInfo::QOpenSLESDeviceInfo(const QByteArray &device, QAudio::Mode mode)
- : m_engine(QOpenSLESEngine::instance())
- , m_device(device)
- , m_mode(mode)
-{
-}
-
-bool QOpenSLESDeviceInfo::isFormatSupported(const QAudioFormat &format) const
-{
- QOpenSLESDeviceInfo *that = const_cast<QOpenSLESDeviceInfo*>(this);
- return that->supportedCodecs().contains(format.codec())
- && that->supportedSampleRates().contains(format.sampleRate())
- && that->supportedChannelCounts().contains(format.channelCount())
- && that->supportedSampleSizes().contains(format.sampleSize())
- && that->supportedByteOrders().contains(format.byteOrder())
- && that->supportedSampleTypes().contains(format.sampleType());
-}
-
-QAudioFormat QOpenSLESDeviceInfo::preferredFormat() const
-{
- QAudioFormat format;
- format.setCodec(QStringLiteral("audio/pcm"));
- format.setSampleSize(16);
- format.setSampleType(QAudioFormat::SignedInt);
- format.setSampleRate(QOpenSLESEngine::getOutputValue(QOpenSLESEngine::SampleRate, 48000));
- format.setChannelCount(m_mode == QAudio::AudioInput ? 1 : 2);
- return format;
-}
-
-QString QOpenSLESDeviceInfo::deviceName() const
-{
- return m_device;
-}
-
-QStringList QOpenSLESDeviceInfo::supportedCodecs()
-{
- return QStringList() << QStringLiteral("audio/pcm");
-}
-
-QList<int> QOpenSLESDeviceInfo::supportedSampleRates()
-{
- return m_engine->supportedSampleRates(m_mode);
-}
-
-QList<int> QOpenSLESDeviceInfo::supportedChannelCounts()
-{
- return m_engine->supportedChannelCounts(m_mode);
-}
-
-QList<int> QOpenSLESDeviceInfo::supportedSampleSizes()
-{
- if (m_mode == QAudio::AudioInput)
- return QList<int>() << 16;
- else
- return QList<int>() << 8 << 16;
-}
-
-QList<QAudioFormat::Endian> QOpenSLESDeviceInfo::supportedByteOrders()
-{
- return QList<QAudioFormat::Endian>() << QAudioFormat::LittleEndian;
-}
-
-QList<QAudioFormat::SampleType> QOpenSLESDeviceInfo::supportedSampleTypes()
-{
- return QList<QAudioFormat::SampleType>() << QAudioFormat::SignedInt;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/opensles/qopenslesdeviceinfo.h b/src/plugins/opensles/qopenslesdeviceinfo.h
deleted file mode 100644
index ebeb6b4b2..000000000
--- a/src/plugins/opensles/qopenslesdeviceinfo.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QOPENSLESDEVICEINFO_H
-#define QOPENSLESDEVICEINFO_H
-
-#include <qaudiosystem.h>
-
-QT_BEGIN_NAMESPACE
-
-class QOpenSLESEngine;
-
-class QOpenSLESDeviceInfo : public QAbstractAudioDeviceInfo
-{
- Q_OBJECT
-
-public:
- QOpenSLESDeviceInfo(const QByteArray &device, QAudio::Mode mode);
- ~QOpenSLESDeviceInfo() {}
-
- QAudioFormat preferredFormat() const;
- bool isFormatSupported(const QAudioFormat &format) const;
- QString deviceName() const;
- QStringList supportedCodecs();
- QList<int> supportedSampleRates();
- QList<int> supportedChannelCounts();
- QList<int> supportedSampleSizes();
- QList<QAudioFormat::Endian> supportedByteOrders();
- QList<QAudioFormat::SampleType> supportedSampleTypes();
-
-private:
- QOpenSLESEngine *m_engine;
- QByteArray m_device;
- QAudio::Mode m_mode;
-};
-
-QT_END_NAMESPACE
-
-#endif // QOPENSLESDEVICEINFO_H
diff --git a/src/plugins/opensles/qopenslesengine.cpp b/src/plugins/opensles/qopenslesengine.cpp
deleted file mode 100644
index 36025dcfd..000000000
--- a/src/plugins/opensles/qopenslesengine.cpp
+++ /dev/null
@@ -1,369 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qopenslesengine.h"
-
-#include "qopenslesaudioinput.h"
-#include <qdebug.h>
-
-#ifdef ANDROID
-#include <SLES/OpenSLES_Android.h>
-#include <QtCore/private/qjnihelpers_p.h>
-#include <QtCore/private/qjni_p.h>
-#endif
-
-#define MINIMUM_PERIOD_TIME_MS 5
-#define DEFAULT_PERIOD_TIME_MS 50
-
-#define CheckError(message) if (result != SL_RESULT_SUCCESS) { qWarning(message); return; }
-
-Q_GLOBAL_STATIC(QOpenSLESEngine, openslesEngine);
-
-QOpenSLESEngine::QOpenSLESEngine()
- : m_engineObject(0)
- , m_engine(0)
- , m_checkedInputFormats(false)
-{
- SLresult result;
-
- result = slCreateEngine(&m_engineObject, 0, 0, 0, 0, 0);
- CheckError("Failed to create engine");
-
- result = (*m_engineObject)->Realize(m_engineObject, SL_BOOLEAN_FALSE);
- CheckError("Failed to realize engine");
-
- result = (*m_engineObject)->GetInterface(m_engineObject, SL_IID_ENGINE, &m_engine);
- CheckError("Failed to get engine interface");
-}
-
-QOpenSLESEngine::~QOpenSLESEngine()
-{
- if (m_engineObject)
- (*m_engineObject)->Destroy(m_engineObject);
-}
-
-QOpenSLESEngine *QOpenSLESEngine::instance()
-{
- return openslesEngine();
-}
-
-SLDataFormat_PCM QOpenSLESEngine::audioFormatToSLFormatPCM(const QAudioFormat &format)
-{
- SLDataFormat_PCM format_pcm;
- format_pcm.formatType = SL_DATAFORMAT_PCM;
- format_pcm.numChannels = format.channelCount();
- format_pcm.samplesPerSec = format.sampleRate() * 1000;
- format_pcm.bitsPerSample = format.sampleSize();
- format_pcm.containerSize = format.sampleSize();
- format_pcm.channelMask = (format.channelCount() == 1 ?
- SL_SPEAKER_FRONT_CENTER :
- SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT);
- format_pcm.endianness = (format.byteOrder() == QAudioFormat::LittleEndian ?
- SL_BYTEORDER_LITTLEENDIAN :
- SL_BYTEORDER_BIGENDIAN);
- return format_pcm;
-
-}
-
-QByteArray QOpenSLESEngine::defaultDevice(QAudio::Mode mode) const
-{
- const auto &devices = availableDevices(mode);
- return !devices.isEmpty() ? devices.first() : QByteArray();
-}
-
-QList<QByteArray> QOpenSLESEngine::availableDevices(QAudio::Mode mode) const
-{
- QList<QByteArray> devices;
- if (mode == QAudio::AudioInput) {
-#ifdef ANDROID
- devices << QT_ANDROID_PRESET_MIC
- << QT_ANDROID_PRESET_CAMCORDER
- << QT_ANDROID_PRESET_VOICE_RECOGNITION
- << QT_ANDROID_PRESET_VOICE_COMMUNICATION;
-#else
- devices << "default";
-#endif
- } else {
- devices << "default";
- }
- return devices;
-}
-
-QList<int> QOpenSLESEngine::supportedChannelCounts(QAudio::Mode mode) const
-{
- if (mode == QAudio::AudioInput) {
- if (!m_checkedInputFormats)
- const_cast<QOpenSLESEngine *>(this)->checkSupportedInputFormats();
- return m_supportedInputChannelCounts;
- } else {
- return QList<int>() << 1 << 2;
- }
-}
-
-QList<int> QOpenSLESEngine::supportedSampleRates(QAudio::Mode mode) const
-{
- if (mode == QAudio::AudioInput) {
- if (!m_checkedInputFormats)
- const_cast<QOpenSLESEngine *>(this)->checkSupportedInputFormats();
- return m_supportedInputSampleRates;
- } else {
- return QList<int>() << 8000 << 11025 << 12000 << 16000 << 22050
- << 24000 << 32000 << 44100 << 48000;
- }
-}
-
-int QOpenSLESEngine::getOutputValue(QOpenSLESEngine::OutputValue type, int defaultValue)
-{
-#if defined(Q_OS_ANDROID)
- static int sampleRate = 0;
- static int framesPerBuffer = 0;
- static const int sdkVersion = QtAndroidPrivate::androidSdkVersion();
-
- if (sdkVersion < 17) // getProperty() was added in API level 17...
- return defaultValue;
-
- if (type == FramesPerBuffer && framesPerBuffer != 0)
- return framesPerBuffer;
-
- if (type == SampleRate && sampleRate != 0)
- return sampleRate;
-
- QJNIObjectPrivate ctx(QtAndroidPrivate::activity());
- if (!ctx.isValid())
- return defaultValue;
-
-
- QJNIObjectPrivate audioServiceString = ctx.getStaticObjectField("android/content/Context",
- "AUDIO_SERVICE",
- "Ljava/lang/String;");
- QJNIObjectPrivate am = ctx.callObjectMethod("getSystemService",
- "(Ljava/lang/String;)Ljava/lang/Object;",
- audioServiceString.object());
- if (!am.isValid())
- return defaultValue;
-
- QJNIObjectPrivate sampleRateField = QJNIObjectPrivate::getStaticObjectField("android/media/AudioManager",
- "PROPERTY_OUTPUT_SAMPLE_RATE",
- "Ljava/lang/String;");
- QJNIObjectPrivate framesPerBufferField = QJNIObjectPrivate::getStaticObjectField("android/media/AudioManager",
- "PROPERTY_OUTPUT_FRAMES_PER_BUFFER",
- "Ljava/lang/String;");
-
- QJNIObjectPrivate sampleRateString = am.callObjectMethod("getProperty",
- "(Ljava/lang/String;)Ljava/lang/String;",
- sampleRateField.object());
- QJNIObjectPrivate framesPerBufferString = am.callObjectMethod("getProperty",
- "(Ljava/lang/String;)Ljava/lang/String;",
- framesPerBufferField.object());
-
- if (!sampleRateString.isValid() || !framesPerBufferString.isValid())
- return defaultValue;
-
- framesPerBuffer = framesPerBufferString.toString().toInt();
- sampleRate = sampleRateString.toString().toInt();
-
- if (type == FramesPerBuffer)
- return framesPerBuffer;
-
- if (type == SampleRate)
- return sampleRate;
-
-#endif // Q_OS_ANDROID
-
- return defaultValue;
-}
-
-int QOpenSLESEngine::getDefaultBufferSize(const QAudioFormat &format)
-{
-#if defined(Q_OS_ANDROID)
- if (!format.isValid())
- return 0;
-
- const int channelConfig = [&format]() -> int
- {
- if (format.channelCount() == 1)
- return 4; /* MONO */
- else if (format.channelCount() == 2)
- return 12; /* STEREO */
- else if (format.channelCount() > 2)
- return 1052; /* SURROUND */
- else
- return 1; /* DEFAULT */
- }();
-
- const int audioFormat = [&format]() -> int
- {
- if (format.sampleType() == QAudioFormat::Float && QtAndroidPrivate::androidSdkVersion() >= 21)
- return 4; /* PCM_FLOAT */
- else if (format.sampleSize() == 8)
- return 3; /* PCM_8BIT */
- else if (format.sampleSize() == 16)
- return 2; /* PCM_16BIT*/
- else
- return 1; /* DEFAULT */
- }();
-
- const int sampleRate = format.sampleRate();
- const int minBufferSize = QJNIObjectPrivate::callStaticMethod<jint>("android/media/AudioTrack",
- "getMinBufferSize",
- "(III)I",
- sampleRate,
- channelConfig,
- audioFormat);
- return minBufferSize > 0 ? minBufferSize : format.bytesForDuration(DEFAULT_PERIOD_TIME_MS);
-#else
- return format.bytesForDuration(DEFAULT_PERIOD_TIME_MS);
-#endif // Q_OS_ANDROID
-}
-
-int QOpenSLESEngine::getLowLatencyBufferSize(const QAudioFormat &format)
-{
- return format.bytesForFrames(QOpenSLESEngine::getOutputValue(QOpenSLESEngine::FramesPerBuffer,
- format.framesForDuration(MINIMUM_PERIOD_TIME_MS)));
-}
-
-bool QOpenSLESEngine::supportsLowLatency()
-{
-#if defined(Q_OS_ANDROID)
- static int isSupported = -1;
-
- if (isSupported != -1)
- return (isSupported == 1);
-
- QJNIObjectPrivate ctx(QtAndroidPrivate::activity());
- if (!ctx.isValid())
- return false;
-
- QJNIObjectPrivate pm = ctx.callObjectMethod("getPackageManager", "()Landroid/content/pm/PackageManager;");
- if (!pm.isValid())
- return false;
-
- QJNIObjectPrivate audioFeatureField = QJNIObjectPrivate::getStaticObjectField("android/content/pm/PackageManager",
- "FEATURE_AUDIO_LOW_LATENCY",
- "Ljava/lang/String;");
- if (!audioFeatureField.isValid())
- return false;
-
- isSupported = pm.callMethod<jboolean>("hasSystemFeature",
- "(Ljava/lang/String;)Z",
- audioFeatureField.object());
- return (isSupported == 1);
-#else
- return true;
-#endif // Q_OS_ANDROID
-}
-
-bool QOpenSLESEngine::printDebugInfo()
-{
- return qEnvironmentVariableIsSet("QT_OPENSL_INFO");
-}
-
-void QOpenSLESEngine::checkSupportedInputFormats()
-{
- m_supportedInputChannelCounts = QList<int>() << 1;
- m_supportedInputSampleRates.clear();
-
- SLDataFormat_PCM defaultFormat;
- defaultFormat.formatType = SL_DATAFORMAT_PCM;
- defaultFormat.numChannels = 1;
- defaultFormat.samplesPerSec = SL_SAMPLINGRATE_44_1;
- defaultFormat.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
- defaultFormat.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16;
- defaultFormat.channelMask = SL_SPEAKER_FRONT_CENTER;
- defaultFormat.endianness = SL_BYTEORDER_LITTLEENDIAN;
-
- const SLuint32 rates[9] = { SL_SAMPLINGRATE_8,
- SL_SAMPLINGRATE_11_025,
- SL_SAMPLINGRATE_12,
- SL_SAMPLINGRATE_16,
- SL_SAMPLINGRATE_22_05,
- SL_SAMPLINGRATE_24,
- SL_SAMPLINGRATE_32,
- SL_SAMPLINGRATE_44_1,
- SL_SAMPLINGRATE_48 };
-
-
- // Test sampling rates
- for (int i = 0 ; i < 9; ++i) {
- SLDataFormat_PCM format = defaultFormat;
- format.samplesPerSec = rates[i];
-
- if (inputFormatIsSupported(format))
- m_supportedInputSampleRates.append(rates[i] / 1000);
-
- }
-
- // Test if stereo is supported
- {
- SLDataFormat_PCM format = defaultFormat;
- format.numChannels = 2;
- format.channelMask = 0;
- if (inputFormatIsSupported(format))
- m_supportedInputChannelCounts.append(2);
- }
-
- m_checkedInputFormats = true;
-}
-
-bool QOpenSLESEngine::inputFormatIsSupported(SLDataFormat_PCM format)
-{
- SLresult result;
- SLObjectItf recorder = 0;
- SLDataLocator_IODevice loc_dev = { SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT,
- SL_DEFAULTDEVICEID_AUDIOINPUT, NULL };
- SLDataSource audioSrc = { &loc_dev, NULL };
-
-#ifdef ANDROID
- SLDataLocator_AndroidSimpleBufferQueue loc_bq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 1 };
-#else
- SLDataLocator_BufferQueue loc_bq = { SL_DATALOCATOR_BUFFERQUEUE, 1 };
-#endif
- SLDataSink audioSnk = { &loc_bq, &format };
-
- result = (*m_engine)->CreateAudioRecorder(m_engine, &recorder, &audioSrc, &audioSnk, 0, 0, 0);
- if (result == SL_RESULT_SUCCESS)
- result = (*recorder)->Realize(recorder, false);
-
- if (result == SL_RESULT_SUCCESS) {
- (*recorder)->Destroy(recorder);
- return true;
- }
-
- return false;
-}
diff --git a/src/plugins/opensles/qopenslesengine.h b/src/plugins/opensles/qopenslesengine.h
deleted file mode 100644
index c36b21488..000000000
--- a/src/plugins/opensles/qopenslesengine.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QOPENSLESENGINE_H
-#define QOPENSLESENGINE_H
-
-#include <qglobal.h>
-#include <qaudio.h>
-#include <qlist.h>
-#include <qaudioformat.h>
-#include <SLES/OpenSLES.h>
-
-QT_BEGIN_NAMESPACE
-
-class QOpenSLESEngine
-{
-public:
- enum OutputValue { FramesPerBuffer, SampleRate };
-
- QOpenSLESEngine();
- ~QOpenSLESEngine();
-
- static QOpenSLESEngine *instance();
-
- SLEngineItf slEngine() const { return m_engine; }
-
- static SLDataFormat_PCM audioFormatToSLFormatPCM(const QAudioFormat &format);
-
- QByteArray defaultDevice(QAudio::Mode mode) const;
- QList<QByteArray> availableDevices(QAudio::Mode mode) const;
- QList<int> supportedChannelCounts(QAudio::Mode mode) const;
- QList<int> supportedSampleRates(QAudio::Mode mode) const;
-
- static int getOutputValue(OutputValue type, int defaultValue = 0);
- static int getDefaultBufferSize(const QAudioFormat &format);
- static int getLowLatencyBufferSize(const QAudioFormat &format);
- static bool supportsLowLatency();
- static bool printDebugInfo();
-
-private:
- void checkSupportedInputFormats();
- bool inputFormatIsSupported(SLDataFormat_PCM format);
-
- SLObjectItf m_engineObject;
- SLEngineItf m_engine;
-
- QList<int> m_supportedInputChannelCounts;
- QList<int> m_supportedInputSampleRates;
- bool m_checkedInputFormats;
-};
-
-QT_END_NAMESPACE
-
-#endif // QOPENSLESENGINE_H
diff --git a/src/plugins/opensles/qopenslesplugin.cpp b/src/plugins/opensles/qopenslesplugin.cpp
deleted file mode 100644
index 9a2fbbf79..000000000
--- a/src/plugins/opensles/qopenslesplugin.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qopenslesplugin.h"
-
-#include "qopenslesengine.h"
-#include "qopenslesdeviceinfo.h"
-#include "qopenslesaudioinput.h"
-#include "qopenslesaudiooutput.h"
-
-QT_BEGIN_NAMESPACE
-
-QOpenSLESPlugin::QOpenSLESPlugin(QObject *parent)
- : QAudioSystemPlugin(parent)
- , m_engine(QOpenSLESEngine::instance())
-{
-}
-
-QByteArray QOpenSLESPlugin::defaultDevice(QAudio::Mode mode) const
-{
- return m_engine->defaultDevice(mode);
-}
-
-QList<QByteArray> QOpenSLESPlugin::availableDevices(QAudio::Mode mode) const
-{
- return m_engine->availableDevices(mode);
-}
-
-QAbstractAudioInput *QOpenSLESPlugin::createInput(const QByteArray &device)
-{
- return new QOpenSLESAudioInput(device);
-}
-
-QAbstractAudioOutput *QOpenSLESPlugin::createOutput(const QByteArray &device)
-{
- return new QOpenSLESAudioOutput(device);
-}
-
-QAbstractAudioDeviceInfo *QOpenSLESPlugin::createDeviceInfo(const QByteArray &device, QAudio::Mode mode)
-{
- return new QOpenSLESDeviceInfo(device, mode);
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/plugins/opensles/qopenslesplugin.h b/src/plugins/opensles/qopenslesplugin.h
deleted file mode 100644
index d45a47923..000000000
--- a/src/plugins/opensles/qopenslesplugin.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QOPENSLESPLUGIN_H
-#define QOPENSLESPLUGIN_H
-
-#include <QtMultimedia/qaudiosystemplugin.h>
-#include <QtMultimedia/private/qaudiosystempluginext_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QOpenSLESEngine;
-
-class QOpenSLESPlugin : public QAudioSystemPlugin, public QAudioSystemPluginExtension
-{
- Q_OBJECT
-
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.audiosystemfactory/5.0" FILE "opensles.json")
- Q_INTERFACES(QAudioSystemPluginExtension)
-
-public:
- QOpenSLESPlugin(QObject *parent = 0);
- ~QOpenSLESPlugin() {}
-
- QByteArray defaultDevice(QAudio::Mode mode) const;
- QList<QByteArray> availableDevices(QAudio::Mode mode) const;
- QAbstractAudioInput *createInput(const QByteArray &device);
- QAbstractAudioOutput *createOutput(const QByteArray &device);
- QAbstractAudioDeviceInfo *createDeviceInfo(const QByteArray &device, QAudio::Mode mode);
-
-private:
- QOpenSLESEngine *m_engine;
-};
-
-QT_END_NAMESPACE
-
-#endif // QOPENSLESPLUGIN_H
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro
deleted file mode 100644
index a087e8182..000000000
--- a/src/plugins/plugins.pro
+++ /dev/null
@@ -1,54 +0,0 @@
-######################################################################
-#
-# Qt Multimedia
-#
-######################################################################
-
-TEMPLATE = subdirs
-QT_FOR_CONFIG += multimedia-private
-
-SUBDIRS += m3u
-
-qtHaveModule(quick) {
- SUBDIRS += videonode
-}
-
-android {
- SUBDIRS += android opensles
-}
-
-qnx {
- qtConfig(mmrenderer): SUBDIRS += qnx
- SUBDIRS += audiocapture
-}
-
-qnx {
- SUBDIRS += qnx-audio
-}
-
-win32: {
- SUBDIRS += audiocapture \
- windowsaudio
-
- qtConfig(directshow): SUBDIRS += directshow
- qtConfig(wmf): SUBDIRS += wmf
-}
-
-qtConfig(gstreamer): SUBDIRS += gstreamer
-
-unix:!mac:!android {
- !qtConfig(gstreamer): SUBDIRS += audiocapture
-
- qtConfig(pulseaudio): SUBDIRS += pulseaudio
- qtConfig(alsa): SUBDIRS += alsa
-}
-
-darwin:!watchos {
- SUBDIRS += audiocapture coreaudio
- qtConfig(avfoundation): SUBDIRS += avfoundation
-}
-
-qtConfig(resourcepolicy) {
- SUBDIRS += resourcepolicy
-}
-
diff --git a/src/plugins/pulseaudio/pulseaudio.json b/src/plugins/pulseaudio/pulseaudio.json
deleted file mode 100644
index a31d52107..000000000
--- a/src/plugins/pulseaudio/pulseaudio.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": ["default"]
-}
diff --git a/src/plugins/pulseaudio/pulseaudio.pro b/src/plugins/pulseaudio/pulseaudio.pro
deleted file mode 100644
index c6339e9e8..000000000
--- a/src/plugins/pulseaudio/pulseaudio.pro
+++ /dev/null
@@ -1,25 +0,0 @@
-TARGET = qtmedia_pulse
-QT += multimedia-private
-
-QMAKE_USE += pulseaudio
-
-HEADERS += qpulseaudioplugin.h \
- qaudiodeviceinfo_pulse.h \
- qaudiooutput_pulse.h \
- qaudioinput_pulse.h \
- qpulseaudioengine.h \
- qpulsehelpers.h
-
-SOURCES += qpulseaudioplugin.cpp \
- qaudiodeviceinfo_pulse.cpp \
- qaudiooutput_pulse.cpp \
- qaudioinput_pulse.cpp \
- qpulseaudioengine.cpp \
- qpulsehelpers.cpp
-
-OTHER_FILES += \
- pulseaudio.json
-
-PLUGIN_TYPE = audio
-PLUGIN_CLASS_NAME = QPulseAudioPlugin
-load(qt_plugin)
diff --git a/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.cpp b/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.cpp
deleted file mode 100644
index c9cdfb3c5..000000000
--- a/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qaudiodeviceinfo_pulse.h"
-#include "qpulseaudioengine.h"
-#include "qpulsehelpers.h"
-
-QT_BEGIN_NAMESPACE
-
-QPulseAudioDeviceInfo::QPulseAudioDeviceInfo(const QByteArray &device, QAudio::Mode mode)
- : m_device(device)
- , m_mode(mode)
-{
-}
-
-bool QPulseAudioDeviceInfo::isFormatSupported(const QAudioFormat &format) const
-{
- pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(format);
- if (!pa_sample_spec_valid(&spec))
- return false;
-
- return true;
-}
-
-QAudioFormat QPulseAudioDeviceInfo::preferredFormat() const
-{
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- QAudioFormat format = pulseEngine->m_preferredFormats.value(m_device);
- return format;
-}
-
-QString QPulseAudioDeviceInfo::deviceName() const
-{
- return m_device;
-}
-
-QStringList QPulseAudioDeviceInfo::supportedCodecs()
-{
- return QStringList() << "audio/pcm";
-}
-
-QList<int> QPulseAudioDeviceInfo::supportedSampleRates()
-{
- return QList<int>() << 8000 << 11025 << 22050 << 44100 << 48000;
-}
-
-QList<int> QPulseAudioDeviceInfo::supportedChannelCounts()
-{
- return QList<int>() << 1 << 2 << 4 << 6 << 8;
-}
-
-QList<int> QPulseAudioDeviceInfo::supportedSampleSizes()
-{
- return QList<int>() << 8 << 16 << 24 << 32;
-}
-
-QList<QAudioFormat::Endian> QPulseAudioDeviceInfo::supportedByteOrders()
-{
- return QList<QAudioFormat::Endian>() << QAudioFormat::BigEndian << QAudioFormat::LittleEndian;
-}
-
-QList<QAudioFormat::SampleType> QPulseAudioDeviceInfo::supportedSampleTypes()
-{
- return QList<QAudioFormat::SampleType>() << QAudioFormat::SignedInt << QAudioFormat::UnSignedInt << QAudioFormat::Float;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.h b/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.h
deleted file mode 100644
index 1cec772c0..000000000
--- a/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIODEVICEINFOPULSE_H
-#define QAUDIODEVICEINFOPULSE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qbytearray.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qlist.h>
-
-#include "qaudio.h"
-#include "qaudiodeviceinfo.h"
-#include "qaudiosystem.h"
-
-QT_BEGIN_NAMESPACE
-
-class QPulseAudioDeviceInfo : public QAbstractAudioDeviceInfo
-{
- Q_OBJECT
-
-public:
- QPulseAudioDeviceInfo(const QByteArray &device, QAudio::Mode mode);
- ~QPulseAudioDeviceInfo() {}
-
- QAudioFormat preferredFormat() const override;
- bool isFormatSupported(const QAudioFormat &format) const override;
- QString deviceName() const override;
- QStringList supportedCodecs() override;
- QList<int> supportedSampleRates() override;
- QList<int> supportedChannelCounts() override;
- QList<int> supportedSampleSizes() override;
- QList<QAudioFormat::Endian> supportedByteOrders() override;
- QList<QAudioFormat::SampleType> supportedSampleTypes() override;
-
-private:
- QByteArray m_device;
- QAudio::Mode m_mode;
-};
-
-QT_END_NAMESPACE
-
-#endif
-
diff --git a/src/plugins/pulseaudio/qaudioinput_pulse.cpp b/src/plugins/pulseaudio/qaudioinput_pulse.cpp
deleted file mode 100644
index 3e7b4d79a..000000000
--- a/src/plugins/pulseaudio/qaudioinput_pulse.cpp
+++ /dev/null
@@ -1,682 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qmath.h>
-#include <private/qaudiohelpers_p.h>
-
-#include "qaudioinput_pulse.h"
-#include "qaudiodeviceinfo_pulse.h"
-#include "qpulseaudioengine.h"
-#include "qpulsehelpers.h"
-#include <sys/types.h>
-#include <unistd.h>
-
-QT_BEGIN_NAMESPACE
-
-const int PeriodTimeMs = 50;
-
-static void inputStreamReadCallback(pa_stream *stream, size_t length, void *userdata)
-{
- Q_UNUSED(userdata);
- Q_UNUSED(length);
- Q_UNUSED(stream);
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
-}
-
-static void inputStreamStateCallback(pa_stream *stream, void *userdata)
-{
- Q_UNUSED(userdata);
- pa_stream_state_t state = pa_stream_get_state(stream);
-#ifdef DEBUG_PULSE
- qDebug() << "Stream state: " << QPulseAudioInternal::stateToQString(state);
-#endif
- switch (state) {
- case PA_STREAM_CREATING:
- break;
- case PA_STREAM_READY: {
-#ifdef DEBUG_PULSE
- QPulseAudioInput *audioInput = static_cast<QPulseAudioInput*>(userdata);
- const pa_buffer_attr *buffer_attr = pa_stream_get_buffer_attr(stream);
- qDebug() << "*** maxlength: " << buffer_attr->maxlength;
- qDebug() << "*** prebuf: " << buffer_attr->prebuf;
- qDebug() << "*** fragsize: " << buffer_attr->fragsize;
- qDebug() << "*** minreq: " << buffer_attr->minreq;
- qDebug() << "*** tlength: " << buffer_attr->tlength;
-
- pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(audioInput->format());
- qDebug() << "*** bytes_to_usec: " << pa_bytes_to_usec(buffer_attr->fragsize, &spec);
-#endif
- }
- break;
- case PA_STREAM_TERMINATED:
- break;
- case PA_STREAM_FAILED:
- default:
- qWarning() << QString("Stream error: %1").arg(pa_strerror(pa_context_errno(pa_stream_get_context(stream))));
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
- break;
- }
-}
-
-static void inputStreamUnderflowCallback(pa_stream *stream, void *userdata)
-{
- Q_UNUSED(userdata);
- Q_UNUSED(stream);
- qWarning() << "Got a buffer underflow!";
-}
-
-static void inputStreamOverflowCallback(pa_stream *stream, void *userdata)
-{
- Q_UNUSED(stream);
- Q_UNUSED(userdata);
- qWarning() << "Got a buffer overflow!";
-}
-
-static void inputStreamSuccessCallback(pa_stream *stream, int success, void *userdata)
-{
- Q_UNUSED(stream);
- Q_UNUSED(userdata);
- Q_UNUSED(success);
-
- //if (!success)
- //TODO: Is cork success? i->operation_success = success;
-
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
-}
-
-QPulseAudioInput::QPulseAudioInput(const QByteArray &device)
- : m_totalTimeValue(0)
- , m_audioSource(0)
- , m_errorState(QAudio::NoError)
- , m_deviceState(QAudio::StoppedState)
- , m_volume(qreal(1.0f))
- , m_pullMode(true)
- , m_opened(false)
- , m_bytesAvailable(0)
- , m_bufferSize(0)
- , m_periodSize(0)
- , m_intervalTime(1000)
- , m_periodTime(PeriodTimeMs)
- , m_stream(0)
- , m_device(device)
-{
- m_timer = new QTimer(this);
- connect(m_timer, SIGNAL(timeout()), SLOT(userFeed()));
-}
-
-QPulseAudioInput::~QPulseAudioInput()
-{
- close();
- disconnect(m_timer, SIGNAL(timeout()));
- QCoreApplication::processEvents();
- delete m_timer;
-}
-
-void QPulseAudioInput::setError(QAudio::Error error)
-{
- if (m_errorState == error)
- return;
-
- m_errorState = error;
- emit errorChanged(error);
-}
-
-QAudio::Error QPulseAudioInput::error() const
-{
- return m_errorState;
-}
-
-void QPulseAudioInput::setState(QAudio::State state)
-{
- if (m_deviceState == state)
- return;
-
- m_deviceState = state;
- emit stateChanged(state);
-}
-
-QAudio::State QPulseAudioInput::state() const
-{
- return m_deviceState;
-}
-
-void QPulseAudioInput::setFormat(const QAudioFormat &format)
-{
- if (m_deviceState == QAudio::StoppedState)
- m_format = format;
-}
-
-QAudioFormat QPulseAudioInput::format() const
-{
- return m_format;
-}
-
-void QPulseAudioInput::start(QIODevice *device)
-{
- setState(QAudio::StoppedState);
- setError(QAudio::NoError);
-
- if (!m_pullMode && m_audioSource) {
- delete m_audioSource;
- m_audioSource = 0;
- }
-
- close();
-
- if (!open())
- return;
-
- m_pullMode = true;
- m_audioSource = device;
-
- setState(QAudio::ActiveState);
-}
-
-QIODevice *QPulseAudioInput::start()
-{
- setState(QAudio::StoppedState);
- setError(QAudio::NoError);
-
- if (!m_pullMode && m_audioSource) {
- delete m_audioSource;
- m_audioSource = 0;
- }
-
- close();
-
- if (!open())
- return nullptr;
-
- m_pullMode = false;
- m_audioSource = new PulseInputPrivate(this);
- m_audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
-
- setState(QAudio::IdleState);
-
- return m_audioSource;
-}
-
-void QPulseAudioInput::stop()
-{
- if (m_deviceState == QAudio::StoppedState)
- return;
-
- close();
-
- setError(QAudio::NoError);
- setState(QAudio::StoppedState);
-}
-
-bool QPulseAudioInput::open()
-{
- if (m_opened)
- return true;
-
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
-
- if (!pulseEngine->context() || pa_context_get_state(pulseEngine->context()) != PA_CONTEXT_READY) {
- setError(QAudio::FatalError);
- setState(QAudio::StoppedState);
- return false;
- }
-
- pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(m_format);
-
- if (!pa_sample_spec_valid(&spec)) {
- setError(QAudio::OpenError);
- setState(QAudio::StoppedState);
- return false;
- }
-
- m_spec = spec;
-
-#ifdef DEBUG_PULSE
-// QTime now(QTime::currentTime());
-// qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
-#endif
-
- if (m_streamName.isNull())
- m_streamName = QString(QLatin1String("QtmPulseStream-%1-%2")).arg(::getpid()).arg(quintptr(this)).toUtf8();
-
-#ifdef DEBUG_PULSE
- qDebug() << "Format: " << QPulseAudioInternal::sampleFormatToQString(spec.format);
- qDebug() << "Rate: " << spec.rate;
- qDebug() << "Channels: " << spec.channels;
- qDebug() << "Frame size: " << pa_frame_size(&spec);
-#endif
-
- pulseEngine->lock();
- pa_channel_map channel_map;
-
- pa_channel_map_init_extend(&channel_map, spec.channels, PA_CHANNEL_MAP_DEFAULT);
-
- if (!pa_channel_map_compatible(&channel_map, &spec))
- qWarning() << "Channel map doesn't match sample specification!";
-
- m_stream = pa_stream_new(pulseEngine->context(), m_streamName.constData(), &spec, &channel_map);
-
- pa_stream_set_state_callback(m_stream, inputStreamStateCallback, this);
- pa_stream_set_read_callback(m_stream, inputStreamReadCallback, this);
-
- pa_stream_set_underflow_callback(m_stream, inputStreamUnderflowCallback, this);
- pa_stream_set_overflow_callback(m_stream, inputStreamOverflowCallback, this);
-
- m_periodSize = pa_usec_to_bytes(PeriodTimeMs*1000, &spec);
-
- int flags = 0;
- pa_buffer_attr buffer_attr;
- buffer_attr.maxlength = (uint32_t) -1;
- buffer_attr.prebuf = (uint32_t) -1;
- buffer_attr.tlength = (uint32_t) -1;
- buffer_attr.minreq = (uint32_t) -1;
- flags |= PA_STREAM_ADJUST_LATENCY;
-
- if (m_bufferSize > 0)
- buffer_attr.fragsize = (uint32_t) m_bufferSize;
- else
- buffer_attr.fragsize = (uint32_t) m_periodSize;
-
- if (pa_stream_connect_record(m_stream, m_device.data(), &buffer_attr, (pa_stream_flags_t)flags) < 0) {
- qWarning() << "pa_stream_connect_record() failed!";
- pa_stream_unref(m_stream);
- m_stream = 0;
- pulseEngine->unlock();
- setError(QAudio::OpenError);
- setState(QAudio::StoppedState);
- return false;
- }
-
- while (pa_stream_get_state(m_stream) != PA_STREAM_READY)
- pa_threaded_mainloop_wait(pulseEngine->mainloop());
-
- const pa_buffer_attr *actualBufferAttr = pa_stream_get_buffer_attr(m_stream);
- m_periodSize = actualBufferAttr->fragsize;
- m_periodTime = pa_bytes_to_usec(m_periodSize, &spec) / 1000;
- if (actualBufferAttr->tlength != (uint32_t)-1)
- m_bufferSize = actualBufferAttr->tlength;
-
- pulseEngine->unlock();
-
- connect(pulseEngine, &QPulseAudioEngine::contextFailed, this, &QPulseAudioInput::onPulseContextFailed);
-
- m_opened = true;
- m_timer->start(m_periodTime);
-
- m_clockStamp.restart();
- m_timeStamp.restart();
- m_elapsedTimeOffset = 0;
- m_totalTimeValue = 0;
-
- return true;
-}
-
-void QPulseAudioInput::close()
-{
- if (!m_opened)
- return;
-
- m_timer->stop();
-
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
-
- if (m_stream) {
- pulseEngine->lock();
-
- pa_stream_set_state_callback(m_stream, 0, 0);
- pa_stream_set_read_callback(m_stream, 0, 0);
- pa_stream_set_underflow_callback(m_stream, 0, 0);
- pa_stream_set_overflow_callback(m_stream, 0, 0);
-
- pa_stream_disconnect(m_stream);
- pa_stream_unref(m_stream);
- m_stream = 0;
-
- pulseEngine->unlock();
- }
-
- disconnect(pulseEngine, &QPulseAudioEngine::contextFailed, this, &QPulseAudioInput::onPulseContextFailed);
-
- if (!m_pullMode && m_audioSource) {
- delete m_audioSource;
- m_audioSource = 0;
- }
- m_opened = false;
-}
-
-int QPulseAudioInput::checkBytesReady()
-{
- if (m_deviceState != QAudio::ActiveState && m_deviceState != QAudio::IdleState) {
- m_bytesAvailable = 0;
- } else {
- m_bytesAvailable = pa_stream_readable_size(m_stream);
- }
-
- return m_bytesAvailable;
-}
-
-int QPulseAudioInput::bytesReady() const
-{
- return qMax(m_bytesAvailable, 0);
-}
-
-qint64 QPulseAudioInput::read(char *data, qint64 len)
-{
- m_bytesAvailable = checkBytesReady();
-
- setError(QAudio::NoError);
- setState(QAudio::ActiveState);
-
- int readBytes = 0;
-
- if (!m_pullMode && !m_tempBuffer.isEmpty()) {
- readBytes = qMin(static_cast<int>(len), m_tempBuffer.size());
- memcpy(data, m_tempBuffer.constData(), readBytes);
- m_totalTimeValue += readBytes;
-
- if (readBytes < m_tempBuffer.size()) {
- m_tempBuffer.remove(0, readBytes);
- return readBytes;
- }
-
- m_tempBuffer.clear();
- }
-
- while (pa_stream_readable_size(m_stream) > 0) {
- size_t readLength = 0;
-
-#ifdef DEBUG_PULSE
- qDebug() << "QPulseAudioInput::read -- " << pa_stream_readable_size(m_stream) << " bytes available from pulse audio";
-#endif
-
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- pulseEngine->lock();
-
- const void *audioBuffer;
-
- // Second and third parameters (audioBuffer and length) to pa_stream_peek are output parameters,
- // the audioBuffer pointer is set to point to the actual pulse audio data,
- // and the length is set to the length of this data.
- if (pa_stream_peek(m_stream, &audioBuffer, &readLength) < 0) {
- qWarning() << QString("pa_stream_peek() failed: %1").arg(pa_strerror(pa_context_errno(pa_stream_get_context(m_stream))));
- pulseEngine->unlock();
- return 0;
- }
-
- qint64 actualLength = 0;
- if (m_pullMode) {
- QByteArray adjusted(readLength, Qt::Uninitialized);
- applyVolume(audioBuffer, adjusted.data(), readLength);
- actualLength = m_audioSource->write(adjusted);
-
- if (actualLength < qint64(readLength)) {
- pulseEngine->unlock();
-
- setError(QAudio::UnderrunError);
- setState(QAudio::IdleState);
-
- return actualLength;
- }
- } else {
- actualLength = qMin(static_cast<int>(len - readBytes), static_cast<int>(readLength));
- applyVolume(audioBuffer, data + readBytes, actualLength);
- }
-
-#ifdef DEBUG_PULSE
- qDebug() << "QPulseAudioInput::read -- wrote " << actualLength << " to client";
-#endif
-
- if (actualLength < qint64(readLength)) {
-#ifdef DEBUG_PULSE
- qDebug() << "QPulseAudioInput::read -- appending " << readLength - actualLength << " bytes of data to temp buffer";
-#endif
- int diff = readLength - actualLength;
- int oldSize = m_tempBuffer.size();
- m_tempBuffer.resize(m_tempBuffer.size() + diff);
- applyVolume(static_cast<const char *>(audioBuffer) + actualLength, m_tempBuffer.data() + oldSize, diff);
- QMetaObject::invokeMethod(this, "userFeed", Qt::QueuedConnection);
- }
-
- m_totalTimeValue += actualLength;
- readBytes += actualLength;
-
- pa_stream_drop(m_stream);
- pulseEngine->unlock();
-
- if (!m_pullMode && readBytes >= len)
- break;
-
- if (m_intervalTime && (m_timeStamp.elapsed() + m_elapsedTimeOffset) > m_intervalTime) {
- emit notify();
- m_elapsedTimeOffset = m_timeStamp.elapsed() + m_elapsedTimeOffset - m_intervalTime;
- m_timeStamp.restart();
- }
- }
-
-#ifdef DEBUG_PULSE
- qDebug() << "QPulseAudioInput::read -- returning after reading " << readBytes << " bytes";
-#endif
-
- return readBytes;
-}
-
-void QPulseAudioInput::applyVolume(const void *src, void *dest, int len)
-{
- if (m_volume < 1.f)
- QAudioHelperInternal::qMultiplySamples(m_volume, m_format, src, dest, len);
- else
- memcpy(dest, src, len);
-}
-
-void QPulseAudioInput::resume()
-{
- if (m_deviceState == QAudio::SuspendedState || m_deviceState == QAudio::IdleState) {
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- pa_operation *operation;
-
- pulseEngine->lock();
-
- operation = pa_stream_cork(m_stream, 0, inputStreamSuccessCallback, 0);
- pulseEngine->wait(operation);
- pa_operation_unref(operation);
-
- pulseEngine->unlock();
-
- m_timer->start(m_periodTime);
-
- setState(QAudio::ActiveState);
- setError(QAudio::NoError);
- }
-}
-
-void QPulseAudioInput::setVolume(qreal vol)
-{
- if (qFuzzyCompare(m_volume, vol))
- return;
-
- m_volume = qBound(qreal(0), vol, qreal(1));
-}
-
-qreal QPulseAudioInput::volume() const
-{
- return m_volume;
-}
-
-void QPulseAudioInput::setBufferSize(int value)
-{
- m_bufferSize = value;
-}
-
-int QPulseAudioInput::bufferSize() const
-{
- return m_bufferSize;
-}
-
-int QPulseAudioInput::periodSize() const
-{
- return m_periodSize;
-}
-
-void QPulseAudioInput::setNotifyInterval(int ms)
-{
- m_intervalTime = qMax(0, ms);
-}
-
-int QPulseAudioInput::notifyInterval() const
-{
- return m_intervalTime;
-}
-
-qint64 QPulseAudioInput::processedUSecs() const
-{
- pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(m_format);
- qint64 result = pa_bytes_to_usec(m_totalTimeValue, &spec);
-
- return result;
-}
-
-void QPulseAudioInput::suspend()
-{
- if (m_deviceState == QAudio::ActiveState) {
- setError(QAudio::NoError);
- setState(QAudio::SuspendedState);
-
- m_timer->stop();
-
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- pa_operation *operation;
-
- pulseEngine->lock();
-
- operation = pa_stream_cork(m_stream, 1, inputStreamSuccessCallback, 0);
- pulseEngine->wait(operation);
- pa_operation_unref(operation);
-
- pulseEngine->unlock();
- }
-}
-
-void QPulseAudioInput::userFeed()
-{
- if (m_deviceState == QAudio::StoppedState || m_deviceState == QAudio::SuspendedState)
- return;
-#ifdef DEBUG_PULSE
-// QTime now(QTime::currentTime());
-// qDebug()<< now.second() << "s " << now.msec() << "ms :userFeed() IN";
-#endif
- deviceReady();
-}
-
-bool QPulseAudioInput::deviceReady()
-{
- if (m_pullMode) {
- // reads some audio data and writes it to QIODevice
- read(0,0);
- } else {
- // emits readyRead() so user will call read() on QIODevice to get some audio data
- if (m_audioSource != 0) {
- PulseInputPrivate *a = qobject_cast<PulseInputPrivate*>(m_audioSource);
- a->trigger();
- }
- }
- m_bytesAvailable = checkBytesReady();
-
- if (m_deviceState != QAudio::ActiveState)
- return true;
-
- if (m_intervalTime && (m_timeStamp.elapsed() + m_elapsedTimeOffset) > m_intervalTime) {
- emit notify();
- m_elapsedTimeOffset = m_timeStamp.elapsed() + m_elapsedTimeOffset - m_intervalTime;
- m_timeStamp.restart();
- }
-
- return true;
-}
-
-qint64 QPulseAudioInput::elapsedUSecs() const
-{
- if (m_deviceState == QAudio::StoppedState)
- return 0;
-
- return m_clockStamp.elapsed() * qint64(1000);
-}
-
-void QPulseAudioInput::reset()
-{
- stop();
- m_bytesAvailable = 0;
-}
-
-void QPulseAudioInput::onPulseContextFailed()
-{
- close();
-
- setError(QAudio::FatalError);
- setState(QAudio::StoppedState);
-}
-
-PulseInputPrivate::PulseInputPrivate(QPulseAudioInput *audio)
-{
- m_audioDevice = qobject_cast<QPulseAudioInput*>(audio);
-}
-
-qint64 PulseInputPrivate::readData(char *data, qint64 len)
-{
- return m_audioDevice->read(data, len);
-}
-
-qint64 PulseInputPrivate::writeData(const char *data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
- return 0;
-}
-
-void PulseInputPrivate::trigger()
-{
- emit readyRead();
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qaudioinput_pulse.cpp"
diff --git a/src/plugins/pulseaudio/qaudioinput_pulse.h b/src/plugins/pulseaudio/qaudioinput_pulse.h
deleted file mode 100644
index dce212a25..000000000
--- a/src/plugins/pulseaudio/qaudioinput_pulse.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifndef QAUDIOINPUTPULSE_H
-#define QAUDIOINPUTPULSE_H
-
-#include <QtCore/qfile.h>
-#include <QtCore/qtimer.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qelapsedtimer.h>
-#include <QtCore/qiodevice.h>
-
-#include "qaudio.h"
-#include "qaudiodeviceinfo.h"
-#include "qaudiosystem.h"
-
-#include <pulse/pulseaudio.h>
-
-QT_BEGIN_NAMESPACE
-
-class PulseInputPrivate;
-
-class QPulseAudioInput : public QAbstractAudioInput
-{
- Q_OBJECT
-
-public:
- QPulseAudioInput(const QByteArray &device);
- ~QPulseAudioInput();
-
- qint64 read(char *data, qint64 len);
-
- void start(QIODevice *device) override;
- QIODevice *start() override;
- void stop() override;
- void reset() override;
- void suspend() override;
- void resume() override;
- int bytesReady() const override;
- int periodSize() const override;
- void setBufferSize(int value) override;
- int bufferSize() const override;
- void setNotifyInterval(int milliSeconds) override;
- int notifyInterval() const override;
- qint64 processedUSecs() const override;
- qint64 elapsedUSecs() const override;
- QAudio::Error error() const override;
- QAudio::State state() const override;
- void setFormat(const QAudioFormat &format) override;
- QAudioFormat format() const override;
-
- void setVolume(qreal volume) override;
- qreal volume() const override;
-
- qint64 m_totalTimeValue;
- QIODevice *m_audioSource;
- QAudioFormat m_format;
- QAudio::Error m_errorState;
- QAudio::State m_deviceState;
- qreal m_volume;
-
-private slots:
- void userFeed();
- bool deviceReady();
- void onPulseContextFailed();
-
-private:
- void setState(QAudio::State state);
- void setError(QAudio::Error error);
-
- void applyVolume(const void *src, void *dest, int len);
-
- int checkBytesReady();
- bool open();
- void close();
-
- bool m_pullMode;
- bool m_opened;
- int m_bytesAvailable;
- int m_bufferSize;
- int m_periodSize;
- int m_intervalTime;
- unsigned int m_periodTime;
- QTimer *m_timer;
- qint64 m_elapsedTimeOffset;
- pa_stream *m_stream;
- QElapsedTimer m_timeStamp;
- QElapsedTimer m_clockStamp;
- QByteArray m_streamName;
- QByteArray m_device;
- QByteArray m_tempBuffer;
- pa_sample_spec m_spec;
-};
-
-class PulseInputPrivate : public QIODevice
-{
- Q_OBJECT
-public:
- PulseInputPrivate(QPulseAudioInput *audio);
- ~PulseInputPrivate() {};
-
- qint64 readData(char *data, qint64 len) override;
- qint64 writeData(const char *data, qint64 len) override;
-
- void trigger();
-
-private:
- QPulseAudioInput *m_audioDevice;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/pulseaudio/qaudiooutput_pulse.cpp b/src/plugins/pulseaudio/qaudiooutput_pulse.cpp
deleted file mode 100644
index 708c3e0e3..000000000
--- a/src/plugins/pulseaudio/qaudiooutput_pulse.cpp
+++ /dev/null
@@ -1,739 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qmath.h>
-#include <private/qaudiohelpers_p.h>
-
-#include "qaudiooutput_pulse.h"
-#include "qaudiodeviceinfo_pulse.h"
-#include "qpulseaudioengine.h"
-#include "qpulsehelpers.h"
-#include <sys/types.h>
-#include <unistd.h>
-
-QT_BEGIN_NAMESPACE
-
-const int PeriodTimeMs = 20;
-const int LowLatencyPeriodTimeMs = 10;
-const int LowLatencyBufferSizeMs = 40;
-
-#define LOW_LATENCY_CATEGORY_NAME "game"
-
-static void outputStreamWriteCallback(pa_stream *stream, size_t length, void *userdata)
-{
- Q_UNUSED(stream);
- Q_UNUSED(length);
- Q_UNUSED(userdata);
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
-}
-
-static void outputStreamStateCallback(pa_stream *stream, void *userdata)
-{
- Q_UNUSED(userdata);
- pa_stream_state_t state = pa_stream_get_state(stream);
-#ifdef DEBUG_PULSE
- qDebug() << "Stream state: " << QPulseAudioInternal::stateToQString(state);
-#endif
- switch (state) {
- case PA_STREAM_CREATING:
- case PA_STREAM_READY:
- case PA_STREAM_TERMINATED:
- break;
-
- case PA_STREAM_FAILED:
- default:
- qWarning() << QString("Stream error: %1").arg(pa_strerror(pa_context_errno(pa_stream_get_context(stream))));
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
- break;
- }
-}
-
-static void outputStreamUnderflowCallback(pa_stream *stream, void *userdata)
-{
- Q_UNUSED(stream);
- ((QPulseAudioOutput*)userdata)->streamUnderflowCallback();
-}
-
-static void outputStreamOverflowCallback(pa_stream *stream, void *userdata)
-{
- Q_UNUSED(stream);
- Q_UNUSED(userdata);
- qWarning() << "Got a buffer overflow!";
-}
-
-static void outputStreamLatencyCallback(pa_stream *stream, void *userdata)
-{
- Q_UNUSED(stream);
- Q_UNUSED(userdata);
-
-#ifdef DEBUG_PULSE
- const pa_timing_info *info = pa_stream_get_timing_info(stream);
-
- qDebug() << "Write index corrupt: " << info->write_index_corrupt;
- qDebug() << "Write index: " << info->write_index;
- qDebug() << "Read index corrupt: " << info->read_index_corrupt;
- qDebug() << "Read index: " << info->read_index;
- qDebug() << "Sink usec: " << info->sink_usec;
- qDebug() << "Configured sink usec: " << info->configured_sink_usec;
-#endif
-}
-
-static void outputStreamSuccessCallback(pa_stream *stream, int success, void *userdata)
-{
- Q_UNUSED(stream);
- Q_UNUSED(success);
- Q_UNUSED(userdata);
-
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
-}
-
-static void outputStreamDrainComplete(pa_stream *stream, int success, void *userdata)
-{
- Q_UNUSED(stream);
- Q_UNUSED(success);
- Q_UNUSED(userdata);
-
-#ifdef DEBUG_PULSE
- qDebug() << "Draining completed successfully: " << (bool)success;
-#endif
-}
-
-static void streamAdjustPrebufferCallback(pa_stream *stream, int success, void *userdata)
-{
- Q_UNUSED(stream);
- Q_UNUSED(success);
- Q_UNUSED(userdata);
-
-#ifdef DEBUG_PULSE
- qDebug() << "Adjust prebuffer completed successfully: " << (bool)success;
-#endif
-}
-
-
-QPulseAudioOutput::QPulseAudioOutput(const QByteArray &device)
- : m_device(device)
- , m_errorState(QAudio::NoError)
- , m_deviceState(QAudio::StoppedState)
- , m_pullMode(true)
- , m_opened(false)
- , m_audioSource(0)
- , m_periodTime(0)
- , m_stream(0)
- , m_notifyInterval(1000)
- , m_periodSize(0)
- , m_bufferSize(0)
- , m_maxBufferSize(0)
- , m_totalTimeValue(0)
- , m_tickTimer(new QTimer(this))
- , m_audioBuffer(0)
- , m_resuming(false)
- , m_volume(1.0)
-{
- connect(m_tickTimer, SIGNAL(timeout()), SLOT(userFeed()));
-}
-
-QPulseAudioOutput::~QPulseAudioOutput()
-{
- close();
- disconnect(m_tickTimer, SIGNAL(timeout()));
- QCoreApplication::processEvents();
-}
-
-void QPulseAudioOutput::setError(QAudio::Error error)
-{
- if (m_errorState == error)
- return;
-
- m_errorState = error;
- emit errorChanged(error);
-}
-
-QAudio::Error QPulseAudioOutput::error() const
-{
- return m_errorState;
-}
-
-void QPulseAudioOutput::setState(QAudio::State state)
-{
- if (m_deviceState == state)
- return;
-
- m_deviceState = state;
- emit stateChanged(state);
-}
-
-QAudio::State QPulseAudioOutput::state() const
-{
- return m_deviceState;
-}
-
-void QPulseAudioOutput::streamUnderflowCallback()
-{
- if (m_deviceState != QAudio::IdleState && !m_resuming) {
- setError(QAudio::UnderrunError);
- setState(QAudio::IdleState);
- }
-}
-
-void QPulseAudioOutput::start(QIODevice *device)
-{
- setState(QAudio::StoppedState);
- setError(QAudio::NoError);
-
- // Handle change of mode
- if (m_audioSource && !m_pullMode) {
- delete m_audioSource;
- }
- m_audioSource = 0;
-
- close();
-
- m_pullMode = true;
- m_audioSource = device;
-
- if (!open()) {
- m_audioSource = 0;
- return;
- }
-
- setState(QAudio::ActiveState);
-}
-
-QIODevice *QPulseAudioOutput::start()
-{
- setState(QAudio::StoppedState);
- setError(QAudio::NoError);
-
- // Handle change of mode
- if (m_audioSource && !m_pullMode) {
- delete m_audioSource;
- }
- m_audioSource = 0;
-
- close();
-
- m_pullMode = false;
-
- if (!open())
- return nullptr;
-
- m_audioSource = new PulseOutputPrivate(this);
- m_audioSource->open(QIODevice::WriteOnly|QIODevice::Unbuffered);
-
- setState(QAudio::IdleState);
-
- return m_audioSource;
-}
-
-bool QPulseAudioOutput::open()
-{
- if (m_opened)
- return true;
-
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
-
- if (!pulseEngine->context() || pa_context_get_state(pulseEngine->context()) != PA_CONTEXT_READY) {
- setError(QAudio::FatalError);
- setState(QAudio::StoppedState);
- emit stateChanged(m_deviceState);
- return false;
- }
-
- pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(m_format);
-
- if (!pa_sample_spec_valid(&spec)) {
- setError(QAudio::OpenError);
- setState(QAudio::StoppedState);
- emit stateChanged(m_deviceState);
- return false;
- }
-
- m_spec = spec;
- m_totalTimeValue = 0;
-
- if (m_streamName.isNull())
- m_streamName = QString(QLatin1String("QtmPulseStream-%1-%2")).arg(::getpid()).arg(quintptr(this)).toUtf8();
-
-#ifdef DEBUG_PULSE
- qDebug() << "Format: " << QPulseAudioInternal::sampleFormatToQString(spec.format);
- qDebug() << "Rate: " << spec.rate;
- qDebug() << "Channels: " << spec.channels;
- qDebug() << "Frame size: " << pa_frame_size(&spec);
-#endif
-
- pulseEngine->lock();
-
- qint64 bytesPerSecond = m_format.sampleRate() * m_format.channelCount() * m_format.sampleSize() / 8;
-
- pa_proplist *propList = pa_proplist_new();
- if (!m_category.isNull())
- pa_proplist_sets(propList, PA_PROP_MEDIA_ROLE, m_category.toLatin1().constData());
-
- static const auto mapName = qEnvironmentVariable("QT_PA_CHANNEL_MAP");
- pa_channel_map_def_t mapDef = PA_CHANNEL_MAP_DEFAULT;
- if (mapName == QLatin1String("ALSA"))
- mapDef = PA_CHANNEL_MAP_ALSA;
- else if (mapName == QLatin1String("AUX"))
- mapDef = PA_CHANNEL_MAP_AUX;
- else if (mapName == QLatin1String("WAVEEX"))
- mapDef = PA_CHANNEL_MAP_WAVEEX;
- else if (mapName == QLatin1String("OSS"))
- mapDef = PA_CHANNEL_MAP_OSS;
- else if (!mapName.isEmpty())
- qWarning() << "Unknown pulse audio channel mapping definition:" << mapName;
-
- pa_channel_map m;
- auto channelMap = pa_channel_map_init_extend(&m, m_spec.channels, mapDef);
- if (!channelMap)
- qWarning() << "QAudioOutput: pa_channel_map_init_extend() Could not initialize channel map";
-
- m_stream = pa_stream_new_with_proplist(pulseEngine->context(), m_streamName.constData(), &m_spec, channelMap, propList);
- if (!m_stream) {
- qWarning() << "QAudioOutput: pa_stream_new_with_proplist() failed!";
- pulseEngine->unlock();
- setError(QAudio::OpenError);
- setState(QAudio::StoppedState);
- emit stateChanged(m_deviceState);
- return false;
- }
-
- pa_proplist_free(propList);
-
- pa_stream_set_state_callback(m_stream, outputStreamStateCallback, this);
- pa_stream_set_write_callback(m_stream, outputStreamWriteCallback, this);
-
- pa_stream_set_underflow_callback(m_stream, outputStreamUnderflowCallback, this);
- pa_stream_set_overflow_callback(m_stream, outputStreamOverflowCallback, this);
- pa_stream_set_latency_update_callback(m_stream, outputStreamLatencyCallback, this);
-
- if (m_bufferSize <= 0 && m_category == LOW_LATENCY_CATEGORY_NAME) {
- m_bufferSize = bytesPerSecond * LowLatencyBufferSizeMs / qint64(1000);
- }
-
- pa_buffer_attr requestedBuffer;
- requestedBuffer.fragsize = (uint32_t)-1;
- requestedBuffer.maxlength = (uint32_t)-1;
- requestedBuffer.minreq = (uint32_t)-1;
- requestedBuffer.prebuf = (uint32_t)-1;
- requestedBuffer.tlength = m_bufferSize;
-
- if (pa_stream_connect_playback(m_stream, m_device.data(), (m_bufferSize > 0) ? &requestedBuffer : NULL, (pa_stream_flags_t)0, NULL, NULL) < 0) {
- qWarning() << "pa_stream_connect_playback() failed!";
- pa_stream_unref(m_stream);
- m_stream = 0;
- pulseEngine->unlock();
- setError(QAudio::OpenError);
- setState(QAudio::StoppedState);
- emit stateChanged(m_deviceState);
- return false;
- }
-
- while (pa_stream_get_state(m_stream) != PA_STREAM_READY)
- pa_threaded_mainloop_wait(pulseEngine->mainloop());
-
- const pa_buffer_attr *buffer = pa_stream_get_buffer_attr(m_stream);
- m_periodTime = (m_category == LOW_LATENCY_CATEGORY_NAME) ? LowLatencyPeriodTimeMs : PeriodTimeMs;
- m_periodSize = pa_usec_to_bytes(m_periodTime*1000, &m_spec);
- m_bufferSize = buffer->tlength;
- m_maxBufferSize = buffer->maxlength;
- m_audioBuffer = new char[m_maxBufferSize];
-
- const qint64 streamSize = m_audioSource ? m_audioSource->size() : 0;
- if (m_pullMode && streamSize > 0 && static_cast<qint64>(buffer->prebuf) > streamSize) {
- pa_buffer_attr newBufferAttr;
- newBufferAttr = *buffer;
- newBufferAttr.prebuf = streamSize;
- pa_operation *o = pa_stream_set_buffer_attr(m_stream, &newBufferAttr, streamAdjustPrebufferCallback, NULL);
- if (o)
- pa_operation_unref(o);
- }
-
-#ifdef DEBUG_PULSE
- qDebug() << "Buffering info:";
- qDebug() << "\tMax length: " << buffer->maxlength;
- qDebug() << "\tTarget length: " << buffer->tlength;
- qDebug() << "\tPre-buffering: " << buffer->prebuf;
- qDebug() << "\tMinimum request: " << buffer->minreq;
- qDebug() << "\tFragment size: " << buffer->fragsize;
-#endif
-
- pulseEngine->unlock();
-
- connect(pulseEngine, &QPulseAudioEngine::contextFailed, this, &QPulseAudioOutput::onPulseContextFailed);
-
- m_opened = true;
-
- m_tickTimer->start(m_periodTime);
-
- m_elapsedTimeOffset = 0;
- m_timeStamp.restart();
- m_clockStamp.restart();
-
- return true;
-}
-
-void QPulseAudioOutput::close()
-{
- if (!m_opened)
- return;
-
- m_tickTimer->stop();
-
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
-
- if (m_stream) {
- pulseEngine->lock();
-
- pa_stream_set_state_callback(m_stream, 0, 0);
- pa_stream_set_write_callback(m_stream, 0, 0);
- pa_stream_set_underflow_callback(m_stream, 0, 0);
- pa_stream_set_overflow_callback(m_stream, 0, 0);
- pa_stream_set_latency_update_callback(m_stream, 0, 0);
-
- pa_operation *o = pa_stream_drain(m_stream, outputStreamDrainComplete, NULL);
- if (o)
- pa_operation_unref(o);
-
- pa_stream_disconnect(m_stream);
- pa_stream_unref(m_stream);
- m_stream = NULL;
-
- pulseEngine->unlock();
- }
-
- disconnect(pulseEngine, &QPulseAudioEngine::contextFailed, this, &QPulseAudioOutput::onPulseContextFailed);
-
- if (!m_pullMode && m_audioSource) {
- delete m_audioSource;
- m_audioSource = 0;
- }
- m_opened = false;
- if (m_audioBuffer) {
- delete[] m_audioBuffer;
- m_audioBuffer = 0;
- }
-}
-
-void QPulseAudioOutput::userFeed()
-{
- if (m_deviceState == QAudio::StoppedState || m_deviceState == QAudio::SuspendedState)
- return;
-
- m_resuming = false;
-
- if (m_pullMode) {
- int writableSize = bytesFree();
- int chunks = writableSize / m_periodSize;
- if (chunks == 0)
- return;
-
- int input = m_periodSize; // always request 1 chunk of data from user
- if (input > m_maxBufferSize)
- input = m_maxBufferSize;
-
- int audioBytesPulled = m_audioSource->read(m_audioBuffer, input);
- Q_ASSERT(audioBytesPulled <= input);
- if (m_audioBuffer && audioBytesPulled > 0) {
- if (audioBytesPulled > input) {
- qWarning() << "QPulseAudioOutput::userFeed() - Invalid audio data size provided from user:"
- << audioBytesPulled << "should be less than" << input;
- audioBytesPulled = input;
- }
- qint64 bytesWritten = write(m_audioBuffer, audioBytesPulled);
- Q_ASSERT(bytesWritten == audioBytesPulled); //unfinished write should not happen since the data provided is less than writableSize
- Q_UNUSED(bytesWritten);
-
- if (chunks > 1) {
- // PulseAudio needs more data. Ask for it immediately.
- QMetaObject::invokeMethod(this, "userFeed", Qt::QueuedConnection);
- }
- }
- }
-
- if (m_deviceState != QAudio::ActiveState)
- return;
-
- if (m_notifyInterval && (m_timeStamp.elapsed() + m_elapsedTimeOffset) > m_notifyInterval) {
- emit notify();
- m_elapsedTimeOffset = m_timeStamp.restart() + m_elapsedTimeOffset - m_notifyInterval;
- }
-}
-
-qint64 QPulseAudioOutput::write(const char *data, qint64 len)
-{
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
-
- pulseEngine->lock();
-
- len = qMin(len, static_cast<qint64>(pa_stream_writable_size(m_stream)));
-
- if (m_volume < 1.0f) {
- // Don't use PulseAudio volume, as it might affect all other streams of the same category
- // or even affect the system volume if flat volumes are enabled
- void *dest = NULL;
- size_t nbytes = len;
- if (pa_stream_begin_write(m_stream, &dest, &nbytes) < 0) {
- qWarning("QAudioOutput(pulseaudio): pa_stream_begin_write, error = %s",
- pa_strerror(pa_context_errno(pulseEngine->context())));
- setError(QAudio::IOError);
- return 0;
- }
-
- len = int(nbytes);
- QAudioHelperInternal::qMultiplySamples(m_volume, m_format, data, dest, len);
- data = reinterpret_cast<char *>(dest);
- }
-
- if (pa_stream_write(m_stream, data, len, NULL, 0, PA_SEEK_RELATIVE) < 0) {
- qWarning("QAudioOutput(pulseaudio): pa_stream_write, error = %s",
- pa_strerror(pa_context_errno(pulseEngine->context())));
- setError(QAudio::IOError);
- return 0;
- }
-
- pulseEngine->unlock();
- m_totalTimeValue += len;
-
- setError(QAudio::NoError);
- setState(QAudio::ActiveState);
-
- return len;
-}
-
-void QPulseAudioOutput::stop()
-{
- if (m_deviceState == QAudio::StoppedState)
- return;
-
- close();
-
- setError(QAudio::NoError);
- setState(QAudio::StoppedState);
-}
-
-int QPulseAudioOutput::bytesFree() const
-{
- if (m_deviceState != QAudio::ActiveState && m_deviceState != QAudio::IdleState)
- return 0;
-
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- pulseEngine->lock();
- int writableSize = pa_stream_writable_size(m_stream);
- pulseEngine->unlock();
- return writableSize;
-}
-
-int QPulseAudioOutput::periodSize() const
-{
- return m_periodSize;
-}
-
-void QPulseAudioOutput::setBufferSize(int value)
-{
- m_bufferSize = value;
-}
-
-int QPulseAudioOutput::bufferSize() const
-{
- return m_bufferSize;
-}
-
-void QPulseAudioOutput::setNotifyInterval(int ms)
-{
- m_notifyInterval = qMax(0, ms);
-}
-
-int QPulseAudioOutput::notifyInterval() const
-{
- return m_notifyInterval;
-}
-
-qint64 QPulseAudioOutput::processedUSecs() const
-{
- qint64 result = qint64(1000000) * m_totalTimeValue /
- (m_format.channelCount() * (m_format.sampleSize() / 8)) /
- m_format.sampleRate();
-
- return result;
-}
-
-void QPulseAudioOutput::resume()
-{
- if (m_deviceState == QAudio::SuspendedState) {
- m_resuming = true;
-
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
-
- pulseEngine->lock();
-
- pa_operation *operation = pa_stream_cork(m_stream, 0, outputStreamSuccessCallback, NULL);
- pulseEngine->wait(operation);
- pa_operation_unref(operation);
-
- operation = pa_stream_trigger(m_stream, outputStreamSuccessCallback, NULL);
- pulseEngine->wait(operation);
- pa_operation_unref(operation);
-
- pulseEngine->unlock();
-
- m_tickTimer->start(m_periodTime);
-
- setState(m_pullMode ? QAudio::ActiveState : QAudio::IdleState);
- setError(QAudio::NoError);
- }
-}
-
-void QPulseAudioOutput::setFormat(const QAudioFormat &format)
-{
- m_format = format;
-}
-
-QAudioFormat QPulseAudioOutput::format() const
-{
- return m_format;
-}
-
-void QPulseAudioOutput::suspend()
-{
- if (m_deviceState == QAudio::ActiveState || m_deviceState == QAudio::IdleState) {
- setError(QAudio::NoError);
- setState(QAudio::SuspendedState);
-
- m_tickTimer->stop();
-
- QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
- pa_operation *operation;
-
- pulseEngine->lock();
-
- operation = pa_stream_cork(m_stream, 1, outputStreamSuccessCallback, NULL);
- pulseEngine->wait(operation);
- pa_operation_unref(operation);
-
- pulseEngine->unlock();
- }
-}
-
-qint64 QPulseAudioOutput::elapsedUSecs() const
-{
- if (m_deviceState == QAudio::StoppedState)
- return 0;
-
- return m_clockStamp.elapsed() * qint64(1000);
-}
-
-void QPulseAudioOutput::reset()
-{
- stop();
-}
-
-PulseOutputPrivate::PulseOutputPrivate(QPulseAudioOutput *audio)
-{
- m_audioDevice = qobject_cast<QPulseAudioOutput*>(audio);
-}
-
-qint64 PulseOutputPrivate::readData(char *data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
-
- return 0;
-}
-
-qint64 PulseOutputPrivate::writeData(const char *data, qint64 len)
-{
- int retry = 0;
- qint64 written = 0;
-
- if ((m_audioDevice->m_deviceState == QAudio::ActiveState
- || m_audioDevice->m_deviceState == QAudio::IdleState)) {
- while(written < len) {
- int chunk = m_audioDevice->write(data+written, (len-written));
- if (chunk <= 0)
- retry++;
- written+=chunk;
- if (retry > 10)
- return written;
- }
- }
-
- return written;
-}
-
-void QPulseAudioOutput::setVolume(qreal vol)
-{
- if (qFuzzyCompare(m_volume, vol))
- return;
-
- m_volume = qBound(qreal(0), vol, qreal(1));
-}
-
-qreal QPulseAudioOutput::volume() const
-{
- return m_volume;
-}
-
-void QPulseAudioOutput::setCategory(const QString &category)
-{
- if (m_category != category) {
- m_category = category;
- }
-}
-
-QString QPulseAudioOutput::category() const
-{
- return m_category;
-}
-
-void QPulseAudioOutput::onPulseContextFailed()
-{
- close();
-
- setError(QAudio::FatalError);
- setState(QAudio::StoppedState);
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qaudiooutput_pulse.cpp"
diff --git a/src/plugins/pulseaudio/qaudiooutput_pulse.h b/src/plugins/pulseaudio/qaudiooutput_pulse.h
deleted file mode 100644
index e11f2ab2f..000000000
--- a/src/plugins/pulseaudio/qaudiooutput_pulse.h
+++ /dev/null
@@ -1,166 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIOOUTPUTPULSE_H
-#define QAUDIOOUTPUTPULSE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qfile.h>
-#include <QtCore/qtimer.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qelapsedtimer.h>
-#include <QtCore/qiodevice.h>
-
-#include "qaudio.h"
-#include "qaudiodeviceinfo.h"
-#include "qaudiosystem.h"
-
-#include <pulse/pulseaudio.h>
-
-QT_BEGIN_NAMESPACE
-
-class QPulseAudioOutput : public QAbstractAudioOutput
-{
- friend class PulseOutputPrivate;
- Q_OBJECT
-
-public:
- QPulseAudioOutput(const QByteArray &device);
- ~QPulseAudioOutput();
-
- void start(QIODevice *device) override;
- QIODevice *start() override;
- void stop() override;
- void reset() override;
- void suspend() override;
- void resume() override;
- int bytesFree() const override;
- int periodSize() const override;
- void setBufferSize(int value) override;
- int bufferSize() const override;
- void setNotifyInterval(int milliSeconds) override;
- int notifyInterval() const override;
- qint64 processedUSecs() const override;
- qint64 elapsedUSecs() const override;
- QAudio::Error error() const override;
- QAudio::State state() const override;
- void setFormat(const QAudioFormat &format) override;
- QAudioFormat format() const override;
-
- void setVolume(qreal volume) override;
- qreal volume() const override;
-
- void setCategory(const QString &category) override;
- QString category() const override;
-
-public:
- void streamUnderflowCallback();
-
-private:
- void setState(QAudio::State state);
- void setError(QAudio::Error error);
-
- bool open();
- void close();
- qint64 write(const char *data, qint64 len);
-
-private Q_SLOTS:
- void userFeed();
- void onPulseContextFailed();
-
-private:
- QByteArray m_device;
- QByteArray m_streamName;
- QAudioFormat m_format;
- QAudio::Error m_errorState;
- QAudio::State m_deviceState;
- bool m_pullMode;
- bool m_opened;
- QIODevice *m_audioSource;
- QTimer m_periodTimer;
- int m_periodTime;
- pa_stream *m_stream;
- int m_notifyInterval;
- int m_periodSize;
- int m_bufferSize;
- int m_maxBufferSize;
- QElapsedTimer m_clockStamp;
- qint64 m_totalTimeValue;
- QTimer *m_tickTimer;
- char *m_audioBuffer;
- QElapsedTimer m_timeStamp;
- qint64 m_elapsedTimeOffset;
- bool m_resuming;
- QString m_category;
-
- qreal m_volume;
- pa_sample_spec m_spec;
-};
-
-class PulseOutputPrivate : public QIODevice
-{
- friend class QPulseAudioOutput;
- Q_OBJECT
-
-public:
- PulseOutputPrivate(QPulseAudioOutput *audio);
- virtual ~PulseOutputPrivate() {}
-
-protected:
- qint64 readData(char *data, qint64 len) override;
- qint64 writeData(const char *data, qint64 len) override;
-
-private:
- QPulseAudioOutput *m_audioDevice;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/pulseaudio/qpulseaudioengine.cpp b/src/plugins/pulseaudio/qpulseaudioengine.cpp
deleted file mode 100644
index 653fea57e..000000000
--- a/src/plugins/pulseaudio/qpulseaudioengine.cpp
+++ /dev/null
@@ -1,482 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qdebug.h>
-
-#include <qaudiodeviceinfo.h>
-#include "qpulseaudioengine.h"
-#include "qaudiodeviceinfo_pulse.h"
-#include "qaudiooutput_pulse.h"
-#include "qpulsehelpers.h"
-#include <sys/types.h>
-#include <unistd.h>
-
-QT_BEGIN_NAMESPACE
-
-static void serverInfoCallback(pa_context *context, const pa_server_info *info, void *userdata)
-{
- if (!info) {
- qWarning() << QString("Failed to get server information: %s").arg(pa_strerror(pa_context_errno(context)));
- return;
- }
-
-#ifdef DEBUG_PULSE
- char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
-
- pa_sample_spec_snprint(ss, sizeof(ss), &info->sample_spec);
- pa_channel_map_snprint(cm, sizeof(cm), &info->channel_map);
-
- qDebug() << QString("User name: %1\n"
- "Host Name: %2\n"
- "Server Name: %3\n"
- "Server Version: %4\n"
- "Default Sample Specification: %5\n"
- "Default Channel Map: %6\n"
- "Default Sink: %7\n"
- "Default Source: %8\n").arg(
- info->user_name,
- info->host_name,
- info->server_name,
- info->server_version,
- ss,
- cm,
- info->default_sink_name,
- info->default_source_name);
-#endif
-
- QPulseAudioEngine *pulseEngine = static_cast<QPulseAudioEngine*>(userdata);
- pulseEngine->m_serverLock.lockForWrite();
- pulseEngine->m_defaultSink = info->default_sink_name;
- pulseEngine->m_defaultSource = info->default_source_name;
- pulseEngine->m_serverLock.unlock();
-
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
-}
-
-static void sinkInfoCallback(pa_context *context, const pa_sink_info *info, int isLast, void *userdata)
-{
- QPulseAudioEngine *pulseEngine = static_cast<QPulseAudioEngine*>(userdata);
-
- if (isLast < 0) {
- qWarning() << QString("Failed to get sink information: %s").arg(pa_strerror(pa_context_errno(context)));
- return;
- }
-
- if (isLast) {
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
- return;
- }
-
- Q_ASSERT(info);
-
-#ifdef DEBUG_PULSE
- QMap<pa_sink_state, QString> stateMap;
- stateMap[PA_SINK_INVALID_STATE] = "n/a";
- stateMap[PA_SINK_RUNNING] = "RUNNING";
- stateMap[PA_SINK_IDLE] = "IDLE";
- stateMap[PA_SINK_SUSPENDED] = "SUSPENDED";
-
- qDebug() << QString("Sink #%1\n"
- "\tState: %2\n"
- "\tName: %3\n"
- "\tDescription: %4\n"
- ).arg(QString::number(info->index),
- stateMap.value(info->state),
- info->name,
- info->description);
-#endif
-
- QAudioFormat format = QPulseAudioInternal::sampleSpecToAudioFormat(info->sample_spec);
-
- QWriteLocker locker(&pulseEngine->m_sinkLock);
- pulseEngine->m_preferredFormats.insert(info->name, format);
- pulseEngine->m_sinks.insert(info->index, info->name);
-}
-
-static void sourceInfoCallback(pa_context *context, const pa_source_info *info, int isLast, void *userdata)
-{
- Q_UNUSED(context);
- QPulseAudioEngine *pulseEngine = static_cast<QPulseAudioEngine*>(userdata);
-
- if (isLast) {
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
- return;
- }
-
- Q_ASSERT(info);
-
-#ifdef DEBUG_PULSE
- QMap<pa_source_state, QString> stateMap;
- stateMap[PA_SOURCE_INVALID_STATE] = "n/a";
- stateMap[PA_SOURCE_RUNNING] = "RUNNING";
- stateMap[PA_SOURCE_IDLE] = "IDLE";
- stateMap[PA_SOURCE_SUSPENDED] = "SUSPENDED";
-
- qDebug() << QString("Source #%1\n"
- "\tState: %2\n"
- "\tName: %3\n"
- "\tDescription: %4\n"
- ).arg(QString::number(info->index),
- stateMap.value(info->state),
- info->name,
- info->description);
-#endif
-
- QAudioFormat format = QPulseAudioInternal::sampleSpecToAudioFormat(info->sample_spec);
-
- QWriteLocker locker(&pulseEngine->m_sourceLock);
- pulseEngine->m_preferredFormats.insert(info->name, format);
- pulseEngine->m_sources.insert(info->index, info->name);
-}
-
-static void event_cb(pa_context* context, pa_subscription_event_type_t t, uint32_t index, void* userdata)
-{
- QPulseAudioEngine *pulseEngine = static_cast<QPulseAudioEngine*>(userdata);
-
- int type = t & PA_SUBSCRIPTION_EVENT_TYPE_MASK;
- int facility = t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK;
-
- switch (type) {
- case PA_SUBSCRIPTION_EVENT_NEW:
- case PA_SUBSCRIPTION_EVENT_CHANGE:
- switch (facility) {
- case PA_SUBSCRIPTION_EVENT_SERVER: {
- pa_operation *op = pa_context_get_server_info(context, serverInfoCallback, userdata);
- if (op)
- pa_operation_unref(op);
- else
- qWarning("PulseAudioService: failed to get server info");
- break;
- }
- case PA_SUBSCRIPTION_EVENT_SINK: {
- pa_operation *op = pa_context_get_sink_info_by_index(context, index, sinkInfoCallback, userdata);
- if (op)
- pa_operation_unref(op);
- else
- qWarning("PulseAudioService: failed to get sink info");
- break;
- }
- case PA_SUBSCRIPTION_EVENT_SOURCE: {
- pa_operation *op = pa_context_get_source_info_by_index(context, index, sourceInfoCallback, userdata);
- if (op)
- pa_operation_unref(op);
- else
- qWarning("PulseAudioService: failed to get source info");
- break;
- }
- default:
- break;
- }
- break;
- case PA_SUBSCRIPTION_EVENT_REMOVE:
- switch (facility) {
- case PA_SUBSCRIPTION_EVENT_SINK:
- pulseEngine->m_sinkLock.lockForWrite();
- pulseEngine->m_preferredFormats.remove(pulseEngine->m_sinks.value(index));
- pulseEngine->m_sinks.remove(index);
- pulseEngine->m_sinkLock.unlock();
- break;
- case PA_SUBSCRIPTION_EVENT_SOURCE:
- pulseEngine->m_sourceLock.lockForWrite();
- pulseEngine->m_preferredFormats.remove(pulseEngine->m_sources.value(index));
- pulseEngine->m_sources.remove(index);
- pulseEngine->m_sourceLock.unlock();
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
-}
-
-static void contextStateCallbackInit(pa_context *context, void *userdata)
-{
- Q_UNUSED(context);
-#ifdef DEBUG_PULSE
- qDebug() << QPulseAudioInternal::stateToQString(pa_context_get_state(context));
-#endif
- QPulseAudioEngine *pulseEngine = reinterpret_cast<QPulseAudioEngine*>(userdata);
- pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
-}
-
-static void contextStateCallback(pa_context *c, void *userdata)
-{
- QPulseAudioEngine *self = reinterpret_cast<QPulseAudioEngine*>(userdata);
- pa_context_state_t state = pa_context_get_state(c);
-
-#ifdef DEBUG_PULSE
- qDebug() << QPulseAudioInternal::stateToQString(state);
-#endif
-
- if (state == PA_CONTEXT_FAILED)
- QMetaObject::invokeMethod(self, "onContextFailed", Qt::QueuedConnection);
-}
-
-Q_GLOBAL_STATIC(QPulseAudioEngine, pulseEngine);
-
-QPulseAudioEngine::QPulseAudioEngine(QObject *parent)
- : QObject(parent)
- , m_mainLoopApi(0)
- , m_context(0)
- , m_prepared(false)
-{
- prepare();
-}
-
-QPulseAudioEngine::~QPulseAudioEngine()
-{
- if (m_prepared)
- release();
-}
-
-void QPulseAudioEngine::prepare()
-{
- bool keepGoing = true;
- bool ok = true;
-
- m_mainLoop = pa_threaded_mainloop_new();
- if (m_mainLoop == 0) {
- qWarning("PulseAudioService: unable to create pulseaudio mainloop");
- return;
- }
-
- if (pa_threaded_mainloop_start(m_mainLoop) != 0) {
- qWarning("PulseAudioService: unable to start pulseaudio mainloop");
- pa_threaded_mainloop_free(m_mainLoop);
- m_mainLoop = 0;
- return;
- }
-
- m_mainLoopApi = pa_threaded_mainloop_get_api(m_mainLoop);
-
- lock();
-
- m_context = pa_context_new(m_mainLoopApi, QString(QLatin1String("QtPulseAudio:%1")).arg(::getpid()).toLatin1().constData());
-
- if (m_context == 0) {
- qWarning("PulseAudioService: Unable to create new pulseaudio context");
- pa_threaded_mainloop_unlock(m_mainLoop);
- pa_threaded_mainloop_free(m_mainLoop);
- m_mainLoop = 0;
- onContextFailed();
- return;
- }
-
- pa_context_set_state_callback(m_context, contextStateCallbackInit, this);
-
- if (pa_context_connect(m_context, 0, (pa_context_flags_t)0, 0) < 0) {
- qWarning("PulseAudioService: pa_context_connect() failed");
- pa_context_unref(m_context);
- pa_threaded_mainloop_unlock(m_mainLoop);
- pa_threaded_mainloop_free(m_mainLoop);
- m_mainLoop = 0;
- m_context = 0;
- return;
- }
-
- pa_threaded_mainloop_wait(m_mainLoop);
-
- while (keepGoing) {
- switch (pa_context_get_state(m_context)) {
- case PA_CONTEXT_CONNECTING:
- case PA_CONTEXT_AUTHORIZING:
- case PA_CONTEXT_SETTING_NAME:
- break;
-
- case PA_CONTEXT_READY:
-#ifdef DEBUG_PULSE
- qDebug("Connection established.");
-#endif
- keepGoing = false;
- break;
-
- case PA_CONTEXT_TERMINATED:
- qCritical("PulseAudioService: Context terminated.");
- keepGoing = false;
- ok = false;
- break;
-
- case PA_CONTEXT_FAILED:
- default:
- qCritical() << QString("PulseAudioService: Connection failure: %1").arg(pa_strerror(pa_context_errno(m_context)));
- keepGoing = false;
- ok = false;
- }
-
- if (keepGoing)
- pa_threaded_mainloop_wait(m_mainLoop);
- }
-
- if (ok) {
- pa_context_set_state_callback(m_context, contextStateCallback, this);
-
- pa_context_set_subscribe_callback(m_context, event_cb, this);
- pa_operation *op = pa_context_subscribe(m_context,
- pa_subscription_mask_t(PA_SUBSCRIPTION_MASK_SINK |
- PA_SUBSCRIPTION_MASK_SOURCE |
- PA_SUBSCRIPTION_MASK_SERVER),
- NULL, NULL);
- if (op)
- pa_operation_unref(op);
- else
- qWarning("PulseAudioService: failed to subscribe to context notifications");
- } else {
- pa_context_unref(m_context);
- m_context = 0;
- }
-
- unlock();
-
- if (ok) {
- updateDevices();
- m_prepared = true;
- } else {
- pa_threaded_mainloop_free(m_mainLoop);
- m_mainLoop = 0;
- onContextFailed();
- }
-}
-
-void QPulseAudioEngine::release()
-{
- if (!m_prepared)
- return;
-
- if (m_context) {
- pa_context_disconnect(m_context);
- pa_context_unref(m_context);
- m_context = 0;
- }
-
- if (m_mainLoop) {
- pa_threaded_mainloop_stop(m_mainLoop);
- pa_threaded_mainloop_free(m_mainLoop);
- m_mainLoop = 0;
- }
-
- m_prepared = false;
-}
-
-void QPulseAudioEngine::updateDevices()
-{
- lock();
-
- // Get default input and output devices
- pa_operation *operation = pa_context_get_server_info(m_context, serverInfoCallback, this);
- if (operation) {
- while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(m_mainLoop);
- pa_operation_unref(operation);
- } else {
- qWarning("PulseAudioService: failed to get server info");
- }
-
- // Get output devices
- operation = pa_context_get_sink_info_list(m_context, sinkInfoCallback, this);
- if (operation) {
- while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(m_mainLoop);
- pa_operation_unref(operation);
- } else {
- qWarning("PulseAudioService: failed to get sink info");
- }
-
- // Get input devices
- operation = pa_context_get_source_info_list(m_context, sourceInfoCallback, this);
- if (operation) {
- while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(m_mainLoop);
- pa_operation_unref(operation);
- } else {
- qWarning("PulseAudioService: failed to get source info");
- }
-
- unlock();
-}
-
-void QPulseAudioEngine::onContextFailed()
-{
- // Give a chance to the connected slots to still use the Pulse main loop before releasing it.
- emit contextFailed();
-
- release();
-
- // Try to reconnect later
- QTimer::singleShot(3000, this, SLOT(prepare()));
-}
-
-QPulseAudioEngine *QPulseAudioEngine::instance()
-{
- return pulseEngine();
-}
-
-QList<QByteArray> QPulseAudioEngine::availableDevices(QAudio::Mode mode) const
-{
- QList<QByteArray> devices;
- QByteArray defaultDevice;
-
- m_serverLock.lockForRead();
-
- if (mode == QAudio::AudioOutput) {
- QReadLocker locker(&m_sinkLock);
- devices = m_sinks.values();
- defaultDevice = m_defaultSink;
- } else {
- QReadLocker locker(&m_sourceLock);
- devices = m_sources.values();
- defaultDevice = m_defaultSource;
- }
-
- m_serverLock.unlock();
-
- // Swap the default device to index 0
- devices.removeOne(defaultDevice);
- devices.prepend(defaultDevice);
-
- return devices;
-}
-
-QByteArray QPulseAudioEngine::defaultDevice(QAudio::Mode mode) const
-{
- return (mode == QAudio::AudioOutput) ? m_defaultSink : m_defaultSource;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/pulseaudio/qpulseaudioengine.h b/src/plugins/pulseaudio/qpulseaudioengine.h
deleted file mode 100644
index a19be1841..000000000
--- a/src/plugins/pulseaudio/qpulseaudioengine.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QPULSEAUDIOENGINE_H
-#define QPULSEAUDIOENGINE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qmap.h>
-#include <QtCore/qbytearray.h>
-#include <QtCore/qreadwritelock.h>
-#include <QtMultimedia/qaudiosystemplugin.h>
-#include <pulse/pulseaudio.h>
-#include "qpulsehelpers.h"
-#include <qaudioformat.h>
-
-QT_BEGIN_NAMESPACE
-
-class QPulseAudioEngine : public QObject
-{
- Q_OBJECT
-
-public:
- QPulseAudioEngine(QObject *parent = 0);
- ~QPulseAudioEngine();
-
- static QPulseAudioEngine *instance();
- pa_threaded_mainloop *mainloop() { return m_mainLoop; }
- pa_context *context() { return m_context; }
-
- inline void lock()
- {
- if (m_mainLoop)
- pa_threaded_mainloop_lock(m_mainLoop);
- }
-
- inline void unlock()
- {
- if (m_mainLoop)
- pa_threaded_mainloop_unlock(m_mainLoop);
- }
-
- inline void wait(pa_operation *op)
- {
- while (m_mainLoop && pa_operation_get_state(op) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(m_mainLoop);
- }
-
- QList<QByteArray> availableDevices(QAudio::Mode mode) const;
- QByteArray defaultDevice(QAudio::Mode mode) const;
-
-Q_SIGNALS:
- void contextFailed();
-
-private Q_SLOTS:
- void prepare();
- void onContextFailed();
-
-private:
- void updateDevices();
- void release();
-
-public:
- QMap<int, QByteArray> m_sinks;
- QMap<int, QByteArray> m_sources;
- QMap<QByteArray, QAudioFormat> m_preferredFormats;
-
- QByteArray m_defaultSink;
- QByteArray m_defaultSource;
-
- mutable QReadWriteLock m_sinkLock;
- mutable QReadWriteLock m_sourceLock;
- mutable QReadWriteLock m_serverLock;
-
-private:
- pa_mainloop_api *m_mainLoopApi;
- pa_threaded_mainloop *m_mainLoop;
- pa_context *m_context;
- bool m_prepared;
- };
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/pulseaudio/qpulseaudioplugin.cpp b/src/plugins/pulseaudio/qpulseaudioplugin.cpp
deleted file mode 100644
index 6b3019279..000000000
--- a/src/plugins/pulseaudio/qpulseaudioplugin.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qaudiodeviceinfo.h>
-
-#include "qpulseaudioplugin.h"
-#include "qaudiodeviceinfo_pulse.h"
-#include "qaudiooutput_pulse.h"
-#include "qaudioinput_pulse.h"
-#include "qpulseaudioengine.h"
-
-QT_BEGIN_NAMESPACE
-
-QPulseAudioPlugin::QPulseAudioPlugin(QObject *parent)
- : QAudioSystemPlugin(parent)
- , m_pulseEngine(QPulseAudioEngine::instance())
-{
-}
-
-QByteArray QPulseAudioPlugin::defaultDevice(QAudio::Mode mode) const
-{
- return m_pulseEngine->defaultDevice(mode);
-}
-
-QList<QByteArray> QPulseAudioPlugin::availableDevices(QAudio::Mode mode) const
-{
- return m_pulseEngine->availableDevices(mode);
-}
-
-QAbstractAudioInput *QPulseAudioPlugin::createInput(const QByteArray &device)
-{
- QPulseAudioInput *input = new QPulseAudioInput(device);
- return input;
-}
-
-QAbstractAudioOutput *QPulseAudioPlugin::createOutput(const QByteArray &device)
-{
-
- QPulseAudioOutput *output = new QPulseAudioOutput(device);
- return output;
-}
-
-QAbstractAudioDeviceInfo *QPulseAudioPlugin::createDeviceInfo(const QByteArray &device, QAudio::Mode mode)
-{
- QPulseAudioDeviceInfo *deviceInfo = new QPulseAudioDeviceInfo(device, mode);
- return deviceInfo;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/pulseaudio/qpulseaudioplugin.h b/src/plugins/pulseaudio/qpulseaudioplugin.h
deleted file mode 100644
index 7d27cad48..000000000
--- a/src/plugins/pulseaudio/qpulseaudioplugin.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QPULSEAUDIOPLUGIN_H
-#define QPULSEAUDIOPLUGIN_H
-
-#include <QtMultimedia/qaudiosystemplugin.h>
-#include <QtMultimedia/private/qaudiosystempluginext_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QPulseAudioEngine;
-
-class QPulseAudioPlugin : public QAudioSystemPlugin, public QAudioSystemPluginExtension
-{
- Q_OBJECT
-
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.audiosystemfactory/5.0" FILE "pulseaudio.json")
- Q_INTERFACES(QAudioSystemPluginExtension)
-
-public:
- QPulseAudioPlugin(QObject *parent = 0);
- ~QPulseAudioPlugin() {}
-
- QByteArray defaultDevice(QAudio::Mode mode) const override;
- QList<QByteArray> availableDevices(QAudio::Mode mode) const override;
- QAbstractAudioInput *createInput(const QByteArray &device) override;
- QAbstractAudioOutput *createOutput(const QByteArray &device) override;
- QAbstractAudioDeviceInfo *createDeviceInfo(const QByteArray &device, QAudio::Mode mode) override;
-
-private:
- QPulseAudioEngine *m_pulseEngine;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/pulseaudio/qpulsehelpers.cpp b/src/plugins/pulseaudio/qpulsehelpers.cpp
deleted file mode 100644
index 0604c97f5..000000000
--- a/src/plugins/pulseaudio/qpulsehelpers.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qpulsehelpers.h"
-
-QT_BEGIN_NAMESPACE
-
-namespace QPulseAudioInternal
-{
-pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format)
-{
- pa_sample_spec spec;
-
- spec.rate = format.sampleRate();
- spec.channels = format.channelCount();
- spec.format = PA_SAMPLE_INVALID;
- const bool isBigEndian = (format.byteOrder() == QAudioFormat::BigEndian);
-
- if (format.sampleType() == QAudioFormat::UnSignedInt) {
- if (format.sampleSize() == 8)
- spec.format = PA_SAMPLE_U8;
- } else if (format.sampleType() == QAudioFormat::SignedInt) {
- if (format.sampleSize() == 16) {
- spec.format = isBigEndian ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE;
- } else if (format.sampleSize() == 24) {
- spec.format = isBigEndian ? PA_SAMPLE_S24BE : PA_SAMPLE_S24LE;
- } else if (format.sampleSize() == 32) {
- spec.format = isBigEndian ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE;
- }
- } else if (format.sampleType() == QAudioFormat::Float) {
- if (format.sampleSize() == 32)
- spec.format = isBigEndian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE;
- }
-
- return spec;
-}
-
-#ifdef DEBUG_PULSE
-QString stateToQString(pa_stream_state_t state)
-{
- switch (state)
- {
- case PA_STREAM_UNCONNECTED: return "Unconnected";
- case PA_STREAM_CREATING: return "Creating";
- case PA_STREAM_READY: return "Ready";
- case PA_STREAM_FAILED: return "Failed";
- case PA_STREAM_TERMINATED: return "Terminated";
- }
-
- return QString("Unknown state: %0").arg(state);
-}
-
-QString sampleFormatToQString(pa_sample_format format)
-{
- switch (format)
- {
- case PA_SAMPLE_U8: return "Unsigned 8 Bit PCM.";
- case PA_SAMPLE_ALAW: return "8 Bit a-Law ";
- case PA_SAMPLE_ULAW: return "8 Bit mu-Law";
- case PA_SAMPLE_S16LE: return "Signed 16 Bit PCM, little endian (PC).";
- case PA_SAMPLE_S16BE: return "Signed 16 Bit PCM, big endian.";
- case PA_SAMPLE_FLOAT32LE: return "32 Bit IEEE floating point, little endian (PC), range -1.0 to 1.0";
- case PA_SAMPLE_FLOAT32BE: return "32 Bit IEEE floating point, big endian, range -1.0 to 1.0";
- case PA_SAMPLE_S32LE: return "Signed 32 Bit PCM, little endian (PC).";
- case PA_SAMPLE_S32BE: return "Signed 32 Bit PCM, big endian.";
- case PA_SAMPLE_S24LE: return "Signed 24 Bit PCM packed, little endian (PC).";
- case PA_SAMPLE_S24BE: return "Signed 24 Bit PCM packed, big endian.";
- case PA_SAMPLE_S24_32LE: return "Signed 24 Bit PCM in LSB of 32 Bit words, little endian (PC).";
- case PA_SAMPLE_S24_32BE: return "Signed 24 Bit PCM in LSB of 32 Bit words, big endian.";
- case PA_SAMPLE_MAX: return "Upper limit of valid sample types.";
- case PA_SAMPLE_INVALID: return "Invalid sample format";
- }
-
- return QString("Invalid value: %0").arg(format);
-}
-
-QString stateToQString(pa_context_state_t state)
-{
- switch (state)
- {
- case PA_CONTEXT_UNCONNECTED: return "Unconnected";
- case PA_CONTEXT_CONNECTING: return "Connecting";
- case PA_CONTEXT_AUTHORIZING: return "Authorizing";
- case PA_CONTEXT_SETTING_NAME: return "Setting Name";
- case PA_CONTEXT_READY: return "Ready";
- case PA_CONTEXT_FAILED: return "Failed";
- case PA_CONTEXT_TERMINATED: return "Terminated";
- }
-
- return QString("Unknown state: %0").arg(state);
-}
-#endif
-
-QAudioFormat sampleSpecToAudioFormat(pa_sample_spec spec)
-{
- QAudioFormat format;
- format.setSampleRate(spec.rate);
- format.setChannelCount(spec.channels);
- format.setCodec("audio/pcm");
-
- switch (spec.format) {
- case PA_SAMPLE_U8:
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::UnSignedInt);
- format.setSampleSize(8);
- break;
- case PA_SAMPLE_ALAW:
- // TODO:
- break;
- case PA_SAMPLE_ULAW:
- // TODO:
- break;
- case PA_SAMPLE_S16LE:
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::SignedInt);
- format.setSampleSize(16);
- break;
- case PA_SAMPLE_S16BE:
- format.setByteOrder(QAudioFormat::BigEndian);
- format.setSampleType(QAudioFormat::SignedInt);
- format.setSampleSize(16);
- break;
- case PA_SAMPLE_FLOAT32LE:
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::Float);
- format.setSampleSize(32);
- break;
- case PA_SAMPLE_FLOAT32BE:
- format.setByteOrder(QAudioFormat::BigEndian);
- format.setSampleType(QAudioFormat::Float);
- format.setSampleSize(32);
- break;
- case PA_SAMPLE_S32LE:
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::SignedInt);
- format.setSampleSize(32);
- break;
- case PA_SAMPLE_S32BE:
- format.setByteOrder(QAudioFormat::BigEndian);
- format.setSampleType(QAudioFormat::SignedInt);
- format.setSampleSize(32);
- break;
- case PA_SAMPLE_S24LE:
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::SignedInt);
- format.setSampleSize(24);
- break;
- case PA_SAMPLE_S24BE:
- format.setByteOrder(QAudioFormat::BigEndian);
- format.setSampleType(QAudioFormat::SignedInt);
- format.setSampleSize(24);
- break;
- case PA_SAMPLE_S24_32LE:
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::SignedInt);
- format.setSampleSize(24);
- break;
- case PA_SAMPLE_S24_32BE:
- format.setByteOrder(QAudioFormat::BigEndian);
- format.setSampleType(QAudioFormat::SignedInt);
- format.setSampleSize(24);
- break;
- case PA_SAMPLE_MAX:
- case PA_SAMPLE_INVALID:
- default:
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::Unknown);
- format.setSampleSize(0);
- }
-
- return format;
-}
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/pulseaudio/qpulsehelpers.h b/src/plugins/pulseaudio/qpulsehelpers.h
deleted file mode 100644
index 279cecc2f..000000000
--- a/src/plugins/pulseaudio/qpulsehelpers.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QPULSEHELPER_H
-#define QPULSEHELPER_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qaudiodeviceinfo.h"
-#include <qaudioformat.h>
-#include <pulse/pulseaudio.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace QPulseAudioInternal
-{
-pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format);
-QString stateToQString(pa_stream_state_t state);
-QString stateToQString(pa_context_state_t state);
-QString sampleFormatToQString(pa_sample_format format);
-QAudioFormat sampleSpecToAudioFormat(pa_sample_spec spec);
-}
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx-audio/audio/audio.pro b/src/plugins/qnx-audio/audio/audio.pro
deleted file mode 100644
index bd69dfe1e..000000000
--- a/src/plugins/qnx-audio/audio/audio.pro
+++ /dev/null
@@ -1,22 +0,0 @@
-TARGET = qtmedia_qnx_audio
-
-QT += multimedia-private
-
-LIBS += -lasound
-
-HEADERS += qnxaudioplugin.h \
- qnxaudiodeviceinfo.h \
- qnxaudioinput.h \
- qnxaudiooutput.h \
- qnxaudioutils.h
-
-SOURCES += qnxaudioplugin.cpp \
- qnxaudiodeviceinfo.cpp \
- qnxaudioinput.cpp \
- qnxaudiooutput.cpp \
- qnxaudioutils.cpp
-
-OTHER_FILES += qnx_audio.json
-
-PLUGIN_TYPE = audio
-load(qt_plugin)
diff --git a/src/plugins/qnx-audio/audio/qnx_audio.json b/src/plugins/qnx-audio/audio/qnx_audio.json
deleted file mode 100644
index a31d52107..000000000
--- a/src/plugins/qnx-audio/audio/qnx_audio.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": ["default"]
-}
diff --git a/src/plugins/qnx-audio/audio/qnxaudiodeviceinfo.cpp b/src/plugins/qnx-audio/audio/qnxaudiodeviceinfo.cpp
deleted file mode 100644
index 7e73ca264..000000000
--- a/src/plugins/qnx-audio/audio/qnxaudiodeviceinfo.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnxaudiodeviceinfo.h"
-
-#include "qnxaudioutils.h"
-
-#include <sys/asoundlib.h>
-
-QT_BEGIN_NAMESPACE
-
-QnxAudioDeviceInfo::QnxAudioDeviceInfo(const QString &deviceName, QAudio::Mode mode)
- : m_name(deviceName),
- m_mode(mode)
-{
-}
-
-QnxAudioDeviceInfo::~QnxAudioDeviceInfo()
-{
-}
-
-QAudioFormat QnxAudioDeviceInfo::preferredFormat() const
-{
- QAudioFormat format;
- if (m_mode == QAudio::AudioOutput) {
- format.setSampleRate(44100);
- format.setChannelCount(2);
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::SignedInt);
- format.setSampleSize(16);
- format.setCodec(QLatin1String("audio/pcm"));
- } else {
- format.setSampleRate(8000);
- format.setChannelCount(1);
- format.setSampleType(QAudioFormat::UnSignedInt);
- format.setSampleSize(8);
- format.setCodec(QLatin1String("audio/pcm"));
- if (!isFormatSupported(format)) {
- format.setChannelCount(2);
- format.setSampleSize(16);
- format.setSampleType(QAudioFormat::SignedInt);
- }
- }
- return format;
-}
-
-bool QnxAudioDeviceInfo::isFormatSupported(const QAudioFormat &format) const
-{
- if (!format.codec().startsWith(QLatin1String("audio/pcm")))
- return false;
-
- const int pcmMode = (m_mode == QAudio::AudioOutput) ? SND_PCM_OPEN_PLAYBACK : SND_PCM_OPEN_CAPTURE;
- snd_pcm_t *handle;
-
- int card = 0;
- int device = 0;
- if (snd_pcm_open_preferred(&handle, &card, &device, pcmMode) < 0)
- return false;
-
- snd_pcm_channel_info_t info;
- memset (&info, 0, sizeof(info));
- info.channel = (m_mode == QAudio::AudioOutput) ? SND_PCM_CHANNEL_PLAYBACK : SND_PCM_CHANNEL_CAPTURE;
-
- if (snd_pcm_plugin_info(handle, &info) < 0) {
- qWarning("QAudioDeviceInfo: couldn't get channel info");
- snd_pcm_close(handle);
- return false;
- }
-
- snd_pcm_channel_params_t params = QnxAudioUtils::formatToChannelParams(format, m_mode, info.max_fragment_size);
- const int errorCode = snd_pcm_plugin_params(handle, &params);
- snd_pcm_close(handle);
-
- return errorCode == 0;
-}
-
-QString QnxAudioDeviceInfo::deviceName() const
-{
- return m_name;
-}
-
-QStringList QnxAudioDeviceInfo::supportedCodecs()
-{
- return QStringList() << QLatin1String("audio/pcm");
-}
-
-QList<int> QnxAudioDeviceInfo::supportedSampleRates()
-{
- return QList<int>() << 8000 << 11025 << 22050 << 44100 << 48000;
-}
-
-QList<int> QnxAudioDeviceInfo::supportedChannelCounts()
-{
- return QList<int>() << 1 << 2;
-}
-
-QList<int> QnxAudioDeviceInfo::supportedSampleSizes()
-{
- return QList<int>() << 8 << 16 << 32;
-}
-
-QList<QAudioFormat::Endian> QnxAudioDeviceInfo::supportedByteOrders()
-{
- return QList<QAudioFormat::Endian>() << QAudioFormat::LittleEndian << QAudioFormat::BigEndian;
-}
-
-QList<QAudioFormat::SampleType> QnxAudioDeviceInfo::supportedSampleTypes()
-{
- return QList<QAudioFormat::SampleType>() << QAudioFormat::SignedInt << QAudioFormat::UnSignedInt << QAudioFormat::Float;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx-audio/audio/qnxaudiodeviceinfo.h b/src/plugins/qnx-audio/audio/qnxaudiodeviceinfo.h
deleted file mode 100644
index cb620be3b..000000000
--- a/src/plugins/qnx-audio/audio/qnxaudiodeviceinfo.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNXAUDIODEVICEINFO_H
-#define QNXAUDIODEVICEINFO_H
-
-#include "qaudiosystem.h"
-
-QT_BEGIN_NAMESPACE
-
-class QnxAudioDeviceInfo : public QAbstractAudioDeviceInfo
-{
- Q_OBJECT
-
-public:
- QnxAudioDeviceInfo(const QString &deviceName, QAudio::Mode mode);
- ~QnxAudioDeviceInfo();
-
- QAudioFormat preferredFormat() const override;
- bool isFormatSupported(const QAudioFormat &format) const override;
- QString deviceName() const override;
- QStringList supportedCodecs() override;
- QList<int> supportedSampleRates() override;
- QList<int> supportedChannelCounts() override;
- QList<int> supportedSampleSizes() override;
- QList<QAudioFormat::Endian> supportedByteOrders() override;
- QList<QAudioFormat::SampleType> supportedSampleTypes() override;
-
-private:
- const QString m_name;
- const QAudio::Mode m_mode;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx-audio/audio/qnxaudioinput.cpp b/src/plugins/qnx-audio/audio/qnxaudioinput.cpp
deleted file mode 100644
index 31347b7f3..000000000
--- a/src/plugins/qnx-audio/audio/qnxaudioinput.cpp
+++ /dev/null
@@ -1,453 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnxaudioinput.h"
-
-#include "qnxaudioutils.h"
-
-#include <private/qaudiohelpers_p.h>
-
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-QnxAudioInput::QnxAudioInput()
- : m_audioSource(0)
- , m_pcmHandle(0)
- , m_pcmNotifier(0)
- , m_error(QAudio::NoError)
- , m_state(QAudio::StoppedState)
- , m_bytesRead(0)
- , m_elapsedTimeOffset(0)
- , m_totalTimeValue(0)
- , m_volume(qreal(1.0f))
- , m_bytesAvailable(0)
- , m_bufferSize(0)
- , m_periodSize(0)
- , m_intervalTime(1000)
- , m_pullMode(true)
-{
-}
-
-QnxAudioInput::~QnxAudioInput()
-{
- close();
-}
-
-void QnxAudioInput::start(QIODevice *device)
-{
- if (m_state != QAudio::StoppedState)
- close();
-
- if (!m_pullMode && m_audioSource)
- delete m_audioSource;
-
- m_pullMode = true;
- m_audioSource = device;
-
- if (open()) {
- setError(QAudio::NoError);
- setState(QAudio::ActiveState);
- } else {
- setError(QAudio::OpenError);
- setState(QAudio::StoppedState);
- }
-}
-
-QIODevice *QnxAudioInput::start()
-{
- if (m_state != QAudio::StoppedState)
- close();
-
- if (!m_pullMode && m_audioSource)
- delete m_audioSource;
-
- m_pullMode = false;
- m_audioSource = new InputPrivate(this);
- m_audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
-
- if (open()) {
- setError(QAudio::NoError);
- setState(QAudio::IdleState);
- } else {
- delete m_audioSource;
- m_audioSource = 0;
-
- setError(QAudio::OpenError);
- setState(QAudio::StoppedState);
- }
-
- return m_audioSource;
-}
-
-void QnxAudioInput::stop()
-{
- if (m_state == QAudio::StoppedState)
- return;
-
- setError(QAudio::NoError);
- setState(QAudio::StoppedState);
- close();
-}
-
-void QnxAudioInput::reset()
-{
- stop();
- m_bytesAvailable = 0;
-}
-
-void QnxAudioInput::suspend()
-{
- snd_pcm_capture_pause(m_pcmHandle);
-
- if (m_pcmNotifier)
- m_pcmNotifier->setEnabled(false);
-
- setState(QAudio::SuspendedState);
-}
-
-void QnxAudioInput::resume()
-{
- snd_pcm_capture_resume(m_pcmHandle);
-
- if (m_pcmNotifier)
- m_pcmNotifier->setEnabled(true);
-
- if (m_pullMode) {
- setState(QAudio::ActiveState);
- } else {
- setState(QAudio::IdleState);
- }
-}
-
-int QnxAudioInput::bytesReady() const
-{
- return qMax(m_bytesAvailable, 0);
-}
-
-int QnxAudioInput::periodSize() const
-{
- return m_periodSize;
-}
-
-void QnxAudioInput::setBufferSize(int bufferSize)
-{
- m_bufferSize = bufferSize;
-}
-
-int QnxAudioInput::bufferSize() const
-{
- return m_bufferSize;
-}
-
-void QnxAudioInput::setNotifyInterval(int milliSeconds)
-{
- m_intervalTime = qMax(0, milliSeconds);
-}
-
-int QnxAudioInput::notifyInterval() const
-{
- return m_intervalTime;
-}
-
-qint64 QnxAudioInput::processedUSecs() const
-{
- return qint64(1000000) * m_format.framesForBytes(m_bytesRead) / m_format.sampleRate();
-}
-
-qint64 QnxAudioInput::elapsedUSecs() const
-{
- if (m_state == QAudio::StoppedState)
- return 0;
-
- return m_clockStamp.elapsed() * qint64(1000);
-}
-
-QAudio::Error QnxAudioInput::error() const
-{
- return m_error;
-}
-
-QAudio::State QnxAudioInput::state() const
-{
- return m_state;
-}
-
-void QnxAudioInput::setFormat(const QAudioFormat &format)
-{
- if (m_state == QAudio::StoppedState)
- m_format = format;
-}
-
-QAudioFormat QnxAudioInput::format() const
-{
- return m_format;
-}
-
-void QnxAudioInput::setVolume(qreal volume)
-{
- m_volume = qBound(qreal(0.0), volume, qreal(1.0));
-}
-
-qreal QnxAudioInput::volume() const
-{
- return m_volume;
-}
-
-void QnxAudioInput::userFeed()
-{
- if (m_state == QAudio::StoppedState || m_state == QAudio::SuspendedState)
- return;
-
- deviceReady();
-}
-
-bool QnxAudioInput::deviceReady()
-{
- if (m_pullMode) {
- // reads some audio data and writes it to QIODevice
- read(0, 0);
- } else {
- m_bytesAvailable = m_periodSize;
-
- // emits readyRead() so user will call read() on QIODevice to get some audio data
- if (m_audioSource != 0) {
- InputPrivate *input = qobject_cast<InputPrivate*>(m_audioSource);
- input->trigger();
- }
- }
-
- if (m_state != QAudio::ActiveState)
- return true;
-
- if (m_intervalTime && (m_timeStamp.elapsed() + m_elapsedTimeOffset) > m_intervalTime) {
- emit notify();
- m_elapsedTimeOffset = m_timeStamp.elapsed() + m_elapsedTimeOffset - m_intervalTime;
- m_timeStamp.restart();
- }
-
- return true;
-}
-
-bool QnxAudioInput::open()
-{
- if (!m_format.isValid() || m_format.sampleRate() <= 0) {
- if (!m_format.isValid())
- qWarning("QnxAudioInput: open error, invalid format.");
- else
- qWarning("QnxAudioInput: open error, invalid sample rate (%d).", m_format.sampleRate());
-
- return false;
- }
-
- int errorCode = 0;
-
- int card = 0;
- int device = 0;
- if ((errorCode = snd_pcm_open_preferred(&m_pcmHandle, &card, &device, SND_PCM_OPEN_CAPTURE)) < 0) {
- qWarning("QnxAudioInput: open error, couldn't open card (0x%x)", -errorCode);
- return false;
- }
-
- // Necessary so that bytesFree() which uses the "free" member of the status struct works
- snd_pcm_plugin_set_disable(m_pcmHandle, PLUGIN_MMAP);
-
- snd_pcm_channel_info_t info;
- memset(&info, 0, sizeof(info));
- info.channel = SND_PCM_CHANNEL_CAPTURE;
- if ((errorCode = snd_pcm_plugin_info(m_pcmHandle, &info)) < 0) {
- qWarning("QnxAudioInput: open error, couldn't get channel info (0x%x)", -errorCode);
- close();
- return false;
- }
-
- snd_pcm_channel_params_t params = QnxAudioUtils::formatToChannelParams(m_format, QAudio::AudioInput, info.max_fragment_size);
-
- if ((errorCode = snd_pcm_plugin_params(m_pcmHandle, &params)) < 0) {
- qWarning("QnxAudioInput: open error, couldn't set channel params (0x%x)", -errorCode);
- close();
- return false;
- }
-
- if ((errorCode = snd_pcm_plugin_prepare(m_pcmHandle, SND_PCM_CHANNEL_CAPTURE)) < 0) {
- qWarning("QnxAudioInput: open error, couldn't prepare channel (0x%x)", -errorCode);
- close();
- return false;
- }
-
- snd_pcm_channel_setup_t setup;
-
- memset(&setup, 0, sizeof(setup));
- setup.channel = SND_PCM_CHANNEL_CAPTURE;
- if ((errorCode = snd_pcm_plugin_setup(m_pcmHandle, &setup)) < 0) {
- qWarning("QnxAudioInput: open error, couldn't get channel setup (0x%x)", -errorCode);
- close();
- return false;
- }
-
- m_periodSize = qMin(2048, setup.buf.block.frag_size);
-
- m_clockStamp.restart();
- m_timeStamp.restart();
- m_elapsedTimeOffset = 0;
- m_totalTimeValue = 0;
- m_bytesRead = 0;
-
- m_pcmNotifier = new QSocketNotifier(snd_pcm_file_descriptor(m_pcmHandle, SND_PCM_CHANNEL_CAPTURE),
- QSocketNotifier::Read, this);
- connect(m_pcmNotifier, SIGNAL(activated(QSocketDescriptor)), SLOT(userFeed()));
-
- return true;
-}
-
-void QnxAudioInput::close()
-{
- if (m_pcmHandle)
-#if SND_PCM_VERSION < SND_PROTOCOL_VERSION('P',3,0,2)
- snd_pcm_plugin_flush(m_pcmHandle, SND_PCM_CHANNEL_CAPTURE);
-#else
- snd_pcm_plugin_drop(m_pcmHandle, SND_PCM_CHANNEL_CAPTURE);
-#endif
-
- if (m_pcmNotifier) {
- delete m_pcmNotifier;
- m_pcmNotifier = 0;
- }
-
- if (m_pcmHandle) {
- snd_pcm_close(m_pcmHandle);
- m_pcmHandle = 0;
- }
-
- if (!m_pullMode && m_audioSource) {
- delete m_audioSource;
- m_audioSource = 0;
- }
-}
-
-qint64 QnxAudioInput::read(char *data, qint64 len)
-{
- int errorCode = 0;
- QByteArray tempBuffer(m_periodSize, 0);
-
- const int actualRead = snd_pcm_plugin_read(m_pcmHandle, tempBuffer.data(), m_periodSize);
- if (actualRead < 1) {
- snd_pcm_channel_status_t status;
- memset(&status, 0, sizeof(status));
- status.channel = SND_PCM_CHANNEL_CAPTURE;
- if ((errorCode = snd_pcm_plugin_status(m_pcmHandle, &status)) < 0) {
- qWarning("QnxAudioInput: read error, couldn't get plugin status (0x%x)", -errorCode);
- close();
- setError(QAudio::FatalError);
- setState(QAudio::StoppedState);
- return -1;
- }
-
- if (status.status == SND_PCM_STATUS_READY
- || status.status == SND_PCM_STATUS_OVERRUN) {
- if ((errorCode = snd_pcm_plugin_prepare(m_pcmHandle, SND_PCM_CHANNEL_CAPTURE)) < 0) {
- qWarning("QnxAudioInput: read error, couldn't prepare plugin (0x%x)", -errorCode);
- close();
- setError(QAudio::FatalError);
- setState(QAudio::StoppedState);
- return -1;
- }
- }
- } else {
- setError(QAudio::NoError);
- setState(QAudio::ActiveState);
- }
-
- if (m_volume < 1.0f)
- QAudioHelperInternal::qMultiplySamples(m_volume, m_format, tempBuffer.data(), tempBuffer.data(), actualRead);
-
- m_bytesRead += actualRead;
-
- if (m_pullMode) {
- m_audioSource->write(tempBuffer.data(), actualRead);
- } else {
- memcpy(data, tempBuffer.data(), qMin(static_cast<qint64>(actualRead), len));
- }
-
- m_bytesAvailable = 0;
-
- return actualRead;
-}
-
-void QnxAudioInput::setError(QAudio::Error error)
-{
- if (m_error == error)
- return;
-
- m_error = error;
- emit errorChanged(m_error);
-}
-
-void QnxAudioInput::setState(QAudio::State state)
-{
- if (m_state == state)
- return;
-
- m_state = state;
- emit stateChanged(m_state);
-}
-
-InputPrivate::InputPrivate(QnxAudioInput *audio)
- : m_audioDevice(audio)
-{
-}
-
-qint64 InputPrivate::readData(char *data, qint64 len)
-{
- return m_audioDevice->read(data, len);
-}
-
-qint64 InputPrivate::writeData(const char *data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
- return 0;
-}
-
-void InputPrivate::trigger()
-{
- emit readyRead();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx-audio/audio/qnxaudioinput.h b/src/plugins/qnx-audio/audio/qnxaudioinput.h
deleted file mode 100644
index a08491321..000000000
--- a/src/plugins/qnx-audio/audio/qnxaudioinput.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNXAUDIOINPUT_H
-#define QNXAUDIOINPUT_H
-
-#include "qaudiosystem.h"
-
-#include <QSocketNotifier>
-#include <QIODevice>
-#include <QElapsedTimer>
-#include <QTimer>
-
-#include <sys/asoundlib.h>
-
-QT_BEGIN_NAMESPACE
-
-class QnxAudioInput : public QAbstractAudioInput
-{
- Q_OBJECT
-
-public:
- QnxAudioInput();
- ~QnxAudioInput();
-
- void start(QIODevice*) override;
- QIODevice* start() override;
- void stop() override;
- void reset() override;
- void suspend() override;
- void resume() override;
- int bytesReady() const override;
- int periodSize() const override;
- void setBufferSize(int ) override;
- int bufferSize() const override;
- void setNotifyInterval(int ) override;
- int notifyInterval() const override;
- qint64 processedUSecs() const override;
- qint64 elapsedUSecs() const override;
- QAudio::Error error() const override;
- QAudio::State state() const override;
- void setFormat(const QAudioFormat&) override;
- QAudioFormat format() const override;
- void setVolume(qreal) override;
- qreal volume() const override;
-
-private slots:
- void userFeed();
- bool deviceReady();
-
-private:
- friend class InputPrivate;
-
- bool open();
- void close();
- qint64 read(char *data, qint64 len);
- void setError(QAudio::Error error);
- void setState(QAudio::State state);
-
- QElapsedTimer m_timeStamp;
- QElapsedTimer m_clockStamp;
- QAudioFormat m_format;
-
- QIODevice *m_audioSource;
- snd_pcm_t *m_pcmHandle;
- QSocketNotifier *m_pcmNotifier;
-
- QAudio::Error m_error;
- QAudio::State m_state;
-
- qint64 m_bytesRead;
- qint64 m_elapsedTimeOffset;
- qint64 m_totalTimeValue;
-
- qreal m_volume;
-
- int m_bytesAvailable;
- int m_bufferSize;
- int m_periodSize;
- int m_intervalTime;
-
- bool m_pullMode;
-};
-
-class InputPrivate : public QIODevice
-{
- Q_OBJECT
-public:
- InputPrivate(QnxAudioInput *audio);
-
- qint64 readData(char *data, qint64 len) override;
- qint64 writeData(const char *data, qint64 len) override;
-
- void trigger();
-
-private:
- QnxAudioInput *m_audioDevice;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx-audio/audio/qnxaudiooutput.cpp b/src/plugins/qnx-audio/audio/qnxaudiooutput.cpp
deleted file mode 100644
index 34ea23604..000000000
--- a/src/plugins/qnx-audio/audio/qnxaudiooutput.cpp
+++ /dev/null
@@ -1,578 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnxaudiooutput.h"
-
-#include "qnxaudioutils.h"
-
-#include <private/qaudiohelpers_p.h>
-
-#pragma GCC diagnostic ignored "-Wvla"
-
-QT_BEGIN_NAMESPACE
-
-QnxAudioOutput::QnxAudioOutput()
- : m_source(0)
- , m_pushSource(false)
- , m_notifyInterval(1000)
- , m_error(QAudio::NoError)
- , m_state(QAudio::StoppedState)
- , m_volume(1.0)
- , m_periodSize(0)
- , m_pcmHandle(0)
- , m_bytesWritten(0)
- , m_intervalOffset(0)
-#if _NTO_VERSION >= 700
- , m_pcmNotifier(0)
-#endif
-{
- m_timer.setSingleShot(false);
- m_timer.setInterval(20);
- connect(&m_timer, SIGNAL(timeout()), this, SLOT(pullData()));
-}
-
-QnxAudioOutput::~QnxAudioOutput()
-{
- stop();
-}
-
-void QnxAudioOutput::start(QIODevice *source)
-{
- if (m_state != QAudio::StoppedState)
- stop();
-
- m_error = QAudio::NoError;
- m_source = source;
- m_pushSource = false;
-
- if (open()) {
- setState(QAudio::ActiveState);
- m_timer.start();
- } else {
- setError(QAudio::OpenError);
- setState(QAudio::StoppedState);
- }
-}
-
-QIODevice *QnxAudioOutput::start()
-{
- if (m_state != QAudio::StoppedState)
- stop();
-
- m_error = QAudio::NoError;
- m_source = new QnxPushIODevice(this);
- m_source->open(QIODevice::WriteOnly|QIODevice::Unbuffered);
- m_pushSource = true;
-
- if (open())
- setState(QAudio::IdleState);
- else {
- setError(QAudio::OpenError);
- setState(QAudio::StoppedState);
- }
-
- return m_source;
-}
-
-void QnxAudioOutput::stop()
-{
- if (m_state == QAudio::StoppedState)
- return;
-
- setError(QAudio::NoError);
- setState(QAudio::StoppedState);
- close();
-}
-
-void QnxAudioOutput::reset()
-{
- if (m_pcmHandle)
-#if SND_PCM_VERSION < SND_PROTOCOL_VERSION('P',3,0,2)
- snd_pcm_playback_drain(m_pcmHandle);
-#else
- snd_pcm_channel_drain(m_pcmHandle, SND_PCM_CHANNEL_PLAYBACK);
-#endif
- stop();
-}
-
-void QnxAudioOutput::suspend()
-{
- snd_pcm_playback_pause(m_pcmHandle);
- if (state() != QAudio::InterruptedState)
- suspendInternal(QAudio::SuspendedState);
-}
-
-void QnxAudioOutput::resume()
-{
- snd_pcm_playback_resume(m_pcmHandle);
- if (state() != QAudio::InterruptedState)
- resumeInternal();
-}
-
-int QnxAudioOutput::bytesFree() const
-{
- if (m_state != QAudio::ActiveState && m_state != QAudio::IdleState)
- return 0;
-
- snd_pcm_channel_status_t status;
- memset(&status, 0, sizeof(status));
- status.channel = SND_PCM_CHANNEL_PLAYBACK;
- const int errorCode = snd_pcm_plugin_status(m_pcmHandle, &status);
-
- if (errorCode)
- return 0;
- else
- return status.free;
-}
-
-int QnxAudioOutput::periodSize() const
-{
- return m_periodSize;
-}
-
-void QnxAudioOutput::setNotifyInterval(int ms)
-{
- m_notifyInterval = ms;
-}
-
-int QnxAudioOutput::notifyInterval() const
-{
- return m_notifyInterval;
-}
-
-qint64 QnxAudioOutput::processedUSecs() const
-{
- return qint64(1000000) * m_format.framesForBytes(m_bytesWritten) / m_format.sampleRate();
-}
-
-qint64 QnxAudioOutput::elapsedUSecs() const
-{
- if (m_state == QAudio::StoppedState)
- return 0;
- else
- return m_startTimeStamp.elapsed() * qint64(1000);
-}
-
-QAudio::Error QnxAudioOutput::error() const
-{
- return m_error;
-}
-
-QAudio::State QnxAudioOutput::state() const
-{
- return m_state;
-}
-
-void QnxAudioOutput::setFormat(const QAudioFormat &format)
-{
- if (m_state == QAudio::StoppedState)
- m_format = format;
-}
-
-QAudioFormat QnxAudioOutput::format() const
-{
- return m_format;
-}
-
-void QnxAudioOutput::setVolume(qreal volume)
-{
- m_volume = qBound(qreal(0.0), volume, qreal(1.0));
-}
-
-qreal QnxAudioOutput::volume() const
-{
- return m_volume;
-}
-
-void QnxAudioOutput::setCategory(const QString &category)
-{
- m_category = category;
-}
-
-QString QnxAudioOutput::category() const
-{
- return m_category;
-}
-
-void QnxAudioOutput::pullData()
-{
- if (m_state == QAudio::StoppedState
- || m_state == QAudio::SuspendedState
- || m_state == QAudio::InterruptedState)
- return;
-
- const int bytesAvailable = bytesFree();
- const int frames = m_format.framesForBytes(bytesAvailable);
-
- if (frames == 0 || bytesAvailable < periodSize())
- return;
-
- // The buffer is placed on the stack so no more than 64K or 1 frame
- // whichever is larger.
- const int maxFrames = qMax(m_format.framesForBytes(64 * 1024), 1);
- const int bytesRequested = m_format.bytesForFrames(qMin(frames, maxFrames));
-
- char buffer[bytesRequested];
- const int bytesRead = m_source->read(buffer, bytesRequested);
-
- // reading can take a while and stream may have been stopped
- if (!m_pcmHandle)
- return;
-
- if (bytesRead > 0) {
- // Got some data to output
- if (m_state != QAudio::ActiveState)
- return;
-
- const qint64 bytesWritten = write(buffer, bytesRead);
- if (bytesWritten != bytesRead)
- m_source->seek(m_source->pos()-(bytesRead-bytesWritten));
-
- } else {
- // We're done
- close();
- if (bytesRead != 0)
- setError(QAudio::IOError);
- setState(QAudio::StoppedState);
- }
-
- if (m_state != QAudio::ActiveState)
- return;
-
- if (m_notifyInterval > 0 && (m_intervalTimeStamp.elapsed() + m_intervalOffset) > m_notifyInterval) {
- emit notify();
- m_intervalOffset = m_intervalTimeStamp.elapsed() + m_intervalOffset - m_notifyInterval;
- m_intervalTimeStamp.restart();
- }
-}
-
-bool QnxAudioOutput::open()
-{
- if (!m_format.isValid() || m_format.sampleRate() <= 0) {
- if (!m_format.isValid())
- qWarning("QnxAudioOutput: open error, invalid format.");
- else
- qWarning("QnxAudioOutput: open error, invalid sample rate (%d).", m_format.sampleRate());
-
- return false;
- }
-
- int errorCode = 0;
-
- int card = 0;
- int device = 0;
- if ((errorCode = snd_pcm_open_preferred(&m_pcmHandle, &card, &device, SND_PCM_OPEN_PLAYBACK)) < 0) {
- qWarning("QnxAudioOutput: open error, couldn't open card (0x%x)", -errorCode);
- return false;
- }
-
- if ((errorCode = snd_pcm_nonblock_mode(m_pcmHandle, 0)) < 0) {
- qWarning("QnxAudioOutput: open error, couldn't set non block mode (0x%x)", -errorCode);
- close();
- return false;
- }
-
- addPcmEventFilter();
-
- // Necessary so that bytesFree() which uses the "free" member of the status struct works
- snd_pcm_plugin_set_disable(m_pcmHandle, PLUGIN_MMAP);
-
- snd_pcm_channel_info_t info;
- memset(&info, 0, sizeof(info));
- info.channel = SND_PCM_CHANNEL_PLAYBACK;
- if ((errorCode = snd_pcm_plugin_info(m_pcmHandle, &info)) < 0) {
- qWarning("QnxAudioOutput: open error, couldn't get channel info (0x%x)", -errorCode);
- close();
- return false;
- }
-
- snd_pcm_channel_params_t params = QnxAudioUtils::formatToChannelParams(m_format, QAudio::AudioOutput, info.max_fragment_size);
- setTypeName(&params);
-
- if ((errorCode = snd_pcm_plugin_params(m_pcmHandle, &params)) < 0) {
- qWarning("QnxAudioOutput: open error, couldn't set channel params (0x%x)", -errorCode);
- close();
- return false;
- }
-
- if ((errorCode = snd_pcm_plugin_prepare(m_pcmHandle, SND_PCM_CHANNEL_PLAYBACK)) < 0) {
- qWarning("QnxAudioOutput: open error, couldn't prepare channel (0x%x)", -errorCode);
- close();
- return false;
- }
-
- snd_pcm_channel_setup_t setup;
- memset(&setup, 0, sizeof(setup));
- setup.channel = SND_PCM_CHANNEL_PLAYBACK;
- if ((errorCode = snd_pcm_plugin_setup(m_pcmHandle, &setup)) < 0) {
- qWarning("QnxAudioOutput: open error, couldn't get channel setup (0x%x)", -errorCode);
- close();
- return false;
- }
-
- m_periodSize = qMin(2048, setup.buf.block.frag_size);
- m_startTimeStamp.restart();
- m_intervalTimeStamp.restart();
- m_intervalOffset = 0;
- m_bytesWritten = 0;
-
- createPcmNotifiers();
-
- return true;
-}
-
-void QnxAudioOutput::close()
-{
- m_timer.stop();
-
- destroyPcmNotifiers();
-
- if (m_pcmHandle) {
-#if SND_PCM_VERSION < SND_PROTOCOL_VERSION('P',3,0,2)
- snd_pcm_plugin_flush(m_pcmHandle, SND_PCM_CHANNEL_PLAYBACK);
-#else
- snd_pcm_plugin_drop(m_pcmHandle, SND_PCM_CHANNEL_PLAYBACK);
-#endif
- snd_pcm_close(m_pcmHandle);
- m_pcmHandle = 0;
- }
-
- if (m_pushSource) {
- delete m_source;
- m_source = 0;
- }
-}
-
-void QnxAudioOutput::setError(QAudio::Error error)
-{
- if (m_error != error) {
- m_error = error;
- emit errorChanged(error);
- }
-}
-
-void QnxAudioOutput::setState(QAudio::State state)
-{
- if (m_state != state) {
- m_state = state;
- emit stateChanged(state);
- }
-}
-
-qint64 QnxAudioOutput::write(const char *data, qint64 len)
-{
- if (!m_pcmHandle)
- return 0;
-
- // Make sure we're writing (N * frame) worth of bytes
- const int size = m_format.bytesForFrames(qBound(qint64(0), qint64(bytesFree()), len) / m_format.bytesPerFrame());
-
- if (size == 0)
- return 0;
-
- int written = 0;
-
- if (m_volume < 1.0f) {
- char out[size];
- QAudioHelperInternal::qMultiplySamples(m_volume, m_format, data, out, size);
- written = snd_pcm_plugin_write(m_pcmHandle, out, size);
- } else {
- written = snd_pcm_plugin_write(m_pcmHandle, data, size);
- }
-
- if (written > 0) {
- m_bytesWritten += written;
- setError(QAudio::NoError);
- setState(QAudio::ActiveState);
- return written;
- } else {
- close();
- setError(QAudio::FatalError);
- setState(QAudio::StoppedState);
- return 0;
- }
-}
-
-void QnxAudioOutput::suspendInternal(QAudio::State suspendState)
-{
- m_timer.stop();
- setState(suspendState);
-}
-
-void QnxAudioOutput::resumeInternal()
-{
- if (m_pushSource) {
- setState(QAudio::IdleState);
- } else {
- setState(QAudio::ActiveState);
- m_timer.start();
- }
-}
-
-#if _NTO_VERSION >= 700
-
-QAudio::State suspendState(const snd_pcm_event_t &event)
-{
- Q_ASSERT(event.type == SND_PCM_EVENT_AUDIOMGMT_STATUS);
- Q_ASSERT(event.data.audiomgmt_status.new_status == SND_PCM_STATUS_SUSPENDED);
- return event.data.audiomgmt_status.flags & SND_PCM_STATUS_EVENT_HARD_SUSPEND
- ? QAudio::InterruptedState : QAudio::SuspendedState;
-}
-
-void QnxAudioOutput::addPcmEventFilter()
-{
- /* Enable PCM events */
- snd_pcm_filter_t filter;
- memset(&filter, 0, sizeof(filter));
- filter.enable = (1<<SND_PCM_EVENT_AUDIOMGMT_STATUS) |
- (1<<SND_PCM_EVENT_AUDIOMGMT_MUTE) |
- (1<<SND_PCM_EVENT_OUTPUTCLASS);
- snd_pcm_set_filter(m_pcmHandle, SND_PCM_CHANNEL_PLAYBACK, &filter);
-}
-
-void QnxAudioOutput::createPcmNotifiers()
-{
- // QSocketNotifier::Read for poll based event dispatcher. Exception for
- // select based event dispatcher.
- m_pcmNotifier = new QSocketNotifier(snd_pcm_file_descriptor(m_pcmHandle,
- SND_PCM_CHANNEL_PLAYBACK),
- QSocketNotifier::Read, this);
- connect(m_pcmNotifier, &QSocketNotifier::activated,
- this, &QnxAudioOutput::pcmNotifierActivated);
-}
-
-void QnxAudioOutput::destroyPcmNotifiers()
-{
- if (m_pcmNotifier) {
- delete m_pcmNotifier;
- m_pcmNotifier = 0;
- }
-}
-
-void QnxAudioOutput::setTypeName(snd_pcm_channel_params_t *params)
-{
- if (m_category.isEmpty())
- return;
-
- QByteArray latin1Category = m_category.toLatin1();
-
- if (QString::fromLatin1(latin1Category) != m_category) {
- qWarning("QnxAudioOutput: audio category name isn't a Latin1 string.");
- return;
- }
-
- if (latin1Category.size() >= static_cast<int>(sizeof(params->audio_type_name))) {
- qWarning("QnxAudioOutput: audio category name too long.");
- return;
- }
-
- strcpy(params->audio_type_name, latin1Category.constData());
-}
-
-void QnxAudioOutput::pcmNotifierActivated(int socket)
-{
- Q_UNUSED(socket);
-
- snd_pcm_event_t pcm_event;
- memset(&pcm_event, 0, sizeof(pcm_event));
- while (snd_pcm_channel_read_event(m_pcmHandle, SND_PCM_CHANNEL_PLAYBACK, &pcm_event) == 0) {
- if (pcm_event.type == SND_PCM_EVENT_AUDIOMGMT_STATUS) {
- if (pcm_event.data.audiomgmt_status.new_status == SND_PCM_STATUS_SUSPENDED)
- suspendInternal(suspendState(pcm_event));
- else if (pcm_event.data.audiomgmt_status.new_status == SND_PCM_STATUS_RUNNING)
- resumeInternal();
- else if (pcm_event.data.audiomgmt_status.new_status == SND_PCM_STATUS_PAUSED)
- suspendInternal(QAudio::SuspendedState);
- }
- }
-}
-
-#else
-
-void QnxAudioOutput::addPcmEventFilter() {}
-void QnxAudioOutput::createPcmNotifiers() {}
-void QnxAudioOutput::destroyPcmNotifiers() {}
-void QnxAudioOutput::setTypeName(snd_pcm_channel_params_t *) {}
-
-#endif
-
-QnxPushIODevice::QnxPushIODevice(QnxAudioOutput *output)
- : QIODevice(output),
- m_output(output)
-{
-}
-
-QnxPushIODevice::~QnxPushIODevice()
-{
-}
-
-qint64 QnxPushIODevice::readData(char *data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
- return 0;
-}
-
-qint64 QnxPushIODevice::writeData(const char *data, qint64 len)
-{
- int retry = 0;
- qint64 written = 0;
-
- if (m_output->state() == QAudio::ActiveState
- || m_output->state() == QAudio::IdleState) {
- while (written < len) {
- const int writeSize = m_output->write(data + written, len - written);
-
- if (writeSize <= 0) {
- retry++;
- if (retry > 10)
- return written;
- else
- continue;
- }
-
- retry = 0;
- written += writeSize;
- }
- }
-
- return written;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx-audio/audio/qnxaudiooutput.h b/src/plugins/qnx-audio/audio/qnxaudiooutput.h
deleted file mode 100644
index bbbd40b17..000000000
--- a/src/plugins/qnx-audio/audio/qnxaudiooutput.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNXAUDIOOUTPUT_H
-#define QNXAUDIOOUTPUT_H
-
-#include "qaudiosystem.h"
-
-#include <QElapsedTimer>
-#include <QTimer>
-#include <QIODevice>
-#include <QSocketNotifier>
-
-#include <sys/asoundlib.h>
-#include <sys/neutrino.h>
-
-QT_BEGIN_NAMESPACE
-
-class QnxPushIODevice;
-
-class QnxAudioOutput : public QAbstractAudioOutput
-{
- Q_OBJECT
-
-public:
- QnxAudioOutput();
- ~QnxAudioOutput();
-
- void start(QIODevice *source) override;
- QIODevice *start() override;
- void stop() override;
- void reset() override;
- void suspend() override;
- void resume() override;
- int bytesFree() const override;
- int periodSize() const override;
- void setBufferSize(int) override {}
- int bufferSize() const override { return 0; }
- void setNotifyInterval(int ms) override;
- int notifyInterval() const override;
- qint64 processedUSecs() const override;
- qint64 elapsedUSecs() const override;
- QAudio::Error error() const override;
- QAudio::State state() const override;
- void setFormat(const QAudioFormat &format) override;
- QAudioFormat format() const override;
- void setVolume(qreal volume) override;
- qreal volume() const override;
- void setCategory(const QString &category) override;
- QString category() const override;
-
-private slots:
- void pullData();
-
-private:
- bool open();
- void close();
- void setError(QAudio::Error error);
- void setState(QAudio::State state);
-
- void addPcmEventFilter();
- void createPcmNotifiers();
- void destroyPcmNotifiers();
- void setTypeName(snd_pcm_channel_params_t *params);
-
- void suspendInternal(QAudio::State suspendState);
- void resumeInternal();
-
- friend class QnxPushIODevice;
- qint64 write(const char *data, qint64 len);
-
- QIODevice *m_source;
- bool m_pushSource;
- QTimer m_timer;
-
- int m_notifyInterval;
- QAudio::Error m_error;
- QAudio::State m_state;
- QAudioFormat m_format;
- qreal m_volume;
- QString m_category;
- int m_periodSize;
-
- snd_pcm_t *m_pcmHandle;
- qint64 m_bytesWritten;
- QElapsedTimer m_startTimeStamp;
- QElapsedTimer m_intervalTimeStamp;
- qint64 m_intervalOffset;
-
-#if _NTO_VERSION >= 700
- QSocketNotifier *m_pcmNotifier;
-
-private slots:
- void pcmNotifierActivated(int socket);
-#endif
-};
-
-class QnxPushIODevice : public QIODevice
-{
- Q_OBJECT
-public:
- explicit QnxPushIODevice(QnxAudioOutput *output);
- ~QnxPushIODevice();
-
- qint64 readData(char *data, qint64 len);
- qint64 writeData(const char *data, qint64 len);
-
-private:
- QnxAudioOutput *m_output;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx-audio/audio/qnxaudioplugin.cpp b/src/plugins/qnx-audio/audio/qnxaudioplugin.cpp
deleted file mode 100644
index 5d26c8954..000000000
--- a/src/plugins/qnx-audio/audio/qnxaudioplugin.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnxaudioplugin.h"
-
-#include "qnxaudiodeviceinfo.h"
-#include "qnxaudioinput.h"
-#include "qnxaudiooutput.h"
-
-#include <sys/asoundlib.h>
-
-static const char *INPUT_ID = "QnxAudioInput";
-static const char *OUTPUT_ID = "QnxAudioOutput";
-
-QT_BEGIN_NAMESPACE
-
-QnxAudioPlugin::QnxAudioPlugin(QObject *parent)
- : QAudioSystemPlugin(parent)
-{
-}
-
-QByteArray QnxAudioPlugin::defaultDevice(QAudio::Mode mode) const
-{
- return (mode == QAudio::AudioOutput) ? OUTPUT_ID : INPUT_ID;
-}
-
-QList<QByteArray> QnxAudioPlugin::availableDevices(QAudio::Mode mode) const
-{
- if (mode == QAudio::AudioOutput)
- return QList<QByteArray>() << OUTPUT_ID;
- else
- return QList<QByteArray>() << INPUT_ID;
-}
-
-QAbstractAudioInput *QnxAudioPlugin::createInput(const QByteArray &device)
-{
- Q_ASSERT(device == INPUT_ID);
- Q_UNUSED(device);
- return new QnxAudioInput();
-}
-
-QAbstractAudioOutput *QnxAudioPlugin::createOutput(const QByteArray &device)
-{
- Q_ASSERT(device == OUTPUT_ID);
- Q_UNUSED(device);
- return new QnxAudioOutput();
-}
-
-QAbstractAudioDeviceInfo *QnxAudioPlugin::createDeviceInfo(const QByteArray &device, QAudio::Mode mode)
-{
- Q_ASSERT(device == OUTPUT_ID || device == INPUT_ID);
- return new QnxAudioDeviceInfo(device, mode);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx-audio/audio/qnxaudioplugin.h b/src/plugins/qnx-audio/audio/qnxaudioplugin.h
deleted file mode 100644
index d41f4020a..000000000
--- a/src/plugins/qnx-audio/audio/qnxaudioplugin.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNXAUDIOPLUGIN_H
-#define QNXAUDIOPLUGIN_H
-
-#include <QtMultimedia/qaudiosystemplugin.h>
-#include <QtMultimedia/private/qaudiosystempluginext_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QnxAudioPlugin : public QAudioSystemPlugin, public QAudioSystemPluginExtension
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.audiosystemfactory/5.0" FILE "qnx_audio.json")
- Q_INTERFACES(QAudioSystemPluginExtension)
-
-public:
- explicit QnxAudioPlugin(QObject *parent = 0);
- ~QnxAudioPlugin() {}
-
- QByteArray defaultDevice(QAudio::Mode mode) const override;
- QList<QByteArray> availableDevices(QAudio::Mode mode) const override;
- QAbstractAudioInput *createInput(const QByteArray &device) override;
- QAbstractAudioOutput *createOutput(const QByteArray &device) override;
- QAbstractAudioDeviceInfo *createDeviceInfo(const QByteArray &device, QAudio::Mode mode) override;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx-audio/audio/qnxaudioutils.cpp b/src/plugins/qnx-audio/audio/qnxaudioutils.cpp
deleted file mode 100644
index ee7bccbda..000000000
--- a/src/plugins/qnx-audio/audio/qnxaudioutils.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qnxaudioutils.h"
-
-QT_BEGIN_NAMESPACE
-
-snd_pcm_channel_params_t QnxAudioUtils::formatToChannelParams(const QAudioFormat &format, QAudio::Mode mode, int fragmentSize)
-{
- snd_pcm_channel_params_t params;
- memset(&params, 0, sizeof(params));
- params.channel = (mode == QAudio::AudioOutput) ? SND_PCM_CHANNEL_PLAYBACK : SND_PCM_CHANNEL_CAPTURE;
- params.mode = SND_PCM_MODE_BLOCK;
- params.start_mode = SND_PCM_START_DATA;
- params.stop_mode = SND_PCM_STOP_ROLLOVER;
- params.buf.block.frag_size = fragmentSize;
- params.buf.block.frags_min = 1;
- params.buf.block.frags_max = 1;
- strcpy(params.sw_mixer_subchn_name, "QAudio Channel");
-
- params.format.interleave = 1;
- params.format.rate = format.sampleRate();
- params.format.voices = format.channelCount();
-
- switch (format.sampleSize()) {
- case 8:
- switch (format.sampleType()) {
- case QAudioFormat::SignedInt:
- params.format.format = SND_PCM_SFMT_S8;
- break;
- case QAudioFormat::UnSignedInt:
- params.format.format = SND_PCM_SFMT_U8;
- break;
- default:
- break;
- }
- break;
-
- case 16:
- switch (format.sampleType()) {
- case QAudioFormat::SignedInt:
- if (format.byteOrder() == QAudioFormat::LittleEndian) {
- params.format.format = SND_PCM_SFMT_S16_LE;
- } else {
- params.format.format = SND_PCM_SFMT_S16_BE;
- }
- break;
- case QAudioFormat::UnSignedInt:
- if (format.byteOrder() == QAudioFormat::LittleEndian) {
- params.format.format = SND_PCM_SFMT_U16_LE;
- } else {
- params.format.format = SND_PCM_SFMT_U16_BE;
- }
- break;
- default:
- break;
- }
- break;
-
- case 32:
- switch (format.sampleType()) {
- case QAudioFormat::SignedInt:
- if (format.byteOrder() == QAudioFormat::LittleEndian) {
- params.format.format = SND_PCM_SFMT_S32_LE;
- } else {
- params.format.format = SND_PCM_SFMT_S32_BE;
- }
- break;
- case QAudioFormat::UnSignedInt:
- if (format.byteOrder() == QAudioFormat::LittleEndian) {
- params.format.format = SND_PCM_SFMT_U32_LE;
- } else {
- params.format.format = SND_PCM_SFMT_U32_BE;
- }
- break;
- case QAudioFormat::Float:
- if (format.byteOrder() == QAudioFormat::LittleEndian) {
- params.format.format = SND_PCM_SFMT_FLOAT_LE;
- } else {
- params.format.format = SND_PCM_SFMT_FLOAT_BE;
- }
- break;
- default:
- break;
- }
- break;
- }
-
- return params;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx-audio/audio/qnxaudioutils.h b/src/plugins/qnx-audio/audio/qnxaudioutils.h
deleted file mode 100644
index 2f3db63c1..000000000
--- a/src/plugins/qnx-audio/audio/qnxaudioutils.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QNXAUDIOUTILS_H
-#define QNXAUDIOUTILS_H
-
-#include "qaudiosystem.h"
-#include <sys/asoundlib.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace QnxAudioUtils
-{
- snd_pcm_channel_params_t formatToChannelParams(const QAudioFormat &format, QAudio::Mode mode, int fragmentSize);
-}
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx-audio/qnx-audio.pro b/src/plugins/qnx-audio/qnx-audio.pro
deleted file mode 100644
index 3049729b8..000000000
--- a/src/plugins/qnx-audio/qnx-audio.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS = audio
diff --git a/src/plugins/qnx/camera/bbcameraaudioencodersettingscontrol.cpp b/src/plugins/qnx/camera/bbcameraaudioencodersettingscontrol.cpp
deleted file mode 100644
index 96686830f..000000000
--- a/src/plugins/qnx/camera/bbcameraaudioencodersettingscontrol.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameraaudioencodersettingscontrol.h"
-
-#include "bbcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-BbCameraAudioEncoderSettingsControl::BbCameraAudioEncoderSettingsControl(BbCameraSession *session, QObject *parent)
- : QAudioEncoderSettingsControl(parent)
- , m_session(session)
-{
-}
-
-QStringList BbCameraAudioEncoderSettingsControl::supportedAudioCodecs() const
-{
- return QStringList() << QLatin1String("none") << QLatin1String("aac") << QLatin1String("raw");
-}
-
-QString BbCameraAudioEncoderSettingsControl::codecDescription(const QString &codecName) const
-{
- if (codecName == QLatin1String("none"))
- return tr("No compression");
- else if (codecName == QLatin1String("aac"))
- return tr("AAC compression");
- else if (codecName == QLatin1String("raw"))
- return tr("PCM uncompressed");
-
- return QString();
-}
-
-QList<int> BbCameraAudioEncoderSettingsControl::supportedSampleRates(const QAudioEncoderSettings &settings, bool *continuous) const
-{
- Q_UNUSED(settings);
- Q_UNUSED(continuous);
-
- // no API provided by BB10 yet
- return QList<int>();
-}
-
-QAudioEncoderSettings BbCameraAudioEncoderSettingsControl::audioSettings() const
-{
- return m_session->audioSettings();
-}
-
-void BbCameraAudioEncoderSettingsControl::setAudioSettings(const QAudioEncoderSettings &settings)
-{
- m_session->setAudioSettings(settings);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameraaudioencodersettingscontrol.h b/src/plugins/qnx/camera/bbcameraaudioencodersettingscontrol.h
deleted file mode 100644
index 38c01f86c..000000000
--- a/src/plugins/qnx/camera/bbcameraaudioencodersettingscontrol.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERAAUDIOENCODERSETTINGSCONTROL_H
-#define BBCAMERAAUDIOENCODERSETTINGSCONTROL_H
-
-#include <qaudioencodersettingscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraAudioEncoderSettingsControl : public QAudioEncoderSettingsControl
-{
- Q_OBJECT
-public:
- explicit BbCameraAudioEncoderSettingsControl(BbCameraSession *session, QObject *parent = 0);
-
- QStringList supportedAudioCodecs() const override;
- QString codecDescription(const QString &codecName) const override;
- QList<int> supportedSampleRates(const QAudioEncoderSettings &settings, bool *continuous = 0) const override;
- QAudioEncoderSettings audioSettings() const override;
- void setAudioSettings(const QAudioEncoderSettings &settings) override;
-
-private:
- BbCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameracapturebufferformatcontrol.cpp b/src/plugins/qnx/camera/bbcameracapturebufferformatcontrol.cpp
deleted file mode 100644
index a2607ca93..000000000
--- a/src/plugins/qnx/camera/bbcameracapturebufferformatcontrol.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameracapturebufferformatcontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-BbCameraCaptureBufferFormatControl::BbCameraCaptureBufferFormatControl(QObject *parent)
- : QCameraCaptureBufferFormatControl(parent)
-{
-}
-
-QList<QVideoFrame::PixelFormat> BbCameraCaptureBufferFormatControl::supportedBufferFormats() const
-{
- return (QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_Jpeg);
-}
-
-QVideoFrame::PixelFormat BbCameraCaptureBufferFormatControl::bufferFormat() const
-{
- return QVideoFrame::Format_Jpeg;
-}
-
-void BbCameraCaptureBufferFormatControl::setBufferFormat(QVideoFrame::PixelFormat format)
-{
- Q_UNUSED(format);
- // Do nothing, we support only Jpeg for now
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameracapturebufferformatcontrol.h b/src/plugins/qnx/camera/bbcameracapturebufferformatcontrol.h
deleted file mode 100644
index 4aac740c8..000000000
--- a/src/plugins/qnx/camera/bbcameracapturebufferformatcontrol.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERACAPTUREBUFFERFORMATCONTROL_H
-#define BBCAMERACAPTUREBUFFERFORMATCONTROL_H
-
-#include <qcameracapturebufferformatcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraCaptureBufferFormatControl : public QCameraCaptureBufferFormatControl
-{
- Q_OBJECT
-public:
- explicit BbCameraCaptureBufferFormatControl(QObject *parent = 0);
-
- QList<QVideoFrame::PixelFormat> supportedBufferFormats() const override;
- QVideoFrame::PixelFormat bufferFormat() const override;
- void setBufferFormat(QVideoFrame::PixelFormat format) override;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameracapturedestinationcontrol.cpp b/src/plugins/qnx/camera/bbcameracapturedestinationcontrol.cpp
deleted file mode 100644
index 8dad17208..000000000
--- a/src/plugins/qnx/camera/bbcameracapturedestinationcontrol.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameracapturedestinationcontrol.h"
-
-#include "bbcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-BbCameraCaptureDestinationControl::BbCameraCaptureDestinationControl(BbCameraSession *session, QObject *parent)
- : QCameraCaptureDestinationControl(parent)
- , m_session(session)
-{
- connect(m_session, SIGNAL(captureDestinationChanged(QCameraImageCapture::CaptureDestinations)),
- this, SIGNAL(captureDestinationChanged(QCameraImageCapture::CaptureDestinations)));
-}
-
-bool BbCameraCaptureDestinationControl::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const
-{
- return m_session->isCaptureDestinationSupported(destination);
-}
-
-QCameraImageCapture::CaptureDestinations BbCameraCaptureDestinationControl::captureDestination() const
-{
- return m_session->captureDestination();;
-}
-
-void BbCameraCaptureDestinationControl::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination)
-{
- m_session->setCaptureDestination(destination);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameracapturedestinationcontrol.h b/src/plugins/qnx/camera/bbcameracapturedestinationcontrol.h
deleted file mode 100644
index 9586ec56a..000000000
--- a/src/plugins/qnx/camera/bbcameracapturedestinationcontrol.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERACAPTUREDESTINATIONCONTROL_H
-#define BBCAMERACAPTUREDESTINATIONCONTROL_H
-
-#include <qcameracapturedestinationcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraCaptureDestinationControl : public QCameraCaptureDestinationControl
-{
- Q_OBJECT
-public:
- explicit BbCameraCaptureDestinationControl(BbCameraSession *session, QObject *parent = 0);
-
- bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const override;
- QCameraImageCapture::CaptureDestinations captureDestination() const override;
- void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) override;
-
-private:
- BbCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameracontrol.cpp b/src/plugins/qnx/camera/bbcameracontrol.cpp
deleted file mode 100644
index 8652c0528..000000000
--- a/src/plugins/qnx/camera/bbcameracontrol.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameracontrol.h"
-
-#include "bbcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-BbCameraControl::BbCameraControl(BbCameraSession *session, QObject *parent)
- : QCameraControl(parent)
- , m_session(session)
-{
- connect(m_session, SIGNAL(statusChanged(QCamera::Status)), this, SIGNAL(statusChanged(QCamera::Status)));
- connect(m_session, SIGNAL(stateChanged(QCamera::State)), this, SIGNAL(stateChanged(QCamera::State)));
- connect(m_session, SIGNAL(error(int,QString)), this, SIGNAL(error(int,QString)));
- connect(m_session, SIGNAL(captureModeChanged(QCamera::CaptureModes)), this, SIGNAL(captureModeChanged(QCamera::CaptureModes)));
-}
-
-QCamera::State BbCameraControl::state() const
-{
- return m_session->state();
-}
-
-void BbCameraControl::setState(QCamera::State state)
-{
- m_session->setState(state);
-}
-
-QCamera::CaptureModes BbCameraControl::captureMode() const
-{
- return m_session->captureMode();
-}
-
-void BbCameraControl::setCaptureMode(QCamera::CaptureModes mode)
-{
- m_session->setCaptureMode(mode);
-}
-
-QCamera::Status BbCameraControl::status() const
-{
- return m_session->status();
-}
-
-bool BbCameraControl::isCaptureModeSupported(QCamera::CaptureModes mode) const
-{
- return m_session->isCaptureModeSupported(mode);
-}
-
-bool BbCameraControl::canChangeProperty(PropertyChangeType /* changeType */, QCamera::Status /* status */) const
-{
- return false;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameracontrol.h b/src/plugins/qnx/camera/bbcameracontrol.h
deleted file mode 100644
index 0c97bd83c..000000000
--- a/src/plugins/qnx/camera/bbcameracontrol.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERACONTROL_H
-#define BBCAMERACONTROL_H
-
-#include <qcameracontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraControl : public QCameraControl
-{
- Q_OBJECT
-public:
- explicit BbCameraControl(BbCameraSession *session, QObject *parent = 0);
-
- QCamera::State state() const override;
- void setState(QCamera::State state) override;
-
- QCamera::Status status() const override;
-
- QCamera::CaptureModes captureMode() const override;
- void setCaptureMode(QCamera::CaptureModes) override;
- bool isCaptureModeSupported(QCamera::CaptureModes mode) const override;
-
- bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const override;
-
-private:
- BbCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameraexposurecontrol.cpp b/src/plugins/qnx/camera/bbcameraexposurecontrol.cpp
deleted file mode 100644
index 795e42877..000000000
--- a/src/plugins/qnx/camera/bbcameraexposurecontrol.cpp
+++ /dev/null
@@ -1,232 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameraexposurecontrol.h"
-
-#include "bbcamerasession.h"
-
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-BbCameraExposureControl::BbCameraExposureControl(BbCameraSession *session, QObject *parent)
- : QCameraExposureControl(parent)
- , m_session(session)
- , m_requestedExposureMode(QCameraExposure::ExposureAuto)
-{
- connect(m_session, SIGNAL(statusChanged(QCamera::Status)), this, SLOT(statusChanged(QCamera::Status)));
-}
-
-bool BbCameraExposureControl::isParameterSupported(ExposureParameter parameter) const
-{
- switch (parameter) {
- case QCameraExposureControl::ISO:
- return false;
- case QCameraExposureControl::Aperture:
- return false;
- case QCameraExposureControl::ShutterSpeed:
- return false;
- case QCameraExposureControl::ExposureCompensation:
- return false;
- case QCameraExposureControl::FlashPower:
- return false;
- case QCameraExposureControl::FlashCompensation:
- return false;
- case QCameraExposureControl::TorchPower:
- return false;
- case QCameraExposureControl::SpotMeteringPoint:
- return false;
- case QCameraExposureControl::ExposureMode:
- return true;
- case QCameraExposureControl::MeteringMode:
- return false;
- default:
- return false;
- }
-}
-
-QVariantList BbCameraExposureControl::supportedParameterRange(ExposureParameter parameter, bool *continuous) const
-{
- if (parameter != QCameraExposureControl::ExposureMode) // no other parameter supported by BB10 API at the moment
- return QVariantList();
-
- if (m_session->status() != QCamera::ActiveStatus) // we can query supported exposure modes only with active viewfinder
- return QVariantList();
-
- if (continuous)
- *continuous = false;
-
- int supported = 0;
- camera_scenemode_t modes[20];
- const camera_error_t result = camera_get_scene_modes(m_session->handle(), 20, &supported, modes);
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve supported scene modes:" << result;
- return QVariantList();
- }
-
- QVariantList exposureModes;
- for (int i = 0; i < supported; ++i) {
- switch (modes[i]) {
- case CAMERA_SCENE_AUTO:
- exposureModes << QVariant::fromValue(QCameraExposure::ExposureAuto);
- break;
- case CAMERA_SCENE_SPORTS:
- exposureModes << QVariant::fromValue(QCameraExposure::ExposureSports);
- break;
- case CAMERA_SCENE_CLOSEUP:
- exposureModes << QVariant::fromValue(QCameraExposure::ExposurePortrait);
- break;
- case CAMERA_SCENE_ACTION:
- exposureModes << QVariant::fromValue(QCameraExposure::ExposureSports);
- break;
- case CAMERA_SCENE_BEACHANDSNOW:
- exposureModes << QVariant::fromValue(QCameraExposure::ExposureBeach) << QVariant::fromValue(QCameraExposure::ExposureSnow);
- break;
- case CAMERA_SCENE_NIGHT:
- exposureModes << QVariant::fromValue(QCameraExposure::ExposureNight);
- break;
- default: break;
- }
- }
-
- return exposureModes;
-}
-
-QVariant BbCameraExposureControl::requestedValue(ExposureParameter parameter) const
-{
- if (parameter != QCameraExposureControl::ExposureMode) // no other parameter supported by BB10 API at the moment
- return QVariant();
-
- return QVariant::fromValue(m_requestedExposureMode);
-}
-
-QVariant BbCameraExposureControl::actualValue(ExposureParameter parameter) const
-{
- if (parameter != QCameraExposureControl::ExposureMode) // no other parameter supported by BB10 API at the moment
- return QVariantList();
-
- if (m_session->status() != QCamera::ActiveStatus) // we can query actual scene modes only with active viewfinder
- return QVariantList();
-
- camera_scenemode_t sceneMode = CAMERA_SCENE_DEFAULT;
- const camera_error_t result = camera_get_scene_mode(m_session->handle(), &sceneMode);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve scene mode:" << result;
- return QVariant();
- }
-
- switch (sceneMode) {
- case CAMERA_SCENE_AUTO:
- return QVariant::fromValue(QCameraExposure::ExposureAuto);
- case CAMERA_SCENE_SPORTS:
- return QVariant::fromValue(QCameraExposure::ExposureSports);
- case CAMERA_SCENE_CLOSEUP:
- return QVariant::fromValue(QCameraExposure::ExposurePortrait);
- case CAMERA_SCENE_ACTION:
- return QVariant::fromValue(QCameraExposure::ExposureSports);
- case CAMERA_SCENE_BEACHANDSNOW:
- return (m_requestedExposureMode == QCameraExposure::ExposureBeach ? QVariant::fromValue(QCameraExposure::ExposureBeach)
- : QVariant::fromValue(QCameraExposure::ExposureSnow));
- case CAMERA_SCENE_NIGHT:
- return QVariant::fromValue(QCameraExposure::ExposureNight);
- default:
- break;
- }
-
- return QVariant();
-}
-
-bool BbCameraExposureControl::setValue(ExposureParameter parameter, const QVariant& value)
-{
- if (parameter != QCameraExposureControl::ExposureMode) // no other parameter supported by BB10 API at the moment
- return false;
-
- if (m_session->status() != QCamera::ActiveStatus) // we can set actual scene modes only with active viewfinder
- return false;
-
- camera_scenemode_t sceneMode = CAMERA_SCENE_DEFAULT;
-
- if (value.isValid()) {
- m_requestedExposureMode = value.value<QCameraExposure::ExposureMode>();
- emit requestedValueChanged(QCameraExposureControl::ExposureMode);
-
- switch (m_requestedExposureMode) {
- case QCameraExposure::ExposureAuto:
- sceneMode = CAMERA_SCENE_AUTO;
- break;
- case QCameraExposure::ExposureSports:
- sceneMode = CAMERA_SCENE_SPORTS;
- break;
- case QCameraExposure::ExposurePortrait:
- sceneMode = CAMERA_SCENE_CLOSEUP;
- break;
- case QCameraExposure::ExposureBeach:
- sceneMode = CAMERA_SCENE_BEACHANDSNOW;
- break;
- case QCameraExposure::ExposureSnow:
- sceneMode = CAMERA_SCENE_BEACHANDSNOW;
- break;
- case QCameraExposure::ExposureNight:
- sceneMode = CAMERA_SCENE_NIGHT;
- break;
- default:
- sceneMode = CAMERA_SCENE_DEFAULT;
- break;
- }
- }
-
- const camera_error_t result = camera_set_scene_mode(m_session->handle(), sceneMode);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to set scene mode:" << result;
- return false;
- }
-
- emit actualValueChanged(QCameraExposureControl::ExposureMode);
-
- return true;
-}
-
-void BbCameraExposureControl::statusChanged(QCamera::Status status)
-{
- if (status == QCamera::ActiveStatus || status == QCamera::LoadedStatus)
- emit parameterRangeChanged(QCameraExposureControl::ExposureMode);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameraexposurecontrol.h b/src/plugins/qnx/camera/bbcameraexposurecontrol.h
deleted file mode 100644
index 2d0da29bd..000000000
--- a/src/plugins/qnx/camera/bbcameraexposurecontrol.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERAEXPOSURECONTROL_H
-#define BBCAMERAEXPOSURECONTROL_H
-
-#include <qcameraexposurecontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraExposureControl : public QCameraExposureControl
-{
- Q_OBJECT
-public:
- explicit BbCameraExposureControl(BbCameraSession *session, QObject *parent = 0);
-
- bool isParameterSupported(ExposureParameter parameter) const override;
- QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const override;
-
- QVariant requestedValue(ExposureParameter parameter) const override;
- QVariant actualValue(ExposureParameter parameter) const override;
- bool setValue(ExposureParameter parameter, const QVariant& value) override;
-
-private Q_SLOTS:
- void statusChanged(QCamera::Status status);
-
-private:
- BbCameraSession *m_session;
- QCameraExposure::ExposureMode m_requestedExposureMode;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameraflashcontrol.cpp b/src/plugins/qnx/camera/bbcameraflashcontrol.cpp
deleted file mode 100644
index 1cf8b38f9..000000000
--- a/src/plugins/qnx/camera/bbcameraflashcontrol.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameraflashcontrol.h"
-
-#include "bbcamerasession.h"
-
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-BbCameraFlashControl::BbCameraFlashControl(BbCameraSession *session, QObject *parent)
- : QCameraFlashControl(parent)
- , m_session(session)
- , m_flashMode(QCameraExposure::FlashAuto)
-{
-}
-
-QCameraExposure::FlashModes BbCameraFlashControl::flashMode() const
-{
- return m_flashMode;
-}
-
-void BbCameraFlashControl::setFlashMode(QCameraExposure::FlashModes mode)
-{
- if (m_flashMode == mode)
- return;
-
- if (m_session->status() != QCamera::ActiveStatus) // can only be changed when viewfinder is active
- return;
-
- if (m_flashMode == QCameraExposure::FlashVideoLight) {
- const camera_error_t result = camera_config_videolight(m_session->handle(), CAMERA_VIDEOLIGHT_OFF);
- if (result != CAMERA_EOK)
- qWarning() << "Unable to switch off video light:" << result;
- }
-
- m_flashMode = mode;
-
- if (m_flashMode == QCameraExposure::FlashVideoLight) {
- const camera_error_t result = camera_config_videolight(m_session->handle(), CAMERA_VIDEOLIGHT_ON);
- if (result != CAMERA_EOK)
- qWarning() << "Unable to switch on video light:" << result;
- } else {
- camera_flashmode_t flashMode = CAMERA_FLASH_AUTO;
-
- if (m_flashMode.testFlag(QCameraExposure::FlashAuto)) flashMode = CAMERA_FLASH_AUTO;
- else if (mode.testFlag(QCameraExposure::FlashOff)) flashMode = CAMERA_FLASH_OFF;
- else if (mode.testFlag(QCameraExposure::FlashOn)) flashMode = CAMERA_FLASH_ON;
-
- const camera_error_t result = camera_config_flash(m_session->handle(), flashMode);
- if (result != CAMERA_EOK)
- qWarning() << "Unable to configure flash:" << result;
- }
-}
-
-bool BbCameraFlashControl::isFlashModeSupported(QCameraExposure::FlashModes mode) const
-{
- bool supportsVideoLight = false;
- if (m_session->handle() != CAMERA_HANDLE_INVALID) {
- supportsVideoLight = camera_has_feature(m_session->handle(), CAMERA_FEATURE_VIDEOLIGHT);
- }
-
- return (mode == QCameraExposure::FlashOff ||
- mode == QCameraExposure::FlashOn ||
- mode == QCameraExposure::FlashAuto ||
- ((mode == QCameraExposure::FlashVideoLight) && supportsVideoLight));
-}
-
-bool BbCameraFlashControl::isFlashReady() const
-{
- //TODO: check for flash charge-level here?!?
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameraflashcontrol.h b/src/plugins/qnx/camera/bbcameraflashcontrol.h
deleted file mode 100644
index 8ce9c1f41..000000000
--- a/src/plugins/qnx/camera/bbcameraflashcontrol.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERAFLASHCONTROL_H
-#define BBCAMERAFLASHCONTROL_H
-
-#include <qcameraflashcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraFlashControl : public QCameraFlashControl
-{
- Q_OBJECT
-public:
- explicit BbCameraFlashControl(BbCameraSession *session, QObject *parent = 0);
-
- QCameraExposure::FlashModes flashMode() const override;
- void setFlashMode(QCameraExposure::FlashModes mode) override;
- bool isFlashModeSupported(QCameraExposure::FlashModes mode) const override;
- bool isFlashReady() const override;
-
-private:
- BbCameraSession *m_session;
- QCameraExposure::FlashModes m_flashMode;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcamerafocuscontrol.cpp b/src/plugins/qnx/camera/bbcamerafocuscontrol.cpp
deleted file mode 100644
index a815882d2..000000000
--- a/src/plugins/qnx/camera/bbcamerafocuscontrol.cpp
+++ /dev/null
@@ -1,329 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcamerafocuscontrol.h"
-
-#include "bbcamerasession.h"
-
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-BbCameraFocusControl::BbCameraFocusControl(BbCameraSession *session, QObject *parent)
- : QCameraFocusControl(parent)
- , m_session(session)
- , m_focusMode(QCameraFocus::FocusModes())
- , m_focusPointMode(QCameraFocus::FocusPointAuto)
- , m_customFocusPoint(QPointF(0, 0))
-{
-}
-
-QCameraFocus::FocusModes BbCameraFocusControl::focusMode() const
-{
- camera_focusmode_t focusMode = CAMERA_FOCUSMODE_OFF;
-
- const camera_error_t result = camera_get_focus_mode(m_session->handle(), &focusMode);
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve focus mode from camera:" << result;
- return QCameraFocus::FocusModes();
- }
-
- switch (focusMode) {
- case CAMERA_FOCUSMODE_EDOF:
- return QCameraFocus::HyperfocalFocus;
- case CAMERA_FOCUSMODE_MANUAL:
- return QCameraFocus::ManualFocus;
- case CAMERA_FOCUSMODE_AUTO:
- return QCameraFocus::AutoFocus;
- case CAMERA_FOCUSMODE_MACRO:
- return QCameraFocus::MacroFocus;
- case CAMERA_FOCUSMODE_CONTINUOUS_AUTO:
- return QCameraFocus::ContinuousFocus;
- case CAMERA_FOCUSMODE_CONTINUOUS_MACRO: // fall through
- case CAMERA_FOCUSMODE_OFF: // fall through
- default:
- return QCameraFocus::FocusModes();
- }
-}
-
-void BbCameraFocusControl::setFocusMode(QCameraFocus::FocusModes mode)
-{
- if (m_focusMode == mode)
- return;
-
- camera_focusmode_t focusMode = CAMERA_FOCUSMODE_OFF;
-
- if (mode == QCameraFocus::HyperfocalFocus)
- focusMode = CAMERA_FOCUSMODE_EDOF;
- else if (mode == QCameraFocus::ManualFocus)
- focusMode = CAMERA_FOCUSMODE_MANUAL;
- else if (mode == QCameraFocus::AutoFocus)
- focusMode = CAMERA_FOCUSMODE_AUTO;
- else if (mode == QCameraFocus::MacroFocus)
- focusMode = CAMERA_FOCUSMODE_MACRO;
- else if (mode == QCameraFocus::ContinuousFocus)
- focusMode = CAMERA_FOCUSMODE_CONTINUOUS_AUTO;
-
- const camera_error_t result = camera_set_focus_mode(m_session->handle(), focusMode);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to set focus mode:" << result;
- return;
- }
-
- m_focusMode = mode;
- emit focusModeChanged(m_focusMode);
-}
-
-bool BbCameraFocusControl::isFocusModeSupported(QCameraFocus::FocusModes mode) const
-{
- if (m_session->state() == QCamera::UnloadedState)
- return false;
-
- if (mode == QCameraFocus::HyperfocalFocus)
- return false; //TODO how to check?
- else if (mode == QCameraFocus::ManualFocus)
- return camera_has_feature(m_session->handle(), CAMERA_FEATURE_MANUALFOCUS);
- else if (mode == QCameraFocus::AutoFocus)
- return camera_has_feature(m_session->handle(), CAMERA_FEATURE_AUTOFOCUS);
- else if (mode == QCameraFocus::MacroFocus)
- return camera_has_feature(m_session->handle(), CAMERA_FEATURE_MACROFOCUS);
- else if (mode == QCameraFocus::ContinuousFocus)
- return camera_has_feature(m_session->handle(), CAMERA_FEATURE_AUTOFOCUS);
-
- return false;
-}
-
-QCameraFocus::FocusPointMode BbCameraFocusControl::focusPointMode() const
-{
- return m_focusPointMode;
-}
-
-void BbCameraFocusControl::setFocusPointMode(QCameraFocus::FocusPointMode mode)
-{
- if (m_session->status() != QCamera::ActiveStatus)
- return;
-
- if (m_focusPointMode == mode)
- return;
-
- m_focusPointMode = mode;
- emit focusPointModeChanged(m_focusPointMode);
-
- if (m_focusPointMode == QCameraFocus::FocusPointAuto) {
- //TODO: is this correct?
- const camera_error_t result = camera_set_focus_regions(m_session->handle(), 0, 0);
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to set focus region:" << result;
- return;
- }
-
- emit focusZonesChanged();
- } else if (m_focusPointMode == QCameraFocus::FocusPointCenter) {
- // get the size of the viewfinder
- int viewfinderWidth = 0;
- int viewfinderHeight = 0;
-
- if (!retrieveViewfinderSize(&viewfinderWidth, &viewfinderHeight))
- return;
-
- // define a 40x40 pixel focus region in the center of the viewfinder
- camera_region_t focusRegion;
- focusRegion.left = (viewfinderWidth / 2) - 20;
- focusRegion.top = (viewfinderHeight / 2) - 20;
- focusRegion.width = 40;
- focusRegion.height = 40;
-
- camera_error_t result = camera_set_focus_regions(m_session->handle(), 1, &focusRegion);
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to set focus region:" << result;
- return;
- }
-
- // re-set focus mode to apply focus region changes
- camera_focusmode_t focusMode = CAMERA_FOCUSMODE_OFF;
- result = camera_get_focus_mode(m_session->handle(), &focusMode);
- camera_set_focus_mode(m_session->handle(), focusMode);
-
- emit focusZonesChanged();
-
- } else if (m_focusPointMode == QCameraFocus::FocusPointFaceDetection) {
- //TODO: implement later
- } else if (m_focusPointMode == QCameraFocus::FocusPointCustom) {
- updateCustomFocusRegion();
- }
-}
-
-bool BbCameraFocusControl::isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const
-{
- if (m_session->state() == QCamera::UnloadedState)
- return false;
-
- if (mode == QCameraFocus::FocusPointAuto) {
- return camera_has_feature(m_session->handle(), CAMERA_FEATURE_AUTOFOCUS);
- } else if (mode == QCameraFocus::FocusPointCenter) {
- return camera_has_feature(m_session->handle(), CAMERA_FEATURE_REGIONFOCUS);
- } else if (mode == QCameraFocus::FocusPointFaceDetection) {
- return false; //TODO: implement via custom region in combination with face detection in viewfinder
- } else if (mode == QCameraFocus::FocusPointCustom) {
- return camera_has_feature(m_session->handle(), CAMERA_FEATURE_REGIONFOCUS);
- }
-
- return false;
-}
-
-QPointF BbCameraFocusControl::customFocusPoint() const
-{
- return m_customFocusPoint;
-}
-
-void BbCameraFocusControl::setCustomFocusPoint(const QPointF &point)
-{
- if (m_customFocusPoint == point)
- return;
-
- m_customFocusPoint = point;
- emit customFocusPointChanged(m_customFocusPoint);
-
- updateCustomFocusRegion();
-}
-
-QCameraFocusZoneList BbCameraFocusControl::focusZones() const
-{
- if (m_session->state() == QCamera::UnloadedState)
- return QCameraFocusZoneList();
-
- camera_region_t regions[20];
- int supported = 0;
- int asked = 0;
- camera_error_t result = camera_get_focus_regions(m_session->handle(), 20, &supported, &asked, regions);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve focus regions:" << result;
- return QCameraFocusZoneList();
- }
-
- // retrieve width and height of viewfinder
- int viewfinderWidth = 0;
- int viewfinderHeight = 0;
- if (m_session->captureMode() & QCamera::CaptureStillImage)
- result = camera_get_photovf_property(m_session->handle(),
- CAMERA_IMGPROP_WIDTH, &viewfinderWidth,
- CAMERA_IMGPROP_HEIGHT, &viewfinderHeight);
- else if (m_session->captureMode() & QCamera::CaptureVideo)
- result = camera_get_videovf_property(m_session->handle(),
- CAMERA_IMGPROP_WIDTH, &viewfinderWidth,
- CAMERA_IMGPROP_HEIGHT, &viewfinderHeight);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve viewfinder size:" << result;
- return QCameraFocusZoneList();
- }
-
- QCameraFocusZoneList list;
- for (int i = 0; i < asked; ++i) {
- const int x = regions[i].left;
- const int y = regions[i].top;
- const int width = regions[i].width;
- const int height = regions[i].height;
-
- QRectF rect(static_cast<float>(x)/static_cast<float>(viewfinderWidth),
- static_cast<float>(y)/static_cast<float>(viewfinderHeight),
- static_cast<float>(width)/static_cast<float>(viewfinderWidth),
- static_cast<float>(height)/static_cast<float>(viewfinderHeight));
-
- list << QCameraFocusZone(rect, QCameraFocusZone::Focused); //TODO: how to know if a zone is unused/selected/focused?!?
- }
-
- return list;
-}
-
-void BbCameraFocusControl::updateCustomFocusRegion()
-{
- // get the size of the viewfinder
- int viewfinderWidth = 0;
- int viewfinderHeight = 0;
-
- if (!retrieveViewfinderSize(&viewfinderWidth, &viewfinderHeight))
- return;
-
- // define a 40x40 pixel focus region around the custom focus point
- camera_region_t focusRegion;
- focusRegion.left = qMax(0, static_cast<int>(m_customFocusPoint.x() * viewfinderWidth) - 20);
- focusRegion.top = qMax(0, static_cast<int>(m_customFocusPoint.y() * viewfinderHeight) - 20);
- focusRegion.width = 40;
- focusRegion.height = 40;
-
- camera_error_t result = camera_set_focus_regions(m_session->handle(), 1, &focusRegion);
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to set focus region:" << result;
- return;
- }
-
- // re-set focus mode to apply focus region changes
- camera_focusmode_t focusMode = CAMERA_FOCUSMODE_OFF;
- result = camera_get_focus_mode(m_session->handle(), &focusMode);
- camera_set_focus_mode(m_session->handle(), focusMode);
-
- emit focusZonesChanged();
-}
-
-bool BbCameraFocusControl::retrieveViewfinderSize(int *width, int *height)
-{
- if (!width || !height)
- return false;
-
- camera_error_t result = CAMERA_EOK;
- if (m_session->captureMode() & QCamera::CaptureStillImage)
- result = camera_get_photovf_property(m_session->handle(),
- CAMERA_IMGPROP_WIDTH, width,
- CAMERA_IMGPROP_HEIGHT, height);
- else if (m_session->captureMode() & QCamera::CaptureVideo)
- result = camera_get_videovf_property(m_session->handle(),
- CAMERA_IMGPROP_WIDTH, width,
- CAMERA_IMGPROP_HEIGHT, height);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve viewfinder size:" << result;
- return false;
- }
-
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcamerafocuscontrol.h b/src/plugins/qnx/camera/bbcamerafocuscontrol.h
deleted file mode 100644
index bf11ea03e..000000000
--- a/src/plugins/qnx/camera/bbcamerafocuscontrol.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERAFOCUSCONTROL_H
-#define BBCAMERAFOCUSCONTROL_H
-
-#include <qcamerafocuscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraFocusControl : public QCameraFocusControl
-{
- Q_OBJECT
-public:
- explicit BbCameraFocusControl(BbCameraSession *session, QObject *parent = 0);
-
- QCameraFocus::FocusModes focusMode() const override;
- void setFocusMode(QCameraFocus::FocusModes mode) override;
- bool isFocusModeSupported(QCameraFocus::FocusModes mode) const override;
- QCameraFocus::FocusPointMode focusPointMode() const override;
- void setFocusPointMode(QCameraFocus::FocusPointMode mode) override;
- bool isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const override;
- QPointF customFocusPoint() const override;
- void setCustomFocusPoint(const QPointF &point) override;
- QCameraFocusZoneList focusZones() const override;
-
-private:
- void updateCustomFocusRegion();
- bool retrieveViewfinderSize(int *width, int *height);
-
- BbCameraSession *m_session;
-
- QCameraFocus::FocusModes m_focusMode;
- QCameraFocus::FocusPointMode m_focusPointMode;
- QPointF m_customFocusPoint;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameraimagecapturecontrol.cpp b/src/plugins/qnx/camera/bbcameraimagecapturecontrol.cpp
deleted file mode 100644
index 2fcd2baed..000000000
--- a/src/plugins/qnx/camera/bbcameraimagecapturecontrol.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameraimagecapturecontrol.h"
-
-#include "bbcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-BbCameraImageCaptureControl::BbCameraImageCaptureControl(BbCameraSession *session, QObject *parent)
- : QCameraImageCaptureControl(parent)
- , m_session(session)
-{
- connect(m_session, SIGNAL(readyForCaptureChanged(bool)), this, SIGNAL(readyForCaptureChanged(bool)));
- connect(m_session, SIGNAL(imageExposed(int)), this, SIGNAL(imageExposed(int)));
- connect(m_session, SIGNAL(imageCaptured(int,QImage)), this, SIGNAL(imageCaptured(int,QImage)));
- connect(m_session, SIGNAL(imageMetadataAvailable(int,QString,QVariant)), this, SIGNAL(imageMetadataAvailable(int,QString,QVariant)));
- connect(m_session, SIGNAL(imageAvailable(int,QVideoFrame)), this, SIGNAL(imageAvailable(int,QVideoFrame)));
- connect(m_session, SIGNAL(imageSaved(int,QString)), this, SIGNAL(imageSaved(int,QString)));
- connect(m_session, SIGNAL(imageCaptureError(int,int,QString)), this, SIGNAL(error(int,int,QString)));
-}
-
-bool BbCameraImageCaptureControl::isReadyForCapture() const
-{
- return m_session->isReadyForCapture();
-}
-
-QCameraImageCapture::DriveMode BbCameraImageCaptureControl::driveMode() const
-{
- return m_session->driveMode();
-}
-
-void BbCameraImageCaptureControl::setDriveMode(QCameraImageCapture::DriveMode mode)
-{
- m_session->setDriveMode(mode);
-}
-
-int BbCameraImageCaptureControl::capture(const QString &fileName)
-{
- return m_session->capture(fileName);
-}
-
-void BbCameraImageCaptureControl::cancelCapture()
-{
- m_session->cancelCapture();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameraimagecapturecontrol.h b/src/plugins/qnx/camera/bbcameraimagecapturecontrol.h
deleted file mode 100644
index b8013ba1f..000000000
--- a/src/plugins/qnx/camera/bbcameraimagecapturecontrol.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERAIMAGECAPTURECONTROL_H
-#define BBCAMERAIMAGECAPTURECONTROL_H
-
-#include <qcameraimagecapturecontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraImageCaptureControl : public QCameraImageCaptureControl
-{
- Q_OBJECT
-public:
- explicit BbCameraImageCaptureControl(BbCameraSession *session, QObject *parent = 0);
-
- bool isReadyForCapture() const override;
-
- QCameraImageCapture::DriveMode driveMode() const override;
- void setDriveMode(QCameraImageCapture::DriveMode mode) override;
-
- int capture(const QString &fileName) override;
- void cancelCapture() override;
-
-private:
- BbCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameraimageprocessingcontrol.cpp b/src/plugins/qnx/camera/bbcameraimageprocessingcontrol.cpp
deleted file mode 100644
index 250a85ca0..000000000
--- a/src/plugins/qnx/camera/bbcameraimageprocessingcontrol.cpp
+++ /dev/null
@@ -1,144 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameraimageprocessingcontrol.h"
-
-#include "bbcamerasession.h"
-
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-BbCameraImageProcessingControl::BbCameraImageProcessingControl(BbCameraSession *session, QObject *parent)
- : QCameraImageProcessingControl(parent)
- , m_session(session)
-{
-}
-
-bool BbCameraImageProcessingControl::isParameterSupported(ProcessingParameter parameter) const
-{
- return (parameter == QCameraImageProcessingControl::WhiteBalancePreset);
-}
-
-bool BbCameraImageProcessingControl::isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const
-{
- if (parameter != QCameraImageProcessingControl::WhiteBalancePreset)
- return false;
-
- if (m_session->handle() == CAMERA_HANDLE_INVALID)
- return false;
-
- int supported = 0;
- camera_whitebalancemode_t modes[20];
- const camera_error_t result = camera_get_whitebalance_modes(m_session->handle(), 20, &supported, modes);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve supported whitebalance modes:" << result;
- return false;
- }
-
- QSet<QCameraImageProcessing::WhiteBalanceMode> supportedModes;
- for (int i = 0; i < supported; ++i) {
- switch (modes[i]) {
- case CAMERA_WHITEBALANCEMODE_AUTO:
- supportedModes.insert(QCameraImageProcessing::WhiteBalanceAuto);
- break;
- case CAMERA_WHITEBALANCEMODE_MANUAL:
- supportedModes.insert(QCameraImageProcessing::WhiteBalanceManual);
- break;
- default:
- break;
- }
- }
-
- return supportedModes.contains(value.value<QCameraImageProcessing::WhiteBalanceMode>());
-}
-
-QVariant BbCameraImageProcessingControl::parameter(ProcessingParameter parameter) const
-{
- if (parameter != QCameraImageProcessingControl::WhiteBalancePreset)
- return QVariant();
-
- if (m_session->handle() == CAMERA_HANDLE_INVALID)
- return QVariant();
-
- camera_whitebalancemode_t mode;
- const camera_error_t result = camera_get_whitebalance_mode(m_session->handle(), &mode);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve current whitebalance mode:" << result;
- return QVariant();
- }
-
- switch (mode) {
- case CAMERA_WHITEBALANCEMODE_AUTO:
- return QVariant::fromValue(QCameraImageProcessing::WhiteBalanceAuto);
- case CAMERA_WHITEBALANCEMODE_MANUAL:
- return QVariant::fromValue(QCameraImageProcessing::WhiteBalanceManual);
- default:
- return QVariant();
- }
-}
-
-void BbCameraImageProcessingControl::setParameter(ProcessingParameter parameter, const QVariant &value)
-{
- if (parameter != QCameraImageProcessingControl::WhiteBalancePreset)
- return;
-
- if (m_session->handle() == CAMERA_HANDLE_INVALID)
- return;
-
- camera_whitebalancemode_t mode = CAMERA_WHITEBALANCEMODE_DEFAULT;
- switch (value.value<QCameraImageProcessing::WhiteBalanceMode>()) {
- case QCameraImageProcessing::WhiteBalanceAuto:
- mode = CAMERA_WHITEBALANCEMODE_AUTO;
- break;
- case QCameraImageProcessing::WhiteBalanceManual:
- mode = CAMERA_WHITEBALANCEMODE_MANUAL;
- break;
- default:
- break;
- }
-
- const camera_error_t result = camera_set_whitebalance_mode(m_session->handle(), mode);
-
- if (result != CAMERA_EOK)
- qWarning() << "Unable to set whitebalance mode:" << result;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameraimageprocessingcontrol.h b/src/plugins/qnx/camera/bbcameraimageprocessingcontrol.h
deleted file mode 100644
index 0eefdd2a1..000000000
--- a/src/plugins/qnx/camera/bbcameraimageprocessingcontrol.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERAIMAGEPROCESSINGCONTROL_H
-#define BBCAMERAIMAGEPROCESSINGCONTROL_H
-
-#include <qcameraimageprocessingcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraImageProcessingControl : public QCameraImageProcessingControl
-{
- Q_OBJECT
-public:
- explicit BbCameraImageProcessingControl(BbCameraSession *session, QObject *parent = 0);
-
- bool isParameterSupported(ProcessingParameter) const override;
- bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const override;
- QVariant parameter(ProcessingParameter parameter) const override;
- void setParameter(ProcessingParameter parameter, const QVariant &value) override;
-
-private:
- BbCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcamerainfocontrol.cpp b/src/plugins/qnx/camera/bbcamerainfocontrol.cpp
deleted file mode 100644
index 3d0481408..000000000
--- a/src/plugins/qnx/camera/bbcamerainfocontrol.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "bbcamerainfocontrol.h"
-
-#include "bbcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-BbCameraInfoControl::BbCameraInfoControl(QObject *parent)
- : QCameraInfoControl(parent)
-{
-}
-
-QCamera::Position BbCameraInfoControl::position(const QString &deviceName)
-{
- if (deviceName == QString::fromUtf8(BbCameraSession::cameraIdentifierFront()))
- return QCamera::FrontFace;
- else if (deviceName == QString::fromUtf8(BbCameraSession::cameraIdentifierRear()))
- return QCamera::BackFace;
- else
- return QCamera::UnspecifiedPosition;
-}
-
-int BbCameraInfoControl::orientation(const QString &deviceName)
-{
- // The camera sensor orientation could be retrieved with camera_get_native_orientation()
- // but since the sensor angular offset is compensated with camera_set_videovf_property() and
- // camera_set_photovf_property() we should always return 0 here.
- Q_UNUSED(deviceName);
- return 0;
-}
-
-QCamera::Position BbCameraInfoControl::cameraPosition(const QString &deviceName) const
-{
- return position(deviceName);
-}
-
-int BbCameraInfoControl::cameraOrientation(const QString &deviceName) const
-{
- return orientation(deviceName);
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/plugins/qnx/camera/bbcamerainfocontrol.h b/src/plugins/qnx/camera/bbcamerainfocontrol.h
deleted file mode 100644
index 1c51410f7..000000000
--- a/src/plugins/qnx/camera/bbcamerainfocontrol.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef BBCAMERAINFOCONTROL_H
-#define BBCAMERAINFOCONTROL_H
-
-#include <qcamerainfocontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraInfoControl : public QCameraInfoControl
-{
- Q_OBJECT
-public:
- explicit BbCameraInfoControl(QObject *parent = 0);
-
- QCamera::Position cameraPosition(const QString &deviceName) const;
- int cameraOrientation(const QString &deviceName) const;
-
- static QCamera::Position position(const QString &deviceName);
- static int orientation(const QString &deviceName);
-};
-
-QT_END_NAMESPACE
-
-#endif // BBCAMERAINFOCONTROL_H
-
diff --git a/src/plugins/qnx/camera/bbcameralockscontrol.cpp b/src/plugins/qnx/camera/bbcameralockscontrol.cpp
deleted file mode 100644
index 5802064e6..000000000
--- a/src/plugins/qnx/camera/bbcameralockscontrol.cpp
+++ /dev/null
@@ -1,256 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameralockscontrol.h"
-
-#include "bbcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-BbCameraLocksControl::BbCameraLocksControl(BbCameraSession *session, QObject *parent)
- : QCameraLocksControl(parent)
- , m_session(session)
- , m_locksApplyMode(IndependentMode)
- , m_focusLockStatus(QCamera::Unlocked)
- , m_exposureLockStatus(QCamera::Unlocked)
- , m_whiteBalanceLockStatus(QCamera::Unlocked)
- , m_currentLockTypes(QCamera::NoLock)
- , m_supportedLockTypes(QCamera::NoLock)
-{
- connect(m_session, SIGNAL(cameraOpened()), SLOT(cameraOpened()));
- connect(m_session, SIGNAL(focusStatusChanged(int)), SLOT(focusStatusChanged(int)));
-}
-
-QCamera::LockTypes BbCameraLocksControl::supportedLocks() const
-{
- return (QCamera::LockFocus | QCamera::LockExposure | QCamera::LockWhiteBalance);
-}
-
-QCamera::LockStatus BbCameraLocksControl::lockStatus(QCamera::LockType lock) const
-{
- if (!m_supportedLockTypes.testFlag(lock) || (m_session->handle() == CAMERA_HANDLE_INVALID))
- return QCamera::Locked;
-
- switch (lock) {
- case QCamera::LockExposure:
- return m_exposureLockStatus;
- case QCamera::LockWhiteBalance:
- return m_whiteBalanceLockStatus;
- case QCamera::LockFocus:
- return m_focusLockStatus;
- default:
- return QCamera::Locked;
- }
-}
-
-void BbCameraLocksControl::searchAndLock(QCamera::LockTypes locks)
-{
- if (m_session->handle() == CAMERA_HANDLE_INVALID)
- return;
-
- // filter out unsupported locks
- locks &= m_supportedLockTypes;
-
- m_currentLockTypes |= locks;
-
- uint32_t lockModes = CAMERA_3A_NONE;
-
- switch (m_locksApplyMode) {
- case IndependentMode:
- if (m_currentLockTypes & QCamera::LockExposure)
- lockModes |= CAMERA_3A_AUTOEXPOSURE;
- if (m_currentLockTypes & QCamera::LockWhiteBalance)
- lockModes |= CAMERA_3A_AUTOWHITEBALANCE;
- if (m_currentLockTypes & QCamera::LockFocus)
- lockModes |= CAMERA_3A_AUTOFOCUS;
- break;
- case FocusExposureBoundMode:
- if ((m_currentLockTypes & QCamera::LockExposure) || (m_currentLockTypes & QCamera::LockFocus))
- lockModes = (CAMERA_3A_AUTOEXPOSURE | CAMERA_3A_AUTOFOCUS);
- break;
- case AllBoundMode:
- lockModes = (CAMERA_3A_AUTOEXPOSURE | CAMERA_3A_AUTOFOCUS | CAMERA_3A_AUTOWHITEBALANCE);
- break;
- case FocusOnlyMode:
- lockModes = CAMERA_3A_AUTOFOCUS;
- break;
- }
-
- const camera_error_t result = camera_set_3a_lock(m_session->handle(), lockModes);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to set lock modes:" << result;
- } else {
- if (lockModes & CAMERA_3A_AUTOFOCUS) {
- // handled by focusStatusChanged()
- }
-
- if (lockModes & CAMERA_3A_AUTOEXPOSURE) {
- m_exposureLockStatus = QCamera::Locked;
- emit lockStatusChanged(QCamera::LockExposure, QCamera::Locked, QCamera::LockAcquired);
- }
-
- if (lockModes & CAMERA_3A_AUTOWHITEBALANCE) {
- m_whiteBalanceLockStatus = QCamera::Locked;
- emit lockStatusChanged(QCamera::LockWhiteBalance, QCamera::Locked, QCamera::LockAcquired);
- }
- }
-}
-
-void BbCameraLocksControl::unlock(QCamera::LockTypes locks)
-{
- // filter out unsupported locks
- locks &= m_supportedLockTypes;
-
- m_currentLockTypes &= ~locks;
-
- uint32_t lockModes = CAMERA_3A_NONE;
-
- switch (m_locksApplyMode) {
- case IndependentMode:
- if (m_currentLockTypes & QCamera::LockExposure)
- lockModes |= CAMERA_3A_AUTOEXPOSURE;
- if (m_currentLockTypes & QCamera::LockWhiteBalance)
- lockModes |= CAMERA_3A_AUTOWHITEBALANCE;
- if (m_currentLockTypes & QCamera::LockFocus)
- lockModes |= CAMERA_3A_AUTOFOCUS;
- break;
- case FocusExposureBoundMode:
- if ((m_currentLockTypes & QCamera::LockExposure) || (m_currentLockTypes & QCamera::LockFocus))
- lockModes = (CAMERA_3A_AUTOEXPOSURE | CAMERA_3A_AUTOFOCUS);
- break;
- case AllBoundMode:
- lockModes = (CAMERA_3A_AUTOEXPOSURE | CAMERA_3A_AUTOFOCUS | CAMERA_3A_AUTOWHITEBALANCE);
- break;
- case FocusOnlyMode:
- lockModes = CAMERA_3A_AUTOFOCUS;
- break;
- }
-
- const camera_error_t result = camera_set_3a_lock(m_session->handle(), lockModes);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to set lock modes:" << result;
- } else {
- if (locks.testFlag(QCamera::LockFocus)) {
- // handled by focusStatusChanged()
- }
-
- if (locks.testFlag(QCamera::LockExposure)) {
- m_exposureLockStatus = QCamera::Unlocked;
- emit lockStatusChanged(QCamera::LockExposure, QCamera::Unlocked, QCamera::UserRequest);
- }
-
- if (locks.testFlag(QCamera::LockWhiteBalance)) {
- m_whiteBalanceLockStatus = QCamera::Unlocked;
- emit lockStatusChanged(QCamera::LockWhiteBalance, QCamera::Unlocked, QCamera::UserRequest);
- }
- }
-}
-
-void BbCameraLocksControl::cameraOpened()
-{
- // retrieve information about lock apply modes
- int supported = 0;
- uint32_t modes[20];
-
- const camera_error_t result = camera_get_3a_lock_modes(m_session->handle(), 20, &supported, modes);
-
- if (result == CAMERA_EOK) {
- // see API documentation of camera_get_3a_lock_modes for explanation of case discrimination below
- if (supported == 4) {
- m_locksApplyMode = IndependentMode;
- } else if (supported == 3) {
- m_locksApplyMode = FocusExposureBoundMode;
- } else if (supported == 2) {
- if (modes[0] == (CAMERA_3A_AUTOFOCUS | CAMERA_3A_AUTOEXPOSURE | CAMERA_3A_AUTOWHITEBALANCE))
- m_locksApplyMode = AllBoundMode;
- else
- m_locksApplyMode = FocusOnlyMode;
- }
- }
-
- // retrieve information about supported lock types
- m_supportedLockTypes = QCamera::NoLock;
-
- if (camera_has_feature(m_session->handle(), CAMERA_FEATURE_AUTOFOCUS))
- m_supportedLockTypes |= QCamera::LockFocus;
-
- if (camera_has_feature(m_session->handle(), CAMERA_FEATURE_AUTOEXPOSURE))
- m_supportedLockTypes |= QCamera::LockExposure;
-
- if (camera_has_feature(m_session->handle(), CAMERA_FEATURE_AUTOWHITEBALANCE))
- m_supportedLockTypes |= QCamera::LockWhiteBalance;
-
- m_focusLockStatus = QCamera::Unlocked;
- m_exposureLockStatus = QCamera::Unlocked;
- m_whiteBalanceLockStatus = QCamera::Unlocked;
-}
-
-void BbCameraLocksControl::focusStatusChanged(int value)
-{
- const camera_focusstate_t focusState = static_cast<camera_focusstate_t>(value);
-
- switch (focusState) {
- case CAMERA_FOCUSSTATE_NONE:
- m_focusLockStatus = QCamera::Unlocked;
- emit lockStatusChanged(QCamera::LockFocus, QCamera::Unlocked, QCamera::UserRequest);
- break;
- case CAMERA_FOCUSSTATE_WAITING:
- case CAMERA_FOCUSSTATE_SEARCHING:
- m_focusLockStatus = QCamera::Searching;
- emit lockStatusChanged(QCamera::LockFocus, QCamera::Searching, QCamera::UserRequest);
- break;
- case CAMERA_FOCUSSTATE_FAILED:
- m_focusLockStatus = QCamera::Unlocked;
- emit lockStatusChanged(QCamera::LockFocus, QCamera::Unlocked, QCamera::LockFailed);
- break;
- case CAMERA_FOCUSSTATE_LOCKED:
- m_focusLockStatus = QCamera::Locked;
- emit lockStatusChanged(QCamera::LockFocus, QCamera::Locked, QCamera::LockAcquired);
- break;
- case CAMERA_FOCUSSTATE_SCENECHANGE:
- m_focusLockStatus = QCamera::Unlocked;
- emit lockStatusChanged(QCamera::LockFocus, QCamera::Unlocked, QCamera::LockTemporaryLost);
- break;
- default:
- break;
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameralockscontrol.h b/src/plugins/qnx/camera/bbcameralockscontrol.h
deleted file mode 100644
index be3d1bd02..000000000
--- a/src/plugins/qnx/camera/bbcameralockscontrol.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERALOCKSCONTROL_H
-#define BBCAMERALOCKSCONTROL_H
-
-#include <qcameralockscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraLocksControl : public QCameraLocksControl
-{
- Q_OBJECT
-public:
- enum LocksApplyMode
- {
- IndependentMode,
- FocusExposureBoundMode,
- AllBoundMode,
- FocusOnlyMode
- };
-
- explicit BbCameraLocksControl(BbCameraSession *session, QObject *parent = 0);
-
- QCamera::LockTypes supportedLocks() const override;
- QCamera::LockStatus lockStatus(QCamera::LockType lock) const override;
- void searchAndLock(QCamera::LockTypes locks) override;
- void unlock(QCamera::LockTypes locks) override;
-
-private Q_SLOTS:
- void cameraOpened();
- void focusStatusChanged(int value);
-
-private:
- BbCameraSession *m_session;
-
- LocksApplyMode m_locksApplyMode;
- QCamera::LockStatus m_focusLockStatus;
- QCamera::LockStatus m_exposureLockStatus;
- QCamera::LockStatus m_whiteBalanceLockStatus;
- QCamera::LockTypes m_currentLockTypes;
- QCamera::LockTypes m_supportedLockTypes;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameramediarecordercontrol.cpp b/src/plugins/qnx/camera/bbcameramediarecordercontrol.cpp
deleted file mode 100644
index 3cb9ed38d..000000000
--- a/src/plugins/qnx/camera/bbcameramediarecordercontrol.cpp
+++ /dev/null
@@ -1,156 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameramediarecordercontrol.h"
-
-#include "bbcamerasession.h"
-
-#include <QDebug>
-#include <QUrl>
-
-#include <audio/audio_manager_device.h>
-#include <audio/audio_manager_volume.h>
-
-QT_BEGIN_NAMESPACE
-
-static audio_manager_device_t currentAudioInputDevice()
-{
- audio_manager_device_t device = AUDIO_DEVICE_HEADSET;
-
- const int result = audio_manager_get_default_input_device(&device);
- if (result != EOK) {
- qWarning() << "Unable to retrieve default audio input device:" << result;
- return AUDIO_DEVICE_HEADSET;
- }
-
- return device;
-}
-
-BbCameraMediaRecorderControl::BbCameraMediaRecorderControl(BbCameraSession *session, QObject *parent)
- : QMediaRecorderControl(parent)
- , m_session(session)
-{
- connect(m_session, SIGNAL(videoStateChanged(QMediaRecorder::State)), this, SIGNAL(stateChanged(QMediaRecorder::State)));
- connect(m_session, SIGNAL(videoStatusChanged(QMediaRecorder::Status)), this, SIGNAL(statusChanged(QMediaRecorder::Status)));
- connect(m_session, SIGNAL(durationChanged(qint64)), this, SIGNAL(durationChanged(qint64)));
- connect(m_session, SIGNAL(actualLocationChanged(QUrl)), this, SIGNAL(actualLocationChanged(QUrl)));
- connect(m_session, SIGNAL(videoError(int,QString)), this, SIGNAL(error(int,QString)));
-}
-
-QUrl BbCameraMediaRecorderControl::outputLocation() const
-{
- return m_session->outputLocation();
-}
-
-bool BbCameraMediaRecorderControl::setOutputLocation(const QUrl &location)
-{
- return m_session->setOutputLocation(location);
-}
-
-QMediaRecorder::State BbCameraMediaRecorderControl::state() const
-{
- return m_session->videoState();
-}
-
-QMediaRecorder::Status BbCameraMediaRecorderControl::status() const
-{
- return m_session->videoStatus();
-}
-
-qint64 BbCameraMediaRecorderControl::duration() const
-{
- return m_session->duration();
-}
-
-bool BbCameraMediaRecorderControl::isMuted() const
-{
- bool muted = false;
-
- const int result = audio_manager_get_input_mute(currentAudioInputDevice(), &muted);
- if (result != EOK) {
- emit const_cast<BbCameraMediaRecorderControl*>(this)->error(QMediaRecorder::ResourceError, tr("Unable to retrieve mute status"));
- return false;
- }
-
- return muted;
-}
-
-qreal BbCameraMediaRecorderControl::volume() const
-{
- double level = 0.0;
-
- const int result = audio_manager_get_input_level(currentAudioInputDevice(), &level);
- if (result != EOK) {
- emit const_cast<BbCameraMediaRecorderControl*>(this)->error(QMediaRecorder::ResourceError, tr("Unable to retrieve audio input volume"));
- return 0.0;
- }
-
- return (level / 100);
-}
-
-void BbCameraMediaRecorderControl::applySettings()
-{
- m_session->applyVideoSettings();
-}
-
-void BbCameraMediaRecorderControl::setState(QMediaRecorder::State state)
-{
- m_session->setVideoState(state);
-}
-
-void BbCameraMediaRecorderControl::setMuted(bool muted)
-{
- const int result = audio_manager_set_input_mute(currentAudioInputDevice(), muted);
- if (result != EOK) {
- emit error(QMediaRecorder::ResourceError, tr("Unable to set mute status"));
- } else {
- emit mutedChanged(muted);
- }
-}
-
-void BbCameraMediaRecorderControl::setVolume(qreal volume)
-{
- const int result = audio_manager_set_input_level(currentAudioInputDevice(), (volume * 100));
- if (result != EOK) {
- emit error(QMediaRecorder::ResourceError, tr("Unable to set audio input volume"));
- } else {
- emit volumeChanged(volume);
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameramediarecordercontrol.h b/src/plugins/qnx/camera/bbcameramediarecordercontrol.h
deleted file mode 100644
index af46479a5..000000000
--- a/src/plugins/qnx/camera/bbcameramediarecordercontrol.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERAMEDIARECORDERCONTROL_H
-#define BBCAMERAMEDIARECORDERCONTROL_H
-
-#include <qmediarecordercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraMediaRecorderControl : public QMediaRecorderControl
-{
- Q_OBJECT
-public:
- explicit BbCameraMediaRecorderControl(BbCameraSession *session, QObject *parent = 0);
-
- QUrl outputLocation() const override;
- bool setOutputLocation(const QUrl &location) override;
- QMediaRecorder::State state() const override;
- QMediaRecorder::Status status() const override;
- qint64 duration() const override;
- bool isMuted() const override;
- qreal volume() const override;
- void applySettings() override;
-
-public Q_SLOTS:
- void setState(QMediaRecorder::State state) override;
- void setMuted(bool muted) override;
- void setVolume(qreal volume) override;
-
-private:
- BbCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameraorientationhandler.cpp b/src/plugins/qnx/camera/bbcameraorientationhandler.cpp
deleted file mode 100644
index d600f3db0..000000000
--- a/src/plugins/qnx/camera/bbcameraorientationhandler.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameraorientationhandler.h"
-
-#include <QAbstractEventDispatcher>
-#include <QGuiApplication>
-#include <QScreen>
-#include <QDebug>
-
-#include <bps/orientation.h>
-
-QT_BEGIN_NAMESPACE
-
-BbCameraOrientationHandler::BbCameraOrientationHandler(QObject *parent)
- : QObject(parent)
- , m_orientation(0)
-{
- QCoreApplication::eventDispatcher()->installNativeEventFilter(this);
- int result = orientation_request_events(0);
- if (result == BPS_FAILURE)
- qWarning() << "Unable to register for orientation change events";
-
- orientation_direction_t direction = ORIENTATION_FACE_UP;
- int angle = 0;
-
- result = orientation_get(&direction, &angle);
- if (result == BPS_FAILURE) {
- qWarning() << "Unable to retrieve initial orientation";
- } else {
- m_orientation = angle;
- }
-}
-
-BbCameraOrientationHandler::~BbCameraOrientationHandler()
-{
- const int result = orientation_stop_events(0);
- if (result == BPS_FAILURE)
- qWarning() << "Unable to unregister for orientation change events";
-
- QCoreApplication::eventDispatcher()->removeNativeEventFilter(this);
-}
-
-bool BbCameraOrientationHandler::nativeEventFilter(const QByteArray&, void *message, qintptr *)
-{
- bps_event_t* const event = static_cast<bps_event_t*>(message);
- if (!event || bps_event_get_domain(event) != orientation_get_domain())
- return false;
-
- const int angle = orientation_event_get_angle(event);
- if (angle != m_orientation) {
- if (angle == 180) // The screen does not rotate at 180 degrees
- return false;
-
- m_orientation = angle;
- emit orientationChanged(m_orientation);
- }
-
- return false; // do not drop the event
-}
-
-int BbCameraOrientationHandler::viewfinderOrientation() const
-{
- // On a keyboard device we do not rotate the screen at all
- if (qGuiApp->primaryScreen()->nativeOrientation()
- != qGuiApp->primaryScreen()->primaryOrientation()) {
- return m_orientation;
- }
-
- return 0;
-}
-
-int BbCameraOrientationHandler::orientation() const
-{
- return m_orientation;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameraorientationhandler.h b/src/plugins/qnx/camera/bbcameraorientationhandler.h
deleted file mode 100644
index af80bd4e1..000000000
--- a/src/plugins/qnx/camera/bbcameraorientationhandler.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERAORIENTATIONHANDLER_H
-#define BBCAMERAORIENTATIONHANDLER_H
-
-#include <QAbstractNativeEventFilter>
-#include <QObject>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraOrientationHandler : public QObject, public QAbstractNativeEventFilter
-{
- Q_OBJECT
-public:
- explicit BbCameraOrientationHandler(QObject *parent = 0);
- ~BbCameraOrientationHandler();
-
- bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
-
- int orientation() const;
-
- int viewfinderOrientation() const;
-
-Q_SIGNALS:
- void orientationChanged(int degree);
-
-private:
- int m_orientation;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameraservice.cpp b/src/plugins/qnx/camera/bbcameraservice.cpp
deleted file mode 100644
index 2879f6981..000000000
--- a/src/plugins/qnx/camera/bbcameraservice.cpp
+++ /dev/null
@@ -1,143 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameraservice.h"
-
-#include "bbcameraaudioencodersettingscontrol.h"
-#include "bbcameracapturebufferformatcontrol.h"
-#include "bbcameracapturedestinationcontrol.h"
-#include "bbcameracontrol.h"
-#include "bbcameraexposurecontrol.h"
-#include "bbcameraflashcontrol.h"
-#include "bbcamerafocuscontrol.h"
-#include "bbcameraimagecapturecontrol.h"
-#include "bbcameraimageprocessingcontrol.h"
-#include "bbcamerainfocontrol.h"
-#include "bbcameralockscontrol.h"
-#include "bbcameramediarecordercontrol.h"
-#include "bbcamerasession.h"
-#include "bbcameravideoencodersettingscontrol.h"
-#include "bbcameraviewfindersettingscontrol.h"
-#include "bbcamerazoomcontrol.h"
-#include "bbimageencodercontrol.h"
-#include "bbvideodeviceselectorcontrol.h"
-#include "bbvideorenderercontrol.h"
-
-#include <QDebug>
-#include <QVariant>
-
-QT_BEGIN_NAMESPACE
-
-BbCameraService::BbCameraService(QObject *parent)
- : QMediaService(parent)
- , m_cameraSession(new BbCameraSession(this))
- , m_cameraAudioEncoderSettingsControl(new BbCameraAudioEncoderSettingsControl(m_cameraSession, this))
- , m_cameraCaptureBufferFormatControl(new BbCameraCaptureBufferFormatControl(this))
- , m_cameraCaptureDestinationControl(new BbCameraCaptureDestinationControl(m_cameraSession, this))
- , m_cameraControl(new BbCameraControl(m_cameraSession, this))
- , m_cameraExposureControl(new BbCameraExposureControl(m_cameraSession, this))
- , m_cameraFlashControl(new BbCameraFlashControl(m_cameraSession, this))
- , m_cameraFocusControl(new BbCameraFocusControl(m_cameraSession, this))
- , m_cameraImageCaptureControl(new BbCameraImageCaptureControl(m_cameraSession, this))
- , m_cameraImageProcessingControl(new BbCameraImageProcessingControl(m_cameraSession, this))
- , m_cameraInfoControl(new BbCameraInfoControl(this))
- , m_cameraLocksControl(new BbCameraLocksControl(m_cameraSession, this))
- , m_cameraMediaRecorderControl(new BbCameraMediaRecorderControl(m_cameraSession, this))
- , m_cameraVideoEncoderSettingsControl(new BbCameraVideoEncoderSettingsControl(m_cameraSession, this))
- , m_cameraViewfinderSettingsControl(new BbCameraViewfinderSettingsControl(m_cameraSession, this))
- , m_cameraZoomControl(new BbCameraZoomControl(m_cameraSession, this))
- , m_imageEncoderControl(new BbImageEncoderControl(m_cameraSession, this))
- , m_videoDeviceSelectorControl(new BbVideoDeviceSelectorControl(m_cameraSession, this))
- , m_videoRendererControl(new BbVideoRendererControl(m_cameraSession, this))
-{
-}
-
-BbCameraService::~BbCameraService()
-{
-}
-
-QMediaControl* BbCameraService::requestControl(const char *name)
-{
- if (qstrcmp(name, QAudioEncoderSettingsControl_iid) == 0)
- return m_cameraAudioEncoderSettingsControl;
- else if (qstrcmp(name, QCameraCaptureBufferFormatControl_iid) == 0)
- return m_cameraCaptureBufferFormatControl;
- else if (qstrcmp(name, QCameraCaptureDestinationControl_iid) == 0)
- return m_cameraCaptureDestinationControl;
- else if (qstrcmp(name, QCameraControl_iid) == 0)
- return m_cameraControl;
- else if (qstrcmp(name, QCameraInfoControl_iid) == 0)
- return m_cameraInfoControl;
- else if (qstrcmp(name, QCameraExposureControl_iid) == 0)
- return m_cameraExposureControl;
- else if (qstrcmp(name, QCameraFlashControl_iid) == 0)
- return m_cameraFlashControl;
- else if (qstrcmp(name, QCameraFocusControl_iid) == 0)
- return m_cameraFocusControl;
- else if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0)
- return m_cameraImageCaptureControl;
- else if (qstrcmp(name, QCameraImageProcessingControl_iid) == 0)
- return m_cameraImageProcessingControl;
- else if (qstrcmp(name, QCameraLocksControl_iid) == 0)
- return m_cameraLocksControl;
- else if (qstrcmp(name, QMediaRecorderControl_iid) == 0)
- return m_cameraMediaRecorderControl;
- else if (qstrcmp(name, QVideoEncoderSettingsControl_iid) == 0)
- return m_cameraVideoEncoderSettingsControl;
- else if (qstrcmp(name, QCameraViewfinderSettingsControl_iid) == 0)
- return m_cameraViewfinderSettingsControl;
- else if (qstrcmp(name, QCameraZoomControl_iid) == 0)
- return m_cameraZoomControl;
- else if (qstrcmp(name, QImageEncoderControl_iid) == 0)
- return m_imageEncoderControl;
- else if (qstrcmp(name, QVideoDeviceSelectorControl_iid) == 0)
- return m_videoDeviceSelectorControl;
- else if (qstrcmp(name, QVideoRendererControl_iid) == 0)
- return m_videoRendererControl;
-
- return 0;
-}
-
-void BbCameraService::releaseControl(QMediaControl *control)
-{
- Q_UNUSED(control);
-
- // Implemented as a singleton, so we do nothing.
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameraservice.h b/src/plugins/qnx/camera/bbcameraservice.h
deleted file mode 100644
index b13da6a4a..000000000
--- a/src/plugins/qnx/camera/bbcameraservice.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERASERVICE_H
-#define BBCAMERASERVICE_H
-
-#include <QObject>
-
-#include <qmediaservice.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraAudioEncoderSettingsControl;
-class BbCameraCaptureBufferFormatControl;
-class BbCameraCaptureDestinationControl;
-class BbCameraControl;
-class BbCameraExposureControl;
-class BbCameraFlashControl;
-class BbCameraFocusControl;
-class BbCameraImageCaptureControl;
-class BbCameraImageProcessingControl;
-class BbCameraInfoControl;
-class BbCameraLocksControl;
-class BbCameraMediaRecorderControl;
-class BbCameraSession;
-class BbCameraVideoEncoderSettingsControl;
-class BbCameraViewfinderSettingsControl;
-class BbCameraZoomControl;
-class BbImageEncoderControl;
-class BbVideoDeviceSelectorControl;
-class BbVideoRendererControl;
-
-class BbCameraService : public QMediaService
-{
- Q_OBJECT
-
-public:
- explicit BbCameraService(QObject *parent = 0);
- ~BbCameraService();
-
- virtual QMediaControl* requestControl(const char *name);
- virtual void releaseControl(QMediaControl *control);
-
-private:
- BbCameraSession* m_cameraSession;
-
- BbCameraAudioEncoderSettingsControl* m_cameraAudioEncoderSettingsControl;
- BbCameraCaptureBufferFormatControl* m_cameraCaptureBufferFormatControl;
- BbCameraCaptureDestinationControl* m_cameraCaptureDestinationControl;
- BbCameraControl* m_cameraControl;
- BbCameraExposureControl* m_cameraExposureControl;
- BbCameraFlashControl* m_cameraFlashControl;
- BbCameraFocusControl* m_cameraFocusControl;
- BbCameraImageCaptureControl* m_cameraImageCaptureControl;
- BbCameraImageProcessingControl* m_cameraImageProcessingControl;
- BbCameraInfoControl* m_cameraInfoControl;
- BbCameraLocksControl* m_cameraLocksControl;
- BbCameraMediaRecorderControl* m_cameraMediaRecorderControl;
- BbCameraVideoEncoderSettingsControl* m_cameraVideoEncoderSettingsControl;
- BbCameraViewfinderSettingsControl* m_cameraViewfinderSettingsControl;
- BbCameraZoomControl* m_cameraZoomControl;
- BbImageEncoderControl* m_imageEncoderControl;
- BbVideoDeviceSelectorControl* m_videoDeviceSelectorControl;
- BbVideoRendererControl* m_videoRendererControl;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcamerasession.cpp b/src/plugins/qnx/camera/bbcamerasession.cpp
deleted file mode 100644
index 7b3974084..000000000
--- a/src/plugins/qnx/camera/bbcamerasession.cpp
+++ /dev/null
@@ -1,1154 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcamerasession.h"
-
-#include "bbcameraorientationhandler.h"
-#include "bbcameraviewfindersettingscontrol.h"
-#include "windowgrabber.h"
-
-#include <QAbstractVideoSurface>
-#include <QBuffer>
-#include <QDebug>
-#include <QImage>
-#include <QUrl>
-#include <QVideoSurfaceFormat>
-#include <qmath.h>
-
-#include <algorithm>
-
-QT_BEGIN_NAMESPACE
-
-static QString errorToString(camera_error_t error)
-{
- switch (error) {
- case CAMERA_EOK:
- return QLatin1String("No error");
- case CAMERA_EAGAIN:
- return QLatin1String("Camera unavailable");
- case CAMERA_EINVAL:
- return QLatin1String("Invalid argument");
- case CAMERA_ENODEV:
- return QLatin1String("Camera not found");
- case CAMERA_EMFILE:
- return QLatin1String("File table overflow");
- case CAMERA_EBADF:
- return QLatin1String("Invalid handle passed");
- case CAMERA_EACCESS:
- return QLatin1String("No permission");
- case CAMERA_EBADR:
- return QLatin1String("Invalid file descriptor");
- case CAMERA_ENOENT:
- return QLatin1String("File or directory does not exists");
- case CAMERA_ENOMEM:
- return QLatin1String("Memory allocation failed");
- case CAMERA_EOPNOTSUPP:
- return QLatin1String("Operation not supported");
- case CAMERA_ETIMEDOUT:
- return QLatin1String("Communication timeout");
- case CAMERA_EALREADY:
- return QLatin1String("Operation already in progress");
- case CAMERA_EUNINIT:
- return QLatin1String("Camera library not initialized");
- case CAMERA_EREGFAULT:
- return QLatin1String("Callback registration failed");
- case CAMERA_EMICINUSE:
- return QLatin1String("Microphone in use already");
- case CAMERA_ENODATA:
- return QLatin1String("Data does not exist");
- case CAMERA_EBUSY:
- return QLatin1String("Camera busy");
- case CAMERA_EDESKTOPCAMERAINUSE:
- return QLatin1String("Desktop camera in use already");
- case CAMERA_ENOSPC:
- return QLatin1String("Disk is full");
- case CAMERA_EPOWERDOWN:
- return QLatin1String("Camera in power down state");
- case CAMERA_3ALOCKED:
- return QLatin1String("3A have been locked");
-// case CAMERA_EVIEWFINDERFROZEN: // not yet available in 10.2 NDK
-// return QLatin1String("Freeze flag set");
- default:
- return QLatin1String("Unknown error");
- }
-}
-
-QDebug operator<<(QDebug debug, camera_error_t error)
-{
- debug.nospace() << errorToString(error);
- return debug.space();
-}
-
-BbCameraSession::BbCameraSession(QObject *parent)
- : QObject(parent)
- , m_nativeCameraOrientation(0)
- , m_orientationHandler(new BbCameraOrientationHandler(this))
- , m_status(QCamera::UnloadedStatus)
- , m_state(QCamera::UnloadedState)
- , m_captureMode(QCamera::CaptureStillImage)
- , m_device("bb:RearCamera")
- , m_previewIsVideo(true)
- , m_surface(0)
- , m_captureImageDriveMode(QCameraImageCapture::SingleImageCapture)
- , m_lastImageCaptureId(0)
- , m_captureDestination(QCameraImageCapture::CaptureToFile)
- , m_videoState(QMediaRecorder::StoppedState)
- , m_videoStatus(QMediaRecorder::LoadedStatus)
- , m_handle(CAMERA_HANDLE_INVALID)
- , m_windowGrabber(new WindowGrabber(this))
-{
- connect(this, SIGNAL(statusChanged(QCamera::Status)), SLOT(updateReadyForCapture()));
- connect(this, SIGNAL(captureModeChanged(QCamera::CaptureModes)), SLOT(updateReadyForCapture()));
- connect(m_orientationHandler, SIGNAL(orientationChanged(int)), SLOT(deviceOrientationChanged(int)));
-
- connect(m_windowGrabber, SIGNAL(frameGrabbed(QImage, int)), SLOT(viewfinderFrameGrabbed(QImage)));
-}
-
-BbCameraSession::~BbCameraSession()
-{
- stopViewFinder();
- closeCamera();
-}
-
-camera_handle_t BbCameraSession::handle() const
-{
- return m_handle;
-}
-
-QCamera::State BbCameraSession::state() const
-{
- return m_state;
-}
-
-void BbCameraSession::setState(QCamera::State state)
-{
- if (m_state == state)
- return;
-
- const QCamera::State previousState = m_state;
-
- if (previousState == QCamera::UnloadedState) {
- if (state == QCamera::LoadedState) {
- if (openCamera()) {
- m_state = state;
- }
- } else if (state == QCamera::ActiveState) {
- if (openCamera()) {
- QMetaObject::invokeMethod(this, "applyConfiguration", Qt::QueuedConnection);
- m_state = state;
- }
- }
- } else if (previousState == QCamera::LoadedState) {
- if (state == QCamera::UnloadedState) {
- closeCamera();
- m_state = state;
- } else if (state == QCamera::ActiveState) {
- QMetaObject::invokeMethod(this, "applyConfiguration", Qt::QueuedConnection);
- m_state = state;
- }
- } else if (previousState == QCamera::ActiveState) {
- if (state == QCamera::LoadedState) {
- stopViewFinder();
- m_state = state;
- } else if (state == QCamera::UnloadedState) {
- stopViewFinder();
- closeCamera();
- m_state = state;
- }
- }
-
- if (m_state != previousState)
- emit stateChanged(m_state);
-}
-
-QCamera::Status BbCameraSession::status() const
-{
- return m_status;
-}
-
-QCamera::CaptureModes BbCameraSession::captureMode() const
-{
- return m_captureMode;
-}
-
-void BbCameraSession::setCaptureMode(QCamera::CaptureModes captureMode)
-{
- if (m_captureMode == captureMode)
- return;
-
- m_captureMode = captureMode;
- emit captureModeChanged(m_captureMode);
-}
-
-bool BbCameraSession::isCaptureModeSupported(QCamera::CaptureModes mode) const
-{
- if (m_handle == CAMERA_HANDLE_INVALID) {
- // the camera has not been loaded yet via QCamera::load(), so
- // we open it temporarily to peek for the supported capture modes
-
- camera_unit_t unit = CAMERA_UNIT_REAR;
- if (m_device == cameraIdentifierFront())
- unit = CAMERA_UNIT_FRONT;
- else if (m_device == cameraIdentifierRear())
- unit = CAMERA_UNIT_REAR;
- else if (m_device == cameraIdentifierDesktop())
- unit = CAMERA_UNIT_DESKTOP;
-
- camera_handle_t handle;
- const camera_error_t result = camera_open(unit, CAMERA_MODE_RW, &handle);
- if (result != CAMERA_EOK)
- return true;
-
- const bool supported = isCaptureModeSupported(handle, mode);
-
- camera_close(handle);
-
- return supported;
- } else {
- return isCaptureModeSupported(m_handle, mode);
- }
-}
-
-QByteArray BbCameraSession::cameraIdentifierFront()
-{
- return "bb:FrontCamera";
-}
-
-QByteArray BbCameraSession::cameraIdentifierRear()
-{
- return "bb:RearCamera";
-}
-
-QByteArray BbCameraSession::cameraIdentifierDesktop()
-{
- return "bb:DesktopCamera";
-}
-
-void BbCameraSession::setDevice(const QByteArray &device)
-{
- m_device = device;
-}
-
-QByteArray BbCameraSession::device() const
-{
- return m_device;
-}
-
-QAbstractVideoSurface* BbCameraSession::surface() const
-{
- return m_surface;
-}
-
-void BbCameraSession::setSurface(QAbstractVideoSurface *surface)
-{
- QMutexLocker locker(&m_surfaceMutex);
-
- if (m_surface == surface)
- return;
-
- m_surface = surface;
-}
-
-bool BbCameraSession::isReadyForCapture() const
-{
- if (m_captureMode & QCamera::CaptureStillImage)
- return (m_status == QCamera::ActiveStatus);
-
- if (m_captureMode & QCamera::CaptureVideo)
- return (m_status == QCamera::ActiveStatus);
-
- return false;
-}
-
-QCameraImageCapture::DriveMode BbCameraSession::driveMode() const
-{
- return m_captureImageDriveMode;
-}
-
-void BbCameraSession::setDriveMode(QCameraImageCapture::DriveMode mode)
-{
- m_captureImageDriveMode = mode;
-}
-
-/**
- * A helper structure that keeps context data for image capture callbacks.
- */
-struct ImageCaptureData
-{
- int requestId;
- QString fileName;
- BbCameraSession *session;
-};
-
-static void imageCaptureShutterCallback(camera_handle_t handle, void *context)
-{
- Q_UNUSED(handle);
-
- const ImageCaptureData *data = static_cast<ImageCaptureData*>(context);
-
- // We are inside a worker thread here, so emit imageExposed inside the main thread
- QMetaObject::invokeMethod(data->session, "imageExposed", Qt::QueuedConnection,
- Q_ARG(int, data->requestId));
-}
-
-static void imageCaptureImageCallback(camera_handle_t handle, camera_buffer_t *buffer, void *context)
-{
- Q_UNUSED(handle);
-
- QScopedPointer<ImageCaptureData> data(static_cast<ImageCaptureData*>(context));
-
- if (buffer->frametype != CAMERA_FRAMETYPE_JPEG) {
- // We are inside a worker thread here, so emit error signal inside the main thread
- QMetaObject::invokeMethod(data->session, "imageCaptureError", Qt::QueuedConnection,
- Q_ARG(int, data->requestId),
- Q_ARG(QCameraImageCapture::Error, QCameraImageCapture::FormatError),
- Q_ARG(QString, BbCameraSession::tr("Camera provides image in unsupported format")));
- return;
- }
-
- const QByteArray rawData((const char*)buffer->framebuf, buffer->framedesc.jpeg.bufsize);
-
- QImage image;
- const bool ok = image.loadFromData(rawData, "JPG");
- if (!ok) {
- const QString errorMessage = BbCameraSession::tr("Could not load JPEG data from frame");
- // We are inside a worker thread here, so emit error signal inside the main thread
- QMetaObject::invokeMethod(data->session, "imageCaptureError", Qt::QueuedConnection,
- Q_ARG(int, data->requestId),
- Q_ARG(QCameraImageCapture::Error, QCameraImageCapture::FormatError),
- Q_ARG(QString, errorMessage));
- return;
- }
-
-
- // We are inside a worker thread here, so invoke imageCaptured inside the main thread
- QMetaObject::invokeMethod(data->session, "imageCaptured", Qt::QueuedConnection,
- Q_ARG(int, data->requestId),
- Q_ARG(QImage, image),
- Q_ARG(QString, data->fileName));
-}
-
-int BbCameraSession::capture(const QString &fileName)
-{
- m_lastImageCaptureId++;
-
- if (!isReadyForCapture()) {
- emit imageCaptureError(m_lastImageCaptureId, QCameraImageCapture::NotReadyError, tr("Camera not ready"));
- return m_lastImageCaptureId;
- }
-
- if (m_captureImageDriveMode == QCameraImageCapture::SingleImageCapture) {
- // prepare context object for callback
- ImageCaptureData *context = new ImageCaptureData;
- context->requestId = m_lastImageCaptureId;
- context->fileName = fileName;
- context->session = this;
-
- const camera_error_t result = camera_take_photo(m_handle,
- imageCaptureShutterCallback,
- 0,
- 0,
- imageCaptureImageCallback,
- context, false);
-
- if (result != CAMERA_EOK)
- qWarning() << "Unable to take photo:" << result;
- } else {
- // TODO: implement burst mode when available in Qt API
- }
-
- return m_lastImageCaptureId;
-}
-
-void BbCameraSession::cancelCapture()
-{
- // BB10 API doesn't provide functionality for that
-}
-
-bool BbCameraSession::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const
-{
- // capture to buffer, file and both are supported.
- return destination & (QCameraImageCapture::CaptureToFile | QCameraImageCapture::CaptureToBuffer);
-}
-
-QCameraImageCapture::CaptureDestinations BbCameraSession::captureDestination() const
-{
- return m_captureDestination;
-}
-
-void BbCameraSession::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination)
-{
- if (m_captureDestination != destination) {
- m_captureDestination = destination;
- emit captureDestinationChanged(m_captureDestination);
- }
-}
-
-QList<QSize> BbCameraSession::supportedResolutions(const QImageEncoderSettings&, bool *continuous) const
-{
- if (continuous)
- *continuous = false;
-
- if (m_status == QCamera::UnloadedStatus)
- return QList<QSize>();
-
- if (m_captureMode & QCamera::CaptureStillImage) {
- return supportedResolutions(QCamera::CaptureStillImage);
- } else if (m_captureMode & QCamera::CaptureVideo) {
- return supportedResolutions(QCamera::CaptureVideo);
- }
-
- return QList<QSize>();
-}
-
-QImageEncoderSettings BbCameraSession::imageSettings() const
-{
- return m_imageEncoderSettings;
-}
-
-void BbCameraSession::setImageSettings(const QImageEncoderSettings &settings)
-{
- m_imageEncoderSettings = settings;
- if (m_imageEncoderSettings.codec().isEmpty())
- m_imageEncoderSettings.setCodec(QLatin1String("jpeg"));
-}
-
-QUrl BbCameraSession::outputLocation() const
-{
- return QUrl::fromLocalFile(m_videoOutputLocation);
-}
-
-bool BbCameraSession::setOutputLocation(const QUrl &location)
-{
- m_videoOutputLocation = location.toLocalFile();
-
- return true;
-}
-
-QMediaRecorder::State BbCameraSession::videoState() const
-{
- return m_videoState;
-}
-
-void BbCameraSession::setVideoState(QMediaRecorder::State state)
-{
- if (m_videoState == state)
- return;
-
- const QMediaRecorder::State previousState = m_videoState;
-
- if (previousState == QMediaRecorder::StoppedState) {
- if (state == QMediaRecorder::RecordingState) {
- if (startVideoRecording()) {
- m_videoState = state;
- }
- } else if (state == QMediaRecorder::PausedState) {
- // do nothing
- }
- } else if (previousState == QMediaRecorder::RecordingState) {
- if (state == QMediaRecorder::StoppedState) {
- stopVideoRecording();
- m_videoState = state;
- } else if (state == QMediaRecorder::PausedState) {
- //TODO: (pause) not supported by BB10 API yet
- }
- } else if (previousState == QMediaRecorder::PausedState) {
- if (state == QMediaRecorder::StoppedState) {
- stopVideoRecording();
- m_videoState = state;
- } else if (state == QMediaRecorder::RecordingState) {
- //TODO: (resume) not supported by BB10 API yet
- }
- }
-
- emit videoStateChanged(m_videoState);
-}
-
-QMediaRecorder::Status BbCameraSession::videoStatus() const
-{
- return m_videoStatus;
-}
-
-qint64 BbCameraSession::duration() const
-{
- return (m_videoRecordingDuration.isValid() ? m_videoRecordingDuration.elapsed() : 0);
-}
-
-void BbCameraSession::applyVideoSettings()
-{
- if (m_handle == CAMERA_HANDLE_INVALID)
- return;
-
- // apply viewfinder configuration
- const QList<QSize> videoOutputResolutions = supportedResolutions(QCamera::CaptureVideo);
-
- if (!m_videoEncoderSettings.resolution().isValid() || !videoOutputResolutions.contains(m_videoEncoderSettings.resolution()))
- m_videoEncoderSettings.setResolution(videoOutputResolutions.first());
-
- QSize viewfinderResolution;
-
- if (m_previewIsVideo) {
- // The viewfinder is responsible for encoding the video frames, so the resolutions must match.
- viewfinderResolution = m_videoEncoderSettings.resolution();
- } else {
- // The frames are encoded separately from the viewfinder, so only the aspect ratio must match.
- const QSize videoResolution = m_videoEncoderSettings.resolution();
- const qreal aspectRatio = static_cast<qreal>(videoResolution.width())/static_cast<qreal>(videoResolution.height());
-
- QList<QSize> sizes = supportedViewfinderResolutions(QCamera::CaptureVideo);
- std::reverse(sizes.begin(), sizes.end()); // use smallest possible resolution
- for (const QSize &size : qAsConst(sizes)) {
- // search for viewfinder resolution with the same aspect ratio
- if (qFuzzyCompare(aspectRatio, (static_cast<qreal>(size.width())/static_cast<qreal>(size.height())))) {
- viewfinderResolution = size;
- break;
- }
- }
- }
-
- Q_ASSERT(viewfinderResolution.isValid());
-
- const QByteArray windowId = QString().sprintf("qcamera_vf_%p", this).toLatin1();
- m_windowGrabber->setWindowId(windowId);
-
- const QByteArray windowGroupId = m_windowGrabber->windowGroupId();
-
- const int rotationAngle = (360 - m_nativeCameraOrientation);
-
- camera_error_t result = CAMERA_EOK;
- result = camera_set_videovf_property(m_handle,
- CAMERA_IMGPROP_WIN_GROUPID, windowGroupId.data(),
- CAMERA_IMGPROP_WIN_ID, windowId.data(),
- CAMERA_IMGPROP_WIDTH, viewfinderResolution.width(),
- CAMERA_IMGPROP_HEIGHT, viewfinderResolution.height(),
- CAMERA_IMGPROP_ROTATION, rotationAngle);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to apply video viewfinder settings:" << result;
- return;
- }
-
- const QSize resolution = m_videoEncoderSettings.resolution();
-
- QString videoCodec = m_videoEncoderSettings.codec();
- if (videoCodec.isEmpty())
- videoCodec = QLatin1String("h264");
-
- camera_videocodec_t cameraVideoCodec = CAMERA_VIDEOCODEC_H264;
- if (videoCodec == QLatin1String("none"))
- cameraVideoCodec = CAMERA_VIDEOCODEC_NONE;
- else if (videoCodec == QLatin1String("avc1"))
- cameraVideoCodec = CAMERA_VIDEOCODEC_AVC1;
- else if (videoCodec == QLatin1String("h264"))
- cameraVideoCodec = CAMERA_VIDEOCODEC_H264;
-
- qreal frameRate = m_videoEncoderSettings.frameRate();
- if (frameRate == 0) {
- const QList<qreal> frameRates = supportedFrameRates(QVideoEncoderSettings(), 0);
- if (!frameRates.isEmpty())
- frameRate = frameRates.last();
- }
-
- QString audioCodec = m_audioEncoderSettings.codec();
- if (audioCodec.isEmpty())
- audioCodec = QLatin1String("aac");
-
- camera_audiocodec_t cameraAudioCodec = CAMERA_AUDIOCODEC_AAC;
- if (audioCodec == QLatin1String("none"))
- cameraAudioCodec = CAMERA_AUDIOCODEC_NONE;
- else if (audioCodec == QLatin1String("aac"))
- cameraAudioCodec = CAMERA_AUDIOCODEC_AAC;
- else if (audioCodec == QLatin1String("raw"))
- cameraAudioCodec = CAMERA_AUDIOCODEC_RAW;
-
- result = camera_set_video_property(m_handle,
- CAMERA_IMGPROP_WIDTH, resolution.width(),
- CAMERA_IMGPROP_HEIGHT, resolution.height(),
- CAMERA_IMGPROP_ROTATION, rotationAngle,
- CAMERA_IMGPROP_VIDEOCODEC, cameraVideoCodec,
- CAMERA_IMGPROP_AUDIOCODEC, cameraAudioCodec);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to apply video settings:" << result;
- emit videoError(QMediaRecorder::ResourceError, tr("Unable to apply video settings"));
- }
-}
-
-QList<QSize> BbCameraSession::supportedResolutions(const QVideoEncoderSettings &settings, bool *continuous) const
-{
- Q_UNUSED(settings);
-
- if (continuous)
- *continuous = false;
-
- return supportedResolutions(QCamera::CaptureVideo);
-}
-
-QList<qreal> BbCameraSession::supportedFrameRates(const QVideoEncoderSettings &settings, bool *continuous) const
-{
- Q_UNUSED(settings);
-
- if (m_handle == CAMERA_HANDLE_INVALID)
- return QList<qreal>();
-
- int supported = 0;
- double rates[20];
- bool maxmin = false;
-
- /**
- * Since in current version of the BB10 platform the video viewfinder encodes the video frames, we use
- * the values as returned by camera_get_video_vf_framerates().
- */
- const camera_error_t result = camera_get_video_vf_framerates(m_handle, 20, &supported, rates, &maxmin);
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve supported viewfinder framerates:" << result;
- return QList<qreal>();
- }
-
- QList<qreal> frameRates;
- for (int i = 0; i < supported; ++i)
- frameRates << rates[i];
-
- if (continuous)
- *continuous = maxmin;
-
- return frameRates;
-}
-
-QVideoEncoderSettings BbCameraSession::videoSettings() const
-{
- return m_videoEncoderSettings;
-}
-
-void BbCameraSession::setVideoSettings(const QVideoEncoderSettings &settings)
-{
- m_videoEncoderSettings = settings;
-}
-
-QAudioEncoderSettings BbCameraSession::audioSettings() const
-{
- return m_audioEncoderSettings;
-}
-
-void BbCameraSession::setAudioSettings(const QAudioEncoderSettings &settings)
-{
- m_audioEncoderSettings = settings;
-}
-
-void BbCameraSession::updateReadyForCapture()
-{
- emit readyForCaptureChanged(isReadyForCapture());
-}
-
-void BbCameraSession::imageCaptured(int requestId, const QImage &rawImage, const QString &fileName)
-{
- QTransform transform;
-
- // subtract out the native rotation
- transform.rotate(m_nativeCameraOrientation);
-
- // subtract out the current device orientation
- if (m_device == cameraIdentifierRear())
- transform.rotate(360 - m_orientationHandler->orientation());
- else
- transform.rotate(m_orientationHandler->orientation());
-
- const QImage image = rawImage.transformed(transform);
-
- // Generate snap preview as downscaled image
- {
- QSize previewSize = image.size();
- int downScaleSteps = 0;
- while (previewSize.width() > 800 && downScaleSteps < 8) {
- previewSize.rwidth() /= 2;
- previewSize.rheight() /= 2;
- downScaleSteps++;
- }
-
- const QImage snapPreview = image.scaled(previewSize);
-
- emit imageCaptured(requestId, snapPreview);
- }
-
- if (m_captureDestination & QCameraImageCapture::CaptureToBuffer) {
- QVideoFrame frame(image);
-
- emit imageAvailable(requestId, frame);
- }
-
- if (m_captureDestination & QCameraImageCapture::CaptureToFile) {
- const QString actualFileName = m_mediaStorageLocation.generateFileName(fileName,
- QCamera::CaptureStillImage,
- QLatin1String("IMG_"),
- QLatin1String("jpg"));
-
- QFile file(actualFileName);
- if (file.open(QFile::WriteOnly)) {
- if (image.save(&file, "JPG")) {
- emit imageSaved(requestId, actualFileName);
- } else {
- emit imageCaptureError(requestId, QCameraImageCapture::OutOfSpaceError, file.errorString());
- }
- } else {
- const QString errorMessage = tr("Could not open destination file:\n%1").arg(actualFileName);
- emit imageCaptureError(requestId, QCameraImageCapture::ResourceError, errorMessage);
- }
- }
-}
-
-void BbCameraSession::handleVideoRecordingPaused()
-{
- //TODO: implement once BB10 API supports pausing a video
-}
-
-void BbCameraSession::handleVideoRecordingResumed()
-{
- if (m_videoStatus == QMediaRecorder::StartingStatus) {
- m_videoStatus = QMediaRecorder::RecordingStatus;
- emit videoStatusChanged(m_videoStatus);
-
- m_videoRecordingDuration.restart();
- }
-}
-
-void BbCameraSession::deviceOrientationChanged(int angle)
-{
- if (m_handle != CAMERA_HANDLE_INVALID)
- camera_set_device_orientation(m_handle, angle);
-}
-
-void BbCameraSession::handleCameraPowerUp()
-{
- stopViewFinder();
- startViewFinder();
-}
-
-void BbCameraSession::viewfinderFrameGrabbed(const QImage &image)
-{
- QTransform transform;
-
- // subtract out the native rotation
- transform.rotate(m_nativeCameraOrientation);
-
- // subtract out the current device orientation
- if (m_device == cameraIdentifierRear())
- transform.rotate(360 - m_orientationHandler->viewfinderOrientation());
- else
- transform.rotate(m_orientationHandler->viewfinderOrientation());
-
- QImage frame = image.copy().transformed(transform);
-
- QMutexLocker locker(&m_surfaceMutex);
- if (m_surface) {
- if (frame.size() != m_surface->surfaceFormat().frameSize()) {
- m_surface->stop();
- m_surface->start(QVideoSurfaceFormat(frame.size(), QVideoFrame::Format_ARGB32));
- }
-
- QVideoFrame videoFrame(frame);
-
- m_surface->present(videoFrame);
- }
-}
-
-bool BbCameraSession::openCamera()
-{
- if (m_handle != CAMERA_HANDLE_INVALID) // camera is already open
- return true;
-
- m_status = QCamera::LoadingStatus;
- emit statusChanged(m_status);
-
- camera_unit_t unit = CAMERA_UNIT_REAR;
- if (m_device == cameraIdentifierFront())
- unit = CAMERA_UNIT_FRONT;
- else if (m_device == cameraIdentifierRear())
- unit = CAMERA_UNIT_REAR;
- else if (m_device == cameraIdentifierDesktop())
- unit = CAMERA_UNIT_DESKTOP;
-
- camera_error_t result = camera_open(unit, CAMERA_MODE_RW, &m_handle);
- if (result != CAMERA_EOK) {
- m_handle = CAMERA_HANDLE_INVALID;
- m_status = QCamera::UnloadedStatus;
- emit statusChanged(m_status);
-
- qWarning() << "Unable to open camera:" << result;
- emit error(QCamera::CameraError, tr("Unable to open camera"));
- return false;
- }
-
- result = camera_get_native_orientation(m_handle, &m_nativeCameraOrientation);
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve native camera orientation:" << result;
- emit error(QCamera::CameraError, tr("Unable to retrieve native camera orientation"));
- return false;
- }
-
- m_previewIsVideo = camera_has_feature(m_handle, CAMERA_FEATURE_PREVIEWISVIDEO);
-
- m_status = QCamera::LoadedStatus;
- emit statusChanged(m_status);
-
- emit cameraOpened();
-
- return true;
-}
-
-void BbCameraSession::closeCamera()
-{
- if (m_handle == CAMERA_HANDLE_INVALID) // camera is closed already
- return;
-
- m_status = QCamera::UnloadingStatus;
- emit statusChanged(m_status);
-
- const camera_error_t result = camera_close(m_handle);
- if (result != CAMERA_EOK) {
- m_status = QCamera::LoadedStatus;
- emit statusChanged(m_status);
-
- qWarning() << "Unable to close camera:" << result;
- emit error(QCamera::CameraError, tr("Unable to close camera"));
- return;
- }
-
- m_handle = CAMERA_HANDLE_INVALID;
-
- m_status = QCamera::UnloadedStatus;
- emit statusChanged(m_status);
-}
-
-static void viewFinderStatusCallback(camera_handle_t handle, camera_devstatus_t status, uint16_t value, void *context)
-{
- Q_UNUSED(handle);
-
- if (status == CAMERA_STATUS_FOCUS_CHANGE) {
- BbCameraSession *session = static_cast<BbCameraSession*>(context);
- QMetaObject::invokeMethod(session, "focusStatusChanged", Qt::QueuedConnection, Q_ARG(int, value));
- return;
- } else if (status == CAMERA_STATUS_POWERUP) {
- BbCameraSession *session = static_cast<BbCameraSession*>(context);
- QMetaObject::invokeMethod(session, "handleCameraPowerUp", Qt::QueuedConnection);
- }
-}
-
-bool BbCameraSession::startViewFinder()
-{
- m_status = QCamera::StartingStatus;
- emit statusChanged(m_status);
-
- QSize viewfinderResolution;
- camera_error_t result = CAMERA_EOK;
- if (m_captureMode & QCamera::CaptureStillImage) {
- result = camera_start_photo_viewfinder(m_handle, 0, viewFinderStatusCallback, this);
- viewfinderResolution = currentViewfinderResolution(QCamera::CaptureStillImage);
- } else if (m_captureMode & QCamera::CaptureVideo) {
- result = camera_start_video_viewfinder(m_handle, 0, viewFinderStatusCallback, this);
- viewfinderResolution = currentViewfinderResolution(QCamera::CaptureVideo);
- }
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to start viewfinder:" << result;
- return false;
- }
-
- const int angle = m_orientationHandler->viewfinderOrientation();
-
- const QSize rotatedSize = ((angle == 0 || angle == 180) ? viewfinderResolution
- : viewfinderResolution.transposed());
-
- m_surfaceMutex.lock();
- if (m_surface) {
- const bool ok = m_surface->start(QVideoSurfaceFormat(rotatedSize, QVideoFrame::Format_ARGB32));
- if (!ok)
- qWarning() << "Unable to start camera viewfinder surface";
- }
- m_surfaceMutex.unlock();
-
- m_status = QCamera::ActiveStatus;
- emit statusChanged(m_status);
-
- return true;
-}
-
-void BbCameraSession::stopViewFinder()
-{
- m_windowGrabber->stop();
-
- m_status = QCamera::StoppingStatus;
- emit statusChanged(m_status);
-
- m_surfaceMutex.lock();
- if (m_surface) {
- m_surface->stop();
- }
- m_surfaceMutex.unlock();
-
- camera_error_t result = CAMERA_EOK;
- if (m_captureMode & QCamera::CaptureStillImage)
- result = camera_stop_photo_viewfinder(m_handle);
- else if (m_captureMode & QCamera::CaptureVideo)
- result = camera_stop_video_viewfinder(m_handle);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to stop viewfinder:" << result;
- return;
- }
-
- m_status = QCamera::LoadedStatus;
- emit statusChanged(m_status);
-}
-
-void BbCameraSession::applyConfiguration()
-{
- if (m_captureMode & QCamera::CaptureStillImage) {
- const QList<QSize> photoOutputResolutions = supportedResolutions(QCamera::CaptureStillImage);
-
- if (!m_imageEncoderSettings.resolution().isValid() || !photoOutputResolutions.contains(m_imageEncoderSettings.resolution()))
- m_imageEncoderSettings.setResolution(photoOutputResolutions.first());
-
- const QSize photoResolution = m_imageEncoderSettings.resolution();
- const qreal aspectRatio = static_cast<qreal>(photoResolution.width())/static_cast<qreal>(photoResolution.height());
-
- // apply viewfinder configuration
- QSize viewfinderResolution;
- QList<QSize> sizes = supportedViewfinderResolutions(QCamera::CaptureStillImage);
- std::reverse(sizes.begin(), sizes.end()); // use smallest possible resolution
- for (const QSize &size : qAsConst(sizes)) {
- // search for viewfinder resolution with the same aspect ratio
- if (qFuzzyCompare(aspectRatio, (static_cast<qreal>(size.width())/static_cast<qreal>(size.height())))) {
- viewfinderResolution = size;
- break;
- }
- }
-
- Q_ASSERT(viewfinderResolution.isValid());
-
- const QByteArray windowId = QString().sprintf("qcamera_vf_%p", this).toLatin1();
- m_windowGrabber->setWindowId(windowId);
-
- const QByteArray windowGroupId = m_windowGrabber->windowGroupId();
-
- camera_error_t result = camera_set_photovf_property(m_handle,
- CAMERA_IMGPROP_WIN_GROUPID, windowGroupId.data(),
- CAMERA_IMGPROP_WIN_ID, windowId.data(),
- CAMERA_IMGPROP_WIDTH, viewfinderResolution.width(),
- CAMERA_IMGPROP_HEIGHT, viewfinderResolution.height(),
- CAMERA_IMGPROP_FORMAT, CAMERA_FRAMETYPE_NV12,
- CAMERA_IMGPROP_ROTATION, 360 - m_nativeCameraOrientation);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to apply photo viewfinder settings:" << result;
- return;
- }
-
-
- int jpegQuality = 100;
- switch (m_imageEncoderSettings.quality()) {
- case QMultimedia::VeryLowQuality:
- jpegQuality = 20;
- break;
- case QMultimedia::LowQuality:
- jpegQuality = 40;
- break;
- case QMultimedia::NormalQuality:
- jpegQuality = 60;
- break;
- case QMultimedia::HighQuality:
- jpegQuality = 80;
- break;
- case QMultimedia::VeryHighQuality:
- jpegQuality = 100;
- break;
- }
-
- // apply photo configuration
- result = camera_set_photo_property(m_handle,
- CAMERA_IMGPROP_WIDTH, photoResolution.width(),
- CAMERA_IMGPROP_HEIGHT, photoResolution.height(),
- CAMERA_IMGPROP_JPEGQFACTOR, jpegQuality,
- CAMERA_IMGPROP_ROTATION, 360 - m_nativeCameraOrientation);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to apply photo settings:" << result;
- return;
- }
-
- } else if (m_captureMode & QCamera::CaptureVideo) {
- applyVideoSettings();
- }
-
- startViewFinder();
-}
-
-static void videoRecordingStatusCallback(camera_handle_t handle, camera_devstatus_t status, uint16_t value, void *context)
-{
- Q_UNUSED(handle);
- Q_UNUSED(value);
-
- if (status == CAMERA_STATUS_VIDEO_PAUSE) {
- BbCameraSession *session = static_cast<BbCameraSession*>(context);
- QMetaObject::invokeMethod(session, "handleVideoRecordingPaused", Qt::QueuedConnection);
- } else if (status == CAMERA_STATUS_VIDEO_RESUME) {
- BbCameraSession *session = static_cast<BbCameraSession*>(context);
- QMetaObject::invokeMethod(session, "handleVideoRecordingResumed", Qt::QueuedConnection);
- }
-}
-
-bool BbCameraSession::startVideoRecording()
-{
- m_videoRecordingDuration.invalidate();
-
- m_videoStatus = QMediaRecorder::StartingStatus;
- emit videoStatusChanged(m_videoStatus);
-
- if (m_videoOutputLocation.isEmpty())
- m_videoOutputLocation = m_mediaStorageLocation.generateFileName(QLatin1String("VID_"), m_mediaStorageLocation.defaultDir(QCamera::CaptureVideo), QLatin1String("mp4"));
-
- emit actualLocationChanged(m_videoOutputLocation);
-
- const camera_error_t result = camera_start_video(m_handle, QFile::encodeName(m_videoOutputLocation), 0, videoRecordingStatusCallback, this);
- if (result != CAMERA_EOK) {
- m_videoStatus = QMediaRecorder::LoadedStatus;
- emit videoStatusChanged(m_videoStatus);
-
- emit videoError(QMediaRecorder::ResourceError, tr("Unable to start video recording"));
- return false;
- }
-
- return true;
-}
-
-void BbCameraSession::stopVideoRecording()
-{
- m_videoStatus = QMediaRecorder::FinalizingStatus;
- emit videoStatusChanged(m_videoStatus);
-
- const camera_error_t result = camera_stop_video(m_handle);
- if (result != CAMERA_EOK) {
- emit videoError(QMediaRecorder::ResourceError, tr("Unable to stop video recording"));
- }
-
- m_videoStatus = QMediaRecorder::LoadedStatus;
- emit videoStatusChanged(m_videoStatus);
-
- m_videoRecordingDuration.invalidate();
-}
-
-bool BbCameraSession::isCaptureModeSupported(camera_handle_t handle, QCamera::CaptureModes mode) const
-{
- if (mode & QCamera::CaptureStillImage)
- return camera_has_feature(handle, CAMERA_FEATURE_PHOTO);
-
- if (mode & QCamera::CaptureVideo)
- return camera_has_feature(handle, CAMERA_FEATURE_VIDEO);
-
- return false;
-}
-
-QList<QSize> BbCameraSession::supportedResolutions(QCamera::CaptureMode mode) const
-{
- Q_ASSERT(m_handle != CAMERA_HANDLE_INVALID);
-
- QList<QSize> list;
-
- camera_error_t result = CAMERA_EOK;
- camera_res_t resolutions[20];
- unsigned int supported = 0;
-
- if (mode == QCamera::CaptureStillImage)
- result = camera_get_photo_output_resolutions(m_handle, CAMERA_FRAMETYPE_JPEG, 20, &supported, resolutions);
- else if (mode == QCamera::CaptureVideo)
- result = camera_get_video_output_resolutions(m_handle, 20, &supported, resolutions);
-
- if (result != CAMERA_EOK)
- return list;
-
- for (unsigned int i = 0; i < supported; ++i)
- list << QSize(resolutions[i].width, resolutions[i].height);
-
- return list;
-}
-
-QList<QSize> BbCameraSession::supportedViewfinderResolutions(QCamera::CaptureMode mode) const
-{
- Q_ASSERT(m_handle != CAMERA_HANDLE_INVALID);
-
- QList<QSize> list;
-
- camera_error_t result = CAMERA_EOK;
- camera_res_t resolutions[20];
- unsigned int supported = 0;
-
- if (mode == QCamera::CaptureStillImage)
- result = camera_get_photo_vf_resolutions(m_handle, 20, &supported, resolutions);
- else if (mode == QCamera::CaptureVideo)
- result = camera_get_video_vf_resolutions(m_handle, 20, &supported, resolutions);
-
- if (result != CAMERA_EOK)
- return list;
-
- for (unsigned int i = 0; i < supported; ++i)
- list << QSize(resolutions[i].width, resolutions[i].height);
-
- return list;
-}
-
-QSize BbCameraSession::currentViewfinderResolution(QCamera::CaptureMode mode) const
-{
- Q_ASSERT(m_handle != CAMERA_HANDLE_INVALID);
-
- camera_error_t result = CAMERA_EOK;
- int width = 0;
- int height = 0;
-
- if (mode == QCamera::CaptureStillImage)
- result = camera_get_photovf_property(m_handle, CAMERA_IMGPROP_WIDTH, &width,
- CAMERA_IMGPROP_HEIGHT, &height);
- else if (mode == QCamera::CaptureVideo)
- result = camera_get_videovf_property(m_handle, CAMERA_IMGPROP_WIDTH, &width,
- CAMERA_IMGPROP_HEIGHT, &height);
-
- if (result != CAMERA_EOK)
- return QSize();
-
- return QSize(width, height);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcamerasession.h b/src/plugins/qnx/camera/bbcamerasession.h
deleted file mode 100644
index 70523f1e3..000000000
--- a/src/plugins/qnx/camera/bbcamerasession.h
+++ /dev/null
@@ -1,215 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERASESSION_H
-#define BBCAMERASESSION_H
-
-#include "bbmediastoragelocation.h"
-
-#include <QCamera>
-#include <QCameraImageCapture>
-#include <QCameraViewfinderSettingsControl>
-#include <QElapsedTimer>
-#include <QMediaRecorder>
-#include <QMutex>
-#include <QObject>
-#include <QPointer>
-
-#include <camera/camera_api.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraOrientationHandler;
-class WindowGrabber;
-
-class BbCameraSession : public QObject
-{
- Q_OBJECT
-public:
- explicit BbCameraSession(QObject *parent = 0);
- ~BbCameraSession();
-
- camera_handle_t handle() const;
-
- // camera control
- QCamera::State state() const;
- void setState(QCamera::State state);
- QCamera::Status status() const;
- QCamera::CaptureModes captureMode() const;
- void setCaptureMode(QCamera::CaptureModes);
- bool isCaptureModeSupported(QCamera::CaptureModes mode) const;
-
- // video device selector control
- static QByteArray cameraIdentifierFront();
- static QByteArray cameraIdentifierRear();
- static QByteArray cameraIdentifierDesktop();
-
- void setDevice(const QByteArray &device);
- QByteArray device() const;
-
- // video renderer control
- QAbstractVideoSurface *surface() const;
- void setSurface(QAbstractVideoSurface *surface);
-
- // image capture control
- bool isReadyForCapture() const;
- QCameraImageCapture::DriveMode driveMode() const;
- void setDriveMode(QCameraImageCapture::DriveMode mode);
- int capture(const QString &fileName);
- void cancelCapture();
-
- // capture destination control
- bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const;
- QCameraImageCapture::CaptureDestinations captureDestination() const;
- void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination);
-
- // image encoder control
- QList<QSize> supportedResolutions(const QImageEncoderSettings &settings, bool *continuous) const;
- QImageEncoderSettings imageSettings() const;
- void setImageSettings(const QImageEncoderSettings &settings);
-
- // media recorder control
- QUrl outputLocation() const;
- bool setOutputLocation(const QUrl &location);
- QMediaRecorder::State videoState() const;
- void setVideoState(QMediaRecorder::State state);
- QMediaRecorder::Status videoStatus() const;
- qint64 duration() const;
- void applyVideoSettings();
-
- // video encoder settings control
- QList<QSize> supportedResolutions(const QVideoEncoderSettings &settings, bool *continuous) const;
- QList<qreal> supportedFrameRates(const QVideoEncoderSettings &settings, bool *continuous) const;
- QVideoEncoderSettings videoSettings() const;
- void setVideoSettings(const QVideoEncoderSettings &settings);
-
- // audio encoder settings control
- QAudioEncoderSettings audioSettings() const;
- void setAudioSettings(const QAudioEncoderSettings &settings);
-
-Q_SIGNALS:
- // camera control
- void statusChanged(QCamera::Status);
- void stateChanged(QCamera::State);
- void error(int error, const QString &errorString);
- void captureModeChanged(QCamera::CaptureModes);
-
- // image capture control
- void readyForCaptureChanged(bool);
- void imageExposed(int id);
- void imageCaptured(int id, const QImage &preview);
- void imageMetadataAvailable(int id, const QString &key, const QVariant &value);
- void imageAvailable(int id, const QVideoFrame &buffer);
- void imageSaved(int id, const QString &fileName);
- void imageCaptureError(int id, int error, const QString &errorString);
-
- // capture destination control
- void captureDestinationChanged(QCameraImageCapture::CaptureDestinations destination);
-
- // media recorder control
- void videoStateChanged(QMediaRecorder::State state);
- void videoStatusChanged(QMediaRecorder::Status status);
- void durationChanged(qint64 duration);
- void actualLocationChanged(const QUrl &location);
- void videoError(int error, const QString &errorString);
-
- void cameraOpened();
- void focusStatusChanged(int status);
-
-private slots:
- void updateReadyForCapture();
- void imageCaptured(int, const QImage&, const QString&);
- void handleVideoRecordingPaused();
- void handleVideoRecordingResumed();
- void deviceOrientationChanged(int);
- void handleCameraPowerUp();
- void viewfinderFrameGrabbed(const QImage &image);
- void applyConfiguration();
-
-private:
- bool openCamera();
- void closeCamera();
- bool startViewFinder();
- void stopViewFinder();
- bool startVideoRecording();
- void stopVideoRecording();
-
- bool isCaptureModeSupported(camera_handle_t handle, QCamera::CaptureModes mode) const;
- QList<QSize> supportedResolutions(QCamera::CaptureMode mode) const;
- QList<QSize> supportedViewfinderResolutions(QCamera::CaptureMode mode) const;
- QSize currentViewfinderResolution(QCamera::CaptureMode mode) const;
-
- quint32 m_nativeCameraOrientation;
- BbCameraOrientationHandler* m_orientationHandler;
-
- QCamera::Status m_status;
- QCamera::State m_state;
- QCamera::CaptureModes m_captureMode;
-
- QByteArray m_device;
- bool m_previewIsVideo;
-
- QPointer<QAbstractVideoSurface> m_surface;
- QMutex m_surfaceMutex;
-
- QCameraImageCapture::DriveMode m_captureImageDriveMode;
- int m_lastImageCaptureId;
- QCameraImageCapture::CaptureDestinations m_captureDestination;
-
- QImageEncoderSettings m_imageEncoderSettings;
-
- QString m_videoOutputLocation;
- QMediaRecorder::State m_videoState;
- QMediaRecorder::Status m_videoStatus;
- QElapsedTimer m_videoRecordingDuration;
-
- QVideoEncoderSettings m_videoEncoderSettings;
- QAudioEncoderSettings m_audioEncoderSettings;
-
- BbMediaStorageLocation m_mediaStorageLocation;
-
- camera_handle_t m_handle;
-
- WindowGrabber* m_windowGrabber;
-};
-
-QDebug operator<<(QDebug debug, camera_error_t error);
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameravideoencodersettingscontrol.cpp b/src/plugins/qnx/camera/bbcameravideoencodersettingscontrol.cpp
deleted file mode 100644
index 5e3a902c2..000000000
--- a/src/plugins/qnx/camera/bbcameravideoencodersettingscontrol.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameravideoencodersettingscontrol.h"
-
-#include "bbcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-BbCameraVideoEncoderSettingsControl::BbCameraVideoEncoderSettingsControl(BbCameraSession *session, QObject *parent)
- : QVideoEncoderSettingsControl(parent)
- , m_session(session)
-{
-}
-
-QList<QSize> BbCameraVideoEncoderSettingsControl::supportedResolutions(const QVideoEncoderSettings &settings, bool *continuous) const
-{
- return m_session->supportedResolutions(settings, continuous);
-}
-
-QList<qreal> BbCameraVideoEncoderSettingsControl::supportedFrameRates(const QVideoEncoderSettings &settings, bool *continuous) const
-{
- return m_session->supportedFrameRates(settings, continuous);
-}
-
-QStringList BbCameraVideoEncoderSettingsControl::supportedVideoCodecs() const
-{
- return QStringList() << QLatin1String("none") << QLatin1String("avc1") << QLatin1String("h264");
-}
-
-QString BbCameraVideoEncoderSettingsControl::videoCodecDescription(const QString &codecName) const
-{
- if (codecName == QLatin1String("none"))
- return tr("No compression");
- else if (codecName == QLatin1String("avc1"))
- return tr("AVC1 compression");
- else if (codecName == QLatin1String("h264"))
- return tr("H264 compression");
-
- return QString();
-}
-
-QVideoEncoderSettings BbCameraVideoEncoderSettingsControl::videoSettings() const
-{
- return m_session->videoSettings();
-}
-
-void BbCameraVideoEncoderSettingsControl::setVideoSettings(const QVideoEncoderSettings &settings)
-{
- m_session->setVideoSettings(settings);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameravideoencodersettingscontrol.h b/src/plugins/qnx/camera/bbcameravideoencodersettingscontrol.h
deleted file mode 100644
index f67196be1..000000000
--- a/src/plugins/qnx/camera/bbcameravideoencodersettingscontrol.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERAVIDEOENCODERSETTINGSCONTROL_H
-#define BBCAMERAVIDEOENCODERSETTINGSCONTROL_H
-
-#include <qvideoencodersettingscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraVideoEncoderSettingsControl : public QVideoEncoderSettingsControl
-{
- Q_OBJECT
-public:
- explicit BbCameraVideoEncoderSettingsControl(BbCameraSession *session, QObject *parent = 0);
-
- QList<QSize> supportedResolutions(const QVideoEncoderSettings &settings, bool *continuous = 0) const override;
- QList<qreal> supportedFrameRates(const QVideoEncoderSettings &settings, bool *continuous = 0) const override;
- QStringList supportedVideoCodecs() const override;
- QString videoCodecDescription(const QString &codecName) const override;
- QVideoEncoderSettings videoSettings() const override;
- void setVideoSettings(const QVideoEncoderSettings &settings) override;
-
-private:
- BbCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcameraviewfindersettingscontrol.cpp b/src/plugins/qnx/camera/bbcameraviewfindersettingscontrol.cpp
deleted file mode 100644
index d800ffe13..000000000
--- a/src/plugins/qnx/camera/bbcameraviewfindersettingscontrol.cpp
+++ /dev/null
@@ -1,245 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcameraviewfindersettingscontrol.h"
-
-#include "bbcamerasession.h"
-
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-BbCameraViewfinderSettingsControl::BbCameraViewfinderSettingsControl(BbCameraSession *session, QObject *parent)
- : QCameraViewfinderSettingsControl(parent)
- , m_session(session)
-{
-}
-
-bool BbCameraViewfinderSettingsControl::isViewfinderParameterSupported(ViewfinderParameter parameter) const
-{
- switch (parameter) {
- case QCameraViewfinderSettingsControl::Resolution:
- return true;
- case QCameraViewfinderSettingsControl::PixelAspectRatio:
- return false;
- case QCameraViewfinderSettingsControl::MinimumFrameRate:
- return true;
- case QCameraViewfinderSettingsControl::MaximumFrameRate:
- return true;
- case QCameraViewfinderSettingsControl::PixelFormat:
- return true;
- default:
- return false;
- }
-}
-
-QVariant BbCameraViewfinderSettingsControl::viewfinderParameter(ViewfinderParameter parameter) const
-{
- if (parameter == QCameraViewfinderSettingsControl::Resolution) {
- camera_error_t result = CAMERA_EOK;
- unsigned int width = 0;
- unsigned int height = 0;
-
- if (m_session->captureMode() & QCamera::CaptureStillImage) {
- result = camera_get_photovf_property(m_session->handle(), CAMERA_IMGPROP_WIDTH, &width,
- CAMERA_IMGPROP_HEIGHT, &height);
- } else if (m_session->captureMode() & QCamera::CaptureVideo) {
- result = camera_get_videovf_property(m_session->handle(), CAMERA_IMGPROP_WIDTH, &width,
- CAMERA_IMGPROP_HEIGHT, &height);
- }
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve resolution of viewfinder:" << result;
- return QVariant();
- }
-
- return QSize(width, height);
-
- } else if (parameter == QCameraViewfinderSettingsControl::MinimumFrameRate) {
- camera_error_t result = CAMERA_EOK;
- double minimumFrameRate = 0;
-
- if (m_session->captureMode() & QCamera::CaptureStillImage)
- result = camera_get_photovf_property(m_session->handle(), CAMERA_IMGPROP_MINFRAMERATE, &minimumFrameRate);
- else if (m_session->captureMode() & QCamera::CaptureVideo)
- result = camera_get_videovf_property(m_session->handle(), CAMERA_IMGPROP_MINFRAMERATE, &minimumFrameRate);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve minimum framerate of viewfinder:" << result;
- return QVariant();
- }
-
- return QVariant(static_cast<qreal>(minimumFrameRate));
-
- } else if (parameter == QCameraViewfinderSettingsControl::MaximumFrameRate) {
- camera_error_t result = CAMERA_EOK;
- double maximumFrameRate = 0;
-
- if (m_session->captureMode() & QCamera::CaptureStillImage)
- result = camera_get_photovf_property(m_session->handle(), CAMERA_IMGPROP_FRAMERATE, &maximumFrameRate);
- else if (m_session->captureMode() & QCamera::CaptureVideo)
- result = camera_get_videovf_property(m_session->handle(), CAMERA_IMGPROP_FRAMERATE, &maximumFrameRate);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve maximum framerate of viewfinder:" << result;
- return QVariant();
- }
-
- return QVariant(static_cast<qreal>(maximumFrameRate));
- } else if (parameter == QCameraViewfinderSettingsControl::PixelFormat) {
- camera_error_t result = CAMERA_EOK;
- camera_frametype_t format = CAMERA_FRAMETYPE_UNSPECIFIED;
-
- if (m_session->captureMode() & QCamera::CaptureStillImage)
- result = camera_get_photovf_property(m_session->handle(), CAMERA_IMGPROP_FORMAT, &format);
- else if (m_session->captureMode() & QCamera::CaptureVideo)
- result = camera_get_videovf_property(m_session->handle(), CAMERA_IMGPROP_FORMAT, &format);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve pixel format of viewfinder:" << result;
- return QVariant();
- }
-
- switch (format) {
- case CAMERA_FRAMETYPE_UNSPECIFIED:
- return QVideoFrame::Format_Invalid;
- case CAMERA_FRAMETYPE_NV12:
- return QVideoFrame::Format_NV12;
- case CAMERA_FRAMETYPE_RGB8888:
- return QVideoFrame::Format_ARGB32;
- case CAMERA_FRAMETYPE_RGB888:
- return QVideoFrame::Format_RGB24;
- case CAMERA_FRAMETYPE_JPEG:
- return QVideoFrame::Format_Jpeg;
- case CAMERA_FRAMETYPE_GRAY8:
- return QVideoFrame::Format_Y8;
- case CAMERA_FRAMETYPE_METADATA:
- return QVideoFrame::Format_Invalid;
- case CAMERA_FRAMETYPE_BAYER:
- return QVideoFrame::Format_Invalid;
- case CAMERA_FRAMETYPE_CBYCRY:
- return QVideoFrame::Format_Invalid;
- case CAMERA_FRAMETYPE_COMPRESSEDVIDEO:
- return QVideoFrame::Format_Invalid;
- case CAMERA_FRAMETYPE_COMPRESSEDAUDIO:
- return QVideoFrame::Format_Invalid;
- default:
- return QVideoFrame::Format_Invalid;
- }
- }
-
- return QVariant();
-}
-
-void BbCameraViewfinderSettingsControl::setViewfinderParameter(ViewfinderParameter parameter, const QVariant &value)
-{
- if (parameter == QCameraViewfinderSettingsControl::Resolution) {
- camera_error_t result = CAMERA_EOK;
- const QSize size = value.toSize();
-
- if (m_session->captureMode() & QCamera::CaptureStillImage) {
- result = camera_set_photovf_property(m_session->handle(), CAMERA_IMGPROP_WIDTH, size.width(),
- CAMERA_IMGPROP_HEIGHT, size.height());
- } else if (m_session->captureMode() & QCamera::CaptureVideo) {
- result = camera_set_videovf_property(m_session->handle(), CAMERA_IMGPROP_WIDTH, size.width(),
- CAMERA_IMGPROP_HEIGHT, size.height());
- }
-
- if (result != CAMERA_EOK)
- qWarning() << "Unable to set resolution of viewfinder:" << result;
-
- } else if (parameter == QCameraViewfinderSettingsControl::MinimumFrameRate) {
- camera_error_t result = CAMERA_EOK;
- const double minimumFrameRate = value.toReal();
-
- if (m_session->captureMode() & QCamera::CaptureStillImage)
- result = camera_set_photovf_property(m_session->handle(), CAMERA_IMGPROP_MINFRAMERATE, minimumFrameRate);
- else if (m_session->captureMode() & QCamera::CaptureVideo)
- result = camera_set_videovf_property(m_session->handle(), CAMERA_IMGPROP_MINFRAMERATE, minimumFrameRate);
-
- if (result != CAMERA_EOK)
- qWarning() << "Unable to set minimum framerate of viewfinder:" << result;
-
- } else if (parameter == QCameraViewfinderSettingsControl::MaximumFrameRate) {
- camera_error_t result = CAMERA_EOK;
- const double maximumFrameRate = value.toReal();
-
- if (m_session->captureMode() & QCamera::CaptureStillImage)
- result = camera_set_photovf_property(m_session->handle(), CAMERA_IMGPROP_FRAMERATE, maximumFrameRate);
- else if (m_session->captureMode() & QCamera::CaptureVideo)
- result = camera_set_videovf_property(m_session->handle(), CAMERA_IMGPROP_FRAMERATE, maximumFrameRate);
-
- if (result != CAMERA_EOK)
- qWarning() << "Unable to set maximum framerate of viewfinder:" << result;
-
- } else if (parameter == QCameraViewfinderSettingsControl::PixelFormat) {
- camera_error_t result = CAMERA_EOK;
- camera_frametype_t format = CAMERA_FRAMETYPE_UNSPECIFIED;
-
- switch (value.value<QVideoFrame::PixelFormat>()) {
- case QVideoFrame::Format_NV12:
- format = CAMERA_FRAMETYPE_NV12;
- break;
- case QVideoFrame::Format_ARGB32:
- format = CAMERA_FRAMETYPE_RGB8888;
- break;
- case QVideoFrame::Format_RGB24:
- format = CAMERA_FRAMETYPE_RGB888;
- break;
- case QVideoFrame::Format_Jpeg:
- format = CAMERA_FRAMETYPE_JPEG;
- break;
- case QVideoFrame::Format_Y8:
- format = CAMERA_FRAMETYPE_GRAY8;
- break;
- default:
- format = CAMERA_FRAMETYPE_UNSPECIFIED;
- break;
- }
-
- if (m_session->captureMode() & QCamera::CaptureStillImage)
- result = camera_set_photovf_property(m_session->handle(), CAMERA_IMGPROP_FORMAT, format);
- else if (m_session->captureMode() & QCamera::CaptureVideo)
- result = camera_set_videovf_property(m_session->handle(), CAMERA_IMGPROP_FORMAT, format);
-
- if (result != CAMERA_EOK)
- qWarning() << "Unable to set pixel format of viewfinder:" << result;
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcameraviewfindersettingscontrol.h b/src/plugins/qnx/camera/bbcameraviewfindersettingscontrol.h
deleted file mode 100644
index 7a8e57a13..000000000
--- a/src/plugins/qnx/camera/bbcameraviewfindersettingscontrol.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERAVIEWVINDERSETTINGSCONTROL_H
-#define BBCAMERAVIEWVINDERSETTINGSCONTROL_H
-
-#include <qcameraviewfindersettingscontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraViewfinderSettingsControl : public QCameraViewfinderSettingsControl
-{
- Q_OBJECT
-public:
- explicit BbCameraViewfinderSettingsControl(BbCameraSession *session, QObject *parent = 0);
-
- bool isViewfinderParameterSupported(ViewfinderParameter parameter) const override;
- QVariant viewfinderParameter(ViewfinderParameter parameter) const override;
- void setViewfinderParameter(ViewfinderParameter parameter, const QVariant &value) override;
-
-private:
- BbCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbcamerazoomcontrol.cpp b/src/plugins/qnx/camera/bbcamerazoomcontrol.cpp
deleted file mode 100644
index 21f328b4f..000000000
--- a/src/plugins/qnx/camera/bbcamerazoomcontrol.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbcamerazoomcontrol.h"
-
-#include "bbcamerasession.h"
-
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-BbCameraZoomControl::BbCameraZoomControl(BbCameraSession *session, QObject *parent)
- : QCameraZoomControl(parent)
- , m_session(session)
- , m_minimumZoomFactor(1.0)
- , m_maximumZoomFactor(1.0)
- , m_supportsSmoothZoom(false)
- , m_requestedZoomFactor(1.0)
-{
- connect(m_session, SIGNAL(statusChanged(QCamera::Status)), this, SLOT(statusChanged(QCamera::Status)));
-}
-
-qreal BbCameraZoomControl::maximumOpticalZoom() const
-{
- //TODO: optical zoom support not available in BB10 API yet
- return 1.0;
-}
-
-qreal BbCameraZoomControl::maximumDigitalZoom() const
-{
- return m_maximumZoomFactor;
-}
-
-qreal BbCameraZoomControl::requestedOpticalZoom() const
-{
- //TODO: optical zoom support not available in BB10 API yet
- return 1.0;
-}
-
-qreal BbCameraZoomControl::requestedDigitalZoom() const
-{
- return currentDigitalZoom();
-}
-
-qreal BbCameraZoomControl::currentOpticalZoom() const
-{
- //TODO: optical zoom support not available in BB10 API yet
- return 1.0;
-}
-
-qreal BbCameraZoomControl::currentDigitalZoom() const
-{
- if (m_session->status() != QCamera::ActiveStatus)
- return 1.0;
-
- unsigned int zoomFactor = 0;
- camera_error_t result = CAMERA_EOK;
-
- if (m_session->captureMode() & QCamera::CaptureStillImage)
- result = camera_get_photovf_property(m_session->handle(), CAMERA_IMGPROP_ZOOMFACTOR, &zoomFactor);
- else if (m_session->captureMode() & QCamera::CaptureVideo)
- result = camera_get_videovf_property(m_session->handle(), CAMERA_IMGPROP_ZOOMFACTOR, &zoomFactor);
-
- if (result != CAMERA_EOK)
- return 1.0;
-
- return zoomFactor;
-}
-
-void BbCameraZoomControl::zoomTo(qreal optical, qreal digital)
-{
- Q_UNUSED(optical);
-
- if (m_session->status() != QCamera::ActiveStatus)
- return;
-
- const qreal actualZoom = qBound(m_minimumZoomFactor, digital, m_maximumZoomFactor);
-
- const camera_error_t result = camera_set_zoom(m_session->handle(), actualZoom, false);
-
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to change zoom factor:" << result;
- return;
- }
-
- if (m_requestedZoomFactor != digital) {
- m_requestedZoomFactor = digital;
- emit requestedDigitalZoomChanged(m_requestedZoomFactor);
- }
-
- emit currentDigitalZoomChanged(actualZoom);
-}
-
-void BbCameraZoomControl::statusChanged(QCamera::Status status)
-{
- if (status == QCamera::ActiveStatus) {
- // retrieve information about zoom limits
- unsigned int maximumZoomLimit = 0;
- unsigned int minimumZoomLimit = 0;
- bool smoothZoom = false;
-
- const camera_error_t result = camera_get_zoom_limits(m_session->handle(), &maximumZoomLimit, &minimumZoomLimit, &smoothZoom);
- if (result == CAMERA_EOK) {
- const qreal oldMaximumZoomFactor = m_maximumZoomFactor;
- m_maximumZoomFactor = maximumZoomLimit;
-
- if (oldMaximumZoomFactor != m_maximumZoomFactor)
- emit maximumDigitalZoomChanged(m_maximumZoomFactor);
-
- m_minimumZoomFactor = minimumZoomLimit;
- m_supportsSmoothZoom = smoothZoom;
- } else {
- m_maximumZoomFactor = 1.0;
- m_minimumZoomFactor = 1.0;
- m_supportsSmoothZoom = false;
- }
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbcamerazoomcontrol.h b/src/plugins/qnx/camera/bbcamerazoomcontrol.h
deleted file mode 100644
index 7b5e06f8d..000000000
--- a/src/plugins/qnx/camera/bbcamerazoomcontrol.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBCAMERAZOOMCONTROL_H
-#define BBCAMERAZOOMCONTROL_H
-
-#include <qcamera.h>
-#include <qcamerazoomcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbCameraZoomControl : public QCameraZoomControl
-{
- Q_OBJECT
-public:
- explicit BbCameraZoomControl(BbCameraSession *session, QObject *parent = 0);
-
- qreal maximumOpticalZoom() const override;
- qreal maximumDigitalZoom() const override;
- qreal requestedOpticalZoom() const override;
- qreal requestedDigitalZoom() const override;
- qreal currentOpticalZoom() const override;
- qreal currentDigitalZoom() const override;
- void zoomTo(qreal optical, qreal digital) override;
-
-private Q_SLOTS:
- void statusChanged(QCamera::Status status);
-
-private:
- BbCameraSession *m_session;
-
- qreal m_minimumZoomFactor;
- qreal m_maximumZoomFactor;
- bool m_supportsSmoothZoom;
- qreal m_requestedZoomFactor;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbimageencodercontrol.cpp b/src/plugins/qnx/camera/bbimageencodercontrol.cpp
deleted file mode 100644
index cd564a1d4..000000000
--- a/src/plugins/qnx/camera/bbimageencodercontrol.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbimageencodercontrol.h"
-
-#include "bbcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-BbImageEncoderControl::BbImageEncoderControl(BbCameraSession *session, QObject *parent)
- : QImageEncoderControl(parent)
- , m_session(session)
-{
-}
-
-QStringList BbImageEncoderControl::supportedImageCodecs() const
-{
- return QStringList() << QLatin1String("jpeg");
-}
-
-QString BbImageEncoderControl::imageCodecDescription(const QString &codecName) const
-{
- if (codecName == QLatin1String("jpeg"))
- return tr("JPEG image");
-
- return QString();
-}
-
-QList<QSize> BbImageEncoderControl::supportedResolutions(const QImageEncoderSettings &settings, bool *continuous) const
-{
- return m_session->supportedResolutions(settings, continuous);
-}
-
-QImageEncoderSettings BbImageEncoderControl::imageSettings() const
-{
- return m_session->imageSettings();
-}
-
-void BbImageEncoderControl::setImageSettings(const QImageEncoderSettings &settings)
-{
- m_session->setImageSettings(settings);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbimageencodercontrol.h b/src/plugins/qnx/camera/bbimageencodercontrol.h
deleted file mode 100644
index bb246def6..000000000
--- a/src/plugins/qnx/camera/bbimageencodercontrol.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBIMAGEENCODERCONTROL_H
-#define BBIMAGEENCODERCONTROL_H
-
-#include <qimageencodercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbImageEncoderControl : public QImageEncoderControl
-{
- Q_OBJECT
-public:
- explicit BbImageEncoderControl(BbCameraSession *session, QObject *parent = 0);
-
- QStringList supportedImageCodecs() const override;
- QString imageCodecDescription(const QString &codecName) const override;
- QList<QSize> supportedResolutions(const QImageEncoderSettings &settings, bool *continuous = 0) const override;
- QImageEncoderSettings imageSettings() const override;
- void setImageSettings(const QImageEncoderSettings &settings) override;
-
-private:
- BbCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbmediastoragelocation.cpp b/src/plugins/qnx/camera/bbmediastoragelocation.cpp
deleted file mode 100644
index c3aaed55d..000000000
--- a/src/plugins/qnx/camera/bbmediastoragelocation.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbmediastoragelocation.h"
-
-#include <QStandardPaths>
-
-QT_BEGIN_NAMESPACE
-
-BbMediaStorageLocation::BbMediaStorageLocation()
-{
-}
-
-QDir BbMediaStorageLocation::defaultDir(QCamera::CaptureMode mode) const
-{
- QStringList dirCandidates;
-
- dirCandidates << QLatin1String("shared/camera");
-
- if (mode == QCamera::CaptureVideo) {
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
- } else {
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
- }
-
- dirCandidates << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
- dirCandidates << QDir::homePath();
- dirCandidates << QDir::currentPath();
- dirCandidates << QDir::tempPath();
-
- for (const QString &path : qAsConst(dirCandidates)) {
- if (QFileInfo(path).isWritable())
- return QDir(path);
- }
-
- return QDir();
-}
-
-QString BbMediaStorageLocation::generateFileName(const QString &requestedName, QCamera::CaptureMode mode, const QString &prefix, const QString &extension) const
-{
- if (requestedName.isEmpty())
- return generateFileName(prefix, defaultDir(mode), extension);
-
- if (QFileInfo(requestedName).isDir())
- return generateFileName(prefix, QDir(requestedName), extension);
-
- return requestedName;
-}
-
-QString BbMediaStorageLocation::generateFileName(const QString &prefix, const QDir &dir, const QString &extension) const
-{
- const QString lastMediaKey = dir.absolutePath() + QLatin1Char(' ') + prefix + QLatin1Char(' ') + extension;
- qint64 lastMediaIndex = m_lastUsedIndex.value(lastMediaKey, 0);
-
- if (lastMediaIndex == 0) {
- // first run, find the maximum media number during the fist capture
- const auto list = dir.entryList(QStringList() << QString("%1*.%2").arg(prefix).arg(extension));
- for (const QString &fileName : list) {
- const qint64 mediaIndex = QStringView{fileName}.mid(prefix.length(), fileName.size() - prefix.length() - extension.length() - 1).toInt();
- lastMediaIndex = qMax(lastMediaIndex, mediaIndex);
- }
- }
-
- // don't just rely on cached lastMediaIndex value,
- // someone else may create a file after camera started
- while (true) {
- const QString name = QString("%1%2.%3").arg(prefix)
- .arg(lastMediaIndex + 1, 8, 10, QLatin1Char('0'))
- .arg(extension);
-
- const QString path = dir.absoluteFilePath(name);
- if (!QFileInfo(path).exists()) {
- m_lastUsedIndex[lastMediaKey] = lastMediaIndex + 1;
- return path;
- }
-
- lastMediaIndex++;
- }
-
- return QString();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbmediastoragelocation.h b/src/plugins/qnx/camera/bbmediastoragelocation.h
deleted file mode 100644
index 8a953c27d..000000000
--- a/src/plugins/qnx/camera/bbmediastoragelocation.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBMEDIASTORAGELOCATION_H
-#define BBMEDIASTORAGELOCATION_H
-
-#include <QCamera>
-#include <QDir>
-#include <QHash>
-
-QT_BEGIN_NAMESPACE
-
-class BbMediaStorageLocation
-{
-public:
- BbMediaStorageLocation();
-
- QDir defaultDir(QCamera::CaptureMode mode) const;
-
- QString generateFileName(const QString &requestedName, QCamera::CaptureMode mode, const QString &prefix, const QString &extension) const;
- QString generateFileName(const QString &prefix, const QDir &dir, const QString &extension) const;
-
-private:
- mutable QHash<QString, qint64> m_lastUsedIndex;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbvideodeviceselectorcontrol.cpp b/src/plugins/qnx/camera/bbvideodeviceselectorcontrol.cpp
deleted file mode 100644
index fd7deb179..000000000
--- a/src/plugins/qnx/camera/bbvideodeviceselectorcontrol.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "bbvideodeviceselectorcontrol.h"
-
-#include "bbcamerasession.h"
-
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-BbVideoDeviceSelectorControl::BbVideoDeviceSelectorControl(BbCameraSession *session, QObject *parent)
- : QVideoDeviceSelectorControl(parent)
- , m_session(session)
- , m_default(0)
- , m_selected(0)
-{
- enumerateDevices(&m_devices, &m_descriptions);
-
- // pre-select the rear camera
- const int index = m_devices.indexOf(BbCameraSession::cameraIdentifierRear());
- if (index != -1)
- m_default = m_selected = index;
-}
-
-int BbVideoDeviceSelectorControl::deviceCount() const
-{
- return m_devices.count();
-}
-
-QString BbVideoDeviceSelectorControl::deviceName(int index) const
-{
- if (index < 0 || index >= m_devices.count())
- return QString();
-
- return QString::fromUtf8(m_devices.at(index));
-}
-
-QString BbVideoDeviceSelectorControl::deviceDescription(int index) const
-{
- if (index < 0 || index >= m_descriptions.count())
- return QString();
-
- return m_descriptions.at(index);
-}
-
-int BbVideoDeviceSelectorControl::defaultDevice() const
-{
- return m_default;
-}
-
-int BbVideoDeviceSelectorControl::selectedDevice() const
-{
- return m_selected;
-}
-
-void BbVideoDeviceSelectorControl::enumerateDevices(QList<QByteArray> *devices, QStringList *descriptions)
-{
- devices->clear();
- descriptions->clear();
-
- camera_unit_t cameras[10];
-
- unsigned int knownCameras = 0;
- const camera_error_t result = camera_get_supported_cameras(10, &knownCameras, cameras);
- if (result != CAMERA_EOK) {
- qWarning() << "Unable to retrieve supported camera types:" << result;
- return;
- }
-
- for (unsigned int i = 0; i < knownCameras; ++i) {
- switch (cameras[i]) {
- case CAMERA_UNIT_FRONT:
- devices->append(BbCameraSession::cameraIdentifierFront());
- descriptions->append(tr("Front Camera"));
- break;
- case CAMERA_UNIT_REAR:
- devices->append(BbCameraSession::cameraIdentifierRear());
- descriptions->append(tr("Rear Camera"));
- break;
- case CAMERA_UNIT_DESKTOP:
- devices->append(BbCameraSession::cameraIdentifierDesktop());
- descriptions->append(tr("Desktop Camera"));
- break;
- default:
- break;
- }
- }
-}
-
-void BbVideoDeviceSelectorControl::setSelectedDevice(int index)
-{
- if (index < 0 || index >= m_devices.count())
- return;
-
- if (!m_session)
- return;
-
- const QByteArray device = m_devices.at(index);
- if (device == m_session->device())
- return;
-
- m_session->setDevice(device);
- m_selected = index;
-
- emit selectedDeviceChanged(QString::fromUtf8(device));
- emit selectedDeviceChanged(index);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbvideodeviceselectorcontrol.h b/src/plugins/qnx/camera/bbvideodeviceselectorcontrol.h
deleted file mode 100644
index 08d6cbb14..000000000
--- a/src/plugins/qnx/camera/bbvideodeviceselectorcontrol.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBVIDEODEVICESELECTORCONTROL_H
-#define BBVIDEODEVICESELECTORCONTROL_H
-
-#include <qvideodeviceselectorcontrol.h>
-#include <QStringList>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbVideoDeviceSelectorControl : public QVideoDeviceSelectorControl
-{
- Q_OBJECT
-public:
- explicit BbVideoDeviceSelectorControl(BbCameraSession *session, QObject *parent = 0);
-
- int deviceCount() const override;
- QString deviceName(int index) const override;
- QString deviceDescription(int index) const override;
- int defaultDevice() const override;
- int selectedDevice() const override;
-
- static void enumerateDevices(QList<QByteArray> *devices, QStringList *descriptions);
-
-public Q_SLOTS:
- void setSelectedDevice(int index) override;
-
-private:
- BbCameraSession* m_session;
-
- QList<QByteArray> m_devices;
- QStringList m_descriptions;
-
- int m_default;
- int m_selected;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/bbvideorenderercontrol.cpp b/src/plugins/qnx/camera/bbvideorenderercontrol.cpp
deleted file mode 100644
index fd271c9de..000000000
--- a/src/plugins/qnx/camera/bbvideorenderercontrol.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "bbvideorenderercontrol.h"
-
-#include "bbcamerasession.h"
-
-QT_BEGIN_NAMESPACE
-
-BbVideoRendererControl::BbVideoRendererControl(BbCameraSession *session, QObject *parent)
- : QVideoRendererControl(parent)
- , m_session(session)
-{
-}
-
-QAbstractVideoSurface* BbVideoRendererControl::surface() const
-{
- return m_session->surface();
-}
-
-void BbVideoRendererControl::setSurface(QAbstractVideoSurface *surface)
-{
- m_session->setSurface(surface);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/camera/bbvideorenderercontrol.h b/src/plugins/qnx/camera/bbvideorenderercontrol.h
deleted file mode 100644
index 441ff369d..000000000
--- a/src/plugins/qnx/camera/bbvideorenderercontrol.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef BBVIDEORENDERERCONTROL_H
-#define BBVIDEORENDERERCONTROL_H
-
-#include <qvideorenderercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class BbCameraSession;
-
-class BbVideoRendererControl : public QVideoRendererControl
-{
- Q_OBJECT
-public:
- explicit BbVideoRendererControl(BbCameraSession *session, QObject *parent = 0);
-
- QAbstractVideoSurface *surface() const override;
- void setSurface(QAbstractVideoSurface *surface) override;
-
-private:
- BbCameraSession *m_session;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/camera/camera.pri b/src/plugins/qnx/camera/camera.pri
deleted file mode 100644
index 886351862..000000000
--- a/src/plugins/qnx/camera/camera.pri
+++ /dev/null
@@ -1,52 +0,0 @@
-INCLUDEPATH += $$PWD
-
-HEADERS += \
- $$PWD/bbcameraaudioencodersettingscontrol.h \
- $$PWD/bbcameracapturebufferformatcontrol.h \
- $$PWD/bbcameracapturedestinationcontrol.h \
- $$PWD/bbcameracontrol.h \
- $$PWD/bbcameraexposurecontrol.h \
- $$PWD/bbcameraflashcontrol.h \
- $$PWD/bbcamerafocuscontrol.h \
- $$PWD/bbcameraimagecapturecontrol.h \
- $$PWD/bbcameraimageprocessingcontrol.h \
- $$PWD/bbcamerainfocontrol.h \
- $$PWD/bbcameralockscontrol.h \
- $$PWD/bbcameramediarecordercontrol.h \
- $$PWD/bbcameraorientationhandler.h \
- $$PWD/bbcameraservice.h \
- $$PWD/bbcamerasession.h \
- $$PWD/bbcameravideoencodersettingscontrol.h \
- $$PWD/bbcameraviewfindersettingscontrol.h \
- $$PWD/bbcamerazoomcontrol.h \
- $$PWD/bbimageencodercontrol.h \
- $$PWD/bbmediastoragelocation.h \
- $$PWD/bbvideodeviceselectorcontrol.h \
- $$PWD/bbvideorenderercontrol.h
-
-SOURCES += \
- $$PWD/bbcameraaudioencodersettingscontrol.cpp \
- $$PWD/bbcameracapturebufferformatcontrol.cpp \
- $$PWD/bbcameracapturedestinationcontrol.cpp \
- $$PWD/bbcameracontrol.cpp \
- $$PWD/bbcameraexposurecontrol.cpp \
- $$PWD/bbcameraflashcontrol.cpp \
- $$PWD/bbcamerafocuscontrol.cpp \
- $$PWD/bbcameraimagecapturecontrol.cpp \
- $$PWD/bbcameraimageprocessingcontrol.cpp \
- $$PWD/bbcamerainfocontrol.cpp \
- $$PWD/bbcameralockscontrol.cpp \
- $$PWD/bbcameramediarecordercontrol.cpp \
- $$PWD/bbcameraorientationhandler.cpp \
- $$PWD/bbcameraservice.cpp \
- $$PWD/bbcamerasession.cpp \
- $$PWD/bbcameravideoencodersettingscontrol.cpp \
- $$PWD/bbcameraviewfindersettingscontrol.cpp \
- $$PWD/bbcamerazoomcontrol.cpp \
- $$PWD/bbimageencodercontrol.cpp \
- $$PWD/bbmediastoragelocation.cpp \
- $$PWD/bbvideodeviceselectorcontrol.cpp \
- $$PWD/bbvideorenderercontrol.cpp
-
-LIBS += -lcamapi -laudio_manager
-
diff --git a/src/plugins/qnx/common/common.pri b/src/plugins/qnx/common/common.pri
deleted file mode 100644
index 1a6693474..000000000
--- a/src/plugins/qnx/common/common.pri
+++ /dev/null
@@ -1,7 +0,0 @@
-INCLUDEPATH += $$PWD
-
-HEADERS += \
- $$PWD/windowgrabber.h
-
-SOURCES += \
- $$PWD/windowgrabber.cpp
diff --git a/src/plugins/qnx/common/windowgrabber.cpp b/src/plugins/qnx/common/windowgrabber.cpp
deleted file mode 100644
index 65037fcce..000000000
--- a/src/plugins/qnx/common/windowgrabber.cpp
+++ /dev/null
@@ -1,419 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "windowgrabber.h"
-
-#include <QAbstractEventDispatcher>
-#include <QDebug>
-#include <QGuiApplication>
-#include <QImage>
-#include <QThread>
-#include <qpa/qplatformnativeinterface.h>
-
-#include <QOpenGLContext>
-#include <QOpenGLFunctions>
-
-#include <errno.h>
-
-QT_BEGIN_NAMESPACE
-
-static PFNEGLCREATEIMAGEKHRPROC s_eglCreateImageKHR;
-static PFNEGLDESTROYIMAGEKHRPROC s_eglDestroyImageKHR;
-
-WindowGrabber::WindowGrabber(QObject *parent)
- : QObject(parent),
- m_windowParent(nullptr),
- m_screenContext(0),
- m_active(false),
- m_currentFrame(0),
- m_eglImageSupported(false),
- m_eglImageCheck(false)
-{
- // grab the window frame with 60 frames per second
- m_timer.setInterval(1000/60);
-
- connect(&m_timer, SIGNAL(timeout()), SLOT(triggerUpdate()));
-
- QCoreApplication::eventDispatcher()->installNativeEventFilter(this);
-
- for ( int i = 0; i < 2; ++i )
- m_images[i] = 0;
-
- // Use of EGL images can be disabled by setting QQNX_MM_DISABLE_EGLIMAGE_SUPPORT to something
- // non-zero. This is probably useful only to test that this path still works since it results
- // in a high CPU load.
- if (!s_eglCreateImageKHR && qgetenv("QQNX_MM_DISABLE_EGLIMAGE_SUPPORT").toInt() == 0) {
- s_eglCreateImageKHR = reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(eglGetProcAddress("eglCreateImageKHR"));
- s_eglDestroyImageKHR = reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(eglGetProcAddress("eglDestroyImageKHR"));
- }
-
- QPlatformNativeInterface *const nativeInterface = QGuiApplication::platformNativeInterface();
- if (nativeInterface) {
- m_screenContext = static_cast<screen_context_t>(
- nativeInterface->nativeResourceForIntegration("screenContext"));
- }
-
- // Create a parent window for the window whose content will be grabbed. Since the
- // window is only a buffer conduit, the characteristics of the parent window are
- // irrelevant. The contents of the window can be grabbed so long as the window
- // joins the parent window's group and the parent window is in this process.
- // Using the window that displays this content isn't possible because there's no
- // way to reliably retrieve it from this code or any calling code.
- screen_create_window(&m_windowParent, m_screenContext);
- screen_create_window_group(m_windowParent, nullptr);
-}
-
-WindowGrabber::~WindowGrabber()
-{
- screen_destroy_window(m_windowParent);
- QCoreApplication::eventDispatcher()->removeNativeEventFilter(this);
- cleanup();
-}
-
-void WindowGrabber::setFrameRate(int frameRate)
-{
- m_timer.setInterval(1000/frameRate);
-}
-
-
-void WindowGrabber::setWindowId(const QByteArray &windowId)
-{
- m_windowId = windowId;
-}
-
-void WindowGrabber::start()
-{
- if (m_active)
- return;
-
- if (!m_screenContext)
- screen_get_window_property_pv(m_window, SCREEN_PROPERTY_CONTEXT, reinterpret_cast<void**>(&m_screenContext));
-
- m_timer.start();
-
- m_active = true;
-}
-
-void WindowGrabber::stop()
-{
- if (!m_active)
- return;
-
- cleanup();
-
- m_timer.stop();
-
- m_active = false;
-}
-
-void WindowGrabber::pause()
-{
- m_timer.stop();
-}
-
-void WindowGrabber::resume()
-{
- if (!m_active)
- return;
-
- m_timer.start();
-}
-
-bool WindowGrabber::handleScreenEvent(screen_event_t screen_event)
-{
-
- int eventType;
- if (screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &eventType) != 0) {
- qWarning() << "WindowGrabber: Failed to query screen event type";
- return false;
- }
-
- if (eventType != SCREEN_EVENT_CREATE)
- return false;
-
- screen_window_t window = 0;
- if (screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&window) != 0) {
- qWarning() << "WindowGrabber: Failed to query window property";
- return false;
- }
-
- const int maxIdStrLength = 128;
- char idString[maxIdStrLength];
- if (screen_get_window_property_cv(window, SCREEN_PROPERTY_ID_STRING, maxIdStrLength, idString) != 0) {
- qWarning() << "WindowGrabber: Failed to query window ID string";
- return false;
- }
-
- // Grab windows that have a non-empty ID string and a matching window id to grab
- if (idString[0] != '\0' && m_windowId == idString) {
- m_window = window;
- start();
- }
-
- return false;
-}
-
-bool WindowGrabber::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *)
-{
- if (eventType == "screen_event_t") {
- const screen_event_t event = static_cast<screen_event_t>(message);
- return handleScreenEvent(event);
- }
-
- return false;
-}
-
-QByteArray WindowGrabber::windowGroupId() const
-{
- char groupName[256];
- memset(groupName, 0, sizeof(groupName));
- screen_get_window_property_cv(m_windowParent,
- SCREEN_PROPERTY_GROUP,
- sizeof(groupName) - 1,
- groupName);
- return QByteArray(groupName);
-}
-
-bool WindowGrabber::eglImageSupported()
-{
- return m_eglImageSupported;
-}
-
-void WindowGrabber::checkForEglImageExtension()
-{
- QOpenGLContext *m_context = QOpenGLContext::currentContext();
- if (!m_context) //Should not happen, because we are called from the render thread
- return;
-
- QByteArray eglExtensions = QByteArray(eglQueryString(eglGetDisplay(EGL_DEFAULT_DISPLAY),
- EGL_EXTENSIONS));
- m_eglImageSupported = m_context->hasExtension(QByteArrayLiteral("GL_OES_EGL_image"))
- && eglExtensions.contains(QByteArrayLiteral("EGL_KHR_image"))
- && s_eglCreateImageKHR && s_eglDestroyImageKHR;
-
- if (strstr(reinterpret_cast<const char*>(glGetString(GL_VENDOR)), "VMware"))
- m_eglImageSupported = false;
-
- m_eglImageCheck = true;
-}
-
-void WindowGrabber::triggerUpdate()
-{
- if (!m_eglImageCheck) // We did not check for egl images yet
- return;
-
- int size[2] = { 0, 0 };
-
- int result = screen_get_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, size);
- if (result != 0) {
- cleanup();
- qWarning() << "WindowGrabber: cannot get window size:" << strerror(errno);
- return;
- }
-
- if (m_size.width() != size[0] || m_size.height() != size[1])
- m_size = QSize(size[0], size[1]);
-
- emit updateScene(m_size);
-}
-
-bool WindowGrabber::selectBuffer()
-{
- // If we're using egl images we need to double buffer since the gpu may still be using the last
- // video frame. If we're not, it doesn't matter since the data is immediately copied.
- if (eglImageSupported())
- m_currentFrame = (m_currentFrame + 1) % 2;
-
- if (!m_images[m_currentFrame]) {
- m_images[m_currentFrame] = new WindowGrabberImage();
- if (!m_images[m_currentFrame]->initialize(m_screenContext)) {
- delete m_images[m_currentFrame];
- m_images[m_currentFrame] = 0;
- return false;
- }
- }
- return true;
-}
-
-int WindowGrabber::getNextTextureId()
-{
- if (!selectBuffer())
- return 0;
- return m_images[m_currentFrame]->getTexture(m_window, m_size);
-}
-
-QImage WindowGrabber::getNextImage()
-{
- if (!selectBuffer())
- return QImage();
-
- return m_images[m_currentFrame]->getImage(m_window, m_size);
-}
-
-void WindowGrabber::cleanup()
-{
- for ( int i = 0; i < 2; ++i ) {
- if (m_images[i]) {
- m_images[i]->destroy();
- m_images[i] = 0;
- }
- }
-}
-
-
-WindowGrabberImage::WindowGrabberImage()
- : m_pixmap(0), m_pixmapBuffer(0), m_eglImage(0), m_glTexture(0), m_bufferAddress(0), m_bufferStride(0)
-{
-}
-
-WindowGrabberImage::~WindowGrabberImage()
-{
- if (m_glTexture)
- glDeleteTextures(1, &m_glTexture);
- if (m_eglImage)
- s_eglDestroyImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), m_eglImage);
- if (m_pixmap)
- screen_destroy_pixmap(m_pixmap);
-}
-
-bool
-WindowGrabberImage::initialize(screen_context_t screenContext)
-{
- if (screen_create_pixmap(&m_pixmap, screenContext) != 0) {
- qWarning() << "WindowGrabber: cannot create pixmap:" << strerror(errno);
- return false;
- }
- const int usage = SCREEN_USAGE_WRITE | SCREEN_USAGE_READ | SCREEN_USAGE_NATIVE;
- screen_set_pixmap_property_iv(m_pixmap, SCREEN_PROPERTY_USAGE, &usage);
-
- const int format = SCREEN_FORMAT_RGBX8888;
- screen_set_pixmap_property_iv(m_pixmap, SCREEN_PROPERTY_FORMAT, &format);
-
- return true;
-}
-
-void
-WindowGrabberImage::destroy()
-{
- // We want to delete in the thread we were created in since we need the thread that
- // has called eglMakeCurrent on the right EGL context. This doesn't actually guarantee
- // this but that would be hard to achieve and in practice it works.
- if (QThread::currentThread() == thread())
- delete this;
- else
- deleteLater();
-}
-
-bool
-WindowGrabberImage::resize(const QSize &newSize)
-{
- if (m_pixmapBuffer) {
- screen_destroy_pixmap_buffer(m_pixmap);
- m_pixmapBuffer = 0;
- m_bufferAddress = 0;
- m_bufferStride = 0;
- }
-
- int size[2] = { newSize.width(), newSize.height() };
-
- screen_set_pixmap_property_iv(m_pixmap, SCREEN_PROPERTY_BUFFER_SIZE, size);
-
- if (screen_create_pixmap_buffer(m_pixmap) == 0) {
- screen_get_pixmap_property_pv(m_pixmap, SCREEN_PROPERTY_RENDER_BUFFERS,
- reinterpret_cast<void**>(&m_pixmapBuffer));
- screen_get_buffer_property_pv(m_pixmapBuffer, SCREEN_PROPERTY_POINTER,
- reinterpret_cast<void**>(&m_bufferAddress));
- screen_get_buffer_property_iv(m_pixmapBuffer, SCREEN_PROPERTY_STRIDE, &m_bufferStride);
- m_size = newSize;
-
- return true;
- } else {
- m_size = QSize();
- return false;
- }
-}
-
-bool
-WindowGrabberImage::grab(screen_window_t window)
-{
- const int rect[] = { 0, 0, m_size.width(), m_size.height() };
- return screen_read_window(window, m_pixmapBuffer, 1, rect, 0) == 0;
-}
-
-QImage
-WindowGrabberImage::getImage(screen_window_t window, const QSize &size)
-{
- if (size != m_size) {
- if (!resize(size))
- return QImage();
- }
- if (!m_bufferAddress || !grab(window))
- return QImage();
-
- return QImage(m_bufferAddress, m_size.width(), m_size.height(), m_bufferStride, QImage::Format_ARGB32);
-}
-
-GLuint
-WindowGrabberImage::getTexture(screen_window_t window, const QSize &size)
-{
- if (size != m_size) {
- if (!m_glTexture)
- glGenTextures(1, &m_glTexture);
- glBindTexture(GL_TEXTURE_2D, m_glTexture);
- if (m_eglImage) {
- glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, 0);
- s_eglDestroyImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), m_eglImage);
- m_eglImage = 0;
- }
- if (!resize(size))
- return 0;
- m_eglImage = s_eglCreateImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), EGL_NO_CONTEXT,
- EGL_NATIVE_PIXMAP_KHR, m_pixmap, 0);
- glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_eglImage);
- }
-
- if (!m_pixmap || !grab(window))
- return 0;
-
- return m_glTexture;
-}
-
-
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/common/windowgrabber.h b/src/plugins/qnx/common/windowgrabber.h
deleted file mode 100644
index c4c1f6a53..000000000
--- a/src/plugins/qnx/common/windowgrabber.h
+++ /dev/null
@@ -1,144 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef WINDOWGRABBER_H
-#define WINDOWGRABBER_H
-
-#define EGL_EGLEXT_PROTOTYPES
-#define GL_GLEXT_PROTOTYPES
-#include <EGL/egl.h>
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-#include <EGL/eglext.h>
-#include <QAbstractNativeEventFilter>
-#include <QObject>
-#include <QSize>
-#include <QTimer>
-
-#include <screen/screen.h>
-
-QT_BEGIN_NAMESPACE
-
-class WindowGrabberImage : public QObject
-{
- Q_OBJECT
-
-public:
- WindowGrabberImage();
- ~WindowGrabberImage();
-
- bool initialize(screen_context_t screenContext);
-
- void destroy();
-
- QImage getImage(screen_window_t window, const QSize &size);
- GLuint getTexture(screen_window_t window, const QSize &size);
-
-private:
- bool grab(screen_window_t window);
- bool resize(const QSize &size);
-
- QSize m_size;
- screen_pixmap_t m_pixmap;
- screen_buffer_t m_pixmapBuffer;
- EGLImageKHR m_eglImage;
- GLuint m_glTexture;
- unsigned char *m_bufferAddress;
- int m_bufferStride;
-};
-
-class WindowGrabber : public QObject, public QAbstractNativeEventFilter
-{
- Q_OBJECT
-
-public:
- explicit WindowGrabber(QObject *parent = 0);
- ~WindowGrabber();
-
- void setFrameRate(int frameRate);
-
- void setWindowId(const QByteArray &windowId);
-
- void start();
- void stop();
-
- void pause();
- void resume();
-
- bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
-
- bool handleScreenEvent(screen_event_t event);
-
- QByteArray windowGroupId() const;
-
- bool eglImageSupported();
- void checkForEglImageExtension();
-
- int getNextTextureId();
- QImage getNextImage();
-
-signals:
- void updateScene(const QSize &size);
-
-private slots:
- void triggerUpdate();
-
-private:
- bool selectBuffer();
- void cleanup();
-
- QTimer m_timer;
-
- QByteArray m_windowId;
-
- screen_window_t m_windowParent;
- screen_window_t m_window;
- screen_context_t m_screenContext;
-
- WindowGrabberImage *m_images[2];
- QSize m_size;
-
- bool m_active;
- int m_currentFrame;
- bool m_eglImageSupported;
- bool m_eglImageCheck; // We must not send a grabed frame before this is true
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/mediaplayer/mediaplayer.pri b/src/plugins/qnx/mediaplayer/mediaplayer.pri
deleted file mode 100644
index f39b542cc..000000000
--- a/src/plugins/qnx/mediaplayer/mediaplayer.pri
+++ /dev/null
@@ -1,28 +0,0 @@
-INCLUDEPATH += $$PWD
-
-HEADERS += \
- $$PWD/mmrendereraudiorolecontrol.h \
- $$PWD/mmrenderermediaplayercontrol.h \
- $$PWD/mmrenderermediaplayerservice.h \
- $$PWD/mmrenderermetadata.h \
- $$PWD/mmrenderermetadatareadercontrol.h \
- $$PWD/mmrendererplayervideorenderercontrol.h \
- $$PWD/mmrendererutil.h \
- $$PWD/mmrenderervideowindowcontrol.h \
- $$PWD/mmreventmediaplayercontrol.h \
- $$PWD/mmreventthread.h \
- $$PWD/mmrenderercustomaudiorolecontrol.h
-SOURCES += \
- $$PWD/mmrendereraudiorolecontrol.cpp \
- $$PWD/mmrenderermediaplayercontrol.cpp \
- $$PWD/mmrenderermediaplayerservice.cpp \
- $$PWD/mmrenderermetadata.cpp \
- $$PWD/mmrenderermetadatareadercontrol.cpp \
- $$PWD/mmrendererplayervideorenderercontrol.cpp \
- $$PWD/mmrendererutil.cpp \
- $$PWD/mmrenderervideowindowcontrol.cpp \
- $$PWD/mmreventmediaplayercontrol.cpp \
- $$PWD/mmreventthread.cpp \
- $$PWD/mmrenderercustomaudiorolecontrol.cpp
-
-QMAKE_USE += mmrenderer
diff --git a/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.cpp b/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.cpp
deleted file mode 100644
index e470ed4c5..000000000
--- a/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 QNX Software Systems. All rights reserved.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "mmrendereraudiorolecontrol.h"
-#include "mmrendererutil.h"
-
-QT_BEGIN_NAMESPACE
-
-MmRendererAudioRoleControl::MmRendererAudioRoleControl(QObject *parent)
- : QAudioRoleControl(parent)
- , m_role(QAudio::UnknownRole)
-{
-}
-
-QAudio::Role MmRendererAudioRoleControl::audioRole() const
-{
- return m_role;
-}
-
-void MmRendererAudioRoleControl::setAudioRole(QAudio::Role role)
-{
- if (m_role != role) {
- m_role = role;
- emit audioRoleChanged(m_role);
- }
-}
-
-QList<QAudio::Role> MmRendererAudioRoleControl::supportedAudioRoles() const
-{
- return qnxSupportedAudioRoles();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.h b/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.h
deleted file mode 100644
index d0d2165eb..000000000
--- a/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 QNX Software Systems. All rights reserved.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef MMRENDERERAUDIOROLECONTROL_H
-#define MMRENDERERAUDIOROLECONTROL_H
-
-#include <qaudiorolecontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class MmRendererAudioRoleControl : public QAudioRoleControl
-{
- Q_OBJECT
-public:
- explicit MmRendererAudioRoleControl(QObject *parent = 0);
-
- QAudio::Role audioRole() const override;
- void setAudioRole(QAudio::Role role) override;
-
- QList<QAudio::Role> supportedAudioRoles() const override;
-
-private:
- QAudio::Role m_role;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/mediaplayer/mmrenderercustomaudiorolecontrol.cpp b/src/plugins/qnx/mediaplayer/mmrenderercustomaudiorolecontrol.cpp
deleted file mode 100644
index c8971d41c..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderercustomaudiorolecontrol.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 QNX Software Systems. All rights reserved.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "mmrenderercustomaudiorolecontrol.h"
-#include "mmrendererutil.h"
-
-QT_BEGIN_NAMESPACE
-
-MmRendererCustomAudioRoleControl::MmRendererCustomAudioRoleControl(QObject *parent)
- : QCustomAudioRoleControl(parent)
-{
-}
-
-QString MmRendererCustomAudioRoleControl::customAudioRole() const
-{
- return m_role;
-}
-
-void MmRendererCustomAudioRoleControl::setCustomAudioRole(const QString &role)
-{
- if (m_role != role) {
- m_role = role;
- emit customAudioRoleChanged(m_role);
- }
-}
-
-QStringList MmRendererCustomAudioRoleControl::supportedCustomAudioRoles() const
-{
- return QStringList();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrenderercustomaudiorolecontrol.h b/src/plugins/qnx/mediaplayer/mmrenderercustomaudiorolecontrol.h
deleted file mode 100644
index ff16f9355..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderercustomaudiorolecontrol.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 QNX Software Systems. All rights reserved.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef MMRENDERERCUSTOMAUDIOROLECONTROL_H
-#define MMRENDERERCUSTOMAUDIOROLECONTROL_H
-
-#include <qcustomaudiorolecontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class MmRendererCustomAudioRoleControl : public QCustomAudioRoleControl
-{
- Q_OBJECT
-public:
- explicit MmRendererCustomAudioRoleControl(QObject *parent = 0);
-
- QString customAudioRole() const Q_DECL_OVERRIDE;
- void setCustomAudioRole(const QString &role) Q_DECL_OVERRIDE;
-
- QStringList supportedCustomAudioRoles() const Q_DECL_OVERRIDE;
-
-private:
- QString m_role;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.cpp b/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.cpp
deleted file mode 100644
index fc48ed818..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.cpp
+++ /dev/null
@@ -1,653 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "mmrendereraudiorolecontrol.h"
-#include "mmrenderercustomaudiorolecontrol.h"
-#include "mmrenderermediaplayercontrol.h"
-#include "mmrenderermetadatareadercontrol.h"
-#include "mmrendererplayervideorenderercontrol.h"
-#include "mmrendererutil.h"
-#include "mmrenderervideowindowcontrol.h"
-#include <QtCore/qabstracteventdispatcher.h>
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qdir.h>
-#include <QtCore/qfileinfo.h>
-#include <QtCore/quuid.h>
-#include <mm/renderer.h>
-
-#include <errno.h>
-#include <sys/strm.h>
-#include <sys/stat.h>
-
-QT_BEGIN_NAMESPACE
-
-static int idCounter = 0;
-
-MmRendererMediaPlayerControl::MmRendererMediaPlayerControl(QObject *parent)
- : QMediaPlayerControl(parent),
- m_context(0),
- m_id(-1),
- m_connection(0),
- m_audioId(-1),
- m_state(QMediaPlayer::StoppedState),
- m_volume(100),
- m_muted(false),
- m_rate(1),
- m_position(0),
- m_mediaStatus(QMediaPlayer::NoMedia),
- m_playAfterMediaLoaded(false),
- m_inputAttached(false),
- m_bufferLevel(0)
-{
- m_loadingTimer.setSingleShot(true);
- m_loadingTimer.setInterval(0);
- connect(&m_loadingTimer, SIGNAL(timeout()), this, SLOT(continueLoadMedia()));
- QCoreApplication::eventDispatcher()->installNativeEventFilter(this);
-}
-
-void MmRendererMediaPlayerControl::destroy()
-{
- stop();
- detach();
- closeConnection();
- QCoreApplication::eventDispatcher()->removeNativeEventFilter(this);
-}
-
-void MmRendererMediaPlayerControl::openConnection()
-{
- m_connection = mmr_connect(NULL);
- if (!m_connection) {
- emitPError("Unable to connect to the multimedia renderer");
- return;
- }
-
- m_id = idCounter++;
- m_contextName = QString("MmRendererMediaPlayerControl_%1_%2").arg(m_id)
- .arg(QCoreApplication::applicationPid());
- m_context = mmr_context_create(m_connection, m_contextName.toLatin1(),
- 0, S_IRWXU|S_IRWXG|S_IRWXO);
- if (!m_context) {
- emitPError("Unable to create context");
- closeConnection();
- return;
- }
-
- startMonitoring();
-}
-
-void MmRendererMediaPlayerControl::handleMmStopped()
-{
- // Only react to stop events that happen when the end of the stream is reached and
- // playback is stopped because of this.
- // Ignore other stop event sources, such as calling mmr_stop() ourselves.
- if (m_state != QMediaPlayer::StoppedState) {
- setMediaStatus(QMediaPlayer::EndOfMedia);
- stopInternal(IgnoreMmRenderer);
- }
-}
-
-void MmRendererMediaPlayerControl::handleMmSuspend(const QString &reason)
-{
- if (m_state == QMediaPlayer::StoppedState)
- return;
-
- Q_UNUSED(reason);
- setMediaStatus(QMediaPlayer::StalledMedia);
-}
-
-void MmRendererMediaPlayerControl::handleMmSuspendRemoval(const QString &bufferStatus)
-{
- if (m_state == QMediaPlayer::StoppedState)
- return;
-
- if (bufferStatus == QLatin1String("buffering"))
- setMediaStatus(QMediaPlayer::BufferingMedia);
- else
- setMediaStatus(QMediaPlayer::BufferedMedia);
-}
-
-void MmRendererMediaPlayerControl::handleMmPause()
-{
- if (m_state == QMediaPlayer::PlayingState) {
- setState(QMediaPlayer::PausedState);
- }
-}
-
-void MmRendererMediaPlayerControl::handleMmPlay()
-{
- if (m_state == QMediaPlayer::PausedState) {
- setState(QMediaPlayer::PlayingState);
- }
-}
-
-void MmRendererMediaPlayerControl::closeConnection()
-{
- stopMonitoring();
-
- if (m_context) {
- mmr_context_destroy(m_context);
- m_context = 0;
- m_contextName.clear();
- }
-
- if (m_connection) {
- mmr_disconnect(m_connection);
- m_connection = 0;
- }
-}
-
-QByteArray MmRendererMediaPlayerControl::resourcePathForUrl(const QUrl &url)
-{
- // If this is a local file, mmrenderer expects the file:// prefix and an absolute path.
- // We treat URLs without scheme as local files, most likely someone just forgot to set the
- // file:// prefix when constructing the URL.
- if (url.isLocalFile() || url.scheme().isEmpty()) {
- QString relativeFilePath;
- if (!url.scheme().isEmpty())
- relativeFilePath = url.toLocalFile();
- else
- relativeFilePath = url.path();
- const QFileInfo fileInfo(relativeFilePath);
- return QFile::encodeName(QStringLiteral("file://") + fileInfo.absoluteFilePath());
-
- // HTTP or similar URL
- } else {
- return url.toEncoded();
- }
-}
-
-void MmRendererMediaPlayerControl::attach()
-{
- // Should only be called in detached state
- Q_ASSERT(m_audioId == -1 && !m_inputAttached);
-
- if (m_media.isNull() || !m_context) {
- setMediaStatus(QMediaPlayer::NoMedia);
- return;
- }
-
- resetMonitoring();
-
- if (m_videoRendererControl)
- m_videoRendererControl->attachDisplay(m_context);
-
- if (m_videoWindowControl)
- m_videoWindowControl->attachDisplay(m_context);
-
- const QByteArray defaultAudioDevice = qgetenv("QQNX_RENDERER_DEFAULT_AUDIO_SINK");
- m_audioId = mmr_output_attach(m_context, defaultAudioDevice.isEmpty() ? "audio:default" : defaultAudioDevice.constData(), "audio");
- if (m_audioId == -1) {
- emitMmError("mmr_output_attach() for audio failed");
- return;
- }
-
- if (m_audioId != -1 && m_audioRoleControl) {
- QAudio::Role audioRole = m_audioRoleControl->audioRole();
- QString audioType = (audioRole == QAudio::CustomRole && m_customAudioRoleControl)
- ? m_customAudioRoleControl->customAudioRole()
- : qnxAudioType(audioRole);
- QByteArray latin1AudioType = audioType.toLatin1();
- if (!audioType.isEmpty() && latin1AudioType == audioType) {
- strm_dict_t *dict = strm_dict_new();
- dict = strm_dict_set(dict, "audio_type", latin1AudioType.constData());
- if (mmr_output_parameters(m_context, m_audioId, dict) != 0)
- emitMmError("mmr_output_parameters: Setting audio_type failed");
- }
- }
-
- const QByteArray resourcePath = resourcePathForUrl(m_media.request().url());
- if (resourcePath.isEmpty()) {
- detach();
- return;
- }
-
- if (mmr_input_attach(m_context, resourcePath.constData(), "track") != 0) {
- emitMmError(QStringLiteral("mmr_input_attach() failed for ") + QString(resourcePath));
- setMediaStatus(QMediaPlayer::InvalidMedia);
- detach();
- return;
- }
-
- m_inputAttached = true;
- setMediaStatus(QMediaPlayer::LoadedMedia);
-
- // mm-renderer has buffer properties "status" and "level"
- // QMediaPlayer's buffer status maps to mm-renderer's buffer level
- m_bufferLevel = 0;
- emit bufferStatusChanged(m_bufferLevel);
-}
-
-void MmRendererMediaPlayerControl::detach()
-{
- if (m_context) {
- if (m_inputAttached) {
- mmr_input_detach(m_context);
- m_inputAttached = false;
- }
- if (m_videoRendererControl)
- m_videoRendererControl->detachDisplay();
- if (m_videoWindowControl)
- m_videoWindowControl->detachDisplay();
- if (m_audioId != -1 && m_context) {
- mmr_output_detach(m_context, m_audioId);
- m_audioId = -1;
- }
- }
-
- m_loadingTimer.stop();
-}
-
-QMediaPlayer::State MmRendererMediaPlayerControl::state() const
-{
- return m_state;
-}
-
-QMediaPlayer::MediaStatus MmRendererMediaPlayerControl::mediaStatus() const
-{
- return m_mediaStatus;
-}
-
-qint64 MmRendererMediaPlayerControl::duration() const
-{
- return m_metaData.duration();
-}
-
-qint64 MmRendererMediaPlayerControl::position() const
-{
- return m_position;
-}
-
-void MmRendererMediaPlayerControl::setPosition(qint64 position)
-{
- if (m_position != position) {
- m_position = position;
-
- // Don't update in stopped state, it would not have any effect. Instead, the position is
- // updated in play().
- if (m_state != QMediaPlayer::StoppedState)
- setPositionInternal(m_position);
-
- emit positionChanged(m_position);
- }
-}
-
-int MmRendererMediaPlayerControl::volume() const
-{
- return m_volume;
-}
-
-void MmRendererMediaPlayerControl::setVolumeInternal(int newVolume)
-{
- if (!m_context)
- return;
-
- newVolume = qBound(0, newVolume, 100);
- if (m_audioId != -1) {
- strm_dict_t * dict = strm_dict_new();
- dict = strm_dict_set(dict, "volume", QString::number(newVolume).toLatin1());
- if (mmr_output_parameters(m_context, m_audioId, dict) != 0)
- emitMmError("mmr_output_parameters: Setting volume failed");
- }
-}
-
-void MmRendererMediaPlayerControl::setPlaybackRateInternal(qreal rate)
-{
- if (!m_context)
- return;
-
- const int mmRate = rate * 1000;
- if (mmr_speed_set(m_context, mmRate) != 0)
- emitMmError("mmr_speed_set failed");
-}
-
-void MmRendererMediaPlayerControl::setPositionInternal(qint64 position)
-{
- if (!m_context)
- return;
-
- if (m_metaData.isSeekable()) {
- if (mmr_seek(m_context, QString::number(position).toLatin1()) != 0)
- emitMmError("Seeking failed");
- }
-}
-
-void MmRendererMediaPlayerControl::setMediaStatus(QMediaPlayer::MediaStatus status)
-{
- if (m_mediaStatus != status) {
- m_mediaStatus = status;
- emit mediaStatusChanged(m_mediaStatus);
- }
-}
-
-void MmRendererMediaPlayerControl::setState(QMediaPlayer::State state)
-{
- if (m_state != state) {
- if (m_videoRendererControl) {
- if (state == QMediaPlayer::PausedState || state == QMediaPlayer::StoppedState) {
- m_videoRendererControl->pause();
- } else if ((state == QMediaPlayer::PlayingState)
- && (m_state == QMediaPlayer::PausedState
- || m_state == QMediaPlayer::StoppedState)) {
- m_videoRendererControl->resume();
- }
- }
-
- m_state = state;
- emit stateChanged(m_state);
- }
-}
-
-void MmRendererMediaPlayerControl::stopInternal(StopCommand stopCommand)
-{
- resetMonitoring();
- setPosition(0);
-
- if (m_state != QMediaPlayer::StoppedState) {
-
- if (stopCommand == StopMmRenderer) {
- mmr_stop(m_context);
- }
-
- setState(QMediaPlayer::StoppedState);
- }
-}
-
-void MmRendererMediaPlayerControl::setVolume(int volume)
-{
- const int newVolume = qBound(0, volume, 100);
- if (m_volume != newVolume) {
- m_volume = newVolume;
- if (!m_muted)
- setVolumeInternal(m_volume);
- emit volumeChanged(m_volume);
- }
-}
-
-bool MmRendererMediaPlayerControl::isMuted() const
-{
- return m_muted;
-}
-
-void MmRendererMediaPlayerControl::setMuted(bool muted)
-{
- if (m_muted != muted) {
- m_muted = muted;
- setVolumeInternal(muted ? 0 : m_volume);
- emit mutedChanged(muted);
- }
-}
-
-int MmRendererMediaPlayerControl::bufferStatus() const
-{
- // mm-renderer has buffer properties "status" and "level"
- // QMediaPlayer's buffer status maps to mm-renderer's buffer level
- return m_bufferLevel;
-}
-
-bool MmRendererMediaPlayerControl::isAudioAvailable() const
-{
- return m_metaData.hasAudio();
-}
-
-bool MmRendererMediaPlayerControl::isVideoAvailable() const
-{
- return m_metaData.hasVideo();
-}
-
-bool MmRendererMediaPlayerControl::isSeekable() const
-{
- return m_metaData.isSeekable();
-}
-
-QMediaTimeRange MmRendererMediaPlayerControl::availablePlaybackRanges() const
-{
- // We can't get this information from the mmrenderer API yet, so pretend we can seek everywhere
- return QMediaTimeRange(0, m_metaData.duration());
-}
-
-qreal MmRendererMediaPlayerControl::playbackRate() const
-{
- return m_rate;
-}
-
-void MmRendererMediaPlayerControl::setPlaybackRate(qreal rate)
-{
- if (m_rate != rate) {
- m_rate = rate;
- setPlaybackRateInternal(m_rate);
- emit playbackRateChanged(m_rate);
- }
-}
-
-QMediaContent MmRendererMediaPlayerControl::media() const
-{
- return m_media;
-}
-
-const QIODevice *MmRendererMediaPlayerControl::mediaStream() const
-{
- // Always 0, we don't support QIODevice streams
- return 0;
-}
-
-void MmRendererMediaPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream)
-{
- Q_UNUSED(stream); // not supported
-
- stop();
- detach();
-
- m_media = media;
- emit mediaChanged(m_media);
-
- // Slight hack: With MediaPlayer QtQuick elements that have autoPlay set to true, playback
- // would start before the QtQuick canvas is propagated to all elements, and therefore our
- // video output would not work. Therefore, delay actually playing the media a bit so that the
- // canvas is ready.
- // The mmrenderer doesn't allow to attach video outputs after playing has started, otherwise
- // this would be unnecessary.
- if (!m_media.isNull()) {
- setMediaStatus(QMediaPlayer::LoadingMedia);
- m_loadingTimer.start(); // singleshot timer to continueLoadMedia()
- } else {
- continueLoadMedia(); // still needed, as it will update the media status and clear metadata
- }
-}
-
-void MmRendererMediaPlayerControl::continueLoadMedia()
-{
- updateMetaData(nullptr);
- attach();
- if (m_playAfterMediaLoaded)
- play();
-}
-
-MmRendererVideoWindowControl *MmRendererMediaPlayerControl::videoWindowControl() const
-{
- return m_videoWindowControl;
-}
-
-void MmRendererMediaPlayerControl::play()
-{
- if (m_playAfterMediaLoaded)
- m_playAfterMediaLoaded = false;
-
- // No-op if we are already playing, except if we were called from continueLoadMedia(), in which
- // case m_playAfterMediaLoaded is true (hence the 'else').
- else if (m_state == QMediaPlayer::PlayingState)
- return;
-
- if (m_mediaStatus == QMediaPlayer::LoadingMedia) {
-
- // State changes are supposed to be synchronous
- setState(QMediaPlayer::PlayingState);
-
- // Defer playing to later, when the timer triggers continueLoadMedia()
- m_playAfterMediaLoaded = true;
- return;
- }
-
- // Un-pause the state when it is paused
- if (m_state == QMediaPlayer::PausedState) {
- setPlaybackRateInternal(m_rate);
- setState(QMediaPlayer::PlayingState);
- return;
- }
-
- if (m_media.isNull() || !m_connection || !m_context || m_audioId == -1) {
- setState(QMediaPlayer::StoppedState);
- return;
- }
-
- if (m_mediaStatus == QMediaPlayer::EndOfMedia)
- m_position = 0;
-
- resetMonitoring();
- setPositionInternal(m_position);
- setVolumeInternal(m_muted ? 0 : m_volume);
- setPlaybackRateInternal(m_rate);
-
- if (mmr_play(m_context) != 0) {
- setState(QMediaPlayer::StoppedState);
- emitMmError("mmr_play() failed");
- return;
- }
-
- setState( QMediaPlayer::PlayingState);
-}
-
-void MmRendererMediaPlayerControl::pause()
-{
- if (m_state == QMediaPlayer::PlayingState) {
- setPlaybackRateInternal(0);
- setState(QMediaPlayer::PausedState);
- }
-}
-
-void MmRendererMediaPlayerControl::stop()
-{
- stopInternal(StopMmRenderer);
-}
-
-MmRendererPlayerVideoRendererControl *MmRendererMediaPlayerControl::videoRendererControl() const
-{
- return m_videoRendererControl;
-}
-
-void MmRendererMediaPlayerControl::setVideoRendererControl(MmRendererPlayerVideoRendererControl *videoControl)
-{
- m_videoRendererControl = videoControl;
-}
-
-void MmRendererMediaPlayerControl::setVideoWindowControl(MmRendererVideoWindowControl *videoControl)
-{
- m_videoWindowControl = videoControl;
-}
-
-void MmRendererMediaPlayerControl::setMetaDataReaderControl(MmRendererMetaDataReaderControl *metaDataReaderControl)
-{
- m_metaDataReaderControl = metaDataReaderControl;
-}
-
-void MmRendererMediaPlayerControl::setAudioRoleControl(MmRendererAudioRoleControl *audioRoleControl)
-{
- m_audioRoleControl = audioRoleControl;
-}
-
-void MmRendererMediaPlayerControl::setCustomAudioRoleControl(MmRendererCustomAudioRoleControl *customAudioRoleControl)
-{
- m_customAudioRoleControl = customAudioRoleControl;
-}
-
-void MmRendererMediaPlayerControl::setMmPosition(qint64 newPosition)
-{
- if (newPosition != 0 && newPosition != m_position) {
- m_position = newPosition;
- emit positionChanged(m_position);
- }
-}
-
-void MmRendererMediaPlayerControl::setMmBufferStatus(const QString &bufferStatus)
-{
- if (bufferStatus == QLatin1String("buffering"))
- setMediaStatus(QMediaPlayer::BufferingMedia);
- else if (bufferStatus == QLatin1String("playing"))
- setMediaStatus(QMediaPlayer::BufferedMedia);
- // ignore "idle" buffer status
-}
-
-void MmRendererMediaPlayerControl::setMmBufferLevel(int level, int capacity)
-{
- m_bufferLevel = capacity == 0 ? 0 : level / static_cast<float>(capacity) * 100.0f;
- m_bufferLevel = qBound(0, m_bufferLevel, 100);
- emit bufferStatusChanged(m_bufferLevel);
-}
-
-void MmRendererMediaPlayerControl::updateMetaData(const strm_dict *dict)
-{
- m_metaData.update(dict);
-
- if (m_videoWindowControl)
- m_videoWindowControl->setMetaData(m_metaData);
-
- if (m_metaDataReaderControl)
- m_metaDataReaderControl->setMetaData(m_metaData);
-
- emit durationChanged(m_metaData.duration());
- emit audioAvailableChanged(m_metaData.hasAudio());
- emit videoAvailableChanged(m_metaData.hasVideo());
- emit availablePlaybackRangesChanged(availablePlaybackRanges());
- emit seekableChanged(m_metaData.isSeekable());
-}
-
-void MmRendererMediaPlayerControl::emitMmError(const QString &msg)
-{
- int errorCode = MMR_ERROR_NONE;
- const QString errorMessage = mmErrorMessage(msg, m_context, &errorCode);
- qDebug() << errorMessage;
- emit error(errorCode, errorMessage);
-}
-
-void MmRendererMediaPlayerControl::emitPError(const QString &msg)
-{
- const QString errorMessage = QString("%1: %2").arg(msg).arg(strerror(errno));
- qDebug() << errorMessage;
- emit error(errno, errorMessage);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.h b/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.h
deleted file mode 100644
index 3426ef2f2..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.h
+++ /dev/null
@@ -1,180 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef MMRENDERERMEDIAPLAYERCONTROL_H
-#define MMRENDERERMEDIAPLAYERCONTROL_H
-
-#include "mmrenderermetadata.h"
-#include <qmediaplayercontrol.h>
-#include <QtCore/qabstractnativeeventfilter.h>
-#include <QtCore/qpointer.h>
-#include <QtCore/qtimer.h>
-
-typedef struct mmr_connection mmr_connection_t;
-typedef struct mmr_context mmr_context_t;
-typedef struct mmrenderer_monitor mmrenderer_monitor_t;
-typedef struct strm_dict strm_dict_t;
-
-QT_BEGIN_NAMESPACE
-
-class MmRendererAudioRoleControl;
-class MmRendererCustomAudioRoleControl;
-class MmRendererMetaDataReaderControl;
-class MmRendererPlayerVideoRendererControl;
-class MmRendererVideoWindowControl;
-
-class MmRendererMediaPlayerControl : public QMediaPlayerControl, public QAbstractNativeEventFilter
-{
- Q_OBJECT
-public:
- explicit MmRendererMediaPlayerControl(QObject *parent = 0);
-
- QMediaPlayer::State state() const override;
-
- QMediaPlayer::MediaStatus mediaStatus() const override;
-
- qint64 duration() const override;
-
- qint64 position() const override;
- void setPosition(qint64 position) override;
-
- int volume() const override;
- void setVolume(int volume) override;
-
- bool isMuted() const override;
- void setMuted(bool muted) override;
-
- int bufferStatus() const override;
-
- bool isAudioAvailable() const override;
- bool isVideoAvailable() const override;
-
- bool isSeekable() const override;
-
- QMediaTimeRange availablePlaybackRanges() const override;
-
- qreal playbackRate() const override;
- void setPlaybackRate(qreal rate) override;
-
- QMediaContent media() const override;
- const QIODevice *mediaStream() const override;
- void setMedia(const QMediaContent &media, QIODevice *stream) override;
-
- void play() override;
- void pause() override;
- void stop() override;
-
- MmRendererPlayerVideoRendererControl *videoRendererControl() const;
- void setVideoRendererControl(MmRendererPlayerVideoRendererControl *videoControl);
-
- MmRendererVideoWindowControl *videoWindowControl() const;
- void setVideoWindowControl(MmRendererVideoWindowControl *videoControl);
- void setMetaDataReaderControl(MmRendererMetaDataReaderControl *metaDataReaderControl);
- void setAudioRoleControl(MmRendererAudioRoleControl *audioRoleControl);
- void setCustomAudioRoleControl(MmRendererCustomAudioRoleControl *customAudioRoleControl);
-
-protected:
- virtual void startMonitoring() = 0;
- virtual void stopMonitoring() = 0;
- virtual void resetMonitoring() = 0;
-
- void openConnection();
- void emitMmError(const QString &msg);
- void emitPError(const QString &msg);
- void setMmPosition(qint64 newPosition);
- void setMmBufferStatus(const QString &bufferStatus);
- void setMmBufferLevel(int level, int capacity);
- void handleMmStopped();
- void handleMmSuspend(const QString &reason);
- void handleMmSuspendRemoval(const QString &bufferStatus);
- void handleMmPause();
- void handleMmPlay();
- void updateMetaData(const strm_dict_t *dict);
-
- // must be called from subclass dtors (calls virtual function stopMonitoring())
- void destroy();
-
- mmr_context_t *m_context;
- int m_id;
- QString m_contextName;
-
-private Q_SLOTS:
- void continueLoadMedia();
-
-private:
- QByteArray resourcePathForUrl(const QUrl &url);
- void closeConnection();
- void attach();
- void detach();
-
- // All these set the specified value to the backend, but neither emit changed signals
- // nor change the member value.
- void setVolumeInternal(int newVolume);
- void setPlaybackRateInternal(qreal rate);
- void setPositionInternal(qint64 position);
-
- void setMediaStatus(QMediaPlayer::MediaStatus status);
- void setState(QMediaPlayer::State state);
-
- enum StopCommand { StopMmRenderer, IgnoreMmRenderer };
- void stopInternal(StopCommand stopCommand);
-
- QMediaContent m_media;
- mmr_connection_t *m_connection;
- int m_audioId;
- QMediaPlayer::State m_state;
- int m_volume;
- bool m_muted;
- qreal m_rate;
- QPointer<MmRendererPlayerVideoRendererControl> m_videoRendererControl;
- QPointer<MmRendererVideoWindowControl> m_videoWindowControl;
- QPointer<MmRendererMetaDataReaderControl> m_metaDataReaderControl;
- QPointer<MmRendererAudioRoleControl> m_audioRoleControl;
- QPointer<MmRendererCustomAudioRoleControl> m_customAudioRoleControl;
- MmRendererMetaData m_metaData;
- qint64 m_position;
- QMediaPlayer::MediaStatus m_mediaStatus;
- bool m_playAfterMediaLoaded;
- bool m_inputAttached;
- int m_bufferLevel;
- QTimer m_loadingTimer;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.cpp b/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.cpp
deleted file mode 100644
index 190cb8b80..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "mmrenderermediaplayerservice.h"
-
-#include "mmrendereraudiorolecontrol.h"
-#include "mmrenderercustomaudiorolecontrol.h"
-#include "mmrenderermediaplayercontrol.h"
-#include "mmrenderermetadatareadercontrol.h"
-#include "mmrendererplayervideorenderercontrol.h"
-#include "mmrendererutil.h"
-#include "mmrenderervideowindowcontrol.h"
-
-#include "mmreventmediaplayercontrol.h"
-
-QT_BEGIN_NAMESPACE
-
-MmRendererMediaPlayerService::MmRendererMediaPlayerService(QObject *parent)
- : QMediaService(parent),
- m_videoRendererControl(0),
- m_videoWindowControl(0),
- m_mediaPlayerControl(0),
- m_metaDataReaderControl(0),
- m_appHasDrmPermission(false),
- m_appHasDrmPermissionChecked(false)
-{
-}
-
-MmRendererMediaPlayerService::~MmRendererMediaPlayerService()
-{
- // Someone should have called releaseControl(), but better be safe
- delete m_videoRendererControl;
- delete m_videoWindowControl;
- delete m_mediaPlayerControl;
- delete m_metaDataReaderControl;
- delete m_audioRoleControl;
- delete m_customAudioRoleControl;
-}
-
-QMediaControl *MmRendererMediaPlayerService::requestControl(const char *name)
-{
- if (qstrcmp(name, QMediaPlayerControl_iid) == 0) {
- if (!m_mediaPlayerControl) {
- m_mediaPlayerControl = new MmrEventMediaPlayerControl;
- updateControls();
- }
- return m_mediaPlayerControl;
- } else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) {
- if (!m_metaDataReaderControl) {
- m_metaDataReaderControl = new MmRendererMetaDataReaderControl();
- updateControls();
- }
- return m_metaDataReaderControl;
- } else if (qstrcmp(name, QAudioRoleControl_iid) == 0) {
- if (!m_audioRoleControl) {
- m_audioRoleControl = new MmRendererAudioRoleControl();
- updateControls();
- }
- return m_audioRoleControl;
- } else if (qstrcmp(name, QCustomAudioRoleControl_iid) == 0) {
- if (!m_customAudioRoleControl) {
- m_customAudioRoleControl = new MmRendererCustomAudioRoleControl();
- updateControls();
- }
- return m_customAudioRoleControl;
- } else if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
- if (!m_appHasDrmPermissionChecked) {
- m_appHasDrmPermission = checkForDrmPermission();
- m_appHasDrmPermissionChecked = true;
- }
-
- if (m_appHasDrmPermission) {
- // When the application wants to play back DRM secured media, we can't use
- // the QVideoRendererControl, because we won't have access to the pixel data
- // in this case.
- return 0;
- }
-
- if (!m_videoRendererControl) {
- m_videoRendererControl = new MmRendererPlayerVideoRendererControl();
- updateControls();
- }
- return m_videoRendererControl;
- } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
- if (!m_videoWindowControl) {
- m_videoWindowControl = new MmRendererVideoWindowControl();
- updateControls();
- }
- return m_videoWindowControl;
- }
- return 0;
-}
-
-void MmRendererMediaPlayerService::releaseControl(QMediaControl *control)
-{
- if (control == m_videoRendererControl)
- m_videoRendererControl = 0;
- if (control == m_videoWindowControl)
- m_videoWindowControl = 0;
- if (control == m_mediaPlayerControl)
- m_mediaPlayerControl = 0;
- if (control == m_metaDataReaderControl)
- m_metaDataReaderControl = 0;
- if (control == m_audioRoleControl)
- m_audioRoleControl = 0;
- if (control == m_customAudioRoleControl)
- m_customAudioRoleControl = 0;
- delete control;
-}
-
-void MmRendererMediaPlayerService::updateControls()
-{
- if (m_videoRendererControl && m_mediaPlayerControl)
- m_mediaPlayerControl->setVideoRendererControl(m_videoRendererControl);
-
- if (m_videoWindowControl && m_mediaPlayerControl)
- m_mediaPlayerControl->setVideoWindowControl(m_videoWindowControl);
-
- if (m_metaDataReaderControl && m_mediaPlayerControl)
- m_mediaPlayerControl->setMetaDataReaderControl(m_metaDataReaderControl);
-
- if (m_audioRoleControl && m_mediaPlayerControl)
- m_mediaPlayerControl->setAudioRoleControl(m_audioRoleControl);
-
- if (m_customAudioRoleControl && m_mediaPlayerControl)
- m_mediaPlayerControl->setCustomAudioRoleControl(m_customAudioRoleControl);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.h b/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.h
deleted file mode 100644
index ab3054af5..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef MMRENDERERMEDIAPLAYERSERVICE_H
-#define MMRENDERERMEDIAPLAYERSERVICE_H
-
-#include <qmediaservice.h>
-#include <QtCore/qpointer.h>
-
-QT_BEGIN_NAMESPACE
-
-class MmRendererAudioRoleControl;
-class MmRendererCustomAudioRoleControl;
-class MmRendererMediaPlayerControl;
-class MmRendererMetaDataReaderControl;
-class MmRendererPlayerVideoRendererControl;
-class MmRendererVideoWindowControl;
-
-class MmRendererMediaPlayerService : public QMediaService
-{
- Q_OBJECT
-public:
- explicit MmRendererMediaPlayerService(QObject *parent = 0);
- ~MmRendererMediaPlayerService();
-
- QMediaControl *requestControl(const char *name) override;
- void releaseControl(QMediaControl *control) override;
-
-private:
- void updateControls();
-
- QPointer<MmRendererPlayerVideoRendererControl> m_videoRendererControl;
- QPointer<MmRendererVideoWindowControl> m_videoWindowControl;
- QPointer<MmRendererMediaPlayerControl> m_mediaPlayerControl;
- QPointer<MmRendererMetaDataReaderControl> m_metaDataReaderControl;
- QPointer<MmRendererAudioRoleControl> m_audioRoleControl;
- QPointer<MmRendererCustomAudioRoleControl> m_customAudioRoleControl;
-
- bool m_appHasDrmPermission : 1;
- bool m_appHasDrmPermissionChecked : 1;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermetadata.cpp b/src/plugins/qnx/mediaplayer/mmrenderermetadata.cpp
deleted file mode 100644
index a8b92c267..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderermetadata.cpp
+++ /dev/null
@@ -1,298 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "mmrenderermetadata.h"
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qfile.h>
-#include <QtCore/qstringlist.h>
-
-#include <mm/renderer/events.h>
-#include <sys/neutrino.h>
-#include <sys/strm.h>
-
-static const char *strm_string_getx(const strm_string_t *sstr, const char *defaultValue)
-{
- return sstr ? strm_string_get(sstr) : defaultValue;
-}
-
-#if _NTO_VERSION < 700
-static strm_dict_t *mmr_metadata_split(strm_dict_t const *, const char *, unsigned)
-{
- return nullptr;
-}
-#endif
-
-QT_BEGIN_NAMESPACE
-
-MmRendererMetaData::MmRendererMetaData()
-{
- clear();
-}
-
-static const char * titleKey = "md_title_name";
-static const char * artistKey = "md_title_artist";
-static const char * commentKey = "md_title_comment";
-static const char * genreKey = "md_title_genre";
-static const char * yearKey = "md_title_year";
-static const char * durationKey = "md_title_duration";
-static const char * bitRateKey = "md_title_bitrate";
-static const char * sampleKey = "md_title_samplerate";
-static const char * albumKey = "md_title_album";
-static const char * trackKey = "md_title_track";
-static const char * widthKey = "md_video_width";
-static const char * heightKey = "md_video_height";
-static const char * mediaTypeKey = "md_title_mediatype";
-static const char * pixelWidthKey = "md_video_pixel_width";
-static const char * pixelHeightKey = "md_video_pixel_height";
-static const char * seekableKey = "md_title_seekable";
-static const char * trackSampleKey = "sample_rate";
-static const char * trackBitRateKey = "bitrate";
-static const char * trackWidthKey = "width";
-static const char * trackHeightKey = "height";
-static const char * trackPixelWidthKey = "pixel_width";
-static const char * trackPixelHeightKey = "pixel_height";
-
-static const int mediaTypeAudioFlag = 4;
-static const int mediaTypeVideoFlag = 2;
-
-bool MmRendererMetaData::update(const strm_dict_t *dict)
-{
- if (!dict) {
- clear();
- return true;
- }
-
- const strm_string_t *value;
-
- value = strm_dict_find_rstr(dict, durationKey);
- m_duration = QByteArray(strm_string_getx(value, "0")).toLongLong();
-
- value = strm_dict_find_rstr(dict, mediaTypeKey);
- m_mediaType = QByteArray(strm_string_getx(value, "-1")).toInt();
-
- value = strm_dict_find_rstr(dict, titleKey);
- m_title = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
-
- value = strm_dict_find_rstr(dict, seekableKey);
- m_seekable = (strcmp(strm_string_getx(value, "1"), "0") != 0);
-
- value = strm_dict_find_rstr(dict, artistKey);
- m_artist = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
-
- value = strm_dict_find_rstr(dict, commentKey);
- m_comment = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
-
- value = strm_dict_find_rstr(dict, genreKey);
- m_genre = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
-
- value = strm_dict_find_rstr(dict, yearKey);
- m_year = QByteArray(strm_string_getx(value, "0")).toInt();
-
- value = strm_dict_find_rstr(dict, albumKey);
- m_album = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
-
- value = strm_dict_find_rstr(dict, trackKey);
- m_track = QByteArray(strm_string_getx(value, "0")).toInt();
-
- strm_dict_t *at = mmr_metadata_split(dict, "audio", 0);
- if (at) {
- value = strm_dict_find_rstr(at, trackSampleKey);
- m_sampleRate = QByteArray(strm_string_getx(value, "0")).toInt();
-
- value = strm_dict_find_rstr(at, trackBitRateKey);
- m_audioBitRate = QByteArray(strm_string_getx(value, "0")).toInt();
-
- strm_dict_destroy(at);
- } else {
- value = strm_dict_find_rstr(dict, sampleKey);
- m_sampleRate = QByteArray(strm_string_getx(value, "0")).toInt();
-
- value = strm_dict_find_rstr(dict, bitRateKey);
- m_audioBitRate = QByteArray(strm_string_getx(value, "0")).toInt();
- }
-
- strm_dict_t *vt = mmr_metadata_split(dict, "video", 0);
- if (vt) {
- value = strm_dict_find_rstr(vt, trackWidthKey);
- m_width = QByteArray(strm_string_getx(value, "0")).toInt();
-
- value = strm_dict_find_rstr(vt, trackHeightKey);
- m_height = QByteArray(strm_string_getx(value, "0")).toInt();
-
- value = strm_dict_find_rstr(vt, trackPixelWidthKey);
- m_pixelWidth = QByteArray(strm_string_getx(value, "1")).toFloat();
-
- value = strm_dict_find_rstr(vt, trackPixelHeightKey);
- m_pixelHeight = QByteArray(strm_string_getx(value, "1")).toFloat();
-
- strm_dict_destroy(vt);
- } else {
- value = strm_dict_find_rstr(dict, widthKey);
- m_width = QByteArray(strm_string_getx(value, "0")).toInt();
-
- value = strm_dict_find_rstr(dict, heightKey);
- m_height = QByteArray(strm_string_getx(value, "0")).toInt();
-
- value = strm_dict_find_rstr(dict, pixelWidthKey);
- m_pixelWidth = QByteArray(strm_string_getx(value, "1")).toFloat();
-
- value = strm_dict_find_rstr(dict, pixelHeightKey);
- m_pixelHeight = QByteArray(strm_string_getx(value, "1")).toFloat();
- }
-
- return true;
-}
-
-void MmRendererMetaData::clear()
-{
- strm_dict_t *dict;
- dict = strm_dict_new();
- update(dict);
- strm_dict_destroy(dict);
-}
-
-qlonglong MmRendererMetaData::duration() const
-{
- return m_duration;
-}
-
-// Handling of pixel aspect ratio
-//
-// If the pixel aspect ratio is different from 1:1, it means the video needs to be stretched in
-// order to look natural.
-// For example, if the pixel width is 2, and the pixel height is 1, it means a video of 300x200
-// pixels needs to be displayed as 600x200 to look correct.
-// In order to support this the easiest way, we simply pretend that the actual size of the video
-// is 600x200, which will cause the video to be displayed in an aspect ratio of 3:1 instead of 3:2,
-// and therefore look correct.
-
-int MmRendererMetaData::height() const
-{
- return m_height * m_pixelHeight;
-}
-
-int MmRendererMetaData::width() const
-{
- return m_width * m_pixelWidth;
-}
-
-bool MmRendererMetaData::hasVideo() const
-{
- // By default, assume no video if we can't extract the information
- if (m_mediaType == -1)
- return false;
-
- return (m_mediaType & mediaTypeVideoFlag);
-}
-
-bool MmRendererMetaData::hasAudio() const
-{
- // By default, assume audio only if we can't extract the information
- if (m_mediaType == -1)
- return true;
-
- return (m_mediaType & mediaTypeAudioFlag);
-}
-
-QString MmRendererMetaData::title() const
-{
- return m_title;
-}
-
-bool MmRendererMetaData::isSeekable() const
-{
- return m_seekable;
-}
-
-QString MmRendererMetaData::artist() const
-{
- return m_artist;
-}
-
-QString MmRendererMetaData::comment() const
-{
- return m_comment;
-}
-
-QString MmRendererMetaData::genre() const
-{
- return m_genre;
-}
-
-int MmRendererMetaData::year() const
-{
- return m_year;
-}
-
-QString MmRendererMetaData::mediaType() const
-{
- if (hasVideo())
- return QLatin1String("video");
- else if (hasAudio())
- return QLatin1String("audio");
- else
- return QString();
-}
-
-int MmRendererMetaData::audioBitRate() const
-{
- return m_audioBitRate;
-}
-
-int MmRendererMetaData::sampleRate() const
-{
- return m_sampleRate;
-}
-
-QString MmRendererMetaData::album() const
-{
- return m_album;
-}
-
-int MmRendererMetaData::track() const
-{
- return m_track;
-}
-
-QSize MmRendererMetaData::resolution() const
-{
- return QSize(width(), height());
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermetadata.h b/src/plugins/qnx/mediaplayer/mmrenderermetadata.h
deleted file mode 100644
index ad2193d29..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderermetadata.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef MMRENDERERMETADATA_H
-#define MMRENDERERMETADATA_H
-
-#include <QtCore/qglobal.h>
-#include <QtCore/QSize>
-#include <QtCore/QString>
-
-typedef struct strm_dict strm_dict_t;
-
-QT_BEGIN_NAMESPACE
-
-class MmRendererMetaData
-{
-public:
- MmRendererMetaData();
- bool update(const strm_dict_t *dict);
- void clear();
-
- // Duration in milliseconds
- qlonglong duration() const;
-
- int height() const;
- int width() const;
- bool hasVideo() const;
- bool hasAudio() const;
- bool isSeekable() const;
-
- QString title() const;
- QString artist() const;
- QString comment() const;
- QString genre() const;
- int year() const;
- QString mediaType() const;
- int audioBitRate() const;
- int sampleRate() const;
- QString album() const;
- int track() const;
- QSize resolution() const;
-
-private:
- qlonglong m_duration;
- int m_height;
- int m_width;
- int m_mediaType;
- float m_pixelWidth;
- float m_pixelHeight;
- bool m_seekable;
- QString m_title;
- QString m_artist;
- QString m_comment;
- QString m_genre;
- int m_year;
- int m_audioBitRate;
- int m_sampleRate;
- QString m_album;
- int m_track;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermetadatareadercontrol.cpp b/src/plugins/qnx/mediaplayer/mmrenderermetadatareadercontrol.cpp
deleted file mode 100644
index 5367e0c54..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderermetadatareadercontrol.cpp
+++ /dev/null
@@ -1,170 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "mmrenderermetadatareadercontrol.h"
-#include <QtMultimedia/qmediametadata.h>
-
-QT_BEGIN_NAMESPACE
-
-MmRendererMetaDataReaderControl::MmRendererMetaDataReaderControl(QObject *parent)
- : QMetaDataReaderControl(parent)
-{
-}
-
-bool MmRendererMetaDataReaderControl::isMetaDataAvailable() const
-{
- return !availableMetaData().isEmpty();
-}
-
-QVariant MmRendererMetaDataReaderControl::metaData(const QString &key) const
-{
- if (key == QMediaMetaData::Title)
- return m_metaData.title();
- else if (key == QMediaMetaData::AlbumArtist)
- return m_metaData.artist();
- else if (key == QMediaMetaData::Comment)
- return m_metaData.comment();
- else if (key == QMediaMetaData::Genre)
- return m_metaData.genre();
- else if (key == QMediaMetaData::Year)
- return m_metaData.year();
- else if (key == QMediaMetaData::MediaType)
- return m_metaData.mediaType();
- else if (key == QMediaMetaData::Duration)
- return m_metaData.duration();
- else if (key == QMediaMetaData::AudioBitRate)
- return m_metaData.audioBitRate();
- else if (key == QMediaMetaData::SampleRate)
- return m_metaData.sampleRate();
- else if (key == QMediaMetaData::AlbumTitle)
- return m_metaData.album();
- else if (key == QMediaMetaData::TrackNumber)
- return m_metaData.track();
- else if (key == QMediaMetaData::Resolution)
- return m_metaData.resolution();
-
- return QVariant();
-}
-
-QStringList MmRendererMetaDataReaderControl::availableMetaData() const
-{
- QStringList metaData;
-
- if (!m_metaData.title().isEmpty())
- metaData << QMediaMetaData::Title;
- if (!m_metaData.artist().isEmpty())
- metaData << QMediaMetaData::Author;
- if (!m_metaData.comment().isEmpty())
- metaData << QMediaMetaData::Comment;
- if (!m_metaData.genre().isEmpty())
- metaData << QMediaMetaData::Genre;
- if (m_metaData.year() != 0)
- metaData << QMediaMetaData::Year;
- if (!m_metaData.mediaType().isEmpty())
- metaData << QMediaMetaData::MediaType;
- if (m_metaData.duration() != 0)
- metaData << QMediaMetaData::Duration;
- if (m_metaData.audioBitRate() != 0)
- metaData << QMediaMetaData::AudioBitRate;
- if (m_metaData.sampleRate() != 0)
- metaData << QMediaMetaData::SampleRate;
- if (!m_metaData.album().isEmpty())
- metaData << QMediaMetaData::AlbumTitle;
- if (m_metaData.track() != 0)
- metaData << QMediaMetaData::TrackNumber;
- if (m_metaData.resolution().isValid())
- metaData << QMediaMetaData::Resolution;
-
- return metaData;
-}
-
-void MmRendererMetaDataReaderControl::setMetaData(const MmRendererMetaData &data)
-{
- const MmRendererMetaData oldMetaData = m_metaData;
- const bool oldMetaDataAvailable = isMetaDataAvailable();
-
- m_metaData = data;
-
- bool changed = false;
- if (m_metaData.title() != oldMetaData.title()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::Title, m_metaData.title());
- } else if (m_metaData.artist() != oldMetaData.artist()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::Author, m_metaData.artist());
- } else if (m_metaData.comment() != oldMetaData.comment()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::Comment, m_metaData.comment());
- } else if (m_metaData.genre() != oldMetaData.genre()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::Genre, m_metaData.genre());
- } else if (m_metaData.year() != oldMetaData.year()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::Year, m_metaData.year());
- } else if (m_metaData.mediaType() != oldMetaData.mediaType()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::MediaType, m_metaData.mediaType());
- } else if (m_metaData.duration() != oldMetaData.duration()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::Duration, m_metaData.duration());
- } else if (m_metaData.audioBitRate() != oldMetaData.audioBitRate()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::AudioBitRate, m_metaData.audioBitRate());
- } else if (m_metaData.sampleRate() != oldMetaData.sampleRate()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::SampleRate, m_metaData.sampleRate());
- } else if (m_metaData.album() != oldMetaData.album()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::AlbumTitle, m_metaData.album());
- } else if (m_metaData.track() != oldMetaData.track()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::TrackNumber, m_metaData.track());
- } else if (m_metaData.resolution() != oldMetaData.resolution()) {
- changed = true;
- emit metaDataChanged(QMediaMetaData::Resolution, m_metaData.resolution());
- }
-
- if (changed)
- emit metaDataChanged();
-
- const bool metaDataAvailable = isMetaDataAvailable();
- if (metaDataAvailable != oldMetaDataAvailable)
- emit metaDataAvailableChanged(metaDataAvailable);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermetadatareadercontrol.h b/src/plugins/qnx/mediaplayer/mmrenderermetadatareadercontrol.h
deleted file mode 100644
index 878420460..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderermetadatareadercontrol.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef MMRENDERERMETADATAREADERCONTROL_H
-#define MMRENDERERMETADATAREADERCONTROL_H
-
-#include "mmrenderermetadata.h"
-#include <qmetadatareadercontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-class MmRendererMetaDataReaderControl : public QMetaDataReaderControl
-{
- Q_OBJECT
-public:
- explicit MmRendererMetaDataReaderControl(QObject *parent = 0);
-
- bool isMetaDataAvailable() const override;
-
- QVariant metaData(const QString &key) const override;
- QStringList availableMetaData() const override;
-
- void setMetaData(const MmRendererMetaData &data);
-
-private:
- MmRendererMetaData m_metaData;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.cpp b/src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.cpp
deleted file mode 100644
index 3b5715157..000000000
--- a/src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.cpp
+++ /dev/null
@@ -1,218 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mmrendererplayervideorenderercontrol.h"
-
-#include "windowgrabber.h"
-
-#include <QCoreApplication>
-#include <QDebug>
-#include <QVideoSurfaceFormat>
-#include <QOpenGLContext>
-
-#include <mm/renderer.h>
-
-QT_BEGIN_NAMESPACE
-
-static int winIdCounter = 0;
-
-MmRendererPlayerVideoRendererControl::MmRendererPlayerVideoRendererControl(QObject *parent)
- : QVideoRendererControl(parent)
- , m_windowGrabber(new WindowGrabber(this))
- , m_context(0)
- , m_videoId(-1)
-{
- connect(m_windowGrabber, SIGNAL(updateScene(const QSize &)), SLOT(updateScene(const QSize &)));
-}
-
-MmRendererPlayerVideoRendererControl::~MmRendererPlayerVideoRendererControl()
-{
- detachDisplay();
-}
-
-QAbstractVideoSurface *MmRendererPlayerVideoRendererControl::surface() const
-{
- return m_surface;
-}
-
-void MmRendererPlayerVideoRendererControl::setSurface(QAbstractVideoSurface *surface)
-{
- m_surface = QPointer<QAbstractVideoSurface>(surface);
- if (QOpenGLContext::currentContext())
- m_windowGrabber->checkForEglImageExtension();
- else if (m_surface)
- m_surface->setProperty("_q_GLThreadCallback", QVariant::fromValue<QObject*>(this));
-}
-
-void MmRendererPlayerVideoRendererControl::attachDisplay(mmr_context_t *context)
-{
- if (m_videoId != -1) {
- qWarning() << "MmRendererPlayerVideoRendererControl: Video output already attached!";
- return;
- }
-
- if (!context) {
- qWarning() << "MmRendererPlayerVideoRendererControl: No media player context!";
- return;
- }
-
- const QByteArray windowGroupId = m_windowGrabber->windowGroupId();
- if (windowGroupId.isEmpty()) {
- qWarning() << "MmRendererPlayerVideoRendererControl: Unable to find window group";
- return;
- }
-
- const QString windowName = QStringLiteral("MmRendererPlayerVideoRendererControl_%1_%2")
- .arg(winIdCounter++)
- .arg(QCoreApplication::applicationPid());
-
- m_windowGrabber->setWindowId(windowName.toLatin1());
-
- // Start with an invisible window, because we just want to grab the frames from it.
- const QString videoDeviceUrl = QStringLiteral("screen:?winid=%1&wingrp=%2&initflags=invisible&nodstviewport=1")
- .arg(windowName)
- .arg(QString::fromLatin1(windowGroupId));
-
- m_videoId = mmr_output_attach(context, videoDeviceUrl.toLatin1(), "video");
- if (m_videoId == -1) {
- qWarning() << "mmr_output_attach() for video failed";
- return;
- }
-
- m_context = context;
-}
-
-void MmRendererPlayerVideoRendererControl::detachDisplay()
-{
- m_windowGrabber->stop();
-
- if (m_surface)
- m_surface->stop();
-
- if (m_context && m_videoId != -1)
- mmr_output_detach(m_context, m_videoId);
-
- m_context = 0;
- m_videoId = -1;
-}
-
-void MmRendererPlayerVideoRendererControl::pause()
-{
- m_windowGrabber->pause();
-}
-
-void MmRendererPlayerVideoRendererControl::resume()
-{
- m_windowGrabber->resume();
-}
-
-class QnxTextureBuffer : public QAbstractVideoBuffer
-{
-public:
- QnxTextureBuffer(WindowGrabber *windowGrabber) :
- QAbstractVideoBuffer(QAbstractVideoBuffer::GLTextureHandle)
- {
- m_windowGrabber = windowGrabber;
- m_handle = 0;
- }
- MapMode mapMode() const {
- return QAbstractVideoBuffer::ReadWrite;
- }
- void unmap() {
-
- }
- uchar *map(MapMode mode, int * numBytes, int * bytesPerLine) {
- Q_UNUSED(mode);
- Q_UNUSED(numBytes);
- Q_UNUSED(bytesPerLine);
- return 0;
- }
- QVariant handle() const {
- if (!m_handle) {
- const_cast<QnxTextureBuffer*>(this)->m_handle = m_windowGrabber->getNextTextureId();
- }
- return m_handle;
- }
-private:
- WindowGrabber *m_windowGrabber;
- int m_handle;
-};
-
-void MmRendererPlayerVideoRendererControl::updateScene(const QSize &size)
-{
- if (m_surface) {
- if (!m_surface->isActive()) {
- if (m_windowGrabber->eglImageSupported()) {
- m_surface->start(QVideoSurfaceFormat(size, QVideoFrame::Format_BGR32,
- QAbstractVideoBuffer::GLTextureHandle));
- } else {
- m_surface->start(QVideoSurfaceFormat(size, QVideoFrame::Format_ARGB32));
- }
- } else {
- if (m_surface->surfaceFormat().frameSize() != size) {
- m_surface->stop();
- if (m_windowGrabber->eglImageSupported()) {
- m_surface->start(QVideoSurfaceFormat(size, QVideoFrame::Format_BGR32,
- QAbstractVideoBuffer::GLTextureHandle));
- } else {
- m_surface->start(QVideoSurfaceFormat(size, QVideoFrame::Format_ARGB32));
- }
- }
- }
-
- // Depending on the support of EGL images on the current platform we either pass a texture
- // handle or a copy of the image data
- if (m_windowGrabber->eglImageSupported()) {
- QnxTextureBuffer *textBuffer = new QnxTextureBuffer(m_windowGrabber);
- QVideoFrame actualFrame(textBuffer, size, QVideoFrame::Format_BGR32);
- m_surface->present(actualFrame);
- } else {
- m_surface->present(m_windowGrabber->getNextImage().copy());
- }
- }
-}
-
-void MmRendererPlayerVideoRendererControl::customEvent(QEvent *e)
-{
- // This is running in the render thread (OpenGL enabled)
- if (e->type() == QEvent::User)
- m_windowGrabber->checkForEglImageExtension();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.h b/src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.h
deleted file mode 100644
index c547ef534..000000000
--- a/src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef MMRENDERERPLAYERVIDEORENDERERCONTROL_H
-#define MMRENDERERPLAYERVIDEORENDERERCONTROL_H
-
-#include <QPointer>
-#include <qabstractvideosurface.h>
-#include <qvideorenderercontrol.h>
-
-typedef struct mmr_context mmr_context_t;
-
-QT_BEGIN_NAMESPACE
-
-class WindowGrabber;
-
-class MmRendererPlayerVideoRendererControl : public QVideoRendererControl
-{
- Q_OBJECT
-public:
- explicit MmRendererPlayerVideoRendererControl(QObject *parent = 0);
- ~MmRendererPlayerVideoRendererControl();
-
- QAbstractVideoSurface *surface() const override;
- void setSurface(QAbstractVideoSurface *surface) override;
-
- // Called by media control
- void attachDisplay(mmr_context_t *context);
- void detachDisplay();
- void pause();
- void resume();
-
- void customEvent(QEvent *) override;
-
-private Q_SLOTS:
- void updateScene(const QSize &size);
-
-private:
- QPointer<QAbstractVideoSurface> m_surface;
-
- WindowGrabber* m_windowGrabber;
- mmr_context_t *m_context;
-
- int m_videoId;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/mediaplayer/mmrendererutil.cpp b/src/plugins/qnx/mediaplayer/mmrendererutil.cpp
deleted file mode 100644
index d8af4a746..000000000
--- a/src/plugins/qnx/mediaplayer/mmrendererutil.cpp
+++ /dev/null
@@ -1,246 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "mmrendererutil.h"
-
-#include <QDebug>
-#include <QDir>
-#include <QFile>
-#include <QJsonDocument>
-#include <QJsonObject>
-#include <QJsonValue>
-#include <QMutex>
-#include <QMutex>
-#include <QString>
-#include <QXmlStreamReader>
-
-#include <mm/renderer.h>
-
-QT_BEGIN_NAMESPACE
-
-struct MmError {
- int errorCode;
- const char *name;
-};
-
-#define MM_ERROR_ENTRY(error) { error, #error }
-static const MmError mmErrors[] = {
- MM_ERROR_ENTRY(MMR_ERROR_NONE),
- MM_ERROR_ENTRY(MMR_ERROR_UNKNOWN ),
- MM_ERROR_ENTRY(MMR_ERROR_INVALID_PARAMETER ),
- MM_ERROR_ENTRY(MMR_ERROR_INVALID_STATE),
- MM_ERROR_ENTRY(MMR_ERROR_UNSUPPORTED_VALUE),
- MM_ERROR_ENTRY(MMR_ERROR_UNSUPPORTED_MEDIA_TYPE),
- MM_ERROR_ENTRY(MMR_ERROR_MEDIA_PROTECTED),
- MM_ERROR_ENTRY(MMR_ERROR_UNSUPPORTED_OPERATION),
- MM_ERROR_ENTRY(MMR_ERROR_READ),
- MM_ERROR_ENTRY(MMR_ERROR_WRITE),
- MM_ERROR_ENTRY(MMR_ERROR_MEDIA_UNAVAILABLE),
- MM_ERROR_ENTRY(MMR_ERROR_MEDIA_CORRUPTED),
- MM_ERROR_ENTRY(MMR_ERROR_OUTPUT_UNAVAILABLE),
- MM_ERROR_ENTRY(MMR_ERROR_NO_MEMORY),
- MM_ERROR_ENTRY(MMR_ERROR_RESOURCE_UNAVAILABLE),
- MM_ERROR_ENTRY(MMR_ERROR_MEDIA_DRM_NO_RIGHTS),
- MM_ERROR_ENTRY(MMR_ERROR_DRM_CORRUPTED_DATA_STORE),
- MM_ERROR_ENTRY(MMR_ERROR_DRM_OUTPUT_PROTECTION),
- MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_HDMI),
- MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_DISPLAYPORT),
- MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_DVI),
- MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_ANALOG_VIDEO),
- MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_ANALOG_AUDIO),
- MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_TOSLINK),
- MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_SPDIF),
- MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_BLUETOOTH),
- MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_WIRELESSHD),
-};
-static const unsigned int numMmErrors = sizeof(mmErrors) / sizeof(MmError);
-
-static QBasicMutex roleMapMutex;
-static bool roleMapInitialized = false;
-static QString roleMap[QAudio::CustomRole + 1];
-
-template <typename T, size_t N>
-constexpr size_t countof(T (&)[N])
-{
- return N;
-}
-
-constexpr bool inBounds(QAudio::Role r)
-{
- return r >= 0 && r < countof(roleMap);
-}
-
-QString keyValueMapsLocation()
-{
- QByteArray qtKeyValueMaps = qgetenv("QT_KEY_VALUE_MAPS");
- if (qtKeyValueMaps.isNull())
- return QStringLiteral("/etc/qt/keyvaluemaps");
- else
- return qtKeyValueMaps;
-}
-
-QJsonObject loadMapObject(const QString &keyValueMapPath)
-{
- QFile mapFile(keyValueMapsLocation() + keyValueMapPath);
- if (mapFile.open(QIODevice::ReadOnly)) {
- QByteArray mapFileContents = mapFile.readAll();
- QJsonDocument mapDocument = QJsonDocument::fromJson(mapFileContents);
- if (mapDocument.isObject()) {
- QJsonObject mapObject = mapDocument.object();
- return mapObject;
- }
- }
- return QJsonObject();
-}
-
-static void loadRoleMap()
-{
- QMutexLocker locker(&roleMapMutex);
-
- if (!roleMapInitialized) {
- QJsonObject mapObject = loadMapObject("/QAudio/Role.json");
- if (!mapObject.isEmpty()) {
- // Wrapping the loads in a switch like this ensures that anyone adding
- // a new enumerator will be notified that this code must be updated. A
- // compile error will occur because the enumerator is missing from the
- // switch. A compile error will also occur if the enumerator used to
- // size the mapping table isn't updated when a new enumerator is added.
- // One or more enumerators will be outside the bounds of the array when
- // the wrong enumerator is used to size the array.
- //
- // The code loads a mapping for each enumerator because role is set
- // to UnknownRole and all the cases drop through to the next case.
-#pragma GCC diagnostic push
-#pragma GCC diagnostic error "-Wswitch"
-#define loadRoleMapping(r) \
- case QAudio::r: \
- static_assert(inBounds(QAudio::r), #r " out-of-bounds." \
- " Do you need to change the enumerator used to size the mapping table" \
- " because you added new QAudio::Role enumerators?"); \
- roleMap[QAudio::r] = mapObject.value(QLatin1String(#r)).toString();
-
- QAudio::Role role = QAudio::UnknownRole;
- switch (role) {
- loadRoleMapping(UnknownRole);
- loadRoleMapping(MusicRole);
- loadRoleMapping(VideoRole);
- loadRoleMapping(VoiceCommunicationRole);
- loadRoleMapping(AlarmRole);
- loadRoleMapping(NotificationRole);
- loadRoleMapping(RingtoneRole);
- loadRoleMapping(AccessibilityRole);
- loadRoleMapping(SonificationRole);
- loadRoleMapping(GameRole);
- loadRoleMapping(CustomRole);
- }
-#undef loadRoleMapping
-#pragma GCC diagnostic pop
-
- if (!roleMap[QAudio::CustomRole].isEmpty()) {
- qWarning("CustomRole mapping ignored");
- roleMap[QAudio::CustomRole].clear();
- }
- }
-
- roleMapInitialized = true;
- }
-}
-
-QString mmErrorMessage(const QString &msg, mmr_context_t *context, int *errorCode)
-{
- const mmr_error_info_t * const mmError = mmr_error_info(context);
-
- if (errorCode)
- *errorCode = mmError->error_code;
-
- if (mmError->error_code < numMmErrors) {
- return QString("%1: %2 (code %3)").arg(msg).arg(mmErrors[mmError->error_code].name)
- .arg(mmError->error_code);
- } else {
- return QString("%1: Unknown error code %2").arg(msg).arg(mmError->error_code);
- }
-}
-
-bool checkForDrmPermission()
-{
- QDir sandboxDir = QDir::home(); // always returns 'data' directory
- sandboxDir.cdUp(); // change to app sandbox directory
-
- QFile file(sandboxDir.filePath("app/native/bar-descriptor.xml"));
- if (!file.open(QIODevice::ReadOnly)) {
- qWarning() << "checkForDrmPermission: Unable to open bar-descriptor.xml";
- return false;
- }
-
- QXmlStreamReader reader(&file);
- while (!reader.atEnd()) {
- reader.readNextStartElement();
- if (reader.name() == QLatin1String("action")
- || reader.name() == QLatin1String("permission")) {
- if (reader.readElementText().trimmed() == QLatin1String("access_protected_media"))
- return true;
- }
- }
-
- return false;
-}
-
-QString qnxAudioType(QAudio::Role role)
-{
- loadRoleMap();
-
- if (role >= 0 && role < countof(roleMap))
- return roleMap[role];
- else
- return QString();
-}
-
-QList<QAudio::Role> qnxSupportedAudioRoles()
-{
- loadRoleMap();
-
- QList<QAudio::Role> result;
- for (size_t i = 0; i < countof(roleMap); ++i) {
- if (!roleMap[i].isEmpty() || (i == QAudio::UnknownRole))
- result.append(static_cast<QAudio::Role>(i));
- }
-
- return result;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrendererutil.h b/src/plugins/qnx/mediaplayer/mmrendererutil.h
deleted file mode 100644
index ac6f73a7d..000000000
--- a/src/plugins/qnx/mediaplayer/mmrendererutil.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef MMRENDERERUTIL_H
-#define MMRENDERERUTIL_H
-
-#include <QtCore/qglobal.h>
-#include <QtMultimedia/qaudio.h>
-
-typedef struct mmr_context mmr_context_t;
-
-QT_BEGIN_NAMESPACE
-
-class QString;
-
-QString mmErrorMessage(const QString &msg, mmr_context_t *context, int * errorCode = 0);
-
-bool checkForDrmPermission();
-
-QString qnxAudioType(QAudio::Role role);
-QList<QAudio::Role> qnxSupportedAudioRoles();
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/mediaplayer/mmrenderervideowindowcontrol.cpp b/src/plugins/qnx/mediaplayer/mmrenderervideowindowcontrol.cpp
deleted file mode 100644
index fbd698eea..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderervideowindowcontrol.cpp
+++ /dev/null
@@ -1,413 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "mmrenderervideowindowcontrol.h"
-#include "mmrendererutil.h"
-#include <QtCore/qdebug.h>
-#include <QtGui/qguiapplication.h>
-#include <QtGui/qpa/qplatformnativeinterface.h>
-#include <QtGui/qscreen.h>
-#include <QtGui/qwindow.h>
-#include <mm/renderer.h>
-
-QT_BEGIN_NAMESPACE
-
-static int winIdCounter = 0;
-
-MmRendererVideoWindowControl::MmRendererVideoWindowControl(QObject *parent)
- : QVideoWindowControl(parent),
- m_videoId(-1),
- m_winId(0),
- m_context(0),
- m_fullscreen(false),
- m_aspectRatioMode(Qt::IgnoreAspectRatio),
- m_window(0),
- m_hue(0),
- m_brightness(0),
- m_contrast(0),
- m_saturation(0)
-{
-}
-
-MmRendererVideoWindowControl::~MmRendererVideoWindowControl()
-{
-}
-
-WId MmRendererVideoWindowControl::winId() const
-{
- return m_winId;
-}
-
-void MmRendererVideoWindowControl::setWinId(WId id)
-{
- m_winId = id;
-}
-
-QRect MmRendererVideoWindowControl::displayRect() const
-{
- return m_displayRect ;
-}
-
-void MmRendererVideoWindowControl::setDisplayRect(const QRect &rect)
-{
- if (m_displayRect != rect) {
- m_displayRect = rect;
- updateVideoPosition();
- }
-}
-
-bool MmRendererVideoWindowControl::isFullScreen() const
-{
- return m_fullscreen;
-}
-
-void MmRendererVideoWindowControl::setFullScreen(bool fullScreen)
-{
- if (m_fullscreen != fullScreen) {
- m_fullscreen = fullScreen;
- updateVideoPosition();
- emit fullScreenChanged(m_fullscreen);
- }
-}
-
-void MmRendererVideoWindowControl::repaint()
-{
- // Nothing we can or should do here
-}
-
-QSize MmRendererVideoWindowControl::nativeSize() const
-{
- return QSize(m_metaData.width(), m_metaData.height());
-}
-
-Qt::AspectRatioMode MmRendererVideoWindowControl::aspectRatioMode() const
-{
- return m_aspectRatioMode;
-}
-
-void MmRendererVideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
-{
- m_aspectRatioMode = mode;
-}
-
-int MmRendererVideoWindowControl::brightness() const
-{
- return m_brightness;
-}
-
-void MmRendererVideoWindowControl::setBrightness(int brightness)
-{
- if (m_brightness != brightness) {
- m_brightness = brightness;
- updateBrightness();
- emit brightnessChanged(m_brightness);
- }
-}
-
-int MmRendererVideoWindowControl::contrast() const
-{
- return m_contrast;
-}
-
-void MmRendererVideoWindowControl::setContrast(int contrast)
-{
- if (m_contrast != contrast) {
- m_contrast = contrast;
- updateContrast();
- emit contrastChanged(m_contrast);
- }
-}
-
-int MmRendererVideoWindowControl::hue() const
-{
- return m_hue;
-}
-
-void MmRendererVideoWindowControl::setHue(int hue)
-{
- if (m_hue != hue) {
- m_hue = hue;
- updateHue();
- emit hueChanged(m_hue);
- }
-}
-
-int MmRendererVideoWindowControl::saturation() const
-{
- return m_saturation;
-}
-
-void MmRendererVideoWindowControl::setSaturation(int saturation)
-{
- if (m_saturation != saturation) {
- m_saturation = saturation;
- updateSaturation();
- emit saturationChanged(m_saturation);
- }
-}
-
-void MmRendererVideoWindowControl::attachDisplay(mmr_context_t *context)
-{
- if (m_videoId != -1) {
- qDebug() << "MmRendererVideoWindowControl: Video output already attached!";
- return;
- }
-
- if (!context) {
- qDebug() << "MmRendererVideoWindowControl: No media player context!";
- return;
- }
-
- QWindow *window = findWindow(m_winId);
- if (!window) {
- qDebug() << "MmRendererVideoWindowControl: No video window!";
- return;
- }
-
- QPlatformNativeInterface * const nativeInterface = QGuiApplication::platformNativeInterface();
- if (!nativeInterface) {
- qDebug() << "MmRendererVideoWindowControl: Unable to get platform native interface";
- return;
- }
-
- const char * const groupNameData = static_cast<const char *>(
- nativeInterface->nativeResourceForWindow("windowGroup", window));
- if (!groupNameData) {
- qDebug() << "MmRendererVideoWindowControl: Unable to find window group for window"
- << window;
- return;
- }
-
- const QString groupName = QString::fromLatin1(groupNameData);
- m_windowName = QString("MmRendererVideoWindowControl_%1_%2").arg(winIdCounter++)
- .arg(QCoreApplication::applicationPid());
-
- nativeInterface->setWindowProperty(window->handle(),
- QStringLiteral("mmRendererWindowName"), m_windowName);
-
- // Start with an invisible window. If it would be visible right away, it would be at the wrong
- // position, and we can only change the position once we get the window handle.
- const QString videoDeviceUrl =
- QString("screen:?winid=%1&wingrp=%2&initflags=invisible&nodstviewport=1").arg(m_windowName).arg(groupName);
-
- m_videoId = mmr_output_attach(context, videoDeviceUrl.toLatin1(), "video");
- if (m_videoId == -1) {
- qDebug() << mmErrorMessage("mmr_output_attach() for video failed", context);
- return;
- }
-
- m_context = context;
- updateVideoPosition();
- updateHue();
- updateContrast();
- updateBrightness();
- updateSaturation();
-}
-
-void MmRendererVideoWindowControl::updateVideoPosition()
-{
- QWindow * const window = findWindow(m_winId);
- if (m_context && m_videoId != -1 && window) {
- QPoint topLeft = m_displayRect.topLeft();
-
- QScreen * const screen = window->screen();
- int width = m_fullscreen ?
- screen->size().width() :
- m_displayRect.width();
- int height = m_fullscreen ?
- screen->size().height() :
- m_displayRect.height();
-
- if (m_metaData.hasVideo() && m_metaData.width() > 0 && m_metaData.height() > 0) {
- // We need the source size to do aspect ratio scaling
- const qreal sourceRatio = m_metaData.width() / static_cast<float>(m_metaData.height());
- const qreal targetRatio = width / static_cast<float>(height);
-
- if (m_aspectRatioMode == Qt::KeepAspectRatio) {
- if (targetRatio < sourceRatio) {
- // Need to make height smaller
- const int newHeight = width / sourceRatio;
- const int heightDiff = height - newHeight;
- topLeft.ry() += heightDiff / 2;
- height = newHeight;
- } else {
- // Need to make width smaller
- const int newWidth = sourceRatio * height;
- const int widthDiff = width - newWidth;
- topLeft.rx() += widthDiff / 2;
- width = newWidth;
- }
-
- } else if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
- if (targetRatio < sourceRatio) {
- // Need to make width larger
- const int newWidth = sourceRatio * height;
- const int widthDiff = newWidth - width;
- topLeft.rx() -= widthDiff / 2;
- width = newWidth;
- } else {
- // Need to make height larger
- const int newHeight = width / sourceRatio;
- const int heightDiff = newHeight - height;
- topLeft.ry() -= heightDiff / 2;
- height = newHeight;
- }
- }
- }
-
- if (m_window != 0) {
- const int position[2] = { topLeft.x(), topLeft.y() };
- const int size[2] = { width, height };
- const int visible = m_displayRect.isValid();
- if (screen_set_window_property_iv(m_window, SCREEN_PROPERTY_POSITION, position) != 0)
- perror("Setting video position failed");
- if (screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, size) != 0)
- perror("Setting video size failed");
- if (screen_set_window_property_iv(m_window, SCREEN_PROPERTY_VISIBLE, &visible) != 0)
- perror("Setting video visibility failed");
- }
- }
-}
-
-void MmRendererVideoWindowControl::updateBrightness()
-{
- if (m_window != 0) {
- const int backendValue = m_brightness * 2.55f;
- if (screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BRIGHTNESS, &backendValue) != 0)
- perror("Setting brightness failed");
- }
-}
-
-void MmRendererVideoWindowControl::updateContrast()
-{
- if (m_window != 0) {
- const int backendValue = m_contrast * 1.27f;
- if (screen_set_window_property_iv(m_window, SCREEN_PROPERTY_CONTRAST, &backendValue) != 0)
- perror("Setting contrast failed");
- }
-}
-
-void MmRendererVideoWindowControl::updateHue()
-{
- if (m_window != 0) {
- const int backendValue = m_hue * 1.27f;
- if (screen_set_window_property_iv(m_window, SCREEN_PROPERTY_HUE, &backendValue) != 0)
- perror("Setting hue failed");
- }
-}
-
-void MmRendererVideoWindowControl::updateSaturation()
-{
- if (m_window != 0) {
- const int backendValue = m_saturation * 1.27f;
- if (screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SATURATION, &backendValue) != 0)
- perror("Setting saturation failed");
- }
-}
-
-void MmRendererVideoWindowControl::detachDisplay()
-{
- if (m_context && m_videoId != -1)
- mmr_output_detach(m_context, m_videoId);
-
- m_context = 0;
- m_videoId = -1;
- m_metaData.clear();
- m_windowName.clear();
- m_window = 0;
- m_hue = 0;
- m_brightness = 0;
- m_contrast = 0;
- m_saturation = 0;
-}
-
-void MmRendererVideoWindowControl::setMetaData(const MmRendererMetaData &metaData)
-{
- m_metaData = metaData;
- emit nativeSizeChanged();
-
- // To handle the updated source size data
- updateVideoPosition();
-}
-
-void MmRendererVideoWindowControl::screenEventHandler(const screen_event_t &screen_event)
-{
- int eventType;
- if (screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &eventType) != 0) {
- perror("MmRendererVideoWindowControl: Failed to query screen event type");
- return;
- }
-
- if (eventType != SCREEN_EVENT_CREATE)
- return;
-
- screen_window_t window = 0;
- if (screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&window) != 0) {
- perror("MmRendererVideoWindowControl: Failed to query window property");
- return;
- }
-
- const int maxIdStrLength = 128;
- char idString[maxIdStrLength];
- if (screen_get_window_property_cv(window, SCREEN_PROPERTY_ID_STRING, maxIdStrLength, idString) != 0) {
- perror("MmRendererVideoWindowControl: Failed to query window ID string");
- return;
- }
-
- if (m_windowName == idString) {
- m_window = window;
- updateVideoPosition();
-
- const int visibleFlag = 1;
- if (screen_set_window_property_iv(m_window, SCREEN_PROPERTY_VISIBLE, &visibleFlag) != 0) {
- perror("MmRendererVideoWindowControl: Failed to make window visible");
- return;
- }
- }
-}
-
-QWindow *MmRendererVideoWindowControl::findWindow(WId id) const
-{
- const auto allWindows = QGuiApplication::allWindows();
- for (QWindow *window : allWindows)
- if (window->winId() == id)
- return window;
- return 0;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrenderervideowindowcontrol.h b/src/plugins/qnx/mediaplayer/mmrenderervideowindowcontrol.h
deleted file mode 100644
index 8327e259d..000000000
--- a/src/plugins/qnx/mediaplayer/mmrenderervideowindowcontrol.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef MMRENDERERVIDEOWINDOWCONTROL_H
-#define MMRENDERERVIDEOWINDOWCONTROL_H
-
-#include "mmrenderermetadata.h"
-#include <qvideowindowcontrol.h>
-#include <screen/screen.h>
-
-typedef struct mmr_context mmr_context_t;
-
-QT_BEGIN_NAMESPACE
-
-class MmRendererVideoWindowControl : public QVideoWindowControl
-{
- Q_OBJECT
-public:
- explicit MmRendererVideoWindowControl(QObject *parent = 0);
- ~MmRendererVideoWindowControl();
-
- WId winId() const override;
- void setWinId(WId id) override;
-
- QRect displayRect() const override;
- void setDisplayRect(const QRect &rect) override;
-
- bool isFullScreen() const override;
- void setFullScreen(bool fullScreen) override;
-
- void repaint() override;
-
- QSize nativeSize() const override;
-
- Qt::AspectRatioMode aspectRatioMode() const override;
- void setAspectRatioMode(Qt::AspectRatioMode mode) override;
-
- int brightness() const override;
- void setBrightness(int brightness) override;
-
- int contrast() const override;
- void setContrast(int contrast) override;
-
- int hue() const override;
- void setHue(int hue) override;
-
- int saturation() const override;
- void setSaturation(int saturation) override;
-
- //
- // Called by media control
- //
- void detachDisplay();
- void attachDisplay(mmr_context_t *context);
- void setMetaData(const MmRendererMetaData &metaData);
- void screenEventHandler(const screen_event_t &event);
-
-private:
- QWindow *findWindow(WId id) const;
- void updateVideoPosition();
- void updateBrightness();
- void updateContrast();
- void updateHue();
- void updateSaturation();
-
- int m_videoId;
- WId m_winId;
- QRect m_displayRect;
- mmr_context_t *m_context;
- bool m_fullscreen;
- MmRendererMetaData m_metaData;
- Qt::AspectRatioMode m_aspectRatioMode;
- QString m_windowName;
- screen_window_t m_window;
- int m_hue;
- int m_brightness;
- int m_contrast;
- int m_saturation;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/mediaplayer/mmreventmediaplayercontrol.cpp b/src/plugins/qnx/mediaplayer/mmreventmediaplayercontrol.cpp
deleted file mode 100644
index b5c9804ab..000000000
--- a/src/plugins/qnx/mediaplayer/mmreventmediaplayercontrol.cpp
+++ /dev/null
@@ -1,229 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 QNX Software Systems. All rights reserved.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mmreventmediaplayercontrol.h"
-#include "mmreventthread.h"
-#include "mmrenderervideowindowcontrol.h"
-
-#include <mm/renderer.h>
-#include <tuple>
-
-QT_BEGIN_NAMESPACE
-
-static std::tuple<int, int, bool> parseBufferLevel(const QByteArray &value)
-{
- const int slashPos = value.indexOf('/');
- if (slashPos <= 0)
- return std::make_tuple(0, 0, false);
-
- bool ok = false;
- const int level = value.left(slashPos).toInt(&ok);
- if (!ok || level < 0)
- return std::make_tuple(0, 0, false);
-
- const int capacity = value.mid(slashPos + 1).toInt(&ok);
- if (!ok || capacity < 0)
- return std::make_tuple(0, 0, false);
-
- return std::make_tuple(level, capacity, true);
-}
-
-MmrEventMediaPlayerControl::MmrEventMediaPlayerControl(QObject *parent)
- : MmRendererMediaPlayerControl(parent)
- , m_eventThread(nullptr)
- , m_bufferStatus("")
- , m_bufferLevel(0)
- , m_bufferCapacity(0)
- , m_position(0)
- , m_suspended(false)
- , m_suspendedReason("unknown")
- , m_state(MMR_STATE_IDLE)
- , m_speed(0)
-{
- openConnection();
-}
-
-MmrEventMediaPlayerControl::~MmrEventMediaPlayerControl()
-{
- destroy();
-}
-
-void MmrEventMediaPlayerControl::startMonitoring()
-{
- m_eventThread = new MmrEventThread(m_context);
-
- connect(m_eventThread, &MmrEventThread::eventPending,
- this, &MmrEventMediaPlayerControl::readEvents);
-
- m_eventThread->setObjectName(QStringLiteral("MmrEventThread-") + QString::number(m_id));
- m_eventThread->start();
-}
-
-void MmrEventMediaPlayerControl::stopMonitoring()
-{
- delete m_eventThread;
- m_eventThread = nullptr;
-}
-
-void MmrEventMediaPlayerControl::resetMonitoring()
-{
- m_bufferStatus = "";
- m_bufferLevel = 0;
- m_bufferCapacity = 0;
- m_position = 0;
- m_suspended = false;
- m_suspendedReason = "unknown";
- m_state = MMR_STATE_IDLE;
- m_speed = 0;
-}
-
-bool MmrEventMediaPlayerControl::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
-{
- Q_UNUSED(result);
- if (eventType == "screen_event_t") {
- screen_event_t event = static_cast<screen_event_t>(message);
- if (MmRendererVideoWindowControl *control = videoWindowControl())
- control->screenEventHandler(event);
- }
-
- return false;
-}
-
-void MmrEventMediaPlayerControl::readEvents()
-{
- const mmr_event_t *event;
-
- while ((event = mmr_event_get(m_context))) {
- if (event->type == MMR_EVENT_NONE)
- break;
-
- switch (event->type) {
- case MMR_EVENT_STATUS: {
- if (event->data) {
- const strm_string_t *value;
- value = strm_dict_find_rstr(event->data, "bufferstatus");
- if (value) {
- m_bufferStatus = QByteArray(strm_string_get(value));
- if (!m_suspended)
- setMmBufferStatus(m_bufferStatus);
- }
-
- value = strm_dict_find_rstr(event->data, "bufferlevel");
- if (value) {
- const char *cstrValue = strm_string_get(value);
- int level;
- int capacity;
- bool ok;
- std::tie(level, capacity, ok) = parseBufferLevel(QByteArray(cstrValue));
- if (!ok) {
- qCritical("Could not parse buffer capacity from '%s'", cstrValue);
- } else {
- m_bufferLevel = level;
- m_bufferCapacity = capacity;
- setMmBufferLevel(level, capacity);
- }
- }
-
- value = strm_dict_find_rstr(event->data, "suspended");
- if (value) {
- if (!m_suspended) {
- m_suspended = true;
- m_suspendedReason = strm_string_get(value);
- handleMmSuspend(m_suspendedReason);
- }
- } else if (m_suspended) {
- m_suspended = false;
- handleMmSuspendRemoval(m_bufferStatus);
- }
- }
-
- if (event->pos_str) {
- const QByteArray valueBa = QByteArray(event->pos_str);
- bool ok;
- m_position = valueBa.toLongLong(&ok);
- if (!ok) {
- qCritical("Could not parse position from '%s'", valueBa.constData());
- } else {
- setMmPosition(m_position);
- }
- }
- break;
- }
- case MMR_EVENT_STATE: {
- if (event->state == MMR_STATE_PLAYING && m_speed != event->speed) {
- m_speed = event->speed;
- if (m_speed == 0)
- handleMmPause();
- else
- handleMmPlay();
- }
- break;
- }
- case MMR_EVENT_METADATA: {
- updateMetaData(event->data);
- break;
- }
- case MMR_EVENT_ERROR:
- case MMR_EVENT_NONE:
- case MMR_EVENT_OVERFLOW:
- case MMR_EVENT_WARNING:
- case MMR_EVENT_PLAYLIST:
- case MMR_EVENT_INPUT:
- case MMR_EVENT_OUTPUT:
- case MMR_EVENT_CTXTPAR:
- case MMR_EVENT_TRKPAR:
- case MMR_EVENT_OTHER: {
- break;
- }
- }
-
- // Currently, any exit from the playing state is considered a stop (end-of-media).
- // If you ever need to separate end-of-media from things like "stopped unexpectedly"
- // or "stopped because of an error", you'll find that end-of-media is signaled by an
- // MMR_EVENT_ERROR of MMR_ERROR_NONE with state changed to MMR_STATE_STOPPED.
- if (event->state != m_state && m_state == MMR_STATE_PLAYING)
- handleMmStopped();
- m_state = event->state;
- }
-
- if (m_eventThread)
- m_eventThread->signalRead();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmreventmediaplayercontrol.h b/src/plugins/qnx/mediaplayer/mmreventmediaplayercontrol.h
deleted file mode 100644
index e6c138f89..000000000
--- a/src/plugins/qnx/mediaplayer/mmreventmediaplayercontrol.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 QNX Software Systems. All rights reserved.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef MMREVENTMEDIAPLAYERCONTROL_H
-#define MMREVENTMEDIAPLAYERCONTROL_H
-
-#include "mmrenderermediaplayercontrol.h"
-
-#include <mm/renderer/events.h>
-
-QT_BEGIN_NAMESPACE
-
-class MmrEventThread;
-
-class MmrEventMediaPlayerControl final : public MmRendererMediaPlayerControl
-{
- Q_OBJECT
-public:
- explicit MmrEventMediaPlayerControl(QObject *parent = 0);
- ~MmrEventMediaPlayerControl() override;
-
- void startMonitoring() override;
- void stopMonitoring() override;
- void resetMonitoring() override;
-
- bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
-
-private Q_SLOTS:
- void readEvents();
-
-private:
- MmrEventThread *m_eventThread;
-
- // status properties.
- QByteArray m_bufferStatus;
- int m_bufferLevel;
- int m_bufferCapacity;
- qint64 m_position;
- bool m_suspended;
- QByteArray m_suspendedReason;
-
- // state properties.
- mmr_state_t m_state;
- int m_speed;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/mediaplayer/mmreventthread.cpp b/src/plugins/qnx/mediaplayer/mmreventthread.cpp
deleted file mode 100644
index 25f26e216..000000000
--- a/src/plugins/qnx/mediaplayer/mmreventthread.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 QNX Software Systems. All rights reserved.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mmreventthread.h"
-
-#include <QtCore/QDebug>
-
-#include <errno.h>
-#include <mm/renderer/events.h>
-#include <sys/neutrino.h>
-
-static const int c_mmrCode = _PULSE_CODE_MINAVAIL + 0;
-static const int c_readCode = _PULSE_CODE_MINAVAIL + 1;
-static const int c_quitCode = _PULSE_CODE_MINAVAIL + 2;
-
-MmrEventThread::MmrEventThread(mmr_context_t *context)
- : QThread(),
- m_mmrContext(context)
-{
- if (Q_UNLIKELY((m_channelId = ChannelCreate(_NTO_CHF_DISCONNECT
- | _NTO_CHF_UNBLOCK
- | _NTO_CHF_PRIVATE)) == -1)) {
- qFatal("MmrEventThread: Can't continue without a channel");
- }
-
- if (Q_UNLIKELY((m_connectionId = ConnectAttach(0, 0, m_channelId,
- _NTO_SIDE_CHANNEL, 0)) == -1)) {
- ChannelDestroy(m_channelId);
- qFatal("MmrEventThread: Can't continue without a channel connection");
- }
-
- SIGEV_PULSE_INIT(&m_mmrEvent, m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_mmrCode, 0);
-}
-
-MmrEventThread::~MmrEventThread()
-{
- // block until thread terminates
- shutdown();
-
- ConnectDetach(m_connectionId);
- ChannelDestroy(m_channelId);
-}
-
-void MmrEventThread::run()
-{
- int armResult = mmr_event_arm(m_mmrContext, &m_mmrEvent);
- if (armResult > 0)
- emit eventPending();
-
- while (1) {
- struct _pulse msg;
- memset(&msg, 0, sizeof(msg));
- int receiveId = MsgReceive(m_channelId, &msg, sizeof(msg), nullptr);
- if (receiveId == 0) {
- if (msg.code == c_mmrCode) {
- emit eventPending();
- } else if (msg.code == c_readCode) {
- armResult = mmr_event_arm(m_mmrContext, &m_mmrEvent);
- if (armResult > 0)
- emit eventPending();
- } else if (msg.code == c_quitCode) {
- break;
- } else {
- qWarning() << Q_FUNC_INFO << "Unexpected pulse" << msg.code;
- }
- } else if (receiveId > 0) {
- qWarning() << Q_FUNC_INFO << "Unexpected message" << msg.code;
- } else {
- qWarning() << Q_FUNC_INFO << "MsgReceive error" << strerror(errno);
- }
- }
-}
-
-void MmrEventThread::signalRead()
-{
- MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_readCode, 0);
-}
-
-void MmrEventThread::shutdown()
-{
- MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_quitCode, 0);
-
- // block until thread terminates
- wait();
-}
diff --git a/src/plugins/qnx/mediaplayer/mmreventthread.h b/src/plugins/qnx/mediaplayer/mmreventthread.h
deleted file mode 100644
index f7bc5cf5e..000000000
--- a/src/plugins/qnx/mediaplayer/mmreventthread.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 QNX Software Systems. All rights reserved.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MMREVENTTHREAD_H
-#define MMREVENTTHREAD_H
-
-#include <QtCore/QThread>
-
-#include <sys/neutrino.h>
-#include <sys/siginfo.h>
-
-QT_BEGIN_NAMESPACE
-
-typedef struct mmr_context mmr_context_t;
-
-class MmrEventThread : public QThread
-{
- Q_OBJECT
-
-public:
- MmrEventThread(mmr_context_t *context);
- ~MmrEventThread() override;
-
- void signalRead();
-
-protected:
- void run() override;
-
-Q_SIGNALS:
- void eventPending();
-
-private:
- void shutdown();
-
- int m_channelId;
- int m_connectionId;
- struct sigevent m_mmrEvent;
- mmr_context_t *m_mmrContext;
-};
-
-QT_END_NAMESPACE
-
-#endif // MMREVENTTHREAD_H
diff --git a/src/plugins/qnx/neutrino_mediaservice.json b/src/plugins/qnx/neutrino_mediaservice.json
deleted file mode 100644
index 919368d73..000000000
--- a/src/plugins/qnx/neutrino_mediaservice.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["neutrinomultimedia"],
- "Services": ["org.qt-project.qt.mediaplayer"]
-}
diff --git a/src/plugins/qnx/neutrinoserviceplugin.cpp b/src/plugins/qnx/neutrinoserviceplugin.cpp
deleted file mode 100644
index 842796c83..000000000
--- a/src/plugins/qnx/neutrinoserviceplugin.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "neutrinoserviceplugin.h"
-
-#include "mmrenderermediaplayerservice.h"
-
-QT_BEGIN_NAMESPACE
-
-NeutrinoServicePlugin::NeutrinoServicePlugin()
-{
-}
-
-QMediaService *NeutrinoServicePlugin::create(const QString &key)
-{
- if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER))
- return new MmRendererMediaPlayerService();
-
- return 0;
-}
-
-void NeutrinoServicePlugin::release(QMediaService *service)
-{
- delete service;
-}
-
-QMediaServiceProviderHint::Features NeutrinoServicePlugin::supportedFeatures(const QByteArray &service) const
-{
- Q_UNUSED(service);
- return QMediaServiceProviderHint::Features();
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/qnx/neutrinoserviceplugin.h b/src/plugins/qnx/neutrinoserviceplugin.h
deleted file mode 100644
index 62ed7f0bd..000000000
--- a/src/plugins/qnx/neutrinoserviceplugin.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef NEUTRINOSERVICEPLUGIN_H
-#define NEUTRINOSERVICEPLUGIN_H
-
-#include <qmediaserviceproviderplugin.h>
-
-QT_BEGIN_NAMESPACE
-
-class NeutrinoServicePlugin
- : public QMediaServiceProviderPlugin,
- public QMediaServiceFeaturesInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaServiceFeaturesInterface)
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "neutrino_mediaservice.json")
-public:
- NeutrinoServicePlugin();
-
- QMediaService *create(const QString &key) override;
- void release(QMediaService *service) override;
- QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const override;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/qnx/qnx.pro b/src/plugins/qnx/qnx.pro
deleted file mode 100644
index 960c614e0..000000000
--- a/src/plugins/qnx/qnx.pro
+++ /dev/null
@@ -1,15 +0,0 @@
-TARGET = qtmedia_qnx
-QT += multimedia-private gui-private core-private
-
-LIBS += -lscreen
-
-include(common/common.pri)
-include(mediaplayer/mediaplayer.pri)
-
-HEADERS += neutrinoserviceplugin.h
-SOURCES += neutrinoserviceplugin.cpp
-OTHER_FILES += neutrino_mediaservice.json
-PLUGIN_CLASS_NAME = NeutrinoServicePlugin
-
-PLUGIN_TYPE = mediaservice
-load(qt_plugin)
diff --git a/src/plugins/resourcepolicy/resourcepolicy.json b/src/plugins/resourcepolicy/resourcepolicy.json
deleted file mode 100644
index d751b849c..000000000
--- a/src/plugins/resourcepolicy/resourcepolicy.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["resourcepolicy"],
- "Services": ["org.qt-project.qt.mediaplayerresourcesetfactory", "default"]
-}
diff --git a/src/plugins/resourcepolicy/resourcepolicy.pro b/src/plugins/resourcepolicy/resourcepolicy.pro
deleted file mode 100644
index 89e75be1b..000000000
--- a/src/plugins/resourcepolicy/resourcepolicy.pro
+++ /dev/null
@@ -1,22 +0,0 @@
-TARGET = resourceqt
-
-QT += multimedia-private
-
-QMAKE_USE += libresourceqt5
-
-INCLUDEPATH += $$PWD \
- $${SOURCE_DIR}/src/multimedia
-
-HEADERS += \
- $$PWD/resourcepolicyplugin.h \
- $$PWD/resourcepolicyimpl.h \
- $$PWD/resourcepolicyint.h
-
-SOURCES += \
- $$PWD/resourcepolicyplugin.cpp \
- $$PWD/resourcepolicyimpl.cpp \
- $$PWD/resourcepolicyint.cpp
-
-PLUGIN_TYPE = resourcepolicy
-PLUGIN_CLASS_NAME = ResourceQtPolicyPlugin
-load(qt_plugin)
diff --git a/src/plugins/resourcepolicy/resourcepolicyimpl.cpp b/src/plugins/resourcepolicy/resourcepolicyimpl.cpp
deleted file mode 100644
index 0ce02e9b4..000000000
--- a/src/plugins/resourcepolicy/resourcepolicyimpl.cpp
+++ /dev/null
@@ -1,100 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd, author: <robin.burchell@jollamobile.com>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QGlobalStatic>
-
-#include <policy/resource.h>
-#include <policy/resources.h>
-#include <policy/resource-set.h>
-
-#include "resourcepolicyimpl.h"
-#include "resourcepolicyint.h"
-
-Q_GLOBAL_STATIC(ResourcePolicyInt, globalResourcePolicyInt);
-
-ResourcePolicyImpl::ResourcePolicyImpl(QObject *parent)
- : QMediaPlayerResourceSetInterface(parent)
-{
- ResourcePolicyInt *set = globalResourcePolicyInt;
- set->addClient(this);
-}
-
-ResourcePolicyImpl::~ResourcePolicyImpl()
-{
- ResourcePolicyInt *set = globalResourcePolicyInt;
- if (!globalResourcePolicyInt.isDestroyed())
- set->removeClient(this);
-}
-
-bool ResourcePolicyImpl::isVideoEnabled() const
-{
- ResourcePolicyInt *set = globalResourcePolicyInt;
- return set->isVideoEnabled(this);
-}
-
-void ResourcePolicyImpl::setVideoEnabled(bool videoEnabled)
-{
- ResourcePolicyInt *set = globalResourcePolicyInt;
- set->setVideoEnabled(this, videoEnabled);
-}
-
-void ResourcePolicyImpl::acquire()
-{
- ResourcePolicyInt *set = globalResourcePolicyInt;
- set->acquire(this);
-}
-
-void ResourcePolicyImpl::release()
-{
- ResourcePolicyInt *set = globalResourcePolicyInt;
- set->release(this);
-}
-
-bool ResourcePolicyImpl::isGranted() const
-{
- ResourcePolicyInt *set = globalResourcePolicyInt;
- return set->isGranted(this);
-}
-
-bool ResourcePolicyImpl::isAvailable() const
-{
- ResourcePolicyInt *set = globalResourcePolicyInt;
- return set->isAvailable();
-}
diff --git a/src/plugins/resourcepolicy/resourcepolicyimpl.h b/src/plugins/resourcepolicy/resourcepolicyimpl.h
deleted file mode 100644
index 27eb32dc8..000000000
--- a/src/plugins/resourcepolicy/resourcepolicyimpl.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd, author: <robin.burchell@jollamobile.com>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef RESOURCEPOLICYIMPL_H
-#define RESOURCEPOLICYIMPL_H
-
-#include <QObject>
-
-#include <private/qmediaresourceset_p.h>
-
-namespace ResourcePolicy {
- class ResourceSet;
-};
-
-class ResourcePolicyImpl : public QMediaPlayerResourceSetInterface
-{
- Q_OBJECT
-public:
- ResourcePolicyImpl(QObject *parent = 0);
- ~ResourcePolicyImpl();
-
- bool isVideoEnabled() const;
- void setVideoEnabled(bool videoEnabled);
- void acquire();
- void release();
- bool isGranted() const;
- bool isAvailable() const;
-};
-
-#endif // RESOURCEPOLICYIMPL_H
diff --git a/src/plugins/resourcepolicy/resourcepolicyint.cpp b/src/plugins/resourcepolicy/resourcepolicyint.cpp
deleted file mode 100644
index fc6a3d874..000000000
--- a/src/plugins/resourcepolicy/resourcepolicyint.cpp
+++ /dev/null
@@ -1,405 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd, author: <robin.burchell@jollamobile.com>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include <policy/resource.h>
-#include <policy/resources.h>
-#include <policy/resource-set.h>
-
-#include "resourcepolicyint.h"
-#include "resourcepolicyimpl.h"
-
-#include <QMap>
-#include <QByteArray>
-#include <QString>
-
-static int clientid = 0;
-
-ResourcePolicyInt::ResourcePolicyInt(QObject *parent)
- : QObject(parent)
- , m_acquired(0)
- , m_status(Initial)
- , m_video(0)
- , m_available(false)
- , m_resourceSet(0)
-{
- const char *resourceClass = "player";
-
- QByteArray envVar = qgetenv("NEMO_RESOURCE_CLASS_OVERRIDE");
- if (!envVar.isEmpty()) {
- QString data(envVar);
- // Only allow few resource classes
- if (data == "navigator" ||
- data == "call" ||
- data == "camera" ||
- data == "game" ||
- data == "player" ||
- data == "event")
- resourceClass = envVar.constData();
- }
-
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### Using resource class " << resourceClass;
-#endif
-
- m_resourceSet = new ResourcePolicy::ResourceSet(resourceClass, this);
- m_resourceSet->setAlwaysReply();
-
- connect(m_resourceSet, SIGNAL(resourcesGranted(QList<ResourcePolicy::ResourceType>)),
- this, SLOT(handleResourcesGranted()));
- connect(m_resourceSet, SIGNAL(resourcesDenied()),
- this, SLOT(handleResourcesDenied()));
- connect(m_resourceSet, SIGNAL(resourcesReleased()),
- this, SLOT(handleResourcesReleased()));
- connect(m_resourceSet, SIGNAL(lostResources()),
- this, SLOT(handleResourcesLost()));
- connect(m_resourceSet, SIGNAL(resourcesReleasedByManager()),
- this, SLOT(handleResourcesReleasedByManager()));
-
- connect(m_resourceSet, SIGNAL(resourcesBecameAvailable(const QList<ResourcePolicy::ResourceType>)),
- this, SLOT(handleResourcesBecameAvailable(const QList<ResourcePolicy::ResourceType>)));
-
- ResourcePolicy::AudioResource *audioResource = new ResourcePolicy::AudioResource(resourceClass);
-
- audioResource->setProcessID(QCoreApplication::applicationPid());
- audioResource->setStreamTag("media.name", "*");
- m_resourceSet->addResourceObject(audioResource);
- m_resourceSet->update();
-}
-
-ResourcePolicyInt::~ResourcePolicyInt()
-{
- delete m_resourceSet;
- m_resourceSet = 0;
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### Tearing down singleton.";
-#endif
-}
-
-void ResourcePolicyInt::addClient(ResourcePolicyImpl *client)
-{
- clientEntry entry;
- entry.id = clientid++;
- entry.client = client;
- entry.status = Initial;
- entry.videoEnabled = false;
- m_clients.insert(entry.client, entry);
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### Add client " << client << " : " << entry.id;
-#endif
-}
-
-void ResourcePolicyInt::removeClient(ResourcePolicyImpl *client)
-{
- QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.find(client);
- if (i != m_clients.end()) {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### Remove client " << client << " : " << i.value().id;
-#endif
- if (i.value().status == GrantedResource)
- --m_acquired;
- m_clients.erase(i);
- }
-
- if (m_acquired == 0 && m_status != Initial) {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### Remove client, acquired = 0, release";
-#endif
- m_resourceSet->release();
- m_status = Initial;
- }
-}
-
-bool ResourcePolicyInt::isVideoEnabled(const ResourcePolicyImpl *client) const
-{
- QMap<const ResourcePolicyImpl*, clientEntry>::const_iterator i = m_clients.find(client);
- if (i != m_clients.constEnd())
- return i.value().videoEnabled;
-
- return false;
-}
-
-void ResourcePolicyInt::setVideoEnabled(const ResourcePolicyImpl *client, bool videoEnabled)
-{
- bool update = false;
-
- QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.find(client);
- if (i != m_clients.end()) {
- if (videoEnabled == i.value().videoEnabled)
- return;
-
- if (videoEnabled) {
- if (m_video > 0) {
- i.value().videoEnabled = true;
- } else {
- m_resourceSet->addResource(ResourcePolicy::VideoPlaybackType);
- update = true;
- }
- ++m_video;
- } else {
- --m_video;
- i.value().videoEnabled = false;
- if (m_video == 0) {
- m_resourceSet->deleteResource(ResourcePolicy::VideoPlaybackType);
- update = true;
- }
- }
- }
-
- if (update)
- m_resourceSet->update();
-}
-
-void ResourcePolicyInt::acquire(const ResourcePolicyImpl *client)
-{
- QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.find(client);
- if (i != m_clients.end()) {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": ACQUIRE";
-#endif
- if (i.value().status == Initial) {
-
- if (m_status == RequestedResource) {
- i.value().status = RequestedResource;
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": Already requesting, set client as RequestResource and return";
-#endif
- return;
- }
-
- if (m_status == GrantedResource) {
- ++m_acquired;
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": Already granted, set as GrantedResource and return";
-#endif
- i.value().status = GrantedResource;
- emit i.value().client->resourcesGranted();
- return;
- }
- } else if (i.value().status == RequestedResource) {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": Already requesting, return";
-#endif
- return;
- } else {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": Already granted, return ";
-#endif
- return;
- }
- i.value().status = RequestedResource;
- m_status = RequestedResource;
-
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": ACQUIRE call resourceSet->acquire()";
-#endif
- // If m_status was Initial this is the first time resources are requested,
- // so let's actually do the acquiring
- m_resourceSet->acquire();
- }
-}
-
-void ResourcePolicyInt::release(const ResourcePolicyImpl *client)
-{
- QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.find(client);
- if (i != m_clients.end()) {
- if (i.value().status == GrantedResource) {
- i.value().status = Initial;
- --m_acquired;
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": RELEASE, acquired (" << m_acquired << ")";
-#endif
- emit i.value().client->resourcesReleased();
- }
- }
-
- if (m_acquired == 0 && m_status != Initial) {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": RELEASE call resourceSet->release()";
-#endif
- m_resourceSet->release();
- m_status = Initial;
- }
-}
-
-bool ResourcePolicyInt::isGranted(const ResourcePolicyImpl *client) const
-{
- QMap<const ResourcePolicyImpl*, clientEntry>::const_iterator i = m_clients.find(client);
- if (i != m_clients.constEnd()) {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": IS GRANTED, status: " << i.value().status;
-#endif
- return i.value().status == GrantedResource;
- }
-
- return false;
-}
-
-bool ResourcePolicyInt::isAvailable() const
-{
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### isAvailable " << m_available;
-#endif
- return m_available;
-}
-
-void ResourcePolicyInt::handleResourcesGranted()
-{
- m_status = GrantedResource;
- QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.begin();
- while (i != m_clients.end()) {
- if (i.value().status == RequestedResource) {
- ++m_acquired;
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": HANDLE GRANTED, acquired (" << m_acquired << ") emitting resourcesGranted()";
-#endif
- i.value().status = GrantedResource;
- emit i.value().client->resourcesGranted();
- }
- ++i;
- }
-}
-
-void ResourcePolicyInt::handleResourcesDenied()
-{
- m_status = Initial;
- m_acquired = 0;
- QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.begin();
- while (i != m_clients.end()) {
- if (i.value().status == RequestedResource) {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": HANDLE DENIED, acquired (" << m_acquired << ") emitting resourcesDenied()";
-#endif
- i.value().status = Initial;
- emit i.value().client->resourcesDenied();
- }
- // Do we need to act for clients that are in granted state?
- ++i;
- }
-}
-
-void ResourcePolicyInt::handleResourcesReleased()
-{
- m_status = Initial;
- m_acquired = 0;
- QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.begin();
- while (i != m_clients.end()) {
- if (i.value().status != Initial) {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": HANDLE RELEASED, acquired (" << m_acquired << ") emitting resourcesReleased()";
-#endif
- i.value().status = Initial;
- emit i.value().client->resourcesReleased();
- }
- ++i;
- }
-}
-
-void ResourcePolicyInt::handleResourcesLost()
-{
- // If resources were granted switch to acquiring state,
- // so that if the resources are freed elsewhere we
- // will acquire them again properly.
- if (m_status == GrantedResource)
- m_status = RequestedResource;
-
- m_acquired = 0;
-
- QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.begin();
- while (i != m_clients.end()) {
- if (i.value().status == GrantedResource) {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": HANDLE LOST, acquired (" << m_acquired << ") emitting resourcesLost()";
-#endif
- i.value().status = RequestedResource;
- emit i.value().client->resourcesLost();
- }
- ++i;
- }
-}
-
-void ResourcePolicyInt::handleResourcesReleasedByManager()
-{
- if (m_status != Initial)
- m_status = Initial;
-
- m_acquired = 0;
-
- QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.begin();
- while (i != m_clients.end()) {
- if (i.value().status != Initial) {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": HANDLE RELEASEDBYMANAGER, acquired (" << m_acquired << ") emitting resourcesLost()";
-#endif
- i.value().status = Initial;
- emit i.value().client->resourcesLost();
- }
- ++i;
- }
-}
-
-void ResourcePolicyInt::handleResourcesBecameAvailable(const QList<ResourcePolicy::ResourceType> &resources)
-{
- bool available = false;
-
- for (int i = 0; i < resources.size(); ++i) {
- if (resources.at(i) == ResourcePolicy::AudioPlaybackType)
- available = true;
- }
-
- availabilityChanged(available);
-}
-
-void ResourcePolicyInt::availabilityChanged(bool available)
-{
- if (available == m_available)
- return;
-
- m_available = available;
-
- QMap<const ResourcePolicyImpl*, clientEntry>::const_iterator i = m_clients.constBegin();
- while (i != m_clients.constEnd()) {
-#ifdef RESOURCE_DEBUG
- qDebug() << "##### " << i.value().id << ": emitting availabilityChanged(" << m_available << ")";
-#endif
- emit i.value().client->availabilityChanged(m_available);
- ++i;
- }
-}
diff --git a/src/plugins/resourcepolicy/resourcepolicyint.h b/src/plugins/resourcepolicy/resourcepolicyint.h
deleted file mode 100644
index 9ba79c1bc..000000000
--- a/src/plugins/resourcepolicy/resourcepolicyint.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd, author: <robin.burchell@jollamobile.com>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef RESOURCEPOLICYINT_H
-#define RESOURCEPOLICYINT_H
-
-#include <QObject>
-#include <QMap>
-
-#include <policy/resource-set.h>
-#include <policy/resource.h>
-#include <private/qmediaresourceset_p.h>
-#include "resourcepolicyimpl.h"
-
-namespace ResourcePolicy {
- class ResourceSet;
-};
-
-enum ResourceStatus {
- Initial = 0,
- RequestedResource,
- GrantedResource
-};
-
-struct clientEntry {
- int id;
- ResourcePolicyImpl *client;
- ResourceStatus status;
- bool videoEnabled;
-};
-
-class ResourcePolicyInt : public QObject
-{
- Q_OBJECT
-public:
- ResourcePolicyInt(QObject *parent = 0);
- ~ResourcePolicyInt();
-
- bool isVideoEnabled(const ResourcePolicyImpl *client) const;
- void setVideoEnabled(const ResourcePolicyImpl *client, bool videoEnabled);
- void acquire(const ResourcePolicyImpl *client);
- void release(const ResourcePolicyImpl *client);
- bool isGranted(const ResourcePolicyImpl *client) const;
- bool isAvailable() const;
-
- void addClient(ResourcePolicyImpl *client);
- void removeClient(ResourcePolicyImpl *client);
-
-private slots:
- void handleResourcesGranted();
- void handleResourcesDenied();
- void handleResourcesReleased();
- void handleResourcesLost();
- void handleResourcesReleasedByManager();
- void handleResourcesBecameAvailable(const QList<ResourcePolicy::ResourceType> &resources);
-
-private:
- void availabilityChanged(bool available);
-
- QMap<const ResourcePolicyImpl*, clientEntry> m_clients;
-
- int m_acquired;
- ResourceStatus m_status;
- int m_video;
- bool m_available;
- ResourcePolicy::ResourceSet *m_resourceSet;
-};
-
-#endif // RESOURCEPOLICYINT_H
diff --git a/src/plugins/resourcepolicy/resourcepolicyplugin.cpp b/src/plugins/resourcepolicy/resourcepolicyplugin.cpp
deleted file mode 100644
index bc78d6fbe..000000000
--- a/src/plugins/resourcepolicy/resourcepolicyplugin.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd, author: <robin.burchell@jollamobile.com>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QDebug>
-
-#include "resourcepolicyplugin.h"
-#include "resourcepolicyimpl.h"
-
-ResourcePolicyPlugin::ResourcePolicyPlugin(QObject *parent)
- : QMediaResourcePolicyPlugin(parent)
-{
-}
-
-QObject *ResourcePolicyPlugin::create(const QString &interfaceId)
-{
- // TODO: what is interfaceId for?
- return new ResourcePolicyImpl(this);
-}
-
-void ResourcePolicyPlugin::destroy(QObject *resourceSet)
-{
- // TODO: do we need to do anything more elaborate here?
- delete resourceSet;
-}
-
diff --git a/src/plugins/resourcepolicy/resourcepolicyplugin.h b/src/plugins/resourcepolicy/resourcepolicyplugin.h
deleted file mode 100644
index 6661c73de..000000000
--- a/src/plugins/resourcepolicy/resourcepolicyplugin.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd, author: <robin.burchell@jollamobile.com>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef RESOURCEPOLICYPLUGIN_H
-#define RESOURCEPOLICYPLUGIN_H
-
-#include <private/qmediaresourcepolicyplugin_p.h>
-#include <QObject>
-
-class ResourcePolicyPlugin : public QMediaResourcePolicyPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaresourcesetfactory/5.0" FILE "resourcepolicy.json")
- Q_INTERFACES(QMediaResourceSetFactoryInterface)
-public:
- ResourcePolicyPlugin(QObject *parent = 0);
-
- QObject *create(const QString &interfaceId);
- void destroy(QObject *resourceSet);
-};
-
-#endif // RESOURCEPOLICYPLUGIN_H
diff --git a/src/plugins/videonode/CMakeLists.txt b/src/plugins/videonode/CMakeLists.txt
new file mode 100644
index 000000000..176628276
--- /dev/null
+++ b/src/plugins/videonode/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Generated from videonode.pro.
+
+if(QT_FEATURE_gpu_vivante)
+ add_subdirectory(imx6)
+endif()
diff --git a/src/plugins/videonode/imx6/CMakeLists.txt b/src/plugins/videonode/imx6/CMakeLists.txt
new file mode 100644
index 000000000..659f73469
--- /dev/null
+++ b/src/plugins/videonode/imx6/CMakeLists.txt
@@ -0,0 +1,43 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Generated from imx6.pro.
+
+#####################################################################
+## QSGVivanteVideoNodeFactory Plugin:
+#####################################################################
+
+qt_internal_add_plugin(QSGVivanteVideoNodeFactoryPlugin
+ OUTPUT_NAME imx6vivantevideonode
+ PLUGIN_TYPE video/videonode
+ CLASS_NAME QSGVivanteVideoNodeFactory
+ SOURCES
+ qsgvivantevideomaterial.cpp qsgvivantevideomaterial.h
+ qsgvivantevideomaterialshader.cpp qsgvivantevideomaterialshader.h
+ qsgvivantevideonode.cpp qsgvivantevideonode.h
+ qsgvivantevideonodefactory.cpp qsgvivantevideonodefactory.h
+ LIBRARIES
+ Qt::Core
+ Qt::Gui
+ Qt::MultimediaPrivate
+ Qt::MultimediaQuickPrivate
+ GStreamer::GStreamer # special case
+)
+
+# Resources:
+set(imx6_resource_files
+ "shaders/rgba.frag.qsb"
+ "shaders/rgba.vert.qsb"
+)
+
+qt_internal_add_resource(QSGVivanteVideoNodeFactoryPlugin "imx6"
+ PREFIX
+ "/imx6"
+ FILES
+ ${imx6_resource_files}
+)
+
+
+#### Keys ignored in scope 1:.:.:imx6.pro:<TRUE>:
+# OTHER_FILES = "imx6.json"
+# PLUGIN_EXTENDS = "quick"
diff --git a/src/plugins/videonode/imx6/imx6.pro b/src/plugins/videonode/imx6/imx6.pro
deleted file mode 100644
index 4b2a2e720..000000000
--- a/src/plugins/videonode/imx6/imx6.pro
+++ /dev/null
@@ -1,28 +0,0 @@
-TARGET = imx6vivantevideonode
-
-QT += multimedia-private qtmultimediaquicktools-private multimediagsttools-private
-
-QMAKE_USE += gstreamer
-
-HEADERS += \
- qsgvivantevideonode.h \
- qsgvivantevideomaterialshader.h \
- qsgvivantevideomaterial.h \
- qsgvivantevideonodefactory.h
-
-SOURCES += \
- qsgvivantevideonode.cpp \
- qsgvivantevideomaterialshader.cpp \
- qsgvivantevideomaterial.cpp \
- qsgvivantevideonodefactory.cpp
-
-OTHER_FILES += \
- imx6.json
-
-RESOURCES += \
- imx6.qrc
-
-PLUGIN_TYPE = video/videonode
-PLUGIN_EXTENDS = quick
-PLUGIN_CLASS_NAME = QSGVivanteVideoNodeFactory
-load(qt_plugin)
diff --git a/src/plugins/videonode/imx6/imx6.qrc b/src/plugins/videonode/imx6/imx6.qrc
deleted file mode 100644
index c64fa4c64..000000000
--- a/src/plugins/videonode/imx6/imx6.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<RCC>
- <qresource prefix="/imx6">
- <file>shaders/rgba.vert.qsb</file>
- <file>shaders/rgba.frag.qsb</file>
- </qresource>
-</RCC>
diff --git a/src/plugins/videonode/imx6/qsgvivantevideomaterial.cpp b/src/plugins/videonode/imx6/qsgvivantevideomaterial.cpp
index 2e6c712e3..599dbb9e2 100644
--- a/src/plugins/videonode/imx6/qsgvivantevideomaterial.cpp
+++ b/src/plugins/videonode/imx6/qsgvivantevideomaterial.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Pelagicore AG
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Pelagicore AG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
@@ -44,6 +8,7 @@
#include "qsgvivantevideomaterialshader.h"
#include "qsgvivantevideonode.h"
#include "private/qsgvideotexture_p.h"
+#include "private/qvideoframe_p.h"
#include <QOpenGLContext>
#include <QThread>
@@ -52,7 +17,9 @@
#include <QtMultimedia/private/qtmultimediaglobal_p.h>
#include "private/qgstvideobuffer_p.h"
+#if GST_CHECK_VERSION(1,14,0)
#include <gst/allocators/gstphysmemory.h>
+#endif
//#define QT_VIVANTE_VIDEO_DEBUG
@@ -60,7 +27,7 @@ QSGVivanteVideoMaterial::QSGVivanteVideoMaterial() :
mOpacity(1.0),
mWidth(0),
mHeight(0),
- mFormat(QVideoFrame::Format_Invalid),
+ mFormat(QVideoFrameFormat::Format_Invalid),
mCurrentTexture(0),
mMappable(true),
mTexDirectTexture(0)
@@ -107,7 +74,7 @@ void QSGVivanteVideoMaterial::setCurrentFrame(const QVideoFrame &frame, QSGVideo
{
QMutexLocker lock(&mFrameMutex);
mCurrentFrame = frame;
- mMappable = mMapError == GL_NO_ERROR && !flags.testFlag(QSGVideoNode::FrameFiltered);
+ mMappable = mMapError == GL_NO_ERROR;
#ifdef QT_VIVANTE_VIDEO_DEBUG
qDebug() << Q_FUNC_INFO << " new frame: " << frame;
@@ -176,7 +143,7 @@ GLuint QSGVivanteVideoMaterial::vivanteMapping(QVideoFrame vF)
clearTextures();
}
- if (vF.map(QAbstractVideoBuffer::ReadOnly)) {
+ if (vF.map(QtVideo::MapMode::ReadOnly)) {
if (mMappable) {
if (!mBitsToTextureMap.contains(vF.bits())) {
@@ -225,7 +192,7 @@ GLuint QSGVivanteVideoMaterial::vivanteMapping(QVideoFrame vF)
GLuint physical = ~0U;
#if GST_CHECK_VERSION(1,14,0)
- auto buffer = reinterpret_cast<QGstVideoBuffer *>(vF.buffer());
+ auto buffer = reinterpret_cast<QGstVideoBuffer *>(QVideoFramePrivate::buffer(vF));
auto mem = gst_buffer_peek_memory(buffer->buffer(), 0);
auto phys_addr = gst_is_phys_memory(mem) ? gst_phys_memory_get_phys_addr(mem) : 0;
if (phys_addr)
@@ -273,14 +240,14 @@ GLuint QSGVivanteVideoMaterial::vivanteMapping(QVideoFrame vF)
glBindTexture(GL_TEXTURE_2D, mTexDirectTexture);
}
switch (mCurrentFrame.pixelFormat()) {
- case QVideoFrame::Format_YUV420P:
- case QVideoFrame::Format_YV12:
+ case QVideoFrameFormat::Format_YUV420P:
+ case QVideoFrameFormat::Format_YV12:
memcpy(mTexDirectPlanes[0], mCurrentFrame.bits(0), mCurrentFrame.height() * mCurrentFrame.bytesPerLine(0));
memcpy(mTexDirectPlanes[1], mCurrentFrame.bits(1), mCurrentFrame.height() / 2 * mCurrentFrame.bytesPerLine(1));
memcpy(mTexDirectPlanes[2], mCurrentFrame.bits(2), mCurrentFrame.height() / 2 * mCurrentFrame.bytesPerLine(2));
break;
- case QVideoFrame::Format_NV12:
- case QVideoFrame::Format_NV21:
+ case QVideoFrameFormat::Format_NV12:
+ case QVideoFrameFormat::Format_NV21:
memcpy(mTexDirectPlanes[0], mCurrentFrame.bits(0), mCurrentFrame.height() * mCurrentFrame.bytesPerLine(0));
memcpy(mTexDirectPlanes[1], mCurrentFrame.bits(1), mCurrentFrame.height() / 2 * mCurrentFrame.bytesPerLine(1));
break;
diff --git a/src/plugins/videonode/imx6/qsgvivantevideomaterial.h b/src/plugins/videonode/imx6/qsgvivantevideomaterial.h
index 10fd5447f..0c3976e3a 100644
--- a/src/plugins/videonode/imx6/qsgvivantevideomaterial.h
+++ b/src/plugins/videonode/imx6/qsgvivantevideomaterial.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Pelagicore AG
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Pelagicore AG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSGVIDEOMATERIAL_VIVMAP_H
#define QSGVIDEOMATERIAL_VIVMAP_H
@@ -75,7 +39,7 @@ private:
int mWidth;
int mHeight;
- QVideoFrame::PixelFormat mFormat;
+ QVideoFrameFormat::PixelFormat mFormat;
QMap<const uchar*, GLuint> mBitsToTextureMap;
QVideoFrame mCurrentFrame;
diff --git a/src/plugins/videonode/imx6/qsgvivantevideomaterialshader.cpp b/src/plugins/videonode/imx6/qsgvivantevideomaterialshader.cpp
index 9e529c3df..ed78192b6 100644
--- a/src/plugins/videonode/imx6/qsgvivantevideomaterialshader.cpp
+++ b/src/plugins/videonode/imx6/qsgvivantevideomaterialshader.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Pelagicore AG
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Pelagicore AG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsgvivantevideomaterialshader.h"
#include "qsgvivantevideonode.h"
diff --git a/src/plugins/videonode/imx6/qsgvivantevideomaterialshader.h b/src/plugins/videonode/imx6/qsgvivantevideomaterialshader.h
index b0e19d28e..73edff7d2 100644
--- a/src/plugins/videonode/imx6/qsgvivantevideomaterialshader.h
+++ b/src/plugins/videonode/imx6/qsgvivantevideomaterialshader.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Pelagicore AG
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Pelagicore AG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSGVIDEOMATERIALSHADER_VIVANTE_H
#define QSGVIDEOMATERIALSHADER_VIVANTE_H
diff --git a/src/plugins/videonode/imx6/qsgvivantevideonode.cpp b/src/plugins/videonode/imx6/qsgvivantevideonode.cpp
index c8d83b4b2..a800c0e62 100644
--- a/src/plugins/videonode/imx6/qsgvivantevideonode.cpp
+++ b/src/plugins/videonode/imx6/qsgvivantevideonode.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Pelagicore AG
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Pelagicore AG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
@@ -44,9 +8,9 @@
#include "qsgvivantevideomaterialshader.h"
#include "qsgvivantevideomaterial.h"
-QMap<QVideoFrame::PixelFormat, GLenum> QSGVivanteVideoNode::static_VideoFormat2GLFormatMap = QMap<QVideoFrame::PixelFormat, GLenum>();
+QMap<QVideoFrameFormat::PixelFormat, GLenum> QSGVivanteVideoNode::static_VideoFormat2GLFormatMap = QMap<QVideoFrameFormat::PixelFormat, GLenum>();
-QSGVivanteVideoNode::QSGVivanteVideoNode(const QVideoSurfaceFormat &format) :
+QSGVivanteVideoNode::QSGVivanteVideoNode(const QVideoFrameFormat &format) :
mFormat(format)
{
setFlag(QSGNode::OwnsMaterial, true);
@@ -64,40 +28,38 @@ void QSGVivanteVideoNode::setCurrentFrame(const QVideoFrame &frame, FrameFlags f
markDirty(DirtyMaterial);
}
-const QMap<QVideoFrame::PixelFormat, GLenum>& QSGVivanteVideoNode::getVideoFormat2GLFormatMap()
+const QMap<QVideoFrameFormat::PixelFormat, GLenum>& QSGVivanteVideoNode::getVideoFormat2GLFormatMap()
{
if (static_VideoFormat2GLFormatMap.isEmpty()) {
- static_VideoFormat2GLFormatMap.insert(QVideoFrame::Format_YUV420P, GL_VIV_I420);
- static_VideoFormat2GLFormatMap.insert(QVideoFrame::Format_YV12, GL_VIV_YV12);
- static_VideoFormat2GLFormatMap.insert(QVideoFrame::Format_NV12, GL_VIV_NV12);
- static_VideoFormat2GLFormatMap.insert(QVideoFrame::Format_NV21, GL_VIV_NV21);
- static_VideoFormat2GLFormatMap.insert(QVideoFrame::Format_UYVY, GL_VIV_UYVY);
- static_VideoFormat2GLFormatMap.insert(QVideoFrame::Format_YUYV, GL_VIV_YUY2);
- static_VideoFormat2GLFormatMap.insert(QVideoFrame::Format_RGB32, GL_BGRA_EXT);
- static_VideoFormat2GLFormatMap.insert(QVideoFrame::Format_ARGB32, GL_BGRA_EXT);
- static_VideoFormat2GLFormatMap.insert(QVideoFrame::Format_BGR32, GL_RGBA);
- static_VideoFormat2GLFormatMap.insert(QVideoFrame::Format_BGRA32, GL_RGBA);
- static_VideoFormat2GLFormatMap.insert(QVideoFrame::Format_RGB565, GL_RGB565);
+ static_VideoFormat2GLFormatMap.insert(QVideoFrameFormat::Format_YUV420P, GL_VIV_I420);
+ static_VideoFormat2GLFormatMap.insert(QVideoFrameFormat::Format_YV12, GL_VIV_YV12);
+ static_VideoFormat2GLFormatMap.insert(QVideoFrameFormat::Format_NV12, GL_VIV_NV12);
+ static_VideoFormat2GLFormatMap.insert(QVideoFrameFormat::Format_NV21, GL_VIV_NV21);
+ static_VideoFormat2GLFormatMap.insert(QVideoFrameFormat::Format_UYVY, GL_VIV_UYVY);
+ static_VideoFormat2GLFormatMap.insert(QVideoFrameFormat::Format_YUYV, GL_VIV_YUY2);
+ static_VideoFormat2GLFormatMap.insert(QVideoFrameFormat::Format_RGB32, GL_BGRA_EXT);
+ static_VideoFormat2GLFormatMap.insert(QVideoFrameFormat::Format_ARGB32, GL_BGRA_EXT);
+ static_VideoFormat2GLFormatMap.insert(QVideoFrameFormat::Format_BGR32, GL_RGBA);
+ static_VideoFormat2GLFormatMap.insert(QVideoFrameFormat::Format_BGRA32, GL_RGBA);
}
return static_VideoFormat2GLFormatMap;
}
-int QSGVivanteVideoNode::getBytesForPixelFormat(QVideoFrame::PixelFormat pixelformat)
+int QSGVivanteVideoNode::getBytesForPixelFormat(QVideoFrameFormat::PixelFormat pixelformat)
{
switch (pixelformat) {
- case QVideoFrame::Format_YUV420P: return 1;
- case QVideoFrame::Format_YV12: return 1;
- case QVideoFrame::Format_NV12: return 1;
- case QVideoFrame::Format_NV21: return 1;
- case QVideoFrame::Format_UYVY: return 2;
- case QVideoFrame::Format_YUYV: return 2;
- case QVideoFrame::Format_RGB32: return 4;
- case QVideoFrame::Format_ARGB32: return 4;
- case QVideoFrame::Format_BGR32: return 4;
- case QVideoFrame::Format_BGRA32: return 4;
- case QVideoFrame::Format_RGB565: return 2;
+ case QVideoFrameFormat::Format_YUV420P: return 1;
+ case QVideoFrameFormat::Format_YV12: return 1;
+ case QVideoFrameFormat::Format_NV12: return 1;
+ case QVideoFrameFormat::Format_NV21: return 1;
+ case QVideoFrameFormat::Format_UYVY: return 2;
+ case QVideoFrameFormat::Format_YUYV: return 2;
+ case QVideoFrameFormat::Format_RGB32: return 4;
+ case QVideoFrameFormat::Format_ARGB32: return 4;
+ case QVideoFrameFormat::Format_BGR32: return 4;
+ case QVideoFrameFormat::Format_BGRA32: return 4;
default: return 1;
}
}
diff --git a/src/plugins/videonode/imx6/qsgvivantevideonode.h b/src/plugins/videonode/imx6/qsgvivantevideonode.h
index 2796f1e44..05ab4f25b 100644
--- a/src/plugins/videonode/imx6/qsgvivantevideonode.h
+++ b/src/plugins/videonode/imx6/qsgvivantevideonode.h
@@ -1,67 +1,31 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Pelagicore AG
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Pelagicore AG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSGVIDEONODE_VIVANTE_H
#define QSGVIDEONODE_VIVANTE_H
#include <private/qsgvideonode_p.h>
-#include <QVideoSurfaceFormat>
+#include <QVideoFrameFormat>
class QSGVivanteVideoMaterial;
class QSGVivanteVideoNode : public QSGVideoNode
{
public:
- QSGVivanteVideoNode(const QVideoSurfaceFormat &format);
+ QSGVivanteVideoNode(const QVideoFrameFormat &format);
~QSGVivanteVideoNode();
- QVideoFrame::PixelFormat pixelFormat() const { return mFormat.pixelFormat(); }
- QAbstractVideoBuffer::HandleType handleType() const { return QAbstractVideoBuffer::NoHandle; }
+ QVideoFrameFormat::PixelFormat pixelFormat() const { return mFormat.pixelFormat(); }
+ QVideoFrame::HandleType handleType() const { return QVideoFrame::NoHandle; }
void setCurrentFrame(const QVideoFrame &frame, FrameFlags flags);
- static const QMap<QVideoFrame::PixelFormat, GLenum>& getVideoFormat2GLFormatMap();
- static int getBytesForPixelFormat(QVideoFrame::PixelFormat pixelformat);
+ static const QMap<QVideoFrameFormat::PixelFormat, GLenum>& getVideoFormat2GLFormatMap();
+ static int getBytesForPixelFormat(QVideoFrameFormat::PixelFormat pixelformat);
private:
- QVideoSurfaceFormat mFormat;
+ QVideoFrameFormat mFormat;
QSGVivanteVideoMaterial *mMaterial;
- static QMap<QVideoFrame::PixelFormat, GLenum> static_VideoFormat2GLFormatMap;
+ static QMap<QVideoFrameFormat::PixelFormat, GLenum> static_VideoFormat2GLFormatMap;
};
#endif // QSGVIDEONODE_VIVANTE_H
diff --git a/src/plugins/videonode/imx6/qsgvivantevideonodefactory.cpp b/src/plugins/videonode/imx6/qsgvivantevideonodefactory.cpp
index 55ed57c10..ca6550776 100644
--- a/src/plugins/videonode/imx6/qsgvivantevideonodefactory.cpp
+++ b/src/plugins/videonode/imx6/qsgvivantevideonodefactory.cpp
@@ -1,57 +1,21 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Pelagicore AG
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Pelagicore AG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsgvivantevideonodefactory.h"
#include "qsgvivantevideonode.h"
#include <QtGui/QGuiApplication>
-QList<QVideoFrame::PixelFormat> QSGVivanteVideoNodeFactory::supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const
+QList<QVideoFrameFormat::PixelFormat> QSGVivanteVideoNodeFactory::supportedPixelFormats(
+ QVideoFrame::HandleType handleType) const
{
const bool isWebGl = QGuiApplication::platformName() == QLatin1String("webgl");
- if (!isWebGl && handleType == QAbstractVideoBuffer::NoHandle)
+ if (!isWebGl && handleType == QVideoFrame::NoHandle)
return QSGVivanteVideoNode::getVideoFormat2GLFormatMap().keys();
else
- return QList<QVideoFrame::PixelFormat>();
+ return QList<QVideoFrameFormat::PixelFormat>();
}
-QSGVideoNode *QSGVivanteVideoNodeFactory::createNode(const QVideoSurfaceFormat &format)
+QSGVideoNode *QSGVivanteVideoNodeFactory::createNode(const QVideoFrameFormat &format)
{
if (supportedPixelFormats(format.handleType()).contains(format.pixelFormat())) {
return new QSGVivanteVideoNode(format);
diff --git a/src/plugins/videonode/imx6/qsgvivantevideonodefactory.h b/src/plugins/videonode/imx6/qsgvivantevideonodefactory.h
index dfb6a0123..d81582788 100644
--- a/src/plugins/videonode/imx6/qsgvivantevideonodefactory.h
+++ b/src/plugins/videonode/imx6/qsgvivantevideonodefactory.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Pelagicore AG
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Pelagicore AG
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSGVIDEONODEFACTORY_VIVANTE_H
#define QSGVIDEONODEFACTORY_VIVANTE_H
@@ -50,7 +14,7 @@ public:
Q_PLUGIN_METADATA(IID QSGVideoNodeFactoryInterface_iid FILE "imx6.json")
Q_INTERFACES(QSGVideoNodeFactoryInterface)
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const;
- QSGVideoNode *createNode(const QVideoSurfaceFormat &format);
+ QList<QVideoFrameFormat::PixelFormat> supportedPixelFormats(QVideoFrame::HandleType handleType) const;
+ QSGVideoNode *createNode(const QVideoFrameFormat &format);
};
#endif // QSGVIDEONODEFACTORY_VIVANTE_H
diff --git a/src/plugins/videonode/imx6/shaders/compile.bat b/src/plugins/videonode/imx6/shaders/compile.bat
index 712bee6c5..5827ee9c0 100755
--- a/src/plugins/videonode/imx6/shaders/compile.bat
+++ b/src/plugins/videonode/imx6/shaders/compile.bat
@@ -1,41 +1,5 @@
-:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-::
:: Copyright (C) 2020 The Qt Company Ltd.
-:: Contact: https://www.qt.io/licensing/
-::
-:: This file is part of the QtQuick module of the Qt Toolkit.
-::
-:: $QT_BEGIN_LICENSE:LGPL$
-:: Commercial License Usage
-:: Licensees holding valid commercial Qt licenses may use this file in
-:: accordance with the commercial license agreement provided with the
-:: Software or, alternatively, in accordance with the terms contained in
-:: a written agreement between you and The Qt Company. For licensing terms
-:: and conditions see https://www.qt.io/terms-conditions. For further
-:: information use the contact form at https://www.qt.io/contact-us.
-::
-:: GNU Lesser General Public License Usage
-:: Alternatively, this file may be used under the terms of the GNU Lesser
-:: General Public License version 3 as published by the Free Software
-:: Foundation and appearing in the file LICENSE.LGPL3 included in the
-:: packaging of this file. Please review the following information to
-:: ensure the GNU Lesser General Public License version 3 requirements
-:: will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-::
-:: GNU General Public License Usage
-:: Alternatively, this file may be used under the terms of the GNU
-:: General Public License version 2.0 or (at your option) the GNU General
-:: Public license version 3 or any later version approved by the KDE Free
-:: Qt Foundation. The licenses are as published by the Free Software
-:: Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-:: included in the packaging of this file. Please review the following
-:: information to ensure the GNU General Public License requirements will
-:: be met: https://www.gnu.org/licenses/gpl-2.0.html and
-:: https://www.gnu.org/licenses/gpl-3.0.html.
-::
-:: $QT_END_LICENSE$
-::
-:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+:: SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o rgba.vert.qsb rgba.vert
qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o rgba.frag.qsb rgba.frag
diff --git a/src/plugins/videonode/videonode.pro b/src/plugins/videonode/videonode.pro
deleted file mode 100644
index b8bd43329..000000000
--- a/src/plugins/videonode/videonode.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-TEMPLATE = subdirs
-QT_FOR_CONFIG += gui-private multimedia-private
-
-qtConfig(gpu_vivante) {
- SUBDIRS += imx6
-}
diff --git a/src/plugins/windowsaudio/qwindowsaudiodeviceinfo.cpp b/src/plugins/windowsaudio/qwindowsaudiodeviceinfo.cpp
deleted file mode 100644
index 72d142da9..000000000
--- a/src/plugins/windowsaudio/qwindowsaudiodeviceinfo.cpp
+++ /dev/null
@@ -1,469 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// INTERNAL USE ONLY: Do NOT use for any other purpose.
-//
-
-
-#include <QtCore/qt_windows.h>
-#include <QtCore/QDataStream>
-#include <QtCore/QIODevice>
-#include <mmsystem.h>
-#include "qwindowsaudiodeviceinfo.h"
-#include "qwindowsaudioutils.h"
-
-#if defined(Q_CC_MINGW) && !defined(__MINGW64_VERSION_MAJOR)
-struct IBaseFilter; // Needed for strmif.h from stock MinGW.
-struct _DDPIXELFORMAT;
-typedef struct _DDPIXELFORMAT* LPDDPIXELFORMAT;
-#endif
-
-#include <strmif.h>
-#if !defined(Q_CC_MINGW) || defined(__MINGW64_VERSION_MAJOR)
-# include <uuids.h>
-#else
-
-extern GUID CLSID_AudioInputDeviceCategory;
-extern GUID CLSID_AudioRendererCategory;
-extern GUID IID_ICreateDevEnum;
-extern GUID CLSID_SystemDeviceEnum;
-
-#ifndef __ICreateDevEnum_INTERFACE_DEFINED__
-#define __ICreateDevEnum_INTERFACE_DEFINED__
-
-DECLARE_INTERFACE_(ICreateDevEnum, IUnknown)
-{
- STDMETHOD(CreateClassEnumerator)(REFCLSID clsidDeviceClass,
- IEnumMoniker **ppEnumMoniker,
- DWORD dwFlags) PURE;
-};
-
-#endif // __ICreateDevEnum_INTERFACE_DEFINED__
-
-#ifndef __IErrorLog_INTERFACE_DEFINED__
-#define __IErrorLog_INTERFACE_DEFINED__
-
-DECLARE_INTERFACE_(IErrorLog, IUnknown)
-{
- STDMETHOD(AddError)(THIS_ LPCOLESTR, EXCEPINFO *) PURE;
-};
-
-#endif /* __IErrorLog_INTERFACE_DEFINED__ */
-
-#ifndef __IPropertyBag_INTERFACE_DEFINED__
-#define __IPropertyBag_INTERFACE_DEFINED__
-
-const GUID IID_IPropertyBag = {0x55272A00, 0x42CB, 0x11CE, {0x81, 0x35, 0x00, 0xAA, 0x00, 0x4B, 0xB8, 0x51}};
-
-DECLARE_INTERFACE_(IPropertyBag, IUnknown)
-{
- STDMETHOD(Read)(THIS_ LPCOLESTR, VARIANT *, IErrorLog *) PURE;
- STDMETHOD(Write)(THIS_ LPCOLESTR, VARIANT *) PURE;
-};
-
-#endif /* __IPropertyBag_INTERFACE_DEFINED__ */
-
-#endif // defined(Q_CC_MINGW) && !defined(__MINGW64_VERSION_MAJOR)
-
-QT_BEGIN_NAMESPACE
-
-// For mingw toolchain mmsystem.h only defines half the defines, so add if needed.
-#ifndef WAVE_FORMAT_44M08
-#define WAVE_FORMAT_44M08 0x00000100
-#define WAVE_FORMAT_44S08 0x00000200
-#define WAVE_FORMAT_44M16 0x00000400
-#define WAVE_FORMAT_44S16 0x00000800
-#define WAVE_FORMAT_48M08 0x00001000
-#define WAVE_FORMAT_48S08 0x00002000
-#define WAVE_FORMAT_48M16 0x00004000
-#define WAVE_FORMAT_48S16 0x00008000
-#define WAVE_FORMAT_96M08 0x00010000
-#define WAVE_FORMAT_96S08 0x00020000
-#define WAVE_FORMAT_96M16 0x00040000
-#define WAVE_FORMAT_96S16 0x00080000
-#endif
-
-
-QWindowsAudioDeviceInfo::QWindowsAudioDeviceInfo(QByteArray dev, QAudio::Mode mode)
-{
- QDataStream ds(&dev, QIODevice::ReadOnly);
- ds >> devId >> device;
- this->mode = mode;
-
- updateLists();
-}
-
-QWindowsAudioDeviceInfo::~QWindowsAudioDeviceInfo()
-{
- close();
-}
-
-bool QWindowsAudioDeviceInfo::isFormatSupported(const QAudioFormat& format) const
-{
- return testSettings(format);
-}
-
-QAudioFormat QWindowsAudioDeviceInfo::preferredFormat() const
-{
- QAudioFormat nearest;
- if (mode == QAudio::AudioOutput) {
- nearest.setSampleRate(44100);
- nearest.setChannelCount(2);
- nearest.setByteOrder(QAudioFormat::LittleEndian);
- nearest.setSampleType(QAudioFormat::SignedInt);
- nearest.setSampleSize(16);
- nearest.setCodec(QLatin1String("audio/pcm"));
- } else {
- nearest.setSampleRate(11025);
- nearest.setChannelCount(1);
- nearest.setByteOrder(QAudioFormat::LittleEndian);
- nearest.setSampleType(QAudioFormat::SignedInt);
- nearest.setSampleSize(8);
- nearest.setCodec(QLatin1String("audio/pcm"));
- }
- return nearest;
-}
-
-QString QWindowsAudioDeviceInfo::deviceName() const
-{
- return device;
-}
-
-QStringList QWindowsAudioDeviceInfo::supportedCodecs()
-{
- return QStringList() << QStringLiteral("audio/pcm");
-}
-
-QList<int> QWindowsAudioDeviceInfo::supportedSampleRates()
-{
- updateLists();
- return sampleRatez;
-}
-
-QList<int> QWindowsAudioDeviceInfo::supportedChannelCounts()
-{
- updateLists();
- return channelz;
-}
-
-QList<int> QWindowsAudioDeviceInfo::supportedSampleSizes()
-{
- updateLists();
- return sizez;
-}
-
-QList<QAudioFormat::Endian> QWindowsAudioDeviceInfo::supportedByteOrders()
-{
- return QList<QAudioFormat::Endian>() << QAudioFormat::LittleEndian;
-}
-
-QList<QAudioFormat::SampleType> QWindowsAudioDeviceInfo::supportedSampleTypes()
-{
- updateLists();
- return typez;
-}
-
-
-bool QWindowsAudioDeviceInfo::open()
-{
- return true;
-}
-
-void QWindowsAudioDeviceInfo::close()
-{
-}
-
-bool QWindowsAudioDeviceInfo::testSettings(const QAudioFormat& format) const
-{
- WAVEFORMATEXTENSIBLE wfx;
- if (qt_convertFormat(format, &wfx)) {
- // query only, do not open device
- if (mode == QAudio::AudioOutput) {
- return (waveOutOpen(NULL, UINT_PTR(devId), &wfx.Format, 0, 0,
- WAVE_FORMAT_QUERY) == MMSYSERR_NOERROR);
- } else { // AudioInput
- return (waveInOpen(NULL, UINT_PTR(devId), &wfx.Format, 0, 0,
- WAVE_FORMAT_QUERY) == MMSYSERR_NOERROR);
- }
- }
-
- return false;
-}
-
-void QWindowsAudioDeviceInfo::updateLists()
-{
- if (!sizez.isEmpty())
- return;
-
- DWORD fmt = 0;
-
- if(mode == QAudio::AudioOutput) {
- WAVEOUTCAPS woc;
- if (waveOutGetDevCaps(devId, &woc, sizeof(WAVEOUTCAPS)) == MMSYSERR_NOERROR)
- fmt = woc.dwFormats;
- } else {
- WAVEINCAPS woc;
- if (waveInGetDevCaps(devId, &woc, sizeof(WAVEINCAPS)) == MMSYSERR_NOERROR)
- fmt = woc.dwFormats;
- }
-
- sizez.clear();
- sampleRatez.clear();
- channelz.clear();
- typez.clear();
-
- if (fmt) {
- // Check sample size
- if ((fmt & WAVE_FORMAT_1M08)
- || (fmt & WAVE_FORMAT_1S08)
- || (fmt & WAVE_FORMAT_2M08)
- || (fmt & WAVE_FORMAT_2S08)
- || (fmt & WAVE_FORMAT_4M08)
- || (fmt & WAVE_FORMAT_4S08)
- || (fmt & WAVE_FORMAT_48M08)
- || (fmt & WAVE_FORMAT_48S08)
- || (fmt & WAVE_FORMAT_96M08)
- || (fmt & WAVE_FORMAT_96S08)) {
- sizez.append(8);
- }
- if ((fmt & WAVE_FORMAT_1M16)
- || (fmt & WAVE_FORMAT_1S16)
- || (fmt & WAVE_FORMAT_2M16)
- || (fmt & WAVE_FORMAT_2S16)
- || (fmt & WAVE_FORMAT_4M16)
- || (fmt & WAVE_FORMAT_4S16)
- || (fmt & WAVE_FORMAT_48M16)
- || (fmt & WAVE_FORMAT_48S16)
- || (fmt & WAVE_FORMAT_96M16)
- || (fmt & WAVE_FORMAT_96S16)) {
- sizez.append(16);
- }
-
- // Check sample rate
- if ((fmt & WAVE_FORMAT_1M08)
- || (fmt & WAVE_FORMAT_1S08)
- || (fmt & WAVE_FORMAT_1M16)
- || (fmt & WAVE_FORMAT_1S16)) {
- sampleRatez.append(11025);
- }
- if ((fmt & WAVE_FORMAT_2M08)
- || (fmt & WAVE_FORMAT_2S08)
- || (fmt & WAVE_FORMAT_2M16)
- || (fmt & WAVE_FORMAT_2S16)) {
- sampleRatez.append(22050);
- }
- if ((fmt & WAVE_FORMAT_4M08)
- || (fmt & WAVE_FORMAT_4S08)
- || (fmt & WAVE_FORMAT_4M16)
- || (fmt & WAVE_FORMAT_4S16)) {
- sampleRatez.append(44100);
- }
- if ((fmt & WAVE_FORMAT_48M08)
- || (fmt & WAVE_FORMAT_48S08)
- || (fmt & WAVE_FORMAT_48M16)
- || (fmt & WAVE_FORMAT_48S16)) {
- sampleRatez.append(48000);
- }
- if ((fmt & WAVE_FORMAT_96M08)
- || (fmt & WAVE_FORMAT_96S08)
- || (fmt & WAVE_FORMAT_96M16)
- || (fmt & WAVE_FORMAT_96S16)) {
- sampleRatez.append(96000);
- }
-
- // Check channel count
- if (fmt & WAVE_FORMAT_1M08
- || fmt & WAVE_FORMAT_1M16
- || fmt & WAVE_FORMAT_2M08
- || fmt & WAVE_FORMAT_2M16
- || fmt & WAVE_FORMAT_4M08
- || fmt & WAVE_FORMAT_4M16
- || fmt & WAVE_FORMAT_48M08
- || fmt & WAVE_FORMAT_48M16
- || fmt & WAVE_FORMAT_96M08
- || fmt & WAVE_FORMAT_96M16) {
- channelz.append(1);
- }
- if (fmt & WAVE_FORMAT_1S08
- || fmt & WAVE_FORMAT_1S16
- || fmt & WAVE_FORMAT_2S08
- || fmt & WAVE_FORMAT_2S16
- || fmt & WAVE_FORMAT_4S08
- || fmt & WAVE_FORMAT_4S16
- || fmt & WAVE_FORMAT_48S08
- || fmt & WAVE_FORMAT_48S16
- || fmt & WAVE_FORMAT_96S08
- || fmt & WAVE_FORMAT_96S16) {
- channelz.append(2);
- }
-
- typez.append(QAudioFormat::SignedInt);
- typez.append(QAudioFormat::UnSignedInt);
-
- // WAVEOUTCAPS and WAVEINCAPS contains information only for the previously tested parameters.
- // WaveOut and WaveInt might actually support more formats, the only way to know is to try
- // opening the device with it.
- QAudioFormat testFormat;
- testFormat.setCodec(QStringLiteral("audio/pcm"));
- testFormat.setByteOrder(QAudioFormat::LittleEndian);
- testFormat.setSampleType(QAudioFormat::SignedInt);
- testFormat.setChannelCount(channelz.first());
- testFormat.setSampleRate(sampleRatez.at(sampleRatez.size() / 2));
- testFormat.setSampleSize(sizez.last());
- const QAudioFormat defaultTestFormat(testFormat);
-
- // Check if float samples are supported
- testFormat.setSampleType(QAudioFormat::Float);
- testFormat.setSampleSize(32);
- if (testSettings(testFormat))
- typez.append(QAudioFormat::Float);
-
- // Check channel counts > 2
- testFormat = defaultTestFormat;
- for (int i = 3; i < 19; ++i) { // <mmreg.h> defines 18 different channels
- testFormat.setChannelCount(i);
- if (testSettings(testFormat))
- channelz.append(i);
- }
-
- // Check more sample sizes
- testFormat = defaultTestFormat;
- const QList<int> testSampleSizes = QList<int>() << 24 << 32 << 48 << 64;
- for (int s : testSampleSizes) {
- testFormat.setSampleSize(s);
- if (testSettings(testFormat))
- sizez.append(s);
- }
-
- // Check more sample rates
- testFormat = defaultTestFormat;
- const QList<int> testSampleRates = QList<int>() << 8000 << 16000 << 32000 << 88200 << 192000;
- for (int r : testSampleRates) {
- testFormat.setSampleRate(r);
- if (testSettings(testFormat))
- sampleRatez.append(r);
- }
- std::sort(sampleRatez.begin(), sampleRatez.end());
- }
-}
-
-QList<QByteArray> QWindowsAudioDeviceInfo::availableDevices(QAudio::Mode mode)
-{
- Q_UNUSED(mode);
-
- QList<QByteArray> devices;
- //enumerate device fullnames through directshow api
- auto hrCoInit = CoInitialize(nullptr);
- ICreateDevEnum *pDevEnum = NULL;
- IEnumMoniker *pEnum = NULL;
- // Create the System device enumerator
- HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
- CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
- reinterpret_cast<void **>(&pDevEnum));
-
- unsigned long iNumDevs = mode == QAudio::AudioOutput ? waveOutGetNumDevs() : waveInGetNumDevs();
- if (SUCCEEDED(hr)) {
- // Create the enumerator for the audio input/output category
- if (pDevEnum->CreateClassEnumerator(
- mode == QAudio::AudioOutput ? CLSID_AudioRendererCategory : CLSID_AudioInputDeviceCategory,
- &pEnum, 0) == S_OK) {
- pEnum->Reset();
- // go through and find all audio devices
- IMoniker *pMoniker = NULL;
- while (pEnum->Next(1, &pMoniker, NULL) == S_OK) {
- IPropertyBag *pPropBag;
- hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag,
- reinterpret_cast<void **>(&pPropBag));
- if (FAILED(hr)) {
- pMoniker->Release();
- continue; // skip this one
- }
- // Find if it is a wave device
- VARIANT var;
- VariantInit(&var);
- hr = pPropBag->Read(mode == QAudio::AudioOutput ? L"WaveOutID" : L"WaveInID", &var, 0);
- if (SUCCEEDED(hr)) {
- LONG waveID = var.lVal;
- if (waveID >= 0 && waveID < LONG(iNumDevs)) {
- VariantClear(&var);
- // Find the description
- hr = pPropBag->Read(L"FriendlyName", &var, 0);
- if (SUCCEEDED(hr)) {
- QByteArray device;
- QDataStream ds(&device, QIODevice::WriteOnly);
- ds << quint32(waveID) << QString::fromWCharArray(var.bstrVal);
- devices.append(device);
- }
- }
- }
-
- pPropBag->Release();
- pMoniker->Release();
- }
- pEnum->Release();
- }
- pDevEnum->Release();
- }
- if (SUCCEEDED(hrCoInit))
- CoUninitialize();
-
- return devices;
-}
-
-QByteArray QWindowsAudioDeviceInfo::defaultDevice(QAudio::Mode mode)
-{
- const QString &name = (mode == QAudio::AudioOutput) ? QStringLiteral("Default Output Device")
- : QStringLiteral("Default Input Device");
- QByteArray defaultDevice;
- QDataStream ds(&defaultDevice, QIODevice::WriteOnly);
- ds << quint32(WAVE_MAPPER) // device ID for default device
- << name;
-
- return defaultDevice;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/windowsaudio/qwindowsaudiodeviceinfo.h b/src/plugins/windowsaudio/qwindowsaudiodeviceinfo.h
deleted file mode 100644
index d84eb8acf..000000000
--- a/src/plugins/windowsaudio/qwindowsaudiodeviceinfo.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-
-#ifndef QWINDOWSAUDIODEVICEINFO_H
-#define QWINDOWSAUDIODEVICEINFO_H
-
-#include <QtCore/qbytearray.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qlist.h>
-#include <QtCore/qdebug.h>
-
-#include <QtMultimedia/qaudiodeviceinfo.h>
-#include <QtMultimedia/qaudiosystem.h>
-
-
-QT_BEGIN_NAMESPACE
-
-const unsigned int MAX_SAMPLE_RATES = 5;
-const unsigned int SAMPLE_RATES[] = { 8000, 11025, 22050, 44100, 48000 };
-
-class QWindowsAudioDeviceInfo : public QAbstractAudioDeviceInfo
-{
- Q_OBJECT
-
-public:
- QWindowsAudioDeviceInfo(QByteArray dev,QAudio::Mode mode);
- ~QWindowsAudioDeviceInfo();
-
- bool open();
- void close();
-
- bool testSettings(const QAudioFormat& format) const;
- void updateLists();
- QAudioFormat preferredFormat() const;
- bool isFormatSupported(const QAudioFormat& format) const;
- QString deviceName() const;
- QStringList supportedCodecs();
- QList<int> supportedSampleRates();
- QList<int> supportedChannelCounts();
- QList<int> supportedSampleSizes();
- QList<QAudioFormat::Endian> supportedByteOrders();
- QList<QAudioFormat::SampleType> supportedSampleTypes();
- static QByteArray defaultDevice(QAudio::Mode mode);
- static QList<QByteArray> availableDevices(QAudio::Mode);
-
-private:
- QAudio::Mode mode;
- QString device;
- quint32 devId;
- QList<int> sampleRatez;
- QList<int> channelz;
- QList<int> sizez;
- QList<QAudioFormat::SampleType> typez;
-};
-
-
-
-QT_END_NAMESPACE
-
-
-#endif // QWINDOWSAUDIODEVICEINFO_H
diff --git a/src/plugins/windowsaudio/qwindowsaudioinput.cpp b/src/plugins/windowsaudio/qwindowsaudioinput.cpp
deleted file mode 100644
index addabbd32..000000000
--- a/src/plugins/windowsaudio/qwindowsaudioinput.cpp
+++ /dev/null
@@ -1,732 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// INTERNAL USE ONLY: Do NOT use for any other purpose.
-//
-
-
-#include "qwindowsaudioinput.h"
-
-#include <QtCore/QDataStream>
-#include <QtCore/qtimer.h>
-
-QT_BEGIN_NAMESPACE
-
-//#define DEBUG_AUDIO 1
-
-QWindowsAudioInput::QWindowsAudioInput(const QByteArray &device)
-{
- bytesAvailable = 0;
- buffer_size = 0;
- period_size = 0;
- m_device = device;
- totalTimeValue = 0;
- intervalTime = 1000;
- errorState = QAudio::NoError;
- deviceState = QAudio::StoppedState;
- audioSource = 0;
- pullMode = true;
- resuming = false;
- finished = false;
- waveBlockOffset = 0;
-
- mixerID = 0;
- cachedVolume = -1.0f;
- memset(&mixerLineControls, 0, sizeof(mixerLineControls));
-}
-
-QWindowsAudioInput::~QWindowsAudioInput()
-{
- stop();
-}
-
-void QT_WIN_CALLBACK QWindowsAudioInput::waveInProc( HWAVEIN hWaveIn, UINT uMsg,
- DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2 )
-{
- Q_UNUSED(dwParam1);
- Q_UNUSED(dwParam2);
- Q_UNUSED(hWaveIn);
-
- QWindowsAudioInput* qAudio;
- qAudio = (QWindowsAudioInput*)(dwInstance);
- if(!qAudio)
- return;
-
- QMutexLocker locker(&qAudio->mutex);
-
- switch(uMsg) {
- case WIM_OPEN:
- break;
- case WIM_DATA:
- if(qAudio->waveFreeBlockCount > 0)
- qAudio->waveFreeBlockCount--;
- qAudio->feedback();
- break;
- case WIM_CLOSE:
- qAudio->finished = true;
- break;
- default:
- return;
- }
-}
-
-WAVEHDR* QWindowsAudioInput::allocateBlocks(int size, int count)
-{
- int i;
- unsigned char* buffer;
- WAVEHDR* blocks;
- DWORD totalBufferSize = (size + sizeof(WAVEHDR))*count;
-
- if((buffer=(unsigned char*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
- totalBufferSize)) == 0) {
- qWarning("QAudioInput: Memory allocation error");
- return 0;
- }
- blocks = (WAVEHDR*)buffer;
- buffer += sizeof(WAVEHDR)*count;
- for(i = 0; i < count; i++) {
- blocks[i].dwBufferLength = size;
- blocks[i].lpData = (LPSTR)buffer;
- blocks[i].dwBytesRecorded=0;
- blocks[i].dwUser = 0L;
- blocks[i].dwFlags = 0L;
- blocks[i].dwLoops = 0L;
- result = waveInPrepareHeader(hWaveIn,&blocks[i], sizeof(WAVEHDR));
- if(result != MMSYSERR_NOERROR) {
- qWarning("QAudioInput: Can't prepare block %d",i);
- return 0;
- }
- buffer += size;
- }
- return blocks;
-}
-
-void QWindowsAudioInput::freeBlocks(WAVEHDR* blockArray)
-{
- WAVEHDR* blocks = blockArray;
-
- int count = buffer_size/period_size;
-
- for(int i = 0; i < count; i++) {
- waveInUnprepareHeader(hWaveIn,blocks, sizeof(WAVEHDR));
- blocks++;
- }
- HeapFree(GetProcessHeap(), 0, blockArray);
-}
-
-QAudio::Error QWindowsAudioInput::error() const
-{
- return errorState;
-}
-
-QAudio::State QWindowsAudioInput::state() const
-{
- return deviceState;
-}
-
-#ifndef DRVM_MAPPER_CONSOLEVOICECOM_GET
- #ifndef DRVM_MAPPER
- #define DRVM_MAPPER 0x2000
- #endif
- #ifndef DRVM_MAPPER_STATUS
- #define DRVM_MAPPER_STATUS (DRVM_MAPPER+0)
- #endif
- #define DRVM_USER 0x4000
- #define DRVM_MAPPER_RECONFIGURE (DRVM_MAPPER+1)
- #define DRVM_MAPPER_PREFERRED_GET (DRVM_MAPPER+21)
- #define DRVM_MAPPER_CONSOLEVOICECOM_GET (DRVM_MAPPER+23)
-#endif
-
-void QWindowsAudioInput::setVolume(qreal volume)
-{
- cachedVolume = volume;
- for (DWORD i = 0; i < mixerLineControls.cControls; i++) {
-
- MIXERCONTROLDETAILS controlDetails;
- controlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
- controlDetails.dwControlID = mixerLineControls.pamxctrl[i].dwControlID;
- controlDetails.cChannels = 1;
-
- if ((mixerLineControls.pamxctrl[i].dwControlType == MIXERCONTROL_CONTROLTYPE_FADER) ||
- (mixerLineControls.pamxctrl[i].dwControlType == MIXERCONTROL_CONTROLTYPE_VOLUME)) {
- MIXERCONTROLDETAILS_UNSIGNED controlDetailsUnsigned;
- controlDetailsUnsigned.dwValue = qBound(DWORD(0), DWORD(65535.0 * volume + 0.5), DWORD(65535));
- controlDetails.cMultipleItems = 0;
- controlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
- controlDetails.paDetails = &controlDetailsUnsigned;
- mixerSetControlDetails(mixerID, &controlDetails, MIXER_SETCONTROLDETAILSF_VALUE);
- }
- }
-}
-
-qreal QWindowsAudioInput::volume() const
-{
- for (DWORD i = 0; i < mixerLineControls.cControls; i++) {
- if ((mixerLineControls.pamxctrl[i].dwControlType != MIXERCONTROL_CONTROLTYPE_FADER) &&
- (mixerLineControls.pamxctrl[i].dwControlType != MIXERCONTROL_CONTROLTYPE_VOLUME)) {
- continue;
- }
-
- MIXERCONTROLDETAILS controlDetails;
- controlDetails.cbStruct = sizeof(controlDetails);
- controlDetails.dwControlID = mixerLineControls.pamxctrl[i].dwControlID;
- controlDetails.cChannels = 1;
- controlDetails.cMultipleItems = 0;
- controlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
- MIXERCONTROLDETAILS_UNSIGNED detailsUnsigned;
- controlDetails.paDetails = &detailsUnsigned;
- memset(controlDetails.paDetails, 0, controlDetails.cbDetails);
-
- MMRESULT result = mixerGetControlDetails(mixerID, &controlDetails, MIXER_GETCONTROLDETAILSF_VALUE);
- if (result != MMSYSERR_NOERROR)
- continue;
- if (controlDetails.cbDetails < sizeof(MIXERCONTROLDETAILS_UNSIGNED))
- continue;
- return detailsUnsigned.dwValue / 65535.0;
- }
-
- return qFuzzyCompare(cachedVolume, qreal(-1.0f)) ? 1.0f : cachedVolume;
-}
-
-void QWindowsAudioInput::setFormat(const QAudioFormat& fmt)
-{
- if (deviceState == QAudio::StoppedState)
- settings = fmt;
-}
-
-QAudioFormat QWindowsAudioInput::format() const
-{
- return settings;
-}
-
-void QWindowsAudioInput::start(QIODevice* device)
-{
- if(deviceState != QAudio::StoppedState)
- close();
-
- if(!pullMode && audioSource)
- delete audioSource;
-
- pullMode = true;
- audioSource = device;
-
- deviceState = QAudio::ActiveState;
-
- if(!open())
- return;
-
- emit stateChanged(deviceState);
-}
-
-QIODevice* QWindowsAudioInput::start()
-{
- if(deviceState != QAudio::StoppedState)
- close();
-
- if(!pullMode && audioSource)
- delete audioSource;
-
- pullMode = false;
- audioSource = new InputPrivate(this);
- audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
-
- deviceState = QAudio::IdleState;
-
- if(!open())
- return 0;
-
- emit stateChanged(deviceState);
-
- return audioSource;
-}
-
-void QWindowsAudioInput::stop()
-{
- if(deviceState == QAudio::StoppedState)
- return;
-
- close();
- emit stateChanged(deviceState);
-}
-
-bool QWindowsAudioInput::open()
-{
-#ifdef DEBUG_AUDIO
- QTime now(QTime::currentTime());
- qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
-#endif
- header = 0;
-
- period_size = 0;
-
- if (!qt_convertFormat(settings, &wfx)) {
- qWarning("QAudioInput: open error, invalid format.");
- } else if (buffer_size == 0) {
- buffer_size
- = (settings.sampleRate()
- * settings.channelCount()
- * settings.sampleSize()
- + 39) / 40;
- period_size = buffer_size / 5;
- } else {
- period_size = buffer_size / 5;
- }
-
- if (period_size == 0) {
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- return false;
- }
-
- timeStamp.restart();
- elapsedTimeOffset = 0;
-
- QDataStream ds(&m_device, QIODevice::ReadOnly);
- quint32 deviceId;
- ds >> deviceId;
-
- if (waveInOpen(&hWaveIn, UINT_PTR(deviceId), &wfx.Format,
- (DWORD_PTR)&waveInProc,
- (DWORD_PTR) this,
- CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- qWarning("QAudioInput: failed to open audio device");
- return false;
- }
- waveBlocks = allocateBlocks(period_size, buffer_size/period_size);
- waveBlockOffset = 0;
-
- if(waveBlocks == 0) {
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- qWarning("QAudioInput: failed to allocate blocks. open failed");
- return false;
- }
-
- mutex.lock();
- waveFreeBlockCount = buffer_size/period_size;
- mutex.unlock();
-
- for(int i=0; i<buffer_size/period_size; i++) {
- result = waveInAddBuffer(hWaveIn, &waveBlocks[i], sizeof(WAVEHDR));
- if(result != MMSYSERR_NOERROR) {
- qWarning("QAudioInput: failed to setup block %d,err=%d",i,result);
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- return false;
- }
- }
- result = waveInStart(hWaveIn);
- if(result) {
- qWarning("QAudioInput: failed to start audio input");
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- return false;
- }
- timeStampOpened.restart();
- elapsedTimeOffset = 0;
- totalTimeValue = 0;
- errorState = QAudio::NoError;
- initMixer();
- return true;
-}
-
-void QWindowsAudioInput::close()
-{
- if(deviceState == QAudio::StoppedState)
- return;
-
- deviceState = QAudio::StoppedState;
- waveInReset(hWaveIn);
-
- mutex.lock();
- for (int i=0; i<waveFreeBlockCount; i++)
- waveInUnprepareHeader(hWaveIn,&waveBlocks[i],sizeof(WAVEHDR));
- freeBlocks(waveBlocks);
- mutex.unlock();
-
- waveInClose(hWaveIn);
- closeMixer();
-
- int count = 0;
- while(!finished && count < 500) {
- count++;
- Sleep(10);
- }
-}
-
-void QWindowsAudioInput::initMixer()
-{
- // Get the Mixer ID from the Sound Device ID
- UINT mixerIntID = 0;
- if (mixerGetID(reinterpret_cast<HMIXEROBJ>(hWaveIn),
- &mixerIntID, MIXER_OBJECTF_HWAVEIN) != MMSYSERR_NOERROR)
- return;
- mixerID = reinterpret_cast<HMIXEROBJ>(quintptr(mixerIntID));
-
- // Get the Destination (Recording) Line Information
- MIXERLINE mixerLine;
- mixerLine.cbStruct = sizeof(MIXERLINE);
- mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
- if (mixerGetLineInfo(mixerID, &mixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE) != MMSYSERR_NOERROR)
- return;
-
- // Set all the Destination (Recording) Line Controls
- if (mixerLine.cControls > 0) {
- mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS);
- mixerLineControls.dwLineID = mixerLine.dwLineID;
- mixerLineControls.cControls = mixerLine.cControls;
- mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL);
- mixerLineControls.pamxctrl = new MIXERCONTROL[mixerLineControls.cControls];
- if (mixerGetLineControls(mixerID, &mixerLineControls, MIXER_GETLINECONTROLSF_ALL) != MMSYSERR_NOERROR)
- closeMixer();
- else if (!qFuzzyCompare(cachedVolume, qreal(-1.0f)))
- setVolume(cachedVolume);
- }
-}
-
-void QWindowsAudioInput::closeMixer()
-{
- delete[] mixerLineControls.pamxctrl;
- memset(&mixerLineControls, 0, sizeof(mixerLineControls));
-}
-
-int QWindowsAudioInput::bytesReady() const
-{
- if(period_size == 0 || buffer_size == 0)
- return 0;
-
- int buf = ((buffer_size/period_size)-waveFreeBlockCount)*period_size;
- if(buf < 0)
- buf = 0;
- return buf;
-}
-
-qint64 QWindowsAudioInput::read(char* data, qint64 len)
-{
- bool done = false;
-
- char* p = data;
- qint64 l = 0;
- qint64 written = 0;
- while(!done) {
- // Read in some audio data
- if(waveBlocks[header].dwBytesRecorded > 0 && waveBlocks[header].dwFlags & WHDR_DONE) {
- if(pullMode) {
- l = audioSource->write(waveBlocks[header].lpData + waveBlockOffset,
- waveBlocks[header].dwBytesRecorded - waveBlockOffset);
-#ifdef DEBUG_AUDIO
- qDebug()<<"IN: "<<waveBlocks[header].dwBytesRecorded<<", OUT: "<<l;
-#endif
- if(l < 0) {
- // error
- qWarning("QAudioInput: IOError");
- errorState = QAudio::IOError;
-
- } else if(l == 0) {
- // cant write to IODevice
- qWarning("QAudioInput: IOError, can't write to QIODevice");
- errorState = QAudio::IOError;
-
- } else {
- totalTimeValue += l;
- errorState = QAudio::NoError;
- if (deviceState != QAudio::ActiveState) {
- deviceState = QAudio::ActiveState;
- emit stateChanged(deviceState);
- }
- resuming = false;
- }
- } else {
- l = qMin<qint64>(len, waveBlocks[header].dwBytesRecorded - waveBlockOffset);
- // push mode
- memcpy(p, waveBlocks[header].lpData + waveBlockOffset, l);
-
- len -= l;
-
-#ifdef DEBUG_AUDIO
- qDebug()<<"IN: "<<waveBlocks[header].dwBytesRecorded<<", OUT: "<<l;
-#endif
- totalTimeValue += l;
- errorState = QAudio::NoError;
- if (deviceState != QAudio::ActiveState) {
- deviceState = QAudio::ActiveState;
- emit stateChanged(deviceState);
- }
- resuming = false;
- }
- } else {
- //no data, not ready yet, next time
- break;
- }
-
- if (l < waveBlocks[header].dwBytesRecorded - waveBlockOffset) {
- waveBlockOffset += l;
- done = true;
- } else {
- waveBlockOffset = 0;
-
- waveInUnprepareHeader(hWaveIn,&waveBlocks[header], sizeof(WAVEHDR));
-
- mutex.lock();
- waveFreeBlockCount++;
- mutex.unlock();
-
- waveBlocks[header].dwBytesRecorded=0;
- waveBlocks[header].dwFlags = 0L;
- result = waveInPrepareHeader(hWaveIn,&waveBlocks[header], sizeof(WAVEHDR));
- if(result != MMSYSERR_NOERROR) {
- result = waveInPrepareHeader(hWaveIn,&waveBlocks[header], sizeof(WAVEHDR));
- qWarning("QAudioInput: failed to prepare block %d,err=%d",header,result);
- errorState = QAudio::IOError;
-
- mutex.lock();
- waveFreeBlockCount--;
- mutex.unlock();
-
- return 0;
- }
- result = waveInAddBuffer(hWaveIn, &waveBlocks[header], sizeof(WAVEHDR));
- if(result != MMSYSERR_NOERROR) {
- qWarning("QAudioInput: failed to setup block %d,err=%d",header,result);
- errorState = QAudio::IOError;
-
- mutex.lock();
- waveFreeBlockCount--;
- mutex.unlock();
-
- return 0;
- }
- header++;
- if(header >= buffer_size/period_size)
- header = 0;
- p+=l;
-
- mutex.lock();
- if(!pullMode) {
- if(len < period_size || waveFreeBlockCount == buffer_size/period_size)
- done = true;
- } else {
- if(waveFreeBlockCount == buffer_size/period_size)
- done = true;
- }
- mutex.unlock();
- }
-
- written+=l;
- }
-#ifdef DEBUG_AUDIO
- qDebug()<<"read in len="<<written;
-#endif
- return written;
-}
-
-void QWindowsAudioInput::resume()
-{
- if(deviceState == QAudio::SuspendedState) {
- deviceState = QAudio::ActiveState;
- for(int i=0; i<buffer_size/period_size; i++) {
- result = waveInAddBuffer(hWaveIn, &waveBlocks[i], sizeof(WAVEHDR));
- if(result != MMSYSERR_NOERROR) {
- qWarning("QAudioInput: failed to setup block %d,err=%d",i,result);
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- return;
- }
- }
-
- mutex.lock();
- waveFreeBlockCount = buffer_size/period_size;
- mutex.unlock();
-
- header = 0;
- resuming = true;
- waveBlockOffset = 0;
- waveInStart(hWaveIn);
- QTimer::singleShot(20,this,SLOT(feedback()));
- emit stateChanged(deviceState);
- }
-}
-
-void QWindowsAudioInput::setBufferSize(int value)
-{
- buffer_size = value;
-}
-
-int QWindowsAudioInput::bufferSize() const
-{
- return buffer_size;
-}
-
-int QWindowsAudioInput::periodSize() const
-{
- return period_size;
-}
-
-void QWindowsAudioInput::setNotifyInterval(int ms)
-{
- intervalTime = qMax(0, ms);
-}
-
-int QWindowsAudioInput::notifyInterval() const
-{
- return intervalTime;
-}
-
-qint64 QWindowsAudioInput::processedUSecs() const
-{
- if (deviceState == QAudio::StoppedState)
- return 0;
- qint64 result = qint64(1000000) * totalTimeValue /
- (settings.channelCount()*(settings.sampleSize()/8)) /
- settings.sampleRate();
-
- return result;
-}
-
-void QWindowsAudioInput::suspend()
-{
- if(deviceState == QAudio::ActiveState) {
- waveInReset(hWaveIn);
- deviceState = QAudio::SuspendedState;
- emit stateChanged(deviceState);
- }
-}
-
-void QWindowsAudioInput::feedback()
-{
-#ifdef DEBUG_AUDIO
- QTime now(QTime::currentTime());
- qDebug()<<now.second()<<"s "<<now.msec()<<"ms :feedback() INPUT "<<this;
-#endif
- if(!(deviceState==QAudio::StoppedState||deviceState==QAudio::SuspendedState))
- QMetaObject::invokeMethod(this, "deviceReady", Qt::QueuedConnection);
-}
-
-bool QWindowsAudioInput::deviceReady()
-{
- bytesAvailable = bytesReady();
-#ifdef DEBUG_AUDIO
- QTime now(QTime::currentTime());
- qDebug()<<now.second()<<"s "<<now.msec()<<"ms :deviceReady() INPUT";
-#endif
- if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
- return true;
-
- if(pullMode) {
- // reads some audio data and writes it to QIODevice
- read(0, buffer_size);
- } else {
- // emits readyRead() so user will call read() on QIODevice to get some audio data
- InputPrivate* a = qobject_cast<InputPrivate*>(audioSource);
- a->trigger();
- }
-
- if(intervalTime && (timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
- emit notify();
- elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime;
- timeStamp.restart();
- }
- return true;
-}
-
-qint64 QWindowsAudioInput::elapsedUSecs() const
-{
- if (deviceState == QAudio::StoppedState)
- return 0;
-
- return timeStampOpened.elapsed() * qint64(1000);
-}
-
-void QWindowsAudioInput::reset()
-{
- stop();
- if (period_size > 0)
- waveFreeBlockCount = buffer_size / period_size;
-}
-
-InputPrivate::InputPrivate(QWindowsAudioInput* audio)
-{
- audioDevice = qobject_cast<QWindowsAudioInput*>(audio);
-}
-
-InputPrivate::~InputPrivate() {}
-
-qint64 InputPrivate::readData( char* data, qint64 len)
-{
- // push mode, user read() called
- if(audioDevice->deviceState != QAudio::ActiveState &&
- audioDevice->deviceState != QAudio::IdleState)
- return 0;
- // Read in some audio data
- return audioDevice->read(data,len);
-}
-
-qint64 InputPrivate::writeData(const char* data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
-
- emit readyRead();
- return 0;
-}
-
-void InputPrivate::trigger()
-{
- emit readyRead();
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qwindowsaudioinput.cpp"
diff --git a/src/plugins/windowsaudio/qwindowsaudioinput.h b/src/plugins/windowsaudio/qwindowsaudioinput.h
deleted file mode 100644
index 817176731..000000000
--- a/src/plugins/windowsaudio/qwindowsaudioinput.h
+++ /dev/null
@@ -1,177 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifndef QWINDOWSAUDIOINPUT_H
-#define QWINDOWSAUDIOINPUT_H
-
-#include "qwindowsaudioutils.h"
-
-#include <QtCore/qfile.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qelapsedtimer.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qdatetime.h>
-#include <QtCore/qmutex.h>
-
-#include <QtMultimedia/qaudio.h>
-#include <QtMultimedia/qaudiodeviceinfo.h>
-#include <QtMultimedia/qaudiosystem.h>
-
-
-QT_BEGIN_NAMESPACE
-
-
-// For compat with 4.6
-#if !defined(QT_WIN_CALLBACK)
-# if defined(Q_CC_MINGW)
-# define QT_WIN_CALLBACK CALLBACK __attribute__ ((force_align_arg_pointer))
-# else
-# define QT_WIN_CALLBACK CALLBACK
-# endif
-#endif
-
-class QWindowsAudioInput : public QAbstractAudioInput
-{
- Q_OBJECT
-public:
- QWindowsAudioInput(const QByteArray &device);
- ~QWindowsAudioInput();
-
- qint64 read(char* data, qint64 len);
-
- void setFormat(const QAudioFormat& fmt);
- QAudioFormat format() const;
- QIODevice* start();
- void start(QIODevice* device);
- void stop();
- void reset();
- void suspend();
- void resume();
- int bytesReady() const;
- int periodSize() const;
- void setBufferSize(int value);
- int bufferSize() const;
- void setNotifyInterval(int milliSeconds);
- int notifyInterval() const;
- qint64 processedUSecs() const;
- qint64 elapsedUSecs() const;
- QAudio::Error error() const;
- QAudio::State state() const;
- void setVolume(qreal volume);
- qreal volume() const;
-
- QIODevice* audioSource;
- QAudioFormat settings;
- QAudio::Error errorState;
- QAudio::State deviceState;
-
-private:
- qint32 buffer_size;
- qint32 period_size;
- qint32 header;
- QByteArray m_device;
- int bytesAvailable;
- int intervalTime;
- QElapsedTimer timeStamp;
- qint64 elapsedTimeOffset;
- QElapsedTimer timeStampOpened;
- qint64 totalTimeValue;
- bool pullMode;
- bool resuming;
- WAVEFORMATEXTENSIBLE wfx;
- HWAVEIN hWaveIn;
- MMRESULT result;
- WAVEHDR* waveBlocks;
- volatile bool finished;
- volatile int waveFreeBlockCount;
- int waveBlockOffset;
-
- QMutex mutex;
- static void QT_WIN_CALLBACK waveInProc( HWAVEIN hWaveIn, UINT uMsg,
- DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2 );
-
- WAVEHDR* allocateBlocks(int size, int count);
- void freeBlocks(WAVEHDR* blockArray);
- bool open();
- void close();
-
- void initMixer();
- void closeMixer();
- HMIXEROBJ mixerID;
- MIXERLINECONTROLS mixerLineControls;
- qreal cachedVolume;
-
-private slots:
- void feedback();
- bool deviceReady();
-
-signals:
- void processMore();
-};
-
-class InputPrivate : public QIODevice
-{
- Q_OBJECT
-public:
- InputPrivate(QWindowsAudioInput* audio);
- ~InputPrivate();
-
- qint64 readData( char* data, qint64 len);
- qint64 writeData(const char* data, qint64 len);
-
- void trigger();
-private:
- QWindowsAudioInput *audioDevice;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/windowsaudio/qwindowsaudiooutput.cpp b/src/plugins/windowsaudio/qwindowsaudiooutput.cpp
deleted file mode 100644
index e0635307e..000000000
--- a/src/plugins/windowsaudio/qwindowsaudiooutput.cpp
+++ /dev/null
@@ -1,676 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// INTERNAL USE ONLY: Do NOT use for any other purpose.
-//
-
-#include "qwindowsaudiooutput.h"
-#include "qwindowsaudiodeviceinfo.h"
-#include "qwindowsaudioutils.h"
-#include <QtEndian>
-#include <QtCore/QDataStream>
-#include <QtCore/qtimer.h>
-#include <private/qaudiohelpers_p.h>
-
-//#define DEBUG_AUDIO 1
-
-QT_BEGIN_NAMESPACE
-
-QWindowsAudioOutput::QWindowsAudioOutput(const QByteArray &device)
-{
- bytesAvailable = 0;
- buffer_size = 0;
- period_size = 0;
- m_device = device;
- totalTimeValue = 0;
- intervalTime = 1000;
- audioBuffer = 0;
- errorState = QAudio::NoError;
- deviceState = QAudio::StoppedState;
- audioSource = 0;
- pullMode = true;
- finished = false;
- volumeCache = qreal(1.0);
- blocks_count = 5;
-}
-
-QWindowsAudioOutput::~QWindowsAudioOutput()
-{
- mutex.lock();
- finished = true;
- mutex.unlock();
-
- close();
-}
-
-void CALLBACK QWindowsAudioOutput::waveOutProc( HWAVEOUT hWaveOut, UINT uMsg,
- DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2 )
-{
- Q_UNUSED(dwParam1);
- Q_UNUSED(dwParam2);
- Q_UNUSED(hWaveOut);
-
- QWindowsAudioOutput* qAudio;
- qAudio = (QWindowsAudioOutput*)(dwInstance);
- if(!qAudio)
- return;
-
- QMutexLocker locker(&qAudio->mutex);
-
- switch(uMsg) {
- case WOM_OPEN:
- qAudio->feedback();
- break;
- case WOM_CLOSE:
- return;
- case WOM_DONE:
- if(qAudio->finished || qAudio->buffer_size == 0 || qAudio->period_size == 0) {
- return;
- }
- qAudio->waveFreeBlockCount++;
- if (qAudio->waveFreeBlockCount >= qAudio->blocks_count)
- qAudio->waveFreeBlockCount = qAudio->blocks_count;
-
- qAudio->feedback();
- break;
- default:
- return;
- }
-}
-
-WAVEHDR* QWindowsAudioOutput::allocateBlocks(int size, int count)
-{
- int i;
- unsigned char* buffer;
- WAVEHDR* blocks;
- DWORD totalBufferSize = (size + sizeof(WAVEHDR))*count;
-
- if((buffer=(unsigned char*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
- totalBufferSize)) == 0) {
- qWarning("QAudioOutput: Memory allocation error");
- return 0;
- }
- blocks = (WAVEHDR*)buffer;
- buffer += sizeof(WAVEHDR)*count;
- for(i = 0; i < count; i++) {
- blocks[i].dwBufferLength = size;
- blocks[i].lpData = (LPSTR)buffer;
- buffer += size;
- }
- return blocks;
-}
-
-void QWindowsAudioOutput::freeBlocks(WAVEHDR* blockArray)
-{
- WAVEHDR* blocks = blockArray;
- for (int i = 0; i < blocks_count; ++i) {
- waveOutUnprepareHeader(hWaveOut,blocks, sizeof(WAVEHDR));
- blocks++;
- }
- HeapFree(GetProcessHeap(), 0, blockArray);
-}
-
-QAudioFormat QWindowsAudioOutput::format() const
-{
- return settings;
-}
-
-void QWindowsAudioOutput::setFormat(const QAudioFormat& fmt)
-{
- if (deviceState == QAudio::StoppedState)
- settings = fmt;
-}
-
-void QWindowsAudioOutput::start(QIODevice* device)
-{
- if(deviceState != QAudio::StoppedState)
- close();
-
- if(!pullMode && audioSource)
- delete audioSource;
-
- pullMode = true;
- audioSource = device;
-
- deviceState = QAudio::ActiveState;
-
- if(!open())
- return;
-
- emit stateChanged(deviceState);
-}
-
-QIODevice* QWindowsAudioOutput::start()
-{
- if(deviceState != QAudio::StoppedState)
- close();
-
- if(!pullMode && audioSource)
- delete audioSource;
-
- pullMode = false;
- audioSource = new OutputPrivate(this);
- audioSource->open(QIODevice::WriteOnly|QIODevice::Unbuffered);
-
- deviceState = QAudio::IdleState;
-
- if(!open())
- return 0;
-
- emit stateChanged(deviceState);
-
- return audioSource;
-}
-
-void QWindowsAudioOutput::stop()
-{
- if(deviceState == QAudio::StoppedState)
- return;
- close();
- if(!pullMode && audioSource) {
- delete audioSource;
- audioSource = 0;
- }
- emit stateChanged(deviceState);
-}
-
-bool QWindowsAudioOutput::open()
-{
-#ifdef DEBUG_AUDIO
- QTime now(QTime::currentTime());
- qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
-#endif
-
- period_size = 0;
-
- if (!qt_convertFormat(settings, &wfx)) {
- qWarning("QAudioOutput: open error, invalid format.");
- } else if (buffer_size == 0) {
- // Default buffer size, 200ms, default period size is 40ms
- buffer_size
- = (settings.sampleRate()
- * settings.channelCount()
- * settings.sampleSize()
- + 39) / 40;
- period_size = buffer_size / 5;
- } else {
- period_size = buffer_size / 5;
- }
-
- // Make even size of wave block to prevent crackling
- // due to waveOutWrite() does not like odd buffer length
- period_size &= ~1;
-
- if (period_size == 0) {
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- return false;
- }
-
- const int periods = buffer_size / period_size;
- bool ok = false;
- static int wave_buffers = qEnvironmentVariableIntValue("QT_WAVE_BUFFERS", &ok);
- if (wave_buffers < periods) {
- if (ok)
- qWarning("Number of WAVE buffers (QT_WAVE_BUFFERS=%d) cannot be less than %d.", wave_buffers, periods);
- wave_buffers = periods;
- }
-
- blocks_count = wave_buffers;
- waveBlocks = allocateBlocks(period_size, blocks_count);
-
- mutex.lock();
- waveFreeBlockCount = blocks_count;
- mutex.unlock();
-
- waveCurrentBlock = 0;
-
- if(audioBuffer == 0)
- audioBuffer = new char[blocks_count * period_size];
-
- timeStamp.restart();
- elapsedTimeOffset = 0;
-
- QDataStream ds(&m_device, QIODevice::ReadOnly);
- quint32 deviceId;
- ds >> deviceId;
-
- if (waveOutOpen(&hWaveOut, UINT_PTR(deviceId), &wfx.Format,
- (DWORD_PTR)&waveOutProc,
- (DWORD_PTR) this,
- CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
- errorState = QAudio::OpenError;
- deviceState = QAudio::StoppedState;
- emit stateChanged(deviceState);
- qWarning("QAudioOutput: open error");
- return false;
- }
-
- totalTimeValue = 0;
- timeStampOpened.restart();
- elapsedTimeOffset = 0;
-
- errorState = QAudio::NoError;
- if(pullMode) {
- deviceState = QAudio::ActiveState;
- QTimer::singleShot(10, this, SLOT(feedback()));
- } else
- deviceState = QAudio::IdleState;
-
- return true;
-}
-
-void QWindowsAudioOutput::pauseAndSleep()
-{
- waveOutPause(hWaveOut);
- int bitrate = settings.sampleRate() * settings.channelCount() * settings.sampleSize() / 8;
- // Time of written data.
- int delay = (buffer_size - bytesFree()) * 1000 / bitrate;
- Sleep(delay + 10);
-}
-
-void QWindowsAudioOutput::close()
-{
- if(deviceState == QAudio::StoppedState)
- return;
-
- // Pause playback before reset to avoid uneeded crackling at the end.
- pauseAndSleep();
- deviceState = QAudio::StoppedState;
- errorState = QAudio::NoError;
- waveOutReset(hWaveOut);
-
- freeBlocks(waveBlocks);
- waveOutClose(hWaveOut);
- delete [] audioBuffer;
- audioBuffer = 0;
- buffer_size = 0;
-}
-
-int QWindowsAudioOutput::bytesFree() const
-{
- int buf;
- buf = waveFreeBlockCount*period_size;
-
- return buf;
-}
-
-int QWindowsAudioOutput::periodSize() const
-{
- return period_size;
-}
-
-void QWindowsAudioOutput::setBufferSize(int value)
-{
- if(deviceState == QAudio::StoppedState)
- buffer_size = value;
-}
-
-int QWindowsAudioOutput::bufferSize() const
-{
- return buffer_size;
-}
-
-void QWindowsAudioOutput::setNotifyInterval(int ms)
-{
- intervalTime = qMax(0, ms);
-}
-
-int QWindowsAudioOutput::notifyInterval() const
-{
- return intervalTime;
-}
-
-qint64 QWindowsAudioOutput::processedUSecs() const
-{
- if (deviceState == QAudio::StoppedState)
- return 0;
- qint64 result = qint64(1000000) * totalTimeValue /
- (settings.channelCount()*(settings.sampleSize()/8)) /
- settings.sampleRate();
-
- return result;
-}
-
-qint64 QWindowsAudioOutput::write( const char *data, qint64 len )
-{
- // Write out some audio data
- if (deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
- return 0;
-
- char* p = (char*)data;
- int l = (int)len;
-
- QByteArray reverse;
- if (settings.byteOrder() == QAudioFormat::BigEndian) {
-
- switch (settings.sampleSize()) {
- case 8:
- // No need to convert
- break;
-
- case 16:
- reverse.resize(l);
- for (qint64 i = 0; i < (l >> 1); i++)
- *((qint16*)reverse.data() + i) = qFromBigEndian(*((qint16*)data + i));
- p = reverse.data();
- break;
-
- case 32:
- reverse.resize(l);
- for (qint64 i = 0; i < (l >> 2); i++)
- *((qint32*)reverse.data() + i) = qFromBigEndian(*((qint32*)data + i));
- p = reverse.data();
- break;
- }
- }
-
- WAVEHDR* current;
- int remain;
- current = &waveBlocks[waveCurrentBlock];
- while(l > 0) {
- mutex.lock();
- if(waveFreeBlockCount==0) {
- mutex.unlock();
- break;
- }
- mutex.unlock();
-
- if(current->dwFlags & WHDR_PREPARED)
- waveOutUnprepareHeader(hWaveOut, current, sizeof(WAVEHDR));
-
- if(l < period_size)
- remain = l;
- else
- remain = period_size;
-
- if (volumeCache < qreal(1.0))
- QAudioHelperInternal::qMultiplySamples(volumeCache, settings, p, current->lpData, remain);
- else
- memcpy(current->lpData, p, remain);
-
- l -= remain;
- p += remain;
- current->dwBufferLength = remain;
- waveOutPrepareHeader(hWaveOut, current, sizeof(WAVEHDR));
- waveOutWrite(hWaveOut, current, sizeof(WAVEHDR));
-
- mutex.lock();
- waveFreeBlockCount--;
-#ifdef DEBUG_AUDIO
- qDebug("write out l=%d, waveFreeBlockCount=%d",
- current->dwBufferLength,waveFreeBlockCount);
-#endif
- mutex.unlock();
-
- totalTimeValue += current->dwBufferLength;
- waveCurrentBlock++;
- waveCurrentBlock %= blocks_count;
- current = &waveBlocks[waveCurrentBlock];
- current->dwUser = 0;
- errorState = QAudio::NoError;
- if (deviceState != QAudio::ActiveState) {
- deviceState = QAudio::ActiveState;
- emit stateChanged(deviceState);
- }
- }
- return (len-l);
-}
-
-void QWindowsAudioOutput::resume()
-{
- if(deviceState == QAudio::SuspendedState) {
- deviceState = pullMode ? QAudio::ActiveState : QAudio::IdleState;
- errorState = QAudio::NoError;
- waveOutRestart(hWaveOut);
- QTimer::singleShot(10, this, SLOT(feedback()));
- emit stateChanged(deviceState);
- }
-}
-
-void QWindowsAudioOutput::suspend()
-{
- if(deviceState == QAudio::ActiveState || deviceState == QAudio::IdleState) {
- pauseAndSleep();
- deviceState = QAudio::SuspendedState;
- errorState = QAudio::NoError;
- emit stateChanged(deviceState);
- }
-}
-
-void QWindowsAudioOutput::feedback()
-{
-#ifdef DEBUG_AUDIO
- QTime now(QTime::currentTime());
- qDebug()<<now.second()<<"s "<<now.msec()<<"ms :feedback()";
-#endif
- bytesAvailable = bytesFree();
-
- if(!(deviceState==QAudio::StoppedState||deviceState==QAudio::SuspendedState)) {
- if(bytesAvailable >= period_size)
- QMetaObject::invokeMethod(this, "deviceReady", Qt::QueuedConnection);
- }
-}
-
-bool QWindowsAudioOutput::deviceReady()
-{
- if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState)
- return false;
-
- if(pullMode) {
- int chunks = bytesAvailable/period_size;
-#ifdef DEBUG_AUDIO
- qDebug()<<"deviceReady() avail="<<bytesAvailable<<" bytes, period size="<<period_size<<" bytes";
- qDebug()<<"deviceReady() no. of chunks that can fit ="<<chunks<<", chunks in bytes ="<<chunks*period_size;
-#endif
- bool startup = false;
- if(totalTimeValue == 0)
- startup = true;
-
- bool full=false;
-
- mutex.lock();
- if (waveFreeBlockCount==0) full = true;
- mutex.unlock();
-
- if (full) {
-#ifdef DEBUG_AUDIO
- qDebug() << "Skipping data as unable to write";
-#endif
- if ((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
- emit notify();
- elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime;
- timeStamp.restart();
- }
- return true;
- }
-
- if(startup)
- waveOutPause(hWaveOut);
- int input = period_size*chunks;
- int l = audioSource->read(audioBuffer,input);
- if(l > 0) {
- int out= write(audioBuffer,l);
- if(out > 0) {
- if (deviceState != QAudio::ActiveState) {
- deviceState = QAudio::ActiveState;
- emit stateChanged(deviceState);
- }
- }
- if ( out < l) {
- // Didn't write all data
- audioSource->seek(audioSource->pos()-(l-out));
- }
- if (startup)
- waveOutRestart(hWaveOut);
- } else if(l == 0) {
- bytesAvailable = bytesFree();
-
- int check = 0;
-
- mutex.lock();
- check = waveFreeBlockCount;
- mutex.unlock();
-
- if (check == blocks_count) {
- if (deviceState != QAudio::IdleState) {
- errorState = QAudio::UnderrunError;
- deviceState = QAudio::IdleState;
- emit stateChanged(deviceState);
- }
- }
-
- } else if(l < 0) {
- bytesAvailable = bytesFree();
- if (errorState != QAudio::IOError)
- errorState = QAudio::IOError;
- }
- } else {
- int buffered;
-
- mutex.lock();
- buffered = waveFreeBlockCount;
- mutex.unlock();
-
- if (buffered >= blocks_count && deviceState == QAudio::ActiveState) {
- if (deviceState != QAudio::IdleState) {
- errorState = QAudio::UnderrunError;
- deviceState = QAudio::IdleState;
- emit stateChanged(deviceState);
- }
- }
- }
- if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
- return true;
-
- if(intervalTime && (timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
- emit notify();
- elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime;
- timeStamp.restart();
- }
-
- return true;
-}
-
-qint64 QWindowsAudioOutput::elapsedUSecs() const
-{
- if (deviceState == QAudio::StoppedState)
- return 0;
-
- return timeStampOpened.elapsed() * qint64(1000);
-}
-
-QAudio::Error QWindowsAudioOutput::error() const
-{
- return errorState;
-}
-
-QAudio::State QWindowsAudioOutput::state() const
-{
- return deviceState;
-}
-
-void QWindowsAudioOutput::setVolume(qreal v)
-{
- if (qFuzzyCompare(volumeCache, v))
- return;
-
- volumeCache = qBound(qreal(0), v, qreal(1));
-}
-
-qreal QWindowsAudioOutput::volume() const
-{
- return volumeCache;
-}
-
-void QWindowsAudioOutput::reset()
-{
- stop();
-}
-
-OutputPrivate::OutputPrivate(QWindowsAudioOutput* audio)
-{
- audioDevice = qobject_cast<QWindowsAudioOutput*>(audio);
-}
-
-OutputPrivate::~OutputPrivate() {}
-
-qint64 OutputPrivate::readData( char* data, qint64 len)
-{
- Q_UNUSED(data);
- Q_UNUSED(len);
-
- return 0;
-}
-
-qint64 OutputPrivate::writeData(const char* data, qint64 len)
-{
- int retry = 0;
- qint64 written = 0;
-
- if((audioDevice->deviceState == QAudio::ActiveState)
- ||(audioDevice->deviceState == QAudio::IdleState)) {
- qint64 l = len;
- while(written < l) {
- int chunk = audioDevice->write(data+written,(l-written));
- if(chunk <= 0)
- retry++;
- else
- written+=chunk;
-
- if(retry > 10)
- return written;
- }
- audioDevice->deviceState = QAudio::ActiveState;
- }
- return written;
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qwindowsaudiooutput.cpp"
diff --git a/src/plugins/windowsaudio/qwindowsaudiooutput.h b/src/plugins/windowsaudio/qwindowsaudiooutput.h
deleted file mode 100644
index e81121810..000000000
--- a/src/plugins/windowsaudio/qwindowsaudiooutput.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifndef QWINDOWSAUDIOOUTPUT_H
-#define QWINDOWSAUDIOOUTPUT_H
-
-#include "qwindowsaudioutils.h"
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qelapsedtimer.h>
-#include <QtCore/qiodevice.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qdatetime.h>
-#include <QtCore/qmutex.h>
-
-#include <QtMultimedia/qaudio.h>
-#include <QtMultimedia/qaudiodeviceinfo.h>
-#include <QtMultimedia/qaudiosystem.h>
-
-// For compat with 4.6
-#if !defined(QT_WIN_CALLBACK)
-# if defined(Q_CC_MINGW)
-# define QT_WIN_CALLBACK CALLBACK __attribute__ ((force_align_arg_pointer))
-# else
-# define QT_WIN_CALLBACK CALLBACK
-# endif
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class QWindowsAudioOutput : public QAbstractAudioOutput
-{
- Q_OBJECT
-public:
- QWindowsAudioOutput(const QByteArray &device);
- ~QWindowsAudioOutput();
-
- qint64 write( const char *data, qint64 len );
-
- void setFormat(const QAudioFormat& fmt);
- QAudioFormat format() const;
- QIODevice* start();
- void start(QIODevice* device);
- void stop();
- void reset();
- void suspend();
- void resume();
- int bytesFree() const;
- int periodSize() const;
- void setBufferSize(int value);
- int bufferSize() const;
- void setNotifyInterval(int milliSeconds);
- int notifyInterval() const;
- qint64 processedUSecs() const;
- qint64 elapsedUSecs() const;
- QAudio::Error error() const;
- QAudio::State state() const;
- void setVolume(qreal);
- qreal volume() const;
-
- QIODevice* audioSource;
- QAudioFormat settings;
- QAudio::Error errorState;
- QAudio::State deviceState;
-
-private slots:
- void feedback();
- bool deviceReady();
-
-private:
- void pauseAndSleep();
- QByteArray m_device;
- int bytesAvailable;
- QElapsedTimer timeStamp;
- qint64 elapsedTimeOffset;
- QElapsedTimer timeStampOpened;
- qint32 buffer_size;
- qint32 period_size;
- qint32 blocks_count;
- qint64 totalTimeValue;
- bool pullMode;
- int intervalTime;
- qreal volumeCache;
- static void QT_WIN_CALLBACK waveOutProc( HWAVEOUT hWaveOut, UINT uMsg,
- DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2 );
-
- QMutex mutex;
-
- WAVEHDR* allocateBlocks(int size, int count);
- void freeBlocks(WAVEHDR* blockArray);
- bool open();
- void close();
-
- WAVEFORMATEXTENSIBLE wfx;
- HWAVEOUT hWaveOut;
- WAVEHDR* waveBlocks;
- volatile bool finished;
- volatile int waveFreeBlockCount;
- int waveCurrentBlock;
- char* audioBuffer;
-};
-
-class OutputPrivate : public QIODevice
-{
- Q_OBJECT
-public:
- OutputPrivate(QWindowsAudioOutput* audio);
- ~OutputPrivate();
-
- qint64 readData( char* data, qint64 len);
- qint64 writeData(const char* data, qint64 len);
-
-private:
- QWindowsAudioOutput *audioDevice;
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QWINDOWSAUDIOOUTPUT_H
diff --git a/src/plugins/windowsaudio/qwindowsaudioplugin.cpp b/src/plugins/windowsaudio/qwindowsaudioplugin.cpp
deleted file mode 100644
index 8f532fa70..000000000
--- a/src/plugins/windowsaudio/qwindowsaudioplugin.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qwindowsaudioplugin.h"
-#include "qwindowsaudiodeviceinfo.h"
-#include "qwindowsaudioinput.h"
-#include "qwindowsaudiooutput.h"
-
-QT_BEGIN_NAMESPACE
-
-QWindowsAudioPlugin::QWindowsAudioPlugin(QObject *parent)
- : QAudioSystemPlugin(parent)
-{
-}
-
-QByteArray QWindowsAudioPlugin::defaultDevice(QAudio::Mode mode) const
-{
- return QWindowsAudioDeviceInfo::defaultDevice(mode);
-}
-
-QList<QByteArray> QWindowsAudioPlugin::availableDevices(QAudio::Mode mode) const
-{
- return QWindowsAudioDeviceInfo::availableDevices(mode);
-}
-
-QAbstractAudioInput *QWindowsAudioPlugin::createInput(const QByteArray &device)
-{
- return new QWindowsAudioInput(device);
-}
-
-QAbstractAudioOutput *QWindowsAudioPlugin::createOutput(const QByteArray &device)
-{
- return new QWindowsAudioOutput(device);
-}
-
-QAbstractAudioDeviceInfo *QWindowsAudioPlugin::createDeviceInfo(const QByteArray &device, QAudio::Mode mode)
-{
- return new QWindowsAudioDeviceInfo(device, mode);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/windowsaudio/qwindowsaudioplugin.h b/src/plugins/windowsaudio/qwindowsaudioplugin.h
deleted file mode 100644
index a155ae082..000000000
--- a/src/plugins/windowsaudio/qwindowsaudioplugin.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QWINDOWSAUDIOPLUGIN_H
-#define QWINDOWSAUDIOPLUGIN_H
-
-#include <QtMultimedia/qaudiosystemplugin.h>
-#include <QtMultimedia/private/qaudiosystempluginext_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QWindowsAudioPlugin : public QAudioSystemPlugin, public QAudioSystemPluginExtension
-{
- Q_OBJECT
-
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.audiosystemfactory/5.0" FILE "windowsaudio.json")
- Q_INTERFACES(QAudioSystemPluginExtension)
-
-public:
- QWindowsAudioPlugin(QObject *parent = 0);
- ~QWindowsAudioPlugin() {}
-
- QByteArray defaultDevice(QAudio::Mode mode) const override;
- QList<QByteArray> availableDevices(QAudio::Mode mode) const override;
- QAbstractAudioInput *createInput(const QByteArray &device) override;
- QAbstractAudioOutput *createOutput(const QByteArray &device) override;
- QAbstractAudioDeviceInfo *createDeviceInfo(const QByteArray &device, QAudio::Mode mode) override;
-};
-
-QT_END_NAMESPACE
-
-#endif // QWINDOWSAUDIOPLUGIN_H
diff --git a/src/plugins/windowsaudio/qwindowsaudioutils.cpp b/src/plugins/windowsaudio/qwindowsaudioutils.cpp
deleted file mode 100644
index 4eaa80b41..000000000
--- a/src/plugins/windowsaudio/qwindowsaudioutils.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qwindowsaudioutils.h"
-
-#ifndef SPEAKER_FRONT_LEFT
- #define SPEAKER_FRONT_LEFT 0x00000001
- #define SPEAKER_FRONT_RIGHT 0x00000002
- #define SPEAKER_FRONT_CENTER 0x00000004
- #define SPEAKER_LOW_FREQUENCY 0x00000008
- #define SPEAKER_BACK_LEFT 0x00000010
- #define SPEAKER_BACK_RIGHT 0x00000020
- #define SPEAKER_FRONT_LEFT_OF_CENTER 0x00000040
- #define SPEAKER_FRONT_RIGHT_OF_CENTER 0x00000080
- #define SPEAKER_BACK_CENTER 0x00000100
- #define SPEAKER_SIDE_LEFT 0x00000200
- #define SPEAKER_SIDE_RIGHT 0x00000400
- #define SPEAKER_TOP_CENTER 0x00000800
- #define SPEAKER_TOP_FRONT_LEFT 0x00001000
- #define SPEAKER_TOP_FRONT_CENTER 0x00002000
- #define SPEAKER_TOP_FRONT_RIGHT 0x00004000
- #define SPEAKER_TOP_BACK_LEFT 0x00008000
- #define SPEAKER_TOP_BACK_CENTER 0x00010000
- #define SPEAKER_TOP_BACK_RIGHT 0x00020000
- #define SPEAKER_RESERVED 0x7FFC0000
- #define SPEAKER_ALL 0x80000000
-#endif
-
-#ifndef WAVE_FORMAT_EXTENSIBLE
- #define WAVE_FORMAT_EXTENSIBLE 0xFFFE
-#endif
-
-#ifndef WAVE_FORMAT_IEEE_FLOAT
- #define WAVE_FORMAT_IEEE_FLOAT 0x0003
-#endif
-
-static const GUID _KSDATAFORMAT_SUBTYPE_PCM = {
- 0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
-
-static const GUID _KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = {
- 0x00000003, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
-
-QT_BEGIN_NAMESPACE
-
-bool qt_convertFormat(const QAudioFormat &format, WAVEFORMATEXTENSIBLE *wfx)
-{
- if (!wfx
- || !format.isValid()
- || format.codec() != QStringLiteral("audio/pcm")
- || format.sampleRate() <= 0
- || format.channelCount() <= 0
- || format.sampleSize() <= 0
- || format.byteOrder() != QAudioFormat::LittleEndian) {
- return false;
- }
-
- wfx->Format.nSamplesPerSec = format.sampleRate();
- wfx->Format.wBitsPerSample = wfx->Samples.wValidBitsPerSample = format.sampleSize();
- wfx->Format.nChannels = format.channelCount();
- wfx->Format.nBlockAlign = (wfx->Format.wBitsPerSample / 8) * wfx->Format.nChannels;
- wfx->Format.nAvgBytesPerSec = wfx->Format.nBlockAlign * wfx->Format.nSamplesPerSec;
- wfx->Format.cbSize = 0;
-
- if (format.sampleType() == QAudioFormat::Float) {
- wfx->Format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
- wfx->SubFormat = _KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
- } else {
- wfx->Format.wFormatTag = WAVE_FORMAT_PCM;
- wfx->SubFormat = _KSDATAFORMAT_SUBTYPE_PCM;
- }
-
- if (format.channelCount() > 2) {
- wfx->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
- wfx->Format.cbSize = 22;
- wfx->dwChannelMask = 0xFFFFFFFF >> (32 - format.channelCount());
- }
-
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/windowsaudio/qwindowsaudioutils.h b/src/plugins/windowsaudio/qwindowsaudioutils.h
deleted file mode 100644
index b8567d85c..000000000
--- a/src/plugins/windowsaudio/qwindowsaudioutils.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QWINDOWSAUDIOUTILS_H
-#define QWINDOWSAUDIOUTILS_H
-
-#include <qaudioformat.h>
-#include <QtCore/qt_windows.h>
-#include <mmsystem.h>
-
-#ifndef _WAVEFORMATEXTENSIBLE_
-
- #define _WAVEFORMATEXTENSIBLE_
- typedef struct
- {
- WAVEFORMATEX Format; // Base WAVEFORMATEX data
- union
- {
- WORD wValidBitsPerSample; // Valid bits in each sample container
- WORD wSamplesPerBlock; // Samples per block of audio data; valid
- // if wBitsPerSample=0 (but rarely used).
- WORD wReserved; // Zero if neither case above applies.
- } Samples;
- DWORD dwChannelMask; // Positions of the audio channels
- GUID SubFormat; // Format identifier GUID
- } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE, *LPPWAVEFORMATEXTENSIBLE;
- typedef const WAVEFORMATEXTENSIBLE* LPCWAVEFORMATEXTENSIBLE;
-
-#endif
-
-QT_BEGIN_NAMESPACE
-
-bool qt_convertFormat(const QAudioFormat &format, WAVEFORMATEXTENSIBLE *wfx);
-
-QT_END_NAMESPACE
-
-#endif // QWINDOWSAUDIOUTILS_H
diff --git a/src/plugins/windowsaudio/windowsaudio.json b/src/plugins/windowsaudio/windowsaudio.json
deleted file mode 100644
index a31d52107..000000000
--- a/src/plugins/windowsaudio/windowsaudio.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "Keys": ["default"]
-}
diff --git a/src/plugins/windowsaudio/windowsaudio.pro b/src/plugins/windowsaudio/windowsaudio.pro
deleted file mode 100644
index 6d5fe9495..000000000
--- a/src/plugins/windowsaudio/windowsaudio.pro
+++ /dev/null
@@ -1,25 +0,0 @@
-TARGET = qtaudio_windows
-QT += multimedia-private
-
-LIBS += -lstrmiids -lole32 -loleaut32 -lwinmm
-
-HEADERS += \
- qwindowsaudioplugin.h \
- qwindowsaudiodeviceinfo.h \
- qwindowsaudioinput.h \
- qwindowsaudiooutput.h \
- qwindowsaudioutils.h
-
-SOURCES += \
- qwindowsaudioplugin.cpp \
- qwindowsaudiodeviceinfo.cpp \
- qwindowsaudioinput.cpp \
- qwindowsaudiooutput.cpp \
- qwindowsaudioutils.cpp
-
-OTHER_FILES += \
- windowsaudio.json
-
-PLUGIN_TYPE = audio
-PLUGIN_CLASS_NAME = QWindowsAudioPlugin
-load(qt_plugin)
diff --git a/src/plugins/wmf/decoder/decoder.pri b/src/plugins/wmf/decoder/decoder.pri
deleted file mode 100644
index 7637ac848..000000000
--- a/src/plugins/wmf/decoder/decoder.pri
+++ /dev/null
@@ -1,14 +0,0 @@
-INCLUDEPATH += $$PWD
-
-LIBS += -lmfreadwrite -lwmcodecdspuuid
-QMAKE_USE += wmf
-
-HEADERS += \
- $$PWD/mfdecoderservice.h \
- $$PWD/mfdecodersourcereader.h \
- $$PWD/mfaudiodecodercontrol.h
-
-SOURCES += \
- $$PWD/mfdecoderservice.cpp \
- $$PWD/mfdecodersourcereader.cpp \
- $$PWD/mfaudiodecodercontrol.cpp
diff --git a/src/plugins/wmf/decoder/mfaudiodecodercontrol.cpp b/src/plugins/wmf/decoder/mfaudiodecodercontrol.cpp
deleted file mode 100644
index c0eada324..000000000
--- a/src/plugins/wmf/decoder/mfaudiodecodercontrol.cpp
+++ /dev/null
@@ -1,486 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "Wmcodecdsp.h"
-#include "mfaudiodecodercontrol.h"
-
-MFAudioDecoderControl::MFAudioDecoderControl(QObject *parent)
- : QAudioDecoderControl(parent)
- , m_decoderSourceReader(new MFDecoderSourceReader)
- , m_sourceResolver(new SourceResolver)
- , m_resampler(0)
- , m_state(QAudioDecoder::StoppedState)
- , m_device(0)
- , m_mfInputStreamID(0)
- , m_mfOutputStreamID(0)
- , m_bufferReady(false)
- , m_duration(0)
- , m_position(0)
- , m_loadingSource(false)
- , m_mfOutputType(0)
- , m_convertSample(0)
- , m_sourceReady(false)
- , m_resamplerDirty(false)
-{
- CoCreateInstance(CLSID_CResamplerMediaObject, NULL, CLSCTX_INPROC_SERVER, IID_IMFTransform, (LPVOID*)(&m_resampler));
- if (!m_resampler) {
- qCritical("MFAudioDecoderControl: Failed to create resampler(CLSID_CResamplerMediaObject)!");
- return;
- }
- m_resampler->AddInputStreams(1, &m_mfInputStreamID);
-
- connect(m_sourceResolver, SIGNAL(mediaSourceReady()), this, SLOT(handleMediaSourceReady()));
- connect(m_sourceResolver, SIGNAL(error(long)), this, SLOT(handleMediaSourceError(long)));
- connect(m_decoderSourceReader, SIGNAL(finished()), this, SLOT(handleSourceFinished()));
-
- QAudioFormat defaultFormat;
- defaultFormat.setCodec("audio/pcm");
- setAudioFormat(defaultFormat);
-}
-
-MFAudioDecoderControl::~MFAudioDecoderControl()
-{
- if (m_mfOutputType)
- m_mfOutputType->Release();
- m_decoderSourceReader->shutdown();
- m_decoderSourceReader->Release();
- m_sourceResolver->Release();
- if (m_resampler)
- m_resampler->Release();
-}
-
-QAudioDecoder::State MFAudioDecoderControl::state() const
-{
- return m_state;
-}
-
-QString MFAudioDecoderControl::sourceFilename() const
-{
- return m_sourceFilename;
-}
-
-void MFAudioDecoderControl::onSourceCleared()
-{
- bool positionDirty = false;
- bool durationDirty = false;
- if (m_position != 0) {
- m_position = 0;
- positionDirty = true;
- }
- if (m_duration != 0) {
- m_duration = 0;
- durationDirty = true;
- }
- if (positionDirty)
- emit positionChanged(m_position);
- if (durationDirty)
- emit durationChanged(m_duration);
-}
-
-void MFAudioDecoderControl::setSourceFilename(const QString &fileName)
-{
- if (!m_device && m_sourceFilename == fileName)
- return;
- m_sourceReady = false;
- m_sourceResolver->cancel();
- m_decoderSourceReader->setSource(0, m_audioFormat);
- m_device = 0;
- m_sourceFilename = fileName;
- if (!m_sourceFilename.isEmpty()) {
- m_sourceResolver->shutdown();
- QUrl url;
- if (m_sourceFilename.startsWith(':'))
- url = QUrl(QStringLiteral("qrc%1").arg(m_sourceFilename));
- else
- url = QUrl::fromLocalFile(m_sourceFilename);
- m_sourceResolver->load(url, 0);
- m_loadingSource = true;
- } else {
- onSourceCleared();
- }
- emit sourceChanged();
-}
-
-QIODevice* MFAudioDecoderControl::sourceDevice() const
-{
- return m_device;
-}
-
-void MFAudioDecoderControl::setSourceDevice(QIODevice *device)
-{
- if (m_device == device && m_sourceFilename.isEmpty())
- return;
- m_sourceReady = false;
- m_sourceResolver->cancel();
- m_decoderSourceReader->setSource(0, m_audioFormat);
- m_sourceFilename.clear();
- m_device = device;
- if (m_device) {
- m_sourceResolver->shutdown();
- m_sourceResolver->load(QUrl(), m_device);
- m_loadingSource = true;
- } else {
- onSourceCleared();
- }
- emit sourceChanged();
-}
-
-void MFAudioDecoderControl::updateResamplerOutputType()
-{
- m_resamplerDirty = false;
- if (m_audioFormat == m_sourceOutputFormat)
- return;
- HRESULT hr = m_resampler->SetOutputType(m_mfOutputStreamID, m_mfOutputType, 0);
- if (SUCCEEDED(hr)) {
- MFT_OUTPUT_STREAM_INFO streamInfo;
- m_resampler->GetOutputStreamInfo(m_mfOutputStreamID, &streamInfo);
- if ((streamInfo.dwFlags & (MFT_OUTPUT_STREAM_PROVIDES_SAMPLES | MFT_OUTPUT_STREAM_CAN_PROVIDE_SAMPLES)) == 0) {
- //if resampler does not allocate output sample memory, we do it here
- if (m_convertSample) {
- m_convertSample->Release();
- m_convertSample = 0;
- }
- if (SUCCEEDED(MFCreateSample(&m_convertSample))) {
- IMFMediaBuffer *mbuf = 0;;
- if (SUCCEEDED(MFCreateMemoryBuffer(streamInfo.cbSize, &mbuf))) {
- m_convertSample->AddBuffer(mbuf);
- mbuf->Release();
- }
- }
- }
- } else {
- qWarning() << "MFAudioDecoderControl: failed to SetOutputType of resampler" << hr;
- }
-}
-
-void MFAudioDecoderControl::handleMediaSourceReady()
-{
- m_loadingSource = false;
- m_sourceReady = true;
- IMFMediaType *mediaType = m_decoderSourceReader->setSource(m_sourceResolver->mediaSource(), m_audioFormat);
- m_sourceOutputFormat = QAudioFormat();
-
- if (mediaType) {
- m_sourceOutputFormat = m_audioFormat;
- QAudioFormat af = m_audioFormat;
-
- UINT32 val = 0;
- if (SUCCEEDED(mediaType->GetUINT32(MF_MT_AUDIO_NUM_CHANNELS, &val))) {
- m_sourceOutputFormat.setChannelCount(int(val));
- }
- if (SUCCEEDED(mediaType->GetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, &val))) {
- m_sourceOutputFormat.setSampleRate(int(val));
- }
- if (SUCCEEDED(mediaType->GetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, &val))) {
- m_sourceOutputFormat.setSampleSize(int(val));
- }
-
- GUID subType;
- if (SUCCEEDED(mediaType->GetGUID(MF_MT_SUBTYPE, &subType))) {
- if (subType == MFAudioFormat_Float) {
- m_sourceOutputFormat.setSampleType(QAudioFormat::Float);
- } else if (m_sourceOutputFormat.sampleSize() == 8) {
- m_sourceOutputFormat.setSampleType(QAudioFormat::UnSignedInt);
- } else {
- m_sourceOutputFormat.setSampleType(QAudioFormat::SignedInt);
- }
- }
- if (m_sourceOutputFormat.sampleType() != QAudioFormat::Float) {
- m_sourceOutputFormat.setByteOrder(QAudioFormat::LittleEndian);
- }
-
- if (m_audioFormat.sampleType() != QAudioFormat::Float
- && m_audioFormat.sampleType() != QAudioFormat::SignedInt) {
- af.setSampleType(m_sourceOutputFormat.sampleType());
- }
- if (af.sampleType() == QAudioFormat::SignedInt) {
- af.setByteOrder(QAudioFormat::LittleEndian);
- }
- if (m_audioFormat.channelCount() <= 0) {
- af.setChannelCount(m_sourceOutputFormat.channelCount());
- }
- if (m_audioFormat.sampleRate() <= 0) {
- af.setSampleRate(m_sourceOutputFormat.sampleRate());
- }
- if (m_audioFormat.sampleSize() <= 0) {
- af.setSampleSize(m_sourceOutputFormat.sampleSize());
- }
- setAudioFormat(af);
- }
-
- if (m_sourceResolver->mediaSource()) {
- if (mediaType && m_resampler) {
- HRESULT hr = S_OK;
- hr = m_resampler->SetInputType(m_mfInputStreamID, mediaType, 0);
- if (SUCCEEDED(hr)) {
- updateResamplerOutputType();
- } else {
- qWarning() << "MFAudioDecoderControl: failed to SetInputType of resampler" << hr;
- }
- }
- IMFPresentationDescriptor *pd;
- if (SUCCEEDED(m_sourceResolver->mediaSource()->CreatePresentationDescriptor(&pd))) {
- UINT64 duration = 0;
- pd->GetUINT64(MF_PD_DURATION, &duration);
- pd->Release();
- duration /= 10000;
- if (m_duration != qint64(duration)) {
- m_duration = qint64(duration);
- emit durationChanged(m_duration);
- }
- }
- if (m_state == QAudioDecoder::DecodingState) {
- activatePipeline();
- }
- } else if (m_state != QAudioDecoder::StoppedState) {
- m_state = QAudioDecoder::StoppedState;
- emit stateChanged(m_state);
- }
-}
-
-void MFAudioDecoderControl::handleMediaSourceError(long hr)
-{
- Q_UNUSED(hr);
- m_loadingSource = false;
- m_decoderSourceReader->setSource(0, m_audioFormat);
- if (m_state != QAudioDecoder::StoppedState) {
- m_state = QAudioDecoder::StoppedState;
- emit stateChanged(m_state);
- }
-}
-
-void MFAudioDecoderControl::activatePipeline()
-{
- Q_ASSERT(!m_bufferReady);
- m_state = QAudioDecoder::DecodingState;
- connect(m_decoderSourceReader, SIGNAL(sampleAdded()), this, SLOT(handleSampleAdded()));
- if (m_resamplerDirty) {
- updateResamplerOutputType();
- }
- m_decoderSourceReader->reset();
- m_decoderSourceReader->readNextSample();
- if (m_position != 0) {
- m_position = 0;
- emit positionChanged(0);
- }
-}
-
-void MFAudioDecoderControl::start()
-{
- if (m_state != QAudioDecoder::StoppedState)
- return;
-
- if (m_loadingSource) {
- //deferred starting
- m_state = QAudioDecoder::DecodingState;
- emit stateChanged(m_state);
- return;
- }
-
- if (!m_decoderSourceReader->mediaSource())
- return;
- activatePipeline();
- emit stateChanged(m_state);
-}
-
-void MFAudioDecoderControl::stop()
-{
- if (m_state == QAudioDecoder::StoppedState)
- return;
- m_state = QAudioDecoder::StoppedState;
- disconnect(m_decoderSourceReader, SIGNAL(sampleAdded()), this, SLOT(handleSampleAdded()));
- if (m_bufferReady) {
- m_bufferReady = false;
- emit bufferAvailableChanged(m_bufferReady);
- }
- emit stateChanged(m_state);
-}
-
-void MFAudioDecoderControl::handleSampleAdded()
-{
- QList<IMFSample*> samples = m_decoderSourceReader->takeSamples();
- Q_ASSERT(samples.count() > 0);
- Q_ASSERT(!m_bufferReady);
- Q_ASSERT(m_resampler);
- LONGLONG sampleStartTime = 0;
- IMFSample *firstSample = samples.first();
- firstSample->GetSampleTime(&sampleStartTime);
- QByteArray abuf;
- if (m_sourceOutputFormat == m_audioFormat) {
- //no need for resampling
- for (IMFSample *s : qAsConst(samples)) {
- IMFMediaBuffer *buffer;
- s->ConvertToContiguousBuffer(&buffer);
- DWORD bufLen = 0;
- BYTE *buf = 0;
- if (SUCCEEDED(buffer->Lock(&buf, NULL, &bufLen))) {
- abuf.push_back(QByteArray(reinterpret_cast<char*>(buf), bufLen));
- buffer->Unlock();
- }
- buffer->Release();
- LONGLONG sampleTime = 0, sampleDuration = 0;
- s->GetSampleTime(&sampleTime);
- s->GetSampleDuration(&sampleDuration);
- m_position = qint64(sampleTime + sampleDuration) / 10000;
- s->Release();
- }
- } else {
- for (IMFSample *s : qAsConst(samples)) {
- HRESULT hr = m_resampler->ProcessInput(m_mfInputStreamID, s, 0);
- if (SUCCEEDED(hr)) {
- MFT_OUTPUT_DATA_BUFFER outputDataBuffer;
- outputDataBuffer.dwStreamID = m_mfOutputStreamID;
- while (true) {
- outputDataBuffer.pEvents = 0;
- outputDataBuffer.dwStatus = 0;
- outputDataBuffer.pSample = m_convertSample;
- DWORD status = 0;
- if (SUCCEEDED(m_resampler->ProcessOutput(0, 1, &outputDataBuffer, &status))) {
- IMFMediaBuffer *buffer;
- outputDataBuffer.pSample->ConvertToContiguousBuffer(&buffer);
- DWORD bufLen = 0;
- BYTE *buf = 0;
- if (SUCCEEDED(buffer->Lock(&buf, NULL, &bufLen))) {
- abuf.push_back(QByteArray(reinterpret_cast<char*>(buf), bufLen));
- buffer->Unlock();
- }
- buffer->Release();
- } else {
- break;
- }
- }
- }
- LONGLONG sampleTime = 0, sampleDuration = 0;
- s->GetSampleTime(&sampleTime);
- s->GetSampleDuration(&sampleDuration);
- m_position = qint64(sampleTime + sampleDuration) / 10000;
- s->Release();
- }
- }
- // WMF uses 100-nanosecond units, QAudioDecoder uses milliseconds, QAudioBuffer uses microseconds...
- m_cachedAudioBuffer = QAudioBuffer(abuf, m_audioFormat, qint64(sampleStartTime / 10));
- m_bufferReady = true;
- emit positionChanged(m_position);
- emit bufferAvailableChanged(m_bufferReady);
- emit bufferReady();
-}
-
-void MFAudioDecoderControl::handleSourceFinished()
-{
- stop();
- emit finished();
-}
-
-QAudioFormat MFAudioDecoderControl::audioFormat() const
-{
- return m_audioFormat;
-}
-
-void MFAudioDecoderControl::setAudioFormat(const QAudioFormat &format)
-{
- if (m_audioFormat == format || !m_resampler)
- return;
- if (format.codec() != QLatin1String("audio/x-wav") && format.codec() != QLatin1String("audio/pcm")) {
- qWarning("MFAudioDecoderControl does not accept non-pcm audio format!");
- return;
- }
- m_audioFormat = format;
-
- if (m_audioFormat.isValid()) {
- IMFMediaType *mediaType = 0;
- MFCreateMediaType(&mediaType);
- mediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
- if (format.sampleType() == QAudioFormat::Float) {
- mediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_Float);
- } else {
- mediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
- }
-
- mediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, UINT32(m_audioFormat.channelCount()));
- mediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, UINT32(m_audioFormat.sampleRate()));
- UINT32 alignmentBlock = UINT32(m_audioFormat.channelCount() * m_audioFormat.sampleSize() / 8);
- mediaType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, alignmentBlock);
- UINT32 avgBytesPerSec = UINT32(m_audioFormat.sampleRate() * m_audioFormat.sampleSize() / 8 * m_audioFormat.channelCount());
- mediaType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, avgBytesPerSec);
- mediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, UINT32(m_audioFormat.sampleSize()));
- mediaType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
-
- if (m_mfOutputType)
- m_mfOutputType->Release();
- m_mfOutputType = mediaType;
- } else {
- if (m_mfOutputType)
- m_mfOutputType->Release();
- m_mfOutputType = NULL;
- }
-
- if (m_sourceReady && m_state == QAudioDecoder::StoppedState) {
- updateResamplerOutputType();
- } else {
- m_resamplerDirty = true;
- }
-
- emit formatChanged(m_audioFormat);
-}
-
-QAudioBuffer MFAudioDecoderControl::read()
-{
- if (!m_bufferReady)
- return QAudioBuffer();
- QAudioBuffer buffer = m_cachedAudioBuffer;
- m_bufferReady = false;
- emit bufferAvailableChanged(m_bufferReady);
- m_decoderSourceReader->readNextSample();
- return buffer;
-}
-
-bool MFAudioDecoderControl::bufferAvailable() const
-{
- return m_bufferReady;
-}
-
-qint64 MFAudioDecoderControl::position() const
-{
- return m_position;
-}
-
-qint64 MFAudioDecoderControl::duration() const
-{
- return m_duration;
-}
diff --git a/src/plugins/wmf/decoder/mfaudiodecodercontrol.h b/src/plugins/wmf/decoder/mfaudiodecodercontrol.h
deleted file mode 100644
index cfb8e9091..000000000
--- a/src/plugins/wmf/decoder/mfaudiodecodercontrol.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFAUDIODECODERCONTROL_H
-#define MFAUDIODECODERCONTROL_H
-
-#include "qaudiodecodercontrol.h"
-#include "mfdecodersourcereader.h"
-#include "sourceresolver.h"
-
-QT_USE_NAMESPACE
-
-class MFAudioDecoderControl : public QAudioDecoderControl
-{
- Q_OBJECT
-public:
- MFAudioDecoderControl(QObject *parent = 0);
- ~MFAudioDecoderControl();
-
- QAudioDecoder::State state() const;
-
- QString sourceFilename() const;
- void setSourceFilename(const QString &fileName);
-
- QIODevice* sourceDevice() const;
- void setSourceDevice(QIODevice *device);
-
- void start();
- void stop();
-
- QAudioFormat audioFormat() const;
- void setAudioFormat(const QAudioFormat &format);
-
- QAudioBuffer read();
- bool bufferAvailable() const;
-
- qint64 position() const;
- qint64 duration() const;
-
-private Q_SLOTS:
- void handleMediaSourceReady();
- void handleMediaSourceError(long hr);
- void handleSampleAdded();
- void handleSourceFinished();
-
-private:
- void updateResamplerOutputType();
- void activatePipeline();
- void onSourceCleared();
-
- MFDecoderSourceReader *m_decoderSourceReader;
- SourceResolver *m_sourceResolver;
- IMFTransform *m_resampler;
- QAudioDecoder::State m_state;
- QString m_sourceFilename;
- QIODevice *m_device;
- QAudioFormat m_audioFormat;
- DWORD m_mfInputStreamID;
- DWORD m_mfOutputStreamID;
- bool m_bufferReady;
- QAudioBuffer m_cachedAudioBuffer;
- qint64 m_duration;
- qint64 m_position;
- bool m_loadingSource;
- IMFMediaType *m_mfOutputType;
- IMFSample *m_convertSample;
- QAudioFormat m_sourceOutputFormat;
- bool m_sourceReady;
- bool m_resamplerDirty;
-};
-
-#endif//MFAUDIODECODERCONTROL_H
diff --git a/src/plugins/wmf/decoder/mfdecoderservice.cpp b/src/plugins/wmf/decoder/mfdecoderservice.cpp
deleted file mode 100644
index c6ed3976a..000000000
--- a/src/plugins/wmf/decoder/mfdecoderservice.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mfdecoderservice.h"
-#include "mfaudiodecodercontrol.h"
-
-MFAudioDecoderService::MFAudioDecoderService(QObject *parent)
- : QMediaService(parent)
-{
-}
-
-MFAudioDecoderService::~MFAudioDecoderService()
-{
-}
-
-QMediaControl* MFAudioDecoderService::requestControl(const char *name)
-{
- if (qstrcmp(name, QAudioDecoderControl_iid) == 0) {
- return new MFAudioDecoderControl(this);
- }
- return 0;
-}
-
-void MFAudioDecoderService::releaseControl(QMediaControl *control)
-{
- if (control && control->inherits("MFAudioDecoderControl")) {
- delete control;
- }
-}
diff --git a/src/plugins/wmf/decoder/mfdecoderservice.h b/src/plugins/wmf/decoder/mfdecoderservice.h
deleted file mode 100644
index 14899ee39..000000000
--- a/src/plugins/wmf/decoder/mfdecoderservice.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFDECODERSERVICE_H
-#define MFDECODERSERVICE_H
-
-#include "qmediaservice.h"
-
-class MFAudioDecoderService : public QMediaService
-{
- Q_OBJECT
-public:
- MFAudioDecoderService(QObject *parent = 0);
- ~MFAudioDecoderService();
-
- QMediaControl* requestControl(const char *name);
- void releaseControl(QMediaControl *control);
-};
-
-#endif//MFDECODERSERVICE_H
diff --git a/src/plugins/wmf/decoder/mfdecodersourcereader.cpp b/src/plugins/wmf/decoder/mfdecodersourcereader.cpp
deleted file mode 100644
index e907cfaf0..000000000
--- a/src/plugins/wmf/decoder/mfdecodersourcereader.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mfdecodersourcereader.h"
-
-MFDecoderSourceReader::MFDecoderSourceReader(QObject *parent)
- : m_cRef(1)
- , m_sourceReader(0)
- , m_source(0)
-{
- Q_UNUSED(parent);
-}
-
-void MFDecoderSourceReader::shutdown()
-{
- if (m_source) {
- m_source->Release();
- m_source = NULL;
- }
- if (m_sourceReader) {
- m_sourceReader->Release();
- m_sourceReader = NULL;
- }
-}
-
-IMFMediaSource* MFDecoderSourceReader::mediaSource()
-{
- return m_source;
-}
-
-IMFMediaType* MFDecoderSourceReader::setSource(IMFMediaSource *source, const QAudioFormat &audioFormat)
-{
- IMFMediaType *mediaType = NULL;
- if (m_source == source)
- return mediaType;
- if (m_source) {
- m_source->Release();
- m_source = NULL;
- }
- if (m_sourceReader) {
- m_sourceReader->Release();
- m_sourceReader = NULL;
- }
- if (!source)
- return mediaType;
- IMFAttributes *attr = NULL;
- MFCreateAttributes(&attr, 1);
- if (SUCCEEDED(attr->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, this))) {
- if (SUCCEEDED(MFCreateSourceReaderFromMediaSource(source, attr, &m_sourceReader))) {
- m_source = source;
- m_source->AddRef();
- m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_ALL_STREAMS), FALSE);
- m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), TRUE);
- IMFMediaType *pPartialType = NULL;
- MFCreateMediaType(&pPartialType);
- pPartialType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
-
- if (audioFormat.sampleType() == QAudioFormat::Float) {
- pPartialType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_Float);
- } else {
- pPartialType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
- }
-
- m_sourceReader->SetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), NULL, pPartialType);
- pPartialType->Release();
- m_sourceReader->GetCurrentMediaType(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), &mediaType);
- // Ensure the stream is selected.
- m_sourceReader->SetStreamSelection(DWORD(MF_SOURCE_READER_FIRST_AUDIO_STREAM), TRUE);
- }
- attr->Release();
- }
- return mediaType;
-}
-
-void MFDecoderSourceReader::reset()
-{
- if (!m_sourceReader)
- return;
- PROPVARIANT vPos;
- PropVariantInit(&vPos);
- vPos.vt = VT_I8;
- vPos.uhVal.QuadPart = 0;
- m_sourceReader->SetCurrentPosition(GUID_NULL, vPos);
-}
-
-void MFDecoderSourceReader::readNextSample()
-{
- if (!m_sourceReader)
- return;
- m_sourceReader->ReadSample(MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, NULL, NULL, NULL, NULL);
-}
-
-QList<IMFSample*> MFDecoderSourceReader::takeSamples() //internal samples will be cleared after this
-{
- QList<IMFSample*> samples;
- m_samplesMutex.lock();
- samples = m_cachedSamples;
- m_cachedSamples.clear();
- m_samplesMutex.unlock();
- return samples;
-}
-
-//from IUnknown
-STDMETHODIMP MFDecoderSourceReader::QueryInterface(REFIID riid, LPVOID *ppvObject)
-{
- if (!ppvObject)
- return E_POINTER;
- if (riid == IID_IMFSourceReaderCallback) {
- *ppvObject = static_cast<IMFSourceReaderCallback*>(this);
- } else if (riid == IID_IUnknown) {
- *ppvObject = static_cast<IUnknown*>(this);
- } else {
- *ppvObject = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
-}
-
-STDMETHODIMP_(ULONG) MFDecoderSourceReader::AddRef(void)
-{
- return InterlockedIncrement(&m_cRef);
-}
-
-STDMETHODIMP_(ULONG) MFDecoderSourceReader::Release(void)
-{
- LONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0) {
- this->deleteLater();
- }
- return cRef;
-}
-
-//from IMFSourceReaderCallback
-STDMETHODIMP MFDecoderSourceReader::OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex,
- DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample *pSample)
-{
- Q_UNUSED(hrStatus);
- Q_UNUSED(dwStreamIndex);
- Q_UNUSED(llTimestamp);
- if (pSample) {
- pSample->AddRef();
- m_samplesMutex.lock();
- m_cachedSamples.push_back(pSample);
- m_samplesMutex.unlock();
- emit sampleAdded();
- } else if ((dwStreamFlags & MF_SOURCE_READERF_ENDOFSTREAM) == MF_SOURCE_READERF_ENDOFSTREAM) {
- emit finished();
- }
- return S_OK;
-}
-
-STDMETHODIMP MFDecoderSourceReader::OnFlush(DWORD)
-{
- return S_OK;
-}
-
-STDMETHODIMP MFDecoderSourceReader::OnEvent(DWORD, IMFMediaEvent*)
-{
- return S_OK;
-}
diff --git a/src/plugins/wmf/decoder/mfdecodersourcereader.h b/src/plugins/wmf/decoder/mfdecodersourcereader.h
deleted file mode 100644
index 21c6b5eb3..000000000
--- a/src/plugins/wmf/decoder/mfdecodersourcereader.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFDECODERSOURCEREADER_H
-#define MFDECODERSOURCEREADER_H
-#include <mfapi.h>
-#include <mfidl.h>
-#include <Mfreadwrite.h>
-
-#include <QtCore/qobject.h>
-#include <QtCore/qmutex.h>
-#include "qaudioformat.h"
-
-QT_USE_NAMESPACE
-
-class MFDecoderSourceReader : public QObject, public IMFSourceReaderCallback
-{
- Q_OBJECT
-public:
- MFDecoderSourceReader(QObject *parent = 0);
- void shutdown();
-
- IMFMediaSource* mediaSource();
- IMFMediaType* setSource(IMFMediaSource *source, const QAudioFormat &audioFormat);
-
- void reset();
- void readNextSample();
- QList<IMFSample*> takeSamples(); //internal samples will be cleared after this
-
- //from IUnknown
- STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject);
- STDMETHODIMP_(ULONG) AddRef(void);
- STDMETHODIMP_(ULONG) Release(void);
-
- //from IMFSourceReaderCallback
- STDMETHODIMP OnReadSample(HRESULT hrStatus, DWORD dwStreamIndex,
- DWORD dwStreamFlags, LONGLONG llTimestamp, IMFSample *pSample);
- STDMETHODIMP OnFlush(DWORD dwStreamIndex);
- STDMETHODIMP OnEvent(DWORD dwStreamIndex, IMFMediaEvent *pEvent);
-
-Q_SIGNALS:
- void sampleAdded();
- void finished();
-
-private:
- long m_cRef;
- QList<IMFSample*> m_cachedSamples;
- QMutex m_samplesMutex;
-
- IMFSourceReader *m_sourceReader;
- IMFMediaSource *m_source;
-};
-#endif//MFDECODERSOURCEREADER_H
diff --git a/src/plugins/wmf/mfstream.cpp b/src/plugins/wmf/mfstream.cpp
deleted file mode 100644
index a98b5a704..000000000
--- a/src/plugins/wmf/mfstream.cpp
+++ /dev/null
@@ -1,361 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mfstream.h"
-#include <QtCore/qcoreapplication.h>
-
-//MFStream is added for supporting QIODevice type of media source.
-//It is used to delegate invocations from media foundation(through IMFByteStream) to QIODevice.
-
-MFStream::MFStream(QIODevice *stream, bool ownStream)
- : m_cRef(1)
- , m_stream(stream)
- , m_ownStream(ownStream)
- , m_currentReadResult(0)
-{
- //Move to the thread of the stream object
- //to make sure invocations on stream
- //are happened in the same thread of stream object
- this->moveToThread(stream->thread());
- connect(stream, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));
-}
-
-MFStream::~MFStream()
-{
- if (m_currentReadResult)
- m_currentReadResult->Release();
- if (m_ownStream)
- m_stream->deleteLater();
-}
-
-//from IUnknown
-STDMETHODIMP MFStream::QueryInterface(REFIID riid, LPVOID *ppvObject)
-{
- if (!ppvObject)
- return E_POINTER;
- if (riid == IID_IMFByteStream) {
- *ppvObject = static_cast<IMFByteStream*>(this);
- } else if (riid == IID_IUnknown) {
- *ppvObject = static_cast<IUnknown*>(this);
- } else {
- *ppvObject = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
-}
-
-STDMETHODIMP_(ULONG) MFStream::AddRef(void)
-{
- return InterlockedIncrement(&m_cRef);
-}
-
-STDMETHODIMP_(ULONG) MFStream::Release(void)
-{
- LONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0) {
- this->deleteLater();
- }
- return cRef;
-}
-
-
-//from IMFByteStream
-STDMETHODIMP MFStream::GetCapabilities(DWORD *pdwCapabilities)
-{
- if (!pdwCapabilities)
- return E_INVALIDARG;
- *pdwCapabilities = MFBYTESTREAM_IS_READABLE;
- if (!m_stream->isSequential())
- *pdwCapabilities |= MFBYTESTREAM_IS_SEEKABLE;
- return S_OK;
-}
-
-STDMETHODIMP MFStream::GetLength(QWORD *pqwLength)
-{
- if (!pqwLength)
- return E_INVALIDARG;
- QMutexLocker locker(&m_mutex);
- *pqwLength = QWORD(m_stream->size());
- return S_OK;
-}
-
-STDMETHODIMP MFStream::SetLength(QWORD)
-{
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFStream::GetCurrentPosition(QWORD *pqwPosition)
-{
- if (!pqwPosition)
- return E_INVALIDARG;
- QMutexLocker locker(&m_mutex);
- *pqwPosition = m_stream->pos();
- return S_OK;
-}
-
-STDMETHODIMP MFStream::SetCurrentPosition(QWORD qwPosition)
-{
- QMutexLocker locker(&m_mutex);
- //SetCurrentPosition may happend during the BeginRead/EndRead pair,
- //refusing to execute SetCurrentPosition during that time seems to be
- //the simplest workable solution
- if (m_currentReadResult)
- return S_FALSE;
-
- bool seekOK = m_stream->seek(qint64(qwPosition));
- if (seekOK)
- return S_OK;
- else
- return S_FALSE;
-}
-
-STDMETHODIMP MFStream::IsEndOfStream(BOOL *pfEndOfStream)
-{
- if (!pfEndOfStream)
- return E_INVALIDARG;
- QMutexLocker locker(&m_mutex);
- *pfEndOfStream = m_stream->atEnd() ? TRUE : FALSE;
- return S_OK;
-}
-
-STDMETHODIMP MFStream::Read(BYTE *pb, ULONG cb, ULONG *pcbRead)
-{
- QMutexLocker locker(&m_mutex);
- qint64 read = m_stream->read((char*)(pb), qint64(cb));
- if (pcbRead)
- *pcbRead = ULONG(read);
- return S_OK;
-}
-
-STDMETHODIMP MFStream::BeginRead(BYTE *pb, ULONG cb, IMFAsyncCallback *pCallback,
- IUnknown *punkState)
-{
- if (!pCallback || !pb)
- return E_INVALIDARG;
-
- Q_ASSERT(m_currentReadResult == NULL);
-
- AsyncReadState *state = new (std::nothrow) AsyncReadState(pb, cb);
- if (state == NULL)
- return E_OUTOFMEMORY;
-
- HRESULT hr = MFCreateAsyncResult(state, pCallback, punkState, &m_currentReadResult);
- state->Release();
- if (FAILED(hr))
- return hr;
-
- QCoreApplication::postEvent(this, new QEvent(QEvent::User));
- return hr;
-}
-
-STDMETHODIMP MFStream::EndRead(IMFAsyncResult* pResult, ULONG *pcbRead)
-{
- if (!pcbRead)
- return E_INVALIDARG;
- IUnknown *pUnk;
- pResult->GetObject(&pUnk);
- AsyncReadState *state = static_cast<AsyncReadState*>(pUnk);
- *pcbRead = state->bytesRead();
- pUnk->Release();
-
- m_currentReadResult->Release();
- m_currentReadResult = NULL;
-
- return S_OK;
-}
-
-STDMETHODIMP MFStream::Write(const BYTE *, ULONG, ULONG *)
-{
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFStream::BeginWrite(const BYTE *, ULONG ,
- IMFAsyncCallback *,
- IUnknown *)
-{
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFStream::EndWrite(IMFAsyncResult *,
- ULONG *)
-{
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFStream::Seek(
- MFBYTESTREAM_SEEK_ORIGIN SeekOrigin,
- LONGLONG llSeekOffset,
- DWORD,
- QWORD *pqwCurrentPosition)
-{
- QMutexLocker locker(&m_mutex);
- if (m_currentReadResult)
- return S_FALSE;
-
- qint64 pos = qint64(llSeekOffset);
- switch (SeekOrigin) {
- case msoBegin:
- break;
- case msoCurrent:
- pos += m_stream->pos();
- break;
- }
- bool seekOK = m_stream->seek(pos);
- if (pqwCurrentPosition)
- *pqwCurrentPosition = pos;
- if (seekOK)
- return S_OK;
- else
- return S_FALSE;
-}
-
-STDMETHODIMP MFStream::Flush()
-{
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFStream::Close()
-{
- QMutexLocker locker(&m_mutex);
- if (m_ownStream)
- m_stream->close();
- return S_OK;
-}
-
-void MFStream::doRead()
-{
- bool readDone = true;
- IUnknown *pUnk = NULL;
- HRESULT hr = m_currentReadResult->GetObject(&pUnk);
- if (SUCCEEDED(hr)) {
- //do actual read
- AsyncReadState *state = static_cast<AsyncReadState*>(pUnk);
- ULONG cbRead;
- Read(state->pb(), state->cb() - state->bytesRead(), &cbRead);
- pUnk->Release();
-
- state->setBytesRead(cbRead + state->bytesRead());
- if (state->cb() > state->bytesRead() && !m_stream->atEnd()) {
- readDone = false;
- }
- }
-
- if (readDone) {
- //now inform the original caller
- m_currentReadResult->SetStatus(hr);
- MFInvokeCallback(m_currentReadResult);
- }
-}
-
-
-void MFStream::handleReadyRead()
-{
- doRead();
-}
-
-void MFStream::customEvent(QEvent *event)
-{
- if (event->type() != QEvent::User) {
- QObject::customEvent(event);
- return;
- }
- doRead();
-}
-
-//AsyncReadState is a helper class used in BeginRead for asynchronous operation
-//to record some BeginRead parameters, so these parameters could be
-//used later when actually executing the read operation in another thread.
-MFStream::AsyncReadState::AsyncReadState(BYTE *pb, ULONG cb)
- : m_cRef(1)
- , m_pb(pb)
- , m_cb(cb)
- , m_cbRead(0)
-{
-}
-
-//from IUnknown
-STDMETHODIMP MFStream::AsyncReadState::QueryInterface(REFIID riid, LPVOID *ppvObject)
-{
- if (!ppvObject)
- return E_POINTER;
-
- if (riid == IID_IUnknown) {
- *ppvObject = static_cast<IUnknown*>(this);
- } else {
- *ppvObject = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
-}
-
-STDMETHODIMP_(ULONG) MFStream::AsyncReadState::AddRef(void)
-{
- return InterlockedIncrement(&m_cRef);
-}
-
-STDMETHODIMP_(ULONG) MFStream::AsyncReadState::Release(void)
-{
- LONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0)
- delete this;
- // For thread safety, return a temporary variable.
- return cRef;
-}
-
-BYTE* MFStream::AsyncReadState::pb() const
-{
- return m_pb;
-}
-
-ULONG MFStream::AsyncReadState::cb() const
-{
- return m_cb;
-}
-
-ULONG MFStream::AsyncReadState::bytesRead() const
-{
- return m_cbRead;
-}
-
-void MFStream::AsyncReadState::setBytesRead(ULONG cbRead)
-{
- m_cbRead = cbRead;
-}
diff --git a/src/plugins/wmf/mfstream.h b/src/plugins/wmf/mfstream.h
deleted file mode 100644
index f98ab42a9..000000000
--- a/src/plugins/wmf/mfstream.h
+++ /dev/null
@@ -1,148 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFSTREAM_H
-#define MFSTREAM_H
-
-#include <mfapi.h>
-#include <mfidl.h>
-#include <QtCore/qmutex.h>
-#include <QtCore/qiodevice.h>
-#include <QtCore/qcoreevent.h>
-
-QT_USE_NAMESPACE
-
-class MFStream : public QObject, public IMFByteStream
-{
- Q_OBJECT
-public:
- MFStream(QIODevice *stream, bool ownStream);
-
- ~MFStream();
-
- //from IUnknown
- STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject);
-
- STDMETHODIMP_(ULONG) AddRef(void);
-
- STDMETHODIMP_(ULONG) Release(void);
-
-
- //from IMFByteStream
- STDMETHODIMP GetCapabilities(DWORD *pdwCapabilities);
-
- STDMETHODIMP GetLength(QWORD *pqwLength);
-
- STDMETHODIMP SetLength(QWORD);
-
- STDMETHODIMP GetCurrentPosition(QWORD *pqwPosition);
-
- STDMETHODIMP SetCurrentPosition(QWORD qwPosition);
-
- STDMETHODIMP IsEndOfStream(BOOL *pfEndOfStream);
-
- STDMETHODIMP Read(BYTE *pb, ULONG cb, ULONG *pcbRead);
-
- STDMETHODIMP BeginRead(BYTE *pb, ULONG cb, IMFAsyncCallback *pCallback,
- IUnknown *punkState);
-
- STDMETHODIMP EndRead(IMFAsyncResult* pResult, ULONG *pcbRead);
-
- STDMETHODIMP Write(const BYTE *, ULONG, ULONG *);
-
- STDMETHODIMP BeginWrite(const BYTE *, ULONG ,
- IMFAsyncCallback *,
- IUnknown *);
-
- STDMETHODIMP EndWrite(IMFAsyncResult *,
- ULONG *);
-
- STDMETHODIMP Seek(
- MFBYTESTREAM_SEEK_ORIGIN SeekOrigin,
- LONGLONG llSeekOffset,
- DWORD,
- QWORD *pqwCurrentPosition);
-
- STDMETHODIMP Flush();
-
- STDMETHODIMP Close();
-
-private:
- class AsyncReadState : public IUnknown
- {
- public:
- AsyncReadState(BYTE *pb, ULONG cb);
-
- //from IUnknown
- STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject);
-
- STDMETHODIMP_(ULONG) AddRef(void);
-
- STDMETHODIMP_(ULONG) Release(void);
-
- BYTE* pb() const;
- ULONG cb() const;
- ULONG bytesRead() const;
-
- void setBytesRead(ULONG cbRead);
-
- private:
- long m_cRef;
- BYTE *m_pb;
- ULONG m_cb;
- ULONG m_cbRead;
- };
-
- long m_cRef;
- QIODevice *m_stream;
- bool m_ownStream;
- DWORD m_workQueueId;
- QMutex m_mutex;
-
- void doRead();
-
-private Q_SLOTS:
- void handleReadyRead();
-
-protected:
- void customEvent(QEvent *event);
- IMFAsyncResult *m_currentReadResult;
-};
-
-#endif
diff --git a/src/plugins/wmf/player/mfactivate.cpp b/src/plugins/wmf/player/mfactivate.cpp
deleted file mode 100644
index e06906584..000000000
--- a/src/plugins/wmf/player/mfactivate.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mfactivate.h"
-
-#include <mfapi.h>
-
-MFAbstractActivate::MFAbstractActivate()
- : m_attributes(0)
- , m_cRef(1)
-{
- MFCreateAttributes(&m_attributes, 0);
-}
-
-MFAbstractActivate::~MFAbstractActivate()
-{
- if (m_attributes)
- m_attributes->Release();
-}
-
-
-HRESULT MFAbstractActivate::QueryInterface(REFIID riid, LPVOID *ppvObject)
-{
- if (!ppvObject)
- return E_POINTER;
- if (riid == IID_IMFActivate) {
- *ppvObject = static_cast<IMFActivate*>(this);
- } else if (riid == IID_IMFAttributes) {
- *ppvObject = static_cast<IMFAttributes*>(this);
- } else if (riid == IID_IUnknown) {
- *ppvObject = static_cast<IUnknown*>(static_cast<IMFActivate*>(this));
- } else {
- *ppvObject = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
-}
-
-ULONG MFAbstractActivate::AddRef(void)
-{
- return InterlockedIncrement(&m_cRef);
-}
-
-ULONG MFAbstractActivate::Release(void)
-{
- ULONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0)
- delete this;
- return cRef;
-}
diff --git a/src/plugins/wmf/player/mfactivate.h b/src/plugins/wmf/player/mfactivate.h
deleted file mode 100644
index 3243296e8..000000000
--- a/src/plugins/wmf/player/mfactivate.h
+++ /dev/null
@@ -1,212 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFACTIVATE_H
-#define MFACTIVATE_H
-
-#include <mfidl.h>
-
-class MFAbstractActivate : public IMFActivate
-{
-public:
- explicit MFAbstractActivate();
- virtual ~MFAbstractActivate();
-
- //from IUnknown
- STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject);
- STDMETHODIMP_(ULONG) AddRef(void);
- STDMETHODIMP_(ULONG) Release(void);
-
- //from IMFAttributes
- STDMETHODIMP GetItem(REFGUID guidKey, PROPVARIANT *pValue)
- {
- return m_attributes->GetItem(guidKey, pValue);
- }
-
- STDMETHODIMP GetItemType(REFGUID guidKey, MF_ATTRIBUTE_TYPE *pType)
- {
- return m_attributes->GetItemType(guidKey, pType);
- }
-
- STDMETHODIMP CompareItem(REFGUID guidKey, REFPROPVARIANT Value, BOOL *pbResult)
- {
- return m_attributes->CompareItem(guidKey, Value, pbResult);
- }
-
- STDMETHODIMP Compare(IMFAttributes *pTheirs, MF_ATTRIBUTES_MATCH_TYPE MatchType, BOOL *pbResult)
- {
- return m_attributes->Compare(pTheirs, MatchType, pbResult);
- }
-
- STDMETHODIMP GetUINT32(REFGUID guidKey, UINT32 *punValue)
- {
- return m_attributes->GetUINT32(guidKey, punValue);
- }
-
- STDMETHODIMP GetUINT64(REFGUID guidKey, UINT64 *punValue)
- {
- return m_attributes->GetUINT64(guidKey, punValue);
- }
-
- STDMETHODIMP GetDouble(REFGUID guidKey, double *pfValue)
- {
- return m_attributes->GetDouble(guidKey, pfValue);
- }
-
- STDMETHODIMP GetGUID(REFGUID guidKey, GUID *pguidValue)
- {
- return m_attributes->GetGUID(guidKey, pguidValue);
- }
-
- STDMETHODIMP GetStringLength(REFGUID guidKey, UINT32 *pcchLength)
- {
- return m_attributes->GetStringLength(guidKey, pcchLength);
- }
-
- STDMETHODIMP GetString(REFGUID guidKey, LPWSTR pwszValue, UINT32 cchBufSize, UINT32 *pcchLength)
- {
- return m_attributes->GetString(guidKey, pwszValue, cchBufSize, pcchLength);
- }
-
- STDMETHODIMP GetAllocatedString(REFGUID guidKey, LPWSTR *ppwszValue, UINT32 *pcchLength)
- {
- return m_attributes->GetAllocatedString(guidKey, ppwszValue, pcchLength);
- }
-
- STDMETHODIMP GetBlobSize(REFGUID guidKey, UINT32 *pcbBlobSize)
- {
- return m_attributes->GetBlobSize(guidKey, pcbBlobSize);
- }
-
- STDMETHODIMP GetBlob(REFGUID guidKey, UINT8 *pBuf, UINT32 cbBufSize, UINT32 *pcbBlobSize)
- {
- return m_attributes->GetBlob(guidKey, pBuf, cbBufSize, pcbBlobSize);
- }
-
- STDMETHODIMP GetAllocatedBlob(REFGUID guidKey, UINT8 **ppBuf, UINT32 *pcbSize)
- {
- return m_attributes->GetAllocatedBlob(guidKey, ppBuf, pcbSize);
- }
-
- STDMETHODIMP GetUnknown(REFGUID guidKey, REFIID riid, LPVOID *ppv)
- {
- return m_attributes->GetUnknown(guidKey, riid, ppv);
- }
-
- STDMETHODIMP SetItem(REFGUID guidKey, REFPROPVARIANT Value)
- {
- return m_attributes->SetItem(guidKey, Value);
- }
-
- STDMETHODIMP DeleteItem(REFGUID guidKey)
- {
- return m_attributes->DeleteItem(guidKey);
- }
-
- STDMETHODIMP DeleteAllItems()
- {
- return m_attributes->DeleteAllItems();
- }
-
- STDMETHODIMP SetUINT32(REFGUID guidKey, UINT32 unValue)
- {
- return m_attributes->SetUINT32(guidKey, unValue);
- }
-
- STDMETHODIMP SetUINT64(REFGUID guidKey, UINT64 unValue)
- {
- return m_attributes->SetUINT64(guidKey, unValue);
- }
-
- STDMETHODIMP SetDouble(REFGUID guidKey, double fValue)
- {
- return m_attributes->SetDouble(guidKey, fValue);
- }
-
- STDMETHODIMP SetGUID(REFGUID guidKey, REFGUID guidValue)
- {
- return m_attributes->SetGUID(guidKey, guidValue);
- }
-
- STDMETHODIMP SetString(REFGUID guidKey, LPCWSTR wszValue)
- {
- return m_attributes->SetString(guidKey, wszValue);
- }
-
- STDMETHODIMP SetBlob(REFGUID guidKey, const UINT8 *pBuf, UINT32 cbBufSize)
- {
- return m_attributes->SetBlob(guidKey, pBuf, cbBufSize);
- }
-
- STDMETHODIMP SetUnknown(REFGUID guidKey, IUnknown *pUnknown)
- {
- return m_attributes->SetUnknown(guidKey, pUnknown);
- }
-
- STDMETHODIMP LockStore()
- {
- return m_attributes->LockStore();
- }
-
- STDMETHODIMP UnlockStore()
- {
- return m_attributes->UnlockStore();
- }
-
- STDMETHODIMP GetCount(UINT32 *pcItems)
- {
- return m_attributes->GetCount(pcItems);
- }
-
- STDMETHODIMP GetItemByIndex(UINT32 unIndex, GUID *pguidKey, PROPVARIANT *pValue)
- {
- return m_attributes->GetItemByIndex(unIndex, pguidKey, pValue);
- }
-
- STDMETHODIMP CopyAllItems(IMFAttributes *pDest)
- {
- return m_attributes->CopyAllItems(pDest);
- }
-
-private:
- IMFAttributes *m_attributes;
- ULONG m_cRef;
-};
-
-#endif // MFACTIVATE_H
diff --git a/src/plugins/wmf/player/mfaudioendpointcontrol.cpp b/src/plugins/wmf/player/mfaudioendpointcontrol.cpp
deleted file mode 100644
index 3b86c52b7..000000000
--- a/src/plugins/wmf/player/mfaudioendpointcontrol.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "QtCore/qdebug.h"
-#include "mfaudioendpointcontrol.h"
-
-#include <mmdeviceapi.h>
-
-MFAudioEndpointControl::MFAudioEndpointControl(QObject *parent)
- : QAudioOutputSelectorControl(parent)
- , m_currentActivate(0)
-{
-}
-
-MFAudioEndpointControl::~MFAudioEndpointControl()
-{
- clear();
-}
-
-void MFAudioEndpointControl::clear()
-{
- m_activeEndpoint.clear();
-
- for (auto it = m_devices.cbegin(), end = m_devices.cend(); it != end; ++it)
- CoTaskMemFree(it.value());
-
- m_devices.clear();
-
- if (m_currentActivate)
- m_currentActivate->Release();
- m_currentActivate = NULL;
-}
-
-QList<QString> MFAudioEndpointControl::availableOutputs() const
-{
- return m_devices.keys();
-}
-
-QString MFAudioEndpointControl::outputDescription(const QString &name) const
-{
- return name.section(QLatin1Char('\\'), -1);
-}
-
-QString MFAudioEndpointControl::defaultOutput() const
-{
- return m_defaultEndpoint;
-}
-
-QString MFAudioEndpointControl::activeOutput() const
-{
- return m_activeEndpoint;
-}
-
-void MFAudioEndpointControl::setActiveOutput(const QString &name)
-{
- if (m_activeEndpoint == name)
- return;
- QMap<QString, LPWSTR>::iterator it = m_devices.find(name);
- if (it == m_devices.end())
- return;
-
- LPWSTR wstrID = *it;
- IMFActivate *activate = NULL;
- HRESULT hr = MFCreateAudioRendererActivate(&activate);
- if (FAILED(hr)) {
- qWarning() << "Failed to create audio renderer activate";
- return;
- }
-
- if (wstrID) {
- hr = activate->SetString(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ID, wstrID);
- } else {
- //This is the default one that has been inserted in updateEndpoints(),
- //so give the activate a hint that we want to use the device for multimedia playback
- //then the media foundation will choose an appropriate one.
-
- //from MSDN:
- //The ERole enumeration defines constants that indicate the role that the system has assigned to an audio endpoint device.
- //eMultimedia: Music, movies, narration, and live music recording.
- hr = activate->SetUINT32(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ROLE, eMultimedia);
- }
-
- if (FAILED(hr)) {
- qWarning() << "Failed to set attribute for audio device" << name;
- return;
- }
-
- if (m_currentActivate)
- m_currentActivate->Release();
- m_currentActivate = activate;
- m_activeEndpoint = name;
-}
-
-IMFActivate* MFAudioEndpointControl::createActivate()
-{
- clear();
-
- updateEndpoints();
-
- // Check if an endpoint is available ("Default" is always inserted)
- if (m_devices.count() <= 1)
- return NULL;
-
- setActiveOutput(m_defaultEndpoint);
-
- return m_currentActivate;
-}
-
-void MFAudioEndpointControl::updateEndpoints()
-{
- m_defaultEndpoint = QString::fromLatin1("Default");
- m_devices.insert(m_defaultEndpoint, NULL);
-
- IMMDeviceEnumerator *pEnum = NULL;
- HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
- NULL, CLSCTX_ALL,
- __uuidof(IMMDeviceEnumerator),
- (void**)&pEnum);
- if (SUCCEEDED(hr)) {
- IMMDeviceCollection *pDevices = NULL;
- hr = pEnum->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &pDevices);
- if (SUCCEEDED(hr)) {
- UINT count;
- hr = pDevices->GetCount(&count);
- if (SUCCEEDED(hr)) {
- for (UINT i = 0; i < count; ++i) {
- IMMDevice *pDevice = NULL;
- hr = pDevices->Item(i, &pDevice);
- if (SUCCEEDED(hr)) {
- LPWSTR wstrID = NULL;
- hr = pDevice->GetId(&wstrID);
- if (SUCCEEDED(hr)) {
- QString deviceId = QString::fromWCharArray(wstrID);
- m_devices.insert(deviceId, wstrID);
- }
- pDevice->Release();
- }
- }
- }
- pDevices->Release();
- }
- pEnum->Release();
- }
-}
diff --git a/src/plugins/wmf/player/mfaudioendpointcontrol.h b/src/plugins/wmf/player/mfaudioendpointcontrol.h
deleted file mode 100644
index a439c31a5..000000000
--- a/src/plugins/wmf/player/mfaudioendpointcontrol.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFAUDIOENDPOINTCONTROL_H
-#define MFAUDIOENDPOINTCONTROL_H
-
-#include <mfapi.h>
-#include <mfidl.h>
-
-#include "qaudiooutputselectorcontrol.h"
-
-class MFPlayerService;
-
-QT_USE_NAMESPACE
-
-class MFAudioEndpointControl : public QAudioOutputSelectorControl
-{
- Q_OBJECT
-public:
- MFAudioEndpointControl(QObject *parent = 0);
- ~MFAudioEndpointControl();
-
- QList<QString> availableOutputs() const;
-
- QString outputDescription(const QString &name) const;
-
- QString defaultOutput() const;
- QString activeOutput() const;
-
- void setActiveOutput(const QString& name);
-
- IMFActivate* createActivate();
-
-private:
- void clear();
- void updateEndpoints();
-
- QString m_defaultEndpoint;
- QString m_activeEndpoint;
- QMap<QString, LPWSTR> m_devices;
- IMFActivate *m_currentActivate;
-
-};
-
-#endif
-
diff --git a/src/plugins/wmf/player/mfaudioprobecontrol.cpp b/src/plugins/wmf/player/mfaudioprobecontrol.cpp
deleted file mode 100644
index c703922c8..000000000
--- a/src/plugins/wmf/player/mfaudioprobecontrol.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mfaudioprobecontrol.h"
-
-MFAudioProbeControl::MFAudioProbeControl(QObject *parent):
- QMediaAudioProbeControl(parent)
-{
-}
-
-MFAudioProbeControl::~MFAudioProbeControl()
-{
-}
-
-void MFAudioProbeControl::bufferProbed(const char *data, quint32 size, const QAudioFormat& format, qint64 startTime)
-{
- if (!format.isValid())
- return;
-
- QAudioBuffer audioBuffer = QAudioBuffer(QByteArray(data, size), format, startTime);
-
- {
- QMutexLocker locker(&m_bufferMutex);
- m_pendingBuffer = audioBuffer;
- QMetaObject::invokeMethod(this, "bufferProbed", Qt::QueuedConnection);
- }
-}
-
-void MFAudioProbeControl::bufferProbed()
-{
- QAudioBuffer audioBuffer;
- {
- QMutexLocker locker(&m_bufferMutex);
- if (!m_pendingBuffer.isValid())
- return;
- audioBuffer = m_pendingBuffer;
- }
- emit audioBufferProbed(audioBuffer);
-}
diff --git a/src/plugins/wmf/player/mfaudioprobecontrol.h b/src/plugins/wmf/player/mfaudioprobecontrol.h
deleted file mode 100644
index c8a06148f..000000000
--- a/src/plugins/wmf/player/mfaudioprobecontrol.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFAUDIOPROBECONTROL_H
-#define MFAUDIOPROBECONTROL_H
-
-#include <qmediaaudioprobecontrol.h>
-#include <QtCore/qmutex.h>
-#include <qaudiobuffer.h>
-
-QT_USE_NAMESPACE
-
-class MFAudioProbeControl : public QMediaAudioProbeControl
-{
- Q_OBJECT
-public:
- explicit MFAudioProbeControl(QObject *parent);
- virtual ~MFAudioProbeControl();
-
- void bufferProbed(const char *data, quint32 size, const QAudioFormat& format, qint64 startTime);
-
-private slots:
- void bufferProbed();
-
-private:
- QAudioBuffer m_pendingBuffer;
- QMutex m_bufferMutex;
-};
-
-#endif
diff --git a/src/plugins/wmf/player/mfevrvideowindowcontrol.cpp b/src/plugins/wmf/player/mfevrvideowindowcontrol.cpp
deleted file mode 100644
index 4b3e0f303..000000000
--- a/src/plugins/wmf/player/mfevrvideowindowcontrol.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mfevrvideowindowcontrol.h"
-
-#include <qdebug.h>
-
-MFEvrVideoWindowControl::MFEvrVideoWindowControl(QObject *parent)
- : EvrVideoWindowControl(parent)
- , m_currentActivate(NULL)
- , m_evrSink(NULL)
-{
-}
-
-MFEvrVideoWindowControl::~MFEvrVideoWindowControl()
-{
- clear();
-}
-
-void MFEvrVideoWindowControl::clear()
-{
- setEvr(NULL);
-
- if (m_evrSink)
- m_evrSink->Release();
- if (m_currentActivate) {
- m_currentActivate->ShutdownObject();
- m_currentActivate->Release();
- }
- m_evrSink = NULL;
- m_currentActivate = NULL;
-}
-
-IMFActivate* MFEvrVideoWindowControl::createActivate()
-{
- clear();
-
- if (FAILED(MFCreateVideoRendererActivate(0, &m_currentActivate))) {
- qWarning() << "Failed to create evr video renderer activate!";
- return NULL;
- }
- if (FAILED(m_currentActivate->ActivateObject(IID_IMFMediaSink, (LPVOID*)(&m_evrSink)))) {
- qWarning() << "Failed to activate evr media sink!";
- return NULL;
- }
- if (!setEvr(m_evrSink))
- return NULL;
-
- return m_currentActivate;
-}
-
-void MFEvrVideoWindowControl::releaseActivate()
-{
- clear();
-}
diff --git a/src/plugins/wmf/player/mfevrvideowindowcontrol.h b/src/plugins/wmf/player/mfevrvideowindowcontrol.h
deleted file mode 100644
index 96634e6d8..000000000
--- a/src/plugins/wmf/player/mfevrvideowindowcontrol.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFEVRVIDEOWINDOWCONTROL_H
-#define MFEVRVIDEOWINDOWCONTROL_H
-
-#include "evrvideowindowcontrol.h"
-
-QT_USE_NAMESPACE
-
-class MFEvrVideoWindowControl : public EvrVideoWindowControl
-{
-public:
- MFEvrVideoWindowControl(QObject *parent = 0);
- ~MFEvrVideoWindowControl();
-
- IMFActivate* createActivate();
- void releaseActivate();
-
-private:
- void clear();
-
- IMFActivate *m_currentActivate;
- IMFMediaSink *m_evrSink;
-};
-
-#endif // MFEVRVIDEOWINDOWCONTROL_H
diff --git a/src/plugins/wmf/player/mfmetadatacontrol.cpp b/src/plugins/wmf/player/mfmetadatacontrol.cpp
deleted file mode 100644
index 74063f7d1..000000000
--- a/src/plugins/wmf/player/mfmetadatacontrol.cpp
+++ /dev/null
@@ -1,431 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qmediametadata.h>
-#include <qdatetime.h>
-#include <qimage.h>
-
-#include "mfmetadatacontrol.h"
-#include "mfplayerservice.h"
-#include "Propkey.h"
-
-//#define DEBUG_MEDIAFOUNDATION
-
-static QString nameForGUID(GUID guid)
-{
- // Audio formats
- if (guid == MFAudioFormat_AAC)
- return QStringLiteral("MPEG AAC Audio");
- else if (guid == MFAudioFormat_ADTS)
- return QStringLiteral("MPEG ADTS AAC Audio");
- else if (guid == MFAudioFormat_Dolby_AC3_SPDIF)
- return QStringLiteral("Dolby AC-3 SPDIF");
- else if (guid == MFAudioFormat_DRM)
- return QStringLiteral("DRM");
- else if (guid == MFAudioFormat_DTS)
- return QStringLiteral("Digital Theater Systems Audio (DTS)");
- else if (guid == MFAudioFormat_Float)
- return QStringLiteral("IEEE Float Audio");
- else if (guid == MFAudioFormat_MP3)
- return QStringLiteral("MPEG Audio Layer-3 (MP3)");
- else if (guid == MFAudioFormat_MPEG)
- return QStringLiteral("MPEG-1 Audio");
- else if (guid == MFAudioFormat_MSP1)
- return QStringLiteral("Windows Media Audio Voice");
- else if (guid == MFAudioFormat_PCM)
- return QStringLiteral("Uncompressed PCM Audio");
- else if (guid == MFAudioFormat_WMASPDIF)
- return QStringLiteral("Windows Media Audio 9 SPDIF");
- else if (guid == MFAudioFormat_WMAudioV8)
- return QStringLiteral("Windows Media Audio 8 (WMA2)");
- else if (guid == MFAudioFormat_WMAudioV9)
- return QStringLiteral("Windows Media Audio 9 (WMA3");
- else if (guid == MFAudioFormat_WMAudio_Lossless)
- return QStringLiteral("Windows Media Audio 9 Lossless");
-
- // Video formats
- if (guid == MFVideoFormat_DV25)
- return QStringLiteral("DVCPRO 25 (DV25)");
- else if (guid == MFVideoFormat_DV50)
- return QStringLiteral("DVCPRO 50 (DV50)");
- else if (guid == MFVideoFormat_DVC)
- return QStringLiteral("DVC/DV Video");
- else if (guid == MFVideoFormat_DVH1)
- return QStringLiteral("DVCPRO 100 (DVH1)");
- else if (guid == MFVideoFormat_DVHD)
- return QStringLiteral("HD-DVCR (DVHD)");
- else if (guid == MFVideoFormat_DVSD)
- return QStringLiteral("SDL-DVCR (DVSD)");
- else if (guid == MFVideoFormat_DVSL)
- return QStringLiteral("SD-DVCR (DVSL)");
- else if (guid == MFVideoFormat_H264)
- return QStringLiteral("H.264 Video");
- else if (guid == MFVideoFormat_M4S2)
- return QStringLiteral("MPEG-4 part 2 Video (M4S2)");
- else if (guid == MFVideoFormat_MJPG)
- return QStringLiteral("Motion JPEG (MJPG)");
- else if (guid == MFVideoFormat_MP43)
- return QStringLiteral("Microsoft MPEG 4 version 3 (MP43)");
- else if (guid == MFVideoFormat_MP4S)
- return QStringLiteral("ISO MPEG 4 version 1 (MP4S)");
- else if (guid == MFVideoFormat_MP4V)
- return QStringLiteral("MPEG-4 part 2 Video (MP4V)");
- else if (guid == MFVideoFormat_MPEG2)
- return QStringLiteral("MPEG-2 Video");
- else if (guid == MFVideoFormat_MPG1)
- return QStringLiteral("MPEG-1 Video");
- else if (guid == MFVideoFormat_MSS1)
- return QStringLiteral("Windows Media Screen 1 (MSS1)");
- else if (guid == MFVideoFormat_MSS2)
- return QStringLiteral("Windows Media Video 9 Screen (MSS2)");
- else if (guid == MFVideoFormat_WMV1)
- return QStringLiteral("Windows Media Video 7 (WMV1)");
- else if (guid == MFVideoFormat_WMV2)
- return QStringLiteral("Windows Media Video 8 (WMV2)");
- else if (guid == MFVideoFormat_WMV3)
- return QStringLiteral("Windows Media Video 9 (WMV3)");
- else if (guid == MFVideoFormat_WVC1)
- return QStringLiteral("Windows Media Video VC1 (WVC1)");
-
- else
- return QStringLiteral("Unknown codec");
-}
-
-MFMetaDataControl::MFMetaDataControl(QObject *parent)
- : QMetaDataReaderControl(parent)
- , m_metaData(0)
- , m_content(0)
-{
-}
-
-MFMetaDataControl::~MFMetaDataControl()
-{
- if (m_metaData)
- m_metaData->Release();
- if (m_content)
- m_content->Release();
-}
-
-bool MFMetaDataControl::isMetaDataAvailable() const
-{
- return m_content || m_metaData;
-}
-
-QVariant MFMetaDataControl::metaData(const QString &key) const
-{
- QVariant value;
- if (!isMetaDataAvailable())
- return value;
-
- int index = m_availableMetaDatas.indexOf(key);
- if (index < 0)
- return value;
-
- PROPVARIANT var;
- PropVariantInit(&var);
- HRESULT hr = S_FALSE;
- if (m_content)
- hr = m_content->GetValue(m_commonKeys[index], &var);
- else if (m_metaData)
- hr = m_metaData->GetProperty(reinterpret_cast<LPCWSTR>(m_commonNames[index].utf16()), &var);
-
- if (SUCCEEDED(hr)) {
- value = convertValue(var);
-
- // some metadata needs to be reformatted
- if (value.isValid() && m_content) {
- if (key == QMediaMetaData::MediaType) {
- QString v = value.toString();
- if (v == QLatin1String("{D1607DBC-E323-4BE2-86A1-48A42A28441E}"))
- value = QStringLiteral("Music");
- else if (v == QLatin1String("{DB9830BD-3AB3-4FAB-8A37-1A995F7FF74B}"))
- value = QStringLiteral("Video");
- else if (v == QLatin1String("{01CD0F29-DA4E-4157-897B-6275D50C4F11}"))
- value = QStringLiteral("Audio");
- else if (v == QLatin1String("{FCF24A76-9A57-4036-990D-E35DD8B244E1}"))
- value = QStringLiteral("Other");
- } else if (key == QMediaMetaData::Duration) {
- // duration is provided in 100-nanosecond units, convert to milliseconds
- value = (value.toLongLong() + 10000) / 10000;
- } else if (key == QMediaMetaData::AudioCodec || key == QMediaMetaData::VideoCodec) {
- GUID guid;
- if (SUCCEEDED(CLSIDFromString((const WCHAR*)value.toString().utf16(), &guid)))
- value = nameForGUID(guid);
- } else if (key == QMediaMetaData::Resolution) {
- QSize res;
- res.setHeight(value.toUInt());
- if (m_content && SUCCEEDED(m_content->GetValue(PKEY_Video_FrameWidth, &var)))
- res.setWidth(convertValue(var).toUInt());
- value = res;
- } else if (key == QMediaMetaData::Orientation) {
- uint orientation = 0;
- if (m_content && SUCCEEDED(m_content->GetValue(PKEY_Video_Orientation, &var)))
- orientation = convertValue(var).toUInt();
- value = orientation;
- } else if (key == QMediaMetaData::PixelAspectRatio) {
- QSize aspectRatio;
- aspectRatio.setWidth(value.toUInt());
- if (m_content && SUCCEEDED(m_content->GetValue(PKEY_Video_VerticalAspectRatio, &var)))
- aspectRatio.setHeight(convertValue(var).toUInt());
- value = aspectRatio;
- } else if (key == QMediaMetaData::VideoFrameRate) {
- value = value.toReal() / 1000.f;
- }
- }
- }
-
- PropVariantClear(&var);
- return value;
-}
-
-QVariant MFMetaDataControl::convertValue(const PROPVARIANT& var) const
-{
- QVariant value;
- switch (var.vt) {
- case VT_LPWSTR:
- value = QString::fromUtf16(reinterpret_cast<const ushort*>(var.pwszVal));
- break;
- case VT_UI4:
- value = uint(var.ulVal);
- break;
- case VT_UI8:
- value = qulonglong(var.uhVal.QuadPart);
- break;
- case VT_BOOL:
- value = bool(var.boolVal);
- break;
- case VT_FILETIME:
- SYSTEMTIME sysDate;
- if (!FileTimeToSystemTime(&var.filetime, &sysDate))
- break;
- value = QDate(sysDate.wYear, sysDate.wMonth, sysDate.wDay);
- break;
- case VT_STREAM:
- {
- STATSTG stat;
- if (FAILED(var.pStream->Stat(&stat, STATFLAG_NONAME)))
- break;
- void *data = malloc(stat.cbSize.QuadPart);
- ULONG read = 0;
- if (FAILED(var.pStream->Read(data, stat.cbSize.QuadPart, &read))) {
- free(data);
- break;
- }
- value = QImage::fromData((const uchar*)data, read);
- free(data);
- }
- break;
- case VT_VECTOR | VT_LPWSTR:
- QStringList vList;
- for (ULONG i = 0; i < var.calpwstr.cElems; ++i)
- vList.append(QString::fromUtf16(reinterpret_cast<const ushort*>(var.calpwstr.pElems[i])));
- value = vList;
- break;
- }
- return value;
-}
-
-QStringList MFMetaDataControl::availableMetaData() const
-{
- return m_availableMetaDatas;
-}
-
-void MFMetaDataControl::updateSource(IMFPresentationDescriptor* sourcePD, IMFMediaSource* mediaSource)
-{
- if (m_metaData) {
- m_metaData->Release();
- m_metaData = 0;
- }
-
- if (m_content) {
- m_content->Release();
- m_content = 0;
- }
-
- m_availableMetaDatas.clear();
- m_commonKeys.clear();
- m_commonNames.clear();
-
- if (SUCCEEDED(MFGetService(mediaSource, MF_PROPERTY_HANDLER_SERVICE, IID_PPV_ARGS(&m_content)))) {
- DWORD cProps;
- if (SUCCEEDED(m_content->GetCount(&cProps))) {
- for (DWORD i = 0; i < cProps; i++)
- {
- PROPERTYKEY key;
- if (FAILED(m_content->GetAt(i, &key)))
- continue;
- bool common = true;
- if (key == PKEY_Author) {
- m_availableMetaDatas.push_back(QMediaMetaData::Author);
- } else if (key == PKEY_Title) {
- m_availableMetaDatas.push_back(QMediaMetaData::Title);
- } else if (key == PKEY_Media_SubTitle) {
- m_availableMetaDatas.push_back(QMediaMetaData::SubTitle);
- } else if (key == PKEY_ParentalRating) {
- m_availableMetaDatas.push_back(QMediaMetaData::ParentalRating);
- } else if (key == PKEY_Media_EncodingSettings) {
- m_availableMetaDatas.push_back(QMediaMetaData::Description);
- } else if (key == PKEY_Copyright) {
- m_availableMetaDatas.push_back(QMediaMetaData::Copyright);
- } else if (key == PKEY_Comment) {
- m_availableMetaDatas.push_back(QMediaMetaData::Comment);
- } else if (key == PKEY_Media_ProviderStyle) {
- m_availableMetaDatas.push_back(QMediaMetaData::Genre);
- } else if (key == PKEY_Media_Year) {
- m_availableMetaDatas.push_back(QMediaMetaData::Year);
- } else if (key == PKEY_Media_DateEncoded) {
- m_availableMetaDatas.push_back(QMediaMetaData::Date);
- } else if (key == PKEY_Rating) {
- m_availableMetaDatas.push_back(QMediaMetaData::UserRating);
- } else if (key == PKEY_Keywords) {
- m_availableMetaDatas.push_back(QMediaMetaData::Keywords);
- } else if (key == PKEY_Language) {
- m_availableMetaDatas.push_back(QMediaMetaData::Language);
- } else if (key == PKEY_Media_Publisher) {
- m_availableMetaDatas.push_back(QMediaMetaData::Publisher);
- } else if (key == PKEY_Media_ClassPrimaryID) {
- m_availableMetaDatas.push_back(QMediaMetaData::MediaType);
- } else if (key == PKEY_Media_Duration) {
- m_availableMetaDatas.push_back(QMediaMetaData::Duration);
- } else if (key == PKEY_Audio_EncodingBitrate) {
- m_availableMetaDatas.push_back(QMediaMetaData::AudioBitRate);
- } else if (key == PKEY_Audio_Format) {
- m_availableMetaDatas.push_back(QMediaMetaData::AudioCodec);
- } else if (key == PKEY_Media_AverageLevel) {
- m_availableMetaDatas.push_back(QMediaMetaData::AverageLevel);
- } else if (key == PKEY_Audio_ChannelCount) {
- m_availableMetaDatas.push_back(QMediaMetaData::ChannelCount);
- } else if (key == PKEY_Audio_PeakValue) {
- m_availableMetaDatas.push_back(QMediaMetaData::PeakValue);
- } else if (key == PKEY_Audio_SampleRate) {
- m_availableMetaDatas.push_back(QMediaMetaData::SampleRate);
- } else if (key == PKEY_Music_AlbumTitle) {
- m_availableMetaDatas.push_back(QMediaMetaData::AlbumTitle);
- } else if (key == PKEY_Music_AlbumArtist) {
- m_availableMetaDatas.push_back(QMediaMetaData::AlbumArtist);
- } else if (key == PKEY_Music_Artist) {
- m_availableMetaDatas.push_back(QMediaMetaData::ContributingArtist);
- } else if (key == PKEY_Music_Composer) {
- m_availableMetaDatas.push_back(QMediaMetaData::Composer);
- } else if (key == PKEY_Music_Conductor) {
- m_availableMetaDatas.push_back(QMediaMetaData::Conductor);
- } else if (key == PKEY_Music_Lyrics) {
- m_availableMetaDatas.push_back(QMediaMetaData::Lyrics);
- } else if (key == PKEY_Music_Mood) {
- m_availableMetaDatas.push_back(QMediaMetaData::Mood);
- } else if (key == PKEY_Music_TrackNumber) {
- m_availableMetaDatas.push_back(QMediaMetaData::TrackNumber);
- } else if (key == PKEY_Music_Genre) {
- m_availableMetaDatas.push_back(QMediaMetaData::Genre);
- } else if (key == PKEY_ThumbnailStream) {
- m_availableMetaDatas.push_back(QMediaMetaData::ThumbnailImage);
- } else if (key == PKEY_Video_FrameHeight) {
- m_availableMetaDatas.push_back(QMediaMetaData::Resolution);
- } else if (key == PKEY_Video_Orientation) {
- m_availableMetaDatas.push_back(QMediaMetaData::Orientation);
- } else if (key == PKEY_Video_HorizontalAspectRatio) {
- m_availableMetaDatas.push_back(QMediaMetaData::PixelAspectRatio);
- } else if (key == PKEY_Video_FrameRate) {
- m_availableMetaDatas.push_back(QMediaMetaData::VideoFrameRate);
- } else if (key == PKEY_Video_EncodingBitrate) {
- m_availableMetaDatas.push_back(QMediaMetaData::VideoBitRate);
- } else if (key == PKEY_Video_Compression) {
- m_availableMetaDatas.push_back(QMediaMetaData::VideoCodec);
- } else if (key == PKEY_Video_Director) {
- m_availableMetaDatas.push_back(QMediaMetaData::Director);
- } else if (key == PKEY_Media_Writer) {
- m_availableMetaDatas.push_back(QMediaMetaData::Writer);
- } else {
- common = false;
- //TODO: add more extended keys
- }
- if (common)
- m_commonKeys.push_back(key);
- }
- } else {
- m_content->Release();
- m_content = NULL;
- }
- }
-
- if (!m_content) {
- //fallback to Vista approach
- IMFMetadataProvider *provider = NULL;
- if (SUCCEEDED(MFGetService(mediaSource, MF_METADATA_PROVIDER_SERVICE, IID_PPV_ARGS(&provider)))) {
- if (SUCCEEDED(provider->GetMFMetadata(sourcePD, 0, 0, &m_metaData))) {
- PROPVARIANT varNames;
- PropVariantInit(&varNames);
- if (SUCCEEDED(m_metaData->GetAllPropertyNames(&varNames)) && varNames.vt == (VT_VECTOR | VT_LPWSTR)) {
- ULONG cElements = varNames.calpwstr.cElems;
- for (ULONG i = 0; i < cElements; i++)
- {
- const WCHAR* sName = varNames.calpwstr.pElems[i];
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "metadata: " << QString::fromUtf16(sName);
-#endif
- if (wcscmp(sName, L"Author") == 0) {
- m_availableMetaDatas.push_back(QMediaMetaData::Author);
- } else if (wcscmp(sName, L"Title") == 0) {
- m_availableMetaDatas.push_back(QMediaMetaData::Title);
- } else if (wcscmp(sName, L"Rating") == 0) {
- m_availableMetaDatas.push_back(QMediaMetaData::ParentalRating);
- } else if (wcscmp(sName, L"Description") == 0) {
- m_availableMetaDatas.push_back(QMediaMetaData::Description);
- } else if (wcscmp(sName, L"Copyright") == 0) {
- m_availableMetaDatas.push_back(QMediaMetaData::Copyright);
- //TODO: add more common keys
- } else {
- m_availableMetaDatas.push_back(QString::fromUtf16(reinterpret_cast<const ushort*>(sName)));
- }
- m_commonNames.push_back(QString::fromUtf16(reinterpret_cast<const ushort*>(sName)));
- }
- }
- PropVariantClear(&varNames);
- } else {
- qWarning("Failed to get IMFMetadata");
- }
- provider->Release();
- } else {
- qWarning("Failed to get IMFMetadataProvider from source");
- }
- }
-
- emit metaDataChanged();
- emit metaDataAvailableChanged(m_metaData || m_content);
-}
diff --git a/src/plugins/wmf/player/mfmetadatacontrol.h b/src/plugins/wmf/player/mfmetadatacontrol.h
deleted file mode 100644
index 7ae06cedb..000000000
--- a/src/plugins/wmf/player/mfmetadatacontrol.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFMETADATACONTROL_H
-#define MFMETADATACONTROL_H
-
-#include <qmetadatareadercontrol.h>
-#include "Mfidl.h"
-
-QT_USE_NAMESPACE
-
-class MFMetaDataControl : public QMetaDataReaderControl
-{
- Q_OBJECT
-public:
- MFMetaDataControl(QObject *parent = 0);
- ~MFMetaDataControl();
-
- bool isMetaDataAvailable() const;
-
- QVariant metaData(const QString &key) const;
- QStringList availableMetaData() const;
-
- void updateSource(IMFPresentationDescriptor* sourcePD, IMFMediaSource* mediaSource);
-
-private:
- QVariant convertValue(const PROPVARIANT& var) const;
- IPropertyStore *m_content; //for Windows7
- IMFMetadata *m_metaData; //for Vista
-
- QStringList m_availableMetaDatas;
- QList<PROPERTYKEY> m_commonKeys; //for Windows7
- QStringList m_commonNames; //for Vista
-};
-
-#endif
diff --git a/src/plugins/wmf/player/mfplayercontrol.cpp b/src/plugins/wmf/player/mfplayercontrol.cpp
deleted file mode 100644
index b070ce482..000000000
--- a/src/plugins/wmf/player/mfplayercontrol.cpp
+++ /dev/null
@@ -1,316 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mfplayercontrol.h"
-#include <qtcore/qdebug.h>
-
-//#define DEBUG_MEDIAFOUNDATION
-
-MFPlayerControl::MFPlayerControl(MFPlayerSession *session)
-: QMediaPlayerControl(session)
-, m_state(QMediaPlayer::StoppedState)
-, m_stateDirty(false)
-, m_videoAvailable(false)
-, m_audioAvailable(false)
-, m_duration(-1)
-, m_seekable(false)
-, m_session(session)
-{
- QObject::connect(m_session, SIGNAL(statusChanged()), this, SLOT(handleStatusChanged()));
- QObject::connect(m_session, SIGNAL(videoAvailable()), this, SLOT(handleVideoAvailable()));
- QObject::connect(m_session, SIGNAL(audioAvailable()), this, SLOT(handleAudioAvailable()));
- QObject::connect(m_session, SIGNAL(durationUpdate(qint64)), this, SLOT(handleDurationUpdate(qint64)));
- QObject::connect(m_session, SIGNAL(seekableUpdate(bool)), this, SLOT(handleSeekableUpdate(bool)));
- QObject::connect(m_session, SIGNAL(error(QMediaPlayer::Error,QString,bool)), this, SLOT(handleError(QMediaPlayer::Error,QString,bool)));
- QObject::connect(m_session, SIGNAL(positionChanged(qint64)), this, SIGNAL(positionChanged(qint64)));
- QObject::connect(m_session, SIGNAL(volumeChanged(int)), this, SIGNAL(volumeChanged(int)));
- QObject::connect(m_session, SIGNAL(mutedChanged(bool)), this, SIGNAL(mutedChanged(bool)));
- QObject::connect(m_session, SIGNAL(playbackRateChanged(qreal)), this, SIGNAL(playbackRateChanged(qreal)));
- QObject::connect(m_session, SIGNAL(bufferStatusChanged(int)), this, SIGNAL(bufferStatusChanged(int)));
-}
-
-MFPlayerControl::~MFPlayerControl()
-{
-}
-
-void MFPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream)
-{
- if (m_state != QMediaPlayer::StoppedState) {
- changeState(QMediaPlayer::StoppedState);
- m_session->stop(true);
- refreshState();
- }
-
- m_media = media;
- m_stream = stream;
- resetAudioVideoAvailable();
- handleDurationUpdate(-1);
- handleSeekableUpdate(false);
- m_session->load(media, stream);
- emit mediaChanged(m_media);
-}
-
-void MFPlayerControl::play()
-{
- if (m_state == QMediaPlayer::PlayingState)
- return;
- if (QMediaPlayer::InvalidMedia == m_session->status())
- m_session->load(m_media, m_stream);
-
- switch (m_session->status()) {
- case QMediaPlayer::UnknownMediaStatus:
- case QMediaPlayer::NoMedia:
- case QMediaPlayer::InvalidMedia:
- return;
- case QMediaPlayer::LoadedMedia:
- case QMediaPlayer::BufferingMedia:
- case QMediaPlayer::BufferedMedia:
- case QMediaPlayer::EndOfMedia:
- changeState(QMediaPlayer::PlayingState);
- m_session->start();
- break;
- default: //Loading/Stalled
- changeState(QMediaPlayer::PlayingState);
- break;
- }
- refreshState();
-}
-
-void MFPlayerControl::pause()
-{
- if (m_state != QMediaPlayer::PlayingState)
- return;
- changeState(QMediaPlayer::PausedState);
- m_session->pause();
- refreshState();
-}
-
-void MFPlayerControl::stop()
-{
- if (m_state == QMediaPlayer::StoppedState)
- return;
- changeState(QMediaPlayer::StoppedState);
- m_session->stop();
- refreshState();
-}
-
-void MFPlayerControl::changeState(QMediaPlayer::State state)
-{
- if (m_state == state)
- return;
- m_state = state;
- m_stateDirty = true;
-}
-
-void MFPlayerControl::refreshState()
-{
- if (!m_stateDirty)
- return;
- m_stateDirty = false;
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MFPlayerControl::emit stateChanged" << m_state;
-#endif
- emit stateChanged(m_state);
-}
-
-void MFPlayerControl::handleStatusChanged()
-{
- QMediaPlayer::MediaStatus status = m_session->status();
- switch (status) {
- case QMediaPlayer::EndOfMedia:
- changeState(QMediaPlayer::StoppedState);
- break;
- case QMediaPlayer::InvalidMedia:
- break;
- case QMediaPlayer::LoadedMedia:
- case QMediaPlayer::BufferingMedia:
- case QMediaPlayer::BufferedMedia:
- if (m_state == QMediaPlayer::PlayingState)
- m_session->start();
- break;
- }
- emit mediaStatusChanged(m_session->status());
- refreshState();
-}
-
-void MFPlayerControl::handleVideoAvailable()
-{
- if (m_videoAvailable)
- return;
- m_videoAvailable = true;
- emit videoAvailableChanged(m_videoAvailable);
-}
-
-void MFPlayerControl::handleAudioAvailable()
-{
- if (m_audioAvailable)
- return;
- m_audioAvailable = true;
- emit audioAvailableChanged(m_audioAvailable);
-}
-
-void MFPlayerControl::resetAudioVideoAvailable()
-{
- bool videoDirty = false;
- if (m_videoAvailable) {
- m_videoAvailable = false;
- videoDirty = true;
- }
- if (m_audioAvailable) {
- m_audioAvailable = false;
- emit audioAvailableChanged(m_audioAvailable);
- }
- if (videoDirty)
- emit videoAvailableChanged(m_videoAvailable);
-}
-
-void MFPlayerControl::handleDurationUpdate(qint64 duration)
-{
- if (m_duration == duration)
- return;
- m_duration = duration;
- emit durationChanged(m_duration);
-}
-
-void MFPlayerControl::handleSeekableUpdate(bool seekable)
-{
- if (m_seekable == seekable)
- return;
- m_seekable = seekable;
- emit seekableChanged(m_seekable);
-}
-
-QMediaPlayer::State MFPlayerControl::state() const
-{
- return m_state;
-}
-
-QMediaPlayer::MediaStatus MFPlayerControl::mediaStatus() const
-{
- return m_session->status();
-}
-
-qint64 MFPlayerControl::duration() const
-{
- return m_duration;
-}
-
-qint64 MFPlayerControl::position() const
-{
- return m_session->position();
-}
-
-void MFPlayerControl::setPosition(qint64 position)
-{
- if (!m_seekable || position == m_session->position())
- return;
- m_session->setPosition(position);
-}
-
-int MFPlayerControl::volume() const
-{
- return m_session->volume();
-}
-
-void MFPlayerControl::setVolume(int volume)
-{
- m_session->setVolume(volume);
-}
-
-bool MFPlayerControl::isMuted() const
-{
- return m_session->isMuted();
-}
-
-void MFPlayerControl::setMuted(bool muted)
-{
- m_session->setMuted(muted);
-}
-
-int MFPlayerControl::bufferStatus() const
-{
- return m_session->bufferStatus();
-}
-
-bool MFPlayerControl::isAudioAvailable() const
-{
- return m_audioAvailable;
-}
-
-bool MFPlayerControl::isVideoAvailable() const
-{
- return m_videoAvailable;
-}
-
-bool MFPlayerControl::isSeekable() const
-{
- return m_seekable;
-}
-
-QMediaTimeRange MFPlayerControl::availablePlaybackRanges() const
-{
- return m_session->availablePlaybackRanges();
-}
-
-qreal MFPlayerControl::playbackRate() const
-{
- return m_session->playbackRate();
-}
-
-void MFPlayerControl::setPlaybackRate(qreal rate)
-{
- m_session->setPlaybackRate(rate);
-}
-
-QMediaContent MFPlayerControl::media() const
-{
- return m_media;
-}
-
-const QIODevice* MFPlayerControl::mediaStream() const
-{
- return m_stream;
-}
-
-void MFPlayerControl::handleError(QMediaPlayer::Error errorCode, const QString& errorString, bool isFatal)
-{
- if (isFatal)
- stop();
- emit error(int(errorCode), errorString);
-}
diff --git a/src/plugins/wmf/player/mfplayercontrol.h b/src/plugins/wmf/player/mfplayercontrol.h
deleted file mode 100644
index a75fac493..000000000
--- a/src/plugins/wmf/player/mfplayercontrol.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFPLAYERCONTROL_H
-#define MFPLAYERCONTROL_H
-
-#include "qmediacontent.h"
-#include "qmediaplayercontrol.h"
-
-#include <QtCore/qcoreevent.h>
-
-#include "mfplayersession.h"
-
-QT_USE_NAMESPACE
-
-class MFPlayerControl : public QMediaPlayerControl
-{
- Q_OBJECT
-public:
- MFPlayerControl(MFPlayerSession *session);
- ~MFPlayerControl();
-
- QMediaPlayer::State state() const;
-
- QMediaPlayer::MediaStatus mediaStatus() const;
-
- qint64 duration() const;
-
- qint64 position() const;
- void setPosition(qint64 position);
-
- int volume() const;
- void setVolume(int volume);
-
- bool isMuted() const;
- void setMuted(bool muted);
-
- int bufferStatus() const;
-
- bool isAudioAvailable() const;
- bool isVideoAvailable() const;
-
- bool isSeekable() const;
-
- QMediaTimeRange availablePlaybackRanges() const;
-
- qreal playbackRate() const;
- void setPlaybackRate(qreal rate);
-
- QMediaContent media() const;
- const QIODevice *mediaStream() const;
- void setMedia(const QMediaContent &media, QIODevice *stream);
-
- void play();
- void pause();
- void stop();
-
-private Q_SLOTS:
- void handleStatusChanged();
- void handleVideoAvailable();
- void handleAudioAvailable();
- void handleDurationUpdate(qint64 duration);
- void handleSeekableUpdate(bool seekable);
- void handleError(QMediaPlayer::Error errorCode, const QString& errorString, bool isFatal);
-
-private:
- void changeState(QMediaPlayer::State state);
- void resetAudioVideoAvailable();
- void refreshState();
-
- QMediaPlayer::State m_state;
- bool m_stateDirty;
- QMediaPlayer::MediaStatus m_status;
- QMediaPlayer::Error m_error;
-
- bool m_videoAvailable;
- bool m_audioAvailable;
- qint64 m_duration;
- bool m_seekable;
-
- QIODevice *m_stream;
- QMediaContent m_media;
- MFPlayerSession *m_session;
-};
-
-#endif
diff --git a/src/plugins/wmf/player/mfplayerservice.cpp b/src/plugins/wmf/player/mfplayerservice.cpp
deleted file mode 100644
index b73390ac7..000000000
--- a/src/plugins/wmf/player/mfplayerservice.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediacontent.h"
-
-#include <QtCore/qdebug.h>
-
-#include "mfplayercontrol.h"
-#include "mfevrvideowindowcontrol.h"
-#include "mfvideorenderercontrol.h"
-#include "mfaudioendpointcontrol.h"
-#include "mfaudioprobecontrol.h"
-#include "mfvideoprobecontrol.h"
-#include "mfplayerservice.h"
-#include "mfplayersession.h"
-#include "mfmetadatacontrol.h"
-
-MFPlayerService::MFPlayerService(QObject *parent)
- : QMediaService(parent)
- , m_session(0)
- , m_videoWindowControl(0)
- , m_videoRendererControl(0)
-{
- m_audioEndpointControl = new MFAudioEndpointControl(this);
- m_session = new MFPlayerSession(this);
- m_player = new MFPlayerControl(m_session);
- m_metaDataControl = new MFMetaDataControl(this);
-}
-
-MFPlayerService::~MFPlayerService()
-{
- m_session->close();
-
- if (m_videoWindowControl)
- delete m_videoWindowControl;
-
- if (m_videoRendererControl)
- delete m_videoRendererControl;
-
- m_session->Release();
-}
-
-QMediaControl* MFPlayerService::requestControl(const char *name)
-{
- if (qstrcmp(name, QMediaPlayerControl_iid) == 0) {
- return m_player;
- } else if (qstrcmp(name, QAudioOutputSelectorControl_iid) == 0) {
- return m_audioEndpointControl;
- } else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) {
- return m_metaDataControl;
- } else if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
- if (!m_videoRendererControl && !m_videoWindowControl) {
- m_videoRendererControl = new MFVideoRendererControl;
- return m_videoRendererControl;
- }
- } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
- if (!m_videoRendererControl && !m_videoWindowControl) {
- m_videoWindowControl = new MFEvrVideoWindowControl;
- return m_videoWindowControl;
- }
- } else if (qstrcmp(name,QMediaAudioProbeControl_iid) == 0) {
- if (m_session) {
- MFAudioProbeControl *probe = new MFAudioProbeControl(this);
- m_session->addProbe(probe);
- return probe;
- }
- return 0;
- } else if (qstrcmp(name,QMediaVideoProbeControl_iid) == 0) {
- if (m_session) {
- MFVideoProbeControl *probe = new MFVideoProbeControl(this);
- m_session->addProbe(probe);
- return probe;
- }
- return 0;
- }
-
- return 0;
-}
-
-void MFPlayerService::releaseControl(QMediaControl *control)
-{
- if (!control) {
- qWarning("QMediaService::releaseControl():"
- " Attempted release of null control");
- } else if (control == m_videoRendererControl) {
- m_videoRendererControl->setSurface(0);
- delete m_videoRendererControl;
- m_videoRendererControl = 0;
- return;
- } else if (control == m_videoWindowControl) {
- delete m_videoWindowControl;
- m_videoWindowControl = 0;
- return;
- }
-
- MFAudioProbeControl* audioProbe = qobject_cast<MFAudioProbeControl*>(control);
- if (audioProbe) {
- if (m_session)
- m_session->removeProbe(audioProbe);
- delete audioProbe;
- return;
- }
-
- MFVideoProbeControl* videoProbe = qobject_cast<MFVideoProbeControl*>(control);
- if (videoProbe) {
- if (m_session)
- m_session->removeProbe(videoProbe);
- delete videoProbe;
- return;
- }
-}
-
-MFAudioEndpointControl* MFPlayerService::audioEndpointControl() const
-{
- return m_audioEndpointControl;
-}
-
-MFVideoRendererControl* MFPlayerService::videoRendererControl() const
-{
- return m_videoRendererControl;
-}
-
-MFEvrVideoWindowControl* MFPlayerService::videoWindowControl() const
-{
- return m_videoWindowControl;
-}
-
-MFMetaDataControl* MFPlayerService::metaDataControl() const
-{
- return m_metaDataControl;
-}
diff --git a/src/plugins/wmf/player/mfplayerservice.h b/src/plugins/wmf/player/mfplayerservice.h
deleted file mode 100644
index 78423c0b1..000000000
--- a/src/plugins/wmf/player/mfplayerservice.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFPLAYERSERVICE_H
-#define MFPLAYERSERVICE_H
-
-#include <mfapi.h>
-#include <mfidl.h>
-
-#include "qmediaplayer.h"
-#include "qmediaservice.h"
-#include "qmediatimerange.h"
-
-QT_BEGIN_NAMESPACE
-class QMediaContent;
-QT_END_NAMESPACE
-
-QT_USE_NAMESPACE
-
-class MFEvrVideoWindowControl;
-class MFAudioEndpointControl;
-class MFVideoRendererControl;
-class MFPlayerControl;
-class MFMetaDataControl;
-class MFPlayerSession;
-
-class MFPlayerService : public QMediaService
-{
- Q_OBJECT
-public:
- MFPlayerService(QObject *parent = 0);
- ~MFPlayerService();
-
- QMediaControl* requestControl(const char *name);
- void releaseControl(QMediaControl *control);
-
- MFAudioEndpointControl* audioEndpointControl() const;
- MFVideoRendererControl* videoRendererControl() const;
- MFEvrVideoWindowControl* videoWindowControl() const;
- MFMetaDataControl* metaDataControl() const;
-
-private:
- MFPlayerSession *m_session;
- MFVideoRendererControl *m_videoRendererControl;
- MFAudioEndpointControl *m_audioEndpointControl;
- MFEvrVideoWindowControl *m_videoWindowControl;
- MFPlayerControl *m_player;
- MFMetaDataControl *m_metaDataControl;
-};
-
-#endif
diff --git a/src/plugins/wmf/player/mfplayersession.cpp b/src/plugins/wmf/player/mfplayersession.cpp
deleted file mode 100644
index 1d145edc4..000000000
--- a/src/plugins/wmf/player/mfplayersession.cpp
+++ /dev/null
@@ -1,1818 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmediacontent.h"
-#include "qmediaplayercontrol.h"
-
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qdatetime.h>
-#include <QtCore/qthread.h>
-#include <QtCore/qvarlengtharray.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qfile.h>
-#include <QtCore/qbuffer.h>
-
-#include "mfplayercontrol.h"
-#include "mfevrvideowindowcontrol.h"
-#include "mfvideorenderercontrol.h"
-#include "mfaudioendpointcontrol.h"
-
-#include "mfplayersession.h"
-#include "mfplayerservice.h"
-#include "mfmetadatacontrol.h"
-#include <mferror.h>
-#include <nserror.h>
-#include "sourceresolver.h"
-#include "samplegrabber.h"
-#include "mftvideo.h"
-#include <wmcodecdsp.h>
-
-//#define DEBUG_MEDIAFOUNDATION
-
-MFPlayerSession::MFPlayerSession(MFPlayerService *playerService)
- : m_playerService(playerService)
- , m_cRef(1)
- , m_session(0)
- , m_presentationClock(0)
- , m_rateControl(0)
- , m_rateSupport(0)
- , m_volumeControl(0)
- , m_netsourceStatistics(0)
- , m_duration(0)
- , m_sourceResolver(0)
- , m_hCloseEvent(0)
- , m_closing(false)
- , m_pendingRate(1)
- , m_volume(100)
- , m_muted(false)
- , m_status(QMediaPlayer::NoMedia)
- , m_scrubbing(false)
- , m_restoreRate(1)
- , m_mediaTypes(0)
- , m_audioSampleGrabber(0)
- , m_audioSampleGrabberNode(0)
- , m_videoProbeMFT(0)
-{
- QObject::connect(this, SIGNAL(sessionEvent(IMFMediaEvent*)), this, SLOT(handleSessionEvent(IMFMediaEvent*)));
-
- m_pendingState = NoPending;
- ZeroMemory(&m_state, sizeof(m_state));
- m_state.command = CmdStop;
- m_state.prevCmd = CmdNone;
- m_state.rate = 1.0f;
- ZeroMemory(&m_request, sizeof(m_request));
- m_request.command = CmdNone;
- m_request.prevCmd = CmdNone;
- m_request.rate = 1.0f;
-
- m_audioSampleGrabber = new AudioSampleGrabberCallback;
-}
-
-void MFPlayerSession::close()
-{
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "close";
-#endif
-
- clear();
- if (!m_session)
- return;
-
- HRESULT hr = S_OK;
- if (m_session) {
- m_closing = true;
- hr = m_session->Close();
- if (SUCCEEDED(hr)) {
- DWORD dwWaitResult = WaitForSingleObject(m_hCloseEvent, 100);
- if (dwWaitResult == WAIT_TIMEOUT) {
- qWarning() << "session close time out!";
- }
- }
- m_closing = false;
- }
-
- if (SUCCEEDED(hr)) {
- if (m_session)
- m_session->Shutdown();
- if (m_sourceResolver)
- m_sourceResolver->shutdown();
- }
- if (m_sourceResolver) {
- m_sourceResolver->Release();
- m_sourceResolver = 0;
- }
- if (m_videoProbeMFT) {
- m_videoProbeMFT->Release();
- m_videoProbeMFT = 0;
- }
-
- if (m_playerService->videoRendererControl()) {
- m_playerService->videoRendererControl()->releaseActivate();
- } else if (m_playerService->videoWindowControl()) {
- m_playerService->videoWindowControl()->releaseActivate();
- }
-
- if (m_session)
- m_session->Release();
- m_session = 0;
- if (m_hCloseEvent)
- CloseHandle(m_hCloseEvent);
- m_hCloseEvent = 0;
-}
-
-void MFPlayerSession::addProbe(MFAudioProbeControl *probe)
-{
- m_audioSampleGrabber->addProbe(probe);
-}
-
-void MFPlayerSession::removeProbe(MFAudioProbeControl *probe)
-{
- m_audioSampleGrabber->removeProbe(probe);
-}
-
-void MFPlayerSession::addProbe(MFVideoProbeControl* probe)
-{
- if (m_videoProbes.contains(probe))
- return;
-
- m_videoProbes.append(probe);
-
- if (m_videoProbeMFT)
- m_videoProbeMFT->addProbe(probe);
-}
-
-void MFPlayerSession::removeProbe(MFVideoProbeControl* probe)
-{
- m_videoProbes.removeOne(probe);
-
- if (m_videoProbeMFT)
- m_videoProbeMFT->removeProbe(probe);
-}
-
-MFPlayerSession::~MFPlayerSession()
-{
- m_audioSampleGrabber->Release();
-}
-
-
-void MFPlayerSession::load(const QMediaContent &media, QIODevice *stream)
-{
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "load";
-#endif
- clear();
- QUrl url = media.request().url();
-
- if (m_status == QMediaPlayer::LoadingMedia && m_sourceResolver)
- m_sourceResolver->cancel();
-
- if (url.isEmpty() && !stream) {
- changeStatus(QMediaPlayer::NoMedia);
- } else if (stream && (!stream->isReadable())) {
- changeStatus(QMediaPlayer::InvalidMedia);
- emit error(QMediaPlayer::ResourceError, tr("Invalid stream source."), true);
- } else {
- createSession();
- changeStatus(QMediaPlayer::LoadingMedia);
- m_sourceResolver->load(url, stream);
- }
- emit positionChanged(position());
-}
-
-void MFPlayerSession::handleSourceError(long hr)
-{
- QString errorString;
- QMediaPlayer::Error errorCode = QMediaPlayer::ResourceError;
- switch (hr) {
- case QMediaPlayer::FormatError:
- errorCode = QMediaPlayer::FormatError;
- errorString = tr("Attempting to play invalid Qt resource.");
- break;
- case NS_E_FILE_NOT_FOUND:
- errorString = tr("The system cannot find the file specified.");
- break;
- case NS_E_SERVER_NOT_FOUND:
- errorString = tr("The specified server could not be found.");
- break;
- case MF_E_UNSUPPORTED_BYTESTREAM_TYPE:
- errorCode = QMediaPlayer::FormatError;
- errorString = tr("Unsupported media type.");
- break;
- default:
- errorString = tr("Failed to load source.");
- break;
- }
- changeStatus(QMediaPlayer::InvalidMedia);
- emit error(errorCode, errorString, true);
-}
-
-void MFPlayerSession::handleMediaSourceReady()
-{
- if (QMediaPlayer::LoadingMedia != m_status || !m_sourceResolver || m_sourceResolver != sender())
- return;
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "handleMediaSourceReady";
-#endif
- HRESULT hr = S_OK;
- IMFMediaSource* mediaSource = m_sourceResolver->mediaSource();
-
- DWORD dwCharacteristics = 0;
- mediaSource->GetCharacteristics(&dwCharacteristics);
- emit seekableUpdate(MFMEDIASOURCE_CAN_SEEK & dwCharacteristics);
-
- IMFPresentationDescriptor* sourcePD;
- hr = mediaSource->CreatePresentationDescriptor(&sourcePD);
- if (SUCCEEDED(hr)) {
- m_duration = 0;
- m_playerService->metaDataControl()->updateSource(sourcePD, mediaSource);
- sourcePD->GetUINT64(MF_PD_DURATION, &m_duration);
- //convert from 100 nanosecond to milisecond
- emit durationUpdate(qint64(m_duration / 10000));
- setupPlaybackTopology(mediaSource, sourcePD);
- sourcePD->Release();
- } else {
- changeStatus(QMediaPlayer::InvalidMedia);
- emit error(QMediaPlayer::ResourceError, tr("Cannot create presentation descriptor."), true);
- }
-}
-
-MFPlayerSession::MediaType MFPlayerSession::getStreamType(IMFStreamDescriptor *stream) const
-{
- if (!stream)
- return Unknown;
-
- struct SafeRelease {
- IMFMediaTypeHandler *ptr = nullptr;
- ~SafeRelease() { if (ptr) ptr->Release(); }
- } typeHandler;
- if (SUCCEEDED(stream->GetMediaTypeHandler(&typeHandler.ptr))) {
- GUID guidMajorType;
- if (SUCCEEDED(typeHandler.ptr->GetMajorType(&guidMajorType))) {
- if (guidMajorType == MFMediaType_Audio)
- return Audio;
- else if (guidMajorType == MFMediaType_Video)
- return Video;
- }
- }
-
- return Unknown;
-}
-
-void MFPlayerSession::setupPlaybackTopology(IMFMediaSource *source, IMFPresentationDescriptor *sourcePD)
-{
- HRESULT hr = S_OK;
- // Get the number of streams in the media source.
- DWORD cSourceStreams = 0;
- hr = sourcePD->GetStreamDescriptorCount(&cSourceStreams);
- if (FAILED(hr)) {
- changeStatus(QMediaPlayer::UnknownMediaStatus);
- emit error(QMediaPlayer::ResourceError, tr("Failed to get stream count."), true);
- return;
- }
-
- IMFTopology *topology;
- hr = MFCreateTopology(&topology);
- if (FAILED(hr)) {
- changeStatus(QMediaPlayer::UnknownMediaStatus);
- emit error(QMediaPlayer::ResourceError, tr("Failed to create topology."), true);
- return;
- }
-
- // Remember output node id for a first video stream
- TOPOID outputNodeId = -1;
-
- // For each stream, create the topology nodes and add them to the topology.
- DWORD succeededCount = 0;
- for (DWORD i = 0; i < cSourceStreams; i++)
- {
- BOOL fSelected = FALSE;
- bool streamAdded = false;
- IMFStreamDescriptor *streamDesc = NULL;
-
- HRESULT hr = sourcePD->GetStreamDescriptorByIndex(i, &fSelected, &streamDesc);
- if (SUCCEEDED(hr)) {
- // The media might have multiple audio and video streams,
- // only use one of each kind, and only if it is selected by default.
- MediaType mediaType = getStreamType(streamDesc);
- if (mediaType != Unknown
- && ((m_mediaTypes & mediaType) == 0) // Check if this type isn't already added
- && fSelected) {
-
- IMFTopologyNode *sourceNode = addSourceNode(topology, source, sourcePD, streamDesc);
- if (sourceNode) {
- IMFTopologyNode *outputNode = addOutputNode(mediaType, topology, 0);
- if (outputNode) {
- bool connected = false;
- if (mediaType == Audio) {
- if (!m_audioSampleGrabberNode)
- connected = setupAudioSampleGrabber(topology, sourceNode, outputNode);
- } else if (mediaType == Video && outputNodeId == -1) {
- // Remember video output node ID.
- outputNode->GetTopoNodeID(&outputNodeId);
- }
-
- if (!connected)
- hr = sourceNode->ConnectOutput(0, outputNode, 0);
-
- if (FAILED(hr)) {
- emit error(QMediaPlayer::FormatError, tr("Unable to play any stream."), false);
- } else {
- streamAdded = true;
- succeededCount++;
- m_mediaTypes |= mediaType;
- switch (mediaType) {
- case Audio:
- emit audioAvailable();
- break;
- case Video:
- emit videoAvailable();
- break;
- }
- }
- outputNode->Release();
- }
- sourceNode->Release();
- }
- }
-
- if (fSelected && !streamAdded)
- sourcePD->DeselectStream(i);
-
- streamDesc->Release();
- }
- }
-
- if (succeededCount == 0) {
- changeStatus(QMediaPlayer::InvalidMedia);
- emit error(QMediaPlayer::ResourceError, tr("Unable to play."), true);
- } else {
- if (outputNodeId != -1) {
- topology = insertMFT(topology, outputNodeId);
- }
-
- hr = m_session->SetTopology(MFSESSION_SETTOPOLOGY_IMMEDIATE, topology);
- if (FAILED(hr)) {
- changeStatus(QMediaPlayer::UnknownMediaStatus);
- emit error(QMediaPlayer::ResourceError, tr("Failed to set topology."), true);
- }
- }
- topology->Release();
-}
-
-IMFTopologyNode* MFPlayerSession::addSourceNode(IMFTopology* topology, IMFMediaSource* source,
- IMFPresentationDescriptor* presentationDesc, IMFStreamDescriptor *streamDesc)
-{
- IMFTopologyNode *node = NULL;
- HRESULT hr = MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, &node);
- if (SUCCEEDED(hr)) {
- hr = node->SetUnknown(MF_TOPONODE_SOURCE, source);
- if (SUCCEEDED(hr)) {
- hr = node->SetUnknown(MF_TOPONODE_PRESENTATION_DESCRIPTOR, presentationDesc);
- if (SUCCEEDED(hr)) {
- hr = node->SetUnknown(MF_TOPONODE_STREAM_DESCRIPTOR, streamDesc);
- if (SUCCEEDED(hr)) {
- hr = topology->AddNode(node);
- if (SUCCEEDED(hr))
- return node;
- }
- }
- }
- node->Release();
- }
- return NULL;
-}
-
-IMFTopologyNode* MFPlayerSession::addOutputNode(MediaType mediaType, IMFTopology* topology, DWORD sinkID)
-{
- IMFTopologyNode *node = NULL;
- if (FAILED(MFCreateTopologyNode(MF_TOPOLOGY_OUTPUT_NODE, &node)))
- return NULL;
-
- IMFActivate *activate = NULL;
- if (mediaType == Audio) {
- activate = m_playerService->audioEndpointControl()->createActivate();
- } else if (mediaType == Video) {
- if (m_playerService->videoRendererControl()) {
- activate = m_playerService->videoRendererControl()->createActivate();
- } else if (m_playerService->videoWindowControl()) {
- activate = m_playerService->videoWindowControl()->createActivate();
- } else {
- qWarning() << "no videoWindowControl or videoRendererControl, unable to add output node for video data";
- }
- } else {
- // Unknown stream type.
- emit error(QMediaPlayer::FormatError, tr("Unknown stream type."), false);
- }
-
- if (!activate
- || FAILED(node->SetObject(activate))
- || FAILED(node->SetUINT32(MF_TOPONODE_STREAMID, sinkID))
- || FAILED(node->SetUINT32(MF_TOPONODE_NOSHUTDOWN_ON_REMOVE, FALSE))
- || FAILED(topology->AddNode(node))) {
- node->Release();
- node = NULL;
- }
-
- return node;
-}
-
-bool MFPlayerSession::addAudioSampleGrabberNode(IMFTopology *topology)
-{
- HRESULT hr = S_OK;
- IMFMediaType *pType = 0;
- IMFActivate *sinkActivate = 0;
- do {
- hr = MFCreateMediaType(&pType);
- if (FAILED(hr))
- break;
-
- hr = pType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
- if (FAILED(hr))
- break;
-
- hr = pType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
- if (FAILED(hr))
- break;
-
- hr = MFCreateSampleGrabberSinkActivate(pType, m_audioSampleGrabber, &sinkActivate);
- if (FAILED(hr))
- break;
-
- // Note: Data is distorted if this attribute is enabled
- hr = sinkActivate->SetUINT32(MF_SAMPLEGRABBERSINK_IGNORE_CLOCK, FALSE);
- if (FAILED(hr))
- break;
-
- hr = MFCreateTopologyNode(MF_TOPOLOGY_OUTPUT_NODE, &m_audioSampleGrabberNode);
- if (FAILED(hr))
- break;
-
- hr = m_audioSampleGrabberNode->SetObject(sinkActivate);
- if (FAILED(hr))
- break;
-
- hr = m_audioSampleGrabberNode->SetUINT32(MF_TOPONODE_STREAMID, 0); // Identifier of the stream sink.
- if (FAILED(hr))
- break;
-
- hr = m_audioSampleGrabberNode->SetUINT32(MF_TOPONODE_NOSHUTDOWN_ON_REMOVE, FALSE);
- if (FAILED(hr))
- break;
-
- hr = topology->AddNode(m_audioSampleGrabberNode);
- if (FAILED(hr))
- break;
-
- pType->Release();
- sinkActivate->Release();
- return true;
- } while (false);
-
- if (pType)
- pType->Release();
- if (sinkActivate)
- sinkActivate->Release();
- if (m_audioSampleGrabberNode) {
- m_audioSampleGrabberNode->Release();
- m_audioSampleGrabberNode = NULL;
- }
- return false;
-}
-
-bool MFPlayerSession::setupAudioSampleGrabber(IMFTopology *topology, IMFTopologyNode *sourceNode, IMFTopologyNode *outputNode)
-{
- if (!addAudioSampleGrabberNode(topology))
- return false;
-
- HRESULT hr = S_OK;
- IMFTopologyNode *pTeeNode = NULL;
-
- IMFMediaTypeHandler *typeHandler = NULL;
- IMFMediaType *mediaType = NULL;
- do {
- hr = MFCreateTopologyNode(MF_TOPOLOGY_TEE_NODE, &pTeeNode);
- if (FAILED(hr))
- break;
- hr = sourceNode->ConnectOutput(0, pTeeNode, 0);
- if (FAILED(hr))
- break;
- hr = pTeeNode->ConnectOutput(0, outputNode, 0);
- if (FAILED(hr))
- break;
- hr = pTeeNode->ConnectOutput(1, m_audioSampleGrabberNode, 0);
- if (FAILED(hr))
- break;
- } while (false);
-
- if (pTeeNode)
- pTeeNode->Release();
- if (mediaType)
- mediaType->Release();
- if (typeHandler)
- typeHandler->Release();
- return hr == S_OK;
-}
-
-QAudioFormat MFPlayerSession::audioFormatForMFMediaType(IMFMediaType *mediaType) const
-{
- WAVEFORMATEX *wfx = 0;
- UINT32 size;
- HRESULT hr = MFCreateWaveFormatExFromMFMediaType(mediaType, &wfx, &size, MFWaveFormatExConvertFlag_Normal);
- if (FAILED(hr))
- return QAudioFormat();
-
- if (size < sizeof(WAVEFORMATEX)) {
- CoTaskMemFree(wfx);
- return QAudioFormat();
- }
-
- if (wfx->wFormatTag != WAVE_FORMAT_PCM) {
- CoTaskMemFree(wfx);
- return QAudioFormat();
- }
-
- QAudioFormat format;
- format.setSampleRate(wfx->nSamplesPerSec);
- format.setChannelCount(wfx->nChannels);
- format.setSampleSize(wfx->wBitsPerSample);
- format.setCodec("audio/pcm");
- format.setByteOrder(QAudioFormat::LittleEndian);
- if (format.sampleSize() == 8)
- format.setSampleType(QAudioFormat::UnSignedInt);
- else
- format.setSampleType(QAudioFormat::SignedInt);
-
- CoTaskMemFree(wfx);
- return format;
-}
-
-// BindOutputNode
-// Sets the IMFStreamSink pointer on an output node.
-// IMFActivate pointer in the output node must be converted to an
-// IMFStreamSink pointer before the topology loader resolves the topology.
-HRESULT BindOutputNode(IMFTopologyNode *pNode)
-{
- IUnknown *nodeObject = NULL;
- IMFActivate *activate = NULL;
- IMFStreamSink *stream = NULL;
- IMFMediaSink *sink = NULL;
-
- HRESULT hr = pNode->GetObject(&nodeObject);
- if (FAILED(hr))
- return hr;
-
- hr = nodeObject->QueryInterface(IID_PPV_ARGS(&activate));
- if (SUCCEEDED(hr)) {
- DWORD dwStreamID = 0;
-
- // Try to create the media sink.
- hr = activate->ActivateObject(IID_PPV_ARGS(&sink));
- if (SUCCEEDED(hr))
- dwStreamID = MFGetAttributeUINT32(pNode, MF_TOPONODE_STREAMID, 0);
-
- if (SUCCEEDED(hr)) {
- // First check if the media sink already has a stream sink with the requested ID.
- hr = sink->GetStreamSinkById(dwStreamID, &stream);
- if (FAILED(hr)) {
- // Create the stream sink.
- hr = sink->AddStreamSink(dwStreamID, NULL, &stream);
- }
- }
-
- // Replace the node's object pointer with the stream sink.
- if (SUCCEEDED(hr)) {
- hr = pNode->SetObject(stream);
- }
- } else {
- hr = nodeObject->QueryInterface(IID_PPV_ARGS(&stream));
- }
-
- if (nodeObject)
- nodeObject->Release();
- if (activate)
- activate->Release();
- if (stream)
- stream->Release();
- if (sink)
- sink->Release();
- return hr;
-}
-
-// BindOutputNodes
-// Sets the IMFStreamSink pointers on all of the output nodes in a topology.
-HRESULT BindOutputNodes(IMFTopology *pTopology)
-{
- IMFCollection *collection;
-
- // Get the collection of output nodes.
- HRESULT hr = pTopology->GetOutputNodeCollection(&collection);
-
- // Enumerate all of the nodes in the collection.
- if (SUCCEEDED(hr)) {
- DWORD cNodes;
- hr = collection->GetElementCount(&cNodes);
-
- if (SUCCEEDED(hr)) {
- for (DWORD i = 0; i < cNodes; i++) {
- IUnknown *element;
- hr = collection->GetElement(i, &element);
- if (FAILED(hr))
- break;
-
- IMFTopologyNode *node;
- hr = element->QueryInterface(IID_IMFTopologyNode, (void**)&node);
- element->Release();
- if (FAILED(hr))
- break;
-
- // Bind this node.
- hr = BindOutputNode(node);
- node->Release();
- if (FAILED(hr))
- break;
- }
- }
- collection->Release();
- }
-
- return hr;
-}
-
-// This method binds output nodes to complete the topology,
-// then loads the topology and inserts MFT between the output node
-// and a filter connected to the output node.
-IMFTopology *MFPlayerSession::insertMFT(IMFTopology *topology, TOPOID outputNodeId)
-{
- bool isNewTopology = false;
-
- IMFTopoLoader *topoLoader = 0;
- IMFTopology *resolvedTopology = 0;
- IMFCollection *outputNodes = 0;
-
- do {
- if (FAILED(BindOutputNodes(topology)))
- break;
-
- if (FAILED(MFCreateTopoLoader(&topoLoader)))
- break;
-
- if (FAILED(topoLoader->Load(topology, &resolvedTopology, NULL))) {
- // Topology could not be resolved, adding ourselves a color converter
- // to the topology might solve the problem
- insertColorConverter(topology, outputNodeId);
- if (FAILED(topoLoader->Load(topology, &resolvedTopology, NULL)))
- break;
- }
-
- if (insertResizer(resolvedTopology))
- isNewTopology = true;
-
- // Get all output nodes and search for video output node.
- if (FAILED(resolvedTopology->GetOutputNodeCollection(&outputNodes)))
- break;
-
- DWORD elementCount = 0;
- if (FAILED(outputNodes->GetElementCount(&elementCount)))
- break;
-
- for (DWORD n = 0; n < elementCount; n++) {
- IUnknown *element = 0;
- IMFTopologyNode *node = 0;
- IUnknown *outputObject = 0;
- IMFTopologyNode *inputNode = 0;
- IMFTopologyNode *mftNode = 0;
- bool mftAdded = false;
-
- do {
- if (FAILED(outputNodes->GetElement(n, &element)))
- break;
-
- if (FAILED(element->QueryInterface(IID_IMFTopologyNode, (void**)&node)))
- break;
-
- TOPOID id;
- if (FAILED(node->GetTopoNodeID(&id)))
- break;
-
- if (id != outputNodeId)
- break;
-
- if (FAILED(node->GetObject(&outputObject)))
- break;
-
- m_videoProbeMFT->setVideoSink(outputObject);
-
- // Insert MFT between the output node and the node connected to it.
- DWORD outputIndex = 0;
- if (FAILED(node->GetInput(0, &inputNode, &outputIndex)))
- break;
-
- if (FAILED(MFCreateTopologyNode(MF_TOPOLOGY_TRANSFORM_NODE, &mftNode)))
- break;
-
- if (FAILED(mftNode->SetObject(m_videoProbeMFT)))
- break;
-
- if (FAILED(resolvedTopology->AddNode(mftNode)))
- break;
-
- if (FAILED(inputNode->ConnectOutput(0, mftNode, 0)))
- break;
-
- if (FAILED(mftNode->ConnectOutput(0, node, 0)))
- break;
-
- mftAdded = true;
- isNewTopology = true;
- } while (false);
-
- if (mftNode)
- mftNode->Release();
- if (inputNode)
- inputNode->Release();
- if (node)
- node->Release();
- if (element)
- element->Release();
- if (outputObject)
- outputObject->Release();
-
- if (mftAdded)
- break;
- else
- m_videoProbeMFT->setVideoSink(NULL);
- }
- } while (false);
-
- if (outputNodes)
- outputNodes->Release();
-
- if (topoLoader)
- topoLoader->Release();
-
- if (isNewTopology) {
- topology->Release();
- return resolvedTopology;
- }
-
- if (resolvedTopology)
- resolvedTopology->Release();
-
- return topology;
-}
-
-// This method checks if the topology contains a color converter transform (CColorConvertDMO),
-// if it does it inserts a resizer transform (CResizerDMO) to handle dynamic frame size change
-// of the video stream.
-// Returns true if it inserted a resizer
-bool MFPlayerSession::insertResizer(IMFTopology *topology)
-{
- bool inserted = false;
- WORD elementCount = 0;
- IMFTopologyNode *node = 0;
- IUnknown *object = 0;
- IWMColorConvProps *colorConv = 0;
- IMFTransform *resizer = 0;
- IMFTopologyNode *resizerNode = 0;
- IMFTopologyNode *inputNode = 0;
-
- HRESULT hr = topology->GetNodeCount(&elementCount);
- if (FAILED(hr))
- return false;
-
- for (WORD i = 0; i < elementCount; ++i) {
- if (node) {
- node->Release();
- node = 0;
- }
- if (object) {
- object->Release();
- object = 0;
- }
-
- if (FAILED(topology->GetNode(i, &node)))
- break;
-
- MF_TOPOLOGY_TYPE nodeType;
- if (FAILED(node->GetNodeType(&nodeType)))
- break;
-
- if (nodeType != MF_TOPOLOGY_TRANSFORM_NODE)
- continue;
-
- if (FAILED(node->GetObject(&object)))
- break;
-
- if (FAILED(object->QueryInterface(&colorConv)))
- continue;
-
- if (FAILED(CoCreateInstance(CLSID_CResizerDMO, NULL, CLSCTX_INPROC_SERVER, IID_IMFTransform, (void**)&resizer)))
- break;
-
- if (FAILED(MFCreateTopologyNode(MF_TOPOLOGY_TRANSFORM_NODE, &resizerNode)))
- break;
-
- if (FAILED(resizerNode->SetObject(resizer)))
- break;
-
- if (FAILED(topology->AddNode(resizerNode)))
- break;
-
- DWORD outputIndex = 0;
- if (FAILED(node->GetInput(0, &inputNode, &outputIndex))) {
- topology->RemoveNode(resizerNode);
- break;
- }
-
- if (FAILED(inputNode->ConnectOutput(0, resizerNode, 0))) {
- topology->RemoveNode(resizerNode);
- break;
- }
-
- if (FAILED(resizerNode->ConnectOutput(0, node, 0))) {
- inputNode->ConnectOutput(0, node, 0);
- topology->RemoveNode(resizerNode);
- break;
- }
-
- inserted = true;
- break;
- }
-
- if (node)
- node->Release();
- if (object)
- object->Release();
- if (colorConv)
- colorConv->Release();
- if (resizer)
- resizer->Release();
- if (resizerNode)
- resizerNode->Release();
- if (inputNode)
- inputNode->Release();
-
- return inserted;
-}
-
-// This method inserts a color converter (CColorConvertDMO) in the topology,
-// typically to convert to RGB format.
-// Usually this converter is automatically inserted when the topology is resolved but
-// for some reason it fails to do so in some cases, we then do it ourselves.
-void MFPlayerSession::insertColorConverter(IMFTopology *topology, TOPOID outputNodeId)
-{
- IMFCollection *outputNodes = 0;
-
- if (FAILED(topology->GetOutputNodeCollection(&outputNodes)))
- return;
-
- DWORD elementCount = 0;
- if (FAILED(outputNodes->GetElementCount(&elementCount)))
- goto done;
-
- for (DWORD n = 0; n < elementCount; n++) {
- IUnknown *element = 0;
- IMFTopologyNode *node = 0;
- IMFTopologyNode *inputNode = 0;
- IMFTopologyNode *mftNode = 0;
- IMFTransform *converter = 0;
-
- do {
- if (FAILED(outputNodes->GetElement(n, &element)))
- break;
-
- if (FAILED(element->QueryInterface(IID_IMFTopologyNode, (void**)&node)))
- break;
-
- TOPOID id;
- if (FAILED(node->GetTopoNodeID(&id)))
- break;
-
- if (id != outputNodeId)
- break;
-
- DWORD outputIndex = 0;
- if (FAILED(node->GetInput(0, &inputNode, &outputIndex)))
- break;
-
- if (FAILED(MFCreateTopologyNode(MF_TOPOLOGY_TRANSFORM_NODE, &mftNode)))
- break;
-
- if (FAILED(CoCreateInstance(CLSID_CColorConvertDMO, NULL, CLSCTX_INPROC_SERVER, IID_IMFTransform, (void**)&converter)))
- break;
-
- if (FAILED(mftNode->SetObject(converter)))
- break;
-
- if (FAILED(topology->AddNode(mftNode)))
- break;
-
- if (FAILED(inputNode->ConnectOutput(0, mftNode, 0)))
- break;
-
- if (FAILED(mftNode->ConnectOutput(0, node, 0)))
- break;
-
- } while (false);
-
- if (mftNode)
- mftNode->Release();
- if (inputNode)
- inputNode->Release();
- if (node)
- node->Release();
- if (element)
- element->Release();
- if (converter)
- converter->Release();
- }
-
-done:
- if (outputNodes)
- outputNodes->Release();
-}
-
-void MFPlayerSession::stop(bool immediate)
-{
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "stop";
-#endif
- if (!immediate && m_pendingState != NoPending) {
- m_request.setCommand(CmdStop);
- } else {
- if (m_state.command == CmdStop)
- return;
-
- if (m_scrubbing)
- scrub(false);
-
- if (SUCCEEDED(m_session->Stop())) {
- m_state.setCommand(CmdStop);
- m_pendingState = CmdPending;
- if (m_status != QMediaPlayer::EndOfMedia) {
- m_varStart.vt = VT_I8;
- m_varStart.hVal.QuadPart = 0;
- }
- } else {
- emit error(QMediaPlayer::ResourceError, tr("Failed to stop."), true);
- }
- }
-}
-
-void MFPlayerSession::start()
-{
- if (m_status == QMediaPlayer::EndOfMedia)
- m_varStart.hVal.QuadPart = 0; // restart from the beginning
-
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "start";
-#endif
-
- if (m_pendingState != NoPending) {
- m_request.setCommand(CmdStart);
- } else {
- if (m_state.command == CmdStart)
- return;
-
- if (m_scrubbing)
- scrub(false);
-
- if (SUCCEEDED(m_session->Start(&GUID_NULL, &m_varStart))) {
- m_state.setCommand(CmdStart);
- m_pendingState = CmdPending;
- PropVariantInit(&m_varStart);
- } else {
- emit error(QMediaPlayer::ResourceError, tr("failed to start playback"), true);
- }
- }
-}
-
-void MFPlayerSession::pause()
-{
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "pause";
-#endif
- if (m_pendingState != NoPending) {
- m_request.setCommand(CmdPause);
- } else {
- if (m_state.command == CmdPause)
- return;
-
- if (SUCCEEDED(m_session->Pause())) {
- m_state.setCommand(CmdPause);
- m_pendingState = CmdPending;
- } else {
- emit error(QMediaPlayer::ResourceError, tr("Failed to pause."), false);
- }
- }
-}
-
-void MFPlayerSession::changeStatus(QMediaPlayer::MediaStatus newStatus)
-{
- if (m_status == newStatus)
- return;
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MFPlayerSession::changeStatus" << newStatus;
-#endif
- m_status = newStatus;
- emit statusChanged();
-}
-
-QMediaPlayer::MediaStatus MFPlayerSession::status() const
-{
- return m_status;
-}
-
-void MFPlayerSession::createSession()
-{
- close();
-
- m_hCloseEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
-
- m_sourceResolver = new SourceResolver();
- QObject::connect(m_sourceResolver, SIGNAL(mediaSourceReady()), this, SLOT(handleMediaSourceReady()));
- QObject::connect(m_sourceResolver, SIGNAL(error(long)), this, SLOT(handleSourceError(long)));
-
- m_videoProbeMFT = new MFTransform;
- for (int i = 0; i < m_videoProbes.size(); ++i)
- m_videoProbeMFT->addProbe(m_videoProbes.at(i));
-
- Q_ASSERT(m_session == NULL);
- HRESULT hr = MFCreateMediaSession(NULL, &m_session);
- if (FAILED(hr)) {
- changeStatus(QMediaPlayer::UnknownMediaStatus);
- emit error(QMediaPlayer::ResourceError, tr("Unable to create mediasession."), true);
- }
-
- hr = m_session->BeginGetEvent(this, m_session);
-
- if (FAILED(hr)) {
- changeStatus(QMediaPlayer::UnknownMediaStatus);
- emit error(QMediaPlayer::ResourceError, tr("Unable to pull session events."), false);
- }
-
- PropVariantInit(&m_varStart);
- m_varStart.vt = VT_I8;
- m_varStart.hVal.QuadPart = 0;
-}
-
-qint64 MFPlayerSession::position()
-{
- if (m_request.command == CmdSeek || m_request.command == CmdSeekResume)
- return m_request.start;
-
- if (m_pendingState == SeekPending)
- return m_state.start;
-
- if (m_state.command == CmdStop)
- return qint64(m_varStart.hVal.QuadPart / 10000);
-
- if (m_presentationClock) {
- MFTIME time, sysTime;
- if (FAILED(m_presentationClock->GetCorrelatedTime(0, &time, &sysTime)))
- return 0;
- return qint64(time / 10000);
- }
- return 0;
-}
-
-void MFPlayerSession::setPosition(qint64 position)
-{
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "setPosition";
-#endif
- if (m_pendingState != NoPending) {
- m_request.setCommand(CmdSeek);
- m_request.start = position;
- } else {
- setPositionInternal(position, CmdNone);
- }
-}
-
-void MFPlayerSession::setPositionInternal(qint64 position, Command requestCmd)
-{
- if (m_status == QMediaPlayer::EndOfMedia)
- changeStatus(QMediaPlayer::LoadedMedia);
- if (m_state.command == CmdStop && requestCmd != CmdSeekResume) {
- m_varStart.vt = VT_I8;
- m_varStart.hVal.QuadPart = LONGLONG(position * 10000);
- // Even though the position is not actually set on the session yet,
- // report it to have changed anyway for UI controls to be updated
- emit positionChanged(this->position());
- return;
- }
-
- if (m_state.command == CmdPause)
- scrub(true);
-
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "setPositionInternal";
-#endif
-
- PROPVARIANT varStart;
- varStart.vt = VT_I8;
- varStart.hVal.QuadPart = LONGLONG(position * 10000);
- if (SUCCEEDED(m_session->Start(NULL, &varStart)))
- {
- PropVariantInit(&m_varStart);
- // Store the pending state.
- m_state.setCommand(CmdStart);
- m_state.start = position;
- m_pendingState = SeekPending;
- } else {
- emit error(QMediaPlayer::ResourceError, tr("Failed to seek."), true);
- }
-}
-
-qreal MFPlayerSession::playbackRate() const
-{
- if (m_scrubbing)
- return m_restoreRate;
- return m_state.rate;
-}
-
-void MFPlayerSession::setPlaybackRate(qreal rate)
-{
- if (m_scrubbing) {
- m_restoreRate = rate;
- emit playbackRateChanged(rate);
- return;
- }
- setPlaybackRateInternal(rate);
-}
-
-void MFPlayerSession::setPlaybackRateInternal(qreal rate)
-{
- if (rate == m_request.rate)
- return;
-
- m_pendingRate = rate;
- if (!m_rateSupport)
- return;
-
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "setPlaybackRate";
-#endif
- BOOL isThin = FALSE;
-
- //from MSDN http://msdn.microsoft.com/en-us/library/aa965220%28v=vs.85%29.aspx
- //Thinning applies primarily to video streams.
- //In thinned mode, the source drops delta frames and deliver only key frames.
- //At very high playback rates, the source might skip some key frames (for example, deliver every other key frame).
-
- if (FAILED(m_rateSupport->IsRateSupported(FALSE, rate, NULL))) {
- isThin = TRUE;
- if (FAILED(m_rateSupport->IsRateSupported(isThin, rate, NULL))) {
- qWarning() << "unable to set playbackrate = " << rate;
- m_pendingRate = m_request.rate = m_state.rate;
- return;
- }
- }
- if (m_pendingState != NoPending) {
- m_request.rate = rate;
- m_request.isThin = isThin;
- // Remember the current transport state (play, paused, etc), so that we
- // can restore it after the rate change, if necessary. However, if
- // anothercommand is already pending, that one takes precedent.
- if (m_request.command == CmdNone)
- m_request.setCommand(m_state.command);
- } else {
- //No pending operation. Commit the new rate.
- commitRateChange(rate, isThin);
- }
-}
-
-void MFPlayerSession::commitRateChange(qreal rate, BOOL isThin)
-{
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "commitRateChange";
-#endif
- Q_ASSERT(m_pendingState == NoPending);
- MFTIME hnsSystemTime = 0;
- MFTIME hnsClockTime = 0;
- Command cmdNow = m_state.command;
- bool resetPosition = false;
- // Allowed rate transitions:
- // Positive <-> negative: Stopped
- // Negative <-> zero: Stopped
- // Postive <-> zero: Paused or stopped
- if ((rate > 0 && m_state.rate <= 0) || (rate < 0 && m_state.rate >= 0)) {
- if (cmdNow == CmdStart) {
- // Get the current clock position. This will be the restart time.
- m_presentationClock->GetCorrelatedTime(0, &hnsClockTime, &hnsSystemTime);
- Q_ASSERT(hnsSystemTime != 0);
-
- if (rate < 0 || m_state.rate < 0)
- m_request.setCommand(CmdSeekResume);
- else if (isThin || m_state.isThin)
- m_request.setCommand(CmdStartAndSeek);
- else
- m_request.setCommand(CmdStart);
-
- // We need to stop only when dealing with negative rates
- if (rate >= 0 && m_state.rate >= 0)
- pause();
- else
- stop();
-
- // If we deal with negative rates, we stopped the session and consequently
- // reset the position to zero. We then need to resume to the current position.
- m_request.start = hnsClockTime / 10000;
- } else if (cmdNow == CmdPause) {
- if (rate < 0 || m_state.rate < 0) {
- // The current state is paused.
- // For this rate change, the session must be stopped. However, the
- // session cannot transition back from stopped to paused.
- // Therefore, this rate transition is not supported while paused.
- qWarning() << "Unable to change rate from positive to negative or vice versa in paused state";
- rate = m_state.rate;
- isThin = m_state.isThin;
- goto done;
- }
-
- // This happens when resuming playback after scrubbing in pause mode.
- // This transition requires the session to be paused. Even though our
- // internal state is set to paused, the session might not be so we need
- // to enforce it
- if (rate > 0 && m_state.rate == 0) {
- m_state.setCommand(CmdNone);
- pause();
- }
- }
- } else if (rate == 0 && m_state.rate > 0) {
- if (cmdNow != CmdPause) {
- // Transition to paused.
- // This transisition requires the paused state.
- // Pause and set the rate.
- pause();
-
- // Request: Switch back to current state.
- m_request.setCommand(cmdNow);
- }
- } else if (rate == 0 && m_state.rate < 0) {
- // Changing rate from negative to zero requires to stop the session
- m_presentationClock->GetCorrelatedTime(0, &hnsClockTime, &hnsSystemTime);
-
- m_request.setCommand(CmdSeekResume);
-
- stop();
-
- // Resume to the current position (stop() will reset the position to 0)
- m_request.start = hnsClockTime / 10000;
- } else if (!isThin && m_state.isThin) {
- if (cmdNow == CmdStart) {
- // When thinning, only key frames are read and presented. Going back
- // to normal playback requires to reset the current position to force
- // the pipeline to decode the actual frame at the current position
- // (which might be earlier than the last decoded key frame)
- resetPosition = true;
- } else if (cmdNow == CmdPause) {
- // If paused, don't reset the position until we resume, otherwise
- // a new frame will be rendered
- m_presentationClock->GetCorrelatedTime(0, &hnsClockTime, &hnsSystemTime);
- m_request.setCommand(CmdSeekResume);
- m_request.start = hnsClockTime / 10000;
- }
-
- }
-
- // Set the rate.
- if (FAILED(m_rateControl->SetRate(isThin, rate))) {
- qWarning() << "failed to set playbackrate = " << rate;
- rate = m_state.rate;
- isThin = m_state.isThin;
- goto done;
- }
-
- if (resetPosition) {
- m_presentationClock->GetCorrelatedTime(0, &hnsClockTime, &hnsSystemTime);
- setPosition(hnsClockTime / 10000);
- }
-
-done:
- // Adjust our current rate and requested rate.
- m_pendingRate = m_request.rate = m_state.rate = rate;
- if (rate != 0)
- m_state.isThin = isThin;
- emit playbackRateChanged(rate);
-}
-
-void MFPlayerSession::scrub(bool enableScrub)
-{
- if (m_scrubbing == enableScrub)
- return;
-
- m_scrubbing = enableScrub;
-
- if (!canScrub()) {
- if (!enableScrub)
- m_pendingRate = m_restoreRate;
- return;
- }
-
- if (enableScrub) {
- // Enter scrubbing mode. Cache the rate.
- m_restoreRate = m_request.rate;
- setPlaybackRateInternal(0.0f);
- } else {
- // Leaving scrubbing mode. Restore the old rate.
- setPlaybackRateInternal(m_restoreRate);
- }
-}
-
-int MFPlayerSession::volume() const
-{
- return m_volume;
-}
-
-void MFPlayerSession::setVolume(int volume)
-{
- if (m_volume == volume)
- return;
- m_volume = volume;
-
- if (!m_muted)
- setVolumeInternal(volume);
-
- emit volumeChanged(m_volume);
-}
-
-bool MFPlayerSession::isMuted() const
-{
- return m_muted;
-}
-
-void MFPlayerSession::setMuted(bool muted)
-{
- if (m_muted == muted)
- return;
- m_muted = muted;
-
- setVolumeInternal(muted ? 0 : m_volume);
-
- emit mutedChanged(m_muted);
-}
-
-void MFPlayerSession::setVolumeInternal(int volume)
-{
- if (m_volumeControl) {
- quint32 channelCount = 0;
- if (!SUCCEEDED(m_volumeControl->GetChannelCount(&channelCount))
- || channelCount == 0)
- return;
-
- float scaled = volume * 0.01f;
- for (quint32 i = 0; i < channelCount; ++i)
- m_volumeControl->SetChannelVolume(i, scaled);
- }
-}
-
-int MFPlayerSession::bufferStatus()
-{
- if (!m_netsourceStatistics)
- return 0;
- PROPVARIANT var;
- PropVariantInit(&var);
- PROPERTYKEY key;
- key.fmtid = MFNETSOURCE_STATISTICS;
- key.pid = MFNETSOURCE_BUFFERPROGRESS_ID;
- int progress = -1;
- // GetValue returns S_FALSE if the property is not available, which has
- // a value > 0. We therefore can't use the SUCCEEDED macro here.
- if (m_netsourceStatistics->GetValue(key, &var) == S_OK) {
- progress = var.lVal;
- PropVariantClear(&var);
- }
-
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "bufferStatus: progress = " << progress;
-#endif
-
- return progress;
-}
-
-QMediaTimeRange MFPlayerSession::availablePlaybackRanges()
-{
- // defaults to the whole media
- qint64 start = 0;
- qint64 end = qint64(m_duration / 10000);
-
- if (m_netsourceStatistics) {
- PROPVARIANT var;
- PropVariantInit(&var);
- PROPERTYKEY key;
- key.fmtid = MFNETSOURCE_STATISTICS;
- key.pid = MFNETSOURCE_SEEKRANGESTART_ID;
- // GetValue returns S_FALSE if the property is not available, which has
- // a value > 0. We therefore can't use the SUCCEEDED macro here.
- if (m_netsourceStatistics->GetValue(key, &var) == S_OK) {
- start = qint64(var.uhVal.QuadPart / 10000);
- PropVariantClear(&var);
- PropVariantInit(&var);
- key.pid = MFNETSOURCE_SEEKRANGEEND_ID;
- if (m_netsourceStatistics->GetValue(key, &var) == S_OK) {
- end = qint64(var.uhVal.QuadPart / 10000);
- PropVariantClear(&var);
- }
- }
- }
-
- return QMediaTimeRange(start, end);
-}
-
-HRESULT MFPlayerSession::QueryInterface(REFIID riid, void** ppvObject)
-{
- if (!ppvObject)
- return E_POINTER;
- if (riid == IID_IMFAsyncCallback) {
- *ppvObject = static_cast<IMFAsyncCallback*>(this);
- } else if (riid == IID_IUnknown) {
- *ppvObject = static_cast<IUnknown*>(this);
- } else {
- *ppvObject = NULL;
- return E_NOINTERFACE;
- }
- return S_OK;
-}
-
-ULONG MFPlayerSession::AddRef(void)
-{
- return InterlockedIncrement(&m_cRef);
-}
-
-ULONG MFPlayerSession::Release(void)
-{
- LONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0)
- this->deleteLater();
- return cRef;
-}
-
-HRESULT MFPlayerSession::Invoke(IMFAsyncResult *pResult)
-{
- if (pResult->GetStateNoAddRef() != m_session)
- return S_OK;
-
- IMFMediaEvent *pEvent = NULL;
- // Get the event from the event queue.
- HRESULT hr = m_session->EndGetEvent(pResult, &pEvent);
- if (FAILED(hr)) {
- return S_OK;
- }
-
- MediaEventType meType = MEUnknown;
- hr = pEvent->GetType(&meType);
- if (FAILED(hr)) {
- pEvent->Release();
- return S_OK;
- }
-
- if (meType == MESessionClosed) {
- SetEvent(m_hCloseEvent);
- pEvent->Release();
- return S_OK;
- } else {
- hr = m_session->BeginGetEvent(this, m_session);
- if (FAILED(hr)) {
- pEvent->Release();
- return S_OK;
- }
- }
-
- if (!m_closing) {
- emit sessionEvent(pEvent);
- } else {
- pEvent->Release();
- }
- return S_OK;
-}
-
-void MFPlayerSession::handleSessionEvent(IMFMediaEvent *sessionEvent)
-{
- HRESULT hrStatus = S_OK;
- HRESULT hr = sessionEvent->GetStatus(&hrStatus);
- if (FAILED(hr) || !m_session) {
- sessionEvent->Release();
- return;
- }
-
- MediaEventType meType = MEUnknown;
- hr = sessionEvent->GetType(&meType);
-
-#ifdef DEBUG_MEDIAFOUNDATION
- if (FAILED(hrStatus))
- qDebug() << "handleSessionEvent: MediaEventType = " << meType << "Failed";
- else
- qDebug() << "handleSessionEvent: MediaEventType = " << meType;
-#endif
-
- switch (meType) {
- case MENonFatalError: {
- PROPVARIANT var;
- PropVariantInit(&var);
- sessionEvent->GetValue(&var);
- qWarning() << "handleSessionEvent: non fatal error = " << var.ulVal;
- PropVariantClear(&var);
- emit error(QMediaPlayer::ResourceError, tr("Media session non-fatal error."), false);
- }
- break;
- case MESourceUnknown:
- changeStatus(QMediaPlayer::InvalidMedia);
- break;
- case MEError:
- changeStatus(QMediaPlayer::UnknownMediaStatus);
- qWarning() << "handleSessionEvent: serious error = " << hrStatus;
- emit error(QMediaPlayer::ResourceError, tr("Media session serious error."), true);
- break;
- case MESessionRateChanged:
- // If the rate change succeeded, we've already got the rate
- // cached. If it failed, try to get the actual rate.
- if (FAILED(hrStatus)) {
- PROPVARIANT var;
- PropVariantInit(&var);
- if (SUCCEEDED(sessionEvent->GetValue(&var)) && (var.vt == VT_R4)) {
- m_state.rate = var.fltVal;
- }
- emit playbackRateChanged(playbackRate());
- }
- break;
- case MESessionScrubSampleComplete :
- if (m_scrubbing)
- updatePendingCommands(CmdStart);
- break;
- case MESessionStarted:
- if (m_status == QMediaPlayer::EndOfMedia
- || m_status == QMediaPlayer::LoadedMedia) {
- // If the session started, then enough data is buffered to play
- changeStatus(QMediaPlayer::BufferedMedia);
- }
-
- updatePendingCommands(CmdStart);
- // playback started, we can now set again the procAmpValues if they have been
- // changed previously (these are lost when loading a new media)
- if (m_playerService->videoWindowControl()) {
- m_playerService->videoWindowControl()->applyImageControls();
- }
- break;
- case MESessionStopped:
- if (m_status != QMediaPlayer::EndOfMedia) {
- m_varStart.vt = VT_I8;
- m_varStart.hVal.QuadPart = 0;
-
- // Reset to Loaded status unless we are loading a new media
- // or changing the playback rate to negative values (stop required)
- if (m_status != QMediaPlayer::LoadingMedia && m_request.command != CmdSeekResume)
- changeStatus(QMediaPlayer::LoadedMedia);
- }
- updatePendingCommands(CmdStop);
- break;
- case MESessionPaused:
- updatePendingCommands(CmdPause);
- break;
- case MEReconnectStart:
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MEReconnectStart" << ((hrStatus == S_OK) ? "OK" : "Failed");
-#endif
- break;
- case MEReconnectEnd:
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MEReconnectEnd" << ((hrStatus == S_OK) ? "OK" : "Failed");
-#endif
- break;
- case MESessionTopologySet:
- if (FAILED(hrStatus)) {
- changeStatus(QMediaPlayer::InvalidMedia);
- emit error(QMediaPlayer::FormatError, tr("Unsupported media, a codec is missing."), true);
- } else {
- if (m_audioSampleGrabberNode) {
- IUnknown *obj = 0;
- if (SUCCEEDED(m_audioSampleGrabberNode->GetObject(&obj))) {
- IMFStreamSink *streamSink = 0;
- if (SUCCEEDED(obj->QueryInterface(IID_PPV_ARGS(&streamSink)))) {
- IMFMediaTypeHandler *typeHandler = 0;
- if (SUCCEEDED(streamSink->GetMediaTypeHandler((&typeHandler)))) {
- IMFMediaType *mediaType = 0;
- if (SUCCEEDED(typeHandler->GetCurrentMediaType(&mediaType))) {
- m_audioSampleGrabber->setFormat(audioFormatForMFMediaType(mediaType));
- mediaType->Release();
- }
- typeHandler->Release();
- }
- streamSink->Release();
- }
- obj->Release();
- }
- }
-
- // Topology is resolved and successfuly set, this happens only after loading a new media.
- // Make sure we always start the media from the beginning
- m_varStart.vt = VT_I8;
- m_varStart.hVal.QuadPart = 0;
-
- changeStatus(QMediaPlayer::LoadedMedia);
- }
- break;
- }
-
- if (FAILED(hrStatus)) {
- sessionEvent->Release();
- return;
- }
-
- switch (meType) {
- case MEBufferingStarted:
- changeStatus(QMediaPlayer::StalledMedia);
- emit bufferStatusChanged(bufferStatus());
- break;
- case MEBufferingStopped:
- changeStatus(QMediaPlayer::BufferedMedia);
- emit bufferStatusChanged(bufferStatus());
- break;
- case MESessionEnded:
- m_pendingState = NoPending;
- m_state.command = CmdStop;
- m_state.prevCmd = CmdNone;
- m_request.command = CmdNone;
- m_request.prevCmd = CmdNone;
-
- m_varStart.vt = VT_I8;
- //keep reporting the final position after end of media
- m_varStart.hVal.QuadPart = m_duration;
- emit positionChanged(position());
-
- changeStatus(QMediaPlayer::EndOfMedia);
- break;
- case MEEndOfPresentationSegment:
- break;
- case MESessionTopologyStatus: {
- UINT32 status;
- if (SUCCEEDED(sessionEvent->GetUINT32(MF_EVENT_TOPOLOGY_STATUS, &status))) {
- if (status == MF_TOPOSTATUS_READY) {
- IMFClock* clock;
- if (SUCCEEDED(m_session->GetClock(&clock))) {
- clock->QueryInterface(IID_IMFPresentationClock, (void**)(&m_presentationClock));
- clock->Release();
- }
-
- if (SUCCEEDED(MFGetService(m_session, MF_RATE_CONTROL_SERVICE, IID_PPV_ARGS(&m_rateControl)))) {
- if (SUCCEEDED(MFGetService(m_session, MF_RATE_CONTROL_SERVICE, IID_PPV_ARGS(&m_rateSupport)))) {
- if ((m_mediaTypes & Video) == Video
- && SUCCEEDED(m_rateSupport->IsRateSupported(TRUE, 0, NULL)))
- m_canScrub = true;
- }
- BOOL isThin = FALSE;
- float rate = 1;
- if (SUCCEEDED(m_rateControl->GetRate(&isThin, &rate))) {
- if (m_pendingRate != rate) {
- m_state.rate = m_request.rate = rate;
- setPlaybackRate(m_pendingRate);
- }
- }
- }
- MFGetService(m_session, MFNETSOURCE_STATISTICS_SERVICE, IID_PPV_ARGS(&m_netsourceStatistics));
-
- if (SUCCEEDED(MFGetService(m_session, MR_STREAM_VOLUME_SERVICE, IID_PPV_ARGS(&m_volumeControl))))
- setVolumeInternal(m_muted ? 0 : m_volume);
- }
- }
- }
- break;
- default:
- break;
- }
-
- sessionEvent->Release();
-}
-
-void MFPlayerSession::updatePendingCommands(Command command)
-{
- emit positionChanged(position());
- if (m_state.command != command || m_pendingState == NoPending)
- return;
-
- // Seek while paused completed
- if (m_pendingState == SeekPending && m_state.prevCmd == CmdPause) {
- m_pendingState = NoPending;
- // A seek operation actually restarts playback. If scrubbing is possible, playback rate
- // is set to 0.0 at this point and we just need to reset the current state to Pause.
- // If scrubbing is not possible, the playback rate was not changed and we explicitly need
- // to re-pause playback.
- if (!canScrub())
- pause();
- else
- m_state.setCommand(CmdPause);
- }
-
- m_pendingState = NoPending;
-
- //First look for rate changes.
- if (m_request.rate != m_state.rate) {
- commitRateChange(m_request.rate, m_request.isThin);
- }
-
- // Now look for new requests.
- if (m_pendingState == NoPending) {
- switch (m_request.command) {
- case CmdStart:
- start();
- break;
- case CmdPause:
- pause();
- break;
- case CmdStop:
- stop();
- break;
- case CmdSeek:
- case CmdSeekResume:
- setPositionInternal(m_request.start, m_request.command);
- break;
- case CmdStartAndSeek:
- start();
- setPositionInternal(m_request.start, m_request.command);
- break;
- }
- m_request.setCommand(CmdNone);
- }
-
-}
-
-bool MFPlayerSession::canScrub() const
-{
- return m_canScrub && m_rateSupport && m_rateControl;
-}
-
-void MFPlayerSession::clear()
-{
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MFPlayerSession::clear";
-#endif
- m_mediaTypes = 0;
- m_canScrub = false;
-
- m_pendingState = NoPending;
- m_state.command = CmdStop;
- m_state.prevCmd = CmdNone;
- m_request.command = CmdNone;
- m_request.prevCmd = CmdNone;
-
- if (m_presentationClock) {
- m_presentationClock->Release();
- m_presentationClock = NULL;
- }
- if (m_rateControl) {
- m_rateControl->Release();
- m_rateControl = NULL;
- }
- if (m_rateSupport) {
- m_rateSupport->Release();
- m_rateSupport = NULL;
- }
- if (m_volumeControl) {
- m_volumeControl->Release();
- m_volumeControl = NULL;
- }
- if (m_netsourceStatistics) {
- m_netsourceStatistics->Release();
- m_netsourceStatistics = NULL;
- }
- if (m_audioSampleGrabberNode) {
- m_audioSampleGrabberNode->Release();
- m_audioSampleGrabberNode = NULL;
- }
-}
diff --git a/src/plugins/wmf/player/mfplayersession.h b/src/plugins/wmf/player/mfplayersession.h
deleted file mode 100644
index c6ffba91f..000000000
--- a/src/plugins/wmf/player/mfplayersession.h
+++ /dev/null
@@ -1,239 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFPLAYERSESSION_H
-#define MFPLAYERSESSION_H
-
-#include <mfapi.h>
-#include <mfidl.h>
-
-#include "qmediaplayer.h"
-#include "qmediaservice.h"
-#include "qmediatimerange.h"
-
-#include <QtCore/qcoreevent.h>
-#include <QtCore/qmutex.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qwaitcondition.h>
-#include <QtMultimedia/qaudioformat.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
-
-QT_BEGIN_NAMESPACE
-class QMediaContent;
-QT_END_NAMESPACE
-
-QT_USE_NAMESPACE
-
-class SourceResolver;
-class MFAudioEndpointControl;
-class MFVideoRendererControl;
-class MFPlayerControl;
-class MFMetaDataControl;
-class MFPlayerService;
-class AudioSampleGrabberCallback;
-class MFTransform;
-class MFAudioProbeControl;
-class MFVideoProbeControl;
-
-class MFPlayerSession : public QObject, public IMFAsyncCallback
-{
- Q_OBJECT
- friend class SourceResolver;
-public:
- MFPlayerSession(MFPlayerService *playerService = 0);
- ~MFPlayerSession();
-
- STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject);
-
- STDMETHODIMP_(ULONG) AddRef(void);
-
- STDMETHODIMP_(ULONG) Release(void);
-
- STDMETHODIMP Invoke(IMFAsyncResult *pResult);
-
- STDMETHODIMP GetParameters(DWORD *pdwFlags, DWORD *pdwQueue)
- {
- Q_UNUSED(pdwFlags);
- Q_UNUSED(pdwQueue);
- return E_NOTIMPL;
- }
-
- void load(const QMediaContent &media, QIODevice *stream);
- void stop(bool immediate = false);
- void start();
- void pause();
-
- QMediaPlayer::MediaStatus status() const;
- qint64 position();
- void setPosition(qint64 position);
- qreal playbackRate() const;
- void setPlaybackRate(qreal rate);
- int volume() const;
- void setVolume(int volume);
- bool isMuted() const;
- void setMuted(bool muted);
- int bufferStatus();
- QMediaTimeRange availablePlaybackRanges();
-
- void changeStatus(QMediaPlayer::MediaStatus newStatus);
-
- void close();
-
- void addProbe(MFAudioProbeControl* probe);
- void removeProbe(MFAudioProbeControl* probe);
- void addProbe(MFVideoProbeControl* probe);
- void removeProbe(MFVideoProbeControl* probe);
-
-Q_SIGNALS:
- void error(QMediaPlayer::Error error, QString errorString, bool isFatal);
- void sessionEvent(IMFMediaEvent *sessionEvent);
- void statusChanged();
- void audioAvailable();
- void videoAvailable();
- void durationUpdate(qint64 duration);
- void seekableUpdate(bool seekable);
- void positionChanged(qint64 position);
- void playbackRateChanged(qreal rate);
- void volumeChanged(int volume);
- void mutedChanged(bool muted);
- void bufferStatusChanged(int percentFilled);
-
-private Q_SLOTS:
- void handleMediaSourceReady();
- void handleSessionEvent(IMFMediaEvent *sessionEvent);
- void handleSourceError(long hr);
-
-private:
- long m_cRef;
- MFPlayerService *m_playerService;
- IMFMediaSession *m_session;
- IMFPresentationClock *m_presentationClock;
- IMFRateControl *m_rateControl;
- IMFRateSupport *m_rateSupport;
- IMFAudioStreamVolume *m_volumeControl;
- IPropertyStore *m_netsourceStatistics;
- PROPVARIANT m_varStart;
- UINT64 m_duration;
-
- enum Command
- {
- CmdNone = 0,
- CmdStop,
- CmdStart,
- CmdPause,
- CmdSeek,
- CmdSeekResume,
- CmdStartAndSeek
- };
-
- void clear();
- void setPositionInternal(qint64 position, Command requestCmd);
- void setPlaybackRateInternal(qreal rate);
- void commitRateChange(qreal rate, BOOL isThin);
- bool canScrub() const;
- void scrub(bool enableScrub);
- bool m_scrubbing;
- float m_restoreRate;
-
- SourceResolver *m_sourceResolver;
- HANDLE m_hCloseEvent;
- bool m_closing;
-
- enum MediaType
- {
- Unknown = 0,
- Audio = 1,
- Video = 2,
- };
- DWORD m_mediaTypes;
-
- enum PendingState
- {
- NoPending = 0,
- CmdPending,
- SeekPending,
- };
-
- struct SeekState
- {
- void setCommand(Command cmd) {
- prevCmd = command;
- command = cmd;
- }
- Command command;
- Command prevCmd;
- float rate; // Playback rate
- BOOL isThin; // Thinned playback?
- qint64 start; // Start position
- };
- SeekState m_state; // Current nominal state.
- SeekState m_request; // Pending request.
- PendingState m_pendingState;
- float m_pendingRate;
- void updatePendingCommands(Command command);
-
- QMediaPlayer::MediaStatus m_status;
- bool m_canScrub;
- int m_volume;
- bool m_muted;
-
- void setVolumeInternal(int volume);
-
- void createSession();
- void setupPlaybackTopology(IMFMediaSource *source, IMFPresentationDescriptor *sourcePD);
- MediaType getStreamType(IMFStreamDescriptor *stream) const;
- IMFTopologyNode* addSourceNode(IMFTopology* topology, IMFMediaSource* source,
- IMFPresentationDescriptor* presentationDesc, IMFStreamDescriptor *streamDesc);
- IMFTopologyNode* addOutputNode(MediaType mediaType, IMFTopology* topology, DWORD sinkID);
-
- bool addAudioSampleGrabberNode(IMFTopology* topology);
- bool setupAudioSampleGrabber(IMFTopology *topology, IMFTopologyNode *sourceNode, IMFTopologyNode *outputNode);
- QAudioFormat audioFormatForMFMediaType(IMFMediaType *mediaType) const;
- AudioSampleGrabberCallback *m_audioSampleGrabber;
- IMFTopologyNode *m_audioSampleGrabberNode;
-
- IMFTopology *insertMFT(IMFTopology *topology, TOPOID outputNodeId);
- bool insertResizer(IMFTopology *topology);
- void insertColorConverter(IMFTopology *topology, TOPOID outputNodeId);
- MFTransform *m_videoProbeMFT;
- QList<MFVideoProbeControl*> m_videoProbes;
-};
-
-
-#endif
diff --git a/src/plugins/wmf/player/mftvideo.cpp b/src/plugins/wmf/player/mftvideo.cpp
deleted file mode 100644
index 9dce654f2..000000000
--- a/src/plugins/wmf/player/mftvideo.cpp
+++ /dev/null
@@ -1,753 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mftvideo.h"
-#include "mfvideoprobecontrol.h"
-#include <private/qmemoryvideobuffer_p.h>
-#include <mferror.h>
-#include <strmif.h>
-#include <uuids.h>
-#include <InitGuid.h>
-#include <d3d9.h>
-#include <qdebug.h>
-
-// This MFT sends all samples it processes to connected video probes.
-// Sample is sent to probes in ProcessInput.
-// In ProcessOutput this MFT simply returns the original sample.
-
-// The implementation is based on a boilerplate from the MF SDK example.
-
-MFTransform::MFTransform():
- m_cRef(1),
- m_inputType(0),
- m_outputType(0),
- m_sample(0),
- m_videoSinkTypeHandler(0),
- m_bytesPerLine(0)
-{
-}
-
-MFTransform::~MFTransform()
-{
- if (m_inputType)
- m_inputType->Release();
-
- if (m_outputType)
- m_outputType->Release();
-
- if (m_videoSinkTypeHandler)
- m_videoSinkTypeHandler->Release();
-}
-
-void MFTransform::addProbe(MFVideoProbeControl *probe)
-{
- QMutexLocker locker(&m_videoProbeMutex);
-
- if (m_videoProbes.contains(probe))
- return;
-
- m_videoProbes.append(probe);
-}
-
-void MFTransform::removeProbe(MFVideoProbeControl *probe)
-{
- QMutexLocker locker(&m_videoProbeMutex);
- m_videoProbes.removeOne(probe);
-}
-
-void MFTransform::setVideoSink(IUnknown *videoSink)
-{
- // This transform supports the same input types as the video sink.
- // Store its type handler interface in order to report the correct supported types.
-
- if (m_videoSinkTypeHandler) {
- m_videoSinkTypeHandler->Release();
- m_videoSinkTypeHandler = NULL;
- }
-
- if (videoSink)
- videoSink->QueryInterface(IID_PPV_ARGS(&m_videoSinkTypeHandler));
-}
-
-STDMETHODIMP MFTransform::QueryInterface(REFIID riid, void** ppv)
-{
- if (!ppv)
- return E_POINTER;
- if (riid == IID_IMFTransform) {
- *ppv = static_cast<IMFTransform*>(this);
- } else if (riid == IID_IUnknown) {
- *ppv = static_cast<IUnknown*>(this);
- } else {
- *ppv = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
-}
-
-STDMETHODIMP_(ULONG) MFTransform::AddRef()
-{
- return InterlockedIncrement(&m_cRef);
-}
-
-STDMETHODIMP_(ULONG) MFTransform::Release()
-{
- ULONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0) {
- delete this;
- }
- return cRef;
-}
-
-STDMETHODIMP MFTransform::GetStreamLimits(DWORD *pdwInputMinimum, DWORD *pdwInputMaximum, DWORD *pdwOutputMinimum, DWORD *pdwOutputMaximum)
-{
- if (!pdwInputMinimum || !pdwInputMaximum || !pdwOutputMinimum || !pdwOutputMaximum)
- return E_POINTER;
- *pdwInputMinimum = 1;
- *pdwInputMaximum = 1;
- *pdwOutputMinimum = 1;
- *pdwOutputMaximum = 1;
- return S_OK;
-}
-
-STDMETHODIMP MFTransform::GetStreamCount(DWORD *pcInputStreams, DWORD *pcOutputStreams)
-{
- if (!pcInputStreams || !pcOutputStreams)
- return E_POINTER;
-
- *pcInputStreams = 1;
- *pcOutputStreams = 1;
- return S_OK;
-}
-
-STDMETHODIMP MFTransform::GetStreamIDs(DWORD dwInputIDArraySize, DWORD *pdwInputIDs, DWORD dwOutputIDArraySize, DWORD *pdwOutputIDs)
-{
- // streams are numbered consecutively
- Q_UNUSED(dwInputIDArraySize);
- Q_UNUSED(pdwInputIDs);
- Q_UNUSED(dwOutputIDArraySize);
- Q_UNUSED(pdwOutputIDs);
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFTransform::GetInputStreamInfo(DWORD dwInputStreamID, MFT_INPUT_STREAM_INFO *pStreamInfo)
-{
- QMutexLocker locker(&m_mutex);
-
- if (dwInputStreamID > 0)
- return MF_E_INVALIDSTREAMNUMBER;
-
- if (!pStreamInfo)
- return E_POINTER;
-
- pStreamInfo->cbSize = 0;
- pStreamInfo->hnsMaxLatency = 0;
- pStreamInfo->cbMaxLookahead = 0;
- pStreamInfo->cbAlignment = 0;
- pStreamInfo->dwFlags = MFT_INPUT_STREAM_WHOLE_SAMPLES
- | MFT_INPUT_STREAM_SINGLE_SAMPLE_PER_BUFFER
- | MFT_INPUT_STREAM_PROCESSES_IN_PLACE;
-
- return S_OK;
-}
-
-STDMETHODIMP MFTransform::GetOutputStreamInfo(DWORD dwOutputStreamID, MFT_OUTPUT_STREAM_INFO *pStreamInfo)
-{
- QMutexLocker locker(&m_mutex);
-
- if (dwOutputStreamID > 0)
- return MF_E_INVALIDSTREAMNUMBER;
-
- if (!pStreamInfo)
- return E_POINTER;
-
- pStreamInfo->cbSize = 0;
- pStreamInfo->cbAlignment = 0;
- pStreamInfo->dwFlags = MFT_OUTPUT_STREAM_WHOLE_SAMPLES
- | MFT_OUTPUT_STREAM_SINGLE_SAMPLE_PER_BUFFER
- | MFT_OUTPUT_STREAM_PROVIDES_SAMPLES
- | MFT_OUTPUT_STREAM_DISCARDABLE;
-
- return S_OK;
-}
-
-STDMETHODIMP MFTransform::GetAttributes(IMFAttributes **pAttributes)
-{
- // This MFT does not support attributes.
- Q_UNUSED(pAttributes);
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFTransform::GetInputStreamAttributes(DWORD dwInputStreamID, IMFAttributes **pAttributes)
-{
- // This MFT does not support input stream attributes.
- Q_UNUSED(dwInputStreamID);
- Q_UNUSED(pAttributes);
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFTransform::GetOutputStreamAttributes(DWORD dwOutputStreamID, IMFAttributes **pAttributes)
-{
- // This MFT does not support output stream attributes.
- Q_UNUSED(dwOutputStreamID);
- Q_UNUSED(pAttributes);
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFTransform::DeleteInputStream(DWORD dwStreamID)
-{
- // This MFT has a fixed number of input streams.
- Q_UNUSED(dwStreamID);
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFTransform::AddInputStreams(DWORD cStreams, DWORD *adwStreamIDs)
-{
- // This MFT has a fixed number of input streams.
- Q_UNUSED(cStreams);
- Q_UNUSED(adwStreamIDs);
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFTransform::GetInputAvailableType(DWORD dwInputStreamID, DWORD dwTypeIndex, IMFMediaType **ppType)
-{
- // We support the same input types as the video sink
- if (!m_videoSinkTypeHandler)
- return E_NOTIMPL;
-
- if (dwInputStreamID > 0)
- return MF_E_INVALIDSTREAMNUMBER;
-
- if (!ppType)
- return E_POINTER;
-
- return m_videoSinkTypeHandler->GetMediaTypeByIndex(dwTypeIndex, ppType);
-}
-
-STDMETHODIMP MFTransform::GetOutputAvailableType(DWORD dwOutputStreamID, DWORD dwTypeIndex, IMFMediaType **ppType)
-{
- // Since we don't modify the samples, the output type must be the same as the input type.
- // Report our input type as the only available output type.
-
- if (dwOutputStreamID > 0)
- return MF_E_INVALIDSTREAMNUMBER;
-
- if (!ppType)
- return E_POINTER;
-
- // Input type must be set first
- if (!m_inputType)
- return MF_E_TRANSFORM_TYPE_NOT_SET;
-
- if (dwTypeIndex > 0)
- return MF_E_NO_MORE_TYPES;
-
- // Return a copy to make sure our type is not modified
- if (FAILED(MFCreateMediaType(ppType)))
- return E_OUTOFMEMORY;
-
- return m_inputType->CopyAllItems(*ppType);
-}
-
-STDMETHODIMP MFTransform::SetInputType(DWORD dwInputStreamID, IMFMediaType *pType, DWORD dwFlags)
-{
- if (dwInputStreamID > 0)
- return MF_E_INVALIDSTREAMNUMBER;
-
- QMutexLocker locker(&m_mutex);
-
- if (m_sample)
- return MF_E_TRANSFORM_CANNOT_CHANGE_MEDIATYPE_WHILE_PROCESSING;
-
- if (!isMediaTypeSupported(pType))
- return MF_E_INVALIDMEDIATYPE;
-
- if (dwFlags == MFT_SET_TYPE_TEST_ONLY)
- return pType ? S_OK : E_POINTER;
-
- if (m_inputType) {
- m_inputType->Release();
- // Input type has changed, discard output type (if it's set) so it's reset later on
- DWORD flags = 0;
- if (m_outputType && m_outputType->IsEqual(pType, &flags) != S_OK) {
- m_outputType->Release();
- m_outputType = 0;
- }
- }
-
- m_inputType = pType;
-
- if (m_inputType)
- m_inputType->AddRef();
-
- return S_OK;
-}
-
-STDMETHODIMP MFTransform::SetOutputType(DWORD dwOutputStreamID, IMFMediaType *pType, DWORD dwFlags)
-{
- if (dwOutputStreamID > 0)
- return MF_E_INVALIDSTREAMNUMBER;
-
- if (dwFlags == MFT_SET_TYPE_TEST_ONLY && !pType)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
-
- // Input type must be set first
- if (!m_inputType)
- return MF_E_TRANSFORM_TYPE_NOT_SET;
-
- if (m_sample)
- return MF_E_TRANSFORM_CANNOT_CHANGE_MEDIATYPE_WHILE_PROCESSING;
-
- DWORD flags = 0;
- if (pType && m_inputType->IsEqual(pType, &flags) != S_OK)
- return MF_E_INVALIDMEDIATYPE;
-
- if (dwFlags == MFT_SET_TYPE_TEST_ONLY)
- return pType ? S_OK : E_POINTER;
-
- if (m_outputType)
- m_outputType->Release();
-
- m_outputType = pType;
-
- if (m_outputType) {
- m_outputType->AddRef();
- m_format = videoFormatForMFMediaType(m_outputType, &m_bytesPerLine);
- }
-
- return S_OK;
-}
-
-STDMETHODIMP MFTransform::GetInputCurrentType(DWORD dwInputStreamID, IMFMediaType **ppType)
-{
- if (dwInputStreamID > 0)
- return MF_E_INVALIDSTREAMNUMBER;
-
- if (ppType == NULL)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
-
- if (!m_inputType)
- return MF_E_TRANSFORM_TYPE_NOT_SET;
-
- // Return a copy to make sure our type is not modified
- if (FAILED(MFCreateMediaType(ppType)))
- return E_OUTOFMEMORY;
-
- return m_inputType->CopyAllItems(*ppType);
-}
-
-STDMETHODIMP MFTransform::GetOutputCurrentType(DWORD dwOutputStreamID, IMFMediaType **ppType)
-{
- if (dwOutputStreamID > 0)
- return MF_E_INVALIDSTREAMNUMBER;
-
- if (ppType == NULL)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
-
- if (!m_outputType)
- return MF_E_TRANSFORM_TYPE_NOT_SET;
-
- // Return a copy to make sure our type is not modified
- if (FAILED(MFCreateMediaType(ppType)))
- return E_OUTOFMEMORY;
-
- return m_outputType->CopyAllItems(*ppType);
-}
-
-STDMETHODIMP MFTransform::GetInputStatus(DWORD dwInputStreamID, DWORD *pdwFlags)
-{
- if (dwInputStreamID > 0)
- return MF_E_INVALIDSTREAMNUMBER;
-
- if (!pdwFlags)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
-
- if (!m_inputType || !m_outputType)
- return MF_E_TRANSFORM_TYPE_NOT_SET;
-
- if (m_sample)
- *pdwFlags = 0;
- else
- *pdwFlags = MFT_INPUT_STATUS_ACCEPT_DATA;
-
- return S_OK;
-}
-
-STDMETHODIMP MFTransform::GetOutputStatus(DWORD *pdwFlags)
-{
- if (!pdwFlags)
- return E_POINTER;
-
- QMutexLocker locker(&m_mutex);
-
- if (!m_inputType || !m_outputType)
- return MF_E_TRANSFORM_TYPE_NOT_SET;
-
- if (m_sample)
- *pdwFlags = MFT_OUTPUT_STATUS_SAMPLE_READY;
- else
- *pdwFlags = 0;
-
- return S_OK;
-}
-
-STDMETHODIMP MFTransform::SetOutputBounds(LONGLONG hnsLowerBound, LONGLONG hnsUpperBound)
-{
- Q_UNUSED(hnsLowerBound);
- Q_UNUSED(hnsUpperBound);
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFTransform::ProcessEvent(DWORD dwInputStreamID, IMFMediaEvent *pEvent)
-{
- // This MFT ignores all events, and the pipeline should send all events downstream.
- Q_UNUSED(dwInputStreamID);
- Q_UNUSED(pEvent);
- return E_NOTIMPL;
-}
-
-STDMETHODIMP MFTransform::ProcessMessage(MFT_MESSAGE_TYPE eMessage, ULONG_PTR ulParam)
-{
- Q_UNUSED(ulParam);
-
- HRESULT hr = S_OK;
-
- switch (eMessage)
- {
- case MFT_MESSAGE_COMMAND_FLUSH:
- hr = OnFlush();
- break;
-
- case MFT_MESSAGE_COMMAND_DRAIN:
- // Drain: Tells the MFT not to accept any more input until
- // all of the pending output has been processed. That is our
- // default behevior already, so there is nothing to do.
- break;
-
- case MFT_MESSAGE_SET_D3D_MANAGER:
- // The pipeline should never send this message unless the MFT
- // has the MF_SA_D3D_AWARE attribute set to TRUE. However, if we
- // do get this message, it's invalid and we don't implement it.
- hr = E_NOTIMPL;
- break;
-
- // The remaining messages do not require any action from this MFT.
- case MFT_MESSAGE_NOTIFY_BEGIN_STREAMING:
- case MFT_MESSAGE_NOTIFY_END_STREAMING:
- case MFT_MESSAGE_NOTIFY_END_OF_STREAM:
- case MFT_MESSAGE_NOTIFY_START_OF_STREAM:
- break;
- }
-
- return hr;
-}
-
-STDMETHODIMP MFTransform::ProcessInput(DWORD dwInputStreamID, IMFSample *pSample, DWORD dwFlags)
-{
- if (dwInputStreamID > 0)
- return MF_E_INVALIDSTREAMNUMBER;
-
- if (dwFlags != 0)
- return E_INVALIDARG; // dwFlags is reserved and must be zero.
-
- QMutexLocker locker(&m_mutex);
-
- if (!m_inputType)
- return MF_E_TRANSFORM_TYPE_NOT_SET;
-
- if (m_sample)
- return MF_E_NOTACCEPTING;
-
- // Validate the number of buffers. There should only be a single buffer to hold the video frame.
- DWORD dwBufferCount = 0;
- HRESULT hr = pSample->GetBufferCount(&dwBufferCount);
- if (FAILED(hr))
- return hr;
-
- if (dwBufferCount == 0)
- return E_FAIL;
-
- if (dwBufferCount > 1)
- return MF_E_SAMPLE_HAS_TOO_MANY_BUFFERS;
-
- m_sample = pSample;
- m_sample->AddRef();
-
- QMutexLocker lockerProbe(&m_videoProbeMutex);
-
- if (!m_videoProbes.isEmpty()) {
- QVideoFrame frame = makeVideoFrame();
-
- for (MFVideoProbeControl* probe : qAsConst(m_videoProbes))
- probe->bufferProbed(frame);
- }
-
- return S_OK;
-}
-
-STDMETHODIMP MFTransform::ProcessOutput(DWORD dwFlags, DWORD cOutputBufferCount, MFT_OUTPUT_DATA_BUFFER *pOutputSamples, DWORD *pdwStatus)
-{
- if (pOutputSamples == NULL || pdwStatus == NULL)
- return E_POINTER;
-
- if (cOutputBufferCount != 1)
- return E_INVALIDARG;
-
- QMutexLocker locker(&m_mutex);
-
- if (!m_inputType)
- return MF_E_TRANSFORM_TYPE_NOT_SET;
-
- if (!m_outputType) {
- pOutputSamples[0].dwStatus = MFT_OUTPUT_DATA_BUFFER_FORMAT_CHANGE;
- return MF_E_TRANSFORM_STREAM_CHANGE;
- }
-
- IMFMediaBuffer *input = NULL;
- IMFMediaBuffer *output = NULL;
-
- if (dwFlags == MFT_PROCESS_OUTPUT_DISCARD_WHEN_NO_BUFFER)
- goto done;
- else if (dwFlags != 0)
- return E_INVALIDARG;
-
- if (!m_sample)
- return MF_E_TRANSFORM_NEED_MORE_INPUT;
-
- // Since the MFT_OUTPUT_STREAM_PROVIDES_SAMPLES flag is set, the client
- // should not be providing samples here
- if (pOutputSamples[0].pSample != NULL)
- return E_INVALIDARG;
-
- pOutputSamples[0].pSample = m_sample;
- pOutputSamples[0].pSample->AddRef();
-
- // Send video frame to probes
- // We do it here (instead of inside ProcessInput) to make sure samples discarded by the renderer
- // are not sent.
- m_videoProbeMutex.lock();
- if (!m_videoProbes.isEmpty()) {
- QVideoFrame frame = makeVideoFrame();
-
- for (MFVideoProbeControl* probe : qAsConst(m_videoProbes))
- probe->bufferProbed(frame);
- }
- m_videoProbeMutex.unlock();
-
-done:
- pOutputSamples[0].dwStatus = 0;
- *pdwStatus = 0;
-
- m_sample->Release();
- m_sample = 0;
-
- if (input)
- input->Release();
- if (output)
- output->Release();
-
- return S_OK;
-}
-
-HRESULT MFTransform::OnFlush()
-{
- QMutexLocker locker(&m_mutex);
-
- if (m_sample) {
- m_sample->Release();
- m_sample = 0;
- }
- return S_OK;
-}
-
-QVideoFrame::PixelFormat MFTransform::formatFromSubtype(const GUID& subtype)
-{
- if (subtype == MFVideoFormat_ARGB32)
- return QVideoFrame::Format_ARGB32;
- else if (subtype == MFVideoFormat_RGB32)
- return QVideoFrame::Format_RGB32;
- else if (subtype == MFVideoFormat_RGB24)
- return QVideoFrame::Format_RGB24;
- else if (subtype == MFVideoFormat_RGB565)
- return QVideoFrame::Format_RGB565;
- else if (subtype == MFVideoFormat_RGB555)
- return QVideoFrame::Format_RGB555;
- else if (subtype == MFVideoFormat_AYUV)
- return QVideoFrame::Format_AYUV444;
- else if (subtype == MFVideoFormat_I420)
- return QVideoFrame::Format_YUV420P;
- else if (subtype == MFVideoFormat_UYVY)
- return QVideoFrame::Format_UYVY;
- else if (subtype == MFVideoFormat_YV12)
- return QVideoFrame::Format_YV12;
- else if (subtype == MFVideoFormat_NV12)
- return QVideoFrame::Format_NV12;
-
- return QVideoFrame::Format_Invalid;
-}
-
-QVideoSurfaceFormat MFTransform::videoFormatForMFMediaType(IMFMediaType *mediaType, int *bytesPerLine)
-{
- UINT32 stride;
- if (FAILED(mediaType->GetUINT32(MF_MT_DEFAULT_STRIDE, &stride))) {
- *bytesPerLine = 0;
- return QVideoSurfaceFormat();
- }
-
- *bytesPerLine = (int)stride;
-
- QSize size;
- UINT32 width, height;
- if (FAILED(MFGetAttributeSize(mediaType, MF_MT_FRAME_SIZE, &width, &height)))
- return QVideoSurfaceFormat();
-
- size.setWidth(width);
- size.setHeight(height);
-
- GUID subtype = GUID_NULL;
- if (FAILED(mediaType->GetGUID(MF_MT_SUBTYPE, &subtype)))
- return QVideoSurfaceFormat();
-
- QVideoFrame::PixelFormat pixelFormat = formatFromSubtype(subtype);
- QVideoSurfaceFormat format(size, pixelFormat);
-
- UINT32 num, den;
- if (SUCCEEDED(MFGetAttributeRatio(mediaType, MF_MT_PIXEL_ASPECT_RATIO, &num, &den))) {
- format.setPixelAspectRatio(num, den);
- }
- if (SUCCEEDED(MFGetAttributeRatio(mediaType, MF_MT_FRAME_RATE, &num, &den))) {
- format.setFrameRate(qreal(num)/den);
- }
-
- return format;
-}
-
-QVideoFrame MFTransform::makeVideoFrame()
-{
- QVideoFrame frame;
-
- if (!m_format.isValid())
- return frame;
-
- IMFMediaBuffer *buffer = 0;
-
- do {
- if (FAILED(m_sample->ConvertToContiguousBuffer(&buffer)))
- break;
-
- QByteArray array = dataFromBuffer(buffer, m_format.frameHeight(), &m_bytesPerLine);
- if (array.isEmpty())
- break;
-
- // Wrapping IMFSample or IMFMediaBuffer in a QVideoFrame is not possible because we cannot hold
- // IMFSample for a "long" time without affecting the rest of the topology.
- // If IMFSample is held for more than 5 frames decoder starts to reuse it even though it hasn't been released it yet.
- // That is why we copy data from IMFMediaBuffer here.
- frame = QVideoFrame(new QMemoryVideoBuffer(array, m_bytesPerLine), m_format.frameSize(), m_format.pixelFormat());
-
- // WMF uses 100-nanosecond units, Qt uses microseconds
- LONGLONG startTime = -1;
- if (SUCCEEDED(m_sample->GetSampleTime(&startTime))) {
- frame.setStartTime(startTime * 0.1);
-
- LONGLONG duration = -1;
- if (SUCCEEDED(m_sample->GetSampleDuration(&duration)))
- frame.setEndTime((startTime + duration) * 0.1);
- }
- } while (false);
-
- if (buffer)
- buffer->Release();
-
- return frame;
-}
-
-QByteArray MFTransform::dataFromBuffer(IMFMediaBuffer *buffer, int height, int *bytesPerLine)
-{
- QByteArray array;
- BYTE *bytes;
- DWORD length;
- HRESULT hr = buffer->Lock(&bytes, NULL, &length);
- if (SUCCEEDED(hr)) {
- array = QByteArray((const char *)bytes, (int)length);
- buffer->Unlock();
- } else {
- // try to lock as Direct3DSurface
- IDirect3DSurface9 *surface = 0;
- do {
- if (FAILED(MFGetService(buffer, MR_BUFFER_SERVICE, IID_IDirect3DSurface9, (void**)&surface)))
- break;
-
- D3DLOCKED_RECT rect;
- if (FAILED(surface->LockRect(&rect, NULL, D3DLOCK_READONLY)))
- break;
-
- if (bytesPerLine)
- *bytesPerLine = (int)rect.Pitch;
-
- array = QByteArray((const char *)rect.pBits, rect.Pitch * height);
- surface->UnlockRect();
- } while (false);
-
- if (surface) {
- surface->Release();
- surface = 0;
- }
- }
-
- return array;
-}
-
-bool MFTransform::isMediaTypeSupported(IMFMediaType *type)
-{
- // If we don't have the video sink's type handler,
- // assume it supports anything...
- if (!m_videoSinkTypeHandler || !type)
- return true;
-
- return m_videoSinkTypeHandler->IsMediaTypeSupported(type, NULL) == S_OK;
-}
diff --git a/src/plugins/wmf/player/mftvideo.h b/src/plugins/wmf/player/mftvideo.h
deleted file mode 100644
index ffcb80b32..000000000
--- a/src/plugins/wmf/player/mftvideo.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFTRANSFORM_H
-#define MFTRANSFORM_H
-
-#include <mfapi.h>
-#include <mfidl.h>
-#include <QtCore/qlist.h>
-#include <QtCore/qmutex.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
-
-QT_USE_NAMESPACE
-
-class MFVideoProbeControl;
-
-class MFTransform: public IMFTransform
-{
-public:
- MFTransform();
- ~MFTransform();
-
- void addProbe(MFVideoProbeControl* probe);
- void removeProbe(MFVideoProbeControl* probe);
-
- void setVideoSink(IUnknown *videoSink);
-
- // IUnknown methods
- STDMETHODIMP QueryInterface(REFIID iid, void** ppv);
- STDMETHODIMP_(ULONG) AddRef();
- STDMETHODIMP_(ULONG) Release();
-
- // IMFTransform methods
- STDMETHODIMP GetStreamLimits(DWORD *pdwInputMinimum, DWORD *pdwInputMaximum, DWORD *pdwOutputMinimum, DWORD *pdwOutputMaximum);
- STDMETHODIMP GetStreamCount(DWORD *pcInputStreams, DWORD *pcOutputStreams);
- STDMETHODIMP GetStreamIDs(DWORD dwInputIDArraySize, DWORD *pdwInputIDs, DWORD dwOutputIDArraySize, DWORD *pdwOutputIDs);
- STDMETHODIMP GetInputStreamInfo(DWORD dwInputStreamID, MFT_INPUT_STREAM_INFO *pStreamInfo);
- STDMETHODIMP GetOutputStreamInfo(DWORD dwOutputStreamID, MFT_OUTPUT_STREAM_INFO *pStreamInfo);
- STDMETHODIMP GetAttributes(IMFAttributes **pAttributes);
- STDMETHODIMP GetInputStreamAttributes(DWORD dwInputStreamID, IMFAttributes **pAttributes);
- STDMETHODIMP GetOutputStreamAttributes(DWORD dwOutputStreamID, IMFAttributes **pAttributes);
- STDMETHODIMP DeleteInputStream(DWORD dwStreamID);
- STDMETHODIMP AddInputStreams(DWORD cStreams, DWORD *adwStreamIDs);
- STDMETHODIMP GetInputAvailableType(DWORD dwInputStreamID, DWORD dwTypeIndex, IMFMediaType **ppType);
- STDMETHODIMP GetOutputAvailableType(DWORD dwOutputStreamID,DWORD dwTypeIndex, IMFMediaType **ppType);
- STDMETHODIMP SetInputType(DWORD dwInputStreamID, IMFMediaType *pType, DWORD dwFlags);
- STDMETHODIMP SetOutputType(DWORD dwOutputStreamID, IMFMediaType *pType, DWORD dwFlags);
- STDMETHODIMP GetInputCurrentType(DWORD dwInputStreamID, IMFMediaType **ppType);
- STDMETHODIMP GetOutputCurrentType(DWORD dwOutputStreamID, IMFMediaType **ppType);
- STDMETHODIMP GetInputStatus(DWORD dwInputStreamID, DWORD *pdwFlags);
- STDMETHODIMP GetOutputStatus(DWORD *pdwFlags);
- STDMETHODIMP SetOutputBounds(LONGLONG hnsLowerBound, LONGLONG hnsUpperBound);
- STDMETHODIMP ProcessEvent(DWORD dwInputStreamID, IMFMediaEvent *pEvent);
- STDMETHODIMP ProcessMessage(MFT_MESSAGE_TYPE eMessage, ULONG_PTR ulParam);
- STDMETHODIMP ProcessInput(DWORD dwInputStreamID, IMFSample *pSample, DWORD dwFlags);
- STDMETHODIMP ProcessOutput(DWORD dwFlags, DWORD cOutputBufferCount, MFT_OUTPUT_DATA_BUFFER *pOutputSamples, DWORD *pdwStatus);
-
-private:
- HRESULT OnFlush();
- static QVideoFrame::PixelFormat formatFromSubtype(const GUID& subtype);
- static QVideoSurfaceFormat videoFormatForMFMediaType(IMFMediaType *mediaType, int *bytesPerLine);
- QVideoFrame makeVideoFrame();
- QByteArray dataFromBuffer(IMFMediaBuffer *buffer, int height, int *bytesPerLine);
- bool isMediaTypeSupported(IMFMediaType *type);
-
- long m_cRef;
- IMFMediaType *m_inputType;
- IMFMediaType *m_outputType;
- IMFSample *m_sample;
- QMutex m_mutex;
-
- IMFMediaTypeHandler *m_videoSinkTypeHandler;
-
- QList<MFVideoProbeControl*> m_videoProbes;
- QMutex m_videoProbeMutex;
-
- QVideoSurfaceFormat m_format;
- int m_bytesPerLine;
-};
-
-#endif
diff --git a/src/plugins/wmf/player/mfvideoprobecontrol.cpp b/src/plugins/wmf/player/mfvideoprobecontrol.cpp
deleted file mode 100644
index 13d9a1bfe..000000000
--- a/src/plugins/wmf/player/mfvideoprobecontrol.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mfvideoprobecontrol.h"
-
-MFVideoProbeControl::MFVideoProbeControl(QObject *parent)
- : QMediaVideoProbeControl(parent)
-{
-}
-
-MFVideoProbeControl::~MFVideoProbeControl()
-{
-}
-
-void MFVideoProbeControl::bufferProbed(const QVideoFrame& frame)
-{
- QMetaObject::invokeMethod(this, "videoFrameProbed", Qt::QueuedConnection, Q_ARG(QVideoFrame, frame));
-}
diff --git a/src/plugins/wmf/player/mfvideoprobecontrol.h b/src/plugins/wmf/player/mfvideoprobecontrol.h
deleted file mode 100644
index 2b238725a..000000000
--- a/src/plugins/wmf/player/mfvideoprobecontrol.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFVIDEOPROBECONTROL_H
-#define MFVIDEOPROBECONTROL_H
-
-#include <qmediavideoprobecontrol.h>
-#include <QtCore/qmutex.h>
-#include <qvideoframe.h>
-
-QT_USE_NAMESPACE
-
-class MFVideoProbeControl : public QMediaVideoProbeControl
-{
- Q_OBJECT
-public:
- explicit MFVideoProbeControl(QObject *parent);
- virtual ~MFVideoProbeControl();
-
- void bufferProbed(const QVideoFrame& frame);
-};
-
-#endif
diff --git a/src/plugins/wmf/player/mfvideorenderercontrol.cpp b/src/plugins/wmf/player/mfvideorenderercontrol.cpp
deleted file mode 100644
index 7b121255f..000000000
--- a/src/plugins/wmf/player/mfvideorenderercontrol.cpp
+++ /dev/null
@@ -1,2426 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mfvideorenderercontrol.h"
-#include "mfactivate.h"
-
-#include "evrcustompresenter.h"
-
-#include <qabstractvideosurface.h>
-#include <qvideosurfaceformat.h>
-#include <qtcore/qtimer.h>
-#include <qtcore/qmutex.h>
-#include <qtcore/qcoreevent.h>
-#include <qtcore/qcoreapplication.h>
-#include <qtcore/qthread.h>
-#include "guiddef.h"
-#include <qtcore/qdebug.h>
-
-//#define DEBUG_MEDIAFOUNDATION
-#define PAD_TO_DWORD(x) (((x) + 3) & ~3)
-
-namespace
-{
- class MediaSampleVideoBuffer : public QAbstractVideoBuffer
- {
- public:
- MediaSampleVideoBuffer(IMFMediaBuffer *buffer, int bytesPerLine)
- : QAbstractVideoBuffer(NoHandle)
- , m_buffer(buffer)
- , m_bytesPerLine(bytesPerLine)
- , m_mapMode(NotMapped)
- {
- buffer->AddRef();
- }
-
- ~MediaSampleVideoBuffer()
- {
- m_buffer->Release();
- }
-
- uchar *map(MapMode mode, int *numBytes, int *bytesPerLine)
- {
- if (m_mapMode == NotMapped && mode != NotMapped) {
- BYTE *bytes;
- DWORD length;
- HRESULT hr = m_buffer->Lock(&bytes, NULL, &length);
- if (SUCCEEDED(hr)) {
- if (numBytes)
- *numBytes = int(length);
-
- if (bytesPerLine)
- *bytesPerLine = m_bytesPerLine;
-
- m_mapMode = mode;
- return reinterpret_cast<uchar *>(bytes);
- } else {
- qWarning("Faild to lock mf buffer!");
- }
- }
- return 0;
- }
-
- void unmap()
- {
- if (m_mapMode == NotMapped)
- return;
- m_mapMode = NotMapped;
- m_buffer->Unlock();
- }
-
- MapMode mapMode() const
- {
- return m_mapMode;
- }
-
- private:
- IMFMediaBuffer *m_buffer;
- int m_bytesPerLine;
- MapMode m_mapMode;
- };
-
- // Custom interface for handling IMFStreamSink::PlaceMarker calls asynchronously.
- MIDL_INTERFACE("a3ff32de-1031-438a-8b47-82f8acda59b7")
- IMarker : public IUnknown
- {
- virtual STDMETHODIMP GetMarkerType(MFSTREAMSINK_MARKER_TYPE *pType) = 0;
- virtual STDMETHODIMP GetMarkerValue(PROPVARIANT *pvar) = 0;
- virtual STDMETHODIMP GetContext(PROPVARIANT *pvar) = 0;
- };
-
- class Marker : public IMarker
- {
- public:
- static HRESULT Create(
- MFSTREAMSINK_MARKER_TYPE eMarkerType,
- const PROPVARIANT* pvarMarkerValue, // Can be NULL.
- const PROPVARIANT* pvarContextValue, // Can be NULL.
- IMarker **ppMarker)
- {
- if (ppMarker == NULL)
- return E_POINTER;
-
- HRESULT hr = S_OK;
- Marker *pMarker = new Marker(eMarkerType);
- if (pMarker == NULL)
- hr = E_OUTOFMEMORY;
-
- // Copy the marker data.
- if (SUCCEEDED(hr) && pvarMarkerValue)
- hr = PropVariantCopy(&pMarker->m_varMarkerValue, pvarMarkerValue);
-
- if (SUCCEEDED(hr) && pvarContextValue)
- hr = PropVariantCopy(&pMarker->m_varContextValue, pvarContextValue);
-
- if (SUCCEEDED(hr)) {
- *ppMarker = pMarker;
- (*ppMarker)->AddRef();
- }
-
- if (pMarker)
- pMarker->Release();
-
- return hr;
- }
-
- // IUnknown methods.
- STDMETHODIMP QueryInterface(REFIID iid, void** ppv)
- {
- if (!ppv)
- return E_POINTER;
- if (iid == IID_IUnknown) {
- *ppv = static_cast<IUnknown*>(this);
- } else if (iid == __uuidof(IMarker)) {
- *ppv = static_cast<IMarker*>(this);
- } else {
- *ppv = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
- }
-
- STDMETHODIMP_(ULONG) AddRef()
- {
- return InterlockedIncrement(&m_cRef);
- }
-
- STDMETHODIMP_(ULONG) Release()
- {
- LONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0)
- delete this;
- // For thread safety, return a temporary variable.
- return cRef;
- }
-
- STDMETHODIMP GetMarkerType(MFSTREAMSINK_MARKER_TYPE *pType)
- {
- if (pType == NULL)
- return E_POINTER;
- *pType = m_eMarkerType;
- return S_OK;
- }
-
- STDMETHODIMP GetMarkerValue(PROPVARIANT *pvar)
- {
- if (pvar == NULL)
- return E_POINTER;
- return PropVariantCopy(pvar, &m_varMarkerValue);
- }
-
- STDMETHODIMP GetContext(PROPVARIANT *pvar)
- {
- if (pvar == NULL)
- return E_POINTER;
- return PropVariantCopy(pvar, &m_varContextValue);
- }
-
- protected:
- MFSTREAMSINK_MARKER_TYPE m_eMarkerType;
- PROPVARIANT m_varMarkerValue;
- PROPVARIANT m_varContextValue;
-
- private:
- long m_cRef;
-
- Marker(MFSTREAMSINK_MARKER_TYPE eMarkerType) : m_cRef(1), m_eMarkerType(eMarkerType)
- {
- PropVariantInit(&m_varMarkerValue);
- PropVariantInit(&m_varContextValue);
- }
-
- virtual ~Marker()
- {
- PropVariantClear(&m_varMarkerValue);
- PropVariantClear(&m_varContextValue);
- }
- };
-
- class MediaStream : public QObject, public IMFStreamSink, public IMFMediaTypeHandler
- {
- Q_OBJECT
- friend class MFVideoRendererControl;
- public:
- static const DWORD DEFAULT_MEDIA_STREAM_ID = 0x0;
-
- MediaStream(IMFMediaSink *parent, MFVideoRendererControl *rendererControl)
- : m_cRef(1)
- , m_eventQueue(0)
- , m_shutdown(false)
- , m_surface(0)
- , m_state(State_TypeNotSet)
- , m_currentFormatIndex(-1)
- , m_bytesPerLine(0)
- , m_workQueueId(0)
- , m_workQueueCB(this, &MediaStream::onDispatchWorkItem)
- , m_finalizeResult(0)
- , m_scheduledBuffer(0)
- , m_bufferStartTime(-1)
- , m_bufferDuration(-1)
- , m_presentationClock(0)
- , m_sampleRequested(false)
- , m_currentMediaType(0)
- , m_prerolling(false)
- , m_prerollTargetTime(0)
- , m_startTime(0)
- , m_rendererControl(rendererControl)
- , m_rate(1.f)
- {
- m_sink = parent;
-
- if (FAILED(MFCreateEventQueue(&m_eventQueue)))
- qWarning("Failed to create mf event queue!");
- if (FAILED(MFAllocateWorkQueue(&m_workQueueId)))
- qWarning("Failed to allocated mf work queue!");
- }
-
- ~MediaStream()
- {
- Q_ASSERT(m_shutdown);
- }
-
- //from IUnknown
- STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject)
- {
- if (!ppvObject)
- return E_POINTER;
- if (riid == IID_IMFStreamSink) {
- *ppvObject = static_cast<IMFStreamSink*>(this);
- } else if (riid == IID_IMFMediaEventGenerator) {
- *ppvObject = static_cast<IMFMediaEventGenerator*>(this);
- } else if (riid == IID_IMFMediaTypeHandler) {
- *ppvObject = static_cast<IMFMediaTypeHandler*>(this);
- } else if (riid == IID_IUnknown) {
- *ppvObject = static_cast<IUnknown*>(static_cast<IMFStreamSink*>(this));
- } else {
- *ppvObject = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
- }
-
- STDMETHODIMP_(ULONG) AddRef(void)
- {
- return InterlockedIncrement(&m_cRef);
- }
-
- STDMETHODIMP_(ULONG) Release(void)
- {
- LONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0)
- delete this;
- // For thread safety, return a temporary variable.
- return cRef;
- }
-
- //from IMFMediaEventGenerator
- STDMETHODIMP GetEvent(
- DWORD dwFlags,
- IMFMediaEvent **ppEvent)
- {
- // GetEvent can block indefinitely, so we don't hold the lock.
- // This requires some juggling with the event queue pointer.
- HRESULT hr = S_OK;
- IMFMediaEventQueue *queue = NULL;
-
- m_mutex.lock();
- if (m_shutdown)
- hr = MF_E_SHUTDOWN;
- if (SUCCEEDED(hr)) {
- queue = m_eventQueue;
- queue->AddRef();
- }
- m_mutex.unlock();
-
- // Now get the event.
- if (SUCCEEDED(hr)) {
- hr = queue->GetEvent(dwFlags, ppEvent);
- queue->Release();
- }
-
- return hr;
- }
-
- STDMETHODIMP BeginGetEvent(
- IMFAsyncCallback *pCallback,
- IUnknown *punkState)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- return m_eventQueue->BeginGetEvent(pCallback, punkState);
- }
-
- STDMETHODIMP EndGetEvent(
- IMFAsyncResult *pResult,
- IMFMediaEvent **ppEvent)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- return m_eventQueue->EndGetEvent(pResult, ppEvent);
- }
-
- STDMETHODIMP QueueEvent(
- MediaEventType met,
- REFGUID guidExtendedType,
- HRESULT hrStatus,
- const PROPVARIANT *pvValue)
- {
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MediaStream::QueueEvent" << met;
-#endif
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- return m_eventQueue->QueueEventParamVar(met, guidExtendedType, hrStatus, pvValue);
- }
-
- //from IMFStreamSink
- STDMETHODIMP GetMediaSink(
- IMFMediaSink **ppMediaSink)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- else if (!ppMediaSink)
- return E_INVALIDARG;
-
- m_sink->AddRef();
- *ppMediaSink = m_sink;
- return S_OK;
- }
-
- STDMETHODIMP GetIdentifier(
- DWORD *pdwIdentifier)
- {
- *pdwIdentifier = MediaStream::DEFAULT_MEDIA_STREAM_ID;
- return S_OK;
- }
-
- STDMETHODIMP GetMediaTypeHandler(
- IMFMediaTypeHandler **ppHandler)
- {
- LPVOID handler = NULL;
- HRESULT hr = QueryInterface(IID_IMFMediaTypeHandler, &handler);
- *ppHandler = (IMFMediaTypeHandler*)(handler);
- return hr;
- }
-
- STDMETHODIMP ProcessSample(
- IMFSample *pSample)
- {
- if (pSample == NULL)
- return E_INVALIDARG;
- HRESULT hr = S_OK;
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
-
- if (!m_prerolling) {
- hr = validateOperation(OpProcessSample);
- if (FAILED(hr))
- return hr;
- }
-
- pSample->AddRef();
- m_sampleQueue.push_back(pSample);
-
- // Unless we are paused, start an async operation to dispatch the next sample.
- if (m_state != State_Paused)
- hr = queueAsyncOperation(OpProcessSample);
-
- return hr;
- }
-
- STDMETHODIMP PlaceMarker(
- MFSTREAMSINK_MARKER_TYPE eMarkerType,
- const PROPVARIANT *pvarMarkerValue,
- const PROPVARIANT *pvarContextValue)
- {
- HRESULT hr = S_OK;
- QMutexLocker locker(&m_mutex);
- IMarker *pMarker = NULL;
- if (m_shutdown)
- return MF_E_SHUTDOWN;
-
- hr = validateOperation(OpPlaceMarker);
- if (FAILED(hr))
- return hr;
-
- // Create a marker object and put it on the sample queue.
- hr = Marker::Create(eMarkerType, pvarMarkerValue, pvarContextValue, &pMarker);
- if (FAILED(hr))
- return hr;
-
- m_sampleQueue.push_back(pMarker);
-
- // Unless we are paused, start an async operation to dispatch the next sample/marker.
- if (m_state != State_Paused)
- hr = queueAsyncOperation(OpPlaceMarker); // Increments ref count on pOp.
- return hr;
- }
-
- STDMETHODIMP Flush( void)
- {
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MediaStream::Flush";
-#endif
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- // Note: Even though we are flushing data, we still need to send
- // any marker events that were queued.
- clearBufferCache();
- return processSamplesFromQueue(DropSamples);
- }
-
- //from IMFMediaTypeHandler
- STDMETHODIMP IsMediaTypeSupported(
- IMFMediaType *pMediaType,
- IMFMediaType **ppMediaType)
- {
- if (ppMediaType)
- *ppMediaType = NULL;
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
-
- int index = getMediaTypeIndex(pMediaType);
- if (index < 0) {
- if (ppMediaType && m_mediaTypes.size() > 0) {
- *ppMediaType = m_mediaTypes[0];
- (*ppMediaType)->AddRef();
- }
- return MF_E_INVALIDMEDIATYPE;
- }
-
- BOOL compressed = TRUE;
- pMediaType->IsCompressedFormat(&compressed);
- if (compressed) {
- if (ppMediaType && (SUCCEEDED(MFCreateMediaType(ppMediaType)))) {
- (*ppMediaType)->CopyAllItems(pMediaType);
- (*ppMediaType)->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE);
- (*ppMediaType)->SetUINT32(MF_MT_COMPRESSED, FALSE);
- (*ppMediaType)->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
- }
- return MF_E_INVALIDMEDIATYPE;
- }
-
- return S_OK;
- }
-
- STDMETHODIMP GetMediaTypeCount(
- DWORD *pdwTypeCount)
- {
- if (pdwTypeCount == NULL)
- return E_INVALIDARG;
- QMutexLocker locker(&m_mutex);
- *pdwTypeCount = DWORD(m_mediaTypes.size());
- return S_OK;
- }
-
- STDMETHODIMP GetMediaTypeByIndex(
- DWORD dwIndex,
- IMFMediaType **ppType)
- {
- if (ppType == NULL)
- return E_INVALIDARG;
- HRESULT hr = S_OK;
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- hr = MF_E_SHUTDOWN;
-
- if (SUCCEEDED(hr)) {
- if (dwIndex >= DWORD(m_mediaTypes.size()))
- hr = MF_E_NO_MORE_TYPES;
- }
-
- if (SUCCEEDED(hr)) {
- *ppType = m_mediaTypes[dwIndex];
- (*ppType)->AddRef();
- }
- return hr;
- }
-
- STDMETHODIMP SetCurrentMediaType(
- IMFMediaType *pMediaType)
- {
- HRESULT hr = S_OK;
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
-
- DWORD flag = MF_MEDIATYPE_EQUAL_MAJOR_TYPES |
- MF_MEDIATYPE_EQUAL_FORMAT_TYPES |
- MF_MEDIATYPE_EQUAL_FORMAT_DATA;
-
- if (m_currentMediaType && (m_currentMediaType->IsEqual(pMediaType, &flag) == S_OK))
- return S_OK;
-
- hr = validateOperation(OpSetMediaType);
-
- if (SUCCEEDED(hr)) {
- int index = getMediaTypeIndex(pMediaType);
- if (index >= 0) {
- UINT64 size;
- hr = pMediaType->GetUINT64(MF_MT_FRAME_SIZE, &size);
- if (SUCCEEDED(hr)) {
- m_currentFormatIndex = index;
- int width = int(HI32(size));
- int height = int(LO32(size));
- QVideoSurfaceFormat format(QSize(width, height), m_pixelFormats[index]);
- m_surfaceFormat = format;
-
- MFVideoArea viewport;
- if (SUCCEEDED(pMediaType->GetBlob(MF_MT_GEOMETRIC_APERTURE,
- reinterpret_cast<UINT8*>(&viewport),
- sizeof(MFVideoArea),
- NULL))) {
-
- m_surfaceFormat.setViewport(QRect(viewport.OffsetX.value,
- viewport.OffsetY.value,
- viewport.Area.cx,
- viewport.Area.cy));
- }
-
- if (FAILED(pMediaType->GetUINT32(MF_MT_DEFAULT_STRIDE, (UINT32*)&m_bytesPerLine))) {
- m_bytesPerLine = getBytesPerLine(format);
- }
-
- m_state = State_Ready;
- if (m_currentMediaType)
- m_currentMediaType->Release();
- m_currentMediaType = pMediaType;
- pMediaType->AddRef();
- }
- } else {
- hr = MF_E_INVALIDREQUEST;
- }
- }
- return hr;
- }
-
- STDMETHODIMP GetCurrentMediaType(
- IMFMediaType **ppMediaType)
- {
- if (ppMediaType == NULL)
- return E_INVALIDARG;
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- if (m_currentFormatIndex < 0)
- return MF_E_NOT_INITIALIZED;
- *ppMediaType = m_currentMediaType;
- (*ppMediaType)->AddRef();
- return S_OK;
- }
-
- STDMETHODIMP GetMajorType(
- GUID *pguidMajorType)
- {
- if (pguidMajorType == NULL)
- return E_INVALIDARG;
- *pguidMajorType = MFMediaType_Video;
- return S_OK;
- }
-
- //
- void setSurface(QAbstractVideoSurface *surface)
- {
- m_mutex.lock();
- m_surface = surface;
- m_mutex.unlock();
- supportedFormatsChanged();
- }
-
- void setClock(IMFPresentationClock *presentationClock)
- {
- QMutexLocker locker(&m_mutex);
- if (!m_shutdown) {
- if (m_presentationClock)
- m_presentationClock->Release();
- m_presentationClock = presentationClock;
- if (m_presentationClock)
- m_presentationClock->AddRef();
- }
- }
-
- void shutdown()
- {
- QMutexLocker locker(&m_mutex);
- Q_ASSERT(!m_shutdown);
-
- if (m_currentMediaType) {
- m_currentMediaType->Release();
- m_currentMediaType = NULL;
- m_currentFormatIndex = -1;
- }
-
- if (m_eventQueue)
- m_eventQueue->Shutdown();
-
- MFUnlockWorkQueue(m_workQueueId);
-
- if (m_presentationClock) {
- m_presentationClock->Release();
- m_presentationClock = NULL;
- }
-
- clearMediaTypes();
- clearSampleQueue();
- clearBufferCache();
-
- if (m_eventQueue) {
- m_eventQueue->Release();
- m_eventQueue = NULL;
- }
-
- m_shutdown = true;
- }
-
- HRESULT startPreroll(MFTIME hnsUpcomingStartTime)
- {
- QMutexLocker locker(&m_mutex);
- HRESULT hr = validateOperation(OpPreroll);
- if (SUCCEEDED(hr)) {
- m_state = State_Prerolling;
- m_prerollTargetTime = hnsUpcomingStartTime;
- hr = queueAsyncOperation(OpPreroll);
- }
- return hr;
- }
-
- HRESULT finalize(IMFAsyncCallback *pCallback, IUnknown *punkState)
- {
- QMutexLocker locker(&m_mutex);
- HRESULT hr = S_OK;
- hr = validateOperation(OpFinalize);
- if (SUCCEEDED(hr) && m_finalizeResult != NULL)
- hr = MF_E_INVALIDREQUEST; // The operation is already pending.
-
- // Create and store the async result object.
- if (SUCCEEDED(hr))
- hr = MFCreateAsyncResult(NULL, pCallback, punkState, &m_finalizeResult);
-
- if (SUCCEEDED(hr)) {
- m_state = State_Finalized;
- hr = queueAsyncOperation(OpFinalize);
- }
- return hr;
- }
-
- HRESULT start(MFTIME start)
- {
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MediaStream::start" << start;
-#endif
- HRESULT hr = S_OK;
- QMutexLocker locker(&m_mutex);
- if (m_rate != 0)
- hr = validateOperation(OpStart);
-
- if (SUCCEEDED(hr)) {
- MFTIME sysTime;
- if (start != PRESENTATION_CURRENT_POSITION)
- m_startTime = start; // Cache the start time.
- else
- m_presentationClock->GetCorrelatedTime(0, &m_startTime, &sysTime);
- m_state = State_Started;
- hr = queueAsyncOperation(OpStart);
- }
- return hr;
- }
-
- HRESULT restart()
- {
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MediaStream::restart";
-#endif
- QMutexLocker locker(&m_mutex);
- HRESULT hr = validateOperation(OpRestart);
- if (SUCCEEDED(hr)) {
- m_state = State_Started;
- hr = queueAsyncOperation(OpRestart);
- }
- return hr;
- }
-
- HRESULT stop()
- {
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MediaStream::stop";
-#endif
- QMutexLocker locker(&m_mutex);
- HRESULT hr = validateOperation(OpStop);
- if (SUCCEEDED(hr)) {
- m_state = State_Stopped;
- hr = queueAsyncOperation(OpStop);
- }
- return hr;
- }
-
- HRESULT pause()
- {
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MediaStream::pause";
-#endif
- QMutexLocker locker(&m_mutex);
- HRESULT hr = validateOperation(OpPause);
- if (SUCCEEDED(hr)) {
- m_state = State_Paused;
- hr = queueAsyncOperation(OpPause);
- }
- return hr;
- }
-
- HRESULT setRate(float rate)
- {
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "MediaStream::setRate" << rate;
-#endif
- QMutexLocker locker(&m_mutex);
- HRESULT hr = validateOperation(OpSetRate);
- if (SUCCEEDED(hr)) {
- m_rate = rate;
- hr = queueAsyncOperation(OpSetRate);
- }
- return hr;
- }
-
- void supportedFormatsChanged()
- {
- QMutexLocker locker(&m_mutex);
- m_pixelFormats.clear();
- clearMediaTypes();
- if (!m_surface)
- return;
- const QList<QVideoFrame::PixelFormat> formats = m_surface->supportedPixelFormats();
- for (QVideoFrame::PixelFormat format : formats) {
- IMFMediaType *mediaType;
- if (FAILED(MFCreateMediaType(&mediaType))) {
- qWarning("Failed to create mf media type!");
- continue;
- }
- mediaType->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE);
- mediaType->SetUINT32(MF_MT_COMPRESSED, FALSE);
- mediaType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
- mediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
- switch (format) {
- case QVideoFrame::Format_ARGB32:
- case QVideoFrame::Format_ARGB32_Premultiplied:
- mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_ARGB32);
- break;
- case QVideoFrame::Format_RGB32:
- mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32);
- break;
- case QVideoFrame::Format_BGR24: // MFVideoFormat_RGB24 has a BGR layout
- mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB24);
- break;
- case QVideoFrame::Format_RGB565:
- mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB565);
- break;
- case QVideoFrame::Format_RGB555:
- mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB555);
- break;
- case QVideoFrame::Format_AYUV444:
- case QVideoFrame::Format_AYUV444_Premultiplied:
- mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_AYUV);
- break;
- case QVideoFrame::Format_YUV420P:
- mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_I420);
- break;
- case QVideoFrame::Format_UYVY:
- mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_UYVY);
- break;
- case QVideoFrame::Format_YV12:
- mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_YV12);
- break;
- case QVideoFrame::Format_NV12:
- mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12);
- break;
- default:
- mediaType->Release();
- continue;
- }
- // QAbstractVideoSurface::supportedPixelFormats() returns formats in descending
- // order of preference, while IMFMediaTypeHandler is supposed to return supported
- // formats in ascending order of preference. We need to reverse the list.
- m_pixelFormats.prepend(format);
- m_mediaTypes.prepend(mediaType);
- }
- }
-
- void present()
- {
- QMutexLocker locker(&m_mutex);
- if (!m_scheduledBuffer)
- return;
- QVideoFrame frame = QVideoFrame(
- new MediaSampleVideoBuffer(m_scheduledBuffer, m_bytesPerLine),
- m_surfaceFormat.frameSize(),
- m_surfaceFormat.pixelFormat());
- frame.setStartTime(m_bufferStartTime * 0.1);
- frame.setEndTime((m_bufferStartTime + m_bufferDuration) * 0.1);
- m_surface->present(frame);
- m_scheduledBuffer->Release();
- m_scheduledBuffer = NULL;
- if (m_rate != 0)
- schedulePresentation(true);
- }
-
- void clearScheduledFrame()
- {
- QMutexLocker locker(&m_mutex);
- if (m_scheduledBuffer) {
- m_scheduledBuffer->Release();
- m_scheduledBuffer = NULL;
- schedulePresentation(true);
- }
- }
-
- enum
- {
- StartSurface = QEvent::User,
- StopSurface,
- FlushSurface,
- PresentSurface
- };
-
- class PresentEvent : public QEvent
- {
- public:
- PresentEvent(MFTIME targetTime)
- : QEvent(QEvent::Type(PresentSurface))
- , m_time(targetTime)
- {
- }
-
- MFTIME targetTime()
- {
- return m_time;
- }
-
- private:
- MFTIME m_time;
- };
-
- protected:
- void customEvent(QEvent *event)
- {
- QMutexLocker locker(&m_mutex);
- if (event->type() == StartSurface) {
- if (m_state == State_WaitForSurfaceStart) {
- m_startResult = startSurface();
- queueAsyncOperation(OpStart);
- }
- } else if (event->type() == StopSurface) {
- stopSurface();
- } else {
- QObject::customEvent(event);
- }
- }
- HRESULT m_startResult;
-
- private:
- HRESULT startSurface()
- {
- if (!m_surface->isFormatSupported(m_surfaceFormat))
- return S_FALSE;
- if (!m_surface->start(m_surfaceFormat))
- return S_FALSE;
- return S_OK;
- }
-
- void stopSurface()
- {
- m_surface->stop();
- }
-
- enum FlushState
- {
- DropSamples = 0,
- WriteSamples
- };
-
- // State enum: Defines the current state of the stream.
- enum State
- {
- State_TypeNotSet = 0, // No media type is set
- State_Ready, // Media type is set, Start has never been called.
- State_Prerolling,
- State_Started,
- State_Paused,
- State_Stopped,
- State_WaitForSurfaceStart,
- State_Finalized,
- State_Count = State_Finalized + 1 // Number of states
- };
-
- // StreamOperation: Defines various operations that can be performed on the stream.
- enum StreamOperation
- {
- OpSetMediaType = 0,
- OpStart,
- OpPreroll,
- OpRestart,
- OpPause,
- OpStop,
- OpSetRate,
- OpProcessSample,
- OpPlaceMarker,
- OpFinalize,
-
- Op_Count = OpFinalize + 1 // Number of operations
- };
-
- // AsyncOperation:
- // Used to queue asynchronous operations. When we call MFPutWorkItem, we use this
- // object for the callback state (pState). Then, when the callback is invoked,
- // we can use the object to determine which asynchronous operation to perform.
- class AsyncOperation : public IUnknown
- {
- public:
- AsyncOperation(StreamOperation op)
- :m_cRef(1), m_op(op)
- {
- }
-
- StreamOperation m_op; // The operation to perform.
-
- //from IUnknown
- STDMETHODIMP QueryInterface(REFIID iid, void** ppv)
- {
- if (!ppv)
- return E_POINTER;
- if (iid == IID_IUnknown) {
- *ppv = static_cast<IUnknown*>(this);
- } else {
- *ppv = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
- }
- STDMETHODIMP_(ULONG) AddRef()
- {
- return InterlockedIncrement(&m_cRef);
- }
- STDMETHODIMP_(ULONG) Release()
- {
- ULONG uCount = InterlockedDecrement(&m_cRef);
- if (uCount == 0)
- delete this;
- // For thread safety, return a temporary variable.
- return uCount;
- }
-
- private:
- long m_cRef;
- virtual ~AsyncOperation()
- {
- Q_ASSERT(m_cRef == 0);
- }
- };
-
- // ValidStateMatrix: Defines a look-up table that says which operations
- // are valid from which states.
- static BOOL ValidStateMatrix[State_Count][Op_Count];
-
- long m_cRef;
- QMutex m_mutex;
-
- IMFMediaType *m_currentMediaType;
- State m_state;
- IMFMediaSink *m_sink;
- IMFMediaEventQueue *m_eventQueue;
- DWORD m_workQueueId;
- AsyncCallback<MediaStream> m_workQueueCB;
- QList<IUnknown*> m_sampleQueue;
- IMFAsyncResult *m_finalizeResult; // Result object for Finalize operation.
- MFTIME m_startTime; // Presentation time when the clock started.
-
- bool m_shutdown;
- QList<IMFMediaType*> m_mediaTypes;
- QList<QVideoFrame::PixelFormat> m_pixelFormats;
- int m_currentFormatIndex;
- int m_bytesPerLine;
- QVideoSurfaceFormat m_surfaceFormat;
- QAbstractVideoSurface* m_surface;
- MFVideoRendererControl *m_rendererControl;
-
- void clearMediaTypes()
- {
- for (IMFMediaType* mediaType : qAsConst(m_mediaTypes))
- mediaType->Release();
- m_mediaTypes.clear();
- }
-
- int getMediaTypeIndex(IMFMediaType *mt)
- {
- GUID majorType;
- if (FAILED(mt->GetMajorType(&majorType)))
- return -1;
- if (majorType != MFMediaType_Video)
- return -1;
-
- GUID subType;
- if (FAILED(mt->GetGUID(MF_MT_SUBTYPE, &subType)))
- return -1;
-
- for (int index = 0; index < m_mediaTypes.size(); ++index) {
- GUID st;
- m_mediaTypes[index]->GetGUID(MF_MT_SUBTYPE, &st);
- if (st == subType)
- return index;
- }
- return -1;
- }
-
- int getBytesPerLine(const QVideoSurfaceFormat &format)
- {
- switch (format.pixelFormat()) {
- // 32 bpp packed formats.
- case QVideoFrame::Format_RGB32:
- case QVideoFrame::Format_AYUV444:
- return format.frameWidth() * 4;
- // 24 bpp packed formats.
- case QVideoFrame::Format_RGB24:
- case QVideoFrame::Format_BGR24:
- return PAD_TO_DWORD(format.frameWidth() * 3);
- // 16 bpp packed formats.
- case QVideoFrame::Format_RGB565:
- case QVideoFrame::Format_RGB555:
- case QVideoFrame::Format_YUYV:
- case QVideoFrame::Format_UYVY:
- return PAD_TO_DWORD(format.frameWidth() * 2);
- // Planar formats.
- case QVideoFrame::Format_IMC1:
- case QVideoFrame::Format_IMC2:
- case QVideoFrame::Format_IMC3:
- case QVideoFrame::Format_IMC4:
- case QVideoFrame::Format_YV12:
- case QVideoFrame::Format_NV12:
- case QVideoFrame::Format_YUV420P:
- return PAD_TO_DWORD(format.frameWidth());
- default:
- return 0;
- }
- }
-
- // Callback for MFPutWorkItem.
- HRESULT onDispatchWorkItem(IMFAsyncResult* pAsyncResult)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
-
- HRESULT hr = S_OK;
- IUnknown *pState = NULL;
- hr = pAsyncResult->GetState(&pState);
- if (SUCCEEDED(hr)) {
- // The state object is an AsncOperation object.
- AsyncOperation *pOp = (AsyncOperation*)pState;
- StreamOperation op = pOp->m_op;
- switch (op) {
- case OpStart:
- endPreroll(S_FALSE);
- if (m_state == State_WaitForSurfaceStart) {
- hr = m_startResult;
- m_state = State_Started;
- } else if (!m_surface->isActive()) {
- if (thread() == QThread::currentThread()) {
- hr = startSurface();
- }
- else {
- m_state = State_WaitForSurfaceStart;
- QCoreApplication::postEvent(m_rendererControl, new QChildEvent(QEvent::Type(StartSurface), this));
- break;
- }
- }
-
- if (m_state == State_Started)
- schedulePresentation(true);
- case OpRestart:
- endPreroll(S_FALSE);
- if (SUCCEEDED(hr)) {
- // Send MEStreamSinkStarted.
- hr = queueEvent(MEStreamSinkStarted, GUID_NULL, hr, NULL);
- // Kick things off by requesting samples...
- schedulePresentation(true);
- // There might be samples queue from earlier (ie, while paused).
- if (SUCCEEDED(hr))
- hr = processSamplesFromQueue(WriteSamples);
- }
- break;
- case OpPreroll:
- beginPreroll();
- break;
- case OpStop:
- // Drop samples from queue.
- hr = processSamplesFromQueue(DropSamples);
- clearBufferCache();
- // Send the event even if the previous call failed.
- hr = queueEvent(MEStreamSinkStopped, GUID_NULL, hr, NULL);
- if (m_surface->isActive()) {
- if (thread() == QThread::currentThread()) {
- stopSurface();
- }
- else {
- QCoreApplication::postEvent(m_rendererControl, new QChildEvent(QEvent::Type(StopSurface), this));
- }
- }
- break;
- case OpPause:
- hr = queueEvent(MEStreamSinkPaused, GUID_NULL, hr, NULL);
- break;
- case OpSetRate:
- hr = queueEvent(MEStreamSinkRateChanged, GUID_NULL, S_OK, NULL);
- break;
- case OpProcessSample:
- case OpPlaceMarker:
- hr = dispatchProcessSample(pOp);
- break;
- case OpFinalize:
- endPreroll(S_FALSE);
- hr = dispatchFinalize(pOp);
- break;
- }
- }
-
- if (pState)
- pState->Release();
- return hr;
- }
-
-
- HRESULT queueEvent(MediaEventType met, REFGUID guidExtendedType, HRESULT hrStatus, const PROPVARIANT* pvValue)
- {
- HRESULT hr = S_OK;
- if (m_shutdown)
- hr = MF_E_SHUTDOWN;
- if (SUCCEEDED(hr))
- hr = m_eventQueue->QueueEventParamVar(met, guidExtendedType, hrStatus, pvValue);
- return hr;
- }
-
- HRESULT validateOperation(StreamOperation op)
- {
- Q_ASSERT(!m_shutdown);
- if (ValidStateMatrix[m_state][op])
- return S_OK;
- else
- return MF_E_INVALIDREQUEST;
- }
-
- HRESULT queueAsyncOperation(StreamOperation op)
- {
- HRESULT hr = S_OK;
- AsyncOperation *asyncOp = new AsyncOperation(op);
- if (asyncOp == NULL)
- hr = E_OUTOFMEMORY;
-
- if (SUCCEEDED(hr))
- hr = MFPutWorkItem(m_workQueueId, &m_workQueueCB, asyncOp);
-
- if (asyncOp)
- asyncOp->Release();
-
- return hr;
- }
-
- HRESULT processSamplesFromQueue(FlushState bFlushData)
- {
- HRESULT hr = S_OK;
- QList<IUnknown*>::Iterator pos = m_sampleQueue.begin();
- // Enumerate all of the samples/markers in the queue.
- while (pos != m_sampleQueue.end()) {
- IUnknown *pUnk = NULL;
- IMarker *pMarker = NULL;
- IMFSample *pSample = NULL;
- pUnk = *pos;
- // Figure out if this is a marker or a sample.
- if (SUCCEEDED(hr)) {
- hr = pUnk->QueryInterface(__uuidof(IMarker), (void**)&pMarker);
- if (hr == E_NOINTERFACE)
- hr = pUnk->QueryInterface(IID_IMFSample, (void**)&pSample);
- }
-
- // Now handle the sample/marker appropriately.
- if (SUCCEEDED(hr)) {
- if (pMarker) {
- hr = sendMarkerEvent(pMarker, bFlushData);
- } else {
- Q_ASSERT(pSample != NULL); // Not a marker, must be a sample
- if (bFlushData == WriteSamples)
- hr = processSampleData(pSample);
- }
- }
- if (pMarker)
- pMarker->Release();
- if (pSample)
- pSample->Release();
-
- if (FAILED(hr))
- break;
-
- pos++;
- }
-
- clearSampleQueue();
- return hr;
- }
-
- void beginPreroll()
- {
- if (m_prerolling)
- return;
- m_prerolling = true;
- clearSampleQueue();
- clearBufferCache();
- queueEvent(MEStreamSinkRequestSample, GUID_NULL, S_OK, NULL);
- }
-
- void endPreroll(HRESULT hrStatus)
- {
- if (!m_prerolling)
- return;
- m_prerolling = false;
- queueEvent(MEStreamSinkPrerolled, GUID_NULL, hrStatus, NULL);
- }
- MFTIME m_prerollTargetTime;
- bool m_prerolling;
-
- void clearSampleQueue() {
- for (IUnknown* sample : qAsConst(m_sampleQueue))
- sample->Release();
- m_sampleQueue.clear();
- }
-
- HRESULT sendMarkerEvent(IMarker *pMarker, FlushState FlushState)
- {
- HRESULT hr = S_OK;
- HRESULT hrStatus = S_OK; // Status code for marker event.
- if (FlushState == DropSamples)
- hrStatus = E_ABORT;
-
- PROPVARIANT var;
- PropVariantInit(&var);
-
- // Get the context data.
- hr = pMarker->GetContext(&var);
-
- if (SUCCEEDED(hr))
- hr = queueEvent(MEStreamSinkMarker, GUID_NULL, hrStatus, &var);
-
- PropVariantClear(&var);
- return hr;
- }
-
- HRESULT dispatchProcessSample(AsyncOperation* pOp)
- {
- HRESULT hr = S_OK;
- Q_ASSERT(pOp != NULL);
- Q_UNUSED(pOp);
- hr = processSamplesFromQueue(WriteSamples);
- // We are in the middle of an asynchronous operation, so if something failed, send an error.
- if (FAILED(hr))
- hr = queueEvent(MEError, GUID_NULL, hr, NULL);
-
- return hr;
- }
-
- HRESULT dispatchFinalize(AsyncOperation*)
- {
- HRESULT hr = S_OK;
- // Write any samples left in the queue...
- hr = processSamplesFromQueue(WriteSamples);
-
- // Set the async status and invoke the callback.
- m_finalizeResult->SetStatus(hr);
- hr = MFInvokeCallback(m_finalizeResult);
- return hr;
- }
-
- HRESULT processSampleData(IMFSample *pSample)
- {
- m_sampleRequested = false;
-
- LONGLONG time, duration = -1;
- HRESULT hr = pSample->GetSampleTime(&time);
- if (SUCCEEDED(hr))
- pSample->GetSampleDuration(&duration);
-
- if (m_prerolling) {
- if (SUCCEEDED(hr) && ((time - m_prerollTargetTime) * m_rate) >= 0) {
- IMFMediaBuffer *pBuffer = NULL;
- hr = pSample->ConvertToContiguousBuffer(&pBuffer);
- if (SUCCEEDED(hr)) {
- SampleBuffer sb;
- sb.m_buffer = pBuffer;
- sb.m_time = time;
- sb.m_duration = duration;
- m_bufferCache.push_back(sb);
- endPreroll(S_OK);
- }
- } else {
- queueEvent(MEStreamSinkRequestSample, GUID_NULL, S_OK, NULL);
- }
- } else {
- bool requestSample = true;
- // If the time stamp is too early, just discard this sample.
- if (SUCCEEDED(hr) && ((time - m_startTime) * m_rate) >= 0) {
- IMFMediaBuffer *pBuffer = NULL;
- hr = pSample->ConvertToContiguousBuffer(&pBuffer);
- if (SUCCEEDED(hr)) {
- SampleBuffer sb;
- sb.m_buffer = pBuffer;
- sb.m_time = time;
- sb.m_duration = duration;
- m_bufferCache.push_back(sb);
- }
- if (m_rate == 0)
- requestSample = false;
- }
- schedulePresentation(requestSample);
- }
- return hr;
- }
-
- class SampleBuffer
- {
- public:
- IMFMediaBuffer *m_buffer;
- LONGLONG m_time;
- LONGLONG m_duration;
- };
- QList<SampleBuffer> m_bufferCache;
- static const int BUFFER_CACHE_SIZE = 2;
-
- void clearBufferCache()
- {
- for (SampleBuffer sb : qAsConst(m_bufferCache))
- sb.m_buffer->Release();
- m_bufferCache.clear();
-
- if (m_scheduledBuffer) {
- m_scheduledBuffer->Release();
- m_scheduledBuffer = NULL;
- }
- }
-
- void schedulePresentation(bool requestSample)
- {
- if (m_state == State_Paused || m_state == State_Prerolling)
- return;
- if (!m_scheduledBuffer) {
- //get time from presentation time
- MFTIME currentTime = m_startTime, sysTime;
- bool timeOK = true;
- if (m_rate != 0) {
- if (FAILED(m_presentationClock->GetCorrelatedTime(0, &currentTime, &sysTime)))
- timeOK = false;
- }
- while (!m_bufferCache.isEmpty()) {
- SampleBuffer sb = m_bufferCache.takeFirst();
- if (timeOK && ((sb.m_time - currentTime) * m_rate) < 0) {
- sb.m_buffer->Release();
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "currentPresentTime =" << float(currentTime / 10000) * 0.001f << " and sampleTime is" << float(sb.m_time / 10000) * 0.001f;
-#endif
- continue;
- }
- m_scheduledBuffer = sb.m_buffer;
- m_bufferStartTime = sb.m_time;
- m_bufferDuration = sb.m_duration;
- QCoreApplication::postEvent(m_rendererControl, new PresentEvent(sb.m_time));
- if (m_rate == 0)
- queueEvent(MEStreamSinkScrubSampleComplete, GUID_NULL, S_OK, NULL);
- break;
- }
- }
- if (requestSample && !m_sampleRequested && m_bufferCache.size() < BUFFER_CACHE_SIZE) {
- m_sampleRequested = true;
- queueEvent(MEStreamSinkRequestSample, GUID_NULL, S_OK, NULL);
- }
- }
- IMFMediaBuffer *m_scheduledBuffer;
- MFTIME m_bufferStartTime;
- MFTIME m_bufferDuration;
- IMFPresentationClock *m_presentationClock;
- bool m_sampleRequested;
- float m_rate;
- };
-
- BOOL MediaStream::ValidStateMatrix[MediaStream::State_Count][MediaStream::Op_Count] =
- {
- // States: Operations:
- // SetType Start Preroll, Restart Pause Stop SetRate Sample Marker Finalize
- /* NotSet */ TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
-
- /* Ready */ TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE,
-
- /* Prerolling */ TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
-
- /* Start */ FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
-
- /* Pause */ FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
-
- /* Stop */ FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE,
-
- /*WaitForSurfaceStart*/ FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE,
-
- /* Final */ FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
-
- // Note about states:
- // 1. OnClockRestart should only be called from paused state.
- // 2. While paused, the sink accepts samples but does not process them.
- };
-
- class MediaSink : public IMFFinalizableMediaSink,
- public IMFClockStateSink,
- public IMFMediaSinkPreroll,
- public IMFGetService,
- public IMFRateSupport
- {
- public:
- MediaSink(MFVideoRendererControl *rendererControl)
- : m_cRef(1)
- , m_shutdown(false)
- , m_presentationClock(0)
- , m_playRate(1)
- {
- m_stream = new MediaStream(this, rendererControl);
- }
-
- ~MediaSink()
- {
- Q_ASSERT(m_shutdown);
- }
-
- void setSurface(QAbstractVideoSurface *surface)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return;
- m_stream->setSurface(surface);
- }
-
- void supportedFormatsChanged()
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return;
- m_stream->supportedFormatsChanged();
- }
-
- void present()
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return;
- m_stream->present();
- }
-
- void clearScheduledFrame()
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return;
- m_stream->clearScheduledFrame();
- }
-
- MFTIME getTime()
- {
- QMutexLocker locker(&m_mutex);
- if (!m_presentationClock)
- return 0;
- MFTIME time, sysTime;
- m_presentationClock->GetCorrelatedTime(0, &time, &sysTime);
- return time;
- }
-
- float getPlayRate()
- {
- QMutexLocker locker(&m_mutex);
- return m_playRate;
- }
-
- //from IUnknown
- STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject)
- {
- if (!ppvObject)
- return E_POINTER;
- if (riid == IID_IMFMediaSink) {
- *ppvObject = static_cast<IMFMediaSink*>(this);
- } else if (riid == IID_IMFGetService) {
- *ppvObject = static_cast<IMFGetService*>(this);
- } else if (riid == IID_IMFMediaSinkPreroll) {
- *ppvObject = static_cast<IMFMediaSinkPreroll*>(this);
- } else if (riid == IID_IMFClockStateSink) {
- *ppvObject = static_cast<IMFClockStateSink*>(this);
- } else if (riid == IID_IMFRateSupport) {
- *ppvObject = static_cast<IMFRateSupport*>(this);
- } else if (riid == IID_IUnknown) {
- *ppvObject = static_cast<IUnknown*>(static_cast<IMFFinalizableMediaSink*>(this));
- } else {
- *ppvObject = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
- }
-
- STDMETHODIMP_(ULONG) AddRef(void)
- {
- return InterlockedIncrement(&m_cRef);
- }
-
- STDMETHODIMP_(ULONG) Release(void)
- {
- LONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0)
- delete this;
- // For thread safety, return a temporary variable.
- return cRef;
- }
-
- // IMFGetService methods
- STDMETHODIMP GetService(const GUID &guidService,
- const IID &riid,
- LPVOID *ppvObject)
- {
- if (!ppvObject)
- return E_POINTER;
-
- if (guidService != MF_RATE_CONTROL_SERVICE)
- return MF_E_UNSUPPORTED_SERVICE;
-
- return QueryInterface(riid, ppvObject);
- }
-
- //IMFMediaSinkPreroll
- STDMETHODIMP NotifyPreroll(MFTIME hnsUpcomingStartTime)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- return m_stream->startPreroll(hnsUpcomingStartTime);
- }
-
- //from IMFFinalizableMediaSink
- STDMETHODIMP BeginFinalize(IMFAsyncCallback *pCallback, IUnknown *punkState)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- return m_stream->finalize(pCallback, punkState);
- }
-
- STDMETHODIMP EndFinalize(IMFAsyncResult *pResult)
- {
- HRESULT hr = S_OK;
- // Return the status code from the async result.
- if (pResult == NULL)
- hr = E_INVALIDARG;
- else
- hr = pResult->GetStatus();
- return hr;
- }
-
- //from IMFMediaSink
- STDMETHODIMP GetCharacteristics(
- DWORD *pdwCharacteristics)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- *pdwCharacteristics = MEDIASINK_FIXED_STREAMS | MEDIASINK_CAN_PREROLL;
- return S_OK;
- }
-
- STDMETHODIMP AddStreamSink(
- DWORD,
- IMFMediaType *,
- IMFStreamSink **)
- {
- QMutexLocker locker(&m_mutex);
- return m_shutdown ? MF_E_SHUTDOWN : MF_E_STREAMSINKS_FIXED;
- }
-
- STDMETHODIMP RemoveStreamSink(
- DWORD)
- {
- QMutexLocker locker(&m_mutex);
- return m_shutdown ? MF_E_SHUTDOWN : MF_E_STREAMSINKS_FIXED;
- }
-
- STDMETHODIMP GetStreamSinkCount(
- DWORD *pcStreamSinkCount)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- *pcStreamSinkCount = 1;
- return S_OK;
- }
-
- STDMETHODIMP GetStreamSinkByIndex(
- DWORD dwIndex,
- IMFStreamSink **ppStreamSink)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
-
- if (dwIndex != 0)
- return MF_E_INVALIDINDEX;
-
- *ppStreamSink = m_stream;
- m_stream->AddRef();
- return S_OK;
- }
-
- STDMETHODIMP GetStreamSinkById(
- DWORD dwStreamSinkIdentifier,
- IMFStreamSink **ppStreamSink)
- {
- if (ppStreamSink == NULL)
- return E_INVALIDARG;
- if (dwStreamSinkIdentifier != MediaStream::DEFAULT_MEDIA_STREAM_ID)
- return MF_E_INVALIDSTREAMNUMBER;
-
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
-
- *ppStreamSink = m_stream;
- m_stream->AddRef();
- return S_OK;
- }
-
- STDMETHODIMP SetPresentationClock(
- IMFPresentationClock *pPresentationClock)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
-
- if (m_presentationClock) {
- m_presentationClock->RemoveClockStateSink(this);
- m_presentationClock->Release();
- }
- m_presentationClock = pPresentationClock;
- if (m_presentationClock) {
- m_presentationClock->AddRef();
- m_presentationClock->AddClockStateSink(this);
- }
- m_stream->setClock(m_presentationClock);
- return S_OK;
- }
-
- STDMETHODIMP GetPresentationClock(
- IMFPresentationClock **ppPresentationClock)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- *ppPresentationClock = m_presentationClock;
- if (m_presentationClock) {
- m_presentationClock->AddRef();
- return S_OK;
- }
- return MF_E_NO_CLOCK;
- }
-
- STDMETHODIMP Shutdown(void)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
-
- m_stream->shutdown();
- if (m_presentationClock) {
- m_presentationClock->Release();
- m_presentationClock = NULL;
- }
- m_stream->Release();
- m_stream = NULL;
- m_shutdown = true;
- return S_OK;
- }
-
- // IMFClockStateSink methods
- STDMETHODIMP OnClockStart(MFTIME, LONGLONG llClockStartOffset)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- return m_stream->start(llClockStartOffset);
- }
-
- STDMETHODIMP OnClockStop(MFTIME)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- return m_stream->stop();
- }
-
- STDMETHODIMP OnClockPause(MFTIME)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- return m_stream->pause();
- }
-
- STDMETHODIMP OnClockRestart(MFTIME)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- return m_stream->restart();
- }
-
- STDMETHODIMP OnClockSetRate(MFTIME, float flRate)
- {
- QMutexLocker locker(&m_mutex);
- if (m_shutdown)
- return MF_E_SHUTDOWN;
- m_playRate = flRate;
- return m_stream->setRate(flRate);
- }
-
- // IMFRateSupport methods
- STDMETHODIMP GetFastestRate(MFRATE_DIRECTION eDirection,
- BOOL fThin,
- float *pflRate)
- {
- if (!pflRate)
- return E_POINTER;
-
- *pflRate = (fThin ? 8.f : 2.0f) * (eDirection == MFRATE_FORWARD ? 1 : -1) ;
-
- return S_OK;
- }
-
- STDMETHODIMP GetSlowestRate(MFRATE_DIRECTION eDirection,
- BOOL fThin,
- float *pflRate)
- {
- Q_UNUSED(eDirection);
- Q_UNUSED(fThin);
-
- if (!pflRate)
- return E_POINTER;
-
- // we support any rate
- *pflRate = 0.f;
-
- return S_OK;
- }
-
- STDMETHODIMP IsRateSupported(BOOL fThin,
- float flRate,
- float *pflNearestSupportedRate)
- {
- HRESULT hr = S_OK;
-
- if (!qFuzzyIsNull(flRate)) {
- MFRATE_DIRECTION direction = flRate > 0.f ? MFRATE_FORWARD
- : MFRATE_REVERSE;
-
- float fastestRate = 0.f;
- float slowestRate = 0.f;
- GetFastestRate(direction, fThin, &fastestRate);
- GetSlowestRate(direction, fThin, &slowestRate);
-
- if (direction == MFRATE_REVERSE)
- qSwap(fastestRate, slowestRate);
-
- if (flRate < slowestRate || flRate > fastestRate) {
- hr = MF_E_UNSUPPORTED_RATE;
- if (pflNearestSupportedRate) {
- *pflNearestSupportedRate = qBound(slowestRate,
- flRate,
- fastestRate);
- }
- }
- } else if (pflNearestSupportedRate) {
- *pflNearestSupportedRate = flRate;
- }
-
- return hr;
- }
-
- private:
- long m_cRef;
- QMutex m_mutex;
- bool m_shutdown;
- IMFPresentationClock *m_presentationClock;
- MediaStream *m_stream;
- float m_playRate;
- };
-
- class VideoRendererActivate : public IMFActivate
- {
- public:
- VideoRendererActivate(MFVideoRendererControl *rendererControl)
- : m_cRef(1)
- , m_sink(0)
- , m_rendererControl(rendererControl)
- , m_attributes(0)
- , m_surface(0)
- {
- MFCreateAttributes(&m_attributes, 0);
- m_sink = new MediaSink(rendererControl);
- }
-
- ~VideoRendererActivate()
- {
- m_attributes->Release();
- }
-
- //from IUnknown
- STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject)
- {
- if (!ppvObject)
- return E_POINTER;
- if (riid == IID_IMFActivate) {
- *ppvObject = static_cast<IMFActivate*>(this);
- } else if (riid == IID_IMFAttributes) {
- *ppvObject = static_cast<IMFAttributes*>(this);
- } else if (riid == IID_IUnknown) {
- *ppvObject = static_cast<IUnknown*>(static_cast<IMFActivate*>(this));
- } else {
- *ppvObject = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
- }
-
- STDMETHODIMP_(ULONG) AddRef(void)
- {
- return InterlockedIncrement(&m_cRef);
- }
-
- STDMETHODIMP_(ULONG) Release(void)
- {
- LONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0)
- delete this;
- // For thread safety, return a temporary variable.
- return cRef;
- }
-
- //from IMFActivate
- STDMETHODIMP ActivateObject(REFIID riid, void **ppv)
- {
- if (!ppv)
- return E_INVALIDARG;
- QMutexLocker locker(&m_mutex);
- if (!m_sink) {
- m_sink = new MediaSink(m_rendererControl);
- if (m_surface)
- m_sink->setSurface(m_surface);
- }
- return m_sink->QueryInterface(riid, ppv);
- }
-
- STDMETHODIMP ShutdownObject(void)
- {
- QMutexLocker locker(&m_mutex);
- HRESULT hr = S_OK;
- if (m_sink) {
- hr = m_sink->Shutdown();
- m_sink->Release();
- m_sink = NULL;
- }
- return hr;
- }
-
- STDMETHODIMP DetachObject(void)
- {
- QMutexLocker locker(&m_mutex);
- if (m_sink) {
- m_sink->Release();
- m_sink = NULL;
- }
- return S_OK;
- }
-
- //from IMFAttributes
- STDMETHODIMP GetItem(
- REFGUID guidKey,
- PROPVARIANT *pValue)
- {
- return m_attributes->GetItem(guidKey, pValue);
- }
-
- STDMETHODIMP GetItemType(
- REFGUID guidKey,
- MF_ATTRIBUTE_TYPE *pType)
- {
- return m_attributes->GetItemType(guidKey, pType);
- }
-
- STDMETHODIMP CompareItem(
- REFGUID guidKey,
- REFPROPVARIANT Value,
- BOOL *pbResult)
- {
- return m_attributes->CompareItem(guidKey, Value, pbResult);
- }
-
- STDMETHODIMP Compare(
- IMFAttributes *pTheirs,
- MF_ATTRIBUTES_MATCH_TYPE MatchType,
- BOOL *pbResult)
- {
- return m_attributes->Compare(pTheirs, MatchType, pbResult);
- }
-
- STDMETHODIMP GetUINT32(
- REFGUID guidKey,
- UINT32 *punValue)
- {
- return m_attributes->GetUINT32(guidKey, punValue);
- }
-
- STDMETHODIMP GetUINT64(
- REFGUID guidKey,
- UINT64 *punValue)
- {
- return m_attributes->GetUINT64(guidKey, punValue);
- }
-
- STDMETHODIMP GetDouble(
- REFGUID guidKey,
- double *pfValue)
- {
- return m_attributes->GetDouble(guidKey, pfValue);
- }
-
- STDMETHODIMP GetGUID(
- REFGUID guidKey,
- GUID *pguidValue)
- {
- return m_attributes->GetGUID(guidKey, pguidValue);
- }
-
- STDMETHODIMP GetStringLength(
- REFGUID guidKey,
- UINT32 *pcchLength)
- {
- return m_attributes->GetStringLength(guidKey, pcchLength);
- }
-
- STDMETHODIMP GetString(
- REFGUID guidKey,
- LPWSTR pwszValue,
- UINT32 cchBufSize,
- UINT32 *pcchLength)
- {
- return m_attributes->GetString(guidKey, pwszValue, cchBufSize, pcchLength);
- }
-
- STDMETHODIMP GetAllocatedString(
- REFGUID guidKey,
- LPWSTR *ppwszValue,
- UINT32 *pcchLength)
- {
- return m_attributes->GetAllocatedString(guidKey, ppwszValue, pcchLength);
- }
-
- STDMETHODIMP GetBlobSize(
- REFGUID guidKey,
- UINT32 *pcbBlobSize)
- {
- return m_attributes->GetBlobSize(guidKey, pcbBlobSize);
- }
-
- STDMETHODIMP GetBlob(
- REFGUID guidKey,
- UINT8 *pBuf,
- UINT32 cbBufSize,
- UINT32 *pcbBlobSize)
- {
- return m_attributes->GetBlob(guidKey, pBuf, cbBufSize, pcbBlobSize);
- }
-
- STDMETHODIMP GetAllocatedBlob(
- REFGUID guidKey,
- UINT8 **ppBuf,
- UINT32 *pcbSize)
- {
- return m_attributes->GetAllocatedBlob(guidKey, ppBuf, pcbSize);
- }
-
- STDMETHODIMP GetUnknown(
- REFGUID guidKey,
- REFIID riid,
- LPVOID *ppv)
- {
- return m_attributes->GetUnknown(guidKey, riid, ppv);
- }
-
- STDMETHODIMP SetItem(
- REFGUID guidKey,
- REFPROPVARIANT Value)
- {
- return m_attributes->SetItem(guidKey, Value);
- }
-
- STDMETHODIMP DeleteItem(
- REFGUID guidKey)
- {
- return m_attributes->DeleteItem(guidKey);
- }
-
- STDMETHODIMP DeleteAllItems(void)
- {
- return m_attributes->DeleteAllItems();
- }
-
- STDMETHODIMP SetUINT32(
- REFGUID guidKey,
- UINT32 unValue)
- {
- return m_attributes->SetUINT32(guidKey, unValue);
- }
-
- STDMETHODIMP SetUINT64(
- REFGUID guidKey,
- UINT64 unValue)
- {
- return m_attributes->SetUINT64(guidKey, unValue);
- }
-
- STDMETHODIMP SetDouble(
- REFGUID guidKey,
- double fValue)
- {
- return m_attributes->SetDouble(guidKey, fValue);
- }
-
- STDMETHODIMP SetGUID(
- REFGUID guidKey,
- REFGUID guidValue)
- {
- return m_attributes->SetGUID(guidKey, guidValue);
- }
-
- STDMETHODIMP SetString(
- REFGUID guidKey,
- LPCWSTR wszValue)
- {
- return m_attributes->SetString(guidKey, wszValue);
- }
-
- STDMETHODIMP SetBlob(
- REFGUID guidKey,
- const UINT8 *pBuf,
- UINT32 cbBufSize)
- {
- return m_attributes->SetBlob(guidKey, pBuf, cbBufSize);
- }
-
- STDMETHODIMP SetUnknown(
- REFGUID guidKey,
- IUnknown *pUnknown)
- {
- return m_attributes->SetUnknown(guidKey, pUnknown);
- }
-
- STDMETHODIMP LockStore(void)
- {
- return m_attributes->LockStore();
- }
-
- STDMETHODIMP UnlockStore(void)
- {
- return m_attributes->UnlockStore();
- }
-
- STDMETHODIMP GetCount(
- UINT32 *pcItems)
- {
- return m_attributes->GetCount(pcItems);
- }
-
- STDMETHODIMP GetItemByIndex(
- UINT32 unIndex,
- GUID *pguidKey,
- PROPVARIANT *pValue)
- {
- return m_attributes->GetItemByIndex(unIndex, pguidKey, pValue);
- }
-
- STDMETHODIMP CopyAllItems(
- IMFAttributes *pDest)
- {
- return m_attributes->CopyAllItems(pDest);
- }
-
- /////////////////////////////////
- void setSurface(QAbstractVideoSurface *surface)
- {
- QMutexLocker locker(&m_mutex);
- if (m_surface == surface)
- return;
-
- m_surface = surface;
-
- if (!m_sink)
- return;
- m_sink->setSurface(m_surface);
- }
-
- void supportedFormatsChanged()
- {
- QMutexLocker locker(&m_mutex);
- if (!m_sink)
- return;
- m_sink->supportedFormatsChanged();
- }
-
- void present()
- {
- QMutexLocker locker(&m_mutex);
- if (!m_sink)
- return;
- m_sink->present();
- }
-
- void clearScheduledFrame()
- {
- QMutexLocker locker(&m_mutex);
- if (!m_sink)
- return;
- m_sink->clearScheduledFrame();
- }
-
- MFTIME getTime()
- {
- if (m_sink)
- return m_sink->getTime();
- return 0;
- }
-
- float getPlayRate()
- {
- if (m_sink)
- return m_sink->getPlayRate();
- return 1;
- }
-
- private:
- long m_cRef;
- bool m_shutdown;
- MediaSink *m_sink;
- MFVideoRendererControl *m_rendererControl;
- IMFAttributes *m_attributes;
- QAbstractVideoSurface *m_surface;
- QMutex m_mutex;
- };
-}
-
-
-class EVRCustomPresenterActivate : public MFAbstractActivate
-{
-public:
- EVRCustomPresenterActivate();
- ~EVRCustomPresenterActivate()
- { }
-
- STDMETHODIMP ActivateObject(REFIID riid, void **ppv);
- STDMETHODIMP ShutdownObject();
- STDMETHODIMP DetachObject();
-
- void setSurface(QAbstractVideoSurface *surface);
-
-private:
- EVRCustomPresenter *m_presenter;
- QAbstractVideoSurface *m_surface;
- QMutex m_mutex;
-};
-
-
-MFVideoRendererControl::MFVideoRendererControl(QObject *parent)
- : QVideoRendererControl(parent)
- , m_surface(0)
- , m_currentActivate(0)
- , m_callback(0)
- , m_presenterActivate(0)
-{
-}
-
-MFVideoRendererControl::~MFVideoRendererControl()
-{
- clear();
-}
-
-void MFVideoRendererControl::clear()
-{
- if (m_surface)
- m_surface->stop();
-
- if (m_presenterActivate) {
- m_presenterActivate->ShutdownObject();
- m_presenterActivate->Release();
- m_presenterActivate = NULL;
- }
-
- if (m_currentActivate) {
- m_currentActivate->ShutdownObject();
- m_currentActivate->Release();
- }
- m_currentActivate = NULL;
-}
-
-void MFVideoRendererControl::releaseActivate()
-{
- clear();
-}
-
-QAbstractVideoSurface *MFVideoRendererControl::surface() const
-{
- return m_surface;
-}
-
-void MFVideoRendererControl::setSurface(QAbstractVideoSurface *surface)
-{
- if (m_surface)
- disconnect(m_surface, SIGNAL(supportedFormatsChanged()), this, SLOT(supportedFormatsChanged()));
- m_surface = surface;
-
- if (m_surface) {
- connect(m_surface, SIGNAL(supportedFormatsChanged()), this, SLOT(supportedFormatsChanged()));
- }
-
- if (m_presenterActivate)
- m_presenterActivate->setSurface(m_surface);
- else if (m_currentActivate)
- static_cast<VideoRendererActivate*>(m_currentActivate)->setSurface(m_surface);
-}
-
-void MFVideoRendererControl::customEvent(QEvent *event)
-{
- if (m_presenterActivate)
- return;
-
- if (!m_currentActivate)
- return;
-
- if (event->type() == MediaStream::PresentSurface) {
- MFTIME targetTime = static_cast<MediaStream::PresentEvent*>(event)->targetTime();
- MFTIME currentTime = static_cast<VideoRendererActivate*>(m_currentActivate)->getTime();
- float playRate = static_cast<VideoRendererActivate*>(m_currentActivate)->getPlayRate();
- if (!qFuzzyIsNull(playRate) && targetTime != currentTime) {
- // If the scheduled frame is too late, skip it
- const int interval = ((targetTime - currentTime) / 10000) / playRate;
- if (interval < 0)
- static_cast<VideoRendererActivate*>(m_currentActivate)->clearScheduledFrame();
- else
- QTimer::singleShot(interval, this, SLOT(present()));
- } else {
- present();
- }
- return;
- }
- if (event->type() >= MediaStream::StartSurface) {
- QChildEvent *childEvent = static_cast<QChildEvent*>(event);
- static_cast<MediaStream*>(childEvent->child())->customEvent(event);
- } else {
- QObject::customEvent(event);
- }
-}
-
-void MFVideoRendererControl::supportedFormatsChanged()
-{
- if (m_presenterActivate)
- return;
-
- if (m_currentActivate)
- static_cast<VideoRendererActivate*>(m_currentActivate)->supportedFormatsChanged();
-}
-
-void MFVideoRendererControl::present()
-{
- if (m_presenterActivate)
- return;
-
- if (m_currentActivate)
- static_cast<VideoRendererActivate*>(m_currentActivate)->present();
-}
-
-IMFActivate* MFVideoRendererControl::createActivate()
-{
- Q_ASSERT(m_surface);
-
- clear();
-
- // Create the EVR media sink, but replace the presenter with our own
- if (SUCCEEDED(MFCreateVideoRendererActivate(::GetShellWindow(), &m_currentActivate))) {
- m_presenterActivate = new EVRCustomPresenterActivate;
- m_currentActivate->SetUnknown(MF_ACTIVATE_CUSTOM_VIDEO_PRESENTER_ACTIVATE, m_presenterActivate);
- } else {
- m_currentActivate = new VideoRendererActivate(this);
- }
-
- setSurface(m_surface);
-
- return m_currentActivate;
-}
-
-
-EVRCustomPresenterActivate::EVRCustomPresenterActivate()
- : MFAbstractActivate()
- , m_presenter(0)
- , m_surface(0)
-{ }
-
-HRESULT EVRCustomPresenterActivate::ActivateObject(REFIID riid, void **ppv)
-{
- if (!ppv)
- return E_INVALIDARG;
- QMutexLocker locker(&m_mutex);
- if (!m_presenter) {
- m_presenter = new EVRCustomPresenter;
- if (m_surface)
- m_presenter->setSurface(m_surface);
- }
- return m_presenter->QueryInterface(riid, ppv);
-}
-
-HRESULT EVRCustomPresenterActivate::ShutdownObject()
-{
- // The presenter does not implement IMFShutdown so
- // this function is the same as DetachObject()
- return DetachObject();
-}
-
-HRESULT EVRCustomPresenterActivate::DetachObject()
-{
- QMutexLocker locker(&m_mutex);
- if (m_presenter) {
- m_presenter->Release();
- m_presenter = 0;
- }
- return S_OK;
-}
-
-void EVRCustomPresenterActivate::setSurface(QAbstractVideoSurface *surface)
-{
- QMutexLocker locker(&m_mutex);
- if (m_surface == surface)
- return;
-
- m_surface = surface;
-
- if (m_presenter)
- m_presenter->setSurface(surface);
-}
-
-#include "moc_mfvideorenderercontrol.cpp"
-#include "mfvideorenderercontrol.moc"
diff --git a/src/plugins/wmf/player/mfvideorenderercontrol.h b/src/plugins/wmf/player/mfvideorenderercontrol.h
deleted file mode 100644
index da9e97ba9..000000000
--- a/src/plugins/wmf/player/mfvideorenderercontrol.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Mobility Components.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MFVIDEORENDERERCONTROL_H
-#define MFVIDEORENDERERCONTROL_H
-
-#include "qvideorenderercontrol.h"
-#include <mfapi.h>
-#include <mfidl.h>
-
-QT_USE_NAMESPACE
-
-class EVRCustomPresenterActivate;
-
-class MFVideoRendererControl : public QVideoRendererControl
-{
- Q_OBJECT
-public:
- MFVideoRendererControl(QObject *parent = 0);
- ~MFVideoRendererControl();
-
- QAbstractVideoSurface *surface() const;
- void setSurface(QAbstractVideoSurface *surface);
-
- IMFActivate* createActivate();
- void releaseActivate();
-
-protected:
- void customEvent(QEvent *event);
-
-private Q_SLOTS:
- void supportedFormatsChanged();
- void present();
-
-private:
- void clear();
-
- QAbstractVideoSurface *m_surface;
- IMFActivate *m_currentActivate;
- IMFSampleGrabberSinkCallback *m_callback;
-
- EVRCustomPresenterActivate *m_presenterActivate;
-};
-
-#endif
diff --git a/src/plugins/wmf/player/player.pri b/src/plugins/wmf/player/player.pri
deleted file mode 100644
index af2f7458b..000000000
--- a/src/plugins/wmf/player/player.pri
+++ /dev/null
@@ -1,34 +0,0 @@
-INCLUDEPATH += $$PWD
-
-LIBS += -lgdi32 -luser32
-QMAKE_USE += wmf
-
-HEADERS += \
- $$PWD/mfplayerservice.h \
- $$PWD/mfplayersession.h \
- $$PWD/mfplayercontrol.h \
- $$PWD/mfvideorenderercontrol.h \
- $$PWD/mfaudioendpointcontrol.h \
- $$PWD/mfmetadatacontrol.h \
- $$PWD/mfaudioprobecontrol.h \
- $$PWD/mfvideoprobecontrol.h \
- $$PWD/mfevrvideowindowcontrol.h \
- $$PWD/samplegrabber.h \
- $$PWD/mftvideo.h \
- $$PWD/mfactivate.h
-
-SOURCES += \
- $$PWD/mfplayerservice.cpp \
- $$PWD/mfplayersession.cpp \
- $$PWD/mfplayercontrol.cpp \
- $$PWD/mfvideorenderercontrol.cpp \
- $$PWD/mfaudioendpointcontrol.cpp \
- $$PWD/mfmetadatacontrol.cpp \
- $$PWD/mfaudioprobecontrol.cpp \
- $$PWD/mfvideoprobecontrol.cpp \
- $$PWD/mfevrvideowindowcontrol.cpp \
- $$PWD/samplegrabber.cpp \
- $$PWD/mftvideo.cpp \
- $$PWD/mfactivate.cpp
-
-include($$PWD/../../common/evr.pri)
diff --git a/src/plugins/wmf/player/samplegrabber.cpp b/src/plugins/wmf/player/samplegrabber.cpp
deleted file mode 100644
index d137335f3..000000000
--- a/src/plugins/wmf/player/samplegrabber.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "samplegrabber.h"
-#include "mfaudioprobecontrol.h"
-
-STDMETHODIMP SampleGrabberCallback::QueryInterface(REFIID riid, void** ppv)
-{
- if (!ppv)
- return E_POINTER;
- if (riid == IID_IMFSampleGrabberSinkCallback) {
- *ppv = static_cast<IMFSampleGrabberSinkCallback*>(this);
- } else if (riid == IID_IMFClockStateSink) {
- *ppv = static_cast<IMFClockStateSink*>(this);
- } else if (riid == IID_IUnknown) {
- *ppv = static_cast<IUnknown*>(this);
- } else {
- *ppv = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
-}
-
-STDMETHODIMP_(ULONG) SampleGrabberCallback::AddRef()
-{
- return InterlockedIncrement(&m_cRef);
-}
-
-STDMETHODIMP_(ULONG) SampleGrabberCallback::Release()
-{
- ULONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0) {
- delete this;
- }
- return cRef;
-
-}
-
-// IMFClockStateSink methods.
-
-STDMETHODIMP SampleGrabberCallback::OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset)
-{
- Q_UNUSED(hnsSystemTime);
- Q_UNUSED(llClockStartOffset);
- return S_OK;
-}
-
-STDMETHODIMP SampleGrabberCallback::OnClockStop(MFTIME hnsSystemTime)
-{
- Q_UNUSED(hnsSystemTime);
- return S_OK;
-}
-
-STDMETHODIMP SampleGrabberCallback::OnClockPause(MFTIME hnsSystemTime)
-{
- Q_UNUSED(hnsSystemTime);
- return S_OK;
-}
-
-STDMETHODIMP SampleGrabberCallback::OnClockRestart(MFTIME hnsSystemTime)
-{
- Q_UNUSED(hnsSystemTime);
- return S_OK;
-}
-
-STDMETHODIMP SampleGrabberCallback::OnClockSetRate(MFTIME hnsSystemTime, float flRate)
-{
- Q_UNUSED(hnsSystemTime);
- Q_UNUSED(flRate);
- return S_OK;
-}
-
-// IMFSampleGrabberSink methods.
-
-STDMETHODIMP SampleGrabberCallback::OnSetPresentationClock(IMFPresentationClock* pClock)
-{
- Q_UNUSED(pClock);
- return S_OK;
-}
-
-STDMETHODIMP SampleGrabberCallback::OnShutdown()
-{
- return S_OK;
-}
-
-void AudioSampleGrabberCallback::addProbe(MFAudioProbeControl* probe)
-{
- QMutexLocker locker(&m_audioProbeMutex);
-
- if (m_audioProbes.contains(probe))
- return;
-
- m_audioProbes.append(probe);
-}
-
-void AudioSampleGrabberCallback::removeProbe(MFAudioProbeControl* probe)
-{
- QMutexLocker locker(&m_audioProbeMutex);
- m_audioProbes.removeOne(probe);
-}
-
-void AudioSampleGrabberCallback::setFormat(const QAudioFormat& format)
-{
- m_format = format;
-}
-
-STDMETHODIMP AudioSampleGrabberCallback::OnProcessSample(REFGUID guidMajorMediaType, DWORD dwSampleFlags,
- LONGLONG llSampleTime, LONGLONG llSampleDuration, const BYTE * pSampleBuffer,
- DWORD dwSampleSize)
-{
- Q_UNUSED(dwSampleFlags);
- Q_UNUSED(llSampleTime);
- Q_UNUSED(llSampleDuration);
-
- if (guidMajorMediaType != GUID_NULL && guidMajorMediaType != MFMediaType_Audio)
- return S_OK;
-
- QMutexLocker locker(&m_audioProbeMutex);
-
- if (m_audioProbes.isEmpty())
- return S_OK;
-
- // Check if sample has a presentation time
- if (llSampleTime == _I64_MAX) {
- // Set default QAudioBuffer start time
- llSampleTime = -1;
- } else {
- // WMF uses 100-nanosecond units, Qt uses microseconds
- llSampleTime /= 10;
- }
-
- for (MFAudioProbeControl* probe : qAsConst(m_audioProbes))
- probe->bufferProbed((const char*)pSampleBuffer, dwSampleSize, m_format, llSampleTime);
-
- return S_OK;
-}
diff --git a/src/plugins/wmf/player/samplegrabber.h b/src/plugins/wmf/player/samplegrabber.h
deleted file mode 100644
index 9ca673a1b..000000000
--- a/src/plugins/wmf/player/samplegrabber.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef SAMPLEGRABBER_H
-#define SAMPLEGRABBER_H
-
-#include <QtCore/qmutex.h>
-#include <QtCore/qlist.h>
-#include <QtMultimedia/qaudioformat.h>
-#include <mfapi.h>
-#include <mfidl.h>
-
-class MFAudioProbeControl;
-
-class SampleGrabberCallback : public IMFSampleGrabberSinkCallback
-{
-public:
- // IUnknown methods
- STDMETHODIMP QueryInterface(REFIID iid, void** ppv);
- STDMETHODIMP_(ULONG) AddRef();
- STDMETHODIMP_(ULONG) Release();
-
- // IMFClockStateSink methods
- STDMETHODIMP OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset);
- STDMETHODIMP OnClockStop(MFTIME hnsSystemTime);
- STDMETHODIMP OnClockPause(MFTIME hnsSystemTime);
- STDMETHODIMP OnClockRestart(MFTIME hnsSystemTime);
- STDMETHODIMP OnClockSetRate(MFTIME hnsSystemTime, float flRate);
-
- // IMFSampleGrabberSinkCallback methods
- STDMETHODIMP OnSetPresentationClock(IMFPresentationClock* pClock);
- STDMETHODIMP OnShutdown();
-
-protected:
- SampleGrabberCallback() : m_cRef(1) {}
-
-public:
- virtual ~SampleGrabberCallback() {}
-
-private:
- long m_cRef;
-};
-
-class AudioSampleGrabberCallback: public SampleGrabberCallback {
-public:
- void addProbe(MFAudioProbeControl* probe);
- void removeProbe(MFAudioProbeControl* probe);
- void setFormat(const QAudioFormat& format);
-
- STDMETHODIMP OnProcessSample(REFGUID guidMajorMediaType, DWORD dwSampleFlags,
- LONGLONG llSampleTime, LONGLONG llSampleDuration, const BYTE * pSampleBuffer,
- DWORD dwSampleSize);
-
-private:
- QList<MFAudioProbeControl*> m_audioProbes;
- QMutex m_audioProbeMutex;
- QAudioFormat m_format;
-};
-
-#endif // SAMPLEGRABBER_H
diff --git a/src/plugins/wmf/sourceresolver.cpp b/src/plugins/wmf/sourceresolver.cpp
deleted file mode 100644
index 15ef6f0ab..000000000
--- a/src/plugins/wmf/sourceresolver.cpp
+++ /dev/null
@@ -1,325 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mfstream.h"
-#include "sourceresolver.h"
-#include <mferror.h>
-#include <nserror.h>
-#include <QtCore/qfile.h>
-#include <QtCore/qdebug.h>
-#include <QtMultimedia/qmediaplayer.h>
-
-/*
- SourceResolver is separated from MFPlayerSession to handle the work of resolving a media source
- asynchronously. You call SourceResolver::load to request resolving a media source asynchronously,
- and it will emit mediaSourceReady() when resolving is done. You can call SourceResolver::cancel to
- stop the previous load operation if there is any.
-*/
-
-SourceResolver::SourceResolver()
- : m_cRef(1)
- , m_cancelCookie(0)
- , m_sourceResolver(0)
- , m_mediaSource(0)
- , m_stream(0)
-{
-}
-
-SourceResolver::~SourceResolver()
-{
- shutdown();
- if (m_mediaSource) {
- m_mediaSource->Release();
- m_mediaSource = NULL;
- }
-
- if (m_cancelCookie)
- m_cancelCookie->Release();
- if (m_sourceResolver)
- m_sourceResolver->Release();
-}
-
-STDMETHODIMP SourceResolver::QueryInterface(REFIID riid, LPVOID *ppvObject)
-{
- if (!ppvObject)
- return E_POINTER;
- if (riid == IID_IUnknown) {
- *ppvObject = static_cast<IUnknown*>(this);
- } else if (riid == IID_IMFAsyncCallback) {
- *ppvObject = static_cast<IMFAsyncCallback*>(this);
- } else {
- *ppvObject = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
-}
-
-STDMETHODIMP_(ULONG) SourceResolver::AddRef(void)
-{
- return InterlockedIncrement(&m_cRef);
-}
-
-STDMETHODIMP_(ULONG) SourceResolver::Release(void)
-{
- LONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0)
- this->deleteLater();
- return cRef;
-}
-
-HRESULT STDMETHODCALLTYPE SourceResolver::Invoke(IMFAsyncResult *pAsyncResult)
-{
- QMutexLocker locker(&m_mutex);
-
- if (!m_sourceResolver)
- return S_OK;
-
- MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;
- IUnknown* pSource = NULL;
- State *state = static_cast<State*>(pAsyncResult->GetStateNoAddRef());
-
- HRESULT hr = S_OK;
- if (state->fromStream())
- hr = m_sourceResolver->EndCreateObjectFromByteStream(pAsyncResult, &ObjectType, &pSource);
- else
- hr = m_sourceResolver->EndCreateObjectFromURL(pAsyncResult, &ObjectType, &pSource);
-
- if (state->sourceResolver() != m_sourceResolver) {
- //This is a cancelled one
- return S_OK;
- }
-
- if (m_cancelCookie) {
- m_cancelCookie->Release();
- m_cancelCookie = NULL;
- }
-
- if (FAILED(hr)) {
- emit error(hr);
- return S_OK;
- }
-
- if (m_mediaSource) {
- m_mediaSource->Release();
- m_mediaSource = NULL;
- }
-
- hr = pSource->QueryInterface(IID_PPV_ARGS(&m_mediaSource));
- pSource->Release();
- if (FAILED(hr)) {
- emit error(hr);
- return S_OK;
- }
-
- emit mediaSourceReady();
-
- return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE SourceResolver::GetParameters(DWORD*, DWORD*)
-{
- return E_NOTIMPL;
-}
-
-void SourceResolver::load(const QUrl &url, QIODevice* stream)
-{
- QMutexLocker locker(&m_mutex);
- HRESULT hr = S_OK;
- if (!m_sourceResolver)
- hr = MFCreateSourceResolver(&m_sourceResolver);
-
- if (m_stream) {
- m_stream->Release();
- m_stream = NULL;
- }
-
- if (FAILED(hr)) {
- qWarning() << "Failed to create Source Resolver!";
- emit error(hr);
- } else if (stream) {
- QString urlString = url.toString();
- m_stream = new MFStream(stream, false);
- hr = m_sourceResolver->BeginCreateObjectFromByteStream(
- m_stream, urlString.isEmpty() ? 0 : reinterpret_cast<LPCWSTR>(urlString.utf16()),
- MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE
- , NULL, &m_cancelCookie, this, new State(m_sourceResolver, true));
- if (FAILED(hr)) {
- qWarning() << "Unsupported stream!";
- emit error(hr);
- }
- } else {
-#ifdef DEBUG_MEDIAFOUNDATION
- qDebug() << "loading :" << url;
- qDebug() << "url path =" << url.path().mid(1);
-#endif
-#ifdef TEST_STREAMING
- //Testing stream function
- if (url.scheme() == QLatin1String("file")) {
- stream = new QFile(url.path().mid(1));
- if (stream->open(QIODevice::ReadOnly)) {
- m_stream = new MFStream(stream, true);
- hr = m_sourceResolver->BeginCreateObjectFromByteStream(
- m_stream, reinterpret_cast<const OLECHAR *>(url.toString().utf16()),
- MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE,
- NULL, &m_cancelCookie, this, new State(m_sourceResolver, true));
- if (FAILED(hr)) {
- qWarning() << "Unsupported stream!";
- emit error(hr);
- }
- } else {
- delete stream;
- emit error(QMediaPlayer::FormatError);
- }
- } else
-#endif
- if (url.scheme() == QLatin1String("qrc")) {
- // If the canonical URL refers to a Qt resource, open with QFile and use
- // the stream playback capability to play.
- stream = new QFile(QLatin1Char(':') + url.path());
- if (stream->open(QIODevice::ReadOnly)) {
- m_stream = new MFStream(stream, true);
- hr = m_sourceResolver->BeginCreateObjectFromByteStream(
- m_stream, reinterpret_cast<const OLECHAR *>(url.toString().utf16()),
- MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE,
- NULL, &m_cancelCookie, this, new State(m_sourceResolver, true));
- if (FAILED(hr)) {
- qWarning() << "Unsupported stream!";
- emit error(hr);
- }
- } else {
- delete stream;
- emit error(QMediaPlayer::FormatError);
- }
- } else {
- hr = m_sourceResolver->BeginCreateObjectFromURL(
- reinterpret_cast<const OLECHAR *>(url.toString().utf16()),
- MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE,
- NULL, &m_cancelCookie, this, new State(m_sourceResolver, false));
- if (FAILED(hr)) {
- qWarning() << "Unsupported url scheme!";
- emit error(hr);
- }
- }
- }
-}
-
-void SourceResolver::cancel()
-{
- QMutexLocker locker(&m_mutex);
- if (m_cancelCookie) {
- m_sourceResolver->CancelObjectCreation(m_cancelCookie);
- m_cancelCookie->Release();
- m_cancelCookie = NULL;
- m_sourceResolver->Release();
- m_sourceResolver = NULL;
- }
-}
-
-void SourceResolver::shutdown()
-{
- if (m_mediaSource) {
- m_mediaSource->Shutdown();
- m_mediaSource->Release();
- m_mediaSource = NULL;
- }
-
- if (m_stream) {
- m_stream->Release();
- m_stream = NULL;
- }
-}
-
-IMFMediaSource* SourceResolver::mediaSource() const
-{
- return m_mediaSource;
-}
-
-/////////////////////////////////////////////////////////////////////////////////
-SourceResolver::State::State(IMFSourceResolver *sourceResolver, bool fromStream)
- : m_cRef(0)
- , m_sourceResolver(sourceResolver)
- , m_fromStream(fromStream)
-{
- sourceResolver->AddRef();
-}
-
-SourceResolver::State::~State()
-{
- m_sourceResolver->Release();
-}
-
-STDMETHODIMP SourceResolver::State::QueryInterface(REFIID riid, LPVOID *ppvObject)
-{
- if (!ppvObject)
- return E_POINTER;
- if (riid == IID_IUnknown) {
- *ppvObject = static_cast<IUnknown*>(this);
- } else {
- *ppvObject = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
-}
-
-STDMETHODIMP_(ULONG) SourceResolver::State::AddRef(void)
-{
- return InterlockedIncrement(&m_cRef);
-}
-
-STDMETHODIMP_(ULONG) SourceResolver::State::Release(void)
-{
- LONG cRef = InterlockedDecrement(&m_cRef);
- if (cRef == 0)
- delete this;
- // For thread safety, return a temporary variable.
- return cRef;
-}
-
-IMFSourceResolver* SourceResolver::State::sourceResolver() const
-{
- return m_sourceResolver;
-}
-
-bool SourceResolver::State::fromStream() const
-{
- return m_fromStream;
-}
-
diff --git a/src/plugins/wmf/sourceresolver.h b/src/plugins/wmf/sourceresolver.h
deleted file mode 100644
index 007552cb0..000000000
--- a/src/plugins/wmf/sourceresolver.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef SOURCERESOLVER_H
-#define SOURCERESOLVER_H
-
-#include "mfstream.h"
-#include <QUrl>
-
-class SourceResolver: public QObject, public IMFAsyncCallback
-{
- Q_OBJECT
-public:
- SourceResolver();
-
- ~SourceResolver();
-
- STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject);
- STDMETHODIMP_(ULONG) AddRef(void);
- STDMETHODIMP_(ULONG) Release(void);
-
- HRESULT STDMETHODCALLTYPE Invoke(IMFAsyncResult *pAsyncResult);
-
- HRESULT STDMETHODCALLTYPE GetParameters(DWORD*, DWORD*);
-
- void load(const QUrl &url, QIODevice* stream);
-
- void cancel();
-
- void shutdown();
-
- IMFMediaSource* mediaSource() const;
-
-Q_SIGNALS:
- void error(long hr);
- void mediaSourceReady();
-
-private:
- class State : public IUnknown
- {
- public:
- State(IMFSourceResolver *sourceResolver, bool fromStream);
- ~State();
-
- STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject);
-
- STDMETHODIMP_(ULONG) AddRef(void);
-
- STDMETHODIMP_(ULONG) Release(void);
-
- IMFSourceResolver* sourceResolver() const;
- bool fromStream() const;
-
- private:
- long m_cRef;
- IMFSourceResolver *m_sourceResolver;
- bool m_fromStream;
- };
-
- long m_cRef;
- IUnknown *m_cancelCookie;
- IMFSourceResolver *m_sourceResolver;
- IMFMediaSource *m_mediaSource;
- MFStream *m_stream;
- QMutex m_mutex;
-};
-
-#endif
diff --git a/src/plugins/wmf/wmf.json b/src/plugins/wmf/wmf.json
deleted file mode 100644
index e70736480..000000000
--- a/src/plugins/wmf/wmf.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "Keys": ["windowsmediafoundation"],
- "Services": ["org.qt-project.qt.mediaplayer", "org.qt-project.qt.audiodecode"]
-}
diff --git a/src/plugins/wmf/wmf.pro b/src/plugins/wmf/wmf.pro
deleted file mode 100644
index 7c712233d..000000000
--- a/src/plugins/wmf/wmf.pro
+++ /dev/null
@@ -1,28 +0,0 @@
-TARGET = wmfengine
-QT += multimedia-private network
-
-win32:!qtHaveModule(opengl) {
- LIBS_PRIVATE += -lgdi32 -luser32
-}
-
-INCLUDEPATH += .
-
-HEADERS += \
- wmfserviceplugin.h \
- mfstream.h \
- sourceresolver.h
-
-SOURCES += \
- wmfserviceplugin.cpp \
- mfstream.cpp \
- sourceresolver.cpp
-
-include (player/player.pri)
-include (decoder/decoder.pri)
-
-OTHER_FILES += \
- wmf.json
-
-PLUGIN_TYPE = mediaservice
-PLUGIN_CLASS_NAME = WMFServicePlugin
-load(qt_plugin)
diff --git a/src/plugins/wmf/wmfserviceplugin.cpp b/src/plugins/wmf/wmfserviceplugin.cpp
deleted file mode 100644
index 740067600..000000000
--- a/src/plugins/wmf/wmfserviceplugin.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qstring.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/QFile>
-
-#include "wmfserviceplugin.h"
-#include "mfplayerservice.h"
-#include "mfdecoderservice.h"
-
-#include <mfapi.h>
-
-namespace
-{
-static int g_refCount = 0;
-void addRefCount()
-{
- g_refCount++;
- if (g_refCount == 1) {
- CoInitialize(NULL);
- MFStartup(MF_VERSION);
- }
-}
-
-void releaseRefCount()
-{
- g_refCount--;
- if (g_refCount == 0) {
- MFShutdown();
- CoUninitialize();
- }
-}
-
-}
-
-QMediaService* WMFServicePlugin::create(QString const& key)
-{
- if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER)) {
- addRefCount();
- return new MFPlayerService;
- }
-
- if (key == QLatin1String(Q_MEDIASERVICE_AUDIODECODER)) {
- addRefCount();
- return new MFAudioDecoderService;
- }
- //qDebug() << "unsupported key:" << key;
- return 0;
-}
-
-void WMFServicePlugin::release(QMediaService *service)
-{
- delete service;
- releaseRefCount();
-}
-
-QMediaServiceProviderHint::Features WMFServicePlugin::supportedFeatures(
- const QByteArray &service) const
-{
- if (service == Q_MEDIASERVICE_MEDIAPLAYER)
- return QMediaServiceProviderHint::StreamPlayback;
- else
- return QMediaServiceProviderHint::Features();
-}
-
-QByteArray WMFServicePlugin::defaultDevice(const QByteArray &) const
-{
- return QByteArray();
-}
-
-QList<QByteArray> WMFServicePlugin::devices(const QByteArray &) const
-{
- return QList<QByteArray>();
-}
-
-QString WMFServicePlugin::deviceDescription(const QByteArray &, const QByteArray &)
-{
- return QString();
-}
-
diff --git a/src/plugins/wmf/wmfserviceplugin.h b/src/plugins/wmf/wmfserviceplugin.h
deleted file mode 100644
index 493a0b08c..000000000
--- a/src/plugins/wmf/wmfserviceplugin.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef WMFSERVICEPLUGIN_H
-#define WMFSERVICEPLUGIN_H
-
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-#include "qmediaserviceproviderplugin.h"
-
-QT_USE_NAMESPACE
-
-class WMFServicePlugin
- : public QMediaServiceProviderPlugin
- , public QMediaServiceSupportedDevicesInterface
- , public QMediaServiceDefaultDeviceInterface
- , public QMediaServiceFeaturesInterface
-{
- Q_OBJECT
- Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
- Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
- Q_INTERFACES(QMediaServiceFeaturesInterface)
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "wmf.json")
-
-public:
- QMediaService* create(QString const& key);
- void release(QMediaService *service);
-
- QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const;
-
- QByteArray defaultDevice(const QByteArray &service) const;
- QList<QByteArray> devices(const QByteArray &service) const;
- QString deviceDescription(const QByteArray &service, const QByteArray &device);
-};
-
-#endif // WMFSERVICEPLUGIN_H
diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput.cpp b/src/qtmultimediaquicktools/qdeclarativevideooutput.cpp
deleted file mode 100644
index 5f5b2f2a0..000000000
--- a/src/qtmultimediaquicktools/qdeclarativevideooutput.cpp
+++ /dev/null
@@ -1,919 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "qdeclarativevideooutput_p.h"
-
-#include "qdeclarativevideooutput_render_p.h"
-#include "qdeclarativevideooutput_window_p.h"
-#include <private/qvideooutputorientationhandler_p.h>
-#include <QtMultimedia/qmediaobject.h>
-#include <QtMultimedia/qmediaservice.h>
-#include <private/qmediapluginloader_p.h>
-#include <QtCore/qloggingcategory.h>
-
-static void initResource() {
- Q_INIT_RESOURCE(qtmultimediaquicktools);
-}
-
-QT_BEGIN_NAMESPACE
-
-Q_LOGGING_CATEGORY(qLcVideo, "qt.multimedia.video")
-
-/*!
- \qmltype VideoOutput
- //! \instantiates QDeclarativeVideoOutput
- \brief Render video or camera viewfinder.
-
- \ingroup multimedia_qml
- \ingroup multimedia_video_qml
- \inqmlmodule QtMultimedia
-
- \qml
-
- Rectangle {
- width: 800
- height: 600
- color: "black"
-
- MediaPlayer {
- id: player
- source: "file://video.webm"
- autoPlay: true
- }
-
- VideoOutput {
- id: videoOutput
- source: player
- anchors.fill: parent
- }
- }
-
- \endqml
-
- The VideoOutput item supports untransformed, stretched, and uniformly scaled video presentation.
- For a description of stretched uniformly scaled presentation, see the \l fillMode property
- description.
-
- The VideoOutput item works with backends that support either QVideoRendererControl or
- QVideoWindowControl. If the backend only supports QVideoWindowControl, the video is rendered
- onto an overlay window that is layered on top of the QtQuick window. Due to the nature of the
- video overlays, certain features are not available for these kind of backends:
- \list
- \li Some transformations like rotations
- \li Having other QtQuick items on top of the VideoOutput item
- \endlist
- Most backends however do support QVideoRendererControl and therefore don't have the limitations
- listed above.
-
- \sa MediaPlayer, Camera
-
-\omit
- \section1 Screen Saver
-
- If it is likely that an application will be playing video for an extended
- period of time without user interaction it may be necessary to disable
- the platform's screen saver. The \l ScreenSaver (from \l QtSystemInfo)
- may be used to disable the screensaver in this fashion:
-
- \qml
- import QtSystemInfo 5.0
-
- ScreenSaver { screenSaverEnabled: false }
- \endqml
-\endomit
-*/
-
-// TODO: Restore Qt System Info docs when the module is released
-
-/*!
- \internal
- \class QDeclarativeVideoOutput
- \brief The QDeclarativeVideoOutput class provides a video output item.
-*/
-
-QDeclarativeVideoOutput::QDeclarativeVideoOutput(QQuickItem *parent) :
- QQuickItem(parent),
- m_sourceType(NoSource),
- m_fillMode(PreserveAspectFit),
- m_geometryDirty(true),
- m_orientation(0),
- m_autoOrientation(false),
- m_screenOrientationHandler(0)
-{
- initResource();
- setFlag(ItemHasContents, true);
- createBackend(nullptr);
-}
-
-QDeclarativeVideoOutput::~QDeclarativeVideoOutput()
-{
- m_backend.reset();
- m_source.clear();
- _q_updateMediaObject();
-}
-
-/*!
- \qmlproperty object QtMultimedia::VideoOutput::videoSurface
- \since 5.15
-
- This property holds the underlaying video surface that can be used
- to render the video frames to this VideoOutput element.
- It is similar to setting a QObject with \c videoSurface property as a source,
- where this video surface will be set.
-
- \sa source
-*/
-
-QAbstractVideoSurface *QDeclarativeVideoOutput::videoSurface() const
-{
- return m_backend ? m_backend->videoSurface() : nullptr;
-}
-
-/*!
- \qmlproperty variant QtMultimedia::VideoOutput::source
-
- This property holds the source item providing the video frames like MediaPlayer or Camera.
-
- If you are extending your own C++ classes to interoperate with VideoOutput, you can
- either provide a QObject based class with a \c mediaObject property that exposes a
- QMediaObject derived class that has a QVideoRendererControl available, or you can
- provide a QObject based class with a writable \c videoSurface property that can
- accept a QAbstractVideoSurface based class and can follow the correct protocol to
- deliver QVideoFrames to it.
-*/
-
-void QDeclarativeVideoOutput::setSource(QObject *source)
-{
- qCDebug(qLcVideo) << "source is" << source;
-
- if (source == m_source.data())
- return;
-
- if (m_source && m_sourceType == MediaObjectSource) {
- disconnect(m_source.data(), 0, this, SLOT(_q_updateMediaObject()));
- disconnect(m_source.data(), 0, this, SLOT(_q_updateCameraInfo()));
- }
-
- if (m_backend)
- m_backend->releaseSource();
-
- m_source = source;
-
- if (m_source) {
- const QMetaObject *metaObject = m_source.data()->metaObject();
-
- int mediaObjectPropertyIndex = metaObject->indexOfProperty("mediaObject");
- if (mediaObjectPropertyIndex != -1) {
- const QMetaProperty mediaObjectProperty = metaObject->property(mediaObjectPropertyIndex);
-
- if (mediaObjectProperty.hasNotifySignal()) {
- QMetaMethod method = mediaObjectProperty.notifySignal();
- QMetaObject::connect(m_source.data(), method.methodIndex(),
- this, this->metaObject()->indexOfSlot("_q_updateMediaObject()"),
- Qt::DirectConnection, 0);
-
- }
-
- int deviceIdPropertyIndex = metaObject->indexOfProperty("deviceId");
- if (deviceIdPropertyIndex != -1) { // Camera source
- const QMetaProperty deviceIdProperty = metaObject->property(deviceIdPropertyIndex);
-
- if (deviceIdProperty.hasNotifySignal()) {
- QMetaMethod method = deviceIdProperty.notifySignal();
- QMetaObject::connect(m_source.data(), method.methodIndex(),
- this, this->metaObject()->indexOfSlot("_q_updateCameraInfo()"),
- Qt::DirectConnection, 0);
-
- }
- }
-
- m_sourceType = MediaObjectSource;
- } else if (metaObject->indexOfProperty("videoSurface") != -1) {
- m_source.data()->setProperty("videoSurface",
- QVariant::fromValue<QAbstractVideoSurface *>(videoSurface()));
- m_sourceType = VideoSurfaceSource;
- } else {
- m_sourceType = NoSource;
- }
- } else {
- m_sourceType = NoSource;
- }
-
- _q_updateMediaObject();
- emit sourceChanged();
-}
-
-Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, videoBackendFactoryLoader,
- (QDeclarativeVideoBackendFactoryInterface_iid, QLatin1String("video/declarativevideobackend"), Qt::CaseInsensitive))
-
-bool QDeclarativeVideoOutput::createBackend(QMediaService *service)
-{
- bool backendAvailable = false;
-
- const auto instances = videoBackendFactoryLoader()->instances(QLatin1String("declarativevideobackend"));
- for (QObject *instance : instances) {
- if (QDeclarativeVideoBackendFactoryInterface *plugin = qobject_cast<QDeclarativeVideoBackendFactoryInterface*>(instance)) {
- if (!m_backend)
- m_backend.reset(plugin->create(this));
- if (m_backend && m_backend->init(service)) {
- backendAvailable = true;
- break;
- }
- }
- }
-
- if (!backendAvailable) {
- if (!m_backend)
- m_backend.reset(new QDeclarativeVideoRendererBackend(this));
- if (m_backend->init(service))
- backendAvailable = true;
- }
-
- // QDeclarativeVideoWindowBackend only works when there is a service with a QVideoWindowControl.
- // Without service, the QDeclarativeVideoRendererBackend should always work.
- if (!backendAvailable) {
- Q_ASSERT(service);
- m_backend.reset(new QDeclarativeVideoWindowBackend(this));
- if (m_backend->init(service))
- backendAvailable = true;
- }
-
- if (backendAvailable) {
- // Since new backend has been created needs to update its geometry.
- m_geometryDirty = true;
-
- m_backend->clearFilters();
- for (int i = 0; i < m_filters.count(); ++i)
- m_backend->appendFilter(m_filters[i]);
- } else {
- qWarning() << Q_FUNC_INFO << "Media service has neither renderer nor window control available.";
- m_backend.reset();
- }
-
- return backendAvailable;
-}
-
-void QDeclarativeVideoOutput::_q_updateMediaObject()
-{
- QMediaObject *mediaObject = 0;
-
- if (m_source)
- mediaObject = qobject_cast<QMediaObject*>(m_source.data()->property("mediaObject").value<QObject*>());
-
- qCDebug(qLcVideo) << "media object is" << mediaObject;
-
- if (m_mediaObject.data() == mediaObject)
- return;
-
- m_mediaObject.clear();
- m_service.clear();
-
- if (mediaObject) {
- if (QMediaService *service = mediaObject->service()) {
- if (createBackend(service)) {
- m_service = service;
- m_mediaObject = mediaObject;
- }
- }
- }
-
- _q_updateCameraInfo();
-}
-
-void QDeclarativeVideoOutput::_q_updateCameraInfo()
-{
- if (m_mediaObject) {
- const QCamera *camera = qobject_cast<const QCamera *>(m_mediaObject);
- if (camera) {
- QCameraInfo info(*camera);
-
- if (m_cameraInfo != info) {
- m_cameraInfo = info;
-
- // The camera position and orientation need to be taken into account for
- // the viewport auto orientation
- if (m_autoOrientation)
- _q_screenOrientationChanged(m_screenOrientationHandler->currentOrientation());
- }
- }
- } else {
- m_cameraInfo = QCameraInfo();
- }
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::VideoOutput::fillMode
-
- Set this property to define how the video is scaled to fit the target area.
-
- \list
- \li Stretch - the video is scaled to fit.
- \li PreserveAspectFit - the video is scaled uniformly to fit without cropping
- \li PreserveAspectCrop - the video is scaled uniformly to fill, cropping if necessary
- \endlist
-
- The default fill mode is PreserveAspectFit.
-*/
-
-QDeclarativeVideoOutput::FillMode QDeclarativeVideoOutput::fillMode() const
-{
- return m_fillMode;
-}
-
-void QDeclarativeVideoOutput::setFillMode(FillMode mode)
-{
- if (mode == m_fillMode)
- return;
-
- m_fillMode = mode;
- m_geometryDirty = true;
- update();
-
- emit fillModeChanged(mode);
-}
-
-void QDeclarativeVideoOutput::_q_updateNativeSize()
-{
- if (!m_backend)
- return;
-
- QSize size = m_backend->nativeSize();
- if (!qIsDefaultAspect(m_orientation)) {
- size.transpose();
- }
-
- if (m_nativeSize != size) {
- m_nativeSize = size;
-
- m_geometryDirty = true;
-
- setImplicitWidth(size.width());
- setImplicitHeight(size.height());
-
- emit sourceRectChanged();
- }
-}
-
-/* Based on fill mode and our size, figure out the source/dest rects */
-void QDeclarativeVideoOutput::_q_updateGeometry()
-{
- const QRectF rect(0, 0, width(), height());
- const QRectF absoluteRect(x(), y(), width(), height());
-
- if (!m_geometryDirty && m_lastRect == absoluteRect)
- return;
-
- QRectF oldContentRect(m_contentRect);
-
- m_geometryDirty = false;
- m_lastRect = absoluteRect;
-
- if (m_nativeSize.isEmpty()) {
- //this is necessary for item to receive the
- //first paint event and configure video surface.
- m_contentRect = rect;
- } else if (m_fillMode == Stretch) {
- m_contentRect = rect;
- } else if (m_fillMode == PreserveAspectFit || m_fillMode == PreserveAspectCrop) {
- QSizeF scaled = m_nativeSize;
- scaled.scale(rect.size(), m_fillMode == PreserveAspectFit ?
- Qt::KeepAspectRatio : Qt::KeepAspectRatioByExpanding);
-
- m_contentRect = QRectF(QPointF(), scaled);
- m_contentRect.moveCenter(rect.center());
- }
-
- if (m_backend) {
- if (!m_backend->videoSurface() || m_backend->videoSurface()->isActive())
- m_backend->updateGeometry();
- else
- m_geometryDirty = true;
- }
-
-
- if (m_contentRect != oldContentRect)
- emit contentRectChanged();
-}
-
-void QDeclarativeVideoOutput::_q_screenOrientationChanged(int orientation)
-{
- // If the source is a camera, take into account its sensor position and orientation
- if (!m_cameraInfo.isNull()) {
- switch (m_cameraInfo.position()) {
- case QCamera::FrontFace:
- // Front facing cameras are flipped horizontally, compensate the mirror
- orientation += (360 - m_cameraInfo.orientation());
- break;
- case QCamera::BackFace:
- default:
- orientation += m_cameraInfo.orientation();
- break;
- }
- }
-
- setOrientation(orientation % 360);
-}
-
-/*!
- \qmlproperty int QtMultimedia::VideoOutput::orientation
-
- In some cases the source video stream requires a certain
- orientation to be correct. This includes
- sources like a camera viewfinder, where the displayed
- viewfinder should match reality, no matter what rotation
- the rest of the user interface has.
-
- This property allows you to apply a rotation (in steps
- of 90 degrees) to compensate for any user interface
- rotation, with positive values in the anti-clockwise direction.
-
- The orientation change will also affect the mapping
- of coordinates from source to viewport.
-
- \sa autoOrientation
-*/
-int QDeclarativeVideoOutput::orientation() const
-{
- return m_orientation;
-}
-
-void QDeclarativeVideoOutput::setOrientation(int orientation)
-{
- // Make sure it's a multiple of 90.
- if (orientation % 90)
- return;
-
- // If there's no actual change, return
- if (m_orientation == orientation)
- return;
-
- // If the new orientation is the same effect
- // as the old one, don't update the video node stuff
- if ((m_orientation % 360) == (orientation % 360)) {
- m_orientation = orientation;
- emit orientationChanged();
- return;
- }
-
- m_geometryDirty = true;
-
- // Otherwise, a new orientation
- // See if we need to change aspect ratio orientation too
- bool oldAspect = qIsDefaultAspect(m_orientation);
- bool newAspect = qIsDefaultAspect(orientation);
-
- m_orientation = orientation;
-
- if (oldAspect != newAspect) {
- m_nativeSize.transpose();
-
- setImplicitWidth(m_nativeSize.width());
- setImplicitHeight(m_nativeSize.height());
-
- // Source rectangle does not change for orientation
- }
-
- update();
- emit orientationChanged();
-}
-
-/*!
- \qmlproperty bool QtMultimedia::VideoOutput::autoOrientation
-
- This property allows you to enable and disable auto orientation
- of the video stream, so that its orientation always matches
- the orientation of the screen. If \c autoOrientation is enabled,
- the \c orientation property is overwritten.
-
- By default \c autoOrientation is disabled.
-
- \sa orientation
- \since 5.2
-*/
-bool QDeclarativeVideoOutput::autoOrientation() const
-{
- return m_autoOrientation;
-}
-
-void QDeclarativeVideoOutput::setAutoOrientation(bool autoOrientation)
-{
- if (autoOrientation == m_autoOrientation)
- return;
-
- m_autoOrientation = autoOrientation;
- if (m_autoOrientation) {
- m_screenOrientationHandler = new QVideoOutputOrientationHandler(this);
- connect(m_screenOrientationHandler, SIGNAL(orientationChanged(int)),
- this, SLOT(_q_screenOrientationChanged(int)));
-
- _q_screenOrientationChanged(m_screenOrientationHandler->currentOrientation());
- } else {
- disconnect(m_screenOrientationHandler, SIGNAL(orientationChanged(int)),
- this, SLOT(_q_screenOrientationChanged(int)));
- m_screenOrientationHandler->deleteLater();
- m_screenOrientationHandler = 0;
- }
-
- emit autoOrientationChanged();
-}
-
-/*!
- \qmlproperty rectangle QtMultimedia::VideoOutput::contentRect
-
- This property holds the item coordinates of the area that
- would contain video to render. With certain fill modes,
- this rectangle will be larger than the visible area of the
- \c VideoOutput.
-
- This property is useful when other coordinates are specified
- in terms of the source dimensions - this applied for relative
- (normalized) frame coordinates in the range of 0 to 1.0.
-
- \sa mapRectToItem(), mapPointToItem()
-
- Areas outside this will be transparent.
-*/
-QRectF QDeclarativeVideoOutput::contentRect() const
-{
- return m_contentRect;
-}
-
-/*!
- \qmlproperty rectangle QtMultimedia::VideoOutput::sourceRect
-
- This property holds the area of the source video
- content that is considered for rendering. The
- values are in source pixel coordinates, adjusted for
- the source's pixel aspect ratio.
-
- Note that typically the top left corner of this rectangle
- will be \c {0,0} while the width and height will be the
- width and height of the input content. Only when the video
- source has a viewport set, these values will differ.
-
- The orientation setting does not affect this rectangle.
-
- \sa QVideoSurfaceFormat::pixelAspectRatio()
- \sa QVideoSurfaceFormat::viewport()
-*/
-QRectF QDeclarativeVideoOutput::sourceRect() const
-{
- // We might have to transpose back
- QSizeF size = m_nativeSize;
- if (!qIsDefaultAspect(m_orientation)) {
- size.transpose();
- }
-
- // No backend? Just assume no viewport.
- if (!m_nativeSize.isValid() || !m_backend) {
- return QRectF(QPointF(), size);
- }
-
- // Take the viewport into account for the top left position.
- // m_nativeSize is already adjusted to the viewport, as it originats
- // from QVideoSurfaceFormat::sizeHint(), which includes pixel aspect
- // ratio and viewport.
- const QRectF viewport = m_backend->adjustedViewport();
- Q_ASSERT(viewport.size() == size);
- return QRectF(viewport.topLeft(), size);
-}
-
-/*!
- \qmlmethod QPointF QtMultimedia::VideoOutput::mapNormalizedPointToItem (const QPointF &point) const
-
- Given normalized coordinates \a point (that is, each
- component in the range of 0 to 1.0), return the mapped point
- that it corresponds to (in item coordinates).
- This mapping is affected by the orientation.
-
- Depending on the fill mode, this point may lie outside the rendered
- rectangle.
- */
-QPointF QDeclarativeVideoOutput::mapNormalizedPointToItem(const QPointF &point) const
-{
- qreal dx = point.x();
- qreal dy = point.y();
-
- if (qIsDefaultAspect(m_orientation)) {
- dx *= m_contentRect.width();
- dy *= m_contentRect.height();
- } else {
- dx *= m_contentRect.height();
- dy *= m_contentRect.width();
- }
-
- switch (qNormalizedOrientation(m_orientation)) {
- case 0:
- default:
- return m_contentRect.topLeft() + QPointF(dx, dy);
- case 90:
- return m_contentRect.bottomLeft() + QPointF(dy, -dx);
- case 180:
- return m_contentRect.bottomRight() + QPointF(-dx, -dy);
- case 270:
- return m_contentRect.topRight() + QPointF(-dy, dx);
- }
-}
-
-/*!
- \qmlmethod QRectF QtMultimedia::VideoOutput::mapNormalizedRectToItem(const QRectF &rectangle) const
-
- Given a rectangle \a rectangle in normalized
- coordinates (that is, each component in the range of 0 to 1.0),
- return the mapped rectangle that it corresponds to (in item coordinates).
- This mapping is affected by the orientation.
-
- Depending on the fill mode, this rectangle may extend outside the rendered
- rectangle.
- */
-QRectF QDeclarativeVideoOutput::mapNormalizedRectToItem(const QRectF &rectangle) const
-{
- return QRectF(mapNormalizedPointToItem(rectangle.topLeft()),
- mapNormalizedPointToItem(rectangle.bottomRight())).normalized();
-}
-
-/*!
- \qmlmethod QPointF QtMultimedia::VideoOutput::mapPointToSource(const QPointF &point) const
-
- Given a point \a point in item coordinates, return the
- corresponding point in source coordinates. This mapping is
- affected by the orientation.
-
- If the supplied point lies outside the rendered area, the returned
- point will be outside the source rectangle.
- */
-QPointF QDeclarativeVideoOutput::mapPointToSource(const QPointF &point) const
-{
- QPointF norm = mapPointToSourceNormalized(point);
-
- if (qIsDefaultAspect(m_orientation))
- return QPointF(norm.x() * m_nativeSize.width(), norm.y() * m_nativeSize.height());
- else
- return QPointF(norm.x() * m_nativeSize.height(), norm.y() * m_nativeSize.width());
-}
-
-/*!
- \qmlmethod QRectF QtMultimedia::VideoOutput::mapRectToSource(const QRectF &rectangle) const
-
- Given a rectangle \a rectangle in item coordinates, return the
- corresponding rectangle in source coordinates. This mapping is
- affected by the orientation.
-
- This mapping is affected by the orientation.
-
- If the supplied point lies outside the rendered area, the returned
- point will be outside the source rectangle.
- */
-QRectF QDeclarativeVideoOutput::mapRectToSource(const QRectF &rectangle) const
-{
- return QRectF(mapPointToSource(rectangle.topLeft()),
- mapPointToSource(rectangle.bottomRight())).normalized();
-}
-
-/*!
- \qmlmethod QPointF QtMultimedia::VideoOutput::mapPointToSourceNormalized(const QPointF &point) const
-
- Given a point \a point in item coordinates, return the
- corresponding point in normalized source coordinates. This mapping is
- affected by the orientation.
-
- If the supplied point lies outside the rendered area, the returned
- point will be outside the source rectangle. No clamping is performed.
- */
-QPointF QDeclarativeVideoOutput::mapPointToSourceNormalized(const QPointF &point) const
-{
- if (m_contentRect.isEmpty())
- return QPointF();
-
- // Normalize the item source point
- qreal nx = (point.x() - m_contentRect.left()) / m_contentRect.width();
- qreal ny = (point.y() - m_contentRect.top()) / m_contentRect.height();
-
- const qreal one(1.0f);
-
- // For now, the origin of the source rectangle is 0,0
- switch (qNormalizedOrientation(m_orientation)) {
- case 0:
- default:
- return QPointF(nx, ny);
- case 90:
- return QPointF(one - ny, nx);
- case 180:
- return QPointF(one - nx, one - ny);
- case 270:
- return QPointF(ny, one - nx);
- }
-}
-
-/*!
- \qmlmethod QRectF QtMultimedia::VideoOutput::mapRectToSourceNormalized(const QRectF &rectangle) const
-
- Given a rectangle \a rectangle in item coordinates, return the
- corresponding rectangle in normalized source coordinates. This mapping is
- affected by the orientation.
-
- This mapping is affected by the orientation.
-
- If the supplied point lies outside the rendered area, the returned
- point will be outside the source rectangle. No clamping is performed.
- */
-QRectF QDeclarativeVideoOutput::mapRectToSourceNormalized(const QRectF &rectangle) const
-{
- return QRectF(mapPointToSourceNormalized(rectangle.topLeft()),
- mapPointToSourceNormalized(rectangle.bottomRight())).normalized();
-}
-
-QDeclarativeVideoOutput::SourceType QDeclarativeVideoOutput::sourceType() const
-{
- return m_sourceType;
-}
-
-/*!
- \qmlmethod QPointF QtMultimedia::VideoOutput::mapPointToItem(const QPointF &point) const
-
- Given a point \a point in source coordinates, return the
- corresponding point in item coordinates. This mapping is
- affected by the orientation.
-
- Depending on the fill mode, this point may lie outside the rendered
- rectangle.
- */
-QPointF QDeclarativeVideoOutput::mapPointToItem(const QPointF &point) const
-{
- if (m_nativeSize.isEmpty())
- return QPointF();
-
- // Just normalize and use that function
- // m_nativeSize is transposed in some orientations
- if (qIsDefaultAspect(m_orientation))
- return mapNormalizedPointToItem(QPointF(point.x() / m_nativeSize.width(), point.y() / m_nativeSize.height()));
- else
- return mapNormalizedPointToItem(QPointF(point.x() / m_nativeSize.height(), point.y() / m_nativeSize.width()));
-}
-
-/*!
- \qmlmethod QRectF QtMultimedia::VideoOutput::mapRectToItem(const QRectF &rectangle) const
-
- Given a rectangle \a rectangle in source coordinates, return the
- corresponding rectangle in item coordinates. This mapping is
- affected by the orientation.
-
- Depending on the fill mode, this rectangle may extend outside the rendered
- rectangle.
-
- */
-QRectF QDeclarativeVideoOutput::mapRectToItem(const QRectF &rectangle) const
-{
- return QRectF(mapPointToItem(rectangle.topLeft()),
- mapPointToItem(rectangle.bottomRight())).normalized();
-}
-
-QSGNode *QDeclarativeVideoOutput::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
-{
- _q_updateGeometry();
-
- if (!m_backend)
- return 0;
-
- return m_backend->updatePaintNode(oldNode, data);
-}
-
-void QDeclarativeVideoOutput::itemChange(QQuickItem::ItemChange change,
- const QQuickItem::ItemChangeData &changeData)
-{
- if (m_backend)
- m_backend->itemChange(change, changeData);
-}
-
-void QDeclarativeVideoOutput::releaseResources()
-{
- if (m_backend)
- m_backend->releaseResources();
-}
-
-void QDeclarativeVideoOutput::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
-{
- Q_UNUSED(newGeometry);
- Q_UNUSED(oldGeometry);
-
- QQuickItem::geometryChange(newGeometry, oldGeometry);
-
- // Explicitly listen to geometry changes here. This is needed since changing the position does
- // not trigger a call to updatePaintNode().
- // We need to react to position changes though, as the window backened's display rect gets
- // changed in that situation.
- _q_updateGeometry();
-}
-
-/*!
- \qmlproperty list<object> QtMultimedia::VideoOutput::filters
-
- This property holds the list of video filters that are run on the video
- frames. The order of the filters in the list matches the order in which
- they will be invoked on the video frames. The objects in the list must be
- instances of a subclass of QAbstractVideoFilter.
-
- \sa QAbstractVideoFilter
-*/
-
-QQmlListProperty<QAbstractVideoFilter> QDeclarativeVideoOutput::filters()
-{
- return QQmlListProperty<QAbstractVideoFilter>(this, 0, filter_append, filter_count, filter_at, filter_clear);
-}
-
-void QDeclarativeVideoOutput::filter_append(QQmlListProperty<QAbstractVideoFilter> *property, QAbstractVideoFilter *value)
-{
- QDeclarativeVideoOutput *self = static_cast<QDeclarativeVideoOutput *>(property->object);
- self->m_filters.append(value);
- if (self->m_backend)
- self->m_backend->appendFilter(value);
-}
-
-int QDeclarativeVideoOutput::filter_count(QQmlListProperty<QAbstractVideoFilter> *property)
-{
- QDeclarativeVideoOutput *self = static_cast<QDeclarativeVideoOutput *>(property->object);
- return self->m_filters.count();
-}
-
-QAbstractVideoFilter *QDeclarativeVideoOutput::filter_at(QQmlListProperty<QAbstractVideoFilter> *property, int index)
-{
- QDeclarativeVideoOutput *self = static_cast<QDeclarativeVideoOutput *>(property->object);
- return self->m_filters.at(index);
-}
-
-void QDeclarativeVideoOutput::filter_clear(QQmlListProperty<QAbstractVideoFilter> *property)
-{
- QDeclarativeVideoOutput *self = static_cast<QDeclarativeVideoOutput *>(property->object);
- self->m_filters.clear();
- if (self->m_backend)
- self->m_backend->clearFilters();
-}
-
-void QDeclarativeVideoOutput::_q_invalidateSceneGraph()
-{
- if (m_backend)
- m_backend->invalidateSceneGraph();
-}
-
-/*!
- \qmlproperty enumeration QtMultimedia::VideoOutput::flushMode
- \since 5.13
-
- Set this property to define what \c VideoOutput should show
- when playback is finished or stopped.
-
- \list
- \li EmptyFrame - clears video output.
- \li FirstFrame - shows the first valid frame.
- \li LastFrame - shows the last valid frame.
- \endlist
-
- The default flush mode is EmptyFrame.
-*/
-
-void QDeclarativeVideoOutput::setFlushMode(FlushMode mode)
-{
- if (m_flushMode == mode)
- return;
-
- m_flushMode = mode;
- emit flushModeChanged();
-}
-
-QT_END_NAMESPACE
diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_backend_p.h b/src/qtmultimediaquicktools/qdeclarativevideooutput_backend_p.h
deleted file mode 100644
index da99b387a..000000000
--- a/src/qtmultimediaquicktools/qdeclarativevideooutput_backend_p.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEVIDEOOUTPUT_BACKEND_P_H
-#define QDECLARATIVEVIDEOOUTPUT_BACKEND_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qpointer.h>
-#include <QtCore/qsize.h>
-#include <QtQuick/qquickitem.h>
-#include <QtQuick/qsgnode.h>
-#include <private/qtmultimediaquickdefs_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAbstractVideoSurface;
-class QDeclarativeVideoOutput;
-class QMediaService;
-class QAbstractVideoFilter;
-
-class Q_MULTIMEDIAQUICK_EXPORT QDeclarativeVideoBackend
-{
-public:
- explicit QDeclarativeVideoBackend(QDeclarativeVideoOutput *parent)
- : q(parent)
- {}
-
- virtual ~QDeclarativeVideoBackend()
- {}
-
- virtual bool init(QMediaService *service) = 0;
- virtual void releaseSource() = 0;
- virtual void releaseControl() = 0;
- virtual void itemChange(QQuickItem::ItemChange change,
- const QQuickItem::ItemChangeData &changeData) = 0;
- virtual QSize nativeSize() const = 0;
- virtual void updateGeometry() = 0;
- virtual QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) = 0;
- virtual QAbstractVideoSurface *videoSurface() const = 0;
-
- // The viewport, adjusted for the pixel aspect ratio
- virtual QRectF adjustedViewport() const = 0;
-
- virtual void appendFilter(QAbstractVideoFilter *filter) { Q_UNUSED(filter); }
- virtual void clearFilters() { }
-
- virtual void releaseResources() { }
- virtual void invalidateSceneGraph() { }
-
-protected:
- QDeclarativeVideoOutput *q;
- QPointer<QMediaService> m_service;
-};
-
-class QDeclarativeVideoBackendFactoryInterface
-{
-public:
- virtual QDeclarativeVideoBackend *create(QDeclarativeVideoOutput *parent) = 0;
-};
-
-#define QDeclarativeVideoBackendFactoryInterface_iid "org.qt-project.qt.declarativevideobackendfactory/5.2"
-Q_DECLARE_INTERFACE(QDeclarativeVideoBackendFactoryInterface, QDeclarativeVideoBackendFactoryInterface_iid)
-
-/*
- * Helper - returns true if the given orientation has the same aspect as the default (e.g. 180*n)
- */
-namespace {
-
-inline bool qIsDefaultAspect(int o)
-{
- return (o % 180) == 0;
-}
-
-/*
- * Return the orientation normalized to 0-359
- */
-inline int qNormalizedOrientation(int o)
-{
- // Negative orientations give negative results
- int o2 = o % 360;
- if (o2 < 0)
- o2 += 360;
- return o2;
-}
-
-}
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_p.h b/src/qtmultimediaquicktools/qdeclarativevideooutput_p.h
deleted file mode 100644
index a7ed5c36d..000000000
--- a/src/qtmultimediaquicktools/qdeclarativevideooutput_p.h
+++ /dev/null
@@ -1,203 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEVIDEOOUTPUT_P_H
-#define QDECLARATIVEVIDEOOUTPUT_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qrect.h>
-#include <QtCore/qsharedpointer.h>
-#include <QtQuick/qquickitem.h>
-#include <QtCore/qpointer.h>
-#include <QtMultimedia/qcamerainfo.h>
-#include <QtMultimedia/qabstractvideofilter.h>
-
-#include <private/qtmultimediaquickdefs_p.h>
-
-Q_MOC_INCLUDE("QtMultimedia/qabstractvideosurface.h")
-
-QT_BEGIN_NAMESPACE
-
-class QMediaObject;
-class QMediaService;
-class QDeclarativeVideoBackend;
-class QVideoOutputOrientationHandler;
-class QAbstractVideoSurface;
-
-class Q_MULTIMEDIAQUICK_EXPORT QDeclarativeVideoOutput : public QQuickItem
-{
- Q_OBJECT
- Q_DISABLE_COPY(QDeclarativeVideoOutput)
- Q_PROPERTY(QObject* source READ source WRITE setSource NOTIFY sourceChanged)
- Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
- Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
- Q_PROPERTY(bool autoOrientation READ autoOrientation WRITE setAutoOrientation NOTIFY autoOrientationChanged REVISION 2)
- Q_PROPERTY(QRectF sourceRect READ sourceRect NOTIFY sourceRectChanged)
- Q_PROPERTY(QRectF contentRect READ contentRect NOTIFY contentRectChanged)
- Q_PROPERTY(QQmlListProperty<QAbstractVideoFilter> filters READ filters);
- Q_PROPERTY(FlushMode flushMode READ flushMode WRITE setFlushMode NOTIFY flushModeChanged REVISION 13)
- Q_PROPERTY(QAbstractVideoSurface* videoSurface READ videoSurface CONSTANT REVISION 15)
- Q_ENUMS(FlushMode)
- Q_ENUMS(FillMode)
-
-public:
-
- enum FlushMode
- {
- EmptyFrame,
- FirstFrame,
- LastFrame
- };
-
- enum FillMode
- {
- Stretch = Qt::IgnoreAspectRatio,
- PreserveAspectFit = Qt::KeepAspectRatio,
- PreserveAspectCrop = Qt::KeepAspectRatioByExpanding
- };
-
- QDeclarativeVideoOutput(QQuickItem *parent = 0);
- ~QDeclarativeVideoOutput();
-
- QAbstractVideoSurface *videoSurface() const;
-
- QObject *source() const { return m_source.data(); }
- void setSource(QObject *source);
-
- FillMode fillMode() const;
- void setFillMode(FillMode mode);
-
- int orientation() const;
- void setOrientation(int);
-
- bool autoOrientation() const;
- void setAutoOrientation(bool);
-
- QRectF sourceRect() const;
- QRectF contentRect() const;
-
- Q_INVOKABLE QPointF mapPointToItem(const QPointF &point) const;
- Q_INVOKABLE QRectF mapRectToItem(const QRectF &rectangle) const;
- Q_INVOKABLE QPointF mapNormalizedPointToItem(const QPointF &point) const;
- Q_INVOKABLE QRectF mapNormalizedRectToItem(const QRectF &rectangle) const;
- Q_INVOKABLE QPointF mapPointToSource(const QPointF &point) const;
- Q_INVOKABLE QRectF mapRectToSource(const QRectF &rectangle) const;
- Q_INVOKABLE QPointF mapPointToSourceNormalized(const QPointF &point) const;
- Q_INVOKABLE QRectF mapRectToSourceNormalized(const QRectF &rectangle) const;
-
- enum SourceType {
- NoSource,
- MediaObjectSource,
- VideoSurfaceSource
- };
- SourceType sourceType() const;
-
- QQmlListProperty<QAbstractVideoFilter> filters();
-
- FlushMode flushMode() const { return m_flushMode; }
- void setFlushMode(FlushMode mode);
-
-Q_SIGNALS:
- void sourceChanged();
- void fillModeChanged(QDeclarativeVideoOutput::FillMode);
- void orientationChanged();
- void autoOrientationChanged();
- void sourceRectChanged();
- void contentRectChanged();
- void flushModeChanged();
-
-protected:
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
- void itemChange(ItemChange change, const ItemChangeData &changeData) override;
- void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
- void releaseResources() override;
-
-private Q_SLOTS:
- void _q_updateMediaObject();
- void _q_updateCameraInfo();
- void _q_updateNativeSize();
- void _q_updateGeometry();
- void _q_screenOrientationChanged(int);
- void _q_invalidateSceneGraph();
-
-private:
- bool createBackend(QMediaService *service);
-
- static void filter_append(QQmlListProperty<QAbstractVideoFilter> *property, QAbstractVideoFilter *value);
- static int filter_count(QQmlListProperty<QAbstractVideoFilter> *property);
- static QAbstractVideoFilter *filter_at(QQmlListProperty<QAbstractVideoFilter> *property, int index);
- static void filter_clear(QQmlListProperty<QAbstractVideoFilter> *property);
-
- SourceType m_sourceType;
-
- QPointer<QObject> m_source;
- QPointer<QMediaObject> m_mediaObject;
- QPointer<QMediaService> m_service;
- QCameraInfo m_cameraInfo;
-
- FillMode m_fillMode;
- QSize m_nativeSize;
-
- bool m_geometryDirty;
- QRectF m_lastRect; // Cache of last rect to avoid recalculating geometry
- QRectF m_contentRect; // Destination pixel coordinates, unclipped
- int m_orientation;
- bool m_autoOrientation;
- QVideoOutputOrientationHandler *m_screenOrientationHandler;
-
- QScopedPointer<QDeclarativeVideoBackend> m_backend;
-
- QList<QAbstractVideoFilter *> m_filters;
- FlushMode m_flushMode = EmptyFrame;
-};
-
-QT_END_NAMESPACE
-
-#endif // QDECLARATIVEVIDEOOUTPUT_H
diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp b/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp
deleted file mode 100644
index 02026a182..000000000
--- a/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp
+++ /dev/null
@@ -1,501 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativevideooutput_render_p.h"
-#include "qdeclarativevideooutput_p.h"
-#include <QtMultimedia/qabstractvideofilter.h>
-#include <QtMultimedia/qvideorenderercontrol.h>
-#include <QtMultimedia/qmediaservice.h>
-#include <QtCore/qloggingcategory.h>
-#include <private/qmediapluginloader_p.h>
-#include <private/qsgvideonode_p.h>
-
-#if QT_CONFIG(opengl)
-#include <QtGui/QOpenGLContext>
-#endif
-
-#include <QtQuick/QQuickWindow>
-#include <QtCore/QRunnable>
-
-QT_BEGIN_NAMESPACE
-
-Q_DECLARE_LOGGING_CATEGORY(qLcVideo)
-
-Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, videoNodeFactoryLoader,
- (QSGVideoNodeFactoryInterface_iid, QLatin1String("video/videonode"), Qt::CaseInsensitive))
-
-QDeclarativeVideoRendererBackend::QDeclarativeVideoRendererBackend(QDeclarativeVideoOutput *parent)
- : QDeclarativeVideoBackend(parent),
- m_frameChanged(false)
-{
- m_surface = new QSGVideoItemSurface(this);
- QObject::connect(m_surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)),
- q, SLOT(_q_updateNativeSize()), Qt::QueuedConnection);
-
- // Prioritize the plugin requested by the environment
- QString requestedVideoNode = QString::fromLatin1(qgetenv("QT_VIDEONODE"));
-
- const auto keys = videoNodeFactoryLoader()->keys();
- for (const QString &key : keys) {
- QObject *instance = videoNodeFactoryLoader()->instance(key);
- QSGVideoNodeFactoryInterface* plugin = qobject_cast<QSGVideoNodeFactoryInterface*>(instance);
- if (plugin) {
- if (key == requestedVideoNode)
- m_videoNodeFactories.prepend(plugin);
- else
- m_videoNodeFactories.append(plugin);
- qCDebug(qLcVideo) << "found videonode plugin" << key << plugin;
- }
- }
-
- // Append existing node factories as fallback if we have no plugins
- m_videoNodeFactories.append(&m_i420Factory);
- m_videoNodeFactories.append(&m_rgbFactory);
- m_videoNodeFactories.append(&m_textureFactory);
-}
-
-QDeclarativeVideoRendererBackend::~QDeclarativeVideoRendererBackend()
-{
- releaseSource();
- releaseControl();
- delete m_surface;
-}
-
-bool QDeclarativeVideoRendererBackend::init(QMediaService *service)
-{
- // When there is no service, the source is an object with a "videoSurface" property, which
- // doesn't require a QVideoRendererControl and therefore always works
- if (!service)
- return true;
-
- if (QMediaControl *control = service->requestControl(QVideoRendererControl_iid)) {
- if ((m_rendererControl = qobject_cast<QVideoRendererControl *>(control))) {
- m_rendererControl->setSurface(m_surface);
- m_service = service;
- return true;
- }
- }
- return false;
-}
-
-void QDeclarativeVideoRendererBackend::appendFilter(QAbstractVideoFilter *filter)
-{
- QMutexLocker lock(&m_frameMutex);
- m_filters.append(Filter(filter));
-}
-
-void QDeclarativeVideoRendererBackend::clearFilters()
-{
- QMutexLocker lock(&m_frameMutex);
- scheduleDeleteFilterResources();
- m_filters.clear();
-}
-
-class FilterRunnableDeleter : public QRunnable
-{
-public:
- FilterRunnableDeleter(const QList<QVideoFilterRunnable *> &runnables) : m_runnables(runnables) { }
- void run() override {
- for (QVideoFilterRunnable *runnable : qAsConst(m_runnables))
- delete runnable;
- }
-private:
- QList<QVideoFilterRunnable *> m_runnables;
-};
-
-void QDeclarativeVideoRendererBackend::scheduleDeleteFilterResources()
-{
- if (!q->window())
- return;
-
- QList<QVideoFilterRunnable *> runnables;
- for (int i = 0; i < m_filters.count(); ++i) {
- if (m_filters[i].runnable) {
- runnables.append(m_filters[i].runnable);
- m_filters[i].runnable = 0;
- }
- }
-
- if (!runnables.isEmpty()) {
- // Request the scenegraph to run our cleanup job on the render thread.
- // The execution of our QRunnable may happen after the QML tree including the QAbstractVideoFilter instance is
- // destroyed on the main thread so no references to it must be used during cleanup.
- q->window()->scheduleRenderJob(new FilterRunnableDeleter(runnables), QQuickWindow::BeforeSynchronizingStage);
- }
-}
-
-void QDeclarativeVideoRendererBackend::releaseResources()
-{
- // Called on the gui thread when the window is closed or changed.
- invalidateSceneGraph();
-}
-
-void QDeclarativeVideoRendererBackend::invalidateSceneGraph()
-{
- // Called on the render thread, e.g. when the context is lost.
- QMutexLocker lock(&m_frameMutex);
- for (int i = 0; i < m_filters.count(); ++i) {
- if (m_filters[i].runnable) {
- delete m_filters[i].runnable;
- m_filters[i].runnable = 0;
- }
- }
-}
-
-void QDeclarativeVideoRendererBackend::itemChange(QQuickItem::ItemChange change,
- const QQuickItem::ItemChangeData &changeData)
-{
- if (change == QQuickItem::ItemSceneChange) {
- if (changeData.window)
- QObject::connect(changeData.window, SIGNAL(sceneGraphInvalidated()),
- q, SLOT(_q_invalidateSceneGraph()), Qt::DirectConnection);
- }
-}
-
-void QDeclarativeVideoRendererBackend::releaseSource()
-{
- if (q->source() && q->sourceType() == QDeclarativeVideoOutput::VideoSurfaceSource) {
- if (q->source()->property("videoSurface").value<QAbstractVideoSurface*>() == m_surface)
- q->source()->setProperty("videoSurface", QVariant::fromValue<QAbstractVideoSurface*>(0));
- }
-
- m_surface->stop();
-}
-
-void QDeclarativeVideoRendererBackend::releaseControl()
-{
- if (m_rendererControl) {
- m_rendererControl->setSurface(0);
- if (m_service)
- m_service->releaseControl(m_rendererControl);
- m_rendererControl = 0;
- }
-}
-
-QSize QDeclarativeVideoRendererBackend::nativeSize() const
-{
- return m_surfaceFormat.sizeHint();
-}
-
-void QDeclarativeVideoRendererBackend::updateGeometry()
-{
- const QRectF viewport = m_surfaceFormat.viewport();
- const QSizeF frameSize = m_surfaceFormat.frameSize();
- const QRectF normalizedViewport(viewport.x() / frameSize.width(),
- viewport.y() / frameSize.height(),
- viewport.width() / frameSize.width(),
- viewport.height() / frameSize.height());
- const QRectF rect(0, 0, q->width(), q->height());
- if (nativeSize().isEmpty()) {
- m_renderedRect = rect;
- m_sourceTextureRect = normalizedViewport;
- } else if (q->fillMode() == QDeclarativeVideoOutput::Stretch) {
- m_renderedRect = rect;
- m_sourceTextureRect = normalizedViewport;
- } else if (q->fillMode() == QDeclarativeVideoOutput::PreserveAspectFit) {
- m_sourceTextureRect = normalizedViewport;
- m_renderedRect = q->contentRect();
- } else if (q->fillMode() == QDeclarativeVideoOutput::PreserveAspectCrop) {
- m_renderedRect = rect;
- const qreal contentHeight = q->contentRect().height();
- const qreal contentWidth = q->contentRect().width();
-
- // Calculate the size of the source rectangle without taking the viewport into account
- const qreal relativeOffsetLeft = -q->contentRect().left() / contentWidth;
- const qreal relativeOffsetTop = -q->contentRect().top() / contentHeight;
- const qreal relativeWidth = rect.width() / contentWidth;
- const qreal relativeHeight = rect.height() / contentHeight;
-
- // Now take the viewport size into account
- const qreal totalOffsetLeft = normalizedViewport.x() + relativeOffsetLeft * normalizedViewport.width();
- const qreal totalOffsetTop = normalizedViewport.y() + relativeOffsetTop * normalizedViewport.height();
- const qreal totalWidth = normalizedViewport.width() * relativeWidth;
- const qreal totalHeight = normalizedViewport.height() * relativeHeight;
-
- if (qIsDefaultAspect(q->orientation())) {
- m_sourceTextureRect = QRectF(totalOffsetLeft, totalOffsetTop,
- totalWidth, totalHeight);
- } else {
- m_sourceTextureRect = QRectF(totalOffsetTop, totalOffsetLeft,
- totalHeight, totalWidth);
- }
- }
-
- if (m_surfaceFormat.scanLineDirection() == QVideoSurfaceFormat::BottomToTop) {
- qreal top = m_sourceTextureRect.top();
- m_sourceTextureRect.setTop(m_sourceTextureRect.bottom());
- m_sourceTextureRect.setBottom(top);
- }
-
- if (m_surfaceFormat.property("mirrored").toBool()) {
- qreal left = m_sourceTextureRect.left();
- m_sourceTextureRect.setLeft(m_sourceTextureRect.right());
- m_sourceTextureRect.setRight(left);
- }
-}
-
-QSGNode *QDeclarativeVideoRendererBackend::updatePaintNode(QSGNode *oldNode,
- QQuickItem::UpdatePaintNodeData *data)
-{
- Q_UNUSED(data);
- QSGVideoNode *videoNode = static_cast<QSGVideoNode *>(oldNode);
-
- QMutexLocker lock(&m_frameMutex);
-
-#if QT_CONFIG(opengl)
- if (!m_glContext) {
- m_glContext = QOpenGLContext::currentContext();
- m_surface->scheduleOpenGLContextUpdate();
-
- // Internal mechanism to call back the surface renderer from the QtQuick render thread
- QObject *obj = m_surface->property("_q_GLThreadCallback").value<QObject*>();
- if (obj) {
- QEvent ev(QEvent::User);
- obj->event(&ev);
- }
- }
-#endif
-
- bool isFrameModified = false;
- if (m_frameChanged) {
- // Run the VideoFilter if there is one. This must be done before potentially changing the videonode below.
- if (m_frame.isValid() && !m_filters.isEmpty()) {
- for (int i = 0; i < m_filters.count(); ++i) {
- QAbstractVideoFilter *filter = m_filters[i].filter;
- QVideoFilterRunnable *&runnable = m_filters[i].runnable;
- if (filter && filter->isActive()) {
- // Create the filter runnable if not yet done. Ownership is taken and is tied to this thread, on which rendering happens.
- if (!runnable)
- runnable = filter->createFilterRunnable();
- if (!runnable)
- continue;
-
- QVideoFilterRunnable::RunFlags flags;
- if (i == m_filters.count() - 1)
- flags |= QVideoFilterRunnable::LastInChain;
-
- QVideoFrame newFrame = runnable->run(&m_frame, m_surfaceFormat, flags);
-
- if (newFrame.isValid() && newFrame != m_frame) {
- isFrameModified = true;
- m_frame = newFrame;
- }
- }
- }
- }
-
- if (videoNode && (videoNode->pixelFormat() != m_frame.pixelFormat() || videoNode->handleType() != m_frame.handleType())) {
- qCDebug(qLcVideo) << "updatePaintNode: deleting old video node because frame format changed";
- delete videoNode;
- videoNode = 0;
- }
-
- if (!m_frame.isValid()) {
- qCDebug(qLcVideo) << "updatePaintNode: no frames yet";
- m_frameChanged = false;
- return 0;
- }
-
- if (!videoNode) {
- for (QSGVideoNodeFactoryInterface* factory : qAsConst(m_videoNodeFactories)) {
- // Get a node that supports our frame. The surface is irrelevant, our
- // QSGVideoItemSurface supports (logically) anything.
- QVideoSurfaceFormat nodeFormat(m_frame.size(), m_frame.pixelFormat(), m_frame.handleType());
- nodeFormat.setYCbCrColorSpace(m_surfaceFormat.yCbCrColorSpace());
- nodeFormat.setPixelAspectRatio(m_surfaceFormat.pixelAspectRatio());
- nodeFormat.setScanLineDirection(m_surfaceFormat.scanLineDirection());
- nodeFormat.setViewport(m_surfaceFormat.viewport());
- nodeFormat.setFrameRate(m_surfaceFormat.frameRate());
- // Update current surface format if something has changed.
- m_surfaceFormat = nodeFormat;
- videoNode = factory->createNode(nodeFormat);
- if (videoNode) {
- qCDebug(qLcVideo) << "updatePaintNode: Video node created. Handle type:" << m_frame.handleType()
- << " Supported formats for the handle by this node:"
- << factory->supportedPixelFormats(m_frame.handleType());
- break;
- }
- }
- }
- }
-
- if (!videoNode) {
- m_frameChanged = false;
- m_frame = QVideoFrame();
- return 0;
- }
-
- // Negative rotations need lots of %360
- videoNode->setTexturedRectGeometry(m_renderedRect, m_sourceTextureRect,
- qNormalizedOrientation(q->orientation()));
- if (m_frameChanged) {
- QSGVideoNode::FrameFlags flags;
- if (isFrameModified)
- flags |= QSGVideoNode::FrameFiltered;
- videoNode->setCurrentFrame(m_frame, flags);
-
- if ((q->flushMode() == QDeclarativeVideoOutput::FirstFrame && !m_frameOnFlush.isValid())
- || q->flushMode() == QDeclarativeVideoOutput::LastFrame) {
- m_frameOnFlush = m_surfaceFormat.handleType() == QAbstractVideoBuffer::NoHandle
- ? m_frame
- : m_frame.image();
- }
-
- //don't keep the frame for more than really necessary
- m_frameChanged = false;
- m_frame = QVideoFrame();
- }
- return videoNode;
-}
-
-QAbstractVideoSurface *QDeclarativeVideoRendererBackend::videoSurface() const
-{
- return m_surface;
-}
-
-QRectF QDeclarativeVideoRendererBackend::adjustedViewport() const
-{
- const QRectF viewport = m_surfaceFormat.viewport();
- const QSizeF pixelAspectRatio = m_surfaceFormat.pixelAspectRatio();
-
- if (pixelAspectRatio.isValid()) {
- const qreal ratio = pixelAspectRatio.width() / pixelAspectRatio.height();
- QRectF result = viewport;
- result.setX(result.x() * ratio);
- result.setWidth(result.width() * ratio);
- return result;
- }
-
- return viewport;
-}
-
-#if QT_CONFIG(opengl)
-QOpenGLContext *QDeclarativeVideoRendererBackend::glContext() const
-{
- return m_glContext;
-}
-#endif
-
-void QDeclarativeVideoRendererBackend::present(const QVideoFrame &frame)
-{
- m_frameMutex.lock();
- m_frame = frame.isValid() ? frame : m_frameOnFlush;
- m_frameChanged = true;
- m_frameMutex.unlock();
-
- q->update();
-}
-
-void QDeclarativeVideoRendererBackend::stop()
-{
- present(QVideoFrame());
-}
-
-QSGVideoItemSurface::QSGVideoItemSurface(QDeclarativeVideoRendererBackend *backend, QObject *parent)
- : QAbstractVideoSurface(parent),
- m_backend(backend)
-{
-}
-
-QSGVideoItemSurface::~QSGVideoItemSurface()
-{
-}
-
-QList<QVideoFrame::PixelFormat> QSGVideoItemSurface::supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const
-{
- QList<QVideoFrame::PixelFormat> formats;
-
- static bool noGLTextures = false;
- static bool noGLTexturesChecked = false;
- if (handleType == QAbstractVideoBuffer::GLTextureHandle) {
- if (!noGLTexturesChecked) {
- noGLTexturesChecked = true;
- noGLTextures = qEnvironmentVariableIsSet("QT_QUICK_NO_TEXTURE_VIDEOFRAMES");
- }
- if (noGLTextures)
- return formats;
- }
-
- for (QSGVideoNodeFactoryInterface* factory : qAsConst(m_backend->m_videoNodeFactories))
- formats.append(factory->supportedPixelFormats(handleType));
-
- return formats;
-}
-
-bool QSGVideoItemSurface::start(const QVideoSurfaceFormat &format)
-{
- qCDebug(qLcVideo) << "Video surface format:" << format << "all supported formats:" << supportedPixelFormats(format.handleType());
- m_backend->m_frameOnFlush = QVideoFrame();
-
- if (!supportedPixelFormats(format.handleType()).contains(format.pixelFormat()))
- return false;
-
- m_backend->m_surfaceFormat = format;
- return QAbstractVideoSurface::start(format);
-}
-
-void QSGVideoItemSurface::stop()
-{
- m_backend->stop();
- QAbstractVideoSurface::stop();
-}
-
-bool QSGVideoItemSurface::present(const QVideoFrame &frame)
-{
- m_backend->present(frame);
- return true;
-}
-
-#if QT_CONFIG(opengl)
-void QSGVideoItemSurface::scheduleOpenGLContextUpdate()
-{
- //This method is called from render thread
- QMetaObject::invokeMethod(this, "updateOpenGLContext");
-}
-
-void QSGVideoItemSurface::updateOpenGLContext()
-{
- //Set a dynamic property to access the OpenGL context in Qt Quick render thread.
- this->setProperty("GLContext", QVariant::fromValue<QObject*>(m_backend->glContext()));
-}
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_render_p.h b/src/qtmultimediaquicktools/qdeclarativevideooutput_render_p.h
deleted file mode 100644
index 445c5a01a..000000000
--- a/src/qtmultimediaquicktools/qdeclarativevideooutput_render_p.h
+++ /dev/null
@@ -1,154 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEVIDEOOUTPUT_RENDER_P_H
-#define QDECLARATIVEVIDEOOUTPUT_RENDER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qdeclarativevideooutput_backend_p.h>
-#include <private/qsgvideonode_yuv_p.h>
-#include <private/qsgvideonode_rgb_p.h>
-#include <private/qsgvideonode_texture_p.h>
-
-#include <QtCore/qmutex.h>
-#include <QtMultimedia/qabstractvideosurface.h>
-
-QT_BEGIN_NAMESPACE
-
-class QSGVideoItemSurface;
-class QVideoRendererControl;
-class QOpenGLContext;
-class QAbstractVideoFilter;
-class QVideoFilterRunnable;
-
-class QDeclarativeVideoRendererBackend : public QDeclarativeVideoBackend
-{
-public:
- QDeclarativeVideoRendererBackend(QDeclarativeVideoOutput *parent);
- ~QDeclarativeVideoRendererBackend();
-
- bool init(QMediaService *service) override;
- void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &changeData) override;
- void releaseSource() override;
- void releaseControl() override;
- QSize nativeSize() const override;
- void updateGeometry() override;
- QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) override;
- QAbstractVideoSurface *videoSurface() const override;
- QRectF adjustedViewport() const override;
-
-#if QT_CONFIG(opengl)
- QOpenGLContext *glContext() const;
-#endif
-
- friend class QSGVideoItemSurface;
- void present(const QVideoFrame &frame);
- void stop();
-
- void appendFilter(QAbstractVideoFilter *filter) override;
- void clearFilters() override;
- void releaseResources() override;
- void invalidateSceneGraph() override;
-
-private:
- void scheduleDeleteFilterResources();
-
- QPointer<QVideoRendererControl> m_rendererControl;
- QList<QSGVideoNodeFactoryInterface*> m_videoNodeFactories;
- QSGVideoItemSurface *m_surface;
- QVideoSurfaceFormat m_surfaceFormat;
-
-#if QT_CONFIG(opengl)
- QOpenGLContext *m_glContext = nullptr;
-#endif
-
- QVideoFrame m_frame;
- QVideoFrame m_frameOnFlush;
- bool m_frameChanged;
- QSGVideoNodeFactory_YUV m_i420Factory;
- QSGVideoNodeFactory_RGB m_rgbFactory;
- QSGVideoNodeFactory_Texture m_textureFactory;
- QMutex m_frameMutex;
- QRectF m_renderedRect; // Destination pixel coordinates, clipped
- QRectF m_sourceTextureRect; // Source texture coordinates
-
- struct Filter {
- Filter() : filter(0), runnable(0) { }
- Filter(QAbstractVideoFilter *filter) : filter(filter), runnable(0) { }
- QAbstractVideoFilter *filter;
- QVideoFilterRunnable *runnable;
- };
- QList<Filter> m_filters;
-};
-
-class QSGVideoItemSurface : public QAbstractVideoSurface
-{
- Q_OBJECT
-public:
- explicit QSGVideoItemSurface(QDeclarativeVideoRendererBackend *backend, QObject *parent = 0);
- ~QSGVideoItemSurface();
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const override;
- bool start(const QVideoSurfaceFormat &format) override;
- void stop() override;
- bool present(const QVideoFrame &frame) override;
-
-#if QT_CONFIG(opengl)
- void scheduleOpenGLContextUpdate();
-private slots:
- void updateOpenGLContext();
-#endif
-
-private:
- QDeclarativeVideoRendererBackend *m_backend;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_window.cpp b/src/qtmultimediaquicktools/qdeclarativevideooutput_window.cpp
deleted file mode 100644
index bae29e14c..000000000
--- a/src/qtmultimediaquicktools/qdeclarativevideooutput_window.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativevideooutput_window_p.h"
-#include "qdeclarativevideooutput_p.h"
-#include <QtQuick/qquickwindow.h>
-#include <QtMultimedia/qmediaservice.h>
-#include <QtMultimedia/qvideowindowcontrol.h>
-
-QT_BEGIN_NAMESPACE
-
-QDeclarativeVideoWindowBackend::QDeclarativeVideoWindowBackend(QDeclarativeVideoOutput *parent)
- : QDeclarativeVideoBackend(parent),
- m_visible(true)
-{
-}
-
-QDeclarativeVideoWindowBackend::~QDeclarativeVideoWindowBackend()
-{
- releaseSource();
- releaseControl();
-}
-
-bool QDeclarativeVideoWindowBackend::init(QMediaService *service)
-{
- if (QMediaControl *control = service->requestControl(QVideoWindowControl_iid)) {
- if ((m_videoWindowControl = qobject_cast<QVideoWindowControl *>(control))) {
- if (q->window())
- m_videoWindowControl->setWinId(q->window()->winId());
- m_service = service;
- QObject::connect(m_videoWindowControl.data(), SIGNAL(nativeSizeChanged()),
- q, SLOT(_q_updateNativeSize()));
- return true;
- }
- }
- return false;
-}
-
-void QDeclarativeVideoWindowBackend::itemChange(QQuickItem::ItemChange change,
- const QQuickItem::ItemChangeData &changeData)
-{
- if (!m_videoWindowControl)
- return;
-
- switch (change) {
- case QQuickItem::ItemVisibleHasChanged:
- m_visible = changeData.boolValue;
- updateGeometry();
- break;
- case QQuickItem::ItemSceneChange:
- if (changeData.window)
- m_videoWindowControl->setWinId(changeData.window->winId());
- else
- m_videoWindowControl->setWinId(0);
- break;
- default: break;
- }
-}
-
-void QDeclarativeVideoWindowBackend::releaseSource()
-{
-}
-
-void QDeclarativeVideoWindowBackend::releaseControl()
-{
- if (m_videoWindowControl) {
- m_videoWindowControl->setWinId(0);
- if (m_service)
- m_service->releaseControl(m_videoWindowControl);
- m_videoWindowControl = 0;
- }
-}
-
-QSize QDeclarativeVideoWindowBackend::nativeSize() const
-{
- return m_videoWindowControl->nativeSize();
-}
-
-void QDeclarativeVideoWindowBackend::updateGeometry()
-{
- switch (q->fillMode()) {
- case QDeclarativeVideoOutput::PreserveAspectFit:
- m_videoWindowControl->setAspectRatioMode(Qt::KeepAspectRatio); break;
- case QDeclarativeVideoOutput::PreserveAspectCrop:
- m_videoWindowControl->setAspectRatioMode(Qt::KeepAspectRatioByExpanding); break;
- case QDeclarativeVideoOutput::Stretch:
- m_videoWindowControl->setAspectRatioMode(Qt::IgnoreAspectRatio); break;
- };
-
- const QRectF canvasRect = q->mapRectToScene(QRectF(0, 0, q->width(), q->height()));
- m_videoWindowControl->setDisplayRect(m_visible ? canvasRect.toAlignedRect() : QRect());
-}
-
-QSGNode *QDeclarativeVideoWindowBackend::updatePaintNode(QSGNode *oldNode,
- QQuickItem::UpdatePaintNodeData *data)
-{
- Q_UNUSED(oldNode);
- Q_UNUSED(data);
- m_videoWindowControl->repaint();
- return 0;
-}
-
-QAbstractVideoSurface *QDeclarativeVideoWindowBackend::videoSurface() const
-{
- return 0;
-}
-
-QRectF QDeclarativeVideoWindowBackend::adjustedViewport() const
-{
- // No viewport supported by QVideoWindowControl, so make the viewport the same size
- // as the source
- return QRectF(QPointF(0, 0), nativeSize());
-}
-
-QT_END_NAMESPACE
diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_window_p.h b/src/qtmultimediaquicktools/qdeclarativevideooutput_window_p.h
deleted file mode 100644
index eb1814b07..000000000
--- a/src/qtmultimediaquicktools/qdeclarativevideooutput_window_p.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEVIDEOOUTPUT_WINDOW_P_H
-#define QDECLARATIVEVIDEOOUTPUT_WINDOW_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qdeclarativevideooutput_backend_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QVideoWindowControl;
-
-class QDeclarativeVideoWindowBackend : public QDeclarativeVideoBackend
-{
-public:
- QDeclarativeVideoWindowBackend(QDeclarativeVideoOutput *parent);
- ~QDeclarativeVideoWindowBackend();
-
- bool init(QMediaService *service) override;
- void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &changeData) override;
- void releaseSource() override;
- void releaseControl() override;
- QSize nativeSize() const override;
- void updateGeometry() override;
- QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) override;
- QAbstractVideoSurface *videoSurface() const override;
- QRectF adjustedViewport() const override;
-
-private:
- QPointer<QVideoWindowControl> m_videoWindowControl;
- bool m_visible;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/qtmultimediaquicktools/qsgvideonode_p.cpp b/src/qtmultimediaquicktools/qsgvideonode_p.cpp
deleted file mode 100644
index eb2b0c1a9..000000000
--- a/src/qtmultimediaquicktools/qsgvideonode_p.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qsgvideonode_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QSGVideoNode::QSGVideoNode()
- : m_orientation(-1)
-{
- setFlag(QSGNode::OwnsGeometry);
-}
-
-/* Helpers */
-static inline void qSetGeom(QSGGeometry::TexturedPoint2D *v, const QPointF &p)
-{
- v->x = p.x();
- v->y = p.y();
-}
-
-static inline void qSetTex(QSGGeometry::TexturedPoint2D *v, const QPointF &p)
-{
- v->tx = p.x();
- v->ty = p.y();
-}
-
-/* Update the vertices and texture coordinates. Orientation must be in {0,90,180,270} */
-void QSGVideoNode::setTexturedRectGeometry(const QRectF &rect, const QRectF &textureRect, int orientation)
-{
- if (rect == m_rect && textureRect == m_textureRect && orientation == m_orientation)
- return;
-
- m_rect = rect;
- m_textureRect = textureRect;
- m_orientation = orientation;
-
- QSGGeometry *g = geometry();
-
- if (g == 0)
- g = new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4);
-
- QSGGeometry::TexturedPoint2D *v = g->vertexDataAsTexturedPoint2D();
-
- // Set geometry first
- qSetGeom(v + 0, rect.topLeft());
- qSetGeom(v + 1, rect.bottomLeft());
- qSetGeom(v + 2, rect.topRight());
- qSetGeom(v + 3, rect.bottomRight());
-
- // and then texture coordinates
- switch (orientation) {
- default:
- // tl, bl, tr, br
- qSetTex(v + 0, textureRect.topLeft());
- qSetTex(v + 1, textureRect.bottomLeft());
- qSetTex(v + 2, textureRect.topRight());
- qSetTex(v + 3, textureRect.bottomRight());
- break;
-
- case 90:
- // tr, tl, br, bl
- qSetTex(v + 0, textureRect.topRight());
- qSetTex(v + 1, textureRect.topLeft());
- qSetTex(v + 2, textureRect.bottomRight());
- qSetTex(v + 3, textureRect.bottomLeft());
- break;
-
- case 180:
- // br, tr, bl, tl
- qSetTex(v + 0, textureRect.bottomRight());
- qSetTex(v + 1, textureRect.topRight());
- qSetTex(v + 2, textureRect.bottomLeft());
- qSetTex(v + 3, textureRect.topLeft());
- break;
-
- case 270:
- // bl, br, tl, tr
- qSetTex(v + 0, textureRect.bottomLeft());
- qSetTex(v + 1, textureRect.bottomRight());
- qSetTex(v + 2, textureRect.topLeft());
- qSetTex(v + 3, textureRect.topRight());
- break;
- }
-
- if (!geometry())
- setGeometry(g);
-
- markDirty(DirtyGeometry);
-}
-
-QSGVideoNodeFactoryInterface::~QSGVideoNodeFactoryInterface()
-{
-}
-
-QT_END_NAMESPACE
diff --git a/src/qtmultimediaquicktools/qsgvideonode_p.h b/src/qtmultimediaquicktools/qsgvideonode_p.h
deleted file mode 100644
index c094bed1f..000000000
--- a/src/qtmultimediaquicktools/qsgvideonode_p.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSGVIDEONODE_P_H
-#define QSGVIDEONODE_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtQuick/qsgnode.h>
-#include <private/qtmultimediaquickdefs_p.h>
-
-#include <QtMultimedia/qvideoframe.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
-#include <QtGui/qopenglfunctions.h>
-
-QT_BEGIN_NAMESPACE
-
-class Q_MULTIMEDIAQUICK_EXPORT QSGVideoNode : public QSGGeometryNode
-{
-public:
- enum FrameFlag {
- FrameFiltered = 0x01
- };
- Q_DECLARE_FLAGS(FrameFlags, FrameFlag)
-
- QSGVideoNode();
-
- virtual void setCurrentFrame(const QVideoFrame &frame, FrameFlags flags) = 0;
- virtual QVideoFrame::PixelFormat pixelFormat() const = 0;
- virtual QAbstractVideoBuffer::HandleType handleType() const = 0;
-
- void setTexturedRectGeometry(const QRectF &boundingRect, const QRectF &textureRect, int orientation);
-
-private:
- QRectF m_rect;
- QRectF m_textureRect;
- int m_orientation;
-};
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(QSGVideoNode::FrameFlags)
-
-class Q_MULTIMEDIAQUICK_EXPORT QSGVideoNodeFactoryInterface
-{
-public:
- virtual ~QSGVideoNodeFactoryInterface();
-
- virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const = 0;
- virtual QSGVideoNode *createNode(const QVideoSurfaceFormat &format) = 0;
-};
-
-#define QSGVideoNodeFactoryInterface_iid "org.qt-project.qt.sgvideonodefactory/5.2"
-Q_DECLARE_INTERFACE(QSGVideoNodeFactoryInterface, QSGVideoNodeFactoryInterface_iid)
-
-class Q_MULTIMEDIAQUICK_EXPORT QSGVideoNodeFactoryPlugin : public QObject, public QSGVideoNodeFactoryInterface
-{
- Q_OBJECT
- Q_INTERFACES(QSGVideoNodeFactoryInterface)
-public:
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const override = 0;
- QSGVideoNode *createNode(const QVideoSurfaceFormat &format) override = 0;
-};
-
-QT_END_NAMESPACE
-
-#endif // QSGVIDEONODE_H
diff --git a/src/qtmultimediaquicktools/qsgvideonode_rgb.cpp b/src/qtmultimediaquicktools/qsgvideonode_rgb.cpp
deleted file mode 100644
index c9f27869c..000000000
--- a/src/qtmultimediaquicktools/qsgvideonode_rgb.cpp
+++ /dev/null
@@ -1,205 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "qsgvideonode_rgb_p.h"
-#include "qsgvideotexture_p.h"
-#include <QtQuick/qsgmaterial.h>
-#include <QtCore/qmutex.h>
-
-QT_BEGIN_NAMESPACE
-
-QList<QVideoFrame::PixelFormat> QSGVideoNodeFactory_RGB::supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const
-{
- QList<QVideoFrame::PixelFormat> pixelFormats;
-
- if (handleType == QAbstractVideoBuffer::NoHandle) {
- pixelFormats.append(QVideoFrame::Format_RGB32);
- pixelFormats.append(QVideoFrame::Format_ARGB32);
- pixelFormats.append(QVideoFrame::Format_BGR32);
- pixelFormats.append(QVideoFrame::Format_BGRA32);
- pixelFormats.append(QVideoFrame::Format_RGB565);
- }
-
- return pixelFormats;
-}
-
-QSGVideoNode *QSGVideoNodeFactory_RGB::createNode(const QVideoSurfaceFormat &format)
-{
- if (supportedPixelFormats(format.handleType()).contains(format.pixelFormat()))
- return new QSGVideoNode_RGB(format);
-
- return 0;
-}
-
-class QSGVideoMaterialRhiShader_RGB : public QSGMaterialShader
-{
-public:
- QSGVideoMaterialRhiShader_RGB()
- {
- setShaderFileName(VertexStage, QStringLiteral(":/qtmultimediaquicktools/shaders/rgba.vert.qsb"));
- setShaderFileName(FragmentStage, QStringLiteral(":/qtmultimediaquicktools/shaders/rgba.frag.qsb"));
- }
-
- bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
- QSGMaterial *oldMaterial) override;
-
- void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
- QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
-};
-
-class QSGVideoMaterial_RGB : public QSGMaterial
-{
-public:
- QSGVideoMaterial_RGB(const QVideoSurfaceFormat &format) :
- m_format(format),
- m_opacity(1.0)
- {
- setFlag(Blending, false);
- m_texture.reset(new QSGVideoTexture);
- }
-
- QSGMaterialType *type() const override {
- static QSGMaterialType normalType;
- return &normalType;
- }
-
- QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override {
- return new QSGVideoMaterialRhiShader_RGB;
- }
-
- int compare(const QSGMaterial *other) const override {
- const QSGVideoMaterial_RGB *m = static_cast<const QSGVideoMaterial_RGB *>(other);
-
- const qint64 diff = m_texture->comparisonKey() - m->m_texture->comparisonKey();
- return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
- }
-
- void updateBlending() {
- setFlag(Blending, !qFuzzyCompare(m_opacity, float(1.0)));
- }
-
- void setVideoFrame(const QVideoFrame &frame) {
- QMutexLocker lock(&m_frameMutex);
- m_frame = frame;
- }
-
- QVideoFrame m_frame;
- QMutex m_frameMutex;
- QSize m_textureSize;
- QVideoSurfaceFormat m_format;
- float m_opacity;
- QScopedPointer<QSGVideoTexture> m_texture;
-};
-
-bool QSGVideoMaterialRhiShader_RGB::updateUniformData(RenderState &state, QSGMaterial *newMaterial,
- QSGMaterial *oldMaterial)
-{
- Q_UNUSED(oldMaterial);
-
- bool changed = false;
- QByteArray *buf = state.uniformData();
-
- if (state.isMatrixDirty()) {
- memcpy(buf->data(), state.combinedMatrix().constData(), 64);
- changed = true;
- }
-
- if (state.isOpacityDirty()) {
- auto m = static_cast<QSGVideoMaterial_RGB *>(newMaterial);
- m->m_opacity = state.opacity();
- m->updateBlending();
- memcpy(buf->data() + 64, &m->m_opacity, 4);
- changed = true;
- }
-
- return changed;
-}
-
-void QSGVideoMaterialRhiShader_RGB::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
- QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
-{
- Q_UNUSED(oldMaterial);
-
- if (binding < 1)
- return;
-
- auto m = static_cast<QSGVideoMaterial_RGB *>(newMaterial);
-
- m->m_frameMutex.lock();
- auto frame = m->m_frame;
-
- if (frame.pixelFormat() == QVideoFrame::Format_RGB565) // Format_RGB565 requires GL_UNSIGNED_SHORT_5_6_5
- frame = frame.image().convertToFormat(QImage::Format_RGBA8888_Premultiplied);
-
- auto format = QRhiTexture::RGBA8;
- if (frame.pixelFormat() == QVideoFrame::Format_RGB32
- || frame.pixelFormat() == QVideoFrame::Format_ARGB32)
- {
- format = QRhiTexture::BGRA8;
- }
-
- if (frame.isValid() && frame.map(QAbstractVideoBuffer::ReadOnly)) {
- m->m_texture->setData(format, frame.size(), frame.bits(), frame.bytesPerLine() * frame.height());
- frame.unmap();
- }
- m->m_frameMutex.unlock();
-
- m->m_texture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
- *texture = m->m_texture.data();
-}
-
-QSGVideoNode_RGB::QSGVideoNode_RGB(const QVideoSurfaceFormat &format) :
- m_format(format)
-{
- setFlag(QSGNode::OwnsMaterial);
- m_material = new QSGVideoMaterial_RGB(format);
- setMaterial(m_material);
-}
-
-QSGVideoNode_RGB::~QSGVideoNode_RGB()
-{
-}
-
-void QSGVideoNode_RGB::setCurrentFrame(const QVideoFrame &frame, FrameFlags)
-{
- m_material->setVideoFrame(frame);
- markDirty(DirtyMaterial);
-}
-
-QT_END_NAMESPACE
diff --git a/src/qtmultimediaquicktools/qsgvideonode_rgb_p.h b/src/qtmultimediaquicktools/qsgvideonode_rgb_p.h
deleted file mode 100644
index 95b74be0b..000000000
--- a/src/qtmultimediaquicktools/qsgvideonode_rgb_p.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSGVIDEONODE_RGB_H
-#define QSGVIDEONODE_RGB_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qsgvideonode_p.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
-
-QT_BEGIN_NAMESPACE
-
-class QSGVideoMaterial_RGB;
-
-class QSGVideoNode_RGB : public QSGVideoNode
-{
-public:
- QSGVideoNode_RGB(const QVideoSurfaceFormat &format);
- ~QSGVideoNode_RGB();
-
- QVideoFrame::PixelFormat pixelFormat() const override {
- return m_format.pixelFormat();
- }
- QAbstractVideoBuffer::HandleType handleType() const override {
- return QAbstractVideoBuffer::NoHandle;
- }
- void setCurrentFrame(const QVideoFrame &frame, FrameFlags flags) override;
-
-private:
- QVideoSurfaceFormat m_format;
- QSGVideoMaterial_RGB *m_material;
- QVideoFrame m_frame;
-};
-
-class QSGVideoNodeFactory_RGB : public QSGVideoNodeFactoryInterface {
-public:
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const override;
- QSGVideoNode *createNode(const QVideoSurfaceFormat &format) override;
-};
-
-QT_END_NAMESPACE
-
-#endif // QSGVIDEONODE_RGB_H
diff --git a/src/qtmultimediaquicktools/qsgvideonode_texture.cpp b/src/qtmultimediaquicktools/qsgvideonode_texture.cpp
deleted file mode 100644
index 68e0d2d1a..000000000
--- a/src/qtmultimediaquicktools/qsgvideonode_texture.cpp
+++ /dev/null
@@ -1,229 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "qsgvideonode_texture_p.h"
-#include "qsgvideotexture_p.h"
-#include <private/qsgrhisupport_p.h>
-#include <QtQuick/qsgmaterial.h>
-#include <QtCore/qmutex.h>
-#include <QtMultimedia/private/qtmultimediaglobal_p.h>
-
-QT_BEGIN_NAMESPACE
-
-QList<QVideoFrame::PixelFormat> QSGVideoNodeFactory_Texture::supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const
-{
- QList<QVideoFrame::PixelFormat> pixelFormats;
-
- QList<QAbstractVideoBuffer::HandleType> types;
-
- auto rhi = QSGRhiSupport::instance();
- auto metalEnabled = rhi->isRhiEnabled() && rhi->rhiBackend() == QRhi::Metal;
- if (metalEnabled)
- types.append(QAbstractVideoBuffer::MTLTextureHandle);
-
-#if QT_CONFIG(opengl)
- types.append(QAbstractVideoBuffer::GLTextureHandle);
-#endif
-
- if (types.contains(handleType)) {
- pixelFormats.append(QVideoFrame::Format_RGB565);
- pixelFormats.append(QVideoFrame::Format_RGB32);
- pixelFormats.append(QVideoFrame::Format_ARGB32);
- pixelFormats.append(QVideoFrame::Format_BGR32);
- pixelFormats.append(QVideoFrame::Format_BGRA32);
-#if !QT_CONFIG(gpu_vivante)
- pixelFormats.append(QVideoFrame::Format_ABGR32);
-#endif
- }
-
- return pixelFormats;
-}
-
-QSGVideoNode *QSGVideoNodeFactory_Texture::createNode(const QVideoSurfaceFormat &format)
-{
- if (supportedPixelFormats(format.handleType()).contains(format.pixelFormat()))
- return new QSGVideoNode_Texture(format);
-
- return 0;
-}
-
-class QSGVideoMaterialRhiShader_Texture : public QSGMaterialShader
-{
-public:
- QSGVideoMaterialRhiShader_Texture()
- {
- setShaderFileName(VertexStage, QStringLiteral(":/qtmultimediaquicktools/shaders/rgba.vert.qsb"));
- setShaderFileName(FragmentStage, QStringLiteral(":/qtmultimediaquicktools/shaders/rgba.frag.qsb"));
- }
-
- bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
- QSGMaterial *oldMaterial) override;
-
- void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
- QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
-};
-
-class QSGVideoMaterialRhiShader_Texture_swizzle : public QSGVideoMaterialRhiShader_Texture
-{
-public:
- QSGVideoMaterialRhiShader_Texture_swizzle()
- {
- setShaderFileName(FragmentStage, QStringLiteral(":/qtmultimediaquicktools/shaders/bgra.frag.qsb"));
- }
-};
-
-class QSGVideoMaterial_Texture : public QSGMaterial
-{
-public:
- QSGVideoMaterial_Texture(const QVideoSurfaceFormat &format) :
- m_format(format),
- m_opacity(1.0)
- {
- setFlag(Blending, false);
- m_texture.reset(new QSGVideoTexture);
- }
-
- ~QSGVideoMaterial_Texture()
- {
- }
-
- QSGMaterialType *type() const override {
- static QSGMaterialType normalType, swizzleType;
- return needsSwizzling() ? &swizzleType : &normalType;
- }
-
- QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override {
- return needsSwizzling() ? new QSGVideoMaterialRhiShader_Texture_swizzle
- : new QSGVideoMaterialRhiShader_Texture;
- }
-
- int compare(const QSGMaterial *other) const override {
- const QSGVideoMaterial_Texture *m = static_cast<const QSGVideoMaterial_Texture *>(other);
-
- const qint64 diff = m_texture->comparisonKey() - m->m_texture->comparisonKey();
- return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
- }
-
- void updateBlending() {
- setFlag(Blending, qFuzzyCompare(m_opacity, float(1.0)) ? false : true);
- }
-
- void setVideoFrame(const QVideoFrame &frame) {
- QMutexLocker lock(&m_frameMutex);
- m_frame = frame;
- }
-
- QVideoFrame m_frame;
- QMutex m_frameMutex;
- QVideoSurfaceFormat m_format;
- quint64 m_textureId;
- float m_opacity;
- QScopedPointer<QSGVideoTexture> m_texture;
-
-private:
- bool needsSwizzling() const {
- return m_format.pixelFormat() == QVideoFrame::Format_RGB32
- || m_format.pixelFormat() == QVideoFrame::Format_ARGB32;
- }
-};
-
-bool QSGVideoMaterialRhiShader_Texture::updateUniformData(RenderState &state, QSGMaterial *newMaterial,
- QSGMaterial *oldMaterial)
-{
- Q_UNUSED(oldMaterial);
-
- bool changed = false;
- QByteArray *buf = state.uniformData();
-
- if (state.isMatrixDirty()) {
- memcpy(buf->data(), state.combinedMatrix().constData(), 64);
- changed = true;
- }
-
- if (state.isOpacityDirty()) {
- auto m = static_cast<QSGVideoMaterial_Texture *>(newMaterial);
- m->m_opacity = state.opacity();
- m->updateBlending();
- memcpy(buf->data() + 64, &m->m_opacity, 4);
- changed = true;
- }
-
- return changed;
-}
-
-void QSGVideoMaterialRhiShader_Texture::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
- QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
-{
- Q_UNUSED(oldMaterial);
-
- if (binding < 1)
- return;
-
- auto m = static_cast<QSGVideoMaterial_Texture *>(newMaterial);
-
- m->m_frameMutex.lock();
- auto size = m->m_frame.size();
- if (m->m_frame.isValid())
- m->m_textureId = m->m_frame.handle().toULongLong();
- m->m_frameMutex.unlock();
-
- m->m_texture->setNativeObject(m->m_textureId, size);
- m->m_texture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
- *texture = m->m_texture.data();
-}
-
-QSGVideoNode_Texture::QSGVideoNode_Texture(const QVideoSurfaceFormat &format) :
- m_format(format)
-{
- setFlag(QSGNode::OwnsMaterial);
- m_material = new QSGVideoMaterial_Texture(format);
- setMaterial(m_material);
-}
-
-QSGVideoNode_Texture::~QSGVideoNode_Texture()
-{
-}
-
-void QSGVideoNode_Texture::setCurrentFrame(const QVideoFrame &frame, FrameFlags)
-{
- m_material->setVideoFrame(frame);
- markDirty(DirtyMaterial);
-}
-
-QT_END_NAMESPACE
diff --git a/src/qtmultimediaquicktools/qsgvideonode_texture_p.h b/src/qtmultimediaquicktools/qsgvideonode_texture_p.h
deleted file mode 100644
index d7348473e..000000000
--- a/src/qtmultimediaquicktools/qsgvideonode_texture_p.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSGVIDEONODE_TEXTURE_H
-#define QSGVIDEONODE_TEXTURE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qsgvideonode_p.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
-
-QT_BEGIN_NAMESPACE
-
-class QSGVideoMaterial_Texture;
-
-class QSGVideoNode_Texture : public QSGVideoNode
-{
-public:
- QSGVideoNode_Texture(const QVideoSurfaceFormat &format);
- ~QSGVideoNode_Texture();
-
- QVideoFrame::PixelFormat pixelFormat() const override {
- return m_format.pixelFormat();
- }
- QAbstractVideoBuffer::HandleType handleType() const override {
- return m_format.handleType();
- }
- void setCurrentFrame(const QVideoFrame &frame, FrameFlags flags) override;
-
-private:
- QVideoSurfaceFormat m_format;
- QSGVideoMaterial_Texture *m_material;
- QVideoFrame m_frame;
-};
-
-class QSGVideoNodeFactory_Texture : public QSGVideoNodeFactoryInterface {
-public:
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const override;
- QSGVideoNode *createNode(const QVideoSurfaceFormat &format) override;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/qtmultimediaquicktools/qsgvideonode_yuv.cpp b/src/qtmultimediaquicktools/qsgvideonode_yuv.cpp
deleted file mode 100644
index bce757584..000000000
--- a/src/qtmultimediaquicktools/qsgvideonode_yuv.cpp
+++ /dev/null
@@ -1,407 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "qsgvideonode_yuv_p.h"
-#include "qsgvideotexture_p.h"
-#include <QtCore/qmutex.h>
-#include <QtQuick/qsgmaterial.h>
-
-QT_BEGIN_NAMESPACE
-
-QList<QVideoFrame::PixelFormat> QSGVideoNodeFactory_YUV::supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const
-{
- QList<QVideoFrame::PixelFormat> formats;
-
- if (handleType == QAbstractVideoBuffer::NoHandle) {
- formats << QVideoFrame::Format_YUV420P << QVideoFrame::Format_YV12 << QVideoFrame::Format_YUV422P
- << QVideoFrame::Format_NV12 << QVideoFrame::Format_NV21
- << QVideoFrame::Format_UYVY << QVideoFrame::Format_YUYV;
- } else if (handleType == QAbstractVideoBuffer::GLTextureHandle) {
- formats << QVideoFrame::Format_NV12 << QVideoFrame::Format_NV21;
- } else if (handleType == QAbstractVideoBuffer::MTLTextureHandle) {
- formats << QVideoFrame::Format_NV12 << QVideoFrame::Format_NV21;
- }
-
- return formats;
-}
-
-QSGVideoNode *QSGVideoNodeFactory_YUV::createNode(const QVideoSurfaceFormat &format)
-{
- if (supportedPixelFormats(format.handleType()).contains(format.pixelFormat()))
- return new QSGVideoNode_YUV(format);
-
- return 0;
-}
-
-class QSGVideoMaterialRhiShader_YUV : public QSGMaterialShader
-{
-public:
- QSGVideoMaterialRhiShader_YUV()
- {
- setShaderFileName(VertexStage, QStringLiteral(":/qtmultimediaquicktools/shaders/yuv.vert.qsb"));
- }
-
- bool updateUniformData(RenderState &state, QSGMaterial *newMaterial,
- QSGMaterial *oldMaterial) override;
-
- void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
- QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
-
- virtual void mapFrame(QSGVideoMaterial_YUV *) = 0;
-
-protected:
- float m_planeWidth[3] = {0, 0, 0};
- QMatrix4x4 m_colorMatrix;
-};
-
-class QSGVideoMaterialRhiShader_UYVY : public QSGVideoMaterialRhiShader_YUV
-{
-public:
- QSGVideoMaterialRhiShader_UYVY()
- {
- setShaderFileName(FragmentStage, QStringLiteral(":/qtmultimediaquicktools/shaders/uyvy.frag.qsb"));
- }
-
- void mapFrame(QSGVideoMaterial_YUV *m) override;
-};
-
-class QSGVideoMaterialRhiShader_YUYV : public QSGVideoMaterialRhiShader_UYVY
-{
-public:
- QSGVideoMaterialRhiShader_YUYV()
- {
- setShaderFileName(FragmentStage, QStringLiteral(":/qtmultimediaquicktools/shaders/yuyv.frag.qsb"));
- }
-};
-
-class QSGVideoMaterialRhiShader_YUV_YV : public QSGVideoMaterialRhiShader_YUV
-{
-public:
- QSGVideoMaterialRhiShader_YUV_YV()
- {
- setShaderFileName(FragmentStage, QStringLiteral(":/qtmultimediaquicktools/shaders/yuv_yv.frag.qsb"));
- }
-
- void mapFrame(QSGVideoMaterial_YUV *m) override;
-};
-
-class QSGVideoMaterialRhiShader_NV12 : public QSGVideoMaterialRhiShader_YUV
-{
-public:
- QSGVideoMaterialRhiShader_NV12()
- {
- setShaderFileName(FragmentStage, QStringLiteral(":/qtmultimediaquicktools/shaders/nv12.frag.qsb"));
- }
-
- void mapFrame(QSGVideoMaterial_YUV *m) override;
-};
-
-class QSGVideoMaterialRhiShader_NV21 : public QSGVideoMaterialRhiShader_NV12
-{
-public:
- QSGVideoMaterialRhiShader_NV21()
- {
- setShaderFileName(FragmentStage, QStringLiteral(":/qtmultimediaquicktools/shaders/nv21.frag.qsb"));
- }
-};
-
-class QSGVideoMaterial_YUV : public QSGMaterial
-{
-public:
- QSGVideoMaterial_YUV(const QVideoSurfaceFormat &format);
-
- QSGMaterialType *type() const override {
- static QSGMaterialType biPlanarType, biPlanarSwizzleType, triPlanarType, uyvyType, yuyvType;
-
- switch (m_format.pixelFormat()) {
- case QVideoFrame::Format_NV12:
- return &biPlanarType;
- case QVideoFrame::Format_NV21:
- return &biPlanarSwizzleType;
- case QVideoFrame::Format_UYVY:
- return &uyvyType;
- case QVideoFrame::Format_YUYV:
- return &yuyvType;
- default: // Currently: YUV420P, YUV422P and YV12
- return &triPlanarType;
- }
- }
-
- QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override {
- switch (m_format.pixelFormat()) {
- case QVideoFrame::Format_NV12:
- return new QSGVideoMaterialRhiShader_NV12;
- case QVideoFrame::Format_NV21:
- return new QSGVideoMaterialRhiShader_NV21;
- case QVideoFrame::Format_UYVY:
- return new QSGVideoMaterialRhiShader_UYVY;
- case QVideoFrame::Format_YUYV:
- return new QSGVideoMaterialRhiShader_YUYV;
- default: // Currently: YUV420P, YUV422P and YV12
- return new QSGVideoMaterialRhiShader_YUV_YV;
- }
- }
-
- int compare(const QSGMaterial *other) const override {
- const QSGVideoMaterial_YUV *m = static_cast<const QSGVideoMaterial_YUV *>(other);
-
- qint64 diff = m_textures[0]->comparisonKey() - m->m_textures[0]->comparisonKey();
- if (!diff)
- diff = m_textures[1]->comparisonKey() - m->m_textures[1]->comparisonKey();
- if (!diff)
- diff = m_textures[2]->comparisonKey() - m->m_textures[2]->comparisonKey();
-
- return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
- }
-
- void updateBlending() {
- setFlag(Blending, !qFuzzyCompare(m_opacity, float(1.0)));
- }
-
- void setCurrentFrame(const QVideoFrame &frame) {
- QMutexLocker lock(&m_frameMutex);
- m_frame = frame;
- }
-
- QVideoSurfaceFormat m_format;
- float m_planeWidth[3];
- float m_opacity;
- QMatrix4x4 m_colorMatrix;
- QVideoFrame m_frame;
- QMutex m_frameMutex;
- QScopedPointer<QSGVideoTexture> m_textures[3];
-};
-
-bool QSGVideoMaterialRhiShader_YUV::updateUniformData(RenderState &state, QSGMaterial *newMaterial,
- QSGMaterial *oldMaterial)
-{
- Q_UNUSED(oldMaterial);
-
- auto m = static_cast<QSGVideoMaterial_YUV *>(newMaterial);
- bool changed = false;
- QByteArray *buf = state.uniformData();
-
- if (state.isMatrixDirty()) {
- memcpy(buf->data(), state.combinedMatrix().constData(), 64);
- changed = true;
- }
-
- if (m->m_colorMatrix != m_colorMatrix) {
- memcpy(buf->data() + 64, m->m_colorMatrix.constData(), 64);
- changed = true;
- }
- m_colorMatrix = m->m_colorMatrix;
-
- if (state.isOpacityDirty()) {
- m->m_opacity = state.opacity();
- m->updateBlending();
- memcpy(buf->data() + 64 + 64, &m->m_opacity, 4);
- changed = true;
- }
-
- m->m_frameMutex.lock();
- mapFrame(m);
- m->m_frameMutex.unlock();
-
- if (!qFuzzyCompare(m->m_planeWidth[0], m_planeWidth[0])
- || !qFuzzyCompare(m->m_planeWidth[1], m_planeWidth[1])
- || !qFuzzyCompare(m->m_planeWidth[2], m_planeWidth[2]))
- {
- memcpy(buf->data() + 64 + 64 + 4, &m->m_planeWidth[0], 4);
- memcpy(buf->data() + 64 + 64 + 4 + 4, &m->m_planeWidth[1], 4);
- memcpy(buf->data() + 64 + 64 + 4 + 4 + 4, &m->m_planeWidth[2], 4);
- changed = true;
- }
- m_planeWidth[0] = m->m_planeWidth[0];
- m_planeWidth[1] = m->m_planeWidth[1];
- m_planeWidth[2] = m->m_planeWidth[2];
-
- return changed;
-}
-
-void QSGVideoMaterialRhiShader_YUV::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
- QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
-{
- Q_UNUSED(oldMaterial);
- if (binding < 1 || binding > 3)
- return;
-
- auto m = static_cast<QSGVideoMaterial_YUV *>(newMaterial);
- *texture = m->m_textures[binding - 1].data();
- (*texture)->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
-}
-
-void QSGVideoMaterialRhiShader_UYVY::mapFrame(QSGVideoMaterial_YUV *m)
-{
- if (!m->m_frame.isValid() || !m->m_frame.map(QAbstractVideoBuffer::ReadOnly))
- return;
-
- int fw = m->m_frame.width();
- int fh = m->m_frame.height();
-
- m->m_planeWidth[0] = 1;
- m->m_planeWidth[1] = 1;
-
- // Either r,b (YUYV) or g,a (UYVY) values are used as source of UV.
- // Additionally U and V are set per 2 pixels hence only 1/2 of image width is used.
- m->m_textures[0]->setData(QRhiTexture::RG8, m->m_frame.size(),
- m->m_frame.bits(), m->m_frame.bytesPerLine() * fh);
- m->m_textures[1]->setData(QRhiTexture::RGBA8, QSize(fw / 2, fh),
- m->m_frame.bits(), m->m_frame.bytesPerLine() * fh);
-
- m->m_frame.unmap();
-}
-
-void QSGVideoMaterialRhiShader_YUV_YV::mapFrame(QSGVideoMaterial_YUV *m)
-{
- if (!m->m_frame.isValid() || !m->m_frame.map(QAbstractVideoBuffer::ReadOnly))
- return;
-
- int y = 0;
- int u = m->m_frame.pixelFormat() == QVideoFrame::Format_YV12 ? 2 : 1;
- int v = m->m_frame.pixelFormat() == QVideoFrame::Format_YV12 ? 1 : 2;
- int fw = m->m_frame.width();
- int fh = m->m_frame.height();
- int uvHeight = m->m_frame.pixelFormat() == QVideoFrame::Format_YUV422P ? fh : fh / 2;
-
- m->m_planeWidth[0] = float(fw) / m->m_frame.bytesPerLine(y);
- m->m_planeWidth[1] = m->m_planeWidth[2] = float(fw) / (2 * m->m_frame.bytesPerLine(u));
-
- m->m_textures[0]->setData(QRhiTexture::R8, QSize(m->m_frame.bytesPerLine(y), fh),
- m->m_frame.bits(y), m->m_frame.bytesPerLine(y) * fh);
- m->m_textures[1]->setData(QRhiTexture::R8, QSize(m->m_frame.bytesPerLine(u), uvHeight),
- m->m_frame.bits(u), m->m_frame.bytesPerLine(u) * uvHeight);
- m->m_textures[2]->setData(QRhiTexture::R8, QSize(m->m_frame.bytesPerLine(v), uvHeight),
- m->m_frame.bits(v), m->m_frame.bytesPerLine(v) * uvHeight);
-
- m->m_frame.unmap();
-}
-
-void QSGVideoMaterialRhiShader_NV12::mapFrame(QSGVideoMaterial_YUV *m)
-{
- if (!m->m_frame.isValid())
- return;
-
- if (m->m_frame.handleType() == QAbstractVideoBuffer::GLTextureHandle || m->m_frame.handleType() == QAbstractVideoBuffer::MTLTextureHandle) {
- m->m_planeWidth[0] = m->m_planeWidth[1] = 1;
- auto textures = m->m_frame.handle().toList();
- if (!textures.isEmpty()) {
- auto w = m->m_frame.size().width();
- auto h = m->m_frame.size().height();
- m->m_textures[0]->setNativeObject(textures[0].toULongLong(), {w, h});
- m->m_textures[1]->setNativeObject(textures[1].toULongLong(), {w / 2, h / 2});
- } else {
- qWarning() << "NV12/NV21 requires 2 textures";
- }
-
- return;
- }
-
- if (!m->m_frame.map(QAbstractVideoBuffer::ReadOnly))
- return;
-
- int y = 0;
- int uv = 1;
- int fw = m->m_frame.width();
- int fh = m->m_frame.height();
-
- m->m_planeWidth[0] = m->m_planeWidth[1] = qreal(fw) / m->m_frame.bytesPerLine(y);
-
- m->m_textures[0]->setData(QRhiTexture::R8, m->m_frame.size(),
- m->m_frame.bits(y), m->m_frame.bytesPerLine(y) * fh);
- m->m_textures[1]->setData(QRhiTexture::RG8, QSize(m->m_frame.bytesPerLine(uv) / 2 , fh / 2),
- m->m_frame.bits(uv), m->m_frame.bytesPerLine(uv) * fh / 2);
-
- m->m_frame.unmap();
-}
-
-QSGVideoMaterial_YUV::QSGVideoMaterial_YUV(const QVideoSurfaceFormat &format) :
- m_format(format),
- m_opacity(1.0)
-{
- m_textures[0].reset(new QSGVideoTexture);
- m_textures[1].reset(new QSGVideoTexture);
- m_textures[2].reset(new QSGVideoTexture);
-
- switch (format.yCbCrColorSpace()) {
- case QVideoSurfaceFormat::YCbCr_JPEG:
- m_colorMatrix = QMatrix4x4(
- 1.0f, 0.000f, 1.402f, -0.701f,
- 1.0f, -0.344f, -0.714f, 0.529f,
- 1.0f, 1.772f, 0.000f, -0.886f,
- 0.0f, 0.000f, 0.000f, 1.0000f);
- break;
- case QVideoSurfaceFormat::YCbCr_BT709:
- case QVideoSurfaceFormat::YCbCr_xvYCC709:
- m_colorMatrix = QMatrix4x4(
- 1.164f, 0.000f, 1.793f, -0.5727f,
- 1.164f, -0.534f, -0.213f, 0.3007f,
- 1.164f, 2.115f, 0.000f, -1.1302f,
- 0.0f, 0.000f, 0.000f, 1.0000f);
- break;
- default: //BT 601:
- m_colorMatrix = QMatrix4x4(
- 1.164f, 0.000f, 1.596f, -0.8708f,
- 1.164f, -0.392f, -0.813f, 0.5296f,
- 1.164f, 2.017f, 0.000f, -1.081f,
- 0.0f, 0.000f, 0.000f, 1.0000f);
- }
-
- setFlag(Blending, false);
-}
-
-QSGVideoNode_YUV::QSGVideoNode_YUV(const QVideoSurfaceFormat &format) :
- m_format(format)
-{
- setFlag(QSGNode::OwnsMaterial);
- m_material = new QSGVideoMaterial_YUV(format);
- setMaterial(m_material);
-}
-
-QSGVideoNode_YUV::~QSGVideoNode_YUV()
-{
-}
-
-void QSGVideoNode_YUV::setCurrentFrame(const QVideoFrame &frame, FrameFlags)
-{
- m_material->setCurrentFrame(frame);
- markDirty(DirtyMaterial);
-}
-
-QT_END_NAMESPACE
diff --git a/src/qtmultimediaquicktools/qsgvideonode_yuv_p.h b/src/qtmultimediaquicktools/qsgvideonode_yuv_p.h
deleted file mode 100644
index 643f40c71..000000000
--- a/src/qtmultimediaquicktools/qsgvideonode_yuv_p.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSGVIDEONODE_YUV_H
-#define QSGVIDEONODE_YUV_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qsgvideonode_p.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
-
-QT_BEGIN_NAMESPACE
-
-class QSGVideoMaterial_YUV;
-class QSGVideoNode_YUV : public QSGVideoNode
-{
-public:
- QSGVideoNode_YUV(const QVideoSurfaceFormat &format);
- ~QSGVideoNode_YUV();
-
- QVideoFrame::PixelFormat pixelFormat() const override {
- return m_format.pixelFormat();
- }
- QAbstractVideoBuffer::HandleType handleType() const override {
- return QAbstractVideoBuffer::NoHandle;
- }
- void setCurrentFrame(const QVideoFrame &frame, FrameFlags flags) override;
-
-private:
- void bindTexture(int id, int unit, int w, int h, const uchar *bits);
-
- QVideoSurfaceFormat m_format;
- QSGVideoMaterial_YUV *m_material;
-};
-
-class QSGVideoNodeFactory_YUV : public QSGVideoNodeFactoryInterface {
-public:
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const override;
- QSGVideoNode *createNode(const QVideoSurfaceFormat &format) override;
-};
-
-QT_END_NAMESPACE
-
-#endif // QSGVIDEONODE_YUV_H
diff --git a/src/qtmultimediaquicktools/qsgvideotexture.cpp b/src/qtmultimediaquicktools/qsgvideotexture.cpp
deleted file mode 100644
index 92b9245cb..000000000
--- a/src/qtmultimediaquicktools/qsgvideotexture.cpp
+++ /dev/null
@@ -1,166 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qsgvideotexture_p.h"
-#include <QtQuick/qsgtexturematerial.h>
-#include <QtQuick/qsgmaterial.h>
-
-QT_BEGIN_NAMESPACE
-
-class QSGVideoTexturePrivate
-{
- Q_DECLARE_PUBLIC(QSGVideoTexture)
-public:
- void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates);
-
-private:
- QSGVideoTexture *q_ptr = nullptr;
- QRhiTexture::Format m_format;
- QSize m_size;
- QByteArray m_data;
-
- QScopedPointer<QRhiTexture> m_texture;
- quint64 m_nativeObject = 0;
-};
-
-QSGVideoTexture::QSGVideoTexture()
- : d_ptr(new QSGVideoTexturePrivate)
-{
- d_ptr->q_ptr = this;
-}
-
-QSGVideoTexture::~QSGVideoTexture()
-{
-}
-
-qint64 QSGVideoTexture::comparisonKey() const
-{
- Q_D(const QSGVideoTexture);
- if (d->m_nativeObject)
- return d->m_nativeObject;
-
- if (d->m_texture)
- return qint64(qintptr(d->m_texture.data()));
-
- // two textures (and so materials) with not-yet-created texture underneath are never equal
- return qint64(qintptr(this));
-}
-
-QRhiTexture *QSGVideoTexture::rhiTexture() const
-{
- return d_func()->m_texture.data();
-}
-
-QSize QSGVideoTexture::textureSize() const
-{
- return d_func()->m_size;
-}
-
-bool QSGVideoTexture::hasAlphaChannel() const
-{
- Q_D(const QSGVideoTexture);
- return d->m_format == QRhiTexture::RGBA8 || d->m_format == QRhiTexture::BGRA8;
-}
-
-bool QSGVideoTexture::hasMipmaps() const
-{
- return mipmapFiltering() != QSGTexture::None;
-}
-
-void QSGVideoTexture::setData(QRhiTexture::Format f, const QSize &s, const uchar *data, int bytes)
-{
- Q_D(QSGVideoTexture);
- d->m_size = s;
- d->m_format = f;
- d->m_data = {reinterpret_cast<const char *>(data), bytes};
-}
-
-void QSGVideoTexture::setNativeObject(quint64 obj, const QSize &s)
-{
- Q_D(QSGVideoTexture);
- setData(QRhiTexture::RGBA8, s, nullptr, 0);
- if (d->m_nativeObject != obj) {
- d->m_nativeObject = obj;
- d->m_texture.reset();
- }
-}
-
-void QSGVideoTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
-{
- Q_Q(QSGVideoTexture);
-
- bool needsRebuild = m_texture && m_texture->pixelSize() != m_size;
- if (!m_texture) {
- QRhiTexture::Flags flags;
- if (q->hasMipmaps())
- flags |= QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips;
-
- m_texture.reset(rhi->newTexture(m_format, m_size, 1, flags));
- needsRebuild = true;
- }
-
- if (needsRebuild) {
- m_texture->setPixelSize(m_size);
- bool created = m_nativeObject
- ? m_texture->createFrom({m_nativeObject, 0})
- : m_texture->create();
- if (!created) {
- qWarning("Failed to build texture (size %dx%d)",
- m_size.width(), m_size.height());
- return;
- }
- }
-
- if (!m_data.isEmpty()) {
- QRhiTextureSubresourceUploadDescription subresDesc(m_data.constData(), m_data.size());
- subresDesc.setSourceSize(m_size);
- subresDesc.setDestinationTopLeft(QPoint(0, 0));
- QRhiTextureUploadEntry entry(0, 0, subresDesc);
- QRhiTextureUploadDescription desc({ entry });
- resourceUpdates->uploadTexture(m_texture.data(), desc);
- m_data.clear();
- }
-}
-
-void QSGVideoTexture::commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
-{
- d_func()->updateRhiTexture(rhi, resourceUpdates);
-}
-
-QT_END_NAMESPACE
diff --git a/src/qtmultimediaquicktools/qsgvideotexture_p.h b/src/qtmultimediaquicktools/qsgvideotexture_p.h
deleted file mode 100644
index 1cae713b8..000000000
--- a/src/qtmultimediaquicktools/qsgvideotexture_p.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSGVIDEOTEXTURE_H
-#define QSGVIDEOTEXTURE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtQuick/QSGTexture>
-#include <QImage>
-#include <private/qrhi_p.h>
-#include <private/qtmultimediaquickdefs_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QSGVideoTexturePrivate;
-class Q_MULTIMEDIAQUICK_EXPORT QSGVideoTexture : public QSGTexture
-{
- Q_DECLARE_PRIVATE(QSGVideoTexture)
-public:
- QSGVideoTexture();
- ~QSGVideoTexture();
-
- qint64 comparisonKey() const override;
- QRhiTexture *rhiTexture() const override;
- QSize textureSize() const override;
- bool hasAlphaChannel() const override;
- bool hasMipmaps() const override;
- void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
- void setData(QRhiTexture::Format f, const QSize &s, const uchar *data, int bytes);
- void setNativeObject(quint64 obj, const QSize &s);
-
-protected:
- QScopedPointer<QSGVideoTexturePrivate> d_ptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QSGVIDEOTEXTURE_H
diff --git a/src/qtmultimediaquicktools/qtmultimediaquickdefs_p.h b/src/qtmultimediaquicktools/qtmultimediaquickdefs_p.h
deleted file mode 100644
index 20188739c..000000000
--- a/src/qtmultimediaquicktools/qtmultimediaquickdefs_p.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifndef QMULTIMEDIAQUICKDEFS_P_H
-#define QMULTIMEDIAQUICKDEFS_P_H
-
-#include <QtCore/qglobal.h>
-
-#ifndef QT_STATIC
-# if defined(QT_BUILD_QTMULTIMEDIAQUICKTOOLS_LIB)
-# define Q_MULTIMEDIAQUICK_EXPORT Q_DECL_EXPORT
-# else
-# define Q_MULTIMEDIAQUICK_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define Q_MULTIMEDIAQUICK_EXPORT
-#endif
-
-
-#endif // QMULTIMEDIAQUICKDEFS_P_H
-
diff --git a/src/qtmultimediaquicktools/qtmultimediaquicktools.pro b/src/qtmultimediaquicktools/qtmultimediaquicktools.pro
deleted file mode 100644
index 82e3e463f..000000000
--- a/src/qtmultimediaquicktools/qtmultimediaquicktools.pro
+++ /dev/null
@@ -1,35 +0,0 @@
-TARGET = QtMultimediaQuick
-
-QT = core quick multimedia-private quick-private
-CONFIG += internal_module
-
-PRIVATE_HEADERS += \
- qdeclarativevideooutput_p.h \
- qdeclarativevideooutput_backend_p.h \
- qsgvideonode_p.h \
- qsgvideotexture_p.h \
- qtmultimediaquickdefs_p.h
-
-HEADERS += \
- $$PRIVATE_HEADERS \
- qdeclarativevideooutput_window_p.h
-
-SOURCES += \
- qsgvideonode_p.cpp \
- qsgvideotexture.cpp \
- qdeclarativevideooutput.cpp \
- qdeclarativevideooutput_window.cpp
-
-SOURCES += qdeclarativevideooutput_render.cpp \
- qsgvideonode_rgb.cpp \
- qsgvideonode_yuv.cpp \
- qsgvideonode_texture.cpp
-HEADERS += qdeclarativevideooutput_render_p.h \
- qsgvideonode_rgb_p.h \
- qsgvideonode_yuv_p.h \
- qsgvideonode_texture_p.h
-
-RESOURCES += \
- qtmultimediaquicktools.qrc
-
-load(qt_module)
diff --git a/src/qtmultimediaquicktools/qtmultimediaquicktools.qrc b/src/qtmultimediaquicktools/qtmultimediaquicktools.qrc
deleted file mode 100644
index ceac8cff4..000000000
--- a/src/qtmultimediaquicktools/qtmultimediaquicktools.qrc
+++ /dev/null
@@ -1,13 +0,0 @@
-<RCC>
- <qresource prefix="/qtmultimediaquicktools">
- <file>shaders/rgba.vert.qsb</file>
- <file>shaders/rgba.frag.qsb</file>
- <file>shaders/bgra.frag.qsb</file>
- <file>shaders/yuv.vert.qsb</file>
- <file>shaders/yuv_yv.frag.qsb</file>
- <file>shaders/nv12.frag.qsb</file>
- <file>shaders/nv21.frag.qsb</file>
- <file>shaders/uyvy.frag.qsb</file>
- <file>shaders/yuyv.frag.qsb</file>
- </qresource>
-</RCC>
diff --git a/src/qtmultimediaquicktools/shaders/bgra.frag b/src/qtmultimediaquicktools/shaders/bgra.frag
deleted file mode 100644
index f04e3e721..000000000
--- a/src/qtmultimediaquicktools/shaders/bgra.frag
+++ /dev/null
@@ -1,16 +0,0 @@
-#version 440
-
-layout(location = 0) in vec2 qt_TexCoord;
-layout(location = 0) out vec4 fragColor;
-
-layout(std140, binding = 0) uniform buf {
- mat4 matrix;
- float opacity;
-} ubuf;
-
-layout(binding = 1) uniform sampler2D rgbTexture;
-
-void main()
-{
- fragColor = texture(rgbTexture, qt_TexCoord).bgra * ubuf.opacity;
-}
diff --git a/src/qtmultimediaquicktools/shaders/bgra.frag.qsb b/src/qtmultimediaquicktools/shaders/bgra.frag.qsb
deleted file mode 100644
index 4910d5654..000000000
--- a/src/qtmultimediaquicktools/shaders/bgra.frag.qsb
+++ /dev/null
Binary files differ
diff --git a/src/qtmultimediaquicktools/shaders/compile.bat b/src/qtmultimediaquicktools/shaders/compile.bat
deleted file mode 100755
index 682cc71b8..000000000
--- a/src/qtmultimediaquicktools/shaders/compile.bat
+++ /dev/null
@@ -1,50 +0,0 @@
-:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-::
-:: Copyright (C) 2019 The Qt Company Ltd.
-:: Contact: https://www.qt.io/licensing/
-::
-:: This file is part of the QtQuick module of the Qt Toolkit.
-::
-:: $QT_BEGIN_LICENSE:LGPL$
-:: Commercial License Usage
-:: Licensees holding valid commercial Qt licenses may use this file in
-:: accordance with the commercial license agreement provided with the
-:: Software or, alternatively, in accordance with the terms contained in
-:: a written agreement between you and The Qt Company. For licensing terms
-:: and conditions see https://www.qt.io/terms-conditions. For further
-:: information use the contact form at https://www.qt.io/contact-us.
-::
-:: GNU Lesser General Public License Usage
-:: Alternatively, this file may be used under the terms of the GNU Lesser
-:: General Public License version 3 as published by the Free Software
-:: Foundation and appearing in the file LICENSE.LGPL3 included in the
-:: packaging of this file. Please review the following information to
-:: ensure the GNU Lesser General Public License version 3 requirements
-:: will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-::
-:: GNU General Public License Usage
-:: Alternatively, this file may be used under the terms of the GNU
-:: General Public License version 2.0 or (at your option) the GNU General
-:: Public license version 3 or any later version approved by the KDE Free
-:: Qt Foundation. The licenses are as published by the Free Software
-:: Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-:: included in the packaging of this file. Please review the following
-:: information to ensure the GNU General Public License requirements will
-:: be met: https://www.gnu.org/licenses/gpl-2.0.html and
-:: https://www.gnu.org/licenses/gpl-3.0.html.
-::
-:: $QT_END_LICENSE$
-::
-:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
-qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o rgba.vert.qsb rgba.vert
-qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o rgba.frag.qsb rgba.frag
-qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o bgra.frag.qsb bgra.frag
-
-qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o yuv.vert.qsb yuv.vert
-qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o yuv_yv.frag.qsb yuv_yv.frag
-
-qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o nv12.frag.qsb nv12.frag
-qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o nv21.frag.qsb nv21.frag
-qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o uyvy.frag.qsb uyvy.frag
-qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o yuyv.frag.qsb yuyv.frag
diff --git a/src/qtmultimediaquicktools/shaders/nv12.frag b/src/qtmultimediaquicktools/shaders/nv12.frag
deleted file mode 100644
index 9ef6bd648..000000000
--- a/src/qtmultimediaquicktools/shaders/nv12.frag
+++ /dev/null
@@ -1,25 +0,0 @@
-#version 440
-
-layout(location = 0) in vec2 plane1TexCoord;
-layout(location = 1) in vec2 plane2TexCoord;
-layout(location = 0) out vec4 fragColor;
-
-layout(std140, binding = 0) uniform buf {
- mat4 matrix;
- mat4 colorMatrix;
- float opacity;
- float plane1Width;
- float plane2Width;
- float plane3Width;
-} ubuf;
-
-layout(binding = 1) uniform sampler2D plane1Texture;
-layout(binding = 2) uniform sampler2D plane2Texture;
-
-void main()
-{
- float Y = texture(plane1Texture, plane1TexCoord).r;
- vec2 UV = texture(plane2Texture, plane2TexCoord).rg;
- vec4 color = vec4(Y, UV.x, UV.y, 1.);
- fragColor = ubuf.colorMatrix * color * ubuf.opacity;
-}
diff --git a/src/qtmultimediaquicktools/shaders/nv12.frag.qsb b/src/qtmultimediaquicktools/shaders/nv12.frag.qsb
deleted file mode 100644
index f5adaef48..000000000
--- a/src/qtmultimediaquicktools/shaders/nv12.frag.qsb
+++ /dev/null
Binary files differ
diff --git a/src/qtmultimediaquicktools/shaders/nv21.frag b/src/qtmultimediaquicktools/shaders/nv21.frag
deleted file mode 100644
index 636294048..000000000
--- a/src/qtmultimediaquicktools/shaders/nv21.frag
+++ /dev/null
@@ -1,25 +0,0 @@
-#version 440
-
-layout(location = 0) in vec2 plane1TexCoord;
-layout(location = 1) in vec2 plane2TexCoord;
-layout(location = 0) out vec4 fragColor;
-
-layout(std140, binding = 0) uniform buf {
- mat4 matrix;
- mat4 colorMatrix;
- float opacity;
- float plane1Width;
- float plane2Width;
- float plane3Width;
-} ubuf;
-
-layout(binding = 1) uniform sampler2D plane1Texture;
-layout(binding = 2) uniform sampler2D plane2Texture;
-
-void main()
-{
- float Y = texture(plane1Texture, plane1TexCoord).r;
- vec2 UV = texture(plane2Texture, plane2TexCoord).gr;
- vec4 color = vec4(Y, UV.x, UV.y, 1.);
- fragColor = ubuf.colorMatrix * color * ubuf.opacity;
-}
diff --git a/src/qtmultimediaquicktools/shaders/nv21.frag.qsb b/src/qtmultimediaquicktools/shaders/nv21.frag.qsb
deleted file mode 100644
index 6fb2c46dd..000000000
--- a/src/qtmultimediaquicktools/shaders/nv21.frag.qsb
+++ /dev/null
Binary files differ
diff --git a/src/qtmultimediaquicktools/shaders/rgba.frag b/src/qtmultimediaquicktools/shaders/rgba.frag
deleted file mode 100644
index 1623c2cc7..000000000
--- a/src/qtmultimediaquicktools/shaders/rgba.frag
+++ /dev/null
@@ -1,16 +0,0 @@
-#version 440
-
-layout(location = 0) in vec2 qt_TexCoord;
-layout(location = 0) out vec4 fragColor;
-
-layout(std140, binding = 0) uniform buf {
- mat4 matrix;
- float opacity;
-} ubuf;
-
-layout(binding = 1) uniform sampler2D rgbTexture;
-
-void main()
-{
- fragColor = texture(rgbTexture, qt_TexCoord) * ubuf.opacity;
-}
diff --git a/src/qtmultimediaquicktools/shaders/rgba.frag.qsb b/src/qtmultimediaquicktools/shaders/rgba.frag.qsb
deleted file mode 100644
index 8f782fcdb..000000000
--- a/src/qtmultimediaquicktools/shaders/rgba.frag.qsb
+++ /dev/null
Binary files differ
diff --git a/src/qtmultimediaquicktools/shaders/rgba.vert b/src/qtmultimediaquicktools/shaders/rgba.vert
deleted file mode 100644
index ebc53a65f..000000000
--- a/src/qtmultimediaquicktools/shaders/rgba.vert
+++ /dev/null
@@ -1,18 +0,0 @@
-#version 440
-
-layout(location = 0) in vec4 qt_VertexPosition;
-layout(location = 1) in vec2 qt_VertexTexCoord;
-
-layout(location = 0) out vec2 qt_TexCoord;
-
-layout(std140, binding = 0) uniform buf {
- mat4 matrix;
- float opacity;
-} ubuf;
-
-out gl_PerVertex { vec4 gl_Position; };
-
-void main() {
- qt_TexCoord = qt_VertexTexCoord;
- gl_Position = ubuf.matrix * qt_VertexPosition;
-}
diff --git a/src/qtmultimediaquicktools/shaders/rgba.vert.qsb b/src/qtmultimediaquicktools/shaders/rgba.vert.qsb
deleted file mode 100644
index 3d81483ce..000000000
--- a/src/qtmultimediaquicktools/shaders/rgba.vert.qsb
+++ /dev/null
Binary files differ
diff --git a/src/qtmultimediaquicktools/shaders/uyvy.frag b/src/qtmultimediaquicktools/shaders/uyvy.frag
deleted file mode 100644
index f1c7c1aec..000000000
--- a/src/qtmultimediaquicktools/shaders/uyvy.frag
+++ /dev/null
@@ -1,23 +0,0 @@
-#version 440
-
-layout(location = 0) in vec2 plane1TexCoord;
-layout(location = 1) in vec2 plane2TexCoord;
-layout(location = 0) out vec4 fragColor;
-
-layout(std140, binding = 0) uniform buf {
- mat4 matrix;
- mat4 colorMatrix;
- float opacity;
- float plane1Width;
- float plane2Width;
- float plane3Width;
-} ubuf;
-
-layout(binding = 1) uniform sampler2D plane1Texture;
-layout(binding = 2) uniform sampler2D plane2Texture;
-
-void main()
-{
- vec3 YUV = vec3(texture(plane1Texture, plane1TexCoord).g, texture(plane2Texture, plane2TexCoord).rb);
- fragColor = ubuf.colorMatrix * vec4(YUV, 1.0) * ubuf.opacity;
-}
diff --git a/src/qtmultimediaquicktools/shaders/uyvy.frag.qsb b/src/qtmultimediaquicktools/shaders/uyvy.frag.qsb
deleted file mode 100644
index bb3237004..000000000
--- a/src/qtmultimediaquicktools/shaders/uyvy.frag.qsb
+++ /dev/null
Binary files differ
diff --git a/src/qtmultimediaquicktools/shaders/yuv.vert b/src/qtmultimediaquicktools/shaders/yuv.vert
deleted file mode 100644
index 6f103372f..000000000
--- a/src/qtmultimediaquicktools/shaders/yuv.vert
+++ /dev/null
@@ -1,26 +0,0 @@
-#version 440
-
-layout(location = 0) in vec4 qt_VertexPosition;
-layout(location = 1) in vec2 qt_VertexTexCoord;
-
-layout(location = 0) out vec2 plane1TexCoord;
-layout(location = 1) out vec2 plane2TexCoord;
-layout(location = 2) out vec2 plane3TexCoord;
-
-layout(std140, binding = 0) uniform buf {
- mat4 matrix;
- mat4 colorMatrix;
- float opacity;
- float plane1Width;
- float plane2Width;
- float plane3Width;
-} ubuf;
-
-out gl_PerVertex { vec4 gl_Position; };
-
-void main() {
- plane1TexCoord = qt_VertexTexCoord * vec2(ubuf.plane1Width, 1);
- plane2TexCoord = qt_VertexTexCoord * vec2(ubuf.plane2Width, 1);
- plane3TexCoord = qt_VertexTexCoord * vec2(ubuf.plane3Width, 1);
- gl_Position = ubuf.matrix * qt_VertexPosition;
-}
diff --git a/src/qtmultimediaquicktools/shaders/yuv.vert.qsb b/src/qtmultimediaquicktools/shaders/yuv.vert.qsb
deleted file mode 100644
index d4605e8de..000000000
--- a/src/qtmultimediaquicktools/shaders/yuv.vert.qsb
+++ /dev/null
Binary files differ
diff --git a/src/qtmultimediaquicktools/shaders/yuv_yv.frag b/src/qtmultimediaquicktools/shaders/yuv_yv.frag
deleted file mode 100644
index 07ea52aab..000000000
--- a/src/qtmultimediaquicktools/shaders/yuv_yv.frag
+++ /dev/null
@@ -1,28 +0,0 @@
-#version 440
-
-layout(location = 0) in vec2 plane1TexCoord;
-layout(location = 1) in vec2 plane2TexCoord;
-layout(location = 2) in vec2 plane3TexCoord;
-layout(location = 0) out vec4 fragColor;
-
-layout(std140, binding = 0) uniform buf {
- mat4 matrix;
- mat4 colorMatrix;
- float opacity;
- float plane1Width;
- float plane2Width;
- float plane3Width;
-} ubuf;
-
-layout(binding = 1) uniform sampler2D plane1Texture;
-layout(binding = 2) uniform sampler2D plane2Texture;
-layout(binding = 3) uniform sampler2D plane3Texture;
-
-void main()
-{
- float Y = texture(plane1Texture, plane1TexCoord).r;
- float U = texture(plane2Texture, plane2TexCoord).r;
- float V = texture(plane3Texture, plane3TexCoord).r;
- vec4 color = vec4(Y, U, V, 1.);
- fragColor = ubuf.colorMatrix * color * ubuf.opacity;
-}
diff --git a/src/qtmultimediaquicktools/shaders/yuv_yv.frag.qsb b/src/qtmultimediaquicktools/shaders/yuv_yv.frag.qsb
deleted file mode 100644
index af1816011..000000000
--- a/src/qtmultimediaquicktools/shaders/yuv_yv.frag.qsb
+++ /dev/null
Binary files differ
diff --git a/src/qtmultimediaquicktools/shaders/yuyv.frag b/src/qtmultimediaquicktools/shaders/yuyv.frag
deleted file mode 100644
index 454fdc21e..000000000
--- a/src/qtmultimediaquicktools/shaders/yuyv.frag
+++ /dev/null
@@ -1,23 +0,0 @@
-#version 440
-
-layout(location = 0) in vec2 plane1TexCoord;
-layout(location = 1) in vec2 plane2TexCoord;
-layout(location = 0) out vec4 fragColor;
-
-layout(std140, binding = 0) uniform buf {
- mat4 matrix;
- mat4 colorMatrix;
- float opacity;
- float plane1Width;
- float plane2Width;
- float plane3Width;
-} ubuf;
-
-layout(binding = 1) uniform sampler2D plane1Texture;
-layout(binding = 2) uniform sampler2D plane2Texture;
-
-void main()
-{
- vec3 YUV = vec3(texture(plane1Texture, plane1TexCoord).r, texture(plane2Texture, plane2TexCoord).ga);
- fragColor = ubuf.colorMatrix * vec4(YUV, 1.0) * ubuf.opacity;
-}
diff --git a/src/qtmultimediaquicktools/shaders/yuyv.frag.qsb b/src/qtmultimediaquicktools/shaders/yuyv.frag.qsb
deleted file mode 100644
index f7af4db3d..000000000
--- a/src/qtmultimediaquicktools/shaders/yuyv.frag.qsb
+++ /dev/null
Binary files differ
diff --git a/src/resonance-audio/CMakeLists.txt b/src/resonance-audio/CMakeLists.txt
new file mode 100644
index 000000000..1e967a117
--- /dev/null
+++ b/src/resonance-audio/CMakeLists.txt
@@ -0,0 +1,238 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 4)
+ set(NO_SIMD_DEFINES PFFFT_SIMD_DISABLE DISABLE_SIMD)
+endif()
+
+set(PFFFT_DIR "../3rdparty/pffft/" CACHE PATH "Path to pffft library")
+set(PFFFT_INCLUDE_DIR ${PFFFT_DIR})
+set(PFFFT_SOURCE
+ ${PFFFT_DIR}/pffft.c
+ ${PFFFT_DIR}/pffft.h
+ )
+
+set(SADIE_HRTFS_DIR "../3rdparty/resonance-audio/third_party/SADIE_hrtf_database/generated/" CACHE PATH "Path to SADIE_hrtf_database library")
+set(SADIE_HRTFS_INCLUDE_DIR ${SADIE_HRTFS_DIR})
+set(SADIE_HRTFS_SOURCE
+ ${SADIE_HRTFS_DIR}/hrtf_assets.cc
+ ${SADIE_HRTFS_DIR}/hrtf_assets.h
+ )
+add_library(SadieHrtfsObj OBJECT ${SADIE_HRTFS_SOURCE})
+
+set(RA_TOPLEVEL_DIR "../3rdparty/resonance-audio" CACHE PATH "Path to resonance audio top level dir")
+set(RA_SOURCE_DIR "${RA_TOPLEVEL_DIR}/resonance_audio")
+
+# Build Resonance Audio.
+set(RA_SOURCES
+ ${RA_TOPLEVEL_DIR}/platforms/common/utils.cc
+ ${RA_TOPLEVEL_DIR}/platforms/common/utils.h
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_binaural_decoder.h
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_binaural_decoder.cc
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_codec.h
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_codec_impl.h
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_lookup_table.cc
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_lookup_table.h
+ ${RA_SOURCE_DIR}/ambisonics/ambisonic_spread_coefficients.h
+ ${RA_SOURCE_DIR}/ambisonics/associated_legendre_polynomials_generator.cc
+ ${RA_SOURCE_DIR}/ambisonics/associated_legendre_polynomials_generator.h
+ ${RA_SOURCE_DIR}/ambisonics/foa_rotator.cc
+ ${RA_SOURCE_DIR}/ambisonics/foa_rotator.h
+ ${RA_SOURCE_DIR}/ambisonics/hoa_rotator.cc
+ ${RA_SOURCE_DIR}/ambisonics/hoa_rotator.h
+ ${RA_SOURCE_DIR}/ambisonics/stereo_from_soundfield_converter.cc
+ ${RA_SOURCE_DIR}/ambisonics/stereo_from_soundfield_converter.h
+ ${RA_SOURCE_DIR}/ambisonics/utils.h
+ ${RA_SOURCE_DIR}/api/binaural_surround_renderer.cc
+ ${RA_SOURCE_DIR}/api/binaural_surround_renderer.h
+ ${RA_SOURCE_DIR}/api/resonance_audio_api.cc
+ ${RA_SOURCE_DIR}/api/resonance_audio_api.h
+ ${RA_SOURCE_DIR}/base/aligned_allocator.h
+ ${RA_SOURCE_DIR}/base/audio_buffer.cc
+ ${RA_SOURCE_DIR}/base/audio_buffer.h
+ ${RA_SOURCE_DIR}/base/channel_view.cc
+ ${RA_SOURCE_DIR}/base/channel_view.h
+ ${RA_SOURCE_DIR}/base/constants_and_types.h
+ ${RA_SOURCE_DIR}/base/integral_types.h
+ ${RA_SOURCE_DIR}/base/logging.h
+ ${RA_SOURCE_DIR}/base/misc_math.cc
+ ${RA_SOURCE_DIR}/base/misc_math.h
+ ${RA_SOURCE_DIR}/base/object_transform.h
+ ${RA_SOURCE_DIR}/base/simd_macros.h
+ ${RA_SOURCE_DIR}/base/simd_utils.cc
+ ${RA_SOURCE_DIR}/base/simd_utils.h
+ ${RA_SOURCE_DIR}/base/source_parameters.h
+ ${RA_SOURCE_DIR}/base/spherical_angle.cc
+ ${RA_SOURCE_DIR}/base/spherical_angle.h
+ ${RA_SOURCE_DIR}/base/unique_ptr_wrapper.h
+ ${RA_SOURCE_DIR}/config/global_config.h
+ ${RA_SOURCE_DIR}/config/source_config.cc
+ ${RA_SOURCE_DIR}/config/source_config.h
+ ${RA_SOURCE_DIR}/dsp/biquad_filter.cc
+ ${RA_SOURCE_DIR}/dsp/biquad_filter.h
+ ${RA_SOURCE_DIR}/dsp/channel_converter.cc
+ ${RA_SOURCE_DIR}/dsp/channel_converter.h
+ ${RA_SOURCE_DIR}/dsp/circular_buffer.cc
+ ${RA_SOURCE_DIR}/dsp/circular_buffer.h
+ ${RA_SOURCE_DIR}/dsp/delay_filter.cc
+ ${RA_SOURCE_DIR}/dsp/delay_filter.h
+ ${RA_SOURCE_DIR}/dsp/distance_attenuation.cc
+ ${RA_SOURCE_DIR}/dsp/distance_attenuation.h
+ ${RA_SOURCE_DIR}/dsp/fft_manager.cc
+ ${RA_SOURCE_DIR}/dsp/fft_manager.h
+ ${RA_SOURCE_DIR}/dsp/filter_coefficient_generators.cc
+ ${RA_SOURCE_DIR}/dsp/filter_coefficient_generators.h
+ ${RA_SOURCE_DIR}/dsp/fir_filter.cc
+ ${RA_SOURCE_DIR}/dsp/fir_filter.h
+ ${RA_SOURCE_DIR}/dsp/gain.cc
+ ${RA_SOURCE_DIR}/dsp/gain.h
+ ${RA_SOURCE_DIR}/dsp/gain_mixer.cc
+ ${RA_SOURCE_DIR}/dsp/gain_mixer.h
+ ${RA_SOURCE_DIR}/dsp/gain_processor.cc
+ ${RA_SOURCE_DIR}/dsp/gain_processor.h
+ ${RA_SOURCE_DIR}/dsp/mixer.cc
+ ${RA_SOURCE_DIR}/dsp/mixer.h
+ ${RA_SOURCE_DIR}/dsp/mono_pole_filter.cc
+ ${RA_SOURCE_DIR}/dsp/mono_pole_filter.h
+ ${RA_SOURCE_DIR}/dsp/multi_channel_iir.cc
+ ${RA_SOURCE_DIR}/dsp/multi_channel_iir.h
+ ${RA_SOURCE_DIR}/dsp/near_field_processor.cc
+ ${RA_SOURCE_DIR}/dsp/near_field_processor.h
+ ${RA_SOURCE_DIR}/dsp/occlusion_calculator.cc
+ ${RA_SOURCE_DIR}/dsp/occlusion_calculator.h
+ ${RA_SOURCE_DIR}/dsp/partitioned_fft_filter.cc
+ ${RA_SOURCE_DIR}/dsp/partitioned_fft_filter.h
+ ${RA_SOURCE_DIR}/dsp/reflection.h
+ ${RA_SOURCE_DIR}/dsp/reflections_processor.cc
+ ${RA_SOURCE_DIR}/dsp/reflections_processor.h
+ ${RA_SOURCE_DIR}/dsp/resampler.cc
+ ${RA_SOURCE_DIR}/dsp/resampler.h
+ ${RA_SOURCE_DIR}/dsp/reverb_onset_compensator.cc
+ ${RA_SOURCE_DIR}/dsp/reverb_onset_compensator.h
+ ${RA_SOURCE_DIR}/dsp/reverb_onset_update_processor.cc
+ ${RA_SOURCE_DIR}/dsp/reverb_onset_update_processor.h
+ ${RA_SOURCE_DIR}/dsp/sh_hrir_creator.cc
+ ${RA_SOURCE_DIR}/dsp/sh_hrir_creator.h
+ ${RA_SOURCE_DIR}/dsp/shoe_box_room.cc
+ ${RA_SOURCE_DIR}/dsp/shoe_box_room.h
+ ${RA_SOURCE_DIR}/dsp/spectral_reverb.cc
+ ${RA_SOURCE_DIR}/dsp/spectral_reverb.h
+ ${RA_SOURCE_DIR}/dsp/spectral_reverb_constants_and_tables.h
+ ${RA_SOURCE_DIR}/dsp/stereo_panner.cc
+ ${RA_SOURCE_DIR}/dsp/stereo_panner.h
+ ${RA_SOURCE_DIR}/dsp/utils.cc
+ ${RA_SOURCE_DIR}/dsp/utils.h
+ ${RA_SOURCE_DIR}/graph/ambisonic_binaural_decoder_node.cc
+ ${RA_SOURCE_DIR}/graph/ambisonic_binaural_decoder_node.h
+ ${RA_SOURCE_DIR}/graph/ambisonic_mixing_encoder_node.cc
+ ${RA_SOURCE_DIR}/graph/ambisonic_mixing_encoder_node.h
+ ${RA_SOURCE_DIR}/graph/binaural_surround_renderer_impl.cc
+ ${RA_SOURCE_DIR}/graph/binaural_surround_renderer_impl.h
+ ${RA_SOURCE_DIR}/graph/buffered_source_node.cc
+ ${RA_SOURCE_DIR}/graph/buffered_source_node.h
+ ${RA_SOURCE_DIR}/graph/foa_rotator_node.cc
+ ${RA_SOURCE_DIR}/graph/foa_rotator_node.h
+ ${RA_SOURCE_DIR}/graph/gain_mixer_node.cc
+ ${RA_SOURCE_DIR}/graph/gain_mixer_node.h
+ ${RA_SOURCE_DIR}/graph/gain_node.cc
+ ${RA_SOURCE_DIR}/graph/gain_node.h
+ ${RA_SOURCE_DIR}/graph/graph_manager.cc
+ ${RA_SOURCE_DIR}/graph/graph_manager.h
+ ${RA_SOURCE_DIR}/graph/graph_manager_config.h
+ ${RA_SOURCE_DIR}/graph/hoa_rotator_node.cc
+ ${RA_SOURCE_DIR}/graph/hoa_rotator_node.h
+ ${RA_SOURCE_DIR}/graph/mixer_node.cc
+ ${RA_SOURCE_DIR}/graph/mixer_node.h
+ ${RA_SOURCE_DIR}/graph/mono_from_soundfield_node.cc
+ ${RA_SOURCE_DIR}/graph/mono_from_soundfield_node.h
+ ${RA_SOURCE_DIR}/graph/near_field_effect_node.cc
+ ${RA_SOURCE_DIR}/graph/near_field_effect_node.h
+ ${RA_SOURCE_DIR}/graph/occlusion_node.cc
+ ${RA_SOURCE_DIR}/graph/occlusion_node.h
+ ${RA_SOURCE_DIR}/graph/reflections_node.cc
+ ${RA_SOURCE_DIR}/graph/reflections_node.h
+ ${RA_SOURCE_DIR}/graph/resonance_audio_api_impl.cc
+ ${RA_SOURCE_DIR}/graph/resonance_audio_api_impl.h
+ ${RA_SOURCE_DIR}/graph/reverb_node.cc
+ ${RA_SOURCE_DIR}/graph/reverb_node.h
+ ${RA_SOURCE_DIR}/graph/source_graph_config.h
+ ${RA_SOURCE_DIR}/graph/source_parameters_manager.cc
+ ${RA_SOURCE_DIR}/graph/source_parameters_manager.h
+ ${RA_SOURCE_DIR}/graph/stereo_mixing_panner_node.cc
+ ${RA_SOURCE_DIR}/graph/stereo_mixing_panner_node.h
+ ${RA_SOURCE_DIR}/graph/system_settings.h
+ ${RA_SOURCE_DIR}/node/node.h
+ ${RA_SOURCE_DIR}/node/processing_node.cc
+ ${RA_SOURCE_DIR}/node/processing_node.h
+ ${RA_SOURCE_DIR}/node/publisher_node.h
+ ${RA_SOURCE_DIR}/node/sink_node.cc
+ ${RA_SOURCE_DIR}/node/sink_node.h
+ ${RA_SOURCE_DIR}/node/source_node.cc
+ ${RA_SOURCE_DIR}/node/source_node.h
+ ${RA_SOURCE_DIR}/node/subscriber_node.h
+ ${RA_TOPLEVEL_DIR}/platforms/common/room_effects_utils.cc
+ ${RA_TOPLEVEL_DIR}/platforms/common/room_effects_utils.h
+ ${RA_SOURCE_DIR}/utils/buffer_crossfader.cc
+ ${RA_SOURCE_DIR}/utils/buffer_crossfader.h
+ ${RA_SOURCE_DIR}/utils/buffer_partitioner.cc
+ ${RA_SOURCE_DIR}/utils/buffer_partitioner.h
+ ${RA_SOURCE_DIR}/utils/buffer_unpartitioner.cc
+ ${RA_SOURCE_DIR}/utils/buffer_unpartitioner.h
+ ${RA_SOURCE_DIR}/utils/lockless_task_queue.cc
+ ${RA_SOURCE_DIR}/utils/lockless_task_queue.h
+ ${RA_SOURCE_DIR}/utils/planar_interleaved_conversion.cc
+ ${RA_SOURCE_DIR}/utils/planar_interleaved_conversion.h
+ ${RA_SOURCE_DIR}/utils/pseudoinverse.h
+ ${RA_SOURCE_DIR}/utils/sample_type_conversion.cc
+ ${RA_SOURCE_DIR}/utils/sample_type_conversion.h
+ ${RA_SOURCE_DIR}/utils/semi_lockless_fifo.h
+ ${RA_SOURCE_DIR}/utils/sum_and_difference_processor.cc
+ ${RA_SOURCE_DIR}/utils/sum_and_difference_processor.h
+ ${RA_SOURCE_DIR}/utils/threadsafe_fifo.h
+ ${RA_SOURCE_DIR}/utils/wav.cc
+ ${RA_SOURCE_DIR}/utils/wav.h
+ ${RA_SOURCE_DIR}/utils/wav_reader.cc
+ ${RA_SOURCE_DIR}/utils/wav_reader.h
+)
+
+qt_internal_add_3rdparty_library(BundledResonanceAudio
+ STATIC
+ INSTALL
+ DEFINES
+ EIGEN_MPL2_ONLY
+ ${NO_SIMD_DEFINES}
+ SOURCES
+ ${RA_SOURCES}
+ ${PFFFT_SOURCE}
+ ${SADIE_HRTFS_SOURCE}
+ resonance_audio.h resonance_audio.cpp
+ INCLUDE_DIRECTORIES
+ ${RA_TOPLEVEL_DIR}
+ ${RA_SOURCE_DIR}
+ ${PFFFT_DIR}
+ ${SADIE_HRTFS_DIR}
+ ../3rdparty/eigen
+)
+
+# Required by pffft on certain PowerPC archs
+qt_internal_extend_target(BundledResonanceAudio CONDITION GCC AND (${CMAKE_SYSTEM_PROCESSOR} MATCHES "(ppc|ppc64)$")
+ COMPILE_OPTIONS
+ -maltivec
+)
+
+# Required by eigen on certain PowerPC archs
+qt_internal_extend_target(BundledResonanceAudio CONDITION (${CMAKE_SYSTEM_PROCESSOR} MATCHES "(ppc|ppc64)$")
+ COMPILE_OPTIONS
+ -mvsx
+)
+
+# Use fallback mode if SSE is not available
+qt_internal_extend_target(BundledResonanceAudio CONDITION (${CMAKE_SYSTEM_PROCESSOR} MATCHES "i[3-6]86$")
+ COMPILE_OPTIONS
+ -DPFFFT_SIMD_DISABLE
+)
+
+qt_disable_warnings(BundledResonanceAudio)
+qt_set_symbol_visibility_hidden(BundledResonanceAudio)
+
+qt_install_3rdparty_library_wrap_config_extra_file(BundledResonanceAudio)
diff --git a/src/resonance-audio/resonance_audio.cpp b/src/resonance-audio/resonance_audio.cpp
new file mode 100644
index 000000000..5216da048
--- /dev/null
+++ b/src/resonance-audio/resonance_audio.cpp
@@ -0,0 +1,42 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include "resonance_audio.h"
+#include "graph/resonance_audio_api_impl.h"
+#include "graph/graph_manager.h"
+
+namespace vraudio
+{
+
+ResonanceAudio::ResonanceAudio(size_t num_channels, size_t frames_per_buffer, int sample_rate_hz)
+{
+ api = CreateResonanceAudioApi(num_channels, frames_per_buffer, sample_rate_hz);
+ impl = static_cast<ResonanceAudioApiImpl *>(api);
+}
+
+ResonanceAudio::~ResonanceAudio()
+{
+ delete api;
+}
+
+int ResonanceAudio::getAmbisonicOutput(const float *buffers[], const float *reverb[], int nChannels)
+{
+ impl->ProcessNextBuffer();
+ auto *buffer = impl->GetAmbisonicOutputBuffer();
+ if (!buffer || nChannels != buffer->num_channels())
+ return -1;
+
+ for (int i = 0; i < nChannels; ++i) {
+ buffers[i] = buffer->begin()[i].begin();
+ }
+
+ if (roomEffectsEnabled) {
+ const vraudio::AudioBuffer *reverbBuffer = impl->GetReverbBuffer();
+ for (int i = 0; i < 2; ++i) {
+ reverb[i] = reverbBuffer->begin()[i].begin();
+ }
+ }
+
+ return buffer->num_frames();
+}
+
+}
diff --git a/src/resonance-audio/resonance_audio.h b/src/resonance-audio/resonance_audio.h
new file mode 100644
index 000000000..435fa16df
--- /dev/null
+++ b/src/resonance-audio/resonance_audio.h
@@ -0,0 +1,33 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#ifndef RESONANCE_AUDIO_H
+#define RESONANCE_AUDIO_H
+
+#include <api/resonance_audio_api.h>
+
+namespace vraudio
+{
+
+class ResonanceAudioExtensions;
+class ResonanceAudioApiImpl;
+
+class EXPORT_API ResonanceAudio
+{
+public:
+ ResonanceAudio(size_t num_channels, size_t frames_per_buffer, int sample_rate_hz);
+ ~ResonanceAudio();
+
+ // reverb is only calculated in stereo. We get it here as well, and our ambisonic
+ // decoder will then add it to the generated surround signal.
+ int getAmbisonicOutput(const float *buffers[], const float *reverb[], int nChannels);
+
+ ResonanceAudioApi *api = nullptr;
+ ResonanceAudioApiImpl *impl = nullptr;
+ bool roomEffectsEnabled = true;
+};
+
+
+
+}
+
+#endif
diff --git a/src/spatialaudio/CMakeLists.txt b/src/spatialaudio/CMakeLists.txt
new file mode 100644
index 000000000..d0d005e1e
--- /dev/null
+++ b/src/spatialaudio/CMakeLists.txt
@@ -0,0 +1,29 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_internal_add_module(SpatialAudio
+ SOURCES
+ qambisonicdecoder.cpp qambisonicdecoder_p.h qambisonicdecoderdata_p.h
+ qaudioengine.cpp qaudioengine.h qaudioengine_p.h
+ qaudiolistener.cpp qaudiolistener.h
+ qaudioroom.cpp qaudioroom.h qaudioroom_p.h
+ qspatialsound.cpp qspatialsound.h qspatialsound_p.h
+ qambientsound.cpp qambientsound.h qambientsound_p.h
+ qtspatialaudioglobal.h qtspatialaudioglobal_p.h
+ INCLUDE_DIRECTORIES
+ "../3rdparty/resonance-audio/resonance_audio"
+ "../3rdparty/resonance-audio"
+ "../resonance-audio"
+ "../3rdparty/eigen"
+ LIBRARIES
+ Qt::MultimediaPrivate
+ Qt::BundledResonanceAudio
+ PUBLIC_LIBRARIES
+ Qt::Multimedia
+ GENERATE_CPP_EXPORTS
+)
+
+
+qt_internal_add_docs(SpatialAudio
+ doc/qtspatialaudio.qdocconf
+)
diff --git a/src/spatialaudio/doc/qtspatialaudio.qdocconf b/src/spatialaudio/doc/qtspatialaudio.qdocconf
new file mode 100644
index 000000000..3c8916907
--- /dev/null
+++ b/src/spatialaudio/doc/qtspatialaudio.qdocconf
@@ -0,0 +1,62 @@
+include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf)
+
+project = QtSpatialAudio
+description = Qt Spatial Audio Documentation
+version = $QT_VERSION
+buildversion = "Technology Preview"
+
+moduleheader = QtSpatialAudio
+includepaths += .
+
+examplesinstallpath = spatialaudio
+
+# The following parameters are for creating a qhp file, the qhelpgenerator
+# program can convert the qhp file into a qch file which can be opened in
+# Qt Assistant and/or Qt Creator.
+
+# Defines the name of the project. You cannot use operators (+, =, -) in
+# the name. Properties for this project are set using a qhp.<projectname>.property
+# format.
+qhp.projects = QtSpatialAudio
+qhp.QtSpatialAudio.file = qtspatialaudio.qhp
+qhp.QtSpatialAudio.namespace = org.qt-project.qtspatialaudio.$QT_VERSION_TAG
+qhp.QtSpatialAudio.indexTitle = Qt Spatial Audio
+qhp.QtSpatialAudio.virtualFolder = qtspatialaudio
+
+# For listing child nodes in Qt Creator or Assistant.
+qhp.QtSpatialAudio.subprojects = classes qmltypes examples
+
+qhp.QtSpatialAudio.subprojects.classes.title = Qt Spatial Audio Classes
+qhp.QtSpatialAudio.subprojects.classes.indexTitle = Qt Spatial Audio C++ Classes
+qhp.QtSpatialAudio.subprojects.classes.selectors = module:QtSpatialAudio
+qhp.QtSpatialAudio.subprojects.classes.sortPages = true
+
+qhp.QtSpatialAudio.subprojects.qmltypes.title = QML Types
+qhp.QtSpatialAudio.subprojects.qmltypes.indexTitle = Qt Spatial Audio QML Types
+qhp.QtSpatialAudio.subprojects.qmltypes.selectors = qmlclass
+qhp.QtSpatialAudio.subprojects.qmltypes.sortPages = true
+
+qhp.QtSpatialAudio.subprojects.examples.title = Examples
+qhp.QtSpatialAudio.subprojects.examples.indexTitle = Qt Spatial Audio Examples
+qhp.QtSpatialAudio.subprojects.examples.selectors = doc:example
+qhp.QtSpatialAudio.subprojects.examples.sortPages = true
+
+exampledirs += ../../../examples/spatialaudio \
+ snippets
+
+headerdirs += .. \
+ ../../spatialaudioquick3d
+
+imagedirs += src/images \
+
+sourcedirs += .. \
+ ../../spatialaudioquick3d
+
+depends = qtcore qtdoc qtgui qtquick qtqml qtnetwork qmake qtcmake qtquickcontrols qtquick3d qtmultimedia
+
+# Ignore \since commands for versions earlier than 6.3
+ignoresince = 6.4
+
+navigation.landingpage = "Qt Spatial Audio"
+navigation.cppclassespage = "Qt Spatial Audio C++ Classes"
+navigation.qmltypespage = "Qt Spatial Audio QML Types"
diff --git a/src/spatialaudio/doc/src/qtspatialaudio-cpp.qdoc b/src/spatialaudio/doc/src/qtspatialaudio-cpp.qdoc
new file mode 100644
index 000000000..aff743e82
--- /dev/null
+++ b/src/spatialaudio/doc/src/qtspatialaudio-cpp.qdoc
@@ -0,0 +1,33 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \module QtSpatialAudio
+ \title Qt Spatial Audio Module C++ Classes
+ \ingroup modules
+ \qtvariable spatialaudio
+ \qtcmakepackage SpatialAudio
+
+ \brief The \l {Qt Spatial Audio} module provides functionality for 3D audio.
+
+ \include module-use.qdocinc using qt module
+
+ \code
+ find_package(Qt6 REQUIRED COMPONENTS SpatialAudio)
+ target_link_libraries(my_project PRIVATE Qt6::SpatialAudio)
+ \endcode
+*/
+
+/*!
+ \page qtspatialaudio-modules.html
+ \title Qt Spatial Audio C++ Classes
+ \brief Provides C++ class for spatial audio use cases.
+
+ The C++ classes provide the same functionality as the Qt Quick3D spatial audio
+ module.
+
+ \section1 Classes
+
+ \generatelist {classesbymodule QtSpatialAudio}
+
+*/
diff --git a/src/spatialaudio/doc/src/qtspatialaudio-examples.qdoc b/src/spatialaudio/doc/src/qtspatialaudio-examples.qdoc
new file mode 100644
index 000000000..b2ceb118c
--- /dev/null
+++ b/src/spatialaudio/doc/src/qtspatialaudio-examples.qdoc
@@ -0,0 +1,15 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \group spatialaudio_examples
+ \ingroup multimedia_examples
+ \title Qt Spatial Audio Examples
+ \brief Demonstrates the spatial audio functionality provided by Qt.
+
+ The \l{Qt Spatial Audio} module provides cross-platform capabilities to
+ add support for spatial audio to Qt based applications.
+
+ The examples listed below show some typical use cases where audio sources are
+ located in 3D space adding virtual rooms around the source.
+*/
diff --git a/src/spatialaudio/doc/src/qtspatialaudio-index.qdoc b/src/spatialaudio/doc/src/qtspatialaudio-index.qdoc
new file mode 100644
index 000000000..784273b54
--- /dev/null
+++ b/src/spatialaudio/doc/src/qtspatialaudio-index.qdoc
@@ -0,0 +1,104 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page qtspatialaudio-index.html
+ \title Qt Spatial Audio
+ \brief The Qt Spatial Audio module provides APIs for modeling sound source
+ and their surrounds in 3D space
+
+ Qt Spatial Audio is an add-on module that provides a rich set of QML types
+ and C++ classes to implement sound fields in 3D space. It contains an easy to use
+ API for positing a listener in space, adding localized sound sources around the
+ listener and emulating virtual rooms with reverb and reflections.
+
+ \section1 Getting started
+
+ If you are new to Qt Spatial Audio, the QML types can be
+ \l{qtqml import syntax}{imported} into an application using the following
+ statement in your \c {.qml} file.
+
+ \qml
+ import QtQuick3D.SpatialAudio
+ \endqml
+
+ To link against the C++ libraries, add the following to your project's
+ \c CMakeLists.txt file. Substitute \c my_project with the name of your
+ project.
+
+ \code
+ find_package(Qt6 REQUIRED COMPONENTS SpatialAudio)
+ target_link_libraries(my_project PRIVATE Qt6::SpatialAudio)
+ \endcode
+
+ \l{Spatial Audio Overview} provides a more detailed description about how
+ to use the different classes listed below.
+
+ \section1 QML Types
+
+ The following table outlines some important QML types.
+
+ \table
+ \header
+ \li Type
+ \li Description
+ \row
+ \li \l{AudioEngine}
+ \li The engine doing the processing of the audio scene
+ \row
+ \li \l {SpatialSound}
+ \li A sound source located in 3D space.
+ \row
+ \li \l {AmbientSound}
+ \li A location independent stereo sound track.
+ \row
+ \li \l {AudioRoom}
+ \li Defines a room that generates audio reverb and reflections.
+ \endtable
+
+ \section1 C++ Classes
+
+ The following table outlines some important C++ Classes
+
+ \table
+ \header
+ \li Class
+ \li Description
+ \row
+ \li \l{QAudioEngine}
+ \li The engine doing the processing of the audio scene
+ \row
+ \li \l {QSpatialSound}
+ \li A sound source located in 3D space.
+ \row
+ \li \l {QAmbientSound}
+ \li A location independent stereo sound track.
+ \row
+ \li \l {QAudioRoom}
+ \li Defines a room that generates audio reverb and reflections.
+ \endtable
+
+ \section1 Licenses and Attributions
+
+ The Qt Spatial Audio module is available under commercial licenses from
+ \l{The Qt Company}.
+ In addition, it is available under free software licenses. These free software
+ licenses are
+ \l{GNU Lesser General Public License, version 3}, or
+ the \l{GNU General Public License, version 3}.
+ See \l{Qt Licensing} for further details.
+
+ Note that Qt Spatial Audio is not available under the \l{GNU General Public License, version 2}.
+
+ Furthermore, Qt Spatial Audio in Qt \QtVersion contains third party
+ modules under the following permissive licenses:
+
+ \generatelist{groupsbymodule attributions-qtspatialaudio}
+
+ \section1 Reference and Examples
+ \list
+ \li \l{Qt Spatial Audio QML Types}{QML Types}
+ \li \l{Qt Spatial Audio C++ Classes}{C++ Classes}
+ \li \l{Qt Spatial Audio Examples}{Examples}
+ \endlist
+*/
diff --git a/src/spatialaudio/doc/src/qtspatialaudio-qml-types.qdoc b/src/spatialaudio/doc/src/qtspatialaudio-qml-types.qdoc
new file mode 100644
index 000000000..fbd1853d3
--- /dev/null
+++ b/src/spatialaudio/doc/src/qtspatialaudio-qml-types.qdoc
@@ -0,0 +1,26 @@
+// Copyright (C) 2015 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\qmlmodule QtQuick3D.SpatialAudio
+\title Qt Spatial Audio QML Types
+\ingroup qmlmodules
+\brief Provides QML types for spatial audio.
+
+The QML types for \l{Qt Spatial Audio} support the full functionality of the
+C++ API.
+
+\section1 QML Types
+
+Qt Spatial Audio QML types are designed to be used together with \l{Qt Quick 3D}. They
+can be imported into your application using the following import statement in your
+.qml file:
+
+\qml
+import QtQuick3D.SpatialAudio
+\endqml
+
+\generatelist qmltypesbymodule QtQuick3D.SpatialAudio
+
+\noautolist
+*/
diff --git a/src/spatialaudio/doc/src/spatialaudiooverview.qdoc b/src/spatialaudio/doc/src/spatialaudiooverview.qdoc
new file mode 100644
index 000000000..62b95871e
--- /dev/null
+++ b/src/spatialaudio/doc/src/spatialaudiooverview.qdoc
@@ -0,0 +1,64 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\page spatialaudiooverview.html
+\title Spatial Audio Overview
+\brief Support for spatial audio.
+\ingroup explanations-graphicsandmultimedia
+
+The Qt Spatial Audio API provides a number of classes that allow the creation of
+three dimensional sound scene. It is defined by objects located in 3D space
+that emit sound and surrounding geometry that can be modelled using
+one or several rooms. Finally a listener can be placed into this
+sound scene at a specified position and orientation.
+
+There are both C++ and QML APIs that can be used.
+
+\section1 Creating a sound scene
+
+To create the sound scene, one first instantiates a \l QAudioEngine. This engine
+processes input sound data and geometries to create a realistic
+representation of the sound scene as it would be experienced by a person placed
+at a specific location inside the scene.
+
+The \l QAudioEngine::OutputMode property can be used to optimize the output either
+for headphones using binaural (virtual 3D) rendering or for a stereo or surround speaker
+configuration.
+
+The output device can be selected using \l QAudioEngine::outputDevice property.
+
+Once the engine is set up, we can place various sound objects into the scene by creating
+\l QSpatialSound objects and specifying a url to a sound file using the \l
+QSpatialSound::source property.
+
+\l QAudioListener can be used to define the position and orientation of a person
+listening to the sound scene. At max one listener per engine can be used. If no listener
+is specified, the engine assumes that the listener is at the origin of the coordinate system
+facing into a positive z direction, with positive y pointing upwards.
+
+In addition to sound sources and a listener, you can define a geometry that influences how the
+sound is being experienced by the listener through a set of \l QAudioRoom objects. Rooms
+are rectangular and support a wide variety of materials for each wall giving a different experience
+with different sound reflections and reverb. Room effects will get applied if the listener is
+located inside one of the rooms. If he is inside multiple rooms, the room with the smallest
+geometrical volume will take precedence.
+
+If you need some stereo overlay that is independent of the position and orientation of
+the listener (such as background music or a voice-over), you can use
+\l QAmbientSound to create the sound overlay.
+
+For a small QWidget based example showcasing one audio source that can be moved around in a room, have
+a look at the \l {audiopanning}{Spacial Audio Panning Example}.
+
+\section1 Reference Documentation
+
+\section2 C++ Classes
+
+\annotatedlist spatialaudio
+
+\section2 QML Types
+
+\annotatedlist quick3d_spatialaudio
+
+*/
diff --git a/src/spatialaudio/qambientsound.cpp b/src/spatialaudio/qambientsound.cpp
new file mode 100644
index 000000000..cdf61b918
--- /dev/null
+++ b/src/spatialaudio/qambientsound.cpp
@@ -0,0 +1,283 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include "qambientsound.h"
+#include "qambientsound_p.h"
+#include "qaudioengine_p.h"
+#include "resonance_audio.h"
+#include <qaudiosink.h>
+#include <qurl.h>
+#include <qdebug.h>
+#include <qaudiodecoder.h>
+
+QT_BEGIN_NAMESPACE
+
+void QAmbientSoundPrivate::load()
+{
+ decoder.reset(new QAudioDecoder);
+ buffers.clear();
+ currentBuffer = 0;
+ sourceDeviceFile.reset(nullptr);
+ bufPos = 0;
+ m_playing = false;
+ m_loading = true;
+ auto *ep = QAudioEnginePrivate::get(engine);
+ QAudioFormat f;
+ f.setSampleFormat(QAudioFormat::Float);
+ f.setSampleRate(ep->sampleRate);
+ f.setChannelConfig(nchannels == 2 ? QAudioFormat::ChannelConfigStereo : QAudioFormat::ChannelConfigMono);
+ decoder->setAudioFormat(f);
+ if (url.scheme().compare(u"qrc", Qt::CaseInsensitive) == 0) {
+ auto qrcFile = std::make_unique<QFile>(u':' + url.path());
+ if (!qrcFile->open(QFile::ReadOnly))
+ return;
+ sourceDeviceFile = std::move(qrcFile);
+ decoder->setSourceDevice(sourceDeviceFile.get());
+ } else {
+ decoder->setSource(url);
+ }
+ connect(decoder.get(), &QAudioDecoder::bufferReady, this, &QAmbientSoundPrivate::bufferReady);
+ connect(decoder.get(), &QAudioDecoder::finished, this, &QAmbientSoundPrivate::finished);
+ decoder->start();
+}
+
+void QAmbientSoundPrivate::getBuffer(float *buf, int nframes, int channels)
+{
+ Q_ASSERT(channels == nchannels);
+ QMutexLocker l(&mutex);
+ if (!m_playing || currentBuffer >= buffers.size()) {
+ memset(buf, 0, channels * nframes * sizeof(float));
+ } else {
+ int frames = nframes;
+ float *ff = buf;
+ while (frames) {
+ if (currentBuffer < buffers.size()) {
+ const QAudioBuffer &b = buffers.at(currentBuffer);
+ // qDebug() << s << b.format().sampleRate() << b.format().channelCount() << b.format().sampleFormat();
+ auto *f = b.constData<float>() + bufPos*nchannels;
+ int toCopy = qMin(b.frameCount() - bufPos, frames);
+ memcpy(ff, f, toCopy*sizeof(float)*nchannels);
+ ff += toCopy*nchannels;
+ frames -= toCopy;
+ bufPos += toCopy;
+ Q_ASSERT(bufPos <= b.frameCount());
+ if (bufPos == b.frameCount()) {
+ ++currentBuffer;
+ bufPos = 0;
+ }
+ } else {
+ // no more data available
+ if (m_loading)
+ qDebug() << "underrun" << frames << "frames when loading" << url;
+ memset(ff, 0, frames * channels * sizeof(float));
+ ff += frames * channels;
+ frames = 0;
+ }
+ if (!m_loading) {
+ if (currentBuffer == buffers.size()) {
+ currentBuffer = 0;
+ ++m_currentLoop;
+ }
+ if (m_loops > 0 && m_currentLoop >= m_loops) {
+ m_playing = false;
+ m_currentLoop = 0;
+ }
+ }
+ }
+ Q_ASSERT(ff - buf == channels*nframes);
+ }
+}
+
+void QAmbientSoundPrivate::bufferReady()
+{
+ QMutexLocker l(&mutex);
+ auto b = decoder->read();
+ // qDebug() << "read buffer" << b.format() << b.startTime() << b.duration();
+ buffers.append(b);
+ if (m_autoPlay)
+ m_playing = true;
+}
+
+void QAmbientSoundPrivate::finished()
+{
+ m_loading = false;
+}
+
+/*!
+ \class QAmbientSound
+ \inmodule QtSpatialAudio
+ \ingroup spatialaudio
+ \ingroup multimedia_audio
+
+ \brief A stereo overlay sound.
+
+ QAmbientSound represents a position and orientation independent sound.
+ It's commonly used for background sounds (e.g. music) that is supposed to be independent
+ of the listeners position and orientation.
+ */
+
+/*!
+ Creates a stereo sound source for \a engine.
+ */
+QAmbientSound::QAmbientSound(QAudioEngine *engine)
+ : d(new QAmbientSoundPrivate(this))
+{
+ setEngine(engine);
+}
+
+QAmbientSound::~QAmbientSound()
+{
+ setEngine(nullptr);
+ delete d;
+}
+
+/*!
+ \property QAmbientSound::volume
+
+ Defines the volume of the sound.
+
+ Values between 0 and 1 will attenuate the sound, while values above 1
+ provide an additional gain boost.
+ */
+void QAmbientSound::setVolume(float volume)
+{
+ if (d->volume == volume)
+ return;
+ d->volume = volume;
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep)
+ ep->resonanceAudio->api->SetSourceVolume(d->sourceId, d->volume);
+ emit volumeChanged();
+}
+
+float QAmbientSound::volume() const
+{
+ return d->volume;
+}
+
+void QAmbientSound::setSource(const QUrl &url)
+{
+ if (d->url == url)
+ return;
+ d->url = url;
+
+ d->load();
+ emit sourceChanged();
+}
+
+/*!
+ \property QAmbientSound::source
+
+ The source file for the sound to be played.
+ */
+QUrl QAmbientSound::source() const
+{
+ return d->url;
+}
+/*!
+ \enum QAmbientSound::Loops
+
+ Lets you control the playback loop using the following values:
+
+ \value Infinite Loops infinitely
+ \value Once Stops playback after running once
+*/
+/*!
+ \property QAmbientSound::loops
+
+ Determines how many times the sound is played before the player stops.
+ Set to QAmbientSound::Infinite to play the current sound in
+ a loop forever.
+
+ The default value is \c 1.
+ */
+int QAmbientSound::loops() const
+{
+ return d->m_loops.loadRelaxed();
+}
+
+void QAmbientSound::setLoops(int loops)
+{
+ int oldLoops = d->m_loops.fetchAndStoreRelaxed(loops);
+ if (oldLoops != loops)
+ emit loopsChanged();
+}
+
+/*!
+ \property QAmbientSound::autoPlay
+
+ Determines whether the sound should automatically start playing when a source
+ gets specified.
+
+ The default value is \c true.
+ */
+bool QAmbientSound::autoPlay() const
+{
+ return d->m_autoPlay.loadRelaxed();
+}
+
+void QAmbientSound::setAutoPlay(bool autoPlay)
+{
+ bool old = d->m_autoPlay.fetchAndStoreRelaxed(autoPlay);
+ if (old != autoPlay)
+ emit autoPlayChanged();
+}
+
+/*!
+ Starts playing back the sound. Does nothing if the sound is already playing.
+ */
+void QAmbientSound::play()
+{
+ d->play();
+}
+
+/*!
+ Pauses sound playback. Calling play() will continue playback.
+ */
+void QAmbientSound::pause()
+{
+ d->pause();
+}
+
+/*!
+ Stops sound playback and resets the current position and current loop count to 0.
+ Calling play() will start playback at the beginning of the sound file.
+ */
+void QAmbientSound::stop()
+{
+ d->stop();
+}
+
+/*!
+ \internal
+ */
+void QAmbientSound::setEngine(QAudioEngine *engine)
+{
+ if (d->engine == engine)
+ return;
+
+ // Remove self from old engine (if necessary)
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep)
+ ep->removeStereoSound(this);
+
+ d->engine = engine;
+
+ // Add self to new engine if necessary
+ ep = QAudioEnginePrivate::get(d->engine);
+ if (ep) {
+ ep->addStereoSound(this);
+ ep->resonanceAudio->api->SetSourceVolume(d->sourceId, d->volume);
+ }
+}
+
+/*!
+ Returns the engine associated with this sound.
+ */
+QAudioEngine *QAmbientSound::engine() const
+{
+ return d->engine;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qambientsound.cpp"
diff --git a/src/spatialaudio/qambientsound.h b/src/spatialaudio/qambientsound.h
new file mode 100644
index 000000000..f10159251
--- /dev/null
+++ b/src/spatialaudio/qambientsound.h
@@ -0,0 +1,68 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#ifndef QAMBIENTSOUND_H
+#define QAMBIENTSOUND_H
+
+#include <QtSpatialAudio/qtspatialaudioglobal.h>
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtCore/QUrl>
+#include <QtCore/QObject>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioEngine;
+class QAmbientSoundPrivate;
+
+class Q_SPATIALAUDIO_EXPORT QAmbientSound : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
+ Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged)
+ Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged)
+
+public:
+ explicit QAmbientSound(QAudioEngine *engine);
+ ~QAmbientSound();
+
+ void setSource(const QUrl &url);
+ QUrl source() const;
+
+ enum Loops
+ {
+ Infinite = -1,
+ Once = 1
+ };
+ Q_ENUM(Loops)
+
+ int loops() const;
+ void setLoops(int loops);
+
+ bool autoPlay() const;
+ void setAutoPlay(bool autoPlay);
+
+ void setVolume(float volume);
+ float volume() const;
+
+ QAudioEngine *engine() const;
+
+Q_SIGNALS:
+ void sourceChanged();
+ void loopsChanged();
+ void autoPlayChanged();
+ void volumeChanged();
+
+public Q_SLOTS:
+ void play();
+ void pause();
+ void stop();
+
+private:
+ void setEngine(QAudioEngine *engine);
+ friend class QAmbientSoundPrivate;
+ QAmbientSoundPrivate *d = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudio/qambientsound_p.h b/src/spatialaudio/qambientsound_p.h
new file mode 100644
index 000000000..d26404f43
--- /dev/null
+++ b/src/spatialaudio/qambientsound_p.h
@@ -0,0 +1,84 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+
+#ifndef QAMBIENTSOUND_P_H
+#define QAMBIENTSOUND_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qtspatialaudioglobal_p.h>
+#include <qmutex.h>
+#include <qurl.h>
+#include <qfile.h>
+#include <qaudiodecoder.h>
+#include <qaudiobuffer.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioEngine;
+
+class QAmbientSoundPrivate : public QObject
+{
+public:
+ QAmbientSoundPrivate(QObject *parent, int nchannels = 2)
+ : QObject(parent)
+ , nchannels(nchannels)
+ {}
+
+ template<typename T>
+ static QAmbientSoundPrivate *get(T *soundSource) { return soundSource ? soundSource->d : nullptr; }
+
+ QUrl url;
+ float volume = 1.;
+ int nchannels = 2;
+ std::unique_ptr<QAudioDecoder> decoder;
+ std::unique_ptr<QFile> sourceDeviceFile;
+ QAudioEngine *engine = nullptr;
+
+ QMutex mutex;
+ int currentBuffer = 0;
+ int bufPos = 0;
+ int m_currentLoop = 0;
+ QList<QAudioBuffer> buffers;
+ int sourceId = -1; // kInvalidSourceId
+
+ QAtomicInteger<bool> m_autoPlay = true;
+ QAtomicInteger<bool> m_playing = false;
+ QAtomicInt m_loops = 1;
+ bool m_loading = false;
+
+ void play() {
+ m_playing = true;
+ }
+ void pause() {
+ m_playing = false;
+ }
+ void stop() {
+ QMutexLocker locker(&mutex);
+ m_playing = false;
+ currentBuffer = 0;
+ bufPos = 0;
+ m_currentLoop = 0;
+ }
+
+ void load();
+ void getBuffer(float *buf, int frames, int channels);
+
+private Q_SLOTS:
+ void bufferReady();
+ void finished();
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QAMBIENTSOUND_P_H
diff --git a/src/spatialaudio/qambisonicdecoder.cpp b/src/spatialaudio/qambisonicdecoder.cpp
new file mode 100644
index 000000000..4404b11b0
--- /dev/null
+++ b/src/spatialaudio/qambisonicdecoder.cpp
@@ -0,0 +1,314 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include "qambisonicdecoder_p.h"
+
+#include "qambisonicdecoderdata_p.h"
+#include <cmath>
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+// Ambisonic decoding is described in detail in https://ambisonics.dreamhosters.com/BLaH3.pdf.
+// We're using a phase matched band splitting filter to split the ambisonic signal into a low
+// and high frequency component and apply matrix conversions to those components individually
+// as described in the document.
+//
+// We are currently not using a near field compensation filter, something that could potentially
+// improve sound quality further.
+//
+// For mono and stereo decoding, we use a simpler algorithm to avoid artificially dampening signals
+// coming from the back, as we do not have any speakers in that direction and the calculations
+// through matlab would give us audible 'holes'.
+
+struct QAmbisonicDecoderData
+{
+ QAudioFormat::ChannelConfig config;
+ const float *lf[3];
+ const float *hf[3];
+ const float *reverb;
+};
+
+const float reverb_x_0[] =
+{
+ 1.f, 0.f, // L
+ 0.f, 1.f, // R
+ .7f, .7f, // C
+ 1.f, 0.f, // Ls
+ 0.f, 1.f, // Rs
+ 1.f, 0.f, // Lb
+ 0.f, 1.f, // Rb
+};
+
+const float reverb_x_1[] =
+{
+ 1.f, 0.f, // L
+ 0.f, 1.f, // R
+ .7f, .7f, // C
+ .0f, .0f, // LFE
+ 1.f, 0.f, // Ls
+ 0.f, 1.f, // Rs
+ 1.f, 0.f, // Lb
+ 0.f, 1.f, // Rb
+};
+
+static const QAmbisonicDecoderData decoderMap[] =
+{
+ { QAudioFormat::ChannelConfigSurround5Dot0,
+ { decoderMatrix_5dot0_1_lf, decoderMatrix_5dot0_2_lf, decoderMatrix_5dot0_3_lf },
+ { decoderMatrix_5dot0_1_hf, decoderMatrix_5dot0_2_hf, decoderMatrix_5dot0_3_hf },
+ reverb_x_0
+ },
+ { QAudioFormat::ChannelConfigSurround5Dot1,
+ { decoderMatrix_5dot1_1_lf, decoderMatrix_5dot1_2_lf, decoderMatrix_5dot1_3_lf },
+ { decoderMatrix_5dot1_1_hf, decoderMatrix_5dot1_2_hf, decoderMatrix_5dot1_3_hf },
+ reverb_x_1
+ },
+ { QAudioFormat::ChannelConfigSurround7Dot0,
+ { decoderMatrix_7dot0_1_lf, decoderMatrix_7dot0_2_lf, decoderMatrix_7dot0_3_lf },
+ { decoderMatrix_7dot0_1_hf, decoderMatrix_7dot0_2_hf, decoderMatrix_7dot0_3_hf },
+ reverb_x_0
+ },
+ { QAudioFormat::ChannelConfigSurround7Dot1,
+ { decoderMatrix_7dot1_1_lf, decoderMatrix_7dot1_2_lf, decoderMatrix_7dot1_3_lf },
+ { decoderMatrix_7dot1_1_hf, decoderMatrix_7dot1_2_hf, decoderMatrix_7dot1_3_hf },
+ reverb_x_1
+ }
+};
+
+// Implements a split second order IIR filter
+// The audio data is split into a phase synced low and high frequency part
+// This allows us to apply different factors to both parts for better sound
+// localization when converting from ambisonic formats
+//
+// Details are described in https://ambisonics.dreamhosters.com/BLaH3.pdf, Appendix A.2.
+class QAmbisonicDecoderFilter
+{
+public:
+ QAmbisonicDecoderFilter() = default;
+ void configure(float sampleRate, float cutoffFrequency = 380)
+ {
+ double k = tan(M_PI*cutoffFrequency/sampleRate);
+ a1 = float(2.*(k*k - 1.)/(k*k + 2*k + 1.));
+ a2 = float((k*k - 2*k + 1.)/(k*k + 2*k + 1.));
+
+ b0_lf = float(k*k/(k*k + 2*k + 1));
+ b1_lf = 2.f*b0_lf;
+
+ b0_hf = float(1./(k*k + 2*k + 1));
+ b1_hf = -2.f*b0_hf;
+ }
+
+ struct Output
+ {
+ float lf;
+ float hf;
+ };
+
+ Output next(float x)
+ {
+ float r_lf = x*b0_lf +
+ prevX[0]*b1_lf +
+ prevX[1]*b0_lf -
+ prevR_lf[0]*a1 -
+ prevR_lf[1]*a2;
+ float r_hf = x*b0_hf +
+ prevX[0]*b1_hf +
+ prevX[1]*b0_hf -
+ prevR_hf[0]*a1 -
+ prevR_hf[1]*a2;
+ prevX[1] = prevX[0];
+ prevX[0] = x;
+ prevR_lf[1] = prevR_lf[0];
+ prevR_lf[0] = r_lf;
+ prevR_hf[1] = prevR_hf[0];
+ prevR_hf[0] = r_hf;
+ return { r_lf, r_hf };
+ }
+
+private:
+ float a1 = 0.;
+ float a2 = 0.;
+
+ float b0_hf = 0.;
+ float b1_hf = 0.;
+
+ float b0_lf = 0.;
+ float b1_lf = 0.;
+
+ float prevX[2] = {};
+ float prevR_lf[2] = {};
+ float prevR_hf[2] = {};
+};
+
+
+QAmbisonicDecoder::QAmbisonicDecoder(AmbisonicLevel ambisonicLevel, const QAudioFormat &format)
+ : level(ambisonicLevel)
+{
+ Q_ASSERT(level > 0 && level <= 3);
+ inputChannels = (level+1)*(level+1);
+ outputChannels = format.channelCount();
+
+ channelConfig = format.channelConfig();
+ if (channelConfig == QAudioFormat::ChannelConfigUnknown)
+ channelConfig = format.defaultChannelConfigForChannelCount(format.channelCount());
+
+ if (channelConfig == QAudioFormat::ChannelConfigMono ||
+ channelConfig == QAudioFormat::ChannelConfigStereo ||
+ channelConfig == QAudioFormat::ChannelConfig2Dot1 ||
+ channelConfig == QAudioFormat::ChannelConfig3Dot0 ||
+ channelConfig == QAudioFormat::ChannelConfig3Dot1) {
+ // these are non surround configs and handled manually to avoid
+ // audible holes for sounds coming from behing
+ //
+ // We use a simpler decoding process here, only taking first order
+ // ambisonics into account
+ //
+ // Left and right channels get 50% W and 50% X
+ // Center gets 50% W and 50% Y
+ // LFE gets 50% W
+ simpleDecoderFactors = new float[4*outputChannels];
+ float *r = new float[2*outputChannels]; // reverb output is in stereo
+ float *f = simpleDecoderFactors;
+ reverbFactors = r;
+ if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::FrontLeft)) {
+ f[0] = 0.5f; f[1] = 0.5f; f[2] = 0.; f[3] = 0.f;
+ f += 4;
+ r[0] = 1.; r[1] = 0.;
+ r += 2;
+ }
+ if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::FrontRight)) {
+ f[0] = 0.5f; f[1] = -0.5f; f[2] = 0.; f[3] = 0.f;
+ f += 4;
+ r[0] = 0.; r[1] = 1.;
+ r += 2;
+ }
+ if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::FrontCenter)) {
+ f[0] = 0.5f; f[1] = -0.f; f[2] = 0.; f[3] = 0.5f;
+ f += 4;
+ r[0] = .5; r[1] = .5;
+ r += 2;
+ }
+ if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::LFE)) {
+ f[0] = 0.5f; f[1] = -0.f; f[2] = 0.; f[3] = 0.0f;
+ f += 4;
+ r[0] = 0.; r[1] = 0.;
+ r += 2;
+ }
+ Q_UNUSED(f);
+ Q_UNUSED(r);
+ Q_ASSERT((f - simpleDecoderFactors) == 4*outputChannels);
+ Q_ASSERT((r - reverbFactors) == 2*outputChannels);
+
+ return;
+ }
+
+ for (const auto &d : decoderMap) {
+ if (d.config == channelConfig) {
+ decoderData = &d;
+ reverbFactors = decoderData->reverb;
+ break;
+ }
+ }
+ if (!decoderData) {
+ // can't handle this,
+ outputChannels = 0;
+ return;
+ }
+
+ filters = new QAmbisonicDecoderFilter[inputChannels];
+ for (int i = 0; i < inputChannels; ++i)
+ filters[i].configure(format.sampleRate());
+}
+
+QAmbisonicDecoder::~QAmbisonicDecoder()
+{
+ if (simpleDecoderFactors) {
+ delete simpleDecoderFactors;
+ delete reverbFactors;
+ }
+}
+
+void QAmbisonicDecoder::processBuffer(const float *input[], float *output, int nSamples)
+{
+ float *o = output;
+ memset(o, 0, nSamples*outputChannels*sizeof(float));
+
+ if (simpleDecoderFactors) {
+ for (int i = 0; i < nSamples; ++i) {
+ for (int j = 0; j < 4; ++j) {
+ for (int k = 0; k < outputChannels; ++k)
+ o[k] += simpleDecoderFactors[k*4 + j]*input[j][i];
+ }
+ o += outputChannels;
+ }
+ return;
+ }
+
+ const float *matrix_hi = decoderData->hf[level - 1];
+ const float *matrix_lo = decoderData->lf[level - 1];
+ for (int i = 0; i < nSamples; ++i) {
+ QAmbisonicDecoderFilter::Output buf[maxAmbisonicChannels];
+ for (int j = 0; j < inputChannels; ++j)
+ buf[j] = filters[j].next(input[j][i]);
+ for (int j = 0; j < inputChannels; ++j) {
+ for (int k = 0; k < outputChannels; ++k)
+ o[k] += matrix_lo[k*inputChannels + j]*buf[j].lf + matrix_hi[k*inputChannels + j]*buf[j].hf;
+ }
+ o += outputChannels;
+ }
+}
+
+void QAmbisonicDecoder::processBuffer(const float *input[], short *output, int nSamples)
+{
+ const float *reverb[] = { nullptr, nullptr };
+ return processBufferWithReverb(input, reverb, output, nSamples);
+}
+
+void QAmbisonicDecoder::processBufferWithReverb(const float *input[], const float *reverb[2], short *output, int nSamples)
+{
+ if (simpleDecoderFactors) {
+ for (int i = 0; i < nSamples; ++i) {
+ float o[4] = {};
+ for (int k = 0; k < outputChannels; ++k) {
+ for (int j = 0; j < 4; ++j)
+ o[k] += simpleDecoderFactors[k*4 + j]*input[j][i];
+ }
+ if (reverb[0]) {
+ for (int k = 0; k < outputChannels; ++k) {
+ o[k] += reverb[0][i]*reverbFactors[2*k] + reverb[1][i]*reverbFactors[2*k+1];
+ }
+ }
+
+ for (int k = 0; k < outputChannels; ++k)
+ output[k] = static_cast<short>(o[k]*32768.);
+ output += outputChannels;
+ }
+ return;
+ }
+
+ // qDebug() << "XXX" << inputChannels << outputChannels;
+ const float *matrix_hi = decoderData->hf[level - 1];
+ const float *matrix_lo = decoderData->lf[level - 1];
+ for (int i = 0; i < nSamples; ++i) {
+ QAmbisonicDecoderFilter::Output buf[maxAmbisonicChannels];
+ for (int j = 0; j < inputChannels; ++j)
+ buf[j] = filters[j].next(input[j][i]);
+ float o[32] = {}; // we can't support more than 32 channels from our API
+ for (int j = 0; j < inputChannels; ++j) {
+ for (int k = 0; k < outputChannels; ++k)
+ o[k] += matrix_lo[k*inputChannels + j]*buf[j].lf + matrix_hi[k*inputChannels + j]*buf[j].hf;
+ }
+ if (reverb[0]) {
+ for (int k = 0; k < outputChannels; ++k) {
+ o[k] += reverb[0][i]*reverbFactors[2*k] + reverb[1][i]*reverbFactors[2*k+1];
+ }
+ }
+ for (int k = 0; k < outputChannels; ++k)
+ output[k] = static_cast<short>(o[k]*32768.);
+ output += outputChannels;
+ }
+
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/spatialaudio/qambisonicdecoder_p.h b/src/spatialaudio/qambisonicdecoder_p.h
new file mode 100644
index 000000000..9ac60c2a7
--- /dev/null
+++ b/src/spatialaudio/qambisonicdecoder_p.h
@@ -0,0 +1,69 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#ifndef QAMBISONICDECODER_P_H
+#define QAMBISONICDECODER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qtspatialaudioglobal_p.h>
+#include <qaudioformat.h>
+
+QT_BEGIN_NAMESPACE
+
+struct QAmbisonicDecoderData;
+class QAmbisonicDecoderFilter;
+
+class QAmbisonicDecoder
+{
+public:
+ enum AmbisonicLevel
+ {
+ AmbisonicLevel1 = 1,
+ LowQuality = AmbisonicLevel1,
+ AmbisonicLevel2 = 2,
+ MediumQuality = AmbisonicLevel2,
+ AmbisonicLevel3 = 3,
+ HighQuality = AmbisonicLevel3
+ };
+ QAmbisonicDecoder(AmbisonicLevel ambisonicLevel, const QAudioFormat &format);
+ ~QAmbisonicDecoder();
+
+ bool hasValidConfig() const { return outputChannels > 0; }
+
+ int nInputChannels() const { return inputChannels; }
+ int nOutputChannels() const { return outputChannels; }
+
+ int outputSize(int nSamples) const { return outputChannels * nSamples; }
+
+ // input is planar, output interleaved
+ void processBuffer(const float *input[], float *output, int nSamples);
+ void processBuffer(const float *input[], short *output, int nSamples);
+
+ void processBufferWithReverb(const float *input[], const float *reverb[2], short *output, int nSamples);
+
+ static constexpr int maxAmbisonicChannels = 16;
+ static constexpr int maxAmbisonicLevel = 3;
+private:
+ QAudioFormat::ChannelConfig channelConfig;
+ AmbisonicLevel level = AmbisonicLevel1;
+ int inputChannels = 0;
+ int outputChannels = 0;
+ const QAmbisonicDecoderData *decoderData = nullptr;
+ QAmbisonicDecoderFilter *filters = nullptr;
+ float *simpleDecoderFactors = nullptr;
+ const float *reverbFactors = nullptr;
+};
+
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudio/qambisonicdecoderdata_p.h b/src/spatialaudio/qambisonicdecoderdata_p.h
new file mode 100644
index 000000000..dfee9213a
--- /dev/null
+++ b/src/spatialaudio/qambisonicdecoderdata_p.h
@@ -0,0 +1,279 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#ifndef QAMBISONICDECODERDATA_P_H
+#define QAMBISONICDECODERDATA_P_H
+
+#include <qtspatialaudioglobal_p.h>
+
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+// This file is generated by the matlab/octave file adt_generate_qt.m
+// using the Ambisonic Decoder Toolbox (https://bitbucket.org/ambidecodertoolbox/adt/src/master/)
+
+
+QT_BEGIN_NAMESPACE
+
+// Decoder matrix for 5dot0, ambisonic level 1
+static constexpr float decoderMatrix_5dot0_1_lf[5*4] = {
+0.255580f, 0.430877f, 0.000000f, 0.386458f, // L
+0.255573f, -0.430877f, 0.000000f, 0.386450f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, // C
+0.552170f, 0.623932f, 0.000000f, -0.628578f, // Ls
+0.552175f, -0.623939f, 0.000000f, -0.628571f, // Rs
+};
+
+// Decoder matrix for 5dot0, ambisonic level 1
+static constexpr float decoderMatrix_5dot0_1_hf[5*4] = {
+0.361445f, 0.351810f, 0.000000f, 0.315542f, // L
+0.361435f, -0.351809f, 0.000000f, 0.315535f, // R
+0.191780f, 0.000000f, 0.000000f, 0.268870f, // C
+0.780886f, 0.509439f, 0.000000f, -0.513232f, // Ls
+0.780893f, -0.509444f, 0.000000f, -0.513226f, // Rs
+};
+
+// Decoder matrix for 5dot0, ambisonic level 2
+static constexpr float decoderMatrix_5dot0_2_lf[5*9] = {
+0.255580f, 0.430877f, 0.000000f, 0.386458f, 0.157509f, 0.000000f, -0.095304f, 0.000000f, -0.013008f, // L
+0.255573f, -0.430877f, 0.000000f, 0.386450f, -0.157507f, 0.000000f, -0.095343f, 0.000000f, -0.013009f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, 0.000000f, 0.000000f, -0.056105f, 0.000000f, 0.111010f, // C
+0.552170f, 0.623932f, 0.000000f, -0.628578f, -0.041978f, 0.000000f, -0.139072f, 0.000000f, -0.030798f, // Ls
+0.552175f, -0.623939f, 0.000000f, -0.628571f, 0.041979f, 0.000000f, -0.139039f, 0.000000f, -0.030796f, // Rs
+};
+
+// Decoder matrix for 5dot0, ambisonic level 2
+static constexpr float decoderMatrix_5dot0_2_hf[5*9] = {
+0.404108f, 0.527714f, 0.000000f, 0.473313f, 0.099617f, 0.000000f, -0.060276f, 0.000000f, -0.008227f, // L
+0.404097f, -0.527714f, 0.000000f, 0.473303f, -0.099616f, 0.000000f, -0.060300f, 0.000000f, -0.008228f, // R
+0.214417f, 0.000000f, 0.000000f, 0.403305f, 0.000000f, 0.000000f, -0.035484f, 0.000000f, 0.070209f, // C
+0.873057f, 0.764158f, 0.000000f, -0.769848f, -0.026549f, 0.000000f, -0.087957f, 0.000000f, -0.019478f, // Ls
+0.873065f, -0.764166f, 0.000000f, -0.769839f, 0.026550f, 0.000000f, -0.087936f, 0.000000f, -0.019477f, // Rs
+};
+
+// Decoder matrix for 5dot0, ambisonic level 3
+static constexpr float decoderMatrix_5dot0_3_lf[5*16] = {
+0.255580f, 0.430877f, 0.000000f, 0.386458f, 0.157509f, 0.000000f, -0.095304f, 0.000000f, -0.013008f, 0.013422f, 0.000000f, 0.030238f, 0.000000f, 0.025660f, 0.000000f, -0.014215f, // L
+0.255573f, -0.430877f, 0.000000f, 0.386450f, -0.157507f, 0.000000f, -0.095343f, 0.000000f, -0.013009f, -0.013422f, 0.000000f, -0.030227f, 0.000000f, 0.025649f, 0.000000f, -0.014214f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, 0.000000f, 0.000000f, -0.056105f, 0.000000f, 0.111010f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.018999f, 0.000000f, 0.020478f, // C
+0.552170f, 0.623932f, 0.000000f, -0.628578f, -0.041978f, 0.000000f, -0.139072f, 0.000000f, -0.030798f, -0.012642f, 0.000000f, 0.049794f, 0.000000f, -0.073727f, 0.000000f, -0.001768f, // Ls
+0.552175f, -0.623939f, 0.000000f, -0.628571f, 0.041979f, 0.000000f, -0.139039f, 0.000000f, -0.030796f, 0.012642f, 0.000000f, -0.049793f, 0.000000f, -0.073721f, 0.000000f, -0.001769f, // Rs
+};
+
+// Decoder matrix for 5dot0, ambisonic level 3
+static constexpr float decoderMatrix_5dot0_3_hf[5*16] = {
+0.426355f, 0.618969f, 0.000000f, 0.555160f, 0.160893f, 0.000000f, -0.097352f, 0.000000f, -0.013287f, 0.006823f, 0.000000f, 0.015372f, 0.000000f, 0.013045f, 0.000000f, -0.007226f, // L
+0.426343f, -0.618969f, 0.000000f, 0.555149f, -0.160891f, 0.000000f, -0.097392f, 0.000000f, -0.013289f, -0.006823f, 0.000000f, -0.015367f, 0.000000f, 0.013039f, 0.000000f, -0.007226f, // R
+0.226221f, 0.000000f, 0.000000f, 0.473046f, 0.000000f, 0.000000f, -0.057310f, 0.000000f, 0.113395f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.009658f, 0.000000f, 0.010410f, // C
+0.921121f, 0.896300f, 0.000000f, -0.902974f, -0.042880f, 0.000000f, -0.142060f, 0.000000f, -0.031459f, -0.006427f, 0.000000f, 0.025314f, 0.000000f, -0.037481f, 0.000000f, -0.000899f, // Ls
+0.921130f, -0.896310f, 0.000000f, -0.902963f, 0.042881f, 0.000000f, -0.142027f, 0.000000f, -0.031457f, 0.006427f, 0.000000f, -0.025313f, 0.000000f, -0.037478f, 0.000000f, -0.000899f, // Rs
+};
+
+// Decoder matrix for 5dot1, ambisonic level 1
+static constexpr float decoderMatrix_5dot1_1_lf[6*4] = {
+0.255580f, 0.430877f, 0.000000f, 0.386458f, // L
+0.255573f, -0.430877f, 0.000000f, 0.386450f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, // C
+0.5f, 0.0f, 0.0f, 0.0f, // LFE
+0.552170f, 0.623932f, 0.000000f, -0.628578f, // Ls
+0.552175f, -0.623939f, 0.000000f, -0.628571f, // Rs
+};
+
+// Decoder matrix for 5dot1, ambisonic level 1
+static constexpr float decoderMatrix_5dot1_1_hf[6*4] = {
+0.361445f, 0.351810f, 0.000000f, 0.315542f, // L
+0.361435f, -0.351809f, 0.000000f, 0.315535f, // R
+0.191780f, 0.000000f, 0.000000f, 0.268870f, // C
+0.0f, 0.0f, 0.0f, 0.0f, // LFE
+0.780886f, 0.509439f, 0.000000f, -0.513232f, // Ls
+0.780893f, -0.509444f, 0.000000f, -0.513226f, // Rs
+};
+
+// Decoder matrix for 5dot1, ambisonic level 2
+static constexpr float decoderMatrix_5dot1_2_lf[6*9] = {
+0.255580f, 0.430877f, 0.000000f, 0.386458f, 0.157509f, 0.000000f, -0.095304f, 0.000000f, -0.013008f, // L
+0.255573f, -0.430877f, 0.000000f, 0.386450f, -0.157507f, 0.000000f, -0.095343f, 0.000000f, -0.013009f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, 0.000000f, 0.000000f, -0.056105f, 0.000000f, 0.111010f, // C
+0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // LFE
+0.552170f, 0.623932f, 0.000000f, -0.628578f, -0.041978f, 0.000000f, -0.139072f, 0.000000f, -0.030798f, // Ls
+0.552175f, -0.623939f, 0.000000f, -0.628571f, 0.041979f, 0.000000f, -0.139039f, 0.000000f, -0.030796f, // Rs
+};
+
+// Decoder matrix for 5dot1, ambisonic level 2
+static constexpr float decoderMatrix_5dot1_2_hf[6*9] = {
+0.404108f, 0.527714f, 0.000000f, 0.473313f, 0.099617f, 0.000000f, -0.060276f, 0.000000f, -0.008227f, // L
+0.404097f, -0.527714f, 0.000000f, 0.473303f, -0.099616f, 0.000000f, -0.060300f, 0.000000f, -0.008228f, // R
+0.214417f, 0.000000f, 0.000000f, 0.403305f, 0.000000f, 0.000000f, -0.035484f, 0.000000f, 0.070209f, // C
+0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // LFE
+0.873057f, 0.764158f, 0.000000f, -0.769848f, -0.026549f, 0.000000f, -0.087957f, 0.000000f, -0.019478f, // Ls
+0.873065f, -0.764166f, 0.000000f, -0.769839f, 0.026550f, 0.000000f, -0.087936f, 0.000000f, -0.019477f, // Rs
+};
+
+// Decoder matrix for 5dot1, ambisonic level 3
+static constexpr float decoderMatrix_5dot1_3_lf[6*16] = {
+0.255580f, 0.430877f, 0.000000f, 0.386458f, 0.157509f, 0.000000f, -0.095304f, 0.000000f, -0.013008f, 0.013422f, 0.000000f, 0.030238f, 0.000000f, 0.025660f, 0.000000f, -0.014215f, // L
+0.255573f, -0.430877f, 0.000000f, 0.386450f, -0.157507f, 0.000000f, -0.095343f, 0.000000f, -0.013009f, -0.013422f, 0.000000f, -0.030227f, 0.000000f, 0.025649f, 0.000000f, -0.014214f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, 0.000000f, 0.000000f, -0.056105f, 0.000000f, 0.111010f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.018999f, 0.000000f, 0.020478f, // C
+0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // LFE
+0.552170f, 0.623932f, 0.000000f, -0.628578f, -0.041978f, 0.000000f, -0.139072f, 0.000000f, -0.030798f, -0.012642f, 0.000000f, 0.049794f, 0.000000f, -0.073727f, 0.000000f, -0.001768f, // Ls
+0.552175f, -0.623939f, 0.000000f, -0.628571f, 0.041979f, 0.000000f, -0.139039f, 0.000000f, -0.030796f, 0.012642f, 0.000000f, -0.049793f, 0.000000f, -0.073721f, 0.000000f, -0.001769f, // Rs
+};
+
+// Decoder matrix for 5dot1, ambisonic level 3
+static constexpr float decoderMatrix_5dot1_3_hf[6*16] = {
+0.426355f, 0.618969f, 0.000000f, 0.555160f, 0.160893f, 0.000000f, -0.097352f, 0.000000f, -0.013287f, 0.006823f, 0.000000f, 0.015372f, 0.000000f, 0.013045f, 0.000000f, -0.007226f, // L
+0.426343f, -0.618969f, 0.000000f, 0.555149f, -0.160891f, 0.000000f, -0.097392f, 0.000000f, -0.013289f, -0.006823f, 0.000000f, -0.015367f, 0.000000f, 0.013039f, 0.000000f, -0.007226f, // R
+0.226221f, 0.000000f, 0.000000f, 0.473046f, 0.000000f, 0.000000f, -0.057310f, 0.000000f, 0.113395f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.009658f, 0.000000f, 0.010410f, // C
+0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // LFE
+0.921121f, 0.896300f, 0.000000f, -0.902974f, -0.042880f, 0.000000f, -0.142060f, 0.000000f, -0.031459f, -0.006427f, 0.000000f, 0.025314f, 0.000000f, -0.037481f, 0.000000f, -0.000899f, // Ls
+0.921130f, -0.896310f, 0.000000f, -0.902963f, 0.042881f, 0.000000f, -0.142027f, 0.000000f, -0.031457f, 0.006427f, 0.000000f, -0.025313f, 0.000000f, -0.037478f, 0.000000f, -0.000899f, // Rs
+};
+
+// Decoder matrix for 7dot0, ambisonic level 1
+static constexpr float decoderMatrix_7dot0_1_lf[7*4] = {
+0.205900f, 0.314866f, 0.000000f, 0.366133f, // L
+0.205883f, -0.314871f, 0.000000f, 0.366126f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, // C
+0.276200f, 0.619758f, 0.000000f, 0.000000f, // Ls
+0.276228f, -0.619768f, 0.000000f, 0.000000f, // Rs
+0.276222f, 0.309884f, 0.000000f, -0.536733f, // Lb
+0.276196f, -0.309893f, 0.000000f, -0.536723f, // Rb
+};
+
+// Decoder matrix for 7dot0, ambisonic level 1
+static constexpr float decoderMatrix_7dot0_1_hf[7*4] = {
+0.291186f, 0.257087f, 0.000000f, 0.298946f, // L
+0.291162f, -0.257091f, 0.000000f, 0.298940f, // R
+0.191780f, 0.000000f, 0.000000f, 0.268870f, // C
+0.390605f, 0.506030f, 0.000000f, 0.000000f, // Ls
+0.390645f, -0.506039f, 0.000000f, 0.000000f, // Rs
+0.390637f, 0.253019f, 0.000000f, -0.438240f, // Lb
+0.390600f, -0.253026f, 0.000000f, -0.438232f, // Rb
+};
+
+// Decoder matrix for 7dot0, ambisonic level 2
+static constexpr float decoderMatrix_7dot0_2_lf[7*9] = {
+0.205900f, 0.314866f, 0.000000f, 0.366133f, 0.144868f, 0.000000f, -0.081538f, 0.000000f, 0.023353f, // L
+0.205883f, -0.314871f, 0.000000f, 0.366126f, -0.144867f, 0.000000f, -0.081652f, 0.000000f, 0.023347f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, 0.000000f, 0.000000f, -0.056105f, 0.000000f, 0.111010f, // C
+0.276200f, 0.619758f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.106989f, 0.000000f, -0.163267f, // Ls
+0.276228f, -0.619768f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.106856f, 0.000000f, -0.163267f, // Rs
+0.276222f, 0.309884f, 0.000000f, -0.536733f, -0.141395f, 0.000000f, -0.106873f, 0.000000f, 0.081634f, // Lb
+0.276196f, -0.309893f, 0.000000f, -0.536723f, 0.141394f, 0.000000f, -0.107038f, 0.000000f, 0.081628f, // Rb
+};
+
+// Decoder matrix for 7dot0, ambisonic level 2
+static constexpr float decoderMatrix_7dot0_2_hf[7*9] = {
+0.325556f, 0.385630f, 0.000000f, 0.448419f, 0.091623f, 0.000000f, -0.051569f, 0.000000f, 0.014770f, // L
+0.325529f, -0.385637f, 0.000000f, 0.448410f, -0.091622f, 0.000000f, -0.051641f, 0.000000f, 0.014766f, // R
+0.214417f, 0.000000f, 0.000000f, 0.403305f, 0.000000f, 0.000000f, -0.035484f, 0.000000f, 0.070209f, // C
+0.436710f, 0.759045f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.067666f, 0.000000f, -0.103259f, // Ls
+0.436755f, -0.759058f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.067582f, 0.000000f, -0.103259f, // Rs
+0.436746f, 0.379529f, 0.000000f, -0.657361f, -0.089426f, 0.000000f, -0.067593f, 0.000000f, 0.051630f, // Lb
+0.436704f, -0.379539f, 0.000000f, -0.657348f, 0.089426f, 0.000000f, -0.067697f, 0.000000f, 0.051626f, // Rb
+};
+
+// Decoder matrix for 7dot0, ambisonic level 3
+static constexpr float decoderMatrix_7dot0_3_lf[7*16] = {
+0.205900f, 0.314866f, 0.000000f, 0.366133f, 0.144868f, 0.000000f, -0.081538f, 0.000000f, 0.023353f, 0.019489f, 0.000000f, 0.019857f, 0.000000f, 0.022683f, 0.000000f, -0.011066f, // L
+0.205883f, -0.314871f, 0.000000f, 0.366126f, -0.144867f, 0.000000f, -0.081652f, 0.000000f, 0.023347f, -0.019488f, 0.000000f, -0.019830f, 0.000000f, 0.022669f, 0.000000f, -0.011066f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, 0.000000f, 0.000000f, -0.056105f, 0.000000f, 0.111010f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.018999f, 0.000000f, 0.020478f, // C
+0.276200f, 0.619758f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.106989f, 0.000000f, -0.163267f, -0.018501f, 0.000000f, 0.040168f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, // Ls
+0.276228f, -0.619768f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.106856f, 0.000000f, -0.163267f, 0.018501f, 0.000000f, -0.040194f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, // Rs
+0.276222f, 0.309884f, 0.000000f, -0.536733f, -0.141395f, 0.000000f, -0.106873f, 0.000000f, 0.081634f, 0.018501f, 0.000000f, 0.020094f, 0.000000f, -0.034809f, 0.000000f, 0.000000f, // Lb
+0.276196f, -0.309893f, 0.000000f, -0.536723f, 0.141394f, 0.000000f, -0.107038f, 0.000000f, 0.081628f, -0.018500f, 0.000000f, -0.020079f, 0.000000f, -0.034779f, 0.000000f, 0.000000f, // Rb
+};
+
+// Decoder matrix for 7dot0, ambisonic level 3
+static constexpr float decoderMatrix_7dot0_3_hf[7*16] = {
+0.343479f, 0.452315f, 0.000000f, 0.525962f, 0.147981f, 0.000000f, -0.083290f, 0.000000f, 0.023855f, 0.009908f, 0.000000f, 0.010095f, 0.000000f, 0.011532f, 0.000000f, -0.005626f, // L
+0.343450f, -0.452323f, 0.000000f, 0.525952f, -0.147980f, 0.000000f, -0.083406f, 0.000000f, 0.023849f, -0.009907f, 0.000000f, -0.010081f, 0.000000f, 0.011524f, 0.000000f, -0.005626f, // R
+0.226221f, 0.000000f, 0.000000f, 0.473046f, 0.000000f, 0.000000f, -0.057310f, 0.000000f, 0.113395f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.009658f, 0.000000f, 0.010410f, // C
+0.460752f, 0.890303f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.109288f, 0.000000f, -0.166775f, -0.009405f, 0.000000f, 0.020420f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, // Ls
+0.460799f, -0.890318f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.109152f, 0.000000f, -0.166775f, 0.009405f, 0.000000f, -0.020434f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, // Rs
+0.460790f, 0.445159f, 0.000000f, -0.771035f, -0.144433f, 0.000000f, -0.109170f, 0.000000f, 0.083387f, 0.009406f, 0.000000f, 0.010215f, 0.000000f, -0.017696f, 0.000000f, 0.000000f, // Lb
+0.460745f, -0.445171f, 0.000000f, -0.771020f, 0.144432f, 0.000000f, -0.109338f, 0.000000f, 0.083382f, -0.009405f, 0.000000f, -0.010207f, 0.000000f, -0.017681f, 0.000000f, 0.000000f, // Rb
+};
+
+// Decoder matrix for 7dot1, ambisonic level 1
+static constexpr float decoderMatrix_7dot1_1_lf[8*4] = {
+0.205900f, 0.314866f, 0.000000f, 0.366133f, // L
+0.205883f, -0.314871f, 0.000000f, 0.366126f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, // C
+0.5f, 0.0f, 0.0f, 0.0f, // LFE
+0.276200f, 0.619758f, 0.000000f, 0.000000f, // Ls
+0.276228f, -0.619768f, 0.000000f, 0.000000f, // Rs
+0.276222f, 0.309884f, 0.000000f, -0.536733f, // Lb
+0.276196f, -0.309893f, 0.000000f, -0.536723f, // Rb
+};
+
+// Decoder matrix for 7dot1, ambisonic level 1
+static constexpr float decoderMatrix_7dot1_1_hf[8*4] = {
+0.291186f, 0.257087f, 0.000000f, 0.298946f, // L
+0.291162f, -0.257091f, 0.000000f, 0.298940f, // R
+0.191780f, 0.000000f, 0.000000f, 0.268870f, // C
+0.0f, 0.0f, 0.0f, 0.0f, // LFE
+0.390605f, 0.506030f, 0.000000f, 0.000000f, // Ls
+0.390645f, -0.506039f, 0.000000f, 0.000000f, // Rs
+0.390637f, 0.253019f, 0.000000f, -0.438240f, // Lb
+0.390600f, -0.253026f, 0.000000f, -0.438232f, // Rb
+};
+
+// Decoder matrix for 7dot1, ambisonic level 2
+static constexpr float decoderMatrix_7dot1_2_lf[8*9] = {
+0.205900f, 0.314866f, 0.000000f, 0.366133f, 0.144868f, 0.000000f, -0.081538f, 0.000000f, 0.023353f, // L
+0.205883f, -0.314871f, 0.000000f, 0.366126f, -0.144867f, 0.000000f, -0.081652f, 0.000000f, 0.023347f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, 0.000000f, 0.000000f, -0.056105f, 0.000000f, 0.111010f, // C
+0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // LFE
+0.276200f, 0.619758f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.106989f, 0.000000f, -0.163267f, // Ls
+0.276228f, -0.619768f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.106856f, 0.000000f, -0.163267f, // Rs
+0.276222f, 0.309884f, 0.000000f, -0.536733f, -0.141395f, 0.000000f, -0.106873f, 0.000000f, 0.081634f, // Lb
+0.276196f, -0.309893f, 0.000000f, -0.536723f, 0.141394f, 0.000000f, -0.107038f, 0.000000f, 0.081628f, // Rb
+};
+
+// Decoder matrix for 7dot1, ambisonic level 2
+static constexpr float decoderMatrix_7dot1_2_hf[8*9] = {
+0.325556f, 0.385630f, 0.000000f, 0.448419f, 0.091623f, 0.000000f, -0.051569f, 0.000000f, 0.014770f, // L
+0.325529f, -0.385637f, 0.000000f, 0.448410f, -0.091622f, 0.000000f, -0.051641f, 0.000000f, 0.014766f, // R
+0.214417f, 0.000000f, 0.000000f, 0.403305f, 0.000000f, 0.000000f, -0.035484f, 0.000000f, 0.070209f, // C
+0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // LFE
+0.436710f, 0.759045f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.067666f, 0.000000f, -0.103259f, // Ls
+0.436755f, -0.759058f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.067582f, 0.000000f, -0.103259f, // Rs
+0.436746f, 0.379529f, 0.000000f, -0.657361f, -0.089426f, 0.000000f, -0.067593f, 0.000000f, 0.051630f, // Lb
+0.436704f, -0.379539f, 0.000000f, -0.657348f, 0.089426f, 0.000000f, -0.067697f, 0.000000f, 0.051626f, // Rb
+};
+
+// Decoder matrix for 7dot1, ambisonic level 3
+static constexpr float decoderMatrix_7dot1_3_lf[8*16] = {
+0.205900f, 0.314866f, 0.000000f, 0.366133f, 0.144868f, 0.000000f, -0.081538f, 0.000000f, 0.023353f, 0.019489f, 0.000000f, 0.019857f, 0.000000f, 0.022683f, 0.000000f, -0.011066f, // L
+0.205883f, -0.314871f, 0.000000f, 0.366126f, -0.144867f, 0.000000f, -0.081652f, 0.000000f, 0.023347f, -0.019488f, 0.000000f, -0.019830f, 0.000000f, 0.022669f, 0.000000f, -0.011066f, // R
+0.135609f, 0.000000f, 0.000000f, 0.329297f, 0.000000f, 0.000000f, -0.056105f, 0.000000f, 0.111010f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.018999f, 0.000000f, 0.020478f, // C
+0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // LFE
+0.276200f, 0.619758f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.106989f, 0.000000f, -0.163267f, -0.018501f, 0.000000f, 0.040168f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, // Ls
+0.276228f, -0.619768f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.106856f, 0.000000f, -0.163267f, 0.018501f, 0.000000f, -0.040194f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, // Rs
+0.276222f, 0.309884f, 0.000000f, -0.536733f, -0.141395f, 0.000000f, -0.106873f, 0.000000f, 0.081634f, 0.018501f, 0.000000f, 0.020094f, 0.000000f, -0.034809f, 0.000000f, 0.000000f, // Lb
+0.276196f, -0.309893f, 0.000000f, -0.536723f, 0.141394f, 0.000000f, -0.107038f, 0.000000f, 0.081628f, -0.018500f, 0.000000f, -0.020079f, 0.000000f, -0.034779f, 0.000000f, 0.000000f, // Rb
+};
+
+// Decoder matrix for 7dot1, ambisonic level 3
+static constexpr float decoderMatrix_7dot1_3_hf[8*16] = {
+0.343479f, 0.452315f, 0.000000f, 0.525962f, 0.147981f, 0.000000f, -0.083290f, 0.000000f, 0.023855f, 0.009908f, 0.000000f, 0.010095f, 0.000000f, 0.011532f, 0.000000f, -0.005626f, // L
+0.343450f, -0.452323f, 0.000000f, 0.525952f, -0.147980f, 0.000000f, -0.083406f, 0.000000f, 0.023849f, -0.009907f, 0.000000f, -0.010081f, 0.000000f, 0.011524f, 0.000000f, -0.005626f, // R
+0.226221f, 0.000000f, 0.000000f, 0.473046f, 0.000000f, 0.000000f, -0.057310f, 0.000000f, 0.113395f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.009658f, 0.000000f, 0.010410f, // C
+0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // LFE
+0.460752f, 0.890303f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.109288f, 0.000000f, -0.166775f, -0.009405f, 0.000000f, 0.020420f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, // Ls
+0.460799f, -0.890318f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, -0.109152f, 0.000000f, -0.166775f, 0.009405f, 0.000000f, -0.020434f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, // Rs
+0.460790f, 0.445159f, 0.000000f, -0.771035f, -0.144433f, 0.000000f, -0.109170f, 0.000000f, 0.083387f, 0.009406f, 0.000000f, 0.010215f, 0.000000f, -0.017696f, 0.000000f, 0.000000f, // Lb
+0.460745f, -0.445171f, 0.000000f, -0.771020f, 0.144432f, 0.000000f, -0.109338f, 0.000000f, 0.083382f, -0.009405f, 0.000000f, -0.010207f, 0.000000f, -0.017681f, 0.000000f, 0.000000f, // Rb
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/spatialaudio/qaudioengine.cpp b/src/spatialaudio/qaudioengine.cpp
new file mode 100644
index 000000000..82228f72f
--- /dev/null
+++ b/src/spatialaudio/qaudioengine.cpp
@@ -0,0 +1,602 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include <qaudioengine_p.h>
+#include <qambientsound_p.h>
+#include <qspatialsound_p.h>
+#include <qambientsound.h>
+#include <qaudioroom_p.h>
+#include <qaudiolistener.h>
+#include <resonance_audio.h>
+#include <qambisonicdecoder_p.h>
+#include <qaudiodecoder.h>
+#include <qmediadevices.h>
+#include <qiodevice.h>
+#include <qaudiosink.h>
+#include <qdebug.h>
+#include <qelapsedtimer.h>
+
+#include <QFile>
+
+QT_BEGIN_NAMESPACE
+
+// We'd like to have short buffer times, so the sound adjusts itself to changes
+// quickly, but times below 100ms seem to give stuttering on macOS.
+// It might be possible to set this value lower on other OSes.
+const int bufferTimeMs = 100;
+
+// This class lives in the audioThread, but pulls data from QAudioEnginePrivate
+// which lives in the mainThread.
+class QAudioOutputStream : public QIODevice
+{
+ Q_OBJECT
+public:
+ explicit QAudioOutputStream(QAudioEnginePrivate *d)
+ : d(d)
+ {
+ open(QIODevice::ReadOnly);
+ }
+ ~QAudioOutputStream();
+
+ qint64 readData(char *data, qint64 len) override;
+
+ qint64 writeData(const char *, qint64) override;
+
+ qint64 size() const override { return 0; }
+ qint64 bytesAvailable() const override {
+ return std::numeric_limits<qint64>::max();
+ }
+ bool isSequential() const override {
+ return true;
+ }
+ bool atEnd() const override {
+ return false;
+ }
+ qint64 pos() const override {
+ return m_pos;
+ }
+
+ Q_INVOKABLE void startOutput() {
+ d->mutex.lock();
+ Q_ASSERT(!sink);
+ QAudioFormat format;
+ auto channelConfig = d->outputMode == QAudioEngine::Surround ?
+ d->device.channelConfiguration() : QAudioFormat::ChannelConfigStereo;
+ if (channelConfig != QAudioFormat::ChannelConfigUnknown)
+ format.setChannelConfig(channelConfig);
+ else
+ format.setChannelCount(d->device.preferredFormat().channelCount());
+ format.setSampleRate(d->sampleRate);
+ format.setSampleFormat(QAudioFormat::Int16);
+ ambisonicDecoder.reset(new QAmbisonicDecoder(QAmbisonicDecoder::HighQuality, format));
+ sink.reset(new QAudioSink(d->device, format));
+ const qsizetype bufferSize = format.bytesForDuration(bufferTimeMs * 1000);
+ sink->setBufferSize(bufferSize);
+ d->mutex.unlock();
+ // It is important to unlock the mutex before starting the sink, as the sink will
+ // call readData() in the audio thread, which will try to lock the mutex (again)
+ sink->start(this);
+ }
+
+ Q_INVOKABLE void stopOutput() {
+ sink->stop();
+ sink.reset();
+ ambisonicDecoder.reset();
+ }
+
+ Q_INVOKABLE void restartOutput() {
+ stopOutput();
+ startOutput();
+ }
+
+ void setPaused(bool paused) {
+ if (paused)
+ sink->suspend();
+ else
+ sink->resume();
+ }
+
+private:
+ qint64 m_pos = 0;
+ QAudioEnginePrivate *d = nullptr;
+ std::unique_ptr<QAudioSink> sink;
+ std::unique_ptr<QAmbisonicDecoder> ambisonicDecoder;
+};
+
+
+QAudioOutputStream::~QAudioOutputStream()
+{
+}
+
+qint64 QAudioOutputStream::writeData(const char *, qint64)
+{
+ return 0;
+}
+
+qint64 QAudioOutputStream::readData(char *data, qint64 len)
+{
+ if (d->paused.loadRelaxed())
+ return 0;
+
+ QMutexLocker l(&d->mutex);
+ d->updateRooms();
+
+ int nChannels = ambisonicDecoder ? ambisonicDecoder->nOutputChannels() : 2;
+ if (len < nChannels*int(sizeof(float))*QAudioEnginePrivate::bufferSize)
+ return 0;
+
+ short *fd = (short *)data;
+ qint64 frames = len / nChannels / sizeof(short);
+ bool ok = true;
+ while (frames >= qint64(QAudioEnginePrivate::bufferSize)) {
+ // Fill input buffers
+ for (auto *source : std::as_const(d->sources)) {
+ auto *sp = QSpatialSoundPrivate::get(source);
+ if (!sp)
+ continue;
+ float buf[QAudioEnginePrivate::bufferSize];
+ sp->getBuffer(buf, QAudioEnginePrivate::bufferSize, 1);
+ d->resonanceAudio->api->SetInterleavedBuffer(sp->sourceId, buf, 1, QAudioEnginePrivate::bufferSize);
+ }
+ for (auto *source : std::as_const(d->stereoSources)) {
+ auto *sp = QAmbientSoundPrivate::get(source);
+ if (!sp)
+ continue;
+ float buf[2*QAudioEnginePrivate::bufferSize];
+ sp->getBuffer(buf, QAudioEnginePrivate::bufferSize, 2);
+ d->resonanceAudio->api->SetInterleavedBuffer(sp->sourceId, buf, 2, QAudioEnginePrivate::bufferSize);
+ }
+
+ if (ambisonicDecoder && d->outputMode == QAudioEngine::Surround) {
+ const float *channels[QAmbisonicDecoder::maxAmbisonicChannels];
+ const float *reverbBuffers[2];
+ int nSamples = d->resonanceAudio->getAmbisonicOutput(channels, reverbBuffers, ambisonicDecoder->nInputChannels());
+ Q_ASSERT(ambisonicDecoder->nOutputChannels() <= 8);
+ ambisonicDecoder->processBufferWithReverb(channels, reverbBuffers, fd, nSamples);
+ } else {
+ ok = d->resonanceAudio->api->FillInterleavedOutputBuffer(2, QAudioEnginePrivate::bufferSize, fd);
+ if (!ok) {
+ // If we get here, it means that resonanceAudio did not actually fill the buffer.
+ // Sometimes this is expected, for example if resonanceAudio does not have any sources.
+ // In this case we just fill the buffer with silence.
+ if (d->sources.isEmpty() && d->stereoSources.isEmpty()) {
+ memset(fd, 0, nChannels * QAudioEnginePrivate::bufferSize * sizeof(short));
+ } else {
+ // If we get here, it means that something unexpected happened, so bail.
+ qWarning() << " Reading failed!";
+ break;
+ }
+ }
+ }
+ fd += nChannels*QAudioEnginePrivate::bufferSize;
+ frames -= QAudioEnginePrivate::bufferSize;
+ }
+ const int bytesProcessed = ((char *)fd - data);
+ m_pos += bytesProcessed;
+ return bytesProcessed;
+}
+
+
+QAudioEnginePrivate::QAudioEnginePrivate()
+{
+ device = QMediaDevices::defaultAudioOutput();
+}
+
+QAudioEnginePrivate::~QAudioEnginePrivate()
+{
+ delete resonanceAudio;
+}
+
+void QAudioEnginePrivate::addSpatialSound(QSpatialSound *sound)
+{
+ QMutexLocker l(&mutex);
+ QAmbientSoundPrivate *sd = QAmbientSoundPrivate::get(sound);
+
+ sd->sourceId = resonanceAudio->api->CreateSoundObjectSource(vraudio::kBinauralHighQuality);
+ sources.append(sound);
+}
+
+void QAudioEnginePrivate::removeSpatialSound(QSpatialSound *sound)
+{
+ QMutexLocker l(&mutex);
+ QAmbientSoundPrivate *sd = QAmbientSoundPrivate::get(sound);
+
+ resonanceAudio->api->DestroySource(sd->sourceId);
+ sd->sourceId = vraudio::ResonanceAudioApi::kInvalidSourceId;
+ sources.removeOne(sound);
+}
+
+void QAudioEnginePrivate::addStereoSound(QAmbientSound *sound)
+{
+ QMutexLocker l(&mutex);
+ QAmbientSoundPrivate *sd = QAmbientSoundPrivate::get(sound);
+
+ sd->sourceId = resonanceAudio->api->CreateStereoSource(2);
+ stereoSources.append(sound);
+}
+
+void QAudioEnginePrivate::removeStereoSound(QAmbientSound *sound)
+{
+ QMutexLocker l(&mutex);
+ QAmbientSoundPrivate *sd = QAmbientSoundPrivate::get(sound);
+
+ resonanceAudio->api->DestroySource(sd->sourceId);
+ sd->sourceId = vraudio::ResonanceAudioApi::kInvalidSourceId;
+ stereoSources.removeOne(sound);
+}
+
+void QAudioEnginePrivate::addRoom(QAudioRoom *room)
+{
+ QMutexLocker l(&mutex);
+ rooms.append(room);
+}
+
+void QAudioEnginePrivate::removeRoom(QAudioRoom *room)
+{
+ QMutexLocker l(&mutex);
+ rooms.removeOne(room);
+}
+
+// This method is called from the audio thread
+void QAudioEnginePrivate::updateRooms()
+{
+ if (!roomEffectsEnabled)
+ return;
+
+ bool needUpdate = listenerPositionDirty;
+ listenerPositionDirty = false;
+
+ bool roomDirty = false;
+ for (const auto &room : rooms) {
+ auto *rd = QAudioRoomPrivate::get(room);
+ if (rd->dirty) {
+ roomDirty = true;
+ rd->update();
+ needUpdate = true;
+ }
+ }
+
+ if (!needUpdate)
+ return;
+
+ QVector3D listenerPos = listenerPosition();
+ float roomVolume = float(qInf());
+ QAudioRoom *room = nullptr;
+ // Find the smallest room that contains the listener and apply its room effects
+ for (auto *r : std::as_const(rooms)) {
+ QVector3D dim2 = r->dimensions()/2.;
+ float vol = dim2.x()*dim2.y()*dim2.z();
+ if (vol > roomVolume)
+ continue;
+ QVector3D dist = r->position() - listenerPos;
+ // transform into room coordinates
+ dist = r->rotation().rotatedVector(dist);
+ if (qAbs(dist.x()) <= dim2.x() &&
+ qAbs(dist.y()) <= dim2.y() &&
+ qAbs(dist.z()) <= dim2.z()) {
+ room = r;
+ roomVolume = vol;
+ }
+ }
+ if (room != currentRoom)
+ roomDirty = true;
+ const bool previousRoom = currentRoom;
+ currentRoom = room;
+
+ if (!roomDirty)
+ return;
+
+ // apply room to engine
+ if (!currentRoom) {
+ resonanceAudio->api->EnableRoomEffects(false);
+ return;
+ }
+ if (!previousRoom)
+ resonanceAudio->api->EnableRoomEffects(true);
+
+ QAudioRoomPrivate *rp = QAudioRoomPrivate::get(room);
+ resonanceAudio->api->SetReflectionProperties(rp->reflections);
+ resonanceAudio->api->SetReverbProperties(rp->reverb);
+
+ // update room effects for all sound sources
+ for (auto *s : std::as_const(sources)) {
+ auto *sp = QSpatialSoundPrivate::get(s);
+ if (!sp)
+ continue;
+ sp->updateRoomEffects();
+ }
+}
+
+QVector3D QAudioEnginePrivate::listenerPosition() const
+{
+ return listener ? listener->position() : QVector3D();
+}
+
+
+/*!
+ \class QAudioEngine
+ \inmodule QtSpatialAudio
+ \ingroup spatialaudio
+ \ingroup multimedia_audio
+
+ \brief QAudioEngine manages a three dimensional sound field.
+
+ You can use an instance of QAudioEngine to manage a sound field in
+ three dimensions. A sound field is defined by several QSpatialSound
+ objects that define a sound at a specified location in 3D space. You can also
+ add stereo overlays using QAmbientSound.
+
+ You can use QAudioListener to define the position of the person listening
+ to the sound field relative to the sound sources. Sound sources will be less audible
+ if the listener is further away from source. They will also get mapped to the corresponding
+ loudspeakers depending on the direction between listener and source.
+
+ QAudioEngine offers two output modes. The first mode renders the sound field to a set of
+ speakers, either a stereo speaker pair or a surround configuration. The second mode provides
+ an immersive 3D sound experience when using headphones.
+
+ Perception of sound localization is driven mainly by two factors. The first factor is timing
+ differences of the sound waves between left and right ear. The second factor comes from various
+ ways how sounds coming from different direcations create different types of reflections from our
+ ears and heads. See https://en.wikipedia.org/wiki/Sound_localization for more details.
+
+ The spatial audio engine emulates those timing differences and reflections through
+ Head related transfer functions (HRTF, see
+ https://en.wikipedia.org/wiki/Head-related_transfer_function). The functions used emulates those
+ effects for an average persons ears and head. It provides a good and immersive 3D sound localization
+ experience for most persons when using headphones.
+
+ The engine is rather versatile allowing you to define room properties and reverb settings to emulate
+ different types of rooms.
+
+ Sound sources can also be occluded dampening the sound coming from those sources.
+
+ The audio engine uses a coordinate system that is in centimeters by default. The axes are aligned with the
+ typical coordinate system used in 3D. Positive x points to the right, positive y points up and positive z points
+ backwards.
+
+*/
+
+/*!
+ \fn QAudioEngine::QAudioEngine()
+ \fn QAudioEngine::QAudioEngine(QObject *parent)
+ \fn QAudioEngine::QAudioEngine(int sampleRate, QObject *parent = nullptr)
+
+ Constructs a spatial audio engine with \a parent, if any.
+
+ The engine will operate with a sample rate given by \a sampleRate. The
+ default sample rate, if none is provided, is 44100 (44.1kHz).
+
+ Sound content that is not provided at that sample rate will automatically
+ get resampled to \a sampleRate when being processed by the engine. The
+ default sample rate is fine in most cases, but you can define a different
+ rate if most of your sound files are sampled with a different rate, and
+ avoid some CPU overhead for resampling.
+ */
+QAudioEngine::QAudioEngine(int sampleRate, QObject *parent)
+ : QObject(parent)
+ , d(new QAudioEnginePrivate)
+{
+ d->sampleRate = sampleRate;
+ d->resonanceAudio = new vraudio::ResonanceAudio(2, QAudioEnginePrivate::bufferSize, d->sampleRate);
+}
+
+/*!
+ Destroys the spatial audio engine.
+ */
+QAudioEngine::~QAudioEngine()
+{
+ stop();
+ delete d;
+}
+
+/*! \enum QAudioEngine::OutputMode
+ \value Surround Map the sounds to the loudspeaker configuration of the output device.
+ This is normally a stereo or surround speaker setup.
+ \value Stereo Map the sounds to the stereo loudspeaker configuration of the output device.
+ This will ignore any additional speakers and only use the left and right channels
+ to create a stero rendering of the sound field.
+ \value Headphone Use Headphone spatialization to create a 3D audio effect when listening
+ to the sound field through headphones
+*/
+
+/*!
+ \property QAudioEngine::outputMode
+
+ Sets or retrieves the current output mode of the engine.
+
+ \sa QAudioEngine::OutputMode
+ */
+void QAudioEngine::setOutputMode(OutputMode mode)
+{
+ if (d->outputMode == mode)
+ return;
+ d->outputMode = mode;
+ if (d->resonanceAudio->api)
+ d->resonanceAudio->api->SetStereoSpeakerMode(mode != Headphone);
+
+ QMetaObject::invokeMethod(d->outputStream.get(), "restartOutput", Qt::BlockingQueuedConnection);
+
+ emit outputModeChanged();
+}
+
+QAudioEngine::OutputMode QAudioEngine::outputMode() const
+{
+ return d->outputMode;
+}
+
+/*!
+ Returns the sample rate the engine has been configured with.
+ */
+int QAudioEngine::sampleRate() const
+{
+ return d->sampleRate;
+}
+
+/*!
+ \property QAudioEngine::outputDevice
+
+ Sets or returns the device that is being used for playing the sound field.
+ */
+void QAudioEngine::setOutputDevice(const QAudioDevice &device)
+{
+ if (d->device == device)
+ return;
+ if (d->resonanceAudio->api) {
+ qWarning() << "Changing device on a running engine not implemented";
+ return;
+ }
+ d->device = device;
+ emit outputDeviceChanged();
+}
+
+QAudioDevice QAudioEngine::outputDevice() const
+{
+ return d->device;
+}
+
+/*!
+ \property QAudioEngine::masterVolume
+
+ Sets or returns volume being used to render the sound field.
+ */
+void QAudioEngine::setMasterVolume(float volume)
+{
+ if (d->masterVolume == volume)
+ return;
+ d->masterVolume = volume;
+ d->resonanceAudio->api->SetMasterVolume(volume);
+ emit masterVolumeChanged();
+}
+
+float QAudioEngine::masterVolume() const
+{
+ return d->masterVolume;
+}
+
+/*!
+ Starts the engine.
+ */
+void QAudioEngine::start()
+{
+ if (d->outputStream)
+ // already started
+ return;
+
+ d->resonanceAudio->api->SetStereoSpeakerMode(d->outputMode != Headphone);
+ d->resonanceAudio->api->SetMasterVolume(d->masterVolume);
+
+ d->outputStream.reset(new QAudioOutputStream(d));
+ d->outputStream->moveToThread(&d->audioThread);
+ d->audioThread.start(QThread::TimeCriticalPriority);
+
+ QMetaObject::invokeMethod(d->outputStream.get(), "startOutput");
+}
+
+/*!
+ Stops the engine.
+ */
+void QAudioEngine::stop()
+{
+ QMetaObject::invokeMethod(d->outputStream.get(), "stopOutput", Qt::BlockingQueuedConnection);
+ d->outputStream.reset();
+ d->audioThread.exit(0);
+ d->audioThread.wait();
+ delete d->resonanceAudio->api;
+ d->resonanceAudio->api = nullptr;
+}
+
+/*!
+ \property QAudioEngine::paused
+
+ Pauses the spatial audio engine.
+ */
+void QAudioEngine::setPaused(bool paused)
+{
+ bool old = d->paused.fetchAndStoreRelaxed(paused);
+ if (old != paused) {
+ if (d->outputStream)
+ d->outputStream->setPaused(paused);
+ emit pausedChanged();
+ }
+}
+
+bool QAudioEngine::paused() const
+{
+ return d->paused.loadRelaxed();
+}
+
+/*!
+ Enables room effects such as echos and reverb.
+
+ Enables room effects if \a enabled is true.
+ Room effects will only apply if you create one or more \l QAudioRoom objects
+ and the listener is inside at least one of the rooms. If the listener is inside
+ multiple rooms, the room with the smallest volume will be used.
+ */
+void QAudioEngine::setRoomEffectsEnabled(bool enabled)
+{
+ if (d->roomEffectsEnabled == enabled)
+ return;
+ d->roomEffectsEnabled = enabled;
+ d->resonanceAudio->roomEffectsEnabled = enabled;
+}
+
+/*!
+ Returns true if room effects are enabled.
+ */
+bool QAudioEngine::roomEffectsEnabled() const
+{
+ return d->roomEffectsEnabled;
+}
+
+/*!
+ \property QAudioEngine::distanceScale
+
+ Defines the scale of the coordinate system being used by the spatial audio engine.
+ By default, all units are in centimeters, in line with the default units being
+ used by Qt Quick 3D.
+
+ Set the distance scale to QAudioEngine::DistanceScaleMeter to get units in meters.
+*/
+void QAudioEngine::setDistanceScale(float scale)
+{
+ // multiply with 100, to get the conversion to meters that resonance audio uses
+ scale /= 100.f;
+ if (scale <= 0.0f) {
+ qWarning() << "QAudioEngine: Invalid distance scale.";
+ return;
+ }
+ if (scale == d->distanceScale)
+ return;
+ d->distanceScale = scale;
+ emit distanceScaleChanged();
+}
+
+float QAudioEngine::distanceScale() const
+{
+ return d->distanceScale*100.f;
+}
+
+/*!
+ \fn void QAudioEngine::pause()
+
+ Pauses playback.
+*/
+/*!
+ \fn void QAudioEngine::resume()
+
+ Resumes playback.
+*/
+/*!
+ \variable QAudioEngine::DistanceScaleCentimeter
+ \internal
+*/
+/*!
+ \variable QAudioEngine::DistanceScaleMeter
+ \internal
+*/
+
+QT_END_NAMESPACE
+
+#include "moc_qaudioengine.cpp"
+#include "qaudioengine.moc"
diff --git a/src/spatialaudio/qaudioengine.h b/src/spatialaudio/qaudioengine.h
new file mode 100644
index 000000000..13de2638a
--- /dev/null
+++ b/src/spatialaudio/qaudioengine.h
@@ -0,0 +1,80 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+
+#ifndef QAUDIOENGINE_H
+#define QAUDIOENGINE_H
+
+#include <QtSpatialAudio/qtspatialaudioglobal.h>
+#include <QtCore/qobject.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioEnginePrivate;
+class QAudioDevice;
+
+class Q_SPATIALAUDIO_EXPORT QAudioEngine : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(OutputMode outputMode READ outputMode WRITE setOutputMode NOTIFY outputModeChanged)
+ Q_PROPERTY(QAudioDevice outputDevice READ outputDevice WRITE setOutputDevice NOTIFY outputDeviceChanged)
+ Q_PROPERTY(float masterVolume READ masterVolume WRITE setMasterVolume NOTIFY masterVolumeChanged)
+ Q_PROPERTY(bool paused READ paused WRITE setPaused NOTIFY pausedChanged)
+ Q_PROPERTY(float distanceScale READ distanceScale WRITE setDistanceScale NOTIFY distanceScaleChanged)
+public:
+ QAudioEngine() : QAudioEngine(nullptr) {};
+ explicit QAudioEngine(QObject *parent) : QAudioEngine(44100, parent) {}
+ explicit QAudioEngine(int sampleRate, QObject *parent = nullptr);
+ ~QAudioEngine();
+
+ enum OutputMode {
+ Surround,
+ Stereo,
+ Headphone
+ };
+ Q_ENUM(OutputMode)
+
+ void setOutputMode(OutputMode mode);
+ OutputMode outputMode() const;
+
+ int sampleRate() const;
+
+ void setOutputDevice(const QAudioDevice &device);
+ QAudioDevice outputDevice() const;
+
+ void setMasterVolume(float volume);
+ float masterVolume() const;
+
+ void setPaused(bool paused);
+ bool paused() const;
+
+ void setRoomEffectsEnabled(bool enabled);
+ bool roomEffectsEnabled() const;
+
+ static constexpr float DistanceScaleCentimeter = 1.f;
+ static constexpr float DistanceScaleMeter = 100.f;
+
+ void setDistanceScale(float scale);
+ float distanceScale() const;
+
+Q_SIGNALS:
+ void outputModeChanged();
+ void outputDeviceChanged();
+ void masterVolumeChanged();
+ void pausedChanged();
+ void distanceScaleChanged();
+
+public Q_SLOTS:
+ void start();
+ void stop();
+
+ void pause() { setPaused(true); }
+ void resume() { setPaused(false); }
+
+private:
+ friend class QAudioEnginePrivate;
+ QAudioEnginePrivate *d;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudio/qaudioengine_p.h b/src/spatialaudio/qaudioengine_p.h
new file mode 100644
index 000000000..59eaa4540
--- /dev/null
+++ b/src/spatialaudio/qaudioengine_p.h
@@ -0,0 +1,92 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+
+#ifndef QAUDIOENGINE_P_H
+#define QAUDIOENGINE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qtspatialaudioglobal_p.h>
+#include <qaudioengine.h>
+#include <qaudiodevice.h>
+#include <qaudiodecoder.h>
+#include <qthread.h>
+#include <qmutex.h>
+#include <qurl.h>
+#include <qaudiobuffer.h>
+#include <qvector3d.h>
+#include <qfile.h>
+
+namespace vraudio {
+class ResonanceAudio;
+}
+
+QT_BEGIN_NAMESPACE
+
+class QSpatialSound;
+class QAmbientSound;
+class QAudioSink;
+class QAudioOutputStream;
+class QAmbisonicDecoder;
+class QAudioDecoder;
+class QAudioRoom;
+class QAudioListener;
+
+class QAudioEnginePrivate
+{
+public:
+ static QAudioEnginePrivate *get(QAudioEngine *engine) { return engine ? engine->d : nullptr; }
+
+ static constexpr int bufferSize = 128;
+
+ QAudioEnginePrivate();
+ ~QAudioEnginePrivate();
+ vraudio::ResonanceAudio *resonanceAudio = nullptr;
+ int sampleRate = 44100;
+ float masterVolume = 1.;
+ QAudioEngine::OutputMode outputMode = QAudioEngine::Surround;
+ bool roomEffectsEnabled = true;
+
+ // Resonance Audio uses meters internally, while Qt Quick 3D and our API uses cm by default.
+ // To make things independent from the scale setting, we store all distances in meters internally
+ // and convert in the setters and getters.
+ float distanceScale = 0.01f;
+
+ QMutex mutex;
+ QAudioDevice device;
+ QAtomicInteger<bool> paused = false;
+
+ QThread audioThread;
+ std::unique_ptr<QAudioOutputStream> outputStream;
+
+ QAudioListener *listener = nullptr;
+ QList<QSpatialSound *> sources;
+ QList<QAmbientSound *> stereoSources;
+ QList<QAudioRoom *> rooms;
+ mutable bool listenerPositionDirty = true;
+ QAudioRoom *currentRoom = nullptr;
+
+ void addSpatialSound(QSpatialSound *sound);
+ void removeSpatialSound(QSpatialSound *sound);
+ void addStereoSound(QAmbientSound *sound);
+ void removeStereoSound(QAmbientSound *sound);
+
+ void addRoom(QAudioRoom *room);
+ void removeRoom(QAudioRoom *room);
+ void updateRooms();
+
+ QVector3D listenerPosition() const;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudio/qaudiolistener.cpp b/src/spatialaudio/qaudiolistener.cpp
new file mode 100644
index 000000000..ed4dbd58e
--- /dev/null
+++ b/src/spatialaudio/qaudiolistener.cpp
@@ -0,0 +1,134 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include "qaudiolistener.h"
+#include "qaudioengine_p.h"
+#include "resonance_audio.h"
+#include <qaudiosink.h>
+#include <qurl.h>
+#include <qdebug.h>
+#include <qaudiodecoder.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioListenerPrivate
+{
+public:
+ QAudioEngine *engine = nullptr;
+ QVector3D pos;
+ QQuaternion rotation;
+};
+
+/*!
+ \class QAudioListener
+ \inmodule QtSpatialAudio
+ \ingroup spatialaudio
+ \ingroup multimedia_audio
+
+ \brief Defines the position and orientation of the person listening to a sound field
+ defined by QAudioEngine.
+
+ A QAudioEngine can have exactly one listener that defines the position and orientation
+ of the person listening to the sound field.
+ */
+
+/*!
+ Creates a listener for the spatial audio engine for \a engine.
+ */
+QAudioListener::QAudioListener(QAudioEngine *engine)
+ : d(new QAudioListenerPrivate)
+{
+ setEngine(engine);
+}
+
+/*!
+ Destroys the listener.
+ */
+QAudioListener::~QAudioListener()
+{
+ // Unregister this listener from the engine
+ setEngine(nullptr);
+ delete d;
+}
+
+/*!
+ Sets the listener's position in 3D space to \a pos. Units are in centimeters
+ by default.
+
+ \sa QAudioEngine::distanceScale
+ */
+void QAudioListener::setPosition(QVector3D pos)
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (!ep)
+ return;
+ pos *= ep->distanceScale;
+ if (d->pos == pos)
+ return;
+
+ d->pos = pos;
+ if (ep && ep->resonanceAudio->api) {
+ ep->resonanceAudio->api->SetHeadPosition(pos.x(), pos.y(), pos.z());
+ ep->listenerPositionDirty = true;
+ }
+}
+
+/*!
+ Returns the current position of the listener.
+ */
+QVector3D QAudioListener::position() const
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (!ep)
+ return QVector3D();
+ return d->pos/ep->distanceScale;
+}
+
+/*!
+ Sets the listener's orientation in 3D space to \a q.
+ */
+void QAudioListener::setRotation(const QQuaternion &q)
+{
+ d->rotation = q;
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep && ep->resonanceAudio->api)
+ ep->resonanceAudio->api->SetHeadRotation(d->rotation.x(), d->rotation.y(), d->rotation.z(), d->rotation.scalar());
+}
+
+/*!
+ Returns the listener's orientation in 3D space.
+ */
+QQuaternion QAudioListener::rotation() const
+{
+ return d->rotation;
+}
+
+/*!
+ \internal
+ */
+void QAudioListener::setEngine(QAudioEngine *engine)
+{
+ if (d->engine) {
+ auto *ed = QAudioEnginePrivate::get(d->engine);
+ ed->listener = nullptr;
+ }
+ d->engine = engine;
+ if (d->engine) {
+ auto *ed = QAudioEnginePrivate::get(d->engine);
+ if (ed->listener) {
+ qWarning() << "Ignoring attempt to add a second listener to the spatial audio engine.";
+ d->engine = nullptr;
+ return;
+ }
+ ed->listener = this;
+ }
+}
+
+/*!
+ Returns the engine associated with this listener.
+ */
+QAudioEngine *QAudioListener::engine() const
+{
+ return d->engine;
+}
+
+QT_END_NAMESPACE
diff --git a/src/spatialaudio/qaudiolistener.h b/src/spatialaudio/qaudiolistener.h
new file mode 100644
index 000000000..daa088b6d
--- /dev/null
+++ b/src/spatialaudio/qaudiolistener.h
@@ -0,0 +1,37 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#ifndef QLISTENER_H
+#define QLISTENER_H
+
+#include <QtSpatialAudio/qtspatialaudioglobal.h>
+#include <QtCore/QObject>
+#include <QtMultimedia/qaudioformat.h>
+#include <QtGui/qvector3d.h>
+#include <QtGui/qquaternion.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioEngine;
+
+class QAudioListenerPrivate;
+class Q_SPATIALAUDIO_EXPORT QAudioListener : public QObject
+{
+public:
+ explicit QAudioListener(QAudioEngine *engine);
+ ~QAudioListener();
+
+ void setPosition(QVector3D pos);
+ QVector3D position() const;
+ void setRotation(const QQuaternion &q);
+ QQuaternion rotation() const;
+
+ QAudioEngine *engine() const;
+
+private:
+ void setEngine(QAudioEngine *engine);
+ QAudioListenerPrivate *d = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudio/qaudioroom.cpp b/src/spatialaudio/qaudioroom.cpp
new file mode 100644
index 000000000..3187abd10
--- /dev/null
+++ b/src/spatialaudio/qaudioroom.cpp
@@ -0,0 +1,399 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include <qaudioroom_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+inline QVector3D toVector(const float *f)
+{
+ return QVector3D(f[0], f[1], f[2]);
+}
+
+inline void toFloats(const QVector3D &v, float *f)
+{
+ f[0] = v.x();
+ f[1] = v.y();
+ f[2] = v.z();
+}
+
+inline QQuaternion toQuaternion(const float *f)
+{
+ // resonance audio puts the scalar component last
+ return QQuaternion(f[3], f[0], f[1], f[2]);
+}
+
+inline void toFloats(const QQuaternion &q, float *f)
+{
+ f[0] = q.x();
+ f[1] = q.y();
+ f[2] = q.z();
+ f[3] = q.scalar();
+}
+
+// Default values for occlusion and dampening of different wall materials.
+// These values are used as defaults if a wall is only defined by a material
+// and define how sound passes through the wall.
+// We define both occlusion and dampening constants to be able to tune the
+// sound. Dampening only reduces the level of the sound without affecting its
+// tone, while occlusion will dampen higher frequencies more than lower ones
+struct {
+ float occlusion;
+ float dampening;
+} occlusionAndDampening[] = {
+ { 0.f, 1.f }, // Transparent,
+ { 0.f, .1f }, // AcousticCeilingTiles,
+ { 2.f, .4f }, // BrickBare,
+ { 2.f, .4f }, // BrickPainted,
+ { 4.f, 1.f }, // ConcreteBlockCoarse,
+ { 4.f, 1.f }, // ConcreteBlockPainted,
+ { .7f, .7f }, // CurtainHeavy,
+ { .5f, .5f }, // FiberGlassInsulation,
+ { .2f, .3f }, // GlassThin,
+ { .5f, .2f }, // GlassThick,
+ { 7.f, 1.f }, // Grass,
+ { 4.f, 1.f }, // LinoleumOnConcrete,
+ { 4.f, 1.f }, // Marble,
+ { 0.f, .2f }, // Metal,
+ { 4.f, 1.f }, // ParquetOnConcrete,
+ { 2.f, .4f }, // PlasterRough,
+ { 2.f, .4f }, // PlasterSmooth,
+ { 1.5f, .2f }, // PlywoodPanel,
+ { 4.f, 1.f }, // PolishedConcreteOrTile,
+ { 4.f, 1.f }, // Sheetrock,
+ { 4.f, 1.f }, // WaterOrIceSurface,
+ { 1.f, .3f }, // WoodCeiling,
+ { 1.f, .3f }, // WoodPanel,
+ { 0.f, .0f }, // UniformMaterial,
+};
+
+}
+
+// make sure the wall definitions agree with resonance audio
+
+static_assert(QAudioRoom::LeftWall == 0);
+static_assert(QAudioRoom::RightWall == 1);
+static_assert(QAudioRoom::Floor == 2);
+static_assert(QAudioRoom::Ceiling == 3);
+static_assert(QAudioRoom::FrontWall == 4);
+static_assert(QAudioRoom::BackWall == 5);
+
+float QAudioRoomPrivate::wallOcclusion(QAudioRoom::Wall wall) const
+{
+ return m_wallOcclusion[wall] < 0 ? occlusionAndDampening[roomProperties.material_names[wall]].occlusion : m_wallOcclusion[wall];
+}
+
+float QAudioRoomPrivate::wallDampening(QAudioRoom::Wall wall) const
+{
+ return m_wallDampening[wall] < 0 ? occlusionAndDampening[roomProperties.material_names[wall]].dampening : m_wallDampening[wall];
+}
+
+void QAudioRoomPrivate::update()
+{
+ if (!dirty)
+ return;
+ reflections = vraudio::ComputeReflectionProperties(roomProperties);
+ reverb = vraudio::ComputeReverbProperties(roomProperties);
+ dirty = false;
+}
+
+
+/*!
+ \class QAudioRoom
+ \inmodule QtSpatialAudio
+ \ingroup spatialaudio
+ \ingroup multimedia_audio
+
+ Defines a room for the spatial audio engine.
+
+ If the listener is inside a room, first order sound reflections and reverb
+ matching the rooms properties will get applied to the sound field.
+
+ A room is always square and defined by its center position, its orientation and dimensions.
+ Each of the 6 walls of the room can be made of different materials that will contribute
+ to the computed reflections and reverb that the listener will experience while being inside
+ the room.
+
+ If multiple rooms cover the same position, the engine will use the room with the smallest
+ volume.
+ */
+
+/*!
+ Constructs a QAudioRoom for \a engine.
+ */
+QAudioRoom::QAudioRoom(QAudioEngine *engine)
+ : d(new QAudioRoomPrivate)
+{
+ Q_ASSERT(engine);
+ d->engine = engine;
+ auto *ep = QAudioEnginePrivate::get(engine);
+ ep->addRoom(this);
+}
+
+/*!
+ Destroys the room.
+ */
+QAudioRoom::~QAudioRoom()
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep)
+ ep->removeRoom(this);
+ delete d;
+}
+
+/*!
+ \enum QAudioRoom::Material
+
+ Defines different materials that can be applied to the different walls of the room.
+
+ \value Transparent The side of the room is open and won't contribute to reflections or reverb.
+ \value AcousticCeilingTiles Acoustic tiles that suppress most reflections and reverb.
+ \value BrickBare Bare brick wall.
+ \value BrickPainted Painted brick wall.
+ \value ConcreteBlockCoarse Raw concrete wall
+ \value ConcreteBlockPainted Painted concrete wall
+ \value CurtainHeavy Heavy curtain. Will mostly reflect low frequencies
+ \value FiberGlassInsulation Fiber glass insulation. Only reflects very low frequencies
+ \value GlassThin Thin glass wall
+ \value GlassThick Thick glass wall
+ \value Grass Grass
+ \value LinoleumOnConcrete Linoleum floor
+ \value Marble Marble floor
+ \value Metal Metal
+ \value ParquetOnConcrete Parquet wooden floor on concrete
+ \value PlasterRough Rough plaster
+ \value PlasterSmooth Smooth plaster
+ \value PlywoodPanel Plywodden panel
+ \value PolishedConcreteOrTile Polished concrete or tiles
+ \value Sheetrock Rock
+ \value WaterOrIceSurface Water or ice
+ \value WoodCeiling Wooden ceiling
+ \value WoodPanel Wooden panel
+ \value UniformMaterial Artificial material giving uniform reflections on all frequencies
+*/
+
+/*!
+ \enum QAudioRoom::Wall
+
+ An enum defining the 6 walls of the room
+
+ \value LeftWall Left wall (negative x)
+ \value RightWall Right wall (positive x)
+ \value Floor Bottom wall (negative y)
+ \value Ceiling Top wall (positive y)
+ \value FrontWall Front wall (negative z)
+ \value BackWall Back wall (positive z)
+*/
+
+
+/*!
+ \property QAudioRoom::position
+
+ Defines the position of the center of the room in 3D space. Units are in centimeters
+ by default.
+
+ \sa dimensions, QAudioEngine::distanceScale
+ */
+void QAudioRoom::setPosition(QVector3D pos)
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ pos *= ep->distanceScale;
+ if (toVector(d->roomProperties.position) == pos)
+ return;
+ toFloats(pos, d->roomProperties.position);
+ d->dirty = true;
+ emit positionChanged();
+}
+
+QVector3D QAudioRoom::position() const
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ auto pos = toVector(d->roomProperties.position);
+ pos /= ep->distanceScale;
+ return pos;
+}
+
+/*!
+ \property QAudioRoom::dimensions
+
+ Defines the dimensions of the room in 3D space. Units are in centimeters
+ by default.
+
+ \sa position, QAudioEngine::distanceScale
+ */
+void QAudioRoom::setDimensions(QVector3D dim)
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ dim *= ep->distanceScale;
+ if (toVector(d->roomProperties.dimensions) == dim)
+ return;
+ toFloats(dim, d->roomProperties.dimensions);
+ d->dirty = true;
+ emit dimensionsChanged();
+}
+
+QVector3D QAudioRoom::dimensions() const
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ auto dim = toVector(d->roomProperties.dimensions);
+ dim /= ep->distanceScale;
+ return dim;
+}
+
+/*!
+ \property QAudioRoom::rotation
+
+ Defines the orientation of the room in 3D space.
+ */
+void QAudioRoom::setRotation(const QQuaternion &q)
+{
+ if (toQuaternion(d->roomProperties.rotation) == q)
+ return;
+ toFloats(q, d->roomProperties.rotation);
+ d->dirty = true;
+ emit rotationChanged();
+}
+
+QQuaternion QAudioRoom::rotation() const
+{
+ return toQuaternion(d->roomProperties.rotation);
+}
+
+/*!
+ \fn void QAudioRoom::wallsChanged()
+
+ Signals when the wall material changes.
+*/
+/*!
+ Sets \a wall to \a material.
+
+ Different wall materials have different reflection and reverb properties
+ that influence the sound of the room.
+
+ \sa wallMaterial(), Material, QAudioRoom::Wall
+ */
+void QAudioRoom::setWallMaterial(Wall wall, Material material)
+{
+ static_assert(vraudio::kUniform == int(UniformMaterial));
+ static_assert(vraudio::kTransparent == int(Transparent));
+
+ if (d->roomProperties.material_names[int(wall)] == int(material))
+ return;
+ d->roomProperties.material_names[int(wall)] = vraudio::MaterialName(int(material));
+ d->dirty = true;
+ emit wallsChanged();
+}
+
+/*!
+ returns the material being used for \a wall.
+
+ \sa setWallMaterial(), Material, QAudioRoom::Wall
+ */
+QAudioRoom::Material QAudioRoom::wallMaterial(Wall wall) const
+{
+ return Material(d->roomProperties.material_names[int(wall)]);
+}
+
+/*!
+ \property QAudioRoom::reflectionGain
+
+ A gain factor for reflections generated in this room. A value
+ from 0 to 1 will dampen reflections, while a value larger than 1
+ will apply a gain to reflections, making them louder.
+
+ The default is 1, a factor of 0 disables reflections. Negative
+ values are mapped to 0.
+ */
+void QAudioRoom::setReflectionGain(float factor)
+{
+ if (factor < 0.)
+ factor = 0.;
+ if (d->roomProperties.reflection_scalar == factor)
+ return;
+ d->roomProperties.reflection_scalar = factor;
+ d->dirty = true;
+ emit reflectionGainChanged();
+}
+
+float QAudioRoom::reflectionGain() const
+{
+ return d->roomProperties.reflection_scalar;
+}
+
+/*!
+ \property QAudioRoom::reverbGain
+
+ A gain factor for reverb generated in this room. A value
+ from 0 to 1 will dampen reverb, while a value larger than 1
+ will apply a gain to the reverb, making it louder.
+
+ The default is 1, a factor of 0 disables reverb. Negative
+ values are mapped to 0.
+ */
+void QAudioRoom::setReverbGain(float factor)
+{
+ if (factor < 0)
+ factor = 0;
+ if (d->roomProperties.reverb_gain == factor)
+ return;
+ d->roomProperties.reverb_gain = factor;
+ d->dirty = true;
+ emit reverbGainChanged();
+}
+
+float QAudioRoom::reverbGain() const
+{
+ return d->roomProperties.reverb_gain;
+}
+
+/*!
+ \property QAudioRoom::reverbTime
+
+ A factor to be applies to all reverb timings generated for this room.
+ Larger values will lead to longer reverb timings, making the room sound
+ larger.
+
+ The default is 1. Negative values are mapped to 0.
+ */
+void QAudioRoom::setReverbTime(float factor)
+{
+ if (factor < 0)
+ factor = 0;
+ if (d->roomProperties.reverb_time == factor)
+ return;
+ d->roomProperties.reverb_time = factor;
+ d->dirty = true;
+ emit reverbTimeChanged();
+}
+
+float QAudioRoom::reverbTime() const
+{
+ return d->roomProperties.reverb_time;
+}
+
+/*!
+ \property QAudioRoom::reverbBrightness
+
+ A brightness factor to be applied to the generated reverb.
+ A positive value will increase reverb for higher frequencies and
+ dampen lower frequencies, a negative value does the reverse.
+
+ The default is 0.
+ */
+void QAudioRoom::setReverbBrightness(float factor)
+{
+ if (d->roomProperties.reverb_brightness == factor)
+ return;
+ d->roomProperties.reverb_brightness = factor;
+ d->dirty = true;
+ emit reverbBrightnessChanged();
+}
+
+float QAudioRoom::reverbBrightness() const
+{
+ return d->roomProperties.reverb_brightness;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qaudioroom.cpp"
diff --git a/src/spatialaudio/qaudioroom.h b/src/spatialaudio/qaudioroom.h
new file mode 100644
index 000000000..eb2b88cbc
--- /dev/null
+++ b/src/spatialaudio/qaudioroom.h
@@ -0,0 +1,107 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+
+#ifndef QAUDIOROOM_H
+#define QAUDIOROOM_H
+
+#include <QtSpatialAudio/qtspatialaudioglobal.h>
+#include <QtCore/qobject.h>
+#include <QtGui/qvector3d.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioEngine;
+class QAudioRoomPrivate;
+
+class Q_SPATIALAUDIO_EXPORT QAudioRoom : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
+ Q_PROPERTY(QVector3D dimensions READ dimensions WRITE setDimensions NOTIFY dimensionsChanged)
+ Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
+ Q_PROPERTY(float reflectionGain READ reflectionGain WRITE setReflectionGain NOTIFY reflectionGainChanged)
+ Q_PROPERTY(float reverbGain READ reverbGain WRITE setReverbGain NOTIFY reverbGainChanged)
+ Q_PROPERTY(float reverbTime READ reverbTime WRITE setReverbTime NOTIFY reverbTimeChanged)
+ Q_PROPERTY(float reverbBrightness READ reverbBrightness WRITE setReverbBrightness NOTIFY reverbBrightnessChanged)
+public:
+ explicit QAudioRoom(QAudioEngine *engine);
+ ~QAudioRoom();
+
+ enum Material {
+ Transparent,
+ AcousticCeilingTiles,
+ BrickBare,
+ BrickPainted,
+ ConcreteBlockCoarse,
+ ConcreteBlockPainted,
+ CurtainHeavy,
+ FiberGlassInsulation,
+ GlassThin,
+ GlassThick,
+ Grass,
+ LinoleumOnConcrete,
+ Marble,
+ Metal,
+ ParquetOnConcrete,
+ PlasterRough,
+ PlasterSmooth,
+ PlywoodPanel,
+ PolishedConcreteOrTile,
+ Sheetrock,
+ WaterOrIceSurface,
+ WoodCeiling,
+ WoodPanel,
+ UniformMaterial,
+ };
+
+ enum Wall {
+ LeftWall,
+ RightWall,
+ Floor,
+ Ceiling,
+ FrontWall,
+ BackWall
+ };
+
+ void setPosition(QVector3D pos);
+ QVector3D position() const;
+
+ void setDimensions(QVector3D dim);
+ QVector3D dimensions() const;
+
+ void setRotation(const QQuaternion &q);
+ QQuaternion rotation() const;
+
+ void setWallMaterial(Wall wall, Material material);
+ Material wallMaterial(Wall wall) const;
+
+ void setReflectionGain(float factor);
+ float reflectionGain() const;
+
+ void setReverbGain(float factor);
+ float reverbGain() const;
+
+ void setReverbTime(float factor);
+ float reverbTime() const;
+
+ void setReverbBrightness(float factor);
+ float reverbBrightness() const;
+
+Q_SIGNALS:
+ void positionChanged();
+ void dimensionsChanged();
+ void rotationChanged();
+ void wallsChanged();
+ void reflectionGainChanged();
+ void reverbGainChanged();
+ void reverbTimeChanged();
+ void reverbBrightnessChanged();
+
+private:
+ friend class QAudioRoomPrivate;
+ QAudioRoomPrivate *d;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudio/qaudioroom_p.h b/src/spatialaudio/qaudioroom_p.h
new file mode 100644
index 000000000..b320dc9fc
--- /dev/null
+++ b/src/spatialaudio/qaudioroom_p.h
@@ -0,0 +1,50 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#ifndef QAUDIOROOM_P_H
+#define QAUDIOROOM_P_H
+
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qtspatialaudioglobal_p.h>
+#include <qaudioroom.h>
+#include <qaudioengine_p.h>
+#include <QtGui/qquaternion.h>
+
+#include <resonance_audio.h>
+#include "platforms/common/room_effects_utils.h"
+#include "platforms/common/room_properties.h"
+
+QT_BEGIN_NAMESPACE
+
+class QAudioRoomPrivate
+{
+public:
+ static QAudioRoomPrivate *get(const QAudioRoom *r) { return r->d; }
+
+ QAudioEngine *engine = nullptr;
+ vraudio::RoomProperties roomProperties;
+ bool dirty = true;
+
+ vraudio::ReverbProperties reverb;
+ vraudio::ReflectionProperties reflections;
+
+ float m_wallOcclusion[6] = { -1.f, -1.f, -1.f, -1.f, -1.f, -1.f };
+ float m_wallDampening[6] = { -1.f, -1.f, -1.f, -1.f, -1.f, -1.f };
+
+ float wallOcclusion(QAudioRoom::Wall wall) const;
+ float wallDampening(QAudioRoom::Wall wall) const;
+
+ void update();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudio/qspatialsound.cpp b/src/spatialaudio/qspatialsound.cpp
new file mode 100644
index 000000000..84512556c
--- /dev/null
+++ b/src/spatialaudio/qspatialsound.cpp
@@ -0,0 +1,595 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include "qaudioroom_p.h"
+#include "qspatialsound_p.h"
+#include "qaudiolistener.h"
+#include "qaudioengine_p.h"
+#include "resonance_audio.h"
+#include <qaudiosink.h>
+#include <qurl.h>
+#include <qdebug.h>
+#include <qaudiodecoder.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QSpatialSound
+ \inmodule QtSpatialAudio
+ \ingroup spatialaudio
+ \ingroup multimedia_audio
+
+ \brief A sound object in 3D space.
+
+ QSpatialSound represents an audible object in 3D space. You can define
+ its position and orientation in space, set the sound it is playing and define a
+ volume for the object.
+
+ The object can have different attenuation behavior, emit sound mainly in one direction
+ or spherically, and behave as if occluded by some other object.
+ */
+
+/*!
+ Creates a spatial sound source for \a engine. The object can be placed in
+ 3D space and will be louder the closer to the listener it is.
+ */
+QSpatialSound::QSpatialSound(QAudioEngine *engine)
+ : d(new QSpatialSoundPrivate(this))
+{
+ setEngine(engine);
+}
+
+/*!
+ Destroys the sound source.
+ */
+QSpatialSound::~QSpatialSound()
+{
+ setEngine(nullptr);
+}
+
+/*!
+ \property QSpatialSound::position
+
+ Defines the position of the sound source in 3D space. Units are in centimeters
+ by default.
+
+ \sa QAudioEngine::distanceScale
+ */
+void QSpatialSound::setPosition(QVector3D pos)
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ pos *= ep->distanceScale;
+ d->pos = pos;
+ if (ep)
+ ep->resonanceAudio->api->SetSourcePosition(d->sourceId, pos.x(), pos.y(), pos.z());
+ emit positionChanged();
+}
+
+QVector3D QSpatialSound::position() const
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ return d->pos/ep->distanceScale;
+}
+
+/*!
+ \property QSpatialSound::rotation
+
+ Defines the orientation of the sound source in 3D space.
+ */
+void QSpatialSound::setRotation(const QQuaternion &q)
+{
+ d->rotation = q;
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep)
+ ep->resonanceAudio->api->SetSourceRotation(d->sourceId, q.x(), q.y(), q.z(), q.scalar());
+ emit rotationChanged();
+}
+
+QQuaternion QSpatialSound::rotation() const
+{
+ return d->rotation;
+}
+
+/*!
+ \property QSpatialSound::volume
+
+ Defines the volume of the sound.
+
+ Values between 0 and 1 will attenuate the sound, while values above 1
+ provide an additional gain boost.
+ */
+void QSpatialSound::setVolume(float volume)
+{
+ if (d->volume == volume)
+ return;
+ d->volume = volume;
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep)
+ ep->resonanceAudio->api->SetSourceVolume(d->sourceId, d->volume*d->wallDampening);
+ emit volumeChanged();
+}
+
+float QSpatialSound::volume() const
+{
+ return d->volume;
+}
+
+/*!
+ \enum QSpatialSound::DistanceModel
+
+ Defines how the volume of the sound scales with distance to the listener.
+
+ \value Logarithmic Volume decreases logarithmically with distance.
+ \value Linear Volume decreases linearly with distance.
+ \value ManualAttenuation Attenuation is defined manually using the
+ \l manualAttenuation property.
+*/
+
+/*!
+ \property QSpatialSound::distanceModel
+
+ Defines distance model for this sound source. The volume starts scaling down
+ from \l size to \l distanceCutoff. The volume is constant for distances smaller
+ than size and zero for distances larger than the cutoff distance.
+
+ \sa QSpatialSound::DistanceModel
+ */
+void QSpatialSound::setDistanceModel(DistanceModel model)
+{
+ if (d->distanceModel == model)
+ return;
+ d->distanceModel = model;
+
+ d->updateDistanceModel();
+ emit distanceModelChanged();
+}
+
+void QSpatialSoundPrivate::updateDistanceModel()
+{
+ if (!engine || sourceId < 0)
+ return;
+ auto *ep = QAudioEnginePrivate::get(engine);
+
+ vraudio::DistanceRolloffModel dm = vraudio::kLogarithmic;
+ switch (distanceModel) {
+ case QSpatialSound::DistanceModel::Linear:
+ dm = vraudio::kLinear;
+ break;
+ case QSpatialSound::DistanceModel::ManualAttenuation:
+ dm = vraudio::kNone;
+ break;
+ default:
+ break;
+ }
+
+ ep->resonanceAudio->api->SetSourceDistanceModel(sourceId, dm, size, distanceCutoff);
+}
+
+void QSpatialSoundPrivate::updateRoomEffects()
+{
+ if (!engine || sourceId < 0)
+ return;
+ auto *ep = QAudioEnginePrivate::get(engine);
+ if (!ep->currentRoom)
+ return;
+ auto *rp = QAudioRoomPrivate::get(ep->currentRoom);
+ if (!rp)
+ return;
+
+ QVector3D roomDim2 = ep->currentRoom->dimensions()/2.;
+ QVector3D roomPos = ep->currentRoom->position();
+ QQuaternion roomRot = ep->currentRoom->rotation();
+ QVector3D dist = pos - roomPos;
+ // transform into room coordinates
+ dist = roomRot.rotatedVector(dist);
+ if (qAbs(dist.x()) <= roomDim2.x() &&
+ qAbs(dist.y()) <= roomDim2.y() &&
+ qAbs(dist.z()) <= roomDim2.z()) {
+ // Source is inside room, apply
+ ep->resonanceAudio->api->SetSourceRoomEffectsGain(sourceId, 1);
+ wallDampening = 1.;
+ wallOcclusion = 0.;
+ } else {
+ // ### calculate room occlusion and dampening
+ // This is a bit of heuristics on top of the heuristic dampening/occlusion numbers for walls
+ //
+ // We basically cast a ray from the listener through the walls. If walls have different characteristics
+ // and we get close to a corner, we try to use some averaging to avoid abrupt changes
+ auto relativeListenerPos = ep->listenerPosition() - roomPos;
+ relativeListenerPos = roomRot.rotatedVector(relativeListenerPos);
+
+ auto direction = dist.normalized();
+ enum {
+ X, Y, Z
+ };
+ // Very rough approximation, use the size of the source plus twice the size of our head.
+ // One could probably improve upon this.
+ const float transitionDistance = size + 0.4;
+ QAudioRoom::Wall walls[3];
+ walls[X] = direction.x() > 0 ? QAudioRoom::RightWall : QAudioRoom::LeftWall;
+ walls[Y] = direction.y() > 0 ? QAudioRoom::FrontWall : QAudioRoom::BackWall;
+ walls[Z] = direction.z() > 0 ? QAudioRoom::Ceiling : QAudioRoom::Floor;
+ float factors[3] = { 0., 0., 0. };
+ bool foundWall = false;
+ if (direction.x() != 0) {
+ float sign = direction.x() > 0 ? 1.f : -1.f;
+ float dx = sign * roomDim2.x() - relativeListenerPos.x();
+ QVector3D intersection = relativeListenerPos + direction*dx/direction.x();
+ float dy = roomDim2.y() - qAbs(intersection.y());
+ float dz = roomDim2.z() - qAbs(intersection.z());
+ if (dy > 0 && dz > 0) {
+// qDebug() << "Hit with wall X" << walls[0] << dy << dz;
+ // Ray is hitting this wall
+ factors[Y] = qMax(0.f, 1.f/3.f - dy/transitionDistance);
+ factors[Z] = qMax(0.f, 1.f/3.f - dz/transitionDistance);
+ factors[X] = 1.f - factors[Y] - factors[Z];
+ foundWall = true;
+ }
+ }
+ if (!foundWall && direction.y() != 0) {
+ float sign = direction.y() > 0 ? 1.f : -1.f;
+ float dy = sign * roomDim2.y() - relativeListenerPos.y();
+ QVector3D intersection = relativeListenerPos + direction*dy/direction.y();
+ float dx = roomDim2.x() - qAbs(intersection.x());
+ float dz = roomDim2.z() - qAbs(intersection.z());
+ if (dx > 0 && dz > 0) {
+ // Ray is hitting this wall
+// qDebug() << "Hit with wall Y" << walls[1] << dx << dy;
+ factors[X] = qMax(0.f, 1.f/3.f - dx/transitionDistance);
+ factors[Z] = qMax(0.f, 1.f/3.f - dz/transitionDistance);
+ factors[Y] = 1.f - factors[X] - factors[Z];
+ foundWall = true;
+ }
+ }
+ if (!foundWall) {
+ Q_ASSERT(direction.z() != 0);
+ float sign = direction.z() > 0 ? 1.f : -1.f;
+ float dz = sign * roomDim2.z() - relativeListenerPos.z();
+ QVector3D intersection = relativeListenerPos + direction*dz/direction.z();
+ float dx = roomDim2.x() - qAbs(intersection.x());
+ float dy = roomDim2.y() - qAbs(intersection.y());
+ if (dx > 0 && dy > 0) {
+ // Ray is hitting this wall
+// qDebug() << "Hit with wall Z" << walls[2];
+ factors[X] = qMax(0.f, 1.f/3.f - dx/transitionDistance);
+ factors[Y] = qMax(0.f, 1.f/3.f - dy/transitionDistance);
+ factors[Z] = 1.f - factors[X] - factors[Y];
+ foundWall = true;
+ }
+ }
+ wallDampening = 0;
+ wallOcclusion = 0;
+ for (int i = 0; i < 3; ++i) {
+ wallDampening += factors[i]*rp->wallDampening(walls[i]);
+ wallOcclusion += factors[i]*rp->wallOcclusion(walls[i]);
+ }
+
+// qDebug() << "intersection with wall" << walls[0] << walls[1] << walls[2] << factors[0] << factors[1] << factors[2] << wallDampening << wallOcclusion;
+ ep->resonanceAudio->api->SetSourceRoomEffectsGain(sourceId, 0);
+ }
+ ep->resonanceAudio->api->SetSoundObjectOcclusionIntensity(sourceId, occlusionIntensity + wallOcclusion);
+ ep->resonanceAudio->api->SetSourceVolume(sourceId, volume*wallDampening);
+}
+
+QSpatialSound::DistanceModel QSpatialSound::distanceModel() const
+{
+ return d->distanceModel;
+}
+
+/*!
+ \property QSpatialSound::size
+
+ Defines the size of the sound source. If the listener is closer to the sound
+ object than the size, volume will stay constant. The size is also used to for
+ occlusion calculations, where large sources can be partially occluded by a wall.
+ */
+void QSpatialSound::setSize(float size)
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ size *= ep->distanceScale;
+ if (d->size == size)
+ return;
+ d->size = size;
+
+ d->updateDistanceModel();
+ emit sizeChanged();
+}
+
+float QSpatialSound::size() const
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ return d->size/ep->distanceScale;
+}
+
+/*!
+ \property QSpatialSound::distanceCutoff
+
+ Defines a distance beyond which sound coming from the source will cutoff.
+ If the listener is further away from the sound object than the cutoff
+ distance it won't be audible anymore.
+ */
+void QSpatialSound::setDistanceCutoff(float cutoff)
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ cutoff *= ep->distanceScale;
+ if (d->distanceCutoff == cutoff)
+ return;
+ d->distanceCutoff = cutoff;
+
+ d->updateDistanceModel();
+ emit distanceCutoffChanged();
+}
+
+float QSpatialSound::distanceCutoff() const
+{
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ return d->distanceCutoff/ep->distanceScale;
+}
+
+/*!
+ \property QSpatialSound::manualAttenuation
+
+ Defines a manual attenuation factor if \l distanceModel is set to
+ QSpatialSound::DistanceModel::ManualAttenuation.
+ */
+void QSpatialSound::setManualAttenuation(float attenuation)
+{
+ if (d->manualAttenuation == attenuation)
+ return;
+ d->manualAttenuation = attenuation;
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep)
+ ep->resonanceAudio->api->SetSourceDistanceAttenuation(d->sourceId, d->manualAttenuation);
+ emit manualAttenuationChanged();
+}
+
+float QSpatialSound::manualAttenuation() const
+{
+ return d->manualAttenuation;
+}
+
+/*!
+ \property QSpatialSound::occlusionIntensity
+
+ Defines how much the object is occluded. 0 implies the object is
+ not occluded at all, 1 implies the sound source is fully occluded by
+ another object.
+
+ A fully occluded object will still be audible, but especially higher
+ frequencies will be dampened. In addition, the object will still
+ participate in generating reverb and reflections in the room.
+
+ Values larger than 1 are possible to further dampen the direct
+ sound coming from the source.
+
+ The default is 0.
+ */
+void QSpatialSound::setOcclusionIntensity(float occlusion)
+{
+ if (d->occlusionIntensity == occlusion)
+ return;
+ d->occlusionIntensity = occlusion;
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep)
+ ep->resonanceAudio->api->SetSoundObjectOcclusionIntensity(d->sourceId, d->occlusionIntensity + d->wallOcclusion);
+ emit occlusionIntensityChanged();
+}
+
+float QSpatialSound::occlusionIntensity() const
+{
+ return d->occlusionIntensity;
+}
+
+/*!
+ \property QSpatialSound::directivity
+
+ Defines the directivity of the sound source. A value of 0 implies that the sound is
+ emitted equally in all directions, while a value of 1 implies that the source mainly
+ emits sound in the forward direction.
+
+ Valid values are between 0 and 1, the default is 0.
+ */
+void QSpatialSound::setDirectivity(float alpha)
+{
+ alpha = qBound(0., alpha, 1.);
+ if (alpha == d->directivity)
+ return;
+ d->directivity = alpha;
+
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep)
+ ep->resonanceAudio->api->SetSoundObjectDirectivity(d->sourceId, d->directivity, d->directivityOrder);
+
+ emit directivityChanged();
+}
+
+float QSpatialSound::directivity() const
+{
+ return d->directivity;
+}
+
+/*!
+ \property QSpatialSound::directivityOrder
+
+ Defines the order of the directivity of the sound source. A higher order
+ implies a sharper localization of the sound cone.
+
+ The minimum value and default for this property is 1.
+ */
+void QSpatialSound::setDirectivityOrder(float order)
+{
+ order = qMax(order, 1.);
+ if (order == d->directivityOrder)
+ return;
+ d->directivityOrder = order;
+
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep)
+ ep->resonanceAudio->api->SetSoundObjectDirectivity(d->sourceId, d->directivity, d->directivityOrder);
+
+ emit directivityChanged();
+}
+
+float QSpatialSound::directivityOrder() const
+{
+ return d->directivityOrder;
+}
+
+/*!
+ \property QSpatialSound::nearFieldGain
+
+ Defines the near field gain for the sound source. Valid values are between 0 and 1.
+ A near field gain of 1 will raise the volume of the sound signal by approx 20 dB for
+ distances very close to the listener.
+ */
+void QSpatialSound::setNearFieldGain(float gain)
+{
+ gain = qBound(0., gain, 1.);
+ if (gain == d->nearFieldGain)
+ return;
+ d->nearFieldGain = gain;
+
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep)
+ ep->resonanceAudio->api->SetSoundObjectNearFieldEffectGain(d->sourceId, d->nearFieldGain*9.f);
+
+ emit nearFieldGainChanged();
+
+}
+
+float QSpatialSound::nearFieldGain() const
+{
+ return d->nearFieldGain;
+}
+
+/*!
+ \property QSpatialSound::source
+
+ The source file for the sound to be played.
+ */
+void QSpatialSound::setSource(const QUrl &url)
+{
+ if (d->url == url)
+ return;
+ d->url = url;
+
+ d->load();
+ emit sourceChanged();
+}
+
+QUrl QSpatialSound::source() const
+{
+ return d->url;
+}
+
+/*!
+ \enum QSpatialSound::Loops
+
+ Lets you control the sound playback loop using the following values:
+
+ \value Infinite Playback infinitely
+ \value Once Playback once
+*/
+/*!
+ \property QSpatialSound::loops
+
+ Determines how many times the sound is played before the player stops.
+ Set to QSpatialSound::Infinite to play the current sound in a loop forever.
+
+ The default value is \c 1.
+ */
+int QSpatialSound::loops() const
+{
+ return d->m_loops.loadRelaxed();
+}
+
+void QSpatialSound::setLoops(int loops)
+{
+ int oldLoops = d->m_loops.fetchAndStoreRelaxed(loops);
+ if (oldLoops != loops)
+ emit loopsChanged();
+}
+
+/*!
+ \property QSpatialSound::autoPlay
+
+ Determines whether the sound should automatically start playing when a source
+ gets specified.
+
+ The default value is \c true.
+ */
+bool QSpatialSound::autoPlay() const
+{
+ return d->m_autoPlay.loadRelaxed();
+}
+
+void QSpatialSound::setAutoPlay(bool autoPlay)
+{
+ bool old = d->m_autoPlay.fetchAndStoreRelaxed(autoPlay);
+ if (old != autoPlay)
+ emit autoPlayChanged();
+}
+
+/*!
+ Starts playing back the sound. Does nothing if the sound is already playing.
+ */
+void QSpatialSound::play()
+{
+ d->play();
+}
+
+/*!
+ Pauses sound playback. Calling play() will continue playback.
+ */
+void QSpatialSound::pause()
+{
+ d->pause();
+}
+
+/*!
+ Stops sound playback and resets the current position and current loop count to 0.
+ Calling play() will start playback at the beginning of the sound file.
+ */
+void QSpatialSound::stop()
+{
+ d->stop();
+}
+
+/*!
+ \internal
+ */
+void QSpatialSound::setEngine(QAudioEngine *engine)
+{
+ if (d->engine == engine)
+ return;
+
+ // Remove self from old engine (if necessary)
+ auto *ep = QAudioEnginePrivate::get(d->engine);
+ if (ep)
+ ep->removeSpatialSound(this);
+
+ d->engine = engine;
+
+ // Add self to new engine if necessary
+ ep = QAudioEnginePrivate::get(d->engine);
+ if (ep) {
+ ep->addSpatialSound(this);
+ ep->resonanceAudio->api->SetSourcePosition(d->sourceId, d->pos.x(), d->pos.y(), d->pos.z());
+ ep->resonanceAudio->api->SetSourceRotation(d->sourceId, d->rotation.x(), d->rotation.y(), d->rotation.z(), d->rotation.scalar());
+ ep->resonanceAudio->api->SetSourceVolume(d->sourceId, d->volume);
+ ep->resonanceAudio->api->SetSoundObjectDirectivity(d->sourceId, d->directivity, d->directivityOrder);
+ ep->resonanceAudio->api->SetSoundObjectNearFieldEffectGain(d->sourceId, d->nearFieldGain);
+ d->updateDistanceModel();
+ }
+}
+
+/*!
+ Returns the engine associated with this listener.
+ */
+QAudioEngine *QSpatialSound::engine() const
+{
+ return d->engine;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qspatialsound.cpp"
diff --git a/src/spatialaudio/qspatialsound.h b/src/spatialaudio/qspatialsound.h
new file mode 100644
index 000000000..d171e0526
--- /dev/null
+++ b/src/spatialaudio/qspatialsound.h
@@ -0,0 +1,127 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#ifndef QSPATIALSOUND_H
+#define QSPATIALSOUND_H
+
+#include <QtSpatialAudio/qtspatialaudioglobal.h>
+#include <QtCore/QObject>
+#include <QtGui/qvector3d.h>
+#include <QtGui/qquaternion.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioEngine;
+class QAmbientSoundPrivate;
+
+class QSpatialSoundPrivate;
+class Q_SPATIALAUDIO_EXPORT QSpatialSound : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
+ Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
+ Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
+ Q_PROPERTY(DistanceModel distanceModel READ distanceModel WRITE setDistanceModel NOTIFY distanceModelChanged)
+ Q_PROPERTY(float size READ size WRITE setSize NOTIFY sizeChanged)
+ Q_PROPERTY(float distanceCutoff READ distanceCutoff WRITE setDistanceCutoff NOTIFY distanceCutoffChanged)
+ Q_PROPERTY(float manualAttenuation READ manualAttenuation WRITE setManualAttenuation NOTIFY manualAttenuationChanged)
+ Q_PROPERTY(float occlusionIntensity READ occlusionIntensity WRITE setOcclusionIntensity NOTIFY occlusionIntensityChanged)
+ Q_PROPERTY(float directivity READ directivity WRITE setDirectivity NOTIFY directivityChanged)
+ Q_PROPERTY(float directivityOrder READ directivityOrder WRITE setDirectivityOrder NOTIFY directivityOrderChanged)
+ Q_PROPERTY(float nearFieldGain READ nearFieldGain WRITE setNearFieldGain NOTIFY nearFieldGainChanged)
+ Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged)
+ Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged)
+
+public:
+ explicit QSpatialSound(QAudioEngine *engine);
+ ~QSpatialSound();
+
+ void setSource(const QUrl &url);
+ QUrl source() const;
+
+ enum Loops
+ {
+ Infinite = -1,
+ Once = 1
+ };
+ Q_ENUM(Loops)
+
+ int loops() const;
+ void setLoops(int loops);
+
+ bool autoPlay() const;
+ void setAutoPlay(bool autoPlay);
+
+ void setPosition(QVector3D pos);
+ QVector3D position() const;
+
+ void setRotation(const QQuaternion &q);
+ QQuaternion rotation() const;
+
+ void setVolume(float volume);
+ float volume() const;
+
+ enum class DistanceModel {
+ Logarithmic,
+ Linear,
+ ManualAttenuation
+ };
+ Q_ENUM(DistanceModel);
+
+ void setDistanceModel(DistanceModel model);
+ DistanceModel distanceModel() const;
+
+ void setSize(float size);
+ float size() const;
+
+ void setDistanceCutoff(float cutoff);
+ float distanceCutoff() const;
+
+ void setManualAttenuation(float attenuation);
+ float manualAttenuation() const;
+
+ void setOcclusionIntensity(float occlusion);
+ float occlusionIntensity() const;
+
+ void setDirectivity(float alpha);
+ float directivity() const;
+
+ void setDirectivityOrder(float alpha);
+ float directivityOrder() const;
+
+ void setNearFieldGain(float gain);
+ float nearFieldGain() const;
+
+ QAudioEngine *engine() const;
+
+Q_SIGNALS:
+ void sourceChanged();
+ void loopsChanged();
+ void autoPlayChanged();
+ void positionChanged();
+ void rotationChanged();
+ void volumeChanged();
+ void distanceModelChanged();
+ void sizeChanged();
+ void distanceCutoffChanged();
+ void manualAttenuationChanged();
+ void occlusionIntensityChanged();
+ void directivityChanged();
+ void directivityOrderChanged();
+ void nearFieldGainChanged();
+
+public Q_SLOTS:
+ void play();
+ void pause();
+ void stop();
+
+private:
+ void setEngine(QAudioEngine *engine);
+ friend class QAmbientSoundPrivate;
+ friend class QSpatialSoundPrivate;
+ QSpatialSoundPrivate *d = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudio/qspatialsound_p.h b/src/spatialaudio/qspatialsound_p.h
new file mode 100644
index 000000000..6e1b5d422
--- /dev/null
+++ b/src/spatialaudio/qspatialsound_p.h
@@ -0,0 +1,62 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+
+#ifndef QSPATIALAUDIOSOUNDSOURCE_P_H
+#define QSPATIALAUDIOSOUNDSOURCE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qspatialsound.h>
+#include <qambientsound_p.h>
+#include <qaudioengine_p.h>
+#include <qurl.h>
+#include <qvector3d.h>
+#include <qquaternion.h>
+#include <qaudiobuffer.h>
+#include <qaudiodevice.h>
+#include <qmutex.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioDecoder;
+class QAudioEnginePrivate;
+
+class QSpatialSoundPrivate : public QAmbientSoundPrivate
+{
+public:
+ QSpatialSoundPrivate(QObject *parent)
+ : QAmbientSoundPrivate(parent, 1)
+ {}
+
+ static QSpatialSoundPrivate *get(QSpatialSound *soundSource)
+ { return soundSource ? soundSource->d : nullptr; }
+
+ QVector3D pos;
+ QQuaternion rotation;
+ QSpatialSound::DistanceModel distanceModel = QSpatialSound::DistanceModel::Logarithmic;
+ float size = .1f;
+ float distanceCutoff = 50.f;
+ float manualAttenuation = 0.f;
+ float occlusionIntensity = 0.f;
+ float directivity = 0.f;
+ float directivityOrder = 1.f;
+ float nearFieldGain = 0.f;
+ float wallDampening = 1.f;
+ float wallOcclusion = 0.f;
+
+ void updateDistanceModel();
+ void updateRoomEffects();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudio/qtspatialaudioglobal.h b/src/spatialaudio/qtspatialaudioglobal.h
new file mode 100644
index 000000000..6e5b1ec0c
--- /dev/null
+++ b/src/spatialaudio/qtspatialaudioglobal.h
@@ -0,0 +1,10 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+
+#ifndef QTSPATIALAUDIOGLOBAL_H
+#define QTSPATIALAUDIOGLOBAL_H
+
+#include <QtMultimedia/qtmultimediaglobal.h>
+#include <QtSpatialAudio/qtspatialaudioexports.h>
+
+#endif // QTMULTIMEDIAGLOBAL_H
diff --git a/src/spatialaudio/qtspatialaudioglobal_p.h b/src/spatialaudio/qtspatialaudioglobal_p.h
new file mode 100644
index 000000000..a504da6cd
--- /dev/null
+++ b/src/spatialaudio/qtspatialaudioglobal_p.h
@@ -0,0 +1,21 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+
+#ifndef QTSPATIALAUDIOGLOBAL_P_H
+#define QTSPATIALAUDIOGLOBAL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtMultimedia/private/qtmultimediaglobal_p.h>
+#include <QtSpatialAudio/qtspatialaudioglobal.h>
+
+#endif // QTQMLGLOBAL_P_H
diff --git a/src/spatialaudioquick3d/CMakeLists.txt b/src/spatialaudioquick3d/CMakeLists.txt
new file mode 100644
index 000000000..64b154158
--- /dev/null
+++ b/src/spatialaudioquick3d/CMakeLists.txt
@@ -0,0 +1,33 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## Quick3D.Sound Module:
+#####################################################################
+
+qt_internal_add_qml_module(Quick3DSpatialAudioPrivate
+ URI "QtQuick3D.SpatialAudio"
+ VERSION "${PROJECT_VERSION}"
+ CLASS_NAME QQuick3DAudioModule
+ PLUGIN_TARGET quick3dspatialaudio
+ NO_GENERATE_PLUGIN_SOURCE
+ NO_PLUGIN_OPTIONAL
+ DEPENDENCIES QtQuick QtQuick3DPrivate QtMultimedia
+ CONFIG_MODULE_NAME quick3dspatialaudio
+ INTERNAL_MODULE
+ SOURCES
+ qquick3daudiolistener.cpp qquick3daudiolistener_p.h
+ qquick3daudioroom.cpp qquick3daudioroom_p.h
+ qquick3dspatialsound.cpp qquick3dspatialsound_p.h
+ qquick3dambientsound.cpp qquick3dambientsound_p.h
+ qquick3daudioengine.cpp qquick3daudioengine_p.h
+ qtquick3daudioglobal_p.h
+ qtquick3daudiotypes_p.h
+ QML_FILES
+ PUBLIC_LIBRARIES
+ Qt::Quick3DPrivate
+ Qt::SpatialAudio
+ GENERATE_CPP_EXPORTS
+)
+
+target_sources(quick3dspatialaudio PRIVATE qquick3dspatialaudio_plugin.cpp)
diff --git a/src/spatialaudioquick3d/qquick3dambientsound.cpp b/src/spatialaudioquick3d/qquick3dambientsound.cpp
new file mode 100644
index 000000000..3b8ca4918
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3dambientsound.cpp
@@ -0,0 +1,146 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include "qquick3dambientsound_p.h"
+#include "qquick3daudioengine_p.h"
+#include "qambientsound.h"
+#include <QAudioFormat>
+#include <qdir.h>
+#include <QQmlContext>
+#include <QQmlFile>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype AmbientSound
+ \inqmlmodule QtQuick3D.SpatialAudio
+ \ingroup quick3d_spatialaudio
+ \ingroup multimedia_audio_qml
+
+ \brief A stereo overlay sound.
+
+ A AmbientSound represents a position and orientation independent sound.
+ It's commonly used for background sounds (e.g. music) that is supposed to be independent
+ of the listeners position and orientation.
+ */
+
+QQuick3DAmbientSound::QQuick3DAmbientSound()
+{
+ m_sound = new QAmbientSound(QQuick3DAudioEngine::getEngine());
+
+ connect(m_sound, &QAmbientSound::sourceChanged, this, &QQuick3DAmbientSound::sourceChanged);
+ connect(m_sound, &QAmbientSound::volumeChanged, this, &QQuick3DAmbientSound::volumeChanged);
+ connect(m_sound, &QAmbientSound::loopsChanged, this, &QQuick3DAmbientSound::loopsChanged);
+ connect(m_sound, &QAmbientSound::autoPlayChanged, this, &QQuick3DAmbientSound::autoPlayChanged);
+}
+
+QQuick3DAmbientSound::~QQuick3DAmbientSound()
+{
+ delete m_sound;
+}
+
+/*!
+ \qmlproperty url AmbientSound::source
+
+ The source file for the sound to be played.
+ */
+QUrl QQuick3DAmbientSound::source() const
+{
+ return m_sound->source();
+}
+
+void QQuick3DAmbientSound::setSource(QUrl source)
+{
+ const QQmlContext *context = qmlContext(this);
+ QUrl url;
+ if (context) {
+ url = context->resolvedUrl(source);
+ } else {
+ url = QUrl::fromLocalFile(QDir::currentPath() + u"/");
+ url = url.resolved(source);
+ }
+ m_sound->setSource(url);
+}
+
+/*!
+ \qmlproperty float AmbientSound::volume
+
+ Defines an overall volume for this sound source.
+ */
+void QQuick3DAmbientSound::setVolume(float volume)
+{
+ m_sound->setVolume(volume);
+}
+
+float QQuick3DAmbientSound::volume() const
+{
+ return m_sound->volume();
+}
+
+/*!
+ \qmlproperty int AmbientSound::loops
+
+ Determines how often the sound is played before the player stops.
+ Set to QAmbienSound::Infinite to loop the current sound forever.
+
+ The default value is \c 1.
+ */
+int QQuick3DAmbientSound::loops() const
+{
+ return m_sound->loops();
+}
+
+void QQuick3DAmbientSound::setLoops(int loops)
+{
+ m_sound->setLoops(loops);
+}
+
+/*!
+ \qmlproperty bool AmbientSound::autoPlay
+
+ Determines whether the sound should automatically start playing when a source
+ gets specified.
+
+ The default value is \c true.
+ */
+bool QQuick3DAmbientSound::autoPlay() const
+{
+ return m_sound->autoPlay();
+}
+
+void QQuick3DAmbientSound::setAutoPlay(bool autoPlay)
+{
+ m_sound->setAutoPlay(autoPlay);
+}
+
+/*!
+ \qmlmethod AmbientSound::play()
+
+ Starts playing back the sound. Does nothing if the sound is already playing.
+ */
+void QQuick3DAmbientSound::play()
+{
+ m_sound->play();
+}
+
+/*!
+ \qmlmethod AmbientSound::pause()
+
+ Pauses sound playback at the current position. Calling play() will continue playback.
+ */
+void QQuick3DAmbientSound::pause()
+{
+ m_sound->pause();
+}
+
+/*!
+ \qmlmethod AmbientSound::stop()
+
+ Stops sound playback and resets the current position and loop count to 0. Calling play() will
+ begin playback at the beginning of the sound file.
+ */
+void QQuick3DAmbientSound::stop()
+{
+ m_sound->stop();
+}
+
+QT_END_NAMESPACE
diff --git a/src/spatialaudioquick3d/qquick3dambientsound_p.h b/src/spatialaudioquick3d/qquick3dambientsound_p.h
new file mode 100644
index 000000000..6185179ce
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3dambientsound_p.h
@@ -0,0 +1,74 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#ifndef QQUICK3DAMBIENTSOUND_H
+#define QQUICK3DAMBIENTSOUND_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qquick3dnode_p.h>
+#include <QUrl>
+#include <qvector3d.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAmbientSound;
+
+class QQuick3DAmbientSound : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
+ Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged)
+ Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged)
+ QML_NAMED_ELEMENT(AmbientSound)
+
+public:
+ QQuick3DAmbientSound();
+ ~QQuick3DAmbientSound();
+
+ void setSource(QUrl source);
+ QUrl source() const;
+
+ void setVolume(float volume);
+ float volume() const;
+
+ enum Loops
+ {
+ Infinite = -1,
+ Once = 1
+ };
+ Q_ENUM(Loops)
+
+ int loops() const;
+ void setLoops(int loops);
+
+ bool autoPlay() const;
+ void setAutoPlay(bool autoPlay);
+
+public Q_SLOTS:
+ void play();
+ void pause();
+ void stop();
+
+Q_SIGNALS:
+ void sourceChanged();
+ void volumeChanged();
+ void loopsChanged();
+ void autoPlayChanged();
+
+private:
+ QAmbientSound *m_sound = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudioquick3d/qquick3daudio-qml-types.qdoc b/src/spatialaudioquick3d/qquick3daudio-qml-types.qdoc
new file mode 100644
index 000000000..0ccb69bb9
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3daudio-qml-types.qdoc
@@ -0,0 +1,32 @@
+// Copyright (C) 2015 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\qmlmodule QtQuick3D.Audio
+\title QtQuick3D.SpatialAudio QML Types
+\ingroup qmlmodules
+\brief Provides QML types for spatial audio in Qt Quick 3D.
+
+The QML types Spatial Audio support the basic use cases such as:
+\list
+ \li have a person listening to sounds in 3D space,
+ \li place sound sources in 3D space,
+ \li support room acoustics with direct reflections and reverb,
+ \li support stereo overlay sources (e.g. for sound tracks).
+ \li support output to Headphones using binaural (virtual 3D) rendering of the sound field
+ \li support output to stereo or surround speaker configurations
+\endlist
+
+\section1 QML Types
+
+Qt Quick3D Spatial Audio QML types can be imported into your application using the
+following import statement in your .qml file:
+
+\qml \QtMinorVersion
+import QtQuick3D.Audio
+\endqml
+
+\generatelist qmltypesbymodule QtQuick3D.Audio
+
+\noautolist
+*/
diff --git a/src/spatialaudioquick3d/qquick3daudioengine.cpp b/src/spatialaudioquick3d/qquick3daudioengine.cpp
new file mode 100644
index 000000000..1288effb3
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3daudioengine.cpp
@@ -0,0 +1,128 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include <qquick3daudioengine_p.h>
+#include <qaudiodevice.h>
+
+QT_BEGIN_NAMESPACE
+
+static QAudioEngine *globalEngine = nullptr;
+
+/*!
+ \qmltype AudioEngine
+ \inqmlmodule QtQuick3D.SpatialAudio
+ \ingroup quick3d_spatialaudio
+ \ingroup multimedia_audio_qml
+
+ \brief AudioEngine manages sound objects inside a 3D scene.
+
+ AudioEngine manages sound objects inside a 3D scene. You can add
+ SpatialSound objects to the scene to define sounds that happen
+ at a specified location in 3D space. AmbientSound allows you to add
+ a stereo overlay (for example voice over or a sound track).
+
+ You can use AudioListener to define the position of the person listening
+ to the sound field relative to the sound sources. Sound sources will be less audible
+ if the listener is further away from source. They will also get mapped to the corresponding
+ loudspeakers depending on the direction between listener and source. In many cases, the
+ AudioListener object can simply be instantiated as a child object of the QtQuick3D.Camera
+ object.
+
+ Create AudioRoom objcects to simulate the sound (reflections and reverb) of a room with
+ certain dimensions and different types of walls.
+
+ AudioEngine does offer a mode where Qt is using simulating the effects of the ear
+ using head related impulse reponse functions (see also https://en.wikipedia.org/wiki/Sound_localization)
+ to localize the sound in 3D space when using headphones and create a spatial audio effect through
+ headphones.
+
+ As the rest of Qt Quick 3D, the audio engine uses a coordinate system that is in centimeters by default.
+ The axes are defined so that positive x points to the right, positive y points up and positive z points
+ backwards.
+*/
+
+
+QQuick3DAudioEngine::QQuick3DAudioEngine()
+{
+ auto *e = getEngine();
+ connect(e, &QAudioEngine::outputModeChanged, this, &QQuick3DAudioEngine::outputModeChanged);
+ connect(e, &QAudioEngine::outputDeviceChanged, this, &QQuick3DAudioEngine::outputDeviceChanged);
+ connect(e, &QAudioEngine::masterVolumeChanged, this, &QQuick3DAudioEngine::masterVolumeChanged);
+}
+
+QQuick3DAudioEngine::~QQuick3DAudioEngine()
+{
+}
+
+/*!
+ \qmlproperty enumeration AudioEngine::outputMode
+
+ Sets or retrieves the current output mode of the engine.
+
+ \table
+ \header \li Property value
+ \li Description
+ \row \li Surround
+ \li Map the sounds to the loudspeaker configuration of the output device.
+ This is normally a stereo or surround speaker setup.
+ \row \li Stereo
+ \li Map the sounds to the stereo loudspeaker configuration of the output device.
+ This will ignore any additional speakers and only use the left and right channels
+ to create a stero rendering of the sound field.
+ \row \li Headphone
+ \li Use Headphone spatialization to create a 3D audio effect when listening
+ to the sound field through headphones.
+ \endtable
+ */
+
+void QQuick3DAudioEngine::setOutputMode(OutputMode mode)
+{
+ globalEngine->setOutputMode(QAudioEngine::OutputMode(mode));
+}
+
+QQuick3DAudioEngine::OutputMode QQuick3DAudioEngine::outputMode() const
+{
+ return OutputMode(globalEngine->outputMode());
+}
+
+/*!
+ \qmlproperty QtMultimedia.AudioDevice AudioEngine::outputDevice
+
+ Sets or returns the device that is being used for outputting the sound field.
+ */
+void QQuick3DAudioEngine::setOutputDevice(const QAudioDevice &device)
+{
+ globalEngine->setOutputDevice(device);
+}
+
+QAudioDevice QQuick3DAudioEngine::outputDevice() const
+{
+ return globalEngine->outputDevice();
+}
+
+/*!
+ \qmlproperty float AudioEngine::masterVolume
+
+ Sets or returns overall volume being used to render the sound field.
+ */
+void QQuick3DAudioEngine::setMasterVolume(float volume)
+{
+ globalEngine->setMasterVolume(volume);
+}
+
+float QQuick3DAudioEngine::masterVolume() const
+{
+ return globalEngine->masterVolume();
+}
+
+QAudioEngine *QQuick3DAudioEngine::getEngine()
+{
+ if (!globalEngine) {
+ globalEngine = new QAudioEngine;
+ globalEngine->start();
+ }
+ return globalEngine;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qquick3daudioengine_p.cpp"
diff --git a/src/spatialaudioquick3d/qquick3daudioengine_p.h b/src/spatialaudioquick3d/qquick3daudioengine_p.h
new file mode 100644
index 000000000..9cde33e97
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3daudioengine_p.h
@@ -0,0 +1,64 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#ifndef QQUICK3DAUDIOENGINE_H
+#define QQUICK3DAUDIOENGINE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qquick3dnode_p.h>
+#include <QtGui/qvector3d.h>
+#include <qaudioengine.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuick3DSpatialSound;
+
+class QQuick3DAudioEngine : public QObject
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(AudioEngine)
+ Q_PROPERTY(OutputMode outputMode READ outputMode WRITE setOutputMode NOTIFY outputModeChanged)
+ Q_PROPERTY(QAudioDevice outputDevice READ outputDevice WRITE setOutputDevice NOTIFY outputDeviceChanged)
+ Q_PROPERTY(float masterVolume READ masterVolume WRITE setMasterVolume NOTIFY masterVolumeChanged)
+
+public:
+ // Keep in sync with QAudioEngine::OutputMode
+ enum OutputMode {
+ Surround,
+ Stereo,
+ Headphone
+ };
+ Q_ENUM(OutputMode)
+
+ QQuick3DAudioEngine();
+ ~QQuick3DAudioEngine();
+
+ void setOutputMode(OutputMode mode);
+ OutputMode outputMode() const;
+
+ void setOutputDevice(const QAudioDevice &device);
+ QAudioDevice outputDevice() const;
+
+ void setMasterVolume(float volume);
+ float masterVolume() const;
+
+ static QAudioEngine *getEngine();
+
+Q_SIGNALS:
+ void outputModeChanged();
+ void outputDeviceChanged();
+ void masterVolumeChanged();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudioquick3d/qquick3daudiolistener.cpp b/src/spatialaudioquick3d/qquick3daudiolistener.cpp
new file mode 100644
index 000000000..b8445a799
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3daudiolistener.cpp
@@ -0,0 +1,49 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include <qquick3daudiolistener_p.h>
+#include <qquick3dspatialsound_p.h>
+#include <qquick3daudioengine_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype AudioListener
+ \inqmlmodule QtQuick3D.SpatialAudio
+ \ingroup quick3d_spatialaudio
+ \ingroup multimedia_audio_qml
+
+ \brief defines the position and orientation of the person listening to a sound field
+ defined by a AudioEngine.
+
+ A AudioEngine can have exactly one listener, that defines the position and orientation
+ of the person listening to the sounds defined by the objects placed within the audio engine.
+
+ In most cases, the AudioListener should simply be a child of the Camera element in QtQuick3D.
+ This will ensure that the sound experience is aligned with the visual rendering of the scene.
+ */
+
+QQuick3DAudioListener::QQuick3DAudioListener()
+{
+ m_listener = new QAudioListener(QQuick3DAudioEngine::getEngine());
+ connect(this, &QQuick3DNode::scenePositionChanged, this, &QQuick3DAudioListener::updatePosition);
+ connect(this, &QQuick3DNode::sceneRotationChanged, this, &QQuick3DAudioListener::updateRotation);
+ updatePosition();
+ updateRotation();
+}
+
+QQuick3DAudioListener::~QQuick3DAudioListener()
+{
+ delete m_listener;
+}
+
+void QQuick3DAudioListener::updatePosition()
+{
+ m_listener->setPosition(scenePosition());
+}
+
+void QQuick3DAudioListener::updateRotation()
+{
+ m_listener->setRotation(sceneRotation());
+}
+
+QT_END_NAMESPACE
diff --git a/src/spatialaudioquick3d/qquick3daudiolistener_p.h b/src/spatialaudioquick3d/qquick3daudiolistener_p.h
new file mode 100644
index 000000000..1a24d8f0d
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3daudiolistener_p.h
@@ -0,0 +1,47 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#ifndef QQUICK3DLISTENER_H
+#define QQUICK3DLISTENER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qquick3dnode_p.h>
+#include <QtGui/qvector3d.h>
+
+#include <qaudiolistener.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuick3DAudioListener : public QQuick3DNode
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(AudioListener)
+
+public:
+ QQuick3DAudioListener();
+ ~QQuick3DAudioListener();
+
+ QAudioListener *listener() { return m_listener; }
+protected:
+ QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *) override { return nullptr; }
+
+protected Q_SLOTS:
+ void updatePosition();
+ void updateRotation();
+
+private:
+ QAudioListener *m_listener;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudioquick3d/qquick3daudioroom.cpp b/src/spatialaudioquick3d/qquick3daudioroom.cpp
new file mode 100644
index 000000000..b79a6f609
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3daudioroom.cpp
@@ -0,0 +1,270 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include <qquick3daudioroom_p.h>
+#include <qquick3daudioengine_p.h>
+#include <qaudioroom.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype AudioRoom
+ \inqmlmodule QtQuick3D.SpatialAudio
+ \ingroup quick3d_spatialaudio
+ \ingroup multimedia_audio_qml
+
+ Defines a room for the spatial audio engine.
+
+ If the listener is inside a room, first order sound reflections and reverb
+ matching the rooms properties will get applied to the sound field.
+
+ A room is always square and defined by its center position, its orientation and dimensions.
+ Each of the 6 walls of the room can be made of different materials that will contribute
+ to the computed reflections and reverb that the listener will experience while being inside
+ the room.
+
+ If multiple rooms cover the same position, the engine will use the room with the smallest
+ volume.
+ */
+
+QQuick3DAudioRoom::QQuick3DAudioRoom()
+{
+ m_room = new QAudioRoom(QQuick3DAudioEngine::getEngine());
+
+ connect(this, &QQuick3DNode::scenePositionChanged, this, &QQuick3DAudioRoom::updatePosition);
+ connect(this, &QQuick3DNode::sceneRotationChanged, this, &QQuick3DAudioRoom::updateRotation);
+ connect(m_room, &QAudioRoom::dimensionsChanged, this, &QQuick3DAudioRoom::dimensionsChanged);
+ connect(m_room, &QAudioRoom::rotationChanged, this, &QQuick3DAudioRoom::rotationChanged);
+ connect(m_room, &QAudioRoom::wallsChanged, this, &QQuick3DAudioRoom::wallsChanged);
+ connect(m_room, &QAudioRoom::reflectionGainChanged, this, &QQuick3DAudioRoom::reflectionGainChanged);
+ connect(m_room, &QAudioRoom::reverbGainChanged, this, &QQuick3DAudioRoom::reverbGainChanged);
+ connect(m_room, &QAudioRoom::reverbTimeChanged, this, &QQuick3DAudioRoom::reverbTimeChanged);
+ connect(m_room, &QAudioRoom::reverbBrightnessChanged, this, &QQuick3DAudioRoom::reverbBrightnessChanged);
+}
+
+QQuick3DAudioRoom::~QQuick3DAudioRoom()
+{
+ delete m_room;
+}
+
+/*!
+ \qmlproperty vector3D AudioRoom::dimensions
+
+ Defines the dimensions of the room in 3D space. Units are in centimeters
+ by default.
+
+ \sa QtQuick3D::Node::position
+ */
+void QQuick3DAudioRoom::setDimensions(QVector3D dim)
+{
+ m_room->setDimensions(dim);
+}
+
+QVector3D QQuick3DAudioRoom::dimensions() const
+{
+ return m_room->dimensions();
+}
+
+/*!
+ \qmlproperty AudioRoom::Material AudioRoom::leftMaterial
+ \qmlproperty AudioRoom::Material AudioRoom::rightMaterial
+ \qmlproperty AudioRoom::Material AudioRoom::frontMaterial
+ \qmlproperty AudioRoom::Material AudioRoom::backMaterial
+ \qmlproperty AudioRoom::Material AudioRoom::floorMaterial
+ \qmlproperty AudioRoom::Material AudioRoom::ceilingMaterial
+
+ Sets the material to use for the different sides of the room. Properties correlate to
+ coordinates as follows:
+
+ \table
+ \header
+ \li Property
+ \li Coordinate
+ \row \li left \li Negative x
+ \row \li right \li Positive x
+ \row \li back \li Negative z
+ \row \li front \li Positive z
+ \row \li floor \li Negative y
+ \row \li ceiling \li Positive y
+ \endtable
+
+ Valid values for the material are:
+
+ \table
+ \header
+ \li Property value
+ \li Description
+ \row \li Transparent \li The side of the room is open and won't contribute to reflections or reverb.
+ \row \li AcousticCeilingTiles \li Acoustic tiles that suppress most reflections and reverb.
+ \row \li BrickBare \li A bare brick wall.
+ \row \li BrickPainted \li A painted brick wall.
+ \row \li ConcreteBlockCoarse \li A raw concrete wall
+ \row \li ConcreteBlockPainted \li A painted concrete wall
+ \row \li CurtainHeavy \li A heavy curtain. Will mostly reflect low frequencies
+ \row \li FiberGlassInsulation \li Fiber glass insulation. Only reflects very low frequencies
+ \row \li GlassThin \li A thin glass wall
+ \row \li GlassThick \li A thick glass wall
+ \row \li Grass \li Grass
+ \row \li LinoleumOnConcrete \li A Linoleum floor
+ \row \li Marble \li A marble floor
+ \row \li Metal \li Metal
+ \row \li ParquetOnConcrete \li Parquet wooden floor on concrete
+ \row \li PlasterRough \li Rough plaster
+ \row \li PlasterSmooth \li Smooth plaster
+ \row \li PlywoodPanel \li Plywodden panel
+ \row \li PolishedConcreteOrTile \li Polished concrete or tiles
+ \row \li Sheetrock \li Rock
+ \row \li WaterOrIceSurface \li Water or ice
+ \row \li WoodCeiling \li A wooden ceiling
+ \row \li WoodPanel \li Wooden panel
+ \row \li Uniform \li Artificial material giving uniform reflections on all frequencies
+ \endtable
+ */
+void QQuick3DAudioRoom::setLeftMaterial(Material material)
+{
+ m_room->setWallMaterial(QAudioRoom::LeftWall, QAudioRoom::Material(material));
+}
+
+QQuick3DAudioRoom::Material QQuick3DAudioRoom::leftMaterial() const
+{
+ return Material(m_room->wallMaterial(QAudioRoom::LeftWall));
+}
+
+void QQuick3DAudioRoom::setRightMaterial(Material material)
+{
+ m_room->setWallMaterial(QAudioRoom::RightWall, QAudioRoom::Material(material));
+}
+
+QQuick3DAudioRoom::Material QQuick3DAudioRoom::rightMaterial() const
+{
+ return Material(m_room->wallMaterial(QAudioRoom::RightWall));
+}
+
+void QQuick3DAudioRoom::setFrontMaterial(Material material)
+{
+ m_room->setWallMaterial(QAudioRoom::FrontWall, QAudioRoom::Material(material));
+}
+
+QQuick3DAudioRoom::Material QQuick3DAudioRoom::frontMaterial() const
+{
+ return Material(m_room->wallMaterial(QAudioRoom::FrontWall));
+}
+
+void QQuick3DAudioRoom::setBackMaterial(Material material)
+{
+ m_room->setWallMaterial(QAudioRoom::BackWall, QAudioRoom::Material(material));
+}
+
+QQuick3DAudioRoom::Material QQuick3DAudioRoom::backMaterial() const
+{
+ return Material(m_room->wallMaterial(QAudioRoom::BackWall));
+}
+
+void QQuick3DAudioRoom::setFloorMaterial(Material material)
+{
+ m_room->setWallMaterial(QAudioRoom::Floor, QAudioRoom::Material(material));
+}
+
+QQuick3DAudioRoom::Material QQuick3DAudioRoom::floorMaterial() const
+{
+ return Material(m_room->wallMaterial(QAudioRoom::Floor));
+}
+
+void QQuick3DAudioRoom::setCeilingMaterial(Material material)
+{
+ m_room->setWallMaterial(QAudioRoom::Ceiling, QAudioRoom::Material(material));
+}
+
+QQuick3DAudioRoom::Material QQuick3DAudioRoom::ceilingMaterial() const
+{
+ return Material(m_room->wallMaterial(QAudioRoom::Ceiling));
+}
+
+/*!
+ \qmlproperty float AudioRoom::reflectionGain
+
+ A gain factor for reflections generated in this room. A value
+ from 0 to 1 will dampen reflections, while a value larger than 1
+ will apply a gain to reflections, making them louder.
+
+ The default is 1, a factor of 0 disables reflections. Negative
+ values are mapped to 0.
+ */
+void QQuick3DAudioRoom::setReflectionGain(float factor)
+{
+ m_room->setReflectionGain(factor);
+}
+
+float QQuick3DAudioRoom::reflectionGain() const
+{
+ return m_room->reflectionGain();
+}
+
+/*!
+ \qmlproperty float AudioRoom::reverbGain
+
+ A gain factor for reverb generated in this room. A value
+ from 0 to 1 will dampen reverb, while a value larger than 1
+ will apply a gain to the reverb, making it louder.
+
+ The default is 1, a factor of 0 disables reverb. Negative
+ values are mapped to 0.
+ */
+void QQuick3DAudioRoom::setReverbGain(float factor)
+{
+ m_room->setReverbGain(factor);
+}
+
+float QQuick3DAudioRoom::reverbGain() const
+{
+ return m_room->reverbGain();
+}
+
+/*!
+ \qmlproperty float AudioRoom::reverbTime
+
+ A factor to be applies to all reverb timings generated for this room.
+ Larger values will lead to longer reverb timings, making the room sound
+ larger.
+
+ The default is 1. Negative values are mapped to 0.
+ */
+void QQuick3DAudioRoom::setReverbTime(float factor)
+{
+ m_room->setReverbTime(factor);
+}
+
+float QQuick3DAudioRoom::reverbTime() const
+{
+ return m_room->reverbTime();
+}
+
+/*!
+ \qmlproperty float AudioRoom::reverbBrightness
+
+ A brightness factor to be applied to the generated reverb.
+ A positive value will increase reverb for higher frequencies and
+ dampen lower frequencies, a negative value does the reverse.
+
+ The default is 0.
+ */
+void QQuick3DAudioRoom::setReverbBrightness(float factor)
+{
+ m_room->setReverbBrightness(factor);
+}
+
+float QQuick3DAudioRoom::reverbBrightness() const
+{
+ return m_room->reverbBrightness();
+}
+
+void QQuick3DAudioRoom::updatePosition()
+{
+ m_room->setPosition(scenePosition());
+}
+
+void QQuick3DAudioRoom::updateRotation()
+{
+ m_room->setRotation(sceneRotation());
+}
+
+QT_END_NAMESPACE
diff --git a/src/spatialaudioquick3d/qquick3daudioroom_p.h b/src/spatialaudioquick3d/qquick3daudioroom_p.h
new file mode 100644
index 000000000..8198b9307
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3daudioroom_p.h
@@ -0,0 +1,129 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+
+#ifndef QQUICK3DAUDIOROOM_H
+#define QQUICK3DAUDIOROOM_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qquick3dnode_p.h>
+#include <QtGui/qvector3d.h>
+#include <qaudioroom.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioEngine;
+class QAudioRoomPrivate;
+
+class QQuick3DAudioRoom : public QQuick3DNode
+{
+ Q_OBJECT
+ Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
+ Q_PROPERTY(QVector3D dimensions READ dimensions WRITE setDimensions NOTIFY dimensionsChanged)
+ Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
+ Q_PROPERTY(Material leftMaterial READ leftMaterial WRITE setLeftMaterial NOTIFY wallsChanged)
+ Q_PROPERTY(Material rightMaterial READ rightMaterial WRITE setRightMaterial NOTIFY wallsChanged)
+ Q_PROPERTY(Material frontMaterial READ frontMaterial WRITE setFrontMaterial NOTIFY wallsChanged)
+ Q_PROPERTY(Material backMaterial READ backMaterial WRITE setBackMaterial NOTIFY wallsChanged)
+ Q_PROPERTY(Material floorMaterial READ floorMaterial WRITE setFloorMaterial NOTIFY wallsChanged)
+ Q_PROPERTY(Material ceilingMaterial READ ceilingMaterial WRITE setCeilingMaterial NOTIFY wallsChanged)
+ Q_PROPERTY(float reflectionGain READ reflectionGain WRITE setReflectionGain NOTIFY reflectionGainChanged)
+ Q_PROPERTY(float reverbGain READ reverbGain WRITE setReverbGain NOTIFY reverbGainChanged)
+ Q_PROPERTY(float reverbTime READ reverbTime WRITE setReverbTime NOTIFY reverbTimeChanged)
+ Q_PROPERTY(float reverbBrightness READ reverbBrightness WRITE setReverbBrightness NOTIFY reverbBrightnessChanged)
+ QML_NAMED_ELEMENT(AudioRoom)
+public:
+ QQuick3DAudioRoom();
+ ~QQuick3DAudioRoom();
+
+ enum Material {
+ Transparent,
+ AcousticCeilingTiles,
+ BrickBare,
+ BrickPainted,
+ ConcreteBlockCoarse,
+ ConcreteBlockPainted,
+ CurtainHeavy,
+ FiberGlassInsulation,
+ GlassThin,
+ GlassThick,
+ Grass,
+ LinoleumOnConcrete,
+ Marble,
+ Metal,
+ ParquetOnConcrete,
+ PlasterRough,
+ PlasterSmooth,
+ PlywoodPanel,
+ PolishedConcreteOrTile,
+ Sheetrock,
+ WaterOrIceSurface,
+ WoodCeiling,
+ WoodPanel,
+ Uniform,
+ };
+ Q_ENUM(Material)
+
+ void setDimensions(QVector3D pos);
+ QVector3D dimensions() const;
+
+ void setLeftMaterial(Material material);
+ Material leftMaterial() const;
+
+ void setRightMaterial(Material material);
+ Material rightMaterial() const;
+
+ void setFrontMaterial(Material material);
+ Material frontMaterial() const;
+
+ void setBackMaterial(Material material);
+ Material backMaterial() const;
+
+ void setFloorMaterial(Material material);
+ Material floorMaterial() const;
+
+ void setCeilingMaterial(Material material);
+ Material ceilingMaterial() const;
+
+ void setReflectionGain(float factor);
+ float reflectionGain() const;
+
+ void setReverbGain(float factor);
+ float reverbGain() const;
+
+ void setReverbTime(float factor);
+ float reverbTime() const;
+
+ void setReverbBrightness(float factor);
+ float reverbBrightness() const;
+
+Q_SIGNALS:
+ void positionChanged();
+ void dimensionsChanged();
+ void rotationChanged();
+ void wallsChanged();
+ void reflectionGainChanged();
+ void reverbGainChanged();
+ void reverbTimeChanged();
+ void reverbBrightnessChanged();
+
+protected Q_SLOTS:
+ void updatePosition();
+ void updateRotation();
+
+private:
+ QAudioRoom *m_room;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudioquick3d/qquick3dspatialaudio_plugin.cpp b/src/spatialaudioquick3d/qquick3dspatialaudio_plugin.cpp
new file mode 100644
index 000000000..399a215ad
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3dspatialaudio_plugin.cpp
@@ -0,0 +1,35 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+
+#include <QtQml/qqmlextensionplugin.h>
+#include <QtQml/qqml.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcomponent.h>
+#include "qtquick3daudioglobal_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QQuick3DAudioModule : public QQmlEngineExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
+
+public:
+ QQuick3DAudioModule(QObject *parent = nullptr)
+ : QQmlEngineExtensionPlugin(parent)
+ {
+ volatile auto registration = qml_register_types_QtQuick3D_SpatialAudio;
+ Q_UNUSED(registration);
+ }
+
+ void initializeEngine(QQmlEngine *engine, const char *uri) override
+ {
+ Q_UNUSED(engine);
+ Q_UNUSED(uri);
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "qquick3dspatialaudio_plugin.moc"
+
diff --git a/src/spatialaudioquick3d/qquick3dspatialsound.cpp b/src/spatialaudioquick3d/qquick3dspatialsound.cpp
new file mode 100644
index 000000000..04c935c56
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3dspatialsound.cpp
@@ -0,0 +1,323 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#include "qquick3dspatialsound_p.h"
+#include "qquick3daudioengine_p.h"
+#include "qspatialsound.h"
+#include <QAudioFormat>
+#include <qdir.h>
+#include <QQmlContext>
+#include <QQmlFile>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype SpatialSound
+ \inqmlmodule QtQuick3D.SpatialAudio
+ \ingroup quick3d_spatialaudio
+ \ingroup multimedia_audio_qml
+
+ \brief A sound object in 3D space.
+
+ A SpatialSound represents an audible object in 3D space. You can define
+ it's position and orientation in space, set the sound it is playing and define a
+ volume for the object.
+
+ The object can have different attenuation behavior, emit sound mainly in one direction
+ or spherically, and behave as if occluded by some other object.
+ */
+
+QQuick3DSpatialSound::QQuick3DSpatialSound()
+{
+ m_sound = new QSpatialSound(QQuick3DAudioEngine::getEngine());
+
+ connect(this, &QQuick3DNode::scenePositionChanged, this, &QQuick3DSpatialSound::updatePosition);
+ connect(this, &QQuick3DNode::sceneRotationChanged, this, &QQuick3DSpatialSound::updateRotation);
+ connect(m_sound, &QSpatialSound::sourceChanged, this, &QQuick3DSpatialSound::sourceChanged);
+ connect(m_sound, &QSpatialSound::volumeChanged, this, &QQuick3DSpatialSound::volumeChanged);
+ connect(m_sound, &QSpatialSound::distanceModelChanged, this, &QQuick3DSpatialSound::distanceModelChanged);
+ connect(m_sound, &QSpatialSound::sizeChanged, this, &QQuick3DSpatialSound::sizeChanged);
+ connect(m_sound, &QSpatialSound::distanceCutoffChanged, this, &QQuick3DSpatialSound::distanceCutoffChanged);
+ connect(m_sound, &QSpatialSound::manualAttenuationChanged, this, &QQuick3DSpatialSound::manualAttenuationChanged);
+ connect(m_sound, &QSpatialSound::occlusionIntensityChanged, this, &QQuick3DSpatialSound::occlusionIntensityChanged);
+ connect(m_sound, &QSpatialSound::directivityChanged, this, &QQuick3DSpatialSound::directivityChanged);
+ connect(m_sound, &QSpatialSound::directivityOrderChanged, this, &QQuick3DSpatialSound::directivityOrderChanged);
+ connect(m_sound, &QSpatialSound::nearFieldGainChanged, this, &QQuick3DSpatialSound::nearFieldGainChanged);
+ connect(m_sound, &QSpatialSound::loopsChanged, this, &QQuick3DSpatialSound::loopsChanged);
+ connect(m_sound, &QSpatialSound::autoPlayChanged, this, &QQuick3DSpatialSound::autoPlayChanged);
+}
+
+QQuick3DSpatialSound::~QQuick3DSpatialSound()
+{
+ delete m_sound;
+}
+
+/*!
+ \qmlproperty url SpatialSound::source
+
+ The source file for the sound to be played.
+ */
+QUrl QQuick3DSpatialSound::source() const
+{
+ return m_sound->source();
+}
+
+void QQuick3DSpatialSound::setSource(QUrl source)
+{
+ const QQmlContext *context = qmlContext(this);
+ QUrl url;
+ if (context) {
+ url = context->resolvedUrl(source);
+ } else {
+ url = QUrl::fromLocalFile(QDir::currentPath() + u"/");
+ url = url.resolved(source);
+ }
+ m_sound->setSource(url);
+}
+
+/*!
+ \qmlproperty float SpatialSound::volume
+
+ Defines an overall volume for this sound source.
+
+ Values between 0 and 1 will attenuate the sound, while values above 1
+ provide an additional gain boost.
+ */
+void QQuick3DSpatialSound::setVolume(float volume)
+{
+ m_sound->setVolume(volume);
+}
+
+float QQuick3DSpatialSound::volume() const
+{
+ return m_sound->volume();
+}
+
+/*!
+ \qmlproperty enumeration SpatialSound::distanceModel
+
+ Defines how the volume of the sound scales with distance to the listener.
+ The volume starts scaling down
+ from \l size to \l distanceCutoff. The volume is constant for distances smaller
+ than size and zero for distances larger than the cutoff distance.
+
+ \table
+ \header \li Property value
+ \li Description
+ \row \li Logarithmic
+ \li Volume decreases logarithmically with distance.
+ \row \li Linear
+ \li Volume decreases linearly with distance.
+ \row \li ManualAttenuation
+ \li Attenuation is defined manually using the \l manualAttenuation property.
+ \endtable
+ */
+void QQuick3DSpatialSound::setDistanceModel(DistanceModel model)
+{
+ m_sound->setDistanceModel(QSpatialSound::DistanceModel(model));
+}
+
+QQuick3DSpatialSound::DistanceModel QQuick3DSpatialSound::distanceModel() const
+{
+ return DistanceModel(m_sound->distanceModel());
+}
+
+/*!
+ \qmlproperty float SpatialSound::size
+
+ Defines the size of the sound source. If the listener is closer to the sound
+ object than the size, volume will stay constant. The size is also used to for
+ occlusion calculations, where large sources can be partially occluded by a wall.
+ */
+void QQuick3DSpatialSound::setSize(float min)
+{
+ m_sound->setSize(min);
+}
+
+float QQuick3DSpatialSound::size() const
+{
+ return m_sound->size();
+}
+
+/*!
+ \qmlproperty float SpatialSound::distanceCutoff
+
+ Defines a distance beyond which sound coming from the source will cutoff.
+ If the listener is further away from the sound object than the cutoff
+ distance it won't be audible anymore.
+ */
+void QQuick3DSpatialSound::setDistanceCutoff(float max)
+{
+ m_sound->setDistanceCutoff(max);
+}
+
+float QQuick3DSpatialSound::distanceCutoff() const
+{
+ return m_sound->distanceCutoff();
+}
+
+/*!
+ \qmlproperty float SpatialSound::manualAttenuation
+
+ Defines a manual attenuation factor if \l distanceModel is set to
+ SpatialSound.ManualAttenuation.
+ */
+void QQuick3DSpatialSound::setManualAttenuation(float attenuation)
+{
+ m_sound->setManualAttenuation(attenuation);
+}
+
+float QQuick3DSpatialSound::manualAttenuation() const
+{
+ return m_sound->manualAttenuation();
+}
+
+/*!
+ \qmlproperty float SpatialSound::occlusionIntensity
+
+ Defines how much the object is occluded. 0 implies the object is
+ not occluded at all, while a large number implies a large occlusion.
+
+ The default is 0.
+ */
+void QQuick3DSpatialSound::setOcclusionIntensity(float occlusion)
+{
+ m_sound->setOcclusionIntensity(occlusion);
+}
+
+float QQuick3DSpatialSound::occlusionIntensity() const
+{
+ return m_sound->occlusionIntensity();
+}
+
+/*!
+ \qmlproperty float SpatialSound::directivity
+
+ Defines the directivity of the sound source. A value of 0 implies that the sound is
+ emitted equally in all directions, while a value of 1 implies that the source mainly
+ emits sound in the forward direction.
+
+ Valid values are between 0 and 1, the default is 0.
+ */
+void QQuick3DSpatialSound::setDirectivity(float alpha)
+{
+ m_sound->setDirectivity(alpha);
+}
+
+float QQuick3DSpatialSound::directivity() const
+{
+ return m_sound->directivity();
+}
+
+/*!
+ \qmlproperty float SpatialSound::directivityOrder
+
+ Defines the order of the directivity of the sound source. A higher order
+ implies a sharper localization of the sound cone.
+
+ The minimum value and default for this property is 1.
+ */
+void QQuick3DSpatialSound::setDirectivityOrder(float alpha)
+{
+ m_sound->setDirectivityOrder(alpha);
+}
+
+float QQuick3DSpatialSound::directivityOrder() const
+{
+ return m_sound->directivityOrder();
+}
+
+/*!
+ \qmlproperty float SpatialSound::nearFieldGain
+
+ Defines the near field gain for the sound source. Valid values are between 0 and 1.
+ A near field gain of 1 will raise the volume of the sound signal by approx 20 dB for
+ distances very close to the listener.
+ */
+void QQuick3DSpatialSound::setNearFieldGain(float gain)
+{
+ m_sound->setNearFieldGain(gain);
+}
+
+float QQuick3DSpatialSound::nearFieldGain() const
+{
+ return m_sound->nearFieldGain();
+}
+
+void QQuick3DSpatialSound::updatePosition()
+{
+ m_sound->setPosition(scenePosition());
+}
+
+void QQuick3DSpatialSound::updateRotation()
+{
+ m_sound->setRotation(sceneRotation());
+}
+
+/*!
+ \qmlproperty int SpatialSound::loops
+
+ Determines how often the sound is played before the player stops.
+ Set to SpatialSound::Infinite to loop the current sound forever.
+
+ The default value is \c 1.
+ */
+int QQuick3DSpatialSound::loops() const
+{
+ return m_sound->loops();
+}
+
+void QQuick3DSpatialSound::setLoops(int loops)
+{
+ m_sound->setLoops(loops);
+}
+
+/*!
+ \qmlproperty bool SpatialSound::autoPlay
+
+ Determines whether the sound should automatically start playing when a source
+ gets specified.
+
+ The default value is \c true.
+ */
+bool QQuick3DSpatialSound::autoPlay() const
+{
+ return m_sound->autoPlay();
+}
+
+void QQuick3DSpatialSound::setAutoPlay(bool autoPlay)
+{
+ m_sound->setAutoPlay(autoPlay);
+}
+
+/*!
+ \qmlmethod SpatialSound::play()
+
+ Starts playing back the sound. Does nothing if the sound is already playing.
+ */
+void QQuick3DSpatialSound::play()
+{
+ m_sound->play();
+}
+
+/*!
+ \qmlmethod SpatialSound::pause()
+
+ Pauses sound playback at the current position. Calling play() will continue playback.
+ */
+void QQuick3DSpatialSound::pause()
+{
+ m_sound->pause();
+}
+
+/*!
+ \qmlmethod SpatialSound::stop()
+
+ Stops sound playback and resets the current position and loop count to 0. Calling play() will
+ begin playback at the beginning of the sound file.
+ */
+void QQuick3DSpatialSound::stop()
+{
+ m_sound->stop();
+}
+
+QT_END_NAMESPACE
diff --git a/src/spatialaudioquick3d/qquick3dspatialsound_p.h b/src/spatialaudioquick3d/qquick3dspatialsound_p.h
new file mode 100644
index 000000000..d24a63056
--- /dev/null
+++ b/src/spatialaudioquick3d/qquick3dspatialsound_p.h
@@ -0,0 +1,127 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+#ifndef QQUICK3DSPATIALSOUND_H
+#define QQUICK3DSPATIALSOUND_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qquick3dnode_p.h>
+#include <QUrl>
+#include <qvector3d.h>
+#include <qspatialsound.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuick3DSpatialSound : public QQuick3DNode
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
+ Q_PROPERTY(DistanceModel distanceModel READ distanceModel WRITE setDistanceModel NOTIFY distanceModelChanged)
+ Q_PROPERTY(float size READ size WRITE setSize NOTIFY sizeChanged)
+ Q_PROPERTY(float distanceCutoff READ distanceCutoff WRITE setDistanceCutoff NOTIFY distanceCutoffChanged)
+ Q_PROPERTY(float manualAttenuation READ manualAttenuation WRITE setManualAttenuation NOTIFY manualAttenuationChanged)
+ Q_PROPERTY(float occlusionIntensity READ occlusionIntensity WRITE setOcclusionIntensity NOTIFY occlusionIntensityChanged)
+ Q_PROPERTY(float directivity READ directivity WRITE setDirectivity NOTIFY directivityChanged)
+ Q_PROPERTY(float directivityOrder READ directivityOrder WRITE setDirectivityOrder NOTIFY directivityOrderChanged)
+ Q_PROPERTY(float nearFieldGain READ nearFieldGain WRITE setNearFieldGain NOTIFY nearFieldGainChanged)
+ Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged)
+ Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged)
+ QML_NAMED_ELEMENT(SpatialSound)
+
+public:
+ QQuick3DSpatialSound();
+ ~QQuick3DSpatialSound();
+
+ void setSource(QUrl source);
+ QUrl source() const;
+
+ void setVolume(float volume);
+ float volume() const;
+
+ enum DistanceModel {
+ Logarithmic,
+ Linear,
+ ManualAttenuation
+ };
+ Q_ENUM(DistanceModel);
+
+ void setDistanceModel(DistanceModel model);
+ DistanceModel distanceModel() const;
+
+ void setSize(float min);
+ float size() const;
+
+ void setDistanceCutoff(float max);
+ float distanceCutoff() const;
+
+ void setManualAttenuation(float attenuation);
+ float manualAttenuation() const;
+
+ void setOcclusionIntensity(float occlusion);
+ float occlusionIntensity() const;
+
+ void setDirectivity(float alpha);
+ float directivity() const;
+
+ void setDirectivityOrder(float alpha);
+ float directivityOrder() const;
+
+ void setNearFieldGain(float gain);
+ float nearFieldGain() const;
+
+ enum Loops
+ {
+ Infinite = -1,
+ Once = 1
+ };
+ Q_ENUM(Loops)
+
+ int loops() const;
+ void setLoops(int loops);
+
+ bool autoPlay() const;
+ void setAutoPlay(bool autoPlay);
+
+public Q_SLOTS:
+ void play();
+ void pause();
+ void stop();
+
+Q_SIGNALS:
+ void sourceChanged();
+ void volumeChanged();
+ void distanceModelChanged();
+ void sizeChanged();
+ void distanceCutoffChanged();
+ void manualAttenuationChanged();
+ void occlusionIntensityChanged();
+ void directivityChanged();
+ void directivityOrderChanged();
+ void nearFieldGainChanged();
+ void loopsChanged();
+ void autoPlayChanged();
+
+private Q_SLOTS:
+ void updatePosition();
+ void updateRotation();
+
+protected:
+ QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *) override { return nullptr; }
+
+private:
+ QSpatialSound *m_sound = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/spatialaudioquick3d/qtquick3daudioglobal_p.h b/src/spatialaudioquick3d/qtquick3daudioglobal_p.h
new file mode 100644
index 000000000..9fbad2173
--- /dev/null
+++ b/src/spatialaudioquick3d/qtquick3daudioglobal_p.h
@@ -0,0 +1,28 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QQUICK3DAUDIOGLOBAL_P_H
+#define QQUICK3DAUDIOGLOBAL_P_H
+
+#include <QtCore/qglobal.h>
+#include <QtMultimediaQuick/qtmultimediaquickexports.h>
+
+QT_BEGIN_NAMESPACE
+
+void Q_MULTIMEDIAQUICK_EXPORT qml_register_types_QtQuick3D_SpatialAudio();
+
+QT_END_NAMESPACE
+
+#endif // QMULTIMEDIAQUICKDEFS_P_H
+
diff --git a/src/spatialaudioquick3d/qtquick3daudiotypes_p.h b/src/spatialaudioquick3d/qtquick3daudiotypes_p.h
new file mode 100644
index 000000000..814cb4077
--- /dev/null
+++ b/src/spatialaudioquick3d/qtquick3daudiotypes_p.h
@@ -0,0 +1,27 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
+
+#ifndef QQUICK3DAUDIOTYPES_H
+#define QQUICK3DAUDIOTYPES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQml/qqml.h>
+#include <private/qtquick3daudioglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+// Nothing for now
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/src.pro b/src/src.pro
deleted file mode 100644
index 1dc1015c6..000000000
--- a/src/src.pro
+++ /dev/null
@@ -1,53 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS += multimedia
-
-include($$OUT_PWD/multimedia/qtmultimedia-config.pri)
-QT_FOR_CONFIG += multimedia-private
-
-# Everything else depends on multimedia
-src_qgsttools.subdir = gsttools
-src_qgsttools.depends = multimedia
-
-src_qtmmwidgets.subdir = multimediawidgets
-src_qtmmwidgets.depends = multimedia
-
-src_plugins.subdir = plugins
-src_plugins.depends = multimedia
-
-
-qtHaveModule(quick) {
- src_qtmultimediaquicktools.subdir = qtmultimediaquicktools
- src_qtmultimediaquicktools.depends = multimedia
-
- src_imports.subdir = imports
- src_imports.depends = multimedia src_qtmultimediaquicktools
-
- # For the videonode plugin
- src_plugins.depends += src_qtmultimediaquicktools
-
- SUBDIRS += \
- src_qtmultimediaquicktools \
- src_imports
-}
-
-# Optional bits
-qtHaveModule(widgets) {
- SUBDIRS += src_qtmmwidgets
-
- # If widgets is around, plugins depends on widgets too (imports does not)
- src_plugins.depends += src_qtmmwidgets
-
- # same with qgsttools
- src_qgsttools.depends += src_qtmmwidgets
-}
-
-qtConfig(gstreamer) {
- SUBDIRS += src_qgsttools
-
- # If gstreamer is present, then plugins should depend on it
- src_plugins.depends += src_qgsttools
-}
-
-SUBDIRS += src_plugins
-